mbase-sdk 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +497 -0
- package/dist/index.cjs +714 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +717 -0
- package/dist/index.d.ts +717 -0
- package/dist/index.js +698 -0
- package/dist/index.js.map +1 -0
- package/package.json +76 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts","../src/client.ts","../src/resources/customer-allowances.ts","../src/resources/customer-plan.ts","../src/resources/customers.ts","../src/resources/meters.ts","../src/resources/plans.ts","../src/index.ts"],"names":[],"mappings":";AAGO,IAAM,cAAA,GAAN,cAA6B,KAAA,CAAM;AAAA,EACxC,WAAA,CAAY,SAAiB,OAAA,EAA+B;AAC1D,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA;AACtB,IAAA,IAAA,CAAK,OAAO,GAAA,CAAA,MAAA,CAAW,IAAA;AAAA,EACzB;AACF;AAEO,IAAM,QAAA,GAAN,cAAuB,cAAA,CAAe;AAAA,EAClC,MAAA;AAAA,EACA,IAAA;AAAA;AAAA,EAEA,SAAA;AAAA,EACA,IAAA;AAAA,EAET,YAAY,IAAA,EAMT;AACD,IAAA,KAAA,CAAM,KAAK,OAAO,CAAA;AAClB,IAAA,IAAA,CAAK,SAAS,IAAA,CAAK,MAAA;AACnB,IAAA,IAAA,CAAK,OAAO,IAAA,CAAK,IAAA;AACjB,IAAA,IAAA,CAAK,YAAY,IAAA,CAAK,SAAA;AACtB,IAAA,IAAA,CAAK,OAAO,IAAA,CAAK,IAAA;AAAA,EACnB;AACF;AAEO,IAAM,mBAAA,GAAN,cAAkC,QAAA,CAAS;AAAC;AAC5C,IAAM,qBAAA,GAAN,cAAoC,QAAA,CAAS;AAAC;AAC9C,IAAM,aAAA,GAAN,cAA4B,QAAA,CAAS;AAAC;AACtC,IAAM,aAAA,GAAN,cAA4B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A,EAAQ,MAAA;AAAA,MACR,IAAA,EAAM,iBAAA;AAAA;AAAA;AAAA,MAGN,IAAA,EAAM;AAAA,QACJ,GAAG,MAAA;AAAA,QACH,eAAA,EAAiB,MAAA,CAAO,eAAA,IAAmB,cAAA;AAAe,OAC5D;AAAA,MACA,UAAA,EAAY;AAAA,KACb,CAAA;AAAA,EACH;AAAA;AAAA,EAGA,OAAO,OAAA,EAA2C;AAChD,IAAA,OAAO,IAAA,CAAK,QAAQ,OAAA,CAAQ;AAAA,MAC1B,GAAG,OAAA;AAAA,MACH,MAAA,EAAQ,KAAA;AAAA,MACR,IAAA,EAAM;AAAA,KACP,CAAA;AAAA,EACH;AACF;AAoBA,SAAS,cAAA,GAAyB;AAGhC,EAAA,MAAM,YAAY,UAAA,CAAW,MAAA;AAO7B,EAAA,IAAI,OAAO,SAAA,EAAW,UAAA,KAAe,UAAA,EAAY;AAC/C,IAAA,OAAO,UAAU,UAAA,EAAW;AAAA,EAC9B;AAGA,EAAA,IAAI,OAAO,SAAA,EAAW,eAAA,KAAoB,UAAA,EAAY;AACpD,IAAA,MAAM,QAAQ,SAAA,CAAU,eAAA,CAAgB,IAAI,UAAA,CAAW,EAAE,CAAC,CAAA;AAC1D,IAAA,OAAO,KAAA,CAAM,IAAA,CAAK,KAAA,EAAO,CAAC,MAAM,CAAA,CAAE,QAAA,CAAS,EAAE,CAAA,CAAE,SAAS,CAAA,EAAG,GAAG,CAAC,CAAA,CAAE,KAAK,EAAE,CAAA;AAAA,EAC1E;AAEA,EAAA,MAAM,IAAI,cAAA;AAAA,IACR;AAAA,GAEF;AACF","file":"index.js","sourcesContent":["// Every failure is a MeterbaseError, so a caller can catch one type and still\n// switch on the specific one. `code` is stable; `message` may change.\n\nexport class MeterbaseError extends Error {\n constructor(message: string, options?: { cause?: unknown }) {\n super(message, options)\n this.name = new.target.name\n }\n}\n\nexport class APIError extends MeterbaseError {\n readonly status: number\n readonly code: string\n /** From `X-Request-Id`, when the engine sends one. */\n readonly requestId: string | undefined\n readonly body: unknown\n\n constructor(args: {\n status: number\n code: string\n message: string\n requestId?: string | undefined\n body?: unknown\n }) {\n super(args.message)\n this.status = args.status\n this.code = args.code\n this.requestId = args.requestId\n this.body = args.body\n }\n}\n\nexport class AuthenticationError extends APIError {}\nexport class PermissionDeniedError extends APIError {}\nexport class NotFoundError extends APIError {}\nexport class ConflictError extends APIError {}\n\n/**\n * `409 idempotency_conflict`: the key is in use for a different meter or\n * quantity. A caller told their key is taken asks what it recorded next, so\n * the engine names the original and this carries it.\n *\n * A `ConflictError` still, so `catch (e) { if (e instanceof ConflictError) }`\n * keeps working.\n */\nexport class IdempotencyConflictError extends ConflictError {\n /** The event that key already recorded. Undefined only if the engine sent a\n * body this could not be read out of. */\n readonly existingEventId: string | undefined\n\n constructor(args: ConstructorParameters<typeof APIError>[0]) {\n super(args)\n this.existingEventId = existingEventId(args.body)\n }\n}\n\nexport class InvalidRequestError extends APIError {}\n\n/**\n * `422 cycle_change_requires_reset`: the two plans measure different cycles,\n * so a `next_cycle` change has no shared boundary to wait for and a `prorate`\n * no shared period to weight. The move is `customers.plan.restart`, which\n * closes the current period and opens a fresh one on the new cycle — or\n * `changeNow` with the default `reconciliation: \"none\"` to keep the period\n * that is running. The engine's `message` says as much.\n *\n * An `InvalidRequestError` still, so an existing `catch` keeps working.\n */\nexport class CycleChangeRequiresResetError extends InvalidRequestError {}\nexport class RateLimitError extends APIError {\n /** Seconds to wait, from `Retry-After`, when the engine sends one. */\n readonly retryAfter: number | undefined\n\n constructor(\n args: ConstructorParameters<typeof APIError>[0] & {\n retryAfter?: number | undefined\n },\n ) {\n super(args)\n this.retryAfter = args.retryAfter\n }\n}\nexport class ServerError extends APIError {}\n\n// The request never produced an answer: DNS, TLS, a reset, an abort.\nexport class ConnectionError extends MeterbaseError {}\nexport class TimeoutError extends ConnectionError {}\n\nexport function errorFromResponse(args: {\n status: number\n code: string\n message: string\n requestId?: string | undefined\n retryAfter?: number | undefined\n body?: unknown\n}): APIError {\n switch (args.status) {\n case 401:\n return new AuthenticationError(args)\n case 403:\n return new PermissionDeniedError(args)\n case 404:\n return new NotFoundError(args)\n case 409:\n return args.code === \"idempotency_conflict\"\n ? new IdempotencyConflictError(args)\n : new ConflictError(args)\n case 422:\n return args.code === \"cycle_change_requires_reset\"\n ? new CycleChangeRequiresResetError(args)\n : new InvalidRequestError(args)\n case 429:\n return new RateLimitError(args)\n default:\n return args.status >= 500 ? new ServerError(args) : new APIError(args)\n }\n}\n\n/** The engine carries it beside `code` and `message`, inside `error`. */\nfunction existingEventId(body: unknown): string | undefined {\n if (typeof body !== \"object\" || body === null) return undefined\n\n const error = (body as { error?: unknown }).error\n if (typeof error !== \"object\" || error === null) return undefined\n\n const id = (error as { existing_event_id?: unknown }).existing_event_id\n return typeof id === \"string\" ? id : undefined\n}\n","// Everything goes through `request`, so authentication, timeouts, retries and\n// error mapping are defined once.\n\nimport {\n ConnectionError,\n errorFromResponse,\n MeterbaseError,\n TimeoutError,\n} from \"./errors.js\"\n\nexport type MeterbaseOptions = {\n /** A secret key. It names its own workspace. */\n apiKey: string\n /** Defaults to the hosted engine. */\n baseUrl?: string\n /** Per attempt, not per call. */\n timeout?: number\n maxRetries?: number\n fetch?: typeof globalThis.fetch\n}\n\nexport type RequestOptions = {\n signal?: AbortSignal\n timeout?: number\n maxRetries?: number\n}\n\ntype HttpMethod = \"GET\" | \"POST\" | \"PATCH\" | \"DELETE\"\n\ntype Request = RequestOptions & {\n method: HttpMethod\n path: string\n query?: Record<string, string | number | boolean | undefined>\n body?: unknown\n /**\n * Replay this call even though its method is not safe. Only a route that\n * carries an idempotency key may set it, and the key has to be fixed before\n * `request` is called — the loop re-sends one body, so a key generated\n * per attempt would count the same usage twice.\n */\n idempotent?: boolean\n}\n\nconst DEFAULT_BASE_URL = \"https://api.meterbase.tech\"\nconst DEFAULT_TIMEOUT = 10_000\nconst DEFAULT_MAX_RETRIES = 2\nconst MAX_BACKOFF = 8_000\n\nexport class Client {\n readonly #apiKey: string\n readonly #baseUrl: string\n readonly #timeout: number\n readonly #maxRetries: number\n readonly #fetch: typeof globalThis.fetch\n\n constructor(options: MeterbaseOptions) {\n if (!options.apiKey) {\n throw new MeterbaseError(\n \"An API key is required: new Meterbase({ apiKey: 'mb_sk_live_…' }).\",\n )\n }\n\n this.#apiKey = options.apiKey\n this.#baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\\/+$/, \"\")\n this.#timeout = options.timeout ?? DEFAULT_TIMEOUT\n this.#maxRetries = options.maxRetries ?? DEFAULT_MAX_RETRIES\n this.#fetch = options.fetch ?? globalThis.fetch\n\n if (typeof this.#fetch !== \"function\") {\n throw new MeterbaseError(\n \"No fetch implementation: pass one as `fetch`, or run on Node 18+.\",\n )\n }\n }\n\n async request<T>(req: Request): Promise<T> {\n const maxRetries = req.maxRetries ?? this.#maxRetries\n // Safe methods, plus the routes that carry an idempotency key and say so.\n // Any other POST or PATCH could create a second row on a replay.\n const retryable =\n req.method === \"GET\" || req.method === \"DELETE\" || req.idempotent === true\n\n let lastError: unknown\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n if (attempt > 0) await sleep(backoff(attempt, lastError))\n\n try {\n const response = await this.#send(req)\n\n if (response.ok) return (await parseBody(response)) as T\n\n const error = await errorFrom(response)\n if (retryable && attempt < maxRetries && shouldRetry(response.status)) {\n lastError = error\n continue\n }\n throw error\n } catch (cause) {\n if (\n cause instanceof MeterbaseError &&\n !(cause instanceof ConnectionError)\n ) {\n throw cause\n }\n // A connection failure proves nothing about whether the server acted,\n // so it is replayed under the same idempotency rule.\n if (!retryable || attempt >= maxRetries) throw cause\n lastError = cause\n }\n }\n\n /* c8 ignore next 2 -- the loop always returns or throws */\n throw lastError\n }\n\n async #send(req: Request): Promise<Response> {\n const url = new URL(this.#baseUrl + req.path)\n for (const [key, value] of Object.entries(req.query ?? {})) {\n if (value !== undefined) url.searchParams.set(key, String(value))\n }\n\n const headers: Record<string, string> = {\n authorization: `Bearer ${this.#apiKey}`,\n accept: \"application/json\",\n }\n if (req.body !== undefined) headers[\"content-type\"] = \"application/json\"\n\n const timeout = req.timeout ?? this.#timeout\n const controller = new AbortController()\n const onAbort = () => controller.abort(req.signal?.reason)\n req.signal?.addEventListener(\"abort\", onAbort, { once: true })\n\n let timedOut = false\n const timer = setTimeout(() => {\n timedOut = true\n controller.abort()\n }, timeout)\n\n try {\n return await this.#fetch(url, {\n method: req.method,\n headers,\n body: req.body === undefined ? undefined : JSON.stringify(req.body),\n signal: controller.signal,\n })\n } catch (cause) {\n if (timedOut) {\n throw new TimeoutError(`Request timed out after ${timeout}ms.`, {\n cause,\n })\n }\n // A caller's own abort is theirs to handle, not ours to reclassify.\n if (req.signal?.aborted) throw cause\n throw new ConnectionError(`Could not reach ${url.origin}.`, { cause })\n } finally {\n clearTimeout(timer)\n req.signal?.removeEventListener(\"abort\", onAbort)\n }\n }\n}\n\nfunction shouldRetry(status: number): boolean {\n return status === 408 || status === 429 || status >= 500\n}\n\n/** Exponential backoff with full jitter, unless the engine named a delay. */\nfunction backoff(attempt: number, lastError: unknown): number {\n const retryAfter =\n lastError && typeof lastError === \"object\" && \"retryAfter\" in lastError\n ? (lastError as { retryAfter?: number }).retryAfter\n : undefined\n if (retryAfter !== undefined) return Math.min(retryAfter * 1000, MAX_BACKOFF)\n\n const ceiling = Math.min(500 * 2 ** (attempt - 1), MAX_BACKOFF)\n return Math.random() * ceiling\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms))\n}\n\nasync function parseBody(response: Response): Promise<unknown> {\n if (response.status === 204) return undefined\n\n const text = await response.text()\n if (text === \"\") return undefined\n\n try {\n return JSON.parse(text)\n } catch (cause) {\n throw new MeterbaseError(\"The engine returned a body that is not JSON.\", {\n cause,\n })\n }\n}\n\nasync function errorFrom(response: Response) {\n const body = await response.text()\n const parsed = parseErrorBody(body)\n const retryAfterHeader = response.headers.get(\"retry-after\")\n const retryAfter = retryAfterHeader ? Number(retryAfterHeader) : undefined\n\n return errorFromResponse({\n status: response.status,\n code: parsed?.code ?? `http_${response.status}`,\n message: parsed?.message ?? `The engine responded ${response.status}.`,\n requestId: response.headers.get(\"x-request-id\") ?? undefined,\n retryAfter:\n retryAfter !== undefined && Number.isFinite(retryAfter)\n ? retryAfter\n : undefined,\n body: body === \"\" ? undefined : (safeParse(body) ?? body),\n })\n}\n\nfunction parseErrorBody(body: string) {\n const parsed = safeParse(body) as\n { error?: { code?: string; message?: string } } | undefined\n const error = parsed?.error\n if (!error?.code || !error.message) return undefined\n\n return { code: error.code, message: error.message }\n}\n\nfunction safeParse(body: string): unknown {\n try {\n return JSON.parse(body)\n } catch {\n return undefined\n }\n}\n","import type { Client, RequestOptions } from \"../client.js\"\nimport type {\n Allowance,\n AllowanceGrantParams,\n AllowanceListParams,\n List,\n} from \"../types.js\"\n\n/**\n * Capacity handed to one customer on top of their plan. A grant with\n * `source: \"plan\"` is the engine's own, minted when a plan is assigned, and\n * cannot be created here.\n */\nexport class CustomerAllowances {\n readonly #client: Client\n\n constructor(client: Client) {\n this.#client = client\n }\n\n grant(\n customerId: string,\n params: AllowanceGrantParams,\n options?: RequestOptions,\n ): Promise<Allowance> {\n return this.#client.request({\n ...options,\n method: \"POST\",\n path: `/v1/customers/${encodeURIComponent(customerId)}/allowances`,\n body: params,\n })\n }\n\n /** Open grants only, unless `include_closed`. */\n list(\n customerId: string,\n params: AllowanceListParams = {},\n options?: RequestOptions,\n ): Promise<List<Allowance>> {\n return this.#client.request({\n ...options,\n method: \"GET\",\n path: `/v1/customers/${encodeURIComponent(customerId)}/allowances`,\n query: {\n meter_id: params.meter_id,\n include_closed: params.include_closed,\n },\n })\n }\n\n retrieve(\n customerId: string,\n allowanceId: string,\n options?: RequestOptions,\n ): Promise<Allowance> {\n return this.#client.request({\n ...options,\n method: \"GET\",\n path: `/v1/customers/${encodeURIComponent(customerId)}/allowances/${encodeURIComponent(allowanceId)}`,\n })\n }\n\n /** Withdraws what is left without erasing what was consumed. Idempotent. */\n revoke(\n customerId: string,\n allowanceId: string,\n options?: RequestOptions,\n ): Promise<Allowance> {\n return this.#client.request({\n ...options,\n method: \"DELETE\",\n path: `/v1/customers/${encodeURIComponent(customerId)}/allowances/${encodeURIComponent(allowanceId)}`,\n })\n }\n}\n","import type { Client, RequestOptions } from \"../client.js\"\nimport type {\n AssignPlanParams,\n Assignment,\n List,\n PlanChangeNowParams,\n PlanChangeParams,\n PlanMoveParams,\n} from \"../types.js\"\nimport { NotFoundError } from \"../errors.js\"\n\n/**\n * Which plan a customer holds. The history is append-only: there is no patch\n * and no delete, and moving a customer to a different plan is the same call as\n * their first.\n *\n * `assign` is that call, mirroring the wire. The rest name the four moves a\n * caller actually makes — later, now, now-and-start-over, and never mind — so\n * that picking one does not mean knowing what `effective` and `reconciliation`\n * do to a half-used period.\n */\nexport class CustomerPlan {\n readonly #client: Client\n\n constructor(client: Client) {\n this.#client = client\n }\n\n /**\n * Put a customer on a plan. This is the wire call, and the only one that\n * takes `cycle_anchor` — a first assignment's one chance to put their\n * periods on a date they already have.\n *\n * Returns the instruction as recorded, which is not always as asked: a first\n * plan is recorded `immediate` whatever `effective` said.\n */\n assign(\n customerId: string,\n params: AssignPlanParams,\n options?: RequestOptions,\n ): Promise<Assignment> {\n return this.#client.request({\n ...options,\n method: \"POST\",\n path: `/v1/customers/${encodeURIComponent(customerId)}/plan`,\n body: params,\n })\n }\n\n /**\n * Move a customer to a different plan, with both knobs in the open.\n * `effective` defaults to `next_cycle`; `reconciliation` applies only to an\n * `immediate` change and defaults to `none`.\n *\n * Reach for `changeAtNextCycle`, `changeNow` or `restart` when one of them\n * says what you mean — this is the form to fall back to when the two are\n * chosen at runtime.\n */\n change(\n customerId: string,\n params: PlanChangeParams,\n options?: RequestOptions,\n ): Promise<Assignment> {\n const { plan, ...rest } = params\n\n return this.assign(customerId, { plan_id: plan, ...rest }, options)\n }\n\n /**\n * Schedule the move for the end of the period they are in: they keep the\n * plan they are paying for until it runs out, and the new one starts at\n * their next boundary. Nothing is pro-rated, because nothing is split.\n *\n * Two plans on different cycles share no boundary, and this answers\n * `CycleChangeRequiresResetError` — use `restart` for that move.\n */\n changeAtNextCycle(\n customerId: string,\n params: PlanMoveParams,\n options?: RequestOptions,\n ): Promise<Assignment> {\n return this.change(\n customerId,\n { plan: params.plan, effective: \"next_cycle\" },\n options,\n )\n }\n\n /**\n * Move them now, inside the period already running. Their renewal day does\n * not move; what changes is this period's cap, and `reconciliation` says\n * how:\n *\n * - `none` (the default) — the new plan's amount governs the whole period.\n * Usage already spent still counts, so a downgrade can deny until the\n * period ends.\n * - `prorate` — each plan's amount weighted by the fraction of the period it\n * was held for. Refused between plans on different cycles, which share no\n * period to weight.\n *\n * To have the period itself start over instead, use `restart`.\n */\n changeNow(\n customerId: string,\n params: PlanChangeNowParams,\n options?: RequestOptions,\n ): Promise<Assignment> {\n return this.change(\n customerId,\n { ...params, effective: \"immediate\" },\n options,\n )\n }\n\n /**\n * Move them now and start a fresh period today: the period they were in\n * closes where the change lands, keeping the usage it had, and the new\n * plan's full amount opens immediately.\n *\n * This moves the customer's anchor, so their renewal day becomes today. It\n * is the move for a customer starting over — a new contract, a re-signup —\n * and the only one that can take a customer between plans whose cycles\n * differ.\n */\n restart(\n customerId: string,\n params: PlanMoveParams,\n options?: RequestOptions,\n ): Promise<Assignment> {\n return this.change(\n customerId,\n { plan: params.plan, effective: \"immediate\", reconciliation: \"reset\" },\n options,\n )\n }\n\n /**\n * Call off a change that has not landed yet, leaving the customer on the\n * plan they hold. Naming the plan already held is what supersedes a pending\n * instruction, so this reads the plan in force and names it back.\n *\n * Returns the assignment still in force, or `null` for a customer holding no\n * plan — who can have nothing pending, since a first assignment always lands\n * at once.\n */\n async cancelScheduledChange(\n customerId: string,\n options?: RequestOptions,\n ): Promise<Assignment | null> {\n const current = await this.retrieve(customerId, options)\n if (current === null) return null\n\n return this.assign(customerId, { plan_id: current.plan_id }, options)\n }\n\n /**\n * The plan in force now, which is not always the newest instruction: a\n * change dated ahead does not govern yet.\n *\n * `null` when the customer holds no plan. That is a default deny rather than\n * a failure — they are entitled to nothing — so it is an answer here and not\n * a thrown `NotFoundError`. A customer who does not exist at all still\n * throws one.\n */\n async retrieve(\n customerId: string,\n options?: RequestOptions,\n ): Promise<Assignment | null> {\n try {\n return await this.#client.request<Assignment>({\n ...options,\n method: \"GET\",\n path: `/v1/customers/${encodeURIComponent(customerId)}/plan`,\n })\n } catch (error) {\n if (error instanceof NotFoundError && error.code === \"no_plan_assigned\") {\n return null\n }\n throw error\n }\n }\n\n /**\n * The change waiting to land, or `null` when none is. At most one is ever\n * live: a newer instruction supersedes the one before it.\n *\n * Read against the assignment in force rather than against the local clock,\n * so a change landing seconds from now is not reported as already governing.\n */\n async pending(\n customerId: string,\n options?: RequestOptions,\n ): Promise<Assignment | null> {\n const [current, { data }] = await Promise.all([\n this.retrieve(customerId, options),\n this.history(customerId, options),\n ])\n\n const inForce =\n current === null ? -Infinity : Date.parse(current.effective_at)\n\n return (\n data.find(\n (a) => a.superseded_at === null && Date.parse(a.effective_at) > inForce,\n ) ?? null\n )\n }\n\n /** Every instruction, superseded ones included: it is the whole trail. */\n history(\n customerId: string,\n options?: RequestOptions,\n ): Promise<List<Assignment>> {\n return this.#client.request({\n ...options,\n method: \"GET\",\n path: `/v1/customers/${encodeURIComponent(customerId)}/plan/history`,\n })\n }\n}\n","import type { Client, RequestOptions } from \"../client.js\"\nimport type {\n Customer,\n CustomerCreateParams,\n CustomerListParams,\n CustomerUpdateParams,\n CustomerWithPlan,\n List,\n} from \"../types.js\"\nimport { CustomerAllowances } from \"./customer-allowances.js\"\nimport { CustomerPlan } from \"./customer-plan.js\"\n\nexport class Customers {\n /** The plan they hold, and the trail of instructions that got them there. */\n readonly plan: CustomerPlan\n /** Grants, which sit on top of whatever the plan gives. */\n readonly allowances: CustomerAllowances\n\n readonly #client: Client\n\n constructor(client: Client) {\n this.#client = client\n this.plan = new CustomerPlan(client)\n this.allowances = new CustomerAllowances(client)\n }\n\n create(\n params: CustomerCreateParams,\n options?: RequestOptions,\n ): Promise<Customer> {\n return this.#client.request({\n ...options,\n method: \"POST\",\n path: \"/v1/customers\",\n body: params,\n })\n }\n\n /** Lean: a listing does not embed the plan. Read one customer for that. */\n list(\n params: CustomerListParams = {},\n options?: RequestOptions,\n ): Promise<List<Customer>> {\n return this.#client.request({\n ...options,\n method: \"GET\",\n path: \"/v1/customers\",\n query: { include_deleted: params.include_deleted },\n })\n }\n\n /**\n * One customer, with the plan they hold. `plan` is the one in force now and\n * `pending_plan` the change waiting to land, each `null` when there is\n * none — so knowing what a customer is on costs no second request.\n */\n retrieve(id: string, options?: RequestOptions): Promise<CustomerWithPlan> {\n return this.#client.request({\n ...options,\n method: \"GET\",\n path: `/v1/customers/${encodeURIComponent(id)}`,\n })\n }\n\n /**\n * Resolves the tenant's own identifier, or null, embedding the plan the way\n * `retrieve` does. The engine answers this as a filtered list, so a miss is\n * an empty collection rather than a 404.\n */\n async retrieveByExternalId(\n externalId: string,\n options?: RequestOptions,\n ): Promise<CustomerWithPlan | null> {\n const { data } = await this.#client.request<List<CustomerWithPlan>>({\n ...options,\n method: \"GET\",\n path: \"/v1/customers\",\n query: { external_id: externalId },\n })\n\n return data[0] ?? null\n }\n\n update(\n id: string,\n params: CustomerUpdateParams,\n options?: RequestOptions,\n ): Promise<Customer> {\n return this.#client.request({\n ...options,\n method: \"PATCH\",\n path: `/v1/customers/${encodeURIComponent(id)}`,\n body: params,\n })\n }\n\n /** Soft delete: usage and assignments keep referencing the customer. */\n delete(id: string, options?: RequestOptions): Promise<Customer> {\n return this.#client.request({\n ...options,\n method: \"DELETE\",\n path: `/v1/customers/${encodeURIComponent(id)}`,\n })\n }\n}\n","import type { Client, RequestOptions } from \"../client.js\"\nimport type {\n List,\n Meter,\n MeterCreateParams,\n MeterListParams,\n MeterUpdateParams,\n} from \"../types.js\"\n\nexport class Meters {\n readonly #client: Client\n\n constructor(client: Client) {\n this.#client = client\n }\n\n create(params: MeterCreateParams, options?: RequestOptions): Promise<Meter> {\n return this.#client.request({\n ...options,\n method: \"POST\",\n path: \"/v1/meters\",\n body: params,\n })\n }\n\n list(\n params: MeterListParams = {},\n options?: RequestOptions,\n ): Promise<List<Meter>> {\n return this.#client.request({\n ...options,\n method: \"GET\",\n path: \"/v1/meters\",\n query: { include_archived: params.include_archived },\n })\n }\n\n retrieve(id: string, options?: RequestOptions): Promise<Meter> {\n return this.#client.request({\n ...options,\n method: \"GET\",\n path: `/v1/meters/${encodeURIComponent(id)}`,\n })\n }\n\n update(\n id: string,\n params: MeterUpdateParams,\n options?: RequestOptions,\n ): Promise<Meter> {\n return this.#client.request({\n ...options,\n method: \"PATCH\",\n path: `/v1/meters/${encodeURIComponent(id)}`,\n body: params,\n })\n }\n\n /** Soft delete: plans and usage keep referencing the meter. Idempotent. */\n archive(id: string, options?: RequestOptions): Promise<Meter> {\n return this.#client.request({\n ...options,\n method: \"DELETE\",\n path: `/v1/meters/${encodeURIComponent(id)}`,\n })\n }\n}\n","import type { Client, RequestOptions } from \"../client.js\"\nimport type {\n List,\n Plan,\n PlanAllowance,\n PlanAllowanceListParams,\n PlanAllowanceSetParams,\n PlanCreateParams,\n PlanListParams,\n PlanUpdateParams,\n} from \"../types.js\"\n\n/**\n * A plan's entitlement, versioned. There is no update and no delete: an edit\n * appends the next version, so which amount applied when stays derivable.\n */\nexport class PlanAllowances {\n readonly #client: Client\n\n constructor(client: Client) {\n this.#client = client\n }\n\n set(\n planId: string,\n params: PlanAllowanceSetParams,\n options?: RequestOptions,\n ): Promise<PlanAllowance> {\n return this.#client.request({\n ...options,\n method: \"POST\",\n path: `/v1/plans/${encodeURIComponent(planId)}/allowances`,\n body: params,\n })\n }\n\n /** Every version of every meter, newest first — history, not just current. */\n list(\n planId: string,\n params: PlanAllowanceListParams = {},\n options?: RequestOptions,\n ): Promise<List<PlanAllowance>> {\n return this.#client.request({\n ...options,\n method: \"GET\",\n path: `/v1/plans/${encodeURIComponent(planId)}/allowances`,\n query: { meter_id: params.meter_id },\n })\n }\n}\n\nexport class Plans {\n readonly allowances: PlanAllowances\n\n readonly #client: Client\n\n constructor(client: Client) {\n this.#client = client\n this.allowances = new PlanAllowances(client)\n }\n\n /** A new plan grants nothing; attach entitlement with `allowances.set`. */\n create(params: PlanCreateParams, options?: RequestOptions): Promise<Plan> {\n return this.#client.request({\n ...options,\n method: \"POST\",\n path: \"/v1/plans\",\n body: params,\n })\n }\n\n list(\n params: PlanListParams = {},\n options?: RequestOptions,\n ): Promise<List<Plan>> {\n return this.#client.request({\n ...options,\n method: \"GET\",\n path: \"/v1/plans\",\n query: { include_archived: params.include_archived },\n })\n }\n\n retrieve(id: string, options?: RequestOptions): Promise<Plan> {\n return this.#client.request({\n ...options,\n method: \"GET\",\n path: `/v1/plans/${encodeURIComponent(id)}`,\n })\n }\n\n update(\n id: string,\n params: PlanUpdateParams,\n options?: RequestOptions,\n ): Promise<Plan> {\n return this.#client.request({\n ...options,\n method: \"PATCH\",\n path: `/v1/plans/${encodeURIComponent(id)}`,\n body: params,\n })\n }\n\n /**\n * Stops new assignments without withdrawing capacity from anyone already on\n * the plan, which is why an archived plan still resolves by id. Idempotent.\n */\n archive(id: string, options?: RequestOptions): Promise<Plan> {\n return this.#client.request({\n ...options,\n method: \"DELETE\",\n path: `/v1/plans/${encodeURIComponent(id)}`,\n })\n }\n}\n","import { Client, type MeterbaseOptions, type RequestOptions } from \"./client.js\"\nimport { MeterbaseError } from \"./errors.js\"\nimport type { CustomerAllowances } from \"./resources/customer-allowances.js\"\nimport type { CustomerPlan } from \"./resources/customer-plan.js\"\nimport { Customers } from \"./resources/customers.js\"\nimport { Meters } from \"./resources/meters.js\"\nimport { Plans, type PlanAllowances } from \"./resources/plans.js\"\nimport type {\n CheckParams,\n CheckResult,\n TrackParams,\n TrackResult,\n WhoAmI,\n} from \"./types.js\"\n\nexport class Meterbase {\n readonly customers: Customers\n readonly meters: Meters\n readonly plans: Plans\n\n readonly #client: Client\n\n constructor(options: MeterbaseOptions) {\n this.#client = new Client(options)\n this.customers = new Customers(this.#client)\n this.meters = new Meters(this.#client)\n this.plans = new Plans(this.#client)\n }\n\n /**\n * Asks whether a customer may consume `quantity` of a meter, named by the\n * tenant's own external id and the meter's key. Absence of entitlement is\n * not permission: a customer with no plan and no grant is denied.\n *\n * This is the gate, and the only call that ever refuses. Run it before the\n * work; record the work with `track` afterwards.\n */\n check(params: CheckParams, options?: RequestOptions): Promise<CheckResult> {\n return this.#client.request({\n ...options,\n method: \"POST\",\n path: \"/v1/check\",\n body: params,\n })\n }\n\n /**\n * Records usage that already happened — the tokens were spent, the image\n * was generated — so it never refuses on capacity. A quantity beyond the\n * customer's capacity is recorded, drives `available` to 0, and the next\n * `check` says no. The answer is a receipt, not a verdict.\n *\n * `idempotency_key` is generated when omitted, so retrying this call — the\n * SDK's own retries included — replays the original rather than counting\n * the same work twice.\n */\n // `async` so that generating the key cannot throw synchronously out of a\n // method that otherwise only ever rejects: one call, one way to fail.\n async track(\n params: TrackParams,\n options?: RequestOptions,\n ): Promise<TrackResult> {\n return this.#client.request({\n ...options,\n method: \"POST\",\n path: \"/v1/usage/track\",\n // Fixed here, once, before the retry loop is entered: every attempt of\n // this call carries the same key, which is what makes replaying it safe.\n body: {\n ...params,\n idempotency_key: params.idempotency_key ?? idempotencyKey(),\n },\n idempotent: true,\n })\n }\n\n /** Reports which workspace this key acts for. */\n whoami(options?: RequestOptions): Promise<WhoAmI> {\n return this.#client.request({\n ...options,\n method: \"GET\",\n path: \"/v1/whoami\",\n })\n }\n}\n\n// Type-only: none of them is constructible without the unexported Client.\nexport type {\n CustomerAllowances,\n CustomerPlan,\n Customers,\n MeterbaseOptions,\n Meters,\n PlanAllowances,\n Plans,\n RequestOptions,\n}\nexport * from \"./errors.js\"\nexport type * from \"./types.js\"\n\n/**\n * The engine requires a key, and a caller made to invent one on every call\n * eventually will not — which is the moment a retry counts twice.\n */\nfunction idempotencyKey(): string {\n // Structurally, not as `Crypto`: that lib type is the DOM's, and this\n // compiles without it so the SDK stays as portable as `fetch` is.\n const webcrypto = globalThis.crypto as\n | {\n randomUUID?: () => string\n getRandomValues?: (array: Uint8Array) => Uint8Array\n }\n | undefined\n\n if (typeof webcrypto?.randomUUID === \"function\") {\n return webcrypto.randomUUID()\n }\n // `randomUUID` needs a secure context; `getRandomValues` does not, so a\n // page served over plain http still gets 128 random bits.\n if (typeof webcrypto?.getRandomValues === \"function\") {\n const bytes = webcrypto.getRandomValues(new Uint8Array(16))\n return Array.from(bytes, (b) => b.toString(16).padStart(2, \"0\")).join(\"\")\n }\n\n throw new MeterbaseError(\n \"No crypto to generate an idempotency key with: pass `idempotency_key` \" +\n \"yourself, or run somewhere `crypto.getRandomValues` exists.\",\n )\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mbase-sdk",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "TypeScript SDK for the Meterbase engine",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/usemeterbase/ts-sdk.git"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"LICENSE",
|
|
15
|
+
"README.md"
|
|
16
|
+
],
|
|
17
|
+
"main": "./dist/index.cjs",
|
|
18
|
+
"module": "./dist/index.js",
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"import": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"default": "./dist/index.js"
|
|
25
|
+
},
|
|
26
|
+
"require": {
|
|
27
|
+
"types": "./dist/index.d.cts",
|
|
28
|
+
"default": "./dist/index.cjs"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"./package.json": "./package.json"
|
|
32
|
+
},
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=18"
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsup",
|
|
41
|
+
"test": "vitest run",
|
|
42
|
+
"test:watch": "vitest",
|
|
43
|
+
"test:contract": "vitest run --config vitest.contract.config.ts",
|
|
44
|
+
"coverage": "vitest run --coverage",
|
|
45
|
+
"typecheck": "tsc --noEmit",
|
|
46
|
+
"lint": "eslint .",
|
|
47
|
+
"format": "prettier --write \"**/*.{ts,json,md,yml}\"",
|
|
48
|
+
"format:check": "prettier --check \"**/*.{ts,json,md,yml}\"",
|
|
49
|
+
"check": "npm run typecheck && npm run lint && npm run format:check && npm run test && npm run build && npm run check:publish",
|
|
50
|
+
"check:publish": "publint && attw --pack .",
|
|
51
|
+
"prepublishOnly": "npm run build"
|
|
52
|
+
},
|
|
53
|
+
"devDependencies": {
|
|
54
|
+
"@arethetypeswrong/cli": "^0.18.2",
|
|
55
|
+
"@eslint/js": "^10.0.1",
|
|
56
|
+
"@faker-js/faker": "^10.6.0",
|
|
57
|
+
"@types/node": "^22",
|
|
58
|
+
"@vitest/coverage-v8": "^3.2.4",
|
|
59
|
+
"eslint": "^10.10.0",
|
|
60
|
+
"globals": "^17.12.0",
|
|
61
|
+
"prettier": "^3.8.3",
|
|
62
|
+
"publint": "^0.3.14",
|
|
63
|
+
"tsup": "^8.5.0",
|
|
64
|
+
"typescript": "^6",
|
|
65
|
+
"typescript-eslint": "^8.70.0",
|
|
66
|
+
"vitest": "^3.2.4"
|
|
67
|
+
},
|
|
68
|
+
"keywords": [
|
|
69
|
+
"meterbase",
|
|
70
|
+
"metering",
|
|
71
|
+
"usage",
|
|
72
|
+
"billing",
|
|
73
|
+
"entitlements",
|
|
74
|
+
"sdk"
|
|
75
|
+
]
|
|
76
|
+
}
|