wapi-client 0.8.1 → 0.8.3

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,11 +1,9 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
2
  var __defProps = Object.defineProperties;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
6
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
- var __getProtoOf = Object.getPrototypeOf;
9
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
10
8
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
9
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -21,9 +19,6 @@ var __spreadValues = (a, b) => {
21
19
  return a;
22
20
  };
23
21
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
- var __commonJS = (cb, mod) => function __require() {
25
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
26
- };
27
22
  var __export = (target, all) => {
28
23
  for (var name in all)
29
24
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -36,14 +31,6 @@ var __copyProps = (to, from, except, desc) => {
36
31
  }
37
32
  return to;
38
33
  };
39
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
40
- // If the importer is in node compatibility mode or this is not an ESM
41
- // file that has been converted to a CommonJS file using a Babel-
42
- // compatible transform (i.e. "__esModule" has not been set), then set
43
- // "default" to the CommonJS "module.exports" for node compatibility.
44
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
45
- mod
46
- ));
47
34
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
48
35
  var __async = (__this, __arguments, generator) => {
49
36
  return new Promise((resolve, reject) => {
@@ -66,527 +53,6 @@ var __async = (__this, __arguments, generator) => {
66
53
  });
67
54
  };
68
55
 
69
- // node_modules/cross-fetch/dist/browser-ponyfill.js
70
- var require_browser_ponyfill = __commonJS({
71
- "node_modules/cross-fetch/dist/browser-ponyfill.js"(exports, module2) {
72
- var __global__ = typeof globalThis !== "undefined" && globalThis || typeof self !== "undefined" && self || typeof global !== "undefined" && global;
73
- var __globalThis__ = function() {
74
- function F() {
75
- this.fetch = false;
76
- this.DOMException = __global__.DOMException;
77
- }
78
- F.prototype = __global__;
79
- return new F();
80
- }();
81
- (function(globalThis2) {
82
- var irrelevant = function(exports2) {
83
- var global2 = typeof globalThis2 !== "undefined" && globalThis2 || typeof self !== "undefined" && self || typeof global2 !== "undefined" && global2;
84
- var support = {
85
- searchParams: "URLSearchParams" in global2,
86
- iterable: "Symbol" in global2 && "iterator" in Symbol,
87
- blob: "FileReader" in global2 && "Blob" in global2 && function() {
88
- try {
89
- new Blob();
90
- return true;
91
- } catch (e) {
92
- return false;
93
- }
94
- }(),
95
- formData: "FormData" in global2,
96
- arrayBuffer: "ArrayBuffer" in global2
97
- };
98
- function isDataView(obj) {
99
- return obj && DataView.prototype.isPrototypeOf(obj);
100
- }
101
- if (support.arrayBuffer) {
102
- var viewClasses = [
103
- "[object Int8Array]",
104
- "[object Uint8Array]",
105
- "[object Uint8ClampedArray]",
106
- "[object Int16Array]",
107
- "[object Uint16Array]",
108
- "[object Int32Array]",
109
- "[object Uint32Array]",
110
- "[object Float32Array]",
111
- "[object Float64Array]"
112
- ];
113
- var isArrayBufferView = ArrayBuffer.isView || function(obj) {
114
- return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1;
115
- };
116
- }
117
- function normalizeName(name) {
118
- if (typeof name !== "string") {
119
- name = String(name);
120
- }
121
- if (/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(name) || name === "") {
122
- throw new TypeError('Invalid character in header field name: "' + name + '"');
123
- }
124
- return name.toLowerCase();
125
- }
126
- function normalizeValue(value) {
127
- if (typeof value !== "string") {
128
- value = String(value);
129
- }
130
- return value;
131
- }
132
- function iteratorFor(items) {
133
- var iterator = {
134
- next: function() {
135
- var value = items.shift();
136
- return { done: value === void 0, value };
137
- }
138
- };
139
- if (support.iterable) {
140
- iterator[Symbol.iterator] = function() {
141
- return iterator;
142
- };
143
- }
144
- return iterator;
145
- }
146
- function Headers(headers) {
147
- this.map = {};
148
- if (headers instanceof Headers) {
149
- headers.forEach(function(value, name) {
150
- this.append(name, value);
151
- }, this);
152
- } else if (Array.isArray(headers)) {
153
- headers.forEach(function(header) {
154
- this.append(header[0], header[1]);
155
- }, this);
156
- } else if (headers) {
157
- Object.getOwnPropertyNames(headers).forEach(function(name) {
158
- this.append(name, headers[name]);
159
- }, this);
160
- }
161
- }
162
- Headers.prototype.append = function(name, value) {
163
- name = normalizeName(name);
164
- value = normalizeValue(value);
165
- var oldValue = this.map[name];
166
- this.map[name] = oldValue ? oldValue + ", " + value : value;
167
- };
168
- Headers.prototype["delete"] = function(name) {
169
- delete this.map[normalizeName(name)];
170
- };
171
- Headers.prototype.get = function(name) {
172
- name = normalizeName(name);
173
- return this.has(name) ? this.map[name] : null;
174
- };
175
- Headers.prototype.has = function(name) {
176
- return this.map.hasOwnProperty(normalizeName(name));
177
- };
178
- Headers.prototype.set = function(name, value) {
179
- this.map[normalizeName(name)] = normalizeValue(value);
180
- };
181
- Headers.prototype.forEach = function(callback, thisArg) {
182
- for (var name in this.map) {
183
- if (this.map.hasOwnProperty(name)) {
184
- callback.call(thisArg, this.map[name], name, this);
185
- }
186
- }
187
- };
188
- Headers.prototype.keys = function() {
189
- var items = [];
190
- this.forEach(function(value, name) {
191
- items.push(name);
192
- });
193
- return iteratorFor(items);
194
- };
195
- Headers.prototype.values = function() {
196
- var items = [];
197
- this.forEach(function(value) {
198
- items.push(value);
199
- });
200
- return iteratorFor(items);
201
- };
202
- Headers.prototype.entries = function() {
203
- var items = [];
204
- this.forEach(function(value, name) {
205
- items.push([name, value]);
206
- });
207
- return iteratorFor(items);
208
- };
209
- if (support.iterable) {
210
- Headers.prototype[Symbol.iterator] = Headers.prototype.entries;
211
- }
212
- function consumed(body) {
213
- if (body.bodyUsed) {
214
- return Promise.reject(new TypeError("Already read"));
215
- }
216
- body.bodyUsed = true;
217
- }
218
- function fileReaderReady(reader) {
219
- return new Promise(function(resolve, reject) {
220
- reader.onload = function() {
221
- resolve(reader.result);
222
- };
223
- reader.onerror = function() {
224
- reject(reader.error);
225
- };
226
- });
227
- }
228
- function readBlobAsArrayBuffer(blob) {
229
- var reader = new FileReader();
230
- var promise = fileReaderReady(reader);
231
- reader.readAsArrayBuffer(blob);
232
- return promise;
233
- }
234
- function readBlobAsText(blob) {
235
- var reader = new FileReader();
236
- var promise = fileReaderReady(reader);
237
- reader.readAsText(blob);
238
- return promise;
239
- }
240
- function readArrayBufferAsText(buf) {
241
- var view = new Uint8Array(buf);
242
- var chars = new Array(view.length);
243
- for (var i = 0; i < view.length; i++) {
244
- chars[i] = String.fromCharCode(view[i]);
245
- }
246
- return chars.join("");
247
- }
248
- function bufferClone(buf) {
249
- if (buf.slice) {
250
- return buf.slice(0);
251
- } else {
252
- var view = new Uint8Array(buf.byteLength);
253
- view.set(new Uint8Array(buf));
254
- return view.buffer;
255
- }
256
- }
257
- function Body() {
258
- this.bodyUsed = false;
259
- this._initBody = function(body) {
260
- this.bodyUsed = this.bodyUsed;
261
- this._bodyInit = body;
262
- if (!body) {
263
- this._bodyText = "";
264
- } else if (typeof body === "string") {
265
- this._bodyText = body;
266
- } else if (support.blob && Blob.prototype.isPrototypeOf(body)) {
267
- this._bodyBlob = body;
268
- } else if (support.formData && FormData.prototype.isPrototypeOf(body)) {
269
- this._bodyFormData = body;
270
- } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
271
- this._bodyText = body.toString();
272
- } else if (support.arrayBuffer && support.blob && isDataView(body)) {
273
- this._bodyArrayBuffer = bufferClone(body.buffer);
274
- this._bodyInit = new Blob([this._bodyArrayBuffer]);
275
- } else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) {
276
- this._bodyArrayBuffer = bufferClone(body);
277
- } else {
278
- this._bodyText = body = Object.prototype.toString.call(body);
279
- }
280
- if (!this.headers.get("content-type")) {
281
- if (typeof body === "string") {
282
- this.headers.set("content-type", "text/plain;charset=UTF-8");
283
- } else if (this._bodyBlob && this._bodyBlob.type) {
284
- this.headers.set("content-type", this._bodyBlob.type);
285
- } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) {
286
- this.headers.set("content-type", "application/x-www-form-urlencoded;charset=UTF-8");
287
- }
288
- }
289
- };
290
- if (support.blob) {
291
- this.blob = function() {
292
- var rejected = consumed(this);
293
- if (rejected) {
294
- return rejected;
295
- }
296
- if (this._bodyBlob) {
297
- return Promise.resolve(this._bodyBlob);
298
- } else if (this._bodyArrayBuffer) {
299
- return Promise.resolve(new Blob([this._bodyArrayBuffer]));
300
- } else if (this._bodyFormData) {
301
- throw new Error("could not read FormData body as blob");
302
- } else {
303
- return Promise.resolve(new Blob([this._bodyText]));
304
- }
305
- };
306
- this.arrayBuffer = function() {
307
- if (this._bodyArrayBuffer) {
308
- var isConsumed = consumed(this);
309
- if (isConsumed) {
310
- return isConsumed;
311
- }
312
- if (ArrayBuffer.isView(this._bodyArrayBuffer)) {
313
- return Promise.resolve(
314
- this._bodyArrayBuffer.buffer.slice(
315
- this._bodyArrayBuffer.byteOffset,
316
- this._bodyArrayBuffer.byteOffset + this._bodyArrayBuffer.byteLength
317
- )
318
- );
319
- } else {
320
- return Promise.resolve(this._bodyArrayBuffer);
321
- }
322
- } else {
323
- return this.blob().then(readBlobAsArrayBuffer);
324
- }
325
- };
326
- }
327
- this.text = function() {
328
- var rejected = consumed(this);
329
- if (rejected) {
330
- return rejected;
331
- }
332
- if (this._bodyBlob) {
333
- return readBlobAsText(this._bodyBlob);
334
- } else if (this._bodyArrayBuffer) {
335
- return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer));
336
- } else if (this._bodyFormData) {
337
- throw new Error("could not read FormData body as text");
338
- } else {
339
- return Promise.resolve(this._bodyText);
340
- }
341
- };
342
- if (support.formData) {
343
- this.formData = function() {
344
- return this.text().then(decode);
345
- };
346
- }
347
- this.json = function() {
348
- return this.text().then(JSON.parse);
349
- };
350
- return this;
351
- }
352
- var methods = ["DELETE", "GET", "HEAD", "OPTIONS", "POST", "PUT"];
353
- function normalizeMethod(method) {
354
- var upcased = method.toUpperCase();
355
- return methods.indexOf(upcased) > -1 ? upcased : method;
356
- }
357
- function Request(input, options) {
358
- if (!(this instanceof Request)) {
359
- throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');
360
- }
361
- options = options || {};
362
- var body = options.body;
363
- if (input instanceof Request) {
364
- if (input.bodyUsed) {
365
- throw new TypeError("Already read");
366
- }
367
- this.url = input.url;
368
- this.credentials = input.credentials;
369
- if (!options.headers) {
370
- this.headers = new Headers(input.headers);
371
- }
372
- this.method = input.method;
373
- this.mode = input.mode;
374
- this.signal = input.signal;
375
- if (!body && input._bodyInit != null) {
376
- body = input._bodyInit;
377
- input.bodyUsed = true;
378
- }
379
- } else {
380
- this.url = String(input);
381
- }
382
- this.credentials = options.credentials || this.credentials || "same-origin";
383
- if (options.headers || !this.headers) {
384
- this.headers = new Headers(options.headers);
385
- }
386
- this.method = normalizeMethod(options.method || this.method || "GET");
387
- this.mode = options.mode || this.mode || null;
388
- this.signal = options.signal || this.signal;
389
- this.referrer = null;
390
- if ((this.method === "GET" || this.method === "HEAD") && body) {
391
- throw new TypeError("Body not allowed for GET or HEAD requests");
392
- }
393
- this._initBody(body);
394
- if (this.method === "GET" || this.method === "HEAD") {
395
- if (options.cache === "no-store" || options.cache === "no-cache") {
396
- var reParamSearch = /([?&])_=[^&]*/;
397
- if (reParamSearch.test(this.url)) {
398
- this.url = this.url.replace(reParamSearch, "$1_=" + (/* @__PURE__ */ new Date()).getTime());
399
- } else {
400
- var reQueryString = /\?/;
401
- this.url += (reQueryString.test(this.url) ? "&" : "?") + "_=" + (/* @__PURE__ */ new Date()).getTime();
402
- }
403
- }
404
- }
405
- }
406
- Request.prototype.clone = function() {
407
- return new Request(this, { body: this._bodyInit });
408
- };
409
- function decode(body) {
410
- var form = new FormData();
411
- body.trim().split("&").forEach(function(bytes) {
412
- if (bytes) {
413
- var split = bytes.split("=");
414
- var name = split.shift().replace(/\+/g, " ");
415
- var value = split.join("=").replace(/\+/g, " ");
416
- form.append(decodeURIComponent(name), decodeURIComponent(value));
417
- }
418
- });
419
- return form;
420
- }
421
- function parseHeaders(rawHeaders) {
422
- var headers = new Headers();
423
- var preProcessedHeaders = rawHeaders.replace(/\r?\n[\t ]+/g, " ");
424
- preProcessedHeaders.split("\r").map(function(header) {
425
- return header.indexOf("\n") === 0 ? header.substr(1, header.length) : header;
426
- }).forEach(function(line) {
427
- var parts = line.split(":");
428
- var key = parts.shift().trim();
429
- if (key) {
430
- var value = parts.join(":").trim();
431
- headers.append(key, value);
432
- }
433
- });
434
- return headers;
435
- }
436
- Body.call(Request.prototype);
437
- function Response(bodyInit, options) {
438
- if (!(this instanceof Response)) {
439
- throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');
440
- }
441
- if (!options) {
442
- options = {};
443
- }
444
- this.type = "default";
445
- this.status = options.status === void 0 ? 200 : options.status;
446
- this.ok = this.status >= 200 && this.status < 300;
447
- this.statusText = options.statusText === void 0 ? "" : "" + options.statusText;
448
- this.headers = new Headers(options.headers);
449
- this.url = options.url || "";
450
- this._initBody(bodyInit);
451
- }
452
- Body.call(Response.prototype);
453
- Response.prototype.clone = function() {
454
- return new Response(this._bodyInit, {
455
- status: this.status,
456
- statusText: this.statusText,
457
- headers: new Headers(this.headers),
458
- url: this.url
459
- });
460
- };
461
- Response.error = function() {
462
- var response = new Response(null, { status: 0, statusText: "" });
463
- response.type = "error";
464
- return response;
465
- };
466
- var redirectStatuses = [301, 302, 303, 307, 308];
467
- Response.redirect = function(url, status) {
468
- if (redirectStatuses.indexOf(status) === -1) {
469
- throw new RangeError("Invalid status code");
470
- }
471
- return new Response(null, { status, headers: { location: url } });
472
- };
473
- exports2.DOMException = global2.DOMException;
474
- try {
475
- new exports2.DOMException();
476
- } catch (err) {
477
- exports2.DOMException = function(message, name) {
478
- this.message = message;
479
- this.name = name;
480
- var error = Error(message);
481
- this.stack = error.stack;
482
- };
483
- exports2.DOMException.prototype = Object.create(Error.prototype);
484
- exports2.DOMException.prototype.constructor = exports2.DOMException;
485
- }
486
- function fetch2(input, init) {
487
- return new Promise(function(resolve, reject) {
488
- var request = new Request(input, init);
489
- if (request.signal && request.signal.aborted) {
490
- return reject(new exports2.DOMException("Aborted", "AbortError"));
491
- }
492
- var xhr = new XMLHttpRequest();
493
- function abortXhr() {
494
- xhr.abort();
495
- }
496
- xhr.onload = function() {
497
- var options = {
498
- status: xhr.status,
499
- statusText: xhr.statusText,
500
- headers: parseHeaders(xhr.getAllResponseHeaders() || "")
501
- };
502
- options.url = "responseURL" in xhr ? xhr.responseURL : options.headers.get("X-Request-URL");
503
- var body = "response" in xhr ? xhr.response : xhr.responseText;
504
- setTimeout(function() {
505
- resolve(new Response(body, options));
506
- }, 0);
507
- };
508
- xhr.onerror = function() {
509
- setTimeout(function() {
510
- reject(new TypeError("Network request failed"));
511
- }, 0);
512
- };
513
- xhr.ontimeout = function() {
514
- setTimeout(function() {
515
- reject(new TypeError("Network request failed"));
516
- }, 0);
517
- };
518
- xhr.onabort = function() {
519
- setTimeout(function() {
520
- reject(new exports2.DOMException("Aborted", "AbortError"));
521
- }, 0);
522
- };
523
- function fixUrl(url) {
524
- try {
525
- return url === "" && global2.location.href ? global2.location.href : url;
526
- } catch (e) {
527
- return url;
528
- }
529
- }
530
- xhr.open(request.method, fixUrl(request.url), true);
531
- if (request.credentials === "include") {
532
- xhr.withCredentials = true;
533
- } else if (request.credentials === "omit") {
534
- xhr.withCredentials = false;
535
- }
536
- if ("responseType" in xhr) {
537
- if (support.blob) {
538
- xhr.responseType = "blob";
539
- } else if (support.arrayBuffer && request.headers.get("Content-Type") && request.headers.get("Content-Type").indexOf("application/octet-stream") !== -1) {
540
- xhr.responseType = "arraybuffer";
541
- }
542
- }
543
- if (init && typeof init.headers === "object" && !(init.headers instanceof Headers)) {
544
- Object.getOwnPropertyNames(init.headers).forEach(function(name) {
545
- xhr.setRequestHeader(name, normalizeValue(init.headers[name]));
546
- });
547
- } else {
548
- request.headers.forEach(function(value, name) {
549
- xhr.setRequestHeader(name, value);
550
- });
551
- }
552
- if (request.signal) {
553
- request.signal.addEventListener("abort", abortXhr);
554
- xhr.onreadystatechange = function() {
555
- if (xhr.readyState === 4) {
556
- request.signal.removeEventListener("abort", abortXhr);
557
- }
558
- };
559
- }
560
- xhr.send(typeof request._bodyInit === "undefined" ? null : request._bodyInit);
561
- });
562
- }
563
- fetch2.polyfill = true;
564
- if (!global2.fetch) {
565
- global2.fetch = fetch2;
566
- global2.Headers = Headers;
567
- global2.Request = Request;
568
- global2.Response = Response;
569
- }
570
- exports2.Headers = Headers;
571
- exports2.Request = Request;
572
- exports2.Response = Response;
573
- exports2.fetch = fetch2;
574
- return exports2;
575
- }({});
576
- })(__globalThis__);
577
- __globalThis__.fetch.ponyfill = true;
578
- delete __globalThis__.fetch.polyfill;
579
- var ctx = __global__.fetch ? __global__ : __globalThis__;
580
- exports = ctx.fetch;
581
- exports.default = ctx.fetch;
582
- exports.fetch = ctx.fetch;
583
- exports.Headers = ctx.Headers;
584
- exports.Request = ctx.Request;
585
- exports.Response = ctx.Response;
586
- module2.exports = exports;
587
- }
588
- });
589
-
590
56
  // src/api/http-client.ts
591
57
  var http_client_exports = {};
592
58
  __export(http_client_exports, {
@@ -594,7 +60,7 @@ __export(http_client_exports, {
594
60
  createHttpClient: () => createHttpClient
595
61
  });
596
62
  module.exports = __toCommonJS(http_client_exports);
597
- var import_browser_ponyfill = __toESM(require_browser_ponyfill(), 1);
63
+ var import_fetch = require('../lib/isomorphic/web/fetch.cjs');
598
64
  var import_debug = require('../lib/debug.cjs');
599
65
  var import_jsonrpc = require('./jsonrpc/jsonrpc.enums.cjs');
600
66
  var import_base_client = require('./base-client.cjs');
@@ -614,7 +80,7 @@ function createConnection(opts) {
614
80
  function send(body, jwt) {
615
81
  return __async(this, null, function* () {
616
82
  const jsonBody = JSON.parse(body);
617
- const res = yield (0, import_browser_ponyfill.default)(`${opts.host}/api`, {
83
+ const res = yield (0, import_fetch.fetch)(`${opts.host}/api`, {
618
84
  keepalive: true,
619
85
  method: "POST",
620
86
  headers: {
@@ -626,7 +92,7 @@ function createConnection(opts) {
626
92
  this.onmessage(__spreadProps(__spreadValues({}, responseBody), { id: jsonBody.id }));
627
93
  });
628
94
  }
629
- const $connect = (0, import_browser_ponyfill.default)(`${url}/api`, {
95
+ const $connect = (0, import_fetch.fetch)(`${url}/api`, {
630
96
  method: "POST",
631
97
  headers: {
632
98
  Authorization: `Bearer ${opts.jwt}`
@@ -641,7 +107,7 @@ function createConnection(opts) {
641
107
  if (res.error) {
642
108
  throw new Error(res.error.message);
643
109
  }
644
- return true;
110
+ return;
645
111
  });
646
112
  return {
647
113
  send,