@reopt-ai/data-sdk-client 0.1.5 → 0.2.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.
- package/README.md +141 -7
- package/dist/client-B1GlWwVq.d.ts +744 -0
- package/dist/client-B1GlWwVq.d.ts.map +1 -0
- package/dist/client-BCrui21p.d.cts +744 -0
- package/dist/client-BCrui21p.d.cts.map +1 -0
- package/dist/exceptions-C9Fh0BIR.js +285 -0
- package/dist/exceptions-C9Fh0BIR.js.map +1 -0
- package/dist/exceptions-CuhGo9A5.cjs +289 -0
- package/dist/exceptions-CuhGo9A5.cjs.map +1 -0
- package/dist/index.cjs +75 -1874
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +83 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +35 -33
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +49 -70
- package/dist/index.js.map +1 -1
- package/dist/next.cjs +51 -1919
- package/dist/next.cjs.map +1 -1
- package/dist/next.d.cts +31 -0
- package/dist/next.d.cts.map +1 -0
- package/dist/next.d.ts +8 -10
- package/dist/next.d.ts.map +1 -0
- package/dist/next.js +36 -49
- package/dist/next.js.map +1 -1
- package/dist/observe-D-BHMwrO.cjs +54 -0
- package/dist/observe-D-BHMwrO.cjs.map +1 -0
- package/dist/observe-D1pNg1qL.js +54 -0
- package/dist/observe-D1pNg1qL.js.map +1 -0
- package/dist/react.cjs +105 -1863
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +80 -0
- package/dist/react.d.cts.map +1 -0
- package/dist/react.d.ts +53 -47
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +118 -23
- package/dist/react.js.map +1 -1
- package/dist/registry-BPhiH_l9.js +1775 -0
- package/dist/registry-BPhiH_l9.js.map +1 -0
- package/dist/registry-CGqrOtf4.cjs +1810 -0
- package/dist/registry-CGqrOtf4.cjs.map +1 -0
- package/dist/tracing-DAhaKkl0.cjs +93 -0
- package/dist/tracing-DAhaKkl0.cjs.map +1 -0
- package/dist/tracing-Dt1RVuQ9.js +93 -0
- package/dist/tracing-Dt1RVuQ9.js.map +1 -0
- package/package.json +31 -16
- package/dist/chunk-2UPF3C7D.js +0 -106
- package/dist/chunk-2UPF3C7D.js.map +0 -1
- package/dist/chunk-4MTDZBRS.js +0 -57
- package/dist/chunk-4MTDZBRS.js.map +0 -1
- package/dist/chunk-BJGIHFDA.js +0 -1627
- package/dist/chunk-BJGIHFDA.js.map +0 -1
- package/dist/client-TesmBLXd.d.ts +0 -581
- package/dist/exceptions-NQHZUDYO.js +0 -9
- package/dist/exceptions-NQHZUDYO.js.map +0 -1
- package/dist/tracing-LC3NZND7.js +0 -91
- package/dist/tracing-LC3NZND7.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,116 +1,95 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
extractUTMParams,
|
|
4
|
-
forgetClient,
|
|
5
|
-
getClient,
|
|
6
|
-
getOrCreateClient
|
|
7
|
-
} from "./chunk-BJGIHFDA.js";
|
|
8
|
-
import "./chunk-4MTDZBRS.js";
|
|
9
|
-
|
|
10
|
-
// src/index.ts
|
|
1
|
+
import { a as extractUTMParams, i as ReoptClient, n as getClient, r as getOrCreateClient, t as forgetClient } from "./registry-BPhiH_l9.js";
|
|
2
|
+
//#region src/index.ts
|
|
11
3
|
function init(config) {
|
|
12
|
-
|
|
4
|
+
return getOrCreateClient(config);
|
|
13
5
|
}
|
|
14
6
|
function getInstance() {
|
|
15
|
-
|
|
7
|
+
return getClient();
|
|
16
8
|
}
|
|
17
9
|
function current() {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
10
|
+
const client = getClient();
|
|
11
|
+
if (!client) console.warn("[reopt] not initialized — call init() first");
|
|
12
|
+
return client;
|
|
21
13
|
}
|
|
22
|
-
|
|
14
|
+
const withId = (idOrOptions, rest) => typeof idOrOptions === "object" ? idOrOptions : {
|
|
15
|
+
profileId: idOrOptions,
|
|
16
|
+
...rest
|
|
17
|
+
};
|
|
23
18
|
function track(nameOrOptions, properties) {
|
|
24
|
-
|
|
19
|
+
return current()?.track(typeof nameOrOptions === "string" ? {
|
|
20
|
+
name: nameOrOptions,
|
|
21
|
+
properties
|
|
22
|
+
} : nameOrOptions);
|
|
25
23
|
}
|
|
26
24
|
function identify(idOrOptions, properties) {
|
|
27
|
-
|
|
25
|
+
return current()?.identify(withId(idOrOptions, { properties }));
|
|
28
26
|
}
|
|
29
27
|
function increment(idOrOptions, property, value) {
|
|
30
|
-
|
|
28
|
+
return current()?.increment(withId(idOrOptions, {
|
|
29
|
+
property: property ?? "",
|
|
30
|
+
value
|
|
31
|
+
}));
|
|
31
32
|
}
|
|
32
33
|
function decrement(idOrOptions, property, value) {
|
|
33
|
-
|
|
34
|
+
return current()?.decrement(withId(idOrOptions, {
|
|
35
|
+
property: property ?? "",
|
|
36
|
+
value
|
|
37
|
+
}));
|
|
34
38
|
}
|
|
35
39
|
function pageView(options) {
|
|
36
|
-
|
|
40
|
+
return current()?.pageView(options);
|
|
37
41
|
}
|
|
38
42
|
function screenView(screenName, properties) {
|
|
39
|
-
|
|
43
|
+
return current()?.screenView(screenName, properties);
|
|
40
44
|
}
|
|
41
45
|
function captureWebVital(metric) {
|
|
42
|
-
|
|
46
|
+
return current()?.captureWebVital(metric);
|
|
43
47
|
}
|
|
44
48
|
function captureException(error, properties) {
|
|
45
|
-
|
|
49
|
+
return current()?.captureException(error, properties);
|
|
46
50
|
}
|
|
47
51
|
function getDeviceId() {
|
|
48
|
-
|
|
49
|
-
|
|
52
|
+
const client = getClient();
|
|
53
|
+
return client && !client.disabled ? client.getDeviceId() : null;
|
|
50
54
|
}
|
|
51
55
|
function register(properties) {
|
|
52
|
-
|
|
56
|
+
current()?.register(properties);
|
|
53
57
|
}
|
|
54
58
|
function unregister(...keys) {
|
|
55
|
-
|
|
59
|
+
current()?.unregister(...keys);
|
|
56
60
|
}
|
|
57
61
|
function setProfileId(profileId) {
|
|
58
|
-
|
|
62
|
+
current()?.setProfileId(profileId);
|
|
59
63
|
}
|
|
60
64
|
function reset() {
|
|
61
|
-
|
|
65
|
+
getClient()?.reset();
|
|
62
66
|
}
|
|
63
67
|
function flush() {
|
|
64
|
-
|
|
65
|
-
|
|
68
|
+
const client = getClient();
|
|
69
|
+
return client ? client.flush() : Promise.resolve(void 0);
|
|
66
70
|
}
|
|
67
71
|
async function close() {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
const client = getClient();
|
|
73
|
+
if (!client) return void 0;
|
|
74
|
+
forgetClient(client);
|
|
75
|
+
return client.close();
|
|
72
76
|
}
|
|
73
77
|
function setConsent(category, allowed) {
|
|
74
|
-
|
|
78
|
+
current()?.setConsent(category, allowed);
|
|
75
79
|
}
|
|
76
80
|
function getConsent(category) {
|
|
77
|
-
|
|
81
|
+
return current()?.getConsent(category) ?? false;
|
|
78
82
|
}
|
|
79
83
|
function setAllConsent(allowed) {
|
|
80
|
-
|
|
84
|
+
current()?.setAllConsent(allowed);
|
|
81
85
|
}
|
|
82
86
|
function pauseTracking() {
|
|
83
|
-
|
|
87
|
+
current()?.pauseTracking();
|
|
84
88
|
}
|
|
85
89
|
function resumeTracking() {
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
captureWebVital,
|
|
92
|
-
close,
|
|
93
|
-
decrement,
|
|
94
|
-
extractUTMParams,
|
|
95
|
-
flush,
|
|
96
|
-
getClient,
|
|
97
|
-
getConsent,
|
|
98
|
-
getDeviceId,
|
|
99
|
-
getInstance,
|
|
100
|
-
getOrCreateClient,
|
|
101
|
-
identify,
|
|
102
|
-
increment,
|
|
103
|
-
init,
|
|
104
|
-
pageView,
|
|
105
|
-
pauseTracking,
|
|
106
|
-
register,
|
|
107
|
-
reset,
|
|
108
|
-
resumeTracking,
|
|
109
|
-
screenView,
|
|
110
|
-
setAllConsent,
|
|
111
|
-
setConsent,
|
|
112
|
-
setProfileId,
|
|
113
|
-
track,
|
|
114
|
-
unregister
|
|
115
|
-
};
|
|
90
|
+
current()?.resumeTracking();
|
|
91
|
+
}
|
|
92
|
+
//#endregion
|
|
93
|
+
export { ReoptClient, captureException, captureWebVital, close, decrement, extractUTMParams, flush, getClient, getConsent, getDeviceId, getInstance, getOrCreateClient, identify, increment, init, pageView, pauseTracking, register, reset, resumeTracking, screenView, setAllConsent, setConsent, setProfileId, track, unregister };
|
|
94
|
+
|
|
116
95
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * `@reopt-ai/data-sdk-client` — the browser SDK.\n *\n * This entry has no framework directive: it works from a `<script>` tag, a\n * plain SPA, or any framework. `./react` and `./next` add the components.\n *\n * The module-level functions (`track`, `identify`, …) operate on the client\n * created by `init()`. They warn and return `undefined` before `init()`, so a\n * call that runs too early is visible in the console rather than lost.\n */\nimport type {\n ConsentCategory,\n DecrementOptions,\n FlushResult,\n IdentifyOptions,\n IncrementOptions,\n PageViewOptions,\n QueueResult,\n TrackEventOptions,\n} from \"@reopt-ai/data-sdk-core\";\nimport { ReoptClient } from \"./client.js\";\nimport type { WebVitalMetric } from \"./capture/web-vitals.js\";\nimport type { ReoptClientConfig } from \"./config.js\";\nimport { forgetClient, getClient, getOrCreateClient } from \"./registry.js\";\n\nexport { ReoptClient } from \"./client.js\";\nexport { getClient, getOrCreateClient } from \"./registry.js\";\nexport { extractUTMParams } from \"./capture/utm.js\";\nexport type { WebVitalMetric, WebVitalProperties } from \"./capture/web-vitals.js\";\nexport type { ExceptionProperties } from \"./capture/
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * `@reopt-ai/data-sdk-client` — the browser SDK.\n *\n * This entry has no framework directive: it works from a `<script>` tag, a\n * plain SPA, or any framework. `./react` and `./next` add the components.\n *\n * The module-level functions (`track`, `identify`, …) operate on the client\n * created by `init()`. They warn and return `undefined` before `init()`, so a\n * call that runs too early is visible in the console rather than lost.\n */\nimport type {\n ConsentCategory,\n DecrementOptions,\n FlushResult,\n IdentifyOptions,\n IncrementOptions,\n PageViewOptions,\n QueueResult,\n TrackEventOptions,\n} from \"@reopt-ai/data-sdk-core\";\nimport { ReoptClient } from \"./client.js\";\nimport type { WebVitalMetric } from \"./capture/web-vitals.js\";\nimport type { ReoptClientConfig } from \"./config.js\";\nimport { forgetClient, getClient, getOrCreateClient } from \"./registry.js\";\n\nexport { ReoptClient } from \"./client.js\";\nexport { getClient, getOrCreateClient } from \"./registry.js\";\nexport { extractUTMParams } from \"./capture/utm.js\";\nexport type { WebVitalMetric, WebVitalProperties } from \"./capture/web-vitals.js\";\nexport type { ExceptionProperties } from \"./capture/describe-error.js\";\nexport type { PageLeaveProperties } from \"./capture/pageleave.js\";\nexport type {\n CaptureConfig,\n IdentityConfig,\n IdentityStorageKind,\n NormalizePath,\n ReoptBootstrap,\n ReoptClientConfig,\n ReoptClientObservation,\n ReoptClientObserver,\n ReoptObservedEventType,\n} from \"./config.js\";\nexport type {\n BatchConfig,\n CircuitBreakerConfig,\n ConsentCategory,\n ConsentConfig,\n DecrementOptions,\n EventIdentity,\n EventPayload,\n FetchInit,\n FetchLike,\n FetchResponseLike,\n FlushResult,\n IdentifyOptions,\n IncrementOptions,\n PageViewOptions,\n QueueDropReason,\n QueueResult,\n RetryConfig,\n StorageBackend,\n TrackEventOptions,\n UTMParams,\n} from \"@reopt-ai/data-sdk-core\";\n\n/** Creates (or returns) the page's client for `config.writeKey`. */\nexport function init(config: ReoptClientConfig): ReoptClient {\n return getOrCreateClient(config);\n}\n\n/** The client created by `init()`, or `null`. */\nexport function getInstance(): ReoptClient | null {\n return getClient();\n}\n\nfunction current(): ReoptClient | null {\n const client = getClient();\n if (!client) console.warn(\"[reopt] not initialized — call init() first\");\n return client;\n}\n\n/** Normalises the `(id, …)` and `(options)` call forms the module functions accept. */\nconst withId = <T extends { profileId: string | number }>(\n idOrOptions: string | number | T,\n rest: Omit<T, \"profileId\">\n): T => (typeof idOrOptions === \"object\" ? idOrOptions : ({ profileId: idOrOptions, ...rest } as T));\n\nexport function track(options: TrackEventOptions): QueueResult | undefined;\nexport function track(name: string, properties?: Record<string, unknown>): QueueResult | undefined;\nexport function track(\n nameOrOptions: string | TrackEventOptions,\n properties?: Record<string, unknown>\n): QueueResult | undefined {\n return current()?.track(typeof nameOrOptions === \"string\" ? { name: nameOrOptions, properties } : nameOrOptions);\n}\n\nexport function identify(options: IdentifyOptions): QueueResult | undefined;\nexport function identify(profileId: string | number, properties?: Record<string, unknown>): QueueResult | undefined;\nexport function identify(\n idOrOptions: string | number | IdentifyOptions,\n properties?: Record<string, unknown>\n): QueueResult | undefined {\n return current()?.identify(withId<IdentifyOptions>(idOrOptions, { properties }));\n}\n\nexport function increment(options: IncrementOptions): QueueResult | undefined;\nexport function increment(profileId: string | number, property: string, value?: number): QueueResult | undefined;\nexport function increment(\n idOrOptions: string | number | IncrementOptions,\n property?: string,\n value?: number\n): QueueResult | undefined {\n return current()?.increment(withId<IncrementOptions>(idOrOptions, { property: property ?? \"\", value }));\n}\n\nexport function decrement(options: DecrementOptions): QueueResult | undefined;\nexport function decrement(profileId: string | number, property: string, value?: number): QueueResult | undefined;\nexport function decrement(\n idOrOptions: string | number | DecrementOptions,\n property?: string,\n value?: number\n): QueueResult | undefined {\n return current()?.decrement(withId<DecrementOptions>(idOrOptions, { property: property ?? \"\", value }));\n}\n\nexport function pageView(options?: PageViewOptions): QueueResult | undefined {\n return current()?.pageView(options);\n}\n\nexport function screenView(screenName: string, properties?: Record<string, unknown>): QueueResult | undefined {\n return current()?.screenView(screenName, properties);\n}\n\nexport function captureWebVital(metric: WebVitalMetric): QueueResult | undefined {\n return current()?.captureWebVital(metric);\n}\n\nexport function captureException(error: unknown, properties?: Record<string, unknown>): QueueResult | undefined {\n return current()?.captureException(error, properties);\n}\n\n/**\n * The device id this page is tracked under, for passing to your own server\n * calls explicitly (e.g. as a body field a route handler forwards as the\n * event's `deviceId`). `null` before `init()` or when analytics is disabled.\n */\nexport function getDeviceId(): string | null {\n const client = getClient();\n return client && !client.disabled ? client.getDeviceId() : null;\n}\n\n/** Attach `properties` to every event from now on (an event's own properties win). */\nexport function register(properties: Record<string, unknown>): void {\n current()?.register(properties);\n}\n\nexport function unregister(...keys: string[]): void {\n current()?.unregister(...keys);\n}\n\nexport function setProfileId(profileId: string | number | null): void {\n current()?.setProfileId(profileId);\n}\n\nexport function reset(): void {\n getClient()?.reset();\n}\n\nexport function flush(): Promise<FlushResult | undefined> {\n const client = getClient();\n return client ? client.flush() : Promise.resolve(undefined);\n}\n\n/** Flushes, tears down listeners, and forgets the client so `init()` starts fresh. */\nexport async function close(): Promise<FlushResult | undefined> {\n const client = getClient();\n if (!client) return undefined;\n forgetClient(client);\n return client.close();\n}\n\nexport function setConsent(category: ConsentCategory, allowed: boolean): void {\n current()?.setConsent(category, allowed);\n}\n\nexport function getConsent(category: ConsentCategory): boolean {\n return current()?.getConsent(category) ?? false;\n}\n\nexport function setAllConsent(allowed: boolean): void {\n current()?.setAllConsent(allowed);\n}\n\nexport function pauseTracking(): void {\n current()?.pauseTracking();\n}\n\nexport function resumeTracking(): void {\n current()?.resumeTracking();\n}\n"],"mappings":";;AAkEA,SAAgB,KAAK,QAAwC;CAC3D,OAAO,kBAAkB,MAAM;AACjC;AAGA,SAAgB,cAAkC;CAChD,OAAO,UAAU;AACnB;AAEA,SAAS,UAA8B;CACrC,MAAM,SAAS,UAAU;CACzB,IAAI,CAAC,QAAQ,QAAQ,KAAK,6CAA6C;CACvE,OAAO;AACT;AAGA,MAAM,UACJ,aACA,SACO,OAAO,gBAAgB,WAAW,cAAe;CAAE,WAAW;CAAa,GAAG;AAAK;AAI5F,SAAgB,MACd,eACA,YACyB;CACzB,OAAO,QAAQ,CAAC,EAAE,MAAM,OAAO,kBAAkB,WAAW;EAAE,M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