@reactionary/acp 0.10.31 → 0.10.32

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 CHANGED
@@ -19,6 +19,10 @@ It also serves a readiness document from `GET` / `HEAD`.
19
19
 
20
20
  If the adapter is mounted under `/acp`, both `/checkout_sessions/...` and `/acp/checkout_sessions/...` paths are understood. Set `basePath` when mounting somewhere else.
21
21
 
22
+ ## Discovery
23
+
24
+ `GET /.well-known/acp.json` (alias `/.well-known/acp`) serves the ACP discovery document with `Cache-Control: public, max-age=3600`. It advertises the `checkout` service, plus `feeds` when `productFeed` is configured. `api_base_url` defaults to the request origin plus `basePath` (default `/acp`); override it and other fields with the `discovery` option. The host application must route the well-known path to this handler. Payment handlers are not part of ACP discovery; they are negotiated per checkout session.
25
+
22
26
  ## Product feed generation
23
27
 
24
28
  `GET /product_feeds/{id}/products` generates an ACP-compatible product feed from the configured feed definition whose key matches `{id}`.
@@ -16,6 +16,8 @@ import {
16
16
  const ACP_SESSION_ID_HEADER = "acp-session-id";
17
17
  const SESSION_CACHE_KEY_PREFIX = "reactionary:acp:session";
18
18
  const CHECKOUT_SESSION_CACHE_KEY_PREFIX = "reactionary:acp:checkout-session";
19
+ const ACP_DISCOVERY_PATHS = ["/.well-known/acp.json", "/.well-known/acp"];
20
+ const ACP_DEFAULT_API_VERSION = "2026-01-30";
19
21
  class ReactionaryACPServer {
20
22
  constructor(clientFactory, options = {}) {
21
23
  this.clientFactory = clientFactory;
@@ -80,6 +82,12 @@ class ReactionaryACPServer {
80
82
  }
81
83
  });
82
84
  }
85
+ if ((request.method === "GET" || request.method === "HEAD") && ACP_DISCOVERY_PATHS.includes(new URL(request.url).pathname)) {
86
+ return jsonResponse(this.getDiscoveryDocument(request), {
87
+ headers: { "cache-control": "public, max-age=3600" },
88
+ omitBody: request.method === "HEAD"
89
+ });
90
+ }
83
91
  if (request.method === "GET" || request.method === "HEAD") {
84
92
  const productFeedId = getProductFeedId(request, this.options.basePath);
85
93
  if (productFeedId) {
@@ -130,6 +138,28 @@ class ReactionaryACPServer {
130
138
  }
131
139
  });
132
140
  }
141
+ getDiscoveryDocument(request) {
142
+ const discovery = this.options.discovery ?? {};
143
+ const version = discovery.apiVersion ?? ACP_DEFAULT_API_VERSION;
144
+ const supportedVersions = discovery.supportedVersions ?? [version];
145
+ const basePath = (this.options.basePath ?? "/acp").replace(/\/$/, "");
146
+ const apiBaseUrl = discovery.apiBaseUrl ?? `${new URL(request.url).origin}${basePath}`;
147
+ return {
148
+ protocol: {
149
+ name: "acp",
150
+ version,
151
+ supported_versions: supportedVersions,
152
+ ...discovery.documentationUrl ? { documentation_url: discovery.documentationUrl } : {}
153
+ },
154
+ api_base_url: apiBaseUrl,
155
+ transports: ["rest"],
156
+ capabilities: {
157
+ services: this.options.productFeed ? ["checkout", "feeds"] : ["checkout"],
158
+ ...discovery.supportedCurrencies ? { supported_currencies: discovery.supportedCurrencies } : {},
159
+ ...discovery.supportedLocales ? { supported_locales: discovery.supportedLocales } : {}
160
+ }
161
+ };
162
+ }
133
163
  getReadinessDocument() {
134
164
  return {
135
165
  name: this.options.name ?? "@reactionary/acp",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactionary/acp",
3
- "version": "0.10.31",
3
+ "version": "0.10.32",
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.31",
13
- "@reactionary/feeds": "0.10.31",
12
+ "@reactionary/core": "0.10.32",
13
+ "@reactionary/feeds": "0.10.32",
14
14
  "zod": "4.1.9"
15
15
  },
16
16
  "devDependencies": {
@@ -42,6 +42,30 @@ export interface ReactionaryACPServerOptions {
42
42
  paymentProvider?: ACPPaymentProvider;
43
43
  links?: ACPLink[];
44
44
  productFeed?: ACPProductFeedOptions;
45
+ discovery?: ACPDiscoveryOptions;
46
+ }
47
+ export interface ACPDiscoveryOptions {
48
+ apiVersion?: string;
49
+ supportedVersions?: string[];
50
+ apiBaseUrl?: string;
51
+ documentationUrl?: string;
52
+ supportedCurrencies?: string[];
53
+ supportedLocales?: string[];
54
+ }
55
+ export interface ACPDiscoveryResponse {
56
+ protocol: {
57
+ name: 'acp';
58
+ version: string;
59
+ supported_versions: string[];
60
+ documentation_url?: string;
61
+ };
62
+ api_base_url: string;
63
+ transports: ['rest'];
64
+ capabilities: {
65
+ services: Array<'checkout' | 'feeds'>;
66
+ supported_currencies?: string[];
67
+ supported_locales?: string[];
68
+ };
45
69
  }
46
70
  export type ACPPaymentProcessor = 'stripe' | 'adyen' | 'braintree';
47
71
  export interface ACPPaymentProvider {
@@ -81,6 +105,7 @@ export declare class ReactionaryACPServer<TClient extends ReactionaryACPClient =
81
105
  close(): Promise<void>;
82
106
  private createRequestContext;
83
107
  private handleRequest;
108
+ private getDiscoveryDocument;
84
109
  private getReadinessDocument;
85
110
  private getProductFeed;
86
111
  private getRequestedProductFeed;