dockup-cli 1.0.2 → 1.1.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/bin/dockup +2 -0
- package/dist/commands/agent.js +356 -0
- package/dist/commands/auth.js +123 -126
- package/dist/commands/database.js +315 -563
- package/dist/commands/env.js +125 -93
- package/dist/commands/link.js +148 -189
- package/dist/commands/logs.js +100 -82
- package/dist/commands/open.js +69 -41
- package/dist/commands/projects.js +128 -94
- package/dist/commands/push.js +138 -122
- package/dist/commands/service.js +143 -119
- package/dist/commands/status.js +116 -89
- package/dist/commands/workspace.js +210 -220
- package/dist/index.js +75 -179
- package/dist/lib/api.js +241 -191
- package/dist/lib/config.js +135 -142
- package/dist/lib/flags.js +36 -0
- package/dist/lib/output.js +65 -0
- package/dist/lib/target.js +40 -0
- package/dockupcli.md +185 -0
- package/package.json +13 -25
- package/dist/commands/auth.d.ts +0 -5
- package/dist/commands/database.d.ts +0 -16
- package/dist/commands/env.d.ts +0 -5
- package/dist/commands/link.d.ts +0 -2
- package/dist/commands/logs.d.ts +0 -4
- package/dist/commands/open.d.ts +0 -3
- package/dist/commands/projects.d.ts +0 -2
- package/dist/commands/push.d.ts +0 -3
- package/dist/commands/service.d.ts +0 -8
- package/dist/commands/status.d.ts +0 -1
- package/dist/commands/workspace.d.ts +0 -10
- package/dist/index.d.ts +0 -2
- package/dist/lib/api.d.ts +0 -39
- package/dist/lib/config.d.ts +0 -51
package/bin/dockup
ADDED
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target2, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target2, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target2) => (target2 = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target2, "default", { value: mod, enumerable: true }) : target2,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var agent_exports = {};
|
|
30
|
+
__export(agent_exports, {
|
|
31
|
+
deployTrigger: () => deployTrigger,
|
|
32
|
+
deploymentsView: () => deploymentsView,
|
|
33
|
+
envImport: () => envImport,
|
|
34
|
+
envRemove: () => envRemove,
|
|
35
|
+
envSet: () => envSet,
|
|
36
|
+
envView: () => envView,
|
|
37
|
+
info: () => info,
|
|
38
|
+
logsView: () => logsView,
|
|
39
|
+
registryClear: () => registryClear,
|
|
40
|
+
registrySet: () => registrySet,
|
|
41
|
+
servicesList: () => servicesList,
|
|
42
|
+
statusView: () => statusView
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(agent_exports);
|
|
45
|
+
var import_chalk = __toESM(require("chalk"));
|
|
46
|
+
var fs = __toESM(require("fs"));
|
|
47
|
+
var import_config = require("../lib/config");
|
|
48
|
+
var import_flags = require("../lib/flags");
|
|
49
|
+
var import_output = require("../lib/output");
|
|
50
|
+
var import_target = require("../lib/target");
|
|
51
|
+
var import_api = require("../lib/api");
|
|
52
|
+
function applyJson(opts) {
|
|
53
|
+
(0, import_flags.setJson)(!!opts?.json);
|
|
54
|
+
}
|
|
55
|
+
function requireAuth() {
|
|
56
|
+
if (!(0, import_config.isLoggedIn)()) (0, import_output.fail)("Not logged in. Run `dockup login` first.", { code: "not_logged_in" });
|
|
57
|
+
}
|
|
58
|
+
function target(arg) {
|
|
59
|
+
try {
|
|
60
|
+
return (0, import_target.resolveTarget)(arg);
|
|
61
|
+
} catch (e) {
|
|
62
|
+
return (0, import_output.fail)(e.message, { code: "no_target" });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function maskEnv(envVariables = []) {
|
|
66
|
+
return envVariables.map((e) => ({
|
|
67
|
+
key: e.key,
|
|
68
|
+
isSecret: !!e.isSecret,
|
|
69
|
+
value: e.isSecret ? null : e.value
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
async function servicesList(opts) {
|
|
73
|
+
applyJson(opts);
|
|
74
|
+
requireAuth();
|
|
75
|
+
try {
|
|
76
|
+
const services = await import_api.api.getAllServices();
|
|
77
|
+
const slim = services.map((s) => ({
|
|
78
|
+
target: s.target,
|
|
79
|
+
name: s.name,
|
|
80
|
+
project: s.projectName,
|
|
81
|
+
status: s.status,
|
|
82
|
+
domain: s.domain || null,
|
|
83
|
+
branch: s.branch,
|
|
84
|
+
deploymentType: s.deploymentType,
|
|
85
|
+
countryCode: s.countryCode || null
|
|
86
|
+
}));
|
|
87
|
+
(0, import_output.emit)({ count: slim.length, services: slim }, () => {
|
|
88
|
+
console.log(import_chalk.default.cyan(`
|
|
89
|
+
${slim.length} service(s)
|
|
90
|
+
`));
|
|
91
|
+
for (const s of slim) {
|
|
92
|
+
const dot = s.status === "running" ? import_chalk.default.green("\u25CF") : s.status === "error" ? import_chalk.default.red("\u25CF") : import_chalk.default.yellow("\u25CF");
|
|
93
|
+
console.log(` ${dot} ${import_chalk.default.bold(s.target.padEnd(40))} ${import_chalk.default.dim(s.status)}`);
|
|
94
|
+
}
|
|
95
|
+
console.log();
|
|
96
|
+
});
|
|
97
|
+
} catch (e) {
|
|
98
|
+
(0, import_output.fail)(e.message);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
async function info(arg, opts) {
|
|
102
|
+
applyJson(opts);
|
|
103
|
+
requireAuth();
|
|
104
|
+
const t = target(arg);
|
|
105
|
+
try {
|
|
106
|
+
const s = await import_api.api.getServiceStatus(t.projectSlug, t.serviceSlug);
|
|
107
|
+
const data = {
|
|
108
|
+
target: `${t.projectSlug}/${t.serviceSlug}`,
|
|
109
|
+
name: s.name,
|
|
110
|
+
status: s.status,
|
|
111
|
+
deploymentType: s.deploymentType,
|
|
112
|
+
repoUrl: s.repoUrl || null,
|
|
113
|
+
branch: s.branch || null,
|
|
114
|
+
domain: s.domain || null,
|
|
115
|
+
port: s.port ?? null,
|
|
116
|
+
exposedPort: s.exposedPort ?? null,
|
|
117
|
+
autoDeployEnabled: !!s.autoDeployEnabled,
|
|
118
|
+
prPreviewEnabled: !!s.prPreviewEnabled,
|
|
119
|
+
memoryLimit: s.memoryLimit ?? null,
|
|
120
|
+
cpuLimit: s.cpuLimit ?? null,
|
|
121
|
+
lastDeployedAt: s.lastDeployedAt || null,
|
|
122
|
+
lastError: s.lastError || null,
|
|
123
|
+
env: maskEnv(s.envVariables),
|
|
124
|
+
customDomains: (s.customDomains || []).map((d) => ({ domain: d.domain, status: d.status, ssl: !!d.sslEnabled })),
|
|
125
|
+
latestDeployment: (s.deployments || [])[0] || null
|
|
126
|
+
};
|
|
127
|
+
(0, import_output.emit)(data, () => {
|
|
128
|
+
console.log(import_chalk.default.cyan(`
|
|
129
|
+
${import_chalk.default.bold(data.name)} ${import_chalk.default.dim(data.target)}
|
|
130
|
+
`));
|
|
131
|
+
console.log(` ${import_chalk.default.dim("Status:")} ${data.status}`);
|
|
132
|
+
console.log(` ${import_chalk.default.dim("Repo:")} ${data.repoUrl || "N/A"} @ ${data.branch || "main"}`);
|
|
133
|
+
console.log(` ${import_chalk.default.dim("Domain:")} ${data.domain || "N/A"}`);
|
|
134
|
+
console.log(` ${import_chalk.default.dim("Type:")} ${data.deploymentType}`);
|
|
135
|
+
console.log(` ${import_chalk.default.dim("Auto-deploy:")} ${data.autoDeployEnabled}`);
|
|
136
|
+
console.log(` ${import_chalk.default.dim("Env vars:")} ${data.env.length}`);
|
|
137
|
+
console.log();
|
|
138
|
+
});
|
|
139
|
+
} catch (e) {
|
|
140
|
+
(0, import_output.fail)(e.message);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
async function statusView(arg, opts) {
|
|
144
|
+
applyJson(opts);
|
|
145
|
+
requireAuth();
|
|
146
|
+
const t = target(arg);
|
|
147
|
+
try {
|
|
148
|
+
const s = await import_api.api.getServiceStatus(t.projectSlug, t.serviceSlug);
|
|
149
|
+
const latest = (s.deployments || [])[0] || null;
|
|
150
|
+
const data = {
|
|
151
|
+
target: `${t.projectSlug}/${t.serviceSlug}`,
|
|
152
|
+
status: s.status,
|
|
153
|
+
domain: s.domain || null,
|
|
154
|
+
lastDeployedAt: s.lastDeployedAt || null,
|
|
155
|
+
lastError: s.lastError || null,
|
|
156
|
+
latestDeployment: latest && {
|
|
157
|
+
id: latest.id,
|
|
158
|
+
status: latest.status,
|
|
159
|
+
commitHash: latest.commitHash,
|
|
160
|
+
commitMessage: latest.commitMessage,
|
|
161
|
+
startedAt: latest.startedAt,
|
|
162
|
+
completedAt: latest.completedAt
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
(0, import_output.emit)(data, () => {
|
|
166
|
+
console.log(import_chalk.default.cyan(`
|
|
167
|
+
${import_chalk.default.bold(data.target)}: ${data.status}
|
|
168
|
+
`));
|
|
169
|
+
if (data.domain) console.log(` ${import_chalk.default.dim("URL:")} https://${data.domain}`);
|
|
170
|
+
if (latest) console.log(` ${import_chalk.default.dim("Last deploy:")} ${latest.status} (${(latest.commitHash || "").substring(0, 7)})`);
|
|
171
|
+
console.log();
|
|
172
|
+
});
|
|
173
|
+
} catch (e) {
|
|
174
|
+
(0, import_output.fail)(e.message);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
async function deploymentsView(arg, opts) {
|
|
178
|
+
applyJson(opts);
|
|
179
|
+
requireAuth();
|
|
180
|
+
const t = target(arg);
|
|
181
|
+
const limit = parseInt(opts?.number || "10", 10);
|
|
182
|
+
try {
|
|
183
|
+
const deployments = await import_api.api.getDeployments(t.projectSlug, t.serviceSlug, limit);
|
|
184
|
+
(0, import_output.emit)({ target: `${t.projectSlug}/${t.serviceSlug}`, count: deployments.length, deployments }, () => {
|
|
185
|
+
console.log(import_chalk.default.cyan(`
|
|
186
|
+
Deployment history \u2014 ${t.serviceSlug}
|
|
187
|
+
`));
|
|
188
|
+
for (const d of deployments) {
|
|
189
|
+
const c = d.status === "success" ? import_chalk.default.green : d.status === "failed" ? import_chalk.default.red : import_chalk.default.yellow;
|
|
190
|
+
const when = d.createdAt ? new Date(d.createdAt).toLocaleString() : "";
|
|
191
|
+
console.log(` ${c(d.status.padEnd(9))} ${(d.commitHash || "").substring(0, 7)} ${import_chalk.default.dim(when)} ${d.commitMessage || ""}`);
|
|
192
|
+
}
|
|
193
|
+
console.log();
|
|
194
|
+
});
|
|
195
|
+
} catch (e) {
|
|
196
|
+
(0, import_output.fail)(e.message);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
async function logsView(arg, opts) {
|
|
200
|
+
applyJson(opts);
|
|
201
|
+
requireAuth();
|
|
202
|
+
const t = target(arg);
|
|
203
|
+
const lines = parseInt(opts?.number || "200", 10);
|
|
204
|
+
try {
|
|
205
|
+
if (opts?.build) {
|
|
206
|
+
const res = await import_api.api.getBuildLogs(t.projectSlug, t.serviceSlug);
|
|
207
|
+
(0, import_output.emit)({ target: `${t.projectSlug}/${t.serviceSlug}`, type: "build", deployment: res.deployment, lastError: res.lastError, logs: res.logs }, () => {
|
|
208
|
+
console.log(res.logs);
|
|
209
|
+
});
|
|
210
|
+
} else {
|
|
211
|
+
const res = await import_api.api.getRuntimeLogs(t.projectSlug, t.serviceSlug, lines);
|
|
212
|
+
(0, import_output.emit)({ target: `${t.projectSlug}/${t.serviceSlug}`, type: res.type, logs: res.logs }, () => {
|
|
213
|
+
console.log(res.logs);
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
} catch (e) {
|
|
217
|
+
(0, import_output.fail)(e.message);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
async function envView(opts) {
|
|
221
|
+
applyJson(opts);
|
|
222
|
+
requireAuth();
|
|
223
|
+
const t = target(opts?.service);
|
|
224
|
+
try {
|
|
225
|
+
const s = await import_api.api.getServiceStatus(t.projectSlug, t.serviceSlug);
|
|
226
|
+
const env = maskEnv(s.envVariables);
|
|
227
|
+
(0, import_output.emit)({ target: `${t.projectSlug}/${t.serviceSlug}`, count: env.length, env }, () => {
|
|
228
|
+
for (const e of env) console.log(` ${import_chalk.default.green(e.key)}=${e.isSecret ? import_chalk.default.dim("<secret>") : e.value}`);
|
|
229
|
+
});
|
|
230
|
+
} catch (e) {
|
|
231
|
+
(0, import_output.fail)(e.message);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
async function envSet(keyValue, opts) {
|
|
235
|
+
applyJson(opts);
|
|
236
|
+
requireAuth();
|
|
237
|
+
const t = target(opts?.service);
|
|
238
|
+
const eq = keyValue.indexOf("=");
|
|
239
|
+
if (eq === -1) (0, import_output.fail)("Invalid format. Use KEY=value.", { code: "bad_format" });
|
|
240
|
+
const key = keyValue.substring(0, eq);
|
|
241
|
+
const value = keyValue.substring(eq + 1);
|
|
242
|
+
if (!key) (0, import_output.fail)("Key cannot be empty.", { code: "bad_format" });
|
|
243
|
+
try {
|
|
244
|
+
await import_api.api.setEnvVariable(t.projectSlug, t.serviceSlug, key, value, !!opts?.secret);
|
|
245
|
+
(0, import_output.ok)({ target: `${t.projectSlug}/${t.serviceSlug}`, key, secret: !!opts?.secret, hint: "redeploy to apply" }, () => {
|
|
246
|
+
console.log(import_chalk.default.green(`\u2713 set ${key}`) + import_chalk.default.dim(" (redeploy to apply)"));
|
|
247
|
+
});
|
|
248
|
+
} catch (e) {
|
|
249
|
+
(0, import_output.fail)(e.message);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
async function envRemove(key, opts) {
|
|
253
|
+
applyJson(opts);
|
|
254
|
+
requireAuth();
|
|
255
|
+
const t = target(opts?.service);
|
|
256
|
+
try {
|
|
257
|
+
await import_api.api.deleteEnvVariable(t.projectSlug, t.serviceSlug, key);
|
|
258
|
+
(0, import_output.ok)({ target: `${t.projectSlug}/${t.serviceSlug}`, key, removed: true, hint: "redeploy to apply" }, () => {
|
|
259
|
+
console.log(import_chalk.default.green(`\u2713 removed ${key}`) + import_chalk.default.dim(" (redeploy to apply)"));
|
|
260
|
+
});
|
|
261
|
+
} catch (e) {
|
|
262
|
+
(0, import_output.fail)(e.message);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
async function envImport(file, opts) {
|
|
266
|
+
applyJson(opts);
|
|
267
|
+
requireAuth();
|
|
268
|
+
const t = target(opts?.service);
|
|
269
|
+
let content;
|
|
270
|
+
try {
|
|
271
|
+
content = fs.readFileSync(file, "utf-8");
|
|
272
|
+
} catch {
|
|
273
|
+
return (0, import_output.fail)(`Cannot read file: ${file}`, { code: "file_not_found" });
|
|
274
|
+
}
|
|
275
|
+
const entries = [];
|
|
276
|
+
for (const raw of content.split("\n")) {
|
|
277
|
+
const line = raw.trim();
|
|
278
|
+
if (!line || line.startsWith("#")) continue;
|
|
279
|
+
const eq = line.indexOf("=");
|
|
280
|
+
if (eq === -1) continue;
|
|
281
|
+
let value = line.substring(eq + 1).trim();
|
|
282
|
+
if (value.startsWith('"') && value.endsWith('"') || value.startsWith("'") && value.endsWith("'")) {
|
|
283
|
+
value = value.slice(1, -1);
|
|
284
|
+
}
|
|
285
|
+
entries.push({ key: line.substring(0, eq).trim(), value });
|
|
286
|
+
}
|
|
287
|
+
const done = [];
|
|
288
|
+
try {
|
|
289
|
+
for (const e of entries) {
|
|
290
|
+
await import_api.api.setEnvVariable(t.projectSlug, t.serviceSlug, e.key, e.value, !!opts?.secret);
|
|
291
|
+
done.push(e.key);
|
|
292
|
+
}
|
|
293
|
+
(0, import_output.ok)({ target: `${t.projectSlug}/${t.serviceSlug}`, imported: done.length, keys: done, hint: "redeploy to apply" }, () => {
|
|
294
|
+
console.log(import_chalk.default.green(`\u2713 imported ${done.length} variable(s)`) + import_chalk.default.dim(" (redeploy to apply)"));
|
|
295
|
+
});
|
|
296
|
+
} catch (e) {
|
|
297
|
+
(0, import_output.fail)(e.message, { importedBeforeError: done });
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
async function registrySet(arg, opts) {
|
|
301
|
+
applyJson(opts);
|
|
302
|
+
requireAuth();
|
|
303
|
+
const t = target(arg);
|
|
304
|
+
if (!opts?.url || !opts?.user || !opts?.token) {
|
|
305
|
+
return (0, import_output.fail)("--url, --user and --token are required", { code: "bad_args" });
|
|
306
|
+
}
|
|
307
|
+
try {
|
|
308
|
+
await import_api.api.setRegistry(t.projectSlug, t.serviceSlug, opts.url, opts.user, opts.token);
|
|
309
|
+
(0, import_output.ok)({ target: `${t.projectSlug}/${t.serviceSlug}`, registryUrl: opts.url, registryUsername: opts.user, hint: "redeploy to use the private base image" }, () => {
|
|
310
|
+
console.log(import_chalk.default.green(`\u2713 registry credentials saved for ${opts.url}`) + import_chalk.default.dim(" (redeploy to apply)"));
|
|
311
|
+
});
|
|
312
|
+
} catch (e) {
|
|
313
|
+
(0, import_output.fail)(e.message);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
async function registryClear(arg, opts) {
|
|
317
|
+
applyJson(opts);
|
|
318
|
+
requireAuth();
|
|
319
|
+
const t = target(arg);
|
|
320
|
+
try {
|
|
321
|
+
await import_api.api.clearRegistry(t.projectSlug, t.serviceSlug);
|
|
322
|
+
(0, import_output.ok)({ target: `${t.projectSlug}/${t.serviceSlug}`, cleared: true }, () => {
|
|
323
|
+
console.log(import_chalk.default.green("\u2713 registry credentials cleared"));
|
|
324
|
+
});
|
|
325
|
+
} catch (e) {
|
|
326
|
+
(0, import_output.fail)(e.message);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
async function deployTrigger(arg, opts) {
|
|
330
|
+
applyJson(opts);
|
|
331
|
+
requireAuth();
|
|
332
|
+
const t = target(arg);
|
|
333
|
+
try {
|
|
334
|
+
const result = await import_api.api.deploy(t.projectSlug, t.serviceSlug, opts?.branch ? { branch: opts.branch } : void 0);
|
|
335
|
+
(0, import_output.ok)({ target: `${t.projectSlug}/${t.serviceSlug}`, deploymentId: result?.deployment?.id || null, hint: "poll `dockup status` for progress" }, () => {
|
|
336
|
+
console.log(import_chalk.default.green("\u2713 deployment triggered") + import_chalk.default.dim(` (${result?.deployment?.id || "n/a"})`));
|
|
337
|
+
});
|
|
338
|
+
} catch (e) {
|
|
339
|
+
(0, import_output.fail)(e.message);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
343
|
+
0 && (module.exports = {
|
|
344
|
+
deployTrigger,
|
|
345
|
+
deploymentsView,
|
|
346
|
+
envImport,
|
|
347
|
+
envRemove,
|
|
348
|
+
envSet,
|
|
349
|
+
envView,
|
|
350
|
+
info,
|
|
351
|
+
logsView,
|
|
352
|
+
registryClear,
|
|
353
|
+
registrySet,
|
|
354
|
+
servicesList,
|
|
355
|
+
statusView
|
|
356
|
+
});
|
package/dist/commands/auth.js
CHANGED
|
@@ -1,140 +1,137 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
37
19
|
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var auth_exports = {};
|
|
30
|
+
__export(auth_exports, {
|
|
31
|
+
login: () => login,
|
|
32
|
+
logout: () => logout,
|
|
33
|
+
whoami: () => whoami
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(auth_exports);
|
|
36
|
+
var import_chalk = __toESM(require("chalk"));
|
|
37
|
+
var import_ora = __toESM(require("ora"));
|
|
38
|
+
var import_open = __toESM(require("open"));
|
|
39
|
+
var readline = __toESM(require("readline"));
|
|
40
|
+
var import_config = require("../lib/config");
|
|
41
|
+
var import_api = require("../lib/api");
|
|
48
42
|
function question(prompt) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
});
|
|
43
|
+
const rl = readline.createInterface({
|
|
44
|
+
input: process.stdin,
|
|
45
|
+
output: process.stdout
|
|
46
|
+
});
|
|
47
|
+
return new Promise((resolve) => {
|
|
48
|
+
rl.question(prompt, (answer) => {
|
|
49
|
+
rl.close();
|
|
50
|
+
resolve(answer);
|
|
58
51
|
});
|
|
52
|
+
});
|
|
59
53
|
}
|
|
60
54
|
async function login(options) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
let token = options.token;
|
|
70
|
-
if (!token) {
|
|
71
|
-
const authUrl = 'https://app.dockup.ai/cli-auth';
|
|
72
|
-
console.log(chalk_1.default.cyan('\n Dockup CLI Login\n'));
|
|
73
|
-
console.log(chalk_1.default.dim(' Opening browser for authentication...'));
|
|
74
|
-
console.log(chalk_1.default.dim(' If browser does not open, visit:'));
|
|
75
|
-
console.log(chalk_1.default.cyan(` ${authUrl}\n`));
|
|
76
|
-
// Open browser for authentication
|
|
77
|
-
await (0, open_1.default)(authUrl);
|
|
78
|
-
// Ask for the token
|
|
79
|
-
token = await question(chalk_1.default.white(' Paste token from browser: '));
|
|
55
|
+
if ((0, import_config.isLoggedIn)()) {
|
|
56
|
+
const user = (0, import_config.getUser)();
|
|
57
|
+
console.log(import_chalk.default.yellow(`Already logged in as ${user?.email}`));
|
|
58
|
+
const answer = await question("Log in with different account? (y/N): ");
|
|
59
|
+
if (answer.toLowerCase() !== "y") {
|
|
60
|
+
return;
|
|
80
61
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
62
|
+
}
|
|
63
|
+
let token = options.token;
|
|
64
|
+
if (!token) {
|
|
65
|
+
const authUrl = "https://app.dockup.ai/cli-auth";
|
|
66
|
+
console.log(import_chalk.default.cyan("\n Dockup CLI Login\n"));
|
|
67
|
+
console.log(import_chalk.default.dim(" Opening browser for authentication..."));
|
|
68
|
+
console.log(import_chalk.default.dim(" If browser does not open, visit:"));
|
|
69
|
+
console.log(import_chalk.default.cyan(` ${authUrl}
|
|
70
|
+
`));
|
|
71
|
+
await (0, import_open.default)(authUrl);
|
|
72
|
+
token = await question(import_chalk.default.white(" Paste token from browser: "));
|
|
73
|
+
}
|
|
74
|
+
if (!token || token.trim() === "") {
|
|
75
|
+
console.log(import_chalk.default.red("\n No token provided"));
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
token = token.trim();
|
|
79
|
+
const spinner = (0, import_ora.default)("Verifying token...").start();
|
|
80
|
+
(0, import_config.setToken)(token);
|
|
81
|
+
try {
|
|
82
|
+
const user = await import_api.api.verifyToken();
|
|
83
|
+
if (!user) {
|
|
84
|
+
(0, import_config.clearToken)();
|
|
85
|
+
spinner.fail("Invalid token");
|
|
86
|
+
process.exit(1);
|
|
104
87
|
}
|
|
88
|
+
(0, import_config.setUser)(user);
|
|
89
|
+
spinner.succeed(`Logged in as ${import_chalk.default.green(user.email)}`);
|
|
90
|
+
console.log(import_chalk.default.dim(`
|
|
91
|
+
Welcome back, ${user.name}!`));
|
|
92
|
+
} catch (error) {
|
|
93
|
+
(0, import_config.clearToken)();
|
|
94
|
+
spinner.fail(`Authentication failed: ${error.message}`);
|
|
95
|
+
process.exit(1);
|
|
96
|
+
}
|
|
105
97
|
}
|
|
106
98
|
async function logout() {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
99
|
+
if (!(0, import_config.isLoggedIn)()) {
|
|
100
|
+
console.log(import_chalk.default.yellow("Not logged in"));
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const user = (0, import_config.getUser)();
|
|
104
|
+
(0, import_config.clearToken)();
|
|
105
|
+
console.log(import_chalk.default.green(`\u2713 Logged out from ${user?.email}`));
|
|
114
106
|
}
|
|
115
107
|
async function whoami() {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
(0, config_1.setUser)(user);
|
|
130
|
-
spinner.stop();
|
|
131
|
-
console.log(chalk_1.default.cyan('\n Current User:\n'));
|
|
132
|
-
console.log(` ${chalk_1.default.dim('Name:')} ${user.name}`);
|
|
133
|
-
console.log(` ${chalk_1.default.dim('Email:')} ${user.email}`);
|
|
134
|
-
console.log(` ${chalk_1.default.dim('ID:')} ${user.id}`);
|
|
135
|
-
console.log();
|
|
136
|
-
}
|
|
137
|
-
catch (error) {
|
|
138
|
-
spinner.fail(`Failed to fetch user info: ${error.message}`);
|
|
108
|
+
if (!(0, import_config.isLoggedIn)()) {
|
|
109
|
+
console.log(import_chalk.default.yellow("Not logged in"));
|
|
110
|
+
console.log(import_chalk.default.dim("Run `dockup login` to authenticate"));
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const spinner = (0, import_ora.default)("Fetching user info...").start();
|
|
114
|
+
try {
|
|
115
|
+
const user = await import_api.api.verifyToken();
|
|
116
|
+
if (!user) {
|
|
117
|
+
spinner.fail("Session expired. Please login again.");
|
|
118
|
+
(0, import_config.clearToken)();
|
|
119
|
+
return;
|
|
139
120
|
}
|
|
121
|
+
(0, import_config.setUser)(user);
|
|
122
|
+
spinner.stop();
|
|
123
|
+
console.log(import_chalk.default.cyan("\n Current User:\n"));
|
|
124
|
+
console.log(` ${import_chalk.default.dim("Name:")} ${user.name}`);
|
|
125
|
+
console.log(` ${import_chalk.default.dim("Email:")} ${user.email}`);
|
|
126
|
+
console.log(` ${import_chalk.default.dim("ID:")} ${user.id}`);
|
|
127
|
+
console.log();
|
|
128
|
+
} catch (error) {
|
|
129
|
+
spinner.fail(`Failed to fetch user info: ${error.message}`);
|
|
130
|
+
}
|
|
140
131
|
}
|
|
132
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
133
|
+
0 && (module.exports = {
|
|
134
|
+
login,
|
|
135
|
+
logout,
|
|
136
|
+
whoami
|
|
137
|
+
});
|