@adobe/uix-core 0.7.0 → 0.7.1-nightly.20230115
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/constants.d.ts +2 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/index.js +136 -47
- package/dist/index.js.map +1 -1
- package/dist/object-simulator.d.ts +1 -1
- package/dist/object-simulator.d.ts.map +1 -1
- package/dist/object-walker.d.ts +2 -1
- package/dist/object-walker.d.ts.map +1 -1
- package/dist/tunnel/tunnel-messenger.d.ts +25 -0
- package/dist/tunnel/tunnel-messenger.d.ts.map +1 -0
- package/dist/tunnel/tunnel-messenger.test.d.ts +2 -0
- package/dist/tunnel/tunnel-messenger.test.d.ts.map +1 -0
- package/dist/tunnel/tunnel.d.ts +4 -0
- package/dist/tunnel/tunnel.d.ts.map +1 -1
- package/dist/value-assertions.d.ts +3 -0
- package/dist/value-assertions.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/constants.ts +5 -1
- package/src/object-simulator.test.ts +193 -0
- package/src/object-simulator.ts +12 -3
- package/src/object-walker.ts +45 -5
- package/src/tunnel/tunnel-messenger.test.ts +183 -0
- package/src/tunnel/tunnel-messenger.ts +99 -0
- package/src/tunnel/tunnel.test.ts +20 -5
- package/src/tunnel/tunnel.ts +22 -11
- package/src/value-assertions.ts +10 -0
- package/dist/tunnel/tunnel-message.d.ts +0 -19
- package/dist/tunnel/tunnel-message.d.ts.map +0 -1
- package/src/tunnel/tunnel-message.ts +0 -75
package/dist/constants.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** @internal */
|
|
2
2
|
export declare const NS_ROOT = "_$pg";
|
|
3
|
-
export declare const VERSION
|
|
3
|
+
export declare const VERSION: string;
|
|
4
|
+
export declare const BUILDMODE: string;
|
|
4
5
|
export declare const SYM_CLEANUP: unique symbol;
|
|
5
6
|
export declare const SYM_INTERNAL: unique symbol;
|
|
6
7
|
export declare const INIT_CALLBACK: string;
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAGA,gBAAgB;AAChB,eAAO,MAAM,OAAO,SAAS,CAAC;AAC9B,eAAO,MAAM,OAAO,QAAkB,CAAC;AACvC,eAAO,MAAM,SAAS,QAAoB,CAAC;AAC3C,eAAO,MAAM,WAAW,eAA+B,CAAC;AACxD,eAAO,MAAM,YAAY,eAAgC,CAAC;AAC1D,eAAO,MAAM,aAAa,QAAuB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -447,7 +447,7 @@ function makeNamespaceProxy(invoke, path = []) {
|
|
|
447
447
|
|
|
448
448
|
// src/constants.ts
|
|
449
449
|
var NS_ROOT = "_$pg";
|
|
450
|
-
var VERSION = "0.0
|
|
450
|
+
var VERSION = "0.7.0";
|
|
451
451
|
var INIT_CALLBACK = `${NS_ROOT}_init_cb`;
|
|
452
452
|
|
|
453
453
|
// src/value-assertions.ts
|
|
@@ -478,6 +478,13 @@ function isIframe(value) {
|
|
|
478
478
|
const { nodeName } = value;
|
|
479
479
|
return typeof nodeName === "string" && nodeName.toLowerCase() === "iframe";
|
|
480
480
|
}
|
|
481
|
+
function isObjectWithPrototype(value) {
|
|
482
|
+
if (!value || typeof value !== "object") {
|
|
483
|
+
return false;
|
|
484
|
+
}
|
|
485
|
+
const proto = Reflect.getPrototypeOf(value);
|
|
486
|
+
return proto !== Object.prototype;
|
|
487
|
+
}
|
|
481
488
|
|
|
482
489
|
// src/message-wrapper.ts
|
|
483
490
|
function wrap(message) {
|
|
@@ -504,28 +511,63 @@ function isWrapped(item) {
|
|
|
504
511
|
|
|
505
512
|
// src/object-walker.ts
|
|
506
513
|
var NOT_TRANSFORMED = Symbol.for("NOT_TRANSFORMED");
|
|
507
|
-
|
|
514
|
+
var CIRCULAR = "[[Circular]]";
|
|
515
|
+
function transformRecursive(transform, value, parent, _refs = /* @__PURE__ */ new WeakSet()) {
|
|
508
516
|
if (isPrimitive(value)) {
|
|
509
517
|
return value;
|
|
510
518
|
}
|
|
511
|
-
const transformed = transform(value);
|
|
519
|
+
const transformed = transform(value, parent);
|
|
512
520
|
if (transformed !== NOT_TRANSFORMED) {
|
|
513
521
|
return transformed;
|
|
514
522
|
}
|
|
515
523
|
if (isIterable(value)) {
|
|
516
524
|
const outArray = [];
|
|
517
525
|
for (const item of value) {
|
|
518
|
-
outArray.push(transformRecursive(transform, item));
|
|
526
|
+
outArray.push(transformRecursive(transform, item, void 0, _refs));
|
|
519
527
|
}
|
|
520
528
|
return outArray;
|
|
521
529
|
}
|
|
522
530
|
if (isPlainObject(value)) {
|
|
531
|
+
if (_refs.has(value)) {
|
|
532
|
+
return CIRCULAR;
|
|
533
|
+
}
|
|
534
|
+
_refs.add(value);
|
|
523
535
|
const outObj = {};
|
|
524
536
|
for (const key of Reflect.ownKeys(value)) {
|
|
525
537
|
Reflect.set(
|
|
526
538
|
outObj,
|
|
527
539
|
key,
|
|
528
|
-
transformRecursive(transform, Reflect.get(value, key))
|
|
540
|
+
transformRecursive(transform, Reflect.get(value, key), void 0, _refs)
|
|
541
|
+
);
|
|
542
|
+
}
|
|
543
|
+
return outObj;
|
|
544
|
+
}
|
|
545
|
+
if (isObjectWithPrototype(value)) {
|
|
546
|
+
if (_refs.has(value)) {
|
|
547
|
+
return CIRCULAR;
|
|
548
|
+
}
|
|
549
|
+
_refs.add(value);
|
|
550
|
+
const getObjectKeys = (obj) => {
|
|
551
|
+
const result = /* @__PURE__ */ new Set();
|
|
552
|
+
do {
|
|
553
|
+
if (Reflect.getPrototypeOf(obj) !== null) {
|
|
554
|
+
for (const prop of Object.getOwnPropertyNames(obj)) {
|
|
555
|
+
if (prop === "constructor") {
|
|
556
|
+
continue;
|
|
557
|
+
}
|
|
558
|
+
result.add(prop);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
} while (obj = Reflect.getPrototypeOf(obj));
|
|
562
|
+
return [...result];
|
|
563
|
+
};
|
|
564
|
+
const outObj = {};
|
|
565
|
+
const properties = getObjectKeys(value);
|
|
566
|
+
for (const key of properties) {
|
|
567
|
+
Reflect.set(
|
|
568
|
+
outObj,
|
|
569
|
+
key,
|
|
570
|
+
transformRecursive(transform, Reflect.get(value, key), value, _refs)
|
|
529
571
|
);
|
|
530
572
|
}
|
|
531
573
|
return outObj;
|
|
@@ -722,7 +764,7 @@ var ObjectSimulator = class {
|
|
|
722
764
|
simulator = new ObjectSimulator(subject, cleanupNotifier);
|
|
723
765
|
return simulator;
|
|
724
766
|
}
|
|
725
|
-
makeReceiver(fn) {
|
|
767
|
+
makeReceiver(fn, parent) {
|
|
726
768
|
if (typeof fn !== "function") {
|
|
727
769
|
return NOT_TRANSFORMED;
|
|
728
770
|
}
|
|
@@ -731,9 +773,17 @@ var ObjectSimulator = class {
|
|
|
731
773
|
fnTicket = {
|
|
732
774
|
fnId: `${fn.name || "<anonymous>"}_${++this.fnCounter}`
|
|
733
775
|
};
|
|
734
|
-
|
|
776
|
+
let boundFunction = fn;
|
|
777
|
+
if (parent) {
|
|
778
|
+
boundFunction = fn.bind(parent);
|
|
779
|
+
}
|
|
780
|
+
const cleanup = receiveCalls(
|
|
781
|
+
boundFunction,
|
|
782
|
+
fnTicket,
|
|
783
|
+
new WeakRef(this.subject)
|
|
784
|
+
);
|
|
735
785
|
this.subject.onOutOfScope(fnTicket, cleanup);
|
|
736
|
-
this.receiverTicketCache.set(
|
|
786
|
+
this.receiverTicketCache.set(boundFunction, fnTicket);
|
|
737
787
|
}
|
|
738
788
|
return wrap(fnTicket);
|
|
739
789
|
}
|
|
@@ -796,46 +846,74 @@ var INIT_TICKET = {
|
|
|
796
846
|
// src/tunnel/tunnel.ts
|
|
797
847
|
var import_eventemitter3 = __toESM(require_eventemitter3());
|
|
798
848
|
|
|
799
|
-
// src/tunnel/tunnel-
|
|
800
|
-
var
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
}
|
|
807
|
-
function makeOffered(id) {
|
|
808
|
-
return wrap({
|
|
809
|
-
offers: id,
|
|
810
|
-
version: VERSION
|
|
811
|
-
});
|
|
812
|
-
}
|
|
813
|
-
function isHandshakeAccepting(message, id) {
|
|
814
|
-
return isHandshake(message) && unwrap(message).accepts === id;
|
|
815
|
-
}
|
|
816
|
-
function isHandshakeOffer(message) {
|
|
817
|
-
return isHandshake(message) && typeof unwrap(message).offers === "string";
|
|
818
|
-
}
|
|
819
|
-
function isHandshake(message) {
|
|
820
|
-
if (!isWrapped(message)) {
|
|
821
|
-
return false;
|
|
849
|
+
// src/tunnel/tunnel-messenger.ts
|
|
850
|
+
var TunnelMessenger = class {
|
|
851
|
+
constructor(opts) {
|
|
852
|
+
this.versionWarnings = /* @__PURE__ */ new Set();
|
|
853
|
+
this.myOrigin = opts.myOrigin;
|
|
854
|
+
this.remoteOrigin = opts.targetOrigin === "*" ? "remote document" : opts.targetOrigin;
|
|
855
|
+
this.logger = opts.logger;
|
|
822
856
|
}
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
857
|
+
resetWarnings() {
|
|
858
|
+
this.versionWarnings.clear();
|
|
859
|
+
}
|
|
860
|
+
makeAccepted(id) {
|
|
861
|
+
return wrap({
|
|
862
|
+
accepts: id,
|
|
863
|
+
version: VERSION
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
makeOffered(id) {
|
|
867
|
+
return wrap({
|
|
868
|
+
offers: id,
|
|
869
|
+
version: VERSION
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
isHandshakeAccepting(message, id) {
|
|
873
|
+
return this.isHandshake(message) && unwrap(message).accepts === id;
|
|
874
|
+
}
|
|
875
|
+
isHandshakeOffer(message) {
|
|
876
|
+
return this.isHandshake(message) && typeof unwrap(message).offers === "string";
|
|
877
|
+
}
|
|
878
|
+
isHandshake(message) {
|
|
879
|
+
if (!isWrapped(message)) {
|
|
880
|
+
this.logMalformed(message);
|
|
881
|
+
return false;
|
|
882
|
+
}
|
|
883
|
+
const tunnelData = unwrap(
|
|
884
|
+
message
|
|
827
885
|
);
|
|
828
|
-
|
|
886
|
+
if (!isPlainObject(tunnelData) || typeof tunnelData.version !== "string" || !(Reflect.has(tunnelData, "accepts") || Reflect.has(tunnelData, "offers"))) {
|
|
887
|
+
this.logMalformed(message);
|
|
888
|
+
return false;
|
|
889
|
+
}
|
|
890
|
+
const { version } = tunnelData;
|
|
891
|
+
if (version !== VERSION && !this.versionWarnings.has(version)) {
|
|
892
|
+
this.versionWarnings.add(version);
|
|
893
|
+
this.logger.warn(
|
|
894
|
+
`SDK version mismatch. ${this.myOrigin} is using v${VERSION}, but received message from ${this.remoteOrigin} using SDK v${version}. Extensions may be broken or unresponsive.`
|
|
895
|
+
);
|
|
896
|
+
}
|
|
897
|
+
return true;
|
|
829
898
|
}
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
899
|
+
logMalformed(message) {
|
|
900
|
+
let inspectedMessage;
|
|
901
|
+
try {
|
|
902
|
+
inspectedMessage = JSON.stringify(message, null, 2);
|
|
903
|
+
} catch (_) {
|
|
904
|
+
try {
|
|
905
|
+
inspectedMessage = message.toString();
|
|
906
|
+
} catch (e) {
|
|
907
|
+
inspectedMessage = Object.prototype.toString.call(message);
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
this.logger.error(
|
|
911
|
+
`Malformed tunnel message sent from SDK at ${this.remoteOrigin} to ${this.myOrigin}:
|
|
912
|
+
${inspectedMessage}
|
|
913
|
+
Message must be an object with "${NS_ROOT}" property, which must be an object with a "version" string and an either an "accepts" or "offers" property containing an ID string.`
|
|
835
914
|
);
|
|
836
915
|
}
|
|
837
|
-
|
|
838
|
-
}
|
|
916
|
+
};
|
|
839
917
|
|
|
840
918
|
// src/tunnel/tunnel.ts
|
|
841
919
|
var RETRY_MS = 100;
|
|
@@ -876,11 +954,16 @@ var Tunnel = class extends import_eventemitter3.default {
|
|
|
876
954
|
const source = target.contentWindow;
|
|
877
955
|
const config = Tunnel._normalizeConfig(options);
|
|
878
956
|
const tunnel = new Tunnel(config);
|
|
957
|
+
const messenger = new TunnelMessenger({
|
|
958
|
+
myOrigin: window.location.origin,
|
|
959
|
+
targetOrigin: options.targetOrigin,
|
|
960
|
+
logger: options.logger || console
|
|
961
|
+
});
|
|
879
962
|
let frameStatusCheck;
|
|
880
963
|
let timeout;
|
|
881
964
|
const offerListener = (event) => {
|
|
882
|
-
if (isFromOrigin(event, source, config.targetOrigin) && isHandshakeOffer(event.data)) {
|
|
883
|
-
const accepted = makeAccepted(unwrap(event.data).offers);
|
|
965
|
+
if (isFromOrigin(event, source, config.targetOrigin) && messenger.isHandshakeOffer(event.data)) {
|
|
966
|
+
const accepted = messenger.makeAccepted(unwrap(event.data).offers);
|
|
884
967
|
const channel = new MessageChannel();
|
|
885
968
|
source.postMessage(accepted, config.targetOrigin, [channel.port1]);
|
|
886
969
|
tunnel.connect(channel.port2);
|
|
@@ -916,8 +999,13 @@ var Tunnel = class extends import_eventemitter3.default {
|
|
|
916
999
|
const key = makeKey();
|
|
917
1000
|
const config = Tunnel._normalizeConfig(opts);
|
|
918
1001
|
const tunnel = new Tunnel(config);
|
|
1002
|
+
const messenger = new TunnelMessenger({
|
|
1003
|
+
myOrigin: window.location.origin,
|
|
1004
|
+
targetOrigin: config.targetOrigin,
|
|
1005
|
+
logger: config.logger
|
|
1006
|
+
});
|
|
919
1007
|
const acceptListener = (event) => {
|
|
920
|
-
if (isFromOrigin(event, source, config.targetOrigin) && isHandshakeAccepting(event.data, key)) {
|
|
1008
|
+
if (isFromOrigin(event, source, config.targetOrigin) && messenger.isHandshakeAccepting(event.data, key)) {
|
|
921
1009
|
cleanup();
|
|
922
1010
|
if (!event.ports || !event.ports.length) {
|
|
923
1011
|
const portError = new Error(
|
|
@@ -946,7 +1034,7 @@ var Tunnel = class extends import_eventemitter3.default {
|
|
|
946
1034
|
window.addEventListener("message", acceptListener);
|
|
947
1035
|
tunnel.on("destroyed", cleanup);
|
|
948
1036
|
tunnel.on("connected", cleanup);
|
|
949
|
-
const sendOffer = () => source.postMessage(makeOffered(key), config.targetOrigin);
|
|
1037
|
+
const sendOffer = () => source.postMessage(messenger.makeOffered(key), config.targetOrigin);
|
|
950
1038
|
retrying = window.setInterval(sendOffer, RETRY_MS);
|
|
951
1039
|
sendOffer();
|
|
952
1040
|
return tunnel;
|
|
@@ -980,6 +1068,7 @@ var Tunnel = class extends import_eventemitter3.default {
|
|
|
980
1068
|
let errorMessage = "";
|
|
981
1069
|
const config = {
|
|
982
1070
|
timeout: 4e3,
|
|
1071
|
+
logger: console,
|
|
983
1072
|
...options
|
|
984
1073
|
};
|
|
985
1074
|
const timeoutMs = Number(config.timeout);
|