{"_id":"@ag-vibe/auth","_rev":"4-32f08934a6ebf641abc1046dd0f75ad2","name":"@ag-vibe/auth","dist-tags":{"latest":"0.1.3"},"versions":{"0.0.0":{"name":"@ag-vibe/auth","version":"0.0.0","author":{"name":"wibus-wee"},"license":"MIT","_id":"@ag-vibe/auth@0.0.0","maintainers":[{"name":"wibus","email":"wibus@qq.com"}],"homepage":"https://github.com/ag-vibe/auth#readme","bugs":{"url":"https://github.com/ag-vibe/auth/issues"},"dist":{"shasum":"6d0f7af9cc2c7d514383d1d51f18e8bff7ee50bc","tarball":"https://registry.npmjs.org/@ag-vibe/auth/-/auth-0.0.0.tgz","fileCount":2,"integrity":"sha512-uks12cCdMrfyVMiifV4ioLw1OoMNHAf7aVq8bg7XiwdutUBhgcVVKkKrmcIjRHsU5uoQE8gIrGMTpQ8r7f9TBw==","signatures":[{"sig":"MEQCICB9K4WwJ3UDM0uNjtPUrWcIO/YRW4iyr+emkiDiDUufAiBYpc4aSC145U62afBWgZzJlICiqchuXWgvo05qZPbQyg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":3261},"pnpm":{"overrides":{"vite":"npm:@voidzero-dev/vite-plus-core@latest","vitest":"npm:@voidzero-dev/vite-plus-test@latest"}},"type":"module","exports":{".":"./dist/index.js","./package.json":"./package.json"},"gitHead":"c8ebf9296a00693d2708a8f77517e5585b01c058","scripts":{"dev":"vp pack --watch","test":"vp test","build":"vp pack","check":"vp check","prepare":"vp config","prepublishOnly":"vp run build"},"_npmUser":{"name":"wibus","email":"wibus@qq.com"},"repository":{"url":"git+https://github.com/ag-vibe/auth.git","type":"git"},"_npmVersion":"11.11.0","description":"Authentication SDK for the ag-vibe ecosystem (allinone backend).","directories":{},"_nodeVersion":"24.14.1","dependencies":{"ofetch":"^1.4.1","zustand":"^5.0.12"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"packageManager":"pnpm@10.33.0","devDependencies":{"bumpp":"^11.0.1","happy-dom":"^20.8.9","vite-plus":"^0.1.11","typescript":"^5.9.3","@types/node":"^25.5.0","@typescript/native-preview":"7.0.0-dev.20260316.1"},"_npmOperationalInternal":{"tmp":"tmp/auth_0.0.0_1774746668490_0.1420725204940949","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@ag-vibe/auth","version":"0.1.1","author":{"name":"wibus-wee"},"license":"MIT","_id":"@ag-vibe/auth@0.1.1","maintainers":[{"name":"wibus","email":"wibus@qq.com"}],"homepage":"https://github.com/ag-vibe/auth#readme","bugs":{"url":"https://github.com/ag-vibe/auth/issues"},"dist":{"shasum":"eb84db8207cdb6aaf8bb3499dcc15f19cfe9d5c3","tarball":"https://registry.npmjs.org/@ag-vibe/auth/-/auth-0.1.1.tgz","fileCount":4,"integrity":"sha512-FkKBjsW/8nIcNXQnP4wl9eWXz7D2D+ZrcRTRbLpqg8Uvlh+erGe4mfjV9wtJ98nkGbcdhCjt8LuyTXhG9GZkow==","signatures":[{"sig":"MEQCIFG08DAHyfAarc9dhiqq9nCGwoJxfn1f9F1CpDCZqeQeAiBWAuRxs4JXLSn5aSqWjYf/853hyCu+8ZDR69vbriwPhQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@ag-vibe%2fauth@0.1.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":17116},"pnpm":{"overrides":{"vite":"npm:@voidzero-dev/vite-plus-core@latest","vitest":"npm:@voidzero-dev/vite-plus-test@latest"}},"type":"module","exports":{".":"./dist/index.js","./package.json":"./package.json"},"gitHead":"ca5eb96b4e1dfff7609a32fe65950e4ec6467ccd","scripts":{"dev":"vp pack --watch","test":"vp test","build":"vp pack","check":"vp check","prepare":"vp config","prepublishOnly":"vp run build"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:fc4f9f93-7658-40b9-9617-6e690da96de4"}},"repository":{"url":"git+https://github.com/ag-vibe/auth.git","type":"git"},"_npmVersion":"11.9.0","description":"Authentication SDK for the ag-vibe ecosystem (allinone backend).","directories":{},"_nodeVersion":"24.14.0","dependencies":{"ofetch":"^1.4.1","zustand":"^5.0.12"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"packageManager":"pnpm@10.33.0","devDependencies":{"bumpp":"^11.0.1","happy-dom":"^20.8.9","vite-plus":"^0.1.11","typescript":"^5.9.3","@types/node":"^25.5.0","@typescript/native-preview":"7.0.0-dev.20260316.1"},"_npmOperationalInternal":{"tmp":"tmp/auth_0.1.1_1774746977409_0.6233534230255389","host":"s3://npm-registry-packages-npm-production"}},"0.1.2":{"name":"@ag-vibe/auth","version":"0.1.2","author":{"name":"wibus-wee"},"license":"MIT","_id":"@ag-vibe/auth@0.1.2","maintainers":[{"name":"wibus","email":"wibus@qq.com"}],"homepage":"https://github.com/ag-vibe/auth#readme","bugs":{"url":"https://github.com/ag-vibe/auth/issues"},"dist":{"shasum":"27e9599c72676216c5c42b807c148eaf0c5b7898","tarball":"https://registry.npmjs.org/@ag-vibe/auth/-/auth-0.1.2.tgz","fileCount":4,"integrity":"sha512-qjJpD5ezPCogqTMTJdlo5SwHGfFYU7EoJ8TQ6rVEnbIXtJOf/pe2xFXcj6lwYtK9c7IgYjZ+9FNIAxUJ8HKw4w==","signatures":[{"sig":"MEYCIQC5TGSs+LZmjL7qDB8kKDUaVeRCKOifhvfTVFCR4iGnJAIhAIVcVwrcn8i70710b7PgDyJgvMjaFCcdXIVMgUl2hLej","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@ag-vibe%2fauth@0.1.2","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":17470},"pnpm":{"overrides":{"vite":"npm:@voidzero-dev/vite-plus-core@latest","vitest":"npm:@voidzero-dev/vite-plus-test@latest"}},"type":"module","exports":{".":"./dist/index.js","./package.json":"./package.json"},"gitHead":"0adfc3caef897a9048877b835ebb83a4718bc448","scripts":{"dev":"vp pack --watch","test":"vp test","build":"vp pack","check":"vp check","prepare":"vp config","prepublishOnly":"vp run build"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:fc4f9f93-7658-40b9-9617-6e690da96de4"}},"repository":{"url":"git+https://github.com/ag-vibe/auth.git","type":"git"},"_npmVersion":"11.9.0","description":"Authentication SDK for the ag-vibe ecosystem (allinone backend).","directories":{},"_nodeVersion":"24.14.0","dependencies":{"ofetch":"^1.4.1","zustand":"^5.0.12"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"packageManager":"pnpm@10.33.0","devDependencies":{"bumpp":"^11.0.1","happy-dom":"^20.8.9","vite-plus":"^0.1.11","typescript":"^5.9.3","@types/node":"^25.5.0","@typescript/native-preview":"7.0.0-dev.20260316.1"},"_npmOperationalInternal":{"tmp":"tmp/auth_0.1.2_1774748064625_0.9505072065113327","host":"s3://npm-registry-packages-npm-production"}},"0.1.3":{"name":"@ag-vibe/auth","version":"0.1.3","description":"Authentication SDK for the ag-vibe ecosystem (allinone backend).","homepage":"https://github.com/ag-vibe/auth#readme","bugs":{"url":"https://github.com/ag-vibe/auth/issues"},"license":"MIT","author":{"name":"wibus-wee"},"repository":{"type":"git","url":"git+https://github.com/ag-vibe/auth.git"},"type":"module","exports":{".":"./dist/index.js","./package.json":"./package.json"},"publishConfig":{"access":"public"},"scripts":{"build":"vp pack","dev":"vp pack --watch","test":"vp test","check":"vp check","prepublishOnly":"vp run build","prepare":"vp config"},"dependencies":{"ofetch":"^1.4.1","zustand":"^5.0.12"},"devDependencies":{"@types/node":"^25.5.0","@typescript/native-preview":"7.0.0-dev.20260316.1","bumpp":"^11.0.1","happy-dom":"^20.8.9","typescript":"^5.9.3","vite-plus":"^0.1.11"},"packageManager":"pnpm@10.33.0","pnpm":{"overrides":{"vite":"npm:@voidzero-dev/vite-plus-core@latest","vitest":"npm:@voidzero-dev/vite-plus-test@latest"}},"gitHead":"d16cfe276cd7c8edfdfe62257e7a0d63388279a2","_id":"@ag-vibe/auth@0.1.3","_nodeVersion":"24.14.0","_npmVersion":"11.9.0","dist":{"integrity":"sha512-yLpSnA/HOgA9Bzkj5Q5zp3th3WzfklbS8ecy7I0BBgu81lqaXrKjIxU65Kx277RkQfBX+XqPPIQE+lWpPOeD/A==","shasum":"3cac2a6fbb557b447d4ab28ad51ff7214d1e8681","tarball":"https://registry.npmjs.org/@ag-vibe/auth/-/auth-0.1.3.tgz","fileCount":4,"unpackedSize":19598,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@ag-vibe%2fauth@0.1.3","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCTr9vUPFCwcY1p706W9Y4gQfQOBLDTc5cNXRTlZN3abAIhAI0CDfuCjEKN0h0teCzv6Ka7CfpJvsXSWdo6f2E05WRU"}]},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:fc4f9f93-7658-40b9-9617-6e690da96de4"}},"directories":{},"maintainers":[{"name":"wibus","email":"wibus@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/auth_0.1.3_1774799537887_0.5548044033514301"},"_hasShrinkwrap":false}},"time":{"created":"2026-03-29T01:11:08.287Z","modified":"2026-03-29T15:52:18.361Z","0.0.0":"2026-03-29T01:11:08.637Z","0.1.1":"2026-03-29T01:16:17.553Z","0.1.2":"2026-03-29T01:34:24.766Z","0.1.3":"2026-03-29T15:52:18.032Z"},"bugs":{"url":"https://github.com/ag-vibe/auth/issues"},"author":{"name":"wibus-wee"},"license":"MIT","homepage":"https://github.com/ag-vibe/auth#readme","repository":{"type":"git","url":"git+https://github.com/ag-vibe/auth.git"},"description":"Authentication SDK for the ag-vibe ecosystem (allinone backend).","maintainers":[{"name":"wibus","email":"wibus@qq.com"}],"readme":"# @ag-vibe/auth\n\nAuthentication SDK for ag-vibe frontends (allinone backend).\n\n## Features\n\n- Zustand-based auth session store with persistence (`localStorage`)\n- Access token refresh (`/auth/refresh`) with in-flight dedupe\n- 401 auto-retry interceptor for heyapi clients\n- Does not clear session on transient refresh failures (network/429/5xx)\n- Browser-less fallback storage (in-memory) for non-DOM runtimes\n\n## Install\n\n```bash\npnpm add @ag-vibe/auth\n```\n\n## Quick Start\n\n```ts\nimport { createAuthClient } from \"@ag-vibe/auth\";\nimport { client as apiClient } from \"@/api-gen/client.gen\";\n\nexport const auth = createAuthClient({\n  baseUrl: import.meta.env.VITE_API_BASE_URL ?? \"/api/v1\",\n  appId: \"todo\",\n});\n\n// 1) Provide bearer token for generated SDK\nexport const createClientConfig = (config: Record<string, unknown>) => ({\n  ...config,\n  auth: async (a: { scheme: string }) => {\n    if (a.scheme === \"bearer\") {\n      return (await auth.ensureValidAccessToken()) ?? undefined;\n    }\n    return undefined;\n  },\n});\n\n// 2) Install 401 auto-retry interceptor\nauth.applyTo(apiClient);\n```\n\n## API\n\n### `createAuthClient({ baseUrl, appId, authEndpointPaths? })`\n\nReturns:\n\n- `store`: auth state store (`session`, `isAuthenticated`, `setSession`, `clearSession`)\n- `ensureValidAccessToken(forceRefresh?)`: returns valid access token or `null`\n- `applyTo(client | client[])`: installs idempotent 401 retry interceptor\n\n### Refresh Behavior\n\n- Proactive refresh when token is close to expiry\n- Forced refresh when interceptor catches 401\n- Refresh failure handling:\n  - `401/403` from refresh endpoint: clear session\n  - network errors / `429` / `5xx`: keep session, return `null`\n\n## Interceptor Behavior\n\n`applyTo(...)` response interceptor:\n\n1. Skip non-401 responses\n2. Skip auth endpoints (defaults: `/auth/sign-in`, `/auth/sign-up`, `/auth/sign-out`, `/auth/refresh`)\n3. Refresh token once\n4. Retry original request with updated `Authorization` header\n\nYou can override skipped auth paths:\n\n```ts\nconst auth = createAuthClient({\n  baseUrl: \"/api/v1\",\n  appId: \"todo\",\n  authEndpointPaths: [\"/identity/token/refresh\", \"/identity/sign-in\"],\n});\n```\n\n## Development\n\n```bash\nvp install\nvp check\nvp test\nvp pack\n```\n","readmeFilename":"README.md"}