@amohamud23/notihub 1.1.21 → 1.1.23
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.cjs +0 -1674
- package/dist/index.d.cts +1 -706
- package/dist/index.d.ts +1 -706
- package/dist/index.js +0 -1691
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,1691 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __export = (target, all) => {
|
|
3
|
-
for (var name in all)
|
|
4
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
// src/util/index.ts
|
|
8
|
-
function getDate(dateStr) {
|
|
9
|
-
const date = new Date(dateStr);
|
|
10
|
-
const year = date.getFullYear();
|
|
11
|
-
const month = (date.getMonth() + 1).toString().padStart(2, "0");
|
|
12
|
-
const day = date.getDate().toString().padStart(2, "0");
|
|
13
|
-
const formattedDate = `${month}-${day}-${year}`;
|
|
14
|
-
return formattedDate;
|
|
15
|
-
}
|
|
16
|
-
function getDateFormat(dateStr) {
|
|
17
|
-
const date = new Date(dateStr);
|
|
18
|
-
const now = /* @__PURE__ */ new Date();
|
|
19
|
-
const seconds = Math.floor((now.getTime() - date.getTime()) / 1e3);
|
|
20
|
-
let interval = seconds / 31536e3;
|
|
21
|
-
if (interval > 1) {
|
|
22
|
-
return date.toLocaleDateString("en-US", {
|
|
23
|
-
year: "numeric",
|
|
24
|
-
month: "short",
|
|
25
|
-
day: "numeric"
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
interval = seconds / 2592e3;
|
|
29
|
-
if (interval > 1) {
|
|
30
|
-
return date.toLocaleDateString("en-US", {
|
|
31
|
-
year: "numeric",
|
|
32
|
-
month: "short",
|
|
33
|
-
day: "numeric"
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
interval = seconds / 86400;
|
|
37
|
-
if (interval > 7) {
|
|
38
|
-
return date.toLocaleDateString("en-US", {
|
|
39
|
-
year: "numeric",
|
|
40
|
-
month: "short",
|
|
41
|
-
day: "numeric"
|
|
42
|
-
});
|
|
43
|
-
} else if (interval > 1) {
|
|
44
|
-
return Math.floor(interval) + "d ago";
|
|
45
|
-
}
|
|
46
|
-
interval = seconds / 3600;
|
|
47
|
-
if (interval > 1) {
|
|
48
|
-
return Math.floor(interval) + "h ago";
|
|
49
|
-
}
|
|
50
|
-
interval = seconds / 60;
|
|
51
|
-
if (interval > 1) {
|
|
52
|
-
return Math.floor(interval) + "m ago";
|
|
53
|
-
}
|
|
54
|
-
return Math.floor(seconds) + "s ago";
|
|
55
|
-
}
|
|
56
|
-
function addMonths({ date, months }) {
|
|
57
|
-
date.setMonth(date.getMonth() + months);
|
|
58
|
-
return date;
|
|
59
|
-
}
|
|
60
|
-
var handleError = (error, res, req) => {
|
|
61
|
-
console.error(`[${(/* @__PURE__ */ new Date()).toISOString()}] Error:`, {
|
|
62
|
-
message: error.message,
|
|
63
|
-
errorCode: error.errorCode,
|
|
64
|
-
stack: process.env.NODE_ENV !== "production" ? error.stack : void 0,
|
|
65
|
-
path: req?.path,
|
|
66
|
-
method: req?.method
|
|
67
|
-
});
|
|
68
|
-
let statusCode = 500;
|
|
69
|
-
let message = error.message || "Something went wrong";
|
|
70
|
-
if (error.errorCode === "UserNotFound" || error.message?.toLowerCase().includes("not found")) {
|
|
71
|
-
statusCode = 404;
|
|
72
|
-
} else if (error.message?.toLowerCase().includes("required") || error.message?.toLowerCase().includes("invalid")) {
|
|
73
|
-
statusCode = 400;
|
|
74
|
-
} else if (error.statusCode) {
|
|
75
|
-
statusCode = error.statusCode;
|
|
76
|
-
}
|
|
77
|
-
const response = {
|
|
78
|
-
success: false,
|
|
79
|
-
message,
|
|
80
|
-
error: error.errorCode || error.name,
|
|
81
|
-
statusCode,
|
|
82
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
83
|
-
};
|
|
84
|
-
res.status(statusCode).json(response);
|
|
85
|
-
};
|
|
86
|
-
var handleSuccess = (data, res, statusCode = 200) => {
|
|
87
|
-
const response = {
|
|
88
|
-
success: true,
|
|
89
|
-
data,
|
|
90
|
-
statusCode,
|
|
91
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
92
|
-
};
|
|
93
|
-
res.status(statusCode).json(response);
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
// src/util/responseUtils.ts
|
|
97
|
-
var formatResponse = (data, message = "Success", error, statusCode = 200) => {
|
|
98
|
-
const response = {
|
|
99
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
100
|
-
data: data || null,
|
|
101
|
-
message,
|
|
102
|
-
statusCode,
|
|
103
|
-
error
|
|
104
|
-
};
|
|
105
|
-
return response;
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
// src/client/MongooseClient.ts
|
|
109
|
-
import mongoose from "mongoose";
|
|
110
|
-
var conn = null;
|
|
111
|
-
var connectionStr = process.env.DB_CONNECTION_STRING;
|
|
112
|
-
var dbName = process.env.DB_NAME;
|
|
113
|
-
var client = async function() {
|
|
114
|
-
if (conn == null) {
|
|
115
|
-
conn = mongoose.createConnection(connectionStr, {
|
|
116
|
-
dbName,
|
|
117
|
-
serverSelectionTimeoutMS: 5e3
|
|
118
|
-
});
|
|
119
|
-
await conn.asPromise();
|
|
120
|
-
}
|
|
121
|
-
return conn;
|
|
122
|
-
};
|
|
123
|
-
var MongooseClient_default = client;
|
|
124
|
-
|
|
125
|
-
// src/exceptions.ts
|
|
126
|
-
var DocumentNotFoundException = class _DocumentNotFoundException extends Error {
|
|
127
|
-
constructor(msg) {
|
|
128
|
-
super(msg);
|
|
129
|
-
Object.setPrototypeOf(this, _DocumentNotFoundException.prototype);
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
// src/client/DynamoDBClient.ts
|
|
134
|
-
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
|
|
135
|
-
import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";
|
|
136
|
-
var isOffline = process.env.IS_OFFLINE === "true";
|
|
137
|
-
var ddbClient;
|
|
138
|
-
if (isOffline) {
|
|
139
|
-
console.log("Running in offline mode");
|
|
140
|
-
ddbClient = new DynamoDBClient({
|
|
141
|
-
region: "localhost",
|
|
142
|
-
endpoint: "http://0.0.0.0:8000",
|
|
143
|
-
credentials: {
|
|
144
|
-
accessKeyId: "MockAccessKeyId",
|
|
145
|
-
secretAccessKey: "MockSecretAccessKey"
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
} else {
|
|
149
|
-
console.log("Running in production mode");
|
|
150
|
-
ddbClient = new DynamoDBClient();
|
|
151
|
-
}
|
|
152
|
-
var ddbDocClient = DynamoDBDocumentClient.from(ddbClient, {
|
|
153
|
-
marshallOptions: {
|
|
154
|
-
removeUndefinedValues: true
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
var USER_TABLE_NAME = process.env.USER_TABLE_NAME || "NotiHub-Users-v1-dev";
|
|
158
|
-
|
|
159
|
-
// src/DynamoModels/User.ts
|
|
160
|
-
import {
|
|
161
|
-
DeleteCommand,
|
|
162
|
-
GetCommand,
|
|
163
|
-
PutCommand,
|
|
164
|
-
QueryCommand,
|
|
165
|
-
UpdateCommand
|
|
166
|
-
} from "@aws-sdk/lib-dynamodb";
|
|
167
|
-
var User = class _User {
|
|
168
|
-
static ENV = process.env.ENV || "dev";
|
|
169
|
-
/**
|
|
170
|
-
* The name of the DynamoDB table for users.
|
|
171
|
-
*/
|
|
172
|
-
static TABLE_NAME = `NotiHub-Users-v1-${_User.ENV}`;
|
|
173
|
-
/**
|
|
174
|
-
* Retrieves a user by their ID.
|
|
175
|
-
* @param id - The ID of the user to retrieve.
|
|
176
|
-
* @returns A promise that resolves to the user object or null if not found.
|
|
177
|
-
*/
|
|
178
|
-
static async getUserById(id) {
|
|
179
|
-
const command = new GetCommand({
|
|
180
|
-
TableName: _User.TABLE_NAME,
|
|
181
|
-
Key: { id }
|
|
182
|
-
});
|
|
183
|
-
try {
|
|
184
|
-
const result = await ddbDocClient.send(command);
|
|
185
|
-
return result.Item || null;
|
|
186
|
-
} catch (error) {
|
|
187
|
-
console.error("Error fetching user:", error);
|
|
188
|
-
throw new Error("Could not fetch user");
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Retrieves a user by their email.
|
|
193
|
-
* @param email - The email of the user to retrieve.
|
|
194
|
-
* @returns A promise that resolves to the user object or null if not found.
|
|
195
|
-
*/
|
|
196
|
-
static async getUserByEmail(email) {
|
|
197
|
-
const command = new QueryCommand({
|
|
198
|
-
TableName: _User.TABLE_NAME,
|
|
199
|
-
IndexName: "EmailIndex",
|
|
200
|
-
KeyConditionExpression: "email = :email",
|
|
201
|
-
ExpressionAttributeValues: {
|
|
202
|
-
":email": email
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
try {
|
|
206
|
-
const result = await ddbDocClient.send(command);
|
|
207
|
-
return result.Items || null;
|
|
208
|
-
} catch (error) {
|
|
209
|
-
console.error(`Error fetching user by email: ${email}`, error);
|
|
210
|
-
throw new Error("Could not fetch user by email");
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Creates a new user.
|
|
215
|
-
* @param user - The user object to create.
|
|
216
|
-
* @returns A promise that resolves to the created user object.
|
|
217
|
-
*/
|
|
218
|
-
static async createUser(user) {
|
|
219
|
-
const command = new PutCommand({
|
|
220
|
-
TableName: _User.TABLE_NAME,
|
|
221
|
-
Item: user
|
|
222
|
-
});
|
|
223
|
-
try {
|
|
224
|
-
await ddbDocClient.send(command);
|
|
225
|
-
return user;
|
|
226
|
-
} catch (error) {
|
|
227
|
-
console.error("Error creating user:", error);
|
|
228
|
-
throw new Error("Could not create user");
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Updates an existing user.
|
|
233
|
-
* @param user - The user object to update.
|
|
234
|
-
* @returns A promise that resolves to the updated user object.
|
|
235
|
-
*/
|
|
236
|
-
static async updateUser(id, user) {
|
|
237
|
-
const updateFields = Object.keys(user).filter(
|
|
238
|
-
(key) => user[key] !== void 0
|
|
239
|
-
);
|
|
240
|
-
if (updateFields.length === 0) {
|
|
241
|
-
throw new Error("No fields provided to update.");
|
|
242
|
-
}
|
|
243
|
-
const UpdateExpression = `SET ${updateFields.map((field, idx) => `#field${idx} = :value${idx}`).join(", ")}`;
|
|
244
|
-
const ExpressionAttributeNames = updateFields.reduce((acc, field, idx) => {
|
|
245
|
-
acc[`#field${idx}`] = field;
|
|
246
|
-
return acc;
|
|
247
|
-
}, {});
|
|
248
|
-
const ExpressionAttributeValues = updateFields.reduce((acc, field, idx) => {
|
|
249
|
-
acc[`:value${idx}`] = user[field];
|
|
250
|
-
return acc;
|
|
251
|
-
}, {});
|
|
252
|
-
const command = new UpdateCommand({
|
|
253
|
-
TableName: _User.TABLE_NAME,
|
|
254
|
-
Key: { id },
|
|
255
|
-
UpdateExpression,
|
|
256
|
-
ExpressionAttributeNames,
|
|
257
|
-
ExpressionAttributeValues,
|
|
258
|
-
ReturnValues: "ALL_NEW"
|
|
259
|
-
});
|
|
260
|
-
try {
|
|
261
|
-
const result = await ddbDocClient.send(command);
|
|
262
|
-
return result.Attributes;
|
|
263
|
-
} catch (error) {
|
|
264
|
-
console.error("Error updating user: ", error);
|
|
265
|
-
throw new Error("Could not update user");
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* Deletes a user by their ID.
|
|
270
|
-
* @param id - The ID of the user to delete.
|
|
271
|
-
* @returns A promise that resolves when the user is deleted.
|
|
272
|
-
*/
|
|
273
|
-
static async deleteUser(id) {
|
|
274
|
-
const command = new DeleteCommand({
|
|
275
|
-
TableName: _User.TABLE_NAME,
|
|
276
|
-
Key: { id }
|
|
277
|
-
});
|
|
278
|
-
try {
|
|
279
|
-
await ddbDocClient.send(command);
|
|
280
|
-
} catch (error) {
|
|
281
|
-
console.error("Error deleting user:", error);
|
|
282
|
-
throw new Error("Could not delete user");
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
/**
|
|
286
|
-
* Searches for users by email and customerId
|
|
287
|
-
* @param email - The email to search for.
|
|
288
|
-
* @param customerId - The customer ID to filter by.
|
|
289
|
-
* @returns A promise that resolves to an array of user objects.
|
|
290
|
-
*/
|
|
291
|
-
static async searchUsersByEmailAndCustomerId(email, customerId) {
|
|
292
|
-
const command = new QueryCommand({
|
|
293
|
-
TableName: _User.TABLE_NAME,
|
|
294
|
-
IndexName: "EmailCustomerIndex",
|
|
295
|
-
KeyConditionExpression: "begins_with(email, :email) and customerId = :customerId",
|
|
296
|
-
ExpressionAttributeValues: {
|
|
297
|
-
":email": email,
|
|
298
|
-
":customerId": customerId
|
|
299
|
-
}
|
|
300
|
-
});
|
|
301
|
-
try {
|
|
302
|
-
const result = await ddbDocClient.send(command);
|
|
303
|
-
return result.Items || [];
|
|
304
|
-
} catch (error) {
|
|
305
|
-
console.error("Error searching users by email and customerId:", error);
|
|
306
|
-
throw new Error("Could not search users by email and customerId");
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
};
|
|
310
|
-
var User_default = User;
|
|
311
|
-
|
|
312
|
-
// src/DynamoModels/Customer.ts
|
|
313
|
-
import {
|
|
314
|
-
DeleteCommand as DeleteCommand2,
|
|
315
|
-
GetCommand as GetCommand2,
|
|
316
|
-
PutCommand as PutCommand2,
|
|
317
|
-
QueryCommand as QueryCommand2,
|
|
318
|
-
UpdateCommand as UpdateCommand2
|
|
319
|
-
} from "@aws-sdk/lib-dynamodb";
|
|
320
|
-
var Customer = class _Customer {
|
|
321
|
-
static ENV = process.env.ENV || "dev";
|
|
322
|
-
static TABLE_NAME = `NotiHub-Customers-v1-${_Customer.ENV}`;
|
|
323
|
-
/**
|
|
324
|
-
* Retrieves a customer by their ID.
|
|
325
|
-
* @param id - The ID of the customer to retrieve.
|
|
326
|
-
* @returns A promise that resolves to the customer object or null if not found.
|
|
327
|
-
*/
|
|
328
|
-
static async getCustomerById(id) {
|
|
329
|
-
const command = new GetCommand2({
|
|
330
|
-
TableName: _Customer.TABLE_NAME,
|
|
331
|
-
Key: { id }
|
|
332
|
-
});
|
|
333
|
-
try {
|
|
334
|
-
const result = await ddbDocClient.send(command);
|
|
335
|
-
return result.Item || null;
|
|
336
|
-
} catch (error) {
|
|
337
|
-
console.error("Error fetching customer:", error);
|
|
338
|
-
throw new Error("Could not fetch customer");
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
/**
|
|
342
|
-
* Retrieves a customer by their email.
|
|
343
|
-
* @param email - The email of the customer to retrieve.
|
|
344
|
-
* @returns A promise that resolves to the customer object or null if not found.
|
|
345
|
-
*/
|
|
346
|
-
static async getCustomerByEmail(email) {
|
|
347
|
-
const command = new QueryCommand2({
|
|
348
|
-
TableName: _Customer.TABLE_NAME,
|
|
349
|
-
IndexName: "EmailIndex",
|
|
350
|
-
KeyConditionExpression: "#email = :email",
|
|
351
|
-
ExpressionAttributeNames: {
|
|
352
|
-
"#email": "email"
|
|
353
|
-
},
|
|
354
|
-
ExpressionAttributeValues: {
|
|
355
|
-
":email": email
|
|
356
|
-
},
|
|
357
|
-
Limit: 1
|
|
358
|
-
// Optional, assuming email is unique
|
|
359
|
-
});
|
|
360
|
-
try {
|
|
361
|
-
const result = await ddbDocClient.send(command);
|
|
362
|
-
if (!result.Items || result.Items.length === 0) {
|
|
363
|
-
return null;
|
|
364
|
-
}
|
|
365
|
-
return result.Items[0] || null;
|
|
366
|
-
} catch (error) {
|
|
367
|
-
console.error(`Error fetching customer by email: ${email}`, error);
|
|
368
|
-
throw new Error("Could not fetch customer by email");
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
/**
|
|
372
|
-
* Creates a new customer.
|
|
373
|
-
* @param customer - The customer object to create.
|
|
374
|
-
* @returns A promise that resolves to the created customer object.
|
|
375
|
-
*/
|
|
376
|
-
static async createCustomer(customer) {
|
|
377
|
-
const command = new PutCommand2({
|
|
378
|
-
TableName: _Customer.TABLE_NAME,
|
|
379
|
-
Item: customer
|
|
380
|
-
});
|
|
381
|
-
try {
|
|
382
|
-
await ddbDocClient.send(command);
|
|
383
|
-
return customer;
|
|
384
|
-
} catch (error) {
|
|
385
|
-
console.error("Error creating customer:", error);
|
|
386
|
-
throw new Error("Could not create customer");
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
/**
|
|
390
|
-
* Deletes a customer by their ID.
|
|
391
|
-
* @param id - The ID of the customer to delete.
|
|
392
|
-
* @returns A promise that resolves when the customer is deleted.
|
|
393
|
-
*/
|
|
394
|
-
static async deleteCustomer(id) {
|
|
395
|
-
const command = new DeleteCommand2({
|
|
396
|
-
TableName: _Customer.TABLE_NAME,
|
|
397
|
-
Key: { id }
|
|
398
|
-
});
|
|
399
|
-
try {
|
|
400
|
-
await ddbDocClient.send(command);
|
|
401
|
-
} catch (error) {
|
|
402
|
-
console.error("Error deleting customer:", error);
|
|
403
|
-
throw new Error("Could not delete customer");
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
/**
|
|
407
|
-
* Updates an existing customer.
|
|
408
|
-
* @param id - The ID of the customer to update.
|
|
409
|
-
* @param customer - The updated customer object.
|
|
410
|
-
* @returns A promise that resolves to the updated customer object.
|
|
411
|
-
*/
|
|
412
|
-
static async updateCustomer(id, updates) {
|
|
413
|
-
const updateExpressions = [];
|
|
414
|
-
const expressionAttributeValues = {};
|
|
415
|
-
for (const [key, value] of Object.entries(updates)) {
|
|
416
|
-
updateExpressions.push(`${key} = :${key}`);
|
|
417
|
-
expressionAttributeValues[`:${key}`] = value;
|
|
418
|
-
}
|
|
419
|
-
const command = new UpdateCommand2({
|
|
420
|
-
TableName: _Customer.TABLE_NAME,
|
|
421
|
-
Key: { id },
|
|
422
|
-
UpdateExpression: `SET ${updateExpressions.join(", ")}`,
|
|
423
|
-
ExpressionAttributeValues: expressionAttributeValues,
|
|
424
|
-
ReturnValues: "ALL_NEW"
|
|
425
|
-
});
|
|
426
|
-
try {
|
|
427
|
-
const result = await ddbDocClient.send(command);
|
|
428
|
-
return result.Attributes;
|
|
429
|
-
} catch (error) {
|
|
430
|
-
console.error("Error updating customer:", error);
|
|
431
|
-
throw new Error("Could not update customer");
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
};
|
|
435
|
-
var Customer_default = Customer;
|
|
436
|
-
|
|
437
|
-
// src/DynamoModels/Notifications.ts
|
|
438
|
-
import {
|
|
439
|
-
PutCommand as PutCommand3,
|
|
440
|
-
QueryCommand as QueryCommand3
|
|
441
|
-
} from "@aws-sdk/lib-dynamodb";
|
|
442
|
-
var Notifications = class _Notifications {
|
|
443
|
-
static ENV = process.env.ENV || "dev";
|
|
444
|
-
static TABLE_NAME = `NotiHub-Notifications-v1-${_Notifications.ENV}`;
|
|
445
|
-
/**
|
|
446
|
-
* Retrieves a notification by its ID.
|
|
447
|
-
* @param id - The ID of the notification to retrieve.
|
|
448
|
-
* @returns A promise that resolves to the notification object or null if not found.
|
|
449
|
-
*/
|
|
450
|
-
static async getNotificationById(id) {
|
|
451
|
-
const params = {
|
|
452
|
-
TableName: _Notifications.TABLE_NAME,
|
|
453
|
-
IndexName: "NotificationIdIndex",
|
|
454
|
-
KeyConditionExpression: "id = :id",
|
|
455
|
-
ExpressionAttributeValues: {
|
|
456
|
-
":id": id
|
|
457
|
-
}
|
|
458
|
-
};
|
|
459
|
-
const command = new QueryCommand3(params);
|
|
460
|
-
try {
|
|
461
|
-
const response = await ddbDocClient.send(command);
|
|
462
|
-
if (!response.Items || response.Items.length === 0) {
|
|
463
|
-
return null;
|
|
464
|
-
}
|
|
465
|
-
return response.Items[0] ?? null;
|
|
466
|
-
} catch (error) {
|
|
467
|
-
console.error("Error fetching notification:", error);
|
|
468
|
-
throw new Error("Could not fetch notification");
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
static async getAllNotificationsByEntityId(customerId) {
|
|
472
|
-
const command = new QueryCommand3({
|
|
473
|
-
TableName: _Notifications.TABLE_NAME,
|
|
474
|
-
KeyConditionExpression: "customerId = :customerId",
|
|
475
|
-
ExpressionAttributeValues: {
|
|
476
|
-
":customerId": customerId
|
|
477
|
-
}
|
|
478
|
-
});
|
|
479
|
-
try {
|
|
480
|
-
const result = await ddbDocClient.send(command);
|
|
481
|
-
return result.Items || null;
|
|
482
|
-
} catch (error) {
|
|
483
|
-
console.error(
|
|
484
|
-
`Error fetching notifications by customerId: ${customerId}`,
|
|
485
|
-
error
|
|
486
|
-
);
|
|
487
|
-
throw new Error("Could not fetch notifications by customerId");
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
/**
|
|
491
|
-
* Creates a new notification.
|
|
492
|
-
* @param notification - The notification object to create.
|
|
493
|
-
* @returns A promise that resolves to the created notification object.
|
|
494
|
-
*/
|
|
495
|
-
static async createNotification(notification) {
|
|
496
|
-
const command = new PutCommand3({
|
|
497
|
-
TableName: _Notifications.TABLE_NAME,
|
|
498
|
-
Item: notification
|
|
499
|
-
});
|
|
500
|
-
try {
|
|
501
|
-
await ddbDocClient.send(command);
|
|
502
|
-
return notification;
|
|
503
|
-
} catch (error) {
|
|
504
|
-
console.error("Error creating notification:", error);
|
|
505
|
-
throw new Error("Could not create notification");
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
// Additional methods can be added here as needed
|
|
509
|
-
/**
|
|
510
|
-
* Fetches and merges paginated notifications for multiple notiTypeIds, sorted by createdAt descending.
|
|
511
|
-
* @param notiTypeIds - Array of notiTypeIds to fetch.
|
|
512
|
-
* @param limitPerType - Max items to fetch per notiTypeId.
|
|
513
|
-
* @param exclusiveStartKeys - Optional map of pagination keys per notiTypeId.
|
|
514
|
-
* @returns An object with merged, sorted notifications and nextPageKeys map.
|
|
515
|
-
*/
|
|
516
|
-
static async getUnifiedFeedByNotiTypeIds(notiTypeIds, limitPerType = 20, exclusiveStartKeys) {
|
|
517
|
-
const results = await Promise.all(
|
|
518
|
-
notiTypeIds.map(async (ntid) => {
|
|
519
|
-
const params = {
|
|
520
|
-
TableName: this.TABLE_NAME,
|
|
521
|
-
IndexName: "NotiTypeIdCreatedAtIndex",
|
|
522
|
-
// Assuming you have a GSI for notiTypeId
|
|
523
|
-
KeyConditionExpression: "notiTypeId = :ntid",
|
|
524
|
-
ExpressionAttributeValues: { ":ntid": ntid },
|
|
525
|
-
ScanIndexForward: false,
|
|
526
|
-
Limit: limitPerType,
|
|
527
|
-
ExclusiveStartKey: exclusiveStartKeys?.[ntid]
|
|
528
|
-
};
|
|
529
|
-
const result = await ddbDocClient.send(new QueryCommand3(params));
|
|
530
|
-
return {
|
|
531
|
-
notiTypeId: ntid,
|
|
532
|
-
notifications: result.Items || [],
|
|
533
|
-
nextPageKey: result.LastEvaluatedKey
|
|
534
|
-
};
|
|
535
|
-
})
|
|
536
|
-
);
|
|
537
|
-
const mergedNotifications = results.flatMap((r) => r.notifications).sort((a, b) => b.createdAt.localeCompare(a.createdAt));
|
|
538
|
-
const nextPageKeys = results.reduce((acc, curr) => {
|
|
539
|
-
acc[curr.notiTypeId] = curr.nextPageKey;
|
|
540
|
-
return acc;
|
|
541
|
-
}, {});
|
|
542
|
-
return {
|
|
543
|
-
notifications: mergedNotifications,
|
|
544
|
-
nextPageKeys
|
|
545
|
-
};
|
|
546
|
-
}
|
|
547
|
-
};
|
|
548
|
-
var Notifications_default = Notifications;
|
|
549
|
-
|
|
550
|
-
// src/DynamoModels/NotiHubStats.ts
|
|
551
|
-
import {
|
|
552
|
-
PutCommand as PutCommand4,
|
|
553
|
-
QueryCommand as QueryCommand4,
|
|
554
|
-
UpdateCommand as UpdateCommand4,
|
|
555
|
-
DeleteCommand as DeleteCommand4
|
|
556
|
-
} from "@aws-sdk/lib-dynamodb";
|
|
557
|
-
var NotiHubStats = class _NotiHubStats {
|
|
558
|
-
static ENV = process.env.ENV || "dev";
|
|
559
|
-
static TABLE_NAME = `NotiHub-Stats-v1-${_NotiHubStats.ENV}`;
|
|
560
|
-
static async createStats(stats) {
|
|
561
|
-
const command = new PutCommand4({
|
|
562
|
-
TableName: _NotiHubStats.TABLE_NAME,
|
|
563
|
-
Item: stats
|
|
564
|
-
});
|
|
565
|
-
await ddbDocClient.send(command);
|
|
566
|
-
return stats;
|
|
567
|
-
}
|
|
568
|
-
static async getStatsByCustomerId(customerId) {
|
|
569
|
-
const command = new QueryCommand4({
|
|
570
|
-
TableName: _NotiHubStats.TABLE_NAME,
|
|
571
|
-
IndexName: "CustomerCreatedAtIndex",
|
|
572
|
-
KeyConditionExpression: "customerId = :customerId",
|
|
573
|
-
ExpressionAttributeValues: {
|
|
574
|
-
":customerId": customerId
|
|
575
|
-
}
|
|
576
|
-
});
|
|
577
|
-
const result = await ddbDocClient.send(command);
|
|
578
|
-
if (!result.Items || result.Items.length === 0) {
|
|
579
|
-
return null;
|
|
580
|
-
}
|
|
581
|
-
return result.Items[0] || null;
|
|
582
|
-
}
|
|
583
|
-
static async incrementViews(id, customerId) {
|
|
584
|
-
const command = new UpdateCommand4({
|
|
585
|
-
TableName: _NotiHubStats.TABLE_NAME,
|
|
586
|
-
Key: { id, customerId },
|
|
587
|
-
UpdateExpression: "ADD #views :inc",
|
|
588
|
-
ExpressionAttributeNames: {
|
|
589
|
-
"#views": "views"
|
|
590
|
-
},
|
|
591
|
-
ExpressionAttributeValues: {
|
|
592
|
-
":inc": 1
|
|
593
|
-
},
|
|
594
|
-
ReturnValues: "ALL_NEW"
|
|
595
|
-
});
|
|
596
|
-
const result = await ddbDocClient.send(command);
|
|
597
|
-
return result.Attributes;
|
|
598
|
-
}
|
|
599
|
-
/**
|
|
600
|
-
* Increment the count of notifications sent for a specific customer.
|
|
601
|
-
* @param id - The ID of the stats entry.
|
|
602
|
-
* @param customerId - The ID of the customer.
|
|
603
|
-
* @returns A promise that resolves to the updated stats object.
|
|
604
|
-
*/
|
|
605
|
-
static async incrementNotificationsSent(id, customerId) {
|
|
606
|
-
const command = new UpdateCommand4({
|
|
607
|
-
TableName: _NotiHubStats.TABLE_NAME,
|
|
608
|
-
Key: { id, customerId },
|
|
609
|
-
UpdateExpression: "ADD notifications :inc",
|
|
610
|
-
ExpressionAttributeValues: {
|
|
611
|
-
":inc": 1
|
|
612
|
-
},
|
|
613
|
-
ReturnValues: "ALL_NEW"
|
|
614
|
-
});
|
|
615
|
-
const result = await ddbDocClient.send(command);
|
|
616
|
-
return result.Attributes;
|
|
617
|
-
}
|
|
618
|
-
/**
|
|
619
|
-
* Increment the count of subscriptions for a specific customer.
|
|
620
|
-
* @param id - The ID of the stats entry.
|
|
621
|
-
* @param customerId - The ID of the customer.
|
|
622
|
-
* @returns A promise that resolves to the updated stats object.
|
|
623
|
-
*/
|
|
624
|
-
static async incrementSubscriptions(id, customerId) {
|
|
625
|
-
const command = new UpdateCommand4({
|
|
626
|
-
TableName: _NotiHubStats.TABLE_NAME,
|
|
627
|
-
Key: { id, customerId },
|
|
628
|
-
UpdateExpression: "ADD subscriptions :inc",
|
|
629
|
-
ExpressionAttributeValues: {
|
|
630
|
-
":inc": 1
|
|
631
|
-
},
|
|
632
|
-
ReturnValues: "ALL_NEW"
|
|
633
|
-
});
|
|
634
|
-
const result = await ddbDocClient.send(command);
|
|
635
|
-
return result.Attributes;
|
|
636
|
-
}
|
|
637
|
-
static async getStatsInDateRange(customerId, startDate, endDate) {
|
|
638
|
-
const command = new QueryCommand4({
|
|
639
|
-
TableName: _NotiHubStats.TABLE_NAME,
|
|
640
|
-
IndexName: "CustomerCreatedAtIndex",
|
|
641
|
-
KeyConditionExpression: "customerId = :customerId AND createdAt BETWEEN :start_date AND :end_date",
|
|
642
|
-
ExpressionAttributeValues: {
|
|
643
|
-
":customerId": customerId,
|
|
644
|
-
":start_date": startDate,
|
|
645
|
-
":end_date": endDate
|
|
646
|
-
},
|
|
647
|
-
ScanIndexForward: true
|
|
648
|
-
});
|
|
649
|
-
const result = await ddbDocClient.send(command);
|
|
650
|
-
return result.Items || [];
|
|
651
|
-
}
|
|
652
|
-
static async deleteStatsById(id) {
|
|
653
|
-
const command = new DeleteCommand4({
|
|
654
|
-
TableName: _NotiHubStats.TABLE_NAME,
|
|
655
|
-
Key: { id }
|
|
656
|
-
});
|
|
657
|
-
try {
|
|
658
|
-
await ddbDocClient.send(command);
|
|
659
|
-
console.log(`Stats with ID ${id} deleted successfully.`);
|
|
660
|
-
} catch (error) {
|
|
661
|
-
console.error(`Error deleting stats with ID ${id}:`, error);
|
|
662
|
-
throw new Error("Could not delete stats");
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
};
|
|
666
|
-
var NotiHubStats_default = NotiHubStats;
|
|
667
|
-
|
|
668
|
-
// src/DynamoModels/NotiType.ts
|
|
669
|
-
import {
|
|
670
|
-
BatchWriteCommand,
|
|
671
|
-
DeleteCommand as DeleteCommand5,
|
|
672
|
-
PutCommand as PutCommand5,
|
|
673
|
-
QueryCommand as QueryCommand5,
|
|
674
|
-
ScanCommand,
|
|
675
|
-
UpdateCommand as UpdateCommand5
|
|
676
|
-
} from "@aws-sdk/lib-dynamodb";
|
|
677
|
-
var NotiType = class _NotiType {
|
|
678
|
-
static ENV = process.env.ENV || "dev";
|
|
679
|
-
static TABLE_NAME = `NotiHub-NotiTypes-v1-${_NotiType.ENV}`;
|
|
680
|
-
/**
|
|
681
|
-
* Retrieves a notification type by its ID.
|
|
682
|
-
* @param id - The ID of the notification type to retrieve.
|
|
683
|
-
* @param customerId - The customer ID associated with the notification type.
|
|
684
|
-
* @returns A promise that resolves to the notification type object or null if not found.
|
|
685
|
-
*/
|
|
686
|
-
static async getNotiTypeById(id) {
|
|
687
|
-
const command = new QueryCommand5({
|
|
688
|
-
TableName: _NotiType.TABLE_NAME,
|
|
689
|
-
// Replace with your resolved table name
|
|
690
|
-
IndexName: "NotiTypeIdIndex",
|
|
691
|
-
KeyConditionExpression: "id = :id",
|
|
692
|
-
ExpressionAttributeValues: {
|
|
693
|
-
":id": id
|
|
694
|
-
}
|
|
695
|
-
});
|
|
696
|
-
try {
|
|
697
|
-
const result = await ddbDocClient.send(command);
|
|
698
|
-
if (!result.Items || result.Items.length === 0) {
|
|
699
|
-
return null;
|
|
700
|
-
}
|
|
701
|
-
return result.Items[0];
|
|
702
|
-
} catch (error) {
|
|
703
|
-
console.error("Error fetching notification type:", error);
|
|
704
|
-
throw new Error("Could not fetch notification type");
|
|
705
|
-
}
|
|
706
|
-
}
|
|
707
|
-
/**
|
|
708
|
-
* Retrieves all notification types.
|
|
709
|
-
* @returns A promise that resolves to an array of notification type objects.
|
|
710
|
-
*/
|
|
711
|
-
static async getAllNotiTypesByEntityId(entityId) {
|
|
712
|
-
const command = new QueryCommand5({
|
|
713
|
-
TableName: _NotiType.TABLE_NAME,
|
|
714
|
-
KeyConditionExpression: "customerId = :customerId",
|
|
715
|
-
ExpressionAttributeValues: {
|
|
716
|
-
":customerId": entityId
|
|
717
|
-
}
|
|
718
|
-
});
|
|
719
|
-
try {
|
|
720
|
-
const result = await ddbDocClient.send(command);
|
|
721
|
-
return result.Items || null;
|
|
722
|
-
} catch (error) {
|
|
723
|
-
console.error(
|
|
724
|
-
`Error fetching notification types by entityId: ${entityId}`,
|
|
725
|
-
error
|
|
726
|
-
);
|
|
727
|
-
throw new Error("Could not fetch notification types by entityId");
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
/**
|
|
731
|
-
* Creates a new notification type.
|
|
732
|
-
* @param notiType - The notification type object to create.
|
|
733
|
-
* @returns A promise that resolves to the created notification type object.
|
|
734
|
-
*/
|
|
735
|
-
static async createNotiType(notiType) {
|
|
736
|
-
const command = new PutCommand5({
|
|
737
|
-
TableName: _NotiType.TABLE_NAME,
|
|
738
|
-
Item: notiType
|
|
739
|
-
});
|
|
740
|
-
try {
|
|
741
|
-
await ddbDocClient.send(command);
|
|
742
|
-
return notiType;
|
|
743
|
-
} catch (error) {
|
|
744
|
-
console.error("Error creating notification type:", error);
|
|
745
|
-
throw new Error("Could not create notification type");
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
/**
|
|
749
|
-
* Updates an existing notification type.
|
|
750
|
-
* @param id - The ID of the notification type to update.
|
|
751
|
-
* @param updates - An object containing the fields to update.
|
|
752
|
-
* @returns A promise that resolves to the updated notification type object.
|
|
753
|
-
*/
|
|
754
|
-
static async updateNotiType(id, updates) {
|
|
755
|
-
const command = new UpdateCommand5({
|
|
756
|
-
TableName: _NotiType.TABLE_NAME,
|
|
757
|
-
Key: { id },
|
|
758
|
-
UpdateExpression: "set #type = :type, updatedAt = :updatedAt",
|
|
759
|
-
ExpressionAttributeNames: {
|
|
760
|
-
"#type": "type",
|
|
761
|
-
"#updatedAt": "updatedAt"
|
|
762
|
-
},
|
|
763
|
-
ExpressionAttributeValues: {
|
|
764
|
-
":type": updates.type,
|
|
765
|
-
":updatedAt": (/* @__PURE__ */ new Date()).toISOString()
|
|
766
|
-
},
|
|
767
|
-
ReturnValues: "ALL_NEW"
|
|
768
|
-
});
|
|
769
|
-
try {
|
|
770
|
-
const result = await ddbDocClient.send(command);
|
|
771
|
-
return result.Attributes;
|
|
772
|
-
} catch (error) {
|
|
773
|
-
console.error("Error updating notification type:", error);
|
|
774
|
-
throw new Error("Could not update notification type");
|
|
775
|
-
}
|
|
776
|
-
}
|
|
777
|
-
/**
|
|
778
|
-
* Deletes a notification type by its ID.
|
|
779
|
-
* @param id - The ID of the notification type to delete.
|
|
780
|
-
* @returns A promise that resolves when the notification type is deleted.
|
|
781
|
-
*/
|
|
782
|
-
static async deleteNotiType(id) {
|
|
783
|
-
const command = new DeleteCommand5({
|
|
784
|
-
TableName: _NotiType.TABLE_NAME,
|
|
785
|
-
Key: { id }
|
|
786
|
-
});
|
|
787
|
-
try {
|
|
788
|
-
await ddbDocClient.send(command);
|
|
789
|
-
} catch (error) {
|
|
790
|
-
console.error("Error deleting notification type:", error);
|
|
791
|
-
throw new Error("Could not delete notification type");
|
|
792
|
-
}
|
|
793
|
-
}
|
|
794
|
-
/**
|
|
795
|
-
* Delete all notification types for a given customerId
|
|
796
|
-
* Uses Query + BatchWrite with chunking
|
|
797
|
-
*/
|
|
798
|
-
static async deleteAllNotiTypesByCustomerId(customerId) {
|
|
799
|
-
try {
|
|
800
|
-
const itemsToDelete = [];
|
|
801
|
-
let lastEvaluatedKey;
|
|
802
|
-
do {
|
|
803
|
-
const scanResult = await ddbDocClient.send(
|
|
804
|
-
// TODO: update type
|
|
805
|
-
new ScanCommand({
|
|
806
|
-
TableName: _NotiType.TABLE_NAME,
|
|
807
|
-
FilterExpression: "customerId = :customerId",
|
|
808
|
-
ExpressionAttributeValues: {
|
|
809
|
-
":customerId": customerId
|
|
810
|
-
},
|
|
811
|
-
ExclusiveStartKey: lastEvaluatedKey
|
|
812
|
-
})
|
|
813
|
-
);
|
|
814
|
-
if (scanResult.Items) {
|
|
815
|
-
itemsToDelete.push(...scanResult.Items);
|
|
816
|
-
}
|
|
817
|
-
lastEvaluatedKey = scanResult.LastEvaluatedKey;
|
|
818
|
-
} while (lastEvaluatedKey);
|
|
819
|
-
if (itemsToDelete.length === 0) {
|
|
820
|
-
console.log(
|
|
821
|
-
`No notification types found for customerId: ${customerId}`
|
|
822
|
-
);
|
|
823
|
-
return;
|
|
824
|
-
}
|
|
825
|
-
console.log(
|
|
826
|
-
`Found ${itemsToDelete.length} notification types for customerId: ${customerId}. Deleting...`
|
|
827
|
-
);
|
|
828
|
-
const chunkSize = 25;
|
|
829
|
-
for (let i = 0; i < itemsToDelete.length; i += chunkSize) {
|
|
830
|
-
const chunk = itemsToDelete.slice(i, i + chunkSize);
|
|
831
|
-
const deleteRequests = chunk.map((item) => ({
|
|
832
|
-
DeleteRequest: {
|
|
833
|
-
Key: {
|
|
834
|
-
id: item.id,
|
|
835
|
-
customerId: item.customerId
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
}));
|
|
839
|
-
await ddbDocClient.send(
|
|
840
|
-
new BatchWriteCommand({
|
|
841
|
-
RequestItems: {
|
|
842
|
-
[_NotiType.TABLE_NAME]: deleteRequests
|
|
843
|
-
}
|
|
844
|
-
})
|
|
845
|
-
);
|
|
846
|
-
}
|
|
847
|
-
console.log(
|
|
848
|
-
`Successfully deleted ${itemsToDelete.length} notification types for customerId: ${customerId}`
|
|
849
|
-
);
|
|
850
|
-
} catch (error) {
|
|
851
|
-
console.error(
|
|
852
|
-
`Failed to delete notification types for customerId: ${customerId}`,
|
|
853
|
-
error
|
|
854
|
-
);
|
|
855
|
-
throw new Error("Could not delete notification types for customerId");
|
|
856
|
-
}
|
|
857
|
-
}
|
|
858
|
-
};
|
|
859
|
-
var NotiType_default = NotiType;
|
|
860
|
-
|
|
861
|
-
// src/DynamoModels/Subscription.ts
|
|
862
|
-
import {
|
|
863
|
-
DeleteCommand as DeleteCommand6,
|
|
864
|
-
GetCommand as GetCommand6,
|
|
865
|
-
PutCommand as PutCommand6,
|
|
866
|
-
QueryCommand as QueryCommand6
|
|
867
|
-
} from "@aws-sdk/lib-dynamodb";
|
|
868
|
-
var Subscription = class _Subscription {
|
|
869
|
-
static ENV = process.env.ENV || "dev";
|
|
870
|
-
static TABLE_NAME = `NotiHub-Subscriptions-v1-${_Subscription.ENV}`;
|
|
871
|
-
/**
|
|
872
|
-
* Retrieves a subscription by its ID.
|
|
873
|
-
* @param id - The ID of the subscription to retrieve.
|
|
874
|
-
* @returns A promise that resolves to the subscription object or null if not found.
|
|
875
|
-
*/
|
|
876
|
-
static async getSubscriptionById(id) {
|
|
877
|
-
const command = new GetCommand6({
|
|
878
|
-
TableName: _Subscription.TABLE_NAME,
|
|
879
|
-
Key: { id }
|
|
880
|
-
});
|
|
881
|
-
try {
|
|
882
|
-
const result = await ddbDocClient.send(command);
|
|
883
|
-
return result.Item || null;
|
|
884
|
-
} catch (error) {
|
|
885
|
-
console.error("Error fetching subscription:", error);
|
|
886
|
-
throw new Error("Could not fetch subscription");
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
|
-
/**
|
|
890
|
-
* Retrieves subscriptions by user ID.
|
|
891
|
-
* @param userId - The ID of the user whose subscriptions to retrieve.
|
|
892
|
-
* @returns A promise that resolves to an array of subscription objects or null if not found.
|
|
893
|
-
*/
|
|
894
|
-
static async getSubscriptionsByUserId(userId) {
|
|
895
|
-
const command = new QueryCommand6({
|
|
896
|
-
TableName: _Subscription.TABLE_NAME,
|
|
897
|
-
IndexName: "UserIdIndex",
|
|
898
|
-
// Assuming you have a GSI for userId
|
|
899
|
-
KeyConditionExpression: "userId = :userId",
|
|
900
|
-
ExpressionAttributeValues: {
|
|
901
|
-
":userId": userId
|
|
902
|
-
}
|
|
903
|
-
});
|
|
904
|
-
try {
|
|
905
|
-
const result = await ddbDocClient.send(command);
|
|
906
|
-
return result.Items || null;
|
|
907
|
-
} catch (error) {
|
|
908
|
-
console.error(`Error fetching subscriptions by userId: ${userId}`, error);
|
|
909
|
-
throw new Error("Could not fetch subscriptions by userId");
|
|
910
|
-
}
|
|
911
|
-
}
|
|
912
|
-
/**
|
|
913
|
-
* Creates or updates a subscription.
|
|
914
|
-
* @param subscription - The subscription object to create or update.
|
|
915
|
-
* @returns A promise that resolves to the created or updated subscription object.
|
|
916
|
-
*/
|
|
917
|
-
static async createOrUpdateSubscription(subscription) {
|
|
918
|
-
const command = new PutCommand6({
|
|
919
|
-
TableName: _Subscription.TABLE_NAME,
|
|
920
|
-
Item: subscription
|
|
921
|
-
});
|
|
922
|
-
try {
|
|
923
|
-
await ddbDocClient.send(command);
|
|
924
|
-
return subscription;
|
|
925
|
-
} catch (error) {
|
|
926
|
-
console.error("Error creating or updating subscription:", error);
|
|
927
|
-
throw new Error("Could not create or update subscription");
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
|
-
/**
|
|
931
|
-
* Deletes a subscription by its ID.
|
|
932
|
-
* @param id - The ID of the subscription to delete.
|
|
933
|
-
* @returns A promise that resolves when the deletion is complete.
|
|
934
|
-
*/
|
|
935
|
-
static async deleteSubscriptionById(id) {
|
|
936
|
-
const command = new DeleteCommand6({
|
|
937
|
-
TableName: _Subscription.TABLE_NAME,
|
|
938
|
-
Key: { id }
|
|
939
|
-
});
|
|
940
|
-
try {
|
|
941
|
-
await ddbDocClient.send(command);
|
|
942
|
-
} catch (error) {
|
|
943
|
-
console.error("Error deleting subscription:", error);
|
|
944
|
-
throw new Error("Could not delete subscription");
|
|
945
|
-
}
|
|
946
|
-
}
|
|
947
|
-
/**
|
|
948
|
-
* Fetch subscription by SubscriptionId.
|
|
949
|
-
* @param subscriptionId - The ID of the subscription to retrieve.
|
|
950
|
-
* @returns A promise that resolves to the subscription object or null if not found.
|
|
951
|
-
*/
|
|
952
|
-
static async getSubscriptionBySubscriptionId(subscriptionId) {
|
|
953
|
-
const command = new QueryCommand6({
|
|
954
|
-
TableName: _Subscription.TABLE_NAME,
|
|
955
|
-
IndexName: "SubscriptionIdIndex",
|
|
956
|
-
// Assuming you have a GSI for userId
|
|
957
|
-
KeyConditionExpression: "subscriptionId = :subscriptionId",
|
|
958
|
-
ExpressionAttributeValues: {
|
|
959
|
-
":subscriptionId": subscriptionId
|
|
960
|
-
}
|
|
961
|
-
});
|
|
962
|
-
try {
|
|
963
|
-
const result = await ddbDocClient.send(command);
|
|
964
|
-
if (!result.Items || result.Items.length === 0) {
|
|
965
|
-
return null;
|
|
966
|
-
}
|
|
967
|
-
return result.Items[0] || null;
|
|
968
|
-
} catch (error) {
|
|
969
|
-
console.error("Error fetching subscription by SubscriptionId:", error);
|
|
970
|
-
throw new Error("Could not fetch subscription by SubscriptionId");
|
|
971
|
-
}
|
|
972
|
-
}
|
|
973
|
-
/**
|
|
974
|
-
* Delete all subscriptions by user ID.
|
|
975
|
-
* @param userId - The ID of the user whose subscriptions to delete.
|
|
976
|
-
* @returns A promise that resolves when all subscriptions are deleted.
|
|
977
|
-
*/
|
|
978
|
-
static async deleteAllSubscriptionsByUserId(userId) {
|
|
979
|
-
const subscriptions = await this.getSubscriptionsByUserId(userId);
|
|
980
|
-
if (subscriptions && subscriptions.length > 0) {
|
|
981
|
-
const deletePromises = subscriptions.map(
|
|
982
|
-
(sub) => this.deleteSubscriptionById(sub.id)
|
|
983
|
-
);
|
|
984
|
-
await Promise.all(deletePromises);
|
|
985
|
-
}
|
|
986
|
-
}
|
|
987
|
-
};
|
|
988
|
-
var Subscription_default = Subscription;
|
|
989
|
-
|
|
990
|
-
// src/DynamoModels/NotiTypeStats.ts
|
|
991
|
-
import {
|
|
992
|
-
DeleteCommand as DeleteCommand7,
|
|
993
|
-
GetCommand as GetCommand7,
|
|
994
|
-
PutCommand as PutCommand7,
|
|
995
|
-
QueryCommand as QueryCommand7
|
|
996
|
-
} from "@aws-sdk/lib-dynamodb";
|
|
997
|
-
var NotiTypeStats = class _NotiTypeStats {
|
|
998
|
-
static ENV = process.env.ENV || "dev";
|
|
999
|
-
static TABLE_NAME = `NotiHub-NotiTypeStats-v1-${_NotiTypeStats.ENV}`;
|
|
1000
|
-
/**
|
|
1001
|
-
* Retrieves notification type stats by their ID.
|
|
1002
|
-
* @param id - The ID of the notification type stats to retrieve.
|
|
1003
|
-
* @returns A promise that resolves to the notification type stats object or null if not found.
|
|
1004
|
-
*/
|
|
1005
|
-
static async getNotiTypeStatsById(id) {
|
|
1006
|
-
const command = new GetCommand7({
|
|
1007
|
-
TableName: _NotiTypeStats.TABLE_NAME,
|
|
1008
|
-
Key: { id }
|
|
1009
|
-
});
|
|
1010
|
-
try {
|
|
1011
|
-
const result = await ddbDocClient.send(command);
|
|
1012
|
-
return result.Item || null;
|
|
1013
|
-
} catch (error) {
|
|
1014
|
-
console.error("Error fetching notification type stats:", error);
|
|
1015
|
-
throw new Error("Could not fetch notification type stats");
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
/**
|
|
1019
|
-
* Retrieves all notification type stats by entity ID.
|
|
1020
|
-
* @param notiTypeId - The ID of the notification type to retrieve stats for.
|
|
1021
|
-
* @returns A promise that resolves to an array of notification type stats objects or null if not found.
|
|
1022
|
-
*/
|
|
1023
|
-
static async getNotiTypeStatsByNotiTypeId(notiTypeId) {
|
|
1024
|
-
const command = new QueryCommand7({
|
|
1025
|
-
TableName: _NotiTypeStats.TABLE_NAME,
|
|
1026
|
-
IndexName: "NotiTypeIdIndex",
|
|
1027
|
-
// Assuming you have a GSI for notiTypeId
|
|
1028
|
-
KeyConditionExpression: "notiTypeId = :notiTypeId",
|
|
1029
|
-
ExpressionAttributeValues: {
|
|
1030
|
-
":notiTypeId": notiTypeId
|
|
1031
|
-
}
|
|
1032
|
-
});
|
|
1033
|
-
try {
|
|
1034
|
-
const result = await ddbDocClient.send(command);
|
|
1035
|
-
return result.Items || null;
|
|
1036
|
-
} catch (error) {
|
|
1037
|
-
console.error(
|
|
1038
|
-
`Error fetching notification type stats by notiTypeId: ${notiTypeId}`,
|
|
1039
|
-
error
|
|
1040
|
-
);
|
|
1041
|
-
throw new Error("Could not fetch notification type stats by notiTypeId");
|
|
1042
|
-
}
|
|
1043
|
-
}
|
|
1044
|
-
/**
|
|
1045
|
-
* Creates or updates notification type stats.
|
|
1046
|
-
* @param notiTypeStats - The notification type stats object to create or update.
|
|
1047
|
-
* @returns A promise that resolves to the created or updated notification type stats object.
|
|
1048
|
-
*/
|
|
1049
|
-
static async createOrUpdateNotiTypeStats(notiTypeStats) {
|
|
1050
|
-
const command = new PutCommand7({
|
|
1051
|
-
TableName: _NotiTypeStats.TABLE_NAME,
|
|
1052
|
-
Item: notiTypeStats
|
|
1053
|
-
});
|
|
1054
|
-
try {
|
|
1055
|
-
await ddbDocClient.send(command);
|
|
1056
|
-
return notiTypeStats;
|
|
1057
|
-
} catch (error) {
|
|
1058
|
-
console.error(
|
|
1059
|
-
"Error creating or updating notification type stats:",
|
|
1060
|
-
error
|
|
1061
|
-
);
|
|
1062
|
-
throw new Error("Could not create or update notification type stats");
|
|
1063
|
-
}
|
|
1064
|
-
}
|
|
1065
|
-
/**
|
|
1066
|
-
* Deletes notification type stats by their ID.
|
|
1067
|
-
* @param id - The ID of the notification type stats to delete.
|
|
1068
|
-
* @returns A promise that resolves when the deletion is complete.
|
|
1069
|
-
*/
|
|
1070
|
-
static async deleteNotiTypeStatsById(id) {
|
|
1071
|
-
const command = new DeleteCommand7({
|
|
1072
|
-
TableName: _NotiTypeStats.TABLE_NAME,
|
|
1073
|
-
Key: { id }
|
|
1074
|
-
});
|
|
1075
|
-
try {
|
|
1076
|
-
await ddbDocClient.send(command);
|
|
1077
|
-
} catch (error) {
|
|
1078
|
-
console.error("Error deleting notification type stats:", error);
|
|
1079
|
-
throw new Error("Could not delete notification type stats");
|
|
1080
|
-
}
|
|
1081
|
-
}
|
|
1082
|
-
};
|
|
1083
|
-
var NotiTypeStats_default = NotiTypeStats;
|
|
1084
|
-
|
|
1085
|
-
// src/DynamoModels/Views.ts
|
|
1086
|
-
import { QueryCommand as QueryCommand8, PutCommand as PutCommand8 } from "@aws-sdk/lib-dynamodb";
|
|
1087
|
-
var Views = class _Views {
|
|
1088
|
-
static ENV = process.env.ENV || "dev";
|
|
1089
|
-
static TABLE_NAME = `NotiHub-Views-v2-${_Views.ENV}`;
|
|
1090
|
-
/**
|
|
1091
|
-
* Retrieves a view by its ID.
|
|
1092
|
-
* @param id - The ID of the view to retrieve.
|
|
1093
|
-
* @returns A promise that resolves to the view object or null if not found.
|
|
1094
|
-
*/
|
|
1095
|
-
static async getViewByViewId(viewId) {
|
|
1096
|
-
const command = new QueryCommand8({
|
|
1097
|
-
TableName: _Views.TABLE_NAME,
|
|
1098
|
-
IndexName: "ViewIdIndex",
|
|
1099
|
-
// Assuming you have a GSI for viewId
|
|
1100
|
-
KeyConditionExpression: "viewId = :viewId",
|
|
1101
|
-
ExpressionAttributeValues: {
|
|
1102
|
-
":viewId": viewId
|
|
1103
|
-
}
|
|
1104
|
-
});
|
|
1105
|
-
try {
|
|
1106
|
-
const result = await ddbDocClient.send(command);
|
|
1107
|
-
if (!result.Items || result.Items.length === 0) {
|
|
1108
|
-
return null;
|
|
1109
|
-
}
|
|
1110
|
-
return result.Items[0] || null;
|
|
1111
|
-
} catch (error) {
|
|
1112
|
-
console.error("Error fetching view:", error);
|
|
1113
|
-
throw new Error("Could not fetch view");
|
|
1114
|
-
}
|
|
1115
|
-
}
|
|
1116
|
-
/**
|
|
1117
|
-
* Creates or updates a view.
|
|
1118
|
-
* @param view - The view object to create or update.
|
|
1119
|
-
* @returns A promise that resolves to the created or updated view object.
|
|
1120
|
-
*/
|
|
1121
|
-
static async createView(view) {
|
|
1122
|
-
const command = new PutCommand8({
|
|
1123
|
-
TableName: _Views.TABLE_NAME,
|
|
1124
|
-
Item: view
|
|
1125
|
-
});
|
|
1126
|
-
try {
|
|
1127
|
-
await ddbDocClient.send(command);
|
|
1128
|
-
return view;
|
|
1129
|
-
} catch (error) {
|
|
1130
|
-
console.error("Error creating or updating view:", error);
|
|
1131
|
-
throw new Error("Could not create or update view");
|
|
1132
|
-
}
|
|
1133
|
-
}
|
|
1134
|
-
};
|
|
1135
|
-
var Views_default = Views;
|
|
1136
|
-
|
|
1137
|
-
// src/DynamoModels/SubscriptionType.ts
|
|
1138
|
-
import {
|
|
1139
|
-
DeleteCommand as DeleteCommand8,
|
|
1140
|
-
GetCommand as GetCommand8,
|
|
1141
|
-
PutCommand as PutCommand9,
|
|
1142
|
-
QueryCommand as QueryCommand9
|
|
1143
|
-
} from "@aws-sdk/lib-dynamodb";
|
|
1144
|
-
var SubscriptionType = class _SubscriptionType {
|
|
1145
|
-
static ENV = process.env.ENV || "dev";
|
|
1146
|
-
static TABLE_NAME = `NotiHub-SubscriptionTypes-v1-${_SubscriptionType.ENV}`;
|
|
1147
|
-
/**
|
|
1148
|
-
* Retrieves a subscription type by its ID.
|
|
1149
|
-
* @param id - The ID of the subscription type to retrieve.
|
|
1150
|
-
* @returns A promise that resolves to the subscription type object or null if not found.
|
|
1151
|
-
*/
|
|
1152
|
-
static async getSubscriptionTypeById(id) {
|
|
1153
|
-
const command = new GetCommand8({
|
|
1154
|
-
TableName: _SubscriptionType.TABLE_NAME,
|
|
1155
|
-
Key: { id }
|
|
1156
|
-
});
|
|
1157
|
-
try {
|
|
1158
|
-
const result = await ddbDocClient.send(command);
|
|
1159
|
-
return result.Item || null;
|
|
1160
|
-
} catch (error) {
|
|
1161
|
-
console.error("Error fetching subscription type:", error);
|
|
1162
|
-
throw new Error("Could not fetch subscription type");
|
|
1163
|
-
}
|
|
1164
|
-
}
|
|
1165
|
-
static async getSubscriptionTypesByUserId(userId) {
|
|
1166
|
-
const command = new QueryCommand9({
|
|
1167
|
-
TableName: _SubscriptionType.TABLE_NAME,
|
|
1168
|
-
IndexName: "UserIdIndex",
|
|
1169
|
-
// Assuming you have a GSI for userId
|
|
1170
|
-
KeyConditionExpression: "userId = :userId",
|
|
1171
|
-
ExpressionAttributeValues: {
|
|
1172
|
-
":userId": userId
|
|
1173
|
-
}
|
|
1174
|
-
});
|
|
1175
|
-
try {
|
|
1176
|
-
const result = await ddbDocClient.send(command);
|
|
1177
|
-
return result.Items || null;
|
|
1178
|
-
} catch (error) {
|
|
1179
|
-
console.error(
|
|
1180
|
-
`Error fetching subscription types by userId: ${userId}`,
|
|
1181
|
-
error
|
|
1182
|
-
);
|
|
1183
|
-
throw new Error("Could not fetch subscription types by userId");
|
|
1184
|
-
}
|
|
1185
|
-
}
|
|
1186
|
-
/**
|
|
1187
|
-
* Deletes a subscription type by its ID.
|
|
1188
|
-
* @param id - The ID of the subscription type to delete.
|
|
1189
|
-
* @returns A promise that resolves when the subscription type is deleted.
|
|
1190
|
-
*/
|
|
1191
|
-
static async deleteSubscriptionTypeById(id) {
|
|
1192
|
-
const command = new DeleteCommand8({
|
|
1193
|
-
TableName: _SubscriptionType.TABLE_NAME,
|
|
1194
|
-
Key: { id }
|
|
1195
|
-
});
|
|
1196
|
-
try {
|
|
1197
|
-
await ddbDocClient.send(command);
|
|
1198
|
-
} catch (error) {
|
|
1199
|
-
console.error("Error deleting subscription type:", error);
|
|
1200
|
-
throw new Error("Could not delete subscription type");
|
|
1201
|
-
}
|
|
1202
|
-
}
|
|
1203
|
-
/**
|
|
1204
|
-
* Get all subscription types by notifier ID.
|
|
1205
|
-
* @param notiTypeId - The ID of the notifier to retrieve subscription types for.
|
|
1206
|
-
* @returns A promise that resolves to an array of subscription type objects or null if not found.
|
|
1207
|
-
*/
|
|
1208
|
-
static async getSubscriptionTypesByNotifierId(notiTypeId) {
|
|
1209
|
-
const command = new QueryCommand9({
|
|
1210
|
-
TableName: _SubscriptionType.TABLE_NAME,
|
|
1211
|
-
IndexName: "NotiTypeIdIndex",
|
|
1212
|
-
// Assuming you have a GSI for notifierId
|
|
1213
|
-
KeyConditionExpression: "notiTypeId = :notiTypeId",
|
|
1214
|
-
ExpressionAttributeValues: {
|
|
1215
|
-
":notiTypeId": notiTypeId
|
|
1216
|
-
}
|
|
1217
|
-
});
|
|
1218
|
-
try {
|
|
1219
|
-
const result = await ddbDocClient.send(command);
|
|
1220
|
-
return result.Items || null;
|
|
1221
|
-
} catch (error) {
|
|
1222
|
-
console.error(
|
|
1223
|
-
`Error fetching subscription types by notifierId: ${notiTypeId}`,
|
|
1224
|
-
error
|
|
1225
|
-
);
|
|
1226
|
-
throw new Error("Could not fetch subscription types by notifierId");
|
|
1227
|
-
}
|
|
1228
|
-
}
|
|
1229
|
-
/**
|
|
1230
|
-
* Creates a subscription type.
|
|
1231
|
-
* @param subscriptionType - The subscription type object to create.
|
|
1232
|
-
* @returns A promise that resolves to the created subscription type object.
|
|
1233
|
-
*/
|
|
1234
|
-
static async createSubscriptionType(subscriptionType) {
|
|
1235
|
-
const command = new PutCommand9({
|
|
1236
|
-
TableName: _SubscriptionType.TABLE_NAME,
|
|
1237
|
-
Item: subscriptionType
|
|
1238
|
-
});
|
|
1239
|
-
try {
|
|
1240
|
-
await ddbDocClient.send(command);
|
|
1241
|
-
return subscriptionType;
|
|
1242
|
-
} catch (error) {
|
|
1243
|
-
console.error("Error creating subscription type:", error);
|
|
1244
|
-
throw new Error("Could not create subscription type");
|
|
1245
|
-
}
|
|
1246
|
-
}
|
|
1247
|
-
};
|
|
1248
|
-
var SubscriptionType_default = SubscriptionType;
|
|
1249
|
-
|
|
1250
|
-
// src/DynamoModels/CustomerMetaData.ts
|
|
1251
|
-
import {
|
|
1252
|
-
DeleteCommand as DeleteCommand9,
|
|
1253
|
-
GetCommand as GetCommand9,
|
|
1254
|
-
PutCommand as PutCommand10,
|
|
1255
|
-
QueryCommand as QueryCommand10
|
|
1256
|
-
} from "@aws-sdk/lib-dynamodb";
|
|
1257
|
-
var CustomerMetaData = class _CustomerMetaData {
|
|
1258
|
-
static ENV = process.env.ENV || "dev";
|
|
1259
|
-
static TABLE_NAME = `NotiHub-CustomerMetaData-v1-${_CustomerMetaData.ENV}`;
|
|
1260
|
-
/**
|
|
1261
|
-
* Retrieves customer metadata by its ID.
|
|
1262
|
-
* @param id - The ID of the customer metadata to retrieve.
|
|
1263
|
-
* @returns A promise that resolves to the customer metadata object or null if not found.
|
|
1264
|
-
*/
|
|
1265
|
-
static async getCustomerMetaDataById(id) {
|
|
1266
|
-
const command = new GetCommand9({
|
|
1267
|
-
TableName: _CustomerMetaData.TABLE_NAME,
|
|
1268
|
-
Key: { id }
|
|
1269
|
-
});
|
|
1270
|
-
try {
|
|
1271
|
-
const result = await ddbDocClient.send(command);
|
|
1272
|
-
return result.Item || null;
|
|
1273
|
-
} catch (error) {
|
|
1274
|
-
console.error("Error fetching customer metadata:", error);
|
|
1275
|
-
throw new Error("Could not fetch customer metadata");
|
|
1276
|
-
}
|
|
1277
|
-
}
|
|
1278
|
-
/**
|
|
1279
|
-
* Deletes customer metadata by its ID.
|
|
1280
|
-
* @param id - The ID of the customer metadata to delete.
|
|
1281
|
-
* @returns A promise that resolves when the customer metadata is deleted.
|
|
1282
|
-
*/
|
|
1283
|
-
static async deleteCustomerMetaDataById(id) {
|
|
1284
|
-
const command = new DeleteCommand9({
|
|
1285
|
-
TableName: _CustomerMetaData.TABLE_NAME,
|
|
1286
|
-
Key: { id }
|
|
1287
|
-
});
|
|
1288
|
-
try {
|
|
1289
|
-
await ddbDocClient.send(command);
|
|
1290
|
-
} catch (error) {
|
|
1291
|
-
console.error("Error deleting customer metadata:", error);
|
|
1292
|
-
throw new Error("Could not delete customer metadata");
|
|
1293
|
-
}
|
|
1294
|
-
}
|
|
1295
|
-
/**
|
|
1296
|
-
* Retrieve customer metadata by customerId.
|
|
1297
|
-
* @param ids - An array of customer IDs to fetch metadata for.
|
|
1298
|
-
* @returns A promise that resolves to an array of customer metadata objects or null if not found.
|
|
1299
|
-
*/
|
|
1300
|
-
static async getCustomerMetaDataByCustomerId(customerId) {
|
|
1301
|
-
const command = new QueryCommand10({
|
|
1302
|
-
TableName: _CustomerMetaData.TABLE_NAME,
|
|
1303
|
-
// replace with your resolved table name
|
|
1304
|
-
KeyConditionExpression: "customerId = :cid",
|
|
1305
|
-
ExpressionAttributeValues: {
|
|
1306
|
-
":cid": customerId
|
|
1307
|
-
}
|
|
1308
|
-
});
|
|
1309
|
-
try {
|
|
1310
|
-
const result = await ddbDocClient.send(command);
|
|
1311
|
-
if (!result.Items || result.Items.length === 0) {
|
|
1312
|
-
return null;
|
|
1313
|
-
}
|
|
1314
|
-
return result?.Items[0] || null;
|
|
1315
|
-
} catch (error) {
|
|
1316
|
-
console.error("Error fetching customer metadata by customerId:", error);
|
|
1317
|
-
throw new Error("Could not fetch customer metadata by customerId");
|
|
1318
|
-
}
|
|
1319
|
-
}
|
|
1320
|
-
/**
|
|
1321
|
-
* Creates or updates customer metadata.
|
|
1322
|
-
* @param customerMetaData - The customer metadata object to create or update.
|
|
1323
|
-
* @returns A promise that resolves to the created or updated customer metadata object.
|
|
1324
|
-
*/
|
|
1325
|
-
static async createOrUpdateCustomerMetaData(customerMetaData) {
|
|
1326
|
-
const command = new PutCommand10({
|
|
1327
|
-
TableName: _CustomerMetaData.TABLE_NAME,
|
|
1328
|
-
Item: customerMetaData
|
|
1329
|
-
});
|
|
1330
|
-
try {
|
|
1331
|
-
await ddbDocClient.send(command);
|
|
1332
|
-
return customerMetaData;
|
|
1333
|
-
} catch (error) {
|
|
1334
|
-
console.error("Error creating or updating customer metadata:", error);
|
|
1335
|
-
throw new Error("Could not create or update customer metadata");
|
|
1336
|
-
}
|
|
1337
|
-
}
|
|
1338
|
-
};
|
|
1339
|
-
var CustomerMetaData_default = CustomerMetaData;
|
|
1340
|
-
|
|
1341
|
-
// src/DynamoModels/CustomerMinified.ts
|
|
1342
|
-
import {
|
|
1343
|
-
DeleteCommand as DeleteCommand10,
|
|
1344
|
-
GetCommand as GetCommand10,
|
|
1345
|
-
PutCommand as PutCommand11,
|
|
1346
|
-
QueryCommand as QueryCommand11,
|
|
1347
|
-
ScanCommand as ScanCommand2
|
|
1348
|
-
} from "@aws-sdk/lib-dynamodb";
|
|
1349
|
-
var CustomerMinified = class _CustomerMinified {
|
|
1350
|
-
static ENV = process.env.ENV || "dev";
|
|
1351
|
-
static TABLE_NAME = `NotiHub-CustomersMinified-v1-${_CustomerMinified.ENV}`;
|
|
1352
|
-
/**
|
|
1353
|
-
* Retrieves a customer by their ID.
|
|
1354
|
-
* @param id - The ID of the customer to retrieve.
|
|
1355
|
-
* @returns A promise that resolves to the customer object or null if not found.
|
|
1356
|
-
*/
|
|
1357
|
-
static async getCustomerMinifiedById(id) {
|
|
1358
|
-
const command = new GetCommand10({
|
|
1359
|
-
TableName: _CustomerMinified.TABLE_NAME,
|
|
1360
|
-
Key: { id }
|
|
1361
|
-
});
|
|
1362
|
-
try {
|
|
1363
|
-
const result = await ddbDocClient.send(command);
|
|
1364
|
-
return result.Item || null;
|
|
1365
|
-
} catch (error) {
|
|
1366
|
-
console.error("Error fetching customer:", error);
|
|
1367
|
-
throw new Error("Could not fetch customer");
|
|
1368
|
-
}
|
|
1369
|
-
}
|
|
1370
|
-
/**
|
|
1371
|
-
* Searches for customers by their username.
|
|
1372
|
-
* @param username - The username of the customer to search for.
|
|
1373
|
-
* @returns A promise that resolves to an array of customer objects or an empty array if not found.
|
|
1374
|
-
*/
|
|
1375
|
-
static async searchCustomersByUsername(username) {
|
|
1376
|
-
const command = new ScanCommand2({
|
|
1377
|
-
TableName: _CustomerMinified.TABLE_NAME,
|
|
1378
|
-
FilterExpression: "begins_with(username, :uname)",
|
|
1379
|
-
ExpressionAttributeValues: {
|
|
1380
|
-
":uname": username
|
|
1381
|
-
}
|
|
1382
|
-
});
|
|
1383
|
-
try {
|
|
1384
|
-
const result = await ddbDocClient.send(command);
|
|
1385
|
-
return result.Items || [];
|
|
1386
|
-
} catch (error) {
|
|
1387
|
-
console.error("Error searching customers by username:", error);
|
|
1388
|
-
throw new Error("Could not search customers by username");
|
|
1389
|
-
}
|
|
1390
|
-
}
|
|
1391
|
-
/**
|
|
1392
|
-
* Creates or updates a customer minified.
|
|
1393
|
-
* @param customer - The customer object to create or update.
|
|
1394
|
-
* @returns A promise that resolves to the created or updated customer object.
|
|
1395
|
-
*/
|
|
1396
|
-
static async createOrUpdateCustomerMinified(customer) {
|
|
1397
|
-
const command = new PutCommand11({
|
|
1398
|
-
TableName: _CustomerMinified.TABLE_NAME,
|
|
1399
|
-
Item: customer
|
|
1400
|
-
});
|
|
1401
|
-
try {
|
|
1402
|
-
await ddbDocClient.send(command);
|
|
1403
|
-
return customer;
|
|
1404
|
-
} catch (error) {
|
|
1405
|
-
console.error("Error creating or updating customer:", error);
|
|
1406
|
-
throw new Error("Could not create or update customer");
|
|
1407
|
-
}
|
|
1408
|
-
}
|
|
1409
|
-
/**
|
|
1410
|
-
* Delete customer minified by ID.
|
|
1411
|
-
* @param id - The ID of the customer to delete.
|
|
1412
|
-
* @returns A promise that resolves when the customer is deleted.
|
|
1413
|
-
*/
|
|
1414
|
-
static async deleteCustomerMinifiedById(id) {
|
|
1415
|
-
const command = new DeleteCommand10({
|
|
1416
|
-
TableName: _CustomerMinified.TABLE_NAME,
|
|
1417
|
-
Key: { id }
|
|
1418
|
-
});
|
|
1419
|
-
try {
|
|
1420
|
-
await ddbDocClient.send(command);
|
|
1421
|
-
console.log(`Customer with ID ${id} deleted successfully.`);
|
|
1422
|
-
} catch (error) {
|
|
1423
|
-
console.error(`Error deleting customer with ID ${id}:`, error);
|
|
1424
|
-
throw new Error("Could not delete customer");
|
|
1425
|
-
}
|
|
1426
|
-
}
|
|
1427
|
-
/**
|
|
1428
|
-
* Get Customer Minified by username
|
|
1429
|
-
* @param username - The username of the customer to retrieve.
|
|
1430
|
-
* @returns A promise that resolves to the customer object or null if not found.
|
|
1431
|
-
*/
|
|
1432
|
-
static async getCustomerMinifiedByUsername(username) {
|
|
1433
|
-
const command = new QueryCommand11({
|
|
1434
|
-
TableName: _CustomerMinified.TABLE_NAME,
|
|
1435
|
-
// IndexName: "UsernameIndex", // Assuming you have a GSI for username
|
|
1436
|
-
KeyConditionExpression: "username = :username",
|
|
1437
|
-
ExpressionAttributeValues: {
|
|
1438
|
-
":username": username
|
|
1439
|
-
}
|
|
1440
|
-
});
|
|
1441
|
-
try {
|
|
1442
|
-
const result = await ddbDocClient.send(command);
|
|
1443
|
-
if (!result.Items || result.Items.length === 0) {
|
|
1444
|
-
return null;
|
|
1445
|
-
}
|
|
1446
|
-
return result.Items[0] || null;
|
|
1447
|
-
} catch (error) {
|
|
1448
|
-
console.error(`Error fetching customer by username: ${username}`, error);
|
|
1449
|
-
throw new Error("Could not fetch customer by username");
|
|
1450
|
-
}
|
|
1451
|
-
}
|
|
1452
|
-
};
|
|
1453
|
-
var CustomerMinified_default = CustomerMinified;
|
|
1454
|
-
|
|
1455
|
-
// src/DynamoModels/NotificationStats.ts
|
|
1456
|
-
import { DeleteCommand as DeleteCommand11, GetCommand as GetCommand11, PutCommand as PutCommand12 } from "@aws-sdk/lib-dynamodb";
|
|
1457
|
-
var NotificationStats = class _NotificationStats {
|
|
1458
|
-
static ENV = process.env.ENV || "dev";
|
|
1459
|
-
static TABLE_NAME = `NotiHub-NotificationStats-v1-${_NotificationStats.ENV}`;
|
|
1460
|
-
/**
|
|
1461
|
-
* Retrieves notification stats by their ID.
|
|
1462
|
-
* @param id - The ID of the notification stats to retrieve.
|
|
1463
|
-
* @returns A promise that resolves to the notification stats object or null if not found.
|
|
1464
|
-
*/
|
|
1465
|
-
static async getNotificationStatsById(id, customerId) {
|
|
1466
|
-
const command = new GetCommand11({
|
|
1467
|
-
TableName: _NotificationStats.TABLE_NAME,
|
|
1468
|
-
Key: { id, customerId }
|
|
1469
|
-
});
|
|
1470
|
-
try {
|
|
1471
|
-
const result = await ddbDocClient.send(command);
|
|
1472
|
-
return result.Item || null;
|
|
1473
|
-
} catch (error) {
|
|
1474
|
-
console.error("Error fetching notification stats:", error);
|
|
1475
|
-
throw new Error("Could not fetch notification stats");
|
|
1476
|
-
}
|
|
1477
|
-
}
|
|
1478
|
-
/**
|
|
1479
|
-
* Creates a new notification stats entry.
|
|
1480
|
-
* @param stats - The notification stats object to create.
|
|
1481
|
-
* @returns A promise that resolves to the created notification stats object.
|
|
1482
|
-
*/
|
|
1483
|
-
static async createNotificationStats(stats) {
|
|
1484
|
-
const command = new PutCommand12({
|
|
1485
|
-
TableName: _NotificationStats.TABLE_NAME,
|
|
1486
|
-
Item: stats
|
|
1487
|
-
});
|
|
1488
|
-
try {
|
|
1489
|
-
const result = await ddbDocClient.send(command);
|
|
1490
|
-
return result.Attributes;
|
|
1491
|
-
} catch (error) {
|
|
1492
|
-
console.error("Error creating notification stats:", error);
|
|
1493
|
-
throw new Error("Could not create notification stats");
|
|
1494
|
-
}
|
|
1495
|
-
}
|
|
1496
|
-
/**
|
|
1497
|
-
* Deletes a notification stats entry by its ID.
|
|
1498
|
-
* @param id - The ID of the notification stats to delete.
|
|
1499
|
-
* @returns A promise that resolves when the deletion is complete.
|
|
1500
|
-
*/
|
|
1501
|
-
static async deleteNotificationStatsById(id) {
|
|
1502
|
-
const command = new DeleteCommand11({
|
|
1503
|
-
TableName: _NotificationStats.TABLE_NAME,
|
|
1504
|
-
Key: { id }
|
|
1505
|
-
});
|
|
1506
|
-
try {
|
|
1507
|
-
await ddbDocClient.send(command);
|
|
1508
|
-
} catch (error) {
|
|
1509
|
-
console.error("Error deleting notification stats:", error);
|
|
1510
|
-
throw new Error("Could not delete notification stats");
|
|
1511
|
-
}
|
|
1512
|
-
}
|
|
1513
|
-
};
|
|
1514
|
-
var NotificationStats_default = NotificationStats;
|
|
1515
|
-
|
|
1516
|
-
// src/DynamoModels/NotiHubStatsHistory.ts
|
|
1517
|
-
import {
|
|
1518
|
-
PutCommand as PutCommand13,
|
|
1519
|
-
QueryCommand as QueryCommand12
|
|
1520
|
-
} from "@aws-sdk/lib-dynamodb";
|
|
1521
|
-
var NotiHubStatsHistory = class _NotiHubStatsHistory {
|
|
1522
|
-
static ENV = process.env.ENV || "dev";
|
|
1523
|
-
static TABLE_NAME = `NotiHub-StatsHistory-v1-${_NotiHubStatsHistory.ENV}`;
|
|
1524
|
-
/**
|
|
1525
|
-
* Creates a new NotiHub stats history entry.
|
|
1526
|
-
* @param statsHistory - The statistics history object to create.
|
|
1527
|
-
* @returns A promise that resolves to the created statistics history object.
|
|
1528
|
-
*/
|
|
1529
|
-
static async createStatsHistory(statsHistory) {
|
|
1530
|
-
const command = new PutCommand13({
|
|
1531
|
-
TableName: _NotiHubStatsHistory.TABLE_NAME,
|
|
1532
|
-
Item: statsHistory
|
|
1533
|
-
});
|
|
1534
|
-
try {
|
|
1535
|
-
const result = await ddbDocClient.send(command);
|
|
1536
|
-
return result.Attributes;
|
|
1537
|
-
} catch (error) {
|
|
1538
|
-
console.error("Error creating NotiHub stats history:", error);
|
|
1539
|
-
throw new Error("Could not create NotiHub stats history");
|
|
1540
|
-
}
|
|
1541
|
-
}
|
|
1542
|
-
/**
|
|
1543
|
-
* Gets stats history by customerId in the last year
|
|
1544
|
-
* @param customerId - The ID of the customer to retrieve stats history for.
|
|
1545
|
-
* @returns A promise that resolves to an array of statistics history objects or null if not found.
|
|
1546
|
-
*/
|
|
1547
|
-
static async getStatsHistoryPastYearByCustomerId(customerId) {
|
|
1548
|
-
const oneYearAgo = new Date(
|
|
1549
|
-
Date.now() - 365 * 24 * 60 * 60 * 1e3
|
|
1550
|
-
).toISOString();
|
|
1551
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1552
|
-
const command = new QueryCommand12({
|
|
1553
|
-
TableName: _NotiHubStatsHistory.TABLE_NAME,
|
|
1554
|
-
IndexName: "CustomerIdIndex",
|
|
1555
|
-
KeyConditionExpression: "customerId = :customerId AND createdAt BETWEEN :start AND :end",
|
|
1556
|
-
ExpressionAttributeValues: {
|
|
1557
|
-
":customerId": customerId,
|
|
1558
|
-
":start": oneYearAgo,
|
|
1559
|
-
":end": now
|
|
1560
|
-
}
|
|
1561
|
-
});
|
|
1562
|
-
try {
|
|
1563
|
-
const result = await ddbDocClient.send(command);
|
|
1564
|
-
return result.Items || null;
|
|
1565
|
-
} catch (error) {
|
|
1566
|
-
console.error(
|
|
1567
|
-
`Error fetching NotiHub stats history by customerId: ${customerId}`,
|
|
1568
|
-
error
|
|
1569
|
-
);
|
|
1570
|
-
throw new Error("Could not fetch NotiHub stats history by customerId");
|
|
1571
|
-
}
|
|
1572
|
-
}
|
|
1573
|
-
/**
|
|
1574
|
-
* Gets stats history by customerId from last 6 months
|
|
1575
|
-
* @param customerId - The ID of the customer to retrieve stats history for.
|
|
1576
|
-
* @returns A promise that resolves to an array of statistics history objects or null if not found.
|
|
1577
|
-
*/
|
|
1578
|
-
static async getStatsHistoryPastSixMonthsByCustomerId(customerId) {
|
|
1579
|
-
const sixMonthsAgo = new Date(
|
|
1580
|
-
Date.now() - 182 * 24 * 60 * 60 * 1e3
|
|
1581
|
-
).toISOString();
|
|
1582
|
-
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
1583
|
-
const command = new QueryCommand12({
|
|
1584
|
-
TableName: _NotiHubStatsHistory.TABLE_NAME,
|
|
1585
|
-
IndexName: "CustomerIdIndex",
|
|
1586
|
-
KeyConditionExpression: "customerId = :customerId AND createdAt BETWEEN :start AND :end",
|
|
1587
|
-
ExpressionAttributeValues: {
|
|
1588
|
-
":customerId": customerId,
|
|
1589
|
-
":start": sixMonthsAgo,
|
|
1590
|
-
":end": now
|
|
1591
|
-
}
|
|
1592
|
-
});
|
|
1593
|
-
try {
|
|
1594
|
-
const result = await ddbDocClient.send(command);
|
|
1595
|
-
return result.Items || null;
|
|
1596
|
-
} catch (error) {
|
|
1597
|
-
console.error(
|
|
1598
|
-
`Error fetching NotiHub stats history by customerId: ${customerId}`,
|
|
1599
|
-
error
|
|
1600
|
-
);
|
|
1601
|
-
throw new Error("Could not fetch NotiHub stats history by customerId");
|
|
1602
|
-
}
|
|
1603
|
-
}
|
|
1604
|
-
/**
|
|
1605
|
-
* Get last stats history by customerId
|
|
1606
|
-
* @param customerId - The ID of the customer to retrieve stats history for.
|
|
1607
|
-
* @returns A promise that resolves to the last statistics history object or null if not found.
|
|
1608
|
-
*/
|
|
1609
|
-
static async getLastStatsHistoryByCustomerId(customerId) {
|
|
1610
|
-
const command = new QueryCommand12({
|
|
1611
|
-
TableName: _NotiHubStatsHistory.TABLE_NAME,
|
|
1612
|
-
IndexName: "CustomerIdIndex",
|
|
1613
|
-
KeyConditionExpression: "customerId = :customerId",
|
|
1614
|
-
ExpressionAttributeValues: {
|
|
1615
|
-
":customerId": customerId
|
|
1616
|
-
},
|
|
1617
|
-
ScanIndexForward: false,
|
|
1618
|
-
// Get the latest entry first
|
|
1619
|
-
Limit: 1
|
|
1620
|
-
// Only get the last entry
|
|
1621
|
-
});
|
|
1622
|
-
try {
|
|
1623
|
-
const result = await ddbDocClient.send(command);
|
|
1624
|
-
if (result.Items && result.Items.length > 0) {
|
|
1625
|
-
return result.Items[0];
|
|
1626
|
-
}
|
|
1627
|
-
return null;
|
|
1628
|
-
} catch (error) {
|
|
1629
|
-
console.error(
|
|
1630
|
-
`Error fetching last NotiHub stats history by customerId: ${customerId}`,
|
|
1631
|
-
error
|
|
1632
|
-
);
|
|
1633
|
-
throw new Error(
|
|
1634
|
-
"Could not fetch last NotiHub stats history by customerId"
|
|
1635
|
-
);
|
|
1636
|
-
}
|
|
1637
|
-
}
|
|
1638
|
-
};
|
|
1639
|
-
var NotiHubStatsHistory_default = NotiHubStatsHistory;
|
|
1640
|
-
|
|
1641
|
-
// src/DynamoModels/index.ts
|
|
1642
|
-
var TABLES = {
|
|
1643
|
-
User: User_default,
|
|
1644
|
-
Customer: Customer_default,
|
|
1645
|
-
Notifications: Notifications_default,
|
|
1646
|
-
NotiHubStats: NotiHubStats_default,
|
|
1647
|
-
NotiType: NotiType_default,
|
|
1648
|
-
Subscription: Subscription_default,
|
|
1649
|
-
NotiTypeStats: NotiTypeStats_default,
|
|
1650
|
-
Views: Views_default,
|
|
1651
|
-
SubscriptionType: SubscriptionType_default,
|
|
1652
|
-
CustomerMetaData: CustomerMetaData_default,
|
|
1653
|
-
CustomerMinified: CustomerMinified_default,
|
|
1654
|
-
NotificationStats: NotificationStats_default,
|
|
1655
|
-
NotiHubStatsHistory: NotiHubStatsHistory_default
|
|
1656
|
-
};
|
|
1657
|
-
|
|
1658
|
-
// src/errorcodes.ts
|
|
1659
|
-
var errorcodes_exports = {};
|
|
1660
|
-
__export(errorcodes_exports, {
|
|
1661
|
-
CustomerNotFound: () => CustomerNotFound,
|
|
1662
|
-
DocumentNotFound: () => DocumentNotFound,
|
|
1663
|
-
InvalidDate: () => InvalidDate,
|
|
1664
|
-
InvalidEmail: () => InvalidEmail,
|
|
1665
|
-
InvalidName: () => InvalidName,
|
|
1666
|
-
InvalidPassword: () => InvalidPassword,
|
|
1667
|
-
InvalidPhoneNumber: () => InvalidPhoneNumber,
|
|
1668
|
-
InvalidPushToken: () => InvalidPushToken,
|
|
1669
|
-
UserNotFound: () => UserNotFound
|
|
1670
|
-
});
|
|
1671
|
-
var DocumentNotFound = "4001";
|
|
1672
|
-
var UserNotFound = "4002";
|
|
1673
|
-
var CustomerNotFound = "4003";
|
|
1674
|
-
var InvalidEmail = "4006";
|
|
1675
|
-
var InvalidPassword = "4007";
|
|
1676
|
-
var InvalidName = "4008";
|
|
1677
|
-
var InvalidPushToken = "4009";
|
|
1678
|
-
var InvalidPhoneNumber = "4010";
|
|
1679
|
-
var InvalidDate = "4011";
|
|
1680
|
-
export {
|
|
1681
|
-
DocumentNotFoundException,
|
|
1682
|
-
errorcodes_exports as ErrorCode,
|
|
1683
|
-
MongooseClient_default as MongooseClient,
|
|
1684
|
-
TABLES,
|
|
1685
|
-
addMonths,
|
|
1686
|
-
formatResponse,
|
|
1687
|
-
getDate,
|
|
1688
|
-
getDateFormat,
|
|
1689
|
-
handleError,
|
|
1690
|
-
handleSuccess
|
|
1691
|
-
};
|