@builder.io/sdk 1.1.34 → 1.1.36-0

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 (69) hide show
  1. package/.yarnrc.yml +1 -0
  2. package/CHANGELOG.md +4 -1
  3. package/coverage/clover.xml +3848 -0
  4. package/coverage/coverage-final.json +19 -0
  5. package/coverage/lcov-report/base.css +224 -0
  6. package/coverage/lcov-report/block-navigation.js +87 -0
  7. package/coverage/lcov-report/favicon.png +0 -0
  8. package/coverage/lcov-report/index.html +176 -0
  9. package/coverage/lcov-report/prettify.css +1 -0
  10. package/coverage/lcov-report/prettify.js +2 -0
  11. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  12. package/coverage/lcov-report/sorter.js +196 -0
  13. package/coverage/lcov-report/src/builder.class.ts.html +8107 -0
  14. package/coverage/lcov-report/src/classes/animator.class.ts.html +847 -0
  15. package/coverage/lcov-report/src/classes/cookies.class.ts.html +559 -0
  16. package/coverage/lcov-report/src/classes/index.html +176 -0
  17. package/coverage/lcov-report/src/classes/observable.class.ts.html +388 -0
  18. package/coverage/lcov-report/src/classes/promise.class.ts.html +607 -0
  19. package/coverage/lcov-report/src/classes/query-string.class.ts.html +328 -0
  20. package/coverage/lcov-report/src/functions/assign.function.ts.html +139 -0
  21. package/coverage/lcov-report/src/functions/fetch.function.ts.html +427 -0
  22. package/coverage/lcov-report/src/functions/get-top-level-domain.ts.html +121 -0
  23. package/coverage/lcov-report/src/functions/index.html +236 -0
  24. package/coverage/lcov-report/src/functions/next-tick.function.ts.html +184 -0
  25. package/coverage/lcov-report/src/functions/omit.function.ts.html +106 -0
  26. package/coverage/lcov-report/src/functions/server-only-require.function.ts.html +121 -0
  27. package/coverage/lcov-report/src/functions/throttle.function.ts.html +181 -0
  28. package/coverage/lcov-report/src/functions/to-error.ts.html +133 -0
  29. package/coverage/lcov-report/src/functions/uuid.ts.html +136 -0
  30. package/coverage/lcov-report/src/index.html +131 -0
  31. package/coverage/lcov-report/src/polyfills/custom-event-polyfill.js.html +121 -0
  32. package/coverage/lcov-report/src/polyfills/index.html +116 -0
  33. package/coverage/lcov-report/src/types/api-version.ts.html +91 -0
  34. package/coverage/lcov-report/src/types/index.html +116 -0
  35. package/coverage/lcov-report/src/url.ts.html +253 -0
  36. package/coverage/lcov.info +4317 -0
  37. package/dist/index.browser.js +2718 -1
  38. package/dist/index.browser.js.map +1 -1
  39. package/dist/index.cjs.js +88 -39
  40. package/dist/index.cjs.js.map +1 -1
  41. package/dist/index.d.ts +1 -0
  42. package/dist/index.esm.js +81 -34
  43. package/dist/index.esm.js.map +1 -1
  44. package/dist/index.js.map +1 -1
  45. package/dist/index.umd.js +101 -49
  46. package/dist/index.umd.js.map +1 -1
  47. package/dist/package.json +17 -15
  48. package/dist/src/builder.class.d.ts +16 -10
  49. package/dist/src/builder.class.js +58 -8
  50. package/dist/src/builder.class.js.map +1 -1
  51. package/dist/src/builder.class.test.d.ts +1 -0
  52. package/dist/src/builder.class.test.js +23 -0
  53. package/dist/src/builder.class.test.js.map +1 -0
  54. package/dist/src/classes/cookies.class.d.ts +1 -1
  55. package/dist/src/classes/observable.class.d.ts +1 -1
  56. package/dist/src/classes/query-string.class.d.ts +1 -1
  57. package/dist/src/functions/finder.function.d.ts +1 -1
  58. package/dist/src/functions/finder.function.js +1 -1
  59. package/dist/src/functions/next-tick.function.d.ts +2 -1
  60. package/dist/src/functions/server-only-require.function.d.ts +1 -1
  61. package/dist/src/types/api-version.d.ts +2 -0
  62. package/dist/src/types/api-version.js +5 -0
  63. package/dist/src/types/api-version.js.map +1 -0
  64. package/dist/src/types/element.d.ts +2 -2
  65. package/dist/src/url.d.ts +3 -3
  66. package/dist/src/url.test.js +1 -1
  67. package/dist/tsconfig.tsbuildinfo +1 -1
  68. package/jest.config.ts +1 -3
  69. package/package.json +17 -15
package/dist/index.d.ts CHANGED
@@ -3,4 +3,5 @@ export { Builder, BuilderComponent, isBrowser, Input, Component, GetContentOptio
3
3
  export { BehaviorSubject, Subscription } from './src/classes/observable.class';
4
4
  export { BuilderElement } from './src/types/element';
5
5
  export { BuilderContent, BuilderContentVariation } from './src/types/content';
6
+ export { ApiVersion } from './src/types/api-version';
6
7
  export { builder } from './src/constants/builder';
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.34-2";
126
+ var version = "1.1.36-0";
127
127
 
128
128
  var Subscription = /** @class */ (function () {
129
129
  function Subscription(listeners, listener) {
@@ -473,10 +473,6 @@ function getFetch() {
473
473
  }
474
474
 
475
475
  function assign(target) {
476
- var args = [];
477
- for (var _i = 1; _i < arguments.length; _i++) {
478
- args[_i - 1] = arguments[_i];
479
- }
480
476
  var to = Object(target);
481
477
  for (var index = 1; index < arguments.length; index++) {
482
478
  var nextSource = arguments[index];
@@ -917,7 +913,7 @@ function emptyUrl() {
917
913
  }
918
914
  // Replacement for `url.parse` using `URL` global object that works with relative paths.
919
915
  // Assumptions: this function operates in a NodeJS environment.
920
- function parse(url) {
916
+ function parse$1(url) {
921
917
  var out = emptyUrl();
922
918
  var u;
923
919
  var pathOnly = url === '' || url[0] === '/';
@@ -963,6 +959,8 @@ function toError(err) {
963
959
  return new Error(String(err));
964
960
  }
965
961
 
962
+ var DEFAULT_API_VERSION = 'v1';
963
+
966
964
  function datePlusMinutes(minutes) {
967
965
  if (minutes === void 0) { minutes = 30; }
968
966
  return new Date(Date.now() + minutes * 60000);
@@ -1025,12 +1023,12 @@ var urlParser = {
1025
1023
  return out;
1026
1024
  },
1027
1025
  };
1028
- var parse$1 = isReactNative
1026
+ var parse = isReactNative
1029
1027
  ? function () { return emptyUrl(); }
1030
1028
  : typeof window === 'object'
1031
1029
  ? urlParser.parse
1032
- : parse;
1033
- function setCookie(name$$1, value, expires) {
1030
+ : parse$1;
1031
+ function setCookie(name, value, expires) {
1034
1032
  try {
1035
1033
  var expiresString = '';
1036
1034
  // TODO: need to know if secure server side
@@ -1039,7 +1037,7 @@ function setCookie(name$$1, value, expires) {
1039
1037
  }
1040
1038
  var secure = isBrowser ? location.protocol === 'https:' : true;
1041
1039
  document.cookie =
1042
- name$$1 +
1040
+ name +
1043
1041
  '=' +
1044
1042
  (value || '') +
1045
1043
  expiresString +
@@ -1051,10 +1049,10 @@ function setCookie(name$$1, value, expires) {
1051
1049
  console.warn('Could not set cookie', err);
1052
1050
  }
1053
1051
  }
1054
- function getCookie(name$$1) {
1052
+ function getCookie(name) {
1055
1053
  try {
1056
1054
  return (decodeURIComponent(document.cookie.replace(new RegExp('(?:(?:^|.*;)\\s*' +
1057
- encodeURIComponent(name$$1).replace(/[\-\.\+\*]/g, '\\$&') +
1055
+ encodeURIComponent(name).replace(/[\-\.\+\*]/g, '\\$&') +
1058
1056
  '\\s*\\=\\s*([^;]*).*$)|^.*$'), '$1')) || null);
1059
1057
  }
1060
1058
  catch (err) {
@@ -1085,7 +1083,7 @@ function BuilderComponent(info) {
1085
1083
  return Builder.Component(info);
1086
1084
  }
1087
1085
  var Builder = /** @class */ (function () {
1088
- function Builder(apiKey, request, response, forceNewInstance, authToken) {
1086
+ function Builder(apiKey, request, response, forceNewInstance, authToken, apiVersion) {
1089
1087
  if (apiKey === void 0) { apiKey = null; }
1090
1088
  if (forceNewInstance === void 0) { forceNewInstance = false; }
1091
1089
  if (authToken === void 0) { authToken = null; }
@@ -1110,6 +1108,7 @@ var Builder = /** @class */ (function () {
1110
1108
  this.overrideParams = '';
1111
1109
  this.noCache = false;
1112
1110
  this.preview = false;
1111
+ this.apiVersion$ = new BehaviorSubject(undefined);
1113
1112
  this.canTrack$ = new BehaviorSubject(!this.browserTrackingDisabled);
1114
1113
  this.apiKey$ = new BehaviorSubject(null);
1115
1114
  this.authToken$ = new BehaviorSubject(null);
@@ -1149,6 +1148,9 @@ var Builder = /** @class */ (function () {
1149
1148
  if (apiKey) {
1150
1149
  this.apiKey = apiKey;
1151
1150
  }
1151
+ if (apiVersion) {
1152
+ this.apiVersion = apiVersion;
1153
+ }
1152
1154
  if (authToken) {
1153
1155
  this.authToken = authToken;
1154
1156
  }
@@ -1260,7 +1262,11 @@ var Builder = /** @class */ (function () {
1260
1262
  this.trustedHosts.push(host);
1261
1263
  };
1262
1264
  Builder.isTrustedHost = function (hostname) {
1263
- return (this.trustedHosts.findIndex(function (trustedHost) { return trustedHost === hostname || hostname.endsWith(".".concat(trustedHost)); }) > -1);
1265
+ return (this.trustedHosts.findIndex(function (trustedHost) {
1266
+ return trustedHost.startsWith('*.')
1267
+ ? hostname.endsWith(trustedHost.slice(1))
1268
+ : trustedHost === hostname;
1269
+ }) > -1);
1264
1270
  };
1265
1271
  Builder.runAction = function (action) {
1266
1272
  // TODO
@@ -1269,11 +1275,11 @@ var Builder = /** @class */ (function () {
1269
1275
  throw new Error("Action not found: ".concat(action));
1270
1276
  }
1271
1277
  };
1272
- Builder.fields = function (name$$1, fields) {
1278
+ Builder.fields = function (name, fields) {
1273
1279
  var _a;
1274
1280
  (_a = window.parent) === null || _a === void 0 ? void 0 : _a.postMessage({
1275
1281
  type: 'builder.fields',
1276
- data: { name: name$$1, fields: fields },
1282
+ data: { name: name, fields: fields },
1277
1283
  }, '*');
1278
1284
  };
1279
1285
  /**
@@ -1457,6 +1463,18 @@ var Builder = /** @class */ (function () {
1457
1463
  enumerable: false,
1458
1464
  configurable: true
1459
1465
  });
1466
+ Object.defineProperty(Builder.prototype, "apiVersion", {
1467
+ get: function () {
1468
+ return this.apiVersion$.value;
1469
+ },
1470
+ set: function (apiVersion) {
1471
+ if (this.apiVersion !== apiVersion) {
1472
+ this.apiVersion$.next(apiVersion);
1473
+ }
1474
+ },
1475
+ enumerable: false,
1476
+ configurable: true
1477
+ });
1460
1478
  Object.defineProperty(Builder.prototype, "editingMode", {
1461
1479
  get: function () {
1462
1480
  return this.editingMode$.value;
@@ -1754,7 +1772,7 @@ var Builder = /** @class */ (function () {
1754
1772
  var params = QueryString.parseDeep(this.modifySearch(location.search || '').substr(1));
1755
1773
  var builder = params.builder;
1756
1774
  if (builder) {
1757
- var userAttributes = builder.userAttributes, overrides = builder.overrides, env = builder.env, host = builder.host, api = builder.api, cachebust = builder.cachebust, noCache = builder.noCache, preview = builder.preview, editing = builder.editing, frameEditing = builder.frameEditing, options = builder.options, overrideParams = builder.params;
1775
+ var userAttributes = builder.userAttributes, overrides = builder.overrides, env = builder.env; builder.host; var api = builder.api, cachebust = builder.cachebust, noCache = builder.noCache, preview = builder.preview, editing = builder.editing, frameEditing = builder.frameEditing, options = builder.options, overrideParams = builder.params;
1758
1776
  if (userAttributes) {
1759
1777
  this.setUserAttributes(userAttributes);
1760
1778
  }
@@ -1802,7 +1820,7 @@ var Builder = /** @class */ (function () {
1802
1820
  if (isBrowser) {
1803
1821
  addEventListener('message', function (event) {
1804
1822
  var _a, _b, _c, _d, _e;
1805
- var url = parse$1(event.origin);
1823
+ var url = parse(event.origin);
1806
1824
  var isRestricted = ['builder.register', 'builder.registerComponent'].indexOf((_a = event.data) === null || _a === void 0 ? void 0 : _a.type) === -1;
1807
1825
  var isTrusted = url.hostname && Builder.isTrustedHost(url.hostname);
1808
1826
  if (isRestricted && !isTrusted) {
@@ -1988,7 +2006,7 @@ var Builder = /** @class */ (function () {
1988
2006
  enumerable: false,
1989
2007
  configurable: true
1990
2008
  });
1991
- Builder.prototype.init = function (apiKey, canTrack, req, res, authToken) {
2009
+ Builder.prototype.init = function (apiKey, canTrack, req, res, authToken, apiVersion) {
1992
2010
  if (canTrack === void 0) { canTrack = this.defaultCanTrack; }
1993
2011
  if (req) {
1994
2012
  this.request = req;
@@ -2001,6 +2019,9 @@ var Builder = /** @class */ (function () {
2001
2019
  if (authToken) {
2002
2020
  this.authToken = authToken;
2003
2021
  }
2022
+ if (apiVersion) {
2023
+ this.apiVersion = apiVersion;
2024
+ }
2004
2025
  return this;
2005
2026
  };
2006
2027
  Object.defineProperty(Builder.prototype, "previewingModel", {
@@ -2018,11 +2039,11 @@ var Builder = /** @class */ (function () {
2018
2039
  var parsedLocation = {};
2019
2040
  // in ssr mode
2020
2041
  if (this.request) {
2021
- parsedLocation = parse$1((_a = this.request.url) !== null && _a !== void 0 ? _a : '');
2042
+ parsedLocation = parse((_a = this.request.url) !== null && _a !== void 0 ? _a : '');
2022
2043
  }
2023
2044
  else if (typeof location === 'object') {
2024
2045
  // in the browser
2025
- parsedLocation = parse$1(location.href);
2046
+ parsedLocation = parse(location.href);
2026
2047
  }
2027
2048
  // IE11 bug with parsed path being empty string
2028
2049
  // causes issues with our user targeting
@@ -2083,16 +2104,21 @@ var Builder = /** @class */ (function () {
2083
2104
  if (options === void 0) { options = {}; }
2084
2105
  var instance = this;
2085
2106
  if (!Builder.isBrowser) {
2086
- instance = new Builder(options.apiKey || this.apiKey, options.req, options.res, undefined, options.authToken || this.authToken);
2107
+ instance = new Builder(options.apiKey || this.apiKey, options.req, options.res, undefined, options.authToken || this.authToken, options.apiVersion || this.apiVersion);
2087
2108
  instance.setUserAttributes(this.getUserAttributes());
2088
2109
  }
2089
2110
  else {
2111
+ // NOTE: All these are when .init is not called and the customer
2112
+ // directly calls .get on the singleton instance of Builder
2090
2113
  if (options.apiKey && !this.apiKey) {
2091
2114
  this.apiKey = options.apiKey;
2092
2115
  }
2093
2116
  if (options.authToken && !this.authToken) {
2094
2117
  this.authToken = options.authToken;
2095
2118
  }
2119
+ if (options.apiVersion && !this.apiVersion) {
2120
+ this.apiVersion = options.apiVersion;
2121
+ }
2096
2122
  }
2097
2123
  return instance.queueGetContent(modelName, options).map(
2098
2124
  /* map( */ function (matches) {
@@ -2233,6 +2259,14 @@ var Builder = /** @class */ (function () {
2233
2259
  if (!this.apiKey) {
2234
2260
  throw new Error("Fetching content failed, expected apiKey to be defined instead got: ".concat(this.apiKey));
2235
2261
  }
2262
+ if (this.apiVersion) {
2263
+ if (!['v1', 'v3'].includes(this.apiVersion)) {
2264
+ throw new Error("Invalid apiVersion: expected 'v1' or 'v3', received '".concat(this.apiVersion, "'"));
2265
+ }
2266
+ }
2267
+ else {
2268
+ this.apiVersion = DEFAULT_API_VERSION;
2269
+ }
2236
2270
  if (!usePastQueue && !this.getContentQueue) {
2237
2271
  return;
2238
2272
  }
@@ -2250,7 +2284,7 @@ var Builder = /** @class */ (function () {
2250
2284
  }
2251
2285
  var pageQueryParams = typeof location !== 'undefined'
2252
2286
  ? QueryString.parseDeep(location.search.substr(1))
2253
- : undefined || {};
2287
+ : {};
2254
2288
  var userAttributes =
2255
2289
  // FIXME: HACK: only checks first in queue for user attributes overrides, should check all
2256
2290
  // TODO: merge user attributes provided here with defaults and current user attiributes (?)
@@ -2362,7 +2396,9 @@ var Builder = /** @class */ (function () {
2362
2396
  requestOptions.headers = __assign(__assign({}, requestOptions.headers), { Authorization: "Bearer ".concat(this.authToken) });
2363
2397
  }
2364
2398
  var fn = format === 'solid' || format === 'react' ? 'codegen' : 'query';
2365
- var url = "".concat(host, "/api/v1/").concat(fn, "/").concat(this.apiKey, "/").concat(keyNames) +
2399
+ // NOTE: this is a hack to get around the fact that the codegen endpoint is not yet available in v3
2400
+ var apiVersionBasedOnFn = fn === 'query' ? this.apiVersion : 'v1';
2401
+ var url = "".concat(host, "/api/").concat(apiVersionBasedOnFn, "/").concat(fn, "/").concat(this.apiKey, "/").concat(keyNames) +
2366
2402
  (queryParams && hasParams ? "?".concat(queryStr) : '');
2367
2403
  var promise = getFetch()(url, requestOptions)
2368
2404
  .then(function (res) { return res.json(); })
@@ -2466,20 +2502,20 @@ var Builder = /** @class */ (function () {
2466
2502
  future.setDate(future.getDate() + 30);
2467
2503
  return this.setCookie("".concat(this.testCookiePrefix, ".").concat(contentId), variationId, future);
2468
2504
  };
2469
- Builder.prototype.getCookie = function (name$$1) {
2505
+ Builder.prototype.getCookie = function (name) {
2470
2506
  if (this.cookies) {
2471
- return this.cookies.get(name$$1);
2507
+ return this.cookies.get(name);
2472
2508
  }
2473
- return Builder.isBrowser && getCookie(name$$1);
2509
+ return Builder.isBrowser && getCookie(name);
2474
2510
  };
2475
- Builder.prototype.setCookie = function (name$$1, value, expires) {
2511
+ Builder.prototype.setCookie = function (name, value, expires) {
2476
2512
  if (this.cookies && !(Builder.isServer && Builder.isStatic)) {
2477
- return this.cookies.set(name$$1, value, {
2513
+ return this.cookies.set(name, value, {
2478
2514
  expires: expires,
2479
2515
  secure: this.getLocation().protocol === 'https:',
2480
2516
  });
2481
2517
  }
2482
- return Builder.isBrowser && setCookie(name$$1, value, expires);
2518
+ return Builder.isBrowser && setCookie(name, value, expires);
2483
2519
  };
2484
2520
  Builder.prototype.getContent = function (modelName, options) {
2485
2521
  if (options === void 0) { options = {}; }
@@ -2492,17 +2528,22 @@ var Builder = /** @class */ (function () {
2492
2528
  if (options === void 0) { options = {}; }
2493
2529
  var instance = this;
2494
2530
  if (!Builder.isBrowser) {
2495
- instance = new Builder(options.apiKey || this.apiKey, options.req, options.res);
2531
+ instance = new Builder(options.apiKey || this.apiKey, options.req, options.res, false, null, options.apiVersion);
2496
2532
  instance.setUserAttributes(this.getUserAttributes());
2497
2533
  }
2498
2534
  else {
2535
+ // NOTE: All these are when .init is not called and the customer
2536
+ // directly calls .get on the singleton instance of Builder
2499
2537
  if (options.apiKey && !this.apiKey) {
2500
2538
  this.apiKey = options.apiKey;
2501
2539
  }
2540
+ if (options.apiVersion && !this.apiVersion) {
2541
+ this.apiVersion = options.apiVersion;
2542
+ }
2502
2543
  }
2503
2544
  return instance
2504
2545
  .getContent(modelName, __assign(__assign({ limit: 30 }, options), { key: options.key ||
2505
- // Make the key include all options so we don't reuse cache for the same conent fetched
2546
+ // Make the key include all options, so we don't reuse cache for the same content fetched
2506
2547
  // with different options
2507
2548
  Builder.isBrowser
2508
2549
  ? "".concat(modelName, ":").concat(hash(omit(options, 'initialContent', 'req', 'res')))
@@ -2527,7 +2568,13 @@ var Builder = /** @class */ (function () {
2527
2568
  Builder.nextTick = nextTick;
2528
2569
  Builder.throttle = throttle;
2529
2570
  Builder.editors = [];
2530
- Builder.trustedHosts = ['builder.io', 'localhost'];
2571
+ Builder.trustedHosts = [
2572
+ '*.beta.builder.io',
2573
+ 'beta.builder.io',
2574
+ 'builder.io',
2575
+ 'localhost',
2576
+ 'qa.builder.io',
2577
+ ];
2531
2578
  Builder.plugins = [];
2532
2579
  Builder.actions = [];
2533
2580
  Builder.registry = {};
@@ -2557,5 +2604,5 @@ var Builder = /** @class */ (function () {
2557
2604
  var builder = new Builder(null, undefined, undefined, true);
2558
2605
  Builder.singletonInstance = builder;
2559
2606
 
2560
- export { Builder, BuilderComponent, isBrowser, BehaviorSubject, Subscription, builder };
2607
+ export { BehaviorSubject, Builder, BuilderComponent, Subscription, builder, isBrowser };
2561
2608
  //# sourceMappingURL=index.esm.js.map