@devlab.group/agent-commerce 2.4.1 → 2.6.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 +168 -16
- package/dist/ap2.d.ts +42 -17
- package/dist/ap2.js +83 -27
- package/dist/ap2.js.map +1 -1
- package/dist/{chunk-CXWC5LWM.js → chunk-DRLBML7Z.js} +661 -75
- package/dist/chunk-DRLBML7Z.js.map +1 -0
- package/dist/{chunk-WZW5ORZH.js → chunk-G3EYYHKF.js} +3 -3
- package/dist/{chunk-WZW5ORZH.js.map → chunk-G3EYYHKF.js.map} +1 -1
- package/dist/chunk-GA3O2A7R.js +92 -0
- package/dist/chunk-GA3O2A7R.js.map +1 -0
- package/dist/{chunk-DTKU3Z2M.js → chunk-M52FBNJX.js} +36 -5
- package/dist/chunk-M52FBNJX.js.map +1 -0
- package/dist/chunk-M6BSXXTF.js +8 -0
- package/dist/chunk-M6BSXXTF.js.map +1 -0
- package/dist/{chunk-QPV3EGJO.js → chunk-M6MQ3FYS.js} +25 -4
- package/dist/chunk-M6MQ3FYS.js.map +1 -0
- package/dist/chunk-M6WW6QIT.js +18 -0
- package/dist/chunk-M6WW6QIT.js.map +1 -0
- package/dist/cli/{ap2-GWSP4LYY.js → ap2-2YMYA2H6.js} +85 -29
- package/dist/cli/ap2-2YMYA2H6.js.map +1 -0
- package/dist/cli/{chunk-OZ4LAWBK.js → chunk-3NOMLMJW.js} +29 -8
- package/dist/cli/chunk-3NOMLMJW.js.map +1 -0
- package/dist/cli/chunk-4KLYFXMW.js +8 -0
- package/dist/cli/{chunk-ITWNSS2B.js.map → chunk-4KLYFXMW.js.map} +1 -1
- package/dist/cli/chunk-663ALDZA.js +92 -0
- package/dist/cli/chunk-663ALDZA.js.map +1 -0
- package/dist/cli/chunk-6R6WJ4FD.js +18 -0
- package/dist/cli/chunk-6R6WJ4FD.js.map +1 -0
- package/dist/cli/{chunk-G2JEY7MB.js → chunk-AZL7RPFU.js} +39 -33
- package/dist/cli/chunk-AZL7RPFU.js.map +1 -0
- package/dist/cli/chunk-DHFMIBPG.js +107 -0
- package/dist/cli/chunk-DHFMIBPG.js.map +1 -0
- package/dist/cli/{chunk-QQ3WY5L3.js → chunk-GET3CZGR.js} +36 -104
- package/dist/cli/chunk-GET3CZGR.js.map +1 -0
- package/dist/cli/chunk-NSYSMDQN.js +1544 -0
- package/dist/cli/chunk-NSYSMDQN.js.map +1 -0
- package/dist/cli/{chunk-PIMFPCNZ.js → chunk-PTL7SNOI.js} +313 -138
- package/dist/cli/chunk-PTL7SNOI.js.map +1 -0
- package/dist/cli/chunk-SYQLJXIU.js +105 -0
- package/dist/cli/chunk-SYQLJXIU.js.map +1 -0
- package/dist/cli/chunk-TFV3K6YS.js +373 -0
- package/dist/cli/chunk-TFV3K6YS.js.map +1 -0
- package/dist/cli/{chunk-3MGAJ5FX.js → chunk-VJ4EO4LE.js} +3 -3
- package/dist/cli/{chunk-3MGAJ5FX.js.map → chunk-VJ4EO4LE.js.map} +1 -1
- package/dist/cli/chunk-VJH6RYRK.js +119 -0
- package/dist/cli/chunk-VJH6RYRK.js.map +1 -0
- package/dist/cli/{chunk-TNMLDPUO.js → chunk-YOF7IK4V.js} +663 -77
- package/dist/cli/chunk-YOF7IK4V.js.map +1 -0
- package/dist/cli/{chunk-WYOGIANL.js → chunk-YWG2ZN3L.js} +4 -4
- package/dist/cli/{chunk-WYOGIANL.js.map → chunk-YWG2ZN3L.js.map} +1 -1
- package/dist/cli/config-3K65QJ22.js +12 -0
- package/dist/cli/{config-UI4EDG4L.js.map → config-3K65QJ22.js.map} +1 -1
- package/dist/cli/index.js +753 -212
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/{mcp-PGBRWZVA.js → mcp-6F64A7KE.js} +5 -4
- package/dist/cli/mcp-6F64A7KE.js.map +1 -0
- package/dist/cli/{near-5AY3HWYF.js → near-U6365VFX.js} +15 -4
- package/dist/cli/near-U6365VFX.js.map +1 -0
- package/dist/cli/payment-providers-2ITS6KNR.js +6 -0
- package/dist/cli/payment-providers-2ITS6KNR.js.map +1 -0
- package/dist/cli/{provider-I2ESL6RS.js → provider-5BGG5YKQ.js} +53 -24
- package/dist/cli/provider-5BGG5YKQ.js.map +1 -0
- package/dist/cli/receipts-I4IIE7U6.js +8 -0
- package/dist/cli/receipts-I4IIE7U6.js.map +1 -0
- package/dist/cli/reconcile-55WNCSFC.js +4 -0
- package/dist/cli/reconcile-55WNCSFC.js.map +1 -0
- package/dist/cli/{run-JK4ERPJV.js → run-2P6ZGFUE.js} +356 -173
- package/dist/cli/run-2P6ZGFUE.js.map +1 -0
- package/dist/cli/svm-KDSPDFJG.js +48 -0
- package/dist/cli/svm-KDSPDFJG.js.map +1 -0
- package/dist/cli/{x402-7WBFZQXV.js → x402-4LPIIELI.js} +10 -9
- package/dist/cli/x402-4LPIIELI.js.map +1 -0
- package/dist/index.d.ts +116 -113
- package/dist/index.js +1928 -351
- package/dist/index.js.map +1 -1
- package/dist/logger-CllGwQ8i.d.ts +19 -0
- package/dist/mcp.d.ts +3 -2
- package/dist/mcp.js +2 -1
- package/dist/mcp.js.map +1 -1
- package/dist/mpp.d.ts +2 -1
- package/dist/mpp.js +48 -19
- package/dist/mpp.js.map +1 -1
- package/dist/{near-D6C42VPE.js → near-FH7HPZV3.js} +15 -4
- package/dist/near-FH7HPZV3.js.map +1 -0
- package/dist/{protocol-adapter-C9odYl6l.d.ts → protocol-adapter-1WbtM3xG.d.ts} +12 -85
- package/dist/{runtime-Cl_BLVZV.d.ts → runtime-B-kARa2f.d.ts} +218 -15
- package/dist/store-kIIMpUA-.d.ts +372 -0
- package/dist/svm-KNC3PHMS.js +48 -0
- package/dist/svm-KNC3PHMS.js.map +1 -0
- package/dist/testing.d.ts +51 -0
- package/dist/testing.js +1896 -0
- package/dist/testing.js.map +1 -0
- package/dist/transaction-Dv0UFGg5.d.ts +129 -0
- package/dist/{types-j7MnUXYN.d.ts → types-DWqjz81-.d.ts} +5 -2
- package/dist/x402.d.ts +2 -1
- package/dist/x402.js +6 -5
- package/dist/x402.js.map +1 -1
- package/package.json +5 -1
- package/dist/authorization-DjAecwuW.d.ts +0 -115
- package/dist/chunk-CXWC5LWM.js.map +0 -1
- package/dist/chunk-DTKU3Z2M.js.map +0 -1
- package/dist/chunk-KA2AX5FH.js +0 -44
- package/dist/chunk-KA2AX5FH.js.map +0 -1
- package/dist/chunk-QPV3EGJO.js.map +0 -1
- package/dist/cli/ap2-GWSP4LYY.js.map +0 -1
- package/dist/cli/chunk-G2JEY7MB.js.map +0 -1
- package/dist/cli/chunk-GJIMDMYT.js +0 -639
- package/dist/cli/chunk-GJIMDMYT.js.map +0 -1
- package/dist/cli/chunk-ITWNSS2B.js +0 -8
- package/dist/cli/chunk-OSTCU6ZK.js +0 -44
- package/dist/cli/chunk-OSTCU6ZK.js.map +0 -1
- package/dist/cli/chunk-OZ4LAWBK.js.map +0 -1
- package/dist/cli/chunk-PIMFPCNZ.js.map +0 -1
- package/dist/cli/chunk-QQ3WY5L3.js.map +0 -1
- package/dist/cli/chunk-TNMLDPUO.js.map +0 -1
- package/dist/cli/config-UI4EDG4L.js +0 -11
- package/dist/cli/mcp-PGBRWZVA.js.map +0 -1
- package/dist/cli/near-5AY3HWYF.js.map +0 -1
- package/dist/cli/provider-I2ESL6RS.js.map +0 -1
- package/dist/cli/run-JK4ERPJV.js.map +0 -1
- package/dist/cli/svm-3MMYFPC7.js +0 -33
- package/dist/cli/svm-3MMYFPC7.js.map +0 -1
- package/dist/cli/x402-7WBFZQXV.js.map +0 -1
- package/dist/near-D6C42VPE.js.map +0 -1
- package/dist/svm-QEUAUNPQ.js +0 -33
- package/dist/svm-QEUAUNPQ.js.map +0 -1
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { HttpBackendExecutor, createResourceRegistry, createStoreEventSink, createExecutionPipeline, ACP_WELL_KNOWN_PATH, ACP_CHECKOUT_OPERATIONS, ACP_IN_FLIGHT_RETRY_AFTER_SECONDS, ACP_IDEMPOTENT_REPLAYED_HEADER, ACP_IDEMPOTENCY_KEY_HEADER, ACP_REQUEST_ID_HEADER, ACP_SPEC_VERSION, ACP_JSON_MEDIA_TYPE, ACP_API_VERSION, ACP_API_VERSION_HEADER, ACP_MAX_REQUEST_ID_LENGTH, ACP_OPERATION_INPUT_KEYS, ACP_OPERATION_OPTIONAL_INPUT_KEYS, ACP_SESSION_ID_INPUT_KEY, ACP_FORWARDED_HEADERS, ACP_MAX_FORWARDED_HEADER_LENGTH, BackendErrorResponse, ACP_MERCHANT_RETRY_AFTER_DEFAULT_SECONDS, ACP_MERCHANT_RETRY_AFTER_MAX_SECONDS } from './chunk-PIMFPCNZ.js';
|
|
4
|
-
import { MPP_DEFAULT_PAYMENT_FLOW, MPP_PROFILE } from './chunk-AA3FIEAR.js';
|
|
5
|
-
import { x402OfferName } from './chunk-WYOGIANL.js';
|
|
6
|
-
import { X402_DEFAULT_PAYMENT_FLOW, resolveDeploymentMode, requireX402Network } from './chunk-OZ4LAWBK.js';
|
|
7
|
-
import { openSqliteDatabase } from './chunk-3MGAJ5FX.js';
|
|
8
|
-
import './chunk-FHCFR2GS.js';
|
|
1
|
+
import { hasMethodGroup } from './chunk-6R6WJ4FD.js';
|
|
2
|
+
import { createConfiguredPaymentProviders, importOptionalPeer } from './chunk-DHFMIBPG.js';
|
|
9
3
|
import { readCappedBody, createBearerCheck, joinUrl, settlementResponse, settlementResponseFromDetails, settlementFailure, x402ErrorCode, x402RefusalStatus } from './chunk-SPAYKVUP.js';
|
|
4
|
+
import { A2A_DEFAULT_MOUNT_PATH, A2A_DEFAULT_AGENT_NAME, buildDescriptor, A2A_AGENT_CARD_PATH, A2A_JSON_MEDIA_TYPE, A2A_VERSION_HEADER, A2A_PROTOCOL_VERSION, A2A_EXTENSIONS_HEADER, A2A_PUSH_CONFIG_METHODS, A2A_TASK_LOOKUP_METHODS, A2A_UNSUPPORTED_METHODS, A2A_METHOD_SEND_MESSAGE, buildDescriptor2, A2A_PROTOCOL_BINDING, A2A_TASK_STATE_FAILED, A2A_TASK_STATE_COMPLETED, A2A_TASK_STATE_INPUT_REQUIRED } from './chunk-VJH6RYRK.js';
|
|
5
|
+
import { loadConfig } from './chunk-AZL7RPFU.js';
|
|
6
|
+
import { HttpBackendExecutor, createResourceRegistry, createStoreEventSink, createExecutionPipeline, ACP_WELL_KNOWN_PATH, ACP_CHECKOUT_OPERATIONS, ACP_IN_FLIGHT_RETRY_AFTER_SECONDS, ACP_IDEMPOTENT_REPLAYED_HEADER, ACP_IDEMPOTENCY_KEY_HEADER, ACP_REQUEST_ID_HEADER, ACP_SPEC_VERSION, ACP_JSON_MEDIA_TYPE, ACP_API_VERSION, ACP_API_VERSION_HEADER, ACP_MAX_REQUEST_ID_LENGTH, ACP_OPERATION_INPUT_KEYS, ACP_OPERATION_OPTIONAL_INPUT_KEYS, ACP_SESSION_ID_INPUT_KEY, ACP_FORWARDED_HEADERS, ACP_MAX_FORWARDED_HEADER_LENGTH, BackendErrorResponse, ACP_MERCHANT_RETRY_AFTER_DEFAULT_SECONDS, ACP_MERCHANT_RETRY_AFTER_MAX_SECONDS } from './chunk-PTL7SNOI.js';
|
|
7
|
+
import './chunk-FHCFR2GS.js';
|
|
10
8
|
import './chunk-TPC4EJLT.js';
|
|
9
|
+
import { createSqliteReceiptStore } from './chunk-NSYSMDQN.js';
|
|
10
|
+
import { openSqliteDatabase } from './chunk-VJ4EO4LE.js';
|
|
11
|
+
import { resolveManually, journalOf } from './chunk-TFV3K6YS.js';
|
|
11
12
|
import { contentDigest, CONTENT_DIGEST_METADATA_KEY, mppProblem, mppProblemDetail } from './chunk-5K4XEAZV.js';
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
13
|
+
import { MPP_DEFAULT_PAYMENT_FLOW, MPP_PROFILE } from './chunk-AA3FIEAR.js';
|
|
14
|
+
import { x402OfferName } from './chunk-YWG2ZN3L.js';
|
|
15
|
+
import { X402_DEFAULT_PAYMENT_FLOW, resolveDeploymentMode, requireX402Network } from './chunk-3NOMLMJW.js';
|
|
16
|
+
import { PACKAGE_VERSION } from './chunk-4KLYFXMW.js';
|
|
17
|
+
import { PAYMENT_HEADER, AUTHORIZATION_HEADER, systemClock, extractReservedInputFields, isHttpProtocolAdapter, toErrorEnvelope, DELIVERY_SUMMARY_META_KEY, toDeliverySummary, toPaymentRequiredEnvelope, NOOP_LOGGER, parseAuthorizationHeader, PAYMENT_REQUIRED_HEADER, PAYMENT_RESPONSE_HEADER, PAYMENT_INPUT_FIELD, AUTHORIZATION_INPUT_FIELD, parseAuthorizationSubmission, TRANSACTION_STATES } from './chunk-GET3CZGR.js';
|
|
18
|
+
import { CommerceError, isCommerceError, toLogInfo, toCommerceError } from './chunk-SYQLJXIU.js';
|
|
14
19
|
import { isRecord } from './chunk-3M6U7ILB.js';
|
|
15
20
|
import { createHash, randomUUID } from 'crypto';
|
|
16
21
|
import { z } from 'zod';
|
|
@@ -133,14 +138,13 @@ var A2A_CALL_SHAPE = 'one data part {"resource": "<skill id>", "input": {...}}';
|
|
|
133
138
|
function userRoleProblem(role) {
|
|
134
139
|
return role === A2A_USER_ROLE ? void 0 : `Unsupported message role "${String(role)}": only ${A2A_USER_ROLE} is accepted.`;
|
|
135
140
|
}
|
|
136
|
-
var UnknownRecord = z.record(z.string(), z.unknown());
|
|
137
141
|
var MessageSchema = z.object({
|
|
138
142
|
role: z.string(),
|
|
139
143
|
messageId: z.string().optional(),
|
|
140
|
-
parts: z.array(
|
|
144
|
+
parts: z.array(z.unknown()),
|
|
141
145
|
taskId: z.string().optional(),
|
|
142
146
|
contextId: z.string().optional(),
|
|
143
|
-
referenceTaskIds: z.array(z.
|
|
147
|
+
referenceTaskIds: z.array(z.unknown()).optional()
|
|
144
148
|
});
|
|
145
149
|
var ParamsSchema = z.object({
|
|
146
150
|
message: MessageSchema,
|
|
@@ -161,7 +165,7 @@ function assertNoContinuation(params) {
|
|
|
161
165
|
const message = params.message;
|
|
162
166
|
if (params.taskId !== void 0 || message.taskId !== void 0) {
|
|
163
167
|
throw unsupported(
|
|
164
|
-
"Task not found:
|
|
168
|
+
"Task not found: only a task waiting for payment can be continued, so send a request with no taskId.",
|
|
165
169
|
A2A_ERROR_TASK_NOT_FOUND
|
|
166
170
|
);
|
|
167
171
|
}
|
|
@@ -224,6 +228,7 @@ function parseInvocation(rawParams) {
|
|
|
224
228
|
}
|
|
225
229
|
const part = message.parts[0];
|
|
226
230
|
if (part === void 0) throw invalid("Message carries no parts.");
|
|
231
|
+
if (!isRecord(part)) throw invalid("Message part must be a JSON object.");
|
|
227
232
|
assertSupportedPart(part);
|
|
228
233
|
const data = part["data"];
|
|
229
234
|
if (!isRecord(data)) {
|
|
@@ -260,6 +265,11 @@ function requestsX402Extension(header2) {
|
|
|
260
265
|
(value) => value.split(",").some((uri) => uri.trim() === A2A_X402_EXTENSION_URI)
|
|
261
266
|
);
|
|
262
267
|
}
|
|
268
|
+
function expiryMs(nowMs, expiresAt) {
|
|
269
|
+
const requested = expiresAt !== void 0 ? Date.parse(expiresAt) : Number.NaN;
|
|
270
|
+
const ttl = Number.isFinite(requested) ? requested - nowMs : DEFAULT_PENDING_TTL_MS;
|
|
271
|
+
return nowMs + Math.min(Math.max(ttl, 0), MAX_PENDING_TTL_MS);
|
|
272
|
+
}
|
|
263
273
|
function createPendingPayments(clock, maxEntries = MAX_PENDING_PAYMENTS) {
|
|
264
274
|
const tasks = /* @__PURE__ */ new Map();
|
|
265
275
|
const now = () => clock.now().getTime();
|
|
@@ -269,28 +279,27 @@ function createPendingPayments(clock, maxEntries = MAX_PENDING_PAYMENTS) {
|
|
|
269
279
|
if (pending.expiresAtMs <= at) tasks.delete(taskId);
|
|
270
280
|
}
|
|
271
281
|
}
|
|
282
|
+
function get(taskId) {
|
|
283
|
+
const pending = tasks.get(taskId);
|
|
284
|
+
if (pending === void 0) return void 0;
|
|
285
|
+
if (pending.expiresAtMs <= now()) {
|
|
286
|
+
tasks.delete(taskId);
|
|
287
|
+
return void 0;
|
|
288
|
+
}
|
|
289
|
+
return pending;
|
|
290
|
+
}
|
|
272
291
|
return {
|
|
273
|
-
/** Holds a purchase until `expiresAt`; returns false, holding nothing, when full */
|
|
274
292
|
put(taskId, pending, expiresAt) {
|
|
275
293
|
purgeExpired();
|
|
276
294
|
if (tasks.size >= maxEntries) return false;
|
|
277
|
-
|
|
278
|
-
const ttl = Number.isFinite(requested) ? requested - now() : DEFAULT_PENDING_TTL_MS;
|
|
279
|
-
const expiresAtMs = now() + Math.min(Math.max(ttl, 0), MAX_PENDING_TTL_MS);
|
|
280
|
-
tasks.set(taskId, { ...pending, expiresAtMs });
|
|
295
|
+
tasks.set(taskId, { ...pending, expiresAtMs: expiryMs(now(), expiresAt) });
|
|
281
296
|
return true;
|
|
282
297
|
},
|
|
283
|
-
get
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
if (pending.expiresAtMs <= now()) {
|
|
287
|
-
tasks.delete(taskId);
|
|
288
|
-
return void 0;
|
|
289
|
-
}
|
|
290
|
-
return pending;
|
|
291
|
-
},
|
|
292
|
-
delete(taskId) {
|
|
298
|
+
get,
|
|
299
|
+
take(taskId) {
|
|
300
|
+
const pending = get(taskId);
|
|
293
301
|
tasks.delete(taskId);
|
|
302
|
+
return pending;
|
|
294
303
|
},
|
|
295
304
|
size() {
|
|
296
305
|
return tasks.size;
|
|
@@ -300,6 +309,73 @@ function createPendingPayments(clock, maxEntries = MAX_PENDING_PAYMENTS) {
|
|
|
300
309
|
}
|
|
301
310
|
};
|
|
302
311
|
}
|
|
312
|
+
function createStoredPendingPayments(store, clock, maxTasks = MAX_PENDING_PAYMENTS) {
|
|
313
|
+
const mandates = /* @__PURE__ */ new Map();
|
|
314
|
+
const now = () => clock.now().getTime();
|
|
315
|
+
function purgeExpired() {
|
|
316
|
+
const at = now();
|
|
317
|
+
for (const [taskId, held] of mandates) {
|
|
318
|
+
if (held.expiresAtMs <= at) mandates.delete(taskId);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
function toPending(task2) {
|
|
322
|
+
const { contextId, network } = task2.adapterData ?? {};
|
|
323
|
+
if (task2.protocol !== "a2a" || typeof contextId !== "string") return void 0;
|
|
324
|
+
purgeExpired();
|
|
325
|
+
const authorization = mandates.get(task2.id)?.authorization;
|
|
326
|
+
return {
|
|
327
|
+
contextId,
|
|
328
|
+
resourceId: task2.resourceId,
|
|
329
|
+
input: task2.input,
|
|
330
|
+
...authorization !== void 0 ? { authorization } : {},
|
|
331
|
+
...typeof network === "string" ? { network } : {},
|
|
332
|
+
expiresAtMs: Date.parse(task2.expiresAt)
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
return {
|
|
336
|
+
async put(taskId, pending, expiresAt) {
|
|
337
|
+
const expiresAtMs = expiryMs(now(), expiresAt);
|
|
338
|
+
const held = await store.putPendingTask(
|
|
339
|
+
{
|
|
340
|
+
id: taskId,
|
|
341
|
+
protocol: "a2a",
|
|
342
|
+
resourceId: pending.resourceId,
|
|
343
|
+
input: pending.input,
|
|
344
|
+
adapterData: {
|
|
345
|
+
contextId: pending.contextId,
|
|
346
|
+
...pending.network !== void 0 ? { network: pending.network } : {}
|
|
347
|
+
},
|
|
348
|
+
expiresAt: new Date(expiresAtMs).toISOString()
|
|
349
|
+
},
|
|
350
|
+
{ maxTasks }
|
|
351
|
+
);
|
|
352
|
+
purgeExpired();
|
|
353
|
+
mandates.delete(taskId);
|
|
354
|
+
if (held && pending.authorization !== void 0) {
|
|
355
|
+
mandates.set(taskId, { authorization: pending.authorization, expiresAtMs });
|
|
356
|
+
}
|
|
357
|
+
return held;
|
|
358
|
+
},
|
|
359
|
+
async get(taskId) {
|
|
360
|
+
const task2 = await store.getPendingTask(taskId);
|
|
361
|
+
return task2 !== void 0 ? toPending(task2) : void 0;
|
|
362
|
+
},
|
|
363
|
+
async take(taskId) {
|
|
364
|
+
const task2 = await store.takePendingTask(taskId);
|
|
365
|
+
if (task2 === void 0) return void 0;
|
|
366
|
+
const pending = toPending(task2);
|
|
367
|
+
if (pending === void 0) {
|
|
368
|
+
await store.putPendingTask(task2, { maxTasks: Number.MAX_SAFE_INTEGER });
|
|
369
|
+
return void 0;
|
|
370
|
+
}
|
|
371
|
+
mandates.delete(taskId);
|
|
372
|
+
return pending;
|
|
373
|
+
},
|
|
374
|
+
clear() {
|
|
375
|
+
mandates.clear();
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
}
|
|
303
379
|
function readPaymentSubmission(message) {
|
|
304
380
|
const metadata = isRecord(message) ? message["metadata"] : void 0;
|
|
305
381
|
if (!isRecord(metadata)) return void 0;
|
|
@@ -541,7 +617,7 @@ async function resumePayment(context, pendingPayments, id, params) {
|
|
|
541
617
|
const message = isRecord(params) ? params["message"] : void 0;
|
|
542
618
|
const taskId = isRecord(message) ? message["taskId"] : void 0;
|
|
543
619
|
if (context === void 0 || typeof taskId !== "string") return void 0;
|
|
544
|
-
const pending = pendingPayments?.get(taskId);
|
|
620
|
+
const pending = await pendingPayments?.get(taskId);
|
|
545
621
|
if (pending === void 0) return void 0;
|
|
546
622
|
const messageId = isRecord(message) ? message["messageId"] : void 0;
|
|
547
623
|
if (typeof messageId !== "string" || messageId.length === 0) {
|
|
@@ -561,19 +637,21 @@ async function resumePayment(context, pendingPayments, id, params) {
|
|
|
561
637
|
`For a pending task, set "${X402_PAYMENT_STATUS_KEY}" to "payment-submitted" and provide a "${X402_PAYMENT_PAYLOAD_KEY}" object, or set it to "payment-rejected".`
|
|
562
638
|
);
|
|
563
639
|
}
|
|
564
|
-
let
|
|
565
|
-
if (authorization === void 0 && submission.kind === "submitted") {
|
|
640
|
+
let followUp;
|
|
641
|
+
if (pending.authorization === void 0 && submission.kind === "submitted") {
|
|
566
642
|
try {
|
|
567
|
-
|
|
643
|
+
followUp = readFollowUpAuthorization(message);
|
|
568
644
|
} catch (err) {
|
|
569
645
|
return jsonRpcError(id, JSONRPC_INVALID_PARAMS, toCommerceError(err).message);
|
|
570
646
|
}
|
|
571
647
|
}
|
|
572
|
-
pendingPayments?.
|
|
648
|
+
const taken = await pendingPayments?.take(taskId);
|
|
649
|
+
if (taken === void 0) return void 0;
|
|
650
|
+
const authorization = taken.authorization ?? followUp;
|
|
573
651
|
const statusMessageId = context.ids.next("a2a-msg");
|
|
574
652
|
const identity = {
|
|
575
653
|
taskId,
|
|
576
|
-
contextId:
|
|
654
|
+
contextId: taken.contextId,
|
|
577
655
|
artifactId: context.ids.next("a2a-artifact"),
|
|
578
656
|
statusMessageId,
|
|
579
657
|
timestamp: context.clock.nowIso()
|
|
@@ -581,7 +659,7 @@ async function resumePayment(context, pendingPayments, id, params) {
|
|
|
581
659
|
if (submission.kind === "rejected") {
|
|
582
660
|
const declined = {
|
|
583
661
|
id: taskId,
|
|
584
|
-
contextId:
|
|
662
|
+
contextId: taken.contextId,
|
|
585
663
|
status: { state: A2A_TASK_STATE_FAILED, timestamp: identity.timestamp },
|
|
586
664
|
artifacts: []
|
|
587
665
|
};
|
|
@@ -599,7 +677,7 @@ async function resumePayment(context, pendingPayments, id, params) {
|
|
|
599
677
|
id,
|
|
600
678
|
await payPending(
|
|
601
679
|
context,
|
|
602
|
-
{ ...
|
|
680
|
+
{ ...taken, ...authorization !== void 0 ? { authorization } : {} },
|
|
603
681
|
submission.payload,
|
|
604
682
|
identity
|
|
605
683
|
)
|
|
@@ -663,6 +741,7 @@ var A2aProtocolAdapter = class {
|
|
|
663
741
|
agentName;
|
|
664
742
|
agentDescription;
|
|
665
743
|
agentVersion;
|
|
744
|
+
store;
|
|
666
745
|
context;
|
|
667
746
|
started = false;
|
|
668
747
|
// The card lists only a2a-exposed resources, but a caller can name any id,
|
|
@@ -680,6 +759,7 @@ var A2aProtocolAdapter = class {
|
|
|
680
759
|
this.agentName = options.agentName ?? A2A_DEFAULT_AGENT_NAME;
|
|
681
760
|
this.agentDescription = options.agentDescription ?? DEFAULT_AGENT_DESCRIPTION;
|
|
682
761
|
this.agentVersion = options.agentVersion ?? PACKAGE_VERSION;
|
|
762
|
+
this.store = options.store;
|
|
683
763
|
this.descriptor = buildDescriptor(PACKAGE_VERSION);
|
|
684
764
|
this.additionalHttpRoutes = [
|
|
685
765
|
{
|
|
@@ -711,7 +791,7 @@ var A2aProtocolAdapter = class {
|
|
|
711
791
|
mountPath: this.mountPath,
|
|
712
792
|
resources
|
|
713
793
|
});
|
|
714
|
-
this.pendingPayments = createPendingPayments(context.clock);
|
|
794
|
+
this.pendingPayments = hasMethodGroup(this.store, "pending_tasks") ? createStoredPendingPayments(this.store, context.clock) : createPendingPayments(context.clock);
|
|
715
795
|
this.cardBody = JSON.stringify(this.card);
|
|
716
796
|
this.cardEtag = `"${createHash("sha256").update(this.cardBody).digest("base64url")}"`;
|
|
717
797
|
this.started = true;
|
|
@@ -912,7 +992,7 @@ var A2aProtocolAdapter = class {
|
|
|
912
992
|
return taskResult(id, task2);
|
|
913
993
|
}
|
|
914
994
|
const network = outcome.requirement.network;
|
|
915
|
-
const held = this.pendingPayments?.put(
|
|
995
|
+
const held = await this.pendingPayments?.put(
|
|
916
996
|
identity.taskId,
|
|
917
997
|
{
|
|
918
998
|
contextId: identity.contextId,
|
|
@@ -1179,23 +1259,22 @@ function createAcpIdempotencyStore(options) {
|
|
|
1179
1259
|
};
|
|
1180
1260
|
}
|
|
1181
1261
|
function resolveOrphanedClaims(db, logger, release) {
|
|
1262
|
+
const { changes } = release ? db.prepare("DELETE FROM acp_idempotency WHERE state = 'in_flight'").run() : db.prepare("UPDATE acp_idempotency SET state = 'unresolved' WHERE state = 'in_flight'").run();
|
|
1263
|
+
warnOrphanedClaims(logger, changes, release);
|
|
1264
|
+
}
|
|
1265
|
+
function warnOrphanedClaims(logger, count, release) {
|
|
1266
|
+
if (count === 0) return;
|
|
1182
1267
|
if (release) {
|
|
1183
|
-
const { changes: changes2 } = db.prepare("DELETE FROM acp_idempotency WHERE state = 'in_flight'").run();
|
|
1184
|
-
if (changes2 > 0) {
|
|
1185
|
-
logger.warn(
|
|
1186
|
-
{ released: changes2 },
|
|
1187
|
-
"acp idempotency: freed claims left in flight by an earlier process; merchant deduplication is enabled"
|
|
1188
|
-
);
|
|
1189
|
-
}
|
|
1190
|
-
return;
|
|
1191
|
-
}
|
|
1192
|
-
const { changes } = db.prepare("UPDATE acp_idempotency SET state = 'unresolved' WHERE state = 'in_flight'").run();
|
|
1193
|
-
if (changes > 0) {
|
|
1194
1268
|
logger.warn(
|
|
1195
|
-
{
|
|
1196
|
-
"acp idempotency:
|
|
1269
|
+
{ released: count },
|
|
1270
|
+
"acp idempotency: freed claims left in flight by an earlier process; merchant deduplication is enabled"
|
|
1197
1271
|
);
|
|
1272
|
+
return;
|
|
1198
1273
|
}
|
|
1274
|
+
logger.warn(
|
|
1275
|
+
{ unresolved: count },
|
|
1276
|
+
"acp idempotency: marked claims left in flight by an earlier process as unresolved; reconcile these operations against the merchant before trusting a retry"
|
|
1277
|
+
);
|
|
1199
1278
|
}
|
|
1200
1279
|
function migrate(db, logger) {
|
|
1201
1280
|
const current = db.pragma("user_version", { simple: true });
|
|
@@ -5750,6 +5829,27 @@ function reachedFor(error) {
|
|
|
5750
5829
|
function notReached(failure) {
|
|
5751
5830
|
return { response: asResponse(failure), reached: "no" };
|
|
5752
5831
|
}
|
|
5832
|
+
function backendOverReceiptStore(store, clock, retentionHours) {
|
|
5833
|
+
const retentionMs = retentionHours * 60 * 60 * 1e3;
|
|
5834
|
+
return {
|
|
5835
|
+
claim: (scope, fingerprint) => store.claimIdempotencyKey(
|
|
5836
|
+
scope,
|
|
5837
|
+
fingerprint,
|
|
5838
|
+
new Date(clock.now().getTime() + retentionMs).toISOString()
|
|
5839
|
+
),
|
|
5840
|
+
complete: (scope, { status, body }) => store.updateIdempotencyKey(scope, { kind: "completed", status, body }),
|
|
5841
|
+
markUnresolved: (scope) => store.updateIdempotencyKey(scope, { kind: "unresolved" }),
|
|
5842
|
+
release: (scope) => store.updateIdempotencyKey(scope, { kind: "released" })
|
|
5843
|
+
};
|
|
5844
|
+
}
|
|
5845
|
+
function backendOverFileStore(store) {
|
|
5846
|
+
return {
|
|
5847
|
+
claim: async (scope, fingerprint) => store.claim(scope, fingerprint),
|
|
5848
|
+
complete: async (scope, response) => store.complete(scope, response),
|
|
5849
|
+
markUnresolved: async (scope) => store.markUnresolved(scope),
|
|
5850
|
+
release: async (scope) => store.release(scope)
|
|
5851
|
+
};
|
|
5852
|
+
}
|
|
5753
5853
|
var AcpProtocolAdapter = class {
|
|
5754
5854
|
name = "acp";
|
|
5755
5855
|
mountPath;
|
|
@@ -5764,7 +5864,10 @@ var AcpProtocolAdapter = class {
|
|
|
5764
5864
|
*/
|
|
5765
5865
|
deployment;
|
|
5766
5866
|
discoveryMetadata;
|
|
5867
|
+
store;
|
|
5767
5868
|
idempotency;
|
|
5869
|
+
// Track the file opened by this adapter so borrowed receipt stores stay open
|
|
5870
|
+
fileStore;
|
|
5768
5871
|
resources = /* @__PURE__ */ new Map();
|
|
5769
5872
|
context;
|
|
5770
5873
|
started = false;
|
|
@@ -5776,6 +5879,7 @@ var AcpProtocolAdapter = class {
|
|
|
5776
5879
|
this.isAuthorized = createBearerCheck(options.token);
|
|
5777
5880
|
this.operations = options.operations;
|
|
5778
5881
|
this.idempotencyOptions = options.idempotency;
|
|
5882
|
+
this.store = options.store;
|
|
5779
5883
|
this.discoveryMetadata = options.discovery;
|
|
5780
5884
|
this.descriptor = buildDescriptor2(PACKAGE_VERSION);
|
|
5781
5885
|
this.additionalHttpRoutes = [
|
|
@@ -5820,12 +5924,7 @@ var AcpProtocolAdapter = class {
|
|
|
5820
5924
|
}
|
|
5821
5925
|
this.resources = resolved;
|
|
5822
5926
|
this.deployment = context.publicBaseUrl;
|
|
5823
|
-
this.idempotency =
|
|
5824
|
-
path: this.idempotencyOptions.path,
|
|
5825
|
-
retentionHours: this.idempotencyOptions.retentionHours,
|
|
5826
|
-
releaseOrphans: this.idempotencyOptions.merchantIdempotent === true,
|
|
5827
|
-
logger: context.logger
|
|
5828
|
-
});
|
|
5927
|
+
this.idempotency = await this.openIdempotency(context);
|
|
5829
5928
|
this.discovery = document;
|
|
5830
5929
|
this.started = true;
|
|
5831
5930
|
context.logger.info(
|
|
@@ -5837,6 +5936,32 @@ var AcpProtocolAdapter = class {
|
|
|
5837
5936
|
"acp adapter started"
|
|
5838
5937
|
);
|
|
5839
5938
|
}
|
|
5939
|
+
// Recover claims at adapter start, not when the shared store opens for
|
|
5940
|
+
// another consumer
|
|
5941
|
+
async openIdempotency(context) {
|
|
5942
|
+
const { path, retentionHours, merchantIdempotent } = this.idempotencyOptions;
|
|
5943
|
+
const release = merchantIdempotent === true;
|
|
5944
|
+
const store = this.store;
|
|
5945
|
+
if (hasMethodGroup(store, "idempotency_claims")) {
|
|
5946
|
+
const recovered = await store.recoverIdempotencyKeys({ release });
|
|
5947
|
+
warnOrphanedClaims(context.logger, recovered, release);
|
|
5948
|
+
return backendOverReceiptStore(store, context.clock, retentionHours);
|
|
5949
|
+
}
|
|
5950
|
+
if (path === void 0) {
|
|
5951
|
+
throw new CommerceError(
|
|
5952
|
+
"CONFIG_INVALID",
|
|
5953
|
+
"ACP idempotency needs a receipt store with idempotency methods or a file - set protocols.acp.idempotency.path",
|
|
5954
|
+
{ details: { path: "protocols.acp.idempotency.path" } }
|
|
5955
|
+
);
|
|
5956
|
+
}
|
|
5957
|
+
this.fileStore = createAcpIdempotencyStore({
|
|
5958
|
+
path,
|
|
5959
|
+
retentionHours,
|
|
5960
|
+
releaseOrphans: release,
|
|
5961
|
+
logger: context.logger
|
|
5962
|
+
});
|
|
5963
|
+
return backendOverFileStore(this.fileStore);
|
|
5964
|
+
}
|
|
5840
5965
|
/** `GET /.well-known/acp.json`: public, unauthenticated, cacheable */
|
|
5841
5966
|
async handleDiscovery(req, res) {
|
|
5842
5967
|
try {
|
|
@@ -5914,7 +6039,7 @@ var AcpProtocolAdapter = class {
|
|
|
5914
6039
|
return (await this.runCheckout(request)).response;
|
|
5915
6040
|
}
|
|
5916
6041
|
const scope = { deployment, endpoint: request.route.path, key };
|
|
5917
|
-
const claim = store.claim(scope, requestFingerprint(request.body));
|
|
6042
|
+
const claim = await store.claim(scope, requestFingerprint(request.body));
|
|
5918
6043
|
switch (claim.kind) {
|
|
5919
6044
|
case "in-flight":
|
|
5920
6045
|
return {
|
|
@@ -5953,15 +6078,15 @@ var AcpProtocolAdapter = class {
|
|
|
5953
6078
|
try {
|
|
5954
6079
|
outcome = await this.runCheckout(request, operationKey(scope));
|
|
5955
6080
|
} catch (err) {
|
|
5956
|
-
store.markUnresolved(scope);
|
|
6081
|
+
await store.markUnresolved(scope);
|
|
5957
6082
|
throw err;
|
|
5958
6083
|
}
|
|
5959
6084
|
if (outcome.response.status < 500) {
|
|
5960
|
-
store.complete(scope, outcome.response);
|
|
6085
|
+
await store.complete(scope, outcome.response);
|
|
5961
6086
|
} else if (outcome.reached === "no" || this.idempotencyOptions.merchantIdempotent === true) {
|
|
5962
|
-
store.release(scope);
|
|
6087
|
+
await store.release(scope);
|
|
5963
6088
|
} else {
|
|
5964
|
-
store.markUnresolved(scope);
|
|
6089
|
+
await store.markUnresolved(scope);
|
|
5965
6090
|
}
|
|
5966
6091
|
return outcome.response;
|
|
5967
6092
|
}
|
|
@@ -6061,7 +6186,8 @@ var AcpProtocolAdapter = class {
|
|
|
6061
6186
|
this.started = false;
|
|
6062
6187
|
this.discovery = void 0;
|
|
6063
6188
|
this.resources = /* @__PURE__ */ new Map();
|
|
6064
|
-
this.
|
|
6189
|
+
this.fileStore?.close();
|
|
6190
|
+
this.fileStore = void 0;
|
|
6065
6191
|
this.idempotency = void 0;
|
|
6066
6192
|
this.deployment = void 0;
|
|
6067
6193
|
this.context = void 0;
|
|
@@ -6149,99 +6275,6 @@ function wrapPino(instance) {
|
|
|
6149
6275
|
return logger;
|
|
6150
6276
|
}
|
|
6151
6277
|
|
|
6152
|
-
// src/gateway/optional-peer.ts
|
|
6153
|
-
var MISSING_PACKAGE = /Cannot find package '([^']+)'/;
|
|
6154
|
-
async function importOptionalPeer(feature, load) {
|
|
6155
|
-
try {
|
|
6156
|
-
return await load();
|
|
6157
|
-
} catch (cause) {
|
|
6158
|
-
if (cause?.code !== "ERR_MODULE_NOT_FOUND") throw cause;
|
|
6159
|
-
const pkg = MISSING_PACKAGE.exec(cause.message)?.[1];
|
|
6160
|
-
if (pkg === void 0) throw cause;
|
|
6161
|
-
throw new CommerceError(
|
|
6162
|
-
"CONFIG_INVALID",
|
|
6163
|
-
`${feature} is enabled, but the package "${pkg}" is not installed. Install the optional peers it needs at the versions \`agent-commerce version\` lists, or disable it.`,
|
|
6164
|
-
{ cause }
|
|
6165
|
-
);
|
|
6166
|
-
}
|
|
6167
|
-
}
|
|
6168
|
-
|
|
6169
|
-
// src/gateway/payment-providers.ts
|
|
6170
|
-
function offerOptions(option) {
|
|
6171
|
-
return {
|
|
6172
|
-
network: option.network,
|
|
6173
|
-
rpcUrl: option.rpcUrl,
|
|
6174
|
-
asset: option.asset,
|
|
6175
|
-
assetDecimals: option.assetDecimals,
|
|
6176
|
-
payTo: option.payTo,
|
|
6177
|
-
...option.assetName !== void 0 ? { assetName: option.assetName } : {},
|
|
6178
|
-
...option.assetVersion !== void 0 ? { assetVersion: option.assetVersion } : {},
|
|
6179
|
-
...option.assetTransferMethod !== void 0 ? { assetTransferMethod: option.assetTransferMethod } : {}
|
|
6180
|
-
};
|
|
6181
|
-
}
|
|
6182
|
-
async function createConfiguredPaymentProviders(payments, logger) {
|
|
6183
|
-
const providers = [];
|
|
6184
|
-
const { x402, mpp } = payments;
|
|
6185
|
-
if (x402?.enabled) {
|
|
6186
|
-
const { createX402PaymentProvider } = await importOptionalPeer(
|
|
6187
|
-
"payments.x402",
|
|
6188
|
-
() => import('./x402-7WBFZQXV.js')
|
|
6189
|
-
);
|
|
6190
|
-
providers.push(
|
|
6191
|
-
createX402PaymentProvider({
|
|
6192
|
-
// Support manually built single-option configs without `options`
|
|
6193
|
-
offers: (x402.options ?? [x402]).map(offerOptions),
|
|
6194
|
-
...x402.resourceOptions !== void 0 ? {
|
|
6195
|
-
resourceOffers: Object.fromEntries(
|
|
6196
|
-
Object.entries(x402.resourceOptions).map(([id, list]) => [
|
|
6197
|
-
id,
|
|
6198
|
-
list.map(offerOptions)
|
|
6199
|
-
])
|
|
6200
|
-
)
|
|
6201
|
-
} : {},
|
|
6202
|
-
maxTimeoutSeconds: x402.maxTimeoutSeconds,
|
|
6203
|
-
...x402.paymentFlow !== void 0 ? { paymentFlow: x402.paymentFlow } : {},
|
|
6204
|
-
...x402.resourcePaymentFlows !== void 0 ? { resourcePaymentFlows: x402.resourcePaymentFlows } : {},
|
|
6205
|
-
...x402.resourceMimeTypes !== void 0 ? { resourceMimeTypes: x402.resourceMimeTypes } : {},
|
|
6206
|
-
facilitator: x402.facilitator,
|
|
6207
|
-
...x402.allowMainnet !== void 0 ? { allowMainnet: x402.allowMainnet } : {},
|
|
6208
|
-
...x402.allowUnauthenticatedFacilitator !== void 0 ? { allowUnauthenticatedFacilitator: x402.allowUnauthenticatedFacilitator } : {},
|
|
6209
|
-
...x402.networks !== void 0 ? { customNetworks: x402.networks } : {},
|
|
6210
|
-
// Pass quote settings only to x402; MPP builds a separate settlement
|
|
6211
|
-
// provider without quotes
|
|
6212
|
-
...x402.quote !== void 0 ? { quote: x402.quote } : {},
|
|
6213
|
-
logger
|
|
6214
|
-
})
|
|
6215
|
-
);
|
|
6216
|
-
}
|
|
6217
|
-
if (mpp?.enabled) {
|
|
6218
|
-
const { createMppPaymentProvider } = await importOptionalPeer(
|
|
6219
|
-
"payments.mpp",
|
|
6220
|
-
() => import('./provider-I2ESL6RS.js')
|
|
6221
|
-
);
|
|
6222
|
-
providers.push(
|
|
6223
|
-
createMppPaymentProvider({
|
|
6224
|
-
recipient: mpp.recipient,
|
|
6225
|
-
asset: mpp.asset,
|
|
6226
|
-
assetName: mpp.assetName,
|
|
6227
|
-
assetVersion: mpp.assetVersion,
|
|
6228
|
-
network: mpp.network,
|
|
6229
|
-
realm: mpp.realm,
|
|
6230
|
-
challengeSecret: mpp.challengeSecret,
|
|
6231
|
-
...mpp.challengeTtlSeconds !== void 0 ? { challengeTtlSeconds: mpp.challengeTtlSeconds } : {},
|
|
6232
|
-
rpcUrl: mpp.rpcUrl,
|
|
6233
|
-
facilitator: mpp.facilitator,
|
|
6234
|
-
...mpp.allowMainnet !== void 0 ? { allowMainnet: mpp.allowMainnet } : {},
|
|
6235
|
-
...mpp.allowUnauthenticatedFacilitator !== void 0 ? { allowUnauthenticatedFacilitator: mpp.allowUnauthenticatedFacilitator } : {},
|
|
6236
|
-
...mpp.paymentFlow !== void 0 ? { paymentFlow: mpp.paymentFlow } : {},
|
|
6237
|
-
...mpp.resourcePaymentFlows !== void 0 ? { resourcePaymentFlows: mpp.resourcePaymentFlows } : {},
|
|
6238
|
-
logger
|
|
6239
|
-
})
|
|
6240
|
-
);
|
|
6241
|
-
}
|
|
6242
|
-
return providers;
|
|
6243
|
-
}
|
|
6244
|
-
|
|
6245
6278
|
// src/gateway/access-control.ts
|
|
6246
6279
|
var CORS_METHODS = "GET,POST,OPTIONS";
|
|
6247
6280
|
var CORS_HEADERS = [
|
|
@@ -6776,6 +6809,15 @@ function buildWellKnownDocument(options) {
|
|
|
6776
6809
|
|
|
6777
6810
|
// src/gateway/routes.ts
|
|
6778
6811
|
var X402_V1_PAYMENT_HEADER = "x-payment";
|
|
6812
|
+
var RESOLVE_BODY_LIMIT_BYTES = 4096;
|
|
6813
|
+
var RESOLVE_FIELDS = [
|
|
6814
|
+
"status",
|
|
6815
|
+
"actor",
|
|
6816
|
+
"reason",
|
|
6817
|
+
"externalReference",
|
|
6818
|
+
"confirmExpired"
|
|
6819
|
+
];
|
|
6820
|
+
var TRANSACTION_EVENT_LIMIT = 50;
|
|
6779
6821
|
function registerRoutes(options) {
|
|
6780
6822
|
const { server } = options;
|
|
6781
6823
|
const readinessProbe = createReadinessProbe({
|
|
@@ -6843,6 +6885,113 @@ function registerRoutes(options) {
|
|
|
6843
6885
|
)
|
|
6844
6886
|
)
|
|
6845
6887
|
);
|
|
6888
|
+
const { store, clock } = options;
|
|
6889
|
+
const journal = () => journalOf(store);
|
|
6890
|
+
const withAge = (transaction) => ({
|
|
6891
|
+
...transaction,
|
|
6892
|
+
ageSeconds: Math.max(
|
|
6893
|
+
0,
|
|
6894
|
+
Math.floor((clock.now().getTime() - Date.parse(transaction.createdAt)) / 1e3)
|
|
6895
|
+
)
|
|
6896
|
+
});
|
|
6897
|
+
server.get(
|
|
6898
|
+
"/api/transactions",
|
|
6899
|
+
{ onRequest: tokenHook },
|
|
6900
|
+
operatorHandler(async (request) => {
|
|
6901
|
+
const query = request.query;
|
|
6902
|
+
const limit = parseLimit(query["limit"]);
|
|
6903
|
+
const state = parseText(query["state"]);
|
|
6904
|
+
if (state !== void 0 && !TRANSACTION_STATES.includes(state)) {
|
|
6905
|
+
throw new CommerceError("INPUT_INVALID", `Unknown transaction state "${state}"`, {
|
|
6906
|
+
details: { field: "state" }
|
|
6907
|
+
});
|
|
6908
|
+
}
|
|
6909
|
+
const requestId = parseText(query["requestId"]);
|
|
6910
|
+
const cursor = parseText(query["cursor"]);
|
|
6911
|
+
const page = await journal().listTransactions({
|
|
6912
|
+
...limit !== void 0 ? { limit } : {},
|
|
6913
|
+
...parseFlag(query["unresolved"], "unresolved") ? { unresolved: true } : {},
|
|
6914
|
+
...state !== void 0 ? { state } : {},
|
|
6915
|
+
...requestId !== void 0 ? { requestId } : {},
|
|
6916
|
+
...cursor !== void 0 ? { cursor } : {}
|
|
6917
|
+
});
|
|
6918
|
+
return {
|
|
6919
|
+
transactions: page.transactions.map(withAge),
|
|
6920
|
+
...page.nextCursor !== void 0 ? { nextCursor: page.nextCursor } : {}
|
|
6921
|
+
};
|
|
6922
|
+
})
|
|
6923
|
+
);
|
|
6924
|
+
server.get(
|
|
6925
|
+
"/api/transactions/:id",
|
|
6926
|
+
{ onRequest: tokenHook },
|
|
6927
|
+
operatorHandler(async (request) => {
|
|
6928
|
+
const id = request.params.id;
|
|
6929
|
+
const transaction = await journal().getTransaction(id);
|
|
6930
|
+
if (transaction === void 0) {
|
|
6931
|
+
throw new CommerceError("RESOURCE_NOT_FOUND", `Transaction "${id}" was not found`);
|
|
6932
|
+
}
|
|
6933
|
+
const [attempt, receipt, events] = await Promise.all([
|
|
6934
|
+
journal().getPaymentAttempt(transaction.payment.attemptId),
|
|
6935
|
+
transaction.receiptId !== void 0 ? store.getReceipt(transaction.receiptId) : void 0,
|
|
6936
|
+
store.listEvents({ requestId: transaction.requestId, limit: TRANSACTION_EVENT_LIMIT })
|
|
6937
|
+
]);
|
|
6938
|
+
return {
|
|
6939
|
+
transaction: withAge(transaction),
|
|
6940
|
+
...attempt !== void 0 ? { attempt } : {},
|
|
6941
|
+
...receipt !== void 0 ? { receipt } : {},
|
|
6942
|
+
events
|
|
6943
|
+
};
|
|
6944
|
+
})
|
|
6945
|
+
);
|
|
6946
|
+
server.post(
|
|
6947
|
+
"/api/payment-attempts/:id/resolve",
|
|
6948
|
+
{ onRequest: tokenHook, bodyLimit: RESOLVE_BODY_LIMIT_BYTES },
|
|
6949
|
+
operatorHandler(async (request) => {
|
|
6950
|
+
const result = await resolveManually({
|
|
6951
|
+
store,
|
|
6952
|
+
authorizationProviders: options.authorizationProviders,
|
|
6953
|
+
clock,
|
|
6954
|
+
logger: options.logger,
|
|
6955
|
+
attemptId: request.params.id,
|
|
6956
|
+
...parseResolveBody(request.body)
|
|
6957
|
+
});
|
|
6958
|
+
if (!result.resolved) {
|
|
6959
|
+
throw new CommerceError("INPUT_INVALID", result.message, {
|
|
6960
|
+
httpStatus: 409,
|
|
6961
|
+
details: { reason: result.refusal, attemptStatus: result.attempt.status }
|
|
6962
|
+
});
|
|
6963
|
+
}
|
|
6964
|
+
return {
|
|
6965
|
+
attempt: result.attempt,
|
|
6966
|
+
...result.hold !== void 0 ? { hold: result.hold } : {}
|
|
6967
|
+
};
|
|
6968
|
+
})
|
|
6969
|
+
);
|
|
6970
|
+
}
|
|
6971
|
+
function parseResolveBody(body) {
|
|
6972
|
+
if (!isRecord(body)) {
|
|
6973
|
+
throw new CommerceError("INPUT_INVALID", "The request body must be a JSON object");
|
|
6974
|
+
}
|
|
6975
|
+
const field = (name, type, required) => {
|
|
6976
|
+
const value = body[name];
|
|
6977
|
+
if (value === void 0 && required || value !== void 0 && typeof value !== type) {
|
|
6978
|
+
throw new CommerceError("INPUT_INVALID", `Field "${name}" must be a ${type}`, {
|
|
6979
|
+
details: { field: name }
|
|
6980
|
+
});
|
|
6981
|
+
}
|
|
6982
|
+
};
|
|
6983
|
+
const unknownField = Object.keys(body).find((name) => !RESOLVE_FIELDS.includes(name));
|
|
6984
|
+
if (unknownField !== void 0) {
|
|
6985
|
+
throw new CommerceError("INPUT_INVALID", `Unknown field "${unknownField}"`, {
|
|
6986
|
+
details: { field: unknownField }
|
|
6987
|
+
});
|
|
6988
|
+
}
|
|
6989
|
+
field("status", "string", true);
|
|
6990
|
+
field("actor", "string", true);
|
|
6991
|
+
field("reason", "string", true);
|
|
6992
|
+
field("externalReference", "string", false);
|
|
6993
|
+
field("confirmExpired", "boolean", false);
|
|
6994
|
+
return body;
|
|
6846
6995
|
}
|
|
6847
6996
|
var bodyDigests = /* @__PURE__ */ new WeakMap();
|
|
6848
6997
|
function digestingStream(request) {
|
|
@@ -6858,13 +7007,10 @@ function digestingStream(request) {
|
|
|
6858
7007
|
}
|
|
6859
7008
|
});
|
|
6860
7009
|
}
|
|
6861
|
-
function
|
|
7010
|
+
function operatorHandler(handle) {
|
|
6862
7011
|
return async (request, reply) => {
|
|
6863
7012
|
try {
|
|
6864
|
-
|
|
6865
|
-
const limit = parseLimit(query["limit"]);
|
|
6866
|
-
const page = await list(limit !== void 0 ? { limit } : {}, query);
|
|
6867
|
-
return { [key]: page };
|
|
7013
|
+
return await handle(request, reply);
|
|
6868
7014
|
} catch (error) {
|
|
6869
7015
|
const commerceError = toCommerceError(error);
|
|
6870
7016
|
reply.status(commerceError.httpStatus).send(toErrorEnvelope(commerceError));
|
|
@@ -6872,6 +7018,14 @@ function ledgerHandler(key, list) {
|
|
|
6872
7018
|
}
|
|
6873
7019
|
};
|
|
6874
7020
|
}
|
|
7021
|
+
function ledgerHandler(key, list) {
|
|
7022
|
+
return operatorHandler(async (request) => {
|
|
7023
|
+
const query = request.query;
|
|
7024
|
+
const limit = parseLimit(query["limit"]);
|
|
7025
|
+
const page = await list(limit !== void 0 ? { limit } : {}, query);
|
|
7026
|
+
return { [key]: page };
|
|
7027
|
+
});
|
|
7028
|
+
}
|
|
6875
7029
|
async function handleInvoke(request, reply, options) {
|
|
6876
7030
|
const resourceId = request.params.id;
|
|
6877
7031
|
let paymentMethod;
|
|
@@ -7052,6 +7206,10 @@ function parseLimit(value) {
|
|
|
7052
7206
|
}
|
|
7053
7207
|
return n;
|
|
7054
7208
|
}
|
|
7209
|
+
function parseText(value) {
|
|
7210
|
+
if (Array.isArray(value)) return parseText(value[0]);
|
|
7211
|
+
return typeof value === "string" && value !== "" ? value : void 0;
|
|
7212
|
+
}
|
|
7055
7213
|
function parseFlag(value, field) {
|
|
7056
7214
|
if (Array.isArray(value)) return parseFlag(value[0], field);
|
|
7057
7215
|
if (value === void 0 || value === "false") return false;
|
|
@@ -7163,8 +7321,14 @@ async function createGateway(options) {
|
|
|
7163
7321
|
return { url };
|
|
7164
7322
|
},
|
|
7165
7323
|
async close() {
|
|
7324
|
+
const sweep = setInterval(() => server.server.closeIdleConnections(), 100);
|
|
7325
|
+
sweep.unref();
|
|
7326
|
+
try {
|
|
7327
|
+
await server.close();
|
|
7328
|
+
} finally {
|
|
7329
|
+
clearInterval(sweep);
|
|
7330
|
+
}
|
|
7166
7331
|
await stopAdapters(adapterRuntimes, logger);
|
|
7167
|
-
await server.close();
|
|
7168
7332
|
},
|
|
7169
7333
|
server
|
|
7170
7334
|
};
|
|
@@ -7185,17 +7349,32 @@ async function runGateway(options = {}) {
|
|
|
7185
7349
|
const { core: logger } = createGatewayLogger({ name: config.merchant.id });
|
|
7186
7350
|
const paymentProviders = await createConfiguredPaymentProviders(config.payments, logger);
|
|
7187
7351
|
const ap2 = config.authorization?.ap2;
|
|
7188
|
-
const ap2Module = ap2?.enabled ? await importOptionalPeer("authorization.ap2", () => import('./ap2-
|
|
7352
|
+
const ap2Module = ap2?.enabled ? await importOptionalPeer("authorization.ap2", () => import('./ap2-2YMYA2H6.js')) : void 0;
|
|
7189
7353
|
const mcp = config.protocols.mcp;
|
|
7190
|
-
const mcpModule = mcp.enabled ? await importOptionalPeer("protocols.mcp", () => import('./mcp-
|
|
7354
|
+
const mcpModule = mcp.enabled ? await importOptionalPeer("protocols.mcp", () => import('./mcp-6F64A7KE.js')) : void 0;
|
|
7355
|
+
const acp = config.protocols.acp;
|
|
7356
|
+
const ap2Replay = ap2?.enabled ? ap2.replay?.path : void 0;
|
|
7357
|
+
const acpIdempotency = acp.enabled ? acp.idempotency.path : void 0;
|
|
7191
7358
|
const store = createSqliteReceiptStore({
|
|
7192
7359
|
path: config.storage.receipts.path,
|
|
7193
|
-
logger
|
|
7360
|
+
logger,
|
|
7361
|
+
legacyStores: {
|
|
7362
|
+
...ap2Replay !== void 0 ? { ap2Replay } : {},
|
|
7363
|
+
...acpIdempotency !== void 0 ? { acpIdempotency } : {},
|
|
7364
|
+
enabled: { ap2: ap2?.enabled === true, acp: acp.enabled }
|
|
7365
|
+
}
|
|
7194
7366
|
});
|
|
7195
|
-
|
|
7367
|
+
try {
|
|
7368
|
+
await store.init();
|
|
7369
|
+
} catch (error) {
|
|
7370
|
+
await store.close();
|
|
7371
|
+
throw error;
|
|
7372
|
+
}
|
|
7196
7373
|
const authorizationProviders = [];
|
|
7197
7374
|
if (ap2?.enabled && ap2Module !== void 0) {
|
|
7198
|
-
authorizationProviders.push(
|
|
7375
|
+
authorizationProviders.push(
|
|
7376
|
+
ap2Module.createAp2AuthorizationProvider({ config: ap2, logger, store })
|
|
7377
|
+
);
|
|
7199
7378
|
}
|
|
7200
7379
|
const paidWithoutProvider = config.resources.filter(
|
|
7201
7380
|
(resource) => resource.pricing.type !== "free" && !resource.paymentMethods.some(
|
|
@@ -7218,11 +7397,11 @@ async function runGateway(options = {}) {
|
|
|
7218
7397
|
mountPath: config.protocols.a2a.mountPath,
|
|
7219
7398
|
// The Agent Card names the merchant, not the software: a client
|
|
7220
7399
|
// picking between agents is choosing whose resources to buy
|
|
7221
|
-
agentName: config.merchant.name
|
|
7400
|
+
agentName: config.merchant.name,
|
|
7401
|
+
store
|
|
7222
7402
|
})
|
|
7223
7403
|
);
|
|
7224
7404
|
}
|
|
7225
|
-
const acp = config.protocols.acp;
|
|
7226
7405
|
if (acp.enabled) {
|
|
7227
7406
|
protocolAdapters.push(
|
|
7228
7407
|
createAcpAdapter({
|
|
@@ -7230,6 +7409,7 @@ async function runGateway(options = {}) {
|
|
|
7230
7409
|
token: acp.auth.token,
|
|
7231
7410
|
operations: acp.checkout.operations,
|
|
7232
7411
|
idempotency: acp.idempotency,
|
|
7412
|
+
store,
|
|
7233
7413
|
...acp.discovery !== void 0 ? { discovery: acp.discovery } : {}
|
|
7234
7414
|
})
|
|
7235
7415
|
);
|
|
@@ -7286,7 +7466,10 @@ async function runGateway(options = {}) {
|
|
|
7286
7466
|
}
|
|
7287
7467
|
let shuttingDown = false;
|
|
7288
7468
|
const shutdown = (signal) => {
|
|
7289
|
-
if (shuttingDown)
|
|
7469
|
+
if (shuttingDown) {
|
|
7470
|
+
logger.warn({ signal }, "second signal, exiting without waiting for in-flight requests");
|
|
7471
|
+
process.exit(1);
|
|
7472
|
+
}
|
|
7290
7473
|
shuttingDown = true;
|
|
7291
7474
|
logger.info({ signal }, "shutting down");
|
|
7292
7475
|
void (async () => {
|
|
@@ -7318,5 +7501,5 @@ function printStartupError(error) {
|
|
|
7318
7501
|
}
|
|
7319
7502
|
|
|
7320
7503
|
export { printStartupError, runGateway };
|
|
7321
|
-
//# sourceMappingURL=run-
|
|
7322
|
-
//# sourceMappingURL=run-
|
|
7504
|
+
//# sourceMappingURL=run-2P6ZGFUE.js.map
|
|
7505
|
+
//# sourceMappingURL=run-2P6ZGFUE.js.map
|