@dainprotocol/cli 1.0.43 → 1.0.45

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/dist/utils.js CHANGED
@@ -45,6 +45,7 @@ exports.logError = logError;
45
45
  exports.logSuccess = logSuccess;
46
46
  exports.logInfo = logInfo;
47
47
  exports.getStaticFilesPath = getStaticFilesPath;
48
+ exports.extractOrgId = extractOrgId;
48
49
  var fs_1 = __importDefault(require("fs"));
49
50
  var path_1 = __importDefault(require("path"));
50
51
  var client_1 = require("@dainprotocol/tunnel/client");
@@ -52,12 +53,7 @@ var ora_1 = __importDefault(require("ora"));
52
53
  var chalk_1 = __importDefault(require("chalk"));
53
54
  var dotenv_1 = __importDefault(require("dotenv"));
54
55
  function loadEnvFiles() {
55
- var envFiles = [
56
- ".env.local",
57
- ".env",
58
- ".env.development",
59
- ".env.production",
60
- ];
56
+ var envFiles = ['.env.local', '.env', '.env.development', '.env.production'];
61
57
  envFiles.forEach(function (file) {
62
58
  var envPath = path_1.default.join(process.cwd(), file);
63
59
  if (fs_1.default.existsSync(envPath)) {
@@ -67,34 +63,37 @@ function loadEnvFiles() {
67
63
  }
68
64
  function getDainConfig(configFile) {
69
65
  loadEnvFiles(); // Load environment variables from files
70
- var defaultConfigPath = path_1.default.join(process.cwd(), "dain.json");
66
+ var defaultConfigPath = path_1.default.join(process.cwd(), 'dain.json');
71
67
  var configPath = configFile
72
68
  ? path_1.default.join(process.cwd(), configFile)
73
69
  : defaultConfigPath;
74
- console.log("Config path: ", configPath);
70
+ console.log('Config path: ', configPath);
75
71
  if (!fs_1.default.existsSync(configPath)) {
76
- throw new Error("Configuration file not found: ".concat(configPath));
72
+ logError("Configuration file not found: ".concat(configPath));
73
+ process.exit(1);
77
74
  }
78
75
  try {
79
- var configData = fs_1.default.readFileSync(configPath, "utf8");
76
+ var configData = fs_1.default.readFileSync(configPath, 'utf8');
80
77
  var config = JSON.parse(configData);
81
78
  // Validate required fields
82
- if (!config["main-file"]) {
79
+ if (!config['main-file']) {
83
80
  throw new Error("Configuration must include 'main-file'");
84
81
  }
85
82
  // Set default values for optional fields
86
- config["environment"] = config["environment"] || "development";
87
- config["version"] = config["version"] || "1.0.0";
88
- config["out-dir"] = config["out-dir"] || "dist"; // Default to 'dist' if not specified
89
- config["tunnel-base-url"] =
90
- config["tunnel-base-url"] || "wss:///tunnel.dain-local.com"; // Default value if not specified
91
- config["runtime"] = config["runtime"] || "node"; // Add this line
83
+ config['environment'] = config['environment'] || 'development';
84
+ config['version'] = config['version'] || '1.0.0';
85
+ config['out-dir'] = config['out-dir'] || 'dist'; // Default to 'dist' if not specified
86
+ config['tunnel-base-url'] =
87
+ config['tunnel-base-url'] || 'wss:///tunnel.dain-local.com'; // Default value if not specified
88
+ config['runtime'] = config['runtime'] || 'node'; // Add this line
92
89
  // Handle API key
93
- if (!config["api-key"] || config["api-key"] === "env" || config["api-key"] === "MUST PUT IN .env.development as DAIN_API_KEY=YOUR_API_KEY") {
94
- config["api-key"] = process.env.DAIN_API_KEY;
90
+ if (!config['api-key'] ||
91
+ config['api-key'] === 'env' ||
92
+ config['api-key'] === 'MUST PUT IN .env.development as DAIN_API_KEY=YOUR_API_KEY') {
93
+ config['api-key'] = process.env.DAIN_API_KEY;
95
94
  }
96
- if (!config["api-key"]) {
97
- throw new Error("API key is not set in config or DAIN_API_KEY environment variable");
95
+ if (!config['api-key']) {
96
+ throw new Error('API key is not set in config or DAIN_API_KEY environment variable');
98
97
  }
99
98
  return config;
100
99
  }
@@ -108,19 +107,21 @@ function setupProxy(port, apiKey, config) {
108
107
  return __generator(this, function (_a) {
109
108
  switch (_a.label) {
110
109
  case 0:
111
- spinner = (0, ora_1.default)("Setting up proxy...").start();
110
+ spinner = (0, ora_1.default)('Setting up proxy...').start();
112
111
  _a.label = 1;
113
112
  case 1:
114
113
  _a.trys.push([1, 3, , 4]);
115
- client = new client_1.DainTunnel(config["tunnel-base-url"] || "wss:///tunnel.dain-local.com", apiKey);
114
+ client = new client_1.DainTunnel(config['tunnel-base-url'] || 'wss:///tunnel.dain-local.com', apiKey);
116
115
  return [4 /*yield*/, client.start(parseInt(port))];
117
116
  case 2:
118
117
  tunnelUrl = _a.sent();
119
- spinner.succeed(chalk_1.default.green("\n------------------------------------------------------------\nYour service is available publicly at: ") + chalk_1.default.cyan.underline("".concat(tunnelUrl)) + chalk_1.default.green("\n------------------------------------------------------------\n"));
118
+ spinner.succeed(chalk_1.default.green("\n------------------------------------------------------------\nYour service is available publicly at: ") +
119
+ chalk_1.default.cyan.underline("".concat(tunnelUrl)) +
120
+ chalk_1.default.green("\n------------------------------------------------------------\n"));
120
121
  return [2 /*return*/, client];
121
122
  case 3:
122
123
  error_1 = _a.sent();
123
- spinner.fail(chalk_1.default.red("Error setting up proxy"));
124
+ spinner.fail(chalk_1.default.red('\nError setting up proxy'));
124
125
  console.error(chalk_1.default.red(error_1));
125
126
  return [3 /*break*/, 4];
126
127
  case 4: return [2 /*return*/];
@@ -129,17 +130,21 @@ function setupProxy(port, apiKey, config) {
129
130
  });
130
131
  }
131
132
  function logError(message, error) {
132
- console.error(chalk_1.default.red("Error: ".concat(message)));
133
+ console.error(chalk_1.default.red("\nError: ".concat(message)));
133
134
  if (error) {
134
135
  console.error(chalk_1.default.red(error));
135
136
  }
136
137
  }
137
138
  function logSuccess(message) {
138
- console.log(chalk_1.default.green("Success: ".concat(message)));
139
+ console.log(chalk_1.default.green("\nSuccess: ".concat(message)));
139
140
  }
140
141
  function logInfo(message) {
141
- console.log(chalk_1.default.blue("Info: ".concat(message)));
142
+ console.log(chalk_1.default.blue("\nInfo: ".concat(message)));
142
143
  }
143
144
  function getStaticFilesPath() {
144
- return path_1.default.join(process.cwd(), "static");
145
+ return path_1.default.join(process.cwd(), 'static');
146
+ }
147
+ function extractOrgId(apiKey) {
148
+ var apiKeySplit = apiKey === null || apiKey === void 0 ? void 0 : apiKey.split('_');
149
+ return apiKeySplit ? apiKeySplit[2] : '';
145
150
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dainprotocol/cli",
3
- "version": "1.0.43",
3
+ "version": "1.0.45",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -11,7 +11,7 @@
11
11
  "dain": "./dist/index.js"
12
12
  },
13
13
  "scripts": {
14
- "build": "tsc && cp -r templates dist/",
14
+ "build": "tsc",
15
15
  "prepublishOnly": "pnpm run build"
16
16
  },
17
17
  "files": [
@@ -26,6 +26,7 @@
26
26
  "@types/fs-extra": "^11.0.4",
27
27
  "@types/localtunnel": "^2.0.4",
28
28
  "ai": "^3.3.41",
29
+ "archiver": "^7.0.1",
29
30
  "chalk": "^4.1.2",
30
31
  "chokidar": "^3.6.0",
31
32
  "commander": "^11.1.0",
@@ -37,8 +38,9 @@
37
38
  "ora": "^3.4.0"
38
39
  },
39
40
  "devDependencies": {
41
+ "@types/archiver": "^6.0.3",
40
42
  "@types/node": "^22.5.4",
41
43
  "ts-node": "^10.9.2",
42
44
  "typescript": "^5.5.4"
43
45
  }
44
- }
46
+ }
@@ -1 +1 @@
1
- DAIN_API_KEY=
1
+ DAIN_API_KEY=NEED_TO_BE_SET
@@ -7,6 +7,5 @@
7
7
  "environment": "development",
8
8
  "version": "1.0.0",
9
9
  "tunnel-base-url": "wss:///tunnel.dain-local.com",
10
- "platform-base-url": "https://platform.dain.org",
11
- "runtime": "node"
12
- }
10
+ "deployment-id": ""
11
+ }