@settlemint/btp-sdk-cli
Advanced tools
Comparing version 0.3.2-main7b19911 to 0.3.2-maina62fddf
#!/usr/bin/env node | ||
import { cancel, intro, outro, spinner, password, isCancel, text } from '@clack/prompts'; | ||
import { cancel, select, isCancel, intro, outro, spinner, password, text } from '@clack/prompts'; | ||
import { Command } from '@commander-js/extra-typings'; | ||
@@ -58,7 +58,7 @@ import dotenv from 'dotenv'; | ||
dependencies: { | ||
"@clack/prompts": "^0.7.0", | ||
"@clack/prompts": "0.7.0", | ||
"@commander-js/extra-typings": "12.1.0", | ||
commander: "^12.1.0", | ||
commander: "12.1.0", | ||
cosmiconfig: "9.0.0", | ||
dotenv: "^16.4.5", | ||
dotenv: "16.4.5", | ||
"ts-deepmerge": "7.0.1", | ||
@@ -119,3 +119,3 @@ yoctocolors: "2.1.1", | ||
var ConfigSchema = z.object({ | ||
instance: z.string().default("https://console.settlemint.com") | ||
instance: z.string() | ||
}); | ||
@@ -125,5 +125,12 @@ var EnvSchema = z.object({ | ||
}); | ||
ConfigSchema.extend({ | ||
var ConfigEnvSchema = ConfigSchema.extend({ | ||
pat: z.string() | ||
}); | ||
async function config() { | ||
const config2 = await parseConfig(); | ||
if (!config2) { | ||
throw new Error("No config found"); | ||
} | ||
return ConfigEnvSchema.parse({ ...config2, pat: process.env.BTP_PAT_TOKEN }); | ||
} | ||
async function parseConfig() { | ||
@@ -137,8 +144,8 @@ const explorer = cosmiconfig("btp"); | ||
} | ||
async function createConfig(config) { | ||
async function createConfig(config2) { | ||
const defaultConfig = {}; | ||
const preConfiguredConfig = merge(defaultConfig, config); | ||
const preConfiguredConfig = merge(defaultConfig, config2); | ||
const validatedPreConfiguredConfig = ConfigSchema.parse(preConfiguredConfig); | ||
const existingConfig = await parseConfig(); | ||
const mergedConfig = existingConfig ? merge(validatedPreConfiguredConfig, existingConfig) : preConfiguredConfig; | ||
const mergedConfig = existingConfig ? merge(existingConfig, validatedPreConfiguredConfig) : preConfiguredConfig; | ||
const validatedMergedConfig = ConfigSchema.parse(mergedConfig); | ||
@@ -169,2 +176,18 @@ const projectRoot = findProjectRoot(process.cwd()); | ||
// src/lib/cluster-manager.ts | ||
async function getServices() { | ||
const { instance, pat } = await config(); | ||
const result = await fetch(`${instance}/cm/sdk/services`, { | ||
headers: { | ||
"Content-Type": "application/json", | ||
"x-auth-token": pat | ||
} | ||
}); | ||
if (!result.ok) { | ||
return []; | ||
} | ||
const services = await result.json(); | ||
return services; | ||
} | ||
// src/lib/instance.ts | ||
@@ -241,2 +264,83 @@ async function coerceInstanceUrl(url) { | ||
}); | ||
const services = await printSpinner({ | ||
startMessage: "Fetching services", | ||
task: async () => { | ||
return getServices(); | ||
}, | ||
stopMessage: "Services fetched" | ||
}); | ||
const selectWorkspaceResult = await select({ | ||
message: "Select a workspace", | ||
options: services.map((service) => ({ | ||
value: service, | ||
label: service.name | ||
})) | ||
}); | ||
if (isCancel(selectWorkspaceResult)) { | ||
printCancel("Cancelled"); | ||
process.exit(0); | ||
} | ||
const selectApplicationResult = await select({ | ||
message: "Select an application", | ||
options: selectWorkspaceResult.applications.map((service) => ({ | ||
value: service, | ||
label: service.name | ||
})) | ||
}); | ||
if (isCancel(selectApplicationResult)) { | ||
printCancel("Cancelled"); | ||
process.exit(0); | ||
} | ||
if (selectApplicationResult.portals.length > 0) { | ||
const selectPortalResult = await select({ | ||
message: "Select a Smart Contract Set Portal instance", | ||
options: selectApplicationResult.portals.map((service) => ({ | ||
value: service, | ||
label: service.name | ||
})) | ||
}); | ||
if (isCancel(selectPortalResult)) { | ||
printCancel("Cancelled"); | ||
process.exit(0); | ||
} | ||
} | ||
if (selectApplicationResult.graphs.length > 0) { | ||
const selectGraphResult = await select({ | ||
message: "Select a The Graph instance", | ||
options: selectApplicationResult.graphs.map((service) => ({ | ||
value: service, | ||
label: service.name | ||
})) | ||
}); | ||
if (isCancel(selectGraphResult)) { | ||
printCancel("Cancelled"); | ||
process.exit(0); | ||
} | ||
} | ||
if (selectApplicationResult.hasuras.length > 0) { | ||
const selectHasuraResult = await select({ | ||
message: "Select an Hasura instance", | ||
options: selectApplicationResult.hasuras.map((service) => ({ | ||
value: service, | ||
label: service.name | ||
})) | ||
}); | ||
if (isCancel(selectHasuraResult)) { | ||
printCancel("Cancelled"); | ||
process.exit(0); | ||
} | ||
} | ||
if (selectApplicationResult.nodes.length > 0) { | ||
const selectNodeResult = await select({ | ||
message: "Select a blockchain node or loadbalancer", | ||
options: selectApplicationResult.nodes.map((service) => ({ | ||
value: service, | ||
label: service.name | ||
})) | ||
}); | ||
if (isCancel(selectNodeResult)) { | ||
printCancel("Cancelled"); | ||
process.exit(0); | ||
} | ||
} | ||
printOutro("You're all set!"); | ||
@@ -243,0 +347,0 @@ } catch (error) { |
{ | ||
"name": "@settlemint/btp-sdk-cli", | ||
"version": "0.3.2-main7b19911", | ||
"version": "0.3.2-maina62fddf", | ||
"main": "./dist/index.js", | ||
@@ -46,7 +46,7 @@ "module": "./dist/index.js", | ||
"dependencies": { | ||
"@clack/prompts": "^0.7.0", | ||
"@clack/prompts": "0.7.0", | ||
"@commander-js/extra-typings": "12.1.0", | ||
"commander": "^12.1.0", | ||
"commander": "12.1.0", | ||
"cosmiconfig": "9.0.0", | ||
"dotenv": "^16.4.5", | ||
"dotenv": "16.4.5", | ||
"ts-deepmerge": "7.0.1", | ||
@@ -53,0 +53,0 @@ "yoctocolors": "2.1.1", |
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
44581
357
2
+ Addeddotenv@16.4.5(transitive)
- Removeddotenv@16.4.7(transitive)
Updated@clack/prompts@0.7.0
Updatedcommander@12.1.0
Updateddotenv@16.4.5