@getfrontline/cli 1.0.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 +319 -0
- package/dist/assets/logo3.png +0 -0
- package/dist/commands/agents/analytics.d.ts +3 -0
- package/dist/commands/agents/analytics.d.ts.map +1 -0
- package/dist/commands/agents/analytics.js +67 -0
- package/dist/commands/agents/analytics.js.map +1 -0
- package/dist/commands/agents/flows.d.ts +3 -0
- package/dist/commands/agents/flows.d.ts.map +1 -0
- package/dist/commands/agents/flows.js +47 -0
- package/dist/commands/agents/flows.js.map +1 -0
- package/dist/commands/agents/list.d.ts +3 -0
- package/dist/commands/agents/list.d.ts.map +1 -0
- package/dist/commands/agents/list.js +46 -0
- package/dist/commands/agents/list.js.map +1 -0
- package/dist/commands/api/raw.d.ts +3 -0
- package/dist/commands/api/raw.d.ts.map +1 -0
- package/dist/commands/api/raw.js +54 -0
- package/dist/commands/api/raw.js.map +1 -0
- package/dist/commands/auth/login.d.ts +3 -0
- package/dist/commands/auth/login.d.ts.map +1 -0
- package/dist/commands/auth/login.js +39 -0
- package/dist/commands/auth/login.js.map +1 -0
- package/dist/commands/auth/logout.d.ts +3 -0
- package/dist/commands/auth/logout.d.ts.map +1 -0
- package/dist/commands/auth/logout.js +16 -0
- package/dist/commands/auth/logout.js.map +1 -0
- package/dist/commands/auth/profiles.d.ts +3 -0
- package/dist/commands/auth/profiles.d.ts.map +1 -0
- package/dist/commands/auth/profiles.js +72 -0
- package/dist/commands/auth/profiles.js.map +1 -0
- package/dist/commands/auth/whoami.d.ts +3 -0
- package/dist/commands/auth/whoami.d.ts.map +1 -0
- package/dist/commands/auth/whoami.js +46 -0
- package/dist/commands/auth/whoami.js.map +1 -0
- package/dist/commands/billing/get.d.ts +3 -0
- package/dist/commands/billing/get.d.ts.map +1 -0
- package/dist/commands/billing/get.js +42 -0
- package/dist/commands/billing/get.js.map +1 -0
- package/dist/commands/object/aggregation.d.ts +3 -0
- package/dist/commands/object/aggregation.d.ts.map +1 -0
- package/dist/commands/object/aggregation.js +78 -0
- package/dist/commands/object/aggregation.js.map +1 -0
- package/dist/commands/object/export.d.ts +3 -0
- package/dist/commands/object/export.d.ts.map +1 -0
- package/dist/commands/object/export.js +98 -0
- package/dist/commands/object/export.js.map +1 -0
- package/dist/commands/object/field.d.ts +3 -0
- package/dist/commands/object/field.d.ts.map +1 -0
- package/dist/commands/object/field.js +76 -0
- package/dist/commands/object/field.js.map +1 -0
- package/dist/commands/object/file.d.ts +3 -0
- package/dist/commands/object/file.d.ts.map +1 -0
- package/dist/commands/object/file.js +105 -0
- package/dist/commands/object/file.js.map +1 -0
- package/dist/commands/object/index.d.ts +3 -0
- package/dist/commands/object/index.d.ts.map +1 -0
- package/dist/commands/object/index.js +136 -0
- package/dist/commands/object/index.js.map +1 -0
- package/dist/commands/object/note.d.ts +3 -0
- package/dist/commands/object/note.d.ts.map +1 -0
- package/dist/commands/object/note.js +62 -0
- package/dist/commands/object/note.js.map +1 -0
- package/dist/commands/object/option.d.ts +3 -0
- package/dist/commands/object/option.d.ts.map +1 -0
- package/dist/commands/object/option.js +78 -0
- package/dist/commands/object/option.js.map +1 -0
- package/dist/commands/object/record-type.d.ts +3 -0
- package/dist/commands/object/record-type.d.ts.map +1 -0
- package/dist/commands/object/record-type.js +73 -0
- package/dist/commands/object/record-type.js.map +1 -0
- package/dist/commands/object/record.d.ts +3 -0
- package/dist/commands/object/record.d.ts.map +1 -0
- package/dist/commands/object/record.js +128 -0
- package/dist/commands/object/record.js.map +1 -0
- package/dist/commands/object/relation.d.ts +3 -0
- package/dist/commands/object/relation.d.ts.map +1 -0
- package/dist/commands/object/relation.js +73 -0
- package/dist/commands/object/relation.js.map +1 -0
- package/dist/commands/object/task.d.ts +3 -0
- package/dist/commands/object/task.d.ts.map +1 -0
- package/dist/commands/object/task.js +88 -0
- package/dist/commands/object/task.js.map +1 -0
- package/dist/commands/object/view.d.ts +3 -0
- package/dist/commands/object/view.d.ts.map +1 -0
- package/dist/commands/object/view.js +118 -0
- package/dist/commands/object/view.js.map +1 -0
- package/dist/commands/setup/claudeSkills.d.ts +3 -0
- package/dist/commands/setup/claudeSkills.d.ts.map +1 -0
- package/dist/commands/setup/claudeSkills.js +84 -0
- package/dist/commands/setup/claudeSkills.js.map +1 -0
- package/dist/commands/table/aggregation.d.ts +3 -0
- package/dist/commands/table/aggregation.d.ts.map +1 -0
- package/dist/commands/table/aggregation.js +78 -0
- package/dist/commands/table/aggregation.js.map +1 -0
- package/dist/commands/table/export.d.ts +3 -0
- package/dist/commands/table/export.d.ts.map +1 -0
- package/dist/commands/table/export.js +97 -0
- package/dist/commands/table/export.js.map +1 -0
- package/dist/commands/table/field.d.ts +3 -0
- package/dist/commands/table/field.d.ts.map +1 -0
- package/dist/commands/table/field.js +76 -0
- package/dist/commands/table/field.js.map +1 -0
- package/dist/commands/table/file.d.ts +3 -0
- package/dist/commands/table/file.d.ts.map +1 -0
- package/dist/commands/table/file.js +106 -0
- package/dist/commands/table/file.js.map +1 -0
- package/dist/commands/table/index.d.ts +3 -0
- package/dist/commands/table/index.d.ts.map +1 -0
- package/dist/commands/table/index.js +142 -0
- package/dist/commands/table/index.js.map +1 -0
- package/dist/commands/table/note.d.ts +3 -0
- package/dist/commands/table/note.d.ts.map +1 -0
- package/dist/commands/table/note.js +62 -0
- package/dist/commands/table/note.js.map +1 -0
- package/dist/commands/table/option.d.ts +3 -0
- package/dist/commands/table/option.d.ts.map +1 -0
- package/dist/commands/table/option.js +78 -0
- package/dist/commands/table/option.js.map +1 -0
- package/dist/commands/table/relation.d.ts +3 -0
- package/dist/commands/table/relation.d.ts.map +1 -0
- package/dist/commands/table/relation.js +74 -0
- package/dist/commands/table/relation.js.map +1 -0
- package/dist/commands/table/row.d.ts +3 -0
- package/dist/commands/table/row.d.ts.map +1 -0
- package/dist/commands/table/row.js +124 -0
- package/dist/commands/table/row.js.map +1 -0
- package/dist/commands/table/task.d.ts +3 -0
- package/dist/commands/table/task.d.ts.map +1 -0
- package/dist/commands/table/task.js +88 -0
- package/dist/commands/table/task.js.map +1 -0
- package/dist/commands/workflows/analytics.d.ts +3 -0
- package/dist/commands/workflows/analytics.d.ts.map +1 -0
- package/dist/commands/workflows/analytics.js +60 -0
- package/dist/commands/workflows/analytics.js.map +1 -0
- package/dist/commands/workflows/list.d.ts +3 -0
- package/dist/commands/workflows/list.d.ts.map +1 -0
- package/dist/commands/workflows/list.js +47 -0
- package/dist/commands/workflows/list.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +73 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/auth.d.ts +13 -0
- package/dist/lib/auth.d.ts.map +1 -0
- package/dist/lib/auth.js +40 -0
- package/dist/lib/auth.js.map +1 -0
- package/dist/lib/config.d.ts +28 -0
- package/dist/lib/config.d.ts.map +1 -0
- package/dist/lib/config.js +77 -0
- package/dist/lib/config.js.map +1 -0
- package/dist/lib/errors.d.ts +13 -0
- package/dist/lib/errors.d.ts.map +1 -0
- package/dist/lib/errors.js +31 -0
- package/dist/lib/errors.js.map +1 -0
- package/dist/lib/globalOpts.d.ts +23 -0
- package/dist/lib/globalOpts.d.ts.map +1 -0
- package/dist/lib/globalOpts.js +40 -0
- package/dist/lib/globalOpts.js.map +1 -0
- package/dist/lib/helpEpilog.d.ts +18 -0
- package/dist/lib/helpEpilog.d.ts.map +1 -0
- package/dist/lib/helpEpilog.js +56 -0
- package/dist/lib/helpEpilog.js.map +1 -0
- package/dist/lib/httpClient.d.ts +50 -0
- package/dist/lib/httpClient.d.ts.map +1 -0
- package/dist/lib/httpClient.js +196 -0
- package/dist/lib/httpClient.js.map +1 -0
- package/dist/lib/output.d.ts +38 -0
- package/dist/lib/output.d.ts.map +1 -0
- package/dist/lib/output.js +131 -0
- package/dist/lib/output.js.map +1 -0
- package/dist/max/browserLogin.d.ts +15 -0
- package/dist/max/browserLogin.d.ts.map +1 -0
- package/dist/max/browserLogin.js +164 -0
- package/dist/max/browserLogin.js.map +1 -0
- package/dist/max/commands/auth/login.d.ts +3 -0
- package/dist/max/commands/auth/login.d.ts.map +1 -0
- package/dist/max/commands/auth/login.js +58 -0
- package/dist/max/commands/auth/login.js.map +1 -0
- package/dist/max/commands/auth/logout.d.ts +3 -0
- package/dist/max/commands/auth/logout.d.ts.map +1 -0
- package/dist/max/commands/auth/logout.js +23 -0
- package/dist/max/commands/auth/logout.js.map +1 -0
- package/dist/max/commands/auth/whoami.d.ts +3 -0
- package/dist/max/commands/auth/whoami.d.ts.map +1 -0
- package/dist/max/commands/auth/whoami.js +46 -0
- package/dist/max/commands/auth/whoami.js.map +1 -0
- package/dist/max/commands/chat/repl.d.ts +3 -0
- package/dist/max/commands/chat/repl.d.ts.map +1 -0
- package/dist/max/commands/chat/repl.js +104 -0
- package/dist/max/commands/chat/repl.js.map +1 -0
- package/dist/max/commands/chat/send.d.ts +25 -0
- package/dist/max/commands/chat/send.d.ts.map +1 -0
- package/dist/max/commands/chat/send.js +163 -0
- package/dist/max/commands/chat/send.js.map +1 -0
- package/dist/max/commands/conversations/abort.d.ts +3 -0
- package/dist/max/commands/conversations/abort.d.ts.map +1 -0
- package/dist/max/commands/conversations/abort.js +55 -0
- package/dist/max/commands/conversations/abort.js.map +1 -0
- package/dist/max/commands/conversations/get.d.ts +3 -0
- package/dist/max/commands/conversations/get.d.ts.map +1 -0
- package/dist/max/commands/conversations/get.js +42 -0
- package/dist/max/commands/conversations/get.js.map +1 -0
- package/dist/max/commands/conversations/index.d.ts +3 -0
- package/dist/max/commands/conversations/index.d.ts.map +1 -0
- package/dist/max/commands/conversations/index.js +16 -0
- package/dist/max/commands/conversations/index.js.map +1 -0
- package/dist/max/commands/conversations/list.d.ts +3 -0
- package/dist/max/commands/conversations/list.d.ts.map +1 -0
- package/dist/max/commands/conversations/list.js +35 -0
- package/dist/max/commands/conversations/list.js.map +1 -0
- package/dist/max/commands/conversations/update.d.ts +3 -0
- package/dist/max/commands/conversations/update.d.ts.map +1 -0
- package/dist/max/commands/conversations/update.js +53 -0
- package/dist/max/commands/conversations/update.js.map +1 -0
- package/dist/max/jwtDecode.d.ts +5 -0
- package/dist/max/jwtDecode.d.ts.map +1 -0
- package/dist/max/jwtDecode.js +19 -0
- package/dist/max/jwtDecode.js.map +1 -0
- package/dist/max/lib/auth.d.ts +20 -0
- package/dist/max/lib/auth.d.ts.map +1 -0
- package/dist/max/lib/auth.js +53 -0
- package/dist/max/lib/auth.js.map +1 -0
- package/dist/max/lib/httpClient.d.ts +25 -0
- package/dist/max/lib/httpClient.d.ts.map +1 -0
- package/dist/max/lib/httpClient.js +138 -0
- package/dist/max/lib/httpClient.js.map +1 -0
- package/dist/max/lib/maxResponse.d.ts +30 -0
- package/dist/max/lib/maxResponse.d.ts.map +1 -0
- package/dist/max/lib/maxResponse.js +132 -0
- package/dist/max/lib/maxResponse.js.map +1 -0
- package/dist/max/lib/publicApiPaths.d.ts +12 -0
- package/dist/max/lib/publicApiPaths.d.ts.map +1 -0
- package/dist/max/lib/publicApiPaths.js +15 -0
- package/dist/max/lib/publicApiPaths.js.map +1 -0
- package/dist/max/maxConfig.d.ts +31 -0
- package/dist/max/maxConfig.d.ts.map +1 -0
- package/dist/max/maxConfig.js +50 -0
- package/dist/max/maxConfig.js.map +1 -0
- package/dist/max/ui/banner.d.ts +3 -0
- package/dist/max/ui/banner.d.ts.map +1 -0
- package/dist/max/ui/banner.js +96 -0
- package/dist/max/ui/banner.js.map +1 -0
- package/dist/max.d.ts +3 -0
- package/dist/max.d.ts.map +1 -0
- package/dist/max.js +94 -0
- package/dist/max.js.map +1 -0
- package/dist/scripts/postinstall.d.ts +8 -0
- package/dist/scripts/postinstall.d.ts.map +1 -0
- package/dist/scripts/postinstall.js +149 -0
- package/dist/scripts/postinstall.js.map +1 -0
- package/dist/skills/aggregations/SKILL.md +122 -0
- package/dist/skills/auth-and-profiles/SKILL.md +102 -0
- package/dist/skills/crm-setup/SKILL.md +385 -0
- package/dist/skills/crud-operations/SKILL.md +287 -0
- package/dist/skills/export-and-delete/SKILL.md +96 -0
- package/dist/skills/files/SKILL.md +70 -0
- package/dist/skills/filter-and-query/SKILL.md +199 -0
- package/dist/skills/frontline-agents/SKILL.md +99 -0
- package/dist/skills/frontline-api/SKILL.md +59 -0
- package/dist/skills/frontline-billing/SKILL.md +42 -0
- package/dist/skills/frontline-workflows/SKILL.md +72 -0
- package/dist/skills/max-auth/SKILL.md +76 -0
- package/dist/skills/max-chat/SKILL.md +111 -0
- package/dist/skills/notes-and-tasks/SKILL.md +128 -0
- package/dist/skills/pipeline-setup/SKILL.md +233 -0
- package/dist/skills/record-type-management/SKILL.md +104 -0
- package/dist/skills/relations/SKILL.md +153 -0
- package/dist/skills/resource-creation/SKILL.md +86 -0
- package/dist/skills/schema-design/SKILL.md +263 -0
- package/package.json +47 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FrontlineClient = void 0;
|
|
4
|
+
exports.apiGet = apiGet;
|
|
5
|
+
const errors_1 = require("./errors");
|
|
6
|
+
const config_1 = require("./config");
|
|
7
|
+
const auth_1 = require("./auth");
|
|
8
|
+
const output_1 = require("./output");
|
|
9
|
+
class FrontlineClient {
|
|
10
|
+
apiKey;
|
|
11
|
+
baseUrl;
|
|
12
|
+
debug;
|
|
13
|
+
constructor(opts) {
|
|
14
|
+
this.apiKey = opts.apiKey;
|
|
15
|
+
this.baseUrl = opts.baseUrl;
|
|
16
|
+
this.debug = opts.debug ?? false;
|
|
17
|
+
}
|
|
18
|
+
buildHeaders(extra) {
|
|
19
|
+
return {
|
|
20
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
21
|
+
"Content-Type": "application/json",
|
|
22
|
+
"User-Agent": "frontline-cli",
|
|
23
|
+
...(extra ?? {}),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
buildUrl(path, params) {
|
|
27
|
+
const base = this.baseUrl.endsWith("/") ? this.baseUrl : this.baseUrl + "/";
|
|
28
|
+
const url = new URL(path.replace(/^\//, ""), base);
|
|
29
|
+
if (params) {
|
|
30
|
+
for (const [k, v] of Object.entries(params)) {
|
|
31
|
+
if (v !== undefined && v !== null && v !== "")
|
|
32
|
+
url.searchParams.set(k, v);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return url.toString();
|
|
36
|
+
}
|
|
37
|
+
logRequest(method, url, startedAt, status) {
|
|
38
|
+
if (!this.debug)
|
|
39
|
+
return;
|
|
40
|
+
const elapsed = Date.now() - startedAt;
|
|
41
|
+
process.stderr.write(`[DEBUG] ${method} ${url} -> ${status} (${elapsed}ms) [key=${(0, auth_1.redactToken)(this.apiKey)}]\n`);
|
|
42
|
+
}
|
|
43
|
+
async request(method, path, body, params) {
|
|
44
|
+
const url = this.buildUrl(path, params);
|
|
45
|
+
const startedAt = Date.now();
|
|
46
|
+
let res;
|
|
47
|
+
try {
|
|
48
|
+
res = await fetch(url, {
|
|
49
|
+
method,
|
|
50
|
+
headers: this.buildHeaders(),
|
|
51
|
+
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
56
|
+
(0, output_1.error)("connection_error", `Failed to connect to ${this.baseUrl}: ${message}`, output_1.EXIT_CODES.GENERAL_ERROR, { suggestion: "Check that the server is running and the base URL is correct" });
|
|
57
|
+
}
|
|
58
|
+
this.logRequest(method, url, startedAt, res.status);
|
|
59
|
+
let json;
|
|
60
|
+
try {
|
|
61
|
+
json = await res.json();
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
if (res.ok && res.status === 204)
|
|
65
|
+
return undefined;
|
|
66
|
+
(0, output_1.error)("invalid_response", `Server returned non-JSON response (HTTP ${res.status})`, output_1.EXIT_CODES.GENERAL_ERROR);
|
|
67
|
+
}
|
|
68
|
+
if (!res.ok) {
|
|
69
|
+
const exitCode = (0, output_1.httpStatusToExitCode)(res.status);
|
|
70
|
+
const payload = (json ?? {});
|
|
71
|
+
const errData = payload.error ?? payload;
|
|
72
|
+
(0, output_1.error)(errData?.code ?? "api_error", errData?.message ?? `HTTP ${res.status}`, exitCode, {
|
|
73
|
+
suggestion: errData?.suggestion,
|
|
74
|
+
details: errData?.details,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return json;
|
|
78
|
+
}
|
|
79
|
+
get(path, params) {
|
|
80
|
+
return this.request("GET", path, undefined, params);
|
|
81
|
+
}
|
|
82
|
+
post(path, body) {
|
|
83
|
+
return this.request("POST", path, body);
|
|
84
|
+
}
|
|
85
|
+
patch(path, body) {
|
|
86
|
+
return this.request("PATCH", path, body);
|
|
87
|
+
}
|
|
88
|
+
delete(path) {
|
|
89
|
+
return this.request("DELETE", path);
|
|
90
|
+
}
|
|
91
|
+
/** POST that returns the raw Response (for binary downloads, e.g. exports). */
|
|
92
|
+
async postRaw(path, body) {
|
|
93
|
+
const url = this.buildUrl(path);
|
|
94
|
+
const startedAt = Date.now();
|
|
95
|
+
const res = await fetch(url, {
|
|
96
|
+
method: "POST",
|
|
97
|
+
headers: this.buildHeaders(),
|
|
98
|
+
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
99
|
+
});
|
|
100
|
+
this.logRequest("POST", url, startedAt, res.status);
|
|
101
|
+
if (!res.ok)
|
|
102
|
+
await this.throwFromResponse(res);
|
|
103
|
+
return res;
|
|
104
|
+
}
|
|
105
|
+
/** GET that returns the raw Response (for binary downloads, e.g. file downloads). */
|
|
106
|
+
async getRaw(path) {
|
|
107
|
+
const url = this.buildUrl(path);
|
|
108
|
+
const startedAt = Date.now();
|
|
109
|
+
const res = await fetch(url, {
|
|
110
|
+
method: "GET",
|
|
111
|
+
headers: this.buildHeaders(),
|
|
112
|
+
});
|
|
113
|
+
this.logRequest("GET", url, startedAt, res.status);
|
|
114
|
+
if (!res.ok)
|
|
115
|
+
await this.throwFromResponse(res);
|
|
116
|
+
return res;
|
|
117
|
+
}
|
|
118
|
+
/** POST a multipart/form-data body (for uploads). Content-Type is set by fetch. */
|
|
119
|
+
async postMultipart(path, formData) {
|
|
120
|
+
const url = this.buildUrl(path);
|
|
121
|
+
const startedAt = Date.now();
|
|
122
|
+
const res = await fetch(url, {
|
|
123
|
+
method: "POST",
|
|
124
|
+
headers: {
|
|
125
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
126
|
+
"User-Agent": "frontline-cli",
|
|
127
|
+
},
|
|
128
|
+
body: formData,
|
|
129
|
+
});
|
|
130
|
+
this.logRequest("POST", url, startedAt, res.status);
|
|
131
|
+
if (!res.ok)
|
|
132
|
+
await this.throwFromResponse(res);
|
|
133
|
+
return (await res.json());
|
|
134
|
+
}
|
|
135
|
+
async throwFromResponse(res) {
|
|
136
|
+
const exitCode = (0, output_1.httpStatusToExitCode)(res.status);
|
|
137
|
+
let payload = {};
|
|
138
|
+
try {
|
|
139
|
+
payload = (await res.json());
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
/* noop */
|
|
143
|
+
}
|
|
144
|
+
const errData = payload.error ??
|
|
145
|
+
payload;
|
|
146
|
+
(0, output_1.error)(errData?.code ?? "api_error", errData?.message ?? `HTTP ${res.status}`, exitCode, {
|
|
147
|
+
suggestion: errData?.suggestion,
|
|
148
|
+
details: errData?.details,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
exports.FrontlineClient = FrontlineClient;
|
|
153
|
+
async function apiGet(options) {
|
|
154
|
+
const apiKey = (0, config_1.resolveApiKey)(options.apiKey, options.profile);
|
|
155
|
+
if (!apiKey) {
|
|
156
|
+
throw new errors_1.APIError("No API key found.", 401);
|
|
157
|
+
}
|
|
158
|
+
const baseUrl = (0, config_1.resolveBaseUrl)(options.baseUrl, options.profile);
|
|
159
|
+
const base = baseUrl.endsWith("/") ? baseUrl : baseUrl + "/";
|
|
160
|
+
const normalizedPath = options.path.replace(/^\//, "");
|
|
161
|
+
const url = new URL(normalizedPath, base);
|
|
162
|
+
if (options.query) {
|
|
163
|
+
for (const [key, value] of Object.entries(options.query)) {
|
|
164
|
+
if (value !== undefined && value !== "")
|
|
165
|
+
url.searchParams.set(key, value);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const startedAt = Date.now();
|
|
169
|
+
const res = await fetch(url.toString(), {
|
|
170
|
+
method: "GET",
|
|
171
|
+
headers: {
|
|
172
|
+
Authorization: `Bearer ${apiKey}`,
|
|
173
|
+
Accept: "application/json",
|
|
174
|
+
"User-Agent": "frontline-cli",
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
if (options.debug) {
|
|
178
|
+
const elapsed = Date.now() - startedAt;
|
|
179
|
+
process.stderr.write(`[DEBUG] GET ${url.toString()} -> ${res.status} (${elapsed}ms) [key=${(0, auth_1.redactToken)(apiKey)}]\n`);
|
|
180
|
+
}
|
|
181
|
+
let data;
|
|
182
|
+
try {
|
|
183
|
+
data = await res.json();
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
throw new errors_1.APIError(`Invalid JSON response from API`, res.status);
|
|
187
|
+
}
|
|
188
|
+
if (res.status >= 400) {
|
|
189
|
+
const msg = data?.message ??
|
|
190
|
+
data?.error ??
|
|
191
|
+
`API returned ${res.status}`;
|
|
192
|
+
throw new errors_1.APIError(String(msg), res.status, data);
|
|
193
|
+
}
|
|
194
|
+
return data;
|
|
195
|
+
}
|
|
196
|
+
//# sourceMappingURL=httpClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpClient.js","sourceRoot":"","sources":["../../src/lib/httpClient.ts"],"names":[],"mappings":";;;AAsNA,wBAiDC;AAvQD,qCAAoC;AACpC,qCAAyD;AACzD,iCAAqC;AACrC,qCAAoF;AAgBpF,MAAa,eAAe;IACP,MAAM,CAAS;IACf,OAAO,CAAS;IAChB,KAAK,CAAU;IAEhC,YAAY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IAEH,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;QAChB,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;QACvC,OAAO,CAAC,MAAM,CAAC,KAAK,CAChB,eAAe,GAAG,CAAC,QAAQ,EAAE,OAAO,GAAG,CAAC,MAAM,KAAK,OAAO,YAAY,IAAA,kBAAW,EAAC,MAAM,CAAC,KAAK,CACjG,CAAC;IACN,CAAC;IAED,IAAI,IAAa,CAAC;IAClB,IAAI,CAAC;QACD,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;IAC5B,CAAC;IAAC,MAAM,CAAC;QACL,MAAM,IAAI,iBAAQ,CAAC,gCAAgC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACrE,CAAC;IAED,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,EAAE,CAAC;QACpB,MAAM,GAAG,GACJ,IAAgC,EAAE,OAAO;YACzC,IAAgC,EAAE,KAAK;YACxC,gBAAgB,GAAG,CAAC,MAAM,EAAE,CAAC;QACjC,MAAM,IAAI,iBAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACtD,CAAC;IAED,OAAO,IAAS,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Output helpers for the CLI.
|
|
3
|
+
*
|
|
4
|
+
* Default contract (scripting-friendly):
|
|
5
|
+
* - `success(data)` -> JSON to stdout, exit 0
|
|
6
|
+
* - `error(code, msg, …)` -> JSON error to stdout, human line to stderr, exit with code
|
|
7
|
+
* - `info(msg)` -> human message to stderr (for progress/status, no JSON)
|
|
8
|
+
*
|
|
9
|
+
* Human-readable helpers (`printTable`, `printKeyValue`, `printSuccess`,
|
|
10
|
+
* `printError`, `printJson`) are opt-in: commands that support `--pretty` /
|
|
11
|
+
* `--table` call them instead of `success()`. Stderr lines never interfere
|
|
12
|
+
* with `| jq` or piping stdout.
|
|
13
|
+
*/
|
|
14
|
+
export declare const EXIT_CODES: {
|
|
15
|
+
readonly SUCCESS: 0;
|
|
16
|
+
readonly GENERAL_ERROR: 1;
|
|
17
|
+
readonly BAD_INPUT: 2;
|
|
18
|
+
readonly NOT_FOUND: 3;
|
|
19
|
+
readonly PERMISSION_DENIED: 4;
|
|
20
|
+
readonly CONFLICT: 5;
|
|
21
|
+
};
|
|
22
|
+
/** Maps HTTP status codes to CLI exit codes. */
|
|
23
|
+
export declare function httpStatusToExitCode(status: number): number;
|
|
24
|
+
/** Print success JSON to stdout and exit 0. */
|
|
25
|
+
export declare function success(data: unknown): never;
|
|
26
|
+
/** Print error JSON to stdout, human message to stderr, and exit with given code. */
|
|
27
|
+
export declare function error(code: string, message: string, exitCode?: number, opts?: {
|
|
28
|
+
suggestion?: string;
|
|
29
|
+
details?: Record<string, unknown>;
|
|
30
|
+
}): never;
|
|
31
|
+
/** Print a human progress/status line to stderr (never JSON). */
|
|
32
|
+
export declare function info(message: string): void;
|
|
33
|
+
export declare function printJson(data: unknown): void;
|
|
34
|
+
export declare function printTable(rows: Record<string, unknown>[] | readonly Record<string, unknown>[], columns?: string[]): void;
|
|
35
|
+
export declare function printKeyValue(data: Record<string, unknown>): void;
|
|
36
|
+
export declare function printSuccess(message: string): void;
|
|
37
|
+
export declare function printError(message: string, hint?: string): void;
|
|
38
|
+
//# sourceMappingURL=output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.d.ts","sourceRoot":"","sources":["../../src/lib/output.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AAEH,eAAO,MAAM,UAAU;;;;;;;CAOb,CAAC;AAEX,gDAAgD;AAChD,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAO3D;AAID,+CAA+C;AAC/C,wBAAgB,OAAO,CAAC,IAAI,EAAE,OAAO,GAAG,KAAK,CAG5C;AAED,qFAAqF;AACrF,wBAAgB,KAAK,CACjB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,QAAQ,GAAE,MAAiC,EAC3C,IAAI,CAAC,EAAE;IAAE,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,GAClE,KAAK,CAeP;AAED,iEAAiE;AACjE,wBAAgB,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAE1C;AAID,wBAAgB,SAAS,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,CAE7C;AAED,wBAAgB,UAAU,CACtB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EACpE,OAAO,CAAC,EAAE,MAAM,EAAE,GACnB,IAAI,CAyBN;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAOjE;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAElD;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAG/D"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.EXIT_CODES = void 0;
|
|
7
|
+
exports.httpStatusToExitCode = httpStatusToExitCode;
|
|
8
|
+
exports.success = success;
|
|
9
|
+
exports.error = error;
|
|
10
|
+
exports.info = info;
|
|
11
|
+
exports.printJson = printJson;
|
|
12
|
+
exports.printTable = printTable;
|
|
13
|
+
exports.printKeyValue = printKeyValue;
|
|
14
|
+
exports.printSuccess = printSuccess;
|
|
15
|
+
exports.printError = printError;
|
|
16
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
17
|
+
/**
|
|
18
|
+
* Output helpers for the CLI.
|
|
19
|
+
*
|
|
20
|
+
* Default contract (scripting-friendly):
|
|
21
|
+
* - `success(data)` -> JSON to stdout, exit 0
|
|
22
|
+
* - `error(code, msg, …)` -> JSON error to stdout, human line to stderr, exit with code
|
|
23
|
+
* - `info(msg)` -> human message to stderr (for progress/status, no JSON)
|
|
24
|
+
*
|
|
25
|
+
* Human-readable helpers (`printTable`, `printKeyValue`, `printSuccess`,
|
|
26
|
+
* `printError`, `printJson`) are opt-in: commands that support `--pretty` /
|
|
27
|
+
* `--table` call them instead of `success()`. Stderr lines never interfere
|
|
28
|
+
* with `| jq` or piping stdout.
|
|
29
|
+
*/
|
|
30
|
+
exports.EXIT_CODES = {
|
|
31
|
+
SUCCESS: 0,
|
|
32
|
+
GENERAL_ERROR: 1,
|
|
33
|
+
BAD_INPUT: 2,
|
|
34
|
+
NOT_FOUND: 3,
|
|
35
|
+
PERMISSION_DENIED: 4,
|
|
36
|
+
CONFLICT: 5,
|
|
37
|
+
};
|
|
38
|
+
/** Maps HTTP status codes to CLI exit codes. */
|
|
39
|
+
function httpStatusToExitCode(status) {
|
|
40
|
+
if (status >= 200 && status < 300)
|
|
41
|
+
return exports.EXIT_CODES.SUCCESS;
|
|
42
|
+
if (status === 400 || status === 422)
|
|
43
|
+
return exports.EXIT_CODES.BAD_INPUT;
|
|
44
|
+
if (status === 401 || status === 403)
|
|
45
|
+
return exports.EXIT_CODES.PERMISSION_DENIED;
|
|
46
|
+
if (status === 404)
|
|
47
|
+
return exports.EXIT_CODES.NOT_FOUND;
|
|
48
|
+
if (status === 409)
|
|
49
|
+
return exports.EXIT_CODES.CONFLICT;
|
|
50
|
+
return exports.EXIT_CODES.GENERAL_ERROR;
|
|
51
|
+
}
|
|
52
|
+
// ── Default JSON-first output ──────────────────────────
|
|
53
|
+
/** Print success JSON to stdout and exit 0. */
|
|
54
|
+
function success(data) {
|
|
55
|
+
process.stdout.write(JSON.stringify(data, null, 2) + "\n");
|
|
56
|
+
process.exit(exports.EXIT_CODES.SUCCESS);
|
|
57
|
+
}
|
|
58
|
+
/** Print error JSON to stdout, human message to stderr, and exit with given code. */
|
|
59
|
+
function error(code, message, exitCode = exports.EXIT_CODES.GENERAL_ERROR, opts) {
|
|
60
|
+
const errorObj = {
|
|
61
|
+
ok: false,
|
|
62
|
+
error: {
|
|
63
|
+
code,
|
|
64
|
+
message,
|
|
65
|
+
...(opts?.suggestion ? { suggestion: opts.suggestion } : {}),
|
|
66
|
+
...(opts?.details ? { details: opts.details } : {}),
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
process.stdout.write(JSON.stringify(errorObj, null, 2) + "\n");
|
|
70
|
+
process.stderr.write(`Error: ${message}\n`);
|
|
71
|
+
if (opts?.suggestion)
|
|
72
|
+
process.stderr.write(`Hint: ${opts.suggestion}\n`);
|
|
73
|
+
process.exit(exitCode);
|
|
74
|
+
}
|
|
75
|
+
/** Print a human progress/status line to stderr (never JSON). */
|
|
76
|
+
function info(message) {
|
|
77
|
+
process.stderr.write(message + "\n");
|
|
78
|
+
}
|
|
79
|
+
// ── Opt-in pretty helpers (used by --pretty / --table) ──
|
|
80
|
+
function printJson(data) {
|
|
81
|
+
console.log(JSON.stringify(data, null, 2));
|
|
82
|
+
}
|
|
83
|
+
function printTable(rows, columns) {
|
|
84
|
+
if (rows.length === 0) {
|
|
85
|
+
console.log(chalk_1.default.yellow("No results found."));
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const cols = columns ?? Object.keys(rows[0]);
|
|
89
|
+
const widths = {};
|
|
90
|
+
for (const col of cols) {
|
|
91
|
+
widths[col] = col.length;
|
|
92
|
+
for (const row of rows) {
|
|
93
|
+
const val = formatCell(row[col]);
|
|
94
|
+
widths[col] = Math.max(widths[col], val.length);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const header = cols.map((col) => col.toUpperCase().padEnd(widths[col])).join(" ");
|
|
98
|
+
console.log(chalk_1.default.bold(header));
|
|
99
|
+
console.log(cols.map((col) => "─".repeat(widths[col])).join(" "));
|
|
100
|
+
for (const row of rows) {
|
|
101
|
+
const line = cols.map((col) => formatCell(row[col]).padEnd(widths[col])).join(" ");
|
|
102
|
+
console.log(line);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function printKeyValue(data) {
|
|
106
|
+
const keys = Object.keys(data);
|
|
107
|
+
if (keys.length === 0)
|
|
108
|
+
return;
|
|
109
|
+
const maxKeyLen = Math.max(...keys.map((k) => k.length));
|
|
110
|
+
for (const [key, value] of Object.entries(data)) {
|
|
111
|
+
console.log(`${chalk_1.default.bold(key.padEnd(maxKeyLen))} ${formatCell(value)}`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function printSuccess(message) {
|
|
115
|
+
console.log(chalk_1.default.green(message));
|
|
116
|
+
}
|
|
117
|
+
function printError(message, hint) {
|
|
118
|
+
console.error(chalk_1.default.red(`Error: ${message}`));
|
|
119
|
+
if (hint)
|
|
120
|
+
console.error(chalk_1.default.yellow(`Hint: ${hint}`));
|
|
121
|
+
}
|
|
122
|
+
function formatCell(value) {
|
|
123
|
+
if (value === null || value === undefined)
|
|
124
|
+
return "—";
|
|
125
|
+
if (value instanceof Date)
|
|
126
|
+
return value.toISOString().split("T")[0];
|
|
127
|
+
if (typeof value === "object")
|
|
128
|
+
return JSON.stringify(value);
|
|
129
|
+
return String(value);
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=output.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"output.js","sourceRoot":"","sources":["../../src/lib/output.ts"],"names":[],"mappings":";;;;;;AA0BA,oDAOC;AAKD,0BAGC;AAGD,sBAoBC;AAGD,oBAEC;AAID,8BAEC;AAED,gCA4BC;AAED,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CAAC;IAC5D,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type BrowserLoginProvider = "google" | "microsoft" | "otp" | "email";
|
|
2
|
+
export interface BrowserLoginResult {
|
|
3
|
+
idToken: string;
|
|
4
|
+
refreshToken?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Starts a localhost HTTP server, opens the hosted login page with redirect_uri + state,
|
|
8
|
+
* and waits for GET /callback?token=...&state=... (or error query params).
|
|
9
|
+
*/
|
|
10
|
+
export declare function waitForBrowserCallback(options: {
|
|
11
|
+
loginPageBaseUrl: string;
|
|
12
|
+
provider?: BrowserLoginProvider;
|
|
13
|
+
timeoutMs: number;
|
|
14
|
+
}): Promise<BrowserLoginResult>;
|
|
15
|
+
//# sourceMappingURL=browserLogin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browserLogin.d.ts","sourceRoot":"","sources":["../../src/max/browserLogin.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,oBAAoB,GAAG,QAAQ,GAAG,WAAW,GAAG,KAAK,GAAG,OAAO,CAAC;AAE5E,MAAM,WAAW,kBAAkB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB;AA2BD;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE;IAC5C,gBAAgB,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,oBAAoB,CAAC;IAChC,SAAS,EAAE,MAAM,CAAC;CACrB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAkI9B"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.waitForBrowserCallback = waitForBrowserCallback;
|
|
7
|
+
const http_1 = __importDefault(require("http"));
|
|
8
|
+
const child_process_1 = require("child_process");
|
|
9
|
+
const crypto_1 = require("crypto");
|
|
10
|
+
function openUrlInBrowser(url) {
|
|
11
|
+
try {
|
|
12
|
+
if (process.platform === "win32") {
|
|
13
|
+
// Use PowerShell Start-Process for robust URL handling (avoids cmd.exe quoting issues with `&`).
|
|
14
|
+
(0, child_process_1.spawn)("powershell", ["-NoProfile", "-Command", "Start-Process", url], {
|
|
15
|
+
detached: true,
|
|
16
|
+
stdio: "ignore",
|
|
17
|
+
}).unref();
|
|
18
|
+
}
|
|
19
|
+
else if (process.platform === "darwin") {
|
|
20
|
+
(0, child_process_1.spawn)("open", [url], { detached: true, stdio: "ignore" }).unref();
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
(0, child_process_1.spawn)("xdg-open", [url], { detached: true, stdio: "ignore" }).unref();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
console.error("Could not open browser automatically. Open this URL manually:\n", url);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function parseCallbackUrl(requestUrl) {
|
|
31
|
+
if (!requestUrl)
|
|
32
|
+
return null;
|
|
33
|
+
const q = requestUrl.indexOf("?");
|
|
34
|
+
if (q === -1)
|
|
35
|
+
return null;
|
|
36
|
+
return new URLSearchParams(requestUrl.slice(q + 1));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Starts a localhost HTTP server, opens the hosted login page with redirect_uri + state,
|
|
40
|
+
* and waits for GET /callback?token=...&state=... (or error query params).
|
|
41
|
+
*/
|
|
42
|
+
function waitForBrowserCallback(options) {
|
|
43
|
+
return new Promise((resolve, reject) => {
|
|
44
|
+
const state = (0, crypto_1.randomBytes)(24).toString("hex");
|
|
45
|
+
let settled = false;
|
|
46
|
+
const timer = setTimeout(() => {
|
|
47
|
+
if (!settled) {
|
|
48
|
+
settled = true;
|
|
49
|
+
server.close();
|
|
50
|
+
reject(new Error(`Login timed out after ${Math.round(options.timeoutMs / 1000)}s`));
|
|
51
|
+
}
|
|
52
|
+
}, options.timeoutMs);
|
|
53
|
+
const server = http_1.default.createServer((req, res) => {
|
|
54
|
+
if (settled)
|
|
55
|
+
return;
|
|
56
|
+
const url = req.url ?? "";
|
|
57
|
+
if (!url.startsWith("/callback")) {
|
|
58
|
+
res.writeHead(404);
|
|
59
|
+
res.end("Not found");
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
// Don't keep the process alive because of this socket.
|
|
63
|
+
try {
|
|
64
|
+
req.socket?.unref?.();
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
// ignore
|
|
68
|
+
}
|
|
69
|
+
const params = parseCallbackUrl(url);
|
|
70
|
+
if (!params) {
|
|
71
|
+
res.writeHead(400, { "Content-Type": "text/html; charset=utf-8" });
|
|
72
|
+
res.end("<p>Invalid callback</p>");
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const returnedState = params.get("state");
|
|
76
|
+
const token = params.get("token");
|
|
77
|
+
const refreshToken = params.get("refresh_token") ?? undefined;
|
|
78
|
+
const err = params.get("error");
|
|
79
|
+
const errDesc = params.get("error_description");
|
|
80
|
+
if (returnedState !== state) {
|
|
81
|
+
res.writeHead(400, { "Content-Type": "text/html; charset=utf-8" });
|
|
82
|
+
res.end("<p>Invalid state. Close this tab and try again from the CLI.</p>");
|
|
83
|
+
if (!settled) {
|
|
84
|
+
settled = true;
|
|
85
|
+
clearTimeout(timer);
|
|
86
|
+
server.close();
|
|
87
|
+
reject(new Error("Invalid state parameter (possible CSRF)"));
|
|
88
|
+
}
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (err) {
|
|
92
|
+
res.writeHead(400, { "Content-Type": "text/html; charset=utf-8" });
|
|
93
|
+
res.end(`<p>Login failed: ${escapeHtml(err)}${errDesc ? ` — ${escapeHtml(errDesc)}` : ""}</p>`);
|
|
94
|
+
if (!settled) {
|
|
95
|
+
settled = true;
|
|
96
|
+
clearTimeout(timer);
|
|
97
|
+
server.close();
|
|
98
|
+
reject(new Error(errDesc || err));
|
|
99
|
+
}
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (!token) {
|
|
103
|
+
res.writeHead(400, { "Content-Type": "text/html; charset=utf-8" });
|
|
104
|
+
res.end("<p>Missing token in callback.</p>");
|
|
105
|
+
if (!settled) {
|
|
106
|
+
settled = true;
|
|
107
|
+
clearTimeout(timer);
|
|
108
|
+
server.close();
|
|
109
|
+
reject(new Error("Missing token in callback URL"));
|
|
110
|
+
}
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
|
|
114
|
+
res.end("<p>You can close this tab and return to the terminal.</p>");
|
|
115
|
+
if (!settled) {
|
|
116
|
+
settled = true;
|
|
117
|
+
clearTimeout(timer);
|
|
118
|
+
server.close();
|
|
119
|
+
resolve({ idToken: token, refreshToken });
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
server.listen(0, "127.0.0.1", () => {
|
|
123
|
+
const addr = server.address();
|
|
124
|
+
if (!addr || typeof addr === "string") {
|
|
125
|
+
server.close();
|
|
126
|
+
reject(new Error("Could not bind localhost server"));
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const port = addr.port;
|
|
130
|
+
const redirectUri = `http://127.0.0.1:${port}/callback`;
|
|
131
|
+
const loginUrl = new URL(options.loginPageBaseUrl);
|
|
132
|
+
if (options.provider) {
|
|
133
|
+
loginUrl.searchParams.set("provider", options.provider);
|
|
134
|
+
}
|
|
135
|
+
loginUrl.searchParams.set("redirect_uri", redirectUri);
|
|
136
|
+
loginUrl.searchParams.set("state", state);
|
|
137
|
+
loginUrl.searchParams.set("response_mode", "query");
|
|
138
|
+
console.log("\nOpening browser for sign-in...\nIf it does not open, visit:\n", loginUrl.toString(), "\n");
|
|
139
|
+
openUrlInBrowser(loginUrl.toString());
|
|
140
|
+
});
|
|
141
|
+
// Allow the Node.js process to exit if this is the only thing left.
|
|
142
|
+
try {
|
|
143
|
+
server.unref?.();
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
// ignore
|
|
147
|
+
}
|
|
148
|
+
server.on("error", (e) => {
|
|
149
|
+
if (!settled) {
|
|
150
|
+
settled = true;
|
|
151
|
+
clearTimeout(timer);
|
|
152
|
+
reject(e);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
function escapeHtml(s) {
|
|
158
|
+
return s
|
|
159
|
+
.replace(/&/g, "&")
|
|
160
|
+
.replace(/</g, "<")
|
|
161
|
+
.replace(/>/g, ">")
|
|
162
|
+
.replace(/"/g, """);
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=browserLogin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browserLogin.js","sourceRoot":"","sources":["../../src/max/browserLogin.ts"],"names":[],"mappings":";;;;;AAwCA,wDAsIC;AA9KD,gDAAwB;AACxB,iDAAsC;AACtC,mCAAqC;AASrC,SAAS,gBAAgB,CAAC,GAAW;IACjC,IAAI,CAAC;QACD,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;YAC/B,iGAAiG;YACjG,IAAA,qBAAK,EAAC,YAAY,EAAE,CAAC,YAAY,EAAE,UAAU,EAAE,eAAe,EAAE,GAAG,CAAC,EAAE;gBAClE,QAAQ,EAAE,IAAI;gBACd,KAAK,EAAE,QAAQ;aAClB,CAAC,CAAC,KAAK,EAAE,CAAC;QACf,CAAC;aAAM,IAAI,OAAO,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;YACvC,IAAA,qBAAK,EAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,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AAC;YAEpD,OAAO,CAAC,GAAG,CACP,iEAAiE,EACjE,QAAQ,CAAC,QAAQ,EAAE,EACnB,IAAI,CACP,CAAC;YACF,gBAAgB,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC1C,CAAC,CAAC,CAAC;QAEH,oEAAoE;QACpE,IAAI,CAAC;YACA,MAAc,CAAC,KAAK,EAAE,EAAE,CAAC;QAC9B,CAAC;QAAC,MAAM,CAAC;YACL,SAAS;QACb,CAAC;QAED,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE;YACrB,IAAI,CAAC,OAAO,EAAE,CAAC;gBACX,OAAO,GAAG,IAAI,CAAC;gBACf,YAAY,CAAC,KAAK,CAAC,CAAC;gBACpB,MAAM,CAAC,CAAC,CAAC,CAAC;YACd,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC;AAED,SAAS,UAAU,CAAC,CAAS;IACzB,OAAO,CAAC;SACH,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;SACtB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../../../src/max/commands/auth/login.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAmCpC,eAAO,MAAM,eAAe,SAyDtB,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.maxLoginCommand = void 0;
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const maxConfig_1 = require("../../maxConfig");
|
|
6
|
+
const config_1 = require("../../../lib/config");
|
|
7
|
+
const output_1 = require("../../../lib/output");
|
|
8
|
+
const auth_1 = require("../../../lib/auth");
|
|
9
|
+
const banner_1 = require("../../ui/banner");
|
|
10
|
+
const helpEpilog_1 = require("../../../lib/helpEpilog");
|
|
11
|
+
exports.maxLoginCommand = new commander_1.Command("login")
|
|
12
|
+
.description("Store a per-user API key on the chosen profile. Saves the key to BOTH the Max store and the Frontline store under the same profile name, so `max` and `frontline` commands share credentials.")
|
|
13
|
+
.argument("<api-key>", "Your Frontline per-user API key (generated in the Frontline web app)")
|
|
14
|
+
.option("--profile <name>", helpEpilog_1.MAX_PROFILE_OPTION)
|
|
15
|
+
.option("--base-url <url>", `Public API base URL for this profile (…/public/v1; default: ${(0, config_1.getDefaultBaseUrl)()})`)
|
|
16
|
+
.addHelpText("after", `\n${helpEpilog_1.MAX_AUTH_LOGIN_EPILOG}\n`)
|
|
17
|
+
.action(async (apiKey, options, cmd) => {
|
|
18
|
+
try {
|
|
19
|
+
await (0, banner_1.printMaxWelcome)();
|
|
20
|
+
const trimmed = apiKey.trim();
|
|
21
|
+
if (!trimmed) {
|
|
22
|
+
(0, output_1.printError)("API key cannot be empty.");
|
|
23
|
+
process.exitCode = 1;
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const allOpts = typeof cmd.optsWithGlobals === "function" ? cmd.optsWithGlobals() : options;
|
|
27
|
+
const profileName = allOpts.profile ?? (0, maxConfig_1.getMaxCurrentProfile)();
|
|
28
|
+
if (allOpts.profile) {
|
|
29
|
+
(0, maxConfig_1.setMaxCurrentProfile)(profileName);
|
|
30
|
+
(0, config_1.setCurrentProfile)(profileName);
|
|
31
|
+
}
|
|
32
|
+
const existingMax = (0, maxConfig_1.getMaxProfile)(profileName);
|
|
33
|
+
(0, maxConfig_1.setMaxProfile)(profileName, {
|
|
34
|
+
...existingMax,
|
|
35
|
+
apiKey: trimmed,
|
|
36
|
+
});
|
|
37
|
+
const existingFront = (0, config_1.getProfile)(profileName);
|
|
38
|
+
const nextFrontBaseUrl = allOpts.baseUrl?.trim() ||
|
|
39
|
+
existingFront?.baseUrl ||
|
|
40
|
+
(0, config_1.getDefaultBaseUrl)();
|
|
41
|
+
(0, config_1.setProfile)(profileName, {
|
|
42
|
+
apiKey: trimmed,
|
|
43
|
+
baseUrl: nextFrontBaseUrl,
|
|
44
|
+
});
|
|
45
|
+
(0, output_1.printSuccess)(`API key saved to profile "${profileName}" (shared with Frontline CLI).`);
|
|
46
|
+
(0, output_1.printKeyValue)({
|
|
47
|
+
profile: profileName,
|
|
48
|
+
keyPreview: (0, auth_1.redactToken)(trimmed),
|
|
49
|
+
publicApiBaseUrl: nextFrontBaseUrl,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
54
|
+
(0, output_1.printError)(message);
|
|
55
|
+
process.exitCode = 1;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
//# sourceMappingURL=login.js.map
|