@peac/mappings-acp 0.9.18

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 ADDED
@@ -0,0 +1,23 @@
1
+ # @peac/mappings-acp
2
+
3
+ Agentic Commerce Protocol (ACP) integration for PEAC
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @peac/mappings-acp
9
+ ```
10
+
11
+ ## Documentation
12
+
13
+ See [peacprotocol.org](https://peacprotocol.org) for full documentation.
14
+
15
+ ## License
16
+
17
+ Apache-2.0
18
+
19
+ ---
20
+
21
+ PEAC Protocol is an open source project stewarded by Originary and community contributors.
22
+
23
+ [Originary](https://www.originary.xyz) | [Docs](https://peacprotocol.org) | [GitHub](https://github.com/peacprotocol/peac)
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Agentic Commerce Protocol (ACP) integration
3
+ * Maps ACP checkout events to PEAC receipts
4
+ */
5
+ import type { PaymentEvidence } from '@peac/schema';
6
+ /**
7
+ * ACP Checkout Success Event
8
+ */
9
+ export interface ACPCheckoutSuccess {
10
+ checkout_id: string;
11
+ resource_uri: string;
12
+ total_amount: number;
13
+ currency: string;
14
+ payment_rail: string;
15
+ payment_reference: string;
16
+ customer_id?: string;
17
+ metadata?: Record<string, unknown>;
18
+ }
19
+ /**
20
+ * PEAC Receipt Input (for issue())
21
+ */
22
+ export interface PEACReceiptInput {
23
+ subject_uri: string;
24
+ amt: number;
25
+ cur: string;
26
+ payment: PaymentEvidence;
27
+ }
28
+ /**
29
+ * Convert ACP checkout success event to PEAC receipt input
30
+ *
31
+ * @param event - ACP checkout success event
32
+ * @returns PEAC receipt input ready for issue()
33
+ */
34
+ export declare function fromACPCheckoutSuccess(event: ACPCheckoutSuccess): PEACReceiptInput;
35
+ /**
36
+ * Attach PEAC receipt to ACP response
37
+ *
38
+ * @param response - ACP response object
39
+ * @param receiptJWS - PEAC receipt JWS
40
+ * @returns ACP response with PEAC receipt attached
41
+ */
42
+ export declare function attachReceiptToACPResponse<T extends Record<string, unknown>>(response: T, receiptJWS: string): T & {
43
+ peac_receipt: string;
44
+ };
45
+ /**
46
+ * Extract PEAC receipt from ACP response
47
+ *
48
+ * @param response - ACP response object
49
+ * @returns PEAC receipt JWS or null if not present
50
+ */
51
+ export declare function extractReceiptFromACPResponse(response: Record<string, unknown>): string | null;
52
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,eAAe,CAAC;CAC1B;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,kBAAkB,GAAG,gBAAgB,CAmDlF;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC1E,QAAQ,EAAE,CAAC,EACX,UAAU,EAAE,MAAM,GACjB,CAAC,GAAG;IAAE,YAAY,EAAE,MAAM,CAAA;CAAE,CAK9B;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,IAAI,CAK9F"}
package/dist/index.js ADDED
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ /**
3
+ * Agentic Commerce Protocol (ACP) integration
4
+ * Maps ACP checkout events to PEAC receipts
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.fromACPCheckoutSuccess = fromACPCheckoutSuccess;
8
+ exports.attachReceiptToACPResponse = attachReceiptToACPResponse;
9
+ exports.extractReceiptFromACPResponse = extractReceiptFromACPResponse;
10
+ /**
11
+ * Convert ACP checkout success event to PEAC receipt input
12
+ *
13
+ * @param event - ACP checkout success event
14
+ * @returns PEAC receipt input ready for issue()
15
+ */
16
+ function fromACPCheckoutSuccess(event) {
17
+ // Validate ACP event
18
+ if (!event.checkout_id) {
19
+ throw new Error('ACP checkout event missing checkout_id');
20
+ }
21
+ if (!event.resource_uri || !event.resource_uri.startsWith('https://')) {
22
+ throw new Error('ACP checkout event missing or invalid resource_uri (must be https://)');
23
+ }
24
+ if (typeof event.total_amount !== 'number' || event.total_amount < 0) {
25
+ throw new Error('ACP checkout event invalid total_amount');
26
+ }
27
+ if (!event.currency || !/^[A-Z]{3}$/.test(event.currency)) {
28
+ throw new Error('ACP checkout event invalid currency (must be uppercase ISO 4217)');
29
+ }
30
+ if (!event.payment_rail) {
31
+ throw new Error('ACP checkout event missing payment_rail');
32
+ }
33
+ if (!event.payment_reference) {
34
+ throw new Error('ACP checkout event missing payment_reference');
35
+ }
36
+ // Build payment evidence from ACP event
37
+ const evidence = {};
38
+ // Include ACP metadata in evidence
39
+ if (event.metadata) {
40
+ evidence.acp_metadata = event.metadata;
41
+ }
42
+ if (event.customer_id) {
43
+ evidence.customer_id = event.customer_id;
44
+ }
45
+ if (event.checkout_id) {
46
+ evidence.checkout_id = event.checkout_id;
47
+ }
48
+ const payment = {
49
+ rail: event.payment_rail,
50
+ reference: event.payment_reference,
51
+ amount: event.total_amount,
52
+ currency: event.currency,
53
+ asset: event.currency, // For ACP, asset is typically same as currency
54
+ env: 'live', // Default to live; ACP events should indicate if test
55
+ evidence,
56
+ };
57
+ return {
58
+ subject_uri: event.resource_uri,
59
+ amt: event.total_amount,
60
+ cur: event.currency,
61
+ payment,
62
+ };
63
+ }
64
+ /**
65
+ * Attach PEAC receipt to ACP response
66
+ *
67
+ * @param response - ACP response object
68
+ * @param receiptJWS - PEAC receipt JWS
69
+ * @returns ACP response with PEAC receipt attached
70
+ */
71
+ function attachReceiptToACPResponse(response, receiptJWS) {
72
+ return {
73
+ ...response,
74
+ peac_receipt: receiptJWS,
75
+ };
76
+ }
77
+ /**
78
+ * Extract PEAC receipt from ACP response
79
+ *
80
+ * @param response - ACP response object
81
+ * @returns PEAC receipt JWS or null if not present
82
+ */
83
+ function extractReceiptFromACPResponse(response) {
84
+ if (typeof response.peac_receipt === 'string') {
85
+ return response.peac_receipt;
86
+ }
87
+ return null;
88
+ }
89
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAkCH,wDAmDC;AASD,gEAQC;AAQD,sEAKC;AAvFD;;;;;GAKG;AACH,SAAgB,sBAAsB,CAAC,KAAyB;IAC9D,qBAAqB;IACrB,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC5D,CAAC;IACD,IAAI,CAAC,KAAK,CAAC,YAAY,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QACtE,MAAM,IAAI,KAAK,CAAC,uEAAuE,CAAC,CAAC;IAC3F,CAAC;IACD,IAAI,OAAO,KAAK,CAAC,YAAY,KAAK,QAAQ,IAAI,KAAK,CAAC,YAAY,GAAG,CAAC,EAAE,CAAC;QACrE,MAAM,IA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AAE,KAAK,CAAC,QAAQ;QACnB,OAAO;KACR,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,0BAA0B,CACxC,QAAW,EACX,UAAkB;IAElB,OAAO;QACL,GAAG,QAAQ;QACX,YAAY,EAAE,UAAU;KACzB,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAgB,6BAA6B,CAAC,QAAiC;IAC7E,IAAI,OAAO,QAAQ,CAAC,YAAY,KAAK,QAAQ,EAAE,CAAC;QAC9C,OAAO,QAAQ,CAAC,YAAY,CAAC;IAC/B,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@peac/mappings-acp",
3
+ "version": "0.9.18",
4
+ "description": "Agentic Commerce Protocol (ACP) integration for PEAC",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/peacprotocol/peac.git",
10
+ "directory": "packages/mappings/acp"
11
+ },
12
+ "author": "jithinraj <7850727+jithinraj@users.noreply.github.com>",
13
+ "license": "Apache-2.0",
14
+ "bugs": {
15
+ "url": "https://github.com/peacprotocol/peac/issues"
16
+ },
17
+ "homepage": "https://github.com/peacprotocol/peac#readme",
18
+ "files": [
19
+ "dist",
20
+ "README.md"
21
+ ],
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "scripts": {
26
+ "build": "tsc",
27
+ "test": "vitest run",
28
+ "test:watch": "vitest",
29
+ "clean": "rm -rf dist"
30
+ },
31
+ "dependencies": {
32
+ "@peac/schema": "workspace:*",
33
+ "@peac/protocol": "workspace:*"
34
+ },
35
+ "devDependencies": {
36
+ "@peac/crypto": "workspace:*",
37
+ "@types/node": "^20.10.0",
38
+ "typescript": "^5.3.3",
39
+ "vitest": "^1.1.0"
40
+ }
41
+ }