@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
|
@@ -130,6 +130,13 @@ async function createReportingManagedDeliveryRuntime(options) {
|
|
|
130
130
|
getMediaBuyDelivery,
|
|
131
131
|
...syncReportingReceipts ? { syncReportingReceipts } : {},
|
|
132
132
|
runWorker: (workerOptions) => runManagedDeliveryWorker(options.store, options.adapter, {
|
|
133
|
+
...typeof options.coreStore.getRevision === "function" ? {
|
|
134
|
+
hydrateRevision: async (revision, accountId) => {
|
|
135
|
+
const hydrated = await options.coreStore.getRevision(revision.reporting_revision_id, accountId);
|
|
136
|
+
if (!hydrated) throw new Error("Reporting revision is unavailable for delivery");
|
|
137
|
+
return hydrated;
|
|
138
|
+
}
|
|
139
|
+
} : {},
|
|
133
140
|
...workerOptions,
|
|
134
141
|
minimumResourceRetentionDays: Math.max(
|
|
135
142
|
options.resourceRetentionDays,
|
|
@@ -356,6 +363,17 @@ async function runManagedDeliveryWorker(store, adapter, options = {}) {
|
|
|
356
363
|
if (!lease) break;
|
|
357
364
|
counts.claimed += 1;
|
|
358
365
|
try {
|
|
366
|
+
if (!Array.isArray(lease.revision.rows) && options.hydrateRevision) {
|
|
367
|
+
const hydrated = await options.hydrateRevision(
|
|
368
|
+
lease.revision,
|
|
369
|
+
lease.obligation.account.account_id,
|
|
370
|
+
options.signal
|
|
371
|
+
);
|
|
372
|
+
if (hydrated.reporting_revision_id !== lease.revision.reporting_revision_id || hydrated.binding.sha256 !== lease.revision.binding.sha256 || !Array.isArray(hydrated.rows)) {
|
|
373
|
+
throw new Error("Hydrated reporting revision does not match the claimed revision");
|
|
374
|
+
}
|
|
375
|
+
lease.revision = hydrated;
|
|
376
|
+
}
|
|
359
377
|
const outcome = await withinDeadline(
|
|
360
378
|
(signal) => adapter.deliver(
|
|
361
379
|
{
|
|
@@ -103,6 +103,13 @@ async function createReportingManagedDeliveryRuntime(options) {
|
|
|
103
103
|
getMediaBuyDelivery,
|
|
104
104
|
...syncReportingReceipts ? { syncReportingReceipts } : {},
|
|
105
105
|
runWorker: (workerOptions) => runManagedDeliveryWorker(options.store, options.adapter, {
|
|
106
|
+
...typeof options.coreStore.getRevision === "function" ? {
|
|
107
|
+
hydrateRevision: async (revision, accountId) => {
|
|
108
|
+
const hydrated = await options.coreStore.getRevision(revision.reporting_revision_id, accountId);
|
|
109
|
+
if (!hydrated) throw new Error("Reporting revision is unavailable for delivery");
|
|
110
|
+
return hydrated;
|
|
111
|
+
}
|
|
112
|
+
} : {},
|
|
106
113
|
...workerOptions,
|
|
107
114
|
minimumResourceRetentionDays: Math.max(
|
|
108
115
|
options.resourceRetentionDays,
|
|
@@ -329,6 +336,17 @@ async function runManagedDeliveryWorker(store, adapter, options = {}) {
|
|
|
329
336
|
if (!lease) break;
|
|
330
337
|
counts.claimed += 1;
|
|
331
338
|
try {
|
|
339
|
+
if (!Array.isArray(lease.revision.rows) && options.hydrateRevision) {
|
|
340
|
+
const hydrated = await options.hydrateRevision(
|
|
341
|
+
lease.revision,
|
|
342
|
+
lease.obligation.account.account_id,
|
|
343
|
+
options.signal
|
|
344
|
+
);
|
|
345
|
+
if (hydrated.reporting_revision_id !== lease.revision.reporting_revision_id || hydrated.binding.sha256 !== lease.revision.binding.sha256 || !Array.isArray(hydrated.rows)) {
|
|
346
|
+
throw new Error("Hydrated reporting revision does not match the claimed revision");
|
|
347
|
+
}
|
|
348
|
+
lease.revision = hydrated;
|
|
349
|
+
}
|
|
332
350
|
const outcome = await withinDeadline(
|
|
333
351
|
(signal) => adapter.deliver(
|
|
334
352
|
{
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { REPORTING_LEDGER_AUTHORITY } from './types.mjs';
|
|
2
|
-
import type { ReportingLedgerConfigurationV1, ReportingLedgerAdjustmentV1, ReportingLedgerConsumerStatusV1, ReportingLedgerIssueV1, ReportingLedgerLeaseV1, ReportingLedgerObligationV1, ReportingLedgerPageV1, ReportingLedgerRevisionV1, ReportingLedgerSnapshotQueryV1, ReportingLedgerSnapshotV1, ReportingLedgerStatusTransitionV1, ReportingLedgerNotificationActivityPortV1, ReportingLedgerTransactionV1, ReportingObservedFinalityV1, ReportingLedgerStore, ReportingConsumerStatusBatchInputV1, ReportingConsumerStatusBatchResultV1, ReportingConsumerStatusReplayInputV1, ReportingLedgerRevisionMetadataV1, ReportingManagedLifecycleProjectionV1, ReportingLedgerAuthorityV1 } from './types.mjs';
|
|
2
|
+
import type { ReportingLedgerConfigurationV1, ReportingLedgerAdjustmentMetadataV1, ReportingLedgerAdjustmentV1, ReportingLedgerConsumerStatusV1, ReportingLedgerIssueV1, ReportingLedgerLeaseV1, ReportingLedgerObligationV1, ReportingLedgerPageV1, ReportingLedgerRevisionV1, ReportingLedgerSnapshotQueryV1, ReportingLedgerSnapshotV1, ReportingLedgerStatusTransitionV1, ReportingLedgerNotificationActivityPortV1, ReportingLedgerTransactionV1, ReportingObservedFinalityV1, ReportingLedgerStore, ReportingConsumerStatusBatchInputV1, ReportingConsumerStatusBatchResultV1, ReportingConsumerStatusReplayInputV1, ReportingLedgerRevisionMetadataV1, ReportingRevisionRowsPageV1, ReportingRevisionRowsReadV1, ReportingManagedLifecycleProjectionV1, ReportingLedgerAuthorityV1 } from './types.mjs';
|
|
3
3
|
import type { ReportingConsumerMismatchEscalationV1 } from './types.mjs';
|
|
4
|
+
import { type ReportingChangeKindV1, type ReportingChangesPageV1 } from './change-feed.mjs';
|
|
5
|
+
import { type ReportingRowStorageOptionsV1 } from './row-storage.mjs';
|
|
4
6
|
type QueryResultRow = Record<string, unknown>;
|
|
5
7
|
interface ReportingPgResult<Row extends QueryResultRow> {
|
|
6
8
|
rows: Row[];
|
|
@@ -86,10 +88,28 @@ export interface PostgresReportingLedgerStoreOptions {
|
|
|
86
88
|
* lifecycle transaction. Its tables must be migrated before transitions run.
|
|
87
89
|
*/
|
|
88
90
|
notificationActivityPort?: ReportingLedgerNotificationActivityPortV1<ReportingLedgerTransactionV1>;
|
|
91
|
+
/**
|
|
92
|
+
* Store new revision and adjustment rows as verified canonical JSONL chunks
|
|
93
|
+
* (see `REPORTING_ROW_STORAGE_MIGRATION`) instead of inline in the ledger
|
|
94
|
+
* document. `true` uses a single `postgres` binding. Revisions written
|
|
95
|
+
* before enabling this keep their inline rows; reads handle both forms
|
|
96
|
+
* whether or not this option is set.
|
|
97
|
+
*/
|
|
98
|
+
rowStorage?: boolean | ReportingRowStorageOptionsV1;
|
|
99
|
+
/**
|
|
100
|
+
* Append obligation, revision, adjustment and retirement changes to the
|
|
101
|
+
* host change feed (`REPORTING_LEDGER_CHANGES_MIGRATION`, PostgreSQL 13+) in
|
|
102
|
+
* the same transaction as each record. Required for `changesAfter`.
|
|
103
|
+
*/
|
|
104
|
+
changeFeed?: boolean;
|
|
89
105
|
}
|
|
90
106
|
export declare class ReportingLedgerLeaseLostError extends Error {
|
|
91
107
|
constructor(message?: string);
|
|
92
108
|
}
|
|
109
|
+
/** A planner or writer named a period whose ledger records were retired by retention. */
|
|
110
|
+
export declare class ReportingLedgerPeriodRetiredError extends Error {
|
|
111
|
+
constructor(message?: string);
|
|
112
|
+
}
|
|
93
113
|
export declare class ReportingLedgerContinuityError extends Error {
|
|
94
114
|
constructor(message?: string);
|
|
95
115
|
}
|
|
@@ -113,7 +133,36 @@ export declare class PostgresReportingLedgerStore implements ReportingLedgerStor
|
|
|
113
133
|
private readonly obligatedConsumers;
|
|
114
134
|
readonly transactionalNotificationActivity: boolean;
|
|
115
135
|
private readonly notificationActivityPort?;
|
|
136
|
+
private readonly rowStorage;
|
|
137
|
+
private readonly rowStorageWrites;
|
|
138
|
+
private readonly changeFeed;
|
|
116
139
|
constructor(pool: ReportingPgPool, options?: PostgresReportingLedgerStoreOptions);
|
|
140
|
+
/** Append one host change-feed row inside the caller's account-locked transaction. */
|
|
141
|
+
private appendChange;
|
|
142
|
+
/** Probe and register row storage when enabled. Safe to call repeatedly. */
|
|
143
|
+
readyRowStorage(): Promise<void>;
|
|
144
|
+
/**
|
|
145
|
+
* Move legacy inline revision and adjustment rows into row storage, a
|
|
146
|
+
* bounded batch at a time. Each row set is re-encoded, proven to reproduce
|
|
147
|
+
* its committed binding, written, and only then removed from the ledger
|
|
148
|
+
* document, in one transaction under the account lock. A document whose
|
|
149
|
+
* rows do not reproduce its binding is never rewritten: it is reported in
|
|
150
|
+
* `quarantined` and left inline. Pass the returned `cursor` back to resume
|
|
151
|
+
* after the last examined document; it is absent once every candidate has
|
|
152
|
+
* been examined. Reclaiming the freed space needs `VACUUM FULL` or an online
|
|
153
|
+
* repack.
|
|
154
|
+
*/
|
|
155
|
+
migrateInlineRows(input?: {
|
|
156
|
+
limit?: number;
|
|
157
|
+
account_id?: string;
|
|
158
|
+
cursor?: string;
|
|
159
|
+
bindingId?: string;
|
|
160
|
+
signal?: AbortSignal;
|
|
161
|
+
}): Promise<{
|
|
162
|
+
migrated: number;
|
|
163
|
+
quarantined: string[];
|
|
164
|
+
cursor?: string;
|
|
165
|
+
}>;
|
|
117
166
|
putConfiguration(configuration: ReportingLedgerConfigurationV1): Promise<{
|
|
118
167
|
inserted: boolean;
|
|
119
168
|
value: ReportingLedgerConfigurationV1;
|
|
@@ -124,6 +173,11 @@ export declare class PostgresReportingLedgerStore implements ReportingLedgerStor
|
|
|
124
173
|
value: ReportingLedgerObligationV1;
|
|
125
174
|
}>;
|
|
126
175
|
getObligation(id: string, account_id?: string): Promise<ReportingLedgerObligationV1 | null>;
|
|
176
|
+
/** Periods retired by retention; planners treat them as already covered. */
|
|
177
|
+
listRetiredObligationOrdinals(account_id?: string): Promise<{
|
|
178
|
+
configurationId: string;
|
|
179
|
+
periodOrdinal: number;
|
|
180
|
+
}[]>;
|
|
127
181
|
listObligations(account_id?: string): Promise<ReportingLedgerObligationV1[]>;
|
|
128
182
|
listLifecycleDueObligations(input: {
|
|
129
183
|
ledgerAsOf: string;
|
|
@@ -144,12 +198,136 @@ export declare class PostgresReportingLedgerStore implements ReportingLedgerStor
|
|
|
144
198
|
}>;
|
|
145
199
|
getRevision(id: string, accountId: string): Promise<ReportingLedgerRevisionV1 | null>;
|
|
146
200
|
getRevisionMetadata(id: string, accountId: string): Promise<ReportingLedgerRevisionMetadataV1 | null>;
|
|
201
|
+
readRevisionRows(input: ReportingRevisionRowsReadV1): Promise<ReportingRevisionRowsPageV1 | null>;
|
|
147
202
|
listRevisions(obligationId: string): Promise<ReportingLedgerRevisionV1[]>;
|
|
203
|
+
listRevisionMetadata(obligationId: string, accountId?: string): Promise<ReportingLedgerRevisionMetadataV1[]>;
|
|
148
204
|
commitAdjustment(adjustment: ReportingLedgerAdjustmentV1, lease: ReportingLedgerLeaseV1): Promise<{
|
|
149
205
|
inserted: boolean;
|
|
150
206
|
value: ReportingLedgerAdjustmentV1;
|
|
151
207
|
}>;
|
|
152
208
|
listAdjustments(obligationId: string): Promise<ReportingLedgerAdjustmentV1[]>;
|
|
209
|
+
/**
|
|
210
|
+
* The obligation's current revision header: its official revision if one
|
|
211
|
+
* exists, otherwise its highest-numbered snapshot. An official revision is
|
|
212
|
+
* terminal, so this is always the highest revision number — one index
|
|
213
|
+
* lookup. Rows are read separately through `readRevisionRows`.
|
|
214
|
+
*/
|
|
215
|
+
getCurrentRevision(input: {
|
|
216
|
+
account_id: string;
|
|
217
|
+
reporting_obligation_id: string;
|
|
218
|
+
}): Promise<ReportingLedgerRevisionMetadataV1 | null>;
|
|
219
|
+
/**
|
|
220
|
+
* Current revision headers for an account's obligations whose period starts
|
|
221
|
+
* in `[period_start_from, period_start_to)`, ordered by period start.
|
|
222
|
+
* Obligations without a revision yet are omitted. Page with `cursor`.
|
|
223
|
+
*/
|
|
224
|
+
listCurrentRevisions(input: {
|
|
225
|
+
account_id: string;
|
|
226
|
+
period_start_from: string;
|
|
227
|
+
period_start_to: string;
|
|
228
|
+
delivery_config_id?: string;
|
|
229
|
+
limit?: number;
|
|
230
|
+
cursor?: string;
|
|
231
|
+
}): Promise<{
|
|
232
|
+
revisions: ReportingLedgerRevisionMetadataV1[];
|
|
233
|
+
cursor?: string;
|
|
234
|
+
}>;
|
|
235
|
+
/**
|
|
236
|
+
* Host change feed. Omit `cursor` to start from the oldest retained change.
|
|
237
|
+
* Account-scoped feeds order by sequence; the deployment-wide feed orders by
|
|
238
|
+
* `(xid, seq)` and returns only changes whose transaction precedes every
|
|
239
|
+
* transaction still in flight, so no commit is ever skipped. A cursor older
|
|
240
|
+
* than the retained history throws `ReportingChangeCursorExpiredError`;
|
|
241
|
+
* resynchronize from `listCurrentRevisions`.
|
|
242
|
+
*/
|
|
243
|
+
changesAfter(input?: {
|
|
244
|
+
cursor?: string;
|
|
245
|
+
account_id?: string;
|
|
246
|
+
kinds?: readonly ReportingChangeKindV1[];
|
|
247
|
+
limit?: number;
|
|
248
|
+
}): Promise<ReportingChangesPageV1>;
|
|
249
|
+
/**
|
|
250
|
+
* Record a named durable consumer's position. Registered consumers hold
|
|
251
|
+
* back change-table pruning until `maxFeedHoldDays` after their last update.
|
|
252
|
+
*/
|
|
253
|
+
saveFeedConsumerCursor(name: string, cursor: string): Promise<void>;
|
|
254
|
+
/**
|
|
255
|
+
* Delete change rows older than `changeRetentionDays` that every consumer
|
|
256
|
+
* updated within `maxFeedHoldDays` has passed, and advance the expiry
|
|
257
|
+
* horizon so older cursors fail closed.
|
|
258
|
+
*/
|
|
259
|
+
pruneChanges(input?: {
|
|
260
|
+
changeRetentionDays?: number;
|
|
261
|
+
maxFeedHoldDays?: number;
|
|
262
|
+
limit?: number;
|
|
263
|
+
}): Promise<{
|
|
264
|
+
deleted: number;
|
|
265
|
+
}>;
|
|
266
|
+
/**
|
|
267
|
+
* Retire whole reporting periods whose retention has elapsed (shared SDK
|
|
268
|
+
* persistence spec §4). A period is eligible once both its end and its
|
|
269
|
+
* latest publication are older than `max(statusRetentionDays,
|
|
270
|
+
* recordRetentionDays)`, no worker holds its lease, and no Managed Delivery
|
|
271
|
+
* materialization still references it. Retirement is period-aligned and
|
|
272
|
+
* resumable:
|
|
273
|
+
*
|
|
274
|
+
* 1. under the account lock, record a `retiring` tombstone and mark the
|
|
275
|
+
* period's row sets `pruning`, so exact reads answer as expired;
|
|
276
|
+
* 2. delete the period's external row objects at their recorded versions;
|
|
277
|
+
* 3. under the account lock, delete the period's ledger records (rows,
|
|
278
|
+
* revisions, adjustments, consumer statuses, issues, transitions,
|
|
279
|
+
* lifecycle state, obligation) and mark the tombstone `retired`.
|
|
280
|
+
*
|
|
281
|
+
* Planners skip retired periods, and `ledger_retained_from` advances past
|
|
282
|
+
* them because their obligations no longer exist.
|
|
283
|
+
*/
|
|
284
|
+
retireExpiredPeriods(input: {
|
|
285
|
+
statusRetentionDays: number;
|
|
286
|
+
recordRetentionDays?: number;
|
|
287
|
+
limit?: number;
|
|
288
|
+
account_id?: string;
|
|
289
|
+
signal?: AbortSignal;
|
|
290
|
+
}): Promise<{
|
|
291
|
+
retired: number;
|
|
292
|
+
failed: string[];
|
|
293
|
+
/** Secret-free cause per failed period: a row-store code or the error class name. */
|
|
294
|
+
failures: {
|
|
295
|
+
reporting_obligation_id: string;
|
|
296
|
+
cause: string;
|
|
297
|
+
}[];
|
|
298
|
+
}>;
|
|
299
|
+
private retirePeriod;
|
|
300
|
+
/**
|
|
301
|
+
* Resolve abandoned object uploads (spec §4.3). An expired `open` write
|
|
302
|
+
* intent whose ledger commit never happened is moved to `sweeping` under
|
|
303
|
+
* the account lock, so no writer can commit against it, then only the
|
|
304
|
+
* objects that upload created — never adopted ones, never any object a
|
|
305
|
+
* committed chunk references — are deleted at their recorded versions.
|
|
306
|
+
* Interrupted sweeps resume.
|
|
307
|
+
*/
|
|
308
|
+
sweepRowWriteIntents(input?: {
|
|
309
|
+
limit?: number;
|
|
310
|
+
account_id?: string;
|
|
311
|
+
signal?: AbortSignal;
|
|
312
|
+
}): Promise<{
|
|
313
|
+
swept: number;
|
|
314
|
+
objectsDeleted: number;
|
|
315
|
+
failed: number;
|
|
316
|
+
}>;
|
|
317
|
+
private optionalTables;
|
|
318
|
+
/**
|
|
319
|
+
* Upload an object-kind row set before its ledger commit (spec §3.5):
|
|
320
|
+
* skip when the document already exists (replay), refuse unless the lease
|
|
321
|
+
* still covers the upload deadline, open or take over an expired write
|
|
322
|
+
* intent under the account lock, then write every chunk create-only,
|
|
323
|
+
* recording each object this upload created in the intent first.
|
|
324
|
+
*/
|
|
325
|
+
private uploadRowSetUnlessCommitted;
|
|
326
|
+
/** Persist a prepared row set and close its upload intent in the ledger commit transaction. */
|
|
327
|
+
private writePreparedRowSet;
|
|
328
|
+
/** Attach verified rows to a revision document whose rows live in row storage. */
|
|
329
|
+
private hydrateRevision;
|
|
330
|
+
listAdjustmentMetadata(obligationId: string): Promise<ReportingLedgerAdjustmentMetadataV1[]>;
|
|
153
331
|
putConsumerStatus(status: ReportingLedgerConsumerStatusV1): Promise<{
|
|
154
332
|
inserted: boolean;
|
|
155
333
|
value: ReportingLedgerConsumerStatusV1;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { REPORTING_LEDGER_AUTHORITY } from './types';
|
|
2
|
-
import type { ReportingLedgerConfigurationV1, ReportingLedgerAdjustmentV1, ReportingLedgerConsumerStatusV1, ReportingLedgerIssueV1, ReportingLedgerLeaseV1, ReportingLedgerObligationV1, ReportingLedgerPageV1, ReportingLedgerRevisionV1, ReportingLedgerSnapshotQueryV1, ReportingLedgerSnapshotV1, ReportingLedgerStatusTransitionV1, ReportingLedgerNotificationActivityPortV1, ReportingLedgerTransactionV1, ReportingObservedFinalityV1, ReportingLedgerStore, ReportingConsumerStatusBatchInputV1, ReportingConsumerStatusBatchResultV1, ReportingConsumerStatusReplayInputV1, ReportingLedgerRevisionMetadataV1, ReportingManagedLifecycleProjectionV1, ReportingLedgerAuthorityV1 } from './types';
|
|
2
|
+
import type { ReportingLedgerConfigurationV1, ReportingLedgerAdjustmentMetadataV1, ReportingLedgerAdjustmentV1, ReportingLedgerConsumerStatusV1, ReportingLedgerIssueV1, ReportingLedgerLeaseV1, ReportingLedgerObligationV1, ReportingLedgerPageV1, ReportingLedgerRevisionV1, ReportingLedgerSnapshotQueryV1, ReportingLedgerSnapshotV1, ReportingLedgerStatusTransitionV1, ReportingLedgerNotificationActivityPortV1, ReportingLedgerTransactionV1, ReportingObservedFinalityV1, ReportingLedgerStore, ReportingConsumerStatusBatchInputV1, ReportingConsumerStatusBatchResultV1, ReportingConsumerStatusReplayInputV1, ReportingLedgerRevisionMetadataV1, ReportingRevisionRowsPageV1, ReportingRevisionRowsReadV1, ReportingManagedLifecycleProjectionV1, ReportingLedgerAuthorityV1 } from './types';
|
|
3
3
|
import type { ReportingConsumerMismatchEscalationV1 } from './types';
|
|
4
|
+
import { type ReportingChangeKindV1, type ReportingChangesPageV1 } from './change-feed';
|
|
5
|
+
import { type ReportingRowStorageOptionsV1 } from './row-storage';
|
|
4
6
|
type QueryResultRow = Record<string, unknown>;
|
|
5
7
|
interface ReportingPgResult<Row extends QueryResultRow> {
|
|
6
8
|
rows: Row[];
|
|
@@ -86,10 +88,28 @@ export interface PostgresReportingLedgerStoreOptions {
|
|
|
86
88
|
* lifecycle transaction. Its tables must be migrated before transitions run.
|
|
87
89
|
*/
|
|
88
90
|
notificationActivityPort?: ReportingLedgerNotificationActivityPortV1<ReportingLedgerTransactionV1>;
|
|
91
|
+
/**
|
|
92
|
+
* Store new revision and adjustment rows as verified canonical JSONL chunks
|
|
93
|
+
* (see `REPORTING_ROW_STORAGE_MIGRATION`) instead of inline in the ledger
|
|
94
|
+
* document. `true` uses a single `postgres` binding. Revisions written
|
|
95
|
+
* before enabling this keep their inline rows; reads handle both forms
|
|
96
|
+
* whether or not this option is set.
|
|
97
|
+
*/
|
|
98
|
+
rowStorage?: boolean | ReportingRowStorageOptionsV1;
|
|
99
|
+
/**
|
|
100
|
+
* Append obligation, revision, adjustment and retirement changes to the
|
|
101
|
+
* host change feed (`REPORTING_LEDGER_CHANGES_MIGRATION`, PostgreSQL 13+) in
|
|
102
|
+
* the same transaction as each record. Required for `changesAfter`.
|
|
103
|
+
*/
|
|
104
|
+
changeFeed?: boolean;
|
|
89
105
|
}
|
|
90
106
|
export declare class ReportingLedgerLeaseLostError extends Error {
|
|
91
107
|
constructor(message?: string);
|
|
92
108
|
}
|
|
109
|
+
/** A planner or writer named a period whose ledger records were retired by retention. */
|
|
110
|
+
export declare class ReportingLedgerPeriodRetiredError extends Error {
|
|
111
|
+
constructor(message?: string);
|
|
112
|
+
}
|
|
93
113
|
export declare class ReportingLedgerContinuityError extends Error {
|
|
94
114
|
constructor(message?: string);
|
|
95
115
|
}
|
|
@@ -113,7 +133,36 @@ export declare class PostgresReportingLedgerStore implements ReportingLedgerStor
|
|
|
113
133
|
private readonly obligatedConsumers;
|
|
114
134
|
readonly transactionalNotificationActivity: boolean;
|
|
115
135
|
private readonly notificationActivityPort?;
|
|
136
|
+
private readonly rowStorage;
|
|
137
|
+
private readonly rowStorageWrites;
|
|
138
|
+
private readonly changeFeed;
|
|
116
139
|
constructor(pool: ReportingPgPool, options?: PostgresReportingLedgerStoreOptions);
|
|
140
|
+
/** Append one host change-feed row inside the caller's account-locked transaction. */
|
|
141
|
+
private appendChange;
|
|
142
|
+
/** Probe and register row storage when enabled. Safe to call repeatedly. */
|
|
143
|
+
readyRowStorage(): Promise<void>;
|
|
144
|
+
/**
|
|
145
|
+
* Move legacy inline revision and adjustment rows into row storage, a
|
|
146
|
+
* bounded batch at a time. Each row set is re-encoded, proven to reproduce
|
|
147
|
+
* its committed binding, written, and only then removed from the ledger
|
|
148
|
+
* document, in one transaction under the account lock. A document whose
|
|
149
|
+
* rows do not reproduce its binding is never rewritten: it is reported in
|
|
150
|
+
* `quarantined` and left inline. Pass the returned `cursor` back to resume
|
|
151
|
+
* after the last examined document; it is absent once every candidate has
|
|
152
|
+
* been examined. Reclaiming the freed space needs `VACUUM FULL` or an online
|
|
153
|
+
* repack.
|
|
154
|
+
*/
|
|
155
|
+
migrateInlineRows(input?: {
|
|
156
|
+
limit?: number;
|
|
157
|
+
account_id?: string;
|
|
158
|
+
cursor?: string;
|
|
159
|
+
bindingId?: string;
|
|
160
|
+
signal?: AbortSignal;
|
|
161
|
+
}): Promise<{
|
|
162
|
+
migrated: number;
|
|
163
|
+
quarantined: string[];
|
|
164
|
+
cursor?: string;
|
|
165
|
+
}>;
|
|
117
166
|
putConfiguration(configuration: ReportingLedgerConfigurationV1): Promise<{
|
|
118
167
|
inserted: boolean;
|
|
119
168
|
value: ReportingLedgerConfigurationV1;
|
|
@@ -124,6 +173,11 @@ export declare class PostgresReportingLedgerStore implements ReportingLedgerStor
|
|
|
124
173
|
value: ReportingLedgerObligationV1;
|
|
125
174
|
}>;
|
|
126
175
|
getObligation(id: string, account_id?: string): Promise<ReportingLedgerObligationV1 | null>;
|
|
176
|
+
/** Periods retired by retention; planners treat them as already covered. */
|
|
177
|
+
listRetiredObligationOrdinals(account_id?: string): Promise<{
|
|
178
|
+
configurationId: string;
|
|
179
|
+
periodOrdinal: number;
|
|
180
|
+
}[]>;
|
|
127
181
|
listObligations(account_id?: string): Promise<ReportingLedgerObligationV1[]>;
|
|
128
182
|
listLifecycleDueObligations(input: {
|
|
129
183
|
ledgerAsOf: string;
|
|
@@ -144,12 +198,136 @@ export declare class PostgresReportingLedgerStore implements ReportingLedgerStor
|
|
|
144
198
|
}>;
|
|
145
199
|
getRevision(id: string, accountId: string): Promise<ReportingLedgerRevisionV1 | null>;
|
|
146
200
|
getRevisionMetadata(id: string, accountId: string): Promise<ReportingLedgerRevisionMetadataV1 | null>;
|
|
201
|
+
readRevisionRows(input: ReportingRevisionRowsReadV1): Promise<ReportingRevisionRowsPageV1 | null>;
|
|
147
202
|
listRevisions(obligationId: string): Promise<ReportingLedgerRevisionV1[]>;
|
|
203
|
+
listRevisionMetadata(obligationId: string, accountId?: string): Promise<ReportingLedgerRevisionMetadataV1[]>;
|
|
148
204
|
commitAdjustment(adjustment: ReportingLedgerAdjustmentV1, lease: ReportingLedgerLeaseV1): Promise<{
|
|
149
205
|
inserted: boolean;
|
|
150
206
|
value: ReportingLedgerAdjustmentV1;
|
|
151
207
|
}>;
|
|
152
208
|
listAdjustments(obligationId: string): Promise<ReportingLedgerAdjustmentV1[]>;
|
|
209
|
+
/**
|
|
210
|
+
* The obligation's current revision header: its official revision if one
|
|
211
|
+
* exists, otherwise its highest-numbered snapshot. An official revision is
|
|
212
|
+
* terminal, so this is always the highest revision number — one index
|
|
213
|
+
* lookup. Rows are read separately through `readRevisionRows`.
|
|
214
|
+
*/
|
|
215
|
+
getCurrentRevision(input: {
|
|
216
|
+
account_id: string;
|
|
217
|
+
reporting_obligation_id: string;
|
|
218
|
+
}): Promise<ReportingLedgerRevisionMetadataV1 | null>;
|
|
219
|
+
/**
|
|
220
|
+
* Current revision headers for an account's obligations whose period starts
|
|
221
|
+
* in `[period_start_from, period_start_to)`, ordered by period start.
|
|
222
|
+
* Obligations without a revision yet are omitted. Page with `cursor`.
|
|
223
|
+
*/
|
|
224
|
+
listCurrentRevisions(input: {
|
|
225
|
+
account_id: string;
|
|
226
|
+
period_start_from: string;
|
|
227
|
+
period_start_to: string;
|
|
228
|
+
delivery_config_id?: string;
|
|
229
|
+
limit?: number;
|
|
230
|
+
cursor?: string;
|
|
231
|
+
}): Promise<{
|
|
232
|
+
revisions: ReportingLedgerRevisionMetadataV1[];
|
|
233
|
+
cursor?: string;
|
|
234
|
+
}>;
|
|
235
|
+
/**
|
|
236
|
+
* Host change feed. Omit `cursor` to start from the oldest retained change.
|
|
237
|
+
* Account-scoped feeds order by sequence; the deployment-wide feed orders by
|
|
238
|
+
* `(xid, seq)` and returns only changes whose transaction precedes every
|
|
239
|
+
* transaction still in flight, so no commit is ever skipped. A cursor older
|
|
240
|
+
* than the retained history throws `ReportingChangeCursorExpiredError`;
|
|
241
|
+
* resynchronize from `listCurrentRevisions`.
|
|
242
|
+
*/
|
|
243
|
+
changesAfter(input?: {
|
|
244
|
+
cursor?: string;
|
|
245
|
+
account_id?: string;
|
|
246
|
+
kinds?: readonly ReportingChangeKindV1[];
|
|
247
|
+
limit?: number;
|
|
248
|
+
}): Promise<ReportingChangesPageV1>;
|
|
249
|
+
/**
|
|
250
|
+
* Record a named durable consumer's position. Registered consumers hold
|
|
251
|
+
* back change-table pruning until `maxFeedHoldDays` after their last update.
|
|
252
|
+
*/
|
|
253
|
+
saveFeedConsumerCursor(name: string, cursor: string): Promise<void>;
|
|
254
|
+
/**
|
|
255
|
+
* Delete change rows older than `changeRetentionDays` that every consumer
|
|
256
|
+
* updated within `maxFeedHoldDays` has passed, and advance the expiry
|
|
257
|
+
* horizon so older cursors fail closed.
|
|
258
|
+
*/
|
|
259
|
+
pruneChanges(input?: {
|
|
260
|
+
changeRetentionDays?: number;
|
|
261
|
+
maxFeedHoldDays?: number;
|
|
262
|
+
limit?: number;
|
|
263
|
+
}): Promise<{
|
|
264
|
+
deleted: number;
|
|
265
|
+
}>;
|
|
266
|
+
/**
|
|
267
|
+
* Retire whole reporting periods whose retention has elapsed (shared SDK
|
|
268
|
+
* persistence spec §4). A period is eligible once both its end and its
|
|
269
|
+
* latest publication are older than `max(statusRetentionDays,
|
|
270
|
+
* recordRetentionDays)`, no worker holds its lease, and no Managed Delivery
|
|
271
|
+
* materialization still references it. Retirement is period-aligned and
|
|
272
|
+
* resumable:
|
|
273
|
+
*
|
|
274
|
+
* 1. under the account lock, record a `retiring` tombstone and mark the
|
|
275
|
+
* period's row sets `pruning`, so exact reads answer as expired;
|
|
276
|
+
* 2. delete the period's external row objects at their recorded versions;
|
|
277
|
+
* 3. under the account lock, delete the period's ledger records (rows,
|
|
278
|
+
* revisions, adjustments, consumer statuses, issues, transitions,
|
|
279
|
+
* lifecycle state, obligation) and mark the tombstone `retired`.
|
|
280
|
+
*
|
|
281
|
+
* Planners skip retired periods, and `ledger_retained_from` advances past
|
|
282
|
+
* them because their obligations no longer exist.
|
|
283
|
+
*/
|
|
284
|
+
retireExpiredPeriods(input: {
|
|
285
|
+
statusRetentionDays: number;
|
|
286
|
+
recordRetentionDays?: number;
|
|
287
|
+
limit?: number;
|
|
288
|
+
account_id?: string;
|
|
289
|
+
signal?: AbortSignal;
|
|
290
|
+
}): Promise<{
|
|
291
|
+
retired: number;
|
|
292
|
+
failed: string[];
|
|
293
|
+
/** Secret-free cause per failed period: a row-store code or the error class name. */
|
|
294
|
+
failures: {
|
|
295
|
+
reporting_obligation_id: string;
|
|
296
|
+
cause: string;
|
|
297
|
+
}[];
|
|
298
|
+
}>;
|
|
299
|
+
private retirePeriod;
|
|
300
|
+
/**
|
|
301
|
+
* Resolve abandoned object uploads (spec §4.3). An expired `open` write
|
|
302
|
+
* intent whose ledger commit never happened is moved to `sweeping` under
|
|
303
|
+
* the account lock, so no writer can commit against it, then only the
|
|
304
|
+
* objects that upload created — never adopted ones, never any object a
|
|
305
|
+
* committed chunk references — are deleted at their recorded versions.
|
|
306
|
+
* Interrupted sweeps resume.
|
|
307
|
+
*/
|
|
308
|
+
sweepRowWriteIntents(input?: {
|
|
309
|
+
limit?: number;
|
|
310
|
+
account_id?: string;
|
|
311
|
+
signal?: AbortSignal;
|
|
312
|
+
}): Promise<{
|
|
313
|
+
swept: number;
|
|
314
|
+
objectsDeleted: number;
|
|
315
|
+
failed: number;
|
|
316
|
+
}>;
|
|
317
|
+
private optionalTables;
|
|
318
|
+
/**
|
|
319
|
+
* Upload an object-kind row set before its ledger commit (spec §3.5):
|
|
320
|
+
* skip when the document already exists (replay), refuse unless the lease
|
|
321
|
+
* still covers the upload deadline, open or take over an expired write
|
|
322
|
+
* intent under the account lock, then write every chunk create-only,
|
|
323
|
+
* recording each object this upload created in the intent first.
|
|
324
|
+
*/
|
|
325
|
+
private uploadRowSetUnlessCommitted;
|
|
326
|
+
/** Persist a prepared row set and close its upload intent in the ledger commit transaction. */
|
|
327
|
+
private writePreparedRowSet;
|
|
328
|
+
/** Attach verified rows to a revision document whose rows live in row storage. */
|
|
329
|
+
private hydrateRevision;
|
|
330
|
+
listAdjustmentMetadata(obligationId: string): Promise<ReportingLedgerAdjustmentMetadataV1[]>;
|
|
153
331
|
putConsumerStatus(status: ReportingLedgerConsumerStatusV1): Promise<{
|
|
154
332
|
inserted: boolean;
|
|
155
333
|
value: ReportingLedgerConsumerStatusV1;
|