@ardrive/turbo-sdk 1.0.0-alpha.9 → 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 +13 -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
@@ -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(Object.assign({}, paymentServiceConfig));
10
- const uploadService = new upload_js_1.TurboUnauthenticatedUploadService(Object.assign({}, uploadServiceConfig));
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,
@@ -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
- return __awaiter(this, void 0, void 0, function* () {
26
- const { status, statusText, data } = yield this.axios.get(endpoint, {
27
- headers,
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
- return __awaiter(this, void 0, void 0, function* () {
38
- const { status, statusText, data: response, } = yield this.axios.post(endpoint, data, {
39
- headers,
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 __awaiter(this, void 0, void 0, function* () {
23
- return this.httpService.get({
24
- endpoint: '/rates',
25
- });
12
+ async getFiatRates() {
13
+ return this.httpService.get({
14
+ endpoint: '/rates',
26
15
  });
27
16
  }
28
- getFiatToAR({ currency, }) {
29
- return __awaiter(this, void 0, void 0, function* () {
30
- return this.httpService.get({
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 __awaiter(this, void 0, void 0, function* () {
37
- return this.httpService.get({
38
- endpoint: '/countries',
39
- });
22
+ async getSupportedCountries() {
23
+ return this.httpService.get({
24
+ endpoint: '/countries',
40
25
  });
41
26
  }
42
- getSupportedCurrencies() {
43
- return __awaiter(this, void 0, void 0, function* () {
44
- return this.httpService.get({
45
- endpoint: '/currencies',
46
- });
27
+ async getSupportedCurrencies() {
28
+ return this.httpService.get({
29
+ endpoint: '/currencies',
47
30
  });
48
31
  }
49
- getUploadCosts({ bytes, }) {
50
- return __awaiter(this, void 0, void 0, function* () {
51
- const fetchPricePromises = bytes.map((byteCount) => this.httpService.get({
52
- endpoint: `/price/bytes/${byteCount}`,
53
- }));
54
- const wincCostsForBytes = yield Promise.all(fetchPricePromises);
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 __awaiter(this, void 0, void 0, function* () {
60
- return this.httpService.get({
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
- return __awaiter(this, void 0, void 0, function* () {
75
- const headers = yield this.signer.generateSignedRequestHeaders();
76
- const balance = yield this.httpService.get({
77
- endpoint: '/balance',
78
- headers,
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;
@@ -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 __awaiter(this, void 0, void 0, function* () {
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,40 @@ 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 __awaiter(this, void 0, void 0, function* () {
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 __awaiter(this, void 0, void 0, function* () {
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 __awaiter(this, void 0, void 0, function* () {
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 __awaiter(this, void 0, void 0, function* () {
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 __awaiter(this, void 0, void 0, function* () {
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 __awaiter(this, void 0, void 0, function* () {
76
- return this.uploadService.uploadSignedDataItem({
77
- dataItemStreamFactory,
78
- signal,
79
- });
53
+ async uploadSignedDataItem({ dataItemStreamFactory, signal, }) {
54
+ return this.uploadService.uploadSignedDataItem({
55
+ dataItemStreamFactory,
56
+ signal,
80
57
  });
81
58
  }
82
59
  }
@@ -88,18 +65,14 @@ class TurboAuthenticatedClient extends TurboUnauthenticatedClient {
88
65
  /**
89
66
  * Returns the current balance of the user's wallet in 'winc'.
90
67
  */
91
- getBalance() {
92
- return __awaiter(this, void 0, void 0, function* () {
93
- return this.paymentService.getBalance();
94
- });
68
+ async getBalance() {
69
+ return this.paymentService.getBalance();
95
70
  }
96
71
  /**
97
72
  * Signs and uploads raw data to the Turbo Upload Service.
98
73
  */
99
- uploadFile({ fileStreamFactory, signal, }) {
100
- return __awaiter(this, void 0, void 0, function* () {
101
- return this.uploadService.uploadFile({ fileStreamFactory, signal });
102
- });
74
+ async uploadFile({ fileStreamFactory, signal, }) {
75
+ return this.uploadService.uploadFile({ fileStreamFactory, signal });
103
76
  }
104
77
  }
105
78
  exports.TurboAuthenticatedClient = TurboAuthenticatedClient;
@@ -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.TurboAuthenticatedUploadService = exports.TurboUnauthenticatedUploadService = void 0;
13
4
  const http_js_1 = require("./http.js");
@@ -18,17 +9,15 @@ class TurboUnauthenticatedUploadService {
18
9
  retryConfig,
19
10
  });
20
11
  }
21
- uploadSignedDataItem({ dataItemStreamFactory, signal, }) {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- // TODO: add p-limit constraint or replace with separate upload class
24
- return this.httpService.post({
25
- endpoint: `/tx`,
26
- signal,
27
- data: dataItemStreamFactory(),
28
- headers: {
29
- 'content-type': 'application/octet-stream',
30
- },
31
- });
12
+ async uploadSignedDataItem({ dataItemStreamFactory, signal, }) {
13
+ // TODO: add p-limit constraint or replace with separate upload class
14
+ return this.httpService.post({
15
+ endpoint: `/tx`,
16
+ signal,
17
+ data: dataItemStreamFactory(),
18
+ headers: {
19
+ 'content-type': 'application/octet-stream',
20
+ },
32
21
  });
33
22
  }
34
23
  }
@@ -39,20 +28,18 @@ class TurboAuthenticatedUploadService extends TurboUnauthenticatedUploadService
39
28
  super({ url, retryConfig });
40
29
  this.signer = signer;
41
30
  }
42
- uploadFile({ fileStreamFactory, signal, }) {
43
- return __awaiter(this, void 0, void 0, function* () {
44
- const signedDataItem = yield this.signer.signDataItem({
45
- fileStreamFactory,
46
- });
47
- // TODO: add p-limit constraint or replace with separate upload class
48
- return this.httpService.post({
49
- endpoint: `/tx`,
50
- signal,
51
- data: signedDataItem,
52
- headers: {
53
- 'content-type': 'application/octet-stream',
54
- },
55
- });
31
+ async uploadFile({ fileStreamFactory, signal, }) {
32
+ const signedDataItem = await this.signer.signDataItem({
33
+ fileStreamFactory,
34
+ });
35
+ // TODO: add p-limit constraint or replace with separate upload class
36
+ return this.httpService.post({
37
+ endpoint: `/tx`,
38
+ signal,
39
+ data: signedDataItem,
40
+ headers: {
41
+ 'content-type': 'application/octet-stream',
42
+ },
56
43
  });
57
44
  }
58
45
  }
@@ -23,8 +23,14 @@ const signer_js_1 = require("./signer.js");
23
23
  class TurboFactory extends factory_js_1.TurboBaseFactory {
24
24
  static authenticated({ privateKey, paymentServiceConfig = {}, uploadServiceConfig = {}, }) {
25
25
  const signer = new signer_js_1.TurboNodeArweaveSigner({ privateKey });
26
- const paymentService = new index_js_1.TurboAuthenticatedPaymentService(Object.assign(Object.assign({}, paymentServiceConfig), { signer }));
27
- const uploadService = new index_js_1.TurboAuthenticatedUploadService(Object.assign(Object.assign({}, uploadServiceConfig), { signer }));
26
+ const paymentService = new index_js_1.TurboAuthenticatedPaymentService({
27
+ ...paymentServiceConfig,
28
+ signer,
29
+ });
30
+ const uploadService = new index_js_1.TurboAuthenticatedUploadService({
31
+ ...uploadServiceConfig,
32
+ signer,
33
+ });
28
34
  return new index_js_1.TurboAuthenticatedClient({
29
35
  uploadService,
30
36
  paymentService,
@@ -32,5 +32,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
32
32
  */
33
33
  __exportStar(require("./factory.js"), exports);
34
34
  __exportStar(require("./signer.js"), exports);
35
+ __exportStar(require("../types.js"), exports);
35
36
  __exportStar(require("../common/index.js"), exports);
36
- __exportStar(require("../types/index.js"), exports);
@@ -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
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -45,17 +36,15 @@ class TurboNodeArweaveSigner {
45
36
  return (0, arbundles_1.streamSigner)(stream1, stream2, this.signer);
46
37
  }
47
38
  // 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
48
- generateSignedRequestHeaders() {
49
- return __awaiter(this, void 0, void 0, function* () {
50
- const nonce = (0, node_crypto_1.randomBytes)(16).toString('hex');
51
- const buffer = Buffer.from(nonce);
52
- const signature = yield index_js_1.default.crypto.sign(this.privateKey, buffer);
53
- return {
54
- 'x-public-key': this.privateKey.n,
55
- 'x-nonce': nonce,
56
- 'x-signature': (0, base64_js_1.toB64Url)(Buffer.from(signature)),
57
- };
58
- });
39
+ async generateSignedRequestHeaders() {
40
+ const nonce = (0, node_crypto_1.randomBytes)(16).toString('hex');
41
+ const buffer = Buffer.from(nonce);
42
+ const signature = await index_js_1.default.crypto.sign(this.privateKey, buffer);
43
+ return {
44
+ 'x-public-key': this.privateKey.n,
45
+ 'x-nonce': nonce,
46
+ 'x-signature': (0, base64_js_1.toB64Url)(Buffer.from(signature)),
47
+ };
59
48
  }
60
49
  }
61
50
  exports.TurboNodeArweaveSigner = TurboNodeArweaveSigner;
@@ -0,0 +1 @@
1
+ {"type": "commonjs"}
@@ -43,18 +43,27 @@ exports.createAxiosInstance = void 0;
43
43
  * You should have received a copy of the GNU Affero General Public License
44
44
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
45
45
  */
46
- const axios_1 = __importDefault(require("axios"));
47
- const rax = __importStar(require("retry-axios"));
46
+ const axios_1 = __importStar(require("axios"));
47
+ const axios_retry_1 = __importDefault(require("axios-retry"));
48
48
  const createAxiosInstance = ({ axiosConfig = {}, retryConfig = {
49
- backoffType: 'exponential',
50
- retry: 3,
51
- onRetryAttempt: (err) => {
52
- const cfg = rax.getConfig(err);
53
- console.debug(`Retry attempt #${cfg === null || cfg === void 0 ? void 0 : cfg.currentRetryAttempt}`);
49
+ retryDelay: axios_retry_1.default.exponentialDelay,
50
+ retries: 3,
51
+ retryCondition: (error) => {
52
+ return (!(error instanceof axios_1.CanceledError) &&
53
+ axios_retry_1.default.isNetworkOrIdempotentRequestError(error));
54
+ },
55
+ onRetry: (retryCount, error) => {
56
+ console.debug(`Request failed, ${error}. Retry attempt #${retryCount}...`);
54
57
  },
55
58
  }, }) => {
56
- const axiosInstance = axios_1.default.create(Object.assign(Object.assign({}, axiosConfig), { validateStatus: () => true }));
57
- axiosInstance.defaults.raxConfig = Object.assign({ instance: axiosInstance }, retryConfig);
59
+ const axiosInstance = axios_1.default.create({
60
+ ...axiosConfig,
61
+ validateStatus: () => true, // don't throw on non-200 status codes
62
+ });
63
+ // eslint-disable-next-line
64
+ if (retryConfig.retries && retryConfig.retries > 0) {
65
+ (0, axios_retry_1.default)(axiosInstance, retryConfig);
66
+ }
58
67
  return axiosInstance;
59
68
  };
60
69
  exports.createAxiosInstance = createAxiosInstance;
@@ -1,28 +1,17 @@
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.readableStreamToBuffer = void 0;
13
- function readableStreamToBuffer({ stream, }) {
14
- return __awaiter(this, void 0, void 0, function* () {
15
- const reader = stream.getReader();
16
- const chunks = [];
17
- let done = false;
18
- while (!done) {
19
- const { done: streamDone, value } = yield reader.read();
20
- done = streamDone;
21
- if (!done) {
22
- chunks.push(value);
23
- }
4
+ async function readableStreamToBuffer({ stream, }) {
5
+ const reader = stream.getReader();
6
+ const chunks = [];
7
+ let done = false;
8
+ while (!done) {
9
+ const { done: streamDone, value } = await reader.read();
10
+ done = streamDone;
11
+ if (!done) {
12
+ chunks.push(value);
24
13
  }
25
- return Buffer.concat(chunks);
26
- });
14
+ }
15
+ return Buffer.concat(chunks);
27
16
  }
28
17
  exports.readableStreamToBuffer = readableStreamToBuffer;
@@ -23,8 +23,14 @@ const signer_js_1 = require("./signer.js");
23
23
  class TurboFactory extends factory_js_1.TurboBaseFactory {
24
24
  static authenticated({ privateKey, paymentServiceConfig = {}, uploadServiceConfig = {}, }) {
25
25
  const signer = new signer_js_1.TurboWebArweaveSigner({ privateKey });
26
- const paymentService = new index_js_1.TurboAuthenticatedPaymentService(Object.assign(Object.assign({}, paymentServiceConfig), { signer }));
27
- const uploadService = new index_js_1.TurboAuthenticatedUploadService(Object.assign(Object.assign({}, uploadServiceConfig), { signer }));
26
+ const paymentService = new index_js_1.TurboAuthenticatedPaymentService({
27
+ ...paymentServiceConfig,
28
+ signer,
29
+ });
30
+ const uploadService = new index_js_1.TurboAuthenticatedUploadService({
31
+ ...uploadServiceConfig,
32
+ signer,
33
+ });
28
34
  return new index_js_1.TurboAuthenticatedClient({
29
35
  uploadService,
30
36
  paymentService,
@@ -33,4 +33,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
33
33
  __exportStar(require("./factory.js"), exports);
34
34
  __exportStar(require("./signer.js"), exports);
35
35
  __exportStar(require("../common/index.js"), exports);
36
- __exportStar(require("../types/index.js"), exports);
36
+ __exportStar(require("../types.js"), exports);
@@ -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
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -39,31 +30,28 @@ class TurboWebArweaveSigner {
39
30
  this.privateKey = privateKey;
40
31
  this.signer = new arbundles_1.ArweaveSigner(this.privateKey);
41
32
  }
42
- signDataItem({ fileStreamFactory, }) {
43
- return __awaiter(this, void 0, void 0, function* () {
44
- // TODO: converts the readable stream to a buffer bc incrementally signing ReadableStreams is not trivial
45
- const buffer = yield (0, readableStream_js_1.readableStreamToBuffer)({
46
- stream: fileStreamFactory(),
47
- // TODO: add payload size to get performance improvements
48
- });
49
- const signedDataItem = (0, arbundles_1.createData)(buffer, this.signer);
50
- yield signedDataItem.sign(this.signer);
51
- return signedDataItem.getRaw();
33
+ async signDataItem({ fileStreamFactory, }) {
34
+ // TODO: converts the readable stream to a buffer bc incrementally signing ReadableStreams is not trivial
35
+ const buffer = await (0, readableStream_js_1.readableStreamToBuffer)({
36
+ stream: fileStreamFactory(),
37
+ // TODO: add payload size to get performance improvements
52
38
  });
39
+ const signedDataItem = (0, arbundles_1.createData)(buffer, this.signer);
40
+ await signedDataItem.sign(this.signer);
41
+ return signedDataItem.getRaw();
53
42
  }
54
43
  // 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
55
- generateSignedRequestHeaders() {
56
- return __awaiter(this, void 0, void 0, function* () {
57
- const nonce = (0, node_crypto_1.randomBytes)(16).toString('hex');
58
- const buffer = Buffer.from(nonce);
59
- // a bit hacky - but easiest way to solve web signing issues while still building for cjs
60
- const signature = yield arweave_1.default.default.crypto.sign(this.privateKey, buffer, {});
61
- return {
62
- 'x-public-key': this.privateKey.n,
63
- 'x-nonce': nonce,
64
- 'x-signature': (0, base64_js_1.toB64Url)(Buffer.from(signature)),
65
- };
66
- });
44
+ async generateSignedRequestHeaders() {
45
+ // a bit hacky - but arweave exports cause issues in tests vs. browser
46
+ const arweave = arweave_1.default.default ?? arweave_1.default;
47
+ const nonce = (0, node_crypto_1.randomBytes)(16).toString('hex');
48
+ const buffer = Buffer.from(nonce);
49
+ const signature = await arweave.crypto.sign(this.privateKey, buffer, {});
50
+ return {
51
+ 'x-public-key': this.privateKey.n,
52
+ 'x-nonce': nonce,
53
+ 'x-signature': (0, base64_js_1.toB64Url)(Buffer.from(signature)),
54
+ };
67
55
  }
68
56
  }
69
57
  exports.TurboWebArweaveSigner = TurboWebArweaveSigner;
@@ -3,8 +3,12 @@ import { TurboUnauthenticatedClient } from './turbo.js';
3
3
  import { TurboUnauthenticatedUploadService } from './upload.js';
4
4
  export class TurboBaseFactory {
5
5
  static unauthenticated({ paymentServiceConfig = {}, uploadServiceConfig = {}, } = {}) {
6
- const paymentService = new TurboUnauthenticatedPaymentService(Object.assign({}, paymentServiceConfig));
7
- const uploadService = new TurboUnauthenticatedUploadService(Object.assign({}, uploadServiceConfig));
6
+ const paymentService = new TurboUnauthenticatedPaymentService({
7
+ ...paymentServiceConfig,
8
+ });
9
+ const uploadService = new TurboUnauthenticatedUploadService({
10
+ ...uploadServiceConfig,
11
+ });
8
12
  return new TurboUnauthenticatedClient({
9
13
  uploadService,
10
14
  paymentService,