@atxp/client 0.10.11 → 0.10.13
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/dist/_virtual/index10.js +2 -2
- package/dist/_virtual/index11.js +2 -2
- package/dist/_virtual/index14.js +2 -2
- package/dist/_virtual/index15.js +2 -2
- package/dist/_virtual/index17.js +2 -2
- package/dist/_virtual/index18.js +2 -2
- package/dist/_virtual/index19.js +2 -2
- package/dist/_virtual/index20.js +2 -2
- package/dist/_virtual/index3.js +2 -2
- package/dist/_virtual/index4.js +2 -2
- package/dist/index.cjs +9 -70
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -60
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -70
- package/dist/index.js.map +1 -1
- package/dist/mppProtocolHandler.d.ts +1 -9
- package/dist/mppProtocolHandler.d.ts.map +1 -1
- package/dist/mppProtocolHandler.js +7 -16
- package/dist/mppProtocolHandler.js.map +1 -1
- package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/ajv/dist/compile/validate/index.js +1 -1
- package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/ajv/dist/vocabularies/applicator/index.js +1 -1
- package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/ajv/dist/vocabularies/discriminator/index.js +1 -1
- package/dist/node_modules/@modelcontextprotocol/sdk/node_modules/ajv/dist/vocabularies/format/index.js +1 -1
- package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/applicator/index.js +1 -1
- package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/core/index.js +1 -1
- package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/discriminator/index.js +1 -1
- package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/format/index.js +1 -1
- package/dist/node_modules/ajv-formats/node_modules/ajv/dist/vocabularies/validation/index.js +1 -1
- package/dist/node_modules/fast-uri/index.js +1 -1
- package/dist/paymentClient.d.ts +8 -16
- package/dist/paymentClient.d.ts.map +1 -1
- package/dist/paymentClient.js +8 -15
- package/dist/paymentClient.js.map +1 -1
- package/dist/paymentHeaders.d.ts +11 -0
- package/dist/paymentHeaders.d.ts.map +1 -0
- package/dist/paymentHeaders.js +32 -0
- package/dist/paymentHeaders.js.map +1 -0
- package/dist/x402ProtocolHandler.d.ts +0 -5
- package/dist/x402ProtocolHandler.d.ts.map +1 -1
- package/dist/x402ProtocolHandler.js +4 -12
- package/dist/x402ProtocolHandler.js.map +1 -1
- package/package.json +3 -3
package/dist/_virtual/index10.js
CHANGED
package/dist/_virtual/index11.js
CHANGED
package/dist/_virtual/index14.js
CHANGED
package/dist/_virtual/index15.js
CHANGED
package/dist/_virtual/index17.js
CHANGED
package/dist/_virtual/index18.js
CHANGED
package/dist/_virtual/index19.js
CHANGED
package/dist/_virtual/index20.js
CHANGED
package/dist/_virtual/index3.js
CHANGED
package/dist/_virtual/index4.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -24987,49 +24987,6 @@ function buildPaymentHeaders(result, originalHeaders) {
|
|
|
24987
24987
|
}
|
|
24988
24988
|
return headers;
|
|
24989
24989
|
}
|
|
24990
|
-
/**
|
|
24991
|
-
* Client for authorizing payments.
|
|
24992
|
-
*
|
|
24993
|
-
* Resolves the payment protocol via protocolFlag, then delegates to
|
|
24994
|
-
* account.authorize() for the actual authorization logic.
|
|
24995
|
-
*/
|
|
24996
|
-
class PaymentClient {
|
|
24997
|
-
constructor(config) {
|
|
24998
|
-
this.protocolFlag = config.protocolFlag;
|
|
24999
|
-
this.logger = config.logger;
|
|
25000
|
-
}
|
|
25001
|
-
/**
|
|
25002
|
-
* Authorize a payment by delegating to the account's authorize method.
|
|
25003
|
-
*
|
|
25004
|
-
* PaymentClient resolves the protocol (via explicit param or protocolFlag),
|
|
25005
|
-
* then delegates all protocol-specific logic to account.authorize().
|
|
25006
|
-
*
|
|
25007
|
-
* @param params.account - The account to authorize the payment through
|
|
25008
|
-
* @param params.userId - Passed to protocolFlag for protocol selection
|
|
25009
|
-
* @param params.destination - Payment destination address
|
|
25010
|
-
* @param params.protocol - Explicit protocol override (skips protocolFlag)
|
|
25011
|
-
* @param params.amount - Payment amount
|
|
25012
|
-
* @param params.memo - Payment memo
|
|
25013
|
-
* @param params.paymentRequirements - X402 payment requirements
|
|
25014
|
-
* @param params.challenge - MPP challenge object
|
|
25015
|
-
* @returns AuthorizeResult with protocol and opaque credential
|
|
25016
|
-
*/
|
|
25017
|
-
async authorize(params) {
|
|
25018
|
-
const { account, userId, destination } = params;
|
|
25019
|
-
// Determine protocol
|
|
25020
|
-
const protocol = params.protocol
|
|
25021
|
-
?? (this.protocolFlag ? this.protocolFlag(userId, destination) : 'atxp');
|
|
25022
|
-
// Delegate to the account's authorize method
|
|
25023
|
-
return account.authorize({
|
|
25024
|
-
protocol,
|
|
25025
|
-
amount: params.amount,
|
|
25026
|
-
destination,
|
|
25027
|
-
memo: params.memo,
|
|
25028
|
-
paymentRequirements: params.paymentRequirements,
|
|
25029
|
-
challenge: params.challenge,
|
|
25030
|
-
});
|
|
25031
|
-
}
|
|
25032
|
-
}
|
|
25033
24990
|
|
|
25034
24991
|
function isX402Challenge(obj) {
|
|
25035
24992
|
if (typeof obj !== 'object' || obj === null)
|
|
@@ -25045,9 +25002,8 @@ function isX402Challenge(obj) {
|
|
|
25045
25002
|
* Creates payment headers using the x402 library and retries the request.
|
|
25046
25003
|
*/
|
|
25047
25004
|
class X402ProtocolHandler {
|
|
25048
|
-
constructor(
|
|
25005
|
+
constructor() {
|
|
25049
25006
|
this.protocol = 'x402';
|
|
25050
|
-
this.accountsServer = config?.accountsServer ?? 'https://accounts.atxp.ai';
|
|
25051
25007
|
}
|
|
25052
25008
|
async canHandle(response) {
|
|
25053
25009
|
if (response.status !== 402)
|
|
@@ -25113,16 +25069,9 @@ class X402ProtocolHandler {
|
|
|
25113
25069
|
// Authorize via account.authorize() — ATXPAccount calls the accounts
|
|
25114
25070
|
// service, BaseAccount signs locally. No fallback — each account type
|
|
25115
25071
|
// handles authorization according to its capabilities.
|
|
25116
|
-
const
|
|
25117
|
-
|
|
25118
|
-
logger,
|
|
25119
|
-
fetchFn,
|
|
25120
|
-
});
|
|
25121
|
-
const authorizeResult = await client.authorize({
|
|
25122
|
-
account,
|
|
25123
|
-
userId: accountId,
|
|
25072
|
+
const authorizeResult = await account.authorize({
|
|
25073
|
+
protocols: ['x402'],
|
|
25124
25074
|
destination: url,
|
|
25125
|
-
protocol: 'x402',
|
|
25126
25075
|
paymentRequirements: selectedPaymentRequirements,
|
|
25127
25076
|
});
|
|
25128
25077
|
const paymentHeader = authorizeResult.credential;
|
|
@@ -25271,13 +25220,12 @@ class ATXPProtocolHandler {
|
|
|
25271
25220
|
* 1. HTTP level: HTTP 402 with WWW-Authenticate: Payment header
|
|
25272
25221
|
* 2. MCP level: JSON-RPC error with code -32042 containing MPP data
|
|
25273
25222
|
*
|
|
25274
|
-
* Handles the challenge by calling /authorize/
|
|
25223
|
+
* Handles the challenge by calling /authorize/auto on the accounts service
|
|
25275
25224
|
* and retrying with an Authorization: Payment header.
|
|
25276
25225
|
*/
|
|
25277
25226
|
class MPPProtocolHandler {
|
|
25278
|
-
constructor(
|
|
25227
|
+
constructor() {
|
|
25279
25228
|
this.protocol = 'mpp';
|
|
25280
|
-
this.accountsServer = config?.accountsServer ?? 'https://accounts.atxp.ai';
|
|
25281
25229
|
}
|
|
25282
25230
|
async canHandle(response) {
|
|
25283
25231
|
if (mpp.hasMPPChallenge(response))
|
|
@@ -25383,20 +25331,12 @@ class MPPProtocolHandler {
|
|
|
25383
25331
|
async authorizeAndRetry(challenge, prospectivePayment, originalRequest, config, bodyText, originalResponse) {
|
|
25384
25332
|
const { account, logger, fetchFn, onPayment } = config;
|
|
25385
25333
|
try {
|
|
25386
|
-
logger.debug('MPP: calling /authorize/
|
|
25387
|
-
const client = new PaymentClient({
|
|
25388
|
-
accountsServer: this.accountsServer,
|
|
25389
|
-
logger,
|
|
25390
|
-
fetchFn,
|
|
25391
|
-
});
|
|
25392
|
-
const accountId = await account.getAccountId();
|
|
25334
|
+
logger.debug('MPP: calling /authorize/auto on accounts service');
|
|
25393
25335
|
let authorizeResult;
|
|
25394
25336
|
try {
|
|
25395
|
-
authorizeResult = await
|
|
25396
|
-
|
|
25397
|
-
userId: accountId,
|
|
25337
|
+
authorizeResult = await account.authorize({
|
|
25338
|
+
protocols: ['mpp'],
|
|
25398
25339
|
destination: typeof originalRequest.url === 'string' ? originalRequest.url : originalRequest.url.toString(),
|
|
25399
|
-
protocol: 'mpp',
|
|
25400
25340
|
challenge,
|
|
25401
25341
|
});
|
|
25402
25342
|
}
|
|
@@ -25404,7 +25344,7 @@ class MPPProtocolHandler {
|
|
|
25404
25344
|
// AuthorizationError = server rejected the request (HTTP error from accounts)
|
|
25405
25345
|
// Other errors = data validation or network failure
|
|
25406
25346
|
if (authorizeError instanceof common.AuthorizationError) {
|
|
25407
|
-
logger.debug(`MPP:
|
|
25347
|
+
logger.debug(`MPP: authorize rejected (${authorizeError.statusCode}), returning original response`);
|
|
25408
25348
|
return this.reconstructResponse(bodyText, originalResponse);
|
|
25409
25349
|
}
|
|
25410
25350
|
throw authorizeError;
|
|
@@ -25456,7 +25396,6 @@ exports.OAuthClient = OAuthClient;
|
|
|
25456
25396
|
exports.POLYGON_AMOY = POLYGON_AMOY;
|
|
25457
25397
|
exports.POLYGON_MAINNET = POLYGON_MAINNET;
|
|
25458
25398
|
exports.PassthroughDestinationMaker = PassthroughDestinationMaker;
|
|
25459
|
-
exports.PaymentClient = PaymentClient;
|
|
25460
25399
|
exports.PaymentExpiredError = PaymentExpiredError;
|
|
25461
25400
|
exports.PaymentNetworkError = PaymentNetworkError;
|
|
25462
25401
|
exports.PaymentServerError = PaymentServerError;
|