@builder.io/sdk 4.0.2 → 5.0.0-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.
- package/CHANGELOG.md +7 -0
- package/dist/index.browser.js +25 -13
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs.js +25 -13
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +25 -13
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +25 -13
- package/dist/index.umd.js.map +1 -1
- package/dist/package.json +1 -1
- package/dist/src/builder.class.d.ts +5 -0
- package/dist/src/builder.class.js +23 -11
- package/dist/src/builder.class.js.map +1 -1
- package/dist/src/builder.class.test.js +154 -3
- 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 +2 -2
- package/scripts/set-sdk-version.sh +0 -0
- package/.yarnrc.yml +0 -1
package/dist/index.esm.js
CHANGED
|
@@ -950,7 +950,7 @@ function toError(err) {
|
|
|
950
950
|
|
|
951
951
|
var DEFAULT_API_VERSION = 'v3';
|
|
952
952
|
|
|
953
|
-
var SDK_VERSION = '
|
|
953
|
+
var SDK_VERSION = '5.0.0-0';
|
|
954
954
|
|
|
955
955
|
function datePlusMinutes(minutes) {
|
|
956
956
|
if (minutes === void 0) { minutes = 30; }
|
|
@@ -1350,7 +1350,9 @@ var Builder = /** @class */ (function () {
|
|
|
1350
1350
|
// 1. `function name(args) => {code}`
|
|
1351
1351
|
// 2. `name(args) => {code}`
|
|
1352
1352
|
// 3. `(args) => {}`
|
|
1353
|
-
|
|
1353
|
+
// 4. `args => {}`
|
|
1354
|
+
var isArrowWithoutParens = /^[a-zA-Z0-9_]+\s*=>/i.test(fnStr);
|
|
1355
|
+
var appendFunction = !fnStr.startsWith('function') && !fnStr.startsWith('(') && !isArrowWithoutParens;
|
|
1354
1356
|
return "return (".concat(appendFunction ? 'function ' : '').concat(fnStr, ").apply(this, arguments)");
|
|
1355
1357
|
};
|
|
1356
1358
|
return JSON.parse(JSON.stringify(info, function (key, value) {
|
|
@@ -2116,8 +2118,14 @@ var Builder = /** @class */ (function () {
|
|
|
2116
2118
|
assign(this.trackingUserAttributes, attributes);
|
|
2117
2119
|
};
|
|
2118
2120
|
Builder.prototype.get = function (modelName, options) {
|
|
2121
|
+
var _a;
|
|
2119
2122
|
if (options === void 0) { options = {}; }
|
|
2120
2123
|
var instance = this;
|
|
2124
|
+
var finalLocale = options.locale || ((_a = options.userAttributes) === null || _a === void 0 ? void 0 : _a.locale) || this.getUserAttributes().locale;
|
|
2125
|
+
var finalOptions = __assign(__assign({}, options), (finalLocale && {
|
|
2126
|
+
locale: String(finalLocale),
|
|
2127
|
+
userAttributes: __assign({ locale: String(finalLocale) }, options.userAttributes),
|
|
2128
|
+
}));
|
|
2121
2129
|
if (!Builder.isBrowser) {
|
|
2122
2130
|
instance = new Builder(options.apiKey || this.apiKey, options.req, options.res, undefined, options.authToken || this.authToken, options.apiVersion || this.apiVersion);
|
|
2123
2131
|
instance.setUserAttributes(this.getUserAttributes());
|
|
@@ -2135,7 +2143,7 @@ var Builder = /** @class */ (function () {
|
|
|
2135
2143
|
this.apiVersion = options.apiVersion;
|
|
2136
2144
|
}
|
|
2137
2145
|
}
|
|
2138
|
-
return instance.queueGetContent(modelName,
|
|
2146
|
+
return instance.queueGetContent(modelName, finalOptions).map(
|
|
2139
2147
|
/* map( */ function (matches) {
|
|
2140
2148
|
var match = matches && matches[0];
|
|
2141
2149
|
if (Builder.isStatic) {
|
|
@@ -2303,7 +2311,6 @@ var Builder = /** @class */ (function () {
|
|
|
2303
2311
|
};
|
|
2304
2312
|
Builder.prototype.flushGetContentQueue = function (usePastQueue, useQueue) {
|
|
2305
2313
|
var _this = this;
|
|
2306
|
-
var _a, _b;
|
|
2307
2314
|
if (usePastQueue === void 0) { usePastQueue = false; }
|
|
2308
2315
|
if (!this.apiKey) {
|
|
2309
2316
|
throw new Error("Fetching content failed, expected apiKey to be defined instead got: ".concat(this.apiKey));
|
|
@@ -2320,6 +2327,7 @@ var Builder = /** @class */ (function () {
|
|
|
2320
2327
|
return;
|
|
2321
2328
|
}
|
|
2322
2329
|
var queue = useQueue || (usePastQueue ? this.priorContentQueue : this.getContentQueue) || [];
|
|
2330
|
+
var apiEndpoint = queue[0].apiEndpoint || 'query';
|
|
2323
2331
|
// TODO: do this on every request send?
|
|
2324
2332
|
this.getOverridesFromQueryString();
|
|
2325
2333
|
var queryParams = __assign(__assign({
|
|
@@ -2343,9 +2351,9 @@ var Builder = /** @class */ (function () {
|
|
|
2343
2351
|
if (queue[0].sort) {
|
|
2344
2352
|
queryParams.sort = queue[0].sort;
|
|
2345
2353
|
}
|
|
2346
|
-
var pageQueryParams = typeof location !== 'undefined'
|
|
2354
|
+
var pageQueryParams = (typeof location !== 'undefined'
|
|
2347
2355
|
? QueryString.parseDeep(location.search.substr(1))
|
|
2348
|
-
: {}; // TODO: WHAT about SSR (this.request) ?
|
|
2356
|
+
: undefined) || {}; // TODO: WHAT about SSR (this.request) ?
|
|
2349
2357
|
var userAttributes =
|
|
2350
2358
|
// FIXME: HACK: only checks first in queue for user attributes overrides, should check all
|
|
2351
2359
|
// TODO: merge user attributes provided here with defaults and current user attiributes (?)
|
|
@@ -2394,7 +2402,6 @@ var Builder = /** @class */ (function () {
|
|
|
2394
2402
|
}
|
|
2395
2403
|
}
|
|
2396
2404
|
}
|
|
2397
|
-
var isApiCallForCodegen = ((_a = queue[0].options) === null || _a === void 0 ? void 0 : _a.format) === 'solid' || ((_b = queue[0].options) === null || _b === void 0 ? void 0 : _b.format) === 'react';
|
|
2398
2405
|
for (var _i = 0, queue_2 = queue; _i < queue_2.length; _i++) {
|
|
2399
2406
|
var options = queue_2[_i];
|
|
2400
2407
|
var format_1 = options.format;
|
|
@@ -2426,11 +2433,11 @@ var Builder = /** @class */ (function () {
|
|
|
2426
2433
|
'rev',
|
|
2427
2434
|
'static',
|
|
2428
2435
|
];
|
|
2429
|
-
for (var
|
|
2430
|
-
var key = properties_1[
|
|
2436
|
+
for (var _a = 0, properties_1 = properties; _a < properties_1.length; _a++) {
|
|
2437
|
+
var key = properties_1[_a];
|
|
2431
2438
|
var value = options[key];
|
|
2432
2439
|
if (value !== undefined) {
|
|
2433
|
-
if (
|
|
2440
|
+
if (apiEndpoint === 'query') {
|
|
2434
2441
|
queryParams.options = queryParams.options || {};
|
|
2435
2442
|
queryParams.options[options.key] = queryParams.options[options.key] || {};
|
|
2436
2443
|
queryParams.options[options.key][key] = JSON.stringify(value);
|
|
@@ -2452,8 +2459,10 @@ var Builder = /** @class */ (function () {
|
|
|
2452
2459
|
var params = omit(QueryString.parse(this.overrideParams), 'apiKey');
|
|
2453
2460
|
assign(queryParams, params);
|
|
2454
2461
|
}
|
|
2455
|
-
queryParams.format;
|
|
2456
|
-
|
|
2462
|
+
var format = queryParams.format;
|
|
2463
|
+
var isApiCallForCodegen = format === 'solid' || format === 'react';
|
|
2464
|
+
var isApiCallForCodegenOrQuery = isApiCallForCodegen || apiEndpoint === 'query';
|
|
2465
|
+
if (apiEndpoint === 'content') {
|
|
2457
2466
|
queryParams.enrich = true;
|
|
2458
2467
|
if (queue[0].query) {
|
|
2459
2468
|
var flattened = this.flattenMongoQuery({ query: queue[0].query });
|
|
@@ -2472,6 +2481,9 @@ var Builder = /** @class */ (function () {
|
|
|
2472
2481
|
if (isApiCallForCodegen) {
|
|
2473
2482
|
url = "".concat(host, "/api/v1/codegen/").concat(this.apiKey, "/").concat(keyNames);
|
|
2474
2483
|
}
|
|
2484
|
+
else if (apiEndpoint === 'query') {
|
|
2485
|
+
url = "".concat(host, "/api/v3/query/").concat(this.apiKey, "/").concat(keyNames);
|
|
2486
|
+
}
|
|
2475
2487
|
else {
|
|
2476
2488
|
url = "".concat(host, "/api/v3/content/").concat(queue[0].model);
|
|
2477
2489
|
}
|
|
@@ -2494,7 +2506,7 @@ var Builder = /** @class */ (function () {
|
|
|
2494
2506
|
if (!observer) {
|
|
2495
2507
|
return;
|
|
2496
2508
|
}
|
|
2497
|
-
var data =
|
|
2509
|
+
var data = isApiCallForCodegenOrQuery ? result[keyName] : result.results;
|
|
2498
2510
|
var sorted = data; // sortBy(data, item => item.priority);
|
|
2499
2511
|
if (data) {
|
|
2500
2512
|
var testModifiedResults = Builder.isServer
|