@reactionary/acp 0.0.1 → 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Solteq
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
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.0.1",
3
+ "version": "0.10.32",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "types": "./src/index.d.ts",
@@ -9,12 +9,12 @@
9
9
  "url": "git+https://github.com/Solteq/reactionary.git"
10
10
  },
11
11
  "dependencies": {
12
- "@reactionary/core": "0.0.1",
13
- "@reactionary/feeds": "0.0.1",
12
+ "@reactionary/core": "0.10.32",
13
+ "@reactionary/feeds": "0.10.32",
14
14
  "zod": "4.1.9"
15
15
  },
16
16
  "devDependencies": {
17
17
  "vitest": "^4.0.9"
18
18
  },
19
19
  "sideEffects": false
20
- }
20
+ }
@@ -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;