@finueva/auth 0.1.0 → 0.3.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/README.md +32 -5
- package/THIRD_PARTY_NOTICES.md +52 -0
- package/dist/errors-B0S9-QGH.d.ts +100 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +999 -46
- package/dist/server.d.ts +7 -2
- package/dist/server.js +139 -30
- package/package.json +5 -2
- package/dist/errors-C-cHFWC7.d.ts +0 -55
package/README.md
CHANGED
|
@@ -16,15 +16,36 @@ const auth = createAuthClient({
|
|
|
16
16
|
appOrigin: window.location.origin,
|
|
17
17
|
});
|
|
18
18
|
|
|
19
|
+
const stop = auth.onAuthStateChange((state) => {
|
|
20
|
+
if (state.status === "cached") renderSessionHint(state.session);
|
|
21
|
+
if (state.status === "authenticated") renderVerifiedSession(state.session);
|
|
22
|
+
});
|
|
23
|
+
|
|
19
24
|
const session = await auth.getSession();
|
|
20
25
|
await auth.signIn({ email, password });
|
|
26
|
+
const organizations = await auth.listOrganizations();
|
|
27
|
+
const acceptance = await auth.acceptInvitation({ invitationId });
|
|
21
28
|
const credential = await auth.getDriveCredential({
|
|
22
29
|
workspace: { type: "personal" },
|
|
23
30
|
});
|
|
31
|
+
const organizationCredential = await auth.getDriveCredential({
|
|
32
|
+
workspace: { type: "organization", organizationId: organizations[0].id },
|
|
33
|
+
});
|
|
24
34
|
await auth.signOut();
|
|
35
|
+
stop();
|
|
25
36
|
```
|
|
26
37
|
|
|
27
|
-
The Auth session uses the Auth-owned HTTP-only cookie.
|
|
38
|
+
The Auth session uses the Auth-owned HTTP-only cookie. `getSession()` and `onSessionChange()` report Better Auth authority results only. `onAuthStateChange()` separately emits `loading`, non-authoritative `cached`, authoritative `authenticated`/`unauthenticated`, or non-authoritative `unavailable`; it verifies every cache hint immediately.
|
|
39
|
+
|
|
40
|
+
DOM browsers use local storage by default. Set `persistence` to `"session"`, `"memory"`, or a structural driver with `getItem`, `setItem`, and `removeItem`; Workers and Node default to memory. The one 16 KiB versioned snapshot contains only a normalized session and its Auth authority identity. It expires with the session and never contains cookies, passwords, Drive credentials, tokens, headers, workspace selection, Better Auth payloads, or errors. Persistence failure cannot change an Auth request result.
|
|
41
|
+
|
|
42
|
+
A workspace is either `{ type: "personal" }` or `{ type: "organization", organizationId }`; organization IDs must match `[A-Za-z0-9_-]{1,128}`. Workspace selections are strict and reject additional properties locally with `invalid_workspace_selection` before making a request.
|
|
43
|
+
|
|
44
|
+
`listOrganizations()` returns strict current `{ id, name, slug }` records from Better Auth authority. Results are not cached or persisted. Because the current upstream endpoint is unpaginated and silently capped at 100 records, the SDK fails closed rather than return an ambiguous list when that cap is reached.
|
|
45
|
+
|
|
46
|
+
`acceptInvitation({ invitationId })` performs one non-retried Better Auth acceptance and returns only `{ organizationId }`. Invitation details, recipient email, inviter identity, membership payloads, and raw authority errors are never exposed or persisted. Unknown, expired, canceled, accepted, and concurrently claimed invitations all report the same value-free `invitation_unavailable` conflict.
|
|
47
|
+
|
|
48
|
+
The browser retains at most one completed Drive credential in memory and renews it once it has two minutes remaining. Concurrent requests for the same workspace share one credential request. Selecting a different workspace never reuses the completed or in-flight credential for the previous workspace and replaces the retained credential. Passing `forceRefresh: true` requests a replacement after a Drive authentication failure; the SDK never replays a Drive request.
|
|
28
49
|
|
|
29
50
|
## Server
|
|
30
51
|
|
|
@@ -38,13 +59,19 @@ const auth = createServerAuth({
|
|
|
38
59
|
});
|
|
39
60
|
|
|
40
61
|
const session = await auth.getSession();
|
|
62
|
+
const organizations = await auth.listOrganizations();
|
|
63
|
+
const acceptance = await auth.acceptInvitation({ invitationId });
|
|
64
|
+
const credential = await auth.getDriveCredential({
|
|
65
|
+
workspace: { type: "organization", organizationId: organizations[0].id },
|
|
66
|
+
});
|
|
41
67
|
```
|
|
42
68
|
|
|
43
|
-
The server client is request-scoped. It forwards the incoming Auth cookie only to Auth and never sends it to Drive.
|
|
69
|
+
The server client is request-scoped and does not cache credentials. It forwards the incoming Auth cookie only to Auth and never sends it to Drive. Apply cookies returned by server invitation acceptance to the outgoing response with `acceptance.applyCookies(headers)`.
|
|
44
70
|
|
|
45
71
|
## Current Limits
|
|
46
72
|
|
|
47
|
-
-
|
|
48
|
-
- Cross-root SSO
|
|
49
|
-
- The package does not persist Drive credentials or expose Better Auth internals.
|
|
73
|
+
- Organization mutation and active-organization state are not exposed; callers select an organization returned by `listOrganizations()` explicitly.
|
|
74
|
+
- Cross-root SSO is not part of `0.1.0`.
|
|
75
|
+
- The package does not persist Drive credentials or expose Better Auth or Unstorage internals.
|
|
50
76
|
- Public errors are `AuthError` instances with stable, value-free codes.
|
|
77
|
+
- Organization contexts with more than 50 current teams fail with `organization_context_too_large` and status `422`.
|
package/THIRD_PARTY_NOTICES.md
CHANGED
|
@@ -98,3 +98,55 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
98
98
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
99
99
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
100
100
|
SOFTWARE.
|
|
101
|
+
|
|
102
|
+
## unstorage 1.17.5
|
|
103
|
+
|
|
104
|
+
Source: https://github.com/unjs/unstorage
|
|
105
|
+
|
|
106
|
+
MIT License
|
|
107
|
+
|
|
108
|
+
Copyright (c) Pooya Parsa <pooya@pi0.io>
|
|
109
|
+
|
|
110
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
111
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
112
|
+
in the Software without restriction, including without limitation the rights
|
|
113
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
114
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
115
|
+
furnished to do so, subject to the following conditions:
|
|
116
|
+
|
|
117
|
+
The above copyright notice and this permission notice shall be included in all
|
|
118
|
+
copies or substantial portions of the Software.
|
|
119
|
+
|
|
120
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
121
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
122
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
123
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
124
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
125
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
126
|
+
SOFTWARE.
|
|
127
|
+
|
|
128
|
+
## destr 2.0.5
|
|
129
|
+
|
|
130
|
+
Source: https://github.com/unjs/destr
|
|
131
|
+
|
|
132
|
+
MIT License
|
|
133
|
+
|
|
134
|
+
Copyright (c) Pooya Parsa <pooya@pi0.io>
|
|
135
|
+
|
|
136
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
137
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
138
|
+
in the Software without restriction, including without limitation the rights
|
|
139
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
140
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
141
|
+
furnished to do so, subject to the following conditions:
|
|
142
|
+
|
|
143
|
+
The above copyright notice and this permission notice shall be included in all
|
|
144
|
+
copies or substantial portions of the Software.
|
|
145
|
+
|
|
146
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
147
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
148
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
149
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
150
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
151
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
152
|
+
SOFTWARE.
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
//#region src/types.d.ts
|
|
2
|
+
interface AuthUser {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
email: string;
|
|
6
|
+
emailVerified: boolean;
|
|
7
|
+
image: string | null;
|
|
8
|
+
}
|
|
9
|
+
interface AuthSession {
|
|
10
|
+
id: string;
|
|
11
|
+
expiresAt: Date;
|
|
12
|
+
user: AuthUser;
|
|
13
|
+
}
|
|
14
|
+
interface AuthOrganization {
|
|
15
|
+
id: string;
|
|
16
|
+
name: string;
|
|
17
|
+
slug: string;
|
|
18
|
+
}
|
|
19
|
+
interface AcceptInvitationInput {
|
|
20
|
+
invitationId: string;
|
|
21
|
+
}
|
|
22
|
+
interface InvitationAcceptance {
|
|
23
|
+
organizationId: string;
|
|
24
|
+
}
|
|
25
|
+
type AuthState = {
|
|
26
|
+
status: "loading";
|
|
27
|
+
} | {
|
|
28
|
+
status: "cached";
|
|
29
|
+
session: AuthSession;
|
|
30
|
+
authoritative: false;
|
|
31
|
+
} | {
|
|
32
|
+
status: "authenticated";
|
|
33
|
+
session: AuthSession;
|
|
34
|
+
authoritative: true;
|
|
35
|
+
} | {
|
|
36
|
+
status: "unauthenticated";
|
|
37
|
+
session: null;
|
|
38
|
+
authoritative: true;
|
|
39
|
+
} | {
|
|
40
|
+
status: "unavailable";
|
|
41
|
+
session: AuthSession | null;
|
|
42
|
+
authoritative: false;
|
|
43
|
+
};
|
|
44
|
+
interface AuthPersistenceDriver {
|
|
45
|
+
getItem(key: string): string | null | Promise<string | null>;
|
|
46
|
+
setItem(key: string, value: string): void | Promise<void>;
|
|
47
|
+
removeItem(key: string): void | Promise<void>;
|
|
48
|
+
}
|
|
49
|
+
type AuthPersistence = "local" | "session" | "memory" | AuthPersistenceDriver;
|
|
50
|
+
interface PersonalWorkspaceSelection {
|
|
51
|
+
type: "personal";
|
|
52
|
+
}
|
|
53
|
+
interface OrganizationWorkspaceSelection {
|
|
54
|
+
type: "organization";
|
|
55
|
+
organizationId: string;
|
|
56
|
+
}
|
|
57
|
+
type WorkspaceSelection = PersonalWorkspaceSelection | OrganizationWorkspaceSelection;
|
|
58
|
+
interface DriveCredential {
|
|
59
|
+
tokenType: "Bearer";
|
|
60
|
+
token: string;
|
|
61
|
+
expiresAt: Date;
|
|
62
|
+
}
|
|
63
|
+
interface SignInInput {
|
|
64
|
+
email: string;
|
|
65
|
+
password: string;
|
|
66
|
+
}
|
|
67
|
+
interface DriveCredentialInput {
|
|
68
|
+
workspace: WorkspaceSelection;
|
|
69
|
+
forceRefresh?: boolean;
|
|
70
|
+
}
|
|
71
|
+
interface AuthClientOptions {
|
|
72
|
+
authOrigin: string;
|
|
73
|
+
appOrigin: string;
|
|
74
|
+
fetch?: typeof globalThis.fetch;
|
|
75
|
+
now?: () => number;
|
|
76
|
+
persistence?: AuthPersistence;
|
|
77
|
+
timeoutMs?: number;
|
|
78
|
+
}
|
|
79
|
+
interface FinuevaAuthClient {
|
|
80
|
+
acceptInvitation(input: AcceptInvitationInput): Promise<InvitationAcceptance>;
|
|
81
|
+
getSession(): Promise<AuthSession | null>;
|
|
82
|
+
listOrganizations(): Promise<AuthOrganization[]>;
|
|
83
|
+
signIn(input: SignInInput): Promise<AuthSession>;
|
|
84
|
+
signOut(): Promise<void>;
|
|
85
|
+
getDriveCredential(input: DriveCredentialInput): Promise<DriveCredential>;
|
|
86
|
+
onAuthStateChange(listener: (state: AuthState) => void): () => void;
|
|
87
|
+
onSessionChange(listener: (session: AuthSession | null) => void): () => void;
|
|
88
|
+
}
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region src/errors.d.ts
|
|
91
|
+
type AuthErrorCode = "invalid_credentials" | "authentication_required" | "request_origin_denied" | "invalid_invitation" | "invitation_unavailable" | "invitation_recipient_mismatch" | "email_verification_required" | "invalid_workspace_selection" | "organization_context_too_large" | "credential_rate_limited" | "state_conflict" | "access_denied" | "identity_authority_unavailable";
|
|
92
|
+
type AuthErrorStatus = 401 | 403 | 409 | 422 | 429 | 503;
|
|
93
|
+
declare class AuthError extends Error {
|
|
94
|
+
readonly code: AuthErrorCode;
|
|
95
|
+
readonly status: AuthErrorStatus;
|
|
96
|
+
readonly retryAfterSeconds?: number;
|
|
97
|
+
constructor(code: AuthErrorCode, status: AuthErrorStatus, retryAfterSeconds?: number);
|
|
98
|
+
}
|
|
99
|
+
//#endregion
|
|
100
|
+
export { PersonalWorkspaceSelection as _, AuthClientOptions as a, AuthPersistenceDriver as c, AuthUser as d, DriveCredential as f, OrganizationWorkspaceSelection as g, InvitationAcceptance as h, AcceptInvitationInput as i, AuthSession as l, FinuevaAuthClient as m, AuthErrorCode as n, AuthOrganization as o, DriveCredentialInput as p, AuthErrorStatus as r, AuthPersistence as s, AuthError as t, AuthState as u, SignInInput as v, WorkspaceSelection as y };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { _ as PersonalWorkspaceSelection, a as AuthClientOptions, c as AuthPersistenceDriver, d as AuthUser, f as DriveCredential, g as OrganizationWorkspaceSelection, h as InvitationAcceptance, i as AcceptInvitationInput, l as AuthSession, m as FinuevaAuthClient, n as AuthErrorCode, o as AuthOrganization, p as DriveCredentialInput, r as AuthErrorStatus, s as AuthPersistence, t as AuthError, u as AuthState, v as SignInInput, y as WorkspaceSelection } from "./errors-B0S9-QGH.js";
|
|
2
2
|
//#region src/client.d.ts
|
|
3
3
|
declare function createAuthClient(options: AuthClientOptions): FinuevaAuthClient;
|
|
4
4
|
//#endregion
|
|
5
|
-
export { type AuthClientOptions, AuthError, type AuthErrorCode, type AuthErrorStatus, type AuthSession, type AuthUser, type DriveCredential, type DriveCredentialInput, type FinuevaAuthClient, type PersonalWorkspaceSelection, type SignInInput, createAuthClient };
|
|
5
|
+
export { type AcceptInvitationInput, type AuthClientOptions, AuthError, type AuthErrorCode, type AuthErrorStatus, type AuthOrganization, type AuthPersistence, type AuthPersistenceDriver, type AuthSession, type AuthState, type AuthUser, type DriveCredential, type DriveCredentialInput, type FinuevaAuthClient, type InvitationAcceptance, type OrganizationWorkspaceSelection, type PersonalWorkspaceSelection, type SignInInput, type WorkspaceSelection, createAuthClient };
|