@prezly/theme-kit-nextjs 2.0.0-0 → 2.0.0-1

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 (86) hide show
  1. package/build/@types/global.d.js +1 -0
  2. package/build/adapter-nextjs/api-handlers/fetchGalleries.js +26 -18
  3. package/build/adapter-nextjs/api-handlers/fetchStories.js +36 -20
  4. package/build/adapter-nextjs/api-handlers/index.js +2 -3
  5. package/build/adapter-nextjs/getNewsroomServerSideProps.js +15 -10
  6. package/build/adapter-nextjs/getNewsroomStaticProps.js +14 -10
  7. package/build/adapter-nextjs/index.js +6 -7
  8. package/build/adapter-nextjs/page-props/category.js +115 -91
  9. package/build/adapter-nextjs/page-props/gallery.js +85 -61
  10. package/build/adapter-nextjs/page-props/galleryAlbum.js +61 -44
  11. package/build/adapter-nextjs/page-props/home.js +81 -62
  12. package/build/adapter-nextjs/page-props/index.js +8 -9
  13. package/build/adapter-nextjs/page-props/lib/types.js +1 -2
  14. package/build/adapter-nextjs/page-props/search.js +23 -24
  15. package/build/adapter-nextjs/page-props/sitemap/SitemapBuilder.js +28 -45
  16. package/build/adapter-nextjs/page-props/sitemap/createPaths.js +12 -14
  17. package/build/adapter-nextjs/page-props/sitemap/getServerSideProps.js +32 -30
  18. package/build/adapter-nextjs/page-props/sitemap/index.js +4 -5
  19. package/build/adapter-nextjs/page-props/sitemap/types.js +1 -2
  20. package/build/adapter-nextjs/page-props/story.js +74 -55
  21. package/build/adapter-nextjs/page-props/storyPreview.js +26 -21
  22. package/build/adapter-nextjs/processRequest.js +33 -20
  23. package/build/adapter-nextjs/processStaticRequest.js +18 -11
  24. package/build/components-nextjs/PageSeo/PageSeo.js +81 -71
  25. package/build/components-nextjs/PageSeo/index.js +2 -3
  26. package/build/components-nextjs/PageSeo/lib/getAbsoluteUrl.js +4 -5
  27. package/build/components-nextjs/PageSeo/lib/types.js +1 -2
  28. package/build/components-nextjs/StorySeo/StorySeo.js +67 -41
  29. package/build/components-nextjs/StorySeo/index.js +1 -2
  30. package/build/components-nextjs/document.js +29 -19
  31. package/build/components-nextjs/index.js +3 -4
  32. package/build/data-fetching/api/PrezlyApi.js +205 -185
  33. package/build/data-fetching/api/getPrezlyApi.js +20 -16
  34. package/build/data-fetching/api/index.js +1 -2
  35. package/build/data-fetching/api/queries.js +71 -34
  36. package/build/data-fetching/index.js +3 -4
  37. package/build/data-fetching/lib/getAlgoliaSettings.js +21 -17
  38. package/build/data-fetching/lib/getEnvVariables.js +33 -29
  39. package/build/data-fetching/lib/index.js +4 -5
  40. package/build/data-fetching/lib/isSdkError.js +2 -3
  41. package/build/data-fetching/lib/isUuid.js +2 -3
  42. package/build/data-fetching/types.js +1 -2
  43. package/build/index.js +9 -10
  44. package/build/infinite-loading/index.js +4 -5
  45. package/build/infinite-loading/types.js +1 -2
  46. package/build/infinite-loading/useInfiniteGalleriesLoading.js +41 -32
  47. package/build/infinite-loading/useInfiniteLoading.js +48 -37
  48. package/build/infinite-loading/useInfiniteStoriesLoading.js +54 -44
  49. package/build/intl/index.js +4 -5
  50. package/build/intl/languages.js +135 -97
  51. package/build/intl/locale.js +46 -95
  52. package/build/intl/localeConfig.js +7 -13
  53. package/build/intl/localeList.js +1 -108
  54. package/build/intl/localeObject.js +79 -74
  55. package/build/newsroom-context/context.js +34 -20
  56. package/build/newsroom-context/hooks/index.js +11 -12
  57. package/build/newsroom-context/hooks/useAlgoliaSettings.js +4 -5
  58. package/build/newsroom-context/hooks/useCategories.js +4 -5
  59. package/build/newsroom-context/hooks/useCompanyInformation.js +4 -5
  60. package/build/newsroom-context/hooks/useCurrentCategory.js +4 -5
  61. package/build/newsroom-context/hooks/useCurrentLocale.js +4 -5
  62. package/build/newsroom-context/hooks/useCurrentStory.js +4 -5
  63. package/build/newsroom-context/hooks/useGetLinkLocaleSlug.js +15 -15
  64. package/build/newsroom-context/hooks/useGetTranslationUrl.js +48 -44
  65. package/build/newsroom-context/hooks/useLanguages.js +4 -5
  66. package/build/newsroom-context/hooks/useNewsroom.js +4 -5
  67. package/build/newsroom-context/hooks/useNewsroomContext.js +9 -10
  68. package/build/newsroom-context/index.js +2 -3
  69. package/build/sentry/client.js +3 -4
  70. package/build/sentry/common.js +25 -24
  71. package/build/sentry/index.js +2 -3
  72. package/build/sentry/server.js +3 -4
  73. package/build/types.js +1 -2
  74. package/build/utils/boilerplate.js +4 -13
  75. package/build/utils/constants.js +1 -2
  76. package/build/utils/getAssetsUrl.js +3 -4
  77. package/build/utils/getDataRequestLink.js +5 -7
  78. package/build/utils/getLocalizedCategoryData.js +30 -24
  79. package/build/utils/getNewsroomLogoUrl.js +12 -13
  80. package/build/utils/getPrivacyPortalUrl.js +10 -8
  81. package/build/utils/getStoryPublicationDate.js +8 -9
  82. package/build/utils/getUploadcareGroupUrl.js +4 -5
  83. package/build/utils/index.js +10 -11
  84. package/build/utils/isEmbargoStory.js +2 -3
  85. package/package.json +10 -2
  86. package/build/tsconfig.tsbuildinfo +0 -1
@@ -1,4 +1,3 @@
1
- export { PageSeo } from './PageSeo';
2
- export { StorySeo } from './StorySeo';
3
- export { PrezlyThemeDocument } from './document';
4
- //# sourceMappingURL=index.js.map
1
+ export { PageSeo } from "./PageSeo/index.js";
2
+ export { StorySeo } from "./StorySeo/index.js";
3
+ export { PrezlyThemeDocument } from "./document.js";
@@ -1,194 +1,214 @@
1
1
  import { createPrezlyClient } from '@prezly/sdk';
2
- import { getCompanyInformation, getDefaultLanguage, getLanguageFromNextLocaleIsoCode, getLanguageFromStory, getNotifications, LocaleObject, } from '../../intl';
3
- import { DEFAULT_PAGE_SIZE } from '../../utils';
4
- import { getAlgoliaSettings, isSdkError, isUuid } from '../lib';
5
- import { getContactsQuery, getGalleriesQuery, getSlugQuery, getSortByPublishedDate, getStoriesQuery, } from './queries';
2
+ import { getCompanyInformation, getDefaultLanguage, getLanguageFromNextLocaleIsoCode, getLanguageFromStory, getNotifications, LocaleObject } from "../../intl/index.js";
3
+ import { DEFAULT_PAGE_SIZE } from "../../utils/index.js";
4
+ import { getAlgoliaSettings, isSdkError, isUuid } from "../lib/index.js";
5
+ import { getContactsQuery, getGalleriesQuery, getSlugQuery, getSortByPublishedDate, getStoriesQuery } from "./queries.js";
6
6
  const CATEGORIES_SORT_ORDER = '+order';
7
7
  const DEFAULT_SORT_ORDER = 'desc';
8
8
  const ERROR_CODE_NOT_FOUND = 404;
9
9
  const ERROR_CODE_FORBIDDEN = 403;
10
10
  const ERROR_CODE_GONE = 410;
11
11
  export class PrezlyApi {
12
- sdk;
13
- newsroomUuid;
14
- themeUuid;
15
- constructor(accessToken, newsroomUuid, themeUuid) {
16
- const baseUrl = process.env.API_BASE_URL_OVERRIDE ?? undefined;
17
- this.sdk = createPrezlyClient({
18
- accessToken,
19
- baseUrl,
20
- // This returns stories created by legacy version of the editor in a format that can be displayed by the Prezly Content Renderer.
21
- headers: { 'X-Convert-v1-To-v3': 'true' },
22
- });
23
- this.newsroomUuid = newsroomUuid;
24
- this.themeUuid = themeUuid;
25
- }
26
- async getStory(uuid) {
27
- if (!isUuid(uuid)) {
28
- return undefined;
29
- }
30
- try {
31
- const story = await this.sdk.stories.get(uuid);
32
- return story;
33
- }
34
- catch (error) {
35
- if (isSdkError(error) &&
36
- (error.status === ERROR_CODE_NOT_FOUND ||
37
- error.status === ERROR_CODE_GONE ||
38
- error.status === ERROR_CODE_FORBIDDEN)) {
39
- return null;
40
- }
41
- throw error;
42
- }
43
- }
44
- async getNewsroom() {
45
- return this.sdk.newsrooms.get(this.newsroomUuid);
46
- }
47
- async getNewsroomContacts() {
48
- return this.sdk.newsroomContacts.search(this.newsroomUuid, {
49
- query: JSON.stringify(getContactsQuery()),
50
- });
51
- }
52
- async getNewsroomLanguages() {
53
- return (await this.sdk.newsroomLanguages.list(this.newsroomUuid)).languages;
54
- }
55
- /**
56
- * Note: this method returns ALL stories from the newsroom. It's intended to be used for sitemaps and not to display actual content.
57
- */
58
- async getAllStories(order = DEFAULT_SORT_ORDER) {
59
- const sortOrder = getSortByPublishedDate(order);
60
- const newsroom = await this.getNewsroom();
61
- const query = JSON.stringify(getStoriesQuery(newsroom.uuid));
62
- const maxStories = newsroom.stories_number;
63
- const chunkSize = 200;
64
- const pages = Math.ceil(maxStories / chunkSize);
65
- const storiesPromises = Array.from({ length: pages }, (_, pageIndex) => this.searchStories({
66
- limit: chunkSize,
67
- sortOrder,
68
- query,
69
- offset: pageIndex * chunkSize,
70
- }));
71
- const stories = (await Promise.all(storiesPromises)).flatMap((response) => response.stories);
72
- return stories;
73
- }
74
- async getStories({ page = undefined, pageSize = DEFAULT_PAGE_SIZE, order = DEFAULT_SORT_ORDER, include, localeCode, } = {}) {
75
- const sortOrder = getSortByPublishedDate(order);
76
- const query = JSON.stringify(getStoriesQuery(this.newsroomUuid, undefined, localeCode));
77
- const { stories, pagination } = await this.searchStories({
78
- limit: pageSize,
79
- offset: typeof page === 'undefined' ? undefined : (page - 1) * pageSize,
80
- sortOrder,
81
- query,
82
- include,
83
- });
84
- const storiesTotal = pagination.matched_records_number;
85
- return { stories, storiesTotal };
86
- }
87
- async getStoriesFromCategory(category, { page = undefined, pageSize = DEFAULT_PAGE_SIZE, order = DEFAULT_SORT_ORDER, include, localeCode, } = {}) {
88
- const sortOrder = getSortByPublishedDate(order);
89
- const query = JSON.stringify(getStoriesQuery(this.newsroomUuid, category.id, localeCode));
90
- const { stories, pagination } = await this.searchStories({
91
- limit: pageSize,
92
- offset: typeof page === 'undefined' ? undefined : (page - 1) * pageSize,
93
- sortOrder,
94
- query,
95
- include,
96
- });
97
- const storiesTotal = pagination.matched_records_number;
98
- return { stories, storiesTotal };
99
- }
100
- async getStoryBySlug(slug) {
101
- const query = JSON.stringify(getSlugQuery(this.newsroomUuid, slug));
102
- const { stories } = await this.searchStories({
103
- limit: 1,
104
- query,
105
- });
106
- if (stories[0]) {
107
- return this.getStory(stories[0].uuid);
108
- }
12
+ constructor(accessToken, newsroomUuid, themeUuid) {
13
+ const baseUrl = process.env.API_BASE_URL_OVERRIDE ?? undefined;
14
+ this.sdk = createPrezlyClient({
15
+ accessToken,
16
+ baseUrl,
17
+ // This returns stories created by legacy version of the editor in a format that can be displayed by the Prezly Content Renderer.
18
+ headers: {
19
+ 'X-Convert-v1-To-v3': 'true'
20
+ }
21
+ });
22
+ this.newsroomUuid = newsroomUuid;
23
+ this.themeUuid = themeUuid;
24
+ }
25
+ async getStory(uuid) {
26
+ if (!isUuid(uuid)) {
27
+ return undefined;
28
+ }
29
+ try {
30
+ const story = await this.sdk.stories.get(uuid);
31
+ return story;
32
+ } catch (error) {
33
+ if (isSdkError(error) && (error.status === ERROR_CODE_NOT_FOUND || error.status === ERROR_CODE_GONE || error.status === ERROR_CODE_FORBIDDEN)) {
109
34
  return null;
110
- }
111
- async getCategories() {
112
- const categories = await this.sdk.newsroomCategories.list(this.newsroomUuid, {
113
- sortOrder: CATEGORIES_SORT_ORDER,
114
- });
115
- return Array.isArray(categories) ? categories : Object.values(categories);
116
- }
117
- async getCategoryBySlug(slug) {
118
- const categories = await this.getCategories();
119
- return categories.find((category) => Object.values(category.i18n).some((t) => t.slug === slug));
120
- }
121
- searchStories = (options) => this.sdk.stories.search(options);
122
- async getGalleries({ page, pageSize }) {
123
- return this.sdk.newsroomGalleries.search(this.newsroomUuid, {
124
- limit: pageSize,
125
- offset: typeof page === 'undefined' || typeof pageSize === 'undefined'
126
- ? undefined
127
- : (page - 1) * pageSize,
128
- query: getGalleriesQuery(),
129
- });
130
- }
131
- async getGallery(uuid) {
132
- if (!isUuid(uuid)) {
133
- // Check for legacy number ID reference, which is also supported for back-compat.
134
- if (Number.isNaN(Number(uuid))) {
135
- return undefined;
136
- }
137
- }
138
- try {
139
- const gallery = await this.sdk.newsroomGalleries.get(this.newsroomUuid, uuid);
140
- return gallery;
141
- }
142
- catch (error) {
143
- if (isSdkError(error) && error.status === 404) {
144
- return null;
145
- }
146
- throw error;
147
- }
148
- }
149
- /**
150
- * In order to prevent issues with theme preview, we only load the theme preset for a specified theme, and not the currently active one.
151
- */
152
- async getThemePreset() {
153
- if (this.themeUuid) {
154
- return this.sdk.newsroomThemes.get(this.newsroomUuid, this.themeUuid);
155
- }
35
+ }
36
+ throw error;
37
+ }
38
+ }
39
+ async getNewsroom() {
40
+ return this.sdk.newsrooms.get(this.newsroomUuid);
41
+ }
42
+ async getNewsroomContacts() {
43
+ return this.sdk.newsroomContacts.search(this.newsroomUuid, {
44
+ query: JSON.stringify(getContactsQuery())
45
+ });
46
+ }
47
+ async getNewsroomLanguages() {
48
+ return (await this.sdk.newsroomLanguages.list(this.newsroomUuid)).languages;
49
+ }
50
+
51
+ /**
52
+ * Note: this method returns ALL stories from the newsroom. It's intended to be used for sitemaps and not to display actual content.
53
+ */
54
+ async getAllStories(order = DEFAULT_SORT_ORDER) {
55
+ const sortOrder = getSortByPublishedDate(order);
56
+ const newsroom = await this.getNewsroom();
57
+ const query = JSON.stringify(getStoriesQuery(newsroom.uuid));
58
+ const maxStories = newsroom.stories_number;
59
+ const chunkSize = 200;
60
+ const pages = Math.ceil(maxStories / chunkSize);
61
+ const storiesPromises = Array.from({
62
+ length: pages
63
+ }, (_, pageIndex) => this.searchStories({
64
+ limit: chunkSize,
65
+ sortOrder,
66
+ query,
67
+ offset: pageIndex * chunkSize
68
+ }));
69
+ const stories = (await Promise.all(storiesPromises)).flatMap(response => response.stories);
70
+ return stories;
71
+ }
72
+ async getStories({
73
+ page = undefined,
74
+ pageSize = DEFAULT_PAGE_SIZE,
75
+ order = DEFAULT_SORT_ORDER,
76
+ include,
77
+ localeCode
78
+ } = {}) {
79
+ const sortOrder = getSortByPublishedDate(order);
80
+ const query = JSON.stringify(getStoriesQuery(this.newsroomUuid, undefined, localeCode));
81
+ const {
82
+ stories,
83
+ pagination
84
+ } = await this.searchStories({
85
+ limit: pageSize,
86
+ offset: typeof page === 'undefined' ? undefined : (page - 1) * pageSize,
87
+ sortOrder,
88
+ query,
89
+ include
90
+ });
91
+ const storiesTotal = pagination.matched_records_number;
92
+ return {
93
+ stories,
94
+ storiesTotal
95
+ };
96
+ }
97
+ async getStoriesFromCategory(category, {
98
+ page = undefined,
99
+ pageSize = DEFAULT_PAGE_SIZE,
100
+ order = DEFAULT_SORT_ORDER,
101
+ include,
102
+ localeCode
103
+ } = {}) {
104
+ const sortOrder = getSortByPublishedDate(order);
105
+ const query = JSON.stringify(getStoriesQuery(this.newsroomUuid, category.id, localeCode));
106
+ const {
107
+ stories,
108
+ pagination
109
+ } = await this.searchStories({
110
+ limit: pageSize,
111
+ offset: typeof page === 'undefined' ? undefined : (page - 1) * pageSize,
112
+ sortOrder,
113
+ query,
114
+ include
115
+ });
116
+ const storiesTotal = pagination.matched_records_number;
117
+ return {
118
+ stories,
119
+ storiesTotal
120
+ };
121
+ }
122
+ async getStoryBySlug(slug) {
123
+ const query = JSON.stringify(getSlugQuery(this.newsroomUuid, slug));
124
+ const {
125
+ stories
126
+ } = await this.searchStories({
127
+ limit: 1,
128
+ query
129
+ });
130
+ if (stories[0]) {
131
+ return this.getStory(stories[0].uuid);
132
+ }
133
+ return null;
134
+ }
135
+ async getCategories() {
136
+ const categories = await this.sdk.newsroomCategories.list(this.newsroomUuid, {
137
+ sortOrder: CATEGORIES_SORT_ORDER
138
+ });
139
+ return Array.isArray(categories) ? categories : Object.values(categories);
140
+ }
141
+ async getCategoryBySlug(slug) {
142
+ const categories = await this.getCategories();
143
+ return categories.find(category => Object.values(category.i18n).some(t => t.slug === slug));
144
+ }
145
+ searchStories = options => this.sdk.stories.search(options);
146
+ async getGalleries({
147
+ page,
148
+ pageSize
149
+ }) {
150
+ return this.sdk.newsroomGalleries.search(this.newsroomUuid, {
151
+ limit: pageSize,
152
+ offset: typeof page === 'undefined' || typeof pageSize === 'undefined' ? undefined : (page - 1) * pageSize,
153
+ query: getGalleriesQuery()
154
+ });
155
+ }
156
+ async getGallery(uuid) {
157
+ if (!isUuid(uuid)) {
158
+ // Check for legacy number ID reference, which is also supported for back-compat.
159
+ if (Number.isNaN(Number(uuid))) {
160
+ return undefined;
161
+ }
162
+ }
163
+ try {
164
+ const gallery = await this.sdk.newsroomGalleries.get(this.newsroomUuid, uuid);
165
+ return gallery;
166
+ } catch (error) {
167
+ if (isSdkError(error) && error.status === 404) {
156
168
  return null;
157
- }
158
- async getNewsroomServerSideProps(request, nextLocaleIsoCode, story) {
159
- const [newsroom, languages, categories, themePreset] = await Promise.all([
160
- this.getNewsroom(),
161
- this.getNewsroomLanguages(),
162
- this.getCategories(),
163
- this.getThemePreset(),
164
- ]);
165
- const currentLanguage = story
166
- ? getLanguageFromStory(languages, story)
167
- : getLanguageFromNextLocaleIsoCode(languages, nextLocaleIsoCode);
168
- const defaultLanguage = getDefaultLanguage(languages);
169
- const { code: localeCode } = currentLanguage || defaultLanguage;
170
- const locale = LocaleObject.fromAnyCode(localeCode);
171
- // TODO: if no information given for current language, show boilerplate from default language
172
- const companyInformation = getCompanyInformation(languages, locale);
173
- const notifications = getNotifications(languages, locale);
174
- const algoliaSettings = getAlgoliaSettings(request);
175
- return {
176
- newsroomContextProps: {
177
- newsroom,
178
- companyInformation,
179
- categories,
180
- languages,
181
- localeCode,
182
- notifications,
183
- themePreset,
184
- algoliaSettings,
185
- },
186
- localeResolved: Boolean(currentLanguage),
187
- };
188
- }
189
- async getNewsroomDefaultLanguage() {
190
- const languages = await this.getNewsroomLanguages();
191
- return getDefaultLanguage(languages);
192
- }
193
- }
194
- //# sourceMappingURL=PrezlyApi.js.map
169
+ }
170
+ throw error;
171
+ }
172
+ }
173
+
174
+ /**
175
+ * In order to prevent issues with theme preview, we only load the theme preset for a specified theme, and not the currently active one.
176
+ */
177
+ async getThemePreset() {
178
+ if (this.themeUuid) {
179
+ return this.sdk.newsroomThemes.get(this.newsroomUuid, this.themeUuid);
180
+ }
181
+ return null;
182
+ }
183
+ async getNewsroomServerSideProps(request, nextLocaleIsoCode, story) {
184
+ const [newsroom, languages, categories, themePreset] = await Promise.all([this.getNewsroom(), this.getNewsroomLanguages(), this.getCategories(), this.getThemePreset()]);
185
+ const currentLanguage = story ? getLanguageFromStory(languages, story) : getLanguageFromNextLocaleIsoCode(languages, nextLocaleIsoCode);
186
+ const defaultLanguage = getDefaultLanguage(languages);
187
+ const {
188
+ code: localeCode
189
+ } = currentLanguage || defaultLanguage;
190
+ const locale = LocaleObject.fromAnyCode(localeCode);
191
+
192
+ // TODO: if no information given for current language, show boilerplate from default language
193
+ const companyInformation = getCompanyInformation(languages, locale);
194
+ const notifications = getNotifications(languages, locale);
195
+ const algoliaSettings = getAlgoliaSettings(request);
196
+ return {
197
+ newsroomContextProps: {
198
+ newsroom,
199
+ companyInformation,
200
+ categories,
201
+ languages,
202
+ localeCode,
203
+ notifications,
204
+ themePreset,
205
+ algoliaSettings
206
+ },
207
+ localeResolved: Boolean(currentLanguage)
208
+ };
209
+ }
210
+ async getNewsroomDefaultLanguage() {
211
+ const languages = await this.getNewsroomLanguages();
212
+ return getDefaultLanguage(languages);
213
+ }
214
+ }
@@ -1,17 +1,21 @@
1
- import { getEnvVariables } from '../lib/getEnvVariables';
2
- import { PrezlyApi } from './PrezlyApi';
1
+ import { getEnvVariables } from "../lib/getEnvVariables.js";
2
+ import { PrezlyApi } from "./PrezlyApi.js";
3
3
  export function getPrezlyApi(req) {
4
- if (typeof window !== 'undefined') {
5
- throw new Error('"getPrezlyApi" should only be used on back-end side.');
6
- }
7
- // `getEnvVariables` handles both cases for envs parsing - .env and request headers
8
- const { PREZLY_ACCESS_TOKEN, PREZLY_NEWSROOM_UUID, PREZLY_THEME_UUID } = getEnvVariables(req);
9
- if (!PREZLY_ACCESS_TOKEN) {
10
- throw new Error('"PREZLY_ACCESS_TOKEN" is not set in env variables.');
11
- }
12
- if (!PREZLY_NEWSROOM_UUID) {
13
- throw new Error('"PREZLY_NEWSROOM_UUID" is not set in env variables.');
14
- }
15
- return new PrezlyApi(PREZLY_ACCESS_TOKEN, PREZLY_NEWSROOM_UUID, PREZLY_THEME_UUID);
16
- }
17
- //# sourceMappingURL=getPrezlyApi.js.map
4
+ if (typeof window !== 'undefined') {
5
+ throw new Error('"getPrezlyApi" should only be used on back-end side.');
6
+ }
7
+
8
+ // `getEnvVariables` handles both cases for envs parsing - .env and request headers
9
+ const {
10
+ PREZLY_ACCESS_TOKEN,
11
+ PREZLY_NEWSROOM_UUID,
12
+ PREZLY_THEME_UUID
13
+ } = getEnvVariables(req);
14
+ if (!PREZLY_ACCESS_TOKEN) {
15
+ throw new Error('"PREZLY_ACCESS_TOKEN" is not set in env variables.');
16
+ }
17
+ if (!PREZLY_NEWSROOM_UUID) {
18
+ throw new Error('"PREZLY_NEWSROOM_UUID" is not set in env variables.');
19
+ }
20
+ return new PrezlyApi(PREZLY_ACCESS_TOKEN, PREZLY_NEWSROOM_UUID, PREZLY_THEME_UUID);
21
+ }
@@ -1,2 +1 @@
1
- export * from './getPrezlyApi';
2
- //# sourceMappingURL=index.js.map
1
+ export * from "./getPrezlyApi.js";
@@ -1,43 +1,80 @@
1
- const publishedAndAccessible = [
2
- { lifecycle_status: { $in: ['published', 'embargo'] } },
3
- { visibility: { $in: ['public', 'private', 'embargo'] } },
4
- ];
5
- const publishedAndPublic = [
6
- { lifecycle_status: { $in: ['published'] } },
7
- { visibility: { $in: ['public'] } },
8
- ];
1
+ const publishedAndAccessible = [{
2
+ lifecycle_status: {
3
+ $in: ['published', 'embargo']
4
+ }
5
+ }, {
6
+ visibility: {
7
+ $in: ['public', 'private', 'embargo']
8
+ }
9
+ }];
10
+ const publishedAndPublic = [{
11
+ lifecycle_status: {
12
+ $in: ['published']
13
+ }
14
+ }, {
15
+ visibility: {
16
+ $in: ['public']
17
+ }
18
+ }];
9
19
  export function getSlugQuery(newsroomUuid, slug) {
10
- return {
11
- $and: [
12
- { 'newsroom.uuid': { $in: [newsroomUuid] } },
13
- { slug: { $eq: slug } },
14
- ...publishedAndAccessible,
15
- ],
16
- };
20
+ return {
21
+ $and: [{
22
+ 'newsroom.uuid': {
23
+ $in: [newsroomUuid]
24
+ }
25
+ }, {
26
+ slug: {
27
+ $eq: slug
28
+ }
29
+ }, ...publishedAndAccessible]
30
+ };
17
31
  }
18
32
  export function getStoriesQuery(newsroomUuid, categoryId, localeCode) {
19
- const query = {
20
- $and: [...publishedAndPublic, { 'newsroom.uuid': { $in: [newsroomUuid] } }],
21
- };
22
- if (categoryId) {
23
- query.$and.push({ 'category.id': { $any: [categoryId] } });
24
- }
25
- if (localeCode) {
26
- query.$and.push({ locale: { $in: [localeCode] } });
27
- }
28
- return query;
33
+ const query = {
34
+ $and: [...publishedAndPublic, {
35
+ 'newsroom.uuid': {
36
+ $in: [newsroomUuid]
37
+ }
38
+ }]
39
+ };
40
+ if (categoryId) {
41
+ query.$and.push({
42
+ 'category.id': {
43
+ $any: [categoryId]
44
+ }
45
+ });
46
+ }
47
+ if (localeCode) {
48
+ query.$and.push({
49
+ locale: {
50
+ $in: [localeCode]
51
+ }
52
+ });
53
+ }
54
+ return query;
29
55
  }
30
56
  export function getSortByPublishedDate(order) {
31
- return order === 'desc' ? '-published_at' : 'published_at';
57
+ return order === 'desc' ? '-published_at' : 'published_at';
32
58
  }
33
59
  export function getGalleriesQuery() {
34
- return {
35
- $and: [{ status: { $eq: 'public' } }, { images_number: { $gt: 0 } }],
36
- };
60
+ return {
61
+ $and: [{
62
+ status: {
63
+ $eq: 'public'
64
+ }
65
+ }, {
66
+ images_number: {
67
+ $gt: 0
68
+ }
69
+ }]
70
+ };
37
71
  }
38
72
  export function getContactsQuery() {
39
- return {
40
- $and: [{ is_featured: { $eq: true } }],
41
- };
42
- }
43
- //# sourceMappingURL=queries.js.map
73
+ return {
74
+ $and: [{
75
+ is_featured: {
76
+ $eq: true
77
+ }
78
+ }]
79
+ };
80
+ }
@@ -1,4 +1,3 @@
1
- export * from './api';
2
- export * from './lib';
3
- export * from './types';
4
- //# sourceMappingURL=index.js.map
1
+ export * from "./api/index.js";
2
+ export * from "./lib/index.js";
3
+ export * from "./types.js";
@@ -1,18 +1,22 @@
1
- import { getEnvVariables } from './getEnvVariables';
1
+ import { getEnvVariables } from "./getEnvVariables.js";
2
2
  export function getAlgoliaSettings(req) {
3
- if (typeof window !== 'undefined') {
4
- throw new Error('"getAlgoliaSettings" should only be used on back-end side.');
5
- }
6
- // `getEnvVariables` handles both cases for envs parsing - .env and request headers
7
- const { ALGOLIA_API_KEY = '', ALGOLIA_APP_ID = 'UI4CNRAHQB', ALGOLIA_INDEX = 'public_stories_prod', } = getEnvVariables(req);
8
- if (!ALGOLIA_API_KEY) {
9
- // eslint-disable-next-line no-console
10
- console.error('"ALGOLIA_API_KEY" is not set in env variables. Search will not be enabled');
11
- }
12
- return {
13
- ALGOLIA_API_KEY,
14
- ALGOLIA_APP_ID,
15
- ALGOLIA_INDEX,
16
- };
17
- }
18
- //# sourceMappingURL=getAlgoliaSettings.js.map
3
+ if (typeof window !== 'undefined') {
4
+ throw new Error('"getAlgoliaSettings" should only be used on back-end side.');
5
+ }
6
+
7
+ // `getEnvVariables` handles both cases for envs parsing - .env and request headers
8
+ const {
9
+ ALGOLIA_API_KEY = '',
10
+ ALGOLIA_APP_ID = 'UI4CNRAHQB',
11
+ ALGOLIA_INDEX = 'public_stories_prod'
12
+ } = getEnvVariables(req);
13
+ if (!ALGOLIA_API_KEY) {
14
+ // eslint-disable-next-line no-console
15
+ console.error('"ALGOLIA_API_KEY" is not set in env variables. Search will not be enabled');
16
+ }
17
+ return {
18
+ ALGOLIA_API_KEY,
19
+ ALGOLIA_APP_ID,
20
+ ALGOLIA_INDEX
21
+ };
22
+ }