{"_id":"@alguna/sdk","_rev":"4-7a1e428ecaea20c337746a2a580292e1","name":"@alguna/sdk","dist-tags":{"latest":"0.4.0"},"versions":{"0.1.0":{"name":"@alguna/sdk","version":"0.1.0","keywords":["alguna","billing","subscriptions","invoicing","payments"],"author":{"name":"Alguna"},"license":"UNLICENSED","_id":"@alguna/sdk@0.1.0","maintainers":[{"name":"joluna","email":"joe-r@live.co.uk"},{"name":"reecepm","email":"reecemartin1425@gmail.com"}],"homepage":"https://docs.alguna.io","bugs":{"url":"https://github.com/alguna-io/monorepo/issues"},"dist":{"shasum":"0733d673e8caa0c3dad01880c7e42ba9778dc0d6","tarball":"https://registry.npmjs.org/@alguna/sdk/-/sdk-0.1.0.tgz","fileCount":8,"integrity":"sha512-M5MLZveqIR32A933kIV7Cfm2iHOnQQ4jUood/1PClgaYp0KaWAdfM672HtuZ2Ir2pqyq2Y5j0PMvVni/pDdpkg==","signatures":[{"sig":"MEUCIA0Y3Yz/ypV3M0p0Ijs7DSf7j+z0cHfZSAH1thGrya2uAiEAm6lFnxeU3lIpiDvwb4hSy9nB5fipeft+bJ6e1bfisPc=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":1306858},"main":"./dist/index.js","_from":"file:alguna-sdk-0.1.0.tgz","types":"./dist/index.d.ts","module":"./dist/index.mjs","engines":{"node":">=18.0.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"scripts":{"lint":"biome check .","test":"vitest run","build":"tsup","clean":"rm -rf .turbo node_modules dist","generate":"tsx scripts/generate.ts","lint:fix":"biome check --fix .","test:watch":"vitest","type-check":"tsc --noEmit"},"_npmUser":{"name":"joluna","email":"joe-r@live.co.uk"},"_resolved":"/tmp/29a68ba138773efb2c537ce3462e2ea7/alguna-sdk-0.1.0.tgz","_integrity":"sha512-M5MLZveqIR32A933kIV7Cfm2iHOnQQ4jUood/1PClgaYp0KaWAdfM672HtuZ2Ir2pqyq2Y5j0PMvVni/pDdpkg==","repository":{"url":"git+https://github.com/alguna-io/monorepo.git","type":"git","directory":"typescript/packages/sdk"},"_npmVersion":"10.9.8","description":"Official TypeScript SDK for the Alguna Public API","directories":{},"sideEffects":false,"_nodeVersion":"22.23.1","dependencies":{"axios":"^1.7.9"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.2","tsup":"^8.3.5","vitest":"^4.0.18","typescript":"^7.0.2","@hey-api/openapi-ts":"^0.95.0"},"_npmOperationalInternal":{"tmp":"tmp/sdk_0.1.0_1786437647025_0.9775534316877248","host":"s3://npm-registry-packages-npm-production"}},"0.2.0":{"name":"@alguna/sdk","version":"0.2.0","keywords":["alguna","billing","subscriptions","invoicing","payments"],"author":{"name":"Alguna"},"license":"UNLICENSED","_id":"@alguna/sdk@0.2.0","maintainers":[{"name":"joluna","email":"joe-r@live.co.uk"},{"name":"reecepm","email":"reecemartin1425@gmail.com"}],"homepage":"https://docs.alguna.io","bugs":{"url":"https://github.com/alguna-io/monorepo/issues"},"dist":{"shasum":"0e26ea109a2f9cca042fe14f73617369b2bcd574","tarball":"https://registry.npmjs.org/@alguna/sdk/-/sdk-0.2.0.tgz","fileCount":8,"integrity":"sha512-mCIxFavFSO4CM6zJnGFHQcYlW8K0H6YSKEbWRbNjwSjRY7WGIfaDtGlzS6cfp3U8Yf/clf6vWgZS48xjRlU0Bw==","signatures":[{"sig":"MEUCIEFv96+DINb1TeHfPq1/mWz1mF8gi6cqrhUcSxFc+pzuAiEAyjE/C/jYA8xeOiM3/89oxPob3hhCjLnEjtnoyGyM1o0=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":1478356},"main":"./dist/index.js","_from":"file:alguna-sdk-0.2.0.tgz","types":"./dist/index.d.ts","module":"./dist/index.mjs","engines":{"node":">=18.0.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"scripts":{"lint":"biome check .","test":"vitest run","build":"tsup","clean":"rm -rf .turbo node_modules dist","generate":"tsx scripts/generate.ts","lint:fix":"biome check --fix .","test:watch":"vitest","type-check":"tsc --noEmit"},"_npmUser":{"name":"joluna","email":"joe-r@live.co.uk"},"_resolved":"/tmp/6f3ab752a2ac0daac34b5da593f88f49/alguna-sdk-0.2.0.tgz","_integrity":"sha512-mCIxFavFSO4CM6zJnGFHQcYlW8K0H6YSKEbWRbNjwSjRY7WGIfaDtGlzS6cfp3U8Yf/clf6vWgZS48xjRlU0Bw==","repository":{"url":"git+https://github.com/alguna-io/monorepo.git","type":"git","directory":"typescript/packages/sdk"},"_npmVersion":"10.9.8","description":"Official TypeScript SDK for the Alguna Public API","directories":{},"sideEffects":false,"_nodeVersion":"22.23.2","dependencies":{"axios":"^1.7.9"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.2","tsup":"^8.3.5","vitest":"^4.0.18","typescript":"^7.0.2","@hey-api/openapi-ts":"^0.95.0"},"_npmOperationalInternal":{"tmp":"tmp/sdk_0.2.0_1788273261786_0.8849640952568041","host":"s3://npm-registry-packages-npm-production"}},"0.3.0":{"name":"@alguna/sdk","version":"0.3.0","keywords":["alguna","billing","subscriptions","invoicing","payments"],"author":{"name":"Alguna"},"license":"UNLICENSED","_id":"@alguna/sdk@0.3.0","maintainers":[{"name":"joluna","email":"joe-r@live.co.uk"},{"name":"reecepm","email":"reecemartin1425@gmail.com"}],"homepage":"https://alguna.com/docs","bugs":{"email":"support@alguna.io"},"dist":{"shasum":"cc0a862ca08ef3ad11ed5ddb09ea8cc24f982a0a","tarball":"https://registry.npmjs.org/@alguna/sdk/-/sdk-0.3.0.tgz","fileCount":8,"integrity":"sha512-S+ygNtLC8bVqhDUbF+Dyv8bRtrwueVdQCSzeS8MuBg8MPsNs3VVItOXISMC3JDdIMkPU6cjxCA5KbZlTJRF+cg==","signatures":[{"sig":"MEUCIQCyIcV13mEg9vDc8H9bCXnFsa/IFehW5S+VH7j0L78WDwIgFz29ZRpPNHkeuBET4p5lvukxI2Xcs5dJ4ExEgh79xqQ=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"sig":"MEUCIQDg+ewpgbukbADM2zqeLaaV6pr49ZtbePxYXBk06vW24QIgZTrkg2W6CowIB/JAUPWYdbFj/tDzka4az8xRrMMrfdU=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":1506069},"main":"./dist/index.js","_from":"file:alguna-sdk-0.3.0.tgz","types":"./dist/index.d.ts","module":"./dist/index.mjs","engines":{"node":">=18.0.0"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"}},"scripts":{"lint":"biome check .","test":"vitest run","build":"tsup","clean":"rm -rf .turbo node_modules dist","generate":"tsx scripts/generate.ts","lint:fix":"biome check --fix .","test:watch":"vitest","type-check":"tsc --noEmit"},"_npmUser":{"name":"joluna","email":"joe-r@live.co.uk"},"_resolved":"/tmp/b44eea969ee9d161f6a7c47ec9048652/alguna-sdk-0.3.0.tgz","_integrity":"sha512-S+ygNtLC8bVqhDUbF+Dyv8bRtrwueVdQCSzeS8MuBg8MPsNs3VVItOXISMC3JDdIMkPU6cjxCA5KbZlTJRF+cg==","_npmVersion":"10.9.8","description":"Official TypeScript SDK for the Alguna Public API","directories":{},"sideEffects":false,"_nodeVersion":"22.23.2","dependencies":{"axios":"^1.7.9"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.2","tsup":"^8.3.5","vitest":"^4.0.18","typescript":"^7.0.2","@hey-api/openapi-ts":"^0.95.0"},"_npmOperationalInternal":{"tmp":"tmp/sdk_0.3.0_1789488083355_0.318948439613417","host":"s3://npm-registry-packages-npm-production"}},"0.4.0":{"_id":"@alguna/sdk@0.4.0","bugs":{"email":"support@alguna.io"},"dist":{"shasum":"6065cf571ee01737d64b0fe7343a23ef13463a0f","tarball":"https://registry.npmjs.org/@alguna/sdk/-/sdk-0.4.0.tgz","integrity":"sha512-oeHti1CGApDErQryJBV35cqY+GkzGDR0bKLceC9hlXqr69Ev5332OJWARTJCfg1Ixi1QD5rnlZ+ObxUDCukXFw==","fileCount":9,"unpackedSize":5152634,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@alguna%2fsdk@0.4.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCZb1gdvLgn4h55f0OXr+rlIwxzrIdrWGXWaCM3wLnvmAIgFaZZuoZdxqnRrz3TYIvG6dEKWdkYlvBtCRsYWLnsobg="}]},"main":"./dist/index.js","name":"@alguna/sdk","types":"./dist/index.d.ts","author":{"name":"Alguna"},"module":"./dist/index.mjs","engines":{"node":">=20.0.0"},"exports":{".":{"import":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"require":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"./package.json":"./package.json"},"gitHead":"c3e259c54d4b43b2ec7554cb8f53771e2e9bf0b1","license":"Apache-2.0","scripts":{"build":"tsup","type-check":"tsc --noEmit"},"version":"0.4.0","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"3e93573a-a717-45e0-97c6-503cf023065c"},"approver":{"name":"reecepm","email":"reecemartin1425@gmail.com"}},"homepage":"https://alguna.com/docs","keywords":["alguna","billing","subscriptions","invoicing","payments"],"repository":{"url":"git+https://github.com/alguna-io/alguna-ts.git","type":"git"},"_npmVersion":"11.21.0","description":"Official TypeScript SDK for the Alguna Public API","directories":{},"maintainers":[{"name":"joluna","email":"joe-r@live.co.uk"},{"name":"reecepm","email":"reecemartin1425@gmail.com"}],"sideEffects":false,"_nodeVersion":"24.21.0","publishConfig":{"access":"public"},"devDependencies":{"tsup":"8.5.1","typescript":"6.0.3","@types/node":"24.12.0"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/sdk_0.4.0_1792411983823_0.7864332074165958"},"_hasShrinkwrap":false}},"time":{"created":"2026-08-11T08:40:46.827Z","modified":"2026-10-19T12:13:04.212Z","0.1.0":"2026-08-11T08:40:47.188Z","0.2.0":"2026-09-01T14:34:21.986Z","0.3.0":"2026-09-15T16:01:23.456Z","0.4.0":"2026-10-19T12:13:03.930Z"},"bugs":{"email":"support@alguna.io"},"author":{"name":"Alguna"},"license":"Apache-2.0","homepage":"https://alguna.com/docs","keywords":["alguna","billing","subscriptions","invoicing","payments"],"description":"Official TypeScript SDK for the Alguna Public API","maintainers":[{"name":"joluna","email":"joe-r@live.co.uk"},{"name":"reecepm","email":"reecemartin1425@gmail.com"}],"readme":"# @alguna/sdk\n\nThe official TypeScript SDK for the [Alguna API](https://alguna.com/docs): usage-based\nbilling, subscriptions, invoicing and payments. Upgrading from 0.3? Read\n[MIGRATING.md](https://github.com/alguna-io/alguna-ts/blob/main/MIGRATING.md).\n\n## Install\n\n```bash\nnpm install @alguna/sdk\n```\n\nThe SDK needs Node.js 20 or later, or another runtime with a global `fetch` and\n`crypto.randomUUID()`, such as Deno, Bun or Cloudflare Workers. Use it on a server only: the\nAPI key is a secret.\n\n## Client\n\nCreate an API key in the dashboard under **Settings → Connections → Developers → API keys**.\nA key looks like `<key_id>.<key_secret>`.\n\n```typescript\nimport { Alguna } from \"@alguna/sdk\";\n\n// With no options, the client reads the key from ALGUNA_API_KEY.\nconst alguna = new Alguna();\n\nconst sandbox = new Alguna({\n  apiKey: process.env.ALGUNA_SANDBOX_API_KEY, // a string, or a function called on every request\n  apiVersion: \"2026-04-01\", // default: the version this SDK release targets\n  baseUrl: \"https://api.sandbox.alguna.io\", // default: https://api.alguna.io\n  headers: { \"X-Trace-Id\": \"abc\" }, // sent on every request\n  fetch: globalThis.fetch, // your own fetch, for example to add tracing\n  logging: { level: \"debug\", silent: false }, // silent by default\n});\n```\n\n`new Alguna()` throws an `AlgunaError` when it finds no key: where there is no\n`process.env` (Workers, Deno), pass `apiKey`. Pin `apiVersion` to keep your integration on\none API version when you upgrade the package. The SDK sends\n`User-Agent: alguna-ts/<version>` where the runtime allows it (not in browsers); a\n`User-Agent` in `headers` replaces it. `console.log(alguna)` and `JSON.stringify(alguna)`\nnever print the API key.\n\n## Requests\n\nThe client has one field per API resource (`alguna.customers`, `alguna.subscriptions`,\n`alguna.invoices`, `alguna.wallets`, …) and one method per operation. The request and\nresponse types are exported from the package root (`CreateCustomerRequest`,\n`InvoiceResponse`) and under the `AlgunaApi` namespace.\n\n```typescript\nimport { Alguna } from \"@alguna/sdk\";\n\nconst alguna = new Alguna();\n\nconst customer = await alguna.customers.create({\n  name: \"Acme Corp\",\n  currency: \"USD\",\n  contacts: [{ email: \"billing@acme.com\", is_primary: true }],\n});\n\nconst invoice = await alguna.invoices.create({\n  customer_id: customer.id,\n  currency: \"USD\",\n  line_items: [{ description: \"Onboarding\", unit_price: \"500.00\", quantity: \"1\" }],\n});\n\n// A hosted customer portal session, where the customer can pay. It is valid for 1 hour.\nconst session = await alguna.portal.createSession({ customer_id: customer.id });\nconsole.log(invoice.id, session.url);\n```\n\nEvery method takes per-request options as its last argument: `idempotencyKey` (writes),\n`timeoutInSeconds`, `maxRetries`, `headers` and `abortSignal`. `invoices.generatePdf`,\n`quotes.getPdf` and `subscriptions.downloadPdf` return a `BinaryResponse`: read it with\n`arrayBuffer()`, `blob()` or `stream()`.\n\nFor an endpoint the SDK does not cover yet, `alguna.fetch(path, init, options)` sends a raw\nrequest with the client's auth, headers, timeout, Idempotency-Key and retries. It returns\nthe plain `Response`, whatever its status. When you pass `init`, the method, headers and body\ncome from `init` only, not from a `Request` you pass as `path`. A stream body, such as the\nbody of a `Request`, is read into memory before the first attempt, so that a retry can send\nit again.\n\n## Pagination\n\nA list method returns a `Page`: `data` holds the items of the current page, and `response`\nthe full body, with `pagination`.\n\n```typescript\nimport { Alguna } from \"@alguna/sdk\";\n\nconst alguna = new Alguna();\n\nconst page = await alguna.customers.list({ limit: 50 });\nconsole.log(page.data.length, page.response.pagination); // { per_page, total_pages }\n\n// The SDK gets the next page when you need it.\nfor await (const customer of await alguna.customers.list({ limit: 100 })) {\n  console.log(customer.id);\n}\n```\n\nThe API sends at most the operation's `limit` maximum per page (100 for every list today).\nIteration stops at the first page with fewer items than `limit`, or than that maximum when\n`limit` is larger. When the last page is exactly full, the SDK makes one more request, which\nreturns an empty page. To page by hand, use `page.hasNextPage()` and `page.getNextPage()`.\n\n## Idempotency and retries\n\nEvery request that is not a GET sends an `Idempotency-Key`: your `idempotencyKey`, or a\nUUID v4 that the SDK makes for the call. Every retry of the call sends the same key, so the\nAPI returns the first result and does not do the write again. Pass your own key when you\nrepeat a call yourself, for example after a restart:\n\n```typescript\nimport { Alguna } from \"@alguna/sdk\";\n\nconst alguna = new Alguna();\n\nawait alguna.customers.create(\n  { name: \"Acme Corp\", currency: \"USD\" },\n  { idempotencyKey: \"signup-1234\" },\n);\n```\n\nThe exceptions are `events.ingest`, `credits.track` and `credits.check`: they get no automatic\nkey, because the API identifies their work by the request body. It removes duplicate events by `unique_id`,\nand `credits.track` draws credit once for the same `unique_id`s. A new key on each call would\nreplace that identity on `credits.track`, so a call sent again, for example by a queue, would\ndraw credit twice. The SDK retries these calls without a key. A key that you pass is sent on\nevery attempt. `credits.check` with `reserve` needs your key, because the key identifies the\nhold.\n\nA failed attempt is retried 2 times by default (3 attempts in total) when:\n\n- the status is `408`, `429`, `502`, `503` or `504`;\n- the status is `409` with a `Retry-After` header. The API sends this only while a request\n  with the same key is still running. A `409` without `Retry-After` is a real conflict and is\n  not retried;\n- no response arrived: the connection was refused, reset or closed, or the attempt timed out.\n  Workers, Deno and browsers do not say why a connection failed, so there a TLS error is\n  retried too. This is safe: every retried request is a GET, carries an Idempotency-Key, or is\n  one of the exceptions above.\n\nThe SDK does not retry after you abort a call through `abortSignal`. Between attempts it\nwaits 1 s, then 2 s, with random jitter of 10%. When the response has `Retry-After`\n(seconds or an HTTP date), it waits that long instead, at most 60 s. Set `maxRetries` on the\nclient or on one call; `0` turns retries off.\n\n## Timeouts\n\nEach attempt times out after 60 s. Set `timeout` (in milliseconds) on the client, or\n`timeoutInSeconds` on one call. A timed-out attempt is retried, so one call can take\n3 × the timeout plus the waits. To limit the whole call, pass an `abortSignal`: when it\naborts, the SDK throws `AbortError`.\n\n```typescript\nimport { Alguna } from \"@alguna/sdk\";\n\nconst alguna = new Alguna({ timeout: 10_000 });\n\n// Each attempt may take 5 s; the call, with its retries, at most 20 s.\nconst customer = await alguna.customers.get(\"cus_123\", {\n  timeoutInSeconds: 5,\n  abortSignal: AbortSignal.timeout(20_000),\n});\nconsole.log(customer.name);\n```\n\n## Errors\n\nEvery error that the SDK throws extends `AlgunaError`:\n\n```typescript\nimport { Alguna, AlgunaError, NotFoundError, RateLimitError } from \"@alguna/sdk\";\n\nconst alguna = new Alguna();\n\ntry {\n  await alguna.customers.get(\"nope\");\n} catch (error) {\n  if (error instanceof NotFoundError) {\n    console.log(error.message, error.statusCode, error.requestId);\n  } else if (error instanceof RateLimitError) {\n    console.log(\"retry in\", error.headers[\"retry-after\"], \"seconds\");\n  } else if (error instanceof AlgunaError) {\n    console.log(error.cause); // the underlying error, when there is one\n  } else {\n    throw error;\n  }\n}\n```\n\n| Error                      | When                                          |\n| -------------------------- | --------------------------------------------- |\n| `ValidationError`          | 400                                           |\n| `AuthenticationError`      | 401                                           |\n| `PermissionDeniedError`    | 403                                           |\n| `NotFoundError`            | 404                                           |\n| `ConflictError`            | 409                                           |\n| `UnprocessableEntityError` | 422 (also a `ValidationError`)                |\n| `RateLimitError`           | 429                                           |\n| `InternalServerError`      | 5xx                                           |\n| `ApiError`                 | any other unsuccessful status                 |\n| `ConnectionError`          | no response: DNS, TLS, reset connection       |\n| `TimeoutError`             | `timeout` exceeded (also a `ConnectionError`) |\n| `AbortError`               | you aborted through `abortSignal`             |\n\nAn error from a response has `message`, `statusCode`, `requestId`, `code` (when the body has\none), `body` and `headers` (lower-cased). `message` is the body's `detail`, else its `title`,\nelse its `message`, else the HTTP status text. A connection failure has no `statusCode`; its\n`cause` holds the original error. Give the `requestId` when you contact support.\n\n## Webhooks\n\n`AlgunaWebhookEvent` is a union of every webhook body. Narrow on `type` to get a typed\n`data`:\n\n```typescript\nimport type { AlgunaWebhookEvent } from \"@alguna/sdk\";\n\nfunction handle(event: AlgunaWebhookEvent) {\n  switch (event.type) {\n    case \"payment.created\":\n      console.log(event.data.amount); // a decimal string\n      break;\n    default:\n      break; // new event types can arrive before you upgrade\n  }\n}\n```\n\nThe SDK types a payload; it does not check that Alguna sent it. Alguna signs every delivery\nwith Svix. Before you trust a payload, verify its `svix-id`, `svix-timestamp` and\n`svix-signature` headers against the raw request body with the Svix library:\n`new Webhook(secret).verify(rawBody, headers)`. See\n[Verifying signatures](https://alguna.com/docs/api-reference/v2/webhooks#verifying-signatures).\n\n## Reference\n\n- [TypeScript SDK guide](https://alguna.com/docs/api-reference/v2/sdks/typescript)\n- [API reference](https://alguna.com/docs/api-reference/v2/overview)\n- [Errors](https://alguna.com/docs/api-reference/v2/errors) and\n  [idempotency](https://alguna.com/docs/api-reference/v2/idempotency)\n- Support: support@alguna.io, with the `requestId` of the failed call\n\n## About this repo\n\nAlguna generates this SDK from the Alguna API spec in a private repository. Open issues\nhere. Alguna ports code changes to the generator, so a pull request here is not merged as is.\n","readmeFilename":"README.md","repository":{"url":"git+https://github.com/alguna-io/alguna-ts.git","type":"git"}}