@adcp/sdk 16.0.0-beta.2 → 16.0.0-beta.4
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/README.md +54 -0
- package/dist/lib/auth/oauth/diagnose.js +3 -11
- package/dist/lib/auth/oauth/diagnose.mjs +4 -12
- package/dist/lib/auth/oauth/diagnostics.d.mts +2 -1
- package/dist/lib/auth/oauth/diagnostics.d.ts +2 -1
- package/dist/lib/auth/oauth/diagnostics.js +8 -10
- package/dist/lib/auth/oauth/diagnostics.mjs +7 -10
- package/dist/lib/core/ConversationTypes.d.mts +8 -3
- package/dist/lib/core/ConversationTypes.d.ts +8 -3
- package/dist/lib/core/SingleAgentClient.d.mts +5 -3
- package/dist/lib/core/SingleAgentClient.d.ts +5 -3
- package/dist/lib/core/TaskExecutor.js +5 -1
- package/dist/lib/core/TaskExecutor.mjs +5 -1
- package/dist/lib/errors/index.d.mts +9 -4
- package/dist/lib/errors/index.d.ts +9 -4
- package/dist/lib/index.d.mts +3 -3
- package/dist/lib/index.d.ts +3 -3
- package/dist/lib/index.js +8 -0
- package/dist/lib/index.mjs +14 -2
- package/dist/lib/negotiation/types.d.mts +20 -39
- package/dist/lib/negotiation/types.d.ts +20 -39
- package/dist/lib/protocols/index.d.mts +60 -24
- package/dist/lib/protocols/index.d.ts +60 -24
- package/dist/lib/protocols/index.js +9 -4
- package/dist/lib/protocols/index.mjs +3 -0
- package/dist/lib/protocols/mcp-modern.js +1 -0
- package/dist/lib/protocols/mcp-modern.mjs +2 -1
- package/dist/lib/protocols/mcp.js +1 -0
- package/dist/lib/protocols/mcp.mjs +2 -1
- package/dist/lib/protocols/responseSizeLimit.d.mts +91 -5
- package/dist/lib/protocols/responseSizeLimit.d.ts +91 -5
- package/dist/lib/protocols/responseSizeLimit.js +195 -31
- package/dist/lib/protocols/responseSizeLimit.mjs +192 -31
- package/dist/lib/reporting/consumer-runtime.js +2 -1
- package/dist/lib/reporting/consumer-runtime.mjs +2 -1
- package/dist/lib/reporting/ledger/handler.js +50 -11
- package/dist/lib/reporting/ledger/handler.mjs +50 -12
- package/dist/lib/reporting/ledger/index.d.mts +17 -14
- package/dist/lib/reporting/ledger/index.d.ts +17 -14
- package/dist/lib/reporting/ledger/index.js +32 -20
- package/dist/lib/reporting/ledger/index.mjs +21 -10
- package/dist/lib/reporting/ledger/offering-validation.d.mts +9 -0
- package/dist/lib/reporting/ledger/offering-validation.d.ts +9 -0
- package/dist/lib/reporting/{gcs/bucket-policy.js → ledger/offering-validation.js} +9 -8
- package/dist/lib/reporting/ledger/offering-validation.mjs +8 -0
- package/dist/lib/reporting/ledger/receipts.d.mts +48 -0
- package/dist/lib/reporting/ledger/receipts.d.ts +48 -0
- package/dist/lib/reporting/ledger/receipts.js +186 -0
- package/dist/lib/reporting/ledger/receipts.mjs +161 -0
- package/dist/lib/reporting/ledger/status-ingest.js +3 -3
- package/dist/lib/reporting/ledger/status-ingest.mjs +4 -5
- package/dist/lib/reporting/ledger/types.d.mts +43 -0
- package/dist/lib/reporting/ledger/types.d.ts +43 -0
- package/dist/lib/reporting/ledger/types.js +31 -2
- package/dist/lib/reporting/ledger/types.mjs +26 -1
- package/dist/lib/reporting/pagination.d.mts +6 -0
- package/dist/lib/reporting/pagination.d.ts +6 -0
- package/dist/lib/reporting/{gcs/errors.js → pagination.js} +12 -17
- package/dist/lib/reporting/pagination.mjs +12 -0
- package/dist/lib/reporting/reconciliation.d.mts +1 -0
- package/dist/lib/reporting/reconciliation.d.ts +1 -0
- package/dist/lib/reporting/reconciliation.js +3 -2
- package/dist/lib/reporting/reconciliation.mjs +3 -2
- package/dist/lib/reporting/service/index.d.mts +79 -153
- package/dist/lib/reporting/service/index.d.ts +79 -153
- package/dist/lib/reporting/service/index.js +34 -491
- package/dist/lib/reporting/service/index.mjs +36 -510
- package/dist/lib/reporting/service/scheduler-support.d.mts +43 -0
- package/dist/lib/reporting/service/scheduler-support.d.ts +43 -0
- package/dist/lib/reporting/service/scheduler-support.js +125 -0
- package/dist/lib/reporting/service/scheduler-support.mjs +96 -0
- package/dist/lib/schemas-data/v2.5/_provenance.json +1 -1
- package/dist/lib/signing/canonicalize.d.mts +4 -0
- package/dist/lib/signing/canonicalize.d.ts +4 -0
- package/dist/lib/signing/canonicalize.js +14 -8
- package/dist/lib/signing/canonicalize.mjs +14 -8
- package/dist/lib/signing/content-digest.d.mts +8 -0
- package/dist/lib/signing/content-digest.d.ts +8 -0
- package/dist/lib/signing/content-digest.js +11 -5
- package/dist/lib/signing/content-digest.mjs +10 -5
- package/dist/lib/signing/crypto.d.mts +15 -0
- package/dist/lib/signing/crypto.d.ts +15 -0
- package/dist/lib/signing/crypto.js +75 -3
- package/dist/lib/signing/crypto.mjs +78 -3
- package/dist/lib/signing/server.d.mts +1 -1
- package/dist/lib/signing/server.d.ts +1 -1
- package/dist/lib/signing/server.js +2 -0
- package/dist/lib/signing/server.mjs +2 -1
- package/dist/lib/signing/signer.js +11 -14
- package/dist/lib/signing/signer.mjs +13 -16
- package/dist/lib/signing/testing.js +2 -6
- package/dist/lib/signing/testing.mjs +3 -7
- package/dist/lib/signing/verifier.js +2 -2
- package/dist/lib/signing/verifier.mjs +3 -3
- package/dist/lib/signing/web-bot-auth.js +122 -43
- package/dist/lib/signing/web-bot-auth.mjs +128 -44
- package/dist/lib/signing/webhook-verifier.js +2 -2
- package/dist/lib/signing/webhook-verifier.mjs +3 -3
- package/dist/lib/substitution/compile.js +2 -1
- package/dist/lib/substitution/compile.mjs +2 -1
- package/dist/lib/substitution/consent-macros.d.mts +4 -0
- package/dist/lib/substitution/consent-macros.d.ts +4 -0
- package/dist/lib/substitution/consent-macros.js +45 -0
- package/dist/lib/substitution/consent-macros.mjs +20 -0
- package/dist/lib/substitution/index.d.mts +1 -1
- package/dist/lib/substitution/index.d.ts +1 -1
- package/dist/lib/substitution/index.js +2 -0
- package/dist/lib/substitution/index.mjs +2 -1
- package/dist/lib/substitution/translate.d.mts +15 -2
- package/dist/lib/substitution/translate.d.ts +15 -2
- package/dist/lib/substitution/translate.js +148 -26
- package/dist/lib/substitution/translate.mjs +147 -26
- package/dist/lib/testing/client.js +2 -1
- package/dist/lib/testing/client.mjs +2 -1
- package/dist/lib/testing/scenarios/capabilities.js +1 -1
- package/dist/lib/testing/scenarios/capabilities.mjs +1 -1
- package/dist/lib/testing/storyboard/junit.js +16 -3
- package/dist/lib/testing/storyboard/junit.mjs +16 -3
- package/dist/lib/testing/storyboard/request-signing/builder.js +12 -14
- package/dist/lib/testing/storyboard/request-signing/builder.mjs +13 -15
- package/dist/lib/testing/storyboard/runner.js +94 -25
- package/dist/lib/testing/storyboard/runner.mjs +94 -25
- package/dist/lib/testing/storyboard/signer-grader/grader.js +2 -7
- package/dist/lib/testing/storyboard/signer-grader/grader.mjs +2 -7
- package/dist/lib/testing/storyboard/types.d.mts +6 -0
- package/dist/lib/testing/storyboard/types.d.ts +6 -0
- package/dist/lib/testing/storyboard/validations.d.mts +1 -1
- package/dist/lib/testing/storyboard/validations.d.ts +1 -1
- package/dist/lib/types/enums.generated.d.mts +3 -0
- package/dist/lib/types/enums.generated.d.ts +3 -0
- package/dist/lib/types/enums.generated.js +9 -0
- package/dist/lib/types/enums.generated.mjs +6 -0
- package/dist/lib/validation/schema-loader.js +25 -0
- package/dist/lib/validation/schema-loader.mjs +24 -0
- 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 +28 -5
- package/docs/guides/DISCOVERY-CACHE-AND-SESSION-REUSE.md +3 -2
- package/docs/guides/REPORTING-GCS-FENCE.md +3 -3
- package/docs/guides/REPORTING-GCS-MANAGED.md +4 -4
- package/docs/guides/REPORTING-LEDGER-CUTOVER.md +7 -7
- package/docs/guides/REPORTING-LEDGER.md +107 -51
- package/docs/guides/REPORTING-OPERATIONS.md +66 -5
- package/docs/guides/REPORTING-STABILITY.md +36 -32
- package/docs/guides/UNIVERSAL-MACRO-COMPILATION.md +38 -0
- package/docs/guides/VALIDATE-YOUR-AGENT.md +12 -0
- package/docs/llms.txt +4 -3
- package/docs/migration-14.x-rc-worksheet.md +4 -7
- package/docs/migration-reporting-storage-package.md +186 -0
- package/examples/README.md +1 -1
- package/package.json +14 -78
- package/dist/lib/reporting/azure/index.d.mts +0 -31
- package/dist/lib/reporting/azure/index.d.ts +0 -31
- package/dist/lib/reporting/azure/index.js +0 -266
- package/dist/lib/reporting/azure/index.mjs +0 -249
- package/dist/lib/reporting/bigquery/index.d.mts +0 -246
- package/dist/lib/reporting/bigquery/index.d.ts +0 -246
- package/dist/lib/reporting/bigquery/index.js +0 -633
- package/dist/lib/reporting/bigquery/index.mjs +0 -594
- package/dist/lib/reporting/gcs/adapter.d.mts +0 -38
- package/dist/lib/reporting/gcs/adapter.d.ts +0 -38
- package/dist/lib/reporting/gcs/adapter.js +0 -342
- package/dist/lib/reporting/gcs/adapter.mjs +0 -325
- package/dist/lib/reporting/gcs/bucket-policy.d.mts +0 -3
- package/dist/lib/reporting/gcs/bucket-policy.d.ts +0 -3
- package/dist/lib/reporting/gcs/bucket-policy.mjs +0 -7
- package/dist/lib/reporting/gcs/errors.d.mts +0 -11
- package/dist/lib/reporting/gcs/errors.d.ts +0 -11
- package/dist/lib/reporting/gcs/errors.mjs +0 -16
- package/dist/lib/reporting/gcs/fence.d.mts +0 -41
- package/dist/lib/reporting/gcs/fence.d.ts +0 -41
- package/dist/lib/reporting/gcs/fence.js +0 -250
- package/dist/lib/reporting/gcs/fence.mjs +0 -230
- package/dist/lib/reporting/gcs/index.d.mts +0 -18
- package/dist/lib/reporting/gcs/index.d.ts +0 -18
- package/dist/lib/reporting/gcs/index.js +0 -44
- package/dist/lib/reporting/gcs/index.mjs +0 -14
- package/dist/lib/reporting/gcs/io.d.mts +0 -7
- package/dist/lib/reporting/gcs/io.d.ts +0 -7
- package/dist/lib/reporting/gcs/io.js +0 -95
- package/dist/lib/reporting/gcs/io.mjs +0 -69
- package/dist/lib/reporting/gcs/reader.d.mts +0 -67
- package/dist/lib/reporting/gcs/reader.d.ts +0 -67
- package/dist/lib/reporting/gcs/reader.js +0 -193
- package/dist/lib/reporting/gcs/reader.mjs +0 -169
- package/dist/lib/reporting/gcs/row-provider.d.mts +0 -39
- package/dist/lib/reporting/gcs/row-provider.d.ts +0 -39
- package/dist/lib/reporting/gcs/row-provider.js +0 -225
- package/dist/lib/reporting/gcs/row-provider.mjs +0 -208
- package/dist/lib/reporting/gcs/validation.d.mts +0 -5
- package/dist/lib/reporting/gcs/validation.d.ts +0 -5
- package/dist/lib/reporting/gcs/validation.js +0 -49
- package/dist/lib/reporting/gcs/validation.mjs +0 -25
- package/dist/lib/reporting/ledger/change-feed.d.mts +0 -69
- package/dist/lib/reporting/ledger/change-feed.d.ts +0 -69
- package/dist/lib/reporting/ledger/change-feed.js +0 -107
- package/dist/lib/reporting/ledger/change-feed.mjs +0 -80
- package/dist/lib/reporting/ledger/managed-postgres.d.mts +0 -293
- package/dist/lib/reporting/ledger/managed-postgres.d.ts +0 -293
- package/dist/lib/reporting/ledger/managed-postgres.js +0 -2346
- package/dist/lib/reporting/ledger/managed-postgres.mjs +0 -2332
- package/dist/lib/reporting/ledger/managed-router.d.mts +0 -148
- package/dist/lib/reporting/ledger/managed-router.d.ts +0 -148
- package/dist/lib/reporting/ledger/managed-router.js +0 -280
- package/dist/lib/reporting/ledger/managed-router.mjs +0 -258
- package/dist/lib/reporting/ledger/managed.d.mts +0 -535
- package/dist/lib/reporting/ledger/managed.d.ts +0 -535
- package/dist/lib/reporting/ledger/managed.js +0 -761
- package/dist/lib/reporting/ledger/managed.mjs +0 -729
- package/dist/lib/reporting/ledger/notification-activity.d.mts +0 -332
- package/dist/lib/reporting/ledger/notification-activity.d.ts +0 -332
- package/dist/lib/reporting/ledger/notification-activity.js +0 -1366
- package/dist/lib/reporting/ledger/notification-activity.mjs +0 -1337
- package/dist/lib/reporting/ledger/object-writes.d.mts +0 -128
- package/dist/lib/reporting/ledger/object-writes.d.ts +0 -128
- package/dist/lib/reporting/ledger/object-writes.js +0 -147
- package/dist/lib/reporting/ledger/object-writes.mjs +0 -114
- package/dist/lib/reporting/ledger/postgres.d.mts +0 -689
- package/dist/lib/reporting/ledger/postgres.d.ts +0 -689
- package/dist/lib/reporting/ledger/postgres.js +0 -4462
- package/dist/lib/reporting/ledger/postgres.mjs +0 -4462
- package/dist/lib/reporting/ledger/row-storage-migration.d.mts +0 -59
- package/dist/lib/reporting/ledger/row-storage-migration.d.ts +0 -59
- package/dist/lib/reporting/ledger/row-storage-migration.js +0 -365
- package/dist/lib/reporting/ledger/row-storage-migration.mjs +0 -339
- package/dist/lib/reporting/ledger/row-storage-object.d.mts +0 -203
- package/dist/lib/reporting/ledger/row-storage-object.d.ts +0 -203
- package/dist/lib/reporting/ledger/row-storage-object.js +0 -379
- package/dist/lib/reporting/ledger/row-storage-object.mjs +0 -335
- package/dist/lib/reporting/ledger/row-storage-provider-io.d.mts +0 -44
- package/dist/lib/reporting/ledger/row-storage-provider-io.d.ts +0 -44
- package/dist/lib/reporting/ledger/row-storage-provider-io.js +0 -142
- package/dist/lib/reporting/ledger/row-storage-provider-io.mjs +0 -111
- package/dist/lib/reporting/ledger/row-storage.d.mts +0 -316
- package/dist/lib/reporting/ledger/row-storage.d.ts +0 -316
- package/dist/lib/reporting/ledger/row-storage.js +0 -812
- package/dist/lib/reporting/ledger/row-storage.mjs +0 -802
- package/dist/lib/reporting/s3/index.d.mts +0 -34
- package/dist/lib/reporting/s3/index.d.ts +0 -34
- package/dist/lib/reporting/s3/index.js +0 -347
- package/dist/lib/reporting/s3/index.mjs +0 -340
- package/dist/lib/reporting/service/maintenance.d.mts +0 -148
- package/dist/lib/reporting/service/maintenance.d.ts +0 -148
- package/dist/lib/reporting/service/maintenance.js +0 -185
- package/dist/lib/reporting/service/maintenance.mjs +0 -159
- package/examples/reliable-reporting-service/README.md +0 -169
|
@@ -19,28 +19,25 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
|
|
|
19
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
20
|
var service_exports = {};
|
|
21
21
|
__export(service_exports, {
|
|
22
|
-
|
|
23
|
-
createPostgresReliableReportingProductionService: () => createPostgresReliableReportingProductionService,
|
|
22
|
+
REPORTING_MANAGED_DELIVERY_COMPOSITION_V1: () => REPORTING_MANAGED_DELIVERY_COMPOSITION_V1,
|
|
24
23
|
createReliableReportingService: () => createReliableReportingService
|
|
25
24
|
});
|
|
26
25
|
module.exports = __toCommonJS(service_exports);
|
|
27
26
|
var import_credential_policy = require('../../server/credential-policy.js');
|
|
28
27
|
var import_jcs = require('../../utils/jcs.js');
|
|
29
|
-
var import_redact_credential_patterns = require('../../utils/redact-credential-patterns.js');
|
|
30
28
|
var import_schemas = require('../../types/schemas.generated.js');
|
|
31
|
-
var import_notification_subscriptions = require('../../server/notification-subscriptions/index.js');
|
|
32
29
|
var import_ledger = require('../ledger/index.js');
|
|
33
|
-
var
|
|
34
|
-
var import_maintenance = require('./maintenance.js');
|
|
30
|
+
var import_scheduler_support = require('./scheduler-support.js');
|
|
35
31
|
var import_schedule = require('../ledger/schedule.js');
|
|
36
32
|
var import_source = require('../source/index.js');
|
|
37
33
|
__reExport(service_exports, require('./conformance.js'), module.exports);
|
|
38
|
-
|
|
34
|
+
__reExport(service_exports, require('./scheduler-support.js'), module.exports);
|
|
39
35
|
const ADAPTER_SCOPE_KEY = "_adcp_reporting_adapter";
|
|
40
|
-
const
|
|
41
|
-
|
|
36
|
+
const REPORTING_MANAGED_DELIVERY_COMPOSITION_V1 = /* @__PURE__ */ Symbol.for(
|
|
37
|
+
"@adcp/sdk/reporting/managed-delivery-composition"
|
|
38
|
+
);
|
|
42
39
|
function createReliableReportingService(options) {
|
|
43
|
-
const allowManagedDelivery = options[
|
|
40
|
+
const allowManagedDelivery = options[REPORTING_MANAGED_DELIVERY_COMPOSITION_V1] === options.store;
|
|
44
41
|
const adapterEntries = Object.entries(options.adapters);
|
|
45
42
|
if (adapterEntries.length === 0) throw new TypeError("Reliable reporting requires at least one adapter");
|
|
46
43
|
positiveInteger(options.automatedRecoveryWindowSeconds, "automatedRecoveryWindowSeconds");
|
|
@@ -100,52 +97,25 @@ function createReliableReportingService(options) {
|
|
|
100
97
|
if (hasConsumerStatus) assertConsumerStatusStore(options.store);
|
|
101
98
|
const retentionDays = options.statusRetentionDays;
|
|
102
99
|
positiveInteger(retentionDays, "statusRetentionDays");
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
if (maintenance !== void 0) {
|
|
107
|
-
if (maintenance === null || typeof maintenance !== "object") {
|
|
108
|
-
throw new TypeError("maintenance must be an options object");
|
|
109
|
-
}
|
|
110
|
-
const candidate = options.store;
|
|
111
|
-
for (const method of [
|
|
112
|
-
"retireExpiredPeriods",
|
|
113
|
-
"pruneChanges",
|
|
114
|
-
"sweepRowWriteIntents",
|
|
115
|
-
...maintenance.compaction ? ["compactSupersededSnapshots"] : []
|
|
116
|
-
]) {
|
|
117
|
-
if (typeof candidate[method] !== "function") {
|
|
118
|
-
throw new TypeError(
|
|
119
|
-
`maintenance requires a PostgresReportingLedgerStore (or a store with ${method}); the configured store cannot run ledger maintenance`
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
maintenanceStore = candidate;
|
|
124
|
-
if (maintenance.compaction) {
|
|
125
|
-
candidate.assertCompactionSafeRowBindings?.();
|
|
126
|
-
}
|
|
127
|
-
if (maintenance.changeFeed && maintenanceStore.changeFeedEnabled === false) {
|
|
100
|
+
let maintenance;
|
|
101
|
+
if (options.maintenance !== void 0) {
|
|
102
|
+
if (typeof options.maintenance !== "function") {
|
|
128
103
|
throw new TypeError(
|
|
129
|
-
"maintenance.
|
|
104
|
+
"createReliableReportingService: `maintenance` must be a factory, not an options object. For a PostgreSQL ledger wrap your options with `reportingLedgerMaintenance({ ... })` from the `@adcp/reporting-storage` package, for example `maintenance: reportingLedgerMaintenance({ retention: { enabled: true } })`. See docs/migration-reporting-storage-package.md."
|
|
130
105
|
);
|
|
131
106
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
107
|
+
maintenance = options.maintenance({
|
|
108
|
+
store: options.store,
|
|
109
|
+
statusRetentionDays: retentionDays,
|
|
110
|
+
automatedRecoveryWindowSeconds: options.automatedRecoveryWindowSeconds
|
|
111
|
+
});
|
|
112
|
+
if (!maintenance || typeof maintenance.run !== "function" || !Number.isSafeInteger(maintenance.intervalMilliseconds) || maintenance.intervalMilliseconds <= 0) {
|
|
113
|
+
throw new TypeError(
|
|
114
|
+
"maintenance factory must return { intervalMilliseconds: positive integer, run(): Promise<results> }"
|
|
115
|
+
);
|
|
135
116
|
}
|
|
136
|
-
(0, import_maintenance.assertReportingLedgerMaintenanceOptions)(maintenance, retentionDays);
|
|
137
117
|
}
|
|
138
|
-
const runLedgerMaintenance = (signal, report) => (
|
|
139
|
-
store: maintenanceStore,
|
|
140
|
-
...typeof maintenanceStore.sweepExpiredState === "function" ? { sweepSnapshots: (limit) => maintenanceStore.sweepExpiredState(limit) } : {},
|
|
141
|
-
statusRetentionDays: retentionDays,
|
|
142
|
-
automatedRecoveryWindowSeconds: options.automatedRecoveryWindowSeconds,
|
|
143
|
-
retention: maintenance.retention,
|
|
144
|
-
compaction: maintenance.compaction,
|
|
145
|
-
changeFeed: maintenance.changeFeed,
|
|
146
|
-
signal,
|
|
147
|
-
...report ? { report } : {}
|
|
148
|
-
});
|
|
118
|
+
const runLedgerMaintenance = (signal, report) => maintenance.run({ signal, ...report ? { report } : {} });
|
|
149
119
|
const capabilities = deepFreeze({
|
|
150
120
|
supported: true,
|
|
151
121
|
reliable_reporting_version: "1.0",
|
|
@@ -186,7 +156,7 @@ function createReliableReportingService(options) {
|
|
|
186
156
|
const service = {
|
|
187
157
|
setup: Object.freeze({
|
|
188
158
|
component: "reliable-reporting-core",
|
|
189
|
-
migrations: Object.freeze([
|
|
159
|
+
migrations: Object.freeze([...options.store.migrations ?? []]),
|
|
190
160
|
requiresIsolatedLedgerDatabaseAcknowledgement: true
|
|
191
161
|
}),
|
|
192
162
|
capabilities,
|
|
@@ -334,10 +304,10 @@ function createReliableReportingService(options) {
|
|
|
334
304
|
schedulerAbort = new AbortController();
|
|
335
305
|
const signal = schedulerAbort.signal;
|
|
336
306
|
const scheduledMaintenance = maintenance === void 0 ? void 0 : {
|
|
337
|
-
intervalMilliseconds:
|
|
307
|
+
intervalMilliseconds: maintenance.intervalMilliseconds,
|
|
338
308
|
run: () => runLedgerMaintenance(
|
|
339
309
|
signal,
|
|
340
|
-
(error) =>
|
|
310
|
+
(error) => (0, import_scheduler_support.reportReportingSchedulerError)(scheduler, signal, error, { phase: "maintenance" })
|
|
341
311
|
)
|
|
342
312
|
};
|
|
343
313
|
schedulerPromise = schedulerLoop(service, scheduler, signal, options.store, scheduledMaintenance).finally(() => {
|
|
@@ -353,346 +323,6 @@ function createReliableReportingService(options) {
|
|
|
353
323
|
};
|
|
354
324
|
return service;
|
|
355
325
|
}
|
|
356
|
-
async function createPostgresReliableReportingProductionService(options) {
|
|
357
|
-
if (!options.db || typeof options.db.query !== "function" || typeof options.db.connect !== "function") {
|
|
358
|
-
throw new TypeError("Reliable Reporting production service requires a PostgreSQL pool");
|
|
359
|
-
}
|
|
360
|
-
if (!/^[A-Za-z0-9_.:-]{1,255}$/.test(options.namespace)) {
|
|
361
|
-
throw new TypeError("Reliable Reporting production namespace must be a bounded non-secret identifier");
|
|
362
|
-
}
|
|
363
|
-
if (!/^[A-Za-z0-9_.:-]{1,255}$/.test(options.publisherScope)) {
|
|
364
|
-
throw new TypeError("Reliable Reporting publisherScope must be a bounded non-secret identifier");
|
|
365
|
-
}
|
|
366
|
-
if (typeof options.resolveWebhookActivityScope !== "function") {
|
|
367
|
-
throw new TypeError("Reliable Reporting production service requires resolveWebhookActivityScope");
|
|
368
|
-
}
|
|
369
|
-
if (typeof options.activity?.tenantScopeForAccount !== "function") {
|
|
370
|
-
throw new TypeError("Reliable Reporting production service requires activity.tenantScopeForAccount");
|
|
371
|
-
}
|
|
372
|
-
(0, import_maintenance.assertReportingLedgerMaintenanceOptions)({ compaction: options.compaction }, options.statusRetentionDays);
|
|
373
|
-
if (Object.values(options.adapters).some(
|
|
374
|
-
(adapter) => adapter.deliveryOffering.reconciliation_mode === "consumer_receipt"
|
|
375
|
-
) && typeof options.obligatedConsumers !== "function") {
|
|
376
|
-
throw new TypeError("Reconciled Billing production offerings require a trusted obligatedConsumers roster");
|
|
377
|
-
}
|
|
378
|
-
const recipientCheckpoint = (0, import_ledger.createPostgresReportingNotificationAttemptCheckpoint)({
|
|
379
|
-
db: options.db,
|
|
380
|
-
namespace: options.namespace,
|
|
381
|
-
...options.activity?.tableName !== void 0 ? { tableName: options.activity.tableName } : {}
|
|
382
|
-
});
|
|
383
|
-
const webhookActivity = (0, import_webhook_activity.createPostgresReportingWebhookActivityV1)({
|
|
384
|
-
db: options.db,
|
|
385
|
-
namespace: options.namespace,
|
|
386
|
-
...options.webhookActivity?.tableName !== void 0 ? { tableName: options.webhookActivity.tableName } : {},
|
|
387
|
-
...options.webhookActivity?.retentionDays !== void 0 ? { retentionDays: options.webhookActivity.retentionDays } : {}
|
|
388
|
-
});
|
|
389
|
-
const composedAttemptCheckpoint = (0, import_webhook_activity.composeNotificationDeliveryAttemptCheckpoints)(
|
|
390
|
-
recipientCheckpoint,
|
|
391
|
-
webhookActivity.checkpointDeliveryAttempt
|
|
392
|
-
);
|
|
393
|
-
const attemptCheckpoint = Object.assign(
|
|
394
|
-
async (input) => composedAttemptCheckpoint(input),
|
|
395
|
-
{ activityStore: recipientCheckpoint.activityStore }
|
|
396
|
-
);
|
|
397
|
-
const adopterAttemptResult = options.notifications.webhooks.onAttemptResult;
|
|
398
|
-
const adopterAttemptObserverError = options.notifications.webhooks.onAttemptObserverError;
|
|
399
|
-
const notifications = (0, import_notification_subscriptions.createPostgresPersistentNotificationRuntime)({
|
|
400
|
-
...options.notifications,
|
|
401
|
-
db: options.db,
|
|
402
|
-
publisherScope: options.publisherScope,
|
|
403
|
-
checkpointDeliveryAttempt: attemptCheckpoint,
|
|
404
|
-
supportedAccountEventTypes: ["reporting.ledger_changed", "reporting.status_changed", "reporting.delivery_ready"],
|
|
405
|
-
webhooks: {
|
|
406
|
-
...options.notifications.webhooks,
|
|
407
|
-
onAttemptResult: (0, import_webhook_activity.composeWebhookAttemptResultObservers)(
|
|
408
|
-
webhookActivity.emitterObservers.onAttemptResult,
|
|
409
|
-
adopterAttemptResult
|
|
410
|
-
),
|
|
411
|
-
onAttemptObserverError(error, phase) {
|
|
412
|
-
if (adopterAttemptObserverError) {
|
|
413
|
-
try {
|
|
414
|
-
adopterAttemptObserverError(error, phase);
|
|
415
|
-
return;
|
|
416
|
-
} catch (observerError) {
|
|
417
|
-
console.warn(
|
|
418
|
-
`[adcp/reporting] webhook observer-error hook failed: ${safeMessage(observerError)}; original: ${safeMessage(error)}`
|
|
419
|
-
);
|
|
420
|
-
return;
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
console.warn(`[adcp/reporting] webhook ${phase} observer failed: ${safeMessage(error)}`);
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
});
|
|
427
|
-
const notificationActivity = (0, import_ledger.createPostgresReportingNotificationActivityRuntime)({
|
|
428
|
-
...options.activity,
|
|
429
|
-
db: options.db,
|
|
430
|
-
notifications,
|
|
431
|
-
namespace: options.namespace,
|
|
432
|
-
attemptCheckpoint,
|
|
433
|
-
tenantScopeForAccount: options.activity.tenantScopeForAccount
|
|
434
|
-
});
|
|
435
|
-
const coreStore = new import_ledger.PostgresReportingLedgerStore(options.db, {
|
|
436
|
-
acknowledgeIsolatedDatabase: options.acknowledgeIsolatedDatabase,
|
|
437
|
-
managedDelivery: true,
|
|
438
|
-
...options.obligatedConsumers ? { obligatedConsumers: options.obligatedConsumers } : {},
|
|
439
|
-
...options.consumerMismatchEscalation ? { consumerMismatchEscalation: options.consumerMismatchEscalation } : {},
|
|
440
|
-
notificationActivityPort: notificationActivity.port,
|
|
441
|
-
...options.rowStorage ? { rowStorage: options.rowStorage } : {},
|
|
442
|
-
...options.changeFeed ? { changeFeed: true } : {}
|
|
443
|
-
});
|
|
444
|
-
if (options.compaction) coreStore.assertCompactionSafeRowBindings();
|
|
445
|
-
const managedStore = new import_ledger.PostgresReportingManagedDeliveryStore(options.db, {
|
|
446
|
-
...options.managedDelivery.store,
|
|
447
|
-
statusRetentionDays: options.statusRetentionDays,
|
|
448
|
-
advertisedRecoveryWindowSeconds: options.automatedRecoveryWindowSeconds,
|
|
449
|
-
notificationActivityPort: notificationActivity.port
|
|
450
|
-
});
|
|
451
|
-
const coreOptions = {
|
|
452
|
-
...options,
|
|
453
|
-
store: coreStore,
|
|
454
|
-
[PRODUCTION_MANAGED_COMPOSITION]: true
|
|
455
|
-
};
|
|
456
|
-
const core = createReliableReportingService(coreOptions);
|
|
457
|
-
const migrations = Object.freeze([
|
|
458
|
-
import_ledger.REPORTING_LEDGER_MIGRATION,
|
|
459
|
-
...options.rowStorage ? [import_ledger.REPORTING_ROW_STORAGE_MIGRATION] : [],
|
|
460
|
-
...options.changeFeed ? [import_ledger.REPORTING_LEDGER_CHANGES_MIGRATION] : [],
|
|
461
|
-
import_ledger.REPORTING_MANAGED_DELIVERY_MIGRATION,
|
|
462
|
-
...notifications.migrations.all,
|
|
463
|
-
...notificationActivity.migrations.all,
|
|
464
|
-
...webhookActivity.migrations.all
|
|
465
|
-
]);
|
|
466
|
-
await options.applyMigrations?.(migrations);
|
|
467
|
-
await coreStore.readyRowStorage();
|
|
468
|
-
await notifications.probe();
|
|
469
|
-
await notificationActivity.probe();
|
|
470
|
-
await webhookActivity.probe();
|
|
471
|
-
const managed = await (0, import_ledger.createReportingManagedDeliveryRuntime)({
|
|
472
|
-
coreStore,
|
|
473
|
-
...options.legacyRevisionReader ? { legacyRevisionReader: options.legacyRevisionReader } : {},
|
|
474
|
-
store: managedStore,
|
|
475
|
-
adapter: options.managedDelivery.adapter,
|
|
476
|
-
offerings: core.capabilities.offerings,
|
|
477
|
-
automatedRecoveryWindowSeconds: options.automatedRecoveryWindowSeconds,
|
|
478
|
-
statusRetentionDays: options.statusRetentionDays,
|
|
479
|
-
resourceRetentionDays: options.managedDelivery.resourceRetentionDays,
|
|
480
|
-
authorizationRevocationSeconds: options.managedDelivery.authorizationRevocationSeconds,
|
|
481
|
-
...options.resolveConsumerId ? { resolveConsumerId: options.resolveConsumerId } : {},
|
|
482
|
-
...options.consumerMismatchEscalation ? { consumerMismatchEscalation: options.consumerMismatchEscalation } : {}
|
|
483
|
-
});
|
|
484
|
-
const capabilities = deepFreeze(
|
|
485
|
-
import_schemas.ReportingDeliveryCapabilitiesSchema.parse({
|
|
486
|
-
...core.capabilities,
|
|
487
|
-
...managed.reportingDeliveryCapabilities,
|
|
488
|
-
ledger_notification: "reporting.ledger_changed",
|
|
489
|
-
status_notification: "reporting.status_changed",
|
|
490
|
-
readiness_notification: "reporting.delivery_ready",
|
|
491
|
-
supports_webhook_activity: true
|
|
492
|
-
})
|
|
493
|
-
);
|
|
494
|
-
const platform = {
|
|
495
|
-
capabilities,
|
|
496
|
-
getReportingStatus: (request, context) => managed.getReportingStatus(request, context),
|
|
497
|
-
getMediaBuyDelivery: (request, context) => managed.getMediaBuyDelivery(request, context),
|
|
498
|
-
...core.platform.syncReportingStatus ? {
|
|
499
|
-
syncReportingStatus: core.platform.syncReportingStatus,
|
|
500
|
-
resolveConsumerId: core.platform.resolveConsumerId
|
|
501
|
-
} : {},
|
|
502
|
-
...managed.syncReportingReceipts ? {
|
|
503
|
-
syncReportingReceipts: (request, context) => managed.syncReportingReceipts(request, context)
|
|
504
|
-
} : {},
|
|
505
|
-
async projectListAccounts(request, response, context) {
|
|
506
|
-
const withoutDiagnostics = () => (0, import_webhook_activity.projectListAccountsReportingWebhookActivityV1)({
|
|
507
|
-
request: { ...request, include_webhook_activity: false },
|
|
508
|
-
response,
|
|
509
|
-
tenantId: "diagnostics-not-requested",
|
|
510
|
-
principalId: "diagnostics-not-requested",
|
|
511
|
-
activity: webhookActivity
|
|
512
|
-
});
|
|
513
|
-
if (request.include_webhook_activity !== true) return withoutDiagnostics();
|
|
514
|
-
try {
|
|
515
|
-
const scope = await options.resolveWebhookActivityScope(context);
|
|
516
|
-
return await (0, import_webhook_activity.projectListAccountsReportingWebhookActivityV1)({
|
|
517
|
-
request,
|
|
518
|
-
response,
|
|
519
|
-
tenantId: scope.tenantId,
|
|
520
|
-
principalId: scope.principalId,
|
|
521
|
-
activity: webhookActivity
|
|
522
|
-
});
|
|
523
|
-
} catch (error) {
|
|
524
|
-
defaultSchedulerWarn(`[adcp/reporting] webhook activity projection unavailable: ${safeMessage(error)}`);
|
|
525
|
-
return withoutDiagnostics();
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
};
|
|
529
|
-
let auxiliaryAbort;
|
|
530
|
-
let auxiliaryPromise;
|
|
531
|
-
let auxiliaryRotation = 0;
|
|
532
|
-
const reportAuxiliaryError = async (scheduler, error) => {
|
|
533
|
-
if (scheduler.onError) {
|
|
534
|
-
try {
|
|
535
|
-
await scheduler.onError(error);
|
|
536
|
-
return;
|
|
537
|
-
} catch (observerError) {
|
|
538
|
-
warnSchedulerFailure(scheduler, { phase: "cycle" }, error, observerError);
|
|
539
|
-
return;
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
warnSchedulerFailure(scheduler, { phase: "cycle" }, error);
|
|
543
|
-
};
|
|
544
|
-
const runAuxiliaryPass = async (scheduler, signal) => {
|
|
545
|
-
signal.throwIfAborted();
|
|
546
|
-
try {
|
|
547
|
-
const totalLimit = scheduler.notificationRecoveryLimit ?? 25;
|
|
548
|
-
const concurrency = Math.min(scheduler.notificationRecoveryConcurrency ?? 4, totalLimit);
|
|
549
|
-
const baseLimit = Math.floor(totalLimit / concurrency);
|
|
550
|
-
const remainder = totalLimit % concurrency;
|
|
551
|
-
await Promise.all(
|
|
552
|
-
Array.from(
|
|
553
|
-
{ length: concurrency },
|
|
554
|
-
(_, index) => notificationActivity.recoverOnce({
|
|
555
|
-
limit: baseLimit + (index < remainder ? 1 : 0),
|
|
556
|
-
signal,
|
|
557
|
-
onError: (error) => reportAuxiliaryError(scheduler, error)
|
|
558
|
-
})
|
|
559
|
-
)
|
|
560
|
-
);
|
|
561
|
-
} catch (error) {
|
|
562
|
-
if (!signal.aborted) await reportAuxiliaryError(scheduler, error);
|
|
563
|
-
}
|
|
564
|
-
signal.throwIfAborted();
|
|
565
|
-
try {
|
|
566
|
-
await notifications.recoverOnce({ limit: scheduler.webhookRecoveryLimit ?? 10 });
|
|
567
|
-
} catch (error) {
|
|
568
|
-
if (!signal.aborted) await reportAuxiliaryError(scheduler, error);
|
|
569
|
-
}
|
|
570
|
-
signal.throwIfAborted();
|
|
571
|
-
const pruneResults = await Promise.allSettled([
|
|
572
|
-
notificationActivity.pruneProjected({ limit: 1e3 }),
|
|
573
|
-
webhookActivity.pruneCompleted({ limit: 1e3 })
|
|
574
|
-
]);
|
|
575
|
-
for (const result of pruneResults) {
|
|
576
|
-
if (result.status === "rejected" && !signal.aborted) await reportAuxiliaryError(scheduler, result.reason);
|
|
577
|
-
}
|
|
578
|
-
await (0, import_maintenance.runReportingLedgerMaintenance)({
|
|
579
|
-
store: coreStore,
|
|
580
|
-
sweepSnapshots: (limit) => (0, import_ledger.sweepExpiredReportingLedgerState)(options.db, limit),
|
|
581
|
-
statusRetentionDays: options.statusRetentionDays,
|
|
582
|
-
automatedRecoveryWindowSeconds: options.automatedRecoveryWindowSeconds,
|
|
583
|
-
retention: options.retention,
|
|
584
|
-
compaction: options.compaction,
|
|
585
|
-
changeFeed: options.changeFeed,
|
|
586
|
-
signal,
|
|
587
|
-
report: (error) => reportAuxiliaryError(scheduler, error)
|
|
588
|
-
});
|
|
589
|
-
const accountIds = rotate(await deploymentWideAccountIds(coreStore), auxiliaryRotation);
|
|
590
|
-
auxiliaryRotation += 1;
|
|
591
|
-
for (const accountId of accountIds) {
|
|
592
|
-
signal.throwIfAborted();
|
|
593
|
-
try {
|
|
594
|
-
await managed.runWorker({
|
|
595
|
-
signal,
|
|
596
|
-
...accountId ? { account_id: accountId } : {},
|
|
597
|
-
...scheduler.maxWorkerIterationsPerAccount !== void 0 ? { maxIterations: scheduler.maxWorkerIterationsPerAccount } : {}
|
|
598
|
-
});
|
|
599
|
-
if (accountId) await managedStore.pruneExpiredEvidence?.({ account_id: accountId, limit: 1e3 });
|
|
600
|
-
} catch (error) {
|
|
601
|
-
if (!signal.aborted) await reportAuxiliaryError(scheduler, error);
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
};
|
|
605
|
-
const service = {
|
|
606
|
-
setup: Object.freeze({ component: "reliable-reporting-production", migrations }),
|
|
607
|
-
capabilities,
|
|
608
|
-
platform,
|
|
609
|
-
core,
|
|
610
|
-
managed,
|
|
611
|
-
notifications,
|
|
612
|
-
notificationActivity,
|
|
613
|
-
webhookActivity,
|
|
614
|
-
stores: Object.freeze({ core: coreStore, managed: managedStore }),
|
|
615
|
-
get running() {
|
|
616
|
-
return core.running || auxiliaryPromise !== void 0;
|
|
617
|
-
},
|
|
618
|
-
installConfiguration: core.installConfiguration.bind(core),
|
|
619
|
-
install(target) {
|
|
620
|
-
if (typeof target.accounts.upsert !== "function") {
|
|
621
|
-
throw new TypeError("Reliable reporting requires accounts.upsert");
|
|
622
|
-
}
|
|
623
|
-
if (typeof target.accounts.list !== "function") {
|
|
624
|
-
throw new TypeError(
|
|
625
|
-
"Reliable reporting production webhook activity requires accounts.list so list_accounts can serve the advertised diagnostics"
|
|
626
|
-
);
|
|
627
|
-
}
|
|
628
|
-
if (target.reporting && target.reporting !== platform) {
|
|
629
|
-
throw new TypeError("DecisioningPlatform already has a reporting lifecycle installed");
|
|
630
|
-
}
|
|
631
|
-
if (!target.reporting) {
|
|
632
|
-
Object.defineProperty(target, "reporting", {
|
|
633
|
-
value: platform,
|
|
634
|
-
enumerable: true,
|
|
635
|
-
configurable: false,
|
|
636
|
-
writable: false
|
|
637
|
-
});
|
|
638
|
-
}
|
|
639
|
-
return target;
|
|
640
|
-
},
|
|
641
|
-
async runCycle(cycle) {
|
|
642
|
-
const coreResult = await core.runCycle(cycle);
|
|
643
|
-
const managedResult = await managed.runWorker({
|
|
644
|
-
...cycle.signal ? { signal: cycle.signal } : {},
|
|
645
|
-
...!cycle.deploymentWide ? { account_id: cycle.accountId } : {},
|
|
646
|
-
...cycle.maxWorkerIterations !== void 0 ? { maxIterations: cycle.maxWorkerIterations } : {}
|
|
647
|
-
});
|
|
648
|
-
return { core: coreResult, managed: managedResult };
|
|
649
|
-
},
|
|
650
|
-
async recoverOnce(recoveryOptions) {
|
|
651
|
-
if (recoveryOptions?.deploymentWide !== true) {
|
|
652
|
-
throw new TypeError("Reliable Reporting production recovery requires deploymentWide: true");
|
|
653
|
-
}
|
|
654
|
-
const activityResult = await notificationActivity.recoverOnce();
|
|
655
|
-
const webhookOutbox = await notifications.recoverOnce();
|
|
656
|
-
return { activity: activityResult, webhookOutbox };
|
|
657
|
-
},
|
|
658
|
-
start(scheduler) {
|
|
659
|
-
if (auxiliaryPromise) throw new Error("Reliable Reporting production scheduler is already running");
|
|
660
|
-
if (scheduler.deploymentWide !== true) {
|
|
661
|
-
throw new TypeError("Reliable Reporting production scheduler requires deploymentWide: true");
|
|
662
|
-
}
|
|
663
|
-
if (scheduler.notificationRecoveryLimit !== void 0 && (!Number.isSafeInteger(scheduler.notificationRecoveryLimit) || scheduler.notificationRecoveryLimit < 1 || scheduler.notificationRecoveryLimit > 1e3)) {
|
|
664
|
-
throw new TypeError("notificationRecoveryLimit must be an integer from 1 through 1000");
|
|
665
|
-
}
|
|
666
|
-
if (scheduler.notificationRecoveryConcurrency !== void 0 && (!Number.isSafeInteger(scheduler.notificationRecoveryConcurrency) || scheduler.notificationRecoveryConcurrency < 1 || scheduler.notificationRecoveryConcurrency > 64)) {
|
|
667
|
-
throw new TypeError("notificationRecoveryConcurrency must be an integer from 1 through 64");
|
|
668
|
-
}
|
|
669
|
-
if (scheduler.webhookRecoveryLimit !== void 0 && (!Number.isSafeInteger(scheduler.webhookRecoveryLimit) || scheduler.webhookRecoveryLimit < 1 || scheduler.webhookRecoveryLimit > 1e3)) {
|
|
670
|
-
throw new TypeError("webhookRecoveryLimit must be an integer from 1 through 1000");
|
|
671
|
-
}
|
|
672
|
-
core.start(scheduler);
|
|
673
|
-
auxiliaryAbort = new AbortController();
|
|
674
|
-
const signal = auxiliaryAbort.signal;
|
|
675
|
-
auxiliaryPromise = (async () => {
|
|
676
|
-
while (!signal.aborted) {
|
|
677
|
-
try {
|
|
678
|
-
await runAuxiliaryPass(scheduler, signal);
|
|
679
|
-
} catch (error) {
|
|
680
|
-
if (!signal.aborted) await reportAuxiliaryError(scheduler, error);
|
|
681
|
-
}
|
|
682
|
-
if (!signal.aborted) await abortableDelay(scheduler.intervalMilliseconds, signal);
|
|
683
|
-
}
|
|
684
|
-
})().finally(() => {
|
|
685
|
-
auxiliaryAbort = void 0;
|
|
686
|
-
auxiliaryPromise = void 0;
|
|
687
|
-
});
|
|
688
|
-
},
|
|
689
|
-
async stop() {
|
|
690
|
-
auxiliaryAbort?.abort();
|
|
691
|
-
await Promise.all([core.stop(), auxiliaryPromise]);
|
|
692
|
-
}
|
|
693
|
-
};
|
|
694
|
-
return service;
|
|
695
|
-
}
|
|
696
326
|
function createRoutedSource(sources, offerings) {
|
|
697
327
|
const capabilities = (0, import_source.reportingSourceCapabilitiesV1)([...offerings.values()], "reliable-reporting-service-v1");
|
|
698
328
|
return {
|
|
@@ -723,15 +353,15 @@ async function schedulerLoop(service, options, signal, store, maintenance) {
|
|
|
723
353
|
// it — the producer's own default cap starves the rest just as an
|
|
724
354
|
// explicit per-account cap would. Enumerate the roster so each tenant
|
|
725
355
|
// gets its own bounded cycle, and rotate the starting point each pass.
|
|
726
|
-
|
|
727
|
-
) :
|
|
356
|
+
(0, import_scheduler_support.rotateReportingRoster)(await (0, import_scheduler_support.reportingDeploymentWideAccountIds)(store), rotation)
|
|
357
|
+
) : (0, import_scheduler_support.rotateReportingRoster)(
|
|
728
358
|
validateAccountIds(
|
|
729
359
|
typeof options.accountIds === "function" ? await options.accountIds() : options.accountIds
|
|
730
360
|
),
|
|
731
361
|
rotation
|
|
732
362
|
);
|
|
733
363
|
} catch (error) {
|
|
734
|
-
await
|
|
364
|
+
await (0, import_scheduler_support.reportReportingSchedulerError)(options, signal, error, { phase: "roster" });
|
|
735
365
|
}
|
|
736
366
|
rotation += 1;
|
|
737
367
|
for (const accountId of accountIds) {
|
|
@@ -747,7 +377,7 @@ async function schedulerLoop(service, options, signal, store, maintenance) {
|
|
|
747
377
|
...options.settlementGraceMilliseconds !== void 0 ? { settlementGraceMilliseconds: options.settlementGraceMilliseconds } : {}
|
|
748
378
|
});
|
|
749
379
|
} catch (error) {
|
|
750
|
-
await
|
|
380
|
+
await (0, import_scheduler_support.reportReportingSchedulerError)(options, signal, error, { phase: "cycle", accountId });
|
|
751
381
|
}
|
|
752
382
|
}
|
|
753
383
|
if (maintenance && !signal.aborted && (lastMaintenanceAt === void 0 || Date.now() - lastMaintenanceAt >= maintenance.intervalMilliseconds)) {
|
|
@@ -755,99 +385,12 @@ async function schedulerLoop(service, options, signal, store, maintenance) {
|
|
|
755
385
|
try {
|
|
756
386
|
await maintenance.run();
|
|
757
387
|
} catch (error) {
|
|
758
|
-
await
|
|
388
|
+
await (0, import_scheduler_support.reportReportingSchedulerError)(options, signal, error, { phase: "maintenance" });
|
|
759
389
|
}
|
|
760
390
|
}
|
|
761
|
-
if (!signal.aborted) await
|
|
762
|
-
}
|
|
763
|
-
}
|
|
764
|
-
async function reportSchedulerError(options, signal, error, site) {
|
|
765
|
-
if (signal.aborted) return;
|
|
766
|
-
if (options.onError) {
|
|
767
|
-
try {
|
|
768
|
-
await options.onError(error);
|
|
769
|
-
} catch (observerError) {
|
|
770
|
-
warnSchedulerFailure(options, site, error, observerError);
|
|
771
|
-
}
|
|
772
|
-
return;
|
|
773
|
-
}
|
|
774
|
-
warnSchedulerFailure(options, site, error);
|
|
775
|
-
}
|
|
776
|
-
function warnSchedulerFailure(options, site, error, observerError) {
|
|
777
|
-
const where = site.phase === "roster" ? "could not resolve its account roster, so this pass ran no tenants" : site.phase === "maintenance" ? "ledger maintenance failed; the scheduler continues" : site.accountId === void 0 ? "deployment-wide cycle failed; the scheduler continues" : `cycle failed for account ${site.accountId}; later tenants continue`;
|
|
778
|
-
const observed = observerError === void 0 ? "" : ` (the configured onError also threw: ${safeMessage(observerError)})`;
|
|
779
|
-
const message = `[adcp/reporting] scheduler ${where}: ${safeMessage(error)}${observed}`;
|
|
780
|
-
const logger = options.logger;
|
|
781
|
-
try {
|
|
782
|
-
if (logger !== void 0) logger.warn(message);
|
|
783
|
-
else defaultSchedulerWarn(message);
|
|
784
|
-
} catch {
|
|
391
|
+
if (!signal.aborted) await (0, import_scheduler_support.reportingSchedulerDelay)(options.intervalMilliseconds, signal);
|
|
785
392
|
}
|
|
786
393
|
}
|
|
787
|
-
function defaultSchedulerWarn(message) {
|
|
788
|
-
console.warn(message);
|
|
789
|
-
}
|
|
790
|
-
const MAX_SCHEDULER_MESSAGE_CHARS = 512;
|
|
791
|
-
const MAX_SCHEDULER_SCAN_CHARS = 8192;
|
|
792
|
-
const UNREPORTABLE_SCHEDULER_ERROR = "<unreportable error>";
|
|
793
|
-
function safeMessage(error) {
|
|
794
|
-
try {
|
|
795
|
-
const raw = rawMessage(error);
|
|
796
|
-
const redacted = (0, import_redact_credential_patterns.redactCredentialPatterns)(raw.slice(0, MAX_SCHEDULER_SCAN_CHARS));
|
|
797
|
-
const text = typeof redacted === "string" && redacted.length > 0 ? redacted : UNREPORTABLE_SCHEDULER_ERROR;
|
|
798
|
-
return text.length > MAX_SCHEDULER_MESSAGE_CHARS ? `${text.slice(0, MAX_SCHEDULER_MESSAGE_CHARS)}\u2026` : text;
|
|
799
|
-
} catch {
|
|
800
|
-
return UNREPORTABLE_SCHEDULER_ERROR;
|
|
801
|
-
}
|
|
802
|
-
}
|
|
803
|
-
function rawMessage(error) {
|
|
804
|
-
switch (typeof error) {
|
|
805
|
-
case "string":
|
|
806
|
-
return error;
|
|
807
|
-
case "number":
|
|
808
|
-
case "boolean":
|
|
809
|
-
case "bigint":
|
|
810
|
-
return String(error);
|
|
811
|
-
case "undefined":
|
|
812
|
-
return "undefined";
|
|
813
|
-
case "symbol":
|
|
814
|
-
return error.description ?? "symbol";
|
|
815
|
-
default:
|
|
816
|
-
break;
|
|
817
|
-
}
|
|
818
|
-
if (error === null) return "null";
|
|
819
|
-
const message = error.message;
|
|
820
|
-
return typeof message === "string" ? message : "non-Error scheduler failure";
|
|
821
|
-
}
|
|
822
|
-
const MAX_TIMER_DELAY_MILLISECONDS = 2147483647;
|
|
823
|
-
async function abortableDelay(milliseconds, signal) {
|
|
824
|
-
let remaining = milliseconds;
|
|
825
|
-
while (remaining > 0 && !signal.aborted) {
|
|
826
|
-
const chunk = Math.min(remaining, MAX_TIMER_DELAY_MILLISECONDS);
|
|
827
|
-
await abortableTimeout(chunk, signal);
|
|
828
|
-
remaining -= chunk;
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
function abortableTimeout(milliseconds, signal) {
|
|
832
|
-
return new Promise((resolve) => {
|
|
833
|
-
const timer = setTimeout(done, milliseconds);
|
|
834
|
-
function done() {
|
|
835
|
-
clearTimeout(timer);
|
|
836
|
-
signal.removeEventListener("abort", done);
|
|
837
|
-
resolve();
|
|
838
|
-
}
|
|
839
|
-
signal.addEventListener("abort", done, { once: true });
|
|
840
|
-
});
|
|
841
|
-
}
|
|
842
|
-
function rotate(values, by) {
|
|
843
|
-
if (values.length < 2) return [...values];
|
|
844
|
-
const offset = (by % values.length + values.length) % values.length;
|
|
845
|
-
return [...values.slice(offset), ...values.slice(0, offset)];
|
|
846
|
-
}
|
|
847
|
-
async function deploymentWideAccountIds(store) {
|
|
848
|
-
const configurations = await store.listConfigurations();
|
|
849
|
-
return [...new Set(configurations.map((value) => value.account.account_id))].sort();
|
|
850
|
-
}
|
|
851
394
|
function validateAccountIds(values) {
|
|
852
395
|
if (!Array.isArray(values)) {
|
|
853
396
|
throw new TypeError("Reporting scheduler accountIds resolver must return an array");
|
|
@@ -901,7 +444,7 @@ function validateDeliveryOffering(source, delivery, allowManagedDelivery = false
|
|
|
901
444
|
}
|
|
902
445
|
if (!allowManagedDelivery && (delivery.method !== void 0 || delivery.reconciliation_mode !== "delivery_only" || delivery.feed_purpose === "billing")) {
|
|
903
446
|
throw new TypeError(
|
|
904
|
-
"Managed Delivery and Reconciled Billing require createPostgresReliableReportingProductionService from @adcp/
|
|
447
|
+
"Managed Delivery and Reconciled Billing require createPostgresReliableReportingProductionService from @adcp/reporting-storage/service"
|
|
905
448
|
);
|
|
906
449
|
}
|
|
907
450
|
if (delivery.schedule.alignment !== "utc" && delivery.schedule.alignment !== "source_timezone") {
|
|
@@ -1244,8 +787,8 @@ function deepFreeze(value) {
|
|
|
1244
787
|
}
|
|
1245
788
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1246
789
|
0 && (module.exports = {
|
|
1247
|
-
|
|
1248
|
-
createPostgresReliableReportingProductionService,
|
|
790
|
+
REPORTING_MANAGED_DELIVERY_COMPOSITION_V1,
|
|
1249
791
|
createReliableReportingService,
|
|
1250
|
-
...require('./conformance.js')
|
|
792
|
+
...require('./conformance.js'),
|
|
793
|
+
...require('./scheduler-support.js')
|
|
1251
794
|
});
|