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,EACAkF,EAAmBnI,GACnBmD,EACuB,OAAvBkF,QAAuB,IAAvBA,OAAuB,EAAvBA,EAA0BrI,IAU5B,OAPgB+H,EAAae,QAC3B,SAACiB,GAAS,OAAAA,EAAKC,kBAAoBhK,KAEzBwC,OAAS,GAAKoF,GACxBkC,EAAYG,cAAcrC,GAGrBkC","sources":["../node_modules/@segment/analytics-next/src/lib/is-plan-event-enabled.ts","../node_modules/@segment/analytics-next/src/plugins/ajs-destination/loader.ts","../node_modules/@segment/analytics-next/src/plugins/ajs-destination/index.ts","../node_modules/@segment/analytics-next/src/plugins/ajs-destination/utils.ts"],"sourcesContent":["import { PlanEvent, TrackPlan } from '../core/events/interfaces'\n\n/**\n * Determines whether a track event is allowed to be sent based on the\n * user's tracking plan.\n * If the user does not have a tracking plan or the event is allowed based\n * on the tracking plan configuration, returns true.\n */\nexport function isPlanEventEnabled(\n plan: TrackPlan | undefined,\n planEvent: PlanEvent | undefined\n): boolean {\n // Always prioritize the event's `enabled` status\n if (typeof planEvent?.enabled === 'boolean') {\n return planEvent.enabled\n }\n\n // Assume absence of a tracking plan means events are enabled\n return plan?.__default?.enabled ?? true\n}\n","import { Analytics } from '../../core/analytics'\nimport { LegacyIntegrationConfiguration } from '../../browser'\nimport { getNextIntegrationsURL } from '../../lib/parse-cdn'\nimport { Context } from '../../core/context'\nimport { User } from '../../core/user'\nimport { loadScript, unloadScript } from '../../lib/load-script'\nimport {\n LegacyIntegration,\n ClassicIntegrationBuilder,\n ClassicIntegrationSource,\n} from './types'\n\nfunction normalizeName(name: string): string {\n return name.toLowerCase().replace('.', '').replace(/\\s+/g, '-')\n}\n\nfunction obfuscatePathName(pathName: string, obfuscate = false): string | void {\n return obfuscate ? btoa(pathName).replace(/=/g, '') : undefined\n}\n\nexport function resolveIntegrationNameFromSource(\n integrationSource: ClassicIntegrationSource\n) {\n return (\n 'Integration' in integrationSource\n ? integrationSource.Integration\n : integrationSource\n ).prototype.name\n}\n\nfunction recordLoadMetrics(fullPath: string, ctx: Context, name: string): void {\n try {\n const [metric] =\n window?.performance?.getEntriesByName(fullPath, 'resource') ?? []\n // we assume everything that took under 100ms is cached\n metric &&\n ctx.stats.gauge('legacy_destination_time', Math.round(metric.duration), [\n name,\n ...(metric.duration < 100 ? ['cached'] : []),\n ])\n } catch (_) {\n // not available\n }\n}\n\nexport function buildIntegration(\n integrationSource: ClassicIntegrationSource,\n integrationSettings: { [key: string]: any },\n analyticsInstance: Analytics\n): LegacyIntegration {\n let integrationCtr: ClassicIntegrationBuilder\n // GA and Appcues use a different interface to instantiating integrations\n if ('Integration' in integrationSource) {\n const analyticsStub = {\n user: (): User => analyticsInstance.user(),\n addIntegration: (): void => {},\n }\n\n integrationSource(analyticsStub)\n integrationCtr = integrationSource.Integration\n } else {\n integrationCtr = integrationSource\n }\n\n const integration = new integrationCtr(integrationSettings)\n integration.analytics = analyticsInstance\n return integration\n}\n\nexport async function loadIntegration(\n ctx: Context,\n name: string,\n version: string,\n obfuscate?: boolean\n): Promise {\n const pathName = normalizeName(name)\n const obfuscatedPathName = obfuscatePathName(pathName, obfuscate)\n const path = getNextIntegrationsURL()\n\n const fullPath = `${path}/integrations/${\n obfuscatedPathName ?? pathName\n }/${version}/${obfuscatedPathName ?? pathName}.dynamic.js.gz`\n\n try {\n await loadScript(fullPath)\n recordLoadMetrics(fullPath, ctx, name)\n } catch (err) {\n ctx.stats.gauge('legacy_destination_time', -1, [`plugin:${name}`, `failed`])\n throw err\n }\n\n // @ts-ignore\n const deps: string[] = window[`${pathName}Deps`]\n await Promise.all(deps.map((dep) => loadScript(path + dep + '.gz')))\n\n // @ts-ignore\n window[`${pathName}Loader`]()\n\n return window[\n // @ts-ignore\n `${pathName}Integration`\n ] as ClassicIntegrationSource\n}\n\nexport async function unloadIntegration(\n name: string,\n version: string,\n obfuscate?: boolean\n): Promise {\n const path = getNextIntegrationsURL()\n const pathName = normalizeName(name)\n const obfuscatedPathName = obfuscatePathName(name, obfuscate)\n\n const fullPath = `${path}/integrations/${\n obfuscatedPathName ?? pathName\n }/${version}/${obfuscatedPathName ?? pathName}.dynamic.js.gz`\n\n return unloadScript(fullPath)\n}\n\nexport function resolveVersion(\n settings?: LegacyIntegrationConfiguration\n): string {\n return (\n settings?.versionSettings?.override ??\n settings?.versionSettings?.version ??\n 'latest'\n )\n}\n","import { Integrations, JSONObject } from '../../core/events'\nimport { Alias, Facade, Group, Identify, Page, Track } from '@segment/facade'\nimport { Analytics, InitOptions } from '../../core/analytics'\nimport { LegacySettings } from '../../browser'\nimport { isOffline, isOnline } from '../../core/connection'\nimport { Context, ContextCancelation } from '../../core/context'\nimport { isServer } from '../../core/environment'\nimport { DestinationPlugin, Plugin } from '../../core/plugin'\nimport { attempt } from '@segment/analytics-core'\nimport { isPlanEventEnabled } from '../../lib/is-plan-event-enabled'\nimport { mergedOptions } from '../../lib/merged-options'\nimport { pWhile } from '../../lib/p-while'\nimport { PriorityQueue } from '../../lib/priority-queue'\nimport { PersistedPriorityQueue } from '../../lib/priority-queue/persisted'\nimport {\n applyDestinationMiddleware,\n DestinationMiddlewareFunction,\n} from '../middleware'\nimport {\n buildIntegration,\n loadIntegration,\n resolveIntegrationNameFromSource,\n resolveVersion,\n unloadIntegration,\n} from './loader'\nimport { LegacyIntegration, ClassicIntegrationSource } from './types'\nimport { isPlainObject } from '@segment/analytics-core'\nimport {\n isDisabledIntegration as shouldSkipIntegration,\n isInstallableIntegration,\n} from './utils'\n\nexport type ClassType = new (...args: unknown[]) => T\n\nasync function flushQueue(\n xt: Plugin,\n queue: PriorityQueue\n): Promise> {\n const failedQueue: Context[] = []\n\n if (isOffline()) {\n return queue\n }\n\n await pWhile(\n () => queue.length > 0 && isOnline(),\n async () => {\n const ctx = queue.pop()\n if (!ctx) {\n return\n }\n\n const result = await attempt(ctx, xt)\n const success = result instanceof Context\n if (!success) {\n failedQueue.push(ctx)\n }\n }\n )\n\n // re-add failed tasks\n failedQueue.map((failed) => queue.pushWithBackoff(failed))\n return queue\n}\n\nexport class LegacyDestination implements DestinationPlugin {\n name: string\n version: string\n settings: JSONObject\n options: InitOptions = {}\n type: Plugin['type'] = 'destination'\n middleware: DestinationMiddlewareFunction[] = []\n\n private _ready = false\n private _initialized = false\n private onReady: Promise | undefined\n private onInitialize: Promise | undefined\n private disableAutoISOConversion: boolean\n\n integrationSource?: ClassicIntegrationSource\n integration: LegacyIntegration | undefined\n\n buffer: PriorityQueue\n flushing = false\n\n constructor(\n name: string,\n version: string,\n writeKey: string,\n settings: JSONObject = {},\n options: InitOptions,\n integrationSource?: ClassicIntegrationSource\n ) {\n this.name = name\n this.version = version\n this.settings = { ...settings }\n this.disableAutoISOConversion = options.disableAutoISOConversion || false\n this.integrationSource = integrationSource\n\n // AJS-Renderer sets an extraneous `type` setting that clobbers\n // existing type defaults. We need to remove it if it's present\n if (this.settings['type'] && this.settings['type'] === 'browser') {\n delete this.settings['type']\n }\n\n this.options = options\n this.buffer = options.disableClientPersistence\n ? new PriorityQueue(4, [])\n : new PersistedPriorityQueue(4, `${writeKey}:dest-${name}`)\n\n this.scheduleFlush()\n }\n\n isLoaded(): boolean {\n return this._ready\n }\n\n ready(): Promise {\n return this.onReady ?? Promise.resolve()\n }\n\n async load(ctx: Context, analyticsInstance: Analytics): Promise {\n if (this._ready || this.onReady !== undefined) {\n return\n }\n\n const integrationSource =\n this.integrationSource ??\n (await loadIntegration(\n ctx,\n this.name,\n this.version,\n this.options.obfuscate\n ))\n\n this.integration = buildIntegration(\n integrationSource,\n this.settings,\n analyticsInstance\n )\n\n this.onReady = new Promise((resolve) => {\n const onReadyFn = (): void => {\n this._ready = true\n resolve(true)\n }\n\n this.integration!.once('ready', onReadyFn)\n })\n\n this.onInitialize = new Promise((resolve) => {\n const onInit = (): void => {\n this._initialized = true\n resolve(true)\n }\n\n this.integration!.on('initialize', onInit)\n })\n\n try {\n ctx.stats.increment('analytics_js.integration.invoke', 1, [\n `method:initialize`,\n `integration_name:${this.name}`,\n ])\n\n this.integration.initialize()\n } catch (error) {\n ctx.stats.increment('analytics_js.integration.invoke.error', 1, [\n `method:initialize`,\n `integration_name:${this.name}`,\n ])\n\n throw error\n }\n }\n\n unload(_ctx: Context, _analyticsInstance: Analytics): Promise {\n return unloadIntegration(this.name, this.version, this.options.obfuscate)\n }\n\n addMiddleware(...fn: DestinationMiddlewareFunction[]): void {\n this.middleware = this.middleware.concat(...fn)\n }\n\n shouldBuffer(ctx: Context): boolean {\n return (\n // page events can't be buffered because of destinations that automatically add page views\n ctx.event.type !== 'page' &&\n (isOffline() || this._ready === false || this._initialized === false)\n )\n }\n\n private async send(\n ctx: Context,\n clz: ClassType,\n eventType: 'track' | 'identify' | 'page' | 'alias' | 'group'\n ): Promise {\n if (this.shouldBuffer(ctx)) {\n this.buffer.push(ctx)\n this.scheduleFlush()\n return ctx\n }\n\n const plan = this.options?.plan?.track\n const ev = ctx.event.event\n\n if (plan && ev && this.name !== 'Segment.io') {\n // events are always sent to segment (legacy behavior)\n const planEvent = plan[ev]\n if (!isPlanEventEnabled(plan, planEvent)) {\n ctx.updateEvent('integrations', {\n ...ctx.event.integrations,\n All: false,\n 'Segment.io': true,\n })\n ctx.cancel(\n new ContextCancelation({\n retry: false,\n reason: `Event ${ev} disabled for integration ${this.name} in tracking plan`,\n type: 'Dropped by plan',\n })\n )\n return ctx\n } else {\n ctx.updateEvent('integrations', {\n ...ctx.event.integrations,\n ...planEvent?.integrations,\n })\n }\n\n if (planEvent?.enabled && planEvent?.integrations![this.name] === false) {\n ctx.cancel(\n new ContextCancelation({\n retry: false,\n reason: `Event ${ev} disabled for integration ${this.name} in tracking plan`,\n type: 'Dropped by plan',\n })\n )\n return ctx\n }\n }\n\n const afterMiddleware = await applyDestinationMiddleware(\n this.name,\n ctx.event,\n this.middleware\n )\n\n if (afterMiddleware === null) {\n return ctx\n }\n\n const event = new clz(afterMiddleware, {\n traverse: !this.disableAutoISOConversion,\n })\n\n ctx.stats.increment('analytics_js.integration.invoke', 1, [\n `method:${eventType}`,\n `integration_name:${this.name}`,\n ])\n\n try {\n if (this.integration) {\n await this.integration.invoke.call(this.integration, eventType, event)\n }\n } catch (err) {\n ctx.stats.increment('analytics_js.integration.invoke.error', 1, [\n `method:${eventType}`,\n `integration_name:${this.name}`,\n ])\n throw err\n }\n\n return ctx\n }\n\n async track(ctx: Context): Promise {\n return this.send(ctx, Track as ClassType, 'track')\n }\n\n async page(ctx: Context): Promise {\n if (this.integration?._assumesPageview && !this._initialized) {\n this.integration.initialize()\n }\n\n return this.onInitialize!.then(() => {\n return this.send(ctx, Page as ClassType, 'page')\n })\n }\n\n async identify(ctx: Context): Promise {\n return this.send(ctx, Identify as ClassType, 'identify')\n }\n\n async alias(ctx: Context): Promise {\n return this.send(ctx, Alias as ClassType, 'alias')\n }\n\n async group(ctx: Context): Promise {\n return this.send(ctx, Group as ClassType, 'group')\n }\n\n private scheduleFlush(): void {\n if (this.flushing) {\n return\n }\n\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n setTimeout(async () => {\n this.flushing = true\n this.buffer = await flushQueue(this, this.buffer)\n this.flushing = false\n\n if (this.buffer.todo > 0) {\n this.scheduleFlush()\n }\n }, Math.random() * 5000)\n }\n}\n\nexport function ajsDestinations(\n writeKey: string,\n settings: LegacySettings,\n globalIntegrations: Integrations = {},\n options: InitOptions = {},\n routingMiddleware?: DestinationMiddlewareFunction,\n legacyIntegrationSources?: ClassicIntegrationSource[]\n): LegacyDestination[] {\n if (isServer()) {\n return []\n }\n\n if (settings.plan) {\n options = options ?? {}\n options.plan = settings.plan\n }\n\n const routingRules = settings.middlewareSettings?.routingRules ?? []\n const remoteIntegrationsConfig = settings.integrations\n const localIntegrationsConfig = options.integrations\n // merged remote CDN settings with user provided options\n const integrationOptions = mergedOptions(settings, options ?? {}) as Record<\n string,\n JSONObject\n >\n\n const adhocIntegrationSources = legacyIntegrationSources?.reduce(\n (acc, integrationSource) => ({\n ...acc,\n [resolveIntegrationNameFromSource(integrationSource)]: integrationSource,\n }),\n {} as Record\n )\n\n const installableIntegrations = new Set([\n // Remotely configured installable integrations\n ...Object.keys(remoteIntegrationsConfig).filter((name) =>\n isInstallableIntegration(name, remoteIntegrationsConfig[name])\n ),\n\n // Directly provided integration sources are only installable if settings for them are available\n ...Object.keys(adhocIntegrationSources || {}).filter(\n (name) =>\n isPlainObject(remoteIntegrationsConfig[name]) ||\n isPlainObject(localIntegrationsConfig?.[name])\n ),\n ])\n\n return Array.from(installableIntegrations)\n .filter((name) => !shouldSkipIntegration(name, globalIntegrations))\n .map((name) => {\n const integrationSettings = remoteIntegrationsConfig[name]\n const version = resolveVersion(integrationSettings)\n const destination = new LegacyDestination(\n name,\n version,\n writeKey,\n integrationOptions[name],\n options,\n adhocIntegrationSources?.[name]\n )\n\n const routing = routingRules.filter(\n (rule) => rule.destinationName === name\n )\n if (routing.length > 0 && routingMiddleware) {\n destination.addMiddleware(routingMiddleware)\n }\n\n return destination\n })\n}\n","import { Integrations } from '@segment/analytics-core'\nimport { LegacyIntegrationConfiguration } from '../..'\n\nexport const isInstallableIntegration = (\n name: string,\n integrationSettings: LegacyIntegrationConfiguration\n) => {\n const { type, bundlingStatus, versionSettings } = integrationSettings\n // We use `!== 'unbundled'` (versus `=== 'bundled'`) to be inclusive of\n // destinations without a defined value for `bundlingStatus`\n const deviceMode =\n bundlingStatus !== 'unbundled' &&\n (type === 'browser' || versionSettings?.componentTypes?.includes('browser'))\n\n // checking for iterable is a quick fix we need in place to prevent\n // errors showing Iterable as a failed destiantion. Ideally, we should\n // fix the Iterable metadata instead, but that's a longer process.\n return !name.startsWith('Segment') && name !== 'Iterable' && deviceMode\n}\n\nexport const isDisabledIntegration = (\n integrationName: string,\n globalIntegrations: Integrations\n) => {\n const allDisableAndNotDefined =\n globalIntegrations.All === false &&\n globalIntegrations[integrationName] === undefined\n\n return (\n globalIntegrations[integrationName] === false || allDisableAndNotDefined\n )\n}\n"],"names":["isPlanEventEnabled","plan","planEvent","enabled","__default","normalizeName","name","toLowerCase","replace","obfuscatePathName","pathName","obfuscate","btoa","undefined","loadIntegration","ctx","version","obfuscatedPathName","path","getNextIntegrationsURL","fullPath","loadScript","_a","metric","window","performance","getEntriesByName","stats","gauge","Math","round","duration","_","recordLoadMetrics","err_1","deps","Promise","all","map","dep","flushQueue","xt","queue","failedQueue","isOffline","pWhile","length","isOnline","pop","attempt","result","Context","push","failed","pushWithBackoff","writeKey","settings","options","integrationSource","type","middleware","_ready","_initialized","flushing","this","disableAutoISOConversion","buffer","disableClientPersistence","PriorityQueue","PersistedPriorityQueue","scheduleFlush","LegacyDestination","onReady","resolve","analyticsInstance","_b","_c","integration","integrationSettings","integrationCtr","user","addIntegration","Integration","analytics","buildIntegration","_this","once","onInitialize","on","increment","initialize","error","_ctx","_analyticsInstance","unloadScript","unloadIntegration","_i","fn","concat","event","clz","eventType","shouldBuffer","track","ev","updateEvent","integrations","All","cancel","ContextCancelation","retry","reason","applyDestinationMiddleware","afterMiddleware","traverse","invoke","call","send","Track","_assumesPageview","then","Page","Identify","Alias","Group","setTimeout","todo","random","ajsDestinations","globalIntegrations","routingMiddleware","legacyIntegrationSources","isServer","routingRules","middlewareSettings","remoteIntegrationsConfig","localIntegrationsConfig","integrationOptions","mergedOptions","adhocIntegrationSources","reduce","acc","prototype","resolveIntegrationNameFromSource","installableIntegrations","Set","Object","keys","filter","bundlingStatus","versionSettings","deviceMode","componentTypes","includes","startsWith","isInstallableIntegration","isPlainObject","Array","from","integrationName","allDisableAndNotDefined","shouldSkipIntegration","override","resolveVersion","destination","rule","destinationName","addMiddleware"],"sourceRoot":""}