@prezly/theme-kit-nextjs 1.6.4-4 → 1.7.1-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 (140) hide show
  1. package/README.md +8 -0
  2. package/build/adapter-nextjs/getNewsroomServerSideProps.js +63 -9
  3. package/build/adapter-nextjs/getNewsroomServerSideProps.js.map +1 -1
  4. package/build/adapter-nextjs/index.js +14 -2
  5. package/build/adapter-nextjs/index.js.map +1 -1
  6. package/build/adapter-nextjs/processRequest.js +25 -10
  7. package/build/adapter-nextjs/processRequest.js.map +1 -1
  8. package/build/components-nextjs/PageSeo/PageSeo.js +58 -43
  9. package/build/components-nextjs/PageSeo/PageSeo.js.map +1 -1
  10. package/build/components-nextjs/PageSeo/index.js +16 -2
  11. package/build/components-nextjs/PageSeo/index.js.map +1 -1
  12. package/build/components-nextjs/PageSeo/lib/getAbsoluteUrl.js +6 -2
  13. package/build/components-nextjs/PageSeo/lib/getAbsoluteUrl.js.map +1 -1
  14. package/build/components-nextjs/PageSeo/lib/types.js +2 -1
  15. package/build/components-nextjs/Sitemap/SitemapBuilder.js +22 -18
  16. package/build/components-nextjs/Sitemap/SitemapBuilder.js.map +1 -1
  17. package/build/components-nextjs/Sitemap/createPaths.js +45 -10
  18. package/build/components-nextjs/Sitemap/createPaths.js.map +1 -1
  19. package/build/components-nextjs/Sitemap/getInitialProps.js +75 -23
  20. package/build/components-nextjs/Sitemap/getInitialProps.js.map +1 -1
  21. package/build/components-nextjs/Sitemap/index.js +20 -4
  22. package/build/components-nextjs/Sitemap/index.js.map +1 -1
  23. package/build/components-nextjs/Sitemap/types.js +2 -1
  24. package/build/components-nextjs/StorySeo/StorySeo.js +34 -26
  25. package/build/components-nextjs/StorySeo/StorySeo.js.map +1 -1
  26. package/build/components-nextjs/StorySeo/index.js +5 -1
  27. package/build/components-nextjs/StorySeo/index.js.map +1 -1
  28. package/build/components-nextjs/index.js +18 -3
  29. package/build/components-nextjs/index.js.map +1 -1
  30. package/build/data-fetching/api/PrezlyApi.d.ts +2 -2
  31. package/build/data-fetching/api/PrezlyApi.js +329 -133
  32. package/build/data-fetching/api/PrezlyApi.js.map +1 -1
  33. package/build/data-fetching/api/getPrezlyApi.js +9 -5
  34. package/build/data-fetching/api/getPrezlyApi.js.map +1 -1
  35. package/build/data-fetching/api/index.js +14 -2
  36. package/build/data-fetching/api/index.js.map +1 -1
  37. package/build/data-fetching/api/languages.js +85 -43
  38. package/build/data-fetching/api/languages.js.map +1 -1
  39. package/build/data-fetching/api/queries.js +45 -13
  40. package/build/data-fetching/api/queries.js.map +1 -1
  41. package/build/data-fetching/constants.js +5 -2
  42. package/build/data-fetching/constants.js.map +1 -1
  43. package/build/data-fetching/getAssetsUrl.js +7 -3
  44. package/build/data-fetching/getAssetsUrl.js.map +1 -1
  45. package/build/data-fetching/getLocalizedCategoryData.js +32 -15
  46. package/build/data-fetching/getLocalizedCategoryData.js.map +1 -1
  47. package/build/data-fetching/getNewsroomLogoUrl.js +12 -6
  48. package/build/data-fetching/getNewsroomLogoUrl.js.map +1 -1
  49. package/build/data-fetching/getPrivacyPortalUrl.js +7 -3
  50. package/build/data-fetching/getPrivacyPortalUrl.js.map +1 -1
  51. package/build/data-fetching/getStoryPublicationDate.js +6 -2
  52. package/build/data-fetching/getStoryPublicationDate.js.map +1 -1
  53. package/build/data-fetching/getUploadcareGroupUrl.js +7 -3
  54. package/build/data-fetching/getUploadcareGroupUrl.js.map +1 -1
  55. package/build/data-fetching/index.js +22 -10
  56. package/build/data-fetching/index.js.map +1 -1
  57. package/build/data-fetching/lib/getAlgoliaSettings.js +10 -6
  58. package/build/data-fetching/lib/getAlgoliaSettings.js.map +1 -1
  59. package/build/data-fetching/lib/getEnvVariables.js +29 -11
  60. package/build/data-fetching/lib/getEnvVariables.js.map +1 -1
  61. package/build/data-fetching/lib/index.d.ts +1 -0
  62. package/build/data-fetching/lib/index.js +7 -1
  63. package/build/data-fetching/lib/index.js.map +1 -1
  64. package/build/data-fetching/lib/isSdkError.d.ts +2 -0
  65. package/build/data-fetching/lib/isSdkError.js +8 -0
  66. package/build/data-fetching/lib/isSdkError.js.map +1 -0
  67. package/build/data-fetching/types.js +2 -1
  68. package/build/index.d.ts +6 -6
  69. package/build/index.js +19 -7
  70. package/build/index.js.map +1 -1
  71. package/build/infinite-loading/apiHandlers/fetchGalleries.js +69 -15
  72. package/build/infinite-loading/apiHandlers/fetchGalleries.js.map +1 -1
  73. package/build/infinite-loading/apiHandlers/fetchStories.js +71 -17
  74. package/build/infinite-loading/apiHandlers/fetchStories.js.map +1 -1
  75. package/build/infinite-loading/apiHandlers/index.js +7 -2
  76. package/build/infinite-loading/apiHandlers/index.js.map +1 -1
  77. package/build/infinite-loading/index.js +21 -5
  78. package/build/infinite-loading/index.js.map +1 -1
  79. package/build/infinite-loading/types.js +2 -1
  80. package/build/infinite-loading/useInfiniteGalleriesLoading.js +83 -25
  81. package/build/infinite-loading/useInfiniteGalleriesLoading.js.map +1 -1
  82. package/build/infinite-loading/useInfiniteLoading.js +97 -21
  83. package/build/infinite-loading/useInfiniteLoading.js.map +1 -1
  84. package/build/infinite-loading/useInfiniteStoriesLoading.js +99 -36
  85. package/build/infinite-loading/useInfiniteStoriesLoading.js.map +1 -1
  86. package/build/intl/index.d.ts +1 -2
  87. package/build/intl/index.js +21 -5
  88. package/build/intl/index.js.map +1 -1
  89. package/build/intl/lang.js +11 -4
  90. package/build/intl/lang.js.map +1 -1
  91. package/build/intl/locale.js +27 -21
  92. package/build/intl/locale.js.map +1 -1
  93. package/build/intl/localeConfig.d.ts +2 -1
  94. package/build/intl/localeConfig.js +30 -8
  95. package/build/intl/localeConfig.js.map +1 -1
  96. package/build/intl/localeList.d.ts +56 -4
  97. package/build/intl/localeList.js +2 -1
  98. package/build/intl/localeList.js.map +1 -1
  99. package/build/intl/localeObject.js +49 -30
  100. package/build/intl/localeObject.js.map +1 -1
  101. package/build/newsroom-context/context.js +34 -18
  102. package/build/newsroom-context/context.js.map +1 -1
  103. package/build/newsroom-context/hooks/index.js +23 -11
  104. package/build/newsroom-context/hooks/index.js.map +1 -1
  105. package/build/newsroom-context/hooks/useAlgoliaSettings.js +7 -3
  106. package/build/newsroom-context/hooks/useAlgoliaSettings.js.map +1 -1
  107. package/build/newsroom-context/hooks/useCategories.js +7 -3
  108. package/build/newsroom-context/hooks/useCategories.js.map +1 -1
  109. package/build/newsroom-context/hooks/useCompanyInformation.js +7 -3
  110. package/build/newsroom-context/hooks/useCompanyInformation.js.map +1 -1
  111. package/build/newsroom-context/hooks/useCurrentCategory.js +7 -3
  112. package/build/newsroom-context/hooks/useCurrentCategory.js.map +1 -1
  113. package/build/newsroom-context/hooks/useCurrentLocale.js +7 -3
  114. package/build/newsroom-context/hooks/useCurrentLocale.js.map +1 -1
  115. package/build/newsroom-context/hooks/useCurrentStory.js +7 -3
  116. package/build/newsroom-context/hooks/useCurrentStory.js.map +1 -1
  117. package/build/newsroom-context/hooks/useGetLinkLocaleSlug.js +15 -11
  118. package/build/newsroom-context/hooks/useGetLinkLocaleSlug.js.map +1 -1
  119. package/build/newsroom-context/hooks/useGetTranslationUrl.js +24 -15
  120. package/build/newsroom-context/hooks/useGetTranslationUrl.js.map +1 -1
  121. package/build/newsroom-context/hooks/useLanguages.js +7 -3
  122. package/build/newsroom-context/hooks/useLanguages.js.map +1 -1
  123. package/build/newsroom-context/hooks/useNewsroom.js +7 -3
  124. package/build/newsroom-context/hooks/useNewsroom.js.map +1 -1
  125. package/build/newsroom-context/hooks/useNewsroomContext.js +8 -4
  126. package/build/newsroom-context/hooks/useNewsroomContext.js.map +1 -1
  127. package/build/newsroom-context/index.js +17 -2
  128. package/build/newsroom-context/index.js.map +1 -1
  129. package/build/types.d.ts +10 -0
  130. package/build/types.js +2 -1
  131. package/package.json +3 -5
  132. package/src/data-fetching/api/PrezlyApi.ts +18 -3
  133. package/src/data-fetching/lib/index.ts +1 -0
  134. package/src/data-fetching/lib/isSdkError.ts +5 -0
  135. package/src/index.ts +6 -6
  136. package/src/intl/index.ts +1 -2
  137. package/src/intl/{localeConfig.ts → localeConfig.js} +3 -3
  138. package/src/intl/{localeList.ts → localeList.js} +1 -1
  139. package/src/intl/localeObject.ts +1 -1
  140. package/src/types.ts +12 -0
@@ -1,3 +1,18 @@
1
- export { NewsroomContext, NewsroomContextProvider } from './context';
2
- export * from './hooks';
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.NewsroomContextProvider = exports.NewsroomContext = void 0;
14
+ var context_1 = require("./context");
15
+ Object.defineProperty(exports, "NewsroomContext", { enumerable: true, get: function () { return context_1.NewsroomContext; } });
16
+ Object.defineProperty(exports, "NewsroomContextProvider", { enumerable: true, get: function () { return context_1.NewsroomContextProvider; } });
17
+ __exportStar(require("./hooks"), exports);
3
18
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/newsroom-context/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,uBAAuB,EAAwB,MAAM,WAAW,CAAC;AAC3F,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/newsroom-context/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,qCAA2F;AAAlF,0GAAA,eAAe,OAAA;AAAE,kHAAA,uBAAuB,OAAA;AACjD,0CAAwB"}
package/build/types.d.ts CHANGED
@@ -31,3 +31,13 @@ export declare type AlgoliaStory = Pick<Story, 'uuid' | 'slug' | 'title' | 'subt
31
31
  culture: Pick<CultureRef, 'code' | 'name' | 'native_name' | 'language_code'>;
32
32
  categories: AlgoliaCategoryRef[];
33
33
  };
34
+ export interface SdkError extends Error {
35
+ status: number;
36
+ statusText: string;
37
+ payload: {
38
+ errors: {
39
+ reason: string;
40
+ };
41
+ message: string;
42
+ };
43
+ }
package/build/types.js CHANGED
@@ -1,2 +1,3 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
2
3
  //# sourceMappingURL=types.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prezly/theme-kit-nextjs",
3
- "version": "1.6.4-4",
3
+ "version": "1.7.1-0",
4
4
  "description": "Data layer and utility library for developing Prezly themes with NextJS",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -8,7 +8,6 @@
8
8
  "build",
9
9
  "src"
10
10
  ],
11
- "type": "module",
12
11
  "engines": {
13
12
  "node": ">= 14.x",
14
13
  "npm": ">= 7.x"
@@ -53,7 +52,7 @@
53
52
  "@react-hookz/web": "^13.2.1",
54
53
  "next-seo": "^5.4.0",
55
54
  "parse-data-url": "^4.0.1",
56
- "string-strip-html": "^9.1.9"
55
+ "string-strip-html": "^8.3.0"
57
56
  },
58
57
  "devDependencies": {
59
58
  "@prezly/eslint-config": "^4.0.0",
@@ -69,6 +68,5 @@
69
68
  },
70
69
  "publishConfig": {
71
70
  "access": "public"
72
- },
73
- "prettier": "@prezly/eslint-config/prettier"
71
+ }
74
72
  }
@@ -11,6 +11,7 @@ import type { IncomingMessage } from 'http';
11
11
  import { LocaleObject } from '../../intl';
12
12
  import type { PageProps, ServerSidePageProps } from '../../types';
13
13
  import { DEFAULT_PAGE_SIZE } from '../constants';
14
+ import { isSdkError } from '../lib';
14
15
  import { getAlgoliaSettings } from '../lib/getAlgoliaSettings';
15
16
 
16
17
  import {
@@ -63,8 +64,15 @@ export class PrezlyApi {
63
64
  this.themeUuid = themeUuid;
64
65
  }
65
66
 
66
- getStory(uuid: string) {
67
- return this.sdk.stories.get(uuid);
67
+ async getStory(uuid: string) {
68
+ try {
69
+ return await this.sdk.stories.get(uuid);
70
+ } catch (error) {
71
+ if (isSdkError(error) && error.status === 404) {
72
+ return null;
73
+ }
74
+ throw error;
75
+ }
68
76
  }
69
77
 
70
78
  async getNewsroom() {
@@ -199,7 +207,14 @@ export class PrezlyApi {
199
207
  }
200
208
 
201
209
  async getGallery(uuid: string) {
202
- return this.sdk.newsroomGalleries.get(this.newsroomUuid, uuid);
210
+ try {
211
+ return await this.sdk.newsroomGalleries.get(this.newsroomUuid, uuid);
212
+ } catch (error) {
213
+ if (isSdkError(error) && error.status === 404) {
214
+ return null;
215
+ }
216
+ throw error;
217
+ }
203
218
  }
204
219
 
205
220
  /**
@@ -1 +1,2 @@
1
1
  export { getEnvVariables } from './getEnvVariables';
2
+ export { isSdkError } from './isSdkError';
@@ -0,0 +1,5 @@
1
+ import type { SdkError } from '../../types';
2
+
3
+ export function isSdkError(error: any): error is SdkError {
4
+ return 'payload' in error;
5
+ }
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
- export * from './adapter-nextjs/index';
2
- export * from './components-nextjs/index';
3
- export * from './data-fetching/index';
4
- export * from './infinite-loading/index';
5
- export * from './intl/index';
6
- export * from './newsroom-context/index';
1
+ export * from './adapter-nextjs';
2
+ export * from './components-nextjs';
3
+ export * from './data-fetching';
4
+ export * from './infinite-loading';
5
+ export * from './intl';
6
+ export * from './newsroom-context';
7
7
  export * from './types';
package/src/intl/index.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from './lang';
2
2
  export * from './locale';
3
- export { localeConfig } from './localeConfig';
4
- export { localeList } from './localeList';
3
+ export { default as localeConfig } from './localeConfig';
5
4
  export * from './localeObject';
@@ -3,9 +3,9 @@
3
3
  * Together with permutation performed lower in the code,
4
4
  * the exported list represents all of the possible locale codes that Next.js theme application might accept.
5
5
  */
6
- import { localeList } from './localeList';
6
+ const supportedLocales = require('./localeList');
7
7
 
8
- const lowercaseLocales = localeList.map((l) => l.toLowerCase());
8
+ const lowercaseLocales = supportedLocales.map((l) => l.toLowerCase());
9
9
 
10
10
  // Get all permutations for the shorter locale codes supported by Prezly (e.g. short region codes and neutral language codes)
11
11
  const lowercaseLocalPermutations = Array.from(
@@ -16,4 +16,4 @@ const lowercaseLocalPermutations = Array.from(
16
16
  ]),
17
17
  ).sort();
18
18
 
19
- export const localeConfig = lowercaseLocalPermutations;
19
+ module.exports = lowercaseLocalPermutations;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * This list is pulled from the main Prezly application. The underscores are replaced with dashes.
3
3
  */
4
- export const localeList = [
4
+ module.exports = [
5
5
  'af-ZA',
6
6
  'ar',
7
7
  'ar-AE',
@@ -1,4 +1,4 @@
1
- import { localeConfig } from './localeConfig';
1
+ import localeConfig from './localeConfig';
2
2
 
3
3
  /**
4
4
  * This class is created to simplify working with locales and transforming between different locale code formats.
package/src/types.ts CHANGED
@@ -37,3 +37,15 @@ export type AlgoliaStory = Pick<Story, 'uuid' | 'slug' | 'title' | 'subtitle'> &
37
37
  culture: Pick<CultureRef, 'code' | 'name' | 'native_name' | 'language_code'>;
38
38
  categories: AlgoliaCategoryRef[];
39
39
  };
40
+
41
+ // TODO: This should be exported from `@prezly/sdk`
42
+ export interface SdkError extends Error {
43
+ status: number;
44
+ statusText: string;
45
+ payload: {
46
+ errors: {
47
+ reason: string;
48
+ };
49
+ message: string;
50
+ };
51
+ }