@chaja/sdk-core 0.1.0 → 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/dist/index.d.mts CHANGED
@@ -221,6 +221,14 @@ interface CaptureOptions {
221
221
  * Person properties to set only when the person does not have them yet.
222
222
  */
223
223
  setOnce?: Attributes;
224
+ /**
225
+ * When it happened, in epoch milliseconds, for events recorded earlier and sent later (a client that was offline). Default now.
226
+ */
227
+ timestamp?: number;
228
+ /**
229
+ * The session it belongs to, instead of the platform's current one.
230
+ */
231
+ sessionId?: string;
224
232
  }
225
233
  interface Platform {
226
234
  sdk: SdkInfo;
@@ -265,6 +273,10 @@ interface CaptureContext {
265
273
  mechanism?: Mechanism;
266
274
  request?: RequestInfo;
267
275
  trace?: TraceContext;
276
+ /**
277
+ * When it happened, in epoch milliseconds, for errors recorded earlier and sent later. Default now.
278
+ */
279
+ timestamp?: number;
268
280
  }
269
281
  interface BreadcrumbInput {
270
282
  category: string;
@@ -363,7 +375,7 @@ export declare function parseStack(stack: string | undefined): Frame[];
363
375
  export declare function exceptionsFrom(error: unknown, mechanism: Mechanism): Exception[];
364
376
  //#endregion
365
377
  //#region src/index.d.ts
366
- export declare const SDK_VERSION = "0.1.0";
378
+ export declare const SDK_VERSION = "0.2.0";
367
379
  /**
368
380
  * Parse a `Retry-After` header given in seconds or as an HTTP date.
369
381
  *
package/dist/index.mjs CHANGED
@@ -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.0";
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.0",
4
4
  "description": "Shared client for the Chajá JavaScript SDKs: capture, scrubbing, sampling, batching and retries.",
5
5
  "keywords": [
6
6
  "chaja",