{"_id":"@anmho/auth-client","_rev":"2-4a843dcbfffe6bb51d0a11ef1c4f3a1a","name":"@anmho/auth-client","dist-tags":{"latest":"0.1.1"},"versions":{"0.1.0":{"name":"@anmho/auth-client","version":"0.1.0","license":"UNLICENSED","_id":"@anmho/auth-client@0.1.0","maintainers":[{"name":"anmho","email":"andyminhtuanho@gmail.com"}],"homepage":"https://github.com/anmho/auth#readme","bugs":{"url":"https://github.com/anmho/auth/issues"},"dist":{"shasum":"c7cfad1ccd6f4e6f56fcc81a8e2bdaed0b052b99","tarball":"https://registry.npmjs.org/@anmho/auth-client/-/auth-client-0.1.0.tgz","fileCount":3,"integrity":"sha512-K/uMQrpm7YG3Rw/z5gaJBKc7Xu8puE8miO3dioDEhCayqQod6IU2kFBqobaTuKzzlIATXDecOdhr91TINDMc/A==","signatures":[{"sig":"MEUCIQDhbzchx4Bh2GVlp6rFuUX1HAWv7eO5BMMFneGTqJEKVQIgKJwgpVCa4cu1wRUQuqlrq4c2ZKBy8IBjecBKvJvXqcY=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":11606},"type":"module","exports":{".":"./src/index.ts"},"gitHead":"3148292ce1966929cc4bafaf0c36b19fff6067ba","_npmUser":{"name":"anmho","email":"andyminhtuanho@gmail.com"},"repository":{"url":"git+https://github.com/anmho/auth.git","type":"git","directory":"packages/auth-client"},"_npmVersion":"11.9.0","description":"Client credentials token refresher for anmho service OAuth clients.","directories":{},"_nodeVersion":"24.14.0","dependencies":{"node-vault":"^0.12.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"@types/node-vault":"^0.9.13"},"_npmOperationalInternal":{"tmp":"tmp/auth-client_0.1.0_1779565101758_0.46740684308604474","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@anmho/auth-client","version":"0.1.1","description":"Client credentials token refresher for anmho service OAuth clients.","type":"module","repository":{"type":"git","url":"git+https://github.com/anmho/auth.git","directory":"packages/auth-client"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"types":"./dist/index.d.ts","license":"UNLICENSED","publishConfig":{"access":"public"},"scripts":{"build":"tsc -p tsconfig.build.json"},"dependencies":{"node-vault":"^0.12.0"},"devDependencies":{"@types/node":"^24.10.1","@types/node-vault":"^0.9.13"},"gitHead":"3148292ce1966929cc4bafaf0c36b19fff6067ba","_id":"@anmho/auth-client@0.1.1","bugs":{"url":"https://github.com/anmho/auth/issues"},"homepage":"https://github.com/anmho/auth#readme","_nodeVersion":"24.14.0","_npmVersion":"11.9.0","dist":{"integrity":"sha512-8sfeckF6ca30zXAxou+WIKyzEU+3R39+LWn1hPwklZE3es2+KrLIsZeUFBKg5c4LER259U5599MI6j4jzlRkvw==","shasum":"056ef3f415aa78bd3cae98164e979df1561de674","tarball":"https://registry.npmjs.org/@anmho/auth-client/-/auth-client-0.1.1.tgz","fileCount":6,"unpackedSize":20506,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCVRek/Fll9ILAQWxdpWFK+GnQKp231BD/8DQPpm8C3owIgfZOTV9wzm8vT6GxtKHNnD15YbXqTXEHasWZZhWUeFe4="}]},"_npmUser":{"name":"anmho","email":"andyminhtuanho@gmail.com"},"directories":{},"maintainers":[{"name":"anmho","email":"andyminhtuanho@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/auth-client_0.1.1_1779565484617_0.9580382117421624"},"_hasShrinkwrap":false}},"time":{"created":"2026-05-23T19:38:21.598Z","modified":"2026-05-23T19:44:44.874Z","0.1.0":"2026-05-23T19:38:21.893Z","0.1.1":"2026-05-23T19:44:44.780Z"},"bugs":{"url":"https://github.com/anmho/auth/issues"},"license":"UNLICENSED","homepage":"https://github.com/anmho/auth#readme","repository":{"type":"git","url":"git+https://github.com/anmho/auth.git","directory":"packages/auth-client"},"description":"Client credentials token refresher for anmho service OAuth clients.","maintainers":[{"name":"anmho","email":"andyminhtuanho@gmail.com"}],"readme":"# @anmho/auth-client\n\nTypeScript client-credentials token refresher for long-running Node services.\n\nThe package reads OAuth client credentials from Vault using the `node-vault`\nSDK, exchanges them for a Bearer access token, keeps that token cached in the\nbackground, and exposes `getToken()`.\n\n## Install\n\n```bash\nnpm install @anmho/auth-client\n```\n\n## Usage\n\n```ts\nimport { ClientCredentialsTokenRefresher, vaultCredentialsProvider } from \"@anmho/auth-client\";\n\nconst refresher = new ClientCredentialsTokenRefresher({\n  tokenUrl: \"https://auth.anmho.com/api/auth/oauth2/token\",\n  credentials: vaultCredentialsProvider({\n    path: \"prod/apps/agent/server/oauth-clients/billing\"\n  }),\n  resource: \"api://billing\",\n  scope: [\"invoices:read\"]\n});\n\nrefresher.start();\n\nconst token = await refresher.getToken();\n```\n\n## Vault\n\nThe Vault provider uses the `node-vault` SDK. It reads KV v2 secrets from the\n`secret` mount by default and expects `client_id` and `client_secret` fields.\nPass `endpoint`, `token`, and `namespace` explicitly, or let it read\n`VAULT_ADDR`, `VAULT_TOKEN`, and `VAULT_NAMESPACE`.\n\nThe default authctl Vault path shape is:\n\n```text\nprod/apps/<client_app_id>/<client_identity>/oauth-clients/<resource_server_id>\n```\n\n## Behavior\n\n- `start()` starts an async `setInterval` refresh loop.\n- `stop()` clears the interval.\n- `refresh()` forces a token request and updates the cache.\n- `getToken()` returns a cached valid token, or performs one foreground refresh\n  if startup refresh has not completed or the token is expired.\n- Background refresh failures do not erase the last still-valid token.\n\n## Testing\n\nRun the package tests:\n\n```bash\nbun test packages/auth-client\n```\n\nRun the functional example smoke from the repo root:\n\n```bash\nbun run examples:smoke\n```\n\nThat command starts local Postgres and Vault dev containers, migrates the local\nauth API database, creates an authctl resource server and OAuth client, writes\nthe one-time client credentials into Vault, and runs the Node and Go example\napps against the live local token endpoint.\n\n## Release\n\nVersion `packages/auth-client/package.json` independently when the TypeScript\nruntime client changes. npm publishing is handled by GitHub Actions trusted\npublishing through `.github/workflows/publish-auth-client.yml`.\n\nConfigure the npm trusted publisher:\n\n```text\n@anmho/auth-client -> anmho/auth / publish-auth-client.yml\n```\n","readmeFilename":"README.md"}