n8n-nodes-pocketbase 2.3.25 → 2.3.26
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,131 +1,78 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
2
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
-
var
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __esm = (fn, res, err) => function __init() {
|
|
7
|
+
if (err) throw err[0];
|
|
4
8
|
try {
|
|
5
|
-
return
|
|
9
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
6
10
|
} catch (e) {
|
|
7
|
-
throw
|
|
11
|
+
throw err = [e], e;
|
|
8
12
|
}
|
|
9
13
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
function noop(_arg) {
|
|
22
|
-
}
|
|
23
|
-
function createParser(callbacks) {
|
|
24
|
-
if (typeof callbacks == "function")
|
|
25
|
-
throw new TypeError(
|
|
26
|
-
"`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?"
|
|
27
|
-
);
|
|
28
|
-
const { onEvent = noop, onError = noop, onRetry = noop, onComment } = callbacks;
|
|
29
|
-
let incompleteLine = "", isFirstChunk = true, id, data = "", eventType = "";
|
|
30
|
-
function feed(newChunk) {
|
|
31
|
-
const chunk = isFirstChunk ? newChunk.replace(/^\xEF\xBB\xBF/, "") : newChunk, [complete, incomplete] = splitLines(`${incompleteLine}${chunk}`);
|
|
32
|
-
for (const line of complete)
|
|
33
|
-
parseLine(line);
|
|
34
|
-
incompleteLine = incomplete, isFirstChunk = false;
|
|
35
|
-
}
|
|
36
|
-
function parseLine(line) {
|
|
37
|
-
if (line === "") {
|
|
38
|
-
dispatchEvent();
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
if (line.startsWith(":")) {
|
|
42
|
-
onComment && onComment(line.slice(line.startsWith(": ") ? 2 : 1));
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
const fieldSeparatorIndex = line.indexOf(":");
|
|
46
|
-
if (fieldSeparatorIndex !== -1) {
|
|
47
|
-
const field = line.slice(0, fieldSeparatorIndex), offset = line[fieldSeparatorIndex + 1] === " " ? 2 : 1, value = line.slice(fieldSeparatorIndex + offset);
|
|
48
|
-
processField(field, value, line);
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
processField(line, "", line);
|
|
52
|
-
}
|
|
53
|
-
function processField(field, value, line) {
|
|
54
|
-
switch (field) {
|
|
55
|
-
case "event":
|
|
56
|
-
eventType = value;
|
|
57
|
-
break;
|
|
58
|
-
case "data":
|
|
59
|
-
data = `${data}${value}
|
|
60
|
-
`;
|
|
61
|
-
break;
|
|
62
|
-
case "id":
|
|
63
|
-
id = value.includes("\0") ? void 0 : value;
|
|
64
|
-
break;
|
|
65
|
-
case "retry":
|
|
66
|
-
/^\d+$/.test(value) ? onRetry(parseInt(value, 10)) : onError(
|
|
67
|
-
new ParseError(`Invalid \`retry\` value: "${value}"`, {
|
|
68
|
-
type: "invalid-retry",
|
|
69
|
-
value,
|
|
70
|
-
line
|
|
71
|
-
})
|
|
72
|
-
);
|
|
73
|
-
break;
|
|
74
|
-
default:
|
|
75
|
-
onError(
|
|
76
|
-
new ParseError(
|
|
77
|
-
`Unknown field "${field.length > 20 ? `${field.slice(0, 20)}\u2026` : field}"`,
|
|
78
|
-
{ type: "unknown-field", field, value, line }
|
|
79
|
-
)
|
|
80
|
-
);
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
function dispatchEvent() {
|
|
85
|
-
data.length > 0 && onEvent({
|
|
86
|
-
id,
|
|
87
|
-
event: eventType || void 0,
|
|
88
|
-
// If the data buffer's last character is a U+000A LINE FEED (LF) character,
|
|
89
|
-
// then remove the last character from the data buffer.
|
|
90
|
-
data: data.endsWith(`
|
|
91
|
-
`) ? data.slice(0, -1) : data
|
|
92
|
-
}), id = void 0, data = "", eventType = "";
|
|
93
|
-
}
|
|
94
|
-
function reset(options = {}) {
|
|
95
|
-
incompleteLine && options.consume && parseLine(incompleteLine), isFirstChunk = true, id = void 0, data = "", eventType = "", incompleteLine = "";
|
|
96
|
-
}
|
|
97
|
-
return { feed, reset };
|
|
98
|
-
}
|
|
99
|
-
function splitLines(chunk) {
|
|
100
|
-
const lines = [];
|
|
101
|
-
let incompleteLine = "", searchIndex = 0;
|
|
102
|
-
for (; searchIndex < chunk.length; ) {
|
|
103
|
-
const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
|
|
104
|
-
`, searchIndex);
|
|
105
|
-
let lineEnd = -1;
|
|
106
|
-
if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) {
|
|
107
|
-
incompleteLine = chunk.slice(searchIndex);
|
|
108
|
-
break;
|
|
109
|
-
} else {
|
|
110
|
-
const line = chunk.slice(searchIndex, lineEnd);
|
|
111
|
-
lines.push(line), searchIndex = lineEnd + 1, chunk[searchIndex - 1] === "\r" && chunk[searchIndex] === `
|
|
112
|
-
` && searchIndex++;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return [lines, incompleteLine];
|
|
116
|
-
}
|
|
117
|
-
exports2.ParseError = ParseError;
|
|
118
|
-
exports2.createParser = createParser;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
119
23
|
}
|
|
120
|
-
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
121
27
|
|
|
122
|
-
// node_modules/eventsource/dist/
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
28
|
+
// node_modules/eventsource/dist/errors.js
|
|
29
|
+
function syntaxError(message) {
|
|
30
|
+
const DomException = globalThis.DOMException;
|
|
31
|
+
if (typeof DomException === "function") {
|
|
32
|
+
return new DomException(message, "SyntaxError");
|
|
33
|
+
}
|
|
34
|
+
return new SyntaxError(message);
|
|
35
|
+
}
|
|
36
|
+
function flattenError(err) {
|
|
37
|
+
if (!(err instanceof Error)) {
|
|
38
|
+
return `${err}`;
|
|
39
|
+
}
|
|
40
|
+
if ("errors" in err && Array.isArray(err.errors)) {
|
|
41
|
+
return err.errors.map(flattenError).join(", ");
|
|
42
|
+
}
|
|
43
|
+
if ("cause" in err && err.cause instanceof Error) {
|
|
44
|
+
return `${err}: ${flattenError(err.cause)}`;
|
|
45
|
+
}
|
|
46
|
+
return err.message;
|
|
47
|
+
}
|
|
48
|
+
function inspectableError(err) {
|
|
49
|
+
return {
|
|
50
|
+
type: err.type,
|
|
51
|
+
message: err.message,
|
|
52
|
+
code: err.code,
|
|
53
|
+
defaultPrevented: err.defaultPrevented,
|
|
54
|
+
cancelable: err.cancelable,
|
|
55
|
+
timeStamp: err.timeStamp
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
var ErrorEvent;
|
|
59
|
+
var init_errors = __esm({
|
|
60
|
+
"node_modules/eventsource/dist/errors.js"() {
|
|
61
|
+
ErrorEvent = class extends Event {
|
|
62
|
+
/**
|
|
63
|
+
* HTTP status code, if this was triggered by an HTTP error
|
|
64
|
+
* Note: this is not part of the spec, but is included for better error handling.
|
|
65
|
+
*
|
|
66
|
+
* @public
|
|
67
|
+
*/
|
|
68
|
+
code;
|
|
69
|
+
/**
|
|
70
|
+
* Optional message attached to the error.
|
|
71
|
+
* Note: this is not part of the spec, but is included for better error handling.
|
|
72
|
+
*
|
|
73
|
+
* @public
|
|
74
|
+
*/
|
|
75
|
+
message;
|
|
129
76
|
/**
|
|
130
77
|
* Constructs a new `ErrorEvent` instance. This is typically not called directly,
|
|
131
78
|
* but rather emitted by the `EventSource` object when an error occurs.
|
|
@@ -134,8 +81,9 @@ var require_dist2 = __commonJS({
|
|
|
134
81
|
* @param errorEventInitDict - Optional properties to include in the error event
|
|
135
82
|
*/
|
|
136
83
|
constructor(type, errorEventInitDict) {
|
|
137
|
-
|
|
138
|
-
|
|
84
|
+
super(type);
|
|
85
|
+
this.code = errorEventInitDict?.code ?? void 0;
|
|
86
|
+
this.message = errorEventInitDict?.message ?? void 0;
|
|
139
87
|
}
|
|
140
88
|
/**
|
|
141
89
|
* Node.js "hides" the `message` and `code` properties of the `ErrorEvent` instance,
|
|
@@ -167,168 +115,433 @@ var require_dist2 = __commonJS({
|
|
|
167
115
|
return inspect(inspectableError(this), options);
|
|
168
116
|
}
|
|
169
117
|
};
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
var __typeError = (msg) => {
|
|
188
|
-
throw TypeError(msg);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// node_modules/eventsource-parser/dist/errors.js
|
|
122
|
+
var ParseError;
|
|
123
|
+
var init_errors2 = __esm({
|
|
124
|
+
"node_modules/eventsource-parser/dist/errors.js"() {
|
|
125
|
+
ParseError = class extends Error {
|
|
126
|
+
constructor(message, options) {
|
|
127
|
+
super(message);
|
|
128
|
+
this.name = "ParseError";
|
|
129
|
+
this.type = options.type;
|
|
130
|
+
this.field = options.field;
|
|
131
|
+
this.value = options.value;
|
|
132
|
+
this.line = options.line;
|
|
133
|
+
}
|
|
189
134
|
};
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// node_modules/eventsource-parser/dist/parse.js
|
|
139
|
+
function createParser(config) {
|
|
140
|
+
if (typeof config === "function") {
|
|
141
|
+
throw new TypeError("`config` must be an object, got a function instead. Did you mean `createParser({onEvent: fn})`?");
|
|
142
|
+
}
|
|
143
|
+
const { maxBufferSize, onComment, onError, onEvent, onId, onRetry } = config;
|
|
144
|
+
const pendingFragments = [];
|
|
145
|
+
let pendingFragmentsLength = 0;
|
|
146
|
+
let isFirstChunk = true;
|
|
147
|
+
let id;
|
|
148
|
+
let data = "";
|
|
149
|
+
let dataLines = 0;
|
|
150
|
+
let eventType;
|
|
151
|
+
let terminated = false;
|
|
152
|
+
let skippingLine = false;
|
|
153
|
+
let skipNextLineFeed = false;
|
|
154
|
+
function feed(chunk) {
|
|
155
|
+
if (terminated) {
|
|
156
|
+
throw new Error("Cannot feed parser: it was terminated after exceeding the configured max buffer size. Call `reset()` to resume parsing.");
|
|
157
|
+
}
|
|
158
|
+
if (isFirstChunk) {
|
|
159
|
+
isFirstChunk = false;
|
|
160
|
+
if (chunk.charCodeAt(0) === 65279) {
|
|
161
|
+
chunk = chunk.slice(1);
|
|
162
|
+
} else if (chunk.charCodeAt(0) === 239 && chunk.charCodeAt(1) === 187 && chunk.charCodeAt(2) === 191) {
|
|
163
|
+
chunk = chunk.slice(3);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (skippingLine || skipNextLineFeed) {
|
|
167
|
+
chunk = resumeAfterSkip(chunk);
|
|
168
|
+
if (!chunk) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (!pendingFragments.length) {
|
|
173
|
+
const trailing = processLines(chunk);
|
|
174
|
+
if (trailing !== "") {
|
|
175
|
+
storeTrailing(trailing);
|
|
176
|
+
}
|
|
177
|
+
checkBufferSize();
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (chunk.indexOf("\n") === -1 && chunk.indexOf("\r") === -1) {
|
|
181
|
+
if (pendingFragmentsLength < MAX_FIELD_PREFIX_LENGTH) {
|
|
182
|
+
const head = pendingFragments.join("") + chunk.slice(0, MAX_FIELD_PREFIX_LENGTH - pendingFragmentsLength);
|
|
183
|
+
if (!shouldBufferTrailing(head)) {
|
|
184
|
+
pendingFragments.length = 0;
|
|
185
|
+
pendingFragmentsLength = 0;
|
|
186
|
+
skippingLine = true;
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
pendingFragments.push(chunk);
|
|
191
|
+
pendingFragmentsLength += chunk.length;
|
|
192
|
+
checkBufferSize();
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
pendingFragments.push(chunk);
|
|
196
|
+
const input = pendingFragments.join("");
|
|
197
|
+
pendingFragments.length = 0;
|
|
198
|
+
pendingFragmentsLength = 0;
|
|
199
|
+
storeTrailing(processLines(input));
|
|
200
|
+
checkBufferSize();
|
|
201
|
+
}
|
|
202
|
+
function resumeAfterSkip(chunk) {
|
|
203
|
+
if (chunk.length === 0) {
|
|
204
|
+
return chunk;
|
|
205
|
+
}
|
|
206
|
+
if (skipNextLineFeed) {
|
|
207
|
+
skipNextLineFeed = false;
|
|
208
|
+
return chunk.charCodeAt(0) === LF ? chunk.slice(1) : chunk;
|
|
209
|
+
}
|
|
210
|
+
const crIndex = chunk.indexOf("\r");
|
|
211
|
+
const lfIndex = chunk.indexOf("\n");
|
|
212
|
+
const lineEnd = crIndex === -1 ? lfIndex : lfIndex === -1 ? crIndex : crIndex < lfIndex ? crIndex : lfIndex;
|
|
213
|
+
if (lineEnd === -1) {
|
|
214
|
+
return "";
|
|
215
|
+
}
|
|
216
|
+
if (lineEnd === chunk.length - 1 && chunk.charCodeAt(lineEnd) === CR) {
|
|
217
|
+
skippingLine = false;
|
|
218
|
+
skipNextLineFeed = true;
|
|
219
|
+
return "";
|
|
220
|
+
}
|
|
221
|
+
skippingLine = false;
|
|
222
|
+
return chunk.slice(lineEnd + (chunk.charCodeAt(lineEnd) === CR && chunk.charCodeAt(lineEnd + 1) === LF ? 2 : 1));
|
|
223
|
+
}
|
|
224
|
+
function storeTrailing(trailing) {
|
|
225
|
+
if (!trailing)
|
|
226
|
+
return;
|
|
227
|
+
if (trailing.charCodeAt(trailing.length - 1) === CR) {
|
|
228
|
+
parseLine(trailing, 0, trailing.length - 1);
|
|
229
|
+
skipNextLineFeed = true;
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (shouldBufferTrailing(trailing)) {
|
|
233
|
+
pendingFragments.push(trailing);
|
|
234
|
+
pendingFragmentsLength = trailing.length;
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
skippingLine = true;
|
|
238
|
+
}
|
|
239
|
+
function shouldBufferTrailing(trailing) {
|
|
240
|
+
const firstCharCode = trailing.charCodeAt(0);
|
|
241
|
+
return firstCharCode === 58 && !!onComment || firstCharCode === 100 && isPotentialField(trailing, "data") || firstCharCode === 101 && isPotentialField(trailing, "event") || firstCharCode === 105 && isPotentialField(trailing, "id") || firstCharCode === 114 && isPotentialField(trailing, "retry");
|
|
242
|
+
}
|
|
243
|
+
function checkBufferSize() {
|
|
244
|
+
if (maxBufferSize === void 0)
|
|
245
|
+
return;
|
|
246
|
+
if (pendingFragmentsLength + data.length <= maxBufferSize)
|
|
247
|
+
return;
|
|
248
|
+
terminated = true;
|
|
249
|
+
pendingFragments.length = 0;
|
|
250
|
+
pendingFragmentsLength = 0;
|
|
251
|
+
id = void 0;
|
|
252
|
+
data = "";
|
|
253
|
+
dataLines = 0;
|
|
254
|
+
eventType = void 0;
|
|
255
|
+
skippingLine = false;
|
|
256
|
+
skipNextLineFeed = false;
|
|
257
|
+
onError === null || onError === void 0 ? void 0 : onError(new ParseError(`Buffered data exceeded max buffer size of ${maxBufferSize} characters`, {
|
|
258
|
+
type: "max-buffer-size-exceeded"
|
|
259
|
+
}));
|
|
260
|
+
}
|
|
261
|
+
function processLines(chunk) {
|
|
262
|
+
let searchIndex = 0;
|
|
263
|
+
if (chunk.indexOf("\r") === -1) {
|
|
264
|
+
let lfIndex = chunk.indexOf("\n", searchIndex);
|
|
265
|
+
while (lfIndex !== -1) {
|
|
266
|
+
if (searchIndex === lfIndex) {
|
|
267
|
+
if (id !== void 0) {
|
|
268
|
+
onId === null || onId === void 0 ? void 0 : onId(id);
|
|
232
269
|
}
|
|
233
|
-
if (
|
|
234
|
-
|
|
235
|
-
return;
|
|
270
|
+
if (dataLines > 0) {
|
|
271
|
+
onEvent === null || onEvent === void 0 ? void 0 : onEvent({ id, event: eventType, data });
|
|
236
272
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
273
|
+
id = void 0;
|
|
274
|
+
data = "";
|
|
275
|
+
dataLines = 0;
|
|
276
|
+
eventType = void 0;
|
|
277
|
+
searchIndex = lfIndex + 1;
|
|
278
|
+
lfIndex = chunk.indexOf("\n", searchIndex);
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
const firstCharCode = chunk.charCodeAt(searchIndex);
|
|
282
|
+
if (isDataPrefix(chunk, searchIndex, firstCharCode)) {
|
|
283
|
+
const valueStart = chunk.charCodeAt(searchIndex + 5) === SPACE ? searchIndex + 6 : searchIndex + 5;
|
|
284
|
+
const value = chunk.slice(valueStart, lfIndex);
|
|
285
|
+
if (dataLines === 0 && chunk.charCodeAt(lfIndex + 1) === LF) {
|
|
286
|
+
if (id !== void 0) {
|
|
287
|
+
onId === null || onId === void 0 ? void 0 : onId(id);
|
|
288
|
+
}
|
|
289
|
+
onEvent === null || onEvent === void 0 ? void 0 : onEvent({ id, event: eventType, data: value });
|
|
290
|
+
id = void 0;
|
|
291
|
+
data = "";
|
|
292
|
+
eventType = void 0;
|
|
293
|
+
searchIndex = lfIndex + 2;
|
|
294
|
+
lfIndex = chunk.indexOf("\n", searchIndex);
|
|
295
|
+
continue;
|
|
244
296
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
__privateSet(this, _controller, void 0), !(err.name === "AbortError" || err.type === "aborted") && __privateMethod(this, _EventSource_instances, scheduleReconnect_fn).call(this, flattenError(err));
|
|
253
|
-
}), __privateAdd(this, _onEvent, (event) => {
|
|
254
|
-
typeof event.id == "string" && __privateSet(this, _lastEventId, event.id);
|
|
255
|
-
const messageEvent = new MessageEvent(event.event || "message", {
|
|
256
|
-
data: event.data,
|
|
257
|
-
origin: __privateGet(this, _redirectUrl) ? __privateGet(this, _redirectUrl).origin : __privateGet(this, _url).origin,
|
|
258
|
-
lastEventId: event.id || ""
|
|
259
|
-
});
|
|
260
|
-
__privateGet(this, _onMessage) && (!event.event || event.event === "message") && __privateGet(this, _onMessage).call(this, messageEvent), this.dispatchEvent(messageEvent);
|
|
261
|
-
}), __privateAdd(this, _onRetryChange, (value) => {
|
|
262
|
-
__privateSet(this, _reconnectInterval, value);
|
|
263
|
-
}), __privateAdd(this, _reconnect, () => {
|
|
264
|
-
__privateSet(this, _reconnectTimer, void 0), __privateGet(this, _readyState) === this.CONNECTING && __privateMethod(this, _EventSource_instances, connect_fn).call(this);
|
|
265
|
-
});
|
|
266
|
-
try {
|
|
267
|
-
if (url instanceof URL)
|
|
268
|
-
__privateSet(this, _url, url);
|
|
269
|
-
else if (typeof url == "string")
|
|
270
|
-
__privateSet(this, _url, new URL(url, getBaseURL()));
|
|
271
|
-
else
|
|
272
|
-
throw new Error("Invalid URL");
|
|
273
|
-
} catch {
|
|
274
|
-
throw syntaxError("An invalid or illegal string was specified");
|
|
297
|
+
data = dataLines === 0 ? value : `${data}
|
|
298
|
+
${value}`;
|
|
299
|
+
dataLines++;
|
|
300
|
+
} else if (isEventPrefix(chunk, searchIndex, firstCharCode)) {
|
|
301
|
+
eventType = chunk.slice(chunk.charCodeAt(searchIndex + 6) === SPACE ? searchIndex + 7 : searchIndex + 6, lfIndex) || void 0;
|
|
302
|
+
} else {
|
|
303
|
+
parseLine(chunk, searchIndex, lfIndex);
|
|
275
304
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
onRetry: __privateGet(this, _onRetryChange)
|
|
279
|
-
})), __privateSet(this, _readyState, this.CONNECTING), __privateSet(this, _reconnectInterval, 3e3), __privateSet(this, _fetch, (_a = eventSourceInitDict == null ? void 0 : eventSourceInitDict.fetch) != null ? _a : globalThis.fetch), __privateSet(this, _withCredentials, (_b = eventSourceInitDict == null ? void 0 : eventSourceInitDict.withCredentials) != null ? _b : false), __privateMethod(this, _EventSource_instances, connect_fn).call(this);
|
|
305
|
+
searchIndex = lfIndex + 1;
|
|
306
|
+
lfIndex = chunk.indexOf("\n", searchIndex);
|
|
280
307
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
308
|
+
return chunk.slice(searchIndex);
|
|
309
|
+
}
|
|
310
|
+
while (searchIndex < chunk.length) {
|
|
311
|
+
const crIndex = chunk.indexOf("\r", searchIndex);
|
|
312
|
+
const lfIndex = chunk.indexOf("\n", searchIndex);
|
|
313
|
+
let lineEnd = -1;
|
|
314
|
+
if (crIndex !== -1 && lfIndex !== -1) {
|
|
315
|
+
lineEnd = crIndex < lfIndex ? crIndex : lfIndex;
|
|
316
|
+
} else if (crIndex !== -1) {
|
|
317
|
+
if (crIndex === chunk.length - 1) {
|
|
318
|
+
lineEnd = -1;
|
|
319
|
+
} else {
|
|
320
|
+
lineEnd = crIndex;
|
|
321
|
+
}
|
|
322
|
+
} else if (lfIndex !== -1) {
|
|
323
|
+
lineEnd = lfIndex;
|
|
324
|
+
}
|
|
325
|
+
if (lineEnd === -1) {
|
|
326
|
+
break;
|
|
327
|
+
}
|
|
328
|
+
parseLine(chunk, searchIndex, lineEnd);
|
|
329
|
+
searchIndex = lineEnd + 1;
|
|
330
|
+
if (chunk.charCodeAt(searchIndex - 1) === CR && chunk.charCodeAt(searchIndex) === LF) {
|
|
331
|
+
searchIndex++;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return chunk.slice(searchIndex);
|
|
335
|
+
}
|
|
336
|
+
function parseLine(chunk, start, end) {
|
|
337
|
+
if (start === end) {
|
|
338
|
+
dispatchEvent();
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
const firstCharCode = chunk.charCodeAt(start);
|
|
342
|
+
if (isDataPrefix(chunk, start, firstCharCode)) {
|
|
343
|
+
const valueStart = chunk.charCodeAt(start + 5) === SPACE ? start + 6 : start + 5;
|
|
344
|
+
const value2 = chunk.slice(valueStart, end);
|
|
345
|
+
data = dataLines === 0 ? value2 : `${data}
|
|
346
|
+
${value2}`;
|
|
347
|
+
dataLines++;
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
if (isEventPrefix(chunk, start, firstCharCode)) {
|
|
351
|
+
eventType = chunk.slice(chunk.charCodeAt(start + 6) === SPACE ? start + 7 : start + 6, end) || void 0;
|
|
352
|
+
return;
|
|
353
|
+
}
|
|
354
|
+
if (firstCharCode === 105 && chunk.charCodeAt(start + 1) === 100 && chunk.charCodeAt(start + 2) === 58) {
|
|
355
|
+
const value2 = chunk.slice(chunk.charCodeAt(start + 3) === SPACE ? start + 4 : start + 3, end);
|
|
356
|
+
if (!value2.includes("\0"))
|
|
357
|
+
id = value2;
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
if (firstCharCode === 58) {
|
|
361
|
+
if (onComment) {
|
|
362
|
+
const line2 = chunk.slice(start, end);
|
|
363
|
+
onComment(line2.slice(chunk.charCodeAt(start + 1) === SPACE ? 2 : 1));
|
|
364
|
+
}
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
const line = chunk.slice(start, end);
|
|
368
|
+
const fieldSeparatorIndex = line.indexOf(":");
|
|
369
|
+
if (fieldSeparatorIndex === -1) {
|
|
370
|
+
processField(line, "", line);
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
const field = line.slice(0, fieldSeparatorIndex);
|
|
374
|
+
const offset = line.charCodeAt(fieldSeparatorIndex + 1) === SPACE ? 2 : 1;
|
|
375
|
+
const value = line.slice(fieldSeparatorIndex + offset);
|
|
376
|
+
processField(field, value, line);
|
|
377
|
+
}
|
|
378
|
+
function processField(field, value, line) {
|
|
379
|
+
switch (field) {
|
|
380
|
+
case "event":
|
|
381
|
+
eventType = value || void 0;
|
|
382
|
+
break;
|
|
383
|
+
case "data":
|
|
384
|
+
data = dataLines === 0 ? value : `${data}
|
|
385
|
+
${value}`;
|
|
386
|
+
dataLines++;
|
|
387
|
+
break;
|
|
388
|
+
case "id":
|
|
389
|
+
if (!value.includes("\0"))
|
|
390
|
+
id = value;
|
|
391
|
+
break;
|
|
392
|
+
case "retry":
|
|
393
|
+
if (/^\d+$/.test(value)) {
|
|
394
|
+
onRetry === null || onRetry === void 0 ? void 0 : onRetry(parseInt(value, 10));
|
|
395
|
+
} else {
|
|
396
|
+
onError === null || onError === void 0 ? void 0 : onError(new ParseError(`Invalid \`retry\` value: "${value}"`, {
|
|
397
|
+
type: "invalid-retry",
|
|
398
|
+
value,
|
|
399
|
+
line
|
|
400
|
+
}));
|
|
401
|
+
}
|
|
402
|
+
break;
|
|
403
|
+
default:
|
|
404
|
+
onError === null || onError === void 0 ? void 0 : onError(new ParseError(`Unknown field "${field.length > 20 ? `${field.slice(0, 20)}\u2026` : field}"`, { type: "unknown-field", field, value, line }));
|
|
405
|
+
break;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
function dispatchEvent() {
|
|
409
|
+
if (id !== void 0) {
|
|
410
|
+
onId === null || onId === void 0 ? void 0 : onId(id);
|
|
411
|
+
}
|
|
412
|
+
if (dataLines > 0) {
|
|
413
|
+
onEvent === null || onEvent === void 0 ? void 0 : onEvent({
|
|
414
|
+
id,
|
|
415
|
+
event: eventType,
|
|
416
|
+
data
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
id = void 0;
|
|
420
|
+
data = "";
|
|
421
|
+
dataLines = 0;
|
|
422
|
+
eventType = void 0;
|
|
423
|
+
}
|
|
424
|
+
function reset(options = {}) {
|
|
425
|
+
if (options.consume && pendingFragments.length > 0) {
|
|
426
|
+
const incompleteLine = pendingFragments.join("");
|
|
427
|
+
parseLine(incompleteLine, 0, incompleteLine.length);
|
|
428
|
+
}
|
|
429
|
+
isFirstChunk = true;
|
|
430
|
+
id = void 0;
|
|
431
|
+
data = "";
|
|
432
|
+
dataLines = 0;
|
|
433
|
+
eventType = void 0;
|
|
434
|
+
pendingFragments.length = 0;
|
|
435
|
+
pendingFragmentsLength = 0;
|
|
436
|
+
terminated = false;
|
|
437
|
+
skippingLine = false;
|
|
438
|
+
skipNextLineFeed = false;
|
|
439
|
+
}
|
|
440
|
+
return { feed, reset };
|
|
441
|
+
}
|
|
442
|
+
function isDataPrefix(chunk, i, firstCharCode) {
|
|
443
|
+
return firstCharCode === 100 && chunk.charCodeAt(i + 1) === 97 && chunk.charCodeAt(i + 2) === 116 && chunk.charCodeAt(i + 3) === 97 && chunk.charCodeAt(i + 4) === 58;
|
|
444
|
+
}
|
|
445
|
+
function isEventPrefix(chunk, i, firstCharCode) {
|
|
446
|
+
return firstCharCode === 101 && chunk.charCodeAt(i + 1) === 118 && chunk.charCodeAt(i + 2) === 101 && chunk.charCodeAt(i + 3) === 110 && chunk.charCodeAt(i + 4) === 116 && chunk.charCodeAt(i + 5) === 58;
|
|
447
|
+
}
|
|
448
|
+
function isPotentialField(line, field) {
|
|
449
|
+
let i = 1;
|
|
450
|
+
while (i < line.length && i < field.length) {
|
|
451
|
+
if (line.charCodeAt(i) !== field.charCodeAt(i)) {
|
|
452
|
+
return false;
|
|
453
|
+
}
|
|
454
|
+
i++;
|
|
455
|
+
}
|
|
456
|
+
return line.length <= field.length || line.charCodeAt(field.length) === 58;
|
|
457
|
+
}
|
|
458
|
+
var LF, CR, SPACE, MAX_FIELD_PREFIX_LENGTH;
|
|
459
|
+
var init_parse = __esm({
|
|
460
|
+
"node_modules/eventsource-parser/dist/parse.js"() {
|
|
461
|
+
init_errors2();
|
|
462
|
+
LF = 10;
|
|
463
|
+
CR = 13;
|
|
464
|
+
SPACE = 32;
|
|
465
|
+
MAX_FIELD_PREFIX_LENGTH = 6;
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
// node_modules/eventsource-parser/dist/index.js
|
|
470
|
+
var init_dist = __esm({
|
|
471
|
+
"node_modules/eventsource-parser/dist/index.js"() {
|
|
472
|
+
init_parse();
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
// node_modules/eventsource/dist/EventSource.js
|
|
477
|
+
function getBaseURL() {
|
|
478
|
+
const doc = "document" in globalThis ? globalThis.document : void 0;
|
|
479
|
+
return doc && typeof doc === "object" && "baseURI" in doc && typeof doc.baseURI === "string" ? doc.baseURI : void 0;
|
|
480
|
+
}
|
|
481
|
+
function defineEventProperty(event, property, value) {
|
|
482
|
+
Object.defineProperty(event, property, {
|
|
483
|
+
value,
|
|
484
|
+
enumerable: true,
|
|
485
|
+
configurable: true
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
var DEFAULT_MAX_BUFFER_SIZE, EventSourceImpl, EventSource;
|
|
489
|
+
var init_EventSource = __esm({
|
|
490
|
+
"node_modules/eventsource/dist/EventSource.js"() {
|
|
491
|
+
init_dist();
|
|
492
|
+
init_errors();
|
|
493
|
+
DEFAULT_MAX_BUFFER_SIZE = 100 * 1024 * 1024;
|
|
494
|
+
EventSourceImpl = class extends EventTarget {
|
|
495
|
+
static CONNECTING = 0;
|
|
496
|
+
static OPEN = 1;
|
|
497
|
+
static CLOSED = 2;
|
|
498
|
+
CONNECTING = 0;
|
|
499
|
+
OPEN = 1;
|
|
500
|
+
CLOSED = 2;
|
|
291
501
|
get readyState() {
|
|
292
|
-
return
|
|
502
|
+
return this.#readyState;
|
|
293
503
|
}
|
|
294
|
-
/**
|
|
295
|
-
* Returns the URL providing the event stream.
|
|
296
|
-
*
|
|
297
|
-
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/url)
|
|
298
|
-
*
|
|
299
|
-
* @public
|
|
300
|
-
*/
|
|
301
504
|
get url() {
|
|
302
|
-
return
|
|
505
|
+
return this.#url.href;
|
|
303
506
|
}
|
|
304
|
-
/**
|
|
305
|
-
* Returns true if the credentials mode for connection requests to the URL providing the event stream is set to "include", and false otherwise.
|
|
306
|
-
*
|
|
307
|
-
* [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/withCredentials)
|
|
308
|
-
*/
|
|
309
507
|
get withCredentials() {
|
|
310
|
-
return
|
|
508
|
+
return this.#withCredentials;
|
|
311
509
|
}
|
|
312
|
-
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/error_event) */
|
|
313
510
|
get onerror() {
|
|
314
|
-
return
|
|
511
|
+
return this.#onError;
|
|
315
512
|
}
|
|
316
513
|
set onerror(value) {
|
|
317
|
-
|
|
514
|
+
if (this.#onError) {
|
|
515
|
+
this.removeEventListener("error", this.#onError);
|
|
516
|
+
}
|
|
517
|
+
this.#onError = value;
|
|
518
|
+
if (value) {
|
|
519
|
+
this.addEventListener("error", value);
|
|
520
|
+
}
|
|
318
521
|
}
|
|
319
|
-
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/message_event) */
|
|
320
522
|
get onmessage() {
|
|
321
|
-
return
|
|
523
|
+
return this.#onMessage;
|
|
322
524
|
}
|
|
323
525
|
set onmessage(value) {
|
|
324
|
-
|
|
526
|
+
if (this.#onMessage) {
|
|
527
|
+
this.removeEventListener("message", this.#onMessage);
|
|
528
|
+
}
|
|
529
|
+
this.#onMessage = value;
|
|
530
|
+
if (value) {
|
|
531
|
+
this.addEventListener("message", value);
|
|
532
|
+
}
|
|
325
533
|
}
|
|
326
|
-
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/open_event) */
|
|
327
534
|
get onopen() {
|
|
328
|
-
return
|
|
535
|
+
return this.#onOpen;
|
|
329
536
|
}
|
|
330
537
|
set onopen(value) {
|
|
331
|
-
|
|
538
|
+
if (this.#onOpen) {
|
|
539
|
+
this.removeEventListener("open", this.#onOpen);
|
|
540
|
+
}
|
|
541
|
+
this.#onOpen = value;
|
|
542
|
+
if (value) {
|
|
543
|
+
this.addEventListener("open", value);
|
|
544
|
+
}
|
|
332
545
|
}
|
|
333
546
|
addEventListener(type, listener, options) {
|
|
334
547
|
const listen = listener;
|
|
@@ -338,96 +551,356 @@ var require_dist2 = __commonJS({
|
|
|
338
551
|
const listen = listener;
|
|
339
552
|
super.removeEventListener(type, listen, options);
|
|
340
553
|
}
|
|
554
|
+
constructor(url, eventSourceInitDict) {
|
|
555
|
+
super();
|
|
556
|
+
try {
|
|
557
|
+
if (url instanceof URL) {
|
|
558
|
+
this.#url = url;
|
|
559
|
+
} else if (typeof url === "string") {
|
|
560
|
+
this.#url = new URL(url, getBaseURL());
|
|
561
|
+
} else {
|
|
562
|
+
throw new Error("Invalid URL");
|
|
563
|
+
}
|
|
564
|
+
} catch {
|
|
565
|
+
throw syntaxError("An invalid or illegal string was specified");
|
|
566
|
+
}
|
|
567
|
+
this.#parser = createParser({
|
|
568
|
+
maxBufferSize: eventSourceInitDict?.maxBufferSize ?? DEFAULT_MAX_BUFFER_SIZE,
|
|
569
|
+
onEvent: this.#onEvent,
|
|
570
|
+
onError: this.#onParseError,
|
|
571
|
+
onId: this.#onIdChange,
|
|
572
|
+
onRetry: this.#onRetryChange
|
|
573
|
+
});
|
|
574
|
+
this.#readyState = this.CONNECTING;
|
|
575
|
+
this.#reconnectInterval = 3e3;
|
|
576
|
+
this.#fetch = eventSourceInitDict?.fetch ?? globalThis.fetch;
|
|
577
|
+
this.#withCredentials = eventSourceInitDict?.withCredentials ?? false;
|
|
578
|
+
this.#connect();
|
|
579
|
+
}
|
|
580
|
+
close() {
|
|
581
|
+
if (this.#reconnectTimer)
|
|
582
|
+
clearTimeout(this.#reconnectTimer);
|
|
583
|
+
if (this.#readyState === this.CLOSED)
|
|
584
|
+
return;
|
|
585
|
+
if (this.#controller)
|
|
586
|
+
this.#controller.abort();
|
|
587
|
+
this.#readyState = this.CLOSED;
|
|
588
|
+
this.#controller = void 0;
|
|
589
|
+
}
|
|
590
|
+
// PRIVATES FOLLOW
|
|
341
591
|
/**
|
|
342
|
-
*
|
|
592
|
+
* Current connection state
|
|
343
593
|
*
|
|
344
|
-
*
|
|
594
|
+
* @internal
|
|
595
|
+
*/
|
|
596
|
+
#readyState;
|
|
597
|
+
/**
|
|
598
|
+
* Original URL used to connect.
|
|
345
599
|
*
|
|
346
|
-
*
|
|
600
|
+
* Note that this will stay the same even after a redirect.
|
|
601
|
+
*
|
|
602
|
+
* @internal
|
|
347
603
|
*/
|
|
348
|
-
|
|
349
|
-
|
|
604
|
+
#url;
|
|
605
|
+
/**
|
|
606
|
+
* The destination URL after a redirect. Is reset on reconnection.
|
|
607
|
+
*
|
|
608
|
+
* @internal
|
|
609
|
+
*/
|
|
610
|
+
#redirectUrl;
|
|
611
|
+
/**
|
|
612
|
+
* Whether to include credentials in the request
|
|
613
|
+
*
|
|
614
|
+
* @internal
|
|
615
|
+
*/
|
|
616
|
+
#withCredentials;
|
|
617
|
+
/**
|
|
618
|
+
* The fetch implementation to use
|
|
619
|
+
*
|
|
620
|
+
* @internal
|
|
621
|
+
*/
|
|
622
|
+
#fetch;
|
|
623
|
+
/**
|
|
624
|
+
* The reconnection time in milliseconds
|
|
625
|
+
*
|
|
626
|
+
* @internal
|
|
627
|
+
*/
|
|
628
|
+
#reconnectInterval;
|
|
629
|
+
/**
|
|
630
|
+
* Reference to an ongoing reconnect attempt, if any
|
|
631
|
+
*
|
|
632
|
+
* @internal
|
|
633
|
+
*/
|
|
634
|
+
#reconnectTimer;
|
|
635
|
+
/**
|
|
636
|
+
* The last event ID seen by the EventSource, which will be sent as `Last-Event-ID` in the
|
|
637
|
+
* request headers on a reconnection attempt.
|
|
638
|
+
*
|
|
639
|
+
* @internal
|
|
640
|
+
*/
|
|
641
|
+
#lastEventId = null;
|
|
642
|
+
/**
|
|
643
|
+
* The AbortController instance used to abort the fetch request
|
|
644
|
+
*
|
|
645
|
+
* @internal
|
|
646
|
+
*/
|
|
647
|
+
#controller;
|
|
648
|
+
/**
|
|
649
|
+
* Instance of an EventSource parser (`eventsource-parser` npm module)
|
|
650
|
+
*
|
|
651
|
+
* @internal
|
|
652
|
+
*/
|
|
653
|
+
#parser;
|
|
654
|
+
/**
|
|
655
|
+
* Holds the current error handler, attached through `onerror` property directly.
|
|
656
|
+
* Note that `addEventListener('error', …)` will not be stored here.
|
|
657
|
+
*
|
|
658
|
+
* @internal
|
|
659
|
+
*/
|
|
660
|
+
#onError = null;
|
|
661
|
+
/**
|
|
662
|
+
* Holds the current message handler, attached through `onmessage` property directly.
|
|
663
|
+
* Note that `addEventListener('message', …)` will not be stored here.
|
|
664
|
+
*
|
|
665
|
+
* @internal
|
|
666
|
+
*/
|
|
667
|
+
#onMessage = null;
|
|
668
|
+
/**
|
|
669
|
+
* Holds the current open handler, attached through `onopen` property directly.
|
|
670
|
+
* Note that `addEventListener('open', …)` will not be stored here.
|
|
671
|
+
*
|
|
672
|
+
* @internal
|
|
673
|
+
*/
|
|
674
|
+
#onOpen = null;
|
|
675
|
+
/**
|
|
676
|
+
* Connect to the given URL and start receiving events
|
|
677
|
+
*
|
|
678
|
+
* @internal
|
|
679
|
+
*/
|
|
680
|
+
#connect() {
|
|
681
|
+
this.#readyState = this.CONNECTING;
|
|
682
|
+
this.#controller = new AbortController();
|
|
683
|
+
const fetch = this.#fetch;
|
|
684
|
+
fetch(this.#url, this.#getRequestOptions()).then(this.#onFetchResponse).catch(this.#onFetchError);
|
|
350
685
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
686
|
+
/**
|
|
687
|
+
* Handles the fetch response
|
|
688
|
+
*
|
|
689
|
+
* @param response - The Fetch(ish) response
|
|
690
|
+
* @internal
|
|
691
|
+
*/
|
|
692
|
+
#onFetchResponse = async (response) => {
|
|
693
|
+
this.#parser.reset();
|
|
694
|
+
const { body, redirected, status, headers } = response;
|
|
695
|
+
if (status === 204) {
|
|
696
|
+
this.#failConnection("Server sent HTTP 204, not reconnecting", 204);
|
|
697
|
+
this.close();
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
if (redirected) {
|
|
701
|
+
this.#redirectUrl = new URL(response.url);
|
|
702
|
+
} else {
|
|
703
|
+
this.#redirectUrl = void 0;
|
|
704
|
+
}
|
|
705
|
+
if (status !== 200) {
|
|
706
|
+
this.#failConnection(`Non-200 status code (${status})`, status);
|
|
707
|
+
return;
|
|
708
|
+
}
|
|
709
|
+
const contentType = headers.get("content-type") || "";
|
|
710
|
+
if (!contentType.startsWith("text/event-stream")) {
|
|
711
|
+
this.#failConnection('Invalid content type, expected "text/event-stream"', status);
|
|
712
|
+
return;
|
|
713
|
+
}
|
|
714
|
+
if (this.#readyState === this.CLOSED) {
|
|
715
|
+
return;
|
|
716
|
+
}
|
|
717
|
+
this.#readyState = this.OPEN;
|
|
718
|
+
const openEvent = new Event("open");
|
|
719
|
+
this.dispatchEvent(openEvent);
|
|
720
|
+
if (typeof body !== "object" || !body || !("getReader" in body)) {
|
|
721
|
+
this.#failConnection("Invalid response body, expected a web ReadableStream", status);
|
|
722
|
+
this.close();
|
|
723
|
+
return;
|
|
724
|
+
}
|
|
725
|
+
const decoder = new TextDecoder();
|
|
726
|
+
const reader = body.getReader();
|
|
727
|
+
let open = true;
|
|
728
|
+
do {
|
|
729
|
+
const { done, value } = await reader.read();
|
|
730
|
+
if (this.#readyState === this.CLOSED) {
|
|
731
|
+
open = false;
|
|
732
|
+
break;
|
|
733
|
+
}
|
|
734
|
+
if (value) {
|
|
735
|
+
this.#parser.feed(decoder.decode(value, { stream: !done }));
|
|
736
|
+
}
|
|
737
|
+
if (!done) {
|
|
738
|
+
continue;
|
|
739
|
+
}
|
|
740
|
+
open = false;
|
|
741
|
+
this.#parser.reset();
|
|
742
|
+
this.#scheduleReconnect();
|
|
743
|
+
} while (open);
|
|
375
744
|
};
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
745
|
+
/**
|
|
746
|
+
* Handles rejected requests for the EventSource endpoint
|
|
747
|
+
*
|
|
748
|
+
* @param err - The error from `fetch()`
|
|
749
|
+
* @internal
|
|
750
|
+
*/
|
|
751
|
+
#onFetchError = (err) => {
|
|
752
|
+
this.#controller = void 0;
|
|
753
|
+
if (err.name === "AbortError" || err.type === "aborted") {
|
|
754
|
+
return;
|
|
755
|
+
}
|
|
756
|
+
this.#scheduleReconnect(flattenError(err));
|
|
757
|
+
};
|
|
758
|
+
/**
|
|
759
|
+
* Get request options for the `fetch()` request
|
|
760
|
+
*
|
|
761
|
+
* @returns The request options
|
|
762
|
+
* @internal
|
|
763
|
+
*/
|
|
764
|
+
#getRequestOptions() {
|
|
765
|
+
const lastEvent = this.#lastEventId ? { "Last-Event-ID": this.#lastEventId } : void 0;
|
|
766
|
+
const init = {
|
|
767
|
+
// [spec] Let `corsAttributeState` be `Anonymous`…
|
|
768
|
+
// [spec] …will have their mode set to "cors"…
|
|
769
|
+
mode: "cors",
|
|
770
|
+
redirect: "follow",
|
|
771
|
+
headers: { Accept: "text/event-stream", ...lastEvent },
|
|
772
|
+
cache: "no-store",
|
|
773
|
+
signal: this.#controller?.signal
|
|
774
|
+
};
|
|
775
|
+
if ("window" in globalThis) {
|
|
776
|
+
init.credentials = this.withCredentials ? "include" : "same-origin";
|
|
777
|
+
}
|
|
778
|
+
return init;
|
|
779
|
+
}
|
|
780
|
+
/**
|
|
781
|
+
* Called by EventSourceParser when a blank line ends a block containing a valid `id` field.
|
|
782
|
+
* This runs before `#onEvent` when the same block also contains data.
|
|
783
|
+
*
|
|
784
|
+
* @param value - The value of the `id` field
|
|
785
|
+
* @internal
|
|
786
|
+
*/
|
|
787
|
+
#onIdChange = (value) => {
|
|
788
|
+
this.#lastEventId = value;
|
|
789
|
+
};
|
|
790
|
+
/**
|
|
791
|
+
* Called by EventSourceParser instance when an event has successfully been parsed
|
|
792
|
+
* and is ready to be processed.
|
|
793
|
+
*
|
|
794
|
+
* @param event - The parsed event
|
|
795
|
+
* @internal
|
|
796
|
+
*/
|
|
797
|
+
#onEvent = (event) => {
|
|
798
|
+
const origin = this.#redirectUrl ? this.#redirectUrl.origin : this.#url.origin;
|
|
799
|
+
const lastEventId = this.#lastEventId ?? "";
|
|
800
|
+
const messageEvent = new MessageEvent(event.event || "message", {
|
|
801
|
+
data: event.data,
|
|
802
|
+
origin,
|
|
803
|
+
lastEventId
|
|
804
|
+
});
|
|
805
|
+
if (messageEvent.origin !== origin) {
|
|
806
|
+
defineEventProperty(messageEvent, "origin", origin);
|
|
807
|
+
}
|
|
808
|
+
if (messageEvent.lastEventId !== lastEventId) {
|
|
809
|
+
defineEventProperty(messageEvent, "lastEventId", lastEventId);
|
|
810
|
+
}
|
|
811
|
+
this.dispatchEvent(messageEvent);
|
|
812
|
+
};
|
|
813
|
+
/**
|
|
814
|
+
* Called by EventSourceParser instance when a new reconnection interval is received
|
|
815
|
+
* from the EventSource endpoint.
|
|
816
|
+
*
|
|
817
|
+
* @param value - The new reconnection interval in milliseconds
|
|
818
|
+
* @internal
|
|
819
|
+
*/
|
|
820
|
+
#onRetryChange = (value) => {
|
|
821
|
+
this.#reconnectInterval = value;
|
|
822
|
+
};
|
|
823
|
+
/**
|
|
824
|
+
* Called by EventSourceParser instance when a parse error occurs.
|
|
825
|
+
*
|
|
826
|
+
* @param error - The parser error
|
|
827
|
+
* @internal
|
|
828
|
+
*/
|
|
829
|
+
#onParseError = (error) => {
|
|
830
|
+
if (error.type !== "max-buffer-size-exceeded") {
|
|
831
|
+
return;
|
|
832
|
+
}
|
|
833
|
+
this.close();
|
|
834
|
+
this.#failConnection(error.message);
|
|
835
|
+
};
|
|
836
|
+
/**
|
|
837
|
+
* Handles the process referred to in the EventSource specification as "failing a connection".
|
|
838
|
+
*
|
|
839
|
+
* @param error - The error causing the connection to fail
|
|
840
|
+
* @param code - The HTTP status code, if available
|
|
841
|
+
* @internal
|
|
842
|
+
*/
|
|
843
|
+
#failConnection(message, code) {
|
|
844
|
+
if (this.#readyState !== this.CLOSED) {
|
|
845
|
+
this.#readyState = this.CLOSED;
|
|
846
|
+
}
|
|
847
|
+
const errorEvent = new ErrorEvent("error", { code, message });
|
|
848
|
+
this.dispatchEvent(errorEvent);
|
|
849
|
+
}
|
|
850
|
+
/**
|
|
851
|
+
* Schedules a reconnection attempt against the EventSource endpoint.
|
|
852
|
+
*
|
|
853
|
+
* @param message - The error causing the connection to fail
|
|
854
|
+
* @param code - The HTTP status code, if available
|
|
855
|
+
* @internal
|
|
856
|
+
*/
|
|
857
|
+
#scheduleReconnect(message, code) {
|
|
858
|
+
if (this.#readyState === this.CLOSED) {
|
|
859
|
+
return;
|
|
860
|
+
}
|
|
861
|
+
this.#readyState = this.CONNECTING;
|
|
862
|
+
const errorEvent = new ErrorEvent("error", { code, message });
|
|
863
|
+
this.dispatchEvent(errorEvent);
|
|
864
|
+
const timer = setTimeout(this.#reconnect, this.#reconnectInterval);
|
|
865
|
+
if (typeof timer === "object" && timer !== null && "unref" in timer) {
|
|
866
|
+
timer.unref();
|
|
867
|
+
}
|
|
868
|
+
this.#reconnectTimer = timer;
|
|
869
|
+
}
|
|
870
|
+
/**
|
|
871
|
+
* Reconnects to the EventSource endpoint after a disconnect/failure
|
|
872
|
+
*
|
|
873
|
+
* @internal
|
|
874
|
+
*/
|
|
875
|
+
#reconnect = () => {
|
|
876
|
+
this.#reconnectTimer = void 0;
|
|
877
|
+
if (this.#readyState !== this.CONNECTING) {
|
|
878
|
+
return;
|
|
879
|
+
}
|
|
880
|
+
this.#connect();
|
|
881
|
+
};
|
|
882
|
+
};
|
|
883
|
+
Object.defineProperty(EventSourceImpl, "name", { value: "EventSource" });
|
|
884
|
+
Object.defineProperty(EventSourceImpl, /* @__PURE__ */ Symbol.for("eventsource.supports-fetch-override"), {
|
|
420
885
|
value: true,
|
|
421
886
|
writable: false,
|
|
422
887
|
configurable: false,
|
|
423
888
|
enumerable: false
|
|
424
889
|
});
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
890
|
+
EventSource = EventSourceImpl;
|
|
891
|
+
}
|
|
892
|
+
});
|
|
893
|
+
|
|
894
|
+
// node_modules/eventsource/dist/index.js
|
|
895
|
+
var dist_exports = {};
|
|
896
|
+
__export(dist_exports, {
|
|
897
|
+
ErrorEvent: () => ErrorEvent,
|
|
898
|
+
EventSource: () => EventSource
|
|
899
|
+
});
|
|
900
|
+
var init_dist2 = __esm({
|
|
901
|
+
"node_modules/eventsource/dist/index.js"() {
|
|
902
|
+
init_errors();
|
|
903
|
+
init_EventSource();
|
|
431
904
|
}
|
|
432
905
|
});
|
|
433
906
|
|
|
@@ -435,7 +908,7 @@ var require_dist2 = __commonJS({
|
|
|
435
908
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
436
909
|
exports.PocketbaseTrigger = void 0;
|
|
437
910
|
var n8n_workflow_1 = require("n8n-workflow");
|
|
438
|
-
var eventsource_1 =
|
|
911
|
+
var eventsource_1 = (init_dist2(), __toCommonJS(dist_exports));
|
|
439
912
|
var LoadOptions_1 = require("../Common/LoadOptions");
|
|
440
913
|
var PocketbaseTrigger = class {
|
|
441
914
|
constructor() {
|
|
@@ -492,8 +965,7 @@ var PocketbaseTrigger = class {
|
|
|
492
965
|
required: true,
|
|
493
966
|
description: "The events to trigger the node"
|
|
494
967
|
}
|
|
495
|
-
]
|
|
496
|
-
usableAsTool: true
|
|
968
|
+
]
|
|
497
969
|
};
|
|
498
970
|
this.methods = {
|
|
499
971
|
loadOptions: LoadOptions_1.LoadOptions
|