@atxp/client 0.8.1 → 0.8.3
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/atxpFetcher.d.ts +3 -3
- package/dist/atxpFetcher.d.ts.map +1 -1
- package/dist/atxpFetcher.js +21 -21
- package/dist/atxpFetcher.js.map +1 -1
- package/dist/clientTestHelpers.d.ts.map +1 -1
- package/dist/index.cjs +23 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +23 -22
- package/dist/index.js.map +1 -1
- package/dist/oAuth.d.ts.map +1 -1
- package/dist/oAuth.js +2 -1
- package/dist/oAuth.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -53,7 +53,8 @@ class OAuthClient extends OAuthResourceClient {
|
|
|
53
53
|
strict,
|
|
54
54
|
allowInsecureRequests,
|
|
55
55
|
clientName,
|
|
56
|
-
logger
|
|
56
|
+
logger,
|
|
57
|
+
registrationType: 'client'
|
|
57
58
|
});
|
|
58
59
|
this.extractResourceUrl = (response) => {
|
|
59
60
|
if (response.status !== 401) {
|
|
@@ -348,16 +349,16 @@ class ATXPFetcher {
|
|
|
348
349
|
this.logger.info(`PAYMENT FAILED: ${error.message}`);
|
|
349
350
|
}
|
|
350
351
|
};
|
|
351
|
-
this.handleMultiDestinationPayment = async (
|
|
352
|
-
if (!
|
|
352
|
+
this.handleMultiDestinationPayment = async (paymentRequest, paymentRequestUrl, paymentRequestId) => {
|
|
353
|
+
if (!paymentRequest.options || paymentRequest.options.length === 0) {
|
|
353
354
|
return false;
|
|
354
355
|
}
|
|
355
356
|
// Get sources from the account
|
|
356
357
|
const sources = await this.account.getSources();
|
|
357
|
-
// Apply destination mappers to transform
|
|
358
|
-
// Convert
|
|
358
|
+
// Apply destination mappers to transform options
|
|
359
|
+
// Convert PaymentRequestOption[] to Destination[] for mapper compatibility
|
|
359
360
|
const mappedDestinations = [];
|
|
360
|
-
for (const option of
|
|
361
|
+
for (const option of paymentRequest.options) {
|
|
361
362
|
const destinationMaker = this.destinationMakers.get(option.network);
|
|
362
363
|
if (!destinationMaker) {
|
|
363
364
|
this.logger.debug(`ATXP: destination maker for network '${option.network}' not available, trying next destination`);
|
|
@@ -379,11 +380,11 @@ class ATXPFetcher {
|
|
|
379
380
|
const firstDest = mappedDestinations[0];
|
|
380
381
|
const prospectivePayment = {
|
|
381
382
|
accountId: this.account.accountId,
|
|
382
|
-
resourceUrl:
|
|
383
|
-
resourceName:
|
|
383
|
+
resourceUrl: paymentRequest.resource?.toString() ?? '',
|
|
384
|
+
resourceName: paymentRequest.payeeName ?? '',
|
|
384
385
|
currency: firstDest.currency,
|
|
385
386
|
amount: firstDest.amount,
|
|
386
|
-
iss:
|
|
387
|
+
iss: paymentRequest.payeeName ?? '',
|
|
387
388
|
};
|
|
388
389
|
// Ask for approval once for all payment attempts
|
|
389
390
|
if (!await this.approvePayment(prospectivePayment)) {
|
|
@@ -396,7 +397,7 @@ class ATXPFetcher {
|
|
|
396
397
|
for (const paymentMaker of this.account.paymentMakers) {
|
|
397
398
|
try {
|
|
398
399
|
// Pass all destinations to payment maker - it will filter and pick the one it can handle
|
|
399
|
-
const result = await paymentMaker.makePayment(mappedDestinations,
|
|
400
|
+
const result = await paymentMaker.makePayment(mappedDestinations, paymentRequest.payeeName ?? '', paymentRequestId);
|
|
400
401
|
if (result === null) {
|
|
401
402
|
this.logger.debug(`ATXP: payment maker cannot handle these destinations, trying next`);
|
|
402
403
|
continue; // Try next payment maker
|
|
@@ -460,28 +461,28 @@ class ATXPFetcher {
|
|
|
460
461
|
this.logger.info(`ATXP: payment requirement is not allowed on this server`);
|
|
461
462
|
return false;
|
|
462
463
|
}
|
|
463
|
-
const
|
|
464
|
-
if (!
|
|
464
|
+
const paymentRequest = await this.getPaymentRequest(paymentRequestUrl);
|
|
465
|
+
if (!paymentRequest) {
|
|
465
466
|
throw new Error(`ATXP: payment request ${paymentRequestId} not found on server ${paymentRequestUrl}`);
|
|
466
467
|
}
|
|
467
|
-
// Handle multi-
|
|
468
|
-
if (
|
|
469
|
-
return this.handleMultiDestinationPayment(
|
|
468
|
+
// Handle multi-option format
|
|
469
|
+
if (paymentRequest.options && paymentRequest.options.length > 0) {
|
|
470
|
+
return this.handleMultiDestinationPayment(paymentRequest, paymentRequestUrl, paymentRequestId);
|
|
470
471
|
}
|
|
471
|
-
// Payment request doesn't have
|
|
472
|
-
throw new Error(`ATXP: payment request does not contain
|
|
472
|
+
// Payment request doesn't have options - this shouldn't happen with new SDK
|
|
473
|
+
throw new Error(`ATXP: payment request does not contain options array`);
|
|
473
474
|
};
|
|
474
|
-
this.
|
|
475
|
+
this.getPaymentRequest = async (paymentRequestUrl) => {
|
|
475
476
|
const prRequest = await this.sideChannelFetch(paymentRequestUrl);
|
|
476
477
|
if (!prRequest.ok) {
|
|
477
478
|
throw new Error(`ATXP: GET ${paymentRequestUrl} failed: ${prRequest.status} ${prRequest.statusText}`);
|
|
478
479
|
}
|
|
479
480
|
const paymentRequest = await prRequest.json();
|
|
480
481
|
// Parse amount strings to BigNumber objects
|
|
481
|
-
if (paymentRequest.
|
|
482
|
-
for (const
|
|
483
|
-
if (typeof
|
|
484
|
-
|
|
482
|
+
if (paymentRequest.options) {
|
|
483
|
+
for (const option of paymentRequest.options) {
|
|
484
|
+
if (typeof option.amount === 'string' || typeof option.amount === 'number') {
|
|
485
|
+
option.amount = new BigNumber(option.amount);
|
|
485
486
|
}
|
|
486
487
|
}
|
|
487
488
|
}
|