@jpmorganchase/mosaic-site-middleware 0.1.0-beta.21 → 0.1.0-beta.23

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.
@@ -1,2 +1,2 @@
1
- @jpmorganchase/mosaic-site-middleware:build: cache hit, replaying output eebc1a386641880b
1
+ @jpmorganchase/mosaic-site-middleware:build: cache hit, replaying output 00de0937a50cf8b8
2
2
  @jpmorganchase/mosaic-site-middleware:build: $ tsc
package/CHANGELOG.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # @jpmorganchase/mosaic-site-middleware
2
2
 
3
+ ## 0.1.0-beta.23
4
+
5
+ ### Patch Changes
6
+
7
+ - 513d45f: Sidebar behavior and styling changes.
8
+ Add Client-side search feature.
9
+ Relax node engine requirements.
10
+ Removal of patches from the site package.
11
+ Update site generator templates.
12
+ - Updated dependencies [513d45f]
13
+ - @jpmorganchase/mosaic-schemas@0.1.0-beta.23
14
+ - @jpmorganchase/mosaic-store@0.1.0-beta.23
15
+ - @jpmorganchase/mosaic-types@0.1.0-beta.23
16
+
17
+ ## 0.1.0-beta.22
18
+
19
+ ### Patch Changes
20
+
21
+ - be89e4f: fix markdown tables and update generator's Salt patches
22
+
23
+ - Salt patches in generator were out of sync with Mosaic repo
24
+ - Markdown now support github flavoured markdown, such as Tables
25
+
26
+ - Updated dependencies [be89e4f]
27
+ - @jpmorganchase/mosaic-schemas@0.1.0-beta.22
28
+ - @jpmorganchase/mosaic-store@0.1.0-beta.22
29
+ - @jpmorganchase/mosaic-types@0.1.0-beta.22
30
+
3
31
  ## 0.1.0-beta.21
4
32
 
5
33
  ### Patch Changes
@@ -1,11 +1,12 @@
1
1
  import { serialize } from 'next-mdx-remote/serialize';
2
+ import remarkGfm from 'remark-gfm';
2
3
  import rehypeSlug from 'rehype-slug';
3
4
  import { codeBlocks } from './plugins/codeBlocks.js';
4
5
  export async function compileMDX(content, parseFrontmatter = true, rehypePlugins = [], remarkPlugins = []) {
5
6
  const mdxSource = await serialize(content, {
6
7
  mdxOptions: {
7
8
  rehypePlugins: [rehypeSlug, ...remarkPlugins],
8
- remarkPlugins: [codeBlocks, ...rehypePlugins]
9
+ remarkPlugins: [codeBlocks, remarkGfm, ...rehypePlugins]
9
10
  },
10
11
  parseFrontmatter
11
12
  });
@@ -1 +1 @@
1
- {"version":3,"file":"compileMdx.js","sourceRoot":"","sources":["../src/compileMdx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,OAAO,EACP,gBAAgB,GAAG,IAAI,EACvB,aAAa,GAAG,EAAE,EAClB,aAAa,GAAG,EAAE;IAElB,MAAM,SAAS,GAAG,MAAM,SAAS,CAAC,OAAO,EAAE;QACzC,UAAU,EAAE;YACV,aAAa,EAAE,CAAC,UAAU,EAAE,GAAG,aAAa,CAAC;YAC7C,aAAa,EAAE,CAAC,UAAU,EAAE,GAAG,aAAa,CAAC;SAC9C;QACD,gBAAgB;KACjB,CAAC,CAAC;IACH,OAAO,SAAS,CAAC;AACnB,CAAC"}
1
+ {"version":3,"file":"compileMdx.js","sourceRoot":"","sources":["../src/compileMdx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AACtD,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,OAAO,EACP,gBAAgB,GAAG,IAAI,EACvB,aAAa,GAAG,EAAE,EAClB,aAAa,GAAG,EAAE;IAElB,MAAM,SAAS,GAAG,MAAM,SAAS,CAAC,OAAO,EAAE;QACzC,UAAU,EAAE;YACV,aAAa,EAAE,CAAC,UAAU,EAAE,GAAG,aAAa,CAAC;YAC7C,aAAa,EAAE,CAAC,UAAU,EAAE,SAAS,EAAE,GAAG,aAAa,CAAC;SACzD;QACD,gBAAgB;KACjB,CAAC,CAAC;IACH,OAAO,SAAS,CAAC;AACnB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -4,5 +4,6 @@ export * from './MiddlewareError.js';
4
4
  export * from './middlewarePresets.js';
5
5
  export * from './withMDXContent.js';
6
6
  export * from './withMosaicMode.js';
7
+ export * from './withSearchIndex.js';
7
8
  export * from './withSession.js';
8
9
  export * from './withSharedConfig.js';
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ export * from './MiddlewareError.js';
4
4
  export * from './middlewarePresets.js';
5
5
  export * from './withMDXContent.js';
6
6
  export * from './withMosaicMode.js';
7
+ export * from './withSearchIndex.js';
7
8
  export * from './withSession.js';
8
9
  export * from './withSharedConfig.js';
9
10
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { Redirect } from 'next';
2
- import { SharedConfigSlice } from '@jpmorganchase/mosaic-store';
2
+ import { SearchIndexSlice, SharedConfigSlice } from '@jpmorganchase/mosaic-store';
3
3
  import type { ContentProps } from '@jpmorganchase/mosaic-types';
4
4
  import { MosaicMiddleware, MosaicMiddlewareWithConfig } from './createMiddlewareRunner.js';
5
5
  import { type MosaicModeProps } from './withMosaicMode.js';
@@ -28,6 +28,6 @@ export declare type MosaicAppProps<T> = {
28
28
  /** Mosaic getServerSideProps result which supports error handling */
29
29
  export declare type GetMosaicServerSidePropsResult<T> = MosaicAppProps<T>;
30
30
  /** MiddlewarePresets props */
31
- export declare type MiddlewarePresetsProps = MosaicModeProps & ContentProps & SharedConfigSlice;
31
+ export declare type MiddlewarePresetsProps = MosaicModeProps & ContentProps & SearchIndexSlice & SharedConfigSlice;
32
32
  /** A collection of preset [[`Middleware`]] plugins that will compose together the page props */
33
33
  export declare const middlewarePresets: Array<MosaicMiddleware<MiddlewarePresetsProps> | MosaicMiddlewareWithConfig<MiddlewarePresetsProps, unknown>>;
@@ -1,6 +1,7 @@
1
+ import { withSearchIndex } from './withSearchIndex.js';
1
2
  import { withSharedConfig } from './withSharedConfig.js';
2
3
  import { withMDXContent } from './withMDXContent.js';
3
4
  import { withMosaicMode } from './withMosaicMode.js';
4
5
  /** A collection of preset [[`Middleware`]] plugins that will compose together the page props */
5
- export const middlewarePresets = [withMosaicMode, withSharedConfig, withMDXContent];
6
+ export const middlewarePresets = [withMosaicMode, withSharedConfig, withMDXContent, withSearchIndex];
6
7
  //# sourceMappingURL=middlewarePresets.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"middlewarePresets.js","sourceRoot":"","sources":["../src/middlewarePresets.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,EAAE,cAAc,EAAwB,MAAM,qBAAqB,CAAC;AAgC3E,gGAAgG;AAChG,MAAM,CAAC,MAAM,iBAAiB,GAG1B,CAAC,cAAc,EAAE,gBAAgB,EAAE,cAAc,CAAC,CAAC"}
1
+ {"version":3,"file":"middlewarePresets.js","sourceRoot":"","sources":["../src/middlewarePresets.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,EAAE,cAAc,EAAwB,MAAM,qBAAqB,CAAC;AAmC3E,gGAAgG;AAChG,MAAM,CAAC,MAAM,iBAAiB,GAG1B,CAAC,cAAc,EAAE,gBAAgB,EAAE,cAAc,EAAE,eAAe,CAAC,CAAC"}
@@ -0,0 +1,25 @@
1
+ import type { SearchIndex, SearchIndexSlice } from '@jpmorganchase/mosaic-store';
2
+ import { MosaicMiddleware } from './createMiddlewareRunner.js';
3
+ export { SearchIndex };
4
+ /**
5
+ * Fetch search-data.json
6
+ *
7
+ * @param url the search data file URL
8
+ * @returns search data JSON
9
+ */
10
+ export declare function fetchSearchData(url: string): Promise<Response>;
11
+ /**
12
+ * Get environment vars
13
+ *
14
+ * @param urlPath the path for the page being loaded
15
+ * @returns environment vars
16
+ */
17
+ export declare const getEnv: (urlPath: any) => import("zod").SafeParseSuccess<{
18
+ MOSAIC_SNAPSHOT_DIR: string;
19
+ }>;
20
+ /**
21
+ * Adds the [[`SearchIndex`]] props to the page props
22
+ * @param _context
23
+ * @returns site props object
24
+ */
25
+ export declare const withSearchIndex: MosaicMiddleware<SearchIndexSlice>;
@@ -0,0 +1,96 @@
1
+ import path from 'path';
2
+ import { fileLoaderProcessEnvSchema } from '@jpmorganchase/mosaic-schemas';
3
+ import MiddlewareError from './MiddlewareError.js';
4
+ import { loadLocalFile, loadS3File } from './loaders';
5
+ if (typeof window !== 'undefined') {
6
+ throw new Error('This file should not be loaded on the client.');
7
+ }
8
+ /**
9
+ * Fetch search-data.json
10
+ *
11
+ * @param url the search data file URL
12
+ * @returns search data JSON
13
+ */
14
+ export async function fetchSearchData(url) {
15
+ const response = await fetch(url, {
16
+ headers: {
17
+ 'Content-Type': 'application/json'
18
+ }
19
+ });
20
+ return response;
21
+ }
22
+ /**
23
+ * Get environment vars
24
+ *
25
+ * @param urlPath the path for the page being loaded
26
+ * @returns environment vars
27
+ */
28
+ export const getEnv = urlPath => {
29
+ const env = fileLoaderProcessEnvSchema.safeParse(process.env);
30
+ if (!env.success) {
31
+ env.error.issues.forEach(issue => {
32
+ console.error(`Missing process.env.${issue.path.join()} environment variable required to load shared-config for ${urlPath}`);
33
+ });
34
+ throw new Error(`Environment variables missing for loading of shared-config required by ${urlPath}`);
35
+ }
36
+ return env;
37
+ };
38
+ /**
39
+ * Adds the [[`SearchIndex`]] props to the page props
40
+ * @param _context
41
+ * @returns site props object
42
+ */
43
+ export const withSearchIndex = async (context) => {
44
+ const { res, resolvedUrl } = context;
45
+ const isSnapshotFile = res.getHeader('X-Mosaic-Mode') === 'snapshot-file';
46
+ const isSnapshotS3 = res.getHeader('X-Mosaic-Mode') === 'snapshot-s3';
47
+ const matches = resolvedUrl.match(/(.*)[!/]/);
48
+ const urlPath = matches?.length ? matches[1] : '';
49
+ const mosaicUrl = isSnapshotS3 || isSnapshotFile ? '' : res.getHeader('X-Mosaic-Content-Url');
50
+ const searchDataUrl = `${mosaicUrl}/search-data.json`;
51
+ try {
52
+ let searchIndexData;
53
+ if (isSnapshotFile) {
54
+ const env = getEnv(urlPath);
55
+ const { MOSAIC_SNAPSHOT_DIR: mosaicSnapshotDir } = env.data;
56
+ const filePath = path.join(process.cwd(), mosaicSnapshotDir, 'search-data.json');
57
+ const rawSearchIndexData = await loadLocalFile(filePath);
58
+ searchIndexData = JSON.parse(rawSearchIndexData);
59
+ }
60
+ else if (isSnapshotS3) {
61
+ const s3Key = `/search-data.json`.replace(/^\//, '');
62
+ const rawSearchIndexData = await loadS3File(s3Key);
63
+ searchIndexData = JSON.parse(rawSearchIndexData);
64
+ }
65
+ else {
66
+ const response = await fetchSearchData(searchDataUrl);
67
+ if (response.ok && response.status !== 204) {
68
+ searchIndexData = await response.json();
69
+ }
70
+ else {
71
+ const show500 = response.status !== 404 && response.status !== 204;
72
+ const show404 = response.status === 404;
73
+ let errorMessage = `Could not find any search data defined for ${searchDataUrl}`;
74
+ if (show500) {
75
+ errorMessage = `An un-expected error occurred reading ${searchDataUrl}`;
76
+ }
77
+ throw new MiddlewareError(response.status, searchDataUrl, [errorMessage], {
78
+ show404,
79
+ show500
80
+ });
81
+ }
82
+ }
83
+ return { props: { searchIndex: searchIndexData } };
84
+ }
85
+ catch (error) {
86
+ if (error instanceof Error) {
87
+ console.error(error.message);
88
+ throw new MiddlewareError(500, searchDataUrl, [error.message], { show500: true });
89
+ }
90
+ else {
91
+ console.error('unexpected error');
92
+ throw new MiddlewareError(500, searchDataUrl, ['unexpected error'], { show500: true });
93
+ }
94
+ }
95
+ };
96
+ //# sourceMappingURL=withSearchIndex.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withSearchIndex.js","sourceRoot":"","sources":["../src/withSearchIndex.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAGxB,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAE3E,OAAO,eAAe,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAEtD,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;IACjC,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;CAClE;AAID;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,GAAW;IAC/C,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;QAChC,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;S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AAE,CAAC,YAAY,CAAC,EAAE;oBACxE,OAAO;oBACP,OAAO;iBACR,CAAC,CAAC;aACJ;SACF;QAED,OAAO,EAAE,KAAK,EAAE,EAAE,WAAW,EAAE,eAAe,EAAE,EAAE,CAAC;KACpD;IAAC,OAAO,KAAK,EAAE;QACd,IAAI,KAAK,YAAY,KAAK,EAAE;YAC1B,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAC7B,MAAM,IAAI,eAAe,CAAC,GAAG,EAAE,aAAa,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;SACnF;aAAM;YACL,OAAO,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;YAClC,MAAM,IAAI,eAAe,CAAC,GAAG,EAAE,aAAa,EAAE,CAAC,kBAAkB,CAAC,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;SACxF;KACF;AACH,CAAC,CAAC"}
@@ -28,7 +28,7 @@ async function resolveSession(accessToken) {
28
28
  * @param options
29
29
  */
30
30
  export const withSession = async (context, options) => {
31
- if (process.env.ENABLE_LOGIN !== 'true') {
31
+ if (process.env.NEXT_PUBLIC_ENABLE_LOGIN !== 'true') {
32
32
  return {};
33
33
  }
34
34
  if (!process.env.COOKIE_SECRET) {
@@ -1 +1 @@
1
- {"version":3,"file":"withSession.js","sourceRoot":"","sources":["../src/withSession.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAElF,OAAO,eAAe,MAAM,sBAAsB,CAAC;AAEnD,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;IACjC,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;CAClE;AAiBD,MAAM,kBAAkB,GAAG,CAAC,OAAkC,EAAE,EAAE;IAChE,MAAM,GAAG,GAAG,IAAI,GAAG,CACjB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CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC1D,MAAM,OAAO,GAAG,MAAM,cAAc,CAAC,WAAW,CAAC,CAAC;IAClD,uDAAuD;IACvD,MAAM,iBAAiB,GAAG,OAAO,EAAE,aAAa,CAAC;IACjD,MAAM,UAAU,GAAG,CAAC,CAAC,CACnB,WAAW;QACX,OAAO;QACP,6DAA6D;QAC7D,0BAA0B,CAAC,OAAO,EAAE,MAAM,CAAC,aAAa,CAAC,CAC1D,CAAC;IACF,IAAI,iBAAiB,IAAI,CAAC,UAAU,EAAE;QACpC,OAAO,kBAAkB,CAAC,OAAO,CAAC,CAAC;KACpC;IAED,OAAO;QACL,KAAK,EAAE;YACL,OAAO,EAAE;gBACP,GAAG,OAAO;gBACV,UAAU;gBACV,WAAW;gBACX,gBAAgB;aACjB;SACF;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,SAAS,0BAA0B,CAAC,OAAgB,EAAE,gBAAgB,GAAG,OAAO,CAAC,aAAa;IAC5F,MAAM,EAAE,OAAO,GAAG,CAAC,EAAE,GAAG,OAAO,CAAC;IAChC,OAAO,OAAO,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,gBAAgB,CAAC;AAClD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jpmorganchase/mosaic-site-middleware",
3
- "version": "0.1.0-beta.21",
3
+ "version": "0.1.0-beta.23",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Mosaic - Site middleware",
6
6
  "main": "./dist/index.js",
@@ -27,9 +27,9 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@aws-sdk/client-s3": "^3.256.0",
30
- "@jpmorganchase/mosaic-schemas": "^0.1.0-beta.21",
31
- "@jpmorganchase/mosaic-store": "^0.1.0-beta.21",
32
- "@jpmorganchase/mosaic-types": "^0.1.0-beta.21",
30
+ "@jpmorganchase/mosaic-schemas": "^0.1.0-beta.23",
31
+ "@jpmorganchase/mosaic-store": "^0.1.0-beta.23",
32
+ "@jpmorganchase/mosaic-types": "^0.1.0-beta.23",
33
33
  "@types/mdast": "^3.0.0",
34
34
  "acorn": "^8.0.0",
35
35
  "acorn-jsx": "^5.0.0",
@@ -41,6 +41,7 @@
41
41
  "node-cookie": "^2.1.2",
42
42
  "react-error-boundary": "^3.1.4",
43
43
  "react-pro-sidebar": "1.0.0-alpha.7",
44
+ "remark-gfm": "3.0.1",
44
45
  "rehype-slug": "^5.0.1",
45
46
  "unified": "^10.0.0",
46
47
  "unist-util-visit": "^2.0.0",
package/src/compileMdx.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { serialize } from 'next-mdx-remote/serialize';
2
+ import remarkGfm from 'remark-gfm';
2
3
  import rehypeSlug from 'rehype-slug';
3
4
  import { codeBlocks } from './plugins/codeBlocks.js';
4
5
 
@@ -11,7 +12,7 @@ export async function compileMDX(
11
12
  const mdxSource = await serialize(content, {
12
13
  mdxOptions: {
13
14
  rehypePlugins: [rehypeSlug, ...remarkPlugins],
14
- remarkPlugins: [codeBlocks, ...rehypePlugins]
15
+ remarkPlugins: [codeBlocks, remarkGfm, ...rehypePlugins]
15
16
  },
16
17
  parseFrontmatter
17
18
  });
package/src/index.ts CHANGED
@@ -4,5 +4,6 @@ export * from './MiddlewareError.js';
4
4
  export * from './middlewarePresets.js';
5
5
  export * from './withMDXContent.js';
6
6
  export * from './withMosaicMode.js';
7
+ export * from './withSearchIndex.js';
7
8
  export * from './withSession.js';
8
9
  export * from './withSharedConfig.js';
@@ -1,7 +1,7 @@
1
1
  import type { Redirect } from 'next';
2
- import { SharedConfigSlice } from '@jpmorganchase/mosaic-store';
2
+ import { SearchIndexSlice, SharedConfigSlice } from '@jpmorganchase/mosaic-store';
3
3
  import type { ContentProps } from '@jpmorganchase/mosaic-types';
4
-
4
+ import { withSearchIndex } from './withSearchIndex.js';
5
5
  import { withSharedConfig } from './withSharedConfig.js';
6
6
  import { withMDXContent } from './withMDXContent.js';
7
7
  import { MosaicMiddleware, MosaicMiddlewareWithConfig } from './createMiddlewareRunner.js';
@@ -35,10 +35,13 @@ export type MosaicAppProps<T> = {
35
35
  export type GetMosaicServerSidePropsResult<T> = MosaicAppProps<T>;
36
36
 
37
37
  /** MiddlewarePresets props */
38
- export type MiddlewarePresetsProps = MosaicModeProps & ContentProps & SharedConfigSlice;
38
+ export type MiddlewarePresetsProps = MosaicModeProps &
39
+ ContentProps &
40
+ SearchIndexSlice &
41
+ SharedConfigSlice;
39
42
 
40
43
  /** A collection of preset [[`Middleware`]] plugins that will compose together the page props */
41
44
  export const middlewarePresets: Array<
42
45
  | MosaicMiddleware<MiddlewarePresetsProps>
43
46
  | MosaicMiddlewareWithConfig<MiddlewarePresetsProps, unknown>
44
- > = [withMosaicMode, withSharedConfig, withMDXContent];
47
+ > = [withMosaicMode, withSharedConfig, withMDXContent, withSearchIndex];
@@ -0,0 +1,109 @@
1
+ import path from 'path';
2
+ import { GetServerSidePropsContext } from 'next';
3
+ import type { SearchIndex, SearchIndexSlice } from '@jpmorganchase/mosaic-store';
4
+ import { fileLoaderProcessEnvSchema } from '@jpmorganchase/mosaic-schemas';
5
+ import { MosaicMiddleware } from './createMiddlewareRunner.js';
6
+ import MiddlewareError from './MiddlewareError.js';
7
+ import { loadLocalFile, loadS3File } from './loaders';
8
+
9
+ if (typeof window !== 'undefined') {
10
+ throw new Error('This file should not be loaded on the client.');
11
+ }
12
+
13
+ export { SearchIndex };
14
+
15
+ /**
16
+ * Fetch search-data.json
17
+ *
18
+ * @param url the search data file URL
19
+ * @returns search data JSON
20
+ */
21
+ export async function fetchSearchData(url: string) {
22
+ const response = await fetch(url, {
23
+ headers: {
24
+ 'Content-Type': 'application/json'
25
+ }
26
+ });
27
+ return response;
28
+ }
29
+
30
+ /**
31
+ * Get environment vars
32
+ *
33
+ * @param urlPath the path for the page being loaded
34
+ * @returns environment vars
35
+ */
36
+ export const getEnv = urlPath => {
37
+ const env = fileLoaderProcessEnvSchema.safeParse(process.env);
38
+ if (!env.success) {
39
+ env.error.issues.forEach(issue => {
40
+ console.error(
41
+ `Missing process.env.${issue.path.join()} environment variable required to load shared-config for ${urlPath}`
42
+ );
43
+ });
44
+ throw new Error(
45
+ `Environment variables missing for loading of shared-config required by ${urlPath}`
46
+ );
47
+ }
48
+ return env;
49
+ };
50
+
51
+ /**
52
+ * Adds the [[`SearchIndex`]] props to the page props
53
+ * @param _context
54
+ * @returns site props object
55
+ */
56
+ export const withSearchIndex: MosaicMiddleware<SearchIndexSlice> = async (
57
+ context: GetServerSidePropsContext
58
+ ) => {
59
+ const { res, resolvedUrl } = context;
60
+ const isSnapshotFile = res.getHeader('X-Mosaic-Mode') === 'snapshot-file';
61
+ const isSnapshotS3 = res.getHeader('X-Mosaic-Mode') === 'snapshot-s3';
62
+
63
+ const matches = resolvedUrl.match(/(.*)[!/]/);
64
+ const urlPath = matches?.length ? matches[1] : '';
65
+
66
+ const mosaicUrl = isSnapshotS3 || isSnapshotFile ? '' : res.getHeader('X-Mosaic-Content-Url');
67
+ const searchDataUrl = `${mosaicUrl}/search-data.json`;
68
+
69
+ try {
70
+ let searchIndexData;
71
+ if (isSnapshotFile) {
72
+ const env = getEnv(urlPath);
73
+ const { MOSAIC_SNAPSHOT_DIR: mosaicSnapshotDir } = env.data;
74
+ const filePath = path.join(process.cwd(), mosaicSnapshotDir, 'search-data.json');
75
+ const rawSearchIndexData = await loadLocalFile(filePath);
76
+ searchIndexData = JSON.parse(rawSearchIndexData);
77
+ } else if (isSnapshotS3) {
78
+ const s3Key = `/search-data.json`.replace(/^\//, '');
79
+ const rawSearchIndexData = await loadS3File(s3Key);
80
+ searchIndexData = JSON.parse(rawSearchIndexData);
81
+ } else {
82
+ const response = await fetchSearchData(searchDataUrl);
83
+ if (response.ok && response.status !== 204) {
84
+ searchIndexData = await response.json();
85
+ } else {
86
+ const show500 = response.status !== 404 && response.status !== 204;
87
+ const show404 = response.status === 404;
88
+ let errorMessage = `Could not find any search data defined for ${searchDataUrl}`;
89
+ if (show500) {
90
+ errorMessage = `An un-expected error occurred reading ${searchDataUrl}`;
91
+ }
92
+ throw new MiddlewareError(response.status, searchDataUrl, [errorMessage], {
93
+ show404,
94
+ show500
95
+ });
96
+ }
97
+ }
98
+
99
+ return { props: { searchIndex: searchIndexData } };
100
+ } catch (error) {
101
+ if (error instanceof Error) {
102
+ console.error(error.message);
103
+ throw new MiddlewareError(500, searchDataUrl, [error.message], { show500: true });
104
+ } else {
105
+ console.error('unexpected error');
106
+ throw new MiddlewareError(500, searchDataUrl, ['unexpected error'], { show500: true });
107
+ }
108
+ }
109
+ };
@@ -61,7 +61,7 @@ export const withSession: MosaicMiddleware<SessionProps, SessionOptions> = async
61
61
  context,
62
62
  options
63
63
  ) => {
64
- if (process.env.ENABLE_LOGIN !== 'true') {
64
+ if (process.env.NEXT_PUBLIC_ENABLE_LOGIN !== 'true') {
65
65
  return {};
66
66
  }
67
67
  if (!process.env.COOKIE_SECRET) {