@chaja/sdk-core 0.1.0 → 0.2.1

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.d.mts CHANGED
@@ -125,7 +125,8 @@ interface QueueOptions {
125
125
  schedule: (callback: () => void, delayMs: number) => unknown;
126
126
  cancel: (handle: unknown) => void;
127
127
  /**
128
- * Called with envelopes that exhausted their retries on network failures (Node persists them to disk).
128
+ * Called with envelopes that exhausted their retries on network failures or server back-pressure (429, 5xx), so a long
129
+ * outage or a restarting server does not lose them (Node persists them to disk). Permanent rejections (4xx) are not passed.
129
130
  */
130
131
  onUndeliverable?: (body: string) => void;
131
132
  debug?: (event: string, fields: Record<string, unknown>) => void;
@@ -221,6 +222,14 @@ interface CaptureOptions {
221
222
  * Person properties to set only when the person does not have them yet.
222
223
  */
223
224
  setOnce?: Attributes;
225
+ /**
226
+ * When it happened, in epoch milliseconds, for events recorded earlier and sent later (a client that was offline). Default now.
227
+ */
228
+ timestamp?: number;
229
+ /**
230
+ * The session it belongs to, instead of the platform's current one.
231
+ */
232
+ sessionId?: string;
224
233
  }
225
234
  interface Platform {
226
235
  sdk: SdkInfo;
@@ -265,6 +274,10 @@ interface CaptureContext {
265
274
  mechanism?: Mechanism;
266
275
  request?: RequestInfo;
267
276
  trace?: TraceContext;
277
+ /**
278
+ * When it happened, in epoch milliseconds, for errors recorded earlier and sent later. Default now.
279
+ */
280
+ timestamp?: number;
268
281
  }
269
282
  interface BreadcrumbInput {
270
283
  category: string;
@@ -363,7 +376,7 @@ export declare function parseStack(stack: string | undefined): Frame[];
363
376
  export declare function exceptionsFrom(error: unknown, mechanism: Mechanism): Exception[];
364
377
  //#endregion
365
378
  //#region src/index.d.ts
366
- export declare const SDK_VERSION = "0.1.0";
379
+ export declare const SDK_VERSION = "0.2.1";
367
380
  /**
368
381
  * Parse a `Retry-After` header given in seconds or as an HTTP date.
369
382
  *
package/dist/index.mjs CHANGED
@@ -201,7 +201,7 @@ function createQueue(options) {
201
201
  items: batch.length
202
202
  });
203
203
  failures = 0;
204
- if (result.status === 0) options.onUndeliverable?.(body);
204
+ options.onUndeliverable?.(body);
205
205
  return;
206
206
  }
207
207
  pending.unshift(...batch);
@@ -375,7 +375,7 @@ function createClient(options, platform) {
375
375
  let item = {
376
376
  type: "error",
377
377
  eventId: platform.eventId(),
378
- timestamp: platform.now(),
378
+ timestamp: context.timestamp ?? platform.now(),
379
379
  platform: platform.platform,
380
380
  ...base,
381
381
  ...options.release ? { release: options.release } : {},
@@ -427,15 +427,16 @@ function createClient(options, platform) {
427
427
  * @param name - Event name.
428
428
  * @param properties - Event properties.
429
429
  * @param fields - Person, identify and person-property fields.
430
+ * @param when - When it happened and its session, if not now and the platform's current one.
430
431
  * @returns Event id, if queued.
431
432
  */
432
- function sendEvent(name, properties, fields) {
433
+ function sendEvent(name, properties, fields, when = {}) {
433
434
  if (options.enabled === false || options.analytics === false) return;
434
- const session = platform.session?.current();
435
+ const session = when.sessionId ?? platform.session?.current();
435
436
  const item = {
436
437
  type: "event",
437
438
  eventId: platform.eventId(),
438
- timestamp: platform.now(),
439
+ timestamp: when.timestamp ?? platform.now(),
439
440
  name: name.slice(0, 256),
440
441
  ...fields,
441
442
  ...session ? { sessionId: session } : {},
@@ -507,6 +508,9 @@ function createClient(options, platform) {
507
508
  distinctId: captureOptions.distinctId ?? identity.distinctId,
508
509
  ...captureOptions.set ? { set: captureOptions.set } : {},
509
510
  ...captureOptions.setOnce ? { setOnce: captureOptions.setOnce } : {}
511
+ }, {
512
+ ...captureOptions.timestamp === void 0 ? {} : { timestamp: captureOptions.timestamp },
513
+ ...captureOptions.sessionId === void 0 ? {} : { sessionId: captureOptions.sessionId }
510
514
  });
511
515
  },
512
516
  identify(distinctId, set, setOnce) {
@@ -559,7 +563,7 @@ function createClient(options, platform) {
559
563
  }
560
564
  //#endregion
561
565
  //#region src/index.ts
562
- const SDK_VERSION = "0.1.0";
566
+ const SDK_VERSION = "0.2.1";
563
567
  /**
564
568
  * Parse a `Retry-After` header given in seconds or as an HTTP date.
565
569
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chaja/sdk-core",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "Shared client for the Chajá JavaScript SDKs: capture, scrubbing, sampling, batching and retries.",
5
5
  "keywords": [
6
6
  "chaja",