@indigoai-us/hq-cloud 6.14.16 → 6.14.17

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.
@@ -365,7 +365,7 @@ describe("API surface", () => {
365
365
 
366
366
  it("postTelemetryEvents sends action events without personUid", async () => {
367
367
  fetchSpy.mockResolvedValueOnce(
368
- jsonResponse(200, { ok: true, written: 1, skipped: [] }),
368
+ jsonResponse(200, { contractVersion: 1, ok: true, written: 1, skipped: [] }),
369
369
  );
370
370
  const batch: TelemetryEventsBatch = {
371
371
  events: [
@@ -397,6 +397,17 @@ describe("API surface", () => {
397
397
  expect(JSON.stringify(body)).not.toContain("personUid");
398
398
  });
399
399
 
400
+ it("postTelemetryEvents normalizes the compatible pre-v1 accepted response", async () => {
401
+ fetchSpy.mockResolvedValueOnce(jsonResponse(200, { accepted: 2, deduped: 1 }));
402
+ const batch: TelemetryEventsBatch = { events: [] };
403
+
404
+ await expect(client.postTelemetryEvents(batch)).resolves.toEqual({
405
+ ok: true,
406
+ written: 2,
407
+ skipped: [],
408
+ });
409
+ });
410
+
400
411
  it("updateRole sends correct payload", async () => {
401
412
  fetchSpy.mockResolvedValueOnce(
402
413
  jsonResponse(200, {
@@ -462,7 +462,14 @@ export interface TelemetryEventsBatch {
462
462
  events: RawTelemetryEventInput[];
463
463
  }
464
464
 
465
- /** Same wire shape as `UsageIngestResult`; aliased for call-site clarity. */
465
+ /**
466
+ * Normalized response shape for `POST /v1/telemetry/events`.
467
+ *
468
+ * hq-pro response contract v1 uses the established ingest fields (`ok`,
469
+ * `written`, `skipped`). The decoder also accepts the briefly deployed
470
+ * `{ accepted, deduped }` shape so clients remain compatible while the server
471
+ * rollout catches up.
472
+ */
466
473
  export type TelemetryEventsIngestResult = UsageIngestResult;
467
474
 
468
475
  // ---------------------------------------------------------------------------
@@ -649,6 +656,41 @@ const usageIngestResultSchema: VaultResponseSchema<UsageIngestResult> = z
649
656
  })
650
657
  .strip();
651
658
 
659
+ /**
660
+ * Accept the canonical v1 response and the previous raw-event aliases, then
661
+ * normalize at this boundary so telemetry remains best-effort during rollout.
662
+ */
663
+ const telemetryEventsIngestResultSchema: VaultResponseSchema<TelemetryEventsIngestResult> = z
664
+ .object({
665
+ contractVersion: z.literal(1).optional(),
666
+ ok: z.boolean().optional(),
667
+ written: z.number().nonnegative().optional(),
668
+ skipped: z
669
+ .array(
670
+ z
671
+ .object({
672
+ index: z.number(),
673
+ code: z.string(),
674
+ error: z.string(),
675
+ })
676
+ .strip(),
677
+ )
678
+ .optional(),
679
+ // Compatibility aliases emitted by hq-pro before response contract v1.
680
+ accepted: z.number().nonnegative().optional(),
681
+ deduped: z.number().nonnegative().optional(),
682
+ })
683
+ .refine(
684
+ (value) =>
685
+ value.ok !== undefined || value.written !== undefined || value.accepted !== undefined,
686
+ { message: "telemetry ingest response has no recognized result fields" },
687
+ )
688
+ .transform((value) => ({
689
+ ok: value.ok ?? true,
690
+ written: value.written ?? value.accepted ?? 0,
691
+ skipped: value.skipped ?? [],
692
+ }));
693
+
652
694
  const createInviteResponseSchema: VaultResponseSchema<CreateInviteResult> = z
653
695
  .object({
654
696
  membership: membershipSchema,
@@ -1349,7 +1391,7 @@ export class VaultClient {
1349
1391
  batch: TelemetryEventsBatch,
1350
1392
  options: { timeoutMs?: number } = {},
1351
1393
  ): Promise<TelemetryEventsIngestResult> {
1352
- return this.post("/v1/telemetry/events", batch, usageIngestResultSchema, {
1394
+ return this.post("/v1/telemetry/events", batch, telemetryEventsIngestResultSchema, {
1353
1395
  timeoutMs: options.timeoutMs ?? 1500,
1354
1396
  maxRetries: 0,
1355
1397
  });