@chordcommerce/analytics 1.17.1 → 1.18.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 (48) hide show
  1. package/README.md +8 -0
  2. package/dist/cjs/client/cdp.d.ts +3 -0
  3. package/dist/cjs/client/cdp.js +123 -0
  4. package/dist/cjs/client/consent/index.d.ts +11 -0
  5. package/dist/cjs/client/consent/index.js +241 -0
  6. package/dist/cjs/client/consent/ketch.d.ts +16 -0
  7. package/dist/cjs/client/consent/ketch.js +53 -0
  8. package/dist/cjs/client/consent/onetrust.d.ts +22 -0
  9. package/dist/cjs/client/consent/onetrust.js +61 -0
  10. package/dist/cjs/client/consent/segment.d.ts +17 -0
  11. package/dist/cjs/client/consent/segment.js +155 -0
  12. package/dist/cjs/client/consent/shopify.d.ts +21 -0
  13. package/dist/cjs/client/consent/shopify.js +51 -0
  14. package/dist/cjs/client/index.d.ts +111 -0
  15. package/dist/cjs/client/index.js +861 -0
  16. package/dist/cjs/client/utils.d.ts +1 -0
  17. package/dist/cjs/client/utils.js +12 -0
  18. package/dist/cjs/index.d.ts +2 -0
  19. package/dist/cjs/index.js +18 -0
  20. package/dist/cjs/setupTests.d.ts +1 -0
  21. package/dist/cjs/setupTests.js +6 -0
  22. package/dist/cjs/types/client.d.ts +96 -0
  23. package/dist/cjs/types/client.js +2 -0
  24. package/dist/cjs/types/consent.d.ts +11 -0
  25. package/dist/cjs/types/consent.js +2 -0
  26. package/dist/cjs/types/formatters.d.ts +114 -0
  27. package/dist/cjs/types/formatters.js +2 -0
  28. package/dist/cjs/types/index.d.ts +7 -0
  29. package/dist/cjs/types/index.js +22 -0
  30. package/dist/cjs/types/input.d.ts +396 -0
  31. package/dist/cjs/types/input.js +2 -0
  32. package/dist/cjs/types/objects.d.ts +379 -0
  33. package/dist/cjs/types/objects.js +2 -0
  34. package/dist/cjs/types/typewriter.d.ts +6502 -0
  35. package/dist/cjs/types/typewriter.js +5 -0
  36. package/dist/cjs/utils.d.ts +2 -0
  37. package/dist/cjs/utils.js +25 -0
  38. package/dist/cjs/validators/custom.d.ts +43 -0
  39. package/dist/cjs/validators/custom.js +18 -0
  40. package/dist/cjs/validators/index.d.ts +4 -0
  41. package/dist/cjs/validators/index.js +20 -0
  42. package/dist/cjs/validators/objects.d.ts +696 -0
  43. package/dist/cjs/validators/objects.js +128 -0
  44. package/dist/cjs/validators/tracking-plan-map.d.ts +6603 -0
  45. package/dist/cjs/validators/tracking-plan-map.js +72 -0
  46. package/dist/cjs/validators/tracking-plan.d.ts +9275 -0
  47. package/dist/cjs/validators/tracking-plan.js +1682 -0
  48. package/package.json +4 -2
@@ -0,0 +1 @@
1
+ export declare function normalizeCDPDomain(cdpDomain: string): string;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeCDPDomain = void 0;
4
+ function normalizeCDPDomain(cdpDomain) {
5
+ var domain = cdpDomain.replace(/\/+$/, '');
6
+ if (domain.endsWith('/p.js')) {
7
+ domain = domain.slice(0, -'/p.js'.length);
8
+ domain = domain.replace(/\/+$/, '');
9
+ }
10
+ return domain;
11
+ }
12
+ exports.normalizeCDPDomain = normalizeCDPDomain;
@@ -0,0 +1,2 @@
1
+ export * from './client/index.js';
2
+ export * from './types/index.js';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./client/index.js"), exports);
18
+ __exportStar(require("./types/index.js"), exports);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // eslint-disable-next-line import/no-extraneous-dependencies
4
+ var globals_1 = require("@jest/globals");
5
+ // Make jest available globally
6
+ globalThis.jest = globals_1.jest;
@@ -0,0 +1,96 @@
1
+ import type { EventProperties, AnalyticsSnippet, Analytics, AnalyticsBrowser, Options } from '@segment/analytics-next';
2
+ import { ChordAnalyticsFormatters } from './formatters.js';
3
+ export interface ValidateResult {
4
+ success: boolean;
5
+ error?: any[];
6
+ data?: any;
7
+ }
8
+ export interface ObjectTypes {
9
+ Cart: any;
10
+ Checkout: any;
11
+ LineItem: any;
12
+ Product: any;
13
+ }
14
+ export type AnyAnalytics = AnalyticsSnippet | Analytics | AnalyticsBrowser | ChordAnalyticsQueue;
15
+ export type AnyOptions = Options;
16
+ export type AnyProduct = {
17
+ [key: string]: unknown;
18
+ };
19
+ export type AnyCart = {
20
+ [key: string]: unknown;
21
+ };
22
+ export type AnyCheckout = {
23
+ [key: string]: unknown;
24
+ };
25
+ export type AnyId = string | number;
26
+ export type AnyLineItem = {
27
+ [key: string]: unknown;
28
+ };
29
+ export interface ChordAnalyticsOptions<T extends ObjectTypes = ObjectTypes> {
30
+ cdp?: AnyAnalytics | (() => AnyAnalytics);
31
+ cdpDomain?: string;
32
+ cdpWriteKey?: string;
33
+ consent?: 'ketch' | 'onetrust' | 'shopify' | 'segment';
34
+ awaitConsent?: boolean;
35
+ debug?: boolean;
36
+ enableLogging?: boolean;
37
+ formatters: ChordAnalyticsFormatters<T>;
38
+ namespace?: string;
39
+ stripNull?: boolean;
40
+ metadata: EventMetadata;
41
+ awaitConsentTimeout?: number;
42
+ middleware?: Array<() => void>;
43
+ }
44
+ export interface EventMetadata {
45
+ i18n: i18nMetadata;
46
+ ownership: ownershipMetadata;
47
+ platform: platformMetadata;
48
+ store: storeMetadata;
49
+ version?: versionMetadata;
50
+ }
51
+ export interface i18nMetadata {
52
+ currency: string;
53
+ locale: string;
54
+ }
55
+ export interface ownershipMetadata {
56
+ omsId: string;
57
+ storeId: string;
58
+ tenantId: string;
59
+ }
60
+ export interface platformMetadata {
61
+ name: string;
62
+ type: string;
63
+ }
64
+ export interface versionMetadata {
65
+ major: number;
66
+ minor: number;
67
+ patch: number;
68
+ }
69
+ export interface storeMetadata {
70
+ domain: string;
71
+ }
72
+ export type ChordAnalyticsQueue = {
73
+ track: (...args: any[]) => void;
74
+ identify: (...args: any[]) => void;
75
+ page: (...args: any[]) => void;
76
+ reset: (...args: any[]) => void;
77
+ };
78
+ type PageContext = {
79
+ search: string;
80
+ searchParams: Record<string, string>;
81
+ };
82
+ type MiddlewarePayload = {
83
+ obj: {
84
+ properties?: EventProperties;
85
+ event: string;
86
+ context: {
87
+ page: PageContext;
88
+ };
89
+ };
90
+ };
91
+ type MiddlewareArgs = {
92
+ payload: MiddlewarePayload;
93
+ next: <T>(arg: T) => T;
94
+ };
95
+ export type AnalyticsMiddleware = (args: MiddlewareArgs) => Partial<EventProperties> | void;
96
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,11 @@
1
+ export interface ConsentAdapter {
2
+ getCurrentConsent: () => ConsentConfiguration | Promise<ConsentConfiguration>;
3
+ handleConsentUpdates: (fn: (ConsentConfiguration: any) => void) => void;
4
+ userCanBeTracked: () => boolean | Promise<boolean>;
5
+ }
6
+ export interface ConsentConfiguration {
7
+ consentCategories?: {
8
+ [key: string]: boolean;
9
+ };
10
+ dontSend?: boolean;
11
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,114 @@
1
+ import type { CartViewed, CheckoutStarted, CheckoutStepCompleted, CheckoutStepViewed, ProductAdded, ProductClicked, VariantClicked, ProductViewed, ProductListViewed, CouponApplied, CouponDenied, CouponEntered, CouponRemoved, EmailCaptured, ProductListFiltered, ProductRemoved, ProductsSearched, SignedIn, SignedOut, SignedUp, LoginStarted, SubscriptionCancelled, NavigationClicked, PaymentInfoEntered } from './typewriter.js';
2
+ import type { Cart, Checkout, LineItem, Product } from './objects.js';
3
+ import type { CartInput, CheckoutInput, CheckoutStepCompletedInput, CheckoutStepViewedInput, LineItemInput, ProductInput, CartViewedInput, CheckoutStartedInput, ProductAddedInput, ProductClickedInput, VariantClickedInput, ProductViewedInput, ProductListViewedInput, ProductListFilteredInput, ProductRemovedInput, CouponAppliedInput, CouponDeniedInput, CouponEnteredInput, CouponRemovedInput, EmailCapturedInput, ProductsSearchedInput, SignedInInput, SignedOutInput, SignedUpInput, LoginStartedInput, SubscriptionCancelledInput, NavigationClickedInput, PaymentInfoEnteredInput } from './input.js';
4
+ import type { ObjectTypes } from './client.js';
5
+ export type CartFormatter<T = ObjectTypes['Cart']> = (props: CartInput<T>) => Cart;
6
+ export type CheckoutFormatter<T = ObjectTypes['Checkout']> = (props: CheckoutInput<T>) => Checkout;
7
+ export type LineItemFormatter<T = ObjectTypes['LineItem']> = (props: LineItemInput<T>) => LineItem;
8
+ export type ProductFormatter<T = ObjectTypes['Product']> = (props: ProductInput<T>) => Product;
9
+ export interface CartViewedFormatter<T extends ObjectTypes = ObjectTypes> {
10
+ (props: CartViewedInput<T>, event: CartViewed): CartViewed;
11
+ }
12
+ export interface CheckoutStartedFormatter<T extends ObjectTypes = ObjectTypes> {
13
+ (props: CheckoutStartedInput<T>, event: CheckoutStarted): CheckoutStarted;
14
+ }
15
+ export interface CheckoutStepCompletedFormatter {
16
+ (props: CheckoutStepCompletedInput, event: CheckoutStepCompleted): CheckoutStepCompleted;
17
+ }
18
+ export interface CheckoutStepViewedFormatter {
19
+ (props: CheckoutStepViewedInput, event: CheckoutStepViewed): CheckoutStepViewed;
20
+ }
21
+ export interface CouponAppliedFormatter {
22
+ (props: CouponAppliedInput, event: CouponApplied): CouponApplied;
23
+ }
24
+ export interface CouponDeniedFormatter {
25
+ (props: CouponDeniedInput, event: CouponDenied): CouponDenied;
26
+ }
27
+ export interface CouponEnteredFormatter {
28
+ (props: CouponEnteredInput, event: CouponEntered): CouponEntered;
29
+ }
30
+ export interface CouponRemovedFormatter {
31
+ (props: CouponRemovedInput, event: CouponRemoved): CouponRemoved;
32
+ }
33
+ export interface EmailCapturedFormatter {
34
+ (props: EmailCapturedInput, event: EmailCaptured): EmailCaptured;
35
+ }
36
+ export interface ProductAddedFormatter<T extends ObjectTypes = ObjectTypes> {
37
+ (props: ProductAddedInput<T>, event: ProductAdded): ProductAdded;
38
+ }
39
+ export interface ProductClickedFormatter<T extends ObjectTypes = ObjectTypes> {
40
+ (props: ProductClickedInput<T>, event: ProductClicked): ProductClicked;
41
+ }
42
+ export interface VariantClickedFormatter<T extends ObjectTypes = ObjectTypes> {
43
+ (props: VariantClickedInput<T>, event: VariantClicked): VariantClicked;
44
+ }
45
+ export interface ProductListFilteredFormatter {
46
+ (props: ProductListFilteredInput, event: ProductListFiltered): ProductListFiltered;
47
+ }
48
+ export interface ProductListViewedFormatter<T extends ObjectTypes = ObjectTypes> {
49
+ (props: ProductListViewedInput<T>, event: ProductListViewed): ProductListViewed;
50
+ }
51
+ export interface ProductRemovedFormatter<T extends ObjectTypes = ObjectTypes> {
52
+ (props: ProductRemovedInput<T>, event: ProductRemoved): ProductRemoved;
53
+ }
54
+ export interface ProductViewedFormatter<T extends ObjectTypes = ObjectTypes> {
55
+ (props: ProductViewedInput<T>, event: ProductViewed): ProductViewed;
56
+ }
57
+ export interface ProductsSearchedFormatter {
58
+ (props: ProductsSearchedInput, event: ProductsSearched): ProductsSearched;
59
+ }
60
+ export interface SignedInFormatter {
61
+ (props: SignedInInput, event: SignedIn): SignedIn;
62
+ }
63
+ export interface SignedOutFormatter {
64
+ (props: SignedOutInput, event: SignedOut): SignedOut;
65
+ }
66
+ export interface SignedUpFormatter {
67
+ (props: SignedUpInput, event: SignedUp): SignedUp;
68
+ }
69
+ export interface LoginStartedFormatter {
70
+ (props: LoginStartedInput, event: LoginStarted): LoginStarted;
71
+ }
72
+ export interface SubscriptionCancelledFormatter {
73
+ (props: SubscriptionCancelledInput, event: SubscriptionCancelled): SubscriptionCancelled;
74
+ }
75
+ export interface NavigationClickedFormatter {
76
+ (props: NavigationClickedInput, event: NavigationClicked): NavigationClicked;
77
+ }
78
+ export interface PaymentInfoEnteredFormatter {
79
+ (props: PaymentInfoEnteredInput, event: PaymentInfoEntered): PaymentInfoEntered;
80
+ }
81
+ export interface ChordAnalyticsFormatters<T extends ObjectTypes = ObjectTypes> {
82
+ events?: {
83
+ cartViewed?: CartViewedFormatter<T>;
84
+ checkoutStarted?: CheckoutStartedFormatter<T>;
85
+ checkoutStepCompleted?: CheckoutStepCompletedFormatter;
86
+ checkoutStepViewed?: CheckoutStepViewedFormatter;
87
+ couponApplied?: CouponAppliedFormatter;
88
+ couponDenied?: CouponDeniedFormatter;
89
+ couponEntered?: CouponEnteredFormatter;
90
+ couponRemoved?: CouponRemovedFormatter;
91
+ emailCaptured?: EmailCapturedFormatter;
92
+ productAdded?: ProductAddedFormatter<T>;
93
+ productClicked?: ProductClickedFormatter<T>;
94
+ variantClicked?: VariantClickedFormatter<T>;
95
+ productListFiltered?: ProductListFilteredFormatter;
96
+ productListViewed?: ProductListViewedFormatter<T>;
97
+ productRemoved?: ProductRemovedFormatter<T>;
98
+ productViewed?: ProductViewedFormatter<T>;
99
+ productsSearched?: ProductsSearchedFormatter;
100
+ signedIn?: SignedInFormatter;
101
+ signedOut?: SignedOutFormatter;
102
+ signedUp?: SignedUpFormatter;
103
+ loginStarted?: LoginStartedFormatter;
104
+ subscriptionCancelled?: SubscriptionCancelledFormatter;
105
+ navigationClicked?: NavigationClickedFormatter;
106
+ paymentInfoEntered?: PaymentInfoEnteredFormatter;
107
+ };
108
+ objects: {
109
+ cart: CartFormatter<T['Cart']>;
110
+ checkout: CheckoutFormatter<T['Checkout']>;
111
+ lineItem: LineItemFormatter<T['LineItem']>;
112
+ product: ProductFormatter<T['Product']>;
113
+ };
114
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,7 @@
1
+ export type { AnalyticsSnippet, Analytics, AnalyticsBrowser, EventProperties, Options, } from '@segment/analytics-next';
2
+ export * from './objects.js';
3
+ export * from './typewriter.js';
4
+ export * from './client.js';
5
+ export * from './consent.js';
6
+ export * from './input.js';
7
+ export * from './formatters.js';
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./objects.js"), exports);
18
+ __exportStar(require("./typewriter.js"), exports);
19
+ __exportStar(require("./client.js"), exports);
20
+ __exportStar(require("./consent.js"), exports);
21
+ __exportStar(require("./input.js"), exports);
22
+ __exportStar(require("./formatters.js"), exports);