@botpress/webchat-client 0.1.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.
@@ -0,0 +1,5 @@
1
+ import { createClient as t, createUser as a } from "./webchat-client2.js";
2
+ export {
3
+ t as createClient,
4
+ a as createUser
5
+ };
@@ -0,0 +1,84 @@
1
+ import { createUser as g, getEvent as m, createEvent as C, deleteUser as U, updateUser as f, getUser as M, createFile as b, deleteMessage as y, getMessage as E, updateMessage as P, createMessage as $, listParticipants as q, getParticipant as w, removeParticipant as x, addParticipant as S, listConversationMessages as F, listConversations as J, deleteConversation as O, getConversation as k, createConversation as D } from "./webchat-client3.js";
2
+ import { client as l } from "./webchat-client4.js";
3
+ import { EventSource as N } from "./webchat-client5.js";
4
+ import { EventEmitter as _ } from "./webchat-client6.js";
5
+ const n = (a) => a.data, v = {
6
+ throwOnError: !0
7
+ }, I = ({ clientId: a, apiUrl: h }) => {
8
+ const d = `${h || l.getConfig().baseUrl}/${a}`, t = {
9
+ ...v,
10
+ baseUrl: d
11
+ };
12
+ return g({ ...t, body: {} }).then(n);
13
+ }, K = ({
14
+ userKey: a,
15
+ clientId: h,
16
+ apiUrl: d
17
+ }) => {
18
+ const t = {
19
+ "x-user-key": a
20
+ }, p = `${d || l.getConfig().baseUrl}/${h}`, r = {
21
+ ...v,
22
+ baseUrl: p
23
+ };
24
+ return {
25
+ createConversation: () => D({ ...r, headers: t, body: {} }).then(n),
26
+ getConversation: ({ conversationId: e }) => k({ ...r, headers: t, path: { id: e } }).then(n),
27
+ deleteConversation: ({ conversationId: e }) => O({ ...r, headers: t, path: { id: e } }).then(n),
28
+ listConversations: ({ nextToken: e }) => J({ ...r, headers: t, query: { nextToken: e } }).then(n),
29
+ listConversationMessages: ({ conversationId: e, nextToken: s }) => F({
30
+ ...r,
31
+ headers: t,
32
+ path: { id: e },
33
+ query: { nextToken: s }
34
+ }).then(n),
35
+ addParticipant: ({ conversationId: e, userId: s }) => S({ ...r, headers: t, path: { id: e }, body: { userId: s } }).then(n),
36
+ removeParticipant: ({ conversationId: e, userId: s }) => x({ ...r, headers: t, path: { id: e, userId: s } }).then(n),
37
+ getParticipant: ({ conversationId: e, userId: s }) => w({ ...r, headers: t, path: { id: e, userId: s } }).then(n),
38
+ listParticipants: ({ conversationId: e, nextToken: s }) => q({ ...r, headers: t, path: { id: e }, query: { nextToken: s } }).then(n),
39
+ createMessage: (e) => $({ ...r, headers: t, body: e }).then(n),
40
+ updateMessage: ({ messageId: e, ...s }) => P({ ...r, headers: t, path: { id: e }, body: s }).then(n),
41
+ getMessage: ({ messageId: e }) => E({ ...r, headers: t, path: { id: e } }).then(n),
42
+ deleteMessage: ({ messageId: e }) => y({ ...r, headers: t, path: { id: e } }).then(n),
43
+ createFile: (e) => b({ ...r, headers: t, body: e }).then(n),
44
+ createUser: (e) => g({ ...r, headers: t, body: e }).then(n),
45
+ getUser: () => M({ ...r, headers: t }).then(n),
46
+ updateUser: (e) => f({ ...r, headers: t, body: e }).then(n),
47
+ deleteUser: () => U({ ...r, headers: t }).then(n),
48
+ createEvent: (e) => C({ ...r, headers: t, body: e }).then(n),
49
+ getEvent: ({ eventId: e }) => m({ ...r, headers: t, path: { id: e } }).then(n),
50
+ listenConversation: ({ conversationId: e }) => {
51
+ let s = null;
52
+ const i = new _();
53
+ return (() => {
54
+ s && s.close();
55
+ const u = `${p}/conversations/${e}/listen`;
56
+ s = new N(u, {
57
+ fetch: (c, o) => fetch(c, {
58
+ ...o,
59
+ headers: {
60
+ ...o == null ? void 0 : o.headers,
61
+ ...t,
62
+ timeout: "60_000"
63
+ }
64
+ })
65
+ }), s.onopen = () => i.emit("open"), s.onerror = (c) => {
66
+ i.emit("error", c);
67
+ }, s.onmessage = (c) => {
68
+ const o = j(c.data);
69
+ i.emit(o.type, o.data);
70
+ };
71
+ })(), i.on.bind(i);
72
+ }
73
+ };
74
+ }, j = (a) => {
75
+ try {
76
+ return JSON.parse(a);
77
+ } catch {
78
+ return a;
79
+ }
80
+ };
81
+ export {
82
+ K as createClient,
83
+ I as createUser
84
+ };
@@ -0,0 +1,116 @@
1
+ import { client as r } from "./webchat-client4.js";
2
+ const a = (e) => (e.client ?? r).delete({
3
+ url: "/conversations/{id}",
4
+ ...e
5
+ }), c = (e) => (e.client ?? r).get({
6
+ url: "/conversations/{id}",
7
+ ...e
8
+ }), n = (e) => (e.client ?? r).get({
9
+ url: "/conversations",
10
+ ...e
11
+ }), l = (e) => (e.client ?? r).post({
12
+ url: "/conversations",
13
+ ...e,
14
+ headers: {
15
+ "Content-Type": "application/json",
16
+ ...e == null ? void 0 : e.headers
17
+ }
18
+ }), s = (e) => (e.client ?? r).get({
19
+ url: "/conversations/{id}/messages",
20
+ ...e
21
+ }), u = (e) => (e.client ?? r).get({
22
+ url: "/conversations/{id}/participants",
23
+ ...e
24
+ }), d = (e) => (e.client ?? r).post({
25
+ url: "/conversations/{id}/participants",
26
+ ...e,
27
+ headers: {
28
+ "Content-Type": "application/json",
29
+ ...e == null ? void 0 : e.headers
30
+ }
31
+ }), g = (e) => (e.client ?? r).delete({
32
+ url: "/conversations/{id}/participants/{userId}",
33
+ ...e
34
+ }), i = (e) => (e.client ?? r).get({
35
+ url: "/conversations/{id}/participants/{userId}",
36
+ ...e
37
+ }), v = (e) => (e.client ?? r).delete({
38
+ url: "/messages/{id}",
39
+ ...e
40
+ }), h = (e) => (e.client ?? r).get({
41
+ url: "/messages/{id}",
42
+ ...e
43
+ }), C = (e) => (e.client ?? r).put({
44
+ url: "/messages/{id}",
45
+ ...e,
46
+ headers: {
47
+ "Content-Type": "application/json",
48
+ ...e == null ? void 0 : e.headers
49
+ }
50
+ }), m = (e) => (e.client ?? r).post({
51
+ url: "/messages",
52
+ ...e,
53
+ headers: {
54
+ "Content-Type": "application/json",
55
+ ...e == null ? void 0 : e.headers
56
+ }
57
+ }), j = (e) => (e.client ?? r).delete({
58
+ url: "/users/me",
59
+ ...e
60
+ }), y = (e) => (e.client ?? r).get({
61
+ url: "/users/me",
62
+ ...e
63
+ }), T = (e) => (e.client ?? r).put({
64
+ url: "/users/me",
65
+ ...e,
66
+ headers: {
67
+ "Content-Type": "application/json",
68
+ ...e == null ? void 0 : e.headers
69
+ }
70
+ }), M = (e) => ((e == null ? void 0 : e.client) ?? r).post({
71
+ url: "/users",
72
+ ...e,
73
+ headers: {
74
+ "Content-Type": "application/json",
75
+ ...e == null ? void 0 : e.headers
76
+ }
77
+ }), P = (e) => (e.client ?? r).get({
78
+ url: "/events/{id}",
79
+ ...e
80
+ }), U = (e) => (e.client ?? r).post({
81
+ url: "/events",
82
+ ...e,
83
+ headers: {
84
+ "Content-Type": "application/json",
85
+ ...e == null ? void 0 : e.headers
86
+ }
87
+ }), f = (e) => (e.client ?? r).post({
88
+ url: "/files",
89
+ ...e,
90
+ headers: {
91
+ "Content-Type": "application/json",
92
+ ...e == null ? void 0 : e.headers
93
+ }
94
+ });
95
+ export {
96
+ d as addParticipant,
97
+ l as createConversation,
98
+ U as createEvent,
99
+ f as createFile,
100
+ m as createMessage,
101
+ M as createUser,
102
+ a as deleteConversation,
103
+ v as deleteMessage,
104
+ j as deleteUser,
105
+ c as getConversation,
106
+ P as getEvent,
107
+ h as getMessage,
108
+ i as getParticipant,
109
+ y as getUser,
110
+ s as listConversationMessages,
111
+ n as listConversations,
112
+ u as listParticipants,
113
+ g as removeParticipant,
114
+ C as updateMessage,
115
+ T as updateUser
116
+ };
@@ -0,0 +1,8 @@
1
+ import { createClient as t, createConfig as e } from "./webchat-client9.js";
2
+ import { createClientConfig as o } from "./webchat-client7.js";
3
+ const i = /* @__PURE__ */ t(/* @__PURE__ */ o(/* @__PURE__ */ e({
4
+ baseUrl: "https://webchat.botpress.cloud/"
5
+ })));
6
+ export {
7
+ i as client
8
+ };
@@ -0,0 +1,272 @@
1
+ import { createParser as X } from "./webchat-client8.js";
2
+ class q extends Event {
3
+ /**
4
+ * Constructs a new `ErrorEvent` instance. This is typically not called directly,
5
+ * but rather emitted by the `EventSource` object when an error occurs.
6
+ *
7
+ * @param type - The type of the event (should be "error")
8
+ * @param errorEventInitDict - Optional properties to include in the error event
9
+ */
10
+ constructor(e, i) {
11
+ var r, c;
12
+ super(e), this.code = (r = i == null ? void 0 : i.code) != null ? r : void 0, this.message = (c = i == null ? void 0 : i.message) != null ? c : void 0;
13
+ }
14
+ /**
15
+ * Node.js "hides" the `message` and `code` properties of the `ErrorEvent` instance,
16
+ * when it is `console.log`'ed. This makes it harder to debug errors. To ease debugging,
17
+ * we explicitly include the properties in the `inspect` method.
18
+ *
19
+ * This is automatically called by Node.js when you `console.log` an instance of this class.
20
+ *
21
+ * @param _depth - The current depth
22
+ * @param options - The options passed to `util.inspect`
23
+ * @param inspect - The inspect function to use (prevents having to import it from `util`)
24
+ * @returns A string representation of the error
25
+ */
26
+ [Symbol.for("nodejs.util.inspect.custom")](e, i, r) {
27
+ return r(B(this), i);
28
+ }
29
+ /**
30
+ * Deno "hides" the `message` and `code` properties of the `ErrorEvent` instance,
31
+ * when it is `console.log`'ed. This makes it harder to debug errors. To ease debugging,
32
+ * we explicitly include the properties in the `inspect` method.
33
+ *
34
+ * This is automatically called by Deno when you `console.log` an instance of this class.
35
+ *
36
+ * @param inspect - The inspect function to use (prevents having to import it from `util`)
37
+ * @param options - The options passed to `Deno.inspect`
38
+ * @returns A string representation of the error
39
+ */
40
+ [Symbol.for("Deno.customInspect")](e, i) {
41
+ return e(B(this), i);
42
+ }
43
+ }
44
+ function Y(t) {
45
+ const e = globalThis.DOMException;
46
+ return typeof e == "function" ? new e(t, "SyntaxError") : new SyntaxError(t);
47
+ }
48
+ function T(t) {
49
+ return t instanceof Error ? "errors" in t && Array.isArray(t.errors) ? t.errors.map(T).join(", ") : "cause" in t && t.cause instanceof Error ? `${t}: ${T(t.cause)}` : t.message : `${t}`;
50
+ }
51
+ function B(t) {
52
+ return {
53
+ type: t.type,
54
+ message: t.message,
55
+ code: t.code,
56
+ defaultPrevented: t.defaultPrevented,
57
+ cancelable: t.cancelable,
58
+ timeStamp: t.timeStamp
59
+ };
60
+ }
61
+ var z = (t) => {
62
+ throw TypeError(t);
63
+ }, D = (t, e, i) => e.has(t) || z("Cannot " + i), s = (t, e, i) => (D(t, e, "read from private field"), i ? i.call(t) : e.get(t)), a = (t, e, i) => e.has(t) ? z("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, i), n = (t, e, i, r) => (D(t, e, "write to private field"), e.set(t, i), i), d = (t, e, i) => (D(t, e, "access private method"), i), h, u, E, W, O, M, _, N, p, f, g, w, C, l, L, b, R, H, x, I, y, U, A;
64
+ class S extends EventTarget {
65
+ constructor(e, i) {
66
+ var r, c;
67
+ super(), a(this, l), this.CONNECTING = 0, this.OPEN = 1, this.CLOSED = 2, a(this, h), a(this, u), a(this, E), a(this, W), a(this, O), a(this, M), a(this, _), a(this, N, null), a(this, p), a(this, f), a(this, g, null), a(this, w, null), a(this, C, null), a(this, b, async (o) => {
68
+ var m;
69
+ s(this, f).reset();
70
+ const { body: k, redirected: J, status: v, headers: K } = o;
71
+ if (v === 204) {
72
+ d(this, l, y).call(this, "Server sent HTTP 204, not reconnecting", 204), this.close();
73
+ return;
74
+ }
75
+ if (J ? n(this, E, new URL(o.url)) : n(this, E, void 0), v !== 200) {
76
+ d(this, l, y).call(this, `Non-200 status code (${v})`, v);
77
+ return;
78
+ }
79
+ if (!(K.get("content-type") || "").startsWith("text/event-stream")) {
80
+ d(this, l, y).call(this, 'Invalid content type, expected "text/event-stream"', v);
81
+ return;
82
+ }
83
+ if (s(this, h) === this.CLOSED)
84
+ return;
85
+ n(this, h, this.OPEN);
86
+ const G = new Event("open");
87
+ if ((m = s(this, C)) == null || m.call(this, G), this.dispatchEvent(G), typeof k != "object" || !k || !("getReader" in k)) {
88
+ d(this, l, y).call(this, "Invalid response body, expected a web ReadableStream", v), this.close();
89
+ return;
90
+ }
91
+ const Q = new TextDecoder(), V = k.getReader();
92
+ let P = !0;
93
+ do {
94
+ const { done: $, value: F } = await V.read();
95
+ F && s(this, f).feed(Q.decode(F, { stream: !$ })), $ && (P = !1, s(this, f).reset(), d(this, l, U).call(this));
96
+ } while (P);
97
+ }), a(this, R, (o) => {
98
+ n(this, p, void 0), !(o.name === "AbortError" || o.type === "aborted") && d(this, l, U).call(this, T(o));
99
+ }), a(this, x, (o) => {
100
+ typeof o.id == "string" && n(this, N, o.id);
101
+ const m = new MessageEvent(o.event || "message", {
102
+ data: o.data,
103
+ origin: s(this, E) ? s(this, E).origin : s(this, u).origin,
104
+ lastEventId: o.id || ""
105
+ });
106
+ s(this, w) && (!o.event || o.event === "message") && s(this, w).call(this, m), this.dispatchEvent(m);
107
+ }), a(this, I, (o) => {
108
+ n(this, M, o);
109
+ }), a(this, A, () => {
110
+ n(this, _, void 0), s(this, h) === this.CONNECTING && d(this, l, L).call(this);
111
+ });
112
+ try {
113
+ if (e instanceof URL)
114
+ n(this, u, e);
115
+ else if (typeof e == "string")
116
+ n(this, u, new URL(e, Z()));
117
+ else
118
+ throw new Error("Invalid URL");
119
+ } catch {
120
+ throw Y("An invalid or illegal string was specified");
121
+ }
122
+ n(this, f, X({
123
+ onEvent: s(this, x),
124
+ onRetry: s(this, I)
125
+ })), n(this, h, this.CONNECTING), n(this, M, 3e3), n(this, O, (r = i == null ? void 0 : i.fetch) != null ? r : globalThis.fetch), n(this, W, (c = i == null ? void 0 : i.withCredentials) != null ? c : !1), d(this, l, L).call(this);
126
+ }
127
+ /**
128
+ * Returns the state of this EventSource object's connection. It can have the values described below.
129
+ *
130
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/readyState)
131
+ *
132
+ * Note: typed as `number` instead of `0 | 1 | 2` for compatibility with the `EventSource` interface,
133
+ * defined in the TypeScript `dom` library.
134
+ *
135
+ * @public
136
+ */
137
+ get readyState() {
138
+ return s(this, h);
139
+ }
140
+ /**
141
+ * Returns the URL providing the event stream.
142
+ *
143
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/url)
144
+ *
145
+ * @public
146
+ */
147
+ get url() {
148
+ return s(this, u).href;
149
+ }
150
+ /**
151
+ * Returns true if the credentials mode for connection requests to the URL providing the event stream is set to "include", and false otherwise.
152
+ *
153
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/withCredentials)
154
+ */
155
+ get withCredentials() {
156
+ return s(this, W);
157
+ }
158
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/error_event) */
159
+ get onerror() {
160
+ return s(this, g);
161
+ }
162
+ set onerror(e) {
163
+ n(this, g, e);
164
+ }
165
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/message_event) */
166
+ get onmessage() {
167
+ return s(this, w);
168
+ }
169
+ set onmessage(e) {
170
+ n(this, w, e);
171
+ }
172
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/open_event) */
173
+ get onopen() {
174
+ return s(this, C);
175
+ }
176
+ set onopen(e) {
177
+ n(this, C, e);
178
+ }
179
+ addEventListener(e, i, r) {
180
+ const c = i;
181
+ super.addEventListener(e, c, r);
182
+ }
183
+ removeEventListener(e, i, r) {
184
+ const c = i;
185
+ super.removeEventListener(e, c, r);
186
+ }
187
+ /**
188
+ * Aborts any instances of the fetch algorithm started for this EventSource object, and sets the readyState attribute to CLOSED.
189
+ *
190
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/close)
191
+ *
192
+ * @public
193
+ */
194
+ close() {
195
+ s(this, _) && clearTimeout(s(this, _)), s(this, h) !== this.CLOSED && (s(this, p) && s(this, p).abort(), n(this, h, this.CLOSED), n(this, p, void 0));
196
+ }
197
+ }
198
+ h = /* @__PURE__ */ new WeakMap(), u = /* @__PURE__ */ new WeakMap(), E = /* @__PURE__ */ new WeakMap(), W = /* @__PURE__ */ new WeakMap(), O = /* @__PURE__ */ new WeakMap(), M = /* @__PURE__ */ new WeakMap(), _ = /* @__PURE__ */ new WeakMap(), N = /* @__PURE__ */ new WeakMap(), p = /* @__PURE__ */ new WeakMap(), f = /* @__PURE__ */ new WeakMap(), g = /* @__PURE__ */ new WeakMap(), w = /* @__PURE__ */ new WeakMap(), C = /* @__PURE__ */ new WeakMap(), l = /* @__PURE__ */ new WeakSet(), /**
199
+ * Connect to the given URL and start receiving events
200
+ *
201
+ * @internal
202
+ */
203
+ L = function() {
204
+ n(this, h, this.CONNECTING), n(this, p, new AbortController()), s(this, O)(s(this, u), d(this, l, H).call(this)).then(s(this, b)).catch(s(this, R));
205
+ }, b = /* @__PURE__ */ new WeakMap(), R = /* @__PURE__ */ new WeakMap(), /**
206
+ * Get request options for the `fetch()` request
207
+ *
208
+ * @returns The request options
209
+ * @internal
210
+ */
211
+ H = function() {
212
+ var t;
213
+ const e = {
214
+ // [spec] Let `corsAttributeState` be `Anonymous`…
215
+ // [spec] …will have their mode set to "cors"…
216
+ mode: "cors",
217
+ redirect: "follow",
218
+ headers: { Accept: "text/event-stream", ...s(this, N) ? { "Last-Event-ID": s(this, N) } : void 0 },
219
+ cache: "no-store",
220
+ signal: (t = s(this, p)) == null ? void 0 : t.signal
221
+ };
222
+ return "window" in globalThis && (e.credentials = this.withCredentials ? "include" : "same-origin"), e;
223
+ }, x = /* @__PURE__ */ new WeakMap(), I = /* @__PURE__ */ new WeakMap(), /**
224
+ * Handles the process referred to in the EventSource specification as "failing a connection".
225
+ *
226
+ * @param error - The error causing the connection to fail
227
+ * @param code - The HTTP status code, if available
228
+ * @internal
229
+ */
230
+ y = function(t, e) {
231
+ var i;
232
+ s(this, h) !== this.CLOSED && n(this, h, this.CLOSED);
233
+ const r = new q("error", { code: e, message: t });
234
+ (i = s(this, g)) == null || i.call(this, r), this.dispatchEvent(r);
235
+ }, /**
236
+ * Schedules a reconnection attempt against the EventSource endpoint.
237
+ *
238
+ * @param message - The error causing the connection to fail
239
+ * @param code - The HTTP status code, if available
240
+ * @internal
241
+ */
242
+ U = function(t, e) {
243
+ var i;
244
+ if (s(this, h) === this.CLOSED)
245
+ return;
246
+ n(this, h, this.CONNECTING);
247
+ const r = new q("error", { code: e, message: t });
248
+ (i = s(this, g)) == null || i.call(this, r), this.dispatchEvent(r), n(this, _, setTimeout(s(this, A), s(this, M)));
249
+ }, A = /* @__PURE__ */ new WeakMap(), /**
250
+ * ReadyState representing an EventSource currently trying to connect
251
+ *
252
+ * @public
253
+ */
254
+ S.CONNECTING = 0, /**
255
+ * ReadyState representing an EventSource connection that is open (eg connected)
256
+ *
257
+ * @public
258
+ */
259
+ S.OPEN = 1, /**
260
+ * ReadyState representing an EventSource connection that is closed (eg disconnected)
261
+ *
262
+ * @public
263
+ */
264
+ S.CLOSED = 2;
265
+ function Z() {
266
+ const t = "document" in globalThis ? globalThis.document : void 0;
267
+ return t && typeof t == "object" && "baseURI" in t && typeof t.baseURI == "string" ? t.baseURI : void 0;
268
+ }
269
+ export {
270
+ q as ErrorEvent,
271
+ S as EventSource
272
+ };
@@ -0,0 +1,23 @@
1
+ class h {
2
+ constructor() {
3
+ this.eventMap = {};
4
+ }
5
+ on(t, e) {
6
+ var a;
7
+ return this.eventMap[t] || (this.eventMap[t] = /* @__PURE__ */ new Set()), (a = this.eventMap[t]) == null || a.add(e), () => {
8
+ var i;
9
+ (i = this.eventMap[t]) == null || i.delete(e);
10
+ };
11
+ }
12
+ emit(t, e) {
13
+ var a, i;
14
+ (a = this.eventMap[t]) == null || a.forEach((p) => {
15
+ p(e);
16
+ }), (i = this.eventMap["*"]) == null || i.forEach((p) => {
17
+ p({ type: t, payload: e });
18
+ });
19
+ }
20
+ }
21
+ export {
22
+ h as EventEmitter
23
+ };
@@ -0,0 +1,11 @@
1
+ const e = (t) => ({
2
+ ...t,
3
+ withCredentials: !0,
4
+ timeout: 6e4,
5
+ maxBodyLength: 104857600,
6
+ maxContentLength: 104857600,
7
+ throwOnError: !0
8
+ });
9
+ export {
10
+ e as createClientConfig
11
+ };
@@ -0,0 +1,105 @@
1
+ class E extends Error {
2
+ constructor(d, s) {
3
+ super(d), this.name = "ParseError", this.type = s.type, this.field = s.field, this.value = s.value, this.line = s.line;
4
+ }
5
+ }
6
+ function x(n) {
7
+ }
8
+ function I(n) {
9
+ if (typeof n == "function")
10
+ throw new TypeError(
11
+ "`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?"
12
+ );
13
+ const { onEvent: d = x, onError: s = x, onRetry: r = x, onComment: a } = n;
14
+ let i = "", o = !0, f, c = "", p = "";
15
+ function b(e) {
16
+ const t = o ? e.replace(/^\xEF\xBB\xBF/, "") : e, [l, u] = w(`${i}${t}`);
17
+ for (const h of l)
18
+ y(h);
19
+ i = u, o = !1;
20
+ }
21
+ function y(e) {
22
+ if (e === "") {
23
+ v();
24
+ return;
25
+ }
26
+ if (e.startsWith(":")) {
27
+ a && a(e.slice(e.startsWith(": ") ? 2 : 1));
28
+ return;
29
+ }
30
+ const t = e.indexOf(":");
31
+ if (t !== -1) {
32
+ const l = e.slice(0, t), u = e[t + 1] === " " ? 2 : 1, h = e.slice(t + u);
33
+ m(l, h, e);
34
+ return;
35
+ }
36
+ m(e, "", e);
37
+ }
38
+ function m(e, t, l) {
39
+ switch (e) {
40
+ case "event":
41
+ p = t;
42
+ break;
43
+ case "data":
44
+ c = `${c}${t}
45
+ `;
46
+ break;
47
+ case "id":
48
+ f = t.includes("\0") ? void 0 : t;
49
+ break;
50
+ case "retry":
51
+ /^\d+$/.test(t) ? r(parseInt(t, 10)) : s(
52
+ new E(`Invalid \`retry\` value: "${t}"`, {
53
+ type: "invalid-retry",
54
+ value: t,
55
+ line: l
56
+ })
57
+ );
58
+ break;
59
+ default:
60
+ s(
61
+ new E(
62
+ `Unknown field "${e.length > 20 ? `${e.slice(0, 20)}…` : e}"`,
63
+ { type: "unknown-field", field: e, value: t, line: l }
64
+ )
65
+ );
66
+ break;
67
+ }
68
+ }
69
+ function v() {
70
+ c.length > 0 && d({
71
+ id: f,
72
+ event: p || void 0,
73
+ // If the data buffer's last character is a U+000A LINE FEED (LF) character,
74
+ // then remove the last character from the data buffer.
75
+ data: c.endsWith(`
76
+ `) ? c.slice(0, -1) : c
77
+ }), f = void 0, c = "", p = "";
78
+ }
79
+ function $(e = {}) {
80
+ i && e.consume && y(i), o = !0, f = void 0, c = "", p = "", i = "";
81
+ }
82
+ return { feed: b, reset: $ };
83
+ }
84
+ function w(n) {
85
+ const d = [];
86
+ let s = "", r = 0;
87
+ for (; r < n.length; ) {
88
+ const a = n.indexOf("\r", r), i = n.indexOf(`
89
+ `, r);
90
+ let o = -1;
91
+ if (a !== -1 && i !== -1 ? o = Math.min(a, i) : a !== -1 ? o = a : i !== -1 && (o = i), o === -1) {
92
+ s = n.slice(r);
93
+ break;
94
+ } else {
95
+ const f = n.slice(r, o);
96
+ d.push(f), r = o + 1, n[r - 1] === "\r" && n[r] === `
97
+ ` && r++;
98
+ }
99
+ }
100
+ return [d, s];
101
+ }
102
+ export {
103
+ E as ParseError,
104
+ I as createParser
105
+ };