diff --git a/package-lock.json b/package-lock.json index 7d4f5c553..99f3bf17f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,7 @@ "devDependencies": { "@playwright/test": "1.36.2", "@prezly/eslint-config": "4.5.0", - "@prezly/sdk": "16.5.0", + "@prezly/sdk": "16.7.0", "@types/jest": "29.5.3", "@types/node": "17.0.45", "@types/react": "18.2.18", @@ -3080,9 +3080,9 @@ "integrity": "sha512-uKBTA1gZ90ckKK/4wVoVORC3VUTkOgFwhZWwWsceKxVoAgDxqS5s0NXP5V7J+niEdvCkcoEVeCc25kCs+Hr/uQ==" }, "node_modules/@prezly/sdk": { - "version": "16.5.0", - "resolved": "https://registry.npmjs.org/@prezly/sdk/-/sdk-16.5.0.tgz", - "integrity": "sha512-fOvMzHKIdSzMhMc4EYVb66ZsSvJhkX1SIfhGBB4SkhjxkqLFZ/XLgcqu1QEfc5/ROF39XfIXcLFkQadepZN//Q==", + "version": "16.7.0", + "resolved": "https://registry.npmjs.org/@prezly/sdk/-/sdk-16.7.0.tgz", + "integrity": "sha512-xWSQnGDZ3v4NJ4CnSLCACSh9ZRb3cavCwydHnYGzZx0ARmWZpkjwWIiskHFuIYzzzBzTwAJBCfdWNumaWo/deg==", "dependencies": { "@prezly/progress-promise": "^2.0.1", "@prezly/uploads": "^0.2.1", @@ -18337,9 +18337,9 @@ "integrity": "sha512-uKBTA1gZ90ckKK/4wVoVORC3VUTkOgFwhZWwWsceKxVoAgDxqS5s0NXP5V7J+niEdvCkcoEVeCc25kCs+Hr/uQ==" }, "@prezly/sdk": { - "version": "16.5.0", - "resolved": "https://registry.npmjs.org/@prezly/sdk/-/sdk-16.5.0.tgz", - "integrity": "sha512-fOvMzHKIdSzMhMc4EYVb66ZsSvJhkX1SIfhGBB4SkhjxkqLFZ/XLgcqu1QEfc5/ROF39XfIXcLFkQadepZN//Q==", + "version": "16.7.0", + "resolved": "https://registry.npmjs.org/@prezly/sdk/-/sdk-16.7.0.tgz", + "integrity": "sha512-xWSQnGDZ3v4NJ4CnSLCACSh9ZRb3cavCwydHnYGzZx0ARmWZpkjwWIiskHFuIYzzzBzTwAJBCfdWNumaWo/deg==", "requires": { "@prezly/progress-promise": "^2.0.1", "@prezly/uploads": "^0.2.1", diff --git a/package.json b/package.json index fd68b7d70..cc197dfee 100644 --- a/package.json +++ b/package.json @@ -2,9 +2,7 @@ "name": "theme-kit", "version": "0.0.0", "private": true, - "workspaces": [ - "packages/*" - ], + "workspaces": ["packages/*"], "scripts": { "build": "npx lerna run build", "dev:core": "npx lerna run dev --scope=@prezly/theme-kit-core", @@ -30,7 +28,7 @@ "devDependencies": { "@playwright/test": "1.36.2", "@prezly/eslint-config": "4.5.0", - "@prezly/sdk": "16.5.0", + "@prezly/sdk": "16.7.0", "@types/jest": "29.5.3", "@types/node": "17.0.45", "@types/react": "18.2.18", diff --git a/packages/core/src/data-fetching/api/PrezlyApi.ts b/packages/core/src/data-fetching/api/PrezlyApi.ts index aa64d7e42..83306eec1 100644 --- a/packages/core/src/data-fetching/api/PrezlyApi.ts +++ b/packages/core/src/data-fetching/api/PrezlyApi.ts @@ -72,14 +72,14 @@ export class PrezlyApi { this.themeUuid = themeUuid; } - async getStory(uuid: string) { + async getStory(uuid: string, formats = [Story.FormatVersion.SLATEJS_V4]) { if (!isUuid(uuid)) { return undefined; } try { const story = await this.sdk.stories.get(uuid, { - formats: [Story.FormatVersion.SLATEJS_V4], + formats, }); return story; } catch (error) { @@ -200,11 +200,12 @@ export class PrezlyApi { return { stories, storiesTotal }; } - async getStoryBySlug(slug: string) { + async getStoryBySlug(slug: string, formats = [Story.FormatVersion.SLATEJS_V4]) { const query = JSON.stringify(getSlugQuery(this.newsroomUuid, slug)); const { stories } = await this.searchStories({ limit: 1, query, + formats, }); if (stories[0]) { @@ -230,8 +231,11 @@ export class PrezlyApi { ); } - searchStories: Stories.Client['search'] = (options) => - this.sdk.stories.search({ formats: [Story.FormatVersion.SLATEJS_V4], ...options }); + searchStories: Stories.Client['search'] = (options) => { + const formats = options?.formats ?? [Story.FormatVersion.SLATEJS_V4]; + + return this.sdk.stories.search({ ...options, formats }); + }; async getGalleries({ page, pageSize, type }: GetGalleriesOptions) { const { offset, limit } = toPaginationParams({ page, pageSize }); diff --git a/packages/nextjs/src/adapter-nextjs/page-props/story.ts b/packages/nextjs/src/adapter-nextjs/page-props/story.ts index 1385ec061..d21f3361c 100644 --- a/packages/nextjs/src/adapter-nextjs/page-props/story.ts +++ b/packages/nextjs/src/adapter-nextjs/page-props/story.ts @@ -1,3 +1,4 @@ +import type { Story } from '@prezly/sdk'; import type { GetServerSidePropsContext, GetServerSidePropsResult, @@ -16,6 +17,7 @@ import type { PropsFunction } from './lib/types'; export function getStoryPageServerSideProps>( customProps: CustomProps | PropsFunction, + formats?: Story.FormatVersion[], ) { return async function getServerSideProps( context: GetServerSidePropsContext, @@ -23,7 +25,7 @@ export function getStoryPageServerSideProps>( customProps: CustomProps | PropsFunction, + formats?: Story.FormatVersion[], ) { return async function getStaticProps( context: GetStaticPropsContext, @@ -60,7 +63,7 @@ export function getStoryPageStaticProps> const api = getNextPrezlyApi(); const { slug } = context.params as { slug?: string }; - const story = slug ? await api.getStoryBySlug(slug) : null; + const story = slug ? await api.getStoryBySlug(slug, formats) : null; if (!story) { return { notFound: true }; } diff --git a/packages/nextjs/src/adapter-nextjs/page-props/storyPreview.ts b/packages/nextjs/src/adapter-nextjs/page-props/storyPreview.ts index 52e023055..72501f8e0 100644 --- a/packages/nextjs/src/adapter-nextjs/page-props/storyPreview.ts +++ b/packages/nextjs/src/adapter-nextjs/page-props/storyPreview.ts @@ -1,3 +1,4 @@ +import type { Story } from '@prezly/sdk'; import type { GetServerSidePropsContext, GetServerSidePropsResult } from 'next'; import { getNextPrezlyApi } from '../../data-fetching'; @@ -11,10 +12,11 @@ export function getStoryPreviewPageServerSideProps> { const api = getNextPrezlyApi(context.req); const { uuid } = context.params as { uuid: string }; - const story = await api.getStory(uuid); + const story = await api.getStory(uuid, formats); if (!story) { return { notFound: true }; }