@prezly/theme-kit-nextjs 10.11.0 → 10.12.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.
@@ -39,7 +39,8 @@ function _generateCategoryPageMetadata() {
39
39
  description,
40
40
  generateUrl: localeCode => {
41
41
  var translated = _sdk.Category.translation(category, localeCode);
42
- return translated && _generateUrl('category', _objectSpread(_objectSpread({}, translated), {}, {
42
+ if (!translated || translated.public_stories_number === 0) return undefined;
43
+ return _generateUrl('category', _objectSpread(_objectSpread({}, translated), {}, {
43
44
  localeCode
44
45
  }));
45
46
  }
@@ -33,7 +33,8 @@ function _generateCategoryPageMetadata() {
33
33
  description,
34
34
  generateUrl: localeCode => {
35
35
  var translated = Category.translation(category, localeCode);
36
- return translated && _generateUrl('category', _objectSpread(_objectSpread({}, translated), {}, {
36
+ if (!translated || translated.public_stories_number === 0) return undefined;
37
+ return _generateUrl('category', _objectSpread(_objectSpread({}, translated), {}, {
37
38
  localeCode
38
39
  }));
39
40
  }
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+
3
+ var _generateCategoryPageMetadata = require("./generateCategoryPageMetadata.cjs");
4
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
5
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
6
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
7
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
8
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
9
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
10
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
11
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
12
+ function category(japaneseStories) {
13
+ return {
14
+ id: 1,
15
+ display_name: 'Contacts',
16
+ display_description: null,
17
+ stories_number: 5 + japaneseStories,
18
+ public_stories_number: 5 + japaneseStories,
19
+ image: null,
20
+ is_featured: false,
21
+ i18n: Object.fromEntries([['en', 'contacts', 3], ['fr', 'contacter', 2], ['ja_JP', 'contacts-ja', japaneseStories]].map(_ref => {
22
+ var _ref2 = _slicedToArray(_ref, 3),
23
+ code = _ref2[0],
24
+ slug = _ref2[1],
25
+ count = _ref2[2];
26
+ return [code, {
27
+ locale: {
28
+ code
29
+ },
30
+ name: 'Contacts',
31
+ description: 'Contact our team',
32
+ slug,
33
+ public_stories_number: count
34
+ }];
35
+ }))
36
+ };
37
+ }
38
+ function metadata(value) {
39
+ var languages = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ['en', 'fr', 'ja_JP'];
40
+ var locale = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'en';
41
+ var _generateUrl = (_route, params) => "https://example.com/".concat(params.localeCode, "/category/").concat('slug' in params ? params.slug : '');
42
+ return (0, _generateCategoryPageMetadata.generateCategoryPageMetadata)({
43
+ category: value,
44
+ locale,
45
+ newsroom: {
46
+ uuid: 'newsroom',
47
+ display_name: 'Newsroom'
48
+ },
49
+ companyInformation: {
50
+ name: 'Company'
51
+ },
52
+ languages: languages.map(code => ({
53
+ code,
54
+ is_default: code === 'fr'
55
+ })),
56
+ generateUrl: () => _generateUrl
57
+ });
58
+ }
59
+ describe('generateCategoryPageMetadata', () => {
60
+ it('omits empty translations and their language aliases while preserving the canonical', /*#__PURE__*/_asyncToGenerator(function* () {
61
+ var result = yield metadata(category(0));
62
+ expect(result.title).toBe('Contacts');
63
+ expect(result.description).toBe('Contact our team');
64
+ expect(result.alternates).toEqual({
65
+ canonical: 'https://example.com/en/category/contacts',
66
+ languages: {
67
+ en: 'https://example.com/en/category/contacts',
68
+ fr: 'https://example.com/fr/category/contacter',
69
+ 'x-default': 'https://example.com/en/category/contacts'
70
+ }
71
+ });
72
+ }));
73
+ it('includes Japanese and its alias when the translation has a public story', /*#__PURE__*/_asyncToGenerator(function* () {
74
+ var _result$alternates;
75
+ var result = yield metadata(category(1));
76
+ expect((_result$alternates = result.alternates) === null || _result$alternates === void 0 ? void 0 : _result$alternates.languages).toMatchObject({
77
+ ja: 'https://example.com/ja_JP/category/contacts-ja',
78
+ 'ja-JP': 'https://example.com/ja_JP/category/contacts-ja'
79
+ });
80
+ }));
81
+ it('omits missing and disabled translations', /*#__PURE__*/_asyncToGenerator(function* () {
82
+ var _result$alternates2;
83
+ var result = yield metadata(category(1), ['en', 'de']);
84
+ expect((_result$alternates2 = result.alternates) === null || _result$alternates2 === void 0 ? void 0 : _result$alternates2.languages).toEqual({
85
+ en: 'https://example.com/en/category/contacts',
86
+ 'x-default': 'https://example.com/en/category/contacts'
87
+ });
88
+ }));
89
+ it('uses a populated default language when the English category is empty', /*#__PURE__*/_asyncToGenerator(function* () {
90
+ var value = category(0);
91
+ value.i18n.en.public_stories_number = 0;
92
+ var result = yield metadata(value, ['en', 'fr', 'ja_JP'], 'fr');
93
+ expect(result.alternates).toEqual({
94
+ canonical: 'https://example.com/fr/category/contacter',
95
+ languages: {
96
+ fr: 'https://example.com/fr/category/contacter',
97
+ 'x-default': 'https://example.com/fr/category/contacter'
98
+ }
99
+ });
100
+ }));
101
+ });
@@ -0,0 +1,99 @@
1
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
2
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
3
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
4
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
5
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
6
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
7
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
8
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
9
+ import { generateCategoryPageMetadata } from "./generateCategoryPageMetadata.mjs";
10
+ function category(japaneseStories) {
11
+ return {
12
+ id: 1,
13
+ display_name: 'Contacts',
14
+ display_description: null,
15
+ stories_number: 5 + japaneseStories,
16
+ public_stories_number: 5 + japaneseStories,
17
+ image: null,
18
+ is_featured: false,
19
+ i18n: Object.fromEntries([['en', 'contacts', 3], ['fr', 'contacter', 2], ['ja_JP', 'contacts-ja', japaneseStories]].map(_ref => {
20
+ var _ref2 = _slicedToArray(_ref, 3),
21
+ code = _ref2[0],
22
+ slug = _ref2[1],
23
+ count = _ref2[2];
24
+ return [code, {
25
+ locale: {
26
+ code
27
+ },
28
+ name: 'Contacts',
29
+ description: 'Contact our team',
30
+ slug,
31
+ public_stories_number: count
32
+ }];
33
+ }))
34
+ };
35
+ }
36
+ function metadata(value) {
37
+ var languages = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ['en', 'fr', 'ja_JP'];
38
+ var locale = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'en';
39
+ var _generateUrl = (_route, params) => "https://example.com/".concat(params.localeCode, "/category/").concat('slug' in params ? params.slug : '');
40
+ return generateCategoryPageMetadata({
41
+ category: value,
42
+ locale,
43
+ newsroom: {
44
+ uuid: 'newsroom',
45
+ display_name: 'Newsroom'
46
+ },
47
+ companyInformation: {
48
+ name: 'Company'
49
+ },
50
+ languages: languages.map(code => ({
51
+ code,
52
+ is_default: code === 'fr'
53
+ })),
54
+ generateUrl: () => _generateUrl
55
+ });
56
+ }
57
+ describe('generateCategoryPageMetadata', () => {
58
+ it('omits empty translations and their language aliases while preserving the canonical', /*#__PURE__*/_asyncToGenerator(function* () {
59
+ var result = yield metadata(category(0));
60
+ expect(result.title).toBe('Contacts');
61
+ expect(result.description).toBe('Contact our team');
62
+ expect(result.alternates).toEqual({
63
+ canonical: 'https://example.com/en/category/contacts',
64
+ languages: {
65
+ en: 'https://example.com/en/category/contacts',
66
+ fr: 'https://example.com/fr/category/contacter',
67
+ 'x-default': 'https://example.com/en/category/contacts'
68
+ }
69
+ });
70
+ }));
71
+ it('includes Japanese and its alias when the translation has a public story', /*#__PURE__*/_asyncToGenerator(function* () {
72
+ var _result$alternates;
73
+ var result = yield metadata(category(1));
74
+ expect((_result$alternates = result.alternates) === null || _result$alternates === void 0 ? void 0 : _result$alternates.languages).toMatchObject({
75
+ ja: 'https://example.com/ja_JP/category/contacts-ja',
76
+ 'ja-JP': 'https://example.com/ja_JP/category/contacts-ja'
77
+ });
78
+ }));
79
+ it('omits missing and disabled translations', /*#__PURE__*/_asyncToGenerator(function* () {
80
+ var _result$alternates2;
81
+ var result = yield metadata(category(1), ['en', 'de']);
82
+ expect((_result$alternates2 = result.alternates) === null || _result$alternates2 === void 0 ? void 0 : _result$alternates2.languages).toEqual({
83
+ en: 'https://example.com/en/category/contacts',
84
+ 'x-default': 'https://example.com/en/category/contacts'
85
+ });
86
+ }));
87
+ it('uses a populated default language when the English category is empty', /*#__PURE__*/_asyncToGenerator(function* () {
88
+ var value = category(0);
89
+ value.i18n.en.public_stories_number = 0;
90
+ var result = yield metadata(value, ['en', 'fr', 'ja_JP'], 'fr');
91
+ expect(result.alternates).toEqual({
92
+ canonical: 'https://example.com/fr/category/contacter',
93
+ languages: {
94
+ fr: 'https://example.com/fr/category/contacter',
95
+ 'x-default': 'https://example.com/fr/category/contacter'
96
+ }
97
+ });
98
+ }));
99
+ });
package/package.json CHANGED
@@ -1,114 +1,115 @@
1
1
  {
2
- "name": "@prezly/theme-kit-nextjs",
3
- "version": "10.11.0",
4
- "description": "Data layer and utility library for developing Prezly themes with NextJS",
5
- "type": "module",
6
- "main": "build/index.mjs",
7
- "types": "build/index.d.ts",
8
- "files": [
9
- "build",
10
- "README.md"
11
- ],
12
- "exports": {
13
- ".": {
14
- "types": "./build/index.d.ts",
15
- "require": "./build/index.cjs",
16
- "default": "./build/index.mjs"
2
+ "name": "@prezly/theme-kit-nextjs",
3
+ "version": "10.12.0",
4
+ "description": "Data layer and utility library for developing Prezly themes with NextJS",
5
+ "type": "module",
6
+ "main": "build/index.mjs",
7
+ "types": "build/index.d.ts",
8
+ "files": [
9
+ "build",
10
+ "README.md"
11
+ ],
12
+ "exports": {
13
+ ".": {
14
+ "types": "./build/index.d.ts",
15
+ "require": "./build/index.cjs",
16
+ "default": "./build/index.mjs"
17
+ },
18
+ "./server": {
19
+ "types": "./build/server.d.ts",
20
+ "require": "./build/server.cjs",
21
+ "default": "./build/server.mjs"
22
+ },
23
+ "./middleware": {
24
+ "types": "./build/middleware/index.d.ts",
25
+ "require": "./build/middleware/index.cjs",
26
+ "default": "./build/middleware/index.mjs"
27
+ },
28
+ "./next-config": {
29
+ "types": "./build/next-config/index.d.ts",
30
+ "require": "./build/next-config/index.cjs",
31
+ "default": "./build/next-config/index.mjs"
32
+ },
33
+ "./sentry": {
34
+ "types": "./build/sentry/index.d.ts",
35
+ "require": "./build/sentry/index.cjs",
36
+ "default": "./build/sentry/index.mjs"
37
+ },
38
+ "./playwright": {
39
+ "types": "./build/playwright/index.d.ts",
40
+ "require": "./build/playwright/index.cjs",
41
+ "default": "./build/playwright/index.mjs"
42
+ }
17
43
  },
18
- "./server": {
19
- "types": "./build/server.d.ts",
20
- "require": "./build/server.cjs",
21
- "default": "./build/server.mjs"
44
+ "engines": {
45
+ "node": ">= 18.18.0",
46
+ "npm": ">= 8.x"
22
47
  },
23
- "./middleware": {
24
- "types": "./build/middleware/index.d.ts",
25
- "require": "./build/middleware/index.cjs",
26
- "default": "./build/middleware/index.mjs"
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "git+https://github.com/prezly/theme-kit-js.git",
51
+ "directory": "packages/nextjs"
27
52
  },
28
- "./next-config": {
29
- "types": "./build/next-config/index.d.ts",
30
- "require": "./build/next-config/index.cjs",
31
- "default": "./build/next-config/index.mjs"
53
+ "keywords": [
54
+ "prezly",
55
+ "nextjs"
56
+ ],
57
+ "author": "Prezly Team",
58
+ "license": "MIT",
59
+ "bugs": {
60
+ "url": "https://github.com/prezly/theme-kit-js/issues"
32
61
  },
33
- "./sentry": {
34
- "types": "./build/sentry/index.d.ts",
35
- "require": "./build/sentry/index.cjs",
36
- "default": "./build/sentry/index.mjs"
62
+ "homepage": "https://github.com/prezly/theme-kit-js/tree/main/packages/nextjs#readme",
63
+ "scripts": {
64
+ "prepack": "pnpm test:build",
65
+ "prebuild": "rimraf --glob build/* *.tsbuildinfo",
66
+ "build": "pnpm build:types && pnpm build:esm && pnpm build:cjs",
67
+ "build:types": "tsc --project .",
68
+ "build:esm": "babel --config-file=../../babel.esm.json src/ --extensions=.ts,.tsx --out-dir=build/ --out-file-extension=.mjs",
69
+ "build:cjs": "babel --config-file=../../babel.cjs.json src/ --extensions=.ts,.tsx --out-dir=build/ --out-file-extension=.cjs",
70
+ "dev": "tsc --watch --preserveWatchOutput --project .",
71
+ "typecheck": "tsc --noEmit --emitDeclarationOnly false --incremental --project .",
72
+ "lint": "biome lint src",
73
+ "lint:fix": "biome lint --write src",
74
+ "format": "biome format src",
75
+ "format:fix": "biome format --write src",
76
+ "test": "pnpm test:unit && pnpm test:build",
77
+ "test:unit": "jest",
78
+ "test:redis": "node tests/test-redis-resilience.cjs",
79
+ "test:build": "pnpm test:build:cjs && pnpm test:build:esm && pnpm test:build:types",
80
+ "test:build:types": "tsc --esModuleInterop --noEmit --target es2020 --moduleResolution node tests/test-build-types.ts",
81
+ "test:build:esm": "node tests/test-build.mjs",
82
+ "test:build:cjs": "node tests/test-build.cjs"
37
83
  },
38
- "./playwright": {
39
- "types": "./build/playwright/index.d.ts",
40
- "require": "./build/playwright/index.cjs",
41
- "default": "./build/playwright/index.mjs"
42
- }
43
- },
44
- "engines": {
45
- "node": ">= 18.18.0",
46
- "npm": ">= 8.x"
47
- },
48
- "repository": {
49
- "type": "git",
50
- "url": "git+https://github.com/prezly/theme-kit-js.git",
51
- "directory": "packages/nextjs"
52
- },
53
- "keywords": [
54
- "prezly",
55
- "nextjs"
56
- ],
57
- "author": "Prezly Team",
58
- "license": "MIT",
59
- "bugs": {
60
- "url": "https://github.com/prezly/theme-kit-js/issues"
61
- },
62
- "homepage": "https://github.com/prezly/theme-kit-js/tree/main/packages/nextjs#readme",
63
- "peerDependencies": {
64
- "@playwright/test": "1.x",
65
- "@prezly/sdk": "21.12.0 || ^23.x",
66
- "next": "^14.x || ^15.x",
67
- "react": "^18.x || ^19.x",
68
- "react-dom": "^18.x || ^19.x"
69
- },
70
- "peerDependenciesMeta": {
71
- "@playwright/test": {
72
- "optional": true
73
- }
74
- },
75
- "dependencies": {
76
- "@noble/hashes": "1.8.0",
77
- "@technically/is-not-undefined": "^1.0.0",
78
- "@technically/omit-undefined": "^1.0.4",
79
- "json-stable-stringify": "^1.2.1",
80
- "redis": "^4.7.0",
81
- "url-pattern": "^1.0.3",
82
- "@prezly/theme-kit-core": "^10.11.0",
83
- "@prezly/theme-kit-react": "^10.9.1",
84
- "@prezly/theme-kit-intl": "^10.9.1"
85
- },
86
- "devDependencies": {
87
- "@sentry/nextjs": "7.120.4"
88
- },
89
- "publishConfig": {
90
- "access": "public"
91
- },
92
- "sideEffects": false,
93
- "gitHead": "51b1ce99cf8ce2c886001077bcaf95cb143f86ce",
94
- "scripts": {
95
- "prebuild": "rimraf --glob build/* *.tsbuildinfo",
96
- "build": "pnpm build:types && pnpm build:esm && pnpm build:cjs",
97
- "build:types": "tsc --project .",
98
- "build:esm": "babel --config-file=../../babel.esm.json src/ --extensions=.ts,.tsx --out-dir=build/ --out-file-extension=.mjs",
99
- "build:cjs": "babel --config-file=../../babel.cjs.json src/ --extensions=.ts,.tsx --out-dir=build/ --out-file-extension=.cjs",
100
- "dev": "tsc --watch --preserveWatchOutput --project .",
101
- "typecheck": "tsc --noEmit --emitDeclarationOnly false --incremental --project .",
102
- "lint": "biome lint src",
103
- "lint:fix": "biome lint --write src",
104
- "format": "biome format src",
105
- "format:fix": "biome format --write src",
106
- "test": "pnpm test:unit && pnpm test:build",
107
- "test:unit": "jest",
108
- "test:redis": "node tests/test-redis-resilience.cjs",
109
- "test:build": "pnpm test:build:cjs && pnpm test:build:esm && pnpm test:build:types",
110
- "test:build:types": "tsc --esModuleInterop --noEmit --target es2020 --moduleResolution node tests/test-build-types.ts",
111
- "test:build:esm": "node tests/test-build.mjs",
112
- "test:build:cjs": "node tests/test-build.cjs"
113
- }
114
- }
84
+ "peerDependencies": {
85
+ "@playwright/test": "1.x",
86
+ "@prezly/sdk": "21.12.0 || ^23.x",
87
+ "next": "^14.x || ^15.x",
88
+ "react": "^18.x || ^19.x",
89
+ "react-dom": "^18.x || ^19.x"
90
+ },
91
+ "peerDependenciesMeta": {
92
+ "@playwright/test": {
93
+ "optional": true
94
+ }
95
+ },
96
+ "dependencies": {
97
+ "@noble/hashes": "1.8.0",
98
+ "@prezly/theme-kit-core": "^10.12.0",
99
+ "@prezly/theme-kit-intl": "^10.12.0",
100
+ "@prezly/theme-kit-react": "^10.12.0",
101
+ "@technically/is-not-undefined": "^1.0.0",
102
+ "@technically/omit-undefined": "^1.0.4",
103
+ "json-stable-stringify": "^1.2.1",
104
+ "redis": "^4.7.0",
105
+ "url-pattern": "^1.0.3"
106
+ },
107
+ "devDependencies": {
108
+ "@sentry/nextjs": "7.120.4"
109
+ },
110
+ "publishConfig": {
111
+ "access": "public"
112
+ },
113
+ "sideEffects": false,
114
+ "gitHead": "aa8fe2c8311ddf0c5aa2329da15e086b12a81d96"
115
+ }