@owlmeans/auth-common 0.1.18-rc.10 → 0.1.18-rc.12

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
@@ -1,10 +1,10 @@
1
1
  # @owlmeans/auth-common
2
2
 
3
- Predefined authentication modules, guards, and constants shared between server and client packages.
3
+ Predefined authentication entrypoints, guards, and constants shared between server and client packages.
4
4
 
5
5
  ## Overview
6
6
 
7
- - Exports standard auth module definitions (login, init, rely, dispatcher) ready to register in any app
7
+ - Exports standard auth entrypoint definitions (login, init, rely, dispatcher) ready to register in any app
8
8
  - Provides `DEFAULT_GUARD` and `GUARD_ED25519` constants for protecting routes
9
9
  - Implements the Basic ED25519 signature guard service for cryptographic request authentication
10
10
  - Headers: `BED255_NONCE_HEADER`, `BED255_TIME_HEADER` for auth challenge/response
@@ -17,30 +17,30 @@ bun add @owlmeans/auth-common
17
17
 
18
18
  ## Usage
19
19
 
20
- Register the built-in auth modules and protect a route:
20
+ Register the built-in auth entrypoints and protect a route:
21
21
 
22
22
  ```typescript
23
- import { modules } from '@owlmeans/auth-common'
23
+ import { entrypoints } from '@owlmeans/auth-common'
24
24
  import { GUARD_ED25519, DEFAULT_GUARD } from '@owlmeans/auth-common'
25
25
 
26
- // Add auth modules to your app (includes /authentication, /login, /dispatcher routes)
27
- await main(context, [...modules, ...appModules])
26
+ // Add auth entrypoints to your app (includes /authentication, /login, /dispatcher routes)
27
+ await main(context, [...entrypoints, ...appEntrypoints])
28
28
  ```
29
29
 
30
30
  Protect a route with the ED25519 signature guard (re-exported via `@owlmeans/server-app`):
31
31
 
32
32
  ```typescript
33
33
  import { GUARD_ED25519 } from '@owlmeans/auth-common'
34
- import { module, guard } from '@owlmeans/server-app'
34
+ import { entrypoint, guard } from '@owlmeans/server-app'
35
35
 
36
- const adminModule = module(route('admin', '/api/admin'), guard(GUARD_ED25519))
36
+ const adminEntrypoint = entrypoint(route('admin', '/api/admin'), guard(GUARD_ED25519))
37
37
  ```
38
38
 
39
39
  ## API
40
40
 
41
- ### `modules`
41
+ ### `entrypoints`
42
42
 
43
- Array of pre-built `CommonModule` instances covering the standard auth flow:
43
+ Array of pre-built `CommonEntrypoint` instances covering the standard auth flow:
44
44
  - `AUTHEN` — backend `/authentication` base route
45
45
  - `AUTHEN_INIT` — POST `/authentication/init` (allowance request)
46
46
  - `AUTHEN_AUTHEN` — POST `/authentication/authenticate` (credential submission)
@@ -68,7 +68,7 @@ BED255_CASHE_RESOURCE // resource alias for nonce cache
68
68
  - `DEFAULT_GUARD` protects manager routes after bearer authentication is installed by `@owlmeans/server-auth`.
69
69
  - Product authorization composes a custom gate inside `guard(DEFAULT_GUARD, gate(VIABLE_AUTH_GATE, [...]))` rather than using `OIDC_GATE` for Google login flows.
70
70
  - `GUARD_ED25519` remains the service-to-service guard for internal/publisher/payment/auth-service calls.
71
- - The browser-side alias from `@owlmeans/client-auth` must match the default guard name so shared module declarations elevate consistently.
71
+ - The browser-side alias from `@owlmeans/client-auth` must match the default guard name so shared entrypoint declarations elevate consistently.
72
72
 
73
73
  ## Related Packages
74
74
 
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "schemaVersion": 2,
3
3
  "package": "@owlmeans/auth-common",
4
- "version": "0.1.18-rc.10",
5
- "generatedAt": "2026-09-01T12:04:42.727Z",
4
+ "version": "0.1.18-rc.12",
5
+ "generatedAt": "2026-09-01T17:39:40.761Z",
6
6
  "canonicalRepo": "https://github.com/owlmeans/common",
7
7
  "entries": [
8
8
  {
@@ -8,7 +8,7 @@ user-invocable: false
8
8
  # @owlmeans/auth-common
9
9
 
10
10
  **Layer:** Core
11
- **Install:** `"@owlmeans/auth-common": "^0.1.18-rc.10"` in `dependencies`
11
+ **Install:** `"@owlmeans/auth-common": "^0.1.18-rc.12"` in `dependencies`
12
12
 
13
13
  ## Key Exports
14
14
 
@@ -1 +1 @@
1
- {"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],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e,oBAAoB,CAAA;AAEhD;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,QAA2C,CAAA;AAE3E,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;CAkBnB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"entity.d.ts","sourceRoot":"","sources":["../src/entity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC3E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAKrD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,WAAW,QAAS,eAAe,KAAG,MAAM,GAAG,SAClB,CAAA;AAE1C;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,QAAS,eAAe,KAAG,MAOvD,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,aAAa,QAAS,eAAe,KAAG,cAMpD,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,YAAY,YACd,YAAY,CAAC,GAAG,CAAC,WAAW,eAAe,KACnD,OAAO,CAAC,cAAc,GAAG,SAAS,CAiBpC,CAAA"}
1
+ {"version":3,"file":"entity.d.ts","sourceRoot":"","sources":["../src/entity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC3E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAKrD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,WAAW,GAAI,KAAK,eAAe,KAAG,MAAM,GAAG,SAClB,CAAA;AAE1C;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAI,KAAK,eAAe,KAAG,MAOvD,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAI,KAAK,eAAe,KAAG,cAMpD,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,YAAY,GACvB,SAAS,YAAY,CAAC,GAAG,CAAC,EAAE,SAAS,eAAe,KACnD,OAAO,CAAC,cAAc,GAAG,SAAS,CAiBpC,CAAA"}
@@ -0,0 +1,3 @@
1
+ export declare const entrypoints: import("@owlmeans/entrypoint").CommonEntrypoint[];
2
+ export declare const managerEntrypoints: import("@owlmeans/entrypoint").CommonEntrypoint[];
3
+ //# sourceMappingURL=entrypoints.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entrypoints.d.ts","sourceRoot":"","sources":["../src/entrypoints.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,WAAW,mDAkCvB,CAAA;AAED,eAAO,MAAM,kBAAkB,mDAW9B,CAAA"}
@@ -4,7 +4,7 @@ import { body, filter, entrypoint, query } from '@owlmeans/entrypoint';
4
4
  import { route, RouteMethod, frontend, backend, socket } from '@owlmeans/route';
5
5
  import { DISPATCHER_PATH, SURROGATE_PATH, WEB_API, authApi } from './consts.js';
6
6
  import { SurrogateQuerySchema } from './schemas.js';
7
- export const modules = [
7
+ export const entrypoints = [
8
8
  entrypoint(route(AUTHEN, '/authentication', backend())),
9
9
  entrypoint(route(AUTHEN_INIT, '/init', backend(AUTHEN, RouteMethod.POST)), filter(body(AllowanceRequestSchema))),
10
10
  entrypoint(route(AUTHEN_AUTHEN, '/authenticate', backend(AUTHEN, RouteMethod.POST)), filter(body(AuthCredentialsSchema))),
@@ -18,7 +18,7 @@ export const modules = [
18
18
  // This is a helper route that is useb by service providres to process authentication provisioning via redirect.
19
19
  // Also it can be default starting point to be redirected to an external identity provider.
20
20
  entrypoint(route(DISPATCHER, DISPATCHER_PATH, frontend({ service: DISPATCHER })),
21
- // This module is sticky - it means it's always attach to client router.
21
+ // This entrypoint is sticky - it means it's always attach to client router.
22
22
  // It's required here cause every web app needs dispatcher route to authorize
23
23
  // rediected users.
24
24
  filter(query(AuthTokenSchema), { sticky: true })),
@@ -34,14 +34,14 @@ export const modules = [
34
34
  // a user with OwlMeans server-auth library.
35
35
  entrypoint(route(DISPATCHER_AUTHEN, '/authenticate', backend(null, RouteMethod.POST)), filter(body(AuthTokenSchema))),
36
36
  ];
37
- export const managerModules = [
37
+ export const managerEntrypoints = [
38
38
  entrypoint(route(authApi.profile.base, '/profile', backend({ service: WEB_API }))),
39
39
  entrypoint(route(authApi.profile.toEntityId, '/to-entity-id', backend(authApi.profile.base, RouteMethod.POST))),
40
40
  entrypoint(route(authApi.auth.base, '/auth', backend({ service: WEB_API }))),
41
41
  entrypoint(route(authApi.auth.delegate, '/delegate', backend(authApi.auth.base, RouteMethod.POST))),
42
42
  ];
43
- // const skipModules = [DISPATCHER]
44
- // export const authBackendModules = modules.filter(
45
- // module => !skipModules.includes(module.alias) && module.route.route.type === AppType.Backend
43
+ // const skipEntrypoints = [DISPATCHER]
44
+ // export const authBackendEntrypoints = entrypoints.filter(
45
+ // module => !skipEntrypoints.includes(module.alias) && module.route.route.type === AppType.Backend
46
46
  // ).map(module => module.alias)
47
- //# sourceMappingURL=modules.js.map
47
+ //# sourceMappingURL=entrypoints.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entrypoints.js","sourceRoot":"","sources":["../src/entrypoints.ts"],"names":[],"mappings":"AACA,OAAO,EACL,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,sBAAsB,EAAE,qBAAqB,EAC9F,eAAe,EAAE,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,UAAU,EAClG,iBAAiB,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,kBAAkB,EACrF,MAAM,gBAAgB,CAAA;AACvB,8CAA8C;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AACtE,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAC/E,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,OAAO,EAAE,OAA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CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,CAC7C,CAAC;CACH,CAAA;AAED,uCAAuC;AACvC,4DAA4D;AAC5D,qGAAqG;AACrG,gCAAgC"}
@@ -1 +1 @@
1
- {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/guards/basic-ed25519/service.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAA;AAU7E;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,aAAc,MAAM,SAAS,wBAAwB,KAAG,iBAqHzF,CAAA"}
1
+ {"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/guards/basic-ed25519/service.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAA;AAU7E;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,GAAI,UAAU,MAAM,EAAE,OAAO,wBAAwB,KAAG,iBAqHzF,CAAA"}
package/build/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export type * from './types.js';
2
2
  export * from './schemas.js';
3
- export * from './modules.js';
3
+ export * from './entrypoints.js';
4
4
  export * from './consts.js';
5
5
  export * from './entity.js';
6
6
  export * from './middleware.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,YAAY,CAAA;AAE/B,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,YAAY,CAAA;AAE/B,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA"}
package/build/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from './schemas.js';
2
- export * from './modules.js';
2
+ export * from './entrypoints.js';
3
3
  export * from './consts.js';
4
4
  export * from './entity.js';
5
5
  export * from './middleware.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAOnD,eAAO,MAAM,cAAc,EAAE,UAsC5B,CAAA"}
1
+ {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAOnD,eAAO,MAAM,cAAc,EAAE,UAuC5B,CAAA"}
@@ -6,22 +6,23 @@ export const authMiddleware = {
6
6
  stage: MiddlewareStage.Loading,
7
7
  apply: async (context) => {
8
8
  context.entrypoints().forEach(module => {
9
- if (module.route.route.type === AppType.Backend && module.call != null) {
10
- const guards = module.getGuards();
11
- if (guards.length > 0) {
9
+ if (module.route.route.type === AppType.Backend && module.invoke != null) {
10
+ if (module.getGuards().length > 0) {
12
11
  if (module._auth_common_middleware_applied === true) {
13
12
  return;
14
13
  }
15
14
  module._auth_common_middleware_applied = true;
16
- // const auth = context.service<GuardService>(service)
17
- const call = module.call;
18
- module.call = async (req, res) => {
15
+ // Wrapping `invoke` covers `call` too: `call` reads `invoke` off the entrypoint at the
16
+ // moment it runs, so both verbs carry the authentication header.
17
+ const invoke = module.invoke;
18
+ module.invoke = (async (req) => {
19
19
  // @TODO Actually we may use multiple authentication headers with the same name
20
20
  // As I learnt its not always the case
21
- const [token] = (await Promise.all(guards.map(guard => context.service(guard).authenticated(req)))).filter(token => token != null).reverse();
21
+ // Asked per call, not captured: an ancestor may have gained a guard since the
22
+ // middleware wrapped this entrypoint.
23
+ const [token] = (await Promise.all(module.getGuards().map(guard => context.service(guard).authenticated(req)))).filter(token => token != null).reverse();
22
24
  if (token != null) {
23
- await module.resolve();
24
- const _req = req ?? provideRequest(module.getAlias(), module.getPath());
25
+ const _req = req ?? provideRequest(module.alias, module.path());
25
26
  const headers = (_req.headers ?? {});
26
27
  if (headers[AUTH_HEADER] == null) {
27
28
  headers[AUTH_HEADER] = token;
@@ -29,8 +30,8 @@ export const authMiddleware = {
29
30
  req = _req;
30
31
  }
31
32
  }
32
- return call(req, res);
33
- };
33
+ return invoke(req);
34
+ });
34
35
  }
35
36
  }
36
37
  });
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.js","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAE5D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAG5C,MAAM,CAAC,MAAM,cAAc,GAAe;IACxC,IAAI,EAAE,cAAc,CAAC,OAAO;IAC5B,KAAK,EAAE,eA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OAAO,CAAC,eAAe,CAAC,SACvB,MAAM,GAAG,IAAI,cACR,OAAO,KACjB,MAAM,GAAG,IAgBX,CAAA"}
1
+ {"version":3,"file":"header.d.ts","sourceRoot":"","sources":["../../src/utils/header.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AAE3D,eAAO,MAAM,gBAAgB,GAC3B,KAAK,OAAO,CAAC,eAAe,CAAC,EAC7B,OAAM,MAAM,GAAG,IAA0C,EACzD,YAAW,OAAc,KACxB,MAAM,GAAG,IAgBX,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"header.js","sourceRoot":"","sources":["../../src/utils/header.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAG/D,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,GAA6B,EAC7B,IAAI,GAAkB,iBAAiB,CAAC,iBAAiB,EACzD,SAAS,GAAY,IAAI,EACV,EAAE;IACjB,IAAI,aAAa,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC,WAAW,CAAC,CAAA;IAC9C,aAAa,GAAG,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,CAAA;IAE/E,IAAI,aAAa,IAAI,IAAI,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAA;IACb,CAAC;IAED,MAAM,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAClD,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;QACjB,OAAO,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa,CAAA;IACnD,CAAC;IAED,OAAO,MAAM,KAAK,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;QACpC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa;QAC1C,CAAC,CAAC,IAAI,CAAA;AACV,CAAC,CAAA"}
1
+ {"version":3,"file":"header.js","sourceRoot":"","sources":["../../src/utils/header.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAG/D,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAC9B,GAA6B,EAC7B,OAAsB,iBAAiB,CAAC,iBAAiB,EACzD,YAAqB,IAAI,EACV,EAAE;IACjB,IAAI,aAAa,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC,WAAW,CAAC,CAAA;IAC9C,aAAa,GAAG,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,CAAA;IAE/E,IAAI,aAAa,IAAI,IAAI,EAAE,CAAC;QAC1B,OAAO,IAAI,CAAA;IACb,CAAC;IAED,MAAM,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,GAAG,aAAa,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IAClD,IAAI,IAAI,IAAI,IAAI,EAAE,CAAC;QACjB,OAAO,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa,CAAA;IACnD,CAAC;IAED,OAAO,MAAM,KAAK,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;QACpC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,aAAa;QAC1C,CAAC,CAAC,IAAI,CAAA;AACV,CAAC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"trusted.d.ts","sourceRoot":"","sources":["../../src/utils/trusted.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAIhD,eAAO,MAAM,KAAK,GAAU,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,YAAY,MAAM,YAAY,MAAM,UAAS,MAAM;;;EAUhI,CAAA"}
1
+ {"version":3,"file":"trusted.d.ts","sourceRoot":"","sources":["../../src/utils/trusted.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAIhD,eAAO,MAAM,KAAK,GAAU,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,UAAU,MAAM,EAAE,UAAU,MAAM,EAAE,QAAO,MAAe;;;EAWzI,CAAA"}
@@ -1,6 +1,7 @@
1
1
  import { fromPubKey, makeKeyPairModel } from '@owlmeans/basic-keys';
2
2
  export const trust = async (context, resource, userName, field = 'name') => {
3
- const trustedUser = await context.resource(resource).load(userName, field);
3
+ const where = { [field]: userName };
4
+ const trustedUser = await context.resource(resource).load(where);
4
5
  if (trustedUser == null) {
5
6
  throw new SyntaxError(`Auth service trusted entity is not provided: ${userName}`);
6
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"trusted.js","sourceRoot":"","sources":["../../src/utils/trusted.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAEnE,MAAM,CAAC,MAAM,KAAK,GAAG,KAAK,EAA0C,OAAU,EAAE,QAAgB,EAAE,QAAgB,EAAE,KAAK,GAAW,MAAM,EAAE,EAAE;IAC5I,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,QAAQ,CAA0B,QAAQ,CAAC,C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EAAE,OAAO,EAAE,CAAA;AAC5C,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@owlmeans/auth-common",
3
- "version": "0.1.18-rc.10",
3
+ "version": "0.1.18-rc.12",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -29,19 +29,19 @@
29
29
  }
30
30
  },
31
31
  "dependencies": {
32
- "@owlmeans/auth": "^0.1.18-rc.7",
33
- "@owlmeans/auth-common": "^0.1.18-rc.9",
34
- "@owlmeans/basic-ids": "^0.1.18-rc.7",
35
- "@owlmeans/basic-keys": "^0.1.18-rc.9",
36
- "@owlmeans/client-entrypoint": "^0.1.18-rc.9",
37
- "@owlmeans/context": "^0.1.18-rc.6",
38
- "@owlmeans/entrypoint": "^0.1.18-rc.8",
39
- "@owlmeans/resource": "^0.1.18-rc.7",
40
- "@owlmeans/route": "^0.1.18-rc.6"
32
+ "@owlmeans/auth": "^0.1.18-rc.8",
33
+ "@owlmeans/auth-common": "^0.1.18-rc.12",
34
+ "@owlmeans/basic-ids": "^0.1.18-rc.8",
35
+ "@owlmeans/basic-keys": "^0.1.18-rc.11",
36
+ "@owlmeans/client-entrypoint": "^0.1.18-rc.12",
37
+ "@owlmeans/context": "^0.1.18-rc.7",
38
+ "@owlmeans/entrypoint": "^0.1.18-rc.10",
39
+ "@owlmeans/resource": "^0.1.18-rc.8",
40
+ "@owlmeans/route": "^0.1.18-rc.8"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@owlmeans/dep-config": "workspace:*",
44
- "@owlmeans/test-auth": "^0.1.18-rc.9",
44
+ "@owlmeans/test-auth": "^0.1.18-rc.12",
45
45
  "@types/bun": "^1.4.0",
46
46
  "nodemon": "^3.1.14",
47
47
  "typescript": "^7.0.2"
@@ -10,7 +10,7 @@ import { route, RouteMethod, frontend, backend, socket } from '@owlmeans/route'
10
10
  import { DISPATCHER_PATH, SURROGATE_PATH, WEB_API, authApi } from './consts.js'
11
11
  import { SurrogateQuerySchema } from './schemas.js'
12
12
 
13
- export const modules = [
13
+ export const entrypoints = [
14
14
  entrypoint(route(AUTHEN, '/authentication', backend())),
15
15
  entrypoint(route(AUTHEN_INIT, '/init', backend(AUTHEN, RouteMethod.POST)), filter(body(AllowanceRequestSchema))),
16
16
  entrypoint(route(AUTHEN_AUTHEN, '/authenticate', backend(AUTHEN, RouteMethod.POST)), filter(body(AuthCredentialsSchema))),
@@ -25,7 +25,7 @@ export const modules = [
25
25
  // Also it can be default starting point to be redirected to an external identity provider.
26
26
  entrypoint(
27
27
  route(DISPATCHER, DISPATCHER_PATH, frontend({ service: DISPATCHER })),
28
- // This module is sticky - it means it's always attach to client router.
28
+ // This entrypoint is sticky - it means it's always attach to client router.
29
29
  // It's required here cause every web app needs dispatcher route to authorize
30
30
  // rediected users.
31
31
  filter(query(AuthTokenSchema), { sticky: true })
@@ -46,7 +46,7 @@ export const modules = [
46
46
  entrypoint(route(DISPATCHER_AUTHEN, '/authenticate', backend(null, RouteMethod.POST)), filter(body(AuthTokenSchema))),
47
47
  ]
48
48
 
49
- export const managerModules = [
49
+ export const managerEntrypoints = [
50
50
  entrypoint(route(authApi.profile.base, '/profile', backend({ service: WEB_API }))),
51
51
  entrypoint(route(
52
52
  authApi.profile.toEntityId, '/to-entity-id',
@@ -59,7 +59,7 @@ export const managerModules = [
59
59
  )),
60
60
  ]
61
61
 
62
- // const skipModules = [DISPATCHER]
63
- // export const authBackendModules = modules.filter(
64
- // module => !skipModules.includes(module.alias) && module.route.route.type === AppType.Backend
62
+ // const skipEntrypoints = [DISPATCHER]
63
+ // export const authBackendEntrypoints = entrypoints.filter(
64
+ // module => !skipEntrypoints.includes(module.alias) && module.route.route.type === AppType.Backend
65
65
  // ).map(module => module.alias)
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export type * from './types.js'
2
2
 
3
3
  export * from './schemas.js'
4
- export * from './modules.js'
4
+ export * from './entrypoints.js'
5
5
  export * from './consts.js'
6
6
  export * from './entity.js'
7
7
  export * from './middleware.js'
package/src/middleware.ts CHANGED
@@ -10,24 +10,25 @@ export const authMiddleware: Middleware = {
10
10
  stage: MiddlewareStage.Loading,
11
11
  apply: async context => {
12
12
  context.entrypoints<Perked>().forEach(module => {
13
- if (module.route.route.type === AppType.Backend && module.call != null) {
14
- const guards = module.getGuards()
15
- if (guards.length > 0) {
13
+ if (module.route.route.type === AppType.Backend && module.invoke != null) {
14
+ if (module.getGuards().length > 0) {
16
15
  if (module._auth_common_middleware_applied === true) {
17
16
  return
18
17
  }
19
18
  module._auth_common_middleware_applied = true
20
- // const auth = context.service<GuardService>(service)
21
- const call = module.call
22
- module.call = async (req, res) => {
19
+ // Wrapping `invoke` covers `call` too: `call` reads `invoke` off the entrypoint at the
20
+ // moment it runs, so both verbs carry the authentication header.
21
+ const invoke = module.invoke
22
+ module.invoke = (async req => {
23
23
  // @TODO Actually we may use multiple authentication headers with the same name
24
24
  // As I learnt its not always the case
25
- const [token] = (await Promise.all(guards.map(
25
+ // Asked per call, not captured: an ancestor may have gained a guard since the
26
+ // middleware wrapped this entrypoint.
27
+ const [token] = (await Promise.all(module.getGuards().map(
26
28
  guard => context.service<GuardService>(guard).authenticated(req)
27
29
  ))).filter(token => token != null).reverse()
28
30
  if (token != null) {
29
- await module.resolve()
30
- const _req: Partial<AbstractRequest> = req ?? provideRequest(module.getAlias(), module.getPath())
31
+ const _req: Partial<AbstractRequest> = req ?? provideRequest(module.alias, module.path())
31
32
  const headers = (_req.headers ?? {}) as Record<string, string | undefined>
32
33
  if (headers[AUTH_HEADER] == null) {
33
34
  headers[AUTH_HEADER] = token
@@ -36,8 +37,8 @@ export const authMiddleware: Middleware = {
36
37
  }
37
38
  }
38
39
 
39
- return call(req, res)
40
- }
40
+ return invoke(req)
41
+ }) as typeof module.invoke
41
42
 
42
43
  }
43
44
  }
@@ -1,11 +1,12 @@
1
1
 
2
2
  import type { Context, Config } from './types.js'
3
3
  import type { TrustedRecord } from '../types.js'
4
- import type { Resource } from '@owlmeans/resource'
4
+ import type { Criteria, Resource } from '@owlmeans/resource'
5
5
  import { fromPubKey, makeKeyPairModel } from '@owlmeans/basic-keys'
6
6
 
7
7
  export const trust = async <C extends Config, T extends Context<C>>(context: T, resource: string, userName: string, field: string = 'name') => {
8
- const trustedUser = await context.resource<Resource<TrustedRecord>>(resource).load(userName, field)
8
+ const where: Criteria<TrustedRecord> = { [field]: userName }
9
+ const trustedUser = await context.resource<Resource<TrustedRecord>>(resource).load(where)
9
10
  if (trustedUser == null) {
10
11
  throw new SyntaxError(`Auth service trusted entity is not provided: ${userName}`)
11
12
  }
package/tests/context.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AppType, Layer, makeBasicContext } from '@owlmeans/context'
1
+ import { AppType, makeBasicContext } from '@owlmeans/context'
2
2
  import type { BasicConfig, BasicContext } from '@owlmeans/context'
3
3
  import { makeMemoryTrustedResource, makeFixtureKeyPair } from '@owlmeans/test-auth'
4
4
  import type { TrustedRecord } from '@owlmeans/auth-common'
@@ -38,7 +38,6 @@ export const makeTrustFixture = (
38
38
  const ctx = makeBasicContext<BasicConfig>({
39
39
  ready: false,
40
40
  service: 'auth-common-tests',
41
- layer: Layer.Service,
42
41
  type: AppType.Backend,
43
42
  })
44
43
 
@@ -1,18 +1,18 @@
1
1
  import { describe, expect, test } from 'bun:test'
2
- import { modules } from '@owlmeans/auth-common'
2
+ import { entrypoints } from '@owlmeans/auth-common'
3
3
  import { DISPATCHER, DISPATCHER_AUTHEN } from '@owlmeans/auth'
4
4
  import { DISPATCHER_PATH } from '../src/consts.js'
5
5
 
6
- // The DISPATCHER module intentionally declares service: DISPATCHER so that
7
- // urlCall() produces an absolute URL (pointing to the auth service).
6
+ // The DISPATCHER entrypoint intentionally declares service: DISPATCHER so that
7
+ // url() produces an absolute URL (pointing to the auth service).
8
8
  // The fix for the React Router 404 ("/https:/vib.owl.flat/dispatcher") lives
9
9
  // in @owlmeans/client's navigator.navigate() — when the URL is absolute it
10
10
  // does a browser redirect (globalThis.location.href) instead of React Router navigate().
11
11
 
12
- describe('@owlmeans/auth-common — DISPATCHER module declaration', () => {
13
- const dispatcher = modules.find(m => m.route.route.alias === DISPATCHER)
12
+ describe('@owlmeans/auth-common — DISPATCHER entrypoint declaration', () => {
13
+ const dispatcher = entrypoints.find(m => m.route.route.alias === DISPATCHER)
14
14
 
15
- test('DISPATCHER module is present in the modules array', () => {
15
+ test('DISPATCHER entrypoint is present in the entrypoints array', () => {
16
16
  expect(dispatcher).toBeDefined()
17
17
  })
18
18
 
@@ -26,12 +26,12 @@ describe('@owlmeans/auth-common — DISPATCHER module declaration', () => {
26
26
  expect(dispatcher?.route.route.path).toBe(DISPATCHER_PATH)
27
27
  })
28
28
 
29
- test('DISPATCHER module is sticky (always registered in every app router)', () => {
29
+ test('DISPATCHER entrypoint is sticky (always registered in every app router)', () => {
30
30
  expect(dispatcher?.sticky).toBe(true)
31
31
  })
32
32
 
33
- test('DISPATCHER_AUTHEN backend module is distinct', () => {
34
- const dispatcherAuthen = modules.find(m => m.route.route.alias === DISPATCHER_AUTHEN)
33
+ test('DISPATCHER_AUTHEN backend entrypoint is distinct', () => {
34
+ const dispatcherAuthen = entrypoints.find(m => m.route.route.alias === DISPATCHER_AUTHEN)
35
35
  expect(dispatcherAuthen).toBeDefined()
36
36
  expect(dispatcherAuthen?.sticky).toBeFalsy()
37
37
  })
@@ -1,3 +0,0 @@
1
- export declare const modules: import("@owlmeans/entrypoint").CommonEntrypoint[];
2
- export declare const managerModules: import("@owlmeans/entrypoint").CommonEntrypoint[];
3
- //# sourceMappingURL=modules.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"modules.d.ts","sourceRoot":"","sources":["../src/modules.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,OAAO,mDAkCnB,CAAA;AAED,eAAO,MAAM,cAAc,mDAW1B,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"modules.js","sourceRoot":"","sources":["../src/modules.ts"],"names":[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