@almyty/auth 0.1.0 → 0.1.2
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/dist/browser-login.js +2 -1
- package/dist/config.d.ts +15 -0
- package/dist/config.js +43 -0
- package/dist/index.js +5 -4
- package/package.json +2 -2
package/dist/browser-login.js
CHANGED
|
@@ -136,7 +136,8 @@ export function browserLogin(options = {}) {
|
|
|
136
136
|
return;
|
|
137
137
|
settled = true;
|
|
138
138
|
clearTimeout(timer);
|
|
139
|
-
server
|
|
139
|
+
// Keep server alive briefly so the /success page renders in the browser
|
|
140
|
+
setTimeout(() => server.close(), 3000);
|
|
140
141
|
resolve(value);
|
|
141
142
|
};
|
|
142
143
|
const settleReject = (err) => {
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const CONFIG_FILE: string;
|
|
2
|
+
export interface AlmytyConfig {
|
|
3
|
+
apiUrl?: string;
|
|
4
|
+
frontendUrl?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function loadConfig(): AlmytyConfig;
|
|
7
|
+
export declare function saveConfig(config: AlmytyConfig): void;
|
|
8
|
+
/**
|
|
9
|
+
* Resolve the API URL from (in order): flag > env > config > default.
|
|
10
|
+
*/
|
|
11
|
+
export declare function resolveApiUrl(flagValue?: string): string;
|
|
12
|
+
/**
|
|
13
|
+
* Resolve the frontend URL from (in order): flag > env > config > default.
|
|
14
|
+
*/
|
|
15
|
+
export declare function resolveFrontendUrl(flagValue?: string): string;
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Config file at ~/.almyty/config.json.
|
|
3
|
+
*
|
|
4
|
+
* Stores URL overrides so you don't need env vars every time.
|
|
5
|
+
* Created automatically on first login, or manually:
|
|
6
|
+
*
|
|
7
|
+
* echo '{"apiUrl":"https://api.staging.almyty.com","frontendUrl":"https://app.staging.almyty.com"}' > ~/.almyty/config.json
|
|
8
|
+
*/
|
|
9
|
+
import { readFileSync, writeFileSync, existsSync } from 'fs';
|
|
10
|
+
import { join } from 'path';
|
|
11
|
+
import { CREDENTIALS_DIR } from './credentials';
|
|
12
|
+
export const CONFIG_FILE = join(CREDENTIALS_DIR, 'config.json');
|
|
13
|
+
export function loadConfig() {
|
|
14
|
+
try {
|
|
15
|
+
if (!existsSync(CONFIG_FILE))
|
|
16
|
+
return {};
|
|
17
|
+
return JSON.parse(readFileSync(CONFIG_FILE, 'utf-8'));
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return {};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export function saveConfig(config) {
|
|
24
|
+
writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2) + '\n', 'utf-8');
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Resolve the API URL from (in order): flag > env > config > default.
|
|
28
|
+
*/
|
|
29
|
+
export function resolveApiUrl(flagValue) {
|
|
30
|
+
return flagValue
|
|
31
|
+
|| process.env.ALMYTY_URL
|
|
32
|
+
|| loadConfig().apiUrl
|
|
33
|
+
|| 'https://api.almyty.com';
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Resolve the frontend URL from (in order): flag > env > config > default.
|
|
37
|
+
*/
|
|
38
|
+
export function resolveFrontendUrl(flagValue) {
|
|
39
|
+
return flagValue
|
|
40
|
+
|| process.env.ALMYTY_FRONTEND_URL
|
|
41
|
+
|| loadConfig().frontendUrl
|
|
42
|
+
|| 'https://app.almyty.com';
|
|
43
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -72,10 +72,11 @@ function parseArgs(argv) {
|
|
|
72
72
|
return result;
|
|
73
73
|
}
|
|
74
74
|
async function cmdLogin(args) {
|
|
75
|
-
const
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
const { resolveApiUrl, resolveFrontendUrl, saveConfig } = require('./config');
|
|
76
|
+
const apiUrl = resolveApiUrl(args.flags.api);
|
|
77
|
+
const frontendUrl = resolveFrontendUrl(args.flags.frontend);
|
|
78
|
+
// Persist URL config so future commands don't need env vars
|
|
79
|
+
saveConfig({ apiUrl, frontendUrl });
|
|
79
80
|
// Direct token paste — skips the browser entirely.
|
|
80
81
|
if (typeof args.flags.token === 'string') {
|
|
81
82
|
saveCredentials({ url: apiUrl, token: args.flags.token, frontendUrl });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@almyty/auth",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Browser-based login for almyty CLIs (skills, agents, chat, mcp-server)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"dist"
|
|
12
12
|
],
|
|
13
13
|
"scripts": {
|
|
14
|
-
"build": "tsc",
|
|
14
|
+
"build": "tsc && chmod +x dist/index.js",
|
|
15
15
|
"dev": "tsx src/index.ts",
|
|
16
16
|
"test": "vitest run",
|
|
17
17
|
"test:watch": "vitest",
|