diff --git a/packages/agent/src/utils/query-string.ts b/packages/agent/src/utils/query-string.ts index 2d148f3549..c94d15d9db 100644 --- a/packages/agent/src/utils/query-string.ts +++ b/packages/agent/src/utils/query-string.ts @@ -140,7 +140,12 @@ export default class QueryStringParser { QueryStringParser.VALID_TIMEZONES.add(timezone); } - return { ...context.state.user, timezone, requestId: uuidv4() }; + return { + ...context.state.user, + timezone, + requestId: uuidv4(), + webAppURL: new URL(context.originalUrl), + }; } static parsePagination(context: Context): Page { diff --git a/packages/agent/test/routes/access/api-chart-datasource.test.ts b/packages/agent/test/routes/access/api-chart-datasource.test.ts index 7d8e67e944..a4173d3d89 100644 --- a/packages/agent/test/routes/access/api-chart-datasource.test.ts +++ b/packages/agent/test/routes/access/api-chart-datasource.test.ts @@ -42,7 +42,12 @@ describe('DataSourceApiChartRoute', () => { await route.handleApiChart(context); expect(dataSource.renderChart).toHaveBeenCalledWith( - { email: 'marty@doclabs.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'marty@doclabs.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, 'myChart', ); expect(context.response.body).toMatchObject({ @@ -64,7 +69,12 @@ describe('DataSourceApiChartRoute', () => { await route.handleSmartChart(context); expect(dataSource.renderChart).toHaveBeenCalledWith( - { email: 'marty@doclabs.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'marty@doclabs.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, 'myChart', ); expect(context.response.body).toStrictEqual({ countCurrent: 12 }); diff --git a/packages/agent/test/routes/access/chart.test.ts b/packages/agent/test/routes/access/chart.test.ts index e9eb63f370..9ed8f24304 100644 --- a/packages/agent/test/routes/access/chart.test.ts +++ b/packages/agent/test/routes/access/chart.test.ts @@ -120,7 +120,12 @@ describe('ChartRoute', () => { await chart.handleChart(context); expect(dataSource.getCollection('books').aggregate).toHaveBeenCalledWith( - { ...user, requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + ...user, + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, { conditionTree: null, search: null, searchExtended: false, segment: null }, { field: undefined, groups: undefined, operation: 'Count' }, ); @@ -253,7 +258,12 @@ describe('ChartRoute', () => { expect(dataSource.getCollection('books').aggregate).toHaveBeenCalledTimes(1); expect(dataSource.getCollection('books').aggregate).toHaveBeenCalledWith( - { ...user, requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + ...user, + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, { conditionTree: { field: 'name', operator: 'Present', value: null }, search: null, @@ -303,6 +313,7 @@ describe('ChartRoute', () => { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', }, { conditionTree: { @@ -387,7 +398,12 @@ describe('ChartRoute', () => { await chart.handleChart(context); expect(dataSource.getCollection('books').aggregate).toHaveBeenCalledWith( - { ...user, requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + ...user, + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, { conditionTree: null, search: null, searchExtended: false, segment: null }, { field: undefined, groups: undefined, operation: 'Count' }, ); @@ -428,7 +444,12 @@ describe('ChartRoute', () => { await chart.handleChart(context); expect(dataSource.getCollection('books').aggregate).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, { conditionTree: { field: 'title', operator: 'NotContains', value: '[test]' }, search: null, @@ -472,7 +493,12 @@ describe('ChartRoute', () => { await chart.handleChart(context); expect(dataSource.getCollection('books').aggregate).toHaveBeenCalledWith( - { ...user, requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + ...user, + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, { conditionTree: null, search: null, searchExtended: false, segment: null }, { field: undefined, groups: [{ field: 'author:firstName' }], operation: 'Count' }, ); @@ -524,7 +550,12 @@ describe('ChartRoute', () => { await chart.handleChart(context); expect(dataSource.getCollection('books').aggregate).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, { conditionTree: { field: 'title', operator: 'NotContains', value: '[test]' }, search: null, @@ -578,7 +609,12 @@ describe('ChartRoute', () => { await chart.handleChart(context); expect(dataSource.getCollection('books').aggregate).toHaveBeenCalledWith( - { ...user, requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + ...user, + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, { conditionTree: factories.conditionTreeLeaf.build({ operator: 'Present', @@ -643,7 +679,12 @@ describe('ChartRoute', () => { await chart.handleChart(context); expect(dataSource.getCollection('books').aggregate).toHaveBeenCalledWith( - { ...user, requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + ...user, + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, { conditionTree: factories.conditionTreeBranch.build({ aggregator: 'And', @@ -717,7 +758,12 @@ describe('ChartRoute', () => { await chart.handleChart(context); expect(dataSource.getCollection('books').aggregate).toHaveBeenCalledWith( - { ...user, requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + ...user, + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, { conditionTree: null, search: null, searchExtended: false, segment: null }, { field: 'id', groups: [{ field: 'author:id' }], operation: 'Sum' }, 2, @@ -763,7 +809,12 @@ describe('ChartRoute', () => { await chart.handleChart(context); expect(dataSource.getCollection('books').aggregate).toHaveBeenCalledWith( - { ...user, requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + ...user, + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, { conditionTree: null, search: null, searchExtended: false, segment: null }, { operation: 'Count', field: null, groups: [{ field: 'publisher:id' }] }, 2, @@ -816,7 +867,12 @@ describe('ChartRoute', () => { await chart.handleChart(context); expect(dataSource.getCollection('books').aggregate).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, { conditionTree: { field: 'author:name', @@ -873,7 +929,12 @@ describe('ChartRoute', () => { await chart.handleChart(context); expect(dataSource.getCollection('books').aggregate).toHaveBeenCalledWith( - { ...user, requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + ...user, + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, { conditionTree: null, search: null, searchExtended: false, segment: null }, { groups: [{ field: 'author:id' }], operation: 'Count' }, 2, diff --git a/packages/agent/test/routes/access/count-related.test.ts b/packages/agent/test/routes/access/count-related.test.ts index 970cbe7cdf..a34d5c2605 100644 --- a/packages/agent/test/routes/access/count-related.test.ts +++ b/packages/agent/test/routes/access/count-related.test.ts @@ -124,7 +124,12 @@ describe('CountRelatedRoute', () => { dataSource.getCollection('books'), ['2d162303-78bf-599e-b197-93590ac3d315'], 'myBookPersons', - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, new Filter({ search: 'searched argument', searchExtended: false, @@ -223,7 +228,12 @@ describe('CountRelatedRoute', () => { dataSource.getCollection('books'), ['2d162303-78bf-599e-b197-93590ac3d315'], 'myBookPersons', - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, new Filter({ search: 'searched argument', searchExtended: false, diff --git a/packages/agent/test/routes/access/count.test.ts b/packages/agent/test/routes/access/count.test.ts index 8e43ea8c59..cf38c14b3f 100644 --- a/packages/agent/test/routes/access/count.test.ts +++ b/packages/agent/test/routes/access/count.test.ts @@ -33,7 +33,12 @@ describe('CountRoute', () => { await count.handleCount(context); expect(aggregateSpy).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, { conditionTree: null, search: null, searchExtended: false, segment: null }, { operation: 'Count' }, ); @@ -75,7 +80,12 @@ describe('CountRoute', () => { await count.handleCount(context); expect(aggregateSpy).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, { conditionTree: { field: 'title', diff --git a/packages/agent/test/routes/access/csv-related.test.ts b/packages/agent/test/routes/access/csv-related.test.ts index 31bdcd3e78..526a23c539 100644 --- a/packages/agent/test/routes/access/csv-related.test.ts +++ b/packages/agent/test/routes/access/csv-related.test.ts @@ -122,7 +122,12 @@ describe('CsvRelatedRoute', () => { await readCsv(context.response.body as AsyncGenerator); expect(csvGenerator).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, new Projection('id', 'name'), 'id,name', paginatedFilter, @@ -216,7 +221,12 @@ describe('CsvRelatedRoute', () => { await readCsv(context.response.body as AsyncGenerator); expect(csvGenerator).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, new Projection('id', 'name'), 'id,name', paginatedFilter, diff --git a/packages/agent/test/routes/access/csv.test.ts b/packages/agent/test/routes/access/csv.test.ts index ba7988acc8..e729293f0e 100644 --- a/packages/agent/test/routes/access/csv.test.ts +++ b/packages/agent/test/routes/access/csv.test.ts @@ -91,7 +91,12 @@ describe('CsvRoute', () => { await readCsv(context.response.body as AsyncGenerator); expect(csvGenerator).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, ['id', 'name'], 'id,name', paginatedFilter, diff --git a/packages/agent/test/routes/access/get.test.ts b/packages/agent/test/routes/access/get.test.ts index 5b41953bc3..3579751aa5 100644 --- a/packages/agent/test/routes/access/get.test.ts +++ b/packages/agent/test/routes/access/get.test.ts @@ -69,7 +69,12 @@ describe('GetRoute', () => { await get.handleGet(context); expect(dataSource.getCollection('books').list).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, { conditionTree: { field: 'id', @@ -134,7 +139,12 @@ describe('GetRoute', () => { ); expect(dataSource.getCollection('books').list).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, new PaginatedFilter({ conditionTree: ConditionTreeFactory.fromPlainObject({ aggregator: 'And', diff --git a/packages/agent/test/routes/access/list-related.test.ts b/packages/agent/test/routes/access/list-related.test.ts index 12578dba0f..044361dbe1 100644 --- a/packages/agent/test/routes/access/list-related.test.ts +++ b/packages/agent/test/routes/access/list-related.test.ts @@ -103,7 +103,12 @@ describe('ListRelatedRoute', () => { dataSource.getCollection('books'), ['2d162303-78bf-599e-b197-93590ac3d315'], 'myPersons', - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, new PaginatedFilter({ search: 'aName', searchExtended: false, @@ -208,7 +213,12 @@ describe('ListRelatedRoute', () => { dataSource.getCollection('books'), ['2d162303-78bf-599e-b197-93590ac3d315'], 'myPersons', - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, new PaginatedFilter({ search: 'aName', searchExtended: false, diff --git a/packages/agent/test/routes/access/list.test.ts b/packages/agent/test/routes/access/list.test.ts index bdb437a0d1..eff208b93c 100644 --- a/packages/agent/test/routes/access/list.test.ts +++ b/packages/agent/test/routes/access/list.test.ts @@ -50,7 +50,12 @@ describe('ListRoute', () => { // then expect(collection.list).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com', + }, { conditionTree: null, search: '2', @@ -113,7 +118,12 @@ describe('ListRoute', () => { // then expect(collection.list).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com', + }, { conditionTree: { field: 'title', diff --git a/packages/agent/test/routes/modification/action/action.test.ts b/packages/agent/test/routes/modification/action/action.test.ts index fdb763db1d..213b34a3cb 100644 --- a/packages/agent/test/routes/modification/action/action.test.ts +++ b/packages/agent/test/routes/modification/action/action.test.ts @@ -306,6 +306,7 @@ describe('ActionRoute', () => { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', }, 'MySingleAction', { firstname: 'John' }, @@ -526,6 +527,7 @@ describe('ActionRoute', () => { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', }, 'MySingleAction', null, @@ -572,6 +574,7 @@ describe('ActionRoute', () => { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', }, 'MySingleAction', { firstname: 'John' }, @@ -641,6 +644,7 @@ describe('ActionRoute', () => { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', }, 'MyBulkAction', { firstname: 'John' }, @@ -700,6 +704,7 @@ describe('ActionRoute', () => { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', }, 'MyGlobalAction', expect.any(Object), @@ -772,6 +777,7 @@ describe('ActionRoute', () => { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', }, 'MySingleAction', expect.any(Object), @@ -858,6 +864,7 @@ describe('ActionRoute', () => { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', }, 'MyBulkAction', expect.any(Object), diff --git a/packages/agent/test/routes/modification/associate-related.test.ts b/packages/agent/test/routes/modification/associate-related.test.ts index a3a36dceb5..ec91b5e9c7 100644 --- a/packages/agent/test/routes/modification/associate-related.test.ts +++ b/packages/agent/test/routes/modification/associate-related.test.ts @@ -87,7 +87,12 @@ describe('AssociateRelatedRoute', () => { // then expect(dataSource.getCollection('bookPersons').update).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, new Filter({ conditionTree: factories.conditionTreeBranch.build({ aggregator: 'And', @@ -207,7 +212,12 @@ describe('AssociateRelatedRoute', () => { // then expect(dataSource.getCollection('librariesBooks').create).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, [ { bookId: '123e4567-e89b-12d3-a456-111111111111', diff --git a/packages/agent/test/routes/modification/create.test.ts b/packages/agent/test/routes/modification/create.test.ts index a74a532b33..8a8be26c25 100644 --- a/packages/agent/test/routes/modification/create.test.ts +++ b/packages/agent/test/routes/modification/create.test.ts @@ -63,7 +63,12 @@ describe('CreateRoute', () => { await create.handleCreate(context); expect(collection.create).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, [attributes], ); @@ -149,6 +154,7 @@ describe('CreateRoute', () => { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', }, new Filter({ conditionTree: new ConditionTreeLeaf('personId', 'Equal', 1) }), { personId: null }, @@ -247,7 +253,12 @@ describe('CreateRoute', () => { await create.handleCreate(context); expect(dataSource.getCollection('passports').create).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, [{ personId: '1d162304-78bf-599e-b197-000000000000' }], ); diff --git a/packages/agent/test/routes/modification/delete-related.test.ts b/packages/agent/test/routes/modification/delete-related.test.ts index b7f6164c4b..845ac22bfe 100644 --- a/packages/agent/test/routes/modification/delete-related.test.ts +++ b/packages/agent/test/routes/modification/delete-related.test.ts @@ -73,7 +73,12 @@ describe('DissociateDeleteRelatedRoute > delete', () => { await count.handleDissociateDeleteRelatedRoute(context); expect(dataSource.getCollection('bookPersons').delete).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, new Filter({ conditionTree: factories.conditionTreeBranch.build({ aggregator: 'And', @@ -135,7 +140,12 @@ describe('DissociateDeleteRelatedRoute > delete', () => { await count.handleDissociateDeleteRelatedRoute(context); expect(dataSource.getCollection('bookPersons').delete).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, new Filter({ conditionTree: factories.conditionTreeBranch.build({ aggregator: 'And', @@ -193,6 +203,7 @@ describe('DissociateDeleteRelatedRoute > delete', () => { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', }, new Filter({ conditionTree: factories.conditionTreeLeaf.build({ @@ -310,7 +321,12 @@ describe('DissociateDeleteRelatedRoute > delete', () => { await count.handleDissociateDeleteRelatedRoute(context); expect(dataSource.getCollection('librariesBooks').delete).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, new Filter({ conditionTree: factories.conditionTreeBranch.build({ aggregator: 'And', @@ -413,7 +429,12 @@ describe('DissociateDeleteRelatedRoute > delete', () => { await count.handleDissociateDeleteRelatedRoute(context); expect(dataSource.getCollection('librariesBooks').delete).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, new Filter({ conditionTree: factories.conditionTreeBranch.build({ aggregator: 'And', @@ -511,6 +532,7 @@ describe('DissociateDeleteRelatedRoute > delete', () => { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', }, new Filter({ conditionTree: factories.conditionTreeBranch.build({ diff --git a/packages/agent/test/routes/modification/delete.test.ts b/packages/agent/test/routes/modification/delete.test.ts index 53aea0fbe7..22e970737c 100644 --- a/packages/agent/test/routes/modification/delete.test.ts +++ b/packages/agent/test/routes/modification/delete.test.ts @@ -49,7 +49,12 @@ describe('DeleteRoute', () => { expect(services.authorization.assertCanDelete).toHaveBeenCalledWith(context, 'books'); expect(bookCollection.delete).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, factories.filter.build({ conditionTree: factories.conditionTreeBranch.build({ aggregator: 'And', @@ -111,7 +116,12 @@ describe('DeleteRoute', () => { await deleteRoute.handleDelete(context); expect(bookCollection.delete).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, factories.filter.build({ conditionTree: factories.conditionTreeBranch.build({ aggregator: 'And', @@ -172,7 +182,12 @@ describe('DeleteRoute', () => { expect(services.authorization.assertCanDelete).toHaveBeenCalledWith(context, 'books'); expect(bookCollection.delete).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, factories.filter.build({ conditionTree: factories.conditionTreeLeaf.build({ operator: 'Equal', @@ -224,7 +239,12 @@ describe('DeleteRoute', () => { expect(services.authorization.assertCanDelete).toHaveBeenCalledWith(context, 'books'); expect(bookCollection.delete).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, factories.filter.build({ conditionTree: factories.conditionTreeLeaf.build({ operator: 'In', @@ -274,6 +294,7 @@ describe('DeleteRoute', () => { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', }, factories.filter.build({ conditionTree: factories.conditionTreeLeaf.build({ @@ -321,7 +342,12 @@ describe('DeleteRoute', () => { expect(services.authorization.assertCanDelete).toHaveBeenCalledWith(context, 'books'); expect(bookCollection.delete).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, factories.filter.build({ conditionTree: factories.conditionTreeBranch.build({ aggregator: 'Or', @@ -404,6 +430,7 @@ describe('DeleteRoute', () => { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', }, factories.filter.build({ conditionTree: factories.conditionTreeBranch.build({ diff --git a/packages/agent/test/routes/modification/dissociate-delete-related.test.ts b/packages/agent/test/routes/modification/dissociate-delete-related.test.ts index d81c80ca86..15c935264c 100644 --- a/packages/agent/test/routes/modification/dissociate-delete-related.test.ts +++ b/packages/agent/test/routes/modification/dissociate-delete-related.test.ts @@ -202,7 +202,12 @@ describe('DissociateDeleteRelatedRoute', () => { await count.handleDissociateDeleteRelatedRoute(context); expect(dataSource.getCollection('bookPersons').update).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, new Filter({ conditionTree: factories.conditionTreeBranch.build({ aggregator: 'And', diff --git a/packages/agent/test/routes/modification/dissociate-related.test.ts b/packages/agent/test/routes/modification/dissociate-related.test.ts index 93ae411675..8820dad036 100644 --- a/packages/agent/test/routes/modification/dissociate-related.test.ts +++ b/packages/agent/test/routes/modification/dissociate-related.test.ts @@ -76,7 +76,12 @@ describe('DissociateDeleteRelatedRoute > dissociate', () => { await count.handleDissociateDeleteRelatedRoute(context); expect(dataSource.getCollection('bookPersons').update).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, new PaginatedFilter({ conditionTree: factories.conditionTreeBranch.build({ aggregator: 'And', @@ -141,7 +146,12 @@ describe('DissociateDeleteRelatedRoute > dissociate', () => { await count.handleDissociateDeleteRelatedRoute(context); expect(dataSource.getCollection('bookPersons').update).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, new PaginatedFilter({ conditionTree: factories.conditionTreeBranch.build({ aggregator: 'And', @@ -207,6 +217,7 @@ describe('DissociateDeleteRelatedRoute > dissociate', () => { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', }, new PaginatedFilter({ conditionTree: factories.conditionTreeLeaf.build({ @@ -328,7 +339,12 @@ describe('DissociateDeleteRelatedRoute > dissociate', () => { await count.handleDissociateDeleteRelatedRoute(context); expect(dataSource.getCollection('librariesBooks').delete).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, new Filter({ conditionTree: factories.conditionTreeBranch.build({ aggregator: 'And', @@ -392,7 +408,12 @@ describe('DissociateDeleteRelatedRoute > dissociate', () => { await count.handleDissociateDeleteRelatedRoute(context); expect(dataSource.getCollection('librariesBooks').delete).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, new Filter({ conditionTree: factories.conditionTreeBranch.build({ aggregator: 'And', @@ -457,6 +478,7 @@ describe('DissociateDeleteRelatedRoute > dissociate', () => { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', }, new Filter({ conditionTree: factories.conditionTreeBranch.build({ diff --git a/packages/agent/test/routes/modification/update-field.test.ts b/packages/agent/test/routes/modification/update-field.test.ts index 569fd64c4d..2fe1a0f09a 100644 --- a/packages/agent/test/routes/modification/update-field.test.ts +++ b/packages/agent/test/routes/modification/update-field.test.ts @@ -119,7 +119,12 @@ describe('UpdateField', () => { }); expect(dataSource.getCollection('books').list).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, expectedFilter, new Projection('itemList'), ); @@ -175,7 +180,12 @@ describe('UpdateField', () => { }); expect(dataSource.getCollection('books').list).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, expectedFilter, new Projection('itemList'), ); diff --git a/packages/agent/test/routes/modification/update-relation.test.ts b/packages/agent/test/routes/modification/update-relation.test.ts index 64beaccc4d..8dc390b1eb 100644 --- a/packages/agent/test/routes/modification/update-relation.test.ts +++ b/packages/agent/test/routes/modification/update-relation.test.ts @@ -90,7 +90,12 @@ describe('UpdateRelationRoute', () => { await update.handleUpdateRelationRoute(context); expect(dataSource.getCollection('books').update).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, new Filter({ conditionTree: factories.conditionTreeBranch.build({ aggregator: 'And', @@ -132,7 +137,12 @@ describe('UpdateRelationRoute', () => { await update.handleUpdateRelationRoute(context); expect(dataSource.getCollection('books').update).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, new Filter({ conditionTree: factories.conditionTreeBranch.build({ aggregator: 'And', @@ -222,6 +232,7 @@ describe('UpdateRelationRoute', () => { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', }; expect(owners.aggregate).toHaveBeenCalledWith( @@ -279,6 +290,7 @@ describe('UpdateRelationRoute', () => { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', }; expect(owners.aggregate).toHaveBeenCalledWith( @@ -349,6 +361,7 @@ describe('UpdateRelationRoute', () => { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', }; expect(owners.aggregate).toHaveBeenCalledWith( diff --git a/packages/agent/test/routes/modification/update.test.ts b/packages/agent/test/routes/modification/update.test.ts index ff666fc71f..57c0a6f0e6 100644 --- a/packages/agent/test/routes/modification/update.test.ts +++ b/packages/agent/test/routes/modification/update.test.ts @@ -66,7 +66,12 @@ describe('UpdateRoute', () => { }); expect(bookCollection.update).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, expectedFilter, { name: 'foo name' }, ); @@ -129,12 +134,22 @@ describe('UpdateRoute', () => { }); expect(bookCollection.update).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, expectedFilter, { name: 'foo name' }, ); expect(bookCollection.list).toHaveBeenCalledWith( - { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'Europe/Paris' }, + { + email: 'john.doe@domain.com', + requestId: expect.any(String), + timezone: 'Europe/Paris', + webAppURL: 'http://test.com/', + }, expectedFilter, new Projection('id', 'name'), ); diff --git a/packages/agent/test/utils/query-string.test.ts b/packages/agent/test/utils/query-string.test.ts index bd4159e6ad..1ca78fd885 100644 --- a/packages/agent/test/utils/query-string.test.ts +++ b/packages/agent/test/utils/query-string.test.ts @@ -386,7 +386,7 @@ describe('QueryStringParser', () => { }); describe('parseCaller', () => { - test('should return the timezone and the user', () => { + test('should return the timezone, the user and the current URL', () => { const context = createMockContext({ state: { user: { email: 'john.doe@domain.com' } }, customProperties: { query: { timezone: 'America/Los_Angeles' } }, @@ -396,6 +396,7 @@ describe('QueryStringParser', () => { email: 'john.doe@domain.com', requestId: expect.any(String), timezone: 'America/Los_Angeles', + webAppURL: 'http://test.com/', }); }); diff --git a/packages/datasource-replica/src/cache-interface/datasource.ts b/packages/datasource-replica/src/cache-interface/datasource.ts index b9d301deef..33968dcc88 100644 --- a/packages/datasource-replica/src/cache-interface/datasource.ts +++ b/packages/datasource-replica/src/cache-interface/datasource.ts @@ -16,6 +16,7 @@ export default class CacheDataSourceInterface { team: 'system', timezone: 'UTC', requestId: '', + webAppURL: new URL('https://app.forestadmin.com/aProject/anEnvironment/aRendering'), }; constructor(dataSource: DataSource) { diff --git a/packages/datasource-toolkit/src/interfaces/caller.ts b/packages/datasource-toolkit/src/interfaces/caller.ts index 8621a90265..8a40189300 100644 --- a/packages/datasource-toolkit/src/interfaces/caller.ts +++ b/packages/datasource-toolkit/src/interfaces/caller.ts @@ -9,4 +9,5 @@ export type Caller = { role: string; tags: { [key: string]: string }; timezone: string; + webAppURL: URL; }; diff --git a/packages/datasource-toolkit/test/__factories__/caller.ts b/packages/datasource-toolkit/test/__factories__/caller.ts index 35141bcbf2..710906db7d 100644 --- a/packages/datasource-toolkit/test/__factories__/caller.ts +++ b/packages/datasource-toolkit/test/__factories__/caller.ts @@ -13,4 +13,5 @@ export default Factory.define(() => ({ tags: {}, team: 'team', timezone: 'Europe/Paris', + webAppURL: new URL('https://app.forestadmin.com/aProject/anEnvironment/aRendering'), }));