@prezly/theme-kit-nextjs 3.3.1 → 4.0.0-alpha.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.
Files changed (235) hide show
  1. package/README.md +5 -4
  2. package/build/adapter-nextjs/api-handlers/fetchGalleries.js +1 -1
  3. package/build/adapter-nextjs/api-handlers/fetchGalleries.js.map +1 -1
  4. package/build/adapter-nextjs/api-handlers/fetchStories.js +1 -1
  5. package/build/adapter-nextjs/api-handlers/fetchStories.js.map +1 -1
  6. package/build/adapter-nextjs/getNewsroomServerSideProps.d.ts +1 -1
  7. package/build/adapter-nextjs/getNewsroomServerSideProps.js +1 -1
  8. package/build/adapter-nextjs/getNewsroomServerSideProps.js.map +1 -1
  9. package/build/adapter-nextjs/getNewsroomStaticProps.d.ts +1 -1
  10. package/build/adapter-nextjs/getNewsroomStaticProps.js +1 -1
  11. package/build/adapter-nextjs/getNewsroomStaticProps.js.map +1 -1
  12. package/build/adapter-nextjs/page-props/category.js +6 -7
  13. package/build/adapter-nextjs/page-props/category.js.map +1 -1
  14. package/build/adapter-nextjs/page-props/gallery.js +3 -3
  15. package/build/adapter-nextjs/page-props/gallery.js.map +1 -1
  16. package/build/adapter-nextjs/page-props/galleryAlbum.js +1 -1
  17. package/build/adapter-nextjs/page-props/galleryAlbum.js.map +1 -1
  18. package/build/adapter-nextjs/page-props/home.js +3 -3
  19. package/build/adapter-nextjs/page-props/home.js.map +1 -1
  20. package/build/adapter-nextjs/page-props/sitemap/getServerSideProps.js +1 -1
  21. package/build/adapter-nextjs/page-props/sitemap/getServerSideProps.js.map +1 -1
  22. package/build/adapter-nextjs/page-props/story.js +3 -3
  23. package/build/adapter-nextjs/page-props/story.js.map +1 -1
  24. package/build/adapter-nextjs/page-props/storyPreview.js +1 -1
  25. package/build/adapter-nextjs/page-props/storyPreview.js.map +1 -1
  26. package/build/adapter-nextjs/processRequest.js +3 -2
  27. package/build/adapter-nextjs/processRequest.js.map +1 -1
  28. package/build/components-nextjs/PageSeo/PageSeo.js +8 -10
  29. package/build/components-nextjs/PageSeo/PageSeo.js.map +1 -1
  30. package/build/components-nextjs/PageSeo/index.d.ts +0 -1
  31. package/build/components-nextjs/PageSeo/index.js +0 -15
  32. package/build/components-nextjs/PageSeo/index.js.map +1 -1
  33. package/build/components-nextjs/PageSeo/lib/index.d.ts +1 -0
  34. package/build/components-nextjs/PageSeo/lib/index.js +6 -0
  35. package/build/components-nextjs/PageSeo/lib/index.js.map +1 -0
  36. package/build/components-nextjs/document.js +4 -4
  37. package/build/components-nextjs/document.js.map +1 -1
  38. package/build/data-fetching/NextPrezlyApi.d.ts +8 -0
  39. package/build/data-fetching/NextPrezlyApi.js +40 -0
  40. package/build/data-fetching/NextPrezlyApi.js.map +1 -0
  41. package/build/data-fetching/getNextPrezlyApi.d.ts +4 -0
  42. package/build/data-fetching/getNextPrezlyApi.js +21 -0
  43. package/build/data-fetching/getNextPrezlyApi.js.map +1 -0
  44. package/build/data-fetching/index.d.ts +1 -3
  45. package/build/data-fetching/index.js +3 -17
  46. package/build/data-fetching/index.js.map +1 -1
  47. package/build/index.d.ts +0 -2
  48. package/build/index.js +0 -2
  49. package/build/index.js.map +1 -1
  50. package/build/infinite-loading/useInfiniteStoriesLoading.js.map +1 -1
  51. package/build/intl/index.d.ts +0 -3
  52. package/build/intl/index.js +0 -8
  53. package/build/intl/index.js.map +1 -1
  54. package/build/intl/languages.d.ts +1 -44
  55. package/build/intl/languages.js +8 -151
  56. package/build/intl/languages.js.map +1 -1
  57. package/build/intl/locale.d.ts +0 -11
  58. package/build/intl/locale.js +3 -93
  59. package/build/intl/locale.js.map +1 -1
  60. package/build/newsroom-context/context.d.ts +2 -2
  61. package/build/newsroom-context/context.js +2 -2
  62. package/build/newsroom-context/context.js.map +1 -1
  63. package/build/newsroom-context/hooks/useAlgoliaSettings.d.ts +1 -1
  64. package/build/newsroom-context/hooks/useCurrentLocale.d.ts +1 -1
  65. package/build/newsroom-context/hooks/useGetLinkLocaleSlug.d.ts +1 -1
  66. package/build/newsroom-context/hooks/useGetLinkLocaleSlug.js +3 -3
  67. package/build/newsroom-context/hooks/useGetLinkLocaleSlug.js.map +1 -1
  68. package/build/newsroom-context/hooks/useGetTranslationUrl.d.ts +1 -1
  69. package/build/newsroom-context/hooks/useGetTranslationUrl.js +3 -3
  70. package/build/newsroom-context/hooks/useGetTranslationUrl.js.map +1 -1
  71. package/build/newsroom-context/index.d.ts +1 -1
  72. package/build/newsroom-context/index.js.map +1 -1
  73. package/build/types.d.ts +0 -29
  74. package/package.json +18 -33
  75. package/src/__mocks__/languages.ts +1 -1
  76. package/src/adapter-nextjs/api-handlers/fetchGalleries.ts +2 -2
  77. package/src/adapter-nextjs/api-handlers/fetchStories.ts +2 -2
  78. package/src/adapter-nextjs/getNewsroomServerSideProps.ts +2 -2
  79. package/src/adapter-nextjs/getNewsroomStaticProps.ts +2 -2
  80. package/src/adapter-nextjs/page-props/category.ts +3 -4
  81. package/src/adapter-nextjs/page-props/gallery.ts +1 -1
  82. package/src/adapter-nextjs/page-props/galleryAlbum.ts +2 -2
  83. package/src/adapter-nextjs/page-props/home.ts +1 -1
  84. package/src/adapter-nextjs/page-props/sitemap/getServerSideProps.ts +2 -2
  85. package/src/adapter-nextjs/page-props/story.ts +4 -4
  86. package/src/adapter-nextjs/page-props/storyPreview.ts +2 -2
  87. package/src/adapter-nextjs/processRequest.ts +2 -1
  88. package/src/components-nextjs/PageSeo/PageSeo.tsx +7 -5
  89. package/src/components-nextjs/PageSeo/index.ts +0 -1
  90. package/src/components-nextjs/PageSeo/lib/index.ts +1 -0
  91. package/src/components-nextjs/document.tsx +1 -1
  92. package/src/data-fetching/NextPrezlyApi.ts +57 -0
  93. package/src/data-fetching/{api/getPrezlyApi.ts → getNextPrezlyApi.ts} +5 -6
  94. package/src/data-fetching/index.ts +1 -3
  95. package/src/index.ts +0 -2
  96. package/src/infinite-loading/useInfiniteStoriesLoading.ts +1 -1
  97. package/src/intl/index.ts +0 -3
  98. package/src/intl/languages.test.ts +1 -196
  99. package/src/intl/languages.ts +8 -201
  100. package/src/intl/locale.test.ts +1 -54
  101. package/src/intl/locale.ts +1 -106
  102. package/src/newsroom-context/context.tsx +2 -3
  103. package/src/newsroom-context/hooks/useGetLinkLocaleSlug.ts +1 -2
  104. package/src/newsroom-context/hooks/useGetTranslationUrl.ts +2 -3
  105. package/src/newsroom-context/index.ts +1 -1
  106. package/src/types.ts +0 -35
  107. package/build/components-nextjs/PageSeo/lib/types.d.ts +0 -4
  108. package/build/components-nextjs/PageSeo/lib/types.js +0 -3
  109. package/build/components-nextjs/PageSeo/lib/types.js.map +0 -1
  110. package/build/data-fetching/api/PrezlyApi.d.ts +0 -57
  111. package/build/data-fetching/api/PrezlyApi.js +0 -200
  112. package/build/data-fetching/api/PrezlyApi.js.map +0 -1
  113. package/build/data-fetching/api/getPrezlyApi.d.ts +0 -4
  114. package/build/data-fetching/api/getPrezlyApi.js +0 -21
  115. package/build/data-fetching/api/getPrezlyApi.js.map +0 -1
  116. package/build/data-fetching/api/index.d.ts +0 -1
  117. package/build/data-fetching/api/index.js +0 -18
  118. package/build/data-fetching/api/index.js.map +0 -1
  119. package/build/data-fetching/api/lib.d.ts +0 -11
  120. package/build/data-fetching/api/lib.js +0 -20
  121. package/build/data-fetching/api/lib.js.map +0 -1
  122. package/build/data-fetching/api/queries.d.ts +0 -46
  123. package/build/data-fetching/api/queries.js +0 -56
  124. package/build/data-fetching/api/queries.js.map +0 -1
  125. package/build/data-fetching/lib/getAlgoliaSettings.d.ts +0 -4
  126. package/build/data-fetching/lib/getAlgoliaSettings.js +0 -22
  127. package/build/data-fetching/lib/getAlgoliaSettings.js.map +0 -1
  128. package/build/data-fetching/lib/getEnvVariables.d.ts +0 -4
  129. package/build/data-fetching/lib/getEnvVariables.js +0 -44
  130. package/build/data-fetching/lib/getEnvVariables.js.map +0 -1
  131. package/build/data-fetching/lib/index.d.ts +0 -4
  132. package/build/data-fetching/lib/index.js +0 -12
  133. package/build/data-fetching/lib/index.js.map +0 -1
  134. package/build/data-fetching/lib/isSdkError.d.ts +0 -2
  135. package/build/data-fetching/lib/isSdkError.js +0 -8
  136. package/build/data-fetching/lib/isSdkError.js.map +0 -1
  137. package/build/data-fetching/lib/isUuid.d.ts +0 -1
  138. package/build/data-fetching/lib/isUuid.js +0 -9
  139. package/build/data-fetching/lib/isUuid.js.map +0 -1
  140. package/build/data-fetching/types.d.ts +0 -13
  141. package/build/data-fetching/types.js +0 -3
  142. package/build/data-fetching/types.js.map +0 -1
  143. package/build/intl/getFallbackLocale.d.ts +0 -10
  144. package/build/intl/getFallbackLocale.js +0 -24
  145. package/build/intl/getFallbackLocale.js.map +0 -1
  146. package/build/intl/localeConfig.d.ts +0 -2
  147. package/build/intl/localeConfig.js +0 -20
  148. package/build/intl/localeConfig.js.map +0 -1
  149. package/build/intl/localeList.d.ts +0 -2
  150. package/build/intl/localeList.js +0 -112
  151. package/build/intl/localeList.js.map +0 -1
  152. package/build/intl/localeObject.d.ts +0 -50
  153. package/build/intl/localeObject.js +0 -98
  154. package/build/intl/localeObject.js.map +0 -1
  155. package/build/seo/getAlternateLanguageLinks.d.ts +0 -4
  156. package/build/seo/getAlternateLanguageLinks.js +0 -84
  157. package/build/seo/getAlternateLanguageLinks.js.map +0 -1
  158. package/build/seo/index.d.ts +0 -1
  159. package/build/seo/index.js +0 -18
  160. package/build/seo/index.js.map +0 -1
  161. package/build/seo/utils/bindLanguagesWithLocales.d.ts +0 -11
  162. package/build/seo/utils/bindLanguagesWithLocales.js +0 -23
  163. package/build/seo/utils/bindLanguagesWithLocales.js.map +0 -1
  164. package/build/seo/utils/createAlternateLanguageLink.d.ts +0 -5
  165. package/build/seo/utils/createAlternateLanguageLink.js +0 -15
  166. package/build/seo/utils/createAlternateLanguageLink.js.map +0 -1
  167. package/build/tsconfig.tsbuildinfo +0 -1
  168. package/build/utils/boilerplate.d.ts +0 -4
  169. package/build/utils/boilerplate.js +0 -27
  170. package/build/utils/boilerplate.js.map +0 -1
  171. package/build/utils/constants.d.ts +0 -3
  172. package/build/utils/constants.js +0 -7
  173. package/build/utils/constants.js.map +0 -1
  174. package/build/utils/getAssetsUrl.d.ts +0 -5
  175. package/build/utils/getAssetsUrl.js +0 -13
  176. package/build/utils/getAssetsUrl.js.map +0 -1
  177. package/build/utils/getDataRequestLink.d.ts +0 -3
  178. package/build/utils/getDataRequestLink.js +0 -12
  179. package/build/utils/getDataRequestLink.js.map +0 -1
  180. package/build/utils/getLocalizedCategoryData.d.ts +0 -10
  181. package/build/utils/getLocalizedCategoryData.js +0 -37
  182. package/build/utils/getLocalizedCategoryData.js.map +0 -1
  183. package/build/utils/getNewsroomLogoUrl.d.ts +0 -3
  184. package/build/utils/getNewsroomLogoUrl.js +0 -22
  185. package/build/utils/getNewsroomLogoUrl.js.map +0 -1
  186. package/build/utils/getPrivacyPortalUrl.d.ts +0 -8
  187. package/build/utils/getPrivacyPortalUrl.js +0 -13
  188. package/build/utils/getPrivacyPortalUrl.js.map +0 -1
  189. package/build/utils/getStoryPublicationDate.d.ts +0 -3
  190. package/build/utils/getStoryPublicationDate.js +0 -14
  191. package/build/utils/getStoryPublicationDate.js.map +0 -1
  192. package/build/utils/getUploadcareGroupUrl.d.ts +0 -8
  193. package/build/utils/getUploadcareGroupUrl.js +0 -17
  194. package/build/utils/getUploadcareGroupUrl.js.map +0 -1
  195. package/build/utils/index.d.ts +0 -10
  196. package/build/utils/index.js +0 -27
  197. package/build/utils/index.js.map +0 -1
  198. package/build/utils/isEmbargoStory.d.ts +0 -6
  199. package/build/utils/isEmbargoStory.js +0 -8
  200. package/build/utils/isEmbargoStory.js.map +0 -1
  201. package/src/@types/global.d.ts +0 -7
  202. package/src/__mocks__/story.ts +0 -359
  203. package/src/components-nextjs/PageSeo/lib/types.ts +0 -4
  204. package/src/data-fetching/api/PrezlyApi.ts +0 -312
  205. package/src/data-fetching/api/index.ts +0 -1
  206. package/src/data-fetching/api/lib.ts +0 -24
  207. package/src/data-fetching/api/queries.ts +0 -59
  208. package/src/data-fetching/lib/getAlgoliaSettings.ts +0 -29
  209. package/src/data-fetching/lib/getEnvVariables.ts +0 -46
  210. package/src/data-fetching/lib/index.ts +0 -4
  211. package/src/data-fetching/lib/isSdkError.ts +0 -5
  212. package/src/data-fetching/lib/isUuid.ts +0 -5
  213. package/src/data-fetching/types.ts +0 -14
  214. package/src/intl/getFallbackLocale.ts +0 -29
  215. package/src/intl/localeConfig.js +0 -23
  216. package/src/intl/localeList.js +0 -110
  217. package/src/intl/localeObject.test.ts +0 -81
  218. package/src/intl/localeObject.ts +0 -107
  219. package/src/seo/getAlternateLanguageLinks.test.ts +0 -164
  220. package/src/seo/getAlternateLanguageLinks.ts +0 -115
  221. package/src/seo/index.ts +0 -1
  222. package/src/seo/utils/bindLanguagesWithLocales.ts +0 -31
  223. package/src/seo/utils/createAlternateLanguageLink.ts +0 -17
  224. package/src/utils/boilerplate.ts +0 -30
  225. package/src/utils/constants.ts +0 -3
  226. package/src/utils/getAssetsUrl.test.ts +0 -9
  227. package/src/utils/getAssetsUrl.ts +0 -9
  228. package/src/utils/getDataRequestLink.ts +0 -14
  229. package/src/utils/getLocalizedCategoryData.ts +0 -47
  230. package/src/utils/getNewsroomLogoUrl.ts +0 -22
  231. package/src/utils/getPrivacyPortalUrl.ts +0 -25
  232. package/src/utils/getStoryPublicationDate.tsx +0 -15
  233. package/src/utils/getUploadcareGroupUrl.ts +0 -13
  234. package/src/utils/index.ts +0 -10
  235. package/src/utils/isEmbargoStory.ts +0 -10
@@ -1,312 +0,0 @@
1
- import { createPrezlyClient, SortOrder } from '@prezly/sdk';
2
- import type {
3
- Category,
4
- Newsroom,
5
- NewsroomLanguageSettings,
6
- PrezlyClient,
7
- Stories,
8
- Story,
9
- } from '@prezly/sdk';
10
- import type { IncomingMessage } from 'http';
11
-
12
- import {
13
- getCompanyInformation,
14
- getDefaultLanguage,
15
- getLanguageFromNextLocaleIsoCode,
16
- getLanguageFromStory,
17
- getNotifications,
18
- LocaleObject,
19
- } from '../../intl';
20
- import type { PageProps, ServerSidePageProps } from '../../types';
21
- import { DEFAULT_PAGE_SIZE } from '../../utils';
22
- import { getAlgoliaSettings, isSdkError, isUuid } from '../lib';
23
-
24
- import { toPaginationParams } from './lib';
25
- import {
26
- getChronologicalSortOrder,
27
- getContactsQuery,
28
- getGalleriesQuery,
29
- getSlugQuery,
30
- getStoriesQuery,
31
- } from './queries';
32
-
33
- const CATEGORIES_SORT_ORDER = '+order';
34
- const DEFAULT_SORT_ORDER = SortOrder.Direction.DESC;
35
-
36
- const ERROR_CODE_NOT_FOUND = 404;
37
- const ERROR_CODE_FORBIDDEN = 403;
38
- const ERROR_CODE_GONE = 410;
39
-
40
- interface GetStoriesOptions {
41
- page?: number;
42
- pageSize?: number;
43
- order?: `${SortOrder.Direction}`;
44
- pinning?: boolean;
45
- include?: (keyof Story.ExtraFields)[];
46
- localeCode?: string;
47
- /**
48
- * When set to `true`, the result for the first page will include one extra story to place as highlighted story.
49
- * This will offset each subsequent page by 1 story to account for that.
50
- */
51
- withHighlightedStory?: boolean;
52
- }
53
-
54
- interface GetGalleriesOptions {
55
- page?: number;
56
- pageSize?: number;
57
- }
58
-
59
- export class PrezlyApi {
60
- private readonly sdk: PrezlyClient;
61
-
62
- private readonly newsroomUuid: Newsroom['uuid'];
63
-
64
- private readonly themeUuid: string | undefined;
65
-
66
- constructor(accessToken: string, newsroomUuid: Newsroom['uuid'], themeUuid?: string) {
67
- const baseUrl = process.env.API_BASE_URL_OVERRIDE ?? undefined;
68
- this.sdk = createPrezlyClient({
69
- accessToken,
70
- baseUrl,
71
- // This returns stories created by legacy version of the editor in a format that can be displayed by the Prezly Content Renderer.
72
- headers: { 'X-Convert-v1-To-v3': 'true' },
73
- });
74
- this.newsroomUuid = newsroomUuid;
75
- this.themeUuid = themeUuid;
76
- }
77
-
78
- async getStory(uuid: string) {
79
- if (!isUuid(uuid)) {
80
- return undefined;
81
- }
82
-
83
- try {
84
- const story = await this.sdk.stories.get(uuid);
85
- return story;
86
- } catch (error) {
87
- if (
88
- isSdkError(error) &&
89
- (error.status === ERROR_CODE_NOT_FOUND ||
90
- error.status === ERROR_CODE_GONE ||
91
- error.status === ERROR_CODE_FORBIDDEN)
92
- ) {
93
- return null;
94
- }
95
- throw error;
96
- }
97
- }
98
-
99
- async getNewsroom() {
100
- return this.sdk.newsrooms.get(this.newsroomUuid);
101
- }
102
-
103
- async getNewsroomContacts() {
104
- return this.sdk.newsroomContacts.search(this.newsroomUuid, {
105
- query: JSON.stringify(getContactsQuery()),
106
- });
107
- }
108
-
109
- async getNewsroomLanguages(): Promise<NewsroomLanguageSettings[]> {
110
- return (await this.sdk.newsroomLanguages.list(this.newsroomUuid)).languages;
111
- }
112
-
113
- /**
114
- * Note: this method returns ALL stories from the newsroom. It's intended to be used for sitemaps and not to display actual content.
115
- */
116
- async getAllStories({ order = DEFAULT_SORT_ORDER, pinning = false }: GetStoriesOptions = {}) {
117
- const sortOrder = getChronologicalSortOrder(order, pinning);
118
- const newsroom = await this.getNewsroom();
119
- const query = JSON.stringify(getStoriesQuery(newsroom.uuid));
120
- const maxStories = newsroom.stories_number;
121
- const chunkSize = 200;
122
-
123
- const pages = Math.ceil(maxStories / chunkSize);
124
- const storiesPromises = Array.from({ length: pages }, (_, pageIndex) =>
125
- this.searchStories({
126
- limit: chunkSize,
127
- sortOrder,
128
- query,
129
- offset: pageIndex * chunkSize,
130
- }),
131
- );
132
-
133
- const stories = (await Promise.all(storiesPromises)).flatMap(
134
- (response) => response.stories,
135
- );
136
-
137
- return stories;
138
- }
139
-
140
- async getStories({
141
- page = undefined,
142
- pageSize = DEFAULT_PAGE_SIZE,
143
- order = DEFAULT_SORT_ORDER,
144
- pinning = false,
145
- include,
146
- localeCode,
147
- withHighlightedStory,
148
- }: GetStoriesOptions = {}) {
149
- const sortOrder = getChronologicalSortOrder(order, pinning);
150
- const query = JSON.stringify(getStoriesQuery(this.newsroomUuid, undefined, localeCode));
151
-
152
- const { offset, limit } = toPaginationParams({ page, pageSize, withHighlightedStory });
153
-
154
- const { stories, pagination } = await this.searchStories({
155
- limit,
156
- offset,
157
- sortOrder,
158
- query,
159
- include,
160
- });
161
-
162
- const storiesTotal = pagination.matched_records_number;
163
-
164
- return { stories, storiesTotal };
165
- }
166
-
167
- async getStoriesFromCategory(
168
- category: Category,
169
- {
170
- page = undefined,
171
- pageSize = DEFAULT_PAGE_SIZE,
172
- order = DEFAULT_SORT_ORDER,
173
- include,
174
- localeCode,
175
- }: Omit<GetStoriesOptions, 'pinning' | 'withHighlightedStory'> = {},
176
- ) {
177
- const sortOrder = getChronologicalSortOrder(order);
178
- const query = JSON.stringify(getStoriesQuery(this.newsroomUuid, category.id, localeCode));
179
-
180
- const { offset, limit } = toPaginationParams({ page, pageSize });
181
-
182
- const { stories, pagination } = await this.searchStories({
183
- limit,
184
- offset,
185
- sortOrder,
186
- query,
187
- include,
188
- });
189
-
190
- const storiesTotal = pagination.matched_records_number;
191
-
192
- return { stories, storiesTotal };
193
- }
194
-
195
- async getStoryBySlug(slug: string) {
196
- const query = JSON.stringify(getSlugQuery(this.newsroomUuid, slug));
197
- const { stories } = await this.searchStories({
198
- limit: 1,
199
- query,
200
- });
201
-
202
- if (stories[0]) {
203
- return this.getStory(stories[0].uuid);
204
- }
205
-
206
- return null;
207
- }
208
-
209
- async getCategories(): Promise<Category[]> {
210
- const categories = await this.sdk.newsroomCategories.list(this.newsroomUuid, {
211
- sortOrder: CATEGORIES_SORT_ORDER,
212
- });
213
-
214
- return Array.isArray(categories) ? categories : Object.values(categories);
215
- }
216
-
217
- async getCategoryBySlug(slug: string) {
218
- const categories = await this.getCategories();
219
-
220
- return categories.find((category) =>
221
- Object.values(category.i18n).some((t) => t.slug === slug),
222
- );
223
- }
224
-
225
- searchStories: Stories.Client['search'] = (options) => this.sdk.stories.search(options);
226
-
227
- async getGalleries({ page, pageSize }: GetGalleriesOptions) {
228
- const { offset, limit } = toPaginationParams({ page, pageSize });
229
-
230
- return this.sdk.newsroomGalleries.search(this.newsroomUuid, {
231
- limit,
232
- offset,
233
- scope: getGalleriesQuery(),
234
- });
235
- }
236
-
237
- async getGallery(uuid: string) {
238
- if (!isUuid(uuid)) {
239
- // Check for legacy number ID reference, which is also supported for back-compat.
240
- if (Number.isNaN(Number(uuid))) {
241
- return undefined;
242
- }
243
- }
244
-
245
- try {
246
- const gallery = await this.sdk.newsroomGalleries.get(this.newsroomUuid, uuid);
247
- return gallery;
248
- } catch (error) {
249
- if (isSdkError(error) && error.status === 404) {
250
- return null;
251
- }
252
- throw error;
253
- }
254
- }
255
-
256
- /**
257
- * In order to prevent issues with theme preview, we only load the theme preset for a specified theme, and not the currently active one.
258
- */
259
- async getThemePreset() {
260
- if (this.themeUuid) {
261
- return this.sdk.newsroomThemes.get(this.newsroomUuid, this.themeUuid);
262
- }
263
-
264
- return null;
265
- }
266
-
267
- async getNewsroomServerSideProps(
268
- request?: IncomingMessage,
269
- nextLocaleIsoCode?: string,
270
- story?: Story,
271
- ): Promise<PageProps & ServerSidePageProps> {
272
- const [newsroom, languages, categories, themePreset] = await Promise.all([
273
- this.getNewsroom(),
274
- this.getNewsroomLanguages(),
275
- this.getCategories(),
276
- this.getThemePreset(),
277
- ]);
278
-
279
- const currentLanguage = story
280
- ? getLanguageFromStory(languages, story)
281
- : getLanguageFromNextLocaleIsoCode(languages, nextLocaleIsoCode);
282
- const defaultLanguage = getDefaultLanguage(languages);
283
-
284
- const { code: localeCode } = currentLanguage || defaultLanguage;
285
- const locale = LocaleObject.fromAnyCode(localeCode);
286
-
287
- // TODO: if no information given for current language, show boilerplate from default language
288
- const companyInformation = getCompanyInformation(languages, locale);
289
-
290
- const notifications = getNotifications(languages, locale);
291
- const algoliaSettings = getAlgoliaSettings(request);
292
-
293
- return {
294
- newsroomContextProps: {
295
- newsroom,
296
- companyInformation,
297
- categories,
298
- languages,
299
- localeCode,
300
- notifications,
301
- themePreset,
302
- algoliaSettings,
303
- },
304
- localeResolved: Boolean(currentLanguage),
305
- };
306
- }
307
-
308
- async getNewsroomDefaultLanguage() {
309
- const languages = await this.getNewsroomLanguages();
310
- return getDefaultLanguage(languages);
311
- }
312
- }
@@ -1 +0,0 @@
1
- export * from './getPrezlyApi';
@@ -1,24 +0,0 @@
1
- export function toPaginationParams(params: {
2
- page?: number;
3
- pageSize?: number;
4
- withHighlightedStory?: boolean;
5
- }) {
6
- const { page = 1, pageSize, withHighlightedStory = false } = params;
7
-
8
- if (!pageSize) {
9
- return { offset: undefined, limit: undefined };
10
- }
11
-
12
- const offset = pageSize * (page - 1);
13
- const limit = pageSize;
14
-
15
- if (withHighlightedStory && page === 1) {
16
- return { offset: 0, limit: limit + 1 };
17
- }
18
-
19
- if (withHighlightedStory && page > 1) {
20
- return { offset: offset + 1, limit };
21
- }
22
-
23
- return { offset, limit };
24
- }
@@ -1,59 +0,0 @@
1
- import { SortOrder } from '@prezly/sdk';
2
-
3
- const publishedAndAccessible = [
4
- { lifecycle_status: { $in: ['published', 'embargo'] } },
5
- { visibility: { $in: ['public', 'private', 'embargo'] } },
6
- ];
7
-
8
- const publishedAndPublic = [
9
- { lifecycle_status: { $in: ['published'] } },
10
- { visibility: { $in: ['public'] } },
11
- ];
12
-
13
- export function getSlugQuery(newsroomUuid: string, slug: string) {
14
- return {
15
- $and: [
16
- { 'newsroom.uuid': { $in: [newsroomUuid] } },
17
- { slug: { $eq: slug } },
18
- ...publishedAndAccessible,
19
- ],
20
- };
21
- }
22
-
23
- export function getStoriesQuery(newsroomUuid: string, categoryId?: number, localeCode?: string) {
24
- const query: any = {
25
- $and: [...publishedAndPublic, { 'newsroom.uuid': { $in: [newsroomUuid] } }],
26
- };
27
-
28
- if (categoryId) {
29
- query.$and.push({ 'category.id': { $any: [categoryId] } });
30
- }
31
-
32
- if (localeCode) {
33
- query.$and.push({ locale: { $in: [localeCode] } });
34
- }
35
-
36
- return query;
37
- }
38
-
39
- export function getChronologicalSortOrder(direction: `${SortOrder.Direction}`, pinning = false) {
40
- const pinnedFirst = SortOrder.desc('is_pinned');
41
- const chronological =
42
- direction === SortOrder.Direction.ASC
43
- ? SortOrder.asc('published_at')
44
- : SortOrder.desc('published_at');
45
-
46
- return pinning ? SortOrder.combine(pinnedFirst, chronological) : chronological;
47
- }
48
-
49
- export function getGalleriesQuery() {
50
- return {
51
- $and: [{ status: { $eq: 'public' } }, { images_number: { $gt: 0 } }],
52
- };
53
- }
54
-
55
- export function getContactsQuery() {
56
- return {
57
- $and: [{ is_featured: { $eq: true } }],
58
- };
59
- }
@@ -1,29 +0,0 @@
1
- import type { IncomingMessage } from 'http';
2
-
3
- import type { AlgoliaSettings } from '../types';
4
-
5
- import { getEnvVariables } from './getEnvVariables';
6
-
7
- export function getAlgoliaSettings(req?: IncomingMessage): AlgoliaSettings {
8
- if (typeof window !== 'undefined') {
9
- throw new Error('"getAlgoliaSettings" should only be used on back-end side.');
10
- }
11
-
12
- // `getEnvVariables` handles both cases for envs parsing - .env and request headers
13
- const {
14
- ALGOLIA_API_KEY = '',
15
- ALGOLIA_APP_ID = 'UI4CNRAHQB',
16
- ALGOLIA_INDEX = 'public_stories_prod',
17
- } = getEnvVariables(req);
18
-
19
- if (!ALGOLIA_API_KEY) {
20
- // eslint-disable-next-line no-console
21
- console.error('"ALGOLIA_API_KEY" is not set in env variables. Search will not be enabled');
22
- }
23
-
24
- return {
25
- ALGOLIA_API_KEY,
26
- ALGOLIA_APP_ID,
27
- ALGOLIA_INDEX,
28
- };
29
- }
@@ -1,46 +0,0 @@
1
- import type { IncomingMessage } from 'http';
2
- import parseDataUrl from 'parse-data-url';
3
-
4
- import type { PrezlyEnv } from '../types';
5
-
6
- function decodeJson(json: string): Record<string, any> {
7
- try {
8
- const decoded = JSON.parse(json);
9
- if (decoded && typeof decoded === 'object') {
10
- return decoded;
11
- }
12
- } catch {
13
- // passthru
14
- }
15
- return {};
16
- }
17
-
18
- function decodeHttpEnv(header: string): Record<string, any> {
19
- if (header.startsWith('data:')) {
20
- const parsed = parseDataUrl(header);
21
- if (parsed && parsed.contentType === 'application/json') {
22
- const data = parsed.toBuffer().toString('utf-8');
23
- return decodeJson(data);
24
- }
25
- return {}; // unsupported data-uri
26
- }
27
- return decodeJson(header);
28
- }
29
-
30
- export function getEnvVariables<EnvType extends PrezlyEnv = PrezlyEnv>(
31
- req?: IncomingMessage,
32
- ): NodeJS.ProcessEnv & EnvType {
33
- if (typeof window !== 'undefined') {
34
- throw new Error('"getEnvVariables" should only be used on back-end side.');
35
- }
36
-
37
- const headerName = (process.env.HTTP_ENV_HEADER || '').toLowerCase();
38
-
39
- if (headerName && req) {
40
- const header = req.headers[headerName] as string | undefined;
41
- const httpEnv = decodeHttpEnv(header || '');
42
- return { ...process.env, ...httpEnv } as NodeJS.ProcessEnv & EnvType;
43
- }
44
-
45
- return { ...process.env } as NodeJS.ProcessEnv & EnvType;
46
- }
@@ -1,4 +0,0 @@
1
- export { getAlgoliaSettings } from './getAlgoliaSettings';
2
- export { getEnvVariables } from './getEnvVariables';
3
- export { isSdkError } from './isSdkError';
4
- export { isUuid } from './isUuid';
@@ -1,5 +0,0 @@
1
- import type { SdkError } from '../../types';
2
-
3
- export function isSdkError(error: any): error is SdkError {
4
- return 'payload' in error;
5
- }
@@ -1,5 +0,0 @@
1
- const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
2
-
3
- export function isUuid(input: string) {
4
- return UUID_REGEX.test(input);
5
- }
@@ -1,14 +0,0 @@
1
- export interface AlgoliaSettings {
2
- ALGOLIA_API_KEY: string;
3
- ALGOLIA_APP_ID: string;
4
- ALGOLIA_INDEX: string;
5
- }
6
-
7
- export interface PrezlyNewsroomEnv {
8
- PREZLY_ACCESS_TOKEN: string;
9
- PREZLY_NEWSROOM_UUID: string;
10
- PREZLY_THEME_UUID?: string;
11
- PREZLY_MODE?: 'preview';
12
- }
13
-
14
- export interface PrezlyEnv extends PrezlyNewsroomEnv, AlgoliaSettings {}
@@ -1,29 +0,0 @@
1
- import type { LangCode } from './locale';
2
- import { LocaleObject } from './localeObject';
3
-
4
- const localeFallback: Record<LangCode, LocaleObject[]> = {
5
- en: [LocaleObject.fromAnyCode('en-US'), LocaleObject.fromAnyCode('en-GB')],
6
- fr: [LocaleObject.fromAnyCode('fr-FR'), LocaleObject.fromAnyCode('fr-CA')],
7
- };
8
-
9
- /**
10
- * Fallback locales for each region independent locale.
11
- * For example, a story has en-CA en-AU and en-GB locales. As you can see there is no region independent locale.
12
- * We will use a list of possible fallbacks to determine region independent locale alias.
13
- * In the provided example the result will be en-GB since it is defined in the localeFallback list
14
- * If the list will be en-CA en-AU and en-US then the result will be en-US since it is the first one and hence takes precedence.
15
- */
16
- export function getFallbackLocale(
17
- langCode: LangCode,
18
- availableLocales: LocaleObject[],
19
- ): LocaleObject | undefined {
20
- const fallbacks = localeFallback[langCode];
21
-
22
- if (!fallbacks) {
23
- return undefined;
24
- }
25
-
26
- return fallbacks.find((fallback) =>
27
- Boolean(availableLocales.find((available) => available.isEqual(fallback))),
28
- );
29
- }
@@ -1,23 +0,0 @@
1
- /**
2
- * This list is pulled from the main Prezly application. The underscores are replaced with dashes.
3
- * Together with permutation performed lower in the code,
4
- * the exported list represents all of the possible locale codes that Next.js theme application might accept.
5
- */
6
- const supportedLocales = require('./localeList');
7
-
8
- const lowercaseLocales = supportedLocales.map((l) => l.toLowerCase());
9
-
10
- // Get all permutations for the shorter locale codes supported by Prezly (e.g. short region codes and neutral language codes)
11
- const lowercaseLocalPermutations = Array.from(
12
- new Set([
13
- ...lowercaseLocales,
14
- ...lowercaseLocales.map((code) => code.split('-')[0]),
15
- ...lowercaseLocales
16
- .map((code) => code.split('-')[1])
17
- .filter(Boolean)
18
- // Remove number-only codes from possible permutations (like `419` for `es-419`)
19
- .filter((code) => Number.isNaN(Number(code))),
20
- ]),
21
- ).sort();
22
-
23
- module.exports = lowercaseLocalPermutations;
@@ -1,110 +0,0 @@
1
- /**
2
- * This list is pulled from the main Prezly application. The underscores are replaced with dashes.
3
- */
4
- module.exports = [
5
- 'af-ZA',
6
- 'ar',
7
- 'ar-AE',
8
- 'ar-BH',
9
- 'ar-QA',
10
- 'ar-SA',
11
- 'az',
12
- 'be',
13
- 'bg-BG',
14
- 'ca',
15
- 'cs-CZ',
16
- 'da-DK',
17
- 'de',
18
- 'de-DE',
19
- 'de-BE',
20
- 'de-AT',
21
- 'de-CH',
22
- 'el-GR',
23
- 'en',
24
- 'en-US',
25
- 'en-AE',
26
- 'en-AU',
27
- 'en-BD',
28
- 'en-BE',
29
- 'en-BH',
30
- 'en-CA',
31
- 'en-CN',
32
- 'en-DE',
33
- 'en-DK',
34
- 'en-GB',
35
- 'en-HK',
36
- 'en-ID',
37
- 'en-IE',
38
- 'en-IL',
39
- 'en-IN',
40
- 'en-JM',
41
- 'en-JP',
42
- 'en-KH',
43
- 'en-KR',
44
- 'en-LK',
45
- 'en-MV',
46
- 'en-MM',
47
- 'en-MY',
48
- 'en-NP',
49
- 'en-NZ',
50
- 'en-PH',
51
- 'en-PK',
52
- 'en-QA',
53
- 'en-SA',
54
- 'en-SG',
55
- 'en-TH',
56
- 'en-TW',
57
- 'en-VN',
58
- 'en-ZA',
59
- 'es',
60
- 'es-ES',
61
- 'es-MX',
62
- 'et-EE',
63
- 'es-419',
64
- 'fi-FI',
65
- 'fil',
66
- 'fr',
67
- 'fr-BE',
68
- 'fr-FR',
69
- 'fr-CA',
70
- 'fr-LU',
71
- 'ga-IE',
72
- 'he-IL',
73
- 'hi-IN',
74
- 'hr-HR',
75
- 'hu-HU',
76
- 'id-ID',
77
- 'it-IT',
78
- 'ja-JP',
79
- 'kk',
80
- 'ko-KR',
81
- 'ky',
82
- 'lt-LT',
83
- 'lv-LV',
84
- 'mt-MT',
85
- 'ms-MY',
86
- 'nb-NO',
87
- 'nl',
88
- 'nl-BE',
89
- 'nl-NL',
90
- 'pl-PL',
91
- 'pt',
92
- 'pt-BR',
93
- 'pt-PT',
94
- 'ro-RO',
95
- 'ru-RU',
96
- 'sk-SK',
97
- 'sl-SI',
98
- 'sv-SE',
99
- 'sw',
100
- 'th-TH',
101
- 'tr-TR',
102
- 'uk-UA',
103
- 'ur-PK',
104
- 'uz',
105
- 'vi-VN',
106
- 'zh-Hant',
107
- 'zh-HK',
108
- 'zh-TW',
109
- 'zh-CN',
110
- ];