@takeal/cusfront-sdk 0.2.8 → 0.3.7

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 (77) hide show
  1. package/CHANGELOG.md +100 -0
  2. package/README.md +367 -5
  3. package/dist/devices-C3JHi2Hi.d.cts +165 -0
  4. package/dist/devices-DP_hxwmW.d.ts +165 -0
  5. package/dist/{http-BkCfOCR0.d.cts → http-B-OQwMYn.d.cts} +9 -1
  6. package/dist/{http-BkCfOCR0.d.ts → http-B-OQwMYn.d.ts} +9 -1
  7. package/dist/index.cjs +284 -20
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.cts +65 -9
  10. package/dist/index.d.ts +65 -9
  11. package/dist/index.js +280 -21
  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 +62 -3
  16. package/dist/react/index.d.ts +62 -3
  17. package/dist/react/index.js +131 -8
  18. package/dist/react/index.js.map +1 -1
  19. package/dist/resources/auth.cjs +36 -11
  20. package/dist/resources/auth.cjs.map +1 -1
  21. package/dist/resources/auth.d.cts +57 -5
  22. package/dist/resources/auth.d.ts +57 -5
  23. package/dist/resources/auth.js +36 -11
  24. package/dist/resources/auth.js.map +1 -1
  25. package/dist/resources/balance.d.cts +1 -1
  26. package/dist/resources/balance.d.ts +1 -1
  27. package/dist/resources/blog.d.cts +1 -1
  28. package/dist/resources/blog.d.ts +1 -1
  29. package/dist/resources/branding.d.cts +1 -1
  30. package/dist/resources/branding.d.ts +1 -1
  31. package/dist/resources/cards.cjs +33 -1
  32. package/dist/resources/cards.cjs.map +1 -1
  33. package/dist/resources/cards.d.cts +111 -4
  34. package/dist/resources/cards.d.ts +111 -4
  35. package/dist/resources/cards.js +33 -1
  36. package/dist/resources/cards.js.map +1 -1
  37. package/dist/resources/deposits.d.cts +1 -1
  38. package/dist/resources/deposits.d.ts +1 -1
  39. package/dist/resources/devices.cjs +92 -0
  40. package/dist/resources/devices.cjs.map +1 -0
  41. package/dist/resources/devices.d.cts +3 -0
  42. package/dist/resources/devices.d.ts +3 -0
  43. package/dist/resources/devices.js +89 -0
  44. package/dist/resources/devices.js.map +1 -0
  45. package/dist/resources/me.cjs +32 -0
  46. package/dist/resources/me.cjs.map +1 -0
  47. package/dist/resources/me.d.cts +40 -0
  48. package/dist/resources/me.d.ts +40 -0
  49. package/dist/resources/me.js +30 -0
  50. package/dist/resources/me.js.map +1 -0
  51. package/dist/resources/notifications.cjs +57 -0
  52. package/dist/resources/notifications.cjs.map +1 -0
  53. package/dist/resources/notifications.d.cts +133 -0
  54. package/dist/resources/notifications.d.ts +133 -0
  55. package/dist/resources/notifications.js +54 -0
  56. package/dist/resources/notifications.js.map +1 -0
  57. package/dist/resources/push.cjs +8 -4
  58. package/dist/resources/push.cjs.map +1 -1
  59. package/dist/resources/push.d.cts +14 -17
  60. package/dist/resources/push.d.ts +14 -17
  61. package/dist/resources/push.js +8 -4
  62. package/dist/resources/push.js.map +1 -1
  63. package/dist/resources/sessions.d.cts +1 -1
  64. package/dist/resources/sessions.d.ts +1 -1
  65. package/dist/resources/subscriptions.cjs.map +1 -1
  66. package/dist/resources/subscriptions.d.cts +8 -1
  67. package/dist/resources/subscriptions.d.ts +8 -1
  68. package/dist/resources/subscriptions.js.map +1 -1
  69. package/dist/resources/wallet.d.cts +1 -1
  70. package/dist/resources/wallet.d.ts +1 -1
  71. package/dist/telegram.cjs +321 -23
  72. package/dist/telegram.cjs.map +1 -1
  73. package/dist/telegram.d.cts +62 -7
  74. package/dist/telegram.d.ts +62 -7
  75. package/dist/telegram.js +320 -24
  76. package/dist/telegram.js.map +1 -1
  77. package/package.json +23 -4
@@ -0,0 +1,165 @@
1
+ import { H as HttpClient } from './http-B-OQwMYn.cjs';
2
+ import { PushCapableRegistration } from './resources/push.cjs';
3
+
4
+ /**
5
+ * Which kind of app is talking to the API. Sent on every request as
6
+ * `X-Takeal-Client: <platform>; <version>`. The server keeps it on the
7
+ * session: it decides whether a sign-in counts as a new device, and which
8
+ * channel a notification goes out on (a Mini App gets Telegram messages, a
9
+ * PWA gets Web Push, and so on).
10
+ */
11
+ type ClientPlatform = "pwa" | "web" | "telegram-miniapp" | "ios" | "android";
12
+ /** The `client` option of `createClient`. */
13
+ interface ClientDescriptor {
14
+ /** What the app is. Detected at runtime when omitted; see
15
+ * {@link detectClientPlatform}. */
16
+ platform: ClientPlatform;
17
+ /** The app's own version. Defaults to the SDK version. */
18
+ version?: string;
19
+ }
20
+ /** A descriptor with every field filled in. `client.client` on a
21
+ * {@link CusfrontClient} has this shape. */
22
+ interface ResolvedClientDescriptor {
23
+ platform: ClientPlatform;
24
+ version: string;
25
+ }
26
+ /** Header name carrying the client descriptor. */
27
+ declare const CLIENT_HEADER = "X-Takeal-Client";
28
+ /**
29
+ * Best-effort platform detection for browser runtimes:
30
+ *
31
+ * - `telegram-miniapp` when `window.Telegram.WebApp.initData` is non-empty
32
+ * (the app was launched from Telegram);
33
+ * - `pwa` when the page runs installed: iOS Safari's `navigator.standalone`
34
+ * or a `display-mode: standalone` media query;
35
+ * - `web` otherwise, and always outside a browser (Node, workers without a
36
+ * `navigator`).
37
+ *
38
+ * Native wrappers (Capacitor, React Native) should pass `ios` / `android`
39
+ * explicitly; there is no reliable way to tell them apart from a browser.
40
+ */
41
+ declare function detectClientPlatform(): ClientPlatform;
42
+
43
+ /**
44
+ * Devices resource — `client.devices.*`.
45
+ *
46
+ * A user has many devices: each browser with a Web Push subscription, each
47
+ * phone with an FCM / APNs token, and a marker for "uses the Telegram Mini
48
+ * App". The server picks the notification channel from them: a mobile app
49
+ * first, otherwise the device seen most recently.
50
+ *
51
+ * The usual browser flow, once notification permission is granted:
52
+ *
53
+ * ```ts
54
+ * const reg = await navigator.serviceWorker.ready;
55
+ * const device = await client.devices.registerWebPush(reg, { label: "Chrome on Mac" });
56
+ * // later, from a settings screen:
57
+ * await client.devices.unregisterWebPush(reg);
58
+ * ```
59
+ */
60
+ type DeviceKind = "webpush" | "fcm" | "apns" | "telegram_miniapp";
61
+ type DevicePlatform = "pwa" | "web" | "ios" | "android" | "telegram";
62
+ interface Device {
63
+ id: string;
64
+ kind: DeviceKind;
65
+ platform: DevicePlatform;
66
+ /** Free-form name the app gave it ("Chrome on Mac"), or `null`. */
67
+ label: string | null;
68
+ locale: string | null;
69
+ app_version: string | null;
70
+ created_at: string;
71
+ last_seen_at: string;
72
+ /** Set when the device no longer receives anything (the push endpoint is
73
+ * gone, or someone switched it off). */
74
+ disabled_at: string | null;
75
+ /** `true` when it was registered from the session this client holds. */
76
+ is_current: boolean;
77
+ }
78
+ /** `PushSubscription.toJSON()` minus the parts the server doesn't need. */
79
+ interface WebPushCredential {
80
+ /** `PushSubscription.endpoint`; must be https. */
81
+ endpoint: string;
82
+ keys: {
83
+ /** URL-safe base64. */
84
+ p256dh: string;
85
+ /** URL-safe base64. */
86
+ auth: string;
87
+ };
88
+ }
89
+ /** FCM registration token or APNs device token. */
90
+ interface MobilePushCredential {
91
+ token: string;
92
+ }
93
+ type RegisterDeviceInput = {
94
+ kind: "webpush";
95
+ platform: DevicePlatform;
96
+ credential: WebPushCredential;
97
+ label?: string;
98
+ locale?: string;
99
+ app_version?: string;
100
+ } | {
101
+ kind: "fcm" | "apns";
102
+ platform: DevicePlatform;
103
+ credential: MobilePushCredential;
104
+ label?: string;
105
+ locale?: string;
106
+ app_version?: string;
107
+ } | {
108
+ kind: "telegram_miniapp";
109
+ platform: DevicePlatform;
110
+ /** Nothing to send: the device is a marker. */
111
+ credential: Record<string, never>;
112
+ label?: string;
113
+ locale?: string;
114
+ app_version?: string;
115
+ };
116
+ interface RegisteredDevice {
117
+ id: string;
118
+ kind: DeviceKind;
119
+ platform: DevicePlatform;
120
+ /** VAPID public key (URL-safe base64) for `pushManager.subscribe`;
121
+ * `null` when push is not set up on this deployment. */
122
+ vapid_public_key: string | null;
123
+ }
124
+ interface RegisterWebPushOptions {
125
+ /** A name to show in the user's device list ("Chrome on Mac"). */
126
+ label?: string;
127
+ /** Skip the key lookup when you already hold the deployment's VAPID
128
+ * public key (from an earlier `register` result, for example). */
129
+ vapidPublicKey?: string;
130
+ }
131
+ interface UnregisterWebPushOptions {
132
+ /** The device to delete, from an earlier `registerWebPush` result. When
133
+ * omitted, every Web Push device registered from this session goes. */
134
+ deviceId?: string;
135
+ }
136
+ /** Client platform → the platform the device list uses. */
137
+ declare function devicePlatformOf(platform: ClientPlatform): DevicePlatform;
138
+ declare class DevicesResource {
139
+ private readonly http;
140
+ private readonly client;
141
+ constructor(http: HttpClient, client: ResolvedClientDescriptor);
142
+ /** Every device the user has, disabled ones included. */
143
+ list(): Promise<Device[]>;
144
+ /** Register a device, or refresh it when the same credential is already
145
+ * known (then `last_seen_at`, `label` and `app_version` update and a
146
+ * disabled device comes back). `app_version` defaults to the client
147
+ * version sent in `X-Takeal-Client`.
148
+ *
149
+ * Errors: 400 `validation`; 409 `push_disabled` for `webpush` when the
150
+ * deployment has no VAPID keys. */
151
+ register(input: RegisterDeviceInput): Promise<RegisteredDevice>;
152
+ /** Delete one device. 404 when it isn't the user's. */
153
+ remove(id: string): Promise<void>;
154
+ /** Subscribe this browser to Web Push and register it as a device. Ask
155
+ * for notification permission before calling. Throws when push isn't
156
+ * set up on the deployment. */
157
+ registerWebPush(registration: PushCapableRegistration, opts?: RegisterWebPushOptions): Promise<RegisteredDevice>;
158
+ /** Unsubscribe this browser from Web Push and delete the matching device
159
+ * (see {@link UnregisterWebPushOptions}). Safe when nothing is
160
+ * registered. */
161
+ unregisterWebPush(registration: PushCapableRegistration, opts?: UnregisterWebPushOptions): Promise<void>;
162
+ private vapidPublicKey;
163
+ }
164
+
165
+ export { type ClientDescriptor as C, DevicesResource as D, type MobilePushCredential as M, type ResolvedClientDescriptor as R, type UnregisterWebPushOptions as U, type WebPushCredential as W, CLIENT_HEADER as a, type ClientPlatform as b, type Device as c, type DeviceKind as d, type DevicePlatform as e, type RegisterDeviceInput as f, type RegisterWebPushOptions as g, type RegisteredDevice as h, detectClientPlatform as i, devicePlatformOf as j };
@@ -0,0 +1,165 @@
1
+ import { H as HttpClient } from './http-B-OQwMYn.js';
2
+ import { PushCapableRegistration } from './resources/push.js';
3
+
4
+ /**
5
+ * Which kind of app is talking to the API. Sent on every request as
6
+ * `X-Takeal-Client: <platform>; <version>`. The server keeps it on the
7
+ * session: it decides whether a sign-in counts as a new device, and which
8
+ * channel a notification goes out on (a Mini App gets Telegram messages, a
9
+ * PWA gets Web Push, and so on).
10
+ */
11
+ type ClientPlatform = "pwa" | "web" | "telegram-miniapp" | "ios" | "android";
12
+ /** The `client` option of `createClient`. */
13
+ interface ClientDescriptor {
14
+ /** What the app is. Detected at runtime when omitted; see
15
+ * {@link detectClientPlatform}. */
16
+ platform: ClientPlatform;
17
+ /** The app's own version. Defaults to the SDK version. */
18
+ version?: string;
19
+ }
20
+ /** A descriptor with every field filled in. `client.client` on a
21
+ * {@link CusfrontClient} has this shape. */
22
+ interface ResolvedClientDescriptor {
23
+ platform: ClientPlatform;
24
+ version: string;
25
+ }
26
+ /** Header name carrying the client descriptor. */
27
+ declare const CLIENT_HEADER = "X-Takeal-Client";
28
+ /**
29
+ * Best-effort platform detection for browser runtimes:
30
+ *
31
+ * - `telegram-miniapp` when `window.Telegram.WebApp.initData` is non-empty
32
+ * (the app was launched from Telegram);
33
+ * - `pwa` when the page runs installed: iOS Safari's `navigator.standalone`
34
+ * or a `display-mode: standalone` media query;
35
+ * - `web` otherwise, and always outside a browser (Node, workers without a
36
+ * `navigator`).
37
+ *
38
+ * Native wrappers (Capacitor, React Native) should pass `ios` / `android`
39
+ * explicitly; there is no reliable way to tell them apart from a browser.
40
+ */
41
+ declare function detectClientPlatform(): ClientPlatform;
42
+
43
+ /**
44
+ * Devices resource — `client.devices.*`.
45
+ *
46
+ * A user has many devices: each browser with a Web Push subscription, each
47
+ * phone with an FCM / APNs token, and a marker for "uses the Telegram Mini
48
+ * App". The server picks the notification channel from them: a mobile app
49
+ * first, otherwise the device seen most recently.
50
+ *
51
+ * The usual browser flow, once notification permission is granted:
52
+ *
53
+ * ```ts
54
+ * const reg = await navigator.serviceWorker.ready;
55
+ * const device = await client.devices.registerWebPush(reg, { label: "Chrome on Mac" });
56
+ * // later, from a settings screen:
57
+ * await client.devices.unregisterWebPush(reg);
58
+ * ```
59
+ */
60
+ type DeviceKind = "webpush" | "fcm" | "apns" | "telegram_miniapp";
61
+ type DevicePlatform = "pwa" | "web" | "ios" | "android" | "telegram";
62
+ interface Device {
63
+ id: string;
64
+ kind: DeviceKind;
65
+ platform: DevicePlatform;
66
+ /** Free-form name the app gave it ("Chrome on Mac"), or `null`. */
67
+ label: string | null;
68
+ locale: string | null;
69
+ app_version: string | null;
70
+ created_at: string;
71
+ last_seen_at: string;
72
+ /** Set when the device no longer receives anything (the push endpoint is
73
+ * gone, or someone switched it off). */
74
+ disabled_at: string | null;
75
+ /** `true` when it was registered from the session this client holds. */
76
+ is_current: boolean;
77
+ }
78
+ /** `PushSubscription.toJSON()` minus the parts the server doesn't need. */
79
+ interface WebPushCredential {
80
+ /** `PushSubscription.endpoint`; must be https. */
81
+ endpoint: string;
82
+ keys: {
83
+ /** URL-safe base64. */
84
+ p256dh: string;
85
+ /** URL-safe base64. */
86
+ auth: string;
87
+ };
88
+ }
89
+ /** FCM registration token or APNs device token. */
90
+ interface MobilePushCredential {
91
+ token: string;
92
+ }
93
+ type RegisterDeviceInput = {
94
+ kind: "webpush";
95
+ platform: DevicePlatform;
96
+ credential: WebPushCredential;
97
+ label?: string;
98
+ locale?: string;
99
+ app_version?: string;
100
+ } | {
101
+ kind: "fcm" | "apns";
102
+ platform: DevicePlatform;
103
+ credential: MobilePushCredential;
104
+ label?: string;
105
+ locale?: string;
106
+ app_version?: string;
107
+ } | {
108
+ kind: "telegram_miniapp";
109
+ platform: DevicePlatform;
110
+ /** Nothing to send: the device is a marker. */
111
+ credential: Record<string, never>;
112
+ label?: string;
113
+ locale?: string;
114
+ app_version?: string;
115
+ };
116
+ interface RegisteredDevice {
117
+ id: string;
118
+ kind: DeviceKind;
119
+ platform: DevicePlatform;
120
+ /** VAPID public key (URL-safe base64) for `pushManager.subscribe`;
121
+ * `null` when push is not set up on this deployment. */
122
+ vapid_public_key: string | null;
123
+ }
124
+ interface RegisterWebPushOptions {
125
+ /** A name to show in the user's device list ("Chrome on Mac"). */
126
+ label?: string;
127
+ /** Skip the key lookup when you already hold the deployment's VAPID
128
+ * public key (from an earlier `register` result, for example). */
129
+ vapidPublicKey?: string;
130
+ }
131
+ interface UnregisterWebPushOptions {
132
+ /** The device to delete, from an earlier `registerWebPush` result. When
133
+ * omitted, every Web Push device registered from this session goes. */
134
+ deviceId?: string;
135
+ }
136
+ /** Client platform → the platform the device list uses. */
137
+ declare function devicePlatformOf(platform: ClientPlatform): DevicePlatform;
138
+ declare class DevicesResource {
139
+ private readonly http;
140
+ private readonly client;
141
+ constructor(http: HttpClient, client: ResolvedClientDescriptor);
142
+ /** Every device the user has, disabled ones included. */
143
+ list(): Promise<Device[]>;
144
+ /** Register a device, or refresh it when the same credential is already
145
+ * known (then `last_seen_at`, `label` and `app_version` update and a
146
+ * disabled device comes back). `app_version` defaults to the client
147
+ * version sent in `X-Takeal-Client`.
148
+ *
149
+ * Errors: 400 `validation`; 409 `push_disabled` for `webpush` when the
150
+ * deployment has no VAPID keys. */
151
+ register(input: RegisterDeviceInput): Promise<RegisteredDevice>;
152
+ /** Delete one device. 404 when it isn't the user's. */
153
+ remove(id: string): Promise<void>;
154
+ /** Subscribe this browser to Web Push and register it as a device. Ask
155
+ * for notification permission before calling. Throws when push isn't
156
+ * set up on the deployment. */
157
+ registerWebPush(registration: PushCapableRegistration, opts?: RegisterWebPushOptions): Promise<RegisteredDevice>;
158
+ /** Unsubscribe this browser from Web Push and delete the matching device
159
+ * (see {@link UnregisterWebPushOptions}). Safe when nothing is
160
+ * registered. */
161
+ unregisterWebPush(registration: PushCapableRegistration, opts?: UnregisterWebPushOptions): Promise<void>;
162
+ private vapidPublicKey;
163
+ }
164
+
165
+ export { type ClientDescriptor as C, DevicesResource as D, type MobilePushCredential as M, type ResolvedClientDescriptor as R, type UnregisterWebPushOptions as U, type WebPushCredential as W, CLIENT_HEADER as a, type ClientPlatform as b, type Device as c, type DeviceKind as d, type DevicePlatform as e, type RegisterDeviceInput as f, type RegisterWebPushOptions as g, type RegisteredDevice as h, detectClientPlatform as i, devicePlatformOf as j };
@@ -36,6 +36,8 @@ declare function inMemoryStore(): TokenStore;
36
36
  * - Set `Content-Type: application/json` on bodies.
37
37
  * - Parse JSON responses + map non-2xx to `ApiError`.
38
38
  * - Forward `Idempotency-Key` when the caller passes one.
39
+ * - Send the constructor's `defaultHeaders` (the `X-Takeal-Client`
40
+ * descriptor) on every request.
39
41
  * - Surface network failures (DNS, abort, broken pipe) as
40
42
  * `NetworkError`.
41
43
  *
@@ -62,7 +64,13 @@ declare class HttpClient {
62
64
  private readonly baseUrl;
63
65
  private readonly tokens;
64
66
  private readonly fetchImpl;
65
- constructor(baseUrl: string, tokens: TokenStore, fetchImpl: FetchLike);
67
+ /** Headers sent on every request, below the per-call `headers`
68
+ * (a caller can still override one). */
69
+ private readonly defaultHeaders;
70
+ constructor(baseUrl: string, tokens: TokenStore, fetchImpl: FetchLike,
71
+ /** Headers sent on every request, below the per-call `headers`
72
+ * (a caller can still override one). */
73
+ defaultHeaders?: Record<string, string>);
66
74
  get<T>(path: string, opts?: HttpOptions): Promise<T>;
67
75
  post<T>(path: string, opts?: HttpOptions): Promise<T>;
68
76
  put<T>(path: string, opts?: HttpOptions): Promise<T>;
@@ -36,6 +36,8 @@ declare function inMemoryStore(): TokenStore;
36
36
  * - Set `Content-Type: application/json` on bodies.
37
37
  * - Parse JSON responses + map non-2xx to `ApiError`.
38
38
  * - Forward `Idempotency-Key` when the caller passes one.
39
+ * - Send the constructor's `defaultHeaders` (the `X-Takeal-Client`
40
+ * descriptor) on every request.
39
41
  * - Surface network failures (DNS, abort, broken pipe) as
40
42
  * `NetworkError`.
41
43
  *
@@ -62,7 +64,13 @@ declare class HttpClient {
62
64
  private readonly baseUrl;
63
65
  private readonly tokens;
64
66
  private readonly fetchImpl;
65
- constructor(baseUrl: string, tokens: TokenStore, fetchImpl: FetchLike);
67
+ /** Headers sent on every request, below the per-call `headers`
68
+ * (a caller can still override one). */
69
+ private readonly defaultHeaders;
70
+ constructor(baseUrl: string, tokens: TokenStore, fetchImpl: FetchLike,
71
+ /** Headers sent on every request, below the per-call `headers`
72
+ * (a caller can still override one). */
73
+ defaultHeaders?: Record<string, string>);
66
74
  get<T>(path: string, opts?: HttpOptions): Promise<T>;
67
75
  post<T>(path: string, opts?: HttpOptions): Promise<T>;
68
76
  put<T>(path: string, opts?: HttpOptions): Promise<T>;