@trayio/cdk-cli 3.1.1-unstable → 3.3.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 @trayio/cdk-cli
19
19
  $ tray-cdk COMMAND
20
20
  running command...
21
21
  $ tray-cdk (--version|-v)
22
- @trayio/cdk-cli/3.1.1-unstable linux-x64 node-v18.19.0
22
+ @trayio/cdk-cli/3.3.0 linux-x64 node-v18.19.0
23
23
  $ tray-cdk --help [COMMAND]
24
24
  USAGE
25
25
  $ tray-cdk COMMAND
@@ -38,7 +38,7 @@ USAGE
38
38
  * [`tray-cdk connector init [CONNECTORNAME]`](#tray-cdk-connector-init-connectorname)
39
39
  * [`tray-cdk connector test [OPERATIONNAME]`](#tray-cdk-connector-test-operationname)
40
40
  * [`tray-cdk deployment create`](#tray-cdk-deployment-create)
41
- * [`tray-cdk deployment get CONNECTORNAME CONNECTORVERSION UUID`](#tray-cdk-deployment-get-connectorname-connectorversion-uuid)
41
+ * [`tray-cdk deployment get [CONNECTORNAME] [CONNECTORVERSION] [UUID]`](#tray-cdk-deployment-get-connectorname-connectorversion-uuid)
42
42
  * [`tray-cdk help [COMMANDS]`](#tray-cdk-help-commands)
43
43
  * [`tray-cdk permissions add [CONNECTORNAME] [CONNECTORVERSION]`](#tray-cdk-permissions-add-connectorname-connectorversion)
44
44
  * [`tray-cdk permissions list [CONNECTORNAME] [CONNECTORVERSION]`](#tray-cdk-permissions-list-connectorname-connectorversion)
@@ -174,21 +174,43 @@ DESCRIPTION
174
174
  Creates a new deployment for a connector project
175
175
  ```
176
176
 
177
- ## `tray-cdk deployment get CONNECTORNAME CONNECTORVERSION UUID`
177
+ ## `tray-cdk deployment get [CONNECTORNAME] [CONNECTORVERSION] [UUID]`
178
178
 
179
179
  Retrieves the status of a connector deployment
180
180
 
181
181
  ```
182
182
  USAGE
183
- $ tray-cdk deployment get CONNECTORNAME CONNECTORVERSION UUID
183
+ $ tray-cdk deployment get [CONNECTORNAME] [CONNECTORVERSION] [UUID] [-t]
184
184
 
185
185
  ARGUMENTS
186
186
  CONNECTORNAME The name of the connector
187
187
  CONNECTORVERSION The version of the connector
188
188
  UUID The UUID of the deployment, this is included in the tray-cdk deploy output
189
189
 
190
+ FLAGS
191
+ -t, --tail Enables the command to run until the deployment is complete with either a success or failure.
192
+
190
193
  DESCRIPTION
191
194
  Retrieves the status of a connector deployment
195
+
196
+ EXAMPLES
197
+ $ tray-cdk deployment get
198
+
199
+ $ tray-cdk deployment get --tail
200
+
201
+ $ tray-cdk deployment get -t
202
+
203
+ $ tray-cdk deployment get my-connector 1.0
204
+
205
+ $ tray-cdk deployment get my-connector 1.0 --tail
206
+
207
+ $ tray-cdk deployment get my-connector 1.0 -t
208
+
209
+ $ tray-cdk deployment get my-connector 1.0 3f1de598-d405-4801-9eec-6fe79e8393d3
210
+
211
+ $ tray-cdk deployment get my-connector 1.0 3f1de598-d405-4801-9eec-6fe79e8393d3 --tail
212
+
213
+ $ tray-cdk deployment get my-connector 1.0 3f1de598-d405-4801-9eec-6fe79e8393d3 -t
192
214
  ```
193
215
 
194
216
  ## `tray-cdk help [COMMANDS]`
@@ -2,11 +2,18 @@ import { Command } from '@oclif/core';
2
2
  export default class Get extends Command {
3
3
  static description: string;
4
4
  static args: {
5
- connectorName: import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
6
- connectorVersion: import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
7
- uuid: import("@oclif/core/lib/interfaces").Arg<string, Record<string, unknown>>;
5
+ connectorName: import("@oclif/core/lib/interfaces").Arg<string | undefined, Record<string, unknown>>;
6
+ connectorVersion: import("@oclif/core/lib/interfaces").Arg<string | undefined, Record<string, unknown>>;
7
+ uuid: import("@oclif/core/lib/interfaces").Arg<string | undefined, Record<string, unknown>>;
8
8
  };
9
+ static flags: {
10
+ tail: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
11
+ };
12
+ static examples: string[];
9
13
  private connectorDeployment;
14
+ private generateConnectorDeploymentId;
15
+ private pollConnectorDeploymentStatus;
16
+ private getLocalConnectorInfo;
10
17
  run(): Promise<void>;
11
18
  }
12
19
  //# sourceMappingURL=get.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"get.d.ts","sourceRoot":"","sources":["../../../src/commands/deployment/get.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAY,MAAM,aAAa,CAAC;AAOhD,MAAM,CAAC,OAAO,OAAO,GAAI,SAAQ,OAAO;IACvC,MAAM,CAAC,WAAW,SAAoD;IAEtE,MAAM,CAAC,IAAI;;;;MAiBT;IAEF,OAAO,CAAC,mBAAmB,CAKzB;IAEI,GAAG;CAyDT"}
1
+ {"version":3,"file":"get.d.ts","sourceRoot":"","sources":["../../../src/commands/deployment/get.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAmB,MAAM,aAAa,CAAC;AAcvD,MAAM,CAAC,OAAO,OAAO,GAAI,SAAQ,OAAO;IACvC,MAAM,CAAC,WAAW,SAAoD;IAEtE,MAAM,CAAC,IAAI;;;;MAiBT;IAEF,MAAM,CAAC,KAAK;;MAMV;IAEF,MAAM,CAAC,QAAQ,WAUb;IAEF,OAAO,CAAC,mBAAmB,CAKzB;IAEF,OAAO,CAAC,6BAA6B,CAGmC;IAExE,OAAO,CAAC,6BAA6B,CA8BnC;IAEF,OAAO,CAAC,qBAAqB,CAe3B;IAEI,GAAG;CAsFT"}
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
26
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
27
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -10,9 +33,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
33
  };
11
34
  Object.defineProperty(exports, "__esModule", { value: true });
12
35
  const core_1 = require("@oclif/core");
36
+ const pathLib = __importStar(require("path"));
37
+ const fse = __importStar(require("fs-extra"));
13
38
  const AxiosHttpClient_1 = require("@trayio/axios/http/AxiosHttpClient");
14
39
  const ConnectorDeploymentHttpClient_1 = require("@trayio/tray-client/connector/deployment/ConnectorDeploymentHttpClient");
15
40
  const ConnectorDeploymentApi_1 = require("@trayio/tray-api/connector/deployment/ConnectorDeploymentApi");
41
+ const uuid_1 = require("uuid");
16
42
  const colorizeString_1 = require("../../utils/colorizeString");
17
43
  const check_env_1 = require("../../utils/check-env");
18
44
  class Get extends core_1.Command {
@@ -21,20 +47,67 @@ class Get extends core_1.Command {
21
47
  this.connectorDeployment = new ConnectorDeploymentHttpClient_1.ConnectorDeploymentHttpClient({
22
48
  baseUrl: process.env.TRAY_API_URL,
23
49
  }, new AxiosHttpClient_1.AxiosHttpClient());
50
+ this.generateConnectorDeploymentId = (connectorName, connectorVersion) => (0, uuid_1.v5)(`${connectorName}-${connectorVersion}`, uuid_1.v5.URL);
51
+ this.pollConnectorDeploymentStatus = (connectorName, connectorVersion, id, token) => __awaiter(this, void 0, void 0, function* () {
52
+ const input = {
53
+ connectorName,
54
+ connectorVersion,
55
+ id,
56
+ token,
57
+ };
58
+ const response = yield this.connectorDeployment.get(input);
59
+ if (response.isSuccess &&
60
+ response.value.deploymentStatus === ConnectorDeploymentApi_1.ConnectorDeploymentStatus.Deploying) {
61
+ yield new Promise((resolve) => {
62
+ setTimeout(resolve, 5000);
63
+ });
64
+ return this.pollConnectorDeploymentStatus(connectorName, connectorVersion, id, token);
65
+ }
66
+ return response;
67
+ });
68
+ this.getLocalConnectorInfo = () => {
69
+ const currentDirectory = process.cwd();
70
+ const connectorJsonPath = pathLib.join(currentDirectory, 'connector.json');
71
+ try {
72
+ const connectorJson = fse.readJsonSync(connectorJsonPath);
73
+ return {
74
+ name: connectorJson.name,
75
+ version: connectorJson.version,
76
+ };
77
+ }
78
+ catch (e) {
79
+ throw new Error(`Connector JSON file not found in the current directory. Please provide the connector name and version as arguments`);
80
+ }
81
+ };
24
82
  }
25
83
  run() {
26
84
  return __awaiter(this, void 0, void 0, function* () {
27
85
  (0, check_env_1.checkEnv)();
28
- const { args } = yield this.parse(Get);
86
+ const { args, flags } = yield this.parse(Get);
29
87
  const TRAY_API_TOKEN = process.env.TRAY_API_TOKEN;
88
+ if (!args.connectorName || !args.connectorVersion) {
89
+ core_1.ux.action.start('No arguments provided, attempting to use local connector');
90
+ const { name, version } = this.getLocalConnectorInfo();
91
+ args.connectorName = name;
92
+ args.connectorVersion = version;
93
+ core_1.ux.action.stop(`Local connector found. Name: ${name}, Version: ${version}`);
94
+ }
30
95
  const input = {
31
96
  connectorName: args.connectorName,
32
97
  connectorVersion: args.connectorVersion,
33
- id: args.uuid,
98
+ id: args.uuid ||
99
+ this.generateConnectorDeploymentId(args.connectorName, args.connectorVersion),
34
100
  token: TRAY_API_TOKEN,
35
101
  };
36
- core_1.ux.action.start(`Checking the connector deployment status`);
37
- const response = yield this.connectorDeployment.get(input);
102
+ let response;
103
+ if (flags.tail) {
104
+ core_1.ux.action.start(`Checking the connector deployment status with tailing`);
105
+ response = yield this.pollConnectorDeploymentStatus(input.connectorName, input.connectorVersion, input.id, input.token);
106
+ }
107
+ else {
108
+ core_1.ux.action.start(`Checking the connector deployment status`);
109
+ response = yield this.connectorDeployment.get(input);
110
+ }
38
111
  core_1.ux.action.stop();
39
112
  if (response.isSuccess) {
40
113
  switch (response.value.deploymentStatus) {
@@ -63,18 +136,35 @@ Get.description = 'Retrieves the status of a connector deployment';
63
136
  Get.args = {
64
137
  connectorName: core_1.Args.string({
65
138
  name: 'Connector Name',
66
- required: true,
139
+ required: false,
67
140
  description: 'The name of the connector',
68
141
  }),
69
142
  connectorVersion: core_1.Args.string({
70
143
  name: 'Connector Version',
71
- required: true,
144
+ required: false,
72
145
  description: 'The version of the connector',
73
146
  }),
74
147
  uuid: core_1.Args.string({
75
148
  name: 'Deployment UUID',
76
- required: true,
149
+ required: false,
77
150
  description: 'The UUID of the deployment, this is included in the tray-cdk deploy output',
78
151
  }),
79
152
  };
153
+ Get.flags = {
154
+ tail: core_1.Flags.boolean({
155
+ char: 't',
156
+ description: 'Enables the command to run until the deployment is complete with either a success or failure.',
157
+ }),
158
+ };
159
+ Get.examples = [
160
+ `<%= config.bin %> <%= command.id %>`,
161
+ `<%= config.bin %> <%= command.id %> --tail`,
162
+ `<%= config.bin %> <%= command.id %> -t`,
163
+ `<%= config.bin %> <%= command.id %> my-connector 1.0`,
164
+ `<%= config.bin %> <%= command.id %> my-connector 1.0 --tail`,
165
+ `<%= config.bin %> <%= command.id %> my-connector 1.0 -t`,
166
+ `<%= config.bin %> <%= command.id %> my-connector 1.0 3f1de598-d405-4801-9eec-6fe79e8393d3`,
167
+ `<%= config.bin %> <%= command.id %> my-connector 1.0 3f1de598-d405-4801-9eec-6fe79e8393d3 --tail`,
168
+ `<%= config.bin %> <%= command.id %> my-connector 1.0 3f1de598-d405-4801-9eec-6fe79e8393d3 -t`,
169
+ ];
80
170
  exports.default = Get;
@@ -12,6 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
+ const core_1 = require("@oclif/core");
15
16
  const stdout_stderr_1 = require("stdout-stderr");
16
17
  const ConnectorDeploymentApi_1 = require("@trayio/tray-api/connector/deployment/ConnectorDeploymentApi");
17
18
  const ConnectorDeploymentHttpClient_1 = require("@trayio/tray-client/connector/deployment/ConnectorDeploymentHttpClient");
@@ -33,6 +34,8 @@ describe('GetDeploymentStatus', () => {
33
34
  const connectorVersion = '1.0';
34
35
  const uuid = 'test-uuid';
35
36
  beforeEach(() => {
37
+ success = true;
38
+ failure = false;
36
39
  ConnectorDeploymentHttpClient_1.ConnectorDeploymentHttpClient.mockImplementation(() => ({
37
40
  get: jest.fn().mockReturnValue(Object.assign(Object.assign(Object.assign({ isSuccess: success }, (success && {
38
41
  value: {
@@ -50,9 +53,11 @@ describe('GetDeploymentStatus', () => {
50
53
  });
51
54
  it('should log success message when connector is deployed', () => __awaiter(void 0, void 0, void 0, function* () {
52
55
  status = ConnectorDeploymentApi_1.ConnectorDeploymentStatus.Deployed;
56
+ const uxStartSpy = jest.spyOn(core_1.ux.action, 'start');
53
57
  stdout_stderr_1.stdout.start();
54
58
  yield get_1.default.run([connectorName, connectorVersion, uuid]);
55
59
  stdout_stderr_1.stdout.stop();
60
+ expect(uxStartSpy).toHaveBeenCalledWith(`Checking the connector deployment status`);
56
61
  expect(stdout_stderr_1.stdout.output).toEqual(expect.stringContaining('Connector Deployed Successfully!'));
57
62
  }));
58
63
  it('should log failed message when connector failed to deploy', () => __awaiter(void 0, void 0, void 0, function* () {
@@ -79,4 +84,31 @@ describe('GetDeploymentStatus', () => {
79
84
  expect(stdout_stderr_1.stdout.output).toEqual(expect.stringContaining('Connector Deploy Failed, please try again or contact support'));
80
85
  expect(stdout_stderr_1.stdout.output).toEqual(expect.stringContaining('There was an error fetching deployment status'));
81
86
  }));
87
+ it('should run the polling function when tail flag is set', () => __awaiter(void 0, void 0, void 0, function* () {
88
+ status = ConnectorDeploymentApi_1.ConnectorDeploymentStatus.Deployed;
89
+ const uxStartSpy = jest.spyOn(core_1.ux.action, 'start');
90
+ stdout_stderr_1.stdout.start();
91
+ yield get_1.default.run([connectorName, connectorVersion, uuid, '-t']);
92
+ stdout_stderr_1.stdout.stop();
93
+ expect(uxStartSpy).toHaveBeenCalledWith(`Checking the connector deployment status with tailing`);
94
+ expect(stdout_stderr_1.stdout.output).toEqual(expect.stringContaining('Connector Deployed Successfully!'));
95
+ }));
96
+ it('should run the get status command when a uuid is not provided', () => __awaiter(void 0, void 0, void 0, function* () {
97
+ status = ConnectorDeploymentApi_1.ConnectorDeploymentStatus.Deployed;
98
+ stdout_stderr_1.stdout.start();
99
+ yield get_1.default.run([connectorName, connectorVersion]);
100
+ stdout_stderr_1.stdout.stop();
101
+ expect(stdout_stderr_1.stdout.output).toEqual(expect.stringContaining('Connector Deployed Successfully!'));
102
+ }));
103
+ it('should use local connector when no args are provided', () => __awaiter(void 0, void 0, void 0, function* () {
104
+ status = ConnectorDeploymentApi_1.ConnectorDeploymentStatus.Deployed;
105
+ stdout_stderr_1.stdout.start();
106
+ yield get_1.default.run([]);
107
+ stdout_stderr_1.stdout.stop();
108
+ const uxStartSpy = jest.spyOn(core_1.ux.action, 'start');
109
+ expect(uxStartSpy).toHaveBeenCalledTimes(2);
110
+ expect(uxStartSpy.mock.calls[0][0]).toEqual('No arguments provided, attempting to use local connector');
111
+ expect(uxStartSpy.mock.calls[1][0]).toEqual('Checking the connector deployment status');
112
+ expect(stdout_stderr_1.stdout.output).toEqual(expect.stringContaining('Connector Deployed Successfully!'));
113
+ }));
82
114
  });
@@ -203,21 +203,40 @@
203
203
  "connectorName": {
204
204
  "description": "The name of the connector",
205
205
  "name": "connectorName",
206
- "required": true
206
+ "required": false
207
207
  },
208
208
  "connectorVersion": {
209
209
  "description": "The version of the connector",
210
210
  "name": "connectorVersion",
211
- "required": true
211
+ "required": false
212
212
  },
213
213
  "uuid": {
214
214
  "description": "The UUID of the deployment, this is included in the tray-cdk deploy output",
215
215
  "name": "uuid",
216
- "required": true
216
+ "required": false
217
217
  }
218
218
  },
219
219
  "description": "Retrieves the status of a connector deployment",
220
- "flags": {},
220
+ "examples": [
221
+ "<%= config.bin %> <%= command.id %>",
222
+ "<%= config.bin %> <%= command.id %> --tail",
223
+ "<%= config.bin %> <%= command.id %> -t",
224
+ "<%= config.bin %> <%= command.id %> my-connector 1.0",
225
+ "<%= config.bin %> <%= command.id %> my-connector 1.0 --tail",
226
+ "<%= config.bin %> <%= command.id %> my-connector 1.0 -t",
227
+ "<%= config.bin %> <%= command.id %> my-connector 1.0 3f1de598-d405-4801-9eec-6fe79e8393d3",
228
+ "<%= config.bin %> <%= command.id %> my-connector 1.0 3f1de598-d405-4801-9eec-6fe79e8393d3 --tail",
229
+ "<%= config.bin %> <%= command.id %> my-connector 1.0 3f1de598-d405-4801-9eec-6fe79e8393d3 -t"
230
+ ],
231
+ "flags": {
232
+ "tail": {
233
+ "char": "t",
234
+ "description": "Enables the command to run until the deployment is complete with either a success or failure.",
235
+ "name": "tail",
236
+ "allowNo": false,
237
+ "type": "boolean"
238
+ }
239
+ },
221
240
  "hasDynamicHelp": false,
222
241
  "hiddenAliases": [],
223
242
  "id": "deployment:get",
@@ -324,5 +343,5 @@
324
343
  ]
325
344
  }
326
345
  },
327
- "version": "3.1.1-unstable"
346
+ "version": "3.3.0"
328
347
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trayio/cdk-cli",
3
- "version": "3.1.1-unstable",
3
+ "version": "3.3.0",
4
4
  "description": "A CLI for connector development",
5
5
  "exports": {
6
6
  "./*": "./dist/*.js"
@@ -19,12 +19,12 @@
19
19
  "@oclif/plugin-help": "6.0.12",
20
20
  "@oclif/plugin-version": "2.0.11",
21
21
  "@oclif/test": "3.1.12",
22
- "@trayio/axios": "3.1.1-unstable",
23
- "@trayio/cdk-build": "3.1.1-unstable",
24
- "@trayio/commons": "3.1.1-unstable",
25
- "@trayio/generator": "3.1.1-unstable",
26
- "@trayio/tray-client": "3.1.1-unstable",
27
- "@trayio/tray-openapi": "3.1.1-unstable",
22
+ "@trayio/axios": "3.3.0",
23
+ "@trayio/cdk-build": "3.3.0",
24
+ "@trayio/commons": "3.3.0",
25
+ "@trayio/generator": "3.3.0",
26
+ "@trayio/tray-client": "3.3.0",
27
+ "@trayio/tray-openapi": "3.3.0",
28
28
  "@types/inquirer": "8.2.6",
29
29
  "chalk": "4.1.2",
30
30
  "inquirer": "8.2.5"