@schematichq/schematic-js 0.1.11 → 0.1.13
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/schematic.browser.js +2 -1
- package/dist/schematic.cjs.js +548 -31
- package/dist/schematic.d.ts +1 -1
- package/dist/schematic.esm.js +561 -31
- package/package.json +3 -1
package/dist/schematic.cjs.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
6
11
|
var __export = (target, all) => {
|
|
7
12
|
for (var name in all)
|
|
8
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -15,8 +20,518 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
20
|
}
|
|
16
21
|
return to;
|
|
17
22
|
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
18
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
32
|
|
|
33
|
+
// node_modules/cross-fetch/dist/browser-polyfill.js
|
|
34
|
+
var require_browser_polyfill = __commonJS({
|
|
35
|
+
"node_modules/cross-fetch/dist/browser-polyfill.js"(exports) {
|
|
36
|
+
(function(self2) {
|
|
37
|
+
var irrelevant = function(exports2) {
|
|
38
|
+
var global = typeof globalThis !== "undefined" && globalThis || typeof self2 !== "undefined" && self2 || typeof global !== "undefined" && global;
|
|
39
|
+
var support = {
|
|
40
|
+
searchParams: "URLSearchParams" in global,
|
|
41
|
+
iterable: "Symbol" in global && "iterator" in Symbol,
|
|
42
|
+
blob: "FileReader" in global && "Blob" in global && function() {
|
|
43
|
+
try {
|
|
44
|
+
new Blob();
|
|
45
|
+
return true;
|
|
46
|
+
} catch (e) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}(),
|
|
50
|
+
formData: "FormData" in global,
|
|
51
|
+
arrayBuffer: "ArrayBuffer" in global
|
|
52
|
+
};
|
|
53
|
+
function isDataView(obj) {
|
|
54
|
+
return obj && DataView.prototype.isPrototypeOf(obj);
|
|
55
|
+
}
|
|
56
|
+
if (support.arrayBuffer) {
|
|
57
|
+
var viewClasses = [
|
|
58
|
+
"[object Int8Array]",
|
|
59
|
+
"[object Uint8Array]",
|
|
60
|
+
"[object Uint8ClampedArray]",
|
|
61
|
+
"[object Int16Array]",
|
|
62
|
+
"[object Uint16Array]",
|
|
63
|
+
"[object Int32Array]",
|
|
64
|
+
"[object Uint32Array]",
|
|
65
|
+
"[object Float32Array]",
|
|
66
|
+
"[object Float64Array]"
|
|
67
|
+
];
|
|
68
|
+
var isArrayBufferView = ArrayBuffer.isView || function(obj) {
|
|
69
|
+
return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function normalizeName(name) {
|
|
73
|
+
if (typeof name !== "string") {
|
|
74
|
+
name = String(name);
|
|
75
|
+
}
|
|
76
|
+
if (/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(name) || name === "") {
|
|
77
|
+
throw new TypeError('Invalid character in header field name: "' + name + '"');
|
|
78
|
+
}
|
|
79
|
+
return name.toLowerCase();
|
|
80
|
+
}
|
|
81
|
+
function normalizeValue(value) {
|
|
82
|
+
if (typeof value !== "string") {
|
|
83
|
+
value = String(value);
|
|
84
|
+
}
|
|
85
|
+
return value;
|
|
86
|
+
}
|
|
87
|
+
function iteratorFor(items) {
|
|
88
|
+
var iterator = {
|
|
89
|
+
next: function() {
|
|
90
|
+
var value = items.shift();
|
|
91
|
+
return { done: value === void 0, value };
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
if (support.iterable) {
|
|
95
|
+
iterator[Symbol.iterator] = function() {
|
|
96
|
+
return iterator;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
return iterator;
|
|
100
|
+
}
|
|
101
|
+
function Headers(headers) {
|
|
102
|
+
this.map = {};
|
|
103
|
+
if (headers instanceof Headers) {
|
|
104
|
+
headers.forEach(function(value, name) {
|
|
105
|
+
this.append(name, value);
|
|
106
|
+
}, this);
|
|
107
|
+
} else if (Array.isArray(headers)) {
|
|
108
|
+
headers.forEach(function(header) {
|
|
109
|
+
this.append(header[0], header[1]);
|
|
110
|
+
}, this);
|
|
111
|
+
} else if (headers) {
|
|
112
|
+
Object.getOwnPropertyNames(headers).forEach(function(name) {
|
|
113
|
+
this.append(name, headers[name]);
|
|
114
|
+
}, this);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
Headers.prototype.append = function(name, value) {
|
|
118
|
+
name = normalizeName(name);
|
|
119
|
+
value = normalizeValue(value);
|
|
120
|
+
var oldValue = this.map[name];
|
|
121
|
+
this.map[name] = oldValue ? oldValue + ", " + value : value;
|
|
122
|
+
};
|
|
123
|
+
Headers.prototype["delete"] = function(name) {
|
|
124
|
+
delete this.map[normalizeName(name)];
|
|
125
|
+
};
|
|
126
|
+
Headers.prototype.get = function(name) {
|
|
127
|
+
name = normalizeName(name);
|
|
128
|
+
return this.has(name) ? this.map[name] : null;
|
|
129
|
+
};
|
|
130
|
+
Headers.prototype.has = function(name) {
|
|
131
|
+
return this.map.hasOwnProperty(normalizeName(name));
|
|
132
|
+
};
|
|
133
|
+
Headers.prototype.set = function(name, value) {
|
|
134
|
+
this.map[normalizeName(name)] = normalizeValue(value);
|
|
135
|
+
};
|
|
136
|
+
Headers.prototype.forEach = function(callback, thisArg) {
|
|
137
|
+
for (var name in this.map) {
|
|
138
|
+
if (this.map.hasOwnProperty(name)) {
|
|
139
|
+
callback.call(thisArg, this.map[name], name, this);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
Headers.prototype.keys = function() {
|
|
144
|
+
var items = [];
|
|
145
|
+
this.forEach(function(value, name) {
|
|
146
|
+
items.push(name);
|
|
147
|
+
});
|
|
148
|
+
return iteratorFor(items);
|
|
149
|
+
};
|
|
150
|
+
Headers.prototype.values = function() {
|
|
151
|
+
var items = [];
|
|
152
|
+
this.forEach(function(value) {
|
|
153
|
+
items.push(value);
|
|
154
|
+
});
|
|
155
|
+
return iteratorFor(items);
|
|
156
|
+
};
|
|
157
|
+
Headers.prototype.entries = function() {
|
|
158
|
+
var items = [];
|
|
159
|
+
this.forEach(function(value, name) {
|
|
160
|
+
items.push([name, value]);
|
|
161
|
+
});
|
|
162
|
+
return iteratorFor(items);
|
|
163
|
+
};
|
|
164
|
+
if (support.iterable) {
|
|
165
|
+
Headers.prototype[Symbol.iterator] = Headers.prototype.entries;
|
|
166
|
+
}
|
|
167
|
+
function consumed(body) {
|
|
168
|
+
if (body.bodyUsed) {
|
|
169
|
+
return Promise.reject(new TypeError("Already read"));
|
|
170
|
+
}
|
|
171
|
+
body.bodyUsed = true;
|
|
172
|
+
}
|
|
173
|
+
function fileReaderReady(reader) {
|
|
174
|
+
return new Promise(function(resolve, reject) {
|
|
175
|
+
reader.onload = function() {
|
|
176
|
+
resolve(reader.result);
|
|
177
|
+
};
|
|
178
|
+
reader.onerror = function() {
|
|
179
|
+
reject(reader.error);
|
|
180
|
+
};
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
function readBlobAsArrayBuffer(blob) {
|
|
184
|
+
var reader = new FileReader();
|
|
185
|
+
var promise = fileReaderReady(reader);
|
|
186
|
+
reader.readAsArrayBuffer(blob);
|
|
187
|
+
return promise;
|
|
188
|
+
}
|
|
189
|
+
function readBlobAsText(blob) {
|
|
190
|
+
var reader = new FileReader();
|
|
191
|
+
var promise = fileReaderReady(reader);
|
|
192
|
+
reader.readAsText(blob);
|
|
193
|
+
return promise;
|
|
194
|
+
}
|
|
195
|
+
function readArrayBufferAsText(buf) {
|
|
196
|
+
var view = new Uint8Array(buf);
|
|
197
|
+
var chars = new Array(view.length);
|
|
198
|
+
for (var i = 0; i < view.length; i++) {
|
|
199
|
+
chars[i] = String.fromCharCode(view[i]);
|
|
200
|
+
}
|
|
201
|
+
return chars.join("");
|
|
202
|
+
}
|
|
203
|
+
function bufferClone(buf) {
|
|
204
|
+
if (buf.slice) {
|
|
205
|
+
return buf.slice(0);
|
|
206
|
+
} else {
|
|
207
|
+
var view = new Uint8Array(buf.byteLength);
|
|
208
|
+
view.set(new Uint8Array(buf));
|
|
209
|
+
return view.buffer;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
function Body() {
|
|
213
|
+
this.bodyUsed = false;
|
|
214
|
+
this._initBody = function(body) {
|
|
215
|
+
this.bodyUsed = this.bodyUsed;
|
|
216
|
+
this._bodyInit = body;
|
|
217
|
+
if (!body) {
|
|
218
|
+
this._bodyText = "";
|
|
219
|
+
} else if (typeof body === "string") {
|
|
220
|
+
this._bodyText = body;
|
|
221
|
+
} else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
|
|
222
|
+
this._bodyBlob = body;
|
|
223
|
+
} else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
|
|
224
|
+
this._bodyFormData = body;
|
|
225
|
+
} else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
|
|
226
|
+
this._bodyText = body.toString();
|
|
227
|
+
} else if (support.arrayBuffer && support.blob && isDataView(body)) {
|
|
228
|
+
this._bodyArrayBuffer = bufferClone(body.buffer);
|
|
229
|
+
this._bodyInit = new Blob([this._bodyArrayBuffer]);
|
|
230
|
+
} else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) {
|
|
231
|
+
this._bodyArrayBuffer = bufferClone(body);
|
|
232
|
+
} else {
|
|
233
|
+
this._bodyText = body = Object.prototype.toString.call(body);
|
|
234
|
+
}
|
|
235
|
+
if (!this.headers.get("content-type")) {
|
|
236
|
+
if (typeof body === "string") {
|
|
237
|
+
this.headers.set("content-type", "text/plain;charset=UTF-8");
|
|
238
|
+
} else if (this._bodyBlob && this._bodyBlob.type) {
|
|
239
|
+
this.headers.set("content-type", this._bodyBlob.type);
|
|
240
|
+
} else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
|
|
241
|
+
this.headers.set("content-type", "application/x-www-form-urlencoded;charset=UTF-8");
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
if (support.blob) {
|
|
246
|
+
this.blob = function() {
|
|
247
|
+
var rejected = consumed(this);
|
|
248
|
+
if (rejected) {
|
|
249
|
+
return rejected;
|
|
250
|
+
}
|
|
251
|
+
if (this._bodyBlob) {
|
|
252
|
+
return Promise.resolve(this._bodyBlob);
|
|
253
|
+
} else if (this._bodyArrayBuffer) {
|
|
254
|
+
return Promise.resolve(new Blob([this._bodyArrayBuffer]));
|
|
255
|
+
} else if (this._bodyFormData) {
|
|
256
|
+
throw new Error("could not read FormData body as blob");
|
|
257
|
+
} else {
|
|
258
|
+
return Promise.resolve(new Blob([this._bodyText]));
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
this.arrayBuffer = function() {
|
|
262
|
+
if (this._bodyArrayBuffer) {
|
|
263
|
+
var isConsumed = consumed(this);
|
|
264
|
+
if (isConsumed) {
|
|
265
|
+
return isConsumed;
|
|
266
|
+
}
|
|
267
|
+
if (ArrayBuffer.isView(this._bodyArrayBuffer)) {
|
|
268
|
+
return Promise.resolve(
|
|
269
|
+
this._bodyArrayBuffer.buffer.slice(
|
|
270
|
+
this._bodyArrayBuffer.byteOffset,
|
|
271
|
+
this._bodyArrayBuffer.byteOffset + this._bodyArrayBuffer.byteLength
|
|
272
|
+
)
|
|
273
|
+
);
|
|
274
|
+
} else {
|
|
275
|
+
return Promise.resolve(this._bodyArrayBuffer);
|
|
276
|
+
}
|
|
277
|
+
} else {
|
|
278
|
+
return this.blob().then(readBlobAsArrayBuffer);
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
this.text = function() {
|
|
283
|
+
var rejected = consumed(this);
|
|
284
|
+
if (rejected) {
|
|
285
|
+
return rejected;
|
|
286
|
+
}
|
|
287
|
+
if (this._bodyBlob) {
|
|
288
|
+
return readBlobAsText(this._bodyBlob);
|
|
289
|
+
} else if (this._bodyArrayBuffer) {
|
|
290
|
+
return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer));
|
|
291
|
+
} else if (this._bodyFormData) {
|
|
292
|
+
throw new Error("could not read FormData body as text");
|
|
293
|
+
} else {
|
|
294
|
+
return Promise.resolve(this._bodyText);
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
if (support.formData) {
|
|
298
|
+
this.formData = function() {
|
|
299
|
+
return this.text().then(decode);
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
this.json = function() {
|
|
303
|
+
return this.text().then(JSON.parse);
|
|
304
|
+
};
|
|
305
|
+
return this;
|
|
306
|
+
}
|
|
307
|
+
var methods = ["DELETE", "GET", "HEAD", "OPTIONS", "POST", "PUT"];
|
|
308
|
+
function normalizeMethod(method) {
|
|
309
|
+
var upcased = method.toUpperCase();
|
|
310
|
+
return methods.indexOf(upcased) > -1 ? upcased : method;
|
|
311
|
+
}
|
|
312
|
+
function Request(input, options) {
|
|
313
|
+
if (!(this instanceof Request)) {
|
|
314
|
+
throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');
|
|
315
|
+
}
|
|
316
|
+
options = options || {};
|
|
317
|
+
var body = options.body;
|
|
318
|
+
if (input instanceof Request) {
|
|
319
|
+
if (input.bodyUsed) {
|
|
320
|
+
throw new TypeError("Already read");
|
|
321
|
+
}
|
|
322
|
+
this.url = input.url;
|
|
323
|
+
this.credentials = input.credentials;
|
|
324
|
+
if (!options.headers) {
|
|
325
|
+
this.headers = new Headers(input.headers);
|
|
326
|
+
}
|
|
327
|
+
this.method = input.method;
|
|
328
|
+
this.mode = input.mode;
|
|
329
|
+
this.signal = input.signal;
|
|
330
|
+
if (!body && input._bodyInit != null) {
|
|
331
|
+
body = input._bodyInit;
|
|
332
|
+
input.bodyUsed = true;
|
|
333
|
+
}
|
|
334
|
+
} else {
|
|
335
|
+
this.url = String(input);
|
|
336
|
+
}
|
|
337
|
+
this.credentials = options.credentials || this.credentials || "same-origin";
|
|
338
|
+
if (options.headers || !this.headers) {
|
|
339
|
+
this.headers = new Headers(options.headers);
|
|
340
|
+
}
|
|
341
|
+
this.method = normalizeMethod(options.method || this.method || "GET");
|
|
342
|
+
this.mode = options.mode || this.mode || null;
|
|
343
|
+
this.signal = options.signal || this.signal;
|
|
344
|
+
this.referrer = null;
|
|
345
|
+
if ((this.method === "GET" || this.method === "HEAD") && body) {
|
|
346
|
+
throw new TypeError("Body not allowed for GET or HEAD requests");
|
|
347
|
+
}
|
|
348
|
+
this._initBody(body);
|
|
349
|
+
if (this.method === "GET" || this.method === "HEAD") {
|
|
350
|
+
if (options.cache === "no-store" || options.cache === "no-cache") {
|
|
351
|
+
var reParamSearch = /([?&])_=[^&]*/;
|
|
352
|
+
if (reParamSearch.test(this.url)) {
|
|
353
|
+
this.url = this.url.replace(reParamSearch, "$1_=" + (/* @__PURE__ */ new Date()).getTime());
|
|
354
|
+
} else {
|
|
355
|
+
var reQueryString = /\?/;
|
|
356
|
+
this.url += (reQueryString.test(this.url) ? "&" : "?") + "_=" + (/* @__PURE__ */ new Date()).getTime();
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
Request.prototype.clone = function() {
|
|
362
|
+
return new Request(this, { body: this._bodyInit });
|
|
363
|
+
};
|
|
364
|
+
function decode(body) {
|
|
365
|
+
var form = new FormData();
|
|
366
|
+
body.trim().split("&").forEach(function(bytes) {
|
|
367
|
+
if (bytes) {
|
|
368
|
+
var split = bytes.split("=");
|
|
369
|
+
var name = split.shift().replace(/\+/g, " ");
|
|
370
|
+
var value = split.join("=").replace(/\+/g, " ");
|
|
371
|
+
form.append(decodeURIComponent(name), decodeURIComponent(value));
|
|
372
|
+
}
|
|
373
|
+
});
|
|
374
|
+
return form;
|
|
375
|
+
}
|
|
376
|
+
function parseHeaders(rawHeaders) {
|
|
377
|
+
var headers = new Headers();
|
|
378
|
+
var preProcessedHeaders = rawHeaders.replace(/\r?\n[\t ]+/g, " ");
|
|
379
|
+
preProcessedHeaders.split("\r").map(function(header) {
|
|
380
|
+
return header.indexOf("\n") === 0 ? header.substr(1, header.length) : header;
|
|
381
|
+
}).forEach(function(line) {
|
|
382
|
+
var parts = line.split(":");
|
|
383
|
+
var key = parts.shift().trim();
|
|
384
|
+
if (key) {
|
|
385
|
+
var value = parts.join(":").trim();
|
|
386
|
+
headers.append(key, value);
|
|
387
|
+
}
|
|
388
|
+
});
|
|
389
|
+
return headers;
|
|
390
|
+
}
|
|
391
|
+
Body.call(Request.prototype);
|
|
392
|
+
function Response(bodyInit, options) {
|
|
393
|
+
if (!(this instanceof Response)) {
|
|
394
|
+
throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');
|
|
395
|
+
}
|
|
396
|
+
if (!options) {
|
|
397
|
+
options = {};
|
|
398
|
+
}
|
|
399
|
+
this.type = "default";
|
|
400
|
+
this.status = options.status === void 0 ? 200 : options.status;
|
|
401
|
+
this.ok = this.status >= 200 && this.status < 300;
|
|
402
|
+
this.statusText = options.statusText === void 0 ? "" : "" + options.statusText;
|
|
403
|
+
this.headers = new Headers(options.headers);
|
|
404
|
+
this.url = options.url || "";
|
|
405
|
+
this._initBody(bodyInit);
|
|
406
|
+
}
|
|
407
|
+
Body.call(Response.prototype);
|
|
408
|
+
Response.prototype.clone = function() {
|
|
409
|
+
return new Response(this._bodyInit, {
|
|
410
|
+
status: this.status,
|
|
411
|
+
statusText: this.statusText,
|
|
412
|
+
headers: new Headers(this.headers),
|
|
413
|
+
url: this.url
|
|
414
|
+
});
|
|
415
|
+
};
|
|
416
|
+
Response.error = function() {
|
|
417
|
+
var response = new Response(null, { status: 0, statusText: "" });
|
|
418
|
+
response.type = "error";
|
|
419
|
+
return response;
|
|
420
|
+
};
|
|
421
|
+
var redirectStatuses = [301, 302, 303, 307, 308];
|
|
422
|
+
Response.redirect = function(url, status) {
|
|
423
|
+
if (redirectStatuses.indexOf(status) === -1) {
|
|
424
|
+
throw new RangeError("Invalid status code");
|
|
425
|
+
}
|
|
426
|
+
return new Response(null, { status, headers: { location: url } });
|
|
427
|
+
};
|
|
428
|
+
exports2.DOMException = global.DOMException;
|
|
429
|
+
try {
|
|
430
|
+
new exports2.DOMException();
|
|
431
|
+
} catch (err) {
|
|
432
|
+
exports2.DOMException = function(message, name) {
|
|
433
|
+
this.message = message;
|
|
434
|
+
this.name = name;
|
|
435
|
+
var error = Error(message);
|
|
436
|
+
this.stack = error.stack;
|
|
437
|
+
};
|
|
438
|
+
exports2.DOMException.prototype = Object.create(Error.prototype);
|
|
439
|
+
exports2.DOMException.prototype.constructor = exports2.DOMException;
|
|
440
|
+
}
|
|
441
|
+
function fetch2(input, init) {
|
|
442
|
+
return new Promise(function(resolve, reject) {
|
|
443
|
+
var request = new Request(input, init);
|
|
444
|
+
if (request.signal && request.signal.aborted) {
|
|
445
|
+
return reject(new exports2.DOMException("Aborted", "AbortError"));
|
|
446
|
+
}
|
|
447
|
+
var xhr = new XMLHttpRequest();
|
|
448
|
+
function abortXhr() {
|
|
449
|
+
xhr.abort();
|
|
450
|
+
}
|
|
451
|
+
xhr.onload = function() {
|
|
452
|
+
var options = {
|
|
453
|
+
status: xhr.status,
|
|
454
|
+
statusText: xhr.statusText,
|
|
455
|
+
headers: parseHeaders(xhr.getAllResponseHeaders() || "")
|
|
456
|
+
};
|
|
457
|
+
options.url = "responseURL" in xhr ? xhr.responseURL : options.headers.get("X-Request-URL");
|
|
458
|
+
var body = "response" in xhr ? xhr.response : xhr.responseText;
|
|
459
|
+
setTimeout(function() {
|
|
460
|
+
resolve(new Response(body, options));
|
|
461
|
+
}, 0);
|
|
462
|
+
};
|
|
463
|
+
xhr.onerror = function() {
|
|
464
|
+
setTimeout(function() {
|
|
465
|
+
reject(new TypeError("Network request failed"));
|
|
466
|
+
}, 0);
|
|
467
|
+
};
|
|
468
|
+
xhr.ontimeout = function() {
|
|
469
|
+
setTimeout(function() {
|
|
470
|
+
reject(new TypeError("Network request failed"));
|
|
471
|
+
}, 0);
|
|
472
|
+
};
|
|
473
|
+
xhr.onabort = function() {
|
|
474
|
+
setTimeout(function() {
|
|
475
|
+
reject(new exports2.DOMException("Aborted", "AbortError"));
|
|
476
|
+
}, 0);
|
|
477
|
+
};
|
|
478
|
+
function fixUrl(url) {
|
|
479
|
+
try {
|
|
480
|
+
return url === "" && global.location.href ? global.location.href : url;
|
|
481
|
+
} catch (e) {
|
|
482
|
+
return url;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
xhr.open(request.method, fixUrl(request.url), true);
|
|
486
|
+
if (request.credentials === "include") {
|
|
487
|
+
xhr.withCredentials = true;
|
|
488
|
+
} else if (request.credentials === "omit") {
|
|
489
|
+
xhr.withCredentials = false;
|
|
490
|
+
}
|
|
491
|
+
if ("responseType" in xhr) {
|
|
492
|
+
if (support.blob) {
|
|
493
|
+
xhr.responseType = "blob";
|
|
494
|
+
} else if (support.arrayBuffer && request.headers.get("Content-Type") && request.headers.get("Content-Type").indexOf("application/octet-stream") !== -1) {
|
|
495
|
+
xhr.responseType = "arraybuffer";
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
if (init && typeof init.headers === "object" && !(init.headers instanceof Headers)) {
|
|
499
|
+
Object.getOwnPropertyNames(init.headers).forEach(function(name) {
|
|
500
|
+
xhr.setRequestHeader(name, normalizeValue(init.headers[name]));
|
|
501
|
+
});
|
|
502
|
+
} else {
|
|
503
|
+
request.headers.forEach(function(value, name) {
|
|
504
|
+
xhr.setRequestHeader(name, value);
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
if (request.signal) {
|
|
508
|
+
request.signal.addEventListener("abort", abortXhr);
|
|
509
|
+
xhr.onreadystatechange = function() {
|
|
510
|
+
if (xhr.readyState === 4) {
|
|
511
|
+
request.signal.removeEventListener("abort", abortXhr);
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
xhr.send(typeof request._bodyInit === "undefined" ? null : request._bodyInit);
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
fetch2.polyfill = true;
|
|
519
|
+
if (!global.fetch) {
|
|
520
|
+
global.fetch = fetch2;
|
|
521
|
+
global.Headers = Headers;
|
|
522
|
+
global.Request = Request;
|
|
523
|
+
global.Response = Response;
|
|
524
|
+
}
|
|
525
|
+
exports2.Headers = Headers;
|
|
526
|
+
exports2.Request = Request;
|
|
527
|
+
exports2.Response = Response;
|
|
528
|
+
exports2.fetch = fetch2;
|
|
529
|
+
return exports2;
|
|
530
|
+
}({});
|
|
531
|
+
})(typeof self !== "undefined" ? self : exports);
|
|
532
|
+
}
|
|
533
|
+
});
|
|
534
|
+
|
|
20
535
|
// src/index.ts
|
|
21
536
|
var src_exports = {};
|
|
22
537
|
__export(src_exports, {
|
|
@@ -73,6 +588,7 @@ function v4(options, buf, offset) {
|
|
|
73
588
|
var v4_default = v4;
|
|
74
589
|
|
|
75
590
|
// src/index.ts
|
|
591
|
+
var import_polyfill = __toESM(require_browser_polyfill());
|
|
76
592
|
var anonymousIdKey = "schematicId";
|
|
77
593
|
var Schematic = class {
|
|
78
594
|
apiKey;
|
|
@@ -168,9 +684,16 @@ var Schematic = class {
|
|
|
168
684
|
return false;
|
|
169
685
|
});
|
|
170
686
|
};
|
|
171
|
-
cleanup = () => {
|
|
687
|
+
cleanup = async () => {
|
|
172
688
|
if (this.conn) {
|
|
173
|
-
|
|
689
|
+
try {
|
|
690
|
+
const socket = await this.conn;
|
|
691
|
+
socket.close();
|
|
692
|
+
} catch (error) {
|
|
693
|
+
console.error("Error during cleanup:", error);
|
|
694
|
+
} finally {
|
|
695
|
+
this.conn = null;
|
|
696
|
+
}
|
|
174
697
|
}
|
|
175
698
|
};
|
|
176
699
|
// Send an identify event
|
|
@@ -185,16 +708,16 @@ var Schematic = class {
|
|
|
185
708
|
// this will open a websocket connection (if not already open)
|
|
186
709
|
// and submit this context. The promise will resolve when the
|
|
187
710
|
// websocket sends back an initial set of flag values.
|
|
188
|
-
setContext = (context) => {
|
|
711
|
+
setContext = async (context) => {
|
|
189
712
|
if (!this.useWebSocket) {
|
|
190
713
|
this.context = context;
|
|
191
714
|
return Promise.resolve();
|
|
192
715
|
}
|
|
193
|
-
|
|
194
|
-
this.wsConnect()
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
716
|
+
if (!this.conn) {
|
|
717
|
+
this.conn = this.wsConnect();
|
|
718
|
+
}
|
|
719
|
+
return this.conn.then((socket) => {
|
|
720
|
+
return this.wsSendMessage(socket, context);
|
|
198
721
|
});
|
|
199
722
|
};
|
|
200
723
|
// Send track event
|
|
@@ -263,36 +786,30 @@ var Schematic = class {
|
|
|
263
786
|
return Promise.resolve();
|
|
264
787
|
};
|
|
265
788
|
wsConnect = () => {
|
|
266
|
-
return new Promise((resolve) => {
|
|
267
|
-
if (this.conn) {
|
|
268
|
-
resolve();
|
|
269
|
-
}
|
|
789
|
+
return new Promise((resolve, reject) => {
|
|
270
790
|
const wsUrl = `${this.webSocketUrl}/flags/bootstrap`;
|
|
271
791
|
const webSocket = new WebSocket(wsUrl);
|
|
272
|
-
this.conn = webSocket;
|
|
273
792
|
webSocket.onopen = () => {
|
|
274
|
-
resolve();
|
|
793
|
+
resolve(webSocket);
|
|
794
|
+
};
|
|
795
|
+
webSocket.onerror = (error) => {
|
|
796
|
+
reject(error);
|
|
275
797
|
};
|
|
276
798
|
webSocket.onclose = () => {
|
|
277
799
|
this.conn = null;
|
|
278
800
|
};
|
|
279
801
|
});
|
|
280
802
|
};
|
|
281
|
-
|
|
282
|
-
wsSendMessage = (context) => {
|
|
803
|
+
wsSendMessage = (socket, context) => {
|
|
283
804
|
return new Promise((resolve, reject) => {
|
|
284
805
|
if (contextString(context) == contextString(this.context)) {
|
|
285
806
|
resolve();
|
|
286
807
|
return;
|
|
287
808
|
}
|
|
288
809
|
this.context = context;
|
|
289
|
-
|
|
290
|
-
reject("Not connected");
|
|
291
|
-
return;
|
|
292
|
-
}
|
|
293
|
-
if (this.conn.readyState === WebSocket.OPEN) {
|
|
810
|
+
const sendMessage = () => {
|
|
294
811
|
let resolved = false;
|
|
295
|
-
|
|
812
|
+
const messageHandler = (event) => {
|
|
296
813
|
const message = JSON.parse(event.data);
|
|
297
814
|
if (!(contextString(context) in this.values)) {
|
|
298
815
|
this.values[contextString(context)] = {};
|
|
@@ -309,22 +826,22 @@ var Schematic = class {
|
|
|
309
826
|
resolved = true;
|
|
310
827
|
resolve();
|
|
311
828
|
}
|
|
829
|
+
socket.removeEventListener("message", messageHandler);
|
|
312
830
|
};
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
};
|
|
316
|
-
this.conn.send(
|
|
831
|
+
socket.addEventListener("message", messageHandler);
|
|
832
|
+
socket.send(
|
|
317
833
|
JSON.stringify({
|
|
318
834
|
apiKey: this.apiKey,
|
|
319
835
|
data: context
|
|
320
836
|
})
|
|
321
837
|
);
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
838
|
+
};
|
|
839
|
+
if (socket.readyState === WebSocket.OPEN) {
|
|
840
|
+
sendMessage();
|
|
841
|
+
} else if (socket.readyState === WebSocket.CONNECTING) {
|
|
842
|
+
socket.addEventListener("open", sendMessage);
|
|
326
843
|
} else {
|
|
327
|
-
reject("
|
|
844
|
+
reject("WebSocket is not open or connecting");
|
|
328
845
|
}
|
|
329
846
|
});
|
|
330
847
|
};
|
package/dist/schematic.d.ts
CHANGED
|
@@ -64,7 +64,7 @@ export declare class Schematic {
|
|
|
64
64
|
constructor(apiKey: string, options?: SchematicOptions);
|
|
65
65
|
checkFlag(options: CheckOptions): Promise<boolean>;
|
|
66
66
|
checkFlags: (context?: SchematicContext) => Promise<Record<string, boolean>>;
|
|
67
|
-
cleanup: () => void
|
|
67
|
+
cleanup: () => Promise<void>;
|
|
68
68
|
identify: (body: EventBodyIdentify) => Promise<void>;
|
|
69
69
|
setContext: (context: SchematicContext) => Promise<void>;
|
|
70
70
|
track: (body: EventBodyTrack) => Promise<void>;
|