@bleedingdev/modern-js-bff-core 3.9.0-ultramodern.2 → 3.9.0-ultramodern.20

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.
Files changed (60) hide show
  1. package/dist/cjs/client/generateClient.js +67 -138
  2. package/dist/cjs/index.js +24 -114
  3. package/dist/cjs/router/index.js +7 -5
  4. package/dist/cjs/utils/index.js +11 -21
  5. package/dist/esm/client/generateClient.mjs +65 -139
  6. package/dist/esm/index.mjs +1 -5
  7. package/dist/esm/router/index.mjs +7 -5
  8. package/dist/esm/utils/index.mjs +0 -1
  9. package/dist/esm-node/client/generateClient.mjs +65 -139
  10. package/dist/esm-node/index.mjs +1 -5
  11. package/dist/esm-node/router/index.mjs +7 -5
  12. package/dist/esm-node/utils/index.mjs +0 -1
  13. package/dist/types/client/generateClient.d.ts +24 -1
  14. package/dist/types/index.d.ts +1 -5
  15. package/dist/types/utils/index.d.ts +0 -1
  16. package/package.json +10 -19
  17. package/dist/cjs/adapter-kit/index.js +0 -144
  18. package/dist/cjs/adapter-kit/parity-scenarios/cross-project-denial.js +0 -55
  19. package/dist/cjs/adapter-kit/parity-scenarios/envelope.js +0 -128
  20. package/dist/cjs/adapter-kit/parity-scenarios/operation-context.js +0 -152
  21. package/dist/cjs/adapter-kit/parity-scenarios/schema.js +0 -109
  22. package/dist/cjs/adapter-kit/parity-scenarios/shared.js +0 -71
  23. package/dist/cjs/adapter-kit/parity.js +0 -204
  24. package/dist/cjs/security/crossProjectPolicy.js +0 -309
  25. package/dist/cjs/security/operationContracts.js +0 -183
  26. package/dist/cjs/security/resolveCrossProjectPolicy.js +0 -65
  27. package/dist/cjs/utils/alias.js +0 -112
  28. package/dist/esm/adapter-kit/index.mjs +0 -79
  29. package/dist/esm/adapter-kit/parity-scenarios/cross-project-denial.mjs +0 -17
  30. package/dist/esm/adapter-kit/parity-scenarios/envelope.mjs +0 -90
  31. package/dist/esm/adapter-kit/parity-scenarios/operation-context.mjs +0 -111
  32. package/dist/esm/adapter-kit/parity-scenarios/schema.mjs +0 -71
  33. package/dist/esm/adapter-kit/parity-scenarios/shared.mjs +0 -21
  34. package/dist/esm/adapter-kit/parity.mjs +0 -148
  35. package/dist/esm/security/crossProjectPolicy.mjs +0 -259
  36. package/dist/esm/security/operationContracts.mjs +0 -127
  37. package/dist/esm/security/resolveCrossProjectPolicy.mjs +0 -27
  38. package/dist/esm/utils/alias.mjs +0 -57
  39. package/dist/esm-node/adapter-kit/index.mjs +0 -80
  40. package/dist/esm-node/adapter-kit/parity-scenarios/cross-project-denial.mjs +0 -18
  41. package/dist/esm-node/adapter-kit/parity-scenarios/envelope.mjs +0 -91
  42. package/dist/esm-node/adapter-kit/parity-scenarios/operation-context.mjs +0 -112
  43. package/dist/esm-node/adapter-kit/parity-scenarios/schema.mjs +0 -72
  44. package/dist/esm-node/adapter-kit/parity-scenarios/shared.mjs +0 -22
  45. package/dist/esm-node/adapter-kit/parity.mjs +0 -149
  46. package/dist/esm-node/security/crossProjectPolicy.mjs +0 -260
  47. package/dist/esm-node/security/operationContracts.mjs +0 -130
  48. package/dist/esm-node/security/resolveCrossProjectPolicy.mjs +0 -28
  49. package/dist/esm-node/utils/alias.mjs +0 -58
  50. package/dist/types/adapter-kit/index.d.ts +0 -90
  51. package/dist/types/adapter-kit/parity-scenarios/cross-project-denial.d.ts +0 -2
  52. package/dist/types/adapter-kit/parity-scenarios/envelope.d.ts +0 -2
  53. package/dist/types/adapter-kit/parity-scenarios/operation-context.d.ts +0 -3
  54. package/dist/types/adapter-kit/parity-scenarios/schema.d.ts +0 -2
  55. package/dist/types/adapter-kit/parity-scenarios/shared.d.ts +0 -32
  56. package/dist/types/adapter-kit/parity.d.ts +0 -43
  57. package/dist/types/security/crossProjectPolicy.d.ts +0 -110
  58. package/dist/types/security/operationContracts.d.ts +0 -84
  59. package/dist/types/security/resolveCrossProjectPolicy.d.ts +0 -39
  60. package/dist/types/utils/alias.d.ts +0 -7
@@ -1,183 +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
- DEFAULT_OPERATION_VERSION: ()=>DEFAULT_OPERATION_VERSION,
32
- buildOperationContractMap: ()=>buildOperationContractMap,
33
- createOperationContractHash: ()=>createOperationContractHash,
34
- createOperationEntries: ()=>createOperationEntries,
35
- createOperationSchemaHash: ()=>createOperationSchemaHash,
36
- deriveOperationVersion: ()=>deriveOperationVersion,
37
- serializeOperationSchemas: ()=>serializeOperationSchemas
38
- });
39
- const external_node_module_namespaceObject = require("node:module");
40
- const external_crypto_namespaceObject = require("crypto");
41
- require("reflect-metadata");
42
- const external_types_js_namespaceObject = require("../types.js");
43
- const DEFAULT_OPERATION_VERSION = 1;
44
- const deriveOperationVersion = (packageVersion)=>{
45
- if ('string' != typeof packageVersion) return DEFAULT_OPERATION_VERSION;
46
- const match = packageVersion.trim().match(/^v?(\d+)\./);
47
- if (!match) return DEFAULT_OPERATION_VERSION;
48
- const major = Number.parseInt(match[1], 10);
49
- return Number.isInteger(major) && major >= 0 ? major : DEFAULT_OPERATION_VERSION;
50
- };
51
- const stableStringify = (value)=>{
52
- if (Array.isArray(value)) return `[${value.map((item)=>stableStringify(item)).join(',')}]`;
53
- if (value && 'object' == typeof value) {
54
- const entries = Object.entries(value).filter(([, entryValue])=>void 0 !== entryValue).sort(([a], [b])=>a.localeCompare(b)).map(([key, entryValue])=>`${JSON.stringify(key)}:${stableStringify(entryValue)}`);
55
- return `{${entries.join(',')}}`;
56
- }
57
- return JSON.stringify(value) ?? 'null';
58
- };
59
- const sha256 = (text)=>(0, external_crypto_namespaceObject.createHash)('sha256').update(text).digest('hex');
60
- let cachedZodToJSONSchema;
61
- const ZOD_SPECIFIER = "zod";
62
- const resolveZodToJSONSchema = ()=>{
63
- if (void 0 !== cachedZodToJSONSchema) return cachedZodToJSONSchema;
64
- try {
65
- const load = (0, external_node_module_namespaceObject.createRequire)(__filename);
66
- const zod = load(ZOD_SPECIFIER);
67
- const candidate = zod?.toJSONSchema ?? zod?.z?.toJSONSchema;
68
- cachedZodToJSONSchema = 'function' == typeof candidate ? candidate : null;
69
- } catch {
70
- cachedZodToJSONSchema = null;
71
- }
72
- return cachedZodToJSONSchema;
73
- };
74
- const INPUT_SCHEMA_METADATA_KEYS = [
75
- external_types_js_namespaceObject.HttpMetadata.Data,
76
- external_types_js_namespaceObject.HttpMetadata.Query,
77
- external_types_js_namespaceObject.HttpMetadata.Params,
78
- external_types_js_namespaceObject.HttpMetadata.Headers,
79
- external_types_js_namespaceObject.HttpMetadata.Files
80
- ];
81
- const serializeSchema = (schema)=>{
82
- const toJSONSchema = resolveZodToJSONSchema();
83
- if (toJSONSchema) try {
84
- return toJSONSchema(schema, {
85
- io: 'input',
86
- unrepresentable: 'any'
87
- });
88
- } catch {}
89
- return {
90
- __unserializableSchema: true
91
- };
92
- };
93
- const serializeOperationSchemas = (handler)=>{
94
- if ('function' != typeof handler) return;
95
- const serialized = {};
96
- for (const metadataKey of INPUT_SCHEMA_METADATA_KEYS){
97
- let schema;
98
- try {
99
- schema = Reflect.getMetadata(metadataKey, handler);
100
- } catch {
101
- schema = void 0;
102
- }
103
- if (null != schema) serialized[metadataKey] = serializeSchema(schema);
104
- }
105
- return Object.keys(serialized).length > 0 ? serialized : void 0;
106
- };
107
- const createOperationContractHash = (operation, requestId)=>sha256(stableStringify({
108
- httpMethod: String(operation.httpMethod || '').toUpperCase(),
109
- name: operation.name,
110
- requestId,
111
- routePath: operation.routePath,
112
- ...operation.schemas ? {
113
- schemas: operation.schemas
114
- } : {}
115
- }));
116
- const createOperationEntries = (handlers)=>handlers.map((item)=>({
117
- name: item.name,
118
- httpMethod: String(item.httpMethod || '').toUpperCase(),
119
- routePath: item.routePath
120
- })).sort((a, b)=>{
121
- const keyA = `${a.routePath}:${a.httpMethod}:${a.name}`;
122
- const keyB = `${b.routePath}:${b.httpMethod}:${b.name}`;
123
- return keyA.localeCompare(keyB);
124
- });
125
- const createOperationSchemaHash = (operationEntries, requestId)=>sha256(stableStringify({
126
- operations: [
127
- ...operationEntries
128
- ].map((item)=>({
129
- hash: item.schemaHash ?? createOperationContractHash({
130
- name: item.name,
131
- httpMethod: item.httpMethod,
132
- routePath: item.routePath
133
- }, requestId)
134
- })).sort((a, b)=>a.hash.localeCompare(b.hash)),
135
- requestId
136
- }));
137
- const buildOperationContractMap = ({ handlers, requestId, operationVersion })=>{
138
- const normalizedRequestId = 'string' == typeof requestId && requestId.trim().length > 0 ? requestId.trim() : 'default';
139
- const normalizedOperationVersion = 'number' == typeof operationVersion && Number.isInteger(operationVersion) ? operationVersion : DEFAULT_OPERATION_VERSION;
140
- const contracts = {};
141
- handlers.forEach((item)=>{
142
- const httpMethod = String(item.httpMethod || '').toUpperCase();
143
- const schemaHash = createOperationContractHash({
144
- name: item.name,
145
- httpMethod,
146
- routePath: item.routePath,
147
- schemas: serializeOperationSchemas(item.handler)
148
- }, normalizedRequestId);
149
- const operationId = `${normalizedRequestId}:${item.name}`;
150
- const contract = {
151
- requestId: normalizedRequestId,
152
- operationVersion: normalizedOperationVersion,
153
- schemaHash,
154
- method: httpMethod,
155
- routePath: item.routePath,
156
- operationId,
157
- handlerName: item.name,
158
- filename: item.filename
159
- };
160
- contracts[`${httpMethod}:${item.routePath}`] = contract;
161
- contracts[`operation:${operationId}`] = contract;
162
- });
163
- return contracts;
164
- };
165
- exports.DEFAULT_OPERATION_VERSION = __webpack_exports__.DEFAULT_OPERATION_VERSION;
166
- exports.buildOperationContractMap = __webpack_exports__.buildOperationContractMap;
167
- exports.createOperationContractHash = __webpack_exports__.createOperationContractHash;
168
- exports.createOperationEntries = __webpack_exports__.createOperationEntries;
169
- exports.createOperationSchemaHash = __webpack_exports__.createOperationSchemaHash;
170
- exports.deriveOperationVersion = __webpack_exports__.deriveOperationVersion;
171
- exports.serializeOperationSchemas = __webpack_exports__.serializeOperationSchemas;
172
- for(var __rspack_i in __webpack_exports__)if (-1 === [
173
- "DEFAULT_OPERATION_VERSION",
174
- "buildOperationContractMap",
175
- "createOperationContractHash",
176
- "createOperationEntries",
177
- "createOperationSchemaHash",
178
- "deriveOperationVersion",
179
- "serializeOperationSchemas"
180
- ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
181
- Object.defineProperty(exports, '__esModule', {
182
- value: true
183
- });
@@ -1,65 +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
- resolveCrossProjectPolicy: ()=>resolveCrossProjectPolicy
32
- });
33
- const external_operationContracts_js_namespaceObject = require("./operationContracts.js");
34
- const resolveCrossProjectPolicy = (input)=>{
35
- const { crossProjectPolicy, handlers, requestId, isCrossProjectServer, operationVersion } = input;
36
- if (!crossProjectPolicy && !isCrossProjectServer) return;
37
- const policy = crossProjectPolicy ?? {};
38
- const effectiveRequestId = 'string' == typeof requestId && requestId.trim().length > 0 ? requestId : 'default';
39
- const generatedContracts = (0, external_operationContracts_js_namespaceObject.buildOperationContractMap)({
40
- handlers,
41
- requestId: effectiveRequestId,
42
- operationVersion
43
- });
44
- return {
45
- ...policy,
46
- enabled: policy.enabled ?? Boolean(isCrossProjectServer),
47
- requireEnvelope: policy.requireEnvelope ?? true,
48
- requireOperationContext: policy.requireOperationContext ?? true,
49
- requireOperationContextDetails: policy.requireOperationContextDetails ?? true,
50
- requireOperationSchemaHash: policy.requireOperationSchemaHash ?? true,
51
- requireOperationVersion: policy.requireOperationVersion ?? true,
52
- allowUnknownOperations: policy.allowUnknownOperations ?? false,
53
- expectedOperationContracts: {
54
- ...policy.expectedOperationContracts ?? {},
55
- ...generatedContracts
56
- }
57
- };
58
- };
59
- exports.resolveCrossProjectPolicy = __webpack_exports__.resolveCrossProjectPolicy;
60
- for(var __rspack_i in __webpack_exports__)if (-1 === [
61
- "resolveCrossProjectPolicy"
62
- ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
63
- Object.defineProperty(exports, '__esModule', {
64
- value: true
65
- });
@@ -1,112 +0,0 @@
1
- "use strict";
2
- var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.n = (module)=>{
5
- var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
- __webpack_require__.d(getter, {
7
- a: getter
8
- });
9
- return getter;
10
- };
11
- })();
12
- (()=>{
13
- __webpack_require__.d = (exports1, getters, values)=>{
14
- var define = (defs, kind)=>{
15
- for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
16
- enumerable: true,
17
- [kind]: defs[key]
18
- });
19
- };
20
- define(getters, "get");
21
- define(values, "value");
22
- };
23
- })();
24
- (()=>{
25
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
26
- })();
27
- (()=>{
28
- __webpack_require__.r = (exports1)=>{
29
- if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
30
- value: 'Module'
31
- });
32
- Object.defineProperty(exports1, '__esModule', {
33
- value: true
34
- });
35
- };
36
- })();
37
- var __webpack_exports__ = {};
38
- __webpack_require__.r(__webpack_exports__);
39
- __webpack_require__.d(__webpack_exports__, {
40
- createMatchPath: ()=>createMatchPath,
41
- getRelativeRuntimePath: ()=>getRelativeRuntimePath,
42
- registerPaths: ()=>registerPaths
43
- });
44
- const external_fs_namespaceObject = require("fs");
45
- var external_fs_default = /*#__PURE__*/ __webpack_require__.n(external_fs_namespaceObject);
46
- const external_module_namespaceObject = require("module");
47
- var external_module_default = /*#__PURE__*/ __webpack_require__.n(external_module_namespaceObject);
48
- const external_os_namespaceObject = require("os");
49
- const external_path_namespaceObject = require("path");
50
- const getRelativeRuntimePath = (appDirectory, serverRuntimePath)=>{
51
- let relativeRuntimePath = '';
52
- relativeRuntimePath = 'win32' === external_os_namespaceObject.platform() ? `../${external_path_namespaceObject.relative(appDirectory, serverRuntimePath)}` : external_path_namespaceObject.join('../', external_path_namespaceObject.relative(appDirectory, serverRuntimePath));
53
- if ('development' === process.env.NODE_ENV || 'test' === process.env.NODE_ENV) relativeRuntimePath = `./${external_path_namespaceObject.relative(appDirectory, serverRuntimePath)}`;
54
- return relativeRuntimePath;
55
- };
56
- const sortByLongestPrefix = (arr)=>arr.concat().sort((a, b)=>b.length - a.length);
57
- const createMatchPath = (paths)=>{
58
- const sortedKeys = sortByLongestPrefix(Object.keys(paths));
59
- const sortedPaths = {};
60
- sortedKeys.forEach((key)=>{
61
- sortedPaths[key] = paths[key];
62
- });
63
- return (request)=>{
64
- const found = Object.keys(sortedPaths).find((key)=>request.startsWith(key));
65
- if (found) {
66
- let foundPaths = sortedPaths[found];
67
- if (!Array.isArray(foundPaths)) foundPaths = [
68
- foundPaths
69
- ];
70
- foundPaths = foundPaths.filter((foundPath)=>external_path_namespaceObject.isAbsolute(foundPath));
71
- for (const p of foundPaths){
72
- const foundPath = request.replace(found, p);
73
- if (external_fs_default().existsSync(foundPath)) return foundPath;
74
- }
75
- return request.replace(found, foundPaths[0]);
76
- }
77
- return null;
78
- };
79
- };
80
- const registerPaths = (paths)=>{
81
- const originalResolveFilename = external_module_default()._resolveFilename;
82
- const { builtinModules } = external_module_default();
83
- const matchPath = createMatchPath(paths);
84
- external_module_default()._resolveFilename = function(request, _parent) {
85
- const isCoreModule = builtinModules.includes(request);
86
- if (!isCoreModule) {
87
- const matched = matchPath(request);
88
- if (matched) {
89
- const modifiedArguments = [
90
- matched,
91
- ...[].slice.call(arguments, 1)
92
- ];
93
- return originalResolveFilename.apply(this, modifiedArguments);
94
- }
95
- }
96
- return originalResolveFilename.apply(this, arguments);
97
- };
98
- return ()=>{
99
- external_module_default()._resolveFilename = originalResolveFilename;
100
- };
101
- };
102
- exports.createMatchPath = __webpack_exports__.createMatchPath;
103
- exports.getRelativeRuntimePath = __webpack_exports__.getRelativeRuntimePath;
104
- exports.registerPaths = __webpack_exports__.registerPaths;
105
- for(var __rspack_i in __webpack_exports__)if (-1 === [
106
- "createMatchPath",
107
- "getRelativeRuntimePath",
108
- "registerPaths"
109
- ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
110
- Object.defineProperty(exports, '__esModule', {
111
- value: true
112
- });
@@ -1,79 +0,0 @@
1
- import "reflect-metadata";
2
- import { evaluateCrossProjectPolicy } from "../security/crossProjectPolicy.mjs";
3
- import { HttpMetadata, HttpMethod } from "../types.mjs";
4
- import { isInputParamsDeciderHandler, isWithMetaHandler } from "../utils/index.mjs";
5
- const API_ROUTE_METHODS = {
6
- [HttpMethod.Get]: 'get',
7
- [HttpMethod.Post]: 'post',
8
- [HttpMethod.Put]: 'put',
9
- [HttpMethod.Delete]: 'delete',
10
- [HttpMethod.Connect]: 'connect',
11
- [HttpMethod.Trace]: 'trace',
12
- [HttpMethod.Patch]: 'patch',
13
- [HttpMethod.Options]: 'options',
14
- [HttpMethod.Head]: 'head'
15
- };
16
- const toApiRouteMethod = (httpMethod)=>{
17
- const method = API_ROUTE_METHODS[httpMethod];
18
- if (!method) throw new Error(`[bff-core] Unsupported HTTP method "${String(httpMethod)}" in API handler info`);
19
- return method;
20
- };
21
- const getRouteMiddlewares = (handler)=>{
22
- const middlewares = Reflect.getMetadata('middleware', handler);
23
- return Array.isArray(middlewares) ? middlewares : [];
24
- };
25
- const planApiRoutes = (handlerInfos)=>handlerInfos.map(({ routePath, handler, httpMethod })=>({
26
- method: toApiRouteMethod(httpMethod),
27
- routePath,
28
- handler,
29
- middlewares: getRouteMiddlewares(handler)
30
- }));
31
- const HANDLER_WITH_SCHEMA = 'HANDLER_WITH_SCHEMA';
32
- const isSchemaApiHandler = (handler)=>{
33
- if ('function' != typeof handler) return false;
34
- const marked = handler;
35
- return true === marked[HANDLER_WITH_SCHEMA];
36
- };
37
- const getApiHandlerMode = (handler)=>{
38
- if (isWithMetaHandler(handler)) return 'meta';
39
- if (isSchemaApiHandler(handler)) return 'schema';
40
- if (isInputParamsDeciderHandler(handler)) return 'inputParamsDecider';
41
- return 'plain';
42
- };
43
- const mapSchemaHandlerResult = (result)=>{
44
- if ('HandleSuccess' === result.type) return {
45
- success: true,
46
- status: 200,
47
- body: result.value
48
- };
49
- return {
50
- success: false,
51
- status: 'InputValidationError' === result.type ? 400 : 500,
52
- body: result.message
53
- };
54
- };
55
- const getResponseMetaList = (handler)=>{
56
- const responseMeta = Reflect.getMetadata(HttpMetadata.Response, handler);
57
- return Array.isArray(responseMeta) ? responseMeta : [];
58
- };
59
- const buildPositionalHandlerArgs = (input, routePath)=>{
60
- const paramNames = routePath?.match(/:(\w+)/g)?.map((param)=>param.slice(1)) ?? [];
61
- const positionalParams = paramNames.length > 0 ? paramNames.map((param)=>input.params[param]) : Object.values(input.params);
62
- return [
63
- ...positionalParams,
64
- input
65
- ];
66
- };
67
- const checkCrossProjectPolicy = (headers, policy)=>{
68
- const violation = evaluateCrossProjectPolicy(headers, policy);
69
- if (!violation) return null;
70
- return {
71
- status: violation.status,
72
- body: {
73
- code: violation.code,
74
- reason: violation.reason,
75
- message: violation.message
76
- }
77
- };
78
- };
79
- export { HANDLER_WITH_SCHEMA, buildPositionalHandlerArgs, checkCrossProjectPolicy, getApiHandlerMode, getResponseMetaList, getRouteMiddlewares, isSchemaApiHandler, mapSchemaHandlerResult, planApiRoutes, toApiRouteMethod };
@@ -1,17 +0,0 @@
1
- import { deniedScenario, envelopeHeader } from "./shared.mjs";
2
- const createCrossProjectDenialScenarios = ()=>[
3
- deniedScenario('policy denies missing envelope', 'missing_envelope', {}),
4
- deniedScenario('policy denies invalid envelope', 'invalid_envelope', {
5
- 'x-modernjs-bff-envelope': 'not-json'
6
- }),
7
- deniedScenario('policy denies envelope that is valid JSON but not an object', 'invalid_envelope', {
8
- 'x-modernjs-bff-envelope': '123'
9
- }),
10
- deniedScenario('policy denies missing requestId', 'missing_request_id', {
11
- 'x-modernjs-bff-envelope': envelopeHeader(void 0)
12
- }),
13
- deniedScenario('policy denies namespace outside allowlist', 'namespace_not_allowed', {
14
- 'x-modernjs-bff-envelope': envelopeHeader('billing.producer-z')
15
- })
16
- ];
17
- export { createCrossProjectDenialScenarios };
@@ -1,90 +0,0 @@
1
- const createEnvelopeParityScenarios = ()=>[
2
- {
3
- name: 'plain handler returns object payload',
4
- policy: false,
5
- request: {
6
- method: 'get',
7
- path: '/hello'
8
- },
9
- expected: {
10
- kind: 'payload',
11
- status: 200,
12
- payload: {
13
- message: 'hello'
14
- }
15
- }
16
- },
17
- {
18
- name: 'plain handler returns scalar payload',
19
- policy: false,
20
- request: {
21
- method: 'post',
22
- path: '/hello'
23
- },
24
- expected: {
25
- kind: 'payload',
26
- status: 200,
27
- payload: 'hello'
28
- }
29
- },
30
- {
31
- name: 'plain handler returning undefined',
32
- policy: false,
33
- request: {
34
- method: 'get',
35
- path: '/nothing'
36
- },
37
- expected: {
38
- kind: 'payload',
39
- status: 404,
40
- payload: '404 Not Found'
41
- }
42
- },
43
- {
44
- name: 'plain handler receives data, query and cookies',
45
- policy: false,
46
- request: {
47
- method: 'post',
48
- path: '/echo?q=z',
49
- headers: {
50
- 'content-type': 'application/json',
51
- cookie: 'id=666'
52
- },
53
- body: {
54
- a: 1
55
- }
56
- },
57
- expected: {
58
- kind: 'payload',
59
- status: 200,
60
- payload: {
61
- data: {
62
- a: 1
63
- },
64
- query: {
65
- q: 'z'
66
- },
67
- cookie: 'id=666'
68
- }
69
- }
70
- },
71
- {
72
- name: 'plain handler receives positional route params',
73
- policy: false,
74
- request: {
75
- method: 'get',
76
- path: '/items/123?q=x'
77
- },
78
- expected: {
79
- kind: 'payload',
80
- status: 200,
81
- payload: {
82
- id: '123',
83
- query: {
84
- q: 'x'
85
- }
86
- }
87
- }
88
- }
89
- ];
90
- export { createEnvelopeParityScenarios };
@@ -1,111 +0,0 @@
1
- import { PARITY_PRODUCER_REQUEST_ID, deniedScenario, detailHeader } from "./shared.mjs";
2
- const createOperationContextSuccessScenarios = ({ helloContract, validEnvelope, validOperationId })=>[
3
- {
4
- name: 'policy pass with full operation context',
5
- policy: true,
6
- request: {
7
- method: 'get',
8
- path: '/hello',
9
- headers: {
10
- 'x-modernjs-bff-envelope': validEnvelope,
11
- 'x-operation-id': validOperationId,
12
- 'x-modernjs-bff-operation-context': detailHeader({
13
- requestId: PARITY_PRODUCER_REQUEST_ID,
14
- method: 'GET',
15
- routePath: '/hello',
16
- schemaHash: helloContract.schemaHash,
17
- operationVersion: helloContract.operationVersion
18
- })
19
- }
20
- },
21
- expected: {
22
- kind: 'payload',
23
- status: 200,
24
- payload: {
25
- message: 'hello'
26
- }
27
- }
28
- }
29
- ];
30
- const getMismatchedOperationVersion = (contract)=>{
31
- const operationVersion = contract.operationVersion;
32
- if ('number' != typeof operationVersion) throw new Error('Adapter parity hello contract requires operationVersion');
33
- return operationVersion + 1;
34
- };
35
- const createOperationContextDenialScenarios = ({ helloContract, validEnvelope, validOperationId })=>[
36
- deniedScenario('policy denies missing operation context', 'missing_operation_context', {
37
- 'x-modernjs-bff-envelope': validEnvelope
38
- }),
39
- deniedScenario('policy denies operation context mismatch', 'operation_context_mismatch', {
40
- 'x-modernjs-bff-envelope': validEnvelope,
41
- 'x-operation-id': 'someone-else:parity'
42
- }),
43
- deniedScenario('policy denies missing operation context details', 'missing_operation_context_details', {
44
- 'x-modernjs-bff-envelope': validEnvelope,
45
- 'x-operation-id': validOperationId
46
- }),
47
- deniedScenario('policy denies JSON-array operation context details', 'invalid_operation_context_details', {
48
- 'x-modernjs-bff-envelope': validEnvelope,
49
- 'x-operation-id': validOperationId,
50
- 'x-modernjs-bff-operation-context': '[]'
51
- }),
52
- deniedScenario('policy denies invalid operation context details', 'invalid_operation_context_details', {
53
- 'x-modernjs-bff-envelope': validEnvelope,
54
- 'x-operation-id': validOperationId,
55
- 'x-modernjs-bff-operation-context': 'not-json'
56
- }),
57
- deniedScenario('policy denies detail requestId mismatch', 'operation_context_details_request_id_mismatch', {
58
- 'x-modernjs-bff-envelope': validEnvelope,
59
- 'x-operation-id': validOperationId,
60
- 'x-modernjs-bff-operation-context': detailHeader({
61
- requestId: 'crm.producer-b',
62
- method: 'GET',
63
- routePath: '/hello',
64
- schemaHash: helloContract.schemaHash,
65
- operationVersion: helloContract.operationVersion
66
- })
67
- }),
68
- deniedScenario('policy denies missing operation schema hash', 'missing_operation_schema_hash', {
69
- 'x-modernjs-bff-envelope': validEnvelope,
70
- 'x-operation-id': validOperationId,
71
- 'x-modernjs-bff-operation-context': detailHeader({
72
- requestId: PARITY_PRODUCER_REQUEST_ID,
73
- method: 'GET',
74
- routePath: '/hello',
75
- operationVersion: helloContract.operationVersion
76
- })
77
- }),
78
- deniedScenario('policy denies missing operation version', 'missing_operation_version', {
79
- 'x-modernjs-bff-envelope': validEnvelope,
80
- 'x-operation-id': validOperationId,
81
- 'x-modernjs-bff-operation-context': detailHeader({
82
- requestId: PARITY_PRODUCER_REQUEST_ID,
83
- method: 'GET',
84
- routePath: '/hello',
85
- schemaHash: helloContract.schemaHash
86
- })
87
- }),
88
- deniedScenario('policy denies operation schema hash mismatch', 'operation_schema_hash_mismatch', {
89
- 'x-modernjs-bff-envelope': validEnvelope,
90
- 'x-operation-id': validOperationId,
91
- 'x-modernjs-bff-operation-context': detailHeader({
92
- requestId: PARITY_PRODUCER_REQUEST_ID,
93
- method: 'GET',
94
- routePath: '/hello',
95
- schemaHash: 'deadbeef',
96
- operationVersion: helloContract.operationVersion
97
- })
98
- }),
99
- deniedScenario('policy denies operation version mismatch', 'operation_version_mismatch', {
100
- 'x-modernjs-bff-envelope': validEnvelope,
101
- 'x-operation-id': validOperationId,
102
- 'x-modernjs-bff-operation-context': detailHeader({
103
- requestId: PARITY_PRODUCER_REQUEST_ID,
104
- method: 'GET',
105
- routePath: '/hello',
106
- schemaHash: helloContract.schemaHash,
107
- operationVersion: getMismatchedOperationVersion(helloContract)
108
- })
109
- })
110
- ];
111
- export { createOperationContextDenialScenarios, createOperationContextSuccessScenarios };