@reactionary/acp 0.10.41 → 0.10.43

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactionary/acp",
3
- "version": "0.10.41",
3
+ "version": "0.10.43",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "types": "./src/index.d.ts",
@@ -9,8 +9,8 @@
9
9
  "url": "git+https://github.com/Solteq/reactionary.git"
10
10
  },
11
11
  "dependencies": {
12
- "@reactionary/core": "0.10.41",
13
- "@reactionary/feeds": "0.10.41",
12
+ "@reactionary/core": "0.10.43",
13
+ "@reactionary/feeds": "0.10.43",
14
14
  "zod": "4.1.9"
15
15
  },
16
16
  "devDependencies": {
package/src/index.d.ts CHANGED
@@ -1,2 +1,6 @@
1
1
  export * from './lib/acp-schemas.js';
2
2
  export * from './lib/reactionary-acp-server.js';
3
+ export * from './lib/acp-payment-handlers.js';
4
+ export { ReactionaryACPFeedPublisher, createACPFeedPublisherFromConfig, type ACPFeedApiConfig, type ACPFeedPublishResult, type ACPFeedPublishingConfig, type ReactionaryACPFeedPublisherOptions, } from '@reactionary/feeds';
5
+ export * from './lib/acp-webhooks.js';
6
+ export * from './lib/acp-discounts.js';
@@ -0,0 +1,45 @@
1
+ import type { Cart, MonetaryAmount, Result } from '@reactionary/core';
2
+ import * as z from 'zod';
3
+ /** The discount extension, as declared in session `capabilities.extensions`. */
4
+ export declare const ACP_DISCOUNT_EXTENSION: {
5
+ name: string;
6
+ extends: string[];
7
+ };
8
+ export declare const ACPDiscountsRequestSchema: z.ZodObject<{
9
+ codes: z.ZodOptional<z.ZodArray<z.ZodString>>;
10
+ }, z.core.$strip>;
11
+ export declare const ACPRejectedDiscountSchema: z.ZodObject<{
12
+ code: z.ZodString;
13
+ reason: z.ZodString;
14
+ message: z.ZodOptional<z.ZodString>;
15
+ }, z.core.$strip>;
16
+ export type ACPRejectedDiscount = z.infer<typeof ACPRejectedDiscountSchema>;
17
+ /** The cart operations the discount extension needs. */
18
+ export interface ACPDiscountCart {
19
+ applyCouponCode?(payload: unknown): Promise<Result<Cart>>;
20
+ removeCouponCode?(payload: unknown): Promise<Result<Cart>>;
21
+ }
22
+ /**
23
+ * The codes a request submits: `discounts.codes`, else the deprecated
24
+ * `coupons` alias (discount extension §10.1). Undefined leaves the codes
25
+ * unchanged; an empty list clears them.
26
+ */
27
+ export declare function getRequestedDiscountCodes(discounts: z.infer<typeof ACPDiscountsRequestSchema> | undefined, coupons: string[] | undefined): string[] | undefined;
28
+ /**
29
+ * Applies a submitted code set to the cart with replacement semantics:
30
+ * codes no longer submitted are removed, new ones applied. Codes match
31
+ * case-insensitively; a backend that matches exactly is also tried with the
32
+ * upper-cased code (as in the UCP adapter). The backend does not say why a
33
+ * code was rejected, so rejections are `discount_code_invalid`.
34
+ */
35
+ export declare function applyDiscountCodes(cartCapability: ACPDiscountCart, cart: Cart, codes: string[]): Promise<{
36
+ cart: Cart;
37
+ rejected: ACPRejectedDiscount[];
38
+ }>;
39
+ /**
40
+ * The session's `discounts`: submitted codes, the cart's promotions as
41
+ * applied discounts (code-based and automatic), and rejected codes. A sole
42
+ * promotion is attributed the whole discount, allocated to the discounted
43
+ * line items when it is allocated to lines only.
44
+ */
45
+ export declare function toACPDiscounts(cart: Cart, codes: string[], rejected: ACPRejectedDiscount[], toMinorUnits: (amount: MonetaryAmount) => number): Record<string, unknown>;
@@ -0,0 +1,23 @@
1
+ import type { Cache } from '@reactionary/core';
2
+ /** Keys MUST be retained for at least 24 hours (checkout RFC §6.6). */
3
+ export declare const ACP_MIN_IDEMPOTENCY_TTL_SECONDS: number;
4
+ /**
5
+ * ACP idempotency (checkout RFC §6): every POST carries an Idempotency-Key,
6
+ * scoped to the authenticated identity and endpoint. A replay of the same
7
+ * body returns the stored response without re-executing side effects; a
8
+ * different body is a conflict, and a key still being processed is in
9
+ * flight. Server errors are never stored, so a retry runs afresh.
10
+ *
11
+ * The cache offers no atomic insert, so concurrent requests on one instance
12
+ * are additionally serialized in memory; across instances the in-flight
13
+ * marker is best effort.
14
+ */
15
+ export declare class ACPIdempotency {
16
+ private readonly cache;
17
+ private readonly ttlSeconds;
18
+ /** Fingerprints of the requests in flight on this instance, by cache key. */
19
+ private readonly inFlight;
20
+ constructor(cache: Cache, ttlSeconds: number);
21
+ run(request: Request, scope: string, handle: () => Promise<Response>): Promise<Response>;
22
+ private put;
23
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The ACP MCP transport binding: the five checkout tools over JSON-RPC 2.0
3
+ * (Streamable HTTP, JSON responses). Tool calls are dispatched to the REST
4
+ * handlers: `meta` becomes the protocol headers, `id` the path parameter
5
+ * and `payload` the request body; the connection's Authorization applies to
6
+ * every call. Results are the REST response bodies as-is; errors are
7
+ * JSON-RPC -32000 with the ACP Error in `data`.
8
+ */
9
+ export declare class ACPMcpEndpoint {
10
+ private readonly serverInfo;
11
+ /** Handles a REST request, e.g. the ACP server's own fetch. */
12
+ private readonly rest;
13
+ constructor(serverInfo: {
14
+ name: string;
15
+ version: string;
16
+ },
17
+ /** Handles a REST request, e.g. the ACP server's own fetch. */
18
+ rest: (request: Request) => Promise<Response>);
19
+ handle(request: Request, restBaseUrl: string): Promise<Response>;
20
+ private callTool;
21
+ }
@@ -0,0 +1,64 @@
1
+ import type { PaymentMethod } from '@reactionary/core';
2
+ /**
3
+ * A payment handler declaration, as advertised in a checkout session's
4
+ * `capabilities.payment.handlers` (payment handlers RFC §5.1).
5
+ */
6
+ export interface ACPPaymentHandler {
7
+ /** Seller-defined handler id, referenced by `payment_data.handler_id`. */
8
+ id: string;
9
+ /** Handler specification name in reverse-DNS format, e.g. `dev.acp.tokenized.card`. */
10
+ name: string;
11
+ /** Human-readable name for payment UIs, e.g. `Credit Card`. */
12
+ display_name?: string;
13
+ /** Handler specification version, `YYYY-MM-DD`. */
14
+ version: string;
15
+ spec: string;
16
+ requires_delegate_payment: boolean;
17
+ requires_pci_compliance: boolean;
18
+ /** The seller's payment service provider, e.g. `stripe`. */
19
+ psp: string;
20
+ config_schema: string;
21
+ instrument_schemas: string[];
22
+ /** Handler-specific configuration; MUST include `merchant_id` and `psp` (RFC §10). */
23
+ config: ACPPaymentHandlerConfig;
24
+ /** Suggested display order, lower first. Agents may reorder. */
25
+ display_order?: number;
26
+ }
27
+ export interface ACPPaymentHandlerConfig {
28
+ /** The seller's account with the PSP; agents scope delegated tokens to it. */
29
+ merchant_id: string;
30
+ psp: string;
31
+ [key: string]: unknown;
32
+ }
33
+ /**
34
+ * A payment handler the server advertises, and the backend payment method its
35
+ * payments are placed with.
36
+ */
37
+ export interface ACPPaymentHandlerOption {
38
+ handler: ACPPaymentHandler;
39
+ /**
40
+ * The reactionary payment method used for the payment instruction.
41
+ * Defaults to method `card` with the handler's PSP as name and processor.
42
+ */
43
+ paymentMethod?: PaymentMethod['identifier'];
44
+ }
45
+ export interface ACPTokenizedCardHandlerOptions {
46
+ id?: string;
47
+ psp: string;
48
+ merchantId: string;
49
+ displayName?: string;
50
+ acceptedBrands?: string[];
51
+ acceptedFundingTypes?: Array<'credit' | 'debit' | 'prepaid'>;
52
+ supports3ds?: boolean;
53
+ displayOrder?: number;
54
+ paymentMethod?: PaymentMethod['identifier'];
55
+ /** Additional handler configuration, e.g. `merchant_display_name`. */
56
+ config?: Record<string, unknown>;
57
+ }
58
+ /**
59
+ * The reference card handler, `dev.acp.tokenized.card`: delegated payment
60
+ * tokens (SPTs) minted by the seller's PSP for its merchant account.
61
+ */
62
+ export declare function createTokenizedCardHandler(options: ACPTokenizedCardHandlerOptions): ACPPaymentHandlerOption;
63
+ /** The backend payment method a handler's payments are placed with. */
64
+ export declare function getHandlerPaymentMethod(option: ACPPaymentHandlerOption): PaymentMethod['identifier'];