@peac/audit 0.12.2 → 0.12.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commerce-bundle-types.d.ts +88 -0
- package/dist/commerce-bundle-types.d.ts.map +1 -0
- package/dist/commerce-bundle.d.ts +47 -0
- package/dist/commerce-bundle.d.ts.map +1 -0
- package/dist/index.cjs +104 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +98 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Commerce evidence bundle types (experimental, DD-192).
|
|
3
|
+
*
|
|
4
|
+
* Cross-ecosystem commerce evidence correlation without aggregating
|
|
5
|
+
* or asserting settlement totals. Non-aggregating by default.
|
|
6
|
+
*
|
|
7
|
+
* Promotion gate (must be met before removing -experimental suffix):
|
|
8
|
+
* - At least 2 independent producers
|
|
9
|
+
* - At least 1 independent verifier path
|
|
10
|
+
* - Documented in a versioned spec
|
|
11
|
+
*/
|
|
12
|
+
/** Bundle format version */
|
|
13
|
+
export declare const COMMERCE_BUNDLE_VERSION: "peac.commerce-bundle/0.1-experimental";
|
|
14
|
+
/** Source discriminant for protocol-specific evidence */
|
|
15
|
+
export interface ProtocolEvidence {
|
|
16
|
+
/** Protocol source identifier */
|
|
17
|
+
source: string;
|
|
18
|
+
/** Timestamp of the evidence capture */
|
|
19
|
+
captured_at: string;
|
|
20
|
+
/** Protocol-specific evidence data */
|
|
21
|
+
data: Record<string, unknown>;
|
|
22
|
+
}
|
|
23
|
+
/** Timeline entry for chronological event tracking */
|
|
24
|
+
export interface TimelineEntry {
|
|
25
|
+
/** Timestamp of the event */
|
|
26
|
+
timestamp: string;
|
|
27
|
+
/** Protocol source */
|
|
28
|
+
source: string;
|
|
29
|
+
/** Event description */
|
|
30
|
+
event: string;
|
|
31
|
+
/** Optional metadata */
|
|
32
|
+
metadata?: Record<string, unknown>;
|
|
33
|
+
}
|
|
34
|
+
/** Individual observed amount (non-aggregated) */
|
|
35
|
+
export interface ObservedAmount {
|
|
36
|
+
/** Protocol source that reported this amount */
|
|
37
|
+
source: string;
|
|
38
|
+
/** Amount in minor units (string for arbitrary precision) */
|
|
39
|
+
amount: string;
|
|
40
|
+
/** Currency code */
|
|
41
|
+
currency: string;
|
|
42
|
+
/** Semantic stage if known (e.g., "authorization", "settlement") */
|
|
43
|
+
semantic_stage?: string;
|
|
44
|
+
}
|
|
45
|
+
/** Commerce summary: observation-set, NOT aggregation */
|
|
46
|
+
export interface CommerceSummary {
|
|
47
|
+
/** Individual observed amounts from each source (not rolled up) */
|
|
48
|
+
observed_amounts: ObservedAmount[];
|
|
49
|
+
/** Currencies observed across all sources */
|
|
50
|
+
currencies_observed: string[];
|
|
51
|
+
/** Payment rails observed */
|
|
52
|
+
rails_observed: string[];
|
|
53
|
+
/** Count of protocol evidence snapshots */
|
|
54
|
+
evidence_count: number;
|
|
55
|
+
}
|
|
56
|
+
/** Commerce evidence bundle */
|
|
57
|
+
export interface CommerceEvidenceBundle {
|
|
58
|
+
/** Format version (includes -experimental suffix) */
|
|
59
|
+
version: typeof COMMERCE_BUNDLE_VERSION;
|
|
60
|
+
/** Cross-system transaction correlation ID */
|
|
61
|
+
transaction_ref: string;
|
|
62
|
+
/** Payment rails observed in this transaction */
|
|
63
|
+
rails_observed: string[];
|
|
64
|
+
/** Protocol-specific evidence snapshots */
|
|
65
|
+
protocol_evidence: ProtocolEvidence[];
|
|
66
|
+
/** Chronological event sequence */
|
|
67
|
+
timeline: TimelineEntry[];
|
|
68
|
+
/** Associated PEAC receipt references (receipt_ref hashes) */
|
|
69
|
+
receipts: string[];
|
|
70
|
+
/** Non-aggregating observation summary */
|
|
71
|
+
summary: CommerceSummary;
|
|
72
|
+
/** Bundle creation timestamp */
|
|
73
|
+
created_at: string;
|
|
74
|
+
}
|
|
75
|
+
/** Options for creating a commerce evidence bundle */
|
|
76
|
+
export interface CreateCommerceBundleOptions {
|
|
77
|
+
/** Cross-system transaction correlation ID */
|
|
78
|
+
transaction_ref: string;
|
|
79
|
+
/** Optional initial protocol evidence */
|
|
80
|
+
evidence?: ProtocolEvidence[];
|
|
81
|
+
/** Optional initial timeline entries */
|
|
82
|
+
timeline?: TimelineEntry[];
|
|
83
|
+
/** Optional initial receipt references */
|
|
84
|
+
receipts?: string[];
|
|
85
|
+
/** Optional creation timestamp (for deterministic output; defaults to now) */
|
|
86
|
+
created_at?: string;
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=commerce-bundle-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commerce-bundle-types.d.ts","sourceRoot":"","sources":["../src/commerce-bundle-types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,4BAA4B;AAC5B,eAAO,MAAM,uBAAuB,EAAG,uCAAgD,CAAC;AAExF,yDAAyD;AACzD,MAAM,WAAW,gBAAgB;IAC/B,iCAAiC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,wCAAwC;IACxC,WAAW,EAAE,MAAM,CAAC;IACpB,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED,sDAAsD;AACtD,MAAM,WAAW,aAAa;IAC5B,6BAA6B;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,sBAAsB;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,wBAAwB;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,wBAAwB;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,kDAAkD;AAClD,MAAM,WAAW,cAAc;IAC7B,gDAAgD;IAChD,MAAM,EAAE,MAAM,CAAC;IACf,6DAA6D;IAC7D,MAAM,EAAE,MAAM,CAAC;IACf,oBAAoB;IACpB,QAA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ation. Correlates receipts
|
|
5
|
+
* across payment rails without aggregating or asserting settlement totals.
|
|
6
|
+
*
|
|
7
|
+
* Summary is non-aggregating by default: observed_amounts lists each
|
|
8
|
+
* source's observation independently. A canonical total may only be
|
|
9
|
+
* derived when same currency, same semantic stage, and an explicit
|
|
10
|
+
* authoritative-winner rule is documented and tested.
|
|
11
|
+
*/
|
|
12
|
+
import type { CommerceEvidenceBundle, CommerceSummary, CreateCommerceBundleOptions, ProtocolEvidence, TimelineEntry } from './commerce-bundle-types.js';
|
|
13
|
+
/**
|
|
14
|
+
* Create a new commerce evidence bundle.
|
|
15
|
+
*/
|
|
16
|
+
export declare function createCommerceEvidenceBundle(options: CreateCommerceBundleOptions): CommerceEvidenceBundle;
|
|
17
|
+
/**
|
|
18
|
+
* Add protocol evidence to an existing bundle.
|
|
19
|
+
* Returns a new bundle (immutable pattern).
|
|
20
|
+
*/
|
|
21
|
+
export declare function addProtocolEvidence(bundle: CommerceEvidenceBundle, evidence: ProtocolEvidence): CommerceEvidenceBundle;
|
|
22
|
+
/**
|
|
23
|
+
* Add a timeline entry to an existing bundle.
|
|
24
|
+
* Returns a new bundle with sorted timeline.
|
|
25
|
+
*/
|
|
26
|
+
export declare function addTimelineEntry(bundle: CommerceEvidenceBundle, entry: TimelineEntry): CommerceEvidenceBundle;
|
|
27
|
+
/**
|
|
28
|
+
* Add a receipt reference to an existing bundle.
|
|
29
|
+
*/
|
|
30
|
+
export declare function addReceiptRef(bundle: CommerceEvidenceBundle, receiptRef: string): CommerceEvidenceBundle;
|
|
31
|
+
/**
|
|
32
|
+
* Compute a non-aggregating commerce summary from protocol evidence.
|
|
33
|
+
*
|
|
34
|
+
* Lists each source's observed amounts independently. Does NOT compute
|
|
35
|
+
* a rolled-up transaction total. A canonical total requires same currency,
|
|
36
|
+
* same semantic stage, and an explicit authoritative-winner rule.
|
|
37
|
+
*/
|
|
38
|
+
export declare function computeCommerceSummary(evidence: ProtocolEvidence[]): CommerceSummary;
|
|
39
|
+
/**
|
|
40
|
+
* Serialize a commerce bundle to deterministic JSON.
|
|
41
|
+
*
|
|
42
|
+
* Uses recursive key sorting so nested objects (protocol evidence,
|
|
43
|
+
* timeline metadata, summary) are also serialized deterministically.
|
|
44
|
+
* Arrays are preserved in-order. No nested fields are omitted.
|
|
45
|
+
*/
|
|
46
|
+
export declare function serializeCommerceBundle(bundle: CommerceEvidenceBundle): string;
|
|
47
|
+
//# sourceMappingURL=commerce-bundle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commerce-bundle.d.ts","sourceRoot":"","sources":["../src/commerce-bundle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EACV,sBAAsB,EACtB,eAAe,EACf,2BAA2B,EAE3B,gBAAgB,EAChB,aAAa,EACd,MAAM,4BAA4B,CAAC;AAGpC;;GAEG;AACH,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,2BAA2B,GACnC,sBAAsB,CAiBxB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,sBAAsB,EAC9B,QAAQ,EAAE,gBAAgB,GACzB,sBAAsB,CAQxB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,sBAAsB,EAC9B,KAAK,EAAE,aAAa,GACnB,sBAAsB,CAKxB;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,sBAAsB,EAC9B,UAAU,EAAE,MAAM,GACjB,sBAAsB,CAKxB;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,gBAAgB,EAAE,GAAG,eAAe,CA8CpF;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,sBAAsB,GAAG,MAAM,CAE9E"}
|
package/dist/index.cjs
CHANGED
|
@@ -1548,6 +1548,103 @@ function formatReportText(report) {
|
|
|
1548
1548
|
return lines.join("\n");
|
|
1549
1549
|
}
|
|
1550
1550
|
|
|
1551
|
+
// src/commerce-bundle-types.ts
|
|
1552
|
+
var COMMERCE_BUNDLE_VERSION = "peac.commerce-bundle/0.1-experimental";
|
|
1553
|
+
|
|
1554
|
+
// src/commerce-bundle.ts
|
|
1555
|
+
function createCommerceEvidenceBundle(options) {
|
|
1556
|
+
const evidence = options.evidence ?? [];
|
|
1557
|
+
const timeline = options.timeline ?? [];
|
|
1558
|
+
const receipts = options.receipts ?? [];
|
|
1559
|
+
const bundle = {
|
|
1560
|
+
version: COMMERCE_BUNDLE_VERSION,
|
|
1561
|
+
transaction_ref: options.transaction_ref,
|
|
1562
|
+
rails_observed: extractRails(evidence),
|
|
1563
|
+
protocol_evidence: evidence,
|
|
1564
|
+
timeline: sortTimeline(timeline),
|
|
1565
|
+
receipts,
|
|
1566
|
+
summary: computeCommerceSummary(evidence),
|
|
1567
|
+
created_at: options.created_at ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
1568
|
+
};
|
|
1569
|
+
return bundle;
|
|
1570
|
+
}
|
|
1571
|
+
function addProtocolEvidence(bundle, evidence) {
|
|
1572
|
+
const newEvidence = [...bundle.protocol_evidence, evidence];
|
|
1573
|
+
return {
|
|
1574
|
+
...bundle,
|
|
1575
|
+
protocol_evidence: newEvidence,
|
|
1576
|
+
rails_observed: extractRails(newEvidence),
|
|
1577
|
+
summary: computeCommerceSummary(newEvidence)
|
|
1578
|
+
};
|
|
1579
|
+
}
|
|
1580
|
+
function addTimelineEntry(bundle, entry) {
|
|
1581
|
+
return {
|
|
1582
|
+
...bundle,
|
|
1583
|
+
timeline: sortTimeline([...bundle.timeline, entry])
|
|
1584
|
+
};
|
|
1585
|
+
}
|
|
1586
|
+
function addReceiptRef(bundle, receiptRef) {
|
|
1587
|
+
return {
|
|
1588
|
+
...bundle,
|
|
1589
|
+
receipts: [...bundle.receipts, receiptRef]
|
|
1590
|
+
};
|
|
1591
|
+
}
|
|
1592
|
+
function computeCommerceSummary(evidence) {
|
|
1593
|
+
const observedAmounts = [];
|
|
1594
|
+
const currencies = /* @__PURE__ */ new Set();
|
|
1595
|
+
const rails = /* @__PURE__ */ new Set();
|
|
1596
|
+
for (const ev of evidence) {
|
|
1597
|
+
const data = ev.data;
|
|
1598
|
+
const amount = typeof data.amount_minor === "string" ? data.amount_minor : typeof data.amount === "string" ? data.amount : typeof data.amount === "number" ? String(data.amount) : void 0;
|
|
1599
|
+
const currency = typeof data.currency === "string" ? data.currency : void 0;
|
|
1600
|
+
const rail = typeof data.payment_rail === "string" ? data.payment_rail : void 0;
|
|
1601
|
+
const stage = typeof data.commerce_event === "string" ? data.commerce_event : typeof data.semantic_stage === "string" ? data.semantic_stage : void 0;
|
|
1602
|
+
if (amount && currency) {
|
|
1603
|
+
observedAmounts.push({
|
|
1604
|
+
source: ev.source,
|
|
1605
|
+
amount,
|
|
1606
|
+
currency: currency.toUpperCase(),
|
|
1607
|
+
semantic_stage: stage
|
|
1608
|
+
});
|
|
1609
|
+
currencies.add(currency.toUpperCase());
|
|
1610
|
+
}
|
|
1611
|
+
if (rail) rails.add(rail);
|
|
1612
|
+
}
|
|
1613
|
+
return {
|
|
1614
|
+
observed_amounts: observedAmounts,
|
|
1615
|
+
currencies_observed: [...currencies].sort(),
|
|
1616
|
+
rails_observed: [...rails].sort(),
|
|
1617
|
+
evidence_count: evidence.length
|
|
1618
|
+
};
|
|
1619
|
+
}
|
|
1620
|
+
function serializeCommerceBundle(bundle) {
|
|
1621
|
+
return JSON.stringify(stableSort(bundle), null, 2);
|
|
1622
|
+
}
|
|
1623
|
+
function stableSort(value) {
|
|
1624
|
+
if (value === null || value === void 0) return value;
|
|
1625
|
+
if (typeof value !== "object") return value;
|
|
1626
|
+
if (Array.isArray(value)) return value.map(stableSort);
|
|
1627
|
+
const sorted = {};
|
|
1628
|
+
for (const key of Object.keys(value).sort()) {
|
|
1629
|
+
sorted[key] = stableSort(value[key]);
|
|
1630
|
+
}
|
|
1631
|
+
return sorted;
|
|
1632
|
+
}
|
|
1633
|
+
function extractRails(evidence) {
|
|
1634
|
+
const rails = /* @__PURE__ */ new Set();
|
|
1635
|
+
for (const ev of evidence) {
|
|
1636
|
+
if (typeof ev.data.payment_rail === "string") {
|
|
1637
|
+
rails.add(ev.data.payment_rail);
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
return [...rails].sort();
|
|
1641
|
+
}
|
|
1642
|
+
function sortTimeline(entries) {
|
|
1643
|
+
return [...entries].sort(
|
|
1644
|
+
(a, b) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime()
|
|
1645
|
+
);
|
|
1646
|
+
}
|
|
1647
|
+
|
|
1551
1648
|
// src/index.ts
|
|
1552
1649
|
var AUDIT_PACKAGE_VERSION = "0.9.27";
|
|
1553
1650
|
|
|
@@ -1556,12 +1653,18 @@ exports.AUDIT_PACKAGE_VERSION = AUDIT_PACKAGE_VERSION;
|
|
|
1556
1653
|
exports.AUDIT_SEVERITIES = AUDIT_SEVERITIES;
|
|
1557
1654
|
exports.AUDIT_VERSION = AUDIT_VERSION;
|
|
1558
1655
|
exports.BUNDLE_VERSION = BUNDLE_VERSION;
|
|
1656
|
+
exports.COMMERCE_BUNDLE_VERSION = COMMERCE_BUNDLE_VERSION;
|
|
1559
1657
|
exports.DISPUTE_BUNDLE_VERSION = DISPUTE_BUNDLE_VERSION;
|
|
1560
1658
|
exports.DISPUTE_BUNDLE_VERSION_v2 = BUNDLE_VERSION2;
|
|
1561
1659
|
exports.VERIFICATION_REPORT_VERSION = VERIFICATION_REPORT_VERSION;
|
|
1660
|
+
exports.addProtocolEvidence = addProtocolEvidence;
|
|
1661
|
+
exports.addReceiptRef = addReceiptRef;
|
|
1662
|
+
exports.addTimelineEntry = addTimelineEntry;
|
|
1663
|
+
exports.computeCommerceSummary = computeCommerceSummary;
|
|
1562
1664
|
exports.correlateByTrace = correlateByTrace;
|
|
1563
1665
|
exports.createAuditEntry = createAuditEntry;
|
|
1564
1666
|
exports.createCaseBundle = createCaseBundle;
|
|
1667
|
+
exports.createCommerceEvidenceBundle = createCommerceEvidenceBundle;
|
|
1565
1668
|
exports.createDisputeBundle = createDisputeBundle;
|
|
1566
1669
|
exports.createJsonlAppender = createJsonlAppender;
|
|
1567
1670
|
exports.filterByDispute = filterByDispute;
|
|
@@ -1581,6 +1684,7 @@ exports.parseJsonl = parseJsonl;
|
|
|
1581
1684
|
exports.parseJsonlLine = parseJsonlLine;
|
|
1582
1685
|
exports.readDisputeBundle = readDisputeBundle;
|
|
1583
1686
|
exports.serializeBundle = serializeBundle;
|
|
1687
|
+
exports.serializeCommerceBundle = serializeCommerceBundle;
|
|
1584
1688
|
exports.serializeReport = serializeReport;
|
|
1585
1689
|
exports.validateAuditEntry = validateAuditEntry;
|
|
1586
1690
|
exports.verifyBundle = verifyBundle;
|