@project-ajax/cli 0.0.12 → 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 +0 -1
- 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;
|
|
@@ -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
|
}
|