@financedistrict/medusa-plugin-agentic-commerce 0.1.0
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/.medusa/server/src/admin/index.js +22 -0
- package/.medusa/server/src/admin/index.mjs +23 -0
- package/.medusa/server/src/api/acp/checkout_sessions/[id]/cancel/route.d.ts +3 -0
- package/.medusa/server/src/api/acp/checkout_sessions/[id]/cancel/route.d.ts.map +1 -0
- package/.medusa/server/src/api/acp/checkout_sessions/[id]/cancel/route.js +39 -0
- package/.medusa/server/src/api/acp/checkout_sessions/[id]/cancel/route.js.map +1 -0
- package/.medusa/server/src/api/acp/checkout_sessions/[id]/complete/route.d.ts +3 -0
- package/.medusa/server/src/api/acp/checkout_sessions/[id]/complete/route.d.ts.map +1 -0
- package/.medusa/server/src/api/acp/checkout_sessions/[id]/complete/route.js +73 -0
- package/.medusa/server/src/api/acp/checkout_sessions/[id]/complete/route.js.map +1 -0
- package/.medusa/server/src/api/acp/checkout_sessions/[id]/route.d.ts +4 -0
- package/.medusa/server/src/api/acp/checkout_sessions/[id]/route.d.ts.map +1 -0
- package/.medusa/server/src/api/acp/checkout_sessions/[id]/route.js +107 -0
- package/.medusa/server/src/api/acp/checkout_sessions/[id]/route.js.map +1 -0
- package/.medusa/server/src/api/acp/checkout_sessions/route.d.ts +3 -0
- package/.medusa/server/src/api/acp/checkout_sessions/route.d.ts.map +1 -0
- package/.medusa/server/src/api/acp/checkout_sessions/route.js +70 -0
- package/.medusa/server/src/api/acp/checkout_sessions/route.js.map +1 -0
- package/.medusa/server/src/api/acp/orders/[id]/route.d.ts +3 -0
- package/.medusa/server/src/api/acp/orders/[id]/route.d.ts.map +1 -0
- package/.medusa/server/src/api/acp/orders/[id]/route.js +37 -0
- package/.medusa/server/src/api/acp/orders/[id]/route.js.map +1 -0
- package/.medusa/server/src/api/acp/product-feed/route.d.ts +3 -0
- package/.medusa/server/src/api/acp/product-feed/route.d.ts.map +1 -0
- package/.medusa/server/src/api/acp/product-feed/route.js +57 -0
- package/.medusa/server/src/api/acp/product-feed/route.js.map +1 -0
- package/.medusa/server/src/api/middleware/idempotency.d.ts +21 -0
- package/.medusa/server/src/api/middleware/idempotency.d.ts.map +1 -0
- package/.medusa/server/src/api/middleware/idempotency.js +184 -0
- package/.medusa/server/src/api/middleware/idempotency.js.map +1 -0
- package/.medusa/server/src/api/middlewares.d.ts +3 -0
- package/.medusa/server/src/api/middlewares.d.ts.map +1 -0
- package/.medusa/server/src/api/middlewares.js +309 -0
- package/.medusa/server/src/api/middlewares.js.map +1 -0
- package/.medusa/server/src/api/ucp/carts/[id]/cancel/route.d.ts +3 -0
- package/.medusa/server/src/api/ucp/carts/[id]/cancel/route.d.ts.map +1 -0
- package/.medusa/server/src/api/ucp/carts/[id]/cancel/route.js +39 -0
- package/.medusa/server/src/api/ucp/carts/[id]/cancel/route.js.map +1 -0
- package/.medusa/server/src/api/ucp/carts/[id]/route.d.ts +4 -0
- package/.medusa/server/src/api/ucp/carts/[id]/route.d.ts.map +1 -0
- package/.medusa/server/src/api/ucp/carts/[id]/route.js +96 -0
- package/.medusa/server/src/api/ucp/carts/[id]/route.js.map +1 -0
- package/.medusa/server/src/api/ucp/carts/route.d.ts +3 -0
- package/.medusa/server/src/api/ucp/carts/route.d.ts.map +1 -0
- package/.medusa/server/src/api/ucp/carts/route.js +52 -0
- package/.medusa/server/src/api/ucp/carts/route.js.map +1 -0
- package/.medusa/server/src/api/ucp/catalog/lookup/route.d.ts +3 -0
- package/.medusa/server/src/api/ucp/catalog/lookup/route.d.ts.map +1 -0
- package/.medusa/server/src/api/ucp/catalog/lookup/route.js +66 -0
- package/.medusa/server/src/api/ucp/catalog/lookup/route.js.map +1 -0
- package/.medusa/server/src/api/ucp/catalog/search/route.d.ts +3 -0
- package/.medusa/server/src/api/ucp/catalog/search/route.d.ts.map +1 -0
- package/.medusa/server/src/api/ucp/catalog/search/route.js +84 -0
- package/.medusa/server/src/api/ucp/catalog/search/route.js.map +1 -0
- package/.medusa/server/src/api/ucp/checkout-sessions/[id]/cancel/route.d.ts +3 -0
- package/.medusa/server/src/api/ucp/checkout-sessions/[id]/cancel/route.d.ts.map +1 -0
- package/.medusa/server/src/api/ucp/checkout-sessions/[id]/cancel/route.js +40 -0
- package/.medusa/server/src/api/ucp/checkout-sessions/[id]/cancel/route.js.map +1 -0
- package/.medusa/server/src/api/ucp/checkout-sessions/[id]/complete/route.d.ts +3 -0
- package/.medusa/server/src/api/ucp/checkout-sessions/[id]/complete/route.d.ts.map +1 -0
- package/.medusa/server/src/api/ucp/checkout-sessions/[id]/complete/route.js +77 -0
- package/.medusa/server/src/api/ucp/checkout-sessions/[id]/complete/route.js.map +1 -0
- package/.medusa/server/src/api/ucp/checkout-sessions/[id]/route.d.ts +4 -0
- package/.medusa/server/src/api/ucp/checkout-sessions/[id]/route.d.ts.map +1 -0
- package/.medusa/server/src/api/ucp/checkout-sessions/[id]/route.js +110 -0
- package/.medusa/server/src/api/ucp/checkout-sessions/[id]/route.js.map +1 -0
- package/.medusa/server/src/api/ucp/checkout-sessions/route.d.ts +3 -0
- package/.medusa/server/src/api/ucp/checkout-sessions/route.d.ts.map +1 -0
- package/.medusa/server/src/api/ucp/checkout-sessions/route.js +71 -0
- package/.medusa/server/src/api/ucp/checkout-sessions/route.js.map +1 -0
- package/.medusa/server/src/api/ucp/orders/[id]/route.d.ts +3 -0
- package/.medusa/server/src/api/ucp/orders/[id]/route.d.ts.map +1 -0
- package/.medusa/server/src/api/ucp/orders/[id]/route.js +38 -0
- package/.medusa/server/src/api/ucp/orders/[id]/route.js.map +1 -0
- package/.medusa/server/src/api/validation-schemas.d.ts +992 -0
- package/.medusa/server/src/api/validation-schemas.d.ts.map +1 -0
- package/.medusa/server/src/api/validation-schemas.js +200 -0
- package/.medusa/server/src/api/validation-schemas.js.map +1 -0
- package/.medusa/server/src/api/well-known/acp.json/route.d.ts +3 -0
- package/.medusa/server/src/api/well-known/acp.json/route.d.ts.map +1 -0
- package/.medusa/server/src/api/well-known/acp.json/route.js +44 -0
- package/.medusa/server/src/api/well-known/acp.json/route.js.map +1 -0
- package/.medusa/server/src/api/well-known/ucp/route.d.ts +3 -0
- package/.medusa/server/src/api/well-known/ucp/route.d.ts.map +1 -0
- package/.medusa/server/src/api/well-known/ucp/route.js +34 -0
- package/.medusa/server/src/api/well-known/ucp/route.js.map +1 -0
- package/.medusa/server/src/index.d.ts +51 -0
- package/.medusa/server/src/index.d.ts.map +1 -0
- package/.medusa/server/src/index.js +81 -0
- package/.medusa/server/src/index.js.map +1 -0
- package/.medusa/server/src/jobs/sync-product-feed.d.ts +16 -0
- package/.medusa/server/src/jobs/sync-product-feed.d.ts.map +1 -0
- package/.medusa/server/src/jobs/sync-product-feed.js +78 -0
- package/.medusa/server/src/jobs/sync-product-feed.js.map +1 -0
- package/.medusa/server/src/lib/address-translator.d.ts +40 -0
- package/.medusa/server/src/lib/address-translator.d.ts.map +1 -0
- package/.medusa/server/src/lib/address-translator.js +79 -0
- package/.medusa/server/src/lib/address-translator.js.map +1 -0
- package/.medusa/server/src/lib/cart-fields.d.ts +10 -0
- package/.medusa/server/src/lib/cart-fields.d.ts.map +1 -0
- package/.medusa/server/src/lib/cart-fields.js +42 -0
- package/.medusa/server/src/lib/cart-fields.js.map +1 -0
- package/.medusa/server/src/lib/error-formatters.d.ts +38 -0
- package/.medusa/server/src/lib/error-formatters.d.ts.map +1 -0
- package/.medusa/server/src/lib/error-formatters.js +42 -0
- package/.medusa/server/src/lib/error-formatters.js.map +1 -0
- package/.medusa/server/src/lib/formatters/acp.d.ts +108 -0
- package/.medusa/server/src/lib/formatters/acp.d.ts.map +1 -0
- package/.medusa/server/src/lib/formatters/acp.js +158 -0
- package/.medusa/server/src/lib/formatters/acp.js.map +1 -0
- package/.medusa/server/src/lib/formatters/types.d.ts +19 -0
- package/.medusa/server/src/lib/formatters/types.d.ts.map +1 -0
- package/.medusa/server/src/lib/formatters/types.js +15 -0
- package/.medusa/server/src/lib/formatters/types.js.map +1 -0
- package/.medusa/server/src/lib/formatters/ucp.d.ts +123 -0
- package/.medusa/server/src/lib/formatters/ucp.d.ts.map +1 -0
- package/.medusa/server/src/lib/formatters/ucp.js +226 -0
- package/.medusa/server/src/lib/formatters/ucp.js.map +1 -0
- package/.medusa/server/src/lib/order-fields.d.ts +6 -0
- package/.medusa/server/src/lib/order-fields.d.ts.map +1 -0
- package/.medusa/server/src/lib/order-fields.js +29 -0
- package/.medusa/server/src/lib/order-fields.js.map +1 -0
- package/.medusa/server/src/lib/payment-handler-registry.d.ts +58 -0
- package/.medusa/server/src/lib/payment-handler-registry.d.ts.map +1 -0
- package/.medusa/server/src/lib/payment-handler-registry.js +150 -0
- package/.medusa/server/src/lib/payment-handler-registry.js.map +1 -0
- package/.medusa/server/src/lib/public-url.d.ts +12 -0
- package/.medusa/server/src/lib/public-url.d.ts.map +1 -0
- package/.medusa/server/src/lib/public-url.js +14 -0
- package/.medusa/server/src/lib/public-url.js.map +1 -0
- package/.medusa/server/src/lib/status-maps.d.ts +7 -0
- package/.medusa/server/src/lib/status-maps.d.ts.map +1 -0
- package/.medusa/server/src/lib/status-maps.js +43 -0
- package/.medusa/server/src/lib/status-maps.js.map +1 -0
- package/.medusa/server/src/modules/agentic-commerce/index.d.ts +7 -0
- package/.medusa/server/src/modules/agentic-commerce/index.d.ts.map +1 -0
- package/.medusa/server/src/modules/agentic-commerce/index.js +13 -0
- package/.medusa/server/src/modules/agentic-commerce/index.js.map +1 -0
- package/.medusa/server/src/modules/agentic-commerce/service.d.ts +294 -0
- package/.medusa/server/src/modules/agentic-commerce/service.d.ts.map +1 -0
- package/.medusa/server/src/modules/agentic-commerce/service.js +206 -0
- package/.medusa/server/src/modules/agentic-commerce/service.js.map +1 -0
- package/.medusa/server/src/subscribers/order-placed-webhook.d.ts +16 -0
- package/.medusa/server/src/subscribers/order-placed-webhook.d.ts.map +1 -0
- package/.medusa/server/src/subscribers/order-placed-webhook.js +83 -0
- package/.medusa/server/src/subscribers/order-placed-webhook.js.map +1 -0
- package/.medusa/server/src/types/payment-handler-adapter.d.ts +92 -0
- package/.medusa/server/src/types/payment-handler-adapter.d.ts.map +1 -0
- package/.medusa/server/src/types/payment-handler-adapter.js +34 -0
- package/.medusa/server/src/types/payment-handler-adapter.js.map +1 -0
- package/.medusa/server/src/workflows/cancel-checkout-session.d.ts +9 -0
- package/.medusa/server/src/workflows/cancel-checkout-session.d.ts.map +1 -0
- package/.medusa/server/src/workflows/cancel-checkout-session.js +53 -0
- package/.medusa/server/src/workflows/cancel-checkout-session.js.map +1 -0
- package/.medusa/server/src/workflows/complete-checkout-session.d.ts +23 -0
- package/.medusa/server/src/workflows/complete-checkout-session.d.ts.map +1 -0
- package/.medusa/server/src/workflows/complete-checkout-session.js +44 -0
- package/.medusa/server/src/workflows/complete-checkout-session.js.map +1 -0
- package/.medusa/server/src/workflows/create-checkout-session.d.ts +20 -0
- package/.medusa/server/src/workflows/create-checkout-session.d.ts.map +1 -0
- package/.medusa/server/src/workflows/create-checkout-session.js +65 -0
- package/.medusa/server/src/workflows/create-checkout-session.js.map +1 -0
- package/.medusa/server/src/workflows/index.d.ts +5 -0
- package/.medusa/server/src/workflows/index.d.ts.map +1 -0
- package/.medusa/server/src/workflows/index.js +15 -0
- package/.medusa/server/src/workflows/index.js.map +1 -0
- package/.medusa/server/src/workflows/steps/ensure-shipping-method.d.ts +10 -0
- package/.medusa/server/src/workflows/steps/ensure-shipping-method.d.ts.map +1 -0
- package/.medusa/server/src/workflows/steps/ensure-shipping-method.js +50 -0
- package/.medusa/server/src/workflows/steps/ensure-shipping-method.js.map +1 -0
- package/.medusa/server/src/workflows/steps/setup-payment.d.ts +21 -0
- package/.medusa/server/src/workflows/steps/setup-payment.d.ts.map +1 -0
- package/.medusa/server/src/workflows/steps/setup-payment.js +88 -0
- package/.medusa/server/src/workflows/steps/setup-payment.js.map +1 -0
- package/.medusa/server/src/workflows/steps/validate-checkout-prerequisites.d.ts +9 -0
- package/.medusa/server/src/workflows/steps/validate-checkout-prerequisites.d.ts.map +1 -0
- package/.medusa/server/src/workflows/steps/validate-checkout-prerequisites.js +34 -0
- package/.medusa/server/src/workflows/steps/validate-checkout-prerequisites.js.map +1 -0
- package/.medusa/server/src/workflows/update-checkout-session.d.ts +22 -0
- package/.medusa/server/src/workflows/update-checkout-session.d.ts.map +1 -0
- package/.medusa/server/src/workflows/update-checkout-session.js +103 -0
- package/.medusa/server/src/workflows/update-checkout-session.js.map +1 -0
- package/LICENSE +21 -0
- package/README.md +356 -0
- package/package.json +59 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public-url.js","sourceRoot":"","sources":["../../../../src/lib/public-url.ts"],"names":[],"mappings":";;AAOA,4CAEC;AATD;;;;;;GAMG;AACH,SAAgB,gBAAgB,CAAC,GAAgE;IAC/F,OAAO,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,GAAG,GAAG,CAAC,QAAQ,MAAM,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAA;AAC7E,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Protocol-specific status enum mapping.
|
|
3
|
+
* Maps from Medusa cart state to each protocol's required status values.
|
|
4
|
+
*/
|
|
5
|
+
export declare function resolveAcpStatus(cart: any): string;
|
|
6
|
+
export declare function resolveUcpStatus(cart: any): string;
|
|
7
|
+
//# sourceMappingURL=status-maps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"status-maps.d.ts","sourceRoot":"","sources":["../../../../src/lib/status-maps.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,CAalD;AAKD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,CAMlD"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Protocol-specific status enum mapping.
|
|
4
|
+
* Maps from Medusa cart state to each protocol's required status values.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.resolveAcpStatus = resolveAcpStatus;
|
|
8
|
+
exports.resolveUcpStatus = resolveUcpStatus;
|
|
9
|
+
// --- ACP Status ---
|
|
10
|
+
// Spec values: incomplete, not_ready_for_payment, ready_for_payment, completed, canceled
|
|
11
|
+
function resolveAcpStatus(cart) {
|
|
12
|
+
// Canceled (via metadata flag)
|
|
13
|
+
if (cart.metadata?.checkout_session_canceled)
|
|
14
|
+
return "canceled";
|
|
15
|
+
// Completed
|
|
16
|
+
if (cart.completed_at)
|
|
17
|
+
return "completed";
|
|
18
|
+
// Payment authorized -> still ready_for_payment in ACP terms
|
|
19
|
+
if (cart.payment_collection?.status === "authorized")
|
|
20
|
+
return "ready_for_payment";
|
|
21
|
+
// Has shipping + address -> ready
|
|
22
|
+
if (cart.shipping_methods?.length > 0 && cart.shipping_address)
|
|
23
|
+
return "ready_for_payment";
|
|
24
|
+
// Has items but missing requirements
|
|
25
|
+
if (cart.items?.length > 0)
|
|
26
|
+
return "not_ready_for_payment";
|
|
27
|
+
// Empty cart
|
|
28
|
+
return "incomplete";
|
|
29
|
+
}
|
|
30
|
+
// --- UCP Status ---
|
|
31
|
+
// Spec values: incomplete, ready_for_complete, completed, canceled
|
|
32
|
+
function resolveUcpStatus(cart) {
|
|
33
|
+
if (cart.metadata?.checkout_session_canceled)
|
|
34
|
+
return "canceled";
|
|
35
|
+
if (cart.completed_at)
|
|
36
|
+
return "completed";
|
|
37
|
+
if (cart.payment_collection?.status === "authorized")
|
|
38
|
+
return "ready_for_complete";
|
|
39
|
+
if (cart.shipping_methods?.length > 0 && cart.shipping_address)
|
|
40
|
+
return "ready_for_complete";
|
|
41
|
+
return "incomplete";
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=status-maps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"status-maps.js","sourceRoot":"","sources":["../../../../src/lib/status-maps.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAKH,4CAaC;AAKD,4CAMC;AA3BD,qBAAqB;AACrB,yFAAyF;AAEzF,SAAgB,gBAAgB,CAAC,IAAS;IACxC,+BAA+B;IAC/B,IAAI,IAAI,CAAC,QAAQ,EAAE,yBAAyB;QAAE,OAAO,UAAU,CAAA;IAC/D,YAAY;IACZ,IAAI,IAAI,CAAC,YAAY;QAAE,OAAO,WAAW,CAAA;IACzC,6DAA6D;IAC7D,IAAI,IAAI,CAAC,kBAAkB,EAAE,MAAM,KAAK,YAAY;QAAE,OAAO,mBAAmB,CAAA;IAChF,kCAAkC;IAClC,IAAI,IAAI,CAAC,gBAAgB,EAAE,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,gBAAgB;QAAE,OAAO,mBAAmB,CAAA;IAC1F,qCAAqC;IACrC,IAAI,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC;QAAE,OAAO,uBAAuB,CAAA;IAC1D,aAAa;IACb,OAAO,YAAY,CAAA;AACrB,CAAC;AAED,qBAAqB;AACrB,mEAAmE;AAEnE,SAAgB,gBAAgB,CAAC,IAAS;IACxC,IAAI,IAAI,CAAC,QAAQ,EAAE,yBAAyB;QAAE,OAAO,UAAU,CAAA;IAC/D,IAAI,IAAI,CAAC,YAAY;QAAE,OAAO,WAAW,CAAA;IACzC,IAAI,IAAI,CAAC,kBAAkB,EAAE,MAAM,KAAK,YAAY;QAAE,OAAO,oBAAoB,CAAA;IACjF,IAAI,IAAI,CAAC,gBAAgB,EAAE,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,gBAAgB;QAAE,OAAO,oBAAoB,CAAA;IAC3F,OAAO,YAAY,CAAA;AACrB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import AgenticCommerceService from "./service";
|
|
2
|
+
export declare const AGENTIC_COMMERCE_MODULE = "agenticCommerce";
|
|
3
|
+
declare const _default: import("@medusajs/types").ModuleExports<typeof AgenticCommerceService> & {
|
|
4
|
+
linkable: Record<string, any>;
|
|
5
|
+
};
|
|
6
|
+
export default _default;
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/modules/agentic-commerce/index.ts"],"names":[],"mappings":"AACA,OAAO,sBAAsB,MAAM,WAAW,CAAA;AAE9C,eAAO,MAAM,uBAAuB,oBAAoB,CAAA;;;;AAExD,wBAEE"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AGENTIC_COMMERCE_MODULE = void 0;
|
|
7
|
+
const utils_1 = require("@medusajs/framework/utils");
|
|
8
|
+
const service_1 = __importDefault(require("./service"));
|
|
9
|
+
exports.AGENTIC_COMMERCE_MODULE = "agenticCommerce";
|
|
10
|
+
exports.default = (0, utils_1.Module)(exports.AGENTIC_COMMERCE_MODULE, {
|
|
11
|
+
service: service_1.default,
|
|
12
|
+
});
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/modules/agentic-commerce/index.ts"],"names":[],"mappings":";;;;;;AAAA,qDAAkD;AAClD,wDAA8C;AAEjC,QAAA,uBAAuB,GAAG,iBAAiB,CAAA;AAExD,kBAAe,IAAA,cAAM,EAAC,+BAAuB,EAAE;IAC7C,OAAO,EAAE,iBAAsB;CAChC,CAAC,CAAA"}
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agentic Commerce Service
|
|
3
|
+
*
|
|
4
|
+
* Configuration holder and facade for the agentic commerce plugin.
|
|
5
|
+
* Resolved from the Medusa container as "agenticCommerce".
|
|
6
|
+
*
|
|
7
|
+
* Responsibilities:
|
|
8
|
+
* - Store configuration (name, URL, versions)
|
|
9
|
+
* - Auth: API key validation, HMAC signing/verification
|
|
10
|
+
* - Formatting: delegates to protocol-specific formatters (src/lib/formatters/)
|
|
11
|
+
* - Payment: delegates to PaymentHandlerRegistry with pluggable adapters
|
|
12
|
+
* - Webhooks: event dispatch to registered URLs
|
|
13
|
+
*/
|
|
14
|
+
import { PaymentHandlerRegistry } from "../../lib/payment-handler-registry";
|
|
15
|
+
export type AgenticCommerceOptions = {
|
|
16
|
+
signatureKey?: string;
|
|
17
|
+
storefront_url?: string;
|
|
18
|
+
store_name?: string;
|
|
19
|
+
store_description?: string;
|
|
20
|
+
api_key?: string;
|
|
21
|
+
payment_provider_id?: string;
|
|
22
|
+
ucp_version?: string;
|
|
23
|
+
acp_version?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Container service names of PaymentHandlerAdapter implementations.
|
|
26
|
+
* Each name must match a Medusa module registered by a payment handler plugin.
|
|
27
|
+
*
|
|
28
|
+
* Example: ["prismPaymentHandler"]
|
|
29
|
+
*
|
|
30
|
+
* The referenced modules must implement the PaymentHandlerAdapter interface from
|
|
31
|
+
* @financedistrict/medusa-plugin-agentic-commerce.
|
|
32
|
+
*/
|
|
33
|
+
payment_handler_adapters?: string[];
|
|
34
|
+
};
|
|
35
|
+
export default class AgenticCommerceService {
|
|
36
|
+
private signatureKey;
|
|
37
|
+
private storefrontUrl;
|
|
38
|
+
private storeName;
|
|
39
|
+
private storeDescription;
|
|
40
|
+
private apiKey;
|
|
41
|
+
private paymentProviderId;
|
|
42
|
+
private ucpVersion;
|
|
43
|
+
private acpVersion;
|
|
44
|
+
private paymentHandlerRegistry;
|
|
45
|
+
private ctx;
|
|
46
|
+
private adapterNames;
|
|
47
|
+
private adaptersResolved;
|
|
48
|
+
constructor(_container: Record<string, unknown>, options?: AgenticCommerceOptions);
|
|
49
|
+
/**
|
|
50
|
+
* Resolve payment handler adapters from the request-scoped Medusa container.
|
|
51
|
+
*
|
|
52
|
+
* Module-scoped containers (passed to the constructor) cannot access other
|
|
53
|
+
* top-level modules. The request-scoped container (req.scope) has access to
|
|
54
|
+
* everything, so callers pass it in at request time.
|
|
55
|
+
*
|
|
56
|
+
* Idempotent: once adapters are successfully resolved, subsequent calls are
|
|
57
|
+
* no-ops. If the first attempt fails (zero adapters), retries on next call.
|
|
58
|
+
*/
|
|
59
|
+
resolveAdapters(scope: {
|
|
60
|
+
resolve: (name: string) => unknown;
|
|
61
|
+
}): void;
|
|
62
|
+
signPayload(payload: string): string;
|
|
63
|
+
verifySignature(payload: string, signature: string): boolean;
|
|
64
|
+
validateApiKey(key: string): boolean;
|
|
65
|
+
formatAcpCheckoutSession(cart: any, baseUrl: string): {
|
|
66
|
+
id: any;
|
|
67
|
+
status: string;
|
|
68
|
+
currency: any;
|
|
69
|
+
capabilities: {
|
|
70
|
+
payment: {
|
|
71
|
+
handlers: unknown[];
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
line_items: any;
|
|
75
|
+
totals: {
|
|
76
|
+
type: string;
|
|
77
|
+
display_text: string;
|
|
78
|
+
amount: number;
|
|
79
|
+
}[];
|
|
80
|
+
fulfillment_details: {
|
|
81
|
+
name: string | undefined;
|
|
82
|
+
email: any;
|
|
83
|
+
phone_number: any;
|
|
84
|
+
address: import("../../lib/address-translator").AcpAddress;
|
|
85
|
+
} | null;
|
|
86
|
+
fulfillment_options: any;
|
|
87
|
+
messages: {
|
|
88
|
+
type: "info";
|
|
89
|
+
content_type: string;
|
|
90
|
+
content: string;
|
|
91
|
+
}[];
|
|
92
|
+
links: {
|
|
93
|
+
type: string;
|
|
94
|
+
url: string;
|
|
95
|
+
}[];
|
|
96
|
+
};
|
|
97
|
+
formatAcpCompleteResponse(cart: any, baseUrl: string, orderId: string | null, cartId: string): {
|
|
98
|
+
status: string;
|
|
99
|
+
order: {
|
|
100
|
+
id: string;
|
|
101
|
+
checkout_session_id: string;
|
|
102
|
+
permalink_url: string;
|
|
103
|
+
} | null;
|
|
104
|
+
id: any;
|
|
105
|
+
currency: any;
|
|
106
|
+
capabilities: {
|
|
107
|
+
payment: {
|
|
108
|
+
handlers: unknown[];
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
line_items: any;
|
|
112
|
+
totals: {
|
|
113
|
+
type: string;
|
|
114
|
+
display_text: string;
|
|
115
|
+
amount: number;
|
|
116
|
+
}[];
|
|
117
|
+
fulfillment_details: {
|
|
118
|
+
name: string | undefined;
|
|
119
|
+
email: any;
|
|
120
|
+
phone_number: any;
|
|
121
|
+
address: import("../../lib/address-translator").AcpAddress;
|
|
122
|
+
} | null;
|
|
123
|
+
fulfillment_options: any;
|
|
124
|
+
messages: {
|
|
125
|
+
type: "info";
|
|
126
|
+
content_type: string;
|
|
127
|
+
content: string;
|
|
128
|
+
}[];
|
|
129
|
+
links: {
|
|
130
|
+
type: string;
|
|
131
|
+
url: string;
|
|
132
|
+
}[];
|
|
133
|
+
};
|
|
134
|
+
formatAcpOrder(order: any, baseUrl: string): {
|
|
135
|
+
id: any;
|
|
136
|
+
display_id: any;
|
|
137
|
+
checkout_session_id: any;
|
|
138
|
+
permalink_url: string;
|
|
139
|
+
status: any;
|
|
140
|
+
currency: any;
|
|
141
|
+
email: any;
|
|
142
|
+
line_items: any;
|
|
143
|
+
fulfillment_details: {
|
|
144
|
+
name: string | undefined;
|
|
145
|
+
email: any;
|
|
146
|
+
address: import("../../lib/address-translator").AcpAddress;
|
|
147
|
+
} | null;
|
|
148
|
+
totals: {
|
|
149
|
+
type: string;
|
|
150
|
+
display_text: string;
|
|
151
|
+
amount: number;
|
|
152
|
+
}[];
|
|
153
|
+
created_at: any;
|
|
154
|
+
updated_at: any;
|
|
155
|
+
messages: {
|
|
156
|
+
type: string;
|
|
157
|
+
content_type: string;
|
|
158
|
+
content: string;
|
|
159
|
+
}[];
|
|
160
|
+
links: {
|
|
161
|
+
type: string;
|
|
162
|
+
url: string;
|
|
163
|
+
}[];
|
|
164
|
+
};
|
|
165
|
+
formatUcpCheckoutSession(cart: any, baseUrl: string): {
|
|
166
|
+
ucp: Record<string, unknown>;
|
|
167
|
+
id: any;
|
|
168
|
+
status: string;
|
|
169
|
+
currency: any;
|
|
170
|
+
email: any;
|
|
171
|
+
line_items: {
|
|
172
|
+
id: any;
|
|
173
|
+
item: {
|
|
174
|
+
id: any;
|
|
175
|
+
title: any;
|
|
176
|
+
price: {
|
|
177
|
+
amount: number;
|
|
178
|
+
currency: string;
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
quantity: any;
|
|
182
|
+
totals: {
|
|
183
|
+
type: string;
|
|
184
|
+
amount: number;
|
|
185
|
+
}[];
|
|
186
|
+
}[];
|
|
187
|
+
totals: {
|
|
188
|
+
type: string;
|
|
189
|
+
amount: number;
|
|
190
|
+
}[];
|
|
191
|
+
fulfillment: {
|
|
192
|
+
address: import("../../lib/address-translator").UcpAddress;
|
|
193
|
+
options: any;
|
|
194
|
+
} | null;
|
|
195
|
+
messages: {
|
|
196
|
+
type: "info";
|
|
197
|
+
code: string;
|
|
198
|
+
content: string;
|
|
199
|
+
severity: string;
|
|
200
|
+
}[];
|
|
201
|
+
links: {
|
|
202
|
+
type: string;
|
|
203
|
+
url: string;
|
|
204
|
+
}[];
|
|
205
|
+
};
|
|
206
|
+
formatUcpCart(cart: any, baseUrl: string): {
|
|
207
|
+
ucp: Record<string, unknown>;
|
|
208
|
+
id: any;
|
|
209
|
+
currency: any;
|
|
210
|
+
email: any;
|
|
211
|
+
line_items: {
|
|
212
|
+
id: any;
|
|
213
|
+
item: {
|
|
214
|
+
id: any;
|
|
215
|
+
title: any;
|
|
216
|
+
price: {
|
|
217
|
+
amount: number;
|
|
218
|
+
currency: string;
|
|
219
|
+
};
|
|
220
|
+
};
|
|
221
|
+
quantity: any;
|
|
222
|
+
totals: {
|
|
223
|
+
type: string;
|
|
224
|
+
amount: number;
|
|
225
|
+
}[];
|
|
226
|
+
}[];
|
|
227
|
+
totals: {
|
|
228
|
+
type: string;
|
|
229
|
+
amount: number;
|
|
230
|
+
}[];
|
|
231
|
+
shipping_address: import("../../lib/address-translator").UcpAddress | null;
|
|
232
|
+
links: {
|
|
233
|
+
self: string;
|
|
234
|
+
checkout: string;
|
|
235
|
+
};
|
|
236
|
+
};
|
|
237
|
+
formatUcpProduct(product: any): {
|
|
238
|
+
id: any;
|
|
239
|
+
title: any;
|
|
240
|
+
description: any;
|
|
241
|
+
handle: any;
|
|
242
|
+
categories: any;
|
|
243
|
+
price_range: {
|
|
244
|
+
min: {
|
|
245
|
+
amount: number;
|
|
246
|
+
currency: any;
|
|
247
|
+
};
|
|
248
|
+
max: {
|
|
249
|
+
amount: number;
|
|
250
|
+
currency: any;
|
|
251
|
+
};
|
|
252
|
+
} | null;
|
|
253
|
+
variants: any;
|
|
254
|
+
media: any;
|
|
255
|
+
};
|
|
256
|
+
formatUcpOrder(order: any, baseUrl: string): {
|
|
257
|
+
ucp: Record<string, unknown>;
|
|
258
|
+
id: any;
|
|
259
|
+
display_id: any;
|
|
260
|
+
checkout_id: any;
|
|
261
|
+
permalink_url: string;
|
|
262
|
+
status: any;
|
|
263
|
+
currency: any;
|
|
264
|
+
email: any;
|
|
265
|
+
line_items: any;
|
|
266
|
+
fulfillment: {
|
|
267
|
+
address: import("../../lib/address-translator").UcpAddress;
|
|
268
|
+
} | null;
|
|
269
|
+
totals: {
|
|
270
|
+
type: string;
|
|
271
|
+
amount: number;
|
|
272
|
+
}[];
|
|
273
|
+
created_at: any;
|
|
274
|
+
updated_at: any;
|
|
275
|
+
links: {
|
|
276
|
+
type: string;
|
|
277
|
+
url: string;
|
|
278
|
+
}[];
|
|
279
|
+
};
|
|
280
|
+
getStorefrontUrl(): string;
|
|
281
|
+
getStoreName(): string;
|
|
282
|
+
getStoreDescription(): string;
|
|
283
|
+
getPaymentProviderId(): string;
|
|
284
|
+
getUcpVersion(): string;
|
|
285
|
+
getAcpVersion(): string;
|
|
286
|
+
getPaymentHandlerService(): PaymentHandlerRegistry;
|
|
287
|
+
sendWebhookEvent(params: {
|
|
288
|
+
url: string;
|
|
289
|
+
event_type: string;
|
|
290
|
+
payload: Record<string, unknown>;
|
|
291
|
+
}): Promise<void>;
|
|
292
|
+
sendProductFeed(feedXml: string, regionId: string): Promise<void>;
|
|
293
|
+
}
|
|
294
|
+
//# sourceMappingURL=service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../../../src/modules/agentic-commerce/service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAA;AAM3E,MAAM,MAAM,sBAAsB,GAAG;IACnC,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;;;;;;OAQG;IACH,wBAAwB,CAAC,EAAE,MAAM,EAAE,CAAA;CACpC,CAAA;AAED,MAAM,CAAC,OAAO,OAAO,sBAAsB;IACzC,OAAO,CAAC,YAAY,CAAQ;IAC5B,OAAO,CAAC,aAAa,CAAQ;IAC7B,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,gBAAgB,CAAQ;IAChC,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,iBAAiB,CAAQ;IACjC,OAAO,CAAC,UAAU,CAAQ;IAC1B,OAAO,CAAC,UAAU,CAAQ;IAC1B,OAAO,CAA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,gBAAgB,IAAI,MAAM;IAC1B,YAAY,IAAI,MAAM;IACtB,mBAAmB,IAAI,MAAM;IAC7B,oBAAoB,IAAI,MAAM;IAC9B,aAAa,IAAI,MAAM;IACvB,aAAa,IAAI,MAAM;IACvB,wBAAwB,IAAI,sBAAsB;IAQ5C,gBAAgB,CAAC,MAAM,EAAE;QAC7B,GAAG,EAAE,MAAM,CAAA;QACX,UAAU,EAAE,MAAM,CAAA;QAClB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KACjC,GAAG,OAAO,CAAC,IAAI,CAAC;IA4BX,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGxE"}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Agentic Commerce Service
|
|
4
|
+
*
|
|
5
|
+
* Configuration holder and facade for the agentic commerce plugin.
|
|
6
|
+
* Resolved from the Medusa container as "agenticCommerce".
|
|
7
|
+
*
|
|
8
|
+
* Responsibilities:
|
|
9
|
+
* - Store configuration (name, URL, versions)
|
|
10
|
+
* - Auth: API key validation, HMAC signing/verification
|
|
11
|
+
* - Formatting: delegates to protocol-specific formatters (src/lib/formatters/)
|
|
12
|
+
* - Payment: delegates to PaymentHandlerRegistry with pluggable adapters
|
|
13
|
+
* - Webhooks: event dispatch to registered URLs
|
|
14
|
+
*/
|
|
15
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
18
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
19
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
20
|
+
}
|
|
21
|
+
Object.defineProperty(o, k2, desc);
|
|
22
|
+
}) : (function(o, m, k, k2) {
|
|
23
|
+
if (k2 === undefined) k2 = k;
|
|
24
|
+
o[k2] = m[k];
|
|
25
|
+
}));
|
|
26
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
27
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
28
|
+
}) : function(o, v) {
|
|
29
|
+
o["default"] = v;
|
|
30
|
+
});
|
|
31
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
32
|
+
var ownKeys = function(o) {
|
|
33
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
34
|
+
var ar = [];
|
|
35
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
36
|
+
return ar;
|
|
37
|
+
};
|
|
38
|
+
return ownKeys(o);
|
|
39
|
+
};
|
|
40
|
+
return function (mod) {
|
|
41
|
+
if (mod && mod.__esModule) return mod;
|
|
42
|
+
var result = {};
|
|
43
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
44
|
+
__setModuleDefault(result, mod);
|
|
45
|
+
return result;
|
|
46
|
+
};
|
|
47
|
+
})();
|
|
48
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
49
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
50
|
+
};
|
|
51
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
52
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
53
|
+
const payment_handler_registry_1 = require("../../lib/payment-handler-registry");
|
|
54
|
+
const ucpFormatter = __importStar(require("../../lib/formatters/ucp"));
|
|
55
|
+
const acpFormatter = __importStar(require("../../lib/formatters/acp"));
|
|
56
|
+
class AgenticCommerceService {
|
|
57
|
+
constructor(_container, options = {}) {
|
|
58
|
+
this.adaptersResolved = false;
|
|
59
|
+
this.signatureKey = options.signatureKey || process.env.AGENTIC_COMMERCE_SIGNATURE_KEY || "";
|
|
60
|
+
this.storefrontUrl = options.storefront_url || process.env.STOREFRONT_URL || "http://localhost:8000";
|
|
61
|
+
this.storeName = options.store_name || process.env.AGENTIC_STORE_NAME || "My Store";
|
|
62
|
+
this.storeDescription = options.store_description || process.env.AGENTIC_STORE_DESCRIPTION || "";
|
|
63
|
+
this.apiKey = options.api_key || process.env.AGENTIC_COMMERCE_API_KEY || "";
|
|
64
|
+
this.paymentProviderId = options.payment_provider_id || process.env.AGENTIC_PAYMENT_PROVIDER || "pp_system_default";
|
|
65
|
+
this.ucpVersion = options.ucp_version || "2026-01-11";
|
|
66
|
+
this.acpVersion = options.acp_version || "2026-01-30";
|
|
67
|
+
this.paymentHandlerRegistry = new payment_handler_registry_1.PaymentHandlerRegistry();
|
|
68
|
+
this.adapterNames = options.payment_handler_adapters || [];
|
|
69
|
+
if (this.adapterNames.length === 0) {
|
|
70
|
+
console.info("[agentic-commerce] No payment handler adapters configured. Payment handler discovery will return empty results.");
|
|
71
|
+
}
|
|
72
|
+
// Shared context passed to all formatters
|
|
73
|
+
this.ctx = {
|
|
74
|
+
storeName: this.storeName,
|
|
75
|
+
storefrontUrl: this.storefrontUrl,
|
|
76
|
+
ucpVersion: this.ucpVersion,
|
|
77
|
+
acpVersion: this.acpVersion,
|
|
78
|
+
paymentHandlers: this.paymentHandlerRegistry,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Resolve payment handler adapters from the request-scoped Medusa container.
|
|
83
|
+
*
|
|
84
|
+
* Module-scoped containers (passed to the constructor) cannot access other
|
|
85
|
+
* top-level modules. The request-scoped container (req.scope) has access to
|
|
86
|
+
* everything, so callers pass it in at request time.
|
|
87
|
+
*
|
|
88
|
+
* Idempotent: once adapters are successfully resolved, subsequent calls are
|
|
89
|
+
* no-ops. If the first attempt fails (zero adapters), retries on next call.
|
|
90
|
+
*/
|
|
91
|
+
resolveAdapters(scope) {
|
|
92
|
+
if (this.adaptersResolved && this.paymentHandlerRegistry.getAdapterCount() > 0)
|
|
93
|
+
return;
|
|
94
|
+
if (this.adapterNames.length === 0)
|
|
95
|
+
return;
|
|
96
|
+
this.adaptersResolved = true;
|
|
97
|
+
for (const name of this.adapterNames) {
|
|
98
|
+
try {
|
|
99
|
+
const adapter = scope.resolve(name);
|
|
100
|
+
if (adapter && typeof adapter.getUcpDiscoveryHandlers === "function") {
|
|
101
|
+
this.paymentHandlerRegistry.registerAdapter(adapter);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
console.warn(`[agentic-commerce] Service "${name}" does not implement PaymentHandlerAdapter interface`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
catch (err) {
|
|
108
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
109
|
+
console.warn(`[agentic-commerce] Could not resolve payment handler adapter "${name}": ${message}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (this.adapterNames.length > 0 && this.paymentHandlerRegistry.getAdapterCount() === 0) {
|
|
113
|
+
console.warn("[agentic-commerce] Configured payment handler adapters could not be resolved. Payment discovery will be empty.");
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
// =====================================================
|
|
117
|
+
// Auth
|
|
118
|
+
// =====================================================
|
|
119
|
+
signPayload(payload) {
|
|
120
|
+
return crypto_1.default
|
|
121
|
+
.createHmac("sha256", this.signatureKey)
|
|
122
|
+
.update(payload)
|
|
123
|
+
.digest("hex");
|
|
124
|
+
}
|
|
125
|
+
verifySignature(payload, signature) {
|
|
126
|
+
const expected = this.signPayload(payload);
|
|
127
|
+
try {
|
|
128
|
+
return crypto_1.default.timingSafeEqual(Buffer.from(expected, "hex"), Buffer.from(signature, "hex"));
|
|
129
|
+
}
|
|
130
|
+
catch {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
validateApiKey(key) {
|
|
135
|
+
return key === this.apiKey;
|
|
136
|
+
}
|
|
137
|
+
// =====================================================
|
|
138
|
+
// Formatters — delegate to protocol-specific modules
|
|
139
|
+
// =====================================================
|
|
140
|
+
formatAcpCheckoutSession(cart, baseUrl) {
|
|
141
|
+
return acpFormatter.formatAcpCheckoutSession(this.ctx, cart, baseUrl);
|
|
142
|
+
}
|
|
143
|
+
formatAcpCompleteResponse(cart, baseUrl, orderId, cartId) {
|
|
144
|
+
return acpFormatter.formatAcpCompleteResponse(this.ctx, cart, baseUrl, orderId, cartId);
|
|
145
|
+
}
|
|
146
|
+
formatAcpOrder(order, baseUrl) {
|
|
147
|
+
return acpFormatter.formatAcpOrder(this.ctx, order, baseUrl);
|
|
148
|
+
}
|
|
149
|
+
formatUcpCheckoutSession(cart, baseUrl) {
|
|
150
|
+
return ucpFormatter.formatUcpCheckoutSession(this.ctx, cart, baseUrl);
|
|
151
|
+
}
|
|
152
|
+
formatUcpCart(cart, baseUrl) {
|
|
153
|
+
return ucpFormatter.formatUcpCart(this.ctx, cart, baseUrl);
|
|
154
|
+
}
|
|
155
|
+
formatUcpProduct(product) {
|
|
156
|
+
return ucpFormatter.formatUcpProduct(product);
|
|
157
|
+
}
|
|
158
|
+
formatUcpOrder(order, baseUrl) {
|
|
159
|
+
return ucpFormatter.formatUcpOrder(this.ctx, order, baseUrl);
|
|
160
|
+
}
|
|
161
|
+
// =====================================================
|
|
162
|
+
// Getters
|
|
163
|
+
// =====================================================
|
|
164
|
+
getStorefrontUrl() { return this.storefrontUrl; }
|
|
165
|
+
getStoreName() { return this.storeName; }
|
|
166
|
+
getStoreDescription() { return this.storeDescription; }
|
|
167
|
+
getPaymentProviderId() { return this.paymentProviderId; }
|
|
168
|
+
getUcpVersion() { return this.ucpVersion; }
|
|
169
|
+
getAcpVersion() { return this.acpVersion; }
|
|
170
|
+
getPaymentHandlerService() {
|
|
171
|
+
return this.paymentHandlerRegistry;
|
|
172
|
+
}
|
|
173
|
+
// =====================================================
|
|
174
|
+
// Webhooks
|
|
175
|
+
// =====================================================
|
|
176
|
+
async sendWebhookEvent(params) {
|
|
177
|
+
const body = JSON.stringify({
|
|
178
|
+
type: params.event_type,
|
|
179
|
+
data: params.payload,
|
|
180
|
+
});
|
|
181
|
+
const signature = this.signPayload(body);
|
|
182
|
+
const timestamp = new Date().toISOString();
|
|
183
|
+
try {
|
|
184
|
+
await fetch(params.url, {
|
|
185
|
+
method: "POST",
|
|
186
|
+
headers: {
|
|
187
|
+
"Content-Type": "application/json",
|
|
188
|
+
"Merchant-Signature": signature,
|
|
189
|
+
"Timestamp": timestamp,
|
|
190
|
+
},
|
|
191
|
+
body,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
// Best effort — don't throw on webhook failure
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
// =====================================================
|
|
199
|
+
// Product feed (scheduled job)
|
|
200
|
+
// =====================================================
|
|
201
|
+
async sendProductFeed(feedXml, regionId) {
|
|
202
|
+
console.log(`[agentic-commerce] Product feed generated for region ${regionId} (${feedXml.length} bytes)`);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
exports.default = AgenticCommerceService;
|
|
206
|
+
//# sourceMappingURL=service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../../../../src/modules/agentic-commerce/service.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,oDAA2B;AAC3B,iFAA2E;AAG3E,uEAAwD;AACxD,uEAAwD;AAuBxD,MAAqB,sBAAsB;IAiBzC,YAAY,UAAmC,EAAE,UAAkC,EAAE;QAF7E,qBAAgB,GAAG,KAAK,CAAA;QAG9B,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,8BAA8B,IAAI,EAAE,CAAA;QAC5F,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,uBAAuB,CA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AAC;QAAC,MAAM,CAAC;YACP,+CAA+C;QACjD,CAAC;IACH,CAAC;IAED,wDAAwD;IACxD,+BAA+B;IAC/B,wDAAwD;IAExD,KAAK,CAAC,eAAe,CAAC,OAAe,EAAE,QAAgB;QACrD,OAAO,CAAC,GAAG,CAAC,wDAAwD,QAAQ,KAAK,OAAO,CAAC,MAAM,SAAS,CAAC,CAAA;IAC3G,CAAC;CACF;AA9LD,yCA8LC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { SubscriberArgs, SubscriberConfig } from "@medusajs/framework";
|
|
2
|
+
/**
|
|
3
|
+
* Subscriber that fires when an order is placed.
|
|
4
|
+
* If the originating cart had an `agent_webhook_url` in metadata
|
|
5
|
+
* (set during checkout session creation), we notify the agent.
|
|
6
|
+
*
|
|
7
|
+
* ACP webhook format:
|
|
8
|
+
* - Event type: order_create / order_update
|
|
9
|
+
* - Data: { checkout_session_id, permalink_url, status, refunds[] }
|
|
10
|
+
* - Timestamp in header, not body
|
|
11
|
+
*/
|
|
12
|
+
export default function orderPlacedWebhookHandler({ event, container, }: SubscriberArgs<{
|
|
13
|
+
id: string;
|
|
14
|
+
}>): Promise<void>;
|
|
15
|
+
export declare const config: SubscriberConfig;
|
|
16
|
+
//# sourceMappingURL=order-placed-webhook.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"order-placed-webhook.d.ts","sourceRoot":"","sources":["../../../../src/subscribers/order-placed-webhook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAE3E;;;;;;;;;GASG;AACH,wBAA8B,yBAAyB,CAAC,EACtD,KAAK,EACL,SAAS,GACV,EAAE,cAAc,CAAC;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,CAAC,iBAmEhC;AAED,eAAO,MAAM,MAAM,EAAE,gBAEpB,CAAA"}
|