@builder.io/sdk 1.1.27 → 1.1.28-6

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.
Files changed (44) hide show
  1. package/.envrc +1 -0
  2. package/.task/checksum/build +1 -0
  3. package/CHANGELOG.md +1 -1
  4. package/Taskfile.yaml +15 -0
  5. package/coverage/clover.xml +6 -0
  6. package/coverage/coverage-final.json +1 -0
  7. package/coverage/lcov-report/base.css +224 -0
  8. package/coverage/lcov-report/block-navigation.js +87 -0
  9. package/coverage/lcov-report/favicon.png +0 -0
  10. package/coverage/lcov-report/index.html +101 -0
  11. package/coverage/lcov-report/prettify.css +1 -0
  12. package/coverage/lcov-report/prettify.js +2 -0
  13. package/coverage/lcov-report/query-string.class.ts.html +328 -0
  14. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  15. package/coverage/lcov-report/sorter.js +196 -0
  16. package/coverage/lcov-report/url.ts.html +253 -0
  17. package/coverage/lcov.info +0 -0
  18. package/dist/index.browser.js +1 -1
  19. package/dist/index.browser.js.map +1 -1
  20. package/dist/index.cjs.js +107 -62
  21. package/dist/index.cjs.js.map +1 -1
  22. package/dist/index.esm.js +107 -62
  23. package/dist/index.esm.js.map +1 -1
  24. package/dist/index.umd.js +107 -62
  25. package/dist/index.umd.js.map +1 -1
  26. package/dist/package.json +1 -1
  27. package/dist/src/builder.class.d.ts +0 -5
  28. package/dist/src/builder.class.js +31 -52
  29. package/dist/src/builder.class.js.map +1 -1
  30. package/dist/src/functions/fetch.function.d.ts +2 -2
  31. package/dist/src/functions/fetch.function.js +10 -7
  32. package/dist/src/functions/fetch.function.js.map +1 -1
  33. package/dist/src/functions/to-error.d.ts +13 -0
  34. package/dist/src/functions/to-error.js +22 -0
  35. package/dist/src/functions/to-error.js.map +1 -0
  36. package/dist/src/url.d.ts +9 -0
  37. package/dist/src/url.js +51 -0
  38. package/dist/src/url.js.map +1 -0
  39. package/dist/src/url.test.d.ts +1 -0
  40. package/dist/src/url.test.js +129 -0
  41. package/dist/src/url.test.js.map +1 -0
  42. package/dist/tsconfig.tsbuildinfo +1 -0
  43. package/package.json +1 -1
  44. package/tsconfig.json +15 -3
package/dist/index.umd.js CHANGED
@@ -152,7 +152,7 @@
152
152
  throw new Error("Property name \"".concat(name, "\" is not allowed"));
153
153
  }
154
154
 
155
- var version = "1.1.27-4";
155
+ var version = "1.1.28-5";
156
156
 
157
157
  var Subscription = /** @class */ (function () {
158
158
  function Subscription(listeners, listener) {
@@ -479,13 +479,17 @@
479
479
  }
480
480
  });
481
481
  }
482
- var fetch = typeof global === 'object' && typeof global.fetch === 'function'
483
- ? global.fetch
484
- : typeof window === 'undefined'
485
- ? serverOnlyRequire$1('node-fetch')
486
- : typeof window.fetch !== 'undefined'
487
- ? window.fetch
488
- : tinyFetch;
482
+ var fetch;
483
+ // If fetch is defined, in the browser, via polyfill, or in a Cloudflare worker, use it.
484
+ if (globalThis.fetch) {
485
+ fetch = globalThis.fetch;
486
+ }
487
+ // If fetch is not defined, in a Node.js environment, use node-fetch.
488
+ if (typeof window === 'undefined') {
489
+ fetch !== null && fetch !== void 0 ? fetch : (fetch = serverOnlyRequire$1('node-fetch'));
490
+ }
491
+ // Otherwise, use tiny-fetch.
492
+ fetch !== null && fetch !== void 0 ? fetch : (fetch = tinyFetch);
489
493
 
490
494
  function assign(target) {
491
495
  var args = [];
@@ -899,6 +903,52 @@
899
903
  return uuidv4().replace(/-/g, '');
900
904
  }
901
905
 
906
+ function emptyUrl() {
907
+ return {
908
+ query: null,
909
+ port: null,
910
+ auth: null,
911
+ hash: null,
912
+ host: null,
913
+ hostname: null,
914
+ href: null,
915
+ path: null,
916
+ pathname: null,
917
+ protocol: null,
918
+ search: null,
919
+ slashes: null,
920
+ };
921
+ }
922
+ // Replacement for `url.parse` using `URL` global object that works with relative paths.
923
+ // Assumptions: this function operates in a NodeJS environment.
924
+ function parse(url) {
925
+ var out = emptyUrl();
926
+ var u;
927
+ var pathOnly = url === '' || url[0] === '/';
928
+ if (pathOnly) {
929
+ u = new URL(url, 'http://0.0.0.0/');
930
+ out.href = u.href;
931
+ out.href = out.href.slice(14); // remove 'http://0.0.0.0/'
932
+ }
933
+ else {
934
+ u = new URL(url);
935
+ out.href = u.href;
936
+ out.port = u.port === '' ? null : u.port;
937
+ out.hash = u.hash === '' ? null : u.hash;
938
+ out.host = u.host;
939
+ out.hostname = u.hostname;
940
+ out.href = u.href;
941
+ out.pathname = u.pathname;
942
+ out.protocol = u.protocol;
943
+ out.slashes = url[u.protocol.length] === '/'; // check if the mimetype is proceeded by a slash
944
+ }
945
+ out.search = u.search;
946
+ out.query = u.search.slice(1); // remove '?'
947
+ out.path = "".concat(u.pathname).concat(u.search);
948
+ out.pathname = u.pathname;
949
+ return out;
950
+ }
951
+
902
952
  function pad (hash, len) {
903
953
  while (hash.length < len) {
904
954
  hash = '0' + hash;
@@ -967,6 +1017,24 @@
967
1017
 
968
1018
  var hashSum = sum;
969
1019
 
1020
+ /**
1021
+ * Safe conversion to error type. Intended to be used in catch blocks where the
1022
+ * value is not guaranteed to be an error.
1023
+ *
1024
+ * @example
1025
+ * try {
1026
+ * throw new Error('Something went wrong')
1027
+ * }
1028
+ * catch (err: unknown) {
1029
+ * const error: Error = toError(err)
1030
+ * }
1031
+ */
1032
+ function toError(err) {
1033
+ if (err instanceof Error)
1034
+ return err;
1035
+ return new Error(String(err));
1036
+ }
1037
+
970
1038
  function datePlusMinutes(minutes) {
971
1039
  if (minutes === void 0) { minutes = 30; }
972
1040
  return new Date(Date.now() + minutes * 60000);
@@ -1000,12 +1068,24 @@
1000
1068
  }
1001
1069
  var urlParser = {
1002
1070
  parse: function (url) {
1003
- var parser = document.createElement('a');
1004
- parser.href = url;
1071
+ var el = document.createElement('a');
1072
+ el.href = url;
1005
1073
  var out = {};
1006
- var props = 'username password host hostname port protocol origin pathname search hash'.split(' ');
1007
- for (var i = props.length; i--;) {
1008
- out[props[i]] = parser[props[i]];
1074
+ var props = [
1075
+ 'username',
1076
+ 'password',
1077
+ 'host',
1078
+ 'hostname',
1079
+ 'port',
1080
+ 'protocol',
1081
+ 'origin',
1082
+ 'pathname',
1083
+ 'search',
1084
+ 'hash',
1085
+ ];
1086
+ for (var _i = 0, props_1 = props; _i < props_1.length; _i++) {
1087
+ var prop = props_1[_i];
1088
+ out[prop] = el[prop];
1009
1089
  }
1010
1090
  // IE 11 pathname handling workaround
1011
1091
  // (IE omits preceeding '/', unlike other browsers)
@@ -1017,11 +1097,11 @@
1017
1097
  return out;
1018
1098
  },
1019
1099
  };
1020
- var parse = isReactNative
1021
- ? function () { return ({}); }
1100
+ var parse$1 = isReactNative
1101
+ ? function () { return emptyUrl(); }
1022
1102
  : typeof window === 'object'
1023
1103
  ? urlParser.parse
1024
- : serverOnlyRequire$1('url').parse;
1104
+ : parse;
1025
1105
  function setCookie(name$$1, value, expires) {
1026
1106
  try {
1027
1107
  var expiresString = '';
@@ -1779,7 +1859,7 @@
1779
1859
  if (isBrowser) {
1780
1860
  addEventListener('message', function (event) {
1781
1861
  var _a, _b, _c, _d, _e;
1782
- var url = parse(event.origin);
1862
+ var url = parse$1(event.origin);
1783
1863
  var isRestricted = ['builder.register', 'builder.registerComponent'].indexOf((_a = event.data) === null || _a === void 0 ? void 0 : _a.type) === -1;
1784
1864
  var isTrusted = url.hostname && Builder.isTrustedHost(url.hostname);
1785
1865
  if (isRestricted && !isTrusted) {
@@ -1921,7 +2001,7 @@
1921
2001
  result = fn.apply(_this, args);
1922
2002
  }
1923
2003
  catch (err) {
1924
- error = err;
2004
+ error = toError(err);
1925
2005
  }
1926
2006
  if (error) {
1927
2007
  (_d = window.parent) === null || _d === void 0 ? void 0 : _d.postMessage({
@@ -1991,14 +2071,15 @@
1991
2071
  });
1992
2072
  // TODO: allow adding location object as property and/or in constructor
1993
2073
  Builder.prototype.getLocation = function () {
2074
+ var _a;
1994
2075
  var parsedLocation = {};
1995
2076
  // in ssr mode
1996
2077
  if (this.request) {
1997
- parsedLocation = parse(this.request.url);
2078
+ parsedLocation = parse$1((_a = this.request.url) !== null && _a !== void 0 ? _a : '');
1998
2079
  }
1999
2080
  else if (typeof location === 'object') {
2000
2081
  // in the browser
2001
- parsedLocation = parse(location.href);
2082
+ parsedLocation = parse$1(location.href);
2002
2083
  }
2003
2084
  // IE11 bug with parsed path being empty string
2004
2085
  // causes issues with our user targeting
@@ -2170,47 +2251,6 @@
2170
2251
  }
2171
2252
  return observable;
2172
2253
  };
2173
- Builder.prototype.requestUrl = function (url, options) {
2174
- if (Builder.isBrowser) {
2175
- return fetch(url, options).then(function (res) { return res.json(); });
2176
- }
2177
- return new Promise(function (resolve, reject) {
2178
- var parsedUrl = parse(url);
2179
- var module = parsedUrl.protocol === 'http:' ? serverOnlyRequire$1('http') : serverOnlyRequire$1('https');
2180
- var requestOptions = {
2181
- host: parsedUrl.hostname,
2182
- port: parsedUrl.port,
2183
- path: parsedUrl.pathname + parsedUrl.search,
2184
- headers: __assign({}, options === null || options === void 0 ? void 0 : options.headers),
2185
- };
2186
- module
2187
- .get(requestOptions, function (resp) {
2188
- var data = '';
2189
- // We are collecting textual data
2190
- resp.setEncoding('utf8');
2191
- // A chunk of data has been recieved.
2192
- resp.on('data', function (chunk) {
2193
- data += chunk;
2194
- });
2195
- // The whole response has been received. Print out the result.
2196
- resp.on('end', function () {
2197
- try {
2198
- resolve(JSON.parse(data));
2199
- }
2200
- catch (err) {
2201
- if ((err === null || err === void 0 ? void 0 : err.name) === 'SyntaxError') {
2202
- var jsonParseError = new Error("[Builder.io] ERROR: invalid response.\nRequest: ".concat(JSON.stringify(requestOptions, null, 2), "\nResponse Data: ").concat(data, "\n"));
2203
- reject(jsonParseError);
2204
- }
2205
- reject(err);
2206
- }
2207
- });
2208
- })
2209
- .on('error', function (error) {
2210
- reject(error);
2211
- });
2212
- });
2213
- };
2214
2254
  Object.defineProperty(Builder.prototype, "host", {
2215
2255
  get: function () {
2216
2256
  switch (this.env) {
@@ -2372,7 +2412,12 @@
2372
2412
  if (this.authToken) {
2373
2413
  requestOptions.headers = __assign(__assign({}, requestOptions.headers), { Authorization: "Bearer ".concat(this.authToken) });
2374
2414
  }
2375
- var promise = this.requestUrl("".concat(host, "/api/v1/").concat(format === 'solid' || format === 'react' ? 'codegen' : 'query', "/").concat(this.apiKey, "/").concat(keyNames) + (queryParams && hasParams ? "?".concat(queryStr) : ''), requestOptions).then(function (result) {
2415
+ var fn = format === 'solid' || format === 'react' ? 'codegen' : 'query';
2416
+ var url = "".concat(host, "/api/v1/").concat(fn, "/").concat(this.apiKey, "/").concat(keyNames) +
2417
+ (queryParams && hasParams ? "?".concat(queryStr) : '');
2418
+ var promise = fetch(url, requestOptions)
2419
+ .then(function (res) { return res.json(); })
2420
+ .then(function (result) {
2376
2421
  for (var _i = 0, queue_3 = queue; _i < queue_3.length; _i++) {
2377
2422
  var options = queue_3[_i];
2378
2423
  var keyName = options.key;