@floegence/floe-webapp-boot 0.62.0 → 0.64.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,7 +1,10 @@
1
+ import type { FetchServerSentEventsOptions, ServerSentEvent } from './server-sent-events';
1
2
  import type { ConnectionSnapshot } from '@floegence/flowersec-core';
2
3
  import { type AcquisitionSource, ConnectedAcquisition } from './acquisition';
3
4
  import { ProxyBootstrapOwner } from './proxy-bootstrap';
4
5
  export interface AcquisitionConnectionLifecycle {
6
+ fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
7
+ events(input: RequestInfo | URL, options?: Omit<FetchServerSentEventsOptions, 'fetch'>): AsyncGenerator<ServerSentEvent>;
5
8
  synchronize(snapshot: ConnectionSnapshot): void;
6
9
  dispose(): void;
7
10
  }
@@ -1,22 +1,24 @@
1
- import { createSessionHealthMonitor as l } from "./session-health.js";
2
- import { clearAcquisitionSource as u, AcquisitionError as s, synchronizeAcquisitionSourceSnapshot as a } from "./acquisition.js";
3
- import { closeProxyBootstrap as f, synchronizeProxyBootstrap as d } from "./proxy-bootstrap.js";
4
- function m(n, e = {}) {
5
- let t = !1, r = null;
6
- const c = l();
1
+ import { createSessionHealthMonitor as u } from "./session-health.js";
2
+ import { clearAcquisitionSource as a, AcquisitionError as l, synchronizeAcquisitionSourceSnapshot as f } from "./acquisition.js";
3
+ import { createProxyBootstrapOwner as p, closeProxyBootstrap as y, synchronizeProxyBootstrap as d, readProxyBootstrapEvents as h, fetchProxyBootstrap as x } from "./proxy-bootstrap.js";
4
+ function w(i, c = {}) {
5
+ let n = !1, r = null;
6
+ const s = u(), t = c.proxyBootstrap ?? p();
7
7
  return Object.freeze({
8
- synchronize(i) {
9
- if (t) throw new s("acquisition_lifecycle_disposed");
10
- const o = a(n, i);
11
- if (i.state === "connected" && o === null)
12
- throw new s("connected_acquisition_missing");
13
- e.proxyBootstrap !== void 0 && d(e.proxyBootstrap, o), o !== null && o !== r && e.onConnected?.(o), r = o, c.synchronize(i.state === "connected" ? i.currentSession ?? null : null);
8
+ fetch: (e, o) => x(t, e, o),
9
+ events: (e, o) => h(t, e, o),
10
+ synchronize(e) {
11
+ if (n) throw new l("acquisition_lifecycle_disposed");
12
+ const o = f(i, e);
13
+ if (e.state === "connected" && o === null)
14
+ throw new l("connected_acquisition_missing");
15
+ d(t, o), o !== null && o !== r && c.onConnected?.(o), r = o, s.synchronize(e.state === "connected" ? e.currentSession ?? null : null);
14
16
  },
15
17
  dispose() {
16
- t || (t = !0, r = null, c.dispose(), e.proxyBootstrap !== void 0 && f(e.proxyBootstrap), u(n));
18
+ n || (n = !0, r = null, s.dispose(), y(t), a(i));
17
19
  }
18
20
  });
19
21
  }
20
22
  export {
21
- m as createAcquisitionConnectionLifecycle
23
+ w as createAcquisitionConnectionLifecycle
22
24
  };
@@ -75,6 +75,7 @@ export type ConnectedAcquisitionDetails = Readonly<{
75
75
  session: Session;
76
76
  scope: ProxyRuntimeScope;
77
77
  bindingIdentity: string;
78
+ appOrigin: string;
78
79
  attempt: number;
79
80
  }>;
80
81
  type MaterializeOptions = Readonly<{
@@ -1,10 +1,10 @@
1
1
  import { sha256 as x } from "@noble/hashes/sha2.js";
2
- import { createArtifactLease as A, parseArtifact as E } from "@floegence/flowersec-core";
2
+ import { createArtifactLease as S, parseArtifact as E } from "@floegence/flowersec-core";
3
3
  import { assertProxyRuntimeScope as C } from "@floegence/flowersec-core/proxy";
4
- const j = 32, L = 16384, H = "#redeven=";
4
+ const A = 32, L = 16384, H = "#redeven=";
5
5
  class r extends Error {
6
- constructor(t) {
7
- super(`Floe acquisition failed (code=${t})`), this.code = t, this.name = "AcquisitionError";
6
+ constructor(i) {
7
+ super(`Floe acquisition failed (code=${i})`), this.code = i, this.name = "AcquisitionError";
8
8
  }
9
9
  }
10
10
  class w {
@@ -15,8 +15,8 @@ class w {
15
15
  static create() {
16
16
  return new w();
17
17
  }
18
- static assertAuthentic(t) {
19
- t.#e;
18
+ static assertAuthentic(i) {
19
+ i.#e;
20
20
  }
21
21
  }
22
22
  class v {
@@ -27,46 +27,46 @@ class v {
27
27
  static create() {
28
28
  return new v();
29
29
  }
30
- static assertAuthentic(t) {
31
- t.#e;
30
+ static assertAuthentic(i) {
31
+ i.#e;
32
32
  }
33
33
  }
34
- const g = /* @__PURE__ */ new WeakMap(), O = /* @__PURE__ */ new WeakMap(), P = /* @__PURE__ */ new WeakMap(), D = /* @__PURE__ */ new Set();
34
+ const g = /* @__PURE__ */ new WeakMap(), j = /* @__PURE__ */ new WeakMap(), P = /* @__PURE__ */ new WeakMap(), D = /* @__PURE__ */ new Set();
35
35
  function ee(e) {
36
36
  if (g.has(e)) throw new r("duplicate_acquisition_source");
37
37
  g.set(e, { pending: [] });
38
38
  }
39
- async function te(e, t, i) {
40
- return q(e, t, i, E, A);
39
+ async function te(e, i, t) {
40
+ return q(e, i, t, E, S);
41
41
  }
42
- async function ie(e, t, i) {
42
+ async function ie(e, i, t) {
43
43
  const n = await import("@floegence/flowersec-core/browser");
44
44
  return q(
45
45
  e,
46
- t,
47
46
  i,
47
+ t,
48
48
  n.parsePrivateLoopbackArtifactV1,
49
49
  n.createPrivateLoopbackArtifactLeaseV1
50
50
  );
51
51
  }
52
- async function ne(e, t, i) {
52
+ async function ne(e, i, t) {
53
53
  const n = await import("@floegence/flowersec-core/browser");
54
54
  return q(
55
55
  e,
56
- t,
57
56
  i,
57
+ t,
58
58
  n.parseHTTPDirectArtifactV1,
59
59
  n.createHTTPDirectArtifactLeaseV1
60
60
  );
61
61
  }
62
- async function q(e, t, i, n, c) {
62
+ async function q(e, i, t, n, c) {
63
63
  const o = g.get(e);
64
64
  if (o === void 0) throw new r("invalid_acquisition_source");
65
- const a = await R(t, i, n);
65
+ const a = await R(i, t, n);
66
66
  return B(
67
67
  a,
68
68
  c,
69
- i.commitSpend,
69
+ t.commitSpend,
70
70
  (d) => {
71
71
  o.pending.push(d);
72
72
  },
@@ -75,41 +75,42 @@ async function q(e, t, i, n, c) {
75
75
  }
76
76
  );
77
77
  }
78
- function re(e, t) {
79
- const i = g.get(e);
80
- if (i === void 0) return null;
81
- if (t.state !== "connected" || t.currentSession === void 0)
82
- return (t.state === "idle" || t.state === "waiting" || t.state === "failed" || t.state === "closed") && (i.pending = [], i.connected = void 0, i.connectedSession = void 0), null;
83
- if (i.connected !== void 0 && i.connectedSession === t.currentSession)
84
- return i.connected;
85
- const n = i.pending.filter((a) => a.committed);
86
- if (n.length !== 1 || i.pending.length !== 1)
87
- throw i.pending = [], new r("connected_acquisition_mismatch");
78
+ function re(e, i) {
79
+ const t = g.get(e);
80
+ if (t === void 0) return null;
81
+ if (i.state !== "connected" || i.currentSession === void 0)
82
+ return (i.state === "idle" || i.state === "waiting" || i.state === "failed" || i.state === "closed") && (t.pending = [], t.connected = void 0, t.connectedSession = void 0), null;
83
+ if (t.connected !== void 0 && t.connectedSession === i.currentSession)
84
+ return t.connected;
85
+ const n = t.pending.filter((a) => a.committed);
86
+ if (n.length !== 1 || t.pending.length !== 1)
87
+ throw t.pending = [], new r("connected_acquisition_mismatch");
88
88
  const c = n[0];
89
89
  if (c === void 0) throw new r("connected_acquisition_mismatch");
90
90
  const o = w.create();
91
- return O.set(
91
+ return j.set(
92
92
  o,
93
93
  Object.freeze({
94
- session: t.currentSession,
94
+ session: i.currentSession,
95
95
  scope: c.scope,
96
96
  bindingIdentity: c.bindingIdentity,
97
- attempt: t.attempt
97
+ appOrigin: c.appOrigin,
98
+ attempt: i.attempt
98
99
  })
99
- ), i.pending = [], i.connected = o, i.connectedSession = t.currentSession, o;
100
+ ), t.pending = [], t.connected = o, t.connectedSession = i.currentSession, o;
100
101
  }
101
102
  function oe(e) {
102
- const t = g.get(e);
103
- t !== void 0 && (t.pending = [], t.connected = void 0, t.connectedSession = void 0);
103
+ const i = g.get(e);
104
+ i !== void 0 && (i.pending = [], i.connected = void 0, i.connectedSession = void 0);
104
105
  }
105
106
  function ce(e) {
106
107
  w.assertAuthentic(e);
107
- const t = O.get(e);
108
- if (t === void 0) throw new r("invalid_connected_acquisition");
109
- return t;
108
+ const i = j.get(e);
109
+ if (i === void 0) throw new r("invalid_connected_acquisition");
110
+ return i;
110
111
  }
111
112
  async function ae(e) {
112
- const t = e.rawHandoff, i = typeof t != "string" || V(`${H}${t}`) > L;
113
+ const i = e.rawHandoff, t = typeof i != "string" || V(`${H}${i}`) > L;
113
114
  let n = !1;
114
115
  try {
115
116
  n = e.clearSensitiveLocation() === !0;
@@ -118,8 +119,8 @@ async function ae(e) {
118
119
  }
119
120
  if (!n)
120
121
  throw e.navigateToLauncher(), new r("isolated_location_clear_failed");
121
- if (i) throw new r("isolated_handoff_too_large");
122
- const c = m(t, "invalid_isolated_handoff"), o = await G(c);
122
+ if (t) throw new r("isolated_handoff_too_large");
123
+ const c = m(i, "invalid_isolated_handoff"), o = await G(c);
123
124
  if (D.has(o))
124
125
  throw new r("isolated_handoff_consumed");
125
126
  D.add(o);
@@ -137,29 +138,29 @@ async function ae(e) {
137
138
  let s;
138
139
  const l = B(
139
140
  d,
140
- A,
141
+ S,
141
142
  e.commitSpend,
142
- (_) => {
143
- s = _;
143
+ (u) => {
144
+ s = u;
144
145
  },
145
146
  () => {
146
147
  }
147
148
  );
148
149
  if (s === void 0 || s.lease !== l)
149
150
  throw new r("isolated_materialization_failed");
150
- const u = v.create();
151
- return P.set(u, { pending: s, state: "ready" }), u;
151
+ const p = v.create();
152
+ return P.set(p, { pending: s, state: "ready" }), p;
152
153
  }
153
- async function F(e, t, i) {
154
- const n = J(e, t), c = await R(
154
+ async function F(e, i, t) {
155
+ const n = J(e, i), c = await R(
155
156
  n.acquisition,
156
157
  {
157
- commitSpend: i,
158
+ commitSpend: t,
158
159
  expectedConsumer: "isolated",
159
160
  validateSpendBinding: (o) => {
160
- M(n, o, t);
161
+ M(n, o, i);
161
162
  try {
162
- t.validateTargetBinding(o.targetBinding);
163
+ i.validateTargetBinding(o.targetBinding);
163
164
  } catch {
164
165
  throw new r("invalid_spend_binding");
165
166
  }
@@ -177,11 +178,11 @@ async function F(e, t, i) {
177
178
  }
178
179
  return c;
179
180
  }
180
- async function se(e, t, i) {
181
+ async function se(e, i, t) {
181
182
  const n = g.get(e);
182
183
  if (n === void 0) throw new r("invalid_acquisition_source");
183
184
  const c = h(
184
- t,
185
+ i,
185
186
  ["v", "runtime_origin", "runtime_handoff_b64u"],
186
187
  "invalid_isolated_handoff"
187
188
  ), o = c.runtime_handoff_b64u;
@@ -195,51 +196,52 @@ async function se(e, t, i) {
195
196
  throw new r("invalid_isolated_handoff");
196
197
  }
197
198
  const s = d, l = {
198
- ...i.context,
199
+ ...t.context,
199
200
  runtimeOrigin: f(c.runtime_origin),
200
201
  appOrigin: f(s?.app_origin)
201
- }, u = await F(
202
+ }, p = await F(
202
203
  d,
203
204
  l,
204
- i.commitSpend
205
- ), _ = s?.acquisition;
206
- if (!_) throw new r("invalid_isolated_handoff");
207
- return i.validateSpendBinding($(_.spend_scope)), B(
208
- u,
209
- A,
210
- i.commitSpend,
211
- (p) => n.pending.push(p),
212
- (p) => {
213
- n.pending = n.pending.filter((y) => y !== p);
205
+ t.commitSpend
206
+ ), u = s?.acquisition;
207
+ if (!u) throw new r("invalid_isolated_handoff");
208
+ return t.validateSpendBinding($(u.spend_scope)), B(
209
+ p,
210
+ S,
211
+ t.commitSpend,
212
+ (_) => n.pending.push(_),
213
+ (_) => {
214
+ n.pending = n.pending.filter((y) => y !== _);
214
215
  }
215
216
  );
216
217
  }
217
- async function de(e, t = {}) {
218
+ async function de(e, i = {}) {
218
219
  v.assertAuthentic(e);
219
- const i = P.get(e);
220
- if (i === void 0 || i.state !== "ready")
220
+ const t = P.get(e);
221
+ if (t === void 0 || t.state !== "ready")
221
222
  throw new r("isolated_acquisition_consumed");
222
- i.state = "connecting";
223
+ t.state = "connecting";
223
224
  try {
224
- const { connect: n } = await import("@floegence/flowersec-core/browser"), c = await n(i.pending.lease, t);
225
- if (!i.pending.committed)
225
+ const { connect: n } = await import("@floegence/flowersec-core/browser"), c = await n(t.pending.lease, i);
226
+ if (!t.pending.committed)
226
227
  throw await c.close().catch(() => {
227
228
  }), new r("isolated_spend_not_committed");
228
229
  const o = w.create();
229
- return O.set(
230
+ return j.set(
230
231
  o,
231
232
  Object.freeze({
232
233
  session: c,
233
- scope: i.pending.scope,
234
- bindingIdentity: i.pending.bindingIdentity,
234
+ scope: t.pending.scope,
235
+ bindingIdentity: t.pending.bindingIdentity,
236
+ appOrigin: t.pending.appOrigin,
235
237
  attempt: 1
236
238
  })
237
- ), i.state = "consumed", o;
239
+ ), t.state = "consumed", o;
238
240
  } catch (n) {
239
- throw i.state = "consumed", n;
241
+ throw t.state = "consumed", n;
240
242
  }
241
243
  }
242
- async function R(e, t, i) {
244
+ async function R(e, i, t) {
243
245
  const n = h(
244
246
  e,
245
247
  ["v", "connect_artifact", "critical_scope_projection_json", "spend_scope"],
@@ -247,7 +249,7 @@ async function R(e, t, i) {
247
249
  );
248
250
  if (n.v !== 1 || typeof n.connect_artifact != "string" || n.connect_artifact.length === 0 || typeof n.critical_scope_projection_json != "string" || n.critical_scope_projection_json.length === 0)
249
251
  throw new r("invalid_acquisition_envelope");
250
- const c = U(n.spend_scope, t.expectedConsumer), o = new TextEncoder().encode(n.connect_artifact), a = new TextEncoder().encode(n.critical_scope_projection_json);
252
+ const c = U(n.spend_scope, i.expectedConsumer), o = new TextEncoder().encode(n.connect_artifact), a = new TextEncoder().encode(n.critical_scope_projection_json);
251
253
  await I(o, c.artifact_digest_b64u, "artifact_digest_mismatch"), await I(
252
254
  a,
253
255
  c.projection_digest_b64u,
@@ -272,27 +274,27 @@ async function R(e, t, i) {
272
274
  } catch {
273
275
  throw new r("invalid_proxy_runtime_scope");
274
276
  }
275
- let u;
277
+ let p;
276
278
  try {
277
- u = i(n.connect_artifact);
279
+ p = t(n.connect_artifact);
278
280
  } catch {
279
281
  throw new r("invalid_connect_artifact");
280
282
  }
281
- const _ = $(c), p = t.validateSpendBinding(_);
282
- if (p !== void 0 && (typeof p != "string" || p.trim() === "" || p !== p.trim()))
283
+ const u = $(c), _ = i.validateSpendBinding(u);
284
+ if (_ !== void 0 && (typeof _ != "string" || _.trim() === "" || _ !== _.trim()))
283
285
  throw new r("invalid_spend_binding_identity");
284
286
  return Object.freeze({
285
- artifact: u,
287
+ artifact: p,
286
288
  scope: l,
287
- binding: _,
288
- bindingIdentity: p ?? `${_.artifactDigestB64u}.${_.projectionDigestB64u}`,
289
+ binding: u,
290
+ bindingIdentity: _ ?? `${u.artifactDigestB64u}.${u.projectionDigestB64u}`,
289
291
  receipt: c.receipt
290
292
  });
291
293
  }
292
- function B(e, t, i, n, c) {
294
+ function B(e, i, t, n, c) {
293
295
  const o = e.artifact, a = e.scope, d = e.binding, s = e.bindingIdentity;
294
- let l = e.receipt, u;
295
- const _ = t(o, async (p) => {
296
+ let l = e.receipt, p;
297
+ const u = i(o, async (_) => {
296
298
  const y = l;
297
299
  if (l = void 0, y === void 0) throw new r("spend_binding_consumed");
298
300
  const k = Object.freeze({
@@ -301,15 +303,15 @@ function B(e, t, i, n, c) {
301
303
  receipt: y
302
304
  });
303
305
  try {
304
- await i(k, p), u.committed = !0;
306
+ await t(k, _), p.committed = !0;
305
307
  } catch (N) {
306
- throw c(u), N;
308
+ throw c(p), N;
307
309
  }
308
310
  });
309
- return u = { lease: _, scope: a, bindingIdentity: s, committed: !1 }, n(u), _;
311
+ return p = { lease: u, scope: a, bindingIdentity: s, appOrigin: d.appOrigin, committed: !1 }, n(p), u;
310
312
  }
311
- function U(e, t) {
312
- const i = h(
313
+ function U(e, i) {
314
+ const t = h(
313
315
  e,
314
316
  [
315
317
  "v",
@@ -325,21 +327,21 @@ function U(e, t) {
325
327
  ],
326
328
  "invalid_spend_scope"
327
329
  );
328
- if (i.v !== 1 || typeof i.receipt != "string" || !Z(i.receipt) || typeof i.artifact_digest_b64u != "string" || !T(i.artifact_digest_b64u) || typeof i.projection_digest_b64u != "string" || !T(i.projection_digest_b64u) || i.consumer !== t || typeof i.expires_at != "string" || !W(i.expires_at) || !b(i.target_binding))
330
+ if (t.v !== 1 || typeof t.receipt != "string" || !Z(t.receipt) || typeof t.artifact_digest_b64u != "string" || !T(t.artifact_digest_b64u) || typeof t.projection_digest_b64u != "string" || !T(t.projection_digest_b64u) || t.consumer !== i || typeof t.expires_at != "string" || !W(t.expires_at) || !b(t.target_binding))
329
331
  throw new r("invalid_spend_scope");
330
- const n = f(i.launcher_origin), c = f(i.runtime_origin), o = f(i.app_origin);
331
- if (Date.parse(i.expires_at) <= Date.now()) throw new r("expired_spend_scope");
332
+ const n = f(t.launcher_origin), c = f(t.runtime_origin), o = f(t.app_origin);
333
+ if (Date.parse(t.expires_at) <= Date.now()) throw new r("expired_spend_scope");
332
334
  return Object.freeze({
333
335
  v: 1,
334
- receipt: i.receipt,
335
- artifact_digest_b64u: i.artifact_digest_b64u,
336
- projection_digest_b64u: i.projection_digest_b64u,
336
+ receipt: t.receipt,
337
+ artifact_digest_b64u: t.artifact_digest_b64u,
338
+ projection_digest_b64u: t.projection_digest_b64u,
337
339
  launcher_origin: n,
338
340
  runtime_origin: c,
339
341
  app_origin: o,
340
- consumer: t,
341
- target_binding: S(i.target_binding),
342
- expires_at: i.expires_at
342
+ consumer: i,
343
+ target_binding: O(t.target_binding),
344
+ expires_at: t.expires_at
343
345
  });
344
346
  }
345
347
  function $(e) {
@@ -354,8 +356,8 @@ function $(e) {
354
356
  expiresAt: e.expires_at
355
357
  });
356
358
  }
357
- function J(e, t) {
358
- const i = h(
359
+ function J(e, i) {
360
+ const t = h(
359
361
  e,
360
362
  [
361
363
  "v",
@@ -372,46 +374,46 @@ function J(e, t) {
372
374
  ],
373
375
  "invalid_isolated_handoff"
374
376
  );
375
- if (i.v !== 6 || i.env_public_id !== t.envPublicId || i.floe_app !== t.floeApp || i.code_space_id !== t.codeSpaceId || i.app_path !== t.appPath || i.launcher_kind !== t.launcherKind || i.launcher_id !== t.launcherId || i.launcher_origin !== t.launcherOrigin || i.runtime_origin !== t.runtimeOrigin || i.app_origin !== t.appOrigin)
377
+ if (t.v !== 6 || t.env_public_id !== i.envPublicId || t.floe_app !== i.floeApp || t.code_space_id !== i.codeSpaceId || t.app_path !== i.appPath || t.launcher_kind !== i.launcherKind || t.launcher_id !== i.launcherId || t.launcher_origin !== i.launcherOrigin || t.runtime_origin !== i.runtimeOrigin || t.app_origin !== i.appOrigin)
376
378
  throw new r("isolated_context_mismatch");
377
- return f(i.launcher_origin), f(i.runtime_origin), f(i.app_origin), i;
379
+ return f(t.launcher_origin), f(t.runtime_origin), f(t.app_origin), t;
378
380
  }
379
- function M(e, t, i) {
380
- if (t.consumer !== "isolated" || t.launcherOrigin !== e.launcher_origin || t.runtimeOrigin !== e.runtime_origin || t.appOrigin !== e.app_origin || e.runtime_origin !== i.runtimeOrigin || e.app_origin !== i.appOrigin)
381
+ function M(e, i, t) {
382
+ if (i.consumer !== "isolated" || i.launcherOrigin !== e.launcher_origin || i.runtimeOrigin !== e.runtime_origin || i.appOrigin !== e.app_origin || e.runtime_origin !== t.runtimeOrigin || e.app_origin !== t.appOrigin)
381
383
  throw new r("isolated_spend_binding_mismatch");
382
384
  }
383
- function h(e, t, i) {
385
+ function h(e, i, t) {
384
386
  if (e === null || typeof e != "object" || Array.isArray(e))
385
- throw new r(i);
386
- const n = e, c = new Set(t), o = Object.keys(n);
387
- if (o.length !== t.length || o.some((a) => !c.has(a)))
388
- throw new r(i);
387
+ throw new r(t);
388
+ const n = e, c = new Set(i), o = Object.keys(n);
389
+ if (o.length !== i.length || o.some((a) => !c.has(a)))
390
+ throw new r(t);
389
391
  return n;
390
392
  }
391
393
  function f(e) {
392
394
  if (typeof e != "string") throw new r("invalid_spend_scope");
393
- let t;
395
+ let i;
394
396
  try {
395
- t = new URL(e);
397
+ i = new URL(e);
396
398
  } catch {
397
399
  throw new r("invalid_spend_scope");
398
400
  }
399
- if (t.protocol !== "https:" && t.protocol !== "http:" || t.origin !== e || t.username !== "" || t.password !== "")
401
+ if (i.protocol !== "https:" && i.protocol !== "http:" || i.origin !== e || i.username !== "" || i.password !== "")
400
402
  throw new r("invalid_spend_scope");
401
403
  return e;
402
404
  }
403
405
  function Z(e) {
404
- const t = /^r1\.([A-Za-z0-9_-]{1,64})\.([A-Za-z0-9_-]+)$/u.exec(e);
405
- if (t === null || t[2] === void 0) return !1;
406
+ const i = /^r1\.([A-Za-z0-9_-]{1,64})\.([A-Za-z0-9_-]+)$/u.exec(e);
407
+ if (i === null || i[2] === void 0) return !1;
406
408
  try {
407
- return m(t[2], "invalid_spend_scope").length === j;
409
+ return m(i[2], "invalid_spend_scope").length === A;
408
410
  } catch {
409
411
  return !1;
410
412
  }
411
413
  }
412
414
  function T(e) {
413
415
  try {
414
- return m(e, "invalid_spend_scope").length === j;
416
+ return m(e, "invalid_spend_scope").length === A;
415
417
  } catch {
416
418
  return !1;
417
419
  }
@@ -419,29 +421,29 @@ function T(e) {
419
421
  function W(e) {
420
422
  return /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/u.test(e) ? Number.isFinite(Date.parse(e)) : !1;
421
423
  }
422
- function b(e, t = 0) {
423
- return t > 32 ? !1 : e === null || typeof e == "string" || typeof e == "boolean" ? !0 : typeof e == "number" ? Number.isFinite(e) : Array.isArray(e) ? e.every((i) => b(i, t + 1)) : typeof e != "object" ? !1 : Object.values(e).every(
424
- (i) => b(i, t + 1)
424
+ function b(e, i = 0) {
425
+ return i > 32 ? !1 : e === null || typeof e == "string" || typeof e == "boolean" ? !0 : typeof e == "number" ? Number.isFinite(e) : Array.isArray(e) ? e.every((t) => b(t, i + 1)) : typeof e != "object" ? !1 : Object.values(e).every(
426
+ (t) => b(t, i + 1)
425
427
  );
426
428
  }
427
- function S(e) {
429
+ function O(e) {
428
430
  if (Array.isArray(e)) {
429
- for (const t of e) S(t);
431
+ for (const i of e) O(i);
430
432
  return Object.freeze(e);
431
433
  }
432
434
  if (e !== null && typeof e == "object") {
433
- for (const t of Object.values(e)) S(t);
435
+ for (const i of Object.values(e)) O(i);
434
436
  return Object.freeze(e);
435
437
  }
436
438
  return e;
437
439
  }
438
- async function I(e, t, i) {
439
- const n = await x(e), c = m(t, i);
440
- if (n.length !== c.length) throw new r(i);
440
+ async function I(e, i, t) {
441
+ const n = await x(e), c = m(i, t);
442
+ if (n.length !== c.length) throw new r(t);
441
443
  let o = 0;
442
444
  for (let a = 0; a < n.length; a += 1)
443
445
  o |= n[a] ^ c[a];
444
- if (o !== 0) throw new r(i);
446
+ if (o !== 0) throw new r(t);
445
447
  }
446
448
  async function G(e) {
447
449
  return z(await x(e));
@@ -449,25 +451,25 @@ async function G(e) {
449
451
  function X() {
450
452
  if (globalThis.crypto?.getRandomValues === void 0)
451
453
  throw new r("acquisition_entropy_unavailable");
452
- return z(globalThis.crypto.getRandomValues(new Uint8Array(j)));
454
+ return z(globalThis.crypto.getRandomValues(new Uint8Array(A)));
453
455
  }
454
- function m(e, t) {
455
- if (!/^[A-Za-z0-9_-]*$/u.test(e) || e.length % 4 === 1) throw new r(t);
456
- const i = e.replace(/-/gu, "+").replace(/_/gu, "/") + "=".repeat((4 - e.length % 4) % 4);
456
+ function m(e, i) {
457
+ if (!/^[A-Za-z0-9_-]*$/u.test(e) || e.length % 4 === 1) throw new r(i);
458
+ const t = e.replace(/-/gu, "+").replace(/_/gu, "/") + "=".repeat((4 - e.length % 4) % 4);
457
459
  let n;
458
460
  try {
459
- n = atob(i);
461
+ n = atob(t);
460
462
  } catch {
461
- throw new r(t);
463
+ throw new r(i);
462
464
  }
463
465
  const c = Uint8Array.from(n, (o) => o.charCodeAt(0));
464
- if (z(c) !== e) throw new r(t);
466
+ if (z(c) !== e) throw new r(i);
465
467
  return c;
466
468
  }
467
469
  function z(e) {
468
- let t = "";
469
- for (const i of e) t += String.fromCharCode(i);
470
- return btoa(t).replace(/\+/gu, "-").replace(/\//gu, "_").replace(/=+$/u, "");
470
+ let i = "";
471
+ for (const t of e) i += String.fromCharCode(t);
472
+ return btoa(i).replace(/\+/gu, "-").replace(/\//gu, "_").replace(/=+$/u, "");
471
473
  }
472
474
  function V(e) {
473
475
  return new TextEncoder().encode(e).length;
@@ -1,3 +1,4 @@
1
+ import { type FetchServerSentEventsOptions, type ServerSentEvent } from './server-sent-events';
1
2
  import { type ProxyRuntime } from '@floegence/flowersec-core/proxy';
2
3
  import { ConnectedAcquisition } from './acquisition';
3
4
  export type ProxyBootstrapBinding = Readonly<{
@@ -25,7 +26,7 @@ export type ProxyBootstrapOwnerOptions = Readonly<{
25
26
  }>;
26
27
  export type ProxyBootstrapSnapshot = Readonly<{
27
28
  generation: number;
28
- mode: 'service_worker' | 'controller_bridge';
29
+ mode: 'session' | 'service_worker' | 'controller_bridge';
29
30
  bindingIdentity: string;
30
31
  }>;
31
32
  export declare class ProxyBootstrapOwner {
@@ -34,6 +35,8 @@ export declare class ProxyBootstrapOwner {
34
35
  static create(): ProxyBootstrapOwner;
35
36
  static assertAuthentic(value: ProxyBootstrapOwner): void;
36
37
  }
37
- export declare function createProxyBootstrapOwner(options: ProxyBootstrapOwnerOptions): ProxyBootstrapOwner;
38
+ export declare function createProxyBootstrapOwner(options?: ProxyBootstrapOwnerOptions): ProxyBootstrapOwner;
38
39
  export declare function synchronizeProxyBootstrap(owner: ProxyBootstrapOwner, acquisition: ConnectedAcquisition | null): ProxyBootstrapSnapshot | null;
40
+ export declare function fetchProxyBootstrap(owner: ProxyBootstrapOwner, input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
41
+ export declare function readProxyBootstrapEvents(owner: ProxyBootstrapOwner, input: RequestInfo | URL, options?: Omit<FetchServerSentEventsOptions, 'fetch'>): AsyncGenerator<ServerSentEvent>;
39
42
  export declare function closeProxyBootstrap(owner: ProxyBootstrapOwner): void;
@@ -1,101 +1,133 @@
1
- import { createProxyRuntime as f } from "@floegence/flowersec-core/proxy";
2
- import { connectedAcquisitionDetails as y, AcquisitionError as s } from "./acquisition.js";
3
- class d {
1
+ import { ServerSentEventStreamError as f, fetchServerSentEvents as b } from "./server-sent-events.js";
2
+ import { createProxyRuntime as w } from "@floegence/flowersec-core/proxy";
3
+ import { connectedAcquisitionDetails as y, AcquisitionError as a } from "./acquisition.js";
4
+ class l {
4
5
  #e = void 0;
5
6
  constructor() {
6
7
  Object.freeze(this);
7
8
  }
8
9
  static create() {
9
- return new d();
10
+ return new l();
10
11
  }
11
12
  static assertAuthentic(t) {
12
13
  t.#e;
13
14
  }
14
15
  }
15
- const b = /* @__PURE__ */ new WeakMap();
16
- function P(e) {
17
- const t = d.create();
18
- return b.set(t, { options: e, generation: 0 }), t;
16
+ const v = /* @__PURE__ */ new WeakMap();
17
+ function B(r) {
18
+ const t = l.create();
19
+ return v.set(t, { options: r, generation: 0 }), t;
19
20
  }
20
- function m(e, t) {
21
- const o = h(e);
21
+ function _(r, t) {
22
+ const e = h(r);
22
23
  if (t === null)
23
- return l(o), null;
24
- if (o.acquisition === t && o.snapshot !== void 0) return o.snapshot;
24
+ return u(e), null;
25
+ if (e.acquisition === t && e.snapshot !== void 0) return e.snapshot;
25
26
  const n = y(t);
26
- l(o);
27
- const c = o.generation + 1;
28
- o.generation = c;
29
- const r = n.scope, p = f({
27
+ u(e);
28
+ const i = e.generation + 1;
29
+ e.generation = i;
30
+ const o = n.scope, c = w({
30
31
  session: n.session,
31
- ...r.limits ?? {},
32
- ...r.http?.extraRequestHeaders === void 0 ? {} : { extraRequestHeaders: r.http.extraRequestHeaders },
33
- ...r.appBasePath === void 0 ? {} : { pathPolicy: {
34
- allowedPathPrefixes: Object.freeze([r.appBasePath, ...r.http?.additionalPathPrefixes ?? []]),
35
- allowedWebSocketPathPrefixes: Object.freeze([r.appBasePath])
32
+ externalOrigin: n.appOrigin,
33
+ ...o.limits ?? {},
34
+ ...o.http?.extraRequestHeaders === void 0 ? {} : { extraRequestHeaders: o.http.extraRequestHeaders },
35
+ ...o.appBasePath === void 0 ? {} : { pathPolicy: {
36
+ allowedPathPrefixes: Object.freeze([o.appBasePath, ...o.http?.additionalPathPrefixes ?? []]),
37
+ allowedWebSocketPathPrefixes: Object.freeze([o.appBasePath])
36
38
  } }
37
39
  });
38
40
  try {
39
- let i;
40
- if (r.mode === "service_worker") {
41
- const a = o.options.serviceWorker;
42
- if (a === void 0) throw new s("service_worker_bootstrap_unavailable");
43
- i = a(Object.freeze({
44
- runtime: p,
45
- generation: c,
46
- bindingIdentity: n.bindingIdentity,
47
- scriptUrl: r.serviceWorker.scriptUrl,
48
- serviceWorkerScope: r.serviceWorker.scope,
49
- ...r.appBasePath === void 0 ? {} : { appBasePath: r.appBasePath }
50
- }));
51
- } else {
52
- const a = o.options.controllerBridge;
53
- if (a === void 0) throw new s("controller_bridge_bootstrap_unavailable");
54
- i = a(Object.freeze({
55
- runtime: p,
56
- generation: c,
57
- bindingIdentity: n.bindingIdentity,
58
- allowedOrigins: r.controllerBridge.allowedOrigins,
59
- ...r.appBasePath === void 0 ? {} : { appBasePath: r.appBasePath },
60
- capabilityNonce: g()
61
- }));
41
+ let s;
42
+ if (e.options !== void 0)
43
+ if (o.mode === "service_worker") {
44
+ const d = e.options.serviceWorker;
45
+ if (d === void 0) throw new a("service_worker_bootstrap_unavailable");
46
+ s = d(Object.freeze({
47
+ runtime: c,
48
+ generation: i,
49
+ bindingIdentity: n.bindingIdentity,
50
+ scriptUrl: o.serviceWorker.scriptUrl,
51
+ serviceWorkerScope: o.serviceWorker.scope,
52
+ ...o.appBasePath === void 0 ? {} : { appBasePath: o.appBasePath }
53
+ }));
54
+ } else {
55
+ const d = e.options.controllerBridge;
56
+ if (d === void 0) throw new a("controller_bridge_bootstrap_unavailable");
57
+ s = d(Object.freeze({
58
+ runtime: c,
59
+ generation: i,
60
+ bindingIdentity: n.bindingIdentity,
61
+ allowedOrigins: o.controllerBridge.allowedOrigins,
62
+ ...o.appBasePath === void 0 ? {} : { appBasePath: o.appBasePath },
63
+ capabilityNonce: g()
64
+ }));
65
+ }
66
+ if (e.options !== void 0 && (s === null || typeof s != "object" || typeof s.dispose != "function"))
67
+ throw new a("invalid_proxy_bootstrap_binding");
68
+ const p = Object.freeze({ generation: i, mode: e.options === void 0 ? "session" : o.mode, bindingIdentity: n.bindingIdentity });
69
+ return e.acquisition = t, e.runtime = c, e.binding = s, e.snapshot = p, p;
70
+ } catch (s) {
71
+ throw c.dispose(), s;
72
+ }
73
+ }
74
+ async function O(r, t, e) {
75
+ const n = h(r), i = n.runtime;
76
+ if (i === void 0) throw new a("session_http_unavailable");
77
+ const o = await i.fetch(t, e);
78
+ if (n.runtime !== i)
79
+ throw await o.body?.cancel().catch(() => {
80
+ }), new a("session_http_replaced");
81
+ return o;
82
+ }
83
+ async function* A(r, t, e = {}) {
84
+ const n = h(r), i = n.runtime;
85
+ if (i === void 0) throw new f("transport", "session HTTP is unavailable");
86
+ e.signal?.throwIfAborted();
87
+ const o = new Headers(e.headers ?? (t instanceof Request ? t.headers : void 0));
88
+ o.set("Accept", "text/event-stream");
89
+ for await (const c of b(t, {
90
+ ...e,
91
+ headers: o,
92
+ fetch: (s, p) => i.fetch(s, p),
93
+ onActivity: () => {
94
+ n.runtime === i && !e.signal?.aborted && e.onActivity?.();
62
95
  }
63
- if (i === null || typeof i != "object" || typeof i.dispose != "function")
64
- throw new s("invalid_proxy_bootstrap_binding");
65
- const u = Object.freeze({ generation: c, mode: r.mode, bindingIdentity: n.bindingIdentity });
66
- return o.acquisition = t, o.runtime = p, o.binding = i, o.snapshot = u, u;
67
- } catch (i) {
68
- throw p.dispose(), i;
96
+ })) {
97
+ if (e.signal?.throwIfAborted(), n.runtime !== i) throw new f("transport", "session HTTP was replaced");
98
+ yield c;
69
99
  }
70
100
  }
71
- function B(e) {
72
- l(h(e));
101
+ function S(r) {
102
+ u(h(r));
73
103
  }
74
- function h(e) {
75
- d.assertAuthentic(e);
76
- const t = b.get(e);
77
- if (t === void 0) throw new s("invalid_proxy_bootstrap_owner");
104
+ function h(r) {
105
+ l.assertAuthentic(r);
106
+ const t = v.get(r);
107
+ if (t === void 0) throw new a("invalid_proxy_bootstrap_owner");
78
108
  return t;
79
109
  }
80
- function l(e) {
81
- const t = e.binding, o = e.runtime;
82
- e.acquisition = void 0, e.binding = void 0, e.runtime = void 0, e.snapshot = void 0;
110
+ function u(r) {
111
+ const t = r.binding, e = r.runtime;
112
+ r.acquisition = void 0, r.binding = void 0, r.runtime = void 0, r.snapshot = void 0;
83
113
  try {
84
114
  t?.dispose();
85
115
  } finally {
86
- o?.dispose();
116
+ e?.dispose();
87
117
  }
88
118
  }
89
119
  function g() {
90
- if (globalThis.crypto?.getRandomValues === void 0) throw new s("acquisition_entropy_unavailable");
91
- const e = globalThis.crypto.getRandomValues(new Uint8Array(32));
120
+ if (globalThis.crypto?.getRandomValues === void 0) throw new a("acquisition_entropy_unavailable");
121
+ const r = globalThis.crypto.getRandomValues(new Uint8Array(32));
92
122
  let t = "";
93
- for (const o of e) t += String.fromCharCode(o);
123
+ for (const e of r) t += String.fromCharCode(e);
94
124
  return btoa(t).replace(/\+/gu, "-").replace(/\//gu, "_").replace(/=+$/u, "");
95
125
  }
96
126
  export {
97
- d as ProxyBootstrapOwner,
98
- B as closeProxyBootstrap,
99
- P as createProxyBootstrapOwner,
100
- m as synchronizeProxyBootstrap
127
+ l as ProxyBootstrapOwner,
128
+ S as closeProxyBootstrap,
129
+ B as createProxyBootstrapOwner,
130
+ O as fetchProxyBootstrap,
131
+ A as readProxyBootstrapEvents,
132
+ _ as synchronizeProxyBootstrap
101
133
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floegence/floe-webapp-boot",
3
- "version": "0.62.0",
3
+ "version": "0.64.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -35,7 +35,7 @@
35
35
  "clean": "rm -rf dist *.tsbuildinfo"
36
36
  },
37
37
  "dependencies": {
38
- "@floegence/flowersec-core": "5.2.2",
38
+ "@floegence/flowersec-core": "5.3.1",
39
39
  "@noble/hashes": "2.4.0"
40
40
  },
41
41
  "devDependencies": {