@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.
- package/README.md +130 -23
- package/bundles/web.bundle.min.js +55668 -0
- package/lib/cjs/common/factory.js +6 -2
- package/lib/cjs/common/http.js +16 -29
- package/lib/cjs/common/payment.js +29 -52
- package/lib/cjs/common/turbo.js +20 -47
- package/lib/cjs/common/upload.js +21 -34
- package/lib/cjs/node/factory.js +8 -2
- package/lib/cjs/node/index.js +1 -1
- package/lib/cjs/node/signer.js +9 -20
- package/lib/cjs/package.json +1 -0
- package/lib/cjs/utils/axiosClient.js +18 -9
- package/lib/cjs/utils/readableStream.js +11 -22
- package/lib/cjs/web/factory.js +8 -2
- package/lib/cjs/web/index.js +1 -1
- package/lib/cjs/web/signer.js +19 -31
- package/lib/esm/common/factory.js +6 -2
- package/lib/esm/common/http.js +16 -29
- package/lib/esm/common/payment.js +29 -52
- package/lib/esm/common/turbo.js +20 -47
- package/lib/esm/common/upload.js +21 -34
- package/lib/esm/node/factory.js +8 -2
- package/lib/esm/node/index.js +1 -1
- package/lib/esm/node/signer.js +9 -20
- package/lib/esm/utils/axiosClient.js +18 -9
- package/lib/esm/utils/readableStream.js +11 -22
- package/lib/esm/web/factory.js +8 -2
- package/lib/esm/web/index.js +1 -1
- package/lib/esm/web/signer.js +19 -31
- 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 +1 -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 +2 -2
- package/lib/types/common/payment.d.ts.map +1 -0
- package/lib/{cjs → types}/common/turbo.d.ts +6 -5
- package/lib/types/common/turbo.d.ts.map +1 -0
- package/lib/{esm → types}/common/upload.d.ts +2 -2
- 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 +3 -2
- package/lib/types/node/signer.d.ts.map +1 -0
- package/lib/{cjs/types/turbo.d.ts → types/types.d.ts} +4 -3
- 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 +1 -0
- 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 +3 -2
- package/lib/types/web/signer.d.ts.map +1 -0
- package/package.json +15 -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,14 +30,14 @@ 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
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
|
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
|
-
|
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
|
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
|
-
|
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, 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
|
-
|
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
|