@prezly/theme-kit-nextjs 5.3.0 → 5.3.1-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.
package/README.md CHANGED
@@ -54,6 +54,25 @@ If you don't have these credentials, you can use one of our [testing newsrooms c
54
54
  In a base setup, you don't have to make any changes to your config.
55
55
  Depending on your use-case, you might need to make some additions to your base config.
56
56
 
57
+ #### `withPrezlyConfig` helper
58
+
59
+ You can add all of the necessary properties to your Next config with a single helper function.
60
+ It adds the required `i18n` config, `images` config if you're using `next/image` to display images served from Prezly, and recommended security headers.
61
+ Apart from several properties in `i18n` config, all of your existing config properties will be preserved and merged with our custom properties.
62
+ You can control each of the config overrides with optional parameters object.
63
+
64
+ ```js
65
+ const withPrezlyConfig = require('@prezly/theme-kit-nextjs/config')(/* Optional parameters for PrezlyConfig */);
66
+
67
+ const config ={
68
+ /* ...your next config... */
69
+ };
70
+
71
+ module.exports = withPrezlyConfig(config);
72
+ ```
73
+
74
+ You can also add the properties manually if you want even more control over the config.
75
+
57
76
  #### Using next/image to display images served from Prezly
58
77
 
59
78
  We provide `@prezly/uploadcare-image` package to conveniently display images inside Prezly content, and this is the recommended way to display images in your theme.
@@ -14,7 +14,10 @@ const intl_1 = require("../intl");
14
14
  */
15
15
  function processRequest(context, props, canonicalUrl) {
16
16
  (0, theme_kit_core_1.assertServerEnv)('processRequest');
17
- const { locale: nextLocale, query } = context;
17
+ const { locale: nextLocale, query, res } = context;
18
+ // Since Next 13, Cache-Control header set in `next.config.js` is overwritten by Next in production, effectively bypassing any caching systems setup on top of the theme.
19
+ // This is a workaround for that issue. See https://nextjs.org/docs/pages/building-your-application/deploying/production-checklist#caching
20
+ res.setHeader('Cache-Control', 'public, max-age=0, must-revalidate');
18
21
  const { localeResolved, ...pageProps } = props;
19
22
  // If no locale was provided by Next, it most likely means that the theme is not supporting multi-language.
20
23
  // In that case we won't show 404 page.
@@ -1 +1 @@
1
- {"version":3,"file":"processRequest.js","sourceRoot":"","sources":["../../src/adapter-nextjs/processRequest.ts"],"names":[],"mappings":";;;AAAA,2DAA8F;AAG9F,kCAAuD;AAGvD;;;;;;;;GAQG;AACH,SAAgB,cAAc,CAC1B,OAAkC,EAClC,KAA8C,EAC9C,YAAqB;IAErB,IAAA,gCAAe,EAAC,gBAAgB,CAAC,CAAC;IAClC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;IAE9C,MAAM,EAAE,cAAc,EAAE,GAAG,SAAS,EAAE,GAAG,KAAK,CAAC;IAE/C,2GAA2G;IAC3G,uCAAuC;IACvC,IAAI,CAAC,cAAc,IAAI,UAAU,EAAE;QAC/B,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;KAC7B;IAED,IAAI,YAAY,EAAE;QACd,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,SAAS,CAAC,oBAAoB,CAAC;QACjE,MAAM,aAAa,GAAG,6BAAY,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;QAC3D,MAAM,kBAAkB,GAAG,IAAA,sCAAqB,EAAC,SAAS,EAAE,aAAa,CAAC,CAAC;QAE3E,MAAM,QAAQ,GAAG,IAAA,mCAA4B,EACzC,kBAAkB,EAClB,UAAU,EACV,YAAY,EACZ,KAAK,CACR,CAAC;QACF,IAAI,QAAQ,EAAE;YACV,OAAO,EAAE,QAAQ,EAAE,CAAC;SACvB;KACJ;IAED,OAAO;QACH,KAAK,EAAE,SAA8B;KACxC,CAAC;AACN,CAAC;AAnCD,wCAmCC"}
1
+ {"version":3,"file":"processRequest.js","sourceRoot":"","sources":["../../src/adapter-nextjs/processRequest.ts"],"names":[],"mappings":";;;AAAA,2DAA8F;AAG9F,kCAAuD;AAGvD;;;;;;;;GAQG;AACH,SAAgB,cAAc,CAC1B,OAAkC,EAClC,KAA8C,EAC9C,YAAqB;IAErB,IAAA,gCAAe,EAAC,gBAAgB,CAAC,CAAC;IAClC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;IAEnD,yKAAyK;IACzK,0IAA0I;IAC1I,GAAG,CAAC,SAAS,CAAC,eAAe,EAAE,oCAAoC,CAAC,CAAC;IAErE,MAAM,EAAE,cAAc,EAAE,GAAG,SAAS,EAAE,GAAG,KAAK,CAAC;IAE/C,2GAA2G;IAC3G,uCAAuC;IACvC,IAAI,CAAC,cAAc,IAAI,UAAU,EAAE;QAC/B,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;KAC7B;IAED,IAAI,YAAY,EAAE;QACd,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,SAAS,CAAC,oBAAoB,CAAC;QACjE,MAAM,aAAa,GAAG,6BAAY,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;QAC3D,MAAM,kBAAkB,GAAG,IAAA,sCAAqB,EAAC,SAAS,EAAE,aAAa,CAAC,CAAC;QAE3E,MAAM,QAAQ,GAAG,IAAA,mCAA4B,EACzC,kBAAkB,EAClB,UAAU,EACV,YAAY,EACZ,KAAK,CACR,CAAC;QACF,IAAI,QAAQ,EAAE;YACV,OAAO,EAAE,QAAQ,EAAE,CAAC;SACvB;KACJ;IAED,OAAO;QACH,KAAK,EAAE,SAA8B;KACxC,CAAC;AACN,CAAC;AAvCD,wCAuCC"}
@@ -0,0 +1,17 @@
1
+ import type { NextConfig } from 'next';
2
+ interface PrezlyConfigParams {
3
+ /**
4
+ * Enables Prezly i18n support. Defaults to `true`
5
+ */
6
+ i18n: boolean;
7
+ /**
8
+ * Enables support for Prezly images in `next/image`. Defaults to `true`
9
+ */
10
+ images: boolean;
11
+ /**
12
+ * Adds security headers recommended by Prezly. Defaults to `true`
13
+ */
14
+ recommendedHeaders: boolean;
15
+ }
16
+ export default function PrezlyConfig(params?: Partial<PrezlyConfigParams>): (config: NextConfig) => NextConfig;
17
+ export {};
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const localeConfig_1 = __importDefault(require("@prezly/theme-kit-core/localeConfig"));
7
+ const intl_1 = require("../intl");
8
+ const DEFAULT_PARAMS = {
9
+ i18n: true,
10
+ images: true,
11
+ recommendedHeaders: true,
12
+ };
13
+ // eslint-disable-next-line import/no-default-export
14
+ function PrezlyConfig(params) {
15
+ const finalParams = { ...DEFAULT_PARAMS, ...params };
16
+ return function withPrezlyConfig(config) {
17
+ const { headers } = config;
18
+ return {
19
+ ...config,
20
+ ...(finalParams.recommendedHeaders && {
21
+ async headers() {
22
+ return [
23
+ ...(typeof headers === 'function' ? await headers() : []),
24
+ {
25
+ source: '/(.*)',
26
+ locale: false,
27
+ headers: [
28
+ {
29
+ key: 'Strict-Transport-Security',
30
+ value: 'max-age=63072000; includeSubDomains; preload',
31
+ },
32
+ {
33
+ key: 'X-XSS-Protection',
34
+ value: '1; mode=block',
35
+ },
36
+ {
37
+ key: 'X-Frame-Options',
38
+ value: 'SAMEORIGIN',
39
+ },
40
+ {
41
+ key: 'X-Content-Type-Options',
42
+ value: 'nosniff',
43
+ },
44
+ {
45
+ key: 'Content-Security-Policy',
46
+ value: 'upgrade-insecure-requests; report-uri https://csp.prezly.net/report;',
47
+ },
48
+ ],
49
+ },
50
+ ];
51
+ },
52
+ }),
53
+ images: {
54
+ ...config.images,
55
+ domains: [...(config.images?.domains || []), 'cdn.uc.assets.prezly.com'],
56
+ },
57
+ ...(finalParams.i18n && {
58
+ i18n: {
59
+ ...config.i18n,
60
+ // These are all the locales you want to support in
61
+ // your application
62
+ locales: [...localeConfig_1.default, intl_1.DUMMY_DEFAULT_LOCALE],
63
+ // This is the default locale you want to be used when visiting
64
+ // a non-locale prefixed path e.g. `/hello`
65
+ // We use Pseudo locale used for localization testing, to reliably determine if we need to fallback to the default newsroom language
66
+ defaultLocale: intl_1.DUMMY_DEFAULT_LOCALE,
67
+ // Default locale detection is disabled, since the locales would be determined by Prezly API
68
+ localeDetection: false,
69
+ },
70
+ }),
71
+ };
72
+ };
73
+ }
74
+ exports.default = PrezlyConfig;
75
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":";;;;;AAAA,uFAA0D;AAG1D,kCAA+C;AAiB/C,MAAM,cAAc,GAAuB;IACvC,IAAI,EAAE,IAAI;IACV,MAAM,EAAE,IAAI;IACZ,kBAAkB,EAAE,IAAI;CAC3B,CAAC;AAEF,oDAAoD;AACpD,SAAwB,YAAY,CAAC,MAAoC;IACrE,MAAM,WAAW,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,MAAM,EAAE,CAAC;IAErD,OAAO,SAAS,gBAAgB,CAAC,MAAkB;QAC/C,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;QAE3B,OAAO;YACH,GAAG,MAAM;YACT,GAAG,CAAC,WAAW,CAAC,kBAAkB,IAAI;gBAClC,KAAK,CAAC,OAAO;oBACT,OAAO;wBACH,GAAG,CAAC,OAAO,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;wBACzD;4BACI,MAAM,EAAE,OAAO;4BACf,MAAM,EAAE,KAAK;4BACb,OAAO,EAAE;gCACL;oCACI,GAAG,EAAE,2BAA2B;oCAChC,KAAK,EAAE,8CAA8C;iCACxD;gCACD;oCACI,GAAG,EAAE,kBAAkB;oCACvB,KAAK,EAAE,eAAe;iCACzB;gCACD;oCACI,GAAG,EAAE,iBAAiB;oCACtB,KAAK,EAAE,YAAY;iCACtB;gCACD;oCACI,GAAG,EAAE,wBAAwB;oCAC7B,KAAK,EAAE,SAAS;iCACnB;gCACD;oCACI,GAAG,EAAE,yBAAyB;oCAC9B,KAAK,EAAE,sEAAsE;iCAChF;6BACJ;yBACJ;qBACJ,CAAC;gBACN,CAAC;aACJ,CAAC;YACF,MAAM,EAAE;gBACJ,GAAG,MAAM,CAAC,MAAM;gBAChB,OAAO,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,IAAI,EAAE,CAAC,EAAE,0BAA0B,CAAC;aAC3E;YACD,GAAG,CAAC,WAAW,CAAC,IAAI,IAAI;gBACpB,IAAI,EAAE;oBACF,GAAG,MAAM,CAAC,IAAI;oBACd,mDAAmD;oBACnD,mBAAmB;oBACnB,OAAO,EAAE,CAAC,GAAG,sBAAO,EAAE,2BAAoB,CAAC;oBAC3C,+DAA+D;oBAC/D,2CAA2C;oBAC3C,oIAAoI;oBACpI,aAAa,EAAE,2BAAoB;oBACnC,4FAA4F;oBAC5F,eAAe,EAAE,KAAK;iBACzB;aACJ,CAAC;SACL,CAAC;IACN,CAAC,CAAC;AACN,CAAC;AA7DD,+BA6DC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prezly/theme-kit-nextjs",
3
- "version": "5.3.0",
3
+ "version": "5.3.1-alpha.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",
@@ -10,11 +10,15 @@
10
10
  ],
11
11
  "exports": {
12
12
  ".": "./build/index.js",
13
+ "./config": "./build/config.js",
13
14
  "./server": "./build/server.js",
14
15
  "./playwright": "./build/playwright/index.js"
15
16
  },
16
17
  "typesVersions": {
17
18
  "*": {
19
+ "config": [
20
+ "build/config.d.ts"
21
+ ],
18
22
  "server": [
19
23
  "build/server.d.ts"
20
24
  ],
@@ -71,11 +75,11 @@
71
75
  "next-seo": "^5.4.0"
72
76
  },
73
77
  "devDependencies": {
74
- "@sentry/nextjs": "7.53.0"
78
+ "@sentry/nextjs": "7.53.1"
75
79
  },
76
80
  "publishConfig": {
77
81
  "access": "public"
78
82
  },
79
83
  "sideEffects": false,
80
- "gitHead": "be17fb60560d46fc7e15ae76111594251e7a0ec3"
84
+ "gitHead": "c47bc554ebe87b641bdcc9a2ace51cf8884eb096"
81
85
  }