@adcp/sdk 15.3.0 → 15.5.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.
Files changed (130) hide show
  1. package/dist/lib/advanced.d.mts +2 -2
  2. package/dist/lib/advanced.d.ts +2 -2
  3. package/dist/lib/advanced.js +8 -2
  4. package/dist/lib/advanced.mjs +8 -2
  5. package/dist/lib/core/AgentClient.d.mts +4 -0
  6. package/dist/lib/core/AgentClient.d.ts +4 -0
  7. package/dist/lib/core/AgentClient.js +8 -0
  8. package/dist/lib/core/AgentClient.mjs +8 -0
  9. package/dist/lib/core/SingleAgentClient.d.mts +154 -0
  10. package/dist/lib/core/SingleAgentClient.d.ts +154 -0
  11. package/dist/lib/core/SingleAgentClient.js +661 -23
  12. package/dist/lib/core/SingleAgentClient.mjs +666 -23
  13. package/dist/lib/core/agent-discovery-cache.d.mts +103 -0
  14. package/dist/lib/core/agent-discovery-cache.d.ts +103 -0
  15. package/dist/lib/core/agent-discovery-cache.js +121 -0
  16. package/dist/lib/core/agent-discovery-cache.mjs +92 -0
  17. package/dist/lib/index.d.mts +5 -3
  18. package/dist/lib/index.d.ts +5 -3
  19. package/dist/lib/index.js +7 -0
  20. package/dist/lib/index.mjs +6 -0
  21. package/dist/lib/protocols/index.d.mts +2 -2
  22. package/dist/lib/protocols/index.d.ts +2 -2
  23. package/dist/lib/protocols/index.js +1 -1
  24. package/dist/lib/protocols/index.mjs +1 -1
  25. package/dist/lib/protocols/mcp-call-context.d.mts +109 -0
  26. package/dist/lib/protocols/mcp-call-context.d.ts +109 -0
  27. package/dist/lib/protocols/mcp-call-context.js +221 -0
  28. package/dist/lib/protocols/mcp-call-context.mjs +186 -0
  29. package/dist/lib/protocols/mcp-modern.d.mts +9 -1
  30. package/dist/lib/protocols/mcp-modern.d.ts +9 -1
  31. package/dist/lib/protocols/mcp-modern.js +180 -104
  32. package/dist/lib/protocols/mcp-modern.mjs +193 -104
  33. package/dist/lib/protocols/mcp-scope.d.mts +15 -0
  34. package/dist/lib/protocols/mcp-scope.d.ts +15 -0
  35. package/dist/lib/protocols/mcp.d.mts +4 -2
  36. package/dist/lib/protocols/mcp.d.ts +4 -2
  37. package/dist/lib/protocols/mcp.js +178 -154
  38. package/dist/lib/protocols/mcp.mjs +189 -153
  39. package/dist/lib/protocols/transportDiagnostics.d.mts +33 -1
  40. package/dist/lib/protocols/transportDiagnostics.d.ts +33 -1
  41. package/dist/lib/protocols/transportDiagnostics.js +128 -12
  42. package/dist/lib/protocols/transportDiagnostics.mjs +128 -12
  43. package/dist/lib/reporting/gcs/index.d.mts +2 -0
  44. package/dist/lib/reporting/gcs/index.d.ts +2 -0
  45. package/dist/lib/reporting/gcs/index.js +3 -0
  46. package/dist/lib/reporting/gcs/index.mjs +2 -0
  47. package/dist/lib/reporting/gcs/row-provider.d.mts +32 -0
  48. package/dist/lib/reporting/gcs/row-provider.d.ts +32 -0
  49. package/dist/lib/reporting/gcs/row-provider.js +205 -0
  50. package/dist/lib/reporting/gcs/row-provider.mjs +188 -0
  51. package/dist/lib/reporting/ledger/change-feed.d.mts +41 -0
  52. package/dist/lib/reporting/ledger/change-feed.d.ts +41 -0
  53. package/dist/lib/reporting/ledger/change-feed.js +101 -0
  54. package/dist/lib/reporting/ledger/change-feed.mjs +74 -0
  55. package/dist/lib/reporting/ledger/handler.d.mts +6 -0
  56. package/dist/lib/reporting/ledger/handler.d.ts +6 -0
  57. package/dist/lib/reporting/ledger/handler.js +51 -8
  58. package/dist/lib/reporting/ledger/handler.mjs +50 -8
  59. package/dist/lib/reporting/ledger/index.d.mts +5 -0
  60. package/dist/lib/reporting/ledger/index.d.ts +5 -0
  61. package/dist/lib/reporting/ledger/index.js +11 -1
  62. package/dist/lib/reporting/ledger/index.mjs +5 -0
  63. package/dist/lib/reporting/ledger/lifecycle.js +3 -2
  64. package/dist/lib/reporting/ledger/lifecycle.mjs +3 -2
  65. package/dist/lib/reporting/ledger/managed-postgres.d.mts +2 -0
  66. package/dist/lib/reporting/ledger/managed-postgres.d.ts +2 -0
  67. package/dist/lib/reporting/ledger/managed-postgres.js +26 -6
  68. package/dist/lib/reporting/ledger/managed-postgres.mjs +26 -6
  69. package/dist/lib/reporting/ledger/managed.d.mts +9 -0
  70. package/dist/lib/reporting/ledger/managed.d.ts +9 -0
  71. package/dist/lib/reporting/ledger/managed.js +18 -0
  72. package/dist/lib/reporting/ledger/managed.mjs +18 -0
  73. package/dist/lib/reporting/ledger/postgres.d.mts +179 -1
  74. package/dist/lib/reporting/ledger/postgres.d.ts +179 -1
  75. package/dist/lib/reporting/ledger/postgres.js +882 -19
  76. package/dist/lib/reporting/ledger/postgres.mjs +890 -19
  77. package/dist/lib/reporting/ledger/producer.js +13 -3
  78. package/dist/lib/reporting/ledger/producer.mjs +13 -3
  79. package/dist/lib/reporting/ledger/revision-metadata.d.mts +17 -0
  80. package/dist/lib/reporting/ledger/revision-metadata.d.ts +17 -0
  81. package/dist/lib/reporting/ledger/revision-metadata.js +71 -0
  82. package/dist/lib/reporting/ledger/revision-metadata.mjs +44 -0
  83. package/dist/lib/reporting/ledger/row-encoding.d.mts +128 -0
  84. package/dist/lib/reporting/ledger/row-encoding.d.ts +128 -0
  85. package/dist/lib/reporting/ledger/row-encoding.js +355 -0
  86. package/dist/lib/reporting/ledger/row-encoding.mjs +315 -0
  87. package/dist/lib/reporting/ledger/row-storage-errors.d.mts +7 -0
  88. package/dist/lib/reporting/ledger/row-storage-errors.d.ts +7 -0
  89. package/dist/lib/reporting/ledger/row-storage-errors.js +41 -0
  90. package/dist/lib/reporting/ledger/row-storage-errors.mjs +16 -0
  91. package/dist/lib/reporting/ledger/row-storage-migration.d.mts +41 -0
  92. package/dist/lib/reporting/ledger/row-storage-migration.d.ts +41 -0
  93. package/dist/lib/reporting/ledger/row-storage-migration.js +234 -0
  94. package/dist/lib/reporting/ledger/row-storage-migration.mjs +208 -0
  95. package/dist/lib/reporting/ledger/row-storage-object.d.mts +112 -0
  96. package/dist/lib/reporting/ledger/row-storage-object.d.ts +112 -0
  97. package/dist/lib/reporting/ledger/row-storage-object.js +281 -0
  98. package/dist/lib/reporting/ledger/row-storage-object.mjs +239 -0
  99. package/dist/lib/reporting/ledger/row-storage-provider-io.d.mts +51 -0
  100. package/dist/lib/reporting/ledger/row-storage-provider-io.d.ts +51 -0
  101. package/dist/lib/reporting/ledger/row-storage-provider-io.js +152 -0
  102. package/dist/lib/reporting/ledger/row-storage-provider-io.mjs +119 -0
  103. package/dist/lib/reporting/ledger/row-storage.d.mts +224 -0
  104. package/dist/lib/reporting/ledger/row-storage.d.ts +224 -0
  105. package/dist/lib/reporting/ledger/row-storage.js +692 -0
  106. package/dist/lib/reporting/ledger/row-storage.mjs +680 -0
  107. package/dist/lib/reporting/ledger/types.d.mts +45 -0
  108. package/dist/lib/reporting/ledger/types.d.ts +45 -0
  109. package/dist/lib/reporting/service/index.d.mts +41 -1
  110. package/dist/lib/reporting/service/index.d.ts +41 -1
  111. package/dist/lib/reporting/service/index.js +68 -1
  112. package/dist/lib/reporting/service/index.mjs +70 -1
  113. package/dist/lib/schemas-data/v2.5/_provenance.json +1 -1
  114. package/dist/lib/signing/agent-resolver/fetch-helpers.js +1 -1
  115. package/dist/lib/signing/agent-resolver/fetch-helpers.mjs +1 -1
  116. package/dist/lib/testing/storyboard/validations.d.mts +1 -1
  117. package/dist/lib/testing/storyboard/validations.d.ts +1 -1
  118. package/dist/lib/version.d.mts +3 -3
  119. package/dist/lib/version.d.ts +3 -3
  120. package/dist/lib/version.js +3 -3
  121. package/dist/lib/version.mjs +3 -3
  122. package/docs/README.md +1 -1
  123. package/docs/TYPE-SUMMARY.md +35 -2
  124. package/docs/guides/DISCOVERY-CACHE-AND-SESSION-REUSE.md +142 -0
  125. package/docs/guides/EXISTING-PLATFORM.md +43 -12
  126. package/docs/guides/REPORTING-LEDGER.md +209 -0
  127. package/docs/llms.txt +4 -2
  128. package/docs/migration-14.x-rc-worksheet.md +4 -4
  129. package/docs/recipes/verifying-inbound-webhooks.md +8 -0
  130. package/package.json +1 -1
@@ -15,6 +15,12 @@ export interface ReportingStatusConsumerScopeOptionsV1<TContext = unknown> {
15
15
  }
16
16
  export declare function createReportingStatusHandler(store: ReportingLedgerStore): (request: Parameters<ReportingStatusHandlerV1>[0], context: Pick<Parameters<ReportingStatusHandlerV1>[1], 'account' | 'signal'>) => ReturnType<ReportingStatusHandlerV1>;
17
17
  export declare function createReportingStatusHandler<TContext = unknown>(store: ReportingLedgerStore, options?: ReportingStatusConsumerScopeOptionsV1<TContext>): ReportingStatusHandlerV1;
18
+ /**
19
+ * Largest revision whose rows the `get_reporting_status` `revision` view
20
+ * returns inline. Larger revisions omit `reporting_rows` there; callers page
21
+ * them through the exact `get_media_buy_delivery` read.
22
+ */
23
+ export declare const REPORTING_STATUS_REVISION_VIEW_MAX_ROWS = 10000;
18
24
  /** Exact revision reader for createAdcpServer's getMediaBuyDelivery slot. */
19
25
  export declare function createReportingDeliveryHandler(store: ReportingLedgerStore): ReportingDeliveryHandlerV1;
20
26
  export interface ProjectManagedDeliveryInputV1 {
@@ -18,6 +18,7 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var handler_exports = {};
20
20
  __export(handler_exports, {
21
+ REPORTING_STATUS_REVISION_VIEW_MAX_ROWS: () => REPORTING_STATUS_REVISION_VIEW_MAX_ROWS,
21
22
  ReportingReadCapacityError: () => ReportingReadCapacityError,
22
23
  acquireAccountReadSlot: () => acquireAccountReadSlot,
23
24
  aggregateReportingCoverageV1: () => aggregateReportingCoverageV1,
@@ -34,6 +35,8 @@ var import_source = require('../source/index.js');
34
35
  var import_coverage = require('./coverage.js');
35
36
  var import_health = require('./health.js');
36
37
  var import_instant = require('./instant.js');
38
+ var import_revision_metadata = require('./revision-metadata.js');
39
+ var import_row_storage = require('./row-storage.js');
37
40
  var import_schedule = require('./schedule.js');
38
41
  var import_types = require('./types.js');
39
42
  function createReportingStatusHandler(store, options) {
@@ -248,11 +251,26 @@ function createReportingStatusHandler(store, options) {
248
251
  const id = query.reporting_revision_id;
249
252
  const inSnapshot = id ? page.snapshot.revisions.some((value) => value.reporting_revision_id === id) : false;
250
253
  let revision = null;
254
+ let revisionRows;
251
255
  if (id && inSnapshot) {
252
256
  try {
253
- revision = await store.getRevision(id, accountId);
257
+ revision = await (0, import_revision_metadata.getRevisionMetadataFromStore)(store, id, accountId);
258
+ const rowCount = revision?.binding.rowCount ?? 0;
259
+ if (revision && rowCount <= REPORTING_STATUS_REVISION_VIEW_MAX_ROWS) {
260
+ const page2 = rowCount === 0 ? { rows: [], total: 0 } : await (0, import_revision_metadata.readRevisionRowsFromStore)(store, {
261
+ reporting_revision_id: id,
262
+ account_id: accountId,
263
+ offset: 0,
264
+ limit: rowCount,
265
+ ...context.signal ? { signal: context.signal } : {}
266
+ });
267
+ if (!page2 || page2.total !== rowCount) revision = null;
268
+ else revisionRows = page2.rows;
269
+ }
254
270
  } catch (error) {
255
- if (error instanceof ReportingReadCapacityError) return lookupUnavailable(view);
271
+ if (error instanceof ReportingReadCapacityError || (0, import_row_storage.isReportingRowStoreError)(error)) {
272
+ return lookupUnavailable(view);
273
+ }
256
274
  throw error;
257
275
  }
258
276
  }
@@ -278,7 +296,7 @@ function createReportingStatusHandler(store, options) {
278
296
  revision_content_sha256: revision.wireRevision.revision_content_sha256,
279
297
  row_count: revision.binding.rowCount
280
298
  },
281
- reporting_rows: revision.rows,
299
+ ...revisionRows ? { reporting_rows: revisionRows } : {},
282
300
  adjustments: revisionAdjustments.map((value) => value.wireAdjustment),
283
301
  ...consumerId ? { consumer_statuses: (page.consumerStatuses ?? []).map(wireConsumerStatus) } : {},
284
302
  materializations: (page.materializations ?? []).filter(
@@ -391,6 +409,7 @@ function createReportingStatusHandler(store, options) {
391
409
  }
392
410
  };
393
411
  }
412
+ const REPORTING_STATUS_REVISION_VIEW_MAX_ROWS = 1e4;
394
413
  function createReportingDeliveryHandler(store) {
395
414
  const activeReadsByAccount = /* @__PURE__ */ new Map();
396
415
  return async (request, context) => {
@@ -411,7 +430,7 @@ function createReportingDeliveryHandler(store) {
411
430
  if (typeof raw.reporting_revision_id !== "string" || !raw.reporting_revision_id) {
412
431
  throw new Error("Ledger delivery reads require reporting_revision_id");
413
432
  }
414
- const revision = await store.getRevision(raw.reporting_revision_id, accountId);
433
+ const revision = await (0, import_revision_metadata.getRevisionMetadataFromStore)(store, raw.reporting_revision_id, accountId);
415
434
  if (!revision) throw new Error("Reporting revision is unavailable");
416
435
  const obligation = await store.getObligation(revision.reporting_obligation_id);
417
436
  if (!obligation || obligation.account.account_id !== accountId) {
@@ -419,11 +438,12 @@ function createReportingDeliveryHandler(store) {
419
438
  }
420
439
  const pagination = isRecord(raw.pagination) ? raw.pagination : {};
421
440
  const maxResults = typeof pagination.max_results === "number" && Number.isFinite(pagination.max_results) ? Math.max(1, Math.min(500, Math.trunc(pagination.max_results))) : 100;
441
+ const totalCount = revision.binding.rowCount;
422
442
  let offset = 0;
423
443
  if (typeof pagination.cursor === "string") {
424
444
  try {
425
445
  const cursor = JSON.parse(Buffer.from(pagination.cursor, "base64url").toString("utf8"));
426
- if (cursor.revisionId !== revision.reporting_revision_id || typeof cursor.offset !== "number" || !Number.isSafeInteger(cursor.offset) || cursor.offset < 0 || cursor.offset >= revision.rows.length) {
446
+ if (cursor.revisionId !== revision.reporting_revision_id || typeof cursor.offset !== "number" || !Number.isSafeInteger(cursor.offset) || cursor.offset < 0 || cursor.offset >= totalCount) {
427
447
  throw new Error("invalid");
428
448
  }
429
449
  offset = cursor.offset;
@@ -431,9 +451,31 @@ function createReportingDeliveryHandler(store) {
431
451
  throw new Error("Reporting delivery cursor is invalid");
432
452
  }
433
453
  }
434
- const reportingRows = revision.rows.slice(offset, offset + maxResults);
454
+ let reportingRows = [];
455
+ if (totalCount > 0) {
456
+ let page;
457
+ try {
458
+ page = await (0, import_revision_metadata.readRevisionRowsFromStore)(store, {
459
+ reporting_revision_id: revision.reporting_revision_id,
460
+ account_id: accountId,
461
+ offset,
462
+ limit: maxResults,
463
+ ...context.signal ? { signal: context.signal } : {}
464
+ });
465
+ } catch (error) {
466
+ if ((0, import_row_storage.isReportingRowStoreError)(error)) {
467
+ if (error.code === "ROWS_EXPIRED") throw new Error("Reporting revision is unavailable");
468
+ throw new import_async_outcome.AdcpError("SERVICE_UNAVAILABLE", {
469
+ message: "Reporting revision rows are temporarily unavailable"
470
+ });
471
+ }
472
+ throw error;
473
+ }
474
+ if (!page || page.total !== totalCount) throw new Error("Reporting revision is unavailable");
475
+ reportingRows = page.rows;
476
+ }
435
477
  const nextOffset = offset + reportingRows.length;
436
- const hasMore = nextOffset < revision.rows.length;
478
+ const hasMore = nextOffset < totalCount;
437
479
  return {
438
480
  reporting_period: { start: obligation.period.start, end: obligation.period.end },
439
481
  media_buy_deliveries: [],
@@ -453,7 +495,7 @@ function createReportingDeliveryHandler(store) {
453
495
  errors: [],
454
496
  pagination: {
455
497
  has_more: hasMore,
456
- total_count: revision.rows.length,
498
+ total_count: totalCount,
457
499
  ...hasMore ? {
458
500
  cursor: Buffer.from(
459
501
  JSON.stringify({ revisionId: revision.reporting_revision_id, offset: nextOffset }),
@@ -966,6 +1008,7 @@ function wireSchedule(obligation) {
966
1008
  }
967
1009
  // Annotate the CommonJS export names for ESM import in node:
968
1010
  0 && (module.exports = {
1011
+ REPORTING_STATUS_REVISION_VIEW_MAX_ROWS,
969
1012
  ReportingReadCapacityError,
970
1013
  acquireAccountReadSlot,
971
1014
  aggregateReportingCoverageV1,
@@ -18,6 +18,8 @@ import {
18
18
  projectReportingObligationHealthV1
19
19
  } from "./health.mjs";
20
20
  import { compareReportingInstants } from "./instant.mjs";
21
+ import { getRevisionMetadataFromStore, readRevisionRowsFromStore } from "./revision-metadata.mjs";
22
+ import { isReportingRowStoreError } from "./row-storage.mjs";
21
23
  import { reportingPeriodSchedule } from "./schedule.mjs";
22
24
  import { ReportingLedgerSnapshotUnavailableError } from "./types.mjs";
23
25
  function createReportingStatusHandler(store, options) {
@@ -232,11 +234,26 @@ function createReportingStatusHandler(store, options) {
232
234
  const id = query.reporting_revision_id;
233
235
  const inSnapshot = id ? page.snapshot.revisions.some((value) => value.reporting_revision_id === id) : false;
234
236
  let revision = null;
237
+ let revisionRows;
235
238
  if (id && inSnapshot) {
236
239
  try {
237
- revision = await store.getRevision(id, accountId);
240
+ revision = await getRevisionMetadataFromStore(store, id, accountId);
241
+ const rowCount = revision?.binding.rowCount ?? 0;
242
+ if (revision && rowCount <= REPORTING_STATUS_REVISION_VIEW_MAX_ROWS) {
243
+ const page2 = rowCount === 0 ? { rows: [], total: 0 } : await readRevisionRowsFromStore(store, {
244
+ reporting_revision_id: id,
245
+ account_id: accountId,
246
+ offset: 0,
247
+ limit: rowCount,
248
+ ...context.signal ? { signal: context.signal } : {}
249
+ });
250
+ if (!page2 || page2.total !== rowCount) revision = null;
251
+ else revisionRows = page2.rows;
252
+ }
238
253
  } catch (error) {
239
- if (error instanceof ReportingReadCapacityError) return lookupUnavailable(view);
254
+ if (error instanceof ReportingReadCapacityError || isReportingRowStoreError(error)) {
255
+ return lookupUnavailable(view);
256
+ }
240
257
  throw error;
241
258
  }
242
259
  }
@@ -262,7 +279,7 @@ function createReportingStatusHandler(store, options) {
262
279
  revision_content_sha256: revision.wireRevision.revision_content_sha256,
263
280
  row_count: revision.binding.rowCount
264
281
  },
265
- reporting_rows: revision.rows,
282
+ ...revisionRows ? { reporting_rows: revisionRows } : {},
266
283
  adjustments: revisionAdjustments.map((value) => value.wireAdjustment),
267
284
  ...consumerId ? { consumer_statuses: (page.consumerStatuses ?? []).map(wireConsumerStatus) } : {},
268
285
  materializations: (page.materializations ?? []).filter(
@@ -375,6 +392,7 @@ function createReportingStatusHandler(store, options) {
375
392
  }
376
393
  };
377
394
  }
395
+ const REPORTING_STATUS_REVISION_VIEW_MAX_ROWS = 1e4;
378
396
  function createReportingDeliveryHandler(store) {
379
397
  const activeReadsByAccount = /* @__PURE__ */ new Map();
380
398
  return async (request, context) => {
@@ -395,7 +413,7 @@ function createReportingDeliveryHandler(store) {
395
413
  if (typeof raw.reporting_revision_id !== "string" || !raw.reporting_revision_id) {
396
414
  throw new Error("Ledger delivery reads require reporting_revision_id");
397
415
  }
398
- const revision = await store.getRevision(raw.reporting_revision_id, accountId);
416
+ const revision = await getRevisionMetadataFromStore(store, raw.reporting_revision_id, accountId);
399
417
  if (!revision) throw new Error("Reporting revision is unavailable");
400
418
  const obligation = await store.getObligation(revision.reporting_obligation_id);
401
419
  if (!obligation || obligation.account.account_id !== accountId) {
@@ -403,11 +421,12 @@ function createReportingDeliveryHandler(store) {
403
421
  }
404
422
  const pagination = isRecord(raw.pagination) ? raw.pagination : {};
405
423
  const maxResults = typeof pagination.max_results === "number" && Number.isFinite(pagination.max_results) ? Math.max(1, Math.min(500, Math.trunc(pagination.max_results))) : 100;
424
+ const totalCount = revision.binding.rowCount;
406
425
  let offset = 0;
407
426
  if (typeof pagination.cursor === "string") {
408
427
  try {
409
428
  const cursor = JSON.parse(Buffer.from(pagination.cursor, "base64url").toString("utf8"));
410
- if (cursor.revisionId !== revision.reporting_revision_id || typeof cursor.offset !== "number" || !Number.isSafeInteger(cursor.offset) || cursor.offset < 0 || cursor.offset >= revision.rows.length) {
429
+ if (cursor.revisionId !== revision.reporting_revision_id || typeof cursor.offset !== "number" || !Number.isSafeInteger(cursor.offset) || cursor.offset < 0 || cursor.offset >= totalCount) {
411
430
  throw new Error("invalid");
412
431
  }
413
432
  offset = cursor.offset;
@@ -415,9 +434,31 @@ function createReportingDeliveryHandler(store) {
415
434
  throw new Error("Reporting delivery cursor is invalid");
416
435
  }
417
436
  }
418
- const reportingRows = revision.rows.slice(offset, offset + maxResults);
437
+ let reportingRows = [];
438
+ if (totalCount > 0) {
439
+ let page;
440
+ try {
441
+ page = await readRevisionRowsFromStore(store, {
442
+ reporting_revision_id: revision.reporting_revision_id,
443
+ account_id: accountId,
444
+ offset,
445
+ limit: maxResults,
446
+ ...context.signal ? { signal: context.signal } : {}
447
+ });
448
+ } catch (error) {
449
+ if (isReportingRowStoreError(error)) {
450
+ if (error.code === "ROWS_EXPIRED") throw new Error("Reporting revision is unavailable");
451
+ throw new AdcpError("SERVICE_UNAVAILABLE", {
452
+ message: "Reporting revision rows are temporarily unavailable"
453
+ });
454
+ }
455
+ throw error;
456
+ }
457
+ if (!page || page.total !== totalCount) throw new Error("Reporting revision is unavailable");
458
+ reportingRows = page.rows;
459
+ }
419
460
  const nextOffset = offset + reportingRows.length;
420
- const hasMore = nextOffset < revision.rows.length;
461
+ const hasMore = nextOffset < totalCount;
421
462
  return {
422
463
  reporting_period: { start: obligation.period.start, end: obligation.period.end },
423
464
  media_buy_deliveries: [],
@@ -437,7 +478,7 @@ function createReportingDeliveryHandler(store) {
437
478
  errors: [],
438
479
  pagination: {
439
480
  has_more: hasMore,
440
- total_count: revision.rows.length,
481
+ total_count: totalCount,
441
482
  ...hasMore ? {
442
483
  cursor: Buffer.from(
443
484
  JSON.stringify({ revisionId: revision.reporting_revision_id, offset: nextOffset }),
@@ -949,6 +990,7 @@ function wireSchedule(obligation) {
949
990
  };
950
991
  }
951
992
  export {
993
+ REPORTING_STATUS_REVISION_VIEW_MAX_ROWS,
952
994
  ReportingReadCapacityError,
953
995
  acquireAccountReadSlot,
954
996
  aggregateReportingCoverageV1,
@@ -11,3 +11,8 @@ export * from './managed.mjs';
11
11
  export * from './managed-postgres.mjs';
12
12
  export * from './object-writes.mjs';
13
13
  export * from './notification-activity.mjs';
14
+ export * from './row-encoding.mjs';
15
+ export * from './row-storage-migration.mjs';
16
+ export * from './row-storage.mjs';
17
+ export * from './row-storage-object.mjs';
18
+ export * from './change-feed.mjs';
@@ -11,3 +11,8 @@ export * from './managed';
11
11
  export * from './managed-postgres';
12
12
  export * from './object-writes';
13
13
  export * from './notification-activity';
14
+ export * from './row-encoding';
15
+ export * from './row-storage-migration';
16
+ export * from './row-storage';
17
+ export * from './row-storage-object';
18
+ export * from './change-feed';
@@ -28,6 +28,11 @@ __reExport(ledger_exports, require('./managed.js'), module.exports);
28
28
  __reExport(ledger_exports, require('./managed-postgres.js'), module.exports);
29
29
  __reExport(ledger_exports, require('./object-writes.js'), module.exports);
30
30
  __reExport(ledger_exports, require('./notification-activity.js'), module.exports);
31
+ __reExport(ledger_exports, require('./row-encoding.js'), module.exports);
32
+ __reExport(ledger_exports, require('./row-storage-migration.js'), module.exports);
33
+ __reExport(ledger_exports, require('./row-storage.js'), module.exports);
34
+ __reExport(ledger_exports, require('./row-storage-object.js'), module.exports);
35
+ __reExport(ledger_exports, require('./change-feed.js'), module.exports);
31
36
  // Annotate the CommonJS export names for ESM import in node:
32
37
  0 && (module.exports = {
33
38
  ...require('./types.js'),
@@ -42,5 +47,10 @@ __reExport(ledger_exports, require('./notification-activity.js'), module.exports
42
47
  ...require('./managed.js'),
43
48
  ...require('./managed-postgres.js'),
44
49
  ...require('./object-writes.js'),
45
- ...require('./notification-activity.js')
50
+ ...require('./notification-activity.js'),
51
+ ...require('./row-encoding.js'),
52
+ ...require('./row-storage-migration.js'),
53
+ ...require('./row-storage.js'),
54
+ ...require('./row-storage-object.js'),
55
+ ...require('./change-feed.js')
46
56
  });
@@ -11,3 +11,8 @@ export * from "./managed.mjs";
11
11
  export * from "./managed-postgres.mjs";
12
12
  export * from "./object-writes.mjs";
13
13
  export * from "./notification-activity.mjs";
14
+ export * from "./row-encoding.mjs";
15
+ export * from "./row-storage-migration.mjs";
16
+ export * from "./row-storage.mjs";
17
+ export * from "./row-storage-object.mjs";
18
+ export * from "./change-feed.mjs";
@@ -28,6 +28,7 @@ var import_source = require('../source/index.js');
28
28
  var import_handler = require('./handler.js');
29
29
  var import_instant = require('./instant.js');
30
30
  var import_health = require('./health.js');
31
+ var import_revision_metadata = require('./revision-metadata.js');
31
32
  async function resolveLedgerAsOf(input, attempt) {
32
33
  const resolved = await input.store.readLedgerInstant?.() ?? (input.now ?? (() => /* @__PURE__ */ new Date()))().toISOString();
33
34
  if (input.ledgerAsOf === void 0) return resolved;
@@ -78,7 +79,7 @@ async function reconcileReportingStatusLifecycleV1(input, attempt = 0) {
78
79
  const transactionalNotifications = input.store.transactionalNotificationActivity === true;
79
80
  assertNotificationModesCompatible(input.store, input.subscribers);
80
81
  let ledgerAsOf = await resolveLedgerAsOf(input, attempt);
81
- const revisions = await input.store.listRevisions(obligation.reporting_obligation_id);
82
+ const revisions = await (0, import_revision_metadata.listRevisionMetadataFromStore)(input.store, obligation.reporting_obligation_id);
82
83
  let projected = revisions;
83
84
  const projectCore = (at) => (0, import_health.projectReportingObligationHealthV1)(
84
85
  obligation,
@@ -207,7 +208,7 @@ async function composeManagedLifecycleProjection(input, obligation, revisions, c
207
208
  ledgerAsOf: input.ledgerAsOf
208
209
  });
209
210
  if (!managed) return { projection: coreProjection };
210
- const stored = await input.store.listAdjustments(obligation.reporting_obligation_id);
211
+ const stored = await (0, import_revision_metadata.listAdjustmentMetadataFromStore)(input.store, obligation.reporting_obligation_id);
211
212
  const visibleAdjustmentIds = managed.visibleAdjustmentIds;
212
213
  const adjustments = visibleAdjustmentIds ? stored.filter((value) => visibleAdjustmentIds.includes(value.reporting_adjustment_id)) : stored.filter((value) => (0, import_instant.compareReportingInstants)(value.createdAt, input.ledgerAsOf) <= 0);
213
214
  const rosterAuthoritative = managed.obligatedConsumerRosterComplete === true && managed.receiptEvidenceComplete !== false;
@@ -3,6 +3,7 @@ import { canonicalJsonV1 } from "../source/index.mjs";
3
3
  import { moreSevereReportingHealthV1, projectManagedDelivery } from "./handler.mjs";
4
4
  import { compareReportingInstants } from "./instant.mjs";
5
5
  import { projectReportingObligationHealthV1 } from "./health.mjs";
6
+ import { listAdjustmentMetadataFromStore, listRevisionMetadataFromStore } from "./revision-metadata.mjs";
6
7
  async function resolveLedgerAsOf(input, attempt) {
7
8
  const resolved = await input.store.readLedgerInstant?.() ?? (input.now ?? (() => /* @__PURE__ */ new Date()))().toISOString();
8
9
  if (input.ledgerAsOf === void 0) return resolved;
@@ -53,7 +54,7 @@ async function reconcileReportingStatusLifecycleV1(input, attempt = 0) {
53
54
  const transactionalNotifications = input.store.transactionalNotificationActivity === true;
54
55
  assertNotificationModesCompatible(input.store, input.subscribers);
55
56
  let ledgerAsOf = await resolveLedgerAsOf(input, attempt);
56
- const revisions = await input.store.listRevisions(obligation.reporting_obligation_id);
57
+ const revisions = await listRevisionMetadataFromStore(input.store, obligation.reporting_obligation_id);
57
58
  let projected = revisions;
58
59
  const projectCore = (at) => projectReportingObligationHealthV1(
59
60
  obligation,
@@ -182,7 +183,7 @@ async function composeManagedLifecycleProjection(input, obligation, revisions, c
182
183
  ledgerAsOf: input.ledgerAsOf
183
184
  });
184
185
  if (!managed) return { projection: coreProjection };
185
- const stored = await input.store.listAdjustments(obligation.reporting_obligation_id);
186
+ const stored = await listAdjustmentMetadataFromStore(input.store, obligation.reporting_obligation_id);
186
187
  const visibleAdjustmentIds = managed.visibleAdjustmentIds;
187
188
  const adjustments = visibleAdjustmentIds ? stored.filter((value) => visibleAdjustmentIds.includes(value.reporting_adjustment_id)) : stored.filter((value) => compareReportingInstants(value.createdAt, input.ledgerAsOf) <= 0);
188
189
  const rosterAuthoritative = managed.obligatedConsumerRosterComplete === true && managed.receiptEvidenceComplete !== false;
@@ -94,6 +94,8 @@ export declare class PostgresReportingManagedDeliveryStore implements ReportingM
94
94
  private validateRecoveryWindow;
95
95
  private readPolicyRow;
96
96
  private readPolicy;
97
+ /** Read-only access to PostgreSQL row chunks for claim hydration. */
98
+ private readonly rowStorage;
97
99
  constructor(pool: ReportingPgPool, options?: PostgresReportingManagedDeliveryStoreOptions);
98
100
  /** SQL fragment scoping a count to the active retention window, if one is set. */
99
101
  private activeScope;
@@ -94,6 +94,8 @@ export declare class PostgresReportingManagedDeliveryStore implements ReportingM
94
94
  private validateRecoveryWindow;
95
95
  private readPolicyRow;
96
96
  private readPolicy;
97
+ /** Read-only access to PostgreSQL row chunks for claim hydration. */
98
+ private readonly rowStorage;
97
99
  constructor(pool: ReportingPgPool, options?: PostgresReportingManagedDeliveryStoreOptions);
98
100
  /** SQL fragment scoping a count to the active retention window, if one is set. */
99
101
  private activeScope;
@@ -26,6 +26,7 @@ var import_node_crypto = require("node:crypto");
26
26
  var import_jcs = require('../../utils/jcs.js');
27
27
  var import_evidence = require('../evidence.js');
28
28
  var import_types = require('./types.js');
29
+ var import_row_storage = require('./row-storage.js');
29
30
  var import_object_writes = require('./object-writes.js');
30
31
  var import_managed = require('./managed.js');
31
32
  const REPORTING_MANAGED_DELIVERY_MIGRATION = `
@@ -252,6 +253,7 @@ const MAX_RECEIPT_BATCH_RESULT_BYTES = 64 * 1024;
252
253
  class PostgresReportingManagedDeliveryStore {
253
254
  constructor(pool, options = {}) {
254
255
  this.pool = pool;
256
+ this.rowStorage = new import_row_storage.ReportingRowStorageV1(pool);
255
257
  if (options.statusRetentionDays !== void 0) positiveInteger(options.statusRetentionDays, "statusRetentionDays");
256
258
  if (options.evidenceRetentionDays !== void 0) {
257
259
  positiveInteger(options.evidenceRetentionDays, "evidenceRetentionDays");
@@ -466,6 +468,8 @@ class PostgresReportingManagedDeliveryStore {
466
468
  authorizationRevocationSeconds: policy.advertised_authorization_revocation_seconds
467
469
  };
468
470
  }
471
+ /** Read-only access to PostgreSQL row chunks for claim hydration. */
472
+ rowStorage;
469
473
  /** SQL fragment scoping a count to the active retention window, if one is set. */
470
474
  activeScope(column) {
471
475
  return this.evidenceRetentionDays === void 0 ? "" : ` AND ${column} >= clock_timestamp() - (${this.evidenceRetentionDays}::bigint * INTERVAL '1 day')`;
@@ -987,7 +991,7 @@ class PostgresReportingManagedDeliveryStore {
987
991
  ])
988
992
  );
989
993
  const candidates = await client.query(
990
- `SELECT binding.data AS binding, obligation.data AS obligation, revision.data AS revision,
994
+ `SELECT binding.data AS binding, obligation.data AS obligation, revision.revision_id AS revision_id,
991
995
  GREATEST(COALESCE(MAX(existing.attempt), 0), COALESCE(MAX(tomb.highest_attempt), 0))::integer + 1
992
996
  AS attempt
993
997
  FROM adcp_reporting_managed_bindings binding
@@ -1007,7 +1011,7 @@ class PostgresReportingManagedDeliveryStore {
1007
1011
  ON tomb.configuration_id = binding.configuration_id AND tomb.revision_id = revision.revision_id
1008
1012
  WHERE ($1::text IS NULL OR binding.account_id = $1)
1009
1013
  GROUP BY binding.configuration_id, binding.data, obligation.obligation_id, obligation.data,
1010
- revision.revision_id, revision.data
1014
+ revision.revision_id
1011
1015
  HAVING NOT COALESCE(BOOL_OR(existing.status IN ('pending','available','delivered')), false)
1012
1016
  AND NOT COALESCE(BOOL_OR(tomb.reached_success), false)
1013
1017
  AND GREATEST(COALESCE(MAX(existing.attempt), 0), COALESCE(MAX(tomb.highest_attempt), 0))
@@ -1022,11 +1026,11 @@ class PostgresReportingManagedDeliveryStore {
1022
1026
  const remaining = remainingByAccount.get(binding.account_id) ?? 0;
1023
1027
  if (remaining <= 0) continue;
1024
1028
  const obligation = candidate.obligation;
1025
- const revision = candidate.revision;
1029
+ const revisionId = candidate.revision_id;
1026
1030
  const created_at = (/* @__PURE__ */ new Date()).toISOString();
1027
1031
  const materialization = {
1028
1032
  reporting_materialization_id: `rmat_${(0, import_node_crypto.randomUUID)()}`,
1029
- reporting_revision_id: revision.reporting_revision_id,
1033
+ reporting_revision_id: revisionId,
1030
1034
  reporting_obligation_id: obligation.reporting_obligation_id,
1031
1035
  delivery_config_id: binding.delivery_config_id,
1032
1036
  delivery_config_version: binding.delivery_config_version,
@@ -1049,7 +1053,7 @@ class PostgresReportingManagedDeliveryStore {
1049
1053
  binding.account_id,
1050
1054
  binding.configurationId,
1051
1055
  obligation.reporting_obligation_id,
1052
- revision.reporting_revision_id,
1056
+ revisionId,
1053
1057
  binding.destination_ref,
1054
1058
  binding.authorization_generation,
1055
1059
  candidate.attempt,
@@ -1171,7 +1175,7 @@ class PostgresReportingManagedDeliveryStore {
1171
1175
  }
1172
1176
  async claimMaterialization(input) {
1173
1177
  positiveInteger(input.lease_milliseconds, "lease_milliseconds");
1174
- return this.transaction(async (client) => {
1178
+ const lease = await this.transaction(async (client) => {
1175
1179
  const selected = await client.query(
1176
1180
  `WITH candidate AS (
1177
1181
  SELECT materialization.materialization_id
@@ -1227,6 +1231,22 @@ class PostgresReportingManagedDeliveryStore {
1227
1231
  expires_at: row.expires_at.toISOString()
1228
1232
  };
1229
1233
  });
1234
+ if (!lease || Array.isArray(lease.revision.rows)) return lease;
1235
+ try {
1236
+ const handle = await this.rowStorage.find(
1237
+ lease.revision.reporting_revision_id,
1238
+ lease.obligation.account.account_id
1239
+ );
1240
+ if (handle?.kind === "postgres") {
1241
+ lease.revision = {
1242
+ ...lease.revision,
1243
+ rows: await this.rowStorage.readAll(handle, lease.revision.wireRevision.control_totals)
1244
+ };
1245
+ }
1246
+ } catch (error) {
1247
+ if (!(0, import_row_storage.isReportingRowStoreError)(error)) throw error;
1248
+ }
1249
+ return lease;
1230
1250
  }
1231
1251
  /**
1232
1252
  * Fails materializations that have used every delivery attempt.
@@ -2,6 +2,7 @@ import { createHash, randomUUID } from "node:crypto";
2
2
  import { canonicalize } from "../../utils/jcs.mjs";
3
3
  import { isReportingAdjustmentReceiptEvidence, isReportingReceiptEvidence } from "../evidence.mjs";
4
4
  import { REPORTING_LEDGER_AUTHORITY } from "./types.mjs";
5
+ import { ReportingRowStorageV1, isReportingRowStoreError } from "./row-storage.mjs";
5
6
  import {
6
7
  assertReportingObjectWriteScope,
7
8
  reportingObjectWritePlanFingerprint,
@@ -237,6 +238,7 @@ const MAX_RECEIPT_BATCH_RESULT_BYTES = 64 * 1024;
237
238
  class PostgresReportingManagedDeliveryStore {
238
239
  constructor(pool, options = {}) {
239
240
  this.pool = pool;
241
+ this.rowStorage = new ReportingRowStorageV1(pool);
240
242
  if (options.statusRetentionDays !== void 0) positiveInteger(options.statusRetentionDays, "statusRetentionDays");
241
243
  if (options.evidenceRetentionDays !== void 0) {
242
244
  positiveInteger(options.evidenceRetentionDays, "evidenceRetentionDays");
@@ -451,6 +453,8 @@ class PostgresReportingManagedDeliveryStore {
451
453
  authorizationRevocationSeconds: policy.advertised_authorization_revocation_seconds
452
454
  };
453
455
  }
456
+ /** Read-only access to PostgreSQL row chunks for claim hydration. */
457
+ rowStorage;
454
458
  /** SQL fragment scoping a count to the active retention window, if one is set. */
455
459
  activeScope(column) {
456
460
  return this.evidenceRetentionDays === void 0 ? "" : ` AND ${column} >= clock_timestamp() - (${this.evidenceRetentionDays}::bigint * INTERVAL '1 day')`;
@@ -972,7 +976,7 @@ class PostgresReportingManagedDeliveryStore {
972
976
  ])
973
977
  );
974
978
  const candidates = await client.query(
975
- `SELECT binding.data AS binding, obligation.data AS obligation, revision.data AS revision,
979
+ `SELECT binding.data AS binding, obligation.data AS obligation, revision.revision_id AS revision_id,
976
980
  GREATEST(COALESCE(MAX(existing.attempt), 0), COALESCE(MAX(tomb.highest_attempt), 0))::integer + 1
977
981
  AS attempt
978
982
  FROM adcp_reporting_managed_bindings binding
@@ -992,7 +996,7 @@ class PostgresReportingManagedDeliveryStore {
992
996
  ON tomb.configuration_id = binding.configuration_id AND tomb.revision_id = revision.revision_id
993
997
  WHERE ($1::text IS NULL OR binding.account_id = $1)
994
998
  GROUP BY binding.configuration_id, binding.data, obligation.obligation_id, obligation.data,
995
- revision.revision_id, revision.data
999
+ revision.revision_id
996
1000
  HAVING NOT COALESCE(BOOL_OR(existing.status IN ('pending','available','delivered')), false)
997
1001
  AND NOT COALESCE(BOOL_OR(tomb.reached_success), false)
998
1002
  AND GREATEST(COALESCE(MAX(existing.attempt), 0), COALESCE(MAX(tomb.highest_attempt), 0))
@@ -1007,11 +1011,11 @@ class PostgresReportingManagedDeliveryStore {
1007
1011
  const remaining = remainingByAccount.get(binding.account_id) ?? 0;
1008
1012
  if (remaining <= 0) continue;
1009
1013
  const obligation = candidate.obligation;
1010
- const revision = candidate.revision;
1014
+ const revisionId = candidate.revision_id;
1011
1015
  const created_at = (/* @__PURE__ */ new Date()).toISOString();
1012
1016
  const materialization = {
1013
1017
  reporting_materialization_id: `rmat_${randomUUID()}`,
1014
- reporting_revision_id: revision.reporting_revision_id,
1018
+ reporting_revision_id: revisionId,
1015
1019
  reporting_obligation_id: obligation.reporting_obligation_id,
1016
1020
  delivery_config_id: binding.delivery_config_id,
1017
1021
  delivery_config_version: binding.delivery_config_version,
@@ -1034,7 +1038,7 @@ class PostgresReportingManagedDeliveryStore {
1034
1038
  binding.account_id,
1035
1039
  binding.configurationId,
1036
1040
  obligation.reporting_obligation_id,
1037
- revision.reporting_revision_id,
1041
+ revisionId,
1038
1042
  binding.destination_ref,
1039
1043
  binding.authorization_generation,
1040
1044
  candidate.attempt,
@@ -1156,7 +1160,7 @@ class PostgresReportingManagedDeliveryStore {
1156
1160
  }
1157
1161
  async claimMaterialization(input) {
1158
1162
  positiveInteger(input.lease_milliseconds, "lease_milliseconds");
1159
- return this.transaction(async (client) => {
1163
+ const lease = await this.transaction(async (client) => {
1160
1164
  const selected = await client.query(
1161
1165
  `WITH candidate AS (
1162
1166
  SELECT materialization.materialization_id
@@ -1212,6 +1216,22 @@ class PostgresReportingManagedDeliveryStore {
1212
1216
  expires_at: row.expires_at.toISOString()
1213
1217
  };
1214
1218
  });
1219
+ if (!lease || Array.isArray(lease.revision.rows)) return lease;
1220
+ try {
1221
+ const handle = await this.rowStorage.find(
1222
+ lease.revision.reporting_revision_id,
1223
+ lease.obligation.account.account_id
1224
+ );
1225
+ if (handle?.kind === "postgres") {
1226
+ lease.revision = {
1227
+ ...lease.revision,
1228
+ rows: await this.rowStorage.readAll(handle, lease.revision.wireRevision.control_totals)
1229
+ };
1230
+ }
1231
+ } catch (error) {
1232
+ if (!isReportingRowStoreError(error)) throw error;
1233
+ }
1234
+ return lease;
1215
1235
  }
1216
1236
  /**
1217
1237
  * Fails materializations that have used every delivery attempt.
@@ -258,6 +258,15 @@ export interface ReportingManagedDeliveryWorkerOptionsV1 {
258
258
  */
259
259
  authorizationRevocationSeconds?: number;
260
260
  account_id?: string;
261
+ /**
262
+ * Loads verified rows for a claimed revision whose rows live in row storage
263
+ * rather than in the ledger document. `createReportingManagedDeliveryRuntime`
264
+ * supplies one backed by its Core store. PostgreSQL-kind chunks are
265
+ * hydrated by the managed store's claim itself; a direct caller whose rows
266
+ * live in an external binding must supply this, or the adapter receives a
267
+ * revision without rows.
268
+ */
269
+ hydrateRevision?: (revision: ReportingManagedDeliveryLeaseV1['revision'], account_id: string, signal: AbortSignal | undefined) => Promise<ReportingManagedDeliveryLeaseV1['revision']>;
261
270
  }
262
271
  export interface CreateReportingManagedDeliveryRuntimeOptionsV1<TContext extends {
263
272
  account?: unknown;
@@ -258,6 +258,15 @@ export interface ReportingManagedDeliveryWorkerOptionsV1 {
258
258
  */
259
259
  authorizationRevocationSeconds?: number;
260
260
  account_id?: string;
261
+ /**
262
+ * Loads verified rows for a claimed revision whose rows live in row storage
263
+ * rather than in the ledger document. `createReportingManagedDeliveryRuntime`
264
+ * supplies one backed by its Core store. PostgreSQL-kind chunks are
265
+ * hydrated by the managed store's claim itself; a direct caller whose rows
266
+ * live in an external binding must supply this, or the adapter receives a
267
+ * revision without rows.
268
+ */
269
+ hydrateRevision?: (revision: ReportingManagedDeliveryLeaseV1['revision'], account_id: string, signal: AbortSignal | undefined) => Promise<ReportingManagedDeliveryLeaseV1['revision']>;
261
270
  }
262
271
  export interface CreateReportingManagedDeliveryRuntimeOptionsV1<TContext extends {
263
272
  account?: unknown;