@prezly/theme-kit-nextjs 1.15.0-0 → 1.16.0-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 (50) hide show
  1. package/build/adapter-nextjs/page-props/category.d.ts +1 -1
  2. package/build/adapter-nextjs/page-props/category.js.map +1 -1
  3. package/build/adapter-nextjs/page-props/gallery.d.ts +1 -1
  4. package/build/adapter-nextjs/page-props/gallery.js.map +1 -1
  5. package/build/adapter-nextjs/page-props/galleryAlbum.d.ts +1 -1
  6. package/build/adapter-nextjs/page-props/galleryAlbum.js.map +1 -1
  7. package/build/adapter-nextjs/page-props/home.d.ts +1 -1
  8. package/build/adapter-nextjs/page-props/home.js.map +1 -1
  9. package/build/adapter-nextjs/page-props/lib/types.d.ts +1 -1
  10. package/build/adapter-nextjs/page-props/search.d.ts +2 -2
  11. package/build/adapter-nextjs/page-props/search.js.map +1 -1
  12. package/build/adapter-nextjs/page-props/story.d.ts +1 -1
  13. package/build/adapter-nextjs/page-props/story.js.map +1 -1
  14. package/build/components-nextjs/document.d.ts +6 -0
  15. package/build/components-nextjs/document.js +77 -0
  16. package/build/components-nextjs/document.js.map +1 -0
  17. package/build/components-nextjs/index.d.ts +1 -0
  18. package/build/components-nextjs/index.js +3 -1
  19. package/build/components-nextjs/index.js.map +1 -1
  20. package/build/index.d.ts +1 -0
  21. package/build/index.js +1 -0
  22. package/build/index.js.map +1 -1
  23. package/build/sentry/client.d.ts +2 -0
  24. package/build/sentry/client.js +9 -0
  25. package/build/sentry/client.js.map +1 -0
  26. package/build/sentry/common.d.ts +2 -0
  27. package/build/sentry/common.js +29 -0
  28. package/build/sentry/common.js.map +1 -0
  29. package/build/sentry/index.d.ts +2 -0
  30. package/build/sentry/index.js +8 -0
  31. package/build/sentry/index.js.map +1 -0
  32. package/build/sentry/server.d.ts +2 -0
  33. package/build/sentry/server.js +9 -0
  34. package/build/sentry/server.js.map +1 -0
  35. package/build/tsconfig.tsbuildinfo +1 -1
  36. package/package.json +2 -1
  37. package/src/adapter-nextjs/page-props/category.ts +5 -2
  38. package/src/adapter-nextjs/page-props/gallery.ts +5 -2
  39. package/src/adapter-nextjs/page-props/galleryAlbum.ts +5 -2
  40. package/src/adapter-nextjs/page-props/home.ts +5 -2
  41. package/src/adapter-nextjs/page-props/lib/types.ts +4 -4
  42. package/src/adapter-nextjs/page-props/search.ts +10 -3
  43. package/src/adapter-nextjs/page-props/story.ts +5 -2
  44. package/src/components-nextjs/document.tsx +38 -0
  45. package/src/components-nextjs/index.ts +1 -0
  46. package/src/index.ts +1 -0
  47. package/src/sentry/client.ts +7 -0
  48. package/src/sentry/common.ts +27 -0
  49. package/src/sentry/index.ts +2 -0
  50. package/src/sentry/server.ts +7 -0
@@ -71,7 +71,7 @@ export function getGalleryPageServerSideProps<CustomProps extends Record<string,
71
71
  }
72
72
 
73
73
  export function getGalleryPageStaticProps<CustomProps extends Record<string, any>>(
74
- customProps: CustomProps | PropsFunction<CustomProps>,
74
+ customProps: CustomProps | PropsFunction<CustomProps, GetStaticPropsContext>,
75
75
  options?: Options,
76
76
  ) {
77
77
  const { pageSize = DEFAULT_GALLERY_PAGE_SIZE } = options || {};
@@ -104,7 +104,10 @@ export function getGalleryPageStaticProps<CustomProps extends Record<string, any
104
104
  pageSize,
105
105
  },
106
106
  ...(typeof customProps === 'function'
107
- ? await (customProps as PropsFunction<CustomProps>)(context, staticProps)
107
+ ? await (customProps as PropsFunction<CustomProps, GetStaticPropsContext>)(
108
+ context,
109
+ staticProps,
110
+ )
108
111
  : customProps),
109
112
  });
110
113
  };
@@ -49,7 +49,7 @@ export function getGalleryAlbumPageServerSideProps<CustomProps extends Record<st
49
49
  }
50
50
 
51
51
  export function getGalleryAlbumPageStaticProps<CustomProps extends Record<string, any>>(
52
- customProps: CustomProps | PropsFunction<CustomProps>,
52
+ customProps: CustomProps | PropsFunction<CustomProps, GetStaticPropsContext>,
53
53
  ) {
54
54
  return async function getStaticProps(
55
55
  context: GetStaticPropsContext,
@@ -67,7 +67,10 @@ export function getGalleryAlbumPageStaticProps<CustomProps extends Record<string
67
67
  ...staticProps,
68
68
  gallery,
69
69
  ...(typeof customProps === 'function'
70
- ? await (customProps as PropsFunction<CustomProps>)(context, staticProps)
70
+ ? await (customProps as PropsFunction<CustomProps, GetStaticPropsContext>)(
71
+ context,
72
+ staticProps,
73
+ )
71
74
  : customProps),
72
75
  });
73
76
  };
@@ -74,7 +74,7 @@ export function getHomepageServerSideProps<
74
74
  export function getHomepageStaticProps<
75
75
  CustomProps extends Record<string, any>,
76
76
  StoryType extends Story = Story,
77
- >(customProps: CustomProps | PropsFunction<CustomProps>, options?: Options) {
77
+ >(customProps: CustomProps | PropsFunction<CustomProps, GetStaticPropsContext>, options?: Options) {
78
78
  const { pageSize = DEFAULT_PAGE_SIZE, extraStoryFields } = options || {};
79
79
 
80
80
  return async function getStaticProps(
@@ -103,7 +103,10 @@ export function getHomepageStaticProps<
103
103
  pageSize,
104
104
  },
105
105
  ...(typeof customProps === 'function'
106
- ? await (customProps as PropsFunction<CustomProps>)(context, staticProps)
106
+ ? await (customProps as PropsFunction<CustomProps, GetStaticPropsContext>)(
107
+ context,
108
+ staticProps,
109
+ )
107
110
  : customProps),
108
111
  });
109
112
  };
@@ -2,7 +2,7 @@ import type { GetServerSidePropsContext, GetStaticPropsContext } from 'next';
2
2
 
3
3
  import type { PageProps } from '../../../types';
4
4
 
5
- export type PropsFunction<CustomProps> = (
6
- context: GetServerSidePropsContext | GetStaticPropsContext,
7
- props: PageProps,
8
- ) => CustomProps | Promise<CustomProps>;
5
+ export type PropsFunction<
6
+ CustomProps,
7
+ Context extends GetServerSidePropsContext | GetStaticPropsContext = GetServerSidePropsContext,
8
+ > = (context: Context, props: PageProps) => CustomProps | Promise<CustomProps>;
@@ -1,4 +1,8 @@
1
- import type { GetServerSidePropsContext, GetServerSidePropsResult } from 'next';
1
+ import type {
2
+ GetServerSidePropsContext,
3
+ GetServerSidePropsResult,
4
+ GetStaticPropsContext,
5
+ } from 'next';
2
6
 
3
7
  import { getNewsroomServerSideProps } from '../getNewsroomServerSideProps';
4
8
  import { getNewsroomStaticProps } from '../getNewsroomStaticProps';
@@ -29,7 +33,7 @@ export function getSearchPageServerSideProps<CustomProps extends Record<string,
29
33
  }
30
34
 
31
35
  export function getSearchPageStaticProps<CustomProps extends Record<string, any>>(
32
- customProps: CustomProps | PropsFunction<CustomProps>,
36
+ customProps: CustomProps | PropsFunction<CustomProps, GetStaticPropsContext>,
33
37
  ) {
34
38
  return async function getStaticProps(
35
39
  context: GetServerSidePropsContext,
@@ -39,7 +43,10 @@ export function getSearchPageStaticProps<CustomProps extends Record<string, any>
39
43
  return processStaticRequest(context, {
40
44
  ...staticProps,
41
45
  ...(typeof customProps === 'function'
42
- ? await (customProps as PropsFunction<CustomProps>)(context, staticProps)
46
+ ? await (customProps as PropsFunction<CustomProps, GetStaticPropsContext>)(
47
+ context,
48
+ staticProps,
49
+ )
43
50
  : customProps),
44
51
  });
45
52
  };
@@ -54,7 +54,7 @@ export function getStoryPageServerSideProps<CustomProps extends Record<string, a
54
54
  }
55
55
 
56
56
  export function getStoryPageStaticProps<CustomProps extends Record<string, any>>(
57
- customProps: CustomProps | PropsFunction<CustomProps>,
57
+ customProps: CustomProps | PropsFunction<CustomProps, GetStaticPropsContext>,
58
58
  ) {
59
59
  return async function getStaticProps(
60
60
  context: GetStaticPropsContext,
@@ -76,7 +76,10 @@ export function getStoryPageStaticProps<CustomProps extends Record<string, any>>
76
76
  currentStory: story,
77
77
  },
78
78
  ...(typeof customProps === 'function'
79
- ? await (customProps as PropsFunction<CustomProps>)(context, staticProps)
79
+ ? await (customProps as PropsFunction<CustomProps, GetStaticPropsContext>)(
80
+ context,
81
+ staticProps,
82
+ )
80
83
  : customProps),
81
84
  });
82
85
  };
@@ -0,0 +1,38 @@
1
+ import Document, { Head, Html, Main, NextScript } from 'next/document';
2
+
3
+ import { DEFAULT_LOCALE, getLocaleDirection, LocaleObject } from '../intl';
4
+ import type { PageProps } from '../types';
5
+
6
+ export class PrezlyThemeDocument extends Document {
7
+ getLocaleCode() {
8
+ const {
9
+ newsroomContextProps,
10
+ // eslint-disable-next-line no-underscore-dangle
11
+ } = this.props.__NEXT_DATA__.props.pageProps as PageProps;
12
+
13
+ // In some cases (like server errors) the newsroom context props will not be loaded.
14
+ // We need to fall back to default locale to keep the app working.
15
+ const { localeCode } = newsroomContextProps ?? { localeCode: DEFAULT_LOCALE };
16
+
17
+ return localeCode;
18
+ }
19
+
20
+ render() {
21
+ const locale = LocaleObject.fromAnyCode(this.getLocaleCode());
22
+ // TODO: The direction can be pulled from the Language object
23
+ const direction = getLocaleDirection(locale);
24
+
25
+ return (
26
+ <Html lang={locale.toHyphenCode()} dir={direction}>
27
+ <Head>
28
+ <meta name="og:locale" content={locale.toHyphenCode()} />
29
+ {/* TODO: Add alternate locales */}
30
+ </Head>
31
+ <body>
32
+ <Main />
33
+ <NextScript />
34
+ </body>
35
+ </Html>
36
+ );
37
+ }
38
+ }
@@ -1,2 +1,3 @@
1
1
  export { PageSeo } from './PageSeo';
2
2
  export { StorySeo } from './StorySeo';
3
+ export { PrezlyThemeDocument } from './document';
package/src/index.ts CHANGED
@@ -4,5 +4,6 @@ export * from './data-fetching';
4
4
  export * from './infinite-loading';
5
5
  export * from './intl';
6
6
  export * from './newsroom-context';
7
+ export * from './sentry';
7
8
  export * from './types';
8
9
  export * from './utils';
@@ -0,0 +1,7 @@
1
+ import type { init } from '@sentry/nextjs';
2
+
3
+ import { getCommonClientOptions } from './common';
4
+
5
+ export function getSentryClientOptions(dsn: string, themeName: string): Parameters<typeof init>[0] {
6
+ return getCommonClientOptions(dsn, themeName);
7
+ }
@@ -0,0 +1,27 @@
1
+ import type { init } from '@sentry/nextjs';
2
+
3
+ export function getCommonClientOptions(dsn: string, themeName: string): Parameters<typeof init>[0] {
4
+ return {
5
+ dsn,
6
+ // Adjust this value in production, or use tracesSampler for greater control
7
+ tracesSampleRate: 0.02,
8
+ // ...
9
+ // Note: if you want to override the automatic release value, do not set a
10
+ // `release` value here - use the environment variable `SENTRY_RELEASE`, so
11
+ // that it will also get attached to your source maps
12
+
13
+ ignoreErrors: [
14
+ // This particular error is coming from Microsoft Outlook SafeLink crawler.
15
+ // It doesn't affect the user experience in any way, but produces a lot of unwanted Sentry events.
16
+ // See https://forum.sentry.io/t/unhandledrejection-non-error-promise-rejection-captured-with-value/14062
17
+ 'Object Not Found Matching Id',
18
+ // This error is caused by `beacon.min.js` polyfill in Cloudflare Insights. From what we see, it doesn't affect the user experience.
19
+ 'Illegal invocation',
20
+ ],
21
+ // Attach theme tag to each event
22
+ initialScope: (scope) => {
23
+ scope.setTags({ prezly_theme: themeName });
24
+ return scope;
25
+ },
26
+ };
27
+ }
@@ -0,0 +1,2 @@
1
+ export { getSentryClientOptions } from './client';
2
+ export { getSentryServerOptions } from './server';
@@ -0,0 +1,7 @@
1
+ import type { init } from '@sentry/nextjs';
2
+
3
+ import { getCommonClientOptions } from './common';
4
+
5
+ export function getSentryServerOptions(dsn: string, themeName: string): Parameters<typeof init>[0] {
6
+ return getCommonClientOptions(dsn, themeName);
7
+ }