@builder.io/sdk 1.1.34 → 1.1.35

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 (43) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/dist/index.browser.js +1 -1
  3. package/dist/index.browser.js.map +1 -1
  4. package/dist/index.cjs.js +85 -24
  5. package/dist/index.cjs.js.map +1 -1
  6. package/dist/index.d.ts +7 -6
  7. package/dist/index.esm.js +85 -24
  8. package/dist/index.esm.js.map +1 -1
  9. package/dist/index.js.map +1 -1
  10. package/dist/index.umd.js +96 -35
  11. package/dist/index.umd.js.map +1 -1
  12. package/dist/package.json +16 -14
  13. package/dist/src/builder.class.d.ts +842 -837
  14. package/dist/src/builder.class.js +46 -6
  15. package/dist/src/builder.class.js.map +1 -1
  16. package/dist/src/classes/animator.class.d.ts +26 -26
  17. package/dist/src/classes/cookies.class.d.ts +15 -15
  18. package/dist/src/classes/observable.class.d.ts +26 -26
  19. package/dist/src/classes/promise.class.d.ts +17 -17
  20. package/dist/src/classes/query-string.class.d.ts +9 -9
  21. package/dist/src/classes/query-string.class.test.d.ts +1 -1
  22. package/dist/src/constants/builder.d.ts +2 -2
  23. package/dist/src/functions/assign.function.d.ts +1 -1
  24. package/dist/src/functions/fetch.function.d.ts +28 -28
  25. package/dist/src/functions/finder.function.d.ts +10 -10
  26. package/dist/src/functions/finder.function.js +1 -1
  27. package/dist/src/functions/get-top-level-domain.d.ts +6 -6
  28. package/dist/src/functions/next-tick.function.d.ts +1 -1
  29. package/dist/src/functions/omit.function.d.ts +1 -1
  30. package/dist/src/functions/server-only-require.function.d.ts +3 -3
  31. package/dist/src/functions/throttle.function.d.ts +1 -1
  32. package/dist/src/functions/to-error.d.ts +13 -13
  33. package/dist/src/functions/uuid.d.ts +8 -8
  34. package/dist/src/types/api-version.d.ts +2 -0
  35. package/dist/src/types/api-version.js +5 -0
  36. package/dist/src/types/api-version.js.map +1 -0
  37. package/dist/src/types/content.d.ts +31 -31
  38. package/dist/src/types/element.d.ts +60 -60
  39. package/dist/src/url.d.ts +9 -9
  40. package/dist/src/url.test.d.ts +1 -1
  41. package/dist/src/url.test.js +1 -1
  42. package/dist/tsconfig.tsbuildinfo +1 -1
  43. package/package.json +17 -15
package/dist/index.cjs.js CHANGED
@@ -48,7 +48,8 @@ function nextTick(fn) {
48
48
  });
49
49
  // tslint:disable-next-line
50
50
  element.data = String((called = ++called));
51
- }
51
+ }
52
+ //# sourceMappingURL=next-tick.function.js.map
52
53
 
53
54
  var PROPERTY_NAME_DENY_LIST = Object.freeze(['__proto__', 'prototype', 'constructor']);
54
55
  // TODO: unit tests
@@ -127,9 +128,10 @@ var QueryString = /** @class */ (function () {
127
128
  function assertAllowedPropertyName(name) {
128
129
  if (PROPERTY_NAME_DENY_LIST.indexOf(name) >= 0)
129
130
  throw new Error("Property name \"".concat(name, "\" is not allowed"));
130
- }
131
+ }
132
+ //# sourceMappingURL=query-string.class.js.map
131
133
 
132
- var version = "1.1.34-2";
134
+ var version = "1.1.35";
133
135
 
134
136
  var Subscription = /** @class */ (function () {
135
137
  function Subscription(listeners, listener) {
@@ -222,7 +224,8 @@ var BehaviorSubject = /** @class */ (function () {
222
224
  return this.toPromise();
223
225
  };
224
226
  return BehaviorSubject;
225
- }());
227
+ }());
228
+ //# sourceMappingURL=observable.class.js.map
226
229
 
227
230
  var State = {
228
231
  Pending: 'Pending',
@@ -387,7 +390,8 @@ var TinyPromise = /** @class */ (function () {
387
390
  };
388
391
  return TinyPromise;
389
392
  }());
390
- var Promise$1 = (typeof Promise !== 'undefined' ? Promise : TinyPromise);
393
+ var Promise$1 = (typeof Promise !== 'undefined' ? Promise : TinyPromise);
394
+ //# sourceMappingURL=promise.class.js.map
391
395
 
392
396
  // Webpack workaround to conditionally require certain external modules
393
397
  // only on the server and not bundle them on the client
@@ -400,7 +404,8 @@ catch (err) {
400
404
  // all good
401
405
  serverOnlyRequire = (function () { return null; });
402
406
  }
403
- var serverOnlyRequire$1 = serverOnlyRequire;
407
+ var serverOnlyRequire$1 = serverOnlyRequire;
408
+ //# sourceMappingURL=server-only-require.function.js.map
404
409
 
405
410
  function promiseResolve(value) {
406
411
  return new Promise$1(function (resolve) { return resolve(value); });
@@ -476,7 +481,8 @@ function getFetch() {
476
481
  }
477
482
  // Otherwise, use tiny-fetch.
478
483
  return _fetch !== null && _fetch !== void 0 ? _fetch : tinyFetch;
479
- }
484
+ }
485
+ //# sourceMappingURL=fetch.function.js.map
480
486
 
481
487
  function assign(target) {
482
488
  var args = [];
@@ -497,7 +503,8 @@ function assign(target) {
497
503
  }
498
504
  }
499
505
  return to;
500
- }
506
+ }
507
+ //# sourceMappingURL=assign.function.js.map
501
508
 
502
509
  function throttle(func, wait, options) {
503
510
  if (options === void 0) { options = {}; }
@@ -535,7 +542,8 @@ function throttle(func, wait, options) {
535
542
  }
536
543
  return result;
537
544
  };
538
- }
545
+ }
546
+ //# sourceMappingURL=throttle.function.js.map
539
547
 
540
548
  var camelCaseToKebabCase = function (str) {
541
549
  return str ? str.replace(/([A-Z])/g, function (g) { return "-".concat(g[0].toLowerCase()); }) : '';
@@ -737,7 +745,8 @@ var Animator = /** @class */ (function () {
737
745
  });
738
746
  };
739
747
  return Animator;
740
- }());
748
+ }());
749
+ //# sourceMappingURL=animator.class.js.map
741
750
 
742
751
  /**
743
752
  * Only gets one level up from hostname
@@ -750,7 +759,8 @@ function getTopLevelDomain(host) {
750
759
  return parts.slice(1).join('.');
751
760
  }
752
761
  return host;
753
- }
762
+ }
763
+ //# sourceMappingURL=get-top-level-domain.js.map
754
764
 
755
765
  /**
756
766
  * RegExp to match field-content in RFC 7230 sec 3.2
@@ -874,7 +884,8 @@ function pushCookie(headers, cookie) {
874
884
  }
875
885
  }
876
886
  headers.push(cookie.toHeader());
877
- }
887
+ }
888
+ //# sourceMappingURL=cookies.class.js.map
878
889
 
879
890
  function omit(obj) {
880
891
  var values = [];
@@ -887,7 +898,8 @@ function omit(obj) {
887
898
  delete newObject[key];
888
899
  }
889
900
  return newObject;
890
- }
901
+ }
902
+ //# sourceMappingURL=omit.function.js.map
891
903
 
892
904
  /**
893
905
  * @credit https://stackoverflow.com/a/2117523
@@ -903,7 +915,8 @@ function uuidv4() {
903
915
  */
904
916
  function uuid() {
905
917
  return uuidv4().replace(/-/g, '');
906
- }
918
+ }
919
+ //# sourceMappingURL=uuid.js.map
907
920
 
908
921
  function emptyUrl() {
909
922
  return {
@@ -949,7 +962,8 @@ function parse(url) {
949
962
  out.path = "".concat(u.pathname).concat(u.search);
950
963
  out.pathname = u.pathname;
951
964
  return out;
952
- }
965
+ }
966
+ //# sourceMappingURL=url.js.map
953
967
 
954
968
  /**
955
969
  * Safe conversion to error type. Intended to be used in catch blocks where the
@@ -967,7 +981,11 @@ function toError(err) {
967
981
  if (err instanceof Error)
968
982
  return err;
969
983
  return new Error(String(err));
970
- }
984
+ }
985
+ //# sourceMappingURL=to-error.js.map
986
+
987
+ var DEFAULT_API_VERSION = 'v1';
988
+ //# sourceMappingURL=api-version.js.map
971
989
 
972
990
  function datePlusMinutes(minutes) {
973
991
  if (minutes === void 0) { minutes = 30; }
@@ -1091,7 +1109,7 @@ function BuilderComponent(info) {
1091
1109
  return Builder.Component(info);
1092
1110
  }
1093
1111
  var Builder = /** @class */ (function () {
1094
- function Builder(apiKey, request, response, forceNewInstance, authToken) {
1112
+ function Builder(apiKey, request, response, forceNewInstance, authToken, apiVersion) {
1095
1113
  if (apiKey === void 0) { apiKey = null; }
1096
1114
  if (forceNewInstance === void 0) { forceNewInstance = false; }
1097
1115
  if (authToken === void 0) { authToken = null; }
@@ -1116,6 +1134,7 @@ var Builder = /** @class */ (function () {
1116
1134
  this.overrideParams = '';
1117
1135
  this.noCache = false;
1118
1136
  this.preview = false;
1137
+ this.apiVersion$ = new BehaviorSubject(undefined);
1119
1138
  this.canTrack$ = new BehaviorSubject(!this.browserTrackingDisabled);
1120
1139
  this.apiKey$ = new BehaviorSubject(null);
1121
1140
  this.authToken$ = new BehaviorSubject(null);
@@ -1155,6 +1174,9 @@ var Builder = /** @class */ (function () {
1155
1174
  if (apiKey) {
1156
1175
  this.apiKey = apiKey;
1157
1176
  }
1177
+ if (apiVersion) {
1178
+ this.apiVersion = apiVersion;
1179
+ }
1158
1180
  if (authToken) {
1159
1181
  this.authToken = authToken;
1160
1182
  }
@@ -1463,6 +1485,18 @@ var Builder = /** @class */ (function () {
1463
1485
  enumerable: false,
1464
1486
  configurable: true
1465
1487
  });
1488
+ Object.defineProperty(Builder.prototype, "apiVersion", {
1489
+ get: function () {
1490
+ return this.apiVersion$.value;
1491
+ },
1492
+ set: function (apiVersion) {
1493
+ if (this.apiVersion !== apiVersion) {
1494
+ this.apiVersion$.next(apiVersion);
1495
+ }
1496
+ },
1497
+ enumerable: false,
1498
+ configurable: true
1499
+ });
1466
1500
  Object.defineProperty(Builder.prototype, "editingMode", {
1467
1501
  get: function () {
1468
1502
  return this.editingMode$.value;
@@ -1994,7 +2028,7 @@ var Builder = /** @class */ (function () {
1994
2028
  enumerable: false,
1995
2029
  configurable: true
1996
2030
  });
1997
- Builder.prototype.init = function (apiKey, canTrack, req, res, authToken) {
2031
+ Builder.prototype.init = function (apiKey, canTrack, req, res, authToken, apiVersion) {
1998
2032
  if (canTrack === void 0) { canTrack = this.defaultCanTrack; }
1999
2033
  if (req) {
2000
2034
  this.request = req;
@@ -2007,6 +2041,9 @@ var Builder = /** @class */ (function () {
2007
2041
  if (authToken) {
2008
2042
  this.authToken = authToken;
2009
2043
  }
2044
+ if (apiVersion) {
2045
+ this.apiVersion = apiVersion;
2046
+ }
2010
2047
  return this;
2011
2048
  };
2012
2049
  Object.defineProperty(Builder.prototype, "previewingModel", {
@@ -2089,16 +2126,21 @@ var Builder = /** @class */ (function () {
2089
2126
  if (options === void 0) { options = {}; }
2090
2127
  var instance = this;
2091
2128
  if (!Builder.isBrowser) {
2092
- instance = new Builder(options.apiKey || this.apiKey, options.req, options.res, undefined, options.authToken || this.authToken);
2129
+ instance = new Builder(options.apiKey || this.apiKey, options.req, options.res, undefined, options.authToken || this.authToken, options.apiVersion || this.apiVersion);
2093
2130
  instance.setUserAttributes(this.getUserAttributes());
2094
2131
  }
2095
2132
  else {
2133
+ // NOTE: All these are when .init is not called and the customer
2134
+ // directly calls .get on the singleton instance of Builder
2096
2135
  if (options.apiKey && !this.apiKey) {
2097
2136
  this.apiKey = options.apiKey;
2098
2137
  }
2099
2138
  if (options.authToken && !this.authToken) {
2100
2139
  this.authToken = options.authToken;
2101
2140
  }
2141
+ if (options.apiVersion && !this.apiVersion) {
2142
+ this.apiVersion = options.apiVersion;
2143
+ }
2102
2144
  }
2103
2145
  return instance.queueGetContent(modelName, options).map(
2104
2146
  /* map( */ function (matches) {
@@ -2239,6 +2281,14 @@ var Builder = /** @class */ (function () {
2239
2281
  if (!this.apiKey) {
2240
2282
  throw new Error("Fetching content failed, expected apiKey to be defined instead got: ".concat(this.apiKey));
2241
2283
  }
2284
+ if (this.apiVersion) {
2285
+ if (!['v1', 'v3'].includes(this.apiVersion)) {
2286
+ throw new Error("Invalid apiVersion: expected 'v1' or 'v3', received '".concat(this.apiVersion, "'"));
2287
+ }
2288
+ }
2289
+ else {
2290
+ this.apiVersion = DEFAULT_API_VERSION;
2291
+ }
2242
2292
  if (!usePastQueue && !this.getContentQueue) {
2243
2293
  return;
2244
2294
  }
@@ -2368,7 +2418,9 @@ var Builder = /** @class */ (function () {
2368
2418
  requestOptions.headers = tslib.__assign(tslib.__assign({}, requestOptions.headers), { Authorization: "Bearer ".concat(this.authToken) });
2369
2419
  }
2370
2420
  var fn = format === 'solid' || format === 'react' ? 'codegen' : 'query';
2371
- var url = "".concat(host, "/api/v1/").concat(fn, "/").concat(this.apiKey, "/").concat(keyNames) +
2421
+ // NOTE: this is a hack to get around the fact that the codegen endpoint is not yet available in v3
2422
+ var apiVersionBasedOnFn = fn === 'query' ? this.apiVersion : 'v1';
2423
+ var url = "".concat(host, "/api/").concat(apiVersionBasedOnFn, "/").concat(fn, "/").concat(this.apiKey, "/").concat(keyNames) +
2372
2424
  (queryParams && hasParams ? "?".concat(queryStr) : '');
2373
2425
  var promise = getFetch()(url, requestOptions)
2374
2426
  .then(function (res) { return res.json(); })
@@ -2498,17 +2550,22 @@ var Builder = /** @class */ (function () {
2498
2550
  if (options === void 0) { options = {}; }
2499
2551
  var instance = this;
2500
2552
  if (!Builder.isBrowser) {
2501
- instance = new Builder(options.apiKey || this.apiKey, options.req, options.res);
2553
+ instance = new Builder(options.apiKey || this.apiKey, options.req, options.res, false, null, options.apiVersion);
2502
2554
  instance.setUserAttributes(this.getUserAttributes());
2503
2555
  }
2504
2556
  else {
2557
+ // NOTE: All these are when .init is not called and the customer
2558
+ // directly calls .get on the singleton instance of Builder
2505
2559
  if (options.apiKey && !this.apiKey) {
2506
2560
  this.apiKey = options.apiKey;
2507
2561
  }
2562
+ if (options.apiVersion && !this.apiVersion) {
2563
+ this.apiVersion = options.apiVersion;
2564
+ }
2508
2565
  }
2509
2566
  return instance
2510
2567
  .getContent(modelName, tslib.__assign(tslib.__assign({ limit: 30 }, options), { key: options.key ||
2511
- // Make the key include all options so we don't reuse cache for the same conent fetched
2568
+ // Make the key include all options, so we don't reuse cache for the same content fetched
2512
2569
  // with different options
2513
2570
  Builder.isBrowser
2514
2571
  ? "".concat(modelName, ":").concat(hash(omit(options, 'initialContent', 'req', 'res')))
@@ -2558,10 +2615,14 @@ var Builder = /** @class */ (function () {
2558
2615
  Builder.isReact = false;
2559
2616
  Builder.overrideUserAttributes = {};
2560
2617
  return Builder;
2561
- }());
2618
+ }());
2619
+ //# sourceMappingURL=builder.class.js.map
2562
2620
 
2563
2621
  var builder = new Builder(null, undefined, undefined, true);
2564
- Builder.singletonInstance = builder;
2622
+ Builder.singletonInstance = builder;
2623
+ //# sourceMappingURL=builder.js.map
2624
+
2625
+ //# sourceMappingURL=index.js.map
2565
2626
 
2566
2627
  exports.Builder = Builder;
2567
2628
  exports.BuilderComponent = BuilderComponent;