@builder.io/sdk 1.1.27-4 → 1.1.27-5

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.esm.js CHANGED
@@ -123,7 +123,7 @@ function assertAllowedPropertyName(name) {
123
123
  throw new Error("Property name \"".concat(name, "\" is not allowed"));
124
124
  }
125
125
 
126
- var version = "1.1.27-3";
126
+ var version = "1.1.27-4";
127
127
 
128
128
  var Subscription = /** @class */ (function () {
129
129
  function Subscription(listeners, listener) {
@@ -450,13 +450,17 @@ function tinyFetch(url, options) {
450
450
  }
451
451
  });
452
452
  }
453
- var fetch = typeof global === 'object' && typeof global.fetch === 'function'
454
- ? global.fetch
455
- : typeof window === 'undefined'
456
- ? serverOnlyRequire$1('node-fetch')
457
- : typeof window.fetch !== 'undefined'
458
- ? window.fetch
459
- : tinyFetch;
453
+ var fetch;
454
+ // If fetch is defined, in the browser, via polyfill, or in a Cloudflare worker, use it.
455
+ if (globalThis.fetch) {
456
+ fetch = globalThis.fetch;
457
+ }
458
+ // If fetch is not defined, in a Node.js environment, use node-fetch.
459
+ if (typeof window === 'undefined') {
460
+ fetch !== null && fetch !== void 0 ? fetch : (fetch = serverOnlyRequire$1('node-fetch'));
461
+ }
462
+ // Otherwise, use tiny-fetch.
463
+ fetch !== null && fetch !== void 0 ? fetch : (fetch = tinyFetch);
460
464
 
461
465
  function assign(target) {
462
466
  var args = [];
@@ -870,6 +874,70 @@ function uuid() {
870
874
  return uuidv4().replace(/-/g, '');
871
875
  }
872
876
 
877
+ function emptyUrl() {
878
+ return {
879
+ query: null,
880
+ port: null,
881
+ auth: null,
882
+ hash: null,
883
+ host: null,
884
+ hostname: null,
885
+ href: null,
886
+ path: null,
887
+ pathname: null,
888
+ protocol: null,
889
+ search: null,
890
+ slashes: null,
891
+ };
892
+ }
893
+ // Replacement for `url.parse` using `URL` global object that works with relative paths.
894
+ // Assumptions: this function operates in a NodeJS environment.
895
+ function parse(url) {
896
+ var out = emptyUrl();
897
+ var u;
898
+ var pathOnly = url === '' || url[0] === '/';
899
+ if (pathOnly) {
900
+ u = new URL(url, 'http://0.0.0.0/');
901
+ out.href = u.href;
902
+ out.href = out.href.slice(14); // remove 'http://0.0.0.0/'
903
+ }
904
+ else {
905
+ u = new URL(url);
906
+ out.href = u.href;
907
+ out.port = u.port === '' ? null : u.port;
908
+ out.hash = u.hash === '' ? null : u.hash;
909
+ out.host = u.host;
910
+ out.hostname = u.hostname;
911
+ out.href = u.href;
912
+ out.pathname = u.pathname;
913
+ out.protocol = u.protocol;
914
+ out.slashes = url[u.protocol.length] === '/'; // check if the mimetype is proceeded by a slash
915
+ }
916
+ out.search = u.search;
917
+ out.query = u.search.slice(1); // remove '?'
918
+ out.path = "".concat(u.pathname).concat(u.search);
919
+ out.pathname = u.pathname;
920
+ return out;
921
+ }
922
+
923
+ /**
924
+ * Safe conversion to error type. Intended to be used in catch blocks where the
925
+ * value is not guaranteed to be an error.
926
+ *
927
+ * @example
928
+ * try {
929
+ * throw new Error('Something went wrong')
930
+ * }
931
+ * catch (err: unknown) {
932
+ * const error: Error = toError(err)
933
+ * }
934
+ */
935
+ function toError(err) {
936
+ if (err instanceof Error)
937
+ return err;
938
+ return new Error(String(err));
939
+ }
940
+
873
941
  function datePlusMinutes(minutes) {
874
942
  if (minutes === void 0) { minutes = 30; }
875
943
  return new Date(Date.now() + minutes * 60000);
@@ -903,12 +971,24 @@ function getQueryParam(url, variable) {
903
971
  }
904
972
  var urlParser = {
905
973
  parse: function (url) {
906
- var parser = document.createElement('a');
907
- parser.href = url;
974
+ var el = document.createElement('a');
975
+ el.href = url;
908
976
  var out = {};
909
- var props = 'username password host hostname port protocol origin pathname search hash'.split(' ');
910
- for (var i = props.length; i--;) {
911
- out[props[i]] = parser[props[i]];
977
+ var props = [
978
+ 'username',
979
+ 'password',
980
+ 'host',
981
+ 'hostname',
982
+ 'port',
983
+ 'protocol',
984
+ 'origin',
985
+ 'pathname',
986
+ 'search',
987
+ 'hash',
988
+ ];
989
+ for (var _i = 0, props_1 = props; _i < props_1.length; _i++) {
990
+ var prop = props_1[_i];
991
+ out[prop] = el[prop];
912
992
  }
913
993
  // IE 11 pathname handling workaround
914
994
  // (IE omits preceeding '/', unlike other browsers)
@@ -920,11 +1000,11 @@ var urlParser = {
920
1000
  return out;
921
1001
  },
922
1002
  };
923
- var parse = isReactNative
924
- ? function () { return ({}); }
1003
+ var parse$1 = isReactNative
1004
+ ? function () { return emptyUrl(); }
925
1005
  : typeof window === 'object'
926
1006
  ? urlParser.parse
927
- : serverOnlyRequire$1('url').parse;
1007
+ : parse;
928
1008
  function setCookie(name$$1, value, expires) {
929
1009
  try {
930
1010
  var expiresString = '';
@@ -1682,7 +1762,7 @@ var Builder = /** @class */ (function () {
1682
1762
  if (isBrowser) {
1683
1763
  addEventListener('message', function (event) {
1684
1764
  var _a, _b, _c, _d, _e;
1685
- var url = parse(event.origin);
1765
+ var url = parse$1(event.origin);
1686
1766
  var isRestricted = ['builder.register', 'builder.registerComponent'].indexOf((_a = event.data) === null || _a === void 0 ? void 0 : _a.type) === -1;
1687
1767
  var isTrusted = url.hostname && Builder.isTrustedHost(url.hostname);
1688
1768
  if (isRestricted && !isTrusted) {
@@ -1824,7 +1904,7 @@ var Builder = /** @class */ (function () {
1824
1904
  result = fn.apply(_this, args);
1825
1905
  }
1826
1906
  catch (err) {
1827
- error = err;
1907
+ error = toError(err);
1828
1908
  }
1829
1909
  if (error) {
1830
1910
  (_d = window.parent) === null || _d === void 0 ? void 0 : _d.postMessage({
@@ -1894,14 +1974,15 @@ var Builder = /** @class */ (function () {
1894
1974
  });
1895
1975
  // TODO: allow adding location object as property and/or in constructor
1896
1976
  Builder.prototype.getLocation = function () {
1977
+ var _a;
1897
1978
  var parsedLocation = {};
1898
1979
  // in ssr mode
1899
1980
  if (this.request) {
1900
- parsedLocation = parse(this.request.url);
1981
+ parsedLocation = parse$1((_a = this.request.url) !== null && _a !== void 0 ? _a : '');
1901
1982
  }
1902
1983
  else if (typeof location === 'object') {
1903
1984
  // in the browser
1904
- parsedLocation = parse(location.href);
1985
+ parsedLocation = parse$1(location.href);
1905
1986
  }
1906
1987
  // IE11 bug with parsed path being empty string
1907
1988
  // causes issues with our user targeting
@@ -2073,47 +2154,6 @@ var Builder = /** @class */ (function () {
2073
2154
  }
2074
2155
  return observable;
2075
2156
  };
2076
- Builder.prototype.requestUrl = function (url, options) {
2077
- if (Builder.isBrowser) {
2078
- return fetch(url, options).then(function (res) { return res.json(); });
2079
- }
2080
- return new Promise(function (resolve, reject) {
2081
- var parsedUrl = parse(url);
2082
- var module = parsedUrl.protocol === 'http:' ? serverOnlyRequire$1('http') : serverOnlyRequire$1('https');
2083
- var requestOptions = {
2084
- host: parsedUrl.hostname,
2085
- port: parsedUrl.port,
2086
- path: parsedUrl.pathname + parsedUrl.search,
2087
- headers: __assign({}, options === null || options === void 0 ? void 0 : options.headers),
2088
- };
2089
- module
2090
- .get(requestOptions, function (resp) {
2091
- var data = '';
2092
- // We are collecting textual data
2093
- resp.setEncoding('utf8');
2094
- // A chunk of data has been recieved.
2095
- resp.on('data', function (chunk) {
2096
- data += chunk;
2097
- });
2098
- // The whole response has been received. Print out the result.
2099
- resp.on('end', function () {
2100
- try {
2101
- resolve(JSON.parse(data));
2102
- }
2103
- catch (err) {
2104
- if ((err === null || err === void 0 ? void 0 : err.name) === 'SyntaxError') {
2105
- var jsonParseError = new Error("[Builder.io] ERROR: invalid response.\nRequest: ".concat(JSON.stringify(requestOptions, null, 2), "\nResponse Data: ").concat(data, "\n"));
2106
- reject(jsonParseError);
2107
- }
2108
- reject(err);
2109
- }
2110
- });
2111
- })
2112
- .on('error', function (error) {
2113
- reject(error);
2114
- });
2115
- });
2116
- };
2117
2157
  Object.defineProperty(Builder.prototype, "host", {
2118
2158
  get: function () {
2119
2159
  switch (this.env) {
@@ -2275,7 +2315,12 @@ var Builder = /** @class */ (function () {
2275
2315
  if (this.authToken) {
2276
2316
  requestOptions.headers = __assign(__assign({}, requestOptions.headers), { Authorization: "Bearer ".concat(this.authToken) });
2277
2317
  }
2278
- 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) {
2318
+ var fn = format === 'solid' || format === 'react' ? 'codegen' : 'query';
2319
+ var url = "".concat(host, "/api/v1/").concat(fn, "/").concat(this.apiKey, "/").concat(keyNames) +
2320
+ (queryParams && hasParams ? "?".concat(queryStr) : '');
2321
+ var promise = fetch(url, requestOptions)
2322
+ .then(function (res) { return res.json(); })
2323
+ .then(function (result) {
2279
2324
  for (var _i = 0, queue_3 = queue; _i < queue_3.length; _i++) {
2280
2325
  var options = queue_3[_i];
2281
2326
  var keyName = options.key;