@devlab.group/agent-commerce 2.6.0 → 2.7.1
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-M6MQ3FYS.js → chunk-5AO5N2XY.js} +11 -5
- package/dist/chunk-5AO5N2XY.js.map +1 -0
- package/dist/{chunk-DRLBML7Z.js → chunk-5VW32JPV.js} +191 -78
- package/dist/chunk-5VW32JPV.js.map +1 -0
- 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-IGXQMAKM.js +8 -0
- package/dist/{chunk-M6BSXXTF.js.map → chunk-IGXQMAKM.js.map} +1 -1
- package/dist/chunk-IWXVQYG5.js +6 -0
- package/dist/chunk-IWXVQYG5.js.map +1 -0
- 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/cli/{ap2-2YMYA2H6.js → ap2-NTYL7H4I.js} +10 -11
- package/dist/cli/ap2-NTYL7H4I.js.map +1 -0
- package/dist/cli/chunk-2M2RF3CT.js +8 -0
- package/dist/cli/{chunk-4KLYFXMW.js.map → chunk-2M2RF3CT.js.map} +1 -1
- 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-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-NSYSMDQN.js → chunk-A42BCWZ2.js} +57 -29
- package/dist/cli/chunk-A42BCWZ2.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-YOF7IK4V.js → chunk-EVCIEKHN.js} +193 -80
- package/dist/cli/chunk-EVCIEKHN.js.map +1 -0
- package/dist/cli/{chunk-YWG2ZN3L.js → chunk-FETTSOMT.js} +12 -6
- package/dist/cli/chunk-FETTSOMT.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-AZL7RPFU.js → chunk-GBBG66O6.js} +77 -16
- package/dist/cli/chunk-GBBG66O6.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-DHFMIBPG.js → chunk-MBPOKPQM.js} +6 -6
- package/dist/cli/{chunk-DHFMIBPG.js.map → chunk-MBPOKPQM.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-TFV3K6YS.js → chunk-VSSSU4AU.js} +3 -3
- package/dist/cli/{chunk-TFV3K6YS.js.map → chunk-VSSSU4AU.js.map} +1 -1
- package/dist/cli/config-ODN4IEMZ.js +13 -0
- package/dist/cli/{config-3K65QJ22.js.map → config-ODN4IEMZ.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-V27OKTOV.js} +7 -7
- package/dist/cli/{mcp-6F64A7KE.js.map → mcp-V27OKTOV.js.map} +1 -1
- package/dist/cli/payment-providers-SUATT75K.js +6 -0
- package/dist/cli/{payment-providers-2ITS6KNR.js.map → payment-providers-SUATT75K.js.map} +1 -1
- package/dist/cli/{provider-5BGG5YKQ.js → provider-C3QDAXMR.js} +9 -9
- package/dist/cli/{provider-5BGG5YKQ.js.map → provider-C3QDAXMR.js.map} +1 -1
- package/dist/cli/receipts-ZS3VZ2D4.js +9 -0
- package/dist/cli/{receipts-I4IIE7U6.js.map → receipts-ZS3VZ2D4.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-WYFZUO5D.js} +142 -46
- package/dist/cli/run-WYFZUO5D.js.map +1 -0
- package/dist/cli/{svm-KDSPDFJG.js → svm-NBZY7H6W.js} +9 -6
- package/dist/cli/svm-NBZY7H6W.js.map +1 -0
- package/dist/cli/{x402-4LPIIELI.js → x402-UGLZ3LA7.js} +11 -10
- package/dist/cli/x402-UGLZ3LA7.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 +708 -181
- 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-DQwbKhnc.d.ts} +25 -8
- package/dist/{svm-KNC3PHMS.js → svm-4HR5OEP7.js} +9 -6
- package/dist/svm-4HR5OEP7.js.map +1 -0
- 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/svm-KDSPDFJG.js.map +0 -1
- package/dist/cli/x402-4LPIIELI.js.map +0 -1
- package/dist/svm-KNC3PHMS.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-MBPOKPQM.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-GBBG66O6.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-A42BCWZ2.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-FETTSOMT.js';
|
|
15
|
+
import { X402_DEFAULT_PAYMENT_FLOW, resolveDeploymentMode, requireX402Network } from './chunk-66NTYSXI.js';
|
|
16
|
+
import { PACKAGE_VERSION } from './chunk-2M2RF3CT.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,
|
|
@@ -6593,7 +6617,7 @@ var AUTHORIZATION_PROVIDER_DETAIL = {
|
|
|
6593
6617
|
warn: "authorization-provider-degraded",
|
|
6594
6618
|
fail: "authorization-provider-unreachable"
|
|
6595
6619
|
};
|
|
6596
|
-
async function probe(target, kind, details, options) {
|
|
6620
|
+
async function probe(target, kind, details, options, failing) {
|
|
6597
6621
|
let health;
|
|
6598
6622
|
let threw = false;
|
|
6599
6623
|
try {
|
|
@@ -6604,7 +6628,16 @@ async function probe(target, kind, details, options) {
|
|
|
6604
6628
|
health = { status: "fail", checkedAt: options.clock.nowIso() };
|
|
6605
6629
|
threw = true;
|
|
6606
6630
|
}
|
|
6607
|
-
|
|
6631
|
+
const key = `${kind}:${target.name}`;
|
|
6632
|
+
const startsFailing = health.status === "fail" && !failing.has(key);
|
|
6633
|
+
if (health.status === "fail") failing.add(key);
|
|
6634
|
+
else failing.delete(key);
|
|
6635
|
+
if (startsFailing && !threw) {
|
|
6636
|
+
options.logger.warn(
|
|
6637
|
+
{ name: target.name, ...health.detail !== void 0 ? { detail: health.detail } : {} },
|
|
6638
|
+
`${kind} health check failed (detail not sent to the client)`
|
|
6639
|
+
);
|
|
6640
|
+
} else if (health.detail !== void 0) {
|
|
6608
6641
|
options.logger.debug(
|
|
6609
6642
|
{ name: target.name, detail: health.detail },
|
|
6610
6643
|
`${kind} health detail (not sent to the client)`
|
|
@@ -6620,25 +6653,32 @@ async function probe(target, kind, details, options) {
|
|
|
6620
6653
|
health
|
|
6621
6654
|
};
|
|
6622
6655
|
}
|
|
6623
|
-
async function evaluate(options) {
|
|
6656
|
+
async function evaluate(options, failing) {
|
|
6624
6657
|
const [store, adapters, paymentProviders, authorizationProviders] = await Promise.all([
|
|
6625
|
-
probe(
|
|
6658
|
+
probe(
|
|
6659
|
+
{ name: "store", health: () => options.store.health() },
|
|
6660
|
+
"store",
|
|
6661
|
+
STORE_DETAIL,
|
|
6662
|
+
options,
|
|
6663
|
+
failing
|
|
6664
|
+
),
|
|
6626
6665
|
Promise.all(
|
|
6627
6666
|
options.adapterRuntimes.map(async (runtime) => ({
|
|
6628
6667
|
runtime,
|
|
6629
6668
|
probed: await probe(
|
|
6630
|
-
// getAdapterHealth
|
|
6631
|
-
//
|
|
6669
|
+
// getAdapterHealth converts throws to failed results, which use
|
|
6670
|
+
// the logging rules for returned results
|
|
6632
6671
|
{ name: runtime.adapter.name, health: () => getAdapterHealth(runtime, options.clock) },
|
|
6633
6672
|
"adapter",
|
|
6634
6673
|
ADAPTER_DETAIL,
|
|
6635
|
-
options
|
|
6674
|
+
options,
|
|
6675
|
+
failing
|
|
6636
6676
|
)
|
|
6637
6677
|
}))
|
|
6638
6678
|
),
|
|
6639
6679
|
Promise.all(
|
|
6640
6680
|
options.paymentProviders.map(
|
|
6641
|
-
(provider) => probe(provider, "payment provider", PAYMENT_PROVIDER_DETAIL, options)
|
|
6681
|
+
(provider) => probe(provider, "payment provider", PAYMENT_PROVIDER_DETAIL, options, failing)
|
|
6642
6682
|
)
|
|
6643
6683
|
),
|
|
6644
6684
|
// An unusable authorization provider blocks readiness on the same threshold
|
|
@@ -6646,7 +6686,7 @@ async function evaluate(options) {
|
|
|
6646
6686
|
// without it, and serving the challenge anyway promises what we cannot honor
|
|
6647
6687
|
Promise.all(
|
|
6648
6688
|
options.authorizationProviders.map(
|
|
6649
|
-
(provider) => probe(provider, "authorization provider", AUTHORIZATION_PROVIDER_DETAIL, options)
|
|
6689
|
+
(provider) => probe(provider, "authorization provider", AUTHORIZATION_PROVIDER_DETAIL, options, failing)
|
|
6650
6690
|
)
|
|
6651
6691
|
)
|
|
6652
6692
|
]);
|
|
@@ -6678,11 +6718,12 @@ var READINESS_TTL_MS = 2e3;
|
|
|
6678
6718
|
function createReadinessProbe(options, ttlMs = READINESS_TTL_MS) {
|
|
6679
6719
|
let cached;
|
|
6680
6720
|
let inFlight;
|
|
6721
|
+
const failing = /* @__PURE__ */ new Set();
|
|
6681
6722
|
const current = async () => {
|
|
6682
6723
|
const now = options.clock.monotonicMs();
|
|
6683
6724
|
if (cached && now - cached.at < ttlMs) return cached.evaluation;
|
|
6684
6725
|
if (inFlight) return inFlight;
|
|
6685
|
-
inFlight = evaluate(options).then((evaluation) => {
|
|
6726
|
+
inFlight = evaluate(options, failing).then((evaluation) => {
|
|
6686
6727
|
cached = { evaluation, at: options.clock.monotonicMs() };
|
|
6687
6728
|
return evaluation;
|
|
6688
6729
|
}).finally(() => {
|
|
@@ -7040,6 +7081,7 @@ async function handleInvoke(request, reply, options) {
|
|
|
7040
7081
|
paymentMethod = resource.paymentMethods[0];
|
|
7041
7082
|
const paymentValue = paymentProof(request, paymentMethod);
|
|
7042
7083
|
const payment = paymentValue !== void 0 && paymentMethod !== void 0 ? { method: paymentMethod, payload: paymentValue } : void 0;
|
|
7084
|
+
const retryKey = paymentMethod === "mpp" && resource.idempotency?.redelivery !== void 0 ? mppRetryKey(request, resourceId) : void 0;
|
|
7043
7085
|
const authorization = parseAuthorizationHeader(
|
|
7044
7086
|
request.headers[AUTHORIZATION_HEADER],
|
|
7045
7087
|
request.id
|
|
@@ -7052,6 +7094,7 @@ async function handleInvoke(request, reply, options) {
|
|
|
7052
7094
|
protocol: "http",
|
|
7053
7095
|
receivedAt: options.clock.nowIso(),
|
|
7054
7096
|
...payment !== void 0 ? { payment } : {},
|
|
7097
|
+
...retryKey !== void 0 ? { retryKey } : {},
|
|
7055
7098
|
...authorization !== void 0 ? { authorization } : {},
|
|
7056
7099
|
...digest !== void 0 ? { metadata: { [CONTENT_DIGEST_METADATA_KEY]: digest } } : {}
|
|
7057
7100
|
};
|
|
@@ -7090,11 +7133,13 @@ async function handleInvoke(request, reply, options) {
|
|
|
7090
7133
|
encodeHeaderDocument(settlementResponse(outcome.payment))
|
|
7091
7134
|
);
|
|
7092
7135
|
const receipt = outcome.payment.metadata?.["receipt"];
|
|
7093
|
-
|
|
7136
|
+
const success = outcome.backendStatus >= 200 && outcome.backendStatus < 300;
|
|
7137
|
+
if (outcome.payment.provider === "mpp" && typeof receipt === "string" && (success || outcome.redelivered !== true)) {
|
|
7094
7138
|
reply.header("payment-receipt", receipt);
|
|
7095
7139
|
}
|
|
7096
7140
|
reply.header("cache-control", "private");
|
|
7097
7141
|
}
|
|
7142
|
+
if (outcome.redelivered === true) reply.header("idempotent-replayed", "true");
|
|
7098
7143
|
const contentType = relayedContentType(outcome.headers?.["content-type"], outcome.body);
|
|
7099
7144
|
if (contentType !== void 0) reply.type(contentType);
|
|
7100
7145
|
if (typeof outcome.body === "string") {
|
|
@@ -7103,7 +7148,14 @@ async function handleInvoke(request, reply, options) {
|
|
|
7103
7148
|
}
|
|
7104
7149
|
reply.status(outcome.backendStatus).send(outcome.body);
|
|
7105
7150
|
} catch (error) {
|
|
7106
|
-
|
|
7151
|
+
const commerceError = toCommerceError(error);
|
|
7152
|
+
const entry = { resourceId, requestId: request.id, err: toLogInfo(commerceError) };
|
|
7153
|
+
if (commerceError.httpStatus >= 500) {
|
|
7154
|
+
options.logger.warn(entry, "http adapter: execution failed");
|
|
7155
|
+
} else {
|
|
7156
|
+
options.logger.debug(entry, "http adapter: execution failed");
|
|
7157
|
+
}
|
|
7158
|
+
sendInvokeError(reply, commerceError, paymentMethod);
|
|
7107
7159
|
}
|
|
7108
7160
|
}
|
|
7109
7161
|
function relayedContentType(header2, body) {
|
|
@@ -7134,9 +7186,14 @@ var MPP_PROBLEM_CODES = /* @__PURE__ */ new Set([
|
|
|
7134
7186
|
]);
|
|
7135
7187
|
function sendInvokeError(reply, error, paymentMethod) {
|
|
7136
7188
|
const details = error.details;
|
|
7189
|
+
const reason = typeof details?.["reason"] === "string" ? details["reason"] : void 0;
|
|
7137
7190
|
if (PROVIDER_UNAVAILABLE_CODES.has(error.code)) {
|
|
7138
7191
|
reply.header("retry-after", String(PROVIDER_RETRY_AFTER_SECONDS));
|
|
7139
7192
|
}
|
|
7193
|
+
const retryAfter = details?.["retryAfterSeconds"];
|
|
7194
|
+
if (typeof retryAfter === "number" && Number.isSafeInteger(retryAfter) && retryAfter >= 0) {
|
|
7195
|
+
reply.header("retry-after", String(retryAfter));
|
|
7196
|
+
}
|
|
7140
7197
|
const settled = settlementResponseFromDetails(details);
|
|
7141
7198
|
if (settled !== void 0) {
|
|
7142
7199
|
reply.header(PAYMENT_RESPONSE_HEADER, encodeHeaderDocument(settled));
|
|
@@ -7160,12 +7217,12 @@ function sendInvokeError(reply, error, paymentMethod) {
|
|
|
7160
7217
|
reply.header("cache-control", "no-store");
|
|
7161
7218
|
}
|
|
7162
7219
|
const envelope = toErrorEnvelope(error);
|
|
7163
|
-
if (paymentMethod === "mpp" && MPP_PROBLEM_CODES.has(error.code)) {
|
|
7220
|
+
if (paymentMethod === "mpp" && (MPP_PROBLEM_CODES.has(error.code) || reason?.startsWith("payment_identifier_") === true)) {
|
|
7164
7221
|
const { status: _envelopeStatus, ...members } = envelope;
|
|
7165
|
-
const
|
|
7166
|
-
reply.header("content-type", "application/problem+json").status(
|
|
7167
|
-
...mppProblem(error.code,
|
|
7168
|
-
status:
|
|
7222
|
+
const problemStatus = reason === "payment_identifier_conflict" ? 422 : error.httpStatus;
|
|
7223
|
+
reply.header("content-type", "application/problem+json").status(problemStatus).send({
|
|
7224
|
+
...mppProblem(error.code, problemStatus, reason),
|
|
7225
|
+
status: problemStatus,
|
|
7169
7226
|
// The reason token stays in `message` and `details.reason`
|
|
7170
7227
|
detail: mppProblemDetail(reason, error.message),
|
|
7171
7228
|
...members
|
|
@@ -7175,6 +7232,21 @@ function sendInvokeError(reply, error, paymentMethod) {
|
|
|
7175
7232
|
const status = paymentMethod === "x402" ? x402RefusalStatus(error.code, error.httpStatus, details?.["reason"]) : error.httpStatus;
|
|
7176
7233
|
reply.status(status).send(envelope);
|
|
7177
7234
|
}
|
|
7235
|
+
var SF_STRING = /^"((?:[\x20\x21\x23-\x5b\x5d-\x7e]|\\["\\])*)"$/;
|
|
7236
|
+
function mppRetryKey(request, resourceId) {
|
|
7237
|
+
const value = request.headers["idempotency-key"];
|
|
7238
|
+
if (value === void 0) return void 0;
|
|
7239
|
+
if (typeof value === "string") {
|
|
7240
|
+
const trimmed = value.trim();
|
|
7241
|
+
const key = trimmed.startsWith('"') ? SF_STRING.exec(trimmed)?.[1]?.replace(/\\(["\\])/g, "$1") : trimmed;
|
|
7242
|
+
if (key !== void 0 && isUsableIdempotencyKey(key)) return key;
|
|
7243
|
+
}
|
|
7244
|
+
throw new CommerceError(
|
|
7245
|
+
"INPUT_INVALID",
|
|
7246
|
+
"The Idempotency-Key header must be 1 to 255 printable ASCII characters",
|
|
7247
|
+
{ requestId: request.id, resourceId, details: { reason: "payment_identifier_invalid" } }
|
|
7248
|
+
);
|
|
7249
|
+
}
|
|
7178
7250
|
function paymentProof(request, method) {
|
|
7179
7251
|
if (method === "mpp") {
|
|
7180
7252
|
const value2 = request.headers.authorization;
|
|
@@ -7235,6 +7307,25 @@ function withProviderBackedMethodsFirst(resource, providers) {
|
|
|
7235
7307
|
];
|
|
7236
7308
|
return ordered.some((method, i) => method !== resource.paymentMethods[i]) ? { ...resource, paymentMethods: ordered } : resource;
|
|
7237
7309
|
}
|
|
7310
|
+
async function recoverPaymentKeys(store, logger) {
|
|
7311
|
+
if (!hasMethodGroup(store, "idempotency_claims") || !hasMethodGroup(store, "response_redelivery")) {
|
|
7312
|
+
return;
|
|
7313
|
+
}
|
|
7314
|
+
let recovered;
|
|
7315
|
+
try {
|
|
7316
|
+
recovered = await store.recoverIdempotencyKeys({
|
|
7317
|
+
release: false,
|
|
7318
|
+
endpointPrefix: PAYMENT_KEY_ENDPOINT_PREFIX
|
|
7319
|
+
});
|
|
7320
|
+
} catch (error) {
|
|
7321
|
+
throw new CommerceError("STORAGE_ERROR", "Payment retry keys could not be recovered", {
|
|
7322
|
+
cause: error
|
|
7323
|
+
});
|
|
7324
|
+
}
|
|
7325
|
+
if (recovered > 0) {
|
|
7326
|
+
logger.warn({ recovered }, "Payment retry keys left in flight are now unresolved");
|
|
7327
|
+
}
|
|
7328
|
+
}
|
|
7238
7329
|
async function createGateway(options) {
|
|
7239
7330
|
const clock = options.clock ?? systemClock;
|
|
7240
7331
|
const ids = options.ids ?? createDefaultIdGenerator();
|
|
@@ -7246,6 +7337,10 @@ async function createGateway(options) {
|
|
|
7246
7337
|
(resource) => withProviderBackedMethodsFirst(resource, options.paymentProviders)
|
|
7247
7338
|
)
|
|
7248
7339
|
);
|
|
7340
|
+
for (const resource of resources.list()) {
|
|
7341
|
+
assertRetrySupport(resource, options.store, options.config.merchant.publicBaseUrl);
|
|
7342
|
+
}
|
|
7343
|
+
await recoverPaymentKeys(options.store, logger);
|
|
7249
7344
|
const events = createStoreEventSink({ store: options.store, logger });
|
|
7250
7345
|
const pipeline = createExecutionPipeline({
|
|
7251
7346
|
resources,
|
|
@@ -7256,7 +7351,8 @@ async function createGateway(options) {
|
|
|
7256
7351
|
events,
|
|
7257
7352
|
logger,
|
|
7258
7353
|
clock,
|
|
7259
|
-
ids
|
|
7354
|
+
ids,
|
|
7355
|
+
deployment: options.config.merchant.publicBaseUrl
|
|
7260
7356
|
});
|
|
7261
7357
|
const server = Fastify({
|
|
7262
7358
|
// Same cap as adapter mounts, which enforce it on the socket instead
|
|
@@ -7349,9 +7445,9 @@ async function runGateway(options = {}) {
|
|
|
7349
7445
|
const { core: logger } = createGatewayLogger({ name: config.merchant.id });
|
|
7350
7446
|
const paymentProviders = await createConfiguredPaymentProviders(config.payments, logger);
|
|
7351
7447
|
const ap2 = config.authorization?.ap2;
|
|
7352
|
-
const ap2Module = ap2?.enabled ? await importOptionalPeer("authorization.ap2", () => import('./ap2-
|
|
7448
|
+
const ap2Module = ap2?.enabled ? await importOptionalPeer("authorization.ap2", () => import('./ap2-NTYL7H4I.js')) : void 0;
|
|
7353
7449
|
const mcp = config.protocols.mcp;
|
|
7354
|
-
const mcpModule = mcp.enabled ? await importOptionalPeer("protocols.mcp", () => import('./mcp-
|
|
7450
|
+
const mcpModule = mcp.enabled ? await importOptionalPeer("protocols.mcp", () => import('./mcp-V27OKTOV.js')) : void 0;
|
|
7355
7451
|
const acp = config.protocols.acp;
|
|
7356
7452
|
const ap2Replay = ap2?.enabled ? ap2.replay?.path : void 0;
|
|
7357
7453
|
const acpIdempotency = acp.enabled ? acp.idempotency.path : void 0;
|
|
@@ -7501,5 +7597,5 @@ function printStartupError(error) {
|
|
|
7501
7597
|
}
|
|
7502
7598
|
|
|
7503
7599
|
export { printStartupError, runGateway };
|
|
7504
|
-
//# sourceMappingURL=run-
|
|
7505
|
-
//# sourceMappingURL=run-
|
|
7600
|
+
//# sourceMappingURL=run-WYFZUO5D.js.map
|
|
7601
|
+
//# sourceMappingURL=run-WYFZUO5D.js.map
|