@drip-apex/sdk 0.1.0 → 0.3.0

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 (246) hide show
  1. package/README.md +5 -0
  2. package/dist/bundle-report.json +584 -226
  3. package/dist/define.cjs +123 -0
  4. package/dist/define.cjs.map +7 -0
  5. package/dist/define.mjs +102 -0
  6. package/dist/define.mjs.map +7 -0
  7. package/dist/drip.cjs +19283 -0
  8. package/dist/drip.cjs.map +7 -0
  9. package/dist/drip.debug.js +1 -1
  10. package/dist/drip.debug.js.map +1 -1
  11. package/dist/drip.heatmap.js +1 -1
  12. package/dist/drip.heatmap.js.map +1 -1
  13. package/dist/drip.js +1 -1
  14. package/dist/drip.js.map +1 -1
  15. package/dist/drip.live.js +1 -1
  16. package/dist/drip.live.js.map +1 -1
  17. package/dist/drip.mjs +19267 -0
  18. package/dist/drip.mjs.map +7 -0
  19. package/dist/drip.replay-recorder.js +2 -0
  20. package/dist/drip.replay-recorder.js.map +1 -0
  21. package/dist/editor.js +147 -142
  22. package/dist/editor.js.map +4 -4
  23. package/dist/flags.cjs +1788 -0
  24. package/dist/flags.cjs.map +7 -0
  25. package/dist/flags.mjs +1765 -0
  26. package/dist/flags.mjs.map +7 -0
  27. package/dist/index.mjs +12 -0
  28. package/dist/index.mjs.map +2 -2
  29. package/dist/metafiles/define.cjs.meta.json +28 -0
  30. package/dist/metafiles/define.mjs.meta.json +32 -0
  31. package/dist/metafiles/drip.cjs.meta.json +3193 -0
  32. package/dist/metafiles/drip.debug.meta.json +2859 -574
  33. package/dist/metafiles/drip.heatmap.meta.json +2732 -460
  34. package/dist/metafiles/drip.live.meta.json +2732 -460
  35. package/dist/metafiles/drip.meta.json +2859 -574
  36. package/dist/metafiles/drip.mjs.meta.json +3235 -0
  37. package/dist/metafiles/drip.replay-recorder.meta.json +82 -0
  38. package/dist/metafiles/editor.meta.json +67 -27
  39. package/dist/metafiles/flags.cjs.meta.json +220 -0
  40. package/dist/metafiles/flags.mjs.meta.json +225 -0
  41. package/dist/metafiles/index.meta.json +2717 -491
  42. package/dist/metafiles/index.mjs.meta.json +14 -4
  43. package/dist/react/index.js +16636 -13533
  44. package/dist/react/index.js.map +4 -4
  45. package/dist/sri.json +20 -15
  46. package/dist/types/activation-runtime.d.ts +91 -0
  47. package/dist/types/analytics-runtime.d.ts +166 -0
  48. package/dist/types/antiflicker.d.ts +9 -3
  49. package/dist/types/assignment-cookie-sync.d.ts +31 -0
  50. package/dist/types/assignment-runtime.d.ts +257 -0
  51. package/dist/types/assignment-store.d.ts +4 -8
  52. package/dist/types/bucket.d.ts +1 -2
  53. package/dist/types/compact-store.d.ts +1 -0
  54. package/dist/types/config-runtime.d.ts +313 -0
  55. package/dist/types/consent-evaluation.d.ts +28 -0
  56. package/dist/types/css.d.ts +5 -3
  57. package/dist/types/debug-loader.d.ts +2 -0
  58. package/dist/types/decide-assignments.d.ts +31 -0
  59. package/dist/types/delivery-timing.d.ts +8 -0
  60. package/dist/types/early-interaction-capture.d.ts +79 -0
  61. package/dist/types/early-reassert.d.ts +32 -0
  62. package/dist/types/edge-runtime.d.ts +11 -0
  63. package/dist/types/editor/api.d.ts +3 -0
  64. package/dist/types/editor/controller.d.ts +3 -1
  65. package/dist/types/editor/publication-result.d.ts +11 -0
  66. package/dist/types/editor/types.d.ts +2 -1
  67. package/dist/types/editor/view-kit.d.ts +1 -1
  68. package/dist/types/endpoint.d.ts +8 -0
  69. package/dist/types/exclusion-groups.d.ts +4 -7
  70. package/dist/types/flags.d.ts +2 -0
  71. package/dist/types/goal-eligibility.d.ts +4 -0
  72. package/dist/types/goals.d.ts +10 -1
  73. package/dist/types/guards.d.ts +7 -7
  74. package/dist/types/handover.d.ts +12 -1
  75. package/dist/types/hash.d.ts +8 -4
  76. package/dist/types/hydration.d.ts +2 -1
  77. package/dist/types/index.d.ts +24 -128
  78. package/dist/types/init-test-helpers.d.ts +48 -0
  79. package/dist/types/inline-bootstrap.d.ts +26 -0
  80. package/dist/types/js.d.ts +3 -1
  81. package/dist/types/money.d.ts +12 -0
  82. package/dist/types/mutate.d.ts +45 -6
  83. package/dist/types/performance.d.ts +2 -0
  84. package/dist/types/persistence-decoders.d.ts +12 -0
  85. package/dist/types/public-api.d.ts +209 -0
  86. package/dist/types/qa-assistant-state.d.ts +34 -0
  87. package/dist/types/react/index.d.ts +28 -3
  88. package/dist/types/reassert-sentinel.d.ts +6 -0
  89. package/dist/types/redirect.d.ts +48 -0
  90. package/dist/types/replay-recorder-entry.d.ts +1 -0
  91. package/dist/types/replay-signal-state.d.ts +6 -0
  92. package/dist/types/replay-signals.d.ts +13 -0
  93. package/dist/types/replay.d.ts +110 -0
  94. package/dist/types/router.d.ts +12 -2
  95. package/dist/types/runtime-state.d.ts +166 -0
  96. package/dist/types/sanitize.d.ts +1 -0
  97. package/dist/types/shadow.d.ts +3 -0
  98. package/dist/types/shopify-cart.d.ts +25 -1
  99. package/dist/types/storefront-vitals.d.ts +24 -0
  100. package/dist/types/targeting-diagnostics.d.ts +1 -0
  101. package/dist/types/targeting.d.ts +16 -2
  102. package/dist/types/track.d.ts +15 -1
  103. package/dist/types/types.d.ts +115 -9
  104. package/dist/types/wait.d.ts +14 -1
  105. package/dist/types/weekday-schedule.d.ts +3 -0
  106. package/package.json +17 -8
  107. package/src/activation-runtime.ts +2737 -0
  108. package/src/analytics-runtime.ts +2175 -0
  109. package/src/antiflicker.test.ts +216 -44
  110. package/src/antiflicker.ts +103 -28
  111. package/src/artifact-concurrency.test.ts +1091 -0
  112. package/src/assignment-cookie-sync.test.ts +202 -0
  113. package/src/assignment-cookie-sync.ts +189 -0
  114. package/src/assignment-runtime.ts +3204 -0
  115. package/src/assignment-store.test.ts +56 -0
  116. package/src/assignment-store.ts +7 -38
  117. package/src/bucket.ts +3 -18
  118. package/src/commerce-analytics-lifecycle.test.ts +75 -15
  119. package/src/commerce-config-lifecycle.test.ts +81 -1
  120. package/src/commerce-price-preserve.test.ts +133 -0
  121. package/src/commerce-price.test.ts +97 -0
  122. package/src/commerce-price.ts +74 -20
  123. package/src/commerce-shipping.test.ts +53 -0
  124. package/src/commerce-shipping.ts +5 -11
  125. package/src/compact-store.ts +15 -0
  126. package/src/config-fetch.test.ts +480 -9
  127. package/src/config-runtime.ts +2071 -0
  128. package/src/consent-evaluation-borlabs.test.ts +41 -0
  129. package/src/consent-evaluation-cookiescript.test.ts +50 -0
  130. package/src/consent-evaluation.ts +151 -0
  131. package/src/css.test.ts +30 -0
  132. package/src/css.ts +120 -6
  133. package/src/cwv.test.ts +60 -77
  134. package/src/debug-loader.test.ts +214 -0
  135. package/src/debug-loader.ts +41 -0
  136. package/src/decide-assignments.test.ts +196 -0
  137. package/src/decide-assignments.ts +204 -0
  138. package/src/delivery-timing.test.ts +104 -0
  139. package/src/delivery-timing.ts +89 -0
  140. package/src/early-interaction-capture.test.ts +451 -0
  141. package/src/early-interaction-capture.ts +230 -0
  142. package/src/early-reassert.test.ts +207 -0
  143. package/src/early-reassert.ts +152 -0
  144. package/src/edge-adoption.test.ts +435 -0
  145. package/src/edge-runtime.ts +30 -0
  146. package/src/editor/api.test.ts +109 -0
  147. package/src/editor/api.ts +34 -3
  148. package/src/editor/controller.test.ts +297 -14
  149. package/src/editor/controller.ts +69 -5
  150. package/src/editor/index.test.ts +2 -0
  151. package/src/editor/index.ts +1 -0
  152. package/src/editor/publication-result.ts +58 -0
  153. package/src/editor/types.ts +10 -1
  154. package/src/editor/view-kit.ts +2 -1
  155. package/src/editor/view.test.ts +108 -0
  156. package/src/editor/view.ts +49 -7
  157. package/src/endpoint.test.ts +15 -0
  158. package/src/endpoint.ts +10 -0
  159. package/src/exclusion-groups.ts +8 -18
  160. package/src/flags.test.ts +88 -1
  161. package/src/flags.ts +29 -29
  162. package/src/global-runtime-reconciler.test.ts +271 -0
  163. package/src/goal-eligibility.test.ts +29 -0
  164. package/src/goal-eligibility.ts +17 -0
  165. package/src/goals.test.ts +144 -1
  166. package/src/goals.ts +97 -18
  167. package/src/guards.test.ts +99 -1
  168. package/src/guards.ts +34 -15
  169. package/src/handover-cache-order.test.ts +6 -3
  170. package/src/handover.test.ts +154 -8
  171. package/src/handover.ts +122 -12
  172. package/src/hash.ts +29 -54
  173. package/src/holdout.test.ts +26 -0
  174. package/src/hydration.test.ts +73 -2
  175. package/src/hydration.ts +18 -9
  176. package/src/index.ts +130 -7287
  177. package/src/init-analytics.test.ts +1694 -0
  178. package/src/init-anti-flicker.test.ts +1211 -0
  179. package/src/init-cart-attributes.test.ts +2003 -0
  180. package/src/init-config-resolution.test.ts +999 -0
  181. package/src/init-consent.test.ts +971 -0
  182. package/src/init-empty.test.ts +11 -5406
  183. package/src/init-integrations.test.ts +846 -0
  184. package/src/init-page-activation.test.ts +5064 -0
  185. package/src/init-qa-loading.test.ts +740 -0
  186. package/src/init-redirects.test.ts +2156 -0
  187. package/src/init-test-helpers.ts +287 -0
  188. package/src/inline-bootstrap.test.ts +184 -0
  189. package/src/inline-bootstrap.ts +73 -0
  190. package/src/js.test.ts +51 -1
  191. package/src/js.ts +86 -2
  192. package/src/money.test.ts +55 -1
  193. package/src/money.ts +104 -2
  194. package/src/money.web-parity.contract.test.ts +85 -0
  195. package/src/mutate.test.ts +474 -10
  196. package/src/mutate.ts +739 -230
  197. package/src/page-trigger.test.ts +218 -8
  198. package/src/performance.ts +10 -0
  199. package/src/persistence-decoders.ts +18 -0
  200. package/src/public-api.ts +1828 -0
  201. package/src/qa-assistant-state.test.ts +249 -3
  202. package/src/qa-assistant-state.ts +146 -6
  203. package/src/qa-assistant-view.test.ts +220 -2
  204. package/src/qa-assistant-view.ts +102 -5
  205. package/src/react/index.test.tsx +37 -0
  206. package/src/react/index.tsx +19 -3
  207. package/src/reassert-sentinel.test.ts +155 -1
  208. package/src/reassert-sentinel.ts +168 -8
  209. package/src/redirect.test.ts +541 -0
  210. package/src/redirect.ts +572 -0
  211. package/src/replay-recorder-entry.ts +115 -0
  212. package/src/replay-signal-state.ts +100 -0
  213. package/src/replay-signals.test.ts +249 -0
  214. package/src/replay-signals.ts +151 -0
  215. package/src/replay.test.ts +764 -0
  216. package/src/replay.ts +514 -0
  217. package/src/router.test.ts +61 -2
  218. package/src/router.ts +50 -12
  219. package/src/runtime-state.ts +507 -0
  220. package/src/runtime.test.ts +174 -7
  221. package/src/runtime.ts +88 -14
  222. package/src/sanitize.test.ts +34 -0
  223. package/src/sanitize.ts +23 -12
  224. package/src/shadow.test.ts +187 -0
  225. package/src/shadow.ts +99 -0
  226. package/src/shopify-cart.test.ts +733 -23
  227. package/src/shopify-cart.ts +402 -49
  228. package/src/storefront-vitals.test.ts +217 -0
  229. package/src/storefront-vitals.ts +206 -0
  230. package/src/surface-signals.ts +6 -0
  231. package/src/targeting-conformance.test.ts +9 -0
  232. package/src/targeting-diagnostics.ts +38 -8
  233. package/src/targeting-parity-corpus.json +559 -0
  234. package/src/targeting-parity-corpus.test.ts +18 -0
  235. package/src/targeting.detailed.test.ts +105 -0
  236. package/src/targeting.test.ts +211 -0
  237. package/src/targeting.ts +88 -207
  238. package/src/track.test.ts +147 -0
  239. package/src/track.ts +125 -26
  240. package/src/types.ts +120 -13
  241. package/src/wait.test.ts +23 -0
  242. package/src/wait.ts +129 -13
  243. package/src/weekday-delivery.test.ts +56 -0
  244. package/src/weekday-schedule-parity-corpus.json +92 -0
  245. package/src/weekday-schedule.test.ts +69 -0
  246. package/src/weekday-schedule.ts +20 -0
@@ -1,9 +1,7 @@
1
1
  import type { Assignment, ExclusionGroupConfig } from "./types";
2
+ import { type PersistedGroupSelection } from "./persistence-decoders";
3
+ export { decodePersistedGroupSelections, type PersistedGroupSelection } from "./persistence-decoders";
2
4
  /** A remembered group decision: which member won and at what group epoch. */
3
- export type PersistedGroupSelection = {
4
- experimentId: string;
5
- epoch: number;
6
- };
7
5
  /** Pluggable persistence so the runtime uses browser storage and tests use memory. */
8
6
  export interface GroupStickyStore {
9
7
  read(groupId: string): PersistedGroupSelection | null;
@@ -12,7 +10,7 @@ export interface GroupStickyStore {
12
10
  type CompactSelection = [string, number];
13
11
  type CompactStore = Record<string, CompactSelection>;
14
12
  declare function normalizeEpoch(epoch: number | null | undefined): number;
15
- declare function parseStore(raw: string | null): CompactStore;
13
+ export declare function decodeCompactGroupStore(raw: string | null): CompactStore;
16
14
  /** Browser-backed store (localStorage + cookie mirror) used by the live runtime. */
17
15
  export declare const browserGroupStickyStore: GroupStickyStore;
18
16
  /** Remove consent-gated group stickiness from both browser persistence planes. */
@@ -53,7 +51,6 @@ export declare function resolveExclusionGroups(assignments: Assignment[], groups
53
51
  export declare const __exclusionGroupInternals: {
54
52
  STORAGE_KEY: string;
55
53
  COOKIE_NAME: string;
56
- parseStore: typeof parseStore;
54
+ parseStore: typeof decodeCompactGroupStore;
57
55
  normalizeEpoch: typeof normalizeEpoch;
58
56
  };
59
- export {};
@@ -21,6 +21,8 @@ export interface FlagContext {
21
21
  url?: string;
22
22
  attributes?: Record<string, unknown>;
23
23
  userId?: string;
24
+ /** QA variation overrides use the same weekday bypass as assignment delivery. */
25
+ forceMap?: Record<string, string>;
24
26
  }
25
27
  /**
26
28
  * Evaluate whether a feature flag is enabled.
@@ -0,0 +1,4 @@
1
+ export declare function goalIsEligible(goal: {
2
+ pageId?: string | null;
3
+ urlPattern?: string | null;
4
+ }, pageActiveIds: ReadonlySet<string>, href: string): boolean;
@@ -1,9 +1,18 @@
1
1
  import { Goal, Assignment } from "./types";
2
2
  type GoalCallback = (goalId: string, assignment: Assignment, data?: Record<string, unknown>) => void;
3
+ /**
4
+ * Identity of the goal wiring the given inputs would produce. The runtime
5
+ * diffs this set to decide whether a re-wire is needed, so wiring stays
6
+ * idempotent across repeated reconciliation passes.
7
+ */
8
+ export declare function goalWiringKeys(assignments: Assignment[], experiments: {
9
+ id: string;
10
+ goals?: Goal[];
11
+ }[], pageActiveIds?: ReadonlySet<string>): Set<string>;
3
12
  export declare function setupGoals(assignments: Assignment[], experiments: {
4
13
  id: string;
5
14
  goals?: Goal[];
6
- }[], callback: GoalCallback): void;
15
+ }[], callback: GoalCallback, pageActiveIds?: ReadonlySet<string>): void;
7
16
  export declare function triggerGoal(goalId: string, assignments: Assignment[], experiments: {
8
17
  id: string;
9
18
  goals?: Goal[];
@@ -6,18 +6,18 @@ export declare function isOptedOut(options?: {
6
6
  }): boolean;
7
7
  export declare function isScreenshotMode(): boolean;
8
8
  declare function parseForceParams(params: URLSearchParams): Record<string, string> | null;
9
- export declare function parseForceParam(options?: {
10
- cookieFallback?: boolean;
11
- }): Record<string, string> | null;
9
+ export declare function hasExplicitForceParam(): boolean;
10
+ export declare function clearQaForceFromUrl(): boolean;
11
+ export declare function parseForceParam(): Record<string, string> | null;
12
12
  declare function parseForceString(value: string): Record<string, string> | null;
13
- export declare function isQaMode(options?: {
14
- cookieFallback?: boolean;
15
- }): boolean;
13
+ export declare function isQaMode(): boolean;
16
14
  /**
17
15
  * Persist the force map in a cookie so QA sessions survive navigation.
18
- * Cookie expires after 30 minutes.
16
+ * Cookie expires at most 30 minutes after the latest QA page load or assistant force.
19
17
  */
20
18
  export declare function persistQaForce(forceMap: Record<string, string>): void;
19
+ /** Persist an explicit URL force or renew an existing cookie-backed force. */
20
+ export declare function persistUrlQaForce(forceMap: Record<string, string>): void;
21
21
  declare function sanitizeQaSessionId(value: string | null): string | null;
22
22
  export declare function getQaSessionId(fallback: () => string, options?: {
23
23
  storageAllowed?: boolean;
@@ -2,9 +2,20 @@ import type { Assignment, ExternalTrackingSettings } from "./types";
2
2
  export type HandoverData = {
3
3
  visitorId?: string;
4
4
  forceMap?: Record<string, string>;
5
+ redirectAttribution?: {
6
+ experimentId: string;
7
+ variationId: string;
8
+ destinationUrl: string;
9
+ issuedAt: number;
10
+ token: string;
11
+ };
5
12
  };
6
13
  export declare function handoverMintTimeoutMs(settings?: ExternalTrackingSettings): number;
14
+ /** Decode a handover token carried by another runtime transport. */
15
+ export declare function readBucketingHandoverPayload(value: string): HandoverData | null;
16
+ export declare function bucketingHandoverExpiresAtMs(value: string): number | null;
7
17
  export declare function readBucketingHandover(settings: ExternalTrackingSettings | undefined, shopId: string, verifyToken: (token: string) => Promise<unknown>): Promise<HandoverData | null>;
18
+ export declare function verifyBucketingHandoverToken(value: string, shopId: string, verifyToken: (token: string) => Promise<unknown>): Promise<HandoverData | null>;
8
19
  export declare function hasBucketingHandover(settings?: ExternalTrackingSettings): boolean;
9
- export declare function createBucketingHandoverPayload(visitorId: string, assignments: Assignment[], settings?: ExternalTrackingSettings): string;
20
+ export declare function createBucketingHandoverPayload(visitorId: string, assignments: Array<Pick<Assignment, "experimentId" | "variationId">>, settings?: ExternalTrackingSettings): string;
10
21
  export declare function installBucketingHandover(settings: ExternalTrackingSettings | undefined, getPayload: () => string | null, mintPayload?: () => Promise<string | null>): () => void;
@@ -1,7 +1,10 @@
1
+ export { hashToFloat, murmurhash3_32_gc, variationHashToFloat } from "@drip/shared-runtime/bucketing";
1
2
  type StorageMode = "localStorage" | "sessionStorage" | "cookie" | "memory";
2
- export declare function murmurhash3_32_gc(key: string, seed?: number): number;
3
- export declare function hashToFloat(seed: string, value: string): number;
4
- export declare function variationHashToFloat(experimentId: string, value: string): number;
3
+ export declare function isHoldoutVisitor(config: {
4
+ holdout_v1_enabled?: unknown;
5
+ holdout_pct?: unknown;
6
+ }, visitorId: string): boolean;
7
+ export declare function applyHoldoutGate<T>(config: Parameters<typeof isHoldoutVisitor>[0], visitorId: string, values: T[]): T[];
5
8
  export declare function configureIdentityStorage(settings?: {
6
9
  storageMode?: StorageMode;
7
10
  encodeStorageValues?: boolean;
@@ -14,6 +17,7 @@ export declare function configureIdentityStorage(settings?: {
14
17
  */
15
18
  export declare function lifetimeIdentityStorage(): Storage | null;
16
19
  export declare function getUserId(provided?: string): string;
20
+ /** Reads an existing durable identity without minting or persisting a new one. */
21
+ export declare function getPersistedUserId(): string | null;
17
22
  export declare function getEphemeralUserId(provided?: string): string;
18
23
  export declare function adoptUserId(value: string): void;
19
- export {};
@@ -6,6 +6,7 @@ export declare function hasMutationHold(): boolean;
6
6
  export declare function signalHydrated(): void;
7
7
  export declare function awaitHydration(timeoutMs: number, options?: {
8
8
  waitForHydration?: boolean;
9
- }): Promise<void>;
9
+ recordMetrics?: boolean;
10
+ }, outerStarted?: number): Promise<void>;
10
11
  export declare function resetHydrationState(): void;
11
12
  export declare function assignmentsHaveVisualWork(assignments: Assignment[], priceSettings?: CommercePriceSettings): boolean;
@@ -1,144 +1,40 @@
1
- import { type CartAttributeEntry } from "./shopify-cart";
2
- import { type ApexRuntimeTools } from "./runtime-tools";
3
- import { ActivationMode, AntiFlickerMode, Assignment, ActivationDiagnostics, ConfigProfile, ConsentModeSettings, CustomJsPolicy, DebugSettings, ExecutionMode, Experiment, ExclusionGroupConfig, ExclusionGroupMemberConfig, Goal, InitConfig, PageTargetingRule, PageTriggerMode, PageTriggerSettings, PerfFeatureFlag, PerfFeatureFlags, PlatformHint, ProjectPrerequisites, RouterMode, SpaSettings, ExternalTrackingSettings, ProjectCodeSettings, RuntimeEnvironmentSettings, SdkDiagnostics, BucketingCleanupSettings, DataProtectionSettings, TrackEvent, TrackingStart, Variation } from "./types";
4
- type FetchAttemptInfo = {
5
- attempt: number;
6
- elapsedMs: number;
7
- error?: string;
8
- status?: number;
9
- timedOut?: boolean;
10
- };
11
- type FetchRetryOptions = {
12
- timeoutMs?: number;
13
- firstAttemptTimeoutMs?: number;
14
- slowMs?: number;
15
- onAttemptStart?: (attempt: number) => void;
16
- onAttemptEnd?: (info: FetchAttemptInfo) => void;
17
- onSlow?: (info: {
18
- attempt: number;
19
- elapsedMs: number;
20
- }) => void;
21
- };
22
- declare function fetchWithTimeout(url: string, timeoutMs: number): Promise<Response>;
23
- declare function fetchWithRetry(url: string, retries?: number, delayMs?: number, options?: FetchRetryOptions): Promise<Response>;
24
- declare function normalizePageApiName(value: unknown): string;
25
- declare function triggerPage(apiName: unknown, active?: unknown): void;
26
- declare function installPageTriggerRule(rule: PageTargetingRule, onChange: () => void): () => void;
27
- type OrderIdentityPlatform = "shopify" | "shopware" | "woocommerce" | "centra" | "custom";
28
- type QaAssistantRuntimeSnapshot = {
29
- config: InitConfig | null;
30
- assignments: Assignment[];
31
- activationDiagnostics: ActivationDiagnostics;
32
- forceMap: Record<string, string> | null;
33
- platform: PlatformHint;
34
- qaMode: boolean;
35
- orderIdentity: {
36
- platform: OrderIdentityPlatform;
37
- platformOrderId: string | null;
38
- orderNumber: string | null;
39
- } | null;
40
- };
41
- declare function getConfigCacheKey(shopId: string, environmentKey?: string): string;
42
- declare function withRuntimeSettings(config: InitConfig, runtime: unknown, profile?: InitConfig["profile"]): InitConfig;
43
- export declare function evaluate(experiments: Experiment[], context?: {
44
- url?: string;
45
- attributes?: Record<string, unknown>;
46
- userId?: string;
47
- persistSignals?: boolean;
48
- exclusionGroups?: ExclusionGroupConfig[];
49
- }): Assignment[];
50
- export declare function __getQaAssistantRuntimeSnapshot(): QaAssistantRuntimeSnapshot;
51
- export declare function __subscribeQaAssistantRuntime(listener: () => void): () => void;
52
- export declare function __forceQaAssistantVariation(experimentId: string, variationId: string): void;
53
- export declare function __resetQaAssistantForce(experimentId?: string): void;
54
- export declare function init(config: InitConfig): Assignment[];
55
- export declare function track(type: string, data?: Record<string, unknown>, experimentId?: string, variationId?: string): void;
56
- /**
57
- * Track a virtual funnel step that has no reliable browser event by default,
58
- * such as a postcode form submit, embedded quiz step, or third-party handoff.
59
- */
60
- export declare function trackStep(name: string, data?: Record<string, unknown>): void;
61
- export declare function trackGoal(goalId: string, data?: Record<string, unknown>): void;
62
- export declare function setConsent(granted: boolean): void;
63
- export declare function hold(): number;
64
- export declare function release(): number;
65
- export declare function hydrated(): void;
66
- export declare function recheckPrerequisites(): void;
67
- export declare function reInit(forceReapply?: boolean): Assignment[];
68
- /**
69
- * Track a revenue/purchase event. Convenience method that fires a "purchase" event
70
- * with revenue data for all active experiments.
71
- *
72
- * Usage: drip.trackRevenue(49.99) or drip.trackRevenue(49.99, { orderId: "123", currency: "EUR" })
73
- */
74
- export type RevenueEventData = Record<string, unknown> & {
75
- currency?: string;
76
- };
77
- export declare function trackRevenue(revenue: number, data?: RevenueEventData): void;
78
- export declare function flush(): Promise<void>;
79
- export declare function getAssignments(): Assignment[];
80
- export declare function getCartAttributes(): CartAttributeEntry[];
81
- /**
82
- * Build cart attributes for a headless Shopify Storefront API cart.
83
- *
84
- * Integrator contract: pass the cart's full Storefront Cart GID (including its
85
- * `?key=` secret), write every returned entry to that same cart, and verify the
86
- * Storefront API mutation succeeded with no `userErrors`. Only then call
87
- * {@link confirmCartAttributesWritten} with the same Cart GID. Returning signed
88
- * attributes does not authorize treatment display or exposure by itself. An
89
- * empty result is fail-closed and must not be replaced with unsigned attributes.
90
- * Theme storefronts use the SDK-managed `/cart/update.js` path and do not call
91
- * either headless API.
92
- */
93
- export declare function getSignedCartAttributes(cartToken?: string): Promise<CartAttributeEntry[]>;
94
- /**
95
- * Acknowledge that the latest signed headless cart attributes were persisted.
96
- *
97
- * Call this only after the Storefront API cart-attributes mutation succeeded
98
- * and returned no `userErrors`. The Cart GID must match the one passed to the
99
- * latest {@link getSignedCartAttributes} call. Stale-generation, mismatched,
100
- * or repeated acknowledgements are no-ops and cannot grant or change display
101
- * and exposure authorization. When a staged offer adoption can no longer
102
- * apply, the acknowledgement is rejected (`false`) with retryable pending
103
- * state and no authorization is granted.
104
- *
105
- * @returns `true` only when the latest matching acknowledgement was accepted.
106
- */
107
- export declare function confirmCartAttributesWritten(cartToken?: string): boolean;
108
- export declare function getExperiments(): Experiment[];
109
- export declare function getRuntimeValue(key: string): unknown;
110
- export declare function getRuntimeTools(): ApexRuntimeTools;
111
- export declare function evaluateFlag(flagId: string, context?: {
112
- url?: string;
113
- attributes?: Record<string, unknown>;
114
- userId?: string;
115
- }): boolean;
116
- export declare function evaluateFlagAssignment(flagId: string, context?: {
117
- url?: string;
118
- attributes?: Record<string, unknown>;
119
- userId?: string;
120
- }): Assignment | null;
121
- export declare function evaluateFlagValue<T = unknown>(flagId: string, fallback?: T, context?: {
122
- url?: string;
123
- attributes?: Record<string, unknown>;
124
- userId?: string;
125
- }): T | unknown;
126
- export declare function getDiagnostics(): SdkDiagnostics;
1
+ import { ActivationMode, AntiFlickerMode, Assignment, ConfigProfile, ConsentModeSettings, CustomJsPolicy, DebugSettings, ExecutionMode, Experiment, ExclusionGroupConfig, ExclusionGroupMemberConfig, Goal, InitConfig, PageTriggerMode, PageTriggerSettings, PerfFeatureFlag, PerfFeatureFlags, PlatformHint, ProjectPrerequisites, RouterMode, SpaSettings, ExternalTrackingSettings, ProjectCodeSettings, RuntimeEnvironmentSettings, SdkDiagnostics, BucketingCleanupSettings, DataProtectionSettings, TrackEvent, TrackingStart, Variation } from "./types";
2
+ import { fetchWithTimeout, fetchWithRetry, collectScopedSelectors, normalizePageApiName, triggerPage, installActivateJsTrigger, installPageTriggerRule } from "./config-runtime";
3
+ import { sendRuntimeEventNow, getConfigCacheKey, withRuntimeSettings } from "./analytics-runtime";
4
+ import { ArtifactId, reconcilePageActivation, baseArtifactApplicationKey, artifactRenderableAssignments, evaluate, buildCriticalPathAssignments } from "./assignment-runtime";
5
+ import { buildActiveCartAttributeSyncInput, __getQaAssistantRuntimeSnapshot, __subscribeQaAssistantRuntime, __forceQaAssistantVariation, __resetQaAssistantForce } from "./activation-runtime";
6
+ import { init, track, trackStep, trackGoal, setConsent, hold, release, hydrated, recheckPrerequisites, reInit, RevenueEventData, trackRevenue, flush, getAssignments, getCartAttributes, getCartMetafields, getCartMetafieldStaleKeys, mergeCartAttributes, getSignedCartAttributes, confirmCartAttributesWritten, getExperiments, getRuntimeValue, getRuntimeTools, evaluateFlag, evaluateFlagAssignment, evaluateFlagValue, getDiagnostics } from "./public-api";
127
7
  export { defineExperiment, defineExperiments } from "./define";
128
8
  export { defineFlagExperiment } from "./flags";
129
9
  export { getSignals, rememberProduct, setCartSignals, setSearchSignal, setSignal, } from "./signals";
130
10
  export { createApexRuntimeTools } from "./runtime-tools";
131
11
  export declare const __test: {
12
+ attributionLedgerHas: (experimentId: string) => boolean;
13
+ artifactInventory: () => {
14
+ id: ArtifactId;
15
+ ownerKeys: string[];
16
+ ownerPageIds: string[];
17
+ }[];
18
+ artifactRenderableAssignments: typeof artifactRenderableAssignments;
19
+ baseArtifactApplicationKey: typeof baseArtifactApplicationKey;
20
+ buildActiveCartAttributeSyncInput: typeof buildActiveCartAttributeSyncInput;
21
+ buildCriticalPathAssignments: typeof buildCriticalPathAssignments;
22
+ collectScopedSelectors: typeof collectScopedSelectors;
132
23
  fetchWithTimeout: typeof fetchWithTimeout;
133
24
  fetchWithRetry: typeof fetchWithRetry;
134
25
  getConfigCacheKey: typeof getConfigCacheKey;
26
+ installActivateJsTrigger: typeof installActivateJsTrigger;
135
27
  installPageTriggerRule: typeof installPageTriggerRule;
136
28
  normalizePageApiName: typeof normalizePageApiName;
29
+ reconcilePageActivation: typeof reconcilePageActivation;
137
30
  triggerPage: typeof triggerPage;
31
+ sendRuntimeEventNow: typeof sendRuntimeEventNow;
138
32
  withRuntimeSettings: typeof withRuntimeSettings;
139
- };
33
+ } | undefined;
140
34
  export type { ActivationMode, AntiFlickerMode, Assignment, ConfigProfile, ConsentModeSettings, CustomJsPolicy, ExecutionMode, Experiment, ExclusionGroupConfig, ExclusionGroupMemberConfig, Goal, InitConfig, PageTriggerMode, PageTriggerSettings, PerfFeatureFlag, PerfFeatureFlags, PlatformHint, RouterMode, TrackEvent, TrackingStart, Variation, DebugSettings, ProjectPrerequisites, SpaSettings, ExternalTrackingSettings, ProjectCodeSettings, RuntimeEnvironmentSettings, SdkDiagnostics, BucketingCleanupSettings, DataProtectionSettings, };
141
35
  export type { ExperimentDefinition, VariationDefinition, GoalDefinition } from "./define";
142
36
  export type { FlagDefinition, FlagContext } from "./flags";
143
- export type { CartAttributeEntry } from "./shopify-cart";
37
+ export type { CartAttributeEntry, CartMetafieldInput } from "./shopify-cart";
144
38
  export type { ApexRuntimeTools, DataLayerOptions, DomChangedOptions, ElementInViewOptions, WaitForElementOptions, } from "./runtime-tools";
39
+ export { evaluate, __getQaAssistantRuntimeSnapshot, __subscribeQaAssistantRuntime, __forceQaAssistantVariation, __resetQaAssistantForce, init, track, trackStep, trackGoal, setConsent, hold, release, hydrated, recheckPrerequisites, reInit, trackRevenue, flush, getAssignments, getCartAttributes, getCartMetafields, getCartMetafieldStaleKeys, mergeCartAttributes, getSignedCartAttributes, confirmCartAttributesWritten, getExperiments, getRuntimeValue, getRuntimeTools, evaluateFlag, evaluateFlagAssignment, evaluateFlagValue, getDiagnostics };
40
+ export type { RevenueEventData };
@@ -0,0 +1,48 @@
1
+ import { vi } from "vitest";
2
+ export declare const RECENT_MONDAY_NOON: Date;
3
+ export declare function makeStorage(): {
4
+ getItem: (key: string) => string | null;
5
+ key: (index: number) => string;
6
+ removeItem: (key: string) => void;
7
+ setItem: (key: string, value: string) => void;
8
+ readonly length: number;
9
+ };
10
+ export declare function makeClassList(): {
11
+ add: (...tokens: string[]) => void;
12
+ remove: (...tokens: string[]) => void;
13
+ contains: (token: string) => boolean;
14
+ };
15
+ export declare function appendedAntiFlickerStyle(): {
16
+ id: string;
17
+ remove: ReturnType<typeof vi.fn>;
18
+ textContent: string;
19
+ } | undefined;
20
+ export declare function readCookieValue(name: string): string | null;
21
+ export declare function readDecodedDripContext(): string | null;
22
+ export declare function installCookieJar(initial?: string): string[];
23
+ export declare function installMutationObserverStub(): {
24
+ observe: import("vitest").Mock<(...args: any[]) => any>;
25
+ disconnect: import("vitest").Mock<(...args: any[]) => any>;
26
+ takeRecords: import("vitest").Mock<() => never[]>;
27
+ };
28
+ export declare function flushDynamicImports(): Promise<void>;
29
+ export declare function configPayloadHash(experiments: unknown[]): string;
30
+ export declare function decodeTestHandover(token: string): Record<string, unknown>;
31
+ export declare function verifiedHandoverResponse(input: RequestInfo | URL, init: RequestInit | undefined, shopId?: string): Response | null;
32
+ export declare let windowListeners: Record<string, Array<() => void>>;
33
+ export declare let documentListeners: Record<string, Array<(...args: any[]) => void>>;
34
+ export declare const originalWindow: any;
35
+ export declare const originalDocument: any;
36
+ export declare const originalHistory: any;
37
+ export declare const originalLocation: any;
38
+ export declare const originalNavigator: PropertyDescriptor | undefined;
39
+ export declare const originalRequestIdleCallback: PropertyDescriptor | undefined;
40
+ export declare const originalCancelIdleCallback: PropertyDescriptor | undefined;
41
+ export declare const originalLocalStorage: any;
42
+ export declare const originalSessionStorage: any;
43
+ export declare const originalCustomEvent: any;
44
+ export declare const originalMutationObserver: any;
45
+ export declare const originalElement: any;
46
+ export declare const originalNode: any;
47
+ export declare const originalFetch: typeof fetch;
48
+ export declare function registerInitTestLifecycle(): void;
@@ -0,0 +1,26 @@
1
+ import { type CompactGroupSelections } from "./persistence-decoders";
2
+ import type { Experiment } from "./types";
3
+ export type PredecidedAssignments = {
4
+ decision: Array<[experimentId: string, variationId: string]>;
5
+ configRevision: number;
6
+ visitorId: string;
7
+ groups: CompactGroupSelections;
8
+ consentAllowed: boolean;
9
+ };
10
+ /** Synchronous, read-only bootstrap entrypoint. Bundled into the Worker snippet. */
11
+ export declare function computePredecided(input: {
12
+ experiments: Experiment[];
13
+ holdout?: {
14
+ enabled?: boolean;
15
+ percentage?: number;
16
+ };
17
+ configRevision: number;
18
+ url: string;
19
+ provisionalVisitorId: string;
20
+ requireConsent?: boolean;
21
+ hasConsent?: boolean;
22
+ consentModeEnabled?: boolean;
23
+ consentProvider?: "custom" | "onetrust" | "usercentrics" | "cookiebot" | "ccm19" | "pandectes" | "cookiescript" | "borlabs";
24
+ consentRequiredGroup?: string;
25
+ respectDoNotTrack?: boolean;
26
+ }): PredecidedAssignments;
@@ -2,5 +2,7 @@ import type { CustomJsPolicy } from "./types";
2
2
  export declare function setJsPolicy(policy: CustomJsPolicy): void;
3
3
  export declare function isStrictJsPolicy(): boolean;
4
4
  export declare function execJs(code: string, sourceLabel?: string): void;
5
- export declare function loadExternalJs(url: string, sourceLabel: string): Promise<void>;
5
+ export declare function loadExternalJs(url: string, sourceLabel: string, ownerKeys?: readonly string[], artifactId?: string, epoch?: number): Promise<void>;
6
+ export declare function removeExternalJsForOwner(ownerKey: string, artifactId?: string): void;
7
+ export declare function addExternalJsOwners(existingOwnerKeys: ReadonlySet<string>, ownerKeys: readonly string[], artifactId?: string): void;
6
8
  export declare function removeAllExternalJs(): void;
@@ -10,5 +10,17 @@ export type DisplayedMoney = {
10
10
  start: number;
11
11
  end: number;
12
12
  };
13
+ export type CurrencyToken = {
14
+ symbol: string;
15
+ cents: number;
16
+ raw: string;
17
+ };
18
+ /** Extract marked displayed prices without treating ordinary numbers as money. */
19
+ export declare function extractCurrencyTokens(text: string): CurrencyToken[];
20
+ export declare const ISO_4217_CURRENCY_CODES: string[];
21
+ /** Returns whether a code is currently active in ISO 4217. */
22
+ export declare function isIso4217CurrencyCode(currencyCode: string): boolean;
23
+ /** Authoritative ISO-4217 minor-unit exponent for editor-supported currencies. */
24
+ export declare function currencyExponent(currencyCode: string): number;
13
25
  export declare function parseDisplayedCents(text: string, minorUnits?: number): DisplayedMoney | null;
14
26
  export declare function formatCentsLike(cents: number, convention: MoneyConvention): string;
@@ -1,34 +1,73 @@
1
1
  import { Mutation, MutationAction } from "./types";
2
+ import { type CurrencyToken } from "./money";
2
3
  export type ApplyOptions = {
3
4
  root?: Document | HTMLElement;
4
- onApplied?: (mutation: Mutation, element: Element, index: number) => void;
5
+ artifactId?: string;
6
+ epoch?: number;
7
+ ownerKeys?: readonly string[];
8
+ onApplied?: (mutation: Mutation, element: Element, index: number, journalSeq?: number) => void;
5
9
  onMiss?: (mutation: Mutation, index: number) => void;
10
+ preservePrices?: boolean;
11
+ priceTestExempt?: boolean;
12
+ onPricePreservationViolation?: (input: {
13
+ mutation: Mutation;
14
+ selector: string;
15
+ originalPriceTokens: CurrencyToken[];
16
+ }) => void;
6
17
  };
7
- export declare function isSafeMutationAttribute(name: string, value: string | null): boolean;
18
+ type ElementReference = {
19
+ deref: () => Element | undefined;
20
+ };
21
+ export type MutationJournalEntry = {
22
+ seq: number;
23
+ artifactId: string;
24
+ owners: Set<string>;
25
+ target: {
26
+ selector: string;
27
+ index: number;
28
+ el: ElementReference;
29
+ };
30
+ mutation: Mutation;
31
+ epoch: number;
32
+ kind: "mutation" | "insert" | "adopt-insert";
33
+ insertKey?: string;
34
+ nodes?: Node[];
35
+ state: "applied" | "invalidated";
36
+ };
37
+ export { isSafeMutationAttribute } from "./sanitize";
8
38
  export declare function normalizeCssPropertyName(name: string): string;
9
39
  export declare function getMutationKey(mutation: Mutation, index: number): string;
10
40
  export declare function isInsertAction(action: MutationAction): boolean;
11
41
  export declare function applyToElement(mutation: Mutation, element: Element): void;
12
42
  export declare function isInsertDuplicate(element: Element, key: string): boolean;
13
43
  export declare function markInserted(el: Element, key: string): void;
14
- export declare function applyTrackedMutation(mutation: Mutation, element: Element, key?: string): Element | null;
44
+ export declare function applyTrackedMutation(mutation: Mutation, element: Element, key?: string, ownerKeys?: readonly string[], artifactId?: string, onJournal?: (entry: MutationJournalEntry) => void, epoch?: number): Element | null;
45
+ /** Reject a just-applied guarded mutation without disturbing earlier treatments. */
46
+ export declare function rejectTrackedMutation(entry: MutationJournalEntry | undefined, element: Element, innerHTML: string): void;
15
47
  export declare function matchesOriginalInnerHtmlSnapshot(element: Element, current: string): boolean;
16
48
  export declare function applyMutations(mutations: Mutation[], options?: ApplyOptions): void;
17
49
  export declare function reassertNonStructuralMutations(mutations: Mutation[], options?: ApplyOptions): void;
18
50
  export declare function resetAppliedMutations(): void;
51
+ export declare function resetAppliedMutationsForOwner(ownerKey: string, artifactId?: string, options?: {
52
+ preserveReplacementTargets?: boolean;
53
+ }): void;
54
+ export declare function addAppliedMutationOwners(existingOwnerKeys: ReadonlySet<string>, ownerKeys: readonly string[], artifactId?: string): void;
55
+ export declare function invalidateArtifact(artifactId: string): void;
56
+ export declare function replayArtifact(artifactId: string): void;
57
+ export declare function replayForOwner(ownerKey: string): void;
19
58
  export type MutationApplicationContext = {
20
59
  apply: (mutations: Mutation[], options?: ApplyOptions) => void;
21
60
  rollback: () => void;
22
61
  readonly snapshotCount: number;
23
62
  };
24
63
  /**
25
- * Owns only the DOM snapshots created through this context. Rolling it back
26
- * restores the state that existed immediately before its mutations, without
27
- * touching shopper assignment mutations tracked by the main SDK runtime.
64
+ * Owns only the journal entries created through this context. Rollback
65
+ * restores its baseline without touching shopper assignment entries.
28
66
  */
29
67
  export declare function createMutationApplicationContext(): MutationApplicationContext;
30
68
  /** @internal — exposed for unit testing only. Tree-shaken from production build. */
31
69
  export declare const __test: {
70
+ baselineAttributeNames(element: Element): string[];
32
71
  normalizeCssPropertyName: typeof normalizeCssPropertyName;
33
72
  };
34
73
  export declare function observeSpaNavigation(onChange: () => void): () => void;
@@ -0,0 +1,2 @@
1
+ export declare function roundPerformance(value: number, precision?: number): number;
2
+ export declare function navigationEntry(): PerformanceNavigationTiming | undefined;
@@ -0,0 +1,12 @@
1
+ export type PersistedAssignmentRecord = {
2
+ variationId: string;
3
+ epoch: number;
4
+ assignedAt: number;
5
+ };
6
+ export type PersistedGroupSelection = {
7
+ experimentId: string;
8
+ epoch: number;
9
+ };
10
+ export type CompactGroupSelections = Record<string, [string, number]>;
11
+ export declare function decodePersistedAssignments(local: string | null, cookie: string | null): Record<string, PersistedAssignmentRecord>;
12
+ export declare function decodePersistedGroupSelections(local: string | null, cookie: string | null): CompactGroupSelections;