@geekmidas/constructs 0.0.1
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/README.md +614 -0
- package/dist/AWSLambdaFunction-CpHFE2m6.d.mts +27 -0
- package/dist/AWSLambdaFunction-CwagvPG3.d.cts +27 -0
- package/dist/AWSLambdaFunction-DWIZYsCy.mjs +79 -0
- package/dist/AWSLambdaFunction-DWIZYsCy.mjs.map +1 -0
- package/dist/AWSLambdaFunction-qA5LqPsv.cjs +85 -0
- package/dist/AWSLambdaFunction-qA5LqPsv.cjs.map +1 -0
- package/dist/AWSLambdaSubscriberAdaptor-C1wQuucQ.d.mts +32 -0
- package/dist/AWSLambdaSubscriberAdaptor-CmPZ10JF.cjs +138 -0
- package/dist/AWSLambdaSubscriberAdaptor-CmPZ10JF.cjs.map +1 -0
- package/dist/AWSLambdaSubscriberAdaptor-G8y3YkWj.mjs +132 -0
- package/dist/AWSLambdaSubscriberAdaptor-G8y3YkWj.mjs.map +1 -0
- package/dist/AWSLambdaSubscriberAdaptor-QKVxR6qh.d.cts +32 -0
- package/dist/AmazonApiGatewayEndpointAdaptor-BoBh7vvD.d.mts +61 -0
- package/dist/AmazonApiGatewayEndpointAdaptor-Cx1oqcqh.mjs +124 -0
- package/dist/AmazonApiGatewayEndpointAdaptor-Cx1oqcqh.mjs.map +1 -0
- package/dist/AmazonApiGatewayEndpointAdaptor-DtzgQ9Vb.d.cts +61 -0
- package/dist/AmazonApiGatewayEndpointAdaptor-i74DEUbc.cjs +130 -0
- package/dist/AmazonApiGatewayEndpointAdaptor-i74DEUbc.cjs.map +1 -0
- package/dist/AmazonApiGatewayV1EndpointAdaptor-CLmBDYsl.mjs +42 -0
- package/dist/AmazonApiGatewayV1EndpointAdaptor-CLmBDYsl.mjs.map +1 -0
- package/dist/AmazonApiGatewayV1EndpointAdaptor-EhMd1YqV.d.mts +21 -0
- package/dist/AmazonApiGatewayV1EndpointAdaptor-GkMAUPL5.cjs +47 -0
- package/dist/AmazonApiGatewayV1EndpointAdaptor-GkMAUPL5.cjs.map +1 -0
- package/dist/AmazonApiGatewayV1EndpointAdaptor-Gw-j61qM.d.cts +21 -0
- package/dist/AmazonApiGatewayV2EndpointAdaptor-3RqegmJC.mjs +41 -0
- package/dist/AmazonApiGatewayV2EndpointAdaptor-3RqegmJC.mjs.map +1 -0
- package/dist/AmazonApiGatewayV2EndpointAdaptor-LUlpwmUW.d.cts +21 -0
- package/dist/AmazonApiGatewayV2EndpointAdaptor-YlFoFSS9.cjs +46 -0
- package/dist/AmazonApiGatewayV2EndpointAdaptor-YlFoFSS9.cjs.map +1 -0
- package/dist/AmazonApiGatewayV2EndpointAdaptor-zfd1gqXA.d.mts +21 -0
- package/dist/BaseFunctionBuilder-5QCHkchp.d.cts +31 -0
- package/dist/BaseFunctionBuilder-BFPVGnKi.d.mts +31 -0
- package/dist/BaseFunctionBuilder-BPE9JBbT.mjs +56 -0
- package/dist/BaseFunctionBuilder-BPE9JBbT.mjs.map +1 -0
- package/dist/BaseFunctionBuilder-DtO4Nwxm.cjs +62 -0
- package/dist/BaseFunctionBuilder-DtO4Nwxm.cjs.map +1 -0
- package/dist/Construct-BSEs6uwW.cjs +75 -0
- package/dist/Construct-BSEs6uwW.cjs.map +1 -0
- package/dist/Construct-BbKCIPQm.mjs +63 -0
- package/dist/Construct-BbKCIPQm.mjs.map +1 -0
- package/dist/Construct-Bm-PSO2V.d.cts +42 -0
- package/dist/Construct-DIguIyw4.d.mts +42 -0
- package/dist/Construct.cjs +4 -0
- package/dist/Construct.d.cts +2 -0
- package/dist/Construct.d.mts +2 -0
- package/dist/Construct.mjs +3 -0
- package/dist/Cron-Bgs6EQOb.mjs +20 -0
- package/dist/Cron-Bgs6EQOb.mjs.map +1 -0
- package/dist/Cron-DQiCj3ef.cjs +25 -0
- package/dist/Cron-DQiCj3ef.cjs.map +1 -0
- package/dist/Cron-FpAw03k6.d.mts +25 -0
- package/dist/Cron-ztnK6zgU.d.cts +25 -0
- package/dist/CronBuilder-B2clNQSP.d.mts +24 -0
- package/dist/CronBuilder-Cje9K8lZ.d.cts +24 -0
- package/dist/CronBuilder-DIBqJkh_.cjs +60 -0
- package/dist/CronBuilder-DIBqJkh_.cjs.map +1 -0
- package/dist/CronBuilder-DecAvvcn.mjs +54 -0
- package/dist/CronBuilder-DecAvvcn.mjs.map +1 -0
- package/dist/Endpoint-BaHC9y4Z.cjs +291 -0
- package/dist/Endpoint-BaHC9y4Z.cjs.map +1 -0
- package/dist/Endpoint-C7z9YJHK.d.cts +405 -0
- package/dist/Endpoint-DCn53Vd8.d.mts +405 -0
- package/dist/Endpoint-ierdM62O.mjs +279 -0
- package/dist/Endpoint-ierdM62O.mjs.map +1 -0
- package/dist/EndpointBuilder-BHFSpbPR.cjs +107 -0
- package/dist/EndpointBuilder-BHFSpbPR.cjs.map +1 -0
- package/dist/EndpointBuilder-BLUsoK3l.mjs +101 -0
- package/dist/EndpointBuilder-BLUsoK3l.mjs.map +1 -0
- package/dist/EndpointBuilder-Bfnb2oJr.d.mts +49 -0
- package/dist/EndpointBuilder-CP9RGwZH.d.cts +49 -0
- package/dist/EndpointFactory-BYdDVCNj.mjs +127 -0
- package/dist/EndpointFactory-BYdDVCNj.mjs.map +1 -0
- package/dist/EndpointFactory-CNtMXgIh.d.mts +52 -0
- package/dist/EndpointFactory-CXX4E6Gx.cjs +139 -0
- package/dist/EndpointFactory-CXX4E6Gx.cjs.map +1 -0
- package/dist/EndpointFactory-D2zgWbXZ.d.cts +52 -0
- package/dist/Function-BP58p9Mp.d.cts +59 -0
- package/dist/Function-BsBxc2wA.d.mts +59 -0
- package/dist/Function-C5mW-38v.mjs +72 -0
- package/dist/Function-C5mW-38v.mjs.map +1 -0
- package/dist/Function-CbO2NZx-.cjs +84 -0
- package/dist/Function-CbO2NZx-.cjs.map +1 -0
- package/dist/FunctionBuilder-BS1KgxA_.d.cts +24 -0
- package/dist/FunctionBuilder-C-PfPN3r.d.mts +24 -0
- package/dist/FunctionBuilder-CosgPmMl.mjs +53 -0
- package/dist/FunctionBuilder-CosgPmMl.mjs.map +1 -0
- package/dist/FunctionBuilder-DuOeWCAl.cjs +59 -0
- package/dist/FunctionBuilder-DuOeWCAl.cjs.map +1 -0
- package/dist/FunctionExecutionWrapper-Bx-Dl-2a.d.cts +24 -0
- package/dist/FunctionExecutionWrapper-CElXEjPe.cjs +42 -0
- package/dist/FunctionExecutionWrapper-CElXEjPe.cjs.map +1 -0
- package/dist/FunctionExecutionWrapper-DvglBBjE.d.mts +24 -0
- package/dist/FunctionExecutionWrapper-XGrSAAPD.mjs +36 -0
- package/dist/FunctionExecutionWrapper-XGrSAAPD.mjs.map +1 -0
- package/dist/HonoEndpointAdaptor-B0IO1zj2.d.mts +41 -0
- package/dist/HonoEndpointAdaptor-B4snrp7v.cjs +154 -0
- package/dist/HonoEndpointAdaptor-B4snrp7v.cjs.map +1 -0
- package/dist/HonoEndpointAdaptor-B6lW9Q1k.d.cts +41 -0
- package/dist/HonoEndpointAdaptor-D-M4-6Tf.mjs +148 -0
- package/dist/HonoEndpointAdaptor-D-M4-6Tf.mjs.map +1 -0
- package/dist/Subscriber-BoFm12i_.d.cts +33 -0
- package/dist/Subscriber-BwuCaC9G.mjs +28 -0
- package/dist/Subscriber-BwuCaC9G.mjs.map +1 -0
- package/dist/Subscriber-THGsj7Iy.d.mts +33 -0
- package/dist/Subscriber-iMRFG7ba.cjs +34 -0
- package/dist/Subscriber-iMRFG7ba.cjs.map +1 -0
- package/dist/SubscriberBuilder-CiPxgnKT.d.mts +26 -0
- package/dist/SubscriberBuilder-Dhz0C_t-.mjs +54 -0
- package/dist/SubscriberBuilder-Dhz0C_t-.mjs.map +1 -0
- package/dist/SubscriberBuilder-DuIgxuzc.d.cts +26 -0
- package/dist/SubscriberBuilder-wthr-FL9.cjs +60 -0
- package/dist/SubscriberBuilder-wthr-FL9.cjs.map +1 -0
- package/dist/adaptors/aws.cjs +19 -0
- package/dist/adaptors/aws.d.cts +15 -0
- package/dist/adaptors/aws.d.mts +15 -0
- package/dist/adaptors/aws.mjs +16 -0
- package/dist/adaptors/hono.cjs +12 -0
- package/dist/adaptors/hono.d.cts +9 -0
- package/dist/adaptors/hono.d.mts +9 -0
- package/dist/adaptors/hono.mjs +12 -0
- package/dist/chunk-CUT6urMc.cjs +30 -0
- package/dist/crons/Cron.cjs +8 -0
- package/dist/crons/Cron.d.cts +7 -0
- package/dist/crons/Cron.d.mts +7 -0
- package/dist/crons/Cron.mjs +8 -0
- package/dist/crons/CronBuilder.cjs +9 -0
- package/dist/crons/CronBuilder.d.cts +8 -0
- package/dist/crons/CronBuilder.d.mts +8 -0
- package/dist/crons/CronBuilder.mjs +9 -0
- package/dist/crons/index.cjs +16 -0
- package/dist/crons/index.cjs.map +1 -0
- package/dist/crons/index.d.cts +16 -0
- package/dist/crons/index.d.mts +16 -0
- package/dist/crons/index.mjs +14 -0
- package/dist/crons/index.mjs.map +1 -0
- package/dist/endpoints/AmazonApiGatewayEndpointAdaptor.cjs +10 -0
- package/dist/endpoints/AmazonApiGatewayEndpointAdaptor.d.cts +9 -0
- package/dist/endpoints/AmazonApiGatewayEndpointAdaptor.d.mts +9 -0
- package/dist/endpoints/AmazonApiGatewayEndpointAdaptor.mjs +10 -0
- package/dist/endpoints/AmazonApiGatewayV1EndpointAdaptor.cjs +12 -0
- package/dist/endpoints/AmazonApiGatewayV1EndpointAdaptor.d.cts +10 -0
- package/dist/endpoints/AmazonApiGatewayV1EndpointAdaptor.d.mts +10 -0
- package/dist/endpoints/AmazonApiGatewayV1EndpointAdaptor.mjs +12 -0
- package/dist/endpoints/AmazonApiGatewayV2EndpointAdaptor.cjs +12 -0
- package/dist/endpoints/AmazonApiGatewayV2EndpointAdaptor.d.cts +10 -0
- package/dist/endpoints/AmazonApiGatewayV2EndpointAdaptor.d.mts +10 -0
- package/dist/endpoints/AmazonApiGatewayV2EndpointAdaptor.mjs +12 -0
- package/dist/endpoints/Endpoint.cjs +9 -0
- package/dist/endpoints/Endpoint.d.cts +8 -0
- package/dist/endpoints/Endpoint.d.mts +8 -0
- package/dist/endpoints/Endpoint.mjs +8 -0
- package/dist/endpoints/EndpointBuilder.cjs +9 -0
- package/dist/endpoints/EndpointBuilder.d.cts +9 -0
- package/dist/endpoints/EndpointBuilder.d.mts +9 -0
- package/dist/endpoints/EndpointBuilder.mjs +9 -0
- package/dist/endpoints/EndpointFactory.cjs +11 -0
- package/dist/endpoints/EndpointFactory.d.cts +10 -0
- package/dist/endpoints/EndpointFactory.d.mts +10 -0
- package/dist/endpoints/EndpointFactory.mjs +10 -0
- package/dist/endpoints/HonoEndpointAdaptor.cjs +12 -0
- package/dist/endpoints/HonoEndpointAdaptor.d.cts +9 -0
- package/dist/endpoints/HonoEndpointAdaptor.d.mts +9 -0
- package/dist/endpoints/HonoEndpointAdaptor.mjs +12 -0
- package/dist/endpoints/TestEndpointAdaptor.cjs +54 -0
- package/dist/endpoints/TestEndpointAdaptor.cjs.map +1 -0
- package/dist/endpoints/TestEndpointAdaptor.d.cts +29 -0
- package/dist/endpoints/TestEndpointAdaptor.d.mts +29 -0
- package/dist/endpoints/TestEndpointAdaptor.mjs +53 -0
- package/dist/endpoints/TestEndpointAdaptor.mjs.map +1 -0
- package/dist/endpoints/helpers.cjs +10 -0
- package/dist/endpoints/helpers.d.cts +58 -0
- package/dist/endpoints/helpers.d.mts +58 -0
- package/dist/endpoints/helpers.mjs +9 -0
- package/dist/endpoints/index.cjs +16 -0
- package/dist/endpoints/index.cjs.map +1 -0
- package/dist/endpoints/index.d.cts +16 -0
- package/dist/endpoints/index.d.mts +16 -0
- package/dist/endpoints/index.mjs +15 -0
- package/dist/endpoints/index.mjs.map +1 -0
- package/dist/endpoints/parseHonoQuery.cjs +3 -0
- package/dist/endpoints/parseHonoQuery.d.cts +12 -0
- package/dist/endpoints/parseHonoQuery.d.mts +12 -0
- package/dist/endpoints/parseHonoQuery.mjs +3 -0
- package/dist/endpoints/parseQueryParams.cjs +3 -0
- package/dist/endpoints/parseQueryParams.d.cts +13 -0
- package/dist/endpoints/parseQueryParams.d.mts +13 -0
- package/dist/endpoints/parseQueryParams.mjs +3 -0
- package/dist/functions/AWSLambdaFunction.cjs +9 -0
- package/dist/functions/AWSLambdaFunction.d.cts +5 -0
- package/dist/functions/AWSLambdaFunction.d.mts +5 -0
- package/dist/functions/AWSLambdaFunction.mjs +9 -0
- package/dist/functions/BaseFunctionBuilder.cjs +4 -0
- package/dist/functions/BaseFunctionBuilder.d.cts +3 -0
- package/dist/functions/BaseFunctionBuilder.d.mts +3 -0
- package/dist/functions/BaseFunctionBuilder.mjs +4 -0
- package/dist/functions/Function.cjs +5 -0
- package/dist/functions/Function.d.cts +3 -0
- package/dist/functions/Function.d.mts +3 -0
- package/dist/functions/Function.mjs +4 -0
- package/dist/functions/FunctionBuilder.cjs +6 -0
- package/dist/functions/FunctionBuilder.d.cts +5 -0
- package/dist/functions/FunctionBuilder.d.mts +5 -0
- package/dist/functions/FunctionBuilder.mjs +6 -0
- package/dist/functions/FunctionExecutionWrapper.cjs +8 -0
- package/dist/functions/FunctionExecutionWrapper.d.cts +4 -0
- package/dist/functions/FunctionExecutionWrapper.d.mts +4 -0
- package/dist/functions/FunctionExecutionWrapper.mjs +8 -0
- package/dist/functions/TestFunctionAdaptor.cjs +38 -0
- package/dist/functions/TestFunctionAdaptor.cjs.map +1 -0
- package/dist/functions/TestFunctionAdaptor.d.cts +26 -0
- package/dist/functions/TestFunctionAdaptor.d.mts +26 -0
- package/dist/functions/TestFunctionAdaptor.mjs +37 -0
- package/dist/functions/TestFunctionAdaptor.mjs.map +1 -0
- package/dist/functions/index.cjs +10 -0
- package/dist/functions/index.d.cts +6 -0
- package/dist/functions/index.d.mts +6 -0
- package/dist/functions/index.mjs +7 -0
- package/dist/functions-DVDb5wEA.cjs +13 -0
- package/dist/functions-DVDb5wEA.cjs.map +1 -0
- package/dist/functions-mM-jcphA.mjs +8 -0
- package/dist/functions-mM-jcphA.mjs.map +1 -0
- package/dist/helpers-BeGM4pP_.cjs +95 -0
- package/dist/helpers-BeGM4pP_.cjs.map +1 -0
- package/dist/helpers-DbpO95aE.mjs +83 -0
- package/dist/helpers-DbpO95aE.mjs.map +1 -0
- package/dist/index-CuGR4L7O.d.mts +9 -0
- package/dist/index-Fg3N3EKD.d.cts +9 -0
- package/dist/index.cjs +4 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.mjs +3 -0
- package/dist/parseHonoQuery-DopC24vB.cjs +37 -0
- package/dist/parseHonoQuery-DopC24vB.cjs.map +1 -0
- package/dist/parseHonoQuery-znDKBhdE.mjs +31 -0
- package/dist/parseHonoQuery-znDKBhdE.mjs.map +1 -0
- package/dist/parseQueryParams-BJaRh3OB.mjs +32 -0
- package/dist/parseQueryParams-BJaRh3OB.mjs.map +1 -0
- package/dist/parseQueryParams-BzPop4I1.cjs +38 -0
- package/dist/parseQueryParams-BzPop4I1.cjs.map +1 -0
- package/dist/publisher-Bw4770Hi.mjs +41 -0
- package/dist/publisher-Bw4770Hi.mjs.map +1 -0
- package/dist/publisher-lFQleddL.cjs +53 -0
- package/dist/publisher-lFQleddL.cjs.map +1 -0
- package/dist/publisher.cjs +4 -0
- package/dist/publisher.d.cts +13 -0
- package/dist/publisher.d.mts +13 -0
- package/dist/publisher.mjs +3 -0
- package/dist/subscribers/AWSLambdaSubscriberAdaptor.cjs +3 -0
- package/dist/subscribers/AWSLambdaSubscriberAdaptor.d.cts +4 -0
- package/dist/subscribers/AWSLambdaSubscriberAdaptor.d.mts +4 -0
- package/dist/subscribers/AWSLambdaSubscriberAdaptor.mjs +3 -0
- package/dist/subscribers/Subscriber.cjs +4 -0
- package/dist/subscribers/Subscriber.d.cts +3 -0
- package/dist/subscribers/Subscriber.d.mts +3 -0
- package/dist/subscribers/Subscriber.mjs +4 -0
- package/dist/subscribers/SubscriberBuilder.cjs +5 -0
- package/dist/subscribers/SubscriberBuilder.d.cts +4 -0
- package/dist/subscribers/SubscriberBuilder.d.mts +4 -0
- package/dist/subscribers/SubscriberBuilder.mjs +5 -0
- package/dist/subscribers/index.cjs +12 -0
- package/dist/subscribers/index.cjs.map +1 -0
- package/dist/subscribers/index.d.cts +10 -0
- package/dist/subscribers/index.d.mts +10 -0
- package/dist/subscribers/index.mjs +10 -0
- package/dist/subscribers/index.mjs.map +1 -0
- package/dist/types-Bp9ysFXd.d.cts +7 -0
- package/dist/types-DBKNYvsW.d.mts +7 -0
- package/dist/types.cjs +0 -0
- package/dist/types.d.cts +2 -0
- package/dist/types.d.mts +2 -0
- package/dist/types.mjs +0 -0
- package/package.json +91 -0
- package/src/Construct.ts +98 -0
- package/src/__tests__/Construct.environment.spec.ts +360 -0
- package/src/__tests__/publisher.setting.spec.ts +511 -0
- package/src/__tests__/publisher.spec.ts +454 -0
- package/src/adaptors/aws.ts +4 -0
- package/src/adaptors/hono.ts +1 -0
- package/src/crons/Cron.ts +137 -0
- package/src/crons/CronBuilder.ts +192 -0
- package/src/crons/__tests__/Cron.spec.ts +464 -0
- package/src/crons/index.ts +11 -0
- package/src/endpoints/AmazonApiGatewayEndpointAdaptor.ts +315 -0
- package/src/endpoints/AmazonApiGatewayV1EndpointAdaptor.ts +101 -0
- package/src/endpoints/AmazonApiGatewayV2EndpointAdaptor.ts +95 -0
- package/src/endpoints/Endpoint.ts +771 -0
- package/src/endpoints/EndpointBuilder.ts +308 -0
- package/src/endpoints/EndpointFactory.ts +329 -0
- package/src/endpoints/HonoEndpointAdaptor.ts +365 -0
- package/src/endpoints/TestEndpointAdaptor.ts +130 -0
- package/src/endpoints/__tests__/AmazonApiGatewayV1EndpointAdaptor.events.spec.ts +553 -0
- package/src/endpoints/__tests__/AmazonApiGatewayV1EndpointAdaptor.spec.ts +927 -0
- package/src/endpoints/__tests__/AmazonApiGatewayV2EndpointAdaptor.events.spec.ts +721 -0
- package/src/endpoints/__tests__/AmazonApiGatewayV2EndpointAdaptor.factory-publisher.spec.ts +296 -0
- package/src/endpoints/__tests__/AmazonApiGatewayV2EndpointAdaptor.spec.ts +441 -0
- package/src/endpoints/__tests__/Endpoint.spec.ts +800 -0
- package/src/endpoints/__tests__/EndpointBuilder.spec.ts +488 -0
- package/src/endpoints/__tests__/EndpointFactory.spec.ts +479 -0
- package/src/endpoints/__tests__/HonoEndpointAdaptor.events.spec.ts +569 -0
- package/src/endpoints/__tests__/HonoEndpointAdaptor.openapi.spec.ts +313 -0
- package/src/endpoints/__tests__/HonoEndpointAdaptor.spec.ts +1078 -0
- package/src/endpoints/__tests__/TestEndpointAdaptor.spec.ts +236 -0
- package/src/endpoints/__tests__/__snapshots__/HonoEndpointAdaptor.spec.ts.snap +54 -0
- package/src/endpoints/__tests__/endpoint-types.test.ts +88 -0
- package/src/endpoints/helpers.ts +99 -0
- package/src/endpoints/index.ts +5 -0
- package/src/endpoints/parseHonoQuery.ts +51 -0
- package/src/endpoints/parseQueryParams.ts +51 -0
- package/src/functions/AWSLambdaFunction.ts +222 -0
- package/src/functions/BaseFunctionBuilder.ts +110 -0
- package/src/functions/Function.ts +160 -0
- package/src/functions/FunctionBuilder.ts +182 -0
- package/src/functions/FunctionExecutionWrapper.ts +86 -0
- package/src/functions/TestFunctionAdaptor.ts +125 -0
- package/src/functions/__tests__/AWSLambdaFunctionAdaptor.spec.ts +376 -0
- package/src/functions/__tests__/Function.spec.ts +402 -0
- package/src/functions/__tests__/TestFunctionAdaptor.spec.ts +398 -0
- package/src/functions/index.ts +10 -0
- package/src/index.ts +14 -0
- package/src/publisher.ts +83 -0
- package/src/subscribers/AWSLambdaSubscriberAdaptor.ts +269 -0
- package/src/subscribers/Subscriber.ts +112 -0
- package/src/subscribers/SubscriberBuilder.ts +150 -0
- package/src/subscribers/__tests__/AWSLambdaSubscriberAdaptor.spec.ts +623 -0
- package/src/subscribers/__tests__/Subscriber.spec.ts +432 -0
- package/src/subscribers/index.ts +5 -0
- package/src/types.ts +13 -0
- package/tsdown.config.ts +3 -0
|
@@ -0,0 +1,800 @@
|
|
|
1
|
+
import { EnvironmentParser } from '@geekmidas/envkit';
|
|
2
|
+
import type { Logger } from '@geekmidas/logger';
|
|
3
|
+
import { ServiceDiscovery } from '@geekmidas/services';
|
|
4
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
5
|
+
import { z } from 'zod/v4';
|
|
6
|
+
import { Endpoint } from '../Endpoint';
|
|
7
|
+
|
|
8
|
+
describe('Endpoint', () => {
|
|
9
|
+
describe('toOpenApi3Route', () => {
|
|
10
|
+
it('should generate basic OpenAPI spec for GET endpoint', async () => {
|
|
11
|
+
const endpoint = new Endpoint({
|
|
12
|
+
route: '/users',
|
|
13
|
+
method: 'GET',
|
|
14
|
+
authorize: undefined,
|
|
15
|
+
description: 'Get all users',
|
|
16
|
+
fn: async () => [],
|
|
17
|
+
input: undefined,
|
|
18
|
+
status: undefined,
|
|
19
|
+
getSession: undefined,
|
|
20
|
+
output: undefined,
|
|
21
|
+
services: [],
|
|
22
|
+
logger: {} as any,
|
|
23
|
+
timeout: undefined,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const spec = await endpoint.toOpenApi3Route();
|
|
27
|
+
|
|
28
|
+
expect(spec).toEqual({
|
|
29
|
+
'/users': {
|
|
30
|
+
get: {
|
|
31
|
+
description: 'Get all users',
|
|
32
|
+
responses: {
|
|
33
|
+
'200': {
|
|
34
|
+
description: 'Successful response',
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should include response schema when output is defined', async () => {
|
|
43
|
+
const outputSchema = z.object({
|
|
44
|
+
id: z.string(),
|
|
45
|
+
name: z.string(),
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const endpoint = new Endpoint({
|
|
49
|
+
route: '/users/:id',
|
|
50
|
+
method: 'GET',
|
|
51
|
+
description: 'Get user by ID',
|
|
52
|
+
fn: async () => ({ id: '1', name: 'John' }),
|
|
53
|
+
input: undefined,
|
|
54
|
+
output: outputSchema,
|
|
55
|
+
authorize: undefined,
|
|
56
|
+
services: [],
|
|
57
|
+
status: undefined,
|
|
58
|
+
getSession: undefined,
|
|
59
|
+
logger: {} as any,
|
|
60
|
+
timeout: undefined,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const spec = await endpoint.toOpenApi3Route();
|
|
64
|
+
const doc = spec['/users/{id}'];
|
|
65
|
+
expect(doc.get.responses?.['200']).toHaveProperty('content');
|
|
66
|
+
expect(
|
|
67
|
+
(doc.get.responses?.['200'] as any).content['application/json'].schema,
|
|
68
|
+
).toMatchObject({
|
|
69
|
+
type: 'object',
|
|
70
|
+
properties: {
|
|
71
|
+
id: { type: 'string' },
|
|
72
|
+
name: { type: 'string' },
|
|
73
|
+
},
|
|
74
|
+
required: ['id', 'name'],
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('should include request body for POST endpoint', async () => {
|
|
79
|
+
const bodySchema = z.object({
|
|
80
|
+
name: z.string(),
|
|
81
|
+
email: z.string().email(),
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const endpoint = new Endpoint({
|
|
85
|
+
route: '/users',
|
|
86
|
+
method: 'POST',
|
|
87
|
+
authorize: undefined,
|
|
88
|
+
description: 'Create a new user',
|
|
89
|
+
fn: async (ctx) => ({ id: '1', ...(ctx as any).body }),
|
|
90
|
+
input: {
|
|
91
|
+
body: bodySchema,
|
|
92
|
+
},
|
|
93
|
+
output: undefined,
|
|
94
|
+
status: undefined,
|
|
95
|
+
getSession: undefined,
|
|
96
|
+
services: [],
|
|
97
|
+
logger: {} as any,
|
|
98
|
+
timeout: undefined,
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
const spec = await endpoint.toOpenApi3Route();
|
|
102
|
+
|
|
103
|
+
expect(spec['/users']!.post).toHaveProperty('requestBody');
|
|
104
|
+
expect((spec['/users']!.post! as any).requestBody).toMatchObject({
|
|
105
|
+
required: true,
|
|
106
|
+
content: {
|
|
107
|
+
'application/json': {
|
|
108
|
+
schema: {
|
|
109
|
+
type: 'object',
|
|
110
|
+
properties: {
|
|
111
|
+
name: { type: 'string' },
|
|
112
|
+
email: { type: 'string', format: 'email' },
|
|
113
|
+
},
|
|
114
|
+
required: ['name', 'email'],
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('should include path parameters at route level', async () => {
|
|
122
|
+
const paramsSchema = z.object({
|
|
123
|
+
id: z.string(),
|
|
124
|
+
subId: z.string().optional(),
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
const endpoint = new Endpoint({
|
|
128
|
+
route: '/users/:id/items/:subId',
|
|
129
|
+
method: 'GET',
|
|
130
|
+
status: undefined,
|
|
131
|
+
authorize: undefined,
|
|
132
|
+
getSession: undefined,
|
|
133
|
+
description: 'Get user item',
|
|
134
|
+
fn: async (ctx) => ({
|
|
135
|
+
userId: (ctx as any).params.id,
|
|
136
|
+
itemId: (ctx as any).params.subId,
|
|
137
|
+
}),
|
|
138
|
+
input: {
|
|
139
|
+
params: paramsSchema,
|
|
140
|
+
},
|
|
141
|
+
output: undefined,
|
|
142
|
+
services: [],
|
|
143
|
+
logger: {} as any,
|
|
144
|
+
timeout: undefined,
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
const spec = await endpoint.toOpenApi3Route();
|
|
148
|
+
|
|
149
|
+
const doc = spec['/users/{id}/items/{subId}'];
|
|
150
|
+
|
|
151
|
+
// Path parameters should be at route level, not method level
|
|
152
|
+
expect(doc).toHaveProperty('parameters');
|
|
153
|
+
const parameters = doc.parameters;
|
|
154
|
+
|
|
155
|
+
expect(parameters).toHaveLength(2);
|
|
156
|
+
expect(parameters).toContainEqual({
|
|
157
|
+
name: 'id',
|
|
158
|
+
in: 'path',
|
|
159
|
+
required: true,
|
|
160
|
+
schema: { type: 'string' },
|
|
161
|
+
});
|
|
162
|
+
expect(parameters).toContainEqual({
|
|
163
|
+
name: 'subId',
|
|
164
|
+
in: 'path',
|
|
165
|
+
required: false,
|
|
166
|
+
schema: { type: 'string' },
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
// Method should not have path parameters
|
|
170
|
+
expect(doc.get.parameters).toBeUndefined();
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('should include query parameters', async () => {
|
|
174
|
+
const searchSchema = z.object({
|
|
175
|
+
page: z.number().optional(),
|
|
176
|
+
limit: z.number().optional(),
|
|
177
|
+
sort: z.enum(['asc', 'desc']),
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
const endpoint = new Endpoint({
|
|
181
|
+
route: '/users',
|
|
182
|
+
method: 'GET',
|
|
183
|
+
authorize: undefined,
|
|
184
|
+
description: 'List users with pagination',
|
|
185
|
+
fn: async (ctx) => [],
|
|
186
|
+
input: {
|
|
187
|
+
query: searchSchema,
|
|
188
|
+
},
|
|
189
|
+
output: undefined,
|
|
190
|
+
services: [],
|
|
191
|
+
logger: {} as any,
|
|
192
|
+
timeout: undefined,
|
|
193
|
+
status: undefined,
|
|
194
|
+
getSession: undefined,
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
const spec = await endpoint.toOpenApi3Route();
|
|
198
|
+
|
|
199
|
+
expect(spec['/users']!.get).toHaveProperty('parameters');
|
|
200
|
+
const parameters = (spec['/users']!.get! as any).parameters;
|
|
201
|
+
|
|
202
|
+
expect(parameters).toHaveLength(3);
|
|
203
|
+
expect(parameters).toContainEqual({
|
|
204
|
+
name: 'page',
|
|
205
|
+
in: 'query',
|
|
206
|
+
required: false,
|
|
207
|
+
schema: { type: 'number' },
|
|
208
|
+
});
|
|
209
|
+
expect(parameters).toContainEqual({
|
|
210
|
+
name: 'limit',
|
|
211
|
+
in: 'query',
|
|
212
|
+
required: false,
|
|
213
|
+
schema: { type: 'number' },
|
|
214
|
+
});
|
|
215
|
+
expect(parameters).toContainEqual({
|
|
216
|
+
name: 'sort',
|
|
217
|
+
in: 'query',
|
|
218
|
+
required: true,
|
|
219
|
+
schema: { type: 'string', enum: ['asc', 'desc'] },
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('should handle PUT endpoint with body and params', async () => {
|
|
224
|
+
const bodySchema = z.object({
|
|
225
|
+
name: z.string(),
|
|
226
|
+
email: z.string().email(),
|
|
227
|
+
});
|
|
228
|
+
const paramsSchema = z.object({
|
|
229
|
+
id: z.string(),
|
|
230
|
+
});
|
|
231
|
+
const outputSchema = z.object({
|
|
232
|
+
id: z.string(),
|
|
233
|
+
name: z.string(),
|
|
234
|
+
email: z.string(),
|
|
235
|
+
updatedAt: z.string(),
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
const endpoint = new Endpoint({
|
|
239
|
+
route: '/users/:id',
|
|
240
|
+
method: 'PUT',
|
|
241
|
+
description: 'Update user',
|
|
242
|
+
status: undefined,
|
|
243
|
+
getSession: undefined,
|
|
244
|
+
authorize: undefined,
|
|
245
|
+
fn: async (ctx) => ({
|
|
246
|
+
id: (ctx as any).params.id,
|
|
247
|
+
...(ctx as any).body,
|
|
248
|
+
updatedAt: new Date().toISOString(),
|
|
249
|
+
}),
|
|
250
|
+
input: {
|
|
251
|
+
body: bodySchema,
|
|
252
|
+
params: paramsSchema,
|
|
253
|
+
},
|
|
254
|
+
output: outputSchema,
|
|
255
|
+
services: [],
|
|
256
|
+
logger: {} as any,
|
|
257
|
+
timeout: undefined,
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
const spec = await endpoint.toOpenApi3Route();
|
|
261
|
+
const doc = spec['/users/{id}'];
|
|
262
|
+
|
|
263
|
+
// Check request body
|
|
264
|
+
expect(doc.put).toHaveProperty('requestBody');
|
|
265
|
+
expect(
|
|
266
|
+
(doc.put as any).requestBody.content['application/json'].schema,
|
|
267
|
+
).toMatchObject({
|
|
268
|
+
type: 'object',
|
|
269
|
+
properties: {
|
|
270
|
+
name: { type: 'string' },
|
|
271
|
+
email: { type: 'string', format: 'email' },
|
|
272
|
+
},
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
// Check path parameters at route level
|
|
276
|
+
expect(doc).toHaveProperty('parameters');
|
|
277
|
+
expect(doc.parameters).toHaveLength(1);
|
|
278
|
+
expect(doc.parameters?.[0]).toEqual({
|
|
279
|
+
name: 'id',
|
|
280
|
+
in: 'path',
|
|
281
|
+
required: true,
|
|
282
|
+
schema: { type: 'string' },
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
// Method should not have path parameters
|
|
286
|
+
expect((doc.put as any).parameters).toBeUndefined();
|
|
287
|
+
|
|
288
|
+
// Check response
|
|
289
|
+
expect(
|
|
290
|
+
(doc.put.responses?.['200'] as any).content['application/json'].schema,
|
|
291
|
+
).toMatchObject({
|
|
292
|
+
type: 'object',
|
|
293
|
+
properties: {
|
|
294
|
+
id: { type: 'string' },
|
|
295
|
+
name: { type: 'string' },
|
|
296
|
+
email: { type: 'string' },
|
|
297
|
+
updatedAt: { type: 'string' },
|
|
298
|
+
},
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
it('should handle endpoint without any schemas', async () => {
|
|
303
|
+
const endpoint = new Endpoint({
|
|
304
|
+
route: '/health',
|
|
305
|
+
method: 'GET',
|
|
306
|
+
authorize: undefined,
|
|
307
|
+
fn: async () => ({ status: 'ok' }),
|
|
308
|
+
status: undefined,
|
|
309
|
+
getSession: undefined,
|
|
310
|
+
input: undefined,
|
|
311
|
+
output: undefined,
|
|
312
|
+
services: [],
|
|
313
|
+
logger: {} as any,
|
|
314
|
+
timeout: undefined,
|
|
315
|
+
description: undefined,
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
const spec = await endpoint.toOpenApi3Route();
|
|
319
|
+
|
|
320
|
+
expect(spec).toEqual({
|
|
321
|
+
'/health': {
|
|
322
|
+
get: {
|
|
323
|
+
responses: {
|
|
324
|
+
'200': {
|
|
325
|
+
description: 'Successful response',
|
|
326
|
+
},
|
|
327
|
+
},
|
|
328
|
+
},
|
|
329
|
+
},
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
it('should not include body for GET endpoint even if provided', async () => {
|
|
334
|
+
const bodySchema = z.object({ invalid: z.string() });
|
|
335
|
+
|
|
336
|
+
const endpoint = new Endpoint({
|
|
337
|
+
route: '/users',
|
|
338
|
+
method: 'GET',
|
|
339
|
+
status: undefined,
|
|
340
|
+
getSession: undefined,
|
|
341
|
+
authorize: undefined,
|
|
342
|
+
output: z.object({
|
|
343
|
+
users: z.array(z.object({ id: z.string(), name: z.string() })),
|
|
344
|
+
}),
|
|
345
|
+
fn: async ({}) => ({
|
|
346
|
+
users: [],
|
|
347
|
+
}),
|
|
348
|
+
input: {
|
|
349
|
+
body: bodySchema,
|
|
350
|
+
},
|
|
351
|
+
services: [],
|
|
352
|
+
logger: {} as any,
|
|
353
|
+
timeout: undefined,
|
|
354
|
+
description: undefined,
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
const spec = await endpoint.toOpenApi3Route();
|
|
358
|
+
|
|
359
|
+
expect(spec['/users']!.get).not.toHaveProperty('requestBody');
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
it('should correctly separate path and query parameters', async () => {
|
|
363
|
+
const paramsSchema = z.object({
|
|
364
|
+
userId: z.string(),
|
|
365
|
+
itemId: z.string(),
|
|
366
|
+
});
|
|
367
|
+
const querySchema = z.object({
|
|
368
|
+
limit: z.number().optional(),
|
|
369
|
+
offset: z.number().optional(),
|
|
370
|
+
filter: z.string(),
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
const endpoint = new Endpoint({
|
|
374
|
+
route: '/users/:userId/items/:itemId',
|
|
375
|
+
method: 'GET',
|
|
376
|
+
description: 'Get user item with pagination',
|
|
377
|
+
fn: async () => ({}),
|
|
378
|
+
input: {
|
|
379
|
+
params: paramsSchema,
|
|
380
|
+
query: querySchema,
|
|
381
|
+
},
|
|
382
|
+
output: undefined,
|
|
383
|
+
services: [],
|
|
384
|
+
logger: {} as any,
|
|
385
|
+
timeout: undefined,
|
|
386
|
+
status: undefined,
|
|
387
|
+
getSession: undefined,
|
|
388
|
+
authorize: undefined,
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
const spec = await endpoint.toOpenApi3Route();
|
|
392
|
+
const doc = spec['/users/{userId}/items/{itemId}'];
|
|
393
|
+
|
|
394
|
+
// Path parameters should be at route level
|
|
395
|
+
expect(doc.parameters).toBeDefined();
|
|
396
|
+
expect(doc.parameters).toHaveLength(2);
|
|
397
|
+
expect(doc.parameters).toContainEqual({
|
|
398
|
+
name: 'userId',
|
|
399
|
+
in: 'path',
|
|
400
|
+
required: true,
|
|
401
|
+
schema: { type: 'string' },
|
|
402
|
+
});
|
|
403
|
+
expect(doc.parameters).toContainEqual({
|
|
404
|
+
name: 'itemId',
|
|
405
|
+
in: 'path',
|
|
406
|
+
required: true,
|
|
407
|
+
schema: { type: 'string' },
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
// Query parameters should be at method level
|
|
411
|
+
expect(doc.get.parameters).toBeDefined();
|
|
412
|
+
expect(doc.get.parameters).toHaveLength(3);
|
|
413
|
+
expect(doc.get.parameters).toContainEqual({
|
|
414
|
+
name: 'limit',
|
|
415
|
+
in: 'query',
|
|
416
|
+
required: false,
|
|
417
|
+
schema: { type: 'number' },
|
|
418
|
+
});
|
|
419
|
+
expect(doc.get.parameters).toContainEqual({
|
|
420
|
+
name: 'offset',
|
|
421
|
+
in: 'query',
|
|
422
|
+
required: false,
|
|
423
|
+
schema: { type: 'number' },
|
|
424
|
+
});
|
|
425
|
+
expect(doc.get.parameters).toContainEqual({
|
|
426
|
+
name: 'filter',
|
|
427
|
+
in: 'query',
|
|
428
|
+
required: true,
|
|
429
|
+
schema: { type: 'string' },
|
|
430
|
+
});
|
|
431
|
+
});
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
describe('authorize property', () => {
|
|
435
|
+
const mockLogger: Logger = {
|
|
436
|
+
debug: vi.fn(),
|
|
437
|
+
info: vi.fn(),
|
|
438
|
+
warn: vi.fn(),
|
|
439
|
+
error: vi.fn(),
|
|
440
|
+
fatal: vi.fn(),
|
|
441
|
+
trace: vi.fn(),
|
|
442
|
+
child: vi.fn(() => mockLogger),
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
const services = ServiceDiscovery.getInstance(
|
|
446
|
+
mockLogger,
|
|
447
|
+
new EnvironmentParser({}),
|
|
448
|
+
);
|
|
449
|
+
|
|
450
|
+
it('should have default authorize function that returns true', async () => {
|
|
451
|
+
const endpoint = new Endpoint({
|
|
452
|
+
route: '/test',
|
|
453
|
+
method: 'GET',
|
|
454
|
+
fn: async () => ({ success: true }),
|
|
455
|
+
input: undefined,
|
|
456
|
+
output: undefined,
|
|
457
|
+
services: [],
|
|
458
|
+
authorize: undefined,
|
|
459
|
+
logger: mockLogger,
|
|
460
|
+
timeout: undefined,
|
|
461
|
+
status: undefined,
|
|
462
|
+
getSession: undefined,
|
|
463
|
+
description: undefined,
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
const result = await endpoint.authorize({
|
|
467
|
+
header: vi.fn(),
|
|
468
|
+
services,
|
|
469
|
+
logger: mockLogger,
|
|
470
|
+
session: {},
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
expect(result).toBe(true);
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
it('should allow custom authorize function', async () => {
|
|
477
|
+
const endpoint = new Endpoint({
|
|
478
|
+
route: '/test',
|
|
479
|
+
method: 'GET',
|
|
480
|
+
fn: async () => ({ success: true }),
|
|
481
|
+
input: undefined,
|
|
482
|
+
output: undefined,
|
|
483
|
+
services: [],
|
|
484
|
+
logger: mockLogger,
|
|
485
|
+
authorize: undefined,
|
|
486
|
+
timeout: undefined,
|
|
487
|
+
status: undefined,
|
|
488
|
+
getSession: undefined,
|
|
489
|
+
description: undefined,
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
const customAuthFn = vi.fn().mockResolvedValue(false);
|
|
493
|
+
endpoint.authorize = customAuthFn;
|
|
494
|
+
|
|
495
|
+
const mockContext = {
|
|
496
|
+
header: vi.fn(),
|
|
497
|
+
services,
|
|
498
|
+
logger: mockLogger,
|
|
499
|
+
session: {},
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
const result = await endpoint.authorize(mockContext);
|
|
503
|
+
|
|
504
|
+
expect(result).toBe(false);
|
|
505
|
+
expect(customAuthFn).toHaveBeenCalledWith(mockContext);
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
it('should support synchronous authorize function', () => {
|
|
509
|
+
const endpoint = new Endpoint({
|
|
510
|
+
route: '/test',
|
|
511
|
+
method: 'GET',
|
|
512
|
+
fn: async () => ({ success: true }),
|
|
513
|
+
input: undefined,
|
|
514
|
+
output: undefined,
|
|
515
|
+
services: [],
|
|
516
|
+
logger: mockLogger,
|
|
517
|
+
timeout: undefined,
|
|
518
|
+
authorize: undefined,
|
|
519
|
+
status: undefined,
|
|
520
|
+
getSession: undefined,
|
|
521
|
+
description: undefined,
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
const syncAuthFn = vi.fn().mockReturnValue(true);
|
|
525
|
+
endpoint.authorize = syncAuthFn;
|
|
526
|
+
|
|
527
|
+
const mockContext = {
|
|
528
|
+
header: vi.fn(),
|
|
529
|
+
services,
|
|
530
|
+
logger: mockLogger,
|
|
531
|
+
session: {},
|
|
532
|
+
};
|
|
533
|
+
|
|
534
|
+
const result = endpoint.authorize(mockContext);
|
|
535
|
+
|
|
536
|
+
expect(result).toBe(true);
|
|
537
|
+
expect(syncAuthFn).toHaveBeenCalledWith(mockContext);
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
it('should receive header function in context', async () => {
|
|
541
|
+
const endpoint = new Endpoint({
|
|
542
|
+
route: '/test',
|
|
543
|
+
method: 'GET',
|
|
544
|
+
fn: async () => ({ success: true }),
|
|
545
|
+
input: undefined,
|
|
546
|
+
output: undefined,
|
|
547
|
+
services: [],
|
|
548
|
+
authorize: undefined,
|
|
549
|
+
logger: mockLogger,
|
|
550
|
+
timeout: undefined,
|
|
551
|
+
status: undefined,
|
|
552
|
+
getSession: undefined,
|
|
553
|
+
description: undefined,
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
const headerFn = vi.fn().mockReturnValue('Bearer token123');
|
|
557
|
+
|
|
558
|
+
endpoint.authorize = ({ header }) => {
|
|
559
|
+
return header('authorization') === 'Bearer token123';
|
|
560
|
+
};
|
|
561
|
+
|
|
562
|
+
const result = await endpoint.authorize({
|
|
563
|
+
header: headerFn,
|
|
564
|
+
services,
|
|
565
|
+
logger: mockLogger,
|
|
566
|
+
session: {},
|
|
567
|
+
});
|
|
568
|
+
|
|
569
|
+
expect(result).toBe(true);
|
|
570
|
+
expect(headerFn).toHaveBeenCalledWith('authorization');
|
|
571
|
+
});
|
|
572
|
+
|
|
573
|
+
it('should receive services in context', async () => {
|
|
574
|
+
const TestService = {
|
|
575
|
+
serviceName: 'TestService' as const,
|
|
576
|
+
register() {
|
|
577
|
+
return {
|
|
578
|
+
validateUser(id: string) {
|
|
579
|
+
return id === 'valid';
|
|
580
|
+
},
|
|
581
|
+
};
|
|
582
|
+
},
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
await services.register([TestService]);
|
|
586
|
+
const endpoint = new Endpoint({
|
|
587
|
+
route: '/test',
|
|
588
|
+
method: 'GET',
|
|
589
|
+
fn: async () => ({ success: true }),
|
|
590
|
+
input: undefined,
|
|
591
|
+
output: undefined,
|
|
592
|
+
services: [TestService],
|
|
593
|
+
logger: mockLogger,
|
|
594
|
+
timeout: undefined,
|
|
595
|
+
status: undefined,
|
|
596
|
+
authorize: async ({ services }) => {
|
|
597
|
+
return services.TestService.validateUser('valid');
|
|
598
|
+
},
|
|
599
|
+
getSession: undefined,
|
|
600
|
+
description: undefined,
|
|
601
|
+
});
|
|
602
|
+
|
|
603
|
+
const result = await endpoint.authorize({
|
|
604
|
+
header: vi.fn(),
|
|
605
|
+
services: { TestService: TestService.register() },
|
|
606
|
+
logger: mockLogger,
|
|
607
|
+
session: {},
|
|
608
|
+
});
|
|
609
|
+
|
|
610
|
+
expect(result).toBe(true);
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
it('should receive logger in context', async () => {
|
|
614
|
+
const endpoint = new Endpoint({
|
|
615
|
+
route: '/test',
|
|
616
|
+
method: 'GET',
|
|
617
|
+
fn: async () => ({ success: true }),
|
|
618
|
+
input: undefined,
|
|
619
|
+
output: undefined,
|
|
620
|
+
authorize: undefined,
|
|
621
|
+
services: [],
|
|
622
|
+
logger: mockLogger,
|
|
623
|
+
timeout: undefined,
|
|
624
|
+
status: undefined,
|
|
625
|
+
getSession: undefined,
|
|
626
|
+
description: undefined,
|
|
627
|
+
});
|
|
628
|
+
|
|
629
|
+
const loggerSpy = vi.fn();
|
|
630
|
+
const testLogger = {
|
|
631
|
+
...mockLogger,
|
|
632
|
+
info: loggerSpy,
|
|
633
|
+
};
|
|
634
|
+
|
|
635
|
+
endpoint.authorize = ({ logger }) => {
|
|
636
|
+
logger.info('Authorization check');
|
|
637
|
+
return true;
|
|
638
|
+
};
|
|
639
|
+
|
|
640
|
+
const result = await endpoint.authorize({
|
|
641
|
+
header: vi.fn(),
|
|
642
|
+
services,
|
|
643
|
+
logger: testLogger,
|
|
644
|
+
session: {},
|
|
645
|
+
});
|
|
646
|
+
|
|
647
|
+
expect(result).toBe(true);
|
|
648
|
+
expect(loggerSpy).toHaveBeenCalledWith('Authorization check');
|
|
649
|
+
});
|
|
650
|
+
|
|
651
|
+
it('should receive session in context', async () => {
|
|
652
|
+
const endpoint = new Endpoint({
|
|
653
|
+
route: '/test',
|
|
654
|
+
method: 'GET',
|
|
655
|
+
fn: async () => ({ success: true }),
|
|
656
|
+
input: undefined,
|
|
657
|
+
output: undefined,
|
|
658
|
+
authorize: undefined,
|
|
659
|
+
services: [],
|
|
660
|
+
logger: mockLogger,
|
|
661
|
+
timeout: undefined,
|
|
662
|
+
status: undefined,
|
|
663
|
+
getSession: () => ({ role: 'admin' }),
|
|
664
|
+
description: undefined,
|
|
665
|
+
});
|
|
666
|
+
|
|
667
|
+
const mockSession = { userId: 'user123', role: 'admin' };
|
|
668
|
+
|
|
669
|
+
endpoint.authorize = ({ session }) => {
|
|
670
|
+
return session.role === 'admin';
|
|
671
|
+
};
|
|
672
|
+
|
|
673
|
+
const result = await endpoint.authorize({
|
|
674
|
+
header: vi.fn(),
|
|
675
|
+
services,
|
|
676
|
+
logger: mockLogger,
|
|
677
|
+
session: mockSession,
|
|
678
|
+
});
|
|
679
|
+
|
|
680
|
+
expect(result).toBe(true);
|
|
681
|
+
});
|
|
682
|
+
|
|
683
|
+
it('should handle authorize function that throws error', async () => {
|
|
684
|
+
const endpoint = new Endpoint({
|
|
685
|
+
route: '/test',
|
|
686
|
+
method: 'GET',
|
|
687
|
+
fn: async () => ({ success: true }),
|
|
688
|
+
input: undefined,
|
|
689
|
+
output: undefined,
|
|
690
|
+
services: [],
|
|
691
|
+
authorize: async () => {
|
|
692
|
+
throw new Error('Authorization failed');
|
|
693
|
+
},
|
|
694
|
+
|
|
695
|
+
logger: mockLogger,
|
|
696
|
+
timeout: undefined,
|
|
697
|
+
status: undefined,
|
|
698
|
+
getSession: undefined,
|
|
699
|
+
description: undefined,
|
|
700
|
+
});
|
|
701
|
+
|
|
702
|
+
await expect(() =>
|
|
703
|
+
endpoint.authorize({
|
|
704
|
+
header: vi.fn(),
|
|
705
|
+
services,
|
|
706
|
+
logger: mockLogger,
|
|
707
|
+
session: {},
|
|
708
|
+
}),
|
|
709
|
+
).rejects.toThrow('Authorization failed');
|
|
710
|
+
});
|
|
711
|
+
|
|
712
|
+
it('should handle async authorize function that throws error', async () => {
|
|
713
|
+
const endpoint = new Endpoint({
|
|
714
|
+
route: '/test',
|
|
715
|
+
method: 'GET',
|
|
716
|
+
fn: async () => ({ success: true }),
|
|
717
|
+
input: undefined,
|
|
718
|
+
output: undefined,
|
|
719
|
+
services: [],
|
|
720
|
+
logger: mockLogger,
|
|
721
|
+
timeout: undefined,
|
|
722
|
+
authorize: undefined,
|
|
723
|
+
status: undefined,
|
|
724
|
+
getSession: undefined,
|
|
725
|
+
description: undefined,
|
|
726
|
+
});
|
|
727
|
+
|
|
728
|
+
endpoint.authorize = async () => {
|
|
729
|
+
throw new Error('Async authorization failed');
|
|
730
|
+
};
|
|
731
|
+
|
|
732
|
+
await expect(
|
|
733
|
+
endpoint.authorize({
|
|
734
|
+
header: vi.fn(),
|
|
735
|
+
services,
|
|
736
|
+
logger: mockLogger,
|
|
737
|
+
session: {},
|
|
738
|
+
}),
|
|
739
|
+
).rejects.toThrow('Async authorization failed');
|
|
740
|
+
});
|
|
741
|
+
|
|
742
|
+
it('should work with complex authorization logic', async () => {
|
|
743
|
+
const endpoint = new Endpoint({
|
|
744
|
+
route: '/admin/users',
|
|
745
|
+
method: 'GET',
|
|
746
|
+
authorize: undefined,
|
|
747
|
+
fn: async () => ({ users: [] }),
|
|
748
|
+
input: undefined,
|
|
749
|
+
output: undefined,
|
|
750
|
+
services: [],
|
|
751
|
+
logger: mockLogger,
|
|
752
|
+
timeout: undefined,
|
|
753
|
+
status: undefined,
|
|
754
|
+
getSession: undefined,
|
|
755
|
+
description: undefined,
|
|
756
|
+
});
|
|
757
|
+
|
|
758
|
+
endpoint.authorize = async ({ header, session }) => {
|
|
759
|
+
// Simulate complex authorization logic
|
|
760
|
+
const token = header('authorization');
|
|
761
|
+
if (!token) return false;
|
|
762
|
+
|
|
763
|
+
const user = session as any;
|
|
764
|
+
if (!user?.role) return false;
|
|
765
|
+
|
|
766
|
+
return user.role === 'admin' || user.role === 'superuser';
|
|
767
|
+
};
|
|
768
|
+
|
|
769
|
+
// Test with admin role
|
|
770
|
+
const adminResult = await endpoint.authorize({
|
|
771
|
+
header: vi.fn().mockReturnValue('Bearer admin-token'),
|
|
772
|
+
services,
|
|
773
|
+
logger: mockLogger,
|
|
774
|
+
session: { userId: 'admin1', role: 'admin' },
|
|
775
|
+
});
|
|
776
|
+
|
|
777
|
+
expect(adminResult).toBe(true);
|
|
778
|
+
|
|
779
|
+
// Test with user role
|
|
780
|
+
const userResult = await endpoint.authorize({
|
|
781
|
+
header: vi.fn().mockReturnValue('Bearer user-token'),
|
|
782
|
+
services,
|
|
783
|
+
logger: mockLogger,
|
|
784
|
+
session: { userId: 'user1', role: 'user' },
|
|
785
|
+
});
|
|
786
|
+
|
|
787
|
+
expect(userResult).toBe(false);
|
|
788
|
+
|
|
789
|
+
// Test with no token
|
|
790
|
+
const noTokenResult = await endpoint.authorize({
|
|
791
|
+
header: vi.fn().mockReturnValue(undefined),
|
|
792
|
+
services,
|
|
793
|
+
logger: mockLogger,
|
|
794
|
+
session: { userId: 'user1', role: 'admin' },
|
|
795
|
+
});
|
|
796
|
+
|
|
797
|
+
expect(noTokenResult).toBe(false);
|
|
798
|
+
});
|
|
799
|
+
});
|
|
800
|
+
});
|