@ardrive/turbo-sdk 1.13.0-alpha.1 → 1.13.0-alpha.3

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 CHANGED
@@ -66,8 +66,10 @@ Welcome to the `@ardrive/turbo-sdk`! This SDK provides functionality for interac
66
66
  - [CLI Usage](#cli-usage)
67
67
  - [Options](#options)
68
68
  - [Commands](#commands)
69
- - [`crypto-fund`](#crypto-fund)
70
69
  - [`balance`](#balance)
70
+ - [`top-up`](#top-up)
71
+ - [`crypto-fund`](#crypto-fund)
72
+ - [`upload-folder`](#upload-folder)
71
73
  - [Developers](#developers)
72
74
  - [Requirements](#requirements)
73
75
  - [Setup & Build](#setup--build)
@@ -456,7 +458,7 @@ const { winc: balance } = await turbo.getBalance();
456
458
 
457
459
  #### `signer.getNativeAddress()`
458
460
 
459
- Returns the native address of the connected signer.
461
+ Returns the [native address][docs/native-address] of the connected signer.
460
462
 
461
463
  ```typescript
462
464
  const address = await turbo.signer.getNativeAddress();
@@ -687,36 +689,71 @@ npx turbo --help
687
689
 
688
690
  #### Commands
689
691
 
690
- ##### `crypto-fund`
692
+ ##### `balance`
691
693
 
692
- Fund a wallet with Turbo Credits by submitting a payment transaction for the crypto amount to the Turbo wallet and then submitting that transaction id to Turbo Payment Service for top up processing.
694
+ Get the balance of a connected wallet or native address in Turbo Credits.
693
695
 
694
696
  Command Options:
695
697
 
696
- - `-v, --value <value>` - Amount of tokens in the token type's smallest unit value to fund the wallet with
698
+ - `-a, --address <nativeAddress>` - Native address to get the balance of
697
699
 
698
700
  e.g:
699
701
 
700
702
  ```shell
701
- turbo crypto-fund --value 0.0001 --token kyve --private-key 'b27...45c'
703
+ turbo balance --address 'crypto-wallet-public-native-address' --token solana
702
704
  ```
703
705
 
704
- ##### `balance`
706
+ ```shell
707
+ turbo balance --wallet-file '../path/to/my/wallet.json' --token arweave
708
+ ```
709
+
710
+ ##### `top-up`
711
+
712
+ Top up a connected wallet or native address with Turbo Credits using a supported fiat currency. This command will create a Stripe checkout session for the top-up amount and open the URL in the default browser.
713
+
714
+ Command Options:
715
+
716
+ - `-a, --address <nativeAddress>` - Native address to top up
717
+ - `-c, --currency <currency>` - Currency to top up with
718
+ - `-v, --value <value>` - Value of fiat currency for top up. e.g: 10.50 for $10.50 USD
719
+
720
+ e.g:
721
+
722
+ ```shell
723
+ # Open Stripe hosted checkout session in browser to top up for 10.00 USD worth of Turbo Credits
724
+ turbo top-up --address 'crypto-wallet-public-native-address' --token ethereum --currency USD --value 10
725
+ ```
705
726
 
706
- Get the balance of a wallet or native address in Turbo Credits.
727
+ ##### `crypto-fund`
728
+
729
+ Fund a wallet with Turbo Credits by submitting a payment transaction for the crypto amount to the Turbo wallet and then submitting that transaction id to Turbo Payment Service for top up processing.
707
730
 
708
731
  Command Options:
709
732
 
710
- - `-a, --address <address>` - Address to get the balance of
733
+ - `-v, --value <value>` - Value of crypto token for fund. e.g: 0.0001 for 0.0001 KYVE
711
734
 
712
735
  e.g:
713
736
 
714
737
  ```shell
715
- turbo balance --address 'crypto-wallet-public-native-address'
738
+ turbo crypto-fund --value 0.0001 --token kyve --private-key 'b27...45c'
716
739
  ```
717
740
 
741
+ ##### `upload-folder`
742
+
743
+ Upload a folder of files and create and upload a manifest file for the folder upload to the Turbo Upload Service.
744
+
745
+ Command Options:
746
+
747
+ - `-f, --folder-path <folderPath>` - Path to the folder to upload
748
+ - `--index-file <indexFile>` - File to use for the "index" path in the resulting manifest
749
+ - `--fallback-file <fallbackFile>` - File to use for the "fallback" path in the resulting manifest
750
+ - `--no-manifest` - Disable manifest creation
751
+ - `--max-concurrency <maxConcurrency>` - Maximum number of concurrent uploads
752
+
753
+ e.g:
754
+
718
755
  ```shell
719
- turbo balance --wallet-file '../path/to/my/wallet.json'
756
+ turbo upload-folder --folder-path '../path/to/my/folder' --token solana --wallet-file ../path/to/sol/sec/key.json
720
757
  ```
721
758
 
722
759
  ## Developers
@@ -763,3 +800,4 @@ For more information on how to contribute, please see [CONTRIBUTING.md].
763
800
  [TurboAuthenticatedClient]: #turboauthenticatedclient
764
801
  [AbortSignal]: https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
765
802
  [CONTRIBUTING.md]: ./CONTRIBUTING.md
803
+ [docs/native-address]: https://docs.ar.io/glossary.html#native-address
@@ -312251,7 +312251,7 @@ var import_winston = __toESM(require_winston(), 1);
312251
312251
  init_dirname();
312252
312252
  init_buffer2();
312253
312253
  init_process2();
312254
- var version16 = "1.12.0";
312254
+ var version16 = "1.13.0-alpha.2";
312255
312255
 
312256
312256
  // src/common/logger.ts
312257
312257
  var TurboWinstonLogger = class _TurboWinstonLogger {
@@ -317183,6 +317183,18 @@ var SGD = (sgd) => new TwoDecimalCurrency(sgd, "sgd");
317183
317183
  var HKD = (hkd) => new TwoDecimalCurrency(hkd, "hkd");
317184
317184
  var BRL = (brl) => new TwoDecimalCurrency(brl, "brl");
317185
317185
  var JPY = (jpy) => new ZeroDecimalCurrency(jpy, "jpy");
317186
+ var currencyMap = {
317187
+ usd: USD,
317188
+ eur: EUR,
317189
+ gbp: GBP,
317190
+ cad: CAD,
317191
+ aud: AUD,
317192
+ inr: INR,
317193
+ sgd: SGD,
317194
+ hkd: HKD,
317195
+ brl: BRL,
317196
+ jpy: JPY
317197
+ };
317186
317198
 
317187
317199
  // src/common/token/index.ts
317188
317200
  init_dirname();
@@ -317193,6 +317205,21 @@ init_process2();
317193
317205
  init_dirname();
317194
317206
  init_buffer2();
317195
317207
  init_process2();
317208
+ var fiatCurrencyTypes = [
317209
+ "usd",
317210
+ "eur",
317211
+ "gbp",
317212
+ "cad",
317213
+ "aud",
317214
+ "jpy",
317215
+ "inr",
317216
+ "sgd",
317217
+ "hkd",
317218
+ "brl"
317219
+ ];
317220
+ function isCurrency(currency) {
317221
+ return fiatCurrencyTypes.includes(currency);
317222
+ }
317196
317223
  var tokenTypes = ["arweave", "solana", "ethereum", "kyve"];
317197
317224
  var isNodeUploadFolderParams = (p8) => p8.folderPath !== void 0;
317198
317225
  var isWebUploadFolderParams = (p8) => p8.files !== void 0;
@@ -356071,6 +356098,7 @@ export {
356071
356098
  USD,
356072
356099
  WinstonToTokenAmount,
356073
356100
  ZeroDecimalCurrency,
356101
+ currencyMap,
356074
356102
  defaultPaymentServiceURL,
356075
356103
  defaultTokenMap,
356076
356104
  defaultTurboConfiguration,
@@ -356078,6 +356106,8 @@ export {
356078
356106
  developmentPaymentServiceURL,
356079
356107
  developmentTurboConfiguration,
356080
356108
  developmentUploadServiceURL,
356109
+ fiatCurrencyTypes,
356110
+ isCurrency,
356081
356111
  isEthPrivateKey,
356082
356112
  isJWK,
356083
356113
  isKyvePrivateKey,
@@ -21,34 +21,36 @@ Object.defineProperty(exports, "__esModule", { value: true });
21
21
  const commander_1 = require("commander");
22
22
  const version_js_1 = require("../version.js");
23
23
  const commands_js_1 = require("./commands.js");
24
+ const options_js_1 = require("./options.js");
24
25
  const utils_js_1 = require("./utils.js");
25
26
  (0, utils_js_1.applyOptions)(commander_1.program
26
27
  .name('turbo')
27
28
  .version(version_js_1.version)
28
29
  .description('Turbo CLI')
29
- .helpCommand(true), utils_js_1.globalOptions);
30
- (0, utils_js_1.applyOptions)(commander_1.program.command('balance').description('Get balance of a Turbo address'), [utils_js_1.optionMap.address, utils_js_1.optionMap.token, ...utils_js_1.walletOptions]).action(async (_commandOptions, command) => {
31
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
- const options = command.optsWithGlobals();
33
- return (0, commands_js_1.getBalance)(options);
30
+ .helpCommand(true), options_js_1.globalOptions);
31
+ (0, utils_js_1.applyOptions)(commander_1.program.command('balance').description('Get balance of a Turbo address'), [options_js_1.optionMap.address, ...options_js_1.walletOptions]).action(async (_commandOptions, command) => {
32
+ await (0, utils_js_1.runCommand)(command, commands_js_1.getBalance);
34
33
  });
35
- (0, utils_js_1.applyOptions)(commander_1.program.command('top-up').description('Top up a Turbo address with Fiat'), [utils_js_1.optionMap.address, utils_js_1.optionMap.value, utils_js_1.optionMap.token]).action((options) => {
36
- console.log('TODO: fiat top-up', options.address, options.token, options.value);
34
+ (0, utils_js_1.applyOptions)(commander_1.program.command('top-up').description('Top up a Turbo address with Fiat'), [...options_js_1.walletOptions, options_js_1.optionMap.address, options_js_1.optionMap.value, options_js_1.optionMap.currency]).action(async (_commandOptions, command) => {
35
+ await (0, utils_js_1.runCommand)(command, commands_js_1.topUp);
37
36
  });
38
- (0, utils_js_1.applyOptions)(commander_1.program.command('crypto-fund').description('Top up a wallet with crypto'), [...utils_js_1.walletOptions, utils_js_1.optionMap.value]).action(async (_commandOptions, command) => {
37
+ (0, utils_js_1.applyOptions)(commander_1.program.command('crypto-fund').description('Top up a wallet with crypto'), [...options_js_1.walletOptions, options_js_1.optionMap.value]).action(async (_commandOptions, command) => {
39
38
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
40
39
  const options = command.optsWithGlobals();
41
40
  const token = (0, utils_js_1.tokenFromOptions)(options);
42
41
  const value = (0, utils_js_1.valueFromOptions)(options);
43
42
  const privateKey = await (0, utils_js_1.privateKeyFromOptions)(options);
44
43
  const config = (0, utils_js_1.configFromOptions)(options);
45
- (0, commands_js_1.cryptoFund)({ privateKey, value, token, config });
44
+ try {
45
+ await (0, commands_js_1.cryptoFund)({ privateKey, value, token, config });
46
+ process.exit(0);
47
+ }
48
+ catch (error) {
49
+ (0, utils_js_1.exitWithErrorLog)(error);
50
+ }
46
51
  });
47
- (0, utils_js_1.applyOptions)(commander_1.program
48
- .command('upload-folder')
49
- .description('Upload a folder to a Turbo address')
50
- .argument('<folderPath>', 'Directory to upload'), [...utils_js_1.walletOptions, utils_js_1.optionMap.token]).action((directory, options) => {
51
- console.log('upload-folder TODO', directory, options);
52
+ (0, utils_js_1.applyOptions)(commander_1.program.command('upload-folder').description('Upload a folder using Turbo'), options_js_1.uploadFolderOptions).action(async (_commandOptions, command) => {
53
+ await (0, utils_js_1.runCommand)(command, commands_js_1.uploadFolder);
52
54
  });
53
55
  if (process.argv[1].includes('bin/turbo') || // Running from global .bin
54
56
  process.argv[1].includes('cli/cli') // Running from source
@@ -2,6 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getBalance = getBalance;
4
4
  exports.cryptoFund = cryptoFund;
5
+ exports.topUp = topUp;
6
+ exports.openUrl = openUrl;
7
+ exports.uploadFolder = uploadFolder;
5
8
  /**
6
9
  * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
7
10
  *
@@ -18,19 +21,22 @@ exports.cryptoFund = cryptoFund;
18
21
  * You should have received a copy of the GNU Affero General Public License
19
22
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20
23
  */
24
+ const node_child_process_1 = require("node:child_process");
21
25
  const index_js_1 = require("../node/index.js");
26
+ const common_js_1 = require("../utils/common.js");
27
+ const version_js_1 = require("../version.js");
22
28
  const utils_js_1 = require("./utils.js");
23
29
  async function getBalance(options) {
24
30
  const config = (0, utils_js_1.configFromOptions)(options);
25
- if (options.address !== undefined) {
31
+ const { address, privateKey } = await (0, utils_js_1.addressOrPrivateKeyFromOptions)(options);
32
+ if (address !== undefined) {
26
33
  const turbo = index_js_1.TurboFactory.unauthenticated(config);
27
- const { winc } = await turbo.getBalance(options.address);
28
- console.log(`Turbo Balance for Native Address "${options.address}"\nCredits: ${+winc / 1_000_000_000_000}`);
34
+ const { winc } = await turbo.getBalance(address);
35
+ console.log(`Turbo Balance for Native Address "${address}"\nCredits: ${+winc / 1_000_000_000_000}`);
29
36
  return;
30
37
  }
31
- const privateKey = await (0, utils_js_1.optionalPrivateKeyFromOptions)(options);
32
38
  if (privateKey === undefined) {
33
- throw new Error('Must provide an address (--address) or use a valid wallet');
39
+ throw new Error('Must provide an (--address) or use a valid wallet');
34
40
  }
35
41
  const turbo = index_js_1.TurboFactory.authenticated({
36
42
  ...config,
@@ -51,3 +57,82 @@ async function cryptoFund({ value, privateKey, token, config, }) {
51
57
  });
52
58
  console.log('Sent crypto fund transaction: \n', JSON.stringify(result, null, 2));
53
59
  }
60
+ async function topUp(options) {
61
+ const config = (0, utils_js_1.configFromOptions)(options);
62
+ const { address, privateKey } = await (0, utils_js_1.addressOrPrivateKeyFromOptions)(options);
63
+ const value = options.value;
64
+ if (value === undefined) {
65
+ throw new Error('Must provide a --value to top up');
66
+ }
67
+ const currency = (options.currency ?? 'usd').toLowerCase();
68
+ if (!(0, index_js_1.isCurrency)(currency)) {
69
+ throw new Error(`Invalid fiat currency type ${currency}!\nPlease use one of these:\n${JSON.stringify(index_js_1.fiatCurrencyTypes, null, 2)}`);
70
+ }
71
+ // TODO: Pay in CLI prompts via --cli options
72
+ const { url, paymentAmount, winc } = await (async () => {
73
+ const amount = index_js_1.currencyMap[currency](+value);
74
+ if (address !== undefined) {
75
+ const turbo = index_js_1.TurboFactory.unauthenticated(config);
76
+ return turbo.createCheckoutSession({
77
+ amount,
78
+ owner: address,
79
+ });
80
+ }
81
+ if (privateKey === undefined) {
82
+ throw new Error('Must provide a wallet to top up');
83
+ }
84
+ const turbo = index_js_1.TurboFactory.authenticated({
85
+ ...config,
86
+ privateKey,
87
+ });
88
+ return turbo.createCheckoutSession({
89
+ amount,
90
+ owner: await turbo.signer.getNativeAddress(),
91
+ });
92
+ })();
93
+ if (url === undefined) {
94
+ throw new Error('Failed to create checkout session');
95
+ }
96
+ console.log('Got Checkout Session\n' + JSON.stringify({ url, paymentAmount, winc }));
97
+ console.log('Opening checkout session in browser...');
98
+ await (0, common_js_1.sleep)(2000);
99
+ openUrl(url);
100
+ }
101
+ function openUrl(url) {
102
+ if (process.platform === 'darwin') {
103
+ // macOS
104
+ (0, node_child_process_1.exec)(`open ${url}`);
105
+ }
106
+ else if (process.platform === 'win32') {
107
+ // Windows
108
+ (0, node_child_process_1.exec)(`start "" "${url}"`, { windowsHide: true });
109
+ }
110
+ else {
111
+ // Linux/Unix
112
+ open(url);
113
+ }
114
+ }
115
+ const turboCliTags = [
116
+ { name: 'App-Name', value: 'Turbo-CLI' },
117
+ { name: 'App-Version', value: version_js_1.version },
118
+ { name: 'App-Platform', value: process.platform },
119
+ ];
120
+ async function uploadFolder(options) {
121
+ const privateKey = await (0, utils_js_1.privateKeyFromOptions)(options);
122
+ const turbo = index_js_1.TurboFactory.authenticated({
123
+ ...(0, utils_js_1.configFromOptions)(options),
124
+ privateKey,
125
+ });
126
+ const { disableManifest, fallbackFile, folderPath, indexFile, maxConcurrentUploads, } = (0, utils_js_1.getUploadFolderOptions)(options);
127
+ const result = await turbo.uploadFolder({
128
+ folderPath: folderPath,
129
+ dataItemOpts: { tags: [...turboCliTags] }, // TODO: Inject user tags
130
+ manifestOptions: {
131
+ disableManifest,
132
+ indexFile,
133
+ fallbackFile,
134
+ },
135
+ maxConcurrentUploads,
136
+ });
137
+ console.log('Uploaded folder:', JSON.stringify(result, null, 2));
138
+ }
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
4
+ *
5
+ * This program is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU Affero General Public License as published by
7
+ * the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ * GNU Affero General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Affero General Public License
16
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.uploadFolderOptions = exports.globalOptions = exports.walletOptions = exports.optionMap = void 0;
20
+ exports.optionMap = {
21
+ token: {
22
+ alias: '-t, --token <type>',
23
+ description: 'Crypto token type for wallet or action',
24
+ default: 'arweave',
25
+ },
26
+ currency: {
27
+ alias: '-c, --currency <currency>',
28
+ description: 'Fiat currency type to use for the action',
29
+ default: 'usd',
30
+ },
31
+ address: {
32
+ alias: '-a, --address <nativeAddress>',
33
+ description: 'Native address to use for action',
34
+ },
35
+ value: {
36
+ alias: '-v, --value <value>',
37
+ description: 'Value of fiat currency or crypto token for action. e.g: 10.50 for $10.50 USD or 0.0001 for 0.0001 AR',
38
+ },
39
+ walletFile: {
40
+ alias: '-w, --wallet-file <filePath>',
41
+ description: 'Wallet file to use with the action. Formats accepted: JWK.json, KYVE or ETH private key as a string, or SOL Secret Key as a Uint8Array',
42
+ },
43
+ mnemonic: {
44
+ alias: '-m, --mnemonic <phrase>',
45
+ description: 'Mnemonic to use with the action',
46
+ },
47
+ privateKey: {
48
+ alias: '-p, --private-key <key>',
49
+ description: 'Private key to use with the action',
50
+ },
51
+ gateway: {
52
+ alias: '-g, --gateway <url>',
53
+ description: 'Set a custom crypto gateway URL',
54
+ default: undefined,
55
+ },
56
+ dev: {
57
+ alias: '--dev',
58
+ description: 'Enable development endpoints',
59
+ default: false,
60
+ },
61
+ debug: {
62
+ // TODO: Implement
63
+ alias: '--debug',
64
+ description: 'Enable verbose logging',
65
+ default: false,
66
+ },
67
+ quiet: {
68
+ // TODO: Implement
69
+ alias: '--quiet',
70
+ description: 'Disable logging',
71
+ default: false,
72
+ },
73
+ folderPath: {
74
+ alias: '-f, --folder-path <folderPath>',
75
+ description: 'Directory to upload',
76
+ },
77
+ indexFile: {
78
+ alias: '--index-file <indexFile>',
79
+ description: 'Index file to use in the manifest created for folder upload',
80
+ },
81
+ fallbackFile: {
82
+ alias: '--fallback-file <fallbackFile>',
83
+ description: 'Fallback file to use in the manifest created for folder upload',
84
+ },
85
+ manifest: {
86
+ alias: '--no-manifest',
87
+ description: 'Disable manifest creation with --no-manifest',
88
+ default: false,
89
+ },
90
+ maxConcurrency: {
91
+ alias: '--max-concurrency <maxConcurrency>',
92
+ description: 'Maximum number of concurrent uploads',
93
+ },
94
+ };
95
+ exports.walletOptions = [
96
+ exports.optionMap.walletFile,
97
+ exports.optionMap.mnemonic,
98
+ exports.optionMap.privateKey,
99
+ ];
100
+ exports.globalOptions = [
101
+ exports.optionMap.dev,
102
+ exports.optionMap.gateway,
103
+ exports.optionMap.debug,
104
+ exports.optionMap.quiet,
105
+ exports.optionMap.token,
106
+ ];
107
+ exports.uploadFolderOptions = [
108
+ ...exports.walletOptions,
109
+ exports.optionMap.folderPath,
110
+ exports.optionMap.indexFile,
111
+ exports.optionMap.fallbackFile,
112
+ exports.optionMap.manifest,
113
+ exports.optionMap.maxConcurrency,
114
+ ];
@@ -3,13 +3,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.globalOptions = exports.walletOptions = exports.optionMap = void 0;
6
+ exports.exitWithErrorLog = exitWithErrorLog;
7
+ exports.runCommand = runCommand;
7
8
  exports.applyOptions = applyOptions;
8
9
  exports.tokenFromOptions = tokenFromOptions;
9
10
  exports.valueFromOptions = valueFromOptions;
11
+ exports.getFolderPathFromOptions = getFolderPathFromOptions;
12
+ exports.addressOrPrivateKeyFromOptions = addressOrPrivateKeyFromOptions;
10
13
  exports.optionalPrivateKeyFromOptions = optionalPrivateKeyFromOptions;
11
14
  exports.privateKeyFromOptions = privateKeyFromOptions;
12
15
  exports.configFromOptions = configFromOptions;
16
+ exports.getUploadFolderOptions = getUploadFolderOptions;
13
17
  /**
14
18
  * Copyright (C) 2022-2024 Permanent Data Solutions, Inc. All Rights Reserved.
15
19
  *
@@ -30,72 +34,20 @@ const bs58_1 = __importDefault(require("bs58"));
30
34
  const fs_1 = require("fs");
31
35
  const index_js_1 = require("../node/index.js");
32
36
  const errors_js_1 = require("./errors.js");
33
- exports.optionMap = {
34
- token: {
35
- alias: '-t, --token <type>',
36
- description: 'Token type for wallet or action',
37
- default: 'arweave',
38
- },
39
- currency: {
40
- alias: '-c, --currency <currency>',
41
- description: 'Currency type to top up with',
42
- default: 'usd',
43
- },
44
- address: {
45
- alias: '-a, --address <walletAddress>',
46
- description: 'Wallet address to use for action',
47
- },
48
- value: {
49
- alias: '-v, --value <value>',
50
- description: 'Value of fiat currency or crypto token for action',
51
- },
52
- walletFile: {
53
- alias: '-w, --wallet-file <filePath>',
54
- description: 'Wallet file to use with the action. Formats accepted: JWK.json, KYVE or ETH private key as a string, or SOL Secret Key as a Uint8Array',
55
- },
56
- mnemonic: {
57
- alias: '-m, --mnemonic <phrase>',
58
- description: 'Mnemonic to use with the action',
59
- },
60
- privateKey: {
61
- alias: '-p, --private-key <key>',
62
- description: 'Private key to use with the action',
63
- },
64
- gateway: {
65
- alias: '-g, --gateway <url>',
66
- description: 'Set a custom crypto gateway URL',
67
- default: undefined,
68
- },
69
- dev: {
70
- alias: '--dev',
71
- description: 'Enable development endpoints',
72
- default: false,
73
- },
74
- debug: {
75
- // TODO: Implement
76
- alias: '--debug',
77
- description: 'Enable verbose logging',
78
- default: false,
79
- },
80
- quiet: {
81
- // TODO: Implement
82
- alias: '--quiet',
83
- description: 'Disable logging',
84
- default: false,
85
- },
86
- };
87
- exports.walletOptions = [
88
- exports.optionMap.walletFile,
89
- exports.optionMap.mnemonic,
90
- exports.optionMap.privateKey,
91
- ];
92
- exports.globalOptions = [
93
- exports.optionMap.dev,
94
- exports.optionMap.gateway,
95
- exports.optionMap.debug,
96
- exports.optionMap.quiet,
97
- exports.optionMap.token,
98
- ];
37
+ function exitWithErrorLog(error) {
38
+ console.error(error instanceof Error ? error.message : error);
39
+ process.exit(1);
40
+ }
41
+ async function runCommand(command, action) {
42
+ const options = command.optsWithGlobals();
43
+ try {
44
+ await action(options);
45
+ process.exit(0);
46
+ }
47
+ catch (error) {
48
+ exitWithErrorLog(error);
49
+ }
50
+ }
99
51
  function applyOptions(command, options) {
100
52
  [...options].forEach((option) => {
101
53
  command.option(option.alias, option.description, option.default);
@@ -119,6 +71,27 @@ function valueFromOptions(options) {
119
71
  }
120
72
  return value;
121
73
  }
74
+ function getFolderPathFromOptions(options) {
75
+ const folderPath = options.folderPath;
76
+ if (folderPath === undefined) {
77
+ throw new Error('Folder path is required. Use --folderPath <path>');
78
+ }
79
+ // Check if path exists and is a directory
80
+ const stats = (0, fs_1.statSync)(folderPath);
81
+ if (!stats.isDirectory()) {
82
+ throw new Error('Folder path is not a directory');
83
+ }
84
+ return folderPath;
85
+ }
86
+ async function addressOrPrivateKeyFromOptions(options) {
87
+ if (options.address !== undefined) {
88
+ return { address: options.address, privateKey: undefined };
89
+ }
90
+ return {
91
+ address: undefined,
92
+ privateKey: await optionalPrivateKeyFromOptions(options),
93
+ };
94
+ }
122
95
  async function optionalPrivateKeyFromOptions(options) {
123
96
  try {
124
97
  const key = await privateKeyFromOptions(options);
@@ -157,6 +130,7 @@ const tokenToDevGatewayMap = {
157
130
  solana: 'https://api.devnet.solana.com',
158
131
  ethereum: 'https://ethereum-holesky-rpc.publicnode.com',
159
132
  kyve: 'https://api.korellia.kyve.network',
133
+ // matic: 'https://rpc-amoy.polygon.technology',
160
134
  };
161
135
  function configFromOptions({ gateway, dev, token, }) {
162
136
  let config = {};
@@ -174,3 +148,12 @@ function configFromOptions({ gateway, dev, token, }) {
174
148
  config.token = token;
175
149
  return config;
176
150
  }
151
+ function getUploadFolderOptions(options) {
152
+ return {
153
+ folderPath: options.folderPath,
154
+ indexFile: options.indexFile,
155
+ fallbackFile: options.fallbackFile,
156
+ disableManifest: !options.manifest,
157
+ maxConcurrentUploads: +(options.maxConcurrency ?? 1),
158
+ };
159
+ }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.JPY = exports.BRL = exports.HKD = exports.SGD = exports.INR = exports.AUD = exports.CAD = exports.GBP = exports.EUR = exports.USD = exports.TwoDecimalCurrency = exports.ZeroDecimalCurrency = void 0;
3
+ exports.currencyMap = exports.JPY = exports.BRL = exports.HKD = exports.SGD = exports.INR = exports.AUD = exports.CAD = exports.GBP = exports.EUR = exports.USD = exports.TwoDecimalCurrency = exports.ZeroDecimalCurrency = void 0;
4
4
  class ZeroDecimalCurrency {
5
5
  constructor(amount, type) {
6
6
  this.amount = amount;
@@ -40,3 +40,15 @@ exports.BRL = BRL;
40
40
  // Zero decimal currencies that are supported by the Turbo API
41
41
  const JPY = (jpy) => new ZeroDecimalCurrency(jpy, 'jpy');
42
42
  exports.JPY = JPY;
43
+ exports.currencyMap = {
44
+ usd: exports.USD,
45
+ eur: exports.EUR,
46
+ gbp: exports.GBP,
47
+ cad: exports.CAD,
48
+ aud: exports.AUD,
49
+ inr: exports.INR,
50
+ sgd: exports.SGD,
51
+ hkd: exports.HKD,
52
+ brl: exports.BRL,
53
+ jpy: exports.JPY,
54
+ };
@@ -32,6 +32,9 @@ class TurboAuthenticatedUploadService extends upload_js_1.TurboAuthenticatedBase
32
32
  // Walk the directory and add all file paths to the array
33
33
  const files = await fs_1.promises.readdir(folderPath);
34
34
  for (const file of files) {
35
+ if (file === '.DS_Store') {
36
+ continue;
37
+ }
35
38
  const absoluteFilePath = (0, path_1.join)(folderPath, file);
36
39
  const stat = await fs_1.promises.stat(absoluteFilePath);
37
40
  if (stat.isDirectory()) {
package/lib/cjs/types.js CHANGED
@@ -1,8 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isJWK = exports.isWebUploadFolderParams = exports.isNodeUploadFolderParams = exports.tokenTypes = void 0;
3
+ exports.isJWK = exports.isWebUploadFolderParams = exports.isNodeUploadFolderParams = exports.tokenTypes = exports.fiatCurrencyTypes = void 0;
4
+ exports.isCurrency = isCurrency;
4
5
  exports.isKyvePrivateKey = isKyvePrivateKey;
5
6
  exports.isEthPrivateKey = isEthPrivateKey;
7
+ exports.fiatCurrencyTypes = [
8
+ 'usd',
9
+ 'eur',
10
+ 'gbp',
11
+ 'cad',
12
+ 'aud',
13
+ 'jpy',
14
+ 'inr',
15
+ 'sgd',
16
+ 'hkd',
17
+ 'brl',
18
+ ];
19
+ function isCurrency(currency) {
20
+ return exports.fiatCurrencyTypes.includes(currency);
21
+ }
6
22
  exports.tokenTypes = ['arweave', 'solana', 'ethereum', 'kyve'];
7
23
  const isNodeUploadFolderParams = (p) => p.folderPath !== undefined;
8
24
  exports.isNodeUploadFolderParams = isNodeUploadFolderParams;