diff --git a/CHANGELOG.md b/CHANGELOG.md index 4489ce9..bb0c3ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## Unreleased +### Changed + +- Added request body to parameters of ACL context extraction custom function + ## [3.3.0] - 2024-10-14 ### Added diff --git a/src/lib/extract-acl-context.ts b/src/lib/extract-acl-context.ts index d797b68..6e0fd9d 100644 --- a/src/lib/extract-acl-context.ts +++ b/src/lib/extract-acl-context.ts @@ -34,6 +34,7 @@ export const extractAclContext = async ( ): Promise => { if (config.ACL_CONTEXT_BUILDER !== undefined) { const aclContext = await config.ACL_CONTEXT_BUILDER({ + body: request.body, headers: request.headers, method: request.method, pathParams: request.params, @@ -46,7 +47,7 @@ export const extractAclContext = async ( ? aclContext.filter(element => typeof element === 'string') : [] } - // todo + // @ts-expect-error this is a decorated request // eslint-disable-next-line @typescript-eslint/no-unsafe-call const groups = request.getGroups() as string[] diff --git a/src/sdk/sandbox.ts b/src/sdk/sandbox.ts index 6f2f1b9..4fc79d5 100644 --- a/src/sdk/sandbox.ts +++ b/src/sdk/sandbox.ts @@ -18,6 +18,7 @@ import type { QuickJSContext } from 'quickjs-emscripten' import { newAsyncRuntime } from 'quickjs-emscripten' export interface AclContextBuilderInput { + body?: unknown headers: Record method: string pathParams: unknown @@ -45,6 +46,7 @@ class Sandbox { if (cachedValue !== undefined) { return cachedValue } + /* Follows an alternative if sandbox is too slow const script = `data:text/javascript;base64,${Buffer.from(CODE).toString('base64')}` const module = await import(script) @@ -63,9 +65,11 @@ class Sandbox { const error = context.dump(wrappedResult.error) as { message?: string } throw new Error(`External ACL context builder failed: ${error.message}`) } + context.unwrapResult(wrappedResult).dispose() const result = context.getProp(context.global, 'result').consume(context.dump.bind(context)) as string[] this.cache[hash] = result + return result } } diff --git a/src/sdk/test/sandbox.test.ts b/src/sdk/test/sandbox.test.ts index 98126d8..868ae45 100644 --- a/src/sdk/test/sandbox.test.ts +++ b/src/sdk/test/sandbox.test.ts @@ -30,6 +30,7 @@ describe('Sandbox', () => { it('Scripts throws error', async () => { const input: AclContextBuilderInput = { + body: {}, // @ts-expect-error needed for test headers: undefined, method: 'GET', @@ -43,6 +44,7 @@ describe('Sandbox', () => { it('Eval ACL context builder', async () => { const input: AclContextBuilderInput = { + body: {}, headers: { userproperties: 'property', },