@chordcommerce/analytics 1.24.4 → 1.24.5

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.
package/README.md CHANGED
@@ -47,7 +47,7 @@ const { ChordPixel } = require('@chordcommerce/analytics/dist/cjs')
47
47
  | `cdp` | false | _Required when using a CDP other than Chord._ A reference to the CDP library, or a function that returns a reference to the CDP library. For example, if using Segment's [analytics.js](https://www.npmjs.com/package/@segment/analytics-next) library, this could be `window.analytics` or `() => window.analytics`. |
48
48
  | `cdpDomain` | false | _Required when using Chord CDP._ The Chord CDP domain. To be provided by the Chord team. |
49
49
  | `cdpWriteKey` | false | _Required when using Chord CDP._ The Chord CDP write key. To be provided by the Chord team. |
50
- | `debug` | false | Defaults to `false`. When set to `true`, events are validated against Chord's tracking plan and errors are logged. We recommend enabling this for development and disabling for production. |
50
+ | `debug` | false | Defaults to `false`. When set to `true`, events are validated against Chord's tracking plan and errors are logged. Validation uses zod 4. We recommend enabling this for development and disabling for production. |
51
51
  | `enableLogging` | false | Defaults to `true`. When set to `true`, errors are logged using `console.log`. |
52
52
  | `formatters` | true | Functions that are used to construct tracking events. There are two types of formatters, objects and events. `formatters.objects` is required. See below for details. |
53
53
  | `metadata` | true | Event metadata. See below for details. |
@@ -10,8 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  });
11
11
  };
12
12
  var __generator = (this && this.__generator) || function (thisArg, body) {
13
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
14
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
14
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
15
15
  function verb(n) { return function (v) { return step([n, v]); }; }
16
16
  function step(op) {
17
17
  if (f) throw new TypeError("Generator is already executing.");
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
14
  function verb(n) { return function (v) { return step([n, v]); }; }
15
15
  function step(op) {
16
16
  if (f) throw new TypeError("Generator is already executing.");
@@ -109,5 +109,5 @@ export declare const getNormalizedCategories: () => Record<string, boolean>;
109
109
  * @param model - OneTrust consent model name
110
110
  * @returns 'opt-in' or 'opt-out'
111
111
  */
112
- export declare const coerceConsentModel: (model: OtConsentModel | string) => 'opt-in' | 'opt-out';
112
+ export declare const coerceConsentModel: (model: OtConsentModel | string) => "opt-in" | "opt-out";
113
113
  export {};
@@ -5,6 +5,6 @@ export declare const onetrustConsentAdapter: (options: ChordAnalyticsOptions) =>
5
5
  userCanBeTracked: () => boolean;
6
6
  getCategories: () => Record<string, boolean>;
7
7
  isConsentReady: () => boolean;
8
- getConsentModel: () => 'opt-in' | 'opt-out';
9
- getApi: () => import("./onetrust-api.js").OneTrustGlobal;
8
+ getConsentModel: () => "opt-in" | "opt-out";
9
+ getApi: () => import("./onetrust-api.js").OneTrustGlobal | undefined;
10
10
  };
@@ -20,8 +20,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
20
20
  });
21
21
  };
22
22
  var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
24
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
25
  function verb(n) { return function (v) { return step([n, v]); }; }
26
26
  function step(op) {
27
27
  if (f) throw new TypeError("Generator is already executing.");
@@ -46,17 +46,30 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
46
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
47
  }
48
48
  };
49
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
50
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
51
+ if (ar || !(i in from)) {
52
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
53
+ ar[i] = from[i];
54
+ }
55
+ }
56
+ return to.concat(ar || Array.prototype.slice.call(from));
57
+ };
49
58
  Object.defineProperty(exports, "__esModule", { value: true });
50
59
  exports.segmentConsentAdapter = void 0;
51
60
  var getApi = function () { return window.segmentConsent; };
52
61
  /**
53
62
  * Waits for the Segment consent API to be populated with retry logic.
54
63
  */
55
- var waitForApi = function (maxRetries, baseDelay) {
56
- if (maxRetries === void 0) { maxRetries = 10; }
57
- if (baseDelay === void 0) { baseDelay = 100; }
58
- return __awaiter(void 0, void 0, void 0, function () {
64
+ var waitForApi = function () {
65
+ var args_1 = [];
66
+ for (var _i = 0; _i < arguments.length; _i++) {
67
+ args_1[_i] = arguments[_i];
68
+ }
69
+ return __awaiter(void 0, __spreadArray([], args_1, true), void 0, function (maxRetries, baseDelay) {
59
70
  var attempt, checkAndWait;
71
+ if (maxRetries === void 0) { maxRetries = 10; }
72
+ if (baseDelay === void 0) { baseDelay = 100; }
60
73
  return __generator(this, function (_a) {
61
74
  attempt = 0;
62
75
  checkAndWait = function () { return __awaiter(void 0, void 0, void 0, function () {
@@ -20,8 +20,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
20
20
  });
21
21
  };
22
22
  var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
24
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
25
  function verb(n) { return function (v) { return step([n, v]); }; }
26
26
  function step(op) {
27
27
  if (f) throw new TypeError("Generator is already executing.");
@@ -743,10 +743,14 @@ var ChordAnalytics = /** @class */ (function () {
743
743
  * Send a `page` event to the CDP.
744
744
  * If consent is not ready, the event is queued until consent is available.
745
745
  */
746
- this.page = function (options, props) {
747
- if (props === void 0) { props = {}; }
748
- return __awaiter(_this, void 0, void 0, function () {
746
+ this.page = function (options_1) {
747
+ var args_1 = [];
748
+ for (var _i = 1; _i < arguments.length; _i++) {
749
+ args_1[_i - 1] = arguments[_i];
750
+ }
751
+ return __awaiter(_this, __spreadArray([options_1], args_1, true), void 0, function (options, props) {
749
752
  var gate;
753
+ if (props === void 0) { props = {}; }
750
754
  return __generator(this, function (_a) {
751
755
  switch (_a.label) {
752
756
  case 0:
@@ -772,10 +776,14 @@ var ChordAnalytics = /** @class */ (function () {
772
776
  /**
773
777
  * Internal method to actually send a page event to CDP.
774
778
  */
775
- this.sendPageEvent = function (options, props) {
776
- if (props === void 0) { props = {}; }
777
- return __awaiter(_this, void 0, void 0, function () {
779
+ this.sendPageEvent = function (options_1) {
780
+ var args_1 = [];
781
+ for (var _i = 1; _i < arguments.length; _i++) {
782
+ args_1[_i - 1] = arguments[_i];
783
+ }
784
+ return __awaiter(_this, __spreadArray([options_1], args_1, true), void 0, function (options, props) {
778
785
  var _this = this;
786
+ if (props === void 0) { props = {}; }
779
787
  return __generator(this, function (_a) {
780
788
  switch (_a.label) {
781
789
  case 0:
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeCDPDomain = void 0;
3
+ exports.normalizeCDPDomain = normalizeCDPDomain;
4
4
  function normalizeCDPDomain(cdpDomain) {
5
5
  var domain = cdpDomain.replace(/\/+$/, '');
6
6
  if (domain.endsWith('/p.js')) {
@@ -9,4 +9,3 @@ function normalizeCDPDomain(cdpDomain) {
9
9
  }
10
10
  return domain;
11
11
  }
12
- exports.normalizeCDPDomain = normalizeCDPDomain;
@@ -27,4 +27,4 @@ export declare const isPromise: (value: unknown) => value is Promise<unknown>;
27
27
  * The timer is cleared either way, so a promise that settles quickly does not
28
28
  * leave a pending timeout behind.
29
29
  */
30
- export declare const withTimeout: <T>(promise: Promise<T>, ms: number) => Promise<typeof TIMED_OUT | T>;
30
+ export declare const withTimeout: <T>(promise: Promise<T>, ms: number) => Promise<T | typeof TIMED_OUT>;
package/dist/cjs/utils.js CHANGED
@@ -9,8 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
14
  function verb(n) { return function (v) { return step([n, v]); }; }
15
15
  function step(op) {
16
16
  if (f) throw new TypeError("Generator is already executing.");
@@ -1,43 +1,9 @@
1
- import { z } from 'zod';
2
- export declare const productInProductsSchema: z.ZodEffects<z.ZodObject<{
1
+ import * as z from 'zod';
2
+ export declare const productInProductsSchema: z.ZodObject<{
3
3
  product_id: z.ZodString;
4
4
  sku: z.ZodString;
5
5
  products: z.ZodArray<z.ZodObject<{
6
6
  product_id: z.ZodString;
7
7
  sku: z.ZodString;
8
- }, "strip", z.ZodTypeAny, {
9
- product_id?: string;
10
- sku?: string;
11
- }, {
12
- product_id?: string;
13
- sku?: string;
14
- }>, "many">;
15
- }, "strip", z.ZodTypeAny, {
16
- product_id?: string;
17
- sku?: string;
18
- products?: {
19
- product_id?: string;
20
- sku?: string;
21
- }[];
22
- }, {
23
- product_id?: string;
24
- sku?: string;
25
- products?: {
26
- product_id?: string;
27
- sku?: string;
28
- }[];
29
- }>, {
30
- product_id?: string;
31
- sku?: string;
32
- products?: {
33
- product_id?: string;
34
- sku?: string;
35
- }[];
36
- }, {
37
- product_id?: string;
38
- sku?: string;
39
- products?: {
40
- product_id?: string;
41
- sku?: string;
42
- }[];
43
- }>;
8
+ }, z.z.core.$strip>>;
9
+ }, z.z.core.$strip>;
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.productInProductsSchema = void 0;
4
- var zod_1 = require("zod");
5
- exports.productInProductsSchema = zod_1.z
4
+ var z = require("zod");
5
+ exports.productInProductsSchema = z
6
6
  .object({
7
- product_id: zod_1.z.string(),
8
- sku: zod_1.z.string(),
9
- products: zod_1.z.array(zod_1.z.object({ product_id: zod_1.z.string(), sku: zod_1.z.string() })),
7
+ product_id: z.string(),
8
+ sku: z.string(),
9
+ products: z.array(z.object({ product_id: z.string(), sku: z.string() })),
10
10
  })
11
11
  .refine(function (event) {
12
12
  var productInCart = event.products.find(function (p) {