@devlab.group/agent-commerce 2.6.0 → 2.7.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 +17 -12
- package/dist/ap2.d.ts +1 -1
- package/dist/ap2.js +5 -5
- package/dist/{chunk-ES3V6ECS.js → chunk-77HLISG4.js} +3 -2
- package/dist/chunk-77HLISG4.js.map +1 -0
- package/dist/{chunk-5ZYXBCDX.js → chunk-D7FPSGUQ.js} +25 -4
- package/dist/chunk-D7FPSGUQ.js.map +1 -0
- package/dist/{chunk-G3EYYHKF.js → chunk-DJRWYDKJ.js} +3 -3
- package/dist/{chunk-G3EYYHKF.js.map → chunk-DJRWYDKJ.js.map} +1 -1
- package/dist/{chunk-M6MQ3FYS.js → chunk-EMKITGVV.js} +4 -4
- package/dist/chunk-EMKITGVV.js.map +1 -0
- package/dist/chunk-IWXVQYG5.js +6 -0
- package/dist/chunk-IWXVQYG5.js.map +1 -0
- package/dist/chunk-O3ACF45K.js +8 -0
- package/dist/{chunk-M6BSXXTF.js.map → chunk-O3ACF45K.js.map} +1 -1
- package/dist/{chunk-M6WW6QIT.js → chunk-WDD2ZUR3.js} +5 -3
- package/dist/chunk-WDD2ZUR3.js.map +1 -0
- package/dist/{chunk-M52FBNJX.js → chunk-YHNTTMED.js} +6 -4
- package/dist/chunk-YHNTTMED.js.map +1 -0
- package/dist/{chunk-DRLBML7Z.js → chunk-ZSIUZPNB.js} +175 -74
- package/dist/chunk-ZSIUZPNB.js.map +1 -0
- package/dist/cli/{ap2-2YMYA2H6.js → ap2-5FFGSW6F.js} +10 -11
- package/dist/cli/ap2-5FFGSW6F.js.map +1 -0
- package/dist/cli/{chunk-5K4XEAZV.js → chunk-3IEXJ7I3.js} +25 -4
- package/dist/cli/chunk-3IEXJ7I3.js.map +1 -0
- package/dist/cli/{chunk-VJH6RYRK.js → chunk-3NVJAQRO.js} +3 -3
- package/dist/cli/{chunk-VJH6RYRK.js.map → chunk-3NVJAQRO.js.map} +1 -1
- package/dist/cli/{chunk-GET3CZGR.js → chunk-55AI6CLW.js} +6 -4
- package/dist/cli/chunk-55AI6CLW.js.map +1 -0
- package/dist/cli/{chunk-YOF7IK4V.js → chunk-5K2JDM4G.js} +177 -76
- package/dist/cli/chunk-5K2JDM4G.js.map +1 -0
- package/dist/cli/{chunk-NSYSMDQN.js → chunk-5TID36YG.js} +57 -29
- package/dist/cli/chunk-5TID36YG.js.map +1 -0
- package/dist/cli/{chunk-3NOMLMJW.js → chunk-66NTYSXI.js} +3 -3
- package/dist/cli/{chunk-3NOMLMJW.js.map → chunk-66NTYSXI.js.map} +1 -1
- package/dist/cli/{chunk-VJ4EO4LE.js → chunk-6EBDOH37.js} +3 -3
- package/dist/cli/{chunk-VJ4EO4LE.js.map → chunk-6EBDOH37.js.map} +1 -1
- package/dist/cli/{chunk-YWG2ZN3L.js → chunk-AGQ4U7IN.js} +5 -5
- package/dist/cli/chunk-AGQ4U7IN.js.map +1 -0
- package/dist/cli/chunk-APC5BTQM.js +6 -0
- package/dist/cli/chunk-APC5BTQM.js.map +1 -0
- package/dist/cli/{chunk-SYQLJXIU.js → chunk-C5YISPT6.js} +3 -3
- package/dist/cli/chunk-C5YISPT6.js.map +1 -0
- package/dist/cli/chunk-DKWO6LLX.js +34 -0
- package/dist/cli/chunk-DKWO6LLX.js.map +1 -0
- package/dist/cli/{chunk-SPAYKVUP.js → chunk-FL4HPCD4.js} +3 -2
- package/dist/cli/chunk-FL4HPCD4.js.map +1 -0
- package/dist/cli/{chunk-3EQBCFZY.js → chunk-H7EBJ4I3.js} +3 -3
- package/dist/cli/{chunk-3EQBCFZY.js.map → chunk-H7EBJ4I3.js.map} +1 -1
- package/dist/cli/{chunk-PTL7SNOI.js → chunk-OETKXDGA.js} +467 -122
- package/dist/cli/chunk-OETKXDGA.js.map +1 -0
- package/dist/cli/{chunk-DHFMIBPG.js → chunk-PLHPKXAT.js} +6 -6
- package/dist/cli/{chunk-DHFMIBPG.js.map → chunk-PLHPKXAT.js.map} +1 -1
- package/dist/cli/{chunk-TFV3K6YS.js → chunk-VSSSU4AU.js} +3 -3
- package/dist/cli/{chunk-TFV3K6YS.js.map → chunk-VSSSU4AU.js.map} +1 -1
- package/dist/cli/chunk-ZCW56PZ3.js +8 -0
- package/dist/cli/{chunk-4KLYFXMW.js.map → chunk-ZCW56PZ3.js.map} +1 -1
- package/dist/cli/{chunk-AZL7RPFU.js → chunk-ZFVQWOGG.js} +64 -16
- package/dist/cli/chunk-ZFVQWOGG.js.map +1 -0
- package/dist/cli/config-WT5HHDRR.js +13 -0
- package/dist/cli/{config-3K65QJ22.js.map → config-WT5HHDRR.js.map} +1 -1
- package/dist/cli/index.js +51 -37
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/{mcp-6F64A7KE.js → mcp-HHGNOUKE.js} +7 -7
- package/dist/cli/{mcp-6F64A7KE.js.map → mcp-HHGNOUKE.js.map} +1 -1
- package/dist/cli/payment-providers-EWXZFBIE.js +6 -0
- package/dist/cli/{payment-providers-2ITS6KNR.js.map → payment-providers-EWXZFBIE.js.map} +1 -1
- package/dist/cli/{provider-5BGG5YKQ.js → provider-XUPLYNQ7.js} +9 -9
- package/dist/cli/{provider-5BGG5YKQ.js.map → provider-XUPLYNQ7.js.map} +1 -1
- package/dist/cli/receipts-3DSV4DIK.js +9 -0
- package/dist/cli/{receipts-I4IIE7U6.js.map → receipts-3DSV4DIK.js.map} +1 -1
- package/dist/cli/reconcile-GS25MQ42.js +4 -0
- package/dist/cli/{reconcile-55WNCSFC.js.map → reconcile-GS25MQ42.js.map} +1 -1
- package/dist/cli/{run-2P6ZGFUE.js → run-7KLKW3HE.js} +107 -35
- package/dist/cli/run-7KLKW3HE.js.map +1 -0
- package/dist/cli/{x402-4LPIIELI.js → x402-HP4E3QET.js} +11 -10
- package/dist/cli/x402-HP4E3QET.js.map +1 -0
- package/dist/{guardrails-CX_jYXvZ.d.ts → guardrails-CeyLS1ou.d.ts} +2 -2
- package/dist/index.d.ts +23 -13
- package/dist/index.js +660 -170
- package/dist/index.js.map +1 -1
- package/dist/mcp.d.ts +2 -2
- package/dist/mcp.js +4 -4
- package/dist/mpp.js +5 -5
- package/dist/{protocol-adapter-1WbtM3xG.d.ts → protocol-adapter-DdFL5LBU.d.ts} +12 -2
- package/dist/{runtime-B-kARa2f.d.ts → runtime-BmaSp2Ce.d.ts} +31 -3
- package/dist/{store-kIIMpUA-.d.ts → store-BVvMzpuV.d.ts} +25 -8
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +156 -2
- package/dist/testing.js.map +1 -1
- package/dist/{transaction-Dv0UFGg5.d.ts → transaction-BXXJltZ-.d.ts} +1 -1
- package/dist/x402.d.ts +7 -2
- package/dist/x402.js +7 -6
- package/dist/x402.js.map +1 -1
- package/package.json +13 -29
- package/dist/chunk-5ZYXBCDX.js.map +0 -1
- package/dist/chunk-DRLBML7Z.js.map +0 -1
- package/dist/chunk-ES3V6ECS.js.map +0 -1
- package/dist/chunk-M52FBNJX.js.map +0 -1
- package/dist/chunk-M6BSXXTF.js +0 -8
- package/dist/chunk-M6MQ3FYS.js.map +0 -1
- package/dist/chunk-M6WW6QIT.js.map +0 -1
- package/dist/cli/ap2-2YMYA2H6.js.map +0 -1
- package/dist/cli/chunk-4KLYFXMW.js +0 -8
- package/dist/cli/chunk-5K4XEAZV.js.map +0 -1
- package/dist/cli/chunk-6R6WJ4FD.js +0 -18
- package/dist/cli/chunk-6R6WJ4FD.js.map +0 -1
- package/dist/cli/chunk-AZL7RPFU.js.map +0 -1
- package/dist/cli/chunk-FHCFR2GS.js +0 -17
- package/dist/cli/chunk-FHCFR2GS.js.map +0 -1
- package/dist/cli/chunk-GET3CZGR.js.map +0 -1
- package/dist/cli/chunk-NSYSMDQN.js.map +0 -1
- package/dist/cli/chunk-PTL7SNOI.js.map +0 -1
- package/dist/cli/chunk-SPAYKVUP.js.map +0 -1
- package/dist/cli/chunk-SYQLJXIU.js.map +0 -1
- package/dist/cli/chunk-YOF7IK4V.js.map +0 -1
- package/dist/cli/chunk-YWG2ZN3L.js.map +0 -1
- package/dist/cli/config-3K65QJ22.js +0 -12
- package/dist/cli/payment-providers-2ITS6KNR.js +0 -6
- package/dist/cli/receipts-I4IIE7U6.js +0 -8
- package/dist/cli/reconcile-55WNCSFC.js +0 -4
- package/dist/cli/run-2P6ZGFUE.js.map +0 -1
- package/dist/cli/x402-4LPIIELI.js.map +0 -1
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import './chunk-FHCFR2GS.js';
|
|
1
|
+
import { createConfiguredPaymentProviders, importOptionalPeer } from './chunk-PLHPKXAT.js';
|
|
2
|
+
import { readCappedBody, createBearerCheck, joinUrl, settlementResponse, settlementResponseFromDetails, settlementFailure, x402ErrorCode, x402RefusalStatus } from './chunk-FL4HPCD4.js';
|
|
3
|
+
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-3NVJAQRO.js';
|
|
4
|
+
import { loadConfig } from './chunk-ZFVQWOGG.js';
|
|
5
|
+
import { HttpBackendExecutor, createResourceRegistry, assertRetrySupport, 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-OETKXDGA.js';
|
|
6
|
+
import { hasMethodGroup } from './chunk-DKWO6LLX.js';
|
|
8
7
|
import './chunk-TPC4EJLT.js';
|
|
9
|
-
import { createSqliteReceiptStore } from './chunk-
|
|
10
|
-
import { openSqliteDatabase } from './chunk-
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
8
|
+
import { createSqliteReceiptStore } from './chunk-5TID36YG.js';
|
|
9
|
+
import { openSqliteDatabase } from './chunk-6EBDOH37.js';
|
|
10
|
+
import { PAYMENT_KEY_ENDPOINT_PREFIX } from './chunk-APC5BTQM.js';
|
|
11
|
+
import { resolveManually, journalOf } from './chunk-VSSSU4AU.js';
|
|
12
|
+
import { contentDigest, CONTENT_DIGEST_METADATA_KEY, mppProblem, mppProblemDetail } from './chunk-3IEXJ7I3.js';
|
|
13
13
|
import { MPP_DEFAULT_PAYMENT_FLOW, MPP_PROFILE } from './chunk-AA3FIEAR.js';
|
|
14
|
-
import { x402OfferName } from './chunk-
|
|
15
|
-
import { X402_DEFAULT_PAYMENT_FLOW, resolveDeploymentMode, requireX402Network } from './chunk-
|
|
16
|
-
import { PACKAGE_VERSION } from './chunk-
|
|
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-
|
|
18
|
-
import { CommerceError, isCommerceError, toLogInfo, toCommerceError } from './chunk-
|
|
14
|
+
import { x402OfferName } from './chunk-AGQ4U7IN.js';
|
|
15
|
+
import { X402_DEFAULT_PAYMENT_FLOW, resolveDeploymentMode, requireX402Network } from './chunk-66NTYSXI.js';
|
|
16
|
+
import { PACKAGE_VERSION } from './chunk-ZCW56PZ3.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-55AI6CLW.js';
|
|
18
|
+
import { CommerceError, isCommerceError, toLogInfo, toCommerceError } from './chunk-C5YISPT6.js';
|
|
19
19
|
import { isRecord } from './chunk-3M6U7ILB.js';
|
|
20
20
|
import { createHash, randomUUID } from 'crypto';
|
|
21
21
|
import { z } from 'zod';
|
|
@@ -417,7 +417,8 @@ function paymentFailureMetadata(error, network) {
|
|
|
417
417
|
[X402_PAYMENT_RECEIPTS_KEY]: [settled]
|
|
418
418
|
};
|
|
419
419
|
}
|
|
420
|
-
const
|
|
420
|
+
const reason = error.details?.["reason"];
|
|
421
|
+
const code = error.code.startsWith("PAYMENT_") || typeof reason === "string" && reason.startsWith("payment_identifier_") ? x402ErrorCode(error.code, reason, error.details?.["network"]) : error.code.toLowerCase();
|
|
421
422
|
const failure = settlementFailure(error.details);
|
|
422
423
|
const receipt = failure["network"] === "" && network !== void 0 ? { ...failure, network } : failure;
|
|
423
424
|
return {
|
|
@@ -683,6 +684,17 @@ async function resumePayment(context, pendingPayments, id, params) {
|
|
|
683
684
|
)
|
|
684
685
|
);
|
|
685
686
|
}
|
|
687
|
+
function withoutRetryDelay(error) {
|
|
688
|
+
if (error.details?.["reason"] !== "payment_identifier_in_flight") return error;
|
|
689
|
+
const { retryAfterSeconds: _delay, ...details } = error.details;
|
|
690
|
+
return new CommerceError(error.code, error.message, {
|
|
691
|
+
httpStatus: error.httpStatus,
|
|
692
|
+
retryable: false,
|
|
693
|
+
details,
|
|
694
|
+
...error.requestId !== void 0 ? { requestId: error.requestId } : {},
|
|
695
|
+
...error.resourceId !== void 0 ? { resourceId: error.resourceId } : {}
|
|
696
|
+
});
|
|
697
|
+
}
|
|
686
698
|
async function payPending(context, pending, payload, identity) {
|
|
687
699
|
const requestId = context.ids.next("a2a");
|
|
688
700
|
const request = {
|
|
@@ -711,16 +723,19 @@ async function payPending(context, pending, payload, identity) {
|
|
|
711
723
|
}
|
|
712
724
|
error = new CommerceError("PAYMENT_INVALID", "The payment was not accepted.", { requestId });
|
|
713
725
|
} catch (err) {
|
|
714
|
-
error = toCommerceError(err);
|
|
726
|
+
error = withoutRetryDelay(toCommerceError(err));
|
|
715
727
|
context.logger.warn(
|
|
716
728
|
{ resourceId: pending.resourceId, requestId, err: toLogInfo(error) },
|
|
717
729
|
"a2a adapter: x402 extension payment failed"
|
|
718
730
|
);
|
|
719
731
|
}
|
|
720
732
|
const metadata = paymentFailureMetadata(error, pending.network);
|
|
733
|
+
const reason = error.details?.["reason"];
|
|
721
734
|
let text = "Payment failed.";
|
|
722
735
|
if (metadata[X402_PAYMENT_STATUS_KEY] === "payment-completed") {
|
|
723
736
|
text = "Payment settled, but the resource could not be delivered.";
|
|
737
|
+
} else if (typeof reason === "string" && reason.startsWith("payment_identifier_")) {
|
|
738
|
+
text = error.message;
|
|
724
739
|
} else if (!error.code.startsWith("PAYMENT_")) {
|
|
725
740
|
text = "The resource could not be delivered.";
|
|
726
741
|
}
|
|
@@ -1163,9 +1178,16 @@ function sha256(value) {
|
|
|
1163
1178
|
return createHash("sha256").update(value, "utf8").digest("hex");
|
|
1164
1179
|
}
|
|
1165
1180
|
|
|
1181
|
+
// src/core/idempotency-key.ts
|
|
1182
|
+
var MAX_IDEMPOTENCY_KEY_LENGTH = 255;
|
|
1183
|
+
var USABLE_KEY = new RegExp(`^[\\x20-\\x7e]{1,${MAX_IDEMPOTENCY_KEY_LENGTH}}$`);
|
|
1184
|
+
function isUsableIdempotencyKey(value) {
|
|
1185
|
+
return USABLE_KEY.test(value);
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1166
1188
|
// src/protocols/acp/idempotency/store.ts
|
|
1167
1189
|
var SCHEMA_VERSION = 2;
|
|
1168
|
-
var ACP_MAX_IDEMPOTENCY_KEY_LENGTH =
|
|
1190
|
+
var ACP_MAX_IDEMPOTENCY_KEY_LENGTH = MAX_IDEMPOTENCY_KEY_LENGTH;
|
|
1169
1191
|
function createAcpIdempotencyStore(options) {
|
|
1170
1192
|
const logger = options.logger ?? NOOP_LOGGER;
|
|
1171
1193
|
const now = options.now ?? (() => Date.now());
|
|
@@ -5586,9 +5608,6 @@ function forwardedHeaders(req, requestId) {
|
|
|
5586
5608
|
}
|
|
5587
5609
|
return forwarded;
|
|
5588
5610
|
}
|
|
5589
|
-
function isUsableIdempotencyKey(value) {
|
|
5590
|
-
return value.length > 0 && value.length <= ACP_MAX_IDEMPOTENCY_KEY_LENGTH && isVisibleAscii(value);
|
|
5591
|
-
}
|
|
5592
5611
|
function normalizeRequestId(value) {
|
|
5593
5612
|
if (value === void 0) return void 0;
|
|
5594
5613
|
const trimmed = value.trim().slice(0, ACP_MAX_REQUEST_ID_LENGTH);
|
|
@@ -5943,7 +5962,7 @@ var AcpProtocolAdapter = class {
|
|
|
5943
5962
|
const release = merchantIdempotent === true;
|
|
5944
5963
|
const store = this.store;
|
|
5945
5964
|
if (hasMethodGroup(store, "idempotency_claims")) {
|
|
5946
|
-
const recovered = await store.recoverIdempotencyKeys({ release });
|
|
5965
|
+
const recovered = await store.recoverIdempotencyKeys({ release, endpointPrefix: "/" });
|
|
5947
5966
|
warnOrphanedClaims(context.logger, recovered, release);
|
|
5948
5967
|
return backendOverReceiptStore(store, context.clock, retentionHours);
|
|
5949
5968
|
}
|
|
@@ -6215,7 +6234,12 @@ var SECRET_FIELD_NAMES = [
|
|
|
6215
6234
|
"adminToken",
|
|
6216
6235
|
"token"
|
|
6217
6236
|
];
|
|
6218
|
-
var SECRET_HEADERS = [
|
|
6237
|
+
var SECRET_HEADERS = [
|
|
6238
|
+
"authorization",
|
|
6239
|
+
PAYMENT_HEADER,
|
|
6240
|
+
AUTHORIZATION_HEADER,
|
|
6241
|
+
"idempotency-key"
|
|
6242
|
+
];
|
|
6219
6243
|
var REDACT_PATHS = [
|
|
6220
6244
|
...SECRET_HEADERS.map((name) => `req.headers[${JSON.stringify(name)}]`),
|
|
6221
6245
|
...SECRET_FIELD_NAMES,
|
|
@@ -7040,6 +7064,7 @@ async function handleInvoke(request, reply, options) {
|
|
|
7040
7064
|
paymentMethod = resource.paymentMethods[0];
|
|
7041
7065
|
const paymentValue = paymentProof(request, paymentMethod);
|
|
7042
7066
|
const payment = paymentValue !== void 0 && paymentMethod !== void 0 ? { method: paymentMethod, payload: paymentValue } : void 0;
|
|
7067
|
+
const retryKey = paymentMethod === "mpp" && resource.idempotency?.redelivery !== void 0 ? mppRetryKey(request, resourceId) : void 0;
|
|
7043
7068
|
const authorization = parseAuthorizationHeader(
|
|
7044
7069
|
request.headers[AUTHORIZATION_HEADER],
|
|
7045
7070
|
request.id
|
|
@@ -7052,6 +7077,7 @@ async function handleInvoke(request, reply, options) {
|
|
|
7052
7077
|
protocol: "http",
|
|
7053
7078
|
receivedAt: options.clock.nowIso(),
|
|
7054
7079
|
...payment !== void 0 ? { payment } : {},
|
|
7080
|
+
...retryKey !== void 0 ? { retryKey } : {},
|
|
7055
7081
|
...authorization !== void 0 ? { authorization } : {},
|
|
7056
7082
|
...digest !== void 0 ? { metadata: { [CONTENT_DIGEST_METADATA_KEY]: digest } } : {}
|
|
7057
7083
|
};
|
|
@@ -7090,11 +7116,13 @@ async function handleInvoke(request, reply, options) {
|
|
|
7090
7116
|
encodeHeaderDocument(settlementResponse(outcome.payment))
|
|
7091
7117
|
);
|
|
7092
7118
|
const receipt = outcome.payment.metadata?.["receipt"];
|
|
7093
|
-
|
|
7119
|
+
const success = outcome.backendStatus >= 200 && outcome.backendStatus < 300;
|
|
7120
|
+
if (outcome.payment.provider === "mpp" && typeof receipt === "string" && (success || outcome.redelivered !== true)) {
|
|
7094
7121
|
reply.header("payment-receipt", receipt);
|
|
7095
7122
|
}
|
|
7096
7123
|
reply.header("cache-control", "private");
|
|
7097
7124
|
}
|
|
7125
|
+
if (outcome.redelivered === true) reply.header("idempotent-replayed", "true");
|
|
7098
7126
|
const contentType = relayedContentType(outcome.headers?.["content-type"], outcome.body);
|
|
7099
7127
|
if (contentType !== void 0) reply.type(contentType);
|
|
7100
7128
|
if (typeof outcome.body === "string") {
|
|
@@ -7134,9 +7162,14 @@ var MPP_PROBLEM_CODES = /* @__PURE__ */ new Set([
|
|
|
7134
7162
|
]);
|
|
7135
7163
|
function sendInvokeError(reply, error, paymentMethod) {
|
|
7136
7164
|
const details = error.details;
|
|
7165
|
+
const reason = typeof details?.["reason"] === "string" ? details["reason"] : void 0;
|
|
7137
7166
|
if (PROVIDER_UNAVAILABLE_CODES.has(error.code)) {
|
|
7138
7167
|
reply.header("retry-after", String(PROVIDER_RETRY_AFTER_SECONDS));
|
|
7139
7168
|
}
|
|
7169
|
+
const retryAfter = details?.["retryAfterSeconds"];
|
|
7170
|
+
if (typeof retryAfter === "number" && Number.isSafeInteger(retryAfter) && retryAfter >= 0) {
|
|
7171
|
+
reply.header("retry-after", String(retryAfter));
|
|
7172
|
+
}
|
|
7140
7173
|
const settled = settlementResponseFromDetails(details);
|
|
7141
7174
|
if (settled !== void 0) {
|
|
7142
7175
|
reply.header(PAYMENT_RESPONSE_HEADER, encodeHeaderDocument(settled));
|
|
@@ -7160,12 +7193,12 @@ function sendInvokeError(reply, error, paymentMethod) {
|
|
|
7160
7193
|
reply.header("cache-control", "no-store");
|
|
7161
7194
|
}
|
|
7162
7195
|
const envelope = toErrorEnvelope(error);
|
|
7163
|
-
if (paymentMethod === "mpp" && MPP_PROBLEM_CODES.has(error.code)) {
|
|
7196
|
+
if (paymentMethod === "mpp" && (MPP_PROBLEM_CODES.has(error.code) || reason?.startsWith("payment_identifier_") === true)) {
|
|
7164
7197
|
const { status: _envelopeStatus, ...members } = envelope;
|
|
7165
|
-
const
|
|
7166
|
-
reply.header("content-type", "application/problem+json").status(
|
|
7167
|
-
...mppProblem(error.code,
|
|
7168
|
-
status:
|
|
7198
|
+
const problemStatus = reason === "payment_identifier_conflict" ? 422 : error.httpStatus;
|
|
7199
|
+
reply.header("content-type", "application/problem+json").status(problemStatus).send({
|
|
7200
|
+
...mppProblem(error.code, problemStatus, reason),
|
|
7201
|
+
status: problemStatus,
|
|
7169
7202
|
// The reason token stays in `message` and `details.reason`
|
|
7170
7203
|
detail: mppProblemDetail(reason, error.message),
|
|
7171
7204
|
...members
|
|
@@ -7175,6 +7208,21 @@ function sendInvokeError(reply, error, paymentMethod) {
|
|
|
7175
7208
|
const status = paymentMethod === "x402" ? x402RefusalStatus(error.code, error.httpStatus, details?.["reason"]) : error.httpStatus;
|
|
7176
7209
|
reply.status(status).send(envelope);
|
|
7177
7210
|
}
|
|
7211
|
+
var SF_STRING = /^"((?:[\x20\x21\x23-\x5b\x5d-\x7e]|\\["\\])*)"$/;
|
|
7212
|
+
function mppRetryKey(request, resourceId) {
|
|
7213
|
+
const value = request.headers["idempotency-key"];
|
|
7214
|
+
if (value === void 0) return void 0;
|
|
7215
|
+
if (typeof value === "string") {
|
|
7216
|
+
const trimmed = value.trim();
|
|
7217
|
+
const key = trimmed.startsWith('"') ? SF_STRING.exec(trimmed)?.[1]?.replace(/\\(["\\])/g, "$1") : trimmed;
|
|
7218
|
+
if (key !== void 0 && isUsableIdempotencyKey(key)) return key;
|
|
7219
|
+
}
|
|
7220
|
+
throw new CommerceError(
|
|
7221
|
+
"INPUT_INVALID",
|
|
7222
|
+
"The Idempotency-Key header must be 1 to 255 printable ASCII characters",
|
|
7223
|
+
{ requestId: request.id, resourceId, details: { reason: "payment_identifier_invalid" } }
|
|
7224
|
+
);
|
|
7225
|
+
}
|
|
7178
7226
|
function paymentProof(request, method) {
|
|
7179
7227
|
if (method === "mpp") {
|
|
7180
7228
|
const value2 = request.headers.authorization;
|
|
@@ -7235,6 +7283,25 @@ function withProviderBackedMethodsFirst(resource, providers) {
|
|
|
7235
7283
|
];
|
|
7236
7284
|
return ordered.some((method, i) => method !== resource.paymentMethods[i]) ? { ...resource, paymentMethods: ordered } : resource;
|
|
7237
7285
|
}
|
|
7286
|
+
async function recoverPaymentKeys(store, logger) {
|
|
7287
|
+
if (!hasMethodGroup(store, "idempotency_claims") || !hasMethodGroup(store, "response_redelivery")) {
|
|
7288
|
+
return;
|
|
7289
|
+
}
|
|
7290
|
+
let recovered;
|
|
7291
|
+
try {
|
|
7292
|
+
recovered = await store.recoverIdempotencyKeys({
|
|
7293
|
+
release: false,
|
|
7294
|
+
endpointPrefix: PAYMENT_KEY_ENDPOINT_PREFIX
|
|
7295
|
+
});
|
|
7296
|
+
} catch (error) {
|
|
7297
|
+
throw new CommerceError("STORAGE_ERROR", "Payment retry keys could not be recovered", {
|
|
7298
|
+
cause: error
|
|
7299
|
+
});
|
|
7300
|
+
}
|
|
7301
|
+
if (recovered > 0) {
|
|
7302
|
+
logger.warn({ recovered }, "Payment retry keys left in flight are now unresolved");
|
|
7303
|
+
}
|
|
7304
|
+
}
|
|
7238
7305
|
async function createGateway(options) {
|
|
7239
7306
|
const clock = options.clock ?? systemClock;
|
|
7240
7307
|
const ids = options.ids ?? createDefaultIdGenerator();
|
|
@@ -7246,6 +7313,10 @@ async function createGateway(options) {
|
|
|
7246
7313
|
(resource) => withProviderBackedMethodsFirst(resource, options.paymentProviders)
|
|
7247
7314
|
)
|
|
7248
7315
|
);
|
|
7316
|
+
for (const resource of resources.list()) {
|
|
7317
|
+
assertRetrySupport(resource, options.store, options.config.merchant.publicBaseUrl);
|
|
7318
|
+
}
|
|
7319
|
+
await recoverPaymentKeys(options.store, logger);
|
|
7249
7320
|
const events = createStoreEventSink({ store: options.store, logger });
|
|
7250
7321
|
const pipeline = createExecutionPipeline({
|
|
7251
7322
|
resources,
|
|
@@ -7256,7 +7327,8 @@ async function createGateway(options) {
|
|
|
7256
7327
|
events,
|
|
7257
7328
|
logger,
|
|
7258
7329
|
clock,
|
|
7259
|
-
ids
|
|
7330
|
+
ids,
|
|
7331
|
+
deployment: options.config.merchant.publicBaseUrl
|
|
7260
7332
|
});
|
|
7261
7333
|
const server = Fastify({
|
|
7262
7334
|
// Same cap as adapter mounts, which enforce it on the socket instead
|
|
@@ -7349,9 +7421,9 @@ async function runGateway(options = {}) {
|
|
|
7349
7421
|
const { core: logger } = createGatewayLogger({ name: config.merchant.id });
|
|
7350
7422
|
const paymentProviders = await createConfiguredPaymentProviders(config.payments, logger);
|
|
7351
7423
|
const ap2 = config.authorization?.ap2;
|
|
7352
|
-
const ap2Module = ap2?.enabled ? await importOptionalPeer("authorization.ap2", () => import('./ap2-
|
|
7424
|
+
const ap2Module = ap2?.enabled ? await importOptionalPeer("authorization.ap2", () => import('./ap2-5FFGSW6F.js')) : void 0;
|
|
7353
7425
|
const mcp = config.protocols.mcp;
|
|
7354
|
-
const mcpModule = mcp.enabled ? await importOptionalPeer("protocols.mcp", () => import('./mcp-
|
|
7426
|
+
const mcpModule = mcp.enabled ? await importOptionalPeer("protocols.mcp", () => import('./mcp-HHGNOUKE.js')) : void 0;
|
|
7355
7427
|
const acp = config.protocols.acp;
|
|
7356
7428
|
const ap2Replay = ap2?.enabled ? ap2.replay?.path : void 0;
|
|
7357
7429
|
const acpIdempotency = acp.enabled ? acp.idempotency.path : void 0;
|
|
@@ -7501,5 +7573,5 @@ function printStartupError(error) {
|
|
|
7501
7573
|
}
|
|
7502
7574
|
|
|
7503
7575
|
export { printStartupError, runGateway };
|
|
7504
|
-
//# sourceMappingURL=run-
|
|
7505
|
-
//# sourceMappingURL=run-
|
|
7576
|
+
//# sourceMappingURL=run-7KLKW3HE.js.map
|
|
7577
|
+
//# sourceMappingURL=run-7KLKW3HE.js.map
|