@bigio/better-auth-electron 1.0.3 → 1.0.5
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/README.md +263 -80
- package/dist/main.js +19 -36
- package/dist/main.js.map +1 -1
- package/dist/metafile-esm.json +1 -1
- package/dist/options.d.ts +29 -10
- package/dist/options.js +23 -11
- package/dist/options.js.map +1 -1
- package/dist/renderer.d.ts +27 -2
- package/dist/renderer.js +292 -150
- package/dist/renderer.js.map +1 -1
- package/dist/server.d.ts +5 -0
- package/dist/server.js +42 -21
- package/dist/server.js.map +1 -1
- package/dist/web.d.ts +8 -11
- package/dist/web.js +524 -192
- package/dist/web.js.map +1 -1
- package/package.json +1 -1
package/dist/web.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useRef, useCallback, useSyncExternalStore } from 'react';
|
|
2
|
-
import z from 'zod';
|
|
2
|
+
import z, { boolean } from 'zod';
|
|
3
3
|
|
|
4
4
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
5
5
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
@@ -87,76 +87,6 @@ var atom = /* @__NO_SIDE_EFFECTS__ */ (initialValue) => {
|
|
|
87
87
|
return $atom;
|
|
88
88
|
};
|
|
89
89
|
|
|
90
|
-
// node_modules/.pnpm/nanostores@1.1.0/node_modules/nanostores/lifecycle/index.js
|
|
91
|
-
var MOUNT = 5;
|
|
92
|
-
var UNMOUNT = 6;
|
|
93
|
-
var REVERT_MUTATION = 10;
|
|
94
|
-
var on = (object, listener, eventKey, mutateStore) => {
|
|
95
|
-
object.events = object.events || {};
|
|
96
|
-
if (!object.events[eventKey + REVERT_MUTATION]) {
|
|
97
|
-
object.events[eventKey + REVERT_MUTATION] = mutateStore((eventProps) => {
|
|
98
|
-
object.events[eventKey].reduceRight((event, l) => (l(event), event), {
|
|
99
|
-
shared: {},
|
|
100
|
-
...eventProps
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
object.events[eventKey] = object.events[eventKey] || [];
|
|
105
|
-
object.events[eventKey].push(listener);
|
|
106
|
-
return () => {
|
|
107
|
-
let currentListeners = object.events[eventKey];
|
|
108
|
-
let index = currentListeners.indexOf(listener);
|
|
109
|
-
currentListeners.splice(index, 1);
|
|
110
|
-
if (!currentListeners.length) {
|
|
111
|
-
delete object.events[eventKey];
|
|
112
|
-
object.events[eventKey + REVERT_MUTATION]();
|
|
113
|
-
delete object.events[eventKey + REVERT_MUTATION];
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
};
|
|
117
|
-
var STORE_UNMOUNT_DELAY = 1e3;
|
|
118
|
-
var onMount = ($store, initialize) => {
|
|
119
|
-
let listener = (payload) => {
|
|
120
|
-
let destroy = initialize(payload);
|
|
121
|
-
if (destroy) $store.events[UNMOUNT].push(destroy);
|
|
122
|
-
};
|
|
123
|
-
return on($store, listener, MOUNT, (runListeners) => {
|
|
124
|
-
let originListen = $store.listen;
|
|
125
|
-
$store.listen = (...args) => {
|
|
126
|
-
if (!$store.lc && !$store.active) {
|
|
127
|
-
$store.active = true;
|
|
128
|
-
runListeners();
|
|
129
|
-
}
|
|
130
|
-
return originListen(...args);
|
|
131
|
-
};
|
|
132
|
-
let originOff = $store.off;
|
|
133
|
-
$store.events[UNMOUNT] = [];
|
|
134
|
-
$store.off = () => {
|
|
135
|
-
originOff();
|
|
136
|
-
setTimeout(() => {
|
|
137
|
-
if ($store.active && !$store.lc) {
|
|
138
|
-
$store.active = false;
|
|
139
|
-
for (let destroy of $store.events[UNMOUNT]) destroy();
|
|
140
|
-
$store.events[UNMOUNT] = [];
|
|
141
|
-
}
|
|
142
|
-
}, STORE_UNMOUNT_DELAY);
|
|
143
|
-
};
|
|
144
|
-
if (process.env.NODE_ENV !== "production") {
|
|
145
|
-
let originClean = $store[clean];
|
|
146
|
-
$store[clean] = () => {
|
|
147
|
-
for (let destroy of $store.events[UNMOUNT]) destroy();
|
|
148
|
-
$store.events[UNMOUNT] = [];
|
|
149
|
-
$store.active = false;
|
|
150
|
-
originClean();
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
return () => {
|
|
154
|
-
$store.listen = originListen;
|
|
155
|
-
$store.off = originOff;
|
|
156
|
-
};
|
|
157
|
-
});
|
|
158
|
-
};
|
|
159
|
-
|
|
160
90
|
// node_modules/.pnpm/nanostores@1.1.0/node_modules/nanostores/listen-keys/index.js
|
|
161
91
|
function listenKeys($store, keys, listener) {
|
|
162
92
|
let keysSet = new Set(keys).add(void 0);
|
|
@@ -181,14 +111,19 @@ function useStore(store, { keys, deps = [store, keys] } = {}) {
|
|
|
181
111
|
let get = () => snapshotRef.current;
|
|
182
112
|
return useSyncExternalStore(subscribe, get, get);
|
|
183
113
|
}
|
|
184
|
-
var
|
|
114
|
+
var defaultWebOptions = {
|
|
185
115
|
ELECTRON_SCHEME: "bigio",
|
|
186
116
|
SCHEME_NAME_IN_URL: "scheme",
|
|
187
117
|
PROVIDERS: ["github", "google"],
|
|
188
118
|
PROVIDER_NAME_IN_URL: "provider",
|
|
189
|
-
CHALLENGE_NAME_IN_URL: "
|
|
119
|
+
CHALLENGE_NAME_IN_URL: "electron-challenge",
|
|
190
120
|
WEB_OAUTH_SIGNIN_CALLBACK_PATHNAME: "electron-handoff",
|
|
191
|
-
BACKEND_FAST_TICKET_URL: "electron/fastTicket"
|
|
121
|
+
BACKEND_FAST_TICKET_URL: "electron/fastTicket",
|
|
122
|
+
SCOPES_NAME_IN_URL: "electron-scopes",
|
|
123
|
+
LOGINHINT_NAME_IN_URL: "electron-loginhint",
|
|
124
|
+
ADDITIONAL_DATA_NAME_IN_URL: "electron-addata",
|
|
125
|
+
REQUEST_SIGN_UP_NAME_IN_URL: "electron-reqsignup",
|
|
126
|
+
AUTH_STATUS_NAME_IN_URL: "electron-status"
|
|
192
127
|
};
|
|
193
128
|
|
|
194
129
|
// node_modules/.pnpm/@oslojs+encoding@1.1.0/node_modules/@oslojs/encoding/dist/base32.js
|
|
@@ -204,6 +139,52 @@ var DecodingPadding;
|
|
|
204
139
|
})(DecodingPadding || (DecodingPadding = {}));
|
|
205
140
|
|
|
206
141
|
// node_modules/.pnpm/@oslojs+encoding@1.1.0/node_modules/@oslojs/encoding/dist/base64.js
|
|
142
|
+
function decodeBase64urlIgnorePadding(encoded) {
|
|
143
|
+
return decodeBase64_internal(encoded, base64urlDecodeMap, DecodingPadding2.Ignore);
|
|
144
|
+
}
|
|
145
|
+
function decodeBase64_internal(encoded, decodeMap, padding) {
|
|
146
|
+
const result = new Uint8Array(Math.ceil(encoded.length / 4) * 3);
|
|
147
|
+
let totalBytes = 0;
|
|
148
|
+
for (let i = 0; i < encoded.length; i += 4) {
|
|
149
|
+
let chunk = 0;
|
|
150
|
+
let bitsRead = 0;
|
|
151
|
+
for (let j = 0; j < 4; j++) {
|
|
152
|
+
if (padding === DecodingPadding2.Required && encoded[i + j] === "=") {
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
if (padding === DecodingPadding2.Ignore && (i + j >= encoded.length || encoded[i + j] === "=")) {
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (j > 0 && encoded[i + j - 1] === "=") {
|
|
159
|
+
throw new Error("Invalid padding");
|
|
160
|
+
}
|
|
161
|
+
if (!(encoded[i + j] in decodeMap)) {
|
|
162
|
+
throw new Error("Invalid character");
|
|
163
|
+
}
|
|
164
|
+
chunk |= decodeMap[encoded[i + j]] << (3 - j) * 6;
|
|
165
|
+
bitsRead += 6;
|
|
166
|
+
}
|
|
167
|
+
if (bitsRead < 24) {
|
|
168
|
+
let unused;
|
|
169
|
+
if (bitsRead === 12) {
|
|
170
|
+
unused = chunk & 65535;
|
|
171
|
+
} else if (bitsRead === 18) {
|
|
172
|
+
unused = chunk & 255;
|
|
173
|
+
} else {
|
|
174
|
+
throw new Error("Invalid padding");
|
|
175
|
+
}
|
|
176
|
+
if (unused !== 0) {
|
|
177
|
+
throw new Error("Invalid padding");
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
const byteLength = Math.floor(bitsRead / 8);
|
|
181
|
+
for (let i2 = 0; i2 < byteLength; i2++) {
|
|
182
|
+
result[totalBytes] = chunk >> 16 - i2 * 8 & 255;
|
|
183
|
+
totalBytes++;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return result.slice(0, totalBytes);
|
|
187
|
+
}
|
|
207
188
|
var EncodingPadding2;
|
|
208
189
|
(function(EncodingPadding3) {
|
|
209
190
|
EncodingPadding3[EncodingPadding3["Include"] = 0] = "Include";
|
|
@@ -214,6 +195,72 @@ var DecodingPadding2;
|
|
|
214
195
|
DecodingPadding3[DecodingPadding3["Required"] = 0] = "Required";
|
|
215
196
|
DecodingPadding3[DecodingPadding3["Ignore"] = 1] = "Ignore";
|
|
216
197
|
})(DecodingPadding2 || (DecodingPadding2 = {}));
|
|
198
|
+
var base64urlDecodeMap = {
|
|
199
|
+
"0": 52,
|
|
200
|
+
"1": 53,
|
|
201
|
+
"2": 54,
|
|
202
|
+
"3": 55,
|
|
203
|
+
"4": 56,
|
|
204
|
+
"5": 57,
|
|
205
|
+
"6": 58,
|
|
206
|
+
"7": 59,
|
|
207
|
+
"8": 60,
|
|
208
|
+
"9": 61,
|
|
209
|
+
A: 0,
|
|
210
|
+
B: 1,
|
|
211
|
+
C: 2,
|
|
212
|
+
D: 3,
|
|
213
|
+
E: 4,
|
|
214
|
+
F: 5,
|
|
215
|
+
G: 6,
|
|
216
|
+
H: 7,
|
|
217
|
+
I: 8,
|
|
218
|
+
J: 9,
|
|
219
|
+
K: 10,
|
|
220
|
+
L: 11,
|
|
221
|
+
M: 12,
|
|
222
|
+
N: 13,
|
|
223
|
+
O: 14,
|
|
224
|
+
P: 15,
|
|
225
|
+
Q: 16,
|
|
226
|
+
R: 17,
|
|
227
|
+
S: 18,
|
|
228
|
+
T: 19,
|
|
229
|
+
U: 20,
|
|
230
|
+
V: 21,
|
|
231
|
+
W: 22,
|
|
232
|
+
X: 23,
|
|
233
|
+
Y: 24,
|
|
234
|
+
Z: 25,
|
|
235
|
+
a: 26,
|
|
236
|
+
b: 27,
|
|
237
|
+
c: 28,
|
|
238
|
+
d: 29,
|
|
239
|
+
e: 30,
|
|
240
|
+
f: 31,
|
|
241
|
+
g: 32,
|
|
242
|
+
h: 33,
|
|
243
|
+
i: 34,
|
|
244
|
+
j: 35,
|
|
245
|
+
k: 36,
|
|
246
|
+
l: 37,
|
|
247
|
+
m: 38,
|
|
248
|
+
n: 39,
|
|
249
|
+
o: 40,
|
|
250
|
+
p: 41,
|
|
251
|
+
q: 42,
|
|
252
|
+
r: 43,
|
|
253
|
+
s: 44,
|
|
254
|
+
t: 45,
|
|
255
|
+
u: 46,
|
|
256
|
+
v: 47,
|
|
257
|
+
w: 48,
|
|
258
|
+
x: 49,
|
|
259
|
+
y: 50,
|
|
260
|
+
z: 51,
|
|
261
|
+
"-": 62,
|
|
262
|
+
_: 63
|
|
263
|
+
};
|
|
217
264
|
|
|
218
265
|
// src/utils/electron-plugin-env.ts
|
|
219
266
|
var getGlobal = () => {
|
|
@@ -242,6 +289,7 @@ var getRawNodeEnv = () => {
|
|
|
242
289
|
return "development";
|
|
243
290
|
};
|
|
244
291
|
var RAW_ENV = getRawNodeEnv();
|
|
292
|
+
var IS_DEV = RAW_ENV === "development";
|
|
245
293
|
var IS_ELECTRON_PACKAGED = (() => {
|
|
246
294
|
if (typeof process !== "undefined" && process.versions && process.versions.electron) {
|
|
247
295
|
try {
|
|
@@ -279,6 +327,34 @@ var BigIOError = class extends Error {
|
|
|
279
327
|
};
|
|
280
328
|
}
|
|
281
329
|
};
|
|
330
|
+
var consoleError = (originalError, message, bigioErrorStack) => {
|
|
331
|
+
if (!IS_DEV) {
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
if (message && bigioErrorStack) {
|
|
335
|
+
console.groupCollapsed(`[BigIOError]`);
|
|
336
|
+
console.error("[BigIOError] message: ", message);
|
|
337
|
+
if (Array.isArray(bigioErrorStack) && bigioErrorStack.length > 0) {
|
|
338
|
+
console.log("[BigIOError] Stack Trace Table: ");
|
|
339
|
+
console.table(bigioErrorStack);
|
|
340
|
+
}
|
|
341
|
+
console.error("[BigIOError] Original Error: ", originalError);
|
|
342
|
+
console.groupEnd();
|
|
343
|
+
} else if (originalError instanceof BigIOError) {
|
|
344
|
+
console.groupCollapsed(`[BigIOError]`);
|
|
345
|
+
console.error("[BigIOError] message: ", originalError.message);
|
|
346
|
+
if (Array.isArray(originalError.bigioErrorStack) && originalError.bigioErrorStack.length > 0) {
|
|
347
|
+
console.log("[BigIOError] Stack Trace Table: ");
|
|
348
|
+
console.table(originalError.bigioErrorStack);
|
|
349
|
+
}
|
|
350
|
+
console.error("[BigIOError] Original Error: ", originalError.cause);
|
|
351
|
+
console.groupEnd();
|
|
352
|
+
} else {
|
|
353
|
+
console.groupCollapsed(`[Error]`);
|
|
354
|
+
console.error("[Error]: ", originalError);
|
|
355
|
+
console.groupEnd();
|
|
356
|
+
}
|
|
357
|
+
};
|
|
282
358
|
function getPreviousBigIOErrorStack(error) {
|
|
283
359
|
if (error instanceof BigIOError) {
|
|
284
360
|
return error.bigioErrorStack;
|
|
@@ -295,15 +371,41 @@ function okOr(value, errorMessage) {
|
|
|
295
371
|
const now = Date.now();
|
|
296
372
|
const ctx = (() => {
|
|
297
373
|
const DEFAULT_CTX = "okOr function failed";
|
|
298
|
-
{
|
|
374
|
+
if (!(errorMessage instanceof Error) && typeof errorMessage === "object" && "ctx" in errorMessage) {
|
|
375
|
+
return errorMessage.ctx;
|
|
376
|
+
}
|
|
377
|
+
if (typeof errorMessage === "string") {
|
|
378
|
+
return DEFAULT_CTX;
|
|
379
|
+
}
|
|
380
|
+
if (errorMessage === void 0) {
|
|
381
|
+
return DEFAULT_CTX;
|
|
382
|
+
}
|
|
383
|
+
if (errorMessage instanceof Error) {
|
|
384
|
+
return DEFAULT_CTX;
|
|
385
|
+
}
|
|
386
|
+
if (errorMessage === true) {
|
|
299
387
|
return DEFAULT_CTX;
|
|
300
388
|
}
|
|
389
|
+
return DEFAULT_CTX;
|
|
301
390
|
})();
|
|
302
391
|
const msg = (() => {
|
|
303
392
|
const DEFAULT_MSG = "Unexpected return null or undefined value";
|
|
304
|
-
{
|
|
393
|
+
if (!(errorMessage instanceof Error) && typeof errorMessage === "object" && "msg" in errorMessage && typeof errorMessage.msg === "string") {
|
|
394
|
+
return errorMessage.msg;
|
|
395
|
+
}
|
|
396
|
+
if (typeof errorMessage === "string") {
|
|
397
|
+
return errorMessage;
|
|
398
|
+
}
|
|
399
|
+
if (errorMessage === void 0) {
|
|
305
400
|
return DEFAULT_MSG;
|
|
306
401
|
}
|
|
402
|
+
if (errorMessage instanceof Error) {
|
|
403
|
+
return DEFAULT_MSG;
|
|
404
|
+
}
|
|
405
|
+
if (errorMessage === true) {
|
|
406
|
+
return DEFAULT_MSG;
|
|
407
|
+
}
|
|
408
|
+
return DEFAULT_MSG;
|
|
307
409
|
})();
|
|
308
410
|
const newItem = {
|
|
309
411
|
msg,
|
|
@@ -345,6 +447,114 @@ function okOr(value, errorMessage) {
|
|
|
345
447
|
bigioErrorStack: [newItem]
|
|
346
448
|
});
|
|
347
449
|
}
|
|
450
|
+
var handleUnsafeError = (originalError, errorMessage) => {
|
|
451
|
+
const now = Date.now();
|
|
452
|
+
const prevStack = getPreviousBigIOErrorStack(originalError);
|
|
453
|
+
const originalErrorMsg = originalError instanceof Error ? originalError.message : String(originalError);
|
|
454
|
+
const newMsg = (() => {
|
|
455
|
+
if (errorMessage === true) {
|
|
456
|
+
return originalErrorMsg;
|
|
457
|
+
}
|
|
458
|
+
if (typeof errorMessage === "string") {
|
|
459
|
+
return errorMessage;
|
|
460
|
+
}
|
|
461
|
+
if (typeof errorMessage === "object" && "ctx" in errorMessage && !(errorMessage instanceof Error)) {
|
|
462
|
+
return errorMessage.msg || originalErrorMsg;
|
|
463
|
+
}
|
|
464
|
+
if (errorMessage instanceof Error) {
|
|
465
|
+
return errorMessage.message;
|
|
466
|
+
}
|
|
467
|
+
return originalErrorMsg;
|
|
468
|
+
})();
|
|
469
|
+
const userStack = (() => {
|
|
470
|
+
if (errorMessage === true) {
|
|
471
|
+
return [
|
|
472
|
+
{
|
|
473
|
+
msg: "SafeTry failed",
|
|
474
|
+
ctx: originalErrorMsg,
|
|
475
|
+
timestamp: now
|
|
476
|
+
}
|
|
477
|
+
];
|
|
478
|
+
}
|
|
479
|
+
if (typeof errorMessage === "string") {
|
|
480
|
+
return [
|
|
481
|
+
{
|
|
482
|
+
msg: errorMessage,
|
|
483
|
+
ctx: originalErrorMsg,
|
|
484
|
+
timestamp: now
|
|
485
|
+
}
|
|
486
|
+
];
|
|
487
|
+
}
|
|
488
|
+
if (typeof errorMessage === "object" && "ctx" in errorMessage && !(errorMessage instanceof Error)) {
|
|
489
|
+
return [
|
|
490
|
+
{
|
|
491
|
+
msg: errorMessage.msg || originalErrorMsg,
|
|
492
|
+
ctx: errorMessage.ctx,
|
|
493
|
+
timestamp: now
|
|
494
|
+
}
|
|
495
|
+
];
|
|
496
|
+
}
|
|
497
|
+
if (errorMessage instanceof Error) {
|
|
498
|
+
const userNewStack = getPreviousBigIOErrorStack(errorMessage);
|
|
499
|
+
if (userNewStack.length > 0) {
|
|
500
|
+
const lastItem = userNewStack.at(-1);
|
|
501
|
+
if (lastItem && typeof lastItem === "object" && !("timestamp" in lastItem && lastItem.timestamp)) {
|
|
502
|
+
return [...userNewStack.slice(0, -1), { ...lastItem, timestamp: now }];
|
|
503
|
+
}
|
|
504
|
+
return userNewStack;
|
|
505
|
+
}
|
|
506
|
+
return [{ msg: errorMessage.message, ctx: originalErrorMsg, timestamp: now }];
|
|
507
|
+
}
|
|
508
|
+
return [{ ctx: originalErrorMsg }];
|
|
509
|
+
})();
|
|
510
|
+
const MAX_STACK_SIZE = IS_DEV ? 500 : 50;
|
|
511
|
+
const newStack = (() => {
|
|
512
|
+
const stack = [...prevStack, ...userStack];
|
|
513
|
+
if (stack.length > MAX_STACK_SIZE) {
|
|
514
|
+
return [
|
|
515
|
+
{
|
|
516
|
+
msg: `... Truncated (Stack > ${MAX_STACK_SIZE}) ...`,
|
|
517
|
+
ctx: null,
|
|
518
|
+
timestamp: now
|
|
519
|
+
},
|
|
520
|
+
...stack.slice(-MAX_STACK_SIZE)
|
|
521
|
+
];
|
|
522
|
+
}
|
|
523
|
+
return stack;
|
|
524
|
+
})();
|
|
525
|
+
consoleError(originalError, newMsg, newStack);
|
|
526
|
+
if (errorMessage instanceof Error) {
|
|
527
|
+
if (!errorMessage.cause && originalError) {
|
|
528
|
+
try {
|
|
529
|
+
Object.defineProperty(errorMessage, "cause", {
|
|
530
|
+
value: originalError,
|
|
531
|
+
configurable: true,
|
|
532
|
+
writable: true,
|
|
533
|
+
enumerable: false
|
|
534
|
+
});
|
|
535
|
+
} catch {
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
try {
|
|
539
|
+
Object.defineProperty(errorMessage, "bigioErrorStack", {
|
|
540
|
+
value: newStack,
|
|
541
|
+
configurable: true,
|
|
542
|
+
writable: true,
|
|
543
|
+
enumerable: false
|
|
544
|
+
});
|
|
545
|
+
} catch {
|
|
546
|
+
throw new BigIOError("Wrapper for frozen user error", {
|
|
547
|
+
cause: errorMessage,
|
|
548
|
+
bigioErrorStack: newStack
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
throw errorMessage;
|
|
552
|
+
}
|
|
553
|
+
throw new BigIOError(newMsg, {
|
|
554
|
+
cause: originalError,
|
|
555
|
+
bigioErrorStack: newStack
|
|
556
|
+
});
|
|
557
|
+
};
|
|
348
558
|
var handleSafeError = (originalError) => {
|
|
349
559
|
const prevStack = getPreviousBigIOErrorStack(originalError);
|
|
350
560
|
const originalErrorMsg = originalError instanceof Error ? originalError.message : String(originalError);
|
|
@@ -362,6 +572,9 @@ var handleSafeError = (originalError) => {
|
|
|
362
572
|
};
|
|
363
573
|
};
|
|
364
574
|
var handlePromise = (internalPromise, errorMessage) => {
|
|
575
|
+
if (errorMessage !== void 0) {
|
|
576
|
+
return internalPromise.then((data) => okOr(data, errorMessage)).catch((originalError) => handleUnsafeError(originalError, errorMessage));
|
|
577
|
+
}
|
|
365
578
|
return internalPromise.then((data) => ({ data: okOr(data), error: null })).catch((originalError) => handleSafeError(originalError));
|
|
366
579
|
};
|
|
367
580
|
function safeTry(func, errorMessage) {
|
|
@@ -374,13 +587,18 @@ function safeTry(func, errorMessage) {
|
|
|
374
587
|
if (result instanceof Promise) {
|
|
375
588
|
return handlePromise(result, errorMessage);
|
|
376
589
|
}
|
|
377
|
-
if (errorMessage !== void 0)
|
|
590
|
+
if (errorMessage !== void 0) {
|
|
591
|
+
return okOr(result, errorMessage);
|
|
592
|
+
}
|
|
378
593
|
return {
|
|
379
594
|
data: okOr(result),
|
|
380
595
|
error: null
|
|
381
596
|
};
|
|
382
597
|
}
|
|
383
598
|
} catch (error) {
|
|
599
|
+
if (errorMessage !== void 0) {
|
|
600
|
+
handleUnsafeError(error, errorMessage);
|
|
601
|
+
}
|
|
384
602
|
return handleSafeError(error);
|
|
385
603
|
}
|
|
386
604
|
const now = Date.now();
|
|
@@ -395,22 +613,67 @@ function safeTry(func, errorMessage) {
|
|
|
395
613
|
}
|
|
396
614
|
]
|
|
397
615
|
});
|
|
616
|
+
if (errorMessage !== void 0) {
|
|
617
|
+
throw invalidError;
|
|
618
|
+
}
|
|
398
619
|
return {
|
|
399
620
|
data: null,
|
|
400
621
|
error: invalidError
|
|
401
622
|
};
|
|
402
623
|
}
|
|
403
624
|
new TextEncoder();
|
|
625
|
+
var GLOBAL_DECODER = new TextDecoder();
|
|
626
|
+
function decode64(str) {
|
|
627
|
+
const checkStr = okOr(str, {
|
|
628
|
+
msg: "Invalid string input for fromBase64Url",
|
|
629
|
+
ctx: {
|
|
630
|
+
stringLength: str?.length
|
|
631
|
+
}
|
|
632
|
+
});
|
|
633
|
+
const normalizedStr = checkStr.replace(/\+/g, "-").replace(/\//g, "_");
|
|
634
|
+
const bytesBuffer = safeTry(() => decodeBase64urlIgnorePadding(normalizedStr), {
|
|
635
|
+
msg: "Base64 Decoding Failed",
|
|
636
|
+
ctx: {
|
|
637
|
+
msg: "Oslo decode failed",
|
|
638
|
+
ctx: { strPart: str.slice(0, 10) }
|
|
639
|
+
}
|
|
640
|
+
});
|
|
641
|
+
return bytesBuffer;
|
|
642
|
+
}
|
|
404
643
|
var REGEX_BASE64_URL = /^[a-zA-Z0-9\-_]+=*$/;
|
|
405
|
-
function
|
|
644
|
+
function RequiredSearchParamsBuilder(ELECTRON_SCHEME, PROVIDERS) {
|
|
406
645
|
return z.object({
|
|
407
646
|
scheme: z.string().min(1, "Scheme cannot be empty").regex(REGEX_BASE64_URL).refine((scheme) => scheme === ELECTRON_SCHEME, {
|
|
408
647
|
message: "Invalid scheme provided"
|
|
409
648
|
}),
|
|
410
649
|
provider: z.enum(PROVIDERS),
|
|
411
|
-
challenge: z.string().length(43, "Challenge must be exactly 43 characters").regex(REGEX_BASE64_URL)
|
|
650
|
+
challenge: z.string().length(43, "Challenge must be exactly 43 characters").regex(REGEX_BASE64_URL),
|
|
651
|
+
status: z.enum(["succeed", "error", "newUser"]).optional()
|
|
412
652
|
});
|
|
413
653
|
}
|
|
654
|
+
var OptionalSearchParamsZodBuilder = z.object({
|
|
655
|
+
scopes: z.array(z.string()).optional(),
|
|
656
|
+
loginHint: z.string().optional(),
|
|
657
|
+
additionalData: z.record(z.string(), z.any()).optional(),
|
|
658
|
+
requestSignUp: boolean().optional()
|
|
659
|
+
});
|
|
660
|
+
var safeDecodeURL = (data) => {
|
|
661
|
+
return safeTry(() => {
|
|
662
|
+
if (data === void 0 || data === null) {
|
|
663
|
+
throw new BigIOError("Invalid input for safeDecodeURL: input is null/undefined", {
|
|
664
|
+
bigioErrorStack: [{ msg: "input is null/undefined" }]
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
if (typeof data !== "string") {
|
|
668
|
+
throw new BigIOError("Invalid input for safeDecodeURL: expected string", {
|
|
669
|
+
bigioErrorStack: [{ ctx: { type: typeof data, value: data } }]
|
|
670
|
+
});
|
|
671
|
+
}
|
|
672
|
+
const bytes = decode64(data);
|
|
673
|
+
const jsonStr = GLOBAL_DECODER.decode(bytes);
|
|
674
|
+
return JSON.parse(jsonStr);
|
|
675
|
+
}, true);
|
|
676
|
+
};
|
|
414
677
|
|
|
415
678
|
// src/web/electron-web-clientHelper.ts
|
|
416
679
|
var lazyClient = atom();
|
|
@@ -427,7 +690,7 @@ var checkAndSetGlobalLock = () => {
|
|
|
427
690
|
return false;
|
|
428
691
|
};
|
|
429
692
|
var electronWebHandoffPlugin = () => {
|
|
430
|
-
const config = { ...
|
|
693
|
+
const config = { ...defaultWebOptions };
|
|
431
694
|
const {
|
|
432
695
|
CHALLENGE_NAME_IN_URL,
|
|
433
696
|
PROVIDER_NAME_IN_URL,
|
|
@@ -435,175 +698,244 @@ var electronWebHandoffPlugin = () => {
|
|
|
435
698
|
PROVIDERS,
|
|
436
699
|
ELECTRON_SCHEME,
|
|
437
700
|
WEB_OAUTH_SIGNIN_CALLBACK_PATHNAME,
|
|
438
|
-
BACKEND_FAST_TICKET_URL
|
|
701
|
+
BACKEND_FAST_TICKET_URL,
|
|
702
|
+
SCOPES_NAME_IN_URL,
|
|
703
|
+
LOGINHINT_NAME_IN_URL,
|
|
704
|
+
ADDITIONAL_DATA_NAME_IN_URL,
|
|
705
|
+
REQUEST_SIGN_UP_NAME_IN_URL,
|
|
706
|
+
AUTH_STATUS_NAME_IN_URL
|
|
439
707
|
} = config;
|
|
440
708
|
const electronWebAtoms = ($fetch) => {
|
|
709
|
+
const handoffError = atom(null);
|
|
441
710
|
const handoffStatus = atom("idle");
|
|
442
|
-
const
|
|
443
|
-
|
|
444
|
-
});
|
|
445
|
-
const myAtom = atom(null);
|
|
711
|
+
const fastLogin = atom(null);
|
|
712
|
+
const initializationErrorAtom = atom(null);
|
|
446
713
|
return {
|
|
714
|
+
handoffError,
|
|
447
715
|
handoffStatus,
|
|
448
|
-
|
|
449
|
-
|
|
716
|
+
fastLogin,
|
|
717
|
+
initializationErrorAtom
|
|
450
718
|
};
|
|
451
719
|
};
|
|
452
720
|
return {
|
|
453
|
-
id: "electron-
|
|
721
|
+
id: "bigio-electron-webhandoff-plugin",
|
|
454
722
|
getAtoms: ($fetch) => electronWebAtoms(),
|
|
455
723
|
getActions: ($fetch, $store) => {
|
|
456
|
-
console.log("getActions");
|
|
457
724
|
const sessionAtom = $store.atoms.session;
|
|
458
|
-
const {
|
|
459
|
-
|
|
460
|
-
|
|
725
|
+
const {
|
|
726
|
+
handoffStatus,
|
|
727
|
+
handoffError,
|
|
728
|
+
fastLogin: fastLoginAtom,
|
|
729
|
+
initializationErrorAtom
|
|
730
|
+
} = $store.atoms;
|
|
731
|
+
const handoffLogic = async () => {
|
|
732
|
+
if (handoffStatus.get() !== "idle" && handoffStatus.get() !== "pending") {
|
|
733
|
+
return false;
|
|
734
|
+
}
|
|
461
735
|
const { data: sessionData, isPending, isRefetching, error } = sessionAtom.get();
|
|
462
736
|
if (isPending || isRefetching || error) {
|
|
463
|
-
return;
|
|
464
|
-
}
|
|
465
|
-
if (handoffStatus.get() !== "idle") {
|
|
466
|
-
return;
|
|
737
|
+
return false;
|
|
467
738
|
}
|
|
468
739
|
const searchParams = new URLSearchParams(window.location.search);
|
|
469
740
|
const scheme = searchParams.get(SCHEME_NAME_IN_URL);
|
|
470
741
|
if (!scheme) {
|
|
471
|
-
return;
|
|
742
|
+
return false;
|
|
472
743
|
}
|
|
473
744
|
if (scheme !== ELECTRON_SCHEME) {
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
745
|
+
throw new BigIOError(`Wrong Scheme: ${scheme}`, {
|
|
746
|
+
bigioErrorStack: [
|
|
747
|
+
{
|
|
748
|
+
msg: `Wrong Scheme: ${scheme}`
|
|
749
|
+
}
|
|
750
|
+
]
|
|
477
751
|
});
|
|
478
|
-
handoffStatus.set("failed");
|
|
479
|
-
return;
|
|
480
752
|
}
|
|
481
753
|
const provider = searchParams.get(PROVIDER_NAME_IN_URL);
|
|
754
|
+
if (!provider) {
|
|
755
|
+
return false;
|
|
756
|
+
}
|
|
482
757
|
const challenge = searchParams.get(CHALLENGE_NAME_IN_URL);
|
|
483
|
-
|
|
484
|
-
|
|
758
|
+
if (!challenge) {
|
|
759
|
+
return false;
|
|
760
|
+
}
|
|
761
|
+
const SearchParamsZod = RequiredSearchParamsBuilder(ELECTRON_SCHEME, [...PROVIDERS]);
|
|
762
|
+
const requiredValidParams = SearchParamsZod.parse({
|
|
485
763
|
scheme,
|
|
486
764
|
provider,
|
|
487
765
|
challenge
|
|
488
|
-
};
|
|
489
|
-
const
|
|
766
|
+
});
|
|
767
|
+
const scopes = searchParams.get(SCOPES_NAME_IN_URL);
|
|
768
|
+
const loginHint = searchParams.get(LOGINHINT_NAME_IN_URL);
|
|
769
|
+
const additionalData = searchParams.get(ADDITIONAL_DATA_NAME_IN_URL);
|
|
770
|
+
const requestSignUp = searchParams.get(REQUEST_SIGN_UP_NAME_IN_URL);
|
|
771
|
+
const optionalValidParams = OptionalSearchParamsZodBuilder.parse({
|
|
772
|
+
scopes: scopes ? safeDecodeURL(scopes) : void 0,
|
|
773
|
+
loginHint: loginHint ? safeDecodeURL(loginHint) : void 0,
|
|
774
|
+
additionalData: additionalData ? safeDecodeURL(additionalData) : void 0,
|
|
775
|
+
requestSignUp: requestSignUp ? safeDecodeURL(requestSignUp) : void 0
|
|
776
|
+
});
|
|
490
777
|
const client = lazyClient.get();
|
|
491
778
|
if (!client) {
|
|
492
|
-
|
|
779
|
+
throw new BigIOError("handoff fn faild to get AuthClient", {
|
|
780
|
+
bigioErrorStack: [{ msg: "check the init authClient code" }]
|
|
781
|
+
});
|
|
493
782
|
}
|
|
494
|
-
const
|
|
495
|
-
console.log("\u6AA2\u6E2C\u5230\u6709\u6548 Session,\u555F\u52D5\u5FEB\u901F\u901A\u9053...");
|
|
783
|
+
const fastLogin = async () => {
|
|
496
784
|
handoffStatus.set("connecting");
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
785
|
+
return await safeTry(async () => {
|
|
786
|
+
const { data: fastTicketData, error: fastTicketError } = await client.$fetch(`/${BACKEND_FAST_TICKET_URL}`, {
|
|
787
|
+
method: "POST",
|
|
788
|
+
body: {
|
|
789
|
+
userid: (sessionData?.user).id,
|
|
790
|
+
scheme,
|
|
791
|
+
provider,
|
|
792
|
+
challenge
|
|
793
|
+
},
|
|
794
|
+
credentials: "include"
|
|
795
|
+
});
|
|
796
|
+
if (fastTicketError || !fastTicketData.redirect) {
|
|
797
|
+
throw new BigIOError("Failed to get fast ticket", {
|
|
798
|
+
bigioErrorStack: [
|
|
799
|
+
{
|
|
800
|
+
msg: "Failed to get fast ticket",
|
|
801
|
+
ctx: {
|
|
802
|
+
requiredValidParams,
|
|
803
|
+
error: fastTicketError
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
]
|
|
508
807
|
});
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
808
|
+
}
|
|
809
|
+
const targetUrl = fastTicketData.redirect;
|
|
810
|
+
if (!targetUrl.startsWith(`${scheme}://`)) {
|
|
811
|
+
throw new BigIOError(
|
|
812
|
+
`Failed to get fast ticket with Wrong Scheme: ${scheme}`,
|
|
813
|
+
{
|
|
512
814
|
bigioErrorStack: [
|
|
513
|
-
{
|
|
815
|
+
{
|
|
816
|
+
msg: "Failed to get fast ticket with Wrong Scheme",
|
|
817
|
+
ctx: scheme
|
|
818
|
+
}
|
|
514
819
|
]
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
const targetUrl = fastTicketData.redirect;
|
|
518
|
-
if (!targetUrl.startsWith(`${scheme}://`)) {
|
|
519
|
-
handoffStatus.set("failed");
|
|
520
|
-
console.error(
|
|
521
|
-
`Failed to get fast ticket with Wrong Scheme: ${scheme}`
|
|
522
|
-
);
|
|
523
|
-
throw new BigIOError(
|
|
524
|
-
`Failed to get fast ticket with Wrong Scheme: ${scheme}`,
|
|
525
|
-
{
|
|
526
|
-
bigioErrorStack: [
|
|
527
|
-
{ msg: "Failed to get fast ticket", ctx: scheme }
|
|
528
|
-
]
|
|
529
|
-
}
|
|
530
|
-
);
|
|
531
|
-
}
|
|
532
|
-
return fastTicketData;
|
|
820
|
+
}
|
|
821
|
+
);
|
|
533
822
|
}
|
|
823
|
+
handoffStatus.set("succeed");
|
|
824
|
+
window.location.href = targetUrl;
|
|
825
|
+
return sessionData.user;
|
|
826
|
+
}, true);
|
|
827
|
+
};
|
|
828
|
+
const parseURL = (status) => {
|
|
829
|
+
const callbackURL = new URL(
|
|
830
|
+
`/${WEB_OAUTH_SIGNIN_CALLBACK_PATHNAME}`,
|
|
831
|
+
window.location.origin
|
|
534
832
|
);
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
window.location.href = fastLoginResult.redirect;
|
|
544
|
-
handoffStatus.set("succeed");
|
|
545
|
-
handoffMessage.set({ msg: "succeed" });
|
|
546
|
-
return true;
|
|
833
|
+
callbackURL.searchParams.set(AUTH_STATUS_NAME_IN_URL, status);
|
|
834
|
+
callbackURL.searchParams.set(SCHEME_NAME_IN_URL, requiredValidParams.scheme);
|
|
835
|
+
callbackURL.searchParams.set(PROVIDER_NAME_IN_URL, requiredValidParams.provider);
|
|
836
|
+
callbackURL.searchParams.set(
|
|
837
|
+
CHALLENGE_NAME_IN_URL,
|
|
838
|
+
requiredValidParams.challenge
|
|
839
|
+
);
|
|
840
|
+
return callbackURL.pathname + callbackURL.search;
|
|
547
841
|
};
|
|
548
|
-
const
|
|
549
|
-
console.log("\u767B\u9304ing");
|
|
842
|
+
const regularLogin = async (loginProvider) => {
|
|
550
843
|
handoffStatus.set("connecting");
|
|
551
|
-
|
|
552
|
-
const
|
|
553
|
-
|
|
554
|
-
|
|
844
|
+
return await safeTry(async () => {
|
|
845
|
+
const { data: socialData, error: socialError } = await client.signIn.social(
|
|
846
|
+
{
|
|
847
|
+
provider: loginProvider,
|
|
848
|
+
callbackURL: parseURL("succeed"),
|
|
849
|
+
scopes: optionalValidParams.scopes,
|
|
850
|
+
additionalData: optionalValidParams.additionalData,
|
|
851
|
+
loginHint: optionalValidParams.loginHint,
|
|
852
|
+
requestSignUp: optionalValidParams.requestSignUp,
|
|
853
|
+
disableRedirect: false,
|
|
854
|
+
errorCallbackURL: parseURL("error"),
|
|
855
|
+
newUserCallbackURL: parseURL("newUser")
|
|
856
|
+
}
|
|
555
857
|
);
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
858
|
+
if (!socialData || socialError) {
|
|
859
|
+
throw new BigIOError(`Faild to sign in with ${loginProvider}`, {
|
|
860
|
+
bigioErrorStack: [
|
|
861
|
+
{
|
|
862
|
+
ctx: {
|
|
863
|
+
provider: loginProvider,
|
|
864
|
+
error: socialError
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
]
|
|
868
|
+
});
|
|
869
|
+
}
|
|
870
|
+
handoffStatus.set("succeed");
|
|
871
|
+
return socialData;
|
|
872
|
+
}, true);
|
|
873
|
+
};
|
|
874
|
+
if (sessionData?.session) {
|
|
875
|
+
if (optionalValidParams.requestSignUp) {
|
|
876
|
+
return await regularLogin(provider);
|
|
877
|
+
}
|
|
878
|
+
const isFastLogin = fastLoginAtom.get();
|
|
879
|
+
if (isFastLogin === true) {
|
|
880
|
+
return await fastLogin();
|
|
881
|
+
}
|
|
882
|
+
if (isFastLogin === false) {
|
|
883
|
+
return await regularLogin(provider);
|
|
884
|
+
}
|
|
885
|
+
if (isFastLogin === null) {
|
|
886
|
+
handoffStatus.set("pending");
|
|
564
887
|
return true;
|
|
565
|
-
});
|
|
566
|
-
if (!loginData || loginError) {
|
|
567
|
-
handoffStatus.set("failed");
|
|
568
|
-
handoffMessage.set({
|
|
569
|
-
msg: "failed",
|
|
570
|
-
ctx: searchParamsObj
|
|
571
|
-
});
|
|
572
|
-
return false;
|
|
573
888
|
}
|
|
574
|
-
handoffStatus.set("succeed");
|
|
575
|
-
handoffMessage.set({ msg: "succeed" });
|
|
576
|
-
return true;
|
|
577
|
-
};
|
|
578
|
-
if (sessionData) {
|
|
579
|
-
performFastLogin();
|
|
580
889
|
} else {
|
|
581
|
-
|
|
890
|
+
return await regularLogin(provider);
|
|
582
891
|
}
|
|
892
|
+
return false;
|
|
583
893
|
};
|
|
584
894
|
if (!checkAndSetGlobalLock()) {
|
|
585
|
-
|
|
586
|
-
console.log(
|
|
895
|
+
sessionAtom.listen(async (aatom) => {
|
|
896
|
+
console.log(sessionAtom.get());
|
|
897
|
+
const { data, error } = await safeTry(() => handoffLogic());
|
|
898
|
+
if (error) {
|
|
899
|
+
handoffStatus.set("failed");
|
|
900
|
+
handoffError.set(error.message);
|
|
901
|
+
initializationErrorAtom.set(error);
|
|
902
|
+
console.error(error);
|
|
903
|
+
}
|
|
587
904
|
});
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
905
|
+
fastLoginAtom.listen(async () => {
|
|
906
|
+
handoffStatus.set("idle");
|
|
907
|
+
const { data, error } = await safeTry(() => handoffLogic());
|
|
908
|
+
if (error) {
|
|
909
|
+
handoffStatus.set("failed");
|
|
910
|
+
handoffError.set(error.message);
|
|
911
|
+
initializationErrorAtom.set(error);
|
|
912
|
+
console.error(error);
|
|
913
|
+
}
|
|
591
914
|
});
|
|
592
915
|
}
|
|
916
|
+
const setFastLogin = (decision) => {
|
|
917
|
+
fastLoginAtom.set(decision);
|
|
918
|
+
};
|
|
593
919
|
return {
|
|
594
920
|
bigio: {
|
|
595
921
|
useElectronOAuthSession: () => {
|
|
922
|
+
const initializationError = initializationErrorAtom.get();
|
|
923
|
+
if (initializationError instanceof Error) {
|
|
924
|
+
console.error(initializationError);
|
|
925
|
+
initializationErrorAtom.set(null);
|
|
926
|
+
}
|
|
596
927
|
const { data, error, isPending, isRefetching, refetch } = useStore(sessionAtom);
|
|
597
|
-
const
|
|
598
|
-
|
|
599
|
-
);
|
|
928
|
+
const oauthError = useStore(handoffError);
|
|
929
|
+
const oauthStatus = useStore(handoffStatus);
|
|
600
930
|
return {
|
|
601
931
|
data,
|
|
602
932
|
error,
|
|
603
933
|
isPending,
|
|
604
934
|
isRefetching,
|
|
605
935
|
refetch,
|
|
606
|
-
|
|
936
|
+
oauthStatus,
|
|
937
|
+
oauthError,
|
|
938
|
+
setFastLogin
|
|
607
939
|
};
|
|
608
940
|
}
|
|
609
941
|
}
|