@owlmeans/server-api 0.1.18-rc.50 → 0.1.18-rc.52
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.
- package/README.md +20 -19
- package/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/server-api/SKILL.md +9 -9
- package/build/server.js +3 -3
- package/build/server.js.map +1 -1
- package/build/utils/context/types.d.ts +13 -0
- package/build/utils/context/types.d.ts.map +1 -0
- package/build/utils/context/types.js +2 -0
- package/build/utils/context/types.js.map +1 -0
- package/build/utils/context.d.ts +3 -3
- package/build/utils/context.d.ts.map +1 -1
- package/build/utils/context.js +5 -2
- package/build/utils/context.js.map +1 -1
- package/build/utils/error/types.d.ts +52 -0
- package/build/utils/error/types.d.ts.map +1 -0
- package/build/utils/error/types.js +2 -0
- package/build/utils/error/types.js.map +1 -0
- package/build/utils/error.d.ts +4 -47
- package/build/utils/error.d.ts.map +1 -1
- package/build/utils/error.js +154 -187
- package/build/utils/error.js.map +1 -1
- package/build/utils/guards.d.ts.map +1 -1
- package/build/utils/guards.js +6 -6
- package/build/utils/guards.js.map +1 -1
- package/build/utils/index.d.ts +4 -1
- package/build/utils/index.d.ts.map +1 -1
- package/build/utils/index.js +1 -1
- package/build/utils/index.js.map +1 -1
- package/build/utils/payload/types.d.ts +18 -0
- package/build/utils/payload/types.d.ts.map +1 -0
- package/build/utils/payload/types.js +2 -0
- package/build/utils/payload/types.js.map +1 -0
- package/build/utils/payload.d.ts +3 -15
- package/build/utils/payload.d.ts.map +1 -1
- package/build/utils/payload.js +40 -60
- package/build/utils/payload.js.map +1 -1
- package/build/utils/schema.d.ts +7 -0
- package/build/utils/schema.d.ts.map +1 -0
- package/build/utils/schema.js +20 -0
- package/build/utils/schema.js.map +1 -0
- package/build/utils/server.js +6 -6
- package/build/utils/server.js.map +1 -1
- package/package.json +12 -12
- package/src/server.ts +3 -3
- package/src/utils/context/types.ts +13 -0
- package/src/utils/context.ts +9 -4
- package/src/utils/error/types.ts +52 -0
- package/src/utils/error.ts +156 -186
- package/src/utils/guards.ts +6 -6
- package/src/utils/index.ts +4 -1
- package/src/utils/payload/types.ts +18 -0
- package/src/utils/payload.ts +41 -63
- package/src/utils/schema.ts +23 -0
- package/src/utils/server.ts +6 -6
- package/tests/error-status.spec.ts +11 -11
|
@@ -4,11 +4,11 @@ import type { FastifyInstance } from 'fastify'
|
|
|
4
4
|
import { AuthForbidden, AuthorizationError, AuthUnknown } from '@owlmeans/auth'
|
|
5
5
|
import { ResilientError, SEPARATOR } from '@owlmeans/error'
|
|
6
6
|
import { provideResponse } from '@owlmeans/entrypoint'
|
|
7
|
-
import {
|
|
7
|
+
import { httpErrorHelper } from '../src/utils/error.js'
|
|
8
8
|
import { INCIDENT_ID_HEADER } from '../src/utils/consts.js'
|
|
9
|
-
import {
|
|
9
|
+
import { payloadHelper } from '../src/utils/payload.js'
|
|
10
10
|
import { AccessError, AuthFailedError } from '../src/errors.js'
|
|
11
|
-
import { DENIAL_KIND_HEADER, ACCESS_DENIED_KIND,
|
|
11
|
+
import { DENIAL_KIND_HEADER, ACCESS_DENIED_KIND, apiStatusHelper } from '@owlmeans/api'
|
|
12
12
|
import {
|
|
13
13
|
MigrationError, MisshapedRecord, RecordExists, RecordUpdateFailed, UnknownRecordError,
|
|
14
14
|
UnsupportedArgumentError, UnsupportedMethodError,
|
|
@@ -159,17 +159,17 @@ let thrown: unknown
|
|
|
159
159
|
beforeAll(async () => {
|
|
160
160
|
server = Fastify()
|
|
161
161
|
server.get('/handle', async (_req, reply) => {
|
|
162
|
-
handleError(thrown as Error, reply)
|
|
162
|
+
httpErrorHelper.handleError(thrown as Error, reply)
|
|
163
163
|
return reply
|
|
164
164
|
})
|
|
165
165
|
server.get('/handle-development', async (_req, reply) => {
|
|
166
|
-
handleError(thrown as Error, reply, 'development')
|
|
166
|
+
httpErrorHelper.handleError(thrown as Error, reply, 'development')
|
|
167
167
|
return reply
|
|
168
168
|
})
|
|
169
169
|
server.get('/execute', async (_req, reply) => {
|
|
170
170
|
const response = provideResponse(reply)
|
|
171
171
|
response.reject(thrown as Error)
|
|
172
|
-
executeResponse(response, reply)
|
|
172
|
+
payloadHelper.executeResponse(response, reply)
|
|
173
173
|
return reply
|
|
174
174
|
})
|
|
175
175
|
await server.ready()
|
|
@@ -213,8 +213,8 @@ describe('@owlmeans/server-api — production error exposure', () => {
|
|
|
213
213
|
expect(syntax.body).toBe(syntax.incidentId)
|
|
214
214
|
expect(syntax.body).not.toContain('bad wiring')
|
|
215
215
|
|
|
216
|
-
expect(errorExposure()).toBe('production')
|
|
217
|
-
expect(errorExposure({ http: { errors: { exposure: 'development' } } })).toBe('development')
|
|
216
|
+
expect(httpErrorHelper.errorExposure()).toBe('production')
|
|
217
|
+
expect(httpErrorHelper.errorExposure({ http: { errors: { exposure: 'development' } } })).toBe('development')
|
|
218
218
|
})
|
|
219
219
|
})
|
|
220
220
|
|
|
@@ -284,13 +284,13 @@ describe('@owlmeans/server-api — auth status across a rebuild and duplicate mo
|
|
|
284
284
|
test('an AuthFailedError answers 401 as thrown and after a marshal round trip', async () => {
|
|
285
285
|
expect((await answer(new AuthFailedError())).status).toBe(401)
|
|
286
286
|
expect((await answer(ResilientError.marshal(new AuthFailedError()))).status).toBe(401)
|
|
287
|
-
expect(errorStatus(ResilientError.ensure(ResilientError.marshal(new AuthFailedError())))).toBe(401)
|
|
287
|
+
expect(httpErrorHelper.errorStatus(ResilientError.ensure(ResilientError.marshal(new AuthFailedError())))).toBe(401)
|
|
288
288
|
expect((await answer(new AuthFailedError(), '/execute')).status).toBe(401)
|
|
289
289
|
})
|
|
290
290
|
|
|
291
291
|
test('a class from another module copy answers by its registered type name', async () => {
|
|
292
292
|
// The rebuild alone loses it — the regression this resolution exists for.
|
|
293
|
-
expect(errorStatus(ResilientError.ensure(new ForeignAuthFailedError()))).toBe(500)
|
|
293
|
+
expect(httpErrorHelper.errorStatus(ResilientError.ensure(new ForeignAuthFailedError()))).toBe(500)
|
|
294
294
|
expect((await answer(new ForeignAuthFailedError())).status).toBe(401)
|
|
295
295
|
expect((await answer(new ForeignAuthorizationError())).status).toBe(401)
|
|
296
296
|
expect((await answer(new ForeignAuthForbidden())).status).toBe(403)
|
|
@@ -334,7 +334,7 @@ describe('@owlmeans/server-api — storage refusals of @owlmeans/resource', () =
|
|
|
334
334
|
const rebuilt = Object.assign(ResilientError.ensure(response.body, true), { responseStatus: response.status })
|
|
335
335
|
expect(rebuilt.constructor).toBe(error.constructor)
|
|
336
336
|
expect(rebuilt.message).toBe(error.message)
|
|
337
|
-
expect(httpStatusOf(rebuilt)).toBe(status)
|
|
337
|
+
expect(apiStatusHelper.httpStatusOf(rebuilt)).toBe(status)
|
|
338
338
|
}
|
|
339
339
|
const rebuilt = ResilientError.ensure((await answer(new UnknownRecordError('shelf/3'), '/handle-development')).body, true)
|
|
340
340
|
expect((rebuilt as UnknownRecordError).id).toBe('shelf/3')
|