@settlemint/btp-sdk-cli
Advanced tools
Comparing version 0.3.2-prba49f07 to 0.3.2-prfa8007a
#!/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'; | ||
@@ -55,12 +55,10 @@ import dotenv from 'dotenv'; | ||
"@types/node": "20.14.13", | ||
tsup: "8.2.3", | ||
"type-fest": "4.23.0" | ||
tsup: "8.2.3" | ||
}, | ||
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-stringify": "^3.0.1", | ||
dotenv: "16.4.5", | ||
"ts-deepmerge": "7.0.1", | ||
@@ -121,3 +119,3 @@ yoctocolors: "2.1.1", | ||
var ConfigSchema = z.object({ | ||
instance: z.string().default("https://console.settlemint.com") | ||
instance: z.string() | ||
}); | ||
@@ -127,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() { | ||
@@ -139,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); | ||
@@ -155,3 +160,3 @@ const projectRoot = findProjectRoot(process.cwd()); | ||
const projectRoot = findProjectRoot(process.cwd()); | ||
const envPath = path.join(projectRoot, ".env"); | ||
const envPath = path.join(projectRoot, ".env.local"); | ||
let dotEnv = {}; | ||
@@ -172,2 +177,18 @@ try { | ||
// 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 | ||
@@ -230,16 +251,97 @@ async function coerceInstanceUrl(url) { | ||
await printSpinner({ | ||
startMessage: "Creating .env file", | ||
startMessage: "Creating or updating the .env.local file", | ||
task: async () => { | ||
await createEnv({ BTP_PAT_TOKEN: personalAccessToken }); | ||
}, | ||
stopMessage: ".env file created" | ||
stopMessage: ".env.local file created or updated" | ||
}); | ||
const instanceUrl = await coerceInstanceUrl(instance); | ||
await printSpinner({ | ||
startMessage: "Creating config file", | ||
startMessage: "Creating or updating the .btprc.json config file", | ||
task: async () => { | ||
await createConfig({ instance: instanceUrl }); | ||
}, | ||
stopMessage: ".btprc.json config file created" | ||
stopMessage: ".btprc.json config file created or updated" | ||
}); | ||
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!"); | ||
@@ -246,0 +348,0 @@ } catch (error) { |
{ | ||
"name": "@settlemint/btp-sdk-cli", | ||
"version": "0.3.2-prba49f07", | ||
"version": "0.3.2-prfa8007a", | ||
"main": "./dist/index.js", | ||
@@ -43,12 +43,10 @@ "module": "./dist/index.js", | ||
"@types/node": "20.14.13", | ||
"tsup": "8.2.3", | ||
"type-fest": "4.23.0" | ||
"tsup": "8.2.3" | ||
}, | ||
"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-stringify": "^3.0.1", | ||
"dotenv": "16.4.5", | ||
"ts-deepmerge": "7.0.1", | ||
@@ -55,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
44579
8
2
357
2
1
+ Addeddotenv@16.4.5(transitive)
- Removeddotenv-stringify@^3.0.1
- Removeddotenv@16.4.7(transitive)
- Removeddotenv-stringify@3.0.1(transitive)
Updated@clack/prompts@0.7.0
Updatedcommander@12.1.0
Updateddotenv@16.4.5