@asteroidai/cli 1.9.12 → 1.9.28
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/asteroid.js +387 -53
- package/dist/core.js +14 -2
- package/package.json +3 -8
- package/src/account.ts +0 -224
- package/src/args.ts +0 -39
- package/src/auth/credentials.ts +0 -141
- package/src/auth/store.ts +0 -145
- package/src/auth/workos.ts +0 -171
- package/src/commands.ts +0 -13
- package/src/config.ts +0 -125
- package/src/core.ts +0 -41
- package/src/generated/commands.ts +0 -4772
- package/src/http.ts +0 -115
- package/src/main.ts +0 -49
- package/src/output.test.ts +0 -71
- package/src/output.ts +0 -176
- package/src/program.test.ts +0 -155
- package/src/program.ts +0 -291
- package/src/reference.ts +0 -183
- package/src/request.test.ts +0 -164
- package/src/request.ts +0 -252
- package/src/run.test.ts +0 -431
- package/src/run.ts +0 -229
- package/src/sync/activities.ts +0 -80
- package/src/sync/commands.ts +0 -63
- package/src/sync/execution-pull.ts +0 -273
- package/src/sync/node-files.ts +0 -47
- package/src/sync/paths.ts +0 -45
- package/src/sync/run.ts +0 -136
- package/src/sync/sync.test.ts +0 -502
- package/src/sync/types.ts +0 -58
- package/src/sync/workflow-pull.ts +0 -185
- package/src/sync/workflow-push.ts +0 -161
- package/src/types.ts +0 -46
- package/src/ui.ts +0 -30
package/src/auth/workos.ts
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
export interface DeviceAuthorization {
|
|
2
|
-
device_code: string;
|
|
3
|
-
user_code: string;
|
|
4
|
-
verification_uri: string;
|
|
5
|
-
verification_uri_complete?: string;
|
|
6
|
-
expires_in: number;
|
|
7
|
-
interval: number;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface WorkosOrg {
|
|
11
|
-
id: string;
|
|
12
|
-
name: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface Session {
|
|
16
|
-
accessToken: string;
|
|
17
|
-
refreshToken: string;
|
|
18
|
-
organizationId?: string;
|
|
19
|
-
email?: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export class WorkosError extends Error {
|
|
23
|
-
constructor(
|
|
24
|
-
readonly code: string,
|
|
25
|
-
message: string,
|
|
26
|
-
readonly body: Record<string, unknown> = {},
|
|
27
|
-
) {
|
|
28
|
-
super(message);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface WorkosClient {
|
|
33
|
-
clientId: string;
|
|
34
|
-
apiUrl: string;
|
|
35
|
-
fetch?: typeof fetch;
|
|
36
|
-
sleep?: (ms: number) => Promise<void>;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const AUTHENTICATE = "/user_management/authenticate";
|
|
40
|
-
const TIMEOUT_MS = 15_000;
|
|
41
|
-
|
|
42
|
-
async function post(
|
|
43
|
-
client: WorkosClient,
|
|
44
|
-
path: string,
|
|
45
|
-
body: Record<string, string>,
|
|
46
|
-
): Promise<Record<string, unknown>> {
|
|
47
|
-
const response = await (client.fetch ?? fetch)(`${client.apiUrl}${path}`, {
|
|
48
|
-
method: "POST",
|
|
49
|
-
headers: { Accept: "application/json" },
|
|
50
|
-
body: new URLSearchParams({ client_id: client.clientId, ...body }),
|
|
51
|
-
signal: AbortSignal.timeout(TIMEOUT_MS),
|
|
52
|
-
});
|
|
53
|
-
const json = (await response.json().catch(() => ({}))) as Record<
|
|
54
|
-
string,
|
|
55
|
-
unknown
|
|
56
|
-
>;
|
|
57
|
-
if (!response.ok) {
|
|
58
|
-
const code = String(json.error ?? json.code ?? response.status);
|
|
59
|
-
const message = String(json.error_description ?? json.message ?? code);
|
|
60
|
-
throw new WorkosError(code, message, json);
|
|
61
|
-
}
|
|
62
|
-
return json;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function pollOnce(client: WorkosClient, deviceCode: string) {
|
|
66
|
-
return post(client, AUTHENTICATE, {
|
|
67
|
-
grant_type: "urn:ietf:params:oauth:grant-type:device_code",
|
|
68
|
-
device_code: deviceCode,
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function selectOrg(
|
|
73
|
-
client: WorkosClient,
|
|
74
|
-
pendingAuthenticationToken: string,
|
|
75
|
-
organizationId: string,
|
|
76
|
-
) {
|
|
77
|
-
return post(client, AUTHENTICATE, {
|
|
78
|
-
grant_type: "urn:workos:oauth:grant-type:organization-selection",
|
|
79
|
-
pending_authentication_token: pendingAuthenticationToken,
|
|
80
|
-
organization_id: organizationId,
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function session(json: Record<string, unknown>): Session {
|
|
85
|
-
const user = json.user as { email?: string } | undefined;
|
|
86
|
-
return {
|
|
87
|
-
accessToken: String(json.access_token),
|
|
88
|
-
refreshToken: String(json.refresh_token),
|
|
89
|
-
organizationId: (json.organization_id as string | undefined) ?? undefined,
|
|
90
|
-
email: user?.email,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export async function authorizeDevice(
|
|
95
|
-
client: WorkosClient,
|
|
96
|
-
): Promise<DeviceAuthorization> {
|
|
97
|
-
return (await post(
|
|
98
|
-
client,
|
|
99
|
-
"/user_management/authorize/device",
|
|
100
|
-
{},
|
|
101
|
-
)) as unknown as DeviceAuthorization;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export async function pollDevice(
|
|
105
|
-
client: WorkosClient,
|
|
106
|
-
device: DeviceAuthorization,
|
|
107
|
-
chooseOrg: (orgs: WorkosOrg[]) => Promise<WorkosOrg>,
|
|
108
|
-
): Promise<Session> {
|
|
109
|
-
const sleep = client.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
110
|
-
let interval = (device.interval || 5) * 1000;
|
|
111
|
-
const deadline = Date.now() + device.expires_in * 1000;
|
|
112
|
-
while (Date.now() < deadline) {
|
|
113
|
-
await sleep(interval);
|
|
114
|
-
try {
|
|
115
|
-
return session(await pollOnce(client, device.device_code));
|
|
116
|
-
} catch (error) {
|
|
117
|
-
if (!(error instanceof WorkosError)) throw error;
|
|
118
|
-
if (error.code === "authorization_pending") continue;
|
|
119
|
-
if (error.code === "slow_down") {
|
|
120
|
-
interval += 5000;
|
|
121
|
-
continue;
|
|
122
|
-
}
|
|
123
|
-
if (error.code === "organization_selection_required") {
|
|
124
|
-
const orgs =
|
|
125
|
-
(error.body.organizations as WorkosOrg[] | undefined) ?? [];
|
|
126
|
-
const org = await chooseOrg(orgs);
|
|
127
|
-
return session(
|
|
128
|
-
await selectOrg(
|
|
129
|
-
client,
|
|
130
|
-
String(error.body.pending_authentication_token),
|
|
131
|
-
org.id,
|
|
132
|
-
),
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
throw error;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
throw new WorkosError(
|
|
139
|
-
"expired_token",
|
|
140
|
-
"the sign-in code expired; run asteroid login again",
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export async function refresh(
|
|
145
|
-
client: WorkosClient,
|
|
146
|
-
refreshToken: string,
|
|
147
|
-
organizationId?: string,
|
|
148
|
-
): Promise<Session> {
|
|
149
|
-
return session(
|
|
150
|
-
await post(client, AUTHENTICATE, {
|
|
151
|
-
grant_type: "refresh_token",
|
|
152
|
-
refresh_token: refreshToken,
|
|
153
|
-
...(organizationId ? { organization_id: organizationId } : {}),
|
|
154
|
-
}),
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
export interface Claims {
|
|
159
|
-
exp?: number;
|
|
160
|
-
org_id?: string;
|
|
161
|
-
org?: { id?: string; name?: string };
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export function tokenClaims(token: string): Claims {
|
|
165
|
-
try {
|
|
166
|
-
const payload = token.split(".")[1];
|
|
167
|
-
return JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
|
|
168
|
-
} catch {
|
|
169
|
-
return {};
|
|
170
|
-
}
|
|
171
|
-
}
|
package/src/commands.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { COMMANDS } from "./generated/commands";
|
|
2
|
-
import { SYNC_COMMANDS } from "./sync/commands";
|
|
3
|
-
import type { CliCommand } from "./types";
|
|
4
|
-
|
|
5
|
-
export function withSyncCommands(
|
|
6
|
-
commands: readonly CliCommand[],
|
|
7
|
-
): CliCommand[] {
|
|
8
|
-
return [...commands, ...SYNC_COMMANDS].sort((a, b) =>
|
|
9
|
-
a.command.localeCompare(b.command),
|
|
10
|
-
);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const ALL_COMMANDS = withSyncCommands(COMMANDS);
|
package/src/config.ts
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import envPaths from "env-paths";
|
|
2
|
-
import {
|
|
3
|
-
chmodSync,
|
|
4
|
-
existsSync,
|
|
5
|
-
mkdirSync,
|
|
6
|
-
readFileSync,
|
|
7
|
-
renameSync,
|
|
8
|
-
writeFileSync,
|
|
9
|
-
} from "node:fs";
|
|
10
|
-
import { dirname, join } from "node:path";
|
|
11
|
-
|
|
12
|
-
import { clean } from "./output";
|
|
13
|
-
|
|
14
|
-
export interface Org {
|
|
15
|
-
workosId: string;
|
|
16
|
-
id?: string;
|
|
17
|
-
name?: string;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface Config {
|
|
21
|
-
org?: Org;
|
|
22
|
-
orgs?: Org[];
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const DEFAULT_API_URL = "https://odyssey.asteroid.ai";
|
|
26
|
-
export const DEFAULT_WORKOS_CLIENT_ID = "client_01K3NXPE8X6EJZXZSYCNT5M4P0";
|
|
27
|
-
export const DEFAULT_WORKOS_API_URL = "https://api.workos.com";
|
|
28
|
-
|
|
29
|
-
export interface Env {
|
|
30
|
-
apiUrl: string;
|
|
31
|
-
apiKey?: string;
|
|
32
|
-
org?: string;
|
|
33
|
-
workosClientId: string;
|
|
34
|
-
workosApiUrl: string;
|
|
35
|
-
configDir: string;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function readEnv(env: NodeJS.ProcessEnv = process.env): Env {
|
|
39
|
-
return {
|
|
40
|
-
apiUrl: (env.ASTEROID_API_URL || DEFAULT_API_URL).replace(/\/+$/, ""),
|
|
41
|
-
apiKey: env.ASTEROID_API_KEY || undefined,
|
|
42
|
-
org: env.ASTEROID_ORG || undefined,
|
|
43
|
-
workosClientId: env.ASTEROID_WORKOS_CLIENT_ID || DEFAULT_WORKOS_CLIENT_ID,
|
|
44
|
-
workosApiUrl: (
|
|
45
|
-
env.ASTEROID_WORKOS_API_URL || DEFAULT_WORKOS_API_URL
|
|
46
|
-
).replace(/\/+$/, ""),
|
|
47
|
-
configDir:
|
|
48
|
-
env.ASTEROID_CONFIG_DIR || envPaths("asteroid", { suffix: "" }).config,
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function readJson<T>(path: string, fallback: T): T {
|
|
53
|
-
if (!existsSync(path)) return fallback;
|
|
54
|
-
try {
|
|
55
|
-
return JSON.parse(readFileSync(path, "utf8")) as T;
|
|
56
|
-
} catch {
|
|
57
|
-
return fallback;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export function writePrivateJson(path: string, value: unknown) {
|
|
62
|
-
mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
|
|
63
|
-
const temp = `${path}.${process.pid}.tmp`;
|
|
64
|
-
writeFileSync(temp, `${JSON.stringify(value, null, 2)}\n`, { mode: 0o600 });
|
|
65
|
-
chmodSync(temp, 0o600);
|
|
66
|
-
renameSync(temp, path);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export function loadConfig(env: Env): Config {
|
|
70
|
-
return readJson<Config>(join(env.configDir, "config.json"), {});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export function saveConfig(env: Env, config: Config) {
|
|
74
|
-
writePrivateJson(join(env.configDir, "config.json"), config);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export function repoOrg(cwd: string): string | undefined {
|
|
78
|
-
let dir = cwd;
|
|
79
|
-
for (;;) {
|
|
80
|
-
const file = join(dir, ".asteroid", "org");
|
|
81
|
-
if (existsSync(file)) return readFileSync(file, "utf8").trim() || undefined;
|
|
82
|
-
const parent = dirname(dir);
|
|
83
|
-
if (parent === dir) return undefined;
|
|
84
|
-
dir = parent;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export function requestedOrg(
|
|
89
|
-
flag: string | undefined,
|
|
90
|
-
env: Env,
|
|
91
|
-
cwd: string,
|
|
92
|
-
config: Config,
|
|
93
|
-
) {
|
|
94
|
-
return flag ?? env.org ?? repoOrg(cwd) ?? config.org?.workosId;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export function findOrg(ref: string, orgs: Org[]): Org | undefined {
|
|
98
|
-
const lower = ref.toLowerCase();
|
|
99
|
-
return (
|
|
100
|
-
orgs.find(
|
|
101
|
-
(org) =>
|
|
102
|
-
org.workosId.toLowerCase() === lower || org.id?.toLowerCase() === lower,
|
|
103
|
-
) ??
|
|
104
|
-
orgs.find((org) => org.name?.toLowerCase() === lower) ??
|
|
105
|
-
(/^org_[0-9a-z]+$/i.test(ref) ? { workosId: ref } : undefined)
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export function mergeOrgs(known: Org[] = [], found: Org[] = []): Org[] {
|
|
110
|
-
const byId = new Map(known.map((org) => [org.workosId, org]));
|
|
111
|
-
for (const org of found) {
|
|
112
|
-
const merged = { ...byId.get(org.workosId) };
|
|
113
|
-
for (const [key, value] of Object.entries(org))
|
|
114
|
-
if (value !== undefined) Object.assign(merged, { [key]: value });
|
|
115
|
-
byId.set(org.workosId, merged as Org);
|
|
116
|
-
}
|
|
117
|
-
return [...byId.values()].sort((a, b) =>
|
|
118
|
-
(a.name ?? a.workosId).localeCompare(b.name ?? b.workosId),
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export function orgLabel(org: Org): string {
|
|
123
|
-
const id = clean(org.id ?? org.workosId);
|
|
124
|
-
return org.name ? `${clean(org.name)} (${id})` : id;
|
|
125
|
-
}
|
package/src/core.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
export { leadingWords, matchCommand, type Parsed, UsageError } from "./args";
|
|
2
|
-
export { COMMANDS } from "./generated/commands";
|
|
3
|
-
export { render } from "./output";
|
|
4
|
-
export {
|
|
5
|
-
type Invocation,
|
|
6
|
-
parseInvocation,
|
|
7
|
-
type ProgramOptions,
|
|
8
|
-
} from "./program";
|
|
9
|
-
export { type BuiltRequest, buildRequest, type InputReader } from "./request";
|
|
10
|
-
export type { CliCommand, Option } from "./types";
|
|
11
|
-
export { ALL_COMMANDS, withSyncCommands } from "./commands";
|
|
12
|
-
export { type Activity, formatActivitiesMarkdown } from "./sync/activities";
|
|
13
|
-
export {
|
|
14
|
-
type Execution,
|
|
15
|
-
type ExecutionPullOptions,
|
|
16
|
-
type ExecutionPullResult,
|
|
17
|
-
formatExecutionPull,
|
|
18
|
-
pullExecution,
|
|
19
|
-
} from "./sync/execution-pull";
|
|
20
|
-
export { matchesGlob } from "./sync/paths";
|
|
21
|
-
export { runSync, type SyncDeps, SYNC_COMMANDS } from "./sync/run";
|
|
22
|
-
export {
|
|
23
|
-
type FileEntry,
|
|
24
|
-
type FileTree,
|
|
25
|
-
type LocalFiles,
|
|
26
|
-
MANIFEST,
|
|
27
|
-
type Manifest,
|
|
28
|
-
type Remote,
|
|
29
|
-
type Sync,
|
|
30
|
-
} from "./sync/types";
|
|
31
|
-
export {
|
|
32
|
-
formatWorkflowPull,
|
|
33
|
-
pullWorkflow,
|
|
34
|
-
type WorkflowPullOptions,
|
|
35
|
-
type WorkflowPullResult,
|
|
36
|
-
} from "./sync/workflow-pull";
|
|
37
|
-
export {
|
|
38
|
-
formatWorkflowPush,
|
|
39
|
-
pushWorkflow,
|
|
40
|
-
type WorkflowPushResult,
|
|
41
|
-
} from "./sync/workflow-push";
|