@basis-theory-labs/cli 1.5.1 → 1.6.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.5.1 linux-x64 node-v18.16.1
22
+ @basis-theory-labs/cli/1.6.0 linux-x64 node-v18.16.1
23
23
  $ bt --help [COMMAND]
24
24
  USAGE
25
25
  $ bt COMMAND
@@ -55,7 +55,7 @@ EXAMPLES
55
55
  $ bt proxies
56
56
  ```
57
57
 
58
- _See code: [dist/commands/proxies/index.ts](https://github.com/Basis-Theory-Labs/basistheory-cli/blob/v1.5.1/dist/commands/proxies/index.ts)_
58
+ _See code: [dist/commands/proxies/index.ts](https://github.com/Basis-Theory-Labs/basistheory-cli/blob/v1.6.0/dist/commands/proxies/index.ts)_
59
59
 
60
60
  ## `bt proxies create`
61
61
 
@@ -138,7 +138,7 @@ Updates an existing Pre-Configured Proxy. Requires `proxy:update` Management App
138
138
  ```
139
139
  USAGE
140
140
  $ bt proxies update ID -x <value> [-n <value>] [-u <value>] [-q <value>] [-s <value>] [-i <value>] [-c <value>]
141
- [-a] [-w]
141
+ [-a] [-w] [-l]
142
142
 
143
143
  ARGUMENTS
144
144
  ID Proxy id to update
@@ -148,6 +148,7 @@ FLAGS
148
148
  true
149
149
  -c, --configuration=<value> path to configuration file (.env format) to use in the Proxy
150
150
  -i, --application-id=<value> application ID to use in the Proxy
151
+ -l, --logs Start logs server after update
151
152
  -n, --name=<value> name of the Proxy
152
153
  -q, --request-transform-code=<value> path to JavaScript file containing a Request Transform code
153
154
  -s, --response-transform-code=<value> path to JavaScript file containing a Response Transform code
@@ -187,7 +188,7 @@ EXAMPLES
187
188
  $ bt reactors
188
189
  ```
189
190
 
190
- _See code: [dist/commands/reactors/index.ts](https://github.com/Basis-Theory-Labs/basistheory-cli/blob/v1.5.1/dist/commands/reactors/index.ts)_
191
+ _See code: [dist/commands/reactors/index.ts](https://github.com/Basis-Theory-Labs/basistheory-cli/blob/v1.6.0/dist/commands/reactors/index.ts)_
191
192
 
192
193
  ## `bt reactors logs [ID]`
193
194
 
package/dist/base.d.ts CHANGED
@@ -3,10 +3,11 @@ import { Command } from '@oclif/core';
3
3
  import type { ArgOutput, FlagOutput, Input, ParserOutput } from '@oclif/core/lib/interfaces/parser';
4
4
  export declare abstract class BaseCommand extends Command {
5
5
  static baseFlags: {
6
- 'management-key': import("@oclif/core/lib/interfaces/parser").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
7
- 'api-base-url': import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
6
+ 'management-key': import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
7
+ 'api-base-url': import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
8
8
  };
9
9
  protected parse<F extends FlagOutput, B extends FlagOutput, A extends ArgOutput>(options?: Input<F, B, A>, argv?: string[]): Promise<ParserOutput<F, B, A> & {
10
10
  bt: IBasisTheory;
11
11
  }>;
12
+ protected catch(err: unknown): Promise<unknown>;
12
13
  }
package/dist/base.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BaseCommand = void 0;
4
4
  const basis_theory_js_1 = require("@basis-theory/basis-theory-js");
5
+ const common_1 = require("@basis-theory/basis-theory-js/common");
5
6
  const core_1 = require("@oclif/core");
6
7
  class BaseCommand extends core_1.Command {
7
8
  async parse(options, argv) {
@@ -24,6 +25,12 @@ class BaseCommand extends core_1.Command {
24
25
  bt,
25
26
  };
26
27
  }
28
+ catch(err) {
29
+ if (err instanceof common_1.BasisTheoryApiError) {
30
+ this.logJson(err.data);
31
+ }
32
+ return super.catch(err);
33
+ }
27
34
  }
28
35
  exports.BaseCommand = BaseCommand;
29
36
  BaseCommand.baseFlags = {
@@ -28,14 +28,10 @@ class Proxies extends base_1.BaseCommand {
28
28
  name: 'Delete',
29
29
  value: 'delete',
30
30
  },
31
- {
32
- name: 'Exit',
33
- value: 'exit',
34
- },
35
31
  ],
36
32
  });
37
33
  if (action === 'details') {
38
- this.log(JSON.stringify(proxy, undefined, 2));
34
+ this.logJson(proxy);
39
35
  return undefined;
40
36
  }
41
37
  if (action === 'logs') {
@@ -5,6 +5,7 @@ export default class Update extends BaseCommand {
5
5
  static examples: string[];
6
6
  static flags: {
7
7
  watch: import("@oclif/core/lib/interfaces/parser").BooleanFlag<boolean>;
8
+ logs: import("@oclif/core/lib/interfaces/parser").BooleanFlag<boolean>;
8
9
  name: import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
9
10
  'destination-url': import("@oclif/core/lib/interfaces/parser").OptionFlag<import("url").URL | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
10
11
  'request-transform-code': import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
@@ -3,12 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const core_1 = require("@oclif/core");
4
4
  const base_1 = require("../../base");
5
5
  const files_1 = require("../../files");
6
+ const logs_1 = require("../../logs");
6
7
  const management_1 = require("../../proxies/management");
7
8
  const utils_1 = require("../../proxies/utils");
8
9
  class Update extends base_1.BaseCommand {
9
10
  async run() {
10
11
  var _a, _b;
11
- const { bt, args: { id }, flags: { name, 'destination-url': destinationUrl, 'response-transform-code': responseTransformCode, 'request-transform-code': requestTransformCode, 'application-id': applicationId, configuration, 'require-auth': requireAuth, watch, }, metadata, } = await this.parse(Update);
12
+ const { bt, args: { id }, flags: { name, 'destination-url': destinationUrl, 'response-transform-code': responseTransformCode, 'request-transform-code': requestTransformCode, 'application-id': applicationId, configuration, 'require-auth': requireAuth, watch, logs, }, metadata, } = await this.parse(Update);
12
13
  const model = (0, utils_1.createModelFromFlags)({
13
14
  name,
14
15
  destinationUrl: destinationUrl === null || destinationUrl === void 0 ? void 0 : destinationUrl.toString(),
@@ -22,20 +23,24 @@ class Update extends base_1.BaseCommand {
22
23
  });
23
24
  await (0, management_1.patchProxy)(bt, id, model);
24
25
  this.log('Proxy updated successfully!');
26
+ if (logs) {
27
+ await (0, logs_1.showProxyLogs)(bt, id);
28
+ }
25
29
  if (watch) {
26
- const files = [
30
+ const entries = Object.entries({
27
31
  requestTransformCode,
28
32
  responseTransformCode,
29
33
  configuration,
30
- ].filter((flag) => flag);
34
+ }).filter(([, value]) => Boolean(value));
35
+ const files = entries.reduce((arr, [, file]) => [...arr, file], []);
31
36
  if (files.length) {
32
37
  this.log(`Watching files for changes: ${files.join(', ')} `);
33
38
  }
34
- files.forEach((file) => {
39
+ entries.forEach(([prop, file]) => {
35
40
  (0, files_1.watchForChanges)(file, async () => {
36
41
  core_1.ux.action.start(`Detected change in ${file}. Pushing changes`);
37
42
  await (0, management_1.patchProxy)(bt, id, (0, utils_1.createModelFromFlags)({
38
- responseTransformCode,
43
+ [prop]: file,
39
44
  }));
40
45
  core_1.ux.action.stop('✅\t');
41
46
  });
@@ -59,6 +64,12 @@ Update.flags = {
59
64
  default: false,
60
65
  required: false,
61
66
  }),
67
+ logs: core_1.Flags.boolean({
68
+ char: 'l',
69
+ description: 'Start logs server after update',
70
+ default: false,
71
+ required: false,
72
+ }),
62
73
  };
63
74
  Update.args = {
64
75
  id: core_1.Args.string({
@@ -24,14 +24,10 @@ class Reactors extends base_1.BaseCommand {
24
24
  value: 'logs',
25
25
  description: 'See Reactor real-time logs',
26
26
  },
27
- {
28
- name: 'Exit',
29
- value: 'exit',
30
- },
31
27
  ],
32
28
  });
33
29
  if (action === 'details') {
34
- this.log(JSON.stringify(reactor, undefined, 2));
30
+ this.logJson(reactor);
35
31
  return undefined;
36
32
  }
37
33
  if (action === 'logs') {
@@ -1,2 +1,2 @@
1
- declare const createLogServer: (port: number) => Promise<string>;
1
+ declare const createLogServer: (_port: number) => Promise<string>;
2
2
  export { createLogServer };
@@ -4,6 +4,7 @@ exports.createLogServer = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const core_1 = require("@oclif/core");
6
6
  const cloudflared_1 = require("cloudflared");
7
+ const detect_port_1 = tslib_1.__importDefault(require("detect-port"));
7
8
  const fs = tslib_1.__importStar(require("node:fs"));
8
9
  const pino_1 = tslib_1.__importDefault(require("pino"));
9
10
  const http_1 = require("./http");
@@ -21,7 +22,11 @@ const runTunnel = async (port) => {
21
22
  debug(`tunnel started at ${url}`);
22
23
  return url;
23
24
  };
24
- const createLogServer = async (port) => {
25
+ const createLogServer = async (_port) => {
26
+ const port = await (0, detect_port_1.default)(_port);
27
+ if (port !== _port) {
28
+ core_1.ux.log(`Port ${_port} was occupied, using port ${port}.`);
29
+ }
25
30
  core_1.ux.action.start('Starting log server');
26
31
  const logger = (0, pino_1.default)({
27
32
  transport: {
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.5.1",
2
+ "version": "1.6.0",
3
3
  "commands": {
4
4
  "proxies:create": {
5
5
  "id": "proxies:create",
@@ -292,6 +292,14 @@
292
292
  "description": "Watch for changes in informed files",
293
293
  "required": false,
294
294
  "allowNo": false
295
+ },
296
+ "logs": {
297
+ "name": "logs",
298
+ "type": "boolean",
299
+ "char": "l",
300
+ "description": "Start logs server after update",
301
+ "required": false,
302
+ "allowNo": false
295
303
  }
296
304
  },
297
305
  "args": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@basis-theory-labs/cli",
3
- "version": "1.5.1",
3
+ "version": "1.6.0",
4
4
  "description": "Basis Theory CLI tool",
5
5
  "author": "Davi Aquino @djejaquino",
6
6
  "bin": {
@@ -27,6 +27,7 @@
27
27
  "@oclif/plugin-plugins": "^2.4.7",
28
28
  "cloudflared": "^0.4.0",
29
29
  "debug": "^4.3.4",
30
+ "detect-port": "^1.5.1",
30
31
  "dotenv": "^16.3.1",
31
32
  "fastify": "^4.19.2",
32
33
  "lodash.debounce": "^4.0.8",
@@ -46,6 +47,7 @@
46
47
  "@semantic-release/release-notes-generator": "^11.0.3",
47
48
  "@types/chai": "^4",
48
49
  "@types/debug": "^4.1.8",
50
+ "@types/detect-port": "^1.3.3",
49
51
  "@types/lodash.debounce": "^4.0.7",
50
52
  "@types/mocha": "^9.0.0",
51
53
  "@types/node": "^16.18.36",