@plitzi/sdk-auth 0.33.2 → 0.34.0
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/CHANGELOG.md +15 -0
- package/dist/AuthContextProvider.mjs +4 -4
- package/dist/AuthManager.d.ts +3 -2
- package/dist/AuthManager.mjs +4 -1
- package/dist/AuthProvider.d.ts +13 -2
- package/dist/AuthProvider.mjs +25 -8
- package/dist/index.mjs +7 -7
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @plitzi/sdk-auth
|
|
2
2
|
|
|
3
|
+
## 0.34.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- v0.34.0
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [5aceda0]
|
|
12
|
+
- Updated dependencies
|
|
13
|
+
- Updated dependencies [5aceda0]
|
|
14
|
+
- @plitzi/sdk-shared@0.34.0
|
|
15
|
+
- @plitzi/sdk-navigation@0.34.0
|
|
16
|
+
- @plitzi/sdk-schema@0.34.0
|
|
17
|
+
|
|
3
18
|
## 0.33.2
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import e from "./
|
|
2
|
-
import
|
|
1
|
+
import { AuthContext as e } from "./AuthContext.mjs";
|
|
2
|
+
import t from "./hooks/useAuth/index.mjs";
|
|
3
3
|
import { use as n, useMemo as r, useRef as i } from "react";
|
|
4
4
|
import { QueryBuilderEvaluator as a } from "@plitzi/plitzi-ui/QueryBuilder";
|
|
5
5
|
import o from "@plitzi/sdk-navigation/hooks/useNavigation";
|
|
@@ -65,7 +65,7 @@ var f = [
|
|
|
65
65
|
E,
|
|
66
66
|
b,
|
|
67
67
|
y
|
|
68
|
-
]), { manager: O, loading: k, authenticated: A, state: j, bootstrapUser: M, bootstrapToken: N, peekedUser: P, peekedToken: F } =
|
|
68
|
+
]), { manager: O, loading: k, authenticated: A, state: j, bootstrapUser: M, bootstrapToken: N, peekedUser: P, peekedToken: F } = t({
|
|
69
69
|
server: h,
|
|
70
70
|
isHydrating: _,
|
|
71
71
|
provider: b.userProvider ?? "",
|
|
@@ -93,7 +93,7 @@ var f = [
|
|
|
93
93
|
g,
|
|
94
94
|
B
|
|
95
95
|
]);
|
|
96
|
-
return /* @__PURE__ */ d(
|
|
96
|
+
return /* @__PURE__ */ d(e, {
|
|
97
97
|
value: V,
|
|
98
98
|
children: !k && m
|
|
99
99
|
});
|
package/dist/AuthManager.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { default as AuthProvider, AuthBootstrap, AuthEventListener } from './AuthProvider';
|
|
2
2
|
import { AuthProviderSettings } from './types';
|
|
3
|
-
import { AuthFailureReason, AuthState, TokenResult } from '@plitzi/sdk-shared';
|
|
3
|
+
import { AuthFailureReason, AuthState, LoginResult, TokenResult } from '@plitzi/sdk-shared';
|
|
4
4
|
export type AuthProviderFactory<U = Record<string, unknown>> = (settings: AuthProviderSettings) => AuthProvider<U>;
|
|
5
5
|
/**
|
|
6
6
|
* Adds an auth provider a space can then select by name in its settings. Spaces run against whichever backend their
|
|
@@ -52,7 +52,8 @@ export declare class AuthManager<U = Record<string, unknown>> {
|
|
|
52
52
|
* disagrees.
|
|
53
53
|
*/
|
|
54
54
|
init(bootstrap?: AuthBootstrap<U>): Promise<void>;
|
|
55
|
-
|
|
55
|
+
/** With no provider there is nothing to sign in against, which is a refusal like any other — and has to say so. */
|
|
56
|
+
login(...args: Parameters<AuthProvider<U>['login']>): Promise<LoginResult>;
|
|
56
57
|
refresh(): Promise<TokenResult | undefined>;
|
|
57
58
|
revalidate(force?: boolean): Promise<boolean>;
|
|
58
59
|
invalidate(reason?: AuthFailureReason): void;
|
package/dist/AuthManager.mjs
CHANGED
|
@@ -42,7 +42,10 @@ var t = /* @__PURE__ */ new Map([["basic", (t) => new e(t)]]), n = (e, n) => {
|
|
|
42
42
|
return this.provider.init(e);
|
|
43
43
|
}
|
|
44
44
|
login(...e) {
|
|
45
|
-
return this.provider?.login(...e) ?? Promise.resolve(
|
|
45
|
+
return this.provider?.login(...e) ?? Promise.resolve({
|
|
46
|
+
ok: !1,
|
|
47
|
+
reason: "missing"
|
|
48
|
+
});
|
|
46
49
|
}
|
|
47
50
|
refresh() {
|
|
48
51
|
return this.provider?.refresh() ?? Promise.resolve(void 0);
|
package/dist/AuthProvider.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AuthFailureReason, AuthResult, AuthState, Schema, TokenResult } from '@plitzi/sdk-shared';
|
|
1
|
+
import { AuthFailureReason, AuthResult, AuthState, LoginResult, Schema, TokenResult } from '@plitzi/sdk-shared';
|
|
2
2
|
/** Why a state changed. Not control flow — it is what makes an auth trace readable, and every transition below
|
|
3
3
|
* names one, because "it went to guest" is not a diagnosis and "the hint cookie was gone" is. */
|
|
4
4
|
export type AuthStateReason = 'bootstrap' | 'restored' | 'granted' | 'renewed' | 'identity' | 'redirect' | 'exchanged' | 'no-provider' | 'skip-auth' | 'hint-missing' | 'no-evidence' | 'signed-out' | 'another-tab' | 'settled' | 'authenticating';
|
|
@@ -121,7 +121,15 @@ declare abstract class AuthProvider<U = Record<string, unknown>> {
|
|
|
121
121
|
private decide;
|
|
122
122
|
/** Drops timers and window listeners. Called when the provider is replaced, so a re-configured space leaves none behind. */
|
|
123
123
|
dispose(): void;
|
|
124
|
-
|
|
124
|
+
/**
|
|
125
|
+
* Resolves to WHY when it does not resolve to a session.
|
|
126
|
+
*
|
|
127
|
+
* It used to resolve to `undefined` for every refusal there is, which left the one screen that has to explain
|
|
128
|
+
* itself — a sign-in form — with a single sentence to cover a wrong password, an address that has never been
|
|
129
|
+
* confirmed, a blocked account and a backend that could not be reached. Three quarters of the time it was telling
|
|
130
|
+
* somebody to check credentials that were perfectly correct.
|
|
131
|
+
*/
|
|
132
|
+
login(params: Record<string, unknown>): Promise<LoginResult>;
|
|
125
133
|
/**
|
|
126
134
|
* A credential obtained in the browser — by a client-side identity provider, or by a redirect coming back from
|
|
127
135
|
* one — is unknown to the server that renders the pages. It therefore renders every one of them as a guest while
|
|
@@ -130,6 +138,9 @@ declare abstract class AuthProvider<U = Record<string, unknown>> {
|
|
|
130
138
|
* Handing the credential over closes that gap: the server verifies it with the provider and establishes its own
|
|
131
139
|
* session, cookie and all, so the next server-rendered page already knows. Providers whose grants came from that
|
|
132
140
|
* same server return undefined here and nothing happens.
|
|
141
|
+
*
|
|
142
|
+
* Answers with the reason when it ended the session, so the caller can say which refusal this was rather than
|
|
143
|
+
* inferring one from the state it is left in.
|
|
133
144
|
*/
|
|
134
145
|
private handOffToServer;
|
|
135
146
|
refresh(): Promise<TokenResult | undefined>;
|
package/dist/AuthProvider.mjs
CHANGED
|
@@ -128,14 +128,29 @@ var s = 60, c = 300, l = 2147483647, u = class {
|
|
|
128
128
|
async login(e) {
|
|
129
129
|
this.setState("authenticating", "authenticating");
|
|
130
130
|
let t = await this.requestLogin(e);
|
|
131
|
-
if (!t.ok) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
|
|
131
|
+
if (!t.ok) return this.endSession(t.reason), {
|
|
132
|
+
ok: !1,
|
|
133
|
+
reason: t.reason
|
|
134
|
+
};
|
|
135
|
+
this.adopt(t);
|
|
136
|
+
let n = await this.handOffToServer();
|
|
137
|
+
return n ? {
|
|
138
|
+
ok: !1,
|
|
139
|
+
reason: n
|
|
140
|
+
} : (!this.session.user && this.capabilities.identity && await this.loadIdentity(), this.state === "authenticated" ? (this.emit({
|
|
136
141
|
type: "login",
|
|
137
142
|
token: this.session.token
|
|
138
|
-
}),
|
|
143
|
+
}), {
|
|
144
|
+
ok: !0,
|
|
145
|
+
...this.session.token ?? {
|
|
146
|
+
accessToken: "",
|
|
147
|
+
expiresAt: null,
|
|
148
|
+
refreshToken: null
|
|
149
|
+
}
|
|
150
|
+
}) : {
|
|
151
|
+
ok: !1,
|
|
152
|
+
reason: "inactive"
|
|
153
|
+
});
|
|
139
154
|
}
|
|
140
155
|
async handOffToServer() {
|
|
141
156
|
let e = await this.requestExchange();
|
|
@@ -148,7 +163,7 @@ var s = 60, c = 300, l = 2147483647, u = class {
|
|
|
148
163
|
this.offline = !0;
|
|
149
164
|
return;
|
|
150
165
|
}
|
|
151
|
-
this.endSession(e.reason);
|
|
166
|
+
return this.endSession(e.reason), e.reason;
|
|
152
167
|
}
|
|
153
168
|
}
|
|
154
169
|
async refresh() {
|
|
@@ -230,7 +245,9 @@ var s = 60, c = 300, l = 2147483647, u = class {
|
|
|
230
245
|
return n() - this.session.validatedAt < this.revalidateSeconds;
|
|
231
246
|
}
|
|
232
247
|
hasEvidence() {
|
|
233
|
-
|
|
248
|
+
if (this.session.token?.accessToken || this.session.token?.refreshToken) return !0;
|
|
249
|
+
let t = e(this.hintCookie);
|
|
250
|
+
return t?.refreshExpiresAt !== void 0 && t.refreshExpiresAt <= n() ? !1 : !!t;
|
|
234
251
|
}
|
|
235
252
|
scheduleRenewal() {
|
|
236
253
|
clearTimeout(this.renewalTimer), this.renewalTimer = void 0;
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import r from "./
|
|
4
|
-
import
|
|
5
|
-
import s from "./
|
|
6
|
-
import
|
|
1
|
+
import { AuthContext as e } from "./AuthContext.mjs";
|
|
2
|
+
import { readSessionHint as t } from "./helpers/sessionHint.mjs";
|
|
3
|
+
import { nowInSeconds as n, tokenExpiresAt as r } from "./helpers/tokenClaims.mjs";
|
|
4
|
+
import i from "./AuthProvider.mjs";
|
|
5
|
+
import { AuthManager as a, getAuthProviderNames as o, registerAuthProvider as s } from "./AuthManager.mjs";
|
|
6
|
+
import c from "./hooks/useAuth/index.mjs";
|
|
7
7
|
import l from "./AuthContextProvider.mjs";
|
|
8
|
-
export {
|
|
8
|
+
export { e as AuthContext, l as AuthContextProvider, a as AuthManager, i as AuthProvider, o as getAuthProviderNames, n as nowInSeconds, t as readSessionHint, s as registerAuthProvider, r as tokenExpiresAt, c as useAuth };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plitzi/sdk-auth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.0",
|
|
4
4
|
"license": "AGPL-3.0",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -75,15 +75,15 @@
|
|
|
75
75
|
"build:prod": "vite build && node ../sdk-shared/scripts/generate-exports.mjs"
|
|
76
76
|
},
|
|
77
77
|
"dependencies": {
|
|
78
|
-
"@plitzi/plitzi-ui": "^1.6.
|
|
79
|
-
"@plitzi/sdk-navigation": "0.
|
|
80
|
-
"@plitzi/sdk-schema": "0.
|
|
81
|
-
"@plitzi/sdk-shared": "0.
|
|
78
|
+
"@plitzi/plitzi-ui": "^1.6.21",
|
|
79
|
+
"@plitzi/sdk-navigation": "0.34.0",
|
|
80
|
+
"@plitzi/sdk-schema": "0.34.0",
|
|
81
|
+
"@plitzi/sdk-shared": "0.34.0"
|
|
82
82
|
},
|
|
83
83
|
"devDependencies": {
|
|
84
84
|
"eslint": "^9.39.5",
|
|
85
85
|
"typescript": "^6.0.3",
|
|
86
|
-
"vite": "^8.
|
|
87
|
-
"vitest": "^
|
|
86
|
+
"vite": "^8.3.0",
|
|
87
|
+
"vitest": "^5.0.0"
|
|
88
88
|
}
|
|
89
89
|
}
|