@ardrive/turbo-sdk 1.9.0 → 1.10.0-alpha.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 (99) hide show
  1. package/README.md +103 -11
  2. package/bundles/web.bundle.min.js +25370 -12548
  3. package/lib/cjs/common/factory.js +20 -10
  4. package/lib/cjs/common/http.js +1 -1
  5. package/lib/cjs/common/index.js +1 -1
  6. package/lib/cjs/common/logger.js +1 -1
  7. package/lib/cjs/common/payment.js +1 -1
  8. package/lib/cjs/common/signer.js +1 -1
  9. package/lib/cjs/common/token/arweave.js +3 -3
  10. package/lib/cjs/common/token/ethereum.js +3 -3
  11. package/lib/cjs/common/token/solana.js +3 -3
  12. package/lib/cjs/common/turbo.js +3 -0
  13. package/lib/cjs/common/upload.js +106 -3
  14. package/lib/cjs/node/factory.js +1 -1
  15. package/lib/cjs/node/index.js +2 -1
  16. package/lib/cjs/node/signer.js +1 -1
  17. package/lib/cjs/node/upload.js +72 -0
  18. package/lib/cjs/types.js +6 -2
  19. package/lib/cjs/utils/axiosClient.js +1 -1
  20. package/lib/cjs/utils/base64.js +7 -7
  21. package/lib/cjs/utils/common.js +6 -3
  22. package/lib/cjs/utils/errors.js +1 -1
  23. package/lib/cjs/utils/readableStream.js +1 -2
  24. package/lib/cjs/version.js +2 -2
  25. package/lib/cjs/web/factory.js +3 -2
  26. package/lib/cjs/web/index.js +2 -1
  27. package/lib/cjs/web/signer.js +1 -1
  28. package/lib/cjs/web/upload.js +57 -0
  29. package/lib/esm/common/factory.js +19 -9
  30. package/lib/esm/common/http.js +1 -1
  31. package/lib/esm/common/index.js +1 -1
  32. package/lib/esm/common/logger.js +1 -1
  33. package/lib/esm/common/payment.js +1 -1
  34. package/lib/esm/common/signer.js +1 -1
  35. package/lib/esm/common/token/arweave.js +3 -3
  36. package/lib/esm/common/token/ethereum.js +3 -3
  37. package/lib/esm/common/token/solana.js +3 -3
  38. package/lib/esm/common/turbo.js +3 -0
  39. package/lib/esm/common/upload.js +104 -1
  40. package/lib/esm/node/factory.js +1 -1
  41. package/lib/esm/node/index.js +2 -1
  42. package/lib/esm/node/signer.js +1 -1
  43. package/lib/esm/node/upload.js +68 -0
  44. package/lib/esm/types.js +2 -0
  45. package/lib/esm/utils/axiosClient.js +1 -1
  46. package/lib/esm/utils/base64.js +1 -1
  47. package/lib/esm/utils/common.js +4 -1
  48. package/lib/esm/utils/errors.js +1 -1
  49. package/lib/esm/version.js +2 -2
  50. package/lib/esm/web/factory.js +4 -3
  51. package/lib/esm/web/index.js +2 -1
  52. package/lib/esm/web/signer.js +1 -1
  53. package/lib/esm/web/upload.js +53 -0
  54. package/lib/types/common/currency.d.ts +1 -1
  55. package/lib/types/common/factory.d.ts.map +1 -1
  56. package/lib/types/common/http.d.ts +1 -4
  57. package/lib/types/common/http.d.ts.map +1 -1
  58. package/lib/types/common/index.d.ts +1 -1
  59. package/lib/types/common/jwk.d.ts +1 -1
  60. package/lib/types/common/logger.d.ts +1 -1
  61. package/lib/types/common/signer.d.ts +0 -1
  62. package/lib/types/common/signer.d.ts.map +1 -1
  63. package/lib/types/common/token/arweave.d.ts +1 -1
  64. package/lib/types/common/token/arweave.d.ts.map +1 -1
  65. package/lib/types/common/token/ethereum.d.ts +1 -1
  66. package/lib/types/common/token/ethereum.d.ts.map +1 -1
  67. package/lib/types/common/token/index.d.ts +1 -1
  68. package/lib/types/common/token/solana.d.ts +1 -1
  69. package/lib/types/common/token/solana.d.ts.map +1 -1
  70. package/lib/types/common/turbo.d.ts +3 -2
  71. package/lib/types/common/turbo.d.ts.map +1 -1
  72. package/lib/types/common/upload.d.ts +19 -3
  73. package/lib/types/common/upload.d.ts.map +1 -1
  74. package/lib/types/node/factory.d.ts +1 -1
  75. package/lib/types/node/index.d.ts +2 -1
  76. package/lib/types/node/index.d.ts.map +1 -1
  77. package/lib/types/node/signer.d.ts +1 -2
  78. package/lib/types/node/signer.d.ts.map +1 -1
  79. package/lib/types/node/upload.d.ts +15 -0
  80. package/lib/types/node/upload.d.ts.map +1 -0
  81. package/lib/types/types.d.ts +41 -5
  82. package/lib/types/types.d.ts.map +1 -1
  83. package/lib/types/utils/axiosClient.d.ts +1 -1
  84. package/lib/types/utils/base64.d.ts +0 -1
  85. package/lib/types/utils/base64.d.ts.map +1 -1
  86. package/lib/types/utils/common.d.ts +2 -1
  87. package/lib/types/utils/common.d.ts.map +1 -1
  88. package/lib/types/utils/errors.d.ts +1 -1
  89. package/lib/types/utils/readableStream.d.ts +1 -3
  90. package/lib/types/utils/readableStream.d.ts.map +1 -1
  91. package/lib/types/version.d.ts +2 -2
  92. package/lib/types/web/factory.d.ts.map +1 -1
  93. package/lib/types/web/index.d.ts +2 -1
  94. package/lib/types/web/index.d.ts.map +1 -1
  95. package/lib/types/web/signer.d.ts +1 -2
  96. package/lib/types/web/signer.d.ts.map +1 -1
  97. package/lib/types/web/upload.d.ts +29 -0
  98. package/lib/types/web/upload.d.ts.map +1 -0
  99. package/package.json +11 -5
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TurboBaseFactory = void 0;
4
4
  /**
5
- * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
5
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
6
6
  *
7
7
  * This program is free software: you can redistribute it and/or modify
8
8
  * it under the terms of the GNU Affero General Public License as published by
@@ -19,13 +19,16 @@ exports.TurboBaseFactory = void 0;
19
19
  */
20
20
  const arbundles_1 = require("arbundles");
21
21
  const signer_js_1 = require("../node/signer.js");
22
+ const upload_js_1 = require("../node/upload.js");
22
23
  const types_js_1 = require("../types.js");
24
+ const common_js_1 = require("../utils/common.js");
23
25
  const signer_js_2 = require("../web/signer.js");
26
+ const upload_js_2 = require("../web/upload.js");
24
27
  const logger_js_1 = require("./logger.js");
25
28
  const payment_js_1 = require("./payment.js");
26
29
  const index_js_1 = require("./token/index.js");
27
30
  const turbo_js_1 = require("./turbo.js");
28
- const upload_js_1 = require("./upload.js");
31
+ const upload_js_3 = require("./upload.js");
29
32
  class TurboBaseFactory {
30
33
  static setLogLevel(level) {
31
34
  this.logger.setLogLevel(level);
@@ -38,7 +41,7 @@ class TurboBaseFactory {
38
41
  ...paymentServiceConfig,
39
42
  logger: this.logger,
40
43
  });
41
- const uploadService = new upload_js_1.TurboUnauthenticatedUploadService({
44
+ const uploadService = new upload_js_3.TurboUnauthenticatedUploadService({
42
45
  ...uploadServiceConfig,
43
46
  logger: this.logger,
44
47
  });
@@ -72,7 +75,7 @@ class TurboBaseFactory {
72
75
  else {
73
76
  throw new Error('A privateKey or signer must be provided.');
74
77
  }
75
- if (typeof window !== 'undefined') {
78
+ if ((0, common_js_1.isWeb)()) {
76
79
  return new signer_js_2.TurboWebArweaveSigner({
77
80
  signer,
78
81
  logger: this.logger,
@@ -118,12 +121,19 @@ class TurboBaseFactory {
118
121
  token,
119
122
  tokenTools,
120
123
  });
121
- const uploadService = new upload_js_1.TurboAuthenticatedUploadService({
122
- ...uploadServiceConfig,
123
- signer: turboSigner,
124
- logger: this.logger,
125
- token,
126
- });
124
+ const uploadService = (0, common_js_1.isWeb)()
125
+ ? new upload_js_2.TurboAuthenticatedWebUploadService({
126
+ ...uploadServiceConfig,
127
+ signer: turboSigner,
128
+ logger: this.logger,
129
+ token,
130
+ })
131
+ : new upload_js_1.TurboAuthenticatedNodeUploadService({
132
+ ...uploadServiceConfig,
133
+ signer: turboSigner,
134
+ logger: this.logger,
135
+ token,
136
+ });
127
137
  return new turbo_js_1.TurboAuthenticatedClient({
128
138
  uploadService,
129
139
  paymentService,
@@ -9,7 +9,7 @@ class TurboHTTPService {
9
9
  this.axios = (0, axiosClient_js_1.createAxiosInstance)({
10
10
  axiosConfig: {
11
11
  baseURL: url,
12
- maxRedirects: 0,
12
+ maxRedirects: 0, // prevents backpressure issues when uploading larger streams via https
13
13
  onUploadProgress: (progressEvent) => {
14
14
  this.logger.debug(`Uploading...`, {
15
15
  percent: Math.floor((progressEvent.progress ?? 0) * 100),
@@ -15,7 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  /**
18
- * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
18
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
19
19
  *
20
20
  * This program is free software: you can redistribute it and/or modify
21
21
  * it under the terms of the GNU Affero General Public License as published by
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TurboWinstonLogger = void 0;
4
4
  /**
5
- * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
5
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
6
6
  *
7
7
  * This program is free software: you can redistribute it and/or modify
8
8
  * it under the terms of the GNU Affero General Public License as published by
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TurboAuthenticatedPaymentService = exports.TurboUnauthenticatedPaymentService = exports.defaultPaymentServiceURL = exports.developmentPaymentServiceURL = void 0;
4
4
  /**
5
- * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
5
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
6
6
  *
7
7
  * This program is free software: you can redistribute it and/or modify
8
8
  * it under the terms of the GNU Affero General Public License as published by
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.TurboDataItemAbstractSigner = void 0;
7
7
  /**
8
- * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
8
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
9
9
  *
10
10
  * This program is free software: you can redistribute it and/or modify
11
11
  * it under the terms of the GNU Affero General Public License as published by
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ARToTokenAmount = exports.WinstonToTokenAmount = exports.ArweaveToken = void 0;
7
7
  /**
8
- * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
8
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
9
9
  *
10
10
  * This program is free software: you can redistribute it and/or modify
11
11
  * it under the terms of the GNU Affero General Public License as published by
@@ -30,8 +30,8 @@ class ArweaveToken {
30
30
  url: gatewayUrl,
31
31
  }), logger = new logger_js_1.TurboWinstonLogger(), mintU = true, pollingOptions = {
32
32
  maxAttempts: 10,
33
- pollingIntervalMs: 3000,
34
- initialBackoffMs: 7000,
33
+ pollingIntervalMs: 3_000,
34
+ initialBackoffMs: 7_000,
35
35
  }, } = {}) {
36
36
  this.arweave = arweave;
37
37
  this.logger = logger;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EthereumToken = exports.ETHToTokenAmount = exports.weiToTokenAmount = void 0;
4
4
  /**
5
- * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
5
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
6
6
  *
7
7
  * This program is free software: you can redistribute it and/or modify
8
8
  * it under the terms of the GNU Affero General Public License as published by
@@ -27,8 +27,8 @@ exports.ETHToTokenAmount = ETHToTokenAmount;
27
27
  class EthereumToken {
28
28
  constructor({ logger = new logger_js_1.TurboWinstonLogger(), gatewayUrl = 'https://cloudflare-eth.com/', pollingOptions = {
29
29
  maxAttempts: 10,
30
- pollingIntervalMs: 4000,
31
- initialBackoffMs: 10000,
30
+ pollingIntervalMs: 4_000,
31
+ initialBackoffMs: 10_000,
32
32
  }, } = {}) {
33
33
  this.logger = logger;
34
34
  this.gatewayUrl = gatewayUrl;
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.SolanaToken = exports.SOLToTokenAmount = exports.lamportToTokenAmount = void 0;
7
7
  /**
8
- * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
8
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
9
9
  *
10
10
  * This program is free software: you can redistribute it and/or modify
11
11
  * it under the terms of the GNU Affero General Public License as published by
@@ -32,8 +32,8 @@ exports.SOLToTokenAmount = SOLToTokenAmount;
32
32
  class SolanaToken {
33
33
  constructor({ logger = new logger_js_1.TurboWinstonLogger(), gatewayUrl = 'https://api.mainnet-beta.solana.com', pollingOptions = {
34
34
  maxAttempts: 10,
35
- pollingIntervalMs: 5000,
36
- initialBackoffMs: 7000,
35
+ pollingIntervalMs: 5_000,
36
+ initialBackoffMs: 7_000,
37
37
  }, } = {}) {
38
38
  this.logger = logger;
39
39
  this.gatewayUrl = gatewayUrl;
@@ -114,6 +114,9 @@ class TurboAuthenticatedClient extends TurboUnauthenticatedClient {
114
114
  dataItemOpts,
115
115
  });
116
116
  }
117
+ uploadFolder(p) {
118
+ return this.uploadService.uploadFolder(p);
119
+ }
117
120
  /**
118
121
  * Submits fund transaction to the token's blockchain then sends
119
122
  * the transaction ID to the Turbo Payment Service for processing.
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TurboAuthenticatedUploadService = exports.TurboUnauthenticatedUploadService = exports.defaultUploadServiceURL = exports.developmentUploadServiceURL = void 0;
3
+ exports.TurboAuthenticatedBaseUploadService = exports.TurboUnauthenticatedUploadService = exports.defaultUploadServiceURL = exports.developmentUploadServiceURL = void 0;
4
+ const plimit_lit_1 = require("plimit-lit");
4
5
  const http_js_1 = require("./http.js");
5
6
  const logger_js_1 = require("./logger.js");
6
7
  exports.developmentUploadServiceURL = 'https://upload.ardrive.dev';
@@ -32,7 +33,7 @@ class TurboUnauthenticatedUploadService {
32
33
  }
33
34
  exports.TurboUnauthenticatedUploadService = TurboUnauthenticatedUploadService;
34
35
  // NOTE: to avoid redundancy, we use inheritance here - but generally prefer composition over inheritance
35
- class TurboAuthenticatedUploadService extends TurboUnauthenticatedUploadService {
36
+ class TurboAuthenticatedBaseUploadService extends TurboUnauthenticatedUploadService {
36
37
  constructor({ url = exports.defaultUploadServiceURL, retryConfig, signer, logger, token, }) {
37
38
  super({ url, retryConfig, logger, token });
38
39
  this.signer = signer;
@@ -57,5 +58,107 @@ class TurboAuthenticatedUploadService extends TurboUnauthenticatedUploadService
57
58
  },
58
59
  });
59
60
  }
61
+ async generateManifest({ paths, indexFile, fallbackFile, }) {
62
+ const indexPath =
63
+ // Use the user provided index file if it exists,
64
+ indexFile !== undefined && paths[indexFile]?.id !== undefined
65
+ ? indexFile
66
+ : // Else use index.html if it exists,
67
+ paths['index.html']?.id !== undefined
68
+ ? 'index.html'
69
+ : // Else use the first file in the paths object.
70
+ Object.keys(paths)[0];
71
+ const fallbackId =
72
+ // Use the user provided fallback file if it exists,
73
+ fallbackFile !== undefined && paths[fallbackFile]?.id !== undefined
74
+ ? paths[fallbackFile].id
75
+ : // Else use 404.html if it exists, else use the index path.
76
+ paths['404.html']?.id ?? paths[indexPath].id;
77
+ const manifest = {
78
+ manifest: 'arweave/paths',
79
+ version: '0.2.0',
80
+ index: { path: indexPath },
81
+ paths,
82
+ fallback: { id: fallbackId },
83
+ };
84
+ return manifest;
85
+ }
86
+ getContentType(file, dataItemOpts) {
87
+ const userDefinedContentType = dataItemOpts?.tags?.find((tag) => tag.name === 'Content-Type')?.value;
88
+ if (userDefinedContentType !== undefined) {
89
+ return userDefinedContentType;
90
+ }
91
+ return this.contentTypeFromFile(file);
92
+ }
93
+ async uploadFolder(params) {
94
+ const { dataItemOpts, signal, manifestOptions = {}, maxConcurrentUploads = 5, throwOnFailure = true, } = params;
95
+ const { disableManifest, indexFile, fallbackFile } = manifestOptions;
96
+ const paths = {};
97
+ const response = {
98
+ fileResponses: [],
99
+ };
100
+ const errors = [];
101
+ const uploadFile = async (file) => {
102
+ const contentType = this.getContentType(file, dataItemOpts);
103
+ const dataItemOptsWithContentType = {
104
+ ...dataItemOpts,
105
+ tags: [
106
+ ...(dataItemOpts?.tags?.filter((tag) => tag.name !== 'Content-Type') ?? []),
107
+ { name: 'Content-Type', value: contentType },
108
+ ],
109
+ };
110
+ try {
111
+ const result = await this.uploadFile({
112
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
113
+ fileStreamFactory: () => this.getFileStreamForFile(file),
114
+ fileSizeFactory: () => this.getFileSize(file),
115
+ signal,
116
+ dataItemOpts: dataItemOptsWithContentType,
117
+ });
118
+ const relativePath = this.getRelativePath(file, params);
119
+ paths[relativePath] = { id: result.id };
120
+ response.fileResponses.push(result);
121
+ }
122
+ catch (error) {
123
+ if (throwOnFailure) {
124
+ throw error;
125
+ }
126
+ this.logger.error(`Error uploading file: ${file}`, error);
127
+ errors.push(error);
128
+ }
129
+ };
130
+ const files = await this.getFiles(params);
131
+ const limit = (0, plimit_lit_1.pLimit)(maxConcurrentUploads);
132
+ await Promise.all(files.map((file) => limit(() => uploadFile(file))));
133
+ if (errors.length > 0) {
134
+ response.errors = errors;
135
+ }
136
+ if (disableManifest) {
137
+ return response;
138
+ }
139
+ const manifest = await this.generateManifest({
140
+ paths,
141
+ indexFile,
142
+ fallbackFile,
143
+ });
144
+ const tagsWithManifestContentType = [
145
+ ...(dataItemOpts?.tags?.filter((tag) => tag.name !== 'Content-Type') ??
146
+ []),
147
+ { name: 'Content-Type', value: 'application/x.arweave-manifest+json' },
148
+ ];
149
+ const manifestBuffer = Buffer.from(JSON.stringify(manifest));
150
+ const manifestResponse = await this.uploadFile({
151
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
152
+ fileStreamFactory: () => this.createManifestStream(manifestBuffer),
153
+ fileSizeFactory: () => manifestBuffer.byteLength,
154
+ signal,
155
+ dataItemOpts: { ...dataItemOpts, tags: tagsWithManifestContentType },
156
+ });
157
+ return {
158
+ ...response,
159
+ manifest,
160
+ manifestResponse,
161
+ };
162
+ }
60
163
  }
61
- exports.TurboAuthenticatedUploadService = TurboAuthenticatedUploadService;
164
+ exports.TurboAuthenticatedBaseUploadService = TurboAuthenticatedBaseUploadService;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TurboFactory = void 0;
4
4
  /**
5
- * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
5
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
6
6
  *
7
7
  * This program is free software: you can redistribute it and/or modify
8
8
  * it under the terms of the GNU Affero General Public License as published by
@@ -15,7 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  /**
18
- * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
18
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
19
19
  *
20
20
  * This program is free software: you can redistribute it and/or modify
21
21
  * it under the terms of the GNU Affero General Public License as published by
@@ -32,5 +32,6 @@ 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("./upload.js"), exports);
35
36
  __exportStar(require("../types.js"), exports);
36
37
  __exportStar(require("../common/index.js"), exports);
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TurboNodeSigner = exports.HexSolanaSigner = exports.EthereumSigner = exports.ArweaveSigner = exports.ArconnectSigner = void 0;
4
4
  /**
5
- * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
5
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
6
6
  *
7
7
  * This program is free software: you can redistribute it and/or modify
8
8
  * it under the terms of the GNU Affero General Public License as published by
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TurboAuthenticatedNodeUploadService = void 0;
4
+ /**
5
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
6
+ *
7
+ * This program is free software: you can redistribute it and/or modify
8
+ * it under the terms of the GNU Affero General Public License as published by
9
+ * the Free Software Foundation, either version 3 of the License, or
10
+ * (at your option) any later version.
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ * GNU Affero General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU Affero General Public License
18
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
19
+ */
20
+ const fs_1 = require("fs");
21
+ const mime_types_1 = require("mime-types");
22
+ const node_stream_1 = require("node:stream");
23
+ const path_1 = require("path");
24
+ const upload_js_1 = require("../common/upload.js");
25
+ const types_js_1 = require("../types.js");
26
+ class TurboAuthenticatedNodeUploadService extends upload_js_1.TurboAuthenticatedBaseUploadService {
27
+ constructor({ url = upload_js_1.defaultUploadServiceURL, retryConfig, signer, logger, token, }) {
28
+ super({ url, retryConfig, logger, token, signer });
29
+ }
30
+ async getAbsoluteFilePathsFromFolder(folderPath) {
31
+ const absoluteFilePaths = [];
32
+ // Walk the directory and add all file paths to the array
33
+ const files = await fs_1.promises.readdir(folderPath);
34
+ for (const file of files) {
35
+ const absoluteFilePath = (0, path_1.join)(folderPath, file);
36
+ const stat = await fs_1.promises.stat(absoluteFilePath);
37
+ if (stat.isDirectory()) {
38
+ absoluteFilePaths.push(...(await this.getAbsoluteFilePathsFromFolder(absoluteFilePath)));
39
+ }
40
+ else {
41
+ absoluteFilePaths.push(absoluteFilePath);
42
+ }
43
+ }
44
+ return absoluteFilePaths;
45
+ }
46
+ getFiles(params) {
47
+ if (!(0, types_js_1.isNodeUploadFolderParams)(params)) {
48
+ throw new Error('folderPath is required for node uploadFolder');
49
+ }
50
+ return this.getAbsoluteFilePathsFromFolder(params.folderPath);
51
+ }
52
+ getFileStreamForFile(file) {
53
+ return (0, fs_1.createReadStream)(file);
54
+ }
55
+ getFileSize(file) {
56
+ return (0, fs_1.statSync)(file).size;
57
+ }
58
+ getFileName(file) {
59
+ return file;
60
+ }
61
+ getRelativePath(file, params) {
62
+ return file.replace(params.folderPath + '/', '');
63
+ }
64
+ contentTypeFromFile(file) {
65
+ const mimeType = (0, mime_types_1.lookup)(file);
66
+ return mimeType !== false ? mimeType : 'application/octet-stream';
67
+ }
68
+ createManifestStream(manifestBuffer) {
69
+ return node_stream_1.Readable.from(manifestBuffer);
70
+ }
71
+ }
72
+ exports.TurboAuthenticatedNodeUploadService = TurboAuthenticatedNodeUploadService;
package/lib/cjs/types.js CHANGED
@@ -1,12 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isJWK = exports.isEthPrivateKey = exports.tokenTypes = void 0;
3
+ exports.isJWK = exports.isWebUploadFolderParams = exports.isNodeUploadFolderParams = exports.tokenTypes = void 0;
4
+ exports.isEthPrivateKey = isEthPrivateKey;
4
5
  exports.tokenTypes = ['arweave', 'solana', 'ethereum'];
6
+ const isNodeUploadFolderParams = (p) => p.folderPath !== undefined;
7
+ exports.isNodeUploadFolderParams = isNodeUploadFolderParams;
8
+ const isWebUploadFolderParams = (p) => p.files !== undefined;
9
+ exports.isWebUploadFolderParams = isWebUploadFolderParams;
5
10
  function isEthPrivateKey(wallet) {
6
11
  if (typeof wallet !== 'string')
7
12
  return false;
8
13
  return wallet.startsWith('0x');
9
14
  }
10
- exports.isEthPrivateKey = isEthPrivateKey;
11
15
  const isJWK = (wallet) => wallet.kty !== undefined;
12
16
  exports.isJWK = isJWK;
@@ -28,7 +28,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.createAxiosInstance = exports.defaultRequestHeaders = void 0;
30
30
  /**
31
- * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
31
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
32
32
  *
33
33
  * This program is free software: you can redistribute it and/or modify
34
34
  * it under the terms of the GNU Affero General Public License as published by
@@ -1,8 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sha256B64Url = exports.toB64Url = exports.fromB64Url = exports.ownerToAddress = exports.jwkToPublicArweaveAddress = exports.base64URLRegex = void 0;
3
+ exports.base64URLRegex = void 0;
4
+ exports.jwkToPublicArweaveAddress = jwkToPublicArweaveAddress;
5
+ exports.ownerToAddress = ownerToAddress;
6
+ exports.fromB64Url = fromB64Url;
7
+ exports.toB64Url = toB64Url;
8
+ exports.sha256B64Url = sha256B64Url;
4
9
  /**
5
- * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
10
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
6
11
  *
7
12
  * This program is free software: you can redistribute it and/or modify
8
13
  * it under the terms of the GNU Affero General Public License as published by
@@ -23,11 +28,9 @@ exports.base64URLRegex = /^[a-zA-Z0-9_-]{43}$/;
23
28
  function jwkToPublicArweaveAddress(jwk) {
24
29
  return ownerToAddress(jwk.n);
25
30
  }
26
- exports.jwkToPublicArweaveAddress = jwkToPublicArweaveAddress;
27
31
  function ownerToAddress(owner) {
28
32
  return sha256B64Url(fromB64Url(owner));
29
33
  }
30
- exports.ownerToAddress = ownerToAddress;
31
34
  function fromB64Url(input) {
32
35
  const paddingLength = input.length % 4 === 0 ? 0 : 4 - (input.length % 4);
33
36
  const base64 = input
@@ -36,12 +39,9 @@ function fromB64Url(input) {
36
39
  .concat('='.repeat(paddingLength));
37
40
  return Buffer.from(base64, 'base64');
38
41
  }
39
- exports.fromB64Url = fromB64Url;
40
42
  function toB64Url(buffer) {
41
43
  return (0, utils_js_1.bufferTob64Url)(buffer);
42
44
  }
43
- exports.toB64Url = toB64Url;
44
45
  function sha256B64Url(input) {
45
46
  return toB64Url((0, crypto_1.createHash)('sha256').update(input).digest());
46
47
  }
47
- exports.sha256B64Url = sha256B64Url;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /**
3
- * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
3
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
4
4
  *
5
5
  * This program is free software: you can redistribute it and/or modify
6
6
  * it under the terms of the GNU Affero General Public License as published by
@@ -16,8 +16,11 @@
16
16
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
17
  */
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.sleep = void 0;
19
+ exports.sleep = sleep;
20
+ exports.isWeb = isWeb;
20
21
  function sleep(ms) {
21
22
  return new Promise((resolve) => setTimeout(resolve, ms));
22
23
  }
23
- exports.sleep = sleep;
24
+ function isWeb() {
25
+ return typeof window !== 'undefined';
26
+ }
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FailedRequestError = exports.UnauthenticatedRequestError = void 0;
4
4
  /**
5
- * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
5
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
6
6
  *
7
7
  * This program is free software: you can redistribute it and/or modify
8
8
  * it under the terms of the GNU Affero General Public License as published by
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.readableStreamToBuffer = void 0;
3
+ exports.readableStreamToBuffer = readableStreamToBuffer;
4
4
  async function readableStreamToBuffer({ stream, size, }) {
5
5
  const reader = stream.getReader();
6
6
  const buffer = Buffer.alloc(size);
@@ -16,4 +16,3 @@ async function readableStreamToBuffer({ stream, size, }) {
16
16
  }
17
17
  return buffer;
18
18
  }
19
- exports.readableStreamToBuffer = readableStreamToBuffer;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /**
3
- * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
3
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
4
4
  *
5
5
  * This program is free software: you can redistribute it and/or modify
6
6
  * it under the terms of the GNU Affero General Public License as published by
@@ -18,4 +18,4 @@
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.version = void 0;
20
20
  // AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
21
- exports.version = '1.9.0';
21
+ exports.version = '1.10.0-alpha.1';
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TurboFactory = void 0;
4
4
  /**
5
- * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
5
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
6
6
  *
7
7
  * This program is free software: you can redistribute it and/or modify
8
8
  * it under the terms of the GNU Affero General Public License as published by
@@ -22,6 +22,7 @@ const factory_js_1 = require("../common/factory.js");
22
22
  const index_js_1 = require("../common/index.js");
23
23
  const types_js_1 = require("../types.js");
24
24
  const signer_js_1 = require("./signer.js");
25
+ const upload_js_1 = require("./upload.js");
25
26
  class TurboFactory extends factory_js_1.TurboBaseFactory {
26
27
  static getSigner(providedSigner, providedPrivateKey, token) {
27
28
  let signer;
@@ -89,7 +90,7 @@ class TurboFactory extends factory_js_1.TurboBaseFactory {
89
90
  token,
90
91
  tokenTools,
91
92
  });
92
- const uploadService = new index_js_1.TurboAuthenticatedUploadService({
93
+ const uploadService = new upload_js_1.TurboAuthenticatedWebUploadService({
93
94
  ...uploadServiceConfig,
94
95
  signer: turboSigner,
95
96
  logger: this.logger,
@@ -15,7 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  /**
18
- * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
18
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
19
19
  *
20
20
  * This program is free software: you can redistribute it and/or modify
21
21
  * it under the terms of the GNU Affero General Public License as published by
@@ -31,6 +31,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
31
31
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
32
32
  */
33
33
  __exportStar(require("./factory.js"), exports);
34
+ __exportStar(require("./upload.js"), exports);
34
35
  __exportStar(require("./signer.js"), exports);
35
36
  __exportStar(require("../common/index.js"), exports);
36
37
  __exportStar(require("../types.js"), exports);
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TurboWebArweaveSigner = exports.HexSolanaSigner = exports.EthereumSigner = exports.ArweaveSigner = exports.ArconnectSigner = void 0;
4
4
  /**
5
- * Copyright (C) 2022-2023 Permanent Data Solutions, Inc. All Rights Reserved.
5
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
6
6
  *
7
7
  * This program is free software: you can redistribute it and/or modify
8
8
  * it under the terms of the GNU Affero General Public License as published by