@owlmeans/server-api 0.1.18-rc.43 → 0.1.18-rc.45

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 CHANGED
@@ -10,7 +10,7 @@ only when composing a context without that package. WebSocket routes belong to
10
10
  ## Installation
11
11
 
12
12
  ```bash
13
- bun add @owlmeans/server-api@^0.1.18-rc.43
13
+ bun add @owlmeans/server-api@^0.1.18-rc.45
14
14
  ```
15
15
 
16
16
  ## Concepts
@@ -240,7 +240,7 @@ This package ships embedded agent skills under `agent-meta/`. After installing y
240
240
  your project's skill store (`.agents/skills/`):
241
241
 
242
242
  ```sh
243
- npx @owlmeans/agent-skills@^0.1.18-rc.40
243
+ npx @owlmeans/agent-skills@^0.1.18-rc.42
244
244
  ```
245
245
 
246
246
  The embedded files are version-matched to this package release. Do not edit them
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "schemaVersion": 2,
3
3
  "package": "@owlmeans/server-api",
4
- "version": "0.1.18-rc.43",
5
- "generatedAt": "2026-09-25T21:19:37.929Z",
4
+ "version": "0.1.18-rc.45",
5
+ "generatedAt": "2026-09-29T08:01:58.109Z",
6
6
  "canonicalRepo": "https://github.com/owlmeans/common",
7
7
  "entries": [
8
8
  {
@@ -7,7 +7,7 @@ user-invocable: false
7
7
 
8
8
  # @owlmeans/server-api
9
9
 
10
- **Install:** `bun add @owlmeans/server-api@^0.1.18-rc.43`
10
+ **Install:** `bun add @owlmeans/server-api@^0.1.18-rc.45`
11
11
 
12
12
  Make handlers from the protocol declaration so input and output types stay coupled to the shared
13
13
  contract:
@@ -74,6 +74,9 @@ exposure) and a status from `errorStatus(error)` (`./utils`), resolved in this o
74
74
  that is understood and refused — and a missing configuration, a broken peer, a timeout or a bug
75
75
  stays 500, because monitoring, logs, proxies and retry logic read a 5xx as the server failing.
76
76
  The table and the leaf-class rule are the `error` skill's.
77
+ - The storage refusals of `@owlmeans/resource` declare theirs: `UnknownRecordError` answers 404,
78
+ `RecordExists` 409, every other `ResourceError` 500 — so a handler that lets a `get()` miss
79
+ escape answers 404, and one reading a row the request did not address uses `load` instead.
77
80
  - Declare it on the class: `public static httpStatus = 409` (`override` only when an ancestor
78
81
  already declares one). The declaration is structural — the package declaring an error never
79
82
  imports `@owlmeans/server-api` — and a static property is inherited, so a subclass answers its
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owlmeans/server-api",
3
- "version": "0.1.18-rc.43",
3
+ "version": "0.1.18-rc.45",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -33,14 +33,14 @@
33
33
  "@fastify/helmet": "^13.1.0",
34
34
  "@fastify/middie": "^9.0.2",
35
35
  "@fastify/multipart": "^9.0.1",
36
- "@owlmeans/api": "^0.1.18-rc.39",
36
+ "@owlmeans/api": "^0.1.18-rc.41",
37
37
  "@owlmeans/auth": "^0.1.18-rc.36",
38
- "@owlmeans/auth-common": "^0.1.18-rc.39",
38
+ "@owlmeans/auth-common": "^0.1.18-rc.41",
39
39
  "@owlmeans/context": "^0.1.18-rc.32",
40
40
  "@owlmeans/error": "^0.1.18-rc.36",
41
41
  "@owlmeans/entrypoint": "^0.1.18-rc.37",
42
42
  "@owlmeans/route": "^0.1.18-rc.33",
43
- "@owlmeans/server-context": "^0.1.18-rc.37",
43
+ "@owlmeans/server-context": "^0.1.18-rc.38",
44
44
  "@owlmeans/server-entrypoint": "^0.1.18-rc.36",
45
45
  "ajv-errors": "^3.0.0",
46
46
  "fastify": "^5.0.0",
@@ -53,6 +53,7 @@
53
53
  },
54
54
  "devDependencies": {
55
55
  "@owlmeans/dep-config": "workspace:*",
56
+ "@owlmeans/resource": "^0.1.18-rc.37",
56
57
  "@types/bun": "^1.4.0",
57
58
  "@types/node": "^26.1.0",
58
59
  "nodemon": "^3.1.14",
@@ -7,7 +7,11 @@ import { provideResponse } from '@owlmeans/entrypoint'
7
7
  import { errorExposure, errorStatus, handleError, INCIDENT_ID_HEADER } from '../src/utils/error.js'
8
8
  import { executeResponse } from '../src/utils/payload.js'
9
9
  import { AccessError, AuthFailedError } from '../src/errors.js'
10
- import { DENIAL_KIND_HEADER, ACCESS_DENIED_KIND } from '@owlmeans/api'
10
+ import { DENIAL_KIND_HEADER, ACCESS_DENIED_KIND, httpStatusOf } from '@owlmeans/api'
11
+ import {
12
+ MigrationError, MisshapedRecord, RecordExists, RecordUpdateFailed, UnknownRecordError,
13
+ UnsupportedArgumentError, UnsupportedMethodError,
14
+ } from '@owlmeans/resource'
11
15
 
12
16
  class OutOfCredit extends ResilientError {
13
17
  public static override typeName = 'ServerApiSpecOutOfCredit'
@@ -180,7 +184,7 @@ const answer = async (error: unknown, path: string = '/handle') => {
180
184
  return {
181
185
  status: reply.statusCode,
182
186
  body: reply.body,
183
- incidentId: reply.headers[INCIDENT_ID_HEADER.toLowerCase()],
187
+ incidentId: reply.headers[INCIDENT_ID_HEADER.toLowerCase()] as string,
184
188
  retryAfter: reply.headers['retry-after'],
185
189
  denialKind: reply.headers[DENIAL_KIND_HEADER.toLowerCase()],
186
190
  }
@@ -294,3 +298,45 @@ describe('@owlmeans/server-api — auth status across a rebuild and duplicate mo
294
298
  expect((await answer(new ForeignEntitlementRefusal())).status).toBe(403)
295
299
  })
296
300
  })
301
+
302
+ describe('@owlmeans/server-api — storage refusals of @owlmeans/resource', () => {
303
+ test('an absent record answers 404 and a taken id or key 409 — as thrown and after a marshal hop', async () => {
304
+ expect((await answer(new UnknownRecordError('shelf/3'))).status).toBe(404)
305
+ expect((await answer(new RecordExists('id-present'))).status).toBe(409)
306
+ expect((await answer(ResilientError.marshal(new UnknownRecordError('shelf/3')))).status).toBe(404)
307
+ expect((await answer(ResilientError.marshal(new RecordExists('isbn')))).status).toBe(409)
308
+ expect((await answer(new UnknownRecordError('shelf/3'), '/execute')).status).toBe(404)
309
+ })
310
+
311
+ test('a storage fault still answers 500', async () => {
312
+ for (const fault of [
313
+ new MisshapedRecord('x'), new RecordUpdateFailed('x'), new UnsupportedArgumentError('ttl'),
314
+ new UnsupportedMethodError('watch'), new MigrationError('x'),
315
+ ]) {
316
+ expect([fault.type, (await answer(fault)).status]).toEqual([fault.type, 500])
317
+ }
318
+ })
319
+
320
+ test('a development body rebuilds into the same class, and the status the client stamps agrees with it', async () => {
321
+ for (const [error, status] of [
322
+ [new UnknownRecordError('shelf/3'), 404], [new RecordExists('isbn'), 409],
323
+ ] as const) {
324
+ const response = await answer(error, '/handle-development')
325
+ expect(response.status).toBe(status)
326
+ // What `@owlmeans/api` does with a non-2xx body carrying the separator.
327
+ const rebuilt = Object.assign(ResilientError.ensure(response.body, true), { responseStatus: response.status })
328
+ expect(rebuilt.constructor).toBe(error.constructor)
329
+ expect(rebuilt.message).toBe(error.message)
330
+ expect(httpStatusOf(rebuilt)).toBe(status)
331
+ }
332
+ const rebuilt = ResilientError.ensure((await answer(new UnknownRecordError('shelf/3'), '/handle-development')).body, true)
333
+ expect((rebuilt as UnknownRecordError).id).toBe('shelf/3')
334
+ })
335
+
336
+ test('a production body is the incident id alone, under the declared status', async () => {
337
+ const response = await answer(new UnknownRecordError('shelf/3'))
338
+ expect(response.status).toBe(404)
339
+ expect(response.body).toBe(response.incidentId)
340
+ expect(response.body).not.toContain('shelf')
341
+ })
342
+ })