diff --git a/src/Layout.ts b/src/Layout.ts index 02bcd16..f163763 100644 --- a/src/Layout.ts +++ b/src/Layout.ts @@ -83,7 +83,7 @@ export type GetParams = ScriptP export type Sort = { fieldName : keyof T; - sortOrder : 'ascend' | 'descend' | string; + sortOrder : 'ascend' | 'descend'; }; export type ListParams< @@ -111,6 +111,8 @@ export type File = { buffer : Buffer; }; +export type ExecuteScriptResponse = Pick; + export default class Layout { public constructor(private readonly layout : string, private readonly client : Client) { } @@ -274,6 +276,24 @@ export default class Layout { + const searchParams = new URLSearchParams(); + + if (scriptParam) { + searchParams.set('script.param', scriptParam); + } + + return await this.client.request( + `layouts/${this.layout}/script/${encodeURI(scriptName)}?${searchParams.toString()}` + ); + } + private addPortalRangesToRequest( portalRanges : PortalRanges, request : Record | URLSearchParams diff --git a/test/Layout.test.ts b/test/Layout.test.ts index 6eea001..00e4f7f 100644 --- a/test/Layout.test.ts +++ b/test/Layout.test.ts @@ -379,4 +379,26 @@ describe('Layout', () => { expect(response).toEqual({data: []}); }); }); + + describe('executeScript', () => { + it('should send a execute script call', async () => { + const expectedResponse = {scriptResult: 'bar', scriptError: '0'}; + + clientMock.request.withArgs('layouts/foo/script/testscript?') + .returns(Promise.resolve(expectedResponse)); + + const response = await layout.executeScript('testscript'); + expect(response).toBe(expectedResponse); + }); + + it('should send a execute script call with param', async () => { + const expectedResponse = {scriptError: '0'}; + + clientMock.request.withArgs('layouts/foo/script/test%20%7C%20script?script.param=%3Ftest%2B%3Dparam') + .returns(Promise.resolve(expectedResponse)); + + const response = await layout.executeScript('test | script', '?test+=param'); + expect(response).toBe(expectedResponse); + }); + }); });