@basis-theory-labs/cli 1.3.0 → 1.3.2

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.3.0 linux-x64 node-v18.16.1
22
+ @basis-theory-labs/cli/1.3.2 linux-x64 node-v18.16.1
23
23
  $ bt --help [COMMAND]
24
24
  USAGE
25
25
  $ bt COMMAND
@@ -54,7 +54,7 @@ EXAMPLES
54
54
  $ bt proxies
55
55
  ```
56
56
 
57
- _See code: [dist/commands/proxies/index.ts](https://github.com/Basis-Theory-Labs/basistheory-cli/blob/v1.3.0/dist/commands/proxies/index.ts)_
57
+ _See code: [dist/commands/proxies/index.ts](https://github.com/Basis-Theory-Labs/basistheory-cli/blob/v1.3.2/dist/commands/proxies/index.ts)_
58
58
 
59
59
  ## `bt proxies create`
60
60
 
@@ -163,7 +163,7 @@ EXAMPLES
163
163
  $ bt reactors
164
164
  ```
165
165
 
166
- _See code: [dist/commands/reactors/index.ts](https://github.com/Basis-Theory-Labs/basistheory-cli/blob/v1.3.0/dist/commands/reactors/index.ts)_
166
+ _See code: [dist/commands/reactors/index.ts](https://github.com/Basis-Theory-Labs/basistheory-cli/blob/v1.3.2/dist/commands/reactors/index.ts)_
167
167
 
168
168
  ## `bt reactors logs [ID]`
169
169
 
@@ -9,6 +9,9 @@ class Proxies extends base_1.BaseCommand {
9
9
  async run() {
10
10
  const { flags: { page }, bt, } = await this.parse(Proxies);
11
11
  const proxy = await (0, management_1.selectProxy)(bt, page);
12
+ if (!proxy) {
13
+ return undefined;
14
+ }
12
15
  const action = await (0, prompts_1.select)({
13
16
  message: 'Select action to perform',
14
17
  choices: [
@@ -11,6 +11,9 @@ class Logs extends base_1.BaseCommand {
11
11
  return (0, logs_1.showProxyLogs)(bt, id, port);
12
12
  }
13
13
  const proxy = await (0, management_1.selectProxy)(bt, 1);
14
+ if (!proxy) {
15
+ return undefined;
16
+ }
14
17
  return (0, logs_1.showProxyLogs)(bt, proxy.id, port);
15
18
  }
16
19
  }
@@ -9,6 +9,9 @@ class Reactors extends base_1.BaseCommand {
9
9
  async run() {
10
10
  const { bt, flags: { page }, } = await this.parse(Reactors);
11
11
  const reactor = await (0, management_1.selectReactor)(bt, page);
12
+ if (!reactor) {
13
+ return undefined;
14
+ }
12
15
  const action = await (0, prompts_1.select)({
13
16
  message: 'Select action to perform',
14
17
  choices: [
@@ -11,6 +11,9 @@ class Logs extends base_1.BaseCommand {
11
11
  return (0, logs_1.showReactorLogs)(bt, id, port);
12
12
  }
13
13
  const reactor = await (0, management_1.selectReactor)(bt, 1);
14
+ if (!reactor) {
15
+ return undefined;
16
+ }
14
17
  return (0, logs_1.showReactorLogs)(bt, reactor.id, port);
15
18
  }
16
19
  }
@@ -1,4 +1,6 @@
1
1
  import type { BasisTheory as IBasisTheory } from '@basis-theory/basis-theory-js/types/sdk/sdk';
2
2
  declare const connectToReactor: (bt: IBasisTheory, id: string, url: string) => Promise<void>;
3
+ declare const disconnectFromReactor: (bt: IBasisTheory, id: string) => Promise<void>;
3
4
  declare const connectToProxy: (bt: IBasisTheory, id: string, url: string) => Promise<void>;
4
- export { connectToProxy, connectToReactor };
5
+ declare const disconnectFromProxy: (bt: IBasisTheory, id: string) => Promise<void>;
6
+ export { connectToReactor, disconnectFromReactor, connectToProxy, disconnectFromProxy, };
@@ -1,15 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.connectToReactor = exports.connectToProxy = void 0;
3
+ exports.disconnectFromProxy = exports.connectToProxy = exports.disconnectFromReactor = exports.connectToReactor = void 0;
4
4
  const core_1 = require("@oclif/core");
5
5
  const management_1 = require("../proxies/management");
6
6
  const management_2 = require("../reactors/management");
7
7
  const BT_LOGGING_CONFIGURATION = 'BT_LOGGING_CONFIGURATION';
8
+ /**
9
+ * Creates configuration object to connect/disconnect to a resource
10
+ * @param url - server url for the resource to connect to. If `undefined`,
11
+ * the logging configuration is cleared.
12
+ */
8
13
  const createConfiguration = (url) => ({
9
- [BT_LOGGING_CONFIGURATION]: JSON.stringify({
10
- destination: url,
11
- date: Date.now(),
12
- }),
14
+ [BT_LOGGING_CONFIGURATION]: url
15
+ ? JSON.stringify({
16
+ destination: url,
17
+ date: Date.now(),
18
+ })
19
+ : // eslint-disable-next-line unicorn/no-null
20
+ null,
13
21
  });
14
22
  const connectToReactor = async (bt, id, url) => {
15
23
  core_1.ux.action.start(`Connecting to Reactor (${id})`);
@@ -19,6 +27,14 @@ const connectToReactor = async (bt, id, url) => {
19
27
  core_1.ux.action.stop('✅\t');
20
28
  };
21
29
  exports.connectToReactor = connectToReactor;
30
+ const disconnectFromReactor = async (bt, id) => {
31
+ core_1.ux.action.start(`Disconnecting from Reactor (${id})`);
32
+ await (0, management_2.patchReactor)(bt, id, {
33
+ configuration: createConfiguration(),
34
+ });
35
+ core_1.ux.action.stop('✅\t');
36
+ };
37
+ exports.disconnectFromReactor = disconnectFromReactor;
22
38
  const connectToProxy = async (bt, id, url) => {
23
39
  core_1.ux.action.start(`Connecting to Proxy (${id})`);
24
40
  await (0, management_1.patchProxy)(bt, id, {
@@ -27,3 +43,11 @@ const connectToProxy = async (bt, id, url) => {
27
43
  core_1.ux.action.stop('✅\t');
28
44
  };
29
45
  exports.connectToProxy = connectToProxy;
46
+ const disconnectFromProxy = async (bt, id) => {
47
+ core_1.ux.action.start(`Disconnecting from Proxy (${id})`);
48
+ await (0, management_1.patchProxy)(bt, id, {
49
+ configuration: createConfiguration(),
50
+ });
51
+ core_1.ux.action.stop('✅\t');
52
+ };
53
+ exports.disconnectFromProxy = disconnectFromProxy;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DEFAULT_LOGS_SERVER_PORT = exports.showReactorLogs = exports.showProxyLogs = void 0;
4
+ const utils_1 = require("../utils");
4
5
  const connect_1 = require("./connect");
5
6
  const server_1 = require("./server");
6
7
  const DEFAULT_LOGS_SERVER_PORT = 8220;
@@ -8,10 +9,12 @@ exports.DEFAULT_LOGS_SERVER_PORT = DEFAULT_LOGS_SERVER_PORT;
8
9
  const showProxyLogs = async (bt, id, port = DEFAULT_LOGS_SERVER_PORT) => {
9
10
  const url = await (0, server_1.createLogServer)(port);
10
11
  await (0, connect_1.connectToProxy)(bt, id, url);
12
+ (0, utils_1.cleanUpOnExit)(() => (0, connect_1.disconnectFromProxy)(bt, id));
11
13
  };
12
14
  exports.showProxyLogs = showProxyLogs;
13
15
  const showReactorLogs = async (bt, id, port = DEFAULT_LOGS_SERVER_PORT) => {
14
16
  const url = await (0, server_1.createLogServer)(port);
15
17
  await (0, connect_1.connectToReactor)(bt, id, url);
18
+ (0, utils_1.cleanUpOnExit)(() => (0, connect_1.disconnectFromReactor)(bt, id));
16
19
  };
17
20
  exports.showReactorLogs = showReactorLogs;
@@ -6,5 +6,5 @@ interface LogEvent {
6
6
  level: 'INFO' | 'WARN' | 'ERROR';
7
7
  time: number;
8
8
  }
9
- declare const parseLogEvent: (logger: pino.Logger) => (event: LogEvent) => Promise<void>;
9
+ declare const parseLogEvent: (logger: pino.Logger, event: LogEvent) => Promise<void>;
10
10
  export { parseLogEvent };
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseLogEvent = void 0;
4
4
  const debug = require('debug')('logs:parse');
5
- const parseLogEvent = (logger) => async (event) => {
5
+ const parseLogEvent = async (logger, event) => {
6
6
  debug(event);
7
7
  const { deserializeError } = await import('serialize-error');
8
8
  const [arg1, arg2, ...args] = event.args.map((arg) => {
@@ -39,7 +39,16 @@ const createLogServer = async (port) => {
39
39
  const io = new socket_io_1.Server(server);
40
40
  io.on('connection', (client) => {
41
41
  debug(`socket client connected: ${client.handshake.address}`);
42
- client.on('log', (0, parse_1.parseLogEvent)(logger));
42
+ client.on('log', (data, callback) => {
43
+ debug('received "log" event');
44
+ if (typeof callback === 'function') {
45
+ debug('ack expected');
46
+ // eslint-disable-next-line node/callback-return,node/no-callback-literal
47
+ callback('ack');
48
+ debug('ack sent');
49
+ }
50
+ (0, parse_1.parseLogEvent)(logger, data);
51
+ });
43
52
  client.on('disconnect', (reason) => {
44
53
  debug(`socket client disconnected ${client.handshake.address}: ${reason}`);
45
54
  });
@@ -1,6 +1,6 @@
1
1
  import type { CreateProxy, PatchProxy, Proxy } from '@basis-theory/basis-theory-js/types/models';
2
2
  import type { BasisTheory as IBasisTheory } from '@basis-theory/basis-theory-js/types/sdk';
3
- declare const selectProxy: (bt: IBasisTheory, page: number) => Promise<Proxy>;
3
+ declare const selectProxy: (bt: IBasisTheory, page: number) => Promise<Proxy | undefined>;
4
4
  declare const createProxy: (bt: IBasisTheory, model: CreateProxy) => Promise<Proxy>;
5
5
  declare const patchProxy: (bt: IBasisTheory, id: string, model: PatchProxy) => Promise<void>;
6
6
  export { selectProxy, createProxy, patchProxy };
@@ -11,38 +11,44 @@ const listProxies = async (bt, page) => {
11
11
  size,
12
12
  page,
13
13
  });
14
- const last = (proxies.pagination.pageNumber - 1) * size;
15
- const data = proxies.data.map((proxy, index) => ({
16
- '#': last + (index + 1),
17
- ...proxy,
18
- }));
19
- core_1.ux.table(data, {
20
- '#': {},
21
- id: {},
22
- name: {},
23
- key: {},
24
- /* eslint-disable camelcase */
25
- destination_url: {
26
- header: 'Destination URL',
27
- get: (proxy) => proxy.destinationUrl,
28
- },
29
- require_auth: {
30
- header: 'Require Auth',
31
- get: (proxy) => (proxy.requireAuth ? 'yes' : 'no'),
32
- },
33
- request_transform: {
34
- header: 'Request Transform',
35
- get: (proxy) => { var _a; return (((_a = proxy.requestTransform) === null || _a === void 0 ? void 0 : _a.code) ? 'yes' : 'no'); },
36
- },
37
- response_transform: {
38
- header: 'Response Transform',
39
- get: (proxy) => { var _a; return (((_a = proxy.responseTransform) === null || _a === void 0 ? void 0 : _a.code) ? 'yes' : 'no'); },
40
- },
41
- application_id: {
42
- header: 'Application Id',
43
- },
44
- /* eslint-enable camelcase */
45
- });
14
+ let data = [];
15
+ if (proxies.pagination.totalItems > 0) {
16
+ const last = (proxies.pagination.pageNumber - 1) * size;
17
+ data = proxies.data.map((proxy, index) => ({
18
+ '#': last + (index + 1),
19
+ ...proxy,
20
+ }));
21
+ core_1.ux.table(data, {
22
+ '#': {},
23
+ id: {},
24
+ name: {},
25
+ key: {},
26
+ /* eslint-disable camelcase */
27
+ destination_url: {
28
+ header: 'Destination URL',
29
+ get: (proxy) => proxy.destinationUrl,
30
+ },
31
+ require_auth: {
32
+ header: 'Require Auth',
33
+ get: (proxy) => (proxy.requireAuth ? 'yes' : 'no'),
34
+ },
35
+ request_transform: {
36
+ header: 'Request Transform',
37
+ get: (proxy) => { var _a; return (((_a = proxy.requestTransform) === null || _a === void 0 ? void 0 : _a.code) ? 'yes' : 'no'); },
38
+ },
39
+ response_transform: {
40
+ header: 'Response Transform',
41
+ get: (proxy) => { var _a; return (((_a = proxy.responseTransform) === null || _a === void 0 ? void 0 : _a.code) ? 'yes' : 'no'); },
42
+ },
43
+ application_id: {
44
+ header: 'Application Id',
45
+ },
46
+ /* eslint-enable camelcase */
47
+ });
48
+ }
49
+ else {
50
+ core_1.ux.log('No proxies found.');
51
+ }
46
52
  return {
47
53
  data,
48
54
  pagination: proxies.pagination,
@@ -50,6 +56,9 @@ const listProxies = async (bt, page) => {
50
56
  };
51
57
  const selectProxy = async (bt, page) => {
52
58
  const proxies = await listProxies(bt, page);
59
+ if (proxies.pagination.totalItems === 0) {
60
+ return undefined;
61
+ }
53
62
  const selection = await (0, utils_1.selectOrNavigate)(proxies, '#');
54
63
  if (selection === 'previous') {
55
64
  return selectProxy(bt, page - 1);
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { CreateProxy as CreateProxyModel, PatchProxy as PatchProxyModel } from '@basis-theory/basis-theory-js/types/models/proxies';
2
+ import type { CreateProxy as CreateProxyModel, PatchProxy as PatchProxyModel } from '@basis-theory/basis-theory-js/types/models/proxies';
3
3
  declare const PROXY_FLAGS: {
4
4
  name: import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
5
5
  'destination-url': import("@oclif/core/lib/interfaces/parser").OptionFlag<import("url").URL | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
@@ -27,10 +27,8 @@ interface ProxyFlagProps {
27
27
  */
28
28
  configuration?: string;
29
29
  }
30
- interface CreateProxy extends Omit<CreateProxyModel, 'application' | 'configuration' | 'requestTransform' | 'responseTransform'>, ProxyFlagProps {
31
- }
32
- interface PatchProxy extends Omit<PatchProxyModel, 'application' | 'configuration' | 'requestTransform' | 'responseTransform'>, ProxyFlagProps {
33
- }
30
+ type CreateProxy = ProxyFlagProps & Omit<CreateProxyModel, 'application' | 'configuration' | 'requestTransform' | 'responseTransform'>;
31
+ type PatchProxy = ProxyFlagProps & Omit<PatchProxyModel, 'application' | 'configuration' | 'requestTransform' | 'responseTransform'>;
34
32
  declare function createModelFromFlags(payload: CreateProxy): CreateProxyModel;
35
33
  declare function createModelFromFlags(payload: PatchProxy): PatchProxyModel;
36
34
  export { PROXY_FLAGS, createModelFromFlags };
@@ -1,5 +1,5 @@
1
1
  import type { Reactor, PatchReactor } from '@basis-theory/basis-theory-js/types/models';
2
2
  import type { BasisTheory as IBasisTheory } from '@basis-theory/basis-theory-js/types/sdk';
3
- declare const selectReactor: (bt: IBasisTheory, page: number) => Promise<Reactor>;
3
+ declare const selectReactor: (bt: IBasisTheory, page: number) => Promise<Reactor | undefined>;
4
4
  declare const patchReactor: (bt: IBasisTheory, id: string, model: PatchReactor) => Promise<void>;
5
5
  export { selectReactor, patchReactor };
@@ -11,16 +11,22 @@ const listReactors = async (bt, page) => {
11
11
  size,
12
12
  page,
13
13
  });
14
- const last = (reactors.pagination.pageNumber - 1) * size;
15
- const data = reactors.data.map((reactor, index) => ({
16
- '#': last + (index + 1),
17
- ...reactor,
18
- }));
19
- core_1.ux.table(data, {
20
- '#': {},
21
- id: {},
22
- name: {},
23
- });
14
+ let data = [];
15
+ if (reactors.pagination.totalItems > 0) {
16
+ const last = (reactors.pagination.pageNumber - 1) * size;
17
+ data = reactors.data.map((reactor, index) => ({
18
+ '#': last + (index + 1),
19
+ ...reactor,
20
+ }));
21
+ core_1.ux.table(data, {
22
+ '#': {},
23
+ id: {},
24
+ name: {},
25
+ });
26
+ }
27
+ else {
28
+ core_1.ux.log('No reactors found.');
29
+ }
24
30
  return {
25
31
  data,
26
32
  pagination: reactors.pagination,
@@ -28,6 +34,9 @@ const listReactors = async (bt, page) => {
28
34
  };
29
35
  const selectReactor = async (bt, page) => {
30
36
  const reactors = await listReactors(bt, page);
37
+ if (reactors.pagination.totalItems === 0) {
38
+ return undefined;
39
+ }
31
40
  const selection = await (0, utils_1.selectOrNavigate)(reactors, '#');
32
41
  if (selection === 'previous') {
33
42
  return selectReactor(bt, page - 1);
package/dist/utils.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
1
3
  import { PaginatedList } from '@basis-theory/basis-theory-js/types/sdk';
2
4
  import confirm from '@inquirer/confirm';
3
5
  import input from '@inquirer/input';
@@ -6,4 +8,5 @@ declare const promptStringIfUndefined: (value: string | undefined, options: Para
6
8
  declare const promptUrlIfUndefined: (value: URL | undefined, options: Parameters<typeof input>[0]) => Promise<URL>;
7
9
  declare const promptBooleanIfUndefined: (value: boolean | undefined, options: Parameters<typeof confirm>[0]) => Promise<boolean>;
8
10
  declare const readFileContents: (filePath: string) => string;
9
- export { selectOrNavigate, promptStringIfUndefined, promptUrlIfUndefined, promptBooleanIfUndefined, readFileContents, };
11
+ declare const cleanUpOnExit: (action: () => unknown) => typeof process;
12
+ export { selectOrNavigate, promptStringIfUndefined, promptUrlIfUndefined, promptBooleanIfUndefined, readFileContents, cleanUpOnExit, };
package/dist/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.readFileContents = exports.promptBooleanIfUndefined = exports.promptUrlIfUndefined = exports.promptStringIfUndefined = exports.selectOrNavigate = void 0;
3
+ exports.cleanUpOnExit = exports.readFileContents = exports.promptBooleanIfUndefined = exports.promptUrlIfUndefined = exports.promptStringIfUndefined = exports.selectOrNavigate = void 0;
4
4
  const confirm_1 = require("@inquirer/confirm");
5
5
  const input_1 = require("@inquirer/input");
6
6
  const core_1 = require("@oclif/core");
@@ -17,7 +17,9 @@ const selectOrNavigate = async (list, prop) => {
17
17
  if (hasNext) {
18
18
  prompt += " or 'n' for next page ";
19
19
  }
20
- const selection = await core_1.ux.prompt(prompt);
20
+ const selection = await (0, input_1.default)({
21
+ message: prompt,
22
+ });
21
23
  if (selection === 'p' && hasPrevious) {
22
24
  return 'previous';
23
25
  }
@@ -67,3 +69,8 @@ const promptBooleanIfUndefined = (value, options) => {
67
69
  exports.promptBooleanIfUndefined = promptBooleanIfUndefined;
68
70
  const readFileContents = (filePath) => fs.readFileSync(path.resolve(process.cwd(), filePath)).toString();
69
71
  exports.readFileContents = readFileContents;
72
+ const cleanUpOnExit = (action) => process.on('SIGINT', async () => {
73
+ await action();
74
+ process.exit(1);
75
+ });
76
+ exports.cleanUpOnExit = cleanUpOnExit;
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.3.0",
2
+ "version": "1.3.2",
3
3
  "commands": {
4
4
  "proxies:create": {
5
5
  "id": "proxies:create",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@basis-theory-labs/cli",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
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": "^1.78.1",
20
+ "@basis-theory/basis-theory-js": "^1.79.2",
21
21
  "@inquirer/confirm": "^2.0.3",
22
22
  "@inquirer/input": "^1.2.1",
23
23
  "@inquirer/prompts": "^2.1.1",
@@ -31,7 +31,7 @@
31
31
  "pino": "^8.14.1",
32
32
  "pino-pretty": "^10.0.0",
33
33
  "serialize-error": "^11.0.0",
34
- "socket.io": "^4.6.2"
34
+ "socket.io": "^4.7.1"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@basis-theory/eslint-config": "^1.2.0",