usebecky 0.0.0-stage → 0.2.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 +701 -2
- package/dist/analytics/client.d.ts +219 -0
- package/dist/analytics/client.js +923 -0
- package/dist/analytics/cmp.d.ts +20 -0
- package/dist/analytics/cmp.js +166 -0
- package/dist/analytics/context.d.ts +29 -0
- package/dist/analytics/context.js +97 -0
- package/dist/auth/client.d.ts +401 -0
- package/dist/auth/client.js +1081 -0
- package/dist/auth/webauthn.d.ts +18 -0
- package/dist/auth/webauthn.js +138 -0
- package/dist/cli/ai.d.ts +54 -0
- package/dist/cli/ai.js +202 -0
- package/dist/cli/analytics.d.ts +53 -0
- package/dist/cli/analytics.js +357 -0
- package/dist/cli/config.d.ts +75 -0
- package/dist/cli/config.js +718 -0
- package/dist/cli/db.d.ts +48 -0
- package/dist/cli/db.js +215 -0
- package/dist/cli/deploy-api.d.ts +168 -0
- package/dist/cli/deploy-api.js +177 -0
- package/dist/cli/deploy-ci.d.ts +15 -0
- package/dist/cli/deploy-ci.js +54 -0
- package/dist/cli/deploy-detect.d.ts +64 -0
- package/dist/cli/deploy-detect.js +249 -0
- package/dist/cli/deploy-files.d.ts +112 -0
- package/dist/cli/deploy-files.js +778 -0
- package/dist/cli/deploy.d.ts +10 -0
- package/dist/cli/deploy.js +430 -0
- package/dist/cli/emails.d.ts +29 -0
- package/dist/cli/emails.js +122 -0
- package/dist/cli/framework.d.ts +135 -0
- package/dist/cli/framework.js +459 -0
- package/dist/cli/functions.d.ts +59 -0
- package/dist/cli/functions.js +426 -0
- package/dist/cli/hosting.d.ts +4 -0
- package/dist/cli/hosting.js +532 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +9 -0
- package/dist/cli/payments.d.ts +35 -0
- package/dist/cli/payments.js +176 -0
- package/dist/cli/push.d.ts +36 -0
- package/dist/cli/push.js +172 -0
- package/dist/cli/run.d.ts +65 -0
- package/dist/cli/run.js +850 -0
- package/dist/cli/social.d.ts +52 -0
- package/dist/cli/social.js +532 -0
- package/dist/cli/tokens.d.ts +28 -0
- package/dist/cli/tokens.js +114 -0
- package/dist/cli/ui.d.ts +38 -0
- package/dist/cli/ui.js +140 -0
- package/dist/client.d.ts +94 -0
- package/dist/client.js +156 -0
- package/dist/db/query.d.ts +162 -0
- package/dist/db/query.js +336 -0
- package/dist/db/types.d.ts +93 -0
- package/dist/db/types.js +4 -0
- package/dist/forms/client.d.ts +65 -0
- package/dist/forms/client.js +106 -0
- package/dist/functions/client.d.ts +37 -0
- package/dist/functions/client.js +76 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +16 -0
- package/dist/lib/dashboard-paths.d.ts +4 -0
- package/dist/lib/dashboard-paths.js +8 -0
- package/dist/lib/env.d.ts +9 -0
- package/dist/lib/env.js +55 -0
- package/dist/lib/errors.d.ts +22 -0
- package/dist/lib/errors.js +90 -0
- package/dist/lib/hosted.d.ts +2 -0
- package/dist/lib/hosted.js +7 -0
- package/dist/lib/http.d.ts +59 -0
- package/dist/lib/http.js +172 -0
- package/dist/lib/jwt.d.ts +1 -0
- package/dist/lib/jwt.js +31 -0
- package/dist/lib/locale.d.ts +12 -0
- package/dist/lib/locale.js +51 -0
- package/dist/lib/pkce.d.ts +20 -0
- package/dist/lib/pkce.js +124 -0
- package/dist/lib/storage-adapter.d.ts +15 -0
- package/dist/lib/storage-adapter.js +91 -0
- package/dist/lib/types.d.ts +339 -0
- package/dist/lib/types.js +1 -0
- package/dist/newsletter/client.d.ts +140 -0
- package/dist/newsletter/client.js +85 -0
- package/dist/payments/client.d.ts +352 -0
- package/dist/payments/client.js +323 -0
- package/dist/push/client.d.ts +110 -0
- package/dist/push/client.js +179 -0
- package/dist/realtime/client.d.ts +131 -0
- package/dist/realtime/client.js +513 -0
- package/dist/server/analytics.d.ts +176 -0
- package/dist/server/analytics.js +49 -0
- package/dist/server/cache.d.ts +74 -0
- package/dist/server/cache.js +154 -0
- package/dist/server/emails.d.ts +142 -0
- package/dist/server/emails.js +123 -0
- package/dist/server/events.d.ts +357 -0
- package/dist/server/events.js +219 -0
- package/dist/server/functions.d.ts +40 -0
- package/dist/server/functions.js +1 -0
- package/dist/server/http-utils.d.ts +10 -0
- package/dist/server/http-utils.js +115 -0
- package/dist/server/index.d.ts +195 -0
- package/dist/server/index.js +314 -0
- package/dist/server/payments.d.ts +218 -0
- package/dist/server/payments.js +150 -0
- package/dist/server/push.d.ts +85 -0
- package/dist/server/push.js +37 -0
- package/dist/server/usage.d.ts +43 -0
- package/dist/server/usage.js +8 -0
- package/dist/storage/client.d.ts +143 -0
- package/dist/storage/client.js +224 -0
- package/package.json +52 -4
- package/skill/usebecky/SKILL.md +339 -0
- package/skill/usebecky/references/access-rules.md +307 -0
- package/skill/usebecky/references/addons.md +68 -0
- package/skill/usebecky/references/analytics.md +166 -0
- package/skill/usebecky/references/android.md +434 -0
- package/skill/usebecky/references/auth.md +379 -0
- package/skill/usebecky/references/cache.md +51 -0
- package/skill/usebecky/references/components.md +127 -0
- package/skill/usebecky/references/emails.md +105 -0
- package/skill/usebecky/references/expo.md +147 -0
- package/skill/usebecky/references/functions.md +99 -0
- package/skill/usebecky/references/hosting.md +119 -0
- package/skill/usebecky/references/http-api.md +233 -0
- package/skill/usebecky/references/ios.md +355 -0
- package/skill/usebecky/references/payments.md +493 -0
- package/skill/usebecky/references/realtime.md +143 -0
- package/skill/usebecky/references/scheduled-jobs.md +82 -0
- package/skill/usebecky/references/sdk.md +838 -0
- package/skill/usebecky/references/storage.md +210 -0
- package/skill/usebecky/references/templates.md +191 -0
- package/skill/usebecky/references/wordpress.md +87 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type HostingContext } from './deploy-api.ts';
|
|
2
|
+
/** The plan's per-deploy upload limit when the API doesn't say (Business: 500 MB). */
|
|
3
|
+
export declare const DEFAULT_DEPLOY_BYTES: number;
|
|
4
|
+
export declare const DEPLOY_HELP: string;
|
|
5
|
+
export declare function deployCommand(ctx: HostingContext): Promise<number>;
|
|
6
|
+
/** The URL to PUT to (relative URLs are on the API), and whether it gets the token (only the API's own origin). */
|
|
7
|
+
export declare function uploadTarget(url: string, apiUrl: string): {
|
|
8
|
+
url: string;
|
|
9
|
+
withToken: boolean;
|
|
10
|
+
};
|
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
// `npx usebecky deploy [dir] [--site <name>] [--prod] [--project <ref>] [--no-build]`: put an app online with
|
|
2
|
+
// usebecky Hosting (Business). Detects the framework (deploy-detect.ts), runs its build, collects the files of a static
|
|
3
|
+
// site or packs a Node.js server (deploy-files.ts), creates the site on the first deploy, uploads only what usebecky
|
|
4
|
+
// doesn't have yet and prints the preview and production addresses.
|
|
5
|
+
//
|
|
6
|
+
// Prebuilt only: the build runs here (or in CI); usebecky receives the output. In CI: USEBECKY_DEPLOY_TOKEN plus
|
|
7
|
+
// --project and --site (a deploy token can't create sites). Guide: docs/guide/guides/hosting.md.
|
|
8
|
+
import { spawn } from 'node:child_process';
|
|
9
|
+
import fs from 'node:fs';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import { LINK_FILE, MB, explain, hostingPath, limitOf, noProject, parseHostingArgs, productionUrlFrom, projectRef, readLink, sitePath, tokenFor, writeLink, } from "./deploy-api.js";
|
|
12
|
+
import { detectDeploy, detectPackageManager, existingOutput, scriptCommand, siteNameProblem, suggestSiteName } from "./deploy-detect.js";
|
|
13
|
+
import { buildNodeBundle, bundleBytes, collectStaticFiles, mentionsPort, packTarGz, pool, sha256, sha256File, startNeedsEnvFile } from "./deploy-files.js";
|
|
14
|
+
import { c } from "./ui.js";
|
|
15
|
+
/** The plan's per-deploy upload limit when the API doesn't say (Business: 500 MB). */
|
|
16
|
+
export const DEFAULT_DEPLOY_BYTES = 500 * 1024 * 1024;
|
|
17
|
+
const UPLOAD_CONCURRENCY = 8;
|
|
18
|
+
const HASH_CONCURRENCY = 8;
|
|
19
|
+
const RETRIES = 3;
|
|
20
|
+
export const DEPLOY_HELP = `
|
|
21
|
+
${c.bold('npx usebecky deploy')}: put your app online with usebecky Hosting (Business plan)
|
|
22
|
+
|
|
23
|
+
${c.cyan('npx usebecky deploy')} Build the app in this folder and deploy it (a preview; the first deploy goes live)
|
|
24
|
+
${c.cyan('npx usebecky deploy --prod')} Deploy and put it live on your site's address
|
|
25
|
+
${c.cyan('npx usebecky deploy dist')} Deploy a folder as it is (a built website, or plain HTML files)
|
|
26
|
+
|
|
27
|
+
--site <name> The site to deploy to (first time: the name for a new site, https://<name>.usebecky.site)
|
|
28
|
+
--project <ref> The project (default: usebecky/hosting.json, then your .env file)
|
|
29
|
+
--no-build Don't run the build first; deploy what's already built
|
|
30
|
+
-y, --yes Don't ask questions
|
|
31
|
+
In CI: set USEBECKY_DEPLOY_TOKEN and pass --project and --site. More: npx usebecky hosting help
|
|
32
|
+
`;
|
|
33
|
+
/** Runs the build attached to this terminal (its output shows as it happens). */
|
|
34
|
+
function runAttached(command, args, cwd) {
|
|
35
|
+
return new Promise((resolve) => {
|
|
36
|
+
const child = spawn(command, args, { cwd, stdio: 'inherit', shell: process.platform === 'win32' });
|
|
37
|
+
child.on('error', () => resolve(127));
|
|
38
|
+
child.on('close', (code) => resolve(code ?? 1));
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
const defaultSleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
42
|
+
export async function deployCommand(ctx) {
|
|
43
|
+
const { ui } = ctx;
|
|
44
|
+
const a = parseHostingArgs(ctx.args);
|
|
45
|
+
if (a.positional[0] === 'help') {
|
|
46
|
+
ui.write(DEPLOY_HELP);
|
|
47
|
+
return 0;
|
|
48
|
+
}
|
|
49
|
+
if (a.unknown.length || a.positional.length > 1) {
|
|
50
|
+
ui.error(a.unknown.length ? `Unknown option ${a.unknown.join(', ')}.` : `Deploy one folder at a time (got ${a.positional.join(', ')}).`);
|
|
51
|
+
ui.write(DEPLOY_HELP);
|
|
52
|
+
return 1;
|
|
53
|
+
}
|
|
54
|
+
const appDir = path.resolve(ctx.cwd, a.positional[0] ?? '.');
|
|
55
|
+
if (!fs.existsSync(appDir) || !fs.statSync(appDir).isDirectory()) {
|
|
56
|
+
ui.error(`There is no folder ${a.positional[0]}.`);
|
|
57
|
+
return 1;
|
|
58
|
+
}
|
|
59
|
+
const isApp = fs.existsSync(path.join(appDir, 'package.json'));
|
|
60
|
+
// The folder remembers its site: the app folder, or where the command runs for a folder of files.
|
|
61
|
+
const linkDir = isApp ? appDir : ctx.cwd;
|
|
62
|
+
const link = readLink(linkDir) ?? (linkDir !== ctx.cwd ? readLink(ctx.cwd) : null);
|
|
63
|
+
const ci = !!ctx.deployToken;
|
|
64
|
+
let ref = projectRef(ctx, link) ?? (appDir !== ctx.cwd ? (ctx.refOfFolder?.(appDir) ?? null) : null);
|
|
65
|
+
let siteName = a.site ?? link?.site;
|
|
66
|
+
const sleep = ctx.sleep ?? defaultSleep;
|
|
67
|
+
if (ci && (!ref || !siteName)) {
|
|
68
|
+
ui.error('With a deploy token (USEBECKY_DEPLOY_TOKEN), say which project and site to deploy to.');
|
|
69
|
+
ui.write(` ${c.dim('npx usebecky deploy --project <ref> --site <name> (or commit usebecky/hosting.json from your computer)')}`);
|
|
70
|
+
return 1;
|
|
71
|
+
}
|
|
72
|
+
if (siteName) {
|
|
73
|
+
const bad = siteNameProblem(siteName);
|
|
74
|
+
if (bad && !ci) {
|
|
75
|
+
ui.error(`“${siteName}” can't be a site name. ${bad}`);
|
|
76
|
+
return 1;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
const auth = await tokenFor(ctx, true);
|
|
80
|
+
if (!auth)
|
|
81
|
+
return 1;
|
|
82
|
+
ui.write(`\n${c.bold(c.magenta('usebecky'))} ${c.dim('deploy')}\n`);
|
|
83
|
+
// No project yet (a folder of HTML files, say): pick one.
|
|
84
|
+
if (!ref) {
|
|
85
|
+
if (ctx.yes)
|
|
86
|
+
return noProject(ctx);
|
|
87
|
+
const r = await ctx.api('GET', '/projects', undefined, auth);
|
|
88
|
+
if (r.error)
|
|
89
|
+
return explain(ctx, r.error, null);
|
|
90
|
+
const list = r.data ?? [];
|
|
91
|
+
if (!list.length) {
|
|
92
|
+
ui.error('You have no projects yet.');
|
|
93
|
+
ui.write(` ${c.dim('Create one in the dashboard, or run `npx usebecky init`.')}`);
|
|
94
|
+
return 1;
|
|
95
|
+
}
|
|
96
|
+
ref = await ui.choose('Which project is this site for?', list.map((p) => ({ label: `${p.name} ${c.dim(p.ref)}`, value: p.ref })));
|
|
97
|
+
}
|
|
98
|
+
// What usebecky has: the sites (with a session; a deploy token can only deploy).
|
|
99
|
+
let overview = null;
|
|
100
|
+
let site = null;
|
|
101
|
+
if (!ci) {
|
|
102
|
+
const o = await ctx.api('GET', hostingPath(ref), undefined, auth);
|
|
103
|
+
if (o.error)
|
|
104
|
+
return explain(ctx, o.error, ref);
|
|
105
|
+
overview = o.data;
|
|
106
|
+
if (overview && overview.available_on_plan === false)
|
|
107
|
+
return explain(ctx, { code: 'plan_required', message: '', status: 402, details: { upgrade_url: overview.upgrade_url } }, ref);
|
|
108
|
+
if (overview && overview.configured === false) {
|
|
109
|
+
ui.error('Hosting is temporarily unavailable. Your sites keep working; try deploying again in a little while.');
|
|
110
|
+
return 1;
|
|
111
|
+
}
|
|
112
|
+
const sites = overview?.sites ?? [];
|
|
113
|
+
if (!siteName && sites.length && !ctx.yes) {
|
|
114
|
+
const NEW = '\u0000new';
|
|
115
|
+
const pick = await ui.choose('Which site should this folder deploy to?', [...sites.map((s) => ({ label: `${s.name} ${c.dim(`${s.kind === 'node' ? 'Node.js app' : 'static site'}, ${s.url}`)}`, value: s.name })), { label: c.green('+ A new site'), value: NEW }], sites.length);
|
|
116
|
+
if (pick !== NEW)
|
|
117
|
+
siteName = pick;
|
|
118
|
+
}
|
|
119
|
+
// -y without --site: the site named like the app, when the project has it (else a new one with that name).
|
|
120
|
+
if (!siteName && ctx.yes && sites.some((s) => s.name === suggestSiteName(appDir)))
|
|
121
|
+
siteName = suggestSiteName(appDir);
|
|
122
|
+
site = sites.find((s) => s.name === siteName || s.id === siteName) ?? null;
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
// A deploy token may read its site (not list or create sites): its kind, whether anything is live, its address.
|
|
126
|
+
const r = await ctx.api('GET', sitePath(ref, siteName), undefined, auth);
|
|
127
|
+
if (r.error && r.error.status !== 403)
|
|
128
|
+
return explain(ctx, r.error, ref, siteName);
|
|
129
|
+
site = r.data ?? null;
|
|
130
|
+
}
|
|
131
|
+
if (site?.disabled) {
|
|
132
|
+
ui.error(`usebecky turned ${site.name} off, so it can't get new deploys.`);
|
|
133
|
+
ui.write(` ${c.dim('Write to hello@algorithmo.de if you think this is a mistake.')}`);
|
|
134
|
+
return 1;
|
|
135
|
+
}
|
|
136
|
+
// 1. What's in the folder.
|
|
137
|
+
const plan = detectDeploy(appDir, site?.kind ?? (link?.site === siteName ? link?.kind : undefined) ?? null);
|
|
138
|
+
if (plan.problem) {
|
|
139
|
+
ui.error(plan.problem.message);
|
|
140
|
+
ui.write(` ${plan.problem.fix}`);
|
|
141
|
+
return 1;
|
|
142
|
+
}
|
|
143
|
+
ui.info(`Found ${c.bold(plan.label)}: ${plan.kind === 'node' ? 'a Node.js app' : 'a static website'}`);
|
|
144
|
+
if (site && site.kind !== plan.kind) {
|
|
145
|
+
ui.error(`${site.name} is a ${site.kind === 'node' ? 'Node.js app' : 'static site'}, but this folder has ${plan.kind === 'node' ? 'a Node.js app' : 'a static website'}.`);
|
|
146
|
+
ui.write(` ${c.dim('Deploy it to a new site instead: npx usebecky deploy --site <new-name>')}`);
|
|
147
|
+
return 1;
|
|
148
|
+
}
|
|
149
|
+
// 2. Build.
|
|
150
|
+
if (plan.buildScript && !a.noBuild) {
|
|
151
|
+
const cmd = scriptCommand(detectPackageManager(appDir), plan.buildScript);
|
|
152
|
+
ui.write(`${c.cyan('→')} Building: ${c.bold(cmd.text)}${appDir !== ctx.cwd ? c.dim(` (in ${path.relative(ctx.cwd, appDir) || '.'})`) : ''}`);
|
|
153
|
+
const code = await (ctx.runBuild ?? runAttached)(cmd.command, cmd.args, appDir);
|
|
154
|
+
if (code !== 0) {
|
|
155
|
+
ui.write('');
|
|
156
|
+
ui.error(`The build failed${code === 127 ? ` (couldn't run ${cmd.command})` : ` (exit code ${code})`}. Nothing was deployed.`);
|
|
157
|
+
ui.write(` ${c.dim(`Fix the error above (try ${cmd.text} on its own), then deploy again.`)}`);
|
|
158
|
+
return 1;
|
|
159
|
+
}
|
|
160
|
+
ui.write('');
|
|
161
|
+
}
|
|
162
|
+
else if (plan.buildScript)
|
|
163
|
+
ui.info(`Not building (--no-build): deploying what's already built.`);
|
|
164
|
+
// 3. Collect what goes up.
|
|
165
|
+
const limit = limitOf(overview, 'deploy_bytes') ?? DEFAULT_DEPLOY_BYTES;
|
|
166
|
+
let files = [];
|
|
167
|
+
let archive = null;
|
|
168
|
+
let rawBytes = 0;
|
|
169
|
+
if (plan.kind === 'static') {
|
|
170
|
+
const out = existingOutput(appDir, plan);
|
|
171
|
+
if (!out) {
|
|
172
|
+
ui.error(`There is no ${plan.outputs[0]}/ folder${plan.buildScript ? ' after the build' : ''}.`);
|
|
173
|
+
ui.write(` ${c.dim(a.noBuild && plan.buildScript ? 'Build first, or deploy without --no-build.' : `Check where your build writes its files, then deploy that folder: npx usebecky deploy <folder>`)}`);
|
|
174
|
+
return 1;
|
|
175
|
+
}
|
|
176
|
+
const collected = collectStaticFiles(out, appDir);
|
|
177
|
+
if (collected.problem) {
|
|
178
|
+
ui.error(collected.problem.message);
|
|
179
|
+
ui.write(` ${collected.problem.fix}`);
|
|
180
|
+
return 1;
|
|
181
|
+
}
|
|
182
|
+
files = collected.files;
|
|
183
|
+
if (!files.length) {
|
|
184
|
+
ui.error(`${path.relative(ctx.cwd, out) || 'This folder'} has no files to deploy.`);
|
|
185
|
+
return 1;
|
|
186
|
+
}
|
|
187
|
+
rawBytes = files.reduce((n, f) => n + f.size, 0);
|
|
188
|
+
const where = path.relative(ctx.cwd, out) || '.';
|
|
189
|
+
ui.info(`Found ${files.length} file${files.length === 1 ? '' : 's'} in ${c.bold(where === '.' ? 'this folder' : `${where}/`)} (${MB(rawBytes)})`);
|
|
190
|
+
const secrets = collected.skipped.filter((s) => s.reason.startsWith('Secrets'));
|
|
191
|
+
if (secrets.length)
|
|
192
|
+
ui.write(` ${c.dim(`Left out ${secrets.map((s) => s.path).join(', ')}: .env files are never uploaded.`)}`);
|
|
193
|
+
if (!files.some((f) => f.path === 'index.html'))
|
|
194
|
+
ui.warn('There is no index.html at the top, so your site’s address shows “not found” until there is one.');
|
|
195
|
+
if (rawBytes > limit)
|
|
196
|
+
return tooBig(rawBytes);
|
|
197
|
+
await pool(files, HASH_CONCURRENCY, async (f) => {
|
|
198
|
+
f.sha256 = await sha256File(f.abs);
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
const bundle = await buildNodeBundle(appDir, plan.bundle, ctx.listPackages);
|
|
203
|
+
if (bundle.problem) {
|
|
204
|
+
ui.error(bundle.problem.message);
|
|
205
|
+
ui.write(` ${bundle.problem.fix}`);
|
|
206
|
+
return 1;
|
|
207
|
+
}
|
|
208
|
+
rawBytes = bundleBytes(bundle.entries);
|
|
209
|
+
if (bundle.allModules)
|
|
210
|
+
ui.warn('Couldn’t list your production packages (npm ls), so all of node_modules goes up. Fine, just bigger.');
|
|
211
|
+
if (bundle.nativeModules.length && !(process.platform === 'linux' && process.arch === 'x64')) {
|
|
212
|
+
ui.warn(`${bundle.nativeModules.map((m) => m.replace(/^.*node_modules\//, '')).slice(0, 3).join(', ')}${bundle.nativeModules.length > 3 ? ' and others' : ''} ${bundle.nativeModules.length === 1 ? 'has' : 'have'} native code built for this computer.`);
|
|
213
|
+
ui.write(` ${c.dim('usebecky runs Linux, so they may not start there. Deploy from GitHub Actions (npx usebecky hosting github) to build on Linux.')}`);
|
|
214
|
+
}
|
|
215
|
+
if (startNeedsEnvFile(bundle.start)) {
|
|
216
|
+
ui.warn('Your start script loads .env, which is never uploaded, so it would stop at the start.');
|
|
217
|
+
ui.write(` ${c.dim('Use --env-file-if-exists=.env (or a separate dev script), and set the values with npx usebecky hosting env set NAME=value.')}`);
|
|
218
|
+
}
|
|
219
|
+
if (plan.framework === 'node' && mentionsPort(bundle.entries, bundle.start) === false) {
|
|
220
|
+
ui.warn(`Your server should listen on process.env.PORT (usebecky sets it). Like: app.listen(process.env.PORT || 3000)`);
|
|
221
|
+
}
|
|
222
|
+
if (rawBytes > limit * 4)
|
|
223
|
+
return tooBig(rawBytes);
|
|
224
|
+
archive = await packTarGz(bundle.entries);
|
|
225
|
+
ui.info(`Packed your server: ${bundle.entries.length} files, ${MB(rawBytes)} (${MB(archive.length)} compressed). Starts with ${c.bold(bundle.start ?? 'npm start')}`);
|
|
226
|
+
if (archive.length > limit)
|
|
227
|
+
return tooBig(archive.length);
|
|
228
|
+
}
|
|
229
|
+
// 4. A new site on the first deploy (asks for its name).
|
|
230
|
+
let created = false;
|
|
231
|
+
if (!ci && !site) {
|
|
232
|
+
const made = await createSite(ctx, ref, siteName, appDir, plan.kind, auth);
|
|
233
|
+
if (!made)
|
|
234
|
+
return 1;
|
|
235
|
+
site = made;
|
|
236
|
+
siteName = made.name;
|
|
237
|
+
created = true;
|
|
238
|
+
}
|
|
239
|
+
const name = site?.name ?? siteName;
|
|
240
|
+
// 5. Tell usebecky what's coming; it answers with what it doesn't have yet.
|
|
241
|
+
const body = archive ? { archive: { size: archive.length, sha256: sha256(archive) } } : { files: files.map((f) => ({ path: f.path, size: f.size, sha256: f.sha256 })) };
|
|
242
|
+
const started = await ctx.api('POST', sitePath(ref, name, '/deploys'), body, auth);
|
|
243
|
+
if (started.error || !started.data)
|
|
244
|
+
return explain(ctx, started.error ?? { code: 'unknown', message: 'Could not start the deploy.', status: 500 }, ref, name);
|
|
245
|
+
const { deploy_id: deployId, upload = [] } = started.data;
|
|
246
|
+
// 6. Upload only the missing files.
|
|
247
|
+
const byPath = new Map(files.map((f) => [f.path, f]));
|
|
248
|
+
const items = upload.map((u) => ({ url: u.url, path: u.path, size: archive ? archive.length : (byPath.get(u.path)?.size ?? 0), read: () => (archive ? archive : fs.readFileSync(byPath.get(u.path).abs)) }));
|
|
249
|
+
const unknownPath = upload.find((u) => !archive && !byPath.has(u.path));
|
|
250
|
+
if (unknownPath) {
|
|
251
|
+
ui.error(`usebecky asked for ${unknownPath.path}, which isn't in this deploy. Try again.`);
|
|
252
|
+
return 1;
|
|
253
|
+
}
|
|
254
|
+
if (items.length) {
|
|
255
|
+
const ok = await uploadAll(ctx, items, auth, sleep);
|
|
256
|
+
if (!ok)
|
|
257
|
+
return 1;
|
|
258
|
+
}
|
|
259
|
+
else
|
|
260
|
+
ui.info(archive ? 'usebecky already has this exact server bundle.' : 'Nothing new to upload: usebecky already has every file.');
|
|
261
|
+
// 7. Finish: the first deploy of a site goes live by itself.
|
|
262
|
+
const production = a.prod || created || (!!site && !site.production_deploy_id);
|
|
263
|
+
const fin = await ctx.api('POST', sitePath(ref, name, `/deploys/${encodeURIComponent(deployId)}/finish`), { production }, auth);
|
|
264
|
+
if (fin.error || !fin.data)
|
|
265
|
+
return explain(ctx, fin.error ?? { code: 'unknown', message: 'Could not finish the deploy.', status: 500 }, ref, name);
|
|
266
|
+
const d = fin.data;
|
|
267
|
+
if (d.status === 'failed') {
|
|
268
|
+
ui.error('usebecky couldn’t finish this deploy. Nothing changed on your site; try again.');
|
|
269
|
+
return 1;
|
|
270
|
+
}
|
|
271
|
+
const live = d.production ?? production;
|
|
272
|
+
const prodUrl = site?.url || productionUrlFrom(d.preview_url, name);
|
|
273
|
+
const fileCount = archive ? 1 : files.length;
|
|
274
|
+
ui.write('');
|
|
275
|
+
ui.success(`Deployed ${c.bold(name)} ${c.dim(`(${archive ? `server bundle, ${MB(archive.length)}` : `${fileCount} file${fileCount === 1 ? '' : 's'}, ${MB(rawBytes)}`}${items.length && !archive ? `, ${items.length} new` : ''})`)}`);
|
|
276
|
+
if (d.preview_url)
|
|
277
|
+
ui.write(` Preview: ${c.cyan(d.preview_url)}`);
|
|
278
|
+
if (prodUrl)
|
|
279
|
+
ui.write(` Production: ${c.cyan(prodUrl)} ${live ? c.green('← this deploy') : c.dim('(not changed)')}`);
|
|
280
|
+
if (!live)
|
|
281
|
+
ui.write(` ${c.dim(`Put this deploy live: npx usebecky hosting promote ${d.short_id ?? deployId} (or deploy with --prod)`)}`);
|
|
282
|
+
if (plan.kind === 'node' && live)
|
|
283
|
+
ui.write(` ${c.dim('Your server starts on the first visit (a few seconds), then stays up while people use it.')}`);
|
|
284
|
+
// Lines of _headers / _redirects usebecky skipped, and why (the dashboard's deploy list shows the same).
|
|
285
|
+
const skipped = Array.isArray(d.warnings) ? d.warnings.filter((w) => typeof w === 'string') : [];
|
|
286
|
+
if (skipped.length) {
|
|
287
|
+
ui.warn(skipped.length === 1 ? 'One rule in _headers or _redirects was skipped:' : `${skipped.length} rules in _headers or _redirects were skipped:`);
|
|
288
|
+
for (const w of skipped.slice(0, 10))
|
|
289
|
+
ui.write(` ${c.dim(w)}`);
|
|
290
|
+
if (skipped.length > 10)
|
|
291
|
+
ui.write(` ${c.dim(`…and ${skipped.length - 10} more (Dashboard → Hosting → your site → Deploys).`)}`);
|
|
292
|
+
}
|
|
293
|
+
// 8. Remember the site for next time.
|
|
294
|
+
if (!ci && (link?.site !== name || link?.project !== ref || link?.kind !== plan.kind)) {
|
|
295
|
+
try {
|
|
296
|
+
writeLink(linkDir, { project: ref, site: name, kind: plan.kind });
|
|
297
|
+
ui.write(` ${c.dim(`Saved the site in ${path.relative(ctx.cwd, path.join(linkDir, LINK_FILE)) || LINK_FILE} (safe to commit): next time just run npx usebecky deploy.`)}`);
|
|
298
|
+
}
|
|
299
|
+
catch { }
|
|
300
|
+
}
|
|
301
|
+
ui.write('');
|
|
302
|
+
return 0;
|
|
303
|
+
function tooBig(bytes) {
|
|
304
|
+
ui.error(`This deploy is ${MB(bytes)}; one deploy can be at most ${MB(limit)}.`);
|
|
305
|
+
ui.write(` ${c.dim(plan.kind === 'node' ? 'Move packages you only need while building to devDependencies, and leave big files out with .usebeckyignore.' : 'Leave big files out with a .usebeckyignore file, or put videos and downloads in Storage instead.')}`);
|
|
306
|
+
return 1;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
/** Create the site (asks for a name until one is free). null: gave up or failed (already explained). */
|
|
310
|
+
async function createSite(ctx, ref, wanted, appDir, kind, auth) {
|
|
311
|
+
const { ui } = ctx;
|
|
312
|
+
let name = wanted;
|
|
313
|
+
for (let attempt = 0; attempt < 10; attempt++) {
|
|
314
|
+
if (!name) {
|
|
315
|
+
if (ctx.yes)
|
|
316
|
+
name = suggestSiteName(appDir);
|
|
317
|
+
else {
|
|
318
|
+
ui.write(`${c.bold('A new site.')} ${c.dim('Its name becomes its address: my-app → https://my-app.usebecky.site')}`);
|
|
319
|
+
name = (await ui.ask('Name for your site:', suggestSiteName(appDir))).trim().toLowerCase();
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
const bad = siteNameProblem(name);
|
|
323
|
+
if (bad) {
|
|
324
|
+
ui.error(bad);
|
|
325
|
+
if (ctx.yes)
|
|
326
|
+
return null;
|
|
327
|
+
name = undefined;
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
const r = await ctx.api('POST', hostingPath(ref, '/sites'), { name, kind }, auth);
|
|
331
|
+
if (r.data && !r.error) {
|
|
332
|
+
ui.success(`Created the site ${c.bold(r.data.name)}: ${c.cyan(r.data.url)}`);
|
|
333
|
+
return r.data;
|
|
334
|
+
}
|
|
335
|
+
const e = r.error;
|
|
336
|
+
if (e.status === 409 || e.code === 'site_name_taken' || e.code === 'name_taken') {
|
|
337
|
+
ui.error(`“${name}” is taken. Try another name.`);
|
|
338
|
+
if (ctx.yes) {
|
|
339
|
+
ui.write(` ${c.dim('Pass a different name with --site <name>.')}`);
|
|
340
|
+
return null;
|
|
341
|
+
}
|
|
342
|
+
name = undefined;
|
|
343
|
+
continue;
|
|
344
|
+
}
|
|
345
|
+
if (e.status === 400 && !ctx.yes) {
|
|
346
|
+
ui.error(e.message);
|
|
347
|
+
name = undefined;
|
|
348
|
+
continue;
|
|
349
|
+
}
|
|
350
|
+
await explain(ctx, e, ref);
|
|
351
|
+
return null;
|
|
352
|
+
}
|
|
353
|
+
return null;
|
|
354
|
+
}
|
|
355
|
+
/** The URL to PUT to (relative URLs are on the API), and whether it gets the token (only the API's own origin). */
|
|
356
|
+
export function uploadTarget(url, apiUrl) {
|
|
357
|
+
const abs = new URL(url, apiUrl.endsWith('/') ? apiUrl : `${apiUrl}/`);
|
|
358
|
+
return { url: abs.href, withToken: abs.origin === new URL(apiUrl).origin };
|
|
359
|
+
}
|
|
360
|
+
/** PUT every item, 8 at a time, each tried up to 3 times; one progress line. false: failed (already explained). */
|
|
361
|
+
async function uploadAll(ctx, items, auth, sleep) {
|
|
362
|
+
const { ui, output } = ctx;
|
|
363
|
+
const total = items.reduce((n, i) => n + i.size, 0);
|
|
364
|
+
const tty = !!output.isTTY;
|
|
365
|
+
let doneBytes = 0;
|
|
366
|
+
let doneCount = 0;
|
|
367
|
+
// One item without a path is the server bundle.
|
|
368
|
+
const what = items.length === 1 ? (items[0].path || 'your server') : `${items.length} files`;
|
|
369
|
+
const label = `Uploading ${what}`;
|
|
370
|
+
const draw = () => {
|
|
371
|
+
if (!tty)
|
|
372
|
+
return;
|
|
373
|
+
const pct = total ? Math.floor((doneBytes / total) * 100) : 100;
|
|
374
|
+
output.write(`\r\u001b[2K${c.cyan('↑')} ${label}: ${doneCount} of ${items.length}, ${MB(doneBytes)} of ${MB(total)} (${pct}%)`);
|
|
375
|
+
};
|
|
376
|
+
if (!tty)
|
|
377
|
+
ui.write(`${c.cyan('↑')} ${label} (${MB(total)})...`);
|
|
378
|
+
draw();
|
|
379
|
+
let failure = null;
|
|
380
|
+
await pool(items, UPLOAD_CONCURRENCY, async (item) => {
|
|
381
|
+
if (failure)
|
|
382
|
+
return;
|
|
383
|
+
const body = item.read();
|
|
384
|
+
const target = uploadTarget(item.url, ctx.apiUrl);
|
|
385
|
+
for (let attempt = 1;; attempt++) {
|
|
386
|
+
let status = 0;
|
|
387
|
+
let detail = '';
|
|
388
|
+
try {
|
|
389
|
+
const res = await ctx.fetch(target.url, { method: 'PUT', body: new Uint8Array(body), headers: target.withToken ? { authorization: `Bearer ${auth}` } : {} });
|
|
390
|
+
status = res.status;
|
|
391
|
+
if (res.ok) {
|
|
392
|
+
await res.arrayBuffer().catch(() => null);
|
|
393
|
+
break;
|
|
394
|
+
}
|
|
395
|
+
detail = (await res.text().catch(() => '')).slice(0, 300);
|
|
396
|
+
}
|
|
397
|
+
catch {
|
|
398
|
+
status = 0;
|
|
399
|
+
}
|
|
400
|
+
const retry = status === 0 || status === 429 || status >= 500;
|
|
401
|
+
if (!retry || attempt >= RETRIES) {
|
|
402
|
+
failure = status === 0 ? `Could not upload ${item.path}: the connection failed ${RETRIES} times.` : `Could not upload ${item.path} (HTTP ${status}${retryNote(detail)}).`;
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
await sleep(500 * 3 ** (attempt - 1));
|
|
406
|
+
}
|
|
407
|
+
doneBytes += item.size;
|
|
408
|
+
doneCount++;
|
|
409
|
+
draw();
|
|
410
|
+
});
|
|
411
|
+
if (tty)
|
|
412
|
+
output.write('\n');
|
|
413
|
+
if (failure) {
|
|
414
|
+
ui.error(failure);
|
|
415
|
+
ui.write(` ${c.dim('Nothing changed on your site. Run the same command again: files that made it are not uploaded twice.')}`);
|
|
416
|
+
return false;
|
|
417
|
+
}
|
|
418
|
+
if (!tty)
|
|
419
|
+
ui.success(`Uploaded ${what} (${MB(total)})`);
|
|
420
|
+
return true;
|
|
421
|
+
}
|
|
422
|
+
function retryNote(text) {
|
|
423
|
+
try {
|
|
424
|
+
const m = JSON.parse(text)?.error?.message;
|
|
425
|
+
return m ? `: ${m}` : '';
|
|
426
|
+
}
|
|
427
|
+
catch {
|
|
428
|
+
return '';
|
|
429
|
+
}
|
|
430
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type Ui } from './ui.ts';
|
|
2
|
+
type ApiResult<T> = {
|
|
3
|
+
data: T | null;
|
|
4
|
+
error: {
|
|
5
|
+
code: string;
|
|
6
|
+
message: string;
|
|
7
|
+
hint?: string;
|
|
8
|
+
status: number;
|
|
9
|
+
details?: any;
|
|
10
|
+
} | null;
|
|
11
|
+
};
|
|
12
|
+
export interface EmailsContext {
|
|
13
|
+
ui: Ui;
|
|
14
|
+
args: string[];
|
|
15
|
+
ref: string | null;
|
|
16
|
+
yes: boolean;
|
|
17
|
+
api: <T = any>(method: string, path: string, body?: unknown) => Promise<ApiResult<T>>;
|
|
18
|
+
signIn: () => Promise<boolean>;
|
|
19
|
+
printError: (e: {
|
|
20
|
+
message: string;
|
|
21
|
+
hint?: string;
|
|
22
|
+
status?: number;
|
|
23
|
+
}) => number;
|
|
24
|
+
noProject: () => number;
|
|
25
|
+
/** The environment (CLOUDFLARE_API_TOKEN for `add --dns cloudflare`). */
|
|
26
|
+
env?: Record<string, string | undefined>;
|
|
27
|
+
}
|
|
28
|
+
export declare function emailsCommand(ctx: EmailsContext): Promise<number>;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// `npx usebecky emails domains <list|add|check|remove>`: send your app's emails from your own domain.
|
|
2
|
+
//
|
|
3
|
+
// emails domains list the domains and their status
|
|
4
|
+
// emails domains add <domain> add one (prints the DNS records to add at your DNS provider)
|
|
5
|
+
// emails domains check <domain> check the DNS records now
|
|
6
|
+
// emails domains remove <domain> remove it (emails come from the shared address again)
|
|
7
|
+
//
|
|
8
|
+
// Server side: modules/auth/emails/domains.ts (the dashboard's Emails → Sender and Domains pages use the same routes).
|
|
9
|
+
import { dnsToken, reportDns } from "./deploy-api.js";
|
|
10
|
+
import { c } from "./ui.js";
|
|
11
|
+
const HELP = `
|
|
12
|
+
${c.bold('npx usebecky emails domains')}: send your app's emails from your own domain (paid plans)
|
|
13
|
+
|
|
14
|
+
${c.cyan('emails domains list')} The domains and their status
|
|
15
|
+
${c.cyan('emails domains add <domain>')} Add one, e.g. mail.example.com (shows the DNS records to add;
|
|
16
|
+
--dns cloudflare writes them there with CLOUDFLARE_API_TOKEN)
|
|
17
|
+
${c.cyan('emails domains check <domain>')} Check the DNS records now
|
|
18
|
+
${c.cyan('emails domains remove <domain>')} Remove it
|
|
19
|
+
|
|
20
|
+
Options: --project <ref>, -y (don't ask)
|
|
21
|
+
`;
|
|
22
|
+
const STATUS = { verified: c.green('ready'), pending: c.yellow('waiting for DNS'), failed: c.red('DNS records not found'), paused: c.yellow('paused') };
|
|
23
|
+
function printRecords(ui, d) {
|
|
24
|
+
if (d.dns_managed_by) {
|
|
25
|
+
ui.write(c.dim(' usebecky adds the DNS records for you.'));
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
ui.write(' Add these DNS records at your DNS provider:');
|
|
29
|
+
for (const r of d.records)
|
|
30
|
+
ui.write(` ${c.bold(r.type.padEnd(5))} ${r.name} ${c.cyan(r.value)}${r.priority !== undefined && r.priority !== null ? c.dim(` priority ${r.priority}`) : ''}`);
|
|
31
|
+
ui.write(c.dim(` Then: npx usebecky emails domains check ${d.domain} (DNS can take up to an hour; usebecky also checks on its own)`));
|
|
32
|
+
}
|
|
33
|
+
export async function emailsCommand(ctx) {
|
|
34
|
+
const { ui } = ctx;
|
|
35
|
+
// `--dns cloudflare` anywhere after the command; the rest are words.
|
|
36
|
+
const words = [];
|
|
37
|
+
let dns;
|
|
38
|
+
for (let i = 0; i < ctx.args.length; i++) {
|
|
39
|
+
const a = ctx.args[i];
|
|
40
|
+
if (a === '--dns')
|
|
41
|
+
dns = (ctx.args[++i] ?? '').trim().toLowerCase();
|
|
42
|
+
else if (a.startsWith('--dns='))
|
|
43
|
+
dns = a.slice(6).trim().toLowerCase();
|
|
44
|
+
else
|
|
45
|
+
words.push(a);
|
|
46
|
+
}
|
|
47
|
+
const [area, sub, name] = words;
|
|
48
|
+
if (!area || area === 'help' || (area === 'domains' && (!sub || sub === 'help'))) {
|
|
49
|
+
ui.write(HELP);
|
|
50
|
+
return area === 'help' || sub === 'help' ? 0 : 1;
|
|
51
|
+
}
|
|
52
|
+
if (area !== 'domains' || !['list', 'ls', 'add', 'check', 'remove', 'rm'].includes(sub)) {
|
|
53
|
+
ui.error(`Unknown command "emails ${ctx.args.join(' ')}".`);
|
|
54
|
+
ui.write(HELP);
|
|
55
|
+
return 1;
|
|
56
|
+
}
|
|
57
|
+
if (sub !== 'list' && sub !== 'ls' && !name) {
|
|
58
|
+
ui.error(`Which domain? npx usebecky emails domains ${sub} mail.example.com`);
|
|
59
|
+
return 1;
|
|
60
|
+
}
|
|
61
|
+
if (!ctx.ref)
|
|
62
|
+
return ctx.noProject();
|
|
63
|
+
if (!(await ctx.signIn()))
|
|
64
|
+
return 1;
|
|
65
|
+
if (sub === 'add') {
|
|
66
|
+
const provider = dnsToken(dns, ctx.env);
|
|
67
|
+
if (provider.problem) {
|
|
68
|
+
ui.error(provider.problem);
|
|
69
|
+
return 1;
|
|
70
|
+
}
|
|
71
|
+
const r = await ctx.api('POST', '/auth/emails/domains', { domain: name });
|
|
72
|
+
if (r.error || !r.data)
|
|
73
|
+
return ctx.printError(r.error ?? { message: 'Could not add the domain.' });
|
|
74
|
+
ui.success(`Added ${c.bold(r.data.domain)}. Emails will come from ${r.data.from_address} once it is ready.`);
|
|
75
|
+
if (provider.token && !r.data.dns_managed_by) {
|
|
76
|
+
// usebecky writes the records at Cloudflare (the token is used for this request only) and checks them right away.
|
|
77
|
+
const w = await ctx.api('POST', `/auth/emails/domains/${encodeURIComponent(r.data.id)}/cloudflare`, { token: provider.token });
|
|
78
|
+
if (w.error || !w.data)
|
|
79
|
+
return ctx.printError(w.error ?? { message: 'Could not write the DNS records at Cloudflare.' });
|
|
80
|
+
const ok = reportDns(ui, w.data);
|
|
81
|
+
const d = w.data.domain ?? r.data;
|
|
82
|
+
ui.write(`${c.bold(d.domain)} ${STATUS[d.status] ?? d.status}${d.status === 'verified' ? '' : c.dim(' (DNS can take a few minutes; usebecky checks on its own)')}`);
|
|
83
|
+
return ok ? 0 : 1;
|
|
84
|
+
}
|
|
85
|
+
printRecords(ui, r.data);
|
|
86
|
+
return 0;
|
|
87
|
+
}
|
|
88
|
+
const list = await ctx.api('GET', '/auth/emails/domains');
|
|
89
|
+
if (list.error || !list.data)
|
|
90
|
+
return ctx.printError(list.error ?? { message: 'Could not load the email domains.' });
|
|
91
|
+
if (sub === 'list' || sub === 'ls') {
|
|
92
|
+
if (!list.data.domains.length) {
|
|
93
|
+
ui.info(`No email domains yet. Add one: npx usebecky emails domains add mail.example.com${list.data.plan_allows ? '' : c.dim(' (needs a paid plan)')}`);
|
|
94
|
+
return 0;
|
|
95
|
+
}
|
|
96
|
+
for (const d of list.data.domains)
|
|
97
|
+
ui.write(`${c.bold(d.domain)} ${STATUS[d.status] ?? d.status} ${c.dim(d.from_address)}${d.is_default ? c.dim(' (default)') : ''}`);
|
|
98
|
+
return 0;
|
|
99
|
+
}
|
|
100
|
+
const d = list.data.domains.find((x) => x.domain === name.toLowerCase().replace(/\.$/, ''));
|
|
101
|
+
if (!d) {
|
|
102
|
+
ui.error(`${name} is not an email domain of project ${ctx.ref}.`);
|
|
103
|
+
ui.write(` ${c.dim('See them: npx usebecky emails domains list')}`);
|
|
104
|
+
return 1;
|
|
105
|
+
}
|
|
106
|
+
if (sub === 'check') {
|
|
107
|
+
const r = await ctx.api('POST', `/auth/emails/domains/${encodeURIComponent(d.id)}/check`, {});
|
|
108
|
+
if (r.error || !r.data)
|
|
109
|
+
return ctx.printError(r.error ?? { message: 'Could not check the domain.' });
|
|
110
|
+
ui.write(`${c.bold(r.data.domain)} ${STATUS[r.data.status] ?? r.data.status}`);
|
|
111
|
+
if (r.data.status !== 'verified')
|
|
112
|
+
printRecords(ui, r.data);
|
|
113
|
+
return r.data.status === 'verified' ? 0 : 1;
|
|
114
|
+
}
|
|
115
|
+
if (!ctx.yes && !(await ui.confirm(`Remove ${d.domain}? Emails then come from the shared address.`, false)))
|
|
116
|
+
return 1;
|
|
117
|
+
const r = await ctx.api('DELETE', `/auth/emails/domains/${encodeURIComponent(d.id)}`);
|
|
118
|
+
if (r.error)
|
|
119
|
+
return ctx.printError(r.error);
|
|
120
|
+
ui.success(`Removed ${d.domain}.`);
|
|
121
|
+
return 0;
|
|
122
|
+
}
|