@xenia-martech/sdk-js 1.0.1-dev.1 → 1.1.0-dev.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 +54 -4
- package/dist/{actions-CcBYV--3.d.cts → actions-CKeiofxJ.d.cts} +19 -1
- package/dist/{actions-CcBYV--3.d.ts → actions-CKeiofxJ.d.ts} +19 -1
- package/dist/{cookie-names-B3b0XNc2.d.cts → api-URhxxi4x.d.cts} +19 -42
- package/dist/{cookie-names-B3b0XNc2.d.ts → api-URhxxi4x.d.ts} +19 -42
- package/dist/chunk-5D7SJIO4.cjs +109 -0
- package/dist/chunk-5D7SJIO4.cjs.map +1 -0
- package/dist/{chunk-XXNDHYAS.js → chunk-FYSEKFIY.js} +45 -103
- package/dist/chunk-FYSEKFIY.js.map +1 -0
- package/dist/{chunk-WYM4CQVG.cjs → chunk-JEKVN7HK.cjs} +46 -106
- package/dist/chunk-JEKVN7HK.cjs.map +1 -0
- package/dist/chunk-TLTG3BTC.js +104 -0
- package/dist/chunk-TLTG3BTC.js.map +1 -0
- package/dist/chunk-U2WBBOYT.cjs +233 -0
- package/dist/chunk-U2WBBOYT.cjs.map +1 -0
- package/dist/chunk-WYAMPEVV.js +227 -0
- package/dist/chunk-WYAMPEVV.js.map +1 -0
- package/dist/client/index.cjs +60 -6
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.d.cts +25 -3
- package/dist/client/index.d.ts +25 -3
- package/dist/client/index.js +59 -7
- package/dist/client/index.js.map +1 -1
- package/dist/client/react/index.cjs +58 -6
- package/dist/client/react/index.cjs.map +1 -1
- package/dist/client/react/index.d.cts +2 -2
- package/dist/client/react/index.d.ts +2 -2
- package/dist/client/react/index.js +58 -6
- package/dist/client/react/index.js.map +1 -1
- package/dist/cookie-names-8FxbGKGS.d.ts +127 -0
- package/dist/cookie-names-QYMiEMAq.d.cts +127 -0
- package/dist/index.cjs +41 -32
- package/dist/index.d.cts +4 -71
- package/dist/index.d.ts +4 -71
- package/dist/index.js +2 -1
- package/dist/next/index.cjs +59 -0
- package/dist/next/index.cjs.map +1 -0
- package/dist/next/index.d.cts +45 -0
- package/dist/next/index.d.ts +45 -0
- package/dist/next/index.js +54 -0
- package/dist/next/index.js.map +1 -0
- package/dist/server/index.cjs +38 -214
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.cts +5 -104
- package/dist/server/index.d.ts +5 -104
- package/dist/server/index.js +5 -204
- package/dist/server/index.js.map +1 -1
- package/dist/xenia-sdk.iife.js +3 -3
- package/dist/xenia-sdk.iife.js.map +1 -1
- package/dist/xenia-server-D-ozqSgv.d.ts +126 -0
- package/dist/xenia-server-rs3Gpbw7.d.cts +126 -0
- package/package.json +26 -7
- package/dist/chunk-WYM4CQVG.cjs.map +0 -1
- package/dist/chunk-XXNDHYAS.js.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as react from 'react';
|
|
3
3
|
import { ReactNode, ElementType, ComponentType } from 'react';
|
|
4
|
-
import { y as XeniaClientOptions, x as XeniaClient, s as ResolveResult, q as ResolveBatchResult, J as JsonValue, t as WebhookResponse, R as ResolveBatchItem, g as AnalyticsEventName, T as TrackOptions, e as XeniaAction, I as InteractionType, o as MessageMountContext, c as MessageComponentRenderer } from '../../actions-
|
|
5
|
-
export { A as AnalyticsContext, h as AnalyticsIdentity, i as AnalyticsIngestResponse,
|
|
4
|
+
import { y as XeniaClientOptions, x as XeniaClient, s as ResolveResult, q as ResolveBatchResult, J as JsonValue, t as WebhookResponse, R as ResolveBatchItem, g as AnalyticsEventName, T as TrackOptions, e as XeniaAction, I as InteractionType, o as MessageMountContext, c as MessageComponentRenderer } from '../../actions-CKeiofxJ.cjs';
|
|
5
|
+
export { A as AnalyticsContext, h as AnalyticsIdentity, i as AnalyticsIngestResponse, j as ClientEvent, C as ConsentState, k as ContentSwap, l as IdentifyRequest, m as IdentifyResponse, M as MessageCta, f as MessagePlacement, p as MessageRenderContext, b as MessageTemplateFn, P as PersonalizationSwap, r as ResolveOptions, X as XeniaConfig, a as XeniaEvent, z as createXeniaClient, B as extractContentSwaps, D as parseActions, E as spliceSlots } from '../../actions-CKeiofxJ.cjs';
|
|
6
6
|
|
|
7
7
|
interface XeniaProviderProps extends XeniaClientOptions {
|
|
8
8
|
children: ReactNode;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as react from 'react';
|
|
3
3
|
import { ReactNode, ElementType, ComponentType } from 'react';
|
|
4
|
-
import { y as XeniaClientOptions, x as XeniaClient, s as ResolveResult, q as ResolveBatchResult, J as JsonValue, t as WebhookResponse, R as ResolveBatchItem, g as AnalyticsEventName, T as TrackOptions, e as XeniaAction, I as InteractionType, o as MessageMountContext, c as MessageComponentRenderer } from '../../actions-
|
|
5
|
-
export { A as AnalyticsContext, h as AnalyticsIdentity, i as AnalyticsIngestResponse,
|
|
4
|
+
import { y as XeniaClientOptions, x as XeniaClient, s as ResolveResult, q as ResolveBatchResult, J as JsonValue, t as WebhookResponse, R as ResolveBatchItem, g as AnalyticsEventName, T as TrackOptions, e as XeniaAction, I as InteractionType, o as MessageMountContext, c as MessageComponentRenderer } from '../../actions-CKeiofxJ.js';
|
|
5
|
+
export { A as AnalyticsContext, h as AnalyticsIdentity, i as AnalyticsIngestResponse, j as ClientEvent, C as ConsentState, k as ContentSwap, l as IdentifyRequest, m as IdentifyResponse, M as MessageCta, f as MessagePlacement, p as MessageRenderContext, b as MessageTemplateFn, P as PersonalizationSwap, r as ResolveOptions, X as XeniaConfig, a as XeniaEvent, z as createXeniaClient, B as extractContentSwaps, D as parseActions, E as spliceSlots } from '../../actions-CKeiofxJ.js';
|
|
6
6
|
|
|
7
7
|
interface XeniaProviderProps extends XeniaClientOptions {
|
|
8
8
|
children: ReactNode;
|
|
@@ -168,12 +168,22 @@ var HttpError = class extends Error {
|
|
|
168
168
|
status;
|
|
169
169
|
data;
|
|
170
170
|
};
|
|
171
|
+
var CircuitOpenError = class extends Error {
|
|
172
|
+
constructor(endpoint) {
|
|
173
|
+
super(`Circuit open for ${endpoint}: failing fast until the cooldown passes`);
|
|
174
|
+
this.endpoint = endpoint;
|
|
175
|
+
this.name = "CircuitOpenError";
|
|
176
|
+
}
|
|
177
|
+
endpoint;
|
|
178
|
+
};
|
|
179
|
+
var breakers = /* @__PURE__ */ new Map();
|
|
171
180
|
var HttpClient = class {
|
|
172
181
|
baseUrl;
|
|
173
182
|
defaultHeaders;
|
|
174
183
|
timeout;
|
|
175
184
|
retry;
|
|
176
185
|
debug;
|
|
186
|
+
breaker;
|
|
177
187
|
constructor(opts) {
|
|
178
188
|
this.baseUrl = (opts.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
179
189
|
this.defaultHeaders = opts.defaultHeaders ?? {};
|
|
@@ -183,8 +193,37 @@ var HttpClient = class {
|
|
|
183
193
|
baseDelayMs: opts.retry?.baseDelayMs ?? 300
|
|
184
194
|
};
|
|
185
195
|
this.debug = opts.debug ?? false;
|
|
196
|
+
const cb = opts.circuitBreaker === true ? {} : opts.circuitBreaker || null;
|
|
197
|
+
this.breaker = cb && { failureThreshold: cb.failureThreshold ?? 3, cooldownMs: cb.cooldownMs ?? 3e4 };
|
|
186
198
|
}
|
|
187
199
|
async request(opts) {
|
|
200
|
+
if (!this.breaker) return this.send(opts);
|
|
201
|
+
const key = buildUrl(this.baseUrl + opts.path, opts.query);
|
|
202
|
+
const b = breakers.get(key) ?? { failures: 0, openedAt: 0 };
|
|
203
|
+
if (b.openedAt) {
|
|
204
|
+
if (Date.now() - b.openedAt < this.breaker.cooldownMs) throw new CircuitOpenError(key);
|
|
205
|
+
b.openedAt = 0;
|
|
206
|
+
b.failures = this.breaker.failureThreshold - 1;
|
|
207
|
+
}
|
|
208
|
+
try {
|
|
209
|
+
const result = await this.send(opts);
|
|
210
|
+
breakers.delete(key);
|
|
211
|
+
return result;
|
|
212
|
+
} catch (err) {
|
|
213
|
+
if (err instanceof HttpError && !this.isRetryableStatus(err.status)) {
|
|
214
|
+
breakers.delete(key);
|
|
215
|
+
throw err;
|
|
216
|
+
}
|
|
217
|
+
b.failures += 1;
|
|
218
|
+
if (b.failures >= this.breaker.failureThreshold) {
|
|
219
|
+
b.openedAt = Date.now();
|
|
220
|
+
this.log(`circuit opened for ${opts.path} after ${b.failures} failures`);
|
|
221
|
+
}
|
|
222
|
+
breakers.set(key, b);
|
|
223
|
+
throw err;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
async send(opts) {
|
|
188
227
|
const url = buildUrl(this.baseUrl + opts.path, opts.query);
|
|
189
228
|
const method = opts.method ?? "GET";
|
|
190
229
|
const headers = {
|
|
@@ -337,6 +376,7 @@ var XeniaApi = class {
|
|
|
337
376
|
defaultHeaders: config.headers,
|
|
338
377
|
timeout: config.timeout,
|
|
339
378
|
retry: config.retry,
|
|
379
|
+
circuitBreaker: config.circuitBreaker,
|
|
340
380
|
debug: config.debug
|
|
341
381
|
});
|
|
342
382
|
}
|
|
@@ -509,6 +549,18 @@ var XeniaApi = class {
|
|
|
509
549
|
}
|
|
510
550
|
};
|
|
511
551
|
|
|
552
|
+
// src/core/cookie-names.ts
|
|
553
|
+
var DEFAULT_PREFIX = "xenia";
|
|
554
|
+
function visitorCookieName(prefix = DEFAULT_PREFIX) {
|
|
555
|
+
return `${prefix || DEFAULT_PREFIX}_vid`;
|
|
556
|
+
}
|
|
557
|
+
function consentCookieName(prefix = DEFAULT_PREFIX) {
|
|
558
|
+
return `${prefix || DEFAULT_PREFIX}_consent`;
|
|
559
|
+
}
|
|
560
|
+
function consentCookie(state, prefix, maxAgeDays = 365) {
|
|
561
|
+
return `${consentCookieName(prefix)}=${encodeURIComponent(JSON.stringify(state))}; path=/; max-age=${Math.floor(maxAgeDays * 86400)}; SameSite=Lax`;
|
|
562
|
+
}
|
|
563
|
+
|
|
512
564
|
// src/core/event-payload.ts
|
|
513
565
|
var RESERVED = /* @__PURE__ */ new Set([
|
|
514
566
|
"eventId",
|
|
@@ -938,12 +990,6 @@ var AutoTracker = class {
|
|
|
938
990
|
}
|
|
939
991
|
};
|
|
940
992
|
|
|
941
|
-
// src/core/cookie-names.ts
|
|
942
|
-
var DEFAULT_PREFIX = "xenia";
|
|
943
|
-
function visitorCookieName(prefix = DEFAULT_PREFIX) {
|
|
944
|
-
return `${prefix || DEFAULT_PREFIX}_vid`;
|
|
945
|
-
}
|
|
946
|
-
|
|
947
993
|
// src/client/identity.ts
|
|
948
994
|
var SESSION_TIMEOUT_MS = 30 * 60 * 1e3;
|
|
949
995
|
var Identity = class {
|
|
@@ -2221,6 +2267,12 @@ var XeniaClient = class {
|
|
|
2221
2267
|
async consent(state) {
|
|
2222
2268
|
const wasAllowed = this.analyticsAllowed();
|
|
2223
2269
|
this.consentState = { ...this.consentState, ...state };
|
|
2270
|
+
if (isBrowser()) {
|
|
2271
|
+
try {
|
|
2272
|
+
document.cookie = consentCookie(this.consentState, this.options.prefix);
|
|
2273
|
+
} catch {
|
|
2274
|
+
}
|
|
2275
|
+
}
|
|
2224
2276
|
if (this.analyticsAllowed() && !wasAllowed) {
|
|
2225
2277
|
this.analyticsQueue.start();
|
|
2226
2278
|
void this.analyticsQueue.flush();
|