@bleedingdev/modern-js-bff-core 3.9.0-ultramodern.4 → 3.9.0-ultramodern.5
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/dist/cjs/client/generateClient.js +67 -138
- package/dist/cjs/index.js +25 -101
- package/dist/esm/client/generateClient.mjs +65 -139
- package/dist/esm/index.mjs +0 -4
- package/dist/esm-node/client/generateClient.mjs +65 -139
- package/dist/esm-node/index.mjs +0 -4
- package/dist/types/client/generateClient.d.ts +24 -1
- package/dist/types/index.d.ts +0 -4
- package/package.json +5 -12
- package/dist/cjs/adapter-kit/index.js +0 -144
- package/dist/cjs/adapter-kit/parity-scenarios/cross-project-denial.js +0 -55
- package/dist/cjs/adapter-kit/parity-scenarios/envelope.js +0 -128
- package/dist/cjs/adapter-kit/parity-scenarios/operation-context.js +0 -152
- package/dist/cjs/adapter-kit/parity-scenarios/schema.js +0 -109
- package/dist/cjs/adapter-kit/parity-scenarios/shared.js +0 -71
- package/dist/cjs/adapter-kit/parity.js +0 -204
- package/dist/cjs/security/crossProjectPolicy.js +0 -309
- package/dist/cjs/security/operationContracts.js +0 -183
- package/dist/cjs/security/resolveCrossProjectPolicy.js +0 -65
- package/dist/esm/adapter-kit/index.mjs +0 -79
- package/dist/esm/adapter-kit/parity-scenarios/cross-project-denial.mjs +0 -17
- package/dist/esm/adapter-kit/parity-scenarios/envelope.mjs +0 -90
- package/dist/esm/adapter-kit/parity-scenarios/operation-context.mjs +0 -111
- package/dist/esm/adapter-kit/parity-scenarios/schema.mjs +0 -71
- package/dist/esm/adapter-kit/parity-scenarios/shared.mjs +0 -21
- package/dist/esm/adapter-kit/parity.mjs +0 -148
- package/dist/esm/security/crossProjectPolicy.mjs +0 -259
- package/dist/esm/security/operationContracts.mjs +0 -127
- package/dist/esm/security/resolveCrossProjectPolicy.mjs +0 -27
- package/dist/esm-node/adapter-kit/index.mjs +0 -80
- package/dist/esm-node/adapter-kit/parity-scenarios/cross-project-denial.mjs +0 -18
- package/dist/esm-node/adapter-kit/parity-scenarios/envelope.mjs +0 -91
- package/dist/esm-node/adapter-kit/parity-scenarios/operation-context.mjs +0 -112
- package/dist/esm-node/adapter-kit/parity-scenarios/schema.mjs +0 -72
- package/dist/esm-node/adapter-kit/parity-scenarios/shared.mjs +0 -22
- package/dist/esm-node/adapter-kit/parity.mjs +0 -149
- package/dist/esm-node/security/crossProjectPolicy.mjs +0 -260
- package/dist/esm-node/security/operationContracts.mjs +0 -130
- package/dist/esm-node/security/resolveCrossProjectPolicy.mjs +0 -28
- package/dist/types/adapter-kit/index.d.ts +0 -90
- package/dist/types/adapter-kit/parity-scenarios/cross-project-denial.d.ts +0 -2
- package/dist/types/adapter-kit/parity-scenarios/envelope.d.ts +0 -2
- package/dist/types/adapter-kit/parity-scenarios/operation-context.d.ts +0 -3
- package/dist/types/adapter-kit/parity-scenarios/schema.d.ts +0 -2
- package/dist/types/adapter-kit/parity-scenarios/shared.d.ts +0 -32
- package/dist/types/adapter-kit/parity.d.ts +0 -43
- package/dist/types/security/crossProjectPolicy.d.ts +0 -110
- package/dist/types/security/operationContracts.d.ts +0 -84
- package/dist/types/security/resolveCrossProjectPolicy.d.ts +0 -39
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
import __rslib_shim_module__ from "node:module";
|
|
2
2
|
const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(/*#__PURE__*/ (()=>import.meta.url)());
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
3
4
|
import { ApiRouter } from "../router/index.mjs";
|
|
4
|
-
import { buildOperationContractMap, createOperationSchemaHash, deriveOperationVersion } from "../security/operationContracts.mjs";
|
|
5
5
|
import { Err, Ok } from "./result.mjs";
|
|
6
6
|
import * as __rspack_external_path from "path";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
version: packageJson.version
|
|
14
|
-
};
|
|
15
|
-
} catch (error) {
|
|
16
|
-
return {};
|
|
7
|
+
class ClientCodegenError extends Error {
|
|
8
|
+
constructor(plugin, cause){
|
|
9
|
+
super(`BFF client code-generation plugin failed: ${plugin}`, {
|
|
10
|
+
cause
|
|
11
|
+
});
|
|
12
|
+
this.name = 'ClientCodegenError';
|
|
17
13
|
}
|
|
18
|
-
}
|
|
14
|
+
}
|
|
19
15
|
const INNER_CLIENT_REQUEST_CREATOR = '@modern-js/plugin-bff/client';
|
|
20
|
-
const generateClient = async (
|
|
21
|
-
|
|
16
|
+
const generateClient = async (options)=>{
|
|
17
|
+
const { appDir, resourcePath, apiDir, lambdaDir, prefix, port, target, fetcher, requireResolve = require.resolve, httpMethodDecider, domain, requestId, clientCodegenPlugin } = options;
|
|
22
18
|
const apiRouter = new ApiRouter({
|
|
23
19
|
appDir,
|
|
24
20
|
apiDir,
|
|
@@ -28,131 +24,61 @@ const generateClient = async ({ appDir, resourcePath, apiDir, lambdaDir, prefix,
|
|
|
28
24
|
});
|
|
29
25
|
const handlerInfos = await apiRouter.getSingleModuleHandlers(resourcePath);
|
|
30
26
|
if (!handlerInfos) return Err(`generate client error: Cannot require module ${resourcePath}`);
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
});
|
|
52
|
-
const schemaHash = createOperationSchemaHash(operationEntries, normalizedRequestId);
|
|
53
|
-
let hasUploadHandler = false;
|
|
54
|
-
let handlersCode = '';
|
|
55
|
-
for (const handlerInfo of handlerInfos){
|
|
56
|
-
const { name, httpMethod, routePath, action } = handlerInfo;
|
|
57
|
-
let exportStatement = `var ${name} =`;
|
|
58
|
-
if ('default' === name.toLowerCase()) exportStatement = 'default';
|
|
59
|
-
const upperHttpMethod = httpMethod.toUpperCase();
|
|
60
|
-
const operationSchemaHash = operationContracts[`${upperHttpMethod}:${routePath}`]?.schemaHash ?? '';
|
|
61
|
-
const operationContext = {
|
|
62
|
-
operationId: name,
|
|
63
|
-
routePath,
|
|
64
|
-
method: upperHttpMethod,
|
|
65
|
-
schemaHash: operationSchemaHash,
|
|
66
|
-
operationVersion
|
|
67
|
-
};
|
|
68
|
-
if ('upload' === action) {
|
|
69
|
-
hasUploadHandler = true;
|
|
70
|
-
const uploadOptions = {
|
|
71
|
-
path: routePath,
|
|
72
|
-
...domain ? {
|
|
73
|
-
domain
|
|
74
|
-
} : {},
|
|
75
|
-
...requestId ? {
|
|
76
|
-
requestId
|
|
77
|
-
} : {},
|
|
78
|
-
...requestId ? {
|
|
79
|
-
operationContext
|
|
80
|
-
} : {}
|
|
27
|
+
const draft = {
|
|
28
|
+
requestCreator: options.requestCreator || INNER_CLIENT_REQUEST_CREATOR,
|
|
29
|
+
imports: fetcher ? [
|
|
30
|
+
`import { fetch } from ${JSON.stringify(fetcher)};`
|
|
31
|
+
] : [],
|
|
32
|
+
statements: [],
|
|
33
|
+
handlers: handlerInfos.map((handlerInfo)=>{
|
|
34
|
+
const optionProperties = [
|
|
35
|
+
`path: ${JSON.stringify(handlerInfo.routePath)}`
|
|
36
|
+
];
|
|
37
|
+
if ('upload' !== handlerInfo.action) {
|
|
38
|
+
const portExpression = 'server' === target ? `process.env.PORT || ${String(port)}` : String(port);
|
|
39
|
+
optionProperties.push(`method: ${JSON.stringify(handlerInfo.httpMethod.toUpperCase())}`, `port: ${portExpression}`, `httpMethodDecider: ${JSON.stringify(httpMethodDecider || 'functionName')}`);
|
|
40
|
+
}
|
|
41
|
+
if (domain) optionProperties.push(`domain: ${JSON.stringify(domain)}`);
|
|
42
|
+
if (fetcher && 'upload' !== handlerInfo.action) optionProperties.push('fetch');
|
|
43
|
+
if (requestId) optionProperties.push(`requestId: ${JSON.stringify(requestId)}`);
|
|
44
|
+
return {
|
|
45
|
+
handlerInfo,
|
|
46
|
+
optionProperties
|
|
81
47
|
};
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
48
|
+
})
|
|
49
|
+
};
|
|
50
|
+
if (clientCodegenPlugin) try {
|
|
51
|
+
const specifier = clientCodegenPlugin.startsWith('.') ? __rspack_external_path.resolve(appDir, clientCodegenPlugin) : clientCodegenPlugin;
|
|
52
|
+
const resolved = requireResolve(specifier, {
|
|
53
|
+
paths: [
|
|
54
|
+
appDir
|
|
55
|
+
]
|
|
56
|
+
});
|
|
57
|
+
const extension = await import(pathToFileURL(resolved).href);
|
|
58
|
+
const modifyClient = extension.modifyClient ?? extension.default?.modifyClient;
|
|
59
|
+
if ('function' != typeof modifyClient) throw new TypeError('The module must export a modifyClient function.');
|
|
60
|
+
await modifyClient(draft, {
|
|
61
|
+
options,
|
|
62
|
+
handlerInfos
|
|
63
|
+
});
|
|
64
|
+
} catch (cause) {
|
|
65
|
+
throw new ClientCodegenError(clientCodegenPlugin, cause);
|
|
99
66
|
}
|
|
100
|
-
const
|
|
101
|
-
const
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
return
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
identityBinding: {
|
|
117
|
-
enabled: true,
|
|
118
|
-
strict: true,
|
|
119
|
-
},
|
|
120
|
-
operationContract: {
|
|
121
|
-
enabled: true,
|
|
122
|
-
strict: true,
|
|
123
|
-
requireSchemaHash: true,
|
|
124
|
-
requireOperationVersion: true,
|
|
125
|
-
},
|
|
126
|
-
};
|
|
127
|
-
return configure({
|
|
128
|
-
...defaultSecureOptions,
|
|
129
|
-
...options,
|
|
130
|
-
identityBinding: {
|
|
131
|
-
...defaultSecureOptions.identityBinding,
|
|
132
|
-
...(options && options.identityBinding ? options.identityBinding : {}),
|
|
133
|
-
},
|
|
134
|
-
operationContract: {
|
|
135
|
-
...defaultSecureOptions.operationContract,
|
|
136
|
-
...(options && options.operationContract ? options.operationContract : {}),
|
|
137
|
-
},
|
|
138
|
-
});
|
|
139
|
-
};
|
|
140
|
-
` : '';
|
|
141
|
-
const manifestCode = `export const operationVersion = ${String(operationVersion)};
|
|
142
|
-
export const operationSchemaHash = '${schemaHash}';
|
|
143
|
-
export const operationManifest = ${JSON.stringify({
|
|
144
|
-
operationVersion,
|
|
145
|
-
schemaHash,
|
|
146
|
-
operations: operationEntries
|
|
147
|
-
}, null, 2)};
|
|
148
|
-
`;
|
|
149
|
-
const generatedParts = [
|
|
150
|
-
importCode.trimEnd(),
|
|
151
|
-
bootstrapCode.trimEnd(),
|
|
152
|
-
manifestCode.trimEnd(),
|
|
153
|
-
handlersCode.trimEnd()
|
|
154
|
-
].filter(Boolean);
|
|
155
|
-
return Ok(`${generatedParts.join('\n\n')}
|
|
156
|
-
`);
|
|
67
|
+
const hasUploadHandler = handlerInfos.some((info)=>'upload' === info.action);
|
|
68
|
+
const requestImports = `createRequest${hasUploadHandler ? ', createUploader' : ''}`;
|
|
69
|
+
const importCode = [
|
|
70
|
+
`import { ${requestImports} } from ${JSON.stringify(draft.requestCreator)};`,
|
|
71
|
+
...draft.imports
|
|
72
|
+
].join('\n');
|
|
73
|
+
const handlersCode = draft.handlers.map(({ handlerInfo, optionProperties })=>{
|
|
74
|
+
const exportStatement = 'default' === handlerInfo.name.toLowerCase() ? 'default' : `var ${handlerInfo.name} =`;
|
|
75
|
+
const creator = 'upload' === handlerInfo.action ? 'createUploader' : 'createRequest';
|
|
76
|
+
return `export ${exportStatement} ${creator}({ ${optionProperties.join(', ')} });`;
|
|
77
|
+
}).join('\n');
|
|
78
|
+
return Ok(`${[
|
|
79
|
+
importCode,
|
|
80
|
+
...draft.statements,
|
|
81
|
+
handlersCode
|
|
82
|
+
].filter(Boolean).join('\n\n')}\n`);
|
|
157
83
|
};
|
|
158
|
-
export { INNER_CLIENT_REQUEST_CREATOR, generateClient };
|
|
84
|
+
export { ClientCodegenError, INNER_CLIENT_REQUEST_CREATOR, generateClient };
|
package/dist/esm-node/index.mjs
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
export * from "./adapter-kit/index.mjs";
|
|
3
2
|
export * from "./client/index.mjs";
|
|
4
3
|
export * from "./operators/http.mjs";
|
|
5
4
|
export * from "./router/index.mjs";
|
|
6
|
-
export * from "./security/crossProjectPolicy.mjs";
|
|
7
|
-
export * from "./security/operationContracts.mjs";
|
|
8
|
-
export * from "./security/resolveCrossProjectPolicy.mjs";
|
|
9
5
|
export * from "./types.mjs";
|
|
10
6
|
export { Api } from "./api.mjs";
|
|
11
7
|
export { HttpError, ValidationError } from "./errors/http.mjs";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { HttpMethodDecider } from '@modern-js/types';
|
|
2
|
+
import { type APIHandlerInfo } from '../router/index.js';
|
|
2
3
|
import { type Result } from './result.js';
|
|
3
4
|
export type GenClientResult = Result<string>;
|
|
4
5
|
export type GenClientOptions = {
|
|
@@ -16,6 +17,28 @@ export type GenClientOptions = {
|
|
|
16
17
|
httpMethodDecider?: HttpMethodDecider;
|
|
17
18
|
domain?: string;
|
|
18
19
|
requestId?: string;
|
|
20
|
+
/** Node module exporting a modifyClient code-generation transform. */
|
|
21
|
+
clientCodegenPlugin?: string;
|
|
19
22
|
};
|
|
23
|
+
export interface ClientHandlerDraft {
|
|
24
|
+
readonly handlerInfo: APIHandlerInfo;
|
|
25
|
+
/** Source expressions, including native server port and fetch bindings. */
|
|
26
|
+
optionProperties: string[];
|
|
27
|
+
}
|
|
28
|
+
export interface ClientModuleDraft {
|
|
29
|
+
requestCreator: string;
|
|
30
|
+
imports: string[];
|
|
31
|
+
statements: string[];
|
|
32
|
+
readonly handlers: readonly ClientHandlerDraft[];
|
|
33
|
+
}
|
|
34
|
+
export interface ClientCodegenContext {
|
|
35
|
+
readonly options: Readonly<GenClientOptions>;
|
|
36
|
+
readonly handlerInfos: readonly APIHandlerInfo[];
|
|
37
|
+
}
|
|
38
|
+
export type ClientCodegenPlugin = (draft: ClientModuleDraft, context: ClientCodegenContext) => void | Promise<void>;
|
|
39
|
+
/** A failed transform must not be downgraded to best-effort publication. */
|
|
40
|
+
export declare class ClientCodegenError extends Error {
|
|
41
|
+
constructor(plugin: string, cause: unknown);
|
|
42
|
+
}
|
|
20
43
|
export declare const INNER_CLIENT_REQUEST_CREATOR = "@modern-js/plugin-bff/client";
|
|
21
|
-
export declare const generateClient: (
|
|
44
|
+
export declare const generateClient: (options: GenClientOptions) => Promise<GenClientResult>;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
export * from './adapter-kit/index.js';
|
|
2
1
|
export { Api } from './api.js';
|
|
3
2
|
export * from './client/index.js';
|
|
4
3
|
export type * from './compatible.js';
|
|
5
4
|
export { HttpError, ValidationError } from './errors/http.js';
|
|
6
5
|
export * from './operators/http.js';
|
|
7
6
|
export * from './router/index.js';
|
|
8
|
-
export * from './security/crossProjectPolicy.js';
|
|
9
|
-
export * from './security/operationContracts.js';
|
|
10
|
-
export * from './security/resolveCrossProjectPolicy.js';
|
|
11
7
|
export * from './types.js';
|
|
12
8
|
export { createStorage, getRelativeRuntimePath, HANDLER_WITH_META, INPUT_PARAMS_DECIDER, isInputParamsDeciderHandler, isWithMetaHandler, registerPaths, } from './utils/index.js';
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"modern",
|
|
18
18
|
"modern.js"
|
|
19
19
|
],
|
|
20
|
-
"version": "3.9.0-ultramodern.
|
|
20
|
+
"version": "3.9.0-ultramodern.5",
|
|
21
21
|
"types": "./dist/types/index.d.ts",
|
|
22
22
|
"main": "./dist/cjs/index.js",
|
|
23
23
|
"exports": {
|
|
@@ -28,26 +28,19 @@
|
|
|
28
28
|
"require": "./dist/cjs/index.js"
|
|
29
29
|
},
|
|
30
30
|
"default": "./dist/cjs/index.js"
|
|
31
|
-
},
|
|
32
|
-
"./security/cross-project-policy": {
|
|
33
|
-
"types": "./dist/types/security/crossProjectPolicy.d.ts",
|
|
34
|
-
"node": {
|
|
35
|
-
"import": "./dist/esm-node/security/crossProjectPolicy.mjs",
|
|
36
|
-
"require": "./dist/cjs/security/crossProjectPolicy.js"
|
|
37
|
-
},
|
|
38
|
-
"default": "./dist/esm/security/crossProjectPolicy.mjs"
|
|
39
31
|
}
|
|
40
32
|
},
|
|
41
33
|
"dependencies": {
|
|
42
|
-
"@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.9.0-ultramodern.
|
|
34
|
+
"@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.9.0-ultramodern.5",
|
|
43
35
|
"@swc/helpers": "^0.5.23",
|
|
44
36
|
"koa-compose": "^4.1.0",
|
|
45
37
|
"reflect-metadata": "^0.2.2",
|
|
46
38
|
"type-fest": "5.9.0"
|
|
47
39
|
},
|
|
48
40
|
"devDependencies": {
|
|
49
|
-
"@modern-js/bff-runtime": "npm:@bleedingdev/modern-js-bff-runtime@3.9.0-ultramodern.
|
|
50
|
-
"@modern-js/
|
|
41
|
+
"@modern-js/bff-runtime": "npm:@bleedingdev/modern-js-bff-runtime@3.9.0-ultramodern.5",
|
|
42
|
+
"@modern-js/server-runtime-extensions": "npm:@bleedingdev/modern-js-server-runtime-extensions@3.9.0-ultramodern.5",
|
|
43
|
+
"@modern-js/types": "npm:@bleedingdev/modern-js-types@3.9.0-ultramodern.5",
|
|
51
44
|
"@rslib/core": "1.0.0",
|
|
52
45
|
"@scripts/rstest-config": "2.66.0",
|
|
53
46
|
"@types/koa-compose": "^3.2.9",
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
-
var define = (defs, kind)=>{
|
|
6
|
-
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
[kind]: defs[key]
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
define(getters, "get");
|
|
12
|
-
define(values, "value");
|
|
13
|
-
};
|
|
14
|
-
})();
|
|
15
|
-
(()=>{
|
|
16
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
-
})();
|
|
18
|
-
(()=>{
|
|
19
|
-
__webpack_require__.r = (exports1)=>{
|
|
20
|
-
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
-
value: 'Module'
|
|
22
|
-
});
|
|
23
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
-
value: true
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
})();
|
|
28
|
-
var __webpack_exports__ = {};
|
|
29
|
-
__webpack_require__.r(__webpack_exports__);
|
|
30
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
-
HANDLER_WITH_SCHEMA: ()=>HANDLER_WITH_SCHEMA,
|
|
32
|
-
buildPositionalHandlerArgs: ()=>buildPositionalHandlerArgs,
|
|
33
|
-
checkCrossProjectPolicy: ()=>checkCrossProjectPolicy,
|
|
34
|
-
getApiHandlerMode: ()=>getApiHandlerMode,
|
|
35
|
-
getResponseMetaList: ()=>getResponseMetaList,
|
|
36
|
-
getRouteMiddlewares: ()=>getRouteMiddlewares,
|
|
37
|
-
isSchemaApiHandler: ()=>isSchemaApiHandler,
|
|
38
|
-
mapSchemaHandlerResult: ()=>mapSchemaHandlerResult,
|
|
39
|
-
planApiRoutes: ()=>planApiRoutes,
|
|
40
|
-
toApiRouteMethod: ()=>toApiRouteMethod
|
|
41
|
-
});
|
|
42
|
-
require("reflect-metadata");
|
|
43
|
-
const crossProjectPolicy_js_namespaceObject = require("../security/crossProjectPolicy.js");
|
|
44
|
-
const external_types_js_namespaceObject = require("../types.js");
|
|
45
|
-
const index_js_namespaceObject = require("../utils/index.js");
|
|
46
|
-
const API_ROUTE_METHODS = {
|
|
47
|
-
[external_types_js_namespaceObject.HttpMethod.Get]: 'get',
|
|
48
|
-
[external_types_js_namespaceObject.HttpMethod.Post]: 'post',
|
|
49
|
-
[external_types_js_namespaceObject.HttpMethod.Put]: 'put',
|
|
50
|
-
[external_types_js_namespaceObject.HttpMethod.Delete]: 'delete',
|
|
51
|
-
[external_types_js_namespaceObject.HttpMethod.Connect]: 'connect',
|
|
52
|
-
[external_types_js_namespaceObject.HttpMethod.Trace]: 'trace',
|
|
53
|
-
[external_types_js_namespaceObject.HttpMethod.Patch]: 'patch',
|
|
54
|
-
[external_types_js_namespaceObject.HttpMethod.Options]: 'options',
|
|
55
|
-
[external_types_js_namespaceObject.HttpMethod.Head]: 'head'
|
|
56
|
-
};
|
|
57
|
-
const toApiRouteMethod = (httpMethod)=>{
|
|
58
|
-
const method = API_ROUTE_METHODS[httpMethod];
|
|
59
|
-
if (!method) throw new Error(`[bff-core] Unsupported HTTP method "${String(httpMethod)}" in API handler info`);
|
|
60
|
-
return method;
|
|
61
|
-
};
|
|
62
|
-
const getRouteMiddlewares = (handler)=>{
|
|
63
|
-
const middlewares = Reflect.getMetadata('middleware', handler);
|
|
64
|
-
return Array.isArray(middlewares) ? middlewares : [];
|
|
65
|
-
};
|
|
66
|
-
const planApiRoutes = (handlerInfos)=>handlerInfos.map(({ routePath, handler, httpMethod })=>({
|
|
67
|
-
method: toApiRouteMethod(httpMethod),
|
|
68
|
-
routePath,
|
|
69
|
-
handler,
|
|
70
|
-
middlewares: getRouteMiddlewares(handler)
|
|
71
|
-
}));
|
|
72
|
-
const HANDLER_WITH_SCHEMA = 'HANDLER_WITH_SCHEMA';
|
|
73
|
-
const isSchemaApiHandler = (handler)=>{
|
|
74
|
-
if ('function' != typeof handler) return false;
|
|
75
|
-
const marked = handler;
|
|
76
|
-
return true === marked[HANDLER_WITH_SCHEMA];
|
|
77
|
-
};
|
|
78
|
-
const getApiHandlerMode = (handler)=>{
|
|
79
|
-
if ((0, index_js_namespaceObject.isWithMetaHandler)(handler)) return 'meta';
|
|
80
|
-
if (isSchemaApiHandler(handler)) return 'schema';
|
|
81
|
-
if ((0, index_js_namespaceObject.isInputParamsDeciderHandler)(handler)) return 'inputParamsDecider';
|
|
82
|
-
return 'plain';
|
|
83
|
-
};
|
|
84
|
-
const mapSchemaHandlerResult = (result)=>{
|
|
85
|
-
if ('HandleSuccess' === result.type) return {
|
|
86
|
-
success: true,
|
|
87
|
-
status: 200,
|
|
88
|
-
body: result.value
|
|
89
|
-
};
|
|
90
|
-
return {
|
|
91
|
-
success: false,
|
|
92
|
-
status: 'InputValidationError' === result.type ? 400 : 500,
|
|
93
|
-
body: result.message
|
|
94
|
-
};
|
|
95
|
-
};
|
|
96
|
-
const getResponseMetaList = (handler)=>{
|
|
97
|
-
const responseMeta = Reflect.getMetadata(external_types_js_namespaceObject.HttpMetadata.Response, handler);
|
|
98
|
-
return Array.isArray(responseMeta) ? responseMeta : [];
|
|
99
|
-
};
|
|
100
|
-
const buildPositionalHandlerArgs = (input, routePath)=>{
|
|
101
|
-
const paramNames = routePath?.match(/:(\w+)/g)?.map((param)=>param.slice(1)) ?? [];
|
|
102
|
-
const positionalParams = paramNames.length > 0 ? paramNames.map((param)=>input.params[param]) : Object.values(input.params);
|
|
103
|
-
return [
|
|
104
|
-
...positionalParams,
|
|
105
|
-
input
|
|
106
|
-
];
|
|
107
|
-
};
|
|
108
|
-
const checkCrossProjectPolicy = (headers, policy)=>{
|
|
109
|
-
const violation = (0, crossProjectPolicy_js_namespaceObject.evaluateCrossProjectPolicy)(headers, policy);
|
|
110
|
-
if (!violation) return null;
|
|
111
|
-
return {
|
|
112
|
-
status: violation.status,
|
|
113
|
-
body: {
|
|
114
|
-
code: violation.code,
|
|
115
|
-
reason: violation.reason,
|
|
116
|
-
message: violation.message
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
};
|
|
120
|
-
exports.HANDLER_WITH_SCHEMA = __webpack_exports__.HANDLER_WITH_SCHEMA;
|
|
121
|
-
exports.buildPositionalHandlerArgs = __webpack_exports__.buildPositionalHandlerArgs;
|
|
122
|
-
exports.checkCrossProjectPolicy = __webpack_exports__.checkCrossProjectPolicy;
|
|
123
|
-
exports.getApiHandlerMode = __webpack_exports__.getApiHandlerMode;
|
|
124
|
-
exports.getResponseMetaList = __webpack_exports__.getResponseMetaList;
|
|
125
|
-
exports.getRouteMiddlewares = __webpack_exports__.getRouteMiddlewares;
|
|
126
|
-
exports.isSchemaApiHandler = __webpack_exports__.isSchemaApiHandler;
|
|
127
|
-
exports.mapSchemaHandlerResult = __webpack_exports__.mapSchemaHandlerResult;
|
|
128
|
-
exports.planApiRoutes = __webpack_exports__.planApiRoutes;
|
|
129
|
-
exports.toApiRouteMethod = __webpack_exports__.toApiRouteMethod;
|
|
130
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
131
|
-
"HANDLER_WITH_SCHEMA",
|
|
132
|
-
"buildPositionalHandlerArgs",
|
|
133
|
-
"checkCrossProjectPolicy",
|
|
134
|
-
"getApiHandlerMode",
|
|
135
|
-
"getResponseMetaList",
|
|
136
|
-
"getRouteMiddlewares",
|
|
137
|
-
"isSchemaApiHandler",
|
|
138
|
-
"mapSchemaHandlerResult",
|
|
139
|
-
"planApiRoutes",
|
|
140
|
-
"toApiRouteMethod"
|
|
141
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
142
|
-
Object.defineProperty(exports, '__esModule', {
|
|
143
|
-
value: true
|
|
144
|
-
});
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
-
var define = (defs, kind)=>{
|
|
6
|
-
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
[kind]: defs[key]
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
define(getters, "get");
|
|
12
|
-
define(values, "value");
|
|
13
|
-
};
|
|
14
|
-
})();
|
|
15
|
-
(()=>{
|
|
16
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
-
})();
|
|
18
|
-
(()=>{
|
|
19
|
-
__webpack_require__.r = (exports1)=>{
|
|
20
|
-
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
-
value: 'Module'
|
|
22
|
-
});
|
|
23
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
-
value: true
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
})();
|
|
28
|
-
var __webpack_exports__ = {};
|
|
29
|
-
__webpack_require__.r(__webpack_exports__);
|
|
30
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
-
createCrossProjectDenialScenarios: ()=>createCrossProjectDenialScenarios
|
|
32
|
-
});
|
|
33
|
-
const external_shared_js_namespaceObject = require("./shared.js");
|
|
34
|
-
const createCrossProjectDenialScenarios = ()=>[
|
|
35
|
-
(0, external_shared_js_namespaceObject.deniedScenario)('policy denies missing envelope', 'missing_envelope', {}),
|
|
36
|
-
(0, external_shared_js_namespaceObject.deniedScenario)('policy denies invalid envelope', 'invalid_envelope', {
|
|
37
|
-
'x-modernjs-bff-envelope': 'not-json'
|
|
38
|
-
}),
|
|
39
|
-
(0, external_shared_js_namespaceObject.deniedScenario)('policy denies envelope that is valid JSON but not an object', 'invalid_envelope', {
|
|
40
|
-
'x-modernjs-bff-envelope': '123'
|
|
41
|
-
}),
|
|
42
|
-
(0, external_shared_js_namespaceObject.deniedScenario)('policy denies missing requestId', 'missing_request_id', {
|
|
43
|
-
'x-modernjs-bff-envelope': (0, external_shared_js_namespaceObject.envelopeHeader)(void 0)
|
|
44
|
-
}),
|
|
45
|
-
(0, external_shared_js_namespaceObject.deniedScenario)('policy denies namespace outside allowlist', 'namespace_not_allowed', {
|
|
46
|
-
'x-modernjs-bff-envelope': (0, external_shared_js_namespaceObject.envelopeHeader)('billing.producer-z')
|
|
47
|
-
})
|
|
48
|
-
];
|
|
49
|
-
exports.createCrossProjectDenialScenarios = __webpack_exports__.createCrossProjectDenialScenarios;
|
|
50
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
51
|
-
"createCrossProjectDenialScenarios"
|
|
52
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
53
|
-
Object.defineProperty(exports, '__esModule', {
|
|
54
|
-
value: true
|
|
55
|
-
});
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
-
var define = (defs, kind)=>{
|
|
6
|
-
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
[kind]: defs[key]
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
define(getters, "get");
|
|
12
|
-
define(values, "value");
|
|
13
|
-
};
|
|
14
|
-
})();
|
|
15
|
-
(()=>{
|
|
16
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
-
})();
|
|
18
|
-
(()=>{
|
|
19
|
-
__webpack_require__.r = (exports1)=>{
|
|
20
|
-
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
-
value: 'Module'
|
|
22
|
-
});
|
|
23
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
-
value: true
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
})();
|
|
28
|
-
var __webpack_exports__ = {};
|
|
29
|
-
__webpack_require__.r(__webpack_exports__);
|
|
30
|
-
const createEnvelopeParityScenarios = ()=>[
|
|
31
|
-
{
|
|
32
|
-
name: 'plain handler returns object payload',
|
|
33
|
-
policy: false,
|
|
34
|
-
request: {
|
|
35
|
-
method: 'get',
|
|
36
|
-
path: '/hello'
|
|
37
|
-
},
|
|
38
|
-
expected: {
|
|
39
|
-
kind: 'payload',
|
|
40
|
-
status: 200,
|
|
41
|
-
payload: {
|
|
42
|
-
message: 'hello'
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
name: 'plain handler returns scalar payload',
|
|
48
|
-
policy: false,
|
|
49
|
-
request: {
|
|
50
|
-
method: 'post',
|
|
51
|
-
path: '/hello'
|
|
52
|
-
},
|
|
53
|
-
expected: {
|
|
54
|
-
kind: 'payload',
|
|
55
|
-
status: 200,
|
|
56
|
-
payload: 'hello'
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
name: 'plain handler returning undefined',
|
|
61
|
-
policy: false,
|
|
62
|
-
request: {
|
|
63
|
-
method: 'get',
|
|
64
|
-
path: '/nothing'
|
|
65
|
-
},
|
|
66
|
-
expected: {
|
|
67
|
-
kind: 'payload',
|
|
68
|
-
status: 404,
|
|
69
|
-
payload: '404 Not Found'
|
|
70
|
-
}
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
name: 'plain handler receives data, query and cookies',
|
|
74
|
-
policy: false,
|
|
75
|
-
request: {
|
|
76
|
-
method: 'post',
|
|
77
|
-
path: '/echo?q=z',
|
|
78
|
-
headers: {
|
|
79
|
-
'content-type': 'application/json',
|
|
80
|
-
cookie: 'id=666'
|
|
81
|
-
},
|
|
82
|
-
body: {
|
|
83
|
-
a: 1
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
expected: {
|
|
87
|
-
kind: 'payload',
|
|
88
|
-
status: 200,
|
|
89
|
-
payload: {
|
|
90
|
-
data: {
|
|
91
|
-
a: 1
|
|
92
|
-
},
|
|
93
|
-
query: {
|
|
94
|
-
q: 'z'
|
|
95
|
-
},
|
|
96
|
-
cookie: 'id=666'
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
name: 'plain handler receives positional route params',
|
|
102
|
-
policy: false,
|
|
103
|
-
request: {
|
|
104
|
-
method: 'get',
|
|
105
|
-
path: '/items/123?q=x'
|
|
106
|
-
},
|
|
107
|
-
expected: {
|
|
108
|
-
kind: 'payload',
|
|
109
|
-
status: 200,
|
|
110
|
-
payload: {
|
|
111
|
-
id: '123',
|
|
112
|
-
query: {
|
|
113
|
-
q: 'x'
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
];
|
|
119
|
-
__webpack_require__.d(__webpack_exports__, {}, {
|
|
120
|
-
createEnvelopeParityScenarios: createEnvelopeParityScenarios
|
|
121
|
-
});
|
|
122
|
-
exports.createEnvelopeParityScenarios = __webpack_exports__.createEnvelopeParityScenarios;
|
|
123
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
124
|
-
"createEnvelopeParityScenarios"
|
|
125
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
126
|
-
Object.defineProperty(exports, '__esModule', {
|
|
127
|
-
value: true
|
|
128
|
-
});
|