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