@lvce-editor/auth-worker 1.9.0 → 1.11.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 +54 -141
- 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$3 = (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$3(rpcId, mockRpc);
|
|
1117
1005
|
// @ts-ignore
|
|
1118
1006
|
mockRpc[Symbol.dispose] = () => {
|
|
1119
1007
|
remove(rpcId);
|
|
@@ -1122,11 +1010,16 @@ const create = rpcId => {
|
|
|
1122
1010
|
return mockRpc;
|
|
1123
1011
|
},
|
|
1124
1012
|
set(rpc) {
|
|
1125
|
-
set$
|
|
1013
|
+
set$3(rpcId, rpc);
|
|
1126
1014
|
}
|
|
1127
1015
|
};
|
|
1128
1016
|
};
|
|
1129
1017
|
|
|
1018
|
+
const {
|
|
1019
|
+
invoke: invoke$2,
|
|
1020
|
+
set: set$2
|
|
1021
|
+
} = create(6040);
|
|
1022
|
+
|
|
1130
1023
|
const Electron = 2;
|
|
1131
1024
|
|
|
1132
1025
|
const OpenerWorker = 4561;
|
|
@@ -1146,23 +1039,42 @@ const sendMessagePortToOpenerWorker$1 = async (port, rpcId) => {
|
|
|
1146
1039
|
const command = 'HandleMessagePort.handleMessagePort';
|
|
1147
1040
|
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToOpenerWorker', port, command, rpcId);
|
|
1148
1041
|
};
|
|
1042
|
+
const sendMessagePortToSharedProcess = async port => {
|
|
1043
|
+
const command = 'HandleElectronMessagePort.handleElectronMessagePort';
|
|
1044
|
+
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToSharedProcess', port, command, 0);
|
|
1045
|
+
};
|
|
1046
|
+
|
|
1047
|
+
const sendMessagePortToAuthProcess = async port => {
|
|
1048
|
+
await sendMessagePortToSharedProcess(port);
|
|
1049
|
+
};
|
|
1050
|
+
const initializeAuthProcess = async () => {
|
|
1051
|
+
const rpc = await create$2({
|
|
1052
|
+
commandMap: {},
|
|
1053
|
+
send: sendMessagePortToAuthProcess
|
|
1054
|
+
});
|
|
1055
|
+
set$2(rpc);
|
|
1056
|
+
};
|
|
1149
1057
|
|
|
1150
1058
|
const sendMessagePortToOpenerWorker = async port => {
|
|
1151
1059
|
await sendMessagePortToOpenerWorker$1(port, 0);
|
|
1152
1060
|
};
|
|
1153
1061
|
const initializeOpenerWorker = async () => {
|
|
1154
|
-
const rpc = await create$
|
|
1062
|
+
const rpc = await create$2({
|
|
1155
1063
|
commandMap: {},
|
|
1156
1064
|
send: sendMessagePortToOpenerWorker
|
|
1157
1065
|
});
|
|
1158
1066
|
set$1(rpc);
|
|
1159
1067
|
};
|
|
1160
1068
|
|
|
1161
|
-
const handleMessagePort = async port => {
|
|
1162
|
-
await create$
|
|
1069
|
+
const handleMessagePort = async (port, rpcId) => {
|
|
1070
|
+
const rpc = await create$4({
|
|
1163
1071
|
commandMap: commandMap,
|
|
1072
|
+
isMessagePortOpen: true,
|
|
1164
1073
|
messagePort: port
|
|
1165
1074
|
});
|
|
1075
|
+
if (rpcId) {
|
|
1076
|
+
set$3(rpcId, rpc);
|
|
1077
|
+
}
|
|
1166
1078
|
};
|
|
1167
1079
|
|
|
1168
1080
|
const initialize = async platform => {
|
|
@@ -1613,8 +1525,8 @@ const errorHtml = `<!doctype html>
|
|
|
1613
1525
|
</body>
|
|
1614
1526
|
</html>`;
|
|
1615
1527
|
|
|
1616
|
-
const getElectronRedirectUri = async
|
|
1617
|
-
const localOauthServerPort = await invoke('OAuthServer.create', String(uid), successHtml, errorHtml);
|
|
1528
|
+
const getElectronRedirectUri = async uid => {
|
|
1529
|
+
const localOauthServerPort = await invoke$2('OAuthServer.create', String(uid), successHtml, errorHtml);
|
|
1618
1530
|
return `http://localhost:${localOauthServerPort}`;
|
|
1619
1531
|
};
|
|
1620
1532
|
|
|
@@ -1623,7 +1535,7 @@ const getEffectiveRedirectUri = async (platform, uid, redirectUri) => {
|
|
|
1623
1535
|
return redirectUri;
|
|
1624
1536
|
}
|
|
1625
1537
|
if (platform === Electron) {
|
|
1626
|
-
return getElectronRedirectUri(uid
|
|
1538
|
+
return getElectronRedirectUri(uid);
|
|
1627
1539
|
}
|
|
1628
1540
|
return getCurrentHref();
|
|
1629
1541
|
};
|
|
@@ -1788,7 +1700,8 @@ const commandMap = {
|
|
|
1788
1700
|
'Auth.setNextLoginResponse': setNextLoginResponse,
|
|
1789
1701
|
'Auth.setNextRefreshResponse': setNextRefreshResponse,
|
|
1790
1702
|
'Auth.syncBackendAuth': syncBackendAuth,
|
|
1791
|
-
'HandleMessagePort.handleMessagePort': handleMessagePort
|
|
1703
|
+
'HandleMessagePort.handleMessagePort': handleMessagePort,
|
|
1704
|
+
initialize: (_, port) => handleMessagePort(port)
|
|
1792
1705
|
};
|
|
1793
1706
|
|
|
1794
1707
|
const initializeRendererWorker = async () => {
|
|
@@ -1799,7 +1712,7 @@ const initializeRendererWorker = async () => {
|
|
|
1799
1712
|
};
|
|
1800
1713
|
|
|
1801
1714
|
const listen = async () => {
|
|
1802
|
-
await Promise.all([initializeRendererWorker(), initializeOpenerWorker()]);
|
|
1715
|
+
await Promise.all([initializeRendererWorker(), initializeOpenerWorker(), initializeAuthProcess()]);
|
|
1803
1716
|
};
|
|
1804
1717
|
|
|
1805
1718
|
const main = async () => {
|