@atsignal/browser 0.1.0 → 0.1.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/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1 -1
- package/dist/signal.global.js +53 -45
- package/package.json +2 -2
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
|
+
transportFactory: (_d = options.transportFactory) != 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.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ClientPlugin, KeyValueStorage, SignalClient, ClientConfig,
|
|
1
|
+
import { ClientPlugin, KeyValueStorage, SignalClient, ClientConfig, QueueStorageInput } from '@atsignal/js-core';
|
|
2
2
|
export { ClientPlugin } from '@atsignal/js-core';
|
|
3
3
|
|
|
4
4
|
type BrowserPluginFactory = (...args: unknown[]) => ClientPlugin;
|
|
@@ -28,7 +28,6 @@ declare class BrowserLocalStorage implements KeyValueStorage {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
interface SignalBrowserOptions extends Omit<ClientConfig, "storage"> {
|
|
31
|
-
transport?: Transport;
|
|
32
31
|
storage?: {
|
|
33
32
|
identity?: KeyValueStorage;
|
|
34
33
|
queue?: QueueStorageInput;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ClientPlugin, KeyValueStorage, SignalClient, ClientConfig,
|
|
1
|
+
import { ClientPlugin, KeyValueStorage, SignalClient, ClientConfig, QueueStorageInput } from '@atsignal/js-core';
|
|
2
2
|
export { ClientPlugin } from '@atsignal/js-core';
|
|
3
3
|
|
|
4
4
|
type BrowserPluginFactory = (...args: unknown[]) => ClientPlugin;
|
|
@@ -28,7 +28,6 @@ declare class BrowserLocalStorage implements KeyValueStorage {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
interface SignalBrowserOptions extends Omit<ClientConfig, "storage"> {
|
|
31
|
-
transport?: Transport;
|
|
32
31
|
storage?: {
|
|
33
32
|
identity?: KeyValueStorage;
|
|
34
33
|
queue?: QueueStorageInput;
|
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
|
+
transportFactory: (_d = options.transportFactory) != 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,22 +157,16 @@ var __signalBundle = (() => {
|
|
|
157
157
|
return normalizePersistedQueueEntries(stored);
|
|
158
158
|
}
|
|
159
159
|
};
|
|
160
|
-
function resolveTimerApi() {
|
|
161
|
-
const
|
|
162
|
-
const
|
|
160
|
+
function resolveTimerApi(timerApi) {
|
|
161
|
+
const timers = timerApi != null ? timerApi : globalThis;
|
|
162
|
+
const maybeSetTimeout = timers == null ? void 0 : timers.setTimeout;
|
|
163
|
+
const maybeClearTimeout = timers == null ? void 0 : timers.clearTimeout;
|
|
163
164
|
if (typeof maybeSetTimeout !== "function" || typeof maybeClearTimeout !== "function") {
|
|
164
165
|
return null;
|
|
165
166
|
}
|
|
166
|
-
return
|
|
167
|
-
setTimeout: maybeSetTimeout,
|
|
168
|
-
clearTimeout: maybeClearTimeout
|
|
169
|
-
};
|
|
167
|
+
return timers;
|
|
170
168
|
}
|
|
171
|
-
function scheduleTask(callback, delayMs) {
|
|
172
|
-
const timers = resolveTimerApi();
|
|
173
|
-
if (!timers) {
|
|
174
|
-
return null;
|
|
175
|
-
}
|
|
169
|
+
function scheduleTask(callback, delayMs, timers) {
|
|
176
170
|
const handle = timers.setTimeout(callback, delayMs);
|
|
177
171
|
return {
|
|
178
172
|
cancel: () => {
|
|
@@ -180,14 +174,10 @@ var __signalBundle = (() => {
|
|
|
180
174
|
}
|
|
181
175
|
};
|
|
182
176
|
}
|
|
183
|
-
function createTimeoutController(timeoutMs, createTimeoutValue) {
|
|
177
|
+
function createTimeoutController(timeoutMs, createTimeoutValue, timers) {
|
|
184
178
|
if (typeof timeoutMs !== "number" || timeoutMs <= 0) {
|
|
185
179
|
return null;
|
|
186
180
|
}
|
|
187
|
-
const timers = resolveTimerApi();
|
|
188
|
-
if (!timers) {
|
|
189
|
-
return null;
|
|
190
|
-
}
|
|
191
181
|
let handle;
|
|
192
182
|
const timeout = new Promise((resolve) => {
|
|
193
183
|
handle = timers.setTimeout(() => resolve(createTimeoutValue()), timeoutMs);
|
|
@@ -231,7 +221,7 @@ var __signalBundle = (() => {
|
|
|
231
221
|
return parts.join("&");
|
|
232
222
|
}
|
|
233
223
|
var FetchTransport = class {
|
|
234
|
-
constructor(options = {}) {
|
|
224
|
+
constructor(timers, options = {}) {
|
|
235
225
|
var _a, _b, _c;
|
|
236
226
|
const fetchImpl = (_a = options.fetch) != null ? _a : resolveGlobalFetch();
|
|
237
227
|
if (!fetchImpl) {
|
|
@@ -240,14 +230,19 @@ var __signalBundle = (() => {
|
|
|
240
230
|
this._fetch = fetchImpl;
|
|
241
231
|
this._keepalive = (_b = options.keepalive) != null ? _b : false;
|
|
242
232
|
this._headers = (_c = options.headers) != null ? _c : {};
|
|
233
|
+
this._timers = timers;
|
|
243
234
|
}
|
|
244
235
|
async send(request) {
|
|
245
|
-
const timer = createTimeoutController(
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
236
|
+
const timer = createTimeoutController(
|
|
237
|
+
request.timeoutMs,
|
|
238
|
+
() => ({
|
|
239
|
+
ok: false,
|
|
240
|
+
retryable: true,
|
|
241
|
+
status: 0,
|
|
242
|
+
error: new Error("Request timed out")
|
|
243
|
+
}),
|
|
244
|
+
this._timers
|
|
245
|
+
);
|
|
251
246
|
const requestPromise = this._fetch(request.endpoint, {
|
|
252
247
|
method: "POST",
|
|
253
248
|
headers: {
|
|
@@ -283,11 +278,11 @@ var __signalBundle = (() => {
|
|
|
283
278
|
}
|
|
284
279
|
};
|
|
285
280
|
function createFetchTransport(options = {}) {
|
|
286
|
-
return new FetchTransport(options);
|
|
281
|
+
return (runtime) => new FetchTransport(runtime.timers, options);
|
|
287
282
|
}
|
|
288
283
|
var DEFAULT_ENDPOINT = "https://api.example.com/track";
|
|
289
|
-
var DEFAULT_FLUSH_INTERVAL_MS =
|
|
290
|
-
var DEFAULT_MAX_BATCH_SIZE =
|
|
284
|
+
var DEFAULT_FLUSH_INTERVAL_MS = 1e3;
|
|
285
|
+
var DEFAULT_MAX_BATCH_SIZE = 30;
|
|
291
286
|
var DEFAULT_MAX_QUEUE_SIZE = 1e3;
|
|
292
287
|
var DEFAULT_PART_ID = "";
|
|
293
288
|
var DEFAULT_RETRY_BASE_MS = 500;
|
|
@@ -390,7 +385,16 @@ var __signalBundle = (() => {
|
|
|
390
385
|
}
|
|
391
386
|
return new SnapshotQueueStorage(storage, QUEUE_STORAGE_KEY);
|
|
392
387
|
}
|
|
393
|
-
function
|
|
388
|
+
function resolveRuntime(runtime) {
|
|
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) {
|
|
394
398
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
395
399
|
if (!apiKey) {
|
|
396
400
|
throw new Error("Signal client requires apiKey");
|
|
@@ -400,18 +404,19 @@ var __signalBundle = (() => {
|
|
|
400
404
|
userId: resolveInitialUserId(config.userId),
|
|
401
405
|
deviceId: resolveInitialDeviceId(config.deviceId)
|
|
402
406
|
};
|
|
407
|
+
const transportFactory = (_b = config.transportFactory) != null ? _b : createFetchTransport();
|
|
403
408
|
return {
|
|
404
409
|
apiKey,
|
|
405
410
|
resolvedConfig: {
|
|
406
|
-
endpoint: (
|
|
411
|
+
endpoint: (_c = config.endpoint) != null ? _c : DEFAULT_ENDPOINT,
|
|
407
412
|
flushIntervalMs: toInteger(config.flushIntervalMs, DEFAULT_FLUSH_INTERVAL_MS),
|
|
408
413
|
maxBatchSize: toInteger(config.maxBatchSize, DEFAULT_MAX_BATCH_SIZE),
|
|
409
414
|
maxQueueSize: toInteger(config.maxQueueSize, DEFAULT_MAX_QUEUE_SIZE),
|
|
410
415
|
retry: {
|
|
411
|
-
baseMs: toInteger((
|
|
412
|
-
maxMs: toInteger((
|
|
413
|
-
maxAttempts: toInteger((
|
|
414
|
-
jitter: typeof ((
|
|
416
|
+
baseMs: toInteger((_d = config.retry) == null ? void 0 : _d.baseMs, DEFAULT_RETRY_BASE_MS),
|
|
417
|
+
maxMs: toInteger((_e = config.retry) == null ? void 0 : _e.maxMs, DEFAULT_RETRY_MAX_MS),
|
|
418
|
+
maxAttempts: toInteger((_f = config.retry) == null ? void 0 : _f.maxAttempts, DEFAULT_RETRY_ATTEMPTS),
|
|
419
|
+
jitter: typeof ((_g = config.retry) == null ? void 0 : _g.jitter) === "number" ? config.retry.jitter : DEFAULT_RETRY_JITTER
|
|
415
420
|
},
|
|
416
421
|
persistQueue,
|
|
417
422
|
locationFromIp: resolveLocationFromIp(config.locationFromIp),
|
|
@@ -421,10 +426,10 @@ var __signalBundle = (() => {
|
|
|
421
426
|
blockedProperties: resolveBlockedProperties(config.blockedProperties)
|
|
422
427
|
},
|
|
423
428
|
storage: {
|
|
424
|
-
identity: createIdentityStorage((
|
|
425
|
-
queue: persistQueue ? createQueueStorage((
|
|
429
|
+
identity: createIdentityStorage((_h = config.storage) == null ? void 0 : _h.identity),
|
|
430
|
+
queue: persistQueue ? createQueueStorage((_i = config.storage) == null ? void 0 : _i.queue) : NOOP_QUEUE_STORAGE
|
|
426
431
|
},
|
|
427
|
-
transport: (
|
|
432
|
+
transport: transportFactory(runtime),
|
|
428
433
|
plugins: (_j = config.plugins) != null ? _j : [],
|
|
429
434
|
initialIdentityOverrides
|
|
430
435
|
};
|
|
@@ -934,7 +939,10 @@ var __signalBundle = (() => {
|
|
|
934
939
|
}
|
|
935
940
|
this._state = "initializing";
|
|
936
941
|
try {
|
|
937
|
-
const
|
|
942
|
+
const initConfig = this.resolveInitConfig(options);
|
|
943
|
+
const runtime = resolveRuntime(initConfig.runtime);
|
|
944
|
+
const normalized = normalizeConfig(apiKey, initConfig, runtime);
|
|
945
|
+
this._runtime = runtime;
|
|
938
946
|
this._applyNormalizedConfig(normalized);
|
|
939
947
|
this._ready = this._initialize(normalized.initialIdentityOverrides);
|
|
940
948
|
await this._ready;
|
|
@@ -1603,13 +1611,13 @@ var __signalBundle = (() => {
|
|
|
1603
1611
|
enqueueAutomaticFlush();
|
|
1604
1612
|
return;
|
|
1605
1613
|
}
|
|
1606
|
-
const task = scheduleTask(
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1614
|
+
const task = scheduleTask(
|
|
1615
|
+
() => {
|
|
1616
|
+
enqueueAutomaticFlush();
|
|
1617
|
+
},
|
|
1618
|
+
delayMs,
|
|
1619
|
+
this._runtime.timers
|
|
1620
|
+
);
|
|
1613
1621
|
this._flushTask = task;
|
|
1614
1622
|
}
|
|
1615
1623
|
async _performFlush(reason) {
|
|
@@ -2029,7 +2037,7 @@ var __signalBundle = (() => {
|
|
|
2029
2037
|
const queueStorage = options.persistQueue === false ? void 0 : (_c = options.storage) == null ? void 0 : _c.queue;
|
|
2030
2038
|
return {
|
|
2031
2039
|
...options,
|
|
2032
|
-
|
|
2040
|
+
transportFactory: (_d = options.transportFactory) != null ? _d : createFetchTransport({ keepalive: true }),
|
|
2033
2041
|
storage: {
|
|
2034
2042
|
identity: identityStorage,
|
|
2035
2043
|
...queueStorage !== void 0 ? { queue: queueStorage } : {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atsignal/browser",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
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.1.
|
|
30
|
+
"@atsignal/js-core": "0.1.2"
|
|
31
31
|
},
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public",
|