@ardrive/turbo-sdk 1.0.0-beta.1 → 1.0.0-beta.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/README.md +58 -15
- package/bundles/web.bundle.min.js +171 -37
- package/lib/cjs/common/currency.js +42 -0
- package/lib/cjs/common/index.js +1 -0
- package/lib/cjs/common/payment.js +43 -9
- package/lib/cjs/common/turbo.js +45 -12
- package/lib/cjs/common/upload.js +13 -5
- package/lib/cjs/node/signer.js +33 -2
- package/lib/cjs/utils/readableStream.js +6 -4
- package/lib/cjs/web/signer.js +9 -4
- package/lib/esm/common/currency.js +27 -0
- package/lib/esm/common/index.js +1 -0
- package/lib/esm/common/payment.js +42 -8
- package/lib/esm/common/turbo.js +46 -13
- package/lib/esm/common/upload.js +12 -4
- package/lib/esm/node/signer.js +33 -2
- package/lib/esm/utils/readableStream.js +6 -4
- package/lib/esm/web/signer.js +9 -4
- package/lib/types/common/currency.d.ts +43 -0
- package/lib/types/common/currency.d.ts.map +1 -0
- package/lib/types/common/factory.d.ts +2 -2
- package/lib/types/common/factory.d.ts.map +1 -1
- package/lib/types/common/index.d.ts +1 -0
- package/lib/types/common/index.d.ts.map +1 -1
- package/lib/types/common/payment.d.ts +17 -7
- package/lib/types/common/payment.d.ts.map +1 -1
- package/lib/types/common/turbo.d.ts +32 -9
- package/lib/types/common/turbo.d.ts.map +1 -1
- package/lib/types/common/upload.d.ts +6 -4
- package/lib/types/common/upload.d.ts.map +1 -1
- package/lib/types/node/factory.d.ts +2 -2
- package/lib/types/node/factory.d.ts.map +1 -1
- package/lib/types/node/signer.d.ts +8 -3
- package/lib/types/node/signer.d.ts.map +1 -1
- package/lib/types/types.d.ts +52 -18
- package/lib/types/types.d.ts.map +1 -1
- package/lib/types/utils/readableStream.d.ts +2 -1
- package/lib/types/utils/readableStream.d.ts.map +1 -1
- package/lib/types/web/factory.d.ts +2 -2
- package/lib/types/web/factory.d.ts.map +1 -1
- package/lib/types/web/signer.d.ts +7 -3
- package/lib/types/web/signer.d.ts.map +1 -1
- package/package.json +1 -1
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
|
-
|
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
|
-
|
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
|
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,42 +172,84 @@ 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
|
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
|
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
|
187
|
+
const [uploadCostForFile] = await turbo.getUploadCosts({ bytes: [1024] });
|
188
|
+
const { winc, adjustments } = uploadCostForFile;
|
185
189
|
```
|
186
190
|
|
187
|
-
- `uploadSignedDataItem({ dataItemStreamFactory, signal })` - Uploads a signed data item. The provided dataItemStreamFactory should produce a NEW signed data item stream each time is it invoked.
|
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');
|
195
|
+
const dataItemSize = fs.statSync(filePath).size;
|
191
196
|
const uploadResponse = await turbo.uploadSignedDataItem({
|
192
197
|
dataItemStreamFactory: () => fs.createReadStream(filePath),
|
198
|
+
dataItemSizeFactory: () => dataItemSize,
|
193
199
|
signal: AbortSignal.timeout(10_000), // cancel the upload after 10 seconds
|
194
200
|
});
|
195
201
|
```
|
196
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
|
+
|
197
226
|
### TurboAuthenticatedClient
|
198
227
|
|
199
228
|
- `getBalance()` - Issues a signed request to get the credit balance of a wallet measured in AR (measured in Winston Credits, or winc).
|
200
229
|
|
201
230
|
```typescript
|
202
|
-
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
|
+
});
|
203
242
|
```
|
204
243
|
|
205
|
-
- `uploadFile({ fileStreamFactory })` - Signs and uploads a raw file. The provided fileStreamFactory should produce a NEW file data stream each time is it invoked.
|
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.
|
206
245
|
|
207
246
|
```typescript
|
208
247
|
const filePath = path.join(__dirname, './my-unsigned-file.txt');
|
209
|
-
const
|
248
|
+
const fileSize = fs.stateSync(filePath).size;
|
249
|
+
const uploadResult = await turbo.uploadFile({
|
210
250
|
fileStreamFactory: () => fs.createReadStream(filePath),
|
251
|
+
fileSizeFactory: () => fileSize,
|
252
|
+
// no timeout or AbortSignal provided
|
211
253
|
});
|
212
254
|
```
|
213
255
|
|
@@ -219,3 +261,4 @@ If you encounter any issues or have feature requests, please file an issue on ou
|
|
219
261
|
[examples]: ./examples
|
220
262
|
[TurboUnauthenticatedClient]: #turboUnauthenticatedClient
|
221
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 =
|
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
|
-
|
47409
|
+
getFiatRates() {
|
47408
47410
|
return this.httpService.get({
|
47409
47411
|
endpoint: "/rates"
|
47410
47412
|
});
|
47411
47413
|
}
|
47412
|
-
|
47414
|
+
getFiatToAR({
|
47413
47415
|
currency
|
47414
47416
|
}) {
|
47415
47417
|
return this.httpService.get({
|
47416
47418
|
endpoint: `/rates/${currency}`
|
47417
47419
|
});
|
47418
47420
|
}
|
47419
|
-
|
47421
|
+
getSupportedCountries() {
|
47420
47422
|
return this.httpService.get({
|
47421
47423
|
endpoint: "/countries"
|
47422
47424
|
});
|
47423
47425
|
}
|
47424
|
-
|
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
|
-
|
47442
|
+
getWincForFiat({
|
47443
|
+
amount
|
47444
|
+
}) {
|
47445
|
+
const { amount: paymentAmount, type: currencyType } = amount;
|
47441
47446
|
return this.httpService.get({
|
47442
|
-
endpoint: `/price/${
|
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 =
|
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 =
|
47519
|
+
url = defaultUploadServiceURL,
|
47474
47520
|
retryConfig
|
47475
47521
|
}) {
|
47476
47522
|
this.httpService = new TurboHTTPService({
|
@@ -47480,14 +47526,17 @@ var TurboUnauthenticatedUploadService = class {
|
|
47480
47526
|
}
|
47481
47527
|
async uploadSignedDataItem({
|
47482
47528
|
dataItemStreamFactory,
|
47529
|
+
dataItemSizeFactory,
|
47483
47530
|
signal
|
47484
47531
|
}) {
|
47532
|
+
const fileSize = dataItemSizeFactory();
|
47485
47533
|
return this.httpService.post({
|
47486
47534
|
endpoint: `/tx`,
|
47487
47535
|
signal,
|
47488
47536
|
data: dataItemStreamFactory(),
|
47489
47537
|
headers: {
|
47490
|
-
"content-type": "application/octet-stream"
|
47538
|
+
"content-type": "application/octet-stream",
|
47539
|
+
"content-length": `${fileSize}`
|
47491
47540
|
}
|
47492
47541
|
});
|
47493
47542
|
}
|
@@ -47503,23 +47552,44 @@ var TurboAuthenticatedUploadService = class extends TurboUnauthenticatedUploadSe
|
|
47503
47552
|
}
|
47504
47553
|
async uploadFile({
|
47505
47554
|
fileStreamFactory,
|
47555
|
+
fileSizeFactory,
|
47506
47556
|
signal
|
47507
47557
|
}) {
|
47508
|
-
const
|
47509
|
-
fileStreamFactory
|
47558
|
+
const { dataItemStreamFactory, dataItemSizeFactory } = await this.signer.signDataItem({
|
47559
|
+
fileStreamFactory,
|
47560
|
+
fileSizeFactory
|
47510
47561
|
});
|
47562
|
+
const signedDataItem = dataItemStreamFactory();
|
47563
|
+
const fileSize = dataItemSizeFactory();
|
47511
47564
|
return this.httpService.post({
|
47512
47565
|
endpoint: `/tx`,
|
47513
47566
|
signal,
|
47514
47567
|
data: signedDataItem,
|
47515
47568
|
headers: {
|
47516
|
-
"content-type": "application/octet-stream"
|
47569
|
+
"content-type": "application/octet-stream",
|
47570
|
+
"content-length": `${fileSize}`
|
47517
47571
|
}
|
47518
47572
|
});
|
47519
47573
|
}
|
47520
47574
|
};
|
47521
47575
|
|
47522
47576
|
// src/common/turbo.ts
|
47577
|
+
var developmentTurboConfiguration = {
|
47578
|
+
paymentServiceConfig: {
|
47579
|
+
url: developmentPaymentServiceURL
|
47580
|
+
},
|
47581
|
+
uploadServiceConfig: {
|
47582
|
+
url: developmentUploadServiceURL
|
47583
|
+
}
|
47584
|
+
};
|
47585
|
+
var defaultTurboConfiguration = {
|
47586
|
+
paymentServiceConfig: {
|
47587
|
+
url: defaultPaymentServiceURL
|
47588
|
+
},
|
47589
|
+
uploadServiceConfig: {
|
47590
|
+
url: defaultUploadServiceURL
|
47591
|
+
}
|
47592
|
+
};
|
47523
47593
|
var TurboUnauthenticatedClient = class {
|
47524
47594
|
constructor({
|
47525
47595
|
uploadService = new TurboUnauthenticatedUploadService({}),
|
@@ -47531,7 +47601,7 @@ var TurboUnauthenticatedClient = class {
|
|
47531
47601
|
/**
|
47532
47602
|
* Returns the supported fiat currency conversion rate for 1AR based on current market prices.
|
47533
47603
|
*/
|
47534
|
-
|
47604
|
+
getFiatToAR({
|
47535
47605
|
currency
|
47536
47606
|
}) {
|
47537
47607
|
return this.paymentService.getFiatToAR({ currency });
|
@@ -47542,25 +47612,25 @@ var TurboUnauthenticatedClient = class {
|
|
47542
47612
|
* Note: this does not take into account varying adjustments and promotions for different sizes of data. If you want to calculate the total
|
47543
47613
|
* cost in 'winc' for a given number of bytes, use getUploadCosts.
|
47544
47614
|
*/
|
47545
|
-
|
47615
|
+
getFiatRates() {
|
47546
47616
|
return this.paymentService.getFiatRates();
|
47547
47617
|
}
|
47548
47618
|
/**
|
47549
47619
|
* Returns a comprehensive list of supported countries that can purchase credits through the Turbo Payment Service.
|
47550
47620
|
*/
|
47551
|
-
|
47621
|
+
getSupportedCountries() {
|
47552
47622
|
return this.paymentService.getSupportedCountries();
|
47553
47623
|
}
|
47554
47624
|
/**
|
47555
47625
|
* Returns a list of all supported fiat currencies.
|
47556
47626
|
*/
|
47557
|
-
|
47627
|
+
getSupportedCurrencies() {
|
47558
47628
|
return this.paymentService.getSupportedCurrencies();
|
47559
47629
|
}
|
47560
47630
|
/**
|
47561
47631
|
* Determines the price in 'winc' to upload one data item of a specific size in bytes, including all Turbo cost adjustments and fees.
|
47562
47632
|
*/
|
47563
|
-
|
47633
|
+
getUploadCosts({
|
47564
47634
|
bytes
|
47565
47635
|
}) {
|
47566
47636
|
return this.paymentService.getUploadCosts({ bytes });
|
@@ -47568,24 +47638,29 @@ var TurboUnauthenticatedClient = class {
|
|
47568
47638
|
/**
|
47569
47639
|
* Determines the amount of 'winc' that would be returned for a given currency and amount, including all Turbo cost adjustments and fees.
|
47570
47640
|
*/
|
47571
|
-
|
47572
|
-
|
47573
|
-
currency
|
47574
|
-
}) {
|
47575
|
-
return this.paymentService.getWincForFiat({ amount, currency });
|
47641
|
+
getWincForFiat(params) {
|
47642
|
+
return this.paymentService.getWincForFiat(params);
|
47576
47643
|
}
|
47577
47644
|
/**
|
47578
47645
|
* Uploads a signed data item to the Turbo Upload Service.
|
47579
47646
|
*/
|
47580
|
-
|
47647
|
+
uploadSignedDataItem({
|
47581
47648
|
dataItemStreamFactory,
|
47649
|
+
dataItemSizeFactory,
|
47582
47650
|
signal
|
47583
47651
|
}) {
|
47584
47652
|
return this.uploadService.uploadSignedDataItem({
|
47585
47653
|
dataItemStreamFactory,
|
47654
|
+
dataItemSizeFactory,
|
47586
47655
|
signal
|
47587
47656
|
});
|
47588
47657
|
}
|
47658
|
+
/**
|
47659
|
+
* Creates a Turbo Checkout Session for a given amount and currency.
|
47660
|
+
*/
|
47661
|
+
createCheckoutSession(params) {
|
47662
|
+
return this.paymentService.createCheckoutSession(params);
|
47663
|
+
}
|
47589
47664
|
};
|
47590
47665
|
var TurboAuthenticatedClient = class extends TurboUnauthenticatedClient {
|
47591
47666
|
constructor({
|
@@ -47597,17 +47672,22 @@ var TurboAuthenticatedClient = class extends TurboUnauthenticatedClient {
|
|
47597
47672
|
/**
|
47598
47673
|
* Returns the current balance of the user's wallet in 'winc'.
|
47599
47674
|
*/
|
47600
|
-
|
47675
|
+
getBalance() {
|
47601
47676
|
return this.paymentService.getBalance();
|
47602
47677
|
}
|
47603
47678
|
/**
|
47604
47679
|
* Signs and uploads raw data to the Turbo Upload Service.
|
47605
47680
|
*/
|
47606
|
-
|
47681
|
+
uploadFile({
|
47607
47682
|
fileStreamFactory,
|
47683
|
+
fileSizeFactory,
|
47608
47684
|
signal
|
47609
47685
|
}) {
|
47610
|
-
return this.uploadService.uploadFile({
|
47686
|
+
return this.uploadService.uploadFile({
|
47687
|
+
fileStreamFactory,
|
47688
|
+
fileSizeFactory,
|
47689
|
+
signal
|
47690
|
+
});
|
47611
47691
|
}
|
47612
47692
|
};
|
47613
47693
|
|
@@ -47633,6 +47713,34 @@ var TurboBaseFactory = class {
|
|
47633
47713
|
// src/common/index.ts
|
47634
47714
|
init_shim();
|
47635
47715
|
|
47716
|
+
// src/common/currency.ts
|
47717
|
+
init_shim();
|
47718
|
+
var ZeroDecimalCurrency = class {
|
47719
|
+
constructor(amount, type) {
|
47720
|
+
this.amount = amount;
|
47721
|
+
this.type = type;
|
47722
|
+
}
|
47723
|
+
};
|
47724
|
+
var TwoDecimalCurrency = class {
|
47725
|
+
constructor(a, type) {
|
47726
|
+
this.a = a;
|
47727
|
+
this.type = type;
|
47728
|
+
}
|
47729
|
+
get amount() {
|
47730
|
+
return this.a * 100;
|
47731
|
+
}
|
47732
|
+
};
|
47733
|
+
var USD = (usd) => new TwoDecimalCurrency(usd, "usd");
|
47734
|
+
var EUR = (eur) => new TwoDecimalCurrency(eur, "eur");
|
47735
|
+
var GBP = (gbp) => new TwoDecimalCurrency(gbp, "gbp");
|
47736
|
+
var CAD = (cad) => new TwoDecimalCurrency(cad, "cad");
|
47737
|
+
var AUD = (aud) => new TwoDecimalCurrency(aud, "aud");
|
47738
|
+
var INR = (inr) => new TwoDecimalCurrency(inr, "inr");
|
47739
|
+
var SGD = (sgd) => new TwoDecimalCurrency(sgd, "sgd");
|
47740
|
+
var HKD = (hkd) => new TwoDecimalCurrency(hkd, "hkd");
|
47741
|
+
var BRL = (brl) => new TwoDecimalCurrency(brl, "brl");
|
47742
|
+
var JPY = (jpy) => new ZeroDecimalCurrency(jpy, "jpy");
|
47743
|
+
|
47636
47744
|
// src/web/signer.ts
|
47637
47745
|
init_shim();
|
47638
47746
|
|
@@ -55555,19 +55663,22 @@ function toB64Url(buffer) {
|
|
55555
55663
|
// src/utils/readableStream.ts
|
55556
55664
|
init_shim();
|
55557
55665
|
async function readableStreamToBuffer({
|
55558
|
-
stream
|
55666
|
+
stream,
|
55667
|
+
size
|
55559
55668
|
}) {
|
55560
55669
|
const reader = stream.getReader();
|
55561
|
-
const
|
55670
|
+
const buffer = import_buffer.Buffer.alloc(size);
|
55671
|
+
let offset = 0;
|
55562
55672
|
let done = false;
|
55563
55673
|
while (!done) {
|
55564
55674
|
const { done: streamDone, value } = await reader.read();
|
55565
55675
|
done = streamDone;
|
55566
55676
|
if (!done) {
|
55567
|
-
|
55677
|
+
buffer.set(value, offset);
|
55678
|
+
offset += value.byteLength;
|
55568
55679
|
}
|
55569
55680
|
}
|
55570
|
-
return
|
55681
|
+
return buffer;
|
55571
55682
|
}
|
55572
55683
|
|
55573
55684
|
// src/web/signer.ts
|
@@ -55578,15 +55689,20 @@ var TurboWebArweaveSigner = class {
|
|
55578
55689
|
this.signer = new ArweaveSigner(this.privateKey);
|
55579
55690
|
}
|
55580
55691
|
async signDataItem({
|
55581
|
-
fileStreamFactory
|
55692
|
+
fileStreamFactory,
|
55693
|
+
fileSizeFactory
|
55582
55694
|
}) {
|
55583
55695
|
const buffer = await readableStreamToBuffer({
|
55584
|
-
stream: fileStreamFactory()
|
55585
|
-
|
55696
|
+
stream: fileStreamFactory(),
|
55697
|
+
size: fileSizeFactory()
|
55586
55698
|
});
|
55587
|
-
const signedDataItem = createData(buffer, this.signer);
|
55699
|
+
const signedDataItem = createData(buffer, this.signer, {});
|
55588
55700
|
await signedDataItem.sign(this.signer);
|
55589
|
-
return
|
55701
|
+
return {
|
55702
|
+
// while this returns a Buffer - it needs to match our return type for uploading
|
55703
|
+
dataItemStreamFactory: () => signedDataItem.getRaw(),
|
55704
|
+
dataItemSizeFactory: () => signedDataItem.getRaw().length
|
55705
|
+
};
|
55590
55706
|
}
|
55591
55707
|
// NOTE: this might be better in a parent class or elsewhere - easy enough to leave in here now and does require specific environment version of crypto
|
55592
55708
|
async generateSignedRequestHeaders() {
|
@@ -55628,6 +55744,15 @@ var TurboFactory = class extends TurboBaseFactory {
|
|
55628
55744
|
// src/types.ts
|
55629
55745
|
init_shim();
|
55630
55746
|
export {
|
55747
|
+
AUD,
|
55748
|
+
BRL,
|
55749
|
+
CAD,
|
55750
|
+
EUR,
|
55751
|
+
GBP,
|
55752
|
+
HKD,
|
55753
|
+
INR,
|
55754
|
+
JPY,
|
55755
|
+
SGD,
|
55631
55756
|
TurboAuthenticatedClient,
|
55632
55757
|
TurboAuthenticatedPaymentService,
|
55633
55758
|
TurboAuthenticatedUploadService,
|
@@ -55635,7 +55760,16 @@ export {
|
|
55635
55760
|
TurboUnauthenticatedClient,
|
55636
55761
|
TurboUnauthenticatedPaymentService,
|
55637
55762
|
TurboUnauthenticatedUploadService,
|
55638
|
-
TurboWebArweaveSigner
|
55763
|
+
TurboWebArweaveSigner,
|
55764
|
+
TwoDecimalCurrency,
|
55765
|
+
USD,
|
55766
|
+
ZeroDecimalCurrency,
|
55767
|
+
defaultPaymentServiceURL,
|
55768
|
+
defaultTurboConfiguration,
|
55769
|
+
defaultUploadServiceURL,
|
55770
|
+
developmentPaymentServiceURL,
|
55771
|
+
developmentTurboConfiguration,
|
55772
|
+
developmentUploadServiceURL
|
55639
55773
|
};
|
55640
55774
|
/*! Bundled license information:
|
55641
55775
|
|
@@ -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;
|
package/lib/cjs/common/index.js
CHANGED