@amohamud23/notihub 1.1.18 → 1.1.20

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 CHANGED
@@ -267,15 +267,30 @@ var User = class _User {
267
267
  * @returns A promise that resolves to the updated user object.
268
268
  */
269
269
  static async updateUser(id, user) {
270
+ const updateFields = Object.keys(user);
271
+ if (updateFields.length === 0) {
272
+ throw new Error("No fields provided to update.");
273
+ }
274
+ const UpdateExpression = `SET ${updateFields.map((field, idx) => `#field${idx} = :value${idx}`).join(", ")}`;
275
+ const ExpressionAttributeNames = updateFields.reduce((acc, field, idx) => {
276
+ acc[`#field${idx}`] = field;
277
+ return acc;
278
+ }, {});
279
+ const ExpressionAttributeValues = updateFields.reduce((acc, field, idx) => {
280
+ acc[`:value${idx}`] = user[field];
281
+ return acc;
282
+ }, {});
270
283
  const command = new import_lib_dynamodb2.UpdateCommand({
271
284
  TableName: _User.TABLE_NAME,
272
- Key: {
273
- id
274
- }
285
+ Key: { id },
286
+ UpdateExpression,
287
+ ExpressionAttributeNames,
288
+ ExpressionAttributeValues,
289
+ ReturnValues: "ALL_NEW"
275
290
  });
276
291
  try {
277
- await ddbDocClient.send(command);
278
- return user;
292
+ const result = await ddbDocClient.send(command);
293
+ return result.Attributes;
279
294
  } catch (error) {
280
295
  console.error("Error updating user: ", error);
281
296
  throw new Error("Could not update user");
@@ -1071,20 +1086,28 @@ var NotiTypeStats_default = NotiTypeStats;
1071
1086
  var import_lib_dynamodb9 = require("@aws-sdk/lib-dynamodb");
1072
1087
  var Views = class _Views {
1073
1088
  static ENV = process.env.ENV || "dev";
1074
- static TABLE_NAME = `NotiHub-Views-v1-${_Views.ENV}`;
1089
+ static TABLE_NAME = `NotiHub-Views-v2-${_Views.ENV}`;
1075
1090
  /**
1076
1091
  * Retrieves a view by its ID.
1077
1092
  * @param id - The ID of the view to retrieve.
1078
1093
  * @returns A promise that resolves to the view object or null if not found.
1079
1094
  */
1080
- static async getViewById(id) {
1081
- const command = new import_lib_dynamodb9.GetCommand({
1095
+ static async getViewByViewId(viewId) {
1096
+ const command = new import_lib_dynamodb9.QueryCommand({
1082
1097
  TableName: _Views.TABLE_NAME,
1083
- Key: { id }
1098
+ IndexName: "ViewIdIndex",
1099
+ // Assuming you have a GSI for viewId
1100
+ KeyConditionExpression: "viewId = :viewId",
1101
+ ExpressionAttributeValues: {
1102
+ ":viewId": viewId
1103
+ }
1084
1104
  });
1085
1105
  try {
1086
1106
  const result = await ddbDocClient.send(command);
1087
- return result.Item || null;
1107
+ if (!result.Items || result.Items.length === 0) {
1108
+ return null;
1109
+ }
1110
+ return result.Items[0] || null;
1088
1111
  } catch (error) {
1089
1112
  console.error("Error fetching view:", error);
1090
1113
  throw new Error("Could not fetch view");
package/dist/index.d.cts CHANGED
@@ -287,7 +287,7 @@ declare class User {
287
287
  * @param user - The user object to update.
288
288
  * @returns A promise that resolves to the updated user object.
289
289
  */
290
- static updateUser(id: string, user: INotiHubUser): Promise<INotiHubUser>;
290
+ static updateUser(id: string, user: Partial<INotiHubUser>): Promise<INotiHubUser>;
291
291
  /**
292
292
  * Deletes a user by their ID.
293
293
  * @param id - The ID of the user to delete.
@@ -510,7 +510,7 @@ declare class Views {
510
510
  * @param id - The ID of the view to retrieve.
511
511
  * @returns A promise that resolves to the view object or null if not found.
512
512
  */
513
- static getViewById(id: string): Promise<INotiHubUserView | null>;
513
+ static getViewByViewId(viewId: string): Promise<INotiHubUserView | null>;
514
514
  /**
515
515
  * Creates or updates a view.
516
516
  * @param view - The view object to create or update.
package/dist/index.d.ts CHANGED
@@ -287,7 +287,7 @@ declare class User {
287
287
  * @param user - The user object to update.
288
288
  * @returns A promise that resolves to the updated user object.
289
289
  */
290
- static updateUser(id: string, user: INotiHubUser): Promise<INotiHubUser>;
290
+ static updateUser(id: string, user: Partial<INotiHubUser>): Promise<INotiHubUser>;
291
291
  /**
292
292
  * Deletes a user by their ID.
293
293
  * @param id - The ID of the user to delete.
@@ -510,7 +510,7 @@ declare class Views {
510
510
  * @param id - The ID of the view to retrieve.
511
511
  * @returns A promise that resolves to the view object or null if not found.
512
512
  */
513
- static getViewById(id: string): Promise<INotiHubUserView | null>;
513
+ static getViewByViewId(viewId: string): Promise<INotiHubUserView | null>;
514
514
  /**
515
515
  * Creates or updates a view.
516
516
  * @param view - The view object to create or update.
package/dist/index.js CHANGED
@@ -234,15 +234,30 @@ var User = class _User {
234
234
  * @returns A promise that resolves to the updated user object.
235
235
  */
236
236
  static async updateUser(id, user) {
237
+ const updateFields = Object.keys(user);
238
+ if (updateFields.length === 0) {
239
+ throw new Error("No fields provided to update.");
240
+ }
241
+ const UpdateExpression = `SET ${updateFields.map((field, idx) => `#field${idx} = :value${idx}`).join(", ")}`;
242
+ const ExpressionAttributeNames = updateFields.reduce((acc, field, idx) => {
243
+ acc[`#field${idx}`] = field;
244
+ return acc;
245
+ }, {});
246
+ const ExpressionAttributeValues = updateFields.reduce((acc, field, idx) => {
247
+ acc[`:value${idx}`] = user[field];
248
+ return acc;
249
+ }, {});
237
250
  const command = new UpdateCommand({
238
251
  TableName: _User.TABLE_NAME,
239
- Key: {
240
- id
241
- }
252
+ Key: { id },
253
+ UpdateExpression,
254
+ ExpressionAttributeNames,
255
+ ExpressionAttributeValues,
256
+ ReturnValues: "ALL_NEW"
242
257
  });
243
258
  try {
244
- await ddbDocClient.send(command);
245
- return user;
259
+ const result = await ddbDocClient.send(command);
260
+ return result.Attributes;
246
261
  } catch (error) {
247
262
  console.error("Error updating user: ", error);
248
263
  throw new Error("Could not update user");
@@ -1066,26 +1081,31 @@ var NotiTypeStats = class _NotiTypeStats {
1066
1081
  var NotiTypeStats_default = NotiTypeStats;
1067
1082
 
1068
1083
  // src/DynamoModels/Views.ts
1069
- import {
1070
- GetCommand as GetCommand8,
1071
- PutCommand as PutCommand8
1072
- } from "@aws-sdk/lib-dynamodb";
1084
+ import { QueryCommand as QueryCommand8, PutCommand as PutCommand8 } from "@aws-sdk/lib-dynamodb";
1073
1085
  var Views = class _Views {
1074
1086
  static ENV = process.env.ENV || "dev";
1075
- static TABLE_NAME = `NotiHub-Views-v1-${_Views.ENV}`;
1087
+ static TABLE_NAME = `NotiHub-Views-v2-${_Views.ENV}`;
1076
1088
  /**
1077
1089
  * Retrieves a view by its ID.
1078
1090
  * @param id - The ID of the view to retrieve.
1079
1091
  * @returns A promise that resolves to the view object or null if not found.
1080
1092
  */
1081
- static async getViewById(id) {
1082
- const command = new GetCommand8({
1093
+ static async getViewByViewId(viewId) {
1094
+ const command = new QueryCommand8({
1083
1095
  TableName: _Views.TABLE_NAME,
1084
- Key: { id }
1096
+ IndexName: "ViewIdIndex",
1097
+ // Assuming you have a GSI for viewId
1098
+ KeyConditionExpression: "viewId = :viewId",
1099
+ ExpressionAttributeValues: {
1100
+ ":viewId": viewId
1101
+ }
1085
1102
  });
1086
1103
  try {
1087
1104
  const result = await ddbDocClient.send(command);
1088
- return result.Item || null;
1105
+ if (!result.Items || result.Items.length === 0) {
1106
+ return null;
1107
+ }
1108
+ return result.Items[0] || null;
1089
1109
  } catch (error) {
1090
1110
  console.error("Error fetching view:", error);
1091
1111
  throw new Error("Could not fetch view");
@@ -1114,8 +1134,8 @@ var Views_default = Views;
1114
1134
 
1115
1135
  // src/DynamoModels/SubscriptionType.ts
1116
1136
  import {
1117
- DeleteCommand as DeleteCommand9,
1118
- GetCommand as GetCommand9,
1137
+ DeleteCommand as DeleteCommand8,
1138
+ GetCommand as GetCommand8,
1119
1139
  PutCommand as PutCommand9,
1120
1140
  QueryCommand as QueryCommand9
1121
1141
  } from "@aws-sdk/lib-dynamodb";
@@ -1128,7 +1148,7 @@ var SubscriptionType = class _SubscriptionType {
1128
1148
  * @returns A promise that resolves to the subscription type object or null if not found.
1129
1149
  */
1130
1150
  static async getSubscriptionTypeById(id) {
1131
- const command = new GetCommand9({
1151
+ const command = new GetCommand8({
1132
1152
  TableName: _SubscriptionType.TABLE_NAME,
1133
1153
  Key: { id }
1134
1154
  });
@@ -1167,7 +1187,7 @@ var SubscriptionType = class _SubscriptionType {
1167
1187
  * @returns A promise that resolves when the subscription type is deleted.
1168
1188
  */
1169
1189
  static async deleteSubscriptionTypeById(id) {
1170
- const command = new DeleteCommand9({
1190
+ const command = new DeleteCommand8({
1171
1191
  TableName: _SubscriptionType.TABLE_NAME,
1172
1192
  Key: { id }
1173
1193
  });
@@ -1227,8 +1247,8 @@ var SubscriptionType_default = SubscriptionType;
1227
1247
 
1228
1248
  // src/DynamoModels/CustomerMetaData.ts
1229
1249
  import {
1230
- DeleteCommand as DeleteCommand10,
1231
- GetCommand as GetCommand10,
1250
+ DeleteCommand as DeleteCommand9,
1251
+ GetCommand as GetCommand9,
1232
1252
  PutCommand as PutCommand10,
1233
1253
  QueryCommand as QueryCommand10
1234
1254
  } from "@aws-sdk/lib-dynamodb";
@@ -1241,7 +1261,7 @@ var CustomerMetaData = class _CustomerMetaData {
1241
1261
  * @returns A promise that resolves to the customer metadata object or null if not found.
1242
1262
  */
1243
1263
  static async getCustomerMetaDataById(id) {
1244
- const command = new GetCommand10({
1264
+ const command = new GetCommand9({
1245
1265
  TableName: _CustomerMetaData.TABLE_NAME,
1246
1266
  Key: { id }
1247
1267
  });
@@ -1259,7 +1279,7 @@ var CustomerMetaData = class _CustomerMetaData {
1259
1279
  * @returns A promise that resolves when the customer metadata is deleted.
1260
1280
  */
1261
1281
  static async deleteCustomerMetaDataById(id) {
1262
- const command = new DeleteCommand10({
1282
+ const command = new DeleteCommand9({
1263
1283
  TableName: _CustomerMetaData.TABLE_NAME,
1264
1284
  Key: { id }
1265
1285
  });
@@ -1318,8 +1338,8 @@ var CustomerMetaData_default = CustomerMetaData;
1318
1338
 
1319
1339
  // src/DynamoModels/CustomerMinified.ts
1320
1340
  import {
1321
- DeleteCommand as DeleteCommand11,
1322
- GetCommand as GetCommand11,
1341
+ DeleteCommand as DeleteCommand10,
1342
+ GetCommand as GetCommand10,
1323
1343
  PutCommand as PutCommand11,
1324
1344
  QueryCommand as QueryCommand11,
1325
1345
  ScanCommand as ScanCommand2
@@ -1333,7 +1353,7 @@ var CustomerMinified = class _CustomerMinified {
1333
1353
  * @returns A promise that resolves to the customer object or null if not found.
1334
1354
  */
1335
1355
  static async getCustomerMinifiedById(id) {
1336
- const command = new GetCommand11({
1356
+ const command = new GetCommand10({
1337
1357
  TableName: _CustomerMinified.TABLE_NAME,
1338
1358
  Key: { id }
1339
1359
  });
@@ -1390,7 +1410,7 @@ var CustomerMinified = class _CustomerMinified {
1390
1410
  * @returns A promise that resolves when the customer is deleted.
1391
1411
  */
1392
1412
  static async deleteCustomerMinifiedById(id) {
1393
- const command = new DeleteCommand11({
1413
+ const command = new DeleteCommand10({
1394
1414
  TableName: _CustomerMinified.TABLE_NAME,
1395
1415
  Key: { id }
1396
1416
  });
@@ -1431,7 +1451,7 @@ var CustomerMinified = class _CustomerMinified {
1431
1451
  var CustomerMinified_default = CustomerMinified;
1432
1452
 
1433
1453
  // src/DynamoModels/NotificationStats.ts
1434
- import { DeleteCommand as DeleteCommand12, GetCommand as GetCommand12, PutCommand as PutCommand12 } from "@aws-sdk/lib-dynamodb";
1454
+ import { DeleteCommand as DeleteCommand11, GetCommand as GetCommand11, PutCommand as PutCommand12 } from "@aws-sdk/lib-dynamodb";
1435
1455
  var NotificationStats = class _NotificationStats {
1436
1456
  static ENV = process.env.ENV || "dev";
1437
1457
  static TABLE_NAME = `NotiHub-NotificationStats-v1-${_NotificationStats.ENV}`;
@@ -1441,7 +1461,7 @@ var NotificationStats = class _NotificationStats {
1441
1461
  * @returns A promise that resolves to the notification stats object or null if not found.
1442
1462
  */
1443
1463
  static async getNotificationStatsById(id, customerId) {
1444
- const command = new GetCommand12({
1464
+ const command = new GetCommand11({
1445
1465
  TableName: _NotificationStats.TABLE_NAME,
1446
1466
  Key: { id, customerId }
1447
1467
  });
@@ -1477,7 +1497,7 @@ var NotificationStats = class _NotificationStats {
1477
1497
  * @returns A promise that resolves when the deletion is complete.
1478
1498
  */
1479
1499
  static async deleteNotificationStatsById(id) {
1480
- const command = new DeleteCommand12({
1500
+ const command = new DeleteCommand11({
1481
1501
  TableName: _NotificationStats.TABLE_NAME,
1482
1502
  Key: { id }
1483
1503
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amohamud23/notihub",
3
- "version": "1.1.18",
3
+ "version": "1.1.20",
4
4
  "description": "Notihub Package",
5
5
  "main": "./dist/index.cjs",
6
6
  "types": "./dist/index.d.cts",