@ardrive/turbo-sdk 1.0.0-alpha.9 → 1.0.0-beta.2
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 +169 -28
- package/bundles/web.bundle.min.js +55776 -0
- package/lib/cjs/common/currency.js +42 -0
- package/lib/cjs/common/factory.js +6 -2
- package/lib/cjs/common/http.js +16 -29
- package/lib/cjs/common/index.js +1 -0
- package/lib/cjs/common/payment.js +56 -47
- package/lib/cjs/common/turbo.js +24 -40
- package/lib/cjs/common/upload.js +27 -34
- package/lib/cjs/node/factory.js +8 -2
- package/lib/cjs/node/index.js +1 -1
- package/lib/cjs/node/signer.js +42 -22
- package/lib/cjs/package.json +1 -0
- package/lib/cjs/utils/axiosClient.js +18 -9
- package/lib/cjs/utils/readableStream.js +13 -22
- package/lib/cjs/web/factory.js +8 -2
- package/lib/cjs/web/index.js +1 -1
- package/lib/cjs/web/signer.js +24 -31
- package/lib/esm/common/currency.js +27 -0
- package/lib/esm/common/factory.js +6 -2
- package/lib/esm/common/http.js +16 -29
- package/lib/esm/common/index.js +1 -0
- package/lib/esm/common/payment.js +56 -47
- package/lib/esm/common/turbo.js +24 -40
- package/lib/esm/common/upload.js +27 -34
- package/lib/esm/node/factory.js +8 -2
- package/lib/esm/node/index.js +1 -1
- package/lib/esm/node/signer.js +42 -22
- package/lib/esm/utils/axiosClient.js +18 -9
- package/lib/esm/utils/readableStream.js +13 -22
- package/lib/esm/web/factory.js +8 -2
- package/lib/esm/web/index.js +1 -1
- package/lib/esm/web/signer.js +24 -31
- package/lib/types/common/currency.d.ts +43 -0
- package/lib/types/common/currency.d.ts.map +1 -0
- package/lib/{cjs → types}/common/factory.d.ts +2 -1
- package/lib/types/common/factory.d.ts.map +1 -0
- package/lib/{cjs → types}/common/http.d.ts +4 -3
- package/lib/types/common/http.d.ts.map +1 -0
- package/lib/{esm → types}/common/index.d.ts +2 -0
- package/lib/types/common/index.d.ts.map +1 -0
- package/lib/{esm/types/arweave.d.ts → types/common/jwk.d.ts} +1 -0
- package/lib/types/common/jwk.d.ts.map +1 -0
- package/lib/{esm → types}/common/payment.d.ts +14 -6
- package/lib/types/common/payment.d.ts.map +1 -0
- package/lib/{cjs → types}/common/turbo.d.ts +13 -11
- package/lib/types/common/turbo.d.ts.map +1 -0
- package/lib/{esm → types}/common/upload.d.ts +4 -4
- package/lib/types/common/upload.d.ts.map +1 -0
- package/lib/{esm → types}/node/factory.d.ts +2 -1
- package/lib/types/node/factory.d.ts.map +1 -0
- package/lib/{esm → types}/node/index.d.ts +2 -1
- package/lib/types/node/index.d.ts.map +1 -0
- package/lib/{cjs → types}/node/signer.d.ts +10 -4
- package/lib/types/node/signer.d.ts.map +1 -0
- package/lib/{cjs/types/turbo.d.ts → types/types.d.ts} +46 -11
- package/lib/types/types.d.ts.map +1 -0
- package/lib/{esm → types}/utils/axiosClient.d.ts +3 -2
- package/lib/types/utils/axiosClient.d.ts.map +1 -0
- package/lib/{cjs → types}/utils/base64.d.ts +3 -2
- package/lib/types/utils/base64.d.ts.map +1 -0
- package/lib/{esm → types}/utils/errors.d.ts +1 -0
- package/lib/types/utils/errors.d.ts.map +1 -0
- package/lib/{cjs → types}/utils/readableStream.d.ts +3 -1
- package/lib/types/utils/readableStream.d.ts.map +1 -0
- package/lib/{cjs → types}/web/factory.d.ts +2 -1
- package/lib/types/web/factory.d.ts.map +1 -0
- package/lib/{cjs → types}/web/index.d.ts +2 -1
- package/lib/types/web/index.d.ts.map +1 -0
- package/lib/{cjs → types}/web/signer.d.ts +9 -4
- package/lib/types/web/signer.d.ts.map +1 -0
- package/package.json +13 -15
- package/lib/cjs/common/index.d.ts +0 -19
- package/lib/cjs/common/payment.d.ts +0 -41
- package/lib/cjs/common/upload.d.ts +0 -29
- package/lib/cjs/node/factory.d.ts +0 -22
- package/lib/cjs/node/index.d.ts +0 -20
- package/lib/cjs/types/arweave.d.ts +0 -29
- package/lib/cjs/types/index.d.ts +0 -18
- package/lib/cjs/types/index.js +0 -34
- package/lib/cjs/utils/axiosClient.d.ts +0 -23
- package/lib/cjs/utils/errors.d.ts +0 -22
- package/lib/esm/common/factory.d.ts +0 -21
- package/lib/esm/common/http.d.ts +0 -44
- package/lib/esm/common/turbo.d.ts +0 -73
- package/lib/esm/node/signer.d.ts +0 -36
- package/lib/esm/types/index.d.ts +0 -18
- package/lib/esm/types/index.js +0 -18
- package/lib/esm/types/turbo.d.ts +0 -149
- package/lib/esm/utils/base64.d.ts +0 -9
- package/lib/esm/utils/readableStream.d.ts +0 -22
- package/lib/esm/web/factory.d.ts +0 -22
- package/lib/esm/web/index.d.ts +0 -20
- package/lib/esm/web/signer.d.ts +0 -37
- /package/lib/cjs/{types/arweave.js → common/jwk.js} +0 -0
- /package/lib/cjs/{types/turbo.js → types.js} +0 -0
- /package/lib/esm/{types/arweave.js → common/jwk.js} +0 -0
- /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
|
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,16 +30,16 @@ yarn add @ardrive/turbo-sdk
|
|
32
30
|
|
33
31
|
## Usage
|
34
32
|
|
35
|
-
The SDK is
|
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
|
40
|
+
import { TurboFactory } from '@ardrive/turbo-sdk';
|
43
41
|
|
44
|
-
const turbo = TurboFactory.unauthenticated(
|
42
|
+
const turbo = TurboFactory.unauthenticated();
|
45
43
|
const rates = await turbo.getFiatRates();
|
46
44
|
```
|
47
45
|
|
@@ -50,7 +48,7 @@ const rates = await turbo.getFiatRates();
|
|
50
48
|
```html
|
51
49
|
<script src="https://cdn.jsdelivr.net/npm/@ardrive/turbo-sdk"></script>
|
52
50
|
<script>
|
53
|
-
const turbo = TurboFactory.unauthenticated(
|
51
|
+
const turbo = TurboFactory.unauthenticated();
|
54
52
|
const rates = await turbo.getFiatRates();
|
55
53
|
</script>
|
56
54
|
```
|
@@ -59,56 +57,199 @@ 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
|
+
Project'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
|
83
|
+
const { TurboFactory } = require('@ardrive/turbo-sdk');
|
64
84
|
|
65
|
-
const turbo = TurboFactory.unauthenticated(
|
85
|
+
const turbo = TurboFactory.unauthenticated();
|
66
86
|
const rates = await turbo.getFiatRates();
|
67
87
|
```
|
68
88
|
|
69
|
-
|
89
|
+
#### ESM
|
90
|
+
|
91
|
+
Project's `package.json`:
|
92
|
+
|
93
|
+
```json
|
94
|
+
{
|
95
|
+
"type": "module"
|
96
|
+
}
|
97
|
+
```
|
98
|
+
|
99
|
+
Project'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';
|
73
115
|
|
74
|
-
const turbo = TurboFactory.unauthenticated(
|
116
|
+
const turbo = TurboFactory.unauthenticated();
|
75
117
|
const rates = await turbo.getFiatRates();
|
76
118
|
```
|
77
119
|
|
78
120
|
### Typescript
|
79
121
|
|
80
|
-
The SDK provides TypeScript
|
122
|
+
The SDK provides TypeScript types. When you import the SDK in a TypeScript project:
|
81
123
|
|
82
124
|
```typescript
|
83
|
-
import
|
125
|
+
import { TurboFactory } from '@ardrive/turbo-sdk/web';
|
84
126
|
|
85
127
|
// or '@ardrive/turbo-sdk/node' for Node.js projects
|
86
128
|
```
|
87
129
|
|
88
|
-
|
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
|
132
|
+
## APIs
|
91
133
|
|
92
134
|
### TurboFactory
|
93
135
|
|
94
|
-
- `
|
95
|
-
|
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
|
-
- `
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
- `
|
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, promoCodes })` - Returns the current amount of Winston Credits including all adjustments for the provided fiat currency, amount, and optional promo codes.
|
176
|
+
|
177
|
+
```typescript
|
178
|
+
const { winc, paymentAmount, quotedPaymentAmount, adjustments } =
|
179
|
+
await turbo.getWincForFiat({
|
180
|
+
amount: USD(100),
|
181
|
+
promoCodes: ['MY_PROMO_CODE'],
|
182
|
+
});
|
183
|
+
```
|
184
|
+
|
185
|
+
- `getUploadCosts({ bytes })` - Returns the estimated cost in Winston Credits for the provided file sizes, including all upload adjustments and fees.
|
186
|
+
|
187
|
+
```typescript
|
188
|
+
const [uploadCostForFile] = await turbo.getUploadCosts({ bytes: [1024] });
|
189
|
+
const { winc, adjustments } = uploadCostForFile;
|
190
|
+
```
|
191
|
+
|
192
|
+
- `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.
|
193
|
+
|
194
|
+
```typescript
|
195
|
+
const filePath = path.join(__dirname, './my-signed-data-item');
|
196
|
+
const dataItemSize = fs.statSync(filePath).size;
|
197
|
+
const uploadResponse = await turbo.uploadSignedDataItem({
|
198
|
+
dataItemStreamFactory: () => fs.createReadStream(filePath),
|
199
|
+
dataItemSizeFactory: () => dataItemSize,
|
200
|
+
signal: AbortSignal.timeout(10_000), // cancel the upload after 10 seconds
|
201
|
+
});
|
202
|
+
```
|
203
|
+
|
204
|
+
- `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.
|
205
|
+
|
206
|
+
```typescript
|
207
|
+
const { url, winc, paymentAmount, quotedPaymentAmount, adjustments } =
|
208
|
+
await turbo.createCheckoutSession({
|
209
|
+
amount: USD(10.0), // $10.00 USD
|
210
|
+
owner: publicArweaveAddress,
|
211
|
+
promoCodes: ['MY_PROMO_CODE'],
|
212
|
+
});
|
213
|
+
|
214
|
+
// Open checkout session in a browser
|
215
|
+
if (process.platform === 'darwin') {
|
216
|
+
// macOS
|
217
|
+
exec(`open ${url}`);
|
218
|
+
} else if (process.platform === 'win32') {
|
219
|
+
// Windows
|
220
|
+
exec(`start "" "${url}"`, { shell: true });
|
221
|
+
} else {
|
222
|
+
// Linux/Unix
|
223
|
+
open(url);
|
224
|
+
}
|
225
|
+
```
|
106
226
|
|
107
227
|
### TurboAuthenticatedClient
|
108
228
|
|
109
|
-
- `getBalance()`
|
110
|
-
|
229
|
+
- `getBalance()` - Issues a signed request to get the credit balance of a wallet measured in AR (measured in Winston Credits, or winc).
|
230
|
+
|
231
|
+
```typescript
|
232
|
+
const { winc: balance } = await turbo.getBalance();
|
233
|
+
```
|
234
|
+
|
235
|
+
- `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.
|
236
|
+
|
237
|
+
```typescript
|
238
|
+
const filePath = path.join(__dirname, './my-unsigned-file.txt');
|
239
|
+
const fileSize = fs.stateSync(filePath).size;
|
240
|
+
const uploadResult = await turboAuthClient.uploadFile({
|
241
|
+
fileStreamFactory: () => fs.createReadStream(filePath),
|
242
|
+
fileSizeFactory: () => fileSize,
|
243
|
+
// no timeout or AbortSignal provided
|
244
|
+
});
|
245
|
+
```
|
111
246
|
|
112
247
|
## Contributions
|
113
248
|
|
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.
|
249
|
+
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.
|
250
|
+
|
251
|
+
[package.json]: ./package.json
|
252
|
+
[examples]: ./examples
|
253
|
+
[TurboUnauthenticatedClient]: #turboUnauthenticatedClient
|
254
|
+
[TurboAuthenticatedClient]: #turboAuthenticatedClient
|
255
|
+
[AbortSignal]: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
|