@chordcommerce/analytics 1.23.1 → 1.25.0-beta.2
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 +28 -2
- package/dist/cjs/client/index.d.ts +5 -42
- package/dist/cjs/client/index.js +302 -487
- package/dist/cjs/types/client.d.ts +14 -1
- package/dist/cjs/utils.d.ts +19 -0
- package/dist/cjs/utils.js +79 -1
- package/dist/client/index.d.ts +5 -42
- package/dist/client/index.js +277 -438
- package/dist/types/client.d.ts +14 -1
- package/dist/utils.d.ts +19 -0
- package/dist/utils.js +39 -0
- package/package.json +11 -1
package/dist/types/client.d.ts
CHANGED
|
@@ -88,10 +88,23 @@ type MiddlewarePayload = {
|
|
|
88
88
|
page: PageContext;
|
|
89
89
|
};
|
|
90
90
|
};
|
|
91
|
+
/**
|
|
92
|
+
* The current user and anonymous ids, read from the CDP at send time.
|
|
93
|
+
* Segment's middleware payload exposes these as `userId()`/`anonymousId()`
|
|
94
|
+
* methods on a facade; they are plain values here.
|
|
95
|
+
*/
|
|
96
|
+
userId?: string;
|
|
97
|
+
anonymousId?: string;
|
|
91
98
|
};
|
|
92
99
|
type MiddlewareArgs = {
|
|
93
100
|
payload: MiddlewarePayload;
|
|
94
101
|
next: <T>(arg: T) => T;
|
|
95
102
|
};
|
|
96
|
-
export type
|
|
103
|
+
export type MiddlewareResult = Partial<EventProperties> | void;
|
|
104
|
+
/**
|
|
105
|
+
* A source middleware may be synchronous or asynchronous. An asynchronous one
|
|
106
|
+
* is awaited before the event is dispatched, bounded by a timeout — see
|
|
107
|
+
* `addSourceMiddleware` in the README.
|
|
108
|
+
*/
|
|
109
|
+
export type AnalyticsMiddleware = (args: MiddlewareArgs) => MiddlewareResult | Promise<MiddlewareResult>;
|
|
97
110
|
export {};
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,2 +1,21 @@
|
|
|
1
1
|
import type { EventProperties } from './types/index.js';
|
|
2
2
|
export declare const pruneNullValues: (props: EventProperties) => EventProperties;
|
|
3
|
+
/**
|
|
4
|
+
* How long a single asynchronous source middleware may take before its
|
|
5
|
+
* contribution is abandoned.
|
|
6
|
+
*
|
|
7
|
+
* Middleware runs on the path to the CDP, so an unbounded wait would let one
|
|
8
|
+
* slow lookup hold up delivery indefinitely. `Order Completed` in particular
|
|
9
|
+
* fires on a confirmation page shoppers close, so a late event is a lost one.
|
|
10
|
+
*/
|
|
11
|
+
export declare const MIDDLEWARE_TIMEOUT_MS = 1000;
|
|
12
|
+
/** Returned by {@link withTimeout} when the promise did not settle in time. */
|
|
13
|
+
export declare const TIMED_OUT: unique symbol;
|
|
14
|
+
export declare const isPromise: (value: unknown) => value is Promise<unknown>;
|
|
15
|
+
/**
|
|
16
|
+
* Resolve `promise`, or {@link TIMED_OUT} if it has not settled within `ms`.
|
|
17
|
+
*
|
|
18
|
+
* The timer is cleared either way, so a promise that settles quickly does not
|
|
19
|
+
* leave a pending timeout behind.
|
|
20
|
+
*/
|
|
21
|
+
export declare const withTimeout: <T>(promise: Promise<T>, ms: number) => Promise<typeof TIMED_OUT | T>;
|
package/dist/utils.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
export const pruneNullValues = (props) => {
|
|
2
11
|
if (typeof props !== 'object' || props === null)
|
|
3
12
|
return props;
|
|
@@ -19,3 +28,33 @@ export const pruneNullValues = (props) => {
|
|
|
19
28
|
}
|
|
20
29
|
return props;
|
|
21
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* How long a single asynchronous source middleware may take before its
|
|
33
|
+
* contribution is abandoned.
|
|
34
|
+
*
|
|
35
|
+
* Middleware runs on the path to the CDP, so an unbounded wait would let one
|
|
36
|
+
* slow lookup hold up delivery indefinitely. `Order Completed` in particular
|
|
37
|
+
* fires on a confirmation page shoppers close, so a late event is a lost one.
|
|
38
|
+
*/
|
|
39
|
+
export const MIDDLEWARE_TIMEOUT_MS = 1000;
|
|
40
|
+
/** Returned by {@link withTimeout} when the promise did not settle in time. */
|
|
41
|
+
export const TIMED_OUT = Symbol('timed-out');
|
|
42
|
+
export const isPromise = (value) => typeof (value === null || value === void 0 ? void 0 : value.then) === 'function';
|
|
43
|
+
/**
|
|
44
|
+
* Resolve `promise`, or {@link TIMED_OUT} if it has not settled within `ms`.
|
|
45
|
+
*
|
|
46
|
+
* The timer is cleared either way, so a promise that settles quickly does not
|
|
47
|
+
* leave a pending timeout behind.
|
|
48
|
+
*/
|
|
49
|
+
export const withTimeout = (promise, ms) => __awaiter(void 0, void 0, void 0, function* () {
|
|
50
|
+
let timer;
|
|
51
|
+
const timeout = new Promise((resolve) => {
|
|
52
|
+
timer = setTimeout(() => resolve(TIMED_OUT), ms);
|
|
53
|
+
});
|
|
54
|
+
try {
|
|
55
|
+
return yield Promise.race([promise, timeout]);
|
|
56
|
+
}
|
|
57
|
+
finally {
|
|
58
|
+
clearTimeout(timer);
|
|
59
|
+
}
|
|
60
|
+
});
|
package/package.json
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chordcommerce/analytics",
|
|
3
3
|
"description": "Chord Commerce event tracking",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.25.0-beta.2",
|
|
5
5
|
"author": "Chord Commerce <help@chord.co> (https://www.chord.co)",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/chordcommerce/chord-pixel.git",
|
|
9
|
+
"directory": "packages/core"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"registry": "https://registry.npmjs.org/",
|
|
13
|
+
"@chordcommerce:registry": "https://registry.npmjs.org/",
|
|
14
|
+
"provenance": false
|
|
15
|
+
},
|
|
6
16
|
"type": "module",
|
|
7
17
|
"main": "dist/index.js",
|
|
8
18
|
"types": "dist/index.d.ts",
|