@prezly/theme-kit-core 7.1.0 → 8.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 (248) hide show
  1. package/build/boilerplate.cjs +17 -0
  2. package/build/boilerplate.d.ts +8 -0
  3. package/build/boilerplate.mjs +9 -0
  4. package/build/constants.cjs +11 -0
  5. package/build/{utils/constants.d.ts → constants.d.ts} +2 -1
  6. package/build/constants.mjs +5 -0
  7. package/build/content-delivery/ContentDelivery.cjs +348 -0
  8. package/build/content-delivery/ContentDelivery.d.ts +8 -4
  9. package/build/content-delivery/ContentDelivery.mjs +342 -0
  10. package/build/content-delivery/cache/index.cjs +35 -0
  11. package/build/content-delivery/cache/index.d.ts +3 -0
  12. package/build/content-delivery/cache/index.mjs +3 -0
  13. package/build/content-delivery/cache/memory.cjs +64 -0
  14. package/build/content-delivery/cache/memory.d.ts +2 -0
  15. package/build/content-delivery/cache/memory.mjs +58 -0
  16. package/build/content-delivery/cache/stacked.cjs +32 -0
  17. package/build/content-delivery/cache/stacked.d.ts +2 -0
  18. package/build/content-delivery/cache/stacked.mjs +26 -0
  19. package/build/content-delivery/cache/type.cjs +1 -0
  20. package/build/content-delivery/cache/type.d.ts +8 -0
  21. package/build/content-delivery/cache/type.mjs +1 -0
  22. package/build/content-delivery/index.cjs +27 -0
  23. package/build/content-delivery/index.d.ts +2 -1
  24. package/build/content-delivery/index.mjs +2 -0
  25. package/build/environment.cjs +42 -0
  26. package/build/environment.d.ts +2 -0
  27. package/build/environment.mjs +36 -0
  28. package/build/galleries.cjs +38 -0
  29. package/build/galleries.d.ts +11 -0
  30. package/build/galleries.mjs +30 -0
  31. package/build/http/HttpClient.cjs +66 -0
  32. package/build/http/HttpClient.d.ts +20 -0
  33. package/build/http/HttpClient.mjs +59 -0
  34. package/build/http/index.cjs +10 -0
  35. package/build/http/index.d.ts +1 -0
  36. package/build/http/index.mjs +2 -0
  37. package/build/index.cjs +88 -0
  38. package/build/index.d.ts +15 -4
  39. package/build/index.mjs +26 -0
  40. package/build/intl/getLanguageDisplayName.cjs +37 -0
  41. package/build/intl/getLanguageDisplayName.d.ts +20 -0
  42. package/build/intl/getLanguageDisplayName.mjs +32 -0
  43. package/build/intl/getLanguageDisplayName.test.cjs +46 -0
  44. package/build/intl/getLanguageDisplayName.test.mjs +44 -0
  45. package/build/intl/index.cjs +12 -0
  46. package/build/intl/index.d.ts +1 -5
  47. package/build/intl/index.mjs +1 -0
  48. package/build/metadata/getAlternateLanguageLinks.cjs +76 -0
  49. package/build/{seo → metadata}/getAlternateLanguageLinks.d.ts +2 -2
  50. package/build/metadata/getAlternateLanguageLinks.mjs +72 -0
  51. package/build/metadata/getAlternateLanguageLinks.test.cjs +198 -0
  52. package/build/metadata/getAlternateLanguageLinks.test.mjs +196 -0
  53. package/build/metadata/index.cjs +12 -0
  54. package/build/metadata/index.d.ts +2 -0
  55. package/build/metadata/index.mjs +1 -0
  56. package/build/metadata/types.cjs +1 -0
  57. package/build/metadata/types.d.ts +6 -0
  58. package/build/metadata/types.mjs +1 -0
  59. package/build/newsrooms.cjs +36 -0
  60. package/build/newsrooms.d.ts +5 -0
  61. package/build/newsrooms.mjs +28 -0
  62. package/build/privacy-portal.cjs +28 -0
  63. package/build/privacy-portal.d.ts +9 -0
  64. package/build/privacy-portal.mjs +21 -0
  65. package/build/resolvable.cjs +38 -0
  66. package/build/resolvable.d.ts +71 -0
  67. package/build/resolvable.mjs +32 -0
  68. package/build/routing/Route.cjs +46 -0
  69. package/build/routing/Route.d.ts +37 -0
  70. package/build/routing/Route.mjs +40 -0
  71. package/build/routing/Router.cjs +51 -0
  72. package/build/routing/Router.d.ts +23 -0
  73. package/build/routing/Router.mjs +45 -0
  74. package/build/routing/Routing.cjs +24 -0
  75. package/build/routing/Routing.d.ts +1 -0
  76. package/build/routing/Routing.mjs +2 -0
  77. package/build/routing/UrlGenerator.cjs +13 -0
  78. package/build/routing/UrlGenerator.d.ts +39 -0
  79. package/build/routing/UrlGenerator.mjs +7 -0
  80. package/build/routing/index.cjs +24 -0
  81. package/build/routing/index.d.ts +4 -0
  82. package/build/routing/index.mjs +4 -0
  83. package/build/routing/types.cjs +1 -0
  84. package/build/routing/types.d.ts +14 -0
  85. package/build/routing/types.mjs +1 -0
  86. package/build/routing/utils/generateUrlFromPattern.cjs +52 -0
  87. package/build/routing/utils/generateUrlFromPattern.d.ts +12 -0
  88. package/build/routing/utils/generateUrlFromPattern.mjs +47 -0
  89. package/build/routing/utils/generateUrlFromPattern.test.cjs +44 -0
  90. package/build/routing/utils/generateUrlFromPattern.test.mjs +42 -0
  91. package/build/routing/utils/getShortestLocaleSlug.cjs +60 -0
  92. package/build/routing/utils/getShortestLocaleSlug.d.ts +11 -0
  93. package/build/routing/utils/getShortestLocaleSlug.mjs +53 -0
  94. package/build/routing/utils/getShortestLocaleSlug.test.cjs +37 -0
  95. package/build/routing/utils/getShortestLocaleSlug.test.mjs +35 -0
  96. package/build/routing/utils/index.cjs +40 -0
  97. package/build/routing/utils/index.d.ts +5 -0
  98. package/build/routing/utils/index.mjs +5 -0
  99. package/build/routing/utils/isNumberCode.cjs +12 -0
  100. package/build/routing/utils/isNumberCode.d.ts +4 -0
  101. package/build/routing/utils/isNumberCode.mjs +6 -0
  102. package/build/routing/utils/matchLocaleSlug.cjs +41 -0
  103. package/build/routing/utils/matchLocaleSlug.d.ts +15 -0
  104. package/build/routing/utils/matchLocaleSlug.mjs +34 -0
  105. package/build/routing/utils/matchLocaleSlug.test.cjs +43 -0
  106. package/build/routing/utils/matchLocaleSlug.test.mjs +40 -0
  107. package/build/routing/utils/normalizeUrl.cjs +9 -0
  108. package/build/routing/utils/normalizeUrl.d.ts +1 -0
  109. package/build/routing/utils/normalizeUrl.mjs +3 -0
  110. package/build/search.cjs +1 -0
  111. package/build/{types.d.ts → search.d.ts} +3 -3
  112. package/build/search.mjs +1 -0
  113. package/build/sitemap/build.cjs +33 -0
  114. package/build/sitemap/build.d.ts +6 -0
  115. package/build/sitemap/build.mjs +27 -0
  116. package/build/sitemap/generate.cjs +192 -0
  117. package/build/sitemap/generate.d.ts +37 -0
  118. package/build/sitemap/generate.mjs +183 -0
  119. package/build/sitemap/index.cjs +38 -0
  120. package/build/sitemap/index.d.ts +4 -0
  121. package/build/sitemap/index.mjs +3 -0
  122. package/build/sitemap/stringify.cjs +24 -0
  123. package/build/sitemap/stringify.d.ts +2 -0
  124. package/build/sitemap/stringify.mjs +18 -0
  125. package/build/sitemap/types.cjs +1 -0
  126. package/build/sitemap/types.d.ts +67 -0
  127. package/build/sitemap/types.mjs +1 -0
  128. package/build/uploads.cjs +14 -0
  129. package/build/{utils/getAssetsUrl.d.ts → uploads.d.ts} +1 -1
  130. package/build/uploads.mjs +8 -0
  131. package/build/uploads.test.cjs +10 -0
  132. package/build/uploads.test.mjs +8 -0
  133. package/package.json +23 -26
  134. package/build/content-delivery/ContentDelivery.js +0 -238
  135. package/build/content-delivery/ContentDelivery.js.map +0 -1
  136. package/build/content-delivery/index.js +0 -28
  137. package/build/content-delivery/index.js.map +0 -1
  138. package/build/data-fetching/api/index.d.ts +0 -1
  139. package/build/data-fetching/api/index.js +0 -6
  140. package/build/data-fetching/api/index.js.map +0 -1
  141. package/build/data-fetching/api/initContentDeliveryClient.d.ts +0 -4
  142. package/build/data-fetching/api/initContentDeliveryClient.js +0 -25
  143. package/build/data-fetching/api/initContentDeliveryClient.js.map +0 -1
  144. package/build/data-fetching/index.d.ts +0 -3
  145. package/build/data-fetching/index.js +0 -20
  146. package/build/data-fetching/index.js.map +0 -1
  147. package/build/data-fetching/lib/getAlgoliaSettings.d.ts +0 -4
  148. package/build/data-fetching/lib/getAlgoliaSettings.js +0 -21
  149. package/build/data-fetching/lib/getAlgoliaSettings.js.map +0 -1
  150. package/build/data-fetching/lib/getEnvVariables.d.ts +0 -4
  151. package/build/data-fetching/lib/getEnvVariables.js +0 -43
  152. package/build/data-fetching/lib/getEnvVariables.js.map +0 -1
  153. package/build/data-fetching/lib/index.d.ts +0 -3
  154. package/build/data-fetching/lib/index.js +0 -10
  155. package/build/data-fetching/lib/index.js.map +0 -1
  156. package/build/data-fetching/lib/isUuid.d.ts +0 -1
  157. package/build/data-fetching/lib/isUuid.js +0 -9
  158. package/build/data-fetching/lib/isUuid.js.map +0 -1
  159. package/build/data-fetching/types.d.ts +0 -13
  160. package/build/data-fetching/types.js +0 -3
  161. package/build/data-fetching/types.js.map +0 -1
  162. package/build/index.js +0 -21
  163. package/build/index.js.map +0 -1
  164. package/build/intl/getFallbackLocale.d.ts +0 -10
  165. package/build/intl/getFallbackLocale.js +0 -24
  166. package/build/intl/getFallbackLocale.js.map +0 -1
  167. package/build/intl/index.js +0 -27
  168. package/build/intl/index.js.map +0 -1
  169. package/build/intl/languages.d.ts +0 -57
  170. package/build/intl/languages.js +0 -191
  171. package/build/intl/languages.js.map +0 -1
  172. package/build/intl/locale.d.ts +0 -11
  173. package/build/intl/locale.js +0 -41
  174. package/build/intl/locale.js.map +0 -1
  175. package/build/intl/localeConfig.d.ts +0 -2
  176. package/build/intl/localeConfig.js +0 -22
  177. package/build/intl/localeConfig.js.map +0 -1
  178. package/build/intl/localeList.d.ts +0 -2
  179. package/build/intl/localeList.js +0 -114
  180. package/build/intl/localeList.js.map +0 -1
  181. package/build/intl/localeObject.d.ts +0 -51
  182. package/build/intl/localeObject.js +0 -98
  183. package/build/intl/localeObject.js.map +0 -1
  184. package/build/seo/getAlternateLanguageLinks.js +0 -85
  185. package/build/seo/getAlternateLanguageLinks.js.map +0 -1
  186. package/build/seo/index.d.ts +0 -2
  187. package/build/seo/index.js +0 -19
  188. package/build/seo/index.js.map +0 -1
  189. package/build/seo/types.d.ts +0 -4
  190. package/build/seo/types.js +0 -3
  191. package/build/seo/types.js.map +0 -1
  192. package/build/seo/utils/bindLanguagesWithLocales.d.ts +0 -11
  193. package/build/seo/utils/bindLanguagesWithLocales.js +0 -23
  194. package/build/seo/utils/bindLanguagesWithLocales.js.map +0 -1
  195. package/build/seo/utils/createAlternateLanguageLink.d.ts +0 -5
  196. package/build/seo/utils/createAlternateLanguageLink.js +0 -15
  197. package/build/seo/utils/createAlternateLanguageLink.js.map +0 -1
  198. package/build/seo/utils/index.d.ts +0 -2
  199. package/build/seo/utils/index.js +0 -8
  200. package/build/seo/utils/index.js.map +0 -1
  201. package/build/server.d.ts +0 -2
  202. package/build/server.js +0 -21
  203. package/build/server.js.map +0 -1
  204. package/build/types.js +0 -3
  205. package/build/types.js.map +0 -1
  206. package/build/utils/assertServerEnv.d.ts +0 -1
  207. package/build/utils/assertServerEnv.js +0 -10
  208. package/build/utils/assertServerEnv.js.map +0 -1
  209. package/build/utils/boilerplate.d.ts +0 -8
  210. package/build/utils/boilerplate.js +0 -27
  211. package/build/utils/boilerplate.js.map +0 -1
  212. package/build/utils/constants.js +0 -8
  213. package/build/utils/constants.js.map +0 -1
  214. package/build/utils/getAssetsUrl.js +0 -13
  215. package/build/utils/getAssetsUrl.js.map +0 -1
  216. package/build/utils/getDataRequestLink.d.ts +0 -3
  217. package/build/utils/getDataRequestLink.js +0 -12
  218. package/build/utils/getDataRequestLink.js.map +0 -1
  219. package/build/utils/getGalleryThumbnail.d.ts +0 -2
  220. package/build/utils/getGalleryThumbnail.js +0 -15
  221. package/build/utils/getGalleryThumbnail.js.map +0 -1
  222. package/build/utils/getLocalizedCategoryData.d.ts +0 -12
  223. package/build/utils/getLocalizedCategoryData.js +0 -34
  224. package/build/utils/getLocalizedCategoryData.js.map +0 -1
  225. package/build/utils/getNewsroomLogoUrl.d.ts +0 -5
  226. package/build/utils/getNewsroomLogoUrl.js +0 -30
  227. package/build/utils/getNewsroomLogoUrl.js.map +0 -1
  228. package/build/utils/getPrivacyPortalUrl.d.ts +0 -8
  229. package/build/utils/getPrivacyPortalUrl.js +0 -13
  230. package/build/utils/getPrivacyPortalUrl.js.map +0 -1
  231. package/build/utils/getStoryPublicationDate.d.ts +0 -3
  232. package/build/utils/getStoryPublicationDate.js +0 -14
  233. package/build/utils/getStoryPublicationDate.js.map +0 -1
  234. package/build/utils/getUploadcareGroupUrl.d.ts +0 -8
  235. package/build/utils/getUploadcareGroupUrl.js +0 -17
  236. package/build/utils/getUploadcareGroupUrl.js.map +0 -1
  237. package/build/utils/index.d.ts +0 -14
  238. package/build/utils/index.js +0 -31
  239. package/build/utils/index.js.map +0 -1
  240. package/build/utils/isEmbargoStory.d.ts +0 -6
  241. package/build/utils/isEmbargoStory.js +0 -9
  242. package/build/utils/isEmbargoStory.js.map +0 -1
  243. package/build/utils/isGalleryEmpty.d.ts +0 -2
  244. package/build/utils/isGalleryEmpty.js +0 -8
  245. package/build/utils/isGalleryEmpty.js.map +0 -1
  246. package/build/utils/sdkHelpers.d.ts +0 -32
  247. package/build/utils/sdkHelpers.js +0 -42
  248. package/build/utils/sdkHelpers.js.map +0 -1
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.hasAnyAboutInformation = hasAnyAboutInformation;
7
+ exports.hasAnyContactInformation = hasAnyContactInformation;
8
+ exports.hasAnySocialMedia = hasAnySocialMedia;
9
+ function hasAnySocialMedia(companyInformation) {
10
+ return Boolean(companyInformation.facebook || companyInformation.instagram || companyInformation.linkedin || companyInformation.pinterest || companyInformation.tiktok || companyInformation.twitter || companyInformation.youtube);
11
+ }
12
+ function hasAnyAboutInformation(companyInformation) {
13
+ return Boolean(companyInformation.about || companyInformation.website || hasAnySocialMedia(companyInformation));
14
+ }
15
+ function hasAnyContactInformation(companyInformation) {
16
+ return Boolean(companyInformation.address || companyInformation.phone || companyInformation.email || companyInformation.website);
17
+ }
@@ -0,0 +1,8 @@
1
+ import type { NewsroomCompanyInformation } from '@prezly/sdk';
2
+ type CompanySocialMediaInformation = Pick<NewsroomCompanyInformation, 'facebook' | 'instagram' | 'linkedin' | 'pinterest' | 'tiktok' | 'twitter' | 'youtube'>;
3
+ type CompanyAboutInformation = CompanySocialMediaInformation & Pick<NewsroomCompanyInformation, 'about' | 'website'>;
4
+ type CompanyContactInformation = Pick<NewsroomCompanyInformation, 'address' | 'phone' | 'email' | 'website'>;
5
+ export declare function hasAnySocialMedia(companyInformation: CompanySocialMediaInformation): boolean;
6
+ export declare function hasAnyAboutInformation(companyInformation: CompanyAboutInformation): boolean;
7
+ export declare function hasAnyContactInformation(companyInformation: CompanyContactInformation): boolean;
8
+ export {};
@@ -0,0 +1,9 @@
1
+ export function hasAnySocialMedia(companyInformation) {
2
+ return Boolean(companyInformation.facebook || companyInformation.instagram || companyInformation.linkedin || companyInformation.pinterest || companyInformation.tiktok || companyInformation.twitter || companyInformation.youtube);
3
+ }
4
+ export function hasAnyAboutInformation(companyInformation) {
5
+ return Boolean(companyInformation.about || companyInformation.website || hasAnySocialMedia(companyInformation));
6
+ }
7
+ export function hasAnyContactInformation(companyInformation) {
8
+ return Boolean(companyInformation.address || companyInformation.phone || companyInformation.email || companyInformation.website);
9
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.PRIVACY_PORTAL_URL = exports.OG_IMAGE_API_URL = exports.DEFAULT_PAGE_SIZE = exports.DEFAULT_GALLERY_PAGE_SIZE = exports.ASSETS_CDN_URL = void 0;
7
+ var ASSETS_CDN_URL = exports.ASSETS_CDN_URL = 'https://cdn.uc.assets.prezly.com';
8
+ var DEFAULT_PAGE_SIZE = exports.DEFAULT_PAGE_SIZE = 12;
9
+ var DEFAULT_GALLERY_PAGE_SIZE = exports.DEFAULT_GALLERY_PAGE_SIZE = 6;
10
+ var OG_IMAGE_API_URL = exports.OG_IMAGE_API_URL = 'https://og.prezly.com/api/og';
11
+ var PRIVACY_PORTAL_URL = exports.PRIVACY_PORTAL_URL = 'https://privacy.prezly.com';
@@ -1,4 +1,5 @@
1
- export declare const ASSETS_URL = "https://cdn.uc.assets.prezly.com";
1
+ export declare const ASSETS_CDN_URL = "https://cdn.uc.assets.prezly.com";
2
2
  export declare const DEFAULT_PAGE_SIZE = 12;
3
3
  export declare const DEFAULT_GALLERY_PAGE_SIZE = 6;
4
4
  export declare const OG_IMAGE_API_URL = "https://og.prezly.com/api/og";
5
+ export declare const PRIVACY_PORTAL_URL = "https://privacy.prezly.com";
@@ -0,0 +1,5 @@
1
+ export var ASSETS_CDN_URL = 'https://cdn.uc.assets.prezly.com';
2
+ export var DEFAULT_PAGE_SIZE = 12;
3
+ export var DEFAULT_GALLERY_PAGE_SIZE = 6;
4
+ export var OG_IMAGE_API_URL = 'https://og.prezly.com/api/og';
5
+ export var PRIVACY_PORTAL_URL = 'https://privacy.prezly.com';
@@ -0,0 +1,348 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.allStories = void 0;
7
+ exports.createClient = createClient;
8
+ exports.story = exports.stories = exports.galleries = void 0;
9
+ var _sdk = require("@prezly/sdk");
10
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
11
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
12
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
13
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
14
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
15
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
16
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } /* eslint-disable @typescript-eslint/no-use-before-define */
17
+ var stories;
18
+ var allStories;
19
+ var story;
20
+ var galleries;
21
+ /**
22
+ * Sort order to list stories chronologically, with pinned stories on top.
23
+ */
24
+ var CHRONOLOGICALLY = _sdk.SortOrder.combine(_sdk.SortOrder.desc('is_pinned'), _sdk.SortOrder.desc('published_at'));
25
+
26
+ /**
27
+ * Do not cache these methods, as they are derivatives of other cached methods.
28
+ */
29
+ var UNCACHED_METHODS = ['themeSettings', 'language', 'usedLanguages', 'locales', 'defaultLanguage', 'defaultLocale', 'languageOrDefault', 'companyInformation', 'notifications', 'category', 'translatedCategory', 'translatedCategories'];
30
+ function createClient(prezly, newsroomUuid, newsroomThemeUuid) {
31
+ var {
32
+ formats = [_sdk.Story.FormatVersion.SLATEJS_V4],
33
+ cache
34
+ } = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
35
+ var client = {
36
+ newsroom() {
37
+ return prezly.newsrooms.get(newsroomUuid);
38
+ },
39
+ theme() {
40
+ return newsroomThemeUuid ? prezly.newsroomThemes.get(newsroomUuid, newsroomThemeUuid) : undefined;
41
+ },
42
+ themeSettings() {
43
+ return _asyncToGenerator(function* () {
44
+ var theme = yield client.theme();
45
+ return theme === null || theme === void 0 ? void 0 : theme.settings;
46
+ })();
47
+ },
48
+ languages() {
49
+ return prezly.newsroomLanguages.list(newsroomUuid).then(data => data.languages);
50
+ },
51
+ usedLanguages() {
52
+ return _asyncToGenerator(function* () {
53
+ var languages = yield client.languages();
54
+ return languages.filter(lang => lang.public_stories_count > 0);
55
+ })();
56
+ },
57
+ locales() {
58
+ return _asyncToGenerator(function* () {
59
+ var languages = yield client.languages();
60
+ return languages.map(lang => lang.code);
61
+ })();
62
+ },
63
+ defaultLanguage() {
64
+ return _asyncToGenerator(function* () {
65
+ var languages = yield client.languages();
66
+ var defaultLanguage = languages.find(lang => lang.is_default);
67
+ if (!defaultLanguage) {
68
+ throw new Error('A newsroom is expected to always have a default language. Something is wrong.');
69
+ }
70
+ return defaultLanguage;
71
+ })();
72
+ },
73
+ companyInformation(code) {
74
+ return _asyncToGenerator(function* () {
75
+ var languageSettings = code ? yield client.languageOrDefault(code) : yield client.defaultLanguage();
76
+ return languageSettings.company_information;
77
+ })();
78
+ },
79
+ notifications(locale) {
80
+ return _asyncToGenerator(function* () {
81
+ var languageSettings = yield client.languageOrDefault(locale);
82
+ return languageSettings.notifications;
83
+ })();
84
+ },
85
+ defaultLocale() {
86
+ return _asyncToGenerator(function* () {
87
+ var defaultLanguage = yield client.defaultLanguage();
88
+ return defaultLanguage.code;
89
+ })();
90
+ },
91
+ language(code) {
92
+ return _asyncToGenerator(function* () {
93
+ var languages = yield client.languages();
94
+ return languages.find(lang => !code && lang.is_default || lang.locale.code === code);
95
+ })();
96
+ },
97
+ languageOrDefault(code) {
98
+ return _asyncToGenerator(function* () {
99
+ var _yield$client$languag;
100
+ return (_yield$client$languag = yield client.language(code)) !== null && _yield$client$languag !== void 0 ? _yield$client$languag : yield client.defaultLanguage();
101
+ })();
102
+ },
103
+ categories() {
104
+ return prezly.newsroomCategories.list(newsroomUuid, {
105
+ sortOrder: '+order'
106
+ });
107
+ },
108
+ category(arg) {
109
+ return _asyncToGenerator(function* () {
110
+ var categories = yield client.categories();
111
+ if (typeof arg === 'number') {
112
+ return categories.find(category => category.id === arg);
113
+ }
114
+ return categories.find(category => _sdk.Category.translations(category).some(translation => translation.slug === arg));
115
+ })();
116
+ },
117
+ translatedCategories(locale, categories) {
118
+ return _asyncToGenerator(function* () {
119
+ return _sdk.Category.translations(categories !== null && categories !== void 0 ? categories : yield client.categories(), locale);
120
+ })();
121
+ },
122
+ translatedCategory(locale, slug) {
123
+ return _asyncToGenerator(function* () {
124
+ var translations = yield client.translatedCategories(locale);
125
+ return translations.find(category => category.slug === slug);
126
+ })();
127
+ },
128
+ featuredContacts() {
129
+ return prezly.newsroomContacts.search(newsroomUuid, {
130
+ query: {
131
+ is_featured: true
132
+ }
133
+ });
134
+ },
135
+ galleries() {
136
+ var params = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
137
+ var {
138
+ offset,
139
+ limit,
140
+ type
141
+ } = params;
142
+ return prezly.newsroomGalleries.search(newsroomUuid, {
143
+ limit,
144
+ offset,
145
+ scope: {
146
+ status: _sdk.NewsroomGallery.Status.PUBLIC,
147
+ is_empty: false,
148
+ type
149
+ }
150
+ });
151
+ },
152
+ gallery(uuid) {
153
+ return _asyncToGenerator(function* () {
154
+ try {
155
+ return yield prezly.newsroomGalleries.get(newsroomUuid, uuid);
156
+ } catch (error) {
157
+ if (error instanceof _sdk.ApiError && isNotAvailableError(error)) {
158
+ return null;
159
+ }
160
+ throw error;
161
+ }
162
+ })();
163
+ },
164
+ stories(params) {
165
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
166
+ var {
167
+ search,
168
+ query,
169
+ offset = 0,
170
+ limit,
171
+ category,
172
+ locale,
173
+ highlighted = 0
174
+ } = params;
175
+ var {
176
+ include = []
177
+ } = options;
178
+ var localeCode = locale && typeof locale === 'object' ? locale.code : locale;
179
+ return prezly.stories.search({
180
+ sortOrder: CHRONOLOGICALLY,
181
+ formats,
182
+ limit: offset === 0 ? limit + highlighted : limit,
183
+ offset: offset > 0 ? offset + highlighted : offset,
184
+ search,
185
+ query: mergeQueries(query, {
186
+ ["category.id"]: category ? {
187
+ $any: [category.id]
188
+ } : undefined,
189
+ ["newsroom.uuid"]: {
190
+ $in: [newsroomUuid]
191
+ },
192
+ ["locale"]: localeCode ? {
193
+ $in: [localeCode]
194
+ } : undefined,
195
+ ["status"]: {
196
+ $in: [_sdk.Story.Status.PUBLISHED]
197
+ },
198
+ ["visibility"]: {
199
+ $in: [_sdk.Story.Visibility.PUBLIC]
200
+ }
201
+ }),
202
+ include
203
+ });
204
+ },
205
+ allStories() {
206
+ var _arguments = arguments;
207
+ return _asyncToGenerator(function* () {
208
+ var params = _arguments.length > 0 && _arguments[0] !== undefined ? _arguments[0] : {};
209
+ var options = _arguments.length > 1 && _arguments[1] !== undefined ? _arguments[1] : {};
210
+ var {
211
+ include = []
212
+ } = options;
213
+ var newsroom = yield client.newsroom();
214
+ var chunkSize = 200;
215
+
216
+ // Note: This is a counter of ALL stories, public, private, or drafts.
217
+ // Depending on the specific newsroom data, the rate of overfetching may be significant.
218
+ var maxStories = newsroom.stories_number;
219
+ var pages = Math.ceil(maxStories / chunkSize);
220
+ var promises = Array.from({
221
+ length: pages
222
+ }, (_, chunkIndex) => client.stories(_objectSpread(_objectSpread({}, params), {}, {
223
+ limit: chunkSize,
224
+ offset: chunkIndex * chunkSize
225
+ }), {
226
+ include
227
+ }));
228
+ return (yield Promise.all(promises)).flatMap(response => response.stories);
229
+ })();
230
+ },
231
+ story(params) {
232
+ var _arguments2 = arguments;
233
+ return _asyncToGenerator(function* () {
234
+ var options = _arguments2.length > 1 && _arguments2[1] !== undefined ? _arguments2[1] : {};
235
+ var {
236
+ include = []
237
+ } = options;
238
+ if (params.uuid) {
239
+ try {
240
+ return yield prezly.stories.get(params.uuid, {
241
+ formats,
242
+ include: [..._sdk.Stories.EXTENDED_STORY_INCLUDED_EXTRA_FIELDS, ...include]
243
+ });
244
+ } catch (error) {
245
+ if (error instanceof _sdk.ApiError && isNotAvailableError(error)) {
246
+ return null;
247
+ }
248
+ throw error;
249
+ }
250
+ }
251
+ try {
252
+ return yield prezly.stories.getBySlug(params.slug, {
253
+ formats,
254
+ query: {
255
+ ["newsroom.uuid"]: {
256
+ $in: [newsroomUuid]
257
+ },
258
+ ["status"]: {
259
+ $in: [_sdk.Story.Status.PUBLISHED, _sdk.Story.Status.EMBARGO]
260
+ },
261
+ ["visibility"]: {
262
+ $in: [_sdk.Story.Visibility.PUBLIC, _sdk.Story.Visibility.PRIVATE, _sdk.Story.Visibility.EMBARGO]
263
+ }
264
+ },
265
+ include: [..._sdk.Stories.EXTENDED_STORY_INCLUDED_EXTRA_FIELDS, ...include]
266
+ });
267
+ } catch (error) {
268
+ if (error instanceof _sdk.ApiError && isNotAvailableError(error)) {
269
+ return null;
270
+ }
271
+ throw error;
272
+ }
273
+ })();
274
+ }
275
+ };
276
+ if (cache) {
277
+ injectCache(client, cache.storage.namespace("".concat(newsroomUuid, ":").concat(newsroomThemeUuid, ":").concat(formats.join(','), ":")), cache.latestVersion, UNCACHED_METHODS);
278
+ }
279
+ return client;
280
+ }
281
+ function injectCache(client, cache, latestVersion) {
282
+ var uncachedMethods = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
283
+ var methodCalls = new Map();
284
+ var methodNames = Object.keys(client);
285
+ methodNames.forEach(methodName => {
286
+ if (uncachedMethods.includes(methodName)) {
287
+ // Do not cache this method.
288
+ return;
289
+ }
290
+ var uncachedFn = client[methodName].bind(client);
291
+
292
+ // eslint-disable-next-line no-param-reassign
293
+ client[methodName] = /*#__PURE__*/_asyncToGenerator(function* () {
294
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
295
+ args[_key] = arguments[_key];
296
+ }
297
+ var cacheKey = "".concat(methodName, ":").concat(JSON.stringify(args));
298
+ var dedupeKey = "".concat(latestVersion, ":").concat(cacheKey);
299
+
300
+ // Dedupe requests
301
+ var pending = methodCalls.get(dedupeKey);
302
+ if (pending) return pending;
303
+ function invoke() {
304
+ return _invoke.apply(this, arguments);
305
+ }
306
+ function _invoke() {
307
+ _invoke = _asyncToGenerator(function* () {
308
+ var cached = yield cache.get(cacheKey, latestVersion);
309
+ if (cached) return cached;
310
+ var value = yield uncachedFn(...args);
311
+ cache.set(cacheKey, value, latestVersion);
312
+ methodCalls.delete(dedupeKey);
313
+ return value;
314
+ });
315
+ return _invoke.apply(this, arguments);
316
+ }
317
+ var invokation = invoke();
318
+ methodCalls.set(dedupeKey, invokation);
319
+ return invokation;
320
+ });
321
+ });
322
+ }
323
+ function mergeQueries() {
324
+ for (var _len2 = arguments.length, queries = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
325
+ queries[_key2] = arguments[_key2];
326
+ }
327
+ var queryObjects = queries.filter(query => Boolean(query)).map(query => {
328
+ if (typeof query === 'string') {
329
+ return JSON.parse(query);
330
+ }
331
+ return query;
332
+ }).filter(query => Boolean(query)).filter(query => Object.keys(query).length > 0);
333
+ if (queryObjects.length === 0) {
334
+ return undefined;
335
+ }
336
+ if (queryObjects.length === 1) {
337
+ return queryObjects[0];
338
+ }
339
+ return {
340
+ $and: queryObjects
341
+ };
342
+ }
343
+ var ERROR_CODE_NOT_FOUND = 404;
344
+ var ERROR_CODE_FORBIDDEN = 403;
345
+ var ERROR_CODE_GONE = 410;
346
+ function isNotAvailableError(error) {
347
+ return error.status === ERROR_CODE_NOT_FOUND || error.status === ERROR_CODE_GONE || error.status === ERROR_CODE_FORBIDDEN;
348
+ }
@@ -1,8 +1,12 @@
1
1
  import type { Culture, Newsroom, NewsroomTheme, PrezlyClient, Query, TranslatedCategory } from '@prezly/sdk';
2
2
  import { Category, NewsroomGallery, Stories, Story } from '@prezly/sdk';
3
+ import type { Cache, UnixTimestampInSeconds } from './cache';
3
4
  export interface Options {
4
5
  formats?: Story.FormatVersion[];
5
- cache?: boolean;
6
+ cache?: {
7
+ storage: Cache;
8
+ latestVersion: UnixTimestampInSeconds;
9
+ };
6
10
  }
7
11
  export declare namespace stories {
8
12
  interface SearchParams {
@@ -40,7 +44,7 @@ export declare namespace story {
40
44
  include?: Include[];
41
45
  }
42
46
  }
43
- export declare namespace mediaAlbums {
47
+ export declare namespace galleries {
44
48
  interface SearchParams {
45
49
  offset?: number;
46
50
  limit?: number;
@@ -66,9 +70,9 @@ export declare function createClient(prezly: PrezlyClient, newsroomUuid: Newsroo
66
70
  translatedCategories(locale: Culture['code'], categories?: Category[]): Promise<TranslatedCategory[]>;
67
71
  translatedCategory(locale: Culture['code'], slug: Category.Translation['slug']): Promise<TranslatedCategory | undefined>;
68
72
  featuredContacts(): Promise<import("@prezly/sdk").NewsroomContact[]>;
69
- galleries(params?: mediaAlbums.SearchParams): Promise<import("@prezly/sdk/dist/endpoints/NewsroomGalleries").ListResponse>;
73
+ galleries(params?: galleries.SearchParams): Promise<import("@prezly/sdk/dist/endpoints/NewsroomGalleries").ListResponse>;
70
74
  gallery(uuid: NewsroomGallery['uuid']): Promise<NewsroomGallery | null>;
71
75
  stories<Include extends keyof Story.ExtraFields = never>(params: stories.SearchParams, options?: stories.IncludeOptions<Include>): Promise<Stories.ListResponse<Story & Pick<Story.ExtraFields, Include>>>;
72
76
  allStories<Include_1 extends keyof Story.ExtraFields = never>(params?: allStories.SearchParams, options?: allStories.IncludeOptions<Include_1>): Promise<(Story & Pick<Story.ExtraFields, Include_1>)[]>;
73
- story<Include_2 extends keyof Story.ExtraFields = never>(params: story.SearchParams, options?: story.IncludeOptions<Include_2>): Promise<(import("@prezly/sdk").ExtendedStory & Pick<Story.ExtraFields, "thumbnail_image" | "header_image" | "preview_image" | "social_image" | "social_text" | "tag_names" | "content" | "attached_gallery_content" | "referenced_entities" | Include_2>) | null>;
77
+ story<Include_2 extends keyof Story.ExtraFields = never>(params: story.SearchParams, options?: story.IncludeOptions<Include_2>): Promise<(import("@prezly/sdk").ExtendedStory & Pick<Story.ExtraFields, "thumbnail_image" | "content" | "header_image" | "preview_image" | "social_image" | "social_text" | "tag_names" | "attached_gallery_content" | "referenced_entities" | Include_2>) | null>;
74
78
  };