@archilogic/extension-sdk 0.3.0 → 0.5.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/CHANGELOG.md +17 -0
- package/dist/extension-sdk.js +348 -278
- package/dist/index.d.ts +2808 -213
- package/package.json +2 -2
package/dist/extension-sdk.js
CHANGED
|
@@ -1,231 +1,231 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
1
|
+
var Re = Object.defineProperty;
|
|
2
|
+
var se = (e) => {
|
|
3
3
|
throw TypeError(e);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var s = (e, t, r) => (
|
|
8
|
-
var
|
|
5
|
+
var Ne = (e, t, r) => t in e ? Re(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
6
|
+
var y = (e, t, r) => Ne(e, typeof t != "symbol" ? t + "" : t, r), ae = (e, t, r) => t.has(e) || se("Cannot " + r);
|
|
7
|
+
var s = (e, t, r) => (ae(e, t, "read from private field"), r ? r.call(e) : t.get(e)), d = (e, t, r) => t.has(e) ? se("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, r), M = (e, t, r, n) => (ae(e, t, "write to private field"), n ? n.call(e, r) : t.set(e, r), r);
|
|
8
|
+
var _e = class extends Error {
|
|
9
9
|
constructor(t, r) {
|
|
10
10
|
super(r);
|
|
11
|
-
|
|
11
|
+
y(this, "code");
|
|
12
12
|
this.name = "PenpalError", this.code = t;
|
|
13
13
|
}
|
|
14
|
-
}, w =
|
|
14
|
+
}, w = _e, ke = (e) => ({
|
|
15
15
|
name: e.name,
|
|
16
16
|
message: e.message,
|
|
17
17
|
stack: e.stack,
|
|
18
18
|
penpalCode: e instanceof w ? e.code : void 0
|
|
19
|
-
}),
|
|
19
|
+
}), Le = ({
|
|
20
20
|
name: e,
|
|
21
21
|
message: t,
|
|
22
22
|
stack: r,
|
|
23
|
-
penpalCode:
|
|
23
|
+
penpalCode: n
|
|
24
24
|
}) => {
|
|
25
|
-
const
|
|
26
|
-
return
|
|
27
|
-
},
|
|
25
|
+
const a = n ? new w(n, t) : new Error(t);
|
|
26
|
+
return a.name = e, a.stack = r, a;
|
|
27
|
+
}, Te = Symbol("Reply"), te, le, De = (le = class {
|
|
28
28
|
constructor(e, t) {
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
y(this, "value");
|
|
30
|
+
y(this, "transferables");
|
|
31
31
|
// Allows TypeScript to distinguish between an actual instance of this
|
|
32
32
|
// class versus an object that looks structurally similar.
|
|
33
33
|
// eslint-disable-next-line no-unused-private-class-members
|
|
34
|
-
|
|
34
|
+
d(this, te, Te);
|
|
35
35
|
this.value = e, this.transferables = t == null ? void 0 : t.transferables;
|
|
36
36
|
}
|
|
37
|
-
},
|
|
37
|
+
}, te = new WeakMap(), le), be = De, P = "penpal", X = (e) => typeof e == "object" && e !== null, ve = (e) => typeof e == "function", He = (e) => X(e) && e.namespace === P, H = (e) => e.type === "SYN", q = (e) => e.type === "ACK1", $ = (e) => e.type === "ACK2", ye = (e) => e.type === "CALL", Me = (e) => e.type === "REPLY", Oe = (e) => e.type === "DESTROY", we = (e, t = []) => {
|
|
38
38
|
const r = [];
|
|
39
|
-
for (const
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
...
|
|
39
|
+
for (const n of Object.keys(e)) {
|
|
40
|
+
const a = e[n];
|
|
41
|
+
ve(a) ? r.push([...t, n]) : X(a) && r.push(
|
|
42
|
+
...we(a, [...t, n])
|
|
43
43
|
);
|
|
44
44
|
}
|
|
45
45
|
return r;
|
|
46
|
-
},
|
|
46
|
+
}, xe = (e, t) => {
|
|
47
47
|
const r = e.reduce(
|
|
48
|
-
(
|
|
48
|
+
(n, a) => X(n) ? n[a] : void 0,
|
|
49
49
|
t
|
|
50
50
|
);
|
|
51
|
-
return
|
|
52
|
-
},
|
|
53
|
-
namespace:
|
|
51
|
+
return ve(r) ? r : void 0;
|
|
52
|
+
}, N = (e) => e.join("."), ie = (e, t, r) => ({
|
|
53
|
+
namespace: P,
|
|
54
54
|
channel: e,
|
|
55
55
|
type: "REPLY",
|
|
56
56
|
callId: t,
|
|
57
57
|
isError: !0,
|
|
58
|
-
...r instanceof Error ? { value:
|
|
59
|
-
}),
|
|
60
|
-
let
|
|
61
|
-
const
|
|
62
|
-
if (
|
|
58
|
+
...r instanceof Error ? { value: ke(r), isSerializedErrorInstance: !0 } : { value: r }
|
|
59
|
+
}), ge = (e, t, r, n) => {
|
|
60
|
+
let a = !1;
|
|
61
|
+
const h = async (l) => {
|
|
62
|
+
if (a || !ye(l))
|
|
63
63
|
return;
|
|
64
|
-
|
|
65
|
-
const { methodPath:
|
|
66
|
-
let i,
|
|
64
|
+
n == null || n(`Received ${N(l.methodPath)}() call`, l);
|
|
65
|
+
const { methodPath: p, args: u, id: o } = l;
|
|
66
|
+
let i, A;
|
|
67
67
|
try {
|
|
68
|
-
const
|
|
69
|
-
if (!
|
|
68
|
+
const f = xe(p, t);
|
|
69
|
+
if (!f)
|
|
70
70
|
throw new w(
|
|
71
71
|
"METHOD_NOT_FOUND",
|
|
72
|
-
`Method \`${
|
|
72
|
+
`Method \`${N(p)}\` is not found.`
|
|
73
73
|
);
|
|
74
|
-
let
|
|
75
|
-
|
|
76
|
-
namespace:
|
|
74
|
+
let v = await f(...u);
|
|
75
|
+
v instanceof be && (A = v.transferables, v = await v.value), i = {
|
|
76
|
+
namespace: P,
|
|
77
77
|
channel: r,
|
|
78
78
|
type: "REPLY",
|
|
79
79
|
callId: o,
|
|
80
|
-
value:
|
|
80
|
+
value: v
|
|
81
81
|
};
|
|
82
|
-
} catch (
|
|
83
|
-
i =
|
|
82
|
+
} catch (f) {
|
|
83
|
+
i = ie(r, o, f);
|
|
84
84
|
}
|
|
85
|
-
if (!
|
|
85
|
+
if (!a)
|
|
86
86
|
try {
|
|
87
|
-
|
|
88
|
-
} catch (
|
|
89
|
-
throw
|
|
87
|
+
n == null || n(`Sending ${N(p)}() reply`, i), e.sendMessage(i, A);
|
|
88
|
+
} catch (f) {
|
|
89
|
+
throw f.name === "DataCloneError" && (i = ie(r, o, f), n == null || n(`Sending ${N(p)}() reply`, i), e.sendMessage(i)), f;
|
|
90
90
|
}
|
|
91
91
|
};
|
|
92
|
-
return e.addMessageHandler(
|
|
93
|
-
|
|
92
|
+
return e.addMessageHandler(h), () => {
|
|
93
|
+
a = !0, e.removeMessageHandler(h);
|
|
94
94
|
};
|
|
95
|
-
},
|
|
95
|
+
}, Fe = ge, he, Ee = ((he = crypto.randomUUID) == null ? void 0 : he.bind(crypto)) ?? (() => new Array(4).fill(0).map(
|
|
96
96
|
() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)
|
|
97
|
-
).join("-")),
|
|
97
|
+
).join("-")), We = Symbol("CallOptions"), re, ue, Ye = (ue = class {
|
|
98
98
|
constructor(e) {
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
y(this, "transferables");
|
|
100
|
+
y(this, "timeout");
|
|
101
101
|
// Allows TypeScript to distinguish between an actual instance of this
|
|
102
102
|
// class versus an object that looks structurally similar.
|
|
103
103
|
// eslint-disable-next-line no-unused-private-class-members
|
|
104
|
-
|
|
104
|
+
d(this, re, We);
|
|
105
105
|
this.transferables = e == null ? void 0 : e.transferables, this.timeout = e == null ? void 0 : e.timeout;
|
|
106
106
|
}
|
|
107
|
-
},
|
|
107
|
+
}, re = new WeakMap(), ue), $e = Ye, Ue = /* @__PURE__ */ new Set(["apply", "call", "bind"]), Ie = (e, t, r = []) => new Proxy(
|
|
108
108
|
r.length ? () => {
|
|
109
109
|
} : /* @__PURE__ */ Object.create(null),
|
|
110
110
|
{
|
|
111
|
-
get(
|
|
112
|
-
if (
|
|
113
|
-
return r.length &&
|
|
111
|
+
get(n, a) {
|
|
112
|
+
if (a !== "then")
|
|
113
|
+
return r.length && Ue.has(a) ? Reflect.get(n, a) : Ie(e, t, [...r, a]);
|
|
114
114
|
},
|
|
115
|
-
apply(
|
|
116
|
-
return e(r,
|
|
115
|
+
apply(n, a, h) {
|
|
116
|
+
return e(r, h);
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
|
-
),
|
|
119
|
+
), oe = (e) => new w(
|
|
120
120
|
"CONNECTION_DESTROYED",
|
|
121
|
-
`Method call ${
|
|
121
|
+
`Method call ${N(
|
|
122
122
|
e
|
|
123
123
|
)}() failed due to destroyed connection`
|
|
124
|
-
),
|
|
125
|
-
let
|
|
126
|
-
const
|
|
127
|
-
if (!
|
|
124
|
+
), Ve = (e, t, r) => {
|
|
125
|
+
let n = !1;
|
|
126
|
+
const a = /* @__PURE__ */ new Map(), h = (u) => {
|
|
127
|
+
if (!Me(u))
|
|
128
128
|
return;
|
|
129
|
-
const { callId: o, value: i, isError:
|
|
130
|
-
|
|
131
|
-
`Received ${
|
|
132
|
-
|
|
133
|
-
),
|
|
134
|
-
|
|
135
|
-
) :
|
|
129
|
+
const { callId: o, value: i, isError: A, isSerializedErrorInstance: f } = u, v = a.get(o);
|
|
130
|
+
v && (a.delete(o), r == null || r(
|
|
131
|
+
`Received ${N(v.methodPath)}() call`,
|
|
132
|
+
u
|
|
133
|
+
), A ? v.reject(
|
|
134
|
+
f ? Le(i) : i
|
|
135
|
+
) : v.resolve(i));
|
|
136
136
|
};
|
|
137
|
-
return e.addMessageHandler(
|
|
138
|
-
remoteProxy:
|
|
139
|
-
if (
|
|
140
|
-
throw
|
|
141
|
-
const i =
|
|
142
|
-
return new Promise((
|
|
143
|
-
const
|
|
144
|
-
|
|
137
|
+
return e.addMessageHandler(h), {
|
|
138
|
+
remoteProxy: Ie((u, o) => {
|
|
139
|
+
if (n)
|
|
140
|
+
throw oe(u);
|
|
141
|
+
const i = Ee(), A = o[o.length - 1], f = A instanceof $e, { timeout: v, transferables: Q } = f ? A : {}, z = f ? o.slice(0, -1) : o;
|
|
142
|
+
return new Promise((G, Y) => {
|
|
143
|
+
const Z = v !== void 0 ? window.setTimeout(() => {
|
|
144
|
+
a.delete(i), Y(
|
|
145
145
|
new w(
|
|
146
146
|
"METHOD_CALL_TIMEOUT",
|
|
147
|
-
`Method call ${
|
|
148
|
-
|
|
149
|
-
)}() timed out after ${
|
|
147
|
+
`Method call ${N(
|
|
148
|
+
u
|
|
149
|
+
)}() timed out after ${v}ms`
|
|
150
150
|
)
|
|
151
151
|
);
|
|
152
|
-
},
|
|
153
|
-
|
|
152
|
+
}, v) : void 0;
|
|
153
|
+
a.set(i, { methodPath: u, resolve: G, reject: Y, timeoutId: Z });
|
|
154
154
|
try {
|
|
155
|
-
const
|
|
156
|
-
namespace:
|
|
155
|
+
const b = {
|
|
156
|
+
namespace: P,
|
|
157
157
|
channel: t,
|
|
158
158
|
type: "CALL",
|
|
159
159
|
id: i,
|
|
160
|
-
methodPath:
|
|
161
|
-
args:
|
|
160
|
+
methodPath: u,
|
|
161
|
+
args: z
|
|
162
162
|
};
|
|
163
|
-
r == null || r(`Sending ${
|
|
164
|
-
} catch (
|
|
165
|
-
|
|
166
|
-
new w("TRANSMISSION_FAILED",
|
|
163
|
+
r == null || r(`Sending ${N(u)}() call`, b), e.sendMessage(b, Q);
|
|
164
|
+
} catch (b) {
|
|
165
|
+
Y(
|
|
166
|
+
new w("TRANSMISSION_FAILED", b.message)
|
|
167
167
|
);
|
|
168
168
|
}
|
|
169
169
|
});
|
|
170
170
|
}, r),
|
|
171
171
|
destroy: () => {
|
|
172
|
-
|
|
173
|
-
for (const { methodPath:
|
|
174
|
-
clearTimeout(i), o(
|
|
175
|
-
|
|
172
|
+
n = !0, e.removeMessageHandler(h);
|
|
173
|
+
for (const { methodPath: u, reject: o, timeoutId: i } of a.values())
|
|
174
|
+
clearTimeout(i), o(oe(u));
|
|
175
|
+
a.clear();
|
|
176
176
|
}
|
|
177
177
|
};
|
|
178
|
-
},
|
|
178
|
+
}, je = Ve, Ke = () => {
|
|
179
179
|
let e, t;
|
|
180
180
|
return {
|
|
181
|
-
promise: new Promise((
|
|
182
|
-
e =
|
|
181
|
+
promise: new Promise((n, a) => {
|
|
182
|
+
e = n, t = a;
|
|
183
183
|
}),
|
|
184
184
|
resolve: e,
|
|
185
185
|
reject: t
|
|
186
186
|
};
|
|
187
|
-
},
|
|
187
|
+
}, ze = Ke, Ge = class extends Error {
|
|
188
188
|
constructor(e) {
|
|
189
189
|
super(
|
|
190
190
|
`You've hit a bug in Penpal. Please file an issue with the following information: ${e}`
|
|
191
191
|
);
|
|
192
192
|
}
|
|
193
|
-
},
|
|
193
|
+
}, O = Ge, ee = "deprecated-penpal", Be = (e) => X(e) && "penpal" in e, Je = (e) => e.split("."), de = (e) => e.join("."), Pe = (e) => new O(
|
|
194
194
|
`Unexpected message to translate: ${JSON.stringify(e)}`
|
|
195
|
-
),
|
|
195
|
+
), Xe = (e) => {
|
|
196
196
|
if (e.penpal === "syn")
|
|
197
197
|
return {
|
|
198
|
-
namespace:
|
|
198
|
+
namespace: P,
|
|
199
199
|
channel: void 0,
|
|
200
200
|
type: "SYN",
|
|
201
|
-
participantId:
|
|
201
|
+
participantId: ee
|
|
202
202
|
};
|
|
203
203
|
if (e.penpal === "ack")
|
|
204
204
|
return {
|
|
205
|
-
namespace:
|
|
205
|
+
namespace: P,
|
|
206
206
|
channel: void 0,
|
|
207
207
|
type: "ACK2"
|
|
208
208
|
};
|
|
209
209
|
if (e.penpal === "call")
|
|
210
210
|
return {
|
|
211
|
-
namespace:
|
|
211
|
+
namespace: P,
|
|
212
212
|
channel: void 0,
|
|
213
213
|
type: "CALL",
|
|
214
214
|
// Actually converting the ID to a string would break communication.
|
|
215
215
|
id: e.id,
|
|
216
|
-
methodPath:
|
|
216
|
+
methodPath: Je(e.methodName),
|
|
217
217
|
args: e.args
|
|
218
218
|
};
|
|
219
219
|
if (e.penpal === "reply")
|
|
220
220
|
return e.resolution === "fulfilled" ? {
|
|
221
|
-
namespace:
|
|
221
|
+
namespace: P,
|
|
222
222
|
channel: void 0,
|
|
223
223
|
type: "REPLY",
|
|
224
224
|
// Actually converting the ID to a string would break communication.
|
|
225
225
|
callId: e.id,
|
|
226
226
|
value: e.returnValue
|
|
227
227
|
} : {
|
|
228
|
-
namespace:
|
|
228
|
+
namespace: P,
|
|
229
229
|
channel: void 0,
|
|
230
230
|
type: "REPLY",
|
|
231
231
|
// Actually converting the ID to a string would break communication.
|
|
@@ -238,22 +238,22 @@ var Pe = class extends Error {
|
|
|
238
238
|
value: e.returnValue
|
|
239
239
|
}
|
|
240
240
|
};
|
|
241
|
-
throw
|
|
242
|
-
},
|
|
243
|
-
if (
|
|
241
|
+
throw Pe(e);
|
|
242
|
+
}, qe = (e) => {
|
|
243
|
+
if (q(e))
|
|
244
244
|
return {
|
|
245
245
|
penpal: "synAck",
|
|
246
|
-
methodNames: e.methodPaths.map(
|
|
246
|
+
methodNames: e.methodPaths.map(de)
|
|
247
247
|
};
|
|
248
|
-
if (
|
|
248
|
+
if (ye(e))
|
|
249
249
|
return {
|
|
250
250
|
penpal: "call",
|
|
251
251
|
// Actually converting the ID to a number would break communication.
|
|
252
252
|
id: e.id,
|
|
253
|
-
methodName:
|
|
253
|
+
methodName: de(e.methodPath),
|
|
254
254
|
args: e.args
|
|
255
255
|
};
|
|
256
|
-
if (
|
|
256
|
+
if (Me(e))
|
|
257
257
|
return e.isError ? {
|
|
258
258
|
penpal: "reply",
|
|
259
259
|
// Actually converting the ID to a number would break communication.
|
|
@@ -270,112 +270,112 @@ var Pe = class extends Error {
|
|
|
270
270
|
resolution: "fulfilled",
|
|
271
271
|
returnValue: e.value
|
|
272
272
|
};
|
|
273
|
-
throw
|
|
274
|
-
},
|
|
273
|
+
throw Pe(e);
|
|
274
|
+
}, Qe = ({
|
|
275
275
|
messenger: e,
|
|
276
276
|
methods: t,
|
|
277
277
|
timeout: r,
|
|
278
|
-
channel:
|
|
279
|
-
log:
|
|
278
|
+
channel: n,
|
|
279
|
+
log: a
|
|
280
280
|
}) => {
|
|
281
|
-
const
|
|
281
|
+
const h = Ee();
|
|
282
282
|
let l;
|
|
283
|
-
const
|
|
284
|
-
let
|
|
285
|
-
const o =
|
|
286
|
-
|
|
283
|
+
const p = [];
|
|
284
|
+
let u = !1;
|
|
285
|
+
const o = we(t), { promise: i, resolve: A, reject: f } = ze(), v = r !== void 0 ? setTimeout(() => {
|
|
286
|
+
f(
|
|
287
287
|
new w(
|
|
288
288
|
"CONNECTION_TIMEOUT",
|
|
289
289
|
`Connection timed out after ${r}ms`
|
|
290
290
|
)
|
|
291
291
|
);
|
|
292
|
-
}, r) : void 0,
|
|
293
|
-
for (const c of
|
|
292
|
+
}, r) : void 0, Q = () => {
|
|
293
|
+
for (const c of p)
|
|
294
294
|
c();
|
|
295
|
-
},
|
|
296
|
-
if (
|
|
295
|
+
}, z = () => {
|
|
296
|
+
if (u)
|
|
297
297
|
return;
|
|
298
|
-
|
|
299
|
-
const { remoteProxy: c, destroy:
|
|
300
|
-
|
|
298
|
+
p.push(Fe(e, t, n, a));
|
|
299
|
+
const { remoteProxy: c, destroy: _ } = je(e, n, a);
|
|
300
|
+
p.push(_), clearTimeout(v), u = !0, A({
|
|
301
301
|
remoteProxy: c,
|
|
302
|
-
destroy:
|
|
302
|
+
destroy: Q
|
|
303
303
|
});
|
|
304
|
-
},
|
|
304
|
+
}, G = () => {
|
|
305
305
|
const c = {
|
|
306
|
-
namespace:
|
|
306
|
+
namespace: P,
|
|
307
307
|
type: "SYN",
|
|
308
|
-
channel:
|
|
309
|
-
participantId:
|
|
308
|
+
channel: n,
|
|
309
|
+
participantId: h
|
|
310
310
|
};
|
|
311
|
-
|
|
311
|
+
a == null || a("Sending handshake SYN", c);
|
|
312
312
|
try {
|
|
313
313
|
e.sendMessage(c);
|
|
314
|
-
} catch (
|
|
315
|
-
|
|
314
|
+
} catch (_) {
|
|
315
|
+
f(new w("TRANSMISSION_FAILED", _.message));
|
|
316
316
|
}
|
|
317
|
-
},
|
|
318
|
-
if (
|
|
319
|
-
l !==
|
|
320
|
-
l ===
|
|
317
|
+
}, Y = (c) => {
|
|
318
|
+
if (a == null || a("Received handshake SYN", c), c.participantId === l && // TODO: Used for backward-compatibility. Remove in next major version.
|
|
319
|
+
l !== ee || (l = c.participantId, G(), !(h > l || // TODO: Used for backward-compatibility. Remove in next major version.
|
|
320
|
+
l === ee)))
|
|
321
321
|
return;
|
|
322
|
-
const
|
|
323
|
-
namespace:
|
|
324
|
-
channel:
|
|
322
|
+
const B = {
|
|
323
|
+
namespace: P,
|
|
324
|
+
channel: n,
|
|
325
325
|
type: "ACK1",
|
|
326
326
|
methodPaths: o
|
|
327
327
|
};
|
|
328
|
-
|
|
328
|
+
a == null || a("Sending handshake ACK1", B);
|
|
329
329
|
try {
|
|
330
|
-
e.sendMessage(
|
|
331
|
-
} catch (
|
|
332
|
-
|
|
330
|
+
e.sendMessage(B);
|
|
331
|
+
} catch (Se) {
|
|
332
|
+
f(new w("TRANSMISSION_FAILED", Se.message));
|
|
333
333
|
return;
|
|
334
334
|
}
|
|
335
|
-
},
|
|
336
|
-
|
|
337
|
-
const
|
|
338
|
-
namespace:
|
|
339
|
-
channel:
|
|
335
|
+
}, Z = (c) => {
|
|
336
|
+
a == null || a("Received handshake ACK1", c);
|
|
337
|
+
const _ = {
|
|
338
|
+
namespace: P,
|
|
339
|
+
channel: n,
|
|
340
340
|
type: "ACK2"
|
|
341
341
|
};
|
|
342
|
-
|
|
342
|
+
a == null || a("Sending handshake ACK2", _);
|
|
343
343
|
try {
|
|
344
|
-
e.sendMessage(
|
|
345
|
-
} catch (
|
|
346
|
-
|
|
344
|
+
e.sendMessage(_);
|
|
345
|
+
} catch (B) {
|
|
346
|
+
f(new w("TRANSMISSION_FAILED", B.message));
|
|
347
347
|
return;
|
|
348
348
|
}
|
|
349
|
-
|
|
350
|
-
},
|
|
351
|
-
|
|
352
|
-
},
|
|
353
|
-
|
|
349
|
+
z();
|
|
350
|
+
}, b = (c) => {
|
|
351
|
+
a == null || a("Received handshake ACK2", c), z();
|
|
352
|
+
}, ne = (c) => {
|
|
353
|
+
H(c) && Y(c), q(c) && Z(c), $(c) && b(c);
|
|
354
354
|
};
|
|
355
|
-
return e.addMessageHandler(
|
|
356
|
-
},
|
|
355
|
+
return e.addMessageHandler(ne), p.push(() => e.removeMessageHandler(ne)), G(), i;
|
|
356
|
+
}, Ze = Qe, et = (e) => {
|
|
357
357
|
let t = !1, r;
|
|
358
|
-
return (...
|
|
359
|
-
},
|
|
358
|
+
return (...n) => (t || (t = !0, r = e(...n)), r);
|
|
359
|
+
}, tt = et, ce = /* @__PURE__ */ new WeakSet(), rt = ({
|
|
360
360
|
messenger: e,
|
|
361
361
|
methods: t = {},
|
|
362
362
|
timeout: r,
|
|
363
|
-
channel:
|
|
364
|
-
log:
|
|
363
|
+
channel: n,
|
|
364
|
+
log: a
|
|
365
365
|
}) => {
|
|
366
366
|
if (!e)
|
|
367
367
|
throw new w("INVALID_ARGUMENT", "messenger must be defined");
|
|
368
|
-
if (
|
|
368
|
+
if (ce.has(e))
|
|
369
369
|
throw new w(
|
|
370
370
|
"INVALID_ARGUMENT",
|
|
371
371
|
"A messenger can only be used for a single connection"
|
|
372
372
|
);
|
|
373
|
-
|
|
374
|
-
const
|
|
373
|
+
ce.add(e);
|
|
374
|
+
const h = [e.destroy], l = tt((o) => {
|
|
375
375
|
if (o) {
|
|
376
376
|
const i = {
|
|
377
|
-
namespace:
|
|
378
|
-
channel:
|
|
377
|
+
namespace: P,
|
|
378
|
+
channel: n,
|
|
379
379
|
type: "DESTROY"
|
|
380
380
|
};
|
|
381
381
|
try {
|
|
@@ -383,24 +383,24 @@ var Pe = class extends Error {
|
|
|
383
383
|
} catch {
|
|
384
384
|
}
|
|
385
385
|
}
|
|
386
|
-
for (const i of
|
|
386
|
+
for (const i of h)
|
|
387
387
|
i();
|
|
388
|
-
|
|
389
|
-
}),
|
|
388
|
+
a == null || a("Connection destroyed");
|
|
389
|
+
}), p = (o) => He(o) && o.channel === n;
|
|
390
390
|
return {
|
|
391
391
|
promise: (async () => {
|
|
392
392
|
try {
|
|
393
|
-
e.initialize({ log:
|
|
394
|
-
|
|
393
|
+
e.initialize({ log: a, validateReceivedMessage: p }), e.addMessageHandler((A) => {
|
|
394
|
+
Oe(A) && l(!1);
|
|
395
395
|
});
|
|
396
|
-
const { remoteProxy: o, destroy: i } = await
|
|
396
|
+
const { remoteProxy: o, destroy: i } = await Ze({
|
|
397
397
|
messenger: e,
|
|
398
398
|
methods: t,
|
|
399
399
|
timeout: r,
|
|
400
|
-
channel:
|
|
401
|
-
log:
|
|
400
|
+
channel: n,
|
|
401
|
+
log: a
|
|
402
402
|
});
|
|
403
|
-
return
|
|
403
|
+
return h.push(i), o;
|
|
404
404
|
} catch (o) {
|
|
405
405
|
throw l(!0), o;
|
|
406
406
|
}
|
|
@@ -411,145 +411,213 @@ var Pe = class extends Error {
|
|
|
411
411
|
l(!0);
|
|
412
412
|
}
|
|
413
413
|
};
|
|
414
|
-
},
|
|
414
|
+
}, Ae = rt, C, k, x, g, L, m, E, T, J, F, U, V, W, fe, nt = (fe = class {
|
|
415
415
|
constructor({ remoteWindow: e, allowedOrigins: t }) {
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
416
|
+
d(this, C);
|
|
417
|
+
d(this, k);
|
|
418
|
+
d(this, x);
|
|
419
|
+
d(this, g);
|
|
420
|
+
d(this, L);
|
|
421
|
+
d(this, m, /* @__PURE__ */ new Set());
|
|
422
|
+
d(this, E);
|
|
423
423
|
// TODO: Used for backward-compatibility. Remove in next major version.
|
|
424
|
-
|
|
425
|
-
|
|
424
|
+
d(this, T, !1);
|
|
425
|
+
y(this, "initialize", ({
|
|
426
426
|
log: e,
|
|
427
427
|
validateReceivedMessage: t
|
|
428
428
|
}) => {
|
|
429
|
-
|
|
429
|
+
M(this, x, e), M(this, g, t), window.addEventListener("message", s(this, V));
|
|
430
430
|
});
|
|
431
|
-
|
|
432
|
-
if (
|
|
433
|
-
const r = s(this,
|
|
434
|
-
s(this,
|
|
431
|
+
y(this, "sendMessage", (e, t) => {
|
|
432
|
+
if (H(e)) {
|
|
433
|
+
const r = s(this, F).call(this, e);
|
|
434
|
+
s(this, C).postMessage(e, {
|
|
435
435
|
targetOrigin: r,
|
|
436
436
|
transfer: t
|
|
437
437
|
});
|
|
438
438
|
return;
|
|
439
439
|
}
|
|
440
|
-
if (
|
|
440
|
+
if (q(e) || // If the child is using a previous version of Penpal, we need to
|
|
441
441
|
// downgrade the message and send it through the window rather than
|
|
442
442
|
// the port because older versions of Penpal don't use MessagePorts.
|
|
443
|
-
s(this,
|
|
444
|
-
const r = s(this,
|
|
445
|
-
s(this,
|
|
446
|
-
targetOrigin:
|
|
443
|
+
s(this, T)) {
|
|
444
|
+
const r = s(this, T) ? qe(e) : e, n = s(this, F).call(this, e);
|
|
445
|
+
s(this, C).postMessage(r, {
|
|
446
|
+
targetOrigin: n,
|
|
447
447
|
transfer: t
|
|
448
448
|
});
|
|
449
449
|
return;
|
|
450
450
|
}
|
|
451
|
-
if (
|
|
452
|
-
const { port1: r, port2:
|
|
453
|
-
|
|
454
|
-
const
|
|
455
|
-
s(this,
|
|
456
|
-
targetOrigin:
|
|
457
|
-
transfer:
|
|
451
|
+
if ($(e)) {
|
|
452
|
+
const { port1: r, port2: n } = new MessageChannel();
|
|
453
|
+
M(this, E, r), r.addEventListener("message", s(this, W)), r.start();
|
|
454
|
+
const a = [n, ...t || []], h = s(this, F).call(this, e);
|
|
455
|
+
s(this, C).postMessage(e, {
|
|
456
|
+
targetOrigin: h,
|
|
457
|
+
transfer: a
|
|
458
458
|
});
|
|
459
459
|
return;
|
|
460
460
|
}
|
|
461
|
-
if (s(this,
|
|
462
|
-
s(this,
|
|
461
|
+
if (s(this, E)) {
|
|
462
|
+
s(this, E).postMessage(e, {
|
|
463
463
|
transfer: t
|
|
464
464
|
});
|
|
465
465
|
return;
|
|
466
466
|
}
|
|
467
|
-
throw new
|
|
467
|
+
throw new O("Port is undefined");
|
|
468
468
|
});
|
|
469
|
-
|
|
470
|
-
s(this,
|
|
469
|
+
y(this, "addMessageHandler", (e) => {
|
|
470
|
+
s(this, m).add(e);
|
|
471
471
|
});
|
|
472
|
-
|
|
473
|
-
s(this,
|
|
472
|
+
y(this, "removeMessageHandler", (e) => {
|
|
473
|
+
s(this, m).delete(e);
|
|
474
474
|
});
|
|
475
|
-
|
|
476
|
-
window.removeEventListener("message", s(this,
|
|
475
|
+
y(this, "destroy", () => {
|
|
476
|
+
window.removeEventListener("message", s(this, V)), s(this, U).call(this), s(this, m).clear();
|
|
477
477
|
});
|
|
478
|
-
|
|
478
|
+
d(this, J, (e) => s(this, k).some(
|
|
479
479
|
(t) => t instanceof RegExp ? t.test(e) : t === e || t === "*"
|
|
480
480
|
));
|
|
481
|
-
|
|
482
|
-
if (
|
|
481
|
+
d(this, F, (e) => {
|
|
482
|
+
if (H(e))
|
|
483
483
|
return "*";
|
|
484
|
-
if (!s(this,
|
|
485
|
-
throw new
|
|
486
|
-
return s(this,
|
|
484
|
+
if (!s(this, L))
|
|
485
|
+
throw new O("Concrete remote origin not set");
|
|
486
|
+
return s(this, L) === "null" && s(this, k).includes("*") ? "*" : s(this, L);
|
|
487
487
|
});
|
|
488
|
-
|
|
488
|
+
d(this, U, () => {
|
|
489
489
|
var e, t;
|
|
490
|
-
(e = s(this,
|
|
490
|
+
(e = s(this, E)) == null || e.removeEventListener("message", s(this, W)), (t = s(this, E)) == null || t.close(), M(this, E, void 0);
|
|
491
491
|
});
|
|
492
|
-
|
|
492
|
+
d(this, V, ({
|
|
493
493
|
source: e,
|
|
494
494
|
origin: t,
|
|
495
495
|
ports: r,
|
|
496
|
-
data:
|
|
496
|
+
data: n
|
|
497
497
|
}) => {
|
|
498
|
-
var
|
|
499
|
-
if (e === s(this,
|
|
498
|
+
var a, h, l;
|
|
499
|
+
if (e === s(this, C) && (Be(n) && ((a = s(this, x)) == null || a.call(
|
|
500
500
|
this,
|
|
501
501
|
"Please upgrade the child window to the latest version of Penpal."
|
|
502
|
-
),
|
|
503
|
-
if (!s(this,
|
|
504
|
-
(l = s(this,
|
|
502
|
+
), M(this, T, !0), n = Xe(n)), !!((h = s(this, g)) != null && h.call(this, n)))) {
|
|
503
|
+
if (!s(this, J).call(this, t)) {
|
|
504
|
+
(l = s(this, x)) == null || l.call(
|
|
505
505
|
this,
|
|
506
|
-
`Received a message from origin \`${t}\` which did not match allowed origins \`[${s(this,
|
|
506
|
+
`Received a message from origin \`${t}\` which did not match allowed origins \`[${s(this, k).join(", ")}]\``
|
|
507
507
|
);
|
|
508
508
|
return;
|
|
509
509
|
}
|
|
510
|
-
if (
|
|
510
|
+
if (H(n) && (s(this, U).call(this), M(this, L, t)), $(n) && // Previous versions of Penpal don't use MessagePorts and do all
|
|
511
511
|
// communication through the window.
|
|
512
|
-
!s(this,
|
|
513
|
-
if (
|
|
514
|
-
throw new
|
|
515
|
-
s(this,
|
|
512
|
+
!s(this, T)) {
|
|
513
|
+
if (M(this, E, r[0]), !s(this, E))
|
|
514
|
+
throw new O("No port received on ACK2");
|
|
515
|
+
s(this, E).addEventListener("message", s(this, W)), s(this, E).start();
|
|
516
516
|
}
|
|
517
|
-
for (const
|
|
518
|
-
|
|
517
|
+
for (const p of s(this, m))
|
|
518
|
+
p(n);
|
|
519
519
|
}
|
|
520
520
|
});
|
|
521
|
-
|
|
521
|
+
d(this, W, ({ data: e }) => {
|
|
522
522
|
var t;
|
|
523
|
-
if ((t = s(this,
|
|
524
|
-
for (const r of s(this,
|
|
523
|
+
if ((t = s(this, g)) != null && t.call(this, e))
|
|
524
|
+
for (const r of s(this, m))
|
|
525
525
|
r(e);
|
|
526
526
|
});
|
|
527
527
|
if (!e)
|
|
528
528
|
throw new w("INVALID_ARGUMENT", "remoteWindow must be defined");
|
|
529
|
-
|
|
529
|
+
M(this, C, e), M(this, k, t != null && t.length ? t : [window.origin]);
|
|
530
530
|
}
|
|
531
|
-
},
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
531
|
+
}, C = new WeakMap(), k = new WeakMap(), x = new WeakMap(), g = new WeakMap(), L = new WeakMap(), m = new WeakMap(), E = new WeakMap(), T = new WeakMap(), J = new WeakMap(), F = new WeakMap(), U = new WeakMap(), V = new WeakMap(), W = new WeakMap(), fe), Ce = nt, S, j, D, I, K, R, pe, st = (pe = class {
|
|
532
|
+
constructor({ worker: e }) {
|
|
533
|
+
d(this, S);
|
|
534
|
+
d(this, j);
|
|
535
|
+
d(this, D, /* @__PURE__ */ new Set());
|
|
536
|
+
d(this, I);
|
|
537
|
+
y(this, "initialize", ({ validateReceivedMessage: e }) => {
|
|
538
|
+
M(this, j, e), s(this, S).addEventListener("message", s(this, R));
|
|
539
|
+
});
|
|
540
|
+
y(this, "sendMessage", (e, t) => {
|
|
541
|
+
if (H(e) || q(e)) {
|
|
542
|
+
s(this, S).postMessage(e, { transfer: t });
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
if ($(e)) {
|
|
546
|
+
const { port1: r, port2: n } = new MessageChannel();
|
|
547
|
+
M(this, I, r), r.addEventListener("message", s(this, R)), r.start(), s(this, S).postMessage(e, {
|
|
548
|
+
transfer: [n, ...t || []]
|
|
549
|
+
});
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
if (s(this, I)) {
|
|
553
|
+
s(this, I).postMessage(e, {
|
|
554
|
+
transfer: t
|
|
555
|
+
});
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
throw new O("Port is undefined");
|
|
559
|
+
});
|
|
560
|
+
y(this, "addMessageHandler", (e) => {
|
|
561
|
+
s(this, D).add(e);
|
|
562
|
+
});
|
|
563
|
+
y(this, "removeMessageHandler", (e) => {
|
|
564
|
+
s(this, D).delete(e);
|
|
565
|
+
});
|
|
566
|
+
y(this, "destroy", () => {
|
|
567
|
+
s(this, S).removeEventListener("message", s(this, R)), s(this, K).call(this), s(this, D).clear();
|
|
568
|
+
});
|
|
569
|
+
d(this, K, () => {
|
|
570
|
+
var e, t;
|
|
571
|
+
(e = s(this, I)) == null || e.removeEventListener("message", s(this, R)), (t = s(this, I)) == null || t.close(), M(this, I, void 0);
|
|
572
|
+
});
|
|
573
|
+
d(this, R, ({ ports: e, data: t }) => {
|
|
574
|
+
var r;
|
|
575
|
+
if ((r = s(this, j)) != null && r.call(this, t)) {
|
|
576
|
+
if (H(t) && s(this, K).call(this), $(t)) {
|
|
577
|
+
if (M(this, I, e[0]), !s(this, I))
|
|
578
|
+
throw new O("No port received on ACK2");
|
|
579
|
+
s(this, I).addEventListener("message", s(this, R)), s(this, I).start();
|
|
580
|
+
}
|
|
581
|
+
for (const n of s(this, D))
|
|
582
|
+
n(t);
|
|
583
|
+
}
|
|
584
|
+
});
|
|
585
|
+
if (!e)
|
|
586
|
+
throw new w("INVALID_ARGUMENT", "worker must be defined");
|
|
587
|
+
M(this, S, e);
|
|
588
|
+
}
|
|
589
|
+
}, S = new WeakMap(), j = new WeakMap(), D = new WeakMap(), I = new WeakMap(), K = new WeakMap(), R = new WeakMap(), pe), me = st;
|
|
590
|
+
const ot = (e, { iframe: t, worker: r }) => {
|
|
591
|
+
let n;
|
|
592
|
+
if (t)
|
|
593
|
+
n = new Ce({
|
|
594
|
+
remoteWindow: t.contentWindow,
|
|
595
|
+
// Defaults to the current origin.
|
|
596
|
+
allowedOrigins: [
|
|
597
|
+
/^http:\/\/localhost(:\d+)/,
|
|
598
|
+
"https://extensions.archilogic.io",
|
|
599
|
+
"https://testing-extensions.archilogic.io"
|
|
600
|
+
]
|
|
601
|
+
// Alternatively,
|
|
602
|
+
// allowedOrigins: [new Url(iframe.src).origin]
|
|
603
|
+
});
|
|
604
|
+
else if (r)
|
|
605
|
+
n = new me({ worker: r });
|
|
606
|
+
else
|
|
607
|
+
throw Error("No iframe or worker to connect to");
|
|
608
|
+
return Ae({
|
|
609
|
+
messenger: n,
|
|
546
610
|
// Methods the parent window is exposing to the iframe window.
|
|
547
|
-
methods:
|
|
611
|
+
methods: e
|
|
548
612
|
});
|
|
549
|
-
},
|
|
550
|
-
|
|
613
|
+
}, at = {
|
|
614
|
+
/**
|
|
615
|
+
* event handler for initial connection of the extension
|
|
616
|
+
* for a headless extension ( without UI ) the host will await this method before it terminates the extension
|
|
617
|
+
*/
|
|
618
|
+
onConnect: () => {
|
|
551
619
|
},
|
|
552
|
-
|
|
620
|
+
onDestroy: () => {
|
|
553
621
|
},
|
|
554
622
|
onLayoutChange: () => {
|
|
555
623
|
},
|
|
@@ -559,8 +627,9 @@ const Qe = (e, t) => {
|
|
|
559
627
|
},
|
|
560
628
|
onCanvasClick: () => {
|
|
561
629
|
}
|
|
562
|
-
},
|
|
563
|
-
|
|
630
|
+
}, dt = (e = {}, t) => {
|
|
631
|
+
let r;
|
|
632
|
+
t != null && t.useWorker ? r = new me({ worker: self }) : r = new Ce({
|
|
564
633
|
remoteWindow: window.parent,
|
|
565
634
|
// Defaults to the current origin.
|
|
566
635
|
allowedOrigins: [
|
|
@@ -568,21 +637,22 @@ const Qe = (e, t) => {
|
|
|
568
637
|
/^https:\/\/(.*)app.archilogic.com/,
|
|
569
638
|
/^https:\/\/(.*).archilogic-frontend.com/
|
|
570
639
|
]
|
|
571
|
-
})
|
|
572
|
-
|
|
640
|
+
});
|
|
641
|
+
const n = Ae({
|
|
642
|
+
messenger: r,
|
|
573
643
|
// Methods the iframe window is exposing to the parent window.
|
|
574
|
-
methods: { ...
|
|
644
|
+
methods: { ...at, ...e }
|
|
575
645
|
});
|
|
576
646
|
return new Proxy(
|
|
577
647
|
{},
|
|
578
648
|
{
|
|
579
|
-
get(
|
|
580
|
-
return async (...
|
|
649
|
+
get(h, l) {
|
|
650
|
+
return async (...p) => (await n.promise)[l](...p);
|
|
581
651
|
}
|
|
582
652
|
}
|
|
583
653
|
);
|
|
584
654
|
};
|
|
585
655
|
export {
|
|
586
|
-
|
|
587
|
-
|
|
656
|
+
ot as createExtensionConnection,
|
|
657
|
+
dt as createHostConnection
|
|
588
658
|
};
|