kinde-cli
Version:
Kinde cli for managing your business integration, users, roles and permissions etc
224 lines (223 loc) • 9.49 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const axios_1 = require("../lib/axios");
const context_1 = __importDefault(require("../lib/context"));
const error_1 = require("../utils/error");
const prompts_1 = require("@clack/prompts");
const querystring_1 = __importDefault(require("querystring"));
const picocolors_1 = __importDefault(require("picocolors"));
const utils_1 = require("../utils");
const command = {
BUSINESS_NAME: {
identifier: "Business Name",
desc: "Business Name eg paystack",
attr: "required",
},
PRIMARY_EMAIL: {
identifier: "Primary Email",
desc: "Email associated with business.",
attr: "required",
},
PRIMARY_PHONE: {
identifier: "Primary Phone",
desc: "Phone number associated with business.",
attr: "optional",
},
INDUSTRY_KEY: {
identifier: "Industry Key",
desc: "The key of the industry your business is in.",
attr: "optional",
},
TIMEZONE_ID: {
identifier: "Timezone Id",
desc: "The ID of the timezone your business is in.",
attr: "optional",
},
PRIVACY_URL: {
identifier: "Privacy Url",
desc: "Your Privacy policy URL.",
attr: "optional",
},
TERMS_URL: {
identifier: "Terms Url",
desc: "Your Terms and Conditions URL.",
attr: "optional",
},
IS_SHOW_KINDE_BRANDING: {
identifier: "Show Kinde Branding",
desc: "Display 'Powered by Kinde' branding",
attr: "optional",
},
IS_CLICK_WRAP: {
identifier: "Show Policy",
desc: "Show a policy acceptance checkbox on sign up.",
attr: "optional",
},
PARTNER_CODE: {
identifier: "Partner Code",
desc: "Your Kinde Perk code.",
attr: "optional",
},
};
class Business {
constructor(program) {
this.program = program;
this.handleBusiness();
}
handleBusiness() {
let program = this.program;
program
.command("business")
.description(picocolors_1.default.blue("Manage your Business details."))
.action((0, utils_1.errorHandler)("Auth", (str, options) => __awaiter(this, void 0, void 0, function* () {
let context = context_1.default.getData();
let prompt = (yield (0, prompts_1.select)({
message: "Proceed with appropriate action",
options: [
{
label: "List Business Details",
value: "list",
},
{
label: "Update Business Details",
value: "update",
},
],
}));
if (prompt === "list") {
let response = yield (0, axios_1.axiosRequest)({
path: `${context.normalDomain}/api/v1/business`,
method: "GET",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
Authorization: `Bearer ${context.token.access_token}`,
},
});
return (0, error_1.prettifyAxios)(response);
}
if (prompt === "update") {
let updateBusinessData = yield this.__updateBusinessDetailsPrompts();
let stringify = querystring_1.default.stringify((0, utils_1.filterUndefined)(updateBusinessData));
let response = yield (0, axios_1.axiosRequest)({
path: `${context.normalDomain}/api/v1/business?${stringify}`,
method: "PATCH",
headers: {
Accept: "application/json",
Authorization: `Bearer ${context.token.access_token}`,
},
});
return (0, error_1.prettifyAxios)(response);
}
})));
}
__updateBusinessDetailsPrompts() {
return __awaiter(this, void 0, void 0, function* () {
let values = yield (0, prompts_1.group)({
business_name: () => (0, prompts_1.text)({
message: (0, utils_1.generateMessage)({
identifier: command.BUSINESS_NAME.identifier,
desc: command.BUSINESS_NAME.desc,
attr: command.BUSINESS_NAME.attr,
}),
validate(value) {
if (!value)
return "Business name is required";
},
}),
email: () => (0, prompts_1.text)({
message: (0, utils_1.generateMessage)({
identifier: command.PRIMARY_EMAIL.identifier,
desc: command.PRIMARY_EMAIL.desc,
attr: command.PRIMARY_EMAIL.attr,
}),
validate(value) {
if (!value)
return "Business email is required";
},
}),
primary_phone: () => (0, prompts_1.text)({
message: (0, utils_1.generateMessage)({
identifier: command.PRIMARY_PHONE.identifier,
desc: command.PRIMARY_PHONE.desc,
attr: command.PRIMARY_PHONE.attr,
}),
defaultValue: undefined,
}),
industry_key: () => (0, prompts_1.text)({
message: (0, utils_1.generateMessage)({
identifier: command.INDUSTRY_KEY.identifier,
desc: command.INDUSTRY_KEY.desc,
attr: command.INDUSTRY_KEY.attr,
}),
defaultValue: undefined,
}),
timezone_id: () => (0, prompts_1.text)({
message: (0, utils_1.generateMessage)({
identifier: command.TIMEZONE_ID.identifier,
desc: command.TIMEZONE_ID.desc,
attr: command.TIMEZONE_ID.attr,
}),
defaultValue: undefined,
}),
privacy_url: () => (0, prompts_1.text)({
message: (0, utils_1.generateMessage)({
identifier: command.PRIVACY_URL.identifier,
desc: command.PRIVACY_URL.desc,
attr: command.PRIVACY_URL.attr,
}),
defaultValue: undefined,
}),
terms_url: () => (0, prompts_1.text)({
message: (0, utils_1.generateMessage)({
identifier: command.TERMS_URL.identifier,
desc: command.TERMS_URL.desc,
attr: command.TERMS_URL.attr,
}),
defaultValue: undefined,
}),
is_show_kinde_branding: () => (0, prompts_1.text)({
message: (0, utils_1.generateMessage)({
identifier: command.IS_SHOW_KINDE_BRANDING.identifier,
desc: command.IS_SHOW_KINDE_BRANDING.desc,
attr: command.IS_SHOW_KINDE_BRANDING.attr,
}),
defaultValue: undefined,
}),
is_click_wrap: () => (0, prompts_1.text)({
message: (0, utils_1.generateMessage)({
identifier: command.IS_CLICK_WRAP.identifier,
desc: command.IS_CLICK_WRAP.desc,
attr: command.IS_CLICK_WRAP.attr,
}),
validate(value) {
if (value !== "true" && value !== "false")
return "Value should be true or false";
},
}),
partner_code: () => (0, prompts_1.text)({
message: (0, utils_1.generateMessage)({
identifier: command.PARTNER_CODE.identifier,
desc: command.PARTNER_CODE.desc,
attr: command.PARTNER_CODE.attr,
}),
defaultValue: undefined,
}),
}, utils_1.onCancelCallback);
return values;
});
}
}
exports.default = Business;