-
Notifications
You must be signed in to change notification settings - Fork 980
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix[gen1][core] ENG-7507 added class field apiEndpoint$ (#3748)
## Description API Endpoint should be set at the class level and not at the options level **Jira ticket** https://builder-io.atlassian.net/browse/ENG-7507 **Loom** https://www.loom.com/share/ffe8bd20e576420f89606a62387f05f5 --------- Co-authored-by: Clyde Mendonca <clydemendonca@Clydes-MacBook-Pro.local> Co-authored-by: Sami Jaber <me@sami.website>
- Loading branch information
1 parent
3e9455b
commit 56f9461
Showing
9 changed files
with
136 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@builder.io/sdk': major | ||
'@builder.io/react': major | ||
--- | ||
|
||
- Adds `apiEndpoint` prop to `builder` instance with permitted values being `'content'` or `'query'`. It dictates which API endpoint is used for fetching Builder content | ||
- Breaking Change 🧨: Removes `apiEndpoint` argument from `builder.get()`, `builder.getAll()`, and the `options` prop of `<BuilderContent>` component. NOTE: this argument was not working as expected. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/sdks-tests/src/snippet-tests/api-endpoint.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { expect } from '@playwright/test'; | ||
import { findTextInPage, test } from '../helpers/index.js'; | ||
|
||
test.describe('API Endpoint', () => { | ||
test.describe('Live', () => { | ||
test('loads symbol', async ({ page }) => { | ||
await page.goto('/contentwithsymbol'); | ||
|
||
await findTextInPage({ page, text: 'This is my Symbol!' }); | ||
}); | ||
|
||
test('records API calls after page load', async ({ page, packageName }) => { | ||
test.skip(packageName !== 'gen1-next'); | ||
// Start monitoring network requests | ||
const urlMatchForContentAPI = /https:\/\/cdn\.builder\.io\/api\/v3\/content/; | ||
const urlMatchForQueryAPI = /https:\/\/cdn\.builder\.io\/api\/v3\/query/; | ||
|
||
let queryApiInvocations = 0; | ||
|
||
const responsePromise = page.waitForResponse(urlMatchForContentAPI); | ||
|
||
await page.route(urlMatchForQueryAPI, route => { | ||
queryApiInvocations++; | ||
return route.continue(); | ||
}); | ||
|
||
await page.goto( | ||
'/contentwithsymbol?builder.space=ee9f13b4981e489a9a1209887695ef2b&builder.user.permissions=read%2Ccreate%2Cpublish%2CeditDesigns%2CeditLayouts%2CeditLayers%2CeditContentPriority&builder.user.role.name=Designer&builder.user.role.id=creator&builder.cachebust=true&builder.preview=page&builder.noCache=true&builder.allowTextEdit=true&__builder_editing__=true&builder.overrides.page=6a2f7e1a9ab2454ba6766522d6d99f0d&builder.overrides.6a2f7e1a9ab2454ba6766522d6d99f0d=6a2f7e1a9ab2454ba6766522d6d99f0d&builder.overrides.page:/contentwithsymbol=6a2f7e1a9ab2454ba6766522d6d99f0d&builder.frameEditing=page&builder.options.locale=Default', | ||
{ waitUntil: 'networkidle' } | ||
); | ||
|
||
// Verify API calls were recorded | ||
const req = (await responsePromise).request(); | ||
expect(req).toBeDefined(); | ||
expect(req!.method()).toBe('GET'); | ||
expect(queryApiInvocations).toBe(0); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
packages/sdks/snippets/gen1-nextjs/pages/contentwithsymbol/[[...index]].tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* Quickstart snippet | ||
* snippets/gen1-nextjs/pages/[[...index]].tsx | ||
*/ | ||
import { BuilderComponent, builder, useIsPreviewing } from '@builder.io/react'; | ||
import type { BuilderContent } from '@builder.io/sdk'; | ||
import type { GetStaticProps } from 'next'; | ||
import DefaultErrorPage from 'next/error'; | ||
import React from 'react'; | ||
|
||
builder.init('ee9f13b4981e489a9a1209887695ef2b'); | ||
builder.apiEndpoint = 'content'; | ||
|
||
export const getStaticProps: GetStaticProps = async () => { | ||
const urlPath = '/contentwithsymbol'; | ||
|
||
const page = await builder | ||
.get('page', { | ||
userAttributes: { | ||
urlPath, | ||
}, | ||
}) | ||
.promise(); | ||
|
||
return { | ||
props: { | ||
page: page || null, | ||
}, | ||
revalidate: 5, | ||
}; | ||
}; | ||
|
||
export const getStaticPaths = async () => { | ||
return { | ||
paths: [], | ||
fallback: 'blocking', | ||
}; | ||
}; | ||
|
||
export default function Page({ page }: { page: BuilderContent | null }) { | ||
const isPreviewing = useIsPreviewing(); | ||
|
||
if (!page && !isPreviewing) { | ||
return <DefaultErrorPage statusCode={404} />; | ||
} | ||
|
||
return ( | ||
<> | ||
<h1>CORRECT</h1> | ||
{/* Render the Builder page */} | ||
<BuilderComponent model="page" content={page || undefined} /> | ||
</> | ||
); | ||
} |