@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
@@ -0,0 +1,109 @@
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
+ interface InboxItem {
29
+ id: string;
30
+ /** What happened, e.g. `deposit_confirmed`, `card_transaction`, `login_new_device`. */
31
+ event_type: string;
32
+ category: NotificationCategory;
33
+ title: string;
34
+ body: string;
35
+ /** A path inside the client app to open on tap (`/cards/<id>`,
36
+ * `/deposits/<id>`, `/subscription`, `/settings/sessions`), or `null`. */
37
+ href: string | null;
38
+ /** Event details (amount, currency, card last four and so on); the keys
39
+ * depend on `event_type`. */
40
+ data: Record<string, unknown>;
41
+ /** Language the item was rendered in. */
42
+ locale: string;
43
+ /** When the user read it, or `null` while unread. */
44
+ read_at: string | null;
45
+ created_at: string;
46
+ }
47
+ interface NotificationPage {
48
+ /** Newest first. */
49
+ items: InboxItem[];
50
+ /** Pass back as `cursor` to get the next page; `null` on the last one. */
51
+ next_cursor: string | null;
52
+ /** Unread items across the whole inbox, not just this page. */
53
+ unread_count: number;
54
+ }
55
+ interface ListNotificationsParams {
56
+ /** `next_cursor` from the previous page. */
57
+ cursor?: string;
58
+ /** Page size; the server caps it. */
59
+ limit?: number;
60
+ /** Only items without `read_at`. */
61
+ unreadOnly?: boolean;
62
+ category?: NotificationCategory;
63
+ }
64
+ /** Per-category channel switches: `{ money: { push: true, email: false } }`.
65
+ * A channel missing from a category keeps its default. */
66
+ type NotificationCategoryPreferences = Partial<Record<NotificationCategory, Partial<Record<NotificationChannel, boolean>>>>;
67
+ interface NotificationPreferences {
68
+ /** The channel to use first; `null` means automatic (the server picks by
69
+ * the user's devices). */
70
+ primary_channel: NotificationChannel | null;
71
+ categories: NotificationCategoryPreferences;
72
+ /** `null` when unset: the server falls back to the Telegram profile's
73
+ * language, then the deployment default. */
74
+ locale: NotificationLocale | null;
75
+ /** Channels this deployment can deliver on. Render toggles only for
76
+ * these. */
77
+ available_channels: NotificationChannel[];
78
+ }
79
+ /** Body of `setPreferences`. Every field is optional; only the given ones
80
+ * change. `primary_channel: null` switches back to automatic. */
81
+ interface NotificationPreferencesInput {
82
+ primary_channel?: NotificationChannel | null;
83
+ categories?: NotificationCategoryPreferences;
84
+ locale?: NotificationLocale | null;
85
+ }
86
+ declare class NotificationsResource {
87
+ private readonly http;
88
+ constructor(http: HttpClient);
89
+ /** One page of the inbox, newest first. */
90
+ list(params?: ListNotificationsParams): Promise<NotificationPage>;
91
+ /** How many items are unread. Cheap; fine to poll for a badge. */
92
+ unreadCount(): Promise<number>;
93
+ /** Mark one item read. Returns the item; calling it again is harmless. */
94
+ markRead(id: string): Promise<InboxItem>;
95
+ /** Mark every unread item read, or only those created before `before`
96
+ * (ISO timestamp). Returns how many changed. */
97
+ markAllRead(before?: string): Promise<{
98
+ marked: number;
99
+ }>;
100
+ /** Delete one item. 404 when it isn't the user's. */
101
+ remove(id: string): Promise<void>;
102
+ /** The user's channel and language settings. */
103
+ getPreferences(): Promise<NotificationPreferences>;
104
+ /** Change some settings; the rest stay. Returns the stored view.
105
+ * 400 `validation` for an unknown category, channel or locale. */
106
+ setPreferences(input: NotificationPreferencesInput): Promise<NotificationPreferences>;
107
+ }
108
+
109
+ export { type InboxItem, type ListNotificationsParams, type NotificationCategory, type NotificationCategoryPreferences, type NotificationChannel, type NotificationLocale, type NotificationPage, type NotificationPreferences, type NotificationPreferencesInput, NotificationsResource };
@@ -0,0 +1,109 @@
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
+ interface InboxItem {
29
+ id: string;
30
+ /** What happened, e.g. `deposit_confirmed`, `card_transaction`, `login_new_device`. */
31
+ event_type: string;
32
+ category: NotificationCategory;
33
+ title: string;
34
+ body: string;
35
+ /** A path inside the client app to open on tap (`/cards/<id>`,
36
+ * `/deposits/<id>`, `/subscription`, `/settings/sessions`), or `null`. */
37
+ href: string | null;
38
+ /** Event details (amount, currency, card last four and so on); the keys
39
+ * depend on `event_type`. */
40
+ data: Record<string, unknown>;
41
+ /** Language the item was rendered in. */
42
+ locale: string;
43
+ /** When the user read it, or `null` while unread. */
44
+ read_at: string | null;
45
+ created_at: string;
46
+ }
47
+ interface NotificationPage {
48
+ /** Newest first. */
49
+ items: InboxItem[];
50
+ /** Pass back as `cursor` to get the next page; `null` on the last one. */
51
+ next_cursor: string | null;
52
+ /** Unread items across the whole inbox, not just this page. */
53
+ unread_count: number;
54
+ }
55
+ interface ListNotificationsParams {
56
+ /** `next_cursor` from the previous page. */
57
+ cursor?: string;
58
+ /** Page size; the server caps it. */
59
+ limit?: number;
60
+ /** Only items without `read_at`. */
61
+ unreadOnly?: boolean;
62
+ category?: NotificationCategory;
63
+ }
64
+ /** Per-category channel switches: `{ money: { push: true, email: false } }`.
65
+ * A channel missing from a category keeps its default. */
66
+ type NotificationCategoryPreferences = Partial<Record<NotificationCategory, Partial<Record<NotificationChannel, boolean>>>>;
67
+ interface NotificationPreferences {
68
+ /** The channel to use first; `null` means automatic (the server picks by
69
+ * the user's devices). */
70
+ primary_channel: NotificationChannel | null;
71
+ categories: NotificationCategoryPreferences;
72
+ /** `null` when unset: the server falls back to the Telegram profile's
73
+ * language, then the deployment default. */
74
+ locale: NotificationLocale | null;
75
+ /** Channels this deployment can deliver on. Render toggles only for
76
+ * these. */
77
+ available_channels: NotificationChannel[];
78
+ }
79
+ /** Body of `setPreferences`. Every field is optional; only the given ones
80
+ * change. `primary_channel: null` switches back to automatic. */
81
+ interface NotificationPreferencesInput {
82
+ primary_channel?: NotificationChannel | null;
83
+ categories?: NotificationCategoryPreferences;
84
+ locale?: NotificationLocale | null;
85
+ }
86
+ declare class NotificationsResource {
87
+ private readonly http;
88
+ constructor(http: HttpClient);
89
+ /** One page of the inbox, newest first. */
90
+ list(params?: ListNotificationsParams): Promise<NotificationPage>;
91
+ /** How many items are unread. Cheap; fine to poll for a badge. */
92
+ unreadCount(): Promise<number>;
93
+ /** Mark one item read. Returns the item; calling it again is harmless. */
94
+ markRead(id: string): Promise<InboxItem>;
95
+ /** Mark every unread item read, or only those created before `before`
96
+ * (ISO timestamp). Returns how many changed. */
97
+ markAllRead(before?: string): Promise<{
98
+ marked: number;
99
+ }>;
100
+ /** Delete one item. 404 when it isn't the user's. */
101
+ remove(id: string): Promise<void>;
102
+ /** The user's channel and language settings. */
103
+ getPreferences(): Promise<NotificationPreferences>;
104
+ /** Change some settings; the rest stay. Returns the stored view.
105
+ * 400 `validation` for an unknown category, channel or locale. */
106
+ setPreferences(input: NotificationPreferencesInput): Promise<NotificationPreferences>;
107
+ }
108
+
109
+ export { type InboxItem, type ListNotificationsParams, type NotificationCategory, type NotificationCategoryPreferences, type NotificationChannel, type NotificationLocale, type NotificationPage, type NotificationPreferences, type NotificationPreferencesInput, NotificationsResource };
@@ -0,0 +1,51 @@
1
+ // src/resources/notifications.ts
2
+ var NotificationsResource = class {
3
+ constructor(http) {
4
+ this.http = http;
5
+ }
6
+ /** One page of the inbox, newest first. */
7
+ async list(params = {}) {
8
+ const q = new URLSearchParams();
9
+ if (params.cursor) q.set("cursor", params.cursor);
10
+ if (params.limit !== void 0) q.set("limit", String(params.limit));
11
+ if (params.unreadOnly) q.set("unread", "true");
12
+ if (params.category) q.set("category", params.category);
13
+ const qs = q.toString();
14
+ return this.http.get(`/me/notifications${qs ? `?${qs}` : ""}`);
15
+ }
16
+ /** How many items are unread. Cheap; fine to poll for a badge. */
17
+ async unreadCount() {
18
+ const { unread } = await this.http.get("/me/notifications/unread-count");
19
+ return unread;
20
+ }
21
+ /** Mark one item read. Returns the item; calling it again is harmless. */
22
+ async markRead(id) {
23
+ return this.http.post(`/me/notifications/${encodeURIComponent(id)}/read`);
24
+ }
25
+ /** Mark every unread item read, or only those created before `before`
26
+ * (ISO timestamp). Returns how many changed. */
27
+ async markAllRead(before) {
28
+ return this.http.post("/me/notifications/read-all", {
29
+ body: before ? { before } : {}
30
+ });
31
+ }
32
+ /** Delete one item. 404 when it isn't the user's. */
33
+ async remove(id) {
34
+ await this.http.delete(`/me/notifications/${encodeURIComponent(id)}`);
35
+ }
36
+ /** The user's channel and language settings. */
37
+ async getPreferences() {
38
+ return this.http.get("/me/notification-preferences");
39
+ }
40
+ /** Change some settings; the rest stay. Returns the stored view.
41
+ * 400 `validation` for an unknown category, channel or locale. */
42
+ async setPreferences(input) {
43
+ return this.http.put("/me/notification-preferences", {
44
+ body: input
45
+ });
46
+ }
47
+ };
48
+
49
+ export { NotificationsResource };
50
+ //# sourceMappingURL=notifications.js.map
51
+ //# sourceMappingURL=notifications.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/resources/notifications.ts"],"names":[],"mappings":";AAiGO,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,IAAI,OAAA,EAAS,MAAA,CAAO,MAAA,CAAO,KAAK,CAAC,CAAA;AACnE,IAAA,IAAI,MAAA,CAAO,UAAA,EAAY,CAAA,CAAE,GAAA,CAAI,UAAU,MAAM,CAAA;AAC7C,IAAA,IAAI,OAAO,QAAA,EAAU,CAAA,CAAE,GAAA,CAAI,UAAA,EAAY,OAAO,QAAQ,CAAA;AACtD,IAAA,MAAM,EAAA,GAAK,EAAE,QAAA,EAAS;AACtB,IAAA,OAAO,IAAA,CAAK,KAAK,GAAA,CAAsB,CAAA,iBAAA,EAAoB,KAAK,CAAA,CAAA,EAAI,EAAE,CAAA,CAAA,GAAK,EAAE,CAAA,CAAE,CAAA;AAAA,EACjF;AAAA;AAAA,EAGA,MAAM,WAAA,GAA+B;AACnC,IAAA,MAAM,EAAE,MAAA,EAAO,GAAI,MAAM,IAAA,CAAK,IAAA,CAAK,IAAwB,gCAAgC,CAAA;AAC3F,IAAA,OAAO,MAAA;AAAA,EACT;AAAA;AAAA,EAGA,MAAM,SAAS,EAAA,EAAgC;AAC7C,IAAA,OAAO,KAAK,IAAA,CAAK,IAAA,CAAgB,qBAAqB,kBAAA,CAAmB,EAAE,CAAC,CAAA,KAAA,CAAO,CAAA;AAAA,EACrF;AAAA;AAAA;AAAA,EAIA,MAAM,YAAY,MAAA,EAA8C;AAC9D,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,IAAA,CAAyB,4BAAA,EAA8B;AAAA,MACtE,IAAA,EAAM,MAAA,GAAS,EAAE,MAAA,KAAW;AAAC,KAC9B,CAAA;AAAA,EACH;AAAA;AAAA,EAGA,MAAM,OAAO,EAAA,EAA2B;AACtC,IAAA,MAAM,KAAK,IAAA,CAAK,MAAA,CAAa,qBAAqB,kBAAA,CAAmB,EAAE,CAAC,CAAA,CAAE,CAAA;AAAA,EAC5E;AAAA;AAAA,EAGA,MAAM,cAAA,GAAmD;AACvD,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,GAAA,CAA6B,8BAA8B,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.js","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\nexport interface InboxItem {\n id: string;\n /** What happened, e.g. `deposit_confirmed`, `card_transaction`, `login_new_device`. */\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,65 @@
1
+ 'use strict';
2
+
3
+ // src/resources/push.ts
4
+ var PushResource = class {
5
+ constructor(http) {
6
+ this.http = http;
7
+ }
8
+ /** Whether the user is subscribed, plus the VAPID key to subscribe with. */
9
+ async status() {
10
+ return this.http.get("/me/push-subscription");
11
+ }
12
+ /** Store a subscription you created yourself.
13
+ * 409 `push_disabled` when the deployment has no VAPID keys.
14
+ * @deprecated Use `client.devices.register({ kind: "webpush", ... })`. */
15
+ async save(input) {
16
+ return this.http.put("/me/push-subscription", { body: input });
17
+ }
18
+ /** Delete the stored subscription. Safe when nothing is stored.
19
+ * @deprecated Use `client.devices.remove(id)` or `client.devices.unregisterWebPush(reg)`. */
20
+ async remove() {
21
+ await this.http.delete("/me/push-subscription");
22
+ }
23
+ /** Subscribe this browser and store the subscription. Ask for
24
+ * notification permission before calling. Throws when push isn't set up
25
+ * on the deployment.
26
+ * @deprecated Use `client.devices.registerWebPush(registration)`. */
27
+ async enable(registration) {
28
+ const { vapid_public_key } = await this.status();
29
+ if (!vapid_public_key) {
30
+ throw new Error("@takeal/cusfront-sdk: push notifications are not enabled on this deployment");
31
+ }
32
+ const sub = await registration.pushManager.subscribe({
33
+ userVisibleOnly: true,
34
+ applicationServerKey: base64UrlToBytes(vapid_public_key)
35
+ });
36
+ const json = sub.toJSON();
37
+ if (!json.endpoint || !json.keys?.p256dh || !json.keys.auth) {
38
+ throw new Error("@takeal/cusfront-sdk: the browser returned an incomplete push subscription");
39
+ }
40
+ return this.save({
41
+ endpoint: json.endpoint,
42
+ keys: { p256dh: json.keys.p256dh, auth: json.keys.auth }
43
+ });
44
+ }
45
+ /** Unsubscribe this browser and delete the stored subscription.
46
+ * @deprecated Use `client.devices.unregisterWebPush(registration)`. */
47
+ async disable(registration) {
48
+ const sub = await registration.pushManager.getSubscription();
49
+ if (sub) await sub.unsubscribe();
50
+ await this.remove();
51
+ }
52
+ };
53
+ function base64UrlToBytes(input) {
54
+ const b64 = input.replace(/-/g, "+").replace(/_/g, "/");
55
+ const padded = b64 + "=".repeat((4 - b64.length % 4) % 4);
56
+ const bin = atob(padded);
57
+ const out = new Uint8Array(bin.length);
58
+ for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);
59
+ return out;
60
+ }
61
+
62
+ exports.PushResource = PushResource;
63
+ exports.base64UrlToBytes = base64UrlToBytes;
64
+ //# sourceMappingURL=push.cjs.map
65
+ //# sourceMappingURL=push.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/resources/push.ts"],"names":[],"mappings":";;;AAgDO,IAAM,eAAN,MAAmB;AAAA,EACxB,YAA6B,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAmB;AAAA;AAAA,EAGhD,MAAM,MAAA,GAA8B;AAClC,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,GAAA,CAAgB,uBAAuB,CAAA;AAAA,EAC1D;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,KAAK,KAAA,EAAmD;AAC5D,IAAA,OAAO,KAAK,IAAA,CAAK,GAAA,CAAgB,yBAAyB,EAAE,IAAA,EAAM,OAAO,CAAA;AAAA,EAC3E;AAAA;AAAA;AAAA,EAIA,MAAM,MAAA,GAAwB;AAC5B,IAAA,MAAM,IAAA,CAAK,IAAA,CAAK,MAAA,CAAa,uBAAuB,CAAA;AAAA,EACtD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,OAAO,YAAA,EAA4D;AACvE,IAAA,MAAM,EAAE,gBAAA,EAAiB,GAAI,MAAM,KAAK,MAAA,EAAO;AAC/C,IAAA,IAAI,CAAC,gBAAA,EAAkB;AACrB,MAAA,MAAM,IAAI,MAAM,6EAA6E,CAAA;AAAA,IAC/F;AACA,IAAA,MAAM,GAAA,GAAM,MAAM,YAAA,CAAa,WAAA,CAAY,SAAA,CAAU;AAAA,MACnD,eAAA,EAAiB,IAAA;AAAA,MACjB,oBAAA,EAAsB,iBAAiB,gBAAgB;AAAA,KACxD,CAAA;AACD,IAAA,MAAM,IAAA,GAAO,IAAI,MAAA,EAAO;AACxB,IAAA,IAAI,CAAC,IAAA,CAAK,QAAA,IAAY,CAAC,IAAA,CAAK,MAAM,MAAA,IAAU,CAAC,IAAA,CAAK,IAAA,CAAK,IAAA,EAAM;AAC3D,MAAA,MAAM,IAAI,MAAM,4EAA4E,CAAA;AAAA,IAC9F;AACA,IAAA,OAAO,KAAK,IAAA,CAAK;AAAA,MACf,UAAU,IAAA,CAAK,QAAA;AAAA,MACf,IAAA,EAAM,EAAE,MAAA,EAAQ,IAAA,CAAK,KAAK,MAAA,EAAQ,IAAA,EAAM,IAAA,CAAK,IAAA,CAAK,IAAA;AAAK,KACxD,CAAA;AAAA,EACH;AAAA;AAAA;AAAA,EAIA,MAAM,QAAQ,YAAA,EAAsD;AAClE,IAAA,MAAM,GAAA,GAAM,MAAM,YAAA,CAAa,WAAA,CAAY,eAAA,EAAgB;AAC3D,IAAA,IAAI,GAAA,EAAK,MAAM,GAAA,CAAI,WAAA,EAAY;AAC/B,IAAA,MAAM,KAAK,MAAA,EAAO;AAAA,EACpB;AACF;AAGO,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","file":"push.cjs","sourcesContent":["import type { HttpClient } from \"../http.js\";\n\n/**\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"]}
@@ -0,0 +1,76 @@
1
+ import { H as HttpClient } from '../http-B-OQwMYn.cjs';
2
+
3
+ /**
4
+ * Push resource — `client.push.*`.
5
+ *
6
+ * Web Push for the signed-in user, through the older single-subscription
7
+ * endpoint. The API now keeps one device per browser (see
8
+ * `client.devices`), and this endpoint is an alias over the Web Push
9
+ * devices: it keeps working, but new code should call
10
+ * `client.devices.registerWebPush(reg)` / `unregisterWebPush(reg)` instead.
11
+ *
12
+ * Your service worker shows the notification: the payload is JSON with
13
+ * `title`, `body` and `url` (where a click should lead).
14
+ */
15
+ interface PushStatus {
16
+ /** `true` when a subscription is stored for this user. */
17
+ subscribed: boolean;
18
+ /** Host of the stored endpoint, e.g. `fcm.googleapis.com`. */
19
+ endpoint_host?: string | null;
20
+ /** VAPID public key (URL-safe base64) for `pushManager.subscribe`.
21
+ * `null` when push is not set up on this deployment. */
22
+ vapid_public_key?: string | null;
23
+ }
24
+ interface PushSubscriptionInput {
25
+ /** `PushSubscription.endpoint`; must be https. */
26
+ endpoint: string;
27
+ keys: {
28
+ /** URL-safe base64. */
29
+ p256dh: string;
30
+ /** URL-safe base64. */
31
+ auth: string;
32
+ };
33
+ }
34
+ /** The part of `ServiceWorkerRegistration` the SDK needs. Typed
35
+ * structurally so the core stays free of DOM lib types. */
36
+ interface PushCapableRegistration {
37
+ pushManager: {
38
+ getSubscription(): Promise<{
39
+ unsubscribe(): Promise<boolean>;
40
+ } | null>;
41
+ subscribe(options: {
42
+ userVisibleOnly: boolean;
43
+ applicationServerKey: Uint8Array;
44
+ }): Promise<{
45
+ toJSON(): {
46
+ endpoint?: string;
47
+ keys?: Record<string, string>;
48
+ };
49
+ }>;
50
+ };
51
+ }
52
+ declare class PushResource {
53
+ private readonly http;
54
+ constructor(http: HttpClient);
55
+ /** Whether the user is subscribed, plus the VAPID key to subscribe with. */
56
+ status(): Promise<PushStatus>;
57
+ /** Store a subscription you created yourself.
58
+ * 409 `push_disabled` when the deployment has no VAPID keys.
59
+ * @deprecated Use `client.devices.register({ kind: "webpush", ... })`. */
60
+ save(input: PushSubscriptionInput): Promise<PushStatus>;
61
+ /** Delete the stored subscription. Safe when nothing is stored.
62
+ * @deprecated Use `client.devices.remove(id)` or `client.devices.unregisterWebPush(reg)`. */
63
+ remove(): Promise<void>;
64
+ /** Subscribe this browser and store the subscription. Ask for
65
+ * notification permission before calling. Throws when push isn't set up
66
+ * on the deployment.
67
+ * @deprecated Use `client.devices.registerWebPush(registration)`. */
68
+ enable(registration: PushCapableRegistration): Promise<PushStatus>;
69
+ /** Unsubscribe this browser and delete the stored subscription.
70
+ * @deprecated Use `client.devices.unregisterWebPush(registration)`. */
71
+ disable(registration: PushCapableRegistration): Promise<void>;
72
+ }
73
+ /** URL-safe base64 (padding optional) → bytes. */
74
+ declare function base64UrlToBytes(input: string): Uint8Array;
75
+
76
+ export { type PushCapableRegistration, PushResource, type PushStatus, type PushSubscriptionInput, base64UrlToBytes };
@@ -0,0 +1,76 @@
1
+ import { H as HttpClient } from '../http-B-OQwMYn.js';
2
+
3
+ /**
4
+ * Push resource — `client.push.*`.
5
+ *
6
+ * Web Push for the signed-in user, through the older single-subscription
7
+ * endpoint. The API now keeps one device per browser (see
8
+ * `client.devices`), and this endpoint is an alias over the Web Push
9
+ * devices: it keeps working, but new code should call
10
+ * `client.devices.registerWebPush(reg)` / `unregisterWebPush(reg)` instead.
11
+ *
12
+ * Your service worker shows the notification: the payload is JSON with
13
+ * `title`, `body` and `url` (where a click should lead).
14
+ */
15
+ interface PushStatus {
16
+ /** `true` when a subscription is stored for this user. */
17
+ subscribed: boolean;
18
+ /** Host of the stored endpoint, e.g. `fcm.googleapis.com`. */
19
+ endpoint_host?: string | null;
20
+ /** VAPID public key (URL-safe base64) for `pushManager.subscribe`.
21
+ * `null` when push is not set up on this deployment. */
22
+ vapid_public_key?: string | null;
23
+ }
24
+ interface PushSubscriptionInput {
25
+ /** `PushSubscription.endpoint`; must be https. */
26
+ endpoint: string;
27
+ keys: {
28
+ /** URL-safe base64. */
29
+ p256dh: string;
30
+ /** URL-safe base64. */
31
+ auth: string;
32
+ };
33
+ }
34
+ /** The part of `ServiceWorkerRegistration` the SDK needs. Typed
35
+ * structurally so the core stays free of DOM lib types. */
36
+ interface PushCapableRegistration {
37
+ pushManager: {
38
+ getSubscription(): Promise<{
39
+ unsubscribe(): Promise<boolean>;
40
+ } | null>;
41
+ subscribe(options: {
42
+ userVisibleOnly: boolean;
43
+ applicationServerKey: Uint8Array;
44
+ }): Promise<{
45
+ toJSON(): {
46
+ endpoint?: string;
47
+ keys?: Record<string, string>;
48
+ };
49
+ }>;
50
+ };
51
+ }
52
+ declare class PushResource {
53
+ private readonly http;
54
+ constructor(http: HttpClient);
55
+ /** Whether the user is subscribed, plus the VAPID key to subscribe with. */
56
+ status(): Promise<PushStatus>;
57
+ /** Store a subscription you created yourself.
58
+ * 409 `push_disabled` when the deployment has no VAPID keys.
59
+ * @deprecated Use `client.devices.register({ kind: "webpush", ... })`. */
60
+ save(input: PushSubscriptionInput): Promise<PushStatus>;
61
+ /** Delete the stored subscription. Safe when nothing is stored.
62
+ * @deprecated Use `client.devices.remove(id)` or `client.devices.unregisterWebPush(reg)`. */
63
+ remove(): Promise<void>;
64
+ /** Subscribe this browser and store the subscription. Ask for
65
+ * notification permission before calling. Throws when push isn't set up
66
+ * on the deployment.
67
+ * @deprecated Use `client.devices.registerWebPush(registration)`. */
68
+ enable(registration: PushCapableRegistration): Promise<PushStatus>;
69
+ /** Unsubscribe this browser and delete the stored subscription.
70
+ * @deprecated Use `client.devices.unregisterWebPush(registration)`. */
71
+ disable(registration: PushCapableRegistration): Promise<void>;
72
+ }
73
+ /** URL-safe base64 (padding optional) → bytes. */
74
+ declare function base64UrlToBytes(input: string): Uint8Array;
75
+
76
+ export { type PushCapableRegistration, PushResource, type PushStatus, type PushSubscriptionInput, base64UrlToBytes };
@@ -0,0 +1,62 @@
1
+ // src/resources/push.ts
2
+ var PushResource = class {
3
+ constructor(http) {
4
+ this.http = http;
5
+ }
6
+ /** Whether the user is subscribed, plus the VAPID key to subscribe with. */
7
+ async status() {
8
+ return this.http.get("/me/push-subscription");
9
+ }
10
+ /** Store a subscription you created yourself.
11
+ * 409 `push_disabled` when the deployment has no VAPID keys.
12
+ * @deprecated Use `client.devices.register({ kind: "webpush", ... })`. */
13
+ async save(input) {
14
+ return this.http.put("/me/push-subscription", { body: input });
15
+ }
16
+ /** Delete the stored subscription. Safe when nothing is stored.
17
+ * @deprecated Use `client.devices.remove(id)` or `client.devices.unregisterWebPush(reg)`. */
18
+ async remove() {
19
+ await this.http.delete("/me/push-subscription");
20
+ }
21
+ /** Subscribe this browser and store the subscription. Ask for
22
+ * notification permission before calling. Throws when push isn't set up
23
+ * on the deployment.
24
+ * @deprecated Use `client.devices.registerWebPush(registration)`. */
25
+ async enable(registration) {
26
+ const { vapid_public_key } = await this.status();
27
+ if (!vapid_public_key) {
28
+ throw new Error("@takeal/cusfront-sdk: push notifications are not enabled on this deployment");
29
+ }
30
+ const sub = await registration.pushManager.subscribe({
31
+ userVisibleOnly: true,
32
+ applicationServerKey: base64UrlToBytes(vapid_public_key)
33
+ });
34
+ const json = sub.toJSON();
35
+ if (!json.endpoint || !json.keys?.p256dh || !json.keys.auth) {
36
+ throw new Error("@takeal/cusfront-sdk: the browser returned an incomplete push subscription");
37
+ }
38
+ return this.save({
39
+ endpoint: json.endpoint,
40
+ keys: { p256dh: json.keys.p256dh, auth: json.keys.auth }
41
+ });
42
+ }
43
+ /** Unsubscribe this browser and delete the stored subscription.
44
+ * @deprecated Use `client.devices.unregisterWebPush(registration)`. */
45
+ async disable(registration) {
46
+ const sub = await registration.pushManager.getSubscription();
47
+ if (sub) await sub.unsubscribe();
48
+ await this.remove();
49
+ }
50
+ };
51
+ function base64UrlToBytes(input) {
52
+ const b64 = input.replace(/-/g, "+").replace(/_/g, "/");
53
+ const padded = b64 + "=".repeat((4 - b64.length % 4) % 4);
54
+ const bin = atob(padded);
55
+ const out = new Uint8Array(bin.length);
56
+ for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i);
57
+ return out;
58
+ }
59
+
60
+ export { PushResource, base64UrlToBytes };
61
+ //# sourceMappingURL=push.js.map
62
+ //# sourceMappingURL=push.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/resources/push.ts"],"names":[],"mappings":";AAgDO,IAAM,eAAN,MAAmB;AAAA,EACxB,YAA6B,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAmB;AAAA;AAAA,EAGhD,MAAM,MAAA,GAA8B;AAClC,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,GAAA,CAAgB,uBAAuB,CAAA;AAAA,EAC1D;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,KAAK,KAAA,EAAmD;AAC5D,IAAA,OAAO,KAAK,IAAA,CAAK,GAAA,CAAgB,yBAAyB,EAAE,IAAA,EAAM,OAAO,CAAA;AAAA,EAC3E;AAAA;AAAA;AAAA,EAIA,MAAM,MAAA,GAAwB;AAC5B,IAAA,MAAM,IAAA,CAAK,IAAA,CAAK,MAAA,CAAa,uBAAuB,CAAA;AAAA,EACtD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,OAAO,YAAA,EAA4D;AACvE,IAAA,MAAM,EAAE,gBAAA,EAAiB,GAAI,MAAM,KAAK,MAAA,EAAO;AAC/C,IAAA,IAAI,CAAC,gBAAA,EAAkB;AACrB,MAAA,MAAM,IAAI,MAAM,6EAA6E,CAAA;AAAA,IAC/F;AACA,IAAA,MAAM,GAAA,GAAM,MAAM,YAAA,CAAa,WAAA,CAAY,SAAA,CAAU;AAAA,MACnD,eAAA,EAAiB,IAAA;AAAA,MACjB,oBAAA,EAAsB,iBAAiB,gBAAgB;AAAA,KACxD,CAAA;AACD,IAAA,MAAM,IAAA,GAAO,IAAI,MAAA,EAAO;AACxB,IAAA,IAAI,CAAC,IAAA,CAAK,QAAA,IAAY,CAAC,IAAA,CAAK,MAAM,MAAA,IAAU,CAAC,IAAA,CAAK,IAAA,CAAK,IAAA,EAAM;AAC3D,MAAA,MAAM,IAAI,MAAM,4EAA4E,CAAA;AAAA,IAC9F;AACA,IAAA,OAAO,KAAK,IAAA,CAAK;AAAA,MACf,UAAU,IAAA,CAAK,QAAA;AAAA,MACf,IAAA,EAAM,EAAE,MAAA,EAAQ,IAAA,CAAK,KAAK,MAAA,EAAQ,IAAA,EAAM,IAAA,CAAK,IAAA,CAAK,IAAA;AAAK,KACxD,CAAA;AAAA,EACH;AAAA;AAAA;AAAA,EAIA,MAAM,QAAQ,YAAA,EAAsD;AAClE,IAAA,MAAM,GAAA,GAAM,MAAM,YAAA,CAAa,WAAA,CAAY,eAAA,EAAgB;AAC3D,IAAA,IAAI,GAAA,EAAK,MAAM,GAAA,CAAI,WAAA,EAAY;AAC/B,IAAA,MAAM,KAAK,MAAA,EAAO;AAAA,EACpB;AACF;AAGO,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","file":"push.js","sourcesContent":["import type { HttpClient } from \"../http.js\";\n\n/**\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"]}
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ // src/resources/sessions.ts
4
+ var SessionsResource = class {
5
+ constructor(http) {
6
+ this.http = http;
7
+ }
8
+ /** All live sessions of the account, this one included. */
9
+ async list() {
10
+ return this.http.get("/me/sessions");
11
+ }
12
+ /** Sign out one session. Works on the current one too; the stored JWT
13
+ * stops working, so follow with `client.auth.signOut()`.
14
+ * 404 when the session is unknown or already signed out. */
15
+ async revoke(jti) {
16
+ await this.http.delete(`/me/sessions/${encodeURIComponent(jti)}`);
17
+ }
18
+ /** Sign out every session except this one. */
19
+ async revokeOthers() {
20
+ return this.http.post("/me/sessions/terminate-others");
21
+ }
22
+ };
23
+
24
+ exports.SessionsResource = SessionsResource;
25
+ //# sourceMappingURL=sessions.cjs.map
26
+ //# sourceMappingURL=sessions.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/resources/sessions.ts"],"names":[],"mappings":";;;AA6BO,IAAM,mBAAN,MAAuB;AAAA,EAC5B,YAA6B,IAAA,EAAkB;AAAlB,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAAA,EAAmB;AAAA;AAAA,EAGhD,MAAM,IAAA,GAA+B;AACnC,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,GAAA,CAAmB,cAAc,CAAA;AAAA,EACpD;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,OAAO,GAAA,EAA4B;AACvC,IAAA,MAAM,KAAK,IAAA,CAAK,MAAA,CAAa,gBAAgB,kBAAA,CAAmB,GAAG,CAAC,CAAA,CAAE,CAAA;AAAA,EACxE;AAAA;AAAA,EAGA,MAAM,YAAA,GAAsD;AAC1D,IAAA,OAAO,IAAA,CAAK,IAAA,CAAK,IAAA,CAAmC,+BAA+B,CAAA;AAAA,EACrF;AACF","file":"sessions.cjs","sourcesContent":["import type { HttpClient } from \"../http.js\";\n\n/**\n * Sessions resource — `client.sessions.*`.\n *\n * Every device or browser the user is signed in on. Lets a settings screen\n * show \"where you're signed in\" and sign one or all of them out.\n *\n * ```ts\n * const sessions = await client.sessions.list();\n * const others = sessions.filter((s) => !s.current);\n * await client.sessions.revokeOthers();\n * ```\n */\n\nexport interface UserSession {\n /** Session id; pass it to `revoke`. */\n jti: string;\n issued_at: string;\n expires_at: string;\n last_seen_at: string;\n /** Client IP recorded for the session, if known. */\n remote_ip?: string | null;\n /** Browser or app that opened the session, if known. */\n user_agent?: string | null;\n /** `true` for the session this client is using. */\n current: boolean;\n}\n\nexport class SessionsResource {\n constructor(private readonly http: HttpClient) {}\n\n /** All live sessions of the account, this one included. */\n async list(): Promise<UserSession[]> {\n return this.http.get<UserSession[]>(\"/me/sessions\");\n }\n\n /** Sign out one session. Works on the current one too; the stored JWT\n * stops working, so follow with `client.auth.signOut()`.\n * 404 when the session is unknown or already signed out. */\n async revoke(jti: string): Promise<void> {\n await this.http.delete<void>(`/me/sessions/${encodeURIComponent(jti)}`);\n }\n\n /** Sign out every session except this one. */\n async revokeOthers(): Promise<{ revoked_sessions: number }> {\n return this.http.post<{ revoked_sessions: number }>(\"/me/sessions/terminate-others\");\n }\n}\n"]}