@ardrive/turbo-sdk 1.0.0-alpha.22 → 1.0.0-alpha.24

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 CHANGED
@@ -39,7 +39,7 @@ The SDK is provided in both CommonJS and ESM formats, and it's compatible with b
39
39
  ```javascript
40
40
  import { TurboFactory } from '@ardrive/turbo-sdk';
41
41
 
42
- const turbo = TurboFactory.unauthenticated({});
42
+ const turbo = TurboFactory.unauthenticated();
43
43
  const rates = await turbo.getFiatRates();
44
44
  ```
45
45
 
@@ -48,7 +48,7 @@ const rates = await turbo.getFiatRates();
48
48
  ```html
49
49
  <script src="https://cdn.jsdelivr.net/npm/@ardrive/turbo-sdk"></script>
50
50
  <script>
51
- const turbo = TurboFactory.unauthenticated({});
51
+ const turbo = TurboFactory.unauthenticated();
52
52
  const rates = await turbo.getFiatRates();
53
53
  </script>
54
54
  ```
@@ -65,7 +65,7 @@ Project's `package.json`:
65
65
  }
66
66
  ```
67
67
 
68
- tsconfig's `tsconfig.json`:
68
+ Project's `tsconfig.json`:
69
69
 
70
70
  ```json
71
71
  {
@@ -82,7 +82,7 @@ Usage:
82
82
  ```javascript
83
83
  const { TurboFactory } = require('@ardrive/turbo-sdk');
84
84
 
85
- const turbo = TurboFactory.unauthenticated({});
85
+ const turbo = TurboFactory.unauthenticated();
86
86
  const rates = await turbo.getFiatRates();
87
87
  ```
88
88
 
@@ -96,7 +96,7 @@ Project's `package.json`:
96
96
  }
97
97
  ```
98
98
 
99
- tsconfig's `tsconfig.json`:
99
+ Project's `tsconfig.json`:
100
100
 
101
101
  ```json
102
102
  {
@@ -113,7 +113,7 @@ Usage:
113
113
  ```javascript
114
114
  import { TurboFactory } from '@ardrive/turbo-sdk/node';
115
115
 
116
- const turbo = TurboFactory.unauthenticated({});
116
+ const turbo = TurboFactory.unauthenticated();
117
117
  const rates = await turbo.getFiatRates();
118
118
  ```
119
119
 
@@ -122,7 +122,7 @@ const rates = await turbo.getFiatRates();
122
122
  The SDK provides TypeScript types. When you import the SDK in a TypeScript project:
123
123
 
124
124
  ```typescript
125
- import Ardrive from '@ardrive/turbo-sdk/web';
125
+ import { TurboFactory } from '@ardrive/turbo-sdk/web';
126
126
 
127
127
  // or '@ardrive/turbo-sdk/node' for Node.js projects
128
128
  ```
@@ -136,7 +136,7 @@ Types are exported from `./lib/types/index.d.ts` and should be automatically rec
136
136
  - `unauthenticated()` - Creates an instance of a client that accesses Turbo's unauthenticated services.
137
137
 
138
138
  ```typescript
139
- const turbo = TurboFactory.unauthenticated({});
139
+ const turbo = TurboFactory.unauthenticated();
140
140
  ```
141
141
 
142
142
  - `authenticated()` - Creates an instance of a client that accesses Turbo's authenticated and unauthenticated services.
@@ -172,19 +172,23 @@ Types are exported from `./lib/types/index.d.ts` and should be automatically rec
172
172
  const rates = await turbo.getFiatRates();
173
173
  ```
174
174
 
175
- - `getWincForFiat({ amount, currency })` - Returns the current conversion rate for Winston Credits for the provided fiat currency and amount, including all top-up adjustments and fees.
175
+ - `getWincForFiat({ amount })` - Returns the current amount of Winston Credits including all adjustments for the provided fiat currency, amount. To leverage promo codes, see [TurboAuthenticatedClient].
176
176
 
177
177
  ```typescript
178
- const winc = await turbo.getWincForFiat({ amount: 100, currency: 'USD' });
178
+ const { winc, paymentAmount, quotedPaymentAmount, adjustments } =
179
+ await turbo.getWincForFiat({
180
+ amount: USD(100),
181
+ });
179
182
  ```
180
183
 
181
184
  - `getUploadCosts({ bytes })` - Returns the estimated cost in Winston Credits for the provided file sizes, including all upload adjustments and fees.
182
185
 
183
186
  ```typescript
184
- const costs = await turbo.getUploadCosts({ bytes: [1000, 2000] });
187
+ const [uploadCostForFile] = await turbo.getUploadCosts({ bytes: [1024] });
188
+ const { winc, adjustments } = uploadCostForFile;
185
189
  ```
186
190
 
187
- - `uploadSignedDataItem({ dataItemStreamFactory, dataItemSizeFactory, signal })` - Uploads a signed data item. The provided dataItemStreamFactory should produce a NEW signed data item stream each time is it invoked. The `dataItemSizeFactory` is a function that returns the size of the file.
191
+ - `uploadSignedDataItem({ dataItemStreamFactory, dataItemSizeFactory, signal })` - Uploads a signed data item. The provided `dataItemStreamFactory` should produce a NEW signed data item stream each time is it invoked. The `dataItemSizeFactory` is a function that returns the size of the file. The `signal` is an optional [AbortSignal] that can be used to cancel the upload or timeout the request.
188
192
 
189
193
  ```typescript
190
194
  const filePath = path.join(__dirname, './my-signed-data-item');
@@ -196,22 +200,56 @@ Types are exported from `./lib/types/index.d.ts` and should be automatically rec
196
200
  });
197
201
  ```
198
202
 
203
+ - `createCheckoutSession({ amount, owner, promoCodes })` - Creates a Stripe checkout session for a Turbo Top Up with the provided amount, currency, owner, and optional promo codes. The returned URL can be opened in the browser, all payments are processed by Stripe.
204
+
205
+ ```typescript
206
+ const { url, winc, paymentAmount, quotedPaymentAmount, adjustments } =
207
+ await turbo.createCheckoutSession({
208
+ amount: USD(10.0), // $10.00 USD
209
+ owner: publicArweaveAddress,
210
+ promoCodes: ['MY_PROMO_CODE'],
211
+ });
212
+
213
+ // Open checkout session in a browser
214
+ if (process.platform === 'darwin') {
215
+ // macOS
216
+ exec(`open ${url}`);
217
+ } else if (process.platform === 'win32') {
218
+ // Windows
219
+ exec(`start "" "${url}"`, { shell: true });
220
+ } else {
221
+ // Linux/Unix
222
+ open(url);
223
+ }
224
+ ```
225
+
199
226
  ### TurboAuthenticatedClient
200
227
 
201
228
  - `getBalance()` - Issues a signed request to get the credit balance of a wallet measured in AR (measured in Winston Credits, or winc).
202
229
 
203
230
  ```typescript
204
- const balance = await turbo.getBalance();
231
+ const { winc: balance } = await turbo.getBalance();
232
+ ```
233
+
234
+ - `getWincForFiat({ amount, promoCodes })` - Returns the current amount of Winston Credits including all adjustments for the provided fiat currency, amount, and optional promo codes. Note: promo codes require an authenticated client.
235
+
236
+ ```typescript
237
+ const { winc, paymentAmount, quotedPaymentAmount, adjustments } =
238
+ await turbo.getWincForFiat({
239
+ amount: USD(100),
240
+ promoCodes: ['MY_PROMO_CODE'],
241
+ });
205
242
  ```
206
243
 
207
- - `uploadFile({ fileStreamFactory, fileSizeFactory, signal })` - Signs and uploads a raw file. The provided `fileStreamFactory` should produce a NEW file data stream each time is it invoked. The `fileSizeFactory` is a function that returns the size of the file.
244
+ - `uploadFile({ fileStreamFactory, fileSizeFactory, signal })` - Signs and uploads a raw file. The provided `fileStreamFactory` should produce a NEW file data stream each time is it invoked. The `fileSizeFactory` is a function that returns the size of the file. The `signal` is an optional [AbortSignal] that can be used to cancel the upload or timeout the request.
208
245
 
209
246
  ```typescript
210
247
  const filePath = path.join(__dirname, './my-unsigned-file.txt');
211
248
  const fileSize = fs.stateSync(filePath).size;
212
- const uploadResult = await turboAuthClient.uploadFile({
249
+ const uploadResult = await turbo.uploadFile({
213
250
  fileStreamFactory: () => fs.createReadStream(filePath),
214
251
  fileSizeFactory: () => fileSize,
252
+ // no timeout or AbortSignal provided
215
253
  });
216
254
  ```
217
255
 
@@ -223,3 +261,4 @@ If you encounter any issues or have feature requests, please file an issue on ou
223
261
  [examples]: ./examples
224
262
  [TurboUnauthenticatedClient]: #turboUnauthenticatedClient
225
263
  [TurboAuthenticatedClient]: #turboAuthenticatedClient
264
+ [AbortSignal]: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
@@ -47394,9 +47394,11 @@ var TurboHTTPService = class {
47394
47394
  };
47395
47395
 
47396
47396
  // src/common/payment.ts
47397
+ var developmentPaymentServiceURL = "https://payment.ardrive.dev";
47398
+ var defaultPaymentServiceURL = "https://payment.ardrive.io";
47397
47399
  var TurboUnauthenticatedPaymentService = class {
47398
47400
  constructor({
47399
- url = "https://payment.ardrive.dev",
47401
+ url = defaultPaymentServiceURL,
47400
47402
  retryConfig
47401
47403
  }) {
47402
47404
  this.httpService = new TurboHTTPService({
@@ -47404,24 +47406,24 @@ var TurboUnauthenticatedPaymentService = class {
47404
47406
  retryConfig
47405
47407
  });
47406
47408
  }
47407
- async getFiatRates() {
47409
+ getFiatRates() {
47408
47410
  return this.httpService.get({
47409
47411
  endpoint: "/rates"
47410
47412
  });
47411
47413
  }
47412
- async getFiatToAR({
47414
+ getFiatToAR({
47413
47415
  currency
47414
47416
  }) {
47415
47417
  return this.httpService.get({
47416
47418
  endpoint: `/rates/${currency}`
47417
47419
  });
47418
47420
  }
47419
- async getSupportedCountries() {
47421
+ getSupportedCountries() {
47420
47422
  return this.httpService.get({
47421
47423
  endpoint: "/countries"
47422
47424
  });
47423
47425
  }
47424
- async getSupportedCurrencies() {
47426
+ getSupportedCurrencies() {
47425
47427
  return this.httpService.get({
47426
47428
  endpoint: "/currencies"
47427
47429
  });
@@ -47437,15 +47439,42 @@ var TurboUnauthenticatedPaymentService = class {
47437
47439
  const wincCostsForBytes = await Promise.all(fetchPricePromises);
47438
47440
  return wincCostsForBytes;
47439
47441
  }
47440
- async getWincForFiat({ amount, currency }) {
47442
+ getWincForFiat({
47443
+ amount
47444
+ }) {
47445
+ const { amount: paymentAmount, type: currencyType } = amount;
47441
47446
  return this.httpService.get({
47442
- endpoint: `/price/${currency}/${amount}`
47447
+ endpoint: `/price/${currencyType}/${paymentAmount}`
47448
+ });
47449
+ }
47450
+ appendPromoCodesToQuery(promoCodes) {
47451
+ const promoCodesQuery = promoCodes.join(",");
47452
+ return promoCodesQuery ? `?promoCode=${promoCodesQuery}` : "";
47453
+ }
47454
+ async getCheckout({ amount, owner, promoCodes = [] }, headers) {
47455
+ const { amount: paymentAmount, type: currencyType } = amount;
47456
+ const endpoint = `/top-up/checkout-session/${owner}/${currencyType}/${paymentAmount}${this.appendPromoCodesToQuery(
47457
+ promoCodes
47458
+ )}`;
47459
+ const { adjustments, paymentSession, topUpQuote } = await this.httpService.get({
47460
+ endpoint,
47461
+ headers
47443
47462
  });
47463
+ return {
47464
+ winc: topUpQuote.winstonCreditAmount,
47465
+ adjustments,
47466
+ url: paymentSession.url,
47467
+ paymentAmount: topUpQuote.paymentAmount,
47468
+ quotedPaymentAmount: topUpQuote.quotedPaymentAmount
47469
+ };
47470
+ }
47471
+ createCheckoutSession(params) {
47472
+ return this.getCheckout(params);
47444
47473
  }
47445
47474
  };
47446
47475
  var TurboAuthenticatedPaymentService = class extends TurboUnauthenticatedPaymentService {
47447
47476
  constructor({
47448
- url = "https://payment.ardrive.dev",
47477
+ url = defaultPaymentServiceURL,
47449
47478
  retryConfig,
47450
47479
  signer
47451
47480
  }) {
@@ -47461,6 +47490,21 @@ var TurboAuthenticatedPaymentService = class extends TurboUnauthenticatedPayment
47461
47490
  });
47462
47491
  return balance.winc ? balance : { winc: "0" };
47463
47492
  }
47493
+ async getWincForFiat({
47494
+ amount,
47495
+ promoCodes = []
47496
+ }) {
47497
+ return this.httpService.get({
47498
+ endpoint: `/price/${amount.type}/${amount.amount}${this.appendPromoCodesToQuery(promoCodes)}`,
47499
+ headers: await this.signer.generateSignedRequestHeaders()
47500
+ });
47501
+ }
47502
+ async createCheckoutSession(params) {
47503
+ return this.getCheckout(
47504
+ params,
47505
+ await this.signer.generateSignedRequestHeaders()
47506
+ );
47507
+ }
47464
47508
  };
47465
47509
 
47466
47510
  // src/common/turbo.ts
@@ -47468,9 +47512,11 @@ init_shim();
47468
47512
 
47469
47513
  // src/common/upload.ts
47470
47514
  init_shim();
47515
+ var defaultUploadServiceURL = "https://upload.ardrive.io";
47516
+ var developmentUploadServiceURL = "https://upload.ardrive.dev";
47471
47517
  var TurboUnauthenticatedUploadService = class {
47472
47518
  constructor({
47473
- url = "https://upload.ardrive.dev",
47519
+ url = defaultUploadServiceURL,
47474
47520
  retryConfig
47475
47521
  }) {
47476
47522
  this.httpService = new TurboHTTPService({
@@ -47539,7 +47585,7 @@ var TurboUnauthenticatedClient = class {
47539
47585
  /**
47540
47586
  * Returns the supported fiat currency conversion rate for 1AR based on current market prices.
47541
47587
  */
47542
- async getFiatToAR({
47588
+ getFiatToAR({
47543
47589
  currency
47544
47590
  }) {
47545
47591
  return this.paymentService.getFiatToAR({ currency });
@@ -47550,25 +47596,25 @@ var TurboUnauthenticatedClient = class {
47550
47596
  * Note: this does not take into account varying adjustments and promotions for different sizes of data. If you want to calculate the total
47551
47597
  * cost in 'winc' for a given number of bytes, use getUploadCosts.
47552
47598
  */
47553
- async getFiatRates() {
47599
+ getFiatRates() {
47554
47600
  return this.paymentService.getFiatRates();
47555
47601
  }
47556
47602
  /**
47557
47603
  * Returns a comprehensive list of supported countries that can purchase credits through the Turbo Payment Service.
47558
47604
  */
47559
- async getSupportedCountries() {
47605
+ getSupportedCountries() {
47560
47606
  return this.paymentService.getSupportedCountries();
47561
47607
  }
47562
47608
  /**
47563
47609
  * Returns a list of all supported fiat currencies.
47564
47610
  */
47565
- async getSupportedCurrencies() {
47611
+ getSupportedCurrencies() {
47566
47612
  return this.paymentService.getSupportedCurrencies();
47567
47613
  }
47568
47614
  /**
47569
47615
  * Determines the price in 'winc' to upload one data item of a specific size in bytes, including all Turbo cost adjustments and fees.
47570
47616
  */
47571
- async getUploadCosts({
47617
+ getUploadCosts({
47572
47618
  bytes
47573
47619
  }) {
47574
47620
  return this.paymentService.getUploadCosts({ bytes });
@@ -47576,16 +47622,13 @@ var TurboUnauthenticatedClient = class {
47576
47622
  /**
47577
47623
  * Determines the amount of 'winc' that would be returned for a given currency and amount, including all Turbo cost adjustments and fees.
47578
47624
  */
47579
- async getWincForFiat({
47580
- amount,
47581
- currency
47582
- }) {
47583
- return this.paymentService.getWincForFiat({ amount, currency });
47625
+ getWincForFiat(params) {
47626
+ return this.paymentService.getWincForFiat(params);
47584
47627
  }
47585
47628
  /**
47586
47629
  * Uploads a signed data item to the Turbo Upload Service.
47587
47630
  */
47588
- async uploadSignedDataItem({
47631
+ uploadSignedDataItem({
47589
47632
  dataItemStreamFactory,
47590
47633
  dataItemSizeFactory,
47591
47634
  signal
@@ -47596,6 +47639,12 @@ var TurboUnauthenticatedClient = class {
47596
47639
  signal
47597
47640
  });
47598
47641
  }
47642
+ /**
47643
+ * Creates a Turbo Checkout Session for a given amount and currency.
47644
+ */
47645
+ createCheckoutSession(params) {
47646
+ return this.paymentService.createCheckoutSession(params);
47647
+ }
47599
47648
  };
47600
47649
  var TurboAuthenticatedClient = class extends TurboUnauthenticatedClient {
47601
47650
  constructor({
@@ -47607,13 +47656,13 @@ var TurboAuthenticatedClient = class extends TurboUnauthenticatedClient {
47607
47656
  /**
47608
47657
  * Returns the current balance of the user's wallet in 'winc'.
47609
47658
  */
47610
- async getBalance() {
47659
+ getBalance() {
47611
47660
  return this.paymentService.getBalance();
47612
47661
  }
47613
47662
  /**
47614
47663
  * Signs and uploads raw data to the Turbo Upload Service.
47615
47664
  */
47616
- async uploadFile({
47665
+ uploadFile({
47617
47666
  fileStreamFactory,
47618
47667
  fileSizeFactory,
47619
47668
  signal
@@ -47648,6 +47697,34 @@ var TurboBaseFactory = class {
47648
47697
  // src/common/index.ts
47649
47698
  init_shim();
47650
47699
 
47700
+ // src/common/currency.ts
47701
+ init_shim();
47702
+ var ZeroDecimalCurrency = class {
47703
+ constructor(amount, type) {
47704
+ this.amount = amount;
47705
+ this.type = type;
47706
+ }
47707
+ };
47708
+ var TwoDecimalCurrency = class {
47709
+ constructor(a, type) {
47710
+ this.a = a;
47711
+ this.type = type;
47712
+ }
47713
+ get amount() {
47714
+ return this.a * 100;
47715
+ }
47716
+ };
47717
+ var USD = (usd) => new TwoDecimalCurrency(usd, "usd");
47718
+ var EUR = (eur) => new TwoDecimalCurrency(eur, "eur");
47719
+ var GBP = (gbp) => new TwoDecimalCurrency(gbp, "gbp");
47720
+ var CAD = (cad) => new TwoDecimalCurrency(cad, "cad");
47721
+ var AUD = (aud) => new TwoDecimalCurrency(aud, "aud");
47722
+ var INR = (inr) => new TwoDecimalCurrency(inr, "inr");
47723
+ var SGD = (sgd) => new TwoDecimalCurrency(sgd, "sgd");
47724
+ var HKD = (hkd) => new TwoDecimalCurrency(hkd, "hkd");
47725
+ var BRL = (brl) => new TwoDecimalCurrency(brl, "brl");
47726
+ var JPY = (jpy) => new ZeroDecimalCurrency(jpy, "jpy");
47727
+
47651
47728
  // src/web/signer.ts
47652
47729
  init_shim();
47653
47730
 
@@ -55651,6 +55728,15 @@ var TurboFactory = class extends TurboBaseFactory {
55651
55728
  // src/types.ts
55652
55729
  init_shim();
55653
55730
  export {
55731
+ AUD,
55732
+ BRL,
55733
+ CAD,
55734
+ EUR,
55735
+ GBP,
55736
+ HKD,
55737
+ INR,
55738
+ JPY,
55739
+ SGD,
55654
55740
  TurboAuthenticatedClient,
55655
55741
  TurboAuthenticatedPaymentService,
55656
55742
  TurboAuthenticatedUploadService,
@@ -55658,7 +55744,14 @@ export {
55658
55744
  TurboUnauthenticatedClient,
55659
55745
  TurboUnauthenticatedPaymentService,
55660
55746
  TurboUnauthenticatedUploadService,
55661
- TurboWebArweaveSigner
55747
+ TurboWebArweaveSigner,
55748
+ TwoDecimalCurrency,
55749
+ USD,
55750
+ ZeroDecimalCurrency,
55751
+ defaultPaymentServiceURL,
55752
+ defaultUploadServiceURL,
55753
+ developmentPaymentServiceURL,
55754
+ developmentUploadServiceURL
55662
55755
  };
55663
55756
  /*! Bundled license information:
55664
55757
 
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JPY = exports.BRL = exports.HKD = exports.SGD = exports.INR = exports.AUD = exports.CAD = exports.GBP = exports.EUR = exports.USD = exports.TwoDecimalCurrency = exports.ZeroDecimalCurrency = void 0;
4
+ class ZeroDecimalCurrency {
5
+ constructor(amount, type) {
6
+ this.amount = amount;
7
+ this.type = type;
8
+ }
9
+ }
10
+ exports.ZeroDecimalCurrency = ZeroDecimalCurrency;
11
+ class TwoDecimalCurrency {
12
+ constructor(a, type) {
13
+ this.a = a;
14
+ this.type = type;
15
+ }
16
+ get amount() {
17
+ return this.a * 100;
18
+ }
19
+ }
20
+ exports.TwoDecimalCurrency = TwoDecimalCurrency;
21
+ // Two decimal currencies that are supported by the Turbo API
22
+ const USD = (usd) => new TwoDecimalCurrency(usd, 'usd');
23
+ exports.USD = USD;
24
+ const EUR = (eur) => new TwoDecimalCurrency(eur, 'eur');
25
+ exports.EUR = EUR;
26
+ const GBP = (gbp) => new TwoDecimalCurrency(gbp, 'gbp');
27
+ exports.GBP = GBP;
28
+ const CAD = (cad) => new TwoDecimalCurrency(cad, 'cad');
29
+ exports.CAD = CAD;
30
+ const AUD = (aud) => new TwoDecimalCurrency(aud, 'aud');
31
+ exports.AUD = AUD;
32
+ const INR = (inr) => new TwoDecimalCurrency(inr, 'inr');
33
+ exports.INR = INR;
34
+ const SGD = (sgd) => new TwoDecimalCurrency(sgd, 'sgd');
35
+ exports.SGD = SGD;
36
+ const HKD = (hkd) => new TwoDecimalCurrency(hkd, 'hkd');
37
+ exports.HKD = HKD;
38
+ const BRL = (brl) => new TwoDecimalCurrency(brl, 'brl');
39
+ exports.BRL = BRL;
40
+ // Zero decimal currencies that are supported by the Turbo API
41
+ const JPY = (jpy) => new ZeroDecimalCurrency(jpy, 'jpy');
42
+ exports.JPY = JPY;
@@ -1,9 +1,31 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TurboBaseFactory = void 0;
3
+ exports.TurboBaseFactory = exports.defaultTurboConfiguration = exports.developmentTurboConfiguration = void 0;
4
4
  const payment_js_1 = require("./payment.js");
5
5
  const turbo_js_1 = require("./turbo.js");
6
6
  const upload_js_1 = require("./upload.js");
7
+ /**
8
+ * Testing configuration.
9
+ */
10
+ exports.developmentTurboConfiguration = {
11
+ paymentServiceConfig: {
12
+ url: payment_js_1.developmentPaymentServiceURL,
13
+ },
14
+ uploadServiceConfig: {
15
+ url: upload_js_1.developmentUploadServiceURL,
16
+ },
17
+ };
18
+ /**
19
+ * Production configuration.
20
+ */
21
+ exports.defaultTurboConfiguration = {
22
+ paymentServiceConfig: {
23
+ url: payment_js_1.defaultPaymentServiceURL,
24
+ },
25
+ uploadServiceConfig: {
26
+ url: upload_js_1.defaultUploadServiceURL,
27
+ },
28
+ };
7
29
  class TurboBaseFactory {
8
30
  static unauthenticated({ paymentServiceConfig = {}, uploadServiceConfig = {}, } = {}) {
9
31
  const paymentService = new payment_js_1.TurboUnauthenticatedPaymentService({
@@ -33,3 +33,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
33
33
  __exportStar(require("./upload.js"), exports);
34
34
  __exportStar(require("./payment.js"), exports);
35
35
  __exportStar(require("./turbo.js"), exports);
36
+ __exportStar(require("./currency.js"), exports);
@@ -1,30 +1,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TurboAuthenticatedPaymentService = exports.TurboUnauthenticatedPaymentService = void 0;
3
+ exports.TurboAuthenticatedPaymentService = exports.TurboUnauthenticatedPaymentService = exports.defaultPaymentServiceURL = exports.developmentPaymentServiceURL = void 0;
4
4
  const http_js_1 = require("./http.js");
5
+ exports.developmentPaymentServiceURL = 'https://payment.ardrive.dev';
6
+ exports.defaultPaymentServiceURL = 'https://payment.ardrive.io';
5
7
  class TurboUnauthenticatedPaymentService {
6
- constructor({ url = 'https://payment.ardrive.dev', retryConfig, }) {
8
+ constructor({ url = exports.defaultPaymentServiceURL, retryConfig, }) {
7
9
  this.httpService = new http_js_1.TurboHTTPService({
8
10
  url: `${url}/v1`,
9
11
  retryConfig,
10
12
  });
11
13
  }
12
- async getFiatRates() {
14
+ getFiatRates() {
13
15
  return this.httpService.get({
14
16
  endpoint: '/rates',
15
17
  });
16
18
  }
17
- async getFiatToAR({ currency, }) {
19
+ getFiatToAR({ currency, }) {
18
20
  return this.httpService.get({
19
21
  endpoint: `/rates/${currency}`,
20
22
  });
21
23
  }
22
- async getSupportedCountries() {
24
+ getSupportedCountries() {
23
25
  return this.httpService.get({
24
26
  endpoint: '/countries',
25
27
  });
26
28
  }
27
- async getSupportedCurrencies() {
29
+ getSupportedCurrencies() {
28
30
  return this.httpService.get({
29
31
  endpoint: '/currencies',
30
32
  });
@@ -36,16 +38,39 @@ class TurboUnauthenticatedPaymentService {
36
38
  const wincCostsForBytes = await Promise.all(fetchPricePromises);
37
39
  return wincCostsForBytes;
38
40
  }
39
- async getWincForFiat({ amount, currency }) {
41
+ getWincForFiat({ amount, }) {
42
+ const { amount: paymentAmount, type: currencyType } = amount;
40
43
  return this.httpService.get({
41
- endpoint: `/price/${currency}/${amount}`,
44
+ endpoint: `/price/${currencyType}/${paymentAmount}`,
42
45
  });
43
46
  }
47
+ appendPromoCodesToQuery(promoCodes) {
48
+ const promoCodesQuery = promoCodes.join(',');
49
+ return promoCodesQuery ? `?promoCode=${promoCodesQuery}` : '';
50
+ }
51
+ async getCheckout({ amount, owner, promoCodes = [] }, headers) {
52
+ const { amount: paymentAmount, type: currencyType } = amount;
53
+ const endpoint = `/top-up/checkout-session/${owner}/${currencyType}/${paymentAmount}${this.appendPromoCodesToQuery(promoCodes)}`;
54
+ const { adjustments, paymentSession, topUpQuote } = await this.httpService.get({
55
+ endpoint,
56
+ headers,
57
+ });
58
+ return {
59
+ winc: topUpQuote.winstonCreditAmount,
60
+ adjustments,
61
+ url: paymentSession.url,
62
+ paymentAmount: topUpQuote.paymentAmount,
63
+ quotedPaymentAmount: topUpQuote.quotedPaymentAmount,
64
+ };
65
+ }
66
+ createCheckoutSession(params) {
67
+ return this.getCheckout(params);
68
+ }
44
69
  }
45
70
  exports.TurboUnauthenticatedPaymentService = TurboUnauthenticatedPaymentService;
46
71
  // NOTE: to avoid redundancy, we use inheritance here - but generally prefer composition over inheritance
47
72
  class TurboAuthenticatedPaymentService extends TurboUnauthenticatedPaymentService {
48
- constructor({ url = 'https://payment.ardrive.dev', retryConfig, signer, }) {
73
+ constructor({ url = exports.defaultPaymentServiceURL, retryConfig, signer, }) {
49
74
  super({ url, retryConfig });
50
75
  this.signer = signer;
51
76
  }
@@ -59,5 +84,14 @@ class TurboAuthenticatedPaymentService extends TurboUnauthenticatedPaymentServic
59
84
  // 404's don't return a balance, so default to 0
60
85
  return balance.winc ? balance : { winc: '0' };
61
86
  }
87
+ async getWincForFiat({ amount, promoCodes = [], }) {
88
+ return this.httpService.get({
89
+ endpoint: `/price/${amount.type}/${amount.amount}${this.appendPromoCodesToQuery(promoCodes)}`,
90
+ headers: await this.signer.generateSignedRequestHeaders(),
91
+ });
92
+ }
93
+ async createCheckoutSession(params) {
94
+ return this.getCheckout(params, await this.signer.generateSignedRequestHeaders());
95
+ }
62
96
  }
63
97
  exports.TurboAuthenticatedPaymentService = TurboAuthenticatedPaymentService;