@adcp/sdk 16.0.0-beta.3 → 16.0.0-beta.4

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 (182) hide show
  1. package/dist/lib/auth/oauth/diagnose.js +3 -11
  2. package/dist/lib/auth/oauth/diagnose.mjs +4 -12
  3. package/dist/lib/auth/oauth/diagnostics.d.mts +2 -1
  4. package/dist/lib/auth/oauth/diagnostics.d.ts +2 -1
  5. package/dist/lib/auth/oauth/diagnostics.js +8 -10
  6. package/dist/lib/auth/oauth/diagnostics.mjs +7 -10
  7. package/dist/lib/index.d.mts +1 -1
  8. package/dist/lib/index.d.ts +1 -1
  9. package/dist/lib/index.js +2 -0
  10. package/dist/lib/index.mjs +7 -1
  11. package/dist/lib/reporting/consumer-runtime.js +2 -1
  12. package/dist/lib/reporting/consumer-runtime.mjs +2 -1
  13. package/dist/lib/reporting/ledger/handler.js +50 -11
  14. package/dist/lib/reporting/ledger/handler.mjs +50 -12
  15. package/dist/lib/reporting/ledger/index.d.mts +17 -14
  16. package/dist/lib/reporting/ledger/index.d.ts +17 -14
  17. package/dist/lib/reporting/ledger/index.js +32 -20
  18. package/dist/lib/reporting/ledger/index.mjs +21 -10
  19. package/dist/lib/reporting/ledger/offering-validation.d.mts +9 -0
  20. package/dist/lib/reporting/ledger/offering-validation.d.ts +9 -0
  21. package/dist/lib/reporting/{gcs/bucket-policy.js → ledger/offering-validation.js} +9 -8
  22. package/dist/lib/reporting/ledger/offering-validation.mjs +8 -0
  23. package/dist/lib/reporting/ledger/receipts.d.mts +48 -0
  24. package/dist/lib/reporting/ledger/receipts.d.ts +48 -0
  25. package/dist/lib/reporting/ledger/receipts.js +186 -0
  26. package/dist/lib/reporting/ledger/receipts.mjs +161 -0
  27. package/dist/lib/reporting/ledger/status-ingest.js +3 -3
  28. package/dist/lib/reporting/ledger/status-ingest.mjs +4 -5
  29. package/dist/lib/reporting/ledger/types.d.mts +43 -0
  30. package/dist/lib/reporting/ledger/types.d.ts +43 -0
  31. package/dist/lib/reporting/ledger/types.js +31 -2
  32. package/dist/lib/reporting/ledger/types.mjs +26 -1
  33. package/dist/lib/reporting/pagination.d.mts +6 -0
  34. package/dist/lib/reporting/pagination.d.ts +6 -0
  35. package/dist/lib/reporting/{gcs/errors.js → pagination.js} +12 -17
  36. package/dist/lib/reporting/pagination.mjs +12 -0
  37. package/dist/lib/reporting/reconciliation.d.mts +1 -0
  38. package/dist/lib/reporting/reconciliation.d.ts +1 -0
  39. package/dist/lib/reporting/reconciliation.js +3 -2
  40. package/dist/lib/reporting/reconciliation.mjs +3 -2
  41. package/dist/lib/reporting/service/index.d.mts +79 -153
  42. package/dist/lib/reporting/service/index.d.ts +79 -153
  43. package/dist/lib/reporting/service/index.js +34 -491
  44. package/dist/lib/reporting/service/index.mjs +36 -510
  45. package/dist/lib/reporting/service/scheduler-support.d.mts +43 -0
  46. package/dist/lib/reporting/service/scheduler-support.d.ts +43 -0
  47. package/dist/lib/reporting/service/scheduler-support.js +125 -0
  48. package/dist/lib/reporting/service/scheduler-support.mjs +96 -0
  49. package/dist/lib/schemas-data/v2.5/_provenance.json +1 -1
  50. package/dist/lib/signing/canonicalize.d.mts +4 -0
  51. package/dist/lib/signing/canonicalize.d.ts +4 -0
  52. package/dist/lib/signing/canonicalize.js +14 -8
  53. package/dist/lib/signing/canonicalize.mjs +14 -8
  54. package/dist/lib/signing/content-digest.d.mts +8 -0
  55. package/dist/lib/signing/content-digest.d.ts +8 -0
  56. package/dist/lib/signing/content-digest.js +11 -5
  57. package/dist/lib/signing/content-digest.mjs +10 -5
  58. package/dist/lib/signing/signer.js +9 -6
  59. package/dist/lib/signing/signer.mjs +10 -7
  60. package/dist/lib/signing/web-bot-auth.js +103 -37
  61. package/dist/lib/signing/web-bot-auth.mjs +108 -37
  62. package/dist/lib/testing/storyboard/junit.js +16 -3
  63. package/dist/lib/testing/storyboard/junit.mjs +16 -3
  64. package/dist/lib/testing/storyboard/request-signing/builder.js +10 -9
  65. package/dist/lib/testing/storyboard/request-signing/builder.mjs +10 -9
  66. package/dist/lib/testing/storyboard/runner.js +94 -25
  67. package/dist/lib/testing/storyboard/runner.mjs +94 -25
  68. package/dist/lib/testing/storyboard/types.d.mts +6 -0
  69. package/dist/lib/testing/storyboard/types.d.ts +6 -0
  70. package/dist/lib/testing/storyboard/validations.d.mts +1 -1
  71. package/dist/lib/testing/storyboard/validations.d.ts +1 -1
  72. package/dist/lib/version.d.mts +3 -3
  73. package/dist/lib/version.d.ts +3 -3
  74. package/dist/lib/version.js +3 -3
  75. package/dist/lib/version.mjs +3 -3
  76. package/docs/TYPE-SUMMARY.md +23 -5
  77. package/docs/guides/REPORTING-GCS-FENCE.md +3 -3
  78. package/docs/guides/REPORTING-GCS-MANAGED.md +4 -4
  79. package/docs/guides/REPORTING-LEDGER-CUTOVER.md +7 -7
  80. package/docs/guides/REPORTING-LEDGER.md +107 -51
  81. package/docs/guides/REPORTING-OPERATIONS.md +66 -5
  82. package/docs/guides/REPORTING-STABILITY.md +36 -32
  83. package/docs/llms.txt +4 -3
  84. package/docs/migration-14.x-rc-worksheet.md +4 -7
  85. package/docs/migration-reporting-storage-package.md +186 -0
  86. package/examples/README.md +1 -1
  87. package/package.json +13 -78
  88. package/dist/lib/reporting/azure/index.d.mts +0 -31
  89. package/dist/lib/reporting/azure/index.d.ts +0 -31
  90. package/dist/lib/reporting/azure/index.js +0 -266
  91. package/dist/lib/reporting/azure/index.mjs +0 -249
  92. package/dist/lib/reporting/bigquery/index.d.mts +0 -246
  93. package/dist/lib/reporting/bigquery/index.d.ts +0 -246
  94. package/dist/lib/reporting/bigquery/index.js +0 -633
  95. package/dist/lib/reporting/bigquery/index.mjs +0 -594
  96. package/dist/lib/reporting/gcs/adapter.d.mts +0 -38
  97. package/dist/lib/reporting/gcs/adapter.d.ts +0 -38
  98. package/dist/lib/reporting/gcs/adapter.js +0 -342
  99. package/dist/lib/reporting/gcs/adapter.mjs +0 -325
  100. package/dist/lib/reporting/gcs/bucket-policy.d.mts +0 -3
  101. package/dist/lib/reporting/gcs/bucket-policy.d.ts +0 -3
  102. package/dist/lib/reporting/gcs/bucket-policy.mjs +0 -7
  103. package/dist/lib/reporting/gcs/errors.d.mts +0 -11
  104. package/dist/lib/reporting/gcs/errors.d.ts +0 -11
  105. package/dist/lib/reporting/gcs/errors.mjs +0 -16
  106. package/dist/lib/reporting/gcs/fence.d.mts +0 -41
  107. package/dist/lib/reporting/gcs/fence.d.ts +0 -41
  108. package/dist/lib/reporting/gcs/fence.js +0 -250
  109. package/dist/lib/reporting/gcs/fence.mjs +0 -230
  110. package/dist/lib/reporting/gcs/index.d.mts +0 -18
  111. package/dist/lib/reporting/gcs/index.d.ts +0 -18
  112. package/dist/lib/reporting/gcs/index.js +0 -44
  113. package/dist/lib/reporting/gcs/index.mjs +0 -14
  114. package/dist/lib/reporting/gcs/io.d.mts +0 -7
  115. package/dist/lib/reporting/gcs/io.d.ts +0 -7
  116. package/dist/lib/reporting/gcs/io.js +0 -95
  117. package/dist/lib/reporting/gcs/io.mjs +0 -69
  118. package/dist/lib/reporting/gcs/reader.d.mts +0 -67
  119. package/dist/lib/reporting/gcs/reader.d.ts +0 -67
  120. package/dist/lib/reporting/gcs/reader.js +0 -193
  121. package/dist/lib/reporting/gcs/reader.mjs +0 -169
  122. package/dist/lib/reporting/gcs/row-provider.d.mts +0 -39
  123. package/dist/lib/reporting/gcs/row-provider.d.ts +0 -39
  124. package/dist/lib/reporting/gcs/row-provider.js +0 -225
  125. package/dist/lib/reporting/gcs/row-provider.mjs +0 -208
  126. package/dist/lib/reporting/gcs/validation.d.mts +0 -5
  127. package/dist/lib/reporting/gcs/validation.d.ts +0 -5
  128. package/dist/lib/reporting/gcs/validation.js +0 -49
  129. package/dist/lib/reporting/gcs/validation.mjs +0 -25
  130. package/dist/lib/reporting/ledger/change-feed.d.mts +0 -69
  131. package/dist/lib/reporting/ledger/change-feed.d.ts +0 -69
  132. package/dist/lib/reporting/ledger/change-feed.js +0 -107
  133. package/dist/lib/reporting/ledger/change-feed.mjs +0 -80
  134. package/dist/lib/reporting/ledger/managed-postgres.d.mts +0 -293
  135. package/dist/lib/reporting/ledger/managed-postgres.d.ts +0 -293
  136. package/dist/lib/reporting/ledger/managed-postgres.js +0 -2346
  137. package/dist/lib/reporting/ledger/managed-postgres.mjs +0 -2332
  138. package/dist/lib/reporting/ledger/managed-router.d.mts +0 -148
  139. package/dist/lib/reporting/ledger/managed-router.d.ts +0 -148
  140. package/dist/lib/reporting/ledger/managed-router.js +0 -280
  141. package/dist/lib/reporting/ledger/managed-router.mjs +0 -258
  142. package/dist/lib/reporting/ledger/managed.d.mts +0 -535
  143. package/dist/lib/reporting/ledger/managed.d.ts +0 -535
  144. package/dist/lib/reporting/ledger/managed.js +0 -761
  145. package/dist/lib/reporting/ledger/managed.mjs +0 -729
  146. package/dist/lib/reporting/ledger/notification-activity.d.mts +0 -332
  147. package/dist/lib/reporting/ledger/notification-activity.d.ts +0 -332
  148. package/dist/lib/reporting/ledger/notification-activity.js +0 -1366
  149. package/dist/lib/reporting/ledger/notification-activity.mjs +0 -1337
  150. package/dist/lib/reporting/ledger/object-writes.d.mts +0 -128
  151. package/dist/lib/reporting/ledger/object-writes.d.ts +0 -128
  152. package/dist/lib/reporting/ledger/object-writes.js +0 -147
  153. package/dist/lib/reporting/ledger/object-writes.mjs +0 -114
  154. package/dist/lib/reporting/ledger/postgres.d.mts +0 -689
  155. package/dist/lib/reporting/ledger/postgres.d.ts +0 -689
  156. package/dist/lib/reporting/ledger/postgres.js +0 -4462
  157. package/dist/lib/reporting/ledger/postgres.mjs +0 -4462
  158. package/dist/lib/reporting/ledger/row-storage-migration.d.mts +0 -59
  159. package/dist/lib/reporting/ledger/row-storage-migration.d.ts +0 -59
  160. package/dist/lib/reporting/ledger/row-storage-migration.js +0 -365
  161. package/dist/lib/reporting/ledger/row-storage-migration.mjs +0 -339
  162. package/dist/lib/reporting/ledger/row-storage-object.d.mts +0 -203
  163. package/dist/lib/reporting/ledger/row-storage-object.d.ts +0 -203
  164. package/dist/lib/reporting/ledger/row-storage-object.js +0 -379
  165. package/dist/lib/reporting/ledger/row-storage-object.mjs +0 -335
  166. package/dist/lib/reporting/ledger/row-storage-provider-io.d.mts +0 -44
  167. package/dist/lib/reporting/ledger/row-storage-provider-io.d.ts +0 -44
  168. package/dist/lib/reporting/ledger/row-storage-provider-io.js +0 -142
  169. package/dist/lib/reporting/ledger/row-storage-provider-io.mjs +0 -111
  170. package/dist/lib/reporting/ledger/row-storage.d.mts +0 -316
  171. package/dist/lib/reporting/ledger/row-storage.d.ts +0 -316
  172. package/dist/lib/reporting/ledger/row-storage.js +0 -812
  173. package/dist/lib/reporting/ledger/row-storage.mjs +0 -802
  174. package/dist/lib/reporting/s3/index.d.mts +0 -34
  175. package/dist/lib/reporting/s3/index.d.ts +0 -34
  176. package/dist/lib/reporting/s3/index.js +0 -347
  177. package/dist/lib/reporting/s3/index.mjs +0 -340
  178. package/dist/lib/reporting/service/maintenance.d.mts +0 -148
  179. package/dist/lib/reporting/service/maintenance.d.ts +0 -148
  180. package/dist/lib/reporting/service/maintenance.js +0 -185
  181. package/dist/lib/reporting/service/maintenance.mjs +0 -159
  182. package/examples/reliable-reporting-service/README.md +0 -169
@@ -1,249 +0,0 @@
1
- import { randomUUID } from "node:crypto";
2
- import { ReportingRowStoreError } from "../ledger/row-storage-errors.mjs";
3
- import {
4
- assertReportingRowLocationKeys,
5
- assertReportingRowReadBounds,
6
- readReportingRowStream,
7
- reportingRowClientMap,
8
- runReportingRowProviderOperation,
9
- selectReportingRowClient
10
- } from "../ledger/row-storage-provider-io.mjs";
11
- const ACCOUNT = /^[a-z0-9]{3,24}$/;
12
- const CONTAINER = /^[a-z0-9](?:[a-z0-9]|-(?=[a-z0-9])){2,62}$/;
13
- const VERSION_ID = /^[0-9A-Za-z:.+-]{1,64}$/;
14
- function statusOf(error) {
15
- const status = Number(error?.statusCode);
16
- return Number.isInteger(status) ? status : void 0;
17
- }
18
- function codeOf(error) {
19
- const value = error?.code ?? error?.details?.errorCode;
20
- return typeof value === "string" ? value : "";
21
- }
22
- const isConflict = (error) => statusOf(error) === 409 || statusOf(error) === 412 || codeOf(error) === "BlobAlreadyExists";
23
- const isMissing = (error) => statusOf(error) === 404 || statusOf(error) === 412;
24
- const isForbidden = (error) => statusOf(error) === 401 || statusOf(error) === 403;
25
- function versionOf(response) {
26
- const id = response.versionId;
27
- if (typeof id !== "string" || !VERSION_ID.test(id)) {
28
- throw new ReportingRowStoreError(
29
- "UNSAFE_BINDING",
30
- "store returned no blob versionId; blob versioning must be enabled on the storage account so deletes are fenced to one write"
31
- );
32
- }
33
- return id;
34
- }
35
- function servedVersion(response, versionId) {
36
- return response.versionId === versionId;
37
- }
38
- function metadataOf(metadata) {
39
- const result = {};
40
- for (const [name, value] of Object.entries(metadata)) {
41
- const identifier = name.replace(/[^A-Za-z0-9_]/g, "_");
42
- result[/^[A-Za-z_]/.test(identifier) ? identifier : `_${identifier}`] = value;
43
- }
44
- return result;
45
- }
46
- function createAzureBlobReportingRowObjectProviderV1(options) {
47
- if (!options || typeof options !== "object") {
48
- throw new ReportingRowStoreError("INVALID_INPUT", "Azure Blob row provider options are required");
49
- }
50
- const clients = reportingRowClientMap(options.clients);
51
- const isClient = (value) => !!value && typeof value === "object" && typeof value.getContainerClient === "function" && typeof value.accountName === "string";
52
- if (options.client !== void 0 && !isClient(options.client) || [...clients.values()].some((client) => !isClient(client)) || options.client === void 0 && clients.size === 0) {
53
- throw new ReportingRowStoreError("INVALID_INPUT", "inject an official BlobServiceClient as client or clients");
54
- }
55
- const validateLocation = (location) => {
56
- assertReportingRowLocationKeys(location, ["account", "container"]);
57
- if (!ACCOUNT.test(location.account)) {
58
- throw new ReportingRowStoreError("INVALID_INPUT", "Azure storage account name is invalid");
59
- }
60
- if (!CONTAINER.test(location.container)) {
61
- throw new ReportingRowStoreError("INVALID_INPUT", "Azure container name is invalid");
62
- }
63
- };
64
- const containerFor = (input) => {
65
- validateLocation(input.location);
66
- const client = selectReportingRowClient(options.client, clients, input.credentialRef);
67
- if (client.accountName !== input.location.account) {
68
- throw new ReportingRowStoreError("UNSAFE_BINDING", "client does not belong to the binding account");
69
- }
70
- return client.getContainerClient(input.location.container);
71
- };
72
- const blobFor = (input) => {
73
- if (typeof input.objectRef !== "string" || input.objectRef.length === 0 || input.objectRef.length > 1024) {
74
- throw new ReportingRowStoreError("INVALID_INPUT", "object key is invalid");
75
- }
76
- return containerFor(input).getBlockBlobClient(input.objectRef);
77
- };
78
- const pinned = (blob, nativeVersionRef) => typeof nativeVersionRef === "string" && VERSION_ID.test(nativeVersionRef) ? { blob: blob.withVersion(nativeVersionRef), versionId: nativeVersionRef } : null;
79
- async function assertCreateOnlyEnforced(container, prefix, signal) {
80
- const blob = container.getBlockBlobClient(`${prefix}/.adcp-probe/${randomUUID()}`);
81
- const versionIds = [];
82
- let written = false;
83
- const upload = async (body) => {
84
- const bytes = Buffer.from(body);
85
- const response = await blob.upload(bytes, bytes.byteLength, {
86
- conditions: { ifNoneMatch: "*" },
87
- blobHTTPHeaders: { blobContentType: "application/x-ndjson", blobCacheControl: "no-store" },
88
- abortSignal: signal
89
- });
90
- written = true;
91
- if (response.versionId) versionIds.push(response.versionId);
92
- versionOf(response);
93
- };
94
- try {
95
- await upload('{"probe":1}\n');
96
- try {
97
- await upload('{"probe":2}\n');
98
- } catch (error) {
99
- if (isConflict(error)) return;
100
- throw error;
101
- }
102
- throw new ReportingRowStoreError("UNSAFE_BINDING", "store ignores If-None-Match and replaces blobs");
103
- } finally {
104
- if (written && !signal.aborted) {
105
- await blob.delete({ abortSignal: signal }).catch(() => void 0);
106
- for (const versionId of versionIds) {
107
- if (signal.aborted) break;
108
- await blob.withVersion(versionId).delete({ abortSignal: signal }).catch(() => void 0);
109
- }
110
- }
111
- }
112
- }
113
- return {
114
- name: "azure_blob",
115
- rangedReads: true,
116
- validateLocation,
117
- probe(input, context) {
118
- return runReportingRowProviderOperation(context.signal, async () => {
119
- const container = containerFor(input);
120
- let properties;
121
- try {
122
- properties = await container.getProperties({ abortSignal: context.signal });
123
- } catch (error) {
124
- if (statusOf(error) === 404) throw new ReportingRowStoreError("UNSAFE_BINDING", "container does not exist");
125
- if (isForbidden(error)) throw new ReportingRowStoreError("UNSAFE_BINDING", "container is not accessible");
126
- throw error;
127
- }
128
- if (properties.blobPublicAccess) {
129
- throw new ReportingRowStoreError("UNSAFE_BINDING", "container allows anonymous read access");
130
- }
131
- await assertCreateOnlyEnforced(container, input.prefix, context.signal);
132
- });
133
- },
134
- putIfAbsent(input, context) {
135
- return runReportingRowProviderOperation(context.signal, async () => {
136
- const blob = blobFor(input);
137
- const bytes = Buffer.from(input.bytes);
138
- try {
139
- const response = await blob.upload(bytes, bytes.byteLength, {
140
- conditions: { ifNoneMatch: "*" },
141
- blobHTTPHeaders: { blobContentType: input.contentType, blobCacheControl: "no-store" },
142
- metadata: metadataOf(input.metadata),
143
- abortSignal: context.signal
144
- });
145
- return { created: true, nativeVersionRef: versionOf(response) };
146
- } catch (error) {
147
- if (!isConflict(error)) throw error;
148
- }
149
- const existing = await blob.getProperties({ abortSignal: context.signal });
150
- return { created: false, nativeVersionRef: versionOf(existing) };
151
- });
152
- },
153
- get(input, context) {
154
- return runReportingRowProviderOperation(context.signal, async () => {
155
- const blob = blobFor(input);
156
- assertReportingRowReadBounds(input);
157
- const target = pinned(blob, input.nativeVersionRef);
158
- if (target === null) return null;
159
- try {
160
- if (input.range?.length === 0) {
161
- const properties = await target.blob.getProperties({ abortSignal: context.signal });
162
- if (!servedVersion(properties, target.versionId)) return null;
163
- if (input.range.offset > Number(properties.contentLength ?? 0)) {
164
- throw new ReportingRowStoreError("ROWS_INTEGRITY_FAILED", "requested range exceeds the stored object");
165
- }
166
- return Buffer.alloc(0);
167
- }
168
- const response = await target.blob.download(input.range?.offset ?? 0, input.range?.length, {
169
- abortSignal: context.signal
170
- });
171
- const body = response.readableStreamBody;
172
- if (!body || typeof body[Symbol.asyncIterator] !== "function") {
173
- throw new ReportingRowStoreError("PROVIDER_UNAVAILABLE", "blob body is not a stream");
174
- }
175
- if (!servedVersion(response, target.versionId)) {
176
- body.destroy?.();
177
- return null;
178
- }
179
- if (typeof response.contentLength === "number" && response.contentLength > input.maxBytes) {
180
- body.destroy?.();
181
- throw new ReportingRowStoreError("ROWS_INTEGRITY_FAILED", "stored object exceeds its recorded size");
182
- }
183
- return await readReportingRowStream(body, input.maxBytes, context.signal);
184
- } catch (error) {
185
- if (isMissing(error)) return null;
186
- if (statusOf(error) === 400) return null;
187
- if (statusOf(error) === 416 || codeOf(error) === "InvalidRange") {
188
- throw new ReportingRowStoreError("ROWS_INTEGRITY_FAILED", "requested range exceeds the stored object");
189
- }
190
- throw error;
191
- }
192
- });
193
- },
194
- stat(input, context) {
195
- return runReportingRowProviderOperation(context.signal, async () => {
196
- const blob = blobFor(input);
197
- const target = pinned(blob, input.nativeVersionRef);
198
- if (target === null) return null;
199
- try {
200
- const properties = await target.blob.getProperties({ abortSignal: context.signal });
201
- if (!servedVersion(properties, target.versionId)) return null;
202
- const size = properties.contentLength;
203
- if (typeof size !== "number" || !Number.isSafeInteger(size) || size < 0) {
204
- throw new ReportingRowStoreError("PROVIDER_UNAVAILABLE", "blob metadata is malformed");
205
- }
206
- return { nativeVersionRef: target.versionId, sizeBytes: size };
207
- } catch (error) {
208
- if (isMissing(error) || statusOf(error) === 400) return null;
209
- throw error;
210
- }
211
- });
212
- },
213
- delete(input, context) {
214
- return runReportingRowProviderOperation(context.signal, async () => {
215
- const blob = blobFor(input);
216
- const target = pinned(blob, input.nativeVersionRef);
217
- if (target === null) return "absent";
218
- const signal = context.signal;
219
- try {
220
- const recorded = await target.blob.getProperties({ abortSignal: signal });
221
- if (recorded.versionId !== target.versionId) return "absent";
222
- } catch (error) {
223
- if (isMissing(error) || statusOf(error) === 400) return "absent";
224
- throw error;
225
- }
226
- let deletedCurrent = false;
227
- try {
228
- const current = await blob.getProperties({ abortSignal: signal });
229
- if (current.versionId === target.versionId && current.etag) {
230
- await blob.delete({ conditions: { ifMatch: current.etag }, abortSignal: signal });
231
- deletedCurrent = true;
232
- }
233
- } catch (error) {
234
- if (!isMissing(error)) throw error;
235
- }
236
- try {
237
- await target.blob.delete({ abortSignal: signal });
238
- return "deleted";
239
- } catch (error) {
240
- if (isMissing(error) || statusOf(error) === 400) return deletedCurrent ? "deleted" : "absent";
241
- throw error;
242
- }
243
- });
244
- }
245
- };
246
- }
247
- export {
248
- createAzureBlobReportingRowObjectProviderV1
249
- };
@@ -1,246 +0,0 @@
1
- import type { PostgresReportingLedgerStore, ReportingLedgerRevisionMetadataV1, ReportingPgPool } from '../ledger/index.mjs';
2
- /**
3
- * BigQuery warehouse sink for Reliable Reporting (shared SDK persistence spec,
4
- * adcontextprotocol/adcp#7996 §3.6).
5
- *
6
- * The sink is a derived, non-authoritative copy of committed revisions. It
7
- * follows the ledger's host change feed, reads every revision's rows through
8
- * the store's verified reader, maps them to the adopter's columns, and loads
9
- * one batch per tick with a deterministic job ID. It is never read for
10
- * serving or verification, so its tables, columns, partitioning and retention
11
- * are the adopter's.
12
- *
13
- * Exactly-once loading: a batch (change-feed range, revision list, job IDs) is
14
- * planned durably in PostgreSQL before any load. Before every submission the
15
- * sink looks the deterministic job ID up in the destination project and
16
- * location: a job that finished cleanly counts as loaded, a job still running
17
- * is waited for (never uploaded again), and only a missing job is uploaded.
18
- * A crash or timeout between the load and the cursor commit therefore replays
19
- * the same batch under the same job IDs without a second upload. A failed load
20
- * job is retried under a new attempt suffix only after BigQuery reports that
21
- * job finished with an error, and each table keeps its own attempt count, so
22
- * no batch lands twice. A load that outlasts the deadline never changes the job
23
- * ID: the sink grows that table's deadline instead (persisted with the plan).
24
- * Concurrent runs claim one durable plan with compare-and-swap. Replays of
25
- * that plan share job IDs; stale runs cannot change its attempts or cursor.
26
- */
27
- /**
28
- * Apply after `REPORTING_LEDGER_CHANGES_MIGRATION`. Holds one row per sink.
29
- *
30
- * @experimental Reliable Reporting storage surface: breaking changes may ship in minor releases. See https://github.com/adcontextprotocol/adcp-client/blob/main/docs/guides/REPORTING-STABILITY.md
31
- */
32
- export declare const REPORTING_WAREHOUSE_SINK_MIGRATION: string;
33
- /**
34
- * Structural subset of the official `@google-cloud/bigquery` client the sink uses.
35
- *
36
- * @experimental Reliable Reporting storage surface: breaking changes may ship in minor releases. See https://github.com/adcontextprotocol/adcp-client/blob/main/docs/guides/REPORTING-STABILITY.md
37
- */
38
- export interface ReportingBigQueryClientV1 {
39
- dataset(datasetId: string, options?: {
40
- projectId?: string;
41
- location?: string;
42
- }): {
43
- table(tableId: string): {
44
- load(source: string, metadata: Record<string, unknown>): Promise<unknown>;
45
- };
46
- };
47
- job(jobId: string, options?: {
48
- projectId?: string;
49
- location?: string;
50
- }): {
51
- getMetadata(): Promise<unknown>;
52
- /** @deprecated Unused: BigQuery does not stop a running load, so the sink never cancels. Kept so wrappers that declare it still type-check. */
53
- cancel?(): Promise<unknown>;
54
- };
55
- query(options: {
56
- query: string;
57
- location?: string;
58
- }): Promise<unknown>;
59
- }
60
- /**
61
- * @experimental Reliable Reporting storage surface: breaking changes may ship in minor releases. See https://github.com/adcontextprotocol/adcp-client/blob/main/docs/guides/REPORTING-STABILITY.md
62
- */
63
- export interface ReportingWarehouseRowContextV1 {
64
- revision: ReportingLedgerRevisionMetadataV1;
65
- ordinal: number;
66
- }
67
- /**
68
- * @experimental Reliable Reporting storage surface: breaking changes may ship in minor releases. See https://github.com/adcontextprotocol/adcp-client/blob/main/docs/guides/REPORTING-STABILITY.md
69
- */
70
- export interface CreateBigQueryReportingWarehouseSinkOptionsV1 {
71
- /** Ledger store with `changeFeed: true`. */
72
- store: Pick<PostgresReportingLedgerStore, 'changesAfter' | 'getRevisionMetadata' | 'readRevisionRows'> & {
73
- /**
74
- * The sink ignores the result, so wrappers written when this resolved
75
- * `void` keep compiling.
76
- */
77
- saveFeedConsumerCursor(name: string, cursor: string, options?: {
78
- refreshUnchanged?: boolean;
79
- }): Promise<unknown>;
80
- } & /** Needed only by `reset()`; custom store wrappers that predate it keep compiling. */ Partial<Pick<PostgresReportingLedgerStore, 'removeFeedConsumer'>>;
81
- /** PostgreSQL pool holding `REPORTING_WAREHOUSE_SINK_MIGRATION`. */
82
- db: Pick<ReportingPgPool, 'query'>;
83
- /** Host-constructed official BigQuery client. */
84
- bigquery: ReportingBigQueryClientV1;
85
- /**
86
- * Stable sink and consumer name. All replicas sharing it must use the same
87
- * ledger database, feed scope, destination, location and row mapping. Use
88
- * a new name when that configuration changes. Names must also be unique
89
- * across independent ledgers sharing a BigQuery project.
90
- */
91
- name: string;
92
- projectId?: string;
93
- datasetId: string;
94
- rowsTableId: string;
95
- revisionsTableId: string;
96
- /**
97
- * Dataset location, so jobs run in the dataset's region. Set it for any dataset outside the US and EU
98
- * multi-regions: BigQuery answers a job lookup without the right location with 404, and the sink then
99
- * cannot find the jobs it created.
100
- */
101
- location?: string;
102
- /** Restrict the sink to one account; omit for the deployment-wide feed. */
103
- account_id?: string;
104
- /**
105
- * Map one verified report row to the adopter's columns. The sink always adds
106
- * `reporting_revision_id`, `reporting_obligation_id`, `account_id`,
107
- * `revision_number`, `finality`, `period_date` (the period start's calendar date in its
108
- * `source_timezone`, AdCP's `YYYY-MM-DD`; the batch fails if it cannot be computed) and
109
- * `ordinal`. Default: the
110
- * row as a `row` JSON column.
111
- */
112
- mapRow?(row: Record<string, unknown>, context: ReportingWarehouseRowContextV1): Record<string, unknown>;
113
- /** Revisions per batch. Default 200. */
114
- maxRevisionsPerBatch?: number;
115
- /**
116
- * @deprecated Has no effect, and the sink warns when it is set. The official
117
- * client submits a local-file load by uploading a job resource whose
118
- * `configuration.load` is built from the load options, and offers no way to
119
- * set `configuration.labels`; BigQuery silently drops `labels` found inside
120
- * `configuration.load`. For cost attribution, filter
121
- * `INFORMATION_SCHEMA.JOBS` on `destination_table` or on the `adcp_rr_`
122
- * job ID prefix instead.
123
- */
124
- labels?: Readonly<Record<string, string>>;
125
- /**
126
- * Base deadline for one run's work on one load. Default 10 minutes. It bounds
127
- * how long a run uploads a file or waits for a running job; it does not bound
128
- * the job. BigQuery does not stop a load when the client gives up (a cancel
129
- * is accepted and the job finishes anyway), so the sink never cancels.
130
- * Before every submission it looks the deterministic job ID up in `projectId`
131
- * and `location`: a job that finished cleanly is accepted, a job that is
132
- * pending or running is waited for (polled within the deadline) instead of
133
- * being uploaded again, and only a missing job is uploaded. When the
134
- * deadline passes, the run rejects with the plan retained and nothing
135
- * advanced, and the next run checks the job again. Each such timeout doubles
136
- * that table's deadline for later runs (up to 6 hours, persisted with the
137
- * plan, and never changing the job ID), so an upload slower than the
138
- * deadline eventually gets enough time. Set it above your slowest expected
139
- * load to avoid the extra runs. Only a job that finished with an error
140
- * advances the attempt. A status check that times out is bounded by this base
141
- * deadline and does not grow it. This is a client-side deadline: BigQuery's
142
- * server-side `jobTimeoutMs` cannot be set on a local-file load through the
143
- * official client.
144
- */
145
- loadTimeoutMilliseconds?: number;
146
- }
147
- /**
148
- * @experimental Reliable Reporting storage surface: breaking changes may ship in minor releases. See https://github.com/adcontextprotocol/adcp-client/blob/main/docs/guides/REPORTING-STABILITY.md
149
- */
150
- export interface BigQueryReportingWarehouseSinkV1 {
151
- /**
152
- * Load at most one batch. Resolves with what was loaded; `idle` when no
153
- * revision changes were selected. Idle ticks can advance past other feed changes.
154
- * An overlapping run that loses its plan or cursor claim rejects. Retry
155
- * `runOnce()` to resume the current durable plan or committed cursor.
156
- *
157
- * `missing` lists revision IDs the change feed announced that no longer
158
- * exist in the ledger because their period was retired before this batch
159
- * ran. That is a data-loss signal: the sink fell behind retention (it was
160
- * down longer than `maxFeedHoldDays`, so retention stopped waiting for it)
161
- * and the warehouse lacks those revisions. Backfill them from another source
162
- * or accept the gap. The cursor still advances so the sink is not stuck.
163
- * Alert on a non-empty `missing`. After a crash-and-replay of a planned
164
- * batch, a listed revision may already have been loaded by the first attempt.
165
- */
166
- runOnce(options?: {
167
- signal?: AbortSignal;
168
- }): Promise<{
169
- idle: boolean;
170
- revisions: number;
171
- rows: number;
172
- missing: string[];
173
- }>;
174
- /**
175
- * Clear the sink's saved state so the next `runOnce()` starts again from the
176
- * oldest retained change, and unregister its feed consumer so the old
177
- * checkpoint stops holding back retention. This is the way out of a sink
178
- * that keeps rejecting with `CURSOR_EXPIRED`: a brand-new sink whose first
179
- * read lost a startup race with pruning, or a sink that fell behind
180
- * retention and has been resynchronized from current revisions. Stop every
181
- * worker using this sink name first.
182
- *
183
- * It refuses while a batch plan is retained, because that batch's load jobs
184
- * may already have succeeded; pass `discardRetainedPlan: true` once you have
185
- * reconciled it against BigQuery. The warehouse is not touched: a sink that
186
- * already loaded history will load the retained revisions again, so empty
187
- * the destination tables first, or use a new sink name against new tables.
188
- * Each reset starts a new job ID generation, so reloaded batches submit
189
- * fresh BigQuery jobs instead of matching the finished jobs of the earlier
190
- * history. The sink never cancels a load, so stop every worker and let its
191
- * in-flight uploads and jobs finish before emptying the destination tables. Nothing holds change retention between `reset()` and the first
192
- * committed batch. If `reset()` rejects after clearing the sink's state
193
- * (the consumer could not be unregistered), call it again before restarting
194
- * workers; it is idempotent. Needs a store with `removeFeedConsumer`.
195
- * Resolves with whether a saved sink state existed.
196
- */
197
- reset(options?: {
198
- discardRetainedPlan?: boolean;
199
- }): Promise<{
200
- cleared: boolean;
201
- }>;
202
- /** DDL for the default rows and revisions tables (partitioned and clustered). */
203
- readonly defaultTablesSql: string;
204
- /** DDL for the reference `current_rows` view. */
205
- readonly currentRowsViewSql: string;
206
- }
207
- /**
208
- * @experimental Reliable Reporting storage surface: breaking changes may ship in minor releases. See https://github.com/adcontextprotocol/adcp-client/blob/main/docs/guides/REPORTING-STABILITY.md
209
- */
210
- export declare function createBigQueryReportingWarehouseSinkV1(options: CreateBigQueryReportingWarehouseSinkOptionsV1): BigQueryReportingWarehouseSinkV1;
211
- /**
212
- * How long one run may upload a file or wait for a running job: the configured
213
- * base doubled once per earlier timeout of that table's load, capped at 6 hours.
214
- *
215
- * @experimental Reliable Reporting storage surface: breaking changes may ship in minor releases. See https://github.com/adcontextprotocol/adcp-client/blob/main/docs/guides/REPORTING-STABILITY.md
216
- */
217
- export declare function reportingWarehouseLoadDeadlineV1(baseMilliseconds: number, timeouts: number): number;
218
- /**
219
- * Deterministic load job ID for one planned change-feed range.
220
- *
221
- * @experimental Reliable Reporting storage surface: breaking changes may ship in minor releases. See https://github.com/adcontextprotocol/adcp-client/blob/main/docs/guides/REPORTING-STABILITY.md
222
- */
223
- export declare function reportingWarehouseJobIdV1(name: string, from: string | null, to: string, generation?: number): string;
224
- interface WarehouseTablesV1 {
225
- projectId?: string;
226
- datasetId: string;
227
- rowsTableId: string;
228
- revisionsTableId: string;
229
- }
230
- /**
231
- * DDL for the default warehouse tables: partitioned by period date, clustered by account and revision.
232
- *
233
- * @experimental Reliable Reporting storage surface: breaking changes may ship in minor releases. See https://github.com/adcontextprotocol/adcp-client/blob/main/docs/guides/REPORTING-STABILITY.md
234
- */
235
- export declare function reportingWarehouseDefaultTablesSqlV1(tables: WarehouseTablesV1): string;
236
- /**
237
- * DDL for the reference `current_rows` view: only each obligation's current
238
- * revision (its official revision, otherwise its latest snapshot). Summing
239
- * cumulative snapshots across revisions double-counts; query this view.
240
- *
241
- * @experimental Reliable Reporting storage surface: breaking changes may ship in minor releases. See https://github.com/adcontextprotocol/adcp-client/blob/main/docs/guides/REPORTING-STABILITY.md
242
- */
243
- export declare function reportingWarehouseCurrentRowsViewSqlV1(tables: WarehouseTablesV1 & {
244
- viewId?: string;
245
- }): string;
246
- export {};