@jskit-ai/auth-core 0.1.15 → 0.1.17
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/package.descriptor.mjs +3 -2
- package/package.json +2 -3
- package/src/server/lib/actionContextContributor.js +0 -1
- package/src/server/lib/index.js +0 -1
- package/src/server/providers/FastifyAuthPolicyServiceProvider.js +9 -14
- package/test/providerRuntime.test.js +7 -9
- package/src/server/lib/tokens.js +0 -3
package/package.descriptor.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export default Object.freeze({
|
|
2
2
|
"packageVersion": 1,
|
|
3
3
|
"packageId": "@jskit-ai/auth-core",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.17",
|
|
5
|
+
"kind": "runtime",
|
|
5
6
|
"dependsOn": [
|
|
6
7
|
"@jskit-ai/value-app-config-shared"
|
|
7
8
|
],
|
|
@@ -68,7 +69,7 @@ export default Object.freeze({
|
|
|
68
69
|
"mutations": {
|
|
69
70
|
"dependencies": {
|
|
70
71
|
"runtime": {
|
|
71
|
-
"@jskit-ai/kernel": "0.1.
|
|
72
|
+
"@jskit-ai/kernel": "0.1.18",
|
|
72
73
|
"@fastify/cookie": "^11.0.2",
|
|
73
74
|
"@fastify/csrf-protection": "^7.1.0",
|
|
74
75
|
"@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.
|
|
3
|
+
"version": "0.1.17",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "node --test"
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
"./server/lib/index": "./src/server/lib/index.js",
|
|
16
16
|
"./server/lib/plugin": "./src/server/lib/plugin.js",
|
|
17
17
|
"./server/lib/routeMeta": "./src/server/lib/routeMeta.js",
|
|
18
|
-
"./server/lib/tokens": "./src/server/lib/tokens.js",
|
|
19
18
|
"./client": "./src/client/index.js",
|
|
20
19
|
"./client/authApi": "./src/client/authApi.js",
|
|
21
20
|
"./client/signOutFlow": "./src/client/signOutFlow.js",
|
|
@@ -44,7 +43,7 @@
|
|
|
44
43
|
"./shared/commands/authSessionReadCommand": "./src/shared/commands/authSessionReadCommand.js"
|
|
45
44
|
},
|
|
46
45
|
"dependencies": {
|
|
47
|
-
"@jskit-ai/kernel": "0.1.
|
|
46
|
+
"@jskit-ai/kernel": "0.1.18",
|
|
48
47
|
"@fastify/cookie": "^11.0.2",
|
|
49
48
|
"@fastify/csrf-protection": "^7.1.0",
|
|
50
49
|
"@fastify/rate-limit": "^10.3.0",
|
package/src/server/lib/index.js
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
import { KERNEL_TOKENS } from "@jskit-ai/kernel/shared/support/tokens";
|
|
2
1
|
import { registerActionContextContributor } from "@jskit-ai/kernel/server/actions";
|
|
3
2
|
import { registerRouteVisibilityResolver } from "@jskit-ai/kernel/server/http";
|
|
4
3
|
import { authPolicyPlugin } from "../lib/plugin.js";
|
|
5
|
-
import { AUTH_POLICY_CONTEXT_RESOLVER_TOKEN } from "../lib/tokens.js";
|
|
6
4
|
import { createAuthActionContextContributor } from "../lib/actionContextContributor.js";
|
|
7
5
|
import { createAuthRouteVisibilityResolver } from "../lib/routeVisibilityResolver.js";
|
|
8
6
|
|
|
9
|
-
const AUTH_ACTION_CONTEXT_CONTRIBUTOR_TOKEN = "auth.policy.actionContextContributor";
|
|
10
|
-
const AUTH_ROUTE_VISIBILITY_RESOLVER_TOKEN = "auth.policy.routeVisibilityResolver";
|
|
11
|
-
|
|
12
7
|
function parseBoolean(value, fallback = false) {
|
|
13
8
|
const raw = String(value || "").trim().toLowerCase();
|
|
14
9
|
if (!raw) {
|
|
@@ -48,21 +43,21 @@ class FastifyAuthPolicyServiceProvider {
|
|
|
48
43
|
}
|
|
49
44
|
|
|
50
45
|
if (
|
|
51
|
-
!app.has(
|
|
46
|
+
!app.has("auth.policy.actionContextContributor") &&
|
|
52
47
|
typeof app.singleton === "function" &&
|
|
53
48
|
typeof app.tag === "function"
|
|
54
49
|
) {
|
|
55
|
-
registerActionContextContributor(app,
|
|
50
|
+
registerActionContextContributor(app, "auth.policy.actionContextContributor", () =>
|
|
56
51
|
createAuthActionContextContributor()
|
|
57
52
|
);
|
|
58
53
|
}
|
|
59
54
|
|
|
60
55
|
if (
|
|
61
|
-
!app.has(
|
|
56
|
+
!app.has("auth.policy.routeVisibilityResolver") &&
|
|
62
57
|
typeof app.singleton === "function" &&
|
|
63
58
|
typeof app.tag === "function"
|
|
64
59
|
) {
|
|
65
|
-
registerRouteVisibilityResolver(app,
|
|
60
|
+
registerRouteVisibilityResolver(app, "auth.policy.routeVisibilityResolver", () =>
|
|
66
61
|
createAuthRouteVisibilityResolver()
|
|
67
62
|
);
|
|
68
63
|
}
|
|
@@ -76,17 +71,17 @@ class FastifyAuthPolicyServiceProvider {
|
|
|
76
71
|
throw new Error("FastifyAuthPolicyServiceProvider requires authService binding.");
|
|
77
72
|
}
|
|
78
73
|
|
|
79
|
-
const env = app.has(
|
|
80
|
-
const fastify = app.make(
|
|
74
|
+
const env = app.has("jskit.env") ? app.make("jskit.env") : {};
|
|
75
|
+
const fastify = app.make("jskit.fastify");
|
|
81
76
|
const authService = app.make("authService");
|
|
82
77
|
const resolveContext =
|
|
83
|
-
typeof app.has === "function" && app.has(
|
|
84
|
-
? app.make(
|
|
78
|
+
typeof app.has === "function" && app.has("auth.policy.contextResolver")
|
|
79
|
+
? app.make("auth.policy.contextResolver")
|
|
85
80
|
: null;
|
|
86
81
|
|
|
87
82
|
if (resolveContext != null && typeof resolveContext !== "function") {
|
|
88
83
|
throw new Error(
|
|
89
|
-
|
|
84
|
+
"FastifyAuthPolicyServiceProvider requires auth.policy.contextResolver to be a function when provided."
|
|
90
85
|
);
|
|
91
86
|
}
|
|
92
87
|
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
2
|
import test from "node:test";
|
|
3
|
-
import { KERNEL_TOKENS } from "@jskit-ai/kernel/shared/support/tokens";
|
|
4
|
-
import { AUTH_POLICY_CONTEXT_RESOLVER_TOKEN } from "../src/server/lib/tokens.js";
|
|
5
3
|
import { FastifyAuthPolicyServiceProvider } from "../src/server/providers/FastifyAuthPolicyServiceProvider.js";
|
|
6
4
|
import { createFakeFastifyPolicyRuntime } from "../../../tooling/testUtils/fakeFastify.mjs";
|
|
7
5
|
|
|
8
6
|
test("FastifyAuthPolicyServiceProvider registers auth policy plugin through provider boot", async () => {
|
|
9
7
|
const { fastify, state } = createFakeFastifyPolicyRuntime();
|
|
10
8
|
const bag = new Map([
|
|
11
|
-
[
|
|
12
|
-
[
|
|
13
|
-
[
|
|
9
|
+
["jskit.fastify", fastify],
|
|
10
|
+
["jskit.env", { NODE_ENV: "test" }],
|
|
11
|
+
["jskit.logger", console],
|
|
14
12
|
[
|
|
15
13
|
"authService",
|
|
16
14
|
{
|
|
@@ -52,9 +50,9 @@ test("FastifyAuthPolicyServiceProvider registers auth policy plugin through prov
|
|
|
52
50
|
test("FastifyAuthPolicyServiceProvider wires optional auth policy context resolver", async () => {
|
|
53
51
|
const { fastify, state } = createFakeFastifyPolicyRuntime();
|
|
54
52
|
const bag = new Map([
|
|
55
|
-
[
|
|
56
|
-
[
|
|
57
|
-
[
|
|
53
|
+
["jskit.fastify", fastify],
|
|
54
|
+
["jskit.env", { NODE_ENV: "test" }],
|
|
55
|
+
["jskit.logger", console],
|
|
58
56
|
[
|
|
59
57
|
"authService",
|
|
60
58
|
{
|
|
@@ -68,7 +66,7 @@ test("FastifyAuthPolicyServiceProvider wires optional auth policy context resolv
|
|
|
68
66
|
}
|
|
69
67
|
],
|
|
70
68
|
[
|
|
71
|
-
|
|
69
|
+
"auth.policy.contextResolver",
|
|
72
70
|
async ({ actor, request }) => ({
|
|
73
71
|
workspace: { id: 11, slug: String(request?.params?.workspaceSlug || "").toLowerCase() },
|
|
74
72
|
membership: { roleId: "member" },
|
package/src/server/lib/tokens.js
DELETED