@curless/agentbank-merchant-sdk 0.1.5 → 0.3.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/README.md CHANGED
@@ -5,7 +5,8 @@ Drop into a merchant's backend (Shopify storefront, ClubMed booking flow,
5
5
  TikTok Shop seller service, anything that wants to **accept agent payments**)
6
6
  and you get:
7
7
 
8
- - **`AgentbankMerchant`** — typed client for `PaymentIntents` (create/get/capture/list/ledger-entries across ACP / x402 / AP2 / UCP / A2A), plus `PaymentLinks`, `Customers`, `BalanceTransactions`, and `WebhookEndpoints`. No refund methodrefunds are Curless-originated (see below).
8
+ - **`checkout.open`** — the fast path. **You** price an order from your own catalog and open a checkout; an agent pays it; the money lands in your account. agentbank never stores your catalog the price you pass is authoritative. You accept every agent-payment protocol (ACP, x402, A2A, UCP, AP2, …) with zero protocol code.
9
+ - **`AgentbankMerchant`** — typed client; also exposes `PaymentIntents` (create/get/capture/list/ledger-entries across ACP / x402 / AP2 / UCP / A2A), `PaymentLinks`, `Customers`, `BalanceTransactions`, and `WebhookEndpoints`. No refund method — refunds are Curless-originated (see below).
9
10
  - **`verifyWebhook` / `parseVerifiedWebhook`** — HMAC-SHA256 signature verification (Stripe-style `t=…,v1=…`), constant-time, **edge-safe** (Web Crypto, runs on Vercel Edge / Cloudflare Workers). Async — `await` them.
10
11
  - **`x402`** — `buildChallenge()` to emit your own canonical 402 from your route, `decodeXPaymentHeader()` to parse what the agent paid with.
11
12
 
@@ -16,6 +17,34 @@ One runtime dependency (`@curless/agentbank-core`, for portable crypto + the HTT
16
17
  > forwards the event, which advances the PI to `refunded` / `partially_refunded`.
17
18
  > Read the resulting state via `paymentIntents.get()` / `.list()`.
18
19
 
20
+ ### Fast path — open a merchant-quoted checkout
21
+
22
+ ```ts
23
+ import { AgentbankMerchant } from '@curless/agentbank-merchant-sdk';
24
+
25
+ const agentbank = new AgentbankMerchant({
26
+ baseUrl: 'https://mcp.curless.ai',
27
+ apiKey: process.env.AGENTBANK_MERCHANT_TOKEN!, // merchant:write
28
+ merchantId: process.env.AGENTBANK_MERCHANT_ID!,
29
+ });
30
+
31
+ // In your "an agent wants to buy" handler: YOU set the price.
32
+ const checkout = await agentbank.checkout.open({
33
+ currency: 'EUR',
34
+ items: [
35
+ { sku: 'resort-bali', name: 'Club Med Bali — 7 nights', quantity: 1, unitPrice: 192000 },
36
+ ],
37
+ });
38
+
39
+ // Hand checkout.id back to the buyer agent; it pays, money lands in your account.
40
+ return { checkoutId: checkout.id, amount: checkout.amount, currency: checkout.currency };
41
+ ```
42
+
43
+ That's the whole integration: install, set three env vars, call `checkout.open`.
44
+ You stay the source of truth for your catalog and prices — nothing to sync.
45
+
46
+ ### Lower-level — PaymentIntents, webhooks, x402
47
+
19
48
  ```ts
20
49
  import { AgentbankMerchant, parseVerifiedWebhook, x402 } from '@curless/agentbank-merchant-sdk';
21
50
 
package/dist/client.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { type FetchLike, type RequestOptions } from '@curless/agentbank-core';
2
2
  import { BalanceTransactionsResource } from './resources/balance-transactions.js';
3
+ import { CheckoutResource } from './resources/checkout.js';
3
4
  import { CustomersResource } from './resources/customers.js';
4
5
  import { PaymentIntentsResource } from './resources/payment-intents.js';
5
6
  import { PaymentLinksResource } from './resources/payment-links.js';
@@ -8,14 +9,17 @@ export type { FetchLike, RequestOptions } from '@curless/agentbank-core';
8
9
  export type AgentbankMerchantOptions = {
9
10
  baseUrl: string;
10
11
  apiKey: string;
12
+ merchantId?: string;
11
13
  fetch?: FetchLike;
12
14
  timeoutMs?: number;
13
15
  };
14
16
  export declare class AgentbankMerchant {
15
17
  readonly baseUrl: string;
18
+ readonly merchantId: string | undefined;
16
19
  private readonly fetchImpl;
17
20
  private readonly apiKey;
18
21
  private readonly timeoutMs;
22
+ readonly checkout: CheckoutResource;
19
23
  readonly paymentIntents: PaymentIntentsResource;
20
24
  readonly paymentLinks: PaymentLinksResource;
21
25
  readonly webh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EAAE,wBAAwB,CAAC;IACpD,QAAQ,CAAC,SAAS,EAAE,iBAAiB,CAAC;IACtC,QAAQ,CAAC,mBAAmB,EAAE,2BAA2B,CAAC;gBAE9C,IAAI,EAAE,wBAAwB;IAc1C,gBAAgB;IACV,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,cAAmB,GAAG,OAAO,CAAC,CAAC,CAAC;CAetF"}
package/dist/client.js CHANGED
@@ -1,19 +1,23 @@
1
1
  import { buildUrl, sendJson } from '@curless/agentbank-core';
2
2
  import { BalanceTransactionsResource } from './resources/balance-transactions.js';
3
+ import { CheckoutResource } from './resources/checkout.js';
3
4
  import { CustomersResource } from './resources/customers.js';
4
5
  import { PaymentIntentsResource } from './resources/payment-intents.js';
5
6
  import { PaymentLinksResource } from './resources/payment-links.js';
6
7
  import { WebhookEndpointsResource } from './resources/webhook-endpoints.js';
7
8
  // Merchant-side client for agentbank. Wraps the HTTP surface a merchant
8
- // integrates against: create + capture PaymentIntents (any protocol),
9
+ // integrates against: open a merchant-quoted checkout (you price it, an agent
10
+ // pays it — checkout.open), create + capture PaymentIntents (any protocol),
9
11
  // manage webhook subscriptions, query PI status. Webhook verification
10
12
  // + x402 challenge helpers live in ./webhooks and ./x402 as pure
11
13
  // functions (no client needed).
12
14
  export class AgentbankMerchant {
13
15
  baseUrl;
16
+ merchantId;
14
17
  fetchImpl;
15
18
  apiKey;
16
19
  timeoutMs;
20
+ checkout;
17
21
  paymentIntents;
18
22
  paymentLinks;
19
23
  webhookEndpoints;
@@ -21,9 +25,11 @@ export class AgentbankMerchant {
21
25
  balanceTransactions;
22
26
  constructor(opts) {
23
27
  this.baseUrl = opts.baseUrl.replace(/\/+$/, '');
28
+ this.merchantId = opts.merchantId;
24
29
  this.apiKey = opts.apiKey;
25
30
  this.fetchImpl = opts.fetch ?? fetch;
26
31
  this.timeoutMs = opts.timeoutMs;
32
+ this.checkout = new CheckoutResource(this);
27
33
  this.paymentIntents = new PaymentIntentsResource(this);
28
34
  this.paymentLinks = new PaymentLinksResource(this);
29
35
  this.webhookEndpoints = new WebhookEndpointsResource(this);
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuC,QAAQ,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAClG,OAAO,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC;AAClF,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAe5E,wEAAwE;AACxE,sEAAsE;AACtE,sEAAsE;AACtE,iEAAiE;AACjE,gCAAgC;AAChC,MAAM,OAAO,iBAAiB;IACnB,OAAO,CAAS;IACR,SAAS,CAAY;IACrB,MAAM,CAAS;IACf,SAAS,CAAqB;IAEtC,cAAc,CAAyB;IACvC,YAAY,CAAuB;IACnC,gBAAgB,CAA2B;IAC3C,SAAS,CAAoB;IAC7B,mBAAmB,CAA8B;IAE1D,YAAY,IAA8B;QACxC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAChD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC1B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC;QACrC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;QAChC,IAAI,CAAC,cAAc,GAAG,IAAI,sBAAsB,CAAC,IAAI,CAAC,CAAC;QACvD,IAAI,CAAC,YAAY,GAAG,IAAI,oBAAoB,CAAC,IAAI,CAAC,CAAC;QACnD,IA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AO,GAA2B;YACtC,cAAc,EAAE,kBAAkB;YAClC,aAAa,EAAE,UAAU,IAAI,CAAC,MAAM,EAAE;SACvC,CAAC;QACF,IAAI,IAAI,CAAC,cAAc;YAAE,OAAO,CAAC,iBAAiB,CAAC,GAAG,IAAI,CAAC,cAAc,CAAC;QAC1E,OAAO,QAAQ,CACb,IAAI,CAAC,SAAS,EACd,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,EACxC,MAAM,EACN,OAAO,EACP,IAAI,CAAC,IAAI,EACT,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,EAAE,CACrE,CAAC;IACJ,CAAC;CACF"}
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export { AgentbankMerchant } from './client.js';
2
2
  export type { AgentbankMerchantOptions, FetchLike, RequestOptions, } from './client.js';
3
3
  export { AgentbankError } from '@curless/agentbank-core';
4
4
  export type { BalanceTransaction, Customer, CustomerStatus, LedgerEntryView, Paginated, PaymentIntent, PaymentIntentLedger, PaymentIntentStatus, PaymentLink, PaymentLinkItem, PaymentLinkStatus, PaymentProtocol, WebhookEndpoint, WebhookEndpointWithSecret, X402PaymentRequirements, } from './types.js';
5
+ export type { Checkout, CheckoutLineItem, OpenCheckoutInput, } from './resources/checkout.js';
5
6
  export type { CreateCustomerInput, UpdateCustomerInput } from './resources/customers.js';
6
7
  export type { CreatePaymentIntentInput } from './resources/payment-intents.js';
7
8
  export type { CreatePaymentLinkInput } from './resources/payment-links.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,YAAY,EACV,wBAAwB,EACxB,SAAS,EACT,cAAc,GACf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,YAAY,EACV,kBAAkB,EAClB,QAAQ,EACR,cAAc,EACd,eAAe,EACf,SAAS,EACT,aAAa,EACb,mBAAmB,EACnB,mBAAmB,EACnB,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,YAAY,CAAC;AACpB,YAAY,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACzF,YAAY,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC/E,YAAY,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAC3E,YAAY,EAAE,0BAA0B,EAAE,MAAM,kCAAkC,CAAC;AACnF,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,aAAa,GACd,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAExE,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,CAAC;AAChB,YAAY,EACV,mBAAmB,EACnB,eAAe,EACf,iBAAiB,GAClB,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,YAAY,EACV,wBAAwB,EACxB,SAAS,EACT,cAAc,GACf,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,YAAY,EACV,kBAAkB,EAClB,QAAQ,EACR,cAAc,EACd,eAAe,EACf,SAAS,EACT,aAAa,EACb,mBAAmB,EACnB,mBAAmB,EACnB,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,eAAe,EACf,yBAAyB,EACzB,uBAAuB,GACxB,MAAM,YAAY,CAAC;AACpB,YAAY,EACV,QAAQ,EACR,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,yBAAyB,CAAC;AACjC,YAAY,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACzF,YAAY,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC/E,YAAY,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AAC3E,YAAY,EAAE,0BAA0B,EAAE,MAAM,kCAAkC,CAAC;AACnF,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,aAAa,GACd,MAAM,eAAe,CAAC;AACvB,YAAY,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAExE,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,CAAC;AAChB,YAAY,EACV,mBAAmB,EACnB,eAAe,EACf,iBAAiB,GAClB,MAAM,WAAW,CAAC"}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAMhD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAsBzD,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,aAAa,GACd,MAAM,eAAe,CAAC;AAEvB,qEAAqE;AACrE,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAMhD,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AA2BzD,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,aAAa,GACd,MAAM,eAAe,CAAC;AAEvB,qEAAqE;AACrE,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,CAAC"}
@@ -0,0 +1,50 @@
1
+ import type { AgentbankMerchant } from '../client.js';
2
+ import type { X402PaymentRequirements } from '../types.js';
3
+ export type CheckoutLineItem = {
4
+ /** Your product id / SKU. */
5
+ sku: string;
6
+ quantity: number;
7
+ /** Minor units (e.g. cents). YOU set this from your own catalog. */
8
+ unitPrice: number;
9
+ name?: string;
10
+ };
11
+ export type OpenCheckoutInput = {
12
+ items: CheckoutLineItem[];
13
+ /** Must match your merchant account's currency (USD/EUR/USDT/USDC). */
14
+ currency: string;
15
+ /** Overrides the client's configured `merchantId` for this call. */
16
+ merchantId?: string;
17
+ };
18
+ export type Checkout = {
19
+ /** The checkout id the buyer agent completes to pay. */
20
+ id: string;
21
+ status: string;
22
+ /** Total in minor units. */
23
+ amount: number;
24
+ currency: string;
25
+ };
26
+ export declare class CheckoutResource {
27
+ private readonly client;
28
+ constructor(client: AgentbankMerchant);
29
+ open(input: OpenCheckoutInput): Promise<Checkout>;
30
+ openX402(input: OpenX402CheckoutInput): Promise<X402Checkout>;
31
+ }
32
+ export type OpenX402CheckoutInput = {
33
+ items: CheckoutLineItem[];
34
+ /** Authoritative total in USDC base units (6 dp). YOU set this. */
35
+ amount: number;
36
+ /** Overrides the client's configured `merchantId` for this call. */
37
+ merchantId?: string;
38
+ };
39
+ export type X402Checkout = {
40
+ /** The session id the buyer pays with `{ sessionId }`. */
41
+ sessionId: string;
42
+ x402Version: number;
43
+ /** The x402 challenge the buyer signs against (payTo = your USDC address). */
44
+ accepts: X402PaymentRequirements[];
45
+ amount: number;
46
+ currency: string;
47
+ payTo: string;
48
+ network: string;
49
+ };
50
+ //# sourceMappingURL=checkout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkout.d.ts","sourceRoot":"","sources":["../../src/resources/checkout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAA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,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC"}
@@ -0,0 +1,51 @@
1
+ // Merchant-quoted checkout: YOU price the order from your own catalog and open
2
+ // a checkout; an agent pays it; the money lands in your account. agentbank
3
+ // never stores your catalog — the price you pass here is authoritative.
4
+ export class CheckoutResource {
5
+ client;
6
+ constructor(client) {
7
+ this.client = client;
8
+ }
9
+ async open(input) {
10
+ const merchantId = input.merchantId ?? this.client.merchantId;
11
+ if (!merchantId) {
12
+ throw new Error('merchantId is required — set it on AgentbankMerchant({ merchantId }) or pass it to open()');
13
+ }
14
+ const session = await this.client.request('POST', `/acp/${encodeURIComponent(merchantId)}/checkout_sessions`, {
15
+ body: {
16
+ currency: input.currency,
17
+ items: input.items.map((it) => ({
18
+ id: it.sku,
19
+ quantity: it.quantity,
20
+ unitPrice: it.unitPrice,
21
+ name: it.name,
22
+ })),
23
+ },
24
+ });
25
+ const amount = session.totals?.find((t) => t.type === 'total')?.amount ?? 0;
26
+ return { id: session.id, status: session.status, amount, currency: session.currency };
27
+ }
28
+ // Merchant-quoted x402 (USDC) checkout — the stablecoin twin of `open`. YOU
29
+ // set the authoritative USDC amount (base units, 6 dp); the gateway freezes
30
+ // it and returns the x402 challenge. A buyer agent then pays it by signing an
31
+ // EIP-3009 authorization against `accepts[0]` and POSTing `{ sessionId }` to
32
+ // /x402/:merchantId/checkout — it can't change the amount. Settlement is
33
+ // on-chain via the x402 facilitator; the USDC lands at your address.
34
+ async openX402(input) {
35
+ const merchantId = input.merchantId ?? this.client.merchantId;
36
+ if (!merchantId) {
37
+ throw new Error('merchantId is required — set it on AgentbankMerchant({ merchantId }) or pass it to openX402()');
38
+ }
39
+ return this.client.request('POST', `/x402/${encodeURIComponent(merchantId)}/checkout_sessions`, {
40
+ body: {
41
+ amount: input.amount,
42
+ items: input.items.map((it) => ({
43
+ id: it.sku,
44
+ quantity: it.quantity,
45
+ name: it.name,
46
+ })),
47
+ },
48
+ });
49
+ }
50
+ }
51
+ //# sourceMappingURL=checkout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkout.js","sourceRoot":"","sources":["../../src/resources/checkout.ts"],"names":[],"mappings":"AA6BA,+EAA+E;AAC/E,2EAA2E;AAC3E,wEAAwE;AACxE,MAAM,OAAO,gBAAgB;IACE;IAA7B,YAA6B,MAAyB;QAAzB,WAAM,GAAN,MAAM,CAAmB;IAAG,CAAC;IAE1D,KAAK,CAAC,IAAI,CAAC,KAAwB;QACjC,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,IAAI,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC;QAC9D,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CACb,2FAA2F,CAC5F,CAAC;QACJ,CAAC;QACD,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CAKtC,MAAM,EAAE,QAAQ,kBAAkB,CAAC,UAAU,CAAC,oBAAoB,EAAE;YACrE,IAAI,EAAE;gBACJ,QAAQ,EAAE,KAAK,CAAC,QAAQ;gBACxB,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;oBAC9B,EAAE,EAAE,EAAE,CAAC,GAAG;oBACV,QAAQ,EAAE,EAAE,CAAC,QAAQ;oBACrB,SAAS,EAAE,EAAE,CAAC,SAAS;oBACvB,IAAI,EAAE,EAAE,CAAC,IAAI;iBACd,CAAC,CAAC;aACJ;SACF,CAAC,CAAC;QACH,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC;QAC5E,OAAO,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC;IACxF,CAAC;IAED,4EAA4E;IAC5E,4EAA4E;IAC5E,8EAA8E;IAC9E,6EAA6E;IAC7E,yEAAyE;IACzE,qEAAqE;IACrE,KAAK,CAAC,QAAQ,CAAC,KAA4B;QACzC,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,IAAI,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC;QAC9D,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CACb,+FAA+F,CAChG,CAAC;QACJ,CAAC;QACD,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CACxB,MAAM,EACN,SAAS,kBAAkB,CAAC,UAAU,CAAC,oBAAoB,EAC3D;YACE,IAAI,EAAE;gBACJ,MAAM,EAAE,KAAK,CAAC,MAAM;gBACpB,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;oBAC9B,EAAE,EAAE,EAAE,CAAC,GAAG;oBACV,QAAQ,EAAE,EAAE,CAAC,QAAQ;oBACrB,IAAI,EAAE,EAAE,CAAC,IAAI;iBACd,CAAC,CAAC;aACJ;SACF,CACF,CAAC;IACJ,CAAC;CACF"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@curless/agentbank-merchant-sdk",
3
- "version": "0.1.5",
4
- "description": "Merchant-side SDK for agentbank — accept agent payments: PaymentIntents, edge-safe webhook verification, x402 challenge helpers.",
3
+ "version": "0.3.0",
4
+ "description": "Merchant-side SDK for agentbank — accept agent payments: open a merchant-quoted checkout (you price it, an agent pays it), PaymentIntents, edge-safe webhook verification, x402 challenge helpers.",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",
@@ -39,7 +39,7 @@
39
39
  "repository": {
40
40
  "type": "git",
41
41
  "url": "git+https://gitlab.com/robin-ruan/agentbank.git",
42
- "directory": "packages/merchant-sdk"
42
+ "directory": "packages/sdks/merchant-sdk"
43
43
  },
44
44
  "author": "robin",
45
45
  "scripts": {