@takeal/cusfront-sdk 0.1.0

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.
Files changed (74) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/LICENSE +21 -0
  3. package/README.md +283 -0
  4. package/dist/customer-CoxPwe5o.d.cts +32 -0
  5. package/dist/customer-CoxPwe5o.d.ts +32 -0
  6. package/dist/http-BkZZZI8K.d.cts +72 -0
  7. package/dist/http-BkZZZI8K.d.ts +72 -0
  8. package/dist/index.cjs +486 -0
  9. package/dist/index.cjs.map +1 -0
  10. package/dist/index.d.cts +149 -0
  11. package/dist/index.d.ts +149 -0
  12. package/dist/index.js +478 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/react/index.cjs +82 -0
  15. package/dist/react/index.cjs.map +1 -0
  16. package/dist/react/index.d.cts +93 -0
  17. package/dist/react/index.d.ts +93 -0
  18. package/dist/react/index.js +75 -0
  19. package/dist/react/index.js.map +1 -0
  20. package/dist/resources/auth.cjs +88 -0
  21. package/dist/resources/auth.cjs.map +1 -0
  22. package/dist/resources/auth.d.cts +132 -0
  23. package/dist/resources/auth.d.ts +132 -0
  24. package/dist/resources/auth.js +86 -0
  25. package/dist/resources/auth.js.map +1 -0
  26. package/dist/resources/balance.cjs +21 -0
  27. package/dist/resources/balance.cjs.map +1 -0
  28. package/dist/resources/balance.d.cts +27 -0
  29. package/dist/resources/balance.d.ts +27 -0
  30. package/dist/resources/balance.js +19 -0
  31. package/dist/resources/balance.js.map +1 -0
  32. package/dist/resources/blog.cjs +39 -0
  33. package/dist/resources/blog.cjs.map +1 -0
  34. package/dist/resources/blog.d.cts +112 -0
  35. package/dist/resources/blog.d.ts +112 -0
  36. package/dist/resources/blog.js +37 -0
  37. package/dist/resources/blog.js.map +1 -0
  38. package/dist/resources/branding.cjs +16 -0
  39. package/dist/resources/branding.cjs.map +1 -0
  40. package/dist/resources/branding.d.cts +35 -0
  41. package/dist/resources/branding.d.ts +35 -0
  42. package/dist/resources/branding.js +14 -0
  43. package/dist/resources/branding.js.map +1 -0
  44. package/dist/resources/cards.cjs +91 -0
  45. package/dist/resources/cards.cjs.map +1 -0
  46. package/dist/resources/cards.d.cts +166 -0
  47. package/dist/resources/cards.d.ts +166 -0
  48. package/dist/resources/cards.js +89 -0
  49. package/dist/resources/cards.js.map +1 -0
  50. package/dist/resources/deposits.cjs +52 -0
  51. package/dist/resources/deposits.cjs.map +1 -0
  52. package/dist/resources/deposits.d.cts +168 -0
  53. package/dist/resources/deposits.d.ts +168 -0
  54. package/dist/resources/deposits.js +50 -0
  55. package/dist/resources/deposits.js.map +1 -0
  56. package/dist/resources/subscriptions.cjs +24 -0
  57. package/dist/resources/subscriptions.cjs.map +1 -0
  58. package/dist/resources/subscriptions.d.cts +36 -0
  59. package/dist/resources/subscriptions.d.ts +36 -0
  60. package/dist/resources/subscriptions.js +22 -0
  61. package/dist/resources/subscriptions.js.map +1 -0
  62. package/dist/telegram.cjs +557 -0
  63. package/dist/telegram.cjs.map +1 -0
  64. package/dist/telegram.d.cts +105 -0
  65. package/dist/telegram.d.ts +105 -0
  66. package/dist/telegram.js +550 -0
  67. package/dist/telegram.js.map +1 -0
  68. package/dist/webhooks.cjs +78 -0
  69. package/dist/webhooks.cjs.map +1 -0
  70. package/dist/webhooks.d.cts +70 -0
  71. package/dist/webhooks.d.ts +70 -0
  72. package/dist/webhooks.js +72 -0
  73. package/dist/webhooks.js.map +1 -0
  74. package/package.json +123 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/error.ts","../src/http.ts","../src/resources/auth.ts","../src/resources/deposits.ts","../src/resources/cards.ts","../src/resources/balance.ts","../src/resources/branding.ts","../src/resources/blog.ts","../src/resources/subscriptions.ts","../src/token-store.ts","../src/index.ts","../src/telegram.ts"],"names":["ls"],"mappings":";;;AAQO,IAAM,QAAA,GAAN,cAAuB,KAAA,CAAM;AAAA,EAGlC,WAAA,CAEkB,MAAA,EAIA,IAAA,EAGhB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,OAAO,IAAA,IAAQ,IAAA,CAAK,MAAA,GAAS,CAAA,GAAI,IAAA,GAAO,IAAA;AAC1C;AAMA,eAAsB,kBAAA,CACpB,MAAA,EACA,IAAA,GAA4B,EAAC,EACJ;AACzB,EAAA,MAAM,WAAW,kBAAA,EAAmB;AACpC,EAAA,IAAI,CAAC,QAAA;AACH,IAAA,MAAM,IAAI,aAAA;AAAA,MACR,mFAAA;AAAA,MACA;AAAA,KACF;AACF,EAAA,OAAO,YAAA,CAAa,QAAA,EAAU,MAAA,EAAQ,IAAI,CAAA;AAC5C","file":"telegram.cjs","sourcesContent":["/**\n * Errors surfaced by the SDK. All HTTP failures map onto `ApiError`;\n * network-level / abort / serialisation failures get the generic\n * `NetworkError`. Consumers catch on the discriminator field\n * (`isApiError` / `isNetworkError`) rather than `instanceof` — works\n * across bundler boundaries where multiple copies of the class can\n * coexist.\n */\nexport class ApiError extends Error {\n readonly isApiError = true as const;\n\n constructor(\n /** HTTP status code returned by the Takeal API. */\n public readonly status: number,\n /** Stable machine-readable code (e.g. `\"insufficient_funds\"`,\n * `\"permission_required\"`, `\"validation\"`). Same enum the\n * TypeScript types pin via openapi-typescript. */\n public readonly code: string,\n /** Human-readable message. English; the consumer maps to its\n * own i18n layer before showing to end-users. */\n message: string,\n /** Full parsed response body when available. Carries field-level\n * validation details for `code = \"validation\"`. */\n public readonly body?: unknown,\n ) {\n super(message);\n this.name = \"ApiError\";\n }\n}\n\nexport class NetworkError extends Error {\n readonly isNetworkError = true as const;\n\n constructor(message: string, public readonly cause?: unknown) {\n super(message);\n this.name = \"NetworkError\";\n }\n}\n\n/** Type guard — preferred over `instanceof` (bundler-safe). */\nexport function isApiError(e: unknown): e is ApiError {\n return (\n typeof e === \"object\" && e !== null && (e as { isApiError?: boolean }).isApiError === true\n );\n}\n\nexport function isNetworkError(e: unknown): e is NetworkError {\n return (\n typeof e === \"object\" &&\n e !== null &&\n (e as { isNetworkError?: boolean }).isNetworkError === true\n );\n}\n","import { ApiError, NetworkError } from \"./error.js\";\nimport type { TokenStore } from \"./token-store.js\";\n\n/**\n * Internal HTTP client. One per SDK instance; injected into each\n * resource. Responsibilities:\n *\n * - Construct absolute URLs from `baseUrl` + path.\n * - Set `Authorization: Bearer <jwt>` from the `TokenStore`.\n * - Set `Content-Type: application/json` on bodies.\n * - Parse JSON responses + map non-2xx to `ApiError`.\n * - Forward `Idempotency-Key` when the caller passes one.\n * - Surface network failures (DNS, abort, broken pipe) as\n * `NetworkError`.\n *\n * Auto-refresh + retry policies are deliberately NOT in here — they\n * belong to the resource layer (auth.refresh) which has the right\n * context for \"is this refreshable\" decisions.\n */\n\nexport type FetchLike = typeof fetch;\n\nexport interface HttpOptions {\n /** Request body. Will be JSON-serialised if not already a\n * string / FormData / Blob. */\n body?: unknown;\n /** Idempotency key forwarded as the `Idempotency-Key` header.\n * Required by the Takeal API on most write endpoints. */\n idempotencyKey?: string;\n /** Extra headers merged after the SDK's defaults — caller wins. */\n headers?: Record<string, string>;\n /** Bypass the token store for one call (login, refresh). */\n skipAuth?: boolean;\n /** AbortSignal forwarded to fetch. */\n signal?: AbortSignal;\n}\n\nexport class HttpClient {\n constructor(\n private readonly baseUrl: string,\n private readonly tokens: TokenStore,\n private readonly fetchImpl: FetchLike,\n ) {\n if (!baseUrl) throw new Error(\"HttpClient: baseUrl is required\");\n }\n\n async get<T>(path: string, opts: HttpOptions = {}): Promise<T> {\n return this.request<T>(\"GET\", path, opts);\n }\n\n async post<T>(path: string, opts: HttpOptions = {}): Promise<T> {\n return this.request<T>(\"POST\", path, opts);\n }\n\n async put<T>(path: string, opts: HttpOptions = {}): Promise<T> {\n return this.request<T>(\"PUT\", path, opts);\n }\n\n async patch<T>(path: string, opts: HttpOptions = {}): Promise<T> {\n return this.request<T>(\"PATCH\", path, opts);\n }\n\n async delete<T>(path: string, opts: HttpOptions = {}): Promise<T> {\n return this.request<T>(\"DELETE\", path, opts);\n }\n\n private async request<T>(method: string, path: string, opts: HttpOptions): Promise<T> {\n const url = this.absolute(path);\n const headers: Record<string, string> = {\n Accept: \"application/json\",\n };\n if (opts.body !== undefined) headers[\"Content-Type\"] = \"application/json\";\n if (opts.idempotencyKey) headers[\"Idempotency-Key\"] = opts.idempotencyKey;\n if (!opts.skipAuth) {\n const token = await Promise.resolve(this.tokens.get());\n if (token) headers[\"Authorization\"] = `Bearer ${token}`;\n }\n Object.assign(headers, opts.headers ?? {});\n\n const init: RequestInit = {\n method,\n headers,\n ...(opts.signal ? { signal: opts.signal } : {}),\n };\n if (opts.body !== undefined) {\n init.body =\n typeof opts.body === \"string\" ? opts.body : JSON.stringify(opts.body);\n }\n\n let resp: Response;\n try {\n resp = await this.fetchImpl(url, init);\n } catch (e) {\n // DNS failure, connection refused, abort — anything before the\n // server returns a status. Map to NetworkError for the consumer.\n throw new NetworkError(\n e instanceof Error ? e.message : \"network error\",\n e,\n );\n }\n\n return parseResponse<T>(resp);\n }\n\n private absolute(path: string): string {\n if (path.startsWith(\"http://\") || path.startsWith(\"https://\")) return path;\n const base = this.baseUrl.replace(/\\/+$/, \"\");\n const tail = path.startsWith(\"/\") ? path : `/${path}`;\n return `${base}${tail}`;\n }\n}\n\nasync function parseResponse<T>(resp: Response): Promise<T> {\n // Read body once — the Takeal API either returns JSON or an empty body\n // (204 No Content on some DELETEs). Empty body → undefined cast.\n const text = await resp.text();\n let body: unknown;\n if (text.length === 0) {\n body = undefined;\n } else {\n try {\n body = JSON.parse(text);\n } catch {\n // Non-JSON response. On 2xx that's unexpected but not fatal —\n // hand back the raw text under a synthetic field. On error\n // status, fold into the ApiError body.\n body = { raw: text };\n }\n }\n\n if (!resp.ok) {\n const errBody = (body ?? {}) as { code?: string; message?: string };\n throw new ApiError(\n resp.status,\n errBody.code ?? `http_${resp.status}`,\n errBody.message ?? resp.statusText ?? \"request failed\",\n body,\n );\n }\n return body as T;\n}\n","import type { HttpClient } from \"../http.js\";\nimport type { TokenStore } from \"../token-store.js\";\n\n/**\n * Auth resource — `client.auth.*`.\n *\n * Covers the end-user-facing staged auth flow: password login\n * with optional TOTP/OTP step-up. The shape mirrors the responses\n * the Takeal API returns from `/auth/login`, `/auth/login/totp`,\n * `/auth/login/otp/verify`, `/auth/login/2fa/switch`, and `/auth/me`.\n *\n * The login methods stash the JWT in the configured `TokenStore` on\n * success so subsequent `client.*` calls authenticate automatically.\n * Step-up responses (TotpRequired / OtpSent) carry their own short-\n * lived challenge token which the caller passes to the next method\n * — those tokens DO NOT go through the TokenStore (they're not the\n * end-state JWT).\n */\n\nexport interface User {\n id: string;\n email: string;\n role: string;\n is_active: boolean;\n /** True for users auto-provisioned via the Telegram Mini App who still hold\n * a synthetic placeholder email. The client should prompt for a real email\n * and attach it via `auth.linkEmail` — this flips the flag to false. */\n email_pending?: boolean;\n created_at: string;\n updated_at: string;\n}\n\nexport interface LoginInput {\n email: string;\n password: string;\n}\n\n/** Discriminated union — `stage` is the discriminator. */\nexport type LoginResponse = JwtIssued | TotpRequired | TotpSetupRequired;\n\nexport interface JwtIssued {\n stage: \"jwt\";\n access_token: string;\n expires_at: string;\n user: User;\n /** True iff the user's role grants `system.view_hub`.\n * Cusfront ignores this; the operator console uses it to gate `/dashboard`. */\n hub_access?: boolean;\n}\n\nexport interface TotpRequired {\n stage: \"totp_required\";\n challenge_token: string;\n expires_at: string;\n /** Alternate second factors. Pick one with `/2fa/switch`. */\n available_methods: AvailableMethod[];\n}\n\nexport interface TotpSetupRequired {\n stage: \"totp_setup_required\";\n challenge_token: string;\n expires_at: string;\n /** OTPAuth URI rendered as a QR by the consumer. */\n otpauth_url: string;\n /** Same secret base32-encoded — for manual entry alongside QR. */\n secret_base32: string;\n}\n\nexport interface AvailableMethod {\n kind: \"totp\" | \"telegram_otp\" | \"email_otp\";\n /** Short user-facing hint, e.g. `\"Telegram (@user)\"` or `\"e****@example.com\"`. */\n hint?: string;\n}\n\nexport interface TotpVerifyInput {\n challenge_token: string;\n /** 6-digit TOTP code OR `XXXX-XXXX` backup code. */\n code: string;\n}\n\nexport interface OtpVerifyInput {\n challenge_token: string;\n /** 6-digit one-time code delivered via the selected channel. */\n code: string;\n}\n\nexport interface SwitchMethodInput {\n challenge_token: string;\n method: AvailableMethod[\"kind\"];\n}\n\nexport interface OtpSentResponse {\n stage: \"otp_sent\";\n challenge_token: string;\n expires_at: string;\n method: AvailableMethod[\"kind\"];\n hint?: string;\n available_methods: AvailableMethod[];\n}\n\nexport class AuthResource {\n constructor(\n private readonly http: HttpClient,\n private readonly tokens: TokenStore,\n ) {}\n\n /** Password-auth entry. May resolve to a JWT, or to a step-up\n * challenge that needs `verifyTotp` / `verifyOtp` next. */\n async login(input: LoginInput): Promise<LoginResponse> {\n const resp = await this.http.post<LoginResponse>(\"/auth/login\", {\n body: input,\n skipAuth: true,\n });\n if (resp.stage === \"jwt\") {\n await Promise.resolve(this.tokens.set(resp.access_token));\n }\n return resp;\n }\n\n /** Verify a TOTP code (or XXXX-XXXX backup code) against a\n * `totp_required` challenge. On success the JWT is stored. */\n async verifyTotp(input: TotpVerifyInput): Promise<JwtIssued> {\n const resp = await this.http.post<JwtIssued>(\"/auth/login/totp\", {\n body: input,\n skipAuth: true,\n });\n await Promise.resolve(this.tokens.set(resp.access_token));\n return resp;\n }\n\n /** Verify a 6-digit OTP code (Telegram / email) against an\n * `otp_sent` challenge. */\n async verifyOtp(input: OtpVerifyInput): Promise<JwtIssued> {\n const resp = await this.http.post<JwtIssued>(\"/auth/login/otp/verify\", {\n body: input,\n skipAuth: true,\n });\n await Promise.resolve(this.tokens.set(resp.access_token));\n return resp;\n }\n\n /** Swap the 2FA method mid-flow. Resolves to `otp_sent` for\n * telegram/email; for TOTP it short-circuits back to the challenge. */\n async switchMethod(input: SwitchMethodInput): Promise<OtpSentResponse> {\n return this.http.post<OtpSentResponse>(\"/auth/login/2fa/switch\", {\n body: input,\n skipAuth: true,\n });\n }\n\n /** Exchange a signed Telegram Mini App `initData` payload for a session\n * JWT. The server validates the initData HMAC against the deployment's bot\n * token, then find-or-creates the end-user. First-time Telegram users are\n * auto-provisioned with `user.email_pending === true` — prompt them for a\n * real email and call {@link linkEmail}. Stores the JWT on success.\n *\n * Most consumers use the higher-level `fromInitData` / `fromTelegramWebApp`\n * helpers in `@takeal/cusfront-sdk/telegram`; reach for this directly when\n * you already hold a configured client. */\n async exchangeTelegram(input: { initData: string }): Promise<JwtIssued> {\n const resp = await this.http.post<JwtIssued>(\"/auth/telegram/exchange\", {\n body: { init_data: input.initData },\n skipAuth: true,\n });\n await Promise.resolve(this.tokens.set(resp.access_token));\n return resp;\n }\n\n /** Attach a real email to the current user (and clear `email_pending`).\n * Used after a Telegram exchange to satisfy the email requirement; also\n * works for a password user changing their address. 409 if taken. */\n async linkEmail(input: { email: string }): Promise<User> {\n return this.http.post<User>(\"/me/email\", { body: { email: input.email } });\n }\n\n /** Current user — fails 401 when the stored JWT is expired or\n * missing. Useful as a \"do I have a session\" probe on app boot. */\n async me(): Promise<User> {\n return this.http.get<User>(\"/auth/me\");\n }\n\n /** Local sign-out. The SDK doesn't currently call a server-side\n * endpoint (the Takeal API issues stateless JWTs); clearing the\n * store is enough. Server-side session invalidation may land\n * with a future session table. */\n async signOut(): Promise<void> {\n await Promise.resolve(this.tokens.clear());\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type { CustomerInfo } from \"../types/customer.js\";\n\n/**\n * Deposits resource — `client.deposits.*`.\n *\n * The \"money IN\" surface: an end user tops up their wallet balance via a\n * funder connector. Mirrors the Takeal API's `/me/deposits` routes:\n *\n * POST /me/deposits → initiate\n * GET /me/deposits → list (most recent first)\n * GET /me/deposits/{id} → get\n * POST /me/deposits/{id}/refunds → refund\n *\n * A deposit is rarely terminal on the initiate call: real PSPs return\n * `redirect_required` (3DS / APM redirect) and flip to `confirmed` later via\n * a connector → Takeal API inbound event. Poll `get(id)` or watch the user's\n * webhook stream for the `deposit.confirmed` / `deposit.failed` outcome.\n */\n\n/** Lifecycle of a deposit. `redirect_required` carries `redirect_url`. */\nexport type DepositStatus =\n | \"pending\"\n | \"redirect_required\"\n | \"confirmed\"\n | \"failed\";\n\n/** Top-up rail. The chosen funder decides which it supports. */\nexport type DepositMethod = \"card\" | \"crypto\" | \"bank_transfer\";\n\n/**\n * A deposit record as the Takeal API returns it. Mirrors the `deposits` table; the\n * server-side `id` is the stable handle the SDK polls against. `idempotency_key`\n * and `request_fingerprint` are server-internal and never serialised.\n */\n/** Input for `quote()` — price a cross-currency deposit before paying. */\nexport interface CreateQuoteInput {\n /** Decimal string, e.g. `\"5000.00\"`. */\n amount: string;\n /** ISO 4217 source currency — must differ from the wallet's local currency. */\n currency: string;\n}\n\n/**\n * A rate-locked funding quote: pay `source_amount source_currency`, the\n * wallet is credited `credited_amount credited_currency` (net of the\n * platform's conversion spread). Execute by passing `id` as `quote_id` to\n * `initiate()` before `expires_at`; after that the API returns 409 and a new\n * quote is needed.\n */\nexport interface FundingQuote {\n id: string;\n source_amount: string;\n source_currency: string;\n credited_amount: string;\n credited_currency: string;\n /** Provider rate before spread (credited units per 1 source unit). */\n rate: string;\n spread_bps: number;\n provider: string;\n expires_at: string;\n}\n\nexport interface Deposit {\n id: string;\n user_id: string;\n /** Slug of the funder that handled this deposit, as configured by the deployment. */\n connector_slug: string;\n /** The connector's own reference, populated once it responds. */\n provider_reference: string | null;\n status: DepositStatus;\n /** Decimal serialised as a string to avoid float drift. */\n amount: string;\n currency: string;\n method: DepositMethod;\n /** Present when `status === \"redirect_required\"` — send the user here. */\n redirect_url: string | null;\n failure_reason: string | null;\n /** Final settled amount once confirmed (may differ from `amount` on FX). */\n confirmed_amount: string | null;\n confirmed_at: string | null;\n /** Set on cross-currency deposits: the quote this deposit executed against. */\n quote_id?: string | null;\n /** Locked provider rate (credited units per 1 source unit). */\n fx_rate?: string | null;\n fx_spread_bps?: number | null;\n /** The wallet's local currency the deposit converted into. */\n credited_currency?: string | null;\n /** What the wallet was actually credited, net of spread. */\n credited_amount?: string | null;\n created_at: string;\n updated_at: string;\n}\n\nexport interface InitiateDepositInput {\n /** Decimal as a string (`\"100.00\"`) — avoids float-precision loss on the wire. */\n amount: string;\n /** ISO 4217 code, e.g. `\"USD\"`. */\n currency: string;\n method: DepositMethod;\n /**\n * Optional. Slug of a specific funder to route through. Omit to\n * let the Takeal API pick the first active funder. Unknown slug → 400; empty\n * funder list → 503.\n */\n funder_slug?: string;\n /** Provider-specific extras. The mock funder reads `mock_scenario`. */\n metadata?: Record<string, string>;\n /** Structured billing details — real PSPs require these for 3DS / compliance. */\n customer?: CustomerInfo;\n /**\n * Required by the Takeal API on this write endpoint. Same key + body replays the\n * original deposit; same key + different body returns 409. Supply a stable\n * UUID per logical attempt so a retried network call is safe.\n */\n idempotencyKey: string;\n /**\n * Required when `currency` differs from the wallet's local currency: a\n * fresh quote id from `quote()`. Cross-currency deposits without one are\n * rejected with 400; expired quotes with 409.\n */\n quote_id?: string;\n}\n\nexport interface CreateDepositRefundInput {\n /** Omit for a full refund of the original confirmed amount; same currency. */\n amount?: string;\n /** Human-readable reason, e.g. `\"customer_request\"`. */\n reason?: string;\n metadata?: Record<string, string>;\n /** Required. Replays are keyed on this. */\n idempotencyKey: string;\n}\n\n/** A refund row as the Takeal API returns it (`refunds` table, deposit-targeted). */\nexport interface Refund {\n id: string;\n target_type: string;\n deposit_id?: string;\n payment_id?: string;\n connector_slug: string;\n amount: string;\n currency: string;\n reason: string;\n status: string;\n provider_refund_reference?: string;\n failure_reason?: string;\n requestor_type: string;\n requestor_id: string;\n created_at: string;\n updated_at: string;\n}\n\nexport class DepositsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Initiate a top-up. Resolves to the freshly-created `Deposit`, whose\n * `status` may already be `confirmed` (synchronous rails / mock) or\n * `redirect_required` (3DS / APM — forward the user to `redirect_url`).\n */\n /**\n * Price a cross-currency deposit BEFORE paying. The rate is locked\n * server-side until `expires_at`; deposits in the local currency need no\n * quote (the API answers 400 `no_quote_needed`).\n */\n async quote(input: CreateQuoteInput): Promise<FundingQuote> {\n return this.http.post<FundingQuote>(\"/me/deposits/quotes\", { body: input });\n }\n\n async initiate(input: InitiateDepositInput): Promise<Deposit> {\n const { idempotencyKey, ...body } = input;\n return this.http.post<Deposit>(\"/me/deposits\", {\n body,\n idempotencyKey,\n });\n }\n\n /** Fetch one deposit by id — the poll target while a redirect resolves. */\n async get(id: string): Promise<Deposit> {\n return this.http.get<Deposit>(`/me/deposits/${encodeURIComponent(id)}`);\n }\n\n /** List the caller's deposits, most recent first. */\n async list(): Promise<Deposit[]> {\n return this.http.get<Deposit[]>(\"/me/deposits\");\n }\n\n /**\n * Refund a previously-confirmed deposit. Synchronous when the\n * connector settles inline; otherwise the row stays `pending` and flips\n * later via the inbound `deposit.refunded` event.\n */\n async refund(\n depositId: string,\n input: CreateDepositRefundInput,\n ): Promise<Refund> {\n const { idempotencyKey, ...body } = input;\n return this.http.post<Refund>(\n `/me/deposits/${encodeURIComponent(depositId)}/refunds`,\n { body, idempotencyKey },\n );\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type { CustomerInfo } from \"../types/customer.js\";\n\n/**\n * Cards resource — `client.cards.*`.\n *\n * The end-user \"money OUT\" surface: a user issues themselves a card backed by\n * their wallet balance via an issuer connector. Mirrors the Takeal API's\n * `/me/cards` routes:\n *\n * POST /me/cards → create\n * GET /me/cards → list (most recent first)\n * GET /me/cards/{id} → get\n * GET /me/cards/{id}/balance → balance (prepaid remaining)\n * POST /me/cards/{id}/freeze → freeze\n * POST /me/cards/{id}/unfreeze → unfreeze\n * POST /me/cards/{id}/terminate → terminate (one-way)\n *\n * The lifecycle actions are ownership-gated server-side: a caller can only\n * freeze / unfreeze / terminate a card that belongs to them (else 404).\n *\n * ## What is intentionally NOT here\n *\n * Card-data reveal (PAN / CVV) is a separate, security-sensitive flow with its\n * own re-auth + rate-limit + audit contract and is intentionally\n * NOT part of this resource (tracked separately).\n *\n * Today only PREPAID is wired end-to-end; CREDIT and GIFT return 400 from\n * the Takeal API until their issuer flows land.\n */\n\n/** Card product. Only `prepaid` is fully implemented today. */\nexport type CardType = \"credit\" | \"prepaid\" | \"gift\";\n\n/**\n * Card lifecycle state.\n *\n * `pending_payment` is a transient state: the row exists but the\n * per-card issuance-fee debit has not yet succeeded; such cards have no\n * provider reference and no user-visible side effects.\n */\nexport type CardStatus =\n | \"pending_payment\"\n | \"active\"\n | \"frozen\"\n | \"terminated\"\n | \"redeemed\"\n | \"failed\";\n\n/**\n * A card record as the Takeal API returns it. Mirrors the `cards` table. Note the\n * SDK never receives the full PAN or CVV here — only `last4` + expiry. The\n * gift-card `redemption_code` is returned exactly once (on create) and\n * scrubbed from subsequent list/get responses.\n */\nexport interface Card {\n id: string;\n user_id: string;\n card_type: CardType;\n /** Slug of the issuer that minted this card, as configured by the deployment. */\n connector_slug: string;\n /** The connector's own reference, populated once it responds. */\n provider_reference: string | null;\n status: CardStatus;\n /** Last four digits of the PAN — safe to display. */\n last4: string | null;\n expiry_month: number | null;\n expiry_year: number | null;\n /** Gift cards only, present once on create then scrubbed. */\n redemption_code?: string;\n /** Decimal as a string. */\n initial_amount: string | null;\n currency: string;\n failure_reason: string | null;\n created_at: string;\n updated_at: string;\n}\n\nexport interface CreateCardInput {\n /** `prepaid` (the only fully-wired type today), `credit`, or `gift`. */\n type: CardType;\n /** Decimal as a string. The prepaid load amount drained from wallet balance. */\n initial_amount?: string;\n /** ISO 4217 code, e.g. `\"USD\"`. */\n currency: string;\n /**\n * Optional. Slug of a specific issuer to mint with. Omit to let\n * the Takeal API pick the first active issuer. Unknown slug → 400; empty issuer\n * list → 503.\n */\n issuer_slug?: string;\n metadata?: Record<string, string>;\n /** Structured billing details — real issuers require these for 3DS / KYC. */\n customer?: CustomerInfo;\n /**\n * Required by the Takeal API on this write endpoint. Same key + body replays the\n * original card; same key + different body returns 409.\n */\n idempotencyKey: string;\n}\n\n/** Remaining balance of a prepaid card. */\nexport interface CardBalance {\n amount: string;\n currency: string;\n}\n\n/** Re-auth gate for {@link CardsResource.reveal}. */\nexport interface RevealCardInput {\n /** The user's account password — mandatory re-auth. */\n password: string;\n /** TOTP code; required only when the user has TOTP enrolled. */\n totpCode?: string;\n}\n\n/**\n * Full card data from a successful reveal. **Security**: never persist this —\n * keep it in volatile memory only, clear it within `expires_in_seconds`, and\n * never write it to localStorage / logs (the API marks the response no-store).\n */\nexport interface RevealedCard {\n pan: string;\n cvv: string;\n expiry_month: number;\n expiry_year: number;\n holder_name: string;\n /** Display window before the client should auto-clear the data. */\n expires_in_seconds: number;\n}\n\nexport class CardsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Issue a card backed by the user's wallet balance. Resolves to the new\n * `Card`. On a ledger failure after provider creation, the Takeal API rolls the row\n * to `failed` (never an orphaned active card); inspect `status` /\n * `failure_reason` on the result.\n */\n async create(input: CreateCardInput): Promise<Card> {\n const { idempotencyKey, ...body } = input;\n return this.http.post<Card>(\"/me/cards\", {\n body,\n idempotencyKey,\n });\n }\n\n /** Fetch one card by id. */\n async get(id: string): Promise<Card> {\n return this.http.get<Card>(`/me/cards/${encodeURIComponent(id)}`);\n }\n\n /** List the caller's cards, most recent first. */\n async list(): Promise<Card[]> {\n return this.http.get<Card[]>(\"/me/cards\");\n }\n\n /**\n * Remaining balance of a prepaid card. `currency` is required by the Takeal API and\n * forwarded as a query param.\n */\n async balance(id: string, currency: string): Promise<CardBalance> {\n const q = new URLSearchParams({ currency }).toString();\n return this.http.get<CardBalance>(\n `/me/cards/${encodeURIComponent(id)}/balance?${q}`,\n );\n }\n\n /**\n * Freeze the caller's own card. Reversible via {@link unfreeze}. The optional\n * `reason` is recorded on the audit trail. Resolves to the updated card.\n * 404 if the card isn't the caller's; 501 if the issuer can't freeze.\n */\n async freeze(id: string, reason?: string): Promise<Card> {\n return this.http.post<Card>(\n `/me/cards/${encodeURIComponent(id)}/freeze`,\n { body: { reason } },\n );\n }\n\n /**\n * Reveal the FULL PAN + CVV for the caller's own card. Re-auth gated\n * (password, + TOTP when the user has it enrolled) and rate-limited\n * server-side. The Takeal API never persists this data and marks the\n * response no-store; the SDK returns it verbatim and holds nothing.\n *\n * **Consumer security duties** (the SDK can't enforce these for you):\n * keep the result in volatile memory only, never write it to\n * localStorage / logs, and clear it within `expires_in_seconds`.\n *\n * 401 bad re-auth · 403 not your card · 429 rate-limited · 501 connector\n * has no sensitive-data endpoint · 503 provider error.\n */\n async reveal(id: string, input: RevealCardInput): Promise<RevealedCard> {\n return this.http.post<RevealedCard>(\n `/me/cards/${encodeURIComponent(id)}/reveal`,\n { body: { password: input.password, totp_code: input.totpCode } },\n );\n }\n\n /** Unfreeze a previously-frozen card. Idempotent on an already-active card. */\n async unfreeze(id: string): Promise<Card> {\n return this.http.post<Card>(\n `/me/cards/${encodeURIComponent(id)}/unfreeze`,\n { body: {} },\n );\n }\n\n /**\n * Terminate the caller's own card. **One-way** — a terminated card cannot be\n * reactivated. The optional `reason` is audited. Idempotent on an\n * already-terminated card.\n */\n async terminate(id: string, reason?: string): Promise<Card> {\n return this.http.post<Card>(\n `/me/cards/${encodeURIComponent(id)}/terminate`,\n { body: { reason } },\n );\n }\n}\n","import type { HttpClient } from \"../http.js\";\n\n/**\n * Balance resource — `client.balance.*`.\n *\n * The user's wallet balance, tracked in the ledger. Mirrors\n * the Takeal API's `GET /me/balance?currency=<code>` route. Balance is per-currency:\n * the endpoint requires a `currency` query param and returns the amount held\n * in that currency.\n */\n\n/** Wallet balance for one currency. `amount` is a decimal string. */\nexport interface Balance {\n amount: string;\n currency: string;\n}\n\nexport class BalanceResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Fetch the user's wallet balance for `currency` (ISO 4217, e.g. `\"USD\"`).\n * Required — the ledger holds a separate balance per currency, so there is\n * no \"total\" without one.\n */\n async get(currency: string): Promise<Balance> {\n const q = new URLSearchParams({ currency }).toString();\n return this.http.get<Balance>(`/me/balance?${q}`);\n }\n}\n","import type { HttpClient } from \"../http.js\";\n\n/**\n * Branding resource — `client.branding.*`.\n *\n * Runtime white-label config published by the deployment at `GET /branding`\n * (public, no auth). Lets a Cusfront re-theme itself on the fly — platform\n * name, logo, favicon and the label used for the end-user's balance — without\n * a rebuild. Pairs with the build-time `BrandConfig`: the server-side values\n * win whenever both are present.\n */\n\n/** Public brand config of the deployment. All strings; empty = use the client default. */\nexport interface Branding {\n /** Platform display name (e.g. the white-label brand). */\n platform_name: string;\n /** Name of the merchant-facing portal. */\n merchant_portal_name: string;\n /** Logo image — absolute URL or `data:` URI. Empty → client default. */\n logo_url: string;\n /** Favicon — absolute URL or `data:` URI. Empty → client default. */\n favicon_url: string;\n /** User-facing name of the balance, e.g. `\"Wallet\"` or `\"Acme Wallet\"`.\n * Display-only: the `balance` API shape never changes with it. */\n wallet_label: string;\n}\n\nexport class BrandingResource {\n constructor(private readonly http: HttpClient) {}\n\n /** Fetch the deployment's public brand config. Safe to call before login. */\n async get(opts: { signal?: AbortSignal } = {}): Promise<Branding> {\n return this.http.get<Branding>(\"/branding\", { skipAuth: true, signal: opts.signal });\n }\n}\n","import type { HttpClient } from \"../http.js\";\n\n/**\n * Blog resource — `client.blog.*`.\n *\n * Posts are public: these calls work before the user logs in, which is what\n * a marketing page or a Mini App landing screen needs.\n *\n * A post arrives as a **structured document**, not as HTML. `body_blocks` is\n * a flat list of typed nodes; map each `type` onto your own component and the\n * post inherits your site's styling. `body_markdown` is there too if you'd\n * rather run your own renderer.\n *\n * ```ts\n * const { posts } = await client.blog.list({ perPage: 5 });\n * const post = await client.blog.get(posts[0].slug);\n *\n * post.body_blocks.map((b) => {\n * switch (b.type) {\n * case \"heading\": return <Heading level={b.level}>{b.text}</Heading>;\n * case \"paragraph\": return <P>{b.text}</P>;\n * case \"image\": return <Figure src={b.url} alt={b.alt} caption={b.caption} />;\n * case \"list\": return <List ordered={b.ordered} items={b.items} />;\n * case \"quote\": return <Quote>{b.text}</Quote>;\n * case \"code\": return <Code lang={b.lang}>{b.text}</Code>;\n * case \"divider\": return <Hr />;\n * }\n * });\n * ```\n *\n * Inline emphasis (`**bold**`, `[link](url)`) is left as Markdown inside\n * block text — every renderer already knows what to do with it.\n */\n\n/** One node of a post body. Discriminated on `type`. */\nexport type BlogBlock =\n | { type: \"heading\"; level: number; text: string }\n | { type: \"paragraph\"; text: string }\n | { type: \"image\"; url: string; alt?: string; caption?: string }\n | { type: \"list\"; ordered: boolean; items: string[] }\n | { type: \"quote\"; text: string }\n | { type: \"code\"; lang?: string; text: string }\n | { type: \"divider\" };\n\nexport interface BlogPost {\n /** Stable public key — link by this. */\n slug: string;\n title: string;\n /** Teaser for cards; falls back to the first paragraph. */\n excerpt: string;\n /** Image URL, relative to the API origin. Absent when no cover is set. */\n cover_url?: string;\n /** Raw Markdown, for consumers that bring their own renderer. */\n body_markdown: string;\n /** The recommended input for rendering — see the module docs. */\n body_blocks: BlogBlock[];\n tags: string[];\n /** Present only when the post declares one. */\n locale?: string;\n /** Rough read time in minutes (minimum 1). */\n reading_minutes: number;\n published_at: string | null;\n updated_at: string;\n}\n\nexport interface BlogListInput {\n /** 1-based. Default 1. */\n page?: number;\n /** 1..=50. Default 10. */\n perPage?: number;\n /** Only posts carrying this tag. */\n tag?: string;\n /** Only posts in this locale. */\n locale?: string;\n}\n\nexport interface BlogList {\n posts: BlogPost[];\n total: number;\n page: number;\n per_page: number;\n}\n\nexport class BlogResource {\n constructor(private readonly http: HttpClient) {}\n\n /** Published posts, newest first. No authentication required. */\n async list(input: BlogListInput = {}): Promise<BlogList> {\n const q = new URLSearchParams();\n if (input.page) q.set(\"page\", String(input.page));\n if (input.perPage) q.set(\"per_page\", String(input.perPage));\n if (input.tag) q.set(\"tag\", input.tag);\n if (input.locale) q.set(\"locale\", input.locale);\n const qs = q.toString();\n return this.http.get<BlogList>(`/blog/posts${qs ? `?${qs}` : \"\"}`, {\n skipAuth: true,\n });\n }\n\n /** One post by slug. No authentication required. */\n async get(slug: string): Promise<BlogPost> {\n return this.http.get<BlogPost>(`/blog/posts/${encodeURIComponent(slug)}`, {\n skipAuth: true,\n });\n }\n\n /**\n * Absolute URL for an image path returned inside a post (`cover_url`, or an\n * image block's `url`). Handy when the app renders on a different origin\n * than the API.\n */\n imageUrl(baseUrl: string, path: string): string {\n if (/^https?:\\/\\//i.test(path)) return path;\n return `${baseUrl.replace(/\\/$/, \"\")}${path.startsWith(\"/\") ? \"\" : \"/\"}${path}`;\n }\n}\n","import type { HttpClient } from \"../http.js\";\n\n/**\n * Subscriptions resource — `client.subscriptions.*`.\n *\n * Which channels the signed-in user agreed to receive announcements on.\n * `available` tells you which toggles to render: a deployment with no\n * Telegram bot configured can't deliver there, so offering the switch would\n * be a lie.\n *\n * ```ts\n * const { channels, available } = await client.subscriptions.get();\n * await client.subscriptions.set([...channels, \"telegram\"]);\n * ```\n *\n * Unrelated to paid/VIP tiers — this is only about announcements.\n */\n\nexport type BroadcastChannel = \"email\" | \"telegram\" | (string & {});\n\nexport interface Subscriptions {\n /** Channels the user currently receives announcements on. */\n channels: BroadcastChannel[];\n /** Channels this deployment can actually deliver on. */\n available: BroadcastChannel[];\n}\n\nexport class SubscriptionsResource {\n constructor(private readonly http: HttpClient) {}\n\n async get(): Promise<Subscriptions> {\n return this.http.get<Subscriptions>(\"/me/subscriptions\");\n }\n\n /**\n * Replace the whole set — this is a PUT, not a merge. Pass `[]` to opt out\n * of everything.\n */\n async set(channels: BroadcastChannel[]): Promise<Subscriptions> {\n return this.http.put<Subscriptions>(\"/me/subscriptions\", {\n body: { channels },\n });\n }\n}\n","/**\n * Pluggable storage for the JWT.\n *\n * Default behaviour by environment:\n * - browser → `localStorage` (synchronous, persists across reloads)\n * - Node / SSR / worker → in-memory (no global state to leak)\n * - mobile (Capacitor / RN) → consumer must inject Keychain /\n * EncryptedSharedPreferences via `createClient({ tokenStore })`\n *\n * The store is intentionally tiny — three methods, no eviction\n * policy, no encryption. Encryption is the consumer's call (mobile\n * adapters wrap platform-native secure storage). Persistence shape\n * is opaque to the SDK; tokens are passed through verbatim.\n */\nexport interface TokenStore {\n get(): string | null | Promise<string | null>;\n set(token: string): void | Promise<void>;\n clear(): void | Promise<void>;\n}\n\n/** Sync `localStorage`-backed store. Falls through to in-memory when\n * `window.localStorage` is unavailable (private mode quota, SSR). */\nexport function defaultBrowserStore(key = \"takeal_jwt\"): TokenStore {\n const fallback = inMemoryStore();\n // Probe once at construction — avoid the try/catch on every call.\n let usable = false;\n try {\n if (typeof globalThis !== \"undefined\" && \"localStorage\" in globalThis) {\n const ls = (globalThis as { localStorage: Storage }).localStorage;\n const probe = \"__takeal_probe__\";\n ls.setItem(probe, \"1\");\n ls.removeItem(probe);\n usable = true;\n }\n } catch {\n usable = false;\n }\n if (!usable) return fallback;\n const ls = (globalThis as { localStorage: Storage }).localStorage;\n return {\n get: () => ls.getItem(key),\n set: (token) => ls.setItem(key, token),\n clear: () => ls.removeItem(key),\n };\n}\n\n/** In-memory store. Use for SSR / tests / when persistence isn't\n * desired (e.g. ephemeral kiosk sessions). */\nexport function inMemoryStore(): TokenStore {\n let value: string | null = null;\n return {\n get: () => value,\n set: (token) => {\n value = token;\n },\n clear: () => {\n value = null;\n },\n };\n}\n","/**\n * `@takeal/cusfront-sdk` — typed client for the Takeal end-user API.\n *\n * Entry point: `createClient({ baseUrl, brand?, tokenStore?, fetch? })`.\n * Resources are accessed off the returned client (`client.auth.login`,\n * `client.cards.list`, …). Sub-exports under `@takeal/cusfront-sdk/<resource>`\n * publish each resource independently so a Cusfront only pulls what\n * it imports.\n *\n * Brand-neutral by design. No customer / deployment names embedded.\n * Brand swap happens at runtime via `BrandConfig`.\n */\n\nimport { HttpClient, type FetchLike } from \"./http.js\";\nimport { AuthResource } from \"./resources/auth.js\";\nimport { DepositsResource } from \"./resources/deposits.js\";\nimport { CardsResource } from \"./resources/cards.js\";\nimport { BalanceResource } from \"./resources/balance.js\";\nimport { BrandingResource } from \"./resources/branding.js\";\nimport { BlogResource } from \"./resources/blog.js\";\nimport { SubscriptionsResource } from \"./resources/subscriptions.js\";\nimport {\n defaultBrowserStore,\n inMemoryStore,\n type TokenStore,\n} from \"./token-store.js\";\nimport type { BrandConfig } from \"./brand.js\";\n\nexport type { BrandConfig } from \"./brand.js\";\nexport { ApiError, NetworkError, isApiError, isNetworkError } from \"./error.js\";\nexport { defaultBrowserStore, inMemoryStore, type TokenStore } from \"./token-store.js\";\n\n// Re-export resource types so consumers can `import { Deposit } from\n// \"@takeal/cusfront-sdk\"` without reaching into sub-paths.\nexport type { Address, CustomerInfo } from \"./types/customer.js\";\nexport type {\n Deposit,\n DepositStatus,\n DepositMethod,\n InitiateDepositInput,\n CreateDepositRefundInput,\n Refund,\n CreateQuoteInput, FundingQuote } from \"./resources/deposits.js\";\nexport type {\n Card,\n CardType,\n CardStatus,\n CreateCardInput,\n CardBalance,\n RevealCardInput,\n RevealedCard,\n} from \"./resources/cards.js\";\nexport type { Balance } from \"./resources/balance.js\";\nexport type { Branding } from \"./resources/branding.js\";\nexport type { BlogPost, BlogBlock, BlogList, BlogListInput } from \"./resources/blog.js\";\nexport type {\n Subscriptions,\n BroadcastChannel,\n} from \"./resources/subscriptions.js\";\n\nexport interface CreateClientOptions {\n /** Absolute origin of the Takeal API deployment, no trailing slash.\n * e.g. `\"https://api.takeal.example.com\"`. */\n baseUrl: string;\n /** Runtime brand config. Optional; consumer renders its own brand\n * if omitted. */\n brand?: BrandConfig;\n /** Token persistence. Defaults to `defaultBrowserStore()` when\n * `window.localStorage` is present, else `inMemoryStore()`. */\n tokenStore?: TokenStore;\n /** Override the `fetch` implementation — useful for Node < 18,\n * React Native < 0.74, MSW intercept layers, etc. */\n fetch?: FetchLike;\n /** When true, the SDK runs every response through a zod schema\n * before handing it to the caller. Requires `zod` >= 3.22 as a\n * peer dep. Off by default; types-only validation is sufficient\n * for the steady-state case. */\n validate?: boolean;\n}\n\nexport interface CusfrontClient {\n /** Read-only brand config — pass through from createClient args. */\n readonly brand: BrandConfig | undefined;\n /** Auth resource: login, refresh, current user, logout. */\n readonly auth: AuthResource;\n /** Deposits (money IN via a funder connector): initiate, get, list, refund. */\n readonly deposits: DepositsResource;\n /** Cards (money OUT via an issuer connector): create, get, list, balance. */\n readonly cards: CardsResource;\n /** Wallet balance lookup, per currency. */\n readonly balance: BalanceResource;\n /** Runtime white-label config (`GET /branding`, public): names, logo, wallet label. */\n readonly branding: BrandingResource;\n /** Public blog posts, returned as structured blocks to render in your own style. */\n readonly blog: BlogResource;\n /** The user's announcement channel subscriptions. */\n readonly subscriptions: SubscriptionsResource;\n /** Direct access to the token store (e.g. for an explicit sign-out\n * on Capacitor's lifecycle \"app pausing\" event). */\n readonly tokens: TokenStore;\n}\n\n/**\n * Build a new client. Stateless across calls — multiple clients can\n * coexist (e.g. an admin Cusfront with a different baseUrl than the\n * end-user one). Each gets its own `TokenStore`.\n *\n * `validate: true` is honoured by individual resources that ship\n * matching zod schemas; resources without a schema ignore it.\n */\nexport function createClient(opts: CreateClientOptions): CusfrontClient {\n const tokens = opts.tokenStore ?? pickDefaultStore();\n const fetchImpl = opts.fetch ?? defaultFetch();\n const http = new HttpClient(opts.baseUrl, tokens, fetchImpl);\n\n return {\n brand: opts.brand,\n tokens,\n auth: new AuthResource(http, tokens),\n deposits: new DepositsResource(http),\n cards: new CardsResource(http),\n balance: new BalanceResource(http),\n branding: new BrandingResource(http),\n blog: new BlogResource(http),\n subscriptions: new SubscriptionsResource(http),\n };\n}\n\nfunction pickDefaultStore(): TokenStore {\n if (typeof globalThis !== \"undefined\" && \"localStorage\" in globalThis) {\n return defaultBrowserStore();\n }\n return inMemoryStore();\n}\n\nfunction defaultFetch(): FetchLike {\n if (typeof globalThis !== \"undefined\" && typeof globalThis.fetch === \"function\") {\n // Bind to globalThis so `this` is correct inside the implementation\n // (some polyfills choke on a detached reference).\n return globalThis.fetch.bind(globalThis);\n }\n throw new Error(\n \"@takeal/cusfront-sdk: native fetch is not available in this runtime. \" +\n \"Pass a polyfill via createClient({ fetch }).\",\n );\n}\n","/**\n * `@takeal/cusfront-sdk/telegram` — Telegram Mini App adapter.\n *\n * A Mini App receives a signed `initData` string from the Telegram client\n * (`window.Telegram.WebApp.initData`). This module turns that string into an\n * authenticated SDK client:\n *\n * import { fromTelegramWebApp } from \"@takeal/cusfront-sdk/telegram\";\n * const client = await fromTelegramWebApp({ baseUrl: \"https://api.example.com\" });\n * const me = await client.auth.me(); // me.email_pending? prompt for email\n *\n * Signature validation: the HMAC over `initData` can only be verified with the\n * bot token, which lives on the server. So the **authoritative** check happens\n * server-side at `POST /auth/telegram/exchange`. Here we only do a structural,\n * fail-fast well-formedness check (`hash` + `auth_date` present, not stale)\n * before spending a network round-trip on an obviously-bad payload.\n */\n\nimport {\n createClient,\n type CreateClientOptions,\n type CusfrontClient,\n} from \"./index.js\";\nimport type { JwtIssued } from \"./resources/auth.js\";\n\n/** The Telegram `user` object embedded (URL-encoded JSON) in initData. */\nexport interface TelegramUser {\n id: number;\n first_name?: string;\n last_name?: string;\n username?: string;\n language_code?: string;\n photo_url?: string;\n is_premium?: boolean;\n}\n\n/** Structurally-parsed initData. `raw` is the original string passed to the\n * server verbatim — the server re-derives the HMAC from it, so we never\n * re-serialise. */\nexport interface ParsedInitData {\n raw: string;\n params: Record<string, string>;\n hash?: string;\n auth_date?: number;\n query_id?: string;\n user?: TelegramUser;\n}\n\n/** Thrown by {@link assertWellFormed} when initData is structurally invalid or\n * stale. A signature mismatch is NOT detectable here (no bot token) — that\n * surfaces as a 401 `ApiError` from the exchange call instead. */\nexport class InitDataError extends Error {\n constructor(\n message: string,\n readonly reason:\n | \"empty\"\n | \"missing_hash\"\n | \"missing_auth_date\"\n | \"bad_user\"\n | \"stale\",\n ) {\n super(message);\n this.name = \"InitDataError\";\n }\n}\n\n/** Parse a raw `initData` query string into its fields (best-effort — does\n * not validate). `user` is JSON-decoded when present and parseable. */\nexport function parseInitData(initData: string): ParsedInitData {\n const params: Record<string, string> = {};\n const sp = new URLSearchParams(initData);\n for (const [k, v] of sp.entries()) params[k] = v;\n\n let user: TelegramUser | undefined;\n if (params.user) {\n try {\n user = JSON.parse(params.user) as TelegramUser;\n } catch {\n user = undefined;\n }\n }\n\n const authDateRaw = params.auth_date;\n const auth_date =\n authDateRaw && /^\\d+$/.test(authDateRaw) ? Number(authDateRaw) : undefined;\n\n return {\n raw: initData,\n params,\n ...(params.hash ? { hash: params.hash } : {}),\n ...(auth_date !== undefined ? { auth_date } : {}),\n ...(params.query_id ? { query_id: params.query_id } : {}),\n ...(user ? { user } : {}),\n };\n}\n\nexport interface WellFormedOptions {\n /** Reject initData whose `auth_date` is older than this many seconds.\n * Defaults to 86400 (24h) — match or stay under the server's\n * `auth.telegram.initdata_max_age_secs`. Pass 0 to skip the freshness\n * check client-side (the server still enforces its own window). */\n maxAgeSeconds?: number;\n /** Injectable clock (unix seconds) for testing. Defaults to `Date.now()`. */\n nowUnix?: number;\n}\n\n/** Fail-fast structural check: `hash` present, `auth_date` present + a valid\n * `user`, and (optionally) not stale. Throws {@link InitDataError}. Does NOT\n * verify the HMAC — only the server can. */\nexport function assertWellFormed(\n initData: string,\n opts: WellFormedOptions = {},\n): ParsedInitData {\n if (!initData) throw new InitDataError(\"initData is empty\", \"empty\");\n const parsed = parseInitData(initData);\n if (!parsed.hash)\n throw new InitDataError(\"initData is missing `hash`\", \"missing_hash\");\n if (parsed.auth_date === undefined)\n throw new InitDataError(\n \"initData is missing a valid `auth_date`\",\n \"missing_auth_date\",\n );\n if (!parsed.user || typeof parsed.user.id !== \"number\")\n throw new InitDataError(\n \"initData is missing a valid `user`\",\n \"bad_user\",\n );\n\n const maxAge = opts.maxAgeSeconds ?? 86_400;\n if (maxAge > 0) {\n const now = opts.nowUnix ?? Math.floor(Date.now() / 1000);\n if (now - parsed.auth_date > maxAge)\n throw new InitDataError(\n \"initData is stale (auth_date older than the freshness window)\",\n \"stale\",\n );\n }\n return parsed;\n}\n\nexport interface FromInitDataOptions extends WellFormedOptions {\n /** Skip the client-side well-formedness check and let the server be the\n * sole judge. Default false — the fail-fast check saves a round-trip on\n * obviously-bad input. */\n skipWellFormedCheck?: boolean;\n}\n\n/**\n * Build an authenticated client from a raw `initData` string.\n *\n * 1. (unless skipped) structurally validate the payload — throws\n * {@link InitDataError} on malformed/stale input.\n * 2. exchange it at `POST /auth/telegram/exchange` — the server validates the\n * HMAC; a bad signature throws a 401 `ApiError`.\n * 3. store the returned JWT and return the ready-to-use client.\n *\n * Read `client.auth.me()` (or call `client.auth.exchangeTelegram` directly for\n * the raw session) to check `email_pending` and prompt for an email.\n */\nexport async function fromInitData(\n initData: string,\n config: CreateClientOptions,\n opts: FromInitDataOptions = {},\n): Promise<CusfrontClient> {\n if (!opts.skipWellFormedCheck) assertWellFormed(initData, opts);\n const client = createClient(config);\n await client.auth.exchangeTelegram({ initData });\n return client;\n}\n\n/** Read `window.Telegram.WebApp.initData` if running inside a Telegram Mini\n * App. Returns null when absent or empty (e.g. opened outside Telegram). */\nexport function readWebAppInitData(): string | null {\n const tg = (\n globalThis as unknown as {\n Telegram?: { WebApp?: { initData?: string } };\n }\n ).Telegram;\n const data = tg?.WebApp?.initData;\n return data && data.length > 0 ? data : null;\n}\n\n/**\n * Convenience entry for a Mini App: read `initData` from the Telegram WebApp\n * SDK and exchange it. Throws if not running inside a Telegram Mini App.\n */\nexport async function fromTelegramWebApp(\n config: CreateClientOptions,\n opts: FromInitDataOptions = {},\n): Promise<CusfrontClient> {\n const initData = readWebAppInitData();\n if (!initData)\n throw new InitDataError(\n \"not running inside a Telegram Mini App (window.Telegram.WebApp.initData is empty)\",\n \"empty\",\n );\n return fromInitData(initData, config, opts);\n}\n\n/** Convenience accessor for the typed exchange session (incl. `email_pending`)\n * when you need the envelope rather than just the client. */\nexport type TelegramExchangeSession = JwtIssued;\n"]}
@@ -0,0 +1,105 @@
1
+ import { CreateClientOptions, CusfrontClient } from './index.cjs';
2
+ import { JwtIssued } from './resources/auth.cjs';
3
+ import './http-BkZZZI8K.cjs';
4
+ import './resources/deposits.cjs';
5
+ import './customer-CoxPwe5o.cjs';
6
+ import './resources/cards.cjs';
7
+ import './resources/balance.cjs';
8
+ import './resources/branding.cjs';
9
+ import './resources/blog.cjs';
10
+ import './resources/subscriptions.cjs';
11
+
12
+ /**
13
+ * `@takeal/cusfront-sdk/telegram` — Telegram Mini App adapter.
14
+ *
15
+ * A Mini App receives a signed `initData` string from the Telegram client
16
+ * (`window.Telegram.WebApp.initData`). This module turns that string into an
17
+ * authenticated SDK client:
18
+ *
19
+ * import { fromTelegramWebApp } from "@takeal/cusfront-sdk/telegram";
20
+ * const client = await fromTelegramWebApp({ baseUrl: "https://api.example.com" });
21
+ * const me = await client.auth.me(); // me.email_pending? prompt for email
22
+ *
23
+ * Signature validation: the HMAC over `initData` can only be verified with the
24
+ * bot token, which lives on the server. So the **authoritative** check happens
25
+ * server-side at `POST /auth/telegram/exchange`. Here we only do a structural,
26
+ * fail-fast well-formedness check (`hash` + `auth_date` present, not stale)
27
+ * before spending a network round-trip on an obviously-bad payload.
28
+ */
29
+
30
+ /** The Telegram `user` object embedded (URL-encoded JSON) in initData. */
31
+ interface TelegramUser {
32
+ id: number;
33
+ first_name?: string;
34
+ last_name?: string;
35
+ username?: string;
36
+ language_code?: string;
37
+ photo_url?: string;
38
+ is_premium?: boolean;
39
+ }
40
+ /** Structurally-parsed initData. `raw` is the original string passed to the
41
+ * server verbatim — the server re-derives the HMAC from it, so we never
42
+ * re-serialise. */
43
+ interface ParsedInitData {
44
+ raw: string;
45
+ params: Record<string, string>;
46
+ hash?: string;
47
+ auth_date?: number;
48
+ query_id?: string;
49
+ user?: TelegramUser;
50
+ }
51
+ /** Thrown by {@link assertWellFormed} when initData is structurally invalid or
52
+ * stale. A signature mismatch is NOT detectable here (no bot token) — that
53
+ * surfaces as a 401 `ApiError` from the exchange call instead. */
54
+ declare class InitDataError extends Error {
55
+ readonly reason: "empty" | "missing_hash" | "missing_auth_date" | "bad_user" | "stale";
56
+ constructor(message: string, reason: "empty" | "missing_hash" | "missing_auth_date" | "bad_user" | "stale");
57
+ }
58
+ /** Parse a raw `initData` query string into its fields (best-effort — does
59
+ * not validate). `user` is JSON-decoded when present and parseable. */
60
+ declare function parseInitData(initData: string): ParsedInitData;
61
+ interface WellFormedOptions {
62
+ /** Reject initData whose `auth_date` is older than this many seconds.
63
+ * Defaults to 86400 (24h) — match or stay under the server's
64
+ * `auth.telegram.initdata_max_age_secs`. Pass 0 to skip the freshness
65
+ * check client-side (the server still enforces its own window). */
66
+ maxAgeSeconds?: number;
67
+ /** Injectable clock (unix seconds) for testing. Defaults to `Date.now()`. */
68
+ nowUnix?: number;
69
+ }
70
+ /** Fail-fast structural check: `hash` present, `auth_date` present + a valid
71
+ * `user`, and (optionally) not stale. Throws {@link InitDataError}. Does NOT
72
+ * verify the HMAC — only the server can. */
73
+ declare function assertWellFormed(initData: string, opts?: WellFormedOptions): ParsedInitData;
74
+ interface FromInitDataOptions extends WellFormedOptions {
75
+ /** Skip the client-side well-formedness check and let the server be the
76
+ * sole judge. Default false — the fail-fast check saves a round-trip on
77
+ * obviously-bad input. */
78
+ skipWellFormedCheck?: boolean;
79
+ }
80
+ /**
81
+ * Build an authenticated client from a raw `initData` string.
82
+ *
83
+ * 1. (unless skipped) structurally validate the payload — throws
84
+ * {@link InitDataError} on malformed/stale input.
85
+ * 2. exchange it at `POST /auth/telegram/exchange` — the server validates the
86
+ * HMAC; a bad signature throws a 401 `ApiError`.
87
+ * 3. store the returned JWT and return the ready-to-use client.
88
+ *
89
+ * Read `client.auth.me()` (or call `client.auth.exchangeTelegram` directly for
90
+ * the raw session) to check `email_pending` and prompt for an email.
91
+ */
92
+ declare function fromInitData(initData: string, config: CreateClientOptions, opts?: FromInitDataOptions): Promise<CusfrontClient>;
93
+ /** Read `window.Telegram.WebApp.initData` if running inside a Telegram Mini
94
+ * App. Returns null when absent or empty (e.g. opened outside Telegram). */
95
+ declare function readWebAppInitData(): string | null;
96
+ /**
97
+ * Convenience entry for a Mini App: read `initData` from the Telegram WebApp
98
+ * SDK and exchange it. Throws if not running inside a Telegram Mini App.
99
+ */
100
+ declare function fromTelegramWebApp(config: CreateClientOptions, opts?: FromInitDataOptions): Promise<CusfrontClient>;
101
+ /** Convenience accessor for the typed exchange session (incl. `email_pending`)
102
+ * when you need the envelope rather than just the client. */
103
+ type TelegramExchangeSession = JwtIssued;
104
+
105
+ export { type FromInitDataOptions, InitDataError, type ParsedInitData, type TelegramExchangeSession, type TelegramUser, type WellFormedOptions, assertWellFormed, fromInitData, fromTelegramWebApp, parseInitData, readWebAppInitData };
@@ -0,0 +1,105 @@
1
+ import { CreateClientOptions, CusfrontClient } from './index.js';
2
+ import { JwtIssued } from './resources/auth.js';
3
+ import './http-BkZZZI8K.js';
4
+ import './resources/deposits.js';
5
+ import './customer-CoxPwe5o.js';
6
+ import './resources/cards.js';
7
+ import './resources/balance.js';
8
+ import './resources/branding.js';
9
+ import './resources/blog.js';
10
+ import './resources/subscriptions.js';
11
+
12
+ /**
13
+ * `@takeal/cusfront-sdk/telegram` — Telegram Mini App adapter.
14
+ *
15
+ * A Mini App receives a signed `initData` string from the Telegram client
16
+ * (`window.Telegram.WebApp.initData`). This module turns that string into an
17
+ * authenticated SDK client:
18
+ *
19
+ * import { fromTelegramWebApp } from "@takeal/cusfront-sdk/telegram";
20
+ * const client = await fromTelegramWebApp({ baseUrl: "https://api.example.com" });
21
+ * const me = await client.auth.me(); // me.email_pending? prompt for email
22
+ *
23
+ * Signature validation: the HMAC over `initData` can only be verified with the
24
+ * bot token, which lives on the server. So the **authoritative** check happens
25
+ * server-side at `POST /auth/telegram/exchange`. Here we only do a structural,
26
+ * fail-fast well-formedness check (`hash` + `auth_date` present, not stale)
27
+ * before spending a network round-trip on an obviously-bad payload.
28
+ */
29
+
30
+ /** The Telegram `user` object embedded (URL-encoded JSON) in initData. */
31
+ interface TelegramUser {
32
+ id: number;
33
+ first_name?: string;
34
+ last_name?: string;
35
+ username?: string;
36
+ language_code?: string;
37
+ photo_url?: string;
38
+ is_premium?: boolean;
39
+ }
40
+ /** Structurally-parsed initData. `raw` is the original string passed to the
41
+ * server verbatim — the server re-derives the HMAC from it, so we never
42
+ * re-serialise. */
43
+ interface ParsedInitData {
44
+ raw: string;
45
+ params: Record<string, string>;
46
+ hash?: string;
47
+ auth_date?: number;
48
+ query_id?: string;
49
+ user?: TelegramUser;
50
+ }
51
+ /** Thrown by {@link assertWellFormed} when initData is structurally invalid or
52
+ * stale. A signature mismatch is NOT detectable here (no bot token) — that
53
+ * surfaces as a 401 `ApiError` from the exchange call instead. */
54
+ declare class InitDataError extends Error {
55
+ readonly reason: "empty" | "missing_hash" | "missing_auth_date" | "bad_user" | "stale";
56
+ constructor(message: string, reason: "empty" | "missing_hash" | "missing_auth_date" | "bad_user" | "stale");
57
+ }
58
+ /** Parse a raw `initData` query string into its fields (best-effort — does
59
+ * not validate). `user` is JSON-decoded when present and parseable. */
60
+ declare function parseInitData(initData: string): ParsedInitData;
61
+ interface WellFormedOptions {
62
+ /** Reject initData whose `auth_date` is older than this many seconds.
63
+ * Defaults to 86400 (24h) — match or stay under the server's
64
+ * `auth.telegram.initdata_max_age_secs`. Pass 0 to skip the freshness
65
+ * check client-side (the server still enforces its own window). */
66
+ maxAgeSeconds?: number;
67
+ /** Injectable clock (unix seconds) for testing. Defaults to `Date.now()`. */
68
+ nowUnix?: number;
69
+ }
70
+ /** Fail-fast structural check: `hash` present, `auth_date` present + a valid
71
+ * `user`, and (optionally) not stale. Throws {@link InitDataError}. Does NOT
72
+ * verify the HMAC — only the server can. */
73
+ declare function assertWellFormed(initData: string, opts?: WellFormedOptions): ParsedInitData;
74
+ interface FromInitDataOptions extends WellFormedOptions {
75
+ /** Skip the client-side well-formedness check and let the server be the
76
+ * sole judge. Default false — the fail-fast check saves a round-trip on
77
+ * obviously-bad input. */
78
+ skipWellFormedCheck?: boolean;
79
+ }
80
+ /**
81
+ * Build an authenticated client from a raw `initData` string.
82
+ *
83
+ * 1. (unless skipped) structurally validate the payload — throws
84
+ * {@link InitDataError} on malformed/stale input.
85
+ * 2. exchange it at `POST /auth/telegram/exchange` — the server validates the
86
+ * HMAC; a bad signature throws a 401 `ApiError`.
87
+ * 3. store the returned JWT and return the ready-to-use client.
88
+ *
89
+ * Read `client.auth.me()` (or call `client.auth.exchangeTelegram` directly for
90
+ * the raw session) to check `email_pending` and prompt for an email.
91
+ */
92
+ declare function fromInitData(initData: string, config: CreateClientOptions, opts?: FromInitDataOptions): Promise<CusfrontClient>;
93
+ /** Read `window.Telegram.WebApp.initData` if running inside a Telegram Mini
94
+ * App. Returns null when absent or empty (e.g. opened outside Telegram). */
95
+ declare function readWebAppInitData(): string | null;
96
+ /**
97
+ * Convenience entry for a Mini App: read `initData` from the Telegram WebApp
98
+ * SDK and exchange it. Throws if not running inside a Telegram Mini App.
99
+ */
100
+ declare function fromTelegramWebApp(config: CreateClientOptions, opts?: FromInitDataOptions): Promise<CusfrontClient>;
101
+ /** Convenience accessor for the typed exchange session (incl. `email_pending`)
102
+ * when you need the envelope rather than just the client. */
103
+ type TelegramExchangeSession = JwtIssued;
104
+
105
+ export { type FromInitDataOptions, InitDataError, type ParsedInitData, type TelegramExchangeSession, type TelegramUser, type WellFormedOptions, assertWellFormed, fromInitData, fromTelegramWebApp, parseInitData, readWebAppInitData };