Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@based/cli

Package Overview
Dependencies
Maintainers
1
Versions
189
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@based/cli - npm Package Compare versions

Comparing version 5.8.0 to 5.9.0

dist/commands/backups/make/cmd.d.ts

3

dist/commands/backups/download/cmd.d.ts

@@ -1,2 +0,2 @@

export declare const backupsDownloadCmd: ({ org, project, env, cluster }: {
export declare const backupsDownloadCmd: ({ org, project, env, cluster, apiKey, }: {
org: any;

@@ -6,3 +6,4 @@ project: any;

cluster: any;
apiKey: any;
}) => Promise<void>;
//# sourceMappingURL=cmd.d.ts.map

@@ -38,5 +38,6 @@ "use strict";

const node_os_1 = require("node:os");
const utils_1 = require("../../../utils");
const sanitizeFileName = (fileName) => fileName.replace(/\//gm, '-');
const replaceTilde = (path) => path.replace(/^~(?=$|\/|\\)/, (0, node_os_1.homedir)());
const backupsDownloadCmd = async ({ org, project, env, cluster }) => {
const backupsDownloadCmd = async ({ org, project, env, cluster, apiKey, }) => {
const envAdminClient = await (0, getClient_1.getClient)({

@@ -47,6 +48,9 @@ org,

cluster,
apiKey,
});
const { backups } = (await envAdminClient.call('based:backups-list')) || {};
const { backups } = (await envAdminClient.call('based:backups-list')) || {
backups: {},
};
envAdminClient.destroy();
if (!Object.keys(backups)) {
if (!Object.keys(backups).length) {
console.log('No backups found.');

@@ -65,2 +69,3 @@ process.exit(0);

...backups[instanceName]
.filter((o) => !(0, utils_1.isCurrentDumpKey)(o.key))
.sort()

@@ -72,2 +77,6 @@ .reverse()

})),
{
name: 'New backup...',
value: `env-db${instanceName !== 'default' ? '-' + instanceName : ''}/current-dump.rdb`,
},
new select_1.Separator(),

@@ -74,0 +83,0 @@ ],

@@ -18,5 +18,19 @@ "use strict";

exports.backupsDownload = void 0;
const utils_1 = require("../../../utils");
const getClient_1 = require("../../../utils/getClient");
__exportStar(require("./cmd"), exports);
const backupsDownload = async ({ org, project, env, cluster, instanceName, key, path, }) => {
if ((0, utils_1.isCurrentDumpKey)(key)) {
const adminClient = await (0, getClient_1.getClient)({
adminHub: true,
cluster,
silent: true,
});
await adminClient.call('backup-env', {
org,
project,
env,
});
await adminClient.destroy();
}
const envAdminClient = await (0, getClient_1.getClient)({

@@ -27,2 +41,3 @@ org,

cluster,
silent: true,
});

@@ -33,3 +48,3 @@ const response = await envAdminClient.call('based:backups-download', {

});
envAdminClient.destroy();
await envAdminClient.destroy();
return response;

@@ -36,0 +51,0 @@ };

@@ -1,2 +0,2 @@

export declare const backupsFlushCmd: ({ org, project, env, cluster, name, file, }: {
export declare const backupsFlushCmd: ({ org, project, env, cluster, name, file, apiKey, }: {
org: any;

@@ -8,3 +8,4 @@ project: any;

file: any;
apiKey: any;
}) => Promise<any>;
//# sourceMappingURL=cmd.d.ts.map

@@ -12,3 +12,3 @@ "use strict";

const confirm_1 = __importDefault(require("@inquirer/confirm"));
const backupsFlushCmd = async ({ org, project, env, cluster, name, file, }) => {
const backupsFlushCmd = async ({ org, project, env, cluster, name, file, apiKey, }) => {
const envAdminClient = await (0, getClient_1.getClient)({

@@ -19,2 +19,3 @@ org,

cluster,
apiKey,
});

@@ -21,0 +22,0 @@ const dbs = await envAdminClient.call('based:db-list');

@@ -6,2 +6,3 @@ export * from './upload';

export * from './flush';
export * from './make';
//# sourceMappingURL=index.d.ts.map

@@ -22,2 +22,3 @@ "use strict";

__exportStar(require("./flush"), exports);
__exportStar(require("./make"), exports);
//# sourceMappingURL=index.js.map

@@ -1,7 +0,2 @@

export declare const backupsListCmd: ({ org, project, env, cluster }: {
org: any;
project: any;
env: any;
cluster: any;
}) => Promise<void>;
export declare const backupsListCmd: (args: any) => Promise<void>;
//# sourceMappingURL=cmd.d.ts.map

@@ -9,4 +9,4 @@ "use strict";

const _1 = require(".");
const backupsListCmd = async ({ org, project, env, cluster }) => {
const { backups } = (await (0, _1.backupsList)({ cluster, org, project, env })) || {};
const backupsListCmd = async (args) => {
const { backups } = (await (0, _1.backupsList)(args)) || {};
if (!Object.keys(backups)) {

@@ -13,0 +13,0 @@ console.log('No backups found.');

export * from './cmd';
export declare const backupsList: ({ org, project, env, cluster }: {
export declare const backupsList: ({ org, project, env, cluster, apiKey }: {
org: any;

@@ -7,3 +7,4 @@ project: any;

cluster: any;
apiKey: any;
}) => Promise<any>;
//# sourceMappingURL=index.d.ts.map

@@ -20,3 +20,3 @@ "use strict";

__exportStar(require("./cmd"), exports);
const backupsList = async ({ org, project, env, cluster }) => {
const backupsList = async ({ org, project, env, cluster, apiKey }) => {
const envAdminClient = await (0, getClient_1.getClient)({

@@ -27,2 +27,3 @@ org,

cluster,
apiKey,
});

@@ -29,0 +30,0 @@ const backups = await envAdminClient.call('based:backups-list');

@@ -1,2 +0,2 @@

export declare const backupsSelectCmd: ({ org, project, env, cluster }: {
export declare const backupsSelectCmd: ({ org, project, env, cluster, apiKey, }: {
org: any;

@@ -6,3 +6,4 @@ project: any;

cluster: any;
apiKey: any;
}) => Promise<void>;
//# sourceMappingURL=cmd.d.ts.map

@@ -30,3 +30,3 @@ "use strict";

const _1 = require(".");
const backupsSelectCmd = async ({ org, project, env, cluster }) => {
const backupsSelectCmd = async ({ org, project, env, cluster, apiKey, }) => {
const envAdminClient = await (0, getClient_1.getClient)({

@@ -37,2 +37,3 @@ org,

cluster,
apiKey,
});

@@ -39,0 +40,0 @@ const { backups } = (await envAdminClient.call('based:backups-list')) || {};

import { DB } from '../types';
export * from './cmd';
export declare const backupsSelect: ({ org, project, env, cluster, db, key, }: {
export declare const backupsSelect: ({ org, project, env, cluster, db, key, apiKey, }: {
org: string;

@@ -10,3 +10,4 @@ project: string;

key: string;
apiKey?: string;
}) => Promise<any>;
//# sourceMappingURL=index.d.ts.map

@@ -20,3 +20,9 @@ "use strict";

__exportStar(require("./cmd"), exports);
const backupsSelect = async ({ org, project, env, cluster, db, key, }) => {
const backupsSelect = async ({ org, project, env, cluster, db, key, apiKey, }) => {
let sAcc;
if (apiKey) {
sAcc = {
apiKey,
};
}
const envAdminClient = await (0, getClient_1.getClient)({

@@ -27,2 +33,3 @@ org,

cluster,
apiKey,
});

@@ -29,0 +36,0 @@ const result = await envAdminClient.call('based:backups-select', {

@@ -1,2 +0,2 @@

export declare const backupsUploadCmd: ({ org, project, env, cluster, name, file, }: {
export declare const backupsUploadCmd: ({ org, project, env, cluster, name, file, apiKey, }: {
org: any;

@@ -8,3 +8,4 @@ project: any;

file: any;
apiKey: any;
}) => Promise<void>;
//# sourceMappingURL=cmd.d.ts.map

@@ -14,3 +14,3 @@ "use strict";

const fs_extra_1 = require("fs-extra");
const backupsUploadCmd = async ({ org, project, env, cluster, name, file, }) => {
const backupsUploadCmd = async ({ org, project, env, cluster, name, file, apiKey, }) => {
const envAdminClient = await (0, getClient_1.getClient)({

@@ -21,2 +21,3 @@ org,

cluster,
apiKey,
});

@@ -66,5 +67,13 @@ const dbs = await envAdminClient.call('based:db-list');

}
return (0, _1.backupsUpload)({ org, project, env, cluster, db, file });
return (0, _1.backupsUpload)({
org,
project,
env,
cluster,
db,
file,
apiKey,
});
};
exports.backupsUploadCmd = backupsUploadCmd;
//# sourceMappingURL=cmd.js.map
export * from './cmd';
export declare const backupsUpload: ({ org, project, env, cluster, db, file, }: {
export declare const backupsUpload: ({ org, project, env, cluster, db, file, apiKey, }: {
org: any;

@@ -9,3 +9,4 @@ project: any;

file: any;
apiKey: any;
}) => Promise<void>;
//# sourceMappingURL=index.d.ts.map

@@ -21,3 +21,3 @@ "use strict";

__exportStar(require("./cmd"), exports);
const backupsUpload = async ({ org, project, env, cluster, db, file, }) => {
const backupsUpload = async ({ org, project, env, cluster, db, file, apiKey, }) => {
const envAdminClient = await (0, getClient_1.getClient)({

@@ -28,2 +28,3 @@ org,

cluster,
apiKey,
});

@@ -30,0 +31,0 @@ if (!(await (0, fs_extra_1.pathExists)(file))) {

@@ -1,10 +0,2 @@

export declare const deployCmd: ({ cluster, org, project, env, watch, schema: deploySchema, function: fnNames, }: {
cluster: any;
org: any;
project: any;
env: any;
watch: any;
schema: any;
function: any;
}) => Promise<void>;
export declare const deployCmd: (data: any) => Promise<void>;
//# sourceMappingURL=cmd.d.ts.map

@@ -8,3 +8,4 @@ "use strict";

const utils_1 = require("./utils");
const deployCmd = async ({ cluster, org, project, env, watch, schema: deploySchema, function: fnNames, }) => {
const deployCmd = async (data) => {
const { cluster, org, project, env, watch, force, apiKey, schema: deploySchema, function: fnNames, } = data;
const functions = [];

@@ -49,2 +50,4 @@ let schema;

deploySchema,
force,
apiKey,
update,

@@ -51,0 +54,0 @@ });

@@ -0,1 +1,2 @@

import { BasedClient } from '@based/client';
export * from './cmd';

@@ -12,5 +13,8 @@ type DeployOpts = {

deploySchema?: boolean;
force?: boolean;
apiKey?: string;
envAdminClient?: BasedClient;
update?: (message: string, type?: 'info' | 'log' | 'warn' | 'error') => void;
};
export declare const deploy: ({ org, project, env, cluster, watch, functions, fnNames, schema, deploySchema, update, }: DeployOpts) => Promise<void>;
export declare const deploy: ({ org, project, env, cluster, watch, functions, fnNames, schema, deploySchema, force, envAdminClient, apiKey, update, }: DeployOpts) => Promise<void>;
//# sourceMappingURL=index.d.ts.map

@@ -30,2 +30,3 @@ "use strict";

const opts_1 = __importDefault(require("@based/opts"));
const utils_3 = require("@saulx/utils");
const node_perf_hooks_1 = require("node:perf_hooks");

@@ -39,6 +40,6 @@ __exportStar(require("./cmd"), exports);

};
const deploy = async ({ org, project, env, cluster, watch, functions, fnNames, schema, deploySchema, update = () => { }, }) => {
const deploy = async ({ org, project, env, cluster, watch, functions, fnNames, schema, deploySchema, force = false, envAdminClient, apiKey, update = () => { }, }) => {
const execDir = process.cwd() + '/';
const [envAdminClient, envHubUrl] = await Promise.all([
(0, getClient_1.getClient)({
const envAdmin = envAdminClient ||
(await (0, getClient_1.getClient)({
org,

@@ -48,10 +49,10 @@ project,

cluster,
}),
(0, opts_1.default)({
org,
project,
env,
cluster,
}, true),
]);
apiKey,
}));
const envHubUrl = await (0, opts_1.default)({
org,
project,
env,
cluster,
}, true);
const envId = 'en' +

@@ -71,7 +72,30 @@ (0, hash_1.hashCompact)({

: { schema: schemaObj };
await envAdminClient.call('db:set-schema', payload);
await envAdmin.call('db:set-schema', payload);
update('👌 updated schema');
}, watch);
}
if (functions && (!deploySchema || (fnNames?.length && deploySchema))) {
if (functions?.length && (!deploySchema || fnNames?.length)) {
const { functions: existingFunctions } = (await envAdmin
.query('db', {
$db: 'config',
functions: {
id: true,
current: {
id: true,
config: true,
checksum: true,
},
$list: {
$find: {
$traverse: 'children',
$filter: {
$field: 'type',
$operator: '=',
$value: ['job', 'function'],
},
},
},
},
})
.get());
const concurrency = 10;

@@ -106,2 +130,8 @@ let i = 0;

}
const existing = existingFunctions.find((existingFunction) => existingFunction.current?.checksum === (0, hash_1.hash)(fn.text) &&
(0, utils_3.deepEqual)(existingFunction.current?.config, configObj));
if (!force && configObj.type !== 'app' && existing) {
console.info(' ', picocolors_1.default.dim(`${relFnDir} No changes. Skipping.`));
return;
}
const setFunction = async (checksum, configObj, size = 0) => {

@@ -115,3 +145,3 @@ if (configObj.type === 'authorize') {

}
const res = await envAdminClient.stream('based:set-function', {
const res = await envAdmin.stream('based:set-function', {
contents: fn.contents.buffer,

@@ -126,3 +156,3 @@ payload: {

try {
await envAdminClient.stream('based:set-sourcemap', {
await envAdmin.stream('based:set-sourcemap', {
contents: sourcemap.contents.buffer,

@@ -146,6 +176,7 @@ payload: {

update(`👷 ${relFnDir} ${picocolors_1.default.dim('building..')}`);
const publicPath = cluster === 'local'
? `http://localhost:1111/${envId}`
: `https://based-files-${cluster}.based.dev/${envId}`;
await (0, utils_2.bundleApp)({
publicPath: cluster === 'local'
? `http://localhost:1111/${envId}`
: `https://based-files-${cluster}.based.dev/${envId}`,
publicPath,
config: configObj,

@@ -161,8 +192,25 @@ watch,

const appParams = {};
files.forEach((file) => {
if (file.path === js.path) {
appParams.js = publicPath + file.path;
}
else if (file.path === css.path) {
appParams.css = publicPath + file.path;
}
else if (file.path === favicon.path) {
appParams.favicon = publicPath + file.path;
}
});
const checksum = (0, hash_1.hash)([fn.text, appParams]);
configObj.appParams = appParams;
const existing = existingFunctions.find((existingFunction) => existingFunction.current?.checksum === checksum);
if (!force && existing) {
console.info(' ', picocolors_1.default.dim(`${relFnDir} No changes. Skipping.`));
return;
}
let size = 0;
await Promise.all(files.map(async ({ path, contents }) => {
size += contents.length;
const fileName = path.substring(1);
const id = `fi${(0, hash_1.hashCompact)(fileName, 8)}`;
const { src: url } = await envAdminClient.stream('db:file-upload', {
const { src: url } = await envAdmin.stream('db:file-upload', {
contents: contents.buffer,

@@ -173,15 +221,4 @@ fileName,

});
if (path === js.path) {
appParams.js = url;
}
else if (path === css.path) {
appParams.css = url;
}
else if (path === favicon.path) {
appParams.favicon = url;
}
return { path, url };
}));
const checksum = (0, hash_1.hash)([fn.text, appParams]);
configObj.appParams = appParams;
await setFunction(checksum, configObj, size);

@@ -202,4 +239,5 @@ });

}
else {
envAdminClient.destroy();
else if (!envAdminClient) {
// if client is passed don't destroy it
envAdmin.destroy();
}

@@ -206,0 +244,0 @@ };

@@ -27,3 +27,3 @@ "use strict";

const edit = async (opts) => {
const { org, project, env, cluster, id, language, db, editor } = opts;
const { org, project, env, cluster, id, language, db, editor, apiKey } = opts;
const envAdminClient = await (0, getClient_1.getClient)({

@@ -34,2 +34,3 @@ org,

cluster,
apiKey,
});

@@ -36,0 +37,0 @@ const q = { $id: id, $all: true };

export * from './cmd';
export declare const query: ({ org, project, env, cluster, watch, id, type, language, fields, limit, name, db, }: {
export declare const query: ({ org, project, env, cluster, watch, id, type, language, fields, limit, name, db, apiKey, }: {
org: any;

@@ -15,3 +15,4 @@ project: any;

db: any;
apiKey: any;
}) => Promise<void>;
//# sourceMappingURL=index.d.ts.map

@@ -42,3 +42,3 @@ "use strict";

};
const query = async ({ org, project, env, cluster, watch, id, type, language, fields, limit, name, db, }) => {
const query = async ({ org, project, env, cluster, watch, id, type, language, fields, limit, name, db, apiKey, }) => {
let q;

@@ -86,2 +86,3 @@ let handler = (res) => console.info((0, util_1.inspect)(res, { showHidden: false, depth: null, colors: true }));

cluster,
apiKey,
});

@@ -88,0 +89,0 @@ if (language) {

@@ -57,2 +57,3 @@ "use strict";

.option('-w, --watch', 'watch for changes', false)
.option('-f, --force', 'force deploy unchanged', false)
.action(cmds.deployCmd);

@@ -125,2 +126,6 @@ const dev = commander_1.program.command('dev');

.action(cmds.backupsFlushCmd);
backups
.command('make')
.description('Backup current environment state')
.action(cmds.backupsMakeCmd);
commander_1.program

@@ -159,3 +164,4 @@ .command('init')

.requiredOption('-p, --project <project>', 'project', basedJson?.project)
.requiredOption('-e, --env <env>', 'env', basedJson?.env);
.requiredOption('-e, --env <env>', 'env', basedJson?.env)
.option('--api-key <api-key>', 'API key for service account');
}

@@ -162,0 +168,0 @@ });

@@ -1,2 +0,4 @@

export declare const getClient: ({ org, project, env, adminHub, cluster, }: {
import { BasedClient } from '@based/client';
export declare const getClient: ({ cluster, org, project, env, adminHub, apiKey, silent, }: {
cluster: string;
org?: string;

@@ -6,4 +8,5 @@ project?: string;

adminHub?: boolean;
cluster: string;
}) => Promise<import("@based/client").BasedClient>;
apiKey?: string;
silent?: boolean;
}) => Promise<BasedClient>;
//# sourceMappingURL=getClient.d.ts.map

@@ -15,3 +15,3 @@ "use strict";

const opts_1 = __importDefault(require("@based/opts"));
const getClient = async ({ org, project, env, adminHub = false, cluster, }) => {
const getClient = async ({ cluster, org, project, env, adminHub = false, apiKey, silent = false, }) => {
const adminHubConfig = {

@@ -46,3 +46,5 @@ org: 'saulx',

client.once('connect', async () => {
console.info(`Based Cli v${(await (0, getPackage_1.getPackage)()).version} connected`);
if (!silent) {
console.info(`Based Cli v${(await (0, getPackage_1.getPackage)()).version} connected`);
}
clearTimeout(timeout);

@@ -52,2 +54,15 @@ resolve(true);

});
if (!apiKey) {
return userClient(client, cluster, adminHub, adminHubConfig, clusterInfo, envInfo, silent);
}
else {
await client.setAuthState({
token: apiKey,
type: 'serviceAccount',
});
return client;
}
};
exports.getClient = getClient;
async function userClient(client, cluster, adminHub, adminHubConfig, clusterInfo, envInfo, silent = false) {
client.on('authstate-change', (authState) => {

@@ -97,8 +112,9 @@ (0, fs_extra_1.outputFile)((0, node_path_1.join)(_1.persistentStorage, cluster), JSON.stringify(authState));

}
console.info(`Logged in as ${picocolors_1.default.blue(email)} to${clusterInfo}${envInfo}\n`);
if (!silent) {
console.info(`Logged in as ${picocolors_1.default.blue(email)} to${clusterInfo}${envInfo}\n`);
}
}
catch (error) { }
return client;
};
exports.getClient = getClient;
}
//# sourceMappingURL=getClient.js.map

@@ -12,2 +12,3 @@ export * from './bundle';

export declare const discoverUrlToRestUrl: (discoverUrl: string) => string;
export declare const isCurrentDumpKey: (key: string) => boolean;
//# sourceMappingURL=index.d.ts.map

@@ -17,3 +17,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.discoverUrlToRestUrl = exports.getHostAndPortFromUrl = exports.persistentStorage = void 0;
exports.isCurrentDumpKey = exports.discoverUrlToRestUrl = exports.getHostAndPortFromUrl = exports.persistentStorage = void 0;
const node_os_1 = require("node:os");

@@ -39,2 +39,4 @@ const node_path_1 = require("node:path");

exports.discoverUrlToRestUrl = discoverUrlToRestUrl;
const isCurrentDumpKey = (key) => /\/current-dump.rdb$/.test(key);
exports.isCurrentDumpKey = isCurrentDumpKey;
//# sourceMappingURL=index.js.map
{
"name": "@based/cli",
"version": "5.8.0",
"version": "5.9.0",
"description": "",
"bin": "bin/cmd.js",
"scripts": {
"test": "npx ava",
"test": "npx ava --verbose --timeout 3m",
"build": "node ../../tsconfigure.js && npx tsc -b -v",

@@ -27,3 +27,3 @@ "watch": "npm run build -- --watch"

"dependencies": {
"@based/client": "4.8.5",
"@based/client": "4.8.7",
"@based/server": "6.9.0",

@@ -55,2 +55,3 @@ "@esbuild-plugins/node-globals-polyfill": "^0.2.3",

"@based/opts": "0.6.0",
"@saulx/utils": "^3.4.2",
"escape-html": "1.0.3"

@@ -57,0 +58,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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