@owlmeans/server-socket 0.1.18-rc.53 → 0.1.18-rc.54
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 +12 -11
- package/agent-meta/manifest.json +2 -2
- package/agent-meta/skills/server-socket/SKILL.md +1 -1
- package/build/service.d.ts.map +1 -1
- package/build/service.js +8 -7
- package/build/service.js.map +1 -1
- package/build/utils/connection.d.ts.map +1 -1
- package/build/utils/connection.js +4 -5
- package/build/utils/connection.js.map +1 -1
- package/package.json +11 -11
- package/src/service.ts +8 -7
- package/src/utils/connection.ts +4 -5
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ in a queue (`@owlmeans/server-job`).
|
|
|
11
11
|
## Installation
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
|
-
bun add @owlmeans/server-socket@^0.1.18-rc.
|
|
14
|
+
bun add @owlmeans/server-socket@^0.1.18-rc.54
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
## Concepts
|
|
@@ -71,13 +71,13 @@ export const appEntrypoints = [
|
|
|
71
71
|
The parent declares `guards`, so authentication and the entity are resolved before the upgrade.
|
|
72
72
|
|
|
73
73
|
```ts
|
|
74
|
-
import {
|
|
74
|
+
import { makeEntityScope } from '@owlmeans/auth-common'
|
|
75
75
|
import { MessageType } from '@owlmeans/socket'
|
|
76
76
|
import type { EventMessage } from '@owlmeans/socket'
|
|
77
77
|
|
|
78
78
|
export const events = connection<typeof projectProtocols.events, Context>(projectProtocols.events,
|
|
79
79
|
async (conn, context, request) => {
|
|
80
|
-
const entityId =
|
|
80
|
+
const entityId = makeEntityScope(request).requireEntityKey()
|
|
81
81
|
|
|
82
82
|
// app-local pub/sub resource, one channel per organization
|
|
83
83
|
const unsubscribe = await context.projectEvents().subscribe(async event => {
|
|
@@ -99,12 +99,12 @@ export const events = connection<typeof projectProtocols.events, Context>(projec
|
|
|
99
99
|
### Authenticate in-band
|
|
100
100
|
|
|
101
101
|
When the client cannot send a bearer on the upgrade request, it sends the token as the first auth
|
|
102
|
-
frame. The handler runs the guard itself and must call `attachEntity`.
|
|
102
|
+
frame. The handler runs the guard itself and must call `makeEntityScope(request).attachEntity(context)`.
|
|
103
103
|
|
|
104
104
|
```ts
|
|
105
105
|
import { AUTH_HEADER, AuthenFailed, AuthenticationStage, AuthUnknown } from '@owlmeans/auth'
|
|
106
106
|
import type { Auth, AuthToken } from '@owlmeans/auth'
|
|
107
|
-
import {
|
|
107
|
+
import { DEFAULT_GUARD, makeEntityScope } from '@owlmeans/auth-common'
|
|
108
108
|
import { provideResponse } from '@owlmeans/entrypoint'
|
|
109
109
|
import type { AbstractResponse, GuardService } from '@owlmeans/entrypoint'
|
|
110
110
|
import type { AuthenticateMethod } from '@owlmeans/socket'
|
|
@@ -127,10 +127,11 @@ export const watch = connection<typeof projectProtocols.watch, Context>(projectP
|
|
|
127
127
|
|
|
128
128
|
request.auth = response.value
|
|
129
129
|
// This path establishes authentication, so it resolves the organization entity itself.
|
|
130
|
-
|
|
130
|
+
const scope = makeEntityScope(request)
|
|
131
|
+
await scope.attachEntity(context)
|
|
131
132
|
clearTimeout(timeout)
|
|
132
133
|
|
|
133
|
-
await startWatching(conn, context, requireEntityKey(
|
|
134
|
+
await startWatching(conn, context, scope.requireEntityKey())
|
|
134
135
|
|
|
135
136
|
return [AuthenticationStage.Authenticated, true]
|
|
136
137
|
}) as AuthenticateMethod
|
|
@@ -142,7 +143,7 @@ export const watch = connection<typeof projectProtocols.watch, Context>(projectP
|
|
|
142
143
|
```ts
|
|
143
144
|
export const terminal = connection<typeof projectProtocols.terminal, Context>(projectProtocols.terminal,
|
|
144
145
|
async (conn, context, request) => {
|
|
145
|
-
const entityId =
|
|
146
|
+
const entityId = makeEntityScope(request).requireEntityKey()
|
|
146
147
|
|
|
147
148
|
conn.perform('project:rename', async (id: string, name: string) => {
|
|
148
149
|
const project = await context.project().load({ id, entityId })
|
|
@@ -184,7 +185,7 @@ context.registerMiddleware(createSocketMiddleware())
|
|
|
184
185
|
- Bind with the same protocol object on both sides: `bind(p, connection(p, callback))`.
|
|
185
186
|
- Guards and gates are inherited from the protocol tree and enforced before the handler runs; do not
|
|
186
187
|
re-implement them inside the callback.
|
|
187
|
-
- A socket that authenticates on its own must call `attachEntity(context
|
|
188
|
+
- A socket that authenticates on its own must call `makeEntityScope(request).attachEntity(context)`, or
|
|
188
189
|
`request.entity` stays empty and entity-keyed lookups silently find nothing.
|
|
189
190
|
- The token query parameter is used only to stamp `sender` / `recipient` on frames. It is not
|
|
190
191
|
verified — never treat it as authentication.
|
|
@@ -199,7 +200,7 @@ context.registerMiddleware(createSocketMiddleware())
|
|
|
199
200
|
- [`@owlmeans/server-api`](../server-api) — the API server this service attaches to
|
|
200
201
|
- [`@owlmeans/server-entrypoint`](../server-entrypoint) — `bind()`
|
|
201
202
|
- [`@owlmeans/server-app`](../server-app) — calls `appendSocketService` in `makeContext`
|
|
202
|
-
- [`@owlmeans/auth-common`](../auth-common) — `attachEntity`, `requireEntityKey
|
|
203
|
+
- [`@owlmeans/auth-common`](../auth-common) — `makeEntityScope` (`attachEntity`, `requireEntityKey`), `DEFAULT_GUARD`
|
|
203
204
|
|
|
204
205
|
<!-- owlmeans:agent-guidance:start -->
|
|
205
206
|
## Agent guidance
|
|
@@ -209,7 +210,7 @@ This package ships embedded agent skills under `agent-meta/`. After installing y
|
|
|
209
210
|
your project's skill store (`.agents/skills/`):
|
|
210
211
|
|
|
211
212
|
```sh
|
|
212
|
-
npx @owlmeans/agent-skills@^0.1.18-rc.
|
|
213
|
+
npx @owlmeans/agent-skills@^0.1.18-rc.49
|
|
213
214
|
```
|
|
214
215
|
|
|
215
216
|
The embedded files are version-matched to this package release. Do not edit them
|
package/agent-meta/manifest.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 2,
|
|
3
3
|
"package": "@owlmeans/server-socket",
|
|
4
|
-
"version": "0.1.18-rc.
|
|
5
|
-
"generatedAt": "2026-10-
|
|
4
|
+
"version": "0.1.18-rc.54",
|
|
5
|
+
"generatedAt": "2026-10-05T21:03:06.407Z",
|
|
6
6
|
"canonicalRepo": "https://github.com/owlmeans/common",
|
|
7
7
|
"entries": [
|
|
8
8
|
{
|
|
@@ -6,7 +6,7 @@ description: Bind OwlMeans socket protocol declarations to Fastify WebSocket han
|
|
|
6
6
|
|
|
7
7
|
# Socket protocol handlers
|
|
8
8
|
|
|
9
|
-
**Install:** `bun add @owlmeans/server-socket@^0.1.18-rc.
|
|
9
|
+
**Install:** `bun add @owlmeans/server-socket@^0.1.18-rc.54`
|
|
10
10
|
|
|
11
11
|
Declare a socket route and its contract in the shared protocol package. Bind it on the server with
|
|
12
12
|
`connection()` and `bind()`.
|
package/build/service.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAC/C,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAW,MAAM,sBAAsB,CAAA;AAgBpE,eAAO,MAAM,mBAAmB,WAAW,MAAM,KAAmB,
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAC/C,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAW,MAAM,sBAAsB,CAAA;AAgBpE,eAAO,MAAM,mBAAmB,WAAW,MAAM,KAAmB,aA+GnE,CAAA;AAED,eAAO,MAAM,mBAAmB,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,OACnE,CAAC,UAAS,MAAM,KACpB,CAOF,CAAA"}
|
package/build/service.js
CHANGED
|
@@ -2,7 +2,7 @@ import { assertContext, createService } from '@owlmeans/context';
|
|
|
2
2
|
import { DEFAULT_ALIAS } from './consts.js';
|
|
3
3
|
import { canServerModule } from './utils/server.js';
|
|
4
4
|
import { fastifyWebsocket } from '@fastify/websocket';
|
|
5
|
-
import { authorize,
|
|
5
|
+
import { authorize, httpErrorHelper, makeRequestContextHelper, payloadHelper } from '@owlmeans/server-api/utils';
|
|
6
6
|
import { EntrypointOutcome, provideResponse } from '@owlmeans/entrypoint';
|
|
7
7
|
import { ResilientError } from '@owlmeans/error';
|
|
8
8
|
import { logger, logThrottle } from '@owlmeans/log';
|
|
@@ -17,7 +17,8 @@ export const createSocketService = (alias = DEFAULT_ALIAS) => {
|
|
|
17
17
|
});
|
|
18
18
|
await api.server.register(async (server) => {
|
|
19
19
|
server.addHook('preHandler', async (req, reply) => {
|
|
20
|
-
const
|
|
20
|
+
const requestContext = makeRequestContextHelper(req);
|
|
21
|
+
const context = requestContext.extractContext(service.ctx, alias);
|
|
21
22
|
await context?.entrypoints()
|
|
22
23
|
.filter(module => canServerModule(context, module) && !module.route.isIntermediate())
|
|
23
24
|
.reduce(async (ctx, module) => {
|
|
@@ -30,17 +31,17 @@ export const createSocketService = (alias = DEFAULT_ALIAS) => {
|
|
|
30
31
|
}
|
|
31
32
|
try {
|
|
32
33
|
const response = provideResponse(reply);
|
|
33
|
-
const request = provideRequest(module.alias, req, true);
|
|
34
|
+
const request = payloadHelper.provideRequest(module.alias, req, true);
|
|
34
35
|
const authorized = await authorize(context, module, req, reply);
|
|
35
36
|
context = authorized[0];
|
|
36
37
|
module = authorized[1];
|
|
37
|
-
populateContext(
|
|
38
|
+
requestContext.populateContext(context);
|
|
38
39
|
// @TODO there code duplication with server-api
|
|
39
40
|
const gates = module.getGates();
|
|
40
41
|
for (const [srv, params] of gates) {
|
|
41
42
|
const gate = context.service(srv);
|
|
42
43
|
await gate.assert(request, response, params);
|
|
43
|
-
executeResponse(response, reply, true);
|
|
44
|
+
payloadHelper.executeResponse(response, reply, true);
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
47
|
catch (error) {
|
|
@@ -49,7 +50,7 @@ export const createSocketService = (alias = DEFAULT_ALIAS) => {
|
|
|
49
50
|
fixer.handle(reply, ResilientError.ensure(error));
|
|
50
51
|
}
|
|
51
52
|
else {
|
|
52
|
-
handleError(error, reply, errorExposure(context.cfg));
|
|
53
|
+
httpErrorHelper.handleError(error, reply, httpErrorHelper.errorExposure(context.cfg));
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
56
|
return context;
|
|
@@ -67,7 +68,7 @@ export const createSocketService = (alias = DEFAULT_ALIAS) => {
|
|
|
67
68
|
headers: module.filter?.headers ?? {}
|
|
68
69
|
}, websocket: true
|
|
69
70
|
}, (conn, req) => {
|
|
70
|
-
const request = provideRequest(module.alias, req, true);
|
|
71
|
+
const request = payloadHelper.provideRequest(module.alias, req, true);
|
|
71
72
|
request.body = conn;
|
|
72
73
|
conn.on('error', (error) => log.error('WebSocket error', { route: module.alias, error }));
|
|
73
74
|
void module.handle(request, {
|
package/build/service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAGhE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAE3C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAErD,OAAO,EACL,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAGhE,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAE3C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBA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kBAAkB,CAAA;AAChE,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAI3D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/utils/connection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,KAAK,EAAE,UAAU,EAAgB,MAAM,kBAAkB,CAAA;AAChE,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAI3D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAStD,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,WACvE,eAAe,CAAC,SAAS,CAAC,WAAW,CAAC,KAC9C,UAoKF,CAAA"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { SocketUnsupported, createBasicConnection, MessageType, SocketInitializationError, SocketUnauthorized } from '@owlmeans/socket';
|
|
2
|
-
import { AuthenticationStage, AUTH_QUERY } from '@owlmeans/auth';
|
|
3
|
-
import { isAuth, isAuthCredentials, isAuthToken } from '@owlmeans/auth';
|
|
2
|
+
import { AuthenticationStage, AUTH_QUERY, authHelper } from '@owlmeans/auth';
|
|
4
3
|
import { EnvelopeKind, makeEnvelopeModel } from '@owlmeans/basic-envelope';
|
|
5
4
|
import { logger } from '@owlmeans/log';
|
|
6
5
|
const log = logger('server-socket');
|
|
@@ -30,7 +29,7 @@ export const makeConnection = (request, context) => {
|
|
|
30
29
|
// @TODO This method is fully supported only by authentication services
|
|
31
30
|
model.authenticate = async (stage, payload) => {
|
|
32
31
|
if (AuthenticationStage.Authenticate === stage) {
|
|
33
|
-
if (isAuthToken(payload)) {
|
|
32
|
+
if (authHelper.isAuthToken(payload)) {
|
|
34
33
|
const ctx = context;
|
|
35
34
|
const _auth = await ctx.auth().authenticate(payload);
|
|
36
35
|
if (_auth == null) {
|
|
@@ -40,7 +39,7 @@ export const makeConnection = (request, context) => {
|
|
|
40
39
|
auth = model.message();
|
|
41
40
|
return [AuthenticationStage.Authenticated, _auth];
|
|
42
41
|
}
|
|
43
|
-
if (isAuth(payload)) {
|
|
42
|
+
if (authHelper.isAuth(payload)) {
|
|
44
43
|
auth = payload;
|
|
45
44
|
return [stage, auth];
|
|
46
45
|
}
|
|
@@ -61,7 +60,7 @@ export const makeConnection = (request, context) => {
|
|
|
61
60
|
if (authorization != null) {
|
|
62
61
|
const envelope = makeEnvelopeModel(authorization, EnvelopeKind.Token);
|
|
63
62
|
const _auth = envelope.message();
|
|
64
|
-
if (isAuth(_auth) || isAuthCredentials(_auth)) {
|
|
63
|
+
if (authHelper.isAuth(_auth) || authHelper.isAuthCredentials(_auth)) {
|
|
65
64
|
auth = _auth;
|
|
66
65
|
}
|
|
67
66
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/utils/connection.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,iBAAiB,EAAE,qBAAqB,EAAE,WAAW,EAAE,yBAAyB,EAAE,kBAAkB,EACrG,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/utils/connection.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,iBAAiB,EAAE,qBAAqB,EAAE,WAAW,EAAE,yBAAyB,EAAE,kBAAkB,EACrG,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE5E,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AAE1E,OAAO,E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KAAK,CAAC,iCAAiC,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;QACzD,CAAC,CAAC,CAAA;IACJ,CAAC,CAAA;IAED,IAAI,CAAC,EAAE,CAAC,SAAS,EAAE,cAAc,CAAC,CAAA;IAClC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,YAAY,CAAC,CAAA;IAE9B,OAAO,KAAK,CAAA;AACd,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@owlmeans/server-socket",
|
|
3
|
-
"version": "0.1.18-rc.
|
|
3
|
+
"version": "0.1.18-rc.54",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -31,16 +31,16 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@fastify/websocket": "^11.3.3",
|
|
34
|
-
"@owlmeans/auth": "^0.1.18-rc.
|
|
35
|
-
"@owlmeans/basic-envelope": "^0.1.18-rc.
|
|
36
|
-
"@owlmeans/context": "^0.1.18-rc.
|
|
37
|
-
"@owlmeans/entrypoint": "^0.1.18-rc.
|
|
38
|
-
"@owlmeans/log": "^0.1.18-rc.
|
|
39
|
-
"@owlmeans/server-api": "^0.1.18-rc.
|
|
40
|
-
"@owlmeans/server-auth": "^0.1.18-rc.
|
|
41
|
-
"@owlmeans/server-context": "^0.1.18-rc.
|
|
42
|
-
"@owlmeans/server-entrypoint": "^0.1.18-rc.
|
|
43
|
-
"@owlmeans/socket": "^0.1.18-rc.
|
|
34
|
+
"@owlmeans/auth": "^0.1.18-rc.40",
|
|
35
|
+
"@owlmeans/basic-envelope": "^0.1.18-rc.46",
|
|
36
|
+
"@owlmeans/context": "^0.1.18-rc.34",
|
|
37
|
+
"@owlmeans/entrypoint": "^0.1.18-rc.41",
|
|
38
|
+
"@owlmeans/log": "^0.1.18-rc.2",
|
|
39
|
+
"@owlmeans/server-api": "^0.1.18-rc.51",
|
|
40
|
+
"@owlmeans/server-auth": "^0.1.18-rc.54",
|
|
41
|
+
"@owlmeans/server-context": "^0.1.18-rc.43",
|
|
42
|
+
"@owlmeans/server-entrypoint": "^0.1.18-rc.40",
|
|
43
|
+
"@owlmeans/socket": "^0.1.18-rc.40"
|
|
44
44
|
},
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"access": "public"
|
package/src/service.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { canServerModule } from './utils/server.js'
|
|
|
7
7
|
import { fastifyWebsocket } from '@fastify/websocket'
|
|
8
8
|
import type { WebSocket } from '@fastify/websocket'
|
|
9
9
|
import {
|
|
10
|
-
authorize,
|
|
10
|
+
authorize, httpErrorHelper, makeRequestContextHelper, payloadHelper
|
|
11
11
|
} from '@owlmeans/server-api/utils'
|
|
12
12
|
import { EntrypointOutcome, provideResponse } from '@owlmeans/entrypoint'
|
|
13
13
|
import type { AbstractRequest, GateService } from '@owlmeans/entrypoint'
|
|
@@ -27,7 +27,8 @@ export const createSocketService = (alias: string = DEFAULT_ALIAS): SocketServic
|
|
|
27
27
|
|
|
28
28
|
await api.server.register(async server => {
|
|
29
29
|
server.addHook('preHandler', async (req, reply) => {
|
|
30
|
-
const
|
|
30
|
+
const requestContext = makeRequestContextHelper(req)
|
|
31
|
+
const context = requestContext.extractContext(service.ctx as Context, alias)
|
|
31
32
|
await context?.entrypoints<ServerEntrypoint<Request>>()
|
|
32
33
|
.filter(module => canServerModule(context, module) && !module.route.isIntermediate())
|
|
33
34
|
.reduce<Promise<Context>>(async (ctx, module) => {
|
|
@@ -43,27 +44,27 @@ export const createSocketService = (alias: string = DEFAULT_ALIAS): SocketServic
|
|
|
43
44
|
|
|
44
45
|
try {
|
|
45
46
|
const response = provideResponse(reply)
|
|
46
|
-
const request = provideRequest(module.alias, req, true)
|
|
47
|
+
const request = payloadHelper.provideRequest(module.alias, req, true)
|
|
47
48
|
|
|
48
49
|
const authorized = await authorize(context, module, req, reply)
|
|
49
50
|
context = authorized[0]
|
|
50
51
|
module = authorized[1]
|
|
51
52
|
|
|
52
|
-
populateContext(
|
|
53
|
+
requestContext.populateContext(context)
|
|
53
54
|
|
|
54
55
|
// @TODO there code duplication with server-api
|
|
55
56
|
const gates = module.getGates()
|
|
56
57
|
for (const [srv, params] of gates) {
|
|
57
58
|
const gate: GateService = context.service(srv)
|
|
58
59
|
await gate.assert(request, response, params)
|
|
59
|
-
executeResponse(response, reply, true)
|
|
60
|
+
payloadHelper.executeResponse(response, reply, true)
|
|
60
61
|
}
|
|
61
62
|
} catch (error) {
|
|
62
63
|
if (module.fixer != null) {
|
|
63
64
|
const fixer: FixerService = context.service(module.fixer)
|
|
64
65
|
fixer.handle(reply, ResilientError.ensure(error as Error))
|
|
65
66
|
} else {
|
|
66
|
-
handleError(error as Error, reply, errorExposure(context.cfg))
|
|
67
|
+
httpErrorHelper.handleError(error as Error, reply, httpErrorHelper.errorExposure(context.cfg))
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
70
|
|
|
@@ -86,7 +87,7 @@ export const createSocketService = (alias: string = DEFAULT_ALIAS): SocketServic
|
|
|
86
87
|
headers: module.filter?.headers ?? {}
|
|
87
88
|
}, websocket: true
|
|
88
89
|
}, (conn, req) => {
|
|
89
|
-
const request = provideRequest(module.alias, req, true)
|
|
90
|
+
const request = payloadHelper.provideRequest(module.alias, req, true)
|
|
90
91
|
request.body = conn
|
|
91
92
|
|
|
92
93
|
conn.on('error', (error: Error) => log.error('WebSocket error', { route: module.alias, error }))
|
package/src/utils/connection.ts
CHANGED
|
@@ -5,9 +5,8 @@ import {
|
|
|
5
5
|
SocketUnsupported, createBasicConnection, MessageType, SocketInitializationError, SocketUnauthorized
|
|
6
6
|
} from '@owlmeans/socket'
|
|
7
7
|
import { AbstractRequest } from '@owlmeans/entrypoint'
|
|
8
|
-
import { AuthenticationStage, AUTH_QUERY } from '@owlmeans/auth'
|
|
8
|
+
import { AuthenticationStage, AUTH_QUERY, authHelper } from '@owlmeans/auth'
|
|
9
9
|
import type { Auth, AuthCredentials } from '@owlmeans/auth'
|
|
10
|
-
import { isAuth, isAuthCredentials, isAuthToken } from '@owlmeans/auth'
|
|
11
10
|
import { EnvelopeKind, makeEnvelopeModel } from '@owlmeans/basic-envelope'
|
|
12
11
|
import type { AuthServiceAppend } from '@owlmeans/server-auth'
|
|
13
12
|
import { logger } from '@owlmeans/log'
|
|
@@ -46,7 +45,7 @@ export const makeConnection = <C extends Config, T extends Context<C> = Context<
|
|
|
46
45
|
// @TODO This method is fully supported only by authentication services
|
|
47
46
|
model.authenticate = async (stage, payload) => {
|
|
48
47
|
if (AuthenticationStage.Authenticate === stage) {
|
|
49
|
-
if (isAuthToken(payload)) {
|
|
48
|
+
if (authHelper.isAuthToken(payload)) {
|
|
50
49
|
const ctx = context as AuthServiceAppend & T
|
|
51
50
|
const _auth = await ctx.auth().authenticate(payload)
|
|
52
51
|
if (_auth == null) {
|
|
@@ -57,7 +56,7 @@ export const makeConnection = <C extends Config, T extends Context<C> = Context<
|
|
|
57
56
|
|
|
58
57
|
return [AuthenticationStage.Authenticated, _auth as any]
|
|
59
58
|
}
|
|
60
|
-
if (isAuth(payload)) {
|
|
59
|
+
if (authHelper.isAuth(payload)) {
|
|
61
60
|
auth = payload
|
|
62
61
|
|
|
63
62
|
return [stage, auth as any]
|
|
@@ -80,7 +79,7 @@ export const makeConnection = <C extends Config, T extends Context<C> = Context<
|
|
|
80
79
|
if (authorization != null) {
|
|
81
80
|
const envelope = makeEnvelopeModel<Auth | AuthCredentials>(authorization, EnvelopeKind.Token)
|
|
82
81
|
const _auth = envelope.message()
|
|
83
|
-
if (isAuth(_auth) || isAuthCredentials(_auth)) {
|
|
82
|
+
if (authHelper.isAuth(_auth) || authHelper.isAuthCredentials(_auth)) {
|
|
84
83
|
auth = _auth
|
|
85
84
|
}
|
|
86
85
|
}
|