{"_id":"@affinity-health/effect-sdk","_rev":"4-b69023cfeb081c46c2db54ababaf3bb4","name":"@affinity-health/effect-sdk","dist-tags":{"latest":"0.3.1"},"versions":{"0.1.0":{"name":"@affinity-health/effect-sdk","version":"0.1.0","license":"MIT","_id":"@affinity-health/effect-sdk@0.1.0","maintainers":[{"name":"dawsson","email":"hello@dawson.gg"}],"homepage":"https://docs.joinaffinityai.com/api","bugs":{"url":"https://github.com/affinity-health/affinity-effect-sdk/issues"},"bin":{"affinity":"dist/cli.mjs"},"dist":{"shasum":"e85c4860d94fd459bc25c6e01ee6c488e3442096","tarball":"https://registry.npmjs.org/@affinity-health/effect-sdk/-/effect-sdk-0.1.0.tgz","fileCount":23,"integrity":"sha512-/AcVhO91PPHSi7o12I3RnKeRYvvpJ1bhYQ/4rB4IpTmNgWlwhpdG8dKzhYwmHfEbje6i+59tWv/lERykvJK9sg==","signatures":[{"sig":"MEYCIQCLg/sjLauENZnQ/mevAW6/t4Zez83Bx6vhRpkIKw2CagIhAOgv7CrgetZfEny1SS7/TYJeAWha5mq1a/RO4CFwP3PV","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":1026039},"type":"module","shasum":"e85c4860d94fd459bc25c6e01ee6c488e3442096","engines":{"node":">=20"},"exports":{".":{"types":"./dist/index.d.mts","import":"./dist/index.mjs","default":"./dist/index.mjs"},"./code":{"types":"./dist/code/index.d.mts","import":"./dist/code/index.mjs","default":"./dist/code/index.mjs"},"./operations":{"types":"./dist/services/affinity.d.mts","import":"./dist/services/affinity.mjs","default":"./dist/services/affinity.mjs"}},"scripts":{"build":"vp pack","check":"bun run generate:check && vp check && bun test && bun run build && bun run package:check","clean":"rm -rf dist","convert":"bun scripts/convert.ts","generate":"bun run convert && bun scripts/generate.ts && bun scripts/generate-code.ts","package:check":"bun scripts/check-package.ts","generate:check":"bun scripts/generate-check.ts","prepublishOnly":"bun run check"},"_npmUser":{"name":"dawsson","email":"hello@dawson.gg"},"_integrity":"sha512-/AcVhO91PPHSi7o12I3RnKeRYvvpJ1bhYQ/4rB4IpTmNgWlwhpdG8dKzhYwmHfEbje6i+59tWv/lERykvJK9sg==","repository":{"url":"git+https://github.com/affinity-health/affinity-effect-sdk.git","type":"git"},"_npmVersion":"10.8.3","description":"Effect-native TypeScript SDK for the Affinity API","directories":{},"sideEffects":false,"_nodeVersion":"26.3.0","dependencies":{"@effect/platform-bun":"4.0.0-rc.112","@distilled.cloud/core":"1.0.0-rc.8"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"packageManager":"bun@1.3.12","devDependencies":{"effect":"4.0.0-rc.112","vite-plus":"0.3.0","@types/bun":"1.4.0","typescript":"7.0.2","@typescript/native-preview":"7.0.0-dev.20260707.2"},"peerDependencies":{"effect":">=4.0.0-rc.112 || >=4.0.0"},"_npmOperationalInternal":{"tmp":"tmp/effect-sdk_0.1.0_1788137509573_0.16369179868394146","host":"s3://npm-registry-packages-npm-production"}},"0.2.0":{"name":"@affinity-health/effect-sdk","version":"0.2.0","license":"MIT","_id":"@affinity-health/effect-sdk@0.2.0","maintainers":[{"name":"dawsson","email":"hello@dawson.gg"}],"homepage":"https://docs.joinaffinityai.com/api","bugs":{"url":"https://github.com/affinity-health/affinity-effect-sdk/issues"},"bin":{"affinity":"dist/cli.mjs"},"dist":{"shasum":"695342fda3296a84d1bf0cca5df2a0b23b53687d","tarball":"https://registry.npmjs.org/@affinity-health/effect-sdk/-/effect-sdk-0.2.0.tgz","fileCount":23,"integrity":"sha512-ExEZ8mtuDDiTe5/5wr1+ICvz+Ejb+DwDuM3f8aY0ghfQye4sY5W1VZGYyxfXfiIGrjtpryfTcou1UXg0OfwNrQ==","signatures":[{"sig":"MEYCIQDFUdTITO06vRkvHlgjtHXFBmCQ9l/aT3S9izFQyY2kUwIhAIwzucfmK0A9M/RaEJ1nzYYN9MyKhuY7S7QWscjN1S0U","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEUCIEdoZ1r62G2MR1bUB9oItrOcF/ccfM0dO9K2uzeBaxYGAiEAqiPyIlvSKUuE3QFerrhSklL0Pnxt3ySIhqYFB70B0/w=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":1033287},"type":"module","engines":{"node":">=20"},"exports":{".":{"types":"./dist/index.d.mts","import":"./dist/index.mjs","default":"./dist/index.mjs"},"./code":{"types":"./dist/code/index.d.mts","import":"./dist/code/index.mjs","default":"./dist/code/index.mjs"},"./operations":{"types":"./dist/services/affinity.d.mts","import":"./dist/services/affinity.mjs","default":"./dist/services/affinity.mjs"}},"gitHead":"40124f134c935d82973f4be603b6d9c55719a429","scripts":{"build":"vp pack","check":"bun run generate:check && vp check && bun test && bun run build && bun run package:check","clean":"rm -rf dist","convert":"bun scripts/convert.ts","generate":"bun run convert && bun scripts/generate.ts && bun scripts/generate-code.ts","package:check":"bun scripts/check-package.ts","generate:check":"bun scripts/generate-check.ts","prepublishOnly":"bun run check"},"_npmUser":{"name":"dawsson","email":"hello@dawson.gg"},"repository":{"url":"git+https://github.com/affinity-health/affinity-effect-sdk.git","type":"git"},"_npmVersion":"11.17.0","description":"Effect-native TypeScript SDK for the Affinity API","directories":{},"sideEffects":false,"_nodeVersion":"24.19.0","dependencies":{"@effect/platform-bun":"4.0.0-rc.112","@distilled.cloud/core":"1.0.0-rc.8"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"packageManager":"bun@1.3.12","devDependencies":{"effect":"4.0.0-rc.112","vite-plus":"0.3.0","@types/bun":"1.4.0","typescript":"7.0.2","@typescript/native-preview":"7.0.0-dev.20260707.2"},"peerDependencies":{"effect":">=4.0.0-rc.112 || >=4.0.0"},"_npmOperationalInternal":{"tmp":"tmp/effect-sdk_0.2.0_1788138846991_0.7357528068119035","host":"s3://npm-registry-packages-npm-production"}},"0.3.0":{"name":"@affinity-health/effect-sdk","version":"0.3.0","license":"MIT","_id":"@affinity-health/effect-sdk@0.3.0","maintainers":[{"name":"dawsson","email":"hello@dawson.gg"}],"homepage":"https://docs.joinaffinityai.com/api","bugs":{"url":"https://github.com/affinity-health/affinity-effect-sdk/issues"},"bin":{"affinity":"dist/cli.mjs"},"dist":{"shasum":"f88821e764c63f9a5afac68d1983c0a12102a429","tarball":"https://registry.npmjs.org/@affinity-health/effect-sdk/-/effect-sdk-0.3.0.tgz","fileCount":23,"integrity":"sha512-BI90yR8G1VuwHaS/Zr0+wE12mqxg6XrflJtKMz65KYnifmVWAKUtvVksj83I2tyzTCMlC8b7OjRJlR7yCGs8Ng==","signatures":[{"sig":"MEYCIQD53iDRkTjFllH7bYjlg00VOrkOJI3+4GGpx667QcvTBAIhAM9LKB994NONGVNi0OUbtpoEex3mXfPH+/S5XNSegPJP","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEYCIQDaxoOPUej9WqTEObgBmaiMwPLkcz55yXSar3DwS2DkRwIhAJ+DLQFuuCZ6nedRwpDYvGqt1ccgMvlq3BI1+BBffg+C","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":967513},"type":"module","shasum":"f88821e764c63f9a5afac68d1983c0a12102a429","engines":{"node":">=20"},"exports":{".":{"types":"./dist/index.d.mts","import":"./dist/index.mjs","default":"./dist/index.mjs"},"./code":{"types":"./dist/code/index.d.mts","import":"./dist/code/index.mjs","default":"./dist/code/index.mjs"},"./operations":{"types":"./dist/services/affinity.d.mts","import":"./dist/services/affinity.mjs","default":"./dist/services/affinity.mjs"}},"scripts":{"build":"vp pack","check":"bun run generate:check && vp check && bun test && bun run build && bun run package:check","clean":"rm -rf dist","convert":"bun scripts/convert.ts","generate":"bun run convert && bun scripts/generate.ts && bun scripts/generate-code.ts","package:check":"bun scripts/check-package.ts","generate:check":"bun scripts/generate-check.ts","prepublishOnly":"bun run check"},"_npmUser":{"name":"dawsson","email":"hello@dawson.gg"},"_integrity":"sha512-BI90yR8G1VuwHaS/Zr0+wE12mqxg6XrflJtKMz65KYnifmVWAKUtvVksj83I2tyzTCMlC8b7OjRJlR7yCGs8Ng==","repository":{"url":"git+https://github.com/affinity-health/affinity-effect-sdk.git","type":"git"},"_npmVersion":"10.8.3","description":"Effect-native TypeScript SDK for the Affinity API","directories":{},"sideEffects":false,"_nodeVersion":"26.3.0","dependencies":{"@effect/platform-bun":"4.0.0-rc.112","@distilled.cloud/core":"1.0.0-rc.8"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"packageManager":"bun@1.3.12","readmeFilename":"README.md","devDependencies":{"effect":"4.0.0-rc.112","vite-plus":"0.3.0","@types/bun":"1.4.0","typescript":"7.0.2","@typescript/native-preview":"7.0.0-dev.20260707.2"},"peerDependencies":{"effect":">=4.0.0-rc.112 || >=4.0.0"},"_npmOperationalInternal":{"tmp":"tmp/effect-sdk_0.3.0_1788141249227_0.9510797042496866","host":"s3://npm-registry-packages-npm-production"}},"0.3.1":{"_id":"@affinity-health/effect-sdk@0.3.1","bin":{"affinity":"dist/cli.mjs"},"bugs":{"url":"https://github.com/affinity-health/affinity-effect-sdk/issues"},"dist":{"shasum":"2dd5cc753fb0a5f631df046ce974e290470a9ea1","tarball":"https://registry.npmjs.org/@affinity-health/effect-sdk/-/effect-sdk-0.3.1.tgz","fileCount":23,"integrity":"sha512-/gWnpMGNuZa4QJtGREMhHUN0YTDpy9unoUrT0tmIG9Wdlpe7K1jER/UbEg+ihg63rCh2sKZrNyLGxVFeYMS9CA==","signatures":[{"sig":"MEYCIQDkkrMcnjfRG/DU0ZjvgVA4W5TXK/+kENu/rIPS7RjyGgIhAP+55AYGTn0qmmS9L8ihOlBLnAvYNZvaYNbIKB2wsaNT","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIDjsE5sSUrsEZg866UapTkKAP3gvi68BcxsUmPYQQjbTAiEA93xoqE4ByNnYa0QegQ/Qz/CAayYJvVjs6PzH/8DDuhU="}],"unpackedSize":967701},"name":"@affinity-health/effect-sdk","type":"module","shasum":"2dd5cc753fb0a5f631df046ce974e290470a9ea1","engines":{"node":">=20"},"exports":{".":{"types":"./dist/index.d.mts","import":"./dist/index.mjs","default":"./dist/index.mjs"},"./code":{"types":"./dist/code/index.d.mts","import":"./dist/code/index.mjs","default":"./dist/code/index.mjs"},"./operations":{"types":"./dist/services/affinity.d.mts","import":"./dist/services/affinity.mjs","default":"./dist/services/affinity.mjs"}},"license":"MIT","scripts":{"build":"vp pack","check":"bun run generate:check && vp check && bun test && bun run build && bun run package:check","clean":"rm -rf dist","convert":"bun scripts/convert.ts","generate":"bun run convert && bun scripts/generate.ts && bun scripts/generate-code.ts","package:check":"bun scripts/check-package.ts","generate:check":"bun scripts/generate-check.ts","prepublishOnly":"bun run check"},"version":"0.3.1","_npmUser":{"name":"dawsson","email":"hello@dawson.gg"},"homepage":"https://docs.joinaffinityai.com/api","_integrity":"sha512-/gWnpMGNuZa4QJtGREMhHUN0YTDpy9unoUrT0tmIG9Wdlpe7K1jER/UbEg+ihg63rCh2sKZrNyLGxVFeYMS9CA==","repository":{"url":"git+https://github.com/affinity-health/affinity-effect-sdk.git","type":"git"},"_npmVersion":"10.8.3","description":"Effect-native TypeScript SDK for the Affinity API","directories":{},"maintainers":[{"name":"dawsson","email":"hello@dawson.gg"}],"sideEffects":false,"_nodeVersion":"26.3.0","dependencies":{"@effect/platform-bun":"4.0.0-rc.112","@distilled.cloud/core":"1.0.0-rc.8"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"packageManager":"bun@1.3.12","devDependencies":{"effect":"4.0.0-rc.112","vite-plus":"0.3.0","@types/bun":"1.4.0","typescript":"7.0.2","@typescript/native-preview":"7.0.0-dev.20260707.2"},"peerDependencies":{"effect":">=4.0.0-rc.112 || >=4.0.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/effect-sdk_0.3.1_1788141290513_0.9019441725848565"}}},"time":{"created":"2026-08-31T00:51:49.363Z","modified":"2026-08-31T01:54:50.774Z","0.1.0":"2026-08-31T00:51:49.715Z","0.2.0":"2026-08-31T01:14:07.129Z","0.3.0":"2026-08-31T01:54:09.320Z","0.3.1":"2026-08-31T01:54:50.603Z"},"bugs":{"url":"https://github.com/affinity-health/affinity-effect-sdk/issues"},"license":"MIT","homepage":"https://docs.joinaffinityai.com/api","repository":{"url":"git+https://github.com/affinity-health/affinity-effect-sdk.git","type":"git"},"description":"Effect-native TypeScript SDK for the Affinity API","maintainers":[{"name":"dawsson","email":"hello@dawson.gg"}],"readme":"# Affinity Effect SDK\n\nEffect-native TypeScript SDK and local code runner for the Affinity API. The repository generates 52 typed operations and runtime schemas from Affinity's OpenAPI document.\n\n## Install\n\n```sh\nbun add @affinity-health/effect-sdk effect@rc\n```\n\nSet the API key in the process environment. The CLI never accepts secrets as flags.\n\n```sh\naffinity auth login\n# Request read and write access.\naffinity auth login --access write\n```\n\nThe CLI opens Affinity's browser approval page, polls using OAuth device authorization, and stores\nthe resulting expiring credential in the user's configuration directory with owner-only\npermissions. Inspect or revoke it without exposing the token:\n\n```sh\naffinity auth status --json\naffinity auth logout\n```\n\nA device login can authorize one or more organizations. Select an organization for each command:\n\n```sh\naffinity context --json\naffinity eval 'await affinity.getAccount({})' --organization org_example\n```\n\nWhen the login contains one organization, the CLI selects it automatically. For repeated work,\nset `AFFINITY_ORGANIZATION_ID`. The API rejects an organization that was not approved during\ndevice login.\n\n`AFFINITY_API_KEY` remains available as an explicit environment override for non-interactive\nautomation. Never pass a credential as a command argument.\n\nGive an agent the complete operating contract before it acts:\n\n```sh\naffinity context\naffinity context --json\n```\n\nThe text form is a concise briefing. The JSON form also includes the generated operation catalog,\npolicy classes, clinical invariants, authentication status, and the default budget of 100 API\nrequests with a 30-second timeout per request. It does not require credentials.\n\n## Agent code mode\n\nEvaluate one asynchronous JavaScript expression:\n\n```sh\naffinity eval 'await affinity.getAccount({})'\n```\n\nList every callable operation without making a request:\n\n```sh\naffinity operations\naffinity operations --json\n```\n\nPipe an expression over stdin and get compact JSON:\n\n```sh\nprintf 'await affinity.listPractices({ limit: 10 })' | affinity eval - --json\n```\n\nFor longer programs, default-export an `AgentProgram` from a TypeScript or JavaScript module:\n\n```ts\nimport type { AgentProgram } from \"@affinity-health/effect-sdk/code\";\n\nconst program: AgentProgram = async ({ affinity, log }) => {\n  log(\"Reading the first ten practices\");\n  return affinity.listPractices({ limit: 10 });\n};\n\nexport default program;\n```\n\nRun it with Bun:\n\n```sh\naffinity run program.ts --json\n```\n\nThe runner puts the program's result on stdout. `log(...)`, diagnostics, and errors go to stderr, so agents can parse stdout without removing status messages.\n\n### Mutation policy\n\nCode sessions are read-only by default. Test-mode mutations require `--apply`:\n\n```sh\naffinity run setup-practice.ts --apply\n```\n\nOrder creation, cancellation, and signing-session operations also require `--allow-clinical`. Test mode must use synthetic patient and prescription data.\n\nLive mutations require an exact second confirmation:\n\n```sh\naffinity run update-practice.ts \\\n  --mode live \\\n  --apply \\\n  --confirm-live LIVE\n```\n\nThe mode flag governs the runner's policy. The API key and server remain responsible for authorization and the actual Test or Live data boundary.\n\nEach session permits 100 operations by default, with a 30-second timeout per operation. Use `--max-requests` and `--timeout` to lower or raise those limits.\n\nThe runner executes local code with the current operating-system user's permissions. It is not a sandbox. Run only code you trust. The runner removes `AFFINITY_API_KEY` from its process environment before evaluating agent code, but the injected `affinity` client remains authorized for the operations allowed by the session policy.\n\n## Await-friendly library\n\nApplications can create the same client without the CLI:\n\n```ts\nimport { createCodeSession } from \"@affinity-health/effect-sdk/code\";\n\nconst session = createCodeSession({\n  apiKey: process.env.AFFINITY_API_KEY!,\n  mode: \"test\",\n  organizationId: \"org_example\",\n});\n\ntry {\n  const account = await session.affinity.getAccount({});\n  console.log(account);\n} finally {\n  await session.dispose();\n}\n```\n\nUse `createCodeSession` for bounded work because it exposes `dispose()`. `createClient` is available for process-lifetime clients.\n\n## Raw Effect operations\n\nThe package root exports the generated Effect operations directly:\n\n```ts\nimport { Effect } from \"effect\";\nimport { layer, updatePatient } from \"@affinity-health/effect-sdk\";\n\nconst program = updatePatient({\n  practiceId: \"prac_example\",\n  patientId: \"pat_example\",\n  name: {\n    first: \"Jane\",\n    last: \"Doe\",\n  },\n});\n\nconst patient = await Effect.runPromise(\n  program.pipe(\n    Effect.provide(\n      layer({\n        apiKey: process.env.AFFINITY_API_KEY!,\n      }),\n    ),\n  ),\n);\n```\n\nOperations have typed success, failure, and service requirements. Credentials resolve for each request, and service keys stay redacted inside the Effect configuration.\n\n## Configuration\n\nThe library accepts:\n\n- `apiKey`, required\n- `apiBaseUrl`, defaulting to `https://api.joinaffinityai.com`\n- `apiVersion`, defaulting to `2026-08-11`\n- `actor`, an optional provider or user attribution\n\nThe CLI reads `AFFINITY_API_KEY`, `AFFINITY_API_BASE_URL`, `AFFINITY_API_VERSION`, `AFFINITY_ACTOR_ID`, `AFFINITY_ACTOR_TYPE`, and `AFFINITY_MODE`. Invocation flags take precedence over environment defaults for non-secret settings.\n\nThe SDK has no telemetry. The library supports runtimes with `fetch`, including Bun, Node.js 20 or newer, browsers, and workers. The CLI requires Bun. Service API keys must stay in trusted server-side code.\n\n## Regenerate\n\nThe repository commits the official Affinity OpenAPI document and generated TypeScript:\n\n```sh\nbun run generate\nbun run check\n```\n\nGeneration uses Distilled's OpenAPI-to-Smithy converter and Effect SDK generator. It also builds the agent operation registry from the same OpenAPI paths. Do not edit `src/services` or `src/code/registry.ts` by hand.\n","readmeFilename":"README.md"}