@adcp/sdk 17.0.0-beta.21 → 17.0.0-beta.22
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/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 +10 -1
- package/dist/lib/core/SingleAgentClient.d.ts +10 -1
- package/dist/lib/core/SingleAgentClient.js +56 -7
- package/dist/lib/core/SingleAgentClient.mjs +61 -7
- 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/registry/types.generated.d.ts +18 -2
- 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 +95 -22
- package/dist/lib/server/create-adcp-server.mjs +106 -21
- 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/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 +2 -2
- package/dist/lib/testing/storyboard/runner.mjs +2 -2
- 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
|
|
@@ -199,9 +199,6 @@ function computeTrackStatus(results) {
|
|
|
199
199
|
const totalSteps = totalPassed + totalFailed + totalSkipped;
|
|
200
200
|
const hasAssertionFailure = results.some((result) => collectDetachedAssertionFailures(result).length > 0);
|
|
201
201
|
const stepsOf = (result) => (result.passes?.flatMap((pass) => pass.phases) ?? result.phases).flatMap((phase) => phase.steps);
|
|
202
|
-
const hasFixtureUnavailable = results.some(
|
|
203
|
-
(result) => stepsOf(result).some((step) => step.skip?.reason === "fixture_unavailable")
|
|
204
|
-
);
|
|
205
202
|
const hasUnverifiedSigningCoverage = results.some((result) => (0, import_runner.signingCoverageUnverified)(stepsOf(result)));
|
|
206
203
|
if (totalSteps === 0) return "skip";
|
|
207
204
|
if (totalFailed > 0) return totalPassed === 0 ? "fail" : "partial";
|
|
@@ -209,7 +206,6 @@ function computeTrackStatus(results) {
|
|
|
209
206
|
if (hasUnverifiedSigningCoverage) return "partial";
|
|
210
207
|
if (totalSteps === totalSkipped) return "skip";
|
|
211
208
|
if (results.some((result) => !result.overall_passed)) return "partial";
|
|
212
|
-
if (hasFixtureUnavailable) return "partial";
|
|
213
209
|
const observationRecords = results.flatMap((r) => r.assertions ?? []).filter((a) => typeof a.observation_count === "number");
|
|
214
210
|
if (observationRecords.length > 0 && observationRecords.every((a) => a.observation_count === 0)) {
|
|
215
211
|
return "silent";
|
|
@@ -174,9 +174,6 @@ function computeTrackStatus(results) {
|
|
|
174
174
|
const totalSteps = totalPassed + totalFailed + totalSkipped;
|
|
175
175
|
const hasAssertionFailure = results.some((result) => collectDetachedAssertionFailures(result).length > 0);
|
|
176
176
|
const stepsOf = (result) => (result.passes?.flatMap((pass) => pass.phases) ?? result.phases).flatMap((phase) => phase.steps);
|
|
177
|
-
const hasFixtureUnavailable = results.some(
|
|
178
|
-
(result) => stepsOf(result).some((step) => step.skip?.reason === "fixture_unavailable")
|
|
179
|
-
);
|
|
180
177
|
const hasUnverifiedSigningCoverage = results.some((result) => signingCoverageUnverified(stepsOf(result)));
|
|
181
178
|
if (totalSteps === 0) return "skip";
|
|
182
179
|
if (totalFailed > 0) return totalPassed === 0 ? "fail" : "partial";
|
|
@@ -184,7 +181,6 @@ function computeTrackStatus(results) {
|
|
|
184
181
|
if (hasUnverifiedSigningCoverage) return "partial";
|
|
185
182
|
if (totalSteps === totalSkipped) return "skip";
|
|
186
183
|
if (results.some((result) => !result.overall_passed)) return "partial";
|
|
187
|
-
if (hasFixtureUnavailable) return "partial";
|
|
188
184
|
const observationRecords = results.flatMap((r) => r.assertions ?? []).filter((a) => typeof a.observation_count === "number");
|
|
189
185
|
if (observationRecords.length > 0 && observationRecords.every((a) => a.observation_count === 0)) {
|
|
190
186
|
return "silent";
|
|
@@ -24,6 +24,7 @@ __export(comply_controller_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(comply_controller_exports);
|
|
25
25
|
var import_test_controller = require('../server/test-controller.js');
|
|
26
26
|
var import_adcp_server = require('../server/adcp-server.js');
|
|
27
|
+
var import_declared_input_schema = require('../server/declared-input-schema.js');
|
|
27
28
|
function controllerError(code, detail) {
|
|
28
29
|
return { status: "failed", success: false, error: code, error_detail: detail };
|
|
29
30
|
}
|
|
@@ -254,14 +255,18 @@ function createComplyController(config) {
|
|
|
254
255
|
}
|
|
255
256
|
}
|
|
256
257
|
const mcp = (0, import_adcp_server.getSdkServer)(server) ?? server;
|
|
257
|
-
mcp.registerTool(
|
|
258
|
+
const registered = mcp.registerTool(
|
|
258
259
|
toolDefinition.name,
|
|
259
260
|
{
|
|
260
261
|
description: toolDefinition.description,
|
|
261
262
|
inputSchema: toolDefinition.inputSchema
|
|
262
263
|
},
|
|
263
|
-
(async (
|
|
264
|
+
(async (rawInput) => {
|
|
265
|
+
const parsed = await (0, import_declared_input_schema.parseDeclaredToolInput)(mcp, toolDefinition.name, rawInput);
|
|
266
|
+
return parsed.success ? handle(parsed.data) : parsed.response;
|
|
267
|
+
})
|
|
264
268
|
);
|
|
269
|
+
(0, import_declared_input_schema.validateToolInputAtAdcpLayer)(mcp, toolDefinition.name, registered);
|
|
265
270
|
}
|
|
266
271
|
const controller = { toolDefinition, handleRaw, handle, register };
|
|
267
272
|
resolvedContextHandlers.set(controller, handleRawWithResolvedAuthority);
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
RESET_STATE_SCENARIO
|
|
10
10
|
} from "../server/test-controller.mjs";
|
|
11
11
|
import { getSdkServer } from "../server/adcp-server.mjs";
|
|
12
|
+
import { parseDeclaredToolInput, validateToolInputAtAdcpLayer } from "../server/declared-input-schema.mjs";
|
|
12
13
|
function controllerError(code, detail) {
|
|
13
14
|
return { status: "failed", success: false, error: code, error_detail: detail };
|
|
14
15
|
}
|
|
@@ -239,14 +240,18 @@ function createComplyController(config) {
|
|
|
239
240
|
}
|
|
240
241
|
}
|
|
241
242
|
const mcp = getSdkServer(server) ?? server;
|
|
242
|
-
mcp.registerTool(
|
|
243
|
+
const registered = mcp.registerTool(
|
|
243
244
|
toolDefinition.name,
|
|
244
245
|
{
|
|
245
246
|
description: toolDefinition.description,
|
|
246
247
|
inputSchema: toolDefinition.inputSchema
|
|
247
248
|
},
|
|
248
|
-
(async (
|
|
249
|
+
(async (rawInput) => {
|
|
250
|
+
const parsed = await parseDeclaredToolInput(mcp, toolDefinition.name, rawInput);
|
|
251
|
+
return parsed.success ? handle(parsed.data) : parsed.response;
|
|
252
|
+
})
|
|
249
253
|
);
|
|
254
|
+
validateToolInputAtAdcpLayer(mcp, toolDefinition.name, registered);
|
|
250
255
|
}
|
|
251
256
|
const controller = { toolDefinition, handleRaw, handle, register };
|
|
252
257
|
resolvedContextHandlers.set(controller, handleRawWithResolvedAuthority);
|
|
@@ -105,6 +105,13 @@ export interface GradeOptions extends LoadVectorsOptions {
|
|
|
105
105
|
* provided (its own `protocol_methods_required_for` governs).
|
|
106
106
|
*/
|
|
107
107
|
agentProtocolMethodsRequiredFor?: readonly string[];
|
|
108
|
+
/**
|
|
109
|
+
* The agent's `get_adcp_capabilities` response, used to evaluate a vector's
|
|
110
|
+
* `applies_when` condition (adcp#8064). A vector whose condition does not
|
|
111
|
+
* hold skips as `capability_profile_mismatch`. Without this option,
|
|
112
|
+
* conditional vectors are graded.
|
|
113
|
+
*/
|
|
114
|
+
agentCapabilities?: Record<string, unknown>;
|
|
108
115
|
/**
|
|
109
116
|
* Transport shape the agent speaks. `'mcp'` (default) wraps each
|
|
110
117
|
* vector body in a JSON-RPC `tools/call` envelope and POSTs to the MCP
|
|
@@ -316,6 +323,20 @@ export declare function advertisedContentDigestPolicyExclusion(vector: PositiveV
|
|
|
316
323
|
* 001 unchanged.
|
|
317
324
|
*/
|
|
318
325
|
export declare function advertisedRequiredForExclusion(vector: PositiveVector | NegativeVector, kind: 'positive' | 'negative', agentRequiredFor: readonly string[]): SemanticVectorExclusion | undefined;
|
|
326
|
+
/**
|
|
327
|
+
* Evaluate a vector's `applies_when` condition (adcp#8064) against the agent's
|
|
328
|
+
* advertised `get_adcp_capabilities` response. A vector whose condition does
|
|
329
|
+
* not hold tests a path the agent does not offer, so it skips as
|
|
330
|
+
* `capability_profile_mismatch` instead of failing. Vector 027 uses this:
|
|
331
|
+
* condition (b) of `request_signature_required` applies only while
|
|
332
|
+
* `webhook_signing.legacy_hmac_fallback` is `true`, and an absent
|
|
333
|
+
* `webhook_signing` block does not satisfy it.
|
|
334
|
+
*
|
|
335
|
+
* Supported form: a dotted capability path compared with `==` or `!=` to a
|
|
336
|
+
* JSON scalar. Without capabilities, or with any other expression, the vector
|
|
337
|
+
* stays graded, so a condition the grader cannot read never hides a failure.
|
|
338
|
+
*/
|
|
339
|
+
export declare function appliesWhenExclusion(vector: PositiveVector | NegativeVector, agentCapabilities: unknown): SemanticVectorExclusion | undefined;
|
|
319
340
|
/**
|
|
320
341
|
* The `protocol_methods_required_for` slice of `capabilityMismatch`
|
|
321
342
|
* (adcp#4326 namespace): negative vectors that grade a JSON-RPC protocol
|