Skip to content

Commit

Permalink
Merge pull request #183 from ardriveapp/PE-6830-inject-turbo-urls
Browse files Browse the repository at this point in the history
PE-6830-inject-turbo-urls
  • Loading branch information
fedellen authored Sep 26, 2024
2 parents bfcfe19 + fdc29ea commit 3f386e9
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,8 @@ npx turbo --help
- `-h, --help` - display help for command
- `--dev` - Enable development endpoints (default: false)
- `-g, --gateway <url>` - Set a custom crypto gateway URL
- `--upload-url <url>` - Set a custom upload service URL
- `--payment-url <url>` - Set a custom payment service URL
- `-t, --token <token>` - Token type for the command or connected wallet (default: "arweave")

- `-w, --wallet-file <filePath>` - Wallet file to use with the action. Formats accepted: JWK.json, KYVE, ETH, or POL private key as a string, or SOL Secret Key as a Uint8Array
Expand Down
13 changes: 12 additions & 1 deletion src/cli/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,21 @@ export const optionMap = {
alias: '-p, --private-key <key>',
description: 'Private key to use with the action',
},

gateway: {
alias: '-g, --gateway <url>',
description: 'Set a custom crypto gateway URL',
default: undefined,
},
uploadUrl: {
alias: '--upload-url <url>',
description: 'Set a custom upload service URL',
default: undefined,
},
paymentUrl: {
alias: '--payment-url <url>',
description: 'Set a custom payment service URL',
default: undefined,
},
dev: {
alias: '--dev',
description: 'Enable development endpoints',
Expand Down Expand Up @@ -126,6 +135,8 @@ export const globalOptions = [
optionMap.quiet,
optionMap.token,
optionMap.skipConfirmation,
optionMap.paymentUrl,
optionMap.uploadUrl,
];

export const uploadFolderOptions = [
Expand Down
2 changes: 2 additions & 0 deletions src/cli/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export type GlobalOptions = {
quiet: boolean;
skipConfirmation: boolean;
token: string;
paymentUrl: string | undefined;
uploadUrl: string | undefined;
};

export type WalletOptions = GlobalOptions & {
Expand Down
34 changes: 26 additions & 8 deletions src/cli/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,22 +173,40 @@ const tokenToDevGatewayMap: Record<TokenType, string> = {
export function configFromOptions(
options: GlobalOptions,
): TurboUnauthenticatedConfiguration {
let config: TurboUnauthenticatedConfiguration = {};

const token = tokenFromOptions(options);

let paymentUrl: string | undefined = undefined;
let uploadUrl: string | undefined = undefined;
let gatewayUrl: string | undefined = undefined;

if (options.dev) {
config = developmentTurboConfiguration;
config.gatewayUrl = tokenToDevGatewayMap[token];
// Use development endpoints
paymentUrl = developmentTurboConfiguration.paymentServiceConfig.url;
uploadUrl = developmentTurboConfiguration.uploadServiceConfig.url;
gatewayUrl = tokenToDevGatewayMap[token];
} else {
config = defaultTurboConfiguration;
// Use default endpoints
paymentUrl = defaultTurboConfiguration.paymentServiceConfig.url;
uploadUrl = defaultTurboConfiguration.uploadServiceConfig.url;
}

// If gateway is provided, override the default or dev gateway
// Override gateway, payment, and upload service default endpoints if provided
if (options.gateway !== undefined) {
config.gatewayUrl = options.gateway;
gatewayUrl = options.gateway;
}
if (options.paymentUrl !== undefined) {
paymentUrl = options.paymentUrl;
}
config.token = token;
if (options.uploadUrl !== undefined) {
uploadUrl = options.uploadUrl;
}

const config = {
paymentServiceConfig: { url: paymentUrl },
uploadServiceConfig: { url: uploadUrl },
gatewayUrl,
token,
};

return config;
}
Expand Down

0 comments on commit 3f386e9

Please sign in to comment.