@adcp/sdk 17.0.0-beta.21 → 17.0.0-beta.23
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 +26 -2
- package/dist/lib/adapters/version/index.d.mts +1 -1
- package/dist/lib/adapters/version/index.d.ts +1 -1
- package/dist/lib/adapters/version/index.js +2 -0
- package/dist/lib/adapters/version/index.mjs +2 -0
- package/dist/lib/adapters/version/negotiate.d.mts +13 -0
- package/dist/lib/adapters/version/negotiate.d.ts +13 -0
- package/dist/lib/adapters/version/negotiate.js +6 -0
- package/dist/lib/adapters/version/negotiate.mjs +5 -0
- package/dist/lib/client/core.d.mts +4 -0
- package/dist/lib/client/core.d.ts +4 -0
- package/dist/lib/client/core.js +13 -0
- package/dist/lib/client/core.mjs +12 -0
- package/dist/lib/conformance/property-lists.d.mts +1 -1
- package/dist/lib/conformance/property-lists.d.ts +1 -1
- package/dist/lib/conformance/property-lists.js +1 -1
- package/dist/lib/conformance/property-lists.mjs +1 -1
- package/dist/lib/core/SingleAgentClient.d.mts +23 -1
- package/dist/lib/core/SingleAgentClient.d.ts +23 -1
- package/dist/lib/core/SingleAgentClient.js +102 -18
- package/dist/lib/core/SingleAgentClient.mjs +108 -18
- package/dist/lib/core/targeting-helpers.d.mts +123 -0
- package/dist/lib/core/targeting-helpers.d.ts +123 -0
- package/dist/lib/core/targeting-helpers.js +412 -0
- package/dist/lib/core/targeting-helpers.mjs +370 -0
- package/dist/lib/entrypoints/client-account-changes.d.mts +5 -0
- package/dist/lib/entrypoints/client-account-changes.d.ts +5 -0
- package/dist/lib/entrypoints/client-account-changes.js +28 -0
- package/dist/lib/entrypoints/client-account-changes.mjs +4 -0
- package/dist/lib/entrypoints/client-webhook-stores.d.mts +2 -0
- package/dist/lib/entrypoints/client-webhook-stores.d.ts +2 -0
- package/dist/lib/entrypoints/client-webhook-stores.js +37 -0
- package/dist/lib/entrypoints/client-webhook-stores.mjs +16 -0
- package/dist/lib/entrypoints/discovery.d.mts +9 -0
- package/dist/lib/entrypoints/discovery.d.ts +9 -0
- package/dist/lib/entrypoints/discovery.js +72 -0
- package/dist/lib/entrypoints/discovery.mjs +56 -0
- package/dist/lib/entrypoints/errors.d.mts +11 -0
- package/dist/lib/entrypoints/errors.d.ts +11 -0
- package/dist/lib/entrypoints/errors.js +159 -0
- package/dist/lib/entrypoints/errors.mjs +132 -0
- package/dist/lib/entrypoints/media-buy.d.mts +5 -0
- package/dist/lib/entrypoints/media-buy.d.ts +5 -0
- package/dist/lib/entrypoints/media-buy.js +119 -0
- package/dist/lib/entrypoints/media-buy.mjs +100 -0
- package/dist/lib/entrypoints/registry.d.mts +5 -0
- package/dist/lib/entrypoints/registry.d.ts +5 -0
- package/dist/lib/entrypoints/registry.js +61 -0
- package/dist/lib/entrypoints/registry.mjs +40 -0
- package/dist/lib/entrypoints/utils.d.mts +7 -0
- package/dist/lib/entrypoints/utils.d.ts +7 -0
- package/dist/lib/entrypoints/utils.js +100 -0
- package/dist/lib/entrypoints/utils.mjs +72 -0
- package/dist/lib/entrypoints/version.d.mts +3 -0
- package/dist/lib/entrypoints/version.d.ts +3 -0
- package/dist/lib/entrypoints/version.js +57 -0
- package/dist/lib/entrypoints/version.mjs +36 -0
- package/dist/lib/index.d.mts +1 -1
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/media-buy/action-contracts.js +3 -3
- package/dist/lib/media-buy/action-contracts.mjs +1 -1
- package/dist/lib/media-buy/creative-start-policy.d.mts +19 -0
- package/dist/lib/media-buy/creative-start-policy.d.ts +19 -0
- package/dist/lib/media-buy/creative-start-policy.js +59 -0
- package/dist/lib/media-buy/creative-start-policy.mjs +31 -0
- package/dist/lib/media-buy/valid-actions.d.mts +47 -0
- package/dist/lib/media-buy/valid-actions.d.ts +47 -0
- package/dist/lib/media-buy/valid-actions.js +42 -0
- package/dist/lib/media-buy/valid-actions.mjs +18 -0
- package/dist/lib/net/pin-and-bind-fetch.d.mts +121 -0
- package/dist/lib/net/pin-and-bind-fetch.d.ts +121 -0
- package/dist/lib/net/pin-and-bind-fetch.js +209 -0
- package/dist/lib/net/pin-and-bind-fetch.mjs +183 -0
- package/dist/lib/protocols/mcp-modern.js +20 -4
- package/dist/lib/protocols/mcp-modern.mjs +20 -4
- package/dist/lib/registry/types.generated.d.ts +224 -3
- package/dist/lib/reporting/ledger/index.d.mts +1 -0
- package/dist/lib/reporting/ledger/index.d.ts +1 -0
- package/dist/lib/reporting/ledger/index.js +3 -1
- package/dist/lib/reporting/ledger/index.mjs +1 -0
- package/dist/lib/reporting/ledger/instant.d.mts +5 -0
- package/dist/lib/reporting/ledger/instant.d.ts +5 -0
- package/dist/lib/reporting/ledger/instant.js +10 -0
- package/dist/lib/reporting/ledger/instant.mjs +9 -0
- package/dist/lib/reporting/ledger/issue-events.d.mts +333 -0
- package/dist/lib/reporting/ledger/issue-events.d.ts +333 -0
- package/dist/lib/reporting/ledger/issue-events.js +310 -0
- package/dist/lib/reporting/ledger/issue-events.mjs +282 -0
- package/dist/lib/reporting/service/index.d.mts +36 -1
- package/dist/lib/reporting/service/index.d.ts +36 -1
- package/dist/lib/reporting/service/index.js +51 -1
- package/dist/lib/reporting/service/index.mjs +52 -2
- package/dist/lib/reporting/service/scheduler-support.d.mts +1 -1
- package/dist/lib/reporting/service/scheduler-support.d.ts +1 -1
- package/dist/lib/reporting/service/scheduler-support.js +1 -1
- package/dist/lib/reporting/service/scheduler-support.mjs +1 -1
- package/dist/lib/server/capabilities-release-projection.d.mts +43 -0
- package/dist/lib/server/capabilities-release-projection.d.ts +43 -0
- package/dist/lib/server/capabilities-release-projection.js +128 -0
- package/dist/lib/server/capabilities-release-projection.mjs +112 -0
- package/dist/lib/server/create-adcp-server.d.mts +29 -5
- package/dist/lib/server/create-adcp-server.d.ts +29 -5
- package/dist/lib/server/create-adcp-server.js +97 -24
- package/dist/lib/server/create-adcp-server.mjs +108 -23
- package/dist/lib/server/decisioning/capabilities.d.mts +27 -0
- package/dist/lib/server/decisioning/capabilities.d.ts +27 -0
- package/dist/lib/server/decisioning/runtime/from-platform.js +99 -27
- package/dist/lib/server/decisioning/runtime/from-platform.mjs +103 -27
- package/dist/lib/server/declared-input-schema.d.mts +108 -0
- package/dist/lib/server/declared-input-schema.d.ts +108 -0
- package/dist/lib/server/declared-input-schema.js +167 -0
- package/dist/lib/server/declared-input-schema.mjs +137 -0
- package/dist/lib/server/envelope-allowlist.d.mts +1 -105
- package/dist/lib/server/envelope-allowlist.d.ts +1 -105
- package/dist/lib/server/envelope-allowlist.js +3 -79
- package/dist/lib/server/envelope-allowlist.mjs +1 -71
- package/dist/lib/server/errors.d.mts +1 -186
- package/dist/lib/server/errors.d.ts +1 -186
- package/dist/lib/server/errors.js +3 -98
- package/dist/lib/server/errors.mjs +1 -94
- package/dist/lib/server/index.d.mts +1 -1
- package/dist/lib/server/index.d.ts +1 -1
- package/dist/lib/server/mcp-modern-server.js +21 -4
- package/dist/lib/server/mcp-modern-server.mjs +21 -4
- package/dist/lib/server/media-buy-action-resolver.d.mts +7 -0
- package/dist/lib/server/media-buy-action-resolver.d.ts +7 -0
- package/dist/lib/server/media-buy-action-resolver.js +10 -1
- package/dist/lib/server/media-buy-action-resolver.mjs +10 -1
- package/dist/lib/server/media-buy-helpers.d.mts +1 -47
- package/dist/lib/server/media-buy-helpers.d.ts +1 -47
- package/dist/lib/server/media-buy-helpers.js +3 -23
- package/dist/lib/server/media-buy-helpers.mjs +1 -18
- package/dist/lib/server/pick-safe-details.d.mts +1 -89
- package/dist/lib/server/pick-safe-details.d.ts +1 -89
- package/dist/lib/server/pick-safe-details.js +3 -61
- package/dist/lib/server/pick-safe-details.mjs +1 -56
- package/dist/lib/server/pin-and-bind-fetch.d.mts +1 -121
- package/dist/lib/server/pin-and-bind-fetch.d.ts +1 -121
- package/dist/lib/server/pin-and-bind-fetch.js +3 -190
- package/dist/lib/server/pin-and-bind-fetch.mjs +1 -183
- package/dist/lib/server/targeting-helpers.d.mts +1 -123
- package/dist/lib/server/targeting-helpers.d.ts +1 -123
- package/dist/lib/server/targeting-helpers.js +3 -393
- package/dist/lib/server/targeting-helpers.mjs +1 -370
- package/dist/lib/server/test-controller.js +7 -3
- package/dist/lib/server/test-controller.mjs +7 -3
- package/dist/lib/storage/memory-ledger.js +219 -1
- package/dist/lib/storage/memory-ledger.mjs +223 -1
- package/dist/lib/testing/client.js +26 -5
- package/dist/lib/testing/client.mjs +24 -5
- package/dist/lib/testing/compliance/storyboard-tracks.js +0 -4
- package/dist/lib/testing/compliance/storyboard-tracks.mjs +0 -4
- package/dist/lib/testing/comply-controller.js +7 -2
- package/dist/lib/testing/comply-controller.mjs +7 -2
- package/dist/lib/testing/storyboard/request-signing/grader.d.mts +21 -0
- package/dist/lib/testing/storyboard/request-signing/grader.d.ts +21 -0
- package/dist/lib/testing/storyboard/request-signing/grader.js +31 -0
- package/dist/lib/testing/storyboard/request-signing/grader.mjs +30 -0
- package/dist/lib/testing/storyboard/request-signing/probe-dispatch.js +1 -1
- package/dist/lib/testing/storyboard/request-signing/probe-dispatch.mjs +2 -1
- package/dist/lib/testing/storyboard/request-signing/types.d.mts +12 -0
- package/dist/lib/testing/storyboard/request-signing/types.d.ts +12 -0
- package/dist/lib/testing/storyboard/request-signing/vector-loader.js +7 -2
- package/dist/lib/testing/storyboard/request-signing/vector-loader.mjs +7 -2
- package/dist/lib/testing/storyboard/runner.js +4 -4
- package/dist/lib/testing/storyboard/runner.mjs +4 -4
- package/dist/lib/testing/storyboard/task-map.js +4 -1
- package/dist/lib/testing/storyboard/task-map.mjs +4 -1
- package/dist/lib/testing/storyboard/validations.d.mts +1 -1
- package/dist/lib/testing/storyboard/validations.d.ts +1 -1
- package/dist/lib/utils/adcp-error-response.d.mts +196 -0
- package/dist/lib/utils/adcp-error-response.d.ts +196 -0
- package/dist/lib/utils/adcp-error-response.js +118 -0
- package/dist/lib/utils/adcp-error-response.mjs +95 -0
- package/dist/lib/utils/buyer-retry-policy.js +2 -2
- package/dist/lib/utils/buyer-retry-policy.mjs +1 -1
- package/dist/lib/utils/capabilities.d.mts +6 -0
- package/dist/lib/utils/capabilities.d.ts +6 -0
- package/dist/lib/utils/capabilities.js +6 -2
- package/dist/lib/utils/capabilities.mjs +6 -2
- package/dist/lib/utils/envelope-allowlist.d.mts +105 -0
- package/dist/lib/utils/envelope-allowlist.d.ts +105 -0
- package/dist/lib/utils/envelope-allowlist.js +98 -0
- package/dist/lib/utils/envelope-allowlist.mjs +71 -0
- package/dist/lib/utils/pick-safe-details.d.mts +89 -0
- package/dist/lib/utils/pick-safe-details.d.ts +89 -0
- package/dist/lib/utils/pick-safe-details.js +80 -0
- package/dist/lib/utils/pick-safe-details.mjs +56 -0
- package/dist/lib/v2/projection/augment-response.d.mts +4 -0
- package/dist/lib/v2/projection/augment-response.d.ts +4 -0
- package/dist/lib/v2/projection/creative-delivery.d.mts +20 -3
- package/dist/lib/v2/projection/creative-delivery.d.ts +20 -3
- package/dist/lib/v2/projection/creative-delivery.js +20 -4
- package/dist/lib/v2/projection/creative-delivery.mjs +19 -4
- package/dist/lib/v2/projection/index.d.mts +2 -2
- package/dist/lib/v2/projection/index.d.ts +2 -2
- package/dist/lib/v2/projection/index.js +4 -0
- package/dist/lib/v2/projection/index.mjs +5 -1
- package/dist/lib/v2/projection/legacy-metadata.d.mts +7 -0
- package/dist/lib/v2/projection/legacy-metadata.d.ts +7 -0
- package/dist/lib/v2/projection/legacy-metadata.js +14 -0
- package/dist/lib/v2/projection/legacy-metadata.mjs +12 -0
- package/dist/lib/v2/projection/legacy-routes.d.mts +11 -0
- package/dist/lib/v2/projection/legacy-routes.d.ts +11 -0
- package/dist/lib/v2/projection/legacy-routes.js +2 -1
- package/dist/lib/v2/projection/legacy-routes.mjs +7 -2
- package/dist/lib/v2/projection/v1-to-v2.d.mts +21 -1
- package/dist/lib/v2/projection/v1-to-v2.d.ts +21 -1
- package/dist/lib/v2/projection/v1-to-v2.js +18 -11
- package/dist/lib/v2/projection/v1-to-v2.mjs +19 -11
- package/dist/lib/version.d.mts +3 -3
- package/dist/lib/version.d.ts +3 -3
- package/dist/lib/version.js +3 -3
- package/dist/lib/version.mjs +3 -3
- package/docs/TYPE-SUMMARY.md +2 -2
- package/docs/guides/CREATIVE-DELIVERY.md +12 -0
- package/docs/guides/REPORTING-LEDGER.md +121 -0
- package/docs/guides/VALIDATE-YOUR-AGENT.md +1 -0
- package/docs/llms.txt +2 -2
- package/docs/migration-14.x-rc-worksheet.md +4 -4
- package/docs/migration-16-to-17.md +149 -0
- package/docs/migration-reporting-storage-package.md +10 -0
- package/package.json +106 -1
|
@@ -24,9 +24,14 @@ module.exports = __toCommonJS(memory_ledger_exports);
|
|
|
24
24
|
var import_node_crypto = require("node:crypto");
|
|
25
25
|
var import_coverage = require('../reporting/ledger/coverage.js');
|
|
26
26
|
var import_health = require('../reporting/ledger/health.js');
|
|
27
|
+
var import_instant = require('../reporting/ledger/instant.js');
|
|
28
|
+
var import_issue_events = require('../reporting/ledger/issue-events.js');
|
|
27
29
|
var import_schedule = require('../reporting/ledger/schedule.js');
|
|
28
30
|
var import_types = require('../reporting/ledger/types.js');
|
|
29
31
|
var import_manifest = require('../reporting/source/manifest.js');
|
|
32
|
+
function issueOccurrenceKey(value) {
|
|
33
|
+
return `${value.issueId}\0${value.consumerId}`;
|
|
34
|
+
}
|
|
30
35
|
function sha(value) {
|
|
31
36
|
return (0, import_node_crypto.createHash)("sha256").update((0, import_manifest.canonicalJsonV1)(value)).digest("hex");
|
|
32
37
|
}
|
|
@@ -38,6 +43,11 @@ class MemoryReportingLedgerStore {
|
|
|
38
43
|
this.now = now;
|
|
39
44
|
}
|
|
40
45
|
now;
|
|
46
|
+
/** Records issue-lifecycle events for the issue observer (see `issue-events.ts`). */
|
|
47
|
+
issueEventsSupported = true;
|
|
48
|
+
/** The issue-event outbox, by event id. */
|
|
49
|
+
issueEvents = /* @__PURE__ */ new Map();
|
|
50
|
+
issueEventSeq = 0;
|
|
41
51
|
configurations = /* @__PURE__ */ new Map();
|
|
42
52
|
obligations = /* @__PURE__ */ new Map();
|
|
43
53
|
revisions = /* @__PURE__ */ new Map();
|
|
@@ -185,7 +195,10 @@ class MemoryReportingLedgerStore {
|
|
|
185
195
|
(item) => item.reporting_obligation_id === value.reporting_obligation_id && item.revisionNumber === value.revisionNumber
|
|
186
196
|
);
|
|
187
197
|
if (existing && existing.binding.sha256 !== value.binding.sha256) throw new Error("immutable conflict");
|
|
188
|
-
if (!existing)
|
|
198
|
+
if (!existing) {
|
|
199
|
+
this.revisions.set(value.reporting_revision_id, clone(value));
|
|
200
|
+
this.settleIssueObligation(value.reporting_obligation_id, this.instant());
|
|
201
|
+
}
|
|
189
202
|
return { inserted: !existing, value: clone(existing ?? value) };
|
|
190
203
|
}
|
|
191
204
|
async getRevision(id, accountId) {
|
|
@@ -473,11 +486,216 @@ class MemoryReportingLedgerStore {
|
|
|
473
486
|
continue;
|
|
474
487
|
}
|
|
475
488
|
this.consumerStatements.push(clone(candidate));
|
|
489
|
+
this.settleIssueChain(candidate);
|
|
476
490
|
results.push({ inserted: true, value: clone(candidate) });
|
|
477
491
|
}
|
|
478
492
|
this.consumerStatusBatches.set(batchKey, { requestFingerprint: input.requestFingerprint, results });
|
|
479
493
|
return clone(results);
|
|
480
494
|
}
|
|
495
|
+
// --- issue-lifecycle events (the issue observer) ----------------------------
|
|
496
|
+
obligationMatchesStatement(obligation, status) {
|
|
497
|
+
return obligation.account.account_id === status.account_id && status.delivery_config_id === obligation.delivery_config_id && status.delivery_config_version === obligation.delivery_config_version && status.report_definition_id === obligation.report_definition_id && (0, import_instant.compareReportingInstants)(status.period.start, obligation.period.start) === 0 && (0, import_instant.compareReportingInstants)(status.period.end, obligation.period.end) === 0 && status.period.source_timezone === obligation.period.sourceTimezone;
|
|
498
|
+
}
|
|
499
|
+
revisionMetadata(obligationId) {
|
|
500
|
+
return [...this.revisions.values()].filter((value) => value.reporting_obligation_id === obligationId).sort((a, b) => a.revisionNumber - b.revisionNumber).map(({ rows: _rows, ...metadata }) => metadata);
|
|
501
|
+
}
|
|
502
|
+
/** Occurrences whose `opened` is recorded and that have not resolved. */
|
|
503
|
+
openIssueOccurrences() {
|
|
504
|
+
const resolved = new Set(
|
|
505
|
+
[...this.issueEvents.values()].filter((value) => value.kind === "resolved").map(issueOccurrenceKey)
|
|
506
|
+
);
|
|
507
|
+
return [...this.issueEvents.values()].filter(
|
|
508
|
+
(value) => value.kind === "opened" && !resolved.has(issueOccurrenceKey(value))
|
|
509
|
+
);
|
|
510
|
+
}
|
|
511
|
+
conflictsOn(obligation) {
|
|
512
|
+
const revisions = this.revisionMetadata(obligation.reporting_obligation_id);
|
|
513
|
+
const chains = /* @__PURE__ */ new Map();
|
|
514
|
+
for (const status of this.consumerStatements) {
|
|
515
|
+
if (!this.obligationMatchesStatement(obligation, status)) continue;
|
|
516
|
+
chains.set(status.consumerId, [...chains.get(status.consumerId) ?? [], status]);
|
|
517
|
+
}
|
|
518
|
+
return [...chains.values()].flatMap((statements) => {
|
|
519
|
+
const superseded = new Set(statements.map((value) => value.supersedes_reporting_status_id).filter(Boolean));
|
|
520
|
+
const leaf = statements.find((value) => !superseded.has(value.reporting_status_id));
|
|
521
|
+
const occurrence = (0, import_issue_events.reportingConsumerMismatchOccurrenceV1)(obligation, leaf, revisions);
|
|
522
|
+
return occurrence ? [occurrence] : [];
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
recordIssueEvents(records) {
|
|
526
|
+
let recorded = 0;
|
|
527
|
+
for (const record of records) {
|
|
528
|
+
if (this.issueEvents.has(record.eventId)) continue;
|
|
529
|
+
const now = this.instant();
|
|
530
|
+
this.issueEventSeq += 1;
|
|
531
|
+
this.issueEvents.set(record.eventId, {
|
|
532
|
+
...clone(record),
|
|
533
|
+
seq: this.issueEventSeq,
|
|
534
|
+
recordedAt: now,
|
|
535
|
+
dueAt: now,
|
|
536
|
+
attempts: 0
|
|
537
|
+
});
|
|
538
|
+
recorded += 1;
|
|
539
|
+
}
|
|
540
|
+
return recorded;
|
|
541
|
+
}
|
|
542
|
+
/** Re-derive one obligation's occurrences after a write: open what conflicts, resolve what cleared. */
|
|
543
|
+
settleIssueObligation(obligationId, at) {
|
|
544
|
+
const obligation = this.obligations.get(obligationId);
|
|
545
|
+
this.recordIssueEvents(
|
|
546
|
+
(0, import_issue_events.planReportingIssueEventsV1)({
|
|
547
|
+
open: this.openIssueOccurrences().filter((value) => value.reportingObligationId === obligationId),
|
|
548
|
+
conflicts: obligation ? this.conflictsOn(obligation) : [],
|
|
549
|
+
at
|
|
550
|
+
})
|
|
551
|
+
);
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* After a statement lands: resolve the occurrence of the leaf it superseded, open one for it if it
|
|
555
|
+
* conflicts. Scoped to the statement's own chain, so it works before the obligation exists.
|
|
556
|
+
*/
|
|
557
|
+
settleIssueChain(statement) {
|
|
558
|
+
const chain = new Set(
|
|
559
|
+
this.consumerStatements.filter(
|
|
560
|
+
(value) => value.account_id === statement.account_id && value.consumerId === statement.consumerId && this.consumerChainKey(value) === this.consumerChainKey(statement)
|
|
561
|
+
).map((value) => value.reporting_status_id)
|
|
562
|
+
);
|
|
563
|
+
const obligation = [...this.obligations.values()].find((value) => this.obligationMatchesStatement(value, statement));
|
|
564
|
+
const occurrence = obligation ? (0, import_issue_events.reportingConsumerMismatchOccurrenceV1)(
|
|
565
|
+
obligation,
|
|
566
|
+
statement,
|
|
567
|
+
this.revisionMetadata(obligation.reporting_obligation_id)
|
|
568
|
+
) : void 0;
|
|
569
|
+
this.recordIssueEvents(
|
|
570
|
+
(0, import_issue_events.planReportingIssueEventsV1)({
|
|
571
|
+
open: this.openIssueOccurrences().filter(
|
|
572
|
+
(value) => value.accountId === statement.account_id && value.consumerId === statement.consumerId && chain.has(value.reportingStatusId)
|
|
573
|
+
),
|
|
574
|
+
conflicts: occurrence ? [occurrence] : [],
|
|
575
|
+
at: statement.recorded_at
|
|
576
|
+
})
|
|
577
|
+
);
|
|
578
|
+
}
|
|
579
|
+
async issueEventsReady() {
|
|
580
|
+
return true;
|
|
581
|
+
}
|
|
582
|
+
async sweepIssueEscalations({
|
|
583
|
+
escalationSeconds,
|
|
584
|
+
accountId,
|
|
585
|
+
limit = 100
|
|
586
|
+
}) {
|
|
587
|
+
if (!Number.isSafeInteger(escalationSeconds) || escalationSeconds < 0) {
|
|
588
|
+
throw new RangeError("escalationSeconds must be a non-negative integer");
|
|
589
|
+
}
|
|
590
|
+
if (!Number.isSafeInteger(limit) || limit < 1) throw new RangeError("limit must be a positive integer");
|
|
591
|
+
const now = this.instant();
|
|
592
|
+
const escalated = new Set(
|
|
593
|
+
[...this.issueEvents.values()].filter((value) => value.kind === "escalated").map(issueOccurrenceKey)
|
|
594
|
+
);
|
|
595
|
+
const due = (value) => (accountId === void 0 || value.accountId === accountId) && !escalated.has(issueOccurrenceKey(value)) && (0, import_instant.compareReportingInstantToOffset)(now, value.occurredAt, escalationSeconds * 1e3) >= 0;
|
|
596
|
+
const obligationIds = [
|
|
597
|
+
...new Set(
|
|
598
|
+
this.openIssueOccurrences().filter(due).sort((a, b) => (0, import_instant.compareReportingInstants)(a.occurredAt, b.occurredAt) || a.seq - b.seq).map((value) => value.reportingObligationId)
|
|
599
|
+
)
|
|
600
|
+
].slice(0, limit);
|
|
601
|
+
let recorded = 0;
|
|
602
|
+
for (const obligationId of obligationIds) {
|
|
603
|
+
this.settleIssueObligation(obligationId, now);
|
|
604
|
+
for (const opened of this.openIssueOccurrences().filter(
|
|
605
|
+
(value) => value.reportingObligationId === obligationId && due(value)
|
|
606
|
+
)) {
|
|
607
|
+
const escalation = (0, import_issue_events.reportingIssueEscalationV1)(opened, escalationSeconds, now);
|
|
608
|
+
if (escalation) recorded += this.recordIssueEvents([escalation]);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
return recorded;
|
|
612
|
+
}
|
|
613
|
+
async claimIssueEvents({
|
|
614
|
+
leaseMilliseconds,
|
|
615
|
+
limit,
|
|
616
|
+
accountId
|
|
617
|
+
}) {
|
|
618
|
+
if (!Number.isSafeInteger(leaseMilliseconds) || leaseMilliseconds < 1) {
|
|
619
|
+
throw new RangeError("leaseMilliseconds must be a positive integer");
|
|
620
|
+
}
|
|
621
|
+
if (!Number.isSafeInteger(limit) || limit < 1) throw new RangeError("limit must be a positive integer");
|
|
622
|
+
const now = this.instant();
|
|
623
|
+
const pending = [...this.issueEvents.values()].filter((value) => value.deliveredAt === void 0).sort((a, b) => a.seq - b.seq);
|
|
624
|
+
const head = /* @__PURE__ */ new Map();
|
|
625
|
+
for (const value of pending) {
|
|
626
|
+
if (!head.has(issueOccurrenceKey(value))) head.set(issueOccurrenceKey(value), value.seq);
|
|
627
|
+
}
|
|
628
|
+
const due = pending.filter(
|
|
629
|
+
(value) => head.get(issueOccurrenceKey(value)) === value.seq && (accountId === void 0 || value.accountId === accountId) && Date.parse(value.dueAt) <= Date.parse(now) && (value.leaseExpiresAt === void 0 || Date.parse(value.leaseExpiresAt) <= Date.parse(now))
|
|
630
|
+
).sort((a, b) => Date.parse(a.dueAt) - Date.parse(b.dueAt) || a.seq - b.seq).slice(0, limit);
|
|
631
|
+
const leaseToken = (0, import_node_crypto.createHash)("sha256").update(`${now}:${this.issueEventSeq}:${Math.random()}`).digest("hex");
|
|
632
|
+
const leaseExpiresAt = new Date(Date.parse(now) + leaseMilliseconds).toISOString();
|
|
633
|
+
return due.map((value) => {
|
|
634
|
+
value.attempts += 1;
|
|
635
|
+
value.leaseToken = leaseToken;
|
|
636
|
+
value.leaseExpiresAt = leaseExpiresAt;
|
|
637
|
+
const statement = this.consumerStatements.find(
|
|
638
|
+
(item) => item.account_id === value.accountId && item.consumerId === value.consumerId && item.reporting_status_id === value.reportingStatusId
|
|
639
|
+
);
|
|
640
|
+
const { seq: _seq, dueAt: _dueAt, deliveredAt: _deliveredAt, ...lease } = value;
|
|
641
|
+
return clone({
|
|
642
|
+
...lease,
|
|
643
|
+
leaseToken,
|
|
644
|
+
leaseExpiresAt,
|
|
645
|
+
...statement ? { statement } : {}
|
|
646
|
+
});
|
|
647
|
+
});
|
|
648
|
+
}
|
|
649
|
+
leasedIssueEvent(lease) {
|
|
650
|
+
const value = this.issueEvents.get(lease.eventId);
|
|
651
|
+
return value && value.deliveredAt === void 0 && value.leaseToken === lease.leaseToken ? value : void 0;
|
|
652
|
+
}
|
|
653
|
+
async completeIssueEvent(lease) {
|
|
654
|
+
const value = this.leasedIssueEvent(lease);
|
|
655
|
+
if (!value) return false;
|
|
656
|
+
value.deliveredAt = this.instant();
|
|
657
|
+
delete value.leaseToken;
|
|
658
|
+
delete value.leaseExpiresAt;
|
|
659
|
+
return true;
|
|
660
|
+
}
|
|
661
|
+
async releaseIssueEvent(lease, { retryAfterMilliseconds }) {
|
|
662
|
+
const value = this.leasedIssueEvent(lease);
|
|
663
|
+
if (!value) return false;
|
|
664
|
+
value.dueAt = new Date(Date.parse(this.instant()) + Math.max(0, retryAfterMilliseconds)).toISOString();
|
|
665
|
+
delete value.leaseToken;
|
|
666
|
+
delete value.leaseExpiresAt;
|
|
667
|
+
return true;
|
|
668
|
+
}
|
|
669
|
+
/** Whether an occurrence can never be derived again: its statement is no longer current, or its obligation is gone. */
|
|
670
|
+
issueOccurrenceClosed(event) {
|
|
671
|
+
if (!this.obligations.has(event.reportingObligationId)) return true;
|
|
672
|
+
const statement = this.consumerStatements.find(
|
|
673
|
+
(value) => value.account_id === event.accountId && value.consumerId === event.consumerId && value.reporting_status_id === event.reportingStatusId
|
|
674
|
+
);
|
|
675
|
+
if (!statement) return true;
|
|
676
|
+
return this.currentConsumerLeaf(statement, event.accountId, event.consumerId)?.reporting_status_id !== statement.reporting_status_id;
|
|
677
|
+
}
|
|
678
|
+
async pruneIssueEvents({
|
|
679
|
+
olderThanMilliseconds,
|
|
680
|
+
limit = 1e3
|
|
681
|
+
}) {
|
|
682
|
+
if (!Number.isSafeInteger(limit) || limit < 1) throw new RangeError("limit must be a positive integer");
|
|
683
|
+
const horizon = Date.parse(this.instant()) - olderThanMilliseconds;
|
|
684
|
+
const occurrences = /* @__PURE__ */ new Map();
|
|
685
|
+
for (const value of this.issueEvents.values()) {
|
|
686
|
+
const key = issueOccurrenceKey(value);
|
|
687
|
+
occurrences.set(key, [...occurrences.get(key) ?? [], value]);
|
|
688
|
+
}
|
|
689
|
+
const expired = [...occurrences.values()].filter(
|
|
690
|
+
(events) => events.some((value) => value.kind === "resolved") && events.every((value) => value.deliveredAt !== void 0 && Date.parse(value.deliveredAt) < horizon) && this.issueOccurrenceClosed(events[0])
|
|
691
|
+
).map((events) => ({ events, lastDelivered: Math.max(...events.map((value) => Date.parse(value.deliveredAt))) })).sort((a, b) => a.lastDelivered - b.lastDelivered).slice(0, limit);
|
|
692
|
+
let deleted = 0;
|
|
693
|
+
for (const { events } of expired) {
|
|
694
|
+
for (const value of events) this.issueEvents.delete(value.eventId);
|
|
695
|
+
deleted += events.length;
|
|
696
|
+
}
|
|
697
|
+
return deleted;
|
|
698
|
+
}
|
|
481
699
|
}
|
|
482
700
|
// Annotate the CommonJS export names for ESM import in node:
|
|
483
701
|
0 && (module.exports = {
|
|
@@ -9,12 +9,21 @@ import {
|
|
|
9
9
|
reportingLedgerSubscriptionVisibleV1
|
|
10
10
|
} from "../reporting/ledger/coverage.mjs";
|
|
11
11
|
import { projectReportingObligationHealthV1 } from "../reporting/ledger/health.mjs";
|
|
12
|
+
import { compareReportingInstants, compareReportingInstantToOffset } from "../reporting/ledger/instant.mjs";
|
|
13
|
+
import {
|
|
14
|
+
planReportingIssueEventsV1,
|
|
15
|
+
reportingConsumerMismatchOccurrenceV1,
|
|
16
|
+
reportingIssueEscalationV1
|
|
17
|
+
} from "../reporting/ledger/issue-events.mjs";
|
|
12
18
|
import { reportingPeriodSchedule } from "../reporting/ledger/schedule.mjs";
|
|
13
19
|
import {
|
|
14
20
|
ReportingConsumerStatusConflictError,
|
|
15
21
|
ReportingLedgerSnapshotUnavailableError
|
|
16
22
|
} from "../reporting/ledger/types.mjs";
|
|
17
23
|
import { canonicalJsonV1 } from "../reporting/source/manifest.mjs";
|
|
24
|
+
function issueOccurrenceKey(value) {
|
|
25
|
+
return `${value.issueId}\0${value.consumerId}`;
|
|
26
|
+
}
|
|
18
27
|
function sha(value) {
|
|
19
28
|
return createHash("sha256").update(canonicalJsonV1(value)).digest("hex");
|
|
20
29
|
}
|
|
@@ -26,6 +35,11 @@ class MemoryReportingLedgerStore {
|
|
|
26
35
|
this.now = now;
|
|
27
36
|
}
|
|
28
37
|
now;
|
|
38
|
+
/** Records issue-lifecycle events for the issue observer (see `issue-events.ts`). */
|
|
39
|
+
issueEventsSupported = true;
|
|
40
|
+
/** The issue-event outbox, by event id. */
|
|
41
|
+
issueEvents = /* @__PURE__ */ new Map();
|
|
42
|
+
issueEventSeq = 0;
|
|
29
43
|
configurations = /* @__PURE__ */ new Map();
|
|
30
44
|
obligations = /* @__PURE__ */ new Map();
|
|
31
45
|
revisions = /* @__PURE__ */ new Map();
|
|
@@ -173,7 +187,10 @@ class MemoryReportingLedgerStore {
|
|
|
173
187
|
(item) => item.reporting_obligation_id === value.reporting_obligation_id && item.revisionNumber === value.revisionNumber
|
|
174
188
|
);
|
|
175
189
|
if (existing && existing.binding.sha256 !== value.binding.sha256) throw new Error("immutable conflict");
|
|
176
|
-
if (!existing)
|
|
190
|
+
if (!existing) {
|
|
191
|
+
this.revisions.set(value.reporting_revision_id, clone(value));
|
|
192
|
+
this.settleIssueObligation(value.reporting_obligation_id, this.instant());
|
|
193
|
+
}
|
|
177
194
|
return { inserted: !existing, value: clone(existing ?? value) };
|
|
178
195
|
}
|
|
179
196
|
async getRevision(id, accountId) {
|
|
@@ -461,11 +478,216 @@ class MemoryReportingLedgerStore {
|
|
|
461
478
|
continue;
|
|
462
479
|
}
|
|
463
480
|
this.consumerStatements.push(clone(candidate));
|
|
481
|
+
this.settleIssueChain(candidate);
|
|
464
482
|
results.push({ inserted: true, value: clone(candidate) });
|
|
465
483
|
}
|
|
466
484
|
this.consumerStatusBatches.set(batchKey, { requestFingerprint: input.requestFingerprint, results });
|
|
467
485
|
return clone(results);
|
|
468
486
|
}
|
|
487
|
+
// --- issue-lifecycle events (the issue observer) ----------------------------
|
|
488
|
+
obligationMatchesStatement(obligation, status) {
|
|
489
|
+
return obligation.account.account_id === status.account_id && status.delivery_config_id === obligation.delivery_config_id && status.delivery_config_version === obligation.delivery_config_version && status.report_definition_id === obligation.report_definition_id && compareReportingInstants(status.period.start, obligation.period.start) === 0 && compareReportingInstants(status.period.end, obligation.period.end) === 0 && status.period.source_timezone === obligation.period.sourceTimezone;
|
|
490
|
+
}
|
|
491
|
+
revisionMetadata(obligationId) {
|
|
492
|
+
return [...this.revisions.values()].filter((value) => value.reporting_obligation_id === obligationId).sort((a, b) => a.revisionNumber - b.revisionNumber).map(({ rows: _rows, ...metadata }) => metadata);
|
|
493
|
+
}
|
|
494
|
+
/** Occurrences whose `opened` is recorded and that have not resolved. */
|
|
495
|
+
openIssueOccurrences() {
|
|
496
|
+
const resolved = new Set(
|
|
497
|
+
[...this.issueEvents.values()].filter((value) => value.kind === "resolved").map(issueOccurrenceKey)
|
|
498
|
+
);
|
|
499
|
+
return [...this.issueEvents.values()].filter(
|
|
500
|
+
(value) => value.kind === "opened" && !resolved.has(issueOccurrenceKey(value))
|
|
501
|
+
);
|
|
502
|
+
}
|
|
503
|
+
conflictsOn(obligation) {
|
|
504
|
+
const revisions = this.revisionMetadata(obligation.reporting_obligation_id);
|
|
505
|
+
const chains = /* @__PURE__ */ new Map();
|
|
506
|
+
for (const status of this.consumerStatements) {
|
|
507
|
+
if (!this.obligationMatchesStatement(obligation, status)) continue;
|
|
508
|
+
chains.set(status.consumerId, [...chains.get(status.consumerId) ?? [], status]);
|
|
509
|
+
}
|
|
510
|
+
return [...chains.values()].flatMap((statements) => {
|
|
511
|
+
const superseded = new Set(statements.map((value) => value.supersedes_reporting_status_id).filter(Boolean));
|
|
512
|
+
const leaf = statements.find((value) => !superseded.has(value.reporting_status_id));
|
|
513
|
+
const occurrence = reportingConsumerMismatchOccurrenceV1(obligation, leaf, revisions);
|
|
514
|
+
return occurrence ? [occurrence] : [];
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
recordIssueEvents(records) {
|
|
518
|
+
let recorded = 0;
|
|
519
|
+
for (const record of records) {
|
|
520
|
+
if (this.issueEvents.has(record.eventId)) continue;
|
|
521
|
+
const now = this.instant();
|
|
522
|
+
this.issueEventSeq += 1;
|
|
523
|
+
this.issueEvents.set(record.eventId, {
|
|
524
|
+
...clone(record),
|
|
525
|
+
seq: this.issueEventSeq,
|
|
526
|
+
recordedAt: now,
|
|
527
|
+
dueAt: now,
|
|
528
|
+
attempts: 0
|
|
529
|
+
});
|
|
530
|
+
recorded += 1;
|
|
531
|
+
}
|
|
532
|
+
return recorded;
|
|
533
|
+
}
|
|
534
|
+
/** Re-derive one obligation's occurrences after a write: open what conflicts, resolve what cleared. */
|
|
535
|
+
settleIssueObligation(obligationId, at) {
|
|
536
|
+
const obligation = this.obligations.get(obligationId);
|
|
537
|
+
this.recordIssueEvents(
|
|
538
|
+
planReportingIssueEventsV1({
|
|
539
|
+
open: this.openIssueOccurrences().filter((value) => value.reportingObligationId === obligationId),
|
|
540
|
+
conflicts: obligation ? this.conflictsOn(obligation) : [],
|
|
541
|
+
at
|
|
542
|
+
})
|
|
543
|
+
);
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* After a statement lands: resolve the occurrence of the leaf it superseded, open one for it if it
|
|
547
|
+
* conflicts. Scoped to the statement's own chain, so it works before the obligation exists.
|
|
548
|
+
*/
|
|
549
|
+
settleIssueChain(statement) {
|
|
550
|
+
const chain = new Set(
|
|
551
|
+
this.consumerStatements.filter(
|
|
552
|
+
(value) => value.account_id === statement.account_id && value.consumerId === statement.consumerId && this.consumerChainKey(value) === this.consumerChainKey(statement)
|
|
553
|
+
).map((value) => value.reporting_status_id)
|
|
554
|
+
);
|
|
555
|
+
const obligation = [...this.obligations.values()].find((value) => this.obligationMatchesStatement(value, statement));
|
|
556
|
+
const occurrence = obligation ? reportingConsumerMismatchOccurrenceV1(
|
|
557
|
+
obligation,
|
|
558
|
+
statement,
|
|
559
|
+
this.revisionMetadata(obligation.reporting_obligation_id)
|
|
560
|
+
) : void 0;
|
|
561
|
+
this.recordIssueEvents(
|
|
562
|
+
planReportingIssueEventsV1({
|
|
563
|
+
open: this.openIssueOccurrences().filter(
|
|
564
|
+
(value) => value.accountId === statement.account_id && value.consumerId === statement.consumerId && chain.has(value.reportingStatusId)
|
|
565
|
+
),
|
|
566
|
+
conflicts: occurrence ? [occurrence] : [],
|
|
567
|
+
at: statement.recorded_at
|
|
568
|
+
})
|
|
569
|
+
);
|
|
570
|
+
}
|
|
571
|
+
async issueEventsReady() {
|
|
572
|
+
return true;
|
|
573
|
+
}
|
|
574
|
+
async sweepIssueEscalations({
|
|
575
|
+
escalationSeconds,
|
|
576
|
+
accountId,
|
|
577
|
+
limit = 100
|
|
578
|
+
}) {
|
|
579
|
+
if (!Number.isSafeInteger(escalationSeconds) || escalationSeconds < 0) {
|
|
580
|
+
throw new RangeError("escalationSeconds must be a non-negative integer");
|
|
581
|
+
}
|
|
582
|
+
if (!Number.isSafeInteger(limit) || limit < 1) throw new RangeError("limit must be a positive integer");
|
|
583
|
+
const now = this.instant();
|
|
584
|
+
const escalated = new Set(
|
|
585
|
+
[...this.issueEvents.values()].filter((value) => value.kind === "escalated").map(issueOccurrenceKey)
|
|
586
|
+
);
|
|
587
|
+
const due = (value) => (accountId === void 0 || value.accountId === accountId) && !escalated.has(issueOccurrenceKey(value)) && compareReportingInstantToOffset(now, value.occurredAt, escalationSeconds * 1e3) >= 0;
|
|
588
|
+
const obligationIds = [
|
|
589
|
+
...new Set(
|
|
590
|
+
this.openIssueOccurrences().filter(due).sort((a, b) => compareReportingInstants(a.occurredAt, b.occurredAt) || a.seq - b.seq).map((value) => value.reportingObligationId)
|
|
591
|
+
)
|
|
592
|
+
].slice(0, limit);
|
|
593
|
+
let recorded = 0;
|
|
594
|
+
for (const obligationId of obligationIds) {
|
|
595
|
+
this.settleIssueObligation(obligationId, now);
|
|
596
|
+
for (const opened of this.openIssueOccurrences().filter(
|
|
597
|
+
(value) => value.reportingObligationId === obligationId && due(value)
|
|
598
|
+
)) {
|
|
599
|
+
const escalation = reportingIssueEscalationV1(opened, escalationSeconds, now);
|
|
600
|
+
if (escalation) recorded += this.recordIssueEvents([escalation]);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
return recorded;
|
|
604
|
+
}
|
|
605
|
+
async claimIssueEvents({
|
|
606
|
+
leaseMilliseconds,
|
|
607
|
+
limit,
|
|
608
|
+
accountId
|
|
609
|
+
}) {
|
|
610
|
+
if (!Number.isSafeInteger(leaseMilliseconds) || leaseMilliseconds < 1) {
|
|
611
|
+
throw new RangeError("leaseMilliseconds must be a positive integer");
|
|
612
|
+
}
|
|
613
|
+
if (!Number.isSafeInteger(limit) || limit < 1) throw new RangeError("limit must be a positive integer");
|
|
614
|
+
const now = this.instant();
|
|
615
|
+
const pending = [...this.issueEvents.values()].filter((value) => value.deliveredAt === void 0).sort((a, b) => a.seq - b.seq);
|
|
616
|
+
const head = /* @__PURE__ */ new Map();
|
|
617
|
+
for (const value of pending) {
|
|
618
|
+
if (!head.has(issueOccurrenceKey(value))) head.set(issueOccurrenceKey(value), value.seq);
|
|
619
|
+
}
|
|
620
|
+
const due = pending.filter(
|
|
621
|
+
(value) => head.get(issueOccurrenceKey(value)) === value.seq && (accountId === void 0 || value.accountId === accountId) && Date.parse(value.dueAt) <= Date.parse(now) && (value.leaseExpiresAt === void 0 || Date.parse(value.leaseExpiresAt) <= Date.parse(now))
|
|
622
|
+
).sort((a, b) => Date.parse(a.dueAt) - Date.parse(b.dueAt) || a.seq - b.seq).slice(0, limit);
|
|
623
|
+
const leaseToken = createHash("sha256").update(`${now}:${this.issueEventSeq}:${Math.random()}`).digest("hex");
|
|
624
|
+
const leaseExpiresAt = new Date(Date.parse(now) + leaseMilliseconds).toISOString();
|
|
625
|
+
return due.map((value) => {
|
|
626
|
+
value.attempts += 1;
|
|
627
|
+
value.leaseToken = leaseToken;
|
|
628
|
+
value.leaseExpiresAt = leaseExpiresAt;
|
|
629
|
+
const statement = this.consumerStatements.find(
|
|
630
|
+
(item) => item.account_id === value.accountId && item.consumerId === value.consumerId && item.reporting_status_id === value.reportingStatusId
|
|
631
|
+
);
|
|
632
|
+
const { seq: _seq, dueAt: _dueAt, deliveredAt: _deliveredAt, ...lease } = value;
|
|
633
|
+
return clone({
|
|
634
|
+
...lease,
|
|
635
|
+
leaseToken,
|
|
636
|
+
leaseExpiresAt,
|
|
637
|
+
...statement ? { statement } : {}
|
|
638
|
+
});
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
leasedIssueEvent(lease) {
|
|
642
|
+
const value = this.issueEvents.get(lease.eventId);
|
|
643
|
+
return value && value.deliveredAt === void 0 && value.leaseToken === lease.leaseToken ? value : void 0;
|
|
644
|
+
}
|
|
645
|
+
async completeIssueEvent(lease) {
|
|
646
|
+
const value = this.leasedIssueEvent(lease);
|
|
647
|
+
if (!value) return false;
|
|
648
|
+
value.deliveredAt = this.instant();
|
|
649
|
+
delete value.leaseToken;
|
|
650
|
+
delete value.leaseExpiresAt;
|
|
651
|
+
return true;
|
|
652
|
+
}
|
|
653
|
+
async releaseIssueEvent(lease, { retryAfterMilliseconds }) {
|
|
654
|
+
const value = this.leasedIssueEvent(lease);
|
|
655
|
+
if (!value) return false;
|
|
656
|
+
value.dueAt = new Date(Date.parse(this.instant()) + Math.max(0, retryAfterMilliseconds)).toISOString();
|
|
657
|
+
delete value.leaseToken;
|
|
658
|
+
delete value.leaseExpiresAt;
|
|
659
|
+
return true;
|
|
660
|
+
}
|
|
661
|
+
/** Whether an occurrence can never be derived again: its statement is no longer current, or its obligation is gone. */
|
|
662
|
+
issueOccurrenceClosed(event) {
|
|
663
|
+
if (!this.obligations.has(event.reportingObligationId)) return true;
|
|
664
|
+
const statement = this.consumerStatements.find(
|
|
665
|
+
(value) => value.account_id === event.accountId && value.consumerId === event.consumerId && value.reporting_status_id === event.reportingStatusId
|
|
666
|
+
);
|
|
667
|
+
if (!statement) return true;
|
|
668
|
+
return this.currentConsumerLeaf(statement, event.accountId, event.consumerId)?.reporting_status_id !== statement.reporting_status_id;
|
|
669
|
+
}
|
|
670
|
+
async pruneIssueEvents({
|
|
671
|
+
olderThanMilliseconds,
|
|
672
|
+
limit = 1e3
|
|
673
|
+
}) {
|
|
674
|
+
if (!Number.isSafeInteger(limit) || limit < 1) throw new RangeError("limit must be a positive integer");
|
|
675
|
+
const horizon = Date.parse(this.instant()) - olderThanMilliseconds;
|
|
676
|
+
const occurrences = /* @__PURE__ */ new Map();
|
|
677
|
+
for (const value of this.issueEvents.values()) {
|
|
678
|
+
const key = issueOccurrenceKey(value);
|
|
679
|
+
occurrences.set(key, [...occurrences.get(key) ?? [], value]);
|
|
680
|
+
}
|
|
681
|
+
const expired = [...occurrences.values()].filter(
|
|
682
|
+
(events) => events.some((value) => value.kind === "resolved") && events.every((value) => value.deliveredAt !== void 0 && Date.parse(value.deliveredAt) < horizon) && this.issueOccurrenceClosed(events[0])
|
|
683
|
+
).map((events) => ({ events, lastDelivered: Math.max(...events.map((value) => Date.parse(value.deliveredAt))) })).sort((a, b) => a.lastDelivered - b.lastDelivered).slice(0, limit);
|
|
684
|
+
let deleted = 0;
|
|
685
|
+
for (const { events } of expired) {
|
|
686
|
+
for (const value of events) this.issueEvents.delete(value.eventId);
|
|
687
|
+
deleted += events.length;
|
|
688
|
+
}
|
|
689
|
+
return deleted;
|
|
690
|
+
}
|
|
469
691
|
}
|
|
470
692
|
export {
|
|
471
693
|
MemoryReportingLedgerStore
|
|
@@ -38,6 +38,8 @@ __export(client_exports, {
|
|
|
38
38
|
seedAuthRejectedTestClientProfile: () => seedAuthRejectedTestClientProfile,
|
|
39
39
|
seedTestClientSigningCapability: () => seedTestClientSigningCapability,
|
|
40
40
|
setAgentTesterLogger: () => setAgentTesterLogger,
|
|
41
|
+
storyboardCapabilityStepEnvelope: () => storyboardCapabilityStepEnvelope,
|
|
42
|
+
testClientDiscoveryWireAdcpVersion: () => testClientDiscoveryWireAdcpVersion,
|
|
41
43
|
testClientWireAdcpVersion: () => testClientWireAdcpVersion,
|
|
42
44
|
validateResponseSchema: () => validateResponseSchema,
|
|
43
45
|
withTestClientScope: () => withTestClientScope
|
|
@@ -54,6 +56,7 @@ var import_capabilities = require('../utils/capabilities.js');
|
|
|
54
56
|
var import_probe_policy = require('../utils/probe-policy.js');
|
|
55
57
|
var import_ssrf_fetch = require('../net/ssrf-fetch.js');
|
|
56
58
|
var import_version = require('../version.js');
|
|
59
|
+
var import_negotiate = require('../adapters/version/negotiate.js');
|
|
57
60
|
var import_protocols = require('../protocols/index.js');
|
|
58
61
|
var import_node_crypto = require("node:crypto");
|
|
59
62
|
var import_node_async_hooks = require("node:async_hooks");
|
|
@@ -205,7 +208,7 @@ function createTestClient(agentUrl, protocol = "mcp", options = {}) {
|
|
|
205
208
|
protocol,
|
|
206
209
|
adcpVersion: multiClient.getAdcpVersion(),
|
|
207
210
|
...options.wireAdcpVersion !== void 0 && { wireAdcpVersion: options.wireAdcpVersion },
|
|
208
|
-
versionEnvelope: options.versionEnvelope
|
|
211
|
+
...options.versionEnvelope !== void 0 && { versionEnvelope: options.versionEnvelope },
|
|
209
212
|
strictResponseSchemaValidation: options.strictResponseSchemaValidation !== false,
|
|
210
213
|
...authMode !== void 0 && { authMode },
|
|
211
214
|
...requestScopeMode !== void 0 && { requestScopeMode },
|
|
@@ -261,8 +264,10 @@ function testClientMatchesVersionOptions(client, agentUrl, options) {
|
|
|
261
264
|
}
|
|
262
265
|
const expectedAdcpVersion = effectiveOptions.adcpVersion ?? import_version.ADCP_VERSION;
|
|
263
266
|
const expectedWireAdcpVersion = effectiveOptions.wireAdcpVersion;
|
|
264
|
-
|
|
265
|
-
|
|
267
|
+
return meta.agentUrl === agentUrl && meta.protocol === (effectiveOptions.protocol ?? "mcp") && meta.adcpVersion === expectedAdcpVersion && meta.wireAdcpVersion === expectedWireAdcpVersion && // Unset and `auto` put the same envelope on ordinary calls and authored
|
|
268
|
+
// storyboard steps; they differ only in the reused client's own preview
|
|
269
|
+
// discovery probe, which follows that client's config.
|
|
270
|
+
(meta.versionEnvelope ?? "auto") === (effectiveOptions.versionEnvelope ?? "auto") && meta.strictResponseSchemaValidation === (effectiveOptions.strictResponseSchemaValidation !== false) && meta.authMode === expectedAuthMode && meta.requestScopeMode === expectedRequestScopeMode && meta.requestSigningMode === expectedRequestSigningMode && meta.oauthStorage === expectedOAuthStorage && meta.connectionPartition === expectedTransport?.connectionPartition && meta.connectionReuse === expectedTransport?.connectionReuse && meta.fetchFn === expectedTransport?.trustedFetchFn && meta.allowPrivateIp === expectedTransport?.allowPrivateIp && meta.maxResponseBytes === expectedTransport?.maxResponseBytes && meta.requestTimeoutMs === expectedTransport?.requestTimeoutMs && meta.legacyCompatEnabled === expectedTransport?.legacyCompat?.enabled;
|
|
266
271
|
}
|
|
267
272
|
function withTestKitAuthDefaults(options) {
|
|
268
273
|
if (options.auth) return options;
|
|
@@ -485,11 +490,22 @@ async function runStep(stepName, taskName, fn) {
|
|
|
485
490
|
}
|
|
486
491
|
function testClientWireAdcpVersion(client, fallbackVersion) {
|
|
487
492
|
const meta = client?.[TEST_CLIENT_VERSION_OPTIONS];
|
|
488
|
-
if (meta && meta.versionEnvelope !== "auto") return void 0;
|
|
493
|
+
if (meta && (meta.versionEnvelope ?? "auto") !== "auto") return void 0;
|
|
489
494
|
const getAdcpVersion = client?.getAdcpVersion;
|
|
490
495
|
const pinned = meta?.wireAdcpVersion ?? meta?.adcpVersion ?? (typeof getAdcpVersion === "function" ? getAdcpVersion.call(client) : void 0) ?? fallbackVersion;
|
|
491
496
|
return pinned === void 0 ? void 0 : (0, import_version.toReleasePrecisionVersion)(pinned);
|
|
492
497
|
}
|
|
498
|
+
function storyboardCapabilityStepEnvelope(client) {
|
|
499
|
+
const meta = client?.[TEST_CLIENT_VERSION_OPTIONS];
|
|
500
|
+
return meta && meta.versionEnvelope === void 0 ? "auto" : void 0;
|
|
501
|
+
}
|
|
502
|
+
function testClientDiscoveryWireAdcpVersion(client, fallbackVersion) {
|
|
503
|
+
const meta = client?.[TEST_CLIENT_VERSION_OPTIONS];
|
|
504
|
+
if (meta && (0, import_negotiate.capabilityDiscoveryEnvelope)(meta.versionEnvelope, meta.wireAdcpVersion ?? meta.adcpVersion) === "none") {
|
|
505
|
+
return void 0;
|
|
506
|
+
}
|
|
507
|
+
return testClientWireAdcpVersion(client, fallbackVersion);
|
|
508
|
+
}
|
|
493
509
|
function describeVersionUnsupported(result, requestedVersion) {
|
|
494
510
|
if (!result || typeof result !== "object") return void 0;
|
|
495
511
|
const record = result;
|
|
@@ -586,7 +602,10 @@ async function discoverAgentProfile(client, signal, schemaAdcpVersion) {
|
|
|
586
602
|
};
|
|
587
603
|
const adcpError = caps.adcpError ?? caps.adcp_error;
|
|
588
604
|
if (adcpError) step.adcp_error = (0, import_discovery_evidence.redactDiscoveryEvidence)(adcpError);
|
|
589
|
-
const versionUnsupported = describeVersionUnsupported(
|
|
605
|
+
const versionUnsupported = describeVersionUnsupported(
|
|
606
|
+
caps,
|
|
607
|
+
testClientDiscoveryWireAdcpVersion(client, schemaAdcpVersion)
|
|
608
|
+
);
|
|
590
609
|
if (versionUnsupported) {
|
|
591
610
|
profile.capabilities_probe_error = versionUnsupported;
|
|
592
611
|
step.passed = false;
|
|
@@ -978,6 +997,8 @@ function zodCodeToKeyword(code) {
|
|
|
978
997
|
seedAuthRejectedTestClientProfile,
|
|
979
998
|
seedTestClientSigningCapability,
|
|
980
999
|
setAgentTesterLogger,
|
|
1000
|
+
storyboardCapabilityStepEnvelope,
|
|
1001
|
+
testClientDiscoveryWireAdcpVersion,
|
|
981
1002
|
testClientWireAdcpVersion,
|
|
982
1003
|
validateResponseSchema,
|
|
983
1004
|
withTestClientScope
|