@codingfactory/notify-kit-client 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-7LQBNDRD.js +235 -0
- package/dist/chunk-7LQBNDRD.js.map +1 -0
- package/dist/index.d.ts +547 -0
- package/dist/index.js +737 -0
- package/dist/index.js.map +1 -0
- package/dist/nuxt/index.d.ts +114 -0
- package/dist/nuxt/index.js +55 -0
- package/dist/nuxt/index.js.map +1 -0
- package/dist/useNotifyKitModals-BZ_NiTKw.d.ts +586 -0
- package/package.json +77 -0
|
@@ -0,0 +1,586 @@
|
|
|
1
|
+
import { InjectionKey, ComputedRef, Ref } from 'vue';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Modal-related type definitions for critical notification modals.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Escape key behavior modes for modals.
|
|
8
|
+
*/
|
|
9
|
+
type EscapeKeyBehavior = 'close' | 'snooze' | 'disabled';
|
|
10
|
+
/**
|
|
11
|
+
* Accessibility settings for modal notifications.
|
|
12
|
+
* Ensures WCAG 2.1 AA compliance.
|
|
13
|
+
*/
|
|
14
|
+
interface NotifyKitModalAccessibility {
|
|
15
|
+
/** Escape key behavior: close, snooze, or disabled */
|
|
16
|
+
readonly escape_key_behavior: EscapeKeyBehavior;
|
|
17
|
+
/** Whether focus is trapped inside the modal */
|
|
18
|
+
readonly focus_trap: boolean;
|
|
19
|
+
/** Whether to auto-focus the first action button */
|
|
20
|
+
readonly auto_focus_first_action: boolean;
|
|
21
|
+
/** ARIA role for the modal element */
|
|
22
|
+
readonly aria_role: string;
|
|
23
|
+
/** ID of the element that labels the modal (aria-labelledby) */
|
|
24
|
+
readonly aria_labelled_by: string | null;
|
|
25
|
+
/** ID of the element that describes the modal (aria-describedby) */
|
|
26
|
+
readonly aria_described_by: string | null;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Modal specification included in notifications that require modal display.
|
|
30
|
+
*/
|
|
31
|
+
interface NotifyKitModalSpec {
|
|
32
|
+
/** Whether modal display is enabled for this notification */
|
|
33
|
+
readonly enabled: boolean;
|
|
34
|
+
/** Whether the user must acknowledge before dismissing */
|
|
35
|
+
readonly requires_ack: boolean;
|
|
36
|
+
/** Available snooze duration options in minutes */
|
|
37
|
+
readonly snooze_options_minutes: readonly number[];
|
|
38
|
+
/** Accessibility settings for the modal */
|
|
39
|
+
readonly accessibility: NotifyKitModalAccessibility;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Modal state tracking for a notification.
|
|
43
|
+
* This represents the user's interaction state with a modal notification.
|
|
44
|
+
*/
|
|
45
|
+
interface NotifyKitModalState {
|
|
46
|
+
/** Timestamp when the modal was acknowledged (ISO 8601), null if not yet acknowledged */
|
|
47
|
+
readonly acknowledged_at: string | null;
|
|
48
|
+
/** Timestamp until which the modal is snoozed (ISO 8601), null if not snoozed */
|
|
49
|
+
readonly snoozed_until: string | null;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Type guard to validate if a value is a valid NotifyKitModalSpec.
|
|
53
|
+
*/
|
|
54
|
+
declare function isModalSpec(value: unknown): value is NotifyKitModalSpec;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Notification type definitions matching the Notify Kit backend contract.
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Valid notification categories.
|
|
62
|
+
*/
|
|
63
|
+
type NotificationCategory = 'workspace' | 'security' | 'orders' | 'social' | 'system' | 'marketing';
|
|
64
|
+
/**
|
|
65
|
+
* Valid notification severity levels.
|
|
66
|
+
*/
|
|
67
|
+
type NotificationLevel = 'info' | 'success' | 'warning' | 'danger';
|
|
68
|
+
/**
|
|
69
|
+
* All valid category values for runtime validation.
|
|
70
|
+
*/
|
|
71
|
+
declare const NOTIFICATION_CATEGORIES: readonly NotificationCategory[];
|
|
72
|
+
/**
|
|
73
|
+
* All valid level values for runtime validation.
|
|
74
|
+
*/
|
|
75
|
+
declare const NOTIFICATION_LEVELS: readonly NotificationLevel[];
|
|
76
|
+
/**
|
|
77
|
+
* Core notification payload structure matching the Notify Kit backend contract.
|
|
78
|
+
*/
|
|
79
|
+
interface NotifyKitNotification {
|
|
80
|
+
/** Unique notification ID (UUID) */
|
|
81
|
+
readonly id: string;
|
|
82
|
+
/** Notification key (e.g., 'orders.shipped', 'security.critical_alert') */
|
|
83
|
+
readonly key: string;
|
|
84
|
+
/** Notification category */
|
|
85
|
+
readonly category: NotificationCategory;
|
|
86
|
+
/** Severity level */
|
|
87
|
+
readonly level: NotificationLevel;
|
|
88
|
+
/** Notification title */
|
|
89
|
+
readonly title: string;
|
|
90
|
+
/** Notification body text */
|
|
91
|
+
readonly body: string;
|
|
92
|
+
/** Optional URL for the notification action */
|
|
93
|
+
readonly action_url: string | null;
|
|
94
|
+
/** Workspace ID if this is a workspace-scoped notification */
|
|
95
|
+
readonly workspace_id: string | null;
|
|
96
|
+
/** Modal specification if this notification requires modal display */
|
|
97
|
+
readonly modal: NotifyKitModalSpec | null;
|
|
98
|
+
/** Group key for notification aggregation (Phase 2) */
|
|
99
|
+
readonly group_key: string | null;
|
|
100
|
+
/** Idempotency key to prevent duplicate notifications (Phase 2) */
|
|
101
|
+
readonly idempotency_key: string | null;
|
|
102
|
+
/** Additional arbitrary data */
|
|
103
|
+
readonly data: Record<string, unknown>;
|
|
104
|
+
/** Timestamp when notification was marked as read (ISO 8601) */
|
|
105
|
+
readonly read_at: string | null;
|
|
106
|
+
/** Timestamp when notification was created (ISO 8601) */
|
|
107
|
+
readonly created_at: string;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Type guard to validate if a value is a valid NotificationCategory.
|
|
111
|
+
*/
|
|
112
|
+
declare function isValidCategory(value: unknown): value is NotificationCategory;
|
|
113
|
+
/**
|
|
114
|
+
* Type guard to validate if a value is a valid NotificationLevel.
|
|
115
|
+
*/
|
|
116
|
+
declare function isValidLevel(value: unknown): value is NotificationLevel;
|
|
117
|
+
/**
|
|
118
|
+
* Type guard to validate if a value is a NotifyKitNotification.
|
|
119
|
+
* Use this to validate data from external sources (API responses, WebSocket messages).
|
|
120
|
+
*/
|
|
121
|
+
declare function isNotifyKitNotification(value: unknown): value is NotifyKitNotification;
|
|
122
|
+
/**
|
|
123
|
+
* Helper to check if a notification has modal functionality enabled.
|
|
124
|
+
*/
|
|
125
|
+
declare function isModalEnabled(notification: NotifyKitNotification): boolean;
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* User notification preferences type definitions.
|
|
129
|
+
*/
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Channel preference settings for a single category.
|
|
133
|
+
*/
|
|
134
|
+
interface ChannelPreferences {
|
|
135
|
+
/** Whether to store in database (notification center) */
|
|
136
|
+
readonly database: boolean;
|
|
137
|
+
/** Whether to broadcast in real-time */
|
|
138
|
+
readonly broadcast: boolean;
|
|
139
|
+
/** Whether to send via email */
|
|
140
|
+
readonly mail: boolean;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* User's notification preferences organized by category.
|
|
144
|
+
*/
|
|
145
|
+
interface NotifyKitPreferences {
|
|
146
|
+
/** Preferences per category */
|
|
147
|
+
readonly categories: Readonly<Record<NotificationCategory, ChannelPreferences>>;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Partial preferences update request.
|
|
151
|
+
* Only categories/channels that need updating should be included.
|
|
152
|
+
*/
|
|
153
|
+
interface NotifyKitPreferencesUpdate {
|
|
154
|
+
/** Partial category preferences to update */
|
|
155
|
+
readonly categories?: Partial<Record<NotificationCategory, Partial<ChannelPreferences>>>;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Type guard to validate if a value is valid ChannelPreferences.
|
|
159
|
+
*/
|
|
160
|
+
declare function isChannelPreferences(value: unknown): value is ChannelPreferences;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* API response type definitions for Notify Kit endpoints.
|
|
164
|
+
*/
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Pagination metadata returned with list responses.
|
|
168
|
+
*/
|
|
169
|
+
interface PaginationMeta {
|
|
170
|
+
/** Current page number (1-indexed) */
|
|
171
|
+
readonly current_page: number;
|
|
172
|
+
/** Last page number */
|
|
173
|
+
readonly last_page: number;
|
|
174
|
+
/** Number of items per page */
|
|
175
|
+
readonly per_page: number;
|
|
176
|
+
/** Total number of items */
|
|
177
|
+
readonly total: number;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Response from GET /me endpoint.
|
|
181
|
+
*/
|
|
182
|
+
interface NotifyKitMeResponse {
|
|
183
|
+
/** The private broadcast channel for this user */
|
|
184
|
+
readonly broadcast_channel: string;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Response from GET /notifications endpoint.
|
|
188
|
+
*/
|
|
189
|
+
interface NotifyKitListResponse {
|
|
190
|
+
/** Array of notifications */
|
|
191
|
+
readonly data: readonly NotifyKitNotification[];
|
|
192
|
+
/** Pagination metadata */
|
|
193
|
+
readonly meta: PaginationMeta;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* A grouped notification entry returned when using grouped=1 parameter.
|
|
197
|
+
*/
|
|
198
|
+
interface NotifyKitGroupedEntry {
|
|
199
|
+
/** The group key for this group */
|
|
200
|
+
readonly group_key: string;
|
|
201
|
+
/** Number of notifications in this group */
|
|
202
|
+
readonly group_count: number;
|
|
203
|
+
/** The most recent notification in the group */
|
|
204
|
+
readonly latest_notification: NotifyKitNotification;
|
|
205
|
+
/** IDs of all notifications in this group */
|
|
206
|
+
readonly notification_ids: readonly string[];
|
|
207
|
+
/** Whether any notification in the group is unread */
|
|
208
|
+
readonly has_unread: boolean;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Response from GET /notifications?grouped=1 endpoint.
|
|
212
|
+
*/
|
|
213
|
+
interface NotifyKitGroupedListResponse {
|
|
214
|
+
/** Array of grouped entries (may include ungrouped notifications as single-item groups) */
|
|
215
|
+
readonly data: readonly NotifyKitGroupedEntry[];
|
|
216
|
+
/** Pagination metadata */
|
|
217
|
+
readonly meta: PaginationMeta;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Response from GET /notifications/unread-count endpoint.
|
|
221
|
+
*/
|
|
222
|
+
interface NotifyKitUnreadCountResponse {
|
|
223
|
+
/** Number of unread notifications */
|
|
224
|
+
readonly count: number;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Response from GET /modals endpoint.
|
|
228
|
+
*/
|
|
229
|
+
interface NotifyKitModalsResponse {
|
|
230
|
+
/** Array of outstanding modal notifications */
|
|
231
|
+
readonly data: readonly NotifyKitNotification[];
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Parameters for listing notifications.
|
|
235
|
+
*/
|
|
236
|
+
interface ListNotificationsParams {
|
|
237
|
+
/** Filter to unread notifications only */
|
|
238
|
+
readonly unread?: boolean;
|
|
239
|
+
/** Filter by category */
|
|
240
|
+
readonly category?: NotificationCategory;
|
|
241
|
+
/** Filter by workspace ID */
|
|
242
|
+
readonly workspace_id?: string;
|
|
243
|
+
/** Enable grouped mode (Phase 2) */
|
|
244
|
+
readonly grouped?: boolean;
|
|
245
|
+
/** Page number for pagination */
|
|
246
|
+
readonly page?: number;
|
|
247
|
+
/** Number of items per page */
|
|
248
|
+
readonly per_page?: number;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Parameters for paginated requests.
|
|
252
|
+
*/
|
|
253
|
+
interface PaginationParams {
|
|
254
|
+
/** Page number (1-indexed) */
|
|
255
|
+
readonly page?: number;
|
|
256
|
+
/** Number of items per page */
|
|
257
|
+
readonly per_page?: number;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Standard error response from the API.
|
|
261
|
+
*/
|
|
262
|
+
interface NotifyKitErrorResponse {
|
|
263
|
+
/** Error message */
|
|
264
|
+
readonly message: string;
|
|
265
|
+
/** Validation errors (field -> error messages) */
|
|
266
|
+
readonly errors?: Readonly<Record<string, readonly string[]>>;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Type guard to validate PaginationMeta.
|
|
270
|
+
*/
|
|
271
|
+
declare function isPaginationMeta(value: unknown): value is PaginationMeta;
|
|
272
|
+
/**
|
|
273
|
+
* Type guard to validate NotifyKitMeResponse.
|
|
274
|
+
*/
|
|
275
|
+
declare function isMeResponse(value: unknown): value is NotifyKitMeResponse;
|
|
276
|
+
/**
|
|
277
|
+
* Type guard to validate NotifyKitUnreadCountResponse.
|
|
278
|
+
*/
|
|
279
|
+
declare function isUnreadCountResponse(value: unknown): value is NotifyKitUnreadCountResponse;
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Notify Kit HTTP Client
|
|
283
|
+
*
|
|
284
|
+
* Provides type-safe access to all Notify Kit API endpoints.
|
|
285
|
+
*/
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Configuration options for the NotifyKit client.
|
|
289
|
+
*/
|
|
290
|
+
interface NotifyKitClientConfig {
|
|
291
|
+
/** Base URL for the Notify Kit API (e.g., '/api/notify-kit' or 'https://api.example.com') */
|
|
292
|
+
baseUrl: string;
|
|
293
|
+
/** Optional function to provide auth headers for requests */
|
|
294
|
+
getAuthHeaders?: () => Record<string, string> | Promise<Record<string, string>>;
|
|
295
|
+
/** Optional custom fetch implementation (defaults to global fetch) */
|
|
296
|
+
fetch?: typeof fetch;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* API error thrown when requests fail.
|
|
300
|
+
*/
|
|
301
|
+
declare class NotifyKitApiError extends Error {
|
|
302
|
+
readonly status: number;
|
|
303
|
+
readonly errors?: Readonly<Record<string, readonly string[]>> | undefined;
|
|
304
|
+
readonly name = "NotifyKitApiError";
|
|
305
|
+
constructor(message: string, status: number, errors?: Readonly<Record<string, readonly string[]>> | undefined);
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* HTTP Client for the Notify Kit API.
|
|
309
|
+
*/
|
|
310
|
+
declare class NotifyKitClient {
|
|
311
|
+
private readonly baseUrl;
|
|
312
|
+
private readonly getAuthHeaders;
|
|
313
|
+
private readonly fetchFn;
|
|
314
|
+
constructor(config: NotifyKitClientConfig);
|
|
315
|
+
/**
|
|
316
|
+
* Get the current user's broadcast channel information.
|
|
317
|
+
*/
|
|
318
|
+
getMe(): Promise<NotifyKitMeResponse>;
|
|
319
|
+
/**
|
|
320
|
+
* List notifications for the current user.
|
|
321
|
+
*/
|
|
322
|
+
listNotifications(params?: ListNotificationsParams): Promise<NotifyKitListResponse>;
|
|
323
|
+
/**
|
|
324
|
+
* Get the count of unread notifications.
|
|
325
|
+
*/
|
|
326
|
+
getUnreadCount(): Promise<NotifyKitUnreadCountResponse>;
|
|
327
|
+
/**
|
|
328
|
+
* Mark a notification as read.
|
|
329
|
+
*/
|
|
330
|
+
markRead(id: string): Promise<void>;
|
|
331
|
+
/**
|
|
332
|
+
* Mark all notifications as read.
|
|
333
|
+
*/
|
|
334
|
+
markAllRead(): Promise<void>;
|
|
335
|
+
/**
|
|
336
|
+
* Delete a notification.
|
|
337
|
+
*/
|
|
338
|
+
deleteNotification(id: string): Promise<void>;
|
|
339
|
+
/**
|
|
340
|
+
* Mark all notifications in a group as read.
|
|
341
|
+
*/
|
|
342
|
+
markGroupRead(groupKey: string): Promise<void>;
|
|
343
|
+
/**
|
|
344
|
+
* Get all notifications in a group.
|
|
345
|
+
*/
|
|
346
|
+
getGroupNotifications(groupKey: string, params?: PaginationParams): Promise<NotifyKitListResponse>;
|
|
347
|
+
/**
|
|
348
|
+
* List outstanding modal notifications.
|
|
349
|
+
*/
|
|
350
|
+
listModals(): Promise<readonly NotifyKitNotification[]>;
|
|
351
|
+
/**
|
|
352
|
+
* Acknowledge a modal notification.
|
|
353
|
+
*/
|
|
354
|
+
ackModal(id: string): Promise<void>;
|
|
355
|
+
/**
|
|
356
|
+
* Snooze a modal notification.
|
|
357
|
+
*/
|
|
358
|
+
snoozeModal(id: string, minutes: number): Promise<void>;
|
|
359
|
+
/**
|
|
360
|
+
* Get the current user's notification preferences.
|
|
361
|
+
*/
|
|
362
|
+
getPreferences(): Promise<NotifyKitPreferences>;
|
|
363
|
+
/**
|
|
364
|
+
* Update the current user's notification preferences.
|
|
365
|
+
*/
|
|
366
|
+
updatePreferences(preferences: NotifyKitPreferencesUpdate): Promise<void>;
|
|
367
|
+
private buildNotificationParams;
|
|
368
|
+
private request;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Create a new NotifyKit client instance.
|
|
372
|
+
*/
|
|
373
|
+
declare function createNotifyKitClient(config: NotifyKitClientConfig): NotifyKitClient;
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* useNotifyKitStore composable
|
|
377
|
+
*
|
|
378
|
+
* Provides a reactive store for NotifyKit state management.
|
|
379
|
+
* Manages notifications, unread counts, modal queue, and connection state.
|
|
380
|
+
* Uses singleton pattern to share state across components.
|
|
381
|
+
*/
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Connection state for real-time subscriptions.
|
|
385
|
+
*/
|
|
386
|
+
type ConnectionState = 'disconnected' | 'connecting' | 'connected' | 'error';
|
|
387
|
+
/**
|
|
388
|
+
* Store state shape.
|
|
389
|
+
*/
|
|
390
|
+
interface NotifyKitStoreState {
|
|
391
|
+
readonly notifications: readonly NotifyKitNotification[];
|
|
392
|
+
readonly notificationsLoading: boolean;
|
|
393
|
+
readonly notificationsMeta: PaginationMeta | null;
|
|
394
|
+
readonly unreadCount: number;
|
|
395
|
+
readonly unreadCountLoading: boolean;
|
|
396
|
+
readonly modalQueue: readonly NotifyKitNotification[];
|
|
397
|
+
readonly modalsLoading: boolean;
|
|
398
|
+
readonly broadcastChannel: string | null;
|
|
399
|
+
readonly connectionState: ConnectionState;
|
|
400
|
+
readonly lastNotificationsSync: number | null;
|
|
401
|
+
readonly lastModalsSync: number | null;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Return type of useNotifyKitStore composable.
|
|
405
|
+
*/
|
|
406
|
+
interface UseNotifyKitStoreReturn {
|
|
407
|
+
/** Readonly reactive state */
|
|
408
|
+
readonly state: NotifyKitStoreState;
|
|
409
|
+
/** Computed: whether there are unread notifications */
|
|
410
|
+
readonly hasUnread: ComputedRef<boolean>;
|
|
411
|
+
/** Computed: the current (first) modal in queue, or null */
|
|
412
|
+
readonly currentModal: ComputedRef<NotifyKitNotification | null>;
|
|
413
|
+
/** Computed: whether there are modals in the queue */
|
|
414
|
+
readonly hasModals: ComputedRef<boolean>;
|
|
415
|
+
addNotification: (notification: NotifyKitNotification) => void;
|
|
416
|
+
setNotifications: (notifications: readonly NotifyKitNotification[]) => void;
|
|
417
|
+
markNotificationRead: (id: string) => void;
|
|
418
|
+
removeNotification: (id: string) => void;
|
|
419
|
+
setUnreadCount: (count: number) => void;
|
|
420
|
+
incrementUnreadCount: () => void;
|
|
421
|
+
decrementUnreadCount: () => void;
|
|
422
|
+
enqueueModal: (notification: NotifyKitNotification) => void;
|
|
423
|
+
dequeueModal: (id: string) => void;
|
|
424
|
+
clearModalQueue: () => void;
|
|
425
|
+
setConnectionState: (state: ConnectionState) => void;
|
|
426
|
+
setBroadcastChannel: (channel: string) => void;
|
|
427
|
+
setNotificationsLoading: (loading: boolean) => void;
|
|
428
|
+
setUnreadCountLoading: (loading: boolean) => void;
|
|
429
|
+
setModalsLoading: (loading: boolean) => void;
|
|
430
|
+
setNotificationsMeta: (meta: PaginationMeta | null) => void;
|
|
431
|
+
setLastNotificationsSync: (timestamp: number | null) => void;
|
|
432
|
+
setLastModalsSync: (timestamp: number | null) => void;
|
|
433
|
+
reset: () => void;
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Injection key for the NotifyKit store.
|
|
437
|
+
*/
|
|
438
|
+
declare const NOTIFY_KIT_STORE_KEY: InjectionKey<UseNotifyKitStoreReturn>;
|
|
439
|
+
/**
|
|
440
|
+
* Resets the store state to initial values.
|
|
441
|
+
* Primarily used for testing to ensure clean state between tests.
|
|
442
|
+
*/
|
|
443
|
+
declare function resetNotifyKitStore(): void;
|
|
444
|
+
/**
|
|
445
|
+
* Provides the NotifyKit store for injection into descendant components.
|
|
446
|
+
*
|
|
447
|
+
* Call this in your app's setup or a parent component to make the store
|
|
448
|
+
* available to all child components via useNotifyKitStore().
|
|
449
|
+
*
|
|
450
|
+
* @example
|
|
451
|
+
* ```typescript
|
|
452
|
+
* // In App.vue setup
|
|
453
|
+
* const store = provideNotifyKitStore()
|
|
454
|
+
*
|
|
455
|
+
* // In any child component
|
|
456
|
+
* const { state, addNotification } = useNotifyKitStore()
|
|
457
|
+
* ```
|
|
458
|
+
*/
|
|
459
|
+
declare function provideNotifyKitStore(): UseNotifyKitStoreReturn;
|
|
460
|
+
/**
|
|
461
|
+
* Access the NotifyKit store within a Vue component.
|
|
462
|
+
*
|
|
463
|
+
* Uses a singleton pattern to share state across all components.
|
|
464
|
+
*
|
|
465
|
+
* @example
|
|
466
|
+
* ```typescript
|
|
467
|
+
* const {
|
|
468
|
+
* state,
|
|
469
|
+
* hasUnread,
|
|
470
|
+
* currentModal,
|
|
471
|
+
* addNotification,
|
|
472
|
+
* markNotificationRead
|
|
473
|
+
* } = useNotifyKitStore()
|
|
474
|
+
* ```
|
|
475
|
+
*/
|
|
476
|
+
declare function useNotifyKitStore(): UseNotifyKitStoreReturn;
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* useNotifyKitModals composable
|
|
480
|
+
*
|
|
481
|
+
* Provides modal queue management for critical notifications.
|
|
482
|
+
* Handles loading outstanding modals, acknowledgement, and snoozing.
|
|
483
|
+
*/
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Minimal NotifyKit client interface - just the modal methods.
|
|
487
|
+
*/
|
|
488
|
+
interface NotifyKitModalsClientLike {
|
|
489
|
+
listModals: () => Promise<readonly NotifyKitNotification[]>;
|
|
490
|
+
ackModal: (id: string) => Promise<void>;
|
|
491
|
+
snoozeModal: (id: string, minutes: number) => Promise<void>;
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* Configuration options for useNotifyKitModals.
|
|
495
|
+
*/
|
|
496
|
+
interface UseNotifyKitModalsOptions {
|
|
497
|
+
/**
|
|
498
|
+
* NotifyKit client instance for modal API calls.
|
|
499
|
+
*/
|
|
500
|
+
client: NotifyKitModalsClientLike;
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Return type of useNotifyKitModals composable.
|
|
504
|
+
*/
|
|
505
|
+
interface UseNotifyKitModalsReturn {
|
|
506
|
+
/** The current (first) modal in queue, or null */
|
|
507
|
+
readonly currentModal: ComputedRef<NotifyKitNotification | null>;
|
|
508
|
+
/** All modals in the queue */
|
|
509
|
+
readonly modalQueue: ComputedRef<readonly NotifyKitNotification[]>;
|
|
510
|
+
/** Whether there are modals in the queue */
|
|
511
|
+
readonly hasModals: ComputedRef<boolean>;
|
|
512
|
+
/** Whether modals are currently being loaded */
|
|
513
|
+
readonly isLoading: Ref<boolean>;
|
|
514
|
+
/** Load outstanding modals from the API */
|
|
515
|
+
loadOutstandingModals: () => Promise<void>;
|
|
516
|
+
/** Acknowledge a modal (removes from queue) */
|
|
517
|
+
ack: (id: string) => Promise<void>;
|
|
518
|
+
/** Snooze a modal (removes from queue temporarily) */
|
|
519
|
+
snooze: (id: string, minutes: number) => Promise<void>;
|
|
520
|
+
/** Acknowledge the current modal */
|
|
521
|
+
dismissCurrent: () => Promise<void>;
|
|
522
|
+
/** Snooze the current modal */
|
|
523
|
+
snoozeCurrent: (minutes: number) => Promise<void>;
|
|
524
|
+
/** Get allowed snooze options for a notification */
|
|
525
|
+
getSnoozeOptions: (notification: NotifyKitNotification) => readonly number[];
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Error thrown when an invalid snooze duration is provided.
|
|
529
|
+
*/
|
|
530
|
+
declare class InvalidSnoozeDurationError extends Error {
|
|
531
|
+
readonly name = "InvalidSnoozeDurationError";
|
|
532
|
+
constructor(minutes: number, allowedMinutes: readonly number[]);
|
|
533
|
+
}
|
|
534
|
+
/**
|
|
535
|
+
* Injection key for the NotifyKit modals composable.
|
|
536
|
+
*/
|
|
537
|
+
declare const NOTIFY_KIT_MODALS_KEY: InjectionKey<UseNotifyKitModalsReturn>;
|
|
538
|
+
/**
|
|
539
|
+
* Provides NotifyKit modals management for injection into descendant components.
|
|
540
|
+
*
|
|
541
|
+
* @example
|
|
542
|
+
* ```typescript
|
|
543
|
+
* // In App.vue setup
|
|
544
|
+
* const modals = provideNotifyKitModals({ client })
|
|
545
|
+
*
|
|
546
|
+
* // In any child component
|
|
547
|
+
* const { currentModal, dismissCurrent } = useNotifyKitModals({ client })
|
|
548
|
+
* ```
|
|
549
|
+
*/
|
|
550
|
+
declare function provideNotifyKitModals(options: UseNotifyKitModalsOptions): UseNotifyKitModalsReturn;
|
|
551
|
+
/**
|
|
552
|
+
* Composable for managing modal notification queue.
|
|
553
|
+
*
|
|
554
|
+
* Handles loading outstanding modals from the API, acknowledging them,
|
|
555
|
+
* and snoozing them. Uses the store for reactive queue management.
|
|
556
|
+
*
|
|
557
|
+
* @example
|
|
558
|
+
* ```typescript
|
|
559
|
+
* const {
|
|
560
|
+
* currentModal,
|
|
561
|
+
* hasModals,
|
|
562
|
+
* loadOutstandingModals,
|
|
563
|
+
* dismissCurrent,
|
|
564
|
+
* snoozeCurrent,
|
|
565
|
+
* getSnoozeOptions
|
|
566
|
+
* } = useNotifyKitModals({ client })
|
|
567
|
+
*
|
|
568
|
+
* // Load modals on login
|
|
569
|
+
* await loadOutstandingModals()
|
|
570
|
+
*
|
|
571
|
+
* // Handle current modal
|
|
572
|
+
* if (currentModal.value) {
|
|
573
|
+
* const options = getSnoozeOptions(currentModal.value)
|
|
574
|
+
* // Show modal with snooze options...
|
|
575
|
+
* }
|
|
576
|
+
*
|
|
577
|
+
* // User acknowledges
|
|
578
|
+
* await dismissCurrent()
|
|
579
|
+
*
|
|
580
|
+
* // Or user snoozes for 1 hour
|
|
581
|
+
* await snoozeCurrent(60)
|
|
582
|
+
* ```
|
|
583
|
+
*/
|
|
584
|
+
declare function useNotifyKitModals(options: UseNotifyKitModalsOptions): UseNotifyKitModalsReturn;
|
|
585
|
+
|
|
586
|
+
export { createNotifyKitClient as A, isChannelPreferences as B, type ConnectionState as C, isMeResponse as D, isModalEnabled as E, isModalSpec as F, isNotifyKitNotification as G, isPaginationMeta as H, InvalidSnoozeDurationError as I, isUnreadCountResponse as J, isValidCategory as K, type ListNotificationsParams as L, isValidLevel as M, NotifyKitClient as N, provideNotifyKitModals as O, type PaginationParams as P, provideNotifyKitStore as Q, resetNotifyKitStore as R, useNotifyKitModals as S, useNotifyKitStore as T, type UseNotifyKitModalsOptions as U, type NotifyKitMeResponse as a, type NotifyKitListResponse as b, type NotifyKitUnreadCountResponse as c, type NotifyKitNotification as d, type NotifyKitPreferences as e, type NotifyKitPreferencesUpdate as f, type NotifyKitClientConfig as g, type NotificationCategory as h, type NotificationLevel as i, type ChannelPreferences as j, NOTIFICATION_CATEGORIES as k, NOTIFICATION_LEVELS as l, NOTIFY_KIT_MODALS_KEY as m, NOTIFY_KIT_STORE_KEY as n, NotifyKitApiError as o, type NotifyKitErrorResponse as p, type NotifyKitGroupedEntry as q, type NotifyKitGroupedListResponse as r, type NotifyKitModalSpec as s, type NotifyKitModalState as t, type NotifyKitModalsClientLike as u, type NotifyKitModalsResponse as v, type NotifyKitStoreState as w, type PaginationMeta as x, type UseNotifyKitModalsReturn as y, type UseNotifyKitStoreReturn as z };
|
package/package.json
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@codingfactory/notify-kit-client",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Headless Vue 3/Nuxt client for Notify Kit notifications",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
},
|
|
14
|
+
"./nuxt": {
|
|
15
|
+
"import": "./dist/nuxt/index.js",
|
|
16
|
+
"types": "./dist/nuxt/index.d.ts"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"generate:types": "npx tsx ../../scripts/generate-types.ts",
|
|
24
|
+
"dev": "tsup --watch",
|
|
25
|
+
"prebuild": "npm run generate:types",
|
|
26
|
+
"build": "tsup",
|
|
27
|
+
"typecheck": "tsc --noEmit",
|
|
28
|
+
"lint": "eslint src tests",
|
|
29
|
+
"test": "vitest run",
|
|
30
|
+
"test:watch": "vitest",
|
|
31
|
+
"check": "npm run typecheck && npm run lint && npm run test && npm run build"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"nuxt": "^3.0.0",
|
|
35
|
+
"vue": "^3.4.0"
|
|
36
|
+
},
|
|
37
|
+
"peerDependenciesMeta": {
|
|
38
|
+
"nuxt": {
|
|
39
|
+
"optional": true
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@eslint/js": "^9.39.2",
|
|
44
|
+
"@nuxt/kit": "^3.0.0",
|
|
45
|
+
"@nuxt/schema": "^3.0.0",
|
|
46
|
+
"@types/node": "^22.0.0",
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
48
|
+
"@typescript-eslint/parser": "^8.0.0",
|
|
49
|
+
"@vitest/coverage-v8": "^2.1.9",
|
|
50
|
+
"@vue/test-utils": "^2.4.0",
|
|
51
|
+
"eslint": "^9.0.0",
|
|
52
|
+
"happy-dom": "^15.0.0",
|
|
53
|
+
"tsup": "^8.0.0",
|
|
54
|
+
"typescript": "^5.0.0",
|
|
55
|
+
"typescript-eslint": "^8.54.0",
|
|
56
|
+
"vitest": "^2.0.0",
|
|
57
|
+
"vue": "^3.4.0"
|
|
58
|
+
},
|
|
59
|
+
"keywords": [
|
|
60
|
+
"vue",
|
|
61
|
+
"nuxt",
|
|
62
|
+
"notifications",
|
|
63
|
+
"laravel",
|
|
64
|
+
"real-time",
|
|
65
|
+
"composables"
|
|
66
|
+
],
|
|
67
|
+
"author": "Coding Factory",
|
|
68
|
+
"license": "MIT",
|
|
69
|
+
"repository": {
|
|
70
|
+
"type": "git",
|
|
71
|
+
"url": "https://github.com/coding-factory/notify-kit.git",
|
|
72
|
+
"directory": "packages/notify-kit-client"
|
|
73
|
+
},
|
|
74
|
+
"publishConfig": {
|
|
75
|
+
"access": "restricted"
|
|
76
|
+
}
|
|
77
|
+
}
|