@baliola/auth-sdk 0.2.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.
@@ -0,0 +1,42 @@
1
+ //#region src/types/requests.d.ts
2
+ /** Optional captcha argument shared by every public unauthenticated entrypoint. */
3
+ type CaptchaArgs = {
4
+ /** Cloudflare Turnstile token. Required when captcha is enabled on the server. */captchaToken?: string;
5
+ };
6
+ type SendLoginCodeInput = {
7
+ email: string;
8
+ } & CaptchaArgs;
9
+ type VerifyLoginCodeInput = {
10
+ email: string;
11
+ code: string;
12
+ };
13
+ type ResendLoginCodeInput = {
14
+ email: string;
15
+ } & CaptchaArgs;
16
+ type RegisterInput = {
17
+ email: string;
18
+ password: string;
19
+ } & CaptchaArgs;
20
+ type VerifyRegistrationCodeInput = {
21
+ email: string;
22
+ code: string;
23
+ };
24
+ type ResendRegistrationCodeInput = {
25
+ email: string;
26
+ } & CaptchaArgs;
27
+ type LoginWithPasswordInput = {
28
+ email: string;
29
+ password: string;
30
+ } & CaptchaArgs;
31
+ type SetPasswordInput = {
32
+ password: string;
33
+ };
34
+ type ChangePasswordInput = {
35
+ currentPassword: string;
36
+ newPassword: string;
37
+ };
38
+ type LoginWithGoogleInput = {
39
+ idToken: string;
40
+ };
41
+ //#endregion
42
+ export { RegisterInput as a, SendLoginCodeInput as c, VerifyRegistrationCodeInput as d, LoginWithPasswordInput as i, SetPasswordInput as l, ChangePasswordInput as n, ResendLoginCodeInput as o, LoginWithGoogleInput as r, ResendRegistrationCodeInput as s, CaptchaArgs as t, VerifyLoginCodeInput as u };
@@ -0,0 +1,49 @@
1
+ //#region src/types/session.d.ts
2
+ type Account = {
3
+ id: string;
4
+ email: string;
5
+ status: string;
6
+ };
7
+ type Project = {
8
+ id: string;
9
+ name: string;
10
+ displayName: string | null; /** Exact-match CORS origins enforced by the auth server for this project. */
11
+ allowedOrigins: string[];
12
+ };
13
+ type AuthSession = {
14
+ accessToken: string;
15
+ refreshToken: string; /** Token lifetime in seconds (server-provided). */
16
+ expiresIn: number; /** SDK-set: ms epoch when this session was received from the server. */
17
+ issuedAt: number; /** SDK-computed: ms epoch when accessToken expires (issuedAt + expiresIn * 1000). */
18
+ expiresAt: number;
19
+ account: Account;
20
+ project?: Project;
21
+ roles: string[];
22
+ permissions: string[];
23
+ };
24
+ /** Per-OTP metadata returned alongside send/resend responses. */
25
+ type OtpInfo = {
26
+ /** Seconds until the code expires (relative to the server clock). */expiresInSeconds: number; /** ISO timestamp when the code expires. */
27
+ expiresAt: string; /** Seconds until another resend is permitted (0 = ready). */
28
+ canResendInSeconds: number; /** Resend attempts left for this OTP record. */
29
+ resendsRemaining: number;
30
+ };
31
+ /** Result of `auth.emailOtp.sendLoginCode`. */
32
+ type SendLoginCodeResult = {
33
+ /** Whether the BE recognizes the email as an existing account or a new signup. */flow: 'login' | 'signup'; /** Available login methods for this email. */
34
+ methods: ('password' | 'passwordless')[]; /** OTP timing metadata. */
35
+ otp: OtpInfo;
36
+ };
37
+ /** Result of any resend method (`emailOtp.resendLoginCode`, `emailPassword.resendRegistrationCode`). */
38
+ type ResendCodeResult = {
39
+ otp: OtpInfo;
40
+ };
41
+ /** Result of `auth.emailPassword.register`. */
42
+ type RegisterResult = {
43
+ otp: OtpInfo;
44
+ };
45
+ type SessionChangeHandler = (session: AuthSession | null) => void;
46
+ type ErrorSource = 'session-change-handler' | 'broadcast-channel-message';
47
+ type ErrorHandler = (error: Error, source: ErrorSource) => void;
48
+ //#endregion
49
+ export { OtpInfo as a, ResendCodeResult as c, ErrorSource as i, SendLoginCodeResult as l, AuthSession as n, Project as o, ErrorHandler as r, RegisterResult as s, Account as t, SessionChangeHandler as u };
@@ -0,0 +1,35 @@
1
+ import { n as AuthSession } from "./session-Cs_P7ojF.js";
2
+
3
+ //#region src/store/sessionStore.d.ts
4
+ /**
5
+ * Pluggable session storage. May be sync or async.
6
+ *
7
+ * The SDK awaits `get()` only in `loadSession()` and writes on every
8
+ * session change. Sync reads of the current session happen against the
9
+ * client's in-memory mirror (via `auth.getSession()`), not the store.
10
+ */
11
+ interface SessionStore {
12
+ get(): AuthSession | null | Promise<AuthSession | null>;
13
+ set(session: AuthSession | null): void | Promise<void>;
14
+ }
15
+ /**
16
+ * In-process memory store. Default if no store is supplied to
17
+ * `createAuthClient`. Suitable for: server-side requests, tests,
18
+ * any context where session does not need to persist across reloads.
19
+ */
20
+ declare function memoryStore(): SessionStore;
21
+ type LocalStorageStoreOptions = {
22
+ /** Key under which the serialized session is stored. Defaults to `baliola.auth.session`. */key?: string;
23
+ };
24
+ /**
25
+ * Browser localStorage-backed store. Persists across page reloads in the
26
+ * same origin. Throws on construction if `globalThis.localStorage` is not
27
+ * available — call only in browser environments.
28
+ *
29
+ * Known limitation: cross-tab sync is not implemented. Tab A logging
30
+ * out does not automatically propagate to Tab B until B makes a request
31
+ * and receives a 401.
32
+ */
33
+ declare function localStorageStore(options?: LocalStorageStoreOptions): SessionStore;
34
+ //#endregion
35
+ export { memoryStore as i, SessionStore as n, localStorageStore as r, LocalStorageStoreOptions as t };
@@ -0,0 +1,50 @@
1
+ //#region src/store/sessionStore.ts
2
+ /**
3
+ * In-process memory store. Default if no store is supplied to
4
+ * `createAuthClient`. Suitable for: server-side requests, tests,
5
+ * any context where session does not need to persist across reloads.
6
+ */
7
+ function memoryStore() {
8
+ let current = null;
9
+ return {
10
+ get() {
11
+ return current;
12
+ },
13
+ set(session) {
14
+ current = session;
15
+ }
16
+ };
17
+ }
18
+ const DEFAULT_LOCALSTORAGE_KEY = "baliola.auth.session";
19
+ /**
20
+ * Browser localStorage-backed store. Persists across page reloads in the
21
+ * same origin. Throws on construction if `globalThis.localStorage` is not
22
+ * available — call only in browser environments.
23
+ *
24
+ * Known limitation: cross-tab sync is not implemented. Tab A logging
25
+ * out does not automatically propagate to Tab B until B makes a request
26
+ * and receives a 401.
27
+ */
28
+ function localStorageStore(options = {}) {
29
+ if (typeof globalThis.localStorage === "undefined") throw new Error("localStorageStore() requires globalThis.localStorage. Use memoryStore() in non-browser environments.");
30
+ const key = options.key ?? DEFAULT_LOCALSTORAGE_KEY;
31
+ const storage = globalThis.localStorage;
32
+ return {
33
+ get() {
34
+ const raw = storage.getItem(key);
35
+ if (raw === null) return null;
36
+ try {
37
+ return JSON.parse(raw);
38
+ } catch {
39
+ storage.removeItem(key);
40
+ return null;
41
+ }
42
+ },
43
+ set(session) {
44
+ if (session === null) storage.removeItem(key);
45
+ else storage.setItem(key, JSON.stringify(session));
46
+ }
47
+ };
48
+ }
49
+ //#endregion
50
+ export { memoryStore as n, localStorageStore as t };
@@ -0,0 +1,2 @@
1
+ import { i as memoryStore, n as SessionStore, r as localStorageStore, t as LocalStorageStoreOptions } from "../sessionStore-BDdEpbL8.js";
2
+ export { type LocalStorageStoreOptions, type SessionStore, localStorageStore, memoryStore };
@@ -0,0 +1,2 @@
1
+ import { n as memoryStore, t as localStorageStore } from "../sessionStore-DD6lON9W.js";
2
+ export { localStorageStore, memoryStore };
@@ -0,0 +1,29 @@
1
+ //#region src/types/tokens.d.ts
2
+ /**
3
+ * One project the session is scoped to. A scoped login (`clientId` supplied)
4
+ * carries a single entry; a central login (`clientId` omitted) carries every
5
+ * project the account has active roles in.
6
+ */
7
+ type AccessTokenPayloadProject = {
8
+ id: string;
9
+ name: string;
10
+ clientId: string;
11
+ };
12
+ /**
13
+ * Decoded shape of the JWT access token issued by Baliola Auth.
14
+ * Provided for consumer reference (e.g. when manually decoding the JWT
15
+ * with their own library); the SDK does not parse JWTs itself.
16
+ */
17
+ type AccessTokenPayload = {
18
+ accountId: string;
19
+ email: string;
20
+ projects: AccessTokenPayloadProject[];
21
+ roles?: string[];
22
+ permissions?: string[];
23
+ iat?: number;
24
+ exp?: number;
25
+ sub?: string;
26
+ iss?: string;
27
+ };
28
+ //#endregion
29
+ export { AccessTokenPayloadProject as n, AccessTokenPayload as t };
@@ -0,0 +1,4 @@
1
+ import { a as OtpInfo, c as ResendCodeResult, i as ErrorSource, l as SendLoginCodeResult, n as AuthSession, o as Project, r as ErrorHandler, s as RegisterResult, t as Account, u as SessionChangeHandler } from "../session-Cs_P7ojF.js";
2
+ import { a as RegisterInput, c as SendLoginCodeInput, d as VerifyRegistrationCodeInput, i as LoginWithPasswordInput, l as SetPasswordInput, n as ChangePasswordInput, o as ResendLoginCodeInput, r as LoginWithGoogleInput, s as ResendRegistrationCodeInput, t as CaptchaArgs, u as VerifyLoginCodeInput } from "../requests-eTORIjY5.js";
3
+ import { n as AccessTokenPayloadProject, t as AccessTokenPayload } from "../tokens-BXrPLi5B.js";
4
+ export { type AccessTokenPayload, type AccessTokenPayloadProject, type Account, type AuthSession, type CaptchaArgs, type ChangePasswordInput, type ErrorHandler, type ErrorSource, type LoginWithGoogleInput, type LoginWithPasswordInput, type OtpInfo, type Project, type RegisterInput, type RegisterResult, type ResendCodeResult, type ResendLoginCodeInput, type ResendRegistrationCodeInput, type SendLoginCodeInput, type SendLoginCodeResult, type SessionChangeHandler, type SetPasswordInput, type VerifyLoginCodeInput, type VerifyRegistrationCodeInput };
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@baliola/auth-sdk",
3
+ "version": "0.2.0",
4
+ "description": "Client SDK for Baliola Auth",
5
+ "license": "SEE LICENSE IN LICENSE",
6
+ "author": "Baliola Development Team",
7
+ "type": "module",
8
+ "sideEffects": false,
9
+ "main": "./dist/index.js",
10
+ "module": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.js"
16
+ },
17
+ "./client": {
18
+ "types": "./dist/client/index.d.ts",
19
+ "import": "./dist/client/index.js"
20
+ },
21
+ "./errors": {
22
+ "types": "./dist/errors/index.d.ts",
23
+ "import": "./dist/errors/index.js"
24
+ },
25
+ "./store": {
26
+ "types": "./dist/store/index.d.ts",
27
+ "import": "./dist/store/index.js"
28
+ },
29
+ "./types": {
30
+ "types": "./dist/types/index.d.ts",
31
+ "import": "./dist/types/index.js"
32
+ }
33
+ },
34
+ "files": [
35
+ "dist",
36
+ "LICENSE",
37
+ "README.md",
38
+ "CHANGELOG.md"
39
+ ],
40
+ "publishConfig": {
41
+ "registry": "https://registry.npmjs.org",
42
+ "access": "public"
43
+ },
44
+ "repository": {
45
+ "type": "git",
46
+ "url": "git+https://github.com/baliola/baliola-auth.git",
47
+ "directory": "sdk"
48
+ },
49
+ "scripts": {
50
+ "build": "tsdown",
51
+ "typecheck": "tsc --noEmit",
52
+ "test": "bun test test/unit",
53
+ "prepublishOnly": "bun run build"
54
+ },
55
+ "devDependencies": {
56
+ "@types/bun": "latest",
57
+ "tsdown": "^0.21.10",
58
+ "typescript": "^5.7.0"
59
+ }
60
+ }