-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoutput.ts
More file actions
275 lines (234 loc) · 7.49 KB
/
Copy pathoutput.ts
File metadata and controls
275 lines (234 loc) · 7.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
import kleur from "kleur";
export function printSuccessOutput(config: {
projectName?: string;
root: string;
webFramework: string | null;
apiFramework: string | null;
authMode: "local" | "docker";
adminMode: "api" | "image" | "source" | "none";
ownerEmail: string;
}) {
const {
projectName,
webFramework,
apiFramework,
authMode,
adminMode,
ownerEmail,
} = config;
// Where the admin console lives: proxied by the app API at /console, or a
// standalone container on 5174. "none" scaffolds no console at all.
const consoleUrl =
adminMode === "api"
? "http://localhost:3000/console"
: adminMode === "none"
? null
: "http://localhost:5174";
const title = kleur.bold().cyan("SEAMLESS");
console.log(`
╔════════════════════════════════════════╗
║ ${title} ║
╚════════════════════════════════════════╝
`);
console.log(kleur.green("Project initialized successfully.\n"));
if (projectName) {
console.log(kleur.dim("Project directory: ") + kleur.bold(projectName));
console.log(kleur.cyan(`cd ${projectName}\n`));
}
console.log(kleur.bold("Included services:\n"));
if (webFramework) {
console.log(
" • " +
kleur.white("Web application") +
kleur.dim(` (${formatFramework(webFramework)})`),
);
}
if (apiFramework) {
console.log(
" • " +
kleur.white("API server") +
kleur.dim(` (${formatFramework(apiFramework)})`),
);
}
console.log(
" • " +
kleur.white("Auth server") +
kleur.dim(authMode === "local" ? " (local source)" : " (Docker image)"),
);
if (consoleUrl) {
console.log(
" • " +
kleur.white("Admin console") +
kleur.dim(
adminMode === "api" ? " (served by API at /console)" : " (management UI)",
),
);
}
console.log("");
console.log(kleur.bold("Next steps:\n"));
console.log(" 1. Start services");
console.log(kleur.cyan(" docker compose up\n"));
console.log(" 2. Register in the browser with " + kleur.bold(ownerEmail));
console.log(
kleur.dim(" That address is the owner, so it becomes an admin\n"),
);
console.log(kleur.bold("Available services:\n"));
console.log(" Auth: " + kleur.cyan("http://localhost:5312"));
if (apiFramework) {
console.log(" API: " + kleur.cyan("http://localhost:3000"));
}
if (webFramework) {
console.log(" Web: " + kleur.cyan("http://localhost:5173"));
}
if (consoleUrl) {
console.log(" Console:" + kleur.cyan(` ${consoleUrl}`));
}
console.log("");
console.log(kleur.bold("Notes:\n"));
console.log(kleur.dim(" • Web connects to API automatically"));
console.log(kleur.dim(" • API connects to Auth automatically"));
if (consoleUrl) {
console.log(
kleur.dim(
adminMode === "api"
? " • Admin console is served by the API at /console"
: " • Admin console uses the same auth system",
),
);
}
if (adminMode === "source") {
console.log(
kleur.dim(
" • Admin console source is in admin/, yours to edit and commit",
),
);
console.log(
kleur.dim(" • docker compose builds it from that directory, not an image"),
);
}
console.log(
kleur.dim(
` • ${ownerEmail} is the owner: registering with it grants the admin role`,
),
);
console.log(
kleur.dim(
" • The grant happens at signup, so change OWNER_EMAIL in auth before registering",
),
);
console.log(kleur.dim(" • All secrets and keys are pre-configured\n"));
console.log(
kleur.dim("Docs: ") + kleur.cyan("https://docs.seamlessauth.com\n"),
);
console.log(kleur.bold().green("Setup complete.\n"));
}
export function printManagedSuccessOutput(config: {
projectName?: string;
webFramework: string | null;
apiFramework: string | null;
authServerUrl: string;
appName: string;
databaseUrl?: string;
}) {
const {
projectName,
webFramework,
apiFramework,
authServerUrl,
appName,
databaseUrl,
} = config;
const title = kleur.bold().cyan("SEAMLESS");
console.log(`
╔════════════════════════════════════════╗
║ ${title} ║
╚════════════════════════════════════════╝
`);
console.log(kleur.green("Project connected to a managed instance.\n"));
console.log(kleur.dim("Managed application: ") + kleur.bold(appName));
console.log(kleur.dim("Auth server: ") + kleur.cyan(authServerUrl));
console.log("");
if (projectName) {
console.log(kleur.dim("Project directory: ") + kleur.bold(projectName));
console.log(kleur.cyan(`cd ${projectName}\n`));
}
console.log(kleur.bold("Included services:\n"));
if (webFramework) {
console.log(
" • " +
kleur.white("Web application") +
kleur.dim(` (${formatFramework(webFramework)})`),
);
}
if (apiFramework) {
console.log(
" • " +
kleur.white("API server") +
kleur.dim(` (${formatFramework(apiFramework)})`),
);
}
console.log(
" • " + kleur.white("Auth server") + kleur.dim(" (managed instance)"),
);
console.log("");
console.log(kleur.bold("Next steps:\n"));
// The placeholders are the only thing standing between the scaffold and a
// working database, so they lead rather than sitting in a footnote.
if (databaseUrl) {
console.log(kleur.dim(" # Database"));
console.log(
" Fill in the credentials in " +
kleur.cyan("api/.env") +
kleur.dim(" (DATABASE_URL):"),
);
console.log(" " + kleur.dim(maskDatabaseUrl(databaseUrl)));
console.log(
kleur.dim(" Copy the user and password from the dashboard.\n"),
);
}
if (apiFramework) {
console.log(kleur.dim(" # API server"));
console.log(" cd api && npm install && npm run dev\n");
}
if (webFramework) {
console.log(kleur.dim(" # Web app"));
console.log(" cd web && npm install && npm run dev\n");
}
console.log(" Sign in from the web app to confirm the session resolves.\n");
console.log(kleur.bold("Notes:\n"));
console.log(
kleur.dim(
" • The API service token was written to api/.env. Keep it out of version control.",
),
);
console.log(
kleur.dim(
" • Auth, users, and OAuth providers are managed from the dashboard, not locally.",
),
);
console.log(
kleur.dim(" • Rotate the service token anytime with the dashboard.\n"),
);
console.log(
kleur.dim("Docs: ") + kleur.cyan("https://docs.seamlessauth.com\n"),
);
console.log(kleur.bold().green("Setup complete.\n"));
}
// Belt and braces: the CLI only ever holds a placeholder connection string, but
// anything printed as a connection string gets its userinfo masked so a real one
// pasted through here could never be echoed back in full.
export function maskDatabaseUrl(url: string): string {
return url.replace(/\/\/[^@/]*@/, "//****:****@");
}
function formatFramework(name: string) {
const map: Record<string, string> = {
react: "React",
express: "Express",
angular: "Angular",
next: "Next.js",
fastapi: "FastAPI",
fastify: "Fastify",
vue: "Vue",
};
return map[name] || name;
}