@takeal/cusfront-sdk 0.1.0 → 0.3.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 (91) hide show
  1. package/CHANGELOG.md +104 -2
  2. package/README.md +393 -14
  3. package/dist/devices-C3JHi2Hi.d.cts +165 -0
  4. package/dist/devices-DP_hxwmW.d.ts +165 -0
  5. package/dist/{http-BkZZZI8K.d.cts → http-B-OQwMYn.d.cts} +13 -2
  6. package/dist/{http-BkZZZI8K.d.ts → http-B-OQwMYn.d.ts} +13 -2
  7. package/dist/index.cjs +425 -25
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.cts +77 -8
  10. package/dist/index.d.ts +77 -8
  11. package/dist/index.js +422 -26
  12. package/dist/index.js.map +1 -1
  13. package/dist/react/index.cjs +133 -6
  14. package/dist/react/index.cjs.map +1 -1
  15. package/dist/react/index.d.cts +65 -3
  16. package/dist/react/index.d.ts +65 -3
  17. package/dist/react/index.js +131 -8
  18. package/dist/react/index.js.map +1 -1
  19. package/dist/resources/auth.cjs +73 -15
  20. package/dist/resources/auth.cjs.map +1 -1
  21. package/dist/resources/auth.d.cts +100 -9
  22. package/dist/resources/auth.d.ts +100 -9
  23. package/dist/resources/auth.js +73 -15
  24. package/dist/resources/auth.js.map +1 -1
  25. package/dist/resources/balance.cjs +4 -3
  26. package/dist/resources/balance.cjs.map +1 -1
  27. package/dist/resources/balance.d.cts +8 -9
  28. package/dist/resources/balance.d.ts +8 -9
  29. package/dist/resources/balance.js +4 -3
  30. package/dist/resources/balance.js.map +1 -1
  31. package/dist/resources/blog.d.cts +1 -1
  32. package/dist/resources/blog.d.ts +1 -1
  33. package/dist/resources/branding.cjs.map +1 -1
  34. package/dist/resources/branding.d.cts +8 -2
  35. package/dist/resources/branding.d.ts +8 -2
  36. package/dist/resources/branding.js.map +1 -1
  37. package/dist/resources/cards.cjs +33 -1
  38. package/dist/resources/cards.cjs.map +1 -1
  39. package/dist/resources/cards.d.cts +105 -4
  40. package/dist/resources/cards.d.ts +105 -4
  41. package/dist/resources/cards.js +33 -1
  42. package/dist/resources/cards.js.map +1 -1
  43. package/dist/resources/deposits.d.cts +1 -1
  44. package/dist/resources/deposits.d.ts +1 -1
  45. package/dist/resources/devices.cjs +92 -0
  46. package/dist/resources/devices.cjs.map +1 -0
  47. package/dist/resources/devices.d.cts +3 -0
  48. package/dist/resources/devices.d.ts +3 -0
  49. package/dist/resources/devices.js +89 -0
  50. package/dist/resources/devices.js.map +1 -0
  51. package/dist/resources/me.cjs +32 -0
  52. package/dist/resources/me.cjs.map +1 -0
  53. package/dist/resources/me.d.cts +40 -0
  54. package/dist/resources/me.d.ts +40 -0
  55. package/dist/resources/me.js +30 -0
  56. package/dist/resources/me.js.map +1 -0
  57. package/dist/resources/notifications.cjs +53 -0
  58. package/dist/resources/notifications.cjs.map +1 -0
  59. package/dist/resources/notifications.d.cts +109 -0
  60. package/dist/resources/notifications.d.ts +109 -0
  61. package/dist/resources/notifications.js +51 -0
  62. package/dist/resources/notifications.js.map +1 -0
  63. package/dist/resources/push.cjs +65 -0
  64. package/dist/resources/push.cjs.map +1 -0
  65. package/dist/resources/push.d.cts +76 -0
  66. package/dist/resources/push.d.ts +76 -0
  67. package/dist/resources/push.js +62 -0
  68. package/dist/resources/push.js.map +1 -0
  69. package/dist/resources/sessions.cjs +26 -0
  70. package/dist/resources/sessions.cjs.map +1 -0
  71. package/dist/resources/sessions.d.cts +43 -0
  72. package/dist/resources/sessions.d.ts +43 -0
  73. package/dist/resources/sessions.js +24 -0
  74. package/dist/resources/sessions.js.map +1 -0
  75. package/dist/resources/subscriptions.cjs.map +1 -1
  76. package/dist/resources/subscriptions.d.cts +8 -1
  77. package/dist/resources/subscriptions.d.ts +8 -1
  78. package/dist/resources/subscriptions.js.map +1 -1
  79. package/dist/resources/wallet.cjs +24 -0
  80. package/dist/resources/wallet.cjs.map +1 -0
  81. package/dist/resources/wallet.d.cts +39 -0
  82. package/dist/resources/wallet.d.ts +39 -0
  83. package/dist/resources/wallet.js +22 -0
  84. package/dist/resources/wallet.js.map +1 -0
  85. package/dist/telegram.cjs +466 -28
  86. package/dist/telegram.cjs.map +1 -1
  87. package/dist/telegram.d.cts +65 -7
  88. package/dist/telegram.d.ts +65 -7
  89. package/dist/telegram.js +465 -29
  90. package/dist/telegram.js.map +1 -1
  91. package/package.json +37 -3
@@ -1,13 +1,19 @@
1
- import { CreateClientOptions, CusfrontClient } from './index.js';
2
- import { JwtIssued } from './resources/auth.js';
3
- import './http-BkZZZI8K.js';
1
+ import { CusfrontClient, CreateClientOptions } from './index.js';
2
+ import { JwtIssued, TelegramUnknown } from './resources/auth.js';
3
+ import './http-B-OQwMYn.js';
4
4
  import './resources/deposits.js';
5
5
  import './customer-CoxPwe5o.js';
6
6
  import './resources/cards.js';
7
7
  import './resources/balance.js';
8
8
  import './resources/branding.js';
9
+ import './resources/wallet.js';
9
10
  import './resources/blog.js';
10
11
  import './resources/subscriptions.js';
12
+ import './resources/sessions.js';
13
+ import './resources/push.js';
14
+ import './resources/me.js';
15
+ import './resources/notifications.js';
16
+ import './devices-DP_hxwmW.js';
11
17
 
12
18
  /**
13
19
  * `@takeal/cusfront-sdk/telegram` — Telegram Mini App adapter.
@@ -76,15 +82,65 @@ interface FromInitDataOptions extends WellFormedOptions {
76
82
  * sole judge. Default false — the fail-fast check saves a round-trip on
77
83
  * obviously-bad input. */
78
84
  skipWellFormedCheck?: boolean;
85
+ /** Create an account for a Telegram id the deployment has not seen before.
86
+ * Default `true`. With `false`, an unknown id makes {@link fromInitData} /
87
+ * {@link fromTelegramWebApp} throw {@link TelegramUnknownError} (and
88
+ * {@link exchangeInitData} resolve with `session.stage === "unknown"`)
89
+ * instead of creating anything. */
90
+ provision?: boolean;
91
+ /** After a successful exchange, register this Mini App as a
92
+ * `telegram_miniapp` device so notifications reach the user as bot
93
+ * messages. Default `true`. Best-effort: a failure is logged as a
94
+ * warning and never fails the sign-in. */
95
+ registerDevice?: boolean;
96
+ }
97
+ /** Thrown by {@link fromInitData} / {@link fromTelegramWebApp} when
98
+ * `provision: false` was passed and the Telegram id has no account yet.
99
+ * Nothing was created and no JWT was stored. `initData` is the payload that
100
+ * was exchanged, so the app can go on with
101
+ * `client.auth.linkTelegram({ initData, email, password })` or retry with
102
+ * `provision: true`. */
103
+ declare class TelegramUnknownError extends Error {
104
+ readonly initData: string;
105
+ constructor(initData: string);
106
+ }
107
+ /** What {@link exchangeInitData} resolves to. When `session.stage` is
108
+ * `"jwt"` the client is signed in; when it is `"unknown"` the client is
109
+ * built but has no session. */
110
+ interface InitDataExchange {
111
+ client: CusfrontClient;
112
+ session: JwtIssued | TelegramUnknown;
79
113
  }
80
114
  /**
81
- * Build an authenticated client from a raw `initData` string.
115
+ * Build a client from a raw `initData` string and exchange the payload,
116
+ * returning both the client and the exchange result.
82
117
  *
83
118
  * 1. (unless skipped) structurally validate the payload — throws
84
119
  * {@link InitDataError} on malformed/stale input.
85
120
  * 2. exchange it at `POST /auth/telegram/exchange` — the server validates the
86
121
  * HMAC; a bad signature throws a 401 `ApiError`.
87
- * 3. store the returned JWT and return the ready-to-use client.
122
+ * 3. on `stage: "jwt"` the JWT is stored and the client is ready. With
123
+ * `provision: false` and a Telegram id nobody has signed in with,
124
+ * `session` is `{ stage: "unknown" }` and the client is unauthenticated;
125
+ * continue with `client.auth.linkTelegram(...)` or
126
+ * `client.auth.exchangeTelegram({ initData, provision: true })`.
127
+ * 4. on `stage: "jwt"` the Mini App is registered as a `telegram_miniapp`
128
+ * device (unless `registerDevice: false`), so the user's notifications
129
+ * arrive as bot messages. Errors here are only logged.
130
+ *
131
+ * The client announces itself as `telegram-miniapp` in `X-Takeal-Client`
132
+ * whatever `config.client.platform` says; a given `config.client.version`
133
+ * is kept.
134
+ *
135
+ * Use this when the app wants to branch on the outcome itself;
136
+ * {@link fromInitData} is the throwing shorthand.
137
+ */
138
+ declare function exchangeInitData(initData: string, config: CreateClientOptions, opts?: FromInitDataOptions): Promise<InitDataExchange>;
139
+ /**
140
+ * Build an authenticated client from a raw `initData` string. Thin wrapper
141
+ * over {@link exchangeInitData} that never hands back a client without a
142
+ * session: with `provision: false` and an unknown Telegram id it throws
143
+ * {@link TelegramUnknownError} (carrying `initData`) instead.
88
144
  *
89
145
  * Read `client.auth.me()` (or call `client.auth.exchangeTelegram` directly for
90
146
  * the raw session) to check `email_pending` and prompt for an email.
@@ -95,11 +151,13 @@ declare function fromInitData(initData: string, config: CreateClientOptions, opt
95
151
  declare function readWebAppInitData(): string | null;
96
152
  /**
97
153
  * Convenience entry for a Mini App: read `initData` from the Telegram WebApp
98
- * SDK and exchange it. Throws if not running inside a Telegram Mini App.
154
+ * SDK and exchange it. Throws {@link InitDataError} if not running inside a
155
+ * Telegram Mini App, and {@link TelegramUnknownError} when `provision: false`
156
+ * was passed and the Telegram id has no account yet.
99
157
  */
100
158
  declare function fromTelegramWebApp(config: CreateClientOptions, opts?: FromInitDataOptions): Promise<CusfrontClient>;
101
159
  /** Convenience accessor for the typed exchange session (incl. `email_pending`)
102
160
  * when you need the envelope rather than just the client. */
103
161
  type TelegramExchangeSession = JwtIssued;
104
162
 
105
- export { type FromInitDataOptions, InitDataError, type ParsedInitData, type TelegramExchangeSession, type TelegramUser, type WellFormedOptions, assertWellFormed, fromInitData, fromTelegramWebApp, parseInitData, readWebAppInitData };
163
+ export { type FromInitDataOptions, InitDataError, type InitDataExchange, type ParsedInitData, type TelegramExchangeSession, TelegramUnknownError, type TelegramUser, type WellFormedOptions, assertWellFormed, exchangeInitData, fromInitData, fromTelegramWebApp, parseInitData, readWebAppInitData };