@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,57 +0,0 @@
1
- import fs from "fs";
2
- import module_0 from "module";
3
- import * as __rspack_external_os from "os";
4
- import * as __rspack_external_path from "path";
5
- const getRelativeRuntimePath = (appDirectory, serverRuntimePath)=>{
6
- let relativeRuntimePath = '';
7
- relativeRuntimePath = 'win32' === __rspack_external_os.platform() ? `../${__rspack_external_path.relative(appDirectory, serverRuntimePath)}` : __rspack_external_path.join('../', __rspack_external_path.relative(appDirectory, serverRuntimePath));
8
- if ('development' === process.env.NODE_ENV || 'test' === process.env.NODE_ENV) relativeRuntimePath = `./${__rspack_external_path.relative(appDirectory, serverRuntimePath)}`;
9
- return relativeRuntimePath;
10
- };
11
- const sortByLongestPrefix = (arr)=>arr.concat().sort((a, b)=>b.length - a.length);
12
- const createMatchPath = (paths)=>{
13
- const sortedKeys = sortByLongestPrefix(Object.keys(paths));
14
- const sortedPaths = {};
15
- sortedKeys.forEach((key)=>{
16
- sortedPaths[key] = paths[key];
17
- });
18
- return (request)=>{
19
- const found = Object.keys(sortedPaths).find((key)=>request.startsWith(key));
20
- if (found) {
21
- let foundPaths = sortedPaths[found];
22
- if (!Array.isArray(foundPaths)) foundPaths = [
23
- foundPaths
24
- ];
25
- foundPaths = foundPaths.filter((foundPath)=>__rspack_external_path.isAbsolute(foundPath));
26
- for (const p of foundPaths){
27
- const foundPath = request.replace(found, p);
28
- if (fs.existsSync(foundPath)) return foundPath;
29
- }
30
- return request.replace(found, foundPaths[0]);
31
- }
32
- return null;
33
- };
34
- };
35
- const registerPaths = (paths)=>{
36
- const originalResolveFilename = module_0._resolveFilename;
37
- const { builtinModules } = module_0;
38
- const matchPath = createMatchPath(paths);
39
- module_0._resolveFilename = function(request, _parent) {
40
- const isCoreModule = builtinModules.includes(request);
41
- if (!isCoreModule) {
42
- const matched = matchPath(request);
43
- if (matched) {
44
- const modifiedArguments = [
45
- matched,
46
- ...[].slice.call(arguments, 1)
47
- ];
48
- return originalResolveFilename.apply(this, modifiedArguments);
49
- }
50
- }
51
- return originalResolveFilename.apply(this, arguments);
52
- };
53
- return ()=>{
54
- module_0._resolveFilename = originalResolveFilename;
55
- };
56
- };
57
- export { createMatchPath, getRelativeRuntimePath, registerPaths };
@@ -1,80 +0,0 @@
1
- import "node:module";
2
- import "reflect-metadata";
3
- import { evaluateCrossProjectPolicy } from "../security/crossProjectPolicy.mjs";
4
- import { HttpMetadata, HttpMethod } from "../types.mjs";
5
- import { isInputParamsDeciderHandler, isWithMetaHandler } from "../utils/index.mjs";
6
- const API_ROUTE_METHODS = {
7
- [HttpMethod.Get]: 'get',
8
- [HttpMethod.Post]: 'post',
9
- [HttpMethod.Put]: 'put',
10
- [HttpMethod.Delete]: 'delete',
11
- [HttpMethod.Connect]: 'connect',
12
- [HttpMethod.Trace]: 'trace',
13
- [HttpMethod.Patch]: 'patch',
14
- [HttpMethod.Options]: 'options',
15
- [HttpMethod.Head]: 'head'
16
- };
17
- const toApiRouteMethod = (httpMethod)=>{
18
- const method = API_ROUTE_METHODS[httpMethod];
19
- if (!method) throw new Error(`[bff-core] Unsupported HTTP method "${String(httpMethod)}" in API handler info`);
20
- return method;
21
- };
22
- const getRouteMiddlewares = (handler)=>{
23
- const middlewares = Reflect.getMetadata('middleware', handler);
24
- return Array.isArray(middlewares) ? middlewares : [];
25
- };
26
- const planApiRoutes = (handlerInfos)=>handlerInfos.map(({ routePath, handler, httpMethod })=>({
27
- method: toApiRouteMethod(httpMethod),
28
- routePath,
29
- handler,
30
- middlewares: getRouteMiddlewares(handler)
31
- }));
32
- const HANDLER_WITH_SCHEMA = 'HANDLER_WITH_SCHEMA';
33
- const isSchemaApiHandler = (handler)=>{
34
- if ('function' != typeof handler) return false;
35
- const marked = handler;
36
- return true === marked[HANDLER_WITH_SCHEMA];
37
- };
38
- const getApiHandlerMode = (handler)=>{
39
- if (isWithMetaHandler(handler)) return 'meta';
40
- if (isSchemaApiHandler(handler)) return 'schema';
41
- if (isInputParamsDeciderHandler(handler)) return 'inputParamsDecider';
42
- return 'plain';
43
- };
44
- const mapSchemaHandlerResult = (result)=>{
45
- if ('HandleSuccess' === result.type) return {
46
- success: true,
47
- status: 200,
48
- body: result.value
49
- };
50
- return {
51
- success: false,
52
- status: 'InputValidationError' === result.type ? 400 : 500,
53
- body: result.message
54
- };
55
- };
56
- const getResponseMetaList = (handler)=>{
57
- const responseMeta = Reflect.getMetadata(HttpMetadata.Response, handler);
58
- return Array.isArray(responseMeta) ? responseMeta : [];
59
- };
60
- const buildPositionalHandlerArgs = (input, routePath)=>{
61
- const paramNames = routePath?.match(/:(\w+)/g)?.map((param)=>param.slice(1)) ?? [];
62
- const positionalParams = paramNames.length > 0 ? paramNames.map((param)=>input.params[param]) : Object.values(input.params);
63
- return [
64
- ...positionalParams,
65
- input
66
- ];
67
- };
68
- const checkCrossProjectPolicy = (headers, policy)=>{
69
- const violation = evaluateCrossProjectPolicy(headers, policy);
70
- if (!violation) return null;
71
- return {
72
- status: violation.status,
73
- body: {
74
- code: violation.code,
75
- reason: violation.reason,
76
- message: violation.message
77
- }
78
- };
79
- };
80
- export { HANDLER_WITH_SCHEMA, buildPositionalHandlerArgs, checkCrossProjectPolicy, getApiHandlerMode, getResponseMetaList, getRouteMiddlewares, isSchemaApiHandler, mapSchemaHandlerResult, planApiRoutes, toApiRouteMethod };
@@ -1,18 +0,0 @@
1
- import "node:module";
2
- import { deniedScenario, envelopeHeader } from "./shared.mjs";
3
- const createCrossProjectDenialScenarios = ()=>[
4
- deniedScenario('policy denies missing envelope', 'missing_envelope', {}),
5
- deniedScenario('policy denies invalid envelope', 'invalid_envelope', {
6
- 'x-modernjs-bff-envelope': 'not-json'
7
- }),
8
- deniedScenario('policy denies envelope that is valid JSON but not an object', 'invalid_envelope', {
9
- 'x-modernjs-bff-envelope': '123'
10
- }),
11
- deniedScenario('policy denies missing requestId', 'missing_request_id', {
12
- 'x-modernjs-bff-envelope': envelopeHeader(void 0)
13
- }),
14
- deniedScenario('policy denies namespace outside allowlist', 'namespace_not_allowed', {
15
- 'x-modernjs-bff-envelope': envelopeHeader('billing.producer-z')
16
- })
17
- ];
18
- export { createCrossProjectDenialScenarios };
@@ -1,91 +0,0 @@
1
- import "node:module";
2
- const createEnvelopeParityScenarios = ()=>[
3
- {
4
- name: 'plain handler returns object payload',
5
- policy: false,
6
- request: {
7
- method: 'get',
8
- path: '/hello'
9
- },
10
- expected: {
11
- kind: 'payload',
12
- status: 200,
13
- payload: {
14
- message: 'hello'
15
- }
16
- }
17
- },
18
- {
19
- name: 'plain handler returns scalar payload',
20
- policy: false,
21
- request: {
22
- method: 'post',
23
- path: '/hello'
24
- },
25
- expected: {
26
- kind: 'payload',
27
- status: 200,
28
- payload: 'hello'
29
- }
30
- },
31
- {
32
- name: 'plain handler returning undefined',
33
- policy: false,
34
- request: {
35
- method: 'get',
36
- path: '/nothing'
37
- },
38
- expected: {
39
- kind: 'payload',
40
- status: 404,
41
- payload: '404 Not Found'
42
- }
43
- },
44
- {
45
- name: 'plain handler receives data, query and cookies',
46
- policy: false,
47
- request: {
48
- method: 'post',
49
- path: '/echo?q=z',
50
- headers: {
51
- 'content-type': 'application/json',
52
- cookie: 'id=666'
53
- },
54
- body: {
55
- a: 1
56
- }
57
- },
58
- expected: {
59
- kind: 'payload',
60
- status: 200,
61
- payload: {
62
- data: {
63
- a: 1
64
- },
65
- query: {
66
- q: 'z'
67
- },
68
- cookie: 'id=666'
69
- }
70
- }
71
- },
72
- {
73
- name: 'plain handler receives positional route params',
74
- policy: false,
75
- request: {
76
- method: 'get',
77
- path: '/items/123?q=x'
78
- },
79
- expected: {
80
- kind: 'payload',
81
- status: 200,
82
- payload: {
83
- id: '123',
84
- query: {
85
- q: 'x'
86
- }
87
- }
88
- }
89
- }
90
- ];
91
- export { createEnvelopeParityScenarios };
@@ -1,112 +0,0 @@
1
- import "node:module";
2
- import { PARITY_PRODUCER_REQUEST_ID, deniedScenario, detailHeader } from "./shared.mjs";
3
- const createOperationContextSuccessScenarios = ({ helloContract, validEnvelope, validOperationId })=>[
4
- {
5
- name: 'policy pass with full operation context',
6
- policy: true,
7
- request: {
8
- method: 'get',
9
- path: '/hello',
10
- headers: {
11
- 'x-modernjs-bff-envelope': validEnvelope,
12
- 'x-operation-id': validOperationId,
13
- 'x-modernjs-bff-operation-context': detailHeader({
14
- requestId: PARITY_PRODUCER_REQUEST_ID,
15
- method: 'GET',
16
- routePath: '/hello',
17
- schemaHash: helloContract.schemaHash,
18
- operationVersion: helloContract.operationVersion
19
- })
20
- }
21
- },
22
- expected: {
23
- kind: 'payload',
24
- status: 200,
25
- payload: {
26
- message: 'hello'
27
- }
28
- }
29
- }
30
- ];
31
- const getMismatchedOperationVersion = (contract)=>{
32
- const operationVersion = contract.operationVersion;
33
- if ('number' != typeof operationVersion) throw new Error('Adapter parity hello contract requires operationVersion');
34
- return operationVersion + 1;
35
- };
36
- const createOperationContextDenialScenarios = ({ helloContract, validEnvelope, validOperationId })=>[
37
- deniedScenario('policy denies missing operation context', 'missing_operation_context', {
38
- 'x-modernjs-bff-envelope': validEnvelope
39
- }),
40
- deniedScenario('policy denies operation context mismatch', 'operation_context_mismatch', {
41
- 'x-modernjs-bff-envelope': validEnvelope,
42
- 'x-operation-id': 'someone-else:parity'
43
- }),
44
- deniedScenario('policy denies missing operation context details', 'missing_operation_context_details', {
45
- 'x-modernjs-bff-envelope': validEnvelope,
46
- 'x-operation-id': validOperationId
47
- }),
48
- deniedScenario('policy denies JSON-array operation context details', 'invalid_operation_context_details', {
49
- 'x-modernjs-bff-envelope': validEnvelope,
50
- 'x-operation-id': validOperationId,
51
- 'x-modernjs-bff-operation-context': '[]'
52
- }),
53
- deniedScenario('policy denies invalid operation context details', 'invalid_operation_context_details', {
54
- 'x-modernjs-bff-envelope': validEnvelope,
55
- 'x-operation-id': validOperationId,
56
- 'x-modernjs-bff-operation-context': 'not-json'
57
- }),
58
- deniedScenario('policy denies detail requestId mismatch', 'operation_context_details_request_id_mismatch', {
59
- 'x-modernjs-bff-envelope': validEnvelope,
60
- 'x-operation-id': validOperationId,
61
- 'x-modernjs-bff-operation-context': detailHeader({
62
- requestId: 'crm.producer-b',
63
- method: 'GET',
64
- routePath: '/hello',
65
- schemaHash: helloContract.schemaHash,
66
- operationVersion: helloContract.operationVersion
67
- })
68
- }),
69
- deniedScenario('policy denies missing operation schema hash', 'missing_operation_schema_hash', {
70
- 'x-modernjs-bff-envelope': validEnvelope,
71
- 'x-operation-id': validOperationId,
72
- 'x-modernjs-bff-operation-context': detailHeader({
73
- requestId: PARITY_PRODUCER_REQUEST_ID,
74
- method: 'GET',
75
- routePath: '/hello',
76
- operationVersion: helloContract.operationVersion
77
- })
78
- }),
79
- deniedScenario('policy denies missing operation version', 'missing_operation_version', {
80
- 'x-modernjs-bff-envelope': validEnvelope,
81
- 'x-operation-id': validOperationId,
82
- 'x-modernjs-bff-operation-context': detailHeader({
83
- requestId: PARITY_PRODUCER_REQUEST_ID,
84
- method: 'GET',
85
- routePath: '/hello',
86
- schemaHash: helloContract.schemaHash
87
- })
88
- }),
89
- deniedScenario('policy denies operation schema hash mismatch', 'operation_schema_hash_mismatch', {
90
- 'x-modernjs-bff-envelope': validEnvelope,
91
- 'x-operation-id': validOperationId,
92
- 'x-modernjs-bff-operation-context': detailHeader({
93
- requestId: PARITY_PRODUCER_REQUEST_ID,
94
- method: 'GET',
95
- routePath: '/hello',
96
- schemaHash: 'deadbeef',
97
- operationVersion: helloContract.operationVersion
98
- })
99
- }),
100
- deniedScenario('policy denies operation version mismatch', 'operation_version_mismatch', {
101
- 'x-modernjs-bff-envelope': validEnvelope,
102
- 'x-operation-id': validOperationId,
103
- 'x-modernjs-bff-operation-context': detailHeader({
104
- requestId: PARITY_PRODUCER_REQUEST_ID,
105
- method: 'GET',
106
- routePath: '/hello',
107
- schemaHash: helloContract.schemaHash,
108
- operationVersion: getMismatchedOperationVersion(helloContract)
109
- })
110
- })
111
- ];
112
- export { createOperationContextDenialScenarios, createOperationContextSuccessScenarios };
@@ -1,72 +0,0 @@
1
- import "node:module";
2
- const createSchemaParityScenarios = ()=>[
3
- {
4
- name: 'schema handler success',
5
- policy: false,
6
- request: {
7
- method: 'patch',
8
- path: '/schema',
9
- headers: {
10
- 'content-type': 'application/json'
11
- },
12
- body: {
13
- id: 777
14
- }
15
- },
16
- expected: {
17
- kind: 'payload',
18
- status: 200,
19
- payload: {
20
- type: 'HandleSuccess',
21
- value: {
22
- id: 777
23
- }
24
- }
25
- }
26
- },
27
- {
28
- name: 'schema handler input validation error',
29
- policy: false,
30
- request: {
31
- method: 'patch',
32
- path: '/schema',
33
- headers: {
34
- 'content-type': 'application/json'
35
- },
36
- body: {
37
- id: 'aaa'
38
- }
39
- },
40
- expected: {
41
- kind: 'payload',
42
- status: 200,
43
- payload: {
44
- type: 'InputValidationError',
45
- message: 'invalid input'
46
- }
47
- }
48
- },
49
- {
50
- name: 'schema handler output validation error',
51
- policy: false,
52
- request: {
53
- method: 'patch',
54
- path: '/schema',
55
- headers: {
56
- 'content-type': 'application/json'
57
- },
58
- body: {
59
- id: 'boom'
60
- }
61
- },
62
- expected: {
63
- kind: 'payload',
64
- status: 200,
65
- payload: {
66
- type: 'OutputValidationError',
67
- message: 'invalid output'
68
- }
69
- }
70
- }
71
- ];
72
- export { createSchemaParityScenarios };
@@ -1,22 +0,0 @@
1
- import "node:module";
2
- const PARITY_REQUEST_ID = 'crm';
3
- const PARITY_PRODUCER_REQUEST_ID = 'crm.producer-a';
4
- const envelopeHeader = (requestId)=>JSON.stringify(void 0 === requestId ? {} : {
5
- requestId
6
- });
7
- const detailHeader = (details)=>JSON.stringify(details);
8
- const deniedScenario = (name, reason, headers)=>({
9
- name,
10
- policy: true,
11
- request: {
12
- method: 'get',
13
- path: '/hello',
14
- headers
15
- },
16
- expected: {
17
- kind: 'denied',
18
- status: 403,
19
- reason
20
- }
21
- });
22
- export { PARITY_PRODUCER_REQUEST_ID, PARITY_REQUEST_ID, deniedScenario, detailHeader, envelopeHeader };
@@ -1,149 +0,0 @@
1
- import "node:module";
2
- import { buildOperationContractMap } from "../security/operationContracts.mjs";
3
- import { HttpMethod } from "../types.mjs";
4
- import { createCrossProjectDenialScenarios } from "./parity-scenarios/cross-project-denial.mjs";
5
- import { createEnvelopeParityScenarios } from "./parity-scenarios/envelope.mjs";
6
- import { createOperationContextDenialScenarios, createOperationContextSuccessScenarios } from "./parity-scenarios/operation-context.mjs";
7
- import { createSchemaParityScenarios } from "./parity-scenarios/schema.mjs";
8
- import { PARITY_PRODUCER_REQUEST_ID, PARITY_REQUEST_ID, envelopeHeader } from "./parity-scenarios/shared.mjs";
9
- const PARITY_FIXTURE_FILENAME = 'bff-core/adapter-kit/parity-fixture.ts';
10
- const HANDLER_WITH_SCHEMA = 'HANDLER_WITH_SCHEMA';
11
- const isRecord = (value)=>Boolean(value) && 'object' == typeof value;
12
- const createSchemaFixtureHandler = ()=>{
13
- const handler = (input)=>{
14
- const data = isRecord(input) && isRecord(input.data) ? input.data : void 0;
15
- const id = data?.id;
16
- if ('number' == typeof id) return {
17
- type: 'HandleSuccess',
18
- value: {
19
- id
20
- }
21
- };
22
- if ('boom' === id) return {
23
- type: 'OutputValidationError',
24
- message: 'invalid output'
25
- };
26
- return {
27
- type: 'InputValidationError',
28
- message: 'invalid input'
29
- };
30
- };
31
- return Object.assign(handler, {
32
- [HANDLER_WITH_SCHEMA]: true
33
- });
34
- };
35
- const createParityApiHandlerInfos = ()=>[
36
- {
37
- name: 'getHello',
38
- httpMethod: HttpMethod.Get,
39
- routeName: '/hello',
40
- routePath: '/hello',
41
- filename: PARITY_FIXTURE_FILENAME,
42
- handler: ()=>({
43
- message: 'hello'
44
- })
45
- },
46
- {
47
- name: 'postHello',
48
- httpMethod: HttpMethod.Post,
49
- routeName: '/hello',
50
- routePath: '/hello',
51
- filename: PARITY_FIXTURE_FILENAME,
52
- handler: ()=>'hello'
53
- },
54
- {
55
- name: 'getNothing',
56
- httpMethod: HttpMethod.Get,
57
- routeName: '/nothing',
58
- routePath: '/nothing',
59
- filename: PARITY_FIXTURE_FILENAME,
60
- handler: ()=>void 0
61
- },
62
- {
63
- name: 'postEcho',
64
- httpMethod: HttpMethod.Post,
65
- routeName: '/echo',
66
- routePath: '/echo',
67
- filename: PARITY_FIXTURE_FILENAME,
68
- handler: (input)=>{
69
- const normalized = isRecord(input) ? input : {};
70
- return {
71
- data: normalized.data ?? null,
72
- query: normalized.query ?? {},
73
- cookie: normalized.cookies ?? null
74
- };
75
- }
76
- },
77
- {
78
- name: 'getItem',
79
- httpMethod: HttpMethod.Get,
80
- routeName: '/items/:id',
81
- routePath: '/items/:id',
82
- filename: PARITY_FIXTURE_FILENAME,
83
- handler: (id, input)=>({
84
- id,
85
- query: isRecord(input) ? input.query ?? {} : {}
86
- })
87
- },
88
- {
89
- name: 'patchSchema',
90
- httpMethod: HttpMethod.Patch,
91
- routeName: '/schema',
92
- routePath: '/schema',
93
- filename: PARITY_FIXTURE_FILENAME,
94
- handler: createSchemaFixtureHandler()
95
- }
96
- ];
97
- const createParityBffConfig = ()=>({
98
- requestId: PARITY_PRODUCER_REQUEST_ID,
99
- crossProjectPolicy: {
100
- enabled: true,
101
- allowedNamespaces: [
102
- PARITY_REQUEST_ID
103
- ],
104
- allowClientAssertedNamespace: true
105
- }
106
- });
107
- const getParityContracts = ()=>buildOperationContractMap({
108
- handlers: createParityApiHandlerInfos(),
109
- requestId: PARITY_PRODUCER_REQUEST_ID
110
- });
111
- const createAdapterParityScenarios = ()=>{
112
- const contracts = getParityContracts();
113
- const helloContract = contracts['GET:/hello'];
114
- const validEnvelope = envelopeHeader(PARITY_PRODUCER_REQUEST_ID);
115
- const validOperationId = helloContract.operationId;
116
- const context = {
117
- helloContract,
118
- validEnvelope,
119
- validOperationId
120
- };
121
- return [
122
- ...createEnvelopeParityScenarios(),
123
- ...createSchemaParityScenarios(),
124
- ...createOperationContextSuccessScenarios(context),
125
- ...createCrossProjectDenialScenarios(),
126
- ...createOperationContextDenialScenarios(context)
127
- ];
128
- };
129
- const toParityResult = (res)=>({
130
- status: res.status,
131
- payload: res.type.includes('json') ? res.body : '' === res.text ? void 0 : res.text
132
- });
133
- const formatValue = (value)=>JSON.stringify(value);
134
- const assertParityResult = (scenario, res)=>{
135
- const result = toParityResult(res);
136
- const failures = [];
137
- const { expected } = scenario;
138
- if (result.status !== expected.status) failures.push(`status: expected ${expected.status}, received ${result.status}`);
139
- if ('payload' === expected.kind) {
140
- if (formatValue(result.payload) !== formatValue(expected.payload)) failures.push(`payload: expected ${formatValue(expected.payload)}, received ${formatValue(result.payload)}`);
141
- } else {
142
- const payload = isRecord(result.payload) ? result.payload : {};
143
- if ('BFF_CROSS_PROJECT_POLICY_DENIED' !== payload.code) failures.push(`denial code: expected "BFF_CROSS_PROJECT_POLICY_DENIED", received ${formatValue(payload.code)}`);
144
- if (payload.reason !== expected.reason) failures.push(`denial reason: expected "${expected.reason}", received ${formatValue(payload.reason)}`);
145
- if ('string' != typeof payload.message || 0 === payload.message.length) failures.push(`denial message: expected non-empty string, received ${formatValue(payload.message)}`);
146
- }
147
- if (failures.length > 0) throw new Error(`Adapter parity scenario "${scenario.name}" failed:\n- ${failures.join('\n- ')}`);
148
- };
149
- export { PARITY_PRODUCER_REQUEST_ID, PARITY_REQUEST_ID, assertParityResult, createAdapterParityScenarios, createParityApiHandlerInfos, createParityBffConfig, toParityResult };