convex
Version:
Client for the Convex Cloud
169 lines (168 loc) • 6.64 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var auth_exports = {};
__export(auth_exports, {
auth: () => auth
});
module.exports = __toCommonJS(auth_exports);
var import_commander = require("commander");
var import_config = require("./lib/config.js");
var import_inquirer = __toESM(require("inquirer"));
var import_chalk = __toESM(require("chalk"));
var import_context = require("./lib/context.js");
var import_auth = require("./lib/auth.js");
const list = new import_commander.Command("list").description("List the currently-configured identity providers").action(async () => {
const { projectConfig } = await (0, import_config.readProjectConfig)(import_context.oneoffContext);
const auth2 = projectConfig.authInfo;
for (let i = 0; i < auth2.length; i++) {
console.log(
`${i + 1}. Issuer: "${auth2[i].domain}", Application ID: "${auth2[i].applicationID}"`
);
}
});
const rm = new import_commander.Command("remove").description("Remove one or more identity providers from the config").action(async (_, command) => {
const ctx = import_context.oneoffContext;
const options = command.parent.opts();
const { projectConfig } = await (0, import_config.readProjectConfig)(ctx);
const auth2 = projectConfig.authInfo;
if (auth2.length == 0) {
console.log(
import_chalk.default.yellow("No identity providers configured -- nothing to remove.")
);
return;
}
const answers = await import_inquirer.default.prompt([
{
type: "checkbox",
message: "Choose which provider(s) to delete:",
choices: auth2.map((info) => {
return {
name: `Issuer: "${info.domain}", Application ID: "${info.applicationID}"`,
value: info
};
}),
name: "providers"
}
]);
const toRemove = answers.providers ?? [];
if (toRemove.length == 0) {
console.log(import_chalk.default.green("No providers selected for removal."));
return;
}
const newAuth = auth2.filter((oldInfo) => toRemove.indexOf(oldInfo) < 0);
if (options.verbose) {
console.log(
import_chalk.default.bold(
`Removing ${toRemove.length} identity provider(s). After this operation, the following provider(s) will remain:`
)
);
for (let i = 0; i < newAuth.length; i++) {
console.log(
`${i + 1}. Issuer: "${newAuth[i].domain}", Application ID: "${newAuth[i].applicationID}"`
);
}
await import_inquirer.default.prompt(["Press enter to continue or ctrl-C to abort.\n"]);
}
const newConfig = projectConfig;
newConfig.authInfo = newAuth;
await (0, import_config.writeProjectConfig)(ctx, newConfig);
console.log(
import_chalk.default.green(
"Configuration updated. Run `npx convex dev` or `npx convex deploy to sync these changes."
)
);
});
const add = new import_commander.Command("add").description("Add an identity provider to the config").addOption(new import_commander.Option("--identity-provider-url <url>").hideHelp()).addOption(new import_commander.Option("--application-id <applicationId>").hideHelp()).action(async (options, command) => {
const ctx = import_context.oneoffContext;
const verbose = command.parent.opts().verbose;
const { projectConfig } = await (0, import_config.readProjectConfig)(ctx);
const newProviders = [];
async function ask() {
await import_inquirer.default.prompt([
{
type: "input",
name: "domain",
message: "Enter the identity provider's Domain URL, (e.g. `{your auth0 domain}.us.auth0.com`):",
filter: import_auth.validateIdentityProviderURL
},
{
type: "input",
name: "applicationID",
message: "Enter your application/client ID with this identity provider:",
validate: (id) => {
if (id.startsWith('"')) {
return "Client ID should not be quoted";
}
return true;
}
},
{
type: "confirm",
name: "anotherOne",
message: "Would you like to add another provider?",
default: false
}
]).then(async (answers) => {
newProviders.push({
domain: answers.domain,
applicationID: answers.applicationID
});
if (answers.anotherOne) {
await ask();
}
});
}
if (options.identityProviderUrl && options.applicationId) {
newProviders.push({
domain: options.identityProviderUrl,
applicationID: options.applicationId
});
} else {
await ask();
}
if (newProviders.length == 0) {
console.log(import_chalk.default.yellow("No providers added; nothing to do."));
return;
}
if (verbose) {
console.log(import_chalk.default.bold("Will add the following identity providers:"));
for (let i = 0; i < newProviders.length; i++) {
console.log(
`${i + 1}. Issuer: "${newProviders[i].domain}", Application ID: "${newProviders[i].applicationID}"`
);
}
await import_inquirer.default.prompt(["Press enter to continue or ctrl-C to abort.\n"]);
}
const config = projectConfig;
config.authInfo.push(...newProviders);
await (0, import_config.writeProjectConfig)(ctx, config);
console.log(
import_chalk.default.green(
"Configuration updated. Run `npx convex dev` or `npx convex deploy to sync these changes."
)
);
});
const auth = new import_commander.Command("auth").description("Modify the authentication settings for your Convex project").option("-v, --verbose", "Show changes and prompt for confirmation").addCommand(list).addCommand(rm).addCommand(add);
//# sourceMappingURL=auth.js.map