@takeal/cusfront-sdk 0.3.20 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/CHANGELOG.md +127 -0
  2. package/README.md +407 -8
  3. package/dist/analytics.cjs +417 -0
  4. package/dist/analytics.cjs.map +1 -0
  5. package/dist/analytics.d.cts +129 -0
  6. package/dist/analytics.d.ts +129 -0
  7. package/dist/analytics.js +403 -0
  8. package/dist/analytics.js.map +1 -0
  9. package/dist/cards-B_aNY35J.d.cts +514 -0
  10. package/dist/cards-Ba1wZttb.d.ts +514 -0
  11. package/dist/deposits-BEc8U80M.d.cts +310 -0
  12. package/dist/deposits-DScyT_D9.d.ts +310 -0
  13. package/dist/{devices-DP_hxwmW.d.ts → devices-B_YveTl9.d.ts} +1 -1
  14. package/dist/{devices-C3JHi2Hi.d.cts → devices-a5Z45Mx_.d.cts} +1 -1
  15. package/dist/{http-B-OQwMYn.d.cts → http-DeANAoTs.d.cts} +11 -3
  16. package/dist/{http-B-OQwMYn.d.ts → http-DeANAoTs.d.ts} +11 -3
  17. package/dist/index.cjs +939 -77
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +101 -13
  20. package/dist/index.d.ts +101 -13
  21. package/dist/index.js +924 -78
  22. package/dist/index.js.map +1 -1
  23. package/dist/react/index.d.cts +12 -5
  24. package/dist/react/index.d.ts +12 -5
  25. package/dist/resources/attribution.cjs +82 -0
  26. package/dist/resources/attribution.cjs.map +1 -0
  27. package/dist/resources/attribution.d.cts +100 -0
  28. package/dist/resources/attribution.d.ts +100 -0
  29. package/dist/resources/attribution.js +78 -0
  30. package/dist/resources/attribution.js.map +1 -0
  31. package/dist/resources/auth.cjs +81 -15
  32. package/dist/resources/auth.cjs.map +1 -1
  33. package/dist/resources/auth.d.cts +53 -6
  34. package/dist/resources/auth.d.ts +53 -6
  35. package/dist/resources/auth.js +81 -15
  36. package/dist/resources/auth.js.map +1 -1
  37. package/dist/resources/balance.d.cts +1 -1
  38. package/dist/resources/balance.d.ts +1 -1
  39. package/dist/resources/blog.cjs.map +1 -1
  40. package/dist/resources/blog.d.cts +8 -1
  41. package/dist/resources/blog.d.ts +8 -1
  42. package/dist/resources/blog.js.map +1 -1
  43. package/dist/resources/bonus.cjs +28 -0
  44. package/dist/resources/bonus.cjs.map +1 -0
  45. package/dist/resources/bonus.d.cts +121 -0
  46. package/dist/resources/bonus.d.ts +121 -0
  47. package/dist/resources/bonus.js +26 -0
  48. package/dist/resources/bonus.js.map +1 -0
  49. package/dist/resources/branding.d.cts +1 -1
  50. package/dist/resources/branding.d.ts +1 -1
  51. package/dist/resources/cards.cjs +48 -10
  52. package/dist/resources/cards.cjs.map +1 -1
  53. package/dist/resources/cards.d.cts +2 -347
  54. package/dist/resources/cards.d.ts +2 -347
  55. package/dist/resources/cards.js +48 -11
  56. package/dist/resources/cards.js.map +1 -1
  57. package/dist/resources/codes.cjs +20 -0
  58. package/dist/resources/codes.cjs.map +1 -0
  59. package/dist/resources/codes.d.cts +100 -0
  60. package/dist/resources/codes.d.ts +100 -0
  61. package/dist/resources/codes.js +18 -0
  62. package/dist/resources/codes.js.map +1 -0
  63. package/dist/resources/deposits.cjs +28 -3
  64. package/dist/resources/deposits.cjs.map +1 -1
  65. package/dist/resources/deposits.d.cts +3 -176
  66. package/dist/resources/deposits.d.ts +3 -176
  67. package/dist/resources/deposits.js +28 -3
  68. package/dist/resources/deposits.js.map +1 -1
  69. package/dist/resources/devices.d.cts +2 -2
  70. package/dist/resources/devices.d.ts +2 -2
  71. package/dist/resources/documents.cjs +64 -0
  72. package/dist/resources/documents.cjs.map +1 -0
  73. package/dist/resources/documents.d.cts +212 -0
  74. package/dist/resources/documents.d.ts +212 -0
  75. package/dist/resources/documents.js +62 -0
  76. package/dist/resources/documents.js.map +1 -0
  77. package/dist/resources/funding-options.cjs +16 -0
  78. package/dist/resources/funding-options.cjs.map +1 -0
  79. package/dist/resources/funding-options.d.cts +3 -0
  80. package/dist/resources/funding-options.d.ts +3 -0
  81. package/dist/resources/funding-options.js +14 -0
  82. package/dist/resources/funding-options.js.map +1 -0
  83. package/dist/resources/history.cjs +31 -0
  84. package/dist/resources/history.cjs.map +1 -0
  85. package/dist/resources/history.d.cts +95 -0
  86. package/dist/resources/history.d.ts +95 -0
  87. package/dist/resources/history.js +29 -0
  88. package/dist/resources/history.js.map +1 -0
  89. package/dist/resources/me.d.cts +3 -1
  90. package/dist/resources/me.d.ts +3 -1
  91. package/dist/resources/notifications.d.cts +1 -1
  92. package/dist/resources/notifications.d.ts +1 -1
  93. package/dist/resources/push.d.cts +1 -1
  94. package/dist/resources/push.d.ts +1 -1
  95. package/dist/resources/referral.cjs +16 -0
  96. package/dist/resources/referral.cjs.map +1 -0
  97. package/dist/resources/referral.d.cts +58 -0
  98. package/dist/resources/referral.d.ts +58 -0
  99. package/dist/resources/referral.js +14 -0
  100. package/dist/resources/referral.js.map +1 -0
  101. package/dist/resources/sessions.d.cts +1 -1
  102. package/dist/resources/sessions.d.ts +1 -1
  103. package/dist/resources/subscription.cjs +24 -0
  104. package/dist/resources/subscription.cjs.map +1 -0
  105. package/dist/resources/subscription.d.cts +48 -0
  106. package/dist/resources/subscription.d.ts +48 -0
  107. package/dist/resources/subscription.js +22 -0
  108. package/dist/resources/subscription.js.map +1 -0
  109. package/dist/resources/subscriptions.d.cts +1 -1
  110. package/dist/resources/subscriptions.d.ts +1 -1
  111. package/dist/resources/wallet.d.cts +1 -1
  112. package/dist/resources/wallet.d.ts +1 -1
  113. package/dist/telegram.cjs +474 -77
  114. package/dist/telegram.cjs.map +1 -1
  115. package/dist/telegram.d.cts +12 -5
  116. package/dist/telegram.d.ts +12 -5
  117. package/dist/telegram.js +474 -77
  118. package/dist/telegram.js.map +1 -1
  119. package/package.json +46 -1
  120. package/dist/customer-CoxPwe5o.d.cts +0 -32
  121. package/dist/customer-CoxPwe5o.d.ts +0 -32
package/CHANGELOG.md CHANGED
@@ -4,6 +4,133 @@ All notable changes to `@takeal/cusfront-sdk` are documented here. The format
4
4
  follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project
5
5
  adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [0.5.0] — 2026-09-29
8
+
9
+ First release with a version of its own: from here the SDK version no longer
10
+ follows the platform tag. Works with platform (TKL) `>=0.5.0, <0.6.0`
11
+ (`SUPPORTED_MEISTER`). 0.4.0 was never published; everything since 0.3.21 is
12
+ listed here.
13
+
14
+ ### Added
15
+
16
+ - `client.ready()`: calls `GET /ready` and says whether the deployment runs a
17
+ platform version this SDK supports (`compatible`, `platformVersion`,
18
+ `supportedMeister`, `warning`, plus `healthy`, `status` and the raw body).
19
+ A 503 from a degraded platform is returned, not thrown. New exports
20
+ `SUPPORTED_MEISTER` and `satisfies()`, types `ReadyInfo` and `ReadyBody`.
21
+
22
+ - Analytics: `@takeal/cusfront-sdk/analytics` (also exported from the root).
23
+ `initAnalytics({ zone, posthog, metrika })` with three zones: `public`
24
+ (autocapture with texts, heatmaps, Yandex Metrica without Webvisor),
25
+ `cabinet` and `miniapp` (no element texts, every input and all text masked,
26
+ recordings only with `sessionRecording: true`, never Metrica). `track()`
27
+ takes names from a fixed list and sends them to PostHog, and the two
28
+ sign-up goals to Metrica on public pages. `page()`, `identify()`,
29
+ `resetAnalytics()`, `setAnalyticsZone()`, `posthogDistinctId()` for
30
+ `auth.register`. Every event passes one filter (`sanitizeUrl`,
31
+ `sanitizeProperties`) that cuts ids from addresses and drops e-mails,
32
+ phones and names. No new dependencies: PostHog and Metrica load only when
33
+ configured.
34
+
35
+ - Promo and referral codes: `auth.register({ code })` and
36
+ `auth.exchangeTelegram({ code })` (a `startapp` code is read by the server
37
+ too) return `code_result`; `promoCode` on `cards.create` and `promo_code`
38
+ on `deposits.initiate`, and a deposit carries `promo_code`. New
39
+ `client.codes.validate()`, `client.referral.get()` (code, link, invited
40
+ friends without personal data, rewards) and `client.subscription`
41
+ (`get()`, gifts included, and `setPromoCode()` for the monthly fee).
42
+ Sub-exports `@takeal/cusfront-sdk/codes`, `/referral`, `/subscription`.
43
+
44
+ - Top-ups straight onto a card: `deposits.initiate` takes `card_id` (an
45
+ existing card) or `issue_card` (a new card issued with its first top-up,
46
+ the fields of `cards.create`). A deposit carries `target`,
47
+ `card_load_status`, `card_load_error`, `card_amount`, `card_commission`,
48
+ `issues_card`, `issue_fee` and `returned_to_wallet_at`.
49
+ `deposits.quote` takes `card_id` or `target_currency` to price a top-up in
50
+ the card's currency. New `client.fundingOptions.list()`: each funding
51
+ connector with where its top-ups may land and the methods it takes.
52
+ Sub-export `@takeal/cusfront-sdk/funding-options`.
53
+
54
+ - Bonuses: `client.bonus.get()` (balance, where bonuses can go, credits,
55
+ history) and `client.bonus.preview()` ("was / now" for a price, worked out
56
+ on the server). `cards.create` takes `useBonus` and `bonusAmount` and
57
+ returns `bonus` when bonuses paid part of the price; `deposits.initiate`
58
+ takes `use_bonus` and `bonus_amount`, and a deposit carries `bonus_units`
59
+ and `bonus_value`. History gets `bonus` entries. Sub-export
60
+ `@takeal/cusfront-sdk/bonus`.
61
+
62
+ - "Remember me": `auth.login({ remember: true })` (and `verifyTotp`,
63
+ `verifyOtp`, `completeTotpSetup`, `register`) keeps the remember token
64
+ the API returns in a `rememberStore` (localStorage `takeal_remember` by
65
+ default). A 401 then renews the session once by itself and repeats the
66
+ call; `auth.refresh()` does it on demand, e.g. on app start. The token
67
+ only works from the browser that signed in.
68
+
69
+ ### Changed
70
+
71
+ - `auth.signOut()` now also ends the session and the remembered sign-in on
72
+ the server (`POST /auth/logout`), then clears both tokens.
73
+
74
+ - `client.documents`: `list({ category?, folderId?, tag?, locale?, q?, page?, perPage? })`,
75
+ `tree({ category? })` for a sidebar, `tags()`, `get(slug, { at? })`,
76
+ `versions(slug)` and `version(slug, n)`. Blog posts, the knowledge base
77
+ and legal pages in one tree; the calls work before sign-in and show more
78
+ with a session. Each document carries `category`, `path`, `read_scope`,
79
+ `version`, `effective_from` and `site_path`.
80
+
81
+ ### Deprecated
82
+
83
+ - `client.blog`: the blog is a category of Documents now. Use
84
+ `client.documents.list({ category: "blog" })` and `client.documents.get(slug)`.
85
+ The old API paths answer for one more release.
86
+
87
+ - `client.history.list({ cardId?, cursor?, limit?, lang? })` and
88
+ `client.history.all()`: everything that happened to the user's money in
89
+ one list, newest first. Card payments (declines too, with the reason in
90
+ plain words), refunds, card issuance with its fee, card top-ups,
91
+ transfers between the user's cards as one entry, wallet top-ups with the
92
+ conversion and the rate, fees and corrections. `kind`, `status` and
93
+ `direction` stay open strings, so a kind added later doesn't break a
94
+ build.
95
+
96
+ - `client.attribution`: `touch()` records a visit (no session needed; a
97
+ visit with nothing new is not stored), `status()` says whether to ask
98
+ "how did you hear about us", `answerSurvey()` answers it once.
99
+ - `anonymousKey()` keeps the visitor's anonymous id in a cookie and in
100
+ `localStorage` for a year and restores one from the other; in the
101
+ Telegram Mini App it is `tg:<telegram id>`. `currentTouch()` reads the
102
+ page address, the referrer, the Mini App's start code and the Metrica
103
+ and Google Analytics cookies.
104
+ - `auth.register({ attribution })` and `auth.exchangeTelegram({ attribution })`
105
+ credit the new account with the visitor's touches and analytics ids.
106
+
107
+ - The product card on `CardProduct`: `tagline` (one line under the name),
108
+ `benefits` (selling points, in order) and `tile_image_url` (a picture for
109
+ the tile; fall back to `design.image_url` when `null`). Both
110
+ `listProducts()` and `catalog()` carry them.
111
+
112
+ ### Changed
113
+
114
+ - `listProducts()` and `catalog()` come in the order the operator arranged
115
+ the storefront. `is_default` still marks the product issued when none is
116
+ chosen, but it is no longer necessarily the first item.
117
+ - `price.currency` is the currency the buyer pays in: for a signed-in user
118
+ their wallet currency, converted the way issuance charges it; in the
119
+ public catalog the currency the operator priced the card in. It may
120
+ differ from `CardProduct.currency`, the currency the card is held in.
121
+ - `price.label` is always the platform's own wording of the fee line.
122
+
123
+ ## [0.3.21] — 2026-09-21
124
+
125
+ Checked against platform `v0.3.21`.
126
+
127
+ ### Changed
128
+
129
+ - A card is issued for its product price alone. `CreateCardInput.initial_amount`
130
+ is deprecated and no longer sent (the API ignores it); the balance a card
131
+ starts with, when its product includes one, is part of the price and shown
132
+ as `CardProduct.starting_balance`. Load money afterwards with `cards.topUp()`.
133
+
7
134
  ## [0.3.20] — 2026-09-21
8
135
 
9
136
  Checked against platform `v0.3.20`.
package/README.md CHANGED
@@ -65,24 +65,30 @@ The API publishes a catalog of the cards a user can order, and the client
65
65
  walks it from the list to the issued card:
66
66
 
67
67
  ```ts
68
- // 1. The catalog: what the user can order, default product first.
68
+ // 1. The catalog: what the user can order, in the order the operator
69
+ // arranged the storefront. `is_default` marks the product issued when
70
+ // the user does not choose; it can sit anywhere in the list.
69
71
  const products = await client.cards.listProducts();
70
72
  // Before sign-in (a landing page), the same list at list prices:
71
73
  // const products = await client.cards.catalog();
72
74
 
73
75
  for (const p of products) {
74
- // Artwork: `image_url` is absolute for uploaded designs and a path
75
- // relative to the API for the deployment default. `assetUrl` handles both.
76
- const img = client.assetUrl(p.design.image_url);
76
+ // The tile: the operator's picture when there is one, the card design
77
+ // otherwise. `image_url` is absolute for uploaded designs and a path
78
+ // relative to the API for the deployment default; `assetUrl` handles both.
79
+ const img = client.assetUrl(p.tile_image_url ?? p.design.image_url);
77
80
 
78
81
  // Price after the user's subscription discount; `null` means free.
82
+ // `price.currency` is what the user pays in (their wallet currency once
83
+ // signed in), which need not be the currency the card is held in.
79
84
  const price = p.price
80
85
  ? p.price.discount_bps > 0
81
86
  ? `${p.price.amount} ${p.price.currency} (was ${p.price.base_amount}, ${p.price.discount_bps / 100}% off)`
82
87
  : `${p.price.amount} ${p.price.currency}`
83
88
  : "free";
84
89
 
85
- console.log(p.name, p.card_type, p.currency, price, img, p.description);
90
+ // The product card: name, one-line tagline, selling points, description.
91
+ console.log(p.name, p.tagline, p.benefits, p.description, p.card_type, p.currency, price, img);
86
92
  }
87
93
 
88
94
  // 2. Issue from a product. `type` and `issuer_slug` are no longer needed:
@@ -123,6 +129,13 @@ the deployment picks the product.
123
129
  exported from the package root, for code that has no client at hand.
124
130
 
125
131
 
132
+ ## What a card costs
133
+
134
+ A card is issued for its product's `price`, nothing else is taken from the
135
+ wallet. Some providers insist on a starting balance; when the product has one
136
+ it is shown as `starting_balance` and is already part of the price. Everything
137
+ beyond that goes onto the card with `topUp()`.
138
+
126
139
  ## Topping up a card
127
140
 
128
141
  Money moves from the wallet onto the user's own card in one call. Read the
@@ -144,6 +157,47 @@ the wallet (402), amount outside the floor or cap (400), card frozen or still
144
157
  being issued (409), provider declined or unreachable (502/503, the wallet is
145
158
  untouched).
146
159
 
160
+ ## Topping up a card directly
161
+
162
+ Some deployments let a top-up go straight onto a card, past the wallet, and
163
+ some have no wallet at all. Ask the API instead of hard-coding it:
164
+
165
+ ```ts
166
+ const options = await client.fundingOptions.list();
167
+ // [{ slug, mode: "wallet" | "spool" | "mixed", targets: ["wallet", "card"],
168
+ // methods: ["card", "crypto"], issue_card: true }]
169
+ const direct = options.find((o) => o.targets.includes("card"));
170
+ ```
171
+
172
+ Top up an existing card with `card_id`, or issue a new card with its first
173
+ top-up with `issue_card` (the fields of `cards.create`). The card's price
174
+ comes out of the top-up and the rest is its starting balance.
175
+
176
+ ```ts
177
+ const deposit = await client.deposits.initiate({
178
+ amount: "25.00",
179
+ currency: "USD",
180
+ method: "card",
181
+ funder_slug: direct.slug,
182
+ card_id: card.id, // or: issue_card: { productId, name }
183
+ idempotencyKey: crypto.randomUUID(),
184
+ });
185
+ ```
186
+
187
+ Paying in another currency than the card's needs a quote in the card's
188
+ currency first: `deposits.quote({ amount, currency, card_id })`, or
189
+ `target_currency` for a card that doesn't exist yet.
190
+
191
+ The deposit comes back with `target: "card"` and a `card_load_status`. It is
192
+ `pending` until the card provider has loaded the card, then `succeeded`. If
193
+ the card can't take it, the deployment either puts the money on the wallet
194
+ (`returned_to_wallet_at` is set and the user gets a notification) or keeps
195
+ it for support to finish (`card_load_status: "failed"`). Errors:
196
+ `target_not_allowed` (this connector doesn't top up that target),
197
+ `card_not_eligible` (the card isn't active or isn't prepaid),
198
+ `amount_too_small` (a new card's price plus a starting balance don't fit in
199
+ the amount).
200
+
147
201
  ## Telegram Mini App
148
202
 
149
203
  Run inside a Telegram Mini App? Exchange the Telegram-signed `initData` for a
@@ -285,6 +339,314 @@ type User = {
285
339
  };
286
340
  ```
287
341
 
342
+ ## Money history
343
+
344
+ One list of everything that happened to the user's money, newest first:
345
+ card payments and declines, refunds, card issuance, card top-ups, transfers
346
+ between the user's own cards, wallet top-ups, fees.
347
+
348
+ ```ts
349
+ const page = await client.history.list({ limit: 30 }); // lang: "ru" for Russian titles
350
+ const older = await client.history.list({ cursor: page.next_cursor! });
351
+ const oneCard = await client.history.list({ cardId: card.id });
352
+ ```
353
+
354
+ Each entry reads the same way: `title`, `amount` (always positive) with
355
+ `direction` (`out`, `in` or `internal`), `status` and `occurred_at`.
356
+
357
+ - `amount` is in the currency the operation happened in. When there was a
358
+ conversion, `counter_amount` holds the other side and `fx_rate` the rate:
359
+ a purchase in euros billed in dollars, or a top-up paid in roubles that
360
+ arrived in dollars.
361
+ - A declined payment has `status: "declined"` and a `decline_reason` with a
362
+ stable `code` and a `text` to show as is.
363
+ - A transfer between cards is one entry with `card` and `to_card`.
364
+ - `pending` means the operation isn't finished yet.
365
+
366
+ New kinds will be added. Show an entry of an unknown `kind` with its
367
+ `title`, `amount` and `status` rather than hiding it.
368
+
369
+ A `bonus` entry counts bonuses, not money: its `amount.currency` is `BNS`.
370
+ When bonuses paid for something, `counter_amount` is the part of the price
371
+ they covered.
372
+
373
+ ## Bonuses
374
+
375
+ Bonuses are a discount on the platform's services. They pay for part of a
376
+ new card's price or of the subscription fee. Bonuses that came with a
377
+ payment can also be added on top of a top-up; gifts can't.
378
+
379
+ ```ts
380
+ const bonus = await client.bonus.get(); // balance, where they can go, credits, history
381
+
382
+ // "Was / now" before the user confirms, worked out on the server:
383
+ const p = await client.bonus.preview({ purpose: "card_issuance", amount: "10", currency: "USD", productId });
384
+ // p.amount "10", p.bonus_units "5", p.due "5"
385
+
386
+ const card = await client.cards.create({ productId, currency: "USD", idempotencyKey });
387
+ // card.bonus: { units, price, covered, paid, currency } when bonuses were used
388
+
389
+ const top = await client.deposits.initiate({ amount: "25", currency: "USD", method: "card", idempotencyKey });
390
+ // top.bonus_units / top.bonus_value: what was added on top of the 25
391
+ ```
392
+
393
+ - Bonuses are used by default whenever the user has some. Pass
394
+ `useBonus: false` (cards) or `use_bonus: false` (deposits) to pay in money
395
+ only, or `bonusAmount` / `bonus_amount` to cap how many go in. The
396
+ subscription fee takes bonuses on its own.
397
+ - Show the balance as a number of bonuses and nothing else. No money figure
398
+ next to it: money belongs next to a price ("was / now", "N bonuses will be
399
+ used").
400
+ - In your copy, call bonuses a discount. Keep words like funds, withdraw or
401
+ exchange away from them.
402
+
403
+ ## Promo and referral codes
404
+
405
+ A code goes with the operation it is for. At sign-up an unknown or expired
406
+ code never blocks the account: it is created, and `code_result` says why the
407
+ code wasn't applied.
408
+
409
+ ```ts
410
+ // Sign-up on the site, with the code from the form or the link.
411
+ const s = await client.auth.register({ email, password, code: "SPRING" });
412
+ // s.code_result: { status: "applied" | "rejected", reason, message, effects }
413
+
414
+ // Mini App: a `startapp=<code>` link is read by the server; `code` overrides it.
415
+ const tg = await client.auth.exchangeTelegram({ initData });
416
+ // tg.code_result is set for a new account opened with a code
417
+
418
+ // Check a code before the user pays; nothing is used up.
419
+ const c = await client.codes.validate({ code: "SPRING", operation: "card_issuance", amount: "10", currency: "USD" });
420
+ // c.valid, c.discount, c.discount_value "5", c.effects
421
+
422
+ await client.cards.create({ productId, currency: "USD", promoCode: "SPRING", idempotencyKey });
423
+ await client.deposits.initiate({ amount: "100", currency: "USD", method: "card", promo_code: "SPRING", idempotencyKey });
424
+ await client.subscription.setPromoCode("SPRING"); // the monthly fee, while the code allows
425
+
426
+ // For referrers: the code, the link to share, friends (no names) and rewards.
427
+ const ref = await client.referral.get();
428
+ ```
429
+
430
+ - A code that can't be used on a card or a top-up fails the request with
431
+ 400 `promo_code_<reason>` and a sentence to show.
432
+ - A code the user signed up with keeps working on the operations its
433
+ program covers, within its limits, so "half off the first card" can come
434
+ with a sign-up link without the user typing it again.
435
+ - `client.subscription.get()` shows a gift subscription as `kind: "gift"`;
436
+ `gift_until: null` means it doesn't end.
437
+ - Rewards and code bonuses are bonuses: a discount on our services, not
438
+ money. Show friends without names; the API sends none.
439
+
440
+ ## Documents
441
+
442
+ Everything the operators write lives in one tree: blog posts, the knowledge
443
+ base, legal pages. `client.documents` reads it. The calls work before the
444
+ user signs in and show more once they have: a signed-in user also gets the
445
+ articles marked for users. The SDK attaches the session token when it has
446
+ one, so the same call serves the public site and the cabinet.
447
+
448
+ ```ts
449
+ // The public blog, newest first.
450
+ const { documents, total } = await client.documents.list({ category: "blog", perPage: 10 });
451
+
452
+ // The knowledge base for a sidebar: folders plus the articles in them.
453
+ const tree = await client.documents.tree({ category: "knowledge-base" });
454
+ const roots = tree.folders.filter((f) => f.parent_id === null);
455
+
456
+ // One document by its permanent address.
457
+ const doc = await client.documents.get("how-to-top-up");
458
+
459
+ // Tags work across categories.
460
+ const tagged = await client.documents.list({ tag: "fees" });
461
+ const tags = await client.documents.tags();
462
+ ```
463
+
464
+ A document comes as `body_blocks` (typed nodes to map onto your components)
465
+ and `body_markdown` (for your own renderer). Image URLs are relative to the
466
+ API origin; `client.assetUrl(url)` makes them absolute.
467
+
468
+ Links between documents arrive as site paths: `/blog/<slug>` for a post,
469
+ `/docs/<slug>` for anything else. Each document's `site_path` says which one
470
+ it lives at. Route those two prefixes to your document pages and the links
471
+ keep working when a document is renamed or moved.
472
+
473
+ ### Legal pages and their history
474
+
475
+ Every saved text is a version with the date it took effect. The footer
476
+ links to the current text; a contract page can show what applied on a given
477
+ day.
478
+
479
+ ```ts
480
+ const offer = await client.documents.get("offer"); // in force now
481
+ const history = await client.documents.versions("offer"); // newest first
482
+ const old = await client.documents.get("offer", { at: "2026-01-01T00:00:00Z" });
483
+ const v2 = await client.documents.version("offer", 2);
484
+ ```
485
+
486
+ A version dated ahead stays out of `get()` until its day comes, so a new
487
+ redaction can be prepared in advance.
488
+
489
+ ### From `client.blog`
490
+
491
+ `client.blog` still works for one release and is marked deprecated. Same
492
+ posts, same slugs: `client.blog.list()` is `client.documents.list({ category: "blog" })`
493
+ with `documents` instead of `posts` in the result, and `client.blog.get(slug)`
494
+ is `client.documents.get(slug)`.
495
+
496
+ ## Where users come from
497
+
498
+ Every account gets a record of where its owner came from: the first visit,
499
+ the last one before sign-up and how many there were in between. The app's
500
+ part is to report visits and to pass the visitor's key at sign-up.
501
+
502
+ ```ts
503
+ import { anonymousKey, currentTouch } from "@takeal/cusfront-sdk";
504
+
505
+ // On every page load. A visit with nothing new is not stored, so there is
506
+ // no need to decide on the client side.
507
+ const key = anonymousKey();
508
+ if (key) await client.attribution.touch({ anonymous_key: key, ...currentTouch() });
509
+
510
+ // In the sign-up form.
511
+ await client.auth.register({ email, password, attribution: { anonymous_key: key } });
512
+ ```
513
+
514
+ `anonymousKey()` keeps a random id in a cookie and in `localStorage` for a
515
+ year. If one of the two is cleared, the id comes back from the other. Pass
516
+ `{ cookieDomain: ".example.com" }` when the site and the app live on
517
+ different subdomains. In the Telegram Mini App the key is the Telegram id,
518
+ and the server reads the `startapp` code from `initData` itself.
519
+
520
+ A visit counts as your campaign only when its code is in the operator's
521
+ campaign directory. Put the code in `utm_campaign`, or in a Telegram link as
522
+ `startapp=<code>`.
523
+
524
+ After sign-up, ask how the user heard about you, once:
525
+
526
+ ```ts
527
+ const { survey_pending } = await client.attribution.status();
528
+ if (survey_pending) {
529
+ // "friend" | "telegram_channel" | "search" | "ads" | "review" | "other" | "skipped"
530
+ await client.attribution.answerSurvey("other", "A podcast");
531
+ }
532
+ ```
533
+
534
+ ## Analytics
535
+
536
+ Call `track()` once per event and the SDK hands it on: to PostHog on every page, to Yandex Metrica on public pages only. Nothing is bundled. PostHog comes from your own `posthog-js` when you pass `load`, otherwise from its script; Metrica comes from its tag script. Neither loads until `initAnalytics` asks for it.
537
+
538
+ Every page belongs to a zone, and the zone decides what is collected:
539
+
540
+ | | `public` | `cabinet`, `miniapp` |
541
+ |---|---|---|
542
+ | PostHog autocapture | on, with element texts | on, without texts or attributes |
543
+ | Heatmaps | on | off |
544
+ | Masking | inputs | every input and all text |
545
+ | Session recording | off | off; `sessionRecording: true` turns it on, masked |
546
+ | Yandex Metrica | yes, without Webvisor | never |
547
+
548
+ ### Public pages
549
+
550
+ ```ts
551
+ import { initAnalytics, track, identify, posthogDistinctId } from "@takeal/cusfront-sdk/analytics";
552
+
553
+ initAnalytics({
554
+ zone: "public",
555
+ posthog: { key: "phc_…", host: "https://example.com/ingest" },
556
+ metrika: { counterId: 12345678 },
557
+ });
558
+
559
+ track("signup_started");
560
+
561
+ // The sign-up form.
562
+ const session = await client.auth.register({
563
+ email,
564
+ password,
565
+ attribution: { anonymous_key: key, posthog_distinct_id: await posthogDistinctId() },
566
+ });
567
+ track("signup_completed");
568
+ identify(session.user.id);
569
+ ```
570
+
571
+ ### Cabinet
572
+
573
+ ```ts
574
+ import { initAnalytics, identify, resetAnalytics, NO_CAPTURE_CLASS } from "@takeal/cusfront-sdk/analytics";
575
+
576
+ initAnalytics({
577
+ zone: "cabinet",
578
+ posthog: {
579
+ key: "phc_…",
580
+ host: "https://example.com/ingest",
581
+ load: () => import("posthog-js").then((m) => m.default), // posthog-js 1.187 or later
582
+ },
583
+ });
584
+
585
+ identify(session.user.id); // after sign-in
586
+ resetAnalytics(); // on sign-out
587
+ ```
588
+
589
+ Put card details, balances and the operations history inside `NO_CAPTURE_CLASS` (`ph-no-capture`). PostHog leaves these blocks out of autocapture and blanks them in recordings.
590
+
591
+ ```tsx
592
+ <div className={NO_CAPTURE_CLASS}>{balance}</div>
593
+ ```
594
+
595
+ Turn on `sessionRecording: true` last, after you have watched one of your own cabinet sessions in PostHog and seen no values in it at all: no card number, balance, amount or e-mail.
596
+
597
+ ### Telegram Mini App
598
+
599
+ The same as the cabinet, with `zone: "miniapp"`.
600
+
601
+ ### Metrica only on public pages
602
+
603
+ Metrica never loads in the cabinet or in the Mini App, even when `metrika` is passed. From the browser it gets page views and two goals, `signup_started` and `signup_completed`. Deposits, cards and subscriptions reach Metrica from the server with their amount in roubles, so the browser doesn't send them. Webvisor, the click map and link tracking are off: Metrica sees only what the SDK sends it.
604
+
605
+ When the site and the cabinet are one app, call `setAnalyticsZone("cabinet")` as the user enters the cabinet. PostHog switches to masking, and Metrica stops receiving anything. A full page load into the cabinet is safer, because then Metrica isn't on the page at all. If `initAnalytics` finds Metrica on a cabinet page, it warns in the console.
606
+
607
+ ### Events and page views
608
+
609
+ `track(name, props)` accepts only names from `ANALYTICS_EVENTS`, and any other name is a type error. Besides the two sign-up events, the list holds the platform's own event types (`deposit_confirmed`, `card_issued` and the rest), so an event has the same name in PostHog and in reports built from the database.
610
+
611
+ Call `page()` on every route change. `initAnalytics` sends the first page view itself, and the same address twice in a row counts once.
612
+
613
+ Identify users by the platform's user id (`session.user.id`), never by e-mail. PostHog creates profiles for identified users only.
614
+
615
+ ### What never leaves the browser
616
+
617
+ Every event goes through one filter, PostHog's autocapture included:
618
+
619
+ - in page addresses, UUIDs, numeric ids and long tokens become `:id`, query parameters with secrets or personal data are dropped, and so is the fragment. Campaign tags stay;
620
+ - properties named `email`, `phone`, `name`, `first_name` and the like are dropped, and so is any value that looks like an e-mail address, a phone number or a card number;
621
+ - amounts and currencies pass.
622
+
623
+ The same filter is exported as `sanitizeUrl` and `sanitizeProperties`.
624
+
625
+ ### A proxy on your own domain
626
+
627
+ Ad blockers cut direct requests to PostHog, so serve it from a path on your domain and pass that path as `host`. The path should:
628
+
629
+ - forward `/static/*` to `https://eu-assets.i.posthog.com/static/*` and everything else to `https://eu.i.posthog.com`;
630
+ - be left out of the service worker's offline cache, and never cached anywhere else either;
631
+ - stay out of the sitemap and be closed to indexing (`Disallow` in `robots.txt`, `X-Robots-Tag: noindex`).
632
+
633
+ With Next.js:
634
+
635
+ ```js
636
+ // next.config.js
637
+ export default {
638
+ skipTrailingSlashRedirect: true,
639
+ async rewrites() {
640
+ return [
641
+ { source: "/ingest/static/:path*", destination: "https://eu-assets.i.posthog.com/static/:path*" },
642
+ { source: "/ingest/:path*", destination: "https://eu.i.posthog.com/:path*" },
643
+ ];
644
+ },
645
+ };
646
+ ```
647
+
648
+ With Workbox, add `/^\/ingest\//` to `navigateFallbackDenylist` and give the path no runtime caching route.
649
+
288
650
  ## Notifications (inbox)
289
651
 
290
652
  Everything the API tells a user (a confirmed deposit, a card transaction, a
@@ -454,6 +816,36 @@ query), `web` otherwise and on any non-browser runtime. Native wrappers
454
816
  (Capacitor, React Native) can't be told apart from a browser, so pass `ios`
455
817
  or `android` yourself. `version` defaults to the SDK version (`SDK_VERSION`).
456
818
 
819
+ ## Platform version (`client.ready()`)
820
+
821
+ Each SDK release works with a range of platform versions, published as
822
+ `SUPPORTED_MEISTER` (for example `">=0.5.0, <0.6.0"`). `client.ready()` calls
823
+ `GET /ready` (public, no login) and checks the version the deployment reports
824
+ against that range:
825
+
826
+ ```ts
827
+ import { createClient, SUPPORTED_MEISTER } from "@takeal/cusfront-sdk";
828
+
829
+ const client = createClient({ baseUrl: "https://api.your-deployment.example.com" });
830
+ const r = await client.ready();
831
+ // {
832
+ // compatible: true,
833
+ // platformVersion: "0.5.0",
834
+ // supportedMeister: ">=0.5.0, <0.6.0",
835
+ // healthy: true,
836
+ // status: "ready",
837
+ // raw: { ... } // the full /ready body
838
+ // }
839
+ if (!r.compatible) console.warn(r.warning);
840
+ ```
841
+
842
+ `compatible` is `false`, with a one-line `warning`, in two cases: the version
843
+ is outside the range, or the platform didn't report one (deployments older
844
+ than 0.5.0). A degraded platform answers 503 with the same body; `ready()`
845
+ returns it with `healthy: false` rather than throwing. Network failures and
846
+ other errors throw as usual. `satisfies(version, range)` is exported too if
847
+ you want to run the same check yourself.
848
+
457
849
  ## Brand config
458
850
 
459
851
  Whitelabel-friendly by design — the SDK ships no embedded brand. Pass `brand` at runtime and the client app reads it back via `client.brand`:
@@ -491,9 +883,12 @@ Available now:
491
883
  - `@takeal/cusfront-sdk` — `createClient` + types.
492
884
  - `@takeal/cusfront-sdk/auth` — auth-only entry.
493
885
  - `@takeal/cusfront-sdk/deposits` — `DepositsResource` (money IN via a funder connector).
886
+ - `@takeal/cusfront-sdk/funding-options` — `FundingOptionsResource` (the ways to top up; see [Topping up a card directly](#topping-up-a-card-directly)).
494
887
  - `@takeal/cusfront-sdk/cards` — `CardsResource` (cards backed by the wallet balance).
495
888
  - `@takeal/cusfront-sdk/balance` — `BalanceResource` (per-currency wallet balance).
496
- - `@takeal/cusfront-sdk/blog` — `BlogResource` (public posts as structured blocks).
889
+ - `@takeal/cusfront-sdk/bonus` — `BonusResource` (bonuses and a price preview; see [Bonuses](#bonuses)).
890
+ - `@takeal/cusfront-sdk/documents` — `DocumentsResource` (blog posts, the knowledge base, legal pages; see [Documents](#documents)).
891
+ - `@takeal/cusfront-sdk/blog` — `BlogResource` (deprecated: the blog is a category of Documents now).
497
892
  - `@takeal/cusfront-sdk/subscriptions` — `SubscriptionsResource` (announcement channels; deprecated, see [Preferences](#preferences)).
498
893
  - `@takeal/cusfront-sdk/wallet` — `WalletResource` (the wallet's currency).
499
894
  - `@takeal/cusfront-sdk/sessions` — `SessionsResource` (where the user is signed in).
@@ -501,9 +896,12 @@ Available now:
501
896
  - `@takeal/cusfront-sdk/notifications` — `NotificationsResource` (the inbox and notification preferences).
502
897
  - `@takeal/cusfront-sdk/devices` — `DevicesResource` (Web Push, mobile push tokens, the Telegram Mini App marker).
503
898
  - `@takeal/cusfront-sdk/me` — `MeResource` (link or unlink Telegram for the signed-in user).
899
+ - `@takeal/cusfront-sdk/history` — `HistoryResource` (the user's money history).
900
+ - `@takeal/cusfront-sdk/attribution` — `AttributionResource`, `anonymousKey`, `currentTouch` (where users come from).
504
901
  - `@takeal/cusfront-sdk/webhooks` — HMAC-SHA256 signature verifier (no network, isomorphic).
505
902
  - `@takeal/cusfront-sdk/react` — optional React hooks layer (`ClientProvider` + `useMe` / `useDeposits` / `useCards` / `useCardProducts` / `useBalance` / `useNotifications` / `useUnreadCount`). React is a `peerDependency`, never bundled.
506
903
  - `@takeal/cusfront-sdk/telegram` — Telegram Mini App `initData` → authenticated client bridge.
904
+ - `@takeal/cusfront-sdk/analytics` — `initAnalytics`, `track`, `page`, `identify`, `resetAnalytics`, `posthogDistinctId` (PostHog and Yandex Metrica behind one call; see [Analytics](#analytics)).
507
905
 
508
906
  ### Verifying webhooks
509
907
 
@@ -526,8 +924,9 @@ Algorithm: HMAC-SHA256, header `X-Takeal-Signature: sha256=<hex>`, signed over
526
924
  the raw body bytes (no timestamp). Comparison is constant-time.
527
925
 
528
926
  > **Card details:** `client.cards.reveal()` returns the full card number and
529
- > CVV to the signed-in user; no password or code is asked again, and the API
530
- > rate-limits and logs every call. The rest of
927
+ > CVV to the signed-in user, along with the billing address the card is
928
+ > registered at, which merchants ask for at checkout; no password or code is
929
+ > asked again, and the API rate-limits and logs every call. The rest of
531
930
  > `client.cards` is catalog, listProducts, getProduct, create, get, list,
532
931
  > update, balance, topUpTerms, topUp, freeze, unfreeze and terminate.
533
932