@geekmidas/constructs 9.0.2 → 10.0.0-alpha.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 +71 -44
- package/dist/{AWSScheduledFunction-Bn99MceY.d.cts → AWSScheduledFunction-9bJS4WdJ.d.cts} +8 -3
- package/dist/{AWSScheduledFunction-ysaCsdWx.d.mts.map → AWSScheduledFunction-9bJS4WdJ.d.cts.map} +1 -1
- package/dist/{AWSScheduledFunction-CufMMhGB.mjs → AWSScheduledFunction-BJjj8B5V.mjs} +3 -3
- package/dist/{AWSScheduledFunction-CufMMhGB.mjs.map → AWSScheduledFunction-BJjj8B5V.mjs.map} +1 -1
- package/dist/{AWSScheduledFunction-ysaCsdWx.d.mts → AWSScheduledFunction-BO5iEMSh.d.mts} +9 -4
- package/dist/{AWSScheduledFunction-Bn99MceY.d.cts.map → AWSScheduledFunction-BO5iEMSh.d.mts.map} +1 -1
- package/dist/{AWSScheduledFunction-DbkDr8CA.cjs → AWSScheduledFunction-qu4ieRZR.cjs} +9 -9
- package/dist/{AWSScheduledFunction-DbkDr8CA.cjs.map → AWSScheduledFunction-qu4ieRZR.cjs.map} +1 -1
- package/dist/{Construct-_1wX7p_Y.d.cts → Construct-B-xc0SE9.d.mts} +27 -5
- package/dist/Construct-B-xc0SE9.d.mts.map +1 -0
- package/dist/{Construct-r0U2zBwW.mjs → Construct-CdhThxDI.mjs} +3 -2
- package/dist/Construct-CdhThxDI.mjs.map +1 -0
- package/dist/{Construct-DCMuYOox.d.mts → Construct-WhCXIOPV.d.cts} +29 -7
- package/dist/Construct-WhCXIOPV.d.cts.map +1 -0
- package/dist/{Construct-vXMZJgRp.cjs → Construct-roId57cU.cjs} +7 -43
- package/dist/Construct-roId57cU.cjs.map +1 -0
- package/dist/{lazyAccessors-DmTG8sQH.cjs → Endpoint-BBkV6l0k.cjs} +869 -1079
- package/dist/Endpoint-BBkV6l0k.cjs.map +1 -0
- package/dist/{Endpoint-DgfRslct.d.cts → Endpoint-BKR5QH6O.d.mts} +57 -8
- package/dist/Endpoint-BKR5QH6O.d.mts.map +1 -0
- package/dist/{Endpoint-CLPSIl6S.d.mts → Endpoint-BQ9O0P1w.d.cts} +58 -9
- package/dist/Endpoint-BQ9O0P1w.d.cts.map +1 -0
- package/dist/{lazyAccessors-DfqZR6C4.mjs → Endpoint-BTj58Gob.mjs} +840 -1003
- package/dist/Endpoint-BTj58Gob.mjs.map +1 -0
- package/dist/EndpointFactory-BejSTzbB.mjs +808 -0
- package/dist/EndpointFactory-BejSTzbB.mjs.map +1 -0
- package/dist/EndpointFactory-DYoGLaIT.cjs +850 -0
- package/dist/EndpointFactory-DYoGLaIT.cjs.map +1 -0
- package/dist/{HonoEndpointAdaptor-DJDT3PMx.mjs → HonoEndpointAdaptor-7aYNdqJq.mjs} +5 -4
- package/dist/HonoEndpointAdaptor-7aYNdqJq.mjs.map +1 -0
- package/dist/{HonoEndpointAdaptor-CkJENANP.cjs → HonoEndpointAdaptor-wMsCyMgt.cjs} +24 -23
- package/dist/HonoEndpointAdaptor-wMsCyMgt.cjs.map +1 -0
- package/dist/{Queue-DaxjwmOQ.d.cts → Queue-D6WeziRD.d.cts} +43 -4
- package/dist/Queue-D6WeziRD.d.cts.map +1 -0
- package/dist/{Queue-HBDf0fqz.d.mts → Queue-DpUeqdC8.d.mts} +43 -4
- package/dist/Queue-DpUeqdC8.d.mts.map +1 -0
- package/dist/{Subscriber-B69ngPwl.d.cts → Subscriber-4rBJgDKI.d.mts} +9 -4
- package/dist/{Subscriber-B69ngPwl.d.cts.map → Subscriber-4rBJgDKI.d.mts.map} +1 -1
- package/dist/{Subscriber-D8Xm-86W.d.mts → Subscriber-DVQowdyj.d.cts} +11 -6
- package/dist/Subscriber-DVQowdyj.d.cts.map +1 -0
- package/dist/{Topic-C5ZMfveW.d.cts → Topic-Ohx9dvWr.d.cts} +33 -2
- package/dist/Topic-Ohx9dvWr.d.cts.map +1 -0
- package/dist/{Topic-DT10AqHk.d.mts → Topic-cmy2jOUy.d.mts} +33 -2
- package/dist/Topic-cmy2jOUy.d.mts.map +1 -0
- package/dist/adaptors/aws.cjs +39 -26
- package/dist/adaptors/aws.cjs.map +1 -1
- package/dist/adaptors/aws.d.cts +24 -16
- package/dist/adaptors/aws.d.cts.map +1 -1
- package/dist/adaptors/aws.d.mts +25 -17
- package/dist/adaptors/aws.d.mts.map +1 -1
- package/dist/adaptors/aws.mjs +26 -14
- package/dist/adaptors/aws.mjs.map +1 -1
- package/dist/adaptors/hono.cjs +9 -6
- package/dist/adaptors/hono.d.cts +7 -6
- package/dist/adaptors/hono.d.cts.map +1 -1
- package/dist/adaptors/hono.d.mts +8 -7
- package/dist/adaptors/hono.d.mts.map +1 -1
- package/dist/adaptors/hono.mjs +9 -6
- package/dist/adaptors/testing.cjs +18 -14
- package/dist/adaptors/testing.cjs.map +1 -1
- package/dist/adaptors/testing.d.cts +7 -6
- package/dist/adaptors/testing.d.cts.map +1 -1
- package/dist/adaptors/testing.d.mts +11 -10
- package/dist/adaptors/testing.d.mts.map +1 -1
- package/dist/adaptors/testing.mjs +10 -7
- package/dist/adaptors/testing.mjs.map +1 -1
- package/dist/auth.cjs +165 -0
- package/dist/auth.cjs.map +1 -0
- package/dist/auth.d.cts +108 -0
- package/dist/auth.d.cts.map +1 -0
- package/dist/auth.d.mts +108 -0
- package/dist/auth.d.mts.map +1 -0
- package/dist/auth.mjs +164 -0
- package/dist/auth.mjs.map +1 -0
- package/dist/cache-0ANvRQnD.mjs +51 -0
- package/dist/cache-0ANvRQnD.mjs.map +1 -0
- package/dist/cache-3WSvAulx.cjs +57 -0
- package/dist/cache-3WSvAulx.cjs.map +1 -0
- package/dist/cache-CdQ7OLpR.d.cts +47 -0
- package/dist/cache-CdQ7OLpR.d.cts.map +1 -0
- package/dist/cache-DYoJFcfd.d.mts +47 -0
- package/dist/cache-DYoJFcfd.d.mts.map +1 -0
- package/dist/cache.cjs +3 -0
- package/dist/cache.d.cts +3 -0
- package/dist/cache.d.mts +3 -0
- package/dist/cache.mjs +3 -0
- package/dist/chunk-DWy1uDak.cjs +39 -0
- package/dist/clone-DblgEZZa.mjs +39 -0
- package/dist/clone-DblgEZZa.mjs.map +1 -0
- package/dist/clone-Dy0cR2SZ.cjs +45 -0
- package/dist/clone-Dy0cR2SZ.cjs.map +1 -0
- package/dist/construct-interface-BfjcOD_E.cjs +117 -0
- package/dist/construct-interface-BfjcOD_E.cjs.map +1 -0
- package/dist/construct-interface-BqwRNYA2.d.mts +131 -0
- package/dist/construct-interface-BqwRNYA2.d.mts.map +1 -0
- package/dist/construct-interface-D2nNkHUN.d.cts +131 -0
- package/dist/construct-interface-D2nNkHUN.d.cts.map +1 -0
- package/dist/construct-interface-Z4CpS8tK.mjs +81 -0
- package/dist/construct-interface-Z4CpS8tK.mjs.map +1 -0
- package/dist/construct-interface.cjs +8 -0
- package/dist/construct-interface.d.cts +2 -0
- package/dist/construct-interface.d.mts +2 -0
- package/dist/construct-interface.mjs +3 -0
- package/dist/credential.cjs +96 -0
- package/dist/credential.cjs.map +1 -0
- package/dist/credential.d.cts +61 -0
- package/dist/credential.d.cts.map +1 -0
- package/dist/credential.d.mts +61 -0
- package/dist/credential.d.mts.map +1 -0
- package/dist/credential.mjs +94 -0
- package/dist/credential.mjs.map +1 -0
- package/dist/crons/index.cjs +39 -37
- package/dist/crons/index.cjs.map +1 -1
- package/dist/crons/index.d.cts +21 -8
- package/dist/crons/index.d.cts.map +1 -1
- package/dist/crons/index.d.mts +29 -13
- package/dist/crons/index.d.mts.map +1 -1
- package/dist/crons/index.mjs +37 -36
- package/dist/crons/index.mjs.map +1 -1
- package/dist/database/kysely.cjs +181 -0
- package/dist/database/kysely.cjs.map +1 -0
- package/dist/database/kysely.d.cts +152 -0
- package/dist/database/kysely.d.cts.map +1 -0
- package/dist/database/kysely.d.mts +152 -0
- package/dist/database/kysely.d.mts.map +1 -0
- package/dist/database/kysely.mjs +180 -0
- package/dist/database/kysely.mjs.map +1 -0
- package/dist/email.cjs +59 -0
- package/dist/email.cjs.map +1 -0
- package/dist/email.d.cts +50 -0
- package/dist/email.d.cts.map +1 -0
- package/dist/email.d.mts +50 -0
- package/dist/email.d.mts.map +1 -0
- package/dist/email.mjs +58 -0
- package/dist/email.mjs.map +1 -0
- package/dist/endpoints/index.cjs +21 -747
- package/dist/endpoints/index.d.cts +7 -343
- package/dist/endpoints/index.d.mts +7 -342
- package/dist/endpoints/index.mjs +11 -738
- package/dist/file-server.cjs +154 -0
- package/dist/file-server.cjs.map +1 -0
- package/dist/file-server.d.cts +156 -0
- package/dist/file-server.d.cts.map +1 -0
- package/dist/file-server.d.mts +156 -0
- package/dist/file-server.d.mts.map +1 -0
- package/dist/file-server.mjs +152 -0
- package/dist/file-server.mjs.map +1 -0
- package/dist/functions/index.cjs +4 -2
- package/dist/functions/index.d.cts +3 -2
- package/dist/functions/index.d.mts +3 -2
- package/dist/functions/index.mjs +4 -2
- package/dist/{functions-B-qt91O7.mjs → functions-Cpff1uZH.mjs} +55 -51
- package/dist/functions-Cpff1uZH.mjs.map +1 -0
- package/dist/{functions-C8i1kCMM.cjs → functions-DukjG8ov.cjs} +62 -57
- package/dist/functions-DukjG8ov.cjs.map +1 -0
- package/dist/{index-BVs9DvIj.d.cts → index-BTvozlUD.d.cts} +36 -9
- package/dist/index-BTvozlUD.d.cts.map +1 -0
- package/dist/index-Cvz551AO.d.mts +419 -0
- package/dist/index-Cvz551AO.d.mts.map +1 -0
- package/dist/index-D5zqAJ2e.d.cts +419 -0
- package/dist/index-D5zqAJ2e.d.cts.map +1 -0
- package/dist/{index-DP6fqv0I.d.mts → index-L7pz0R0T.d.mts} +48 -19
- package/dist/index-L7pz0R0T.d.mts.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +1 -1
- package/dist/lazyAccessors-DM6HcXQk.mjs +175 -0
- package/dist/lazyAccessors-DM6HcXQk.mjs.map +1 -0
- package/dist/lazyAccessors-DrJj8NpA.cjs +223 -0
- package/dist/lazyAccessors-DrJj8NpA.cjs.map +1 -0
- package/dist/object-storage.cjs +48 -0
- package/dist/object-storage.cjs.map +1 -0
- package/dist/object-storage.d.cts +36 -0
- package/dist/object-storage.d.cts.map +1 -0
- package/dist/object-storage.d.mts +36 -0
- package/dist/object-storage.d.mts.map +1 -0
- package/dist/object-storage.mjs +47 -0
- package/dist/object-storage.mjs.map +1 -0
- package/dist/{processAudits-CKjjivyz.cjs → processAudits-Bc8rz6Ev.cjs} +3 -3
- package/dist/{processAudits-CKjjivyz.cjs.map → processAudits-Bc8rz6Ev.cjs.map} +1 -1
- package/dist/{processAudits-ySnizdMG.mjs → processAudits-D89tICM4.mjs} +1 -1
- package/dist/{processAudits-ySnizdMG.mjs.map → processAudits-D89tICM4.mjs.map} +1 -1
- package/dist/{publisher-BrFOF847.mjs → publisher-CGEo8UKD.mjs} +1 -1
- package/dist/{publisher-BrFOF847.mjs.map → publisher-CGEo8UKD.mjs.map} +1 -1
- package/dist/{publisher-lFQleddL.cjs → publisher-CqGsXB2X.cjs} +1 -1
- package/dist/{publisher-lFQleddL.cjs.map → publisher-CqGsXB2X.cjs.map} +1 -1
- package/dist/queue/index.cjs +92 -30
- package/dist/queue/index.cjs.map +1 -1
- package/dist/queue/index.d.cts +19 -4
- package/dist/queue/index.d.cts.map +1 -1
- package/dist/queue/index.d.mts +22 -6
- package/dist/queue/index.d.mts.map +1 -1
- package/dist/queue/index.mjs +90 -29
- package/dist/queue/index.mjs.map +1 -1
- package/dist/rest-api.cjs +187 -0
- package/dist/rest-api.cjs.map +1 -0
- package/dist/rest-api.d.cts +221 -0
- package/dist/rest-api.d.cts.map +1 -0
- package/dist/rest-api.d.mts +221 -0
- package/dist/rest-api.d.mts.map +1 -0
- package/dist/rest-api.mjs +186 -0
- package/dist/rest-api.mjs.map +1 -0
- package/dist/site.cjs +48 -0
- package/dist/site.cjs.map +1 -0
- package/dist/site.d.cts +101 -0
- package/dist/site.d.cts.map +1 -0
- package/dist/site.d.mts +101 -0
- package/dist/site.d.mts.map +1 -0
- package/dist/site.mjs +47 -0
- package/dist/site.mjs.map +1 -0
- package/dist/subscribers/index.cjs +35 -27
- package/dist/subscribers/index.cjs.map +1 -1
- package/dist/subscribers/index.d.cts +20 -5
- package/dist/subscribers/index.d.cts.map +1 -1
- package/dist/subscribers/index.d.mts +23 -7
- package/dist/subscribers/index.d.mts.map +1 -1
- package/dist/subscribers/index.mjs +34 -27
- package/dist/subscribers/index.mjs.map +1 -1
- package/dist/surfaceEnv-BFXEms2f.cjs +39 -0
- package/dist/surfaceEnv-BFXEms2f.cjs.map +1 -0
- package/dist/surfaceEnv-C3Ktahea.mjs +27 -0
- package/dist/surfaceEnv-C3Ktahea.mjs.map +1 -0
- package/dist/{telemetry-3vdxGn4q.d.mts → telemetry-C3L0iS28.d.cts} +2 -2
- package/dist/{telemetry-3vdxGn4q.d.mts.map → telemetry-C3L0iS28.d.cts.map} +1 -1
- package/dist/{telemetry-Dqx-D3F7.d.cts → telemetry-D7bVFLGi.d.mts} +2 -2
- package/dist/{telemetry-Dqx-D3F7.d.cts.map → telemetry-D7bVFLGi.d.mts.map} +1 -1
- package/dist/topic/index.cjs +56 -13
- package/dist/topic/index.cjs.map +1 -1
- package/dist/topic/index.d.cts +2 -2
- package/dist/topic/index.d.cts.map +1 -1
- package/dist/topic/index.d.mts +2 -2
- package/dist/topic/index.d.mts.map +1 -1
- package/dist/topic/index.mjs +54 -12
- package/dist/topic/index.mjs.map +1 -1
- package/dist/{types-BDNGr7pv.d.mts → types-BlAkSuGI.d.cts} +1 -1
- package/dist/{types-BDNGr7pv.d.mts.map → types-BlAkSuGI.d.cts.map} +1 -1
- package/dist/{types-BdAaYDvd.d.cts → types-aKksMEWL.d.mts} +1 -1
- package/dist/{types-BdAaYDvd.d.cts.map → types-aKksMEWL.d.mts.map} +1 -1
- package/dist/types.d.cts +1 -1
- package/dist/types.d.mts +1 -1
- package/package.json +155 -23
- package/CHANGELOG.md +0 -396
- package/dist/Construct-DCMuYOox.d.mts.map +0 -1
- package/dist/Construct-_1wX7p_Y.d.cts.map +0 -1
- package/dist/Construct-r0U2zBwW.mjs.map +0 -1
- package/dist/Construct-vXMZJgRp.cjs.map +0 -1
- package/dist/Endpoint-CLPSIl6S.d.mts.map +0 -1
- package/dist/Endpoint-DgfRslct.d.cts.map +0 -1
- package/dist/HonoEndpointAdaptor-CkJENANP.cjs.map +0 -1
- package/dist/HonoEndpointAdaptor-DJDT3PMx.mjs.map +0 -1
- package/dist/Queue-DaxjwmOQ.d.cts.map +0 -1
- package/dist/Queue-HBDf0fqz.d.mts.map +0 -1
- package/dist/Subscriber-D8Xm-86W.d.mts.map +0 -1
- package/dist/Topic-C5ZMfveW.d.cts.map +0 -1
- package/dist/Topic-DT10AqHk.d.mts.map +0 -1
- package/dist/endpoints/index.cjs.map +0 -1
- package/dist/endpoints/index.d.cts.map +0 -1
- package/dist/endpoints/index.d.mts.map +0 -1
- package/dist/endpoints/index.mjs.map +0 -1
- package/dist/functions-B-qt91O7.mjs.map +0 -1
- package/dist/functions-C8i1kCMM.cjs.map +0 -1
- package/dist/index-BVs9DvIj.d.cts.map +0 -1
- package/dist/index-DP6fqv0I.d.mts.map +0 -1
- package/dist/lazyAccessors-DfqZR6C4.mjs.map +0 -1
- package/dist/lazyAccessors-DmTG8sQH.cjs.map +0 -1
- package/src/Construct.ts +0 -204
- package/src/__benchmarks__/build-time-optimization.bench.ts +0 -274
- package/src/__benchmarks__/endpoint.bench.ts +0 -494
- package/src/__benchmarks__/fixtures.ts +0 -241
- package/src/__benchmarks__/hono-adaptor.bench.ts +0 -533
- package/src/__benchmarks__/hono-server.bench.ts +0 -249
- package/src/__benchmarks__/response-builder.bench.ts +0 -428
- package/src/__benchmarks__/strategies/strategy-a-lazy-services.ts +0 -319
- package/src/__benchmarks__/strategies/strategy-c-middleware.ts +0 -530
- package/src/__benchmarks__/strategies/strategy-d-opt-in-events.ts +0 -567
- package/src/__tests__/Construct.environment.spec.ts +0 -704
- package/src/__tests__/publisher.setting.spec.ts +0 -508
- package/src/__tests__/publisher.spec.ts +0 -452
- package/src/adaptors/aws.ts +0 -6
- package/src/adaptors/hono.ts +0 -1
- package/src/adaptors/testing.ts +0 -11
- package/src/crons/AWSScheduledFunction.ts +0 -73
- package/src/crons/Cron.ts +0 -149
- package/src/crons/CronBuilder.ts +0 -271
- package/src/crons/__tests__/AWSScheduledFunction.spec.ts +0 -152
- package/src/crons/__tests__/Cron.spec.ts +0 -464
- package/src/crons/__tests__/CronBuilder.state-isolation.spec.ts +0 -227
- package/src/crons/index.ts +0 -12
- package/src/endpoints/AmazonApiGatewayEndpointAdaptor.ts +0 -677
- package/src/endpoints/AmazonApiGatewayV1EndpointAdaptor.ts +0 -105
- package/src/endpoints/AmazonApiGatewayV2EndpointAdaptor.ts +0 -97
- package/src/endpoints/Authorizer.ts +0 -152
- package/src/endpoints/Endpoint.ts +0 -1287
- package/src/endpoints/EndpointBuilder.ts +0 -758
- package/src/endpoints/EndpointFactory.ts +0 -1148
- package/src/endpoints/HonoEndpointAdaptor.ts +0 -677
- package/src/endpoints/MswEndpointAdaptor.ts +0 -226
- package/src/endpoints/TestEndpointAdaptor.ts +0 -422
- package/src/endpoints/__tests__/AmazonApiGatewayV1EndpointAdaptor.audits.spec.ts +0 -499
- package/src/endpoints/__tests__/AmazonApiGatewayV1EndpointAdaptor.events.spec.ts +0 -560
- package/src/endpoints/__tests__/AmazonApiGatewayV1EndpointAdaptor.spec.ts +0 -1304
- package/src/endpoints/__tests__/AmazonApiGatewayV2EndpointAdaptor.audits.spec.ts +0 -626
- package/src/endpoints/__tests__/AmazonApiGatewayV2EndpointAdaptor.events.spec.ts +0 -732
- package/src/endpoints/__tests__/AmazonApiGatewayV2EndpointAdaptor.factory-publisher.spec.ts +0 -296
- package/src/endpoints/__tests__/AmazonApiGatewayV2EndpointAdaptor.kysely-audit.integration.spec.ts +0 -951
- package/src/endpoints/__tests__/AmazonApiGatewayV2EndpointAdaptor.responseType.spec.ts +0 -111
- package/src/endpoints/__tests__/AmazonApiGatewayV2EndpointAdaptor.rls.spec.ts +0 -307
- package/src/endpoints/__tests__/AmazonApiGatewayV2EndpointAdaptor.spec.ts +0 -629
- package/src/endpoints/__tests__/Authorizer.spec.ts +0 -286
- package/src/endpoints/__tests__/Endpoint.cookies.spec.ts +0 -207
- package/src/endpoints/__tests__/Endpoint.headers.spec.ts +0 -187
- package/src/endpoints/__tests__/Endpoint.manifest.spec.ts +0 -175
- package/src/endpoints/__tests__/Endpoint.spec.ts +0 -857
- package/src/endpoints/__tests__/EndpointBuilder.audit.spec.ts +0 -448
- package/src/endpoints/__tests__/EndpointBuilder.responseType.spec.ts +0 -47
- package/src/endpoints/__tests__/EndpointBuilder.spec.ts +0 -523
- package/src/endpoints/__tests__/EndpointFactory.authorizers.spec.ts +0 -492
- package/src/endpoints/__tests__/EndpointFactory.database-auditor.spec.ts +0 -509
- package/src/endpoints/__tests__/EndpointFactory.reference-audit.spec.ts +0 -190
- package/src/endpoints/__tests__/EndpointFactory.spec.ts +0 -479
- package/src/endpoints/__tests__/EndpointFactory.state-isolation.spec.ts +0 -155
- package/src/endpoints/__tests__/HonoEndpointAdaptor.audit-transactions.spec.ts +0 -703
- package/src/endpoints/__tests__/HonoEndpointAdaptor.audits.spec.ts +0 -632
- package/src/endpoints/__tests__/HonoEndpointAdaptor.events.spec.ts +0 -577
- package/src/endpoints/__tests__/HonoEndpointAdaptor.kysely-audit.integration.spec.ts +0 -1067
- package/src/endpoints/__tests__/HonoEndpointAdaptor.openapi.spec.ts +0 -317
- package/src/endpoints/__tests__/HonoEndpointAdaptor.pgboss-publisher.spec.ts +0 -289
- package/src/endpoints/__tests__/HonoEndpointAdaptor.responseType.spec.ts +0 -128
- package/src/endpoints/__tests__/HonoEndpointAdaptor.spec.ts +0 -1207
- package/src/endpoints/__tests__/MswEndpointAdaptor.spec.ts +0 -211
- package/src/endpoints/__tests__/ResponseBuilder.spec.ts +0 -235
- package/src/endpoints/__tests__/TestEndpointAdaptor.audits.spec.ts +0 -602
- package/src/endpoints/__tests__/TestEndpointAdaptor.spec.ts +0 -1044
- package/src/endpoints/__tests__/__snapshots__/HonoEndpointAdaptor.spec.ts.snap +0 -54
- package/src/endpoints/__tests__/endpoint-types.test.ts +0 -88
- package/src/endpoints/__tests__/helpers.spec.ts +0 -37
- package/src/endpoints/__tests__/lazyAccessors.spec.ts +0 -330
- package/src/endpoints/__tests__/processAudits.spec.ts +0 -631
- package/src/endpoints/audit.ts +0 -87
- package/src/endpoints/helpers.ts +0 -98
- package/src/endpoints/index.ts +0 -42
- package/src/endpoints/lazyAccessors.ts +0 -241
- package/src/endpoints/parseHonoQuery.ts +0 -16
- package/src/endpoints/parseQueryParams.ts +0 -32
- package/src/endpoints/processAudits.ts +0 -371
- package/src/endpoints/rls.ts +0 -67
- package/src/functions/AWSLambdaFunction.ts +0 -348
- package/src/functions/BaseFunctionBuilder.ts +0 -201
- package/src/functions/Function.ts +0 -238
- package/src/functions/FunctionBuilder.ts +0 -391
- package/src/functions/FunctionExecutionWrapper.ts +0 -216
- package/src/functions/TestFunctionAdaptor.ts +0 -217
- package/src/functions/__tests__/AWSLambdaFunctionAdaptor.spec.ts +0 -513
- package/src/functions/__tests__/Function.audits.spec.ts +0 -393
- package/src/functions/__tests__/Function.spec.ts +0 -477
- package/src/functions/__tests__/FunctionBuilder.state-isolation.spec.ts +0 -207
- package/src/functions/__tests__/TestFunctionAdaptor.spec.ts +0 -480
- package/src/functions/index.ts +0 -12
- package/src/index.ts +0 -23
- package/src/publisher.ts +0 -93
- package/src/queue/AWSLambdaQueueAdaptor.ts +0 -162
- package/src/queue/Queue.ts +0 -128
- package/src/queue/QueueBuilder.ts +0 -115
- package/src/queue/TestQueueAdaptor.ts +0 -63
- package/src/queue/__tests__/QueueBuilder.spec.ts +0 -137
- package/src/queue/index.ts +0 -12
- package/src/subscribers/AWSLambdaSubscriberAdaptor.ts +0 -342
- package/src/subscribers/Subscriber.ts +0 -117
- package/src/subscribers/SubscriberBuilder.ts +0 -186
- package/src/subscribers/TestSubscriberAdaptor.ts +0 -133
- package/src/subscribers/__tests__/AWSLambdaSubscriberAdaptor.spec.ts +0 -1018
- package/src/subscribers/__tests__/Subscriber.spec.ts +0 -430
- package/src/subscribers/__tests__/TestSubscriberAdaptor.spec.ts +0 -652
- package/src/subscribers/index.ts +0 -6
- package/src/telemetry.ts +0 -103
- package/src/topic/Topic.ts +0 -103
- package/src/topic/TopicBuilder.ts +0 -51
- package/src/topic/__tests__/TopicBuilder.spec.ts +0 -82
- package/src/topic/index.ts +0 -11
- package/src/types.ts +0 -13
- package/test.ts +0 -91
- package/tsconfig.json +0 -9
- package/tsdown.config.ts +0 -34
|
@@ -1,631 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AuditableAction,
|
|
3
|
-
Auditor,
|
|
4
|
-
AuditRecord,
|
|
5
|
-
AuditStorage,
|
|
6
|
-
} from '@geekmidas/audit';
|
|
7
|
-
import { DefaultAuditor } from '@geekmidas/audit';
|
|
8
|
-
import { ConsoleLogger } from '@geekmidas/logger/console';
|
|
9
|
-
import type { Service, ServiceDiscovery } from '@geekmidas/services';
|
|
10
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
11
|
-
import { z } from 'zod';
|
|
12
|
-
import { EndpointBuilder } from '../EndpointBuilder';
|
|
13
|
-
import {
|
|
14
|
-
createAuditContext,
|
|
15
|
-
executeWithAuditTransaction,
|
|
16
|
-
processEndpointAudits,
|
|
17
|
-
} from '../processAudits';
|
|
18
|
-
|
|
19
|
-
// Test audit actions
|
|
20
|
-
type TestAuditAction =
|
|
21
|
-
| AuditableAction<'user.created', { userId: string; email: string }>
|
|
22
|
-
| AuditableAction<'user.updated', { userId: string; changes: string[] }>;
|
|
23
|
-
|
|
24
|
-
// In-memory audit storage
|
|
25
|
-
class InMemoryAuditStorage implements AuditStorage {
|
|
26
|
-
records: AuditRecord[] = [];
|
|
27
|
-
withTransactionCalled = false;
|
|
28
|
-
transactionDb: unknown = null;
|
|
29
|
-
|
|
30
|
-
async write(records: AuditRecord[]): Promise<void> {
|
|
31
|
-
this.records.push(...records);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async query(): Promise<AuditRecord[]> {
|
|
35
|
-
return this.records;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
withTransaction<T>(
|
|
39
|
-
auditor: Auditor<any>,
|
|
40
|
-
fn: () => Promise<T>,
|
|
41
|
-
db?: unknown,
|
|
42
|
-
): Promise<T> {
|
|
43
|
-
this.withTransactionCalled = true;
|
|
44
|
-
this.transactionDb = db;
|
|
45
|
-
// Simulate transaction by setting a mock transaction
|
|
46
|
-
if ('setTransaction' in auditor) {
|
|
47
|
-
(auditor as any).setTransaction({ mockTrx: true });
|
|
48
|
-
}
|
|
49
|
-
return fn().then(async (result) => {
|
|
50
|
-
await auditor.flush();
|
|
51
|
-
return result;
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Storage without transaction support
|
|
57
|
-
class SimpleAuditStorage implements AuditStorage {
|
|
58
|
-
records: AuditRecord[] = [];
|
|
59
|
-
|
|
60
|
-
async write(records: AuditRecord[]): Promise<void> {
|
|
61
|
-
this.records.push(...records);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
async query(): Promise<AuditRecord[]> {
|
|
65
|
-
return this.records;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const createMockServiceDiscovery = (
|
|
70
|
-
storage: AuditStorage,
|
|
71
|
-
): ServiceDiscovery<any, any> => {
|
|
72
|
-
return {
|
|
73
|
-
register: vi.fn().mockResolvedValue({ auditStorage: storage }),
|
|
74
|
-
} as unknown as ServiceDiscovery<any, any>;
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const auditStorageService = {
|
|
78
|
-
serviceName: 'auditStorage' as const,
|
|
79
|
-
async register() {
|
|
80
|
-
return new InMemoryAuditStorage();
|
|
81
|
-
},
|
|
82
|
-
} satisfies Service<'auditStorage', InMemoryAuditStorage>;
|
|
83
|
-
|
|
84
|
-
const logger = new ConsoleLogger();
|
|
85
|
-
|
|
86
|
-
describe('processAudits', () => {
|
|
87
|
-
describe('processEndpointAudits', () => {
|
|
88
|
-
it('should skip processing when no audits and no existing records', async () => {
|
|
89
|
-
const endpoint = new EndpointBuilder('/users', 'POST').handle(
|
|
90
|
-
async () => ({ id: '123' }),
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
const storage = new InMemoryAuditStorage();
|
|
94
|
-
const discovery = createMockServiceDiscovery(storage);
|
|
95
|
-
|
|
96
|
-
await processEndpointAudits(endpoint, { id: '123' }, discovery, logger, {
|
|
97
|
-
session: {},
|
|
98
|
-
header: () => undefined,
|
|
99
|
-
cookie: () => undefined,
|
|
100
|
-
services: {},
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
expect(storage.records).toHaveLength(0);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it('should warn when no storage service but has audits', async () => {
|
|
107
|
-
const outputSchema = z.object({ id: z.string(), email: z.string() });
|
|
108
|
-
|
|
109
|
-
const endpoint = new EndpointBuilder('/users', 'POST')
|
|
110
|
-
.output(outputSchema)
|
|
111
|
-
.audit<TestAuditAction>([
|
|
112
|
-
{
|
|
113
|
-
type: 'user.created',
|
|
114
|
-
payload: (r) => ({ userId: r.id, email: r.email }),
|
|
115
|
-
},
|
|
116
|
-
])
|
|
117
|
-
.handle(async () => ({ id: '123', email: 'test@test.com' }));
|
|
118
|
-
|
|
119
|
-
const warnSpy = vi.spyOn(logger, 'warn');
|
|
120
|
-
const discovery = createMockServiceDiscovery(new InMemoryAuditStorage());
|
|
121
|
-
|
|
122
|
-
await processEndpointAudits(
|
|
123
|
-
endpoint,
|
|
124
|
-
{ id: '123', email: 'test@test.com' },
|
|
125
|
-
discovery,
|
|
126
|
-
logger,
|
|
127
|
-
{
|
|
128
|
-
session: {},
|
|
129
|
-
header: () => undefined,
|
|
130
|
-
cookie: () => undefined,
|
|
131
|
-
services: {},
|
|
132
|
-
},
|
|
133
|
-
);
|
|
134
|
-
|
|
135
|
-
expect(warnSpy).toHaveBeenCalledWith(
|
|
136
|
-
'No auditor storage service available',
|
|
137
|
-
);
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it('should process declarative audits', async () => {
|
|
141
|
-
const outputSchema = z.object({ id: z.string(), email: z.string() });
|
|
142
|
-
const storage = new InMemoryAuditStorage();
|
|
143
|
-
|
|
144
|
-
// Create a custom storage service that returns our shared storage
|
|
145
|
-
const customStorageService = {
|
|
146
|
-
serviceName: 'auditStorage' as const,
|
|
147
|
-
async register() {
|
|
148
|
-
return storage;
|
|
149
|
-
},
|
|
150
|
-
} satisfies Service<'auditStorage', InMemoryAuditStorage>;
|
|
151
|
-
|
|
152
|
-
const endpoint = new EndpointBuilder('/users', 'POST')
|
|
153
|
-
.output(outputSchema)
|
|
154
|
-
.auditor(customStorageService)
|
|
155
|
-
.audit<TestAuditAction>([
|
|
156
|
-
{
|
|
157
|
-
type: 'user.created',
|
|
158
|
-
payload: (r) => ({ userId: r.id, email: r.email }),
|
|
159
|
-
},
|
|
160
|
-
])
|
|
161
|
-
.handle(async () => ({ id: '123', email: 'test@test.com' }));
|
|
162
|
-
|
|
163
|
-
// Mock the service discovery to return our storage
|
|
164
|
-
const mockDiscovery = {
|
|
165
|
-
register: vi.fn().mockImplementation(async () => {
|
|
166
|
-
return { auditStorage: storage };
|
|
167
|
-
}),
|
|
168
|
-
} as unknown as ServiceDiscovery<any, any>;
|
|
169
|
-
|
|
170
|
-
await processEndpointAudits(
|
|
171
|
-
endpoint,
|
|
172
|
-
{ id: '123', email: 'test@test.com' },
|
|
173
|
-
mockDiscovery,
|
|
174
|
-
logger,
|
|
175
|
-
{
|
|
176
|
-
session: {},
|
|
177
|
-
header: () => undefined,
|
|
178
|
-
cookie: () => undefined,
|
|
179
|
-
services: {},
|
|
180
|
-
},
|
|
181
|
-
);
|
|
182
|
-
|
|
183
|
-
expect(storage.records).toHaveLength(1);
|
|
184
|
-
expect(storage.records[0].type).toBe('user.created');
|
|
185
|
-
expect(storage.records[0].payload).toEqual({
|
|
186
|
-
userId: '123',
|
|
187
|
-
email: 'test@test.com',
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it('should skip audits when when condition returns false', async () => {
|
|
192
|
-
const outputSchema = z.object({
|
|
193
|
-
id: z.string(),
|
|
194
|
-
email: z.string(),
|
|
195
|
-
active: z.boolean(),
|
|
196
|
-
});
|
|
197
|
-
const storage = new InMemoryAuditStorage();
|
|
198
|
-
|
|
199
|
-
const endpoint = new EndpointBuilder('/users', 'POST')
|
|
200
|
-
.output(outputSchema)
|
|
201
|
-
.auditor(auditStorageService)
|
|
202
|
-
.audit<TestAuditAction>([
|
|
203
|
-
{
|
|
204
|
-
type: 'user.created',
|
|
205
|
-
payload: (r) => ({ userId: r.id, email: r.email }),
|
|
206
|
-
when: (r) => r.active,
|
|
207
|
-
},
|
|
208
|
-
])
|
|
209
|
-
.handle(async () => ({
|
|
210
|
-
id: '123',
|
|
211
|
-
email: 'test@test.com',
|
|
212
|
-
active: false,
|
|
213
|
-
}));
|
|
214
|
-
|
|
215
|
-
const discovery = createMockServiceDiscovery(storage);
|
|
216
|
-
|
|
217
|
-
await processEndpointAudits(
|
|
218
|
-
endpoint,
|
|
219
|
-
{ id: '123', email: 'test@test.com', active: false },
|
|
220
|
-
discovery,
|
|
221
|
-
logger,
|
|
222
|
-
{
|
|
223
|
-
session: {},
|
|
224
|
-
header: () => undefined,
|
|
225
|
-
cookie: () => undefined,
|
|
226
|
-
services: {},
|
|
227
|
-
},
|
|
228
|
-
);
|
|
229
|
-
|
|
230
|
-
expect(storage.records).toHaveLength(0);
|
|
231
|
-
});
|
|
232
|
-
|
|
233
|
-
it('should use existing auditor when provided', async () => {
|
|
234
|
-
const outputSchema = z.object({ id: z.string(), email: z.string() });
|
|
235
|
-
const storage = new InMemoryAuditStorage();
|
|
236
|
-
|
|
237
|
-
const endpoint = new EndpointBuilder('/users', 'POST')
|
|
238
|
-
.output(outputSchema)
|
|
239
|
-
.auditor(auditStorageService)
|
|
240
|
-
.audit<TestAuditAction>([
|
|
241
|
-
{
|
|
242
|
-
type: 'user.created',
|
|
243
|
-
payload: (r) => ({ userId: r.id, email: r.email }),
|
|
244
|
-
},
|
|
245
|
-
])
|
|
246
|
-
.handle(async () => ({ id: '123', email: 'test@test.com' }));
|
|
247
|
-
|
|
248
|
-
const discovery = createMockServiceDiscovery(storage);
|
|
249
|
-
|
|
250
|
-
// Create an existing auditor with some records already
|
|
251
|
-
const existingAuditor = new DefaultAuditor<TestAuditAction>({
|
|
252
|
-
actor: { id: 'existing-user', type: 'user' },
|
|
253
|
-
storage,
|
|
254
|
-
});
|
|
255
|
-
existingAuditor.audit('user.updated', {
|
|
256
|
-
userId: '456',
|
|
257
|
-
changes: ['name'],
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
await processEndpointAudits(
|
|
261
|
-
endpoint,
|
|
262
|
-
{ id: '123', email: 'test@test.com' },
|
|
263
|
-
discovery,
|
|
264
|
-
logger,
|
|
265
|
-
{
|
|
266
|
-
session: {},
|
|
267
|
-
header: () => undefined,
|
|
268
|
-
cookie: () => undefined,
|
|
269
|
-
services: {},
|
|
270
|
-
},
|
|
271
|
-
existingAuditor,
|
|
272
|
-
);
|
|
273
|
-
|
|
274
|
-
// Should have both the existing record and the new declarative one
|
|
275
|
-
expect(storage.records).toHaveLength(2);
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
it('should extract actor when configured', async () => {
|
|
279
|
-
const outputSchema = z.object({ id: z.string(), email: z.string() });
|
|
280
|
-
const storage = new InMemoryAuditStorage();
|
|
281
|
-
|
|
282
|
-
const endpoint = new EndpointBuilder('/users', 'POST')
|
|
283
|
-
.output(outputSchema)
|
|
284
|
-
.auditor(auditStorageService)
|
|
285
|
-
.actor(({ session }) => ({
|
|
286
|
-
id: (session as any).userId,
|
|
287
|
-
type: 'user',
|
|
288
|
-
}))
|
|
289
|
-
.audit<TestAuditAction>([
|
|
290
|
-
{
|
|
291
|
-
type: 'user.created',
|
|
292
|
-
payload: (r) => ({ userId: r.id, email: r.email }),
|
|
293
|
-
},
|
|
294
|
-
])
|
|
295
|
-
.handle(async () => ({ id: '123', email: 'test@test.com' }));
|
|
296
|
-
|
|
297
|
-
const discovery = createMockServiceDiscovery(storage);
|
|
298
|
-
|
|
299
|
-
await processEndpointAudits(
|
|
300
|
-
endpoint,
|
|
301
|
-
{ id: '123', email: 'test@test.com' },
|
|
302
|
-
discovery,
|
|
303
|
-
logger,
|
|
304
|
-
{
|
|
305
|
-
session: { userId: 'actor-123' },
|
|
306
|
-
header: () => undefined,
|
|
307
|
-
cookie: () => undefined,
|
|
308
|
-
services: {},
|
|
309
|
-
},
|
|
310
|
-
);
|
|
311
|
-
|
|
312
|
-
expect(storage.records).toHaveLength(1);
|
|
313
|
-
expect(storage.records[0].actor.id).toBe('actor-123');
|
|
314
|
-
});
|
|
315
|
-
|
|
316
|
-
it('should handle actor extraction errors gracefully', async () => {
|
|
317
|
-
const outputSchema = z.object({ id: z.string(), email: z.string() });
|
|
318
|
-
const storage = new InMemoryAuditStorage();
|
|
319
|
-
|
|
320
|
-
const endpoint = new EndpointBuilder('/users', 'POST')
|
|
321
|
-
.output(outputSchema)
|
|
322
|
-
.auditor(auditStorageService)
|
|
323
|
-
.actor(() => {
|
|
324
|
-
throw new Error('Actor extraction failed');
|
|
325
|
-
})
|
|
326
|
-
.audit<TestAuditAction>([
|
|
327
|
-
{
|
|
328
|
-
type: 'user.created',
|
|
329
|
-
payload: (r) => ({ userId: r.id, email: r.email }),
|
|
330
|
-
},
|
|
331
|
-
])
|
|
332
|
-
.handle(async () => ({ id: '123', email: 'test@test.com' }));
|
|
333
|
-
|
|
334
|
-
const discovery = createMockServiceDiscovery(storage);
|
|
335
|
-
|
|
336
|
-
// Should not throw, continue with system actor
|
|
337
|
-
await processEndpointAudits(
|
|
338
|
-
endpoint,
|
|
339
|
-
{ id: '123', email: 'test@test.com' },
|
|
340
|
-
discovery,
|
|
341
|
-
logger,
|
|
342
|
-
{
|
|
343
|
-
session: {},
|
|
344
|
-
header: () => undefined,
|
|
345
|
-
cookie: () => undefined,
|
|
346
|
-
services: {},
|
|
347
|
-
},
|
|
348
|
-
);
|
|
349
|
-
|
|
350
|
-
expect(storage.records).toHaveLength(1);
|
|
351
|
-
expect(storage.records[0].actor.id).toBe('system');
|
|
352
|
-
});
|
|
353
|
-
|
|
354
|
-
it('should include entityId and table when configured', async () => {
|
|
355
|
-
const outputSchema = z.object({ id: z.string(), email: z.string() });
|
|
356
|
-
const storage = new InMemoryAuditStorage();
|
|
357
|
-
|
|
358
|
-
const endpoint = new EndpointBuilder('/users', 'POST')
|
|
359
|
-
.output(outputSchema)
|
|
360
|
-
.auditor(auditStorageService)
|
|
361
|
-
.audit<TestAuditAction>([
|
|
362
|
-
{
|
|
363
|
-
type: 'user.created',
|
|
364
|
-
payload: (r) => ({ userId: r.id, email: r.email }),
|
|
365
|
-
entityId: (r) => r.id,
|
|
366
|
-
table: 'users',
|
|
367
|
-
},
|
|
368
|
-
])
|
|
369
|
-
.handle(async () => ({ id: '123', email: 'test@test.com' }));
|
|
370
|
-
|
|
371
|
-
const discovery = createMockServiceDiscovery(storage);
|
|
372
|
-
|
|
373
|
-
await processEndpointAudits(
|
|
374
|
-
endpoint,
|
|
375
|
-
{ id: '123', email: 'test@test.com' },
|
|
376
|
-
discovery,
|
|
377
|
-
logger,
|
|
378
|
-
{
|
|
379
|
-
session: {},
|
|
380
|
-
header: () => undefined,
|
|
381
|
-
cookie: () => undefined,
|
|
382
|
-
services: {},
|
|
383
|
-
},
|
|
384
|
-
);
|
|
385
|
-
|
|
386
|
-
expect(storage.records).toHaveLength(1);
|
|
387
|
-
expect(storage.records[0].entityId).toBe('123');
|
|
388
|
-
expect(storage.records[0].table).toBe('users');
|
|
389
|
-
});
|
|
390
|
-
|
|
391
|
-
it('should handle errors during processing', async () => {
|
|
392
|
-
const outputSchema = z.object({ id: z.string(), email: z.string() });
|
|
393
|
-
|
|
394
|
-
const endpoint = new EndpointBuilder('/users', 'POST')
|
|
395
|
-
.output(outputSchema)
|
|
396
|
-
.auditor(auditStorageService)
|
|
397
|
-
.audit<TestAuditAction>([
|
|
398
|
-
{
|
|
399
|
-
type: 'user.created',
|
|
400
|
-
payload: () => {
|
|
401
|
-
throw new Error('Payload extraction failed');
|
|
402
|
-
},
|
|
403
|
-
},
|
|
404
|
-
])
|
|
405
|
-
.handle(async () => ({ id: '123', email: 'test@test.com' }));
|
|
406
|
-
|
|
407
|
-
const discovery = createMockServiceDiscovery(new InMemoryAuditStorage());
|
|
408
|
-
const errorSpy = vi.spyOn(logger, 'error');
|
|
409
|
-
|
|
410
|
-
// Should not throw
|
|
411
|
-
await processEndpointAudits(
|
|
412
|
-
endpoint,
|
|
413
|
-
{ id: '123', email: 'test@test.com' },
|
|
414
|
-
discovery,
|
|
415
|
-
logger,
|
|
416
|
-
{
|
|
417
|
-
session: {},
|
|
418
|
-
header: () => undefined,
|
|
419
|
-
cookie: () => undefined,
|
|
420
|
-
services: {},
|
|
421
|
-
},
|
|
422
|
-
);
|
|
423
|
-
|
|
424
|
-
expect(errorSpy).toHaveBeenCalled();
|
|
425
|
-
});
|
|
426
|
-
});
|
|
427
|
-
|
|
428
|
-
describe('createAuditContext', () => {
|
|
429
|
-
it('should return undefined when no storage service', async () => {
|
|
430
|
-
const endpoint = new EndpointBuilder('/users', 'POST').handle(
|
|
431
|
-
async () => ({ id: '123' }),
|
|
432
|
-
);
|
|
433
|
-
|
|
434
|
-
const discovery = createMockServiceDiscovery(new InMemoryAuditStorage());
|
|
435
|
-
|
|
436
|
-
const context = await createAuditContext(endpoint, discovery, logger, {
|
|
437
|
-
session: {},
|
|
438
|
-
header: () => undefined,
|
|
439
|
-
cookie: () => undefined,
|
|
440
|
-
services: {},
|
|
441
|
-
});
|
|
442
|
-
|
|
443
|
-
expect(context).toBeUndefined();
|
|
444
|
-
});
|
|
445
|
-
|
|
446
|
-
it('should create audit context with storage and auditor', async () => {
|
|
447
|
-
const storage = new InMemoryAuditStorage();
|
|
448
|
-
|
|
449
|
-
const endpoint = new EndpointBuilder('/users', 'POST')
|
|
450
|
-
.auditor(auditStorageService)
|
|
451
|
-
.handle(async () => ({ id: '123' }));
|
|
452
|
-
|
|
453
|
-
const discovery = createMockServiceDiscovery(storage);
|
|
454
|
-
|
|
455
|
-
const context = await createAuditContext(endpoint, discovery, logger, {
|
|
456
|
-
session: {},
|
|
457
|
-
header: () => undefined,
|
|
458
|
-
cookie: () => undefined,
|
|
459
|
-
services: {},
|
|
460
|
-
});
|
|
461
|
-
|
|
462
|
-
expect(context).toBeDefined();
|
|
463
|
-
expect(context!.storage).toBe(storage);
|
|
464
|
-
expect(context!.auditor).toBeDefined();
|
|
465
|
-
});
|
|
466
|
-
|
|
467
|
-
it('should use custom actor extractor', async () => {
|
|
468
|
-
const storage = new InMemoryAuditStorage();
|
|
469
|
-
|
|
470
|
-
const endpoint = new EndpointBuilder('/users', 'POST')
|
|
471
|
-
.auditor(auditStorageService)
|
|
472
|
-
.actor(({ session }) => ({
|
|
473
|
-
id: (session as any).userId,
|
|
474
|
-
type: 'user',
|
|
475
|
-
}))
|
|
476
|
-
.handle(async () => ({ id: '123' }));
|
|
477
|
-
|
|
478
|
-
const discovery = createMockServiceDiscovery(storage);
|
|
479
|
-
|
|
480
|
-
const context = await createAuditContext(endpoint, discovery, logger, {
|
|
481
|
-
session: { userId: 'actor-456' },
|
|
482
|
-
header: () => undefined,
|
|
483
|
-
cookie: () => undefined,
|
|
484
|
-
services: {},
|
|
485
|
-
});
|
|
486
|
-
|
|
487
|
-
expect(context).toBeDefined();
|
|
488
|
-
|
|
489
|
-
// Record an audit and check the actor
|
|
490
|
-
context!.auditor.audit('user.created' as any, {
|
|
491
|
-
userId: '123',
|
|
492
|
-
email: 'test@test.com',
|
|
493
|
-
});
|
|
494
|
-
await context!.auditor.flush();
|
|
495
|
-
|
|
496
|
-
expect(storage.records[0].actor.id).toBe('actor-456');
|
|
497
|
-
});
|
|
498
|
-
|
|
499
|
-
it('should use system actor when extraction fails', async () => {
|
|
500
|
-
const storage = new InMemoryAuditStorage();
|
|
501
|
-
|
|
502
|
-
const endpoint = new EndpointBuilder('/users', 'POST')
|
|
503
|
-
.auditor(auditStorageService)
|
|
504
|
-
.actor(() => {
|
|
505
|
-
throw new Error('Actor extraction failed');
|
|
506
|
-
})
|
|
507
|
-
.handle(async () => ({ id: '123' }));
|
|
508
|
-
|
|
509
|
-
const discovery = createMockServiceDiscovery(storage);
|
|
510
|
-
|
|
511
|
-
const context = await createAuditContext(endpoint, discovery, logger, {
|
|
512
|
-
session: {},
|
|
513
|
-
header: () => undefined,
|
|
514
|
-
cookie: () => undefined,
|
|
515
|
-
services: {},
|
|
516
|
-
});
|
|
517
|
-
|
|
518
|
-
expect(context).toBeDefined();
|
|
519
|
-
|
|
520
|
-
context!.auditor.audit('user.created' as any, {
|
|
521
|
-
userId: '123',
|
|
522
|
-
email: 'test@test.com',
|
|
523
|
-
});
|
|
524
|
-
await context!.auditor.flush();
|
|
525
|
-
|
|
526
|
-
expect(storage.records[0].actor.id).toBe('system');
|
|
527
|
-
});
|
|
528
|
-
});
|
|
529
|
-
|
|
530
|
-
describe('executeWithAuditTransaction', () => {
|
|
531
|
-
it('should run handler without context', async () => {
|
|
532
|
-
const handlerFn = vi.fn().mockResolvedValue({ id: '123' });
|
|
533
|
-
|
|
534
|
-
const result = await executeWithAuditTransaction(undefined, handlerFn);
|
|
535
|
-
|
|
536
|
-
expect(result).toEqual({ id: '123' });
|
|
537
|
-
expect(handlerFn).toHaveBeenCalledWith(undefined);
|
|
538
|
-
});
|
|
539
|
-
|
|
540
|
-
it('should use transaction when storage supports it', async () => {
|
|
541
|
-
const storage = new InMemoryAuditStorage();
|
|
542
|
-
const auditor = new DefaultAuditor<TestAuditAction>({
|
|
543
|
-
actor: { id: 'test', type: 'user' },
|
|
544
|
-
storage,
|
|
545
|
-
});
|
|
546
|
-
|
|
547
|
-
const context = { auditor, storage };
|
|
548
|
-
const handlerFn = vi.fn().mockResolvedValue({ id: '123' });
|
|
549
|
-
|
|
550
|
-
const result = await executeWithAuditTransaction(context, handlerFn);
|
|
551
|
-
|
|
552
|
-
expect(result).toEqual({ id: '123' });
|
|
553
|
-
expect(storage.withTransactionCalled).toBe(true);
|
|
554
|
-
});
|
|
555
|
-
|
|
556
|
-
it('should pass db option to storage transaction', async () => {
|
|
557
|
-
const storage = new InMemoryAuditStorage();
|
|
558
|
-
const auditor = new DefaultAuditor<TestAuditAction>({
|
|
559
|
-
actor: { id: 'test', type: 'user' },
|
|
560
|
-
storage,
|
|
561
|
-
});
|
|
562
|
-
|
|
563
|
-
const context = { auditor, storage };
|
|
564
|
-
const mockDb = { isMockDb: true };
|
|
565
|
-
|
|
566
|
-
await executeWithAuditTransaction(
|
|
567
|
-
context,
|
|
568
|
-
async () => ({ id: '123' }),
|
|
569
|
-
undefined,
|
|
570
|
-
{ db: mockDb },
|
|
571
|
-
);
|
|
572
|
-
|
|
573
|
-
expect(storage.transactionDb).toBe(mockDb);
|
|
574
|
-
});
|
|
575
|
-
|
|
576
|
-
it('should call onComplete callback', async () => {
|
|
577
|
-
const storage = new InMemoryAuditStorage();
|
|
578
|
-
const auditor = new DefaultAuditor<TestAuditAction>({
|
|
579
|
-
actor: { id: 'test', type: 'user' },
|
|
580
|
-
storage,
|
|
581
|
-
});
|
|
582
|
-
|
|
583
|
-
const context = { auditor, storage };
|
|
584
|
-
const onComplete = vi.fn();
|
|
585
|
-
|
|
586
|
-
const _result = await executeWithAuditTransaction(
|
|
587
|
-
context,
|
|
588
|
-
async () => ({ id: '123' }),
|
|
589
|
-
onComplete,
|
|
590
|
-
);
|
|
591
|
-
|
|
592
|
-
expect(onComplete).toHaveBeenCalledWith({ id: '123' }, auditor);
|
|
593
|
-
});
|
|
594
|
-
|
|
595
|
-
it('should flush audits when storage has no transaction support', async () => {
|
|
596
|
-
const storage = new SimpleAuditStorage();
|
|
597
|
-
const auditor = new DefaultAuditor<TestAuditAction>({
|
|
598
|
-
actor: { id: 'test', type: 'user' },
|
|
599
|
-
storage,
|
|
600
|
-
});
|
|
601
|
-
|
|
602
|
-
const context = { auditor, storage };
|
|
603
|
-
|
|
604
|
-
await executeWithAuditTransaction(context, async (a) => {
|
|
605
|
-
a!.audit('user.created', { userId: '123', email: 'test@test.com' });
|
|
606
|
-
return { id: '123' };
|
|
607
|
-
});
|
|
608
|
-
|
|
609
|
-
expect(storage.records).toHaveLength(1);
|
|
610
|
-
});
|
|
611
|
-
|
|
612
|
-
it('should call onComplete even without transaction support', async () => {
|
|
613
|
-
const storage = new SimpleAuditStorage();
|
|
614
|
-
const auditor = new DefaultAuditor<TestAuditAction>({
|
|
615
|
-
actor: { id: 'test', type: 'user' },
|
|
616
|
-
storage,
|
|
617
|
-
});
|
|
618
|
-
|
|
619
|
-
const context = { auditor, storage };
|
|
620
|
-
const onComplete = vi.fn();
|
|
621
|
-
|
|
622
|
-
await executeWithAuditTransaction(
|
|
623
|
-
context,
|
|
624
|
-
async () => ({ id: '123' }),
|
|
625
|
-
onComplete,
|
|
626
|
-
);
|
|
627
|
-
|
|
628
|
-
expect(onComplete).toHaveBeenCalled();
|
|
629
|
-
});
|
|
630
|
-
});
|
|
631
|
-
});
|
package/src/endpoints/audit.ts
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AuditActor,
|
|
3
|
-
AuditableAction,
|
|
4
|
-
AuditStorage,
|
|
5
|
-
ExtractAuditPayload,
|
|
6
|
-
ExtractAuditType,
|
|
7
|
-
} from '@geekmidas/audit';
|
|
8
|
-
import type { Logger } from '@geekmidas/logger';
|
|
9
|
-
import type { InferStandardSchema } from '@geekmidas/schema';
|
|
10
|
-
import type { Service, ServiceRecord } from '@geekmidas/services';
|
|
11
|
-
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
12
|
-
import type { CookieFn, HeaderFn } from './Endpoint';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Defines how to map an endpoint response to an audit record.
|
|
16
|
-
* Similar to MappedEvent for events.
|
|
17
|
-
*
|
|
18
|
-
* @template TAuditAction - Union of all allowed audit action types
|
|
19
|
-
* @template TOutput - The output schema of the endpoint
|
|
20
|
-
*/
|
|
21
|
-
export interface MappedAudit<
|
|
22
|
-
TAuditAction extends AuditableAction<string, unknown>,
|
|
23
|
-
TOutput extends StandardSchemaV1 | undefined,
|
|
24
|
-
TType extends ExtractAuditType<TAuditAction> = ExtractAuditType<TAuditAction>,
|
|
25
|
-
> {
|
|
26
|
-
/** The audit type (must be a valid type from TAuditAction) */
|
|
27
|
-
type: TType;
|
|
28
|
-
/** Function to extract payload from the endpoint response */
|
|
29
|
-
payload: (
|
|
30
|
-
response: TOutput extends StandardSchemaV1
|
|
31
|
-
? InferStandardSchema<TOutput>
|
|
32
|
-
: unknown,
|
|
33
|
-
) => ExtractAuditPayload<TAuditAction, TType>;
|
|
34
|
-
/** Optional condition to determine if audit should be recorded */
|
|
35
|
-
when?: (
|
|
36
|
-
response: TOutput extends StandardSchemaV1
|
|
37
|
-
? InferStandardSchema<TOutput>
|
|
38
|
-
: unknown,
|
|
39
|
-
) => boolean;
|
|
40
|
-
/** Optional function to extract entity ID for easier querying */
|
|
41
|
-
entityId?: (
|
|
42
|
-
response: TOutput extends StandardSchemaV1
|
|
43
|
-
? InferStandardSchema<TOutput>
|
|
44
|
-
: unknown,
|
|
45
|
-
) => string | Record<string, unknown>;
|
|
46
|
-
/** Optional table name for the audit record */
|
|
47
|
-
table?: string;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Function type for extracting actor information from request context.
|
|
52
|
-
*
|
|
53
|
-
* @template TServices - Available service dependencies
|
|
54
|
-
* @template TSession - Session data type
|
|
55
|
-
* @template TLogger - Logger type
|
|
56
|
-
*/
|
|
57
|
-
export type ActorExtractor<
|
|
58
|
-
TServices extends Service[] = [],
|
|
59
|
-
TSession = unknown,
|
|
60
|
-
TLogger extends Logger = Logger,
|
|
61
|
-
> = (ctx: {
|
|
62
|
-
services: ServiceRecord<TServices>;
|
|
63
|
-
session: TSession;
|
|
64
|
-
header: HeaderFn;
|
|
65
|
-
cookie: CookieFn;
|
|
66
|
-
logger: TLogger;
|
|
67
|
-
}) => AuditActor | Promise<AuditActor>;
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Configuration for the auditor on an endpoint.
|
|
71
|
-
*/
|
|
72
|
-
export interface EndpointAuditorConfig<
|
|
73
|
-
TAuditStorage extends AuditStorage,
|
|
74
|
-
TAuditStorageServiceName extends string,
|
|
75
|
-
TServices extends Service[],
|
|
76
|
-
TSession,
|
|
77
|
-
TLogger extends Logger,
|
|
78
|
-
TAuditAction extends AuditableAction<string, unknown>,
|
|
79
|
-
TOutput extends StandardSchemaV1 | undefined,
|
|
80
|
-
> {
|
|
81
|
-
/** The audit storage service */
|
|
82
|
-
storageService: Service<TAuditStorageServiceName, TAuditStorage>;
|
|
83
|
-
/** Optional actor extractor function */
|
|
84
|
-
actorExtractor?: ActorExtractor<TServices, TSession, TLogger>;
|
|
85
|
-
/** Declarative audit definitions */
|
|
86
|
-
audits: MappedAudit<TAuditAction, TOutput>[];
|
|
87
|
-
}
|