@westbayberry/dg 1.0.7 → 1.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/index.mjs +60 -21
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -3318,7 +3318,7 @@ var require_react_development = __commonJS({
|
|
|
3318
3318
|
var dispatcher = resolveDispatcher();
|
|
3319
3319
|
return dispatcher.useLayoutEffect(create2, deps);
|
|
3320
3320
|
}
|
|
3321
|
-
function
|
|
3321
|
+
function useCallback5(callback, deps) {
|
|
3322
3322
|
var dispatcher = resolveDispatcher();
|
|
3323
3323
|
return dispatcher.useCallback(callback, deps);
|
|
3324
3324
|
}
|
|
@@ -4085,7 +4085,7 @@ var require_react_development = __commonJS({
|
|
|
4085
4085
|
exports.memo = memo;
|
|
4086
4086
|
exports.startTransition = startTransition;
|
|
4087
4087
|
exports.unstable_act = act;
|
|
4088
|
-
exports.useCallback =
|
|
4088
|
+
exports.useCallback = useCallback5;
|
|
4089
4089
|
exports.useContext = useContext7;
|
|
4090
4090
|
exports.useDebugValue = useDebugValue;
|
|
4091
4091
|
exports.useDeferredValue = useDeferredValue;
|
|
@@ -36083,12 +36083,15 @@ var init_auth = __esm({
|
|
|
36083
36083
|
});
|
|
36084
36084
|
|
|
36085
36085
|
// src/ui/hooks/useLogin.ts
|
|
36086
|
-
function reducer(
|
|
36086
|
+
function reducer(state, action) {
|
|
36087
36087
|
switch (action.type) {
|
|
36088
36088
|
case "ALREADY_LOGGED_IN":
|
|
36089
36089
|
return { phase: "already_logged_in", apiKey: action.apiKey };
|
|
36090
|
-
case "
|
|
36091
|
-
return { phase: "
|
|
36090
|
+
case "SESSION_READY":
|
|
36091
|
+
return { phase: "ready", verifyUrl: action.verifyUrl };
|
|
36092
|
+
case "BROWSER_OPENED":
|
|
36093
|
+
if (state.phase !== "ready") return state;
|
|
36094
|
+
return { phase: "waiting", verifyUrl: state.verifyUrl };
|
|
36092
36095
|
case "AUTH_COMPLETE":
|
|
36093
36096
|
return { phase: "success", email: action.email };
|
|
36094
36097
|
case "AUTH_EXPIRED":
|
|
@@ -36100,10 +36103,11 @@ function reducer(_state, action) {
|
|
|
36100
36103
|
function useLogin() {
|
|
36101
36104
|
const [state, dispatch] = (0, import_react22.useReducer)(reducer, { phase: "creating" });
|
|
36102
36105
|
const started = (0, import_react22.useRef)(false);
|
|
36106
|
+
const sessionRef = (0, import_react22.useRef)(null);
|
|
36107
|
+
const cancelledRef = (0, import_react22.useRef)(false);
|
|
36103
36108
|
(0, import_react22.useEffect)(() => {
|
|
36104
36109
|
if (started.current) return;
|
|
36105
36110
|
started.current = true;
|
|
36106
|
-
let cancelled = false;
|
|
36107
36111
|
(async () => {
|
|
36108
36112
|
try {
|
|
36109
36113
|
const existing = getStoredApiKey();
|
|
@@ -36121,15 +36125,30 @@ function useLogin() {
|
|
|
36121
36125
|
});
|
|
36122
36126
|
return;
|
|
36123
36127
|
}
|
|
36128
|
+
sessionRef.current = session;
|
|
36129
|
+
dispatch({ type: "SESSION_READY", verifyUrl: session.verifyUrl });
|
|
36130
|
+
} catch (err) {
|
|
36124
36131
|
dispatch({
|
|
36125
|
-
type: "
|
|
36126
|
-
|
|
36132
|
+
type: "ERROR",
|
|
36133
|
+
message: err instanceof Error ? err.message : String(err)
|
|
36127
36134
|
});
|
|
36128
|
-
|
|
36135
|
+
}
|
|
36136
|
+
})();
|
|
36137
|
+
return () => {
|
|
36138
|
+
cancelledRef.current = true;
|
|
36139
|
+
};
|
|
36140
|
+
}, []);
|
|
36141
|
+
const openAndPoll = (0, import_react22.useCallback)(() => {
|
|
36142
|
+
const session = sessionRef.current;
|
|
36143
|
+
if (!session) return;
|
|
36144
|
+
dispatch({ type: "BROWSER_OPENED" });
|
|
36145
|
+
openBrowser(session.verifyUrl);
|
|
36146
|
+
(async () => {
|
|
36147
|
+
try {
|
|
36129
36148
|
for (let i = 0; i < MAX_POLL_ATTEMPTS; i++) {
|
|
36130
|
-
if (
|
|
36149
|
+
if (cancelledRef.current) return;
|
|
36131
36150
|
await new Promise((r) => setTimeout(r, POLL_INTERVAL_MS));
|
|
36132
|
-
if (
|
|
36151
|
+
if (cancelledRef.current) return;
|
|
36133
36152
|
try {
|
|
36134
36153
|
const result = await pollAuthSession(session.sessionId);
|
|
36135
36154
|
if (result.status === "complete" && result.apiKey) {
|
|
@@ -36152,11 +36171,8 @@ function useLogin() {
|
|
|
36152
36171
|
});
|
|
36153
36172
|
}
|
|
36154
36173
|
})();
|
|
36155
|
-
return () => {
|
|
36156
|
-
cancelled = true;
|
|
36157
|
-
};
|
|
36158
36174
|
}, []);
|
|
36159
|
-
return state;
|
|
36175
|
+
return { state, openAndPoll };
|
|
36160
36176
|
}
|
|
36161
36177
|
var import_react22, POLL_INTERVAL_MS, MAX_POLL_ATTEMPTS;
|
|
36162
36178
|
var init_useLogin = __esm({
|
|
@@ -38804,7 +38820,7 @@ var init_LoginApp = __esm({
|
|
|
38804
38820
|
await init_Spinner();
|
|
38805
38821
|
import_jsx_runtime2 = __toESM(require_jsx_runtime());
|
|
38806
38822
|
LoginApp = () => {
|
|
38807
|
-
const state = useLogin();
|
|
38823
|
+
const { state, openAndPoll } = useLogin();
|
|
38808
38824
|
const { exit } = use_app_default();
|
|
38809
38825
|
(0, import_react24.useEffect)(() => {
|
|
38810
38826
|
if (state.phase === "success") {
|
|
@@ -38823,6 +38839,11 @@ var init_LoginApp = __esm({
|
|
|
38823
38839
|
return () => clearTimeout(timer);
|
|
38824
38840
|
}
|
|
38825
38841
|
}, [state, exit]);
|
|
38842
|
+
use_input_default((_input, key) => {
|
|
38843
|
+
if (state.phase === "ready" && key.return) {
|
|
38844
|
+
openAndPoll();
|
|
38845
|
+
}
|
|
38846
|
+
});
|
|
38826
38847
|
switch (state.phase) {
|
|
38827
38848
|
case "creating":
|
|
38828
38849
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Spinner2, { label: "Creating login session..." });
|
|
@@ -38835,12 +38856,19 @@ var init_LoginApp = __esm({
|
|
|
38835
38856
|
" first to re-authenticate."
|
|
38836
38857
|
] })
|
|
38837
38858
|
] });
|
|
38859
|
+
case "ready":
|
|
38860
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Box_default, { flexDirection: "column", paddingLeft: 1, children: [
|
|
38861
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { children: " " }),
|
|
38862
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { children: "Authenticate your account at:" }),
|
|
38863
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { color: "cyan", children: state.verifyUrl }),
|
|
38864
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { children: " " }),
|
|
38865
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { dimColor: true, children: "Press ENTER to open in the browser..." })
|
|
38866
|
+
] });
|
|
38838
38867
|
case "waiting":
|
|
38839
38868
|
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Box_default, { flexDirection: "column", paddingLeft: 1, children: [
|
|
38840
38869
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { children: " " }),
|
|
38841
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { children: "
|
|
38842
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, {
|
|
38843
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { dimColor: true, color: "cyan", children: state.verifyUrl }),
|
|
38870
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { children: "Authenticate your account at:" }),
|
|
38871
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { color: "cyan", children: state.verifyUrl }),
|
|
38844
38872
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Text, { children: " " }),
|
|
38845
38873
|
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Spinner2, { label: "Waiting for authorization..." })
|
|
38846
38874
|
] });
|
|
@@ -39932,11 +39960,22 @@ async function runStaticLogin() {
|
|
|
39932
39960
|
process.exit(1);
|
|
39933
39961
|
}
|
|
39934
39962
|
process.stderr.write(`
|
|
39935
|
-
|
|
39963
|
+
Authenticate your account at:
|
|
39936
39964
|
`);
|
|
39937
|
-
process.stderr.write(`
|
|
39965
|
+
process.stderr.write(` ${import_chalk4.default.cyan(session.verifyUrl)}
|
|
39938
39966
|
|
|
39939
39967
|
`);
|
|
39968
|
+
process.stderr.write(import_chalk4.default.dim(" Press ENTER to open in the browser...\n"));
|
|
39969
|
+
await new Promise((resolve2) => {
|
|
39970
|
+
const onData = () => {
|
|
39971
|
+
process.stdin.removeListener("data", onData);
|
|
39972
|
+
if (process.stdin.unref) process.stdin.unref();
|
|
39973
|
+
resolve2();
|
|
39974
|
+
};
|
|
39975
|
+
process.stdin.setEncoding("utf-8");
|
|
39976
|
+
process.stdin.resume();
|
|
39977
|
+
process.stdin.on("data", onData);
|
|
39978
|
+
});
|
|
39940
39979
|
try {
|
|
39941
39980
|
openBrowser2(session.verifyUrl);
|
|
39942
39981
|
} catch {
|