@jpmorganchase/mosaic-source-readme 0.1.0-beta.60

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.
@@ -0,0 +1,219 @@
1
+ import { z } from 'zod';
2
+ import type { Source } from '@jpmorganchase/mosaic-types';
3
+ import { ReadmePage } from './types/index.js';
4
+ declare const readMeSchema: z.ZodObject<{
5
+ accessToken: z.ZodOptional<z.ZodString>;
6
+ proxyEndpoint: z.ZodOptional<z.ZodString>;
7
+ contentTemplate: z.ZodString;
8
+ readmeUrl: z.ZodString;
9
+ name: z.ZodString;
10
+ meta: z.ZodObject<{
11
+ title: z.ZodString;
12
+ description: z.ZodString;
13
+ layout: z.ZodString;
14
+ tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
15
+ data: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
16
+ }, "strip", z.ZodTypeAny, {
17
+ title: string;
18
+ description: string;
19
+ layout: string;
20
+ tags?: string[] | undefined;
21
+ data?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
22
+ }, {
23
+ title: string;
24
+ description: string;
25
+ layout: string;
26
+ tags?: string[] | undefined;
27
+ data?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
28
+ }>;
29
+ }, "strip", z.ZodTypeAny, {
30
+ contentTemplate: string;
31
+ readmeUrl: string;
32
+ name: string;
33
+ meta: {
34
+ title: string;
35
+ description: string;
36
+ layout: string;
37
+ tags?: string[] | undefined;
38
+ data?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
39
+ };
40
+ accessToken?: string | undefined;
41
+ proxyEndpoint?: string | undefined;
42
+ }, {
43
+ contentTemplate: string;
44
+ readmeUrl: string;
45
+ name: string;
46
+ meta: {
47
+ title: string;
48
+ description: string;
49
+ layout: string;
50
+ tags?: string[] | undefined;
51
+ data?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
52
+ };
53
+ accessToken?: string | undefined;
54
+ proxyEndpoint?: string | undefined;
55
+ }>;
56
+ export declare const schema: z.ZodObject<{
57
+ schedule: z.ZodOptional<z.ZodObject<{
58
+ checkIntervalMins: z.ZodNumber;
59
+ initialDelayMs: z.ZodNumber;
60
+ retryEnabled: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
61
+ retryDelayMins: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
62
+ maxRetries: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
63
+ resetOnSuccess: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
64
+ }, "strip", z.ZodTypeAny, {
65
+ checkIntervalMins: number;
66
+ initialDelayMs: number;
67
+ retryEnabled: boolean;
68
+ retryDelayMins: number;
69
+ maxRetries: number;
70
+ resetOnSuccess: boolean;
71
+ }, {
72
+ checkIntervalMins: number;
73
+ initialDelayMs: number;
74
+ retryEnabled?: boolean | undefined;
75
+ retryDelayMins?: number | undefined;
76
+ maxRetries?: number | undefined;
77
+ resetOnSuccess?: boolean | undefined;
78
+ }>>;
79
+ prefixDir: z.ZodString;
80
+ requestTimeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
81
+ proxyEndpoint: z.ZodOptional<z.ZodString>;
82
+ requestHeaders: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
83
+ readme: z.ZodArray<z.ZodObject<{
84
+ accessToken: z.ZodOptional<z.ZodString>;
85
+ proxyEndpoint: z.ZodOptional<z.ZodString>;
86
+ contentTemplate: z.ZodString;
87
+ readmeUrl: z.ZodString;
88
+ name: z.ZodString;
89
+ meta: z.ZodObject<{
90
+ title: z.ZodString;
91
+ description: z.ZodString;
92
+ layout: z.ZodString;
93
+ tags: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
94
+ data: z.ZodOptional<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
95
+ }, "strip", z.ZodTypeAny, {
96
+ title: string;
97
+ description: string;
98
+ layout: string;
99
+ tags?: string[] | undefined;
100
+ data?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
101
+ }, {
102
+ title: string;
103
+ description: string;
104
+ layout: string;
105
+ tags?: string[] | undefined;
106
+ data?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
107
+ }>;
108
+ }, "strip", z.ZodTypeAny, {
109
+ contentTemplate: string;
110
+ readmeUrl: string;
111
+ name: string;
112
+ meta: {
113
+ title: string;
114
+ description: string;
115
+ layout: string;
116
+ tags?: string[] | undefined;
117
+ data?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
118
+ };
119
+ accessToken?: string | undefined;
120
+ proxyEndpoint?: string | undefined;
121
+ }, {
122
+ contentTemplate: string;
123
+ readmeUrl: string;
124
+ name: string;
125
+ meta: {
126
+ title: string;
127
+ description: string;
128
+ layout: string;
129
+ tags?: string[] | undefined;
130
+ data?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
131
+ };
132
+ accessToken?: string | undefined;
133
+ proxyEndpoint?: string | undefined;
134
+ }>, "atleastone">;
135
+ }, "strip", z.ZodTypeAny, {
136
+ prefixDir: string;
137
+ requestTimeout: number;
138
+ readme: [{
139
+ contentTemplate: string;
140
+ readmeUrl: string;
141
+ name: string;
142
+ meta: {
143
+ title: string;
144
+ description: string;
145
+ layout: string;
146
+ tags?: string[] | undefined;
147
+ data?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
148
+ };
149
+ accessToken?: string | undefined;
150
+ proxyEndpoint?: string | undefined;
151
+ }, ...{
152
+ contentTemplate: string;
153
+ readmeUrl: string;
154
+ name: string;
155
+ meta: {
156
+ title: string;
157
+ description: string;
158
+ layout: string;
159
+ tags?: string[] | undefined;
160
+ data?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
161
+ };
162
+ accessToken?: string | undefined;
163
+ proxyEndpoint?: string | undefined;
164
+ }[]];
165
+ schedule?: {
166
+ checkIntervalMins: number;
167
+ initialDelayMs: number;
168
+ retryEnabled: boolean;
169
+ retryDelayMins: number;
170
+ maxRetries: number;
171
+ resetOnSuccess: boolean;
172
+ } | undefined;
173
+ proxyEndpoint?: string | undefined;
174
+ requestHeaders?: z.objectOutputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
175
+ }, {
176
+ prefixDir: string;
177
+ readme: [{
178
+ contentTemplate: string;
179
+ readmeUrl: string;
180
+ name: string;
181
+ meta: {
182
+ title: string;
183
+ description: string;
184
+ layout: string;
185
+ tags?: string[] | undefined;
186
+ data?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
187
+ };
188
+ accessToken?: string | undefined;
189
+ proxyEndpoint?: string | undefined;
190
+ }, ...{
191
+ contentTemplate: string;
192
+ readmeUrl: string;
193
+ name: string;
194
+ meta: {
195
+ title: string;
196
+ description: string;
197
+ layout: string;
198
+ tags?: string[] | undefined;
199
+ data?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
200
+ };
201
+ accessToken?: string | undefined;
202
+ proxyEndpoint?: string | undefined;
203
+ }[]];
204
+ schedule?: {
205
+ checkIntervalMins: number;
206
+ initialDelayMs: number;
207
+ retryEnabled?: boolean | undefined;
208
+ retryDelayMins?: number | undefined;
209
+ maxRetries?: number | undefined;
210
+ resetOnSuccess?: boolean | undefined;
211
+ } | undefined;
212
+ requestTimeout?: number | undefined;
213
+ proxyEndpoint?: string | undefined;
214
+ requestHeaders?: z.objectInputType<{}, z.ZodTypeAny, "passthrough"> | undefined;
215
+ }>;
216
+ export declare type ReadmeSourceOptions = z.infer<typeof schema>;
217
+ export declare type ReadmeOptions = z.infer<typeof readMeSchema>;
218
+ declare const ReadmeSource: Source<ReadmeSourceOptions, ReadmePage>;
219
+ export default ReadmeSource;
package/dist/index.js ADDED
@@ -0,0 +1,82 @@
1
+ import { map } from 'rxjs';
2
+ import { z } from 'zod';
3
+ import deepmerge from 'deepmerge';
4
+ import { validateMosaicSchema } from '@jpmorganchase/mosaic-schemas';
5
+ import { createHttpSource, httpSourceCreatorSchema, createProxyAgent } from '@jpmorganchase/mosaic-source-http';
6
+ const baseSchema = httpSourceCreatorSchema.omit({
7
+ endpoints: true,
8
+ noProxy: true,
9
+ transformerOptions: true // readme is the prop we need for this so no point duplicating it in source config
10
+ });
11
+ const readMeSchema = z.object({
12
+ accessToken: z.string().optional(),
13
+ proxyEndpoint: z.string().url().optional(),
14
+ contentTemplate: z.string(),
15
+ readmeUrl: z.string(),
16
+ name: z.string(),
17
+ meta: z.object({
18
+ title: z.string(),
19
+ description: z.string(),
20
+ layout: z.string(),
21
+ tags: z.array(z.string()).optional(),
22
+ data: z.object({}).passthrough().optional()
23
+ })
24
+ });
25
+ export const schema = baseSchema.merge(z.object({
26
+ readme: z.array(readMeSchema).nonempty()
27
+ }));
28
+ const createReadmePage = (content, prefixDir, index, sourceOptions) => {
29
+ const { contentTemplate, meta, name, readmeUrl } = sourceOptions[index];
30
+ const { title, description } = meta;
31
+ const route = `${prefixDir}/${name}`;
32
+ const updatedContent = contentTemplate.replace('::content::', content);
33
+ const sourceMeta = {
34
+ title,
35
+ description,
36
+ route,
37
+ fullPath: `${route}.mdx`,
38
+ data: {
39
+ title,
40
+ description,
41
+ readmeUrl,
42
+ link: route
43
+ },
44
+ content: updatedContent
45
+ };
46
+ const configMeta = meta;
47
+ const readmePage = deepmerge(sourceMeta, configMeta);
48
+ return [readmePage];
49
+ };
50
+ const ReadmeSource = {
51
+ create(options, sourceConfig) {
52
+ const parsedOptions = validateMosaicSchema(schema, options);
53
+ const { requestTimeout, requestHeaders: requestHeadersParam, prefixDir, readme: readmeConfig, ...restOptions } = parsedOptions;
54
+ const configuredRequests = readmeConfig.map(config => {
55
+ const { accessToken, readmeUrl, proxyEndpoint } = config;
56
+ let agent;
57
+ if (proxyEndpoint) {
58
+ console.log(`[Mosaic] Readme source using ${proxyEndpoint} proxy for ${readmeUrl}`);
59
+ agent = createProxyAgent(proxyEndpoint);
60
+ }
61
+ let requestHeaders = accessToken ? { Authorization: accessToken } : {};
62
+ requestHeaders = { ...requestHeaders, 'Content-Type': 'text/html', ...requestHeadersParam };
63
+ return new Request(`${readmeUrl}`, {
64
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
65
+ // @ts-ignore
66
+ agent,
67
+ headers: requestHeaders,
68
+ timeout: requestTimeout
69
+ });
70
+ });
71
+ const readmeHttpSource$ = createHttpSource({
72
+ prefixDir,
73
+ ...restOptions,
74
+ configuredRequests,
75
+ transformer: createReadmePage,
76
+ transformerOptions: readmeConfig
77
+ }, sourceConfig);
78
+ return readmeHttpSource$.pipe(map(pages => pages.flat()));
79
+ }
80
+ };
81
+ export default ReadmeSource;
82
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAC3B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,SAAS,MAAM,WAAW,CAAC;AAElC,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EACL,gBAAgB,EAChB,uBAAuB,EACvB,gBAAgB,EACjB,MAAM,mCAAmC,CAAC;AAG3C,MAAM,UAAU,GAAG,uBAAuB,CAAC,IAAI,CAAC;IAC9C,SAAS,EAAE,IAAI;IACf,OAAO,EAAE,IAAI;IACb,kBAAkB,EAAE,IAAI,CAAC,kFAAkF;CAC5G,CAAC,CAAC;AAEH,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5B,WAAW,EAAE,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AAc;gBACvB,OAAO,EAAE,cAAc;aACxB,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,MAAM,iBAAiB,GAAG,gBAAgB,CACxC;YACE,SAAS;YACT,GAAG,WAAW;YACd,kBAAkB;YAClB,WAAW,EAAE,gBAAgB;YAC7B,kBAAkB,EAAE,YAAY;SACjC,EACD,YAAY,CACb,CAAC;QAEF,OAAO,iBAAiB,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAC5D,CAAC;CACF,CAAC;AAEF,eAAe,YAAY,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { Page } from '@jpmorganchase/mosaic-types';
2
+ /** Readme specific metadata */
3
+ export declare type ReadmePageData = {
4
+ title: string;
5
+ description: string;
6
+ link: string;
7
+ repoUrl: string;
8
+ readmeUrl: string;
9
+ };
10
+ /** Readme page */
11
+ export declare type ReadmePage = {
12
+ description: string;
13
+ data: ReadmePageData;
14
+ } & Page;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@jpmorganchase/mosaic-source-readme",
3
+ "version": "0.1.0-beta.60",
4
+ "author": "",
5
+ "description": "Mosaic Readme.md source for core file system",
6
+ "license": "Apache-2.0",
7
+ "main": "./dist/index.js",
8
+ "type": "module",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js",
14
+ "node": "./dist/index.js"
15
+ }
16
+ },
17
+ "engines": {
18
+ "node": ">= 16.0.0"
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "scripts": {
24
+ "build": "tsc",
25
+ "clean": "rm -fr dist",
26
+ "lint": "eslint --ignore-pattern \"**/__tests__/**\""
27
+ },
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git@github.com:jpmorganchase/mosaic.git"
31
+ },
32
+ "dependencies": {
33
+ "@jpmorganchase/mosaic-source-http": "^0.1.0-beta.60",
34
+ "@jpmorganchase/mosaic-schemas": "^0.1.0-beta.60",
35
+ "@jpmorganchase/mosaic-types": "^0.1.0-beta.60",
36
+ "rxjs": "^7.5.5",
37
+ "zod": "^3.22.3"
38
+ },
39
+ "devDependencies": {
40
+ "msw": "^0.47.4"
41
+ }
42
+ }