New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@settlemint/btp-sdk-cli

Package Overview
Dependencies
Maintainers
0
Versions
98
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@settlemint/btp-sdk-cli - npm Package Compare versions

Comparing version 0.3.2-pr5004d47 to 0.3.2-pr907a874

140

dist/index.js
#!/usr/bin/env node
import { cancel, intro, outro } from '@clack/prompts';
import { cancel, intro, outro, password, isCancel, text } from '@clack/prompts';
import { Command } from '@commander-js/extra-typings';
import { inverse, magentaBright, greenBright } from 'yoctocolors';
import { magentaBright, inverse, greenBright, redBright } from 'yoctocolors';
import { writeFileSync, existsSync } from 'node:fs';
import path from 'node:path';
import { cosmiconfig } from 'cosmiconfig';
import { merge } from 'ts-deepmerge';
import { z } from 'zod';

@@ -55,7 +60,4 @@ // package.json

"@commander-js/extra-typings": "12.1.0",
"@inquirer/prompts": "5.3.2",
boxen: "8.0.0",
commander: "^12.1.0",
cosmiconfig: "9.0.0",
"reflect-metadata": "0.2.2",
"ts-deepmerge": "7.0.1",

@@ -67,2 +69,116 @@ yoctocolors: "2.1.1",

};
var printAsciiArt = () => console.log(
magentaBright(`
_________ __ __ .__ _____ .__ __
/ _____/ _____/ |__/ |_| | ____ / \\ |__| _____/ |_
\\_____ \\_/ __ \\ __\\ __\\ | _/ __ \\ / \\ / \\| |/ \\ __\\
/ \\ ___/| | | | | |_\\ ___// Y \\ | | \\ |
/_______ /\\___ >__| |__| |____/\\___ >____|__ /__|___| /__|
\\/ \\/ \\/ \\/ \\/
`)
);
var printIntro = (msg) => intro(inverse(magentaBright(msg)));
var printOutro = (msg) => outro(inverse(greenBright(msg)));
var printCancel = (msg) => cancel(inverse(redBright(msg)));
var promptPassword = async (options) => {
const passwordResult = await password(options);
if (isCancel(passwordResult)) {
printCancel("Cancelled");
process.exit(0);
}
return passwordResult;
};
var promptText = async (options) => {
const textResult = await text(options);
if (isCancel(textResult)) {
printCancel("Cancelled");
process.exit(0);
}
return textResult;
};
var ConfigSchema = z.object({
pat: z.string(),
instance: z.string()
});
async function parseConfig() {
const explorer = cosmiconfig("btp");
const result = await explorer.search();
if (result) {
return ConfigSchema.parse(result.config);
}
return void 0;
}
function findProjectRoot(startDir) {
let currentDir = startDir;
while (currentDir !== path.parse(currentDir).root) {
if (existsSync(path.join(currentDir, "package.json"))) {
return currentDir;
}
currentDir = path.dirname(currentDir);
}
throw new Error("Unable to find project root");
}
async function createConfig(config) {
const defaultConfig = {
pat: "sm_pat_xxxxxxxxxxxxxxxx",
instance: "https://console.settlemint.com"
};
const preConfiguredConfig = merge(defaultConfig, config);
const validatedPreConfiguredConfig = ConfigSchema.parse(preConfiguredConfig);
const existingConfig = await parseConfig();
const mergedConfig = existingConfig ? merge(validatedPreConfiguredConfig, existingConfig) : preConfiguredConfig;
const validatedMergedConfig = ConfigSchema.parse(mergedConfig);
const projectRoot = findProjectRoot(process.cwd());
const configPath = path.join(projectRoot, ".btprc.json");
writeFileSync(configPath, JSON.stringify(validatedMergedConfig, null, 2));
return validatedMergedConfig;
}
// src/lib/instance.ts
async function coerceInstanceUrl(url) {
let envUrl = process.env.BTP_INSTANCE_URL || url;
if (!validateInstanceUrl(envUrl)) {
envUrl = await promptText({
message: "Enter the URL of your BTP instance",
defaultValue: "https://console.settlemint.com",
initialValue: "https://console.settlemint.com",
placeholder: "https://console.settlemint.com",
validate(value) {
if (!validateInstanceUrl(value)) {
return "Invalid BTP instance URL. Please enter a valid HTTPS URL.";
}
}
});
}
return envUrl;
}
function validateInstanceUrl(url) {
try {
const parsedUrl = new URL(url ?? "");
return parsedUrl.protocol === "https:";
} catch {
return false;
}
}
// src/lib/pat-token.ts
async function coercePatToken(pat) {
let envPat = process.env.BTP_PAT_TOKEN || pat;
if (!validatePatToken(envPat)) {
envPat = await promptPassword({
message: "Enter a Personal Access Token for authentication",
validate(value) {
if (!validatePatToken(value)) {
return "Invalid Personal Access Token";
}
}
});
}
return envPat;
}
function validatePatToken(pat) {
return /^sm_pat_[a-f0-9]{16}$/.test(pat?.trim() ?? "");
}
// src/commands/init.ts
function initCommand() {

@@ -73,4 +189,14 @@ return new Command("init").option("-p, --pat <key>", "Personal Access Token for authentication (BTP_PAT_TOKEN environment variable)").option(

).description("Initializes the setup of the BTP SDK").action(async ({ pat, instance }) => {
intro(inverse(magentaBright("Setting up the BTP SDK in your project")));
outro(inverse(greenBright("You're all set!")));
printAsciiArt();
printIntro("Setting up the BTP SDK in your project");
try {
const personalAccessToken = await coercePatToken(pat);
const instanceUrl = await coerceInstanceUrl(instance);
await createConfig({ pat: personalAccessToken, instance: instanceUrl });
printOutro("You're all set!");
} catch (error) {
printCancel(`Error: ${error.message}`);
console.error(error.stack);
process.exit(1);
}
});

@@ -77,0 +203,0 @@ }

5

package.json
{
"name": "@settlemint/btp-sdk-cli",
"version": "0.3.2-pr5004d47",
"version": "0.3.2-pr907a874",
"main": "./dist/index.js",

@@ -49,7 +49,4 @@ "module": "./dist/index.js",

"@commander-js/extra-typings": "12.1.0",
"@inquirer/prompts": "5.3.2",
"boxen": "8.0.0",
"commander": "^12.1.0",
"cosmiconfig": "9.0.0",
"reflect-metadata": "0.2.2",
"ts-deepmerge": "7.0.1",

@@ -56,0 +53,0 @@ "yoctocolors": "2.1.1",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc