@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.
- package/bin/adcp-grade.js +46 -2
- package/bin/adcp.js +13 -3
- package/dist/lib/auth/oauth/ClientCredentialsFlow.js +4 -1
- package/dist/lib/auth/oauth/ClientCredentialsFlow.mjs +4 -1
- package/dist/lib/auth/oauth/MCPOAuthProvider.d.mts +19 -6
- package/dist/lib/auth/oauth/MCPOAuthProvider.d.ts +19 -6
- package/dist/lib/auth/oauth/MCPOAuthProvider.js +95 -30
- package/dist/lib/auth/oauth/MCPOAuthProvider.mjs +96 -30
- package/dist/lib/auth/oauth/NonInteractiveFlowHandler.d.mts +1 -1
- package/dist/lib/auth/oauth/NonInteractiveFlowHandler.d.ts +1 -1
- package/dist/lib/auth/oauth/NonInteractiveFlowHandler.js +1 -1
- package/dist/lib/auth/oauth/NonInteractiveFlowHandler.mjs +1 -1
- package/dist/lib/auth/oauth/client-credentials-schema.d.mts +17 -0
- package/dist/lib/auth/oauth/client-credentials-schema.d.ts +17 -0
- package/dist/lib/auth/oauth/client-credentials-schema.js +37 -0
- package/dist/lib/auth/oauth/client-credentials-schema.mjs +13 -0
- package/dist/lib/auth/oauth/file-storage.d.mts +3 -3
- package/dist/lib/auth/oauth/file-storage.d.ts +3 -3
- package/dist/lib/auth/oauth/file-storage.js +12 -5
- package/dist/lib/auth/oauth/file-storage.mjs +12 -5
- package/dist/lib/auth/oauth/index.d.mts +10 -6
- package/dist/lib/auth/oauth/index.d.ts +10 -6
- package/dist/lib/auth/oauth/index.js +9 -3
- package/dist/lib/auth/oauth/index.mjs +8 -3
- package/dist/lib/auth/oauth/types.d.mts +9 -2
- package/dist/lib/auth/oauth/types.d.ts +9 -2
- package/dist/lib/auth/oauth/types.js +3 -2
- package/dist/lib/auth/oauth/types.mjs +3 -2
- package/dist/lib/auth/oauth/web-flow.d.mts +2 -0
- package/dist/lib/auth/oauth/web-flow.d.ts +2 -0
- package/dist/lib/auth/oauth/web-flow.js +42 -9
- package/dist/lib/auth/oauth/web-flow.mjs +42 -9
- package/dist/lib/canonical-references/index.d.mts +19 -1
- package/dist/lib/canonical-references/index.d.ts +19 -1
- package/dist/lib/canonical-references/index.js +81 -9
- package/dist/lib/canonical-references/index.mjs +80 -9
- package/dist/lib/client/core.d.mts +1 -0
- package/dist/lib/client/core.d.ts +1 -0
- package/dist/lib/core/AgentClient.d.mts +9 -1
- package/dist/lib/core/AgentClient.d.ts +9 -1
- package/dist/lib/core/AgentClient.js +10 -0
- package/dist/lib/core/AgentClient.mjs +10 -0
- package/dist/lib/core/SingleAgentClient.d.mts +13 -2
- package/dist/lib/core/SingleAgentClient.d.ts +13 -2
- package/dist/lib/core/SingleAgentClient.js +23 -5
- package/dist/lib/core/SingleAgentClient.mjs +23 -5
- package/dist/lib/index.d.mts +2 -2
- package/dist/lib/index.d.ts +2 -2
- package/dist/lib/index.js +2 -0
- package/dist/lib/index.mjs +3 -1
- package/dist/lib/reporting/gcs/adapter.d.mts +31 -0
- package/dist/lib/reporting/gcs/adapter.d.ts +31 -0
- package/dist/lib/reporting/gcs/adapter.js +342 -0
- package/dist/lib/reporting/gcs/adapter.mjs +325 -0
- package/dist/lib/reporting/gcs/bucket-policy.d.mts +3 -0
- package/dist/lib/reporting/gcs/bucket-policy.d.ts +3 -0
- package/dist/lib/reporting/gcs/bucket-policy.js +31 -0
- package/dist/lib/reporting/gcs/bucket-policy.mjs +7 -0
- package/dist/lib/reporting/gcs/errors.d.mts +5 -0
- package/dist/lib/reporting/gcs/errors.d.ts +5 -0
- package/dist/lib/reporting/gcs/errors.js +41 -0
- package/dist/lib/reporting/gcs/errors.mjs +16 -0
- package/dist/lib/reporting/gcs/fence.d.mts +36 -0
- package/dist/lib/reporting/gcs/fence.d.ts +36 -0
- package/dist/lib/reporting/gcs/fence.js +250 -0
- package/dist/lib/reporting/gcs/fence.mjs +230 -0
- package/dist/lib/reporting/gcs/index.d.mts +7 -0
- package/dist/lib/reporting/gcs/index.d.ts +7 -0
- package/dist/lib/reporting/gcs/index.js +41 -0
- package/dist/lib/reporting/gcs/index.mjs +12 -0
- package/dist/lib/reporting/gcs/io.d.mts +7 -0
- package/dist/lib/reporting/gcs/io.d.ts +7 -0
- package/dist/lib/reporting/gcs/io.js +95 -0
- package/dist/lib/reporting/gcs/io.mjs +69 -0
- package/dist/lib/reporting/gcs/reader.d.mts +43 -0
- package/dist/lib/reporting/gcs/reader.d.ts +43 -0
- package/dist/lib/reporting/gcs/reader.js +193 -0
- package/dist/lib/reporting/gcs/reader.mjs +169 -0
- package/dist/lib/reporting/gcs/validation.d.mts +5 -0
- package/dist/lib/reporting/gcs/validation.d.ts +5 -0
- package/dist/lib/reporting/gcs/validation.js +49 -0
- package/dist/lib/reporting/gcs/validation.mjs +25 -0
- package/dist/lib/reporting/ledger/handler.d.mts +1 -0
- package/dist/lib/reporting/ledger/handler.d.ts +1 -0
- package/dist/lib/reporting/ledger/index.d.mts +1 -0
- package/dist/lib/reporting/ledger/index.d.ts +1 -0
- package/dist/lib/reporting/ledger/index.js +2 -0
- package/dist/lib/reporting/ledger/index.mjs +1 -0
- package/dist/lib/reporting/ledger/managed-postgres.d.mts +16 -1
- package/dist/lib/reporting/ledger/managed-postgres.d.ts +16 -1
- package/dist/lib/reporting/ledger/managed-postgres.js +243 -2
- package/dist/lib/reporting/ledger/managed-postgres.mjs +248 -2
- package/dist/lib/reporting/ledger/object-writes.d.mts +69 -0
- package/dist/lib/reporting/ledger/object-writes.d.ts +69 -0
- package/dist/lib/reporting/ledger/object-writes.js +147 -0
- package/dist/lib/reporting/ledger/object-writes.mjs +114 -0
- package/dist/lib/schemas/index.d.mts +2 -0
- package/dist/lib/schemas/index.d.ts +2 -0
- package/dist/lib/schemas/index.js +3 -0
- package/dist/lib/schemas/index.mjs +2 -0
- package/dist/lib/schemas-data/v2.5/_provenance.json +1 -1
- package/dist/lib/server/a2a-adapter.d.mts +50 -1
- package/dist/lib/server/a2a-adapter.d.ts +50 -1
- package/dist/lib/server/a2a-adapter.js +230 -7
- package/dist/lib/server/a2a-adapter.mjs +237 -7
- package/dist/lib/server/auth-signature.d.mts +84 -46
- package/dist/lib/server/auth-signature.d.ts +84 -46
- package/dist/lib/server/auth-signature.js +48 -14
- package/dist/lib/server/auth-signature.mjs +58 -15
- package/dist/lib/server/create-adcp-server.js +5 -16
- package/dist/lib/server/create-adcp-server.mjs +5 -16
- package/dist/lib/server/index.d.mts +1 -1
- package/dist/lib/server/index.d.ts +1 -1
- package/dist/lib/server/index.js +2 -0
- package/dist/lib/server/index.mjs +3 -1
- package/dist/lib/signing/agent-fetch.js +3 -33
- package/dist/lib/signing/agent-fetch.mjs +3 -33
- package/dist/lib/signing/middleware.d.mts +9 -1
- package/dist/lib/signing/middleware.d.ts +9 -1
- package/dist/lib/signing/operation-resolution.d.mts +37 -0
- package/dist/lib/signing/operation-resolution.d.ts +37 -0
- package/dist/lib/signing/operation-resolution.js +154 -0
- package/dist/lib/signing/operation-resolution.mjs +125 -0
- package/dist/lib/signing/postgres-replay-store.d.mts +1 -1
- package/dist/lib/signing/postgres-replay-store.d.ts +1 -1
- package/dist/lib/signing/redis-replay-store.d.mts +1 -1
- package/dist/lib/signing/redis-replay-store.d.ts +1 -1
- package/dist/lib/signing/server.d.mts +1 -0
- package/dist/lib/signing/server.d.ts +1 -0
- package/dist/lib/signing/server.js +7 -0
- package/dist/lib/signing/server.mjs +8 -0
- package/dist/lib/signing/verifier.d.mts +36 -1
- package/dist/lib/signing/verifier.d.ts +36 -1
- package/dist/lib/signing/verifier.js +66 -34
- package/dist/lib/signing/verifier.mjs +61 -34
- package/dist/lib/testing/client.js +8 -3
- package/dist/lib/testing/client.mjs +8 -3
- package/dist/lib/testing/storyboard/request-signing/a2a-dispatch.d.mts +12 -0
- package/dist/lib/testing/storyboard/request-signing/a2a-dispatch.d.ts +12 -0
- package/dist/lib/testing/storyboard/request-signing/a2a-dispatch.js +29 -2
- package/dist/lib/testing/storyboard/request-signing/a2a-dispatch.mjs +27 -1
- package/dist/lib/testing/storyboard/request-signing/a2a-operation-resolution.d.mts +61 -0
- package/dist/lib/testing/storyboard/request-signing/a2a-operation-resolution.d.ts +61 -0
- package/dist/lib/testing/storyboard/request-signing/a2a-operation-resolution.js +298 -0
- package/dist/lib/testing/storyboard/request-signing/a2a-operation-resolution.mjs +276 -0
- package/dist/lib/testing/storyboard/request-signing/grader.d.mts +31 -1
- package/dist/lib/testing/storyboard/request-signing/grader.d.ts +31 -1
- package/dist/lib/testing/storyboard/request-signing/grader.js +11 -0
- package/dist/lib/testing/storyboard/request-signing/grader.mjs +11 -0
- package/dist/lib/testing/storyboard/request-signing/index.d.mts +5 -4
- package/dist/lib/testing/storyboard/request-signing/index.d.ts +5 -4
- package/dist/lib/testing/storyboard/request-signing/index.js +13 -0
- package/dist/lib/testing/storyboard/request-signing/index.mjs +18 -2
- package/dist/lib/testing/storyboard/request-signing/types.d.mts +43 -0
- package/dist/lib/testing/storyboard/request-signing/types.d.ts +43 -0
- package/dist/lib/testing/storyboard/request-signing/types.js +3 -0
- package/dist/lib/testing/storyboard/request-signing/types.mjs +2 -0
- package/dist/lib/testing/storyboard/request-signing/vector-loader.d.mts +42 -1
- package/dist/lib/testing/storyboard/request-signing/vector-loader.d.ts +42 -1
- package/dist/lib/testing/storyboard/request-signing/vector-loader.js +100 -1
- package/dist/lib/testing/storyboard/request-signing/vector-loader.mjs +104 -3
- package/dist/lib/testing/storyboard/validations.d.mts +1 -1
- package/dist/lib/testing/storyboard/validations.d.ts +1 -1
- package/dist/lib/testing/types.d.mts +10 -1
- package/dist/lib/testing/types.d.ts +10 -1
- package/dist/lib/version.d.mts +3 -3
- package/dist/lib/version.d.ts +3 -3
- package/dist/lib/version.js +3 -3
- package/dist/lib/version.mjs +3 -3
- package/docs/TYPE-SUMMARY.md +2 -2
- package/docs/ZOD-SCHEMAS.md +19 -0
- package/docs/guides/BUILD-AN-AGENT.md +9 -4
- package/docs/guides/CREATIVE-DELIVERY.md +34 -0
- package/docs/guides/OAUTH-ISSUER-BINDING.md +46 -0
- package/docs/guides/REPORTING-GCS-FENCE.md +52 -0
- package/docs/guides/REPORTING-GCS-MANAGED.md +56 -0
- package/docs/guides/REPORTING-OPERATIONS.md +4 -0
- package/docs/guides/SIGNING-GUIDE.md +20 -6
- package/docs/guides/VALIDATE-YOUR-AGENT.md +4 -0
- package/docs/guides/WEB-OAUTH.md +58 -163
- package/docs/guides/account-resolution.md +1 -1
- package/docs/llms.txt +2 -2
- package/docs/migration-14.0-to-14.1.md +1 -1
- package/docs/migration-14.x-rc-worksheet.md +8 -7
- package/docs/migration-buyer-agent-registry.md +1 -1
- package/docs/migration-oauth-issuer-bindings.md +14 -79
- package/package.json +19 -1
- package/skills/build-seller-agent/specialisms/signed-requests.md +2 -0
|
@@ -0,0 +1,342 @@
|
|
|
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 adapter_exports = {};
|
|
20
|
+
__export(adapter_exports, {
|
|
21
|
+
createGcsReportingManagedDeliveryAdapterV1: () => createGcsReportingManagedDeliveryAdapterV1
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(adapter_exports);
|
|
24
|
+
var import_node_crypto = require("node:crypto");
|
|
25
|
+
var import_jcs = require('../../utils/jcs.js');
|
|
26
|
+
var import_inspection = require('../inspection.js');
|
|
27
|
+
var import_handler = require('../ledger/handler.js');
|
|
28
|
+
var import_object_writes = require('../ledger/object-writes.js');
|
|
29
|
+
var import_fence = require('./fence.js');
|
|
30
|
+
var import_errors = require('./errors.js');
|
|
31
|
+
var import_io = require('./io.js');
|
|
32
|
+
var import_validation = require('./validation.js');
|
|
33
|
+
var import_reader = require('./reader.js');
|
|
34
|
+
const hash = (bytes) => (0, import_node_crypto.createHash)("sha256").update(bytes).digest("hex");
|
|
35
|
+
const scopeFor = (binding) => ({
|
|
36
|
+
account_id: binding.account_id,
|
|
37
|
+
destination_ref: binding.destination_ref,
|
|
38
|
+
generation: binding.authorization_generation
|
|
39
|
+
});
|
|
40
|
+
function deliveryIdentity(input) {
|
|
41
|
+
return hash(
|
|
42
|
+
(0, import_jcs.canonicalize)([
|
|
43
|
+
input.binding.configurationId,
|
|
44
|
+
input.binding.delivery_config_id,
|
|
45
|
+
input.binding.delivery_config_version,
|
|
46
|
+
input.materialization.reporting_materialization_id,
|
|
47
|
+
input.materialization.reporting_revision_id,
|
|
48
|
+
input.materialization.reporting_obligation_id
|
|
49
|
+
])
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
function matchingBinding(input) {
|
|
53
|
+
const { materialization: m, binding: b } = input;
|
|
54
|
+
if (b.method !== "file_transfer" || b.transport !== "gcs" || m.method !== b.method || m.transport !== b.transport || m.destination_ref !== b.destination_ref || m.delivery_config_id !== b.delivery_config_id || m.delivery_config_version !== b.delivery_config_version || m.feed_purpose !== b.feed_purpose || !["manifest_checksums", "canonical_digest"].includes(b.verification_profile) || !Number.isSafeInteger(b.resource_retention_days) || b.resource_retention_days < 1 || b.resource_retention_days > 3650)
|
|
55
|
+
throw new import_errors.ReportingGcsFenceError("INVALID_INPUT");
|
|
56
|
+
}
|
|
57
|
+
async function createGcsReportingManagedDeliveryAdapterV1(options, context = {}) {
|
|
58
|
+
const milliseconds = options.operationDeadlineMilliseconds ?? 6e4;
|
|
59
|
+
const { resolveExpectedPeriod, resolveContractReader, namespace: hostNamespace } = options;
|
|
60
|
+
const minimumDays = options.minimumResourceRetentionDays ?? 1;
|
|
61
|
+
if (options.acknowledgeDedicatedFreshBucket !== true || typeof hostNamespace !== "string" || hostNamespace.length < 1 || hostNamespace.length > 255 || !Number.isSafeInteger(minimumDays) || minimumDays < 1 || minimumDays > 3650 || typeof options.resolveExpectedPeriod !== "function" || typeof options.resolveContractReader !== "function")
|
|
62
|
+
throw new import_errors.ReportingGcsFenceError("INVALID_INPUT");
|
|
63
|
+
const { storage, coreStore, store, bucket } = options;
|
|
64
|
+
const { id, fence } = await (0, import_io.withGcsDeadline)(
|
|
65
|
+
async (signal) => {
|
|
66
|
+
if (await store.probeObjectWriteAuthority({ signal }) !== true)
|
|
67
|
+
throw new import_errors.ReportingGcsFenceError("STATE_UNAVAILABLE");
|
|
68
|
+
(0, import_io.activeGcsSignal)(signal);
|
|
69
|
+
if (await store.probe(coreStore) !== true) throw new import_errors.ReportingGcsFenceError("STATE_UNAVAILABLE");
|
|
70
|
+
(0, import_io.activeGcsSignal)(signal);
|
|
71
|
+
const id2 = await store.getObjectWriteAuthorityId({ signal });
|
|
72
|
+
(0, import_io.activeGcsSignal)(signal);
|
|
73
|
+
const fence2 = (0, import_fence.createGcsReportingObjectFenceV1)({
|
|
74
|
+
storage,
|
|
75
|
+
store,
|
|
76
|
+
bucket,
|
|
77
|
+
namespace: hash((0, import_jcs.canonicalize)([hostNamespace, id2])),
|
|
78
|
+
operationDeadlineMilliseconds: milliseconds
|
|
79
|
+
});
|
|
80
|
+
await fence2.probe({ signal });
|
|
81
|
+
(0, import_io.activeGcsSignal)(signal);
|
|
82
|
+
return { id: id2, fence: fence2 };
|
|
83
|
+
},
|
|
84
|
+
{ signal: context.signal, milliseconds }
|
|
85
|
+
);
|
|
86
|
+
const getStatus = (0, import_handler.createReportingStatusHandler)(coreStore);
|
|
87
|
+
async function readerOptions(binding, signal) {
|
|
88
|
+
const scope = scopeFor(binding);
|
|
89
|
+
const provider = await store.getAuthorizedObjectWriteBinding(scope, { signal });
|
|
90
|
+
(0, import_io.activeGcsSignal)(signal);
|
|
91
|
+
if (!provider) throw new import_errors.ReportingGcsFenceError("REVOKED");
|
|
92
|
+
const prefix = `adcp-reporting/${provider.namespace_key}/${(0, import_object_writes.reportingObjectWriteScopeKey)(scope)}/`;
|
|
93
|
+
return {
|
|
94
|
+
scope: { ...scope, principal_id: `producer:${id}` },
|
|
95
|
+
bucket: provider.bucket,
|
|
96
|
+
objectPrefix: prefix,
|
|
97
|
+
getStorage: async () => storage,
|
|
98
|
+
authorize: async (request, call) => {
|
|
99
|
+
if (request.bucket !== provider.bucket || request.objectPrefix !== prefix || request.scope.principal_id !== `producer:${id}` || request.scope.account_id !== scope.account_id || request.scope.destination_ref !== scope.destination_ref || request.scope.generation !== scope.generation)
|
|
100
|
+
return false;
|
|
101
|
+
const current = await store.getAuthorizedObjectWriteBinding(scope, { signal: call.signal });
|
|
102
|
+
return current?.bucket === provider.bucket && current.namespace_key === provider.namespace_key;
|
|
103
|
+
},
|
|
104
|
+
operationDeadlineMilliseconds: milliseconds
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
async function trueObligation(input, signal) {
|
|
108
|
+
let cursor;
|
|
109
|
+
for (let page = 0; page < 25; page++) {
|
|
110
|
+
(0, import_io.activeGcsSignal)(signal);
|
|
111
|
+
const status = await getStatus(
|
|
112
|
+
{
|
|
113
|
+
account: { account_id: input.binding.account_id },
|
|
114
|
+
view: "periods",
|
|
115
|
+
delivery_config_ids: [input.binding.delivery_config_id],
|
|
116
|
+
period: input.revision.wireRevision.period,
|
|
117
|
+
pagination: { max_results: 100, ...cursor ? { cursor } : {} }
|
|
118
|
+
},
|
|
119
|
+
{ account: { id: input.binding.account_id, account_id: input.binding.account_id }, signal }
|
|
120
|
+
);
|
|
121
|
+
(0, import_io.activeGcsSignal)(signal);
|
|
122
|
+
const selected = status.periods?.find(
|
|
123
|
+
(value) => value.reporting_obligation_id === input.obligation.reporting_obligation_id
|
|
124
|
+
);
|
|
125
|
+
if (selected) return selected;
|
|
126
|
+
cursor = status.pagination?.cursor;
|
|
127
|
+
if (!cursor) break;
|
|
128
|
+
}
|
|
129
|
+
throw new import_errors.ReportingGcsFenceError("STATE_UNAVAILABLE");
|
|
130
|
+
}
|
|
131
|
+
async function hostCallback(work, signal) {
|
|
132
|
+
try {
|
|
133
|
+
const result = await work();
|
|
134
|
+
(0, import_io.activeGcsSignal)(signal);
|
|
135
|
+
return result;
|
|
136
|
+
} catch {
|
|
137
|
+
(0, import_io.activeGcsSignal)(signal);
|
|
138
|
+
throw new import_errors.ReportingGcsFenceError("HOST_CALLBACK_FAILED");
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
verificationProfiles: Object.freeze(["manifest_checksums", "canonical_digest"]),
|
|
143
|
+
revocationFencesDeliveryGenerations: true,
|
|
144
|
+
async deliver(caller, call) {
|
|
145
|
+
return (0, import_io.withGcsDeadline)(
|
|
146
|
+
async (signal) => {
|
|
147
|
+
matchingBinding(caller);
|
|
148
|
+
if (!Number.isSafeInteger(caller.maxBytes) || caller.maxBytes < 1 || caller.maxBytes > 64 * 1024 * 1024 || caller.revision.binding.byteCount > caller.maxBytes || caller.revision.rows.length > 1e5)
|
|
149
|
+
throw new import_errors.ReportingGcsFenceError("INVALID_INPUT");
|
|
150
|
+
const input = structuredClone(caller);
|
|
151
|
+
matchingBinding(input);
|
|
152
|
+
if (input.revision.rows.length > 1e5 || input.revision.binding.byteCount > input.maxBytes || !Number.isSafeInteger(input.maxBytes) || input.maxBytes < 1 || input.maxBytes > 64 * 1024 * 1024)
|
|
153
|
+
throw new import_errors.ReportingGcsFenceError("INVALID_INPUT");
|
|
154
|
+
const { revision, binding, materialization, obligation } = input;
|
|
155
|
+
if (revision.reporting_revision_id !== materialization.reporting_revision_id || revision.reporting_obligation_id !== obligation.reporting_obligation_id || materialization.reporting_obligation_id !== obligation.reporting_obligation_id || obligation.account.account_id !== binding.account_id || obligation.configurationId !== binding.configurationId || obligation.delivery_config_id !== binding.delivery_config_id || obligation.delivery_config_version !== binding.delivery_config_version)
|
|
156
|
+
throw new import_errors.ReportingGcsFenceError("INVALID_INPUT");
|
|
157
|
+
const coreBytes = Buffer.from(
|
|
158
|
+
(0, import_jcs.canonicalize)({
|
|
159
|
+
reporting_revision_id: revision.reporting_revision_id,
|
|
160
|
+
row_count: revision.wireRevision.row_count,
|
|
161
|
+
control_totals: revision.wireRevision.control_totals,
|
|
162
|
+
reporting_rows: revision.rows
|
|
163
|
+
})
|
|
164
|
+
);
|
|
165
|
+
if (revision.binding.algorithm !== "rfc8785_jcs_v1" || coreBytes.length !== revision.binding.byteCount || hash(coreBytes) !== revision.binding.sha256 || revision.wireRevision.revision_content_sha256 !== revision.binding.sha256 || revision.binding.rowCount !== revision.rows.length || revision.wireRevision.row_count !== revision.rows.length)
|
|
166
|
+
throw new import_errors.ReportingGcsFenceError("CONTENT_CONFLICT");
|
|
167
|
+
const expected = await hostCallback(async () => {
|
|
168
|
+
const value = structuredClone(await resolveExpectedPeriod(structuredClone(input), { signal }));
|
|
169
|
+
if (!value || typeof value !== "object" || !Array.isArray(value.mediaBuyIds) || !value.coverage || typeof value.coverage !== "object" || Array.isArray(value.coverage) || value.verificationProfile === "canonical_digest" && (!value.canonicalization || typeof value.canonicalization !== "object"))
|
|
170
|
+
throw new import_errors.ReportingGcsFenceError("HOST_CALLBACK_FAILED");
|
|
171
|
+
return value;
|
|
172
|
+
}, signal);
|
|
173
|
+
(0, import_io.activeGcsSignal)(signal);
|
|
174
|
+
(0, import_validation.assertExpectedBinding)(input, expected);
|
|
175
|
+
const actualObligation = await trueObligation(input, signal);
|
|
176
|
+
const contractOptions = await hostCallback(
|
|
177
|
+
() => resolveContractReader(structuredClone(input), { signal }),
|
|
178
|
+
signal
|
|
179
|
+
);
|
|
180
|
+
(0, import_io.activeGcsSignal)(signal);
|
|
181
|
+
if (!contractOptions || typeof contractOptions !== "object" || !contractOptions.scope)
|
|
182
|
+
throw new import_errors.ReportingGcsFenceError("HOST_CALLBACK_FAILED");
|
|
183
|
+
let contractResolver;
|
|
184
|
+
try {
|
|
185
|
+
contractResolver = (0, import_reader.createGcsReportingReferenceResolverV1)({
|
|
186
|
+
...contractOptions,
|
|
187
|
+
signal: contractOptions.signal ? AbortSignal.any([signal, contractOptions.signal]) : signal
|
|
188
|
+
});
|
|
189
|
+
} catch {
|
|
190
|
+
throw new import_errors.ReportingGcsFenceError("HOST_CALLBACK_FAILED");
|
|
191
|
+
}
|
|
192
|
+
if (contractOptions.scope.account_id !== binding.account_id || contractOptions.scope.destination_ref !== binding.destination_ref || contractOptions.scope.generation !== binding.authorization_generation)
|
|
193
|
+
throw new import_errors.ReportingGcsFenceError("INVALID_INPUT");
|
|
194
|
+
const rows = Buffer.from(revision.rows.map((row) => (0, import_jcs.canonicalize)(row) + "\n").join(""));
|
|
195
|
+
const manifestBytes = Buffer.from(
|
|
196
|
+
(0, import_jcs.canonicalize)({
|
|
197
|
+
manifest_version: "1.0",
|
|
198
|
+
complete: true,
|
|
199
|
+
reporting_revision_id: revision.reporting_revision_id,
|
|
200
|
+
reporting_obligation_id: obligation.reporting_obligation_id,
|
|
201
|
+
reporting_materialization_id: materialization.reporting_materialization_id,
|
|
202
|
+
period: revision.wireRevision.period,
|
|
203
|
+
format: "jsonl",
|
|
204
|
+
compression: "none",
|
|
205
|
+
files: [
|
|
206
|
+
{ object_ref: "0", size_bytes: rows.length, sha256: hash(rows), row_count: revision.rows.length }
|
|
207
|
+
],
|
|
208
|
+
total_size_bytes: rows.length,
|
|
209
|
+
row_count: revision.rows.length,
|
|
210
|
+
control_totals: revision.wireRevision.control_totals,
|
|
211
|
+
created_at: revision.createdAt
|
|
212
|
+
})
|
|
213
|
+
);
|
|
214
|
+
if (rows.length + manifestBytes.length > input.maxBytes) throw new import_errors.ReportingGcsFenceError("INVALID_INPUT");
|
|
215
|
+
const scope = scopeFor(binding);
|
|
216
|
+
const plan = await fence.register(scope, deliveryIdentity(input), [rows, manifestBytes], { signal });
|
|
217
|
+
(0, import_io.activeGcsSignal)(signal);
|
|
218
|
+
await fence.write(plan, 0, rows, { signal });
|
|
219
|
+
await fence.write(plan, 1, manifestBytes, { signal });
|
|
220
|
+
(0, import_io.activeGcsSignal)(signal);
|
|
221
|
+
const readerConfig = await readerOptions(binding, signal);
|
|
222
|
+
const location = `https://storage.googleapis.com/${plan.provider.bucket}/${plan.objects[1].object_name}`;
|
|
223
|
+
const read = await (0, import_reader.createGcsScopedObjectReadV1)(readerConfig)(location, input.maxBytes, signal);
|
|
224
|
+
(0, import_io.activeGcsSignal)(signal);
|
|
225
|
+
if (hash(read.body) !== hash(manifestBytes)) throw new import_errors.ReportingGcsFenceError("CONTENT_CONFLICT");
|
|
226
|
+
const resource = {
|
|
227
|
+
resource_ref: `gcs:${plan.plan_id}`,
|
|
228
|
+
kind: "manifest",
|
|
229
|
+
location,
|
|
230
|
+
manifest_version: "1.0",
|
|
231
|
+
manifest_sha256: hash(read.body),
|
|
232
|
+
immutability: "native_version",
|
|
233
|
+
native_version_ref: read.generation,
|
|
234
|
+
expires_at: new Date(
|
|
235
|
+
Date.now() + Math.max(minimumDays, binding.resource_retention_days) * 864e5
|
|
236
|
+
).toISOString(),
|
|
237
|
+
reader_compatibility: ["jsonl", "utf-8"]
|
|
238
|
+
};
|
|
239
|
+
const inspectionContext = {
|
|
240
|
+
obligation: actualObligation,
|
|
241
|
+
revision: revision.wireRevision,
|
|
242
|
+
materialization: { ...materialization, resource },
|
|
243
|
+
expected
|
|
244
|
+
};
|
|
245
|
+
const reader = (0, import_reader.createGcsReportingResourceReaderV1)(readerConfig);
|
|
246
|
+
const observedChecksums = /* @__PURE__ */ new Map();
|
|
247
|
+
const inspect = (0, import_inspection.createReportingManifestInspector)({
|
|
248
|
+
reader: {
|
|
249
|
+
async read(request) {
|
|
250
|
+
const result = await reader.read({
|
|
251
|
+
...request,
|
|
252
|
+
signal: request.signal ? AbortSignal.any([signal, request.signal]) : signal
|
|
253
|
+
});
|
|
254
|
+
(0, import_io.activeGcsSignal)(signal);
|
|
255
|
+
if (request.role === "object")
|
|
256
|
+
observedChecksums.set(request.objectRef, {
|
|
257
|
+
object_ref: request.objectRef,
|
|
258
|
+
algorithm: "sha256",
|
|
259
|
+
value: hash(result.body)
|
|
260
|
+
});
|
|
261
|
+
return result;
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
referenceResolver: contractResolver,
|
|
265
|
+
referenceAllowedOrigins: ["https://storage.googleapis.com"],
|
|
266
|
+
maxTotalBytes: input.maxBytes,
|
|
267
|
+
maxObjectBytes: input.maxBytes,
|
|
268
|
+
maxRows: 1e5
|
|
269
|
+
});
|
|
270
|
+
const observation = await inspect(inspectionContext);
|
|
271
|
+
(0, import_io.activeGcsSignal)(signal);
|
|
272
|
+
if (!observedChecksums.size) throw new import_errors.ReportingGcsFenceError("CONTENT_CONFLICT");
|
|
273
|
+
resource.expires_at = new Date(
|
|
274
|
+
Date.now() + Math.max(minimumDays, binding.resource_retention_days) * 864e5 + milliseconds
|
|
275
|
+
).toISOString();
|
|
276
|
+
const checksums = [...observedChecksums.values()];
|
|
277
|
+
if (checksums.length !== 1 || checksums[0].object_ref !== "0" || checksums[0].value !== plan.objects[0].sha256)
|
|
278
|
+
throw new import_errors.ReportingGcsFenceError("CONTENT_CONFLICT");
|
|
279
|
+
const verification = {
|
|
280
|
+
verified_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
281
|
+
verification_path: "producer",
|
|
282
|
+
verification_profile: binding.verification_profile,
|
|
283
|
+
row_count: observation.rowCount,
|
|
284
|
+
control_totals: observation.controlTotals,
|
|
285
|
+
physical_checksums: [checksums[0], ...checksums.slice(1)],
|
|
286
|
+
...observation.canonicalContentDigest ? { canonical_content_digest: observation.canonicalContentDigest } : {}
|
|
287
|
+
};
|
|
288
|
+
if (!await store.getAuthorizedObjectWriteBinding(scope, { signal }))
|
|
289
|
+
throw new import_errors.ReportingGcsFenceError("REVOKED");
|
|
290
|
+
(0, import_io.activeGcsSignal)(signal);
|
|
291
|
+
return { status: "available", resource, verification };
|
|
292
|
+
},
|
|
293
|
+
{ signal: call.signal, milliseconds }
|
|
294
|
+
);
|
|
295
|
+
},
|
|
296
|
+
async read(caller, call) {
|
|
297
|
+
return (0, import_io.withGcsDeadline)(
|
|
298
|
+
async (signal) => {
|
|
299
|
+
const input = structuredClone(caller);
|
|
300
|
+
matchingBinding(input);
|
|
301
|
+
const planId = hash(deliveryIdentity(input));
|
|
302
|
+
const scope = scopeFor(input.binding);
|
|
303
|
+
const plan = await store.getObjectWritePlan(scope, planId, { signal });
|
|
304
|
+
(0, import_io.activeGcsSignal)(signal);
|
|
305
|
+
if (!plan) throw new import_errors.ReportingGcsFenceError("REVOKED");
|
|
306
|
+
const location = `https://storage.googleapis.com/${plan.provider.bucket}/${(0, import_object_writes.reportingObjectWriteName)(scope, plan.provider, planId, 1)}`;
|
|
307
|
+
if (plan.objects.length !== 2 || input.resource.resource_ref !== `gcs:${planId}` || input.resource.location !== location || input.resource.kind !== "manifest" || input.resource.immutability !== "native_version" || !input.resource.native_version_ref || !Number.isFinite(Date.parse(input.resource.expires_at ?? "")) || input.resource.manifest_sha256 !== plan.objects[1]?.sha256)
|
|
308
|
+
throw new import_errors.ReportingGcsFenceError("INVALID_INPUT");
|
|
309
|
+
const config = await readerOptions(input.binding, signal);
|
|
310
|
+
const result = await (0, import_reader.createGcsScopedObjectReadV1)(config)(
|
|
311
|
+
location,
|
|
312
|
+
input.maxBytes,
|
|
313
|
+
signal,
|
|
314
|
+
input.resource.native_version_ref
|
|
315
|
+
);
|
|
316
|
+
if (hash(result.body) !== input.resource.manifest_sha256)
|
|
317
|
+
throw new import_errors.ReportingGcsFenceError("CONTENT_CONFLICT");
|
|
318
|
+
return result.body;
|
|
319
|
+
},
|
|
320
|
+
{ signal: call.signal, milliseconds }
|
|
321
|
+
);
|
|
322
|
+
},
|
|
323
|
+
async revoke(input, call) {
|
|
324
|
+
await (0, import_io.withGcsDeadline)(
|
|
325
|
+
async (signal) => {
|
|
326
|
+
for (let page = 0; page < 1e3; page++) {
|
|
327
|
+
(0, import_io.activeGcsSignal)(signal);
|
|
328
|
+
const result = await fence.revoke(input.authorization, { signal });
|
|
329
|
+
if (result.complete) return;
|
|
330
|
+
if (result.fenced < 1) throw new import_errors.ReportingGcsFenceError("STATE_UNAVAILABLE");
|
|
331
|
+
}
|
|
332
|
+
throw new import_errors.ReportingGcsFenceError("STATE_UNAVAILABLE");
|
|
333
|
+
},
|
|
334
|
+
{ signal: call.signal, milliseconds }
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
340
|
+
0 && (module.exports = {
|
|
341
|
+
createGcsReportingManagedDeliveryAdapterV1
|
|
342
|
+
});
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { canonicalize } from "../../utils/jcs.mjs";
|
|
3
|
+
import { createReportingManifestInspector } from "../inspection.mjs";
|
|
4
|
+
import { createReportingStatusHandler } from "../ledger/handler.mjs";
|
|
5
|
+
import {
|
|
6
|
+
reportingObjectWriteName,
|
|
7
|
+
reportingObjectWriteScopeKey
|
|
8
|
+
} from "../ledger/object-writes.mjs";
|
|
9
|
+
import { createGcsReportingObjectFenceV1 } from "./fence.mjs";
|
|
10
|
+
import { ReportingGcsFenceError } from "./errors.mjs";
|
|
11
|
+
import { activeGcsSignal, withGcsDeadline } from "./io.mjs";
|
|
12
|
+
import { assertExpectedBinding } from "./validation.mjs";
|
|
13
|
+
import {
|
|
14
|
+
createGcsReportingResourceReaderV1,
|
|
15
|
+
createGcsReportingReferenceResolverV1,
|
|
16
|
+
createGcsScopedObjectReadV1
|
|
17
|
+
} from "./reader.mjs";
|
|
18
|
+
const hash = (bytes) => createHash("sha256").update(bytes).digest("hex");
|
|
19
|
+
const scopeFor = (binding) => ({
|
|
20
|
+
account_id: binding.account_id,
|
|
21
|
+
destination_ref: binding.destination_ref,
|
|
22
|
+
generation: binding.authorization_generation
|
|
23
|
+
});
|
|
24
|
+
function deliveryIdentity(input) {
|
|
25
|
+
return hash(
|
|
26
|
+
canonicalize([
|
|
27
|
+
input.binding.configurationId,
|
|
28
|
+
input.binding.delivery_config_id,
|
|
29
|
+
input.binding.delivery_config_version,
|
|
30
|
+
input.materialization.reporting_materialization_id,
|
|
31
|
+
input.materialization.reporting_revision_id,
|
|
32
|
+
input.materialization.reporting_obligation_id
|
|
33
|
+
])
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
function matchingBinding(input) {
|
|
37
|
+
const { materialization: m, binding: b } = input;
|
|
38
|
+
if (b.method !== "file_transfer" || b.transport !== "gcs" || m.method !== b.method || m.transport !== b.transport || m.destination_ref !== b.destination_ref || m.delivery_config_id !== b.delivery_config_id || m.delivery_config_version !== b.delivery_config_version || m.feed_purpose !== b.feed_purpose || !["manifest_checksums", "canonical_digest"].includes(b.verification_profile) || !Number.isSafeInteger(b.resource_retention_days) || b.resource_retention_days < 1 || b.resource_retention_days > 3650)
|
|
39
|
+
throw new ReportingGcsFenceError("INVALID_INPUT");
|
|
40
|
+
}
|
|
41
|
+
async function createGcsReportingManagedDeliveryAdapterV1(options, context = {}) {
|
|
42
|
+
const milliseconds = options.operationDeadlineMilliseconds ?? 6e4;
|
|
43
|
+
const { resolveExpectedPeriod, resolveContractReader, namespace: hostNamespace } = options;
|
|
44
|
+
const minimumDays = options.minimumResourceRetentionDays ?? 1;
|
|
45
|
+
if (options.acknowledgeDedicatedFreshBucket !== true || typeof hostNamespace !== "string" || hostNamespace.length < 1 || hostNamespace.length > 255 || !Number.isSafeInteger(minimumDays) || minimumDays < 1 || minimumDays > 3650 || typeof options.resolveExpectedPeriod !== "function" || typeof options.resolveContractReader !== "function")
|
|
46
|
+
throw new ReportingGcsFenceError("INVALID_INPUT");
|
|
47
|
+
const { storage, coreStore, store, bucket } = options;
|
|
48
|
+
const { id, fence } = await withGcsDeadline(
|
|
49
|
+
async (signal) => {
|
|
50
|
+
if (await store.probeObjectWriteAuthority({ signal }) !== true)
|
|
51
|
+
throw new ReportingGcsFenceError("STATE_UNAVAILABLE");
|
|
52
|
+
activeGcsSignal(signal);
|
|
53
|
+
if (await store.probe(coreStore) !== true) throw new ReportingGcsFenceError("STATE_UNAVAILABLE");
|
|
54
|
+
activeGcsSignal(signal);
|
|
55
|
+
const id2 = await store.getObjectWriteAuthorityId({ signal });
|
|
56
|
+
activeGcsSignal(signal);
|
|
57
|
+
const fence2 = createGcsReportingObjectFenceV1({
|
|
58
|
+
storage,
|
|
59
|
+
store,
|
|
60
|
+
bucket,
|
|
61
|
+
namespace: hash(canonicalize([hostNamespace, id2])),
|
|
62
|
+
operationDeadlineMilliseconds: milliseconds
|
|
63
|
+
});
|
|
64
|
+
await fence2.probe({ signal });
|
|
65
|
+
activeGcsSignal(signal);
|
|
66
|
+
return { id: id2, fence: fence2 };
|
|
67
|
+
},
|
|
68
|
+
{ signal: context.signal, milliseconds }
|
|
69
|
+
);
|
|
70
|
+
const getStatus = createReportingStatusHandler(coreStore);
|
|
71
|
+
async function readerOptions(binding, signal) {
|
|
72
|
+
const scope = scopeFor(binding);
|
|
73
|
+
const provider = await store.getAuthorizedObjectWriteBinding(scope, { signal });
|
|
74
|
+
activeGcsSignal(signal);
|
|
75
|
+
if (!provider) throw new ReportingGcsFenceError("REVOKED");
|
|
76
|
+
const prefix = `adcp-reporting/${provider.namespace_key}/${reportingObjectWriteScopeKey(scope)}/`;
|
|
77
|
+
return {
|
|
78
|
+
scope: { ...scope, principal_id: `producer:${id}` },
|
|
79
|
+
bucket: provider.bucket,
|
|
80
|
+
objectPrefix: prefix,
|
|
81
|
+
getStorage: async () => storage,
|
|
82
|
+
authorize: async (request, call) => {
|
|
83
|
+
if (request.bucket !== provider.bucket || request.objectPrefix !== prefix || request.scope.principal_id !== `producer:${id}` || request.scope.account_id !== scope.account_id || request.scope.destination_ref !== scope.destination_ref || request.scope.generation !== scope.generation)
|
|
84
|
+
return false;
|
|
85
|
+
const current = await store.getAuthorizedObjectWriteBinding(scope, { signal: call.signal });
|
|
86
|
+
return current?.bucket === provider.bucket && current.namespace_key === provider.namespace_key;
|
|
87
|
+
},
|
|
88
|
+
operationDeadlineMilliseconds: milliseconds
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
async function trueObligation(input, signal) {
|
|
92
|
+
let cursor;
|
|
93
|
+
for (let page = 0; page < 25; page++) {
|
|
94
|
+
activeGcsSignal(signal);
|
|
95
|
+
const status = await getStatus(
|
|
96
|
+
{
|
|
97
|
+
account: { account_id: input.binding.account_id },
|
|
98
|
+
view: "periods",
|
|
99
|
+
delivery_config_ids: [input.binding.delivery_config_id],
|
|
100
|
+
period: input.revision.wireRevision.period,
|
|
101
|
+
pagination: { max_results: 100, ...cursor ? { cursor } : {} }
|
|
102
|
+
},
|
|
103
|
+
{ account: { id: input.binding.account_id, account_id: input.binding.account_id }, signal }
|
|
104
|
+
);
|
|
105
|
+
activeGcsSignal(signal);
|
|
106
|
+
const selected = status.periods?.find(
|
|
107
|
+
(value) => value.reporting_obligation_id === input.obligation.reporting_obligation_id
|
|
108
|
+
);
|
|
109
|
+
if (selected) return selected;
|
|
110
|
+
cursor = status.pagination?.cursor;
|
|
111
|
+
if (!cursor) break;
|
|
112
|
+
}
|
|
113
|
+
throw new ReportingGcsFenceError("STATE_UNAVAILABLE");
|
|
114
|
+
}
|
|
115
|
+
async function hostCallback(work, signal) {
|
|
116
|
+
try {
|
|
117
|
+
const result = await work();
|
|
118
|
+
activeGcsSignal(signal);
|
|
119
|
+
return result;
|
|
120
|
+
} catch {
|
|
121
|
+
activeGcsSignal(signal);
|
|
122
|
+
throw new ReportingGcsFenceError("HOST_CALLBACK_FAILED");
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
verificationProfiles: Object.freeze(["manifest_checksums", "canonical_digest"]),
|
|
127
|
+
revocationFencesDeliveryGenerations: true,
|
|
128
|
+
async deliver(caller, call) {
|
|
129
|
+
return withGcsDeadline(
|
|
130
|
+
async (signal) => {
|
|
131
|
+
matchingBinding(caller);
|
|
132
|
+
if (!Number.isSafeInteger(caller.maxBytes) || caller.maxBytes < 1 || caller.maxBytes > 64 * 1024 * 1024 || caller.revision.binding.byteCount > caller.maxBytes || caller.revision.rows.length > 1e5)
|
|
133
|
+
throw new ReportingGcsFenceError("INVALID_INPUT");
|
|
134
|
+
const input = structuredClone(caller);
|
|
135
|
+
matchingBinding(input);
|
|
136
|
+
if (input.revision.rows.length > 1e5 || input.revision.binding.byteCount > input.maxBytes || !Number.isSafeInteger(input.maxBytes) || input.maxBytes < 1 || input.maxBytes > 64 * 1024 * 1024)
|
|
137
|
+
throw new ReportingGcsFenceError("INVALID_INPUT");
|
|
138
|
+
const { revision, binding, materialization, obligation } = input;
|
|
139
|
+
if (revision.reporting_revision_id !== materialization.reporting_revision_id || revision.reporting_obligation_id !== obligation.reporting_obligation_id || materialization.reporting_obligation_id !== obligation.reporting_obligation_id || obligation.account.account_id !== binding.account_id || obligation.configurationId !== binding.configurationId || obligation.delivery_config_id !== binding.delivery_config_id || obligation.delivery_config_version !== binding.delivery_config_version)
|
|
140
|
+
throw new ReportingGcsFenceError("INVALID_INPUT");
|
|
141
|
+
const coreBytes = Buffer.from(
|
|
142
|
+
canonicalize({
|
|
143
|
+
reporting_revision_id: revision.reporting_revision_id,
|
|
144
|
+
row_count: revision.wireRevision.row_count,
|
|
145
|
+
control_totals: revision.wireRevision.control_totals,
|
|
146
|
+
reporting_rows: revision.rows
|
|
147
|
+
})
|
|
148
|
+
);
|
|
149
|
+
if (revision.binding.algorithm !== "rfc8785_jcs_v1" || coreBytes.length !== revision.binding.byteCount || hash(coreBytes) !== revision.binding.sha256 || revision.wireRevision.revision_content_sha256 !== revision.binding.sha256 || revision.binding.rowCount !== revision.rows.length || revision.wireRevision.row_count !== revision.rows.length)
|
|
150
|
+
throw new ReportingGcsFenceError("CONTENT_CONFLICT");
|
|
151
|
+
const expected = await hostCallback(async () => {
|
|
152
|
+
const value = structuredClone(await resolveExpectedPeriod(structuredClone(input), { signal }));
|
|
153
|
+
if (!value || typeof value !== "object" || !Array.isArray(value.mediaBuyIds) || !value.coverage || typeof value.coverage !== "object" || Array.isArray(value.coverage) || value.verificationProfile === "canonical_digest" && (!value.canonicalization || typeof value.canonicalization !== "object"))
|
|
154
|
+
throw new ReportingGcsFenceError("HOST_CALLBACK_FAILED");
|
|
155
|
+
return value;
|
|
156
|
+
}, signal);
|
|
157
|
+
activeGcsSignal(signal);
|
|
158
|
+
assertExpectedBinding(input, expected);
|
|
159
|
+
const actualObligation = await trueObligation(input, signal);
|
|
160
|
+
const contractOptions = await hostCallback(
|
|
161
|
+
() => resolveContractReader(structuredClone(input), { signal }),
|
|
162
|
+
signal
|
|
163
|
+
);
|
|
164
|
+
activeGcsSignal(signal);
|
|
165
|
+
if (!contractOptions || typeof contractOptions !== "object" || !contractOptions.scope)
|
|
166
|
+
throw new ReportingGcsFenceError("HOST_CALLBACK_FAILED");
|
|
167
|
+
let contractResolver;
|
|
168
|
+
try {
|
|
169
|
+
contractResolver = createGcsReportingReferenceResolverV1({
|
|
170
|
+
...contractOptions,
|
|
171
|
+
signal: contractOptions.signal ? AbortSignal.any([signal, contractOptions.signal]) : signal
|
|
172
|
+
});
|
|
173
|
+
} catch {
|
|
174
|
+
throw new ReportingGcsFenceError("HOST_CALLBACK_FAILED");
|
|
175
|
+
}
|
|
176
|
+
if (contractOptions.scope.account_id !== binding.account_id || contractOptions.scope.destination_ref !== binding.destination_ref || contractOptions.scope.generation !== binding.authorization_generation)
|
|
177
|
+
throw new ReportingGcsFenceError("INVALID_INPUT");
|
|
178
|
+
const rows = Buffer.from(revision.rows.map((row) => canonicalize(row) + "\n").join(""));
|
|
179
|
+
const manifestBytes = Buffer.from(
|
|
180
|
+
canonicalize({
|
|
181
|
+
manifest_version: "1.0",
|
|
182
|
+
complete: true,
|
|
183
|
+
reporting_revision_id: revision.reporting_revision_id,
|
|
184
|
+
reporting_obligation_id: obligation.reporting_obligation_id,
|
|
185
|
+
reporting_materialization_id: materialization.reporting_materialization_id,
|
|
186
|
+
period: revision.wireRevision.period,
|
|
187
|
+
format: "jsonl",
|
|
188
|
+
compression: "none",
|
|
189
|
+
files: [
|
|
190
|
+
{ object_ref: "0", size_bytes: rows.length, sha256: hash(rows), row_count: revision.rows.length }
|
|
191
|
+
],
|
|
192
|
+
total_size_bytes: rows.length,
|
|
193
|
+
row_count: revision.rows.length,
|
|
194
|
+
control_totals: revision.wireRevision.control_totals,
|
|
195
|
+
created_at: revision.createdAt
|
|
196
|
+
})
|
|
197
|
+
);
|
|
198
|
+
if (rows.length + manifestBytes.length > input.maxBytes) throw new ReportingGcsFenceError("INVALID_INPUT");
|
|
199
|
+
const scope = scopeFor(binding);
|
|
200
|
+
const plan = await fence.register(scope, deliveryIdentity(input), [rows, manifestBytes], { signal });
|
|
201
|
+
activeGcsSignal(signal);
|
|
202
|
+
await fence.write(plan, 0, rows, { signal });
|
|
203
|
+
await fence.write(plan, 1, manifestBytes, { signal });
|
|
204
|
+
activeGcsSignal(signal);
|
|
205
|
+
const readerConfig = await readerOptions(binding, signal);
|
|
206
|
+
const location = `https://storage.googleapis.com/${plan.provider.bucket}/${plan.objects[1].object_name}`;
|
|
207
|
+
const read = await createGcsScopedObjectReadV1(readerConfig)(location, input.maxBytes, signal);
|
|
208
|
+
activeGcsSignal(signal);
|
|
209
|
+
if (hash(read.body) !== hash(manifestBytes)) throw new ReportingGcsFenceError("CONTENT_CONFLICT");
|
|
210
|
+
const resource = {
|
|
211
|
+
resource_ref: `gcs:${plan.plan_id}`,
|
|
212
|
+
kind: "manifest",
|
|
213
|
+
location,
|
|
214
|
+
manifest_version: "1.0",
|
|
215
|
+
manifest_sha256: hash(read.body),
|
|
216
|
+
immutability: "native_version",
|
|
217
|
+
native_version_ref: read.generation,
|
|
218
|
+
expires_at: new Date(
|
|
219
|
+
Date.now() + Math.max(minimumDays, binding.resource_retention_days) * 864e5
|
|
220
|
+
).toISOString(),
|
|
221
|
+
reader_compatibility: ["jsonl", "utf-8"]
|
|
222
|
+
};
|
|
223
|
+
const inspectionContext = {
|
|
224
|
+
obligation: actualObligation,
|
|
225
|
+
revision: revision.wireRevision,
|
|
226
|
+
materialization: { ...materialization, resource },
|
|
227
|
+
expected
|
|
228
|
+
};
|
|
229
|
+
const reader = createGcsReportingResourceReaderV1(readerConfig);
|
|
230
|
+
const observedChecksums = /* @__PURE__ */ new Map();
|
|
231
|
+
const inspect = createReportingManifestInspector({
|
|
232
|
+
reader: {
|
|
233
|
+
async read(request) {
|
|
234
|
+
const result = await reader.read({
|
|
235
|
+
...request,
|
|
236
|
+
signal: request.signal ? AbortSignal.any([signal, request.signal]) : signal
|
|
237
|
+
});
|
|
238
|
+
activeGcsSignal(signal);
|
|
239
|
+
if (request.role === "object")
|
|
240
|
+
observedChecksums.set(request.objectRef, {
|
|
241
|
+
object_ref: request.objectRef,
|
|
242
|
+
algorithm: "sha256",
|
|
243
|
+
value: hash(result.body)
|
|
244
|
+
});
|
|
245
|
+
return result;
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
referenceResolver: contractResolver,
|
|
249
|
+
referenceAllowedOrigins: ["https://storage.googleapis.com"],
|
|
250
|
+
maxTotalBytes: input.maxBytes,
|
|
251
|
+
maxObjectBytes: input.maxBytes,
|
|
252
|
+
maxRows: 1e5
|
|
253
|
+
});
|
|
254
|
+
const observation = await inspect(inspectionContext);
|
|
255
|
+
activeGcsSignal(signal);
|
|
256
|
+
if (!observedChecksums.size) throw new ReportingGcsFenceError("CONTENT_CONFLICT");
|
|
257
|
+
resource.expires_at = new Date(
|
|
258
|
+
Date.now() + Math.max(minimumDays, binding.resource_retention_days) * 864e5 + milliseconds
|
|
259
|
+
).toISOString();
|
|
260
|
+
const checksums = [...observedChecksums.values()];
|
|
261
|
+
if (checksums.length !== 1 || checksums[0].object_ref !== "0" || checksums[0].value !== plan.objects[0].sha256)
|
|
262
|
+
throw new ReportingGcsFenceError("CONTENT_CONFLICT");
|
|
263
|
+
const verification = {
|
|
264
|
+
verified_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
265
|
+
verification_path: "producer",
|
|
266
|
+
verification_profile: binding.verification_profile,
|
|
267
|
+
row_count: observation.rowCount,
|
|
268
|
+
control_totals: observation.controlTotals,
|
|
269
|
+
physical_checksums: [checksums[0], ...checksums.slice(1)],
|
|
270
|
+
...observation.canonicalContentDigest ? { canonical_content_digest: observation.canonicalContentDigest } : {}
|
|
271
|
+
};
|
|
272
|
+
if (!await store.getAuthorizedObjectWriteBinding(scope, { signal }))
|
|
273
|
+
throw new ReportingGcsFenceError("REVOKED");
|
|
274
|
+
activeGcsSignal(signal);
|
|
275
|
+
return { status: "available", resource, verification };
|
|
276
|
+
},
|
|
277
|
+
{ signal: call.signal, milliseconds }
|
|
278
|
+
);
|
|
279
|
+
},
|
|
280
|
+
async read(caller, call) {
|
|
281
|
+
return withGcsDeadline(
|
|
282
|
+
async (signal) => {
|
|
283
|
+
const input = structuredClone(caller);
|
|
284
|
+
matchingBinding(input);
|
|
285
|
+
const planId = hash(deliveryIdentity(input));
|
|
286
|
+
const scope = scopeFor(input.binding);
|
|
287
|
+
const plan = await store.getObjectWritePlan(scope, planId, { signal });
|
|
288
|
+
activeGcsSignal(signal);
|
|
289
|
+
if (!plan) throw new ReportingGcsFenceError("REVOKED");
|
|
290
|
+
const location = `https://storage.googleapis.com/${plan.provider.bucket}/${reportingObjectWriteName(scope, plan.provider, planId, 1)}`;
|
|
291
|
+
if (plan.objects.length !== 2 || input.resource.resource_ref !== `gcs:${planId}` || input.resource.location !== location || input.resource.kind !== "manifest" || input.resource.immutability !== "native_version" || !input.resource.native_version_ref || !Number.isFinite(Date.parse(input.resource.expires_at ?? "")) || input.resource.manifest_sha256 !== plan.objects[1]?.sha256)
|
|
292
|
+
throw new ReportingGcsFenceError("INVALID_INPUT");
|
|
293
|
+
const config = await readerOptions(input.binding, signal);
|
|
294
|
+
const result = await createGcsScopedObjectReadV1(config)(
|
|
295
|
+
location,
|
|
296
|
+
input.maxBytes,
|
|
297
|
+
signal,
|
|
298
|
+
input.resource.native_version_ref
|
|
299
|
+
);
|
|
300
|
+
if (hash(result.body) !== input.resource.manifest_sha256)
|
|
301
|
+
throw new ReportingGcsFenceError("CONTENT_CONFLICT");
|
|
302
|
+
return result.body;
|
|
303
|
+
},
|
|
304
|
+
{ signal: call.signal, milliseconds }
|
|
305
|
+
);
|
|
306
|
+
},
|
|
307
|
+
async revoke(input, call) {
|
|
308
|
+
await withGcsDeadline(
|
|
309
|
+
async (signal) => {
|
|
310
|
+
for (let page = 0; page < 1e3; page++) {
|
|
311
|
+
activeGcsSignal(signal);
|
|
312
|
+
const result = await fence.revoke(input.authorization, { signal });
|
|
313
|
+
if (result.complete) return;
|
|
314
|
+
if (result.fenced < 1) throw new ReportingGcsFenceError("STATE_UNAVAILABLE");
|
|
315
|
+
}
|
|
316
|
+
throw new ReportingGcsFenceError("STATE_UNAVAILABLE");
|
|
317
|
+
},
|
|
318
|
+
{ signal: call.signal, milliseconds }
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
export {
|
|
324
|
+
createGcsReportingManagedDeliveryAdapterV1
|
|
325
|
+
};
|