@jskit-ai/auth-core 0.1.107 → 0.1.109

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.
@@ -1,7 +1,7 @@
1
1
  export default Object.freeze({
2
2
  "packageVersion": 1,
3
3
  "packageId": "@jskit-ai/auth-core",
4
- "version": "0.1.107",
4
+ "version": "0.1.109",
5
5
  "kind": "runtime",
6
6
  "dependsOn": [
7
7
  "@jskit-ai/value-app-config-shared"
@@ -74,7 +74,7 @@ export default Object.freeze({
74
74
  "mutations": {
75
75
  "dependencies": {
76
76
  "runtime": {
77
- "@jskit-ai/kernel": "0.1.109",
77
+ "@jskit-ai/kernel": "0.1.111",
78
78
  "@fastify/cookie": "^11.0.2",
79
79
  "@fastify/csrf-protection": "^7.1.0",
80
80
  "@fastify/rate-limit": "^10.3.0"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/auth-core",
3
- "version": "0.1.107",
3
+ "version": "0.1.109",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "node --test"
@@ -54,7 +54,7 @@
54
54
  "./shared/commands/authSessionReadCommand": "./src/shared/commands/authSessionReadCommand.js"
55
55
  },
56
56
  "dependencies": {
57
- "@jskit-ai/kernel": "0.1.109",
57
+ "@jskit-ai/kernel": "0.1.111",
58
58
  "@fastify/cookie": "^11.0.2",
59
59
  "@fastify/csrf-protection": "^7.1.0",
60
60
  "@fastify/rate-limit": "^10.3.0",
@@ -49,8 +49,22 @@ function resolveAuthServiceDecorators(scope) {
49
49
  .map((entry) => entry.decorator);
50
50
  }
51
51
 
52
+ function applyAuthServiceDecorators(scope, authService) {
53
+ let decoratedAuthService = authService;
54
+
55
+ for (const decorator of resolveAuthServiceDecorators(scope)) {
56
+ decoratedAuthService = decorator.decorateAuthService(decoratedAuthService);
57
+ if (!decoratedAuthService || typeof decoratedAuthService !== "object") {
58
+ throw new Error(`Auth service decorator "${decorator.decoratorId}" must return an auth service object.`);
59
+ }
60
+ }
61
+
62
+ return decoratedAuthService;
63
+ }
64
+
52
65
  export {
53
66
  AUTH_SERVICE_DECORATOR_TAG,
67
+ applyAuthServiceDecorators,
54
68
  registerAuthServiceDecorator,
55
69
  resolveAuthServiceDecorators
56
70
  };
@@ -3,6 +3,7 @@ import test from "node:test";
3
3
  import { createApplication } from "@jskit-ai/kernel/_testable";
4
4
  import {
5
5
  AUTH_SERVICE_DECORATOR_TAG,
6
+ applyAuthServiceDecorators,
6
7
  registerAuthServiceDecorator,
7
8
  resolveAuthServiceDecorators
8
9
  } from "../src/server/authServiceDecoratorRegistry.js";
@@ -39,13 +40,26 @@ test("auth service decorator registry resolves decorators in order", () => {
39
40
  ["alpha", "zeta"]
40
41
  );
41
42
 
42
- const decorated = decorators.reduce(
43
- (service, decorator) => decorator.decorateAuthService(service),
44
- { trace: [] }
45
- );
43
+ const decorated = applyAuthServiceDecorators(app, { trace: [] });
46
44
  assert.deepEqual(decorated.trace, ["alpha", "zeta"]);
47
45
  });
48
46
 
47
+ test("auth service decorator registry rejects invalid decorated services", () => {
48
+ const app = createApplication();
49
+
50
+ registerAuthServiceDecorator(app, "test.auth.decorator.invalid", () => ({
51
+ decoratorId: "invalid",
52
+ decorateAuthService() {
53
+ return null;
54
+ }
55
+ }));
56
+
57
+ assert.throws(
58
+ () => applyAuthServiceDecorators(app, {}),
59
+ /Auth service decorator "invalid" must return an auth service object/
60
+ );
61
+ });
62
+
49
63
  test("auth service decorator registry exports canonical tag", () => {
50
64
  assert.equal(AUTH_SERVICE_DECORATOR_TAG, "jskit.auth.service.decorators");
51
65
  });