@builder.io/sdk 5.0.0 → 6.0.1
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.
- package/CHANGELOG.md +20 -0
- package/dist/index.browser.js +41 -11
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs.js +41 -11
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +41 -11
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +41 -11
- package/dist/index.umd.js.map +1 -1
- package/dist/package.json +1 -1
- package/dist/src/builder.class.d.ts +10 -5
- package/dist/src/builder.class.js +40 -10
- package/dist/src/builder.class.js.map +1 -1
- package/dist/src/builder.class.test.js +289 -8
- package/dist/src/builder.class.test.js.map +1 -1
- package/dist/src/sdk-version.d.ts +1 -1
- package/dist/src/sdk-version.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -958,7 +958,7 @@ function toError(err) {
|
|
|
958
958
|
|
|
959
959
|
var DEFAULT_API_VERSION = 'v3';
|
|
960
960
|
|
|
961
|
-
var SDK_VERSION = '
|
|
961
|
+
var SDK_VERSION = '6.0.1';
|
|
962
962
|
|
|
963
963
|
function datePlusMinutes(minutes) {
|
|
964
964
|
if (minutes === void 0) { minutes = 30; }
|
|
@@ -1106,6 +1106,11 @@ var Builder = /** @class */ (function () {
|
|
|
1106
1106
|
this.overrideParams = '';
|
|
1107
1107
|
this.noCache = false;
|
|
1108
1108
|
this.preview = false;
|
|
1109
|
+
/**
|
|
1110
|
+
* Dictates which API endpoint is used when fetching content. Allows `'content'` and `'query'`.
|
|
1111
|
+
* Defaults to `'query'`.
|
|
1112
|
+
*/
|
|
1113
|
+
this.apiEndpoint$ = new BehaviorSubject('query');
|
|
1109
1114
|
this.apiVersion$ = new BehaviorSubject(undefined);
|
|
1110
1115
|
this.canTrack$ = new BehaviorSubject(!this.browserTrackingDisabled);
|
|
1111
1116
|
this.apiKey$ = new BehaviorSubject(null);
|
|
@@ -1359,8 +1364,14 @@ var Builder = /** @class */ (function () {
|
|
|
1359
1364
|
// 2. `name(args) => {code}`
|
|
1360
1365
|
// 3. `(args) => {}`
|
|
1361
1366
|
// 4. `args => {}`
|
|
1367
|
+
// 5. `async function(args) {code}`
|
|
1368
|
+
// 6. `async (args) => {}`
|
|
1369
|
+
// 7. `async args => {}`
|
|
1362
1370
|
var isArrowWithoutParens = /^[a-zA-Z0-9_]+\s*=>/i.test(fnStr);
|
|
1363
|
-
var appendFunction = !fnStr.startsWith('function') &&
|
|
1371
|
+
var appendFunction = !fnStr.startsWith('function') &&
|
|
1372
|
+
!fnStr.startsWith('async') &&
|
|
1373
|
+
!fnStr.startsWith('(') &&
|
|
1374
|
+
!isArrowWithoutParens;
|
|
1364
1375
|
return "return (".concat(appendFunction ? 'function ' : '').concat(fnStr, ").apply(this, arguments)");
|
|
1365
1376
|
};
|
|
1366
1377
|
return JSON.parse(JSON.stringify(info, function (key, value) {
|
|
@@ -1492,6 +1503,18 @@ var Builder = /** @class */ (function () {
|
|
|
1492
1503
|
enumerable: false,
|
|
1493
1504
|
configurable: true
|
|
1494
1505
|
});
|
|
1506
|
+
Object.defineProperty(Builder.prototype, "apiEndpoint", {
|
|
1507
|
+
get: function () {
|
|
1508
|
+
return this.apiEndpoint$.value;
|
|
1509
|
+
},
|
|
1510
|
+
set: function (apiEndpoint) {
|
|
1511
|
+
if (this.apiEndpoint !== apiEndpoint) {
|
|
1512
|
+
this.apiEndpoint$.next(apiEndpoint);
|
|
1513
|
+
}
|
|
1514
|
+
},
|
|
1515
|
+
enumerable: false,
|
|
1516
|
+
configurable: true
|
|
1517
|
+
});
|
|
1495
1518
|
Object.defineProperty(Builder.prototype, "editingMode", {
|
|
1496
1519
|
get: function () {
|
|
1497
1520
|
return this.editingMode$.value;
|
|
@@ -2130,12 +2153,16 @@ var Builder = /** @class */ (function () {
|
|
|
2130
2153
|
if (options === void 0) { options = {}; }
|
|
2131
2154
|
var instance = this;
|
|
2132
2155
|
var finalLocale = options.locale || ((_a = options.userAttributes) === null || _a === void 0 ? void 0 : _a.locale) || this.getUserAttributes().locale;
|
|
2156
|
+
if (!('noTraverse' in options)) {
|
|
2157
|
+
options.noTraverse = false;
|
|
2158
|
+
}
|
|
2133
2159
|
var finalOptions = tslib.__assign(tslib.__assign({}, options), (finalLocale && {
|
|
2134
2160
|
locale: String(finalLocale),
|
|
2135
2161
|
userAttributes: tslib.__assign({ locale: String(finalLocale) }, options.userAttributes),
|
|
2136
2162
|
}));
|
|
2137
2163
|
if (!Builder.isBrowser) {
|
|
2138
2164
|
instance = new Builder(options.apiKey || this.apiKey, options.req, options.res, undefined, options.authToken || this.authToken, options.apiVersion || this.apiVersion);
|
|
2165
|
+
instance.apiEndpoint = this.apiEndpoint;
|
|
2139
2166
|
instance.setUserAttributes(this.getUserAttributes());
|
|
2140
2167
|
}
|
|
2141
2168
|
else {
|
|
@@ -2319,6 +2346,7 @@ var Builder = /** @class */ (function () {
|
|
|
2319
2346
|
};
|
|
2320
2347
|
Builder.prototype.flushGetContentQueue = function (usePastQueue, useQueue) {
|
|
2321
2348
|
var _this = this;
|
|
2349
|
+
var _a;
|
|
2322
2350
|
if (usePastQueue === void 0) { usePastQueue = false; }
|
|
2323
2351
|
if (!this.apiKey) {
|
|
2324
2352
|
throw new Error("Fetching content failed, expected apiKey to be defined instead got: ".concat(this.apiKey));
|
|
@@ -2335,7 +2363,6 @@ var Builder = /** @class */ (function () {
|
|
|
2335
2363
|
return;
|
|
2336
2364
|
}
|
|
2337
2365
|
var queue = useQueue || (usePastQueue ? this.priorContentQueue : this.getContentQueue) || [];
|
|
2338
|
-
var apiEndpoint = queue[0].apiEndpoint || 'query';
|
|
2339
2366
|
// TODO: do this on every request send?
|
|
2340
2367
|
this.getOverridesFromQueryString();
|
|
2341
2368
|
var queryParams = tslib.__assign(tslib.__assign({
|
|
@@ -2429,6 +2456,9 @@ var Builder = /** @class */ (function () {
|
|
|
2429
2456
|
if (isPositiveNumber(options.staleCacheSeconds)) {
|
|
2430
2457
|
queryParams.staleCacheSeconds = options.staleCacheSeconds;
|
|
2431
2458
|
}
|
|
2459
|
+
if (this.apiEndpoint === 'content') {
|
|
2460
|
+
queryParams.includeRefs = true;
|
|
2461
|
+
}
|
|
2432
2462
|
var properties = [
|
|
2433
2463
|
'prerender',
|
|
2434
2464
|
'extractCss',
|
|
@@ -2440,12 +2470,13 @@ var Builder = /** @class */ (function () {
|
|
|
2440
2470
|
'entry',
|
|
2441
2471
|
'rev',
|
|
2442
2472
|
'static',
|
|
2473
|
+
'includeRefs',
|
|
2443
2474
|
];
|
|
2444
|
-
for (var
|
|
2445
|
-
var key = properties_1[
|
|
2475
|
+
for (var _b = 0, properties_1 = properties; _b < properties_1.length; _b++) {
|
|
2476
|
+
var key = properties_1[_b];
|
|
2446
2477
|
var value = options[key];
|
|
2447
2478
|
if (value !== undefined) {
|
|
2448
|
-
if (apiEndpoint === 'query') {
|
|
2479
|
+
if (this.apiEndpoint === 'query') {
|
|
2449
2480
|
queryParams.options = queryParams.options || {};
|
|
2450
2481
|
queryParams.options[options.key] = queryParams.options[options.key] || {};
|
|
2451
2482
|
queryParams.options[options.key][key] = JSON.stringify(value);
|
|
@@ -2456,7 +2487,7 @@ var Builder = /** @class */ (function () {
|
|
|
2456
2487
|
}
|
|
2457
2488
|
}
|
|
2458
2489
|
}
|
|
2459
|
-
if (this.preview) {
|
|
2490
|
+
if (this.preview && this.previewingModel === ((_a = queue === null || queue === void 0 ? void 0 : queue[0]) === null || _a === void 0 ? void 0 : _a.model)) {
|
|
2460
2491
|
queryParams.preview = 'true';
|
|
2461
2492
|
}
|
|
2462
2493
|
var hasParams = Object.keys(queryParams).length > 0;
|
|
@@ -2469,9 +2500,8 @@ var Builder = /** @class */ (function () {
|
|
|
2469
2500
|
}
|
|
2470
2501
|
var format = queryParams.format;
|
|
2471
2502
|
var isApiCallForCodegen = format === 'solid' || format === 'react';
|
|
2472
|
-
var isApiCallForCodegenOrQuery = isApiCallForCodegen || apiEndpoint === 'query';
|
|
2473
|
-
if (apiEndpoint === 'content') {
|
|
2474
|
-
queryParams.enrich = true;
|
|
2503
|
+
var isApiCallForCodegenOrQuery = isApiCallForCodegen || this.apiEndpoint === 'query';
|
|
2504
|
+
if (this.apiEndpoint === 'content') {
|
|
2475
2505
|
if (queue[0].query) {
|
|
2476
2506
|
var flattened = this.flattenMongoQuery({ query: queue[0].query });
|
|
2477
2507
|
for (var key in flattened) {
|
|
@@ -2489,7 +2519,7 @@ var Builder = /** @class */ (function () {
|
|
|
2489
2519
|
if (isApiCallForCodegen) {
|
|
2490
2520
|
url = "".concat(host, "/api/v1/codegen/").concat(this.apiKey, "/").concat(keyNames);
|
|
2491
2521
|
}
|
|
2492
|
-
else if (apiEndpoint === 'query') {
|
|
2522
|
+
else if (this.apiEndpoint === 'query') {
|
|
2493
2523
|
url = "".concat(host, "/api/v3/query/").concat(this.apiKey, "/").concat(keyNames);
|
|
2494
2524
|
}
|
|
2495
2525
|
else {
|