@builder.io/sdk
Advanced tools
Comparing version 3.0.2 to 3.0.3
# @builder.io/sdk | ||
## 3.0.3 | ||
### Patch Changes | ||
- d403fca: Adds `apiEndpoint` prop to `builder.get()` and `builder.getAll()` with options `'content'` and `'query'`. It dictates which API endpoint is used for the content fetching. | ||
Defaults to `'query'` | ||
## 3.0.2 | ||
@@ -4,0 +11,0 @@ |
{ | ||
"name": "@builder.io/sdk", | ||
"version": "3.0.2", | ||
"version": "3.0.3", | ||
"unpkg": "./dist/index.browser.js", | ||
@@ -48,4 +48,2 @@ "main": "./dist/index.cjs.js", | ||
"jest": "27.4.7", | ||
"nx": "^19.6.5", | ||
"nx-cloud": "^19.0.0", | ||
"rollup": "^2.38.5", | ||
@@ -52,0 +50,0 @@ "rollup-plugin-alias": "^1.5.1", |
@@ -119,2 +119,7 @@ /// <reference types="node" /> | ||
/** | ||
* Dictates which API endpoint is used when fetching content. Allows `'content'` and `'query'`. | ||
* Defaults to `'query'`. | ||
*/ | ||
apiEndpoint?: 'content' | 'query'; | ||
/** | ||
* User attribute key value pairs to be used for targeting | ||
@@ -889,2 +894,4 @@ * https://www.builder.io/c/docs/custom-targeting-attributes | ||
get host(): string; | ||
private makeFetchApiCall; | ||
private flattenMongoQuery; | ||
private flushGetContentQueue; | ||
@@ -891,0 +898,0 @@ private testCookiePrefix; |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var builder_class_1 = require("./builder.class"); | ||
var observable_class_1 = require("./classes/observable.class"); | ||
describe('Builder', function () { | ||
@@ -159,2 +207,559 @@ test('trustedHosts', function () { | ||
}); | ||
describe('flushGetContentQueue', function () { | ||
var _a; | ||
var API_KEY = '25608a566fbb654ea959c1b1729e370d'; | ||
var MODEL = 'page'; | ||
var AUTH_TOKEN = '82202e99f9fb4ed1da5940f7fa191e72'; | ||
var OMIT = 'data.blocks'; | ||
var builder; | ||
var codegenOrQueryApiResult = (_a = {}, | ||
_a[MODEL] = [ | ||
{ | ||
lastUpdatedBy: 'vkEwLBAcR1VHNUy7DDD366ffYjQ2', | ||
folders: [], | ||
data: { | ||
themeId: false, | ||
title: 'test', | ||
blocks: [ | ||
{ | ||
'@type': '@builder.io/sdk:Element', | ||
'@version': 2, | ||
id: 'builder-370f0829496c41d48b1fb77c1b4ea2b2', | ||
component: { | ||
name: 'Text', | ||
options: { | ||
text: 'A is selected', | ||
}, | ||
}, | ||
responsiveStyles: { | ||
large: { | ||
display: 'flex', | ||
flexDirection: 'column', | ||
position: 'relative', | ||
flexShrink: '0', | ||
boxSizing: 'border-box', | ||
marginTop: '20px', | ||
lineHeight: 'normal', | ||
height: 'auto', | ||
}, | ||
}, | ||
}, | ||
{ | ||
id: 'builder-pixel-lrwo8ns32dg', | ||
'@type': '@builder.io/sdk:Element', | ||
tagName: 'img', | ||
properties: { | ||
src: 'https://cdn.builder.io/api/v1/pixel?apiKey=5271c255f7824802a30f12bdad90e347', | ||
'aria-hidden': 'true', | ||
alt: '', | ||
role: 'presentation', | ||
width: '0', | ||
height: '0', | ||
}, | ||
responsiveStyles: { | ||
large: { | ||
height: '0', | ||
width: '0', | ||
display: 'inline-block', | ||
opacity: '0', | ||
overflow: 'hidden', | ||
pointerEvents: 'none', | ||
}, | ||
}, | ||
}, | ||
], | ||
url: '/test', | ||
state: { | ||
deviceSize: 'large', | ||
location: { | ||
pathname: '/test', | ||
path: ['test'], | ||
query: {}, | ||
}, | ||
}, | ||
}, | ||
modelId: '12518e35051e42dda999e91f1162f0bd', | ||
query: [ | ||
{ | ||
'@type': '@builder.io/core:Query', | ||
property: 'urlPath', | ||
value: '/test', | ||
operator: 'is', | ||
}, | ||
{ | ||
'@type': '@builder.io/core:Query', | ||
property: 'name', | ||
value: ['a'], | ||
operator: 'is', | ||
}, | ||
], | ||
published: 'published', | ||
firstPublished: 1725450385400, | ||
testRatio: 1, | ||
lastUpdated: 1725451287436, | ||
createdDate: 1725450170945, | ||
createdBy: 'vkEwLBAcR1VHNUy7DDD366ffYjQ2', | ||
meta: { | ||
lastPreviewUrl: 'http://localhost:5173/test?builder.space=5271c255f7824802a30f12bdad90e347&builder.user.permissions=read%2Ccreate%2Cpublish%2CeditCode%2CeditDesigns%2Cadmin%2CeditLayouts%2CeditLayers&builder.user.role.name=Admin&builder.user.role.id=admin&builder.cachebust=true&builder.preview=page&builder.noCache=true&builder.allowTextEdit=true&__builder_editing__=true&builder.overrides.page=ad03bbebf34b49a9912aeae629571db7&builder.overrides.ad03bbebf34b49a9912aeae629571db7=ad03bbebf34b49a9912aeae629571db7&builder.overrides.page:/test=ad03bbebf34b49a9912aeae629571db7&builder.options.locale=Default', | ||
kind: 'page', | ||
hasLinks: false, | ||
}, | ||
variations: {}, | ||
name: 'test', | ||
id: 'ad03bbebf34b49a9912aeae629571db7', | ||
rev: '9inkgroan7l', | ||
}, | ||
], | ||
_a); | ||
var contentApiResult = { | ||
results: [ | ||
{ | ||
lastUpdatedBy: 'vkEwLBAcR1VHNUy7DDD366ffYjQ2', | ||
folders: [], | ||
data: { | ||
themeId: false, | ||
title: 'test', | ||
blocks: [], | ||
url: '/test', | ||
state: { | ||
deviceSize: 'large', | ||
location: { | ||
path: '', | ||
query: {}, | ||
}, | ||
}, | ||
}, | ||
modelId: '12518e35051e42dda999e91f1162f0bd', | ||
query: [ | ||
{ | ||
'@type': '@builder.io/core:Query', | ||
property: 'urlPath', | ||
value: '/test', | ||
operator: 'is', | ||
}, | ||
{ | ||
'@type': '@builder.io/core:Query', | ||
property: 'name', | ||
value: ['a'], | ||
operator: 'is', | ||
}, | ||
], | ||
published: 'published', | ||
firstPublished: 1725450385400, | ||
testRatio: 1, | ||
lastUpdated: 1725451287436, | ||
createdDate: 1725450170945, | ||
createdBy: 'vkEwLBAcR1VHNUy7DDD366ffYjQ2', | ||
meta: { | ||
lastPreviewUrl: 'http://localhost:5173/test?builder.space=5271c255f7824802a30f12bdad90e347&builder.user.permissions=read%2Ccreate%2Cpublish%2CeditCode%2CeditDesigns%2Cadmin%2CeditLayouts%2CeditLayers&builder.user.role.name=Admin&builder.user.role.id=admin&builder.cachebust=true&builder.preview=page&builder.noCache=true&builder.allowTextEdit=true&__builder_editing__=true&builder.overrides.page=ad03bbebf34b49a9912aeae629571db7&builder.overrides.ad03bbebf34b49a9912aeae629571db7=ad03bbebf34b49a9912aeae629571db7&builder.overrides.page:/test=ad03bbebf34b49a9912aeae629571db7&builder.options.locale=Default', | ||
kind: 'page', | ||
hasLinks: false, | ||
}, | ||
variations: {}, | ||
name: 'test', | ||
id: 'ad03bbebf34b49a9912aeae629571db7', | ||
rev: 'kvr9rrrklws', | ||
}, | ||
{ | ||
createdDate: 1725363956284, | ||
data: { | ||
title: 'Builder + React Demo Page', | ||
blocks: [], | ||
url: ['/builder-demo'], | ||
state: { | ||
deviceSize: 'large', | ||
location: { | ||
path: '', | ||
query: {}, | ||
}, | ||
}, | ||
}, | ||
modelId: '12518e35051e42dda999e91f1162f0bd', | ||
query: [ | ||
{ | ||
property: 'urlPath', | ||
value: ['/builder-demo'], | ||
operator: 'is', | ||
}, | ||
], | ||
name: 'Builder + React Demo Page', | ||
id: '87853dcacee64c4a9b573faa46823e61', | ||
published: 'published', | ||
meta: {}, | ||
rev: 'kvr9rrrklws', | ||
}, | ||
{ | ||
lastUpdatedBy: 'vkEwLBAcR1VHNUy7DDD366ffYjQ2', | ||
folders: [], | ||
data: { | ||
themeId: false, | ||
title: 'Test Page', | ||
blocks: [], | ||
url: '/test-page', | ||
state: { | ||
deviceSize: 'large', | ||
location: { | ||
path: '', | ||
query: {}, | ||
}, | ||
}, | ||
}, | ||
modelId: '12518e35051e42dda999e91f1162f0bd', | ||
query: [ | ||
{ | ||
'@type': '@builder.io/core:Query', | ||
property: 'urlPath', | ||
value: '/test-page', | ||
operator: 'is', | ||
}, | ||
], | ||
published: 'published', | ||
firstPublished: 1722527310201, | ||
testRatio: 1, | ||
lastUpdated: 1722528875919, | ||
createdDate: 1722527254768, | ||
createdBy: 'vkEwLBAcR1VHNUy7DDD366ffYjQ2', | ||
meta: { | ||
kind: 'page', | ||
lastPreviewUrl: 'http://localhost:3000/test-page?builder.space=5271c255f7824802a30f12bdad90e347&builder.user.permissions=read%2Ccreate%2Cpublish%2CeditCode%2CeditDesigns%2Cadmin%2CeditLayouts%2CeditLayers&builder.user.role.name=Admin&builder.user.role.id=admin&builder.cachebust=true&builder.preview=page&builder.noCache=true&builder.allowTextEdit=true&__builder_editing__=true&builder.overrides.page=e53863a02641455294ac59ab7e2be643&builder.overrides.e53863a02641455294ac59ab7e2be643=e53863a02641455294ac59ab7e2be643&builder.overrides.page:/test-page=e53863a02641455294ac59ab7e2be643', | ||
hasLinks: false, | ||
}, | ||
variations: {}, | ||
name: 'Test Page', | ||
id: 'e53863a02641455294ac59ab7e2be643', | ||
rev: 'kvr9rrrklws', | ||
}, | ||
], | ||
}; | ||
beforeEach(function () { | ||
builder = new builder_class_1.Builder(API_KEY, undefined, undefined, false, AUTH_TOKEN, 'v3'); | ||
var builderSubject = new observable_class_1.BehaviorSubject([]); | ||
builderSubject.next = jest.fn(function () { }); | ||
builder.observersByKey[MODEL] = builderSubject; | ||
builder['makeFetchApiCall'] = jest.fn(function (url) { | ||
var result = url.includes('/codegen/') || url.includes('/query/') | ||
? codegenOrQueryApiResult | ||
: contentApiResult; | ||
return Promise.resolve({ | ||
json: function () { | ||
return Promise.resolve(result); | ||
}, | ||
}); | ||
}); | ||
}); | ||
test('throws error if apiKey is not defined', function () { | ||
builder = new builder_class_1.Builder(); | ||
try { | ||
builder['flushGetContentQueue'](); | ||
} | ||
catch (err) { | ||
expect(err.message).toBe('Fetching content failed, expected apiKey to be defined instead got: null'); | ||
} | ||
}); | ||
test('throws error if apiVersion is not v3', function () { | ||
builder = new builder_class_1.Builder(API_KEY, undefined, undefined, false, AUTH_TOKEN, 'v1'); | ||
try { | ||
builder['flushGetContentQueue'](); | ||
} | ||
catch (err) { | ||
expect(err.message).toBe("Invalid apiVersion: expected 'v3', received 'v1'"); | ||
} | ||
}); | ||
test("hits codegen url when format is 'solid'", function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var expectedFormat, result, observerNextMock; | ||
var _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
expectedFormat = 'solid'; | ||
return [4 /*yield*/, builder['flushGetContentQueue'](true, [ | ||
{ | ||
model: MODEL, | ||
format: expectedFormat, | ||
key: MODEL, | ||
userAttributes: { respectScheduling: true }, | ||
omit: OMIT, | ||
fields: 'data', | ||
}, | ||
])]; | ||
case 1: | ||
result = _b.sent(); | ||
observerNextMock = (_a = builder.observersByKey[MODEL]) === null || _a === void 0 ? void 0 : _a.next; | ||
expect(observerNextMock).toBeCalledTimes(1); | ||
expect(observerNextMock.mock.calls[0][0][0]).toStrictEqual(__assign(__assign({}, codegenOrQueryApiResult[MODEL][0]), { variationId: expect.any(String) })); | ||
expect(builder['makeFetchApiCall']).toBeCalledTimes(1); | ||
expect(builder['makeFetchApiCall']).toBeCalledWith("https://cdn.builder.io/api/v1/codegen/".concat(API_KEY, "/").concat(MODEL, "?omit=").concat(OMIT, "&apiKey=").concat(API_KEY, "&fields=data&format=solid&userAttributes=%7B%22respectScheduling%22%3Atrue%7D&options.").concat(MODEL, ".model=%22").concat(MODEL, "%22"), { headers: { Authorization: "Bearer ".concat(AUTH_TOKEN) } }); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
test("hits codegen url when format is 'react'", function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var expectedFormat, result, observerNextMock; | ||
var _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
expectedFormat = 'react'; | ||
return [4 /*yield*/, builder['flushGetContentQueue'](true, [ | ||
{ | ||
model: MODEL, | ||
format: expectedFormat, | ||
key: MODEL, | ||
userAttributes: { respectScheduling: true }, | ||
omit: OMIT, | ||
fields: 'data', | ||
}, | ||
])]; | ||
case 1: | ||
result = _b.sent(); | ||
observerNextMock = (_a = builder.observersByKey[MODEL]) === null || _a === void 0 ? void 0 : _a.next; | ||
expect(observerNextMock).toBeCalledTimes(1); | ||
expect(observerNextMock.mock.calls[0][0][0]).toStrictEqual(__assign(__assign({}, codegenOrQueryApiResult[MODEL][0]), { variationId: expect.any(String) })); | ||
expect(builder['makeFetchApiCall']).toBeCalledTimes(1); | ||
expect(builder['makeFetchApiCall']).toBeCalledWith("https://cdn.builder.io/api/v1/codegen/".concat(API_KEY, "/").concat(MODEL, "?omit=").concat(OMIT, "&apiKey=").concat(API_KEY, "&fields=data&format=react&userAttributes=%7B%22respectScheduling%22%3Atrue%7D&options.").concat(MODEL, ".model=%22").concat(MODEL, "%22"), { headers: { Authorization: "Bearer ".concat(AUTH_TOKEN) } }); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
test("hits query url when apiEndpoint is undefined and format is 'html'", function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var expectedFormat, result, observerNextMock; | ||
var _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
expectedFormat = 'html'; | ||
return [4 /*yield*/, builder['flushGetContentQueue'](true, [ | ||
{ | ||
model: MODEL, | ||
format: expectedFormat, | ||
key: MODEL, | ||
userAttributes: { respectScheduling: true }, | ||
omit: OMIT, | ||
fields: 'data', | ||
}, | ||
])]; | ||
case 1: | ||
result = _b.sent(); | ||
observerNextMock = (_a = builder.observersByKey[MODEL]) === null || _a === void 0 ? void 0 : _a.next; | ||
expect(observerNextMock).toBeCalledTimes(1); | ||
expect(observerNextMock.mock.calls[0][0][0]).toStrictEqual(__assign(__assign({}, codegenOrQueryApiResult[MODEL][0]), { variationId: expect.any(String) })); | ||
expect(builder['makeFetchApiCall']).toBeCalledTimes(1); | ||
expect(builder['makeFetchApiCall']).toBeCalledWith("https://cdn.builder.io/api/v3/query/".concat(API_KEY, "/").concat(MODEL, "?omit=").concat(OMIT, "&apiKey=").concat(API_KEY, "&fields=data&format=").concat(expectedFormat, "&userAttributes=%7B%22respectScheduling%22%3Atrue%7D&options.").concat(MODEL, ".model=%22").concat(MODEL, "%22"), { headers: { Authorization: "Bearer ".concat(AUTH_TOKEN) } }); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
test("hits content url when apiEndpoint is 'content' and format is 'html'", function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var expectedFormat, result, observerNextMock; | ||
var _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
expectedFormat = 'html'; | ||
return [4 /*yield*/, builder['flushGetContentQueue'](true, [ | ||
{ | ||
apiEndpoint: 'content', | ||
model: MODEL, | ||
format: expectedFormat, | ||
key: MODEL, | ||
userAttributes: { respectScheduling: true }, | ||
omit: OMIT, | ||
fields: 'data', | ||
limit: 10, | ||
}, | ||
])]; | ||
case 1: | ||
result = _b.sent(); | ||
observerNextMock = (_a = builder.observersByKey[MODEL]) === null || _a === void 0 ? void 0 : _a.next; | ||
expect(observerNextMock).toBeCalledTimes(1); | ||
expect(observerNextMock.mock.calls[0][0][0]).toStrictEqual(__assign(__assign({}, contentApiResult.results[0]), { variationId: expect.any(String) })); | ||
expect(observerNextMock.mock.calls[0][0][1]).toStrictEqual(__assign({}, contentApiResult.results[1])); | ||
expect(observerNextMock.mock.calls[0][0][2]).toStrictEqual(__assign(__assign({}, contentApiResult.results[2]), { variationId: expect.any(String) })); | ||
expect(builder['makeFetchApiCall']).toBeCalledTimes(1); | ||
expect(builder['makeFetchApiCall']).toBeCalledWith("https://cdn.builder.io/api/v3/content/".concat(MODEL, "?omit=data.blocks&apiKey=").concat(API_KEY, "&fields=data&format=").concat(expectedFormat, "&userAttributes=%7B%22respectScheduling%22%3Atrue%7D&limit=10&model=%22").concat(MODEL, "%22&enrich=true"), { headers: { Authorization: "Bearer ".concat(AUTH_TOKEN) } }); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
test("hits query url when apiEndpoint is undefined and format is 'amp'", function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var expectedFormat, result, observerNextMock; | ||
var _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
expectedFormat = 'amp'; | ||
return [4 /*yield*/, builder['flushGetContentQueue'](true, [ | ||
{ | ||
model: MODEL, | ||
format: expectedFormat, | ||
key: MODEL, | ||
userAttributes: { respectScheduling: true }, | ||
omit: OMIT, | ||
fields: 'data', | ||
}, | ||
])]; | ||
case 1: | ||
result = _b.sent(); | ||
observerNextMock = (_a = builder.observersByKey[MODEL]) === null || _a === void 0 ? void 0 : _a.next; | ||
expect(observerNextMock).toBeCalledTimes(1); | ||
expect(observerNextMock.mock.calls[0][0][0]).toStrictEqual(__assign(__assign({}, codegenOrQueryApiResult[MODEL][0]), { variationId: expect.any(String) })); | ||
expect(builder['makeFetchApiCall']).toBeCalledTimes(1); | ||
expect(builder['makeFetchApiCall']).toBeCalledWith("https://cdn.builder.io/api/v3/query/".concat(API_KEY, "/").concat(MODEL, "?omit=").concat(OMIT, "&apiKey=").concat(API_KEY, "&fields=data&format=").concat(expectedFormat, "&userAttributes=%7B%22respectScheduling%22%3Atrue%7D&options.").concat(MODEL, ".model=%22").concat(MODEL, "%22"), { headers: { Authorization: "Bearer ".concat(AUTH_TOKEN) } }); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
test("hits content url when apiEndpoint is 'content' and format is 'amp'", function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var expectedFormat, result, observerNextMock; | ||
var _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
expectedFormat = 'amp'; | ||
return [4 /*yield*/, builder['flushGetContentQueue'](true, [ | ||
{ | ||
apiEndpoint: 'content', | ||
model: MODEL, | ||
format: expectedFormat, | ||
key: MODEL, | ||
userAttributes: { respectScheduling: true }, | ||
omit: OMIT, | ||
fields: 'data', | ||
limit: 10, | ||
}, | ||
])]; | ||
case 1: | ||
result = _b.sent(); | ||
observerNextMock = (_a = builder.observersByKey[MODEL]) === null || _a === void 0 ? void 0 : _a.next; | ||
expect(observerNextMock).toBeCalledTimes(1); | ||
expect(observerNextMock.mock.calls[0][0][0]).toStrictEqual(__assign(__assign({}, contentApiResult.results[0]), { variationId: expect.any(String) })); | ||
expect(observerNextMock.mock.calls[0][0][1]).toStrictEqual(__assign({}, contentApiResult.results[1])); | ||
expect(observerNextMock.mock.calls[0][0][2]).toStrictEqual(__assign(__assign({}, contentApiResult.results[2]), { variationId: expect.any(String) })); | ||
expect(builder['makeFetchApiCall']).toBeCalledTimes(1); | ||
expect(builder['makeFetchApiCall']).toBeCalledWith("https://cdn.builder.io/api/v3/content/".concat(MODEL, "?omit=data.blocks&apiKey=").concat(API_KEY, "&fields=data&format=").concat(expectedFormat, "&userAttributes=%7B%22respectScheduling%22%3Atrue%7D&limit=10&model=%22").concat(MODEL, "%22&enrich=true"), { headers: { Authorization: "Bearer ".concat(AUTH_TOKEN) } }); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
test("hits query url when apiEndpoint is undefined and format is 'email'", function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var expectedFormat, result, observerNextMock; | ||
var _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
expectedFormat = 'email'; | ||
return [4 /*yield*/, builder['flushGetContentQueue'](true, [ | ||
{ | ||
model: MODEL, | ||
format: expectedFormat, | ||
key: MODEL, | ||
userAttributes: { respectScheduling: true }, | ||
omit: OMIT, | ||
fields: 'data', | ||
}, | ||
])]; | ||
case 1: | ||
result = _b.sent(); | ||
observerNextMock = (_a = builder.observersByKey[MODEL]) === null || _a === void 0 ? void 0 : _a.next; | ||
expect(observerNextMock).toBeCalledTimes(1); | ||
expect(observerNextMock.mock.calls[0][0][0]).toStrictEqual(__assign(__assign({}, codegenOrQueryApiResult[MODEL][0]), { variationId: expect.any(String) })); | ||
expect(builder['makeFetchApiCall']).toBeCalledTimes(1); | ||
expect(builder['makeFetchApiCall']).toBeCalledWith("https://cdn.builder.io/api/v3/query/".concat(API_KEY, "/").concat(MODEL, "?omit=").concat(OMIT, "&apiKey=").concat(API_KEY, "&fields=data&format=").concat(expectedFormat, "&userAttributes=%7B%22respectScheduling%22%3Atrue%7D&options.").concat(MODEL, ".model=%22").concat(MODEL, "%22"), { headers: { Authorization: "Bearer ".concat(AUTH_TOKEN) } }); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
test("hits query url when apiEndpoint is undefined and format is 'email' and url is passed instead of userAttributes", function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var expectedFormat, result, observerNextMock; | ||
var _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
expectedFormat = 'email'; | ||
return [4 /*yield*/, builder['flushGetContentQueue'](true, [ | ||
{ | ||
model: MODEL, | ||
format: expectedFormat, | ||
key: MODEL, | ||
url: '/test-page', | ||
omit: OMIT, | ||
fields: 'data', | ||
}, | ||
])]; | ||
case 1: | ||
result = _b.sent(); | ||
observerNextMock = (_a = builder.observersByKey[MODEL]) === null || _a === void 0 ? void 0 : _a.next; | ||
expect(observerNextMock).toBeCalledTimes(1); | ||
expect(observerNextMock.mock.calls[0][0][0]).toStrictEqual(__assign(__assign({}, codegenOrQueryApiResult[MODEL][0]), { variationId: expect.any(String) })); | ||
expect(builder['makeFetchApiCall']).toBeCalledTimes(1); | ||
expect(builder['makeFetchApiCall']).toBeCalledWith("https://cdn.builder.io/api/v3/query/".concat(API_KEY, "/").concat(MODEL, "?omit=").concat(OMIT, "&apiKey=").concat(API_KEY, "&fields=data&format=").concat(expectedFormat, "&userAttributes=%7B%22urlPath%22%3A%22%2Ftest-page%22%2C%22host%22%3A%22localhost%22%2C%22device%22%3A%22desktop%22%7D&options.").concat(MODEL, ".model=%22").concat(MODEL, "%22"), { headers: { Authorization: "Bearer ".concat(AUTH_TOKEN) } }); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
test("hits content url when apiEndpoint is 'content' and format is 'email'", function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var expectedFormat, result, observerNextMock; | ||
var _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
expectedFormat = 'email'; | ||
return [4 /*yield*/, builder['flushGetContentQueue'](true, [ | ||
{ | ||
apiEndpoint: 'content', | ||
model: MODEL, | ||
format: expectedFormat, | ||
key: MODEL, | ||
userAttributes: { respectScheduling: true }, | ||
omit: OMIT, | ||
fields: 'data', | ||
limit: 10, | ||
}, | ||
])]; | ||
case 1: | ||
result = _b.sent(); | ||
observerNextMock = (_a = builder.observersByKey[MODEL]) === null || _a === void 0 ? void 0 : _a.next; | ||
expect(observerNextMock).toBeCalledTimes(1); | ||
expect(observerNextMock.mock.calls[0][0][0]).toStrictEqual(__assign(__assign({}, contentApiResult.results[0]), { variationId: expect.any(String) })); | ||
expect(observerNextMock.mock.calls[0][0][1]).toStrictEqual(__assign({}, contentApiResult.results[1])); | ||
expect(observerNextMock.mock.calls[0][0][2]).toStrictEqual(__assign(__assign({}, contentApiResult.results[2]), { variationId: expect.any(String) })); | ||
expect(builder['makeFetchApiCall']).toBeCalledTimes(1); | ||
expect(builder['makeFetchApiCall']).toBeCalledWith("https://cdn.builder.io/api/v3/content/".concat(MODEL, "?omit=data.blocks&apiKey=").concat(API_KEY, "&fields=data&format=").concat(expectedFormat, "&userAttributes=%7B%22respectScheduling%22%3Atrue%7D&limit=10&model=%22").concat(MODEL, "%22&enrich=true"), { headers: { Authorization: "Bearer ".concat(AUTH_TOKEN) } }); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
test("hits content url when apiEndpoint is 'content' and format is 'email' and url is passed instead of userAttributes", function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var expectedFormat, result, observerNextMock; | ||
var _a; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
expectedFormat = 'email'; | ||
return [4 /*yield*/, builder['flushGetContentQueue'](true, [ | ||
{ | ||
apiEndpoint: 'content', | ||
model: MODEL, | ||
format: expectedFormat, | ||
key: MODEL, | ||
url: '/test-page', | ||
omit: OMIT, | ||
fields: 'data', | ||
limit: 10, | ||
}, | ||
])]; | ||
case 1: | ||
result = _b.sent(); | ||
observerNextMock = (_a = builder.observersByKey[MODEL]) === null || _a === void 0 ? void 0 : _a.next; | ||
expect(observerNextMock).toBeCalledTimes(1); | ||
expect(observerNextMock.mock.calls[0][0][0]).toStrictEqual(__assign(__assign({}, contentApiResult.results[0]), { variationId: expect.any(String) })); | ||
expect(observerNextMock.mock.calls[0][0][1]).toStrictEqual(__assign({}, contentApiResult.results[1])); | ||
expect(observerNextMock.mock.calls[0][0][2]).toStrictEqual(__assign(__assign({}, contentApiResult.results[2]), { variationId: expect.any(String) })); | ||
expect(builder['makeFetchApiCall']).toBeCalledTimes(1); | ||
expect(builder['makeFetchApiCall']).toBeCalledWith("https://cdn.builder.io/api/v3/content/".concat(MODEL, "?omit=data.blocks&apiKey=").concat(API_KEY, "&fields=data&format=").concat(expectedFormat, "&userAttributes=%7B%22urlPath%22%3A%22%2Ftest-page%22%2C%22host%22%3A%22localhost%22%2C%22device%22%3A%22desktop%22%7D&limit=10&model=%22").concat(MODEL, "%22&enrich=true"), { headers: { Authorization: "Bearer ".concat(AUTH_TOKEN) } }); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); }); | ||
}); | ||
//# sourceMappingURL=builder.class.test.js.map |
{ | ||
"name": "@builder.io/sdk", | ||
"version": "3.0.2", | ||
"version": "3.0.3", | ||
"unpkg": "./dist/index.browser.js", | ||
@@ -48,4 +48,2 @@ "main": "./dist/index.cjs.js", | ||
"jest": "27.4.7", | ||
"nx": "^19.6.5", | ||
"nx-cloud": "^19.0.0", | ||
"rollup": "^2.38.5", | ||
@@ -52,0 +50,0 @@ "rollup-plugin-alias": "^1.5.1", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1729553
34
16379