@adcp/sdk 15.4.0 → 15.6.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 (164) hide show
  1. package/README.md +15 -0
  2. package/dist/lib/advanced.d.mts +2 -2
  3. package/dist/lib/advanced.d.ts +2 -2
  4. package/dist/lib/advanced.js +8 -2
  5. package/dist/lib/advanced.mjs +8 -2
  6. package/dist/lib/auth/oauth/index.d.mts +1 -0
  7. package/dist/lib/auth/oauth/index.d.ts +1 -0
  8. package/dist/lib/auth/oauth/index.js +5 -0
  9. package/dist/lib/auth/oauth/index.mjs +3 -0
  10. package/dist/lib/auth/oauth/pending-web-flow.d.mts +16 -0
  11. package/dist/lib/auth/oauth/pending-web-flow.d.ts +16 -0
  12. package/dist/lib/auth/oauth/pending-web-flow.js +66 -0
  13. package/dist/lib/auth/oauth/pending-web-flow.mjs +41 -0
  14. package/dist/lib/auth/oauth/web-flow.js +3 -3
  15. package/dist/lib/auth/oauth/web-flow.mjs +3 -3
  16. package/dist/lib/core/AgentClient.d.mts +4 -0
  17. package/dist/lib/core/AgentClient.d.ts +4 -0
  18. package/dist/lib/core/AgentClient.js +8 -0
  19. package/dist/lib/core/AgentClient.mjs +8 -0
  20. package/dist/lib/core/SingleAgentClient.d.mts +154 -0
  21. package/dist/lib/core/SingleAgentClient.d.ts +154 -0
  22. package/dist/lib/core/SingleAgentClient.js +661 -23
  23. package/dist/lib/core/SingleAgentClient.mjs +666 -23
  24. package/dist/lib/core/agent-discovery-cache.d.mts +103 -0
  25. package/dist/lib/core/agent-discovery-cache.d.ts +103 -0
  26. package/dist/lib/core/agent-discovery-cache.js +121 -0
  27. package/dist/lib/core/agent-discovery-cache.mjs +92 -0
  28. package/dist/lib/index.d.mts +5 -3
  29. package/dist/lib/index.d.ts +5 -3
  30. package/dist/lib/index.js +7 -0
  31. package/dist/lib/index.mjs +6 -0
  32. package/dist/lib/protocols/index.d.mts +2 -2
  33. package/dist/lib/protocols/index.d.ts +2 -2
  34. package/dist/lib/protocols/index.js +1 -1
  35. package/dist/lib/protocols/index.mjs +1 -1
  36. package/dist/lib/protocols/mcp-call-context.d.mts +109 -0
  37. package/dist/lib/protocols/mcp-call-context.d.ts +109 -0
  38. package/dist/lib/protocols/mcp-call-context.js +221 -0
  39. package/dist/lib/protocols/mcp-call-context.mjs +186 -0
  40. package/dist/lib/protocols/mcp-modern.d.mts +9 -1
  41. package/dist/lib/protocols/mcp-modern.d.ts +9 -1
  42. package/dist/lib/protocols/mcp-modern.js +180 -104
  43. package/dist/lib/protocols/mcp-modern.mjs +193 -104
  44. package/dist/lib/protocols/mcp-scope.d.mts +15 -0
  45. package/dist/lib/protocols/mcp-scope.d.ts +15 -0
  46. package/dist/lib/protocols/mcp.d.mts +4 -2
  47. package/dist/lib/protocols/mcp.d.ts +4 -2
  48. package/dist/lib/protocols/mcp.js +178 -154
  49. package/dist/lib/protocols/mcp.mjs +189 -153
  50. package/dist/lib/protocols/transportDiagnostics.d.mts +33 -1
  51. package/dist/lib/protocols/transportDiagnostics.d.ts +33 -1
  52. package/dist/lib/protocols/transportDiagnostics.js +128 -12
  53. package/dist/lib/protocols/transportDiagnostics.mjs +128 -12
  54. package/dist/lib/registry/types.generated.d.mts +63 -1
  55. package/dist/lib/registry/types.generated.d.ts +63 -1
  56. package/dist/lib/reporting/azure/index.d.mts +26 -0
  57. package/dist/lib/reporting/azure/index.d.ts +26 -0
  58. package/dist/lib/reporting/azure/index.js +247 -0
  59. package/dist/lib/reporting/azure/index.mjs +230 -0
  60. package/dist/lib/reporting/bigquery/index.d.mts +127 -0
  61. package/dist/lib/reporting/bigquery/index.d.ts +127 -0
  62. package/dist/lib/reporting/bigquery/index.js +379 -0
  63. package/dist/lib/reporting/bigquery/index.mjs +341 -0
  64. package/dist/lib/reporting/gcs/index.d.mts +2 -0
  65. package/dist/lib/reporting/gcs/index.d.ts +2 -0
  66. package/dist/lib/reporting/gcs/index.js +3 -0
  67. package/dist/lib/reporting/gcs/index.mjs +2 -0
  68. package/dist/lib/reporting/gcs/row-provider.d.mts +32 -0
  69. package/dist/lib/reporting/gcs/row-provider.d.ts +32 -0
  70. package/dist/lib/reporting/gcs/row-provider.js +205 -0
  71. package/dist/lib/reporting/gcs/row-provider.mjs +188 -0
  72. package/dist/lib/reporting/ledger/change-feed.d.mts +41 -0
  73. package/dist/lib/reporting/ledger/change-feed.d.ts +41 -0
  74. package/dist/lib/reporting/ledger/change-feed.js +101 -0
  75. package/dist/lib/reporting/ledger/change-feed.mjs +74 -0
  76. package/dist/lib/reporting/ledger/handler.js +22 -8
  77. package/dist/lib/reporting/ledger/handler.mjs +22 -8
  78. package/dist/lib/reporting/ledger/index.d.mts +4 -0
  79. package/dist/lib/reporting/ledger/index.d.ts +4 -0
  80. package/dist/lib/reporting/ledger/index.js +9 -1
  81. package/dist/lib/reporting/ledger/index.mjs +4 -0
  82. package/dist/lib/reporting/ledger/managed-postgres.d.mts +2 -0
  83. package/dist/lib/reporting/ledger/managed-postgres.d.ts +2 -0
  84. package/dist/lib/reporting/ledger/managed-postgres.js +21 -1
  85. package/dist/lib/reporting/ledger/managed-postgres.mjs +21 -1
  86. package/dist/lib/reporting/ledger/managed.d.mts +9 -0
  87. package/dist/lib/reporting/ledger/managed.d.ts +9 -0
  88. package/dist/lib/reporting/ledger/managed.js +18 -0
  89. package/dist/lib/reporting/ledger/managed.mjs +18 -0
  90. package/dist/lib/reporting/ledger/postgres.d.mts +185 -0
  91. package/dist/lib/reporting/ledger/postgres.d.ts +185 -0
  92. package/dist/lib/reporting/ledger/postgres.js +872 -26
  93. package/dist/lib/reporting/ledger/postgres.mjs +880 -26
  94. package/dist/lib/reporting/ledger/producer.js +10 -1
  95. package/dist/lib/reporting/ledger/producer.mjs +10 -1
  96. package/dist/lib/reporting/ledger/row-storage-errors.d.mts +7 -0
  97. package/dist/lib/reporting/ledger/row-storage-errors.d.ts +7 -0
  98. package/dist/lib/reporting/ledger/row-storage-errors.js +41 -0
  99. package/dist/lib/reporting/ledger/row-storage-errors.mjs +16 -0
  100. package/dist/lib/reporting/ledger/row-storage-migration.d.mts +41 -0
  101. package/dist/lib/reporting/ledger/row-storage-migration.d.ts +41 -0
  102. package/dist/lib/reporting/ledger/row-storage-migration.js +234 -0
  103. package/dist/lib/reporting/ledger/row-storage-migration.mjs +208 -0
  104. package/dist/lib/reporting/ledger/row-storage-object.d.mts +112 -0
  105. package/dist/lib/reporting/ledger/row-storage-object.d.ts +112 -0
  106. package/dist/lib/reporting/ledger/row-storage-object.js +304 -0
  107. package/dist/lib/reporting/ledger/row-storage-object.mjs +262 -0
  108. package/dist/lib/reporting/ledger/row-storage-provider-io.d.mts +44 -0
  109. package/dist/lib/reporting/ledger/row-storage-provider-io.d.ts +44 -0
  110. package/dist/lib/reporting/ledger/row-storage-provider-io.js +142 -0
  111. package/dist/lib/reporting/ledger/row-storage-provider-io.mjs +111 -0
  112. package/dist/lib/reporting/ledger/row-storage.d.mts +224 -0
  113. package/dist/lib/reporting/ledger/row-storage.d.ts +224 -0
  114. package/dist/lib/reporting/ledger/row-storage.js +692 -0
  115. package/dist/lib/reporting/ledger/row-storage.mjs +680 -0
  116. package/dist/lib/reporting/ledger/types.d.mts +8 -0
  117. package/dist/lib/reporting/ledger/types.d.ts +8 -0
  118. package/dist/lib/reporting/s3/index.d.mts +29 -0
  119. package/dist/lib/reporting/s3/index.d.ts +29 -0
  120. package/dist/lib/reporting/s3/index.js +324 -0
  121. package/dist/lib/reporting/s3/index.mjs +317 -0
  122. package/dist/lib/reporting/service/index.d.mts +43 -1
  123. package/dist/lib/reporting/service/index.d.ts +43 -1
  124. package/dist/lib/reporting/service/index.js +69 -1
  125. package/dist/lib/reporting/service/index.mjs +71 -1
  126. package/dist/lib/schemas/browser.d.mts +14 -0
  127. package/dist/lib/schemas/browser.d.ts +14 -0
  128. package/dist/lib/schemas/browser.js +48 -0
  129. package/dist/lib/schemas/browser.mjs +20 -0
  130. package/dist/lib/schemas/index.d.mts +2 -120
  131. package/dist/lib/schemas/index.d.ts +2 -120
  132. package/dist/lib/schemas/index.js +3 -11
  133. package/dist/lib/schemas/index.mjs +1 -9
  134. package/dist/lib/schemas-data/v2.5/_provenance.json +1 -1
  135. package/dist/lib/testing/index.d.mts +1 -0
  136. package/dist/lib/testing/index.d.ts +1 -0
  137. package/dist/lib/testing/index.js +3 -0
  138. package/dist/lib/testing/index.mjs +2 -0
  139. package/dist/lib/testing/pending-web-flow-store.d.mts +20 -0
  140. package/dist/lib/testing/pending-web-flow-store.d.ts +20 -0
  141. package/dist/lib/testing/pending-web-flow-store.js +132 -0
  142. package/dist/lib/testing/pending-web-flow-store.mjs +98 -0
  143. package/dist/lib/testing/storyboard/validations.d.mts +1 -1
  144. package/dist/lib/testing/storyboard/validations.d.ts +1 -1
  145. package/dist/lib/validation/get-products-request.d.mts +122 -0
  146. package/dist/lib/validation/get-products-request.d.ts +122 -0
  147. package/dist/lib/validation/get-products-request.js +39 -0
  148. package/dist/lib/validation/get-products-request.mjs +14 -0
  149. package/dist/lib/version.d.mts +3 -3
  150. package/dist/lib/version.d.ts +3 -3
  151. package/dist/lib/version.js +3 -3
  152. package/dist/lib/version.mjs +3 -3
  153. package/docs/README.md +1 -1
  154. package/docs/TYPE-SUMMARY.md +35 -2
  155. package/docs/ZOD-SCHEMAS.md +13 -1
  156. package/docs/guides/DISCOVERY-CACHE-AND-SESSION-REUSE.md +142 -0
  157. package/docs/guides/EXISTING-PLATFORM.md +43 -12
  158. package/docs/guides/OAUTH-ISSUER-BINDING.md +6 -0
  159. package/docs/guides/REPORTING-LEDGER.md +374 -0
  160. package/docs/guides/REPORTING-OPERATIONS.md +76 -1
  161. package/docs/guides/WEB-OAUTH.md +48 -1
  162. package/docs/llms.txt +4 -2
  163. package/docs/migration-14.x-rc-worksheet.md +6 -4
  164. package/package.json +64 -1
@@ -0,0 +1,188 @@
1
+ import { createHash } from "node:crypto";
2
+ import { ReportingRowStoreError } from "../ledger/row-storage-errors.mjs";
3
+ import {
4
+ assertReportingRowLocationKeys,
5
+ assertReportingRowReadBounds,
6
+ readReportingRowStream,
7
+ reportingRowClientMap,
8
+ reportingRowPrefixFilterOverlaps,
9
+ runReportingRowProviderOperation,
10
+ selectReportingRowClient
11
+ } from "../ledger/row-storage-provider-io.mjs";
12
+ const BUCKET = /^[a-z0-9][a-z0-9._-]{1,220}[a-z0-9]$/;
13
+ const GENERATION = /^[1-9][0-9]{0,15}$/;
14
+ const NONCURRENT_ONLY_CONDITIONS = ["numNewerVersions", "daysSinceNoncurrentTime", "noncurrentTimeBefore"];
15
+ function status(error) {
16
+ if (!error || typeof error !== "object" || !("code" in error)) return void 0;
17
+ const code = Number(error.code);
18
+ return Number.isInteger(code) ? code : void 0;
19
+ }
20
+ function generationOf(metadata) {
21
+ const generation = metadata?.generation === void 0 ? "" : String(metadata.generation);
22
+ if (!GENERATION.test(generation) || !Number.isSafeInteger(Number(generation))) {
23
+ throw new ReportingRowStoreError("PROVIDER_UNAVAILABLE", "object generation is missing");
24
+ }
25
+ return generation;
26
+ }
27
+ function pinnedGeneration(nativeVersion) {
28
+ return typeof nativeVersion === "string" && GENERATION.test(nativeVersion) && Number.isSafeInteger(Number(nativeVersion)) ? nativeVersion : null;
29
+ }
30
+ function assertGcsReportingRowBucketPolicyV1(metadata, prefix) {
31
+ if (!metadata || typeof metadata !== "object") {
32
+ throw new ReportingRowStoreError("UNSAFE_BINDING", "bucket policy is unavailable");
33
+ }
34
+ if (metadata.iamConfiguration?.uniformBucketLevelAccess?.enabled !== true) {
35
+ throw new ReportingRowStoreError("UNSAFE_BINDING", "bucket must enable uniform bucket-level access");
36
+ }
37
+ if (metadata.iamConfiguration?.publicAccessPrevention !== "enforced") {
38
+ throw new ReportingRowStoreError("UNSAFE_BINDING", "bucket must enforce public access prevention");
39
+ }
40
+ for (const rule of metadata.lifecycle?.rule ?? []) {
41
+ if (rule?.action?.type !== "Delete") continue;
42
+ const condition = rule.condition ?? {};
43
+ if (condition.isLive === false) continue;
44
+ if (NONCURRENT_ONLY_CONDITIONS.some((name) => condition[name] !== void 0 && condition[name] !== null)) continue;
45
+ const prefixes = condition.matchesPrefix ?? [];
46
+ if (prefixes.length === 0 || prefixes.some((filter) => reportingRowPrefixFilterOverlaps(filter, prefix))) {
47
+ throw new ReportingRowStoreError("UNSAFE_BINDING", "a bucket lifecycle rule can delete live row objects");
48
+ }
49
+ }
50
+ }
51
+ function createGcsReportingRowObjectProviderV1(options) {
52
+ if (!options || typeof options !== "object") {
53
+ throw new ReportingRowStoreError("INVALID_INPUT", "GCS row provider options are required");
54
+ }
55
+ const clients = reportingRowClientMap(options.clients);
56
+ const isStorage = (value) => !!value && typeof value === "object" && typeof value.bucket === "function";
57
+ if (options.storage !== void 0 && !isStorage(options.storage) || [...clients.values()].some((client) => !isStorage(client)) || options.storage === void 0 && clients.size === 0) {
58
+ throw new ReportingRowStoreError("INVALID_INPUT", "inject an official Storage client as storage or clients");
59
+ }
60
+ const validateLocation = (location) => {
61
+ assertReportingRowLocationKeys(location, ["bucket"]);
62
+ if (!BUCKET.test(location.bucket) || location.bucket.includes("..")) {
63
+ throw new ReportingRowStoreError("INVALID_INPUT", "GCS bucket name is invalid");
64
+ }
65
+ };
66
+ const bucketFor = (input) => {
67
+ validateLocation(input.location);
68
+ return selectReportingRowClient(options.storage, clients, input.credentialRef).bucket(input.location.bucket);
69
+ };
70
+ const assertKey = (key) => {
71
+ if (typeof key !== "string" || key.length === 0 || Buffer.byteLength(key) > 1024) {
72
+ throw new ReportingRowStoreError("INVALID_INPUT", "object key is invalid");
73
+ }
74
+ };
75
+ return {
76
+ name: "gcs",
77
+ rangedReads: true,
78
+ validateLocation,
79
+ probe(input, context) {
80
+ return runReportingRowProviderOperation(context.signal, async () => {
81
+ const bucket = bucketFor(input);
82
+ let metadata;
83
+ try {
84
+ [metadata] = await bucket.getMetadata();
85
+ } catch (error) {
86
+ const code = status(error);
87
+ if (code === 404) throw new ReportingRowStoreError("UNSAFE_BINDING", "bucket does not exist");
88
+ if (code === 401 || code === 403) {
89
+ throw new ReportingRowStoreError("UNSAFE_BINDING", "bucket policy cannot be read with this client");
90
+ }
91
+ throw error;
92
+ }
93
+ assertGcsReportingRowBucketPolicyV1(metadata, input.prefix);
94
+ });
95
+ },
96
+ putIfAbsent(input, context) {
97
+ return runReportingRowProviderOperation(context.signal, async () => {
98
+ const bucket = bucketFor(input);
99
+ assertKey(input.key);
100
+ const file = bucket.file(input.key);
101
+ try {
102
+ const bytes = Buffer.from(input.bytes);
103
+ await file.save(bytes, {
104
+ resumable: false,
105
+ gzip: false,
106
+ // GCS verifies the declared MD5 before creating the object, so a corrupted upload
107
+ // is refused server-side. Client-side validation is off because on mismatch the
108
+ // client deletes the key without a generation precondition.
109
+ validation: false,
110
+ contentType: input.contentType,
111
+ metadata: {
112
+ contentType: input.contentType,
113
+ md5Hash: createHash("md5").update(bytes).digest("base64"),
114
+ cacheControl: "no-store",
115
+ metadata: { ...input.metadata }
116
+ },
117
+ preconditionOpts: { ifGenerationMatch: 0 }
118
+ });
119
+ } catch (error) {
120
+ if (status(error) !== 412) throw error;
121
+ context.signal.throwIfAborted();
122
+ const [existing] = await bucket.file(input.key).getMetadata();
123
+ return { created: false, nativeVersion: generationOf(existing) };
124
+ }
125
+ if (file.metadata?.generation !== void 0) {
126
+ return { created: true, nativeVersion: generationOf(file.metadata) };
127
+ }
128
+ const [created] = await file.getMetadata();
129
+ return { created: true, nativeVersion: generationOf(created) };
130
+ });
131
+ },
132
+ get(input, context) {
133
+ return runReportingRowProviderOperation(context.signal, async () => {
134
+ const bucket = bucketFor(input);
135
+ assertKey(input.key);
136
+ assertReportingRowReadBounds(input);
137
+ const generation = pinnedGeneration(input.nativeVersion);
138
+ if (generation === null) return null;
139
+ const file = bucket.file(input.key, { generation });
140
+ try {
141
+ if (input.range?.length === 0) {
142
+ const [metadata] = await file.getMetadata();
143
+ if (input.range.offset > Number(metadata.size)) {
144
+ throw new ReportingRowStoreError("ROWS_INTEGRITY_FAILED", "requested range exceeds the stored object");
145
+ }
146
+ return Buffer.alloc(0);
147
+ }
148
+ const stream = file.createReadStream({
149
+ // The client always sends `Accept-Encoding: gzip`; with `decompress: false`
150
+ // neither GCS nor the client transcodes, so these are the stored bytes.
151
+ decompress: false,
152
+ // Digests recorded in PostgreSQL verify every byte returned.
153
+ validation: false,
154
+ ...input.range ? { start: input.range.offset, end: input.range.offset + input.range.length - 1 } : {}
155
+ });
156
+ return await readReportingRowStream(stream, input.maxBytes, context.signal);
157
+ } catch (error) {
158
+ const code = status(error);
159
+ if (code === 404) return null;
160
+ if (code === 416) {
161
+ throw new ReportingRowStoreError("ROWS_INTEGRITY_FAILED", "requested range exceeds the stored object");
162
+ }
163
+ throw error;
164
+ }
165
+ });
166
+ },
167
+ delete(input, context) {
168
+ return runReportingRowProviderOperation(context.signal, async () => {
169
+ const bucket = bucketFor(input);
170
+ assertKey(input.key);
171
+ const generation = pinnedGeneration(input.nativeVersion);
172
+ if (generation === null) return "absent";
173
+ try {
174
+ await bucket.file(input.key, { generation }).delete();
175
+ return "deleted";
176
+ } catch (error) {
177
+ const code = status(error);
178
+ if (code === 404 || code === 412) return "absent";
179
+ throw error;
180
+ }
181
+ });
182
+ }
183
+ };
184
+ }
185
+ export {
186
+ assertGcsReportingRowBucketPolicyV1,
187
+ createGcsReportingRowObjectProviderV1
188
+ };
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Host-facing reporting change feed (shared SDK persistence spec,
3
+ * adcontextprotocol/adcp#7996 §2.1 and §3.7).
4
+ *
5
+ * Apply after {@link REPORTING_LEDGER_MIGRATION}; PostgreSQL 13 or later
6
+ * (`xid8`). The store appends one row per committed obligation, revision,
7
+ * adjustment and retirement in the same transaction as the record, taking the
8
+ * sequence value only after the account lock, so per-account sequence order is
9
+ * commit order. Deployment-wide readers order by `(xid, seq)` and stop below
10
+ * the reading snapshot's `xmin`, so a slow commit is never skipped.
11
+ */
12
+ export declare const REPORTING_LEDGER_CHANGES_MIGRATION: string;
13
+ export type ReportingChangeKindV1 = 'obligation' | 'revision' | 'adjustment' | 'retirement';
14
+ export interface ReportingChangeRecordV1 {
15
+ kind: ReportingChangeKindV1;
16
+ record_id: string;
17
+ reporting_obligation_id: string;
18
+ account_id: string;
19
+ recorded_at: string;
20
+ }
21
+ export interface ReportingChangesPageV1 {
22
+ records: ReportingChangeRecordV1[];
23
+ /** Pass back to resume. Always present; equal to the input when nothing new committed. */
24
+ cursor: string;
25
+ }
26
+ interface ChangeCursorV1 {
27
+ v: 1;
28
+ /** Account scope, or `null` for the deployment-wide feed. */
29
+ account: string | null;
30
+ seq: string;
31
+ /** Deployment-wide feeds only: the writing transaction of the last record returned. */
32
+ xid?: string;
33
+ }
34
+ export declare function encodeReportingChangeCursorV1(cursor: ChangeCursorV1): string;
35
+ export declare function decodeReportingChangeCursorV1(value: string, account: string | null): ChangeCursorV1;
36
+ /** Thrown when a change cursor is older than the retained change history. */
37
+ export declare class ReportingChangeCursorExpiredError extends Error {
38
+ readonly code: "CURSOR_EXPIRED";
39
+ constructor();
40
+ }
41
+ export {};
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Host-facing reporting change feed (shared SDK persistence spec,
3
+ * adcontextprotocol/adcp#7996 §2.1 and §3.7).
4
+ *
5
+ * Apply after {@link REPORTING_LEDGER_MIGRATION}; PostgreSQL 13 or later
6
+ * (`xid8`). The store appends one row per committed obligation, revision,
7
+ * adjustment and retirement in the same transaction as the record, taking the
8
+ * sequence value only after the account lock, so per-account sequence order is
9
+ * commit order. Deployment-wide readers order by `(xid, seq)` and stop below
10
+ * the reading snapshot's `xmin`, so a slow commit is never skipped.
11
+ */
12
+ export declare const REPORTING_LEDGER_CHANGES_MIGRATION: string;
13
+ export type ReportingChangeKindV1 = 'obligation' | 'revision' | 'adjustment' | 'retirement';
14
+ export interface ReportingChangeRecordV1 {
15
+ kind: ReportingChangeKindV1;
16
+ record_id: string;
17
+ reporting_obligation_id: string;
18
+ account_id: string;
19
+ recorded_at: string;
20
+ }
21
+ export interface ReportingChangesPageV1 {
22
+ records: ReportingChangeRecordV1[];
23
+ /** Pass back to resume. Always present; equal to the input when nothing new committed. */
24
+ cursor: string;
25
+ }
26
+ interface ChangeCursorV1 {
27
+ v: 1;
28
+ /** Account scope, or `null` for the deployment-wide feed. */
29
+ account: string | null;
30
+ seq: string;
31
+ /** Deployment-wide feeds only: the writing transaction of the last record returned. */
32
+ xid?: string;
33
+ }
34
+ export declare function encodeReportingChangeCursorV1(cursor: ChangeCursorV1): string;
35
+ export declare function decodeReportingChangeCursorV1(value: string, account: string | null): ChangeCursorV1;
36
+ /** Thrown when a change cursor is older than the retained change history. */
37
+ export declare class ReportingChangeCursorExpiredError extends Error {
38
+ readonly code: "CURSOR_EXPIRED";
39
+ constructor();
40
+ }
41
+ export {};
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var change_feed_exports = {};
20
+ __export(change_feed_exports, {
21
+ REPORTING_LEDGER_CHANGES_MIGRATION: () => REPORTING_LEDGER_CHANGES_MIGRATION,
22
+ ReportingChangeCursorExpiredError: () => ReportingChangeCursorExpiredError,
23
+ decodeReportingChangeCursorV1: () => decodeReportingChangeCursorV1,
24
+ encodeReportingChangeCursorV1: () => encodeReportingChangeCursorV1
25
+ });
26
+ module.exports = __toCommonJS(change_feed_exports);
27
+ var import_row_storage_errors = require('./row-storage-errors.js');
28
+ const REPORTING_LEDGER_CHANGES_MIGRATION = `
29
+ CREATE TABLE IF NOT EXISTS adcp_reporting_changes (
30
+ seq BIGSERIAL PRIMARY KEY,
31
+ xid xid8 NOT NULL DEFAULT pg_current_xact_id(),
32
+ account_id TEXT NOT NULL,
33
+ record_kind TEXT NOT NULL
34
+ CHECK (record_kind IN ('obligation', 'revision', 'adjustment', 'retirement')),
35
+ record_id TEXT NOT NULL,
36
+ obligation_id TEXT NOT NULL,
37
+ recorded_at TIMESTAMPTZ NOT NULL DEFAULT clock_timestamp()
38
+ );
39
+ CREATE INDEX IF NOT EXISTS adcp_reporting_changes_account
40
+ ON adcp_reporting_changes (account_id, seq);
41
+ CREATE INDEX IF NOT EXISTS adcp_reporting_changes_deployment
42
+ ON adcp_reporting_changes (xid, seq);
43
+ CREATE INDEX IF NOT EXISTS adcp_reporting_changes_recorded
44
+ ON adcp_reporting_changes (recorded_at, seq);
45
+
46
+ -- Highest (xid, seq) ever pruned: a deployment-wide cursor below it may have
47
+ -- missed a deleted change and fails closed.
48
+ CREATE TABLE IF NOT EXISTS adcp_reporting_change_horizon (
49
+ singleton BOOLEAN PRIMARY KEY DEFAULT TRUE CHECK (singleton),
50
+ pruned_through_xid xid8 NOT NULL DEFAULT '0',
51
+ pruned_through_seq BIGINT NOT NULL DEFAULT 0
52
+ );
53
+ INSERT INTO adcp_reporting_change_horizon (singleton) VALUES (TRUE) ON CONFLICT DO NOTHING;
54
+
55
+ -- Highest seq ever pruned per account: an account cursor below it fails closed.
56
+ CREATE TABLE IF NOT EXISTS adcp_reporting_change_account_horizon (
57
+ account_id TEXT PRIMARY KEY,
58
+ pruned_through_seq BIGINT NOT NULL
59
+ );
60
+
61
+ -- Registered consumers hold back pruning in their own feed order: account
62
+ -- consumers by seq within their account, deployment consumers by (xid, seq).
63
+ CREATE TABLE IF NOT EXISTS adcp_reporting_feed_consumers (
64
+ consumer_name TEXT PRIMARY KEY CHECK (consumer_name ~ '^[A-Za-z0-9_.:-]{1,128}$'),
65
+ account_id TEXT,
66
+ cursor_xid xid8,
67
+ cursor_seq BIGINT NOT NULL,
68
+ updated_at TIMESTAMPTZ NOT NULL DEFAULT clock_timestamp(),
69
+ CHECK ((account_id IS NULL) = (cursor_xid IS NOT NULL))
70
+ );
71
+ `.trim();
72
+ function encodeReportingChangeCursorV1(cursor) {
73
+ return Buffer.from(JSON.stringify(cursor), "utf8").toString("base64url");
74
+ }
75
+ function decodeReportingChangeCursorV1(value, account) {
76
+ let parsed;
77
+ try {
78
+ parsed = JSON.parse(Buffer.from(value, "base64url").toString("utf8"));
79
+ } catch {
80
+ throw new import_row_storage_errors.ReportingRowStoreError("INVALID_INPUT", "change cursor is malformed");
81
+ }
82
+ const cursor = parsed;
83
+ if (cursor.v !== 1 || (cursor.account ?? null) !== account || typeof cursor.seq !== "string" || !/^\d{1,19}$/.test(cursor.seq) || (account === null ? typeof cursor.xid !== "string" || !/^\d{1,20}$/.test(cursor.xid) : cursor.xid !== void 0)) {
84
+ throw new import_row_storage_errors.ReportingRowStoreError("INVALID_INPUT", "change cursor does not belong to this feed");
85
+ }
86
+ return cursor;
87
+ }
88
+ class ReportingChangeCursorExpiredError extends Error {
89
+ code = "CURSOR_EXPIRED";
90
+ constructor() {
91
+ super("Reporting change cursor is older than the retained change history; resynchronize from current revisions");
92
+ this.name = "ReportingChangeCursorExpiredError";
93
+ }
94
+ }
95
+ // Annotate the CommonJS export names for ESM import in node:
96
+ 0 && (module.exports = {
97
+ REPORTING_LEDGER_CHANGES_MIGRATION,
98
+ ReportingChangeCursorExpiredError,
99
+ decodeReportingChangeCursorV1,
100
+ encodeReportingChangeCursorV1
101
+ });
@@ -0,0 +1,74 @@
1
+ import { ReportingRowStoreError } from "./row-storage-errors.mjs";
2
+ const REPORTING_LEDGER_CHANGES_MIGRATION = `
3
+ CREATE TABLE IF NOT EXISTS adcp_reporting_changes (
4
+ seq BIGSERIAL PRIMARY KEY,
5
+ xid xid8 NOT NULL DEFAULT pg_current_xact_id(),
6
+ account_id TEXT NOT NULL,
7
+ record_kind TEXT NOT NULL
8
+ CHECK (record_kind IN ('obligation', 'revision', 'adjustment', 'retirement')),
9
+ record_id TEXT NOT NULL,
10
+ obligation_id TEXT NOT NULL,
11
+ recorded_at TIMESTAMPTZ NOT NULL DEFAULT clock_timestamp()
12
+ );
13
+ CREATE INDEX IF NOT EXISTS adcp_reporting_changes_account
14
+ ON adcp_reporting_changes (account_id, seq);
15
+ CREATE INDEX IF NOT EXISTS adcp_reporting_changes_deployment
16
+ ON adcp_reporting_changes (xid, seq);
17
+ CREATE INDEX IF NOT EXISTS adcp_reporting_changes_recorded
18
+ ON adcp_reporting_changes (recorded_at, seq);
19
+
20
+ -- Highest (xid, seq) ever pruned: a deployment-wide cursor below it may have
21
+ -- missed a deleted change and fails closed.
22
+ CREATE TABLE IF NOT EXISTS adcp_reporting_change_horizon (
23
+ singleton BOOLEAN PRIMARY KEY DEFAULT TRUE CHECK (singleton),
24
+ pruned_through_xid xid8 NOT NULL DEFAULT '0',
25
+ pruned_through_seq BIGINT NOT NULL DEFAULT 0
26
+ );
27
+ INSERT INTO adcp_reporting_change_horizon (singleton) VALUES (TRUE) ON CONFLICT DO NOTHING;
28
+
29
+ -- Highest seq ever pruned per account: an account cursor below it fails closed.
30
+ CREATE TABLE IF NOT EXISTS adcp_reporting_change_account_horizon (
31
+ account_id TEXT PRIMARY KEY,
32
+ pruned_through_seq BIGINT NOT NULL
33
+ );
34
+
35
+ -- Registered consumers hold back pruning in their own feed order: account
36
+ -- consumers by seq within their account, deployment consumers by (xid, seq).
37
+ CREATE TABLE IF NOT EXISTS adcp_reporting_feed_consumers (
38
+ consumer_name TEXT PRIMARY KEY CHECK (consumer_name ~ '^[A-Za-z0-9_.:-]{1,128}$'),
39
+ account_id TEXT,
40
+ cursor_xid xid8,
41
+ cursor_seq BIGINT NOT NULL,
42
+ updated_at TIMESTAMPTZ NOT NULL DEFAULT clock_timestamp(),
43
+ CHECK ((account_id IS NULL) = (cursor_xid IS NOT NULL))
44
+ );
45
+ `.trim();
46
+ function encodeReportingChangeCursorV1(cursor) {
47
+ return Buffer.from(JSON.stringify(cursor), "utf8").toString("base64url");
48
+ }
49
+ function decodeReportingChangeCursorV1(value, account) {
50
+ let parsed;
51
+ try {
52
+ parsed = JSON.parse(Buffer.from(value, "base64url").toString("utf8"));
53
+ } catch {
54
+ throw new ReportingRowStoreError("INVALID_INPUT", "change cursor is malformed");
55
+ }
56
+ const cursor = parsed;
57
+ if (cursor.v !== 1 || (cursor.account ?? null) !== account || typeof cursor.seq !== "string" || !/^\d{1,19}$/.test(cursor.seq) || (account === null ? typeof cursor.xid !== "string" || !/^\d{1,20}$/.test(cursor.xid) : cursor.xid !== void 0)) {
58
+ throw new ReportingRowStoreError("INVALID_INPUT", "change cursor does not belong to this feed");
59
+ }
60
+ return cursor;
61
+ }
62
+ class ReportingChangeCursorExpiredError extends Error {
63
+ code = "CURSOR_EXPIRED";
64
+ constructor() {
65
+ super("Reporting change cursor is older than the retained change history; resynchronize from current revisions");
66
+ this.name = "ReportingChangeCursorExpiredError";
67
+ }
68
+ }
69
+ export {
70
+ REPORTING_LEDGER_CHANGES_MIGRATION,
71
+ ReportingChangeCursorExpiredError,
72
+ decodeReportingChangeCursorV1,
73
+ encodeReportingChangeCursorV1
74
+ };
@@ -36,6 +36,7 @@ var import_coverage = require('./coverage.js');
36
36
  var import_health = require('./health.js');
37
37
  var import_instant = require('./instant.js');
38
38
  var import_revision_metadata = require('./revision-metadata.js');
39
+ var import_row_storage = require('./row-storage.js');
39
40
  var import_schedule = require('./schedule.js');
40
41
  var import_types = require('./types.js');
41
42
  function createReportingStatusHandler(store, options) {
@@ -267,7 +268,9 @@ function createReportingStatusHandler(store, options) {
267
268
  else revisionRows = page2.rows;
268
269
  }
269
270
  } catch (error) {
270
- if (error instanceof ReportingReadCapacityError) return lookupUnavailable(view);
271
+ if (error instanceof ReportingReadCapacityError || (0, import_row_storage.isReportingRowStoreError)(error)) {
272
+ return lookupUnavailable(view);
273
+ }
271
274
  throw error;
272
275
  }
273
276
  }
@@ -450,13 +453,24 @@ function createReportingDeliveryHandler(store) {
450
453
  }
451
454
  let reportingRows = [];
452
455
  if (totalCount > 0) {
453
- const page = await (0, import_revision_metadata.readRevisionRowsFromStore)(store, {
454
- reporting_revision_id: revision.reporting_revision_id,
455
- account_id: accountId,
456
- offset,
457
- limit: maxResults,
458
- ...context.signal ? { signal: context.signal } : {}
459
- });
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
+ }
460
474
  if (!page || page.total !== totalCount) throw new Error("Reporting revision is unavailable");
461
475
  reportingRows = page.rows;
462
476
  }
@@ -19,6 +19,7 @@ import {
19
19
  } from "./health.mjs";
20
20
  import { compareReportingInstants } from "./instant.mjs";
21
21
  import { getRevisionMetadataFromStore, readRevisionRowsFromStore } from "./revision-metadata.mjs";
22
+ import { isReportingRowStoreError } from "./row-storage.mjs";
22
23
  import { reportingPeriodSchedule } from "./schedule.mjs";
23
24
  import { ReportingLedgerSnapshotUnavailableError } from "./types.mjs";
24
25
  function createReportingStatusHandler(store, options) {
@@ -250,7 +251,9 @@ function createReportingStatusHandler(store, options) {
250
251
  else revisionRows = page2.rows;
251
252
  }
252
253
  } catch (error) {
253
- if (error instanceof ReportingReadCapacityError) return lookupUnavailable(view);
254
+ if (error instanceof ReportingReadCapacityError || isReportingRowStoreError(error)) {
255
+ return lookupUnavailable(view);
256
+ }
254
257
  throw error;
255
258
  }
256
259
  }
@@ -433,13 +436,24 @@ function createReportingDeliveryHandler(store) {
433
436
  }
434
437
  let reportingRows = [];
435
438
  if (totalCount > 0) {
436
- const page = await readRevisionRowsFromStore(store, {
437
- reporting_revision_id: revision.reporting_revision_id,
438
- account_id: accountId,
439
- offset,
440
- limit: maxResults,
441
- ...context.signal ? { signal: context.signal } : {}
442
- });
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
+ }
443
457
  if (!page || page.total !== totalCount) throw new Error("Reporting revision is unavailable");
444
458
  reportingRows = page.rows;
445
459
  }
@@ -12,3 +12,7 @@ export * from './managed-postgres.mjs';
12
12
  export * from './object-writes.mjs';
13
13
  export * from './notification-activity.mjs';
14
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';
@@ -12,3 +12,7 @@ export * from './managed-postgres';
12
12
  export * from './object-writes';
13
13
  export * from './notification-activity';
14
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';
@@ -29,6 +29,10 @@ __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
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);
32
36
  // Annotate the CommonJS export names for ESM import in node:
33
37
  0 && (module.exports = {
34
38
  ...require('./types.js'),
@@ -44,5 +48,9 @@ __reExport(ledger_exports, require('./row-encoding.js'), module.exports);
44
48
  ...require('./managed-postgres.js'),
45
49
  ...require('./object-writes.js'),
46
50
  ...require('./notification-activity.js'),
47
- ...require('./row-encoding.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')
48
56
  });
@@ -12,3 +12,7 @@ export * from "./managed-postgres.mjs";
12
12
  export * from "./object-writes.mjs";
13
13
  export * from "./notification-activity.mjs";
14
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";
@@ -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;