@adcp/sdk 14.4.0 → 15.2.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 (188) hide show
  1. package/bin/adcp-grade.js +46 -2
  2. package/bin/adcp.js +13 -3
  3. package/dist/lib/auth/oauth/ClientCredentialsFlow.js +4 -1
  4. package/dist/lib/auth/oauth/ClientCredentialsFlow.mjs +4 -1
  5. package/dist/lib/auth/oauth/MCPOAuthProvider.d.mts +19 -6
  6. package/dist/lib/auth/oauth/MCPOAuthProvider.d.ts +19 -6
  7. package/dist/lib/auth/oauth/MCPOAuthProvider.js +95 -30
  8. package/dist/lib/auth/oauth/MCPOAuthProvider.mjs +96 -30
  9. package/dist/lib/auth/oauth/NonInteractiveFlowHandler.d.mts +1 -1
  10. package/dist/lib/auth/oauth/NonInteractiveFlowHandler.d.ts +1 -1
  11. package/dist/lib/auth/oauth/NonInteractiveFlowHandler.js +1 -1
  12. package/dist/lib/auth/oauth/NonInteractiveFlowHandler.mjs +1 -1
  13. package/dist/lib/auth/oauth/client-credentials-schema.d.mts +17 -0
  14. package/dist/lib/auth/oauth/client-credentials-schema.d.ts +17 -0
  15. package/dist/lib/auth/oauth/client-credentials-schema.js +37 -0
  16. package/dist/lib/auth/oauth/client-credentials-schema.mjs +13 -0
  17. package/dist/lib/auth/oauth/file-storage.d.mts +3 -3
  18. package/dist/lib/auth/oauth/file-storage.d.ts +3 -3
  19. package/dist/lib/auth/oauth/file-storage.js +12 -5
  20. package/dist/lib/auth/oauth/file-storage.mjs +12 -5
  21. package/dist/lib/auth/oauth/index.d.mts +10 -6
  22. package/dist/lib/auth/oauth/index.d.ts +10 -6
  23. package/dist/lib/auth/oauth/index.js +9 -3
  24. package/dist/lib/auth/oauth/index.mjs +8 -3
  25. package/dist/lib/auth/oauth/types.d.mts +9 -2
  26. package/dist/lib/auth/oauth/types.d.ts +9 -2
  27. package/dist/lib/auth/oauth/types.js +3 -2
  28. package/dist/lib/auth/oauth/types.mjs +3 -2
  29. package/dist/lib/auth/oauth/web-flow.d.mts +2 -0
  30. package/dist/lib/auth/oauth/web-flow.d.ts +2 -0
  31. package/dist/lib/auth/oauth/web-flow.js +42 -9
  32. package/dist/lib/auth/oauth/web-flow.mjs +42 -9
  33. package/dist/lib/canonical-references/index.d.mts +19 -1
  34. package/dist/lib/canonical-references/index.d.ts +19 -1
  35. package/dist/lib/canonical-references/index.js +81 -9
  36. package/dist/lib/canonical-references/index.mjs +80 -9
  37. package/dist/lib/client/core.d.mts +1 -0
  38. package/dist/lib/client/core.d.ts +1 -0
  39. package/dist/lib/core/AgentClient.d.mts +9 -1
  40. package/dist/lib/core/AgentClient.d.ts +9 -1
  41. package/dist/lib/core/AgentClient.js +10 -0
  42. package/dist/lib/core/AgentClient.mjs +10 -0
  43. package/dist/lib/core/SingleAgentClient.d.mts +13 -2
  44. package/dist/lib/core/SingleAgentClient.d.ts +13 -2
  45. package/dist/lib/core/SingleAgentClient.js +23 -5
  46. package/dist/lib/core/SingleAgentClient.mjs +23 -5
  47. package/dist/lib/index.d.mts +2 -2
  48. package/dist/lib/index.d.ts +2 -2
  49. package/dist/lib/index.js +2 -0
  50. package/dist/lib/index.mjs +3 -1
  51. package/dist/lib/reporting/gcs/adapter.d.mts +31 -0
  52. package/dist/lib/reporting/gcs/adapter.d.ts +31 -0
  53. package/dist/lib/reporting/gcs/adapter.js +342 -0
  54. package/dist/lib/reporting/gcs/adapter.mjs +325 -0
  55. package/dist/lib/reporting/gcs/bucket-policy.d.mts +3 -0
  56. package/dist/lib/reporting/gcs/bucket-policy.d.ts +3 -0
  57. package/dist/lib/reporting/gcs/bucket-policy.js +31 -0
  58. package/dist/lib/reporting/gcs/bucket-policy.mjs +7 -0
  59. package/dist/lib/reporting/gcs/errors.d.mts +5 -0
  60. package/dist/lib/reporting/gcs/errors.d.ts +5 -0
  61. package/dist/lib/reporting/gcs/errors.js +41 -0
  62. package/dist/lib/reporting/gcs/errors.mjs +16 -0
  63. package/dist/lib/reporting/gcs/fence.d.mts +36 -0
  64. package/dist/lib/reporting/gcs/fence.d.ts +36 -0
  65. package/dist/lib/reporting/gcs/fence.js +250 -0
  66. package/dist/lib/reporting/gcs/fence.mjs +230 -0
  67. package/dist/lib/reporting/gcs/index.d.mts +7 -0
  68. package/dist/lib/reporting/gcs/index.d.ts +7 -0
  69. package/dist/lib/reporting/gcs/index.js +41 -0
  70. package/dist/lib/reporting/gcs/index.mjs +12 -0
  71. package/dist/lib/reporting/gcs/io.d.mts +7 -0
  72. package/dist/lib/reporting/gcs/io.d.ts +7 -0
  73. package/dist/lib/reporting/gcs/io.js +95 -0
  74. package/dist/lib/reporting/gcs/io.mjs +69 -0
  75. package/dist/lib/reporting/gcs/reader.d.mts +43 -0
  76. package/dist/lib/reporting/gcs/reader.d.ts +43 -0
  77. package/dist/lib/reporting/gcs/reader.js +193 -0
  78. package/dist/lib/reporting/gcs/reader.mjs +169 -0
  79. package/dist/lib/reporting/gcs/validation.d.mts +5 -0
  80. package/dist/lib/reporting/gcs/validation.d.ts +5 -0
  81. package/dist/lib/reporting/gcs/validation.js +49 -0
  82. package/dist/lib/reporting/gcs/validation.mjs +25 -0
  83. package/dist/lib/reporting/ledger/handler.d.mts +1 -0
  84. package/dist/lib/reporting/ledger/handler.d.ts +1 -0
  85. package/dist/lib/reporting/ledger/index.d.mts +1 -0
  86. package/dist/lib/reporting/ledger/index.d.ts +1 -0
  87. package/dist/lib/reporting/ledger/index.js +2 -0
  88. package/dist/lib/reporting/ledger/index.mjs +1 -0
  89. package/dist/lib/reporting/ledger/managed-postgres.d.mts +16 -1
  90. package/dist/lib/reporting/ledger/managed-postgres.d.ts +16 -1
  91. package/dist/lib/reporting/ledger/managed-postgres.js +243 -2
  92. package/dist/lib/reporting/ledger/managed-postgres.mjs +248 -2
  93. package/dist/lib/reporting/ledger/object-writes.d.mts +69 -0
  94. package/dist/lib/reporting/ledger/object-writes.d.ts +69 -0
  95. package/dist/lib/reporting/ledger/object-writes.js +147 -0
  96. package/dist/lib/reporting/ledger/object-writes.mjs +114 -0
  97. package/dist/lib/schemas/index.d.mts +2 -0
  98. package/dist/lib/schemas/index.d.ts +2 -0
  99. package/dist/lib/schemas/index.js +3 -0
  100. package/dist/lib/schemas/index.mjs +2 -0
  101. package/dist/lib/schemas-data/v2.5/_provenance.json +1 -1
  102. package/dist/lib/server/a2a-adapter.d.mts +50 -1
  103. package/dist/lib/server/a2a-adapter.d.ts +50 -1
  104. package/dist/lib/server/a2a-adapter.js +230 -7
  105. package/dist/lib/server/a2a-adapter.mjs +237 -7
  106. package/dist/lib/server/auth-signature.d.mts +84 -46
  107. package/dist/lib/server/auth-signature.d.ts +84 -46
  108. package/dist/lib/server/auth-signature.js +48 -14
  109. package/dist/lib/server/auth-signature.mjs +58 -15
  110. package/dist/lib/server/create-adcp-server.js +5 -16
  111. package/dist/lib/server/create-adcp-server.mjs +5 -16
  112. package/dist/lib/server/index.d.mts +1 -1
  113. package/dist/lib/server/index.d.ts +1 -1
  114. package/dist/lib/server/index.js +2 -0
  115. package/dist/lib/server/index.mjs +3 -1
  116. package/dist/lib/signing/agent-fetch.js +3 -33
  117. package/dist/lib/signing/agent-fetch.mjs +3 -33
  118. package/dist/lib/signing/middleware.d.mts +9 -1
  119. package/dist/lib/signing/middleware.d.ts +9 -1
  120. package/dist/lib/signing/operation-resolution.d.mts +37 -0
  121. package/dist/lib/signing/operation-resolution.d.ts +37 -0
  122. package/dist/lib/signing/operation-resolution.js +154 -0
  123. package/dist/lib/signing/operation-resolution.mjs +125 -0
  124. package/dist/lib/signing/postgres-replay-store.d.mts +1 -1
  125. package/dist/lib/signing/postgres-replay-store.d.ts +1 -1
  126. package/dist/lib/signing/redis-replay-store.d.mts +1 -1
  127. package/dist/lib/signing/redis-replay-store.d.ts +1 -1
  128. package/dist/lib/signing/server.d.mts +1 -0
  129. package/dist/lib/signing/server.d.ts +1 -0
  130. package/dist/lib/signing/server.js +7 -0
  131. package/dist/lib/signing/server.mjs +8 -0
  132. package/dist/lib/signing/verifier.d.mts +36 -1
  133. package/dist/lib/signing/verifier.d.ts +36 -1
  134. package/dist/lib/signing/verifier.js +66 -34
  135. package/dist/lib/signing/verifier.mjs +61 -34
  136. package/dist/lib/testing/client.js +8 -3
  137. package/dist/lib/testing/client.mjs +8 -3
  138. package/dist/lib/testing/storyboard/request-signing/a2a-dispatch.d.mts +12 -0
  139. package/dist/lib/testing/storyboard/request-signing/a2a-dispatch.d.ts +12 -0
  140. package/dist/lib/testing/storyboard/request-signing/a2a-dispatch.js +29 -2
  141. package/dist/lib/testing/storyboard/request-signing/a2a-dispatch.mjs +27 -1
  142. package/dist/lib/testing/storyboard/request-signing/a2a-operation-resolution.d.mts +61 -0
  143. package/dist/lib/testing/storyboard/request-signing/a2a-operation-resolution.d.ts +61 -0
  144. package/dist/lib/testing/storyboard/request-signing/a2a-operation-resolution.js +298 -0
  145. package/dist/lib/testing/storyboard/request-signing/a2a-operation-resolution.mjs +276 -0
  146. package/dist/lib/testing/storyboard/request-signing/grader.d.mts +31 -1
  147. package/dist/lib/testing/storyboard/request-signing/grader.d.ts +31 -1
  148. package/dist/lib/testing/storyboard/request-signing/grader.js +11 -0
  149. package/dist/lib/testing/storyboard/request-signing/grader.mjs +11 -0
  150. package/dist/lib/testing/storyboard/request-signing/index.d.mts +5 -4
  151. package/dist/lib/testing/storyboard/request-signing/index.d.ts +5 -4
  152. package/dist/lib/testing/storyboard/request-signing/index.js +13 -0
  153. package/dist/lib/testing/storyboard/request-signing/index.mjs +18 -2
  154. package/dist/lib/testing/storyboard/request-signing/types.d.mts +43 -0
  155. package/dist/lib/testing/storyboard/request-signing/types.d.ts +43 -0
  156. package/dist/lib/testing/storyboard/request-signing/types.js +3 -0
  157. package/dist/lib/testing/storyboard/request-signing/types.mjs +2 -0
  158. package/dist/lib/testing/storyboard/request-signing/vector-loader.d.mts +42 -1
  159. package/dist/lib/testing/storyboard/request-signing/vector-loader.d.ts +42 -1
  160. package/dist/lib/testing/storyboard/request-signing/vector-loader.js +100 -1
  161. package/dist/lib/testing/storyboard/request-signing/vector-loader.mjs +104 -3
  162. package/dist/lib/testing/storyboard/validations.d.mts +1 -1
  163. package/dist/lib/testing/storyboard/validations.d.ts +1 -1
  164. package/dist/lib/testing/types.d.mts +10 -1
  165. package/dist/lib/testing/types.d.ts +10 -1
  166. package/dist/lib/version.d.mts +3 -3
  167. package/dist/lib/version.d.ts +3 -3
  168. package/dist/lib/version.js +3 -3
  169. package/dist/lib/version.mjs +3 -3
  170. package/docs/TYPE-SUMMARY.md +2 -2
  171. package/docs/ZOD-SCHEMAS.md +19 -0
  172. package/docs/guides/BUILD-AN-AGENT.md +9 -4
  173. package/docs/guides/CREATIVE-DELIVERY.md +34 -0
  174. package/docs/guides/OAUTH-ISSUER-BINDING.md +46 -0
  175. package/docs/guides/REPORTING-GCS-FENCE.md +52 -0
  176. package/docs/guides/REPORTING-GCS-MANAGED.md +56 -0
  177. package/docs/guides/REPORTING-OPERATIONS.md +4 -0
  178. package/docs/guides/SIGNING-GUIDE.md +20 -6
  179. package/docs/guides/VALIDATE-YOUR-AGENT.md +4 -0
  180. package/docs/guides/WEB-OAUTH.md +58 -163
  181. package/docs/guides/account-resolution.md +1 -1
  182. package/docs/llms.txt +2 -2
  183. package/docs/migration-14.0-to-14.1.md +1 -1
  184. package/docs/migration-14.x-rc-worksheet.md +8 -7
  185. package/docs/migration-buyer-agent-registry.md +1 -1
  186. package/docs/migration-oauth-issuer-bindings.md +14 -79
  187. package/package.json +19 -1
  188. package/skills/build-seller-agent/specialisms/signed-requests.md +2 -0
@@ -0,0 +1,230 @@
1
+ import { createHash } from "node:crypto";
2
+ import {
3
+ assertReportingObjectWriteScope,
4
+ reportingObjectWritePlanFingerprint,
5
+ reportingObjectWriteName,
6
+ reportingObjectWriteScopeKey
7
+ } from "../ledger/object-writes.mjs";
8
+ import { ReportingGcsFenceError, isReportingGcsFenceError } from "./errors.mjs";
9
+ import { activeGcsSignal as active, withGcsDeadline, readGcsBytes } from "./io.mjs";
10
+ import { assertGcsReportingBucketPolicy } from "./bucket-policy.mjs";
11
+ const hash = (bytes) => createHash("sha256").update(bytes).digest("hex");
12
+ const TOMBSTONE = "adcp_reporting_tombstone";
13
+ import { ReportingGcsFenceError as ReportingGcsFenceError2 } from "./errors.mjs";
14
+ function createGcsReportingObjectFenceV1(options) {
15
+ if (!options || typeof options.bucket !== "string" || !/^[a-z0-9][a-z0-9.-]{1,220}[a-z0-9]$/.test(options.bucket) || typeof options.namespace !== "string" || options.namespace.length < 1 || options.namespace.length > 255 || !options.storage || typeof options.storage.bucket !== "function" || !options.store)
16
+ throw new ReportingGcsFenceError("INVALID_INPUT");
17
+ const { storage, store, bucket: bucketName, namespace } = options;
18
+ const deadline = options.operationDeadlineMilliseconds ?? 6e4;
19
+ if (!Number.isSafeInteger(deadline) || deadline < 1 || deadline > 6e4)
20
+ throw new ReportingGcsFenceError("INVALID_INPUT");
21
+ const provider = { bucket: bucketName, namespace_key: hash(namespace) };
22
+ const status = (error, code) => !!error && typeof error === "object" && "code" in error && Number(error.code) === code;
23
+ const bounded = (work, signal) => withGcsDeadline(work, { signal, milliseconds: deadline });
24
+ async function probe(bucket, signal) {
25
+ active(signal);
26
+ try {
27
+ const [metadata] = await bucket.getMetadata();
28
+ active(signal);
29
+ try {
30
+ assertGcsReportingBucketPolicy(metadata);
31
+ } catch {
32
+ throw new ReportingGcsFenceError("UNSAFE_BUCKET");
33
+ }
34
+ } catch (error) {
35
+ active(signal);
36
+ if (isReportingGcsFenceError(error)) throw error;
37
+ throw new ReportingGcsFenceError("PROVIDER_UNAVAILABLE");
38
+ }
39
+ }
40
+ function assertScope(scope) {
41
+ try {
42
+ assertReportingObjectWriteScope(scope);
43
+ } catch {
44
+ throw new ReportingGcsFenceError("INVALID_INPUT");
45
+ }
46
+ }
47
+ function assertPlan(plan) {
48
+ try {
49
+ reportingObjectWritePlanFingerprint(plan);
50
+ } catch {
51
+ throw new ReportingGcsFenceError("INVALID_INPUT");
52
+ }
53
+ if (plan.provider.bucket !== bucketName || plan.provider.namespace_key !== provider.namespace_key)
54
+ throw new ReportingGcsFenceError("INVALID_INPUT");
55
+ }
56
+ async function register(scope, deliveryId, bodies, signal) {
57
+ assertScope(scope);
58
+ if (typeof deliveryId !== "string" || deliveryId.length < 1 || deliveryId.length > 255 || !Array.isArray(bodies) || bodies.length < 1 || bodies.length > 128 || bodies.some((b) => !(b instanceof Uint8Array) || b.byteLength > 64 * 1024 * 1024) || bodies.reduce((total, b) => total + b.byteLength, 0) > 64 * 1024 * 1024)
59
+ throw new ReportingGcsFenceError("INVALID_INPUT");
60
+ const scopeCopy = {
61
+ account_id: scope.account_id,
62
+ destination_ref: scope.destination_ref,
63
+ generation: scope.generation
64
+ };
65
+ const planId = hash(deliveryId);
66
+ const plan = {
67
+ ...scopeCopy,
68
+ provider: { ...provider },
69
+ plan_id: planId,
70
+ objects: bodies.map((b, i) => ({
71
+ bucket: bucketName,
72
+ object_name: reportingObjectWriteName(scopeCopy, provider, planId, i),
73
+ sha256: hash(b),
74
+ size_bytes: b.byteLength
75
+ }))
76
+ };
77
+ await probe(storage.bucket(bucketName), signal);
78
+ active(signal);
79
+ const registered = await store.registerObjectWritePlan(plan, { signal });
80
+ active(signal);
81
+ if (registered === "revoked") throw new ReportingGcsFenceError("REVOKED");
82
+ return plan;
83
+ }
84
+ async function write(input, index, inputBytes, signal) {
85
+ const plan = structuredClone(input);
86
+ assertPlan(plan);
87
+ const expected = plan.objects[index];
88
+ if (!Number.isInteger(index) || !expected || !(inputBytes instanceof Uint8Array))
89
+ throw new ReportingGcsFenceError("INVALID_INPUT");
90
+ if (inputBytes.byteLength !== expected.size_bytes) throw new ReportingGcsFenceError("CONTENT_CONFLICT");
91
+ const bytes = Buffer.from(inputBytes);
92
+ if (hash(bytes) !== expected.sha256) throw new ReportingGcsFenceError("CONTENT_CONFLICT");
93
+ active(signal);
94
+ const bucket = storage.bucket(bucketName);
95
+ await probe(bucket, signal);
96
+ active(signal);
97
+ const registered = await store.registerObjectWritePlan(plan, { signal });
98
+ active(signal);
99
+ if (registered === "revoked") throw new ReportingGcsFenceError("REVOKED");
100
+ const file = bucket.file(expected.object_name);
101
+ try {
102
+ await file.save(bytes, {
103
+ resumable: false,
104
+ preconditionOpts: { ifGenerationMatch: 0 },
105
+ metadata: { cacheControl: "no-store" }
106
+ });
107
+ active(signal);
108
+ } catch (error) {
109
+ active(signal);
110
+ if (!status(error, 412)) throw new ReportingGcsFenceError("PROVIDER_UNAVAILABLE");
111
+ try {
112
+ const [metadata] = await file.getMetadata();
113
+ active(signal);
114
+ if (metadata.metadata?.[TOMBSTONE] !== void 0) throw new ReportingGcsFenceError("REVOKED");
115
+ const existing = await readGcsBytes(
116
+ bucket.file(expected.object_name, { generation: metadata.generation }),
117
+ bytes.length,
118
+ signal
119
+ );
120
+ if (existing.length !== bytes.length || hash(existing) !== expected.sha256)
121
+ throw new ReportingGcsFenceError("CONTENT_CONFLICT");
122
+ } catch (error2) {
123
+ active(signal);
124
+ if (status(error2, 404)) {
125
+ const current = await store.registerObjectWritePlan(plan, { signal });
126
+ active(signal);
127
+ if (current === "revoked") throw new ReportingGcsFenceError("REVOKED");
128
+ }
129
+ if (isReportingGcsFenceError(error2)) throw error2;
130
+ throw new ReportingGcsFenceError("PROVIDER_UNAVAILABLE");
131
+ }
132
+ }
133
+ active(signal);
134
+ if (await store.registerObjectWritePlan(plan, { signal }) === "revoked")
135
+ throw new ReportingGcsFenceError("REVOKED");
136
+ active(signal);
137
+ }
138
+ async function revoke(scopeInput, maxObjects, signal) {
139
+ assertScope(scopeInput);
140
+ const scope = {
141
+ account_id: scopeInput.account_id,
142
+ destination_ref: scopeInput.destination_ref,
143
+ generation: scopeInput.generation
144
+ };
145
+ const limit = maxObjects ?? 10;
146
+ if (!Number.isSafeInteger(limit) || limit < 1 || limit > 1e3) throw new ReportingGcsFenceError("INVALID_INPUT");
147
+ active(signal);
148
+ const binding = await store.getObjectWriteBinding(scope, { signal });
149
+ active(signal);
150
+ const objects = await store.listRevokedObjectWrites(scope, { limit }, { signal });
151
+ active(signal);
152
+ if (!binding) {
153
+ if (objects.length) throw new ReportingGcsFenceError("STATE_UNAVAILABLE");
154
+ return { fenced: 0, complete: true };
155
+ }
156
+ const bucket = storage.bucket(binding.bucket);
157
+ await probe(bucket, signal);
158
+ const scopeKey = reportingObjectWriteScopeKey(scope);
159
+ for (const object of objects) {
160
+ active(signal);
161
+ if (object.bucket !== binding.bucket || object.object_name !== reportingObjectWriteName(scope, binding, object.plan_id, object.object_index))
162
+ throw new ReportingGcsFenceError("STATE_UNAVAILABLE");
163
+ const file = bucket.file(object.object_name);
164
+ let fencedGeneration;
165
+ for (let attempt = 0; attempt < 4 && !fencedGeneration; attempt++) {
166
+ active(signal);
167
+ let generation = 0;
168
+ try {
169
+ const [metadata] = await file.getMetadata();
170
+ active(signal);
171
+ generation = String(metadata.generation);
172
+ if (metadata.metadata?.[TOMBSTONE] === scopeKey && String(metadata.size) === "0") {
173
+ fencedGeneration = String(metadata.generation);
174
+ break;
175
+ }
176
+ } catch (error) {
177
+ active(signal);
178
+ if (!status(error, 404)) throw new ReportingGcsFenceError("PROVIDER_UNAVAILABLE");
179
+ }
180
+ active(signal);
181
+ try {
182
+ await file.save(Buffer.alloc(0), {
183
+ resumable: false,
184
+ preconditionOpts: { ifGenerationMatch: generation },
185
+ metadata: { cacheControl: "no-store", metadata: { [TOMBSTONE]: scopeKey } }
186
+ });
187
+ active(signal);
188
+ const [verified] = await file.getMetadata();
189
+ active(signal);
190
+ if (verified.metadata?.[TOMBSTONE] !== scopeKey || String(verified.size) !== "0")
191
+ throw new ReportingGcsFenceError("PROVIDER_UNAVAILABLE");
192
+ fencedGeneration = String(verified.generation);
193
+ } catch (error) {
194
+ active(signal);
195
+ if (isReportingGcsFenceError(error)) throw error;
196
+ if (!status(error, 412)) throw new ReportingGcsFenceError("PROVIDER_UNAVAILABLE");
197
+ }
198
+ }
199
+ if (!fencedGeneration) throw new ReportingGcsFenceError("PROVIDER_UNAVAILABLE");
200
+ active(signal);
201
+ await store.markObjectWriteFenced(
202
+ {
203
+ ...scope,
204
+ plan_id: object.plan_id,
205
+ object_index: object.object_index,
206
+ tombstone_generation: fencedGeneration
207
+ },
208
+ { signal }
209
+ );
210
+ active(signal);
211
+ }
212
+ const remaining = await store.listRevokedObjectWrites(scope, { limit: 1 }, { signal });
213
+ active(signal);
214
+ return { fenced: objects.length, complete: remaining.length === 0 };
215
+ }
216
+ function requireSignal(context) {
217
+ if (!(context?.signal instanceof AbortSignal)) throw new ReportingGcsFenceError("INVALID_INPUT");
218
+ return context.signal;
219
+ }
220
+ return {
221
+ probe: async (context) => bounded((signal) => probe(storage.bucket(bucketName), signal), context?.signal),
222
+ register: async (scope, deliveryId, bodies, context) => bounded((signal) => register(scope, deliveryId, bodies, signal), context?.signal),
223
+ write: async (plan, index, bytes, context) => bounded((signal) => write(plan, index, bytes, signal), requireSignal(context)),
224
+ revoke: async (scope, context) => bounded((signal) => revoke(scope, context.maxObjects, signal), requireSignal(context))
225
+ };
226
+ }
227
+ export {
228
+ ReportingGcsFenceError2 as ReportingGcsFenceError,
229
+ createGcsReportingObjectFenceV1
230
+ };
@@ -0,0 +1,7 @@
1
+ export { createGcsReportingObjectFenceV1 } from './fence.mjs';
2
+ export type { GcsReportingObjectFenceV1 } from './fence.mjs';
3
+ export { ReportingGcsFenceError, isReportingGcsFenceError } from './errors.mjs';
4
+ export { createGcsReportingResourceReaderV1, createGcsReportingReferenceResolverV1 } from './reader.mjs';
5
+ export type { GcsReportingReadScopeV1, GcsReportingReadAuthorizationV1, GcsReportingReaderOptionsV1 } from './reader.mjs';
6
+ export { createGcsReportingManagedDeliveryAdapterV1 } from './adapter.mjs';
7
+ export type { CreateGcsReportingManagedDeliveryAdapterOptionsV1 } from './adapter.mjs';
@@ -0,0 +1,7 @@
1
+ export { createGcsReportingObjectFenceV1 } from './fence';
2
+ export type { GcsReportingObjectFenceV1 } from './fence';
3
+ export { ReportingGcsFenceError, isReportingGcsFenceError } from './errors';
4
+ export { createGcsReportingResourceReaderV1, createGcsReportingReferenceResolverV1 } from './reader';
5
+ export type { GcsReportingReadScopeV1, GcsReportingReadAuthorizationV1, GcsReportingReaderOptionsV1 } from './reader';
6
+ export { createGcsReportingManagedDeliveryAdapterV1 } from './adapter';
7
+ export type { CreateGcsReportingManagedDeliveryAdapterOptionsV1 } from './adapter';
@@ -0,0 +1,41 @@
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 gcs_exports = {};
20
+ __export(gcs_exports, {
21
+ ReportingGcsFenceError: () => import_errors.ReportingGcsFenceError,
22
+ createGcsReportingManagedDeliveryAdapterV1: () => import_adapter.createGcsReportingManagedDeliveryAdapterV1,
23
+ createGcsReportingObjectFenceV1: () => import_fence.createGcsReportingObjectFenceV1,
24
+ createGcsReportingReferenceResolverV1: () => import_reader.createGcsReportingReferenceResolverV1,
25
+ createGcsReportingResourceReaderV1: () => import_reader.createGcsReportingResourceReaderV1,
26
+ isReportingGcsFenceError: () => import_errors.isReportingGcsFenceError
27
+ });
28
+ module.exports = __toCommonJS(gcs_exports);
29
+ var import_fence = require('./fence.js');
30
+ var import_errors = require('./errors.js');
31
+ var import_reader = require('./reader.js');
32
+ var import_adapter = require('./adapter.js');
33
+ // Annotate the CommonJS export names for ESM import in node:
34
+ 0 && (module.exports = {
35
+ ReportingGcsFenceError,
36
+ createGcsReportingManagedDeliveryAdapterV1,
37
+ createGcsReportingObjectFenceV1,
38
+ createGcsReportingReferenceResolverV1,
39
+ createGcsReportingResourceReaderV1,
40
+ isReportingGcsFenceError
41
+ });
@@ -0,0 +1,12 @@
1
+ import { createGcsReportingObjectFenceV1 } from "./fence.mjs";
2
+ import { ReportingGcsFenceError, isReportingGcsFenceError } from "./errors.mjs";
3
+ import { createGcsReportingResourceReaderV1, createGcsReportingReferenceResolverV1 } from "./reader.mjs";
4
+ import { createGcsReportingManagedDeliveryAdapterV1 } from "./adapter.mjs";
5
+ export {
6
+ ReportingGcsFenceError,
7
+ createGcsReportingManagedDeliveryAdapterV1,
8
+ createGcsReportingObjectFenceV1,
9
+ createGcsReportingReferenceResolverV1,
10
+ createGcsReportingResourceReaderV1,
11
+ isReportingGcsFenceError
12
+ };
@@ -0,0 +1,7 @@
1
+ import type { File } from '@google-cloud/storage';
2
+ export declare function activeGcsSignal(signal: AbortSignal): void;
3
+ export declare function withGcsDeadline<T>(work: (signal: AbortSignal) => Promise<T>, context?: {
4
+ signal?: AbortSignal;
5
+ milliseconds?: number;
6
+ }): Promise<T>;
7
+ export declare function readGcsBytes(file: File, maxBytes: number, signal: AbortSignal): Promise<Buffer>;
@@ -0,0 +1,7 @@
1
+ import type { File } from '@google-cloud/storage';
2
+ export declare function activeGcsSignal(signal: AbortSignal): void;
3
+ export declare function withGcsDeadline<T>(work: (signal: AbortSignal) => Promise<T>, context?: {
4
+ signal?: AbortSignal;
5
+ milliseconds?: number;
6
+ }): Promise<T>;
7
+ export declare function readGcsBytes(file: File, maxBytes: number, signal: AbortSignal): Promise<Buffer>;
@@ -0,0 +1,95 @@
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 io_exports = {};
20
+ __export(io_exports, {
21
+ activeGcsSignal: () => activeGcsSignal,
22
+ readGcsBytes: () => readGcsBytes,
23
+ withGcsDeadline: () => withGcsDeadline
24
+ });
25
+ module.exports = __toCommonJS(io_exports);
26
+ var import_object_writes = require('../ledger/object-writes.js');
27
+ var import_errors = require('./errors.js');
28
+ function activeGcsSignal(signal) {
29
+ if (signal.aborted) throw signal.reason;
30
+ }
31
+ const active = activeGcsSignal;
32
+ async function withGcsDeadline(work, context = {}) {
33
+ const signal = context.signal;
34
+ const deadline = context.milliseconds ?? 6e4;
35
+ if (!Number.isSafeInteger(deadline) || deadline < 1 || deadline > 6e4)
36
+ throw new import_errors.ReportingGcsFenceError("INVALID_INPUT");
37
+ if (signal !== void 0 && !(signal instanceof AbortSignal)) throw new import_errors.ReportingGcsFenceError("INVALID_INPUT");
38
+ const controller = new AbortController();
39
+ const onAbort = () => controller.abort(new import_errors.ReportingGcsFenceError("ABORTED"));
40
+ signal?.addEventListener("abort", onAbort, { once: true });
41
+ if (signal?.aborted) onAbort();
42
+ const timer = setTimeout(() => controller.abort(new import_errors.ReportingGcsFenceError("DEADLINE_EXCEEDED")), deadline);
43
+ let rejectAbort;
44
+ try {
45
+ active(controller.signal);
46
+ return await Promise.race([
47
+ work(controller.signal),
48
+ new Promise((_, reject) => {
49
+ rejectAbort = () => reject(controller.signal.reason);
50
+ controller.signal.addEventListener("abort", rejectAbort, { once: true });
51
+ if (controller.signal.aborted) rejectAbort();
52
+ })
53
+ ]);
54
+ } catch (error) {
55
+ if (controller.signal.aborted) throw controller.signal.reason;
56
+ if ((0, import_errors.isReportingGcsFenceError)(error)) throw error;
57
+ if ((0, import_object_writes.isReportingObjectWriteConflictError)(error) || error instanceof Error && (0, import_object_writes.isReportingObjectWriteConflictError)(error.cause))
58
+ throw new import_errors.ReportingGcsFenceError("CONTENT_CONFLICT");
59
+ if ((0, import_object_writes.isReportingObjectWriteNotRevokedError)(error) || error instanceof Error && (0, import_object_writes.isReportingObjectWriteNotRevokedError)(error.cause))
60
+ throw new import_errors.ReportingGcsFenceError("NOT_REVOKED");
61
+ throw new import_errors.ReportingGcsFenceError("STATE_UNAVAILABLE");
62
+ } finally {
63
+ clearTimeout(timer);
64
+ signal?.removeEventListener("abort", onAbort);
65
+ if (rejectAbort) controller.signal.removeEventListener("abort", rejectAbort);
66
+ }
67
+ }
68
+ async function readGcsBytes(file, maxBytes, signal) {
69
+ active(signal);
70
+ const stream = file.createReadStream();
71
+ const abort = () => stream.destroy(new import_errors.ReportingGcsFenceError("ABORTED"));
72
+ signal.addEventListener("abort", abort, { once: true });
73
+ if (signal.aborted) abort();
74
+ const chunks = [];
75
+ let count = 0;
76
+ try {
77
+ for await (const chunk of stream) {
78
+ active(signal);
79
+ count += chunk.length;
80
+ if (count > maxBytes) throw new import_errors.ReportingGcsFenceError("CONTENT_CONFLICT");
81
+ chunks.push(Buffer.from(chunk));
82
+ }
83
+ active(signal);
84
+ return Buffer.concat(chunks);
85
+ } finally {
86
+ signal.removeEventListener("abort", abort);
87
+ stream.destroy();
88
+ }
89
+ }
90
+ // Annotate the CommonJS export names for ESM import in node:
91
+ 0 && (module.exports = {
92
+ activeGcsSignal,
93
+ readGcsBytes,
94
+ withGcsDeadline
95
+ });
@@ -0,0 +1,69 @@
1
+ import { isReportingObjectWriteConflictError, isReportingObjectWriteNotRevokedError } from "../ledger/object-writes.mjs";
2
+ import { ReportingGcsFenceError, isReportingGcsFenceError } from "./errors.mjs";
3
+ function activeGcsSignal(signal) {
4
+ if (signal.aborted) throw signal.reason;
5
+ }
6
+ const active = activeGcsSignal;
7
+ async function withGcsDeadline(work, context = {}) {
8
+ const signal = context.signal;
9
+ const deadline = context.milliseconds ?? 6e4;
10
+ if (!Number.isSafeInteger(deadline) || deadline < 1 || deadline > 6e4)
11
+ throw new ReportingGcsFenceError("INVALID_INPUT");
12
+ if (signal !== void 0 && !(signal instanceof AbortSignal)) throw new ReportingGcsFenceError("INVALID_INPUT");
13
+ const controller = new AbortController();
14
+ const onAbort = () => controller.abort(new ReportingGcsFenceError("ABORTED"));
15
+ signal?.addEventListener("abort", onAbort, { once: true });
16
+ if (signal?.aborted) onAbort();
17
+ const timer = setTimeout(() => controller.abort(new ReportingGcsFenceError("DEADLINE_EXCEEDED")), deadline);
18
+ let rejectAbort;
19
+ try {
20
+ active(controller.signal);
21
+ return await Promise.race([
22
+ work(controller.signal),
23
+ new Promise((_, reject) => {
24
+ rejectAbort = () => reject(controller.signal.reason);
25
+ controller.signal.addEventListener("abort", rejectAbort, { once: true });
26
+ if (controller.signal.aborted) rejectAbort();
27
+ })
28
+ ]);
29
+ } catch (error) {
30
+ if (controller.signal.aborted) throw controller.signal.reason;
31
+ if (isReportingGcsFenceError(error)) throw error;
32
+ if (isReportingObjectWriteConflictError(error) || error instanceof Error && isReportingObjectWriteConflictError(error.cause))
33
+ throw new ReportingGcsFenceError("CONTENT_CONFLICT");
34
+ if (isReportingObjectWriteNotRevokedError(error) || error instanceof Error && isReportingObjectWriteNotRevokedError(error.cause))
35
+ throw new ReportingGcsFenceError("NOT_REVOKED");
36
+ throw new ReportingGcsFenceError("STATE_UNAVAILABLE");
37
+ } finally {
38
+ clearTimeout(timer);
39
+ signal?.removeEventListener("abort", onAbort);
40
+ if (rejectAbort) controller.signal.removeEventListener("abort", rejectAbort);
41
+ }
42
+ }
43
+ async function readGcsBytes(file, maxBytes, signal) {
44
+ active(signal);
45
+ const stream = file.createReadStream();
46
+ const abort = () => stream.destroy(new ReportingGcsFenceError("ABORTED"));
47
+ signal.addEventListener("abort", abort, { once: true });
48
+ if (signal.aborted) abort();
49
+ const chunks = [];
50
+ let count = 0;
51
+ try {
52
+ for await (const chunk of stream) {
53
+ active(signal);
54
+ count += chunk.length;
55
+ if (count > maxBytes) throw new ReportingGcsFenceError("CONTENT_CONFLICT");
56
+ chunks.push(Buffer.from(chunk));
57
+ }
58
+ active(signal);
59
+ return Buffer.concat(chunks);
60
+ } finally {
61
+ signal.removeEventListener("abort", abort);
62
+ stream.destroy();
63
+ }
64
+ }
65
+ export {
66
+ activeGcsSignal,
67
+ readGcsBytes,
68
+ withGcsDeadline
69
+ };
@@ -0,0 +1,43 @@
1
+ import type { Storage } from '@google-cloud/storage';
2
+ import { type CanonicalReferenceResolver } from '../../canonical-references/index.mjs';
3
+ import type { ReportingResourceReader } from '../inspection.mjs';
4
+ import { type ReportingObjectWriteScopeV1 } from '../ledger/object-writes.mjs';
5
+ export interface GcsReportingReadScopeV1 extends ReportingObjectWriteScopeV1 {
6
+ /** Non-secret identity from the host's authenticated principal registry. Never a bearer. */
7
+ principal_id: string;
8
+ }
9
+ export interface GcsReportingReadAuthorizationV1 {
10
+ scope: Readonly<GcsReportingReadScopeV1>;
11
+ bucket: string;
12
+ objectPrefix: string;
13
+ objectName: string;
14
+ }
15
+ export interface GcsReportingReaderOptionsV1 {
16
+ scope: GcsReportingReadScopeV1;
17
+ bucket: string;
18
+ /** Exact saved destination prefix, including the trailing slash. */
19
+ objectPrefix: string;
20
+ /** Resolve an official client with keyless credentials for this operation. */
21
+ getStorage(scope: Readonly<GcsReportingReadScopeV1>, context: {
22
+ signal: AbortSignal;
23
+ }): Promise<Storage>;
24
+ /** Host verifies principal/account/destination ownership and the current grant generation. */
25
+ authorize(request: Readonly<GcsReportingReadAuthorizationV1>, context: {
26
+ signal: AbortSignal;
27
+ }): Promise<boolean>;
28
+ /** Optional operation lifetime, composed with each read deadline/caller signal. */
29
+ signal?: AbortSignal;
30
+ operationDeadlineMilliseconds?: number;
31
+ maxBytes?: number;
32
+ }
33
+ /** Restrictive provider-native URL grammar: no credentials, queries, encoding or traversal. */
34
+ export declare function gcsReportingObjectFromUriV1(uri: string, bucket: string, prefix: string): string;
35
+ export declare function createGcsScopedObjectReadV1(options: GcsReportingReaderOptionsV1): (uri: string, maxBytes: number, signal?: AbortSignal, nativeVersion?: string) => Promise<{
36
+ body: Buffer<ArrayBufferLike>;
37
+ contentType: string | undefined;
38
+ generation: string;
39
+ }>;
40
+ /** Destination-bound manifest/object reader. The caller never supplies bucket or credential scope. */
41
+ export declare function createGcsReportingResourceReaderV1(options: GcsReportingReaderOptionsV1): ReportingResourceReader;
42
+ /** Digest-pinned private contract resolver; all resolutions re-authorize and bypass caches. */
43
+ export declare function createGcsReportingReferenceResolverV1(options: GcsReportingReaderOptionsV1): CanonicalReferenceResolver;
@@ -0,0 +1,43 @@
1
+ import type { Storage } from '@google-cloud/storage';
2
+ import { type CanonicalReferenceResolver } from '../../canonical-references';
3
+ import type { ReportingResourceReader } from '../inspection';
4
+ import { type ReportingObjectWriteScopeV1 } from '../ledger/object-writes';
5
+ export interface GcsReportingReadScopeV1 extends ReportingObjectWriteScopeV1 {
6
+ /** Non-secret identity from the host's authenticated principal registry. Never a bearer. */
7
+ principal_id: string;
8
+ }
9
+ export interface GcsReportingReadAuthorizationV1 {
10
+ scope: Readonly<GcsReportingReadScopeV1>;
11
+ bucket: string;
12
+ objectPrefix: string;
13
+ objectName: string;
14
+ }
15
+ export interface GcsReportingReaderOptionsV1 {
16
+ scope: GcsReportingReadScopeV1;
17
+ bucket: string;
18
+ /** Exact saved destination prefix, including the trailing slash. */
19
+ objectPrefix: string;
20
+ /** Resolve an official client with keyless credentials for this operation. */
21
+ getStorage(scope: Readonly<GcsReportingReadScopeV1>, context: {
22
+ signal: AbortSignal;
23
+ }): Promise<Storage>;
24
+ /** Host verifies principal/account/destination ownership and the current grant generation. */
25
+ authorize(request: Readonly<GcsReportingReadAuthorizationV1>, context: {
26
+ signal: AbortSignal;
27
+ }): Promise<boolean>;
28
+ /** Optional operation lifetime, composed with each read deadline/caller signal. */
29
+ signal?: AbortSignal;
30
+ operationDeadlineMilliseconds?: number;
31
+ maxBytes?: number;
32
+ }
33
+ /** Restrictive provider-native URL grammar: no credentials, queries, encoding or traversal. */
34
+ export declare function gcsReportingObjectFromUriV1(uri: string, bucket: string, prefix: string): string;
35
+ export declare function createGcsScopedObjectReadV1(options: GcsReportingReaderOptionsV1): (uri: string, maxBytes: number, signal?: AbortSignal, nativeVersion?: string) => Promise<{
36
+ body: Buffer<ArrayBufferLike>;
37
+ contentType: string | undefined;
38
+ generation: string;
39
+ }>;
40
+ /** Destination-bound manifest/object reader. The caller never supplies bucket or credential scope. */
41
+ export declare function createGcsReportingResourceReaderV1(options: GcsReportingReaderOptionsV1): ReportingResourceReader;
42
+ /** Digest-pinned private contract resolver; all resolutions re-authorize and bypass caches. */
43
+ export declare function createGcsReportingReferenceResolverV1(options: GcsReportingReaderOptionsV1): CanonicalReferenceResolver;