@lvce-editor/auth-worker 3.22.2 → 3.23.0
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/authWorkerMain.js +151 -56
- package/package.json +1 -1
package/dist/authWorkerMain.js
CHANGED
|
@@ -573,9 +573,12 @@ const applyDataProperties = (restoredError, error) => {
|
|
|
573
573
|
writable: true
|
|
574
574
|
});
|
|
575
575
|
}
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
restoredError
|
|
576
|
+
const name = error.data.name || error.data.type;
|
|
577
|
+
if (name) {
|
|
578
|
+
Object.defineProperty(restoredError, 'name', {
|
|
579
|
+
configurable: true,
|
|
580
|
+
value: name
|
|
581
|
+
});
|
|
579
582
|
}
|
|
580
583
|
};
|
|
581
584
|
const applyDirectProperties = (restoredError, error) => {
|
|
@@ -592,7 +595,7 @@ const applyDirectProperties = (restoredError, error) => {
|
|
|
592
595
|
}
|
|
593
596
|
};
|
|
594
597
|
const restoreMessageError = (error, _currentStack) => {
|
|
595
|
-
const restoredError = constructError(error.message, error.type || error.data?.type, error.name);
|
|
598
|
+
const restoredError = constructError(error.message, error.type || error.data?.type, error.name || error.data?.name);
|
|
596
599
|
if (typeof error.code === 'string' || typeof error.code === 'number') {
|
|
597
600
|
Object.defineProperty(restoredError, 'code', {
|
|
598
601
|
configurable: true,
|
|
@@ -802,6 +805,12 @@ const handleJsonRpcMessage = async (...args) => {
|
|
|
802
805
|
requiresSocket,
|
|
803
806
|
resolve
|
|
804
807
|
} = options;
|
|
808
|
+
if (message === 'ready') {
|
|
809
|
+
return;
|
|
810
|
+
}
|
|
811
|
+
if (!message || typeof message !== 'object') {
|
|
812
|
+
throw new JsonRpcError('unexpected message');
|
|
813
|
+
}
|
|
805
814
|
if ('id' in message) {
|
|
806
815
|
if ('method' in message) {
|
|
807
816
|
const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
|
|
@@ -1102,6 +1111,7 @@ const create = rpcId => {
|
|
|
1102
1111
|
};
|
|
1103
1112
|
|
|
1104
1113
|
const {
|
|
1114
|
+
dispose,
|
|
1105
1115
|
invoke: invoke$3,
|
|
1106
1116
|
set: set$2
|
|
1107
1117
|
} = create(6040);
|
|
@@ -1135,6 +1145,90 @@ const {
|
|
|
1135
1145
|
const {
|
|
1136
1146
|
invoke,
|
|
1137
1147
|
invokeAndTransfer} = create(RendererWorker);
|
|
1148
|
+
const createAuthProcessRpc = create => {
|
|
1149
|
+
let pending;
|
|
1150
|
+
const get = () => {
|
|
1151
|
+
if (!pending) {
|
|
1152
|
+
pending = create();
|
|
1153
|
+
}
|
|
1154
|
+
return pending;
|
|
1155
|
+
};
|
|
1156
|
+
return {
|
|
1157
|
+
async dispose() {
|
|
1158
|
+
const previous = pending;
|
|
1159
|
+
pending = undefined;
|
|
1160
|
+
if (previous) {
|
|
1161
|
+
const rpc = await previous;
|
|
1162
|
+
await rpc.dispose();
|
|
1163
|
+
}
|
|
1164
|
+
},
|
|
1165
|
+
async invoke(method, ...params) {
|
|
1166
|
+
const rpc = await get();
|
|
1167
|
+
return rpc.invoke(method, ...params);
|
|
1168
|
+
},
|
|
1169
|
+
async invokeAndTransfer(method, ...params) {
|
|
1170
|
+
const rpc = await get();
|
|
1171
|
+
return rpc.invokeAndTransfer(method, ...params);
|
|
1172
|
+
},
|
|
1173
|
+
send(method, ...params) {
|
|
1174
|
+
void get().then(rpc => rpc.send(method, ...params));
|
|
1175
|
+
}
|
|
1176
|
+
};
|
|
1177
|
+
};
|
|
1178
|
+
const initializeAuthProcess = async () => {
|
|
1179
|
+
const rpc = createAuthProcessRpc(async () => {
|
|
1180
|
+
const {
|
|
1181
|
+
port1,
|
|
1182
|
+
port2
|
|
1183
|
+
} = new MessageChannel();
|
|
1184
|
+
let resolveClosed;
|
|
1185
|
+
// Promise.withResolvers requires Node 22, while this package supports Node 16.
|
|
1186
|
+
// eslint-disable-next-line unicorn/prefer-promise-with-resolvers
|
|
1187
|
+
const closed = new Promise(resolve => {
|
|
1188
|
+
resolveClosed = resolve;
|
|
1189
|
+
});
|
|
1190
|
+
const handleClose = () => resolveClosed(new Error('Auth process connection closed'));
|
|
1191
|
+
port2.addEventListener('close', handleClose, {
|
|
1192
|
+
once: true
|
|
1193
|
+
});
|
|
1194
|
+
const failOnClose = async () => {
|
|
1195
|
+
throw await closed;
|
|
1196
|
+
};
|
|
1197
|
+
const raceClose = promise => Promise.race([promise, failOnClose()]);
|
|
1198
|
+
try {
|
|
1199
|
+
await raceClose(invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToSharedProcess', port1, 'HandleMessagePortForAuthProcess.handleMessagePortForAuthProcess'));
|
|
1200
|
+
const messagePortRpc = await create$4({
|
|
1201
|
+
commandMap: {},
|
|
1202
|
+
messagePort: port2
|
|
1203
|
+
});
|
|
1204
|
+
return {
|
|
1205
|
+
async dispose() {
|
|
1206
|
+
handleClose();
|
|
1207
|
+
port2.removeEventListener('close', handleClose);
|
|
1208
|
+
await messagePortRpc.dispose();
|
|
1209
|
+
},
|
|
1210
|
+
invoke: (method, ...params) => raceClose(messagePortRpc.invoke(method, ...params)),
|
|
1211
|
+
invokeAndTransfer: (method, ...params) => raceClose(messagePortRpc.invokeAndTransfer(method, ...params)),
|
|
1212
|
+
send: messagePortRpc.send
|
|
1213
|
+
};
|
|
1214
|
+
} catch (error) {
|
|
1215
|
+
port2.removeEventListener('close', handleClose);
|
|
1216
|
+
port1.close();
|
|
1217
|
+
port2.close();
|
|
1218
|
+
throw error;
|
|
1219
|
+
}
|
|
1220
|
+
});
|
|
1221
|
+
set$2(rpc);
|
|
1222
|
+
};
|
|
1223
|
+
const initializeMainProcess = async () => {
|
|
1224
|
+
const rpc = await create$2({
|
|
1225
|
+
commandMap: {},
|
|
1226
|
+
send: async port => {
|
|
1227
|
+
await invokeAndTransfer('SendMessagePortToMainProcess.sendMessagePortToMainProcess', port, 'HandleElectronMessagePort.handleElectronMessagePort', 0);
|
|
1228
|
+
}
|
|
1229
|
+
});
|
|
1230
|
+
set$1(rpc);
|
|
1231
|
+
};
|
|
1138
1232
|
const sendMessagePortToOpenerWorker = async (port, rpcId) => {
|
|
1139
1233
|
const command = 'HandleMessagePort.handleMessagePort';
|
|
1140
1234
|
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToOpenerWorker', port, command, rpcId);
|
|
@@ -1248,22 +1342,22 @@ const getAuthBackendUrl = async backendUrl => {
|
|
|
1248
1342
|
return invoke('Layout.getBackendUrl');
|
|
1249
1343
|
};
|
|
1250
1344
|
|
|
1251
|
-
const state$
|
|
1345
|
+
const state$4 = {
|
|
1252
1346
|
platform: Web,
|
|
1253
1347
|
useNativeAuth: false
|
|
1254
1348
|
};
|
|
1255
1349
|
const getAuthPlatform = () => {
|
|
1256
|
-
return state$
|
|
1350
|
+
return state$4.platform;
|
|
1257
1351
|
};
|
|
1258
1352
|
const setAuthPlatform = value => {
|
|
1259
|
-
state$
|
|
1353
|
+
state$4.platform = value;
|
|
1260
1354
|
};
|
|
1261
1355
|
|
|
1262
1356
|
// Native shells can use loopback OAuth without Electron's process or secret storage.
|
|
1263
1357
|
const setUseNativeAuth = value => {
|
|
1264
|
-
state$
|
|
1358
|
+
state$4.useNativeAuth = value;
|
|
1265
1359
|
};
|
|
1266
|
-
const getUseNativeAuth = () => state$
|
|
1360
|
+
const getUseNativeAuth = () => state$4.useNativeAuth;
|
|
1267
1361
|
|
|
1268
1362
|
let USER_AGENT;
|
|
1269
1363
|
if (typeof navigator === 'undefined' || !navigator.userAgent?.startsWith?.('Mozilla/5.0 ')) {
|
|
@@ -2435,15 +2529,15 @@ const databaseName = 'auth-worker';
|
|
|
2435
2529
|
const objectStoreName = 'auth';
|
|
2436
2530
|
const memoryStorage = new Map();
|
|
2437
2531
|
const secretKeys = new Set(['accessToken', 'refreshToken', 'accountSessions']);
|
|
2438
|
-
const state$
|
|
2532
|
+
const state$3 = {
|
|
2439
2533
|
databasePromise: undefined
|
|
2440
2534
|
};
|
|
2441
2535
|
const getDatabase = async () => {
|
|
2442
2536
|
if (typeof indexedDB === 'undefined') {
|
|
2443
2537
|
return undefined;
|
|
2444
2538
|
}
|
|
2445
|
-
if (!state$
|
|
2446
|
-
state$
|
|
2539
|
+
if (!state$3.databasePromise) {
|
|
2540
|
+
state$3.databasePromise = openDB(databaseName, 1, {
|
|
2447
2541
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
2448
2542
|
upgrade(database) {
|
|
2449
2543
|
if (!database.objectStoreNames.contains(objectStoreName)) {
|
|
@@ -2452,7 +2546,7 @@ const getDatabase = async () => {
|
|
|
2452
2546
|
}
|
|
2453
2547
|
});
|
|
2454
2548
|
}
|
|
2455
|
-
return state$
|
|
2549
|
+
return state$3.databasePromise;
|
|
2456
2550
|
};
|
|
2457
2551
|
const getIndexedDbValue = async key => {
|
|
2458
2552
|
const database = await getDatabase();
|
|
@@ -2640,40 +2734,40 @@ const getAccountProfile = async (backendUrl, accessToken, fetchFn = fetch) => {
|
|
|
2640
2734
|
};
|
|
2641
2735
|
};
|
|
2642
2736
|
|
|
2643
|
-
const getBackendRefreshUrl = backendUrl => {
|
|
2644
|
-
return getBackendAuthUrl(backendUrl, '/auth/refresh');
|
|
2645
|
-
};
|
|
2646
|
-
|
|
2647
2737
|
const delay = async ms => {
|
|
2648
2738
|
await new Promise(resolve => setTimeout(resolve, ms));
|
|
2649
2739
|
};
|
|
2650
2740
|
|
|
2651
|
-
const
|
|
2741
|
+
const getBackendRefreshUrl = backendUrl => {
|
|
2742
|
+
return getBackendAuthUrl(backendUrl, '/auth/refresh');
|
|
2743
|
+
};
|
|
2744
|
+
|
|
2745
|
+
const state$2 = {
|
|
2652
2746
|
nextLoginResponse: undefined,
|
|
2653
2747
|
nextRefreshResponse: undefined
|
|
2654
2748
|
};
|
|
2655
2749
|
const setNextLoginResponse = response => {
|
|
2656
|
-
state$
|
|
2750
|
+
state$2.nextLoginResponse = response;
|
|
2657
2751
|
};
|
|
2658
2752
|
const setNextRefreshResponse = response => {
|
|
2659
|
-
state$
|
|
2753
|
+
state$2.nextRefreshResponse = response;
|
|
2660
2754
|
};
|
|
2661
2755
|
const clear = () => {
|
|
2662
|
-
state$
|
|
2663
|
-
state$
|
|
2756
|
+
state$2.nextLoginResponse = undefined;
|
|
2757
|
+
state$2.nextRefreshResponse = undefined;
|
|
2664
2758
|
};
|
|
2665
2759
|
const hasPendingMockLoginResponse = () => {
|
|
2666
|
-
return !!state$
|
|
2760
|
+
return !!state$2.nextLoginResponse;
|
|
2667
2761
|
};
|
|
2668
2762
|
const hasPendingMockRefreshResponse = () => {
|
|
2669
|
-
return !!state$
|
|
2763
|
+
return !!state$2.nextRefreshResponse;
|
|
2670
2764
|
};
|
|
2671
2765
|
const consumeNextLoginResponse = async () => {
|
|
2672
|
-
if (!state$
|
|
2766
|
+
if (!state$2.nextLoginResponse) {
|
|
2673
2767
|
return undefined;
|
|
2674
2768
|
}
|
|
2675
|
-
const response = state$
|
|
2676
|
-
state$
|
|
2769
|
+
const response = state$2.nextLoginResponse;
|
|
2770
|
+
state$2.nextLoginResponse = undefined;
|
|
2677
2771
|
if (response.delay > 0) {
|
|
2678
2772
|
await delay(response.delay);
|
|
2679
2773
|
}
|
|
@@ -2683,11 +2777,11 @@ const consumeNextLoginResponse = async () => {
|
|
|
2683
2777
|
return response.response;
|
|
2684
2778
|
};
|
|
2685
2779
|
const consumeNextRefreshResponse = async () => {
|
|
2686
|
-
if (!state$
|
|
2780
|
+
if (!state$2.nextRefreshResponse) {
|
|
2687
2781
|
return undefined;
|
|
2688
2782
|
}
|
|
2689
|
-
const response = state$
|
|
2690
|
-
state$
|
|
2783
|
+
const response = state$2.nextRefreshResponse;
|
|
2784
|
+
state$2.nextRefreshResponse = undefined;
|
|
2691
2785
|
if (response.delay > 0) {
|
|
2692
2786
|
await new Promise(resolve => setTimeout(resolve, response.delay));
|
|
2693
2787
|
}
|
|
@@ -3302,6 +3396,9 @@ const waitForElectronBackendLogin = async (backendUrl, uid, redirectUri, codeVer
|
|
|
3302
3396
|
return getLoggedOutBackendAuthState('Timed out waiting for backend login.');
|
|
3303
3397
|
};
|
|
3304
3398
|
|
|
3399
|
+
const state$1 = {
|
|
3400
|
+
nativeLoginCount: 0
|
|
3401
|
+
};
|
|
3305
3402
|
const getMockLoginResult = async (signingInState, persistResult) => {
|
|
3306
3403
|
if (!hasPendingMockLoginResponse()) {
|
|
3307
3404
|
return undefined;
|
|
@@ -3322,10 +3419,13 @@ const getMockLoginResult = async (signingInState, persistResult) => {
|
|
|
3322
3419
|
return persistResult(getLoggedInState(signingInState, response));
|
|
3323
3420
|
};
|
|
3324
3421
|
const getInteractiveLoginResult = async (backendUrl, platform, signingInState, persistResult, selectAccount) => {
|
|
3325
|
-
const nativeAuth = getUseNativeAuth();
|
|
3422
|
+
const nativeAuth = getUseNativeAuth() || platform === Electron;
|
|
3326
3423
|
const transportPlatform = nativeAuth ? Electron : platform;
|
|
3327
3424
|
const authUseRedirect = getAuthUseRedirect(transportPlatform);
|
|
3328
3425
|
const uid = nativeAuth ? globalThis.crypto.randomUUID() : 0;
|
|
3426
|
+
if (nativeAuth) {
|
|
3427
|
+
state$1.nativeLoginCount++;
|
|
3428
|
+
}
|
|
3329
3429
|
try {
|
|
3330
3430
|
const {
|
|
3331
3431
|
clientId,
|
|
@@ -3358,7 +3458,14 @@ const getInteractiveLoginResult = async (backendUrl, platform, signingInState, p
|
|
|
3358
3458
|
});
|
|
3359
3459
|
} finally {
|
|
3360
3460
|
if (nativeAuth) {
|
|
3361
|
-
|
|
3461
|
+
try {
|
|
3462
|
+
await invoke$3('OAuthServer.dispose', String(uid));
|
|
3463
|
+
} finally {
|
|
3464
|
+
state$1.nativeLoginCount--;
|
|
3465
|
+
if (state$1.nativeLoginCount === 0) {
|
|
3466
|
+
await dispose();
|
|
3467
|
+
}
|
|
3468
|
+
}
|
|
3362
3469
|
}
|
|
3363
3470
|
}
|
|
3364
3471
|
};
|
|
@@ -3677,36 +3784,24 @@ const approveCloudflareMachine = (id, code, zoneId) => {
|
|
|
3677
3784
|
});
|
|
3678
3785
|
};
|
|
3679
3786
|
|
|
3680
|
-
const
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
const initializeAuthProcess = async () => {
|
|
3684
|
-
const rpc = await create$2({
|
|
3685
|
-
commandMap: {},
|
|
3686
|
-
send: sendMessagePortToAuthProcess
|
|
3687
|
-
});
|
|
3688
|
-
set$2(rpc);
|
|
3787
|
+
const processInitializers = {
|
|
3788
|
+
initializeAuthProcess: () => initializeAuthProcess(),
|
|
3789
|
+
initializeMainProcess: () => initializeMainProcess()
|
|
3689
3790
|
};
|
|
3690
3791
|
|
|
3691
|
-
const
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
set$1(rpc);
|
|
3792
|
+
const getProcessInitializers = (options, initializers = processInitializers) => {
|
|
3793
|
+
if (options.platform === Electron) {
|
|
3794
|
+
return [initializers.initializeAuthProcess, initializers.initializeMainProcess];
|
|
3795
|
+
}
|
|
3796
|
+
if (options.useNativeAuth) {
|
|
3797
|
+
return [initializers.initializeAuthProcess];
|
|
3798
|
+
}
|
|
3799
|
+
return [];
|
|
3700
3800
|
};
|
|
3701
|
-
|
|
3702
3801
|
const configure = async options => {
|
|
3703
3802
|
setAuthPlatform(options.platform);
|
|
3704
3803
|
setUseNativeAuth(options.useNativeAuth === true);
|
|
3705
|
-
|
|
3706
|
-
await Promise.all([initializeAuthProcess(), initializeMainProcess()]);
|
|
3707
|
-
} else if (options.useNativeAuth) {
|
|
3708
|
-
await initializeAuthProcess();
|
|
3709
|
-
}
|
|
3804
|
+
await Promise.all(getProcessInitializers(options).map(initialize => initialize()));
|
|
3710
3805
|
};
|
|
3711
3806
|
|
|
3712
3807
|
const handleMessagePort = async (port, rpcId) => {
|