@lvce-editor/auth-worker 3.22.3 → 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 +113 -93
- 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);
|
|
@@ -1136,6 +1145,90 @@ const {
|
|
|
1136
1145
|
const {
|
|
1137
1146
|
invoke,
|
|
1138
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
|
+
};
|
|
1139
1232
|
const sendMessagePortToOpenerWorker = async (port, rpcId) => {
|
|
1140
1233
|
const command = 'HandleMessagePort.handleMessagePort';
|
|
1141
1234
|
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToOpenerWorker', port, command, rpcId);
|
|
@@ -2641,14 +2734,14 @@ const getAccountProfile = async (backendUrl, accessToken, fetchFn = fetch) => {
|
|
|
2641
2734
|
};
|
|
2642
2735
|
};
|
|
2643
2736
|
|
|
2644
|
-
const getBackendRefreshUrl = backendUrl => {
|
|
2645
|
-
return getBackendAuthUrl(backendUrl, '/auth/refresh');
|
|
2646
|
-
};
|
|
2647
|
-
|
|
2648
2737
|
const delay = async ms => {
|
|
2649
2738
|
await new Promise(resolve => setTimeout(resolve, ms));
|
|
2650
2739
|
};
|
|
2651
2740
|
|
|
2741
|
+
const getBackendRefreshUrl = backendUrl => {
|
|
2742
|
+
return getBackendAuthUrl(backendUrl, '/auth/refresh');
|
|
2743
|
+
};
|
|
2744
|
+
|
|
2652
2745
|
const state$2 = {
|
|
2653
2746
|
nextLoginResponse: undefined,
|
|
2654
2747
|
nextRefreshResponse: undefined
|
|
@@ -3691,97 +3784,24 @@ const approveCloudflareMachine = (id, code, zoneId) => {
|
|
|
3691
3784
|
});
|
|
3692
3785
|
};
|
|
3693
3786
|
|
|
3694
|
-
const
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
port2
|
|
3698
|
-
} = new MessageChannel();
|
|
3699
|
-
const closed = Promise.withResolvers();
|
|
3700
|
-
const handleClose = () => closed.resolve(new Error('Auth process connection closed'));
|
|
3701
|
-
port2.addEventListener('close', handleClose, {
|
|
3702
|
-
once: true
|
|
3703
|
-
});
|
|
3704
|
-
const failOnClose = async () => {
|
|
3705
|
-
throw await closed.promise;
|
|
3706
|
-
};
|
|
3707
|
-
const raceClose = promise => Promise.race([promise, failOnClose()]);
|
|
3708
|
-
try {
|
|
3709
|
-
await raceClose(invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToSharedProcess', port1, 'HandleMessagePortForAuthProcess.handleMessagePortForAuthProcess'));
|
|
3710
|
-
const rpc = await create$4({
|
|
3711
|
-
commandMap: {},
|
|
3712
|
-
messagePort: port2
|
|
3713
|
-
});
|
|
3714
|
-
return {
|
|
3715
|
-
async dispose() {
|
|
3716
|
-
handleClose();
|
|
3717
|
-
port2.removeEventListener('close', handleClose);
|
|
3718
|
-
await rpc.dispose();
|
|
3719
|
-
},
|
|
3720
|
-
invoke: (method, ...params) => raceClose(rpc.invoke(method, ...params)),
|
|
3721
|
-
invokeAndTransfer: (method, ...params) => raceClose(rpc.invokeAndTransfer(method, ...params)),
|
|
3722
|
-
send: rpc.send
|
|
3723
|
-
};
|
|
3724
|
-
} catch (error) {
|
|
3725
|
-
port2.removeEventListener('close', handleClose);
|
|
3726
|
-
port1.close();
|
|
3727
|
-
port2.close();
|
|
3728
|
-
throw error;
|
|
3729
|
-
}
|
|
3730
|
-
};
|
|
3731
|
-
const createAuthProcessRpc = (create = connect) => {
|
|
3732
|
-
let pending;
|
|
3733
|
-
const get = () => {
|
|
3734
|
-
if (!pending) {
|
|
3735
|
-
pending = create();
|
|
3736
|
-
}
|
|
3737
|
-
return pending;
|
|
3738
|
-
};
|
|
3739
|
-
return {
|
|
3740
|
-
async dispose() {
|
|
3741
|
-
const previous = pending;
|
|
3742
|
-
// Detach before awaiting: a new login may connect while the old port closes.
|
|
3743
|
-
pending = undefined;
|
|
3744
|
-
if (previous) {
|
|
3745
|
-
const rpc = await previous;
|
|
3746
|
-
await rpc.dispose();
|
|
3747
|
-
}
|
|
3748
|
-
},
|
|
3749
|
-
async invoke(method, ...params) {
|
|
3750
|
-
const rpc = await get();
|
|
3751
|
-
return rpc.invoke(method, ...params);
|
|
3752
|
-
},
|
|
3753
|
-
async invokeAndTransfer(method, ...params) {
|
|
3754
|
-
const rpc = await get();
|
|
3755
|
-
return rpc.invokeAndTransfer(method, ...params);
|
|
3756
|
-
},
|
|
3757
|
-
send(method, ...params) {
|
|
3758
|
-
void get().then(rpc => rpc.send(method, ...params));
|
|
3759
|
-
}
|
|
3760
|
-
};
|
|
3761
|
-
};
|
|
3762
|
-
const initializeAuthProcess = async () => {
|
|
3763
|
-
set$2(createAuthProcessRpc());
|
|
3787
|
+
const processInitializers = {
|
|
3788
|
+
initializeAuthProcess: () => initializeAuthProcess(),
|
|
3789
|
+
initializeMainProcess: () => initializeMainProcess()
|
|
3764
3790
|
};
|
|
3765
3791
|
|
|
3766
|
-
const
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
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 [];
|
|
3775
3800
|
};
|
|
3776
|
-
|
|
3777
3801
|
const configure = async options => {
|
|
3778
3802
|
setAuthPlatform(options.platform);
|
|
3779
3803
|
setUseNativeAuth(options.useNativeAuth === true);
|
|
3780
|
-
|
|
3781
|
-
await Promise.all([initializeAuthProcess(), initializeMainProcess()]);
|
|
3782
|
-
} else if (options.useNativeAuth) {
|
|
3783
|
-
await initializeAuthProcess();
|
|
3784
|
-
}
|
|
3804
|
+
await Promise.all(getProcessInitializers(options).map(initialize => initialize()));
|
|
3785
3805
|
};
|
|
3786
3806
|
|
|
3787
3807
|
const handleMessagePort = async (port, rpcId) => {
|