@@ -36,25 +36,29 @@ import { attachInspector } from '../core/inspector'
3636import { Stats } from '../core/stats'
3737import { setGlobalAnalyticsKey } from '../lib/global-analytics-helper'
3838
39- export interface LegacyIntegrationConfiguration {
39+ export interface RemoteIntegrationSettings {
4040 /* @deprecated - This does not indicate browser types anymore */
4141 type ?: string
4242
4343 versionSettings ?: {
4444 version ?: string
4545 override ?: string
46- componentTypes ?: Array < 'browser' | 'android' | 'ios' | 'server' >
46+ componentTypes ?: ( 'browser' | 'android' | 'ios' | 'server' ) [ ]
4747 }
4848
49- bundlingStatus ?: string
49+ /**
50+ * We know if an integration is device mode if it has `bundlingStatus: 'bundled'` and the `browser` componentType in `versionSettings`.
51+ * History: The term 'bundle' is left over from before action destinations, when a device mode destinations were 'bundled' in a custom bundle for every analytics.js source.
52+ */
53+ bundlingStatus ?: 'bundled' | 'unbundled'
5054
5155 /**
5256 * Consent settings for the integration
5357 */
5458 consentSettings ?: {
5559 /**
5660 * Consent categories for the integration
57- * @example ["Analytics ", "Advertising", "CAT001 "]
61+ * @example ["CAT001 ", "CAT002 "]
5862 */
5963 categories : string [ ]
6064 }
@@ -67,9 +71,13 @@ export interface LegacyIntegrationConfiguration {
6771 [ key : string ] : any
6872}
6973
70- export interface LegacySettings {
74+ /**
75+ * The remote settings object for a source, typically fetched from the Segment CDN.
76+ * Warning: this is an *unstable* object.
77+ */
78+ export interface CDNSettings {
7179 integrations : {
72- [ name : string ] : LegacyIntegrationConfiguration
80+ [ creationName : string ] : RemoteIntegrationSettings
7381 }
7482
7583 middlewareSettings ?: {
@@ -109,7 +117,7 @@ export interface AnalyticsBrowserSettings extends AnalyticsSettings {
109117 * If provided, `AnalyticsBrowser` will not fetch remote settings
110118 * for the source.
111119 */
112- cdnSettings ?: LegacySettings & Record < string , unknown >
120+ cdnSettings ?: CDNSettings & Record < string , unknown >
113121 /**
114122 * If provided, will override the default Segment CDN (https://cdn.segment.com) for this application.
115123 */
@@ -119,7 +127,7 @@ export interface AnalyticsBrowserSettings extends AnalyticsSettings {
119127export function loadLegacySettings (
120128 writeKey : string ,
121129 cdnURL ?: string
122- ) : Promise < LegacySettings > {
130+ ) : Promise < CDNSettings > {
123131 const baseUrl = cdnURL ?? getCDN ( )
124132
125133 return fetch ( `${ baseUrl } /v1/projects/${ writeKey } /settings` )
@@ -137,15 +145,15 @@ export function loadLegacySettings(
137145 } )
138146}
139147
140- function hasLegacyDestinations ( settings : LegacySettings ) : boolean {
148+ function hasLegacyDestinations ( settings : CDNSettings ) : boolean {
141149 return (
142150 getProcessEnv ( ) . NODE_ENV !== 'test' &&
143151 // just one integration means segmentio
144152 Object . keys ( settings . integrations ) . length > 1
145153 )
146154}
147155
148- function hasTsubMiddleware ( settings : LegacySettings ) : boolean {
156+ function hasTsubMiddleware ( settings : CDNSettings ) : boolean {
149157 return (
150158 getProcessEnv ( ) . NODE_ENV !== 'test' &&
151159 ( settings . middlewareSettings ?. routingRules ?. length ?? 0 ) > 0
@@ -185,7 +193,7 @@ async function flushFinalBuffer(
185193
186194async function registerPlugins (
187195 writeKey : string ,
188- legacySettings : LegacySettings ,
196+ cdnSettings : CDNSettings ,
189197 analytics : Analytics ,
190198 options : InitOptions ,
191199 pluginLikes : ( Plugin | PluginFactory ) [ ] = [ ] ,
@@ -201,24 +209,22 @@ async function registerPlugins(
201209 typeof pluginLike . pluginName === 'string'
202210 ) as PluginFactory [ ]
203211
204- const tsubMiddleware = hasTsubMiddleware ( legacySettings )
212+ const tsubMiddleware = hasTsubMiddleware ( cdnSettings )
205213 ? await import (
206214 /* webpackChunkName: "tsub-middleware" */ '../plugins/routing-middleware'
207215 ) . then ( ( mod ) => {
208- return mod . tsubMiddleware (
209- legacySettings . middlewareSettings ! . routingRules
210- )
216+ return mod . tsubMiddleware ( cdnSettings . middlewareSettings ! . routingRules )
211217 } )
212218 : undefined
213219
214220 const legacyDestinations =
215- hasLegacyDestinations ( legacySettings ) || legacyIntegrationSources . length > 0
221+ hasLegacyDestinations ( cdnSettings ) || legacyIntegrationSources . length > 0
216222 ? await import (
217223 /* webpackChunkName: "ajs-destination" */ '../plugins/ajs-destination'
218224 ) . then ( ( mod ) => {
219225 return mod . ajsDestinations (
220226 writeKey ,
221- legacySettings ,
227+ cdnSettings ,
222228 analytics . integrations ,
223229 options ,
224230 tsubMiddleware ,
@@ -227,7 +233,7 @@ async function registerPlugins(
227233 } )
228234 : [ ]
229235
230- if ( legacySettings . legacyVideoPluginsEnabled ) {
236+ if ( cdnSettings . legacyVideoPluginsEnabled ) {
231237 await import (
232238 /* webpackChunkName: "legacyVideos" */ '../plugins/legacy-video-plugins'
233239 ) . then ( ( mod ) => {
@@ -239,13 +245,13 @@ async function registerPlugins(
239245 ? await import (
240246 /* webpackChunkName: "schemaFilter" */ '../plugins/schema-filter'
241247 ) . then ( ( mod ) => {
242- return mod . schemaFilter ( options . plan ?. track , legacySettings )
248+ return mod . schemaFilter ( options . plan ?. track , cdnSettings )
243249 } )
244250 : undefined
245251
246- const mergedSettings = mergedOptions ( legacySettings , options )
252+ const mergedSettings = mergedOptions ( cdnSettings , options )
247253 const remotePlugins = await remoteLoader (
248- legacySettings ,
254+ cdnSettings ,
249255 analytics . integrations ,
250256 mergedSettings ,
251257 options ,
@@ -274,15 +280,15 @@ async function registerPlugins(
274280 await segmentio (
275281 analytics ,
276282 mergedSettings [ 'Segment.io' ] as SegmentioSettings ,
277- legacySettings . integrations
283+ cdnSettings . integrations
278284 )
279285 )
280286 }
281287
282288 const ctx = await analytics . register ( ...toRegister )
283289
284290 if (
285- Object . entries ( legacySettings . enabledMiddleware ?? { } ) . some (
291+ Object . entries ( cdnSettings . enabledMiddleware ?? { } ) . some (
286292 ( [ , enabled ] ) => enabled
287293 )
288294 ) {
@@ -291,7 +297,7 @@ async function registerPlugins(
291297 ) . then ( async ( { remoteMiddlewares } ) => {
292298 const middleware = await remoteMiddlewares (
293299 ctx ,
294- legacySettings ,
300+ cdnSettings ,
295301 options . obfuscate
296302 )
297303 const promises = middleware . map ( ( mdw ) =>
0 commit comments