@ardrive/turbo-sdk 1.9.0 → 1.10.0-alpha.1
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 +103 -11
- package/bundles/web.bundle.min.js +25370 -12548
- package/lib/cjs/common/factory.js +20 -10
- package/lib/cjs/common/http.js +1 -1
- package/lib/cjs/common/index.js +1 -1
- package/lib/cjs/common/logger.js +1 -1
- package/lib/cjs/common/payment.js +1 -1
- package/lib/cjs/common/signer.js +1 -1
- package/lib/cjs/common/token/arweave.js +3 -3
- package/lib/cjs/common/token/ethereum.js +3 -3
- package/lib/cjs/common/token/solana.js +3 -3
- package/lib/cjs/common/turbo.js +3 -0
- package/lib/cjs/common/upload.js +106 -3
- package/lib/cjs/node/factory.js +1 -1
- package/lib/cjs/node/index.js +2 -1
- package/lib/cjs/node/signer.js +1 -1
- package/lib/cjs/node/upload.js +72 -0
- package/lib/cjs/types.js +6 -2
- package/lib/cjs/utils/axiosClient.js +1 -1
- package/lib/cjs/utils/base64.js +7 -7
- package/lib/cjs/utils/common.js +6 -3
- package/lib/cjs/utils/errors.js +1 -1
- package/lib/cjs/utils/readableStream.js +1 -2
- package/lib/cjs/version.js +2 -2
- package/lib/cjs/web/factory.js +3 -2
- package/lib/cjs/web/index.js +2 -1
- package/lib/cjs/web/signer.js +1 -1
- package/lib/cjs/web/upload.js +57 -0
- package/lib/esm/common/factory.js +19 -9
- package/lib/esm/common/http.js +1 -1
- package/lib/esm/common/index.js +1 -1
- package/lib/esm/common/logger.js +1 -1
- package/lib/esm/common/payment.js +1 -1
- package/lib/esm/common/signer.js +1 -1
- package/lib/esm/common/token/arweave.js +3 -3
- package/lib/esm/common/token/ethereum.js +3 -3
- package/lib/esm/common/token/solana.js +3 -3
- package/lib/esm/common/turbo.js +3 -0
- package/lib/esm/common/upload.js +104 -1
- package/lib/esm/node/factory.js +1 -1
- package/lib/esm/node/index.js +2 -1
- package/lib/esm/node/signer.js +1 -1
- package/lib/esm/node/upload.js +68 -0
- package/lib/esm/types.js +2 -0
- package/lib/esm/utils/axiosClient.js +1 -1
- package/lib/esm/utils/base64.js +1 -1
- package/lib/esm/utils/common.js +4 -1
- package/lib/esm/utils/errors.js +1 -1
- package/lib/esm/version.js +2 -2
- package/lib/esm/web/factory.js +4 -3
- package/lib/esm/web/index.js +2 -1
- package/lib/esm/web/signer.js +1 -1
- package/lib/esm/web/upload.js +53 -0
- package/lib/types/common/currency.d.ts +1 -1
- package/lib/types/common/factory.d.ts.map +1 -1
- package/lib/types/common/http.d.ts +1 -4
- package/lib/types/common/http.d.ts.map +1 -1
- package/lib/types/common/index.d.ts +1 -1
- package/lib/types/common/jwk.d.ts +1 -1
- package/lib/types/common/logger.d.ts +1 -1
- package/lib/types/common/signer.d.ts +0 -1
- package/lib/types/common/signer.d.ts.map +1 -1
- package/lib/types/common/token/arweave.d.ts +1 -1
- package/lib/types/common/token/arweave.d.ts.map +1 -1
- package/lib/types/common/token/ethereum.d.ts +1 -1
- package/lib/types/common/token/ethereum.d.ts.map +1 -1
- package/lib/types/common/token/index.d.ts +1 -1
- package/lib/types/common/token/solana.d.ts +1 -1
- package/lib/types/common/token/solana.d.ts.map +1 -1
- package/lib/types/common/turbo.d.ts +3 -2
- package/lib/types/common/turbo.d.ts.map +1 -1
- package/lib/types/common/upload.d.ts +19 -3
- package/lib/types/common/upload.d.ts.map +1 -1
- package/lib/types/node/factory.d.ts +1 -1
- package/lib/types/node/index.d.ts +2 -1
- package/lib/types/node/index.d.ts.map +1 -1
- package/lib/types/node/signer.d.ts +1 -2
- package/lib/types/node/signer.d.ts.map +1 -1
- package/lib/types/node/upload.d.ts +15 -0
- package/lib/types/node/upload.d.ts.map +1 -0
- package/lib/types/types.d.ts +41 -5
- package/lib/types/types.d.ts.map +1 -1
- package/lib/types/utils/axiosClient.d.ts +1 -1
- package/lib/types/utils/base64.d.ts +0 -1
- package/lib/types/utils/base64.d.ts.map +1 -1
- package/lib/types/utils/common.d.ts +2 -1
- package/lib/types/utils/common.d.ts.map +1 -1
- package/lib/types/utils/errors.d.ts +1 -1
- package/lib/types/utils/readableStream.d.ts +1 -3
- package/lib/types/utils/readableStream.d.ts.map +1 -1
- package/lib/types/version.d.ts +2 -2
- package/lib/types/web/factory.d.ts.map +1 -1
- package/lib/types/web/index.d.ts +2 -1
- package/lib/types/web/index.d.ts.map +1 -1
- package/lib/types/web/signer.d.ts +1 -2
- package/lib/types/web/signer.d.ts.map +1 -1
- package/lib/types/web/upload.d.ts +29 -0
- package/lib/types/web/upload.d.ts.map +1 -0
- package/package.json +11 -5
package/README.md
CHANGED
@@ -6,17 +6,31 @@ Welcome to the `@ardrive/turbo-sdk`! This SDK provides functionality for interac
|
|
6
6
|
|
7
7
|
## Table of Contents
|
8
8
|
|
9
|
+
<!-- toc -->
|
10
|
+
|
11
|
+
- [Table of Contents](#table-of-contents)
|
9
12
|
- [Installation](#installation)
|
10
13
|
- [Quick Start](#quick-start)
|
11
14
|
- [Usage](#usage)
|
12
15
|
- [Web](#web)
|
16
|
+
- [Bundlers (Webpack, Rollup, ESbuild, etc.)](#bundlers-webpack-rollup-esbuild-etc)
|
17
|
+
- [Browser](#browser)
|
13
18
|
- [NodeJS](#nodejs)
|
19
|
+
- [CommonJS](#commonjs)
|
20
|
+
- [ESM](#esm)
|
14
21
|
- [Typescript](#typescript)
|
15
22
|
- [Examples](#examples)
|
16
23
|
- [APIs](#apis)
|
17
24
|
- [TurboFactory](#turbofactory)
|
18
25
|
- [`unauthenticated()`](#unauthenticated)
|
19
26
|
- [`authenticated()`](#authenticated)
|
27
|
+
- [Arweave JWK](#arweave-jwk)
|
28
|
+
- [ArweaveSigner](#arweavesigner)
|
29
|
+
- [ArconnectSigner](#arconnectsigner)
|
30
|
+
- [EthereumSigner](#ethereumsigner)
|
31
|
+
- [Ethereum Private Key](#ethereum-private-key)
|
32
|
+
- [HexSolanaSigner](#hexsolanasigner)
|
33
|
+
- [Solana Secret Key](#solana-secret-key)
|
20
34
|
- [TurboUnauthenticatedClient](#turbounauthenticatedclient)
|
21
35
|
- [`getSupportedCurrencies()`](#getsupportedcurrencies)
|
22
36
|
- [`getSupportedCountries()`](#getsupportedcountries)
|
@@ -26,14 +40,29 @@ Welcome to the `@ardrive/turbo-sdk`! This SDK provides functionality for interac
|
|
26
40
|
- [`getUploadCosts({ bytes })`](#getuploadcosts-bytes-)
|
27
41
|
- [`uploadSignedDataItem({ dataItemStreamFactory, dataItemSizeFactory, signal })`](#uploadsigneddataitem-dataitemstreamfactory-dataitemsizefactory-signal-)
|
28
42
|
- [`createCheckoutSession({ amount, owner })`](#createcheckoutsession-amount-owner-)
|
43
|
+
- [Arweave (AR)](#arweave-ar)
|
44
|
+
- [Ethereum (ETH)](#ethereum-eth)
|
45
|
+
- [Solana (SOL)](#solana-sol)
|
29
46
|
- [`submitFundTransaction({ txId })`](#submitfundtransaction-txid-)
|
30
47
|
- [TurboAuthenticatedClient](#turboauthenticatedclient)
|
31
48
|
- [`getBalance()`](#getbalance)
|
32
49
|
- [`getWincForFiat({ amount, promoCodes })`](#getwincforfiat-amount-promocodes-)
|
33
50
|
- [`createCheckoutSession({ amount, owner, promoCodes })`](#createcheckoutsession-amount-owner-promocodes-)
|
34
51
|
- [`uploadFile({ fileStreamFactory, fileSizeFactory, signal, dataItemOpts })`](#uploadfile-filestreamfactory-filesizefactory-signal-dataitemopts-)
|
52
|
+
- [`uploadFolder({ folderPath, files, dataItemOpts, signal, maxConcurrentUploads, throwOnFailure, manifestOptions })`](#uploadfolder-folderpath-files-dataitemopts-signal-maxconcurrentuploads-throwonfailure-manifestoptions-)
|
53
|
+
- [NodeJS Upload Folder](#nodejs-upload-folder)
|
54
|
+
- [Browser Upload Folder](#browser-upload-folder)
|
35
55
|
- [`topUpWithTokens({ tokenAmount, feeMultiplier })`](#topupwithtokens-tokenamount-feemultiplier-)
|
56
|
+
- [Ethereum (ETH)](#ethereum-eth-1)
|
57
|
+
- [Solana (SOL)](#solana-sol-1)
|
36
58
|
- [Developers](#developers)
|
59
|
+
- [Requirements](#requirements)
|
60
|
+
- [Setup & Build](#setup--build)
|
61
|
+
- [Testing](#testing)
|
62
|
+
- [Linting & Formatting](#linting--formatting)
|
63
|
+
- [Architecture](#architecture)
|
64
|
+
|
65
|
+
<!-- tocstop -->
|
37
66
|
|
38
67
|
## Installation
|
39
68
|
|
@@ -119,6 +148,9 @@ const turbo = TurboFactory.unauthenticated();
|
|
119
148
|
const rates = await turbo.getFiatRates();
|
120
149
|
```
|
121
150
|
|
151
|
+
> [!WARNING]
|
152
|
+
> Polyfills are not provided by default for bundled web projects (Vite, ESBuild, Webpack, Rollup, etc.) . Depending on your apps bundler configuration and plugins, you will need to provide polyfills for various imports including `crypto`, `process`, `fs` and `buffer`. Refer to your bundler's documentation for how to provide the necessary polyfills.
|
153
|
+
|
122
154
|
ESM:
|
123
155
|
|
124
156
|
```javascript
|
@@ -183,35 +215,35 @@ const turbo = TurboFactory.unauthenticated();
|
|
183
215
|
|
184
216
|
Creates an instance of a client that accesses Turbo's authenticated and unauthenticated services. Requires either a signer, or private key to be provided.
|
185
217
|
|
186
|
-
#####
|
218
|
+
##### Arweave JWK
|
187
219
|
|
188
220
|
```typescript
|
189
221
|
const jwk = await arweave.crypto.generateJWK();
|
190
222
|
const turbo = TurboFactory.authenticated({ privateKey: jwk });
|
191
223
|
```
|
192
224
|
|
193
|
-
#####
|
225
|
+
##### ArweaveSigner
|
194
226
|
|
195
227
|
```typescript
|
196
228
|
const signer = new ArweaveSigner(jwk);
|
197
229
|
const turbo = TurboFactory.authenticated({ signer });
|
198
230
|
```
|
199
231
|
|
200
|
-
#####
|
232
|
+
##### ArconnectSigner
|
201
233
|
|
202
234
|
```typescript
|
203
235
|
const signer = new ArconnectSigner(window.arweaveWallet);
|
204
236
|
const turbo = TurboFactory.authenticated({ signer });
|
205
237
|
```
|
206
238
|
|
207
|
-
#####
|
239
|
+
##### EthereumSigner
|
208
240
|
|
209
241
|
```typescript
|
210
242
|
const signer = new EthereumSigner(privateKey);
|
211
243
|
const turbo = TurboFactory.authenticated({ signer });
|
212
244
|
```
|
213
245
|
|
214
|
-
#####
|
246
|
+
##### Ethereum Private Key
|
215
247
|
|
216
248
|
```typescript
|
217
249
|
const turbo = TurboFactory.authenticated({
|
@@ -220,14 +252,14 @@ const turbo = TurboFactory.authenticated({
|
|
220
252
|
});
|
221
253
|
```
|
222
254
|
|
223
|
-
#####
|
255
|
+
##### HexSolanaSigner
|
224
256
|
|
225
257
|
```typescript
|
226
258
|
const signer = new HexSolanaSigner(bs58.encode(secretKey));
|
227
259
|
const turbo = TurboFactory.authenticated({ signer });
|
228
260
|
```
|
229
261
|
|
230
|
-
#####
|
262
|
+
##### Solana Secret Key
|
231
263
|
|
232
264
|
```typescript
|
233
265
|
const turbo = TurboFactory.authenticated({
|
@@ -309,6 +341,8 @@ const uploadResponse = await turbo.uploadSignedDataItem({
|
|
309
341
|
|
310
342
|
Creates a Stripe checkout session for a Turbo Top Up with the provided amount, currency, owner. The returned URL can be opened in the browser, all payments are processed by Stripe. To leverage promo codes, see [TurboAuthenticatedClient].
|
311
343
|
|
344
|
+
##### Arweave (AR)
|
345
|
+
|
312
346
|
```typescript
|
313
347
|
const { url, winc, paymentAmount, quotedPaymentAmount, adjustments } =
|
314
348
|
await turbo.createCheckoutSession({
|
@@ -330,7 +364,7 @@ if (process.platform === 'darwin') {
|
|
330
364
|
}
|
331
365
|
```
|
332
366
|
|
333
|
-
#####
|
367
|
+
##### Ethereum (ETH)
|
334
368
|
|
335
369
|
```ts
|
336
370
|
const turbo = TurboFactory.unauthenticated({ token: 'ethereum' });
|
@@ -341,6 +375,8 @@ const { url, winc, paymentAmount } = await turbo.createCheckoutSession({
|
|
341
375
|
});
|
342
376
|
```
|
343
377
|
|
378
|
+
##### Solana (SOL)
|
379
|
+
|
344
380
|
```ts
|
345
381
|
const turbo = TurboFactory.unauthenticated({ token: 'solana' });
|
346
382
|
|
@@ -354,7 +390,8 @@ const { url, winc, paymentAmount } = await turbo.createCheckoutSession({
|
|
354
390
|
|
355
391
|
Submits the transaction ID of a funding transaction to Turbo Payment Service for top up processing. The `txId` is the transaction ID of the transaction to be submitted.
|
356
392
|
|
357
|
-
|
393
|
+
> [!NOTE]
|
394
|
+
> Use this API if you've already executed your token transfer to the Turbo wallet. Otherwise, consider using `topUpWithTokens` to execute a new token transfer to the Turbo wallet and submit its resulting transaction ID for top up processing all in one go
|
358
395
|
|
359
396
|
```typescript
|
360
397
|
const turbo = TurboFactory.unauthenticated(); // defaults to arweave token type
|
@@ -437,6 +474,61 @@ const uploadResult = await turbo.uploadFile({
|
|
437
474
|
});
|
438
475
|
```
|
439
476
|
|
477
|
+
#### `uploadFolder({ folderPath, files, dataItemOpts, signal, maxConcurrentUploads, throwOnFailure, manifestOptions })`
|
478
|
+
|
479
|
+
Signs and uploads a folder of files. For NodeJS, the `folderPath` of the folder to upload is required. For the browser, an array of `files` is required. The `dataItemOpts` is an optional object that can be used to configure tags, target, and anchor for the data item upload. The `signal` is an optional [AbortSignal] that can be used to cancel the upload or timeout the request. The `maxConcurrentUploads` is an optional number that can be used to limit the number of concurrent uploads. The `throwOnFailure` is an optional boolean that can be used to throw an error if any upload fails. The `manifestOptions` is an optional object that can be used to configure the manifest file, including a custom index file, fallback file, or whether to disable manifests altogether. Manifests are enabled by default.
|
480
|
+
|
481
|
+
##### NodeJS Upload Folder
|
482
|
+
|
483
|
+
```typescript
|
484
|
+
const folderPath = path.join(__dirname, './my-folder');
|
485
|
+
const { manifest, fileResponses, manifestResponse } = await turbo.uploadFolder({
|
486
|
+
folderPath,
|
487
|
+
dataItemOpts: {
|
488
|
+
// optional
|
489
|
+
tags: [
|
490
|
+
{
|
491
|
+
// User defined content type will overwrite file content type
|
492
|
+
name: 'Content-Type',
|
493
|
+
value: 'text/plain',
|
494
|
+
},
|
495
|
+
{
|
496
|
+
name: 'My-Custom-Tag',
|
497
|
+
value: 'my-custom-value',
|
498
|
+
},
|
499
|
+
],
|
500
|
+
// no timeout or AbortSignal provided
|
501
|
+
},
|
502
|
+
manifestOptions: {
|
503
|
+
// optional
|
504
|
+
indexFile: 'custom-index.html',
|
505
|
+
fallbackFile: 'custom-fallback.html',
|
506
|
+
disableManifests: false,
|
507
|
+
},
|
508
|
+
});
|
509
|
+
```
|
510
|
+
|
511
|
+
##### Browser Upload Folder
|
512
|
+
|
513
|
+
```html
|
514
|
+
<input type="file" id="folder" name="folder" webkitdirectory />
|
515
|
+
<script type="module">
|
516
|
+
const folderInput = document.getElementById('folder');
|
517
|
+
|
518
|
+
folderInput.addEventListener('change', async (event) => {
|
519
|
+
const selectedFiles = folderInput.files;
|
520
|
+
console.log('Folder selected:', selectedFiles);
|
521
|
+
|
522
|
+
const { manifest, fileResponses, manifestResponse } =
|
523
|
+
await turbo.uploadFolder({
|
524
|
+
files: Array.from(selectedFiles).map((file) => file),
|
525
|
+
});
|
526
|
+
|
527
|
+
console.log(manifest, fileResponses, manifestResponse);
|
528
|
+
});
|
529
|
+
</script>
|
530
|
+
```
|
531
|
+
|
440
532
|
#### `topUpWithTokens({ tokenAmount, feeMultiplier })`
|
441
533
|
|
442
534
|
Tops up the connected wallet with Credits by submitting a payment transaction for the token amount to the Turbo wallet and then submitting that transaction id to Turbo Payment Service for top up processing.
|
@@ -453,7 +545,7 @@ const { winc, status, id, ...fundResult } = await turbo.topUpWithTokens({
|
|
453
545
|
});
|
454
546
|
```
|
455
547
|
|
456
|
-
#####
|
548
|
+
##### Ethereum (ETH)
|
457
549
|
|
458
550
|
```ts
|
459
551
|
const turbo = TurboFactory.authenticated({ signer, token: 'ethereum' });
|
@@ -463,7 +555,7 @@ const { winc, status, id, ...fundResult } = await turbo.topUpWithTokens({
|
|
463
555
|
});
|
464
556
|
```
|
465
557
|
|
466
|
-
#####
|
558
|
+
##### Solana (SOL)
|
467
559
|
|
468
560
|
```ts
|
469
561
|
const turbo = TurboFactory.authenticated({ signer, token: 'solana' });
|