@adcp/sdk 15.0.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 +7 -2
- 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 +1 -1
- package/dist/lib/index.d.ts +1 -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-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/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/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/guides/BUILD-AN-AGENT.md +9 -4
- package/docs/guides/CREATIVE-DELIVERY.md +34 -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/llms.txt +2 -2
- package/docs/migration-14.x-rc-worksheet.md +5 -4
- package/docs/migration-buyer-agent-registry.md +1 -1
- package/package.json +19 -1
- package/skills/build-seller-agent/specialisms/signed-requests.md +2 -0
|
@@ -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;
|
|
@@ -0,0 +1,193 @@
|
|
|
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 reader_exports = {};
|
|
20
|
+
__export(reader_exports, {
|
|
21
|
+
createGcsReportingReferenceResolverV1: () => createGcsReportingReferenceResolverV1,
|
|
22
|
+
createGcsReportingResourceReaderV1: () => createGcsReportingResourceReaderV1,
|
|
23
|
+
createGcsScopedObjectReadV1: () => createGcsScopedObjectReadV1,
|
|
24
|
+
gcsReportingObjectFromUriV1: () => gcsReportingObjectFromUriV1
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(reader_exports);
|
|
27
|
+
var import_canonical_references = require('../../canonical-references/index.js');
|
|
28
|
+
var import_object_writes = require('../ledger/object-writes.js');
|
|
29
|
+
var import_errors = require('./errors.js');
|
|
30
|
+
var import_io = require('./io.js');
|
|
31
|
+
function gcsReportingObjectFromUriV1(uri, bucket, prefix) {
|
|
32
|
+
if (typeof uri !== "string" || uri.length > 2048) throw new import_errors.ReportingGcsFenceError("INVALID_INPUT");
|
|
33
|
+
const expectedBase = `https://storage.googleapis.com/${bucket}/`;
|
|
34
|
+
let parsed;
|
|
35
|
+
try {
|
|
36
|
+
parsed = new URL(uri);
|
|
37
|
+
} catch {
|
|
38
|
+
throw new import_errors.ReportingGcsFenceError("INVALID_INPUT");
|
|
39
|
+
}
|
|
40
|
+
const name = uri.startsWith(expectedBase) ? uri.slice(expectedBase.length) : "";
|
|
41
|
+
if (parsed.href !== uri || parsed.username || parsed.password || parsed.search || parsed.hash || !name.startsWith(prefix) || name.length <= prefix.length || name.length > 1024 || !/^[A-Za-z0-9/_.-]+$/.test(name) || name.split("/").some((part) => !part || part === "." || part === ".."))
|
|
42
|
+
throw new import_errors.ReportingGcsFenceError("INVALID_INPUT");
|
|
43
|
+
return name;
|
|
44
|
+
}
|
|
45
|
+
function createGcsScopedObjectReadV1(options) {
|
|
46
|
+
let scope;
|
|
47
|
+
try {
|
|
48
|
+
scope = structuredClone(options.scope);
|
|
49
|
+
(0, import_object_writes.assertReportingObjectWriteScope)(scope);
|
|
50
|
+
} catch {
|
|
51
|
+
throw new import_errors.ReportingGcsFenceError("INVALID_INPUT");
|
|
52
|
+
}
|
|
53
|
+
if (typeof scope.principal_id !== "string" || scope.principal_id.length < 1 || scope.principal_id.length > 255 || typeof options.bucket !== "string" || !/^[a-z0-9][a-z0-9.-]{1,220}[a-z0-9]$/.test(options.bucket) || typeof options.objectPrefix !== "string" || !/^[A-Za-z0-9/_.-]+\/$/.test(options.objectPrefix) || options.objectPrefix.length > 1e3 || options.objectPrefix.split("/").slice(0, -1).some((p) => !p || p === "." || p === "..") || typeof options.authorize !== "function" || typeof options.getStorage !== "function")
|
|
54
|
+
throw new import_errors.ReportingGcsFenceError("INVALID_INPUT");
|
|
55
|
+
Object.freeze(scope);
|
|
56
|
+
const { bucket, objectPrefix, authorize, getStorage, signal: parentSignal } = options;
|
|
57
|
+
if (parentSignal !== void 0 && !(parentSignal instanceof AbortSignal))
|
|
58
|
+
throw new import_errors.ReportingGcsFenceError("INVALID_INPUT");
|
|
59
|
+
const maximum = options.maxBytes ?? 64 * 1024 * 1024;
|
|
60
|
+
const milliseconds = options.operationDeadlineMilliseconds ?? 6e4;
|
|
61
|
+
if (!Number.isSafeInteger(maximum) || maximum < 1 || maximum > 64 * 1024 * 1024 || !Number.isSafeInteger(milliseconds) || milliseconds < 1 || milliseconds > 6e4)
|
|
62
|
+
throw new import_errors.ReportingGcsFenceError("INVALID_INPUT");
|
|
63
|
+
async function authorized(signal, objectName) {
|
|
64
|
+
(0, import_io.activeGcsSignal)(signal);
|
|
65
|
+
const allowed = await authorize({ scope, bucket, objectPrefix, objectName }, { signal });
|
|
66
|
+
(0, import_io.activeGcsSignal)(signal);
|
|
67
|
+
if (allowed !== true) throw new import_errors.ReportingGcsFenceError("REVOKED");
|
|
68
|
+
}
|
|
69
|
+
return async (uri, maxBytes, signal, nativeVersion) => (0, import_io.withGcsDeadline)(
|
|
70
|
+
async (active) => {
|
|
71
|
+
const name = gcsReportingObjectFromUriV1(uri, bucket, objectPrefix);
|
|
72
|
+
if (!Number.isSafeInteger(maxBytes) || maxBytes < 1 || nativeVersion !== void 0 && !/^[1-9][0-9]{0,39}$/.test(nativeVersion))
|
|
73
|
+
throw new import_errors.ReportingGcsFenceError("INVALID_INPUT");
|
|
74
|
+
await authorized(active, name);
|
|
75
|
+
const storage = await getStorage(scope, { signal: active });
|
|
76
|
+
(0, import_io.activeGcsSignal)(active);
|
|
77
|
+
try {
|
|
78
|
+
const file = storage.bucket(bucket).file(name, nativeVersion ? { generation: nativeVersion } : void 0);
|
|
79
|
+
const [metadata] = await file.getMetadata();
|
|
80
|
+
(0, import_io.activeGcsSignal)(active);
|
|
81
|
+
if (metadata.metadata?.adcp_reporting_tombstone !== void 0) throw new import_errors.ReportingGcsFenceError("REVOKED");
|
|
82
|
+
const generation = String(metadata.generation);
|
|
83
|
+
if (nativeVersion !== void 0 && generation !== nativeVersion)
|
|
84
|
+
throw new import_errors.ReportingGcsFenceError("CONTENT_CONFLICT");
|
|
85
|
+
if (!/^[1-9][0-9]{0,39}$/.test(generation) || !/^(?:0|[1-9][0-9]{0,19})$/.test(String(metadata.size)) || BigInt(String(metadata.size)) > BigInt(Math.min(maxBytes, maximum)))
|
|
86
|
+
throw new import_errors.ReportingGcsFenceError("CONTENT_CONFLICT");
|
|
87
|
+
const body = await (0, import_io.readGcsBytes)(
|
|
88
|
+
storage.bucket(bucket).file(name, { generation }),
|
|
89
|
+
Math.min(maxBytes, maximum),
|
|
90
|
+
active
|
|
91
|
+
);
|
|
92
|
+
(0, import_io.activeGcsSignal)(active);
|
|
93
|
+
await authorized(active, name);
|
|
94
|
+
return { body, contentType: metadata.contentType, generation };
|
|
95
|
+
} catch (error) {
|
|
96
|
+
(0, import_io.activeGcsSignal)(active);
|
|
97
|
+
if ((0, import_errors.isReportingGcsFenceError)(error)) throw error;
|
|
98
|
+
await authorized(active, name);
|
|
99
|
+
throw new import_errors.ReportingGcsFenceError("PROVIDER_UNAVAILABLE");
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
signal: parentSignal && signal ? AbortSignal.any([parentSignal, signal]) : parentSignal ?? signal,
|
|
104
|
+
milliseconds
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
function createGcsReportingResourceReaderV1(options) {
|
|
109
|
+
const read = createGcsScopedObjectReadV1(options);
|
|
110
|
+
const scope = structuredClone(options.scope);
|
|
111
|
+
const { bucket, objectPrefix } = options;
|
|
112
|
+
return {
|
|
113
|
+
async read(request) {
|
|
114
|
+
if (!request?.context?.materialization?.resource || !["manifest", "object"].includes(request.role) || request.context.obligation?.account_id !== scope.account_id || request.location !== request.context.materialization.resource.location || request.context.materialization.destination_ref !== scope.destination_ref)
|
|
115
|
+
throw new import_errors.ReportingGcsFenceError("INVALID_INPUT");
|
|
116
|
+
let uri = request.location;
|
|
117
|
+
if (request.role === "object") {
|
|
118
|
+
if (typeof request.objectRef !== "string" || !/^[A-Za-z0-9_.-]+$/.test(request.objectRef) || request.objectRef === "." || request.objectRef === "..")
|
|
119
|
+
throw new import_errors.ReportingGcsFenceError("INVALID_INPUT");
|
|
120
|
+
const name = gcsReportingObjectFromUriV1(request.location, bucket, objectPrefix);
|
|
121
|
+
uri = `https://storage.googleapis.com/${bucket}/${name.slice(0, name.lastIndexOf("/") + 1)}${request.objectRef}`;
|
|
122
|
+
}
|
|
123
|
+
return read(
|
|
124
|
+
uri,
|
|
125
|
+
request.maxBytes,
|
|
126
|
+
request.signal,
|
|
127
|
+
request.role === "manifest" ? request.context.materialization.resource?.native_version_ref : void 0
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function createGcsReportingReferenceResolverV1(options) {
|
|
133
|
+
const read = createGcsScopedObjectReadV1(options);
|
|
134
|
+
const documentReader = {
|
|
135
|
+
async read(request) {
|
|
136
|
+
try {
|
|
137
|
+
return await read(request.uri, request.maxBytes, request.signal);
|
|
138
|
+
} catch (error) {
|
|
139
|
+
if ((0, import_errors.isReportingGcsFenceError)(error)) {
|
|
140
|
+
if (error.code === "ABORTED") throw new import_canonical_references.CanonicalDocumentReadError("aborted");
|
|
141
|
+
if (error.code === "INVALID_INPUT") throw new import_canonical_references.CanonicalDocumentReadError("unsafe_url");
|
|
142
|
+
if (error.code === "REVOKED") throw new import_canonical_references.CanonicalDocumentReadError("access_denied");
|
|
143
|
+
if (error.code === "CONTENT_CONFLICT") throw new import_canonical_references.CanonicalDocumentReadError("body_too_large");
|
|
144
|
+
}
|
|
145
|
+
throw new import_canonical_references.CanonicalDocumentReadError("network_error");
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
const parentSignal = options.signal;
|
|
150
|
+
const resolver = (0, import_canonical_references.createCanonicalReferenceResolver)({ documentReader, signal: parentSignal });
|
|
151
|
+
const routing = { bucket: options.bucket, objectPrefix: options.objectPrefix };
|
|
152
|
+
const forced = (input) => ({
|
|
153
|
+
...input,
|
|
154
|
+
documentReader,
|
|
155
|
+
signal: parentSignal && input?.signal ? AbortSignal.any([parentSignal, input.signal]) : parentSignal ?? input?.signal
|
|
156
|
+
});
|
|
157
|
+
function blocked(ref, kind) {
|
|
158
|
+
try {
|
|
159
|
+
gcsReportingObjectFromUriV1(ref.uri, routing.bucket, routing.objectPrefix);
|
|
160
|
+
return void 0;
|
|
161
|
+
} catch {
|
|
162
|
+
return {
|
|
163
|
+
ok: false,
|
|
164
|
+
status: "blocked_unsafe_url",
|
|
165
|
+
kind,
|
|
166
|
+
ref: {
|
|
167
|
+
uri: "https://storage.googleapis.com/redacted-invalid-reference",
|
|
168
|
+
digest: /^sha256:[a-f0-9]{64}$/.test(ref?.digest) ? ref.digest : "invalid"
|
|
169
|
+
},
|
|
170
|
+
cacheKey: "private-reference-refused",
|
|
171
|
+
fromCache: false,
|
|
172
|
+
error: {
|
|
173
|
+
code: "unsafe_url",
|
|
174
|
+
message: "Private reference is outside the saved destination scope",
|
|
175
|
+
retryable: false
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return {
|
|
181
|
+
cache: resolver.cache,
|
|
182
|
+
resolve: async (ref, context) => blocked(ref, "generic") ?? resolver.resolve(ref, forced(context)),
|
|
183
|
+
resolveFormatSchema: async (ref, context) => blocked(ref, "format_schema") ?? resolver.resolveFormatSchema(ref, forced(context)),
|
|
184
|
+
resolvePlatformExtensions: async (ref, context) => blocked(ref, "platform_extensions") ?? resolver.resolvePlatformExtensions(ref, forced(context))
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
188
|
+
0 && (module.exports = {
|
|
189
|
+
createGcsReportingReferenceResolverV1,
|
|
190
|
+
createGcsReportingResourceReaderV1,
|
|
191
|
+
createGcsScopedObjectReadV1,
|
|
192
|
+
gcsReportingObjectFromUriV1
|
|
193
|
+
});
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CanonicalDocumentReadError,
|
|
3
|
+
createCanonicalReferenceResolver
|
|
4
|
+
} from "../../canonical-references/index.mjs";
|
|
5
|
+
import { assertReportingObjectWriteScope } from "../ledger/object-writes.mjs";
|
|
6
|
+
import { ReportingGcsFenceError, isReportingGcsFenceError } from "./errors.mjs";
|
|
7
|
+
import { activeGcsSignal, readGcsBytes, withGcsDeadline } from "./io.mjs";
|
|
8
|
+
function gcsReportingObjectFromUriV1(uri, bucket, prefix) {
|
|
9
|
+
if (typeof uri !== "string" || uri.length > 2048) throw new ReportingGcsFenceError("INVALID_INPUT");
|
|
10
|
+
const expectedBase = `https://storage.googleapis.com/${bucket}/`;
|
|
11
|
+
let parsed;
|
|
12
|
+
try {
|
|
13
|
+
parsed = new URL(uri);
|
|
14
|
+
} catch {
|
|
15
|
+
throw new ReportingGcsFenceError("INVALID_INPUT");
|
|
16
|
+
}
|
|
17
|
+
const name = uri.startsWith(expectedBase) ? uri.slice(expectedBase.length) : "";
|
|
18
|
+
if (parsed.href !== uri || parsed.username || parsed.password || parsed.search || parsed.hash || !name.startsWith(prefix) || name.length <= prefix.length || name.length > 1024 || !/^[A-Za-z0-9/_.-]+$/.test(name) || name.split("/").some((part) => !part || part === "." || part === ".."))
|
|
19
|
+
throw new ReportingGcsFenceError("INVALID_INPUT");
|
|
20
|
+
return name;
|
|
21
|
+
}
|
|
22
|
+
function createGcsScopedObjectReadV1(options) {
|
|
23
|
+
let scope;
|
|
24
|
+
try {
|
|
25
|
+
scope = structuredClone(options.scope);
|
|
26
|
+
assertReportingObjectWriteScope(scope);
|
|
27
|
+
} catch {
|
|
28
|
+
throw new ReportingGcsFenceError("INVALID_INPUT");
|
|
29
|
+
}
|
|
30
|
+
if (typeof scope.principal_id !== "string" || scope.principal_id.length < 1 || scope.principal_id.length > 255 || typeof options.bucket !== "string" || !/^[a-z0-9][a-z0-9.-]{1,220}[a-z0-9]$/.test(options.bucket) || typeof options.objectPrefix !== "string" || !/^[A-Za-z0-9/_.-]+\/$/.test(options.objectPrefix) || options.objectPrefix.length > 1e3 || options.objectPrefix.split("/").slice(0, -1).some((p) => !p || p === "." || p === "..") || typeof options.authorize !== "function" || typeof options.getStorage !== "function")
|
|
31
|
+
throw new ReportingGcsFenceError("INVALID_INPUT");
|
|
32
|
+
Object.freeze(scope);
|
|
33
|
+
const { bucket, objectPrefix, authorize, getStorage, signal: parentSignal } = options;
|
|
34
|
+
if (parentSignal !== void 0 && !(parentSignal instanceof AbortSignal))
|
|
35
|
+
throw new ReportingGcsFenceError("INVALID_INPUT");
|
|
36
|
+
const maximum = options.maxBytes ?? 64 * 1024 * 1024;
|
|
37
|
+
const milliseconds = options.operationDeadlineMilliseconds ?? 6e4;
|
|
38
|
+
if (!Number.isSafeInteger(maximum) || maximum < 1 || maximum > 64 * 1024 * 1024 || !Number.isSafeInteger(milliseconds) || milliseconds < 1 || milliseconds > 6e4)
|
|
39
|
+
throw new ReportingGcsFenceError("INVALID_INPUT");
|
|
40
|
+
async function authorized(signal, objectName) {
|
|
41
|
+
activeGcsSignal(signal);
|
|
42
|
+
const allowed = await authorize({ scope, bucket, objectPrefix, objectName }, { signal });
|
|
43
|
+
activeGcsSignal(signal);
|
|
44
|
+
if (allowed !== true) throw new ReportingGcsFenceError("REVOKED");
|
|
45
|
+
}
|
|
46
|
+
return async (uri, maxBytes, signal, nativeVersion) => withGcsDeadline(
|
|
47
|
+
async (active) => {
|
|
48
|
+
const name = gcsReportingObjectFromUriV1(uri, bucket, objectPrefix);
|
|
49
|
+
if (!Number.isSafeInteger(maxBytes) || maxBytes < 1 || nativeVersion !== void 0 && !/^[1-9][0-9]{0,39}$/.test(nativeVersion))
|
|
50
|
+
throw new ReportingGcsFenceError("INVALID_INPUT");
|
|
51
|
+
await authorized(active, name);
|
|
52
|
+
const storage = await getStorage(scope, { signal: active });
|
|
53
|
+
activeGcsSignal(active);
|
|
54
|
+
try {
|
|
55
|
+
const file = storage.bucket(bucket).file(name, nativeVersion ? { generation: nativeVersion } : void 0);
|
|
56
|
+
const [metadata] = await file.getMetadata();
|
|
57
|
+
activeGcsSignal(active);
|
|
58
|
+
if (metadata.metadata?.adcp_reporting_tombstone !== void 0) throw new ReportingGcsFenceError("REVOKED");
|
|
59
|
+
const generation = String(metadata.generation);
|
|
60
|
+
if (nativeVersion !== void 0 && generation !== nativeVersion)
|
|
61
|
+
throw new ReportingGcsFenceError("CONTENT_CONFLICT");
|
|
62
|
+
if (!/^[1-9][0-9]{0,39}$/.test(generation) || !/^(?:0|[1-9][0-9]{0,19})$/.test(String(metadata.size)) || BigInt(String(metadata.size)) > BigInt(Math.min(maxBytes, maximum)))
|
|
63
|
+
throw new ReportingGcsFenceError("CONTENT_CONFLICT");
|
|
64
|
+
const body = await readGcsBytes(
|
|
65
|
+
storage.bucket(bucket).file(name, { generation }),
|
|
66
|
+
Math.min(maxBytes, maximum),
|
|
67
|
+
active
|
|
68
|
+
);
|
|
69
|
+
activeGcsSignal(active);
|
|
70
|
+
await authorized(active, name);
|
|
71
|
+
return { body, contentType: metadata.contentType, generation };
|
|
72
|
+
} catch (error) {
|
|
73
|
+
activeGcsSignal(active);
|
|
74
|
+
if (isReportingGcsFenceError(error)) throw error;
|
|
75
|
+
await authorized(active, name);
|
|
76
|
+
throw new ReportingGcsFenceError("PROVIDER_UNAVAILABLE");
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
signal: parentSignal && signal ? AbortSignal.any([parentSignal, signal]) : parentSignal ?? signal,
|
|
81
|
+
milliseconds
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
function createGcsReportingResourceReaderV1(options) {
|
|
86
|
+
const read = createGcsScopedObjectReadV1(options);
|
|
87
|
+
const scope = structuredClone(options.scope);
|
|
88
|
+
const { bucket, objectPrefix } = options;
|
|
89
|
+
return {
|
|
90
|
+
async read(request) {
|
|
91
|
+
if (!request?.context?.materialization?.resource || !["manifest", "object"].includes(request.role) || request.context.obligation?.account_id !== scope.account_id || request.location !== request.context.materialization.resource.location || request.context.materialization.destination_ref !== scope.destination_ref)
|
|
92
|
+
throw new ReportingGcsFenceError("INVALID_INPUT");
|
|
93
|
+
let uri = request.location;
|
|
94
|
+
if (request.role === "object") {
|
|
95
|
+
if (typeof request.objectRef !== "string" || !/^[A-Za-z0-9_.-]+$/.test(request.objectRef) || request.objectRef === "." || request.objectRef === "..")
|
|
96
|
+
throw new ReportingGcsFenceError("INVALID_INPUT");
|
|
97
|
+
const name = gcsReportingObjectFromUriV1(request.location, bucket, objectPrefix);
|
|
98
|
+
uri = `https://storage.googleapis.com/${bucket}/${name.slice(0, name.lastIndexOf("/") + 1)}${request.objectRef}`;
|
|
99
|
+
}
|
|
100
|
+
return read(
|
|
101
|
+
uri,
|
|
102
|
+
request.maxBytes,
|
|
103
|
+
request.signal,
|
|
104
|
+
request.role === "manifest" ? request.context.materialization.resource?.native_version_ref : void 0
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function createGcsReportingReferenceResolverV1(options) {
|
|
110
|
+
const read = createGcsScopedObjectReadV1(options);
|
|
111
|
+
const documentReader = {
|
|
112
|
+
async read(request) {
|
|
113
|
+
try {
|
|
114
|
+
return await read(request.uri, request.maxBytes, request.signal);
|
|
115
|
+
} catch (error) {
|
|
116
|
+
if (isReportingGcsFenceError(error)) {
|
|
117
|
+
if (error.code === "ABORTED") throw new CanonicalDocumentReadError("aborted");
|
|
118
|
+
if (error.code === "INVALID_INPUT") throw new CanonicalDocumentReadError("unsafe_url");
|
|
119
|
+
if (error.code === "REVOKED") throw new CanonicalDocumentReadError("access_denied");
|
|
120
|
+
if (error.code === "CONTENT_CONFLICT") throw new CanonicalDocumentReadError("body_too_large");
|
|
121
|
+
}
|
|
122
|
+
throw new CanonicalDocumentReadError("network_error");
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
const parentSignal = options.signal;
|
|
127
|
+
const resolver = createCanonicalReferenceResolver({ documentReader, signal: parentSignal });
|
|
128
|
+
const routing = { bucket: options.bucket, objectPrefix: options.objectPrefix };
|
|
129
|
+
const forced = (input) => ({
|
|
130
|
+
...input,
|
|
131
|
+
documentReader,
|
|
132
|
+
signal: parentSignal && input?.signal ? AbortSignal.any([parentSignal, input.signal]) : parentSignal ?? input?.signal
|
|
133
|
+
});
|
|
134
|
+
function blocked(ref, kind) {
|
|
135
|
+
try {
|
|
136
|
+
gcsReportingObjectFromUriV1(ref.uri, routing.bucket, routing.objectPrefix);
|
|
137
|
+
return void 0;
|
|
138
|
+
} catch {
|
|
139
|
+
return {
|
|
140
|
+
ok: false,
|
|
141
|
+
status: "blocked_unsafe_url",
|
|
142
|
+
kind,
|
|
143
|
+
ref: {
|
|
144
|
+
uri: "https://storage.googleapis.com/redacted-invalid-reference",
|
|
145
|
+
digest: /^sha256:[a-f0-9]{64}$/.test(ref?.digest) ? ref.digest : "invalid"
|
|
146
|
+
},
|
|
147
|
+
cacheKey: "private-reference-refused",
|
|
148
|
+
fromCache: false,
|
|
149
|
+
error: {
|
|
150
|
+
code: "unsafe_url",
|
|
151
|
+
message: "Private reference is outside the saved destination scope",
|
|
152
|
+
retryable: false
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
cache: resolver.cache,
|
|
159
|
+
resolve: async (ref, context) => blocked(ref, "generic") ?? resolver.resolve(ref, forced(context)),
|
|
160
|
+
resolveFormatSchema: async (ref, context) => blocked(ref, "format_schema") ?? resolver.resolveFormatSchema(ref, forced(context)),
|
|
161
|
+
resolvePlatformExtensions: async (ref, context) => blocked(ref, "platform_extensions") ?? resolver.resolvePlatformExtensions(ref, forced(context))
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
export {
|
|
165
|
+
createGcsReportingReferenceResolverV1,
|
|
166
|
+
createGcsReportingResourceReaderV1,
|
|
167
|
+
createGcsScopedObjectReadV1,
|
|
168
|
+
gcsReportingObjectFromUriV1
|
|
169
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ReportingManagedDeliveryAdapterV1 } from '../ledger/managed.mjs';
|
|
2
|
+
import type { ExpectedReportingPeriod } from '../reconciliation.mjs';
|
|
3
|
+
type DeliveryInput = Parameters<ReportingManagedDeliveryAdapterV1['deliver']>[0];
|
|
4
|
+
export declare function assertExpectedBinding(input: DeliveryInput, expected: ExpectedReportingPeriod): void;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ReportingManagedDeliveryAdapterV1 } from '../ledger/managed';
|
|
2
|
+
import type { ExpectedReportingPeriod } from '../reconciliation';
|
|
3
|
+
type DeliveryInput = Parameters<ReportingManagedDeliveryAdapterV1['deliver']>[0];
|
|
4
|
+
export declare function assertExpectedBinding(input: DeliveryInput, expected: ExpectedReportingPeriod): void;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
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 validation_exports = {};
|
|
20
|
+
__export(validation_exports, {
|
|
21
|
+
assertExpectedBinding: () => assertExpectedBinding
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(validation_exports);
|
|
24
|
+
var import_jcs = require('../../utils/jcs.js');
|
|
25
|
+
var import_errors = require('./errors.js');
|
|
26
|
+
function assertExpectedBinding(input, expected) {
|
|
27
|
+
const {
|
|
28
|
+
binding,
|
|
29
|
+
revision: { wireRevision: r },
|
|
30
|
+
obligation
|
|
31
|
+
} = input;
|
|
32
|
+
const shaMatches = (a, b) => typeof a === "string" && /^[a-fA-F0-9]{64}$/.test(a) && /^[a-fA-F0-9]{64}$/.test(b) && a.toLowerCase() === b.toLowerCase();
|
|
33
|
+
if (expected.verificationProfile !== binding.verification_profile || expected.destinationRef !== binding.destination_ref || expected.deliveryMethod !== binding.method || expected.deliveryConfigId !== binding.delivery_config_id || expected.deliveryConfigVersion !== binding.delivery_config_version || expected.reportDefinitionId !== r.report_definition_id || expected.feedPurpose !== binding.feed_purpose || expected.reportingProfile !== r.reporting_profile || expected.reconciliationMode !== binding.reconciliation_mode || expected.requiredFinality !== obligation.requiredFinality || expected.periodStart !== r.period.start || expected.periodEnd !== r.period.end || (0, import_jcs.canonicalize)([...expected.mediaBuyIds].sort()) !== (0, import_jcs.canonicalize)([...r.media_buy_ids].sort()) || expected.reportDefinitionUri !== r.report_definition_uri || !shaMatches(r.report_definition_sha256, expected.reportDefinitionSha256) || expected.schemaUri !== r.schema_uri || !shaMatches(r.schema_sha256, expected.schemaSha256) || expected.schemaVersion !== r.schema_version || expected.schemaDialect !== r.schema_dialect || expected.schemaRefPolicy !== r.schema_ref_policy || r.finality === "official" && (!expected.officialFinality || expected.officialFinality.policyId !== r.finality_policy_id || expected.officialFinality.basis !== r.finality_basis))
|
|
34
|
+
throw new import_errors.ReportingGcsFenceError("CONTENT_CONFLICT");
|
|
35
|
+
const coverage = (value) => Object.fromEntries(
|
|
36
|
+
Object.entries(value).filter(([key]) => !["evaluated_at", "limitations"].includes(key)).map(([key, item]) => [key, Array.isArray(item) ? [...item].sort() : item])
|
|
37
|
+
);
|
|
38
|
+
if ((0, import_jcs.canonicalize)(coverage(expected.coverage)) !== (0, import_jcs.canonicalize)(coverage(r.coverage)))
|
|
39
|
+
throw new import_errors.ReportingGcsFenceError("CONTENT_CONFLICT");
|
|
40
|
+
if (expected.verificationProfile === "canonical_digest") {
|
|
41
|
+
const pin = expected.canonicalization, digest = r.canonical_content_digest;
|
|
42
|
+
if (!digest || digest.canonicalization_id !== pin.id || digest.canonicalization_uri !== pin.uri || !shaMatches(digest.canonicalization_sha256, pin.sha256))
|
|
43
|
+
throw new import_errors.ReportingGcsFenceError("CONTENT_CONFLICT");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
assertExpectedBinding
|
|
49
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { canonicalize } from "../../utils/jcs.mjs";
|
|
2
|
+
import { ReportingGcsFenceError } from "./errors.mjs";
|
|
3
|
+
function assertExpectedBinding(input, expected) {
|
|
4
|
+
const {
|
|
5
|
+
binding,
|
|
6
|
+
revision: { wireRevision: r },
|
|
7
|
+
obligation
|
|
8
|
+
} = input;
|
|
9
|
+
const shaMatches = (a, b) => typeof a === "string" && /^[a-fA-F0-9]{64}$/.test(a) && /^[a-fA-F0-9]{64}$/.test(b) && a.toLowerCase() === b.toLowerCase();
|
|
10
|
+
if (expected.verificationProfile !== binding.verification_profile || expected.destinationRef !== binding.destination_ref || expected.deliveryMethod !== binding.method || expected.deliveryConfigId !== binding.delivery_config_id || expected.deliveryConfigVersion !== binding.delivery_config_version || expected.reportDefinitionId !== r.report_definition_id || expected.feedPurpose !== binding.feed_purpose || expected.reportingProfile !== r.reporting_profile || expected.reconciliationMode !== binding.reconciliation_mode || expected.requiredFinality !== obligation.requiredFinality || expected.periodStart !== r.period.start || expected.periodEnd !== r.period.end || canonicalize([...expected.mediaBuyIds].sort()) !== canonicalize([...r.media_buy_ids].sort()) || expected.reportDefinitionUri !== r.report_definition_uri || !shaMatches(r.report_definition_sha256, expected.reportDefinitionSha256) || expected.schemaUri !== r.schema_uri || !shaMatches(r.schema_sha256, expected.schemaSha256) || expected.schemaVersion !== r.schema_version || expected.schemaDialect !== r.schema_dialect || expected.schemaRefPolicy !== r.schema_ref_policy || r.finality === "official" && (!expected.officialFinality || expected.officialFinality.policyId !== r.finality_policy_id || expected.officialFinality.basis !== r.finality_basis))
|
|
11
|
+
throw new ReportingGcsFenceError("CONTENT_CONFLICT");
|
|
12
|
+
const coverage = (value) => Object.fromEntries(
|
|
13
|
+
Object.entries(value).filter(([key]) => !["evaluated_at", "limitations"].includes(key)).map(([key, item]) => [key, Array.isArray(item) ? [...item].sort() : item])
|
|
14
|
+
);
|
|
15
|
+
if (canonicalize(coverage(expected.coverage)) !== canonicalize(coverage(r.coverage)))
|
|
16
|
+
throw new ReportingGcsFenceError("CONTENT_CONFLICT");
|
|
17
|
+
if (expected.verificationProfile === "canonical_digest") {
|
|
18
|
+
const pin = expected.canonicalization, digest = r.canonical_content_digest;
|
|
19
|
+
if (!digest || digest.canonicalization_id !== pin.id || digest.canonicalization_uri !== pin.uri || !shaMatches(digest.canonicalization_sha256, pin.sha256))
|
|
20
|
+
throw new ReportingGcsFenceError("CONTENT_CONFLICT");
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
assertExpectedBinding
|
|
25
|
+
};
|
|
@@ -13,6 +13,7 @@ export interface ReportingStatusConsumerScopeOptionsV1<TContext = unknown> {
|
|
|
13
13
|
*/
|
|
14
14
|
consumerMismatchEscalation?: ReportingConsumerMismatchEscalationV1;
|
|
15
15
|
}
|
|
16
|
+
export declare function createReportingStatusHandler(store: ReportingLedgerStore): (request: Parameters<ReportingStatusHandlerV1>[0], context: Pick<Parameters<ReportingStatusHandlerV1>[1], 'account' | 'signal'>) => ReturnType<ReportingStatusHandlerV1>;
|
|
16
17
|
export declare function createReportingStatusHandler<TContext = unknown>(store: ReportingLedgerStore, options?: ReportingStatusConsumerScopeOptionsV1<TContext>): ReportingStatusHandlerV1;
|
|
17
18
|
/** Exact revision reader for createAdcpServer's getMediaBuyDelivery slot. */
|
|
18
19
|
export declare function createReportingDeliveryHandler(store: ReportingLedgerStore): ReportingDeliveryHandlerV1;
|
|
@@ -13,6 +13,7 @@ export interface ReportingStatusConsumerScopeOptionsV1<TContext = unknown> {
|
|
|
13
13
|
*/
|
|
14
14
|
consumerMismatchEscalation?: ReportingConsumerMismatchEscalationV1;
|
|
15
15
|
}
|
|
16
|
+
export declare function createReportingStatusHandler(store: ReportingLedgerStore): (request: Parameters<ReportingStatusHandlerV1>[0], context: Pick<Parameters<ReportingStatusHandlerV1>[1], 'account' | 'signal'>) => ReturnType<ReportingStatusHandlerV1>;
|
|
16
17
|
export declare function createReportingStatusHandler<TContext = unknown>(store: ReportingLedgerStore, options?: ReportingStatusConsumerScopeOptionsV1<TContext>): ReportingStatusHandlerV1;
|
|
17
18
|
/** Exact revision reader for createAdcpServer's getMediaBuyDelivery slot. */
|
|
18
19
|
export declare function createReportingDeliveryHandler(store: ReportingLedgerStore): ReportingDeliveryHandlerV1;
|