@ada-cx/messaging-sdk 1.9.5 → 1.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/client/client-channel-handlers.d.ts +3 -0
  2. package/dist/client/client-host-runtime.d.ts +6 -0
  3. package/dist/client/client-types.d.ts +1 -0
  4. package/dist/client/client.d.ts +16 -2
  5. package/dist/client/config-helpers.d.ts +1 -17
  6. package/dist/client/embed-interface.d.ts +2 -0
  7. package/dist/client/frame-styles.d.ts +1 -1
  8. package/dist/client/frame-visibility.d.ts +1 -0
  9. package/dist/client/proactive/proactive-channel.d.ts +1 -0
  10. package/dist/client/proactive/proactive-runtime.d.ts +1 -0
  11. package/dist/embed-host/bridge.d.ts +17 -0
  12. package/dist/embed-host/controller-origin.d.ts +3 -0
  13. package/dist/embed-host/index.d.ts +2 -0
  14. package/dist/embed-host/layout.d.ts +16 -0
  15. package/dist/embed-host/registry.d.ts +220 -0
  16. package/dist/embed-host/window-events.d.ts +2 -0
  17. package/dist/embed-host/wire.d.ts +13 -0
  18. package/dist/embed-protocol.d.ts +217 -0
  19. package/dist/frame-channel/types.d.ts +2 -0
  20. package/dist/helpers/api-endpoint.d.ts +17 -0
  21. package/dist/helpers/bridge-validation.d.ts +1 -0
  22. package/dist/helpers/host-environment.d.ts +40 -0
  23. package/dist/helpers/iframe-embed-mode.d.ts +23 -0
  24. package/dist/helpers/integration-lifecycle.d.ts +1 -0
  25. package/dist/helpers/launch-controls.d.ts +3 -2
  26. package/dist/npm/index.cjs +1 -1
  27. package/dist/npm/index.cjs.map +1 -1
  28. package/dist/npm/index.js +1 -1
  29. package/dist/npm/index.js.map +1 -1
  30. package/dist/npm/testing.cjs +1 -1
  31. package/dist/npm/testing.cjs.map +1 -1
  32. package/dist/npm/testing.js +79 -95
  33. package/dist/npm/testing.js.map +1 -1
  34. package/package.json +8 -2
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../shared/utils/src/browser-polyfills.ts","../../src/npm/build-info.ts","../../src/client/embed-lifecycle.ts","../../src/npm/loader.ts"],"sourcesContent":["/**\n * Defence in depth for engines just below the declared browser floor.\n * The floor is defined in `messaging/vite.browser-targets.mjs`.\n *\n * Internal Ada code should prefer direct helpers, such as `hasOwn(...)` from\n * `guards.ts`. Every Ada bundle includes these fallbacks, including the host-page\n * SDK. These fallbacks also ship inside the customer-held npm tarballs of the SDK\n * and bridge. Each fallback defines a member only when it is missing. These\n * fallbacks do not extend browser support below the floor required by the shipped CSS.\n */\n\nconst objectHasOwnProperty = Object.prototype.hasOwnProperty;\n\nfunction defineValue(\n\ttarget: object,\n\tname: PropertyKey,\n\tvalue: (...args: unknown[]) => unknown,\n): void {\n\tObject.defineProperty(target, name, {\n\t\tvalue,\n\t\tconfigurable: true,\n\t\twritable: true,\n\t});\n}\n\nif (!Object.hasOwn) {\n\tdefineValue(Object, \"hasOwn\", (object: unknown, key: unknown) => {\n\t\tif (object == null) {\n\t\t\tthrow new TypeError(\n\t\t\t\t\"ada browser-polyfills: Cannot convert undefined or null to object\",\n\t\t\t);\n\t\t}\n\t\treturn objectHasOwnProperty.call(Object(object), key as PropertyKey);\n\t});\n}\n\nfunction at<T>(\n\tthis: { length: number; [index: number]: T },\n\tindex: unknown,\n): T | undefined {\n\tconst length = Math.trunc(Number(this.length)) || 0;\n\tlet relativeIndex = Math.trunc(Number(index)) || 0;\n\tif (relativeIndex < 0) {\n\t\trelativeIndex += length;\n\t}\n\treturn relativeIndex < 0 || relativeIndex >= length\n\t\t? undefined\n\t\t: this[relativeIndex];\n}\n\nfunction stringAt(this: string, index: unknown): string | undefined {\n\tconst value = String(this);\n\tconst length = value.length;\n\tlet relativeIndex = Math.trunc(Number(index)) || 0;\n\tif (relativeIndex < 0) {\n\t\trelativeIndex += length;\n\t}\n\treturn relativeIndex < 0 || relativeIndex >= length\n\t\t? undefined\n\t\t: value.charAt(relativeIndex);\n}\n\nconst typedArrayConstructors = [\n\tglobalThis.Int8Array,\n\tglobalThis.Uint8Array,\n\tglobalThis.Uint8ClampedArray,\n\tglobalThis.Int16Array,\n\tglobalThis.Uint16Array,\n\tglobalThis.Int32Array,\n\tglobalThis.Uint32Array,\n\tglobalThis.Float32Array,\n\tglobalThis.Float64Array,\n\tglobalThis.BigInt64Array,\n\tglobalThis.BigUint64Array,\n].filter(Boolean);\n\nif (!Array.prototype.at) {\n\tdefineValue(Array.prototype, \"at\", at);\n}\n\nif (!String.prototype.at) {\n\tdefineValue(String.prototype, \"at\", stringAt);\n}\n\nfor (const TypedArrayConstructor of typedArrayConstructors) {\n\tconst prototype = TypedArrayConstructor.prototype;\n\tif (!prototype.at) {\n\t\tdefineValue(prototype, \"at\", at);\n\t}\n}\n","// The repo copy carries the 40-zero placeholder; the publish workflow\n// (.github/workflows/messaging-publish-web-packages.yml) stamps the real\n// commit SHA into the built output via scripts/stamp-cdn-build-sha.mjs and\n// verifies the packed tarball before `npm publish`. Keep the placeholder as\n// a single 40-zero string literal: the stamp is a same-length text\n// replacement, so source maps stay valid.\nconst GIT_SHA_PATTERN = /^[0-9a-f]{40}$/;\nconst UNSTAMPED_SHA_PATTERN = /^0{40}$/;\n\n/**\n * Git commit SHA of the monorepo commit this npm version was published from.\n * The CDN pipeline deploys each main commit's runtime under an immutable\n * SHA root, so this value names the CDN build associated with this npm\n * version. Pass it as the `pinBuildSha` loader option to load exactly that\n * runtime build — not recommended for production (see the README).\n *\n * In the repository, and in any locally built copy, the value is the\n * unstamped 40-zero placeholder ({@link isCdnBuildShaStamped} returns\n * `false`); only published tarballs carry a real SHA.\n */\nexport const CDN_BUILD_SHA: string = \"e7166c32375fbdd1a0f4ec5eedaa1cec124c0f52\";\n\n/**\n * Whether `sha` (default {@link CDN_BUILD_SHA}) is a stamped full git commit\n * SHA rather than the unstamped repo placeholder.\n */\nexport function isCdnBuildShaStamped(sha: string = CDN_BUILD_SHA): boolean {\n\tconst normalized = sha.trim().toLowerCase();\n\treturn (\n\t\tGIT_SHA_PATTERN.test(normalized) && !UNSTAMPED_SHA_PATTERN.test(normalized)\n\t);\n}\n","/**\n * Lifecycle channel between `createAdaEmbedInterface` and the npm loader's\n * memo: a non-enumerable getter over closure state, so the loader never\n * mutates the public surface and `Object.freeze` on the facade still works.\n * `Symbol.for` because the loader and the CDN runtime are separate builds;\n * a runtime that predates the getter yields `undefined` — degrade gracefully.\n */\nexport const EMBED_LIFECYCLE_STOPPED = Symbol.for(\n\t\"ada-cx/messaging-sdk/embed-stopped\",\n);\n\n/** Read the host-initiated stop flag; `undefined` when the runtime predates it. */\nexport function readEmbedStoppedFlag(ada: object): boolean | undefined {\n\tconst value = (ada as Record<symbol, unknown>)[EMBED_LIFECYCLE_STOPPED];\n\treturn typeof value === \"boolean\" ? value : undefined;\n}\n\n/** Define the getter at facade creation time, before any host freeze. */\nexport function defineEmbedStoppedFlag(\n\tada: object,\n\treadStopped: () => boolean,\n): void {\n\tObject.defineProperty(ada, EMBED_LIFECYCLE_STOPPED, {\n\t\tget: readStopped,\n\t\tenumerable: false,\n\t\tconfigurable: false,\n\t});\n}\n","import type { AdaMessagingClient } from \"../client/client\";\nimport type { AdaMessagingStartOptions } from \"../client/client-types\";\nimport type {\n\tAdaEmbedInterface,\n\tcreateAdaEmbedInterface,\n\tdispatchEmbedLoaderInitialActionQueue,\n\tdispatchEmbedLoaderInitialActionQueueForAtomicHandoff,\n} from \"../client/embed-interface\";\nimport { readEmbedStoppedFlag } from \"../client/embed-lifecycle\";\nimport type {\n\tmountAdaWebViewRuntime,\n\tresolveAdaWebViewRuntimeAssets,\n} from \"../mobile-webview-runtime\";\n\n/**\n * Production CDN root the loader resolves the SDK bootstrap from when no\n * `cdnBase` override is given. The npm package never pins a runtime version;\n * the bootstrap at this root resolves the current rollout at load time.\n */\nexport const DEFAULT_MESSAGING_CDN_BASE =\n\t\"https://messaging-assets.ada.support/\";\n\nexport const FALLBACK_MESSAGING_CDN_BASE =\n\t\"https://static.ada.support/messaging/\";\n\nconst SDK_BOOTSTRAP_FILENAME = \"sdk.js\";\n\n// The CDN pipeline deploys each main commit's runtime as an immutable\n// SHA-rooted entry (`<cdnBase>/<sha>/sdk/index.js`); the mutable `sdk.js`\n// bootstrap resolves the current rollout to one of those roots at load time.\n// A pin bypasses the bootstrap and imports one root directly.\nconst PINNED_SDK_ENTRY_PATH = \"sdk/index.js\";\n\n// Strict on purpose: the pin is interpolated into a CDN path, so only a full\n// lowercase 40-hex git SHA may pass (mirrors scripts/sdk.js's\n// VERSION_OVERRIDE_PATTERN security boundary, minus the short-SHA and pr-N\n// forms — the npm surface pins exactly what CDN_BUILD_SHA carries).\nconst PINNED_BUILD_SHA_PATTERN = /^[0-9a-f]{40}$/;\nconst UNSTAMPED_BUILD_SHA_PATTERN = /^0{40}$/;\n\n/** Why a {@link MessagingSdkLoadError} was raised. */\nexport type MessagingSdkLoadErrorCode =\n\t/**\n\t * The `cdnBase` option is not a valid `https:` URL (plain `http:` is\n\t * allowed only for loopback hosts).\n\t */\n\t| \"invalid_cdn_base\"\n\t/** The `pinBuildSha` option is not a full 40-character hex git SHA. */\n\t| \"invalid_build_sha\"\n\t/**\n\t * The `pinBuildSha` option is the unstamped 40-zero placeholder: this\n\t * copy of the package was built from the repository, not published, so\n\t * its `CDN_BUILD_SHA` names no CDN build.\n\t */\n\t| \"unstamped_build_sha\"\n\t/** The dynamic import of the CDN bootstrap failed (fetch or evaluation). */\n\t| \"sdk_import_failed\"\n\t/** The imported module does not expose the Ada Messaging SDK surface. */\n\t| \"sdk_module_invalid\";\n\n/** Typed failure raised by {@link loadMessagingSdk} and {@link loadAdaMessaging}. */\nexport class MessagingSdkLoadError extends Error {\n\treadonly code: MessagingSdkLoadErrorCode;\n\tdeclare readonly fallbackCause?: MessagingSdkLoadError;\n\n\tconstructor(\n\t\tmessage: string,\n\t\tcode: MessagingSdkLoadErrorCode,\n\t\tcause?: unknown,\n\t\tfallbackCause?: MessagingSdkLoadError,\n\t) {\n\t\tsuper(message);\n\t\tthis.name = \"MessagingSdkLoadError\";\n\t\tthis.code = code;\n\t\tif (cause !== undefined) {\n\t\t\tthis.cause = cause;\n\t\t}\n\t\tif (fallbackCause !== undefined) {\n\t\t\tObject.defineProperty(this, \"fallbackCause\", {\n\t\t\t\tvalue: fallbackCause,\n\t\t\t\tenumerable: true,\n\t\t\t});\n\t\t}\n\t}\n}\n\n/**\n * The programmatic messaging interface {@link loadAdaMessaging} resolves. An\n * alias of the runtime's `AdaEmbedInterface`, which keeps that name because it\n * is also the legacy `window.adaEmbed` compat facade.\n * Includes `selectQuickReply(messageId, index)` for Web SDK integrations.\n */\nexport type AdaMessagingInterface = AdaEmbedInterface;\n\n/**\n * The public surface of the CDN-resolved SDK module, as loaded from\n * `<cdnBase>/sdk.js`. Types only — the implementation always comes from the\n * CDN at load time and is never part of this npm package.\n */\nexport interface MessagingSdkModule {\n\tAdaMessagingClient: typeof AdaMessagingClient;\n\tcreateAdaEmbedInterface: typeof createAdaEmbedInterface;\n\tdispatchEmbedLoaderInitialActionQueue: typeof dispatchEmbedLoaderInitialActionQueue;\n\tdispatchEmbedLoaderInitialActionQueueForAtomicHandoff: typeof dispatchEmbedLoaderInitialActionQueueForAtomicHandoff;\n\tmountAdaWebViewRuntime: typeof mountAdaWebViewRuntime;\n\tresolveAdaWebViewRuntimeAssets: typeof resolveAdaWebViewRuntimeAssets;\n}\n\ntype ImportSdkModule = (url: string) => Promise<unknown>;\n\nexport interface LoadMessagingSdkOptions {\n\t/**\n\t * CDN root to resolve `sdk.js` from. Must be an `https:` URL; plain\n\t * `http:` is accepted only for loopback hosts (`localhost`, `127.0.0.1`,\n\t * `[::1]`, `*.localhost`) during local development. Defaults to the\n\t * production root ({@link DEFAULT_MESSAGING_CDN_BASE}). An explicit value,\n\t * including {@link FALLBACK_MESSAGING_CDN_BASE}, disables the automatic\n\t * static-root fallback.\n\t */\n\tcdnBase?: string;\n\t/**\n\t * Full 40-character git commit SHA of a deployed CDN build. When set, the\n\t * loader skips the rollout bootstrap and imports that build's immutable\n\t * entry (`<cdnBase>/<sha>/sdk/index.js`) directly. Pass the package's\n\t * `CDN_BUILD_SHA` export to pin the build associated with this npm\n\t * version. NOT recommended for production: a pinned runtime misses Ada's\n\t * fixes and rollouts, and may predate server contract changes. Composes\n\t * with `cdnBase` for staged validation.\n\t */\n\tpinBuildSha?: string;\n\t/**\n\t * Import seam for unit tests. Defaults to a native dynamic `import()` of\n\t * the resolved bootstrap URL.\n\t */\n\timportModule?: ImportSdkModule;\n}\n\n// Both annotations are load-bearing: bundlers rewrite bare dynamic imports,\n// and this specifier must reach the browser untouched so the runtime always\n// resolves from Ada's CDN. The npm build for this entry is unminified so the\n// annotations survive into the published output.\nconst defaultImportModule: ImportSdkModule = (url) =>\n\timport(/* webpackIgnore: true */ /* @vite-ignore */ url);\n\n// Keyed by import seam so production memoizes on the module-level default\n// while each injected test seam gets an isolated cache.\ninterface SdkLoaderState {\n\timports: Map<string, Promise<MessagingSdkModule>>;\n\tdefaultLoads: Map<string, Promise<MessagingSdkModule>>;\n}\n\nconst loadsByImporter = new WeakMap<ImportSdkModule, SdkLoaderState>();\n\n// Share the warning across independently bundled copies of this loader.\nconst FALLBACK_WARNING_KEY = Symbol.for(\"ada.messaging.sdk.fallbackWarning\");\nconst warningScope = globalThis as typeof globalThis & {\n\t[FALLBACK_WARNING_KEY]?: boolean;\n};\n\n// Mirrors the loopback semantics of the shared `isLoopbackHost` /\n// `validateMessagingEndpoint` (shared/utils/src/url.ts) and the bridge\n// loader's copy (packages/bridge/src/npm/loader.ts). Inlined because the\n// published loader must stay dependency-free; keep the host set in sync.\nconst LOOPBACK_HOSTS = new Set([\"localhost\", \"127.0.0.1\", \"[::1]\", \"::1\"]);\n\nfunction isLoopbackHostname(hostname: string): boolean {\n\tconst normalized = hostname.trim().toLowerCase();\n\t// `*.localhost` resolves to the loopback interface and is \"potentially\n\t// trustworthy\" per the Secure Contexts spec; no production host ends in\n\t// `.localhost`.\n\treturn LOOPBACK_HOSTS.has(normalized) || normalized.endsWith(\".localhost\");\n}\n\nfunction resolvePinnedBuildSha(pinBuildSha: string): string {\n\tconst sha = pinBuildSha.trim().toLowerCase();\n\tif (!PINNED_BUILD_SHA_PATTERN.test(sha)) {\n\t\tthrow new MessagingSdkLoadError(\n\t\t\t`The pinBuildSha option must be a full 40-character hex git SHA: \"${pinBuildSha}\".`,\n\t\t\t\"invalid_build_sha\",\n\t\t);\n\t}\n\tif (UNSTAMPED_BUILD_SHA_PATTERN.test(sha)) {\n\t\tthrow new MessagingSdkLoadError(\n\t\t\t\"The pinBuildSha option is the unstamped CDN_BUILD_SHA placeholder. Only the published npm package carries a stamped SHA; a repository or local build cannot pin a CDN build.\",\n\t\t\t\"unstamped_build_sha\",\n\t\t);\n\t}\n\treturn sha;\n}\n\n/**\n * The runtime this URL serves carries the SDK's security logic (endpoint\n * validation, session handling, the origin checks), so a cleartext transport\n * would let an on-path attacker replace it wholesale: `https:` is required,\n * with a loopback-only `http:` exception for local development.\n */\nfunction resolveSdkBootstrapUrl(\n\tcdnBase: string | undefined,\n\tpinBuildSha: string | undefined,\n): string {\n\tconst base = (cdnBase ?? DEFAULT_MESSAGING_CDN_BASE).trim();\n\t// Resolving against a base without a trailing slash would drop its last\n\t// path segment, so normalize before building the bootstrap URL.\n\tconst normalizedBase = base.endsWith(\"/\") ? base : `${base}/`;\n\tconst entryPath =\n\t\tpinBuildSha === undefined\n\t\t\t? SDK_BOOTSTRAP_FILENAME\n\t\t\t: `${resolvePinnedBuildSha(pinBuildSha)}/${PINNED_SDK_ENTRY_PATH}`;\n\tlet url: URL;\n\ttry {\n\t\turl = new URL(entryPath, normalizedBase);\n\t} catch (cause) {\n\t\tthrow new MessagingSdkLoadError(\n\t\t\t`The cdnBase option is not a valid URL: \"${base}\".`,\n\t\t\t\"invalid_cdn_base\",\n\t\t\tcause,\n\t\t);\n\t}\n\tconst isHttps = url.protocol === \"https:\";\n\tconst isLoopbackHttp =\n\t\turl.protocol === \"http:\" && isLoopbackHostname(url.hostname);\n\tif (!isHttps && !isLoopbackHttp) {\n\t\tthrow new MessagingSdkLoadError(\n\t\t\t`The cdnBase option must use https (plain http is allowed only for loopback hosts): \"${base}\".`,\n\t\t\t\"invalid_cdn_base\",\n\t\t);\n\t}\n\treturn url.toString();\n}\n\n// A partial CDN module (mid-deploy, or a rolled-back build missing a newer\n// export) must fail here as a typed sdk_module_invalid error, not later as a\n// TypeError on the first missing call — so every export is checked. The\n// `satisfies` clause rejects names that are not interface members; the\n// exhaustiveness type below is what forces this list to grow with it.\nconst REQUIRED_SDK_EXPORTS = [\n\t\"AdaMessagingClient\",\n\t\"createAdaEmbedInterface\",\n\t\"dispatchEmbedLoaderInitialActionQueue\",\n\t\"dispatchEmbedLoaderInitialActionQueueForAtomicHandoff\",\n\t\"mountAdaWebViewRuntime\",\n\t\"resolveAdaWebViewRuntimeAssets\",\n] as const satisfies readonly (keyof MessagingSdkModule)[];\n\n// Compile-time exhaustiveness: adding a MessagingSdkModule member without\n// listing it in REQUIRED_SDK_EXPORTS turns this type into `never`, failing\n// the `true` assignment below.\ntype AllSdkExportsListed =\n\tExclude<\n\t\tkeyof MessagingSdkModule,\n\t\t(typeof REQUIRED_SDK_EXPORTS)[number]\n\t> extends never\n\t\t? true\n\t\t: never;\nconst _allSdkExportsListed: AllSdkExportsListed = true;\nvoid _allSdkExportsListed;\n\nfunction isMessagingSdkModule(value: unknown): value is MessagingSdkModule {\n\tif (typeof value !== \"object\" || value === null) {\n\t\treturn false;\n\t}\n\tconst candidate = value as Record<string, unknown>;\n\treturn REQUIRED_SDK_EXPORTS.every(\n\t\t(key) => typeof candidate[key] === \"function\",\n\t);\n}\n\nasync function importSdkModule(\n\turl: string,\n\timportModule: ImportSdkModule,\n): Promise<MessagingSdkModule> {\n\tlet loaded: unknown;\n\ttry {\n\t\tloaded = await importModule(url);\n\t} catch (cause) {\n\t\tthrow new MessagingSdkLoadError(\n\t\t\t`The Ada Messaging SDK failed to load from ${url}.`,\n\t\t\t\"sdk_import_failed\",\n\t\t\tcause,\n\t\t);\n\t}\n\tif (!isMessagingSdkModule(loaded)) {\n\t\tthrow new MessagingSdkLoadError(\n\t\t\t`The module at ${url} does not expose the Ada Messaging SDK interface.`,\n\t\t\t\"sdk_module_invalid\",\n\t\t);\n\t}\n\treturn loaded;\n}\n\nfunction memoizeLoad(\n\tcache: Map<string, Promise<MessagingSdkModule>>,\n\turl: string,\n\tload: () => Promise<MessagingSdkModule>,\n): Promise<MessagingSdkModule> {\n\tconst existing = cache.get(url);\n\tif (existing) {\n\t\treturn existing;\n\t}\n\tconst pending = load();\n\tcache.set(url, pending);\n\tpending.catch(() => {\n\t\tif (cache.get(url) === pending) {\n\t\t\tcache.delete(url);\n\t\t}\n\t});\n\treturn pending;\n}\n\n/**\n * Load the Ada Messaging SDK module from Ada's CDN.\n *\n * The returned promise is memoized per resolved URL: concurrent and repeated\n * calls share one in-flight import. A failed load clears the memo so a later\n * call retries. Without `cdnBase`, an import failure at the default root is\n * retried once from {@link FALLBACK_MESSAGING_CDN_BASE}. Rejections are always\n * {@link MessagingSdkLoadError}.\n *\n * @example\n * const { createAdaEmbedInterface } = await loadMessagingSdk();\n */\nexport function loadMessagingSdk(\n\toptions: LoadMessagingSdkOptions = {},\n): Promise<MessagingSdkModule> {\n\tconst importModule = options.importModule ?? defaultImportModule;\n\tlet url: string;\n\tlet fallbackUrl: string | undefined;\n\ttry {\n\t\turl = resolveSdkBootstrapUrl(options.cdnBase, options.pinBuildSha);\n\t\tif (options.cdnBase === undefined) {\n\t\t\tfallbackUrl = resolveSdkBootstrapUrl(\n\t\t\t\tFALLBACK_MESSAGING_CDN_BASE,\n\t\t\t\toptions.pinBuildSha,\n\t\t\t);\n\t\t}\n\t} catch (error) {\n\t\treturn Promise.reject(error);\n\t}\n\n\tconst state = loadsByImporter.get(importModule) ?? {\n\t\timports: new Map<string, Promise<MessagingSdkModule>>(),\n\t\tdefaultLoads: new Map<string, Promise<MessagingSdkModule>>(),\n\t};\n\tloadsByImporter.set(importModule, state);\n\tconst load = (entryUrl: string) =>\n\t\tmemoizeLoad(state.imports, entryUrl, () =>\n\t\t\timportSdkModule(entryUrl, importModule),\n\t\t);\n\tif (fallbackUrl === undefined) {\n\t\treturn load(url);\n\t}\n\n\tconst retryUrl = fallbackUrl;\n\t// Keep fallback outcomes separate so explicit-root callers share the import,\n\t// but never inherit another caller's permission to retry a different root.\n\treturn memoizeLoad(state.defaultLoads, url, () =>\n\t\tload(url).catch(async (error: unknown) => {\n\t\t\tif (\n\t\t\t\t!(error instanceof MessagingSdkLoadError) ||\n\t\t\t\terror.code !== \"sdk_import_failed\"\n\t\t\t) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\t// CSP rejects import() without a network request, so this retry adds no\n\t\t\t// user-visible delay; retrying a genuine network failure once is acceptable too.\n\t\t\tlet module: MessagingSdkModule;\n\t\t\ttry {\n\t\t\t\tmodule = await load(retryUrl);\n\t\t\t} catch (cause) {\n\t\t\t\tif (!(cause instanceof MessagingSdkLoadError)) {\n\t\t\t\t\tthrow cause;\n\t\t\t\t}\n\t\t\t\tthrow new MessagingSdkLoadError(\n\t\t\t\t\tcause.code === \"sdk_import_failed\"\n\t\t\t\t\t\t? `The Ada Messaging SDK failed to load from both ${url} and ${retryUrl}.`\n\t\t\t\t\t\t: cause.message,\n\t\t\t\t\tcause.code,\n\t\t\t\t\terror,\n\t\t\t\t\tcause,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (!warningScope[FALLBACK_WARNING_KEY]) {\n\t\t\t\twarningScope[FALLBACK_WARNING_KEY] = true;\n\t\t\t\tconst cause = error.cause;\n\t\t\t\t// Browsers reject blocked, unreachable, or missing imports with TypeError.\n\t\t\t\t// An evaluation-time TypeError still looks like a fetch failure, as before;\n\t\t\t\t// this heuristic narrows diagnostic noise but cannot prove the cause.\n\t\t\t\twarnHost(\n\t\t\t\t\tcause instanceof TypeError\n\t\t\t\t\t\t? `Loaded the Messaging SDK from ${FALLBACK_MESSAGING_CDN_BASE} because the default root ${DEFAULT_MESSAGING_CDN_BASE} was blocked or unavailable. Add https://messaging-assets.ada.support to script-src, connect-src and frame-src, or pass cdnBase: \"${FALLBACK_MESSAGING_CDN_BASE}\".`\n\t\t\t\t\t\t: `Loaded the Messaging SDK from ${FALLBACK_MESSAGING_CDN_BASE} because the module at ${url} failed to evaluate (${describeRejection(cause)}). This is an Ada-side problem, not your host's CSP. Report it to Ada.`,\n\t\t\t\t\tcause,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn module;\n\t\t}),\n\t);\n}\n\n// Keyed by import seam like the module memo above: production memoizes on\n// the module-level default while each injected test seam gets an isolated\n// cache. `ada` is set when the promise resolves, so the stopped-interface\n// diagnostic can consult the resolved facade without wrapping it.\ninterface StartedInterfaceMemo {\n\tpromise: Promise<AdaMessagingInterface>;\n\tsettings: AdaMessagingStartOptions;\n\tada?: AdaMessagingInterface;\n}\n\nconst startedInterfaceByImporter = new WeakMap<\n\tImportSdkModule,\n\tStartedInterfaceMemo\n>();\n\n// A rejection can be any value, including one that throws on String(); a\n// diagnostic must never turn a successful fallback into a rejected load.\nfunction describeRejection(cause: unknown): string {\n\ttry {\n\t\treturn cause instanceof Error\n\t\t\t? `${cause.name}: ${cause.message}`\n\t\t\t: String(cause);\n\t} catch {\n\t\treturn \"unknown error\";\n\t}\n}\n\n// Ungated like the runtime logger's dropped-host-value channel so host\n// configuration diagnostics remain visible without debug logging.\nfunction warnHost(message: string, cause?: unknown): void {\n\ttry {\n\t\t// biome-ignore lint/suspicious/noConsole: the loader's sanctioned host-page diagnostic sink\n\t\tconsole.warn(`[Ada] ${message}`, ...(cause === undefined ? [] : [cause]));\n\t} catch {\n\t\t// A host may replace console methods; diagnostics must not throw.\n\t}\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n\tif (typeof value !== \"object\" || value === null) {\n\t\treturn false;\n\t}\n\tconst prototype = Object.getPrototypeOf(value);\n\treturn prototype === Object.prototype || prototype === null;\n}\n\n// Structural equality over the settings surface. Two functions compare equal:\n// fresh inline callbacks on a re-run (React Strict Mode effects) are not a\n// settings change worth a warning. Exotic objects compare by reference.\nfunction settingsEqual(a: unknown, b: unknown): boolean {\n\tif (Object.is(a, b)) {\n\t\treturn true;\n\t}\n\tif (typeof a === \"function\" && typeof b === \"function\") {\n\t\treturn true;\n\t}\n\tif (Array.isArray(a) && Array.isArray(b)) {\n\t\treturn (\n\t\t\ta.length === b.length &&\n\t\t\ta.every((item, index) => settingsEqual(item, b[index]))\n\t\t);\n\t}\n\tif (isPlainObject(a) && isPlainObject(b)) {\n\t\tconst aKeys = Object.keys(a);\n\t\tconst bKeys = new Set(Object.keys(b));\n\t\treturn (\n\t\t\taKeys.length === bKeys.size &&\n\t\t\taKeys.every((key) => bKeys.has(key) && settingsEqual(a[key], b[key]))\n\t\t);\n\t}\n\treturn false;\n}\n\n// Observes the facade's symbol-keyed lifecycle getter (embed-lifecycle.ts)\n// instead of wrapping stop/start, so the customer's interface is never\n// mutated; a pinned runtime that predates the getter yields no flag and the\n// stopped-interface diagnostic is skipped rather than guessed.\nfunction isInterfaceStopped(ada: AdaMessagingInterface): boolean {\n\treturn readEmbedStoppedFlag(ada) === true;\n}\n\nasync function startAdaMessaging(\n\tsettings: AdaMessagingStartOptions,\n\toptions: LoadMessagingSdkOptions,\n): Promise<AdaMessagingInterface> {\n\tconst sdkModule = await loadMessagingSdk(options);\n\tconst ada = sdkModule.createAdaEmbedInterface();\n\tawait ada.start(settings);\n\treturn ada;\n}\n\n/**\n * Load the SDK, create the messaging interface, and start the widget —\n * the npm-first equivalent of the script-tag + `window.adaSettings` setup.\n *\n * One widget per page: the returned promise is memoized, so repeated and\n * concurrent calls resolve to the same interface and the first\n * call's settings win. A failed load or start clears the memo so a later\n * call retries.\n *\n * If the bot's web chat setting is off, startup resolves without mounting the\n * widget. The interface stays memoized. Enable web chat in the\n * bot's settings before calling `start(settings)` again.\n *\n * Manage the running widget through the returned interface:\n * `stop()` tears it down and a later `start(settings)` on the same interface\n * runs again. Calling {@link loadAdaMessaging} after `stop()` returns the\n * same stopped interface without restarting it. Both memo outcomes log a\n * console warning: ignored differing settings, and a resolved interface\n * whose widget was stopped by the host.\n *\n * Never assigns the interface to `window` or any other global: the returned\n * reference is the only handle, so hold it in module scope. A reference in\n * module scope is reachable only by your own code, never by other scripts on\n * the page.\n *\n * @example\n * // module scope: your code keeps the only reference\n * const ada = await loadAdaMessaging({\n * handle: \"my-bot\",\n * enableProgrammaticControl: true,\n * });\n * await ada.sendMessage(\"Hello\");\n */\nexport function loadAdaMessaging(\n\tsettings: AdaMessagingStartOptions,\n\toptions: LoadMessagingSdkOptions = {},\n): Promise<AdaMessagingInterface> {\n\tconst importModule = options.importModule ?? defaultImportModule;\n\tconst existing = startedInterfaceByImporter.get(importModule);\n\tif (existing) {\n\t\tif (!settingsEqual(settings, existing.settings)) {\n\t\t\twarnHost(\n\t\t\t\t\"loadAdaMessaging() was already called: the new settings are ignored and the existing interface is returned. To apply new settings, call stop() then start(settings) on it.\",\n\t\t\t);\n\t\t}\n\t\tif (existing.ada && isInterfaceStopped(existing.ada)) {\n\t\t\twarnHost(\n\t\t\t\t\"loadAdaMessaging() resolved an interface whose widget was stopped and never restarts it. Call start(settings) on it to run the widget again.\",\n\t\t\t);\n\t\t}\n\t\treturn existing.promise;\n\t}\n\tconst memo: StartedInterfaceMemo = {\n\t\tpromise: startAdaMessaging(settings, options),\n\t\tsettings,\n\t};\n\tstartedInterfaceByImporter.set(importModule, memo);\n\tmemo.promise.then(\n\t\t(ada) => {\n\t\t\tmemo.ada = ada;\n\t\t},\n\t\t() => {\n\t\t\tif (startedInterfaceByImporter.get(importModule) === memo) {\n\t\t\t\tstartedInterfaceByImporter.delete(importModule);\n\t\t\t}\n\t\t},\n\t);\n\treturn memo.promise;\n}\n"],"mappings":";;;;;;;;;;;AAWA,IAAM,uBAAuB,OAAO,UAAU;AAE9C,SAAS,YACR,QACA,MACA,OACO;CACP,OAAO,eAAe,QA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mB,KAAqC;CAChE,OAAO,qBAAqB,GAAG,MAAM;AACtC;AAEA,eAAe,kBACd,UACA,SACiC;CAEjC,MAAM,OAAM,MADY,iBAAiB,OAAO,EAAA,CAC1B,wBAAwB;CAC9C,MAAM,IAAI,MAAM,QAAQ;CACxB,OAAO;AACR;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA,SAAgB,iBACf,UACA,UAAmC,CAAC,GACH;CACjC,MAAM,eAAe,QAAQ,gBAAgB;CAC7C,MAAM,WAAW,2BAA2B,IAAI,YAAY;CAC5D,IAAI,UAAU;EACb,IAAI,CAAC,cAAc,UAAU,SAAS,QAAQ,GAC7C,SACC,4KACD;EAED,IAAI,SAAS,OAAO,mBAAmB,SAAS,GAAG,GAClD,SACC,8IACD;EAED,OAAO,SAAS;CACjB;CACA,MAAM,OAA6B;EAClC,SAAS,kBAAkB,UAAU,OAAO;EAC5C;CACD;CACA,2BAA2B,IAAI,cAAc,IAAI;CACjD,KAAK,QAAQ,MACX,QAAQ;EACR,KAAK,MAAM;CACZ,SACM;EACL,IAAI,2BAA2B,IAAI,YAAY,MAAM,MACpD,2BAA2B,OAAO,YAAY;CAEhD,CACD;CACA,OAAO,KAAK;AACb"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../shared/utils/src/browser-polyfills.ts","../../src/npm/build-info.ts","../../src/client/embed-lifecycle.ts","../../src/npm/loader.ts"],"sourcesContent":["/**\n * Defence in depth for engines just below the declared browser floor.\n * The floor is defined in `messaging/vite.browser-targets.mjs`.\n *\n * Internal Ada code should prefer direct helpers, such as `hasOwn(...)` from\n * `guards.ts`. Every Ada bundle includes these fallbacks, including the host-page\n * SDK. These fallbacks also ship inside the customer-held npm tarballs of the SDK\n * and bridge. Each fallback defines a member only when it is missing. These\n * fallbacks do not extend browser support below the floor required by the shipped CSS.\n */\n\nconst objectHasOwnProperty = Object.prototype.hasOwnProperty;\n\nfunction defineValue(\n\ttarget: object,\n\tname: PropertyKey,\n\tvalue: (...args: unknown[]) => unknown,\n): void {\n\tObject.defineProperty(target, name, {\n\t\tvalue,\n\t\tconfigurable: true,\n\t\twritable: true,\n\t});\n}\n\nif (!Object.hasOwn) {\n\tdefineValue(Object, \"hasOwn\", (object: unknown, key: unknown) => {\n\t\tif (object == null) {\n\t\t\tthrow new TypeError(\n\t\t\t\t\"ada browser-polyfills: Cannot convert undefined or null to object\",\n\t\t\t);\n\t\t}\n\t\treturn objectHasOwnProperty.call(Object(object), key as PropertyKey);\n\t});\n}\n\nfunction at<T>(\n\tthis: { length: number; [index: number]: T },\n\tindex: unknown,\n): T | undefined {\n\tconst length = Math.trunc(Number(this.length)) || 0;\n\tlet relativeIndex = Math.trunc(Number(index)) || 0;\n\tif (relativeIndex < 0) {\n\t\trelativeIndex += length;\n\t}\n\treturn relativeIndex < 0 || relativeIndex >= length\n\t\t? undefined\n\t\t: this[relativeIndex];\n}\n\nfunction stringAt(this: string, index: unknown): string | undefined {\n\tconst value = String(this);\n\tconst length = value.length;\n\tlet relativeIndex = Math.trunc(Number(index)) || 0;\n\tif (relativeIndex < 0) {\n\t\trelativeIndex += length;\n\t}\n\treturn relativeIndex < 0 || relativeIndex >= length\n\t\t? undefined\n\t\t: value.charAt(relativeIndex);\n}\n\nconst typedArrayConstructors = [\n\tglobalThis.Int8Array,\n\tglobalThis.Uint8Array,\n\tglobalThis.Uint8ClampedArray,\n\tglobalThis.Int16Array,\n\tglobalThis.Uint16Array,\n\tglobalThis.Int32Array,\n\tglobalThis.Uint32Array,\n\tglobalThis.Float32Array,\n\tglobalThis.Float64Array,\n\tglobalThis.BigInt64Array,\n\tglobalThis.BigUint64Array,\n].filter(Boolean);\n\nif (!Array.prototype.at) {\n\tdefineValue(Array.prototype, \"at\", at);\n}\n\nif (!String.prototype.at) {\n\tdefineValue(String.prototype, \"at\", stringAt);\n}\n\nfor (const TypedArrayConstructor of typedArrayConstructors) {\n\tconst prototype = TypedArrayConstructor.prototype;\n\tif (!prototype.at) {\n\t\tdefineValue(prototype, \"at\", at);\n\t}\n}\n","// The repo copy carries the 40-zero placeholder; the publish workflow\n// (.github/workflows/messaging-publish-web-packages.yml) stamps the real\n// commit SHA into the built output via scripts/stamp-cdn-build-sha.mjs and\n// verifies the packed tarball before `npm publish`. Keep the placeholder as\n// a single 40-zero string literal: the stamp is a same-length text\n// replacement, so source maps stay valid.\nconst GIT_SHA_PATTERN = /^[0-9a-f]{40}$/;\nconst UNSTAMPED_SHA_PATTERN = /^0{40}$/;\n\n/**\n * Git commit SHA of the monorepo commit this npm version was published from.\n * The CDN pipeline deploys each main commit's runtime under an immutable\n * SHA root, so this value names the CDN build associated with this npm\n * version. Pass it as the `pinBuildSha` loader option to load exactly that\n * runtime build — not recommended for production (see the README).\n *\n * In the repository, and in any locally built copy, the value is the\n * unstamped 40-zero placeholder ({@link isCdnBuildShaStamped} returns\n * `false`); only published tarballs carry a real SHA.\n */\nexport const CDN_BUILD_SHA: string = \"96a4d978600322e3d174666bc70e2b3d912f13bb\";\n\n/**\n * Whether `sha` (default {@link CDN_BUILD_SHA}) is a stamped full git commit\n * SHA rather than the unstamped repo placeholder.\n */\nexport function isCdnBuildShaStamped(sha: string = CDN_BUILD_SHA): boolean {\n\tconst normalized = sha.trim().toLowerCase();\n\treturn (\n\t\tGIT_SHA_PATTERN.test(normalized) && !UNSTAMPED_SHA_PATTERN.test(normalized)\n\t);\n}\n","/**\n * Lifecycle channel between `createAdaEmbedInterface` and the npm loader's\n * memo: a non-enumerable getter over closure state, so the loader never\n * mutates the public surface and `Object.freeze` on the facade still works.\n * `Symbol.for` because the loader and the CDN runtime are separate builds;\n * a runtime that predates the getter yields `undefined` — degrade gracefully.\n */\nexport const EMBED_LIFECYCLE_STOPPED = Symbol.for(\n\t\"ada-cx/messaging-sdk/embed-stopped\",\n);\n\n/** Read the host-initiated stop flag; `undefined` when the runtime predates it. */\nexport function readEmbedStoppedFlag(ada: object): boolean | undefined {\n\tconst value = (ada as Record<symbol, unknown>)[EMBED_LIFECYCLE_STOPPED];\n\treturn typeof value === \"boolean\" ? value : undefined;\n}\n\n/** Define the getter at facade creation time, before any host freeze. */\nexport function defineEmbedStoppedFlag(\n\tada: object,\n\treadStopped: () => boolean,\n): void {\n\tObject.defineProperty(ada, EMBED_LIFECYCLE_STOPPED, {\n\t\tget: readStopped,\n\t\tenumerable: false,\n\t\tconfigurable: false,\n\t});\n}\n","import type { AdaMessagingClient } from \"../client/client\";\nimport type { AdaMessagingStartOptions } from \"../client/client-types\";\nimport type {\n\tAdaEmbedInterface,\n\tcreateAdaEmbedInterface,\n\tdispatchEmbedLoaderInitialActionQueue,\n\tdispatchEmbedLoaderInitialActionQueueForAtomicHandoff,\n} from \"../client/embed-interface\";\nimport { readEmbedStoppedFlag } from \"../client/embed-lifecycle\";\nimport type {\n\tmountAdaWebViewRuntime,\n\tresolveAdaWebViewRuntimeAssets,\n} from \"../mobile-webview-runtime\";\n\n/**\n * Production CDN root the loader resolves the SDK bootstrap from when no\n * `cdnBase` override is given. The npm package never pins a runtime version;\n * the bootstrap at this root resolves the current rollout at load time.\n */\nexport const DEFAULT_MESSAGING_CDN_BASE =\n\t\"https://messaging-assets.ada.support/\";\n\nexport const FALLBACK_MESSAGING_CDN_BASE =\n\t\"https://static.ada.support/messaging/\";\n\nconst SDK_BOOTSTRAP_FILENAME = \"sdk.js\";\n\n// The CDN pipeline deploys each main commit's runtime as an immutable\n// SHA-rooted entry (`<cdnBase>/<sha>/sdk/index.js`); the mutable `sdk.js`\n// bootstrap resolves the current rollout to one of those roots at load time.\n// A pin bypasses the bootstrap and imports one root directly.\nconst PINNED_SDK_ENTRY_PATH = \"sdk/index.js\";\n\n// Strict on purpose: the pin is interpolated into a CDN path, so only a full\n// lowercase 40-hex git SHA may pass (mirrors scripts/sdk.js's\n// VERSION_OVERRIDE_PATTERN security boundary, minus the short-SHA and pr-N\n// forms — the npm surface pins exactly what CDN_BUILD_SHA carries).\nconst PINNED_BUILD_SHA_PATTERN = /^[0-9a-f]{40}$/;\nconst UNSTAMPED_BUILD_SHA_PATTERN = /^0{40}$/;\n\n/** Why a {@link MessagingSdkLoadError} was raised. */\nexport type MessagingSdkLoadErrorCode =\n\t/**\n\t * The `cdnBase` option is not a valid `https:` URL (plain `http:` is\n\t * allowed only for loopback hosts).\n\t */\n\t| \"invalid_cdn_base\"\n\t/** The `pinBuildSha` option is not a full 40-character hex git SHA. */\n\t| \"invalid_build_sha\"\n\t/**\n\t * The `pinBuildSha` option is the unstamped 40-zero placeholder: this\n\t * copy of the package was built from the repository, not published, so\n\t * its `CDN_BUILD_SHA` names no CDN build.\n\t */\n\t| \"unstamped_build_sha\"\n\t/** The dynamic import of the CDN bootstrap failed (fetch or evaluation). */\n\t| \"sdk_import_failed\"\n\t/** The imported module does not expose the Ada Messaging SDK surface. */\n\t| \"sdk_module_invalid\";\n\n/** Typed failure raised by {@link loadMessagingSdk} and {@link loadAdaMessaging}. */\nexport class MessagingSdkLoadError extends Error {\n\treadonly code: MessagingSdkLoadErrorCode;\n\tdeclare readonly fallbackCause?: MessagingSdkLoadError;\n\n\tconstructor(\n\t\tmessage: string,\n\t\tcode: MessagingSdkLoadErrorCode,\n\t\tcause?: unknown,\n\t\tfallbackCause?: MessagingSdkLoadError,\n\t) {\n\t\tsuper(message);\n\t\tthis.name = \"MessagingSdkLoadError\";\n\t\tthis.code = code;\n\t\tif (cause !== undefined) {\n\t\t\tthis.cause = cause;\n\t\t}\n\t\tif (fallbackCause !== undefined) {\n\t\t\tObject.defineProperty(this, \"fallbackCause\", {\n\t\t\t\tvalue: fallbackCause,\n\t\t\t\tenumerable: true,\n\t\t\t});\n\t\t}\n\t}\n}\n\n/**\n * The programmatic messaging interface {@link loadAdaMessaging} resolves. An\n * alias of the runtime's `AdaEmbedInterface`, which keeps that name because it\n * is also the legacy `window.adaEmbed` compat facade.\n * Includes `selectQuickReply(messageId, index)` for Web SDK integrations.\n */\nexport type AdaMessagingInterface = AdaEmbedInterface;\n\n/**\n * The public surface of the CDN-resolved SDK module, as loaded from\n * `<cdnBase>/sdk.js`. Types only — the implementation always comes from the\n * CDN at load time and is never part of this npm package.\n */\nexport interface MessagingSdkModule {\n\tAdaMessagingClient: typeof AdaMessagingClient;\n\tcreateAdaEmbedInterface: typeof createAdaEmbedInterface;\n\tdispatchEmbedLoaderInitialActionQueue: typeof dispatchEmbedLoaderInitialActionQueue;\n\tdispatchEmbedLoaderInitialActionQueueForAtomicHandoff: typeof dispatchEmbedLoaderInitialActionQueueForAtomicHandoff;\n\tmountAdaWebViewRuntime: typeof mountAdaWebViewRuntime;\n\tresolveAdaWebViewRuntimeAssets: typeof resolveAdaWebViewRuntimeAssets;\n}\n\ntype ImportSdkModule = (url: string) => Promise<unknown>;\n\nexport interface LoadMessagingSdkOptions {\n\t/**\n\t * CDN root to resolve `sdk.js` from. Must be an `https:` URL; plain\n\t * `http:` is accepted only for loopback hosts (`localhost`, `127.0.0.1`,\n\t * `[::1]`, `*.localhost`) during local development. Defaults to the\n\t * production root ({@link DEFAULT_MESSAGING_CDN_BASE}). An explicit value,\n\t * including {@link FALLBACK_MESSAGING_CDN_BASE}, disables the automatic\n\t * static-root fallback.\n\t */\n\tcdnBase?: string;\n\t/**\n\t * Full 40-character git commit SHA of a deployed CDN build. When set, the\n\t * loader skips the rollout bootstrap and imports that build's immutable\n\t * entry (`<cdnBase>/<sha>/sdk/index.js`) directly. Pass the package's\n\t * `CDN_BUILD_SHA` export to pin the build associated with this npm\n\t * version. NOT recommended for production: a pinned runtime misses Ada's\n\t * fixes and rollouts, and may predate server contract changes. Composes\n\t * with `cdnBase` for staged validation.\n\t */\n\tpinBuildSha?: string;\n\t/**\n\t * Import seam for unit tests. Defaults to a native dynamic `import()` of\n\t * the resolved bootstrap URL.\n\t */\n\timportModule?: ImportSdkModule;\n}\n\n// Both annotations are load-bearing: bundlers rewrite bare dynamic imports,\n// and this specifier must reach the browser untouched so the runtime always\n// resolves from Ada's CDN. The npm build for this entry is unminified so the\n// annotations survive into the published output.\nconst defaultImportModule: ImportSdkModule = (url) =>\n\timport(/* webpackIgnore: true */ /* @vite-ignore */ url);\n\n// Keyed by import seam so production memoizes on the module-level default\n// while each injected test seam gets an isolated cache.\ninterface SdkLoaderState {\n\timports: Map<string, Promise<MessagingSdkModule>>;\n\tdefaultLoads: Map<string, Promise<MessagingSdkModule>>;\n}\n\nconst loadsByImporter = new WeakMap<ImportSdkModule, SdkLoaderState>();\n\n// Share the warning across independently bundled copies of this loader.\nconst FALLBACK_WARNING_KEY = Symbol.for(\"ada.messaging.sdk.fallbackWarning\");\nconst warningScope = globalThis as typeof globalThis & {\n\t[FALLBACK_WARNING_KEY]?: boolean;\n};\n\n// Mirrors the loopback semantics of the shared `isLoopbackHost` /\n// `validateMessagingEndpoint` (shared/utils/src/url.ts) and the bridge\n// loader's copy (packages/bridge/src/npm/loader.ts). Inlined because the\n// published loader must stay dependency-free; keep the host set in sync.\nconst LOOPBACK_HOSTS = new Set([\"localhost\", \"127.0.0.1\", \"[::1]\", \"::1\"]);\n\nfunction isLoopbackHostname(hostname: string): boolean {\n\tconst normalized = hostname.trim().toLowerCase();\n\t// `*.localhost` resolves to the loopback interface and is \"potentially\n\t// trustworthy\" per the Secure Contexts spec; no production host ends in\n\t// `.localhost`.\n\treturn LOOPBACK_HOSTS.has(normalized) || normalized.endsWith(\".localhost\");\n}\n\nfunction resolvePinnedBuildSha(pinBuildSha: string): string {\n\tconst sha = pinBuildSha.trim().toLowerCase();\n\tif (!PINNED_BUILD_SHA_PATTERN.test(sha)) {\n\t\tthrow new MessagingSdkLoadError(\n\t\t\t`The pinBuildSha option must be a full 40-character hex git SHA: \"${pinBuildSha}\".`,\n\t\t\t\"invalid_build_sha\",\n\t\t);\n\t}\n\tif (UNSTAMPED_BUILD_SHA_PATTERN.test(sha)) {\n\t\tthrow new MessagingSdkLoadError(\n\t\t\t\"The pinBuildSha option is the unstamped CDN_BUILD_SHA placeholder. Only the published npm package carries a stamped SHA; a repository or local build cannot pin a CDN build.\",\n\t\t\t\"unstamped_build_sha\",\n\t\t);\n\t}\n\treturn sha;\n}\n\n/**\n * The runtime this URL serves carries the SDK's security logic (endpoint\n * validation, session handling, the origin checks), so a cleartext transport\n * would let an on-path attacker replace it wholesale: `https:` is required,\n * with a loopback-only `http:` exception for local development.\n */\nfunction resolveSdkBootstrapUrl(\n\tcdnBase: string | undefined,\n\tpinBuildSha: string | undefined,\n): string {\n\tconst base = (cdnBase ?? DEFAULT_MESSAGING_CDN_BASE).trim();\n\t// Resolving against a base without a trailing slash would drop its last\n\t// path segment, so normalize before building the bootstrap URL.\n\tconst normalizedBase = base.endsWith(\"/\") ? base : `${base}/`;\n\tconst entryPath =\n\t\tpinBuildSha === undefined\n\t\t\t? SDK_BOOTSTRAP_FILENAME\n\t\t\t: `${resolvePinnedBuildSha(pinBuildSha)}/${PINNED_SDK_ENTRY_PATH}`;\n\tlet url: URL;\n\ttry {\n\t\turl = new URL(entryPath, normalizedBase);\n\t} catch (cause) {\n\t\tthrow new MessagingSdkLoadError(\n\t\t\t`The cdnBase option is not a valid URL: \"${base}\".`,\n\t\t\t\"invalid_cdn_base\",\n\t\t\tcause,\n\t\t);\n\t}\n\tconst isHttps = url.protocol === \"https:\";\n\tconst isLoopbackHttp =\n\t\turl.protocol === \"http:\" && isLoopbackHostname(url.hostname);\n\tif (!isHttps && !isLoopbackHttp) {\n\t\tthrow new MessagingSdkLoadError(\n\t\t\t`The cdnBase option must use https (plain http is allowed only for loopback hosts): \"${base}\".`,\n\t\t\t\"invalid_cdn_base\",\n\t\t);\n\t}\n\treturn url.toString();\n}\n\n// A partial CDN module (mid-deploy, or a rolled-back build missing a newer\n// export) must fail here as a typed sdk_module_invalid error, not later as a\n// TypeError on the first missing call — so every export is checked. The\n// `satisfies` clause rejects names that are not interface members; the\n// exhaustiveness type below is what forces this list to grow with it.\nconst REQUIRED_SDK_EXPORTS = [\n\t\"AdaMessagingClient\",\n\t\"createAdaEmbedInterface\",\n\t\"dispatchEmbedLoaderInitialActionQueue\",\n\t\"dispatchEmbedLoaderInitialActionQueueForAtomicHandoff\",\n\t\"mountAdaWebViewRuntime\",\n\t\"resolveAdaWebViewRuntimeAssets\",\n] as const satisfies readonly (keyof MessagingSdkModule)[];\n\n// Compile-time exhaustiveness: adding a MessagingSdkModule member without\n// listing it in REQUIRED_SDK_EXPORTS turns this type into `never`, failing\n// the `true` assignment below.\ntype AllSdkExportsListed =\n\tExclude<\n\t\tkeyof MessagingSdkModule,\n\t\t(typeof REQUIRED_SDK_EXPORTS)[number]\n\t> extends never\n\t\t? true\n\t\t: never;\nconst _allSdkExportsListed: AllSdkExportsListed = true;\nvoid _allSdkExportsListed;\n\nfunction isMessagingSdkModule(value: unknown): value is MessagingSdkModule {\n\tif (typeof value !== \"object\" || value === null) {\n\t\treturn false;\n\t}\n\tconst candidate = value as Record<string, unknown>;\n\treturn REQUIRED_SDK_EXPORTS.every(\n\t\t(key) => typeof candidate[key] === \"function\",\n\t);\n}\n\nasync function importSdkModule(\n\turl: string,\n\timportModule: ImportSdkModule,\n): Promise<MessagingSdkModule> {\n\tlet loaded: unknown;\n\ttry {\n\t\tloaded = await importModule(url);\n\t} catch (cause) {\n\t\tthrow new MessagingSdkLoadError(\n\t\t\t`The Ada Messaging SDK failed to load from ${url}.`,\n\t\t\t\"sdk_import_failed\",\n\t\t\tcause,\n\t\t);\n\t}\n\tif (!isMessagingSdkModule(loaded)) {\n\t\tthrow new MessagingSdkLoadError(\n\t\t\t`The module at ${url} does not expose the Ada Messaging SDK interface.`,\n\t\t\t\"sdk_module_invalid\",\n\t\t);\n\t}\n\treturn loaded;\n}\n\nfunction memoizeLoad(\n\tcache: Map<string, Promise<MessagingSdkModule>>,\n\turl: string,\n\tload: () => Promise<MessagingSdkModule>,\n): Promise<MessagingSdkModule> {\n\tconst existing = cache.get(url);\n\tif (existing) {\n\t\treturn existing;\n\t}\n\tconst pending = load();\n\tcache.set(url, pending);\n\tpending.catch(() => {\n\t\tif (cache.get(url) === pending) {\n\t\t\tcache.delete(url);\n\t\t}\n\t});\n\treturn pending;\n}\n\n/**\n * Load the Ada Messaging SDK module from Ada's CDN.\n *\n * The returned promise is memoized per resolved URL: concurrent and repeated\n * calls share one in-flight import. A failed load clears the memo so a later\n * call retries. Without `cdnBase`, an import failure at the default root is\n * retried once from {@link FALLBACK_MESSAGING_CDN_BASE}. Rejections are always\n * {@link MessagingSdkLoadError}.\n *\n * @example\n * const { createAdaEmbedInterface } = await loadMessagingSdk();\n */\nexport function loadMessagingSdk(\n\toptions: LoadMessagingSdkOptions = {},\n): Promise<MessagingSdkModule> {\n\tconst importModule = options.importModule ?? defaultImportModule;\n\tlet url: string;\n\tlet fallbackUrl: string | undefined;\n\ttry {\n\t\turl = resolveSdkBootstrapUrl(options.cdnBase, options.pinBuildSha);\n\t\tif (options.cdnBase === undefined) {\n\t\t\tfallbackUrl = resolveSdkBootstrapUrl(\n\t\t\t\tFALLBACK_MESSAGING_CDN_BASE,\n\t\t\t\toptions.pinBuildSha,\n\t\t\t);\n\t\t}\n\t} catch (error) {\n\t\treturn Promise.reject(error);\n\t}\n\n\tconst state = loadsByImporter.get(importModule) ?? {\n\t\timports: new Map<string, Promise<MessagingSdkModule>>(),\n\t\tdefaultLoads: new Map<string, Promise<MessagingSdkModule>>(),\n\t};\n\tloadsByImporter.set(importModule, state);\n\tconst load = (entryUrl: string) =>\n\t\tmemoizeLoad(state.imports, entryUrl, () =>\n\t\t\timportSdkModule(entryUrl, importModule),\n\t\t);\n\tif (fallbackUrl === undefined) {\n\t\treturn load(url);\n\t}\n\n\tconst retryUrl = fallbackUrl;\n\t// Keep fallback outcomes separate so explicit-root callers share the import,\n\t// but never inherit another caller's permission to retry a different root.\n\treturn memoizeLoad(state.defaultLoads, url, () =>\n\t\tload(url).catch(async (error: unknown) => {\n\t\t\tif (\n\t\t\t\t!(error instanceof MessagingSdkLoadError) ||\n\t\t\t\terror.code !== \"sdk_import_failed\"\n\t\t\t) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\t// CSP rejects import() without a network request, so this retry adds no\n\t\t\t// user-visible delay; retrying a genuine network failure once is acceptable too.\n\t\t\tlet module: MessagingSdkModule;\n\t\t\ttry {\n\t\t\t\tmodule = await load(retryUrl);\n\t\t\t} catch (cause) {\n\t\t\t\tif (!(cause instanceof MessagingSdkLoadError)) {\n\t\t\t\t\tthrow cause;\n\t\t\t\t}\n\t\t\t\tthrow new MessagingSdkLoadError(\n\t\t\t\t\tcause.code === \"sdk_import_failed\"\n\t\t\t\t\t\t? `The Ada Messaging SDK failed to load from both ${url} and ${retryUrl}.`\n\t\t\t\t\t\t: cause.message,\n\t\t\t\t\tcause.code,\n\t\t\t\t\terror,\n\t\t\t\t\tcause,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (!warningScope[FALLBACK_WARNING_KEY]) {\n\t\t\t\twarningScope[FALLBACK_WARNING_KEY] = true;\n\t\t\t\tconst cause = error.cause;\n\t\t\t\t// Browsers reject blocked, unreachable, or missing imports with TypeError.\n\t\t\t\t// An evaluation-time TypeError still looks like a fetch failure, as before;\n\t\t\t\t// this heuristic narrows diagnostic noise but cannot prove the cause.\n\t\t\t\twarnHost(\n\t\t\t\t\tcause instanceof TypeError\n\t\t\t\t\t\t? `Loaded the Messaging SDK from ${FALLBACK_MESSAGING_CDN_BASE} because the default root ${DEFAULT_MESSAGING_CDN_BASE} was blocked or unavailable. Add https://messaging-assets.ada.support to script-src, connect-src and frame-src, or pass cdnBase: \"${FALLBACK_MESSAGING_CDN_BASE}\".`\n\t\t\t\t\t\t: `Loaded the Messaging SDK from ${FALLBACK_MESSAGING_CDN_BASE} because the module at ${url} failed to evaluate (${describeRejection(cause)}). This is an Ada-side problem, not your host's CSP. Report it to Ada.`,\n\t\t\t\t\tcause,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn module;\n\t\t}),\n\t);\n}\n\n// Keyed by import seam like the module memo above: production memoizes on\n// the module-level default while each injected test seam gets an isolated\n// cache. `ada` is set when the promise resolves, so the stopped-interface\n// diagnostic can consult the resolved facade without wrapping it.\ninterface StartedInterfaceMemo {\n\tpromise: Promise<AdaMessagingInterface>;\n\tsettings: AdaMessagingStartOptions;\n\tada?: AdaMessagingInterface;\n}\n\nconst startedInterfaceByImporter = new WeakMap<\n\tImportSdkModule,\n\tStartedInterfaceMemo\n>();\n\n// A rejection can be any value, including one that throws on String(); a\n// diagnostic must never turn a successful fallback into a rejected load.\nfunction describeRejection(cause: unknown): string {\n\ttry {\n\t\treturn cause instanceof Error\n\t\t\t? `${cause.name}: ${cause.message}`\n\t\t\t: String(cause);\n\t} catch {\n\t\treturn \"unknown error\";\n\t}\n}\n\n// Ungated like the runtime logger's dropped-host-value channel so host\n// configuration diagnostics remain visible without debug logging.\nfunction warnHost(message: string, cause?: unknown): void {\n\ttry {\n\t\t// biome-ignore lint/suspicious/noConsole: the loader's sanctioned host-page diagnostic sink\n\t\tconsole.warn(`[Ada] ${message}`, ...(cause === undefined ? [] : [cause]));\n\t} catch {\n\t\t// A host may replace console methods; diagnostics must not throw.\n\t}\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n\tif (typeof value !== \"object\" || value === null) {\n\t\treturn false;\n\t}\n\tconst prototype = Object.getPrototypeOf(value);\n\treturn prototype === Object.prototype || prototype === null;\n}\n\n// Structural equality over the settings surface. Two functions compare equal:\n// fresh inline callbacks on a re-run (React Strict Mode effects) are not a\n// settings change worth a warning. Exotic objects compare by reference.\nfunction settingsEqual(a: unknown, b: unknown): boolean {\n\tif (Object.is(a, b)) {\n\t\treturn true;\n\t}\n\tif (typeof a === \"function\" && typeof b === \"function\") {\n\t\treturn true;\n\t}\n\tif (Array.isArray(a) && Array.isArray(b)) {\n\t\treturn (\n\t\t\ta.length === b.length &&\n\t\t\ta.every((item, index) => settingsEqual(item, b[index]))\n\t\t);\n\t}\n\tif (isPlainObject(a) && isPlainObject(b)) {\n\t\tconst aKeys = Object.keys(a);\n\t\tconst bKeys = new Set(Object.keys(b));\n\t\treturn (\n\t\t\taKeys.length === bKeys.size &&\n\t\t\taKeys.every((key) => bKeys.has(key) && settingsEqual(a[key], b[key]))\n\t\t);\n\t}\n\treturn false;\n}\n\n// Observes the facade's symbol-keyed lifecycle getter (embed-lifecycle.ts)\n// instead of wrapping stop/start, so the customer's interface is never\n// mutated; a pinned runtime that predates the getter yields no flag and the\n// stopped-interface diagnostic is skipped rather than guessed.\nfunction isInterfaceStopped(ada: AdaMessagingInterface): boolean {\n\treturn readEmbedStoppedFlag(ada) === true;\n}\n\nasync function startAdaMessaging(\n\tsettings: AdaMessagingStartOptions,\n\toptions: LoadMessagingSdkOptions,\n): Promise<AdaMessagingInterface> {\n\tconst sdkModule = await loadMessagingSdk(options);\n\tconst ada = sdkModule.createAdaEmbedInterface();\n\tawait ada.start(settings);\n\treturn ada;\n}\n\n/**\n * Load the SDK, create the messaging interface, and start the widget —\n * the npm-first equivalent of the script-tag + `window.adaSettings` setup.\n *\n * One widget per page: the returned promise is memoized, so repeated and\n * concurrent calls resolve to the same interface and the first\n * call's settings win. A failed load or start clears the memo so a later\n * call retries.\n *\n * If the bot's web chat setting is off, startup resolves without mounting the\n * widget. The interface stays memoized. Enable web chat in the\n * bot's settings before calling `start(settings)` again.\n *\n * Manage the running widget through the returned interface:\n * `stop()` tears it down and a later `start(settings)` on the same interface\n * runs again. Calling {@link loadAdaMessaging} after `stop()` returns the\n * same stopped interface without restarting it. Both memo outcomes log a\n * console warning: ignored differing settings, and a resolved interface\n * whose widget was stopped by the host.\n *\n * Never assigns the interface to `window` or any other global: the returned\n * reference is the only handle, so hold it in module scope. A reference in\n * module scope is reachable only by your own code, never by other scripts on\n * the page.\n *\n * @example\n * // module scope: your code keeps the only reference\n * const ada = await loadAdaMessaging({\n * handle: \"my-bot\",\n * enableProgrammaticControl: true,\n * });\n * await ada.sendMessage(\"Hello\");\n */\nexport function loadAdaMessaging(\n\tsettings: AdaMessagingStartOptions,\n\toptions: LoadMessagingSdkOptions = {},\n): Promise<AdaMessagingInterface> {\n\tconst importModule = options.importModule ?? defaultImportModule;\n\tconst existing = startedInterfaceByImporter.get(importModule);\n\tif (existing) {\n\t\tif (!settingsEqual(settings, existing.settings)) {\n\t\t\twarnHost(\n\t\t\t\t\"loadAdaMessaging() was already called: the new settings are ignored and the existing interface is returned. To apply new settings, call stop() then start(settings) on it.\",\n\t\t\t);\n\t\t}\n\t\tif (existing.ada && isInterfaceStopped(existing.ada)) {\n\t\t\twarnHost(\n\t\t\t\t\"loadAdaMessaging() resolved an interface whose widget was stopped and never restarts it. Call start(settings) on it to run the widget again.\",\n\t\t\t);\n\t\t}\n\t\treturn existing.promise;\n\t}\n\tconst memo: StartedInterfaceMemo = {\n\t\tpromise: startAdaMessaging(settings, options),\n\t\tsettings,\n\t};\n\tstartedInterfaceByImporter.set(importModule, memo);\n\tmemo.promise.then(\n\t\t(ada) => {\n\t\t\tmemo.ada = ada;\n\t\t},\n\t\t() => {\n\t\t\tif (startedInterfaceByImporter.get(importModule) === memo) {\n\t\t\t\tstartedInterfaceByImporter.delete(importModule);\n\t\t\t}\n\t\t},\n\t);\n\treturn memo.promise;\n}\n"],"mappings":";;;;;;;;;;;AAWA,IAAM,uBAAuB,OAAO,UAAU;AAE9C,SAAS,YACR,QACA,MACA,OACO;CACP,OAAO,eAAe,QAAQ,MAAM;EACnC;EACA,cAAc;EACd,UAAU;CACX,CAAC;AACF;AAEA,IAAI,CAAC,OAAO,QACX,YAAY,QAAQ,WAAW,QAAiB,QAAiB;CAChE,IAAI,UAAU,MACb,MAAM,IAAI,UACT,mEACD;CAED,OAAO,qBAAqB,KAAK,OAAO,MAAM,GAAG,GAAkB;AACpE,CAAC;AAGF,SAAS,GAER,OACgB;CAChB,MAAM,SAAS,KAAK,MAAM,OAAO,KAAK,MAAM,CAAC,KAAK;CAClD,IAAI,gBAAgB,KAAK,MAAM,OAAO,KAAK,CAAC,KAAK;CACjD,IAAI,gBAAgB,GACnB,iBAAiB;CAElB,OAAO,gBAAgB,KAAK,iBAAiB,SAC1C,KAAA,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BAAmB,SAAS,GAAG,GAClD,SACC,8IACD;EAED,OAAO,SAAS;CACjB;CACA,MAAM,OAA6B;EAClC,SAAS,kBAAkB,UAAU,OAAO;EAC5C;CACD;CACA,2BAA2B,IAAI,cAAc,IAAI;CACjD,KAAK,QAAQ,MACX,QAAQ;EACR,KAAK,MAAM;CACZ,SACM;EACL,IAAI,2BAA2B,IAAI,YAAY,MAAM,MACpD,2BAA2B,OAAO,YAAY;CAEhD,CACD;CACA,OAAO,KAAK;AACb"}
@@ -1,3 +1,3 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var O=Object.prototype.hasOwnProperty;function g(n,e,a){Object.defineProperty(n,e,{value:a,configurable:!0,writable:!0})}Object.hasOwn||g(Object,"hasOwn",(n,e)=>{if(n==null)throw new TypeError("ada browser-polyfills: Cannot convert undefined or null to object");return O.call(Object(n),e)});function v(n){const e=Math.trunc(Number(this.length))||0;let a=Math.trunc(Number(n))||0;return a<0&&(a+=e),a<0||a>=e?void 0:this[a]}function T(n){const e=String(this),a=e.length;let r=Math.trunc(Number(n))||0;return r<0&&(r+=a),r<0||r>=a?void 0:e.charAt(r)}var C=[globalThis.Int8Array,globalThis.Uint8Array,globalThis.Uint8ClampedArray,globalThis.Int16Array,globalThis.Uint16Array,globalThis.Int32Array,globalThis.Uint32Array,globalThis.Float32Array,globalThis.Float64Array,globalThis.BigInt64Array,globalThis.BigUint64Array].filter(Boolean);Array.prototype.at||g(Array.prototype,"at",v);String.prototype.at||g(String.prototype,"at",T);for(const n of C){const e=n.prototype;e.at||g(e,"at",v)}var b=new Set(["ada:message:sent","ada:message:received"]);function w(n,e){return b.has(e)?n===e:n===e||e.startsWith(n)}function p(n){const e={};for(const[a,r]of Object.entries(n))(typeof r=="string"||typeof r=="number"||typeof r=="boolean"||r===null)&&(e[a]=r);return e}function S(n={}){const e=[];let a=1,r=1,o=!1,c=null;const u={},l=[],d=new Map,y=new Map,h=(t,s)=>{for(const i of d.values())w(i.key,t)&&i.callback(s,{eventKey:t});if(!b.has(t))for(const i of y.values())i(t,s)},f=()=>{l.length=0,c=null},m={start:async()=>{},stop:async()=>{},toggle:async()=>{o=!o},deleteHistory:async()=>{f()},reset:async()=>{f()},setMetaFields:async t=>{Object.assign(u,p(t))},setSensitiveMetaFields:async()=>{},setTestModeBanner:async()=>{},getInfo:async()=>({isChatOpen:o,isDrawerOpen:o,hasActiveChatter:l.length>0,hasClosedChat:!1}),getMetaFields:async()=>({...u}),isOpen:async()=>o,getConversation:async()=>({id:c,handoff:{inLiveChat:!1}}),getMessages:async()=>[...l],setComposerText:async()=>{},selectQuickReply:async()=>{},setDelegate:()=>{},trackEvent:async()=>{},subscribeEvent:async(t,s)=>{const i=a++;return d.set(i,{key:t,callback:s}),i},unsubscribeEvent:async t=>{d.delete(t),y.delete(t)},subscribeAll:async t=>{const s=a++;return y.set(s,t),s},open:async()=>{o=!0},close:async()=>{o=!1},setLanguage:async()=>{},setTheme:async()=>{},setDeviceToken:async()=>{},acknowledgeSessionMirrorClear:async()=>{},deliverSessionMirrorSeed:async()=>{},triggerPlaybook:async(t,s)=>{o=!0,Object.assign(u,p(s?.metaFields??{})),c=c??"mock-conversation"},sendMessage:async t=>{const s=`mock-message-${r++}`;return c=c??"mock-conversation",l.push({id:s,role:"user",type:"text",body:t,createdAt:Math.floor(Date.now()/1e3),origin:"programmatic"}),{id:s}},handleNotification:async()=>{o=!0},requestNotifications:async()=>"granted",createProactive:async()=>{},triggerCampaign:async()=>{},evaluateCampaignConditions:async()=>{},closeCampaign:async()=>{},triggerAnswer:async()=>{},triggerProactive:async()=>{},triggerGreeting:async()=>{},destroy:async()=>{d.clear(),y.clear(),o=!1}},A=Object.fromEntries(Object.entries(n).filter(([,t])=>t!==void 0)),M={...m,...A};return{...Object.fromEntries(Object.entries(M).map(([t,s])=>[t,(...i)=>(e.push({method:t,args:i}),s(...i))])),calls:e,$emit:h}}exports.createMockAdaMessaging=S;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var T=Object.prototype.hasOwnProperty;function y(n,e,a){Object.defineProperty(n,e,{value:a,configurable:!0,writable:!0})}Object.hasOwn||y(Object,"hasOwn",(n,e)=>{if(n==null)throw new TypeError("ada browser-polyfills: Cannot convert undefined or null to object");return T.call(Object(n),e)});function h(n){const e=Math.trunc(Number(this.length))||0;let a=Math.trunc(Number(n))||0;return a<0&&(a+=e),a<0||a>=e?void 0:this[a]}function C(n){const e=String(this),a=e.length;let o=Math.trunc(Number(n))||0;return o<0&&(o+=a),o<0||o>=a?void 0:e.charAt(o)}var w=[globalThis.Int8Array,globalThis.Uint8Array,globalThis.Uint8ClampedArray,globalThis.Int16Array,globalThis.Uint16Array,globalThis.Int32Array,globalThis.Uint32Array,globalThis.Float32Array,globalThis.Float64Array,globalThis.BigInt64Array,globalThis.BigUint64Array].filter(Boolean);Array.prototype.at||y(Array.prototype,"at",h);String.prototype.at||y(String.prototype,"at",C);for(const n of w){const e=n.prototype;e.at||y(e,"at",h)}var v=new Set(["ada:message:sent","ada:message:received"]);function S(n,e){return v.has(e)?n===e:n===e||e.startsWith(n)}function b(n){const e={};for(const[a,o]of Object.entries(n))(typeof o=="string"||typeof o=="number"||typeof o=="boolean"||o===null)&&(e[a]=o);return e}var r=async()=>{};function j(n={}){const e=[];let a=1,o=1,i=!1,l=null;const f={},g=[],u=new Map,d=new Map,m=(t,s)=>{for(const c of u.values())S(c.key,t)&&c.callback(s,{eventKey:t});if(!v.has(t))for(const c of d.values())c(t,s)},p=()=>{g.length=0,l=null},A={start:r,stop:r,toggle:async()=>{i=!i},deleteHistory:async()=>{p()},reset:async()=>{p()},setMetaFields:async t=>{Object.assign(f,b(t))},setSensitiveMetaFields:r,setTestModeBanner:r,getInfo:async()=>({isChatOpen:i,isDrawerOpen:i,hasActiveChatter:g.length>0,hasClosedChat:!1}),getMetaFields:async()=>({...f}),isOpen:async()=>i,getConversation:async()=>({id:l,handoff:{inLiveChat:!1}}),getMessages:async()=>[...g],setComposerText:r,selectQuickReply:r,setDelegate:()=>{},trackEvent:r,subscribeEvent:async(t,s)=>{const c=a++;return u.set(c,{key:t,callback:s}),c},unsubscribeEvent:async t=>{u.delete(t),d.delete(t)},subscribeAll:async t=>{const s=a++;return d.set(s,t),s},open:async()=>{i=!0},close:async()=>{i=!1},setLanguage:r,setTheme:r,setDeviceToken:r,acknowledgeSessionMirrorClear:r,deliverSessionMirrorSeed:r,triggerPlaybook:async(t,s)=>{i=!0,Object.assign(f,b(s?.metaFields??{})),l=l??"mock-conversation"},sendMessage:async t=>{const s=`mock-message-${o++}`;return l=l??"mock-conversation",g.push({id:s,role:"user",type:"text",body:t,createdAt:Math.floor(Date.now()/1e3),origin:"programmatic"}),{id:s}},handleNotification:async()=>{i=!0},requestNotifications:async()=>"granted",createProactive:r,triggerCampaign:r,evaluateCampaignConditions:r,closeCampaign:r,setPageUrl:r,triggerAnswer:r,triggerProactive:r,triggerGreeting:r,destroy:async()=>{u.clear(),d.clear(),i=!1}},M=Object.fromEntries(Object.entries(n).filter(([,t])=>t!==void 0)),O={...A,...M};return{...Object.fromEntries(Object.entries(O).map(([t,s])=>[t,(...c)=>(e.push({method:t,args:c}),s(...c))])),calls:e,$emit:m}}exports.createMockAdaMessaging=j;
2
2
 
3
3
  //# sourceMappingURL=testing.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"testing.cjs","names":[],"sources":["../../../../shared/utils/src/browser-polyfills.ts","../../src/npm/testing.ts"],"sourcesContent":["/**\n * Defence in depth for engines just below the declared browser floor.\n * The floor is defined in `messaging/vite.browser-targets.mjs`.\n *\n * Internal Ada code should prefer direct helpers, such as `hasOwn(...)` from\n * `guards.ts`. Every Ada bundle includes these fallbacks, including the host-page\n * SDK. These fallbacks also ship inside the customer-held npm tarballs of the SDK\n * and bridge. Each fallback defines a member only when it is missing. These\n * fallbacks do not extend browser support below the floor required by the shipped CSS.\n */\n\nconst objectHasOwnProperty = Object.prototype.hasOwnProperty;\n\nfunction defineValue(\n\ttarget: object,\n\tname: PropertyKey,\n\tvalue: (...args: unknown[]) => unknown,\n): void {\n\tObject.defineProperty(target, name, {\n\t\tvalue,\n\t\tconfigurable: true,\n\t\twritable: true,\n\t});\n}\n\nif (!Object.hasOwn) {\n\tdefineValue(Object, \"hasOwn\", (object: unknown, key: unknown) => {\n\t\tif (object == null) {\n\t\t\tthrow new TypeError(\n\t\t\t\t\"ada browser-polyfills: Cannot convert undefined or null to object\",\n\t\t\t);\n\t\t}\n\t\treturn objectHasOwnProperty.call(Object(object), key as PropertyKey);\n\t});\n}\n\nfunction at<T>(\n\tthis: { length: number; [index: number]: T },\n\tindex: unknown,\n): T | undefined {\n\tconst length = Math.trunc(Number(this.length)) || 0;\n\tlet relativeIndex = Math.trunc(Number(index)) || 0;\n\tif (relativeIndex < 0) {\n\t\trelativeIndex += length;\n\t}\n\treturn relativeIndex < 0 || relativeIndex >= length\n\t\t? undefined\n\t\t: this[relativeIndex];\n}\n\nfunction stringAt(this: string, index: unknown): string | undefined {\n\tconst value = String(this);\n\tconst length = value.length;\n\tlet relativeIndex = Math.trunc(Number(index)) || 0;\n\tif (relativeIndex < 0) {\n\t\trelativeIndex += length;\n\t}\n\treturn relativeIndex < 0 || relativeIndex >= length\n\t\t? undefined\n\t\t: value.charAt(relativeIndex);\n}\n\nconst typedArrayConstructors = [\n\tglobalThis.Int8Array,\n\tglobalThis.Uint8Array,\n\tglobalThis.Uint8ClampedArray,\n\tglobalThis.Int16Array,\n\tglobalThis.Uint16Array,\n\tglobalThis.Int32Array,\n\tglobalThis.Uint32Array,\n\tglobalThis.Float32Array,\n\tglobalThis.Float64Array,\n\tglobalThis.BigInt64Array,\n\tglobalThis.BigUint64Array,\n].filter(Boolean);\n\nif (!Array.prototype.at) {\n\tdefineValue(Array.prototype, \"at\", at);\n}\n\nif (!String.prototype.at) {\n\tdefineValue(String.prototype, \"at\", stringAt);\n}\n\nfor (const TypedArrayConstructor of typedArrayConstructors) {\n\tconst prototype = TypedArrayConstructor.prototype;\n\tif (!prototype.at) {\n\t\tdefineValue(prototype, \"at\", at);\n\t}\n}\n","import type {\n\tAdaSdkEventCallback,\n\tMetaFieldValue,\n\tPublicMessage,\n} from \"../client/client-types\";\nimport type { AdaMessagingInterface } from \"./loader\";\n\n/** One recorded method invocation on a {@link MockAdaMessaging}. */\nexport interface RecordedAdaMessagingCall {\n\tmethod: string;\n\targs: unknown[];\n}\n\n/**\n * The mock returned by {@link createMockAdaMessaging}: the full\n * {@link AdaMessagingInterface} plus test hooks for inspecting calls and\n * simulating SDK events.\n */\nexport interface MockAdaMessaging extends AdaMessagingInterface {\n\t/** Every method invocation, in call order. */\n\tcalls: RecordedAdaMessagingCall[];\n\t/**\n\t * Deliver an event to `subscribeEvent` and `subscribeAll` callbacks, as if\n\t * the SDK emitted it (e.g. `$emit(\"ada:ready\", { isRolledOut: true })`).\n\t * Routing matches the real SDK: keyed subscriptions match by prefix\n\t * (`\"ada:campaigns\"` catches `\"ada:campaigns:shown\"`), except the\n\t * transcript events `ada:message:sent`/`ada:message:received`, which reach\n\t * exact-key subscribers only and never `subscribeAll`.\n\t */\n\t$emit: (key: string, data?: unknown) => void;\n}\n\ninterface KeyedSubscription {\n\tkey: string;\n\tcallback: AdaSdkEventCallback;\n}\n\n// Mirrors EXACT_MATCH_EVENT_KEYS in client/client-host-runtime.ts: transcript\n// events reach exact-key subscribers only, never prefix or subscribeAll\n// subscribers. Duplicated (not imported) so the published testing entry stays\n// free of runtime modules; a drift test pins the mock against the real matcher.\nconst EXACT_MATCH_EVENT_KEYS = new Set([\n\t\"ada:message:sent\",\n\t\"ada:message:received\",\n]);\n\nfunction keyedSubscriptionMatches(\n\tsubscriptionKey: string,\n\teventKey: string,\n): boolean {\n\tif (EXACT_MATCH_EVENT_KEYS.has(eventKey)) {\n\t\treturn subscriptionKey === eventKey;\n\t}\n\t// Raw prefix match, same as the real SDK: \"ada:campaigns\" also catches\n\t// \"ada:campaigns:shown\" and underscore-suffixed keys.\n\treturn subscriptionKey === eventKey || eventKey.startsWith(subscriptionKey);\n}\n\nfunction toMetaFieldRecord(\n\tfields: Record<string, unknown>,\n): Record<string, MetaFieldValue> {\n\tconst record: Record<string, MetaFieldValue> = {};\n\tfor (const [key, value] of Object.entries(fields)) {\n\t\tif (\n\t\t\ttypeof value === \"string\" ||\n\t\t\ttypeof value === \"number\" ||\n\t\t\ttypeof value === \"boolean\" ||\n\t\t\tvalue === null\n\t\t) {\n\t\t\trecord[key] = value;\n\t\t}\n\t}\n\treturn record;\n}\n\n/**\n * Create an in-memory messaging-interface stand-in for unit-testing an\n * integration without loading the SDK from the CDN.\n *\n * Every method resolves, records itself in `calls`, and keeps just enough\n * state to behave like the real interface: `sendMessage` appends a\n * programmatic user message that `getMessages` returns, `open`/`close`/\n * `toggle` drive `isOpen` and `getInfo`, `setMetaFields` feeds\n * `getMetaFields` (sensitive fields are never returned, matching the real\n * SDK), and `$emit` fans out to `subscribeEvent`/`subscribeAll` callbacks.\n *\n * Pass `overrides` to replace any method (e.g. with `vi.fn()`); overridden\n * methods are still recorded in `calls`.\n */\nexport function createMockAdaMessaging(\n\toverrides: Partial<AdaMessagingInterface> = {},\n): MockAdaMessaging {\n\tconst calls: RecordedAdaMessagingCall[] = [];\n\tlet nextSubscriptionId = 1;\n\tlet nextMessageId = 1;\n\tlet chatOpen = false;\n\tlet conversationId: string | null = null;\n\tconst metaFields: Record<string, MetaFieldValue> = {};\n\tconst messages: PublicMessage[] = [];\n\tconst keyedSubscriptions = new Map<number, KeyedSubscription>();\n\tconst wildcardSubscriptions = new Map<\n\t\tnumber,\n\t\t(key: string, data: unknown) => void\n\t>();\n\n\tconst emit = (key: string, data?: unknown): void => {\n\t\tfor (const subscription of keyedSubscriptions.values()) {\n\t\t\tif (keyedSubscriptionMatches(subscription.key, key)) {\n\t\t\t\tsubscription.callback(data, { eventKey: key });\n\t\t\t}\n\t\t}\n\t\tif (EXACT_MATCH_EVENT_KEYS.has(key)) {\n\t\t\treturn;\n\t\t}\n\t\tfor (const callback of wildcardSubscriptions.values()) {\n\t\t\tcallback(key, data);\n\t\t}\n\t};\n\n\tconst clearTranscript = (): void => {\n\t\tmessages.length = 0;\n\t\tconversationId = null;\n\t};\n\n\tconst base: AdaMessagingInterface = {\n\t\tstart: async () => undefined,\n\t\tstop: async () => undefined,\n\t\ttoggle: async () => {\n\t\t\tchatOpen = !chatOpen;\n\t\t},\n\t\tdeleteHistory: async () => {\n\t\t\tclearTranscript();\n\t\t},\n\t\treset: async () => {\n\t\t\tclearTranscript();\n\t\t},\n\t\tsetMetaFields: async (fields) => {\n\t\t\tObject.assign(metaFields, toMetaFieldRecord(fields));\n\t\t},\n\t\t// Sensitive fields are accepted but never readable back, matching the\n\t\t// real SDK's getMetaFields contract.\n\t\tsetSensitiveMetaFields: async () => undefined,\n\t\tsetTestModeBanner: async () => undefined,\n\t\tgetInfo: async () => ({\n\t\t\tisChatOpen: chatOpen,\n\t\t\tisDrawerOpen: chatOpen,\n\t\t\thasActiveChatter: messages.length > 0,\n\t\t\thasClosedChat: false,\n\t\t}),\n\t\tgetMetaFields: async () => ({ ...metaFields }),\n\t\tisOpen: async () => chatOpen,\n\t\tgetConversation: async () => ({\n\t\t\tid: conversationId,\n\t\t\thandoff: { inLiveChat: false },\n\t\t}),\n\t\tgetMessages: async () => [...messages],\n\t\tsetComposerText: async () => undefined,\n\t\tselectQuickReply: async () => undefined,\n\t\tsetDelegate: () => undefined,\n\t\ttrackEvent: async () => undefined,\n\t\tsubscribeEvent: async (key, callback) => {\n\t\t\tconst id = nextSubscriptionId++;\n\t\t\tkeyedSubscriptions.set(id, { key, callback });\n\t\t\treturn id;\n\t\t},\n\t\tunsubscribeEvent: async (id) => {\n\t\t\tkeyedSubscriptions.delete(id);\n\t\t\twildcardSubscriptions.delete(id);\n\t\t},\n\t\tsubscribeAll: async (callback) => {\n\t\t\tconst id = nextSubscriptionId++;\n\t\t\twildcardSubscriptions.set(id, callback);\n\t\t\treturn id;\n\t\t},\n\t\topen: async () => {\n\t\t\tchatOpen = true;\n\t\t},\n\t\tclose: async () => {\n\t\t\tchatOpen = false;\n\t\t},\n\t\tsetLanguage: async () => undefined,\n\t\tsetTheme: async () => undefined,\n\t\tsetDeviceToken: async () => undefined,\n\t\t// Optional on AdaEmbedInterface (internal mobile-webview plumbing), but\n\t\t// Ada's own maintained test double still implements the full surface — the\n\t\t// types-drift guard requires the shipped mock to cover every interface\n\t\t// member so a customer's double never lags it.\n\t\tacknowledgeSessionMirrorClear: async () => undefined,\n\t\tdeliverSessionMirrorSeed: async () => undefined,\n\t\ttriggerPlaybook: async (_playbookId, options) => {\n\t\t\tchatOpen = true;\n\t\t\tObject.assign(metaFields, toMetaFieldRecord(options?.metaFields ?? {}));\n\t\t\tconversationId = conversationId ?? \"mock-conversation\";\n\t\t},\n\t\tsendMessage: async (body) => {\n\t\t\tconst id = `mock-message-${nextMessageId++}`;\n\t\t\tconversationId = conversationId ?? \"mock-conversation\";\n\t\t\tmessages.push({\n\t\t\t\tid,\n\t\t\t\trole: \"user\",\n\t\t\t\ttype: \"text\",\n\t\t\t\tbody,\n\t\t\t\tcreatedAt: Math.floor(Date.now() / 1000),\n\t\t\t\torigin: \"programmatic\",\n\t\t\t});\n\t\t\treturn { id };\n\t\t},\n\t\thandleNotification: async () => {\n\t\t\tchatOpen = true;\n\t\t},\n\t\trequestNotifications: async () => \"granted\",\n\t\tcreateProactive: async () => undefined,\n\t\ttriggerCampaign: async () => undefined,\n\t\tevaluateCampaignConditions: async () => undefined,\n\t\tcloseCampaign: async () => undefined,\n\t\ttriggerAnswer: async () => undefined,\n\t\ttriggerProactive: async () => undefined,\n\t\ttriggerGreeting: async () => undefined,\n\t\tdestroy: async () => {\n\t\t\tkeyedSubscriptions.clear();\n\t\t\twildcardSubscriptions.clear();\n\t\t\tchatOpen = false;\n\t\t},\n\t};\n\n\tconst definedOverrides = Object.fromEntries(\n\t\tObject.entries(overrides).filter(([, value]) => value !== undefined),\n\t);\n\tconst implementation = { ...base, ...definedOverrides };\n\tconst recorded = Object.fromEntries(\n\t\tObject.entries(implementation).map(([method, fn]) => [\n\t\t\tmethod,\n\t\t\t(...args: unknown[]) => {\n\t\t\t\tcalls.push({ method, args });\n\t\t\t\treturn (fn as (...callArgs: unknown[]) => unknown)(...args);\n\t\t\t},\n\t\t]),\n\t) as unknown as AdaMessagingInterface;\n\n\treturn { ...recorded, calls, $emit: emit };\n}\n"],"mappings":"mEAWA,IAAM,EAAuB,OAAO,UAAU,eAE9C,SAAS,EACR,EACA,EACA,EACO,CACP,OAAO,eAAe,EAAQ,EAAM,CACnC,MAAA,EACA,aAAc,GACd,SAAU,EACX,CAAC,CACF,CAEK,OAAO,QACX,EAAY,OAAQ,SAAA,CAAW,EAAiB,IAAiB,CAChE,GAAI,GAAU,KACb,MAAM,IAAI,UACT,mEACD,EAED,OAAO,EAAqB,KAAK,OAAO,CAAM,EAAG,CAAkB,CACpE,CAAC,EAGF,SAAS,EAER,EACgB,CAChB,MAAM,EAAS,KAAK,MAAM,OAAO,KAAK,MAAM,CAAC,GAAK,EAClD,IAAI,EAAgB,KAAK,MAAM,OAAO,CAAK,CAAC,GAAK,EACjD,OAAI,EAAgB,IACnB,GAAiB,GAEX,EAAgB,GAAK,GAAiB,EAC1C,OACA,KAAK,CAAA,CACT,CAEA,SAAS,EAAuB,EAAoC,CACnE,MAAM,EAAQ,OAAO,IAAI,EACnB,EAAS,EAAM,OACrB,IAAI,EAAgB,KAAK,MAAM,OAAO,CAAK,CAAC,GAAK,EACjD,OAAI,EAAgB,IACnB,GAAiB,GAEX,EAAgB,GAAK,GAAiB,EAC1C,OACA,EAAM,OAAO,CAAa,CAC9B,CAEA,IAAM,EAAyB,CAC9B,WAAW,UACX,WAAW,WACX,WAAW,kBACX,WAAW,WACX,WAAW,YACX,WAAW,WACX,WAAW,YACX,WAAW,aACX,WAAW,aACX,WAAW,cACX,WAAW,cACZ,EAAE,OAAO,OAAO,EAEX,MAAM,UAAU,IACpB,EAAY,MAAM,UAAW,KAAM,CAAE,E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,CAAC,EACM,CAAE,GAAA,CAAG,CACb,EACA,mBAAoB,SAAY,CAC/B,EAAW,EACZ,EACA,qBAAsB,SAAY,UAClC,gBAAiB,SAAA,GACjB,gBAAiB,SAAA,GACjB,2BAA4B,SAAA,GAC5B,cAAe,SAAA,GACf,cAAe,SAAA,GACf,iBAAkB,SAAA,GAClB,gBAAiB,SAAA,GACjB,QAAS,SAAY,CACpB,EAAmB,MAAM,EACzB,EAAsB,MAAM,EAC5B,EAAW,EACZ,CACD,EAEM,EAAmB,OAAO,YAC/B,OAAO,QAAQ,CAAS,EAAE,OAAA,CAAQ,CAAA,CAAG,CAAA,IAAW,IAAU,MAAS,CACpE,EACM,EAAiB,CAAE,GAAG,EAAM,GAAG,CAAiB,EAWtD,MAAO,CAAE,GAVQ,OAAO,YACvB,OAAO,QAAQ,CAAc,EAAE,IAAA,CAAK,CAAC,EAAQ,CAAA,IAAQ,CACpD,EAAA,IACI,KACH,EAAM,KAAK,CAAE,OAAA,EAAQ,KAAA,CAAK,CAAC,EACnB,EAA2C,GAAG,CAAI,EAE5D,CAAC,CAGU,EAAU,MAAA,EAAO,MAAO,CAAK,CAC1C"}
1
+ {"version":3,"file":"testing.cjs","names":[],"sources":["../../../../shared/utils/src/browser-polyfills.ts","../../src/npm/testing.ts"],"sourcesContent":["/**\n * Defence in depth for engines just below the declared browser floor.\n * The floor is defined in `messaging/vite.browser-targets.mjs`.\n *\n * Internal Ada code should prefer direct helpers, such as `hasOwn(...)` from\n * `guards.ts`. Every Ada bundle includes these fallbacks, including the host-page\n * SDK. These fallbacks also ship inside the customer-held npm tarballs of the SDK\n * and bridge. Each fallback defines a member only when it is missing. These\n * fallbacks do not extend browser support below the floor required by the shipped CSS.\n */\n\nconst objectHasOwnProperty = Object.prototype.hasOwnProperty;\n\nfunction defineValue(\n\ttarget: object,\n\tname: PropertyKey,\n\tvalue: (...args: unknown[]) => unknown,\n): void {\n\tObject.defineProperty(target, name, {\n\t\tvalue,\n\t\tconfigurable: true,\n\t\twritable: true,\n\t});\n}\n\nif (!Object.hasOwn) {\n\tdefineValue(Object, \"hasOwn\", (object: unknown, key: unknown) => {\n\t\tif (object == null) {\n\t\t\tthrow new TypeError(\n\t\t\t\t\"ada browser-polyfills: Cannot convert undefined or null to object\",\n\t\t\t);\n\t\t}\n\t\treturn objectHasOwnProperty.call(Object(object), key as PropertyKey);\n\t});\n}\n\nfunction at<T>(\n\tthis: { length: number; [index: number]: T },\n\tindex: unknown,\n): T | undefined {\n\tconst length = Math.trunc(Number(this.length)) || 0;\n\tlet relativeIndex = Math.trunc(Number(index)) || 0;\n\tif (relativeIndex < 0) {\n\t\trelativeIndex += length;\n\t}\n\treturn relativeIndex < 0 || relativeIndex >= length\n\t\t? undefined\n\t\t: this[relativeIndex];\n}\n\nfunction stringAt(this: string, index: unknown): string | undefined {\n\tconst value = String(this);\n\tconst length = value.length;\n\tlet relativeIndex = Math.trunc(Number(index)) || 0;\n\tif (relativeIndex < 0) {\n\t\trelativeIndex += length;\n\t}\n\treturn relativeIndex < 0 || relativeIndex >= length\n\t\t? undefined\n\t\t: value.charAt(relativeIndex);\n}\n\nconst typedArrayConstructors = [\n\tglobalThis.Int8Array,\n\tglobalThis.Uint8Array,\n\tglobalThis.Uint8ClampedArray,\n\tglobalThis.Int16Array,\n\tglobalThis.Uint16Array,\n\tglobalThis.Int32Array,\n\tglobalThis.Uint32Array,\n\tglobalThis.Float32Array,\n\tglobalThis.Float64Array,\n\tglobalThis.BigInt64Array,\n\tglobalThis.BigUint64Array,\n].filter(Boolean);\n\nif (!Array.prototype.at) {\n\tdefineValue(Array.prototype, \"at\", at);\n}\n\nif (!String.prototype.at) {\n\tdefineValue(String.prototype, \"at\", stringAt);\n}\n\nfor (const TypedArrayConstructor of typedArrayConstructors) {\n\tconst prototype = TypedArrayConstructor.prototype;\n\tif (!prototype.at) {\n\t\tdefineValue(prototype, \"at\", at);\n\t}\n}\n","import type {\n\tAdaSdkEventCallback,\n\tMetaFieldValue,\n\tPublicMessage,\n} from \"../client/client-types\";\nimport type { AdaMessagingInterface } from \"./loader\";\n\n/** One recorded method invocation on a {@link MockAdaMessaging}. */\nexport interface RecordedAdaMessagingCall {\n\tmethod: string;\n\targs: unknown[];\n}\n\n/**\n * The mock returned by {@link createMockAdaMessaging}: the full\n * {@link AdaMessagingInterface} plus test hooks for inspecting calls and\n * simulating SDK events.\n */\nexport interface MockAdaMessaging extends AdaMessagingInterface {\n\t/** Every method invocation, in call order. */\n\tcalls: RecordedAdaMessagingCall[];\n\t/**\n\t * Deliver an event to `subscribeEvent` and `subscribeAll` callbacks, as if\n\t * the SDK emitted it (e.g. `$emit(\"ada:ready\", { isRolledOut: true })`).\n\t * Routing matches the real SDK: keyed subscriptions match by prefix\n\t * (`\"ada:campaigns\"` catches `\"ada:campaigns:shown\"`), except the\n\t * transcript events `ada:message:sent`/`ada:message:received`, which reach\n\t * exact-key subscribers only and never `subscribeAll`.\n\t */\n\t$emit: (key: string, data?: unknown) => void;\n}\n\ninterface KeyedSubscription {\n\tkey: string;\n\tcallback: AdaSdkEventCallback;\n}\n\n// Mirrors EXACT_MATCH_EVENT_KEYS in client/client-host-runtime.ts: transcript\n// events reach exact-key subscribers only, never prefix or subscribeAll\n// subscribers. Duplicated (not imported) so the published testing entry stays\n// free of runtime modules; a drift test pins the mock against the real matcher.\nconst EXACT_MATCH_EVENT_KEYS = new Set([\n\t\"ada:message:sent\",\n\t\"ada:message:received\",\n]);\n\nfunction keyedSubscriptionMatches(\n\tsubscriptionKey: string,\n\teventKey: string,\n): boolean {\n\tif (EXACT_MATCH_EVENT_KEYS.has(eventKey)) {\n\t\treturn subscriptionKey === eventKey;\n\t}\n\t// Raw prefix match, same as the real SDK: \"ada:campaigns\" also catches\n\t// \"ada:campaigns:shown\" and underscore-suffixed keys.\n\treturn subscriptionKey === eventKey || eventKey.startsWith(subscriptionKey);\n}\n\nfunction toMetaFieldRecord(\n\tfields: Record<string, unknown>,\n): Record<string, MetaFieldValue> {\n\tconst record: Record<string, MetaFieldValue> = {};\n\tfor (const [key, value] of Object.entries(fields)) {\n\t\tif (\n\t\t\ttypeof value === \"string\" ||\n\t\t\ttypeof value === \"number\" ||\n\t\t\ttypeof value === \"boolean\" ||\n\t\t\tvalue === null\n\t\t) {\n\t\t\trecord[key] = value;\n\t\t}\n\t}\n\treturn record;\n}\n\nconst resolveVoid = async (): Promise<void> => undefined;\n\n/**\n * Create an in-memory messaging-interface stand-in for unit-testing an\n * integration without loading the SDK from the CDN.\n *\n * Every method resolves, records itself in `calls`, and keeps just enough\n * state to behave like the real interface: `sendMessage` appends a\n * programmatic user message that `getMessages` returns, `open`/`close`/\n * `toggle` drive `isOpen` and `getInfo`, `setMetaFields` feeds\n * `getMetaFields` (sensitive fields are never returned, matching the real\n * SDK), and `$emit` fans out to `subscribeEvent`/`subscribeAll` callbacks.\n *\n * Pass `overrides` to replace any method (e.g. with `vi.fn()`); overridden\n * methods are still recorded in `calls`.\n */\nexport function createMockAdaMessaging(\n\toverrides: Partial<AdaMessagingInterface> = {},\n): MockAdaMessaging {\n\tconst calls: RecordedAdaMessagingCall[] = [];\n\tlet nextSubscriptionId = 1;\n\tlet nextMessageId = 1;\n\tlet chatOpen = false;\n\tlet conversationId: string | null = null;\n\tconst metaFields: Record<string, MetaFieldValue> = {};\n\tconst messages: PublicMessage[] = [];\n\tconst keyedSubscriptions = new Map<number, KeyedSubscription>();\n\tconst wildcardSubscriptions = new Map<\n\t\tnumber,\n\t\t(key: string, data: unknown) => void\n\t>();\n\n\tconst emit = (key: string, data?: unknown): void => {\n\t\tfor (const subscription of keyedSubscriptions.values()) {\n\t\t\tif (keyedSubscriptionMatches(subscription.key, key)) {\n\t\t\t\tsubscription.callback(data, { eventKey: key });\n\t\t\t}\n\t\t}\n\t\tif (EXACT_MATCH_EVENT_KEYS.has(key)) {\n\t\t\treturn;\n\t\t}\n\t\tfor (const callback of wildcardSubscriptions.values()) {\n\t\t\tcallback(key, data);\n\t\t}\n\t};\n\n\tconst clearTranscript = (): void => {\n\t\tmessages.length = 0;\n\t\tconversationId = null;\n\t};\n\n\tconst base: AdaMessagingInterface = {\n\t\tstart: resolveVoid,\n\t\tstop: resolveVoid,\n\t\ttoggle: async () => {\n\t\t\tchatOpen = !chatOpen;\n\t\t},\n\t\tdeleteHistory: async () => {\n\t\t\tclearTranscript();\n\t\t},\n\t\treset: async () => {\n\t\t\tclearTranscript();\n\t\t},\n\t\tsetMetaFields: async (fields) => {\n\t\t\tObject.assign(metaFields, toMetaFieldRecord(fields));\n\t\t},\n\t\t// Sensitive fields are accepted but never readable back, matching the\n\t\t// real SDK's getMetaFields contract.\n\t\tsetSensitiveMetaFields: resolveVoid,\n\t\tsetTestModeBanner: resolveVoid,\n\t\tgetInfo: async () => ({\n\t\t\tisChatOpen: chatOpen,\n\t\t\tisDrawerOpen: chatOpen,\n\t\t\thasActiveChatter: messages.length > 0,\n\t\t\thasClosedChat: false,\n\t\t}),\n\t\tgetMetaFields: async () => ({ ...metaFields }),\n\t\tisOpen: async () => chatOpen,\n\t\tgetConversation: async () => ({\n\t\t\tid: conversationId,\n\t\t\thandoff: { inLiveChat: false },\n\t\t}),\n\t\tgetMessages: async () => [...messages],\n\t\tsetComposerText: resolveVoid,\n\t\tselectQuickReply: resolveVoid,\n\t\tsetDelegate: () => undefined,\n\t\ttrackEvent: resolveVoid,\n\t\tsubscribeEvent: async (key, callback) => {\n\t\t\tconst id = nextSubscriptionId++;\n\t\t\tkeyedSubscriptions.set(id, { key, callback });\n\t\t\treturn id;\n\t\t},\n\t\tunsubscribeEvent: async (id) => {\n\t\t\tkeyedSubscriptions.delete(id);\n\t\t\twildcardSubscriptions.delete(id);\n\t\t},\n\t\tsubscribeAll: async (callback) => {\n\t\t\tconst id = nextSubscriptionId++;\n\t\t\twildcardSubscriptions.set(id, callback);\n\t\t\treturn id;\n\t\t},\n\t\topen: async () => {\n\t\t\tchatOpen = true;\n\t\t},\n\t\tclose: async () => {\n\t\t\tchatOpen = false;\n\t\t},\n\t\tsetLanguage: resolveVoid,\n\t\tsetTheme: resolveVoid,\n\t\tsetDeviceToken: resolveVoid,\n\t\t// Optional on AdaEmbedInterface (internal mobile-webview plumbing), but\n\t\t// Ada's own maintained test double still implements the full surface — the\n\t\t// types-drift guard requires the shipped mock to cover every interface\n\t\t// member so a customer's double never lags it.\n\t\tacknowledgeSessionMirrorClear: resolveVoid,\n\t\tdeliverSessionMirrorSeed: resolveVoid,\n\t\ttriggerPlaybook: async (_playbookId, options) => {\n\t\t\tchatOpen = true;\n\t\t\tObject.assign(metaFields, toMetaFieldRecord(options?.metaFields ?? {}));\n\t\t\tconversationId = conversationId ?? \"mock-conversation\";\n\t\t},\n\t\tsendMessage: async (body) => {\n\t\t\tconst id = `mock-message-${nextMessageId++}`;\n\t\t\tconversationId = conversationId ?? \"mock-conversation\";\n\t\t\tmessages.push({\n\t\t\t\tid,\n\t\t\t\trole: \"user\",\n\t\t\t\ttype: \"text\",\n\t\t\t\tbody,\n\t\t\t\tcreatedAt: Math.floor(Date.now() / 1000),\n\t\t\t\torigin: \"programmatic\",\n\t\t\t});\n\t\t\treturn { id };\n\t\t},\n\t\thandleNotification: async () => {\n\t\t\tchatOpen = true;\n\t\t},\n\t\trequestNotifications: async () => \"granted\",\n\t\tcreateProactive: resolveVoid,\n\t\ttriggerCampaign: resolveVoid,\n\t\tevaluateCampaignConditions: resolveVoid,\n\t\tcloseCampaign: resolveVoid,\n\t\tsetPageUrl: resolveVoid,\n\t\ttriggerAnswer: resolveVoid,\n\t\ttriggerProactive: resolveVoid,\n\t\ttriggerGreeting: resolveVoid,\n\t\tdestroy: async () => {\n\t\t\tkeyedSubscriptions.clear();\n\t\t\twildcardSubscriptions.clear();\n\t\t\tchatOpen = false;\n\t\t},\n\t};\n\n\tconst definedOverrides = Object.fromEntries(\n\t\tObject.entries(overrides).filter(([, value]) => value !== undefined),\n\t);\n\tconst implementation = { ...base, ...definedOverrides };\n\tconst recorded = Object.fromEntries(\n\t\tObject.entries(implementation).map(([method, fn]) => [\n\t\t\tmethod,\n\t\t\t(...args: unknown[]) => {\n\t\t\t\tcalls.push({ method, args });\n\t\t\t\treturn (fn as (...callArgs: unknown[]) => unknown)(...args);\n\t\t\t},\n\t\t]),\n\t) as unknown as AdaMessagingInterface;\n\n\treturn { ...recorded, calls, $emit: emit };\n}\n"],"mappings":"mEAWA,IAAM,EAAuB,OAAO,UAAU,eAE9C,SAAS,EACR,EACA,EACA,EACO,CACP,OAAO,eAAe,EAAQ,EAAM,CACnC,MAAA,EACA,aAAc,GACd,SAAU,EACX,CAAC,CACF,CAEK,OAAO,QACX,EAAY,OAAQ,SAAA,CAAW,EAAiB,IAAiB,CAChE,GAAI,GAAU,KACb,MAAM,IAAI,UACT,mEACD,EAED,OAAO,EAAqB,KAAK,OAAO,CAAM,EAAG,CAAkB,CACpE,CAAC,EAGF,SAAS,EAER,EACgB,CAChB,MAAM,EAAS,KAAK,MAAM,OAAO,KAAK,MAAM,CAAC,GAAK,EAClD,IAAI,EAAgB,KAAK,MAAM,OAAO,CAAK,CAAC,GAAK,EACjD,OAAI,EAAgB,IACnB,GAAiB,GAEX,EAAgB,GAAK,GAAiB,EAC1C,OACA,KAAK,CAAA,CACT,CAEA,SAAS,EAAuB,EAAoC,CACnE,MAAM,EAAQ,OAAO,IAAI,EACnB,EAAS,EAAM,OACrB,IAAI,EAAgB,KAAK,MAAM,OAAO,CAAK,CAAC,GAAK,EACjD,OAAI,EAAgB,IACnB,GAAiB,GAEX,EAAgB,GAAK,GAAiB,EAC1C,OACA,EAAM,OAAO,CAAa,CAC9B,CAEA,IAAM,EAAyB,CAC9B,WAAW,UACX,WAAW,WACX,WAAW,kBACX,WAAW,WACX,WAAW,YACX,WAAW,WACX,WAAW,YACX,WAAW,aACX,WAAW,aACX,WAAW,cACX,WAAW,cACZ,EAAE,OAAO,OAAO,EAEX,MAAM,UAAU,IACpB,EAAY,MAAM,UAAW,KAAM,CAAE,EAGjC,OAAO,UAAU,IACrB,EAAY,OAAO,U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B,SAAY,UAClC,gBAAiB,EACjB,gBAAiB,EACjB,2BAA4B,EAC5B,cAAe,EACf,WAAY,EACZ,cAAe,EACf,iBAAkB,EAClB,gBAAiB,EACjB,QAAS,SAAY,CACpB,EAAmB,MAAM,EACzB,EAAsB,MAAM,EAC5B,EAAW,EACZ,CACD,EAEM,EAAmB,OAAO,YAC/B,OAAO,QAAQ,CAAS,EAAE,OAAA,CAAQ,CAAA,CAAG,CAAA,IAAW,IAAU,MAAS,CACpE,EACM,EAAiB,CAAE,GAAG,EAAM,GAAG,CAAiB,EAWtD,MAAO,CAAE,GAVQ,OAAO,YACvB,OAAO,QAAQ,CAAc,EAAE,IAAA,CAAK,CAAC,EAAQ,CAAA,IAAQ,CACpD,EAAA,IACI,KACH,EAAM,KAAK,CAAE,OAAA,EAAQ,KAAA,CAAK,CAAC,EACnB,EAA2C,GAAG,CAAI,EAE5D,CAAC,CAGU,EAAU,MAAA,EAAO,MAAO,CAAK,CAC1C"}
@@ -1,26 +1,26 @@
1
- var T = Object.prototype.hasOwnProperty;
2
- function g(n, e, a) {
1
+ var M = Object.prototype.hasOwnProperty;
2
+ function y(n, e, a) {
3
3
  Object.defineProperty(n, e, {
4
4
  value: a,
5
5
  configurable: !0,
6
6
  writable: !0
7
7
  });
8
8
  }
9
- Object.hasOwn || g(Object, "hasOwn", (n, e) => {
9
+ Object.hasOwn || y(Object, "hasOwn", (n, e) => {
10
10
  if (n == null) throw new TypeError("ada browser-polyfills: Cannot convert undefined or null to object");
11
- return T.call(Object(n), e);
11
+ return M.call(Object(n), e);
12
12
  });
13
- function v(n) {
13
+ function h(n) {
14
14
  const e = Math.trunc(Number(this.length)) || 0;
15
15
  let a = Math.trunc(Number(n)) || 0;
16
16
  return a < 0 && (a += e), a < 0 || a >= e ? void 0 : this[a];
17
17
  }
18
- function M(n) {
18
+ function C(n) {
19
19
  const e = String(this), a = e.length;
20
- let r = Math.trunc(Number(n)) || 0;
21
- return r < 0 && (r += a), r < 0 || r >= a ? void 0 : e.charAt(r);
20
+ let o = Math.trunc(Number(n)) || 0;
21
+ return o < 0 && (o += a), o < 0 || o >= a ? void 0 : e.charAt(o);
22
22
  }
23
- var C = [
23
+ var w = [
24
24
  globalThis.Int8Array,
25
25
  globalThis.Uint8Array,
26
26
  globalThis.Uint8ClampedArray,
@@ -33,108 +33,98 @@ var C = [
33
33
  globalThis.BigInt64Array,
34
34
  globalThis.BigUint64Array
35
35
  ].filter(Boolean);
36
- Array.prototype.at || g(Array.prototype, "at", v);
37
- String.prototype.at || g(String.prototype, "at", M);
38
- for (const n of C) {
36
+ Array.prototype.at || y(Array.prototype, "at", h);
37
+ String.prototype.at || y(String.prototype, "at", C);
38
+ for (const n of w) {
39
39
  const e = n.prototype;
40
- e.at || g(e, "at", v);
40
+ e.at || y(e, "at", h);
41
41
  }
42
- var b = /* @__PURE__ */ new Set(["ada:message:sent", "ada:message:received"]);
43
- function w(n, e) {
44
- return b.has(e) ? n === e : n === e || e.startsWith(n);
42
+ var v = /* @__PURE__ */ new Set(["ada:message:sent", "ada:message:received"]);
43
+ function j(n, e) {
44
+ return v.has(e) ? n === e : n === e || e.startsWith(n);
45
45
  }
46
- function f(n) {
46
+ function b(n) {
47
47
  const e = {};
48
- for (const [a, r] of Object.entries(n)) (typeof r == "string" || typeof r == "number" || typeof r == "boolean" || r === null) && (e[a] = r);
48
+ for (const [a, o] of Object.entries(n)) (typeof o == "string" || typeof o == "number" || typeof o == "boolean" || o === null) && (e[a] = o);
49
49
  return e;
50
50
  }
51
- function j(n = {}) {
51
+ var r = async () => {
52
+ };
53
+ function k(n = {}) {
52
54
  const e = [];
53
- let a = 1, r = 1, o = !1, c = null;
54
- const u = {}, l = [], y = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map(), h = (t, s) => {
55
- for (const i of y.values()) w(i.key, t) && i.callback(s, { eventKey: t });
56
- if (!b.has(t))
57
- for (const i of d.values()) i(t, s);
58
- }, p = () => {
59
- l.length = 0, c = null;
60
- }, m = {
61
- start: async () => {
62
- },
63
- stop: async () => {
64
- },
55
+ let a = 1, o = 1, i = !1, l = null;
56
+ const p = {}, g = [], u = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map(), m = (t, s) => {
57
+ for (const c of u.values()) j(c.key, t) && c.callback(s, { eventKey: t });
58
+ if (!v.has(t))
59
+ for (const c of d.values()) c(t, s);
60
+ }, f = () => {
61
+ g.length = 0, l = null;
62
+ }, A = {
63
+ start: r,
64
+ stop: r,
65
65
  toggle: async () => {
66
- o = !o;
66
+ i = !i;
67
67
  },
68
68
  deleteHistory: async () => {
69
- p();
69
+ f();
70
70
  },
71
71
  reset: async () => {
72
- p();
72
+ f();
73
73
  },
74
74
  setMetaFields: async (t) => {
75
- Object.assign(u, f(t));
76
- },
77
- setSensitiveMetaFields: async () => {
78
- },
79
- setTestModeBanner: async () => {
75
+ Object.assign(p, b(t));
80
76
  },
77
+ setSensitiveMetaFields: r,
78
+ setTestModeBanner: r,
81
79
  getInfo: async () => ({
82
- isChatOpen: o,
83
- isDrawerOpen: o,
84
- hasActiveChatter: l.length > 0,
80
+ isChatOpen: i,
81
+ isDrawerOpen: i,
82
+ hasActiveChatter: g.length > 0,
85
83
  hasClosedChat: !1
86
84
  }),
87
- getMetaFields: async () => ({ ...u }),
88
- isOpen: async () => o,
85
+ getMetaFields: async () => ({ ...p }),
86
+ isOpen: async () => i,
89
87
  getConversation: async () => ({
90
- id: c,
88
+ id: l,
91
89
  handoff: { inLiveChat: !1 }
92
90
  }),
93
- getMessages: async () => [...l],
94
- setComposerText: async () => {
95
- },
96
- selectQuickReply: async () => {
97
- },
91
+ getMessages: async () => [...g],
92
+ setComposerText: r,
93
+ selectQuickReply: r,
98
94
  setDelegate: () => {
99
95
  },
100
- trackEvent: async () => {
101
- },
96
+ trackEvent: r,
102
97
  subscribeEvent: async (t, s) => {
103
- const i = a++;
104
- return y.set(i, {
98
+ const c = a++;
99
+ return u.set(c, {
105
100
  key: t,
106
101
  callback: s
107
- }), i;
102
+ }), c;
108
103
  },
109
104
  unsubscribeEvent: async (t) => {
110
- y.delete(t), d.delete(t);
105
+ u.delete(t), d.delete(t);
111
106
  },
112
107
  subscribeAll: async (t) => {
113
108
  const s = a++;
114
109
  return d.set(s, t), s;
115
110
  },
116
111
  open: async () => {
117
- o = !0;
112
+ i = !0;
118
113
  },
119
114
  close: async () => {
120
- o = !1;
121
- },
122
- setLanguage: async () => {
123
- },
124
- setTheme: async () => {
125
- },
126
- setDeviceToken: async () => {
127
- },
128
- acknowledgeSessionMirrorClear: async () => {
129
- },
130
- deliverSessionMirrorSeed: async () => {
115
+ i = !1;
131
116
  },
117
+ setLanguage: r,
118
+ setTheme: r,
119
+ setDeviceToken: r,
120
+ acknowledgeSessionMirrorClear: r,
121
+ deliverSessionMirrorSeed: r,
132
122
  triggerPlaybook: async (t, s) => {
133
- o = !0, Object.assign(u, f(s?.metaFields ?? {})), c = c ?? "mock-conversation";
123
+ i = !0, Object.assign(p, b(s?.metaFields ?? {})), l = l ?? "mock-conversation";
134
124
  },
135
125
  sendMessage: async (t) => {
136
- const s = `mock-message-${r++}`;
137
- return c = c ?? "mock-conversation", l.push({
126
+ const s = `mock-message-${o++}`;
127
+ return l = l ?? "mock-conversation", g.push({
138
128
  id: s,
139
129
  role: "user",
140
130
  type: "text",
@@ -144,41 +134,35 @@ function j(n = {}) {
144
134
  }), { id: s };
145
135
  },
146
136
  handleNotification: async () => {
147
- o = !0;
137
+ i = !0;
148
138
  },
149
139
  requestNotifications: async () => "granted",
150
- createProactive: async () => {
151
- },
152
- triggerCampaign: async () => {
153
- },
154
- evaluateCampaignConditions: async () => {
155
- },
156
- closeCampaign: async () => {
157
- },
158
- triggerAnswer: async () => {
159
- },
160
- triggerProactive: async () => {
161
- },
162
- triggerGreeting: async () => {
163
- },
140
+ createProactive: r,
141
+ triggerCampaign: r,
142
+ evaluateCampaignConditions: r,
143
+ closeCampaign: r,
144
+ setPageUrl: r,
145
+ triggerAnswer: r,
146
+ triggerProactive: r,
147
+ triggerGreeting: r,
164
148
  destroy: async () => {
165
- y.clear(), d.clear(), o = !1;
149
+ u.clear(), d.clear(), i = !1;
166
150
  }
167
- }, A = Object.fromEntries(Object.entries(n).filter(([, t]) => t !== void 0)), O = {
168
- ...m,
169
- ...A
151
+ }, O = Object.fromEntries(Object.entries(n).filter(([, t]) => t !== void 0)), T = {
152
+ ...A,
153
+ ...O
170
154
  };
171
155
  return {
172
- ...Object.fromEntries(Object.entries(O).map(([t, s]) => [t, (...i) => (e.push({
156
+ ...Object.fromEntries(Object.entries(T).map(([t, s]) => [t, (...c) => (e.push({
173
157
  method: t,
174
- args: i
175
- }), s(...i))])),
158
+ args: c
159
+ }), s(...c))])),
176
160
  calls: e,
177
- $emit: h
161
+ $emit: m
178
162
  };
179
163
  }
180
164
  export {
181
- j as createMockAdaMessaging
165
+ k as createMockAdaMessaging
182
166
  };
183
167
 
184
168
  //# sourceMappingURL=testing.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"testing.js","names":[],"sources":["../../../../shared/utils/src/browser-polyfills.ts","../../src/npm/testing.ts"],"sourcesContent":["/**\n * Defence in depth for engines just below the declared browser floor.\n * The floor is defined in `messaging/vite.browser-targets.mjs`.\n *\n * Internal Ada code should prefer direct helpers, such as `hasOwn(...)` from\n * `guards.ts`. Every Ada bundle includes these fallbacks, including the host-page\n * SDK. These fallbacks also ship inside the customer-held npm tarballs of the SDK\n * and bridge. Each fallback defines a member only when it is missing. These\n * fallbacks do not extend browser support below the floor required by the shipped CSS.\n */\n\nconst objectHasOwnProperty = Object.prototype.hasOwnProperty;\n\nfunction defineValue(\n\ttarget: object,\n\tname: PropertyKey,\n\tvalue: (...args: unknown[]) => unknown,\n): void {\n\tObject.defineProperty(target, name, {\n\t\tvalue,\n\t\tconfigurable: true,\n\t\twritable: true,\n\t});\n}\n\nif (!Object.hasOwn) {\n\tdefineValue(Object, \"hasOwn\", (object: unknown, key: unknown) => {\n\t\tif (object == null) {\n\t\t\tthrow new TypeError(\n\t\t\t\t\"ada browser-polyfills: Cannot convert undefined or null to object\",\n\t\t\t);\n\t\t}\n\t\treturn objectHasOwnProperty.call(Object(object), key as PropertyKey);\n\t});\n}\n\nfunction at<T>(\n\tthis: { length: number; [index: number]: T },\n\tindex: unknown,\n): T | undefined {\n\tconst length = Math.trunc(Number(this.length)) || 0;\n\tlet relativeIndex = Math.trunc(Number(index)) || 0;\n\tif (relativeIndex < 0) {\n\t\trelativeIndex += length;\n\t}\n\treturn relativeIndex < 0 || relativeIndex >= length\n\t\t? undefined\n\t\t: this[relativeIndex];\n}\n\nfunction stringAt(this: string, index: unknown): string | undefined {\n\tconst value = String(this);\n\tconst length = value.length;\n\tlet relativeIndex = Math.trunc(Number(index)) || 0;\n\tif (relativeIndex < 0) {\n\t\trelativeIndex += length;\n\t}\n\treturn relativeIndex < 0 || relativeIndex >= length\n\t\t? undefined\n\t\t: value.charAt(relativeIndex);\n}\n\nconst typedArrayConstructors = [\n\tglobalThis.Int8Array,\n\tglobalThis.Uint8Array,\n\tglobalThis.Uint8ClampedArray,\n\tglobalThis.Int16Array,\n\tglobalThis.Uint16Array,\n\tglobalThis.Int32Array,\n\tglobalThis.Uint32Array,\n\tglobalThis.Float32Array,\n\tglobalThis.Float64Array,\n\tglobalThis.BigInt64Array,\n\tglobalThis.BigUint64Array,\n].filter(Boolean);\n\nif (!Array.prototype.at) {\n\tdefineValue(Array.prototype, \"at\", at);\n}\n\nif (!String.prototype.at) {\n\tdefineValue(String.prototype, \"at\", stringAt);\n}\n\nfor (const TypedArrayConstructor of typedArrayConstructors) {\n\tconst prototype = TypedArrayConstructor.prototype;\n\tif (!prototype.at) {\n\t\tdefineValue(prototype, \"at\", at);\n\t}\n}\n","import type {\n\tAdaSdkEventCallback,\n\tMetaFieldValue,\n\tPublicMessage,\n} from \"../client/client-types\";\nimport type { AdaMessagingInterface } from \"./loader\";\n\n/** One recorded method invocation on a {@link MockAdaMessaging}. */\nexport interface RecordedAdaMessagingCall {\n\tmethod: string;\n\targs: unknown[];\n}\n\n/**\n * The mock returned by {@link createMockAdaMessaging}: the full\n * {@link AdaMessagingInterface} plus test hooks for inspecting calls and\n * simulating SDK events.\n */\nexport interface MockAdaMessaging extends AdaMessagingInterface {\n\t/** Every method invocation, in call order. */\n\tcalls: RecordedAdaMessagingCall[];\n\t/**\n\t * Deliver an event to `subscribeEvent` and `subscribeAll` callbacks, as if\n\t * the SDK emitted it (e.g. `$emit(\"ada:ready\", { isRolledOut: true })`).\n\t * Routing matches the real SDK: keyed subscriptions match by prefix\n\t * (`\"ada:campaigns\"` catches `\"ada:campaigns:shown\"`), except the\n\t * transcript events `ada:message:sent`/`ada:message:received`, which reach\n\t * exact-key subscribers only and never `subscribeAll`.\n\t */\n\t$emit: (key: string, data?: unknown) => void;\n}\n\ninterface KeyedSubscription {\n\tkey: string;\n\tcallback: AdaSdkEventCallback;\n}\n\n// Mirrors EXACT_MATCH_EVENT_KEYS in client/client-host-runtime.ts: transcript\n// events reach exact-key subscribers only, never prefix or subscribeAll\n// subscribers. Duplicated (not imported) so the published testing entry stays\n// free of runtime modules; a drift test pins the mock against the real matcher.\nconst EXACT_MATCH_EVENT_KEYS = new Set([\n\t\"ada:message:sent\",\n\t\"ada:message:received\",\n]);\n\nfunction keyedSubscriptionMatches(\n\tsubscriptionKey: string,\n\teventKey: string,\n): boolean {\n\tif (EXACT_MATCH_EVENT_KEYS.has(eventKey)) {\n\t\treturn subscriptionKey === eventKey;\n\t}\n\t// Raw prefix match, same as the real SDK: \"ada:campaigns\" also catches\n\t// \"ada:campaigns:shown\" and underscore-suffixed keys.\n\treturn subscriptionKey === eventKey || eventKey.startsWith(subscriptionKey);\n}\n\nfunction toMetaFieldRecord(\n\tfields: Record<string, unknown>,\n): Record<string, MetaFieldValue> {\n\tconst record: Record<string, MetaFieldValue> = {};\n\tfor (const [key, value] of Object.entries(fields)) {\n\t\tif (\n\t\t\ttypeof value === \"string\" ||\n\t\t\ttypeof value === \"number\" ||\n\t\t\ttypeof value === \"boolean\" ||\n\t\t\tvalue === null\n\t\t) {\n\t\t\trecord[key] = value;\n\t\t}\n\t}\n\treturn record;\n}\n\n/**\n * Create an in-memory messaging-interface stand-in for unit-testing an\n * integration without loading the SDK from the CDN.\n *\n * Every method resolves, records itself in `calls`, and keeps just enough\n * state to behave like the real interface: `sendMessage` appends a\n * programmatic user message that `getMessages` returns, `open`/`close`/\n * `toggle` drive `isOpen` and `getInfo`, `setMetaFields` feeds\n * `getMetaFields` (sensitive fields are never returned, matching the real\n * SDK), and `$emit` fans out to `subscribeEvent`/`subscribeAll` callbacks.\n *\n * Pass `overrides` to replace any method (e.g. with `vi.fn()`); overridden\n * methods are still recorded in `calls`.\n */\nexport function createMockAdaMessaging(\n\toverrides: Partial<AdaMessagingInterface> = {},\n): MockAdaMessaging {\n\tconst calls: RecordedAdaMessagingCall[] = [];\n\tlet nextSubscriptionId = 1;\n\tlet nextMessageId = 1;\n\tlet chatOpen = false;\n\tlet conversationId: string | null = null;\n\tconst metaFields: Record<string, MetaFieldValue> = {};\n\tconst messages: PublicMessage[] = [];\n\tconst keyedSubscriptions = new Map<number, KeyedSubscription>();\n\tconst wildcardSubscriptions = new Map<\n\t\tnumber,\n\t\t(key: string, data: unknown) => void\n\t>();\n\n\tconst emit = (key: string, data?: unknown): void => {\n\t\tfor (const subscription of keyedSubscriptions.values()) {\n\t\t\tif (keyedSubscriptionMatches(subscription.key, key)) {\n\t\t\t\tsubscription.callback(data, { eventKey: key });\n\t\t\t}\n\t\t}\n\t\tif (EXACT_MATCH_EVENT_KEYS.has(key)) {\n\t\t\treturn;\n\t\t}\n\t\tfor (const callback of wildcardSubscriptions.values()) {\n\t\t\tcallback(key, data);\n\t\t}\n\t};\n\n\tconst clearTranscript = (): void => {\n\t\tmessages.length = 0;\n\t\tconversationId = null;\n\t};\n\n\tconst base: AdaMessagingInterface = {\n\t\tstart: async () => undefined,\n\t\tstop: async () => undefined,\n\t\ttoggle: async () => {\n\t\t\tchatOpen = !chatOpen;\n\t\t},\n\t\tdeleteHistory: async () => {\n\t\t\tclearTranscript();\n\t\t},\n\t\treset: async () => {\n\t\t\tclearTranscript();\n\t\t},\n\t\tsetMetaFields: async (fields) => {\n\t\t\tObject.assign(metaFields, toMetaFieldRecord(fields));\n\t\t},\n\t\t// Sensitive fields are accepted but never readable back, matching the\n\t\t// real SDK's getMetaFields contract.\n\t\tsetSensitiveMetaFields: async () => undefined,\n\t\tsetTestModeBanner: async () => undefined,\n\t\tgetInfo: async () => ({\n\t\t\tisChatOpen: chatOpen,\n\t\t\tisDrawerOpen: chatOpen,\n\t\t\thasActiveChatter: messages.length > 0,\n\t\t\thasClosedChat: false,\n\t\t}),\n\t\tgetMetaFields: async () => ({ ...metaFields }),\n\t\tisOpen: async () => chatOpen,\n\t\tgetConversation: async () => ({\n\t\t\tid: conversationId,\n\t\t\thandoff: { inLiveChat: false },\n\t\t}),\n\t\tgetMessages: async () => [...messages],\n\t\tsetComposerText: async () => undefined,\n\t\tselectQuickReply: async () => undefined,\n\t\tsetDelegate: () => undefined,\n\t\ttrackEvent: async () => undefined,\n\t\tsubscribeEvent: async (key, callback) => {\n\t\t\tconst id = nextSubscriptionId++;\n\t\t\tkeyedSubscriptions.set(id, { key, callback });\n\t\t\treturn id;\n\t\t},\n\t\tunsubscribeEvent: async (id) => {\n\t\t\tkeyedSubscriptions.delete(id);\n\t\t\twildcardSubscriptions.delete(id);\n\t\t},\n\t\tsubscribeAll: async (callback) => {\n\t\t\tconst id = nextSubscriptionId++;\n\t\t\twildcardSubscriptions.set(id, callback);\n\t\t\treturn id;\n\t\t},\n\t\topen: async () => {\n\t\t\tchatOpen = true;\n\t\t},\n\t\tclose: async () => {\n\t\t\tchatOpen = false;\n\t\t},\n\t\tsetLanguage: async () => undefined,\n\t\tsetTheme: async () => undefined,\n\t\tsetDeviceToken: async () => undefined,\n\t\t// Optional on AdaEmbedInterface (internal mobile-webview plumbing), but\n\t\t// Ada's own maintained test double still implements the full surface — the\n\t\t// types-drift guard requires the shipped mock to cover every interface\n\t\t// member so a customer's double never lags it.\n\t\tacknowledgeSessionMirrorClear: async () => undefined,\n\t\tdeliverSessionMirrorSeed: async () => undefined,\n\t\ttriggerPlaybook: async (_playbookId, options) => {\n\t\t\tchatOpen = true;\n\t\t\tObject.assign(metaFields, toMetaFieldRecord(options?.metaFields ?? {}));\n\t\t\tconversationId = conversationId ?? \"mock-conversation\";\n\t\t},\n\t\tsendMessage: async (body) => {\n\t\t\tconst id = `mock-message-${nextMessageId++}`;\n\t\t\tconversationId = conversationId ?? \"mock-conversation\";\n\t\t\tmessages.push({\n\t\t\t\tid,\n\t\t\t\trole: \"user\",\n\t\t\t\ttype: \"text\",\n\t\t\t\tbody,\n\t\t\t\tcreatedAt: Math.floor(Date.now() / 1000),\n\t\t\t\torigin: \"programmatic\",\n\t\t\t});\n\t\t\treturn { id };\n\t\t},\n\t\thandleNotification: async () => {\n\t\t\tchatOpen = true;\n\t\t},\n\t\trequestNotifications: async () => \"granted\",\n\t\tcreateProactive: async () => undefined,\n\t\ttriggerCampaign: async () => undefined,\n\t\tevaluateCampaignConditions: async () => undefined,\n\t\tcloseCampaign: async () => undefined,\n\t\ttriggerAnswer: async () => undefined,\n\t\ttriggerProactive: async () => undefined,\n\t\ttriggerGreeting: async () => undefined,\n\t\tdestroy: async () => {\n\t\t\tkeyedSubscriptions.clear();\n\t\t\twildcardSubscriptions.clear();\n\t\t\tchatOpen = false;\n\t\t},\n\t};\n\n\tconst definedOverrides = Object.fromEntries(\n\t\tObject.entries(overrides).filter(([, value]) => value !== undefined),\n\t);\n\tconst implementation = { ...base, ...definedOverrides };\n\tconst recorded = Object.fromEntries(\n\t\tObject.entries(implementation).map(([method, fn]) => [\n\t\t\tmethod,\n\t\t\t(...args: unknown[]) => {\n\t\t\t\tcalls.push({ method, args });\n\t\t\t\treturn (fn as (...callArgs: unknown[]) => unknown)(...args);\n\t\t\t},\n\t\t]),\n\t) as unknown as AdaMessagingInterface;\n\n\treturn { ...recorded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AE5D,CAAC,CAGU;AAAA,IAAU,OAAA;AAAA,IAAO,OAAO;AAAA,EAAK;AAC1C"}
1
+ {"version":3,"file":"testing.js","names":[],"sources":["../../../../shared/utils/src/browser-polyfills.ts","../../src/npm/testing.ts"],"sourcesContent":["/**\n * Defence in depth for engines just below the declared browser floor.\n * The floor is defined in `messaging/vite.browser-targets.mjs`.\n *\n * Internal Ada code should prefer direct helpers, such as `hasOwn(...)` from\n * `guards.ts`. Every Ada bundle includes these fallbacks, including the host-page\n * SDK. These fallbacks also ship inside the customer-held npm tarballs of the SDK\n * and bridge. Each fallback defines a member only when it is missing. These\n * fallbacks do not extend browser support below the floor required by the shipped CSS.\n */\n\nconst objectHasOwnProperty = Object.prototype.hasOwnProperty;\n\nfunction defineValue(\n\ttarget: object,\n\tname: PropertyKey,\n\tvalue: (...args: unknown[]) => unknown,\n): void {\n\tObject.defineProperty(target, name, {\n\t\tvalue,\n\t\tconfigurable: true,\n\t\twritable: true,\n\t});\n}\n\nif (!Object.hasOwn) {\n\tdefineValue(Object, \"hasOwn\", (object: unknown, key: unknown) => {\n\t\tif (object == null) {\n\t\t\tthrow new TypeError(\n\t\t\t\t\"ada browser-polyfills: Cannot convert undefined or null to object\",\n\t\t\t);\n\t\t}\n\t\treturn objectHasOwnProperty.call(Object(object), key as PropertyKey);\n\t});\n}\n\nfunction at<T>(\n\tthis: { length: number; [index: number]: T },\n\tindex: unknown,\n): T | undefined {\n\tconst length = Math.trunc(Number(this.length)) || 0;\n\tlet relativeIndex = Math.trunc(Number(index)) || 0;\n\tif (relativeIndex < 0) {\n\t\trelativeIndex += length;\n\t}\n\treturn relativeIndex < 0 || relativeIndex >= length\n\t\t? undefined\n\t\t: this[relativeIndex];\n}\n\nfunction stringAt(this: string, index: unknown): string | undefined {\n\tconst value = String(this);\n\tconst length = value.length;\n\tlet relativeIndex = Math.trunc(Number(index)) || 0;\n\tif (relativeIndex < 0) {\n\t\trelativeIndex += length;\n\t}\n\treturn relativeIndex < 0 || relativeIndex >= length\n\t\t? undefined\n\t\t: value.charAt(relativeIndex);\n}\n\nconst typedArrayConstructors = [\n\tglobalThis.Int8Array,\n\tglobalThis.Uint8Array,\n\tglobalThis.Uint8ClampedArray,\n\tglobalThis.Int16Array,\n\tglobalThis.Uint16Array,\n\tglobalThis.Int32Array,\n\tglobalThis.Uint32Array,\n\tglobalThis.Float32Array,\n\tglobalThis.Float64Array,\n\tglobalThis.BigInt64Array,\n\tglobalThis.BigUint64Array,\n].filter(Boolean);\n\nif (!Array.prototype.at) {\n\tdefineValue(Array.prototype, \"at\", at);\n}\n\nif (!String.prototype.at) {\n\tdefineValue(String.prototype, \"at\", stringAt);\n}\n\nfor (const TypedArrayConstructor of typedArrayConstructors) {\n\tconst prototype = TypedArrayConstructor.prototype;\n\tif (!prototype.at) {\n\t\tdefineValue(prototype, \"at\", at);\n\t}\n}\n","import type {\n\tAdaSdkEventCallback,\n\tMetaFieldValue,\n\tPublicMessage,\n} from \"../client/client-types\";\nimport type { AdaMessagingInterface } from \"./loader\";\n\n/** One recorded method invocation on a {@link MockAdaMessaging}. */\nexport interface RecordedAdaMessagingCall {\n\tmethod: string;\n\targs: unknown[];\n}\n\n/**\n * The mock returned by {@link createMockAdaMessaging}: the full\n * {@link AdaMessagingInterface} plus test hooks for inspecting calls and\n * simulating SDK events.\n */\nexport interface MockAdaMessaging extends AdaMessagingInterface {\n\t/** Every method invocation, in call order. */\n\tcalls: RecordedAdaMessagingCall[];\n\t/**\n\t * Deliver an event to `subscribeEvent` and `subscribeAll` callbacks, as if\n\t * the SDK emitted it (e.g. `$emit(\"ada:ready\", { isRolledOut: true })`).\n\t * Routing matches the real SDK: keyed subscriptions match by prefix\n\t * (`\"ada:campaigns\"` catches `\"ada:campaigns:shown\"`), except the\n\t * transcript events `ada:message:sent`/`ada:message:received`, which reach\n\t * exact-key subscribers only and never `subscribeAll`.\n\t */\n\t$emit: (key: string, data?: unknown) => void;\n}\n\ninterface KeyedSubscription {\n\tkey: string;\n\tcallback: AdaSdkEventCallback;\n}\n\n// Mirrors EXACT_MATCH_EVENT_KEYS in client/client-host-runtime.ts: transcript\n// events reach exact-key subscribers only, never prefix or subscribeAll\n// subscribers. Duplicated (not imported) so the published testing entry stays\n// free of runtime modules; a drift test pins the mock against the real matcher.\nconst EXACT_MATCH_EVENT_KEYS = new Set([\n\t\"ada:message:sent\",\n\t\"ada:message:received\",\n]);\n\nfunction keyedSubscriptionMatches(\n\tsubscriptionKey: string,\n\teventKey: string,\n): boolean {\n\tif (EXACT_MATCH_EVENT_KEYS.has(eventKey)) {\n\t\treturn subscriptionKey === eventKey;\n\t}\n\t// Raw prefix match, same as the real SDK: \"ada:campaigns\" also catches\n\t// \"ada:campaigns:shown\" and underscore-suffixed keys.\n\treturn subscriptionKey === eventKey || eventKey.startsWith(subscriptionKey);\n}\n\nfunction toMetaFieldRecord(\n\tfields: Record<string, unknown>,\n): Record<string, MetaFieldValue> {\n\tconst record: Record<string, MetaFieldValue> = {};\n\tfor (const [key, value] of Object.entries(fields)) {\n\t\tif (\n\t\t\ttypeof value === \"string\" ||\n\t\t\ttypeof value === \"number\" ||\n\t\t\ttypeof value === \"boolean\" ||\n\t\t\tvalue === null\n\t\t) {\n\t\t\trecord[key] = value;\n\t\t}\n\t}\n\treturn record;\n}\n\nconst resolveVoid = async (): Promise<void> => undefined;\n\n/**\n * Create an in-memory messaging-interface stand-in for unit-testing an\n * integration without loading the SDK from the CDN.\n *\n * Every method resolves, records itself in `calls`, and keeps just enough\n * state to behave like the real interface: `sendMessage` appends a\n * programmatic user message that `getMessages` returns, `open`/`close`/\n * `toggle` drive `isOpen` and `getInfo`, `setMetaFields` feeds\n * `getMetaFields` (sensitive fields are never returned, matching the real\n * SDK), and `$emit` fans out to `subscribeEvent`/`subscribeAll` callbacks.\n *\n * Pass `overrides` to replace any method (e.g. with `vi.fn()`); overridden\n * methods are still recorded in `calls`.\n */\nexport function createMockAdaMessaging(\n\toverrides: Partial<AdaMessagingInterface> = {},\n): MockAdaMessaging {\n\tconst calls: RecordedAdaMessagingCall[] = [];\n\tlet nextSubscriptionId = 1;\n\tlet nextMessageId = 1;\n\tlet chatOpen = false;\n\tlet conversationId: string | null = null;\n\tconst metaFields: Record<string, MetaFieldValue> = {};\n\tconst messages: PublicMessage[] = [];\n\tconst keyedSubscriptions = new Map<number, KeyedSubscription>();\n\tconst wildcardSubscriptions = new Map<\n\t\tnumber,\n\t\t(key: string, data: unknown) => void\n\t>();\n\n\tconst emit = (key: string, data?: unknown): void => {\n\t\tfor (const subscription of keyedSubscriptions.values()) {\n\t\t\tif (keyedSubscriptionMatches(subscription.key, key)) {\n\t\t\t\tsubscription.callback(data, { eventKey: key });\n\t\t\t}\n\t\t}\n\t\tif (EXACT_MATCH_EVENT_KEYS.has(key)) {\n\t\t\treturn;\n\t\t}\n\t\tfor (const callback of wildcardSubscriptions.values()) {\n\t\t\tcallback(key, data);\n\t\t}\n\t};\n\n\tconst clearTranscript = (): void => {\n\t\tmessages.length = 0;\n\t\tconversationId = null;\n\t};\n\n\tconst base: AdaMessagingInterface = {\n\t\tstart: resolveVoid,\n\t\tstop: resolveVoid,\n\t\ttoggle: async () => {\n\t\t\tchatOpen = !chatOpen;\n\t\t},\n\t\tdeleteHistory: async () => {\n\t\t\tclearTranscript();\n\t\t},\n\t\treset: async () => {\n\t\t\tclearTranscript();\n\t\t},\n\t\tsetMetaFields: async (fields) => {\n\t\t\tObject.assign(metaFields, toMetaFieldRecord(fields));\n\t\t},\n\t\t// Sensitive fields are accepted but never readable back, matching the\n\t\t// real SDK's getMetaFields contract.\n\t\tsetSensitiveMetaFields: resolveVoid,\n\t\tsetTestModeBanner: resolveVoid,\n\t\tgetInfo: async () => ({\n\t\t\tisChatOpen: chatOpen,\n\t\t\tisDrawerOpen: chatOpen,\n\t\t\thasActiveChatter: messages.length > 0,\n\t\t\thasClosedChat: false,\n\t\t}),\n\t\tgetMetaFields: async () => ({ ...metaFields }),\n\t\tisOpen: async () => chatOpen,\n\t\tgetConversation: async () => ({\n\t\t\tid: conversationId,\n\t\t\thandoff: { inLiveChat: false },\n\t\t}),\n\t\tgetMessages: async () => [...messages],\n\t\tsetComposerText: resolveVoid,\n\t\tselectQuickReply: resolveVoid,\n\t\tsetDelegate: () => undefined,\n\t\ttrackEvent: resolveVoid,\n\t\tsubscribeEvent: async (key, callback) => {\n\t\t\tconst id = nextSubscriptionId++;\n\t\t\tkeyedSubscriptions.set(id, { key, callback });\n\t\t\treturn id;\n\t\t},\n\t\tunsubscribeEvent: async (id) => {\n\t\t\tkeyedSubscriptions.delete(id);\n\t\t\twildcardSubscriptions.delete(id);\n\t\t},\n\t\tsubscribeAll: async (callback) => {\n\t\t\tconst id = nextSubscriptionId++;\n\t\t\twildcardSubscriptions.set(id, callback);\n\t\t\treturn id;\n\t\t},\n\t\topen: async () => {\n\t\t\tchatOpen = true;\n\t\t},\n\t\tclose: async () => {\n\t\t\tchatOpen = false;\n\t\t},\n\t\tsetLanguage: resolveVoid,\n\t\tsetTheme: resolveVoid,\n\t\tsetDeviceToken: resolveVoid,\n\t\t// Optional on AdaEmbedInterface (internal mobile-webview plumbing), but\n\t\t// Ada's own maintained test double still implements the full surface — the\n\t\t// types-drift guard requires the shipped mock to cover every interface\n\t\t// member so a customer's double never lags it.\n\t\tacknowledgeSessionMirrorClear: resolveVoid,\n\t\tdeliverSessionMirrorSeed: resolveVoid,\n\t\ttriggerPlaybook: async (_playbookId, options) => {\n\t\t\tchatOpen = true;\n\t\t\tObject.assign(metaFields, toMetaFieldRecord(options?.metaFields ?? {}));\n\t\t\tconversationId = conversationId ?? \"mock-conversation\";\n\t\t},\n\t\tsendMessage: async (body) => {\n\t\t\tconst id = `mock-message-${nextMessageId++}`;\n\t\t\tconversationId = conversationId ?? \"mock-conversation\";\n\t\t\tmessages.push({\n\t\t\t\tid,\n\t\t\t\trole: \"user\",\n\t\t\t\ttype: \"text\",\n\t\t\t\tbody,\n\t\t\t\tcreatedAt: Math.floor(Date.now() / 1000),\n\t\t\t\torigin: \"programmatic\",\n\t\t\t});\n\t\t\treturn { id };\n\t\t},\n\t\thandleNotification: async () => {\n\t\t\tchatOpen = true;\n\t\t},\n\t\trequestNotifications: async () => \"granted\",\n\t\tcreateProactive: resolveVoid,\n\t\ttriggerCampaign: resolveVoid,\n\t\tevaluateCampaignConditions: resolveVoid,\n\t\tcloseCampaign: resolveVoid,\n\t\tsetPageUrl: resolveVoid,\n\t\ttriggerAnswer: resolveVoid,\n\t\ttriggerProactive: resolveVoid,\n\t\ttriggerGreeting: resolveVoid,\n\t\tdestroy: async () => {\n\t\t\tkeyedSubscriptions.clear();\n\t\t\twildcardSubscriptions.clear();\n\t\t\tchatOpen = false;\n\t\t},\n\t};\n\n\tconst definedOverrides = Object.fromEntries(\n\t\tObject.entries(overrides).filter(([, value]) => value !== undefined),\n\t);\n\tconst implementation = { ...base, ...definedOverrides };\n\tconst recorded = Object.fromEntries(\n\t\tObject.entries(implementation).map(([method, fn]) => [\n\t\t\tmethod,\n\t\t\t(...args: unknown[]) => {\n\t\t\t\tcalls.push({ method, args });\n\t\t\t\treturn (fn as (...callArgs: unknown[]) => unknown)(...args);\n\t\t\t},\n\t\t]),\n\t) as unknown as AdaMessagingInterface;\n\n\treturn { ...recorded, calls, $emit: emit };\n}\n"],"mappings":"AAWA,IAAM,IAAuB,OAAO,UAAU;AAE9C,SAAS,EACR,GACA,GACA,GACO;AACP,SAAO,eAAe,GAAQ,GAAM;AAAA,IACnC,OAAA;AAAA,IACA,cAAc;AAAA,IACd,UAAU;AAAA,EACX,CAAC;AACF;AAEK,OAAO,UACX,EAAY,QAAQ,UAAA,CAAW,GAAiB,MAAiB;AAChE,MAAI,KAAU,KACb,OAAM,IAAI,UACT,mEACD;AAED,SAAO,EAAqB,KAAK,OAAO,CAAM,GAAG,CAAkB;AACpE,CAAC;AAGF,SAAS,EAER,GACgB;AAChB,QAAM,IAAS,KAAK,MAAM,OAAO,KAAK,MAAM,CAAC,KAAK;AAClD,MAAI,IAAgB,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