@ardrive/turbo-sdk 1.0.0-alpha.20 → 1.0.0-alpha.22
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 +134 -23
- package/bundles/web.bundle.min.js +37 -14
- 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 +24 -46
- package/lib/cjs/common/upload.js +27 -34
- package/lib/cjs/node/factory.js +8 -2
- package/lib/cjs/node/signer.js +42 -22
- package/lib/cjs/utils/axiosClient.js +4 -1
- package/lib/cjs/utils/readableStream.js +13 -22
- package/lib/cjs/web/factory.js +8 -2
- package/lib/cjs/web/signer.js +24 -33
- 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 +24 -46
- package/lib/esm/common/upload.js +27 -34
- package/lib/esm/node/factory.js +8 -2
- package/lib/esm/node/signer.js +42 -22
- package/lib/esm/utils/axiosClient.js +4 -1
- package/lib/esm/utils/readableStream.js +13 -22
- package/lib/esm/web/factory.js +8 -2
- package/lib/esm/web/signer.js +24 -33
- package/lib/types/common/payment.d.ts +0 -1
- package/lib/types/common/payment.d.ts.map +1 -1
- package/lib/types/common/turbo.d.ts +6 -6
- package/lib/types/common/turbo.d.ts.map +1 -1
- package/lib/types/common/upload.d.ts +2 -3
- package/lib/types/common/upload.d.ts.map +1 -1
- package/lib/types/node/signer.d.ts +8 -3
- package/lib/types/node/signer.d.ts.map +1 -1
- package/lib/types/types.d.ts +5 -2
- package/lib/types/types.d.ts.map +1 -1
- package/lib/types/utils/readableStream.d.ts +2 -1
- package/lib/types/utils/readableStream.d.ts.map +1 -1
- package/lib/types/web/signer.d.ts +7 -3
- package/lib/types/web/signer.d.ts.map +1 -1
- package/package.json +1 -1
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,99 @@ 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, 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.
|
188
|
+
|
189
|
+
```typescript
|
190
|
+
const filePath = path.join(__dirname, './my-signed-data-item');
|
191
|
+
const dataItemSize = fs.statSync(filePath).size;
|
192
|
+
const uploadResponse = await turbo.uploadSignedDataItem({
|
193
|
+
dataItemStreamFactory: () => fs.createReadStream(filePath),
|
194
|
+
dataItemSizeFactory: () => dataItemSize,
|
195
|
+
signal: AbortSignal.timeout(10_000), // cancel the upload after 10 seconds
|
196
|
+
});
|
197
|
+
```
|
106
198
|
|
107
199
|
### TurboAuthenticatedClient
|
108
200
|
|
109
|
-
- `getBalance()`
|
110
|
-
|
201
|
+
- `getBalance()` - Issues a signed request to get the credit balance of a wallet measured in AR (measured in Winston Credits, or winc).
|
202
|
+
|
203
|
+
```typescript
|
204
|
+
const balance = await turbo.getBalance();
|
205
|
+
```
|
206
|
+
|
207
|
+
- `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.
|
208
|
+
|
209
|
+
```typescript
|
210
|
+
const filePath = path.join(__dirname, './my-unsigned-file.txt');
|
211
|
+
const fileSize = fs.stateSync(filePath).size;
|
212
|
+
const uploadResult = await turboAuthClient.uploadFile({
|
213
|
+
fileStreamFactory: () => fs.createReadStream(filePath),
|
214
|
+
fileSizeFactory: () => fileSize,
|
215
|
+
});
|
216
|
+
```
|
111
217
|
|
112
218
|
## Contributions
|
113
219
|
|
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.
|
220
|
+
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.
|
221
|
+
|
222
|
+
[package.json]: ./package.json
|
223
|
+
[examples]: ./examples
|
224
|
+
[TurboUnauthenticatedClient]: #turboUnauthenticatedClient
|
225
|
+
[TurboAuthenticatedClient]: #turboAuthenticatedClient
|
@@ -47480,14 +47480,17 @@ var TurboUnauthenticatedUploadService = class {
|
|
47480
47480
|
}
|
47481
47481
|
async uploadSignedDataItem({
|
47482
47482
|
dataItemStreamFactory,
|
47483
|
+
dataItemSizeFactory,
|
47483
47484
|
signal
|
47484
47485
|
}) {
|
47486
|
+
const fileSize = dataItemSizeFactory();
|
47485
47487
|
return this.httpService.post({
|
47486
47488
|
endpoint: `/tx`,
|
47487
47489
|
signal,
|
47488
47490
|
data: dataItemStreamFactory(),
|
47489
47491
|
headers: {
|
47490
|
-
"content-type": "application/octet-stream"
|
47492
|
+
"content-type": "application/octet-stream",
|
47493
|
+
"content-length": `${fileSize}`
|
47491
47494
|
}
|
47492
47495
|
});
|
47493
47496
|
}
|
@@ -47503,17 +47506,22 @@ var TurboAuthenticatedUploadService = class extends TurboUnauthenticatedUploadSe
|
|
47503
47506
|
}
|
47504
47507
|
async uploadFile({
|
47505
47508
|
fileStreamFactory,
|
47509
|
+
fileSizeFactory,
|
47506
47510
|
signal
|
47507
47511
|
}) {
|
47508
|
-
const
|
47509
|
-
fileStreamFactory
|
47512
|
+
const { dataItemStreamFactory, dataItemSizeFactory } = await this.signer.signDataItem({
|
47513
|
+
fileStreamFactory,
|
47514
|
+
fileSizeFactory
|
47510
47515
|
});
|
47516
|
+
const signedDataItem = dataItemStreamFactory();
|
47517
|
+
const fileSize = dataItemSizeFactory();
|
47511
47518
|
return this.httpService.post({
|
47512
47519
|
endpoint: `/tx`,
|
47513
47520
|
signal,
|
47514
47521
|
data: signedDataItem,
|
47515
47522
|
headers: {
|
47516
|
-
"content-type": "application/octet-stream"
|
47523
|
+
"content-type": "application/octet-stream",
|
47524
|
+
"content-length": `${fileSize}`
|
47517
47525
|
}
|
47518
47526
|
});
|
47519
47527
|
}
|
@@ -47579,10 +47587,12 @@ var TurboUnauthenticatedClient = class {
|
|
47579
47587
|
*/
|
47580
47588
|
async uploadSignedDataItem({
|
47581
47589
|
dataItemStreamFactory,
|
47590
|
+
dataItemSizeFactory,
|
47582
47591
|
signal
|
47583
47592
|
}) {
|
47584
47593
|
return this.uploadService.uploadSignedDataItem({
|
47585
47594
|
dataItemStreamFactory,
|
47595
|
+
dataItemSizeFactory,
|
47586
47596
|
signal
|
47587
47597
|
});
|
47588
47598
|
}
|
@@ -47605,9 +47615,14 @@ var TurboAuthenticatedClient = class extends TurboUnauthenticatedClient {
|
|
47605
47615
|
*/
|
47606
47616
|
async uploadFile({
|
47607
47617
|
fileStreamFactory,
|
47618
|
+
fileSizeFactory,
|
47608
47619
|
signal
|
47609
47620
|
}) {
|
47610
|
-
return this.uploadService.uploadFile({
|
47621
|
+
return this.uploadService.uploadFile({
|
47622
|
+
fileStreamFactory,
|
47623
|
+
fileSizeFactory,
|
47624
|
+
signal
|
47625
|
+
});
|
47611
47626
|
}
|
47612
47627
|
};
|
47613
47628
|
|
@@ -55555,19 +55570,22 @@ function toB64Url(buffer) {
|
|
55555
55570
|
// src/utils/readableStream.ts
|
55556
55571
|
init_shim();
|
55557
55572
|
async function readableStreamToBuffer({
|
55558
|
-
stream
|
55573
|
+
stream,
|
55574
|
+
size
|
55559
55575
|
}) {
|
55560
55576
|
const reader = stream.getReader();
|
55561
|
-
const
|
55577
|
+
const buffer = import_buffer.Buffer.alloc(size);
|
55578
|
+
let offset = 0;
|
55562
55579
|
let done = false;
|
55563
55580
|
while (!done) {
|
55564
55581
|
const { done: streamDone, value } = await reader.read();
|
55565
55582
|
done = streamDone;
|
55566
55583
|
if (!done) {
|
55567
|
-
|
55584
|
+
buffer.set(value, offset);
|
55585
|
+
offset += value.byteLength;
|
55568
55586
|
}
|
55569
55587
|
}
|
55570
|
-
return
|
55588
|
+
return buffer;
|
55571
55589
|
}
|
55572
55590
|
|
55573
55591
|
// src/web/signer.ts
|
@@ -55578,15 +55596,20 @@ var TurboWebArweaveSigner = class {
|
|
55578
55596
|
this.signer = new ArweaveSigner(this.privateKey);
|
55579
55597
|
}
|
55580
55598
|
async signDataItem({
|
55581
|
-
fileStreamFactory
|
55599
|
+
fileStreamFactory,
|
55600
|
+
fileSizeFactory
|
55582
55601
|
}) {
|
55583
55602
|
const buffer = await readableStreamToBuffer({
|
55584
|
-
stream: fileStreamFactory()
|
55585
|
-
|
55603
|
+
stream: fileStreamFactory(),
|
55604
|
+
size: fileSizeFactory()
|
55586
55605
|
});
|
55587
|
-
const signedDataItem = createData(buffer, this.signer);
|
55606
|
+
const signedDataItem = createData(buffer, this.signer, {});
|
55588
55607
|
await signedDataItem.sign(this.signer);
|
55589
|
-
return
|
55608
|
+
return {
|
55609
|
+
// while this returns a Buffer - it needs to match our return type for uploading
|
55610
|
+
dataItemStreamFactory: () => signedDataItem.getRaw(),
|
55611
|
+
dataItemSizeFactory: () => signedDataItem.getRaw().length
|
55612
|
+
};
|
55590
55613
|
}
|
55591
55614
|
// NOTE: this might be better in a parent class or elsewhere - easy enough to leave in here now and does require specific environment version of crypto
|
55592
55615
|
async generateSignedRequestHeaders() {
|
@@ -6,8 +6,12 @@ const turbo_js_1 = require("./turbo.js");
|
|
6
6
|
const upload_js_1 = require("./upload.js");
|
7
7
|
class TurboBaseFactory {
|
8
8
|
static unauthenticated({ paymentServiceConfig = {}, uploadServiceConfig = {}, } = {}) {
|
9
|
-
const paymentService = new payment_js_1.TurboUnauthenticatedPaymentService(
|
10
|
-
|
9
|
+
const paymentService = new payment_js_1.TurboUnauthenticatedPaymentService({
|
10
|
+
...paymentServiceConfig,
|
11
|
+
});
|
12
|
+
const uploadService = new upload_js_1.TurboUnauthenticatedUploadService({
|
13
|
+
...uploadServiceConfig,
|
14
|
+
});
|
11
15
|
return new turbo_js_1.TurboUnauthenticatedClient({
|
12
16
|
uploadService,
|
13
17
|
paymentService,
|
package/lib/cjs/common/http.js
CHANGED
@@ -1,13 +1,4 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
-
});
|
10
|
-
};
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
3
|
exports.TurboHTTPService = void 0;
|
13
4
|
const axiosClient_js_1 = require("../utils/axiosClient.js");
|
@@ -21,29 +12,25 @@ class TurboHTTPService {
|
|
21
12
|
retryConfig,
|
22
13
|
});
|
23
14
|
}
|
24
|
-
get({ endpoint, signal, allowedStatuses = [200, 202], headers, }) {
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
signal,
|
29
|
-
});
|
30
|
-
if (!allowedStatuses.includes(status)) {
|
31
|
-
throw new errors_js_1.FailedRequestError(status, statusText);
|
32
|
-
}
|
33
|
-
return data;
|
15
|
+
async get({ endpoint, signal, allowedStatuses = [200, 202], headers, }) {
|
16
|
+
const { status, statusText, data } = await this.axios.get(endpoint, {
|
17
|
+
headers,
|
18
|
+
signal,
|
34
19
|
});
|
20
|
+
if (!allowedStatuses.includes(status)) {
|
21
|
+
throw new errors_js_1.FailedRequestError(status, statusText);
|
22
|
+
}
|
23
|
+
return data;
|
35
24
|
}
|
36
|
-
post({ endpoint, signal, allowedStatuses = [200, 202], headers, data, }) {
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
signal,
|
41
|
-
});
|
42
|
-
if (!allowedStatuses.includes(status)) {
|
43
|
-
throw new errors_js_1.FailedRequestError(status, statusText);
|
44
|
-
}
|
45
|
-
return response;
|
25
|
+
async post({ endpoint, signal, allowedStatuses = [200, 202], headers, data, }) {
|
26
|
+
const { status, statusText, data: response, } = await this.axios.post(endpoint, data, {
|
27
|
+
headers,
|
28
|
+
signal,
|
46
29
|
});
|
30
|
+
if (!allowedStatuses.includes(status)) {
|
31
|
+
throw new errors_js_1.FailedRequestError(status, statusText);
|
32
|
+
}
|
33
|
+
return response;
|
47
34
|
}
|
48
35
|
}
|
49
36
|
exports.TurboHTTPService = TurboHTTPService;
|
@@ -1,13 +1,4 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
-
});
|
10
|
-
};
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
3
|
exports.TurboAuthenticatedPaymentService = exports.TurboUnauthenticatedPaymentService = void 0;
|
13
4
|
const http_js_1 = require("./http.js");
|
@@ -18,48 +9,36 @@ class TurboUnauthenticatedPaymentService {
|
|
18
9
|
retryConfig,
|
19
10
|
});
|
20
11
|
}
|
21
|
-
getFiatRates() {
|
22
|
-
return
|
23
|
-
|
24
|
-
endpoint: '/rates',
|
25
|
-
});
|
12
|
+
async getFiatRates() {
|
13
|
+
return this.httpService.get({
|
14
|
+
endpoint: '/rates',
|
26
15
|
});
|
27
16
|
}
|
28
|
-
getFiatToAR({ currency, }) {
|
29
|
-
return
|
30
|
-
|
31
|
-
endpoint: `/rates/${currency}`,
|
32
|
-
});
|
17
|
+
async getFiatToAR({ currency, }) {
|
18
|
+
return this.httpService.get({
|
19
|
+
endpoint: `/rates/${currency}`,
|
33
20
|
});
|
34
21
|
}
|
35
|
-
getSupportedCountries() {
|
36
|
-
return
|
37
|
-
|
38
|
-
endpoint: '/countries',
|
39
|
-
});
|
22
|
+
async getSupportedCountries() {
|
23
|
+
return this.httpService.get({
|
24
|
+
endpoint: '/countries',
|
40
25
|
});
|
41
26
|
}
|
42
|
-
getSupportedCurrencies() {
|
43
|
-
return
|
44
|
-
|
45
|
-
endpoint: '/currencies',
|
46
|
-
});
|
27
|
+
async getSupportedCurrencies() {
|
28
|
+
return this.httpService.get({
|
29
|
+
endpoint: '/currencies',
|
47
30
|
});
|
48
31
|
}
|
49
|
-
getUploadCosts({ bytes, }) {
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
return wincCostsForBytes;
|
56
|
-
});
|
32
|
+
async getUploadCosts({ bytes, }) {
|
33
|
+
const fetchPricePromises = bytes.map((byteCount) => this.httpService.get({
|
34
|
+
endpoint: `/price/bytes/${byteCount}`,
|
35
|
+
}));
|
36
|
+
const wincCostsForBytes = await Promise.all(fetchPricePromises);
|
37
|
+
return wincCostsForBytes;
|
57
38
|
}
|
58
|
-
getWincForFiat({ amount, currency }) {
|
59
|
-
return
|
60
|
-
|
61
|
-
endpoint: `/price/${currency}/${amount}`,
|
62
|
-
});
|
39
|
+
async getWincForFiat({ amount, currency }) {
|
40
|
+
return this.httpService.get({
|
41
|
+
endpoint: `/price/${currency}/${amount}`,
|
63
42
|
});
|
64
43
|
}
|
65
44
|
}
|
@@ -70,17 +49,15 @@ class TurboAuthenticatedPaymentService extends TurboUnauthenticatedPaymentServic
|
|
70
49
|
super({ url, retryConfig });
|
71
50
|
this.signer = signer;
|
72
51
|
}
|
73
|
-
getBalance() {
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
allowedStatuses: [200, 404],
|
80
|
-
});
|
81
|
-
// 404's don't return a balance, so default to 0
|
82
|
-
return balance.winc ? balance : { winc: '0' };
|
52
|
+
async getBalance() {
|
53
|
+
const headers = await this.signer.generateSignedRequestHeaders();
|
54
|
+
const balance = await this.httpService.get({
|
55
|
+
endpoint: '/balance',
|
56
|
+
headers,
|
57
|
+
allowedStatuses: [200, 404],
|
83
58
|
});
|
59
|
+
// 404's don't return a balance, so default to 0
|
60
|
+
return balance.winc ? balance : { winc: '0' };
|
84
61
|
}
|
85
62
|
}
|
86
63
|
exports.TurboAuthenticatedPaymentService = TurboAuthenticatedPaymentService;
|
package/lib/cjs/common/turbo.js
CHANGED
@@ -1,13 +1,4 @@
|
|
1
1
|
"use strict";
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
-
});
|
10
|
-
};
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
3
|
exports.TurboAuthenticatedClient = exports.TurboUnauthenticatedClient = void 0;
|
13
4
|
const payment_js_1 = require("./payment.js");
|
@@ -20,10 +11,8 @@ class TurboUnauthenticatedClient {
|
|
20
11
|
/**
|
21
12
|
* Returns the supported fiat currency conversion rate for 1AR based on current market prices.
|
22
13
|
*/
|
23
|
-
getFiatToAR({ currency, }) {
|
24
|
-
return
|
25
|
-
return this.paymentService.getFiatToAR({ currency });
|
26
|
-
});
|
14
|
+
async getFiatToAR({ currency, }) {
|
15
|
+
return this.paymentService.getFiatToAR({ currency });
|
27
16
|
}
|
28
17
|
/**
|
29
18
|
* Returns the latest conversion rates to purchase 1GiB of data for all supported currencies, including all adjustments and fees.
|
@@ -31,52 +20,41 @@ class TurboUnauthenticatedClient {
|
|
31
20
|
* Note: this does not take into account varying adjustments and promotions for different sizes of data. If you want to calculate the total
|
32
21
|
* cost in 'winc' for a given number of bytes, use getUploadCosts.
|
33
22
|
*/
|
34
|
-
getFiatRates() {
|
35
|
-
return
|
36
|
-
return this.paymentService.getFiatRates();
|
37
|
-
});
|
23
|
+
async getFiatRates() {
|
24
|
+
return this.paymentService.getFiatRates();
|
38
25
|
}
|
39
26
|
/**
|
40
27
|
* Returns a comprehensive list of supported countries that can purchase credits through the Turbo Payment Service.
|
41
28
|
*/
|
42
|
-
getSupportedCountries() {
|
43
|
-
return
|
44
|
-
return this.paymentService.getSupportedCountries();
|
45
|
-
});
|
29
|
+
async getSupportedCountries() {
|
30
|
+
return this.paymentService.getSupportedCountries();
|
46
31
|
}
|
47
32
|
/**
|
48
33
|
* Returns a list of all supported fiat currencies.
|
49
34
|
*/
|
50
|
-
getSupportedCurrencies() {
|
51
|
-
return
|
52
|
-
return this.paymentService.getSupportedCurrencies();
|
53
|
-
});
|
35
|
+
async getSupportedCurrencies() {
|
36
|
+
return this.paymentService.getSupportedCurrencies();
|
54
37
|
}
|
55
38
|
/**
|
56
39
|
* Determines the price in 'winc' to upload one data item of a specific size in bytes, including all Turbo cost adjustments and fees.
|
57
40
|
*/
|
58
|
-
getUploadCosts({ bytes, }) {
|
59
|
-
return
|
60
|
-
return this.paymentService.getUploadCosts({ bytes });
|
61
|
-
});
|
41
|
+
async getUploadCosts({ bytes, }) {
|
42
|
+
return this.paymentService.getUploadCosts({ bytes });
|
62
43
|
}
|
63
44
|
/**
|
64
45
|
* Determines the amount of 'winc' that would be returned for a given currency and amount, including all Turbo cost adjustments and fees.
|
65
46
|
*/
|
66
|
-
getWincForFiat({ amount, currency, }) {
|
67
|
-
return
|
68
|
-
return this.paymentService.getWincForFiat({ amount, currency });
|
69
|
-
});
|
47
|
+
async getWincForFiat({ amount, currency, }) {
|
48
|
+
return this.paymentService.getWincForFiat({ amount, currency });
|
70
49
|
}
|
71
50
|
/**
|
72
51
|
* Uploads a signed data item to the Turbo Upload Service.
|
73
52
|
*/
|
74
|
-
uploadSignedDataItem({ dataItemStreamFactory, signal, }) {
|
75
|
-
return
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
});
|
53
|
+
async uploadSignedDataItem({ dataItemStreamFactory, dataItemSizeFactory, signal, }) {
|
54
|
+
return this.uploadService.uploadSignedDataItem({
|
55
|
+
dataItemStreamFactory,
|
56
|
+
dataItemSizeFactory,
|
57
|
+
signal,
|
80
58
|
});
|
81
59
|
}
|
82
60
|
}
|
@@ -88,17 +66,17 @@ class TurboAuthenticatedClient extends TurboUnauthenticatedClient {
|
|
88
66
|
/**
|
89
67
|
* Returns the current balance of the user's wallet in 'winc'.
|
90
68
|
*/
|
91
|
-
getBalance() {
|
92
|
-
return
|
93
|
-
return this.paymentService.getBalance();
|
94
|
-
});
|
69
|
+
async getBalance() {
|
70
|
+
return this.paymentService.getBalance();
|
95
71
|
}
|
96
72
|
/**
|
97
73
|
* Signs and uploads raw data to the Turbo Upload Service.
|
98
74
|
*/
|
99
|
-
uploadFile({ fileStreamFactory, signal, }) {
|
100
|
-
return
|
101
|
-
|
75
|
+
async uploadFile({ fileStreamFactory, fileSizeFactory, signal, }) {
|
76
|
+
return this.uploadService.uploadFile({
|
77
|
+
fileStreamFactory,
|
78
|
+
fileSizeFactory,
|
79
|
+
signal,
|
102
80
|
});
|
103
81
|
}
|
104
82
|
}
|