@project-ajax/cli 0.0.6 → 0.0.8
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/api/client.d.ts +3 -16
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +9 -20
- package/dist/commands/auth.d.ts.map +1 -1
- package/dist/commands/auth.impl.d.ts.map +1 -1
- package/dist/commands/auth.impl.js +87 -16
- package/dist/commands/auth.js +10 -2
- package/dist/commands/oauth.d.ts +2 -0
- package/dist/commands/oauth.d.ts.map +1 -0
- package/dist/commands/oauth.impl.d.ts +3 -0
- package/dist/commands/oauth.impl.d.ts.map +1 -0
- package/dist/commands/oauth.impl.js +110 -0
- package/dist/commands/oauth.impl.test.d.ts +2 -0
- package/dist/commands/oauth.impl.test.d.ts.map +1 -0
- package/dist/commands/oauth.js +35 -0
- package/dist/commands/secrets.impl.d.ts.map +1 -1
- package/dist/commands/secrets.impl.js +0 -6
- package/dist/io.d.ts +1 -0
- package/dist/io.d.ts.map +1 -1
- package/dist/io.js +4 -0
- package/dist/routes.js +2 -2
- package/package.json +1 -1
- package/dist/commands/connect.d.ts +0 -2
- package/dist/commands/connect.d.ts.map +0 -1
- package/dist/commands/connect.impl.d.ts +0 -6
- package/dist/commands/connect.impl.d.ts.map +0 -1
- package/dist/commands/connect.impl.js +0 -116
- package/dist/commands/connect.js +0 -78
package/dist/api/client.d.ts
CHANGED
|
@@ -90,7 +90,7 @@ export declare class ApiClient {
|
|
|
90
90
|
*/
|
|
91
91
|
fetchAndSaveCapabilities(workerId: string): Promise<Result<{
|
|
92
92
|
capabilities: ReadonlyArray<{
|
|
93
|
-
_tag: "sync" | "tool";
|
|
93
|
+
_tag: "sync" | "tool" | "oauth" | "automation" | "slashCommand" | "handleSearch" | "handleSelect";
|
|
94
94
|
spaceId: string;
|
|
95
95
|
workerId: string;
|
|
96
96
|
key: string;
|
|
@@ -134,29 +134,16 @@ export declare class ApiClient {
|
|
|
134
134
|
value: string;
|
|
135
135
|
}>;
|
|
136
136
|
}, ApiError>>;
|
|
137
|
-
listOauthProviders(): Promise<Result<{
|
|
138
|
-
providers: Array<{
|
|
139
|
-
key: string;
|
|
140
|
-
displayName: string;
|
|
141
|
-
}>;
|
|
142
|
-
}, ApiError>>;
|
|
143
137
|
/**
|
|
144
138
|
* Start the OAuth flow for a provider
|
|
145
139
|
*/
|
|
146
140
|
startOauth(args: {
|
|
147
141
|
workerId: string;
|
|
148
|
-
|
|
142
|
+
capabilityKey: string;
|
|
149
143
|
}): Promise<Result<{
|
|
150
144
|
authorizationUrl: string;
|
|
151
145
|
state: string;
|
|
152
146
|
}, ApiError>>;
|
|
153
|
-
/**
|
|
154
|
-
* Remove an OAuth connection for a worker
|
|
155
|
-
*/
|
|
156
|
-
deleteOauthConnection(args: {
|
|
157
|
-
workerId: string;
|
|
158
|
-
provider: string;
|
|
159
|
-
}): Promise<Result<Record<string, never>, ApiError>>;
|
|
160
147
|
/**
|
|
161
148
|
* Delete a secret
|
|
162
149
|
*/
|
|
@@ -166,7 +153,7 @@ export declare class ApiClient {
|
|
|
166
153
|
*/
|
|
167
154
|
listCapabilities(workerId: string): Promise<Result<{
|
|
168
155
|
capabilities: Array<{
|
|
169
|
-
_tag: "sync" | "tool";
|
|
156
|
+
_tag: "sync" | "tool" | "oauth" | "automation" | "slashCommand" | "handleSearch" | "handleSelect";
|
|
170
157
|
key: string;
|
|
171
158
|
}>;
|
|
172
159
|
}, ApiError>>;
|
package/dist/api/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/api/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,SAAS,GAAG,KAAK,GAAG,MAAM,CAA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AAC;YACxB,SAAS,EAAE,MAAM,CAAC;YAClB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;SACvB,CAAC,CAAC;KACH,EACD,QAAQ,CACR,CACD;IASD;;OAEG;IACG,UAAU,CACf,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,GACX,OAAO,CACT,MAAM,CACL;QACC,IAAI,EAAE,MAAM,CAAC;KACb,EACD,QAAQ,CACR,CACD;CASD"}
|
package/dist/api/client.js
CHANGED
|
@@ -154,12 +154,6 @@ class ApiClient {
|
|
|
154
154
|
}
|
|
155
155
|
});
|
|
156
156
|
}
|
|
157
|
-
async listOauthProviders() {
|
|
158
|
-
return this.fetch("/workersListOauthProviders", {
|
|
159
|
-
method: "POST",
|
|
160
|
-
body: {}
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
157
|
/**
|
|
164
158
|
* Start the OAuth flow for a provider
|
|
165
159
|
*/
|
|
@@ -168,19 +162,7 @@ class ApiClient {
|
|
|
168
162
|
method: "POST",
|
|
169
163
|
body: {
|
|
170
164
|
workerId: args.workerId,
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Remove an OAuth connection for a worker
|
|
177
|
-
*/
|
|
178
|
-
async deleteOauthConnection(args) {
|
|
179
|
-
return this.fetch("/workersDeleteOauthConnection", {
|
|
180
|
-
method: "POST",
|
|
181
|
-
body: {
|
|
182
|
-
workerId: args.workerId,
|
|
183
|
-
provider: args.provider
|
|
165
|
+
oauthCapabilityKey: args.capabilityKey
|
|
184
166
|
}
|
|
185
167
|
});
|
|
186
168
|
}
|
|
@@ -296,7 +278,14 @@ function headersInitToEntries(headersInit) {
|
|
|
296
278
|
}
|
|
297
279
|
async function parseApiError(response) {
|
|
298
280
|
const errorText = await response.text();
|
|
299
|
-
|
|
281
|
+
let displayMessage;
|
|
282
|
+
try {
|
|
283
|
+
const errorJson = JSON.parse(errorText);
|
|
284
|
+
displayMessage = errorJson.debugMessage ?? errorJson.message ?? errorText;
|
|
285
|
+
} catch {
|
|
286
|
+
displayMessage = errorText;
|
|
287
|
+
}
|
|
288
|
+
const message = `[${response.status}] ${response.statusText}: ${displayMessage}`;
|
|
300
289
|
const error = {
|
|
301
290
|
status: response.status,
|
|
302
291
|
statusText: response.statusText,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/commands/auth.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/commands/auth.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,YAAY,wEAkEvB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.impl.d.ts","sourceRoot":"","sources":["../../src/commands/auth.impl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"auth.impl.d.ts","sourceRoot":"","sources":["../../src/commands/auth.impl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AA0E/C,eAAO,MAAM,KAAK,+GA8FhB,CAAC;AAEH,eAAO,MAAM,IAAI,mFAEf,CAAC;AAEH,eAAO,MAAM,MAAM,mFAIjB,CAAC"}
|
|
@@ -1,33 +1,104 @@
|
|
|
1
1
|
import { buildHandler } from "../handler.js";
|
|
2
2
|
import { openNotionUrl } from "../utils/openUrl.js";
|
|
3
|
+
async function loginFetch(baseUrl, endpoint, body) {
|
|
4
|
+
const url = `${baseUrl}/api/v3${endpoint}`;
|
|
5
|
+
const response = await fetch(url, {
|
|
6
|
+
method: "POST",
|
|
7
|
+
headers: {
|
|
8
|
+
"Content-Type": "application/json"
|
|
9
|
+
},
|
|
10
|
+
body: JSON.stringify(body)
|
|
11
|
+
});
|
|
12
|
+
if (!response.ok) {
|
|
13
|
+
const text = await response.text();
|
|
14
|
+
throw new Error(`Login request failed: ${response.status} ${text}`);
|
|
15
|
+
}
|
|
16
|
+
return await response.json();
|
|
17
|
+
}
|
|
18
|
+
async function pollLoginRedeem(baseUrl, sessionId, timeoutMs = 3e5, intervalMs = 2e3) {
|
|
19
|
+
const startTime = Date.now();
|
|
20
|
+
while (Date.now() - startTime < timeoutMs) {
|
|
21
|
+
const result = await loginFetch(
|
|
22
|
+
baseUrl,
|
|
23
|
+
"/workersCliLoginRedeem",
|
|
24
|
+
{ sessionId }
|
|
25
|
+
);
|
|
26
|
+
if (result.status === "confirmed" || result.status === "expired") {
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
30
|
+
}
|
|
31
|
+
return { status: "expired" };
|
|
32
|
+
}
|
|
3
33
|
const login = buildHandler(async function(_, token) {
|
|
4
34
|
const environment = this.config.environment;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
await openNotionUrl(environment, url);
|
|
14
|
-
} catch (_error) {
|
|
15
|
-
this.io.writeErr(
|
|
16
|
-
`Failed to open browser automatically. Please visit:
|
|
17
|
-
${url}`
|
|
18
|
-
);
|
|
35
|
+
const baseUrl = this.config.baseUrl;
|
|
36
|
+
if (token) {
|
|
37
|
+
const update2 = {
|
|
38
|
+
token,
|
|
39
|
+
workerId: null
|
|
40
|
+
};
|
|
41
|
+
if (environment !== "prod") {
|
|
42
|
+
update2.environment = environment;
|
|
19
43
|
}
|
|
44
|
+
await this.config.update(update2);
|
|
45
|
+
this.io.writeErr("Successfully logged in!");
|
|
20
46
|
return;
|
|
21
47
|
}
|
|
48
|
+
this.io.writeErr("Starting browser login...\n");
|
|
49
|
+
let initResponse;
|
|
50
|
+
try {
|
|
51
|
+
initResponse = await loginFetch(
|
|
52
|
+
baseUrl,
|
|
53
|
+
"/workersCliLoginInit",
|
|
54
|
+
{}
|
|
55
|
+
);
|
|
56
|
+
} catch (error) {
|
|
57
|
+
this.io.writeErr(
|
|
58
|
+
`Failed to start login: ${error instanceof Error ? error.message : String(error)}`
|
|
59
|
+
);
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
62
|
+
const { sessionId, verificationCode, browserUrl } = initResponse;
|
|
63
|
+
this.io.writeErr(
|
|
64
|
+
"Copy this verification code and paste it in your browser:\n"
|
|
65
|
+
);
|
|
66
|
+
this.io.writeErr(` ${verificationCode}
|
|
67
|
+
`);
|
|
68
|
+
await this.io.input({
|
|
69
|
+
message: "Press Enter to open browser...",
|
|
70
|
+
noTTY: `Please visit this URL to authenticate:
|
|
71
|
+
${browserUrl}`
|
|
72
|
+
});
|
|
73
|
+
try {
|
|
74
|
+
await openNotionUrl(environment, browserUrl);
|
|
75
|
+
} catch (_error) {
|
|
76
|
+
this.io.writeErr(
|
|
77
|
+
`Could not open browser automatically. Please visit:
|
|
78
|
+
${browserUrl}`
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
this.io.writeErr("");
|
|
82
|
+
this.io.writeErr("Waiting for browser confirmation...");
|
|
83
|
+
this.io.writeErr("(Press Ctrl+C to cancel)\n");
|
|
84
|
+
const redeemResponse = await pollLoginRedeem(baseUrl, sessionId);
|
|
85
|
+
if (redeemResponse.status === "expired") {
|
|
86
|
+
this.io.writeErr("Login session expired. Please try again.");
|
|
87
|
+
process.exit(1);
|
|
88
|
+
}
|
|
89
|
+
if (redeemResponse.status !== "confirmed") {
|
|
90
|
+
this.io.writeErr("Login failed. Please try again.");
|
|
91
|
+
process.exit(1);
|
|
92
|
+
}
|
|
22
93
|
const update = {
|
|
23
|
-
token,
|
|
94
|
+
token: redeemResponse.token,
|
|
24
95
|
workerId: null
|
|
25
96
|
};
|
|
26
97
|
if (environment !== "prod") {
|
|
27
98
|
update.environment = environment;
|
|
28
99
|
}
|
|
29
100
|
await this.config.update(update);
|
|
30
|
-
this.io.writeErr("Successfully logged in!");
|
|
101
|
+
this.io.writeErr("\u2713 Successfully logged in!");
|
|
31
102
|
});
|
|
32
103
|
const show = buildHandler(function() {
|
|
33
104
|
this.io.writeOut(`${this.config.token ?? ""}`);
|
package/dist/commands/auth.js
CHANGED
|
@@ -7,14 +7,22 @@ const authCommands = buildRouteMap({
|
|
|
7
7
|
routes: {
|
|
8
8
|
login: buildCommand({
|
|
9
9
|
docs: {
|
|
10
|
-
brief: "Login to the Project Ajax platform
|
|
10
|
+
brief: "Login to the Project Ajax platform via browser authentication",
|
|
11
|
+
fullDescription: `
|
|
12
|
+
Opens a browser window for you to authenticate and select a workspace.
|
|
13
|
+
A verification code will be displayed in the terminal - make sure it matches
|
|
14
|
+
what you see in your browser before confirming.
|
|
15
|
+
|
|
16
|
+
Alternatively, you can pass a token directly (for automation or CI environments):
|
|
17
|
+
workers auth login <token>
|
|
18
|
+
`.trim()
|
|
11
19
|
},
|
|
12
20
|
parameters: {
|
|
13
21
|
positional: {
|
|
14
22
|
kind: "tuple",
|
|
15
23
|
parameters: [
|
|
16
24
|
{
|
|
17
|
-
brief: "A Workers API token",
|
|
25
|
+
brief: "A Workers API token (optional, for CI/automation)",
|
|
18
26
|
parse: String,
|
|
19
27
|
placeholder: "api-token",
|
|
20
28
|
optional: true
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth.d.ts","sourceRoot":"","sources":["../../src/commands/oauth.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,aAAa,wEA6BxB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth.impl.d.ts","sourceRoot":"","sources":["../../src/commands/oauth.impl.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAI5D,eAAO,MAAM,UAAU,oIA+ErB,CAAC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { Result } from "../api/result.js";
|
|
2
|
+
import { buildAuthedHandler } from "../handler.js";
|
|
3
|
+
import { openBrowserUrl } from "../utils/openUrl.js";
|
|
4
|
+
const startOauth = buildAuthedHandler(async function(flags, capabilityKey) {
|
|
5
|
+
const workerId = requireWorkerId(this);
|
|
6
|
+
if (!capabilityKey) {
|
|
7
|
+
const oauthCapabilityKeys = await fetchOauthCapabilityKeys(
|
|
8
|
+
this,
|
|
9
|
+
workerId,
|
|
10
|
+
flags.plain
|
|
11
|
+
);
|
|
12
|
+
if (oauthCapabilityKeys.length === 0) {
|
|
13
|
+
this.process.exitCode = 1;
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (!this.process.stdin.isTTY) {
|
|
17
|
+
this.io.writeErr("Expected argument for capabilityKey");
|
|
18
|
+
this.io.writeErr("Start OAuth with:");
|
|
19
|
+
this.io.writeErr(" npx workers oauth start <capabilityKey>");
|
|
20
|
+
this.process.exitCode = 1;
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const selected = await this.io.select({
|
|
24
|
+
message: "Select an OAuth capability",
|
|
25
|
+
choices: oauthCapabilityKeys.map((key) => ({ name: key, value: key })),
|
|
26
|
+
default: oauthCapabilityKeys[0],
|
|
27
|
+
noTTY: "Expected argument for capabilityKey. Run `npx workers oauth start <capabilityKey>`."
|
|
28
|
+
});
|
|
29
|
+
capabilityKey = selected;
|
|
30
|
+
if (!capabilityKey) {
|
|
31
|
+
this.process.exitCode = 1;
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
this.process.stderr.write(
|
|
36
|
+
`Starting OAuth flow with capability "${capabilityKey}"...`
|
|
37
|
+
);
|
|
38
|
+
const startResult = await this.apiClient.startOauth({
|
|
39
|
+
workerId,
|
|
40
|
+
capabilityKey
|
|
41
|
+
});
|
|
42
|
+
if (Result.isFail(startResult)) {
|
|
43
|
+
this.process.stderr.write("ERROR\n\n");
|
|
44
|
+
reportApiError(this, startResult.error, "start OAuth flow");
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
this.process.stderr.write("OK\n\n");
|
|
48
|
+
const { authorizationUrl } = startResult.value;
|
|
49
|
+
this.io.writeErr("Opening your browser to continue the OAuth flow...");
|
|
50
|
+
try {
|
|
51
|
+
await openBrowserUrl(authorizationUrl);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
this.io.writeErr(
|
|
54
|
+
`Unable to open the browser automatically (${String(
|
|
55
|
+
error
|
|
56
|
+
)}). Please open the link below manually.`
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
this.io.writeErr("");
|
|
60
|
+
this.io.writeErr("If the browser did not open, visit:");
|
|
61
|
+
this.io.writeErr(` ${authorizationUrl}`);
|
|
62
|
+
this.io.writeErr("");
|
|
63
|
+
this.io.writeErr(
|
|
64
|
+
"After completing the flow in your browser, return to the CLI."
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
function requireWorkerId(context) {
|
|
68
|
+
const workerId = context.config.workerId;
|
|
69
|
+
if (!workerId) {
|
|
70
|
+
throw new Error(
|
|
71
|
+
"No worker configured. Run 'workers deploy' first to create a worker."
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
return workerId;
|
|
75
|
+
}
|
|
76
|
+
function reportApiError(context, error, action) {
|
|
77
|
+
context.io.writeErr(`\u2717 Failed to ${action}`);
|
|
78
|
+
context.io.writeErr(`\u2717 ${error.message}`);
|
|
79
|
+
throw new Error(error.message);
|
|
80
|
+
}
|
|
81
|
+
async function fetchOauthCapabilityKeys(context, workerId, plain) {
|
|
82
|
+
context.process.stderr.write("Fetching OAuth capabilities...");
|
|
83
|
+
const capabilitiesResult = await context.apiClient.listCapabilities(workerId);
|
|
84
|
+
if (Result.isFail(capabilitiesResult)) {
|
|
85
|
+
context.process.stderr.write("ERROR\n\n");
|
|
86
|
+
reportApiError(context, capabilitiesResult.error, "list capabilities");
|
|
87
|
+
}
|
|
88
|
+
const oauthCaps = capabilitiesResult.value.capabilities.filter(
|
|
89
|
+
(cap) => cap._tag === "oauth"
|
|
90
|
+
);
|
|
91
|
+
context.process.stderr.write("OK\n\n");
|
|
92
|
+
if (oauthCaps.length === 0) {
|
|
93
|
+
context.io.writeErr("No OAuth capabilities found for this worker.");
|
|
94
|
+
context.io.writeErr(
|
|
95
|
+
"Run `npx workers capabilities list` to see all capabilities."
|
|
96
|
+
);
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
context.io.writeErr("OAuth capabilities:");
|
|
100
|
+
context.io.writeTableErr({
|
|
101
|
+
headers: ["Key"],
|
|
102
|
+
rows: oauthCaps.map((cap) => [cap.key]),
|
|
103
|
+
plain
|
|
104
|
+
});
|
|
105
|
+
context.io.writeErr("");
|
|
106
|
+
return oauthCaps.map((cap) => cap.key);
|
|
107
|
+
}
|
|
108
|
+
export {
|
|
109
|
+
startOauth
|
|
110
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth.impl.test.d.ts","sourceRoot":"","sources":["../../src/commands/oauth.impl.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { buildCommand, buildRouteMap } from "@stricli/core";
|
|
2
|
+
import { formatFlags, globalFlags } from "../flags.js";
|
|
3
|
+
const oauthCommands = buildRouteMap({
|
|
4
|
+
docs: {
|
|
5
|
+
brief: "Manage OAuth connections for your worker"
|
|
6
|
+
},
|
|
7
|
+
routes: {
|
|
8
|
+
start: buildCommand({
|
|
9
|
+
docs: {
|
|
10
|
+
brief: "Start an OAuth flow for a capability"
|
|
11
|
+
},
|
|
12
|
+
parameters: {
|
|
13
|
+
positional: {
|
|
14
|
+
kind: "tuple",
|
|
15
|
+
parameters: [
|
|
16
|
+
{
|
|
17
|
+
brief: "OAuth capability key",
|
|
18
|
+
parse: String,
|
|
19
|
+
placeholder: "capabilityKey",
|
|
20
|
+
optional: true
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
},
|
|
24
|
+
flags: {
|
|
25
|
+
...globalFlags,
|
|
26
|
+
...formatFlags
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
loader: () => import("./oauth.impl.js").then((m) => m.startOauth)
|
|
30
|
+
})
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
export {
|
|
34
|
+
oauthCommands
|
|
35
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"secrets.impl.d.ts","sourceRoot":"","sources":["../../src/commands/secrets.impl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAK5D,eAAO,MAAM,UAAU,sGA0BrB,CAAC;AAEH,eAAO,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"secrets.impl.d.ts","sourceRoot":"","sources":["../../src/commands/secrets.impl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAK5D,eAAO,MAAM,UAAU,sGA0BrB,CAAC;AAEH,eAAO,MAAM,WAAW,iGAkCtB,CAAC;AAEH,eAAO,MAAM,YAAY,gGAwBvB,CAAC"}
|
|
@@ -36,18 +36,12 @@ const listSecrets = buildAuthedHandler(async function(flags) {
|
|
|
36
36
|
const data = Result.unwrap(result);
|
|
37
37
|
if (data.secrets.length === 0) {
|
|
38
38
|
this.io.writeErr("No secrets for this worker.");
|
|
39
|
-
this.io.writeErr(
|
|
40
|
-
"To list OAuth connect secrets, use `npx workers connect list`"
|
|
41
|
-
);
|
|
42
39
|
} else {
|
|
43
40
|
this.io.writeTableOut({
|
|
44
41
|
headers: ["Key", "Created At"],
|
|
45
42
|
rows: data.secrets.map((secret) => [secret.key, secret.createdAt]),
|
|
46
43
|
plain: flags.plain
|
|
47
44
|
});
|
|
48
|
-
this.io.writeErr(
|
|
49
|
-
"To list OAuth connect secrets, use `npx workers connect list`"
|
|
50
|
-
);
|
|
51
45
|
}
|
|
52
46
|
} else {
|
|
53
47
|
this.process.stderr.write("ERROR\n\n");
|
package/dist/io.d.ts
CHANGED
|
@@ -50,6 +50,7 @@ export declare class IO {
|
|
|
50
50
|
writeTableErr(tableConfig: TableOptions): void;
|
|
51
51
|
confirm(config: WithSafety<Parameters<typeof prompts.confirm>[0]>): Promise<boolean | void>;
|
|
52
52
|
input(config: WithSafety<Parameters<typeof prompts.input>[0]>): Promise<string | void>;
|
|
53
|
+
select<Value>(config: WithSafety<Parameters<typeof prompts.select<Value>>[0]>): ReturnType<typeof prompts.select<Value>>;
|
|
53
54
|
}
|
|
54
55
|
export {};
|
|
55
56
|
//# sourceMappingURL=io.d.ts.map
|
package/dist/io.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"io.d.ts","sourceRoot":"","sources":["../src/io.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAe,KAAK,SAAS,EAAkB,MAAM,mBAAmB,CAAC;AAEhF,MAAM,WAAW,aAAa;IAC7B,YAAY,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,YAAY;IAC5B,OAAO,EAAE,SAAS,EAAE,GAAG,SAAS,EAAE,EAAE,CAAC;IACrC,IAAI,EAAE,SAAS,EAAE,EAAE,CAAC;IACpB,KAAK,EAAE,OAAO,CAAC;CACf;AAED,KAAK,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG;IACxB,KAAK,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;GAEG;AACH,qBAAa,EAAE;;IACd,YAAY,EAAE,OAAO,CAAC;gBAEV,OAAO,EAAE,aAAa;IAIlC;;;;OAIG;IACH,KAAK,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,OAAO,CAAC,GAAG,CAAC;IAW7C;;;;OAIG;IACH,QAAQ,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,OAAO,CAAC,MAAM,CAAC,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;IACH,QAAQ,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;IAIzD;;;;OAIG;IACH,aAAa,CAAC,WAAW,EAAE,YAAY;IAKvC;;;;OAIG;IACH,aAAa,CAAC,WAAW,EAAE,YAAY;IAKvC,OAAO,CAAC,MAAM,EAAE,UAAU,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAKjE,KAAK,CAAC,MAAM,EAAE,UAAU,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAK7D,MAAM,CAAC,KAAK,EACX,MAAM,EAAE,UAAU,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAKjB,UAAU,CACvD,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAC5B;CAqCF"}
|
package/dist/io.js
CHANGED
|
@@ -61,6 +61,10 @@ class IO {
|
|
|
61
61
|
this.#ensureTTY(config.noTTY);
|
|
62
62
|
return prompts.input(config).catch(this.#handlePromptExit.bind(this));
|
|
63
63
|
}
|
|
64
|
+
select(config) {
|
|
65
|
+
this.#ensureTTY(config.noTTY);
|
|
66
|
+
return prompts.select(config).catch(this.#handlePromptExit.bind(this));
|
|
67
|
+
}
|
|
64
68
|
#ensureTTY(noTTY) {
|
|
65
69
|
if (!process.stdin.isTTY) {
|
|
66
70
|
this.writeErr(noTTY);
|
package/dist/routes.js
CHANGED
|
@@ -3,10 +3,10 @@ import packageJson from "../package.json" with { type: "json" };
|
|
|
3
3
|
import { authCommands } from "./commands/auth.js";
|
|
4
4
|
import { bundleCommands } from "./commands/bundle.js";
|
|
5
5
|
import { capabilitiesCommands } from "./commands/capabilities.js";
|
|
6
|
-
import { connectCommands } from "./commands/connect.js";
|
|
7
6
|
import deploy from "./commands/deploy.js";
|
|
8
7
|
import { envCommands } from "./commands/env.js";
|
|
9
8
|
import exec from "./commands/exec.js";
|
|
9
|
+
import { oauthCommands } from "./commands/oauth.js";
|
|
10
10
|
import { runsCommands } from "./commands/runs.js";
|
|
11
11
|
import { secretsCommands } from "./commands/secrets.js";
|
|
12
12
|
import { TokenNotSetError } from "./config.js";
|
|
@@ -33,7 +33,7 @@ variables can also be provided:
|
|
|
33
33
|
capabilities: capabilitiesCommands,
|
|
34
34
|
deploy,
|
|
35
35
|
exec,
|
|
36
|
-
|
|
36
|
+
oauth: oauthCommands,
|
|
37
37
|
env: envCommands,
|
|
38
38
|
runs: runsCommands,
|
|
39
39
|
secrets: secretsCommands,
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connect.d.ts","sourceRoot":"","sources":["../../src/commands/connect.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,eAAe,wEA2E1B,CAAC"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { FormatFlags, GlobalFlags } from "../flags.js";
|
|
2
|
-
export declare const listProviders: (this: import("../context.js").LocalContext, flags: GlobalFlags & FormatFlags) => Promise<void>;
|
|
3
|
-
export declare const addConnection: (this: import("../context.js").LocalContext, flags: GlobalFlags, provider: string) => Promise<void>;
|
|
4
|
-
export declare const listConnections: (this: import("../context.js").LocalContext, flags: GlobalFlags & FormatFlags) => Promise<void>;
|
|
5
|
-
export declare const removeConnection: (this: import("../context.js").LocalContext, flags: GlobalFlags, provider: string) => Promise<void>;
|
|
6
|
-
//# sourceMappingURL=connect.impl.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connect.impl.d.ts","sourceRoot":"","sources":["../../src/commands/connect.impl.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAI5D,eAAO,MAAM,aAAa,iGAuBxB,CAAC;AAEH,eAAO,MAAM,aAAa,qGAuCxB,CAAC;AAEH,eAAO,MAAM,eAAe,iGAiC1B,CAAC;AAEH,eAAO,MAAM,gBAAgB,qGAqB3B,CAAC"}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { Result } from "../api/result.js";
|
|
2
|
-
import { buildAuthedHandler } from "../handler.js";
|
|
3
|
-
import { openBrowserUrl } from "../utils/openUrl.js";
|
|
4
|
-
const listProviders = buildAuthedHandler(async function(flags) {
|
|
5
|
-
this.process.stderr.write("Fetching providers...");
|
|
6
|
-
const providersResult = await this.apiClient.listOauthProviders();
|
|
7
|
-
if (Result.isFail(providersResult)) {
|
|
8
|
-
this.process.stderr.write("ERROR\n\n");
|
|
9
|
-
reportApiError(this, providersResult.error, "list providers");
|
|
10
|
-
} else {
|
|
11
|
-
this.process.stderr.write("OK\n\n");
|
|
12
|
-
const providers = providersResult.value.providers;
|
|
13
|
-
if (providers.length === 0) {
|
|
14
|
-
this.io.writeErr("No OAuth providers are currently available.");
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
this.io.writeTableOut({
|
|
18
|
-
headers: ["Provider", "Description"],
|
|
19
|
-
rows: providers.map((provider) => [provider.key, provider.displayName]),
|
|
20
|
-
plain: flags.plain
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
const addConnection = buildAuthedHandler(async function(_flags, provider) {
|
|
25
|
-
const workerId = requireWorkerId(this);
|
|
26
|
-
this.process.stderr.write(
|
|
27
|
-
`Starting OAuth flow with provider "${provider}"...`
|
|
28
|
-
);
|
|
29
|
-
const startResult = await this.apiClient.startOauth({ workerId, provider });
|
|
30
|
-
if (Result.isFail(startResult)) {
|
|
31
|
-
this.process.stderr.write("ERROR\n\n");
|
|
32
|
-
reportApiError(this, startResult.error, "start OAuth flow");
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
this.process.stderr.write("OK\n\n");
|
|
36
|
-
const { authorizationUrl } = startResult.value;
|
|
37
|
-
this.io.writeErr("Opening your browser to continue the OAuth flow...");
|
|
38
|
-
try {
|
|
39
|
-
await openBrowserUrl(authorizationUrl);
|
|
40
|
-
} catch (error) {
|
|
41
|
-
this.io.writeErr(
|
|
42
|
-
`Unable to open the browser automatically (${String(
|
|
43
|
-
error
|
|
44
|
-
)}). Please open the link below manually.`
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
this.io.writeErr("");
|
|
48
|
-
this.io.writeErr("If the browser did not open, visit:");
|
|
49
|
-
this.io.writeErr(` ${authorizationUrl}`);
|
|
50
|
-
this.io.writeErr("");
|
|
51
|
-
this.io.writeErr(
|
|
52
|
-
"After completing the flow in your browser, return to the CLI."
|
|
53
|
-
);
|
|
54
|
-
});
|
|
55
|
-
const listConnections = buildAuthedHandler(async function(flags) {
|
|
56
|
-
const workerId = requireWorkerId(this);
|
|
57
|
-
this.process.stderr.write("Fetching OAuth connections...");
|
|
58
|
-
const secretsResult = await this.apiClient.listSecrets(workerId, {
|
|
59
|
-
secretKinds: ["oauth"]
|
|
60
|
-
});
|
|
61
|
-
if (Result.isFail(secretsResult)) {
|
|
62
|
-
this.process.stderr.write("ERROR\n\n");
|
|
63
|
-
reportApiError(this, secretsResult.error, "list OAuth connections");
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
this.process.stderr.write("OK\n\n");
|
|
67
|
-
const secrets = secretsResult.value.secrets;
|
|
68
|
-
if (secrets.length === 0) {
|
|
69
|
-
this.io.writeErr("No OAuth connections found for this worker.");
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
this.io.writeTableOut({
|
|
73
|
-
headers: ["Env Var", "Created At"],
|
|
74
|
-
rows: secrets.map((secret) => [
|
|
75
|
-
`process.env.${secret.key}`,
|
|
76
|
-
secret.createdAt
|
|
77
|
-
]),
|
|
78
|
-
plain: flags.plain
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
const removeConnection = buildAuthedHandler(async function(_flags, provider) {
|
|
82
|
-
const workerId = requireWorkerId(this);
|
|
83
|
-
this.process.stderr.write(
|
|
84
|
-
`Removing OAuth connection for provider "${provider}"...`
|
|
85
|
-
);
|
|
86
|
-
const result = await this.apiClient.deleteOauthConnection({
|
|
87
|
-
workerId,
|
|
88
|
-
provider
|
|
89
|
-
});
|
|
90
|
-
if (Result.isFail(result)) {
|
|
91
|
-
this.process.stderr.write("ERROR\n\n");
|
|
92
|
-
reportApiError(this, result.error, "remove connection");
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
this.process.stderr.write("OK\n");
|
|
96
|
-
});
|
|
97
|
-
function requireWorkerId(context) {
|
|
98
|
-
const workerId = context.config.workerId;
|
|
99
|
-
if (!workerId) {
|
|
100
|
-
throw new Error(
|
|
101
|
-
"No worker configured. Run 'workers deploy' first to create a worker."
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
return workerId;
|
|
105
|
-
}
|
|
106
|
-
function reportApiError(context, error, action) {
|
|
107
|
-
context.io.writeErr(`\u2717 Failed to ${action}`);
|
|
108
|
-
context.io.writeErr(`\u2717 ${error.message}`);
|
|
109
|
-
throw new Error(error.message);
|
|
110
|
-
}
|
|
111
|
-
export {
|
|
112
|
-
addConnection,
|
|
113
|
-
listConnections,
|
|
114
|
-
listProviders,
|
|
115
|
-
removeConnection
|
|
116
|
-
};
|
package/dist/commands/connect.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { buildCommand, buildRouteMap } from "@stricli/core";
|
|
2
|
-
import { formatFlags, globalFlags } from "../flags.js";
|
|
3
|
-
const connectCommands = buildRouteMap({
|
|
4
|
-
docs: {
|
|
5
|
-
brief: "Manage OAuth connections for your worker"
|
|
6
|
-
},
|
|
7
|
-
routes: {
|
|
8
|
-
providers: buildCommand({
|
|
9
|
-
docs: {
|
|
10
|
-
brief: "List available OAuth providers"
|
|
11
|
-
},
|
|
12
|
-
parameters: {
|
|
13
|
-
flags: {
|
|
14
|
-
...globalFlags,
|
|
15
|
-
...formatFlags
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
loader: () => import("./connect.impl.js").then((m) => m.listProviders)
|
|
19
|
-
}),
|
|
20
|
-
add: buildCommand({
|
|
21
|
-
docs: {
|
|
22
|
-
brief: "Start an OAuth flow for a provider"
|
|
23
|
-
},
|
|
24
|
-
parameters: {
|
|
25
|
-
positional: {
|
|
26
|
-
kind: "tuple",
|
|
27
|
-
parameters: [
|
|
28
|
-
{
|
|
29
|
-
brief: "Provider name (see `providers` command)",
|
|
30
|
-
parse: String,
|
|
31
|
-
placeholder: "provider"
|
|
32
|
-
}
|
|
33
|
-
]
|
|
34
|
-
},
|
|
35
|
-
flags: {
|
|
36
|
-
...globalFlags
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
loader: () => import("./connect.impl.js").then((m) => m.addConnection)
|
|
40
|
-
}),
|
|
41
|
-
list: buildCommand({
|
|
42
|
-
docs: {
|
|
43
|
-
brief: "List active OAuth connections"
|
|
44
|
-
},
|
|
45
|
-
parameters: {
|
|
46
|
-
flags: {
|
|
47
|
-
...globalFlags,
|
|
48
|
-
...formatFlags
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
loader: () => import("./connect.impl.js").then((m) => m.listConnections)
|
|
52
|
-
}),
|
|
53
|
-
rm: buildCommand({
|
|
54
|
-
docs: {
|
|
55
|
-
brief: "Remove an OAuth connection"
|
|
56
|
-
},
|
|
57
|
-
parameters: {
|
|
58
|
-
positional: {
|
|
59
|
-
kind: "tuple",
|
|
60
|
-
parameters: [
|
|
61
|
-
{
|
|
62
|
-
brief: "Provider name to remove",
|
|
63
|
-
parse: String,
|
|
64
|
-
placeholder: "provider"
|
|
65
|
-
}
|
|
66
|
-
]
|
|
67
|
-
},
|
|
68
|
-
flags: {
|
|
69
|
-
...globalFlags
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
loader: () => import("./connect.impl.js").then((m) => m.removeConnection)
|
|
73
|
-
})
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
export {
|
|
77
|
-
connectCommands
|
|
78
|
-
};
|