@basis-theory-labs/cli 1.9.0 → 1.10.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.
package/README.md CHANGED
@@ -19,7 +19,7 @@ $ npm install -g @basis-theory-labs/cli
19
19
  $ bt COMMAND
20
20
  running command...
21
21
  $ bt (--version)
22
- @basis-theory-labs/cli/1.9.0 linux-x64 node-v18.18.2
22
+ @basis-theory-labs/cli/1.10.0 linux-x64 node-v18.19.0
23
23
  $ bt --help [COMMAND]
24
24
  USAGE
25
25
  $ bt COMMAND
@@ -64,7 +64,7 @@ EXAMPLES
64
64
  $ bt applications
65
65
  ```
66
66
 
67
- _See code: [dist/commands/applications/index.ts](https://github.com/Basis-Theory-Labs/basistheory-cli/blob/v1.9.0/dist/commands/applications/index.ts)_
67
+ _See code: [dist/commands/applications/index.ts](https://github.com/Basis-Theory-Labs/basistheory-cli/blob/v1.10.0/dist/commands/applications/index.ts)_
68
68
 
69
69
  ## `bt applications create`
70
70
 
@@ -72,7 +72,7 @@ Creates a new Application. Requires `application:create` Management Application
72
72
 
73
73
  ```
74
74
  USAGE
75
- $ bt applications create -x <value> [-n <value>] [-p <value>] [-t private|public|management]
75
+ $ bt applications create -x <value> [-n <value>] [-p <value>] [-t private|public|management] [-z <value>]
76
76
 
77
77
  FLAGS
78
78
  -n, --name=<value> name of the Application
@@ -80,6 +80,7 @@ FLAGS
80
80
  -t, --type=<option> type of the Application
81
81
  <options: private|public|management>
82
82
  -x, --management-key=<value> (required) management key used for connecting with the reactor / proxy
83
+ -z, --template=<value> template ID to create the application with
83
84
 
84
85
  DESCRIPTION
85
86
  Creates a new Application. Requires `application:create` Management Application permission
@@ -152,7 +153,7 @@ EXAMPLES
152
153
  $ bt proxies
153
154
  ```
154
155
 
155
- _See code: [dist/commands/proxies/index.ts](https://github.com/Basis-Theory-Labs/basistheory-cli/blob/v1.9.0/dist/commands/proxies/index.ts)_
156
+ _See code: [dist/commands/proxies/index.ts](https://github.com/Basis-Theory-Labs/basistheory-cli/blob/v1.10.0/dist/commands/proxies/index.ts)_
156
157
 
157
158
  ## `bt proxies create`
158
159
 
@@ -285,7 +286,7 @@ EXAMPLES
285
286
  $ bt reactorFormulas
286
287
  ```
287
288
 
288
- _See code: [dist/commands/reactorFormulas/index.ts](https://github.com/Basis-Theory-Labs/basistheory-cli/blob/v1.9.0/dist/commands/reactorFormulas/index.ts)_
289
+ _See code: [dist/commands/reactorFormulas/index.ts](https://github.com/Basis-Theory-Labs/basistheory-cli/blob/v1.10.0/dist/commands/reactorFormulas/index.ts)_
289
290
 
290
291
  ## `bt reactorFormulas update ID`
291
292
 
@@ -338,7 +339,7 @@ EXAMPLES
338
339
  $ bt reactors
339
340
  ```
340
341
 
341
- _See code: [dist/commands/reactors/index.ts](https://github.com/Basis-Theory-Labs/basistheory-cli/blob/v1.9.0/dist/commands/reactors/index.ts)_
342
+ _See code: [dist/commands/reactors/index.ts](https://github.com/Basis-Theory-Labs/basistheory-cli/blob/v1.10.0/dist/commands/reactors/index.ts)_
342
343
 
343
344
  ## `bt reactors create`
344
345
 
@@ -1,8 +1,11 @@
1
1
  import type { Application, ApplicationType, CreateApplication, Permission, UpdateApplication } from '@basis-theory/basis-theory-js/types/models';
2
+ import { ApplicationTemplate } from '@basis-theory/basis-theory-js/types/models/application-templates';
2
3
  import type { BasisTheory as IBasisTheory } from '@basis-theory/basis-theory-js/types/sdk';
3
4
  declare const listPermissions: (bt: IBasisTheory, type: ApplicationType) => Promise<Permission[]>;
4
5
  declare const selectApplication: (bt: IBasisTheory, page: number) => Promise<Application | undefined>;
5
6
  declare const createApplication: (bt: IBasisTheory, model: CreateApplication) => Promise<Application>;
6
7
  declare const updateApplication: (bt: IBasisTheory, id: string, model: UpdateApplication) => Promise<Application>;
7
8
  declare const deleteApplication: (bt: IBasisTheory, id: string, force?: boolean) => Promise<boolean>;
8
- export { listPermissions, createApplication, updateApplication, selectApplication, deleteApplication, };
9
+ declare const createApplicationFromTemplate: (bt: IBasisTheory, templateId: string) => Promise<Application>;
10
+ declare const promptTemplate: (bt: IBasisTheory) => Promise<ApplicationTemplate | undefined>;
11
+ export { listPermissions, createApplication, updateApplication, selectApplication, deleteApplication, createApplicationFromTemplate, promptTemplate, };
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.deleteApplication = exports.selectApplication = exports.updateApplication = exports.createApplication = exports.listPermissions = void 0;
3
+ exports.promptTemplate = exports.createApplicationFromTemplate = exports.deleteApplication = exports.selectApplication = exports.updateApplication = exports.createApplication = exports.listPermissions = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const confirm_1 = tslib_1.__importDefault(require("@inquirer/confirm"));
6
+ const select_1 = tslib_1.__importDefault(require("@inquirer/select"));
6
7
  const core_1 = require("@oclif/core");
8
+ const lodash_groupby_1 = tslib_1.__importDefault(require("lodash.groupby"));
7
9
  const utils_1 = require("../utils");
8
10
  const debug = require('debug')('applications:management');
9
11
  const listPermissions = (bt, type) => bt.permissions
@@ -90,3 +92,37 @@ const deleteApplication = async (bt, id, force = false) => {
90
92
  return true;
91
93
  };
92
94
  exports.deleteApplication = deleteApplication;
95
+ const createApplicationFromTemplate = async (bt, templateId) => {
96
+ const template = await bt.applicationTemplates.retrieve(templateId);
97
+ return createApplication(bt, {
98
+ name: template.name,
99
+ type: template.applicationType,
100
+ permissions: template.permissions,
101
+ rules: template.rules,
102
+ });
103
+ };
104
+ exports.createApplicationFromTemplate = createApplicationFromTemplate;
105
+ const promptTemplate = async (bt) => {
106
+ const useTemplate = await (0, confirm_1.default)({
107
+ message: 'Do you want to use an application template?',
108
+ });
109
+ if (!useTemplate) {
110
+ return undefined;
111
+ }
112
+ const templates = (0, lodash_groupby_1.default)(await bt.applicationTemplates.list(), 'templateType');
113
+ const type = await (0, select_1.default)({
114
+ message: 'Which template type do you want to use?',
115
+ choices: Object.keys(templates).map((t) => ({
116
+ value: t,
117
+ })),
118
+ });
119
+ return (0, select_1.default)({
120
+ message: 'Choose a template',
121
+ choices: templates[type].map((t) => ({
122
+ name: t.name,
123
+ value: t,
124
+ description: t.description,
125
+ })),
126
+ });
127
+ };
128
+ exports.promptTemplate = promptTemplate;
@@ -4,6 +4,7 @@ export default class Create extends BaseCommand {
4
4
  static examples: string[];
5
5
  static flags: {
6
6
  type: import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
7
+ template: import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
7
8
  name: import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
8
9
  permission: import("@oclif/core/lib/interfaces/parser").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
9
10
  };
@@ -9,30 +9,53 @@ const utils_2 = require("../../utils");
9
9
  class Create extends base_1.BaseCommand {
10
10
  async run() {
11
11
  const { flags, bt } = await this.parse(Create);
12
- const name = await (0, utils_2.promptStringIfUndefined)(flags.name, {
13
- message: 'What is the Application name?',
14
- validate: (value) => Boolean(value),
15
- });
16
- const type = (await (0, utils_2.promptSelectIfUndefined)(flags.type, {
17
- message: 'What is the Application type?',
18
- choices: models_1.APPLICATION_TYPES.map((t) => ({ value: t })),
19
- }));
20
- const available = await (0, management_1.listPermissions)(bt, type);
21
- const permissions = await (0, utils_2.promptCheckboxIfUndefined)(flags.permission, {
22
- message: 'Select the permissions for the Application',
23
- choices: available.map((p) => ({
24
- value: p.type,
25
- })),
26
- loop: false,
27
- });
28
- const { id, key } = await (0, management_1.createApplication)(bt, {
29
- name,
30
- type,
31
- permissions,
32
- });
12
+ let application;
13
+ if (flags.template) {
14
+ // template passed as flag
15
+ application = await (0, management_1.createApplicationFromTemplate)(bt, flags.template);
16
+ }
17
+ else {
18
+ let template;
19
+ let rules, permissions, type;
20
+ if (!flags.name && !flags.type && !flags.permission) {
21
+ // no other flags where passed, prompt template
22
+ template = await (0, management_1.promptTemplate)(bt);
23
+ }
24
+ const name = await (0, utils_2.promptStringIfUndefined)(flags.name, {
25
+ message: 'What is the Application name?',
26
+ default: template === null || template === void 0 ? void 0 : template.name,
27
+ validate: (value) => Boolean(value),
28
+ });
29
+ if (template) {
30
+ // template has been picked, so type and permissions/rules are defined
31
+ type = template.applicationType;
32
+ rules = template.rules;
33
+ permissions = template.permissions;
34
+ }
35
+ else {
36
+ type = (await (0, utils_2.promptSelectIfUndefined)(flags.type, {
37
+ message: 'What is the Application type?',
38
+ choices: models_1.APPLICATION_TYPES.map((t) => ({ value: t })),
39
+ }));
40
+ const available = await (0, management_1.listPermissions)(bt, type);
41
+ permissions = await (0, utils_2.promptCheckboxIfUndefined)(flags.permission, {
42
+ message: 'Select the permissions for the Application',
43
+ choices: available.map((p) => ({
44
+ value: p.type,
45
+ })),
46
+ loop: false,
47
+ });
48
+ }
49
+ application = await (0, management_1.createApplication)(bt, {
50
+ name,
51
+ type,
52
+ permissions,
53
+ rules,
54
+ });
55
+ }
33
56
  this.log('Application created successfully!');
34
- this.log(`id: ${id}`);
35
- this.log(`key: ${key}`);
57
+ this.log(`id: ${application.id}`);
58
+ this.log(`key: ${application.key}`);
36
59
  }
37
60
  }
38
61
  exports.default = Create;
@@ -45,4 +68,8 @@ Create.flags = {
45
68
  description: 'type of the Application',
46
69
  options: [...models_1.APPLICATION_TYPES],
47
70
  }),
71
+ template: core_1.Flags.string({
72
+ description: 'template ID to create the application with',
73
+ char: 'z',
74
+ }),
48
75
  };
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.9.0",
2
+ "version": "1.10.0",
3
3
  "commands": {
4
4
  "applications:create": {
5
5
  "id": "applications:create",
@@ -53,6 +53,13 @@
53
53
  "public",
54
54
  "management"
55
55
  ]
56
+ },
57
+ "template": {
58
+ "name": "template",
59
+ "type": "option",
60
+ "char": "z",
61
+ "description": "template ID to create the application with",
62
+ "multiple": false
56
63
  }
57
64
  },
58
65
  "args": {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@basis-theory-labs/cli",
3
- "version": "1.9.0",
3
+ "version": "1.10.0",
4
4
  "description": "Basis Theory CLI tool",
5
5
  "author": "Davi Aquino @djejaquino",
6
6
  "bin": {
@@ -17,7 +17,7 @@
17
17
  "/oclif.manifest.json"
18
18
  ],
19
19
  "dependencies": {
20
- "@basis-theory/basis-theory-js": "^2.4.0",
20
+ "@basis-theory/basis-theory-js": "^2.7.0",
21
21
  "@inquirer/checkbox": "^1.5.0",
22
22
  "@inquirer/confirm": "^2.0.15",
23
23
  "@inquirer/input": "^1.2.14",
@@ -31,6 +31,7 @@
31
31
  "dotenv": "^16.3.1",
32
32
  "fastify": "^4.19.2",
33
33
  "lodash.debounce": "^4.0.8",
34
+ "lodash.groupby": "^4.6.0",
34
35
  "pino": "^8.14.1",
35
36
  "pino-pretty": "^10.0.0",
36
37
  "serialize-error": "^11.0.0",
@@ -49,6 +50,7 @@
49
50
  "@types/debug": "^4.1.8",
50
51
  "@types/detect-port": "^1.3.3",
51
52
  "@types/lodash.debounce": "^4.0.7",
53
+ "@types/lodash.groupby": "^4.6.9",
52
54
  "@types/mocha": "^9.0.0",
53
55
  "@types/node": "^16.18.36",
54
56
  "chai": "^4",