@capawesome/cli 1.1.0 → 1.2.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/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
4
4
 
5
+ ## [1.2.0](https://github.com/capawesome-team/cli/compare/v1.1.0...v1.2.0) (2024-12-21)
6
+
7
+
8
+ ### Features
9
+
10
+ * add Sentry for error reporting ([398868c](https://github.com/capawesome-team/cli/commit/398868c762c2fb24dcd631d19f33134ef876a6ed)), closes [#4](https://github.com/capawesome-team/cli/issues/4)
11
+
5
12
  ## [1.1.0](https://github.com/capawesome-team/cli/compare/v1.0.1...v1.1.0) (2024-11-01)
6
13
 
7
14
 
@@ -1,27 +1,4 @@
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
- };
25
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -35,10 +12,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
35
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
36
13
  };
37
14
  Object.defineProperty(exports, "__esModule", { value: true });
38
- const axios_1 = __importStar(require("axios"));
15
+ const axios_1 = require("axios");
39
16
  const citty_1 = require("citty");
40
17
  const consola_1 = __importDefault(require("consola"));
41
- const config_1 = require("../config");
18
+ const sessions_1 = __importDefault(require("../services/sessions"));
42
19
  const users_1 = __importDefault(require("../services/users"));
43
20
  const error_1 = require("../utils/error");
44
21
  const prompt_1 = require("../utils/prompt");
@@ -68,19 +45,18 @@ exports.default = (0, citty_1.defineCommand)({
68
45
  consola_1.default.start('Logging in...');
69
46
  let sessionId;
70
47
  try {
71
- const sessionResponse = yield axios_1.default.post(`${config_1.API_URL}/sessions`, {
72
- email: email,
73
- password: password,
48
+ const response = yield sessions_1.default.create({
49
+ email,
50
+ password,
74
51
  });
75
- sessionId = sessionResponse.data.id;
52
+ sessionId = response.id;
76
53
  }
77
54
  catch (error) {
78
55
  consola_1.default.error('Invalid email or password.');
79
56
  return;
80
57
  }
81
- const tokenResponse = yield axios_1.default.post(`${config_1.API_URL}/tokens`, { name: 'Capawesome CLI' }, { headers: { Authorization: `Bearer ${sessionId}` } });
82
58
  userConfig_1.default.write({
83
- token: tokenResponse.data.token,
59
+ token: sessionId,
84
60
  });
85
61
  consola_1.default.success(`Successfully signed in.`);
86
62
  }
@@ -14,6 +14,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const citty_1 = require("citty");
16
16
  const consola_1 = __importDefault(require("consola"));
17
+ const authorization_service_1 = __importDefault(require("../services/authorization-service"));
18
+ const sessions_1 = __importDefault(require("../services/sessions"));
17
19
  const userConfig_1 = __importDefault(require("../utils/userConfig"));
18
20
  exports.default = (0, citty_1.defineCommand)({
19
21
  meta: {
@@ -22,6 +24,10 @@ exports.default = (0, citty_1.defineCommand)({
22
24
  },
23
25
  args: {},
24
26
  run: () => __awaiter(void 0, void 0, void 0, function* () {
27
+ const token = authorization_service_1.default.getCurrentAuthorizationToken();
28
+ if (token && !token.startsWith('ca_')) {
29
+ yield sessions_1.default.delete({ id: token }).catch(() => { });
30
+ }
25
31
  userConfig_1.default.write({});
26
32
  consola_1.default.success('Successfully signed out.');
27
33
  }),
@@ -1,6 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MANIFEST_JSON_FILE_NAME = exports.API_URL = void 0;
4
- exports.API_URL = 'https://api.cloud.capawesome.io/v1';
5
- // export const API_URL = 'http://api.cloud.capawesome.local/v1';
3
+ exports.MANIFEST_JSON_FILE_NAME = void 0;
6
4
  exports.MANIFEST_JSON_FILE_NAME = 'capawesome-live-update-manifest.json'; // Do NOT change this!
package/dist/index.js CHANGED
@@ -23,12 +23,23 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  __setModuleDefault(result, mod);
24
24
  return result;
25
25
  };
26
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
27
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
28
+ return new (P || (P = Promise))(function (resolve, reject) {
29
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
30
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
31
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
32
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
33
+ });
34
+ };
26
35
  var __importDefault = (this && this.__importDefault) || function (mod) {
27
36
  return (mod && mod.__esModule) ? mod : { "default": mod };
28
37
  };
29
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
+ const Sentry = __importStar(require("@sentry/node"));
30
40
  const citty_1 = require("citty");
31
41
  const package_json_1 = __importDefault(require("../package.json"));
42
+ const config_1 = __importDefault(require("./services/config"));
32
43
  const update_1 = __importDefault(require("./services/update"));
33
44
  const main = (0, citty_1.defineCommand)({
34
45
  meta: {
@@ -57,4 +68,20 @@ const main = (0, citty_1.defineCommand)({
57
68
  'manifests:generate': Promise.resolve().then(() => __importStar(require('./commands/manifests/generate'))).then((mod) => mod.default),
58
69
  },
59
70
  });
60
- (0, citty_1.runMain)(main);
71
+ const captureException = (error) => __awaiter(void 0, void 0, void 0, function* () {
72
+ const environment = yield config_1.default.getValueForKey('ENVIRONMENT');
73
+ if (environment !== 'production') {
74
+ return;
75
+ }
76
+ Sentry.init({
77
+ dsn: 'https://19f30f2ec4b91899abc33818568ceb42@o4507446340747264.ingest.de.sentry.io/4508506426966096',
78
+ });
79
+ Sentry.captureException(error);
80
+ yield Sentry.close();
81
+ });
82
+ (0, citty_1.runMain)(main).catch((error) => __awaiter(void 0, void 0, void 0, function* () {
83
+ yield captureException(error).catch(() => {
84
+ // No op
85
+ });
86
+ process.exit(1);
87
+ }));
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const c12_1 = require("c12");
13
+ class ConfigServiceImpl {
14
+ constructor() {
15
+ this.config = this.loadConfig();
16
+ }
17
+ getValueForKey(key) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ return (yield this.config)[key];
20
+ });
21
+ }
22
+ loadConfig() {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ const { config } = yield (0, c12_1.loadConfig)({
25
+ defaults: {
26
+ API_URL: 'https://api.cloud.capawesome.io/v1',
27
+ ENVIRONMENT: 'production',
28
+ },
29
+ name: 'capawesome',
30
+ });
31
+ return config;
32
+ });
33
+ }
34
+ }
35
+ const configService = new ConfigServiceImpl();
36
+ exports.default = configService;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const http_client_1 = __importDefault(require("../utils/http-client"));
16
+ const authorization_service_1 = __importDefault(require("./authorization-service"));
17
+ class SessionsServiceImpl {
18
+ constructor(httpClient) {
19
+ this.httpClient = httpClient;
20
+ }
21
+ create(dto) {
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ const response = yield this.httpClient.post(`/sessions`, dto);
24
+ return response.data;
25
+ });
26
+ }
27
+ delete(dto) {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ yield this.httpClient.delete(`/sessions/${dto.id}`, {
30
+ headers: {
31
+ Authorization: `Bearer ${authorization_service_1.default.getCurrentAuthorizationToken()}`,
32
+ },
33
+ });
34
+ });
35
+ }
36
+ }
37
+ const sessionsService = new SessionsServiceImpl(http_client_1.default);
38
+ exports.default = sessionsService;
@@ -18,4 +18,5 @@ __exportStar(require("./app"), exports);
18
18
  __exportStar(require("./app-bundle"), exports);
19
19
  __exportStar(require("./app-channel"), exports);
20
20
  __exportStar(require("./app-device"), exports);
21
+ __exportStar(require("./session"), exports);
21
22
  __exportStar(require("./user"), exports);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,30 +1,54 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
13
  };
5
14
  Object.defineProperty(exports, "__esModule", { value: true });
6
15
  const axios_1 = __importDefault(require("axios"));
7
- const config_1 = require("../config");
16
+ const config_1 = __importDefault(require("../services/config"));
8
17
  class HttpClientImpl {
9
18
  delete(url, config) {
10
- const urlWithHost = url.startsWith('http') ? url : config_1.API_URL + url;
11
- return axios_1.default.delete(urlWithHost, config);
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ const baseUrl = yield config_1.default.getValueForKey('API_URL');
21
+ const urlWithHost = url.startsWith('http') ? url : baseUrl + url;
22
+ return axios_1.default.delete(urlWithHost, config);
23
+ });
12
24
  }
13
25
  get(url, config) {
14
- const urlWithHost = url.startsWith('http') ? url : config_1.API_URL + url;
15
- return axios_1.default.get(urlWithHost, config);
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ const baseUrl = yield config_1.default.getValueForKey('API_URL');
28
+ const urlWithHost = url.startsWith('http') ? url : baseUrl + url;
29
+ return axios_1.default.get(urlWithHost, config);
30
+ });
16
31
  }
17
32
  patch(url, data, config) {
18
- const urlWithHost = url.startsWith('http') ? url : config_1.API_URL + url;
19
- return axios_1.default.patch(urlWithHost, data, config);
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ const baseUrl = yield config_1.default.getValueForKey('API_URL');
35
+ const urlWithHost = url.startsWith('http') ? url : baseUrl + url;
36
+ return axios_1.default.patch(urlWithHost, data, config);
37
+ });
20
38
  }
21
39
  post(url, data, config) {
22
- const urlWithHost = url.startsWith('http') ? url : config_1.API_URL + url;
23
- return axios_1.default.post(urlWithHost, data, config);
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ const baseUrl = yield config_1.default.getValueForKey('API_URL');
42
+ const urlWithHost = url.startsWith('http') ? url : baseUrl + url;
43
+ return axios_1.default.post(urlWithHost, data, config);
44
+ });
24
45
  }
25
46
  put(url, data, config) {
26
- const urlWithHost = url.startsWith('http') ? url : config_1.API_URL + url;
27
- return axios_1.default.put(urlWithHost, data, config);
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ const baseUrl = yield config_1.default.getValueForKey('API_URL');
49
+ const urlWithHost = url.startsWith('http') ? url : baseUrl + url;
50
+ return axios_1.default.put(urlWithHost, data, config);
51
+ });
28
52
  }
29
53
  }
30
54
  let httpClient = new HttpClientImpl();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capawesome/cli",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "The Capawesome Cloud Command Line Interface (CLI) to manage Live Updates and more.",
5
5
  "scripts": {
6
6
  "build": "rimraf ./dist && tsc",
@@ -41,11 +41,14 @@
41
41
  ],
42
42
  "dependencies": {
43
43
  "@clack/prompts": "0.7.0",
44
+ "@sentry/node": "8.47.0",
44
45
  "archiver": "7.0.1",
45
46
  "axios": "1.7.7",
47
+ "c12": "2.0.1",
46
48
  "citty": "0.1.6",
47
49
  "consola": "3.2.3",
48
50
  "form-data": "4.0.1",
51
+ "patch-package": "8.0.0",
49
52
  "rc9": "2.1.2",
50
53
  "semver": "7.6.3"
51
54
  },