@takeal/cusfront-sdk 0.5.0 → 0.6.1

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 (65) hide show
  1. package/CHANGELOG.md +49 -2
  2. package/README.md +168 -3
  3. package/dist/analytics.cjs +28 -7
  4. package/dist/analytics.cjs.map +1 -1
  5. package/dist/analytics.js +28 -7
  6. package/dist/analytics.js.map +1 -1
  7. package/dist/{cards-Ba1wZttb.d.ts → cards-CF3-He2x.d.ts} +144 -20
  8. package/dist/{cards-B_aNY35J.d.cts → cards-qfHz6xZY.d.cts} +144 -20
  9. package/dist/{deposits-DScyT_D9.d.ts → deposits-B2LBe2k1.d.ts} +71 -8
  10. package/dist/{deposits-BEc8U80M.d.cts → deposits-ZjT_btgi.d.cts} +71 -8
  11. package/dist/index.cjs +92 -50
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.cts +6 -6
  14. package/dist/index.d.ts +6 -6
  15. package/dist/index.js +92 -50
  16. package/dist/index.js.map +1 -1
  17. package/dist/react/index.cjs +2 -8
  18. package/dist/react/index.cjs.map +1 -1
  19. package/dist/react/index.d.cts +2 -2
  20. package/dist/react/index.d.ts +2 -2
  21. package/dist/react/index.js +2 -8
  22. package/dist/react/index.js.map +1 -1
  23. package/dist/resources/attribution.cjs.map +1 -1
  24. package/dist/resources/attribution.js.map +1 -1
  25. package/dist/resources/auth.cjs.map +1 -1
  26. package/dist/resources/auth.js.map +1 -1
  27. package/dist/resources/cards.cjs +41 -28
  28. package/dist/resources/cards.cjs.map +1 -1
  29. package/dist/resources/cards.d.cts +1 -1
  30. package/dist/resources/cards.d.ts +1 -1
  31. package/dist/resources/cards.js +41 -28
  32. package/dist/resources/cards.js.map +1 -1
  33. package/dist/resources/deposits.cjs +8 -5
  34. package/dist/resources/deposits.cjs.map +1 -1
  35. package/dist/resources/deposits.d.cts +2 -2
  36. package/dist/resources/deposits.d.ts +2 -2
  37. package/dist/resources/deposits.js +8 -5
  38. package/dist/resources/deposits.js.map +1 -1
  39. package/dist/resources/devices.cjs +3 -1
  40. package/dist/resources/devices.cjs.map +1 -1
  41. package/dist/resources/devices.js +3 -1
  42. package/dist/resources/devices.js.map +1 -1
  43. package/dist/resources/documents.cjs +3 -1
  44. package/dist/resources/documents.cjs.map +1 -1
  45. package/dist/resources/documents.js +3 -1
  46. package/dist/resources/documents.js.map +1 -1
  47. package/dist/resources/funding-options.cjs.map +1 -1
  48. package/dist/resources/funding-options.d.cts +2 -2
  49. package/dist/resources/funding-options.d.ts +2 -2
  50. package/dist/resources/funding-options.js.map +1 -1
  51. package/dist/resources/history.cjs +3 -1
  52. package/dist/resources/history.cjs.map +1 -1
  53. package/dist/resources/history.js +3 -1
  54. package/dist/resources/history.js.map +1 -1
  55. package/dist/resources/push.cjs +3 -1
  56. package/dist/resources/push.cjs.map +1 -1
  57. package/dist/resources/push.js +3 -1
  58. package/dist/resources/push.js.map +1 -1
  59. package/dist/telegram.cjs +67 -53
  60. package/dist/telegram.cjs.map +1 -1
  61. package/dist/telegram.d.cts +2 -2
  62. package/dist/telegram.d.ts +2 -2
  63. package/dist/telegram.js +67 -53
  64. package/dist/telegram.js.map +1 -1
  65. package/package.json +12 -5
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/resources/cards.ts","../../src/resources/deposits.ts"],"names":[],"mappings":";AA0PO,SAAS,gBACd,KAAA,EACyB;AACzB,EAAA,MAAM;AAAA,IACJ,SAAA;AAAA,IACA,IAAA;AAAA,IACA,QAAA;AAAA,IACA,QAAA;AAAA,IACA,WAAA;AAAA,IACA,SAAA;AAAA,IACA,cAAA,EAAgB,QAAA;AAAA,IAChB,GAAG;AAAA,GACL,GAAI,KAAA;AACJ,EAAA,MAAM,IAAA,GAAgC,EAAE,GAAG,IAAA,EAAK;AAChD,EAAA,IAAI,SAAA,KAAc,MAAA,EAAW,IAAA,CAAK,YAAY,CAAA,GAAI,SAAA;AAClD,EAAA,IAAI,IAAA,KAAS,MAAA,E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;AAAA,EACxE;AAAA;AAAA,EAGA,MAAM,IAAA,GAA2B;AAC/B,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,GAAA,CAAe,cAAc,CAAA;AAAA,EAChD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,MAAA,CACJ,SAAA,EACA,KAAA,EACiB;AACjB,IAAA,MAAM,EAAE,cAAA,EAAgB,GAAG,IAAA,EAAK,GAAI,KAAA;AACpC,IAAA,OAAO,KAAK,IAAA,CAAK,IAAA;AAAA,MACf,CAAA,aAAA,EAAgB,kBAAA,CAAmB,SAAS,CAAC,CAAA,QAAA,CAAA;AAAA,MAC7C,EAAE,MAAM,cAAA;AAAe,KACzB;AAAA,EACF;AACF","file":"deposits.js","sourcesContent":["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 * GET /card-products → catalog (public, before sign-in)\n * GET /me/card-products → listProducts (the catalog, personal price)\n * GET /me/card-products/{id} → getProduct\n * GET /me/cards/{id}/topup → topUpTerms\n * POST /me/cards/{id}/topup → topUp\n * POST /me/cards → create\n * GET /me/cards → list (most recent first)\n * GET /me/cards/{id} → get\n * PATCH /me/cards/{id} → update (name, design)\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}/transfer → transfer (to another of their cards)\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 design: the artwork a card is shown with. `image_url` is the front,\n * `image_url_back` the back; both are either absolute URLs or paths relative\n * to the API origin (the deployment's default design is\n * `/card-designs/default.svg`, its back `/card-designs/default.svg?side=back`)\n * — pass them through `client.assetUrl()` before rendering. `image_url_back`\n * is `null` or absent for a one-sided design: show the front on both sides.\n * The picture is in the proportions of a plastic card (1586×1000) and draws\n * no chip or card data; the client renders the number, name and expiry on\n * top. `id` is `null` for the deployment default, which is rendered from the\n * branding settings.\n */\nexport interface CardDesignRef {\n id: string | null;\n name?: string;\n image_url: string;\n image_url_back?: string | null;\n}\n\n/**\n * What issuing a card costs the caller. `amount` is the price after the\n * user's subscription discount; `base_amount` is the list price and\n * `discount_bps` the discount in basis points (1000 = 10 %). `label` is the\n * operator's wording for the fee line (\"Card issuance\").\n */\nexport interface CardProductPrice {\n /** What the user pays, decimal string, after their subscription discount. */\n amount: string;\n /**\n * ISO 4217 code: the currency the buyer pays in. A signed-in user sees\n * their wallet currency, converted the way issuance will charge it; the\n * public catalog shows the currency the operator priced the card in. It\n * is not necessarily the currency the card is held in (`CardProduct.currency`).\n */\n currency: string;\n /** Wording for the fee line, e.g. \"Card issuance\". */\n label: string;\n /** The list price before the discount, decimal string, in the same currency. */\n base_amount: string;\n /** Discount applied, in basis points (1000 = 10%). */\n discount_bps: number;\n}\n\n/**\n * A card the user can order, as listed by `GET /me/card-products`. The id is\n * opaque — it names a product, never a provider. The list comes in the\n * order the operator arranged the storefront; `is_default` marks the\n * product issued when none is chosen, wherever it sits. `designs` is the\n * set the user may pick from (may be empty when only the default applies);\n * `design` is what the card gets when no choice is made. `price` is `null`\n * for a free card. `features` is an operator-defined object (scheme, wallet\n * support, load limits, …) with no fixed keys.\n */\nexport interface CardProduct {\n id: string;\n name: string;\n /** One line under the name on the tile, or `null`. */\n tagline: string | null;\n description: string | null;\n /** Selling points to list on the product card, in order. May be empty. */\n benefits: string[];\n /**\n * Picture for the product tile, absolute URL, or `null`: show the card\n * design (`design.image_url`) then.\n */\n tile_image_url: string | null;\n card_type: CardType;\n currency: string | null;\n features: Record<string, unknown>;\n design: CardDesignRef;\n designs: CardDesignRef[];\n price: CardProductPrice | null;\n /**\n * The balance a new card comes with, already included in `price`; `null`\n * when the card starts empty and is funded with `topUp()` afterwards.\n */\n starting_balance: CardBalance | null;\n /** True for the product the deployment issues when none is chosen. */\n is_default: boolean;\n}\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 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 /** The balance the card was issued with, decimal string; `null` or `\"0\"` for a card issued empty. */\n initial_amount: string | null;\n currency: string;\n failure_reason: string | null;\n /** The name the user gave the card, or `null`. */\n name: string | null;\n /** The artwork the card is shown with. Always present. */\n design: CardDesignRef;\n /** The product the card was issued from; `null` for cards issued without one. */\n product: { id: string; name: string } | null;\n created_at: string;\n updated_at: string;\n /** Only on the result of `create`, when bonuses paid part of the price. */\n bonus?: IssuanceBonus;\n}\n\n/** How bonuses changed a new card's price (\"was / now\"). Decimal strings in `currency`. */\nexport interface IssuanceBonus {\n /** Bonuses used. */\n units: string;\n /** The price before bonuses (\"was\"). */\n price: string;\n /** What the bonuses covered. */\n covered: string;\n /** What the wallet paid (\"now\"). */\n paid: string;\n currency: string;\n}\n\nexport interface CreateCardInput {\n /**\n * A product id from {@link CardsResource.listProducts}. Sent as\n * `product_id`. When given, `type` and `issuer_slug` may be omitted; when\n * both are given they must agree with the product (400 `product_mismatch`).\n * Unknown, disabled or hidden product → 400 `unknown_product`.\n */\n productId?: string;\n /** A name for the card, 1–40 characters. Sent as `name`. */\n name?: string;\n /**\n * One of the product's `designs`. Sent as `design_id`. `null` or omitted\n * picks the product's default design; a design outside the product's set →\n * 400 `design_not_allowed`.\n */\n designId?: string | null;\n /**\n * `prepaid` (the only fully-wired type today), `credit`, or `gift`.\n * Optional when `productId` is given, required otherwise.\n */\n type?: CardType;\n /**\n * @deprecated Ignored since 0.3.21. A card is issued for its product price;\n * the balance it starts with, if the product includes one, is part of that\n * price (see `CardProduct.starting_balance`). Money is added afterwards\n * with {@link CardsResource.topUp}. The field is no longer sent.\n */\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 * Pay part of the price with bonuses. Sent as `use_bonus`. On by default\n * whenever the user has bonuses; `false` pays it all from the wallet.\n */\n useBonus?: boolean;\n /** The most bonuses to use, decimal string. Sent as `bonus_amount`. */\n bonusAmount?: string;\n /**\n * A promo code for the card's price. Sent as `promo_code`. Its discount\n * comes off before bonuses; `client.codes.validate` shows it first. A code\n * that can't be used fails the request with 400 `promo_code_*` and the\n * reason. Without one, the code the user signed up with applies when it\n * covers cards. Ignored inside `deposits.initiate({ issue_card })`: send\n * `promo_code` on the top-up there.\n */\n promoCode?: string;\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/**\n * The wire body of a card request: the camelCase fields renamed to what\n * the API reads. Shared by {@link CardsResource.create} and the\n * `issue_card` block of `deposits.initiate`.\n */\nexport function cardRequestBody(\n input: Omit<CreateCardInput, \"idempotencyKey\" | \"currency\"> & { currency?: string },\n): Record<string, unknown> {\n const {\n productId,\n name,\n designId,\n useBonus,\n bonusAmount,\n promoCode,\n initial_amount: _ignored,\n ...rest\n } = input;\n const body: Record<string, unknown> = { ...rest };\n if (productId !== undefined) body[\"product_id\"] = productId;\n if (name !== undefined) body[\"name\"] = name;\n if (designId !== undefined) body[\"design_id\"] = designId;\n if (useBonus !== undefined) body[\"use_bonus\"] = useBonus;\n if (bonusAmount !== undefined) body[\"bonus_amount\"] = bonusAmount;\n if (promoCode !== undefined) body[\"promo_code\"] = promoCode;\n return body;\n}\n\n/** Remaining balance of a prepaid card. */\nexport interface CardBalance {\n amount: string;\n currency: string;\n}\n\n/** What a top-up of a card can be right now, from `GET /me/cards/{id}/topup`. */\nexport interface TopUpTerms {\n /** Whether the card can be topped up at this moment. */\n available: boolean;\n /** Why not, in plain words, when `available` is false. */\n reason: string | null;\n /** Currency top-ups are made in: the card's. */\n currency: string;\n /** What the wallet holds right now, in the wallet's currency. */\n wallet_available: CardBalance;\n /** Smallest single top-up the product allows, or `null` for no floor. */\n min: CardBalance | null;\n /** Largest single top-up the product allows, or `null` for no cap. */\n max: CardBalance | null;\n}\n\nexport interface TopUpInput {\n /** Amount to add, decimal string, in the card's currency. */\n amount: string;\n /**\n * Required. Same key + same amount replays the first outcome; same key +\n * different amount is 409. Use a stable UUID per attempt so a retried\n * network call cannot move the money twice.\n */\n idempotencyKey: string;\n}\n\n/** One top-up attempt as the API records it. */\nexport interface CardTopUp {\n id: string;\n card_id: string;\n status: \"pending\" | \"confirmed\" | \"failed\";\n /** What landed on the card, decimal string, in `currency`. */\n amount: string;\n currency: string;\n /** What the wallet paid, decimal string, in `wallet_currency`. */\n wallet_amount: string;\n wallet_currency: string;\n failure_reason: string | null;\n created_at: string;\n updated_at: string;\n}\n\n/** A completed top-up with the state to redraw: card, its balance, the wallet. */\nexport interface TopUpResult {\n topup: CardTopUp;\n card: Card;\n card_balance: CardBalance;\n wallet: CardBalance;\n}\n\n/** Fields a user can change on their own card. Omitted fields are left as they are. */\nexport interface UpdateCardInput {\n /** New name, 1–40 characters. Sent as `name`. */\n name?: string;\n /**\n * New design (one of the product's `designs`), or `null` for the product's\n * default. Sent as `design_id`.\n */\n designId?: string | null;\n}\n\n/**\n * Kept for callers written against 0.3.x: the API no longer asks for a\n * password or a code on reveal, the session is enough. Both fields are\n * ignored and will be dropped in the next major.\n * @deprecated\n */\nexport interface RevealCardInput {\n password?: string;\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 /**\n * The address the card is registered at — what a merchant's checkout asks\n * for, and the postal code some of them decline a payment over. Absent\n * when the deployment has not set one.\n */\n billing_address?: BillingAddress;\n /** Display window before the client should auto-clear the data. */\n expires_in_seconds: number;\n}\n\n/** Postal address a card is registered at. Which parts exist depends on the country. */\nexport interface BillingAddress {\n line1?: string;\n line2?: string;\n city?: string;\n state?: string;\n postal_code?: string;\n country?: string;\n}\n\n/** What to move, and the key that makes a retry safe. */\nexport interface TransferInput {\n /** The card the money lands on. Must be the caller's, and of the same kind and currency. */\n toCardId: string;\n /** Amount to move, decimal string, in the cards' currency. */\n amount: string;\n /**\n * Required. The same key with the same body replays the first outcome; a\n * different body on the same key is 409.\n */\n idempotencyKey: string;\n}\n\n/** One transfer attempt as the API records it. */\nexport interface CardTransfer {\n id: string;\n from_card_id: string;\n to_card_id: string;\n /**\n * `confirmed` — the money is on the other card. `on_wallet` — it came off\n * the first card but the second did not take it, so it is on the wallet\n * and `failure_reason` says so in words. `pending` / `failed` otherwise.\n */\n status: \"pending\" | \"confirmed\" | \"on_wallet\" | \"failed\";\n amount: string;\n currency: string;\n failure_reason: string | null;\n created_at: string;\n updated_at: string;\n}\n\n/** A finished transfer with the balances to redraw both cards and the wallet. */\nexport interface TransferResult {\n transfer: CardTransfer;\n from_balance: CardBalance;\n to_balance: CardBalance;\n /** Holds the money when `transfer.status` is `on_wallet`. */\n wallet: CardBalance;\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, ...card } = input;\n return this.http.post<Card>(\"/me/cards\", {\n body: cardRequestBody(card),\n idempotencyKey,\n });\n }\n\n /**\n * The cards the caller can order, in the order the storefront shows them\n * (`is_default` marks the one issued when none is chosen). Each item\n * carries its product card (name, tagline, benefits, tile picture),\n * artwork, and the issuance price after the caller's subscription\n * discount, in the caller's wallet currency. Pass an item's `id` as\n * `productId` to {@link create}.\n */\n async listProducts(): Promise<CardProduct[]> {\n return this.http.get<CardProduct[]>(\"/me/card-products\");\n }\n\n /** One product from the catalog. 404 when unknown, disabled or hidden. */\n async getProduct(id: string): Promise<CardProduct> {\n return this.http.get<CardProduct>(\n `/me/card-products/${encodeURIComponent(id)}`,\n );\n }\n\n /**\n * The public catalog: the same products, order and default as\n * {@link listProducts}, but readable before sign-in, for a landing page or\n * the cabinet's first screen. Prices are list prices (`discount_bps` is\n * always 0); once the user is signed in, {@link listProducts} shows what\n * they pay. The API lets caches keep this response for a minute.\n */\n async catalog(): Promise<CardProduct[]> {\n return this.http.get<CardProduct[]>(\"/card-products\");\n }\n\n /**\n * Rename the caller's own card or change its design. Resolves to the\n * updated card. 404 if the card isn't the caller's; 400 `invalid_name` /\n * `design_not_allowed` on a bad value.\n */\n async update(id: string, input: UpdateCardInput): Promise<Card> {\n const body: Record<string, unknown> = {};\n if (input.name !== undefined) body[\"name\"] = input.name;\n if (input.designId !== undefined) body[\"design_id\"] = input.designId;\n return this.http.patch<Card>(`/me/cards/${encodeURIComponent(id)}`, {\n body,\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 * What a top-up of this card can be right now: whether it is possible, the\n * currency, the wallet balance, and the product's floor and cap for one\n * top-up. Read it before drawing the form. 404 if the card isn't the caller's.\n */\n async topUpTerms(id: string): Promise<TopUpTerms> {\n return this.http.get<TopUpTerms>(`/me/cards/${encodeURIComponent(id)}/topup`);\n }\n\n /**\n * Move money from the wallet onto the caller's own card. The wallet is\n * debited first, then the card's provider loads the card; if the provider\n * refuses, the money is back on the wallet and the error says so. Resolves\n * to the card, its new balance and the wallet balance, so no second call\n * is needed. Errors carry a sentence the user can read: 400 outside the\n * floor or cap · 402 not enough in the wallet · 404 not the caller's card ·\n * 409 card frozen, closed or still being issued · 501 provider can't top\n * up · 502/503 provider declined or unreachable (wallet untouched).\n */\n async topUp(id: string, input: TopUpInput): Promise<TopUpResult> {\n const { idempotencyKey, amount } = input;\n return this.http.post<TopUpResult>(`/me/cards/${encodeURIComponent(id)}/topup`, {\n body: { amount },\n idempotencyKey,\n });\n }\n\n /**\n * Move money from one of the caller's cards to another. Both must be\n * theirs, active, in the same currency and of the same kind. The money\n * travels through the wallet one leg at a time: when the second leg does\n * not go through, the call still resolves, `transfer.status` is\n * `on_wallet` and the money is on the wallet — never between two cards.\n * Errors carry a sentence the user can read: 400 the same card twice,\n * different currencies or different kinds · 402 the card holds less than\n * that · 404 one of the cards isn't theirs · 409 a card is frozen, closed\n * or still being issued, or the key was reused with a different body ·\n * 501/502/503 the provider cannot or will not move it.\n */\n async transfer(fromCardId: string, input: TransferInput): Promise<TransferResult> {\n const { toCardId, amount, idempotencyKey } = input;\n return this.http.post<TransferResult>(\n `/me/cards/${encodeURIComponent(fromCardId)}/transfer`,\n { body: { to_card_id: toCardId, amount }, idempotencyKey },\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. The signed-in\n * session is all the API asks for; the call is rate-limited and audited\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>(`/me/cards/${encodeURIComponent(id)}/reveal`);\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\";\nimport type { CustomerInfo } from \"../types/customer.js\";\nimport { cardRequestBody, type CreateCardInput } from \"./cards.js\";\nimport type { DepositTarget, FunderMode } from \"./funding-options.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, or one of their cards straight away, past the wallet\n * (`card_id`, or `issue_card` for a new card). Which of the two a\n * deployment allows is in `client.fundingOptions.list()`. Mirrors the\n * 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 currency credited. */\n currency: string;\n /**\n * Quote a top-up of this card: credited in the card's currency. Pass the\n * same `card_id` to `initiate()`.\n */\n card_id?: string;\n /**\n * Quote into this currency instead of the wallet's: the currency of a\n * card issued with the top-up (`issue_card`). Ignored with `card_id`.\n */\n target_currency?: string;\n}\n\n/** How far a top-up meant for a card has got. */\nexport type CardLoadStatus = \"pending\" | \"succeeded\" | \"failed\";\n\n/**\n * A card to issue with the top-up: the fields of `cards.create` without\n * its idempotency key (the deposit's covers both). The card's price is\n * paid from the top-up and the rest becomes its starting balance.\n */\nexport type IssueCardInput = Omit<CreateCardInput, \"idempotencyKey\" | \"currency\"> & {\n /** Optional with `productId`: the product names the 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 /** Bonuses added on top of the top-up, when any were. */\n bonus_units?: string | null;\n /** What those bonuses added to the wallet, in the credited currency. */\n bonus_value?: string | null;\n /** The promo code the top-up was made with; its discount came off the commission. */\n promo_code?: string | null;\n /** Where the money goes. Older deployments leave it out: the wallet. */\n target?: DepositTarget;\n /** For a top-up onto a card: the card. */\n card_id?: string | null;\n /** The funding connector's mode when the top-up was made. */\n funder_mode?: FunderMode | null;\n /** True when the card was issued with this top-up. */\n issues_card?: boolean;\n /**\n * For a top-up onto a card: `pending` until the card provider has loaded\n * the card, then `succeeded` or `failed`. Show the top-up as done only\n * once it is `succeeded`, or once `returned_to_wallet_at` is set.\n */\n card_load_status?: CardLoadStatus | null;\n /** Why the card could not take it, when `card_load_status` is `failed`. */\n card_load_error?: string | null;\n /** What went towards the card, in its currency, bonuses included. */\n card_amount?: string | null;\n /** The commission taken from a top-up onto a card, in the card's currency. */\n card_commission?: string | null;\n /** The money part of the price of a card issued with the top-up. */\n issue_fee?: string | null;\n /** The bonus part of that price. */\n issue_bonus_units?: string | null;\n issue_bonus_value?: string | null;\n card_loaded_at?: string | null;\n /**\n * Set when the card could not take the top-up and the money went to the\n * wallet instead (funding connectors in `mixed` mode). The user is told.\n */\n returned_to_wallet_at?: 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 /**\n * Passed to the funding connector and stored with the deposit. Two keys\n * work across connectors: `return_url`, where the provider sends the user\n * back after a 3-D Secure step (pair it with `redirect_required`), and on\n * test deployments with the mock funder `mock_scenario`, which picks the\n * outcome: `happy` (confirmed at once, the default), `pending` (confirmed\n * about 15 s later), `redirect` (a hosted page where the user approves or\n * declines) or `fail`.\n */\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 * Add bonuses on top of the top-up: the user pays `amount`, the wallet\n * gets `amount` plus what the bonuses add. On by default whenever the\n * user has bonuses that can go to a top-up (only ones that came with a\n * payment can); `false` tops up without them.\n */\n use_bonus?: boolean;\n /** The most bonuses to add, decimal string. Omit to add as many as allowed. */\n bonus_amount?: string;\n /**\n * Top up this card instead of the wallet. It must be the user's, active\n * and prepaid. A funding connector that tops up the wallet only answers\n * 400 `target_not_allowed`; one that tops up cards only needs `card_id`\n * or `issue_card`. Paying in another currency than the card's needs a\n * quote made with the same `card_id`.\n */\n card_id?: string;\n /**\n * Issue a new card and put this top-up on it. The card shows up as\n * `pending_payment` and is issued once the top-up is confirmed; if the\n * top-up fails, so does the card. Too small to cover the price → 400\n * `amount_too_small`. Not together with `card_id`.\n */\n issue_card?: IssueCardInput;\n /**\n * A promo code for this top-up, to the wallet or to a card. Its discount\n * comes off the commission; bonuses or a gift that come with the code\n * arrive once the top-up is confirmed. A code that can't be used fails the\n * request with 400 `promo_code_*` and the reason. `client.codes.validate`\n * checks it first.\n */\n promo_code?: 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 already in the currency they\n * credit (the wallet's, or the card's with `card_id`) need no quote (the\n * 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, issue_card, ...rest } = input;\n const body: Record<string, unknown> = { ...rest };\n if (issue_card !== undefined) body[\"issue_card\"] = cardRequestBody(issue_card);\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"]}
1
+ {"version":3,"sources":["../../src/resources/cards.ts","../../src/resources/deposits.ts"],"names":[],"mappings":";AAsSO,SAAS,gBACd,KAAA,EACyB;AACzB,EAAA,MAAM;AAAA,IACJ,SAAA;AAAA,IACA,IAAA;AAAA,IACA,QAAA;AAAA,IACA,QAAA;AAAA,IACA,WAAA;AAAA,IACA,SAAA;AAAA,IACA,cAAA,EA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AI,KAAA;AAChD,IAAA,MAAM,IAAA,GAAgC,EAAE,GAAG,IAAA,EAAK;AAChD,IAAA,IAAI,eAAe,MAAA,EAAW,IAAA,CAAK,YAAY,CAAA,GAAI,gBAAgB,UAAU,CAAA;AAC7E,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,IAAA,CAAc,cAAA,EAAgB;AAAA,MAC7C,IAAA;AAAA,MACA;AAAA,KACD,CAAA;AAAA,EACH;AAAA;AAAA,EAGA,MAAM,IAAI,EAAA,EAA8B;AACtC,IAAA,OAAO,KAAK,IAAA,CAAK,GAAA,CAAa,gBAAgB,kBAAA,CAAmB,EAAE,CAAC,CAAA,CAAE,CAAA;AAAA,EACxE;AAAA;AAAA,EAGA,MAAM,IAAA,GAA2B;AAC/B,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,GAAA,CAAe,cAAc,CAAA;AAAA,EAChD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,MAAA,CAAO,SAAA,EAAmB,KAAA,EAAkD;AAChF,IAAA,MAAM,EAAE,cAAA,EAAgB,GAAG,IAAA,EAAK,GAAI,KAAA;AACpC,IAAA,OAAO,KAAK,IAAA,CAAK,IAAA,CAAa,gBAAgB,kBAAA,CAAmB,SAAS,CAAC,CAAA,QAAA,CAAA,EAAY;AAAA,MACrF,IAAA;AAAA,MACA;AAAA,KACD,CAAA;AAAA,EACH;AACF","file":"deposits.js","sourcesContent":["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 * GET /card-products → catalog (public, before sign-in)\n * GET /me/card-products → listProducts (the catalog, personal price)\n * GET /me/card-products/{id} → getProduct\n * GET /me/cards/{id}/topup → topUpTerms\n * POST /me/cards/{id}/topup → topUp\n * POST /me/cards → create\n * GET /me/cards → list (most recent first)\n * GET /me/cards/{id} → get\n * PATCH /me/cards/{id} → update (name, design)\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}/transfer → transfer (to another of their cards)\n * POST /me/cards/{id}/terminate → terminate (one-way)\n * POST /me/cards/{id}/reveal → reveal (the numbers, or a provider page)\n * POST /me/cards/{id}/pin → setPin (physical cards)\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 * 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`: the row exists but the issuance fee has not been\n * paid yet; the provider has not been called and nothing is visible.\n * - `pending`: the issuer accepted the order and has not issued the card\n * yet. The price is charged. Show the card as \"being issued\" with no\n * numbers; it becomes `active` on its own, or `failed` with the price\n * back on the wallet. Some issuers take minutes, some a day.\n * - `active`, `frozen`: the usual states. Read `status_source` before\n * offering to unfreeze.\n * - `terminating`: the holder (or the issuer) closed the card and the\n * issuer has not finished: the balance comes back to the wallet when it\n * does. Show it as closing; no actions apply.\n * - `terminated`, `redeemed`, `failed`: final.\n */\nexport type CardStatus =\n | \"pending_payment\"\n | \"pending\"\n | \"active\"\n | \"frozen\"\n | \"terminating\"\n | \"terminated\"\n | \"redeemed\"\n | \"failed\";\n\n/**\n * Who made the card's last status change. `provider` on a `frozen` card\n * means the issuer froze it (a risk check, a lost-card report): the holder\n * cannot unfreeze it, so do not offer the button; say the freeze is lifted\n * through the issuer's support. `holder` and `operator` freezes are undone\n * with `unfreeze()` as usual.\n */\nexport type CardStatusSource = \"holder\" | \"operator\" | \"provider\";\n\n/** `virtual` cards show their numbers in the app; `physical` cards are plastic and have a PIN. */\nexport type CardForm = \"virtual\" | \"physical\";\n\n/**\n * Why `terminate()` is refused right now: `first_purchase_required` (the\n * card closes after its first purchase) or `card_locked` (only support can\n * change it).\n */\nexport type CloseBlockedReason = \"first_purchase_required\" | \"card_locked\";\n\n/**\n * A card design: the artwork a card is shown with. `image_url` is the front,\n * `image_url_back` the back; both are either absolute URLs or paths relative\n * to the API origin (the deployment's default design is\n * `/card-designs/default.svg`, its back `/card-designs/default.svg?side=back`)\n * — pass them through `client.assetUrl()` before rendering. `image_url_back`\n * is `null` or absent for a one-sided design: show the front on both sides.\n * The picture is in the proportions of a plastic card (1586×1000) and draws\n * no chip or card data; the client renders the number, name and expiry on\n * top. `id` is `null` for the deployment default, which is rendered from the\n * branding settings.\n */\nexport interface CardDesignRef {\n id: string | null;\n name?: string;\n image_url: string;\n image_url_back?: string | null;\n}\n\n/**\n * What issuing a card costs the caller. `amount` is the price after the\n * user's subscription discount; `base_amount` is the list price and\n * `discount_bps` the discount in basis points (1000 = 10 %). `label` is the\n * operator's wording for the fee line (\"Card issuance\").\n */\nexport interface CardProductPrice {\n /** What the user pays, decimal string, after their subscription discount. */\n amount: string;\n /**\n * ISO 4217 code: the currency the buyer pays in. A signed-in user sees\n * their wallet currency, converted the way issuance will charge it; the\n * public catalog shows the currency the operator priced the card in. It\n * is not necessarily the currency the card is held in (`CardProduct.currency`).\n */\n currency: string;\n /** Wording for the fee line, e.g. \"Card issuance\". */\n label: string;\n /** The list price before the discount, decimal string, in the same currency. */\n base_amount: string;\n /** Discount applied, in basis points (1000 = 10%). */\n discount_bps: number;\n}\n\n/**\n * A card the user can order, as listed by `GET /me/card-products`. The id is\n * opaque — it names a product, never a provider. The list comes in the\n * order the operator arranged the storefront; `is_default` marks the\n * product issued when none is chosen, wherever it sits. `designs` is the\n * set the user may pick from (may be empty when only the default applies);\n * `design` is what the card gets when no choice is made. `price` is `null`\n * for a free card. `features` is an operator-defined object (scheme, wallet\n * support, load limits, …) with no fixed keys.\n */\nexport interface CardProduct {\n id: string;\n name: string;\n /** One line under the name on the tile, or `null`. */\n tagline: string | null;\n description: string | null;\n /** Selling points to list on the product card, in order. May be empty. */\n benefits: string[];\n /**\n * Picture for the product tile, absolute URL, or `null`: show the card\n * design (`design.image_url`) then.\n */\n tile_image_url: string | null;\n card_type: CardType;\n currency: string | null;\n features: Record<string, unknown>;\n design: CardDesignRef;\n designs: CardDesignRef[];\n price: CardProductPrice | null;\n /**\n * The balance a new card comes with, already included in `price`; `null`\n * when the card starts empty and is funded with `topUp()` afterwards.\n */\n starting_balance: CardBalance | null;\n /** True for the product the deployment issues when none is chosen. */\n is_default: boolean;\n}\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 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 /** The balance the card was issued with, decimal string; `null` or `\"0\"` for a card issued empty. */\n initial_amount: string | null;\n currency: string;\n failure_reason: string | null;\n /** Who changed the status last; `null` when it never changed. See {@link CardStatusSource}. */\n status_source: CardStatusSource | null;\n /** Virtual or plastic. A `physical` card takes a PIN with {@link CardsResource.setPin}. */\n card_form: CardForm;\n /** Why the card cannot be closed right now, or `null` when it can. */\n close_blocked: CloseBlockedReason | null;\n /**\n * Top-ups the issuer has accepted and not loaded yet, summed, decimal\n * string in `currency`; `null` when there are none. Show it next to the\n * balance as money on its way to the card.\n */\n topups_pending: string | null;\n /**\n * Top-ups the issuer has held for too long, summed, decimal string in\n * `currency`; `null` when there are none. The money is safe and waits for\n * support to settle it; say so instead of offering a retry.\n */\n topups_held: string | null;\n /** The name the user gave the card, or `null`. */\n name: string | null;\n /** The artwork the card is shown with. Always present. */\n design: CardDesignRef;\n /** The product the card was issued from; `null` for cards issued without one. */\n product: { id: string; name: string } | null;\n created_at: string;\n updated_at: string;\n /** Only on the result of `create`, when bonuses paid part of the price. */\n bonus?: IssuanceBonus;\n}\n\n/** How bonuses changed a new card's price (\"was / now\"). Decimal strings in `currency`. */\nexport interface IssuanceBonus {\n /** Bonuses used. */\n units: string;\n /** The price before bonuses (\"was\"). */\n price: string;\n /** What the bonuses covered. */\n covered: string;\n /** What the wallet paid (\"now\"). */\n paid: string;\n currency: string;\n}\n\nexport interface CreateCardInput {\n /**\n * A product id from {@link CardsResource.listProducts}. Sent as\n * `product_id`. When given, `type` and `issuer_slug` may be omitted; when\n * both are given they must agree with the product (400 `product_mismatch`).\n * Unknown, disabled or hidden product → 400 `unknown_product`.\n */\n productId?: string;\n /** A name for the card, 1–40 characters. Sent as `name`. */\n name?: string;\n /**\n * One of the product's `designs`. Sent as `design_id`. `null` or omitted\n * picks the product's default design; a design outside the product's set →\n * 400 `design_not_allowed`.\n */\n designId?: string | null;\n /**\n * `prepaid` (the only fully-wired type today), `credit`, or `gift`.\n * Optional when `productId` is given, required otherwise.\n */\n type?: CardType;\n /**\n * @deprecated Ignored since 0.3.21. A card is issued for its product price;\n * the balance it starts with, if the product includes one, is part of that\n * price (see `CardProduct.starting_balance`). Money is added afterwards\n * with {@link CardsResource.topUp}. The field is no longer sent.\n */\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 * Pay part of the price with bonuses. Sent as `use_bonus`. On by default\n * whenever the user has bonuses; `false` pays it all from the wallet.\n */\n useBonus?: boolean;\n /** The most bonuses to use, decimal string. Sent as `bonus_amount`. */\n bonusAmount?: string;\n /**\n * A promo code for the card's price. Sent as `promo_code`. Its discount\n * comes off before bonuses; `client.codes.validate` shows it first. A code\n * that can't be used fails the request with 400 `promo_code_*` and the\n * reason. Without one, the code the user signed up with applies when it\n * covers cards. Ignored inside `deposits.initiate({ issue_card })`: send\n * `promo_code` on the top-up there.\n */\n promoCode?: string;\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/**\n * The wire body of a card request: the camelCase fields renamed to what\n * the API reads. Shared by {@link CardsResource.create} and the\n * `issue_card` block of `deposits.initiate`.\n */\nexport function cardRequestBody(\n input: Omit<CreateCardInput, \"idempotencyKey\" | \"currency\"> & { currency?: string },\n): Record<string, unknown> {\n const {\n productId,\n name,\n designId,\n useBonus,\n bonusAmount,\n promoCode,\n initial_amount: _ignored,\n ...rest\n } = input;\n const body: Record<string, unknown> = { ...rest };\n if (productId !== undefined) body[\"product_id\"] = productId;\n if (name !== undefined) body[\"name\"] = name;\n if (designId !== undefined) body[\"design_id\"] = designId;\n if (useBonus !== undefined) body[\"use_bonus\"] = useBonus;\n if (bonusAmount !== undefined) body[\"bonus_amount\"] = bonusAmount;\n if (promoCode !== undefined) body[\"promo_code\"] = promoCode;\n return body;\n}\n\n/** Remaining balance of a prepaid card. */\nexport interface CardBalance {\n amount: string;\n currency: string;\n}\n\n/** What a top-up of a card can be right now, from `GET /me/cards/{id}/topup`. */\nexport interface TopUpTerms {\n /** Whether the card can be topped up at this moment. */\n available: boolean;\n /** Why not, in plain words, when `available` is false. */\n reason: string | null;\n /** Currency top-ups are made in: the card's. */\n currency: string;\n /** What the wallet holds right now, in the wallet's currency. */\n wallet_available: CardBalance;\n /** Smallest single top-up the product allows, or `null` for no floor. */\n min: CardBalance | null;\n /** Largest single top-up the product allows, or `null` for no cap. */\n max: CardBalance | null;\n}\n\nexport interface TopUpInput {\n /** Amount to add, decimal string, in the card's currency. */\n amount: string;\n /**\n * Required. Same key + same amount replays the first outcome; same key +\n * different amount is 409. Use a stable UUID per attempt so a retried\n * network call cannot move the money twice.\n */\n idempotencyKey: string;\n}\n\n/**\n * Where a top-up stands.\n *\n * - `pending`: the issuer accepted it and has not loaded the card yet. The\n * wallet is debited, the card balance is unchanged, the amount shows in\n * `Card.topups_pending`. Most issuers finish within minutes.\n * - `confirmed`: the money is on the card.\n * - `failed`: the issuer refused; the wallet is credited back.\n * - `stalled`: pending for longer than the deployment allows. The money is\n * safe and waits for support; it shows in `Card.topups_held`.\n * - `returned`: support sent the money back to the wallet.\n * - `written_off`: support closed it without the money coming back (the\n * issuer kept it); `failure_reason` says so.\n */\nexport type CardTopUpStatus =\n \"pending\" | \"confirmed\" | \"failed\" | \"stalled\" | \"returned\" | \"written_off\";\n\n/** One top-up attempt as the API records it. */\nexport interface CardTopUp {\n id: string;\n card_id: string;\n status: CardTopUpStatus;\n /** What landed on the card, decimal string, in `currency`. */\n amount: string;\n currency: string;\n /** What the wallet paid, decimal string, in `wallet_currency`. */\n wallet_amount: string;\n wallet_currency: string;\n failure_reason: string | null;\n created_at: string;\n updated_at: string;\n}\n\n/**\n * The outcome of a top-up with the state to redraw: card, its balance, the\n * wallet. When `topup.status` is `pending`, the wallet has paid and\n * `card_balance` has not moved yet: show the amount as on its way\n * (`card.topups_pending`) and refresh the card later or on the\n * `card_topup` notification.\n */\nexport interface TopUpResult {\n topup: CardTopUp;\n card: Card;\n card_balance: CardBalance;\n wallet: CardBalance;\n}\n\n/** Fields a user can change on their own card. Omitted fields are left as they are. */\nexport interface UpdateCardInput {\n /** New name, 1–40 characters. Sent as `name`. */\n name?: string;\n /**\n * New design (one of the product's `designs`), or `null` for the product's\n * default. Sent as `design_id`.\n */\n designId?: string | null;\n}\n\n/**\n * Kept for callers written against 0.3.x: the API no longer asks for a\n * password or a code on reveal, the session is enough. Both fields are\n * ignored and will be dropped in the next major.\n * @deprecated\n */\nexport interface RevealCardInput {\n password?: string;\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 *\n * Some issuers hand out a page that shows the numbers instead of the\n * numbers themselves. Then `reveal_url` is set, `pan` and `cvv` are empty,\n * and the client opens the page in a frame; see the README for the frame.\n */\nexport interface RevealedCard {\n /** The card number; empty when `reveal_url` is set. */\n pan: string;\n /** The security code; empty when `reveal_url` is set. */\n cvv: string;\n expiry_month: number;\n expiry_year: number;\n holder_name: string;\n /**\n * A page at the card issuer that shows the details to the holder. Present\n * only for issuers that give a page instead of the numbers. Short-lived,\n * often single use: open it at once in an `<iframe>` and never store it.\n */\n reveal_url?: string;\n /**\n * The person the card is registered to at its issuer: what a checkout\n * asks for. Absent for cards issued before holders were kept.\n */\n cardholder?: Cardholder;\n /**\n * The address the card is registered at — what a merchant's checkout asks\n * for, and the postal code some of them decline a payment over. Absent\n * when the deployment has not set one.\n */\n billing_address?: BillingAddress;\n /** Display window before the client should auto-clear the data. */\n expires_in_seconds: number;\n}\n\n/** Postal address a card is registered at. Which parts exist depends on the country. */\nexport interface BillingAddress {\n line1?: string;\n line2?: string;\n city?: string;\n state?: string;\n postal_code?: string;\n country?: string;\n}\n\n/**\n * The cardholder the issuer knows: the details to type into a checkout\n * that asks for the name, phone or address on the card. `source` says\n * whether the platform made them up (`generated`), the user supplied them\n * (`provided`) or both (`mixed`).\n */\nexport interface Cardholder {\n id: string;\n first_name: string;\n last_name: string;\n /** `YYYY-MM-DD`. */\n birth_date: string;\n /** E.164. */\n phone: string;\n /** A mailbox the platform owns; mail the issuer sends there reaches the user. */\n email: string;\n address: BillingAddress;\n source: \"generated\" | \"provided\" | \"mixed\";\n}\n\n/** The new PIN for a physical card. */\nexport interface SetPinInput {\n /**\n * Four to six digits, as the user typed them. Sent once to the issuer and\n * kept nowhere: not by the SDK, not by the API. Never log it.\n */\n pin: string;\n}\n\n/** What to move, and the key that makes a retry safe. */\nexport interface TransferInput {\n /** The card the money lands on. Must be the caller's, and of the same kind and currency. */\n toCardId: string;\n /** Amount to move, decimal string, in the cards' currency. */\n amount: string;\n /**\n * Required. The same key with the same body replays the first outcome; a\n * different body on the same key is 409.\n */\n idempotencyKey: string;\n}\n\n/** One transfer attempt as the API records it. */\nexport interface CardTransfer {\n id: string;\n from_card_id: string;\n to_card_id: string;\n /**\n * `confirmed` — the money is on the other card. `on_wallet` — it came off\n * the first card but the second did not take it, so it is on the wallet\n * and `failure_reason` says so in words. `pending` / `failed` otherwise.\n */\n status: \"pending\" | \"confirmed\" | \"on_wallet\" | \"failed\";\n amount: string;\n currency: string;\n failure_reason: string | null;\n created_at: string;\n updated_at: string;\n}\n\n/** A finished transfer with the balances to redraw both cards and the wallet. */\nexport interface TransferResult {\n transfer: CardTransfer;\n from_balance: CardBalance;\n to_balance: CardBalance;\n /** Holds the money when `transfer.status` is `on_wallet`. */\n wallet: CardBalance;\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, ...card } = input;\n return this.http.post<Card>(\"/me/cards\", {\n body: cardRequestBody(card),\n idempotencyKey,\n });\n }\n\n /**\n * The cards the caller can order, in the order the storefront shows them\n * (`is_default` marks the one issued when none is chosen). Each item\n * carries its product card (name, tagline, benefits, tile picture),\n * artwork, and the issuance price after the caller's subscription\n * discount, in the caller's wallet currency. Pass an item's `id` as\n * `productId` to {@link create}.\n */\n async listProducts(): Promise<CardProduct[]> {\n return this.http.get<CardProduct[]>(\"/me/card-products\");\n }\n\n /** One product from the catalog. 404 when unknown, disabled or hidden. */\n async getProduct(id: string): Promise<CardProduct> {\n return this.http.get<CardProduct>(`/me/card-products/${encodeURIComponent(id)}`);\n }\n\n /**\n * The public catalog: the same products, order and default as\n * {@link listProducts}, but readable before sign-in, for a landing page or\n * the cabinet's first screen. Prices are list prices (`discount_bps` is\n * always 0); once the user is signed in, {@link listProducts} shows what\n * they pay. The API lets caches keep this response for a minute.\n */\n async catalog(): Promise<CardProduct[]> {\n return this.http.get<CardProduct[]>(\"/card-products\");\n }\n\n /**\n * Rename the caller's own card or change its design. Resolves to the\n * updated card. 404 if the card isn't the caller's; 400 `invalid_name` /\n * `design_not_allowed` on a bad value.\n */\n async update(id: string, input: UpdateCardInput): Promise<Card> {\n const body: Record<string, unknown> = {};\n if (input.name !== undefined) body[\"name\"] = input.name;\n if (input.designId !== undefined) body[\"design_id\"] = input.designId;\n return this.http.patch<Card>(`/me/cards/${encodeURIComponent(id)}`, {\n body,\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>(`/me/cards/${encodeURIComponent(id)}/balance?${q}`);\n }\n\n /**\n * What a top-up of this card can be right now: whether it is possible, the\n * currency, the wallet balance, and the product's floor and cap for one\n * top-up. Read it before drawing the form. 404 if the card isn't the caller's.\n */\n async topUpTerms(id: string): Promise<TopUpTerms> {\n return this.http.get<TopUpTerms>(`/me/cards/${encodeURIComponent(id)}/topup`);\n }\n\n /**\n * Move money from the wallet onto the caller's own card. The wallet is\n * debited first, then the card's provider loads the card; if the provider\n * refuses, the money is back on the wallet and the error says so. Resolves\n * to the card, its new balance and the wallet balance, so no second call\n * is needed. Errors carry a sentence the user can read: 400 outside the\n * floor or cap · 402 not enough in the wallet · 404 not the caller's card ·\n * 409 card frozen, closed or still being issued · 501 provider can't top\n * up · 502/503 provider declined or unreachable (wallet untouched).\n */\n async topUp(id: string, input: TopUpInput): Promise<TopUpResult> {\n const { idempotencyKey, amount } = input;\n return this.http.post<TopUpResult>(`/me/cards/${encodeURIComponent(id)}/topup`, {\n body: { amount },\n idempotencyKey,\n });\n }\n\n /**\n * Move money from one of the caller's cards to another. Both must be\n * theirs, active, in the same currency and of the same kind. The money\n * travels through the wallet one leg at a time: when the second leg does\n * not go through, the call still resolves, `transfer.status` is\n * `on_wallet` and the money is on the wallet — never between two cards.\n * Errors carry a sentence the user can read: 400 the same card twice,\n * different currencies or different kinds · 402 the card holds less than\n * that · 404 one of the cards isn't theirs · 409 a card is frozen, closed\n * or still being issued, or the key was reused with a different body ·\n * 501/502/503 the provider cannot or will not move it.\n */\n async transfer(fromCardId: string, input: TransferInput): Promise<TransferResult> {\n const { toCardId, amount, idempotencyKey } = input;\n return this.http.post<TransferResult>(`/me/cards/${encodeURIComponent(fromCardId)}/transfer`, {\n body: { to_card_id: toCardId, amount },\n idempotencyKey,\n });\n }\n\n /**\n * Freeze the caller's own card. Reversible via {@link unfreeze} while\n * `status_source` is `holder` or `operator`. The optional `reason` is\n * recorded on the audit trail. Resolves to the updated card. 404 if the\n * card isn't the caller's; 409 `card_locked` when support holds it; 501 if\n * the issuer can't freeze.\n */\n async freeze(id: string, reason?: string): Promise<Card> {\n return this.http.post<Card>(`/me/cards/${encodeURIComponent(id)}/freeze`, { body: { reason } });\n }\n\n /**\n * Reveal the FULL PAN + CVV for the caller's own card. The signed-in\n * session is all the API asks for; the call is rate-limited and audited\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 * The result is the numbers, or `reveal_url` with empty `pan` and `cvv`\n * when the issuer shows them on a page of its own: open that page in a\n * frame right away, it is short-lived.\n *\n * 403 not your card · 409 `card_locked` · 429 rate-limited · 501 connector\n * has no sensitive-data endpoint · 503 `provider_unavailable`.\n */\n async reveal(id: string, _input?: RevealCardInput): Promise<RevealedCard> {\n return this.http.post<RevealedCard>(`/me/cards/${encodeURIComponent(id)}/reveal`);\n }\n\n /**\n * Unfreeze a previously-frozen card. Idempotent on an already-active card.\n * A card the issuer froze (`status_source: \"provider\"`) is not the\n * holder's to unfreeze: the API answers 409 `card_locked`, so hide the\n * button and say the freeze is lifted through the issuer's support.\n */\n async unfreeze(id: string): Promise<Card> {\n return this.http.post<Card>(`/me/cards/${encodeURIComponent(id)}/unfreeze`, { body: {} });\n }\n\n /**\n * Set the PIN of the caller's own physical card. The session is enough; the\n * call is rate-limited like {@link reveal} and the PIN is kept nowhere.\n * Resolves to the card; the user also gets a notification that the PIN\n * was set. 400 not four to six digits or the card is not active · 403 not\n * your card · 409 `card_locked`, or `provider_refused` when the issuer did\n * not take it · 429 too many attempts · 501 a virtual card has no PIN.\n */\n async setPin(id: string, input: SetPinInput): Promise<Card> {\n return this.http.post<Card>(`/me/cards/${encodeURIComponent(id)}/pin`, {\n body: { pin: input.pin },\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>(`/me/cards/${encodeURIComponent(id)}/terminate`, {\n body: { reason },\n });\n }\n}\n","import type { HttpClient } from \"../http.js\";\nimport type { CustomerInfo } from \"../types/customer.js\";\nimport { cardRequestBody, type CreateCardInput } from \"./cards.js\";\nimport type { DepositTarget, FunderMode } from \"./funding-options.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, or one of their cards straight away, past the wallet\n * (`card_id`, or `issue_card` for a new card). Which of the two a\n * deployment allows is in `client.fundingOptions.list()`. Mirrors the\n * 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/**\n * Lifecycle of a deposit. `redirect_required` carries `redirect_url`.\n * `expired`: nobody paid before `expires_at`; the user starts over with a\n * new quote. A payment that still arrives is credited at the stored rate\n * and the deposit turns `confirmed` after all.\n */\nexport type DepositStatus = \"pending\" | \"redirect_required\" | \"confirmed\" | \"failed\" | \"expired\";\n\n/**\n * Top-up rail. The chosen funder decides which it supports; `sbp` is\n * Russia's instant payments through a payment page, paid in roubles.\n */\nexport type DepositMethod = \"card\" | \"crypto\" | \"bank_transfer\" | \"sbp\";\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 currency credited. */\n currency: string;\n /**\n * Quote a top-up of this card: credited in the card's currency. Pass the\n * same `card_id` to `initiate()`.\n */\n card_id?: string;\n /**\n * Quote into this currency instead of the wallet's: the currency of a\n * card issued with the top-up (`issue_card`). Ignored with `card_id`.\n */\n target_currency?: string;\n /**\n * The funding connector the deposit will go through (`funder_slug` of\n * `initiate()`). With `method`, the quote is priced on that method's own\n * terms from `fundingOptions.list()`: its fee and kind, its rate source,\n * its lifetime, its limits. Sent as `connector_slug`.\n */\n connectorSlug?: string;\n /** The way the user pays. Pass the same method to `initiate()`. */\n method?: DepositMethod;\n}\n\n/**\n * How a method's fee reads. `spread`: taken off the credited amount at the\n * deployment's rate. `markup`: in the rate the user sees, so show the rate\n * and nothing else. `commission`: the rate is the provider's and the fee is\n * a line of its own on the credited amount.\n */\nexport type FeeKind = \"spread\" | \"markup\" | \"commission\";\n\n/** How far a top-up meant for a card has got. */\nexport type CardLoadStatus = \"pending\" | \"succeeded\" | \"failed\";\n\n/**\n * A card to issue with the top-up: the fields of `cards.create` without\n * its idempotency key (the deposit's covers both). The card's price is\n * paid from the top-up and the rest becomes its starting balance.\n */\nexport type IssueCardInput = Omit<CreateCardInput, \"idempotencyKey\" | \"currency\"> & {\n /** Optional with `productId`: the product names the 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 /**\n * Provider rate before the fee, credited units per 1 source unit. The\n * rate to show the user is `credited_amount / source_amount`, which has\n * the fee in it; see the README for the rouble-per-dollar form.\n */\n rate: string;\n /** The fee in basis points; the same figure as `fee_bps`, under its old name. */\n spread_bps: number;\n /** The fee in basis points (2000 = 20 %). */\n fee_bps: number;\n fee_kind: FeeKind;\n provider: string;\n /** The pair the quote was priced for, when the request named one. */\n connector_slug?: string;\n method?: DepositMethod;\n /** The rate is locked until then; the deposit made with it waits for its payment as long. */\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 /** How `fx_spread_bps` was taken; see `FeeKind`. */\n fx_fee_kind?: FeeKind | null;\n /** When the deposit stops waiting for its payment; `null` for one without a term. */\n expires_at?: string | 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 /** Bonuses added on top of the top-up, when any were. */\n bonus_units?: string | null;\n /** What those bonuses added to the wallet, in the credited currency. */\n bonus_value?: string | null;\n /** The promo code the top-up was made with; its discount came off the commission. */\n promo_code?: string | null;\n /** Where the money goes. Older deployments leave it out: the wallet. */\n target?: DepositTarget;\n /** For a top-up onto a card: the card. */\n card_id?: string | null;\n /** The funding connector's mode when the top-up was made. */\n funder_mode?: FunderMode | null;\n /** True when the card was issued with this top-up. */\n issues_card?: boolean;\n /**\n * For a top-up onto a card: `pending` until the card provider has loaded\n * the card, then `succeeded` or `failed`. Show the top-up as done only\n * once it is `succeeded`, or once `returned_to_wallet_at` is set.\n */\n card_load_status?: CardLoadStatus | null;\n /** Why the card could not take it, when `card_load_status` is `failed`. */\n card_load_error?: string | null;\n /** What went towards the card, in its currency, bonuses included. */\n card_amount?: string | null;\n /** The commission taken from a top-up onto a card, in the card's currency. */\n card_commission?: string | null;\n /** The money part of the price of a card issued with the top-up. */\n issue_fee?: string | null;\n /** The bonus part of that price. */\n issue_bonus_units?: string | null;\n issue_bonus_value?: string | null;\n card_loaded_at?: string | null;\n /**\n * Set when the card could not take the top-up and the money went to the\n * wallet instead (funding connectors in `mixed` mode). The user is told.\n */\n returned_to_wallet_at?: 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 /**\n * Passed to the funding connector and stored with the deposit. Two keys\n * work across connectors: `return_url`, where the provider sends the user\n * back after a 3-D Secure step (pair it with `redirect_required`), and on\n * test deployments with the mock funder `mock_scenario`, which picks the\n * outcome: `happy` (confirmed at once, the default), `pending` (confirmed\n * about 15 s later), `redirect` (a hosted page where the user approves or\n * declines), `late` (paid after the term) or `fail`.\n */\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 * Add bonuses on top of the top-up: the user pays `amount`, the wallet\n * gets `amount` plus what the bonuses add. On by default whenever the\n * user has bonuses that can go to a top-up (only ones that came with a\n * payment can); `false` tops up without them.\n */\n use_bonus?: boolean;\n /** The most bonuses to add, decimal string. Omit to add as many as allowed. */\n bonus_amount?: string;\n /**\n * Top up this card instead of the wallet. It must be the user's, active\n * and prepaid. A funding connector that tops up the wallet only answers\n * 400 `target_not_allowed`; one that tops up cards only needs `card_id`\n * or `issue_card`. Paying in another currency than the card's needs a\n * quote made with the same `card_id`.\n */\n card_id?: string;\n /**\n * Issue a new card and put this top-up on it. The card shows up as\n * `pending_payment` and is issued once the top-up is confirmed; if the\n * top-up fails, so does the card. Too small to cover the price → 400\n * `amount_too_small`. Not together with `card_id`.\n */\n issue_card?: IssueCardInput;\n /**\n * A promo code for this top-up, to the wallet or to a card. Its discount\n * comes off the commission; bonuses or a gift that come with the code\n * arrive once the top-up is confirmed. A code that can't be used fails the\n * request with 400 `promo_code_*` and the reason. `client.codes.validate`\n * checks it first.\n */\n promo_code?: 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 already in the currency they\n * credit (the wallet's, or the card's with `card_id`) need no quote (the\n * API answers 400 `no_quote_needed`).\n */\n async quote(input: CreateQuoteInput): Promise<FundingQuote> {\n const { connectorSlug, ...rest } = input;\n const body: Record<string, unknown> = { ...rest };\n if (connectorSlug !== undefined) body[\"connector_slug\"] = connectorSlug;\n return this.http.post<FundingQuote>(\"/me/deposits/quotes\", { body });\n }\n\n async initiate(input: InitiateDepositInput): Promise<Deposit> {\n const { idempotencyKey, issue_card, ...rest } = input;\n const body: Record<string, unknown> = { ...rest };\n if (issue_card !== undefined) body[\"issue_card\"] = cardRequestBody(issue_card);\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(depositId: string, input: CreateDepositRefundInput): Promise<Refund> {\n const { idempotencyKey, ...body } = input;\n return this.http.post<Refund>(`/me/deposits/${encodeURIComponent(depositId)}/refunds`, {\n body,\n idempotencyKey,\n });\n }\n}\n"]}
@@ -45,7 +45,9 @@ var DevicesResource = class {
45
45
  async registerWebPush(registration, opts = {}) {
46
46
  const key = opts.vapidPublicKey ?? await this.vapidPublicKey();
47
47
  if (!key) {
48
- throw new Error("@takeal/cusfront-sdk: push notifications are not enabled on this deployment");
48
+ throw new Error(
49
+ "@takeal/cusfront-sdk: push notifications are not enabled on this deployment"
50
+ );
49
51
  }
50
52
  const sub = await registration.pushManager.subscribe({
51
53
  userVisibleOnly: true,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/resources/push.ts","../../src/resources/devices.ts"],"names":[],"mappings":";;;AAsGO,SAAS,iBAAiB,KAAA,EAA2B;AAC1D,EAAA,MAAM,GAAA,GAAM,MAAM,OAAA,CAAQ,IAAA,EAAM,GAAG,CAAA,CAAE,OAAA,CAAQ,MAAM,GAAG,CAAA;AACtD,EAAA,MAAM,MAAA,GAAS,MAAM,GAAA,CAAI,MAAA,CAAA,CAAQ,IAAK,GAAA,CAAI,MAAA,GAAS,KAAM,CAAC,CAAA;AAC1D,EAAA,MAAM,GAAA,GAAM,KAAK,MAAM,CAAA;AACvB,EAAA,MAAM,GAAA,GAAM,IAAI,UAAA,CAAW,GAAA,CAAI,MAAM,CAAA;AACrC,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,GAAA,CAAI,MAAA,EAAQ,CAAA,EAAA,EAAK,GAAA,CAAI,CAAC,CAAA,GAAI,GAAA,CAAI,UAAA,CAAW,CAAC,CAAA;AAC9D,EAAA,OAAO,GAAA;AACT;;;ACEO,SAAS,iBAAiB,QAAA,EAA0C;AACzE,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,GAAyC;AACrD,IAAA,MAAM,EAAE,gBAAA,EAAiB,GAAI,MAAM,KAAK,IAAA,CAAK,GAAA;AAAA,MAC3C;AAAA,KACF;AACA,IAAA,OAAO,gBAAA,IAAoB,IAAA;AAAA,EAC7B;AACF","file":"devices.cjs","sourcesContent":["import type { HttpClient } from \"../http.js\";\n\n/**\n * Push resource — `client.push.*`.\n *\n * Web Push for the signed-in user, through the older single-subscription\n * endpoint. The API now keeps one device per browser (see\n * `client.devices`), and this endpoint is an alias over the Web Push\n * devices: it keeps working, but new code should call\n * `client.devices.registerWebPush(reg)` / `unregisterWebPush(reg)` instead.\n *\n * Your service worker shows the notification: the payload is JSON with\n * `title`, `body` and `url` (where a click should lead).\n */\n\nexport interface PushStatus {\n /** `true` when a subscription is stored for this user. */\n subscribed: boolean;\n /** Host of the stored endpoint, e.g. `fcm.googleapis.com`. */\n endpoint_host?: string | null;\n /** VAPID public key (URL-safe base64) for `pushManager.subscribe`.\n * `null` when push is not set up on this deployment. */\n vapid_public_key?: string | null;\n}\n\nexport interface PushSubscriptionInput {\n /** `PushSubscription.endpoint`; must be https. */\n endpoint: string;\n keys: {\n /** URL-safe base64. */\n p256dh: string;\n /** URL-safe base64. */\n auth: string;\n };\n}\n\n/** The part of `ServiceWorkerRegistration` the SDK needs. Typed\n * structurally so the core stays free of DOM lib types. */\nexport interface PushCapableRegistration {\n pushManager: {\n getSubscription(): Promise<{ unsubscribe(): Promise<boolean> } | null>;\n subscribe(options: {\n userVisibleOnly: boolean;\n applicationServerKey: Uint8Array;\n }): Promise<{ toJSON(): { endpoint?: string; keys?: Record<string, string> } }>;\n };\n}\n\nexport class PushResource {\n constructor(private readonly http: HttpClient) {}\n\n /** Whether the user is subscribed, plus the VAPID key to subscribe with. */\n async status(): Promise<PushStatus> {\n return this.http.get<PushStatus>(\"/me/push-subscription\");\n }\n\n /** Store a subscription you created yourself.\n * 409 `push_disabled` when the deployment has no VAPID keys.\n * @deprecated Use `client.devices.register({ kind: \"webpush\", ... })`. */\n async save(input: PushSubscriptionInput): Promise<PushStatus> {\n return this.http.put<PushStatus>(\"/me/push-subscription\", { body: input });\n }\n\n /** Delete the stored subscription. Safe when nothing is stored.\n * @deprecated Use `client.devices.remove(id)` or `client.devices.unregisterWebPush(reg)`. */\n async remove(): Promise<void> {\n await this.http.delete<void>(\"/me/push-subscription\");\n }\n\n /** Subscribe this browser and store the subscription. Ask for\n * notification permission before calling. Throws when push isn't set up\n * on the deployment.\n * @deprecated Use `client.devices.registerWebPush(registration)`. */\n async enable(registration: PushCapableRegistration): Promise<PushStatus> {\n const { vapid_public_key } = await this.status();\n if (!vapid_public_key) {\n throw new Error(\"@takeal/cusfront-sdk: push notifications are not enabled on this deployment\");\n }\n const sub = await registration.pushManager.subscribe({\n userVisibleOnly: true,\n applicationServerKey: base64UrlToBytes(vapid_public_key),\n });\n const json = sub.toJSON();\n if (!json.endpoint || !json.keys?.p256dh || !json.keys.auth) {\n throw new Error(\"@takeal/cusfront-sdk: the browser returned an incomplete push subscription\");\n }\n return this.save({\n endpoint: json.endpoint,\n keys: { p256dh: json.keys.p256dh, auth: json.keys.auth },\n });\n }\n\n /** Unsubscribe this browser and delete the stored subscription.\n * @deprecated Use `client.devices.unregisterWebPush(registration)`. */\n async disable(registration: PushCapableRegistration): Promise<void> {\n const sub = await registration.pushManager.getSubscription();\n if (sub) await sub.unsubscribe();\n await this.remove();\n }\n}\n\n/** URL-safe base64 (padding optional) → bytes. */\nexport function base64UrlToBytes(input: string): Uint8Array {\n const b64 = input.replace(/-/g, \"+\").replace(/_/g, \"/\");\n const padded = b64 + \"=\".repeat((4 - (b64.length % 4)) % 4);\n const bin = atob(padded);\n const out = new Uint8Array(bin.length);\n for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);\n return out;\n}\n","import type { HttpClient } from \"../http.js\";\nimport type { ClientPlatform, ResolvedClientDescriptor } from \"../client-platform.js\";\nimport { base64UrlToBytes, type PushCapableRegistration } from \"./push.js\";\n\n/**\n * Devices resource — `client.devices.*`.\n *\n * A user has many devices: each browser with a Web Push subscription, each\n * phone with an FCM / APNs token, and a marker for \"uses the Telegram Mini\n * App\". The server picks the notification channel from them: a mobile app\n * first, otherwise the device seen most recently.\n *\n * The usual browser flow, once notification permission is granted:\n *\n * ```ts\n * const reg = await navigator.serviceWorker.ready;\n * const device = await client.devices.registerWebPush(reg, { label: \"Chrome on Mac\" });\n * // later, from a settings screen:\n * await client.devices.unregisterWebPush(reg);\n * ```\n */\n\nexport type DeviceKind = \"webpush\" | \"fcm\" | \"apns\" | \"telegram_miniapp\";\n\nexport type DevicePlatform = \"pwa\" | \"web\" | \"ios\" | \"android\" | \"telegram\";\n\nexport interface Device {\n id: string;\n kind: DeviceKind;\n platform: DevicePlatform;\n /** Free-form name the app gave it (\"Chrome on Mac\"), or `null`. */\n label: string | null;\n locale: string | null;\n app_version: string | null;\n created_at: string;\n last_seen_at: string;\n /** Set when the device no longer receives anything (the push endpoint is\n * gone, or someone switched it off). */\n disabled_at: string | null;\n /** `true` when it was registered from the session this client holds. */\n is_current: boolean;\n}\n\n/** `PushSubscription.toJSON()` minus the parts the server doesn't need. */\nexport interface WebPushCredential {\n /** `PushSubscription.endpoint`; must be https. */\n endpoint: string;\n keys: {\n /** URL-safe base64. */\n p256dh: string;\n /** URL-safe base64. */\n auth: string;\n };\n}\n\n/** FCM registration token or APNs device token. */\nexport interface MobilePushCredential {\n token: string;\n}\n\nexport type RegisterDeviceInput =\n | {\n kind: \"webpush\";\n platform: DevicePlatform;\n credential: WebPushCredential;\n label?: string;\n locale?: string;\n app_version?: string;\n }\n | {\n kind: \"fcm\" | \"apns\";\n platform: DevicePlatform;\n credential: MobilePushCredential;\n label?: string;\n locale?: string;\n app_version?: string;\n }\n | {\n kind: \"telegram_miniapp\";\n platform: DevicePlatform;\n /** Nothing to send: the device is a marker. */\n credential: Record<string, never>;\n label?: string;\n locale?: string;\n app_version?: string;\n };\n\nexport interface RegisteredDevice {\n id: string;\n kind: DeviceKind;\n platform: DevicePlatform;\n /** VAPID public key (URL-safe base64) for `pushManager.subscribe`;\n * `null` when push is not set up on this deployment. */\n vapid_public_key: string | null;\n}\n\nexport interface RegisterWebPushOptions {\n /** A name to show in the user's device list (\"Chrome on Mac\"). */\n label?: string;\n /** Skip the key lookup when you already hold the deployment's VAPID\n * public key (from an earlier `register` result, for example). */\n vapidPublicKey?: string;\n}\n\nexport interface UnregisterWebPushOptions {\n /** The device to delete, from an earlier `registerWebPush` result. When\n * omitted, every Web Push device registered from this session goes. */\n deviceId?: string;\n}\n\n/** Client platform → the platform the device list uses. */\nexport function devicePlatformOf(platform: ClientPlatform): DevicePlatform {\n return platform === \"telegram-miniapp\" ? \"telegram\" : platform;\n}\n\nexport class DevicesResource {\n constructor(\n private readonly http: HttpClient,\n private readonly client: ResolvedClientDescriptor,\n ) {}\n\n /** Every device the user has, disabled ones included. */\n async list(): Promise<Device[]> {\n return this.http.get<Device[]>(\"/me/devices\");\n }\n\n /** Register a device, or refresh it when the same credential is already\n * known (then `last_seen_at`, `label` and `app_version` update and a\n * disabled device comes back). `app_version` defaults to the client\n * version sent in `X-Takeal-Client`.\n *\n * Errors: 400 `validation`; 409 `push_disabled` for `webpush` when the\n * deployment has no VAPID keys. */\n async register(input: RegisterDeviceInput): Promise<RegisteredDevice> {\n return this.http.put<RegisteredDevice>(\"/me/devices\", {\n body: { app_version: this.client.version, ...input },\n });\n }\n\n /** Delete one device. 404 when it isn't the user's. */\n async remove(id: string): Promise<void> {\n await this.http.delete<void>(`/me/devices/${encodeURIComponent(id)}`);\n }\n\n /** Subscribe this browser to Web Push and register it as a device. Ask\n * for notification permission before calling. Throws when push isn't\n * set up on the deployment. */\n async registerWebPush(\n registration: PushCapableRegistration,\n opts: RegisterWebPushOptions = {},\n ): Promise<RegisteredDevice> {\n const key = opts.vapidPublicKey ?? (await this.vapidPublicKey());\n if (!key) {\n throw new Error(\"@takeal/cusfront-sdk: push notifications are not enabled on this deployment\");\n }\n const sub = await registration.pushManager.subscribe({\n userVisibleOnly: true,\n applicationServerKey: base64UrlToBytes(key),\n });\n const json = sub.toJSON();\n if (!json.endpoint || !json.keys?.p256dh || !json.keys.auth) {\n throw new Error(\"@takeal/cusfront-sdk: the browser returned an incomplete push subscription\");\n }\n return this.register({\n kind: \"webpush\",\n platform: devicePlatformOf(this.client.platform),\n credential: {\n endpoint: json.endpoint,\n keys: { p256dh: json.keys.p256dh, auth: json.keys.auth },\n },\n ...(opts.label ? { label: opts.label } : {}),\n });\n }\n\n /** Unsubscribe this browser from Web Push and delete the matching device\n * (see {@link UnregisterWebPushOptions}). Safe when nothing is\n * registered. */\n async unregisterWebPush(\n registration: PushCapableRegistration,\n opts: UnregisterWebPushOptions = {},\n ): Promise<void> {\n const sub = await registration.pushManager.getSubscription();\n if (sub) await sub.unsubscribe();\n if (opts.deviceId) {\n await this.remove(opts.deviceId);\n return;\n }\n const mine = (await this.list()).filter((d) => d.kind === \"webpush\" && d.is_current);\n for (const d of mine) await this.remove(d.id);\n }\n\n private async vapidPublicKey(): Promise<string | null> {\n const { vapid_public_key } = await this.http.get<{ vapid_public_key?: string | null }>(\n \"/me/push-subscription\",\n );\n return vapid_public_key ?? null;\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/resources/push.ts","../../src/resources/devices.ts"],"names":[],"mappings":";;;AAwGO,SAAS,iBAAiB,KAAA,EAA2B;AAC1D,EAAA,MAAM,GAAA,GAAM,MAAM,OAAA,CAAQ,IAAA,EAAM,GAAG,CAAA,CAAE,OAAA,CAAQ,MAAM,GAAG,CAAA;AACtD,EAAA,MAAM,MAAA,GAAS,MAAM,GAAA,CAAI,MAAA,CAAA,CAAQ,IAAK,GAAA,CAAI,MAAA,GAAS,KAAM,CAAC,CAAA;AAC1D,EAAA,MAAM,GAAA,GAAM,KAAK,MAAM,CAAA;AACvB,EAAA,MAAM,GAAA,GAAM,IAAI,UAAA,CAAW,GAAA,CAAI,MAAM,CAAA;AACrC,EAAA,KAAA,IAAS,CAAA,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MAAA,CAAO,CAAC,CAAA,KAAM,CAAA,CAAE,IAAA,KAAS,SAAA,IAAa,CAAA,CAAE,UAAU,CAAA;AACnF,IAAA,KAAA,MAAW,KAAK,IAAA,EAAM,MAAM,IAAA,CAAK,MAAA,CAAO,EAAE,EAAE,CAAA;AAAA,EAC9C;AAAA,EAEA,MAAc,cAAA,GAAyC;AACrD,IAAA,MAAM,EAAE,gBAAA,EAAiB,GAAI,MAAM,KAAK,IAAA,CAAK,GAAA;AAAA,MAC3C;AAAA,KACF;AACA,IAAA,OAAO,gBAAA,IAAoB,IAAA;AAAA,EAC7B;AACF","file":"devices.cjs","sourcesContent":["import type { HttpClient } from \"../http.js\";\n\n/**\n * Push resource — `client.push.*`.\n *\n * Web Push for the signed-in user, through the older single-subscription\n * endpoint. The API now keeps one device per browser (see\n * `client.devices`), and this endpoint is an alias over the Web Push\n * devices: it keeps working, but new code should call\n * `client.devices.registerWebPush(reg)` / `unregisterWebPush(reg)` instead.\n *\n * Your service worker shows the notification: the payload is JSON with\n * `title`, `body` and `url` (where a click should lead).\n */\n\nexport interface PushStatus {\n /** `true` when a subscription is stored for this user. */\n subscribed: boolean;\n /** Host of the stored endpoint, e.g. `fcm.googleapis.com`. */\n endpoint_host?: string | null;\n /** VAPID public key (URL-safe base64) for `pushManager.subscribe`.\n * `null` when push is not set up on this deployment. */\n vapid_public_key?: string | null;\n}\n\nexport interface PushSubscriptionInput {\n /** `PushSubscription.endpoint`; must be https. */\n endpoint: string;\n keys: {\n /** URL-safe base64. */\n p256dh: string;\n /** URL-safe base64. */\n auth: string;\n };\n}\n\n/** The part of `ServiceWorkerRegistration` the SDK needs. Typed\n * structurally so the core stays free of DOM lib types. */\nexport interface PushCapableRegistration {\n pushManager: {\n getSubscription(): Promise<{ unsubscribe(): Promise<boolean> } | null>;\n subscribe(options: {\n userVisibleOnly: boolean;\n applicationServerKey: Uint8Array;\n }): Promise<{ toJSON(): { endpoint?: string; keys?: Record<string, string> } }>;\n };\n}\n\nexport class PushResource {\n constructor(private readonly http: HttpClient) {}\n\n /** Whether the user is subscribed, plus the VAPID key to subscribe with. */\n async status(): Promise<PushStatus> {\n return this.http.get<PushStatus>(\"/me/push-subscription\");\n }\n\n /** Store a subscription you created yourself.\n * 409 `push_disabled` when the deployment has no VAPID keys.\n * @deprecated Use `client.devices.register({ kind: \"webpush\", ... })`. */\n async save(input: PushSubscriptionInput): Promise<PushStatus> {\n return this.http.put<PushStatus>(\"/me/push-subscription\", { body: input });\n }\n\n /** Delete the stored subscription. Safe when nothing is stored.\n * @deprecated Use `client.devices.remove(id)` or `client.devices.unregisterWebPush(reg)`. */\n async remove(): Promise<void> {\n await this.http.delete<void>(\"/me/push-subscription\");\n }\n\n /** Subscribe this browser and store the subscription. Ask for\n * notification permission before calling. Throws when push isn't set up\n * on the deployment.\n * @deprecated Use `client.devices.registerWebPush(registration)`. */\n async enable(registration: PushCapableRegistration): Promise<PushStatus> {\n const { vapid_public_key } = await this.status();\n if (!vapid_public_key) {\n throw new Error(\n \"@takeal/cusfront-sdk: push notifications are not enabled on this deployment\",\n );\n }\n const sub = await registration.pushManager.subscribe({\n userVisibleOnly: true,\n applicationServerKey: base64UrlToBytes(vapid_public_key),\n });\n const json = sub.toJSON();\n if (!json.endpoint || !json.keys?.p256dh || !json.keys.auth) {\n throw new Error(\"@takeal/cusfront-sdk: the browser returned an incomplete push subscription\");\n }\n return this.save({\n endpoint: json.endpoint,\n keys: { p256dh: json.keys.p256dh, auth: json.keys.auth },\n });\n }\n\n /** Unsubscribe this browser and delete the stored subscription.\n * @deprecated Use `client.devices.unregisterWebPush(registration)`. */\n async disable(registration: PushCapableRegistration): Promise<void> {\n const sub = await registration.pushManager.getSubscription();\n if (sub) await sub.unsubscribe();\n await this.remove();\n }\n}\n\n/** URL-safe base64 (padding optional) → bytes. */\nexport function base64UrlToBytes(input: string): Uint8Array {\n const b64 = input.replace(/-/g, \"+\").replace(/_/g, \"/\");\n const padded = b64 + \"=\".repeat((4 - (b64.length % 4)) % 4);\n const bin = atob(padded);\n const out = new Uint8Array(bin.length);\n for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);\n return out;\n}\n","import type { HttpClient } from \"../http.js\";\nimport type { ClientPlatform, ResolvedClientDescriptor } from \"../client-platform.js\";\nimport { base64UrlToBytes, type PushCapableRegistration } from \"./push.js\";\n\n/**\n * Devices resource — `client.devices.*`.\n *\n * A user has many devices: each browser with a Web Push subscription, each\n * phone with an FCM / APNs token, and a marker for \"uses the Telegram Mini\n * App\". The server picks the notification channel from them: a mobile app\n * first, otherwise the device seen most recently.\n *\n * The usual browser flow, once notification permission is granted:\n *\n * ```ts\n * const reg = await navigator.serviceWorker.ready;\n * const device = await client.devices.registerWebPush(reg, { label: \"Chrome on Mac\" });\n * // later, from a settings screen:\n * await client.devices.unregisterWebPush(reg);\n * ```\n */\n\nexport type DeviceKind = \"webpush\" | \"fcm\" | \"apns\" | \"telegram_miniapp\";\n\nexport type DevicePlatform = \"pwa\" | \"web\" | \"ios\" | \"android\" | \"telegram\";\n\nexport interface Device {\n id: string;\n kind: DeviceKind;\n platform: DevicePlatform;\n /** Free-form name the app gave it (\"Chrome on Mac\"), or `null`. */\n label: string | null;\n locale: string | null;\n app_version: string | null;\n created_at: string;\n last_seen_at: string;\n /** Set when the device no longer receives anything (the push endpoint is\n * gone, or someone switched it off). */\n disabled_at: string | null;\n /** `true` when it was registered from the session this client holds. */\n is_current: boolean;\n}\n\n/** `PushSubscription.toJSON()` minus the parts the server doesn't need. */\nexport interface WebPushCredential {\n /** `PushSubscription.endpoint`; must be https. */\n endpoint: string;\n keys: {\n /** URL-safe base64. */\n p256dh: string;\n /** URL-safe base64. */\n auth: string;\n };\n}\n\n/** FCM registration token or APNs device token. */\nexport interface MobilePushCredential {\n token: string;\n}\n\nexport type RegisterDeviceInput =\n | {\n kind: \"webpush\";\n platform: DevicePlatform;\n credential: WebPushCredential;\n label?: string;\n locale?: string;\n app_version?: string;\n }\n | {\n kind: \"fcm\" | \"apns\";\n platform: DevicePlatform;\n credential: MobilePushCredential;\n label?: string;\n locale?: string;\n app_version?: string;\n }\n | {\n kind: \"telegram_miniapp\";\n platform: DevicePlatform;\n /** Nothing to send: the device is a marker. */\n credential: Record<string, never>;\n label?: string;\n locale?: string;\n app_version?: string;\n };\n\nexport interface RegisteredDevice {\n id: string;\n kind: DeviceKind;\n platform: DevicePlatform;\n /** VAPID public key (URL-safe base64) for `pushManager.subscribe`;\n * `null` when push is not set up on this deployment. */\n vapid_public_key: string | null;\n}\n\nexport interface RegisterWebPushOptions {\n /** A name to show in the user's device list (\"Chrome on Mac\"). */\n label?: string;\n /** Skip the key lookup when you already hold the deployment's VAPID\n * public key (from an earlier `register` result, for example). */\n vapidPublicKey?: string;\n}\n\nexport interface UnregisterWebPushOptions {\n /** The device to delete, from an earlier `registerWebPush` result. When\n * omitted, every Web Push device registered from this session goes. */\n deviceId?: string;\n}\n\n/** Client platform → the platform the device list uses. */\nexport function devicePlatformOf(platform: ClientPlatform): DevicePlatform {\n return platform === \"telegram-miniapp\" ? \"telegram\" : platform;\n}\n\nexport class DevicesResource {\n constructor(\n private readonly http: HttpClient,\n private readonly client: ResolvedClientDescriptor,\n ) {}\n\n /** Every device the user has, disabled ones included. */\n async list(): Promise<Device[]> {\n return this.http.get<Device[]>(\"/me/devices\");\n }\n\n /** Register a device, or refresh it when the same credential is already\n * known (then `last_seen_at`, `label` and `app_version` update and a\n * disabled device comes back). `app_version` defaults to the client\n * version sent in `X-Takeal-Client`.\n *\n * Errors: 400 `validation`; 409 `push_disabled` for `webpush` when the\n * deployment has no VAPID keys. */\n async register(input: RegisterDeviceInput): Promise<RegisteredDevice> {\n return this.http.put<RegisteredDevice>(\"/me/devices\", {\n body: { app_version: this.client.version, ...input },\n });\n }\n\n /** Delete one device. 404 when it isn't the user's. */\n async remove(id: string): Promise<void> {\n await this.http.delete<void>(`/me/devices/${encodeURIComponent(id)}`);\n }\n\n /** Subscribe this browser to Web Push and register it as a device. Ask\n * for notification permission before calling. Throws when push isn't\n * set up on the deployment. */\n async registerWebPush(\n registration: PushCapableRegistration,\n opts: RegisterWebPushOptions = {},\n ): Promise<RegisteredDevice> {\n const key = opts.vapidPublicKey ?? (await this.vapidPublicKey());\n if (!key) {\n throw new Error(\n \"@takeal/cusfront-sdk: push notifications are not enabled on this deployment\",\n );\n }\n const sub = await registration.pushManager.subscribe({\n userVisibleOnly: true,\n applicationServerKey: base64UrlToBytes(key),\n });\n const json = sub.toJSON();\n if (!json.endpoint || !json.keys?.p256dh || !json.keys.auth) {\n throw new Error(\"@takeal/cusfront-sdk: the browser returned an incomplete push subscription\");\n }\n return this.register({\n kind: \"webpush\",\n platform: devicePlatformOf(this.client.platform),\n credential: {\n endpoint: json.endpoint,\n keys: { p256dh: json.keys.p256dh, auth: json.keys.auth },\n },\n ...(opts.label ? { label: opts.label } : {}),\n });\n }\n\n /** Unsubscribe this browser from Web Push and delete the matching device\n * (see {@link UnregisterWebPushOptions}). Safe when nothing is\n * registered. */\n async unregisterWebPush(\n registration: PushCapableRegistration,\n opts: UnregisterWebPushOptions = {},\n ): Promise<void> {\n const sub = await registration.pushManager.getSubscription();\n if (sub) await sub.unsubscribe();\n if (opts.deviceId) {\n await this.remove(opts.deviceId);\n return;\n }\n const mine = (await this.list()).filter((d) => d.kind === \"webpush\" && d.is_current);\n for (const d of mine) await this.remove(d.id);\n }\n\n private async vapidPublicKey(): Promise<string | null> {\n const { vapid_public_key } = await this.http.get<{ vapid_public_key?: string | null }>(\n \"/me/push-subscription\",\n );\n return vapid_public_key ?? null;\n }\n}\n"]}
@@ -43,7 +43,9 @@ var DevicesResource = class {
43
43
  async registerWebPush(registration, opts = {}) {
44
44
  const key = opts.vapidPublicKey ?? await this.vapidPublicKey();
45
45
  if (!key) {
46
- throw new Error("@takeal/cusfront-sdk: push notifications are not enabled on this deployment");
46
+ throw new Error(
47
+ "@takeal/cusfront-sdk: push notifications are not enabled on this deployment"
48
+ );
47
49
  }
48
50
  const sub = await registration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AA,MACA,GAAI,KAAK,KAAA,GAAQ,EAAE,OAAO,IAAA,CAAK,KAAA,KAAU;AAAC,KAC3C,CAAA;AAAA,EACH;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,iBAAA,CACJ,YAAA,EACA,IAAA,GAAiC,EAAC,EACnB;AACf,IAAA,MAAM,GAAA,GAAM,MAAM,YAAA,CAAa,WAAA,CAAY,eAAA,EAAgB;AAC3D,IAAA,IAAI,GAAA,EAAK,MAAM,GAAA,CAAI,WAAA,EAAY;AAC/B,IAAA,IAAI,KAAK,QAAA,EAAU;AACjB,MAAA,MAAM,IAAA,CAAK,MAAA,CAAO,IAAA,CAAK,QAAQ,CAAA;AAC/B,MAAA;AAAA,IACF;AACA,IAAA,MAAM,IAAA,GAAA,CAAQ,MAAM,IAAA,CAAK,IAAA,EAAK,EAAG,MAAA,CAAO,CAAC,CAAA,KAAM,CAAA,CAAE,IAAA,KAAS,SAAA,IAAa,CAAA,CAAE,UAAU,CAAA;AACnF,IAAA,KAAA,MAAW,KAAK,IAAA,EAAM,MAAM,IAAA,CAAK,MAAA,CAAO,EAAE,EAAE,CAAA;AAAA,EAC9C;AAAA,EAEA,MAAc,cAAA,GAAyC;AACrD,IAAA,MAAM,EAAE,gBAAA,EAAiB,GAAI,MAAM,KAAK,IAAA,CAAK,GAAA;AAAA,MAC3C;AAAA,KACF;AACA,IAAA,OAAO,gBAAA,IAAoB,IAAA;AAAA,EAC7B;AACF","file":"devices.js","sourcesContent":["import type { HttpClient } from \"../http.js\";\n\n/**\n * Push resource — `client.push.*`.\n *\n * Web Push for the signed-in user, through the older single-subscription\n * endpoint. The API now keeps one device per browser (see\n * `client.devices`), and this endpoint is an alias over the Web Push\n * devices: it keeps working, but new code should call\n * `client.devices.registerWebPush(reg)` / `unregisterWebPush(reg)` instead.\n *\n * Your service worker shows the notification: the payload is JSON with\n * `title`, `body` and `url` (where a click should lead).\n */\n\nexport interface PushStatus {\n /** `true` when a subscription is stored for this user. */\n subscribed: boolean;\n /** Host of the stored endpoint, e.g. `fcm.googleapis.com`. */\n endpoint_host?: string | null;\n /** VAPID public key (URL-safe base64) for `pushManager.subscribe`.\n * `null` when push is not set up on this deployment. */\n vapid_public_key?: string | null;\n}\n\nexport interface PushSubscriptionInput {\n /** `PushSubscription.endpoint`; must be https. */\n endpoint: string;\n keys: {\n /** URL-safe base64. */\n p256dh: string;\n /** URL-safe base64. */\n auth: string;\n };\n}\n\n/** The part of `ServiceWorkerRegistration` the SDK needs. Typed\n * structurally so the core stays free of DOM lib types. */\nexport interface PushCapableRegistration {\n pushManager: {\n getSubscription(): Promise<{ unsubscribe(): Promise<boolean> } | null>;\n subscribe(options: {\n userVisibleOnly: boolean;\n applicationServerKey: Uint8Array;\n }): Promise<{ toJSON(): { endpoint?: string; keys?: Record<string, string> } }>;\n };\n}\n\nexport class PushResource {\n constructor(private readonly http: HttpClient) {}\n\n /** Whether the user is subscribed, plus the VAPID key to subscribe with. */\n async status(): Promise<PushStatus> {\n return this.http.get<PushStatus>(\"/me/push-subscription\");\n }\n\n /** Store a subscription you created yourself.\n * 409 `push_disabled` when the deployment has no VAPID keys.\n * @deprecated Use `client.devices.register({ kind: \"webpush\", ... })`. */\n async save(input: PushSubscriptionInput): Promise<PushStatus> {\n return this.http.put<PushStatus>(\"/me/push-subscription\", { body: input });\n }\n\n /** Delete the stored subscription. Safe when nothing is stored.\n * @deprecated Use `client.devices.remove(id)` or `client.devices.unregisterWebPush(reg)`. */\n async remove(): Promise<void> {\n await this.http.delete<void>(\"/me/push-subscription\");\n }\n\n /** Subscribe this browser and store the subscription. Ask for\n * notification permission before calling. Throws when push isn't set up\n * on the deployment.\n * @deprecated Use `client.devices.registerWebPush(registration)`. */\n async enable(registration: PushCapableRegistration): Promise<PushStatus> {\n const { vapid_public_key } = await this.status();\n if (!vapid_public_key) {\n throw new Error(\"@takeal/cusfront-sdk: push notifications are not enabled on this deployment\");\n }\n const sub = await registration.pushManager.subscribe({\n userVisibleOnly: true,\n applicationServerKey: base64UrlToBytes(vapid_public_key),\n });\n const json = sub.toJSON();\n if (!json.endpoint || !json.keys?.p256dh || !json.keys.auth) {\n throw new Error(\"@takeal/cusfront-sdk: the browser returned an incomplete push subscription\");\n }\n return this.save({\n endpoint: json.endpoint,\n keys: { p256dh: json.keys.p256dh, auth: json.keys.auth },\n });\n }\n\n /** Unsubscribe this browser and delete the stored subscription.\n * @deprecated Use `client.devices.unregisterWebPush(registration)`. */\n async disable(registration: PushCapableRegistration): Promise<void> {\n const sub = await registration.pushManager.getSubscription();\n if (sub) await sub.unsubscribe();\n await this.remove();\n }\n}\n\n/** URL-safe base64 (padding optional) → bytes. */\nexport function base64UrlToBytes(input: string): Uint8Array {\n const b64 = input.replace(/-/g, \"+\").replace(/_/g, \"/\");\n const padded = b64 + \"=\".repeat((4 - (b64.length % 4)) % 4);\n const bin = atob(padded);\n const out = new Uint8Array(bin.length);\n for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);\n return out;\n}\n","import type { HttpClient } from \"../http.js\";\nimport type { ClientPlatform, ResolvedClientDescriptor } from \"../client-platform.js\";\nimport { base64UrlToBytes, type PushCapableRegistration } from \"./push.js\";\n\n/**\n * Devices resource — `client.devices.*`.\n *\n * A user has many devices: each browser with a Web Push subscription, each\n * phone with an FCM / APNs token, and a marker for \"uses the Telegram Mini\n * App\". The server picks the notification channel from them: a mobile app\n * first, otherwise the device seen most recently.\n *\n * The usual browser flow, once notification permission is granted:\n *\n * ```ts\n * const reg = await navigator.serviceWorker.ready;\n * const device = await client.devices.registerWebPush(reg, { label: \"Chrome on Mac\" });\n * // later, from a settings screen:\n * await client.devices.unregisterWebPush(reg);\n * ```\n */\n\nexport type DeviceKind = \"webpush\" | \"fcm\" | \"apns\" | \"telegram_miniapp\";\n\nexport type DevicePlatform = \"pwa\" | \"web\" | \"ios\" | \"android\" | \"telegram\";\n\nexport interface Device {\n id: string;\n kind: DeviceKind;\n platform: DevicePlatform;\n /** Free-form name the app gave it (\"Chrome on Mac\"), or `null`. */\n label: string | null;\n locale: string | null;\n app_version: string | null;\n created_at: string;\n last_seen_at: string;\n /** Set when the device no longer receives anything (the push endpoint is\n * gone, or someone switched it off). */\n disabled_at: string | null;\n /** `true` when it was registered from the session this client holds. */\n is_current: boolean;\n}\n\n/** `PushSubscription.toJSON()` minus the parts the server doesn't need. */\nexport interface WebPushCredential {\n /** `PushSubscription.endpoint`; must be https. */\n endpoint: string;\n keys: {\n /** URL-safe base64. */\n p256dh: string;\n /** URL-safe base64. */\n auth: string;\n };\n}\n\n/** FCM registration token or APNs device token. */\nexport interface MobilePushCredential {\n token: string;\n}\n\nexport type RegisterDeviceInput =\n | {\n kind: \"webpush\";\n platform: DevicePlatform;\n credential: WebPushCredential;\n label?: string;\n locale?: string;\n app_version?: string;\n }\n | {\n kind: \"fcm\" | \"apns\";\n platform: DevicePlatform;\n credential: MobilePushCredential;\n label?: string;\n locale?: string;\n app_version?: string;\n }\n | {\n kind: \"telegram_miniapp\";\n platform: DevicePlatform;\n /** Nothing to send: the device is a marker. */\n credential: Record<string, never>;\n label?: string;\n locale?: string;\n app_version?: string;\n };\n\nexport interface RegisteredDevice {\n id: string;\n kind: DeviceKind;\n platform: DevicePlatform;\n /** VAPID public key (URL-safe base64) for `pushManager.subscribe`;\n * `null` when push is not set up on this deployment. */\n vapid_public_key: string | null;\n}\n\nexport interface RegisterWebPushOptions {\n /** A name to show in the user's device list (\"Chrome on Mac\"). */\n label?: string;\n /** Skip the key lookup when you already hold the deployment's VAPID\n * public key (from an earlier `register` result, for example). */\n vapidPublicKey?: string;\n}\n\nexport interface UnregisterWebPushOptions {\n /** The device to delete, from an earlier `registerWebPush` result. When\n * omitted, every Web Push device registered from this session goes. */\n deviceId?: string;\n}\n\n/** Client platform → the platform the device list uses. */\nexport function devicePlatformOf(platform: ClientPlatform): DevicePlatform {\n return platform === \"telegram-miniapp\" ? \"telegram\" : platform;\n}\n\nexport class DevicesResource {\n constructor(\n private readonly http: HttpClient,\n private readonly client: ResolvedClientDescriptor,\n ) {}\n\n /** Every device the user has, disabled ones included. */\n async list(): Promise<Device[]> {\n return this.http.get<Device[]>(\"/me/devices\");\n }\n\n /** Register a device, or refresh it when the same credential is already\n * known (then `last_seen_at`, `label` and `app_version` update and a\n * disabled device comes back). `app_version` defaults to the client\n * version sent in `X-Takeal-Client`.\n *\n * Errors: 400 `validation`; 409 `push_disabled` for `webpush` when the\n * deployment has no VAPID keys. */\n async register(input: RegisterDeviceInput): Promise<RegisteredDevice> {\n return this.http.put<RegisteredDevice>(\"/me/devices\", {\n body: { app_version: this.client.version, ...input },\n });\n }\n\n /** Delete one device. 404 when it isn't the user's. */\n async remove(id: string): Promise<void> {\n await this.http.delete<void>(`/me/devices/${encodeURIComponent(id)}`);\n }\n\n /** Subscribe this browser to Web Push and register it as a device. Ask\n * for notification permission before calling. Throws when push isn't\n * set up on the deployment. */\n async registerWebPush(\n registration: PushCapableRegistration,\n opts: RegisterWebPushOptions = {},\n ): Promise<RegisteredDevice> {\n const key = opts.vapidPublicKey ?? (await this.vapidPublicKey());\n if (!key) {\n throw new Error(\"@takeal/cusfront-sdk: push notifications are not enabled on this deployment\");\n }\n const sub = await registration.pushManager.subscribe({\n userVisibleOnly: true,\n applicationServerKey: base64UrlToBytes(key),\n });\n const json = sub.toJSON();\n if (!json.endpoint || !json.keys?.p256dh || !json.keys.auth) {\n throw new Error(\"@takeal/cusfront-sdk: the browser returned an incomplete push subscription\");\n }\n return this.register({\n kind: \"webpush\",\n platform: devicePlatformOf(this.client.platform),\n credential: {\n endpoint: json.endpoint,\n keys: { p256dh: json.keys.p256dh, auth: json.keys.auth },\n },\n ...(opts.label ? { label: opts.label } : {}),\n });\n }\n\n /** Unsubscribe this browser from Web Push and delete the matching device\n * (see {@link UnregisterWebPushOptions}). Safe when nothing is\n * registered. */\n async unregisterWebPush(\n registration: PushCapableRegistration,\n opts: UnregisterWebPushOptions = {},\n ): Promise<void> {\n const sub = await registration.pushManager.getSubscription();\n if (sub) await sub.unsubscribe();\n if (opts.deviceId) {\n await this.remove(opts.deviceId);\n return;\n }\n const mine = (await this.list()).filter((d) => d.kind === \"webpush\" && d.is_current);\n for (const d of mine) await this.remove(d.id);\n }\n\n private async vapidPublicKey(): Promise<string | null> {\n const { vapid_public_key } = await this.http.get<{ vapid_public_key?: string | null }>(\n \"/me/push-subscription\",\n );\n return vapid_public_key ?? null;\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/resources/push.ts","../../src/resources/devices.ts"],"names":[],"mappings":";AAwGO,SAAS,iBAAiB,KAAA,EAA2B;AAC1D,EAAA,MAAM,GAAA,GAAM,MAAM,OAAA,CAAQ,IAAA,EAAM,GAAG,CAAA,CAAE,OAAA,CAAQ,MAAM,GAAG,CAAA;AACtD,EAAA,MAAM,MAAA,GAAS,MAAM,GAAA,CAAI,MAAA,CAAA,CAAQ,IAAK,GAAA,CAAI,MAAA,GAAS,KAAM,CAAC,CAAA;AAC1D,EAAA,MAAM,GAAA,GAAM,KAAK,MAAM,CAAA;AACvB,EAAA,MAAM,GAAA,GAAM,IAAI,UAAA,CAAW,GAAA,CAAI,MAAM,CAAA;AACrC,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,GAAA,CAAI,MAAA,EAAQ,CAAA,EAAA,EAAK,GAAA,CAAI,CAAC,CAAA,GAAI,GAAA,CAAI,UAAA,CAAW,CAAC,CAAA;AAC9D,EAAA,OAAO,GAAA;AACT;;;ACAO,SAAS,iBAAiB,QAAA,EAA0C;AACzE,EAAA,OAAO,QAAA,KAAa,qBAAqB,UAAA,GAAa,QAAA;AACxD;AAEO,IAAM,kBAAN,MAAsB;AAAA,EAC3B,WAAA,CACmB,MACA,MAAA,EACjB;AAFiB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AACA,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAAA,EAChB;AAAA;AAAA,EAGH,MAAM,IAAA,GAA0B;AAC9B,IAAA,OAAO,IAAA,CAAK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A,CAAO,QAAQ,CAAA;AAAA,MAC/C,UAAA,EAAY;AAAA,QACV,UAAU,IAAA,CAAK,QAAA;AAAA,QACf,IAAA,EAAM,EAAE,MAAA,EAAQ,IAAA,CAAK,KAAK,MAAA,EAAQ,IAAA,EAAM,IAAA,CAAK,IAAA,CAAK,IAAA;AAAK,OACzD;AAAA,MACA,GAAI,KAAK,KAAA,GAAQ,EAAE,OAAO,IAAA,CAAK,KAAA,KAAU;AAAC,KAC3C,CAAA;AAAA,EACH;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,iBAAA,CACJ,YAAA,EACA,IAAA,GAAiC,EAAC,EACnB;AACf,IAAA,MAAM,GAAA,GAAM,MAAM,YAAA,CAAa,WAAA,CAAY,eAAA,EAAgB;AAC3D,IAAA,IAAI,GAAA,EAAK,MAAM,GAAA,CAAI,WAAA,EAAY;AAC/B,IAAA,IAAI,KAAK,QAAA,EAAU;AACjB,MAAA,MAAM,IAAA,CAAK,MAAA,CAAO,IAAA,CAAK,QAAQ,CAAA;AAC/B,MAAA;AAAA,IACF;AACA,IAAA,MAAM,IAAA,GAAA,CAAQ,MAAM,IAAA,CAAK,IAAA,EAAK,EAAG,MAAA,CAAO,CAAC,CAAA,KAAM,CAAA,CAAE,IAAA,KAAS,SAAA,IAAa,CAAA,CAAE,UAAU,CAAA;AACnF,IAAA,KAAA,MAAW,KAAK,IAAA,EAAM,MAAM,IAAA,CAAK,MAAA,CAAO,EAAE,EAAE,CAAA;AAAA,EAC9C;AAAA,EAEA,MAAc,cAAA,GAAyC;AACrD,IAAA,MAAM,EAAE,gBAAA,EAAiB,GAAI,MAAM,KAAK,IAAA,CAAK,GAAA;AAAA,MAC3C;AAAA,KACF;AACA,IAAA,OAAO,gBAAA,IAAoB,IAAA;AAAA,EAC7B;AACF","file":"devices.js","sourcesContent":["import type { HttpClient } from \"../http.js\";\n\n/**\n * Push resource — `client.push.*`.\n *\n * Web Push for the signed-in user, through the older single-subscription\n * endpoint. The API now keeps one device per browser (see\n * `client.devices`), and this endpoint is an alias over the Web Push\n * devices: it keeps working, but new code should call\n * `client.devices.registerWebPush(reg)` / `unregisterWebPush(reg)` instead.\n *\n * Your service worker shows the notification: the payload is JSON with\n * `title`, `body` and `url` (where a click should lead).\n */\n\nexport interface PushStatus {\n /** `true` when a subscription is stored for this user. */\n subscribed: boolean;\n /** Host of the stored endpoint, e.g. `fcm.googleapis.com`. */\n endpoint_host?: string | null;\n /** VAPID public key (URL-safe base64) for `pushManager.subscribe`.\n * `null` when push is not set up on this deployment. */\n vapid_public_key?: string | null;\n}\n\nexport interface PushSubscriptionInput {\n /** `PushSubscription.endpoint`; must be https. */\n endpoint: string;\n keys: {\n /** URL-safe base64. */\n p256dh: string;\n /** URL-safe base64. */\n auth: string;\n };\n}\n\n/** The part of `ServiceWorkerRegistration` the SDK needs. Typed\n * structurally so the core stays free of DOM lib types. */\nexport interface PushCapableRegistration {\n pushManager: {\n getSubscription(): Promise<{ unsubscribe(): Promise<boolean> } | null>;\n subscribe(options: {\n userVisibleOnly: boolean;\n applicationServerKey: Uint8Array;\n }): Promise<{ toJSON(): { endpoint?: string; keys?: Record<string, string> } }>;\n };\n}\n\nexport class PushResource {\n constructor(private readonly http: HttpClient) {}\n\n /** Whether the user is subscribed, plus the VAPID key to subscribe with. */\n async status(): Promise<PushStatus> {\n return this.http.get<PushStatus>(\"/me/push-subscription\");\n }\n\n /** Store a subscription you created yourself.\n * 409 `push_disabled` when the deployment has no VAPID keys.\n * @deprecated Use `client.devices.register({ kind: \"webpush\", ... })`. */\n async save(input: PushSubscriptionInput): Promise<PushStatus> {\n return this.http.put<PushStatus>(\"/me/push-subscription\", { body: input });\n }\n\n /** Delete the stored subscription. Safe when nothing is stored.\n * @deprecated Use `client.devices.remove(id)` or `client.devices.unregisterWebPush(reg)`. */\n async remove(): Promise<void> {\n await this.http.delete<void>(\"/me/push-subscription\");\n }\n\n /** Subscribe this browser and store the subscription. Ask for\n * notification permission before calling. Throws when push isn't set up\n * on the deployment.\n * @deprecated Use `client.devices.registerWebPush(registration)`. */\n async enable(registration: PushCapableRegistration): Promise<PushStatus> {\n const { vapid_public_key } = await this.status();\n if (!vapid_public_key) {\n throw new Error(\n \"@takeal/cusfront-sdk: push notifications are not enabled on this deployment\",\n );\n }\n const sub = await registration.pushManager.subscribe({\n userVisibleOnly: true,\n applicationServerKey: base64UrlToBytes(vapid_public_key),\n });\n const json = sub.toJSON();\n if (!json.endpoint || !json.keys?.p256dh || !json.keys.auth) {\n throw new Error(\"@takeal/cusfront-sdk: the browser returned an incomplete push subscription\");\n }\n return this.save({\n endpoint: json.endpoint,\n keys: { p256dh: json.keys.p256dh, auth: json.keys.auth },\n });\n }\n\n /** Unsubscribe this browser and delete the stored subscription.\n * @deprecated Use `client.devices.unregisterWebPush(registration)`. */\n async disable(registration: PushCapableRegistration): Promise<void> {\n const sub = await registration.pushManager.getSubscription();\n if (sub) await sub.unsubscribe();\n await this.remove();\n }\n}\n\n/** URL-safe base64 (padding optional) → bytes. */\nexport function base64UrlToBytes(input: string): Uint8Array {\n const b64 = input.replace(/-/g, \"+\").replace(/_/g, \"/\");\n const padded = b64 + \"=\".repeat((4 - (b64.length % 4)) % 4);\n const bin = atob(padded);\n const out = new Uint8Array(bin.length);\n for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);\n return out;\n}\n","import type { HttpClient } from \"../http.js\";\nimport type { ClientPlatform, ResolvedClientDescriptor } from \"../client-platform.js\";\nimport { base64UrlToBytes, type PushCapableRegistration } from \"./push.js\";\n\n/**\n * Devices resource — `client.devices.*`.\n *\n * A user has many devices: each browser with a Web Push subscription, each\n * phone with an FCM / APNs token, and a marker for \"uses the Telegram Mini\n * App\". The server picks the notification channel from them: a mobile app\n * first, otherwise the device seen most recently.\n *\n * The usual browser flow, once notification permission is granted:\n *\n * ```ts\n * const reg = await navigator.serviceWorker.ready;\n * const device = await client.devices.registerWebPush(reg, { label: \"Chrome on Mac\" });\n * // later, from a settings screen:\n * await client.devices.unregisterWebPush(reg);\n * ```\n */\n\nexport type DeviceKind = \"webpush\" | \"fcm\" | \"apns\" | \"telegram_miniapp\";\n\nexport type DevicePlatform = \"pwa\" | \"web\" | \"ios\" | \"android\" | \"telegram\";\n\nexport interface Device {\n id: string;\n kind: DeviceKind;\n platform: DevicePlatform;\n /** Free-form name the app gave it (\"Chrome on Mac\"), or `null`. */\n label: string | null;\n locale: string | null;\n app_version: string | null;\n created_at: string;\n last_seen_at: string;\n /** Set when the device no longer receives anything (the push endpoint is\n * gone, or someone switched it off). */\n disabled_at: string | null;\n /** `true` when it was registered from the session this client holds. */\n is_current: boolean;\n}\n\n/** `PushSubscription.toJSON()` minus the parts the server doesn't need. */\nexport interface WebPushCredential {\n /** `PushSubscription.endpoint`; must be https. */\n endpoint: string;\n keys: {\n /** URL-safe base64. */\n p256dh: string;\n /** URL-safe base64. */\n auth: string;\n };\n}\n\n/** FCM registration token or APNs device token. */\nexport interface MobilePushCredential {\n token: string;\n}\n\nexport type RegisterDeviceInput =\n | {\n kind: \"webpush\";\n platform: DevicePlatform;\n credential: WebPushCredential;\n label?: string;\n locale?: string;\n app_version?: string;\n }\n | {\n kind: \"fcm\" | \"apns\";\n platform: DevicePlatform;\n credential: MobilePushCredential;\n label?: string;\n locale?: string;\n app_version?: string;\n }\n | {\n kind: \"telegram_miniapp\";\n platform: DevicePlatform;\n /** Nothing to send: the device is a marker. */\n credential: Record<string, never>;\n label?: string;\n locale?: string;\n app_version?: string;\n };\n\nexport interface RegisteredDevice {\n id: string;\n kind: DeviceKind;\n platform: DevicePlatform;\n /** VAPID public key (URL-safe base64) for `pushManager.subscribe`;\n * `null` when push is not set up on this deployment. */\n vapid_public_key: string | null;\n}\n\nexport interface RegisterWebPushOptions {\n /** A name to show in the user's device list (\"Chrome on Mac\"). */\n label?: string;\n /** Skip the key lookup when you already hold the deployment's VAPID\n * public key (from an earlier `register` result, for example). */\n vapidPublicKey?: string;\n}\n\nexport interface UnregisterWebPushOptions {\n /** The device to delete, from an earlier `registerWebPush` result. When\n * omitted, every Web Push device registered from this session goes. */\n deviceId?: string;\n}\n\n/** Client platform → the platform the device list uses. */\nexport function devicePlatformOf(platform: ClientPlatform): DevicePlatform {\n return platform === \"telegram-miniapp\" ? \"telegram\" : platform;\n}\n\nexport class DevicesResource {\n constructor(\n private readonly http: HttpClient,\n private readonly client: ResolvedClientDescriptor,\n ) {}\n\n /** Every device the user has, disabled ones included. */\n async list(): Promise<Device[]> {\n return this.http.get<Device[]>(\"/me/devices\");\n }\n\n /** Register a device, or refresh it when the same credential is already\n * known (then `last_seen_at`, `label` and `app_version` update and a\n * disabled device comes back). `app_version` defaults to the client\n * version sent in `X-Takeal-Client`.\n *\n * Errors: 400 `validation`; 409 `push_disabled` for `webpush` when the\n * deployment has no VAPID keys. */\n async register(input: RegisterDeviceInput): Promise<RegisteredDevice> {\n return this.http.put<RegisteredDevice>(\"/me/devices\", {\n body: { app_version: this.client.version, ...input },\n });\n }\n\n /** Delete one device. 404 when it isn't the user's. */\n async remove(id: string): Promise<void> {\n await this.http.delete<void>(`/me/devices/${encodeURIComponent(id)}`);\n }\n\n /** Subscribe this browser to Web Push and register it as a device. Ask\n * for notification permission before calling. Throws when push isn't\n * set up on the deployment. */\n async registerWebPush(\n registration: PushCapableRegistration,\n opts: RegisterWebPushOptions = {},\n ): Promise<RegisteredDevice> {\n const key = opts.vapidPublicKey ?? (await this.vapidPublicKey());\n if (!key) {\n throw new Error(\n \"@takeal/cusfront-sdk: push notifications are not enabled on this deployment\",\n );\n }\n const sub = await registration.pushManager.subscribe({\n userVisibleOnly: true,\n applicationServerKey: base64UrlToBytes(key),\n });\n const json = sub.toJSON();\n if (!json.endpoint || !json.keys?.p256dh || !json.keys.auth) {\n throw new Error(\"@takeal/cusfront-sdk: the browser returned an incomplete push subscription\");\n }\n return this.register({\n kind: \"webpush\",\n platform: devicePlatformOf(this.client.platform),\n credential: {\n endpoint: json.endpoint,\n keys: { p256dh: json.keys.p256dh, auth: json.keys.auth },\n },\n ...(opts.label ? { label: opts.label } : {}),\n });\n }\n\n /** Unsubscribe this browser from Web Push and delete the matching device\n * (see {@link UnregisterWebPushOptions}). Safe when nothing is\n * registered. */\n async unregisterWebPush(\n registration: PushCapableRegistration,\n opts: UnregisterWebPushOptions = {},\n ): Promise<void> {\n const sub = await registration.pushManager.getSubscription();\n if (sub) await sub.unsubscribe();\n if (opts.deviceId) {\n await this.remove(opts.deviceId);\n return;\n }\n const mine = (await this.list()).filter((d) => d.kind === \"webpush\" && d.is_current);\n for (const d of mine) await this.remove(d.id);\n }\n\n private async vapidPublicKey(): Promise<string | null> {\n const { vapid_public_key } = await this.http.get<{ vapid_public_key?: string | null }>(\n \"/me/push-subscription\",\n );\n return vapid_public_key ?? null;\n }\n}\n"]}
@@ -42,7 +42,9 @@ var DocumentsResource = class {
42
42
  }
43
43
  /** Every saved text of a document, newest first, with the date each took effect. */
44
44
  async versions(slug) {
45
- return this.http.get(`/documents/${encodeURIComponent(slug)}/versions`);
45
+ return this.http.get(
46
+ `/documents/${encodeURIComponent(slug)}/versions`
47
+ );
46
48
  }
47
49
  /** The document as it read in one version. */
48
50
  async version(slug, version) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/resources/documents.ts"],"names":[],"mappings":";;;AA4KO,IAAM,oBAAN,MAAwB;AAAA,EAC7B,YAA6B,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAmB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMhD,MAAM,IAAA,CAAK,KAAA,GAA2B,EAAC,EAA0B;AAC/D,IAAA,MAAM,CAAA,GAAI,IAAI,eAAA,EAAgB;AAC9B,IAAA,IAAI,MAAM,QAAA,EAAU,CAAA,CAAE,GAAA,CAAI,UAAA,EAAY,MAAM,QAAQ,CAAA;AACpD,IAAA,IAAI,MAAM,QAAA,EAAU,CAAA,CAAE,GAAA,CAAI,WAAA,EAAa,MAAM,QAAQ,CAAA;AACrD,IAAA,IA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EAAA,YAAc,IAAA,GAAO,KAAK,EAAA,CAAG,WAAA,KAAgB,IAAA,CAAK,EAAA;AAClE,IAAA,MAAM,KAAK,EAAA,GAAK,CAAA,IAAA,EAAO,kBAAA,CAAmB,EAAE,CAAC,CAAA,CAAA,GAAK,EAAA;AAClD,IAAA,OAAO,IAAA,CAAK,KAAK,GAAA,CAAc,CAAA,WAAA,EAAc,mBAAmB,IAAI,CAAC,CAAA,EAAG,EAAE,CAAA,CAAE,CAAA;AAAA,EAC9E;AAAA;AAAA,EAGA,MAAM,SAAS,IAAA,EAAiD;AAC9D,IAAA,OAAO,KAAK,IAAA,CAAK,GAAA,CAA8B,cAAc,kBAAA,CAAmB,IAAI,CAAC,CAAA,SAAA,CAAW,CAAA;AAAA,EAClG;AAAA;AAAA,EAGA,MAAM,OAAA,CAAQ,IAAA,EAAc,OAAA,EAAoC;AAC9D,IAAA,OAAO,IAAA,CAAK,KAAK,GAAA,CAAc,CAAA,WAAA,EAAc,mBAAmB,IAAI,CAAC,CAAA,UAAA,EAAa,OAAO,CAAA,CAAE,CAAA;AAAA,EAC7F;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,QAAA,CAAS,SAAiB,IAAA,EAAsB;AAC9C,IAAA,IAAI,eAAA,CAAgB,IAAA,CAAK,IAAI,CAAA,EAAG,OAAO,IAAA;AACvC,IAAA,OAAO,CAAA,EAAG,OAAA,CAAQ,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAC,CAAA,EAAG,IAAA,CAAK,UAAA,CAAW,GAAG,CAAA,GAAI,EAAA,GAAK,GAAG,GAAG,IAAI,CAAA,CAAA;AAAA,EAC/E;AACF","file":"documents.cjs","sourcesContent":["import type { HttpClient } from \"../http.js\";\n\n/**\n * Documents resource: `client.documents.*`.\n *\n * Everything the operators write lives in one tree: blog posts, the\n * knowledge base, legal pages, internal notes. Every call here works before\n * the user signs in and shows more once they have: a signed-in user sees the\n * documents marked for users, staff see theirs. The SDK sends the session\n * token when it has one, so the same call serves the public site and the\n * signed-in cabinet.\n *\n * A document arrives as a list of typed blocks. `body_blocks` is flat; map\n * each `type` onto your own component and the document inherits your site's\n * styling. `body_markdown` is there too if you'd rather run your own renderer.\n *\n * ```ts\n * // The knowledge base: folders and articles for a sidebar.\n * const tree = await client.documents.tree({ category: \"knowledge-base\" });\n *\n * // One article, with the text in force today.\n * const doc = await client.documents.get(\"how-to-top-up\");\n *\n * // A legal page as it read on a given day, and its history.\n * const then = await client.documents.get(\"offer\", { at: \"2026-01-01T00:00:00Z\" });\n * const versions = await client.documents.versions(\"offer\");\n *\n * doc.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={client.assetUrl(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 * Links between documents come out as site paths: `/blog/<slug>` for a post,\n * `/docs/<slug>` for everything else (`site_path` on each document says which\n * one it is). Route those two prefixes to your document pages and links keep\n * working after a document is renamed or moved.\n */\n\n/** Category keys: the four folders at the top of the tree. */\nexport type DocumentCategory = \"blog\" | \"knowledge-base\" | \"legal\" | \"internal\";\n\n/** Who may read a document. */\nexport type DocumentScope = \"public\" | \"users\" | \"staff\" | \"operators\";\n\n/** One node of a document body. Discriminated on `type`. */\nexport type DocumentBlock =\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\n/** One step of the folder trail, root first. */\nexport interface DocumentPathStep {\n id: string;\n key: string;\n title: string;\n}\n\nexport interface Document {\n /** Permanent address. Link by this; it survives renames and moves. */\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: DocumentBlock[];\n tags: string[];\n /** Present only when the document 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 /** Category the document sits in. */\n category: DocumentCategory | string;\n /** Folder trail, root first. */\n path: DocumentPathStep[];\n /** Who may read it. */\n read_scope: DocumentScope;\n /** Number of the text shown. */\n version: number;\n /** When the text shown took effect. */\n effective_from: string;\n /** Path under the site root where this document is read. */\n site_path: string;\n}\n\nexport interface DocumentListInput {\n /** Category key. */\n category?: DocumentCategory | string;\n /** Only documents in this folder and the folders under it. */\n folderId?: string;\n /** Only documents carrying this tag. */\n tag?: string;\n /** Only documents in this locale. */\n locale?: string;\n /** Words to search for in the title and the text. */\n q?: string;\n /** 1-based. Default 1. */\n page?: number;\n /** 1..=50. Default 10. */\n perPage?: number;\n}\n\nexport interface DocumentList {\n documents: Document[];\n total: number;\n page: number;\n per_page: number;\n}\n\n/** A folder as it appears in the navigation tree. */\nexport interface DocumentFolder {\n id: string;\n parent_id: string | null;\n key: string;\n title: string;\n description: string;\n position: number;\n}\n\n/** A document as it appears in the navigation tree: enough for a link. */\nexport interface DocumentTreeEntry {\n folder_id: string;\n slug: string;\n title: string;\n excerpt: string;\n tags: string[];\n position: number;\n updated_at: string;\n site_path: string;\n}\n\nexport interface DocumentTree {\n /** Folders with at least one document you may read under them, plus the categories. */\n folders: DocumentFolder[];\n /** Published documents you may read, in folder order. */\n documents: DocumentTreeEntry[];\n}\n\n/** One saved text of a document, without the text itself. */\nexport interface DocumentVersionSummary {\n version: number;\n title: string;\n /** When this text took effect. */\n effective_from: string;\n /** What changed, in the editor's words. Often empty. */\n note: string;\n changed_at: string;\n}\n\nexport interface DocumentTag {\n tag: string;\n /** Published documents you may read that carry it. */\n count: number;\n}\n\nexport class DocumentsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Published documents you may read, paged. The blog comes newest first,\n * other categories in the order set by the editors.\n */\n async list(input: DocumentListInput = {}): Promise<DocumentList> {\n const q = new URLSearchParams();\n if (input.category) q.set(\"category\", input.category);\n if (input.folderId) q.set(\"folder_id\", input.folderId);\n if (input.tag) q.set(\"tag\", input.tag);\n if (input.locale) q.set(\"locale\", input.locale);\n if (input.q) q.set(\"q\", input.q);\n if (input.page) q.set(\"page\", String(input.page));\n if (input.perPage) q.set(\"per_page\", String(input.perPage));\n const qs = q.toString();\n return this.http.get<DocumentList>(`/documents${qs ? `?${qs}` : \"\"}`);\n }\n\n /** Folders and documents for a sidebar or a table of contents. */\n async tree(input: { category?: DocumentCategory | string } = {}): Promise<DocumentTree> {\n const qs = input.category ? `?category=${encodeURIComponent(input.category)}` : \"\";\n return this.http.get<DocumentTree>(`/documents/tree${qs}`);\n }\n\n /** Every tag on a document you may read, most used first. */\n async tags(): Promise<DocumentTag[]> {\n return this.http.get<DocumentTag[]>(\"/documents/tags\");\n }\n\n /**\n * One document by its address. Without `at`, the text in force now; with\n * `at` (an ISO 8601 moment), the text that was in force then. Unknown\n * addresses and documents above your level are a 404.\n */\n async get(slug: string, opts: { at?: string | Date } = {}): Promise<Document> {\n const at = opts.at instanceof Date ? opts.at.toISOString() : opts.at;\n const qs = at ? `?at=${encodeURIComponent(at)}` : \"\";\n return this.http.get<Document>(`/documents/${encodeURIComponent(slug)}${qs}`);\n }\n\n /** Every saved text of a document, newest first, with the date each took effect. */\n async versions(slug: string): Promise<DocumentVersionSummary[]> {\n return this.http.get<DocumentVersionSummary[]>(`/documents/${encodeURIComponent(slug)}/versions`);\n }\n\n /** The document as it read in one version. */\n async version(slug: string, version: number): Promise<Document> {\n return this.http.get<Document>(`/documents/${encodeURIComponent(slug)}/versions/${version}`);\n }\n\n /**\n * Absolute URL for an image path returned inside a document (`cover_url`,\n * or an image block's `url`). Handy when the app renders on a different\n * origin 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"]}
1
+ {"version":3,"sources":["../../src/resources/documents.ts"],"names":[],"mappings":";;;AA4KO,IAAM,oBAAN,MAAwB;AAAA,EAC7B,YAA6B,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAmB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMhD,MAAM,IAAA,CAAK,KAAA,GAA2B,EAAC,EAA0B;AAC/D,IAAA,MAAM,CAAA,GAAI,IAAI,eAAA,EAAgB;AAC9B,IAAA,IAAI,MAAM,QAAA,EAAU,CAAA,CAAE,GAAA,CAAI,UAAA,EAAY,MAAM,QAAQ,CAAA;AACpD,IAAA,IAAI,MAAM,QAAA,EAAU,CAAA,CAAE,GAAA,CAAI,WAAA,EAAa,MAAM,QAAQ,CAAA;AACrD,IAAA,IAAI,MAAM,GAAA,EAAK,CAAA,CAAE,GAAA,CAAI,KAAA,EAAO,MAAM,GAAG,CAAA;AACrC,IAAA,IAAI,MAAM,MAAA,EAAQ,CAAA,CAAE,GAAA,CAAI,QAAA,EAAU,MAAM,MAAM,CAAA;AAC9C,IAAA,IAAI,MAAM,CAAA,EAAG,CAAA,CAAE,GAAA,CAAI,GAAA,EAAK,MAAM,CAAC,CAAA;AAC/B,IAAA,IAAI,KAAA,CAAM,MAAM,CAAA,CAAE,GAAA,CAAI,QAAQ,MAAA,CAAO,KAAA,CAAM,IAAI,CAAC,CAAA;AAChD,IAAA,IAAI,KAAA,CAAM,SAAS,CAAA,CAAE,GAAA,CAAI,YAAY,MAAA,CAAO,KAAA,CAAM,OAAO,CAAC,CAAA;AAC1D,IAAA,MAAM,EAAA,GA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GA,MAAM,OAAA,CAAQ,IAAA,EAAc,OAAA,EAAoC;AAC9D,IAAA,OAAO,IAAA,CAAK,KAAK,GAAA,CAAc,CAAA,WAAA,EAAc,mBAAmB,IAAI,CAAC,CAAA,UAAA,EAAa,OAAO,CAAA,CAAE,CAAA;AAAA,EAC7F;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,QAAA,CAAS,SAAiB,IAAA,EAAsB;AAC9C,IAAA,IAAI,eAAA,CAAgB,IAAA,CAAK,IAAI,CAAA,EAAG,OAAO,IAAA;AACvC,IAAA,OAAO,CAAA,EAAG,OAAA,CAAQ,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAC,CAAA,EAAG,IAAA,CAAK,UAAA,CAAW,GAAG,CAAA,GAAI,EAAA,GAAK,GAAG,GAAG,IAAI,CAAA,CAAA;AAAA,EAC/E;AACF","file":"documents.cjs","sourcesContent":["import type { HttpClient } from \"../http.js\";\n\n/**\n * Documents resource: `client.documents.*`.\n *\n * Everything the operators write lives in one tree: blog posts, the\n * knowledge base, legal pages, internal notes. Every call here works before\n * the user signs in and shows more once they have: a signed-in user sees the\n * documents marked for users, staff see theirs. The SDK sends the session\n * token when it has one, so the same call serves the public site and the\n * signed-in cabinet.\n *\n * A document arrives as a list of typed blocks. `body_blocks` is flat; map\n * each `type` onto your own component and the document inherits your site's\n * styling. `body_markdown` is there too if you'd rather run your own renderer.\n *\n * ```ts\n * // The knowledge base: folders and articles for a sidebar.\n * const tree = await client.documents.tree({ category: \"knowledge-base\" });\n *\n * // One article, with the text in force today.\n * const doc = await client.documents.get(\"how-to-top-up\");\n *\n * // A legal page as it read on a given day, and its history.\n * const then = await client.documents.get(\"offer\", { at: \"2026-01-01T00:00:00Z\" });\n * const versions = await client.documents.versions(\"offer\");\n *\n * doc.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={client.assetUrl(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 * Links between documents come out as site paths: `/blog/<slug>` for a post,\n * `/docs/<slug>` for everything else (`site_path` on each document says which\n * one it is). Route those two prefixes to your document pages and links keep\n * working after a document is renamed or moved.\n */\n\n/** Category keys: the four folders at the top of the tree. */\nexport type DocumentCategory = \"blog\" | \"knowledge-base\" | \"legal\" | \"internal\";\n\n/** Who may read a document. */\nexport type DocumentScope = \"public\" | \"users\" | \"staff\" | \"operators\";\n\n/** One node of a document body. Discriminated on `type`. */\nexport type DocumentBlock =\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\n/** One step of the folder trail, root first. */\nexport interface DocumentPathStep {\n id: string;\n key: string;\n title: string;\n}\n\nexport interface Document {\n /** Permanent address. Link by this; it survives renames and moves. */\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: DocumentBlock[];\n tags: string[];\n /** Present only when the document 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 /** Category the document sits in. */\n category: DocumentCategory | string;\n /** Folder trail, root first. */\n path: DocumentPathStep[];\n /** Who may read it. */\n read_scope: DocumentScope;\n /** Number of the text shown. */\n version: number;\n /** When the text shown took effect. */\n effective_from: string;\n /** Path under the site root where this document is read. */\n site_path: string;\n}\n\nexport interface DocumentListInput {\n /** Category key. */\n category?: DocumentCategory | string;\n /** Only documents in this folder and the folders under it. */\n folderId?: string;\n /** Only documents carrying this tag. */\n tag?: string;\n /** Only documents in this locale. */\n locale?: string;\n /** Words to search for in the title and the text. */\n q?: string;\n /** 1-based. Default 1. */\n page?: number;\n /** 1..=50. Default 10. */\n perPage?: number;\n}\n\nexport interface DocumentList {\n documents: Document[];\n total: number;\n page: number;\n per_page: number;\n}\n\n/** A folder as it appears in the navigation tree. */\nexport interface DocumentFolder {\n id: string;\n parent_id: string | null;\n key: string;\n title: string;\n description: string;\n position: number;\n}\n\n/** A document as it appears in the navigation tree: enough for a link. */\nexport interface DocumentTreeEntry {\n folder_id: string;\n slug: string;\n title: string;\n excerpt: string;\n tags: string[];\n position: number;\n updated_at: string;\n site_path: string;\n}\n\nexport interface DocumentTree {\n /** Folders with at least one document you may read under them, plus the categories. */\n folders: DocumentFolder[];\n /** Published documents you may read, in folder order. */\n documents: DocumentTreeEntry[];\n}\n\n/** One saved text of a document, without the text itself. */\nexport interface DocumentVersionSummary {\n version: number;\n title: string;\n /** When this text took effect. */\n effective_from: string;\n /** What changed, in the editor's words. Often empty. */\n note: string;\n changed_at: string;\n}\n\nexport interface DocumentTag {\n tag: string;\n /** Published documents you may read that carry it. */\n count: number;\n}\n\nexport class DocumentsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Published documents you may read, paged. The blog comes newest first,\n * other categories in the order set by the editors.\n */\n async list(input: DocumentListInput = {}): Promise<DocumentList> {\n const q = new URLSearchParams();\n if (input.category) q.set(\"category\", input.category);\n if (input.folderId) q.set(\"folder_id\", input.folderId);\n if (input.tag) q.set(\"tag\", input.tag);\n if (input.locale) q.set(\"locale\", input.locale);\n if (input.q) q.set(\"q\", input.q);\n if (input.page) q.set(\"page\", String(input.page));\n if (input.perPage) q.set(\"per_page\", String(input.perPage));\n const qs = q.toString();\n return this.http.get<DocumentList>(`/documents${qs ? `?${qs}` : \"\"}`);\n }\n\n /** Folders and documents for a sidebar or a table of contents. */\n async tree(input: { category?: DocumentCategory | string } = {}): Promise<DocumentTree> {\n const qs = input.category ? `?category=${encodeURIComponent(input.category)}` : \"\";\n return this.http.get<DocumentTree>(`/documents/tree${qs}`);\n }\n\n /** Every tag on a document you may read, most used first. */\n async tags(): Promise<DocumentTag[]> {\n return this.http.get<DocumentTag[]>(\"/documents/tags\");\n }\n\n /**\n * One document by its address. Without `at`, the text in force now; with\n * `at` (an ISO 8601 moment), the text that was in force then. Unknown\n * addresses and documents above your level are a 404.\n */\n async get(slug: string, opts: { at?: string | Date } = {}): Promise<Document> {\n const at = opts.at instanceof Date ? opts.at.toISOString() : opts.at;\n const qs = at ? `?at=${encodeURIComponent(at)}` : \"\";\n return this.http.get<Document>(`/documents/${encodeURIComponent(slug)}${qs}`);\n }\n\n /** Every saved text of a document, newest first, with the date each took effect. */\n async versions(slug: string): Promise<DocumentVersionSummary[]> {\n return this.http.get<DocumentVersionSummary[]>(\n `/documents/${encodeURIComponent(slug)}/versions`,\n );\n }\n\n /** The document as it read in one version. */\n async version(slug: string, version: number): Promise<Document> {\n return this.http.get<Document>(`/documents/${encodeURIComponent(slug)}/versions/${version}`);\n }\n\n /**\n * Absolute URL for an image path returned inside a document (`cover_url`,\n * or an image block's `url`). Handy when the app renders on a different\n * origin 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"]}
@@ -40,7 +40,9 @@ var DocumentsResource = class {
40
40
  }
41
41
  /** Every saved text of a document, newest first, with the date each took effect. */
42
42
  async versions(slug) {
43
- return this.http.get(`/documents/${encodeURIComponent(slug)}/versions`);
43
+ return this.http.get(
44
+ `/documents/${encodeURIComponent(slug)}/versions`
45
+ );
44
46
  }
45
47
  /** The document as it read in one version. */
46
48
  async version(slug, version) {
@@ -1 +1 @@
1
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AiB,IAAA,EAAsB;AAC9C,IAAA,IAAI,eAAA,CAAgB,IAAA,CAAK,IAAI,CAAA,EAAG,OAAO,IAAA;AACvC,IAAA,OAAO,CAAA,EAAG,OAAA,CAAQ,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAC,CAAA,EAAG,IAAA,CAAK,UAAA,CAAW,GAAG,CAAA,GAAI,EAAA,GAAK,GAAG,GAAG,IAAI,CAAA,CAAA;AAAA,EAC/E;AACF","file":"documents.js","sourcesContent":["import type { HttpClient } from \"../http.js\";\n\n/**\n * Documents resource: `client.documents.*`.\n *\n * Everything the operators write lives in one tree: blog posts, the\n * knowledge base, legal pages, internal notes. Every call here works before\n * the user signs in and shows more once they have: a signed-in user sees the\n * documents marked for users, staff see theirs. The SDK sends the session\n * token when it has one, so the same call serves the public site and the\n * signed-in cabinet.\n *\n * A document arrives as a list of typed blocks. `body_blocks` is flat; map\n * each `type` onto your own component and the document inherits your site's\n * styling. `body_markdown` is there too if you'd rather run your own renderer.\n *\n * ```ts\n * // The knowledge base: folders and articles for a sidebar.\n * const tree = await client.documents.tree({ category: \"knowledge-base\" });\n *\n * // One article, with the text in force today.\n * const doc = await client.documents.get(\"how-to-top-up\");\n *\n * // A legal page as it read on a given day, and its history.\n * const then = await client.documents.get(\"offer\", { at: \"2026-01-01T00:00:00Z\" });\n * const versions = await client.documents.versions(\"offer\");\n *\n * doc.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={client.assetUrl(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 * Links between documents come out as site paths: `/blog/<slug>` for a post,\n * `/docs/<slug>` for everything else (`site_path` on each document says which\n * one it is). Route those two prefixes to your document pages and links keep\n * working after a document is renamed or moved.\n */\n\n/** Category keys: the four folders at the top of the tree. */\nexport type DocumentCategory = \"blog\" | \"knowledge-base\" | \"legal\" | \"internal\";\n\n/** Who may read a document. */\nexport type DocumentScope = \"public\" | \"users\" | \"staff\" | \"operators\";\n\n/** One node of a document body. Discriminated on `type`. */\nexport type DocumentBlock =\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\n/** One step of the folder trail, root first. */\nexport interface DocumentPathStep {\n id: string;\n key: string;\n title: string;\n}\n\nexport interface Document {\n /** Permanent address. Link by this; it survives renames and moves. */\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: DocumentBlock[];\n tags: string[];\n /** Present only when the document 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 /** Category the document sits in. */\n category: DocumentCategory | string;\n /** Folder trail, root first. */\n path: DocumentPathStep[];\n /** Who may read it. */\n read_scope: DocumentScope;\n /** Number of the text shown. */\n version: number;\n /** When the text shown took effect. */\n effective_from: string;\n /** Path under the site root where this document is read. */\n site_path: string;\n}\n\nexport interface DocumentListInput {\n /** Category key. */\n category?: DocumentCategory | string;\n /** Only documents in this folder and the folders under it. */\n folderId?: string;\n /** Only documents carrying this tag. */\n tag?: string;\n /** Only documents in this locale. */\n locale?: string;\n /** Words to search for in the title and the text. */\n q?: string;\n /** 1-based. Default 1. */\n page?: number;\n /** 1..=50. Default 10. */\n perPage?: number;\n}\n\nexport interface DocumentList {\n documents: Document[];\n total: number;\n page: number;\n per_page: number;\n}\n\n/** A folder as it appears in the navigation tree. */\nexport interface DocumentFolder {\n id: string;\n parent_id: string | null;\n key: string;\n title: string;\n description: string;\n position: number;\n}\n\n/** A document as it appears in the navigation tree: enough for a link. */\nexport interface DocumentTreeEntry {\n folder_id: string;\n slug: string;\n title: string;\n excerpt: string;\n tags: string[];\n position: number;\n updated_at: string;\n site_path: string;\n}\n\nexport interface DocumentTree {\n /** Folders with at least one document you may read under them, plus the categories. */\n folders: DocumentFolder[];\n /** Published documents you may read, in folder order. */\n documents: DocumentTreeEntry[];\n}\n\n/** One saved text of a document, without the text itself. */\nexport interface DocumentVersionSummary {\n version: number;\n title: string;\n /** When this text took effect. */\n effective_from: string;\n /** What changed, in the editor's words. Often empty. */\n note: string;\n changed_at: string;\n}\n\nexport interface DocumentTag {\n tag: string;\n /** Published documents you may read that carry it. */\n count: number;\n}\n\nexport class DocumentsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Published documents you may read, paged. The blog comes newest first,\n * other categories in the order set by the editors.\n */\n async list(input: DocumentListInput = {}): Promise<DocumentList> {\n const q = new URLSearchParams();\n if (input.category) q.set(\"category\", input.category);\n if (input.folderId) q.set(\"folder_id\", input.folderId);\n if (input.tag) q.set(\"tag\", input.tag);\n if (input.locale) q.set(\"locale\", input.locale);\n if (input.q) q.set(\"q\", input.q);\n if (input.page) q.set(\"page\", String(input.page));\n if (input.perPage) q.set(\"per_page\", String(input.perPage));\n const qs = q.toString();\n return this.http.get<DocumentList>(`/documents${qs ? `?${qs}` : \"\"}`);\n }\n\n /** Folders and documents for a sidebar or a table of contents. */\n async tree(input: { category?: DocumentCategory | string } = {}): Promise<DocumentTree> {\n const qs = input.category ? `?category=${encodeURIComponent(input.category)}` : \"\";\n return this.http.get<DocumentTree>(`/documents/tree${qs}`);\n }\n\n /** Every tag on a document you may read, most used first. */\n async tags(): Promise<DocumentTag[]> {\n return this.http.get<DocumentTag[]>(\"/documents/tags\");\n }\n\n /**\n * One document by its address. Without `at`, the text in force now; with\n * `at` (an ISO 8601 moment), the text that was in force then. Unknown\n * addresses and documents above your level are a 404.\n */\n async get(slug: string, opts: { at?: string | Date } = {}): Promise<Document> {\n const at = opts.at instanceof Date ? opts.at.toISOString() : opts.at;\n const qs = at ? `?at=${encodeURIComponent(at)}` : \"\";\n return this.http.get<Document>(`/documents/${encodeURIComponent(slug)}${qs}`);\n }\n\n /** Every saved text of a document, newest first, with the date each took effect. */\n async versions(slug: string): Promise<DocumentVersionSummary[]> {\n return this.http.get<DocumentVersionSummary[]>(`/documents/${encodeURIComponent(slug)}/versions`);\n }\n\n /** The document as it read in one version. */\n async version(slug: string, version: number): Promise<Document> {\n return this.http.get<Document>(`/documents/${encodeURIComponent(slug)}/versions/${version}`);\n }\n\n /**\n * Absolute URL for an image path returned inside a document (`cover_url`,\n * or an image block's `url`). Handy when the app renders on a different\n * origin 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"]}
1
+ {"version":3,"sources":["../../src/resources/documents.ts"],"names":[],"mappings":";AA4KO,IAAM,oBAAN,MAAwB;AAAA,EAC7B,YAA6B,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAmB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMhD,MAAM,IAAA,CAAK,KAAA,GAA2B,EAAC,EAA0B;AAC/D,IAAA,MAAM,CAAA,GAAI,IAAI,eAAA,EAAgB;AAC9B,IAAA,IAAI,MAAM,QAAA,EAAU,CAAA,CAAE,GAAA,CAAI,UAAA,EAAY,MAAM,QAAQ,CAAA;AACpD,IAAA,IAAI,MAAM,QAAA,EAAU,CAAA,CAAE,GAAA,CAAI,WAAA,EAAa,MAAM,QAAQ,CAAA;AACrD,IAAA,IAAI,MAAM,GAAA,E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,GAAO,KAAK,EAAA,CAAG,WAAA,KAAgB,IAAA,CAAK,EAAA;AAClE,IAAA,MAAM,KAAK,EAAA,GAAK,CAAA,IAAA,EAAO,kBAAA,CAAmB,EAAE,CAAC,CAAA,CAAA,GAAK,EAAA;AAClD,IAAA,OAAO,IAAA,CAAK,KAAK,GAAA,CAAc,CAAA,WAAA,EAAc,mBAAmB,IAAI,CAAC,CAAA,EAAG,EAAE,CAAA,CAAE,CAAA;AAAA,EAC9E;AAAA;AAAA,EAGA,MAAM,SAAS,IAAA,EAAiD;AAC9D,IAAA,OAAO,KAAK,IAAA,CAAK,GAAA;AAAA,MACf,CAAA,WAAA,EAAc,kBAAA,CAAmB,IAAI,CAAC,CAAA,SAAA;AAAA,KACxC;AAAA,EACF;AAAA;AAAA,EAGA,MAAM,OAAA,CAAQ,IAAA,EAAc,OAAA,EAAoC;AAC9D,IAAA,OAAO,IAAA,CAAK,KAAK,GAAA,CAAc,CAAA,WAAA,EAAc,mBAAmB,IAAI,CAAC,CAAA,UAAA,EAAa,OAAO,CAAA,CAAE,CAAA;AAAA,EAC7F;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,QAAA,CAAS,SAAiB,IAAA,EAAsB;AAC9C,IAAA,IAAI,eAAA,CAAgB,IAAA,CAAK,IAAI,CAAA,EAAG,OAAO,IAAA;AACvC,IAAA,OAAO,CAAA,EAAG,OAAA,CAAQ,OAAA,CAAQ,KAAA,EAAO,EAAE,CAAC,CAAA,EAAG,IAAA,CAAK,UAAA,CAAW,GAAG,CAAA,GAAI,EAAA,GAAK,GAAG,GAAG,IAAI,CAAA,CAAA;AAAA,EAC/E;AACF","file":"documents.js","sourcesContent":["import type { HttpClient } from \"../http.js\";\n\n/**\n * Documents resource: `client.documents.*`.\n *\n * Everything the operators write lives in one tree: blog posts, the\n * knowledge base, legal pages, internal notes. Every call here works before\n * the user signs in and shows more once they have: a signed-in user sees the\n * documents marked for users, staff see theirs. The SDK sends the session\n * token when it has one, so the same call serves the public site and the\n * signed-in cabinet.\n *\n * A document arrives as a list of typed blocks. `body_blocks` is flat; map\n * each `type` onto your own component and the document inherits your site's\n * styling. `body_markdown` is there too if you'd rather run your own renderer.\n *\n * ```ts\n * // The knowledge base: folders and articles for a sidebar.\n * const tree = await client.documents.tree({ category: \"knowledge-base\" });\n *\n * // One article, with the text in force today.\n * const doc = await client.documents.get(\"how-to-top-up\");\n *\n * // A legal page as it read on a given day, and its history.\n * const then = await client.documents.get(\"offer\", { at: \"2026-01-01T00:00:00Z\" });\n * const versions = await client.documents.versions(\"offer\");\n *\n * doc.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={client.assetUrl(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 * Links between documents come out as site paths: `/blog/<slug>` for a post,\n * `/docs/<slug>` for everything else (`site_path` on each document says which\n * one it is). Route those two prefixes to your document pages and links keep\n * working after a document is renamed or moved.\n */\n\n/** Category keys: the four folders at the top of the tree. */\nexport type DocumentCategory = \"blog\" | \"knowledge-base\" | \"legal\" | \"internal\";\n\n/** Who may read a document. */\nexport type DocumentScope = \"public\" | \"users\" | \"staff\" | \"operators\";\n\n/** One node of a document body. Discriminated on `type`. */\nexport type DocumentBlock =\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\n/** One step of the folder trail, root first. */\nexport interface DocumentPathStep {\n id: string;\n key: string;\n title: string;\n}\n\nexport interface Document {\n /** Permanent address. Link by this; it survives renames and moves. */\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: DocumentBlock[];\n tags: string[];\n /** Present only when the document 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 /** Category the document sits in. */\n category: DocumentCategory | string;\n /** Folder trail, root first. */\n path: DocumentPathStep[];\n /** Who may read it. */\n read_scope: DocumentScope;\n /** Number of the text shown. */\n version: number;\n /** When the text shown took effect. */\n effective_from: string;\n /** Path under the site root where this document is read. */\n site_path: string;\n}\n\nexport interface DocumentListInput {\n /** Category key. */\n category?: DocumentCategory | string;\n /** Only documents in this folder and the folders under it. */\n folderId?: string;\n /** Only documents carrying this tag. */\n tag?: string;\n /** Only documents in this locale. */\n locale?: string;\n /** Words to search for in the title and the text. */\n q?: string;\n /** 1-based. Default 1. */\n page?: number;\n /** 1..=50. Default 10. */\n perPage?: number;\n}\n\nexport interface DocumentList {\n documents: Document[];\n total: number;\n page: number;\n per_page: number;\n}\n\n/** A folder as it appears in the navigation tree. */\nexport interface DocumentFolder {\n id: string;\n parent_id: string | null;\n key: string;\n title: string;\n description: string;\n position: number;\n}\n\n/** A document as it appears in the navigation tree: enough for a link. */\nexport interface DocumentTreeEntry {\n folder_id: string;\n slug: string;\n title: string;\n excerpt: string;\n tags: string[];\n position: number;\n updated_at: string;\n site_path: string;\n}\n\nexport interface DocumentTree {\n /** Folders with at least one document you may read under them, plus the categories. */\n folders: DocumentFolder[];\n /** Published documents you may read, in folder order. */\n documents: DocumentTreeEntry[];\n}\n\n/** One saved text of a document, without the text itself. */\nexport interface DocumentVersionSummary {\n version: number;\n title: string;\n /** When this text took effect. */\n effective_from: string;\n /** What changed, in the editor's words. Often empty. */\n note: string;\n changed_at: string;\n}\n\nexport interface DocumentTag {\n tag: string;\n /** Published documents you may read that carry it. */\n count: number;\n}\n\nexport class DocumentsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Published documents you may read, paged. The blog comes newest first,\n * other categories in the order set by the editors.\n */\n async list(input: DocumentListInput = {}): Promise<DocumentList> {\n const q = new URLSearchParams();\n if (input.category) q.set(\"category\", input.category);\n if (input.folderId) q.set(\"folder_id\", input.folderId);\n if (input.tag) q.set(\"tag\", input.tag);\n if (input.locale) q.set(\"locale\", input.locale);\n if (input.q) q.set(\"q\", input.q);\n if (input.page) q.set(\"page\", String(input.page));\n if (input.perPage) q.set(\"per_page\", String(input.perPage));\n const qs = q.toString();\n return this.http.get<DocumentList>(`/documents${qs ? `?${qs}` : \"\"}`);\n }\n\n /** Folders and documents for a sidebar or a table of contents. */\n async tree(input: { category?: DocumentCategory | string } = {}): Promise<DocumentTree> {\n const qs = input.category ? `?category=${encodeURIComponent(input.category)}` : \"\";\n return this.http.get<DocumentTree>(`/documents/tree${qs}`);\n }\n\n /** Every tag on a document you may read, most used first. */\n async tags(): Promise<DocumentTag[]> {\n return this.http.get<DocumentTag[]>(\"/documents/tags\");\n }\n\n /**\n * One document by its address. Without `at`, the text in force now; with\n * `at` (an ISO 8601 moment), the text that was in force then. Unknown\n * addresses and documents above your level are a 404.\n */\n async get(slug: string, opts: { at?: string | Date } = {}): Promise<Document> {\n const at = opts.at instanceof Date ? opts.at.toISOString() : opts.at;\n const qs = at ? `?at=${encodeURIComponent(at)}` : \"\";\n return this.http.get<Document>(`/documents/${encodeURIComponent(slug)}${qs}`);\n }\n\n /** Every saved text of a document, newest first, with the date each took effect. */\n async versions(slug: string): Promise<DocumentVersionSummary[]> {\n return this.http.get<DocumentVersionSummary[]>(\n `/documents/${encodeURIComponent(slug)}/versions`,\n );\n }\n\n /** The document as it read in one version. */\n async version(slug: string, version: number): Promise<Document> {\n return this.http.get<Document>(`/documents/${encodeURIComponent(slug)}/versions/${version}`);\n }\n\n /**\n * Absolute URL for an image path returned inside a document (`cover_url`,\n * or an image block's `url`). Handy when the app renders on a different\n * origin 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"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/resources/funding-options.ts"],"names":[],"mappings":";;;AAwCO,IAAM,yBAAN,MAA6B;AAAA,EAClC,YAA6B,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAmB;AAAA;AAAA,EAGhD,MAAM,IAAA,GAAiC;AACrC,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,GAAA,CAAqB,qBAAqB,CAAA;AAAA,EAC7D;AACF","file":"funding-options.cjs","sourcesContent":["import type { HttpClient } from \"../http.js\";\nimport type { DepositMethod } from \"./deposits.js\";\n\n/**\n * Funding options resource — `client.fundingOptions.*`.\n *\n * The ways the user can top up on this deployment: each funding connector,\n * where its top-ups may land and which payment methods it takes. Build the\n * top-up screen from this list instead of fixed connector names: a\n * deployment may top up the wallet only, cards only (no wallet at all), or\n * let the user choose.\n *\n * Mirrors `GET /me/funding-options`.\n */\n\n/**\n * Where a funding connector's top-ups may land: `wallet` (the wallet\n * only), `spool` (straight onto cards only) or `mixed` (either).\n */\nexport type FunderMode = \"wallet\" | \"spool\" | \"mixed\";\n\n/** Where one top-up goes: the wallet, or one of the user's cards. */\nexport type DepositTarget = \"wallet\" | \"card\";\n\n/** One way to top up. */\nexport interface FundingOption {\n /** Pass it as `funder_slug` to `deposits.initiate`. */\n slug: string;\n mode: FunderMode;\n /** Where a top-up through it may land. */\n targets: DepositTarget[];\n /** Payment methods it takes. */\n methods: DepositMethod[];\n /**\n * Whether a new card can be issued with a top-up through it\n * (`issue_card` on `deposits.initiate`).\n */\n issue_card: boolean;\n}\n\nexport class FundingOptionsResource {\n constructor(private readonly http: HttpClient) {}\n\n /** The ways to top up, preferred first. Empty when none is configured. */\n async list(): Promise<FundingOption[]> {\n return this.http.get<FundingOption[]>(\"/me/funding-options\");\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/resources/funding-options.ts"],"names":[],"mappings":";;;AAgEO,IAAM,yBAAN,MAA6B;AAAA,EAClC,YAA6B,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAmB;AAAA;AAAA,EAGhD,MAAM,IAAA,GAAiC;AACrC,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,GAAA,CAAqB,qBAAqB,CAAA;AAAA,EAC7D;AACF","file":"funding-options.cjs","sourcesContent":["import type { HttpClient } from \"../http.js\";\nimport type { DepositMethod, FeeKind } from \"./deposits.js\";\n\n/**\n * Funding options resource — `client.fundingOptions.*`.\n *\n * The ways the user can top up on this deployment: each funding connector,\n * where its top-ups may land and which payment methods it takes. Build the\n * top-up screen from this list instead of fixed connector names: a\n * deployment may top up the wallet only, cards only (no wallet at all), or\n * let the user choose.\n *\n * Mirrors `GET /me/funding-options`.\n */\n\n/**\n * Where a funding connector's top-ups may land: `wallet` (the wallet\n * only), `spool` (straight onto cards only) or `mixed` (either).\n */\nexport type FunderMode = \"wallet\" | \"spool\" | \"mixed\";\n\n/** Where one top-up goes: the wallet, or one of the user's cards. */\nexport type DepositTarget = \"wallet\" | \"card\";\n\n/**\n * What one way of paying through a funding connector costs and allows.\n * Draw the top-up form from it: the currency to ask for, the fee to show\n * (or not, for a markup), the floor, the cap and the day's limit.\n */\nexport interface MethodTerms {\n method: DepositMethod;\n /** ISO 4217 code the user pays in this way; `null` when any the quote accepts. */\n source_currency: string | null;\n fee_kind: FeeKind;\n /** The fee in basis points (2000 = 20 %). */\n fee_bps: number;\n /** How long a quote through this method stays executable, and the deposit waits for its payment. */\n quote_ttl_seconds: number;\n /** Smallest single top-up in the source currency; `null` for no floor. */\n min_amount: string | null;\n /** Largest single top-up in the source currency; `null` for no cap. */\n max_amount: string | null;\n /** What one user may top up this way over 24 hours; `null` for no limit. */\n daily_limit_per_user: string | null;\n}\n\n/** One way to top up. */\nexport interface FundingOption {\n /** Pass it as `funder_slug` to `deposits.initiate`. */\n slug: string;\n mode: FunderMode;\n /** Where a top-up through it may land. */\n targets: DepositTarget[];\n /** Payment methods it takes. */\n methods: DepositMethod[];\n /**\n * Whether a new card can be issued with a top-up through it\n * (`issue_card` on `deposits.initiate`).\n */\n issue_card: boolean;\n /** The terms of each method in `methods`. */\n method_terms: MethodTerms[];\n}\n\nexport class FundingOptionsResource {\n constructor(private readonly http: HttpClient) {}\n\n /** The ways to top up, preferred first. Empty when none is configured. */\n async list(): Promise<FundingOption[]> {\n return this.http.get<FundingOption[]>(\"/me/funding-options\");\n }\n}\n"]}
@@ -1,3 +1,3 @@
1
1
  import '../http-DeANAoTs.cjs';
2
- export { f as DepositTarget, g as FunderMode, h as FundingOption, F as FundingOptionsResource } from '../deposits-BEc8U80M.cjs';
3
- import '../cards-B_aNY35J.cjs';
2
+ export { f as DepositTarget, h as FunderMode, i as FundingOption, F as FundingOptionsResource, M as MethodTerms } from '../deposits-ZjT_btgi.cjs';
3
+ import '../cards-qfHz6xZY.cjs';
@@ -1,3 +1,3 @@
1
1
  import '../http-DeANAoTs.js';
2
- export { f as DepositTarget, g as FunderMode, h as FundingOption, F as FundingOptionsResource } from '../deposits-DScyT_D9.js';
3
- import '../cards-Ba1wZttb.js';
2
+ export { f as DepositTarget, h as FunderMode, i as FundingOption, F as FundingOptionsResource, M as MethodTerms } from '../deposits-B2LBe2k1.js';
3
+ import '../cards-CF3-He2x.js';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/resources/funding-options.ts"],"names":[],"mappings":";AAwCO,IAAM,yBAAN,MAA6B;AAAA,EAClC,YAA6B,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAmB;AAAA;AAAA,EAGhD,MAAM,IAAA,GAAiC;AACrC,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,GAAA,CAAqB,qBAAqB,CAAA;AAAA,EAC7D;AACF","file":"funding-options.js","sourcesContent":["import type { HttpClient } from \"../http.js\";\nimport type { DepositMethod } from \"./deposits.js\";\n\n/**\n * Funding options resource — `client.fundingOptions.*`.\n *\n * The ways the user can top up on this deployment: each funding connector,\n * where its top-ups may land and which payment methods it takes. Build the\n * top-up screen from this list instead of fixed connector names: a\n * deployment may top up the wallet only, cards only (no wallet at all), or\n * let the user choose.\n *\n * Mirrors `GET /me/funding-options`.\n */\n\n/**\n * Where a funding connector's top-ups may land: `wallet` (the wallet\n * only), `spool` (straight onto cards only) or `mixed` (either).\n */\nexport type FunderMode = \"wallet\" | \"spool\" | \"mixed\";\n\n/** Where one top-up goes: the wallet, or one of the user's cards. */\nexport type DepositTarget = \"wallet\" | \"card\";\n\n/** One way to top up. */\nexport interface FundingOption {\n /** Pass it as `funder_slug` to `deposits.initiate`. */\n slug: string;\n mode: FunderMode;\n /** Where a top-up through it may land. */\n targets: DepositTarget[];\n /** Payment methods it takes. */\n methods: DepositMethod[];\n /**\n * Whether a new card can be issued with a top-up through it\n * (`issue_card` on `deposits.initiate`).\n */\n issue_card: boolean;\n}\n\nexport class FundingOptionsResource {\n constructor(private readonly http: HttpClient) {}\n\n /** The ways to top up, preferred first. Empty when none is configured. */\n async list(): Promise<FundingOption[]> {\n return this.http.get<FundingOption[]>(\"/me/funding-options\");\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/resources/funding-options.ts"],"names":[],"mappings":";AAgEO,IAAM,yBAAN,MAA6B;AAAA,EAClC,YAA6B,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAmB;AAAA;AAAA,EAGhD,MAAM,IAAA,GAAiC;AACrC,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,GAAA,CAAqB,qBAAqB,CAAA;AAAA,EAC7D;AACF","file":"funding-options.js","sourcesContent":["import type { HttpClient } from \"../http.js\";\nimport type { DepositMethod, FeeKind } from \"./deposits.js\";\n\n/**\n * Funding options resource — `client.fundingOptions.*`.\n *\n * The ways the user can top up on this deployment: each funding connector,\n * where its top-ups may land and which payment methods it takes. Build the\n * top-up screen from this list instead of fixed connector names: a\n * deployment may top up the wallet only, cards only (no wallet at all), or\n * let the user choose.\n *\n * Mirrors `GET /me/funding-options`.\n */\n\n/**\n * Where a funding connector's top-ups may land: `wallet` (the wallet\n * only), `spool` (straight onto cards only) or `mixed` (either).\n */\nexport type FunderMode = \"wallet\" | \"spool\" | \"mixed\";\n\n/** Where one top-up goes: the wallet, or one of the user's cards. */\nexport type DepositTarget = \"wallet\" | \"card\";\n\n/**\n * What one way of paying through a funding connector costs and allows.\n * Draw the top-up form from it: the currency to ask for, the fee to show\n * (or not, for a markup), the floor, the cap and the day's limit.\n */\nexport interface MethodTerms {\n method: DepositMethod;\n /** ISO 4217 code the user pays in this way; `null` when any the quote accepts. */\n source_currency: string | null;\n fee_kind: FeeKind;\n /** The fee in basis points (2000 = 20 %). */\n fee_bps: number;\n /** How long a quote through this method stays executable, and the deposit waits for its payment. */\n quote_ttl_seconds: number;\n /** Smallest single top-up in the source currency; `null` for no floor. */\n min_amount: string | null;\n /** Largest single top-up in the source currency; `null` for no cap. */\n max_amount: string | null;\n /** What one user may top up this way over 24 hours; `null` for no limit. */\n daily_limit_per_user: string | null;\n}\n\n/** One way to top up. */\nexport interface FundingOption {\n /** Pass it as `funder_slug` to `deposits.initiate`. */\n slug: string;\n mode: FunderMode;\n /** Where a top-up through it may land. */\n targets: DepositTarget[];\n /** Payment methods it takes. */\n methods: DepositMethod[];\n /**\n * Whether a new card can be issued with a top-up through it\n * (`issue_card` on `deposits.initiate`).\n */\n issue_card: boolean;\n /** The terms of each method in `methods`. */\n method_terms: MethodTerms[];\n}\n\nexport class FundingOptionsResource {\n constructor(private readonly http: HttpClient) {}\n\n /** The ways to top up, preferred first. Empty when none is configured. */\n async list(): Promise<FundingOption[]> {\n return this.http.get<FundingOption[]>(\"/me/funding-options\");\n }\n}\n"]}
@@ -13,7 +13,9 @@ var HistoryResource = class {
13
13
  if (params.limit !== void 0) q.set("limit", String(params.limit));
14
14
  if (params.lang) q.set("lang", params.lang);
15
15
  const qs = q.toString();
16
- return this.http.get(`/me/history${qs ? `?${qs}` : ""}`, { signal: params.signal });
16
+ return this.http.get(`/me/history${qs ? `?${qs}` : ""}`, {
17
+ signal: params.signal
18
+ });
17
19
  }
18
20
  /** Every entry, page after page, newest first. */
19
21
  async *all(params = {}) {