@atsignal/browser 0.1.2 → 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 +3 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/signal.global.js +35 -37
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -14,12 +14,15 @@ pnpm add @atsignal/browser
|
|
|
14
14
|
import signal from "@atsignal/browser";
|
|
15
15
|
|
|
16
16
|
await signal.init("your-api-key", {
|
|
17
|
+
endpoint: "https://your-collector.example.com/track",
|
|
17
18
|
persistQueue: false,
|
|
18
19
|
});
|
|
19
20
|
|
|
20
21
|
await signal.track("PageView");
|
|
21
22
|
```
|
|
22
23
|
|
|
24
|
+
Set `endpoint` to your real collector URL. The SDK default, `https://api.example.com/track`, is a placeholder used for docs/tests and will not send events anywhere useful by itself.
|
|
25
|
+
|
|
23
26
|
Optional browser plugins are published as separate packages. For example, install `@atsignal/browser-plugin-enrich-context` and import it before using `signal.plugins.enrichContext()`.
|
|
24
27
|
|
|
25
28
|
More SDK details live in the monorepo root README.
|
package/dist/index.cjs
CHANGED
|
@@ -166,7 +166,7 @@ var SignalBrowserClient = class extends import_js_core2.SignalClient {
|
|
|
166
166
|
const queueStorage = options.persistQueue === false ? void 0 : (_c = options.storage) == null ? void 0 : _c.queue;
|
|
167
167
|
return {
|
|
168
168
|
...options,
|
|
169
|
-
|
|
169
|
+
transport: (_d = options.transport) != null ? _d : (0, import_js_core2.createFetchTransport)({ keepalive: true }),
|
|
170
170
|
storage: {
|
|
171
171
|
identity: identityStorage,
|
|
172
172
|
...queueStorage !== void 0 ? { queue: queueStorage } : {}
|
package/dist/index.js
CHANGED
|
@@ -140,7 +140,7 @@ var SignalBrowserClient = class extends SignalClient {
|
|
|
140
140
|
const queueStorage = options.persistQueue === false ? void 0 : (_c = options.storage) == null ? void 0 : _c.queue;
|
|
141
141
|
return {
|
|
142
142
|
...options,
|
|
143
|
-
|
|
143
|
+
transport: (_d = options.transport) != null ? _d : createFetchTransport({ keepalive: true }),
|
|
144
144
|
storage: {
|
|
145
145
|
identity: identityStorage,
|
|
146
146
|
...queueStorage !== void 0 ? { queue: queueStorage } : {}
|
package/dist/signal.global.js
CHANGED
|
@@ -157,14 +157,17 @@ var __signalBundle = (() => {
|
|
|
157
157
|
return normalizePersistedQueueEntries(stored);
|
|
158
158
|
}
|
|
159
159
|
};
|
|
160
|
-
function resolveTimerApi(
|
|
161
|
-
const timers =
|
|
160
|
+
function resolveTimerApi() {
|
|
161
|
+
const timers = globalThis;
|
|
162
162
|
const maybeSetTimeout = timers == null ? void 0 : timers.setTimeout;
|
|
163
163
|
const maybeClearTimeout = timers == null ? void 0 : timers.clearTimeout;
|
|
164
164
|
if (typeof maybeSetTimeout !== "function" || typeof maybeClearTimeout !== "function") {
|
|
165
165
|
return null;
|
|
166
166
|
}
|
|
167
|
-
return
|
|
167
|
+
return {
|
|
168
|
+
setTimeout: maybeSetTimeout.bind(timers),
|
|
169
|
+
clearTimeout: maybeClearTimeout.bind(timers)
|
|
170
|
+
};
|
|
168
171
|
}
|
|
169
172
|
function scheduleTask(callback, delayMs, timers) {
|
|
170
173
|
const handle = timers.setTimeout(callback, delayMs);
|
|
@@ -190,11 +193,12 @@ var __signalBundle = (() => {
|
|
|
190
193
|
};
|
|
191
194
|
}
|
|
192
195
|
function resolveGlobalFetch() {
|
|
193
|
-
const
|
|
196
|
+
const globalObject2 = globalThis;
|
|
197
|
+
const candidate = globalObject2.fetch;
|
|
194
198
|
if (typeof candidate !== "function") {
|
|
195
199
|
return null;
|
|
196
200
|
}
|
|
197
|
-
return candidate;
|
|
201
|
+
return candidate.bind(globalObject2);
|
|
198
202
|
}
|
|
199
203
|
function encodeRequestBody(request) {
|
|
200
204
|
const parts = [
|
|
@@ -221,12 +225,16 @@ var __signalBundle = (() => {
|
|
|
221
225
|
return parts.join("&");
|
|
222
226
|
}
|
|
223
227
|
var FetchTransport = class {
|
|
224
|
-
constructor(
|
|
228
|
+
constructor(options = {}) {
|
|
225
229
|
var _a, _b, _c;
|
|
226
230
|
const fetchImpl = (_a = options.fetch) != null ? _a : resolveGlobalFetch();
|
|
231
|
+
const timers = resolveTimerApi();
|
|
227
232
|
if (!fetchImpl) {
|
|
228
233
|
throw new Error("No fetch implementation found for FetchTransport");
|
|
229
234
|
}
|
|
235
|
+
if (!timers) {
|
|
236
|
+
throw new Error("No timer implementation found for FetchTransport");
|
|
237
|
+
}
|
|
230
238
|
this._fetch = fetchImpl;
|
|
231
239
|
this._keepalive = (_b = options.keepalive) != null ? _b : false;
|
|
232
240
|
this._headers = (_c = options.headers) != null ? _c : {};
|
|
@@ -278,7 +286,7 @@ var __signalBundle = (() => {
|
|
|
278
286
|
}
|
|
279
287
|
};
|
|
280
288
|
function createFetchTransport(options = {}) {
|
|
281
|
-
return
|
|
289
|
+
return new FetchTransport(options);
|
|
282
290
|
}
|
|
283
291
|
var DEFAULT_ENDPOINT = "https://api.example.com/track";
|
|
284
292
|
var DEFAULT_FLUSH_INTERVAL_MS = 1e3;
|
|
@@ -385,38 +393,28 @@ var __signalBundle = (() => {
|
|
|
385
393
|
}
|
|
386
394
|
return new SnapshotQueueStorage(storage, QUEUE_STORAGE_KEY);
|
|
387
395
|
}
|
|
388
|
-
function
|
|
389
|
-
const timers = resolveTimerApi(runtime == null ? void 0 : runtime.timers);
|
|
390
|
-
if (!timers) {
|
|
391
|
-
throw new Error("Signal client requires a timer implementation");
|
|
392
|
-
}
|
|
393
|
-
return {
|
|
394
|
-
timers
|
|
395
|
-
};
|
|
396
|
-
}
|
|
397
|
-
function normalizeConfig(apiKey, config, runtime) {
|
|
396
|
+
function normalizeConfig(apiKey, config) {
|
|
398
397
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
399
398
|
if (!apiKey) {
|
|
400
399
|
throw new Error("Signal client requires apiKey");
|
|
401
400
|
}
|
|
402
|
-
const persistQueue = (_a = config.persistQueue) != null ? _a :
|
|
401
|
+
const persistQueue = (_a = config.persistQueue) != null ? _a : false;
|
|
403
402
|
const initialIdentityOverrides = {
|
|
404
403
|
userId: resolveInitialUserId(config.userId),
|
|
405
404
|
deviceId: resolveInitialDeviceId(config.deviceId)
|
|
406
405
|
};
|
|
407
|
-
const transportFactory = (_b = config.transportFactory) != null ? _b : createFetchTransport();
|
|
408
406
|
return {
|
|
409
407
|
apiKey,
|
|
410
408
|
resolvedConfig: {
|
|
411
|
-
endpoint: (
|
|
409
|
+
endpoint: (_b = config.endpoint) != null ? _b : DEFAULT_ENDPOINT,
|
|
412
410
|
flushIntervalMs: toInteger(config.flushIntervalMs, DEFAULT_FLUSH_INTERVAL_MS),
|
|
413
411
|
maxBatchSize: toInteger(config.maxBatchSize, DEFAULT_MAX_BATCH_SIZE),
|
|
414
412
|
maxQueueSize: toInteger(config.maxQueueSize, DEFAULT_MAX_QUEUE_SIZE),
|
|
415
413
|
retry: {
|
|
416
|
-
baseMs: toInteger((
|
|
417
|
-
maxMs: toInteger((
|
|
418
|
-
maxAttempts: toInteger((
|
|
419
|
-
jitter: typeof ((
|
|
414
|
+
baseMs: toInteger((_c = config.retry) == null ? void 0 : _c.baseMs, DEFAULT_RETRY_BASE_MS),
|
|
415
|
+
maxMs: toInteger((_d = config.retry) == null ? void 0 : _d.maxMs, DEFAULT_RETRY_MAX_MS),
|
|
416
|
+
maxAttempts: toInteger((_e = config.retry) == null ? void 0 : _e.maxAttempts, DEFAULT_RETRY_ATTEMPTS),
|
|
417
|
+
jitter: typeof ((_f = config.retry) == null ? void 0 : _f.jitter) === "number" ? config.retry.jitter : DEFAULT_RETRY_JITTER
|
|
420
418
|
},
|
|
421
419
|
persistQueue,
|
|
422
420
|
locationFromIp: resolveLocationFromIp(config.locationFromIp),
|
|
@@ -426,10 +424,10 @@ var __signalBundle = (() => {
|
|
|
426
424
|
blockedProperties: resolveBlockedProperties(config.blockedProperties)
|
|
427
425
|
},
|
|
428
426
|
storage: {
|
|
429
|
-
identity: createIdentityStorage((
|
|
430
|
-
queue: persistQueue ? createQueueStorage((
|
|
427
|
+
identity: createIdentityStorage((_g = config.storage) == null ? void 0 : _g.identity),
|
|
428
|
+
queue: persistQueue ? createQueueStorage((_h = config.storage) == null ? void 0 : _h.queue) : NOOP_QUEUE_STORAGE
|
|
431
429
|
},
|
|
432
|
-
transport:
|
|
430
|
+
transport: (_i = config.transport) != null ? _i : createFetchTransport(),
|
|
433
431
|
plugins: (_j = config.plugins) != null ? _j : [],
|
|
434
432
|
initialIdentityOverrides
|
|
435
433
|
};
|
|
@@ -939,10 +937,12 @@ var __signalBundle = (() => {
|
|
|
939
937
|
}
|
|
940
938
|
this._state = "initializing";
|
|
941
939
|
try {
|
|
942
|
-
const
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
940
|
+
const timers = resolveTimerApi();
|
|
941
|
+
if (!timers) {
|
|
942
|
+
throw new Error("Signal client requires a timer implementation");
|
|
943
|
+
}
|
|
944
|
+
const normalized = normalizeConfig(apiKey, this.resolveInitConfig(options));
|
|
945
|
+
this._timers = timers;
|
|
946
946
|
this._applyNormalizedConfig(normalized);
|
|
947
947
|
this._ready = this._initialize(normalized.initialIdentityOverrides);
|
|
948
948
|
await this._ready;
|
|
@@ -1377,7 +1377,6 @@ var __signalBundle = (() => {
|
|
|
1377
1377
|
const dropped = this._enqueue(entry);
|
|
1378
1378
|
queuedResults.push({
|
|
1379
1379
|
entry,
|
|
1380
|
-
queuedEvents: this._queue.length,
|
|
1381
1380
|
request
|
|
1382
1381
|
});
|
|
1383
1382
|
if (dropped) {
|
|
@@ -1389,11 +1388,10 @@ var __signalBundle = (() => {
|
|
|
1389
1388
|
if (droppedIds.length > 0) {
|
|
1390
1389
|
await this._removeQueueEntries(droppedIds);
|
|
1391
1390
|
}
|
|
1392
|
-
for (const { entry,
|
|
1391
|
+
for (const { entry, request } of queuedResults) {
|
|
1393
1392
|
await this._hooks.emitEventQueued({
|
|
1394
1393
|
event: entry.event,
|
|
1395
|
-
options: entry.options
|
|
1396
|
-
queuedEvents
|
|
1394
|
+
options: entry.options
|
|
1397
1395
|
});
|
|
1398
1396
|
if (!request.waitForImmediateFlush) {
|
|
1399
1397
|
request.completion.resolve(void 0);
|
|
@@ -1616,7 +1614,7 @@ var __signalBundle = (() => {
|
|
|
1616
1614
|
enqueueAutomaticFlush();
|
|
1617
1615
|
},
|
|
1618
1616
|
delayMs,
|
|
1619
|
-
this.
|
|
1617
|
+
this._timers
|
|
1620
1618
|
);
|
|
1621
1619
|
this._flushTask = task;
|
|
1622
1620
|
}
|
|
@@ -2037,7 +2035,7 @@ var __signalBundle = (() => {
|
|
|
2037
2035
|
const queueStorage = options.persistQueue === false ? void 0 : (_c = options.storage) == null ? void 0 : _c.queue;
|
|
2038
2036
|
return {
|
|
2039
2037
|
...options,
|
|
2040
|
-
|
|
2038
|
+
transport: (_d = options.transport) != null ? _d : createFetchTransport({ keepalive: true }),
|
|
2041
2039
|
storage: {
|
|
2042
2040
|
identity: identityStorage,
|
|
2043
2041
|
...queueStorage !== void 0 ? { queue: queueStorage } : {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atsignal/browser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Browser SDK for Signal.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"dist"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@atsignal/js-core": "0.
|
|
30
|
+
"@atsignal/js-core": "0.2.0"
|
|
31
31
|
},
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public",
|