@atxp/client 0.8.2 → 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/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 (paymentRequestData, paymentRequestUrl, paymentRequestId) => {
352
- if (!paymentRequestData.destinations || paymentRequestData.destinations.length === 0) {
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 destinations
358
- // Convert PaymentRequestDestination[] to Destination[] for mapper compatibility
358
+ // Apply destination mappers to transform options
359
+ // Convert PaymentRequestOption[] to Destination[] for mapper compatibility
359
360
  const mappedDestinations = [];
360
- for (const option of paymentRequestData.destinations) {
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: paymentRequestData.resource?.toString() ?? '',
383
- resourceName: paymentRequestData.resourceName ?? '',
383
+ resourceUrl: paymentRequest.resource?.toString() ?? '',
384
+ resourceName: paymentRequest.payeeName ?? '',
384
385
  currency: firstDest.currency,
385
386
  amount: firstDest.amount,
386
- iss: paymentRequestData.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, paymentRequestData.iss, paymentRequestId);
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 paymentRequestData = await this.getPaymentRequestData(paymentRequestUrl);
464
- if (!paymentRequestData) {
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-destination format
468
- if (paymentRequestData.destinations && paymentRequestData.destinations.length > 0) {
469
- return this.handleMultiDestinationPayment(paymentRequestData, paymentRequestUrl, paymentRequestId);
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 destinations - this shouldn't happen with new SDK
472
- throw new Error(`ATXP: payment request does not contain destinations array`);
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.getPaymentRequestData = async (paymentRequestUrl) => {
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.destinations) {
482
- for (const dest of paymentRequest.destinations) {
483
- if (typeof dest.amount === 'string' || typeof dest.amount === 'number') {
484
- dest.amount = new BigNumber(dest.amount);
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
  }