@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,3 @@
1
+ import type { BucketMetadata } from '@google-cloud/storage';
2
+ /** Pure policy guard shared by the real-provider probe and deterministic negative controls. */
3
+ export declare function assertGcsReportingBucketPolicy(metadata: BucketMetadata): void;
@@ -0,0 +1,31 @@
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 bucket_policy_exports = {};
20
+ __export(bucket_policy_exports, {
21
+ assertGcsReportingBucketPolicy: () => assertGcsReportingBucketPolicy
22
+ });
23
+ module.exports = __toCommonJS(bucket_policy_exports);
24
+ function assertGcsReportingBucketPolicy(metadata) {
25
+ if (!metadata || metadata.versioning?.enabled || metadata.softDeletePolicy?.retentionDurationSeconds === void 0 || Number(metadata.softDeletePolicy.retentionDurationSeconds) !== 0 || Number(metadata.retentionPolicy?.retentionPeriod ?? 0) !== 0 || metadata.defaultEventBasedHold === true || metadata.objectRetention?.mode === "Enabled" || (metadata.lifecycle?.rule?.length ?? 0) > 0 || metadata.iamConfiguration?.uniformBucketLevelAccess?.enabled !== true || metadata.iamConfiguration?.publicAccessPrevention !== "enforced")
26
+ throw new Error("Unsafe reporting GCS bucket policy");
27
+ }
28
+ // Annotate the CommonJS export names for ESM import in node:
29
+ 0 && (module.exports = {
30
+ assertGcsReportingBucketPolicy
31
+ });
@@ -0,0 +1,7 @@
1
+ function assertGcsReportingBucketPolicy(metadata) {
2
+ if (!metadata || metadata.versioning?.enabled || metadata.softDeletePolicy?.retentionDurationSeconds === void 0 || Number(metadata.softDeletePolicy.retentionDurationSeconds) !== 0 || Number(metadata.retentionPolicy?.retentionPeriod ?? 0) !== 0 || metadata.defaultEventBasedHold === true || metadata.objectRetention?.mode === "Enabled" || (metadata.lifecycle?.rule?.length ?? 0) > 0 || metadata.iamConfiguration?.uniformBucketLevelAccess?.enabled !== true || metadata.iamConfiguration?.publicAccessPrevention !== "enforced")
3
+ throw new Error("Unsafe reporting GCS bucket policy");
4
+ }
5
+ export {
6
+ assertGcsReportingBucketPolicy
7
+ };
@@ -0,0 +1,5 @@
1
+ export declare class ReportingGcsFenceError extends Error {
2
+ readonly code: 'INVALID_INPUT' | 'UNSAFE_BUCKET' | 'REVOKED' | 'NOT_REVOKED' | 'CONTENT_CONFLICT' | 'ABORTED' | 'PROVIDER_UNAVAILABLE' | 'DEADLINE_EXCEEDED' | 'HOST_CALLBACK_FAILED' | 'STATE_UNAVAILABLE';
3
+ constructor(code: 'INVALID_INPUT' | 'UNSAFE_BUCKET' | 'REVOKED' | 'NOT_REVOKED' | 'CONTENT_CONFLICT' | 'ABORTED' | 'PROVIDER_UNAVAILABLE' | 'DEADLINE_EXCEEDED' | 'HOST_CALLBACK_FAILED' | 'STATE_UNAVAILABLE');
4
+ }
5
+ export declare function isReportingGcsFenceError(error: unknown): error is ReportingGcsFenceError;
@@ -0,0 +1,5 @@
1
+ export declare class ReportingGcsFenceError extends Error {
2
+ readonly code: 'INVALID_INPUT' | 'UNSAFE_BUCKET' | 'REVOKED' | 'NOT_REVOKED' | 'CONTENT_CONFLICT' | 'ABORTED' | 'PROVIDER_UNAVAILABLE' | 'DEADLINE_EXCEEDED' | 'HOST_CALLBACK_FAILED' | 'STATE_UNAVAILABLE';
3
+ constructor(code: 'INVALID_INPUT' | 'UNSAFE_BUCKET' | 'REVOKED' | 'NOT_REVOKED' | 'CONTENT_CONFLICT' | 'ABORTED' | 'PROVIDER_UNAVAILABLE' | 'DEADLINE_EXCEEDED' | 'HOST_CALLBACK_FAILED' | 'STATE_UNAVAILABLE');
4
+ }
5
+ export declare function isReportingGcsFenceError(error: unknown): error is ReportingGcsFenceError;
@@ -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 errors_exports = {};
20
+ __export(errors_exports, {
21
+ ReportingGcsFenceError: () => ReportingGcsFenceError,
22
+ isReportingGcsFenceError: () => isReportingGcsFenceError
23
+ });
24
+ module.exports = __toCommonJS(errors_exports);
25
+ class ReportingGcsFenceError extends Error {
26
+ constructor(code) {
27
+ super(`Reporting GCS fence: ${code}`);
28
+ this.code = code;
29
+ this.name = "ReportingGcsFenceError";
30
+ Object.defineProperty(this, /* @__PURE__ */ Symbol.for("adcp.reportingGcsFenceError"), { value: true });
31
+ }
32
+ code;
33
+ }
34
+ function isReportingGcsFenceError(error) {
35
+ return !!error && typeof error === "object" && error[/* @__PURE__ */ Symbol.for("adcp.reportingGcsFenceError")] === true;
36
+ }
37
+ // Annotate the CommonJS export names for ESM import in node:
38
+ 0 && (module.exports = {
39
+ ReportingGcsFenceError,
40
+ isReportingGcsFenceError
41
+ });
@@ -0,0 +1,16 @@
1
+ class ReportingGcsFenceError extends Error {
2
+ constructor(code) {
3
+ super(`Reporting GCS fence: ${code}`);
4
+ this.code = code;
5
+ this.name = "ReportingGcsFenceError";
6
+ Object.defineProperty(this, /* @__PURE__ */ Symbol.for("adcp.reportingGcsFenceError"), { value: true });
7
+ }
8
+ code;
9
+ }
10
+ function isReportingGcsFenceError(error) {
11
+ return !!error && typeof error === "object" && error[/* @__PURE__ */ Symbol.for("adcp.reportingGcsFenceError")] === true;
12
+ }
13
+ export {
14
+ ReportingGcsFenceError,
15
+ isReportingGcsFenceError
16
+ };
@@ -0,0 +1,36 @@
1
+ import type { Storage } from '@google-cloud/storage';
2
+ import { type ReportingObjectWriteScopeV1, type ReportingObjectWritePlanV1, type ReportingObjectWriteStoreV1 } from '../ledger/object-writes.mjs';
3
+ export { ReportingGcsFenceError } from './errors.mjs';
4
+ export interface GcsReportingObjectFenceV1 {
5
+ probe(context?: {
6
+ signal?: AbortSignal;
7
+ }): Promise<void>;
8
+ register(scope: ReportingObjectWriteScopeV1, deliveryId: string, bodies: readonly Uint8Array[], context?: {
9
+ signal?: AbortSignal;
10
+ }): Promise<ReportingObjectWritePlanV1>;
11
+ write(plan: ReportingObjectWritePlanV1, index: number, bytes: Uint8Array, context: {
12
+ signal: AbortSignal;
13
+ }): Promise<void>;
14
+ revoke(scope: ReportingObjectWriteScopeV1, context: {
15
+ signal: AbortSignal;
16
+ maxObjects?: number;
17
+ }): Promise<{
18
+ fenced: number;
19
+ complete: boolean;
20
+ }>;
21
+ }
22
+ /**
23
+ * Provider-side write fence, not a complete Managed Delivery adapter.
24
+ * Derive scope from authenticated host state; these methods do not authorize callers.
25
+ * Bucket configuration must remain managed exclusively by the trusted host.
26
+ * Tombstones and inventory MUST NOT be deleted while stale requests can execute.
27
+ * Inject the official Storage client with host-owned, keyless credentials.
28
+ */
29
+ export declare function createGcsReportingObjectFenceV1(options: {
30
+ storage: Storage;
31
+ store: ReportingObjectWriteStoreV1;
32
+ bucket: string;
33
+ /** Opaque deployment identity, separate from account and destination generations. */
34
+ namespace: string;
35
+ operationDeadlineMilliseconds?: number;
36
+ }): GcsReportingObjectFenceV1;
@@ -0,0 +1,36 @@
1
+ import type { Storage } from '@google-cloud/storage';
2
+ import { type ReportingObjectWriteScopeV1, type ReportingObjectWritePlanV1, type ReportingObjectWriteStoreV1 } from '../ledger/object-writes';
3
+ export { ReportingGcsFenceError } from './errors';
4
+ export interface GcsReportingObjectFenceV1 {
5
+ probe(context?: {
6
+ signal?: AbortSignal;
7
+ }): Promise<void>;
8
+ register(scope: ReportingObjectWriteScopeV1, deliveryId: string, bodies: readonly Uint8Array[], context?: {
9
+ signal?: AbortSignal;
10
+ }): Promise<ReportingObjectWritePlanV1>;
11
+ write(plan: ReportingObjectWritePlanV1, index: number, bytes: Uint8Array, context: {
12
+ signal: AbortSignal;
13
+ }): Promise<void>;
14
+ revoke(scope: ReportingObjectWriteScopeV1, context: {
15
+ signal: AbortSignal;
16
+ maxObjects?: number;
17
+ }): Promise<{
18
+ fenced: number;
19
+ complete: boolean;
20
+ }>;
21
+ }
22
+ /**
23
+ * Provider-side write fence, not a complete Managed Delivery adapter.
24
+ * Derive scope from authenticated host state; these methods do not authorize callers.
25
+ * Bucket configuration must remain managed exclusively by the trusted host.
26
+ * Tombstones and inventory MUST NOT be deleted while stale requests can execute.
27
+ * Inject the official Storage client with host-owned, keyless credentials.
28
+ */
29
+ export declare function createGcsReportingObjectFenceV1(options: {
30
+ storage: Storage;
31
+ store: ReportingObjectWriteStoreV1;
32
+ bucket: string;
33
+ /** Opaque deployment identity, separate from account and destination generations. */
34
+ namespace: string;
35
+ operationDeadlineMilliseconds?: number;
36
+ }): GcsReportingObjectFenceV1;
@@ -0,0 +1,250 @@
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 fence_exports = {};
20
+ __export(fence_exports, {
21
+ ReportingGcsFenceError: () => import_errors2.ReportingGcsFenceError,
22
+ createGcsReportingObjectFenceV1: () => createGcsReportingObjectFenceV1
23
+ });
24
+ module.exports = __toCommonJS(fence_exports);
25
+ var import_node_crypto = require("node:crypto");
26
+ var import_object_writes = require('../ledger/object-writes.js');
27
+ var import_errors = require('./errors.js');
28
+ var import_io = require('./io.js');
29
+ var import_bucket_policy = require('./bucket-policy.js');
30
+ var import_errors2 = require('./errors.js');
31
+ const hash = (bytes) => (0, import_node_crypto.createHash)("sha256").update(bytes).digest("hex");
32
+ const TOMBSTONE = "adcp_reporting_tombstone";
33
+ function createGcsReportingObjectFenceV1(options) {
34
+ 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)
35
+ throw new import_errors.ReportingGcsFenceError("INVALID_INPUT");
36
+ const { storage, store, bucket: bucketName, namespace } = options;
37
+ const deadline = options.operationDeadlineMilliseconds ?? 6e4;
38
+ if (!Number.isSafeInteger(deadline) || deadline < 1 || deadline > 6e4)
39
+ throw new import_errors.ReportingGcsFenceError("INVALID_INPUT");
40
+ const provider = { bucket: bucketName, namespace_key: hash(namespace) };
41
+ const status = (error, code) => !!error && typeof error === "object" && "code" in error && Number(error.code) === code;
42
+ const bounded = (work, signal) => (0, import_io.withGcsDeadline)(work, { signal, milliseconds: deadline });
43
+ async function probe(bucket, signal) {
44
+ (0, import_io.activeGcsSignal)(signal);
45
+ try {
46
+ const [metadata] = await bucket.getMetadata();
47
+ (0, import_io.activeGcsSignal)(signal);
48
+ try {
49
+ (0, import_bucket_policy.assertGcsReportingBucketPolicy)(metadata);
50
+ } catch {
51
+ throw new import_errors.ReportingGcsFenceError("UNSAFE_BUCKET");
52
+ }
53
+ } catch (error) {
54
+ (0, import_io.activeGcsSignal)(signal);
55
+ if ((0, import_errors.isReportingGcsFenceError)(error)) throw error;
56
+ throw new import_errors.ReportingGcsFenceError("PROVIDER_UNAVAILABLE");
57
+ }
58
+ }
59
+ function assertScope(scope) {
60
+ try {
61
+ (0, import_object_writes.assertReportingObjectWriteScope)(scope);
62
+ } catch {
63
+ throw new import_errors.ReportingGcsFenceError("INVALID_INPUT");
64
+ }
65
+ }
66
+ function assertPlan(plan) {
67
+ try {
68
+ (0, import_object_writes.reportingObjectWritePlanFingerprint)(plan);
69
+ } catch {
70
+ throw new import_errors.ReportingGcsFenceError("INVALID_INPUT");
71
+ }
72
+ if (plan.provider.bucket !== bucketName || plan.provider.namespace_key !== provider.namespace_key)
73
+ throw new import_errors.ReportingGcsFenceError("INVALID_INPUT");
74
+ }
75
+ async function register(scope, deliveryId, bodies, signal) {
76
+ assertScope(scope);
77
+ 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)
78
+ throw new import_errors.ReportingGcsFenceError("INVALID_INPUT");
79
+ const scopeCopy = {
80
+ account_id: scope.account_id,
81
+ destination_ref: scope.destination_ref,
82
+ generation: scope.generation
83
+ };
84
+ const planId = hash(deliveryId);
85
+ const plan = {
86
+ ...scopeCopy,
87
+ provider: { ...provider },
88
+ plan_id: planId,
89
+ objects: bodies.map((b, i) => ({
90
+ bucket: bucketName,
91
+ object_name: (0, import_object_writes.reportingObjectWriteName)(scopeCopy, provider, planId, i),
92
+ sha256: hash(b),
93
+ size_bytes: b.byteLength
94
+ }))
95
+ };
96
+ await probe(storage.bucket(bucketName), signal);
97
+ (0, import_io.activeGcsSignal)(signal);
98
+ const registered = await store.registerObjectWritePlan(plan, { signal });
99
+ (0, import_io.activeGcsSignal)(signal);
100
+ if (registered === "revoked") throw new import_errors.ReportingGcsFenceError("REVOKED");
101
+ return plan;
102
+ }
103
+ async function write(input, index, inputBytes, signal) {
104
+ const plan = structuredClone(input);
105
+ assertPlan(plan);
106
+ const expected = plan.objects[index];
107
+ if (!Number.isInteger(index) || !expected || !(inputBytes instanceof Uint8Array))
108
+ throw new import_errors.ReportingGcsFenceError("INVALID_INPUT");
109
+ if (inputBytes.byteLength !== expected.size_bytes) throw new import_errors.ReportingGcsFenceError("CONTENT_CONFLICT");
110
+ const bytes = Buffer.from(inputBytes);
111
+ if (hash(bytes) !== expected.sha256) throw new import_errors.ReportingGcsFenceError("CONTENT_CONFLICT");
112
+ (0, import_io.activeGcsSignal)(signal);
113
+ const bucket = storage.bucket(bucketName);
114
+ await probe(bucket, signal);
115
+ (0, import_io.activeGcsSignal)(signal);
116
+ const registered = await store.registerObjectWritePlan(plan, { signal });
117
+ (0, import_io.activeGcsSignal)(signal);
118
+ if (registered === "revoked") throw new import_errors.ReportingGcsFenceError("REVOKED");
119
+ const file = bucket.file(expected.object_name);
120
+ try {
121
+ await file.save(bytes, {
122
+ resumable: false,
123
+ preconditionOpts: { ifGenerationMatch: 0 },
124
+ metadata: { cacheControl: "no-store" }
125
+ });
126
+ (0, import_io.activeGcsSignal)(signal);
127
+ } catch (error) {
128
+ (0, import_io.activeGcsSignal)(signal);
129
+ if (!status(error, 412)) throw new import_errors.ReportingGcsFenceError("PROVIDER_UNAVAILABLE");
130
+ try {
131
+ const [metadata] = await file.getMetadata();
132
+ (0, import_io.activeGcsSignal)(signal);
133
+ if (metadata.metadata?.[TOMBSTONE] !== void 0) throw new import_errors.ReportingGcsFenceError("REVOKED");
134
+ const existing = await (0, import_io.readGcsBytes)(
135
+ bucket.file(expected.object_name, { generation: metadata.generation }),
136
+ bytes.length,
137
+ signal
138
+ );
139
+ if (existing.length !== bytes.length || hash(existing) !== expected.sha256)
140
+ throw new import_errors.ReportingGcsFenceError("CONTENT_CONFLICT");
141
+ } catch (error2) {
142
+ (0, import_io.activeGcsSignal)(signal);
143
+ if (status(error2, 404)) {
144
+ const current = await store.registerObjectWritePlan(plan, { signal });
145
+ (0, import_io.activeGcsSignal)(signal);
146
+ if (current === "revoked") throw new import_errors.ReportingGcsFenceError("REVOKED");
147
+ }
148
+ if ((0, import_errors.isReportingGcsFenceError)(error2)) throw error2;
149
+ throw new import_errors.ReportingGcsFenceError("PROVIDER_UNAVAILABLE");
150
+ }
151
+ }
152
+ (0, import_io.activeGcsSignal)(signal);
153
+ if (await store.registerObjectWritePlan(plan, { signal }) === "revoked")
154
+ throw new import_errors.ReportingGcsFenceError("REVOKED");
155
+ (0, import_io.activeGcsSignal)(signal);
156
+ }
157
+ async function revoke(scopeInput, maxObjects, signal) {
158
+ assertScope(scopeInput);
159
+ const scope = {
160
+ account_id: scopeInput.account_id,
161
+ destination_ref: scopeInput.destination_ref,
162
+ generation: scopeInput.generation
163
+ };
164
+ const limit = maxObjects ?? 10;
165
+ if (!Number.isSafeInteger(limit) || limit < 1 || limit > 1e3) throw new import_errors.ReportingGcsFenceError("INVALID_INPUT");
166
+ (0, import_io.activeGcsSignal)(signal);
167
+ const binding = await store.getObjectWriteBinding(scope, { signal });
168
+ (0, import_io.activeGcsSignal)(signal);
169
+ const objects = await store.listRevokedObjectWrites(scope, { limit }, { signal });
170
+ (0, import_io.activeGcsSignal)(signal);
171
+ if (!binding) {
172
+ if (objects.length) throw new import_errors.ReportingGcsFenceError("STATE_UNAVAILABLE");
173
+ return { fenced: 0, complete: true };
174
+ }
175
+ const bucket = storage.bucket(binding.bucket);
176
+ await probe(bucket, signal);
177
+ const scopeKey = (0, import_object_writes.reportingObjectWriteScopeKey)(scope);
178
+ for (const object of objects) {
179
+ (0, import_io.activeGcsSignal)(signal);
180
+ if (object.bucket !== binding.bucket || object.object_name !== (0, import_object_writes.reportingObjectWriteName)(scope, binding, object.plan_id, object.object_index))
181
+ throw new import_errors.ReportingGcsFenceError("STATE_UNAVAILABLE");
182
+ const file = bucket.file(object.object_name);
183
+ let fencedGeneration;
184
+ for (let attempt = 0; attempt < 4 && !fencedGeneration; attempt++) {
185
+ (0, import_io.activeGcsSignal)(signal);
186
+ let generation = 0;
187
+ try {
188
+ const [metadata] = await file.getMetadata();
189
+ (0, import_io.activeGcsSignal)(signal);
190
+ generation = String(metadata.generation);
191
+ if (metadata.metadata?.[TOMBSTONE] === scopeKey && String(metadata.size) === "0") {
192
+ fencedGeneration = String(metadata.generation);
193
+ break;
194
+ }
195
+ } catch (error) {
196
+ (0, import_io.activeGcsSignal)(signal);
197
+ if (!status(error, 404)) throw new import_errors.ReportingGcsFenceError("PROVIDER_UNAVAILABLE");
198
+ }
199
+ (0, import_io.activeGcsSignal)(signal);
200
+ try {
201
+ await file.save(Buffer.alloc(0), {
202
+ resumable: false,
203
+ preconditionOpts: { ifGenerationMatch: generation },
204
+ metadata: { cacheControl: "no-store", metadata: { [TOMBSTONE]: scopeKey } }
205
+ });
206
+ (0, import_io.activeGcsSignal)(signal);
207
+ const [verified] = await file.getMetadata();
208
+ (0, import_io.activeGcsSignal)(signal);
209
+ if (verified.metadata?.[TOMBSTONE] !== scopeKey || String(verified.size) !== "0")
210
+ throw new import_errors.ReportingGcsFenceError("PROVIDER_UNAVAILABLE");
211
+ fencedGeneration = String(verified.generation);
212
+ } catch (error) {
213
+ (0, import_io.activeGcsSignal)(signal);
214
+ if ((0, import_errors.isReportingGcsFenceError)(error)) throw error;
215
+ if (!status(error, 412)) throw new import_errors.ReportingGcsFenceError("PROVIDER_UNAVAILABLE");
216
+ }
217
+ }
218
+ if (!fencedGeneration) throw new import_errors.ReportingGcsFenceError("PROVIDER_UNAVAILABLE");
219
+ (0, import_io.activeGcsSignal)(signal);
220
+ await store.markObjectWriteFenced(
221
+ {
222
+ ...scope,
223
+ plan_id: object.plan_id,
224
+ object_index: object.object_index,
225
+ tombstone_generation: fencedGeneration
226
+ },
227
+ { signal }
228
+ );
229
+ (0, import_io.activeGcsSignal)(signal);
230
+ }
231
+ const remaining = await store.listRevokedObjectWrites(scope, { limit: 1 }, { signal });
232
+ (0, import_io.activeGcsSignal)(signal);
233
+ return { fenced: objects.length, complete: remaining.length === 0 };
234
+ }
235
+ function requireSignal(context) {
236
+ if (!(context?.signal instanceof AbortSignal)) throw new import_errors.ReportingGcsFenceError("INVALID_INPUT");
237
+ return context.signal;
238
+ }
239
+ return {
240
+ probe: async (context) => bounded((signal) => probe(storage.bucket(bucketName), signal), context?.signal),
241
+ register: async (scope, deliveryId, bodies, context) => bounded((signal) => register(scope, deliveryId, bodies, signal), context?.signal),
242
+ write: async (plan, index, bytes, context) => bounded((signal) => write(plan, index, bytes, signal), requireSignal(context)),
243
+ revoke: async (scope, context) => bounded((signal) => revoke(scope, context.maxObjects, signal), requireSignal(context))
244
+ };
245
+ }
246
+ // Annotate the CommonJS export names for ESM import in node:
247
+ 0 && (module.exports = {
248
+ ReportingGcsFenceError,
249
+ createGcsReportingObjectFenceV1
250
+ });