Skip to content

Commit a35be3a

Browse files
committed
feat(caller): add the current visited url of the user
1 parent ce0a389 commit a35be3a

File tree

9 files changed

+27
-9
lines changed

9 files changed

+27
-9
lines changed

packages/agent/src/routes/modification/action/action.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ export default class ActionRoute extends CollectionRoute {
6868
this.getRecordSelection(context, false),
6969
]);
7070
const requestBody = context.request.body as SmartActionApprovalRequestBody;
71-
const webAppURL: URL = new URL(context.request.url || context.request.originalUrl);
7271

7372
const canPerformCustomActionParams = {
7473
caller,
@@ -104,9 +103,7 @@ export default class ActionRoute extends CollectionRoute {
104103

105104
// Now that we have the field list, we can parse the data again.
106105
const data = ForestValueConverter.makeFormData(dataSource, rawData, fields);
107-
const result = await this.collection.execute(caller, this.actionName, data, filterForCaller, {
108-
webAppURL,
109-
});
106+
const result = await this.collection.execute(caller, this.actionName, data, filterForCaller);
110107

111108
if (result?.type === 'Error') {
112109
context.response.status = HttpCode.BadRequest;

packages/agent/src/utils/query-string.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,12 @@ export default class QueryStringParser {
140140
QueryStringParser.VALID_TIMEZONES.add(timezone);
141141
}
142142

143-
return { ...context.state.user, timezone, requestId: uuidv4() };
143+
return {
144+
...context.state.user,
145+
timezone,
146+
requestId: uuidv4(),
147+
webAppURL: new URL(context.originalUrl),
148+
};
144149
}
145150

146151
static parsePagination(context: Context): Page {

packages/agent/test/utils/query-string.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,21 @@ describe('QueryStringParser', () => {
399399
});
400400
});
401401

402+
test('should return the current visited url from user eg forestContextUrl', () => {
403+
const context = createMockContext({
404+
state: { user: { email: 'john.doe@domain.com' } },
405+
customProperties: { query: { timezone: 'America/Los_Angeles' } },
406+
url: 'https://app.forestadmin.com/aProject/anEnvironment/aRendering',
407+
});
408+
409+
expect(QueryStringParser.parseCaller(context)).toEqual({
410+
email: 'john.doe@domain.com',
411+
requestId: expect.any(String),
412+
timezone: 'America/Los_Angeles',
413+
webAppURL: new URL('https://app.forestadmin.com/aProject/anEnvironment/aRendering'),
414+
});
415+
});
416+
402417
test('should throw a ValidationError when the timezone is missing', () => {
403418
const context = createMockContext({
404419
customProperties: { query: {} },

packages/datasource-customizer/src/decorators/actions/collection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default class ActionCollectionDecorator extends CollectionDecorator {
3737
if (!action) return this.childCollection.execute(caller, name, data, filter);
3838

3939
// eslint-disable-next-line @typescript-eslint/no-explicit-any
40-
const context = this.getContext(caller, action, data, filter) as any;
40+
const context = this.getContext(caller, action, data, filter, null, null) as any;
4141
const resultBuilder = new ResultBuilder();
4242
const result = await action.execute(context, resultBuilder);
4343

packages/datasource-replica/src/cache-interface/datasource.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default class CacheDataSourceInterface {
1616
team: 'system',
1717
timezone: 'UTC',
1818
requestId: '',
19+
webAppURL: new URL('https://app.forestadmin.com/aProject/anEnvironment/aRendering'),
1920
};
2021

2122
constructor(dataSource: DataSource) {

packages/datasource-toolkit/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export * from './interfaces/query/sort';
4343
export * from './interfaces/query/page';
4444
export * from './interfaces/record';
4545
export * from './interfaces/schema';
46+
4647
export {
4748
GenericTree,
4849
GenericTreeBranch,

packages/datasource-toolkit/src/interfaces/caller.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ export type Caller = {
99
role: string;
1010
tags: { [key: string]: string };
1111
timezone: string;
12+
webAppURL: URL;
1213
};

packages/datasource-toolkit/src/interfaces/collection.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ export interface Collection {
3535
name: string,
3636
formValues: RecordData,
3737
filter?: Filter,
38-
additionalInformation?: {
39-
webAppURL: URL;
40-
},
4138
): Promise<ActionResult>;
4239

4340
getForm(

packages/datasource-toolkit/test/__factories__/caller.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ export default Factory.define<Caller>(() => ({
1313
tags: {},
1414
team: 'team',
1515
timezone: 'Europe/Paris',
16+
webAppURL: new URL('https://app.forestadmin.com/aProject/anEnvironment/aRendering'),
1617
}));

0 commit comments

Comments
 (0)