flowgrid-sdk 1.6.4 → 1.6.6

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.
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview Drop-in consent helpers.
4
+ * @module helpers/consent
5
+ *
6
+ * @description
7
+ * Two convenience wrappers over {@link ConsentManager} so you don't have to
8
+ * wire the manager to the transport layer (or a DOM banner) by hand:
9
+ *
10
+ * - {@link setupConsent} — create a manager that automatically syncs the
11
+ * visitor's choices into FlowGrid's consent gates.
12
+ * - {@link attachConsentBanner} — additionally wire an existing HTML banner's
13
+ * accept / reject buttons, with no framework required.
14
+ *
15
+ * ```ts
16
+ * import { attachConsentBanner } from "flowgrid-sdk";
17
+ *
18
+ * // Markup: <div id="cookie-banner">… <button id="accept-btn"> <button id="reject-btn"> </div>
19
+ * attachConsentBanner();
20
+ * ```
21
+ */
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.setupConsent = setupConsent;
24
+ exports.attachConsentBanner = attachConsentBanner;
25
+ const consent_1 = require("../consent");
26
+ const transport_1 = require("../client/transport");
27
+ /**
28
+ * Create a {@link ConsentManager} that keeps FlowGrid's transport-level consent
29
+ * gates in sync automatically.
30
+ *
31
+ * On creation it pushes the visitor's stored preferences into the transport,
32
+ * and it re-syncs on every change — so analytics/marketing events are gated
33
+ * correctly without any extra wiring. Your own `onChange` (if provided) still
34
+ * runs afterwards.
35
+ *
36
+ * @param config - Optional {@link ConsentConfig} overrides (cookie name, DNT, …).
37
+ * @returns The configured {@link ConsentManager}.
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * const consent = setupConsent({ cookieName: "my_app_consent", cookieDays: 180 });
42
+ * if (!consent.hasConsented()) showMyBanner();
43
+ * ```
44
+ */
45
+ function setupConsent(config) {
46
+ const userOnChange = config?.onChange;
47
+ const manager = new consent_1.ConsentManager({
48
+ ...config,
49
+ onChange: (prefs) => {
50
+ syncTransport(prefs);
51
+ userOnChange?.(prefs);
52
+ },
53
+ });
54
+ // Push whatever is already stored so gates are correct before any interaction.
55
+ syncTransport(manager.getPreferences());
56
+ return manager;
57
+ }
58
+ function syncTransport(prefs) {
59
+ transport_1.FlowGridTransport.setConsent({
60
+ analytics: prefs.analytics,
61
+ marketing: prefs.marketing,
62
+ });
63
+ }
64
+ /**
65
+ * Wire an existing HTML cookie banner to a {@link ConsentManager}: clicking the
66
+ * accept button calls `acceptAll()`, the reject button calls
67
+ * `rejectNonEssential()`, and the banner hides itself afterwards. The banner is
68
+ * shown automatically only if the visitor hasn't consented yet.
69
+ *
70
+ * Framework-agnostic and SSR-safe: returns `null` when there's no `document`
71
+ * (server render) or no banner element is found.
72
+ *
73
+ * Expected markup (ids are configurable):
74
+ * ```html
75
+ * <div id="cookie-banner" style="display:none">
76
+ * <button id="reject-btn">Reject non-essential</button>
77
+ * <button id="accept-btn">Accept all</button>
78
+ * </div>
79
+ * ```
80
+ *
81
+ * @param options - Banner element ids plus any {@link ConsentConfig} overrides.
82
+ * @returns A {@link ConsentBannerHandle}, or `null` when unavailable.
83
+ */
84
+ function attachConsentBanner(options) {
85
+ if (typeof document === "undefined")
86
+ return null;
87
+ const { bannerId = "cookie-banner", acceptId = "accept-btn", rejectId = "reject-btn", manager: providedManager, ...consentConfig } = options ?? {};
88
+ const banner = document.getElementById(bannerId);
89
+ if (!banner)
90
+ return null;
91
+ const manager = providedManager ?? setupConsent(consentConfig);
92
+ const show = () => {
93
+ banner.style.display = "";
94
+ };
95
+ const hide = () => {
96
+ banner.style.display = "none";
97
+ };
98
+ const acceptBtn = banner.querySelector(`#${acceptId}`);
99
+ const rejectBtn = banner.querySelector(`#${rejectId}`);
100
+ const onAccept = () => {
101
+ manager.acceptAll();
102
+ hide();
103
+ };
104
+ const onReject = () => {
105
+ manager.rejectNonEssential();
106
+ hide();
107
+ };
108
+ acceptBtn?.addEventListener("click", onAccept);
109
+ rejectBtn?.addEventListener("click", onReject);
110
+ // Only prompt visitors who haven't made a choice yet.
111
+ if (manager.hasConsented())
112
+ hide();
113
+ else
114
+ show();
115
+ return {
116
+ manager,
117
+ show,
118
+ hide,
119
+ destroy() {
120
+ acceptBtn?.removeEventListener("click", onAccept);
121
+ rejectBtn?.removeEventListener("click", onReject);
122
+ },
123
+ };
124
+ }
125
+ //# sourceMappingURL=consent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consent.js","sourceRoot":"","sources":["../../../src/lib/helpers/consent.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;AAwBH,oCAeC;AAwDD,kDAmDC;AAhJD,wCAA4C;AAE5C,mDAAwD;AAExD;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,YAAY,CAAC,MAAsB;IACjD,MAAM,YAAY,GAAG,MAAM,EAAE,QAAQ,CAAC;IAEtC,MAAM,OAAO,GAAG,IAAI,wBAAc,CAAC;QACjC,GAAG,MAAM;QACT,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE;YAClB,aAAa,CAAC,KAAK,CAAC,CAAC;YACrB,YAAY,EAAE,CAAC,KAAK,CAAC,CAAC;QACxB,CAAC;KACF,CAAC,CAAC;IAEH,+EAA+E;IAC/E,aAAa,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;IAExC,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,aAAa,CAAC,KAAyB;IAC9C,6BAAiB,CAAC,UAAU,CAAC;QAC3B,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,SAAS,EAAE,KAAK,CAAC,SAAS;KAC3B,CAAC,CAAC;AACL,CAAC;AA6BD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,mBAAmB,CAAC,OAA8B;IAChE,IAAI,OAAO,QAAQ,KAAK,WAAW;QAAE,OAAO,IAAI,CAAC;IAEjD,MAAM,EACJ,QAAQ,GAAG,eAAe,EAC1B,QAAQ,GAAG,YAAY,EACvB,QAAQ,GAAG,YAAY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AAS,EAAE,mBAAmB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QACpD,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * @fileoverview Drop-in identity helpers.
3
+ * @module helpers/identity
4
+ *
5
+ * @description
6
+ * Stable, SSR-safe IDs that most apps need to wire up tracking, exposed as
7
+ * plain functions so you never have to re-implement the localStorage /
8
+ * sessionStorage boilerplate yourself.
9
+ *
10
+ * ```ts
11
+ * import { getOrCreateAnonId, getOrCreateCartId } from "flowgrid-sdk";
12
+ *
13
+ * fg.products.view(product, { userId: getOrCreateAnonId() });
14
+ * fg.cart.add(product, 1, getOrCreateCartId());
15
+ * ```
16
+ *
17
+ * Both helpers degrade gracefully: during SSR or when storage is blocked
18
+ * (private mode, strict cookie settings) they return a safe fallback instead
19
+ * of throwing, so they're safe to call anywhere.
20
+ */
21
+ /**
22
+ * Returns a stable anonymous visitor ID, generating and persisting one in
23
+ * `localStorage` on first call. The same value is reused across page loads so
24
+ * a returning visitor is recognised as the same person.
25
+ *
26
+ * Uses the same `fg_anon_id` key as the experiment engine, so the IDs line up
27
+ * across tracking calls and A/B test assignments.
28
+ *
29
+ * @returns The persisted anonymous ID, or `"anon"` when storage is unavailable.
30
+ */
31
+ export declare function getOrCreateAnonId(): string;
32
+ /**
33
+ * Returns a stable cart ID for the lifetime of the browser session, generating
34
+ * and persisting one in `sessionStorage` on first call. Pair this with cart and
35
+ * checkout events so every line item shares the same `cartId`.
36
+ *
37
+ * @returns The persisted cart ID (prefixed `cart_`), or `"cart_anon"` when
38
+ * storage is unavailable.
39
+ */
40
+ export declare function getOrCreateCartId(): string;
41
+ /**
42
+ * Clears the persisted cart ID so the next {@link getOrCreateCartId} call starts
43
+ * a fresh cart. Call this after a completed purchase.
44
+ */
45
+ export declare function resetCartId(): void;
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview Drop-in identity helpers.
4
+ * @module helpers/identity
5
+ *
6
+ * @description
7
+ * Stable, SSR-safe IDs that most apps need to wire up tracking, exposed as
8
+ * plain functions so you never have to re-implement the localStorage /
9
+ * sessionStorage boilerplate yourself.
10
+ *
11
+ * ```ts
12
+ * import { getOrCreateAnonId, getOrCreateCartId } from "flowgrid-sdk";
13
+ *
14
+ * fg.products.view(product, { userId: getOrCreateAnonId() });
15
+ * fg.cart.add(product, 1, getOrCreateCartId());
16
+ * ```
17
+ *
18
+ * Both helpers degrade gracefully: during SSR or when storage is blocked
19
+ * (private mode, strict cookie settings) they return a safe fallback instead
20
+ * of throwing, so they're safe to call anywhere.
21
+ */
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.getOrCreateAnonId = getOrCreateAnonId;
24
+ exports.getOrCreateCartId = getOrCreateCartId;
25
+ exports.resetCartId = resetCartId;
26
+ /** localStorage key for the anonymous visitor ID. Shared with the experiment engine. */
27
+ const ANON_ID_KEY = "fg_anon_id";
28
+ /** sessionStorage key for the per-session cart ID. */
29
+ const CART_ID_KEY = "fg_cart_id";
30
+ /**
31
+ * UUID v4 with a non-crypto fallback for ancient/locked-down runtimes.
32
+ * `crypto.randomUUID()` is preferred when available.
33
+ */
34
+ function uuid() {
35
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
36
+ return crypto.randomUUID();
37
+ }
38
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
39
+ const r = (Math.random() * 16) | 0;
40
+ return (c === "x" ? r : (r & 0x3) | 0x8).toString(16);
41
+ });
42
+ }
43
+ /**
44
+ * Returns a stable anonymous visitor ID, generating and persisting one in
45
+ * `localStorage` on first call. The same value is reused across page loads so
46
+ * a returning visitor is recognised as the same person.
47
+ *
48
+ * Uses the same `fg_anon_id` key as the experiment engine, so the IDs line up
49
+ * across tracking calls and A/B test assignments.
50
+ *
51
+ * @returns The persisted anonymous ID, or `"anon"` when storage is unavailable.
52
+ */
53
+ function getOrCreateAnonId() {
54
+ if (typeof localStorage === "undefined")
55
+ return "anon";
56
+ try {
57
+ const existing = localStorage.getItem(ANON_ID_KEY);
58
+ if (existing)
59
+ return existing;
60
+ const id = uuid();
61
+ localStorage.setItem(ANON_ID_KEY, id);
62
+ return id;
63
+ }
64
+ catch {
65
+ return "anon";
66
+ }
67
+ }
68
+ /**
69
+ * Returns a stable cart ID for the lifetime of the browser session, generating
70
+ * and persisting one in `sessionStorage` on first call. Pair this with cart and
71
+ * checkout events so every line item shares the same `cartId`.
72
+ *
73
+ * @returns The persisted cart ID (prefixed `cart_`), or `"cart_anon"` when
74
+ * storage is unavailable.
75
+ */
76
+ function getOrCreateCartId() {
77
+ if (typeof sessionStorage === "undefined")
78
+ return "cart_anon";
79
+ try {
80
+ const existing = sessionStorage.getItem(CART_ID_KEY);
81
+ if (existing)
82
+ return existing;
83
+ const id = `cart_${uuid()}`;
84
+ sessionStorage.setItem(CART_ID_KEY, id);
85
+ return id;
86
+ }
87
+ catch {
88
+ return "cart_anon";
89
+ }
90
+ }
91
+ /**
92
+ * Clears the persisted cart ID so the next {@link getOrCreateCartId} call starts
93
+ * a fresh cart. Call this after a completed purchase.
94
+ */
95
+ function resetCartId() {
96
+ try {
97
+ if (typeof sessionStorage !== "undefined")
98
+ sessionStorage.removeItem(CART_ID_KEY);
99
+ }
100
+ catch {
101
+ /* SSR or privacy mode */
102
+ }
103
+ }
104
+ //# sourceMappingURL=identity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity.js","sourceRoot":"","sources":["../../../src/lib/helpers/identity.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;AAgCH,8CAWC;AAUD,8CAWC;AAMD,kCAMC;AA1ED,wFAAwF;AACxF,MAAM,WAAW,GAAG,YAAY,CAAC;AAEjC,sDAAsD;AACtD,MAAM,WAAW,GAAG,YAAY,CAAC;AAEjC;;;GAGG;AACH,SAAS,IAAI;IACX,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,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AE,CAAC,CAAC;QACxC,OAAO,EAAE,CAAC;IACZ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,WAAW,CAAC;IACrB,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,SAAgB,WAAW;IACzB,IAAI,CAAC;QACH,IAAI,OAAO,cAAc,KAAK,WAAW;YAAE,cAAc,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;IACpF,CAAC;IAAC,MAAM,CAAC;QACP,yBAAyB;IAC3B,CAAC;AACH,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * @fileoverview Drop-in helpers.
3
+ * @module helpers
4
+ *
5
+ * @description
6
+ * Small, framework-agnostic convenience functions for the things almost every
7
+ * integration needs — stable IDs and consent wiring — so you can import them
8
+ * directly instead of re-implementing the boilerplate in every app.
9
+ *
10
+ * ```ts
11
+ * import {
12
+ * getOrCreateAnonId,
13
+ * getOrCreateCartId,
14
+ * setupConsent,
15
+ * attachConsentBanner,
16
+ * } from "flowgrid-sdk";
17
+ * ```
18
+ */
19
+ export { getOrCreateAnonId, getOrCreateCartId, resetCartId } from "./identity";
20
+ export { setupConsent, attachConsentBanner } from "./consent";
21
+ export type { ConsentBannerOptions, ConsentBannerHandle } from "./consent";
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview Drop-in helpers.
4
+ * @module helpers
5
+ *
6
+ * @description
7
+ * Small, framework-agnostic convenience functions for the things almost every
8
+ * integration needs — stable IDs and consent wiring — so you can import them
9
+ * directly instead of re-implementing the boilerplate in every app.
10
+ *
11
+ * ```ts
12
+ * import {
13
+ * getOrCreateAnonId,
14
+ * getOrCreateCartId,
15
+ * setupConsent,
16
+ * attachConsentBanner,
17
+ * } from "flowgrid-sdk";
18
+ * ```
19
+ */
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.attachConsentBanner = exports.setupConsent = exports.resetCartId = exports.getOrCreateCartId = exports.getOrCreateAnonId = void 0;
22
+ var identity_1 = require("./identity");
23
+ Object.defineProperty(exports, "getOrCreateAnonId", { enumerable: true, get: function () { return identity_1.getOrCreateAnonId; } });
24
+ Object.defineProperty(exports, "getOrCreateCartId", { enumerable: true, get: function () { return identity_1.getOrCreateCartId; } });
25
+ Object.defineProperty(exports, "resetCartId", { enumerable: true, get: function () { return identity_1.resetCartId; } });
26
+ var consent_1 = require("./consent");
27
+ Object.defineProperty(exports, "setupConsent", { enumerable: true, get: function () { return consent_1.setupConsent; } });
28
+ Object.defineProperty(exports, "attachConsentBanner", { enumerable: true, get: function () { return consent_1.attachConsentBanner; } });
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/helpers/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;AAEH,uCAA+E;AAAtE,6GAAA,iBAAiB,OAAA;AAAE,6GAAA,iBAAiB,OAAA;AAAE,uGAAA,WAAW,OAAA;AAC1D,qCAA8D;AAArD,uGAAA,YAAY,OAAA;AAAE,8GAAA,mBAAmB,OAAA"}
@@ -62,6 +62,18 @@ export declare class ExperimentTracker {
62
62
  * Call this when the variant is rendered.
63
63
  */
64
64
  exposure(experimentId: string, userId: string, variantId: string): Promise<import("../../..").ExperimentResponse>;
65
+ /**
66
+ * Browser-side exposure for the locally-assigned variant — resolves both the
67
+ * variant and the user id for you. Call this right after rendering the
68
+ * variant; no-op if the visitor has no assignment yet.
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * await fg.experiments.init([{ id: "checkout_v2", variants: [...] }]);
73
+ * await fg.experiments.exposureAuto("checkout_v2");
74
+ * ```
75
+ */
76
+ exposureAuto(experimentId: string): Promise<void>;
65
77
  /**
66
78
  * Record a conversion against a specific user's variant (server-side).
67
79
  *
@@ -63,6 +63,20 @@ class ExperimentTracker {
63
63
  exposure(experimentId, userId, variantId) {
64
64
  return this.client.trackExposure(experimentId, userId, variantId);
65
65
  }
66
+ /**
67
+ * Browser-side exposure for the locally-assigned variant — resolves both the
68
+ * variant and the user id for you. Call this right after rendering the
69
+ * variant; no-op if the visitor has no assignment yet.
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * await fg.experiments.init([{ id: "checkout_v2", variants: [...] }]);
74
+ * await fg.experiments.exposureAuto("checkout_v2");
75
+ * ```
76
+ */
77
+ exposureAuto(experimentId) {
78
+ return this.client.trackLocalExposure(experimentId);
79
+ }
66
80
  /**
67
81
  * Record a conversion against a specific user's variant (server-side).
68
82
  *
@@ -1 +1 @@
1
- {"version":3,"file":"experiment.js","sourceRoot":"","sources":["../../../../src/lib/tracking/core/experiment.ts"],"names":[],"mappings":";;;AA2BA,MAAa,iBAAiB;IAC5B,YAA4B,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;IAAG,CAAC;IAElD,8EAA8E;IAC9E,QAAQ;IACR,8EAA8E;IAE9E;;;;;;;;;;;;;;OAcG;IACH,MAAM,CAAC,UAAgC;QACrC,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IACxC,CAAC;IAED;;;;;;OAMG;IACH,IAAI,CAAC,WAAmC;QACtC,OAAO,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;IAClD,CAAC;IAED,8EAA8E;IAC9E,aAAa;IACb,8EAA8E;IAE9E;;;OAGG;IACH,OAAO,CAAC,YAAoB;QAC1B,OAAO,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;IACnD,CAAC;IAED;;;OAGG;IACH,MAAM,CACJ,YAAoB,EACpB,MAAc,EACd,SAAiB,EACjB,SAA6C,UAAU;QAEvD,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,CAAC;IACzE,CAAC;IAED,8EAA8E;IAC9E,wBAAwB;IACxB,8EAA8E;IAE9E;;;OAGG;IACH,QAAQ,CAAC,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