{"_id":"@codeletco/sdk","_rev":"2-5d25d00857b14ada08e366bcd2e23361","name":"@codeletco/sdk","dist-tags":{"latest":"0.2.0"},"versions":{"0.1.0":{"name":"@codeletco/sdk","version":"0.1.0","keywords":["codelet","billing","usage","sdk"],"license":"MIT","_id":"@codeletco/sdk@0.1.0","maintainers":[{"name":"danrowden","email":"hello@danrowden.com"}],"homepage":"https://github.com/codelet-co/codelet#readme","bugs":{"url":"https://github.com/codelet-co/codelet/issues"},"dist":{"shasum":"1ec578086fd04aeff8a21ec11aed043517184bd1","tarball":"https://registry.npmjs.org/@codeletco/sdk/-/sdk-0.1.0.tgz","fileCount":470,"integrity":"sha512-P2sz3aAmqcqrjrvRKtODaUlAeEgeGePqsatcdeSwcVB8AuzCYkCV2AufJGiAnSUTewmCnBDda5/th11vQfb6ZQ==","signatures":[{"sig":"MEQCIBNkuCDl0eccnnNjjCWS3e6ZYHc2GQULB0YtcoHEU0J7AiAMpz+SgxDShzgE5+GTjq1wVzD+aJLl/yIP2pzBJtYtTQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":300282},"main":"./dist/index.js","types":"./dist/index.d.ts","engines":{"node":">=18"},"exports":{".":{"types":"./dist/index.d.ts","default":"./dist/index.js","require":"./dist/index.js"}},"gitHead":"5465316a2d318189752c41920f9aab22df91fcce","scripts":{"build":"tsc -p tsconfig.json","generate":"cd ../.. && ./sdks/scripts/generate.sh typescript","typecheck":"tsc -p tsconfig.json --noEmit","prepublishOnly":"npm run build"},"_npmUser":{"name":"danrowden","email":"hello@danrowden.com"},"repository":{"url":"git+https://github.com/codelet-co/codelet.git","type":"git","directory":"sdks/typescript"},"_npmVersion":"10.9.7","description":"Official TypeScript SDK for the Codelet public API","directories":{},"_nodeVersion":"22.22.2","_hasShrinkwrap":false,"devDependencies":{"typescript":"^5.8.3"},"_npmOperationalInternal":{"tmp":"tmp/sdk_0.1.0_1785865184488_0.08395660565923313","host":"s3://npm-registry-packages-npm-production"}},"0.2.0":{"name":"@codeletco/sdk","version":"0.2.0","description":"Official TypeScript SDK for the Codelet public API","main":"./dist/index.js","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","require":"./dist/index.js","default":"./dist/index.js"}},"scripts":{"build":"tsc -p tsconfig.json","typecheck":"tsc -p tsconfig.json --noEmit","generate":"cd ../.. && ./sdks/scripts/generate.sh typescript","prepublishOnly":"npm run build"},"engines":{"node":">=18"},"license":"MIT","keywords":["codelet","billing","usage","sdk","paddle","stripe"],"devDependencies":{"typescript":"^5.8.3"},"_id":"@codeletco/sdk@0.2.0","gitHead":"bf7f9daa4d96aae4d4358f27768557ec7a88cb35","_nodeVersion":"22.22.2","_npmVersion":"10.9.7","dist":{"integrity":"sha512-xpN1mJpyYY/TLTxH423EknaQqzCo464igoyFwSCAiHbdJh0Bk5koq2P19AFmNsEDXdXcYP+AUol1NNn9bpY1rA==","shasum":"5e00259c9b3295a6589e3c983355c10d5b9cc86d","tarball":"https://registry.npmjs.org/@codeletco/sdk/-/sdk-0.2.0.tgz","fileCount":478,"unpackedSize":324524,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIDU5Rm1XWDww9zVCKd+lXQZjmoh8NqjYkOL4amcIMTxtAiA1Bk4x1wIDgkWX3Db2NDOe3XkoK58RspMjrgKp1HQhxQ=="}]},"_npmUser":{"name":"danrowden","email":"hello@danrowden.com"},"directories":{},"maintainers":[{"name":"danrowden","email":"hello@danrowden.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/sdk_0.2.0_1785867662087_0.055066889384239204"},"_hasShrinkwrap":false}},"time":{"created":"2026-08-04T17:39:44.312Z","modified":"2026-08-04T18:21:02.505Z","0.1.0":"2026-08-04T17:39:44.616Z","0.2.0":"2026-08-04T18:21:02.263Z"},"license":"MIT","keywords":["codelet","billing","usage","sdk","paddle","stripe"],"description":"Official TypeScript SDK for the Codelet public API","maintainers":[{"name":"danrowden","email":"hello@danrowden.com"}],"readme":"# `@codeletco/sdk`\n\nOfficial TypeScript SDK for the [Codelet](https://codelet.co) public API.\n\n## Install\n\n```bash\nnpm install @codeletco/sdk\n```\n\n## Usage\n\n```ts\nimport { Codelet, CodeletError } from \"@codeletco/sdk\";\n\nconst codelet = new Codelet({\n  apiKey: process.env.CODELET_API_KEY!, // cl_live_… or cl_test_…\n});\n\n// Ingest (auto idempotency_key when omitted)\nawait codelet.ingest({\n  customer_id: \"org_42\",\n  metric: \"api_call\",\n  quantity: \"1\",\n});\n\nconst me = await codelet.account.getMe();\nconst customers = await codelet.customers.listCustomers();\nconst packs = await codelet.creditPacks.listCreditPacks({\n  metric: \"api_request\",\n  active: \"all\",\n});\nawait codelet.subscriptions.cancelSubscription(\"subs_…\", {\n  mode: \"at_period_end\",\n});\n```\n\nOptional client options: `baseUrl`, `retry`, `headers`, `fetchApi`.\n\n## Examples\n\nCreate metrics before plans, credit packs, or ingest. Unknown metric names return\n400.\n\n### Create a metric\n\n```ts\nconst metric = await codelet.metrics.createMetric({\n  name: \"api_request\",\n  display_name: \"API Request\",\n  aggregation: \"sum\",\n});\n```\n\n### Create a credit pack\n\n```ts\nconst pack = await codelet.creditPacks.createCreditPack({\n  metric: \"api_request\",\n  name: \"500 API requests\",\n  price_amount: \"25.00\",\n  currency: \"USD\",\n  quantity_granted: \"500\",\n});\n```\n\n### Create and publish a plan\n\n```ts\nconst plan = await codelet.plans.createPlan({\n  name: \"Pro\",\n  description: \"Usage-based Pro plan\",\n  version: {\n    currency: \"USD\",\n    billing_period: \"monthly\",\n    billing_mode: \"postpaid\",\n    fixed_fees: [\n      {\n        fee_type: \"period_charge\",\n        name: \"Platform fee\",\n        amount: \"29.00\",\n      },\n    ],\n    usage_fees: [\n      {\n        pricing_model: \"unit\",\n        billing_timing: \"in_arrears\",\n        included_quantity: \"1000\",\n        unit_price: \"0.002\",\n        metric: \"api_request\",\n      },\n    ],\n  },\n});\n\n// Drafts are not checkout-ready until published\nawait codelet.plans.publishPlan(plan.id);\n```\n\n### Create checkout\n\nCredit pack (one-time purchase):\n\n```ts\nconst packCheckout = await codelet.checkout.createCheckout({\n  customer_id: \"org_42\",\n  pack_id: \"pack_…\",\n  success_url: \"https://yourapp.com/billing/success\",\n  cancel_url: \"https://yourapp.com/billing/cancel\",\n  idempotency_key: \"purchase:order-123\",\n});\n// Redirect the browser to packCheckout.checkout_url\n```\n\nSubscription (plan):\n\n```ts\nconst planCheckout = await codelet.checkout.createCheckout({\n  customer_id: \"org_42\",\n  plan_id: \"plan_…\",\n  success_url: \"https://yourapp.com/welcome\",\n});\n// Redirect the browser to planCheckout.checkout_url\n```\n\nPass either `customer_id` or `customer_email`, not both. Exactly one of\n`pack_id` or `plan_id` is required.\n\n## API reference\n\nAll generated methods are available on the `Codelet` instance (for example\n`codelet.customers.listCustomers`). Prefer `codelet.ingest(…)` over\n`codelet.usage.ingestEvent(…)` when recording usage; the helper fills\n`idempotency_key` when omitted.\n\n### `codelet.ingest(body)`\n\nIngest a usage event. Same as `usage.ingestEvent`, but generates\n`idempotency_key` when omitted.\n\n| Method | Description |\n| --- | --- |\n| `ingest(body)` | `POST /v1/ingest` |\n\n### Account (`codelet.account`)\n\n| Method | Description |\n| --- | --- |\n| `getMe()` | API key context (project + environment) |\n\n### Checkout (`codelet.checkout`)\n\n| Method | Description |\n| --- | --- |\n| `createCheckout(requestBody)` | Create a credit pack or subscription checkout |\n\n### Credit packs (`codelet.creditPacks`)\n\n| Method | Description |\n| --- | --- |\n| `listCreditPacks({ metric?, active?, pageSize?, cursor? })` | List packs (default: active only) |\n| `createCreditPack(requestBody)` | Create a pack |\n| `getCreditPack(packId)` | Get a pack by ID |\n| `updateCreditPack(packId, requestBody)` | Update name, description, and/or active |\n\n### Customers (`codelet.customers`)\n\n| Method | Description |\n| --- | --- |\n| `listCustomers({ pageSize?, cursor? })` | List customers |\n| `createCustomer(requestBody)` | Create a customer |\n| `getCustomer(customerId)` | Get a customer |\n| `updateCustomer(customerId, requestBody)` | Update editable fields |\n| `getCustomerBalance(customerId, { metric? })` | Credit balances (all metrics, or one) |\n\n### Metrics (`codelet.metrics`)\n\n| Method | Description |\n| --- | --- |\n| `listMetrics({ pageSize?, cursor? })` | List metrics |\n| `createMetric(requestBody)` | Create a metric |\n| `getMetric(name)` | Get a metric by name |\n| `updateMetric(name, requestBody)` | Partial update (today: `display_name`) |\n\n### Plans (`codelet.plans`)\n\n| Method | Description |\n| --- | --- |\n| `listPlans({ status?, pageSize?, cursor? })` | List plans (default: published) |\n| `createPlan(requestBody)` | Create a draft plan |\n| `getPlan(planId, { includePricingDetails? })` | Get a plan |\n| `publishPlan(planId)` | Publish the draft version |\n\n### Subscriptions (`codelet.subscriptions`)\n\n| Method | Description |\n| --- | --- |\n| `listSubscriptions({ customer?, status?, pageSize?, cursor? })` | List subscriptions |\n| `getSubscription(subscriptionId)` | Get a subscription |\n| `cancelSubscription(subscriptionId, requestBody)` | Cancel (`at_period_end` or `immediate`) |\n| `resumeSubscription(subscriptionId)` | Clear a scheduled cancellation |\n\n### Usage (`codelet.usage`)\n\n| Method | Description |\n| --- | --- |\n| `ingestEvent(requestBody)` | Ingest a usage event (no auto idempotency key) |\n\nRequest and response shapes match the [OpenAPI spec](https://codelet.co/openapi.json).\nSee also [codelet.co/SKILL.md](https://codelet.co/SKILL.md) for merchant integration guidance.\n\n## Errors\n\n```ts\nimport { CodeletError, CodeletRateLimitError } from \"@codeletco/sdk\";\n\ntry {\n  await codelet.ingest({ /* … */ });\n} catch (error) {\n  if (error instanceof CodeletRateLimitError) {\n    // 429\n  } else if (error instanceof CodeletError) {\n    // other API errors (status + body)\n  }\n}\n```\n\nGenerated services throw `ApiError` from the OpenAPI client. The top-level\n`ingest` helper maps those to `CodeletError` / `CodeletRateLimitError`.\n\n## Development\n\n```bash\n# from repo root\nmake sdk-generate\ncd sdks/typescript && npm install && npm run build\n```\n","readmeFilename":"README.md"}