@finueva/auth 0.3.0 → 0.5.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 CHANGED
@@ -23,6 +23,10 @@ const stop = auth.onAuthStateChange((state) => {
23
23
 
24
24
  const session = await auth.getSession();
25
25
  await auth.signIn({ email, password });
26
+ await auth.sendVerificationEmail({
27
+ email,
28
+ callbackURL: `${window.location.origin}/account/email-verified`,
29
+ });
26
30
  const organizations = await auth.listOrganizations();
27
31
  const acceptance = await auth.acceptInvitation({ invitationId });
28
32
  const credential = await auth.getDriveCredential({
@@ -37,6 +41,8 @@ stop();
37
41
 
38
42
  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
43
 
44
+ `sendVerificationEmail({ email, callbackURL? })` sends one non-retried request. An explicit callback must be an exact absolute URL on `appOrigin`; it is never persisted by the SDK. Without one, the email lands on Auth's value-free verification result page after Better Auth completes verification.
45
+
40
46
  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
47
 
42
48
  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.
@@ -64,14 +70,37 @@ const acceptance = await auth.acceptInvitation({ invitationId });
64
70
  const credential = await auth.getDriveCredential({
65
71
  workspace: { type: "organization", organizationId: organizations[0].id },
66
72
  });
73
+ const signOut = await auth.signOut();
74
+ const responseHeaders = new Headers();
75
+ signOut.applyCookies(responseHeaders);
76
+ ```
77
+
78
+ The server client is request-scoped and does not cache credentials. It forwards only reserved Better Auth cookies to Auth and never sends them to Drive. Apply cookies returned by server invitation acceptance or sign-out to the outgoing response with `acceptance.applyCookies(headers)` or `signOut.applyCookies(headers)`.
79
+
80
+ ## Device
81
+
82
+ ```ts
83
+ import { createDeviceAuth } from "@finueva/auth/device";
84
+
85
+ const auth = createDeviceAuth({
86
+ authOrigin: "https://auth.finueva.com",
87
+ clientId: "finueva-cli",
88
+ });
89
+ const authorization = await auth.requestAuthorization();
90
+ showCode(authorization.userCode, authorization.verificationUri);
91
+ const token = await auth.pollForToken(authorization, { signal });
92
+ const session = await auth.getSession();
93
+ await auth.revokeCurrentDevice(); // or revokeAllSessions()
67
94
  ```
68
95
 
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)`.
96
+ Polling starts at the server-provided interval, adds five seconds after each RFC 8628 `slow_down`, has no transport retry, and stops on denial, expiry, cancellation, the configured `maxPollingMs`, malformed/bounded responses, or transport timeout. The only requested scope is `openid`.
97
+
98
+ The token is memory-only by default. Secure persistence is opt-in through a structural adapter implementing `read`, atomic `replace`, and `delete`; every operation receives an `AbortSignal` and must stop without committing when aborted. The caller owns encryption and platform credential storage. Adapter and authority failures are value-free and never include device codes or tokens. This export uses standard expiring/revocable Better Auth sessions and does not implement refresh tokens.
70
99
 
71
100
  ## Current Limits
72
101
 
73
102
  - 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`.
103
+ - Cross-root SSO is not implemented.
75
104
  - The package does not persist Drive credentials or expose Better Auth or Unstorage internals.
76
105
  - Public errors are `AuthError` instances with stable, value-free codes.
77
106
  - Organization contexts with more than 50 current teams fail with `organization_context_too_large` and status `422`.
@@ -0,0 +1,51 @@
1
+ import { o as AuthSession } from "./types-HSdjQWMZ.js";
2
+ //#region src/device.d.ts
3
+ type DeviceAuthorizationErrorCode = "device_access_denied" | "device_authorization_cancelled" | "device_code_expired" | "invalid_device_authorization" | "identity_authority_unavailable";
4
+ declare class DeviceAuthorizationError extends Error {
5
+ readonly code: DeviceAuthorizationErrorCode;
6
+ constructor(code: DeviceAuthorizationErrorCode);
7
+ }
8
+ interface DeviceToken {
9
+ accessToken: string;
10
+ tokenType: "Bearer";
11
+ expiresAt: Date;
12
+ scope: "openid";
13
+ }
14
+ interface DeviceTokenPersistence {
15
+ read(signal: AbortSignal): DeviceToken | null | Promise<DeviceToken | null>;
16
+ replace(token: DeviceToken, signal: AbortSignal): void | Promise<void>;
17
+ delete(signal: AbortSignal): void | Promise<void>;
18
+ }
19
+ interface DeviceAuthorization {
20
+ deviceCode: string;
21
+ userCode: string;
22
+ verificationUri: string;
23
+ verificationUriComplete: string;
24
+ expiresAt: Date;
25
+ intervalSeconds: number;
26
+ }
27
+ interface DeviceAuthOptions {
28
+ authOrigin: string;
29
+ clientId: string;
30
+ fetch?: typeof globalThis.fetch;
31
+ now?: () => number;
32
+ persistence?: DeviceTokenPersistence;
33
+ timeoutMs?: number;
34
+ maxPollingMs?: number;
35
+ }
36
+ interface PollDeviceOptions {
37
+ signal?: AbortSignal;
38
+ }
39
+ interface DeviceAuthClient {
40
+ requestAuthorization(options?: {
41
+ signal?: AbortSignal;
42
+ }): Promise<DeviceAuthorization>;
43
+ pollForToken(authorization: DeviceAuthorization, options?: PollDeviceOptions): Promise<DeviceToken>;
44
+ getSession(): Promise<AuthSession | null>;
45
+ getToken(): Promise<DeviceToken | null>;
46
+ revokeCurrentDevice(): Promise<void>;
47
+ revokeAllSessions(): Promise<void>;
48
+ }
49
+ declare function createDeviceAuth(options: DeviceAuthOptions): DeviceAuthClient;
50
+ //#endregion
51
+ export { DeviceAuthClient, DeviceAuthOptions, DeviceAuthorization, DeviceAuthorizationError, DeviceAuthorizationErrorCode, DeviceToken, DeviceTokenPersistence, PollDeviceOptions, createDeviceAuth };