@adcp/sdk 16.0.0-beta.2 → 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 (248) hide show
  1. package/README.md +54 -0
  2. package/dist/lib/auth/oauth/diagnose.js +3 -11
  3. package/dist/lib/auth/oauth/diagnose.mjs +4 -12
  4. package/dist/lib/auth/oauth/diagnostics.d.mts +2 -1
  5. package/dist/lib/auth/oauth/diagnostics.d.ts +2 -1
  6. package/dist/lib/auth/oauth/diagnostics.js +8 -10
  7. package/dist/lib/auth/oauth/diagnostics.mjs +7 -10
  8. package/dist/lib/core/ConversationTypes.d.mts +8 -3
  9. package/dist/lib/core/ConversationTypes.d.ts +8 -3
  10. package/dist/lib/core/SingleAgentClient.d.mts +5 -3
  11. package/dist/lib/core/SingleAgentClient.d.ts +5 -3
  12. package/dist/lib/core/TaskExecutor.js +5 -1
  13. package/dist/lib/core/TaskExecutor.mjs +5 -1
  14. package/dist/lib/errors/index.d.mts +9 -4
  15. package/dist/lib/errors/index.d.ts +9 -4
  16. package/dist/lib/index.d.mts +3 -3
  17. package/dist/lib/index.d.ts +3 -3
  18. package/dist/lib/index.js +8 -0
  19. package/dist/lib/index.mjs +14 -2
  20. package/dist/lib/negotiation/types.d.mts +20 -39
  21. package/dist/lib/negotiation/types.d.ts +20 -39
  22. package/dist/lib/protocols/index.d.mts +60 -24
  23. package/dist/lib/protocols/index.d.ts +60 -24
  24. package/dist/lib/protocols/index.js +9 -4
  25. package/dist/lib/protocols/index.mjs +3 -0
  26. package/dist/lib/protocols/mcp-modern.js +1 -0
  27. package/dist/lib/protocols/mcp-modern.mjs +2 -1
  28. package/dist/lib/protocols/mcp.js +1 -0
  29. package/dist/lib/protocols/mcp.mjs +2 -1
  30. package/dist/lib/protocols/responseSizeLimit.d.mts +91 -5
  31. package/dist/lib/protocols/responseSizeLimit.d.ts +91 -5
  32. package/dist/lib/protocols/responseSizeLimit.js +195 -31
  33. package/dist/lib/protocols/responseSizeLimit.mjs +192 -31
  34. package/dist/lib/reporting/consumer-runtime.js +2 -1
  35. package/dist/lib/reporting/consumer-runtime.mjs +2 -1
  36. package/dist/lib/reporting/ledger/handler.js +50 -11
  37. package/dist/lib/reporting/ledger/handler.mjs +50 -12
  38. package/dist/lib/reporting/ledger/index.d.mts +17 -14
  39. package/dist/lib/reporting/ledger/index.d.ts +17 -14
  40. package/dist/lib/reporting/ledger/index.js +32 -20
  41. package/dist/lib/reporting/ledger/index.mjs +21 -10
  42. package/dist/lib/reporting/ledger/offering-validation.d.mts +9 -0
  43. package/dist/lib/reporting/ledger/offering-validation.d.ts +9 -0
  44. package/dist/lib/reporting/{gcs/bucket-policy.js → ledger/offering-validation.js} +9 -8
  45. package/dist/lib/reporting/ledger/offering-validation.mjs +8 -0
  46. package/dist/lib/reporting/ledger/receipts.d.mts +48 -0
  47. package/dist/lib/reporting/ledger/receipts.d.ts +48 -0
  48. package/dist/lib/reporting/ledger/receipts.js +186 -0
  49. package/dist/lib/reporting/ledger/receipts.mjs +161 -0
  50. package/dist/lib/reporting/ledger/status-ingest.js +3 -3
  51. package/dist/lib/reporting/ledger/status-ingest.mjs +4 -5
  52. package/dist/lib/reporting/ledger/types.d.mts +43 -0
  53. package/dist/lib/reporting/ledger/types.d.ts +43 -0
  54. package/dist/lib/reporting/ledger/types.js +31 -2
  55. package/dist/lib/reporting/ledger/types.mjs +26 -1
  56. package/dist/lib/reporting/pagination.d.mts +6 -0
  57. package/dist/lib/reporting/pagination.d.ts +6 -0
  58. package/dist/lib/reporting/{gcs/errors.js → pagination.js} +12 -17
  59. package/dist/lib/reporting/pagination.mjs +12 -0
  60. package/dist/lib/reporting/reconciliation.d.mts +1 -0
  61. package/dist/lib/reporting/reconciliation.d.ts +1 -0
  62. package/dist/lib/reporting/reconciliation.js +3 -2
  63. package/dist/lib/reporting/reconciliation.mjs +3 -2
  64. package/dist/lib/reporting/service/index.d.mts +79 -153
  65. package/dist/lib/reporting/service/index.d.ts +79 -153
  66. package/dist/lib/reporting/service/index.js +34 -491
  67. package/dist/lib/reporting/service/index.mjs +36 -510
  68. package/dist/lib/reporting/service/scheduler-support.d.mts +43 -0
  69. package/dist/lib/reporting/service/scheduler-support.d.ts +43 -0
  70. package/dist/lib/reporting/service/scheduler-support.js +125 -0
  71. package/dist/lib/reporting/service/scheduler-support.mjs +96 -0
  72. package/dist/lib/schemas-data/v2.5/_provenance.json +1 -1
  73. package/dist/lib/signing/canonicalize.d.mts +4 -0
  74. package/dist/lib/signing/canonicalize.d.ts +4 -0
  75. package/dist/lib/signing/canonicalize.js +14 -8
  76. package/dist/lib/signing/canonicalize.mjs +14 -8
  77. package/dist/lib/signing/content-digest.d.mts +8 -0
  78. package/dist/lib/signing/content-digest.d.ts +8 -0
  79. package/dist/lib/signing/content-digest.js +11 -5
  80. package/dist/lib/signing/content-digest.mjs +10 -5
  81. package/dist/lib/signing/crypto.d.mts +15 -0
  82. package/dist/lib/signing/crypto.d.ts +15 -0
  83. package/dist/lib/signing/crypto.js +75 -3
  84. package/dist/lib/signing/crypto.mjs +78 -3
  85. package/dist/lib/signing/server.d.mts +1 -1
  86. package/dist/lib/signing/server.d.ts +1 -1
  87. package/dist/lib/signing/server.js +2 -0
  88. package/dist/lib/signing/server.mjs +2 -1
  89. package/dist/lib/signing/signer.js +11 -14
  90. package/dist/lib/signing/signer.mjs +13 -16
  91. package/dist/lib/signing/testing.js +2 -6
  92. package/dist/lib/signing/testing.mjs +3 -7
  93. package/dist/lib/signing/verifier.js +2 -2
  94. package/dist/lib/signing/verifier.mjs +3 -3
  95. package/dist/lib/signing/web-bot-auth.js +122 -43
  96. package/dist/lib/signing/web-bot-auth.mjs +128 -44
  97. package/dist/lib/signing/webhook-verifier.js +2 -2
  98. package/dist/lib/signing/webhook-verifier.mjs +3 -3
  99. package/dist/lib/substitution/compile.js +2 -1
  100. package/dist/lib/substitution/compile.mjs +2 -1
  101. package/dist/lib/substitution/consent-macros.d.mts +4 -0
  102. package/dist/lib/substitution/consent-macros.d.ts +4 -0
  103. package/dist/lib/substitution/consent-macros.js +45 -0
  104. package/dist/lib/substitution/consent-macros.mjs +20 -0
  105. package/dist/lib/substitution/index.d.mts +1 -1
  106. package/dist/lib/substitution/index.d.ts +1 -1
  107. package/dist/lib/substitution/index.js +2 -0
  108. package/dist/lib/substitution/index.mjs +2 -1
  109. package/dist/lib/substitution/translate.d.mts +15 -2
  110. package/dist/lib/substitution/translate.d.ts +15 -2
  111. package/dist/lib/substitution/translate.js +148 -26
  112. package/dist/lib/substitution/translate.mjs +147 -26
  113. package/dist/lib/testing/client.js +2 -1
  114. package/dist/lib/testing/client.mjs +2 -1
  115. package/dist/lib/testing/scenarios/capabilities.js +1 -1
  116. package/dist/lib/testing/scenarios/capabilities.mjs +1 -1
  117. package/dist/lib/testing/storyboard/junit.js +16 -3
  118. package/dist/lib/testing/storyboard/junit.mjs +16 -3
  119. package/dist/lib/testing/storyboard/request-signing/builder.js +12 -14
  120. package/dist/lib/testing/storyboard/request-signing/builder.mjs +13 -15
  121. package/dist/lib/testing/storyboard/runner.js +94 -25
  122. package/dist/lib/testing/storyboard/runner.mjs +94 -25
  123. package/dist/lib/testing/storyboard/signer-grader/grader.js +2 -7
  124. package/dist/lib/testing/storyboard/signer-grader/grader.mjs +2 -7
  125. package/dist/lib/testing/storyboard/types.d.mts +6 -0
  126. package/dist/lib/testing/storyboard/types.d.ts +6 -0
  127. package/dist/lib/testing/storyboard/validations.d.mts +1 -1
  128. package/dist/lib/testing/storyboard/validations.d.ts +1 -1
  129. package/dist/lib/types/enums.generated.d.mts +3 -0
  130. package/dist/lib/types/enums.generated.d.ts +3 -0
  131. package/dist/lib/types/enums.generated.js +9 -0
  132. package/dist/lib/types/enums.generated.mjs +6 -0
  133. package/dist/lib/validation/schema-loader.js +25 -0
  134. package/dist/lib/validation/schema-loader.mjs +24 -0
  135. package/dist/lib/version.d.mts +3 -3
  136. package/dist/lib/version.d.ts +3 -3
  137. package/dist/lib/version.js +3 -3
  138. package/dist/lib/version.mjs +3 -3
  139. package/docs/TYPE-SUMMARY.md +28 -5
  140. package/docs/guides/DISCOVERY-CACHE-AND-SESSION-REUSE.md +3 -2
  141. package/docs/guides/REPORTING-GCS-FENCE.md +3 -3
  142. package/docs/guides/REPORTING-GCS-MANAGED.md +4 -4
  143. package/docs/guides/REPORTING-LEDGER-CUTOVER.md +7 -7
  144. package/docs/guides/REPORTING-LEDGER.md +107 -51
  145. package/docs/guides/REPORTING-OPERATIONS.md +66 -5
  146. package/docs/guides/REPORTING-STABILITY.md +36 -32
  147. package/docs/guides/UNIVERSAL-MACRO-COMPILATION.md +38 -0
  148. package/docs/guides/VALIDATE-YOUR-AGENT.md +12 -0
  149. package/docs/llms.txt +4 -3
  150. package/docs/migration-14.x-rc-worksheet.md +4 -7
  151. package/docs/migration-reporting-storage-package.md +186 -0
  152. package/examples/README.md +1 -1
  153. package/package.json +14 -78
  154. package/dist/lib/reporting/azure/index.d.mts +0 -31
  155. package/dist/lib/reporting/azure/index.d.ts +0 -31
  156. package/dist/lib/reporting/azure/index.js +0 -266
  157. package/dist/lib/reporting/azure/index.mjs +0 -249
  158. package/dist/lib/reporting/bigquery/index.d.mts +0 -246
  159. package/dist/lib/reporting/bigquery/index.d.ts +0 -246
  160. package/dist/lib/reporting/bigquery/index.js +0 -633
  161. package/dist/lib/reporting/bigquery/index.mjs +0 -594
  162. package/dist/lib/reporting/gcs/adapter.d.mts +0 -38
  163. package/dist/lib/reporting/gcs/adapter.d.ts +0 -38
  164. package/dist/lib/reporting/gcs/adapter.js +0 -342
  165. package/dist/lib/reporting/gcs/adapter.mjs +0 -325
  166. package/dist/lib/reporting/gcs/bucket-policy.d.mts +0 -3
  167. package/dist/lib/reporting/gcs/bucket-policy.d.ts +0 -3
  168. package/dist/lib/reporting/gcs/bucket-policy.mjs +0 -7
  169. package/dist/lib/reporting/gcs/errors.d.mts +0 -11
  170. package/dist/lib/reporting/gcs/errors.d.ts +0 -11
  171. package/dist/lib/reporting/gcs/errors.mjs +0 -16
  172. package/dist/lib/reporting/gcs/fence.d.mts +0 -41
  173. package/dist/lib/reporting/gcs/fence.d.ts +0 -41
  174. package/dist/lib/reporting/gcs/fence.js +0 -250
  175. package/dist/lib/reporting/gcs/fence.mjs +0 -230
  176. package/dist/lib/reporting/gcs/index.d.mts +0 -18
  177. package/dist/lib/reporting/gcs/index.d.ts +0 -18
  178. package/dist/lib/reporting/gcs/index.js +0 -44
  179. package/dist/lib/reporting/gcs/index.mjs +0 -14
  180. package/dist/lib/reporting/gcs/io.d.mts +0 -7
  181. package/dist/lib/reporting/gcs/io.d.ts +0 -7
  182. package/dist/lib/reporting/gcs/io.js +0 -95
  183. package/dist/lib/reporting/gcs/io.mjs +0 -69
  184. package/dist/lib/reporting/gcs/reader.d.mts +0 -67
  185. package/dist/lib/reporting/gcs/reader.d.ts +0 -67
  186. package/dist/lib/reporting/gcs/reader.js +0 -193
  187. package/dist/lib/reporting/gcs/reader.mjs +0 -169
  188. package/dist/lib/reporting/gcs/row-provider.d.mts +0 -39
  189. package/dist/lib/reporting/gcs/row-provider.d.ts +0 -39
  190. package/dist/lib/reporting/gcs/row-provider.js +0 -225
  191. package/dist/lib/reporting/gcs/row-provider.mjs +0 -208
  192. package/dist/lib/reporting/gcs/validation.d.mts +0 -5
  193. package/dist/lib/reporting/gcs/validation.d.ts +0 -5
  194. package/dist/lib/reporting/gcs/validation.js +0 -49
  195. package/dist/lib/reporting/gcs/validation.mjs +0 -25
  196. package/dist/lib/reporting/ledger/change-feed.d.mts +0 -69
  197. package/dist/lib/reporting/ledger/change-feed.d.ts +0 -69
  198. package/dist/lib/reporting/ledger/change-feed.js +0 -107
  199. package/dist/lib/reporting/ledger/change-feed.mjs +0 -80
  200. package/dist/lib/reporting/ledger/managed-postgres.d.mts +0 -293
  201. package/dist/lib/reporting/ledger/managed-postgres.d.ts +0 -293
  202. package/dist/lib/reporting/ledger/managed-postgres.js +0 -2346
  203. package/dist/lib/reporting/ledger/managed-postgres.mjs +0 -2332
  204. package/dist/lib/reporting/ledger/managed-router.d.mts +0 -148
  205. package/dist/lib/reporting/ledger/managed-router.d.ts +0 -148
  206. package/dist/lib/reporting/ledger/managed-router.js +0 -280
  207. package/dist/lib/reporting/ledger/managed-router.mjs +0 -258
  208. package/dist/lib/reporting/ledger/managed.d.mts +0 -535
  209. package/dist/lib/reporting/ledger/managed.d.ts +0 -535
  210. package/dist/lib/reporting/ledger/managed.js +0 -761
  211. package/dist/lib/reporting/ledger/managed.mjs +0 -729
  212. package/dist/lib/reporting/ledger/notification-activity.d.mts +0 -332
  213. package/dist/lib/reporting/ledger/notification-activity.d.ts +0 -332
  214. package/dist/lib/reporting/ledger/notification-activity.js +0 -1366
  215. package/dist/lib/reporting/ledger/notification-activity.mjs +0 -1337
  216. package/dist/lib/reporting/ledger/object-writes.d.mts +0 -128
  217. package/dist/lib/reporting/ledger/object-writes.d.ts +0 -128
  218. package/dist/lib/reporting/ledger/object-writes.js +0 -147
  219. package/dist/lib/reporting/ledger/object-writes.mjs +0 -114
  220. package/dist/lib/reporting/ledger/postgres.d.mts +0 -689
  221. package/dist/lib/reporting/ledger/postgres.d.ts +0 -689
  222. package/dist/lib/reporting/ledger/postgres.js +0 -4462
  223. package/dist/lib/reporting/ledger/postgres.mjs +0 -4462
  224. package/dist/lib/reporting/ledger/row-storage-migration.d.mts +0 -59
  225. package/dist/lib/reporting/ledger/row-storage-migration.d.ts +0 -59
  226. package/dist/lib/reporting/ledger/row-storage-migration.js +0 -365
  227. package/dist/lib/reporting/ledger/row-storage-migration.mjs +0 -339
  228. package/dist/lib/reporting/ledger/row-storage-object.d.mts +0 -203
  229. package/dist/lib/reporting/ledger/row-storage-object.d.ts +0 -203
  230. package/dist/lib/reporting/ledger/row-storage-object.js +0 -379
  231. package/dist/lib/reporting/ledger/row-storage-object.mjs +0 -335
  232. package/dist/lib/reporting/ledger/row-storage-provider-io.d.mts +0 -44
  233. package/dist/lib/reporting/ledger/row-storage-provider-io.d.ts +0 -44
  234. package/dist/lib/reporting/ledger/row-storage-provider-io.js +0 -142
  235. package/dist/lib/reporting/ledger/row-storage-provider-io.mjs +0 -111
  236. package/dist/lib/reporting/ledger/row-storage.d.mts +0 -316
  237. package/dist/lib/reporting/ledger/row-storage.d.ts +0 -316
  238. package/dist/lib/reporting/ledger/row-storage.js +0 -812
  239. package/dist/lib/reporting/ledger/row-storage.mjs +0 -802
  240. package/dist/lib/reporting/s3/index.d.mts +0 -34
  241. package/dist/lib/reporting/s3/index.d.ts +0 -34
  242. package/dist/lib/reporting/s3/index.js +0 -347
  243. package/dist/lib/reporting/s3/index.mjs +0 -340
  244. package/dist/lib/reporting/service/maintenance.d.mts +0 -148
  245. package/dist/lib/reporting/service/maintenance.d.ts +0 -148
  246. package/dist/lib/reporting/service/maintenance.js +0 -185
  247. package/dist/lib/reporting/service/maintenance.mjs +0 -159
  248. package/examples/reliable-reporting-service/README.md +0 -169
@@ -1,266 +0,0 @@
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 azure_exports = {};
20
- __export(azure_exports, {
21
- createAzureBlobReportingRowObjectProviderV1: () => createAzureBlobReportingRowObjectProviderV1
22
- });
23
- module.exports = __toCommonJS(azure_exports);
24
- var import_node_crypto = require("node:crypto");
25
- var import_row_storage_errors = require('../ledger/row-storage-errors.js');
26
- var import_row_storage_provider_io = require('../ledger/row-storage-provider-io.js');
27
- const ACCOUNT = /^[a-z0-9]{3,24}$/;
28
- const CONTAINER = /^[a-z0-9](?:[a-z0-9]|-(?=[a-z0-9])){2,62}$/;
29
- const VERSION_ID = /^[0-9A-Za-z:.+-]{1,64}$/;
30
- function statusOf(error) {
31
- const status = Number(error?.statusCode);
32
- return Number.isInteger(status) ? status : void 0;
33
- }
34
- function codeOf(error) {
35
- const value = error?.code ?? error?.details?.errorCode;
36
- return typeof value === "string" ? value : "";
37
- }
38
- const isConflict = (error) => statusOf(error) === 409 || statusOf(error) === 412 || codeOf(error) === "BlobAlreadyExists";
39
- const isMissing = (error) => statusOf(error) === 404 || statusOf(error) === 412;
40
- const isForbidden = (error) => statusOf(error) === 401 || statusOf(error) === 403;
41
- function versionOf(response) {
42
- const id = response.versionId;
43
- if (typeof id !== "string" || !VERSION_ID.test(id)) {
44
- throw new import_row_storage_errors.ReportingRowStoreError(
45
- "UNSAFE_BINDING",
46
- "store returned no blob versionId; blob versioning must be enabled on the storage account so deletes are fenced to one write"
47
- );
48
- }
49
- return id;
50
- }
51
- function servedVersion(response, versionId) {
52
- return response.versionId === versionId;
53
- }
54
- function metadataOf(metadata) {
55
- const result = {};
56
- for (const [name, value] of Object.entries(metadata)) {
57
- const identifier = name.replace(/[^A-Za-z0-9_]/g, "_");
58
- result[/^[A-Za-z_]/.test(identifier) ? identifier : `_${identifier}`] = value;
59
- }
60
- return result;
61
- }
62
- function createAzureBlobReportingRowObjectProviderV1(options) {
63
- if (!options || typeof options !== "object") {
64
- throw new import_row_storage_errors.ReportingRowStoreError("INVALID_INPUT", "Azure Blob row provider options are required");
65
- }
66
- const clients = (0, import_row_storage_provider_io.reportingRowClientMap)(options.clients);
67
- const isClient = (value) => !!value && typeof value === "object" && typeof value.getContainerClient === "function" && typeof value.accountName === "string";
68
- if (options.client !== void 0 && !isClient(options.client) || [...clients.values()].some((client) => !isClient(client)) || options.client === void 0 && clients.size === 0) {
69
- throw new import_row_storage_errors.ReportingRowStoreError("INVALID_INPUT", "inject an official BlobServiceClient as client or clients");
70
- }
71
- const validateLocation = (location) => {
72
- (0, import_row_storage_provider_io.assertReportingRowLocationKeys)(location, ["account", "container"]);
73
- if (!ACCOUNT.test(location.account)) {
74
- throw new import_row_storage_errors.ReportingRowStoreError("INVALID_INPUT", "Azure storage account name is invalid");
75
- }
76
- if (!CONTAINER.test(location.container)) {
77
- throw new import_row_storage_errors.ReportingRowStoreError("INVALID_INPUT", "Azure container name is invalid");
78
- }
79
- };
80
- const containerFor = (input) => {
81
- validateLocation(input.location);
82
- const client = (0, import_row_storage_provider_io.selectReportingRowClient)(options.client, clients, input.credentialRef);
83
- if (client.accountName !== input.location.account) {
84
- throw new import_row_storage_errors.ReportingRowStoreError("UNSAFE_BINDING", "client does not belong to the binding account");
85
- }
86
- return client.getContainerClient(input.location.container);
87
- };
88
- const blobFor = (input) => {
89
- if (typeof input.objectRef !== "string" || input.objectRef.length === 0 || input.objectRef.length > 1024) {
90
- throw new import_row_storage_errors.ReportingRowStoreError("INVALID_INPUT", "object key is invalid");
91
- }
92
- return containerFor(input).getBlockBlobClient(input.objectRef);
93
- };
94
- const pinned = (blob, nativeVersionRef) => typeof nativeVersionRef === "string" && VERSION_ID.test(nativeVersionRef) ? { blob: blob.withVersion(nativeVersionRef), versionId: nativeVersionRef } : null;
95
- async function assertCreateOnlyEnforced(container, prefix, signal) {
96
- const blob = container.getBlockBlobClient(`${prefix}/.adcp-probe/${(0, import_node_crypto.randomUUID)()}`);
97
- const versionIds = [];
98
- let written = false;
99
- const upload = async (body) => {
100
- const bytes = Buffer.from(body);
101
- const response = await blob.upload(bytes, bytes.byteLength, {
102
- conditions: { ifNoneMatch: "*" },
103
- blobHTTPHeaders: { blobContentType: "application/x-ndjson", blobCacheControl: "no-store" },
104
- abortSignal: signal
105
- });
106
- written = true;
107
- if (response.versionId) versionIds.push(response.versionId);
108
- versionOf(response);
109
- };
110
- try {
111
- await upload('{"probe":1}\n');
112
- try {
113
- await upload('{"probe":2}\n');
114
- } catch (error) {
115
- if (isConflict(error)) return;
116
- throw error;
117
- }
118
- throw new import_row_storage_errors.ReportingRowStoreError("UNSAFE_BINDING", "store ignores If-None-Match and replaces blobs");
119
- } finally {
120
- if (written && !signal.aborted) {
121
- await blob.delete({ abortSignal: signal }).catch(() => void 0);
122
- for (const versionId of versionIds) {
123
- if (signal.aborted) break;
124
- await blob.withVersion(versionId).delete({ abortSignal: signal }).catch(() => void 0);
125
- }
126
- }
127
- }
128
- }
129
- return {
130
- name: "azure_blob",
131
- rangedReads: true,
132
- validateLocation,
133
- probe(input, context) {
134
- return (0, import_row_storage_provider_io.runReportingRowProviderOperation)(context.signal, async () => {
135
- const container = containerFor(input);
136
- let properties;
137
- try {
138
- properties = await container.getProperties({ abortSignal: context.signal });
139
- } catch (error) {
140
- if (statusOf(error) === 404) throw new import_row_storage_errors.ReportingRowStoreError("UNSAFE_BINDING", "container does not exist");
141
- if (isForbidden(error)) throw new import_row_storage_errors.ReportingRowStoreError("UNSAFE_BINDING", "container is not accessible");
142
- throw error;
143
- }
144
- if (properties.blobPublicAccess) {
145
- throw new import_row_storage_errors.ReportingRowStoreError("UNSAFE_BINDING", "container allows anonymous read access");
146
- }
147
- await assertCreateOnlyEnforced(container, input.prefix, context.signal);
148
- });
149
- },
150
- putIfAbsent(input, context) {
151
- return (0, import_row_storage_provider_io.runReportingRowProviderOperation)(context.signal, async () => {
152
- const blob = blobFor(input);
153
- const bytes = Buffer.from(input.bytes);
154
- try {
155
- const response = await blob.upload(bytes, bytes.byteLength, {
156
- conditions: { ifNoneMatch: "*" },
157
- blobHTTPHeaders: { blobContentType: input.contentType, blobCacheControl: "no-store" },
158
- metadata: metadataOf(input.metadata),
159
- abortSignal: context.signal
160
- });
161
- return { created: true, nativeVersionRef: versionOf(response) };
162
- } catch (error) {
163
- if (!isConflict(error)) throw error;
164
- }
165
- const existing = await blob.getProperties({ abortSignal: context.signal });
166
- return { created: false, nativeVersionRef: versionOf(existing) };
167
- });
168
- },
169
- get(input, context) {
170
- return (0, import_row_storage_provider_io.runReportingRowProviderOperation)(context.signal, async () => {
171
- const blob = blobFor(input);
172
- (0, import_row_storage_provider_io.assertReportingRowReadBounds)(input);
173
- const target = pinned(blob, input.nativeVersionRef);
174
- if (target === null) return null;
175
- try {
176
- if (input.range?.length === 0) {
177
- const properties = await target.blob.getProperties({ abortSignal: context.signal });
178
- if (!servedVersion(properties, target.versionId)) return null;
179
- if (input.range.offset > Number(properties.contentLength ?? 0)) {
180
- throw new import_row_storage_errors.ReportingRowStoreError("ROWS_INTEGRITY_FAILED", "requested range exceeds the stored object");
181
- }
182
- return Buffer.alloc(0);
183
- }
184
- const response = await target.blob.download(input.range?.offset ?? 0, input.range?.length, {
185
- abortSignal: context.signal
186
- });
187
- const body = response.readableStreamBody;
188
- if (!body || typeof body[Symbol.asyncIterator] !== "function") {
189
- throw new import_row_storage_errors.ReportingRowStoreError("PROVIDER_UNAVAILABLE", "blob body is not a stream");
190
- }
191
- if (!servedVersion(response, target.versionId)) {
192
- body.destroy?.();
193
- return null;
194
- }
195
- if (typeof response.contentLength === "number" && response.contentLength > input.maxBytes) {
196
- body.destroy?.();
197
- throw new import_row_storage_errors.ReportingRowStoreError("ROWS_INTEGRITY_FAILED", "stored object exceeds its recorded size");
198
- }
199
- return await (0, import_row_storage_provider_io.readReportingRowStream)(body, input.maxBytes, context.signal);
200
- } catch (error) {
201
- if (isMissing(error)) return null;
202
- if (statusOf(error) === 400) return null;
203
- if (statusOf(error) === 416 || codeOf(error) === "InvalidRange") {
204
- throw new import_row_storage_errors.ReportingRowStoreError("ROWS_INTEGRITY_FAILED", "requested range exceeds the stored object");
205
- }
206
- throw error;
207
- }
208
- });
209
- },
210
- stat(input, context) {
211
- return (0, import_row_storage_provider_io.runReportingRowProviderOperation)(context.signal, async () => {
212
- const blob = blobFor(input);
213
- const target = pinned(blob, input.nativeVersionRef);
214
- if (target === null) return null;
215
- try {
216
- const properties = await target.blob.getProperties({ abortSignal: context.signal });
217
- if (!servedVersion(properties, target.versionId)) return null;
218
- const size = properties.contentLength;
219
- if (typeof size !== "number" || !Number.isSafeInteger(size) || size < 0) {
220
- throw new import_row_storage_errors.ReportingRowStoreError("PROVIDER_UNAVAILABLE", "blob metadata is malformed");
221
- }
222
- return { nativeVersionRef: target.versionId, sizeBytes: size };
223
- } catch (error) {
224
- if (isMissing(error) || statusOf(error) === 400) return null;
225
- throw error;
226
- }
227
- });
228
- },
229
- delete(input, context) {
230
- return (0, import_row_storage_provider_io.runReportingRowProviderOperation)(context.signal, async () => {
231
- const blob = blobFor(input);
232
- const target = pinned(blob, input.nativeVersionRef);
233
- if (target === null) return "absent";
234
- const signal = context.signal;
235
- try {
236
- const recorded = await target.blob.getProperties({ abortSignal: signal });
237
- if (recorded.versionId !== target.versionId) return "absent";
238
- } catch (error) {
239
- if (isMissing(error) || statusOf(error) === 400) return "absent";
240
- throw error;
241
- }
242
- let deletedCurrent = false;
243
- try {
244
- const current = await blob.getProperties({ abortSignal: signal });
245
- if (current.versionId === target.versionId && current.etag) {
246
- await blob.delete({ conditions: { ifMatch: current.etag }, abortSignal: signal });
247
- deletedCurrent = true;
248
- }
249
- } catch (error) {
250
- if (!isMissing(error)) throw error;
251
- }
252
- try {
253
- await target.blob.delete({ abortSignal: signal });
254
- return "deleted";
255
- } catch (error) {
256
- if (isMissing(error) || statusOf(error) === 400) return deletedCurrent ? "deleted" : "absent";
257
- throw error;
258
- }
259
- });
260
- }
261
- };
262
- }
263
- // Annotate the CommonJS export names for ESM import in node:
264
- 0 && (module.exports = {
265
- createAzureBlobReportingRowObjectProviderV1
266
- });
@@ -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
- };