@anybuild-ai/ab 0.8.0 → 0.9.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/CHANGELOG.md +13 -0
- package/README.md +28 -8
- package/dist/auth/device-login.d.ts +58 -0
- package/dist/auth/device-login.d.ts.map +1 -0
- package/dist/auth/device-login.js +184 -0
- package/dist/auth/device-login.js.map +1 -0
- package/dist/auth/perform-logout.d.ts.map +1 -1
- package/dist/auth/perform-logout.js +6 -1
- package/dist/auth/perform-logout.js.map +1 -1
- package/dist/commands/login.d.ts.map +1 -1
- package/dist/commands/login.js +120 -15
- package/dist/commands/login.js.map +1 -1
- package/dist/commands/pull.d.ts.map +1 -1
- package/dist/commands/pull.js +6 -0
- package/dist/commands/pull.js.map +1 -1
- package/dist/commands/user.js +9 -5
- package/dist/commands/user.js.map +1 -1
- package/dist/config/global-config.d.ts +4 -1
- package/dist/config/global-config.d.ts.map +1 -1
- package/dist/config/global-config.js +29 -0
- package/dist/config/global-config.js.map +1 -1
- package/dist/config/types.d.ts +12 -0
- package/dist/config/types.d.ts.map +1 -1
- package/dist/export/import-batch.d.ts +10 -0
- package/dist/export/import-batch.d.ts.map +1 -1
- package/dist/export/import-batch.js +117 -16
- package/dist/export/import-batch.js.map +1 -1
- package/dist/export/sync.d.ts +5 -0
- package/dist/export/sync.d.ts.map +1 -1
- package/dist/export/sync.js +39 -0
- package/dist/export/sync.js.map +1 -1
- package/dist/io/read-credentials.d.ts +5 -1
- package/dist/io/read-credentials.d.ts.map +1 -1
- package/dist/io/read-credentials.js +47 -15
- package/dist/io/read-credentials.js.map +1 -1
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +11 -4
- package/dist/router.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.9.0
|
|
4
|
+
|
|
5
|
+
- `anybuild login --link <host-url>`: sign in with a link instead of a password. The CLI prints a link; the person opens it in any browser and signs in on the environment's own page (two-factor included), and the CLI stores the session as usual. The CLI never sees the password, so agents and remote machines can sign in to any number of environments without stored credentials. The link works for 10 minutes; running the command again reuses a link that still works. `--no-wait` checks once and exits 0 (signed in) or 2 (still waiting), for agents whose commands time out. `--label <name>` names the session (default: the machine's name), `--username <email>` pre-fills the page. Waiting links are kept in `~/.ab/config.json` (`pending_logins`, secret only) and dropped by `logout`.
|
|
6
|
+
- Host routes (environment, `api_token_handler`): `POST /api/auth/device` starts a link sign-in (`{ device_code, login_url, expires_in, interval }`); the authorize page approves it for the built-in client `anybuild-cli` instead of redirecting; `POST /api/auth/device/token` exchanges `device_code` once (`authorization_pending`, `expired_token`). 10 new links per address per 10 minutes.
|
|
7
|
+
|
|
8
|
+
## 0.8.1
|
|
9
|
+
|
|
10
|
+
- `pull` no longer overwrites unpushed edits: when the server changed (or deleted, or renamed) a file you edited and have not pushed, pull lists those files and changes nothing. Push first, or take the server copy with `pull --force <path>`. Help and README say that `status` is local only.
|
|
11
|
+
- Sign-in and secrets without a terminal: `anybuild login` takes `ANYBUILD_USERNAME` / `ANYBUILD_PASSWORD`, or reads the username and password as two lines on stdin; secret prompts (`api-key …`, `user create --kind person`) read the next line on stdin when there is no terminal. With a terminal nothing changes (hidden prompts). Prompts for piped input go to stderr.
|
|
12
|
+
- `push` and `validate` take folders (`anybuild push ui/liquid` pushes the pending files under it), skip a path that has no pending change (with a note) instead of failing the whole push, and treat a resource's binary (`resources/images/logo.png`) as its JSON, which carries it. `anybuild push --help` (and the other commands without their own help) prints the help instead of reading `--help` as a path.
|
|
13
|
+
- A site's files no longer fail a push halfway. Liquid templates go in kind order (styles, scripts, snippets, blocks, layouts, pages; up to 25 per request), so what a template references is saved first. Portal files and site content go in one request: the server checks the content against the site as the portal file makes it, then publishes both, or neither when the site cannot be built. The server rebuilds the sites once, in the push's last request (they keep serving the previous build until then). Requests stay under 8 MB (resource binaries split across requests; a bigger file goes alone).
|
|
14
|
+
- `ui/liquid/scripts/` (a site's own JavaScript, listed in `site.scripts`) is tracked like the other `ui/liquid` folders; any layout, page, block or snippet may also have a script block after its CSS block. Server-side; no other CLI change.
|
|
15
|
+
|
|
3
16
|
## 0.8.0
|
|
4
17
|
|
|
5
18
|
- Writable `be/identity/providers/<provider_id>.json` (sign-in providers: `kind` `google`, `microsoft` or `oidc`, `client_id`, `issuer`, `tenant`, `scopes`, `trust_email`, `label`). Create/update/delete on push; a file never holds the client secret; delete is refused while a portal still offers the provider. Portals and Liquid sites turn providers on with `ui_application_settings.sign_in.providers`; the portal push prints the redirect URIs to register.
|
package/README.md
CHANGED
|
@@ -40,6 +40,24 @@ anybuild status
|
|
|
40
40
|
anybuild push -m "describe the change"
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
+
### Sign in with a link (agents, remote machines, two-factor accounts)
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
anybuild login --link https://your-host.example.com
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
The CLI prints a sign-in link. The person opens it in any browser and signs in on the environment's own page (two-factor included); the CLI never sees the password. The link works for 10 minutes. Each host keeps its own sign-in, so an agent can work with several environments side by side.
|
|
50
|
+
|
|
51
|
+
For agents whose commands time out, add `--no-wait`: it prints the link, checks once and exits with `0` (signed in) or `2` (still waiting). Run the same command again to check again; a link that still works is reused, not replaced.
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
anybuild login --link --no-wait --label grokbot https://your-host.example.com # prints the link, exit 2
|
|
55
|
+
# … the person signs in …
|
|
56
|
+
anybuild login --link --no-wait --label grokbot https://your-host.example.com # exit 0
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
`--label` names the session in the person's session list (default: this machine's name); `--username <email>` pre-fills the sign-in page. Needs an environment with link sign-in (`POST /api/auth/device`); older environments answer that it is not supported.
|
|
60
|
+
|
|
43
61
|
Sign out when finished (especially on shared machines):
|
|
44
62
|
|
|
45
63
|
```bash
|
|
@@ -67,7 +85,7 @@ If the server cannot export a file, pull skips it with a warning instead of stop
|
|
|
67
85
|
|
|
68
86
|
If a push includes **deletions**, the CLI lists them and asks for confirmation. Pass `--yes` (or `-y`) to skip the prompt (required in non-interactive / CI use).
|
|
69
87
|
|
|
70
|
-
A push goes in this order, so what a file depends on is live before it: backend code (in chunks), schema (auto-increments, field types, entities, views), UI code
|
|
88
|
+
A push goes in this order, so what a file depends on is live before it: backend code (in chunks), schema (auto-increments, field types, entities, views), Liquid templates (styles, scripts, snippets, blocks, layouts, pages), other UI code and resources (in requests of at most 8 MB), navigation, portals together with site content (`ui/page_types`, `ui/content/*`, `ui/actions`, in one request), translations (`ui/translations`, in one request), AnyInput profiles, scenarios, scenario tests, scheduled jobs, web routes, then mail templates, mail providers and sign-in providers. Portals and site content travel together: the server checks the content against the site as the portal file makes it (new locales, routes) and publishes both or neither, and a menu and the page it links are checked together. Sites are rebuilt once, at the end of the push.
|
|
71
89
|
|
|
72
90
|
Pass `-m` / `--message` to record an optional note on the server **Push History** for that command (one history row even when the upload is split into several HTTP batches). `validate` does not write history. Older CLI versions omit the note and still apply files.
|
|
73
91
|
|
|
@@ -80,7 +98,8 @@ Pass `-m` / `--message` to record an optional note on the server **Push History*
|
|
|
80
98
|
| `ui/lit/components/` | Custom Lit widgets (`.js`) and theme JSON |
|
|
81
99
|
| `ui/navigation/` | Navigation instance JSON |
|
|
82
100
|
| `ui/portals/` | Portal (`ui_application`) JSON |
|
|
83
|
-
| `ui/liquid/{layouts,pages,blocks,snippets}/` | Liquid site templates (`.liquid`, with a `__meta` block). Format: `meta/ui/liquid/RULES.md` |
|
|
101
|
+
| `ui/liquid/{layouts,pages,blocks,snippets}/` | Liquid site templates (`.liquid`, with a `__meta` block; optional CSS and script blocks). Format: `meta/ui/liquid/RULES.md` |
|
|
102
|
+
| `ui/liquid/{styles,scripts}/` | A Liquid site's own CSS and JavaScript files, listed in the site file (`site.styles`, `site.scripts`). Format: `meta/ui/liquid/RULES.md` |
|
|
84
103
|
| `ui/page_types/` | Page types of a Liquid site (layout and regions) |
|
|
85
104
|
| `ui/content/{pages,menus,globals,groups}/` | Site content: composed pages, menus, globals, member groups. Published through the site's publish gate |
|
|
86
105
|
| `ui/actions/` | Site actions (forms and buttons that run a command). Format: `meta/ui/liquid/RULES.md` |
|
|
@@ -139,14 +158,15 @@ resources/files/price-list.json resources/files/price-list.pdf
|
|
|
139
158
|
|
|
140
159
|
| Command | Description |
|
|
141
160
|
| --- | --- |
|
|
142
|
-
| `anybuild login <host-url>` | Sign in (prompts for username and password) |
|
|
143
|
-
| `anybuild
|
|
161
|
+
| `anybuild login <host-url>` | Sign in (prompts for username and password; without a terminal, set `ANYBUILD_USERNAME` / `ANYBUILD_PASSWORD` or pipe the two lines on stdin) |
|
|
162
|
+
| `anybuild login --link <host-url>` | Sign in with a link the person opens in a browser (no password in the CLI; two-factor works). Options: `--no-wait` (check once; exit 0 signed in, 2 waiting; run again to check again), `--label <name>`, `--username <email>` |
|
|
163
|
+
| `anybuild logout <host-url>` | Sign out and remove the local session for that host (and a link sign-in still waiting) |
|
|
144
164
|
| `anybuild create <host-url>/<app> [directory]` | Create a blank application on the host and clone it into `./<app>/` (or `[directory]`; use `.` for cwd). Options: `--name <display name>` (defaults to the application id), `--debug`. Fails if that id already exists — use clone. No `--force`. Host route: `POST /api/cli/v1/create/application` (token auth). |
|
|
145
165
|
| `anybuild clone <host-url>/<app> [directory]` | Download an application into `./<app>/` (or `[directory]`; use `.` for cwd). Options: `--force`, `--debug` |
|
|
146
|
-
| `anybuild pull [paths…]` | Download latest changes. Options: `--force` (overwrite local files even when the last snapshot already matches the server; with no paths this re-downloads everything), `--debug` |
|
|
147
|
-
| `anybuild status` | List local added / modified / deleted files |
|
|
148
|
-
| `anybuild validate [paths…]` | Check pending changes against the server without applying them (checksums, JSON shape, JS parse, schema expand). Does not compile entities or views. Options: `--debug` |
|
|
149
|
-
| `anybuild push [paths…]` | Upload local changes
|
|
166
|
+
| `anybuild pull [paths…]` | Download latest changes. Refuses (and changes nothing) when the server changed a file you edited and have not pushed; push first, or take the server copy with `--force <path>`. Options: `--force` (overwrite local files even when the last snapshot already matches the server; with no paths this re-downloads everything), `--debug` |
|
|
167
|
+
| `anybuild status` | List local added / modified / deleted files since the last pull or push. It does not contact the server: run `anybuild pull` to get server changes |
|
|
168
|
+
| `anybuild validate [paths…]` | Check pending changes against the server without applying them (checksums, JSON shape, JS parse, schema expand). Does not compile entities or views. Paths as for `push`. Options: `--debug` |
|
|
169
|
+
| `anybuild push [paths…]` | Upload local changes. Paths are optional files or folders: a folder pushes its pending files; a path with no pending change is skipped with a note; a resource's binary (`resources/images/logo.png`) pushes its JSON. Options: `-m` / `--message <text>` (recorded on the server Push History), `--debug`, `--yes` / `-y` (skip confirm when the push includes deletions) |
|
|
150
170
|
| `anybuild test scenarios [suites…]` | Run AnyInput scenario test suites (`be/scenario_tests/`, the local files) against the pushed scenarios, as you. Options: `--case <id>`, `--tag <tag>` (both repeatable), `--verbose`. Report in `.ab/test-reports/scenarios.json`; exit code 1 when a case fails. `anybuild test` lists the test kinds |
|
|
151
171
|
| `anybuild api <GET\|POST\|PATCH\|DELETE> <path> [--data <json> \| --data-file <file>]` | Call an entity endpoint (OData) of the project's host with the stored API key. `<path>` is relative to `/api/`. Body to stdout, status line to stderr, exit code 1 on HTTP errors |
|
|
152
172
|
| `anybuild api-key set [--allow-writes \| --read-only]` | Store an API key for the project's host (hidden prompt, terminal only). Checks the key first; asks whether writes are allowed (default no) |
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { PendingLogin, SessionTokens } from "../config/types.js";
|
|
2
|
+
import type { LoginUrlContext } from "./login-url.js";
|
|
3
|
+
/**
|
|
4
|
+
* Link sign-in (`anybuild login --link`): the environment returns a login_url for the person and a secret
|
|
5
|
+
* device_code for the CLI. The person signs in on the environment's own page (2FA included); the CLI then
|
|
6
|
+
* exchanges device_code for the usual tokens. The password never reaches the CLI.
|
|
7
|
+
*
|
|
8
|
+
* POST /api/auth/device { client?, login_hint? } -> { device_code, login_url, expires_in, interval }
|
|
9
|
+
* POST /api/auth/device/token { device_code } -> tokens | { error: authorization_pending | expired_token | … }
|
|
10
|
+
*/
|
|
11
|
+
export declare const DEVICE_START_PATH = "/api/auth/device";
|
|
12
|
+
export declare const DEVICE_TOKEN_PATH = "/api/auth/device/token";
|
|
13
|
+
/** Same rule as the server's session label. */
|
|
14
|
+
export declare const CLIENT_LABEL: RegExp;
|
|
15
|
+
/** This machine's name as a session label, or undefined when nothing usable is left. */
|
|
16
|
+
export declare function defaultClientLabel(): string | undefined;
|
|
17
|
+
type Fetch = typeof fetch;
|
|
18
|
+
export declare function startDeviceLogin(origin: string, options?: {
|
|
19
|
+
label?: string;
|
|
20
|
+
loginHint?: string;
|
|
21
|
+
fetchImpl?: Fetch;
|
|
22
|
+
}): Promise<PendingLogin>;
|
|
23
|
+
export type DevicePoll = {
|
|
24
|
+
status: "approved";
|
|
25
|
+
tokens: SessionTokens;
|
|
26
|
+
user_id?: string;
|
|
27
|
+
} | {
|
|
28
|
+
status: "pending";
|
|
29
|
+
slow_down?: boolean;
|
|
30
|
+
};
|
|
31
|
+
export declare function pollDeviceToken(origin: string, deviceCode: string, fetchImpl?: Fetch): Promise<DevicePoll>;
|
|
32
|
+
export type LinkLoginOptions = {
|
|
33
|
+
label?: string;
|
|
34
|
+
loginHint?: string;
|
|
35
|
+
/** Keep checking until the person signs in or the link expires. false: check once and return. */
|
|
36
|
+
wait: boolean;
|
|
37
|
+
/** Called with the link to show the person; resumed = an earlier link that still works. */
|
|
38
|
+
onLink: (pending: PendingLogin, resumed: boolean) => void;
|
|
39
|
+
onWaiting?: () => void;
|
|
40
|
+
fetchImpl?: Fetch;
|
|
41
|
+
globalConfigPath?: string;
|
|
42
|
+
sleep?: (ms: number) => Promise<void>;
|
|
43
|
+
now?: () => number;
|
|
44
|
+
};
|
|
45
|
+
export type LinkLoginResult = {
|
|
46
|
+
status: "signed_in";
|
|
47
|
+
user_id?: string;
|
|
48
|
+
} | {
|
|
49
|
+
status: "pending";
|
|
50
|
+
pending: PendingLogin;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* One link sign-in per environment: a link that still works is reused (so running the command again keeps
|
|
54
|
+
* waiting instead of sending the person a new link). The session is stored like a password login.
|
|
55
|
+
*/
|
|
56
|
+
export declare function performLinkLogin(ctx: LoginUrlContext, options: LinkLoginOptions): Promise<LinkLoginResult>;
|
|
57
|
+
export {};
|
|
58
|
+
//# sourceMappingURL=device-login.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"device-login.d.ts","sourceRoot":"","sources":["../../src/auth/device-login.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEtE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGtD;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,qBAAqB,CAAC;AACpD,eAAO,MAAM,iBAAiB,2BAA2B,CAAC;AAE1D,+CAA+C;AAC/C,eAAO,MAAM,YAAY,QAAiC,CAAC;AAE3D,wFAAwF;AACxF,wBAAgB,kBAAkB,IAAI,MAAM,GAAG,SAAS,CAMvD;AAED,KAAK,KAAK,GAAG,OAAO,KAAK,CAAC;AAsD1B,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,MAAM,EACd,OAAO,GAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,KAAK,CAAA;CAAO,GACtE,OAAO,CAAC,YAAY,CAAC,CA0BvB;AAED,MAAM,MAAM,UAAU,GAClB;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,MAAM,EAAE,aAAa,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GAC/D;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,SAAS,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAE/C,wBAAsB,eAAe,CACnC,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,SAAS,GAAE,KAAa,GACvB,OAAO,CAAC,UAAU,CAAC,CAiBrB;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iGAAiG;IACjG,IAAI,EAAE,OAAO,CAAC;IACd,2FAA2F;IAC3F,MAAM,EAAE,CAAC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IAC1D,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,SAAS,CAAC,EAAE,KAAK,CAAC;IAClB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,KAAK,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACtC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,eAAe,GACvB;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GACzC;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,YAAY,CAAA;CAAE,CAAC;AAEjD;;;GAGG;AACH,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,eAAe,EACpB,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,eAAe,CAAC,CAwE1B"}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { hostname } from "node:os";
|
|
2
|
+
import { getPendingLoginFromGlobal, removePendingLoginFromGlobal, upsertPendingLoginInGlobal, upsertSessionInGlobal, } from "../config/global-config.js";
|
|
3
|
+
import { sessionKey } from "../config/session-key.js";
|
|
4
|
+
import { AbCliError } from "../errors.js";
|
|
5
|
+
import { parseSessionTokensFromAuthBody } from "./token-response.js";
|
|
6
|
+
/**
|
|
7
|
+
* Link sign-in (`anybuild login --link`): the environment returns a login_url for the person and a secret
|
|
8
|
+
* device_code for the CLI. The person signs in on the environment's own page (2FA included); the CLI then
|
|
9
|
+
* exchanges device_code for the usual tokens. The password never reaches the CLI.
|
|
10
|
+
*
|
|
11
|
+
* POST /api/auth/device { client?, login_hint? } -> { device_code, login_url, expires_in, interval }
|
|
12
|
+
* POST /api/auth/device/token { device_code } -> tokens | { error: authorization_pending | expired_token | … }
|
|
13
|
+
*/
|
|
14
|
+
export const DEVICE_START_PATH = "/api/auth/device";
|
|
15
|
+
export const DEVICE_TOKEN_PATH = "/api/auth/device/token";
|
|
16
|
+
/** Same rule as the server's session label. */
|
|
17
|
+
export const CLIENT_LABEL = /^[a-z0-9][a-z0-9_.-]{0,39}$/i;
|
|
18
|
+
/** This machine's name as a session label, or undefined when nothing usable is left. */
|
|
19
|
+
export function defaultClientLabel() {
|
|
20
|
+
const cleaned = hostname()
|
|
21
|
+
.replace(/[^a-z0-9_.-]+/gi, "-")
|
|
22
|
+
.replace(/^[^a-z0-9]+/i, "")
|
|
23
|
+
.slice(0, 40);
|
|
24
|
+
return CLIENT_LABEL.test(cleaned) ? cleaned : undefined;
|
|
25
|
+
}
|
|
26
|
+
async function postJson(fetchImpl, url, body) {
|
|
27
|
+
let res;
|
|
28
|
+
try {
|
|
29
|
+
res = await fetchImpl(url, {
|
|
30
|
+
method: "POST",
|
|
31
|
+
headers: { Accept: "application/json", "Content-Type": "application/json" },
|
|
32
|
+
body: JSON.stringify(body),
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
throw new AbCliError("AUTH_LOGIN", `Sign-in request failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
37
|
+
}
|
|
38
|
+
const text = await res.text();
|
|
39
|
+
let json = {};
|
|
40
|
+
if (text.trim()) {
|
|
41
|
+
try {
|
|
42
|
+
const parsed = JSON.parse(text);
|
|
43
|
+
if (typeof parsed === "object" && parsed !== null) {
|
|
44
|
+
json = parsed;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
throw new AbCliError("AUTH_LOGIN", `Sign-in returned non-JSON (${res.status}): ${text.trim().slice(0, 200)}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return { status: res.status, ok: res.ok, json };
|
|
52
|
+
}
|
|
53
|
+
function errorOf(json) {
|
|
54
|
+
const raw = json.error;
|
|
55
|
+
if (typeof raw === "string") {
|
|
56
|
+
return {
|
|
57
|
+
error: raw,
|
|
58
|
+
description: typeof json.error_description === "string" ? json.error_description : raw,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (typeof raw === "object" && raw !== null) {
|
|
62
|
+
const o = raw;
|
|
63
|
+
const error = typeof o.error === "string" ? o.error : "error";
|
|
64
|
+
return { error, description: typeof o.message === "string" ? o.message : error };
|
|
65
|
+
}
|
|
66
|
+
return { error: "error", description: "Unexpected response" };
|
|
67
|
+
}
|
|
68
|
+
export async function startDeviceLogin(origin, options = {}) {
|
|
69
|
+
const body = {};
|
|
70
|
+
if (options.label)
|
|
71
|
+
body.client = options.label;
|
|
72
|
+
if (options.loginHint)
|
|
73
|
+
body.login_hint = options.loginHint;
|
|
74
|
+
const r = await postJson(options.fetchImpl ?? fetch, `${origin}${DEVICE_START_PATH}`, body);
|
|
75
|
+
if (!r.ok) {
|
|
76
|
+
const { error, description } = errorOf(r.json);
|
|
77
|
+
if (r.status === 404 || error === "not_found") {
|
|
78
|
+
throw new AbCliError("AUTH_LOGIN", "This environment does not support link sign-in yet. Use anybuild login without --link.");
|
|
79
|
+
}
|
|
80
|
+
throw new AbCliError("AUTH_LOGIN", `Could not start link sign-in: ${description}`);
|
|
81
|
+
}
|
|
82
|
+
const { device_code, login_url, expires_in, interval } = r.json;
|
|
83
|
+
if (typeof device_code !== "string" || !device_code || typeof login_url !== "string" || !login_url) {
|
|
84
|
+
throw new AbCliError("AUTH_LOGIN", "Link sign-in response is missing device_code or login_url.");
|
|
85
|
+
}
|
|
86
|
+
const seconds = typeof expires_in === "number" && expires_in > 0 ? expires_in : 600;
|
|
87
|
+
return {
|
|
88
|
+
device_code,
|
|
89
|
+
login_url,
|
|
90
|
+
expires_at: new Date(Date.now() + seconds * 1000).toISOString(),
|
|
91
|
+
interval: typeof interval === "number" && interval > 0 ? interval : 3,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
export async function pollDeviceToken(origin, deviceCode, fetchImpl = fetch) {
|
|
95
|
+
const r = await postJson(fetchImpl, `${origin}${DEVICE_TOKEN_PATH}`, { device_code: deviceCode });
|
|
96
|
+
if (r.ok) {
|
|
97
|
+
const tokens = parseSessionTokensFromAuthBody(r.json, { code: "AUTH_LOGIN" });
|
|
98
|
+
return {
|
|
99
|
+
status: "approved",
|
|
100
|
+
tokens,
|
|
101
|
+
user_id: typeof r.json.user_id === "string" ? r.json.user_id : undefined,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
const { error, description } = errorOf(r.json);
|
|
105
|
+
if (error === "authorization_pending")
|
|
106
|
+
return { status: "pending" };
|
|
107
|
+
if (error === "slow_down")
|
|
108
|
+
return { status: "pending", slow_down: true };
|
|
109
|
+
if (error === "expired_token") {
|
|
110
|
+
throw new AbCliError("AUTH_LOGIN", "The sign-in link has expired.");
|
|
111
|
+
}
|
|
112
|
+
throw new AbCliError("AUTH_LOGIN", `Link sign-in failed: ${description}`);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* One link sign-in per environment: a link that still works is reused (so running the command again keeps
|
|
116
|
+
* waiting instead of sending the person a new link). The session is stored like a password login.
|
|
117
|
+
*/
|
|
118
|
+
export async function performLinkLogin(ctx, options) {
|
|
119
|
+
const fetchImpl = options.fetchImpl ?? fetch;
|
|
120
|
+
const sleep = options.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
121
|
+
const now = options.now ?? Date.now;
|
|
122
|
+
const origin = new URL(ctx.api_url).origin;
|
|
123
|
+
const key = sessionKey(ctx.api_url, ctx.environment);
|
|
124
|
+
let pending = getPendingLoginFromGlobal(key, options.globalConfigPath);
|
|
125
|
+
let resumed = true;
|
|
126
|
+
if (!pending || Date.parse(pending.expires_at) - now() < 5000) {
|
|
127
|
+
pending = await startDeviceLogin(origin, {
|
|
128
|
+
label: options.label,
|
|
129
|
+
loginHint: options.loginHint,
|
|
130
|
+
fetchImpl,
|
|
131
|
+
});
|
|
132
|
+
upsertPendingLoginInGlobal(key, pending, options.globalConfigPath);
|
|
133
|
+
resumed = false;
|
|
134
|
+
}
|
|
135
|
+
// a new link is shown at once; a resumed one only if the person hasn't signed in yet
|
|
136
|
+
let shown = false;
|
|
137
|
+
if (!resumed) {
|
|
138
|
+
options.onLink(pending, false);
|
|
139
|
+
shown = true;
|
|
140
|
+
}
|
|
141
|
+
let interval = Math.max(1, pending.interval);
|
|
142
|
+
let first = true;
|
|
143
|
+
for (;;) {
|
|
144
|
+
if (!first) {
|
|
145
|
+
await sleep(interval * 1000);
|
|
146
|
+
}
|
|
147
|
+
let result;
|
|
148
|
+
try {
|
|
149
|
+
result = await pollDeviceToken(origin, pending.device_code, fetchImpl);
|
|
150
|
+
}
|
|
151
|
+
catch (e) {
|
|
152
|
+
// an expired or refused link is of no further use
|
|
153
|
+
removePendingLoginFromGlobal(key, options.globalConfigPath);
|
|
154
|
+
if (e instanceof AbCliError && e.message === "The sign-in link has expired.") {
|
|
155
|
+
throw new AbCliError("AUTH_LOGIN", "The sign-in link has expired. Run the same command again for a new link.");
|
|
156
|
+
}
|
|
157
|
+
throw e;
|
|
158
|
+
}
|
|
159
|
+
if (result.status === "approved") {
|
|
160
|
+
upsertSessionInGlobal(key, result.tokens, options.globalConfigPath);
|
|
161
|
+
removePendingLoginFromGlobal(key, options.globalConfigPath);
|
|
162
|
+
return { status: "signed_in", user_id: result.user_id };
|
|
163
|
+
}
|
|
164
|
+
if (result.slow_down) {
|
|
165
|
+
interval += 2;
|
|
166
|
+
}
|
|
167
|
+
if (!shown) {
|
|
168
|
+
options.onLink(pending, true);
|
|
169
|
+
shown = true;
|
|
170
|
+
}
|
|
171
|
+
if (!options.wait) {
|
|
172
|
+
return { status: "pending", pending };
|
|
173
|
+
}
|
|
174
|
+
if (first) {
|
|
175
|
+
options.onWaiting?.();
|
|
176
|
+
}
|
|
177
|
+
first = false;
|
|
178
|
+
if (now() >= Date.parse(pending.expires_at)) {
|
|
179
|
+
removePendingLoginFromGlobal(key, options.globalConfigPath);
|
|
180
|
+
throw new AbCliError("AUTH_LOGIN", "The sign-in link has expired. Run the same command again for a new link.");
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
//# sourceMappingURL=device-login.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"device-login.js","sourceRoot":"","sources":["../../src/auth/device-login.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EACL,yBAAyB,EACzB,4BAA4B,EAC5B,0BAA0B,EAC1B,qBAAqB,GACtB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAEtD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,8BAA8B,EAAE,MAAM,qBAAqB,CAAC;AAErE;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,kBAAkB,CAAC;AACpD,MAAM,CAAC,MAAM,iBAAiB,GAAG,wBAAwB,CAAC;AAE1D,+CAA+C;AAC/C,MAAM,CAAC,MAAM,YAAY,GAAG,8BAA8B,CAAC;AAE3D,wFAAwF;AACxF,MAAM,UAAU,kBAAkB;IAChC,MAAM,OAAO,GAAG,QAAQ,EAAE;SACvB,OAAO,CAAC,iBAAiB,EAAE,GAAG,CAAC;SAC/B,OAAO,CAAC,cAAc,EAAE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AAC,SAAS,EAAE,EAAE,CAAC;QACxB,CAAC;QACD,KAAK,GAAG,KAAK,CAAC;QACd,IAAI,GAAG,EAAE,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;YAC5C,4BAA4B,CAAC,GAAG,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC;YAC5D,MAAM,IAAI,UAAU,CAClB,YAAY,EACZ,0EAA0E,CAC3E,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"perform-logout.d.ts","sourceRoot":"","sources":["../../src/auth/perform-logout.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAsB,KAAK,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAG5E,MAAM,MAAM,oBAAoB,GAAG,mBAAmB,GAAG;IACvD,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CAC1B,CAAC;AAEF,wBAAsB,aAAa,CACjC,GAAG,EAAE,gBAAgB,EACrB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"perform-logout.d.ts","sourceRoot":"","sources":["../../src/auth/perform-logout.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAsB,KAAK,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAG5E,MAAM,MAAM,oBAAoB,GAAG,mBAAmB,GAAG;IACvD,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;CAC1B,CAAC;AAEF,wBAAsB,aAAa,CACjC,GAAG,EAAE,gBAAgB,EACrB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,IAAI,CAAC,CA8Ef"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getSessionFromGlobal } from "../config/global-config.js";
|
|
1
|
+
import { getSessionFromGlobal, removePendingLoginFromGlobal } from "../config/global-config.js";
|
|
2
2
|
import { globalConfigPath } from "../config/paths.js";
|
|
3
3
|
import { sessionKey } from "../config/session-key.js";
|
|
4
4
|
import { AbCliError, NoSessionError } from "../errors.js";
|
|
@@ -7,7 +7,12 @@ import { removeSession } from "./session.js";
|
|
|
7
7
|
export async function performLogout(ctx, options) {
|
|
8
8
|
const gcPath = options?.globalConfigPath ?? globalConfigPath();
|
|
9
9
|
const key = sessionKey(ctx.api_url, ctx.environment);
|
|
10
|
+
// a link sign-in still waiting for this host is dropped too
|
|
11
|
+
const hadPending = removePendingLoginFromGlobal(key, gcPath);
|
|
10
12
|
if (!getSessionFromGlobal(key, gcPath)) {
|
|
13
|
+
if (hadPending) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
11
16
|
throw new NoSessionError(ctx.api_url, ctx.environment);
|
|
12
17
|
}
|
|
13
18
|
const { accessToken } = await resolveAccessToken(ctx.api_url, ctx.environment, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"perform-logout.js","sourceRoot":"","sources":["../../src/auth/perform-logout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"perform-logout.js","sourceRoot":"","sources":["../../src/auth/perform-logout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,4BAA4B,EAAE,MAAM,4BAA4B,CAAC;AAChG,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE1D,OAAO,EAAE,kBAAkB,EAA4B,MAAM,cAAc,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;A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AA6B,CAAC,OAAO,KAAK,QAAQ;YACxD,CAAC,CAAE,IAA4B,CAAC,OAAO;YACvC,CAAC,CAAC,QAAQ,GAAG,CAAC,MAAM,EAAE,CAAC;QAC3B,MAAM,IAAI,UAAU,CAAC,aAAa,EAAE,kBAAkB,GAAG,EAAE,CAAC,CAAC;IAC/D,CAAC;IAED,aAAa,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;AACtD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../src/commands/login.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../src/commands/login.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAiHjD,eAAO,MAAM,KAAK,EAAE,cA4CnB,CAAC"}
|
package/dist/commands/login.js
CHANGED
|
@@ -1,37 +1,142 @@
|
|
|
1
|
+
import { CLIENT_LABEL, defaultClientLabel, performLinkLogin } from "../auth/device-login.js";
|
|
1
2
|
import { performLogin } from "../auth/perform-login.js";
|
|
2
3
|
import { parseLoginUrlInput } from "../auth/login-url.js";
|
|
3
4
|
import { readUsernamePassword } from "../io/read-credentials.js";
|
|
4
5
|
import { AbCliError, CLI_PROGRAM } from "../errors.js";
|
|
5
6
|
import { logProgress } from "../progress.js";
|
|
6
7
|
const USAGE = `Usage: ${CLI_PROGRAM} login <host-url>
|
|
7
|
-
|
|
8
|
+
${CLI_PROGRAM} login --link <host-url> [--no-wait] [--label <name>] [--username <email>]
|
|
9
|
+
Sign in to an Anybuild host. Tokens apply to all apps on that host; each host keeps its own sign-in.
|
|
10
|
+
|
|
11
|
+
With a password: prompts for username and password. Without a terminal (CI, coding agents): set
|
|
12
|
+
ANYBUILD_USERNAME and ANYBUILD_PASSWORD, or pipe the username and the password as two lines on stdin.
|
|
13
|
+
Never put a password in argv.
|
|
14
|
+
|
|
15
|
+
With a link (--link): prints a sign-in link for the person to open in any browser. They sign in on the
|
|
16
|
+
environment's own page (two-factor included); the CLI never sees the password. The link works for
|
|
17
|
+
10 minutes. Running the same command again reuses a link that still works.
|
|
18
|
+
--no-wait Print the link, check once and exit: 0 signed in, 2 still waiting.
|
|
19
|
+
Run the same command again to check again.
|
|
20
|
+
--label <name> Name shown in the person's session list (default: this machine's name).
|
|
21
|
+
--username <email> Pre-fill the username on the sign-in page.
|
|
22
|
+
|
|
8
23
|
After login:
|
|
9
24
|
${CLI_PROGRAM} clone <host-url>/<application_id>
|
|
10
25
|
${CLI_PROGRAM} create <host-url>/<application_id> [--name "Display name"]`;
|
|
26
|
+
function parseLoginArgs(args) {
|
|
27
|
+
const rest = [];
|
|
28
|
+
let link = false;
|
|
29
|
+
let wait = true;
|
|
30
|
+
let label;
|
|
31
|
+
let username;
|
|
32
|
+
const valueOf = (flag, i) => {
|
|
33
|
+
const value = args[i + 1];
|
|
34
|
+
if (value === undefined || !value.trim() || value.startsWith("-")) {
|
|
35
|
+
throw new AbCliError("CONFIG", `${flag} requires a value.\n${USAGE}`);
|
|
36
|
+
}
|
|
37
|
+
return value.trim();
|
|
38
|
+
};
|
|
39
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
40
|
+
const arg = args[i];
|
|
41
|
+
if (arg === "--help" || arg === "-h")
|
|
42
|
+
return "help";
|
|
43
|
+
if (arg === "--link") {
|
|
44
|
+
link = true;
|
|
45
|
+
}
|
|
46
|
+
else if (arg === "--no-wait") {
|
|
47
|
+
wait = false;
|
|
48
|
+
}
|
|
49
|
+
else if (arg === "--label") {
|
|
50
|
+
label = valueOf(arg, i);
|
|
51
|
+
i += 1;
|
|
52
|
+
}
|
|
53
|
+
else if (arg.startsWith("--label=")) {
|
|
54
|
+
label = arg.slice("--label=".length).trim();
|
|
55
|
+
}
|
|
56
|
+
else if (arg === "--username") {
|
|
57
|
+
username = valueOf(arg, i);
|
|
58
|
+
i += 1;
|
|
59
|
+
}
|
|
60
|
+
else if (arg.startsWith("--username=")) {
|
|
61
|
+
username = arg.slice("--username=".length).trim();
|
|
62
|
+
}
|
|
63
|
+
else if (arg.startsWith("-")) {
|
|
64
|
+
throw new AbCliError("CONFIG", `Unknown option ${arg}.\n${USAGE}`);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
rest.push(arg);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (rest.length !== 1 || !rest[0].trim()) {
|
|
71
|
+
throw new AbCliError("CONFIG", USAGE);
|
|
72
|
+
}
|
|
73
|
+
if (!link && (!wait || label !== undefined || username !== undefined)) {
|
|
74
|
+
throw new AbCliError("CONFIG", `--no-wait, --label and --username only apply with --link.\n${USAGE}`);
|
|
75
|
+
}
|
|
76
|
+
if (label !== undefined && !CLIENT_LABEL.test(label)) {
|
|
77
|
+
throw new AbCliError("CONFIG", "--label must start with a letter or digit and use only letters, digits, _ . - (up to 40).");
|
|
78
|
+
}
|
|
79
|
+
return { url: rest[0].trim(), link, wait, label, username };
|
|
80
|
+
}
|
|
81
|
+
function nextSteps(ctx) {
|
|
82
|
+
return `Clone an existing application:
|
|
83
|
+
${CLI_PROGRAM} clone ${ctx.api_url}/<application_id>
|
|
84
|
+
|
|
85
|
+
Create a new blank application:
|
|
86
|
+
${CLI_PROGRAM} create ${ctx.api_url}/<application_id> [--name "Display name"]`;
|
|
87
|
+
}
|
|
88
|
+
async function linkLogin(ctx, a, rerun) {
|
|
89
|
+
const result = await performLinkLogin(ctx, {
|
|
90
|
+
label: a.label ?? defaultClientLabel(),
|
|
91
|
+
loginHint: a.username,
|
|
92
|
+
wait: a.wait,
|
|
93
|
+
onLink: (pending, resumed) => {
|
|
94
|
+
const minutes = Math.max(1, Math.round((Date.parse(pending.expires_at) - Date.now()) / 60000));
|
|
95
|
+
console.log(`${resumed ? "Sign-in link (still valid)" : "Sign-in link"} for ${ctx.environment}, valid for about ${minutes} min:\n ${pending.login_url}\n` +
|
|
96
|
+
`Open it in a browser and sign in. Only the person who should sign in may open it.`);
|
|
97
|
+
},
|
|
98
|
+
onWaiting: () => logProgress("Waiting for sign-in… (Ctrl-C to stop; run the same command again to keep waiting)"),
|
|
99
|
+
});
|
|
100
|
+
if (result.status === "pending") {
|
|
101
|
+
console.log(`Not signed in yet. After signing in, run:\n ${rerun}`);
|
|
102
|
+
process.exitCode = 2;
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
console.log(`Logged in${result.user_id ? ` as ${result.user_id}` : ""}. API ${ctx.api_url}, environment "${ctx.environment}" (tokens apply to all apps on this host).\n\n${nextSteps(ctx)}`);
|
|
106
|
+
}
|
|
11
107
|
export const login = async (args) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (
|
|
15
|
-
|
|
16
|
-
return;
|
|
108
|
+
let parsed;
|
|
109
|
+
try {
|
|
110
|
+
if (args.length === 0) {
|
|
111
|
+
throw new AbCliError("CONFIG", USAGE);
|
|
17
112
|
}
|
|
18
|
-
|
|
113
|
+
parsed = parseLoginArgs(args);
|
|
114
|
+
}
|
|
115
|
+
catch (e) {
|
|
116
|
+
console.error(e instanceof Error ? e.message : String(e));
|
|
19
117
|
process.exitCode = 1;
|
|
20
118
|
return;
|
|
21
119
|
}
|
|
120
|
+
if (parsed === "help") {
|
|
121
|
+
console.log(USAGE);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
22
124
|
try {
|
|
125
|
+
const ctx = parseLoginUrlInput(parsed.url);
|
|
126
|
+
if (parsed.link) {
|
|
127
|
+
const flags = [
|
|
128
|
+
"--link",
|
|
129
|
+
...(parsed.wait ? [] : ["--no-wait"]),
|
|
130
|
+
...(parsed.label ? ["--label", parsed.label] : []),
|
|
131
|
+
];
|
|
132
|
+
await linkLogin(ctx, parsed, `${CLI_PROGRAM} login ${flags.join(" ")} ${parsed.url}`);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
23
135
|
logProgress("Signing in…");
|
|
24
|
-
const ctx = parseLoginUrlInput(urlArg);
|
|
25
136
|
const { username, password } = await readUsernamePassword();
|
|
26
137
|
logProgress("Authenticating…");
|
|
27
138
|
await performLogin(ctx, username, password);
|
|
28
|
-
console.log(`Logged in. API ${ctx.api_url}, environment "${ctx.environment}" (tokens apply to all apps on this host)
|
|
29
|
-
|
|
30
|
-
Clone an existing application:
|
|
31
|
-
${CLI_PROGRAM} clone ${ctx.api_url}/<application_id>
|
|
32
|
-
|
|
33
|
-
Create a new blank application:
|
|
34
|
-
${CLI_PROGRAM} create ${ctx.api_url}/<application_id> [--name "Display name"]`);
|
|
139
|
+
console.log(`Logged in. API ${ctx.api_url}, environment "${ctx.environment}" (tokens apply to all apps on this host).\n\n${nextSteps(ctx)}`);
|
|
35
140
|
}
|
|
36
141
|
catch (e) {
|
|
37
142
|
if (e instanceof AbCliError) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"login.js","sourceRoot":"","sources":["../../src/commands/login.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,kBAAkB,
|
|
1
|
+
{"version":3,"file":"login.js","sourceRoot":"","sources":["../../src/commands/login.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC7F,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAwB,MAAM,sBAAsB,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG7C,MAAM,KAAK,GAAG,UAAU,WAAW;SAC1B,WAAW;;;;;;;;;;;;;;;;MAgBd,WAAW;MACX,WAAW,6DAA6D,CAAC;AAU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,"file":"pull.d.ts","sourceRoot":"","sources":["../../src/commands/pull.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AA6DjD,eAAO,MAAM,IAAI,EAAE,cAsElB,CAAC"}
|
package/dist/commands/pull.js
CHANGED
|
@@ -84,11 +84,17 @@ export const pull = async (args) => {
|
|
|
84
84
|
state = manifestToFileState(manifest);
|
|
85
85
|
}
|
|
86
86
|
logProgress(formatPullProgress(force, paths));
|
|
87
|
+
// unpushed local edits, so pull can refuse to overwrite them (unless --force)
|
|
88
|
+
// (only edited files: a file deleted locally is simply restored)
|
|
89
|
+
const localDirtyPaths = force
|
|
90
|
+
? []
|
|
91
|
+
: computeExportStatus(root).modified.map(statusLineToDiskPath);
|
|
87
92
|
const client = await createClientForProjectRoot(root);
|
|
88
93
|
await exportPullProject(root, client, project.application_id, state, {
|
|
89
94
|
force,
|
|
90
95
|
debug,
|
|
91
96
|
onlyPaths: paths.length > 0 ? paths : undefined,
|
|
97
|
+
localDirtyPaths,
|
|
92
98
|
});
|
|
93
99
|
console.log(formatPullComplete(force, paths));
|
|
94
100
|
try {
|