90dc-core 1.10.2 → 1.10.4
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/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/utils/NotificationClient.d.ts +247 -0
- package/dist/lib/utils/NotificationClient.d.ts.map +1 -0
- package/dist/lib/utils/NotificationClient.js +349 -0
- package/dist/lib/utils/NotificationClient.js.map +1 -0
- package/dist/lib/utils/NotificationsUtil.d.ts +4 -13
- package/dist/lib/utils/NotificationsUtil.d.ts.map +1 -1
- package/dist/lib/utils/NotificationsUtil.js +23 -13
- package/dist/lib/utils/NotificationsUtil.js.map +1 -1
- package/package.json +2 -1
- package/src/index.ts +2 -0
- package/src/lib/utils/NotificationClient.ts +513 -0
- package/src/lib/utils/NotificationsUtil.ts +26 -16
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ export * from "./lib/models/ProgramInterfaces";
|
|
|
2
2
|
export * from "./lib/models/ExerciseInterfaces";
|
|
3
3
|
export * from "./lib/models/WorkoutInterfaces";
|
|
4
4
|
export * from "./lib/models/UserInterfaces";
|
|
5
|
+
export * from "./lib/models/NotificationInterfaces";
|
|
5
6
|
export * from "./lib/dbmodels/UsersFriends";
|
|
6
7
|
export * from "./lib/dbmodels/PersistedUser";
|
|
7
8
|
export * from "./lib/dbmodels/UserBadges";
|
|
@@ -21,4 +22,5 @@ export * from "./lib/dbmodels/nonconsprogram/UserNonConsumableProgram";
|
|
|
21
22
|
export * from "./lib/utils/Logger";
|
|
22
23
|
export { AuthenticationUtil } from "./lib/utils/AuthenticationUtil";
|
|
23
24
|
export { NotificationsUtil } from "./lib/utils/NotificationsUtil";
|
|
25
|
+
export { NotificationClient } from "./lib/utils/NotificationClient";
|
|
24
26
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,gCAAgC,CAAC;AAC/C,cAAc,iCAAiC,CAAC;AAChD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,gCAAgC,CAAC;AAC/C,cAAc,iCAAiC,CAAC;AAChD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,qCAAqC,CAAC;AAGpD,cAAc,6BAA6B,CAAA;AAC3C,cAAc,8BAA8B,CAAA;AAC5C,cAAc,2BAA2B,CAAA;AACzC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,sBAAsB,CAAA;AACpC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,gCAAgC,CAAA;AAC9C,cAAc,iCAAiC,CAAA;AAC/C,cAAc,iCAAiC,CAAA;AAC/C,cAAc,6BAA6B,CAAA;AAC3C,cAAc,gCAAgC,CAAA;AAC9C,cAAc,oDAAoD,CAAA;AAClE,cAAc,wEAAwE,CAAA;AACtF,cAAc,2DAA2D,CAAA;AACzE,cAAc,8DAA8D,CAAA;AAC5E,cAAc,wDAAwD,CAAA;AAItE,cAAc,oBAAoB,CAAA;AAClC,OAAO,EAAC,kBAAkB,EAAC,MAAM,gCAAgC,CAAA;AACjE,OAAO,EAAC,iBAAiB,EAAC,MAAM,+BAA+B,CAAA;AAC/D,OAAO,EAAC,kBAAkB,EAAC,MAAM,gCAAgC,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export * from "./lib/models/ProgramInterfaces";
|
|
|
3
3
|
export * from "./lib/models/ExerciseInterfaces";
|
|
4
4
|
export * from "./lib/models/WorkoutInterfaces";
|
|
5
5
|
export * from "./lib/models/UserInterfaces";
|
|
6
|
+
export * from "./lib/models/NotificationInterfaces";
|
|
6
7
|
//DB Models
|
|
7
8
|
export * from "./lib/dbmodels/UsersFriends";
|
|
8
9
|
export * from "./lib/dbmodels/PersistedUser";
|
|
@@ -24,5 +25,6 @@ export * from "./lib/dbmodels/nonconsprogram/UserNonConsumableProgram";
|
|
|
24
25
|
export * from "./lib/utils/Logger";
|
|
25
26
|
export { AuthenticationUtil } from "./lib/utils/AuthenticationUtil";
|
|
26
27
|
export { NotificationsUtil } from "./lib/utils/NotificationsUtil";
|
|
28
|
+
export { NotificationClient } from "./lib/utils/NotificationClient";
|
|
27
29
|
|
|
28
30
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["//Interfaces\nexport * from \"./lib/models/ProgramInterfaces\";\nexport * from \"./lib/models/ExerciseInterfaces\";\nexport * from \"./lib/models/WorkoutInterfaces\";\nexport * from \"./lib/models/UserInterfaces\";\n\n//DB Models\nexport * from \"./lib/dbmodels/UsersFriends\"\nexport * from \"./lib/dbmodels/PersistedUser\"\nexport * from \"./lib/dbmodels/UserBadges\"\nexport * from \"./lib/dbmodels/UserStreaks\"\nexport * from \"./lib/dbmodels/Badge\"\nexport * from \"./lib/dbmodels/program/Program\"\nexport * from \"./lib/dbmodels/program/Workout\"\nexport * from \"./lib/dbmodels/program/Exercise\"\nexport * from \"./lib/dbmodels/program/Superset\"\nexport * from \"./lib/dbmodels/Subscription\"\nexport * from \"./lib/dbmodels/SubscriptionLog\"\nexport * from \"./lib/dbmodels/nonconsprogram/NonConsumableProgram\"\nexport * from \"./lib/dbmodels/nonconsprogram/TranslatedNonConsumableProgramWebContent\"\nexport * from \"./lib/dbmodels/nonconsprogram/TranslatedConsumableProgram\"\nexport * from \"./lib/dbmodels/nonconsprogram/NonConsumableProgramWebContent\"\nexport * from \"./lib/dbmodels/nonconsprogram/UserNonConsumableProgram\"\n\n\n//Utils\nexport * from \"./lib/utils/Logger\"\nexport {AuthenticationUtil} from \"./lib/utils/AuthenticationUtil\"\nexport {NotificationsUtil} from \"./lib/utils/NotificationsUtil\"\n"],"names":["AuthenticationUtil","NotificationsUtil"],"mappings":"AAAA,YAAY;AACZ,cAAc,iCAAiC;AAC/C,cAAc,kCAAkC;AAChD,cAAc,iCAAiC;AAC/C,cAAc,8BAA8B;
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["//Interfaces\nexport * from \"./lib/models/ProgramInterfaces\";\nexport * from \"./lib/models/ExerciseInterfaces\";\nexport * from \"./lib/models/WorkoutInterfaces\";\nexport * from \"./lib/models/UserInterfaces\";\nexport * from \"./lib/models/NotificationInterfaces\";\n\n//DB Models\nexport * from \"./lib/dbmodels/UsersFriends\"\nexport * from \"./lib/dbmodels/PersistedUser\"\nexport * from \"./lib/dbmodels/UserBadges\"\nexport * from \"./lib/dbmodels/UserStreaks\"\nexport * from \"./lib/dbmodels/Badge\"\nexport * from \"./lib/dbmodels/program/Program\"\nexport * from \"./lib/dbmodels/program/Workout\"\nexport * from \"./lib/dbmodels/program/Exercise\"\nexport * from \"./lib/dbmodels/program/Superset\"\nexport * from \"./lib/dbmodels/Subscription\"\nexport * from \"./lib/dbmodels/SubscriptionLog\"\nexport * from \"./lib/dbmodels/nonconsprogram/NonConsumableProgram\"\nexport * from \"./lib/dbmodels/nonconsprogram/TranslatedNonConsumableProgramWebContent\"\nexport * from \"./lib/dbmodels/nonconsprogram/TranslatedConsumableProgram\"\nexport * from \"./lib/dbmodels/nonconsprogram/NonConsumableProgramWebContent\"\nexport * from \"./lib/dbmodels/nonconsprogram/UserNonConsumableProgram\"\n\n\n//Utils\nexport * from \"./lib/utils/Logger\"\nexport {AuthenticationUtil} from \"./lib/utils/AuthenticationUtil\"\nexport {NotificationsUtil} from \"./lib/utils/NotificationsUtil\"\nexport {NotificationClient} from \"./lib/utils/NotificationClient\"\n"],"names":["AuthenticationUtil","NotificationsUtil","NotificationClient"],"mappings":"AAAA,YAAY;AACZ,cAAc,iCAAiC;AAC/C,cAAc,kCAAkC;AAChD,cAAc,iCAAiC;AAC/C,cAAc,8BAA8B;AAC5C,cAAc,sCAAsC;AAEpD,WAAW;AACX,cAAc,8BAA6B;AAC3C,cAAc,+BAA8B;AAC5C,cAAc,4BAA2B;AACzC,cAAc,6BAA4B;AAC1C,cAAc,uBAAsB;AACpC,cAAc,iCAAgC;AAC9C,cAAc,iCAAgC;AAC9C,cAAc,kCAAiC;AAC/C,cAAc,kCAAiC;AAC/C,cAAc,8BAA6B;AAC3C,cAAc,iCAAgC;AAC9C,cAAc,qDAAoD;AAClE,cAAc,yEAAwE;AACtF,cAAc,4DAA2D;AACzE,cAAc,+DAA8D;AAC5E,cAAc,yDAAwD;AAGtE,OAAO;AACP,cAAc,qBAAoB;AAClC,SAAQA,kBAAkB,QAAO,iCAAgC;AACjE,SAAQC,iBAAiB,QAAO,gCAA+B;AAC/D,SAAQC,kBAAkB,QAAO,iCAAgC"}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import type { NotificationPayload, EmailReminderPayload, GroupNotificationRequest, NotificationRequest, CreateNotificationRequest, NotificationTranslationRequest } from "../models/NotificationInterfaces";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration for the notification client
|
|
4
|
+
*/
|
|
5
|
+
export interface NotificationClientConfig {
|
|
6
|
+
baseURL: string;
|
|
7
|
+
timeout?: number;
|
|
8
|
+
headers?: Record<string, string>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Abandoned cart notification payload
|
|
12
|
+
*/
|
|
13
|
+
export interface AbandonedCartPayload {
|
|
14
|
+
email: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Password restoration types
|
|
18
|
+
*/
|
|
19
|
+
export type PasswordRestorationType = "change" | "reset" | "platform-reset";
|
|
20
|
+
/**
|
|
21
|
+
* Password restoration request
|
|
22
|
+
*/
|
|
23
|
+
export interface PasswordRestorationRequest {
|
|
24
|
+
email: string;
|
|
25
|
+
type: PasswordRestorationType;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Email confirmation request
|
|
29
|
+
*/
|
|
30
|
+
export interface EmailConfirmationRequest {
|
|
31
|
+
type: "main" | "utility";
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Shopify email request
|
|
35
|
+
*/
|
|
36
|
+
export interface ShopifyEmailRequest {
|
|
37
|
+
email: string;
|
|
38
|
+
name: string;
|
|
39
|
+
orderNumber: string;
|
|
40
|
+
items: Array<{
|
|
41
|
+
name: string;
|
|
42
|
+
quantity: number;
|
|
43
|
+
price: number;
|
|
44
|
+
}>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Challenge friend email request
|
|
48
|
+
*/
|
|
49
|
+
export interface ChallengeFriendRequest {
|
|
50
|
+
friendsEmail: string;
|
|
51
|
+
name: string;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* NotificationClient
|
|
55
|
+
*
|
|
56
|
+
* Provides methods to interact with the notification service via HTTP API.
|
|
57
|
+
* This allows services to send notifications without direct database access
|
|
58
|
+
* or code duplication.
|
|
59
|
+
*/
|
|
60
|
+
export declare class NotificationClient {
|
|
61
|
+
private client;
|
|
62
|
+
/**
|
|
63
|
+
* Create a new notification client
|
|
64
|
+
*
|
|
65
|
+
* @param config - Client configuration with base URL and optional settings
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* const notificationClient = new NotificationClient({
|
|
70
|
+
* baseURL: 'http://localhost:3037',
|
|
71
|
+
* timeout: 5000
|
|
72
|
+
* });
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
constructor(config: NotificationClientConfig);
|
|
76
|
+
/**
|
|
77
|
+
* Schedule a push notification for a specific user
|
|
78
|
+
*
|
|
79
|
+
* @param payload - Notification details including user UUID and notification type
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* await client.scheduleNotification({
|
|
84
|
+
* userUuid: '123e4567-e89b-12d3-a456-426614174000',
|
|
85
|
+
* name: 'workout_reminder'
|
|
86
|
+
* });
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
scheduleNotification(payload: NotificationPayload): Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Send immediate notification to a specific user
|
|
92
|
+
*
|
|
93
|
+
* @param userUuid - User UUID
|
|
94
|
+
* @param notification - Notification content
|
|
95
|
+
* @returns Message ID from Firebase
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* const messageId = await client.sendToUser('user-uuid', {
|
|
100
|
+
* title: 'Workout Reminder',
|
|
101
|
+
* body: 'Time for your daily workout!',
|
|
102
|
+
* redirectPath: '/workout'
|
|
103
|
+
* });
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
sendToUser(userUuid: string, notification: NotificationRequest): Promise<string>;
|
|
107
|
+
/**
|
|
108
|
+
* Send notification to multiple users in batch
|
|
109
|
+
*
|
|
110
|
+
* @param userUuids - Array of user UUIDs
|
|
111
|
+
* @param notification - Notification content
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* await client.sendToUsers(['uuid1', 'uuid2'], {
|
|
116
|
+
* title: 'New Feature',
|
|
117
|
+
* body: 'Check out what's new!'
|
|
118
|
+
* });
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
sendToUsers(userUuids: string[], notification: NotificationRequest): Promise<void>;
|
|
122
|
+
/**
|
|
123
|
+
* Send notification to all users
|
|
124
|
+
*
|
|
125
|
+
* @param notification - Notification content
|
|
126
|
+
* @returns Total number of users notified
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* const totalSent = await client.sendToAllUsers({
|
|
131
|
+
* title: 'System Update',
|
|
132
|
+
* body: 'App will be updated soon'
|
|
133
|
+
* });
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
sendToAllUsers(notification: NotificationRequest): Promise<number>;
|
|
137
|
+
/**
|
|
138
|
+
* Send a push notification to a specific group of users
|
|
139
|
+
*
|
|
140
|
+
* @param request - Group notification request with target group and message
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```typescript
|
|
144
|
+
* await client.sendGroupNotification({
|
|
145
|
+
* group: NotificationGroups.PREMIUM,
|
|
146
|
+
* notification: {
|
|
147
|
+
* title: 'New Feature!',
|
|
148
|
+
* body: 'Check out our new workout plans'
|
|
149
|
+
* }
|
|
150
|
+
* });
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
sendGroupNotification(request: GroupNotificationRequest): Promise<void>;
|
|
154
|
+
/**
|
|
155
|
+
* Schedule an email checkout reminder
|
|
156
|
+
*
|
|
157
|
+
* @param payload - Email reminder details
|
|
158
|
+
*/
|
|
159
|
+
scheduleEmailReminder(payload: EmailReminderPayload): Promise<void>;
|
|
160
|
+
/**
|
|
161
|
+
* Send abandoned cart notification
|
|
162
|
+
*
|
|
163
|
+
* @param payload - Abandoned cart details with user email
|
|
164
|
+
*/
|
|
165
|
+
sendAbandonedCart(payload: AbandonedCartPayload): Promise<void>;
|
|
166
|
+
/**
|
|
167
|
+
* Send password restoration email
|
|
168
|
+
*
|
|
169
|
+
* @param request - Password restoration request
|
|
170
|
+
*/
|
|
171
|
+
sendPasswordRestoration(request: PasswordRestorationRequest): Promise<void>;
|
|
172
|
+
/**
|
|
173
|
+
* Send email confirmation
|
|
174
|
+
*
|
|
175
|
+
* @param request - Email confirmation request
|
|
176
|
+
* @param authToken - User authentication token (required)
|
|
177
|
+
*/
|
|
178
|
+
sendEmailConfirmation(request: EmailConfirmationRequest, authToken: string): Promise<void>;
|
|
179
|
+
/**
|
|
180
|
+
* Send Shopify email
|
|
181
|
+
*
|
|
182
|
+
* @param request - Shopify email details
|
|
183
|
+
*/
|
|
184
|
+
sendShopifyEmail(request: ShopifyEmailRequest): Promise<void>;
|
|
185
|
+
/**
|
|
186
|
+
* Send challenge friend invitation email
|
|
187
|
+
*
|
|
188
|
+
* @param request - Challenge friend request
|
|
189
|
+
*/
|
|
190
|
+
sendChallengeFriendEmail(request: ChallengeFriendRequest): Promise<void>;
|
|
191
|
+
/**
|
|
192
|
+
* Send account deletion email
|
|
193
|
+
*
|
|
194
|
+
* @param authToken - User authentication token (required)
|
|
195
|
+
*/
|
|
196
|
+
sendDeleteAccountEmail(authToken: string): Promise<void>;
|
|
197
|
+
/**
|
|
198
|
+
* Send export finished email
|
|
199
|
+
*
|
|
200
|
+
* @param authToken - User authentication token (required)
|
|
201
|
+
*/
|
|
202
|
+
sendExportFinishedEmail(authToken: string): Promise<void>;
|
|
203
|
+
/**
|
|
204
|
+
* Create a new notification template
|
|
205
|
+
*
|
|
206
|
+
* @param request - Notification template details
|
|
207
|
+
* @returns The created notification UUID
|
|
208
|
+
*/
|
|
209
|
+
createNotification(request: CreateNotificationRequest): Promise<string>;
|
|
210
|
+
/**
|
|
211
|
+
* Create a notification translation
|
|
212
|
+
*
|
|
213
|
+
* @param request - Translation details
|
|
214
|
+
*/
|
|
215
|
+
createNotificationTranslation(request: NotificationTranslationRequest): Promise<void>;
|
|
216
|
+
/**
|
|
217
|
+
* Update a notification template
|
|
218
|
+
*
|
|
219
|
+
* @param request - Updated notification details
|
|
220
|
+
*/
|
|
221
|
+
updateNotification(request: NotificationTranslationRequest): Promise<void>;
|
|
222
|
+
/**
|
|
223
|
+
* Update a notification translation
|
|
224
|
+
*
|
|
225
|
+
* @param request - Updated translation details
|
|
226
|
+
*/
|
|
227
|
+
updateNotificationTranslation(request: NotificationTranslationRequest): Promise<void>;
|
|
228
|
+
/**
|
|
229
|
+
* Get all notifications, optionally filtered by language
|
|
230
|
+
*
|
|
231
|
+
* @param language - Optional language code to filter translations
|
|
232
|
+
* @returns Array of notifications with translations
|
|
233
|
+
*/
|
|
234
|
+
getNotifications(language?: string): Promise<any[]>;
|
|
235
|
+
/**
|
|
236
|
+
* Delete a notification or translation
|
|
237
|
+
*
|
|
238
|
+
* @param uuid - Notification UUID
|
|
239
|
+
* @param language - Optional language code to delete only translation
|
|
240
|
+
*/
|
|
241
|
+
deleteNotification(uuid: string, language?: string): Promise<void>;
|
|
242
|
+
/**
|
|
243
|
+
* Handle and format errors from notification service
|
|
244
|
+
*/
|
|
245
|
+
private handleError;
|
|
246
|
+
}
|
|
247
|
+
//# sourceMappingURL=NotificationClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NotificationClient.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/NotificationClient.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
/**
|
|
3
|
+
* NotificationClient
|
|
4
|
+
*
|
|
5
|
+
* Provides methods to interact with the notification service via HTTP API.
|
|
6
|
+
* This allows services to send notifications without direct database access
|
|
7
|
+
* or code duplication.
|
|
8
|
+
*/ export class NotificationClient {
|
|
9
|
+
/**
|
|
10
|
+
* Create a new notification client
|
|
11
|
+
*
|
|
12
|
+
* @param config - Client configuration with base URL and optional settings
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const notificationClient = new NotificationClient({
|
|
17
|
+
* baseURL: 'http://localhost:3037',
|
|
18
|
+
* timeout: 5000
|
|
19
|
+
* });
|
|
20
|
+
* ```
|
|
21
|
+
*/ constructor(config){
|
|
22
|
+
this.client = axios.create({
|
|
23
|
+
baseURL: config.baseURL,
|
|
24
|
+
timeout: config.timeout || 10000,
|
|
25
|
+
headers: {
|
|
26
|
+
"Content-Type": "application/json",
|
|
27
|
+
...config.headers
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
// ==================== Push Notification Methods ====================
|
|
32
|
+
/**
|
|
33
|
+
* Schedule a push notification for a specific user
|
|
34
|
+
*
|
|
35
|
+
* @param payload - Notification details including user UUID and notification type
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* await client.scheduleNotification({
|
|
40
|
+
* userUuid: '123e4567-e89b-12d3-a456-426614174000',
|
|
41
|
+
* name: 'workout_reminder'
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/ async scheduleNotification(payload) {
|
|
45
|
+
try {
|
|
46
|
+
await this.client.post("/notifications/save-job", payload);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
this.handleError("Failed to schedule notification", error);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Send immediate notification to a specific user
|
|
53
|
+
*
|
|
54
|
+
* @param userUuid - User UUID
|
|
55
|
+
* @param notification - Notification content
|
|
56
|
+
* @returns Message ID from Firebase
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* const messageId = await client.sendToUser('user-uuid', {
|
|
61
|
+
* title: 'Workout Reminder',
|
|
62
|
+
* body: 'Time for your daily workout!',
|
|
63
|
+
* redirectPath: '/workout'
|
|
64
|
+
* });
|
|
65
|
+
* ```
|
|
66
|
+
*/ async sendToUser(userUuid, notification) {
|
|
67
|
+
try {
|
|
68
|
+
const response = await this.client.post("/notifications/send-to-user", {
|
|
69
|
+
userUuid,
|
|
70
|
+
notification
|
|
71
|
+
});
|
|
72
|
+
return response.data.messageId;
|
|
73
|
+
} catch (error) {
|
|
74
|
+
this.handleError("Failed to send notification to user", error);
|
|
75
|
+
throw error;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Send notification to multiple users in batch
|
|
80
|
+
*
|
|
81
|
+
* @param userUuids - Array of user UUIDs
|
|
82
|
+
* @param notification - Notification content
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* await client.sendToUsers(['uuid1', 'uuid2'], {
|
|
87
|
+
* title: 'New Feature',
|
|
88
|
+
* body: 'Check out what's new!'
|
|
89
|
+
* });
|
|
90
|
+
* ```
|
|
91
|
+
*/ async sendToUsers(userUuids, notification) {
|
|
92
|
+
try {
|
|
93
|
+
await this.client.post("/notifications/send-to-users", {
|
|
94
|
+
userUuids,
|
|
95
|
+
notification
|
|
96
|
+
});
|
|
97
|
+
} catch (error) {
|
|
98
|
+
this.handleError("Failed to send batch notification", error);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Send notification to all users
|
|
103
|
+
*
|
|
104
|
+
* @param notification - Notification content
|
|
105
|
+
* @returns Total number of users notified
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* const totalSent = await client.sendToAllUsers({
|
|
110
|
+
* title: 'System Update',
|
|
111
|
+
* body: 'App will be updated soon'
|
|
112
|
+
* });
|
|
113
|
+
* ```
|
|
114
|
+
*/ async sendToAllUsers(notification) {
|
|
115
|
+
try {
|
|
116
|
+
const response = await this.client.post("/notifications/send-to-all", {
|
|
117
|
+
notification
|
|
118
|
+
});
|
|
119
|
+
return response.data.totalSent;
|
|
120
|
+
} catch (error) {
|
|
121
|
+
this.handleError("Failed to send to all users", error);
|
|
122
|
+
throw error;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Send a push notification to a specific group of users
|
|
127
|
+
*
|
|
128
|
+
* @param request - Group notification request with target group and message
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* await client.sendGroupNotification({
|
|
133
|
+
* group: NotificationGroups.PREMIUM,
|
|
134
|
+
* notification: {
|
|
135
|
+
* title: 'New Feature!',
|
|
136
|
+
* body: 'Check out our new workout plans'
|
|
137
|
+
* }
|
|
138
|
+
* });
|
|
139
|
+
* ```
|
|
140
|
+
*/ async sendGroupNotification(request) {
|
|
141
|
+
try {
|
|
142
|
+
await this.client.post("/notifications/send-group", request);
|
|
143
|
+
} catch (error) {
|
|
144
|
+
this.handleError("Failed to send group notification", error);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
// ==================== Email Methods ====================
|
|
148
|
+
/**
|
|
149
|
+
* Schedule an email checkout reminder
|
|
150
|
+
*
|
|
151
|
+
* @param payload - Email reminder details
|
|
152
|
+
*/ async scheduleEmailReminder(payload) {
|
|
153
|
+
try {
|
|
154
|
+
await this.client.post("/notifications/save-email-checkout-reminder", payload);
|
|
155
|
+
} catch (error) {
|
|
156
|
+
this.handleError("Failed to schedule email reminder", error);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Send abandoned cart notification
|
|
161
|
+
*
|
|
162
|
+
* @param payload - Abandoned cart details with user email
|
|
163
|
+
*/ async sendAbandonedCart(payload) {
|
|
164
|
+
try {
|
|
165
|
+
await this.client.post("/notifications/abandoned-cart", payload);
|
|
166
|
+
} catch (error) {
|
|
167
|
+
this.handleError("Failed to send abandoned cart notification", error);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Send password restoration email
|
|
172
|
+
*
|
|
173
|
+
* @param request - Password restoration request
|
|
174
|
+
*/ async sendPasswordRestoration(request) {
|
|
175
|
+
try {
|
|
176
|
+
await this.client.post("/mail/send-password-restoration", request);
|
|
177
|
+
} catch (error) {
|
|
178
|
+
this.handleError("Failed to send password restoration email", error);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Send email confirmation
|
|
183
|
+
*
|
|
184
|
+
* @param request - Email confirmation request
|
|
185
|
+
* @param authToken - User authentication token (required)
|
|
186
|
+
*/ async sendEmailConfirmation(request, authToken) {
|
|
187
|
+
try {
|
|
188
|
+
await this.client.post("/mail/send-confirmation", request, {
|
|
189
|
+
headers: {
|
|
190
|
+
Authorization: `Bearer ${authToken}`
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
} catch (error) {
|
|
194
|
+
this.handleError("Failed to send email confirmation", error);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Send Shopify email
|
|
199
|
+
*
|
|
200
|
+
* @param request - Shopify email details
|
|
201
|
+
*/ async sendShopifyEmail(request) {
|
|
202
|
+
try {
|
|
203
|
+
await this.client.post("/mail/send-shopify-email", request);
|
|
204
|
+
} catch (error) {
|
|
205
|
+
this.handleError("Failed to send Shopify email", error);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Send challenge friend invitation email
|
|
210
|
+
*
|
|
211
|
+
* @param request - Challenge friend request
|
|
212
|
+
*/ async sendChallengeFriendEmail(request) {
|
|
213
|
+
try {
|
|
214
|
+
await this.client.post("/mail/send-challenge-email", request);
|
|
215
|
+
} catch (error) {
|
|
216
|
+
this.handleError("Failed to send challenge email", error);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Send account deletion email
|
|
221
|
+
*
|
|
222
|
+
* @param authToken - User authentication token (required)
|
|
223
|
+
*/ async sendDeleteAccountEmail(authToken) {
|
|
224
|
+
try {
|
|
225
|
+
await this.client.post("/mail/send-delete-email", {}, {
|
|
226
|
+
headers: {
|
|
227
|
+
Authorization: `Bearer ${authToken}`
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
} catch (error) {
|
|
231
|
+
this.handleError("Failed to send delete account email", error);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Send export finished email
|
|
236
|
+
*
|
|
237
|
+
* @param authToken - User authentication token (required)
|
|
238
|
+
*/ async sendExportFinishedEmail(authToken) {
|
|
239
|
+
try {
|
|
240
|
+
await this.client.post("/mail/send-export-finished-email", {}, {
|
|
241
|
+
headers: {
|
|
242
|
+
Authorization: `Bearer ${authToken}`
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
} catch (error) {
|
|
246
|
+
this.handleError("Failed to send export finished email", error);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
// ==================== Notification Management Methods ====================
|
|
250
|
+
/**
|
|
251
|
+
* Create a new notification template
|
|
252
|
+
*
|
|
253
|
+
* @param request - Notification template details
|
|
254
|
+
* @returns The created notification UUID
|
|
255
|
+
*/ async createNotification(request) {
|
|
256
|
+
try {
|
|
257
|
+
const response = await this.client.post("/notifications/create-notification", request);
|
|
258
|
+
return response.data.uuid;
|
|
259
|
+
} catch (error) {
|
|
260
|
+
this.handleError("Failed to create notification", error);
|
|
261
|
+
throw error;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Create a notification translation
|
|
266
|
+
*
|
|
267
|
+
* @param request - Translation details
|
|
268
|
+
*/ async createNotificationTranslation(request) {
|
|
269
|
+
try {
|
|
270
|
+
await this.client.post("/notifications/create-notification-translation", request);
|
|
271
|
+
} catch (error) {
|
|
272
|
+
this.handleError("Failed to create notification translation", error);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Update a notification template
|
|
277
|
+
*
|
|
278
|
+
* @param request - Updated notification details
|
|
279
|
+
*/ async updateNotification(request) {
|
|
280
|
+
try {
|
|
281
|
+
await this.client.put("/notifications/update-notification", request);
|
|
282
|
+
} catch (error) {
|
|
283
|
+
this.handleError("Failed to update notification", error);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Update a notification translation
|
|
288
|
+
*
|
|
289
|
+
* @param request - Updated translation details
|
|
290
|
+
*/ async updateNotificationTranslation(request) {
|
|
291
|
+
try {
|
|
292
|
+
await this.client.put("/notifications/update-notification-translation", request);
|
|
293
|
+
} catch (error) {
|
|
294
|
+
this.handleError("Failed to update notification translation", error);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Get all notifications, optionally filtered by language
|
|
299
|
+
*
|
|
300
|
+
* @param language - Optional language code to filter translations
|
|
301
|
+
* @returns Array of notifications with translations
|
|
302
|
+
*/ async getNotifications(language) {
|
|
303
|
+
try {
|
|
304
|
+
const url = language ? `/notifications/get-notifications/${language}` : "/notifications/get-notifications";
|
|
305
|
+
const response = await this.client.get(url);
|
|
306
|
+
return response.data;
|
|
307
|
+
} catch (error) {
|
|
308
|
+
this.handleError("Failed to get notifications", error);
|
|
309
|
+
throw error;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Delete a notification or translation
|
|
314
|
+
*
|
|
315
|
+
* @param uuid - Notification UUID
|
|
316
|
+
* @param language - Optional language code to delete only translation
|
|
317
|
+
*/ async deleteNotification(uuid, language) {
|
|
318
|
+
try {
|
|
319
|
+
const params = language ? {
|
|
320
|
+
language
|
|
321
|
+
} : {};
|
|
322
|
+
await this.client.delete(`/notifications/delete-notifications/${uuid}`, {
|
|
323
|
+
params
|
|
324
|
+
});
|
|
325
|
+
} catch (error) {
|
|
326
|
+
this.handleError("Failed to delete notification", error);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
// ==================== Error Handling ====================
|
|
330
|
+
/**
|
|
331
|
+
* Handle and format errors from notification service
|
|
332
|
+
*/ handleError(message, error) {
|
|
333
|
+
if (axios.isAxiosError(error)) {
|
|
334
|
+
const axiosError = error;
|
|
335
|
+
const status = axiosError.response?.status;
|
|
336
|
+
const data = axiosError.response?.data;
|
|
337
|
+
console.error(`[NotificationClient] ${message}:`, {
|
|
338
|
+
status,
|
|
339
|
+
message: axiosError.message,
|
|
340
|
+
data
|
|
341
|
+
});
|
|
342
|
+
throw new Error(`${message}: ${status ? `HTTP ${status}` : axiosError.message}`);
|
|
343
|
+
}
|
|
344
|
+
console.error(`[NotificationClient] ${message}:`, error);
|
|
345
|
+
throw new Error(`${message}: ${error}`);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
//# sourceMappingURL=NotificationClient.js.map
|