@adobe/uix-core 0.7.1-nightly.20230226 → 0.7.1-nightly.20230227
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/cross-realm-object.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +131 -32
- package/dist/index.js.map +1 -1
- package/dist/logging-formatters.d.ts +34 -0
- package/dist/logging-formatters.d.ts.map +1 -0
- package/dist/promises/timed.d.ts +2 -2
- package/dist/promises/timed.d.ts.map +1 -1
- package/dist/tunnel/tunnel.d.ts +3 -1
- package/dist/tunnel/tunnel.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/cross-realm-object.ts +6 -2
- package/src/index.ts +1 -0
- package/src/logging-formatters.ts +57 -0
- package/src/promises/timed.ts +13 -5
- package/src/tunnel/tunnel.test.ts +41 -19
- package/src/tunnel/tunnel.ts +87 -26
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cross-realm-object.d.ts","sourceRoot":"","sources":["../src/cross-realm-object.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAK/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAIlC;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,gBAAgB,CAAC,WAAW;IAC3C;;;;;OAKG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,YAAY,IAAI,OAAO,CAAC,WAAW,CAAC,CAAC;CACtC;
|
|
1
|
+
{"version":3,"file":"cross-realm-object.d.ts","sourceRoot":"","sources":["../src/cross-realm-object.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAK/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAIlC;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,gBAAgB,CAAC,WAAW;IAC3C;;;;;OAKG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,YAAY,IAAI,OAAO,CAAC,WAAW,CAAC,CAAC;CACtC;AAuDD;;;GAGG;AACH,wBAAsB,mBAAmB,CAAC,QAAQ,EAChD,aAAa,EAAE,OAAO,CAAC,YAAY,CAAC,EACpC,SAAS,EAAE,OAAO,GACjB,OAAO,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAGrC;AAED;;;GAGG;AACH,wBAAsB,aAAa,CAAC,QAAQ,EAC1C,KAAK,EAAE,iBAAiB,EACxB,aAAa,EAAE,OAAO,CAAC,YAAY,CAAC,EACpC,SAAS,EAAE,OAAO,GACjB,OAAO,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAGrC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from "./emitter";
|
|
|
8
8
|
export * from "./namespace-proxy";
|
|
9
9
|
export * from "./types";
|
|
10
10
|
export * from "./cross-realm-object";
|
|
11
|
+
export * from "./logging-formatters";
|
|
11
12
|
export * from "./promises";
|
|
12
13
|
export * from "./tunnel";
|
|
13
14
|
export type { Asynced } from "./object-walker";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAYA;;;GAGG;AAEH,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,SAAS,CAAC;AACxB,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,YAAY,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAYA;;;GAGG;AAEH,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,SAAS,CAAC;AACxB,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,YAAY,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -468,6 +468,9 @@ function isPrimitive(value) {
|
|
|
468
468
|
function isIterable(value) {
|
|
469
469
|
return Array.isArray(value);
|
|
470
470
|
}
|
|
471
|
+
function isFunction(value) {
|
|
472
|
+
return typeof value === "function";
|
|
473
|
+
}
|
|
471
474
|
function hasProp(value, prop) {
|
|
472
475
|
return !isPrimitive(value) && Reflect.has(value, prop);
|
|
473
476
|
}
|
|
@@ -816,17 +819,23 @@ var ObjectSimulator = class {
|
|
|
816
819
|
};
|
|
817
820
|
|
|
818
821
|
// src/promises/timed.ts
|
|
819
|
-
function timeoutPromise(
|
|
822
|
+
function timeoutPromise(describe, promise, ms, onReject) {
|
|
820
823
|
return new Promise((resolve, reject) => {
|
|
821
824
|
const cleanupAndReject = async (e) => {
|
|
822
825
|
try {
|
|
823
|
-
|
|
826
|
+
if (onReject) {
|
|
827
|
+
await onReject(e);
|
|
828
|
+
}
|
|
824
829
|
} finally {
|
|
825
830
|
reject(e);
|
|
826
831
|
}
|
|
827
832
|
};
|
|
828
833
|
const timeout = setTimeout(() => {
|
|
829
|
-
cleanupAndReject(
|
|
834
|
+
cleanupAndReject(
|
|
835
|
+
new Error(
|
|
836
|
+
`${typeof describe === "function" ? describe() : describe} timed out after ${ms}ms`
|
|
837
|
+
)
|
|
838
|
+
);
|
|
830
839
|
}, ms);
|
|
831
840
|
promise.then((result) => {
|
|
832
841
|
clearTimeout(timeout);
|
|
@@ -951,21 +960,47 @@ var Tunnel = class extends import_eventemitter3.default {
|
|
|
951
960
|
)}`
|
|
952
961
|
);
|
|
953
962
|
}
|
|
954
|
-
const source = target.contentWindow;
|
|
955
963
|
const config = Tunnel._normalizeConfig(options);
|
|
956
964
|
const tunnel = new Tunnel(config);
|
|
957
965
|
const messenger = new TunnelMessenger({
|
|
958
966
|
myOrigin: window.location.origin,
|
|
959
|
-
targetOrigin:
|
|
960
|
-
logger:
|
|
967
|
+
targetOrigin: config.targetOrigin,
|
|
968
|
+
logger: config.logger
|
|
961
969
|
});
|
|
970
|
+
tunnel.on(
|
|
971
|
+
"destroyed",
|
|
972
|
+
() => config.logger.log(
|
|
973
|
+
`Tunnel to iframe at ${config.targetOrigin} destroyed!`,
|
|
974
|
+
tunnel,
|
|
975
|
+
target
|
|
976
|
+
)
|
|
977
|
+
);
|
|
978
|
+
tunnel.on(
|
|
979
|
+
"connected",
|
|
980
|
+
() => config.logger.log(
|
|
981
|
+
`Tunnel to iframe at ${config.targetOrigin} connected!`,
|
|
982
|
+
tunnel,
|
|
983
|
+
target
|
|
984
|
+
)
|
|
985
|
+
);
|
|
986
|
+
tunnel.on(
|
|
987
|
+
"error",
|
|
988
|
+
(e) => config.logger.log(
|
|
989
|
+
`Tunnel to iframe at ${config.targetOrigin} error!`,
|
|
990
|
+
tunnel,
|
|
991
|
+
target,
|
|
992
|
+
e
|
|
993
|
+
)
|
|
994
|
+
);
|
|
962
995
|
let frameStatusCheck;
|
|
963
996
|
let timeout;
|
|
964
997
|
const offerListener = (event) => {
|
|
965
|
-
if (isFromOrigin(event,
|
|
998
|
+
if (!tunnel.isConnected && isFromOrigin(event, target.contentWindow, config.targetOrigin) && messenger.isHandshakeOffer(event.data)) {
|
|
966
999
|
const accepted = messenger.makeAccepted(unwrap(event.data).offers);
|
|
967
1000
|
const channel = new MessageChannel();
|
|
968
|
-
|
|
1001
|
+
target.contentWindow.postMessage(accepted, config.targetOrigin, [
|
|
1002
|
+
channel.port1
|
|
1003
|
+
]);
|
|
969
1004
|
tunnel.connect(channel.port2);
|
|
970
1005
|
}
|
|
971
1006
|
};
|
|
@@ -975,19 +1010,26 @@ var Tunnel = class extends import_eventemitter3.default {
|
|
|
975
1010
|
window.removeEventListener("message", offerListener);
|
|
976
1011
|
};
|
|
977
1012
|
timeout = window.setTimeout(() => {
|
|
978
|
-
tunnel.
|
|
979
|
-
"error",
|
|
1013
|
+
tunnel.abort(
|
|
980
1014
|
new Error(
|
|
981
|
-
`Timed out awaiting initial message from iframe after ${config.timeout}ms`
|
|
1015
|
+
`Timed out awaiting initial message from target iframe after ${config.timeout}ms`
|
|
982
1016
|
)
|
|
983
1017
|
);
|
|
984
|
-
tunnel.destroy();
|
|
985
1018
|
}, config.timeout);
|
|
986
1019
|
tunnel.on("destroyed", cleanup);
|
|
987
1020
|
tunnel.on("connected", () => clearTimeout(timeout));
|
|
988
1021
|
frameStatusCheck = window.setInterval(() => {
|
|
989
1022
|
if (!target.isConnected) {
|
|
990
|
-
|
|
1023
|
+
cleanup();
|
|
1024
|
+
if (tunnel.isConnected) {
|
|
1025
|
+
const frameDisconnectError = new Error(
|
|
1026
|
+
`Tunnel target iframe at ${tunnel.config.targetOrigin} was disconnected from the document!`
|
|
1027
|
+
);
|
|
1028
|
+
Object.assign(frameDisconnectError, { target });
|
|
1029
|
+
tunnel.abort(frameDisconnectError);
|
|
1030
|
+
} else {
|
|
1031
|
+
tunnel.destroy();
|
|
1032
|
+
}
|
|
991
1033
|
}
|
|
992
1034
|
}, STATUSCHECK_MS);
|
|
993
1035
|
window.addEventListener("message", offerListener);
|
|
@@ -996,16 +1038,29 @@ var Tunnel = class extends import_eventemitter3.default {
|
|
|
996
1038
|
static toParent(source, opts) {
|
|
997
1039
|
let retrying;
|
|
998
1040
|
let timeout;
|
|
1041
|
+
let timedOut = false;
|
|
999
1042
|
const key = makeKey();
|
|
1000
1043
|
const config = Tunnel._normalizeConfig(opts);
|
|
1001
1044
|
const tunnel = new Tunnel(config);
|
|
1045
|
+
tunnel.on(
|
|
1046
|
+
"destroyed",
|
|
1047
|
+
() => config.logger.log(`Tunnel ${key} to parent window destroyed!`, tunnel)
|
|
1048
|
+
);
|
|
1049
|
+
tunnel.on(
|
|
1050
|
+
"connected",
|
|
1051
|
+
() => config.logger.log(`Tunnel ${key} to parent window connected!`, tunnel)
|
|
1052
|
+
);
|
|
1053
|
+
tunnel.on(
|
|
1054
|
+
"error",
|
|
1055
|
+
(e) => config.logger.log(`Tunnel ${key} to parent window error!`, tunnel, e)
|
|
1056
|
+
);
|
|
1002
1057
|
const messenger = new TunnelMessenger({
|
|
1003
1058
|
myOrigin: window.location.origin,
|
|
1004
1059
|
targetOrigin: config.targetOrigin,
|
|
1005
1060
|
logger: config.logger
|
|
1006
1061
|
});
|
|
1007
1062
|
const acceptListener = (event) => {
|
|
1008
|
-
if (isFromOrigin(event, source, config.targetOrigin) && messenger.isHandshakeAccepting(event.data, key)) {
|
|
1063
|
+
if (!timedOut && isFromOrigin(event, source, config.targetOrigin) && messenger.isHandshakeAccepting(event.data, key)) {
|
|
1009
1064
|
cleanup();
|
|
1010
1065
|
if (!event.ports || !event.ports.length) {
|
|
1011
1066
|
const portError = new Error(
|
|
@@ -1023,18 +1078,29 @@ var Tunnel = class extends import_eventemitter3.default {
|
|
|
1023
1078
|
window.removeEventListener("message", acceptListener);
|
|
1024
1079
|
};
|
|
1025
1080
|
timeout = window.setTimeout(() => {
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1081
|
+
if (!timedOut) {
|
|
1082
|
+
timedOut = true;
|
|
1083
|
+
tunnel.abort(
|
|
1084
|
+
new Error(
|
|
1085
|
+
`Timed out waiting for initial response from parent after ${config.timeout}ms`
|
|
1086
|
+
)
|
|
1087
|
+
);
|
|
1088
|
+
}
|
|
1033
1089
|
}, config.timeout);
|
|
1034
1090
|
window.addEventListener("message", acceptListener);
|
|
1035
|
-
tunnel.on("destroyed",
|
|
1036
|
-
|
|
1037
|
-
|
|
1091
|
+
tunnel.on("destroyed", () => {
|
|
1092
|
+
cleanup();
|
|
1093
|
+
});
|
|
1094
|
+
tunnel.on("connected", () => {
|
|
1095
|
+
cleanup();
|
|
1096
|
+
});
|
|
1097
|
+
const sendOffer = () => {
|
|
1098
|
+
if (tunnel.isConnected) {
|
|
1099
|
+
clearInterval(retrying);
|
|
1100
|
+
} else {
|
|
1101
|
+
source.postMessage(messenger.makeOffered(key), config.targetOrigin);
|
|
1102
|
+
}
|
|
1103
|
+
};
|
|
1038
1104
|
retrying = window.setInterval(sendOffer, RETRY_MS);
|
|
1039
1105
|
sendOffer();
|
|
1040
1106
|
return tunnel;
|
|
@@ -1046,16 +1112,22 @@ var Tunnel = class extends import_eventemitter3.default {
|
|
|
1046
1112
|
}
|
|
1047
1113
|
this._messagePort = remote;
|
|
1048
1114
|
remote.addEventListener("message", this._emitFromMessage);
|
|
1049
|
-
this.
|
|
1115
|
+
this.emitLocal("connected");
|
|
1050
1116
|
this._messagePort.start();
|
|
1117
|
+
this.isConnected = true;
|
|
1118
|
+
}
|
|
1119
|
+
abort(error) {
|
|
1120
|
+
this.emitLocal("error", error);
|
|
1121
|
+
this.destroy(error);
|
|
1051
1122
|
}
|
|
1052
|
-
destroy() {
|
|
1123
|
+
destroy(e) {
|
|
1053
1124
|
if (this._messagePort) {
|
|
1054
1125
|
this._messagePort.close();
|
|
1055
1126
|
this._messagePort = null;
|
|
1127
|
+
this.isConnected = false;
|
|
1056
1128
|
}
|
|
1057
|
-
|
|
1058
|
-
this.
|
|
1129
|
+
const context = e ? [e] : [];
|
|
1130
|
+
this.emitLocal("destroyed", ...context);
|
|
1059
1131
|
}
|
|
1060
1132
|
emit(type, payload) {
|
|
1061
1133
|
if (!this._messagePort) {
|
|
@@ -1068,8 +1140,8 @@ var Tunnel = class extends import_eventemitter3.default {
|
|
|
1068
1140
|
let errorMessage = "";
|
|
1069
1141
|
const config = {
|
|
1070
1142
|
timeout: 4e3,
|
|
1071
|
-
|
|
1072
|
-
|
|
1143
|
+
...options,
|
|
1144
|
+
logger: options.logger || quietConsole
|
|
1073
1145
|
};
|
|
1074
1146
|
const timeoutMs = Number(config.timeout);
|
|
1075
1147
|
if (!Number.isSafeInteger(timeoutMs)) {
|
|
@@ -1122,7 +1194,9 @@ async function setupApiExchange(tunnel, apiToSend) {
|
|
|
1122
1194
|
unsubscribe();
|
|
1123
1195
|
if (!done) {
|
|
1124
1196
|
done = true;
|
|
1125
|
-
|
|
1197
|
+
if (e) {
|
|
1198
|
+
reject(e);
|
|
1199
|
+
}
|
|
1126
1200
|
}
|
|
1127
1201
|
};
|
|
1128
1202
|
tunnel.on("destroyed", destroy);
|
|
@@ -1132,7 +1206,9 @@ async function setupApiExchange(tunnel, apiToSend) {
|
|
|
1132
1206
|
);
|
|
1133
1207
|
}),
|
|
1134
1208
|
tunnel.config.timeout,
|
|
1135
|
-
() =>
|
|
1209
|
+
(e) => {
|
|
1210
|
+
tunnel.abort(e);
|
|
1211
|
+
}
|
|
1136
1212
|
);
|
|
1137
1213
|
}
|
|
1138
1214
|
async function connectParentWindow(tunnelOptions, apiToSend) {
|
|
@@ -1144,6 +1220,27 @@ async function connectIframe(frame, tunnelOptions, apiToSend) {
|
|
|
1144
1220
|
return setupApiExchange(tunnel, apiToSend);
|
|
1145
1221
|
}
|
|
1146
1222
|
|
|
1223
|
+
// src/logging-formatters.ts
|
|
1224
|
+
function formatHostMethodArgument(argument) {
|
|
1225
|
+
try {
|
|
1226
|
+
return JSON.stringify(argument, null, 2);
|
|
1227
|
+
} catch (e) {
|
|
1228
|
+
if (isIterable(argument)) {
|
|
1229
|
+
return `Iterable<${argument.length}>`;
|
|
1230
|
+
}
|
|
1231
|
+
if (isPrimitive(argument) || isFunction(argument)) {
|
|
1232
|
+
return `${argument}`;
|
|
1233
|
+
}
|
|
1234
|
+
return Object.prototype.toString.call(argument);
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
function formatHostMethodAddress(address) {
|
|
1238
|
+
const path = address.path?.length < 1 ? "<Missing method path!>" : address.path.join(".");
|
|
1239
|
+
const name = address.name || "<Missing method name!>";
|
|
1240
|
+
const args = address.args?.map(formatHostMethodArgument).join(",");
|
|
1241
|
+
return `host.${path}.${name}(${args})`;
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1147
1244
|
// src/promises/wait.ts
|
|
1148
1245
|
function wait(ms) {
|
|
1149
1246
|
return new Promise((resolve) => {
|
|
@@ -1157,6 +1254,8 @@ exports._customConsole = _customConsole;
|
|
|
1157
1254
|
exports.connectIframe = connectIframe;
|
|
1158
1255
|
exports.connectParentWindow = connectParentWindow;
|
|
1159
1256
|
exports.debugEmitter = debugEmitter;
|
|
1257
|
+
exports.formatHostMethodAddress = formatHostMethodAddress;
|
|
1258
|
+
exports.formatHostMethodArgument = formatHostMethodArgument;
|
|
1160
1259
|
exports.makeNamespaceProxy = makeNamespaceProxy;
|
|
1161
1260
|
exports.quietConsole = quietConsole;
|
|
1162
1261
|
exports.timeoutPromise = timeoutPromise;
|