@floegence/floe-webapp-boot 0.40.3 → 0.40.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -6,5 +6,7 @@ export type { ArtifactAcquireContext, ArtifactSource } from '@floegence/flowerse
6
6
  export { createControlplaneArtifactSource } from '@floegence/flowersec-core/reconnect';
7
7
  export type { DirectArtifactReconnectOptions, TunnelArtifactReconnectOptions } from './reconnect';
8
8
  export { createArtifactDirectReconnectConfig, createArtifactTunnelReconnectConfig, createProxyRuntimeTunnelReconnectConfig, } from './reconnect';
9
+ export type { FetchServerSentEventsOptions, ServerSentEvent, ServerSentEventStreamErrorCode, } from './server-sent-events';
10
+ export { fetchServerSentEvents, ServerSentEventStreamError, } from './server-sent-events';
9
11
  export type { ScopeEnvelope, ScopeResolver, ScopeResolverMap } from './scope';
10
12
  export { createBootstrapScopeResolvers, FLOWERSEC_BOOTSTRAP_SCOPE_RESOLVERS, PROXY_RUNTIME_SCOPE_NAME, validateProxyRuntimeScopeEntry, } from './scope';
package/dist/index.js CHANGED
@@ -1,25 +1,28 @@
1
- import { base64UrlToBase64 as r, clearLocationHash as t, parseBase64UrlJsonFromHash as a, parseHashParam as s } from "./index2.js";
2
- import { postMessageToOrigins as c, waitForMessage as i } from "./index3.js";
3
- import { getSessionStorage as p, removeSessionStorage as f, setSessionStorage as R } from "./index4.js";
4
- import { createControlplaneArtifactSource as g } from "@floegence/flowersec-core/reconnect";
5
- import { createArtifactDirectReconnectConfig as E, createArtifactTunnelReconnectConfig as x, createProxyRuntimeTunnelReconnectConfig as O } from "./index5.js";
6
- import { FLOWERSEC_BOOTSTRAP_SCOPE_RESOLVERS as P, PROXY_RUNTIME_SCOPE_NAME as T, createBootstrapScopeResolvers as _, validateProxyRuntimeScopeEntry as u } from "./index6.js";
1
+ import { base64UrlToBase64 as o, clearLocationHash as t, parseBase64UrlJsonFromHash as a, parseHashParam as n } from "./index2.js";
2
+ import { postMessageToOrigins as c, waitForMessage as S } from "./index3.js";
3
+ import { getSessionStorage as f, removeSessionStorage as p, setSessionStorage as m } from "./index4.js";
4
+ import { createControlplaneArtifactSource as R } from "@floegence/flowersec-core/reconnect";
5
+ import { createArtifactDirectReconnectConfig as l, createArtifactTunnelReconnectConfig as x, createProxyRuntimeTunnelReconnectConfig as O } from "./index5.js";
6
+ import { ServerSentEventStreamError as C, fetchServerSentEvents as P } from "./index6.js";
7
+ import { FLOWERSEC_BOOTSTRAP_SCOPE_RESOLVERS as _, PROXY_RUNTIME_SCOPE_NAME as u, createBootstrapScopeResolvers as A, validateProxyRuntimeScopeEntry as h } from "./index7.js";
7
8
  export {
8
- P as FLOWERSEC_BOOTSTRAP_SCOPE_RESOLVERS,
9
- T as PROXY_RUNTIME_SCOPE_NAME,
10
- r as base64UrlToBase64,
9
+ _ as FLOWERSEC_BOOTSTRAP_SCOPE_RESOLVERS,
10
+ u as PROXY_RUNTIME_SCOPE_NAME,
11
+ C as ServerSentEventStreamError,
12
+ o as base64UrlToBase64,
11
13
  t as clearLocationHash,
12
- E as createArtifactDirectReconnectConfig,
14
+ l as createArtifactDirectReconnectConfig,
13
15
  x as createArtifactTunnelReconnectConfig,
14
- _ as createBootstrapScopeResolvers,
15
- g as createControlplaneArtifactSource,
16
+ A as createBootstrapScopeResolvers,
17
+ R as createControlplaneArtifactSource,
16
18
  O as createProxyRuntimeTunnelReconnectConfig,
17
- p as getSessionStorage,
19
+ P as fetchServerSentEvents,
20
+ f as getSessionStorage,
18
21
  a as parseBase64UrlJsonFromHash,
19
- s as parseHashParam,
22
+ n as parseHashParam,
20
23
  c as postMessageToOrigins,
21
- f as removeSessionStorage,
22
- R as setSessionStorage,
23
- u as validateProxyRuntimeScopeEntry,
24
- i as waitForMessage
24
+ p as removeSessionStorage,
25
+ m as setSessionStorage,
26
+ h as validateProxyRuntimeScopeEntry,
27
+ S as waitForMessage
25
28
  };
package/dist/index5.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createBootstrapScopeResolvers as n } from "./index6.js";
1
+ import { createBootstrapScopeResolvers as n } from "./index7.js";
2
2
  function r(e) {
3
3
  return {
4
4
  source: e.source,
package/dist/index6.js CHANGED
@@ -1,22 +1,150 @@
1
- import { assertProxyRuntimeScopeV1 as t } from "@floegence/flowersec-core/proxy";
2
- const o = "proxy.runtime";
3
- function r(e) {
4
- if (e.scope_version !== 1)
5
- throw new Error(`unsupported ${o} scope_version: ${e.scope_version}`);
6
- t(e.payload);
1
+ class i extends Error {
2
+ code;
3
+ status;
4
+ retryAfter;
5
+ constructor(d, m, c = {}) {
6
+ super(m, c), this.name = "ServerSentEventStreamError", this.code = d, c.status !== void 0 && (this.status = c.status), c.retryAfter !== void 0 && (this.retryAfter = c.retryAfter);
7
+ }
7
8
  }
8
- const n = Object.freeze({
9
- [o]: r
10
- });
11
- function c(e) {
12
- return e ? Object.freeze({
13
- ...e,
14
- [o]: r
15
- }) : n;
9
+ const U = 1024 * 1024, N = 2 * 1024 * 1024;
10
+ function T(n, d) {
11
+ if (n === void 0) return d;
12
+ if (!Number.isSafeInteger(n) || n <= 0)
13
+ throw new TypeError("server-sent event byte limits must be positive safe integers");
14
+ return n;
15
+ }
16
+ function R(n) {
17
+ return n.headers.get("content-type")?.split(";", 1)[0]?.trim().toLowerCase() === "text/event-stream";
18
+ }
19
+ async function A(n) {
20
+ try {
21
+ await n.body?.cancel();
22
+ } catch {
23
+ }
24
+ }
25
+ async function* O(n, d = {}) {
26
+ const {
27
+ fetch: m = globalThis.fetch,
28
+ maxFrameBytes: c,
29
+ maxBufferBytes: F,
30
+ onActivity: x,
31
+ signal: L,
32
+ ...k
33
+ } = d, M = T(c, U), D = T(F, N);
34
+ let a;
35
+ try {
36
+ a = await m(n, { ...k, signal: L });
37
+ } catch (e) {
38
+ throw new i("transport", "failed to open server-sent event stream", { cause: e });
39
+ }
40
+ if (!a.ok) {
41
+ const e = a.headers.get("retry-after") ?? void 0;
42
+ throw await A(a), new i(
43
+ "unexpected_status",
44
+ `server-sent event request returned HTTP ${a.status}`,
45
+ { status: a.status, retryAfter: e }
46
+ );
47
+ }
48
+ if (!R(a))
49
+ throw await A(a), new i(
50
+ "unsupported_content_type",
51
+ "server-sent event response must use text/event-stream"
52
+ );
53
+ if (a.body === null)
54
+ throw new i("malformed_frame", "server-sent event response has no body");
55
+ const y = a.body.getReader(), B = new TextDecoder("utf-8", { fatal: !0 }), E = new TextEncoder();
56
+ let s = "", h = 0, w = [], l, b, u, p = !1, g = !1;
57
+ const _ = () => {
58
+ h = 0, w = [], l = void 0, u = void 0, p = !1;
59
+ }, I = (e, o) => {
60
+ if (h += E.encode(e).byteLength + o, h > M)
61
+ throw new i("oversized_frame", "server-sent event frame exceeds its byte limit");
62
+ if (e === "") {
63
+ if (!p) {
64
+ _();
65
+ return;
66
+ }
67
+ const f = {
68
+ data: w.join(`
69
+ `),
70
+ ...l === void 0 ? {} : { event: l },
71
+ ...b === void 0 ? {} : { id: b },
72
+ ...u === void 0 ? {} : { retry: u }
73
+ };
74
+ return _(), f;
75
+ }
76
+ if (e.startsWith(":")) {
77
+ x?.();
78
+ return;
79
+ }
80
+ const r = e.indexOf(":"), v = r < 0 ? e : e.slice(0, r);
81
+ let t = r < 0 ? "" : e.slice(r + 1);
82
+ switch (t.startsWith(" ") && (t = t.slice(1)), v) {
83
+ case "data":
84
+ p = !0, w.push(t);
85
+ break;
86
+ case "event":
87
+ l = t;
88
+ break;
89
+ case "id":
90
+ t.includes("\0") || (b = t);
91
+ break;
92
+ case "retry":
93
+ if (/^[0-9]+$/u.test(t)) {
94
+ const f = Number(t);
95
+ Number.isSafeInteger(f) && (u = f);
96
+ }
97
+ break;
98
+ }
99
+ };
100
+ try {
101
+ for (; ; ) {
102
+ let e;
103
+ try {
104
+ e = await y.read();
105
+ } catch (r) {
106
+ throw new i("transport", "failed while reading server-sent event stream", { cause: r });
107
+ }
108
+ if (e.value !== void 0) {
109
+ x?.();
110
+ try {
111
+ s += B.decode(e.value, { stream: !e.done });
112
+ } catch (r) {
113
+ throw new i("malformed_frame", "server-sent event stream is not valid UTF-8", { cause: r });
114
+ }
115
+ } else if (e.done)
116
+ try {
117
+ s += B.decode();
118
+ } catch (r) {
119
+ throw new i("malformed_frame", "server-sent event stream ends with invalid UTF-8", { cause: r });
120
+ }
121
+ let o = 0;
122
+ for (; o < s.length; ) {
123
+ const r = s.indexOf(`
124
+ `, o), v = s.indexOf("\r", o);
125
+ let t = -1;
126
+ if (r >= 0 && v >= 0 ? t = Math.min(r, v) : t = Math.max(r, v), t < 0 || s[t] === "\r" && t + 1 === s.length && !e.done) break;
127
+ const f = s[t] === "\r" && s[t + 1] === `
128
+ ` ? 2 : 1, S = I(s.slice(o, t), f);
129
+ o = t + f, S !== void 0 && (yield S);
130
+ }
131
+ if (s = s.slice(o), E.encode(s).byteLength > D)
132
+ throw new i("oversized_buffer", "server-sent event pending buffer exceeds its byte limit");
133
+ if (e.done) {
134
+ g = !0;
135
+ return;
136
+ }
137
+ }
138
+ } finally {
139
+ if (!g)
140
+ try {
141
+ await y.cancel();
142
+ } catch {
143
+ }
144
+ y.releaseLock();
145
+ }
16
146
  }
17
147
  export {
18
- n as FLOWERSEC_BOOTSTRAP_SCOPE_RESOLVERS,
19
- o as PROXY_RUNTIME_SCOPE_NAME,
20
- c as createBootstrapScopeResolvers,
21
- r as validateProxyRuntimeScopeEntry
148
+ i as ServerSentEventStreamError,
149
+ O as fetchServerSentEvents
22
150
  };
package/dist/index7.js ADDED
@@ -0,0 +1,22 @@
1
+ import { assertProxyRuntimeScopeV1 as t } from "@floegence/flowersec-core/proxy";
2
+ const o = "proxy.runtime";
3
+ function r(e) {
4
+ if (e.scope_version !== 1)
5
+ throw new Error(`unsupported ${o} scope_version: ${e.scope_version}`);
6
+ t(e.payload);
7
+ }
8
+ const n = Object.freeze({
9
+ [o]: r
10
+ });
11
+ function c(e) {
12
+ return e ? Object.freeze({
13
+ ...e,
14
+ [o]: r
15
+ }) : n;
16
+ }
17
+ export {
18
+ n as FLOWERSEC_BOOTSTRAP_SCOPE_RESOLVERS,
19
+ o as PROXY_RUNTIME_SCOPE_NAME,
20
+ c as createBootstrapScopeResolvers,
21
+ r as validateProxyRuntimeScopeEntry
22
+ };
@@ -0,0 +1,24 @@
1
+ export type ServerSentEventStreamErrorCode = 'transport' | 'unexpected_status' | 'unsupported_content_type' | 'malformed_frame' | 'oversized_frame' | 'oversized_buffer';
2
+ export declare class ServerSentEventStreamError extends Error {
3
+ readonly code: ServerSentEventStreamErrorCode;
4
+ readonly status?: number;
5
+ readonly retryAfter?: string;
6
+ constructor(code: ServerSentEventStreamErrorCode, message: string, options?: ErrorOptions & Readonly<{
7
+ status?: number;
8
+ retryAfter?: string;
9
+ }>);
10
+ }
11
+ export type ServerSentEvent = Readonly<{
12
+ data: string;
13
+ event?: string;
14
+ id?: string;
15
+ retry?: number;
16
+ }>;
17
+ export type FetchServerSentEventsOptions = Omit<RequestInit, 'signal'> & Readonly<{
18
+ signal?: AbortSignal;
19
+ fetch?: typeof globalThis.fetch;
20
+ maxFrameBytes?: number;
21
+ maxBufferBytes?: number;
22
+ onActivity?: () => void;
23
+ }>;
24
+ export declare function fetchServerSentEvents(input: RequestInfo | URL, options?: FetchServerSentEventsOptions): AsyncGenerator<ServerSentEvent, void, undefined>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floegence/floe-webapp-boot",
3
- "version": "0.40.3",
3
+ "version": "0.40.4",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",