@jskit-ai/auth-core 0.1.149 → 0.1.151
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.json +3 -3
- package/src/server/authActor.js +8 -35
- package/src/server/lib/authPolicySupport.js +1 -6
- package/src/server/lib/index.js +0 -1
- package/src/server/services/authSessionEventsService.js +1 -2
- package/src/shared/authSecurityStatus.js +1 -7
- package/test/authContract.test.js +11 -15
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.151",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "node --test"
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"@fastify/cookie": "^11.0.2",
|
|
60
60
|
"@fastify/csrf-protection": "^7.1.0",
|
|
61
61
|
"@fastify/rate-limit": "^10.3.0",
|
|
62
|
-
"@jskit-ai/kernel": "0.1.
|
|
62
|
+
"@jskit-ai/kernel": "0.1.153",
|
|
63
63
|
"json-rest-schema": "^1.0.17"
|
|
64
64
|
},
|
|
65
65
|
"jskit": {
|
|
@@ -132,7 +132,7 @@
|
|
|
132
132
|
"mutations": {
|
|
133
133
|
"dependencies": {
|
|
134
134
|
"runtime": {
|
|
135
|
-
"@jskit-ai/kernel": "0.1.
|
|
135
|
+
"@jskit-ai/kernel": "0.1.153",
|
|
136
136
|
"@fastify/cookie": "^11.0.2",
|
|
137
137
|
"@fastify/csrf-protection": "^7.1.0",
|
|
138
138
|
"@fastify/rate-limit": "^10.3.0"
|
package/src/server/authActor.js
CHANGED
|
@@ -24,19 +24,13 @@ function createAuthIdentityId(provider, providerUserId) {
|
|
|
24
24
|
|
|
25
25
|
function normalizeAuthActor(value = {}, options = {}) {
|
|
26
26
|
const source = value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
27
|
-
const provider = normalizeAuthProviderId(source.provider ||
|
|
27
|
+
const provider = normalizeAuthProviderId(source.provider || options.provider, {
|
|
28
28
|
fallback: normalizeAuthProviderId(options.provider, { fallback: "unknown" })
|
|
29
29
|
});
|
|
30
|
-
const providerUserId = normalizeProviderUserId(
|
|
31
|
-
source.providerUserId ||
|
|
32
|
-
source.authProviderUserSid ||
|
|
33
|
-
source.sub ||
|
|
34
|
-
source.userId ||
|
|
35
|
-
source.id
|
|
36
|
-
);
|
|
30
|
+
const providerUserId = normalizeProviderUserId(source.providerUserId);
|
|
37
31
|
const email = normalizeEmail(source.email || "");
|
|
38
|
-
const displayName = normalizeDisplayName(source.displayName
|
|
39
|
-
const appUserId = normalizeOpaqueId(source.appUserId
|
|
32
|
+
const displayName = normalizeDisplayName(source.displayName, email);
|
|
33
|
+
const appUserId = normalizeOpaqueId(source.appUserId, {
|
|
40
34
|
fallback: null
|
|
41
35
|
});
|
|
42
36
|
const id = appUserId || providerUserId;
|
|
@@ -58,40 +52,19 @@ function normalizeAuthActor(value = {}, options = {}) {
|
|
|
58
52
|
});
|
|
59
53
|
}
|
|
60
54
|
|
|
61
|
-
function buildLegacyProfileFromActor(actorLike) {
|
|
62
|
-
const actor = normalizeAuthActor(actorLike);
|
|
63
|
-
if (!actor) {
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
return Object.freeze({
|
|
67
|
-
id: actor.id || actor.appUserId || actor.providerUserId || actor.authIdentityId,
|
|
68
|
-
email: actor.email,
|
|
69
|
-
displayName: actor.displayName,
|
|
70
|
-
authProvider: actor.provider,
|
|
71
|
-
authProviderUserSid: actor.providerUserId
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
|
|
75
55
|
function normalizeAuthResult(value = {}, options = {}) {
|
|
76
56
|
const source = value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
77
|
-
const actor = normalizeAuthActor(source.actor, options)
|
|
78
|
-
|
|
79
|
-
profileSource: "users"
|
|
80
|
-
});
|
|
81
|
-
const profile = source.profile && typeof source.profile === "object"
|
|
82
|
-
? source.profile
|
|
83
|
-
: buildLegacyProfileFromActor(actor);
|
|
57
|
+
const actor = normalizeAuthActor(source.actor, options);
|
|
58
|
+
const { profile: _profile, ...result } = source;
|
|
84
59
|
|
|
85
60
|
return Object.freeze({
|
|
86
|
-
...
|
|
87
|
-
...(actor ? { actor } : {})
|
|
88
|
-
...(profile ? { profile } : {})
|
|
61
|
+
...result,
|
|
62
|
+
...(actor ? { actor } : {})
|
|
89
63
|
});
|
|
90
64
|
}
|
|
91
65
|
|
|
92
66
|
export {
|
|
93
67
|
createAuthIdentityId,
|
|
94
68
|
normalizeAuthActor,
|
|
95
|
-
buildLegacyProfileFromActor,
|
|
96
69
|
normalizeAuthResult
|
|
97
70
|
};
|
|
@@ -22,15 +22,10 @@ function assertAuthPolicyDeps(deps = {}) {
|
|
|
22
22
|
|
|
23
23
|
function normalizeActorResolution(result) {
|
|
24
24
|
const source = asObject(result);
|
|
25
|
-
const actor = Object.hasOwn(source, "actor")
|
|
26
|
-
? source.actor
|
|
27
|
-
: Object.hasOwn(source, "profile")
|
|
28
|
-
? source.profile
|
|
29
|
-
: null;
|
|
30
25
|
|
|
31
26
|
return {
|
|
32
27
|
authenticated: Boolean(source.authenticated),
|
|
33
|
-
actor,
|
|
28
|
+
actor: Object.hasOwn(source, "actor") ? source.actor : null,
|
|
34
29
|
transientFailure: Boolean(source.transientFailure)
|
|
35
30
|
};
|
|
36
31
|
}
|
package/src/server/lib/index.js
CHANGED
|
@@ -56,12 +56,7 @@ function normalizeAuthSecurityStatus(value = {}) {
|
|
|
56
56
|
const authMethods = (Array.isArray(source.authMethods) ? source.authMethods : [])
|
|
57
57
|
.map((entry) => normalizeAuthMethodStatus(entry))
|
|
58
58
|
.filter(Boolean);
|
|
59
|
-
const policySource =
|
|
60
|
-
source.policy && typeof source.policy === "object"
|
|
61
|
-
? source.policy
|
|
62
|
-
: source.authPolicy && typeof source.authPolicy === "object"
|
|
63
|
-
? source.authPolicy
|
|
64
|
-
: {};
|
|
59
|
+
const policySource = source.policy && typeof source.policy === "object" ? source.policy : {};
|
|
65
60
|
const minimumEnabledMethods = Number.isInteger(Number(policySource.minimumEnabledMethods))
|
|
66
61
|
? Math.max(1, Number(policySource.minimumEnabledMethods))
|
|
67
62
|
: AUTH_METHOD_MINIMUM_ENABLED;
|
|
@@ -87,7 +82,6 @@ function normalizeAuthSecurityStatus(value = {}) {
|
|
|
87
82
|
methods: Object.freeze([])
|
|
88
83
|
}),
|
|
89
84
|
policy,
|
|
90
|
-
authPolicy: policy,
|
|
91
85
|
actions,
|
|
92
86
|
authMethods: Object.freeze(authMethods)
|
|
93
87
|
});
|
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
normalizeAuthSecurityStatus
|
|
11
11
|
} from "../src/shared/authSecurityStatus.js";
|
|
12
12
|
import {
|
|
13
|
-
buildLegacyProfileFromActor,
|
|
14
13
|
normalizeAuthActor,
|
|
15
14
|
normalizeAuthResult
|
|
16
15
|
} from "../src/server/authActor.js";
|
|
@@ -85,10 +84,10 @@ test("normalizeAuthCapabilities returns one provider-neutral feature shape", ()
|
|
|
85
84
|
);
|
|
86
85
|
});
|
|
87
86
|
|
|
88
|
-
test("normalizeAuthActor builds the
|
|
87
|
+
test("normalizeAuthActor builds the canonical actor", () => {
|
|
89
88
|
const actor = normalizeAuthActor({
|
|
90
|
-
|
|
91
|
-
|
|
89
|
+
provider: "supabase",
|
|
90
|
+
providerUserId: "abc-123",
|
|
92
91
|
email: " ADA@example.COM ",
|
|
93
92
|
displayName: "Ada",
|
|
94
93
|
appUserId: 42,
|
|
@@ -105,14 +104,12 @@ test("normalizeAuthActor builds the stable actor and legacy profile bridge", ()
|
|
|
105
104
|
appUserId: "42",
|
|
106
105
|
profileSource: "users"
|
|
107
106
|
});
|
|
108
|
-
assert.deepEqual(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
});
|
|
115
|
-
assert.deepEqual(normalizeAuthResult({ authenticated: true, actor }).profile, buildLegacyProfileFromActor(actor));
|
|
107
|
+
assert.deepEqual(normalizeAuthResult({ authenticated: true, actor }).actor, actor);
|
|
108
|
+
assert.equal(Object.hasOwn(normalizeAuthResult({ authenticated: true, actor }), "profile"), false);
|
|
109
|
+
assert.equal(
|
|
110
|
+
Object.hasOwn(normalizeAuthResult({ authenticated: true, actor, profile: actor }), "profile"),
|
|
111
|
+
false
|
|
112
|
+
);
|
|
116
113
|
});
|
|
117
114
|
|
|
118
115
|
test("normalizeAuthActor preserves opaque app user ids", () => {
|
|
@@ -126,7 +123,6 @@ test("normalizeAuthActor preserves opaque app user ids", () => {
|
|
|
126
123
|
|
|
127
124
|
assert.equal(actor.id, "app-user-1");
|
|
128
125
|
assert.equal(actor.appUserId, "app-user-1");
|
|
129
|
-
assert.equal(buildLegacyProfileFromActor(actor).id, "app-user-1");
|
|
130
126
|
});
|
|
131
127
|
|
|
132
128
|
test("normalizeAuthActor exposes projected app user id as the stable actor id", () => {
|
|
@@ -154,7 +150,7 @@ test("normalizeAuthActor falls back to provider user id when no app user is proj
|
|
|
154
150
|
assert.equal(actor.providerUserId, "provider-user-1");
|
|
155
151
|
});
|
|
156
152
|
|
|
157
|
-
test("normalizeAuthSecurityStatus emits
|
|
153
|
+
test("normalizeAuthSecurityStatus emits the canonical policy", () => {
|
|
158
154
|
const status = buildSecurityStatusFromAuthMethodsStatus(
|
|
159
155
|
{
|
|
160
156
|
methods: [
|
|
@@ -181,7 +177,7 @@ test("normalizeAuthSecurityStatus emits policy and legacy authPolicy aliases", (
|
|
|
181
177
|
minimumEnabledMethods: 1,
|
|
182
178
|
enabledMethodsCount: 1
|
|
183
179
|
});
|
|
184
|
-
assert.equal(status
|
|
180
|
+
assert.equal(Object.hasOwn(status, "authPolicy"), false);
|
|
185
181
|
assert.equal(status.actions.changePassword, true);
|
|
186
182
|
assert.equal(status.actions.linkProvider, false);
|
|
187
183
|
assert.deepEqual(normalizeAuthSecurityStatus(status), status);
|