@jpmorganchase/mosaic-site-middleware 0.1.0-beta.9
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/.turbo/turbo-build.log +2 -0
- package/README.md +14 -0
- package/dist/MiddlewareError.d.ts +14 -0
- package/dist/MiddlewareError.js +18 -0
- package/dist/MiddlewareError.js.map +1 -0
- package/dist/compileMdx.d.ts +1 -0
- package/dist/compileMdx.js +14 -0
- package/dist/compileMdx.js.map +1 -0
- package/dist/createMiddlewareRunner.d.ts +28 -0
- package/dist/createMiddlewareRunner.js +73 -0
- package/dist/createMiddlewareRunner.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/middlewarePresets.d.ts +34 -0
- package/dist/middlewarePresets.js +12 -0
- package/dist/middlewarePresets.js.map +1 -0
- package/dist/plugins/codeBlocks.d.ts +22 -0
- package/dist/plugins/codeBlocks.js +46 -0
- package/dist/plugins/codeBlocks.js.map +1 -0
- package/dist/session.d.ts +7 -0
- package/dist/session.js +91 -0
- package/dist/session.js.map +1 -0
- package/dist/withContent.d.ts +17 -0
- package/dist/withContent.js +54 -0
- package/dist/withContent.js.map +1 -0
- package/dist/withMosaicMode.d.ts +13 -0
- package/dist/withMosaicMode.js +15 -0
- package/dist/withMosaicMode.js.map +1 -0
- package/dist/withSession.d.ts +21 -0
- package/dist/withSession.js +67 -0
- package/dist/withSession.js.map +1 -0
- package/dist/withSharedConfig.d.ts +9 -0
- package/dist/withSharedConfig.js +83 -0
- package/dist/withSharedConfig.js.map +1 -0
- package/dist/withStaticContent.d.ts +7 -0
- package/dist/withStaticContent.js +42 -0
- package/dist/withStaticContent.js.map +1 -0
- package/package.json +35 -0
- package/src/MiddlewareError.ts +26 -0
- package/src/__tests__/createMDXScope.test.ts +79 -0
- package/src/compileMdx.ts +19 -0
- package/src/createMiddlewareRunner.ts +108 -0
- package/src/index.ts +9 -0
- package/src/middlewarePresets.ts +52 -0
- package/src/plugins/codeBlocks.ts +52 -0
- package/src/session.ts +131 -0
- package/src/withContent.ts +67 -0
- package/src/withMosaicMode.ts +26 -0
- package/src/withSession.ts +103 -0
- package/src/withSharedConfig.ts +92 -0
- package/src/withStaticContent.ts +45 -0
- package/tsconfig.json +10 -0
package/README.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Mosaic Site Components Library
|
|
2
|
+
|
|
3
|
+
`@jpmorganchase/mosaic-site-middleware` contains site specific middleware functions.
|
|
4
|
+
|
|
5
|
+
Middleware functions are server-side only functions. They cannot be run on the client.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
1. Middleware functions.
|
|
10
|
+
2. Middleware Preset
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
`yarn add @jpmorganchase/mosaic-site-components`
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export default class MiddlewareError extends Error {
|
|
2
|
+
/** Response code */
|
|
3
|
+
status: number;
|
|
4
|
+
/** Related route location */
|
|
5
|
+
location: string | undefined;
|
|
6
|
+
/** Array of errors */
|
|
7
|
+
errors: string[];
|
|
8
|
+
/** Props to pass back */
|
|
9
|
+
props: {
|
|
10
|
+
show404?: boolean;
|
|
11
|
+
show500?: boolean;
|
|
12
|
+
};
|
|
13
|
+
constructor(status: MiddlewareError['status'], location: MiddlewareError['location'], errors?: MiddlewareError['errors'], props?: MiddlewareError['props']);
|
|
14
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export default class MiddlewareError extends Error {
|
|
2
|
+
/** Response code */
|
|
3
|
+
status;
|
|
4
|
+
/** Related route location */
|
|
5
|
+
location;
|
|
6
|
+
/** Array of errors */
|
|
7
|
+
errors;
|
|
8
|
+
/** Props to pass back */
|
|
9
|
+
props;
|
|
10
|
+
constructor(status, location, errors = [], props = {}) {
|
|
11
|
+
super(`${status} error`);
|
|
12
|
+
this.status = status;
|
|
13
|
+
this.location = location;
|
|
14
|
+
this.errors = errors;
|
|
15
|
+
this.props = props;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=MiddlewareError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MiddlewareError.js","sourceRoot":"","sources":["../src/MiddlewareError.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,KAAK;IAChD,oBAAoB;IACb,MAAM,CAAS;IAEtB,6BAA6B;IACtB,QAAQ,CAAqB;IAEpC,sBAAsB;IACf,MAAM,CAAW;IAExB,yBAAyB;IAClB,KAAK,CAA2C;IAEvD,YACE,MAAiC,EACjC,QAAqC,EACrC,SAAoC,EAAE,EACtC,QAAkC,EAAE;QAEpC,KAAK,CAAC,GAAG,MAAM,QAAQ,CAAC,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function compileMDX(content: any, parseFrontmatter?: boolean, rehypePlugins?: never[], remarkPlugins?: never[]): Promise<import("next-mdx-remote/dist/types.js").MDXRemoteSerializeResult<Record<string, unknown>, Record<string, string>>>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { serialize } from 'next-mdx-remote/serialize';
|
|
2
|
+
import rehypeSlug from 'rehype-slug';
|
|
3
|
+
import { codeBlocks } from './plugins/codeBlocks.js';
|
|
4
|
+
export async function compileMDX(content, parseFrontmatter = true, rehypePlugins = [], remarkPlugins = []) {
|
|
5
|
+
const mdxSource = await serialize(content, {
|
|
6
|
+
mdxOptions: {
|
|
7
|
+
rehypePlugins: [rehypeSlug, ...remarkPlugins],
|
|
8
|
+
remarkPlugins: [codeBlocks, ...rehypePlugins]
|
|
9
|
+
},
|
|
10
|
+
parseFrontmatter
|
|
11
|
+
});
|
|
12
|
+
return mdxSource;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=compileMdx.js.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { GetServerSidePropsContext } from 'next';
|
|
2
|
+
import type { MosaicAppProps } from './middlewarePresets.js';
|
|
3
|
+
/** Props returned after running Middleware */
|
|
4
|
+
export declare type MiddlewareResult<TProps> = Awaited<MosaicAppProps<TProps>>;
|
|
5
|
+
/** Options to be passed to Middleware */
|
|
6
|
+
export declare type MosaicMiddlewareOptions = Record<string, unknown>;
|
|
7
|
+
/** Middleware callbacks return props to be added to the page */
|
|
8
|
+
export declare type MosaicMiddleware<TProps = unknown, TOptions = MosaicMiddlewareOptions> = (
|
|
9
|
+
/** Context provides information on the current page */
|
|
10
|
+
context: GetServerSidePropsContext,
|
|
11
|
+
/** Middleware specific options */
|
|
12
|
+
options: TOptions,
|
|
13
|
+
/** Previous result created by plugins */
|
|
14
|
+
lastState: Record<string, unknown>) => Promise<MiddlewareResult<TProps>>;
|
|
15
|
+
/** Middleware with a configuration object specifying options */
|
|
16
|
+
export declare type MosaicMiddlewareWithConfig<TProps, TConfig> = [
|
|
17
|
+
MosaicMiddleware<TProps, TConfig>,
|
|
18
|
+
TConfig
|
|
19
|
+
];
|
|
20
|
+
/** Function to run all provided middleware */
|
|
21
|
+
export declare type MosaicMiddlewareRunner<TProps> = (context: GetServerSidePropsContext, options: MosaicMiddlewareOptions) => Promise<MiddlewareResult<TProps>>;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a middleware runner from the collection of provided middleware
|
|
24
|
+
* @param initialState initial state
|
|
25
|
+
* @param middleware a collection of middleware to be executed in order to get the page props
|
|
26
|
+
* @returns a middleware runner
|
|
27
|
+
*/
|
|
28
|
+
export declare function createMiddlewareRunner<TProps>(initialState: Record<string, unknown>, middleware: Array<MosaicMiddleware<any> | MosaicMiddlewareWithConfig<any, any>>): MosaicMiddlewareRunner<TProps>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import deepmerge from 'deepmerge';
|
|
2
|
+
import MiddlewareError from './MiddlewareError.js';
|
|
3
|
+
const overwriteMerge = (_, sourceArray) => sourceArray;
|
|
4
|
+
/**
|
|
5
|
+
* Creates a middleware runner from the collection of provided middleware
|
|
6
|
+
* @param initialState initial state
|
|
7
|
+
* @param middleware a collection of middleware to be executed in order to get the page props
|
|
8
|
+
* @returns a middleware runner
|
|
9
|
+
*/
|
|
10
|
+
export function createMiddlewareRunner(initialState, middleware) {
|
|
11
|
+
return async function middlewareRunner(context, options) {
|
|
12
|
+
let result = initialState;
|
|
13
|
+
const errors = [];
|
|
14
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
15
|
+
for (const fnOrConfig of middleware) {
|
|
16
|
+
let fn;
|
|
17
|
+
let finalOptions = options;
|
|
18
|
+
try {
|
|
19
|
+
if (typeof fnOrConfig === 'function') {
|
|
20
|
+
fn = fnOrConfig;
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
fn = fnOrConfig[0];
|
|
24
|
+
finalOptions = { ...options, ...fnOrConfig[1] };
|
|
25
|
+
}
|
|
26
|
+
// eslint-disable-next-line no-await-in-loop
|
|
27
|
+
const nextState = await fn(context, finalOptions, result);
|
|
28
|
+
result = deepmerge(result, nextState, {
|
|
29
|
+
arrayMerge: overwriteMerge
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
if (error instanceof Error) {
|
|
34
|
+
errors.push(error);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
const unexpectedError = new MiddlewareError(500, undefined, [String(error)], {
|
|
38
|
+
show500: true
|
|
39
|
+
});
|
|
40
|
+
errors.push(unexpectedError);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if (result.redirect) {
|
|
45
|
+
return { redirect: result.redirect };
|
|
46
|
+
}
|
|
47
|
+
const show404 = errors.some(error => {
|
|
48
|
+
if (error instanceof MiddlewareError) {
|
|
49
|
+
return error.props?.show404;
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
52
|
+
});
|
|
53
|
+
const show500 = !show404 &&
|
|
54
|
+
errors.some(error => {
|
|
55
|
+
if (error instanceof MiddlewareError) {
|
|
56
|
+
return error.props?.show500;
|
|
57
|
+
}
|
|
58
|
+
return true;
|
|
59
|
+
});
|
|
60
|
+
if (show500) {
|
|
61
|
+
console.error('An un-expected error(s) was thrown which caused the 500 page to appear');
|
|
62
|
+
errors.forEach(error => {
|
|
63
|
+
console.error(error.message);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
if (show404 || show500) {
|
|
67
|
+
context.res.setHeader(`X-Mosaic-${show404 ? '404' : '500'}`, 'true');
|
|
68
|
+
}
|
|
69
|
+
const props = { ...result.props, show404, show500 };
|
|
70
|
+
return { props };
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=createMiddlewareRunner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createMiddlewareRunner.js","sourceRoot":"","sources":["../src/createMiddlewareRunner.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,WAAW,CAAC;AAGlC,OAAO,eAAe,MAAM,sBAAsB,CAAC;AAEnD,MAAM,cAAc,GAAG,CAAC,CAAC,EAAE,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC;AA8BvD;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CACpC,YAAqC,EACrC,UAA+E;IAE/E,OAAO,KAAK,UAAU,gBAAgB,CAAC,OAAO,EAAE,OAAO;QACrD,IAAI,MAAM,GAA6B,YAAY,CAAC;QACpD,MAAM,MAAM,GAAY,EAAE,CAAC;QAC3B,gDAAgD;QAChD,KAAK,MAAM,UAAU,IAAI,UAAU,EAAE;YACnC,IAAI,EAAiC,CAAC;YACtC,IAAI,YAAY,GAAG,OAAO,CAAC;YAC3B,IAAI;gBACF,IAAI,OAAO,UAAU,KAAK,UAAU,EAAE;oBACpC,EAAE,GAAG,UAAU,CAAC;iBACjB;qBAAM;oBACL,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;oBACnB,YAAY,GAAG,EAAE,GAAG,OAAO,EAAE,GAAG,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;iBACjD;gBACD,4CAA4C;gBAC5C,MAAM,SAAS,GAAG,MAAM,EAAE,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;gBAC1D,MAAM,GAAG,SAAS,CAA2B,MAAM,EAAE,SAAS,EAAE;oBAC9D,UAAU,EAAE,cAAc;iBAC3B,CAAC,CAAC;aACJ;YAAC,OAAO,KAAK,EAAE;gBACd,IAAI,KAAK,YAAY,KAAK,EAAE;oBAC1B,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;iBACpB;qBAAM;oBACL,MAAM,eAAe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,EAAE,CAAC;IACnB,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './compileMdx.js';
|
|
2
|
+
export * from './createMiddlewareRunner.js';
|
|
3
|
+
export * from './MiddlewareError.js';
|
|
4
|
+
export * from './middlewarePresets.js';
|
|
5
|
+
export * from './withContent.js';
|
|
6
|
+
export * from './withMosaicMode.js';
|
|
7
|
+
export * from './withSession.js';
|
|
8
|
+
export * from './withSharedConfig.js';
|
|
9
|
+
export * from './withStaticContent.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './compileMdx.js';
|
|
2
|
+
export * from './createMiddlewareRunner.js';
|
|
3
|
+
export * from './MiddlewareError.js';
|
|
4
|
+
export * from './middlewarePresets.js';
|
|
5
|
+
export * from './withContent.js';
|
|
6
|
+
export * from './withMosaicMode.js';
|
|
7
|
+
export * from './withSession.js';
|
|
8
|
+
export * from './withSharedConfig.js';
|
|
9
|
+
export * from './withStaticContent.js';
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Redirect } from 'next';
|
|
2
|
+
import { SharedConfigSlice } from '@jpmorganchase/mosaic-store';
|
|
3
|
+
import { type SessionProps, type SessionOptions } from './withSession.js';
|
|
4
|
+
import { type ContentProps } from './withContent.js';
|
|
5
|
+
import { MosaicMiddleware, MosaicMiddlewareWithConfig } from './createMiddlewareRunner.js';
|
|
6
|
+
import { type MosaicModeProps } from './withMosaicMode.js';
|
|
7
|
+
export declare type BaseMosaicAppProps = {
|
|
8
|
+
/** Flag to show custom 404 page, whilst maintaining current state/layout */
|
|
9
|
+
show404?: boolean;
|
|
10
|
+
/** Flag to show custom 500 page, whilst maintaining current state/layout */
|
|
11
|
+
show500?: boolean;
|
|
12
|
+
};
|
|
13
|
+
/** Abstract Mosaic App Props */
|
|
14
|
+
export declare type MosaicAppProps<T> = {
|
|
15
|
+
/** Page props created by [[`Middleware`]] */
|
|
16
|
+
props?: T;
|
|
17
|
+
/** Error description */
|
|
18
|
+
errors?: {
|
|
19
|
+
/** Stacktrace * */
|
|
20
|
+
location?: string;
|
|
21
|
+
/** Error message * */
|
|
22
|
+
statusText?: string;
|
|
23
|
+
/** Error code */
|
|
24
|
+
status?: number;
|
|
25
|
+
} & BaseMosaicAppProps;
|
|
26
|
+
/** Next JS Redirect */
|
|
27
|
+
redirect?: Redirect;
|
|
28
|
+
};
|
|
29
|
+
/** Mosaic getServerSideProps result which supports error handling */
|
|
30
|
+
export declare type GetMosaicServerSidePropsResult<T> = MosaicAppProps<T>;
|
|
31
|
+
/** MiddlewarePresets props */
|
|
32
|
+
export declare type MiddlewarePresetsProps = MosaicModeProps & ContentProps & SessionProps & SharedConfigSlice;
|
|
33
|
+
/** A collection of preset [[`Middleware`]] plugins that will compose together the page props */
|
|
34
|
+
export declare const middlewarePresets: Array<MosaicMiddleware<MiddlewarePresetsProps> | MosaicMiddlewareWithConfig<MiddlewarePresetsProps, SessionOptions>>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { withSession } from './withSession.js';
|
|
2
|
+
import { withSharedConfig } from './withSharedConfig.js';
|
|
3
|
+
import { withContent } from './withContent.js';
|
|
4
|
+
import { withMosaicMode } from './withMosaicMode.js';
|
|
5
|
+
/** A collection of preset [[`Middleware`]] plugins that will compose together the page props */
|
|
6
|
+
export const middlewarePresets = [
|
|
7
|
+
[withSession, { loginRequired: process.env.DISABLE_GLOBAL_AUTH !== 'true' }],
|
|
8
|
+
withMosaicMode,
|
|
9
|
+
withSharedConfig,
|
|
10
|
+
withContent
|
|
11
|
+
];
|
|
12
|
+
//# sourceMappingURL=middlewarePresets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middlewarePresets.js","sourceRoot":"","sources":["../src/middlewarePresets.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAA0C,MAAM,kBAAkB,CAAC;AACvF,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,WAAW,EAAqB,MAAM,kBAAkB,CAAC;AAElE,OAAO,EAAE,cAAc,EAAwB,MAAM,qBAAqB,CAAC;AAmC3E,gGAAgG;AAChG,MAAM,CAAC,MAAM,iBAAiB,GAG1B;IACF,CAAC,WAAW,EAAE,EAAE,aAAa,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB,KAAK,MAAM,EAAE,CAAC;IAC5E,cAAc;IACd,gBAAgB;IAChB,WAAW;CACZ,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Plugin, Transformer } from 'unified';
|
|
2
|
+
/**
|
|
3
|
+
* Modified from: https://github.com/remcohaszing/remark-mdx-code-meta
|
|
4
|
+
*
|
|
5
|
+
* Custom meta parser for codefences that have extra params. e.g.
|
|
6
|
+
* ```jsx filename="hello.jsx"
|
|
7
|
+
* <div>Test!</div>
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* Custom meta parser for codefences that have eval or eval="true".
|
|
11
|
+
* This allows vars to be resolved and their values used as the code block body.
|
|
12
|
+
* ```jsx eval
|
|
13
|
+
* meta.data.someStringOnlyAvailableAtRuntime
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare const transformer: Transformer;
|
|
17
|
+
/**
|
|
18
|
+
* A markdown plugin for transforming code metadata.
|
|
19
|
+
*
|
|
20
|
+
* @returns A unified transformer.
|
|
21
|
+
*/
|
|
22
|
+
export declare const codeBlocks: Plugin<[]>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Parser } from 'acorn';
|
|
2
|
+
import jsx from 'acorn-jsx';
|
|
3
|
+
import visit from 'unist-util-visit';
|
|
4
|
+
const parser = Parser.extend(jsx());
|
|
5
|
+
/**
|
|
6
|
+
* Modified from: https://github.com/remcohaszing/remark-mdx-code-meta
|
|
7
|
+
*
|
|
8
|
+
* Custom meta parser for codefences that have extra params. e.g.
|
|
9
|
+
* ```jsx filename="hello.jsx"
|
|
10
|
+
* <div>Test!</div>
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* Custom meta parser for codefences that have eval or eval="true".
|
|
14
|
+
* This allows vars to be resolved and their values used as the code block body.
|
|
15
|
+
* ```jsx eval
|
|
16
|
+
* meta.data.someStringOnlyAvailableAtRuntime
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export const transformer = ast => {
|
|
20
|
+
visit(ast, 'code', (node, index, parent) => {
|
|
21
|
+
if (!node.meta) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
// Limit eval to just basic strings that start with "meta."
|
|
25
|
+
const isEval = /(^| )eval(="true"| |$)/.test(node.meta) && /^meta\.[a-z0-9_[\].$"']+$/i.test(node.value);
|
|
26
|
+
let code;
|
|
27
|
+
if (!isEval) {
|
|
28
|
+
code = JSON.stringify(`${node.value}\n`);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
code = node.value;
|
|
32
|
+
}
|
|
33
|
+
const codeProps = node.lang ? `className="language-${node.lang}"` : '';
|
|
34
|
+
const value = `<pre ${node.meta}><code ${codeProps}>{${code}}</code></pre>`;
|
|
35
|
+
const estree = parser.parse(value, { ecmaVersion: 'latest' });
|
|
36
|
+
// eslint-disable-next-line no-param-reassign
|
|
37
|
+
parent.children[index] = { type: 'mdxFlowExpression', value, data: { estree } };
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* A markdown plugin for transforming code metadata.
|
|
42
|
+
*
|
|
43
|
+
* @returns A unified transformer.
|
|
44
|
+
*/
|
|
45
|
+
export const codeBlocks = () => transformer;
|
|
46
|
+
//# sourceMappingURL=codeBlocks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codeBlocks.js","sourceRoot":"","sources":["../../src/plugins/codeBlocks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/B,OAAO,GAAG,MAAM,WAAW,CAAC;AAG5B,OAAO,KAAK,MAAM,kBAAkB,CAAC;AAErC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;AAEpC;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,WAAW,GAAgB,GAAG,CAAC,EAAE;IAC5C,KAAK,CAAO,GAAG,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;QAC/C,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;YACd,OAAO;SACR;QACD,2DAA2D;QAC3D,MAAM,MAAM,GACV,wBAAwB,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,4BAA4B,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAE5F,IAAI,IAAI,CAAC;QACT,IAAI,CAAC,MAAM,EAAE;YACX,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC;SAC1C;aAAM;YACL,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC;SACnB;QAED,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,uBAAuB,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QACvE,MAAM,KAAK,GAAG,QAAQ,IAAI,CAAC,IAAI,UAAU,SAAS,KAAK,IAAI,gBAAgB,CAAC;QAC5E,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC,CAAC;QAC9D,6CAA6C;QAC7C,MAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,mBAAmB,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,EAAa,CAAC;IAC9F,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAe,GAAG,EAAE,CAAC,WAAW,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Session } from '@jpmorganchase/mosaic-types';
|
|
2
|
+
export declare function getToken(req: any): string | null;
|
|
3
|
+
export declare function getIsCypressSession(req: any): boolean;
|
|
4
|
+
export declare function clearSession(res: any): any;
|
|
5
|
+
export declare function isSessionAgeMoreThan(session: Session, minRemainingTime?: number): boolean;
|
|
6
|
+
export declare function getSessionFromToken(accessToken: any): Session | null;
|
|
7
|
+
export declare function createSession(res: any, accessToken: any, expires: any): any;
|
package/dist/session.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import cookie from 'node-cookie';
|
|
2
|
+
import decode from 'jwt-decode';
|
|
3
|
+
if (typeof window !== 'undefined') {
|
|
4
|
+
throw new Error('This file should not be loaded on the client.');
|
|
5
|
+
}
|
|
6
|
+
const cookieSecret = process.env.COOKIE_SECRET;
|
|
7
|
+
const isCookieSecretSet = !!cookieSecret;
|
|
8
|
+
const TOKEN_COOKIE_NAME = 'access_token';
|
|
9
|
+
const DEFAULT_COOKIE_CONFIG = {
|
|
10
|
+
httpOnly: true,
|
|
11
|
+
secure: process.env.NODE_ENV !== 'development',
|
|
12
|
+
sameSite: 'lax',
|
|
13
|
+
path: '/'
|
|
14
|
+
};
|
|
15
|
+
export function getToken(req) {
|
|
16
|
+
if (!req) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
if (req.headers.authorization?.startsWith('Bearer ')) {
|
|
20
|
+
return req.headers.authorization.split(' ')[1];
|
|
21
|
+
}
|
|
22
|
+
return cookie.get(req, TOKEN_COOKIE_NAME, cookieSecret, isCookieSecretSet);
|
|
23
|
+
}
|
|
24
|
+
export function getIsCypressSession(req) {
|
|
25
|
+
if (!req) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
return Boolean(req.headers?.cypresse2e === 'true');
|
|
29
|
+
}
|
|
30
|
+
export function clearSession(res) {
|
|
31
|
+
if (!res) {
|
|
32
|
+
throw new Error('Cannot clear session - response object invalid');
|
|
33
|
+
}
|
|
34
|
+
return cookie.clear(res, TOKEN_COOKIE_NAME, DEFAULT_COOKIE_CONFIG);
|
|
35
|
+
}
|
|
36
|
+
export function isSessionAgeMoreThan(session, minRemainingTime = 0) {
|
|
37
|
+
const { expires = 0 } = session;
|
|
38
|
+
return expires >= Date.now() + minRemainingTime;
|
|
39
|
+
}
|
|
40
|
+
// eslint-disable-next complexity
|
|
41
|
+
export function getSessionFromToken(accessToken) {
|
|
42
|
+
try {
|
|
43
|
+
if (!accessToken) {
|
|
44
|
+
throw new Error('No token provided');
|
|
45
|
+
}
|
|
46
|
+
const decodedToken = decode(accessToken);
|
|
47
|
+
if (!decodedToken) {
|
|
48
|
+
throw new Error('Invalid token');
|
|
49
|
+
}
|
|
50
|
+
const { exp = -1, UserID = '', JPMCIdentifier = '', UID = '', EmployeeCorporateID = '', CostCenter = '', Country = '', CountryCode = '', Department = '', DisplayName = '', Email = '', EmployeeType = '', FirstName = '', LastName = '', LOB = '', LocationCode = '' } = decodedToken;
|
|
51
|
+
if (decodedToken) {
|
|
52
|
+
const expires = exp * 1000;
|
|
53
|
+
if (expires < Date.now()) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
const sid = UserID || JPMCIdentifier || UID || EmployeeCorporateID;
|
|
57
|
+
return {
|
|
58
|
+
expires,
|
|
59
|
+
isLoggedIn: true,
|
|
60
|
+
accessToken,
|
|
61
|
+
user: {
|
|
62
|
+
avatarUrl: process.env.AVATAR_URL,
|
|
63
|
+
sid,
|
|
64
|
+
country: Country,
|
|
65
|
+
countryCode: CountryCode,
|
|
66
|
+
costCenter: CostCenter,
|
|
67
|
+
department: Department,
|
|
68
|
+
displayName: DisplayName,
|
|
69
|
+
email: Email,
|
|
70
|
+
employeeType: EmployeeType,
|
|
71
|
+
firstName: FirstName,
|
|
72
|
+
lastName: LastName,
|
|
73
|
+
lob: LOB,
|
|
74
|
+
locationCode: LocationCode
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
throw new Error('Could not decode token');
|
|
79
|
+
}
|
|
80
|
+
catch (e) {
|
|
81
|
+
console.error(e);
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
export function createSession(res, accessToken, expires) {
|
|
86
|
+
return cookie.create(res, TOKEN_COOKIE_NAME, accessToken, {
|
|
87
|
+
...DEFAULT_COOKIE_CONFIG,
|
|
88
|
+
maxAge: (expires - new Date().getTime()) / 1000
|
|
89
|
+
}, cookieSecret, isCookieSecretSet);
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,MAAM,MAAM,YAAY,CAAC;AAGhC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;IACjC,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;CAClE;AAED,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;AAC/C,MAAM,iBAAiB,GAAG,CAAC,CAAC,YAAY,CAAC;A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SAAS,EAAE,SAAS;oBACpB,QAAQ,EAAE,QAAQ;oBAClB,GAAG,EAAE,GAAG;oBACR,YAAY,EAAE,YAAY;iBAC3B;aACF,CAAC;SACH;QACD,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;KAC3C;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;KAClB;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,GAAG,EAAE,WAAW,EAAE,OAAO;IACrD,OAAO,MAAM,CAAC,MAAM,CAClB,GAAG,EACH,iBAAiB,EACjB,WAAW,EACX;QACE,GAAG,qBAAqB;QACxB,MAAM,EAAE,CAAC,OAAO,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI;KAChD,EACD,YAAY,EACZ,iBAAiB,CAClB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { MosaicMiddleware } from './createMiddlewareRunner.js';
|
|
2
|
+
/**
|
|
3
|
+
* [[`ContentProps`]] specifies the page source/content
|
|
4
|
+
*/
|
|
5
|
+
export interface ContentProps {
|
|
6
|
+
/** Page source, which will be page type specific */
|
|
7
|
+
source?: Record<string, unknown>;
|
|
8
|
+
/** Page type */
|
|
9
|
+
type?: string;
|
|
10
|
+
/** Raw page content, includes markdown and frontmatter */
|
|
11
|
+
raw?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Adds the [[`ContentProps`]] object to the page props
|
|
15
|
+
* @param context
|
|
16
|
+
*/
|
|
17
|
+
export declare const withContent: MosaicMiddleware<ContentProps>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { compileMDX } from './compileMdx.js';
|
|
2
|
+
import MiddlewareError from './MiddlewareError.js';
|
|
3
|
+
if (typeof window !== 'undefined') {
|
|
4
|
+
throw new Error('This file should not be loaded on the client.');
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Adds the [[`ContentProps`]] object to the page props
|
|
8
|
+
* @param context
|
|
9
|
+
*/
|
|
10
|
+
export const withContent = async (context) => {
|
|
11
|
+
if (context.res.getHeader('X-Mosaic-Mode') !== 'active') {
|
|
12
|
+
return {};
|
|
13
|
+
}
|
|
14
|
+
const { resolvedUrl } = context;
|
|
15
|
+
try {
|
|
16
|
+
const mosaicUrl = context.res.getHeader('X-Mosaic-Content-Url');
|
|
17
|
+
const req = await fetch(`${mosaicUrl}${resolvedUrl}`);
|
|
18
|
+
if (req.ok) {
|
|
19
|
+
const contentType = req.headers.get('content-type');
|
|
20
|
+
if (contentType && contentType.includes('/mdx')) {
|
|
21
|
+
const text = await req.text();
|
|
22
|
+
const mdxSource = await compileMDX(text);
|
|
23
|
+
return { props: { type: 'mdx', source: mdxSource, raw: text } };
|
|
24
|
+
}
|
|
25
|
+
if (contentType && contentType.includes('/json')) {
|
|
26
|
+
const json = await req.json();
|
|
27
|
+
return { props: { type: 'json', ...json } };
|
|
28
|
+
}
|
|
29
|
+
// If redirect url was returned
|
|
30
|
+
}
|
|
31
|
+
else if (req.status === 302) {
|
|
32
|
+
return {
|
|
33
|
+
redirect: {
|
|
34
|
+
destination: (await req.json()).redirect,
|
|
35
|
+
permanent: true
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
if (error instanceof Error) {
|
|
42
|
+
console.error(error.message);
|
|
43
|
+
throw new MiddlewareError(500, resolvedUrl, [error.message], { show500: true });
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
console.error('unexpected error');
|
|
47
|
+
throw new MiddlewareError(500, resolvedUrl, ['unexpected error'], { show500: true });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
throw new MiddlewareError(404, resolvedUrl, [`Could not find any content for ${resolvedUrl}`], {
|
|
51
|
+
show404: true
|
|
52
|
+
});
|
|
53
|
+
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AAE;gBAChD,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;gBAC9B,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,EAAE,CAAC;aAC7C;YACD,+BAA+B;SAChC;aAAM,IAAI,GAAG,CAAC,MAAM,KAAK,GAAG,EAAE;YAC7B,OAAO;gBACL,QAAQ,EAAE;oBACR,WAAW,EAAE,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,QAAQ;oBACxC,SAAS,EAAE,IAAI;iBAChB;aACF,CAAC;SACH;KACF;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,WAAW,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;SACjF;aAAM;YACL,OAAO,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;YAClC,MAAM,IAAI,eAAe,CAAC,GAAG,EAAE,WAAW,EAAE,CAAC,kBAAkB,CAAC,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;SACtF;KACF;IACD,MAAM,IAAI,eAAe,CAAC,GAAG,EAAE,WAAW,EAAE,CAAC,kCAAkC,WAAW,EAAE,CAAC,EAAE;QAC7F,OAAO,EAAE,IAAI;KACd,CAAC,CAAC;AACL,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { MosaicMode } from '@jpmorganchase/mosaic-types';
|
|
2
|
+
import type { MosaicMiddleware } from './createMiddlewareRunner.js';
|
|
3
|
+
/**
|
|
4
|
+
* [[`MosaicModeProps`]] specifies the mode mosaic uses
|
|
5
|
+
*/
|
|
6
|
+
export interface MosaicModeProps {
|
|
7
|
+
mode?: MosaicMode;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Adds the [[`MosaicModeProps`]] object to the page props
|
|
11
|
+
* @param context
|
|
12
|
+
*/
|
|
13
|
+
export declare const withMosaicMode: MosaicMiddleware<MosaicModeProps>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
if (typeof window !== 'undefined') {
|
|
2
|
+
throw new Error('This file should not be loaded on the client.');
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Adds the [[`MosaicModeProps`]] object to the page props
|
|
6
|
+
* @param context
|
|
7
|
+
*/
|
|
8
|
+
export const withMosaicMode = async (context) => {
|
|
9
|
+
const mode = (process.env.MOSAIC_MODE || 'active');
|
|
10
|
+
const mosaicContentUrl = process.env[`MOSAIC_${mode.toUpperCase()}_MODE_URL`] || '';
|
|
11
|
+
context.res.setHeader('X-Mosaic-Mode', mode);
|
|
12
|
+
context.res.setHeader('X-Mosaic-Content-Url', mosaicContentUrl);
|
|
13
|
+
return { props: { mode } };
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=withMosaicMode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withMosaicMode.js","sourceRoot":"","sources":["../src/withMosaicMode.ts"],"names":[],"mappings":"AAIA,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;IACjC,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;CAClE;AASD;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAsC,KAAK,EAAC,OAAO,EAAC,EAAE;IAC/E,MAAM,IAAI,GAAe,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,QAAQ,CAAe,CAAC;IAC7E,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,IAAI,CAAC,WAAW,EAAE,WAAW,CAAC,IAAI,EAAE,CAAC;IACpF,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,eAAe,EAAE,IAAI,CAAC,CAAC;IAC7C,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,sBAAsB,EAAE,gBAAgB,CAAC,CAAC;IAChE,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC;AAC7B,CAAC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Session } from '@jpmorganchase/mosaic-types';
|
|
2
|
+
import { MosaicMiddleware } from './createMiddlewareRunner.js';
|
|
3
|
+
/**
|
|
4
|
+
* [[`SessionProps`]] specifies session object containing user profile of logged in user
|
|
5
|
+
*/
|
|
6
|
+
export interface SessionProps {
|
|
7
|
+
session?: Session;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* [[`SessionOptions`]] specifies a configuration object for the withSession middleware
|
|
11
|
+
*/
|
|
12
|
+
export interface SessionOptions {
|
|
13
|
+
/** is login required for the environment */
|
|
14
|
+
loginRequired: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Adds the [[`Session`]] object to the page props
|
|
18
|
+
* @param context
|
|
19
|
+
* @param options
|
|
20
|
+
*/
|
|
21
|
+
export declare const withSession: MosaicMiddleware<SessionProps, SessionOptions>;
|