@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.
- package/CHANGELOG.md +100 -0
- package/README.md +367 -5
- package/dist/devices-C3JHi2Hi.d.cts +165 -0
- package/dist/devices-DP_hxwmW.d.ts +165 -0
- package/dist/{http-BkCfOCR0.d.cts → http-B-OQwMYn.d.cts} +9 -1
- package/dist/{http-BkCfOCR0.d.ts → http-B-OQwMYn.d.ts} +9 -1
- package/dist/index.cjs +284 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +65 -9
- package/dist/index.d.ts +65 -9
- package/dist/index.js +280 -21
- 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 +62 -3
- package/dist/react/index.d.ts +62 -3
- package/dist/react/index.js +131 -8
- package/dist/react/index.js.map +1 -1
- package/dist/resources/auth.cjs +36 -11
- package/dist/resources/auth.cjs.map +1 -1
- package/dist/resources/auth.d.cts +57 -5
- package/dist/resources/auth.d.ts +57 -5
- package/dist/resources/auth.js +36 -11
- package/dist/resources/auth.js.map +1 -1
- package/dist/resources/balance.d.cts +1 -1
- package/dist/resources/balance.d.ts +1 -1
- package/dist/resources/blog.d.cts +1 -1
- package/dist/resources/blog.d.ts +1 -1
- package/dist/resources/branding.d.cts +1 -1
- package/dist/resources/branding.d.ts +1 -1
- package/dist/resources/cards.cjs +33 -1
- package/dist/resources/cards.cjs.map +1 -1
- package/dist/resources/cards.d.cts +111 -4
- package/dist/resources/cards.d.ts +111 -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 +57 -0
- package/dist/resources/notifications.cjs.map +1 -0
- package/dist/resources/notifications.d.cts +133 -0
- package/dist/resources/notifications.d.ts +133 -0
- package/dist/resources/notifications.js +54 -0
- package/dist/resources/notifications.js.map +1 -0
- package/dist/resources/push.cjs +8 -4
- package/dist/resources/push.cjs.map +1 -1
- package/dist/resources/push.d.cts +14 -17
- package/dist/resources/push.d.ts +14 -17
- package/dist/resources/push.js +8 -4
- package/dist/resources/push.js.map +1 -1
- package/dist/resources/sessions.d.cts +1 -1
- package/dist/resources/sessions.d.ts +1 -1
- 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.d.cts +1 -1
- package/dist/resources/wallet.d.ts +1 -1
- package/dist/telegram.cjs +321 -23
- package/dist/telegram.cjs.map +1 -1
- package/dist/telegram.d.cts +62 -7
- package/dist/telegram.d.ts +62 -7
- package/dist/telegram.js +320 -24
- package/dist/telegram.js.map +1 -1
- package/package.json +23 -4
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import '../http-B-OQwMYn.cjs';
|
|
2
|
+
export { c as Device, d as DeviceKind, e as DevicePlatform, D as DevicesResource, M as MobilePushCredential, f as RegisterDeviceInput, g as RegisterWebPushOptions, h as RegisteredDevice, U as UnregisterWebPushOptions, W as WebPushCredential, j as devicePlatformOf } from '../devices-C3JHi2Hi.cjs';
|
|
3
|
+
import './push.cjs';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import '../http-B-OQwMYn.js';
|
|
2
|
+
export { c as Device, d as DeviceKind, e as DevicePlatform, D as DevicesResource, M as MobilePushCredential, f as RegisterDeviceInput, g as RegisterWebPushOptions, h as RegisteredDevice, U as UnregisterWebPushOptions, W as WebPushCredential, j as devicePlatformOf } from '../devices-DP_hxwmW.js';
|
|
3
|
+
import './push.js';
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// src/resources/push.ts
|
|
2
|
+
function base64UrlToBytes(input) {
|
|
3
|
+
const b64 = input.replace(/-/g, "+").replace(/_/g, "/");
|
|
4
|
+
const padded = b64 + "=".repeat((4 - b64.length % 4) % 4);
|
|
5
|
+
const bin = atob(padded);
|
|
6
|
+
const out = new Uint8Array(bin.length);
|
|
7
|
+
for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);
|
|
8
|
+
return out;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// src/resources/devices.ts
|
|
12
|
+
function devicePlatformOf(platform) {
|
|
13
|
+
return platform === "telegram-miniapp" ? "telegram" : platform;
|
|
14
|
+
}
|
|
15
|
+
var DevicesResource = class {
|
|
16
|
+
constructor(http, client) {
|
|
17
|
+
this.http = http;
|
|
18
|
+
this.client = client;
|
|
19
|
+
}
|
|
20
|
+
/** Every device the user has, disabled ones included. */
|
|
21
|
+
async list() {
|
|
22
|
+
return this.http.get("/me/devices");
|
|
23
|
+
}
|
|
24
|
+
/** Register a device, or refresh it when the same credential is already
|
|
25
|
+
* known (then `last_seen_at`, `label` and `app_version` update and a
|
|
26
|
+
* disabled device comes back). `app_version` defaults to the client
|
|
27
|
+
* version sent in `X-Takeal-Client`.
|
|
28
|
+
*
|
|
29
|
+
* Errors: 400 `validation`; 409 `push_disabled` for `webpush` when the
|
|
30
|
+
* deployment has no VAPID keys. */
|
|
31
|
+
async register(input) {
|
|
32
|
+
return this.http.put("/me/devices", {
|
|
33
|
+
body: { app_version: this.client.version, ...input }
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/** Delete one device. 404 when it isn't the user's. */
|
|
37
|
+
async remove(id) {
|
|
38
|
+
await this.http.delete(`/me/devices/${encodeURIComponent(id)}`);
|
|
39
|
+
}
|
|
40
|
+
/** Subscribe this browser to Web Push and register it as a device. Ask
|
|
41
|
+
* for notification permission before calling. Throws when push isn't
|
|
42
|
+
* set up on the deployment. */
|
|
43
|
+
async registerWebPush(registration, opts = {}) {
|
|
44
|
+
const key = opts.vapidPublicKey ?? await this.vapidPublicKey();
|
|
45
|
+
if (!key) {
|
|
46
|
+
throw new Error("@takeal/cusfront-sdk: push notifications are not enabled on this deployment");
|
|
47
|
+
}
|
|
48
|
+
const sub = await registration.pushManager.subscribe({
|
|
49
|
+
userVisibleOnly: true,
|
|
50
|
+
applicationServerKey: base64UrlToBytes(key)
|
|
51
|
+
});
|
|
52
|
+
const json = sub.toJSON();
|
|
53
|
+
if (!json.endpoint || !json.keys?.p256dh || !json.keys.auth) {
|
|
54
|
+
throw new Error("@takeal/cusfront-sdk: the browser returned an incomplete push subscription");
|
|
55
|
+
}
|
|
56
|
+
return this.register({
|
|
57
|
+
kind: "webpush",
|
|
58
|
+
platform: devicePlatformOf(this.client.platform),
|
|
59
|
+
credential: {
|
|
60
|
+
endpoint: json.endpoint,
|
|
61
|
+
keys: { p256dh: json.keys.p256dh, auth: json.keys.auth }
|
|
62
|
+
},
|
|
63
|
+
...opts.label ? { label: opts.label } : {}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/** Unsubscribe this browser from Web Push and delete the matching device
|
|
67
|
+
* (see {@link UnregisterWebPushOptions}). Safe when nothing is
|
|
68
|
+
* registered. */
|
|
69
|
+
async unregisterWebPush(registration, opts = {}) {
|
|
70
|
+
const sub = await registration.pushManager.getSubscription();
|
|
71
|
+
if (sub) await sub.unsubscribe();
|
|
72
|
+
if (opts.deviceId) {
|
|
73
|
+
await this.remove(opts.deviceId);
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const mine = (await this.list()).filter((d) => d.kind === "webpush" && d.is_current);
|
|
77
|
+
for (const d of mine) await this.remove(d.id);
|
|
78
|
+
}
|
|
79
|
+
async vapidPublicKey() {
|
|
80
|
+
const { vapid_public_key } = await this.http.get(
|
|
81
|
+
"/me/push-subscription"
|
|
82
|
+
);
|
|
83
|
+
return vapid_public_key ?? null;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export { DevicesResource, devicePlatformOf };
|
|
88
|
+
//# sourceMappingURL=devices.js.map
|
|
89
|
+
//# sourceMappingURL=devices.js.map
|
|
@@ -0,0 +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,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;A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\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"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/resources/me.ts
|
|
4
|
+
var MeResource = class {
|
|
5
|
+
constructor(http) {
|
|
6
|
+
this.http = http;
|
|
7
|
+
}
|
|
8
|
+
/** Attach the Telegram account behind `initData` to the signed-in user.
|
|
9
|
+
* Returns the updated user (`telegram` is set). Repeating the call with
|
|
10
|
+
* the same Telegram is fine.
|
|
11
|
+
*
|
|
12
|
+
* Errors: 401 `invalid_init_data`; 403 `user_disabled` /
|
|
13
|
+
* `second_factor_required`; 409 `telegram_already_linked_other` (the
|
|
14
|
+
* account already has a different Telegram; `unlinkTelegram` first) /
|
|
15
|
+
* `telegram_in_use` (that Telegram belongs to another account); 503
|
|
16
|
+
* `telegram_not_configured`. */
|
|
17
|
+
async linkTelegram(initData) {
|
|
18
|
+
return this.http.post("/me/telegram", { body: { init_data: initData } });
|
|
19
|
+
}
|
|
20
|
+
/** Detach the Telegram account from the signed-in user. Returns the
|
|
21
|
+
* updated user (`telegram` is `null`).
|
|
22
|
+
*
|
|
23
|
+
* Errors: 404 `telegram_not_linked`; 409 `last_credential` when the
|
|
24
|
+
* account has no password, so Telegram is its only way to sign in. */
|
|
25
|
+
async unlinkTelegram() {
|
|
26
|
+
return this.http.delete("/me/telegram");
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
exports.MeResource = MeResource;
|
|
31
|
+
//# sourceMappingURL=me.cjs.map
|
|
32
|
+
//# sourceMappingURL=me.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/resources/me.ts"],"names":[],"mappings":";;;AAkBO,IAAM,aAAN,MAAiB;AAAA,EACtB,YAA6B,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWhD,MAAM,aAAa,QAAA,EAAiC;AAClD,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,IAAA,CAAW,cAAA,EAAgB,EAAE,MAAM,EAAE,SAAA,EAAW,QAAA,EAAS,EAAG,CAAA;AAAA,EAC/E;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,cAAA,GAAgC;AACpC,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,MAAA,CAAa,cAAc,CAAA;AAAA,EAC9C;AACF","file":"me.cjs","sourcesContent":["import type { HttpClient } from \"../http.js\";\nimport type { User } from \"./auth.js\";\n\n/**\n * Me resource — `client.me.*`.\n *\n * Profile-level actions for the signed-in user that don't belong to another\n * resource. Today: the Telegram link.\n *\n * ```ts\n * // Inside a Mini App, with a signed-in client (e.g. opened via a deep link):\n * const me = await client.me.linkTelegram(window.Telegram.WebApp.initData);\n * me.telegram; // { username, linked_at }\n *\n * // From a settings screen:\n * await client.me.unlinkTelegram();\n * ```\n */\nexport class MeResource {\n constructor(private readonly http: HttpClient) {}\n\n /** Attach the Telegram account behind `initData` to the signed-in user.\n * Returns the updated user (`telegram` is set). Repeating the call with\n * the same Telegram is fine.\n *\n * Errors: 401 `invalid_init_data`; 403 `user_disabled` /\n * `second_factor_required`; 409 `telegram_already_linked_other` (the\n * account already has a different Telegram; `unlinkTelegram` first) /\n * `telegram_in_use` (that Telegram belongs to another account); 503\n * `telegram_not_configured`. */\n async linkTelegram(initData: string): Promise<User> {\n return this.http.post<User>(\"/me/telegram\", { body: { init_data: initData } });\n }\n\n /** Detach the Telegram account from the signed-in user. Returns the\n * updated user (`telegram` is `null`).\n *\n * Errors: 404 `telegram_not_linked`; 409 `last_credential` when the\n * account has no password, so Telegram is its only way to sign in. */\n async unlinkTelegram(): Promise<User> {\n return this.http.delete<User>(\"/me/telegram\");\n }\n}\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { H as HttpClient } from '../http-B-OQwMYn.cjs';
|
|
2
|
+
import { User } from './auth.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Me resource — `client.me.*`.
|
|
6
|
+
*
|
|
7
|
+
* Profile-level actions for the signed-in user that don't belong to another
|
|
8
|
+
* resource. Today: the Telegram link.
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* // Inside a Mini App, with a signed-in client (e.g. opened via a deep link):
|
|
12
|
+
* const me = await client.me.linkTelegram(window.Telegram.WebApp.initData);
|
|
13
|
+
* me.telegram; // { username, linked_at }
|
|
14
|
+
*
|
|
15
|
+
* // From a settings screen:
|
|
16
|
+
* await client.me.unlinkTelegram();
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
declare class MeResource {
|
|
20
|
+
private readonly http;
|
|
21
|
+
constructor(http: HttpClient);
|
|
22
|
+
/** Attach the Telegram account behind `initData` to the signed-in user.
|
|
23
|
+
* Returns the updated user (`telegram` is set). Repeating the call with
|
|
24
|
+
* the same Telegram is fine.
|
|
25
|
+
*
|
|
26
|
+
* Errors: 401 `invalid_init_data`; 403 `user_disabled` /
|
|
27
|
+
* `second_factor_required`; 409 `telegram_already_linked_other` (the
|
|
28
|
+
* account already has a different Telegram; `unlinkTelegram` first) /
|
|
29
|
+
* `telegram_in_use` (that Telegram belongs to another account); 503
|
|
30
|
+
* `telegram_not_configured`. */
|
|
31
|
+
linkTelegram(initData: string): Promise<User>;
|
|
32
|
+
/** Detach the Telegram account from the signed-in user. Returns the
|
|
33
|
+
* updated user (`telegram` is `null`).
|
|
34
|
+
*
|
|
35
|
+
* Errors: 404 `telegram_not_linked`; 409 `last_credential` when the
|
|
36
|
+
* account has no password, so Telegram is its only way to sign in. */
|
|
37
|
+
unlinkTelegram(): Promise<User>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { MeResource };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { H as HttpClient } from '../http-B-OQwMYn.js';
|
|
2
|
+
import { User } from './auth.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Me resource — `client.me.*`.
|
|
6
|
+
*
|
|
7
|
+
* Profile-level actions for the signed-in user that don't belong to another
|
|
8
|
+
* resource. Today: the Telegram link.
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* // Inside a Mini App, with a signed-in client (e.g. opened via a deep link):
|
|
12
|
+
* const me = await client.me.linkTelegram(window.Telegram.WebApp.initData);
|
|
13
|
+
* me.telegram; // { username, linked_at }
|
|
14
|
+
*
|
|
15
|
+
* // From a settings screen:
|
|
16
|
+
* await client.me.unlinkTelegram();
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
declare class MeResource {
|
|
20
|
+
private readonly http;
|
|
21
|
+
constructor(http: HttpClient);
|
|
22
|
+
/** Attach the Telegram account behind `initData` to the signed-in user.
|
|
23
|
+
* Returns the updated user (`telegram` is set). Repeating the call with
|
|
24
|
+
* the same Telegram is fine.
|
|
25
|
+
*
|
|
26
|
+
* Errors: 401 `invalid_init_data`; 403 `user_disabled` /
|
|
27
|
+
* `second_factor_required`; 409 `telegram_already_linked_other` (the
|
|
28
|
+
* account already has a different Telegram; `unlinkTelegram` first) /
|
|
29
|
+
* `telegram_in_use` (that Telegram belongs to another account); 503
|
|
30
|
+
* `telegram_not_configured`. */
|
|
31
|
+
linkTelegram(initData: string): Promise<User>;
|
|
32
|
+
/** Detach the Telegram account from the signed-in user. Returns the
|
|
33
|
+
* updated user (`telegram` is `null`).
|
|
34
|
+
*
|
|
35
|
+
* Errors: 404 `telegram_not_linked`; 409 `last_credential` when the
|
|
36
|
+
* account has no password, so Telegram is its only way to sign in. */
|
|
37
|
+
unlinkTelegram(): Promise<User>;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { MeResource };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// src/resources/me.ts
|
|
2
|
+
var MeResource = class {
|
|
3
|
+
constructor(http) {
|
|
4
|
+
this.http = http;
|
|
5
|
+
}
|
|
6
|
+
/** Attach the Telegram account behind `initData` to the signed-in user.
|
|
7
|
+
* Returns the updated user (`telegram` is set). Repeating the call with
|
|
8
|
+
* the same Telegram is fine.
|
|
9
|
+
*
|
|
10
|
+
* Errors: 401 `invalid_init_data`; 403 `user_disabled` /
|
|
11
|
+
* `second_factor_required`; 409 `telegram_already_linked_other` (the
|
|
12
|
+
* account already has a different Telegram; `unlinkTelegram` first) /
|
|
13
|
+
* `telegram_in_use` (that Telegram belongs to another account); 503
|
|
14
|
+
* `telegram_not_configured`. */
|
|
15
|
+
async linkTelegram(initData) {
|
|
16
|
+
return this.http.post("/me/telegram", { body: { init_data: initData } });
|
|
17
|
+
}
|
|
18
|
+
/** Detach the Telegram account from the signed-in user. Returns the
|
|
19
|
+
* updated user (`telegram` is `null`).
|
|
20
|
+
*
|
|
21
|
+
* Errors: 404 `telegram_not_linked`; 409 `last_credential` when the
|
|
22
|
+
* account has no password, so Telegram is its only way to sign in. */
|
|
23
|
+
async unlinkTelegram() {
|
|
24
|
+
return this.http.delete("/me/telegram");
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export { MeResource };
|
|
29
|
+
//# sourceMappingURL=me.js.map
|
|
30
|
+
//# sourceMappingURL=me.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/resources/me.ts"],"names":[],"mappings":";AAkBO,IAAM,aAAN,MAAiB;AAAA,EACtB,YAA6B,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAmB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAWhD,MAAM,aAAa,QAAA,EAAiC;AAClD,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,IAAA,CAAW,cAAA,EAAgB,EAAE,MAAM,EAAE,SAAA,EAAW,QAAA,EAAS,EAAG,CAAA;AAAA,EAC/E;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,cAAA,GAAgC;AACpC,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,MAAA,CAAa,cAAc,CAAA;AAAA,EAC9C;AACF","file":"me.js","sourcesContent":["import type { HttpClient } from \"../http.js\";\nimport type { User } from \"./auth.js\";\n\n/**\n * Me resource — `client.me.*`.\n *\n * Profile-level actions for the signed-in user that don't belong to another\n * resource. Today: the Telegram link.\n *\n * ```ts\n * // Inside a Mini App, with a signed-in client (e.g. opened via a deep link):\n * const me = await client.me.linkTelegram(window.Telegram.WebApp.initData);\n * me.telegram; // { username, linked_at }\n *\n * // From a settings screen:\n * await client.me.unlinkTelegram();\n * ```\n */\nexport class MeResource {\n constructor(private readonly http: HttpClient) {}\n\n /** Attach the Telegram account behind `initData` to the signed-in user.\n * Returns the updated user (`telegram` is set). Repeating the call with\n * the same Telegram is fine.\n *\n * Errors: 401 `invalid_init_data`; 403 `user_disabled` /\n * `second_factor_required`; 409 `telegram_already_linked_other` (the\n * account already has a different Telegram; `unlinkTelegram` first) /\n * `telegram_in_use` (that Telegram belongs to another account); 503\n * `telegram_not_configured`. */\n async linkTelegram(initData: string): Promise<User> {\n return this.http.post<User>(\"/me/telegram\", { body: { init_data: initData } });\n }\n\n /** Detach the Telegram account from the signed-in user. Returns the\n * updated user (`telegram` is `null`).\n *\n * Errors: 404 `telegram_not_linked`; 409 `last_credential` when the\n * account has no password, so Telegram is its only way to sign in. */\n async unlinkTelegram(): Promise<User> {\n return this.http.delete<User>(\"/me/telegram\");\n }\n}\n"]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/resources/notifications.ts
|
|
4
|
+
function isCardOtp(item) {
|
|
5
|
+
return item.event_type === "card_otp" && typeof item.data?.otp === "string";
|
|
6
|
+
}
|
|
7
|
+
var NotificationsResource = class {
|
|
8
|
+
constructor(http) {
|
|
9
|
+
this.http = http;
|
|
10
|
+
}
|
|
11
|
+
/** One page of the inbox, newest first. */
|
|
12
|
+
async list(params = {}) {
|
|
13
|
+
const q = new URLSearchParams();
|
|
14
|
+
if (params.cursor) q.set("cursor", params.cursor);
|
|
15
|
+
if (params.limit !== void 0) q.set("limit", String(params.limit));
|
|
16
|
+
if (params.unreadOnly) q.set("unread", "true");
|
|
17
|
+
if (params.category) q.set("category", params.category);
|
|
18
|
+
const qs = q.toString();
|
|
19
|
+
return this.http.get(`/me/notifications${qs ? `?${qs}` : ""}`);
|
|
20
|
+
}
|
|
21
|
+
/** How many items are unread. Cheap; fine to poll for a badge. */
|
|
22
|
+
async unreadCount() {
|
|
23
|
+
const { unread } = await this.http.get("/me/notifications/unread-count");
|
|
24
|
+
return unread;
|
|
25
|
+
}
|
|
26
|
+
/** Mark one item read. Returns the item; calling it again is harmless. */
|
|
27
|
+
async markRead(id) {
|
|
28
|
+
return this.http.post(`/me/notifications/${encodeURIComponent(id)}/read`);
|
|
29
|
+
}
|
|
30
|
+
/** Mark every unread item read, or only those created before `before`
|
|
31
|
+
* (ISO timestamp). Returns how many changed. */
|
|
32
|
+
async markAllRead(before) {
|
|
33
|
+
return this.http.post("/me/notifications/read-all", {
|
|
34
|
+
body: before ? { before } : {}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/** Delete one item. 404 when it isn't the user's. */
|
|
38
|
+
async remove(id) {
|
|
39
|
+
await this.http.delete(`/me/notifications/${encodeURIComponent(id)}`);
|
|
40
|
+
}
|
|
41
|
+
/** The user's channel and language settings. */
|
|
42
|
+
async getPreferences() {
|
|
43
|
+
return this.http.get("/me/notification-preferences");
|
|
44
|
+
}
|
|
45
|
+
/** Change some settings; the rest stay. Returns the stored view.
|
|
46
|
+
* 400 `validation` for an unknown category, channel or locale. */
|
|
47
|
+
async setPreferences(input) {
|
|
48
|
+
return this.http.put("/me/notification-preferences", {
|
|
49
|
+
body: input
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
exports.NotificationsResource = NotificationsResource;
|
|
55
|
+
exports.isCardOtp = isCardOtp;
|
|
56
|
+
//# sourceMappingURL=notifications.cjs.map
|
|
57
|
+
//# sourceMappingURL=notifications.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/resources/notifications.ts"],"names":[],"mappings":";;;AAmDO,SAAS,UACd,IAAA,EACmE;AACnE,EAAA,OAAO,KAAK,UAAA,KAAe,UAAA,IAAc,OAAO,IAAA,CAAK,MAAM,GAAA,KAAQ,QAAA;AACrE;AAqEO,IAAM,wBAAN,MAA4B;AAAA,EACjC,YAA6B,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAmB;AAAA;AAAA,EAGhD,MAAM,IAAA,CAAK,MAAA,GAAkC,EAAC,EAA8B;AAC1E,IAAA,MAAM,CAAA,GAAI,IAAI,eAAA,EAAgB;AAC9B,IAAA,IAAI,OAAO,MAAA,EAAQ,CAAA,CAAE,GAAA,CAAI,QAAA,EAAU,OAAO,MAAM,CAAA;AAChD,IAAA,IAAI,MAAA,CAAO,UAAU,MAAA,EAAW,CAAA,CAAE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8B,CAAA;AAAA,EAC9E;AAAA;AAAA;AAAA,EAIA,MAAM,eAAe,KAAA,EAAuE;AAC1F,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,GAAA,CAA6B,8BAAA,EAAgC;AAAA,MAC5E,IAAA,EAAM;AAAA,KACP,CAAA;AAAA,EACH;AACF","file":"notifications.cjs","sourcesContent":["import type { HttpClient } from \"../http.js\";\n\n/**\n * Notifications resource — `client.notifications.*`.\n *\n * Every notification a user gets is also kept server-side as an inbox item,\n * whatever else was sent (a push, a Telegram message, an email). The inbox\n * is what the app shows; the other channels are the nudge to open it.\n *\n * ```ts\n * const page = await client.notifications.list({ limit: 20 });\n * for (const item of page.items) {\n * render(item.title, item.body, item.href); // href: a path inside your app, or null\n * }\n * await client.notifications.markRead(page.items[0].id);\n * ```\n *\n * Preferences decide where the nudge goes: a primary channel (or automatic\n * when `null`), per-category switches, and the user's language.\n */\n\n/** What an item is about. `security` and `money` can't be switched off\n * completely; `marketing` is off until the user opts in. */\nexport type NotificationCategory = \"money\" | \"card\" | \"security\" | \"account\" | \"marketing\";\n\n/** A way to reach the user outside the inbox. */\nexport type NotificationChannel = \"push\" | \"telegram\" | \"email\" | \"sms\";\n\n/** Language the user reads notifications in. */\nexport type NotificationLocale = \"en\" | \"ru\" | (string & {});\n\n/**\n * `data` of a `card_otp` item: a confirmation code the card issuer sent for a\n * 3-D Secure payment (`purpose: \"payment\"`) or for adding the card to Apple\n * Pay / Google Pay (`purpose: \"wallet\"`). The code is what the user needs\n * right now, so show it prominently with a copy button and a countdown from\n * `expires_in_minutes`; `merchant_name`, `amount` and `currency` are absent\n * for wallet codes. Narrow with `isCardOtp(item)`.\n */\nexport interface CardOtpData {\n otp: string;\n purpose: \"payment\" | \"wallet\";\n merchant_name?: string;\n amount?: string;\n currency?: string;\n last4?: string;\n card_id?: string;\n expires_in_minutes?: number;\n}\n\n/** True when the item carries a card confirmation code (`CardOtpData`). */\nexport function isCardOtp(\n item: InboxItem,\n): item is InboxItem & { event_type: \"card_otp\"; data: CardOtpData } {\n return item.event_type === \"card_otp\" && typeof item.data?.otp === \"string\";\n}\n\nexport interface InboxItem {\n id: string;\n /** What happened, e.g. `deposit_confirmed`, `card_transaction`,\n * `login_new_device`, `card_otp` (see `CardOtpData`). */\n event_type: string;\n category: NotificationCategory;\n title: string;\n body: string;\n /** A path inside the client app to open on tap (`/cards/<id>`,\n * `/deposits/<id>`, `/subscription`, `/settings/sessions`), or `null`. */\n href: string | null;\n /** Event details (amount, currency, card last four and so on); the keys\n * depend on `event_type`. */\n data: Record<string, unknown>;\n /** Language the item was rendered in. */\n locale: string;\n /** When the user read it, or `null` while unread. */\n read_at: string | null;\n created_at: string;\n}\n\nexport interface NotificationPage {\n /** Newest first. */\n items: InboxItem[];\n /** Pass back as `cursor` to get the next page; `null` on the last one. */\n next_cursor: string | null;\n /** Unread items across the whole inbox, not just this page. */\n unread_count: number;\n}\n\nexport interface ListNotificationsParams {\n /** `next_cursor` from the previous page. */\n cursor?: string;\n /** Page size; the server caps it. */\n limit?: number;\n /** Only items without `read_at`. */\n unreadOnly?: boolean;\n category?: NotificationCategory;\n}\n\n/** Per-category channel switches: `{ money: { push: true, email: false } }`.\n * A channel missing from a category keeps its default. */\nexport type NotificationCategoryPreferences = Partial<\n Record<NotificationCategory, Partial<Record<NotificationChannel, boolean>>>\n>;\n\nexport interface NotificationPreferences {\n /** The channel to use first; `null` means automatic (the server picks by\n * the user's devices). */\n primary_channel: NotificationChannel | null;\n categories: NotificationCategoryPreferences;\n /** `null` when unset: the server falls back to the Telegram profile's\n * language, then the deployment default. */\n locale: NotificationLocale | null;\n /** Channels this deployment can deliver on. Render toggles only for\n * these. */\n available_channels: NotificationChannel[];\n}\n\n/** Body of `setPreferences`. Every field is optional; only the given ones\n * change. `primary_channel: null` switches back to automatic. */\nexport interface NotificationPreferencesInput {\n primary_channel?: NotificationChannel | null;\n categories?: NotificationCategoryPreferences;\n locale?: NotificationLocale | null;\n}\n\nexport class NotificationsResource {\n constructor(private readonly http: HttpClient) {}\n\n /** One page of the inbox, newest first. */\n async list(params: ListNotificationsParams = {}): Promise<NotificationPage> {\n const q = new URLSearchParams();\n if (params.cursor) q.set(\"cursor\", params.cursor);\n if (params.limit !== undefined) q.set(\"limit\", String(params.limit));\n if (params.unreadOnly) q.set(\"unread\", \"true\");\n if (params.category) q.set(\"category\", params.category);\n const qs = q.toString();\n return this.http.get<NotificationPage>(`/me/notifications${qs ? `?${qs}` : \"\"}`);\n }\n\n /** How many items are unread. Cheap; fine to poll for a badge. */\n async unreadCount(): Promise<number> {\n const { unread } = await this.http.get<{ unread: number }>(\"/me/notifications/unread-count\");\n return unread;\n }\n\n /** Mark one item read. Returns the item; calling it again is harmless. */\n async markRead(id: string): Promise<InboxItem> {\n return this.http.post<InboxItem>(`/me/notifications/${encodeURIComponent(id)}/read`);\n }\n\n /** Mark every unread item read, or only those created before `before`\n * (ISO timestamp). Returns how many changed. */\n async markAllRead(before?: string): Promise<{ marked: number }> {\n return this.http.post<{ marked: number }>(\"/me/notifications/read-all\", {\n body: before ? { before } : {},\n });\n }\n\n /** Delete one item. 404 when it isn't the user's. */\n async remove(id: string): Promise<void> {\n await this.http.delete<void>(`/me/notifications/${encodeURIComponent(id)}`);\n }\n\n /** The user's channel and language settings. */\n async getPreferences(): Promise<NotificationPreferences> {\n return this.http.get<NotificationPreferences>(\"/me/notification-preferences\");\n }\n\n /** Change some settings; the rest stay. Returns the stored view.\n * 400 `validation` for an unknown category, channel or locale. */\n async setPreferences(input: NotificationPreferencesInput): Promise<NotificationPreferences> {\n return this.http.put<NotificationPreferences>(\"/me/notification-preferences\", {\n body: input,\n });\n }\n}\n"]}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { H as HttpClient } from '../http-B-OQwMYn.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Notifications resource — `client.notifications.*`.
|
|
5
|
+
*
|
|
6
|
+
* Every notification a user gets is also kept server-side as an inbox item,
|
|
7
|
+
* whatever else was sent (a push, a Telegram message, an email). The inbox
|
|
8
|
+
* is what the app shows; the other channels are the nudge to open it.
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* const page = await client.notifications.list({ limit: 20 });
|
|
12
|
+
* for (const item of page.items) {
|
|
13
|
+
* render(item.title, item.body, item.href); // href: a path inside your app, or null
|
|
14
|
+
* }
|
|
15
|
+
* await client.notifications.markRead(page.items[0].id);
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* Preferences decide where the nudge goes: a primary channel (or automatic
|
|
19
|
+
* when `null`), per-category switches, and the user's language.
|
|
20
|
+
*/
|
|
21
|
+
/** What an item is about. `security` and `money` can't be switched off
|
|
22
|
+
* completely; `marketing` is off until the user opts in. */
|
|
23
|
+
type NotificationCategory = "money" | "card" | "security" | "account" | "marketing";
|
|
24
|
+
/** A way to reach the user outside the inbox. */
|
|
25
|
+
type NotificationChannel = "push" | "telegram" | "email" | "sms";
|
|
26
|
+
/** Language the user reads notifications in. */
|
|
27
|
+
type NotificationLocale = "en" | "ru" | (string & {});
|
|
28
|
+
/**
|
|
29
|
+
* `data` of a `card_otp` item: a confirmation code the card issuer sent for a
|
|
30
|
+
* 3-D Secure payment (`purpose: "payment"`) or for adding the card to Apple
|
|
31
|
+
* Pay / Google Pay (`purpose: "wallet"`). The code is what the user needs
|
|
32
|
+
* right now, so show it prominently with a copy button and a countdown from
|
|
33
|
+
* `expires_in_minutes`; `merchant_name`, `amount` and `currency` are absent
|
|
34
|
+
* for wallet codes. Narrow with `isCardOtp(item)`.
|
|
35
|
+
*/
|
|
36
|
+
interface CardOtpData {
|
|
37
|
+
otp: string;
|
|
38
|
+
purpose: "payment" | "wallet";
|
|
39
|
+
merchant_name?: string;
|
|
40
|
+
amount?: string;
|
|
41
|
+
currency?: string;
|
|
42
|
+
last4?: string;
|
|
43
|
+
card_id?: string;
|
|
44
|
+
expires_in_minutes?: number;
|
|
45
|
+
}
|
|
46
|
+
/** True when the item carries a card confirmation code (`CardOtpData`). */
|
|
47
|
+
declare function isCardOtp(item: InboxItem): item is InboxItem & {
|
|
48
|
+
event_type: "card_otp";
|
|
49
|
+
data: CardOtpData;
|
|
50
|
+
};
|
|
51
|
+
interface InboxItem {
|
|
52
|
+
id: string;
|
|
53
|
+
/** What happened, e.g. `deposit_confirmed`, `card_transaction`,
|
|
54
|
+
* `login_new_device`, `card_otp` (see `CardOtpData`). */
|
|
55
|
+
event_type: string;
|
|
56
|
+
category: NotificationCategory;
|
|
57
|
+
title: string;
|
|
58
|
+
body: string;
|
|
59
|
+
/** A path inside the client app to open on tap (`/cards/<id>`,
|
|
60
|
+
* `/deposits/<id>`, `/subscription`, `/settings/sessions`), or `null`. */
|
|
61
|
+
href: string | null;
|
|
62
|
+
/** Event details (amount, currency, card last four and so on); the keys
|
|
63
|
+
* depend on `event_type`. */
|
|
64
|
+
data: Record<string, unknown>;
|
|
65
|
+
/** Language the item was rendered in. */
|
|
66
|
+
locale: string;
|
|
67
|
+
/** When the user read it, or `null` while unread. */
|
|
68
|
+
read_at: string | null;
|
|
69
|
+
created_at: string;
|
|
70
|
+
}
|
|
71
|
+
interface NotificationPage {
|
|
72
|
+
/** Newest first. */
|
|
73
|
+
items: InboxItem[];
|
|
74
|
+
/** Pass back as `cursor` to get the next page; `null` on the last one. */
|
|
75
|
+
next_cursor: string | null;
|
|
76
|
+
/** Unread items across the whole inbox, not just this page. */
|
|
77
|
+
unread_count: number;
|
|
78
|
+
}
|
|
79
|
+
interface ListNotificationsParams {
|
|
80
|
+
/** `next_cursor` from the previous page. */
|
|
81
|
+
cursor?: string;
|
|
82
|
+
/** Page size; the server caps it. */
|
|
83
|
+
limit?: number;
|
|
84
|
+
/** Only items without `read_at`. */
|
|
85
|
+
unreadOnly?: boolean;
|
|
86
|
+
category?: NotificationCategory;
|
|
87
|
+
}
|
|
88
|
+
/** Per-category channel switches: `{ money: { push: true, email: false } }`.
|
|
89
|
+
* A channel missing from a category keeps its default. */
|
|
90
|
+
type NotificationCategoryPreferences = Partial<Record<NotificationCategory, Partial<Record<NotificationChannel, boolean>>>>;
|
|
91
|
+
interface NotificationPreferences {
|
|
92
|
+
/** The channel to use first; `null` means automatic (the server picks by
|
|
93
|
+
* the user's devices). */
|
|
94
|
+
primary_channel: NotificationChannel | null;
|
|
95
|
+
categories: NotificationCategoryPreferences;
|
|
96
|
+
/** `null` when unset: the server falls back to the Telegram profile's
|
|
97
|
+
* language, then the deployment default. */
|
|
98
|
+
locale: NotificationLocale | null;
|
|
99
|
+
/** Channels this deployment can deliver on. Render toggles only for
|
|
100
|
+
* these. */
|
|
101
|
+
available_channels: NotificationChannel[];
|
|
102
|
+
}
|
|
103
|
+
/** Body of `setPreferences`. Every field is optional; only the given ones
|
|
104
|
+
* change. `primary_channel: null` switches back to automatic. */
|
|
105
|
+
interface NotificationPreferencesInput {
|
|
106
|
+
primary_channel?: NotificationChannel | null;
|
|
107
|
+
categories?: NotificationCategoryPreferences;
|
|
108
|
+
locale?: NotificationLocale | null;
|
|
109
|
+
}
|
|
110
|
+
declare class NotificationsResource {
|
|
111
|
+
private readonly http;
|
|
112
|
+
constructor(http: HttpClient);
|
|
113
|
+
/** One page of the inbox, newest first. */
|
|
114
|
+
list(params?: ListNotificationsParams): Promise<NotificationPage>;
|
|
115
|
+
/** How many items are unread. Cheap; fine to poll for a badge. */
|
|
116
|
+
unreadCount(): Promise<number>;
|
|
117
|
+
/** Mark one item read. Returns the item; calling it again is harmless. */
|
|
118
|
+
markRead(id: string): Promise<InboxItem>;
|
|
119
|
+
/** Mark every unread item read, or only those created before `before`
|
|
120
|
+
* (ISO timestamp). Returns how many changed. */
|
|
121
|
+
markAllRead(before?: string): Promise<{
|
|
122
|
+
marked: number;
|
|
123
|
+
}>;
|
|
124
|
+
/** Delete one item. 404 when it isn't the user's. */
|
|
125
|
+
remove(id: string): Promise<void>;
|
|
126
|
+
/** The user's channel and language settings. */
|
|
127
|
+
getPreferences(): Promise<NotificationPreferences>;
|
|
128
|
+
/** Change some settings; the rest stay. Returns the stored view.
|
|
129
|
+
* 400 `validation` for an unknown category, channel or locale. */
|
|
130
|
+
setPreferences(input: NotificationPreferencesInput): Promise<NotificationPreferences>;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export { type CardOtpData, type InboxItem, type ListNotificationsParams, type NotificationCategory, type NotificationCategoryPreferences, type NotificationChannel, type NotificationLocale, type NotificationPage, type NotificationPreferences, type NotificationPreferencesInput, NotificationsResource, isCardOtp };
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { H as HttpClient } from '../http-B-OQwMYn.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Notifications resource — `client.notifications.*`.
|
|
5
|
+
*
|
|
6
|
+
* Every notification a user gets is also kept server-side as an inbox item,
|
|
7
|
+
* whatever else was sent (a push, a Telegram message, an email). The inbox
|
|
8
|
+
* is what the app shows; the other channels are the nudge to open it.
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* const page = await client.notifications.list({ limit: 20 });
|
|
12
|
+
* for (const item of page.items) {
|
|
13
|
+
* render(item.title, item.body, item.href); // href: a path inside your app, or null
|
|
14
|
+
* }
|
|
15
|
+
* await client.notifications.markRead(page.items[0].id);
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* Preferences decide where the nudge goes: a primary channel (or automatic
|
|
19
|
+
* when `null`), per-category switches, and the user's language.
|
|
20
|
+
*/
|
|
21
|
+
/** What an item is about. `security` and `money` can't be switched off
|
|
22
|
+
* completely; `marketing` is off until the user opts in. */
|
|
23
|
+
type NotificationCategory = "money" | "card" | "security" | "account" | "marketing";
|
|
24
|
+
/** A way to reach the user outside the inbox. */
|
|
25
|
+
type NotificationChannel = "push" | "telegram" | "email" | "sms";
|
|
26
|
+
/** Language the user reads notifications in. */
|
|
27
|
+
type NotificationLocale = "en" | "ru" | (string & {});
|
|
28
|
+
/**
|
|
29
|
+
* `data` of a `card_otp` item: a confirmation code the card issuer sent for a
|
|
30
|
+
* 3-D Secure payment (`purpose: "payment"`) or for adding the card to Apple
|
|
31
|
+
* Pay / Google Pay (`purpose: "wallet"`). The code is what the user needs
|
|
32
|
+
* right now, so show it prominently with a copy button and a countdown from
|
|
33
|
+
* `expires_in_minutes`; `merchant_name`, `amount` and `currency` are absent
|
|
34
|
+
* for wallet codes. Narrow with `isCardOtp(item)`.
|
|
35
|
+
*/
|
|
36
|
+
interface CardOtpData {
|
|
37
|
+
otp: string;
|
|
38
|
+
purpose: "payment" | "wallet";
|
|
39
|
+
merchant_name?: string;
|
|
40
|
+
amount?: string;
|
|
41
|
+
currency?: string;
|
|
42
|
+
last4?: string;
|
|
43
|
+
card_id?: string;
|
|
44
|
+
expires_in_minutes?: number;
|
|
45
|
+
}
|
|
46
|
+
/** True when the item carries a card confirmation code (`CardOtpData`). */
|
|
47
|
+
declare function isCardOtp(item: InboxItem): item is InboxItem & {
|
|
48
|
+
event_type: "card_otp";
|
|
49
|
+
data: CardOtpData;
|
|
50
|
+
};
|
|
51
|
+
interface InboxItem {
|
|
52
|
+
id: string;
|
|
53
|
+
/** What happened, e.g. `deposit_confirmed`, `card_transaction`,
|
|
54
|
+
* `login_new_device`, `card_otp` (see `CardOtpData`). */
|
|
55
|
+
event_type: string;
|
|
56
|
+
category: NotificationCategory;
|
|
57
|
+
title: string;
|
|
58
|
+
body: string;
|
|
59
|
+
/** A path inside the client app to open on tap (`/cards/<id>`,
|
|
60
|
+
* `/deposits/<id>`, `/subscription`, `/settings/sessions`), or `null`. */
|
|
61
|
+
href: string | null;
|
|
62
|
+
/** Event details (amount, currency, card last four and so on); the keys
|
|
63
|
+
* depend on `event_type`. */
|
|
64
|
+
data: Record<string, unknown>;
|
|
65
|
+
/** Language the item was rendered in. */
|
|
66
|
+
locale: string;
|
|
67
|
+
/** When the user read it, or `null` while unread. */
|
|
68
|
+
read_at: string | null;
|
|
69
|
+
created_at: string;
|
|
70
|
+
}
|
|
71
|
+
interface NotificationPage {
|
|
72
|
+
/** Newest first. */
|
|
73
|
+
items: InboxItem[];
|
|
74
|
+
/** Pass back as `cursor` to get the next page; `null` on the last one. */
|
|
75
|
+
next_cursor: string | null;
|
|
76
|
+
/** Unread items across the whole inbox, not just this page. */
|
|
77
|
+
unread_count: number;
|
|
78
|
+
}
|
|
79
|
+
interface ListNotificationsParams {
|
|
80
|
+
/** `next_cursor` from the previous page. */
|
|
81
|
+
cursor?: string;
|
|
82
|
+
/** Page size; the server caps it. */
|
|
83
|
+
limit?: number;
|
|
84
|
+
/** Only items without `read_at`. */
|
|
85
|
+
unreadOnly?: boolean;
|
|
86
|
+
category?: NotificationCategory;
|
|
87
|
+
}
|
|
88
|
+
/** Per-category channel switches: `{ money: { push: true, email: false } }`.
|
|
89
|
+
* A channel missing from a category keeps its default. */
|
|
90
|
+
type NotificationCategoryPreferences = Partial<Record<NotificationCategory, Partial<Record<NotificationChannel, boolean>>>>;
|
|
91
|
+
interface NotificationPreferences {
|
|
92
|
+
/** The channel to use first; `null` means automatic (the server picks by
|
|
93
|
+
* the user's devices). */
|
|
94
|
+
primary_channel: NotificationChannel | null;
|
|
95
|
+
categories: NotificationCategoryPreferences;
|
|
96
|
+
/** `null` when unset: the server falls back to the Telegram profile's
|
|
97
|
+
* language, then the deployment default. */
|
|
98
|
+
locale: NotificationLocale | null;
|
|
99
|
+
/** Channels this deployment can deliver on. Render toggles only for
|
|
100
|
+
* these. */
|
|
101
|
+
available_channels: NotificationChannel[];
|
|
102
|
+
}
|
|
103
|
+
/** Body of `setPreferences`. Every field is optional; only the given ones
|
|
104
|
+
* change. `primary_channel: null` switches back to automatic. */
|
|
105
|
+
interface NotificationPreferencesInput {
|
|
106
|
+
primary_channel?: NotificationChannel | null;
|
|
107
|
+
categories?: NotificationCategoryPreferences;
|
|
108
|
+
locale?: NotificationLocale | null;
|
|
109
|
+
}
|
|
110
|
+
declare class NotificationsResource {
|
|
111
|
+
private readonly http;
|
|
112
|
+
constructor(http: HttpClient);
|
|
113
|
+
/** One page of the inbox, newest first. */
|
|
114
|
+
list(params?: ListNotificationsParams): Promise<NotificationPage>;
|
|
115
|
+
/** How many items are unread. Cheap; fine to poll for a badge. */
|
|
116
|
+
unreadCount(): Promise<number>;
|
|
117
|
+
/** Mark one item read. Returns the item; calling it again is harmless. */
|
|
118
|
+
markRead(id: string): Promise<InboxItem>;
|
|
119
|
+
/** Mark every unread item read, or only those created before `before`
|
|
120
|
+
* (ISO timestamp). Returns how many changed. */
|
|
121
|
+
markAllRead(before?: string): Promise<{
|
|
122
|
+
marked: number;
|
|
123
|
+
}>;
|
|
124
|
+
/** Delete one item. 404 when it isn't the user's. */
|
|
125
|
+
remove(id: string): Promise<void>;
|
|
126
|
+
/** The user's channel and language settings. */
|
|
127
|
+
getPreferences(): Promise<NotificationPreferences>;
|
|
128
|
+
/** Change some settings; the rest stay. Returns the stored view.
|
|
129
|
+
* 400 `validation` for an unknown category, channel or locale. */
|
|
130
|
+
setPreferences(input: NotificationPreferencesInput): Promise<NotificationPreferences>;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export { type CardOtpData, type InboxItem, type ListNotificationsParams, type NotificationCategory, type NotificationCategoryPreferences, type NotificationChannel, type NotificationLocale, type NotificationPage, type NotificationPreferences, type NotificationPreferencesInput, NotificationsResource, isCardOtp };
|