@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.
- package/CHANGELOG.md +104 -2
- package/README.md +393 -14
- package/dist/devices-C3JHi2Hi.d.cts +165 -0
- package/dist/devices-DP_hxwmW.d.ts +165 -0
- package/dist/{http-BkZZZI8K.d.cts → http-B-OQwMYn.d.cts} +13 -2
- package/dist/{http-BkZZZI8K.d.ts → http-B-OQwMYn.d.ts} +13 -2
- package/dist/index.cjs +425 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +77 -8
- package/dist/index.d.ts +77 -8
- package/dist/index.js +422 -26
- package/dist/index.js.map +1 -1
- package/dist/react/index.cjs +133 -6
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +65 -3
- package/dist/react/index.d.ts +65 -3
- package/dist/react/index.js +131 -8
- package/dist/react/index.js.map +1 -1
- package/dist/resources/auth.cjs +73 -15
- package/dist/resources/auth.cjs.map +1 -1
- package/dist/resources/auth.d.cts +100 -9
- package/dist/resources/auth.d.ts +100 -9
- package/dist/resources/auth.js +73 -15
- package/dist/resources/auth.js.map +1 -1
- package/dist/resources/balance.cjs +4 -3
- package/dist/resources/balance.cjs.map +1 -1
- package/dist/resources/balance.d.cts +8 -9
- package/dist/resources/balance.d.ts +8 -9
- package/dist/resources/balance.js +4 -3
- package/dist/resources/balance.js.map +1 -1
- package/dist/resources/blog.d.cts +1 -1
- package/dist/resources/blog.d.ts +1 -1
- package/dist/resources/branding.cjs.map +1 -1
- package/dist/resources/branding.d.cts +8 -2
- package/dist/resources/branding.d.ts +8 -2
- package/dist/resources/branding.js.map +1 -1
- package/dist/resources/cards.cjs +33 -1
- package/dist/resources/cards.cjs.map +1 -1
- package/dist/resources/cards.d.cts +105 -4
- package/dist/resources/cards.d.ts +105 -4
- package/dist/resources/cards.js +33 -1
- package/dist/resources/cards.js.map +1 -1
- package/dist/resources/deposits.d.cts +1 -1
- package/dist/resources/deposits.d.ts +1 -1
- package/dist/resources/devices.cjs +92 -0
- package/dist/resources/devices.cjs.map +1 -0
- package/dist/resources/devices.d.cts +3 -0
- package/dist/resources/devices.d.ts +3 -0
- package/dist/resources/devices.js +89 -0
- package/dist/resources/devices.js.map +1 -0
- package/dist/resources/me.cjs +32 -0
- package/dist/resources/me.cjs.map +1 -0
- package/dist/resources/me.d.cts +40 -0
- package/dist/resources/me.d.ts +40 -0
- package/dist/resources/me.js +30 -0
- package/dist/resources/me.js.map +1 -0
- package/dist/resources/notifications.cjs +53 -0
- package/dist/resources/notifications.cjs.map +1 -0
- package/dist/resources/notifications.d.cts +109 -0
- package/dist/resources/notifications.d.ts +109 -0
- package/dist/resources/notifications.js +51 -0
- package/dist/resources/notifications.js.map +1 -0
- package/dist/resources/push.cjs +65 -0
- package/dist/resources/push.cjs.map +1 -0
- package/dist/resources/push.d.cts +76 -0
- package/dist/resources/push.d.ts +76 -0
- package/dist/resources/push.js +62 -0
- package/dist/resources/push.js.map +1 -0
- package/dist/resources/sessions.cjs +26 -0
- package/dist/resources/sessions.cjs.map +1 -0
- package/dist/resources/sessions.d.cts +43 -0
- package/dist/resources/sessions.d.ts +43 -0
- package/dist/resources/sessions.js +24 -0
- package/dist/resources/sessions.js.map +1 -0
- package/dist/resources/subscriptions.cjs.map +1 -1
- package/dist/resources/subscriptions.d.cts +8 -1
- package/dist/resources/subscriptions.d.ts +8 -1
- package/dist/resources/subscriptions.js.map +1 -1
- package/dist/resources/wallet.cjs +24 -0
- package/dist/resources/wallet.cjs.map +1 -0
- package/dist/resources/wallet.d.cts +39 -0
- package/dist/resources/wallet.d.ts +39 -0
- package/dist/resources/wallet.js +22 -0
- package/dist/resources/wallet.js.map +1 -0
- package/dist/telegram.cjs +466 -28
- package/dist/telegram.cjs.map +1 -1
- package/dist/telegram.d.cts +65 -7
- package/dist/telegram.d.ts +65 -7
- package/dist/telegram.js +465 -29
- package/dist/telegram.js.map +1 -1
- package/package.json +37 -3
package/dist/telegram.d.ts
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { JwtIssued } from './resources/auth.js';
|
|
3
|
-
import './http-
|
|
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
|
|
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.
|
|
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
|
|
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 };
|