@basis-theory-labs/cli 1.7.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,21 +5,22 @@ const base_1 = require("../../base");
5
5
  const management_1 = require("../../reactorFormulas/management");
6
6
  class ReactorFormulas extends base_1.BaseCommand {
7
7
  async run() {
8
+ this.log('WARNING: Reactor Formulas are being deprecated and will be removed in a future release.');
8
9
  const { bt, flags: { page }, } = await this.parse(ReactorFormulas);
9
- const reactor = await (0, management_1.selectReactorFormula)(bt, page);
10
- if (!reactor) {
10
+ const formula = await (0, management_1.selectReactorFormula)(bt, page);
11
+ if (!formula) {
11
12
  return undefined;
12
13
  }
13
14
  return undefined;
14
15
  }
15
16
  }
16
17
  exports.default = ReactorFormulas;
17
- ReactorFormulas.description = 'List Reactor Formulas. Requires `reactor:read` Management Application permission';
18
+ ReactorFormulas.description = '[Deprecated] List Reactor Formulas. Requires `reactor:read` Management Application permission';
18
19
  ReactorFormulas.examples = ['<%= config.bin %> <%= command.id %>'];
19
20
  ReactorFormulas.flags = {
20
21
  page: core_1.Flags.integer({
21
22
  char: 'p',
22
- description: 'reactors formulas list page to fetch',
23
+ description: 'Reactors formulas list page to fetch',
23
24
  default: 1,
24
25
  }),
25
26
  };
@@ -7,6 +7,7 @@ const management_1 = require("../../reactorFormulas/management");
7
7
  const utils_1 = require("../../reactorFormulas/utils");
8
8
  class Update extends base_1.BaseCommand {
9
9
  async run() {
10
+ this.log('WARNING: Reactor Formulas are being deprecated and will be removed in a future release.');
10
11
  const { bt, args: { id }, flags: { name, description, code, configuration = '', 'request-parameters': requestParameters = '', watch, }, } = await this.parse(Update);
11
12
  const model = (0, utils_1.createModelFromFlags)({
12
13
  name,
@@ -47,7 +48,7 @@ class Update extends base_1.BaseCommand {
47
48
  }
48
49
  }
49
50
  exports.default = Update;
50
- Update.description = 'Updates an existing Reactor Formula. Requires `reactor:update` Management Application permission';
51
+ Update.description = '[Deprecated] Updates an existing Reactor Formula. Requires `reactor:update` Management Application permission';
51
52
  Update.examples = [
52
53
  '<%= config.bin %> <%= command.id %> 03858bf5-32d3-4a2e-b74b-daeea0883bca',
53
54
  '<%= config.bin %> <%= command.id %> 03858bf5-32d3-4a2e-b74b-daeea0883bca --code ./formula.js',
@@ -0,0 +1,12 @@
1
+ import { BaseCommand } from '../../base';
2
+ export default class Create extends BaseCommand {
3
+ static description: string;
4
+ static examples: string[];
5
+ static flags: {
6
+ name: import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
7
+ configuration: import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
8
+ 'application-id': import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
9
+ code: import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
10
+ };
11
+ run(): Promise<void>;
12
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const base_1 = require("../../base");
4
+ const management_1 = require("../../reactors/management");
5
+ const utils_1 = require("../../reactors/utils");
6
+ const utils_2 = require("../../utils");
7
+ class Create extends base_1.BaseCommand {
8
+ async run() {
9
+ const { flags, bt } = await this.parse(Create);
10
+ const name = await (0, utils_2.promptStringIfUndefined)(flags.name, {
11
+ message: 'What is the Reactor name?',
12
+ validate: (value) => Boolean(value),
13
+ });
14
+ const code = await (0, utils_2.promptStringIfUndefined)(flags['code'], {
15
+ message: 'Enter the Reactor code file path:',
16
+ validate: (value) => Boolean(value),
17
+ });
18
+ const applicationId = await (0, utils_2.promptStringIfUndefined)(flags['application-id'], {
19
+ message: '(Optional) Enter the Application ID to use in the Reactor:',
20
+ });
21
+ const configuration = await (0, utils_2.promptStringIfUndefined)(flags.configuration, {
22
+ message: '(Optional) Enter the configuration file path (.env format):',
23
+ });
24
+ const model = (0, utils_1.createModelFromFlags)({
25
+ name,
26
+ code,
27
+ applicationId,
28
+ configuration,
29
+ });
30
+ const { id } = await (0, management_1.createReactor)(bt, model);
31
+ this.log('Reactor created successfully!');
32
+ this.log(`id: ${id}`);
33
+ }
34
+ }
35
+ exports.default = Create;
36
+ Create.description = 'Creates a new Reactor. Requires `reactor:create` Management Application permission';
37
+ Create.examples = ['<%= config.bin %> <%= command.id %> '];
38
+ Create.flags = {
39
+ ...utils_1.REACTOR_FLAGS,
40
+ };
@@ -0,0 +1,12 @@
1
+ import { BaseCommand } from '../../base';
2
+ export default class Delete extends BaseCommand {
3
+ static description: string;
4
+ static examples: string[];
5
+ static args: {
6
+ id: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
7
+ };
8
+ static flags: {
9
+ yes: import("@oclif/core/lib/interfaces/parser").BooleanFlag<boolean>;
10
+ };
11
+ run(): Promise<void>;
12
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@oclif/core");
4
+ const base_1 = require("../../base");
5
+ const management_1 = require("../../reactors/management");
6
+ class Delete extends base_1.BaseCommand {
7
+ async run() {
8
+ const { bt, flags: { yes }, args: { id }, } = await this.parse(Delete);
9
+ if (await (0, management_1.deleteReactor)(bt, id, yes)) {
10
+ this.log('Reactor deleted successfully!');
11
+ }
12
+ }
13
+ }
14
+ exports.default = Delete;
15
+ Delete.description = 'Deletes a Reactor. Requires `reactor:delete` Management Application permissions';
16
+ Delete.examples = [
17
+ '<%= config.bin %> <%= command.id %> 03858bf5-32d3-4a2e-b74b-daeea0883bca',
18
+ ];
19
+ Delete.args = {
20
+ id: core_1.Args.string({
21
+ description: 'Reactor id to delete',
22
+ required: true,
23
+ }),
24
+ };
25
+ Delete.flags = {
26
+ yes: core_1.Flags.boolean({
27
+ char: 'y',
28
+ description: 'auto confirm the operation',
29
+ default: false,
30
+ allowNo: false,
31
+ }),
32
+ };
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const prompts_1 = require("@inquirer/prompts");
3
+ const tslib_1 = require("tslib");
4
+ const select_1 = tslib_1.__importDefault(require("@inquirer/select"));
4
5
  const core_1 = require("@oclif/core");
5
6
  const base_1 = require("../../base");
6
7
  const logs_1 = require("../../logs");
@@ -12,7 +13,7 @@ class Reactors extends base_1.BaseCommand {
12
13
  if (!reactor) {
13
14
  return undefined;
14
15
  }
15
- const action = await (0, prompts_1.select)({
16
+ const action = await (0, select_1.default)({
16
17
  message: 'Select action to perform',
17
18
  choices: [
18
19
  {
@@ -24,6 +25,10 @@ class Reactors extends base_1.BaseCommand {
24
25
  value: 'logs',
25
26
  description: 'See Reactor real-time logs',
26
27
  },
28
+ {
29
+ name: 'Delete',
30
+ value: 'delete',
31
+ },
27
32
  ],
28
33
  });
29
34
  if (action === 'details') {
@@ -33,6 +38,9 @@ class Reactors extends base_1.BaseCommand {
33
38
  if (action === 'logs') {
34
39
  return (0, logs_1.showReactorLogs)(bt, reactor.id);
35
40
  }
41
+ if (action === 'delete' && (await (0, management_1.deleteReactor)(bt, reactor.id))) {
42
+ return this.log('Reactor deleted successfully!');
43
+ }
36
44
  return undefined;
37
45
  }
38
46
  }
@@ -42,7 +50,7 @@ Reactors.examples = ['<%= config.bin %> <%= command.id %>'];
42
50
  Reactors.flags = {
43
51
  page: core_1.Flags.integer({
44
52
  char: 'p',
45
- description: 'reactors list page to fetch',
53
+ description: 'Reactors list page to fetch',
46
54
  default: 1,
47
55
  }),
48
56
  };
@@ -0,0 +1,17 @@
1
+ import { BaseCommand } from '../../base';
2
+ export default class Update extends BaseCommand {
3
+ static description: string;
4
+ static examples: string[];
5
+ static flags: {
6
+ watch: import("@oclif/core/lib/interfaces/parser").BooleanFlag<boolean>;
7
+ logs: import("@oclif/core/lib/interfaces/parser").BooleanFlag<boolean>;
8
+ name: import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
9
+ configuration: import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
10
+ 'application-id': import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
11
+ code: import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
12
+ };
13
+ static args: {
14
+ id: import("@oclif/core/lib/interfaces/parser").Arg<string, Record<string, unknown>>;
15
+ };
16
+ run(): Promise<void>;
17
+ }
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const core_1 = require("@oclif/core");
4
+ const base_1 = require("../../base");
5
+ const files_1 = require("../../files");
6
+ const logs_1 = require("../../logs");
7
+ const management_1 = require("../../reactors/management");
8
+ const utils_1 = require("../../reactors/utils");
9
+ class Update extends base_1.BaseCommand {
10
+ async run() {
11
+ const { bt, args: { id }, flags: { name, code, 'application-id': applicationId, configuration, watch, logs, }, } = await this.parse(Update);
12
+ const model = (0, utils_1.createModelFromFlags)({
13
+ name,
14
+ code,
15
+ applicationId,
16
+ configuration,
17
+ });
18
+ await (0, management_1.patchReactor)(bt, id, model);
19
+ this.log('Reactor updated successfully!');
20
+ if (logs) {
21
+ await (0, logs_1.showReactorLogs)(bt, id);
22
+ }
23
+ if (watch) {
24
+ const entries = Object.entries({
25
+ code,
26
+ configuration,
27
+ }).filter(([, value]) => Boolean(value));
28
+ const files = entries.reduce((arr, [, file]) => [...arr, file], []);
29
+ if (files.length) {
30
+ this.log(`Watching files for changes: ${files.join(', ')} `);
31
+ }
32
+ entries.forEach(([prop, file]) => {
33
+ (0, files_1.watchForChanges)(file, async () => {
34
+ core_1.ux.action.start(`Detected change in ${file}. Pushing changes`);
35
+ await (0, management_1.patchReactor)(bt, id, (0, utils_1.createModelFromFlags)({
36
+ [prop]: file,
37
+ }));
38
+ core_1.ux.action.stop('✅\t');
39
+ });
40
+ });
41
+ }
42
+ }
43
+ }
44
+ exports.default = Update;
45
+ Update.description = 'Updates an existing Reactor. Requires `reactor:update` Management Application permission';
46
+ Update.examples = [
47
+ '<%= config.bin %> <%= command.id %> 03858bf5-32d3-4a2e-b74b-daeea0883bca',
48
+ '<%= config.bin %> <%= command.id %> 03858bf5-32d3-4a2e-b74b-daeea0883bca --code ./reactor.js',
49
+ '<%= config.bin %> <%= command.id %> 03858bf5-32d3-4a2e-b74b-daeea0883bca --configuration ./.env.reactor',
50
+ ];
51
+ Update.flags = {
52
+ ...utils_1.REACTOR_FLAGS,
53
+ watch: core_1.Flags.boolean({
54
+ char: 'w',
55
+ description: 'Watch for changes in informed files',
56
+ default: false,
57
+ required: false,
58
+ }),
59
+ logs: core_1.Flags.boolean({
60
+ char: 'l',
61
+ description: 'Start logs server after update',
62
+ default: false,
63
+ required: false,
64
+ }),
65
+ };
66
+ Update.args = {
67
+ id: core_1.Args.string({
68
+ description: 'Reactor id to update',
69
+ required: true,
70
+ }),
71
+ };
@@ -1,5 +1,7 @@
1
- import type { Reactor, PatchReactor } from '@basis-theory/basis-theory-js/types/models';
1
+ import type { Reactor, PatchReactor, CreateReactor } from '@basis-theory/basis-theory-js/types/models';
2
2
  import type { BasisTheory as IBasisTheory } from '@basis-theory/basis-theory-js/types/sdk';
3
3
  declare const selectReactor: (bt: IBasisTheory, page: number) => Promise<Reactor | undefined>;
4
+ declare const createReactor: (bt: IBasisTheory, model: CreateReactor) => Promise<Reactor>;
5
+ declare const deleteReactor: (bt: IBasisTheory, id: string, force?: boolean) => Promise<boolean>;
4
6
  declare const patchReactor: (bt: IBasisTheory, id: string, model: PatchReactor) => Promise<void>;
5
- export { selectReactor, patchReactor };
7
+ export { selectReactor, createReactor, patchReactor, deleteReactor };
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.patchReactor = exports.selectReactor = void 0;
3
+ exports.deleteReactor = exports.patchReactor = exports.createReactor = exports.selectReactor = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const confirm_1 = tslib_1.__importDefault(require("@inquirer/confirm"));
4
6
  const core_1 = require("@oclif/core");
5
7
  const utils_1 = require("../utils");
6
8
  const debug = require('debug')('reactors:management');
@@ -47,6 +49,26 @@ const selectReactor = async (bt, page) => {
47
49
  return selection;
48
50
  };
49
51
  exports.selectReactor = selectReactor;
52
+ const createReactor = (bt, model) => {
53
+ debug(`Creating Reactor`, JSON.stringify(model, undefined, 2));
54
+ return bt.reactors.create(model);
55
+ };
56
+ exports.createReactor = createReactor;
57
+ const deleteReactor = async (bt, id, force = false) => {
58
+ if (!force) {
59
+ const proceed = await (0, confirm_1.default)({
60
+ message: `Are you sure you want to delete this Reactor (${id})?`,
61
+ default: false,
62
+ });
63
+ if (!proceed) {
64
+ return false;
65
+ }
66
+ }
67
+ debug(`Deleting Reactor`, id);
68
+ await bt.reactors.delete(id);
69
+ return true;
70
+ };
71
+ exports.deleteReactor = deleteReactor;
50
72
  const patchReactor = (bt, id, model) => {
51
73
  debug(`Patching Reactor ${id}`, JSON.stringify(model, undefined, 2));
52
74
  return bt.reactors.patch(id, model);
@@ -0,0 +1,26 @@
1
+ import type { CreateReactor as CreateReactorModel, PatchReactor as PatchReactorModel } from '@basis-theory/basis-theory-js/types/models/reactors';
2
+ declare const REACTOR_FLAGS: {
3
+ name: import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
4
+ configuration: import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
5
+ 'application-id': import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
6
+ code: import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
7
+ };
8
+ interface ReactorFlagProps {
9
+ /**
10
+ * Reactor's application id
11
+ */
12
+ applicationId?: string;
13
+ /**
14
+ * Path to code file
15
+ */
16
+ code?: string;
17
+ /**
18
+ * Path to .env file
19
+ */
20
+ configuration?: string;
21
+ }
22
+ type CreateReactor = ReactorFlagProps & Omit<CreateReactorModel, 'application' | 'configuration'>;
23
+ type PatchReactor = ReactorFlagProps & Omit<PatchReactorModel, 'application' | 'configuration'>;
24
+ declare function createModelFromFlags(payload: CreateReactor): CreateReactorModel;
25
+ declare function createModelFromFlags(payload: PatchReactor): PatchReactorModel;
26
+ export { REACTOR_FLAGS, createModelFromFlags };
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createModelFromFlags = exports.REACTOR_FLAGS = void 0;
4
+ const core_1 = require("@oclif/core");
5
+ const dotenv_1 = require("dotenv");
6
+ const files_1 = require("../files");
7
+ const REACTOR_FLAGS = {
8
+ name: core_1.Flags.string({
9
+ char: 'n',
10
+ description: 'name of the Reactor',
11
+ }),
12
+ configuration: core_1.Flags.file({
13
+ char: 'c',
14
+ description: 'path to configuration file (.env format) to use in the Reactor',
15
+ }),
16
+ 'application-id': core_1.Flags.string({
17
+ char: 'i',
18
+ description: 'application ID to use in the Reactor',
19
+ }),
20
+ code: core_1.Flags.file({
21
+ char: 'r',
22
+ description: 'path to JavaScript file containing the Reactor code',
23
+ }),
24
+ };
25
+ exports.REACTOR_FLAGS = REACTOR_FLAGS;
26
+ // eslint-disable-next-line get-off-my-lawn/prefer-arrow-functions
27
+ function createModelFromFlags({ name, applicationId, code, configuration, }) {
28
+ return {
29
+ name,
30
+ code: code ? (0, files_1.readFileContents)(code) : undefined,
31
+ application: applicationId ? { id: applicationId } : undefined,
32
+ configuration: configuration
33
+ ? (0, dotenv_1.parse)((0, files_1.readFileContents)(configuration))
34
+ : undefined,
35
+ };
36
+ }
37
+ exports.createModelFromFlags = createModelFromFlags;
package/dist/utils.d.ts CHANGED
@@ -1,11 +1,15 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
3
  import { PaginatedList } from '@basis-theory/basis-theory-js/types/sdk';
4
+ import checkbox from '@inquirer/checkbox';
4
5
  import confirm from '@inquirer/confirm';
5
6
  import input from '@inquirer/input';
7
+ import select from '@inquirer/select';
6
8
  declare const selectOrNavigate: <T>(list: PaginatedList<T>, prop: string) => Promise<T | "previous" | "next">;
7
9
  declare const promptStringIfUndefined: (value: string | undefined, options: Parameters<typeof input>[0]) => Promise<string>;
10
+ declare const promptSelectIfUndefined: (value: string | undefined, options: Parameters<typeof select>[0]) => Promise<string>;
11
+ declare const promptCheckboxIfUndefined: (value: string[] | undefined, options: Parameters<typeof checkbox>[0]) => Promise<string[]>;
8
12
  declare const promptUrlIfUndefined: (value: URL | undefined, options: Parameters<typeof input>[0]) => Promise<URL>;
9
13
  declare const promptBooleanIfUndefined: (value: boolean | undefined, options: Parameters<typeof confirm>[0]) => Promise<boolean>;
10
14
  declare const cleanUpOnExit: (action: () => unknown) => typeof process;
11
- export { selectOrNavigate, promptStringIfUndefined, promptUrlIfUndefined, promptBooleanIfUndefined, cleanUpOnExit, };
15
+ export { selectOrNavigate, promptStringIfUndefined, promptSelectIfUndefined, promptCheckboxIfUndefined, promptUrlIfUndefined, promptBooleanIfUndefined, cleanUpOnExit, };
package/dist/utils.js CHANGED
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cleanUpOnExit = exports.promptBooleanIfUndefined = exports.promptUrlIfUndefined = exports.promptStringIfUndefined = exports.selectOrNavigate = void 0;
3
+ exports.cleanUpOnExit = exports.promptBooleanIfUndefined = exports.promptUrlIfUndefined = exports.promptCheckboxIfUndefined = exports.promptSelectIfUndefined = exports.promptStringIfUndefined = exports.selectOrNavigate = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ const checkbox_1 = tslib_1.__importDefault(require("@inquirer/checkbox"));
5
6
  const confirm_1 = tslib_1.__importDefault(require("@inquirer/confirm"));
6
7
  const input_1 = tslib_1.__importDefault(require("@inquirer/input"));
8
+ const select_1 = tslib_1.__importDefault(require("@inquirer/select"));
7
9
  const core_1 = require("@oclif/core");
8
10
  const selectOrNavigate = async (list, prop) => {
9
11
  const { data, pagination } = list;
@@ -40,6 +42,20 @@ const promptStringIfUndefined = (value, options) => {
40
42
  return (0, input_1.default)(options);
41
43
  };
42
44
  exports.promptStringIfUndefined = promptStringIfUndefined;
45
+ const promptSelectIfUndefined = (value, options) => {
46
+ if (value) {
47
+ return Promise.resolve(value);
48
+ }
49
+ return (0, select_1.default)(options);
50
+ };
51
+ exports.promptSelectIfUndefined = promptSelectIfUndefined;
52
+ const promptCheckboxIfUndefined = (value, options) => {
53
+ if (value) {
54
+ return Promise.resolve(value);
55
+ }
56
+ return (0, checkbox_1.default)(options);
57
+ };
58
+ exports.promptCheckboxIfUndefined = promptCheckboxIfUndefined;
43
59
  const promptUrlIfUndefined = async (value, options) => {
44
60
  if (value) {
45
61
  return Promise.resolve(value);