@dainprotocol/cli 1.2.25 → 1.2.28

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.
@@ -26,13 +26,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
26
26
  }) : function(o, v) {
27
27
  o["default"] = v;
28
28
  });
29
- var __importStar = (this && this.__importStar) || function (mod) {
30
- if (mod && mod.__esModule) return mod;
31
- var result = {};
32
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
33
- __setModuleDefault(result, mod);
34
- return result;
35
- };
29
+ var __importStar = (this && this.__importStar) || (function () {
30
+ var ownKeys = function(o) {
31
+ ownKeys = Object.getOwnPropertyNames || function (o) {
32
+ var ar = [];
33
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
34
+ return ar;
35
+ };
36
+ return ownKeys(o);
37
+ };
38
+ return function (mod) {
39
+ if (mod && mod.__esModule) return mod;
40
+ var result = {};
41
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
42
+ __setModuleDefault(result, mod);
43
+ return result;
44
+ };
45
+ })();
36
46
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
37
47
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
38
48
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
14
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
15
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -42,6 +53,31 @@ Object.defineProperty(exports, "__esModule", { value: true });
42
53
  exports.default = undeploy;
43
54
  var utils_1 = require("../utils");
44
55
  var ora_1 = __importDefault(require("ora"));
56
+ var FETCH_TIMEOUT_MS = 30000;
57
+ function fetchWithTimeout(url_1, options_1) {
58
+ return __awaiter(this, arguments, void 0, function (url, options, timeoutMs) {
59
+ var controller, timeoutId, response;
60
+ if (timeoutMs === void 0) { timeoutMs = FETCH_TIMEOUT_MS; }
61
+ return __generator(this, function (_a) {
62
+ switch (_a.label) {
63
+ case 0:
64
+ controller = new AbortController();
65
+ timeoutId = setTimeout(function () { return controller.abort(); }, timeoutMs);
66
+ _a.label = 1;
67
+ case 1:
68
+ _a.trys.push([1, , 3, 4]);
69
+ return [4 /*yield*/, fetch(url, __assign(__assign({}, options), { signal: controller.signal }))];
70
+ case 2:
71
+ response = _a.sent();
72
+ return [2 /*return*/, response];
73
+ case 3:
74
+ clearTimeout(timeoutId);
75
+ return [7 /*endfinally*/];
76
+ case 4: return [2 /*return*/];
77
+ }
78
+ });
79
+ });
80
+ }
45
81
  function undeploy(options) {
46
82
  return __awaiter(this, void 0, void 0, function () {
47
83
  var config, spinner, orgId, _a, apiKey, deploymentId, undeployUrl, response, error_1;
@@ -52,41 +88,35 @@ function undeploy(options) {
52
88
  spinner = (0, ora_1.default)("Undeploying deployment ".concat(config["deployment-id"], "...")).start();
53
89
  _b.label = 1;
54
90
  case 1:
55
- _b.trys.push([1, 3, 4, 5]);
91
+ _b.trys.push([1, 3, , 4]);
56
92
  orgId = "hackathon";
57
93
  _a = initializeConfig(config, orgId), apiKey = _a.apiKey, deploymentId = _a.deploymentId, undeployUrl = _a.undeployUrl;
58
- if (!orgId || !deploymentId) {
59
- (0, utils_1.logError)("Org ID or deployment ID not found");
60
- return [2 /*return*/];
94
+ if (!deploymentId) {
95
+ (0, utils_1.logError)("Deployment ID not found");
96
+ process.exit(1);
61
97
  }
62
- return [4 /*yield*/, fetch(undeployUrl, {
98
+ return [4 /*yield*/, fetchWithTimeout(undeployUrl, {
63
99
  method: "DELETE",
64
100
  headers: {
65
101
  "Content-Type": "application/json",
66
- "X-DAIN-SIGNATORY-ADDRESS": "TODO: X-DAIN-SIGNATORY-ADDRESS",
67
- "X-DAIN-SIGNATURE": "TODO: X-DAIN-SIGNATORY-SIGNATURE",
68
102
  Authorization: "Bearer ".concat(apiKey),
69
103
  },
70
104
  })];
71
105
  case 2:
72
106
  response = _b.sent();
73
107
  if (!response.ok) {
74
- throw new Error("Undeployment failed: ".concat(response.statusText));
108
+ throw new Error("Undeployment failed: ".concat(response.status, " ").concat(response.statusText));
75
109
  }
76
110
  spinner.succeed("Undeployment completed successfully.");
77
- spinner.info("Undeployment completed with status code: ".concat(response.status));
78
- return [3 /*break*/, 5];
111
+ process.exit(0);
112
+ return [3 /*break*/, 4];
79
113
  case 3:
80
114
  error_1 = _b.sent();
81
115
  spinner.fail("Failed to undeploy project.");
82
116
  (0, utils_1.logError)("Error during undeployment", error_1);
83
117
  process.exit(1);
84
- return [3 /*break*/, 5];
85
- case 4:
86
- spinner.stop();
87
- process.exit(0);
88
- return [7 /*endfinally*/];
89
- case 5: return [2 /*return*/];
118
+ return [3 /*break*/, 4];
119
+ case 4: return [2 /*return*/];
90
120
  }
91
121
  });
92
122
  });
@@ -94,10 +124,9 @@ function undeploy(options) {
94
124
  var initializeConfig = function (config, orgId) {
95
125
  var baseUrl = config["platform-base-url"] || "https://codegen-deploy-service.dainapp.com/";
96
126
  var apiKey = config["api-key"];
97
- var orgIdToBeUsed = orgId || (0, utils_1.extractOrgId)(apiKey);
98
127
  var deploymentId = config["deployment-id"];
99
128
  var environment = config["environment"];
100
129
  var serviceId = config["service-id"];
101
- var undeployUrl = "".concat(baseUrl, "/codegen-deploy/undeploy/").concat(orgIdToBeUsed, "/").concat(serviceId, "/").concat(deploymentId, "/").concat(environment);
102
- return { baseUrl: baseUrl, apiKey: apiKey, orgIdToBeUsed: orgIdToBeUsed, deploymentId: deploymentId, undeployUrl: undeployUrl };
130
+ var undeployUrl = "".concat(baseUrl, "/codegen-deploy/undeploy/").concat(orgId, "/").concat(serviceId, "/").concat(deploymentId, "/").concat(environment);
131
+ return { apiKey: apiKey, deploymentId: deploymentId, undeployUrl: undeployUrl };
103
132
  };
package/dist/index.js CHANGED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dainprotocol/cli",
3
- "version": "1.2.25",
3
+ "version": "1.2.28",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -10,13 +10,20 @@
10
10
  "bin": {
11
11
  "dain": "./dist/index.js"
12
12
  },
13
+ "scripts": {
14
+ "build": "tsc && cp -r templates dist/",
15
+ "test": "jest",
16
+ "test:watch": "jest --watch",
17
+ "test:coverage": "jest --coverage",
18
+ "prepublishOnly": "pnpm run build && pnpm test"
19
+ },
13
20
  "files": [
14
21
  "dist",
15
22
  "README.md"
16
23
  ],
17
24
  "dependencies": {
18
25
  "@ai-sdk/anthropic": "^0.0.50",
19
- "@dainprotocol/service-sdk": "^2.0.75",
26
+ "@dainprotocol/service-sdk": "^2.0.77",
20
27
  "@dainprotocol/tunnel": "^1.1.26",
21
28
  "@types/fs-extra": "^11.0.4",
22
29
  "@types/localtunnel": "^2.0.4",
@@ -26,7 +33,7 @@
26
33
  "chokidar": "^3.6.0",
27
34
  "commander": "^11.1.0",
28
35
  "dotenv": "^16.4.5",
29
- "esbuild": "^0.23.1",
36
+ "esbuild": "^0.27.2",
30
37
  "fs-extra": "^11.2.0",
31
38
  "localtunnel": "^2.0.2",
32
39
  "miniflare": "^3.20240909.1",
@@ -34,11 +41,11 @@
34
41
  },
35
42
  "devDependencies": {
36
43
  "@types/archiver": "^6.0.3",
44
+ "@types/jest": "^30.0.0",
37
45
  "@types/node": "^22.5.4",
46
+ "jest": "^30.2.0",
47
+ "ts-jest": "^29.4.6",
38
48
  "ts-node": "^10.9.2",
39
- "typescript": "^5.5.4"
40
- },
41
- "scripts": {
42
- "build": "tsc && cp -r templates dist/"
49
+ "typescript": "^5.9.3"
43
50
  }
44
- }
51
+ }