@ardrive/turbo-sdk 1.0.0-alpha.8 → 1.0.0-beta.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 (92) hide show
  1. package/README.md +130 -23
  2. package/bundles/web.bundle.min.js +55668 -0
  3. package/lib/cjs/common/factory.js +6 -2
  4. package/lib/cjs/common/http.js +16 -29
  5. package/lib/cjs/common/payment.js +29 -52
  6. package/lib/cjs/common/turbo.js +20 -47
  7. package/lib/cjs/common/upload.js +21 -34
  8. package/lib/cjs/node/factory.js +8 -2
  9. package/lib/cjs/node/index.js +1 -1
  10. package/lib/cjs/node/signer.js +9 -20
  11. package/lib/cjs/package.json +1 -0
  12. package/lib/cjs/utils/axiosClient.js +18 -9
  13. package/lib/cjs/utils/readableStream.js +11 -22
  14. package/lib/cjs/web/factory.js +8 -2
  15. package/lib/cjs/web/index.js +1 -1
  16. package/lib/cjs/web/signer.js +19 -31
  17. package/lib/esm/common/factory.js +6 -2
  18. package/lib/esm/common/http.js +16 -29
  19. package/lib/esm/common/payment.js +29 -52
  20. package/lib/esm/common/turbo.js +20 -47
  21. package/lib/esm/common/upload.js +21 -34
  22. package/lib/esm/node/factory.js +8 -2
  23. package/lib/esm/node/index.js +1 -1
  24. package/lib/esm/node/signer.js +9 -20
  25. package/lib/esm/utils/axiosClient.js +18 -9
  26. package/lib/esm/utils/readableStream.js +11 -22
  27. package/lib/esm/web/factory.js +8 -2
  28. package/lib/esm/web/index.js +1 -1
  29. package/lib/esm/web/signer.js +19 -31
  30. package/lib/{cjs → types}/common/factory.d.ts +2 -1
  31. package/lib/types/common/factory.d.ts.map +1 -0
  32. package/lib/{cjs → types}/common/http.d.ts +4 -3
  33. package/lib/types/common/http.d.ts.map +1 -0
  34. package/lib/{esm → types}/common/index.d.ts +1 -0
  35. package/lib/types/common/index.d.ts.map +1 -0
  36. package/lib/{esm/types/arweave.d.ts → types/common/jwk.d.ts} +1 -0
  37. package/lib/types/common/jwk.d.ts.map +1 -0
  38. package/lib/{esm → types}/common/payment.d.ts +2 -2
  39. package/lib/types/common/payment.d.ts.map +1 -0
  40. package/lib/{cjs → types}/common/turbo.d.ts +6 -5
  41. package/lib/types/common/turbo.d.ts.map +1 -0
  42. package/lib/{esm → types}/common/upload.d.ts +2 -2
  43. package/lib/types/common/upload.d.ts.map +1 -0
  44. package/lib/{esm → types}/node/factory.d.ts +2 -1
  45. package/lib/types/node/factory.d.ts.map +1 -0
  46. package/lib/{esm → types}/node/index.d.ts +2 -1
  47. package/lib/types/node/index.d.ts.map +1 -0
  48. package/lib/{cjs → types}/node/signer.d.ts +3 -2
  49. package/lib/types/node/signer.d.ts.map +1 -0
  50. package/lib/{cjs/types/turbo.d.ts → types/types.d.ts} +4 -3
  51. package/lib/types/types.d.ts.map +1 -0
  52. package/lib/{esm → types}/utils/axiosClient.d.ts +3 -2
  53. package/lib/types/utils/axiosClient.d.ts.map +1 -0
  54. package/lib/{cjs → types}/utils/base64.d.ts +3 -2
  55. package/lib/types/utils/base64.d.ts.map +1 -0
  56. package/lib/{esm → types}/utils/errors.d.ts +1 -0
  57. package/lib/types/utils/errors.d.ts.map +1 -0
  58. package/lib/{cjs → types}/utils/readableStream.d.ts +1 -0
  59. package/lib/types/utils/readableStream.d.ts.map +1 -0
  60. package/lib/{cjs → types}/web/factory.d.ts +2 -1
  61. package/lib/types/web/factory.d.ts.map +1 -0
  62. package/lib/{cjs → types}/web/index.d.ts +2 -1
  63. package/lib/types/web/index.d.ts.map +1 -0
  64. package/lib/{cjs → types}/web/signer.d.ts +3 -2
  65. package/lib/types/web/signer.d.ts.map +1 -0
  66. package/package.json +15 -15
  67. package/lib/cjs/common/index.d.ts +0 -19
  68. package/lib/cjs/common/payment.d.ts +0 -41
  69. package/lib/cjs/common/upload.d.ts +0 -29
  70. package/lib/cjs/node/factory.d.ts +0 -22
  71. package/lib/cjs/node/index.d.ts +0 -20
  72. package/lib/cjs/types/arweave.d.ts +0 -29
  73. package/lib/cjs/types/index.d.ts +0 -18
  74. package/lib/cjs/types/index.js +0 -34
  75. package/lib/cjs/utils/axiosClient.d.ts +0 -23
  76. package/lib/cjs/utils/errors.d.ts +0 -22
  77. package/lib/esm/common/factory.d.ts +0 -21
  78. package/lib/esm/common/http.d.ts +0 -44
  79. package/lib/esm/common/turbo.d.ts +0 -73
  80. package/lib/esm/node/signer.d.ts +0 -36
  81. package/lib/esm/types/index.d.ts +0 -18
  82. package/lib/esm/types/index.js +0 -18
  83. package/lib/esm/types/turbo.d.ts +0 -149
  84. package/lib/esm/utils/base64.d.ts +0 -9
  85. package/lib/esm/utils/readableStream.d.ts +0 -22
  86. package/lib/esm/web/factory.d.ts +0 -22
  87. package/lib/esm/web/index.d.ts +0 -20
  88. package/lib/esm/web/signer.d.ts +0 -37
  89. /package/lib/cjs/{types/arweave.js → common/jwk.js} +0 -0
  90. /package/lib/cjs/{types/turbo.js → types.js} +0 -0
  91. /package/lib/esm/{types/arweave.js → common/jwk.js} +0 -0
  92. /package/lib/esm/{types/turbo.js → types.js} +0 -0
package/README.md CHANGED
@@ -1,12 +1,11 @@
1
1
  # @ardriveapp/turbo-sdk 🚀
2
2
 
3
- Welcome to the `@ardrive/turbo-sdk`! This SDK provides functionalities for interacting with the Turbo Upload and Payment Services. It is available in both NodeJS and Web environments.
3
+ Welcome to the `@ardrive/turbo-sdk`! This SDK provides functionality for interacting with the Turbo Upload and Payment Services and is available for both NodeJS and Web environments.
4
4
 
5
5
  ## Table of Contents
6
6
 
7
7
  - [Installation](#installation)
8
- - [Usage](#usage):
9
-
8
+ - [Usage](#usage)
10
9
  - [NodeJS Environments](#nodejs)
11
10
  - [CommonJS](#commonjs)
12
11
  - [ESM](#esm)
@@ -15,7 +14,6 @@ Welcome to the `@ardrive/turbo-sdk`! This SDK provides functionalities for inter
15
14
  - [Browser](#browser)
16
15
  - [Typescript](#typescript)
17
16
  - [Examples](./examples)
18
-
19
17
  - [Contributions](#contributions)
20
18
 
21
19
  ## Installation
@@ -32,14 +30,14 @@ yarn add @ardrive/turbo-sdk
32
30
 
33
31
  ## Usage
34
32
 
35
- The SDK is available in both CommonJS and ESM formats and is compatible with bundlers such as Webpack, Rollup, and ESbuild.
33
+ The SDK is provided in both CommonJS and ESM formats, and it's compatible with bundlers such as Webpack, Rollup, and ESbuild. Utilize the appropriate named exports provided by this SDK's [package.json] based on your project's configuration. Refer to the [examples] directory to see how to use the SDK in various environments.
36
34
 
37
35
  ### Web
38
36
 
39
37
  #### Bundlers (Webpack, Rollup, ESbuild, etc.)
40
38
 
41
39
  ```javascript
42
- import { TurboFactory } from '@ardrive/turbo-sdk/web';
40
+ import { TurboFactory } from '@ardrive/turbo-sdk';
43
41
 
44
42
  const turbo = TurboFactory.unauthenticated({});
45
43
  const rates = await turbo.getFiatRates();
@@ -59,14 +57,58 @@ const rates = await turbo.getFiatRates();
59
57
 
60
58
  #### CommonJS
61
59
 
60
+ Project's `package.json`:
61
+
62
+ ```json
63
+ {
64
+ "type": "commonjs" // or absent
65
+ }
66
+ ```
67
+
68
+ tsconfig's `tsconfig.json`:
69
+
70
+ ```json
71
+ {
72
+ "compilerOptions": {
73
+ "module": "CommonJS",
74
+ "moduleResolution": "Node",
75
+ "skipLibCheck": true
76
+ }
77
+ }
78
+ ```
79
+
80
+ Usage:
81
+
62
82
  ```javascript
63
- const { TurboFactory } = require('@ardrive/turbo-sdk/node');
83
+ const { TurboFactory } = require('@ardrive/turbo-sdk');
64
84
 
65
85
  const turbo = TurboFactory.unauthenticated({});
66
86
  const rates = await turbo.getFiatRates();
67
87
  ```
68
88
 
69
- ### ESM
89
+ #### ESM
90
+
91
+ Project's `package.json`:
92
+
93
+ ```json
94
+ {
95
+ "type": "module"
96
+ }
97
+ ```
98
+
99
+ tsconfig's `tsconfig.json`:
100
+
101
+ ```json
102
+ {
103
+ "compilerOptions": {
104
+ "module": "NodeNext",
105
+ "moduleResolution": "NodeNext",
106
+ "skipLibCheck": true
107
+ }
108
+ }
109
+ ```
110
+
111
+ Usage:
70
112
 
71
113
  ```javascript
72
114
  import { TurboFactory } from '@ardrive/turbo-sdk/node';
@@ -77,7 +119,7 @@ const rates = await turbo.getFiatRates();
77
119
 
78
120
  ### Typescript
79
121
 
80
- The SDK provides TypeScript typings. When you import the SDK in a TypeScript project:
122
+ The SDK provides TypeScript types. When you import the SDK in a TypeScript project:
81
123
 
82
124
  ```typescript
83
125
  import Ardrive from '@ardrive/turbo-sdk/web';
@@ -85,30 +127,95 @@ import Ardrive from '@ardrive/turbo-sdk/web';
85
127
  // or '@ardrive/turbo-sdk/node' for Node.js projects
86
128
  ```
87
129
 
88
- The provided typings (`./lib/types/index.d.ts`) will be automatically recognized, offering type checking and autocompletion benefits.
130
+ Types are exported from `./lib/types/index.d.ts` and should be automatically recognized, offering benefits such as type-checking and autocompletion.
89
131
 
90
- ## APIs (WIP)
132
+ ## APIs
91
133
 
92
134
  ### TurboFactory
93
135
 
94
- - `public()`
95
- - `private()`
136
+ - `unauthenticated()` - Creates an instance of a client that accesses Turbo's unauthenticated services.
137
+
138
+ ```typescript
139
+ const turbo = TurboFactory.unauthenticated({});
140
+ ```
141
+
142
+ - `authenticated()` - Creates an instance of a client that accesses Turbo's authenticated and unauthenticated services.
143
+
144
+ ```typescript
145
+ const jwk = await arweave.crypto.generateJWK();
146
+ const turbo = TurboFactory.authenticated({ privateKey: jwk });
147
+ ```
96
148
 
97
149
  ### TurboUnauthenticatedClient
98
150
 
99
- - `getFiatRates()`
100
- - `getFiatToAR()`
101
- - `getSupportedCountries()`
102
- - `getSupportedCurrencies()`
103
- - `getWincForFiat()`
104
- - `getUploadCosts()`
105
- - `uploadSignedDataItem()`
151
+ - `getSupportedCurrencies()` - Returns the list of currencies supported by the Turbo Payment Service for topping up a user balance of AR Credits (measured in Winston Credits, or winc).
152
+
153
+ ```typescript
154
+ const currencies = await turbo.getSupportedCurrencies();
155
+ ```
156
+
157
+ - `getSupportedCountries()` - Returns the list of countries supported by the Turbo Payment Service's top up workflow.
158
+
159
+ ```typescript
160
+ const countries = await turbo.getSupportedCountries();
161
+ ```
162
+
163
+ - `getFiatToAR()` - Returns the current raw fiat to AR conversion rate for a specific currency as reported by third-party pricing oracles.
164
+
165
+ ```typescript
166
+ const fiatToAR = await turbo.getFiatToAR({ currency: 'USD' });
167
+ ```
168
+
169
+ - `getFiatRates()` - Returns the current fiat rates for 1 GiB of data for supported currencies, including all top-up adjustments and fees.
170
+
171
+ ```typescript
172
+ const rates = await turbo.getFiatRates();
173
+ ```
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.
176
+
177
+ ```typescript
178
+ const winc = await turbo.getWincForFiat({ amount: 100, currency: 'USD' });
179
+ ```
180
+
181
+ - `getUploadCosts({ bytes })` - Returns the estimated cost in Winston Credits for the provided file sizes, including all upload adjustments and fees.
182
+
183
+ ```typescript
184
+ const costs = await turbo.getUploadCosts({ bytes: [1000, 2000] });
185
+ ```
186
+
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.
188
+
189
+ ```typescript
190
+ const filePath = path.join(__dirname, './my-signed-data-item');
191
+ const uploadResponse = await turbo.uploadSignedDataItem({
192
+ dataItemStreamFactory: () => fs.createReadStream(filePath),
193
+ signal: AbortSignal.timeout(10_000), // cancel the upload after 10 seconds
194
+ });
195
+ ```
106
196
 
107
197
  ### TurboAuthenticatedClient
108
198
 
109
- - `getBalance()`
110
- - `uploadFile()`
199
+ - `getBalance()` - Issues a signed request to get the credit balance of a wallet measured in AR (measured in Winston Credits, or winc).
200
+
201
+ ```typescript
202
+ const balance = await turbo.getBalance();
203
+ ```
204
+
205
+ - `uploadFile({ fileStreamFactory })` - Signs and uploads a raw file. The provided fileStreamFactory should produce a NEW file data stream each time is it invoked.
206
+
207
+ ```typescript
208
+ const filePath = path.join(__dirname, './my-unsigned-file.txt');
209
+ const uploadResult = await turboAuthClient.uploadFile({
210
+ fileStreamFactory: () => fs.createReadStream(filePath),
211
+ });
212
+ ```
111
213
 
112
214
  ## Contributions
113
215
 
114
- If you encounter any issues or have feature requests, please file an issue on our GitHub repository. Contributions, pull requests, and feedback are welcome and encouraged.
216
+ If you encounter any issues or have feature requests, please file an issue on our GitHub repository. Contributions, pull requests, and feedback are both welcome and encouraged.
217
+
218
+ [package.json]: ./package.json
219
+ [examples]: ./examples
220
+ [TurboUnauthenticatedClient]: #turboUnauthenticatedClient
221
+ [TurboAuthenticatedClient]: #turboAuthenticatedClient