@project-ajax/cli 0.0.11 → 0.0.13
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.map +1 -1
- package/dist/commands/auth.impl.js +67 -13
- package/dist/commands/deploy.impl.d.ts.map +1 -1
- package/dist/commands/deploy.impl.js +3 -1
- package/dist/commands/exec.impl.d.ts.map +1 -1
- package/dist/commands/exec.impl.js +26 -0
- package/dist/commands/secrets.impl.d.ts +7 -0
- package/dist/commands/secrets.impl.d.ts.map +1 -1
- package/dist/commands/secrets.impl.js +9 -5
- package/dist/commands/secrets.impl.test.d.ts +2 -0
- package/dist/commands/secrets.impl.test.d.ts.map +1 -0
- package/dist/commands/secrets.js +2 -2
- package/package.json +1 -1
|
@@ -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;AAC/C,OAAO,EAAgB,KAAK,cAAc,EAAE,MAAM,eAAe,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;AAiIlE,wBAAsB,QAAQ,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,CAAC,EAAE,MAAM,iBA8GrE;AAED,eAAO,MAAM,KAAK,+GAMhB,CAAC;AAEH,eAAO,MAAM,IAAI,mFAEf,CAAC;AAEH,eAAO,MAAM,MAAM,mFAIjB,CAAC"}
|
|
@@ -30,6 +30,44 @@ async function pollLoginRedeem(baseUrl, sessionId, timeoutMs = 3e5, intervalMs =
|
|
|
30
30
|
}
|
|
31
31
|
return { status: "expired" };
|
|
32
32
|
}
|
|
33
|
+
async function waitForEnterOrRedeem(context, browserUrl, redeemOutcomePromise) {
|
|
34
|
+
if (!process.stdin.isTTY) {
|
|
35
|
+
context.io.writeErr(
|
|
36
|
+
`Please visit this URL to authenticate:
|
|
37
|
+
${browserUrl}`
|
|
38
|
+
);
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
context.io.writeErr(
|
|
42
|
+
`Press Enter to open the browser, or visit: ${browserUrl}`
|
|
43
|
+
);
|
|
44
|
+
return new Promise((resolve) => {
|
|
45
|
+
let settled = false;
|
|
46
|
+
const cleanup = () => {
|
|
47
|
+
process.stdin.off("data", onData);
|
|
48
|
+
process.stdin.pause();
|
|
49
|
+
};
|
|
50
|
+
const settle = (value) => {
|
|
51
|
+
if (settled) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
settled = true;
|
|
55
|
+
cleanup();
|
|
56
|
+
resolve(value);
|
|
57
|
+
};
|
|
58
|
+
const onData = (data) => {
|
|
59
|
+
const hasNewline = typeof data === "string" ? data.includes("\n") || data.includes("\r") : data.includes(10) || data.includes(13);
|
|
60
|
+
if (hasNewline) {
|
|
61
|
+
settle("enter");
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
process.stdin.resume();
|
|
65
|
+
process.stdin.on("data", onData);
|
|
66
|
+
void redeemOutcomePromise.then(() => {
|
|
67
|
+
settle("redeem");
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
33
71
|
async function runLogin(context, token) {
|
|
34
72
|
const environment = context.config.environment;
|
|
35
73
|
const baseUrl = context.config.baseUrl;
|
|
@@ -65,23 +103,39 @@ async function runLogin(context, token) {
|
|
|
65
103
|
);
|
|
66
104
|
context.io.writeErr(` ${verificationCode}
|
|
67
105
|
`);
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
106
|
+
const redeemPromise = pollLoginRedeem(baseUrl, sessionId);
|
|
107
|
+
const redeemOutcomePromise = redeemPromise.then(
|
|
108
|
+
(value) => ({ ok: true, value }),
|
|
109
|
+
(error) => ({ ok: false, error })
|
|
110
|
+
);
|
|
111
|
+
const nextStep = await waitForEnterOrRedeem(
|
|
112
|
+
context,
|
|
113
|
+
browserUrl,
|
|
114
|
+
redeemOutcomePromise
|
|
115
|
+
);
|
|
116
|
+
if (nextStep === "enter") {
|
|
117
|
+
try {
|
|
118
|
+
await openNotionUrl(environment, browserUrl);
|
|
119
|
+
} catch (_error) {
|
|
120
|
+
context.io.writeErr(
|
|
121
|
+
`Could not open browser automatically. Please visit:
|
|
71
122
|
${browserUrl}`
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (nextStep !== "redeem") {
|
|
127
|
+
context.io.writeErr("");
|
|
128
|
+
context.io.writeErr("Waiting for browser confirmation...");
|
|
129
|
+
context.io.writeErr("(Press Ctrl+C to cancel)\n");
|
|
130
|
+
}
|
|
131
|
+
const redeemOutcome = await redeemOutcomePromise;
|
|
132
|
+
if (!redeemOutcome.ok) {
|
|
76
133
|
context.io.writeErr(
|
|
77
|
-
`
|
|
78
|
-
${browserUrl}`
|
|
134
|
+
`Login failed: ${redeemOutcome.error instanceof Error ? redeemOutcome.error.message : String(redeemOutcome.error)}`
|
|
79
135
|
);
|
|
136
|
+
process.exit(1);
|
|
80
137
|
}
|
|
81
|
-
|
|
82
|
-
context.io.writeErr("Waiting for browser confirmation...");
|
|
83
|
-
context.io.writeErr("(Press Ctrl+C to cancel)\n");
|
|
84
|
-
const redeemResponse = await pollLoginRedeem(baseUrl, sessionId);
|
|
138
|
+
const redeemResponse = redeemOutcome.value;
|
|
85
139
|
if (redeemResponse.status === "expired") {
|
|
86
140
|
context.io.writeErr("Login session expired. Please try again.");
|
|
87
141
|
process.exit(1);
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,iGAoFjB,CAAC"}
|
|
@@ -5,7 +5,6 @@ import { buildHandler } from "../handler.js";
|
|
|
5
5
|
import { runLogin } from "./auth.impl.js";
|
|
6
6
|
const deploy = buildHandler(async function(flags) {
|
|
7
7
|
if (!this.config.token) {
|
|
8
|
-
this.io.writeErr("No authentication token found. Starting login flow...");
|
|
9
8
|
await runLogin(this);
|
|
10
9
|
}
|
|
11
10
|
const { token, cellId } = this.config.tokenInfo;
|
|
@@ -63,6 +62,9 @@ const deploy = buildHandler(async function(flags) {
|
|
|
63
62
|
const { workerId: workerId2 } = Result.unwrap(result);
|
|
64
63
|
await this.config.update({ workerId: workerId2 });
|
|
65
64
|
this.io.writeErr("\u2713 Successfully deployed worker");
|
|
65
|
+
const workerUrl = `${this.config.baseUrl}/__workers__/${workerId2}`;
|
|
66
|
+
this.io.writeErr("");
|
|
67
|
+
this.io.writeErr(`Worker Dashboard: ${workerUrl}`);
|
|
66
68
|
} else {
|
|
67
69
|
this.io.writeErr("\u2717 Failed to deploy worker");
|
|
68
70
|
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
|
}
|
|
@@ -2,4 +2,11 @@ import type { FormatFlags, GlobalFlags } from "../flags.js";
|
|
|
2
2
|
export declare const setSecrets: (this: import("../context.js").LocalContext, flags: GlobalFlags, ...args: string[]) => Promise<void>;
|
|
3
3
|
export declare const listSecrets: (this: import("../context.js").LocalContext, flags: GlobalFlags & FormatFlags) => Promise<void>;
|
|
4
4
|
export declare const removeSecret: (this: import("../context.js").LocalContext, flags: GlobalFlags, key: string) => Promise<void>;
|
|
5
|
+
/**
|
|
6
|
+
* Parse secret arguments from CLI, supporting "key=value" format.
|
|
7
|
+
*/
|
|
8
|
+
export declare function parseSecretArgs(args: readonly string[]): Array<{
|
|
9
|
+
key: string;
|
|
10
|
+
value: string;
|
|
11
|
+
}>;
|
|
5
12
|
//# sourceMappingURL=secrets.impl.d.ts.map
|
|
@@ -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;
|
|
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;AAI5D,eAAO,MAAM,UAAU,sGA0BrB,CAAC;AAEH,eAAO,MAAM,WAAW,iGAkCtB,CAAC;AAEH,eAAO,MAAM,YAAY,gGAwBvB,CAAC;AAQH;;GAEG;AACH,wBAAgB,eAAe,CAC9B,IAAI,EAAE,SAAS,MAAM,EAAE,GACrB,KAAK,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAoBvC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Result } from "../api/result.js";
|
|
2
2
|
import { buildAuthedHandler } from "../handler.js";
|
|
3
|
-
import { chunkEvery } from "../utils/array.js";
|
|
4
3
|
import { pluralize } from "../utils/string.js";
|
|
5
4
|
const setSecrets = buildAuthedHandler(async function(_flags, ...args) {
|
|
6
5
|
const secrets = parseSecretArgs(args);
|
|
@@ -70,24 +69,29 @@ const removeSecret = buildAuthedHandler(async function(_flags, key) {
|
|
|
70
69
|
});
|
|
71
70
|
function usageError() {
|
|
72
71
|
return new Error(
|
|
73
|
-
"Invalid secrets provided. Usage: workers secrets set <key
|
|
72
|
+
"Invalid secrets provided. Usage: workers secrets set <key>=<value> [<key2>=<value2>...]"
|
|
74
73
|
);
|
|
75
74
|
}
|
|
76
75
|
function parseSecretArgs(args) {
|
|
77
76
|
if (args.length === 0) {
|
|
78
77
|
throw usageError();
|
|
79
78
|
}
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
return args.map((arg) => {
|
|
80
|
+
const separatorIndex = arg.indexOf("=");
|
|
81
|
+
if (separatorIndex <= 0 || separatorIndex === arg.length - 1) {
|
|
82
|
+
throw usageError();
|
|
83
|
+
}
|
|
84
|
+
const key = arg.slice(0, separatorIndex);
|
|
85
|
+
const value = arg.slice(separatorIndex + 1);
|
|
82
86
|
if (!key || !value) {
|
|
83
87
|
throw usageError();
|
|
84
88
|
}
|
|
85
89
|
return { key, value };
|
|
86
90
|
});
|
|
87
|
-
return secrets;
|
|
88
91
|
}
|
|
89
92
|
export {
|
|
90
93
|
listSecrets,
|
|
94
|
+
parseSecretArgs,
|
|
91
95
|
removeSecret,
|
|
92
96
|
setSecrets
|
|
93
97
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets.impl.test.d.ts","sourceRoot":"","sources":["../../src/commands/secrets.impl.test.ts"],"names":[],"mappings":""}
|
package/dist/commands/secrets.js
CHANGED
|
@@ -7,13 +7,13 @@ const secretsCommands = buildRouteMap({
|
|
|
7
7
|
routes: {
|
|
8
8
|
set: buildCommand({
|
|
9
9
|
docs: {
|
|
10
|
-
brief: "Set one or more secrets for a worker. Supports 'key
|
|
10
|
+
brief: "Set one or more secrets for a worker. Supports 'key=value' format."
|
|
11
11
|
},
|
|
12
12
|
parameters: {
|
|
13
13
|
positional: {
|
|
14
14
|
kind: "array",
|
|
15
15
|
parameter: {
|
|
16
|
-
brief: "Secret key-value pairs (key
|
|
16
|
+
brief: "Secret key-value pairs (key=value)",
|
|
17
17
|
parse: String,
|
|
18
18
|
placeholder: "secrets..."
|
|
19
19
|
}
|