@project-ajax/cli 0.0.10 → 0.0.12
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/commands/auth.impl.d.ts +2 -0
- package/dist/commands/auth.impl.d.ts.map +1 -1
- package/dist/commands/auth.impl.js +22 -18
- package/dist/commands/deploy.impl.d.ts +2 -1
- package/dist/commands/deploy.impl.d.ts.map +1 -1
- package/dist/commands/deploy.impl.js +22 -5
- package/dist/commands/exec.impl.d.ts.map +1 -1
- package/dist/commands/exec.impl.js +26 -0
- package/package.json +1 -1
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { GlobalFlags } from "../flags.js";
|
|
2
|
+
import { type HandlerContext } from "../handler.js";
|
|
3
|
+
export declare function runLogin(context: HandlerContext, token?: string): Promise<void>;
|
|
2
4
|
export declare const login: (this: import("../context.js").LocalContext, flags: GlobalFlags, token?: string | undefined) => Promise<void>;
|
|
3
5
|
export declare const show: (this: import("../context.js").LocalContext, flags: GlobalFlags) => Promise<void>;
|
|
4
6
|
export declare const logout: (this: import("../context.js").LocalContext, flags: GlobalFlags) => Promise<void>;
|
|
@@ -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;AAC/C,OAAO,EAAgB,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAyElE,wBAAsB,QAAQ,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,CAAC,EAAE,MAAM,iBA0FrE;AAED,eAAO,MAAM,KAAK,+GAMhB,CAAC;AAEH,eAAO,MAAM,IAAI,mFAEf,CAAC;AAEH,eAAO,MAAM,MAAM,mFAIjB,CAAC"}
|
|
@@ -30,9 +30,9 @@ async function pollLoginRedeem(baseUrl, sessionId, timeoutMs = 3e5, intervalMs =
|
|
|
30
30
|
}
|
|
31
31
|
return { status: "expired" };
|
|
32
32
|
}
|
|
33
|
-
|
|
34
|
-
const environment =
|
|
35
|
-
const baseUrl =
|
|
33
|
+
async function runLogin(context, token) {
|
|
34
|
+
const environment = context.config.environment;
|
|
35
|
+
const baseUrl = context.config.baseUrl;
|
|
36
36
|
if (token) {
|
|
37
37
|
const update2 = {
|
|
38
38
|
token,
|
|
@@ -41,11 +41,11 @@ const login = buildHandler(async function(_, token) {
|
|
|
41
41
|
if (environment !== "prod") {
|
|
42
42
|
update2.environment = environment;
|
|
43
43
|
}
|
|
44
|
-
await
|
|
45
|
-
|
|
44
|
+
await context.config.update(update2);
|
|
45
|
+
context.io.writeErr("Successfully logged in!");
|
|
46
46
|
return;
|
|
47
47
|
}
|
|
48
|
-
|
|
48
|
+
context.io.writeErr("Starting browser login...\n");
|
|
49
49
|
let initResponse;
|
|
50
50
|
try {
|
|
51
51
|
initResponse = await loginFetch(
|
|
@@ -54,18 +54,18 @@ const login = buildHandler(async function(_, token) {
|
|
|
54
54
|
{}
|
|
55
55
|
);
|
|
56
56
|
} catch (error) {
|
|
57
|
-
|
|
57
|
+
context.io.writeErr(
|
|
58
58
|
`Failed to start login: ${error instanceof Error ? error.message : String(error)}`
|
|
59
59
|
);
|
|
60
60
|
process.exit(1);
|
|
61
61
|
}
|
|
62
62
|
const { sessionId, verificationCode, browserUrl } = initResponse;
|
|
63
|
-
|
|
63
|
+
context.io.writeErr(
|
|
64
64
|
"Copy this verification code and paste it in your browser:\n"
|
|
65
65
|
);
|
|
66
|
-
|
|
66
|
+
context.io.writeErr(` ${verificationCode}
|
|
67
67
|
`);
|
|
68
|
-
await
|
|
68
|
+
await context.io.input({
|
|
69
69
|
message: `Press Enter to open the browser, or visit: ${browserUrl}`,
|
|
70
70
|
noTTY: `Please visit this URL to authenticate:
|
|
71
71
|
${browserUrl}`
|
|
@@ -73,21 +73,21 @@ const login = buildHandler(async function(_, token) {
|
|
|
73
73
|
try {
|
|
74
74
|
await openNotionUrl(environment, browserUrl);
|
|
75
75
|
} catch (_error) {
|
|
76
|
-
|
|
76
|
+
context.io.writeErr(
|
|
77
77
|
`Could not open browser automatically. Please visit:
|
|
78
78
|
${browserUrl}`
|
|
79
79
|
);
|
|
80
80
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
context.io.writeErr("");
|
|
82
|
+
context.io.writeErr("Waiting for browser confirmation...");
|
|
83
|
+
context.io.writeErr("(Press Ctrl+C to cancel)\n");
|
|
84
84
|
const redeemResponse = await pollLoginRedeem(baseUrl, sessionId);
|
|
85
85
|
if (redeemResponse.status === "expired") {
|
|
86
|
-
|
|
86
|
+
context.io.writeErr("Login session expired. Please try again.");
|
|
87
87
|
process.exit(1);
|
|
88
88
|
}
|
|
89
89
|
if (redeemResponse.status !== "confirmed") {
|
|
90
|
-
|
|
90
|
+
context.io.writeErr("Login failed. Please try again.");
|
|
91
91
|
process.exit(1);
|
|
92
92
|
}
|
|
93
93
|
const update = {
|
|
@@ -97,8 +97,11 @@ const login = buildHandler(async function(_, token) {
|
|
|
97
97
|
if (environment !== "prod") {
|
|
98
98
|
update.environment = environment;
|
|
99
99
|
}
|
|
100
|
-
await
|
|
101
|
-
|
|
100
|
+
await context.config.update(update);
|
|
101
|
+
context.io.writeErr("\u2713 Successfully logged in!");
|
|
102
|
+
}
|
|
103
|
+
const login = buildHandler(async function(_, token) {
|
|
104
|
+
await runLogin(this, token);
|
|
102
105
|
});
|
|
103
106
|
const show = buildHandler(function() {
|
|
104
107
|
this.io.writeOut(`${this.config.token ?? ""}`);
|
|
@@ -111,5 +114,6 @@ const logout = buildHandler(async function() {
|
|
|
111
114
|
export {
|
|
112
115
|
login,
|
|
113
116
|
logout,
|
|
117
|
+
runLogin,
|
|
114
118
|
show
|
|
115
119
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { GlobalFlags } from "../flags.js";
|
|
1
2
|
interface DeployFlags {
|
|
2
3
|
name?: string;
|
|
3
4
|
}
|
|
4
|
-
export declare const deploy: (this: import("../context.js").LocalContext, flags:
|
|
5
|
+
export declare const deploy: (this: import("../context.js").LocalContext, flags: GlobalFlags & DeployFlags) => Promise<void>;
|
|
5
6
|
export {};
|
|
6
7
|
//# sourceMappingURL=deploy.impl.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deploy.impl.d.ts","sourceRoot":"","sources":["../../src/commands/deploy.impl.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"deploy.impl.d.ts","sourceRoot":"","sources":["../../src/commands/deploy.impl.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAI/C,UAAU,WAAW;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED,eAAO,MAAM,MAAM,iGAqFjB,CAAC"}
|
|
@@ -1,14 +1,28 @@
|
|
|
1
|
+
import { ApiClient } from "../api/client.js";
|
|
1
2
|
import { Result } from "../api/result.js";
|
|
2
3
|
import { deployWorker } from "../deploy.js";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
import { buildHandler } from "../handler.js";
|
|
5
|
+
import { runLogin } from "./auth.impl.js";
|
|
6
|
+
const deploy = buildHandler(async function(flags) {
|
|
7
|
+
if (!this.config.token) {
|
|
8
|
+
this.io.writeErr("No authentication token found. Starting login flow...");
|
|
9
|
+
await runLogin(this);
|
|
10
|
+
}
|
|
11
|
+
const { token, cellId } = this.config.tokenInfo;
|
|
6
12
|
const workerId = this.config.workerId;
|
|
7
13
|
const environment = this.config.environment;
|
|
8
14
|
if (!environment) {
|
|
9
15
|
throw new Error("Unexpected error: Environment not set");
|
|
10
16
|
}
|
|
11
17
|
const workerPath = this.process.cwd();
|
|
18
|
+
const apiClient = new ApiClient({
|
|
19
|
+
token,
|
|
20
|
+
environment,
|
|
21
|
+
baseUrl: this.config.baseUrl,
|
|
22
|
+
cellId,
|
|
23
|
+
writer: this.io
|
|
24
|
+
});
|
|
25
|
+
const authedContext = { ...this, apiClient };
|
|
12
26
|
this.io.writeErr("Deploying worker...");
|
|
13
27
|
const name = flags.name;
|
|
14
28
|
if (workerId && name) {
|
|
@@ -16,7 +30,7 @@ const deploy = buildAuthedHandler(async function(flags) {
|
|
|
16
30
|
}
|
|
17
31
|
let result;
|
|
18
32
|
if (workerId) {
|
|
19
|
-
result = await deployWorker(
|
|
33
|
+
result = await deployWorker(authedContext, {
|
|
20
34
|
workerPath,
|
|
21
35
|
workerId,
|
|
22
36
|
token,
|
|
@@ -38,7 +52,7 @@ const deploy = buildAuthedHandler(async function(flags) {
|
|
|
38
52
|
}
|
|
39
53
|
validatedName = trimmedName;
|
|
40
54
|
}
|
|
41
|
-
result = await deployWorker(
|
|
55
|
+
result = await deployWorker(authedContext, {
|
|
42
56
|
name: validatedName,
|
|
43
57
|
workerPath,
|
|
44
58
|
token,
|
|
@@ -49,6 +63,9 @@ const deploy = buildAuthedHandler(async function(flags) {
|
|
|
49
63
|
const { workerId: workerId2 } = Result.unwrap(result);
|
|
50
64
|
await this.config.update({ workerId: workerId2 });
|
|
51
65
|
this.io.writeErr("\u2713 Successfully deployed worker");
|
|
66
|
+
const workerUrl = `${this.config.baseUrl}/__workers__/${workerId2}`;
|
|
67
|
+
this.io.writeErr("");
|
|
68
|
+
this.io.writeErr(`Worker Dashboard: ${workerUrl}`);
|
|
52
69
|
} else {
|
|
53
70
|
this.io.writeErr("\u2717 Failed to deploy worker");
|
|
54
71
|
this.io.writeErr(result.error.message);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exec.impl.d.ts","sourceRoot":"","sources":["../../src/commands/exec.impl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"exec.impl.d.ts","sourceRoot":"","sources":["../../src/commands/exec.impl.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AA4B/C,UAAU,SAAU,SAAQ,WAAW;IACtC,MAAM,EAAE,OAAO,CAAC;CAChB;AAED,eAAO,MAAM,IAAI,2HAmKf,CAAC"}
|
|
@@ -2,6 +2,15 @@ import { Result } from "../api/result.js";
|
|
|
2
2
|
import { buildAuthedHandler } from "../handler.js";
|
|
3
3
|
import { chunkEvery } from "../utils/array.js";
|
|
4
4
|
const usageHint = `Usage: workers exec <capabilityName> <capabilityFunction> [<argName1>=<value1> <argName2>=<value2>...]`;
|
|
5
|
+
function formatIdForUrl(id) {
|
|
6
|
+
return id.replace(/-/g, "");
|
|
7
|
+
}
|
|
8
|
+
function getCollectionId(result) {
|
|
9
|
+
if (typeof result === "object" && result !== null && "collectionId" in result && typeof result.collectionId === "string") {
|
|
10
|
+
return result.collectionId;
|
|
11
|
+
}
|
|
12
|
+
return void 0;
|
|
13
|
+
}
|
|
5
14
|
const exec = buildAuthedHandler(async function(flags, ...args) {
|
|
6
15
|
const { workerId } = this.config;
|
|
7
16
|
if (!workerId) {
|
|
@@ -39,6 +48,7 @@ const exec = buildAuthedHandler(async function(flags, ...args) {
|
|
|
39
48
|
if (Result.isSuccess(result)) {
|
|
40
49
|
const decoder = new TextDecoder();
|
|
41
50
|
let buffer = "";
|
|
51
|
+
let capabilityResult;
|
|
42
52
|
const allOutput = [];
|
|
43
53
|
const onBodyLine = async (jsonLine) => {
|
|
44
54
|
try {
|
|
@@ -58,6 +68,7 @@ const exec = buildAuthedHandler(async function(flags, ...args) {
|
|
|
58
68
|
});
|
|
59
69
|
break;
|
|
60
70
|
case "result":
|
|
71
|
+
capabilityResult = parsedLine.result;
|
|
61
72
|
this.io.writeOut(JSON.stringify(parsedLine.result, null, 2));
|
|
62
73
|
break;
|
|
63
74
|
case "error":
|
|
@@ -80,6 +91,7 @@ const exec = buildAuthedHandler(async function(flags, ...args) {
|
|
|
80
91
|
if (buffer) {
|
|
81
92
|
await onBodyLine(buffer);
|
|
82
93
|
}
|
|
94
|
+
showUrls(this, workerId, getCollectionId(capabilityResult));
|
|
83
95
|
return;
|
|
84
96
|
} else {
|
|
85
97
|
this.io.writeErr(`
|
|
@@ -107,6 +119,7 @@ ${usageHint}`);
|
|
|
107
119
|
if (Result.isSuccess(result)) {
|
|
108
120
|
const data = Result.unwrap(result);
|
|
109
121
|
this.io.writeOut(JSON.stringify(data.result, null, 2));
|
|
122
|
+
showUrls(this, workerId, getCollectionId(data.result));
|
|
110
123
|
} else {
|
|
111
124
|
this.io.writeErr(`
|
|
112
125
|
\u2717 Failed to execute capability`);
|
|
@@ -115,6 +128,19 @@ ${usageHint}`);
|
|
|
115
128
|
}
|
|
116
129
|
}
|
|
117
130
|
});
|
|
131
|
+
function showUrls(context, workerId, collectionId) {
|
|
132
|
+
const baseUrl = context.config.baseUrl;
|
|
133
|
+
context.io.writeErr("");
|
|
134
|
+
const workerUrl = `${baseUrl}/__workers__/${workerId}`;
|
|
135
|
+
context.io.writeErr(`Worker Dashboard: ${workerUrl}`);
|
|
136
|
+
context.io.writeErr(" View execution state, logs, and debugging info");
|
|
137
|
+
if (collectionId) {
|
|
138
|
+
context.io.writeErr("");
|
|
139
|
+
const databaseUrl = `${baseUrl}/${formatIdForUrl(collectionId)}`;
|
|
140
|
+
context.io.writeErr(`Synced Database: ${databaseUrl}`);
|
|
141
|
+
context.io.writeErr(" View the synced data in Notion");
|
|
142
|
+
}
|
|
143
|
+
}
|
|
118
144
|
function usageError() {
|
|
119
145
|
return new Error(`Invalid arguments provided. ${usageHint}`);
|
|
120
146
|
}
|