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AEJ,CEkPsBE,CADYjB,EAAyBrJ,IAE/CuK,EAAc,IAAIrG,EACtBlE,EACAS,EACA8I,EAAmBvJ,GACnBoE,EACuB,OAAvBqF,QAAuB,IAAvBA,OAAuB,EAAvBA,EAA0BzJ,IAU5B,OAPgBmJ,EAAaa,QAC3B,SAACQ,GAAS,OAAAA,EAAKC,kBAAoBzK,CAAzB,IAEAuD,OAAS,GAAKyF,GACxBuB,EAAY5D,cAAcqC,GAGrBuB,CACT,GACJ,C","sources":["../node_modules/@segment/analytics-core/src/validation/helpers.ts","../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 { CoreSegmentEvent } from '../events'\n\nexport function isString(obj: unknown): obj is string {\n return typeof obj === 'string'\n}\n\nexport function isNumber(obj: unknown): obj is number {\n return typeof obj === 'number'\n}\n\nexport function isFunction(obj: unknown): obj is Function {\n return typeof obj === 'function'\n}\n\nexport function isPlainObject(\n obj: unknown\n): obj is Record {\n return (\n Object.prototype.toString.call(obj).slice(8, -1).toLowerCase() === 'object'\n )\n}\n\nexport function hasUser(event: CoreSegmentEvent): boolean {\n const id =\n event.userId ?? event.anonymousId ?? event.groupId ?? event.previousId\n return isString(id)\n}\n","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'\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 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, `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 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 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":["isPlainObject","obj","Object","prototype","toString","call","slice","toLowerCase","isPlanEventEnabled","plan","planEvent","enabled","_b","_a","__default","normalizeName","name","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","settings","options","integrationSource","middleware","_ready","_initialized","flushing","this","__assign","disableAutoISOConversion","buffer","disableClientPersistence","PriorityQueue","PersistedPriorityQueue","scheduleFlush","isLoaded","ready","onReady","resolve","load","analyticsInstance","_c","integration","integrationCtr","user","addIntegration","Integration","analytics","buildIntegration","once","onInitialize","on","increment","initialize","error","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","Track","page","_assumesPageview","then","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","keys","filter","Array","from","shouldSkipIntegration","_d","override","resolveVersion","destination","rule","destinationName"],"sourceRoot":""}