@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.
@@ -1,231 +1,231 @@
1
- var we = Object.defineProperty;
2
- var Q = (e) => {
1
+ var Re = Object.defineProperty;
2
+ var se = (e) => {
3
3
  throw TypeError(e);
4
4
  };
5
- var Ee = (e, t, r) => t in e ? we(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
6
- var P = (e, t, r) => Ee(e, typeof t != "symbol" ? t + "" : t, r), Z = (e, t, r) => t.has(e) || Q("Cannot " + r);
7
- var s = (e, t, r) => (Z(e, t, "read from private field"), r ? r.call(e) : t.get(e)), f = (e, t, r) => t.has(e) ? Q("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, r), I = (e, t, r, a) => (Z(e, t, "write to private field"), a ? a.call(e, r) : t.set(e, r), r);
8
- var Pe = class extends Error {
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
- P(this, "code");
11
+ y(this, "code");
12
12
  this.name = "PenpalError", this.code = t;
13
13
  }
14
- }, w = Pe, Ie = (e) => ({
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
- }), Ae = ({
19
+ }), Le = ({
20
20
  name: e,
21
21
  message: t,
22
22
  stack: r,
23
- penpalCode: a
23
+ penpalCode: n
24
24
  }) => {
25
- const n = a ? new w(a, t) : new Error(t);
26
- return n.name = e, n.stack = r, n;
27
- }, Se = Symbol("Reply"), B, ae, Ce = (ae = class {
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
- P(this, "value");
30
- P(this, "transferables");
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
- f(this, B, Se);
34
+ d(this, te, Te);
35
35
  this.value = e, this.transferables = t == null ? void 0 : t.transferables;
36
36
  }
37
- }, B = new WeakMap(), ae), me = Ce, M = "penpal", W = (e) => typeof e == "object" && e !== null, ce = (e) => typeof e == "function", Re = (e) => W(e) && e.namespace === M, j = (e) => e.type === "SYN", X = (e) => e.type === "ACK1", z = (e) => e.type === "ACK2", de = (e) => e.type === "CALL", le = (e) => e.type === "REPLY", Ne = (e) => e.type === "DESTROY", ue = (e, t = []) => {
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 a of Object.keys(e)) {
40
- const n = e[a];
41
- ce(n) ? r.push([...t, a]) : W(n) && r.push(
42
- ...ue(n, [...t, a])
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
- }, _e = (e, t) => {
46
+ }, xe = (e, t) => {
47
47
  const r = e.reduce(
48
- (a, n) => W(a) ? a[n] : void 0,
48
+ (n, a) => X(n) ? n[a] : void 0,
49
49
  t
50
50
  );
51
- return ce(r) ? r : void 0;
52
- }, C = (e) => e.join("."), ee = (e, t, r) => ({
53
- namespace: M,
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: Ie(r), isSerializedErrorInstance: !0 } : { value: r }
59
- }), Te = (e, t, r, a) => {
60
- let n = !1;
61
- const d = async (l) => {
62
- if (n || !de(l))
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
- a == null || a(`Received ${C(l.methodPath)}() call`, l);
65
- const { methodPath: v, args: h, id: o } = l;
66
- let i, E;
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 u = _e(v, t);
69
- if (!u)
68
+ const f = xe(p, t);
69
+ if (!f)
70
70
  throw new w(
71
71
  "METHOD_NOT_FOUND",
72
- `Method \`${C(v)}\` is not found.`
72
+ `Method \`${N(p)}\` is not found.`
73
73
  );
74
- let p = await u(...h);
75
- p instanceof me && (E = p.transferables, p = await p.value), i = {
76
- namespace: M,
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: p
80
+ value: v
81
81
  };
82
- } catch (u) {
83
- i = ee(r, o, u);
82
+ } catch (f) {
83
+ i = ie(r, o, f);
84
84
  }
85
- if (!n)
85
+ if (!a)
86
86
  try {
87
- a == null || a(`Sending ${C(v)}() reply`, i), e.sendMessage(i, E);
88
- } catch (u) {
89
- throw u.name === "DataCloneError" && (i = ee(r, o, u), a == null || a(`Sending ${C(v)}() reply`, i), e.sendMessage(i)), u;
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(d), () => {
93
- n = !0, e.removeMessageHandler(d);
92
+ return e.addMessageHandler(h), () => {
93
+ a = !0, e.removeMessageHandler(h);
94
94
  };
95
- }, De = Te, se, he = ((se = crypto.randomUUID) == null ? void 0 : se.bind(crypto)) ?? (() => new Array(4).fill(0).map(
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("-")), Le = Symbol("CallOptions"), J, ie, ke = (ie = class {
97
+ ).join("-")), We = Symbol("CallOptions"), re, ue, Ye = (ue = class {
98
98
  constructor(e) {
99
- P(this, "transferables");
100
- P(this, "timeout");
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
- f(this, J, Le);
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
- }, J = new WeakMap(), ie), be = ke, Oe = /* @__PURE__ */ new Set(["apply", "call", "bind"]), pe = (e, t, r = []) => new Proxy(
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(a, n) {
112
- if (n !== "then")
113
- return r.length && Oe.has(n) ? Reflect.get(a, n) : pe(e, t, [...r, n]);
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(a, n, d) {
116
- return e(r, d);
115
+ apply(n, a, h) {
116
+ return e(r, h);
117
117
  }
118
118
  }
119
- ), te = (e) => new w(
119
+ ), oe = (e) => new w(
120
120
  "CONNECTION_DESTROYED",
121
- `Method call ${C(
121
+ `Method call ${N(
122
122
  e
123
123
  )}() failed due to destroyed connection`
124
- ), He = (e, t, r) => {
125
- let a = !1;
126
- const n = /* @__PURE__ */ new Map(), d = (h) => {
127
- if (!le(h))
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: E, isSerializedErrorInstance: u } = h, p = n.get(o);
130
- p && (n.delete(o), r == null || r(
131
- `Received ${C(p.methodPath)}() call`,
132
- h
133
- ), E ? p.reject(
134
- u ? Ae(i) : i
135
- ) : p.resolve(i));
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(d), {
138
- remoteProxy: pe((h, o) => {
139
- if (a)
140
- throw te(h);
141
- const i = he(), E = o[o.length - 1], u = E instanceof be, { timeout: p, transferables: g } = u ? E : {}, F = u ? o.slice(0, -1) : o;
142
- return new Promise((Y, O) => {
143
- const K = p !== void 0 ? window.setTimeout(() => {
144
- n.delete(i), O(
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 ${C(
148
- h
149
- )}() timed out after ${p}ms`
147
+ `Method call ${N(
148
+ u
149
+ )}() timed out after ${v}ms`
150
150
  )
151
151
  );
152
- }, p) : void 0;
153
- n.set(i, { methodPath: h, resolve: Y, reject: O, timeoutId: K });
152
+ }, v) : void 0;
153
+ a.set(i, { methodPath: u, resolve: G, reject: Y, timeoutId: Z });
154
154
  try {
155
- const T = {
156
- namespace: M,
155
+ const b = {
156
+ namespace: P,
157
157
  channel: t,
158
158
  type: "CALL",
159
159
  id: i,
160
- methodPath: h,
161
- args: F
160
+ methodPath: u,
161
+ args: z
162
162
  };
163
- r == null || r(`Sending ${C(h)}() call`, T), e.sendMessage(T, g);
164
- } catch (T) {
165
- O(
166
- new w("TRANSMISSION_FAILED", T.message)
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
- a = !0, e.removeMessageHandler(d);
173
- for (const { methodPath: h, reject: o, timeoutId: i } of n.values())
174
- clearTimeout(i), o(te(h));
175
- n.clear();
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
- }, xe = He, Fe = () => {
178
+ }, je = Ve, Ke = () => {
179
179
  let e, t;
180
180
  return {
181
- promise: new Promise((a, n) => {
182
- e = a, t = n;
181
+ promise: new Promise((n, a) => {
182
+ e = n, t = a;
183
183
  }),
184
184
  resolve: e,
185
185
  reject: t
186
186
  };
187
- }, Ye = Fe, $e = class extends Error {
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
- }, U = $e, G = "deprecated-penpal", je = (e) => W(e) && "penpal" in e, Ue = (e) => e.split("."), re = (e) => e.join("."), fe = (e) => new U(
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
- ), Ve = (e) => {
195
+ ), Xe = (e) => {
196
196
  if (e.penpal === "syn")
197
197
  return {
198
- namespace: M,
198
+ namespace: P,
199
199
  channel: void 0,
200
200
  type: "SYN",
201
- participantId: G
201
+ participantId: ee
202
202
  };
203
203
  if (e.penpal === "ack")
204
204
  return {
205
- namespace: M,
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: M,
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: Ue(e.methodName),
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: M,
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: M,
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 fe(e);
242
- }, We = (e) => {
243
- if (X(e))
241
+ throw Pe(e);
242
+ }, qe = (e) => {
243
+ if (q(e))
244
244
  return {
245
245
  penpal: "synAck",
246
- methodNames: e.methodPaths.map(re)
246
+ methodNames: e.methodPaths.map(de)
247
247
  };
248
- if (de(e))
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: re(e.methodPath),
253
+ methodName: de(e.methodPath),
254
254
  args: e.args
255
255
  };
256
- if (le(e))
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 fe(e);
274
- }, ge = ({
273
+ throw Pe(e);
274
+ }, Qe = ({
275
275
  messenger: e,
276
276
  methods: t,
277
277
  timeout: r,
278
- channel: a,
279
- log: n
278
+ channel: n,
279
+ log: a
280
280
  }) => {
281
- const d = he();
281
+ const h = Ee();
282
282
  let l;
283
- const v = [];
284
- let h = !1;
285
- const o = ue(t), { promise: i, resolve: E, reject: u } = Ye(), p = r !== void 0 ? setTimeout(() => {
286
- u(
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, g = () => {
293
- for (const c of v)
292
+ }, r) : void 0, Q = () => {
293
+ for (const c of p)
294
294
  c();
295
- }, F = () => {
296
- if (h)
295
+ }, z = () => {
296
+ if (u)
297
297
  return;
298
- v.push(De(e, t, a, n));
299
- const { remoteProxy: c, destroy: m } = xe(e, a, n);
300
- v.push(m), clearTimeout(p), h = !0, E({
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: g
302
+ destroy: Q
303
303
  });
304
- }, Y = () => {
304
+ }, G = () => {
305
305
  const c = {
306
- namespace: M,
306
+ namespace: P,
307
307
  type: "SYN",
308
- channel: a,
309
- participantId: d
308
+ channel: n,
309
+ participantId: h
310
310
  };
311
- n == null || n("Sending handshake SYN", c);
311
+ a == null || a("Sending handshake SYN", c);
312
312
  try {
313
313
  e.sendMessage(c);
314
- } catch (m) {
315
- u(new w("TRANSMISSION_FAILED", m.message));
314
+ } catch (_) {
315
+ f(new w("TRANSMISSION_FAILED", _.message));
316
316
  }
317
- }, O = (c) => {
318
- if (n == null || n("Received handshake SYN", c), c.participantId === l && // TODO: Used for backward-compatibility. Remove in next major version.
319
- l !== G || (l = c.participantId, Y(), !(d > l || // TODO: Used for backward-compatibility. Remove in next major version.
320
- l === G)))
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: M,
324
- channel: a,
322
+ const B = {
323
+ namespace: P,
324
+ channel: n,
325
325
  type: "ACK1",
326
326
  methodPaths: o
327
327
  };
328
- n == null || n("Sending handshake ACK1", $);
328
+ a == null || a("Sending handshake ACK1", B);
329
329
  try {
330
- e.sendMessage($);
331
- } catch (Me) {
332
- u(new w("TRANSMISSION_FAILED", Me.message));
330
+ e.sendMessage(B);
331
+ } catch (Se) {
332
+ f(new w("TRANSMISSION_FAILED", Se.message));
333
333
  return;
334
334
  }
335
- }, K = (c) => {
336
- n == null || n("Received handshake ACK1", c);
337
- const m = {
338
- namespace: M,
339
- channel: a,
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
- n == null || n("Sending handshake ACK2", m);
342
+ a == null || a("Sending handshake ACK2", _);
343
343
  try {
344
- e.sendMessage(m);
345
- } catch ($) {
346
- u(new w("TRANSMISSION_FAILED", $.message));
344
+ e.sendMessage(_);
345
+ } catch (B) {
346
+ f(new w("TRANSMISSION_FAILED", B.message));
347
347
  return;
348
348
  }
349
- F();
350
- }, T = (c) => {
351
- n == null || n("Received handshake ACK2", c), F();
352
- }, q = (c) => {
353
- j(c) && O(c), X(c) && K(c), z(c) && T(c);
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(q), v.push(() => e.removeMessageHandler(q)), Y(), i;
356
- }, Ke = ge, ze = (e) => {
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 (...a) => (t || (t = !0, r = e(...a)), r);
359
- }, Ge = ze, ne = /* @__PURE__ */ new WeakSet(), Be = ({
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: a,
364
- log: n
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 (ne.has(e))
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
- ne.add(e);
374
- const d = [e.destroy], l = Ge((o) => {
373
+ ce.add(e);
374
+ const h = [e.destroy], l = tt((o) => {
375
375
  if (o) {
376
376
  const i = {
377
- namespace: M,
378
- channel: a,
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 d)
386
+ for (const i of h)
387
387
  i();
388
- n == null || n("Connection destroyed");
389
- }), v = (o) => Re(o) && o.channel === a;
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: n, validateReceivedMessage: v }), e.addMessageHandler((E) => {
394
- Ne(E) && l(!1);
393
+ e.initialize({ log: a, validateReceivedMessage: p }), e.addMessageHandler((A) => {
394
+ Oe(A) && l(!1);
395
395
  });
396
- const { remoteProxy: o, destroy: i } = await Ke({
396
+ const { remoteProxy: o, destroy: i } = await Ze({
397
397
  messenger: e,
398
398
  methods: t,
399
399
  timeout: r,
400
- channel: a,
401
- log: n
400
+ channel: n,
401
+ log: a
402
402
  });
403
- return d.push(i), o;
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
- }, ve = Be, A, R, D, L, N, S, y, _, V, k, H, x, b, oe, Je = (oe = class {
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
- f(this, A);
417
- f(this, R);
418
- f(this, D);
419
- f(this, L);
420
- f(this, N);
421
- f(this, S, /* @__PURE__ */ new Set());
422
- f(this, y);
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
- f(this, _, !1);
425
- P(this, "initialize", ({
424
+ d(this, T, !1);
425
+ y(this, "initialize", ({
426
426
  log: e,
427
427
  validateReceivedMessage: t
428
428
  }) => {
429
- I(this, D, e), I(this, L, t), window.addEventListener("message", s(this, x));
429
+ M(this, x, e), M(this, g, t), window.addEventListener("message", s(this, V));
430
430
  });
431
- P(this, "sendMessage", (e, t) => {
432
- if (j(e)) {
433
- const r = s(this, k).call(this, e);
434
- s(this, A).postMessage(e, {
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 (X(e) || // If the child is using a previous version of Penpal, we need to
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, _) ? We(e) : e, a = s(this, k).call(this, e);
445
- s(this, A).postMessage(r, {
446
- targetOrigin: a,
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 (z(e)) {
452
- const { port1: r, port2: a } = new MessageChannel();
453
- I(this, y, r), r.addEventListener("message", s(this, b)), r.start();
454
- const n = [a, ...t || []], d = s(this, k).call(this, e);
455
- s(this, A).postMessage(e, {
456
- targetOrigin: d,
457
- transfer: n
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, y)) {
462
- s(this, y).postMessage(e, {
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 U("Port is undefined");
467
+ throw new O("Port is undefined");
468
468
  });
469
- P(this, "addMessageHandler", (e) => {
470
- s(this, S).add(e);
469
+ y(this, "addMessageHandler", (e) => {
470
+ s(this, m).add(e);
471
471
  });
472
- P(this, "removeMessageHandler", (e) => {
473
- s(this, S).delete(e);
472
+ y(this, "removeMessageHandler", (e) => {
473
+ s(this, m).delete(e);
474
474
  });
475
- P(this, "destroy", () => {
476
- window.removeEventListener("message", s(this, x)), s(this, H).call(this), s(this, S).clear();
475
+ y(this, "destroy", () => {
476
+ window.removeEventListener("message", s(this, V)), s(this, U).call(this), s(this, m).clear();
477
477
  });
478
- f(this, V, (e) => s(this, R).some(
478
+ d(this, J, (e) => s(this, k).some(
479
479
  (t) => t instanceof RegExp ? t.test(e) : t === e || t === "*"
480
480
  ));
481
- f(this, k, (e) => {
482
- if (j(e))
481
+ d(this, F, (e) => {
482
+ if (H(e))
483
483
  return "*";
484
- if (!s(this, N))
485
- throw new U("Concrete remote origin not set");
486
- return s(this, N) === "null" && s(this, R).includes("*") ? "*" : s(this, N);
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
- f(this, H, () => {
488
+ d(this, U, () => {
489
489
  var e, t;
490
- (e = s(this, y)) == null || e.removeEventListener("message", s(this, b)), (t = s(this, y)) == null || t.close(), I(this, y, void 0);
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
- f(this, x, ({
492
+ d(this, V, ({
493
493
  source: e,
494
494
  origin: t,
495
495
  ports: r,
496
- data: a
496
+ data: n
497
497
  }) => {
498
- var n, d, l;
499
- if (e === s(this, A) && (je(a) && ((n = s(this, D)) == null || n.call(
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
- ), I(this, _, !0), a = Ve(a)), !!((d = s(this, L)) != null && d.call(this, a)))) {
503
- if (!s(this, V).call(this, t)) {
504
- (l = s(this, D)) == null || l.call(
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, R).join(", ")}]\``
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 (j(a) && (s(this, H).call(this), I(this, N, t)), z(a) && // Previous versions of Penpal don't use MessagePorts and do all
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 (I(this, y, r[0]), !s(this, y))
514
- throw new U("No port received on ACK2");
515
- s(this, y).addEventListener("message", s(this, b)), s(this, y).start();
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 v of s(this, S))
518
- v(a);
517
+ for (const p of s(this, m))
518
+ p(n);
519
519
  }
520
520
  });
521
- f(this, b, ({ data: e }) => {
521
+ d(this, W, ({ data: e }) => {
522
522
  var t;
523
- if ((t = s(this, L)) != null && t.call(this, e))
524
- for (const r of s(this, S))
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
- I(this, A, e), I(this, R, t != null && t.length ? t : [window.origin]);
529
+ M(this, C, e), M(this, k, t != null && t.length ? t : [window.origin]);
530
530
  }
531
- }, A = new WeakMap(), R = new WeakMap(), D = new WeakMap(), L = new WeakMap(), N = new WeakMap(), S = new WeakMap(), y = new WeakMap(), _ = new WeakMap(), V = new WeakMap(), k = new WeakMap(), H = new WeakMap(), x = new WeakMap(), b = new WeakMap(), oe), ye = Je;
532
- const Qe = (e, t) => {
533
- const r = new ye({
534
- remoteWindow: e.contentWindow,
535
- // Defaults to the current origin.
536
- allowedOrigins: [
537
- /^http:\/\/localhost(:\d+)/,
538
- "https://extensions.archilogic.io",
539
- "https://testing-extensions.archilogic.io"
540
- ]
541
- // Alternatively,
542
- // allowedOrigins: [new Url(iframe.src).origin]
543
- });
544
- return ve({
545
- messenger: r,
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: t
611
+ methods: e
548
612
  });
549
- }, Xe = {
550
- onPluginConnect: () => {
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
- onPluginDestroy: () => {
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
- }, Ze = (e = {}) => {
563
- const t = new ye({
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
- }), r = ve({
572
- messenger: t,
640
+ });
641
+ const n = Ae({
642
+ messenger: r,
573
643
  // Methods the iframe window is exposing to the parent window.
574
- methods: { ...Xe, ...e }
644
+ methods: { ...at, ...e }
575
645
  });
576
646
  return new Proxy(
577
647
  {},
578
648
  {
579
- get(n, d) {
580
- return async (...l) => (await r.promise)[d](...l);
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
- Qe as createExtensionConnection,
587
- Ze as createHostConnection
656
+ ot as createExtensionConnection,
657
+ dt as createHostConnection
588
658
  };