@adcp/sdk 15.3.0 → 15.5.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/dist/lib/advanced.d.mts +2 -2
- package/dist/lib/advanced.d.ts +2 -2
- package/dist/lib/advanced.js +8 -2
- package/dist/lib/advanced.mjs +8 -2
- package/dist/lib/core/AgentClient.d.mts +4 -0
- package/dist/lib/core/AgentClient.d.ts +4 -0
- package/dist/lib/core/AgentClient.js +8 -0
- package/dist/lib/core/AgentClient.mjs +8 -0
- package/dist/lib/core/SingleAgentClient.d.mts +154 -0
- package/dist/lib/core/SingleAgentClient.d.ts +154 -0
- package/dist/lib/core/SingleAgentClient.js +661 -23
- package/dist/lib/core/SingleAgentClient.mjs +666 -23
- package/dist/lib/core/agent-discovery-cache.d.mts +103 -0
- package/dist/lib/core/agent-discovery-cache.d.ts +103 -0
- package/dist/lib/core/agent-discovery-cache.js +121 -0
- package/dist/lib/core/agent-discovery-cache.mjs +92 -0
- package/dist/lib/index.d.mts +5 -3
- package/dist/lib/index.d.ts +5 -3
- package/dist/lib/index.js +7 -0
- package/dist/lib/index.mjs +6 -0
- package/dist/lib/protocols/index.d.mts +2 -2
- package/dist/lib/protocols/index.d.ts +2 -2
- package/dist/lib/protocols/index.js +1 -1
- package/dist/lib/protocols/index.mjs +1 -1
- package/dist/lib/protocols/mcp-call-context.d.mts +109 -0
- package/dist/lib/protocols/mcp-call-context.d.ts +109 -0
- package/dist/lib/protocols/mcp-call-context.js +221 -0
- package/dist/lib/protocols/mcp-call-context.mjs +186 -0
- package/dist/lib/protocols/mcp-modern.d.mts +9 -1
- package/dist/lib/protocols/mcp-modern.d.ts +9 -1
- package/dist/lib/protocols/mcp-modern.js +180 -104
- package/dist/lib/protocols/mcp-modern.mjs +193 -104
- package/dist/lib/protocols/mcp-scope.d.mts +15 -0
- package/dist/lib/protocols/mcp-scope.d.ts +15 -0
- package/dist/lib/protocols/mcp.d.mts +4 -2
- package/dist/lib/protocols/mcp.d.ts +4 -2
- package/dist/lib/protocols/mcp.js +178 -154
- package/dist/lib/protocols/mcp.mjs +189 -153
- package/dist/lib/protocols/transportDiagnostics.d.mts +33 -1
- package/dist/lib/protocols/transportDiagnostics.d.ts +33 -1
- package/dist/lib/protocols/transportDiagnostics.js +128 -12
- package/dist/lib/protocols/transportDiagnostics.mjs +128 -12
- package/dist/lib/reporting/gcs/index.d.mts +2 -0
- package/dist/lib/reporting/gcs/index.d.ts +2 -0
- package/dist/lib/reporting/gcs/index.js +3 -0
- package/dist/lib/reporting/gcs/index.mjs +2 -0
- package/dist/lib/reporting/gcs/row-provider.d.mts +32 -0
- package/dist/lib/reporting/gcs/row-provider.d.ts +32 -0
- package/dist/lib/reporting/gcs/row-provider.js +205 -0
- package/dist/lib/reporting/gcs/row-provider.mjs +188 -0
- package/dist/lib/reporting/ledger/change-feed.d.mts +41 -0
- package/dist/lib/reporting/ledger/change-feed.d.ts +41 -0
- package/dist/lib/reporting/ledger/change-feed.js +101 -0
- package/dist/lib/reporting/ledger/change-feed.mjs +74 -0
- package/dist/lib/reporting/ledger/handler.d.mts +6 -0
- package/dist/lib/reporting/ledger/handler.d.ts +6 -0
- package/dist/lib/reporting/ledger/handler.js +51 -8
- package/dist/lib/reporting/ledger/handler.mjs +50 -8
- package/dist/lib/reporting/ledger/index.d.mts +5 -0
- package/dist/lib/reporting/ledger/index.d.ts +5 -0
- package/dist/lib/reporting/ledger/index.js +11 -1
- package/dist/lib/reporting/ledger/index.mjs +5 -0
- package/dist/lib/reporting/ledger/lifecycle.js +3 -2
- package/dist/lib/reporting/ledger/lifecycle.mjs +3 -2
- package/dist/lib/reporting/ledger/managed-postgres.d.mts +2 -0
- package/dist/lib/reporting/ledger/managed-postgres.d.ts +2 -0
- package/dist/lib/reporting/ledger/managed-postgres.js +26 -6
- package/dist/lib/reporting/ledger/managed-postgres.mjs +26 -6
- package/dist/lib/reporting/ledger/managed.d.mts +9 -0
- package/dist/lib/reporting/ledger/managed.d.ts +9 -0
- package/dist/lib/reporting/ledger/managed.js +18 -0
- package/dist/lib/reporting/ledger/managed.mjs +18 -0
- package/dist/lib/reporting/ledger/postgres.d.mts +179 -1
- package/dist/lib/reporting/ledger/postgres.d.ts +179 -1
- package/dist/lib/reporting/ledger/postgres.js +882 -19
- package/dist/lib/reporting/ledger/postgres.mjs +890 -19
- package/dist/lib/reporting/ledger/producer.js +13 -3
- package/dist/lib/reporting/ledger/producer.mjs +13 -3
- package/dist/lib/reporting/ledger/revision-metadata.d.mts +17 -0
- package/dist/lib/reporting/ledger/revision-metadata.d.ts +17 -0
- package/dist/lib/reporting/ledger/revision-metadata.js +71 -0
- package/dist/lib/reporting/ledger/revision-metadata.mjs +44 -0
- package/dist/lib/reporting/ledger/row-encoding.d.mts +128 -0
- package/dist/lib/reporting/ledger/row-encoding.d.ts +128 -0
- package/dist/lib/reporting/ledger/row-encoding.js +355 -0
- package/dist/lib/reporting/ledger/row-encoding.mjs +315 -0
- package/dist/lib/reporting/ledger/row-storage-errors.d.mts +7 -0
- package/dist/lib/reporting/ledger/row-storage-errors.d.ts +7 -0
- package/dist/lib/reporting/ledger/row-storage-errors.js +41 -0
- package/dist/lib/reporting/ledger/row-storage-errors.mjs +16 -0
- package/dist/lib/reporting/ledger/row-storage-migration.d.mts +41 -0
- package/dist/lib/reporting/ledger/row-storage-migration.d.ts +41 -0
- package/dist/lib/reporting/ledger/row-storage-migration.js +234 -0
- package/dist/lib/reporting/ledger/row-storage-migration.mjs +208 -0
- package/dist/lib/reporting/ledger/row-storage-object.d.mts +112 -0
- package/dist/lib/reporting/ledger/row-storage-object.d.ts +112 -0
- package/dist/lib/reporting/ledger/row-storage-object.js +281 -0
- package/dist/lib/reporting/ledger/row-storage-object.mjs +239 -0
- package/dist/lib/reporting/ledger/row-storage-provider-io.d.mts +51 -0
- package/dist/lib/reporting/ledger/row-storage-provider-io.d.ts +51 -0
- package/dist/lib/reporting/ledger/row-storage-provider-io.js +152 -0
- package/dist/lib/reporting/ledger/row-storage-provider-io.mjs +119 -0
- package/dist/lib/reporting/ledger/row-storage.d.mts +224 -0
- package/dist/lib/reporting/ledger/row-storage.d.ts +224 -0
- package/dist/lib/reporting/ledger/row-storage.js +692 -0
- package/dist/lib/reporting/ledger/row-storage.mjs +680 -0
- package/dist/lib/reporting/ledger/types.d.mts +45 -0
- package/dist/lib/reporting/ledger/types.d.ts +45 -0
- package/dist/lib/reporting/service/index.d.mts +41 -1
- package/dist/lib/reporting/service/index.d.ts +41 -1
- package/dist/lib/reporting/service/index.js +68 -1
- package/dist/lib/reporting/service/index.mjs +70 -1
- package/dist/lib/schemas-data/v2.5/_provenance.json +1 -1
- package/dist/lib/signing/agent-resolver/fetch-helpers.js +1 -1
- package/dist/lib/signing/agent-resolver/fetch-helpers.mjs +1 -1
- 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/README.md +1 -1
- package/docs/TYPE-SUMMARY.md +35 -2
- package/docs/guides/DISCOVERY-CACHE-AND-SESSION-REUSE.md +142 -0
- package/docs/guides/EXISTING-PLATFORM.md +43 -12
- package/docs/guides/REPORTING-LEDGER.md +209 -0
- package/docs/llms.txt +4 -2
- package/docs/migration-14.x-rc-worksheet.md +4 -4
- package/docs/recipes/verifying-inbound-webhooks.md +8 -0
- package/package.json +1 -1
|
@@ -0,0 +1,205 @@
|
|
|
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 row_provider_exports = {};
|
|
20
|
+
__export(row_provider_exports, {
|
|
21
|
+
assertGcsReportingRowBucketPolicyV1: () => assertGcsReportingRowBucketPolicyV1,
|
|
22
|
+
createGcsReportingRowObjectProviderV1: () => createGcsReportingRowObjectProviderV1
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(row_provider_exports);
|
|
25
|
+
var import_node_crypto = require("node:crypto");
|
|
26
|
+
var import_row_storage_errors = require('../ledger/row-storage-errors.js');
|
|
27
|
+
var import_row_storage_provider_io = require('../ledger/row-storage-provider-io.js');
|
|
28
|
+
const BUCKET = /^[a-z0-9][a-z0-9._-]{1,220}[a-z0-9]$/;
|
|
29
|
+
const GENERATION = /^[1-9][0-9]{0,15}$/;
|
|
30
|
+
const NONCURRENT_ONLY_CONDITIONS = ["numNewerVersions", "daysSinceNoncurrentTime", "noncurrentTimeBefore"];
|
|
31
|
+
function status(error) {
|
|
32
|
+
if (!error || typeof error !== "object" || !("code" in error)) return void 0;
|
|
33
|
+
const code = Number(error.code);
|
|
34
|
+
return Number.isInteger(code) ? code : void 0;
|
|
35
|
+
}
|
|
36
|
+
function generationOf(metadata) {
|
|
37
|
+
const generation = metadata?.generation === void 0 ? "" : String(metadata.generation);
|
|
38
|
+
if (!GENERATION.test(generation) || !Number.isSafeInteger(Number(generation))) {
|
|
39
|
+
throw new import_row_storage_errors.ReportingRowStoreError("PROVIDER_UNAVAILABLE", "object generation is missing");
|
|
40
|
+
}
|
|
41
|
+
return generation;
|
|
42
|
+
}
|
|
43
|
+
function pinnedGeneration(nativeVersion) {
|
|
44
|
+
return typeof nativeVersion === "string" && GENERATION.test(nativeVersion) && Number.isSafeInteger(Number(nativeVersion)) ? nativeVersion : null;
|
|
45
|
+
}
|
|
46
|
+
function assertGcsReportingRowBucketPolicyV1(metadata, prefix) {
|
|
47
|
+
if (!metadata || typeof metadata !== "object") {
|
|
48
|
+
throw new import_row_storage_errors.ReportingRowStoreError("UNSAFE_BINDING", "bucket policy is unavailable");
|
|
49
|
+
}
|
|
50
|
+
if (metadata.iamConfiguration?.uniformBucketLevelAccess?.enabled !== true) {
|
|
51
|
+
throw new import_row_storage_errors.ReportingRowStoreError("UNSAFE_BINDING", "bucket must enable uniform bucket-level access");
|
|
52
|
+
}
|
|
53
|
+
if (metadata.iamConfiguration?.publicAccessPrevention !== "enforced") {
|
|
54
|
+
throw new import_row_storage_errors.ReportingRowStoreError("UNSAFE_BINDING", "bucket must enforce public access prevention");
|
|
55
|
+
}
|
|
56
|
+
for (const rule of metadata.lifecycle?.rule ?? []) {
|
|
57
|
+
if (rule?.action?.type !== "Delete") continue;
|
|
58
|
+
const condition = rule.condition ?? {};
|
|
59
|
+
if (condition.isLive === false) continue;
|
|
60
|
+
if (NONCURRENT_ONLY_CONDITIONS.some((name) => condition[name] !== void 0 && condition[name] !== null)) continue;
|
|
61
|
+
const prefixes = condition.matchesPrefix ?? [];
|
|
62
|
+
if (prefixes.length === 0 || prefixes.some((filter) => (0, import_row_storage_provider_io.reportingRowPrefixFilterOverlaps)(filter, prefix))) {
|
|
63
|
+
throw new import_row_storage_errors.ReportingRowStoreError("UNSAFE_BINDING", "a bucket lifecycle rule can delete live row objects");
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function createGcsReportingRowObjectProviderV1(options) {
|
|
68
|
+
if (!options || typeof options !== "object") {
|
|
69
|
+
throw new import_row_storage_errors.ReportingRowStoreError("INVALID_INPUT", "GCS row provider options are required");
|
|
70
|
+
}
|
|
71
|
+
const clients = (0, import_row_storage_provider_io.reportingRowClientMap)(options.clients);
|
|
72
|
+
const isStorage = (value) => !!value && typeof value === "object" && typeof value.bucket === "function";
|
|
73
|
+
if (options.storage !== void 0 && !isStorage(options.storage) || [...clients.values()].some((client) => !isStorage(client)) || options.storage === void 0 && clients.size === 0) {
|
|
74
|
+
throw new import_row_storage_errors.ReportingRowStoreError("INVALID_INPUT", "inject an official Storage client as storage or clients");
|
|
75
|
+
}
|
|
76
|
+
const validateLocation = (location) => {
|
|
77
|
+
(0, import_row_storage_provider_io.assertReportingRowLocationKeys)(location, ["bucket"]);
|
|
78
|
+
if (!BUCKET.test(location.bucket) || location.bucket.includes("..")) {
|
|
79
|
+
throw new import_row_storage_errors.ReportingRowStoreError("INVALID_INPUT", "GCS bucket name is invalid");
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
const bucketFor = (input) => {
|
|
83
|
+
validateLocation(input.location);
|
|
84
|
+
return (0, import_row_storage_provider_io.selectReportingRowClient)(options.storage, clients, input.credentialRef).bucket(input.location.bucket);
|
|
85
|
+
};
|
|
86
|
+
const assertKey = (key) => {
|
|
87
|
+
if (typeof key !== "string" || key.length === 0 || Buffer.byteLength(key) > 1024) {
|
|
88
|
+
throw new import_row_storage_errors.ReportingRowStoreError("INVALID_INPUT", "object key is invalid");
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
return {
|
|
92
|
+
name: "gcs",
|
|
93
|
+
rangedReads: true,
|
|
94
|
+
validateLocation,
|
|
95
|
+
probe(input, context) {
|
|
96
|
+
return (0, import_row_storage_provider_io.runReportingRowProviderOperation)(context.signal, async () => {
|
|
97
|
+
const bucket = bucketFor(input);
|
|
98
|
+
let metadata;
|
|
99
|
+
try {
|
|
100
|
+
[metadata] = await bucket.getMetadata();
|
|
101
|
+
} catch (error) {
|
|
102
|
+
const code = status(error);
|
|
103
|
+
if (code === 404) throw new import_row_storage_errors.ReportingRowStoreError("UNSAFE_BINDING", "bucket does not exist");
|
|
104
|
+
if (code === 401 || code === 403) {
|
|
105
|
+
throw new import_row_storage_errors.ReportingRowStoreError("UNSAFE_BINDING", "bucket policy cannot be read with this client");
|
|
106
|
+
}
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
109
|
+
assertGcsReportingRowBucketPolicyV1(metadata, input.prefix);
|
|
110
|
+
});
|
|
111
|
+
},
|
|
112
|
+
putIfAbsent(input, context) {
|
|
113
|
+
return (0, import_row_storage_provider_io.runReportingRowProviderOperation)(context.signal, async () => {
|
|
114
|
+
const bucket = bucketFor(input);
|
|
115
|
+
assertKey(input.key);
|
|
116
|
+
const file = bucket.file(input.key);
|
|
117
|
+
try {
|
|
118
|
+
const bytes = Buffer.from(input.bytes);
|
|
119
|
+
await file.save(bytes, {
|
|
120
|
+
resumable: false,
|
|
121
|
+
gzip: false,
|
|
122
|
+
// GCS verifies the declared MD5 before creating the object, so a corrupted upload
|
|
123
|
+
// is refused server-side. Client-side validation is off because on mismatch the
|
|
124
|
+
// client deletes the key without a generation precondition.
|
|
125
|
+
validation: false,
|
|
126
|
+
contentType: input.contentType,
|
|
127
|
+
metadata: {
|
|
128
|
+
contentType: input.contentType,
|
|
129
|
+
md5Hash: (0, import_node_crypto.createHash)("md5").update(bytes).digest("base64"),
|
|
130
|
+
cacheControl: "no-store",
|
|
131
|
+
metadata: { ...input.metadata }
|
|
132
|
+
},
|
|
133
|
+
preconditionOpts: { ifGenerationMatch: 0 }
|
|
134
|
+
});
|
|
135
|
+
} catch (error) {
|
|
136
|
+
if (status(error) !== 412) throw error;
|
|
137
|
+
context.signal.throwIfAborted();
|
|
138
|
+
const [existing] = await bucket.file(input.key).getMetadata();
|
|
139
|
+
return { created: false, nativeVersion: generationOf(existing) };
|
|
140
|
+
}
|
|
141
|
+
if (file.metadata?.generation !== void 0) {
|
|
142
|
+
return { created: true, nativeVersion: generationOf(file.metadata) };
|
|
143
|
+
}
|
|
144
|
+
const [created] = await file.getMetadata();
|
|
145
|
+
return { created: true, nativeVersion: generationOf(created) };
|
|
146
|
+
});
|
|
147
|
+
},
|
|
148
|
+
get(input, context) {
|
|
149
|
+
return (0, import_row_storage_provider_io.runReportingRowProviderOperation)(context.signal, async () => {
|
|
150
|
+
const bucket = bucketFor(input);
|
|
151
|
+
assertKey(input.key);
|
|
152
|
+
(0, import_row_storage_provider_io.assertReportingRowReadBounds)(input);
|
|
153
|
+
const generation = pinnedGeneration(input.nativeVersion);
|
|
154
|
+
if (generation === null) return null;
|
|
155
|
+
const file = bucket.file(input.key, { generation });
|
|
156
|
+
try {
|
|
157
|
+
if (input.range?.length === 0) {
|
|
158
|
+
const [metadata] = await file.getMetadata();
|
|
159
|
+
if (input.range.offset > Number(metadata.size)) {
|
|
160
|
+
throw new import_row_storage_errors.ReportingRowStoreError("ROWS_INTEGRITY_FAILED", "requested range exceeds the stored object");
|
|
161
|
+
}
|
|
162
|
+
return Buffer.alloc(0);
|
|
163
|
+
}
|
|
164
|
+
const stream = file.createReadStream({
|
|
165
|
+
// The client always sends `Accept-Encoding: gzip`; with `decompress: false`
|
|
166
|
+
// neither GCS nor the client transcodes, so these are the stored bytes.
|
|
167
|
+
decompress: false,
|
|
168
|
+
// Digests recorded in PostgreSQL verify every byte returned.
|
|
169
|
+
validation: false,
|
|
170
|
+
...input.range ? { start: input.range.offset, end: input.range.offset + input.range.length - 1 } : {}
|
|
171
|
+
});
|
|
172
|
+
return await (0, import_row_storage_provider_io.readReportingRowStream)(stream, input.maxBytes, context.signal);
|
|
173
|
+
} catch (error) {
|
|
174
|
+
const code = status(error);
|
|
175
|
+
if (code === 404) return null;
|
|
176
|
+
if (code === 416) {
|
|
177
|
+
throw new import_row_storage_errors.ReportingRowStoreError("ROWS_INTEGRITY_FAILED", "requested range exceeds the stored object");
|
|
178
|
+
}
|
|
179
|
+
throw error;
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
},
|
|
183
|
+
delete(input, context) {
|
|
184
|
+
return (0, import_row_storage_provider_io.runReportingRowProviderOperation)(context.signal, async () => {
|
|
185
|
+
const bucket = bucketFor(input);
|
|
186
|
+
assertKey(input.key);
|
|
187
|
+
const generation = pinnedGeneration(input.nativeVersion);
|
|
188
|
+
if (generation === null) return "absent";
|
|
189
|
+
try {
|
|
190
|
+
await bucket.file(input.key, { generation }).delete();
|
|
191
|
+
return "deleted";
|
|
192
|
+
} catch (error) {
|
|
193
|
+
const code = status(error);
|
|
194
|
+
if (code === 404 || code === 412) return "absent";
|
|
195
|
+
throw error;
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
202
|
+
0 && (module.exports = {
|
|
203
|
+
assertGcsReportingRowBucketPolicyV1,
|
|
204
|
+
createGcsReportingRowObjectProviderV1
|
|
205
|
+
});
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { ReportingRowStoreError } from "../ledger/row-storage-errors.mjs";
|
|
3
|
+
import {
|
|
4
|
+
assertReportingRowLocationKeys,
|
|
5
|
+
assertReportingRowReadBounds,
|
|
6
|
+
readReportingRowStream,
|
|
7
|
+
reportingRowClientMap,
|
|
8
|
+
reportingRowPrefixFilterOverlaps,
|
|
9
|
+
runReportingRowProviderOperation,
|
|
10
|
+
selectReportingRowClient
|
|
11
|
+
} from "../ledger/row-storage-provider-io.mjs";
|
|
12
|
+
const BUCKET = /^[a-z0-9][a-z0-9._-]{1,220}[a-z0-9]$/;
|
|
13
|
+
const GENERATION = /^[1-9][0-9]{0,15}$/;
|
|
14
|
+
const NONCURRENT_ONLY_CONDITIONS = ["numNewerVersions", "daysSinceNoncurrentTime", "noncurrentTimeBefore"];
|
|
15
|
+
function status(error) {
|
|
16
|
+
if (!error || typeof error !== "object" || !("code" in error)) return void 0;
|
|
17
|
+
const code = Number(error.code);
|
|
18
|
+
return Number.isInteger(code) ? code : void 0;
|
|
19
|
+
}
|
|
20
|
+
function generationOf(metadata) {
|
|
21
|
+
const generation = metadata?.generation === void 0 ? "" : String(metadata.generation);
|
|
22
|
+
if (!GENERATION.test(generation) || !Number.isSafeInteger(Number(generation))) {
|
|
23
|
+
throw new ReportingRowStoreError("PROVIDER_UNAVAILABLE", "object generation is missing");
|
|
24
|
+
}
|
|
25
|
+
return generation;
|
|
26
|
+
}
|
|
27
|
+
function pinnedGeneration(nativeVersion) {
|
|
28
|
+
return typeof nativeVersion === "string" && GENERATION.test(nativeVersion) && Number.isSafeInteger(Number(nativeVersion)) ? nativeVersion : null;
|
|
29
|
+
}
|
|
30
|
+
function assertGcsReportingRowBucketPolicyV1(metadata, prefix) {
|
|
31
|
+
if (!metadata || typeof metadata !== "object") {
|
|
32
|
+
throw new ReportingRowStoreError("UNSAFE_BINDING", "bucket policy is unavailable");
|
|
33
|
+
}
|
|
34
|
+
if (metadata.iamConfiguration?.uniformBucketLevelAccess?.enabled !== true) {
|
|
35
|
+
throw new ReportingRowStoreError("UNSAFE_BINDING", "bucket must enable uniform bucket-level access");
|
|
36
|
+
}
|
|
37
|
+
if (metadata.iamConfiguration?.publicAccessPrevention !== "enforced") {
|
|
38
|
+
throw new ReportingRowStoreError("UNSAFE_BINDING", "bucket must enforce public access prevention");
|
|
39
|
+
}
|
|
40
|
+
for (const rule of metadata.lifecycle?.rule ?? []) {
|
|
41
|
+
if (rule?.action?.type !== "Delete") continue;
|
|
42
|
+
const condition = rule.condition ?? {};
|
|
43
|
+
if (condition.isLive === false) continue;
|
|
44
|
+
if (NONCURRENT_ONLY_CONDITIONS.some((name) => condition[name] !== void 0 && condition[name] !== null)) continue;
|
|
45
|
+
const prefixes = condition.matchesPrefix ?? [];
|
|
46
|
+
if (prefixes.length === 0 || prefixes.some((filter) => reportingRowPrefixFilterOverlaps(filter, prefix))) {
|
|
47
|
+
throw new ReportingRowStoreError("UNSAFE_BINDING", "a bucket lifecycle rule can delete live row objects");
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function createGcsReportingRowObjectProviderV1(options) {
|
|
52
|
+
if (!options || typeof options !== "object") {
|
|
53
|
+
throw new ReportingRowStoreError("INVALID_INPUT", "GCS row provider options are required");
|
|
54
|
+
}
|
|
55
|
+
const clients = reportingRowClientMap(options.clients);
|
|
56
|
+
const isStorage = (value) => !!value && typeof value === "object" && typeof value.bucket === "function";
|
|
57
|
+
if (options.storage !== void 0 && !isStorage(options.storage) || [...clients.values()].some((client) => !isStorage(client)) || options.storage === void 0 && clients.size === 0) {
|
|
58
|
+
throw new ReportingRowStoreError("INVALID_INPUT", "inject an official Storage client as storage or clients");
|
|
59
|
+
}
|
|
60
|
+
const validateLocation = (location) => {
|
|
61
|
+
assertReportingRowLocationKeys(location, ["bucket"]);
|
|
62
|
+
if (!BUCKET.test(location.bucket) || location.bucket.includes("..")) {
|
|
63
|
+
throw new ReportingRowStoreError("INVALID_INPUT", "GCS bucket name is invalid");
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
const bucketFor = (input) => {
|
|
67
|
+
validateLocation(input.location);
|
|
68
|
+
return selectReportingRowClient(options.storage, clients, input.credentialRef).bucket(input.location.bucket);
|
|
69
|
+
};
|
|
70
|
+
const assertKey = (key) => {
|
|
71
|
+
if (typeof key !== "string" || key.length === 0 || Buffer.byteLength(key) > 1024) {
|
|
72
|
+
throw new ReportingRowStoreError("INVALID_INPUT", "object key is invalid");
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
return {
|
|
76
|
+
name: "gcs",
|
|
77
|
+
rangedReads: true,
|
|
78
|
+
validateLocation,
|
|
79
|
+
probe(input, context) {
|
|
80
|
+
return runReportingRowProviderOperation(context.signal, async () => {
|
|
81
|
+
const bucket = bucketFor(input);
|
|
82
|
+
let metadata;
|
|
83
|
+
try {
|
|
84
|
+
[metadata] = await bucket.getMetadata();
|
|
85
|
+
} catch (error) {
|
|
86
|
+
const code = status(error);
|
|
87
|
+
if (code === 404) throw new ReportingRowStoreError("UNSAFE_BINDING", "bucket does not exist");
|
|
88
|
+
if (code === 401 || code === 403) {
|
|
89
|
+
throw new ReportingRowStoreError("UNSAFE_BINDING", "bucket policy cannot be read with this client");
|
|
90
|
+
}
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
assertGcsReportingRowBucketPolicyV1(metadata, input.prefix);
|
|
94
|
+
});
|
|
95
|
+
},
|
|
96
|
+
putIfAbsent(input, context) {
|
|
97
|
+
return runReportingRowProviderOperation(context.signal, async () => {
|
|
98
|
+
const bucket = bucketFor(input);
|
|
99
|
+
assertKey(input.key);
|
|
100
|
+
const file = bucket.file(input.key);
|
|
101
|
+
try {
|
|
102
|
+
const bytes = Buffer.from(input.bytes);
|
|
103
|
+
await file.save(bytes, {
|
|
104
|
+
resumable: false,
|
|
105
|
+
gzip: false,
|
|
106
|
+
// GCS verifies the declared MD5 before creating the object, so a corrupted upload
|
|
107
|
+
// is refused server-side. Client-side validation is off because on mismatch the
|
|
108
|
+
// client deletes the key without a generation precondition.
|
|
109
|
+
validation: false,
|
|
110
|
+
contentType: input.contentType,
|
|
111
|
+
metadata: {
|
|
112
|
+
contentType: input.contentType,
|
|
113
|
+
md5Hash: createHash("md5").update(bytes).digest("base64"),
|
|
114
|
+
cacheControl: "no-store",
|
|
115
|
+
metadata: { ...input.metadata }
|
|
116
|
+
},
|
|
117
|
+
preconditionOpts: { ifGenerationMatch: 0 }
|
|
118
|
+
});
|
|
119
|
+
} catch (error) {
|
|
120
|
+
if (status(error) !== 412) throw error;
|
|
121
|
+
context.signal.throwIfAborted();
|
|
122
|
+
const [existing] = await bucket.file(input.key).getMetadata();
|
|
123
|
+
return { created: false, nativeVersion: generationOf(existing) };
|
|
124
|
+
}
|
|
125
|
+
if (file.metadata?.generation !== void 0) {
|
|
126
|
+
return { created: true, nativeVersion: generationOf(file.metadata) };
|
|
127
|
+
}
|
|
128
|
+
const [created] = await file.getMetadata();
|
|
129
|
+
return { created: true, nativeVersion: generationOf(created) };
|
|
130
|
+
});
|
|
131
|
+
},
|
|
132
|
+
get(input, context) {
|
|
133
|
+
return runReportingRowProviderOperation(context.signal, async () => {
|
|
134
|
+
const bucket = bucketFor(input);
|
|
135
|
+
assertKey(input.key);
|
|
136
|
+
assertReportingRowReadBounds(input);
|
|
137
|
+
const generation = pinnedGeneration(input.nativeVersion);
|
|
138
|
+
if (generation === null) return null;
|
|
139
|
+
const file = bucket.file(input.key, { generation });
|
|
140
|
+
try {
|
|
141
|
+
if (input.range?.length === 0) {
|
|
142
|
+
const [metadata] = await file.getMetadata();
|
|
143
|
+
if (input.range.offset > Number(metadata.size)) {
|
|
144
|
+
throw new ReportingRowStoreError("ROWS_INTEGRITY_FAILED", "requested range exceeds the stored object");
|
|
145
|
+
}
|
|
146
|
+
return Buffer.alloc(0);
|
|
147
|
+
}
|
|
148
|
+
const stream = file.createReadStream({
|
|
149
|
+
// The client always sends `Accept-Encoding: gzip`; with `decompress: false`
|
|
150
|
+
// neither GCS nor the client transcodes, so these are the stored bytes.
|
|
151
|
+
decompress: false,
|
|
152
|
+
// Digests recorded in PostgreSQL verify every byte returned.
|
|
153
|
+
validation: false,
|
|
154
|
+
...input.range ? { start: input.range.offset, end: input.range.offset + input.range.length - 1 } : {}
|
|
155
|
+
});
|
|
156
|
+
return await readReportingRowStream(stream, input.maxBytes, context.signal);
|
|
157
|
+
} catch (error) {
|
|
158
|
+
const code = status(error);
|
|
159
|
+
if (code === 404) return null;
|
|
160
|
+
if (code === 416) {
|
|
161
|
+
throw new ReportingRowStoreError("ROWS_INTEGRITY_FAILED", "requested range exceeds the stored object");
|
|
162
|
+
}
|
|
163
|
+
throw error;
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
},
|
|
167
|
+
delete(input, context) {
|
|
168
|
+
return runReportingRowProviderOperation(context.signal, async () => {
|
|
169
|
+
const bucket = bucketFor(input);
|
|
170
|
+
assertKey(input.key);
|
|
171
|
+
const generation = pinnedGeneration(input.nativeVersion);
|
|
172
|
+
if (generation === null) return "absent";
|
|
173
|
+
try {
|
|
174
|
+
await bucket.file(input.key, { generation }).delete();
|
|
175
|
+
return "deleted";
|
|
176
|
+
} catch (error) {
|
|
177
|
+
const code = status(error);
|
|
178
|
+
if (code === 404 || code === 412) return "absent";
|
|
179
|
+
throw error;
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
export {
|
|
186
|
+
assertGcsReportingRowBucketPolicyV1,
|
|
187
|
+
createGcsReportingRowObjectProviderV1
|
|
188
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host-facing reporting change feed (shared SDK persistence spec,
|
|
3
|
+
* adcontextprotocol/adcp#7996 §2.1 and §3.7).
|
|
4
|
+
*
|
|
5
|
+
* Apply after {@link REPORTING_LEDGER_MIGRATION}; PostgreSQL 13 or later
|
|
6
|
+
* (`xid8`). The store appends one row per committed obligation, revision,
|
|
7
|
+
* adjustment and retirement in the same transaction as the record, taking the
|
|
8
|
+
* sequence value only after the account lock, so per-account sequence order is
|
|
9
|
+
* commit order. Deployment-wide readers order by `(xid, seq)` and stop below
|
|
10
|
+
* the reading snapshot's `xmin`, so a slow commit is never skipped.
|
|
11
|
+
*/
|
|
12
|
+
export declare const REPORTING_LEDGER_CHANGES_MIGRATION: string;
|
|
13
|
+
export type ReportingChangeKindV1 = 'obligation' | 'revision' | 'adjustment' | 'retirement';
|
|
14
|
+
export interface ReportingChangeRecordV1 {
|
|
15
|
+
kind: ReportingChangeKindV1;
|
|
16
|
+
record_id: string;
|
|
17
|
+
reporting_obligation_id: string;
|
|
18
|
+
account_id: string;
|
|
19
|
+
recorded_at: string;
|
|
20
|
+
}
|
|
21
|
+
export interface ReportingChangesPageV1 {
|
|
22
|
+
records: ReportingChangeRecordV1[];
|
|
23
|
+
/** Pass back to resume. Always present; equal to the input when nothing new committed. */
|
|
24
|
+
cursor: string;
|
|
25
|
+
}
|
|
26
|
+
interface ChangeCursorV1 {
|
|
27
|
+
v: 1;
|
|
28
|
+
/** Account scope, or `null` for the deployment-wide feed. */
|
|
29
|
+
account: string | null;
|
|
30
|
+
seq: string;
|
|
31
|
+
/** Deployment-wide feeds only: the writing transaction of the last record returned. */
|
|
32
|
+
xid?: string;
|
|
33
|
+
}
|
|
34
|
+
export declare function encodeReportingChangeCursorV1(cursor: ChangeCursorV1): string;
|
|
35
|
+
export declare function decodeReportingChangeCursorV1(value: string, account: string | null): ChangeCursorV1;
|
|
36
|
+
/** Thrown when a change cursor is older than the retained change history. */
|
|
37
|
+
export declare class ReportingChangeCursorExpiredError extends Error {
|
|
38
|
+
readonly code: "CURSOR_EXPIRED";
|
|
39
|
+
constructor();
|
|
40
|
+
}
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host-facing reporting change feed (shared SDK persistence spec,
|
|
3
|
+
* adcontextprotocol/adcp#7996 §2.1 and §3.7).
|
|
4
|
+
*
|
|
5
|
+
* Apply after {@link REPORTING_LEDGER_MIGRATION}; PostgreSQL 13 or later
|
|
6
|
+
* (`xid8`). The store appends one row per committed obligation, revision,
|
|
7
|
+
* adjustment and retirement in the same transaction as the record, taking the
|
|
8
|
+
* sequence value only after the account lock, so per-account sequence order is
|
|
9
|
+
* commit order. Deployment-wide readers order by `(xid, seq)` and stop below
|
|
10
|
+
* the reading snapshot's `xmin`, so a slow commit is never skipped.
|
|
11
|
+
*/
|
|
12
|
+
export declare const REPORTING_LEDGER_CHANGES_MIGRATION: string;
|
|
13
|
+
export type ReportingChangeKindV1 = 'obligation' | 'revision' | 'adjustment' | 'retirement';
|
|
14
|
+
export interface ReportingChangeRecordV1 {
|
|
15
|
+
kind: ReportingChangeKindV1;
|
|
16
|
+
record_id: string;
|
|
17
|
+
reporting_obligation_id: string;
|
|
18
|
+
account_id: string;
|
|
19
|
+
recorded_at: string;
|
|
20
|
+
}
|
|
21
|
+
export interface ReportingChangesPageV1 {
|
|
22
|
+
records: ReportingChangeRecordV1[];
|
|
23
|
+
/** Pass back to resume. Always present; equal to the input when nothing new committed. */
|
|
24
|
+
cursor: string;
|
|
25
|
+
}
|
|
26
|
+
interface ChangeCursorV1 {
|
|
27
|
+
v: 1;
|
|
28
|
+
/** Account scope, or `null` for the deployment-wide feed. */
|
|
29
|
+
account: string | null;
|
|
30
|
+
seq: string;
|
|
31
|
+
/** Deployment-wide feeds only: the writing transaction of the last record returned. */
|
|
32
|
+
xid?: string;
|
|
33
|
+
}
|
|
34
|
+
export declare function encodeReportingChangeCursorV1(cursor: ChangeCursorV1): string;
|
|
35
|
+
export declare function decodeReportingChangeCursorV1(value: string, account: string | null): ChangeCursorV1;
|
|
36
|
+
/** Thrown when a change cursor is older than the retained change history. */
|
|
37
|
+
export declare class ReportingChangeCursorExpiredError extends Error {
|
|
38
|
+
readonly code: "CURSOR_EXPIRED";
|
|
39
|
+
constructor();
|
|
40
|
+
}
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,101 @@
|
|
|
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 change_feed_exports = {};
|
|
20
|
+
__export(change_feed_exports, {
|
|
21
|
+
REPORTING_LEDGER_CHANGES_MIGRATION: () => REPORTING_LEDGER_CHANGES_MIGRATION,
|
|
22
|
+
ReportingChangeCursorExpiredError: () => ReportingChangeCursorExpiredError,
|
|
23
|
+
decodeReportingChangeCursorV1: () => decodeReportingChangeCursorV1,
|
|
24
|
+
encodeReportingChangeCursorV1: () => encodeReportingChangeCursorV1
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(change_feed_exports);
|
|
27
|
+
var import_row_storage_errors = require('./row-storage-errors.js');
|
|
28
|
+
const REPORTING_LEDGER_CHANGES_MIGRATION = `
|
|
29
|
+
CREATE TABLE IF NOT EXISTS adcp_reporting_changes (
|
|
30
|
+
seq BIGSERIAL PRIMARY KEY,
|
|
31
|
+
xid xid8 NOT NULL DEFAULT pg_current_xact_id(),
|
|
32
|
+
account_id TEXT NOT NULL,
|
|
33
|
+
record_kind TEXT NOT NULL
|
|
34
|
+
CHECK (record_kind IN ('obligation', 'revision', 'adjustment', 'retirement')),
|
|
35
|
+
record_id TEXT NOT NULL,
|
|
36
|
+
obligation_id TEXT NOT NULL,
|
|
37
|
+
recorded_at TIMESTAMPTZ NOT NULL DEFAULT clock_timestamp()
|
|
38
|
+
);
|
|
39
|
+
CREATE INDEX IF NOT EXISTS adcp_reporting_changes_account
|
|
40
|
+
ON adcp_reporting_changes (account_id, seq);
|
|
41
|
+
CREATE INDEX IF NOT EXISTS adcp_reporting_changes_deployment
|
|
42
|
+
ON adcp_reporting_changes (xid, seq);
|
|
43
|
+
CREATE INDEX IF NOT EXISTS adcp_reporting_changes_recorded
|
|
44
|
+
ON adcp_reporting_changes (recorded_at, seq);
|
|
45
|
+
|
|
46
|
+
-- Highest (xid, seq) ever pruned: a deployment-wide cursor below it may have
|
|
47
|
+
-- missed a deleted change and fails closed.
|
|
48
|
+
CREATE TABLE IF NOT EXISTS adcp_reporting_change_horizon (
|
|
49
|
+
singleton BOOLEAN PRIMARY KEY DEFAULT TRUE CHECK (singleton),
|
|
50
|
+
pruned_through_xid xid8 NOT NULL DEFAULT '0',
|
|
51
|
+
pruned_through_seq BIGINT NOT NULL DEFAULT 0
|
|
52
|
+
);
|
|
53
|
+
INSERT INTO adcp_reporting_change_horizon (singleton) VALUES (TRUE) ON CONFLICT DO NOTHING;
|
|
54
|
+
|
|
55
|
+
-- Highest seq ever pruned per account: an account cursor below it fails closed.
|
|
56
|
+
CREATE TABLE IF NOT EXISTS adcp_reporting_change_account_horizon (
|
|
57
|
+
account_id TEXT PRIMARY KEY,
|
|
58
|
+
pruned_through_seq BIGINT NOT NULL
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
-- Registered consumers hold back pruning in their own feed order: account
|
|
62
|
+
-- consumers by seq within their account, deployment consumers by (xid, seq).
|
|
63
|
+
CREATE TABLE IF NOT EXISTS adcp_reporting_feed_consumers (
|
|
64
|
+
consumer_name TEXT PRIMARY KEY CHECK (consumer_name ~ '^[A-Za-z0-9_.:-]{1,128}$'),
|
|
65
|
+
account_id TEXT,
|
|
66
|
+
cursor_xid xid8,
|
|
67
|
+
cursor_seq BIGINT NOT NULL,
|
|
68
|
+
updated_at TIMESTAMPTZ NOT NULL DEFAULT clock_timestamp(),
|
|
69
|
+
CHECK ((account_id IS NULL) = (cursor_xid IS NOT NULL))
|
|
70
|
+
);
|
|
71
|
+
`.trim();
|
|
72
|
+
function encodeReportingChangeCursorV1(cursor) {
|
|
73
|
+
return Buffer.from(JSON.stringify(cursor), "utf8").toString("base64url");
|
|
74
|
+
}
|
|
75
|
+
function decodeReportingChangeCursorV1(value, account) {
|
|
76
|
+
let parsed;
|
|
77
|
+
try {
|
|
78
|
+
parsed = JSON.parse(Buffer.from(value, "base64url").toString("utf8"));
|
|
79
|
+
} catch {
|
|
80
|
+
throw new import_row_storage_errors.ReportingRowStoreError("INVALID_INPUT", "change cursor is malformed");
|
|
81
|
+
}
|
|
82
|
+
const cursor = parsed;
|
|
83
|
+
if (cursor.v !== 1 || (cursor.account ?? null) !== account || typeof cursor.seq !== "string" || !/^\d{1,19}$/.test(cursor.seq) || (account === null ? typeof cursor.xid !== "string" || !/^\d{1,20}$/.test(cursor.xid) : cursor.xid !== void 0)) {
|
|
84
|
+
throw new import_row_storage_errors.ReportingRowStoreError("INVALID_INPUT", "change cursor does not belong to this feed");
|
|
85
|
+
}
|
|
86
|
+
return cursor;
|
|
87
|
+
}
|
|
88
|
+
class ReportingChangeCursorExpiredError extends Error {
|
|
89
|
+
code = "CURSOR_EXPIRED";
|
|
90
|
+
constructor() {
|
|
91
|
+
super("Reporting change cursor is older than the retained change history; resynchronize from current revisions");
|
|
92
|
+
this.name = "ReportingChangeCursorExpiredError";
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
96
|
+
0 && (module.exports = {
|
|
97
|
+
REPORTING_LEDGER_CHANGES_MIGRATION,
|
|
98
|
+
ReportingChangeCursorExpiredError,
|
|
99
|
+
decodeReportingChangeCursorV1,
|
|
100
|
+
encodeReportingChangeCursorV1
|
|
101
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { ReportingRowStoreError } from "./row-storage-errors.mjs";
|
|
2
|
+
const REPORTING_LEDGER_CHANGES_MIGRATION = `
|
|
3
|
+
CREATE TABLE IF NOT EXISTS adcp_reporting_changes (
|
|
4
|
+
seq BIGSERIAL PRIMARY KEY,
|
|
5
|
+
xid xid8 NOT NULL DEFAULT pg_current_xact_id(),
|
|
6
|
+
account_id TEXT NOT NULL,
|
|
7
|
+
record_kind TEXT NOT NULL
|
|
8
|
+
CHECK (record_kind IN ('obligation', 'revision', 'adjustment', 'retirement')),
|
|
9
|
+
record_id TEXT NOT NULL,
|
|
10
|
+
obligation_id TEXT NOT NULL,
|
|
11
|
+
recorded_at TIMESTAMPTZ NOT NULL DEFAULT clock_timestamp()
|
|
12
|
+
);
|
|
13
|
+
CREATE INDEX IF NOT EXISTS adcp_reporting_changes_account
|
|
14
|
+
ON adcp_reporting_changes (account_id, seq);
|
|
15
|
+
CREATE INDEX IF NOT EXISTS adcp_reporting_changes_deployment
|
|
16
|
+
ON adcp_reporting_changes (xid, seq);
|
|
17
|
+
CREATE INDEX IF NOT EXISTS adcp_reporting_changes_recorded
|
|
18
|
+
ON adcp_reporting_changes (recorded_at, seq);
|
|
19
|
+
|
|
20
|
+
-- Highest (xid, seq) ever pruned: a deployment-wide cursor below it may have
|
|
21
|
+
-- missed a deleted change and fails closed.
|
|
22
|
+
CREATE TABLE IF NOT EXISTS adcp_reporting_change_horizon (
|
|
23
|
+
singleton BOOLEAN PRIMARY KEY DEFAULT TRUE CHECK (singleton),
|
|
24
|
+
pruned_through_xid xid8 NOT NULL DEFAULT '0',
|
|
25
|
+
pruned_through_seq BIGINT NOT NULL DEFAULT 0
|
|
26
|
+
);
|
|
27
|
+
INSERT INTO adcp_reporting_change_horizon (singleton) VALUES (TRUE) ON CONFLICT DO NOTHING;
|
|
28
|
+
|
|
29
|
+
-- Highest seq ever pruned per account: an account cursor below it fails closed.
|
|
30
|
+
CREATE TABLE IF NOT EXISTS adcp_reporting_change_account_horizon (
|
|
31
|
+
account_id TEXT PRIMARY KEY,
|
|
32
|
+
pruned_through_seq BIGINT NOT NULL
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
-- Registered consumers hold back pruning in their own feed order: account
|
|
36
|
+
-- consumers by seq within their account, deployment consumers by (xid, seq).
|
|
37
|
+
CREATE TABLE IF NOT EXISTS adcp_reporting_feed_consumers (
|
|
38
|
+
consumer_name TEXT PRIMARY KEY CHECK (consumer_name ~ '^[A-Za-z0-9_.:-]{1,128}$'),
|
|
39
|
+
account_id TEXT,
|
|
40
|
+
cursor_xid xid8,
|
|
41
|
+
cursor_seq BIGINT NOT NULL,
|
|
42
|
+
updated_at TIMESTAMPTZ NOT NULL DEFAULT clock_timestamp(),
|
|
43
|
+
CHECK ((account_id IS NULL) = (cursor_xid IS NOT NULL))
|
|
44
|
+
);
|
|
45
|
+
`.trim();
|
|
46
|
+
function encodeReportingChangeCursorV1(cursor) {
|
|
47
|
+
return Buffer.from(JSON.stringify(cursor), "utf8").toString("base64url");
|
|
48
|
+
}
|
|
49
|
+
function decodeReportingChangeCursorV1(value, account) {
|
|
50
|
+
let parsed;
|
|
51
|
+
try {
|
|
52
|
+
parsed = JSON.parse(Buffer.from(value, "base64url").toString("utf8"));
|
|
53
|
+
} catch {
|
|
54
|
+
throw new ReportingRowStoreError("INVALID_INPUT", "change cursor is malformed");
|
|
55
|
+
}
|
|
56
|
+
const cursor = parsed;
|
|
57
|
+
if (cursor.v !== 1 || (cursor.account ?? null) !== account || typeof cursor.seq !== "string" || !/^\d{1,19}$/.test(cursor.seq) || (account === null ? typeof cursor.xid !== "string" || !/^\d{1,20}$/.test(cursor.xid) : cursor.xid !== void 0)) {
|
|
58
|
+
throw new ReportingRowStoreError("INVALID_INPUT", "change cursor does not belong to this feed");
|
|
59
|
+
}
|
|
60
|
+
return cursor;
|
|
61
|
+
}
|
|
62
|
+
class ReportingChangeCursorExpiredError extends Error {
|
|
63
|
+
code = "CURSOR_EXPIRED";
|
|
64
|
+
constructor() {
|
|
65
|
+
super("Reporting change cursor is older than the retained change history; resynchronize from current revisions");
|
|
66
|
+
this.name = "ReportingChangeCursorExpiredError";
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export {
|
|
70
|
+
REPORTING_LEDGER_CHANGES_MIGRATION,
|
|
71
|
+
ReportingChangeCursorExpiredError,
|
|
72
|
+
decodeReportingChangeCursorV1,
|
|
73
|
+
encodeReportingChangeCursorV1
|
|
74
|
+
};
|
|
@@ -15,6 +15,12 @@ export interface ReportingStatusConsumerScopeOptionsV1<TContext = unknown> {
|
|
|
15
15
|
}
|
|
16
16
|
export declare function createReportingStatusHandler(store: ReportingLedgerStore): (request: Parameters<ReportingStatusHandlerV1>[0], context: Pick<Parameters<ReportingStatusHandlerV1>[1], 'account' | 'signal'>) => ReturnType<ReportingStatusHandlerV1>;
|
|
17
17
|
export declare function createReportingStatusHandler<TContext = unknown>(store: ReportingLedgerStore, options?: ReportingStatusConsumerScopeOptionsV1<TContext>): ReportingStatusHandlerV1;
|
|
18
|
+
/**
|
|
19
|
+
* Largest revision whose rows the `get_reporting_status` `revision` view
|
|
20
|
+
* returns inline. Larger revisions omit `reporting_rows` there; callers page
|
|
21
|
+
* them through the exact `get_media_buy_delivery` read.
|
|
22
|
+
*/
|
|
23
|
+
export declare const REPORTING_STATUS_REVISION_VIEW_MAX_ROWS = 10000;
|
|
18
24
|
/** Exact revision reader for createAdcpServer's getMediaBuyDelivery slot. */
|
|
19
25
|
export declare function createReportingDeliveryHandler(store: ReportingLedgerStore): ReportingDeliveryHandlerV1;
|
|
20
26
|
export interface ProjectManagedDeliveryInputV1 {
|