arocapi 5.0.0-beta.2 → 5.0.0-beta.3

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.
Files changed (117) hide show
  1. package/README.md +37 -824
  2. package/dist/app.d.ts +20 -7
  3. package/dist/app.js +42 -28
  4. package/dist/app.js.map +1 -1
  5. package/dist/app.test.js +41 -56
  6. package/dist/app.test.js.map +1 -1
  7. package/dist/errorHandling.test.d.ts +1 -0
  8. package/dist/errorHandling.test.js +222 -0
  9. package/dist/errorHandling.test.js.map +1 -0
  10. package/dist/index.dev.js +4 -3
  11. package/dist/index.dev.js.map +1 -1
  12. package/dist/routes/capabilities.test.js +8 -8
  13. package/dist/routes/capabilities.test.js.map +1 -1
  14. package/dist/routes/crate.test.js +67 -19
  15. package/dist/routes/crate.test.js.map +1 -1
  16. package/dist/routes/entities.d.ts +5 -2
  17. package/dist/routes/entities.js +31 -49
  18. package/dist/routes/entities.js.map +1 -1
  19. package/dist/routes/entities.test.js +16 -12
  20. package/dist/routes/entities.test.js.map +1 -1
  21. package/dist/routes/entity.d.ts +7 -2
  22. package/dist/routes/entity.js +14 -29
  23. package/dist/routes/entity.js.map +1 -1
  24. package/dist/routes/entity.test.js +19 -13
  25. package/dist/routes/entity.test.js.map +1 -1
  26. package/dist/routes/file.d.ts +6 -0
  27. package/dist/routes/file.js +67 -59
  28. package/dist/routes/file.js.map +1 -1
  29. package/dist/routes/file.test.js +99 -22
  30. package/dist/routes/file.test.js.map +1 -1
  31. package/dist/routes/files.d.ts +5 -2
  32. package/dist/routes/files.js +24 -39
  33. package/dist/routes/files.js.map +1 -1
  34. package/dist/routes/files.test.js +44 -21
  35. package/dist/routes/files.test.js.map +1 -1
  36. package/dist/routes/metadata.d.ts +6 -0
  37. package/dist/routes/metadata.js +49 -54
  38. package/dist/routes/metadata.js.map +1 -1
  39. package/dist/routes/search.d.ts +6 -2
  40. package/dist/routes/search.js +95 -99
  41. package/dist/routes/search.js.map +1 -1
  42. package/dist/routes/search.test.js +85 -39
  43. package/dist/routes/search.test.js.map +1 -1
  44. package/dist/test/helpers/fastify.js +2 -3
  45. package/dist/test/helpers/fastify.js.map +1 -1
  46. package/dist/test/integration.setup.d.ts +18 -0
  47. package/dist/test/integration.setup.js +15 -7
  48. package/dist/test/integration.setup.js.map +1 -1
  49. package/dist/test/integration.test.js +368 -2
  50. package/dist/test/integration.test.js.map +1 -1
  51. package/dist/transformers/default.d.ts +10 -18
  52. package/dist/transformers/default.js +41 -15
  53. package/dist/transformers/default.js.map +1 -1
  54. package/dist/transformers/default.test.js +109 -47
  55. package/dist/transformers/default.test.js.map +1 -1
  56. package/dist/transformers/transformer.test.js +12 -34
  57. package/dist/transformers/transformer.test.js.map +1 -1
  58. package/dist/types/access.d.ts +9 -0
  59. package/dist/types/access.js +2 -0
  60. package/dist/types/access.js.map +1 -0
  61. package/dist/types/context.d.ts +6 -0
  62. package/dist/types/context.js +2 -0
  63. package/dist/types/context.js.map +1 -0
  64. package/dist/types/fileHandlers.d.ts +5 -9
  65. package/dist/types/transformers.d.ts +4 -10
  66. package/dist/types/visibility.d.ts +5 -0
  67. package/dist/types/visibility.js +2 -0
  68. package/dist/types/visibility.js.map +1 -0
  69. package/dist/utils/access.d.ts +17 -0
  70. package/dist/utils/access.js +41 -0
  71. package/dist/utils/access.js.map +1 -0
  72. package/dist/utils/errors.d.ts +13 -4
  73. package/dist/utils/errors.js +44 -8
  74. package/dist/utils/errors.js.map +1 -1
  75. package/dist/utils/errors.test.js +14 -1
  76. package/dist/utils/errors.test.js.map +1 -1
  77. package/dist/utils/validation.d.ts +2 -0
  78. package/dist/utils/validation.js +8 -0
  79. package/dist/utils/validation.js.map +1 -0
  80. package/dist/utils/visibility.d.ts +18 -0
  81. package/dist/utils/visibility.js +16 -0
  82. package/dist/utils/visibility.js.map +1 -0
  83. package/package.json +5 -4
  84. package/src/app.test.ts +45 -66
  85. package/src/app.ts +85 -54
  86. package/src/errorHandling.test.ts +288 -0
  87. package/src/index.dev.ts +6 -4
  88. package/src/routes/__snapshots__/search.test.ts.snap +2 -2
  89. package/src/routes/capabilities.test.ts +8 -8
  90. package/src/routes/crate.test.ts +80 -19
  91. package/src/routes/entities.test.ts +16 -12
  92. package/src/routes/entities.ts +40 -59
  93. package/src/routes/entity.test.ts +19 -13
  94. package/src/routes/entity.ts +22 -35
  95. package/src/routes/file.test.ts +117 -22
  96. package/src/routes/file.ts +84 -62
  97. package/src/routes/files.test.ts +52 -26
  98. package/src/routes/files.ts +31 -47
  99. package/src/routes/metadata.ts +64 -58
  100. package/src/routes/search.test.ts +88 -39
  101. package/src/routes/search.ts +123 -119
  102. package/src/test/helpers/fastify.ts +2 -3
  103. package/src/test/integration.setup.ts +18 -7
  104. package/src/test/integration.test.ts +472 -1
  105. package/src/transformers/default.test.ts +139 -47
  106. package/src/transformers/default.ts +103 -83
  107. package/src/transformers/transformer.test.ts +18 -44
  108. package/src/types/access.ts +20 -0
  109. package/src/types/context.ts +15 -0
  110. package/src/types/fileHandlers.ts +5 -13
  111. package/src/types/transformers.ts +4 -32
  112. package/src/types/visibility.ts +18 -0
  113. package/src/utils/access.ts +80 -0
  114. package/src/utils/errors.test.ts +16 -1
  115. package/src/utils/errors.ts +67 -10
  116. package/src/utils/validation.ts +11 -0
  117. package/src/utils/visibility.ts +56 -0
@@ -2,9 +2,10 @@ import type { FastifyPluginAsync } from 'fastify';
2
2
  import type { ZodTypeProvider } from 'fastify-type-provider-zod';
3
3
  import { z } from 'zod';
4
4
  import type { PrismaClient } from '../generated/prisma/client.js';
5
- import { baseFileTransformer } from '../transformers/default.js';
6
- import type { FileAccessTransformer, FileTransformer } from '../types/transformers.js';
7
- import { createInternalError } from '../utils/errors.js';
5
+ import { applyTransformers, authoriseFiles } from '../transformers/default.js';
6
+ import type { AccessFunction } from '../types/access.js';
7
+ import type { FileTransformer } from '../types/transformers.js';
8
+ import type { EntityVisibilityFilter } from '../types/visibility.js';
8
9
 
9
10
  const querySchema = z.object({
10
11
  memberOf: z.url().optional(),
@@ -16,12 +17,13 @@ const querySchema = z.object({
16
17
 
17
18
  type FilesRouteOptions = {
18
19
  prisma: PrismaClient;
19
- fileAccessTransformer: FileAccessTransformer;
20
+ access: AccessFunction;
20
21
  fileTransformers?: FileTransformer[];
22
+ entityVisibilityFilter: EntityVisibilityFilter;
21
23
  };
22
24
 
23
25
  const files: FastifyPluginAsync<FilesRouteOptions> = async (fastify, opts) => {
24
- const { prisma, fileAccessTransformer, fileTransformers = [] } = opts;
26
+ const { prisma, access, fileTransformers = [], entityVisibilityFilter } = opts;
25
27
 
26
28
  fastify.withTypeProvider<ZodTypeProvider>().get(
27
29
  '/files',
@@ -30,53 +32,35 @@ const files: FastifyPluginAsync<FilesRouteOptions> = async (fastify, opts) => {
30
32
  querystring: querySchema,
31
33
  },
32
34
  },
33
- async (request, reply) => {
35
+ async (request) => {
34
36
  const { memberOf, limit, offset, sort, order } = request.query;
35
37
 
36
- try {
37
- const where: NonNullable<Parameters<typeof prisma.file.findMany>[0]>['where'] = {};
38
+ const context = { request, fastify };
39
+ const visibilityWhere = await entityVisibilityFilter(context);
40
+ const where = { entity: { AND: [{ memberOf }, visibilityWhere] } };
38
41
 
39
- if (memberOf) {
40
- where.entity = { memberOf };
41
- }
42
+ const [dbFiles, total] = await Promise.all([
43
+ prisma.file.findMany({
44
+ where,
45
+ include: { entity: { omit: { meta: true } } },
46
+ orderBy: {
47
+ [sort]: order,
48
+ },
49
+ skip: offset,
50
+ take: limit,
51
+ }),
52
+ prisma.file.count({ where }),
53
+ ]);
42
54
 
43
- const [dbFiles, total] = await Promise.all([
44
- prisma.file.findMany({
45
- where,
46
- orderBy: {
47
- [sort]: order,
48
- },
49
- skip: offset,
50
- take: limit,
51
- }),
52
- prisma.file.count({ where }),
53
- ]);
55
+ const authorisedFiles = await authoriseFiles(dbFiles, access, context);
56
+ const filesWithAccess = await Promise.all(
57
+ authorisedFiles.map((file) => applyTransformers(file, fileTransformers, context)),
58
+ );
54
59
 
55
- // Apply transformers to each entity: base -> access -> additional
56
- const filesWithAccess = await Promise.all(
57
- dbFiles.map(async (dbFile) => {
58
- const standardFile = baseFileTransformer(dbFile);
59
- const authorisedFile = await fileAccessTransformer(standardFile, { request, fastify });
60
-
61
- let result = authorisedFile;
62
- for (const transformer of fileTransformers) {
63
- result = await transformer(result, { request, fastify });
64
- }
65
-
66
- return result;
67
- }),
68
- );
69
-
70
- return {
71
- total,
72
- files: filesWithAccess,
73
- };
74
- } catch (error) {
75
- const err = error as Error;
76
- fastify.log.error(`Database error: ${err.message}`);
77
-
78
- return reply.code(500).send(createInternalError());
79
- }
60
+ return {
61
+ total,
62
+ files: filesWithAccess,
63
+ };
80
64
  },
81
65
  );
82
66
  };
@@ -3,9 +3,14 @@ import type { FastifyPluginAsync } from 'fastify';
3
3
  import type { ZodTypeProvider } from 'fastify-type-provider-zod';
4
4
  import { z } from 'zod';
5
5
  import type { PrismaClient } from '../generated/prisma/client.js';
6
+ import type { AccessFunction } from '../types/access.js';
7
+ import type { RequestContext } from '../types/context.js';
6
8
  import type { FileMetadata, RoCrateHandler } from '../types/fileHandlers.js';
7
- import { createInternalError, createNotFoundError } from '../utils/errors.js';
9
+ import type { EntityVisibilityFilter } from '../types/visibility.js';
10
+ import { createAccessGuard } from '../utils/access.js';
11
+ import { createNotFoundError } from '../utils/errors.js';
8
12
  import { setFileHeaders } from '../utils/headers.js';
13
+ import { createEntityNotVisibleResponder, type RefusalOptions } from '../utils/visibility.js';
9
14
 
10
15
  const paramsSchema = z.object({
11
16
  id: z.url(),
@@ -14,10 +19,19 @@ const paramsSchema = z.object({
14
19
  type CrateRouteOptions = {
15
20
  prisma: PrismaClient;
16
21
  roCrateHandler: RoCrateHandler;
22
+ access: AccessFunction;
23
+ entityVisibilityFilter: EntityVisibilityFilter;
24
+ refusal: RefusalOptions;
17
25
  };
18
26
 
19
27
  const crate: FastifyPluginAsync<CrateRouteOptions> = async (fastify, opts) => {
20
- const { prisma, roCrateHandler } = opts;
28
+ const { prisma, roCrateHandler, access, entityVisibilityFilter, refusal } = opts;
29
+
30
+ const findVisibleEntity = async (id: string, context: RequestContext) =>
31
+ prisma.entity.findFirst({ where: { AND: [{ id }, await entityVisibilityFilter(context)] } });
32
+
33
+ const sendEntityNotVisible = createEntityNotVisibleResponder(prisma, refusal);
34
+ const denyMetadata = createAccessGuard({ access, isAuthenticated: refusal.isAuthenticated, level: 'metadata' });
21
35
 
22
36
  fastify.withTypeProvider<ZodTypeProvider>().head(
23
37
  '/entity/:id/metadata',
@@ -29,30 +43,26 @@ const crate: FastifyPluginAsync<CrateRouteOptions> = async (fastify, opts) => {
29
43
  async (request, reply) => {
30
44
  const { id } = request.params;
31
45
 
32
- try {
33
- const entity = await prisma.entity.findUnique({
34
- where: { id },
35
- });
46
+ const context = { request, fastify };
47
+ const entity = await findVisibleEntity(id, context);
36
48
 
37
- if (!entity) {
38
- return reply.code(404).send(createNotFoundError('The requested entity was not found', id));
39
- }
49
+ if (!entity) {
50
+ return sendEntityNotVisible(reply, id, context);
51
+ }
40
52
 
41
- const metadata: FileMetadata | false = await roCrateHandler.head(entity, { request, fastify });
53
+ if (await denyMetadata(reply, entity, context)) {
54
+ return reply;
55
+ }
42
56
 
43
- if (!metadata) {
44
- return reply.code(404).send(createNotFoundError('The requested RO-Crate metadata was not found', id));
45
- }
57
+ const metadata: FileMetadata | false = await roCrateHandler.head(entity, context);
46
58
 
47
- setFileHeaders(reply, metadata);
59
+ if (!metadata) {
60
+ return reply.code(404).send(createNotFoundError('The requested RO-Crate metadata was not found', id));
61
+ }
48
62
 
49
- return reply.code(200).send();
50
- } catch (error) {
51
- const err = error as Error;
52
- fastify.log.error(`RO-Crate metadata retrieval error: ${err}`);
63
+ setFileHeaders(reply, metadata);
53
64
 
54
- return reply.code(500).send(createInternalError());
55
- }
65
+ return reply.code(200).send();
56
66
  },
57
67
  );
58
68
 
@@ -66,56 +76,52 @@ const crate: FastifyPluginAsync<CrateRouteOptions> = async (fastify, opts) => {
66
76
  async (request, reply) => {
67
77
  const { id } = request.params;
68
78
 
69
- try {
70
- const entity = await prisma.entity.findUnique({
71
- where: { id },
72
- });
79
+ const context = { request, fastify };
80
+ const entity = await findVisibleEntity(id, context);
73
81
 
74
- if (!entity) {
75
- return reply.code(404).send(createNotFoundError('The requested entity was not found', id));
76
- }
82
+ if (!entity) {
83
+ return sendEntityNotVisible(reply, id, context);
84
+ }
77
85
 
78
- const result = await roCrateHandler.get(entity, { request, fastify });
86
+ if (await denyMetadata(reply, entity, context)) {
87
+ return reply;
88
+ }
79
89
 
80
- if (!result) {
81
- return reply.code(404).send(createNotFoundError('The requested RO-Crate could not be retrieved', id));
82
- }
90
+ const result = await roCrateHandler.get(entity, context);
83
91
 
84
- if (result.type === 'redirect') {
85
- return reply.code(302).redirect(result.url);
86
- }
92
+ if (!result) {
93
+ return reply.code(404).send(createNotFoundError('The requested RO-Crate could not be retrieved', id));
94
+ }
87
95
 
88
- // Set content type to application/ld+json for RO-Crate
89
- const metadata = {
90
- ...result.metadata,
91
- contentType: 'application/ld+json',
92
- };
96
+ if (result.type === 'redirect') {
97
+ return reply.code(302).redirect(result.url);
98
+ }
93
99
 
94
- setFileHeaders(reply, metadata);
100
+ // Set content type to application/ld+json for RO-Crate
101
+ const metadata = {
102
+ ...result.metadata,
103
+ contentType: 'application/ld+json',
104
+ };
95
105
 
96
- // Handle stream response
97
- if (result.type === 'stream') {
98
- return reply.code(200).send(result.stream);
99
- }
106
+ setFileHeaders(reply, metadata);
100
107
 
101
- if (result.type === 'file') {
102
- if (result.accelPath) {
103
- reply.header('X-Accel-Redirect', result.accelPath);
104
- return reply.code(200).send();
105
- }
108
+ // Handle stream response
109
+ if (result.type === 'stream') {
110
+ return reply.code(200).send(result.stream);
111
+ }
106
112
 
107
- const stream = createReadStream(result.path);
108
- return reply.code(200).send(stream);
113
+ if (result.type === 'file') {
114
+ if (result.accelPath) {
115
+ reply.header('X-Accel-Redirect', result.accelPath);
116
+ return reply.code(200).send();
109
117
  }
110
118
 
111
- // Exhaustiveness check - should never reach here with proper types
112
- throw new Error(`Unexpected RO-Crate result type: ${(result as { type: string }).type}`);
113
- } catch (error) {
114
- const err = error as Error;
115
- fastify.log.error(`RO-Crate retrieval error: ${err.message}`);
116
-
117
- return reply.code(500).send(createInternalError());
119
+ const stream = createReadStream(result.path);
120
+ return reply.code(200).send(stream);
118
121
  }
122
+
123
+ // Exhaustiveness check - should never reach here with proper types
124
+ throw new Error(`Unexpected RO-Crate result type: ${(result as { type: string }).type}`);
119
125
  },
120
126
  );
121
127
  };
@@ -1,18 +1,21 @@
1
1
  import { afterEach, beforeEach, describe, expect, it } from 'vitest';
2
2
 
3
3
  import { fastify, fastifyAfter, fastifyBefore, opensearch, prisma } from '../test/helpers/fastify.js';
4
- import { AllPublicAccessTransformer } from '../transformers/default.js';
4
+ import { AllPublicAccess } from '../utils/access.js';
5
5
  import type { StandardErrorResponse } from '../utils/errors.js';
6
6
  import { OpensearchQueryBuilder } from '../utils/queryBuilder.js';
7
+ import { AllVisibleEntityFilter, AllVisibleSearchFilter } from '../utils/visibility.js';
7
8
  import searchRoute from './search.js';
8
9
 
9
10
  describe('Search Route', () => {
10
11
  beforeEach(async () => {
11
12
  await fastifyBefore();
12
13
  await fastify.register(searchRoute, {
14
+ entityVisibilityFilter: AllVisibleEntityFilter,
15
+ searchVisibilityFilter: AllVisibleSearchFilter,
13
16
  prisma,
14
17
  opensearch,
15
- accessTransformer: AllPublicAccessTransformer,
18
+ access: AllPublicAccess,
16
19
  queryBuilder: new OpensearchQueryBuilder(),
17
20
  });
18
21
  });
@@ -108,9 +111,7 @@ describe('Search Route', () => {
108
111
  // Verify database was queried with correct ids
109
112
  expect(prisma.entity.findMany).toHaveBeenCalledWith({
110
113
  where: {
111
- id: {
112
- in: ['http://example.com/entity/1', 'http://example.com/entity/2'],
113
- },
114
+ AND: [{ id: { in: ['http://example.com/entity/1', 'http://example.com/entity/2'] } }, {}],
114
115
  },
115
116
  include: { file: { select: { id: true } } },
116
117
  });
@@ -120,18 +121,25 @@ describe('Search Route', () => {
120
121
  body: {
121
122
  query: {
122
123
  bool: {
124
+ filter: [{ match_all: {} }],
123
125
  must: [
124
126
  {
125
- multi_match: {
126
- query: 'test',
127
- fields: ['name^2', 'description'],
128
- type: 'best_fields',
129
- fuzziness: 'AUTO',
130
- zero_terms_query: 'all',
127
+ bool: {
128
+ must: [
129
+ {
130
+ multi_match: {
131
+ query: 'test',
132
+ fields: ['name^2', 'description'],
133
+ type: 'best_fields',
134
+ fuzziness: 'AUTO',
135
+ zero_terms_query: 'all',
136
+ },
137
+ },
138
+ ],
139
+ filter: [],
131
140
  },
132
141
  },
133
142
  ],
134
- filter: [],
135
143
  },
136
144
  },
137
145
  aggs: {
@@ -184,16 +192,23 @@ describe('Search Route', () => {
184
192
  body: {
185
193
  query: {
186
194
  bool: {
195
+ filter: [{ match_all: {} }],
187
196
  must: [
188
197
  {
189
- query_string: {
190
- query: 'name:test AND description:entity',
191
- fields: ['name^2', 'description'],
192
- default_operator: 'AND',
198
+ bool: {
199
+ must: [
200
+ {
201
+ query_string: {
202
+ query: 'name:test AND description:entity',
203
+ fields: ['name^2', 'description'],
204
+ default_operator: 'AND',
205
+ },
206
+ },
207
+ ],
208
+ filter: [],
193
209
  },
194
210
  },
195
211
  ],
196
- filter: [],
197
212
  },
198
213
  },
199
214
  aggs: {
@@ -260,11 +275,18 @@ describe('Search Route', () => {
260
275
  expect(opensearch.search).toHaveBeenCalledWith(
261
276
  expect.objectContaining({
262
277
  body: expect.objectContaining({
263
- query: expect.objectContaining({
264
- bool: expect.objectContaining({
265
- filter: expectedFilters,
266
- }),
267
- }),
278
+ query: {
279
+ bool: {
280
+ filter: [{ match_all: {} }],
281
+ must: [
282
+ expect.objectContaining({
283
+ bool: expect.objectContaining({
284
+ filter: expectedFilters,
285
+ }),
286
+ }),
287
+ ],
288
+ },
289
+ },
268
290
  }),
269
291
  }),
270
292
  );
@@ -316,20 +338,27 @@ describe('Search Route', () => {
316
338
  expect(opensearch.search).toHaveBeenCalledWith(
317
339
  expect.objectContaining({
318
340
  body: expect.objectContaining({
319
- query: expect.objectContaining({
320
- bool: expect.objectContaining({
321
- filter: [
322
- {
323
- geo_bounding_box: {
324
- location: {
325
- top_left: { lat: 51.5, lon: 0.0 },
326
- bottom_right: { lat: 51.4, lon: 0.1 },
327
- },
328
- },
329
- },
341
+ query: {
342
+ bool: {
343
+ filter: [{ match_all: {} }],
344
+ must: [
345
+ expect.objectContaining({
346
+ bool: expect.objectContaining({
347
+ filter: [
348
+ {
349
+ geo_bounding_box: {
350
+ location: {
351
+ top_left: { lat: 51.5, lon: 0.0 },
352
+ bottom_right: { lat: 51.4, lon: 0.1 },
353
+ },
354
+ },
355
+ },
356
+ ],
357
+ }),
358
+ }),
330
359
  ],
331
- }),
332
- }),
360
+ },
361
+ },
333
362
  aggs: expect.objectContaining({
334
363
  geohash_grid: {
335
364
  geohash_grid: {
@@ -402,7 +431,7 @@ describe('Search Route', () => {
402
431
 
403
432
  expect(response.statusCode).toBe(422);
404
433
  const body = JSON.parse(response.body) as StandardErrorResponse;
405
- expect(body.error.code).toBe('INVALID_REQUEST');
434
+ expect(body.error.code).toBe('VALIDATION_ERROR');
406
435
  });
407
436
 
408
437
  it('should handle opensearch errors', async () => {
@@ -421,6 +450,24 @@ describe('Search Route', () => {
421
450
  expect(body).toMatchSnapshot();
422
451
  });
423
452
 
453
+ it('should hide opensearch errors with other client statuses behind a generic 500', async () => {
454
+ const opensearchError = Object.assign(new Error('index_not_found_exception: no such index [entities]'), {
455
+ statusCode: 404,
456
+ });
457
+ opensearch.search.mockRejectedValue(opensearchError);
458
+
459
+ const response = await fastify.inject({
460
+ method: 'POST',
461
+ url: '/search',
462
+ payload: {
463
+ query: 'test',
464
+ },
465
+ });
466
+
467
+ expect(response.statusCode).toBe(500);
468
+ expect(response.json()).toEqual({ error: { code: 'INTERNAL_ERROR', message: 'Internal server error' } });
469
+ });
470
+
424
471
  it('should return 422 for malformed opensearch query', async () => {
425
472
  const error = new Error('parsing_exception') as Error & { statusCode: number };
426
473
  error.statusCode = 400;
@@ -436,7 +483,7 @@ describe('Search Route', () => {
436
483
 
437
484
  expect(response.statusCode).toBe(422);
438
485
  const body = JSON.parse(response.body) as StandardErrorResponse;
439
- expect(body.error.code).toBe('INVALID_REQUEST');
486
+ expect(body.error.code).toBe('VALIDATION_ERROR');
440
487
  expect(body.error.message).toBe('parsing_exception');
441
488
  });
442
489
 
@@ -605,7 +652,7 @@ describe('Search Route', () => {
605
652
  expect(response.statusCode).toBe(500);
606
653
  const body = JSON.parse(response.body) as { error: { code: string; message: string } };
607
654
  expect(body.error.code).toBe('INTERNAL_ERROR');
608
- expect(body.error.message).toBe('Search failed');
655
+ expect(body.error.message).toBe('Internal server error');
609
656
  });
610
657
 
611
658
  it('should apply custom entity transformers', async () => {
@@ -617,9 +664,11 @@ describe('Search Route', () => {
617
664
 
618
665
  await fastifyBefore();
619
666
  await fastify.register(searchRoute, {
667
+ entityVisibilityFilter: AllVisibleEntityFilter,
668
+ searchVisibilityFilter: AllVisibleSearchFilter,
620
669
  prisma,
621
670
  opensearch,
622
- accessTransformer: AllPublicAccessTransformer,
671
+ access: AllPublicAccess,
623
672
  entityTransformers: [customTransformer],
624
673
  queryBuilder: new OpensearchQueryBuilder(),
625
674
  });