@akinon/next 2.0.0-beta.2 → 2.0.0-beta.3

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/CHANGELOG.md CHANGED
@@ -1,9 +1,19 @@
1
1
  # @akinon/next
2
2
 
3
+ ## 2.0.0-beta.3
4
+
5
+ ### Minor Changes
6
+
7
+ - 5536b80: ZERO-3104: Add optional headers parameter
8
+
3
9
  ## 2.0.0-beta.2
4
10
 
5
11
  ### Minor Changes
6
12
 
13
+ - a006015: ZERO-3116: Add not-found page and update default middleware.
14
+ - 999168d: ZERO-3104: Remove local cache handler from CacheHandler initialization
15
+ - 1eeb3d8: ZERO-3116: Add not found page
16
+ - 86a5a62: ZERO-3104: Add optional headers parameter to data fetching functions
7
17
  - dd69cc6: ZERO-3079: Modularize pre-order middleware
8
18
 
9
19
  ## 2.0.0-beta.1
@@ -7,7 +7,8 @@ import { ServerVariables } from '../../utils/server-variables';
7
7
  const getFlatPageDataHandler = (
8
8
  pk: number,
9
9
  locale: string,
10
- currency: string
10
+ currency: string,
11
+ headers?: Record<string, string>
11
12
  ) => {
12
13
  return async function () {
13
14
  const data = await appFetch<FlatPage>({
@@ -17,7 +18,8 @@ const getFlatPageDataHandler = (
17
18
  init: {
18
19
  headers: {
19
20
  Accept: 'application/json',
20
- 'Content-Type': 'application/json'
21
+ 'Content-Type': 'application/json',
22
+ ...(headers ?? {})
21
23
  }
22
24
  }
23
25
  });
@@ -29,15 +31,17 @@ const getFlatPageDataHandler = (
29
31
  export const getFlatPageData = ({
30
32
  pk,
31
33
  locale = ServerVariables.locale,
32
- currency = ServerVariables.currency
34
+ currency = ServerVariables.currency,
35
+ headers
33
36
  }: {
34
37
  pk: number;
35
38
  locale?: string;
36
39
  currency?: string;
40
+ headers?: Record<string, string>;
37
41
  }) => {
38
42
  return Cache.wrap(
39
43
  CacheKey.FlatPage(pk),
40
44
  locale,
41
- getFlatPageDataHandler(pk, locale, currency)
45
+ getFlatPageDataHandler(pk, locale, currency, headers)
42
46
  );
43
47
  };
@@ -5,7 +5,12 @@ import appFetch from '../../utils/app-fetch';
5
5
  import { ServerVariables } from '../../utils/server-variables';
6
6
  import { form } from '../urls';
7
7
 
8
- const getFormDataHandler = (pk: number, locale: string, currency: string) => {
8
+ const getFormDataHandler = (
9
+ pk: number,
10
+ locale: string,
11
+ currency: string,
12
+ headers?: Record<string, string>
13
+ ) => {
9
14
  return async function () {
10
15
  const data = await appFetch<FormType>({
11
16
  url: form.getForm(pk),
@@ -14,7 +19,8 @@ const getFormDataHandler = (pk: number, locale: string, currency: string) => {
14
19
  init: {
15
20
  headers: {
16
21
  Accept: 'application/json',
17
- 'Content-Type': 'application/json'
22
+ 'Content-Type': 'application/json',
23
+ ...(headers ?? {})
18
24
  }
19
25
  }
20
26
  });
@@ -26,15 +32,17 @@ const getFormDataHandler = (pk: number, locale: string, currency: string) => {
26
32
  export const getFormData = ({
27
33
  pk,
28
34
  locale = ServerVariables.locale,
29
- currency = ServerVariables.currency
35
+ currency = ServerVariables.currency,
36
+ headers
30
37
  }: {
31
38
  pk: number;
32
39
  locale?: string;
33
40
  currency?: string;
41
+ headers?: Record<string, string>;
34
42
  }) => {
35
43
  return Cache.wrap(
36
44
  CacheKey.Form(pk),
37
45
  locale,
38
- getFormDataHandler(pk, locale, currency)
46
+ getFormDataHandler(pk, locale, currency, headers)
39
47
  );
40
48
  };
@@ -7,7 +7,8 @@ import { ServerVariables } from '../../utils/server-variables';
7
7
  const getLandingPageHandler = (
8
8
  pk: number,
9
9
  locale: string,
10
- currency: string
10
+ currency: string,
11
+ headers?: Record<string, string>
11
12
  ) => {
12
13
  return async function () {
13
14
  const data = await appFetch<LandingPage>({
@@ -17,7 +18,8 @@ const getLandingPageHandler = (
17
18
  init: {
18
19
  headers: {
19
20
  Accept: 'application/json',
20
- 'Content-Type': 'application/json'
21
+ 'Content-Type': 'application/json',
22
+ ...(headers ?? {})
21
23
  }
22
24
  }
23
25
  });
@@ -29,15 +31,17 @@ const getLandingPageHandler = (
29
31
  export const getLandingPageData = ({
30
32
  pk,
31
33
  locale = ServerVariables.locale,
32
- currency = ServerVariables.currency
34
+ currency = ServerVariables.currency,
35
+ headers
33
36
  }: {
34
37
  pk: number;
35
38
  locale?: string;
36
39
  currency?: string;
40
+ headers?: Record<string, string>;
37
41
  }) => {
38
42
  return Cache.wrap(
39
43
  CacheKey.LandingPage(pk),
40
44
  locale,
41
- getLandingPageHandler(pk, locale, currency)
45
+ getLandingPageHandler(pk, locale, currency, headers)
42
46
  );
43
47
  };
@@ -13,6 +13,7 @@ interface MenuHandlerParams {
13
13
  currency?: string;
14
14
  depth?: number;
15
15
  parent?: string;
16
+ headers?: Record<string, string>;
16
17
  }
17
18
 
18
19
  const DEFAULT_DEPTH = 3;
@@ -22,13 +23,17 @@ const getMenuHandler =
22
23
  locale = ServerVariables.locale,
23
24
  currency = ServerVariables.currency,
24
25
  depth,
25
- parent
26
+ parent,
27
+ headers
26
28
  }: MenuHandlerParams = {}) =>
27
29
  async () => {
28
30
  const response = await appFetch<MenuResponse>({
29
31
  url: misc.menus(depth ?? DEFAULT_DEPTH, parent),
30
32
  locale,
31
- currency
33
+ currency,
34
+ init: {
35
+ headers
36
+ }
32
37
  });
33
38
 
34
39
  return response?.menu;
@@ -11,6 +11,7 @@ type GetProduct = {
11
11
  currency?: string;
12
12
  searchParams?: URLSearchParams;
13
13
  groupProduct?: boolean;
14
+ headers?: Record<string, string>;
14
15
  };
15
16
 
16
17
  const getProductDataHandler = ({
@@ -18,7 +19,8 @@ const getProductDataHandler = ({
18
19
  locale,
19
20
  currency,
20
21
  searchParams,
21
- groupProduct
22
+ groupProduct,
23
+ headers
22
24
  }: GetProduct) => {
23
25
  return async function () {
24
26
  let url = groupProduct
@@ -40,7 +42,8 @@ const getProductDataHandler = ({
40
42
  init: {
41
43
  headers: {
42
44
  Accept: 'application/json',
43
- 'Content-Type': 'application/json'
45
+ 'Content-Type': 'application/json',
46
+ ...(headers ?? {})
44
47
  }
45
48
  }
46
49
  });
@@ -95,7 +98,8 @@ export const getProductData = async ({
95
98
  locale = ServerVariables.locale,
96
99
  currency = ServerVariables.currency,
97
100
  searchParams,
98
- groupProduct
101
+ groupProduct,
102
+ headers
99
103
  }: GetProduct) => {
100
104
  return Cache.wrap(
101
105
  CacheKey[groupProduct ? 'GroupProduct' : 'Product'](
@@ -103,7 +107,14 @@ export const getProductData = async ({
103
107
  searchParams ?? new URLSearchParams()
104
108
  ),
105
109
  locale,
106
- getProductDataHandler({ pk, locale, currency, searchParams, groupProduct }),
110
+ getProductDataHandler({
111
+ pk,
112
+ locale,
113
+ currency,
114
+ searchParams,
115
+ groupProduct,
116
+ headers
117
+ }),
107
118
  {
108
119
  expire: 300
109
120
  }
@@ -7,9 +7,10 @@ interface SeoDataParams {
7
7
  url: string;
8
8
  locale?: string;
9
9
  currency?: string;
10
+ headers?: Record<string, string>;
10
11
  }
11
12
 
12
- function getSeoDataHandler({ url, locale, currency }: SeoDataParams) {
13
+ function getSeoDataHandler({ url, locale, currency, headers }: SeoDataParams) {
13
14
  return async function () {
14
15
  let data = {} as {
15
16
  title: string;
@@ -19,7 +20,12 @@ function getSeoDataHandler({ url, locale, currency }: SeoDataParams) {
19
20
  };
20
21
 
21
22
  try {
22
- data = await appFetch({ url: misc.cmsSeo(url), locale, currency });
23
+ data = await appFetch({
24
+ url: misc.cmsSeo(url),
25
+ locale,
26
+ currency,
27
+ init: { headers }
28
+ });
23
29
  } catch (error) {
24
30
  // logger.error('Error while fetching seo data', { url, error });
25
31
  }
@@ -31,11 +37,12 @@ function getSeoDataHandler({ url, locale, currency }: SeoDataParams) {
31
37
  export const getSeoData = async (
32
38
  url,
33
39
  locale = ServerVariables.locale,
34
- currency = ServerVariables.currency
40
+ currency = ServerVariables.currency,
41
+ headers?: Record<string, string>
35
42
  ) => {
36
43
  return Cache.wrap(
37
44
  CacheKey.Seo(url),
38
45
  locale,
39
- getSeoDataHandler({ url, locale, currency })
46
+ getSeoDataHandler({ url, locale, currency, headers })
40
47
  );
41
48
  };
@@ -6,29 +6,44 @@ import { widgets } from '../urls';
6
6
  import { ServerVariables } from '../../utils/server-variables';
7
7
 
8
8
  const getWidgetDataHandler =
9
- (slug: string, locale: string, currency: string) => async () => {
9
+ (
10
+ slug: string,
11
+ locale: string,
12
+ currency: string,
13
+ headers?: Record<string, string>
14
+ ) =>
15
+ async () => {
10
16
  if (!slug) {
11
17
  return null;
12
18
  }
13
19
 
14
- return await appFetch({ url: widgets.getWidget(slug), locale, currency });
20
+ return await appFetch({
21
+ url: widgets.getWidget(slug),
22
+ locale,
23
+ currency,
24
+ init: {
25
+ headers
26
+ }
27
+ });
15
28
  };
16
29
 
17
30
  export const getWidgetData = async <T>({
18
31
  slug,
19
32
  locale = ServerVariables.locale,
20
33
  currency = ServerVariables.currency,
21
- cacheOptions
34
+ cacheOptions,
35
+ headers
22
36
  }: {
23
37
  slug: string;
24
38
  locale?: string;
25
39
  currency?: string;
26
40
  cacheOptions?: CacheOptions;
41
+ headers?: Record<string, string>;
27
42
  }): Promise<WidgetResultType<T>> => {
28
43
  return Cache.wrap(
29
44
  CacheKey.Widget(slug),
30
45
  locale,
31
- getWidgetDataHandler(slug, locale, currency),
46
+ getWidgetDataHandler(slug, locale, currency, headers),
32
47
  cacheOptions
33
48
  );
34
49
  };
@@ -23,10 +23,10 @@ CacheHandler.onCreation(async () => {
23
23
  timeoutMs: 5000
24
24
  });
25
25
 
26
- const localHandler = createLruHandler();
26
+ // const localHandler = createLruHandler();
27
27
 
28
28
  return {
29
- handlers: [redisHandler, localHandler]
29
+ handlers: [redisHandler]
30
30
  };
31
31
  });
32
32
 
@@ -288,19 +288,6 @@ const withPzDefault =
288
288
  `searchparams|${url.searchParams.toString()}`;
289
289
  }
290
290
 
291
- if (
292
- !req.middlewareParams.found &&
293
- Settings.customNotFoundEnabled
294
- ) {
295
- let pathname = url.pathname
296
- .replace(/\/+$/, '')
297
- .split('/');
298
- url.pathname = url.pathname.replace(
299
- pathname.pop(),
300
- 'pz-not-found'
301
- );
302
- }
303
-
304
291
  Settings.rewrites.forEach((rewrite) => {
305
292
  url.pathname = url.pathname.replace(
306
293
  rewrite.source,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@akinon/next",
3
3
  "description": "Core package for Project Zero Next",
4
- "version": "2.0.0-beta.2",
4
+ "version": "2.0.0-beta.3",
5
5
  "private": false,
6
6
  "license": "MIT",
7
7
  "bin": {
@@ -30,7 +30,7 @@
30
30
  "set-cookie-parser": "2.6.0"
31
31
  },
32
32
  "devDependencies": {
33
- "@akinon/eslint-plugin-projectzero": "2.0.0-beta.2",
33
+ "@akinon/eslint-plugin-projectzero": "2.0.0-beta.3",
34
34
  "@types/react-redux": "7.1.30",
35
35
  "@types/set-cookie-parser": "2.4.7",
36
36
  "@typescript-eslint/eslint-plugin": "8.18.2",
package/types/index.ts CHANGED
@@ -199,7 +199,6 @@ export interface Settings {
199
199
  extraPaymentTypes?: string[];
200
200
  masterpassJsUrl?: string;
201
201
  };
202
- customNotFoundEnabled: boolean;
203
202
  useOptimizedTranslations?: boolean;
204
203
  plugins?: Record<string, Record<string, any>>;
205
204
  includedProxyHeaders?: string[];