@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.
- package/README.md +103 -11
- package/bundles/web.bundle.min.js +25370 -12548
- package/lib/cjs/common/factory.js +20 -10
- package/lib/cjs/common/http.js +1 -1
- package/lib/cjs/common/index.js +1 -1
- package/lib/cjs/common/logger.js +1 -1
- package/lib/cjs/common/payment.js +1 -1
- package/lib/cjs/common/signer.js +1 -1
- package/lib/cjs/common/token/arweave.js +3 -3
- package/lib/cjs/common/token/ethereum.js +3 -3
- package/lib/cjs/common/token/solana.js +3 -3
- package/lib/cjs/common/turbo.js +3 -0
- package/lib/cjs/common/upload.js +106 -3
- package/lib/cjs/node/factory.js +1 -1
- package/lib/cjs/node/index.js +2 -1
- package/lib/cjs/node/signer.js +1 -1
- package/lib/cjs/node/upload.js +72 -0
- package/lib/cjs/types.js +6 -2
- package/lib/cjs/utils/axiosClient.js +1 -1
- package/lib/cjs/utils/base64.js +7 -7
- package/lib/cjs/utils/common.js +6 -3
- package/lib/cjs/utils/errors.js +1 -1
- package/lib/cjs/utils/readableStream.js +1 -2
- package/lib/cjs/version.js +2 -2
- package/lib/cjs/web/factory.js +3 -2
- package/lib/cjs/web/index.js +2 -1
- package/lib/cjs/web/signer.js +1 -1
- package/lib/cjs/web/upload.js +57 -0
- package/lib/esm/common/factory.js +19 -9
- package/lib/esm/common/http.js +1 -1
- package/lib/esm/common/index.js +1 -1
- package/lib/esm/common/logger.js +1 -1
- package/lib/esm/common/payment.js +1 -1
- package/lib/esm/common/signer.js +1 -1
- package/lib/esm/common/token/arweave.js +3 -3
- package/lib/esm/common/token/ethereum.js +3 -3
- package/lib/esm/common/token/solana.js +3 -3
- package/lib/esm/common/turbo.js +3 -0
- package/lib/esm/common/upload.js +104 -1
- package/lib/esm/node/factory.js +1 -1
- package/lib/esm/node/index.js +2 -1
- package/lib/esm/node/signer.js +1 -1
- package/lib/esm/node/upload.js +68 -0
- package/lib/esm/types.js +2 -0
- package/lib/esm/utils/axiosClient.js +1 -1
- package/lib/esm/utils/base64.js +1 -1
- package/lib/esm/utils/common.js +4 -1
- package/lib/esm/utils/errors.js +1 -1
- package/lib/esm/version.js +2 -2
- package/lib/esm/web/factory.js +4 -3
- package/lib/esm/web/index.js +2 -1
- package/lib/esm/web/signer.js +1 -1
- package/lib/esm/web/upload.js +53 -0
- package/lib/types/common/currency.d.ts +1 -1
- package/lib/types/common/factory.d.ts.map +1 -1
- package/lib/types/common/http.d.ts +1 -4
- package/lib/types/common/http.d.ts.map +1 -1
- package/lib/types/common/index.d.ts +1 -1
- package/lib/types/common/jwk.d.ts +1 -1
- package/lib/types/common/logger.d.ts +1 -1
- package/lib/types/common/signer.d.ts +0 -1
- package/lib/types/common/signer.d.ts.map +1 -1
- package/lib/types/common/token/arweave.d.ts +1 -1
- package/lib/types/common/token/arweave.d.ts.map +1 -1
- package/lib/types/common/token/ethereum.d.ts +1 -1
- package/lib/types/common/token/ethereum.d.ts.map +1 -1
- package/lib/types/common/token/index.d.ts +1 -1
- package/lib/types/common/token/solana.d.ts +1 -1
- package/lib/types/common/token/solana.d.ts.map +1 -1
- package/lib/types/common/turbo.d.ts +3 -2
- package/lib/types/common/turbo.d.ts.map +1 -1
- package/lib/types/common/upload.d.ts +19 -3
- package/lib/types/common/upload.d.ts.map +1 -1
- package/lib/types/node/factory.d.ts +1 -1
- package/lib/types/node/index.d.ts +2 -1
- package/lib/types/node/index.d.ts.map +1 -1
- package/lib/types/node/signer.d.ts +1 -2
- package/lib/types/node/signer.d.ts.map +1 -1
- package/lib/types/node/upload.d.ts +15 -0
- package/lib/types/node/upload.d.ts.map +1 -0
- package/lib/types/types.d.ts +41 -5
- package/lib/types/types.d.ts.map +1 -1
- package/lib/types/utils/axiosClient.d.ts +1 -1
- package/lib/types/utils/base64.d.ts +0 -1
- package/lib/types/utils/base64.d.ts.map +1 -1
- package/lib/types/utils/common.d.ts +2 -1
- package/lib/types/utils/common.d.ts.map +1 -1
- package/lib/types/utils/errors.d.ts +1 -1
- package/lib/types/utils/readableStream.d.ts +1 -3
- package/lib/types/utils/readableStream.d.ts.map +1 -1
- package/lib/types/version.d.ts +2 -2
- package/lib/types/web/factory.d.ts.map +1 -1
- package/lib/types/web/index.d.ts +2 -1
- package/lib/types/web/index.d.ts.map +1 -1
- package/lib/types/web/signer.d.ts +1 -2
- package/lib/types/web/signer.d.ts.map +1 -1
- package/lib/types/web/upload.d.ts +29 -0
- package/lib/types/web/upload.d.ts.map +1 -0
- package/package.json +11 -5
@@ -0,0 +1,57 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.TurboAuthenticatedWebUploadService = 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 upload_js_1 = require("../common/upload.js");
|
21
|
+
const types_js_1 = require("../types.js");
|
22
|
+
class TurboAuthenticatedWebUploadService extends upload_js_1.TurboAuthenticatedBaseUploadService {
|
23
|
+
constructor({ url = upload_js_1.defaultUploadServiceURL, retryConfig, signer, logger, token, }) {
|
24
|
+
super({ url, retryConfig, logger, token, signer });
|
25
|
+
}
|
26
|
+
getFiles(params) {
|
27
|
+
if (!(0, types_js_1.isWebUploadFolderParams)(params)) {
|
28
|
+
throw new Error('files are required for web uploadFolder');
|
29
|
+
}
|
30
|
+
return Promise.resolve(params.files);
|
31
|
+
}
|
32
|
+
getFileStreamForFile(file) {
|
33
|
+
return file.stream();
|
34
|
+
}
|
35
|
+
getFileSize(file) {
|
36
|
+
return file.size;
|
37
|
+
}
|
38
|
+
getFileName(file) {
|
39
|
+
return file.name;
|
40
|
+
}
|
41
|
+
getRelativePath(file) {
|
42
|
+
return file.name || file.webkitRelativePath;
|
43
|
+
}
|
44
|
+
contentTypeFromFile(file) {
|
45
|
+
return file.type || 'application/octet-stream';
|
46
|
+
}
|
47
|
+
createManifestStream(manifestBuffer) {
|
48
|
+
const stream = new ReadableStream({
|
49
|
+
start(controller) {
|
50
|
+
controller.enqueue(manifestBuffer);
|
51
|
+
controller.close();
|
52
|
+
},
|
53
|
+
});
|
54
|
+
return stream;
|
55
|
+
}
|
56
|
+
}
|
57
|
+
exports.TurboAuthenticatedWebUploadService = TurboAuthenticatedWebUploadService;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (C) 2022-
|
2
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
3
3
|
*
|
4
4
|
* This program is free software: you can redistribute it and/or modify
|
5
5
|
* it under the terms of the GNU Affero General Public License as published by
|
@@ -16,13 +16,16 @@
|
|
16
16
|
*/
|
17
17
|
import { ArweaveSigner, EthereumSigner, HexSolanaSigner } from 'arbundles';
|
18
18
|
import { TurboNodeSigner } from '../node/signer.js';
|
19
|
+
import { TurboAuthenticatedNodeUploadService } from '../node/upload.js';
|
19
20
|
import { isEthPrivateKey, isJWK, } from '../types.js';
|
21
|
+
import { isWeb } from '../utils/common.js';
|
20
22
|
import { TurboWebArweaveSigner } from '../web/signer.js';
|
23
|
+
import { TurboAuthenticatedWebUploadService } from '../web/upload.js';
|
21
24
|
import { TurboWinstonLogger } from './logger.js';
|
22
25
|
import { TurboAuthenticatedPaymentService, TurboUnauthenticatedPaymentService, } from './payment.js';
|
23
26
|
import { defaultTokenMap } from './token/index.js';
|
24
27
|
import { TurboAuthenticatedClient, TurboUnauthenticatedClient, } from './turbo.js';
|
25
|
-
import {
|
28
|
+
import { TurboUnauthenticatedUploadService } from './upload.js';
|
26
29
|
export class TurboBaseFactory {
|
27
30
|
static setLogLevel(level) {
|
28
31
|
this.logger.setLogLevel(level);
|
@@ -69,7 +72,7 @@ export class TurboBaseFactory {
|
|
69
72
|
else {
|
70
73
|
throw new Error('A privateKey or signer must be provided.');
|
71
74
|
}
|
72
|
-
if (
|
75
|
+
if (isWeb()) {
|
73
76
|
return new TurboWebArweaveSigner({
|
74
77
|
signer,
|
75
78
|
logger: this.logger,
|
@@ -115,12 +118,19 @@ export class TurboBaseFactory {
|
|
115
118
|
token,
|
116
119
|
tokenTools,
|
117
120
|
});
|
118
|
-
const uploadService =
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
121
|
+
const uploadService = isWeb()
|
122
|
+
? new TurboAuthenticatedWebUploadService({
|
123
|
+
...uploadServiceConfig,
|
124
|
+
signer: turboSigner,
|
125
|
+
logger: this.logger,
|
126
|
+
token,
|
127
|
+
})
|
128
|
+
: new TurboAuthenticatedNodeUploadService({
|
129
|
+
...uploadServiceConfig,
|
130
|
+
signer: turboSigner,
|
131
|
+
logger: this.logger,
|
132
|
+
token,
|
133
|
+
});
|
124
134
|
return new TurboAuthenticatedClient({
|
125
135
|
uploadService,
|
126
136
|
paymentService,
|
package/lib/esm/common/http.js
CHANGED
@@ -6,7 +6,7 @@ export class TurboHTTPService {
|
|
6
6
|
this.axios = createAxiosInstance({
|
7
7
|
axiosConfig: {
|
8
8
|
baseURL: url,
|
9
|
-
maxRedirects: 0,
|
9
|
+
maxRedirects: 0, // prevents backpressure issues when uploading larger streams via https
|
10
10
|
onUploadProgress: (progressEvent) => {
|
11
11
|
this.logger.debug(`Uploading...`, {
|
12
12
|
percent: Math.floor((progressEvent.progress ?? 0) * 100),
|
package/lib/esm/common/index.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (C) 2022-
|
2
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
3
3
|
*
|
4
4
|
* This program is free software: you can redistribute it and/or modify
|
5
5
|
* it under the terms of the GNU Affero General Public License as published by
|
package/lib/esm/common/logger.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (C) 2022-
|
2
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
3
3
|
*
|
4
4
|
* This program is free software: you can redistribute it and/or modify
|
5
5
|
* it under the terms of the GNU Affero General Public License as published by
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (C) 2022-
|
2
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
3
3
|
*
|
4
4
|
* This program is free software: you can redistribute it and/or modify
|
5
5
|
* it under the terms of the GNU Affero General Public License as published by
|
package/lib/esm/common/signer.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (C) 2022-
|
2
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
3
3
|
*
|
4
4
|
* This program is free software: you can redistribute it and/or modify
|
5
5
|
* it under the terms of the GNU Affero General Public License as published by
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (C) 2022-
|
2
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
3
3
|
*
|
4
4
|
* This program is free software: you can redistribute it and/or modify
|
5
5
|
* it under the terms of the GNU Affero General Public License as published by
|
@@ -24,8 +24,8 @@ export class ArweaveToken {
|
|
24
24
|
url: gatewayUrl,
|
25
25
|
}), logger = new TurboWinstonLogger(), mintU = true, pollingOptions = {
|
26
26
|
maxAttempts: 10,
|
27
|
-
pollingIntervalMs:
|
28
|
-
initialBackoffMs:
|
27
|
+
pollingIntervalMs: 3_000,
|
28
|
+
initialBackoffMs: 7_000,
|
29
29
|
}, } = {}) {
|
30
30
|
this.arweave = arweave;
|
31
31
|
this.logger = logger;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (C) 2022-
|
2
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
3
3
|
*
|
4
4
|
* This program is free software: you can redistribute it and/or modify
|
5
5
|
* it under the terms of the GNU Affero General Public License as published by
|
@@ -22,8 +22,8 @@ export const ETHToTokenAmount = (eth) => new BigNumber(eth).times(1e18).valueOf(
|
|
22
22
|
export class EthereumToken {
|
23
23
|
constructor({ logger = new TurboWinstonLogger(), gatewayUrl = 'https://cloudflare-eth.com/', pollingOptions = {
|
24
24
|
maxAttempts: 10,
|
25
|
-
pollingIntervalMs:
|
26
|
-
initialBackoffMs:
|
25
|
+
pollingIntervalMs: 4_000,
|
26
|
+
initialBackoffMs: 10_000,
|
27
27
|
}, } = {}) {
|
28
28
|
this.logger = logger;
|
29
29
|
this.gatewayUrl = gatewayUrl;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (C) 2022-
|
2
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
3
3
|
*
|
4
4
|
* This program is free software: you can redistribute it and/or modify
|
5
5
|
* it under the terms of the GNU Affero General Public License as published by
|
@@ -24,8 +24,8 @@ export const SOLToTokenAmount = (sol) => new BigNumber(sol).times(1e9).valueOf()
|
|
24
24
|
export class SolanaToken {
|
25
25
|
constructor({ logger = new TurboWinstonLogger(), gatewayUrl = 'https://api.mainnet-beta.solana.com', pollingOptions = {
|
26
26
|
maxAttempts: 10,
|
27
|
-
pollingIntervalMs:
|
28
|
-
initialBackoffMs:
|
27
|
+
pollingIntervalMs: 5_000,
|
28
|
+
initialBackoffMs: 7_000,
|
29
29
|
}, } = {}) {
|
30
30
|
this.logger = logger;
|
31
31
|
this.gatewayUrl = gatewayUrl;
|
package/lib/esm/common/turbo.js
CHANGED
@@ -110,6 +110,9 @@ export class TurboAuthenticatedClient extends TurboUnauthenticatedClient {
|
|
110
110
|
dataItemOpts,
|
111
111
|
});
|
112
112
|
}
|
113
|
+
uploadFolder(p) {
|
114
|
+
return this.uploadService.uploadFolder(p);
|
115
|
+
}
|
113
116
|
/**
|
114
117
|
* Submits fund transaction to the token's blockchain then sends
|
115
118
|
* the transaction ID to the Turbo Payment Service for processing.
|
package/lib/esm/common/upload.js
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import { pLimit } from 'plimit-lit';
|
1
2
|
import { TurboHTTPService } from './http.js';
|
2
3
|
import { TurboWinstonLogger } from './logger.js';
|
3
4
|
export const developmentUploadServiceURL = 'https://upload.ardrive.dev';
|
@@ -28,7 +29,7 @@ export class TurboUnauthenticatedUploadService {
|
|
28
29
|
}
|
29
30
|
}
|
30
31
|
// NOTE: to avoid redundancy, we use inheritance here - but generally prefer composition over inheritance
|
31
|
-
export class
|
32
|
+
export class TurboAuthenticatedBaseUploadService extends TurboUnauthenticatedUploadService {
|
32
33
|
constructor({ url = defaultUploadServiceURL, retryConfig, signer, logger, token, }) {
|
33
34
|
super({ url, retryConfig, logger, token });
|
34
35
|
this.signer = signer;
|
@@ -53,4 +54,106 @@ export class TurboAuthenticatedUploadService extends TurboUnauthenticatedUploadS
|
|
53
54
|
},
|
54
55
|
});
|
55
56
|
}
|
57
|
+
async generateManifest({ paths, indexFile, fallbackFile, }) {
|
58
|
+
const indexPath =
|
59
|
+
// Use the user provided index file if it exists,
|
60
|
+
indexFile !== undefined && paths[indexFile]?.id !== undefined
|
61
|
+
? indexFile
|
62
|
+
: // Else use index.html if it exists,
|
63
|
+
paths['index.html']?.id !== undefined
|
64
|
+
? 'index.html'
|
65
|
+
: // Else use the first file in the paths object.
|
66
|
+
Object.keys(paths)[0];
|
67
|
+
const fallbackId =
|
68
|
+
// Use the user provided fallback file if it exists,
|
69
|
+
fallbackFile !== undefined && paths[fallbackFile]?.id !== undefined
|
70
|
+
? paths[fallbackFile].id
|
71
|
+
: // Else use 404.html if it exists, else use the index path.
|
72
|
+
paths['404.html']?.id ?? paths[indexPath].id;
|
73
|
+
const manifest = {
|
74
|
+
manifest: 'arweave/paths',
|
75
|
+
version: '0.2.0',
|
76
|
+
index: { path: indexPath },
|
77
|
+
paths,
|
78
|
+
fallback: { id: fallbackId },
|
79
|
+
};
|
80
|
+
return manifest;
|
81
|
+
}
|
82
|
+
getContentType(file, dataItemOpts) {
|
83
|
+
const userDefinedContentType = dataItemOpts?.tags?.find((tag) => tag.name === 'Content-Type')?.value;
|
84
|
+
if (userDefinedContentType !== undefined) {
|
85
|
+
return userDefinedContentType;
|
86
|
+
}
|
87
|
+
return this.contentTypeFromFile(file);
|
88
|
+
}
|
89
|
+
async uploadFolder(params) {
|
90
|
+
const { dataItemOpts, signal, manifestOptions = {}, maxConcurrentUploads = 5, throwOnFailure = true, } = params;
|
91
|
+
const { disableManifest, indexFile, fallbackFile } = manifestOptions;
|
92
|
+
const paths = {};
|
93
|
+
const response = {
|
94
|
+
fileResponses: [],
|
95
|
+
};
|
96
|
+
const errors = [];
|
97
|
+
const uploadFile = async (file) => {
|
98
|
+
const contentType = this.getContentType(file, dataItemOpts);
|
99
|
+
const dataItemOptsWithContentType = {
|
100
|
+
...dataItemOpts,
|
101
|
+
tags: [
|
102
|
+
...(dataItemOpts?.tags?.filter((tag) => tag.name !== 'Content-Type') ?? []),
|
103
|
+
{ name: 'Content-Type', value: contentType },
|
104
|
+
],
|
105
|
+
};
|
106
|
+
try {
|
107
|
+
const result = await this.uploadFile({
|
108
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
109
|
+
fileStreamFactory: () => this.getFileStreamForFile(file),
|
110
|
+
fileSizeFactory: () => this.getFileSize(file),
|
111
|
+
signal,
|
112
|
+
dataItemOpts: dataItemOptsWithContentType,
|
113
|
+
});
|
114
|
+
const relativePath = this.getRelativePath(file, params);
|
115
|
+
paths[relativePath] = { id: result.id };
|
116
|
+
response.fileResponses.push(result);
|
117
|
+
}
|
118
|
+
catch (error) {
|
119
|
+
if (throwOnFailure) {
|
120
|
+
throw error;
|
121
|
+
}
|
122
|
+
this.logger.error(`Error uploading file: ${file}`, error);
|
123
|
+
errors.push(error);
|
124
|
+
}
|
125
|
+
};
|
126
|
+
const files = await this.getFiles(params);
|
127
|
+
const limit = pLimit(maxConcurrentUploads);
|
128
|
+
await Promise.all(files.map((file) => limit(() => uploadFile(file))));
|
129
|
+
if (errors.length > 0) {
|
130
|
+
response.errors = errors;
|
131
|
+
}
|
132
|
+
if (disableManifest) {
|
133
|
+
return response;
|
134
|
+
}
|
135
|
+
const manifest = await this.generateManifest({
|
136
|
+
paths,
|
137
|
+
indexFile,
|
138
|
+
fallbackFile,
|
139
|
+
});
|
140
|
+
const tagsWithManifestContentType = [
|
141
|
+
...(dataItemOpts?.tags?.filter((tag) => tag.name !== 'Content-Type') ??
|
142
|
+
[]),
|
143
|
+
{ name: 'Content-Type', value: 'application/x.arweave-manifest+json' },
|
144
|
+
];
|
145
|
+
const manifestBuffer = Buffer.from(JSON.stringify(manifest));
|
146
|
+
const manifestResponse = await this.uploadFile({
|
147
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
148
|
+
fileStreamFactory: () => this.createManifestStream(manifestBuffer),
|
149
|
+
fileSizeFactory: () => manifestBuffer.byteLength,
|
150
|
+
signal,
|
151
|
+
dataItemOpts: { ...dataItemOpts, tags: tagsWithManifestContentType },
|
152
|
+
});
|
153
|
+
return {
|
154
|
+
...response,
|
155
|
+
manifest,
|
156
|
+
manifestResponse,
|
157
|
+
};
|
158
|
+
}
|
56
159
|
}
|
package/lib/esm/node/factory.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (C) 2022-
|
2
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
3
3
|
*
|
4
4
|
* This program is free software: you can redistribute it and/or modify
|
5
5
|
* it under the terms of the GNU Affero General Public License as published by
|
package/lib/esm/node/index.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (C) 2022-
|
2
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
3
3
|
*
|
4
4
|
* This program is free software: you can redistribute it and/or modify
|
5
5
|
* it under the terms of the GNU Affero General Public License as published by
|
@@ -16,5 +16,6 @@
|
|
16
16
|
*/
|
17
17
|
export * from './factory.js';
|
18
18
|
export * from './signer.js';
|
19
|
+
export * from './upload.js';
|
19
20
|
export * from '../types.js';
|
20
21
|
export * from '../common/index.js';
|
package/lib/esm/node/signer.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (C) 2022-
|
2
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
3
3
|
*
|
4
4
|
* This program is free software: you can redistribute it and/or modify
|
5
5
|
* it under the terms of the GNU Affero General Public License as published by
|
@@ -0,0 +1,68 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
3
|
+
*
|
4
|
+
* This program is free software: you can redistribute it and/or modify
|
5
|
+
* it under the terms of the GNU Affero General Public License as published by
|
6
|
+
* the Free Software Foundation, either version 3 of the License, or
|
7
|
+
* (at your option) any later version.
|
8
|
+
*
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
* GNU Affero General Public License for more details.
|
13
|
+
*
|
14
|
+
* You should have received a copy of the GNU Affero General Public License
|
15
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
*/
|
17
|
+
import { createReadStream, promises, statSync } from 'fs';
|
18
|
+
import { lookup } from 'mime-types';
|
19
|
+
import { Readable } from 'node:stream';
|
20
|
+
import { join } from 'path';
|
21
|
+
import { TurboAuthenticatedBaseUploadService, defaultUploadServiceURL, } from '../common/upload.js';
|
22
|
+
import { isNodeUploadFolderParams, } from '../types.js';
|
23
|
+
export class TurboAuthenticatedNodeUploadService extends TurboAuthenticatedBaseUploadService {
|
24
|
+
constructor({ url = defaultUploadServiceURL, retryConfig, signer, logger, token, }) {
|
25
|
+
super({ url, retryConfig, logger, token, signer });
|
26
|
+
}
|
27
|
+
async getAbsoluteFilePathsFromFolder(folderPath) {
|
28
|
+
const absoluteFilePaths = [];
|
29
|
+
// Walk the directory and add all file paths to the array
|
30
|
+
const files = await promises.readdir(folderPath);
|
31
|
+
for (const file of files) {
|
32
|
+
const absoluteFilePath = join(folderPath, file);
|
33
|
+
const stat = await promises.stat(absoluteFilePath);
|
34
|
+
if (stat.isDirectory()) {
|
35
|
+
absoluteFilePaths.push(...(await this.getAbsoluteFilePathsFromFolder(absoluteFilePath)));
|
36
|
+
}
|
37
|
+
else {
|
38
|
+
absoluteFilePaths.push(absoluteFilePath);
|
39
|
+
}
|
40
|
+
}
|
41
|
+
return absoluteFilePaths;
|
42
|
+
}
|
43
|
+
getFiles(params) {
|
44
|
+
if (!isNodeUploadFolderParams(params)) {
|
45
|
+
throw new Error('folderPath is required for node uploadFolder');
|
46
|
+
}
|
47
|
+
return this.getAbsoluteFilePathsFromFolder(params.folderPath);
|
48
|
+
}
|
49
|
+
getFileStreamForFile(file) {
|
50
|
+
return createReadStream(file);
|
51
|
+
}
|
52
|
+
getFileSize(file) {
|
53
|
+
return statSync(file).size;
|
54
|
+
}
|
55
|
+
getFileName(file) {
|
56
|
+
return file;
|
57
|
+
}
|
58
|
+
getRelativePath(file, params) {
|
59
|
+
return file.replace(params.folderPath + '/', '');
|
60
|
+
}
|
61
|
+
contentTypeFromFile(file) {
|
62
|
+
const mimeType = lookup(file);
|
63
|
+
return mimeType !== false ? mimeType : 'application/octet-stream';
|
64
|
+
}
|
65
|
+
createManifestStream(manifestBuffer) {
|
66
|
+
return Readable.from(manifestBuffer);
|
67
|
+
}
|
68
|
+
}
|
package/lib/esm/types.js
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
export const tokenTypes = ['arweave', 'solana', 'ethereum'];
|
2
|
+
export const isNodeUploadFolderParams = (p) => p.folderPath !== undefined;
|
3
|
+
export const isWebUploadFolderParams = (p) => p.files !== undefined;
|
2
4
|
export function isEthPrivateKey(wallet) {
|
3
5
|
if (typeof wallet !== 'string')
|
4
6
|
return false;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (C) 2022-
|
2
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
3
3
|
*
|
4
4
|
* This program is free software: you can redistribute it and/or modify
|
5
5
|
* it under the terms of the GNU Affero General Public License as published by
|
package/lib/esm/utils/base64.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (C) 2022-
|
2
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
3
3
|
*
|
4
4
|
* This program is free software: you can redistribute it and/or modify
|
5
5
|
* it under the terms of the GNU Affero General Public License as published by
|
package/lib/esm/utils/common.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (C) 2022-
|
2
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
3
3
|
*
|
4
4
|
* This program is free software: you can redistribute it and/or modify
|
5
5
|
* it under the terms of the GNU Affero General Public License as published by
|
@@ -17,3 +17,6 @@
|
|
17
17
|
export function sleep(ms) {
|
18
18
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
19
19
|
}
|
20
|
+
export function isWeb() {
|
21
|
+
return typeof window !== 'undefined';
|
22
|
+
}
|
package/lib/esm/utils/errors.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (C) 2022-
|
2
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
3
3
|
*
|
4
4
|
* This program is free software: you can redistribute it and/or modify
|
5
5
|
* it under the terms of the GNU Affero General Public License as published by
|
package/lib/esm/version.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (C) 2022-
|
2
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
3
3
|
*
|
4
4
|
* This program is free software: you can redistribute it and/or modify
|
5
5
|
* it under the terms of the GNU Affero General Public License as published by
|
@@ -15,4 +15,4 @@
|
|
15
15
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
16
|
*/
|
17
17
|
// AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
|
18
|
-
export const version = '1.
|
18
|
+
export const version = '1.10.0-alpha.1';
|
package/lib/esm/web/factory.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (C) 2022-
|
2
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
3
3
|
*
|
4
4
|
* This program is free software: you can redistribute it and/or modify
|
5
5
|
* it under the terms of the GNU Affero General Public License as published by
|
@@ -16,9 +16,10 @@
|
|
16
16
|
*/
|
17
17
|
import { ArweaveSigner, EthereumSigner, HexSolanaSigner } from 'arbundles';
|
18
18
|
import { TurboBaseFactory } from '../common/factory.js';
|
19
|
-
import { TurboAuthenticatedClient, TurboAuthenticatedPaymentService,
|
19
|
+
import { TurboAuthenticatedClient, TurboAuthenticatedPaymentService, defaultTokenMap, } from '../common/index.js';
|
20
20
|
import { isEthPrivateKey, isJWK, } from '../types.js';
|
21
21
|
import { TurboWebArweaveSigner } from './signer.js';
|
22
|
+
import { TurboAuthenticatedWebUploadService } from './upload.js';
|
22
23
|
export class TurboFactory extends TurboBaseFactory {
|
23
24
|
static getSigner(providedSigner, providedPrivateKey, token) {
|
24
25
|
let signer;
|
@@ -86,7 +87,7 @@ export class TurboFactory extends TurboBaseFactory {
|
|
86
87
|
token,
|
87
88
|
tokenTools,
|
88
89
|
});
|
89
|
-
const uploadService = new
|
90
|
+
const uploadService = new TurboAuthenticatedWebUploadService({
|
90
91
|
...uploadServiceConfig,
|
91
92
|
signer: turboSigner,
|
92
93
|
logger: this.logger,
|
package/lib/esm/web/index.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (C) 2022-
|
2
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
3
3
|
*
|
4
4
|
* This program is free software: you can redistribute it and/or modify
|
5
5
|
* it under the terms of the GNU Affero General Public License as published by
|
@@ -15,6 +15,7 @@
|
|
15
15
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
16
|
*/
|
17
17
|
export * from './factory.js';
|
18
|
+
export * from './upload.js';
|
18
19
|
export * from './signer.js';
|
19
20
|
export * from '../common/index.js';
|
20
21
|
export * from '../types.js';
|
package/lib/esm/web/signer.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (C) 2022-
|
2
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
3
3
|
*
|
4
4
|
* This program is free software: you can redistribute it and/or modify
|
5
5
|
* it under the terms of the GNU Affero General Public License as published by
|
@@ -0,0 +1,53 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
3
|
+
*
|
4
|
+
* This program is free software: you can redistribute it and/or modify
|
5
|
+
* it under the terms of the GNU Affero General Public License as published by
|
6
|
+
* the Free Software Foundation, either version 3 of the License, or
|
7
|
+
* (at your option) any later version.
|
8
|
+
*
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
* GNU Affero General Public License for more details.
|
13
|
+
*
|
14
|
+
* You should have received a copy of the GNU Affero General Public License
|
15
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
*/
|
17
|
+
import { TurboAuthenticatedBaseUploadService, defaultUploadServiceURL, } from '../common/upload.js';
|
18
|
+
import { isWebUploadFolderParams, } from '../types.js';
|
19
|
+
export class TurboAuthenticatedWebUploadService extends TurboAuthenticatedBaseUploadService {
|
20
|
+
constructor({ url = defaultUploadServiceURL, retryConfig, signer, logger, token, }) {
|
21
|
+
super({ url, retryConfig, logger, token, signer });
|
22
|
+
}
|
23
|
+
getFiles(params) {
|
24
|
+
if (!isWebUploadFolderParams(params)) {
|
25
|
+
throw new Error('files are required for web uploadFolder');
|
26
|
+
}
|
27
|
+
return Promise.resolve(params.files);
|
28
|
+
}
|
29
|
+
getFileStreamForFile(file) {
|
30
|
+
return file.stream();
|
31
|
+
}
|
32
|
+
getFileSize(file) {
|
33
|
+
return file.size;
|
34
|
+
}
|
35
|
+
getFileName(file) {
|
36
|
+
return file.name;
|
37
|
+
}
|
38
|
+
getRelativePath(file) {
|
39
|
+
return file.name || file.webkitRelativePath;
|
40
|
+
}
|
41
|
+
contentTypeFromFile(file) {
|
42
|
+
return file.type || 'application/octet-stream';
|
43
|
+
}
|
44
|
+
createManifestStream(manifestBuffer) {
|
45
|
+
const stream = new ReadableStream({
|
46
|
+
start(controller) {
|
47
|
+
controller.enqueue(manifestBuffer);
|
48
|
+
controller.close();
|
49
|
+
},
|
50
|
+
});
|
51
|
+
return stream;
|
52
|
+
}
|
53
|
+
}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Copyright (C) 2022-
|
2
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
3
3
|
*
|
4
4
|
* This program is free software: you can redistribute it and/or modify
|
5
5
|
* it under the terms of the GNU Affero General Public License as published by
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/common/factory.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/common/factory.ts"],"names":[],"mappings":"AAoBA,OAAO,EACL,SAAS,EACT,+BAA+B,EAC/B,WAAW,EACX,iCAAiC,EACjC,WAAW,EAGZ,MAAM,aAAa,CAAC;AAKrB,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAKjD,OAAO,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAE1D,OAAO,EACL,wBAAwB,EACxB,0BAA0B,EAC3B,MAAM,YAAY,CAAC;AAGpB,qBAAa,gBAAgB;IAC3B,SAAS,CAAC,MAAM,CAAC,MAAM,qBAA4B;IAEnD,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,MAAM;IAIhC,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM;IAIlC,MAAM,CAAC,eAAe,CAAC,EACrB,oBAAyB,EACzB,mBAAwB,GACzB,GAAE,iCAAsC;IAezC,SAAS,CAAC,MAAM,CAAC,SAAS,CACxB,cAAc,EAAE,WAAW,GAAG,SAAS,EACvC,kBAAkB,EAAE,WAAW,GAAG,SAAS,EAC3C,KAAK,EAAE,SAAS,GACf,2BAA2B;IAqC9B,MAAM,CAAC,aAAa,CAAC,EACnB,UAAU,EACV,MAAM,EAAE,cAAc,EACtB,oBAAyB,EACzB,mBAAwB,EACxB,KAAK,EACL,QAAQ,EACR,UAAU,EACV,UAAU,GACX,EAAE,+BAA+B;CAqDnC"}
|
@@ -1,8 +1,5 @@
|
|
1
|
-
/// <reference types="node" />
|
2
|
-
/// <reference types="node" />
|
3
|
-
/// <reference types="node" />
|
4
1
|
/**
|
5
|
-
* Copyright (C) 2022-
|
2
|
+
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
|
6
3
|
*
|
7
4
|
* This program is free software: you can redistribute it and/or modify
|
8
5
|
* it under the terms of the GNU Affero General Public License as published by
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/common/http.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../../src/common/http.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,OAAO,EACL,yBAAyB,EACzB,WAAW,EACX,yBAAyB,EAC1B,MAAM,aAAa,CAAC;AAIrB,qBAAa,gBAAiB,YAAW,yBAAyB;IAChE,SAAS,CAAC,KAAK,EAAE,aAAa,CAAC;IAC/B,SAAS,CAAC,MAAM,EAAE,WAAW,CAAC;gBAElB,EACV,GAAG,EACH,WAAW,EACX,MAAM,GACP,EAAE;QACD,GAAG,EAAE,MAAM,CAAC;QACZ,WAAW,CAAC,EAAE,iBAAiB,CAAC;QAChC,MAAM,EAAE,WAAW,CAAC;KACrB;IAqBK,GAAG,CAAC,CAAC,EAAE,EACX,QAAQ,EACR,MAAM,EACN,eAA4B,EAC5B,OAAO,GACR,EAAE;QACD,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,CAAC,EAAE,WAAW,CAAC;QACrB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;QAC3B,OAAO,CAAC,EAAE,OAAO,CAAC,yBAAyB,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KACvE,GAAG,OAAO,CAAC,CAAC,CAAC;IAiBR,IAAI,CAAC,CAAC,EAAE,EACZ,QAAQ,EACR,MAAM,EACN,eAA4B,EAC5B,OAAO,EACP,IAAI,GACL,EAAE;QACD,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,CAAC,EAAE,WAAW,CAAC;QACrB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;QAC3B,OAAO,CAAC,EAAE,OAAO,CAAC,yBAAyB,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACtE,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,cAAc,CAAC;KAC1C,GAAG,OAAO,CAAC,CAAC,CAAC;CAoBf"}
|