@lvce-editor/auth-worker 1.10.0 → 1.12.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 +39 -153
- package/package.json +1 -1
package/dist/authWorkerMain.js
CHANGED
|
@@ -267,45 +267,6 @@ const readyMessage = 'ready';
|
|
|
267
267
|
const getData$2 = event => {
|
|
268
268
|
return event.data;
|
|
269
269
|
};
|
|
270
|
-
const listen$8 = ({
|
|
271
|
-
port
|
|
272
|
-
}) => {
|
|
273
|
-
return port;
|
|
274
|
-
};
|
|
275
|
-
const signal$9 = port => {
|
|
276
|
-
port.postMessage(readyMessage);
|
|
277
|
-
};
|
|
278
|
-
class IpcChildWithMessagePort extends Ipc {
|
|
279
|
-
getData(event) {
|
|
280
|
-
return getData$2(event);
|
|
281
|
-
}
|
|
282
|
-
send(message) {
|
|
283
|
-
this._rawIpc.postMessage(message);
|
|
284
|
-
}
|
|
285
|
-
sendAndTransfer(message) {
|
|
286
|
-
const transfer = getTransferrables(message);
|
|
287
|
-
this._rawIpc.postMessage(message, transfer);
|
|
288
|
-
}
|
|
289
|
-
dispose() {
|
|
290
|
-
// ignore
|
|
291
|
-
}
|
|
292
|
-
onClose(callback) {
|
|
293
|
-
// ignore
|
|
294
|
-
}
|
|
295
|
-
onMessage(callback) {
|
|
296
|
-
this._rawIpc.addEventListener('message', callback);
|
|
297
|
-
this._rawIpc.start();
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
const wrap$g = port => {
|
|
301
|
-
return new IpcChildWithMessagePort(port);
|
|
302
|
-
};
|
|
303
|
-
const IpcChildWithMessagePort$1 = {
|
|
304
|
-
__proto__: null,
|
|
305
|
-
listen: listen$8,
|
|
306
|
-
signal: signal$9,
|
|
307
|
-
wrap: wrap$g
|
|
308
|
-
};
|
|
309
270
|
const listen$7 = () => {
|
|
310
271
|
// @ts-ignore
|
|
311
272
|
if (typeof WorkerGlobalScope === 'undefined') {
|
|
@@ -342,70 +303,11 @@ class IpcChildWithModuleWorker extends Ipc {
|
|
|
342
303
|
const wrap$f = global => {
|
|
343
304
|
return new IpcChildWithModuleWorker(global);
|
|
344
305
|
};
|
|
345
|
-
const
|
|
346
|
-
const {
|
|
347
|
-
promise,
|
|
348
|
-
resolve
|
|
349
|
-
} = Promise.withResolvers();
|
|
350
|
-
port.addEventListener('message', resolve, {
|
|
351
|
-
once: true
|
|
352
|
-
});
|
|
353
|
-
const event = await promise;
|
|
354
|
-
// @ts-ignore
|
|
355
|
-
return event.data;
|
|
356
|
-
};
|
|
357
|
-
const listen$6 = async () => {
|
|
358
|
-
const parentIpcRaw = listen$7();
|
|
359
|
-
signal$8(parentIpcRaw);
|
|
360
|
-
const parentIpc = wrap$f(parentIpcRaw);
|
|
361
|
-
const firstMessage = await waitForFirstMessage(parentIpc);
|
|
362
|
-
if (firstMessage.method !== 'initialize') {
|
|
363
|
-
throw new IpcError('unexpected first message');
|
|
364
|
-
}
|
|
365
|
-
const type = firstMessage.params[0];
|
|
366
|
-
if (type === 'message-port') {
|
|
367
|
-
parentIpc.send({
|
|
368
|
-
id: firstMessage.id,
|
|
369
|
-
jsonrpc: '2.0',
|
|
370
|
-
result: null
|
|
371
|
-
});
|
|
372
|
-
parentIpc.dispose();
|
|
373
|
-
const port = firstMessage.params[1];
|
|
374
|
-
return port;
|
|
375
|
-
}
|
|
376
|
-
return globalThis;
|
|
377
|
-
};
|
|
378
|
-
class IpcChildWithModuleWorkerAndMessagePort extends Ipc {
|
|
379
|
-
getData(event) {
|
|
380
|
-
return getData$2(event);
|
|
381
|
-
}
|
|
382
|
-
send(message) {
|
|
383
|
-
this._rawIpc.postMessage(message);
|
|
384
|
-
}
|
|
385
|
-
sendAndTransfer(message) {
|
|
386
|
-
const transfer = getTransferrables(message);
|
|
387
|
-
this._rawIpc.postMessage(message, transfer);
|
|
388
|
-
}
|
|
389
|
-
dispose() {
|
|
390
|
-
if (this._rawIpc.close) {
|
|
391
|
-
this._rawIpc.close();
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
onClose(callback) {
|
|
395
|
-
// ignore
|
|
396
|
-
}
|
|
397
|
-
onMessage(callback) {
|
|
398
|
-
this._rawIpc.addEventListener('message', callback);
|
|
399
|
-
this._rawIpc.start();
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
const wrap$e = port => {
|
|
403
|
-
return new IpcChildWithModuleWorkerAndMessagePort(port);
|
|
404
|
-
};
|
|
405
|
-
const IpcChildWithModuleWorkerAndMessagePort$1 = {
|
|
306
|
+
const IpcChildWithModuleWorker$1 = {
|
|
406
307
|
__proto__: null,
|
|
407
|
-
listen: listen$
|
|
408
|
-
|
|
308
|
+
listen: listen$7,
|
|
309
|
+
signal: signal$8,
|
|
310
|
+
wrap: wrap$f
|
|
409
311
|
};
|
|
410
312
|
const addListener = (emitter, type, callback) => {
|
|
411
313
|
if ('addEventListener' in emitter) {
|
|
@@ -737,7 +639,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
|
|
|
737
639
|
const errorProperty = getErrorProperty(error, prettyError);
|
|
738
640
|
return create$1$1(id, errorProperty);
|
|
739
641
|
};
|
|
740
|
-
const create$
|
|
642
|
+
const create$8 = (message, result) => {
|
|
741
643
|
return {
|
|
742
644
|
id: message.id,
|
|
743
645
|
jsonrpc: Two$1,
|
|
@@ -746,7 +648,7 @@ const create$9 = (message, result) => {
|
|
|
746
648
|
};
|
|
747
649
|
const getSuccessResponse = (message, result) => {
|
|
748
650
|
const resultProperty = result ?? null;
|
|
749
|
-
return create$
|
|
651
|
+
return create$8(message, resultProperty);
|
|
750
652
|
};
|
|
751
653
|
const getErrorResponseSimple = (id, error) => {
|
|
752
654
|
return {
|
|
@@ -840,7 +742,7 @@ const handleJsonRpcMessage = async (...args) => {
|
|
|
840
742
|
|
|
841
743
|
const Two = '2.0';
|
|
842
744
|
|
|
843
|
-
const create$
|
|
745
|
+
const create$7 = (method, params) => {
|
|
844
746
|
return {
|
|
845
747
|
jsonrpc: Two,
|
|
846
748
|
method,
|
|
@@ -848,7 +750,7 @@ const create$8 = (method, params) => {
|
|
|
848
750
|
};
|
|
849
751
|
};
|
|
850
752
|
|
|
851
|
-
const create$
|
|
753
|
+
const create$6 = (id, method, params) => {
|
|
852
754
|
const message = {
|
|
853
755
|
id,
|
|
854
756
|
jsonrpc: Two,
|
|
@@ -859,12 +761,12 @@ const create$7 = (id, method, params) => {
|
|
|
859
761
|
};
|
|
860
762
|
|
|
861
763
|
let id = 0;
|
|
862
|
-
const create$
|
|
764
|
+
const create$5 = () => {
|
|
863
765
|
return ++id;
|
|
864
766
|
};
|
|
865
767
|
|
|
866
768
|
const registerPromise = map => {
|
|
867
|
-
const id = create$
|
|
769
|
+
const id = create$5();
|
|
868
770
|
const {
|
|
869
771
|
promise,
|
|
870
772
|
resolve
|
|
@@ -881,7 +783,7 @@ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer)
|
|
|
881
783
|
id,
|
|
882
784
|
promise
|
|
883
785
|
} = registerPromise(callbacks);
|
|
884
|
-
const message = create$
|
|
786
|
+
const message = create$6(id, method, params);
|
|
885
787
|
if (useSendAndTransfer && ipc.sendAndTransfer) {
|
|
886
788
|
ipc.sendAndTransfer(message);
|
|
887
789
|
} else {
|
|
@@ -917,7 +819,7 @@ const createRpc = ipc => {
|
|
|
917
819
|
* @deprecated
|
|
918
820
|
*/
|
|
919
821
|
send(method, ...params) {
|
|
920
|
-
const message = create$
|
|
822
|
+
const message = create$7(method, params);
|
|
921
823
|
ipc.send(message);
|
|
922
824
|
}
|
|
923
825
|
};
|
|
@@ -957,7 +859,7 @@ const listen$1 = async (module, options) => {
|
|
|
957
859
|
return ipc;
|
|
958
860
|
};
|
|
959
861
|
|
|
960
|
-
const create$
|
|
862
|
+
const create$4 = async ({
|
|
961
863
|
commandMap,
|
|
962
864
|
isMessagePortOpen = true,
|
|
963
865
|
messagePort
|
|
@@ -975,7 +877,7 @@ const create$5 = async ({
|
|
|
975
877
|
return rpc;
|
|
976
878
|
};
|
|
977
879
|
|
|
978
|
-
const create$
|
|
880
|
+
const create$3 = async ({
|
|
979
881
|
commandMap,
|
|
980
882
|
isMessagePortOpen,
|
|
981
883
|
send
|
|
@@ -985,7 +887,7 @@ const create$4 = async ({
|
|
|
985
887
|
port2
|
|
986
888
|
} = new MessageChannel();
|
|
987
889
|
await send(port1);
|
|
988
|
-
return create$
|
|
890
|
+
return create$4({
|
|
989
891
|
commandMap,
|
|
990
892
|
isMessagePortOpen,
|
|
991
893
|
messagePort: port2
|
|
@@ -1020,13 +922,13 @@ const createSharedLazyRpc = factory => {
|
|
|
1020
922
|
};
|
|
1021
923
|
};
|
|
1022
924
|
|
|
1023
|
-
const create$
|
|
925
|
+
const create$2 = async ({
|
|
1024
926
|
commandMap,
|
|
1025
927
|
isMessagePortOpen,
|
|
1026
928
|
send
|
|
1027
929
|
}) => {
|
|
1028
930
|
return createSharedLazyRpc(() => {
|
|
1029
|
-
return create$
|
|
931
|
+
return create$3({
|
|
1030
932
|
commandMap,
|
|
1031
933
|
isMessagePortOpen,
|
|
1032
934
|
send
|
|
@@ -1034,26 +936,12 @@ const create$3 = async ({
|
|
|
1034
936
|
});
|
|
1035
937
|
};
|
|
1036
938
|
|
|
1037
|
-
const create$2 = async ({
|
|
1038
|
-
commandMap,
|
|
1039
|
-
messagePort
|
|
1040
|
-
}) => {
|
|
1041
|
-
// TODO create a commandMap per rpc instance
|
|
1042
|
-
register(commandMap);
|
|
1043
|
-
const ipc = await listen$1(IpcChildWithMessagePort$1, {
|
|
1044
|
-
port: messagePort
|
|
1045
|
-
});
|
|
1046
|
-
handleIpc(ipc);
|
|
1047
|
-
const rpc = createRpc(ipc);
|
|
1048
|
-
return rpc;
|
|
1049
|
-
};
|
|
1050
|
-
|
|
1051
939
|
const create$1 = async ({
|
|
1052
940
|
commandMap
|
|
1053
941
|
}) => {
|
|
1054
942
|
// TODO create a commandMap per rpc instance
|
|
1055
943
|
register(commandMap);
|
|
1056
|
-
const ipc = await listen$1(
|
|
944
|
+
const ipc = await listen$1(IpcChildWithModuleWorker$1);
|
|
1057
945
|
handleIpc(ipc);
|
|
1058
946
|
const rpc = createRpc(ipc);
|
|
1059
947
|
return rpc;
|
|
@@ -1080,7 +968,7 @@ const createMockRpc = ({
|
|
|
1080
968
|
};
|
|
1081
969
|
|
|
1082
970
|
const rpcs = Object.create(null);
|
|
1083
|
-
const set$
|
|
971
|
+
const set$2 = (id, rpc) => {
|
|
1084
972
|
rpcs[id] = rpc;
|
|
1085
973
|
};
|
|
1086
974
|
const get = id => {
|
|
@@ -1113,7 +1001,7 @@ const create = rpcId => {
|
|
|
1113
1001
|
const mockRpc = createMockRpc({
|
|
1114
1002
|
commandMap
|
|
1115
1003
|
});
|
|
1116
|
-
set$
|
|
1004
|
+
set$2(rpcId, mockRpc);
|
|
1117
1005
|
// @ts-ignore
|
|
1118
1006
|
mockRpc[Symbol.dispose] = () => {
|
|
1119
1007
|
remove(rpcId);
|
|
@@ -1122,14 +1010,14 @@ const create = rpcId => {
|
|
|
1122
1010
|
return mockRpc;
|
|
1123
1011
|
},
|
|
1124
1012
|
set(rpc) {
|
|
1125
|
-
set$
|
|
1013
|
+
set$2(rpcId, rpc);
|
|
1126
1014
|
}
|
|
1127
1015
|
};
|
|
1128
1016
|
};
|
|
1129
1017
|
|
|
1130
1018
|
const {
|
|
1131
1019
|
invoke: invoke$2,
|
|
1132
|
-
set: set$
|
|
1020
|
+
set: set$1
|
|
1133
1021
|
} = create(6040);
|
|
1134
1022
|
|
|
1135
1023
|
const Electron = 2;
|
|
@@ -1139,50 +1027,48 @@ const RendererWorker = 1;
|
|
|
1139
1027
|
|
|
1140
1028
|
const {
|
|
1141
1029
|
invoke: invoke$1,
|
|
1142
|
-
set
|
|
1030
|
+
set
|
|
1143
1031
|
} = create(OpenerWorker);
|
|
1144
1032
|
|
|
1145
1033
|
const {
|
|
1146
1034
|
invoke,
|
|
1147
|
-
invokeAndTransfer
|
|
1148
|
-
set
|
|
1149
|
-
} = create(RendererWorker);
|
|
1035
|
+
invokeAndTransfer} = create(RendererWorker);
|
|
1150
1036
|
const sendMessagePortToOpenerWorker$1 = async (port, rpcId) => {
|
|
1151
1037
|
const command = 'HandleMessagePort.handleMessagePort';
|
|
1152
1038
|
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToOpenerWorker', port, command, rpcId);
|
|
1153
1039
|
};
|
|
1154
|
-
const sendMessagePortToSharedProcess = async port => {
|
|
1155
|
-
const command = 'HandleElectronMessagePort.handleElectronMessagePort';
|
|
1156
|
-
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToSharedProcess', port, command, 0);
|
|
1157
|
-
};
|
|
1158
1040
|
|
|
1159
1041
|
const sendMessagePortToAuthProcess = async port => {
|
|
1160
|
-
await sendMessagePortToSharedProcess
|
|
1042
|
+
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToSharedProcess', port, 'HandleMessagePortForAuthProcess.handleMessagePortForAuthProcess');
|
|
1161
1043
|
};
|
|
1162
1044
|
const initializeAuthProcess = async () => {
|
|
1163
|
-
const rpc = await create$
|
|
1045
|
+
const rpc = await create$2({
|
|
1164
1046
|
commandMap: {},
|
|
1165
1047
|
send: sendMessagePortToAuthProcess
|
|
1166
1048
|
});
|
|
1167
|
-
set$
|
|
1049
|
+
set$1(rpc);
|
|
1168
1050
|
};
|
|
1169
1051
|
|
|
1170
1052
|
const sendMessagePortToOpenerWorker = async port => {
|
|
1171
1053
|
await sendMessagePortToOpenerWorker$1(port, 0);
|
|
1172
1054
|
};
|
|
1173
1055
|
const initializeOpenerWorker = async () => {
|
|
1174
|
-
const rpc = await create$
|
|
1056
|
+
const rpc = await create$2({
|
|
1175
1057
|
commandMap: {},
|
|
1176
1058
|
send: sendMessagePortToOpenerWorker
|
|
1177
1059
|
});
|
|
1178
|
-
set
|
|
1060
|
+
set(rpc);
|
|
1179
1061
|
};
|
|
1180
1062
|
|
|
1181
|
-
const handleMessagePort = async port => {
|
|
1182
|
-
await create$
|
|
1063
|
+
const handleMessagePort = async (port, rpcId) => {
|
|
1064
|
+
const rpc = await create$4({
|
|
1183
1065
|
commandMap: commandMap,
|
|
1066
|
+
isMessagePortOpen: true,
|
|
1184
1067
|
messagePort: port
|
|
1185
1068
|
});
|
|
1069
|
+
if (rpcId) {
|
|
1070
|
+
set$2(rpcId, rpc);
|
|
1071
|
+
}
|
|
1186
1072
|
};
|
|
1187
1073
|
|
|
1188
1074
|
const initialize = async platform => {
|
|
@@ -1720,7 +1606,7 @@ const waitForElectronBackendLogin = async (backendUrl, uid, redirectUri, timeout
|
|
|
1720
1606
|
const started = Date.now();
|
|
1721
1607
|
const deadline = started + timeoutMs;
|
|
1722
1608
|
while (Date.now() < deadline) {
|
|
1723
|
-
const authorizationCode = await invoke('OAuthServer.getCode', String(uid));
|
|
1609
|
+
const authorizationCode = await invoke$2('OAuthServer.getCode', String(uid));
|
|
1724
1610
|
if (hasAuthorizationCode(authorizationCode)) {
|
|
1725
1611
|
const elapsed = Date.now() - started;
|
|
1726
1612
|
const remainingTime = Math.max(0, timeoutMs - elapsed);
|
|
@@ -1808,14 +1694,14 @@ const commandMap = {
|
|
|
1808
1694
|
'Auth.setNextLoginResponse': setNextLoginResponse,
|
|
1809
1695
|
'Auth.setNextRefreshResponse': setNextRefreshResponse,
|
|
1810
1696
|
'Auth.syncBackendAuth': syncBackendAuth,
|
|
1811
|
-
'HandleMessagePort.handleMessagePort': handleMessagePort
|
|
1697
|
+
'HandleMessagePort.handleMessagePort': handleMessagePort,
|
|
1698
|
+
initialize: (_, port) => handleMessagePort(port, RendererWorker)
|
|
1812
1699
|
};
|
|
1813
1700
|
|
|
1814
1701
|
const initializeRendererWorker = async () => {
|
|
1815
|
-
|
|
1702
|
+
await create$1({
|
|
1816
1703
|
commandMap: commandMap
|
|
1817
1704
|
});
|
|
1818
|
-
set(rpc);
|
|
1819
1705
|
};
|
|
1820
1706
|
|
|
1821
1707
|
const listen = async () => {
|