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gBAAQ,IAAApL,EAAAA,EACV,QAAzBoG,EAAQ,OAAR3B,QAAQ,IAARA,OAAQ,EAARA,EAAU7B,uBAAe,IAAAwD,OAAA,EAAAA,EAAEtF,eAAO,IAAAqK,EAAAA,EAClC,QAEJ,CE4PsBE,CADYnB,EAAyB9J,IAE/CkL,EAAc,IAAI/G,EACtBnE,EACAU,EACA0D,EACA4F,EAAmBhK,GACnBsE,EACuB,OAAvB4F,QAAuB,IAAvBA,OAAuB,EAAvBA,EAA0BlK,IAU5B,OAPgB4J,EAAac,QAC3B,SAACS,GAAS,OAAAA,EAAKC,kBAAoBpL,CAAzB,IAEAwD,OAAS,GAAKiG,GACxByB,EAAY9D,cAAcqC,GAGrByB,CACT,GACJ,C","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/utils.ts","../node_modules/@segment/analytics-next/src/plugins/ajs-destination/index.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 } 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","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'\nimport { recordIntegrationMetric } from '../../core/stats/metric-helpers'\nimport { createDeferred } from '@segment/analytics-generic-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: boolean | undefined\n private _initialized: boolean | undefined\n private onReady: Promise | undefined\n private initializePromise = createDeferred()\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.initializePromise.promise.then(\n (isInitialized) => (this._initialized = isInitialized),\n () => {}\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.initializePromise.promise.then(\n () => this.onReady ?? Promise.resolve()\n )\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.integration!.on('initialize', () => {\n this.initializePromise.resolve(true)\n })\n\n try {\n recordIntegrationMetric(ctx, {\n integrationName: this.name,\n methodName: 'initialize',\n type: 'classic',\n })\n this.integration.initialize()\n } catch (error) {\n recordIntegrationMetric(ctx, {\n integrationName: this.name,\n methodName: 'initialize',\n type: 'classic',\n didError: true,\n })\n this.initializePromise.resolve(false)\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 recordIntegrationMetric(ctx, {\n integrationName: this.name,\n methodName: eventType,\n type: 'classic',\n })\n\n try {\n if (this.integration) {\n await this.integration!.invoke.call(this.integration, eventType, event)\n }\n } catch (err) {\n recordIntegrationMetric(ctx, {\n integrationName: this.name,\n methodName: eventType,\n type: 'classic',\n didError: true,\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 await this.initializePromise.promise\n return this.send(ctx, Page as ClassType, 'page')\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"],"names":["isPlanEventEnabled","plan","planEvent","enabled","_b","_a","__default","normalizeName","name","toLowerCase","replace","obfuscatePathName","pathName","obfuscate","btoa","undefined","loadIntegration","ctx","version","obfuscatedPathName","path","getNextIntegrationsURL","fullPath","concat","loadScript","sent","metric","window","performance","getEntriesByName","stats","gauge","Math","round","duration","__spreadArray","_","recordLoadMetrics","err_1","deps","Promise","all","map","dep","isInstallableIntegration","integrationSettings","type","bundlingStatus","versionSettings","deviceMode","componentTypes","includes","startsWith","isDisabledIntegration","integrationName","globalIntegrations","allDisableAndNotDefined","All","flushQueue","xt","queue","failedQueue","isOffline","pWhile","length","isOnline","__awaiter","_this","pop","attempt","result","Context","push","failed","pushWithBackoff","LegacyDestination","writeKey","settings","options","integrationSource","middleware","initializePromise","createDeferred","flushing","this","__assign","disableAutoISOConversion","promise","then","isInitialized","_initialized","buffer","disableClientPersistence","PriorityQueue","PersistedPriorityQueue","scheduleFlush","prototype","isLoaded","_ready","ready","onReady","resolve","load","analyticsInstance","_c","integration","integrationCtr","user","addIntegration","Integration","analytics","buildIntegration","once","on","recordIntegrationMetric","methodName","initialize","error","didError","unload","_ctx","_analyticsInstance","unloadScript","unloadIntegration","addMiddleware","fn","_i","arguments","apply","shouldBuffer","event","send","clz","eventType","track","ev","updateEvent","integrations","cancel","ContextCancelation","retry","reason","applyDestinationMiddleware","afterMiddleware","traverse","invoke","call","Track","page","_assumesPageview","Page","identify","Identify","alias","Alias","group","Group","setTimeout","todo","random","ajsDestinations","routingMiddleware","legacyIntegrationSources","isServer","routingRules","middlewareSettings","remoteIntegrationsConfig","localIntegrationsConfig","integrationOptions","mergedOptions","adhocIntegrationSources","reduce","acc","resolveIntegrationNameFromSource","installableIntegrations","Set","Object","keys","filter","isPlainObject","Array","from","shouldSkipIntegration","_d","override","resolveVersion","destination","rule","destinationName"],"sourceRoot":""}