@ardrive/turbo-sdk 1.37.0 → 1.38.0
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/bundles/web.bundle.min.js +14517 -30405
- package/lib/cjs/common/chunked.js +1 -1
- package/lib/cjs/common/factory.js +2 -6
- package/lib/cjs/common/logger.js +50 -59
- package/lib/cjs/common/payment.js +2 -2
- package/lib/cjs/common/signer.js +1 -1
- package/lib/cjs/common/token/ario.js +1 -1
- package/lib/cjs/common/token/arweave.js +1 -1
- package/lib/cjs/common/token/erc20.js +1 -1
- package/lib/cjs/common/token/ethereum.js +1 -1
- package/lib/cjs/common/token/kyve.js +1 -1
- package/lib/cjs/common/token/polygon.js +1 -1
- package/lib/cjs/common/token/solana.js +1 -1
- package/lib/cjs/common/upload.js +1 -1
- package/lib/cjs/utils/axiosClient.js +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/esm/common/chunked.js +2 -2
- package/lib/esm/common/factory.js +3 -7
- package/lib/esm/common/logger.js +48 -57
- package/lib/esm/common/payment.js +3 -3
- package/lib/esm/common/signer.js +2 -2
- package/lib/esm/common/token/ario.js +2 -2
- package/lib/esm/common/token/arweave.js +2 -2
- package/lib/esm/common/token/erc20.js +2 -2
- package/lib/esm/common/token/ethereum.js +2 -2
- package/lib/esm/common/token/kyve.js +2 -2
- package/lib/esm/common/token/polygon.js +2 -2
- package/lib/esm/common/token/solana.js +2 -2
- package/lib/esm/common/upload.js +2 -2
- package/lib/esm/utils/axiosClient.js +2 -2
- package/lib/esm/version.js +1 -1
- package/lib/types/common/chunked.d.ts.map +1 -1
- package/lib/types/common/factory.d.ts +4 -5
- package/lib/types/common/factory.d.ts.map +1 -1
- package/lib/types/common/logger.d.ts +17 -26
- package/lib/types/common/logger.d.ts.map +1 -1
- package/lib/types/common/payment.d.ts.map +1 -1
- package/lib/types/common/signer.d.ts.map +1 -1
- package/lib/types/common/token/ario.d.ts.map +1 -1
- package/lib/types/common/token/arweave.d.ts.map +1 -1
- package/lib/types/common/token/erc20.d.ts.map +1 -1
- package/lib/types/common/token/ethereum.d.ts.map +1 -1
- package/lib/types/common/token/kyve.d.ts.map +1 -1
- package/lib/types/common/token/polygon.d.ts.map +1 -1
- package/lib/types/common/token/solana.d.ts.map +1 -1
- package/lib/types/common/upload.d.ts.map +1 -1
- package/lib/types/types.d.ts +3 -10
- package/lib/types/types.d.ts.map +1 -1
- package/lib/types/version.d.ts +1 -1
- package/package.json +1 -2
|
@@ -41,7 +41,7 @@ const chunkingHeader = { 'x-chunking-version': '2' };
|
|
|
41
41
|
* uploading them in parallel, and emitting progress/error events.
|
|
42
42
|
*/
|
|
43
43
|
class ChunkedUploader {
|
|
44
|
-
constructor({ http, token, maxChunkConcurrency = exports.defaultMaxChunkConcurrency, maxFinalizeMs, chunkByteCount = exports.defaultChunkByteCount, logger = logger_js_1.
|
|
44
|
+
constructor({ http, token, maxChunkConcurrency = exports.defaultMaxChunkConcurrency, maxFinalizeMs, chunkByteCount = exports.defaultChunkByteCount, logger = logger_js_1.Logger.default, chunkingMode = 'auto', dataItemByteCount, }) {
|
|
45
45
|
this.assertChunkParams({
|
|
46
46
|
chunkByteCount,
|
|
47
47
|
chunkingMode,
|
|
@@ -24,14 +24,10 @@ const index_js_1 = require("./token/index.js");
|
|
|
24
24
|
const turbo_js_1 = require("./turbo.js");
|
|
25
25
|
const upload_js_1 = require("./upload.js");
|
|
26
26
|
class TurboBaseFactory {
|
|
27
|
-
/* @deprecated - use
|
|
27
|
+
/* @deprecated - use Logger directly */
|
|
28
28
|
static setLogLevel(level) {
|
|
29
29
|
this.logger.setLogLevel(level);
|
|
30
30
|
}
|
|
31
|
-
/* @deprecated - use TurboWinstonLogger directly */
|
|
32
|
-
static setLogFormat(format) {
|
|
33
|
-
this.logger.setLogFormat(format);
|
|
34
|
-
}
|
|
35
31
|
static unauthenticated({ paymentServiceConfig = {}, uploadServiceConfig = {}, token, } = {}) {
|
|
36
32
|
token = token === 'pol' ? 'matic' : token;
|
|
37
33
|
token ??= 'arweave'; // default to arweave if token is not provided
|
|
@@ -151,4 +147,4 @@ class TurboBaseFactory {
|
|
|
151
147
|
}
|
|
152
148
|
}
|
|
153
149
|
exports.TurboBaseFactory = TurboBaseFactory;
|
|
154
|
-
TurboBaseFactory.logger = logger_js_1.
|
|
150
|
+
TurboBaseFactory.logger = logger_js_1.Logger.default;
|
package/lib/cjs/common/logger.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.Logger = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Copyright (C) 2022-2024 Permanent Data Solutions, Inc.
|
|
6
6
|
*
|
|
@@ -16,77 +16,68 @@ exports.TurboWinstonLogger = void 0;
|
|
|
16
16
|
* See the License for the specific language governing permissions and
|
|
17
17
|
* limitations under the License.
|
|
18
18
|
*/
|
|
19
|
-
const winston_1 = require("winston");
|
|
20
19
|
const version_js_1 = require("../version.js");
|
|
21
|
-
class
|
|
22
|
-
constructor({ level = 'info',
|
|
23
|
-
this.
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
class Logger {
|
|
21
|
+
constructor({ level = 'info', } = {}) {
|
|
22
|
+
this.level = 'info';
|
|
23
|
+
this.levels = {
|
|
24
|
+
debug: 0,
|
|
25
|
+
info: 1,
|
|
26
|
+
warn: 2,
|
|
27
|
+
error: 3,
|
|
28
|
+
none: 999,
|
|
29
|
+
};
|
|
30
|
+
this.level = level;
|
|
31
|
+
}
|
|
32
|
+
formatMessage(level, message, ...args) {
|
|
33
|
+
const timestamp = new Date().toISOString();
|
|
34
|
+
const meta = {
|
|
35
|
+
timestamp,
|
|
36
|
+
level,
|
|
37
|
+
message,
|
|
38
|
+
name: 'turbo-sdk',
|
|
39
|
+
version: version_js_1.version,
|
|
40
|
+
};
|
|
41
|
+
if (args.length > 0) {
|
|
42
|
+
return JSON.stringify({ ...meta, args });
|
|
26
43
|
}
|
|
27
|
-
|
|
28
|
-
|
|
44
|
+
return JSON.stringify(meta);
|
|
45
|
+
}
|
|
46
|
+
log(level, message, ...args) {
|
|
47
|
+
if (this.levels[level] < this.levels[this.level]) {
|
|
48
|
+
return;
|
|
29
49
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
});
|
|
50
|
+
const formattedMessage = this.formatMessage(level, message, ...args);
|
|
51
|
+
switch (level) {
|
|
52
|
+
case 'debug':
|
|
53
|
+
console.debug(formattedMessage);
|
|
54
|
+
break;
|
|
55
|
+
case 'info':
|
|
56
|
+
console.info(formattedMessage);
|
|
57
|
+
break;
|
|
58
|
+
case 'warn':
|
|
59
|
+
console.warn(formattedMessage);
|
|
60
|
+
break;
|
|
61
|
+
case 'error':
|
|
62
|
+
console.error(formattedMessage);
|
|
63
|
+
break;
|
|
45
64
|
}
|
|
46
65
|
}
|
|
47
66
|
info(message, ...args) {
|
|
48
|
-
|
|
49
|
-
return;
|
|
50
|
-
this.logger.info(message, ...args);
|
|
67
|
+
this.log('info', message, ...args);
|
|
51
68
|
}
|
|
52
69
|
warn(message, ...args) {
|
|
53
|
-
|
|
54
|
-
return;
|
|
55
|
-
this.logger.warn(message, ...args);
|
|
70
|
+
this.log('warn', message, ...args);
|
|
56
71
|
}
|
|
57
72
|
error(message, ...args) {
|
|
58
|
-
|
|
59
|
-
return;
|
|
60
|
-
this.logger.error(message, ...args);
|
|
73
|
+
this.log('error', message, ...args);
|
|
61
74
|
}
|
|
62
75
|
debug(message, ...args) {
|
|
63
|
-
|
|
64
|
-
return;
|
|
65
|
-
this.logger.debug(message, ...args);
|
|
76
|
+
this.log('debug', message, ...args);
|
|
66
77
|
}
|
|
67
78
|
setLogLevel(level) {
|
|
68
|
-
this.
|
|
69
|
-
if ('silent' in this.logger) {
|
|
70
|
-
this.logger.silent = level === 'none';
|
|
71
|
-
}
|
|
72
|
-
if ('level' in this.logger) {
|
|
73
|
-
this.logger.level = level;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
setLogFormat(logFormat) {
|
|
77
|
-
if ('format' in this.logger) {
|
|
78
|
-
this.logger.format = getLogFormat(logFormat);
|
|
79
|
-
}
|
|
79
|
+
this.level = level;
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
-
exports.
|
|
83
|
-
|
|
84
|
-
function getLogFormat(logFormat) {
|
|
85
|
-
return winston_1.format.combine((0, winston_1.format)((info) => {
|
|
86
|
-
if (info.stack && info.level !== 'error') {
|
|
87
|
-
delete info.stack;
|
|
88
|
-
}
|
|
89
|
-
return info;
|
|
90
|
-
})(), winston_1.format.errors({ stack: true }), // Ensure errors show a stack trace
|
|
91
|
-
winston_1.format.timestamp(), logFormat === 'json' ? winston_1.format.json() : winston_1.format.simple());
|
|
92
|
-
}
|
|
82
|
+
exports.Logger = Logger;
|
|
83
|
+
Logger.default = new Logger();
|
|
@@ -25,7 +25,7 @@ const index_js_1 = require("./token/index.js");
|
|
|
25
25
|
exports.developmentPaymentServiceURL = 'https://payment.ardrive.dev';
|
|
26
26
|
exports.defaultPaymentServiceURL = 'https://payment.ardrive.io';
|
|
27
27
|
class TurboUnauthenticatedPaymentService {
|
|
28
|
-
constructor({ url = exports.defaultPaymentServiceURL, logger = logger_js_1.
|
|
28
|
+
constructor({ url = exports.defaultPaymentServiceURL, logger = logger_js_1.Logger.default, retryConfig = (0, axiosClient_js_1.defaultRetryConfig)(logger), token = 'arweave', }) {
|
|
29
29
|
this.logger = logger;
|
|
30
30
|
this.httpService = new http_js_1.TurboHTTPService({
|
|
31
31
|
url: `${url}/v1`,
|
|
@@ -245,7 +245,7 @@ class TurboUnauthenticatedPaymentService {
|
|
|
245
245
|
exports.TurboUnauthenticatedPaymentService = TurboUnauthenticatedPaymentService;
|
|
246
246
|
// NOTE: to avoid redundancy, we use inheritance here - but generally prefer composition over inheritance
|
|
247
247
|
class TurboAuthenticatedPaymentService extends TurboUnauthenticatedPaymentService {
|
|
248
|
-
constructor({ url = exports.defaultPaymentServiceURL, retryConfig, signer, logger = logger_js_1.
|
|
248
|
+
constructor({ url = exports.defaultPaymentServiceURL, retryConfig, signer, logger = logger_js_1.Logger.default, token = 'arweave', tokenTools, }) {
|
|
249
249
|
super({ url, retryConfig, logger, token });
|
|
250
250
|
this.signer = signer;
|
|
251
251
|
this.tokenTools = tokenTools;
|
package/lib/cjs/common/signer.js
CHANGED
|
@@ -44,7 +44,7 @@ const solana_js_1 = require("./token/solana.js");
|
|
|
44
44
|
* Abstract class for signing TurboDataItems.
|
|
45
45
|
*/
|
|
46
46
|
class TurboDataItemAbstractSigner {
|
|
47
|
-
constructor({ signer, logger = logger_js_1.
|
|
47
|
+
constructor({ signer, logger = logger_js_1.Logger.default, token, walletAdapter, }) {
|
|
48
48
|
this.logger = logger;
|
|
49
49
|
this.signer = signer;
|
|
50
50
|
this.token = token;
|
|
@@ -23,7 +23,7 @@ const common_js_1 = require("../../utils/common.js");
|
|
|
23
23
|
const version_js_1 = require("../../version.js");
|
|
24
24
|
const logger_js_1 = require("../logger.js");
|
|
25
25
|
class ARIOToken {
|
|
26
|
-
constructor({ cuUrl = common_js_1.defaultProdAoConfigs.ario.cuUrl, logger = logger_js_1.
|
|
26
|
+
constructor({ cuUrl = common_js_1.defaultProdAoConfigs.ario.cuUrl, logger = logger_js_1.Logger.default, pollingOptions = {
|
|
27
27
|
initialBackoffMs: 500,
|
|
28
28
|
pollingIntervalMs: 0, // no polling for ARIO process
|
|
29
29
|
maxAttempts: 0, // no polling for ARIO process
|
|
@@ -29,7 +29,7 @@ const ArweaveClass =
|
|
|
29
29
|
// @ts-ignore -- Access the correct class constructor for Arweave
|
|
30
30
|
arweave_1.default.default?.default || arweave_1.default.default || arweave_1.default;
|
|
31
31
|
class ArweaveToken {
|
|
32
|
-
constructor({ gatewayUrl = 'https://arweave.net', arweave, logger = logger_js_1.
|
|
32
|
+
constructor({ gatewayUrl = 'https://arweave.net', arweave, logger = logger_js_1.Logger.default, mintU = true, pollingOptions = {
|
|
33
33
|
maxAttempts: 10,
|
|
34
34
|
pollingIntervalMs: 3_000,
|
|
35
35
|
initialBackoffMs: 7_000,
|
|
@@ -23,7 +23,7 @@ const common_js_1 = require("../../utils/common.js");
|
|
|
23
23
|
const logger_js_1 = require("../logger.js");
|
|
24
24
|
const ethereum_js_1 = require("./ethereum.js");
|
|
25
25
|
class ERC20Token extends ethereum_js_1.EthereumToken {
|
|
26
|
-
constructor({ tokenContractAddress, logger = logger_js_1.
|
|
26
|
+
constructor({ tokenContractAddress, logger = logger_js_1.Logger.default, gatewayUrl = common_js_1.defaultProdGatewayUrls.ethereum, pollingOptions, }) {
|
|
27
27
|
super({ logger, gatewayUrl, pollingOptions });
|
|
28
28
|
this.tokenContract = new ethers_1.ethers.Contract(tokenContractAddress, [
|
|
29
29
|
'function decimals() view returns (uint8)',
|
|
@@ -31,7 +31,7 @@ exports.defaultEthereumPollingOptions = {
|
|
|
31
31
|
pollingIntervalMs: 1_500,
|
|
32
32
|
};
|
|
33
33
|
class EthereumToken {
|
|
34
|
-
constructor({ logger = logger_js_1.
|
|
34
|
+
constructor({ logger = logger_js_1.Logger.default, gatewayUrl = common_js_1.defaultProdGatewayUrls.ethereum, pollingOptions = exports.defaultEthereumPollingOptions, } = {}) {
|
|
35
35
|
this.logger = logger;
|
|
36
36
|
this.gatewayUrl = gatewayUrl;
|
|
37
37
|
this.pollingOptions = pollingOptions;
|
|
@@ -38,7 +38,7 @@ exports.ukyveToTokenAmount = ukyveToTokenAmount;
|
|
|
38
38
|
const KYVEToTokenAmount = (sol) => new bignumber_js_1.BigNumber(sol).times(1e6).valueOf();
|
|
39
39
|
exports.KYVEToTokenAmount = KYVEToTokenAmount;
|
|
40
40
|
class KyveToken {
|
|
41
|
-
constructor({ logger = logger_js_1.
|
|
41
|
+
constructor({ logger = logger_js_1.Logger.default, gatewayUrl = common_js_1.defaultProdGatewayUrls.kyve, pollingOptions = {
|
|
42
42
|
maxAttempts: 5,
|
|
43
43
|
pollingIntervalMs: 1_000,
|
|
44
44
|
initialBackoffMs: 500,
|
|
@@ -11,7 +11,7 @@ exports.defaultPolygonPollingOptions = {
|
|
|
11
11
|
pollingIntervalMs: 1_000,
|
|
12
12
|
};
|
|
13
13
|
class PolygonToken extends ethereum_js_1.EthereumToken {
|
|
14
|
-
constructor({ logger = logger_js_1.
|
|
14
|
+
constructor({ logger = logger_js_1.Logger.default, gatewayUrl = common_js_1.defaultProdGatewayUrls.pol, pollingOptions = exports.defaultPolygonPollingOptions, } = {}) {
|
|
15
15
|
super({ logger, gatewayUrl, pollingOptions });
|
|
16
16
|
}
|
|
17
17
|
}
|
|
@@ -32,7 +32,7 @@ const SOLToTokenAmount = (sol) => new bignumber_js_1.BigNumber(sol).times(1e9).v
|
|
|
32
32
|
exports.SOLToTokenAmount = SOLToTokenAmount;
|
|
33
33
|
exports.memoProgramId = 'MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr';
|
|
34
34
|
class SolanaToken {
|
|
35
|
-
constructor({ logger = logger_js_1.
|
|
35
|
+
constructor({ logger = logger_js_1.Logger.default, gatewayUrl = common_js_1.defaultProdGatewayUrls.solana, pollingOptions = {
|
|
36
36
|
maxAttempts: 10,
|
|
37
37
|
pollingIntervalMs: 2_500,
|
|
38
38
|
initialBackoffMs: 500,
|
package/lib/cjs/common/upload.js
CHANGED
|
@@ -44,7 +44,7 @@ exports.creditSharingTagNames = {
|
|
|
44
44
|
exports.developmentUploadServiceURL = 'https://upload.ardrive.dev';
|
|
45
45
|
exports.defaultUploadServiceURL = 'https://upload.ardrive.io';
|
|
46
46
|
class TurboUnauthenticatedUploadService {
|
|
47
|
-
constructor({ url = exports.defaultUploadServiceURL, logger = logger_js_1.
|
|
47
|
+
constructor({ url = exports.defaultUploadServiceURL, logger = logger_js_1.Logger.default, retryConfig = (0, axiosClient_js_1.defaultRetryConfig)(logger), token = 'arweave', }) {
|
|
48
48
|
this.token = token;
|
|
49
49
|
this.logger = logger;
|
|
50
50
|
this.httpService = new http_js_1.TurboHTTPService({
|
|
@@ -26,7 +26,7 @@ exports.defaultRequestHeaders = {
|
|
|
26
26
|
'x-turbo-source-version': version_js_1.version,
|
|
27
27
|
'x-turbo-source-identifier': 'turbo-sdk',
|
|
28
28
|
};
|
|
29
|
-
const defaultRetryConfig = (logger = logger_js_1.
|
|
29
|
+
const defaultRetryConfig = (logger = logger_js_1.Logger.default) => ({
|
|
30
30
|
retryDelay: (retryCount) => Math.min(1000 * 2 ** (retryCount - 1), 30 * 1000), // exponential backoff up to 30s
|
|
31
31
|
retries: 5,
|
|
32
32
|
onRetry: (retryCount, error) => {
|
package/lib/cjs/version.js
CHANGED
|
@@ -19,7 +19,7 @@ import { multipartFailedStatus, validChunkingModes, } from '../types.js';
|
|
|
19
19
|
import { sleep } from '../utils/common.js';
|
|
20
20
|
import { FailedRequestError } from '../utils/errors.js';
|
|
21
21
|
import { TurboEventEmitter, createStreamWithUploadEvents } from './events.js';
|
|
22
|
-
import {
|
|
22
|
+
import { Logger } from './logger.js';
|
|
23
23
|
const fiveMiB = 5 * 1024 * 1024; // 5 MiB
|
|
24
24
|
const fiveHundredMiB = fiveMiB * 100; // 500 MiB
|
|
25
25
|
export const defaultMaxChunkConcurrency = 5;
|
|
@@ -35,7 +35,7 @@ const chunkingHeader = { 'x-chunking-version': '2' };
|
|
|
35
35
|
* uploading them in parallel, and emitting progress/error events.
|
|
36
36
|
*/
|
|
37
37
|
export class ChunkedUploader {
|
|
38
|
-
constructor({ http, token, maxChunkConcurrency = defaultMaxChunkConcurrency, maxFinalizeMs, chunkByteCount = defaultChunkByteCount, logger =
|
|
38
|
+
constructor({ http, token, maxChunkConcurrency = defaultMaxChunkConcurrency, maxFinalizeMs, chunkByteCount = defaultChunkByteCount, logger = Logger.default, chunkingMode = 'auto', dataItemByteCount, }) {
|
|
39
39
|
this.assertChunkParams({
|
|
40
40
|
chunkByteCount,
|
|
41
41
|
chunkingMode,
|
|
@@ -15,20 +15,16 @@
|
|
|
15
15
|
*/
|
|
16
16
|
import { HexInjectedSolanaSigner, InjectedEthereumSigner, SignatureConfig, } from '@dha-team/arbundles';
|
|
17
17
|
import { isEthereumWalletAdapter, isSolanaWalletAdapter, supportedEvmSignerTokens, } from '../types.js';
|
|
18
|
-
import {
|
|
18
|
+
import { Logger } from './logger.js';
|
|
19
19
|
import { TurboAuthenticatedPaymentService, TurboUnauthenticatedPaymentService, } from './payment.js';
|
|
20
20
|
import { defaultTokenMap } from './token/index.js';
|
|
21
21
|
import { TurboAuthenticatedClient, TurboUnauthenticatedClient, } from './turbo.js';
|
|
22
22
|
import { TurboUnauthenticatedUploadService } from './upload.js';
|
|
23
23
|
export class TurboBaseFactory {
|
|
24
|
-
/* @deprecated - use
|
|
24
|
+
/* @deprecated - use Logger directly */
|
|
25
25
|
static setLogLevel(level) {
|
|
26
26
|
this.logger.setLogLevel(level);
|
|
27
27
|
}
|
|
28
|
-
/* @deprecated - use TurboWinstonLogger directly */
|
|
29
|
-
static setLogFormat(format) {
|
|
30
|
-
this.logger.setLogFormat(format);
|
|
31
|
-
}
|
|
32
28
|
static unauthenticated({ paymentServiceConfig = {}, uploadServiceConfig = {}, token, } = {}) {
|
|
33
29
|
token = token === 'pol' ? 'matic' : token;
|
|
34
30
|
token ??= 'arweave'; // default to arweave if token is not provided
|
|
@@ -147,4 +143,4 @@ export class TurboBaseFactory {
|
|
|
147
143
|
throw new Error('Unsupported wallet adapter -- wallet adapter is currently only supported for Solana and Ethereum');
|
|
148
144
|
}
|
|
149
145
|
}
|
|
150
|
-
TurboBaseFactory.logger =
|
|
146
|
+
TurboBaseFactory.logger = Logger.default;
|
package/lib/esm/common/logger.js
CHANGED
|
@@ -13,76 +13,67 @@
|
|
|
13
13
|
* See the License for the specific language governing permissions and
|
|
14
14
|
* limitations under the License.
|
|
15
15
|
*/
|
|
16
|
-
import { createLogger, format, transports, } from 'winston';
|
|
17
16
|
import { version } from '../version.js';
|
|
18
|
-
export class
|
|
19
|
-
constructor({ level = 'info',
|
|
20
|
-
this.
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
export class Logger {
|
|
18
|
+
constructor({ level = 'info', } = {}) {
|
|
19
|
+
this.level = 'info';
|
|
20
|
+
this.levels = {
|
|
21
|
+
debug: 0,
|
|
22
|
+
info: 1,
|
|
23
|
+
warn: 2,
|
|
24
|
+
error: 3,
|
|
25
|
+
none: 999,
|
|
26
|
+
};
|
|
27
|
+
this.level = level;
|
|
28
|
+
}
|
|
29
|
+
formatMessage(level, message, ...args) {
|
|
30
|
+
const timestamp = new Date().toISOString();
|
|
31
|
+
const meta = {
|
|
32
|
+
timestamp,
|
|
33
|
+
level,
|
|
34
|
+
message,
|
|
35
|
+
name: 'turbo-sdk',
|
|
36
|
+
version,
|
|
37
|
+
};
|
|
38
|
+
if (args.length > 0) {
|
|
39
|
+
return JSON.stringify({ ...meta, args });
|
|
23
40
|
}
|
|
24
|
-
|
|
25
|
-
|
|
41
|
+
return JSON.stringify(meta);
|
|
42
|
+
}
|
|
43
|
+
log(level, message, ...args) {
|
|
44
|
+
if (this.levels[level] < this.levels[this.level]) {
|
|
45
|
+
return;
|
|
26
46
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
});
|
|
47
|
+
const formattedMessage = this.formatMessage(level, message, ...args);
|
|
48
|
+
switch (level) {
|
|
49
|
+
case 'debug':
|
|
50
|
+
console.debug(formattedMessage);
|
|
51
|
+
break;
|
|
52
|
+
case 'info':
|
|
53
|
+
console.info(formattedMessage);
|
|
54
|
+
break;
|
|
55
|
+
case 'warn':
|
|
56
|
+
console.warn(formattedMessage);
|
|
57
|
+
break;
|
|
58
|
+
case 'error':
|
|
59
|
+
console.error(formattedMessage);
|
|
60
|
+
break;
|
|
42
61
|
}
|
|
43
62
|
}
|
|
44
63
|
info(message, ...args) {
|
|
45
|
-
|
|
46
|
-
return;
|
|
47
|
-
this.logger.info(message, ...args);
|
|
64
|
+
this.log('info', message, ...args);
|
|
48
65
|
}
|
|
49
66
|
warn(message, ...args) {
|
|
50
|
-
|
|
51
|
-
return;
|
|
52
|
-
this.logger.warn(message, ...args);
|
|
67
|
+
this.log('warn', message, ...args);
|
|
53
68
|
}
|
|
54
69
|
error(message, ...args) {
|
|
55
|
-
|
|
56
|
-
return;
|
|
57
|
-
this.logger.error(message, ...args);
|
|
70
|
+
this.log('error', message, ...args);
|
|
58
71
|
}
|
|
59
72
|
debug(message, ...args) {
|
|
60
|
-
|
|
61
|
-
return;
|
|
62
|
-
this.logger.debug(message, ...args);
|
|
73
|
+
this.log('debug', message, ...args);
|
|
63
74
|
}
|
|
64
75
|
setLogLevel(level) {
|
|
65
|
-
this.
|
|
66
|
-
if ('silent' in this.logger) {
|
|
67
|
-
this.logger.silent = level === 'none';
|
|
68
|
-
}
|
|
69
|
-
if ('level' in this.logger) {
|
|
70
|
-
this.logger.level = level;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
setLogFormat(logFormat) {
|
|
74
|
-
if ('format' in this.logger) {
|
|
75
|
-
this.logger.format = getLogFormat(logFormat);
|
|
76
|
-
}
|
|
76
|
+
this.level = level;
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
|
-
|
|
80
|
-
function getLogFormat(logFormat) {
|
|
81
|
-
return format.combine(format((info) => {
|
|
82
|
-
if (info.stack && info.level !== 'error') {
|
|
83
|
-
delete info.stack;
|
|
84
|
-
}
|
|
85
|
-
return info;
|
|
86
|
-
})(), format.errors({ stack: true }), // Ensure errors show a stack trace
|
|
87
|
-
format.timestamp(), logFormat === 'json' ? format.json() : format.simple());
|
|
88
|
-
}
|
|
79
|
+
Logger.default = new Logger();
|
|
@@ -17,12 +17,12 @@ import { BigNumber } from 'bignumber.js';
|
|
|
17
17
|
import { defaultRetryConfig } from '../utils/axiosClient.js';
|
|
18
18
|
import { isAnyValidUserAddress } from '../utils/common.js';
|
|
19
19
|
import { TurboHTTPService } from './http.js';
|
|
20
|
-
import {
|
|
20
|
+
import { Logger } from './logger.js';
|
|
21
21
|
import { exponentMap, tokenToBaseMap } from './token/index.js';
|
|
22
22
|
export const developmentPaymentServiceURL = 'https://payment.ardrive.dev';
|
|
23
23
|
export const defaultPaymentServiceURL = 'https://payment.ardrive.io';
|
|
24
24
|
export class TurboUnauthenticatedPaymentService {
|
|
25
|
-
constructor({ url = defaultPaymentServiceURL, logger =
|
|
25
|
+
constructor({ url = defaultPaymentServiceURL, logger = Logger.default, retryConfig = defaultRetryConfig(logger), token = 'arweave', }) {
|
|
26
26
|
this.logger = logger;
|
|
27
27
|
this.httpService = new TurboHTTPService({
|
|
28
28
|
url: `${url}/v1`,
|
|
@@ -241,7 +241,7 @@ export class TurboUnauthenticatedPaymentService {
|
|
|
241
241
|
}
|
|
242
242
|
// NOTE: to avoid redundancy, we use inheritance here - but generally prefer composition over inheritance
|
|
243
243
|
export class TurboAuthenticatedPaymentService extends TurboUnauthenticatedPaymentService {
|
|
244
|
-
constructor({ url = defaultPaymentServiceURL, retryConfig, signer, logger =
|
|
244
|
+
constructor({ url = defaultPaymentServiceURL, retryConfig, signer, logger = Logger.default, token = 'arweave', tokenTools, }) {
|
|
245
245
|
super({ url, retryConfig, logger, token });
|
|
246
246
|
this.signer = signer;
|
|
247
247
|
this.tokenTools = tokenTools;
|
package/lib/esm/common/signer.js
CHANGED
|
@@ -30,14 +30,14 @@ import { privateKeyToAccount } from 'viem/accounts';
|
|
|
30
30
|
import { baseSepolia } from 'viem/chains';
|
|
31
31
|
import { isEthereumWalletAdapter, isSolanaWalletAdapter, } from '../types.js';
|
|
32
32
|
import { fromB64Url, ownerToAddress as ownerToB64Address, toB64Url, } from '../utils/base64.js';
|
|
33
|
-
import {
|
|
33
|
+
import { Logger } from './logger.js';
|
|
34
34
|
import { ethDataFromTurboCreditDestinationAddress } from './token/ethereum.js';
|
|
35
35
|
import { memoProgramId } from './token/solana.js';
|
|
36
36
|
/**
|
|
37
37
|
* Abstract class for signing TurboDataItems.
|
|
38
38
|
*/
|
|
39
39
|
export class TurboDataItemAbstractSigner {
|
|
40
|
-
constructor({ signer, logger =
|
|
40
|
+
constructor({ signer, logger = Logger.default, token, walletAdapter, }) {
|
|
41
41
|
this.logger = logger;
|
|
42
42
|
this.signer = signer;
|
|
43
43
|
this.token = token;
|
|
@@ -18,9 +18,9 @@ import { connect, createDataItemSigner } from '@permaweb/aoconnect';
|
|
|
18
18
|
import { BigNumber } from 'bignumber.js';
|
|
19
19
|
import { defaultProdAoConfigs, sleep } from '../../utils/common.js';
|
|
20
20
|
import { version } from '../../version.js';
|
|
21
|
-
import {
|
|
21
|
+
import { Logger } from '../logger.js';
|
|
22
22
|
export class ARIOToken {
|
|
23
|
-
constructor({ cuUrl = defaultProdAoConfigs.ario.cuUrl, logger =
|
|
23
|
+
constructor({ cuUrl = defaultProdAoConfigs.ario.cuUrl, logger = Logger.default, pollingOptions = {
|
|
24
24
|
initialBackoffMs: 500,
|
|
25
25
|
pollingIntervalMs: 0, // no polling for ARIO process
|
|
26
26
|
maxAttempts: 0, // no polling for ARIO process
|
|
@@ -17,13 +17,13 @@ import ArweaveModule from 'arweave';
|
|
|
17
17
|
import { BigNumber } from 'bignumber.js';
|
|
18
18
|
import { sha256B64Url, toB64Url } from '../../utils/base64.js';
|
|
19
19
|
import { sleep } from '../../utils/common.js';
|
|
20
|
-
import {
|
|
20
|
+
import { Logger } from '../logger.js';
|
|
21
21
|
const ArweaveClass =
|
|
22
22
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
23
23
|
// @ts-ignore -- Access the correct class constructor for Arweave
|
|
24
24
|
ArweaveModule.default?.default || ArweaveModule.default || ArweaveModule;
|
|
25
25
|
export class ArweaveToken {
|
|
26
|
-
constructor({ gatewayUrl = 'https://arweave.net', arweave, logger =
|
|
26
|
+
constructor({ gatewayUrl = 'https://arweave.net', arweave, logger = Logger.default, mintU = true, pollingOptions = {
|
|
27
27
|
maxAttempts: 10,
|
|
28
28
|
pollingIntervalMs: 3_000,
|
|
29
29
|
initialBackoffMs: 7_000,
|
|
@@ -17,10 +17,10 @@ import { EthereumSigner } from '@dha-team/arbundles';
|
|
|
17
17
|
import { Wallet as EthereumWallet, JsonRpcProvider, ethers } from 'ethers';
|
|
18
18
|
import { isEthereumWalletAdapter, } from '../../types.js';
|
|
19
19
|
import { defaultProdGatewayUrls } from '../../utils/common.js';
|
|
20
|
-
import {
|
|
20
|
+
import { Logger } from '../logger.js';
|
|
21
21
|
import { EthereumToken, ethDataFromTurboCreditDestinationAddress, } from './ethereum.js';
|
|
22
22
|
export class ERC20Token extends EthereumToken {
|
|
23
|
-
constructor({ tokenContractAddress, logger =
|
|
23
|
+
constructor({ tokenContractAddress, logger = Logger.default, gatewayUrl = defaultProdGatewayUrls.ethereum, pollingOptions, }) {
|
|
24
24
|
super({ logger, gatewayUrl, pollingOptions });
|
|
25
25
|
this.tokenContract = new ethers.Contract(tokenContractAddress, [
|
|
26
26
|
'function decimals() view returns (uint8)',
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
import { BigNumber } from 'bignumber.js';
|
|
17
17
|
import { ethers, hexlify, toUtf8Bytes } from 'ethers';
|
|
18
18
|
import { defaultProdGatewayUrls } from '../../utils/common.js';
|
|
19
|
-
import {
|
|
19
|
+
import { Logger } from '../logger.js';
|
|
20
20
|
export const weiToTokenAmount = (wei) => wei;
|
|
21
21
|
export const ETHToTokenAmount = (eth) => new BigNumber(eth).times(1e18).valueOf();
|
|
22
22
|
export const defaultEthereumPollingOptions = {
|
|
@@ -25,7 +25,7 @@ export const defaultEthereumPollingOptions = {
|
|
|
25
25
|
pollingIntervalMs: 1_500,
|
|
26
26
|
};
|
|
27
27
|
export class EthereumToken {
|
|
28
|
-
constructor({ logger =
|
|
28
|
+
constructor({ logger = Logger.default, gatewayUrl = defaultProdGatewayUrls.ethereum, pollingOptions = defaultEthereumPollingOptions, } = {}) {
|
|
29
29
|
this.logger = logger;
|
|
30
30
|
this.gatewayUrl = gatewayUrl;
|
|
31
31
|
this.pollingOptions = pollingOptions;
|
|
@@ -23,14 +23,14 @@ import { BigNumber } from 'bignumber.js';
|
|
|
23
23
|
import { createAxiosInstance } from '../../utils/axiosClient.js';
|
|
24
24
|
import { defaultProdGatewayUrls } from '../../utils/common.js';
|
|
25
25
|
import { sleep } from '../../utils/common.js';
|
|
26
|
-
import {
|
|
26
|
+
import { Logger } from '../logger.js';
|
|
27
27
|
function hasKyveTxResponse(response) {
|
|
28
28
|
return response.tx_response !== undefined;
|
|
29
29
|
}
|
|
30
30
|
export const ukyveToTokenAmount = (winston) => winston;
|
|
31
31
|
export const KYVEToTokenAmount = (sol) => new BigNumber(sol).times(1e6).valueOf();
|
|
32
32
|
export class KyveToken {
|
|
33
|
-
constructor({ logger =
|
|
33
|
+
constructor({ logger = Logger.default, gatewayUrl = defaultProdGatewayUrls.kyve, pollingOptions = {
|
|
34
34
|
maxAttempts: 5,
|
|
35
35
|
pollingIntervalMs: 1_000,
|
|
36
36
|
initialBackoffMs: 500,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defaultProdGatewayUrls } from '../../utils/common.js';
|
|
2
|
-
import {
|
|
2
|
+
import { Logger } from '../logger.js';
|
|
3
3
|
import { ETHToTokenAmount, EthereumToken } from './ethereum.js';
|
|
4
4
|
export const POLToTokenAmount = ETHToTokenAmount;
|
|
5
5
|
export const defaultPolygonPollingOptions = {
|
|
@@ -8,7 +8,7 @@ export const defaultPolygonPollingOptions = {
|
|
|
8
8
|
pollingIntervalMs: 1_000,
|
|
9
9
|
};
|
|
10
10
|
export class PolygonToken extends EthereumToken {
|
|
11
|
-
constructor({ logger =
|
|
11
|
+
constructor({ logger = Logger.default, gatewayUrl = defaultProdGatewayUrls.pol, pollingOptions = defaultPolygonPollingOptions, } = {}) {
|
|
12
12
|
super({ logger, gatewayUrl, pollingOptions });
|
|
13
13
|
}
|
|
14
14
|
}
|
|
@@ -19,12 +19,12 @@ import { BigNumber } from 'bignumber.js';
|
|
|
19
19
|
import bs58 from 'bs58';
|
|
20
20
|
import { defaultProdGatewayUrls } from '../../utils/common.js';
|
|
21
21
|
import { sleep } from '../../utils/common.js';
|
|
22
|
-
import {
|
|
22
|
+
import { Logger } from '../logger.js';
|
|
23
23
|
export const lamportToTokenAmount = (winston) => winston;
|
|
24
24
|
export const SOLToTokenAmount = (sol) => new BigNumber(sol).times(1e9).valueOf();
|
|
25
25
|
export const memoProgramId = 'MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr';
|
|
26
26
|
export class SolanaToken {
|
|
27
|
-
constructor({ logger =
|
|
27
|
+
constructor({ logger = Logger.default, gatewayUrl = defaultProdGatewayUrls.solana, pollingOptions = {
|
|
28
28
|
maxAttempts: 10,
|
|
29
29
|
pollingIntervalMs: 2_500,
|
|
30
30
|
initialBackoffMs: 500,
|