@project-ajax/cli 0.0.14 → 0.0.15
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 +16 -71
- package/dist/config.js +1 -1
- 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;AAwElE,wBAAsB,QAAQ,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,CAAC,EAAE,MAAM,iBAyFrE;AAED,eAAO,MAAM,KAAK,+GAMhB,CAAC;AAEH,eAAO,MAAM,IAAI,mFAEf,CAAC;AAEH,eAAO,MAAM,MAAM,mFAIjB,CAAC"}
|
|
@@ -30,44 +30,6 @@ 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
|
-
}
|
|
71
33
|
async function runLogin(context, token) {
|
|
72
34
|
const environment = context.config.environment;
|
|
73
35
|
const baseUrl = context.config.baseUrl;
|
|
@@ -97,45 +59,28 @@ async function runLogin(context, token) {
|
|
|
97
59
|
);
|
|
98
60
|
process.exit(1);
|
|
99
61
|
}
|
|
100
|
-
const { sessionId,
|
|
101
|
-
context.io.writeErr(
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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:
|
|
62
|
+
const { sessionId, browserUrl } = initResponse;
|
|
63
|
+
context.io.writeErr(`Opening ${browserUrl} ...`);
|
|
64
|
+
try {
|
|
65
|
+
await openNotionUrl(environment, browserUrl);
|
|
66
|
+
} catch (_error) {
|
|
67
|
+
context.io.writeErr(
|
|
68
|
+
`Could not open browser automatically. Please visit:
|
|
122
69
|
${browserUrl}`
|
|
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");
|
|
70
|
+
);
|
|
130
71
|
}
|
|
131
|
-
|
|
132
|
-
|
|
72
|
+
context.io.writeErr("");
|
|
73
|
+
context.io.writeErr("Waiting for browser confirmation...");
|
|
74
|
+
context.io.writeErr("(Press Ctrl+C to cancel)\n");
|
|
75
|
+
let redeemResponse;
|
|
76
|
+
try {
|
|
77
|
+
redeemResponse = await pollLoginRedeem(baseUrl, sessionId);
|
|
78
|
+
} catch (error) {
|
|
133
79
|
context.io.writeErr(
|
|
134
|
-
`Login failed: ${
|
|
80
|
+
`Login failed: ${error instanceof Error ? error.message : String(error)}`
|
|
135
81
|
);
|
|
136
82
|
process.exit(1);
|
|
137
83
|
}
|
|
138
|
-
const redeemResponse = redeemOutcome.value;
|
|
139
84
|
if (redeemResponse.status === "expired") {
|
|
140
85
|
context.io.writeErr("Login session expired. Please try again.");
|
|
141
86
|
process.exit(1);
|
package/dist/config.js
CHANGED
|
@@ -178,7 +178,7 @@ function baseUrlForEnvironment(environment) {
|
|
|
178
178
|
case "local":
|
|
179
179
|
return "http://localhost:3000";
|
|
180
180
|
case "staging":
|
|
181
|
-
return "https://
|
|
181
|
+
return "https://stg.notion.so";
|
|
182
182
|
case "dev":
|
|
183
183
|
return "https://dev.notion.so";
|
|
184
184
|
case "prod":
|