{"_id":"@afinx/bridge-sdk","_rev":"5-17dc0c4d2b0f99096be040a8f9f485dc","name":"@afinx/bridge-sdk","dist-tags":{"latest":"0.2.1"},"versions":{"0.1.0":{"name":"@afinx/bridge-sdk","version":"0.1.0","keywords":["afinx","bridge","banking","mobile-money","momo","africa","ghana","fintech","open-banking","account-linking","plaid"],"author":{"name":"afinX","email":"hello@afinx.co"},"license":"MIT","_id":"@afinx/bridge-sdk@0.1.0","maintainers":[{"name":"afinx-team","email":"dev@afinx.co"}],"homepage":"https://github.com/afinx-team/afinx-bridge-sdk#readme","bugs":{"url":"https://github.com/afinx-team/afinx-bridge-sdk/issues"},"dist":{"shasum":"79b55961daac84fee16151d31d18259b12d802b8","tarball":"https://registry.npmjs.org/@afinx/bridge-sdk/-/bridge-sdk-0.1.0.tgz","fileCount":8,"integrity":"sha512-w6KY3nyKXGDIbcLsD9mbGztb8ugyCUph8mgl8I/uIxErfcXOLAOB1tlonHXefHiN22+PCNQToXkzADSV9Zc/1A==","signatures":[{"sig":"MEYCIQCVjCEdPP6FfWW3s/kUwF+iLWfBCCrF9ZVMrgQj9BOo/QIhAO7lDqmE4OEU6Z3tPUoTBycqz074GznvWoNvj8NvlBLT","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":25050},"main":"dist/index.js","types":"dist/index.d.ts","module":"dist/index.mjs","engines":{"node":">=18"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"gitHead":"62bdb6b88c236cc27efb490717b42f317f15d1ac","scripts":{"dev":"tsup src/index.ts --format cjs,esm --dts --watch","build":"tsup src/index.ts --format cjs,esm --dts --clean","prepublishOnly":"npm run build"},"_npmUser":{"name":"afinx-team","email":"dev@afinx.co"},"repository":{"url":"git+https://github.com/afinx-team/afinx-bridge-sdk.git","type":"git"},"_npmVersion":"11.6.2","description":"JavaScript SDK for integrating afinX Bridge — connect bank accounts and mobile money across Africa.","directories":{},"sideEffects":false,"_nodeVersion":"24.13.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.0","typescript":"^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/bridge-sdk_0.1.0_1777772587551_0.6506225566237631","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@afinx/bridge-sdk","version":"0.1.1","keywords":["afinx","bridge","banking","mobile-money","momo","africa","ghana","fintech","open-banking","account-linking","plaid"],"author":{"name":"afinX","email":"hello@afinx.co"},"license":"MIT","_id":"@afinx/bridge-sdk@0.1.1","maintainers":[{"name":"afinx-team","email":"dev@afinx.co"}],"homepage":"https://github.com/afinx-team/afinx-bridge-sdk#readme","bugs":{"url":"https://github.com/afinx-team/afinx-bridge-sdk/issues"},"dist":{"shasum":"1b72a2f08bfff66c887c2fb21e295cdd5ad5e320","tarball":"https://registry.npmjs.org/@afinx/bridge-sdk/-/bridge-sdk-0.1.1.tgz","fileCount":8,"integrity":"sha512-H5GVkE+qb1a8KvkjMYmgZaeMgPFdz5rTigQnLeo+cSoONU7O8iXvMGFc1HLVXGmLCi9tM35ct+1coePVJr4hBg==","signatures":[{"sig":"MEUCIQCE5zskhhvcHVWG06YJUgpsWL3eejnWmTqSQhng7Q9l/AIgSZDVgxN7s4wqqgBWnV4DJJCOUeRQO7x150sSE+1cFQI=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":25074},"main":"dist/index.js","types":"dist/index.d.ts","module":"dist/index.mjs","engines":{"node":">=18"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"gitHead":"093de939a48753d216c6b55023f891b844b37a13","scripts":{"dev":"tsup src/index.ts --format cjs,esm --dts --watch","build":"tsup src/index.ts --format cjs,esm --dts --clean","prepublishOnly":"npm run build"},"_npmUser":{"name":"afinx-team","email":"dev@afinx.co"},"repository":{"url":"git+https://github.com/afinx-team/afinx-bridge-sdk.git","type":"git"},"_npmVersion":"11.6.2","description":"JavaScript SDK for integrating afinX Bridge — connect bank accounts and mobile money across Africa.","directories":{},"sideEffects":false,"_nodeVersion":"24.13.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.0","typescript":"^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/bridge-sdk_0.1.1_1777818115270_0.7632904020374041","host":"s3://npm-registry-packages-npm-production"}},"0.1.2":{"name":"@afinx/bridge-sdk","version":"0.1.2","keywords":["afinx","bridge","banking","mobile-money","momo","africa","ghana","fintech","open-banking","account-linking","plaid"],"author":{"name":"afinX","email":"hello@afinx.co"},"license":"MIT","_id":"@afinx/bridge-sdk@0.1.2","maintainers":[{"name":"afinx-team","email":"dev@afinx.co"}],"homepage":"https://github.com/afinx-team/afinx-bridge-sdk#readme","bugs":{"url":"https://github.com/afinx-team/afinx-bridge-sdk/issues"},"dist":{"shasum":"ce5a701c00ac5eacfeb3c89a95a34ea037dc52e8","tarball":"https://registry.npmjs.org/@afinx/bridge-sdk/-/bridge-sdk-0.1.2.tgz","fileCount":8,"integrity":"sha512-x0cY6Rz3TQgJ0vBBMIZE0fzgrWqi6wc8SfNjuNEFv92u7qAVCqpw4EJTlV4NPsG5+N4JE+EXCiAx7b+JqQ6iEg==","signatures":[{"sig":"MEUCIALN0UoQCC9Tin37PtH09n7aP3KuA6eIVCl8h8DakRIcAiEAlXfp5d7EJJ6cQIzqkhxvSp5At2mn6GucR3miYXQ8SIw=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":25732},"main":"dist/index.js","types":"dist/index.d.ts","module":"dist/index.mjs","engines":{"node":">=18"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"gitHead":"093de939a48753d216c6b55023f891b844b37a13","scripts":{"dev":"tsup src/index.ts --format cjs,esm --dts --watch","build":"tsup src/index.ts --format cjs,esm --dts --clean","prepublishOnly":"npm run build"},"_npmUser":{"name":"afinx-team","email":"dev@afinx.co"},"repository":{"url":"git+https://github.com/afinx-team/afinx-bridge-sdk.git","type":"git"},"_npmVersion":"11.6.2","description":"JavaScript SDK for integrating afinX Bridge — connect bank accounts and mobile money across Africa.","directories":{},"sideEffects":false,"_nodeVersion":"24.13.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.0","typescript":"^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/bridge-sdk_0.1.2_1777821550341_0.7003706036976638","host":"s3://npm-registry-packages-npm-production"}},"0.2.0":{"name":"@afinx/bridge-sdk","version":"0.2.0","keywords":["afinx","bridge","banking","mobile-money","momo","africa","ghana","fintech","open-banking","account-linking","plaid"],"author":{"name":"afinX","email":"hello@afinx.co"},"license":"MIT","_id":"@afinx/bridge-sdk@0.2.0","maintainers":[{"name":"afinx-team","email":"dev@afinx.co"}],"homepage":"https://github.com/afinx-team/afinx-bridge-sdk#readme","bugs":{"url":"https://github.com/afinx-team/afinx-bridge-sdk/issues"},"dist":{"shasum":"11aa2f07d5b95a18ea48932a279fed7df9428abb","tarball":"https://registry.npmjs.org/@afinx/bridge-sdk/-/bridge-sdk-0.2.0.tgz","fileCount":8,"integrity":"sha512-7Gg4bB6lVgWchhF2STNfJCXsJOA81PCc/EkYk+OaHI+jAGZv/8yhdlpjDUb4ckmgq7Dr8Xu7JHc8/EaS4ih9KA==","signatures":[{"sig":"MEUCIQDoFJ09L01b+JegNI4c3o0yk9PyExMr+crLKnMC3G05iwIgcCHm1YY/GSE71lC9ViYxbhZQgqRw4eYf58MxUQunPCI=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":28439},"main":"dist/index.js","types":"dist/index.d.ts","module":"dist/index.mjs","engines":{"node":">=18"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"gitHead":"0d48b48116a7ec47b1266a54b226862168cd4097","scripts":{"dev":"tsup src/index.ts --format cjs,esm --dts --watch","build":"tsup src/index.ts --format cjs,esm --dts --clean","prepublishOnly":"npm run build"},"_npmUser":{"name":"afinx-team","email":"dev@afinx.co"},"repository":{"url":"git+https://github.com/afinx-team/afinx-bridge-sdk.git","type":"git"},"_npmVersion":"11.6.2","description":"JavaScript SDK for integrating afinX Bridge — connect bank accounts and mobile money across Africa.","directories":{},"sideEffects":false,"_nodeVersion":"24.13.0","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.0","typescript":"^5.0.0"},"_npmOperationalInternal":{"tmp":"tmp/bridge-sdk_0.2.0_1780851620475_0.5041099883342874","host":"s3://npm-registry-packages-npm-production"}},"0.2.1":{"name":"@afinx/bridge-sdk","version":"0.2.1","description":"JavaScript SDK for integrating Afinx Bridge — connect bank accounts and mobile money across Africa.","main":"dist/index.js","module":"dist/index.mjs","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"sideEffects":false,"engines":{"node":">=18"},"scripts":{"build":"tsup src/index.ts --format cjs,esm --dts --clean","dev":"tsup src/index.ts --format cjs,esm --dts --watch","prepublishOnly":"npm run build"},"keywords":["afinx","bridge","banking","mobile-money","momo","africa","ghana","fintech","open-banking","account-linking","plaid"],"author":{"name":"Afinx","email":"hello@afinx.co"},"license":"MIT","homepage":"https://github.com/afinx-team/afinx-bridge-sdk#readme","bugs":{"url":"https://github.com/afinx-team/afinx-bridge-sdk/issues"},"repository":{"type":"git","url":"git+https://github.com/afinx-team/afinx-bridge-sdk.git"},"publishConfig":{"access":"public"},"devDependencies":{"tsup":"^8.0.0","typescript":"^5.0.0"},"gitHead":"f1369e5ced1e32cb19143a99fd6d0cb64b2e3108","_id":"@afinx/bridge-sdk@0.2.1","_nodeVersion":"24.13.0","_npmVersion":"11.6.2","dist":{"integrity":"sha512-hr02EI4IP139V9hcXx0tftK6szj9L2k6eMs1wUDx9BDxJwSoj0LMEVOsP2QsewfCjvsvOu0j6rj0S8zqABV6UQ==","shasum":"1db17013ea809978b373a67f7360e2373bbd99b0","tarball":"https://registry.npmjs.org/@afinx/bridge-sdk/-/bridge-sdk-0.2.1.tgz","fileCount":8,"unpackedSize":28439,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIB/1E0F2oHPXwxCVh59Z1NduHe5bB+BnUhZ8wjjzStBuAiANKkIOH2cx9+NhYzRB9dhe6UODtduzRlewYQAhmlWDmw=="}]},"_npmUser":{"name":"afinx-team","email":"dev@afinx.co"},"directories":{},"maintainers":[{"name":"afinx-team","email":"dev@afinx.co"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/bridge-sdk_0.2.1_1781451850204_0.2787650201700027"},"_hasShrinkwrap":false}},"time":{"created":"2026-05-03T01:43:07.436Z","modified":"2026-06-14T15:44:10.465Z","0.1.0":"2026-05-03T01:43:07.686Z","0.1.1":"2026-05-03T14:21:55.428Z","0.1.2":"2026-05-03T15:19:10.482Z","0.2.0":"2026-06-07T17:00:20.624Z","0.2.1":"2026-06-14T15:44:10.339Z"},"bugs":{"url":"https://github.com/afinx-team/afinx-bridge-sdk/issues"},"author":{"name":"Afinx","email":"hello@afinx.co"},"license":"MIT","homepage":"https://github.com/afinx-team/afinx-bridge-sdk#readme","keywords":["afinx","bridge","banking","mobile-money","momo","africa","ghana","fintech","open-banking","account-linking","plaid"],"repository":{"type":"git","url":"git+https://github.com/afinx-team/afinx-bridge-sdk.git"},"description":"JavaScript SDK for integrating Afinx Bridge — connect bank accounts and mobile money across Africa.","maintainers":[{"name":"afinx-team","email":"dev@afinx.co"}],"readme":"# @afinx/bridge-sdk\n\nJavaScript SDK for integrating the **Afinx Bridge** widget — let your users\nsecurely connect their bank accounts and mobile money wallets across Africa.\n\n```bash\nnpm install @afinx/bridge-sdk\n```\n\n## Production (recommended): server-minted link token\n\nKeep your secret key on your **server**. Mint a one-shot link token there, hand\nit to the browser, and pass it to the SDK — the key never ships in client code.\n\n```ts\n// 1. Your backend mints a link token with your secret key.\n//    POST https://api.afinx.co/bridge/link-token\n//    Authorization: Bearer afinx_test_sk_...   → { linkToken: \"link_...\" }\n\n// 2. Your frontend opens the widget with that token (no key in the browser):\nimport { createBridge } from '@afinx/bridge-sdk';\n\nconst bridge = createBridge(); // no apiKey needed when you pass a linkToken\nbridge.open({\n  linkToken,                              // from your backend\n  onSuccess: async (publicToken) => {\n    // 3. Exchange the public token on YOUR BACKEND (never in the browser).\n    await fetch('/api/afinx/exchange-token', {\n      method: 'POST',\n      body: JSON.stringify({ publicToken }),\n    });\n  },\n  onExit: () => console.log('User closed the widget.'),\n  onError: (err) => console.error('Bridge error:', err),\n});\n```\n\n## Sandbox quick start\n\nFor quick local testing you can let the SDK mint the link token in-browser with\na **sandbox** key. Don't use this with a live key — the key would be exposed in\nclient code.\n\n```ts\nconst bridge = createBridge({ apiKey: 'afinx_test_sk_...', environment: 'sandbox' });\nbridge.open({ userId: 'user_123', onSuccess: (publicToken) => {/* … */} });\n```\n\nEither way, the widget handles institution selection, credential capture,\nUSSD/OTP MFA (and inbox/upload for the Statements product), and returns a\nsingle-use `publicToken` your backend exchanges for an access token.\n\n## Configuration\n\n### `createBridge(config)`\n\n| Field | Type | Required | Default | Description |\n|---|---|---|---|---|\n| `apiKey` | `string` | no* | — | `afinx_test_sk_...` / `afinx_live_sk_...`. *Required only if you DON'T pass a `linkToken` to `open()` (i.e. the sandbox in-browser-mint path). Omit it in production. |\n| `environment` | `'sandbox' \\| 'production'` | no | `'production'` | Selects the default `apiUrl` and `bridgeUrl`. |\n| `apiUrl` | `string` | no | env-derived | Override the API host (self-hosted setups, custom subdomains). |\n| `bridgeUrl` | `string` | no | env-derived | Override the widget host. |\n\n**Default URLs by environment**\n\n| Environment | `apiUrl` | `bridgeUrl` |\n|---|---|---|\n| `sandbox` | `https://api.sandbox.afinx.co` | `https://bridge.afinx.co` |\n| `production` | `https://api.afinx.co` | `https://bridge.afinx.co` |\n\nThe widget URL is the same in both environments — the link token (minted by\neither the sandbox or live API) tells the widget which API to call back to.\nOne widget deployment serves both.\n\n> **Security:** never put a live `apiKey` in client-side code. For browser\n> integrations, mint a one-shot link token on your backend and pass it to\n> `open({ linkToken })` instead (see [Production](#production-recommended-server-minted-link-token)). Available since 0.2.0.\n\n### `bridge.open(options)`\n\n| Field | Type | Description |\n|---|---|---|\n| `linkToken` | `string` | A one-shot link token your backend minted (`POST /bridge/link-token`). Pass this in production — the SDK then skips client-side minting, so `apiKey` isn't needed in the browser. |\n| `userId` | `string` | Your stable identifier for the end user. |\n| `redirectUri` | `string` | Where to send the user after the flow (redirect mode — coming in 0.2). |\n| `webhookUrl` | `string` | Per-session webhook override. Falls back to your developer-level webhook. |\n| `metadata` | `object` | Arbitrary JSON attached to the session and returned in webhooks. |\n| `onSuccess` | `(publicToken, metadata) => void` | Fired with the single-use public token. |\n| `onExit` | `(error?) => void` | Fired when the user closes the widget. `error` is set if the close was due to a problem. |\n| `onError` | `(error) => void` | Fired on terminal failures (network, invalid session, etc.). |\n\n### `bridge.close()` / `bridge.isOpen()`\n\nProgrammatic control of the widget. Useful for cleanup on route change in SPAs.\n\n```ts\nuseEffect(() => () => bridge.close(), []);\n```\n\n## Token exchange (server-side)\n\nThe `publicToken` returned to `onSuccess` is **single-use** and **expires in\n10 minutes**. Exchange it on your backend immediately:\n\n```ts\n// pages/api/afinx/exchange-token.ts (Next.js example)\nconst r = await fetch('https://api.afinx.co/bridge/exchange-token', {\n  method: 'POST',\n  headers: {\n    'Authorization': `Bearer ${process.env.AFINX_API_KEY}`,\n    'Content-Type': 'application/json',\n  },\n  body: JSON.stringify({ publicToken: req.body.publicToken }),\n});\nconst { accessToken, itemId, accounts } = await r.json();\n// Persist accessToken keyed on your user. Use it to call /v1/transactions etc.\n```\n\n## TypeScript\n\nFull types ship with the package — `BridgeConfig`, `BridgeOpenOptions`,\n`BridgeInstance` are exported.\n\n```ts\nimport type { BridgeConfig, BridgeOpenOptions } from '@afinx/bridge-sdk';\n```\n\n## Bundle size\n\n- Tree-shakeable (`\"sideEffects\": false`).\n- Zero runtime dependencies.\n- ~3 kB gzipped.\n\n## Browser support\n\nModern evergreen browsers (Chrome/Edge/Firefox/Safari, last 2 versions). The\nSDK uses `window.postMessage`, `window.open`, and `fetch` — no polyfills\nincluded, no IE11.\n\n## Versioning\n\nThis package follows [Semantic Versioning](https://semver.org/) starting at\n0.1.0. While the major version is `0.x`, minor releases may include breaking\nchanges. **Pin to a minor in production**:\n\n```jsonc\n// package.json\n\"@afinx/bridge-sdk\": \"~0.2.0\"   // accepts 0.2.x, not 0.3.0\n```\n\n## Links\n\n- Docs: https://afinx.co/docs\n- Dashboard: https://afinx.co/dashboard\n- Changelog: [CHANGELOG.md](./CHANGELOG.md)\n- Issues: https://github.com/afinx/bridge-sdk/issues\n\n## License\n\nMIT — see [LICENSE](./LICENSE).\n","readmeFilename":"README.md"}