@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.
Files changed (99) hide show
  1. package/README.md +103 -11
  2. package/bundles/web.bundle.min.js +25370 -12548
  3. package/lib/cjs/common/factory.js +20 -10
  4. package/lib/cjs/common/http.js +1 -1
  5. package/lib/cjs/common/index.js +1 -1
  6. package/lib/cjs/common/logger.js +1 -1
  7. package/lib/cjs/common/payment.js +1 -1
  8. package/lib/cjs/common/signer.js +1 -1
  9. package/lib/cjs/common/token/arweave.js +3 -3
  10. package/lib/cjs/common/token/ethereum.js +3 -3
  11. package/lib/cjs/common/token/solana.js +3 -3
  12. package/lib/cjs/common/turbo.js +3 -0
  13. package/lib/cjs/common/upload.js +106 -3
  14. package/lib/cjs/node/factory.js +1 -1
  15. package/lib/cjs/node/index.js +2 -1
  16. package/lib/cjs/node/signer.js +1 -1
  17. package/lib/cjs/node/upload.js +72 -0
  18. package/lib/cjs/types.js +6 -2
  19. package/lib/cjs/utils/axiosClient.js +1 -1
  20. package/lib/cjs/utils/base64.js +7 -7
  21. package/lib/cjs/utils/common.js +6 -3
  22. package/lib/cjs/utils/errors.js +1 -1
  23. package/lib/cjs/utils/readableStream.js +1 -2
  24. package/lib/cjs/version.js +2 -2
  25. package/lib/cjs/web/factory.js +3 -2
  26. package/lib/cjs/web/index.js +2 -1
  27. package/lib/cjs/web/signer.js +1 -1
  28. package/lib/cjs/web/upload.js +57 -0
  29. package/lib/esm/common/factory.js +19 -9
  30. package/lib/esm/common/http.js +1 -1
  31. package/lib/esm/common/index.js +1 -1
  32. package/lib/esm/common/logger.js +1 -1
  33. package/lib/esm/common/payment.js +1 -1
  34. package/lib/esm/common/signer.js +1 -1
  35. package/lib/esm/common/token/arweave.js +3 -3
  36. package/lib/esm/common/token/ethereum.js +3 -3
  37. package/lib/esm/common/token/solana.js +3 -3
  38. package/lib/esm/common/turbo.js +3 -0
  39. package/lib/esm/common/upload.js +104 -1
  40. package/lib/esm/node/factory.js +1 -1
  41. package/lib/esm/node/index.js +2 -1
  42. package/lib/esm/node/signer.js +1 -1
  43. package/lib/esm/node/upload.js +68 -0
  44. package/lib/esm/types.js +2 -0
  45. package/lib/esm/utils/axiosClient.js +1 -1
  46. package/lib/esm/utils/base64.js +1 -1
  47. package/lib/esm/utils/common.js +4 -1
  48. package/lib/esm/utils/errors.js +1 -1
  49. package/lib/esm/version.js +2 -2
  50. package/lib/esm/web/factory.js +4 -3
  51. package/lib/esm/web/index.js +2 -1
  52. package/lib/esm/web/signer.js +1 -1
  53. package/lib/esm/web/upload.js +53 -0
  54. package/lib/types/common/currency.d.ts +1 -1
  55. package/lib/types/common/factory.d.ts.map +1 -1
  56. package/lib/types/common/http.d.ts +1 -4
  57. package/lib/types/common/http.d.ts.map +1 -1
  58. package/lib/types/common/index.d.ts +1 -1
  59. package/lib/types/common/jwk.d.ts +1 -1
  60. package/lib/types/common/logger.d.ts +1 -1
  61. package/lib/types/common/signer.d.ts +0 -1
  62. package/lib/types/common/signer.d.ts.map +1 -1
  63. package/lib/types/common/token/arweave.d.ts +1 -1
  64. package/lib/types/common/token/arweave.d.ts.map +1 -1
  65. package/lib/types/common/token/ethereum.d.ts +1 -1
  66. package/lib/types/common/token/ethereum.d.ts.map +1 -1
  67. package/lib/types/common/token/index.d.ts +1 -1
  68. package/lib/types/common/token/solana.d.ts +1 -1
  69. package/lib/types/common/token/solana.d.ts.map +1 -1
  70. package/lib/types/common/turbo.d.ts +3 -2
  71. package/lib/types/common/turbo.d.ts.map +1 -1
  72. package/lib/types/common/upload.d.ts +19 -3
  73. package/lib/types/common/upload.d.ts.map +1 -1
  74. package/lib/types/node/factory.d.ts +1 -1
  75. package/lib/types/node/index.d.ts +2 -1
  76. package/lib/types/node/index.d.ts.map +1 -1
  77. package/lib/types/node/signer.d.ts +1 -2
  78. package/lib/types/node/signer.d.ts.map +1 -1
  79. package/lib/types/node/upload.d.ts +15 -0
  80. package/lib/types/node/upload.d.ts.map +1 -0
  81. package/lib/types/types.d.ts +41 -5
  82. package/lib/types/types.d.ts.map +1 -1
  83. package/lib/types/utils/axiosClient.d.ts +1 -1
  84. package/lib/types/utils/base64.d.ts +0 -1
  85. package/lib/types/utils/base64.d.ts.map +1 -1
  86. package/lib/types/utils/common.d.ts +2 -1
  87. package/lib/types/utils/common.d.ts.map +1 -1
  88. package/lib/types/utils/errors.d.ts +1 -1
  89. package/lib/types/utils/readableStream.d.ts +1 -3
  90. package/lib/types/utils/readableStream.d.ts.map +1 -1
  91. package/lib/types/version.d.ts +2 -2
  92. package/lib/types/web/factory.d.ts.map +1 -1
  93. package/lib/types/web/index.d.ts +2 -1
  94. package/lib/types/web/index.d.ts.map +1 -1
  95. package/lib/types/web/signer.d.ts +1 -2
  96. package/lib/types/web/signer.d.ts.map +1 -1
  97. package/lib/types/web/upload.d.ts +29 -0
  98. package/lib/types/web/upload.d.ts.map +1 -0
  99. 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
- ##### Construct Turbo with an Arweave JWK
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
- ##### Construct Turbo with an Arweave signer
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
- ##### Construct Turbo with an Arconnect signer
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
- ##### Construct Turbo with an ETH signer
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
- ##### Construct Turbo with an ETH private key
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
- ##### Construct Turbo with a SOL signer
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
- ##### Construct Turbo with a SOL secret key
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
- ##### Top up to ETH or SOL wallets
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
- - Note: 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
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
- ##### Top up ETH tokens to ETH wallet
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
- ##### Top up SOL tokens to SOL wallet
558
+ ##### Solana (SOL)
467
559
 
468
560
  ```ts
469
561
  const turbo = TurboFactory.authenticated({ signer, token: 'solana' });