@amohamud23/notihub 1.1.24 → 1.1.26

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
@@ -347,6 +347,22 @@ var import_lib_dynamodb3 = require("@aws-sdk/lib-dynamodb");
347
347
  var Customer = class _Customer {
348
348
  static ENV = process.env.ENV || "dev";
349
349
  static TABLE_NAME = `NotiHub-Customers-v1-${_Customer.ENV}`;
350
+ /**
351
+ * Retrieves a list of all customers.
352
+ * @returns A promise that resolves to an array of customer objects.
353
+ */
354
+ static async getAllCustomers() {
355
+ const command = new import_lib_dynamodb3.ScanCommand({
356
+ TableName: _Customer.TABLE_NAME
357
+ });
358
+ try {
359
+ const result = await ddbDocClient.send(command);
360
+ return result.Items || [];
361
+ } catch (error) {
362
+ console.error("Error fetching all customers:", error);
363
+ throw new Error("Could not fetch customers");
364
+ }
365
+ }
350
366
  /**
351
367
  * Retrieves a customer by their ID.
352
368
  * @param id - The ID of the customer to retrieve.
@@ -653,6 +669,25 @@ var NotiHubStats = class _NotiHubStats {
653
669
  const result = await ddbDocClient.send(command);
654
670
  return result.Attributes;
655
671
  }
672
+ /**
673
+ * Decrement the count of subscriptions for a specific customer.
674
+ * @param id - The ID of the stats entry.
675
+ * @param customerId - The ID of the customer.
676
+ * @returns A promise that resolves to the updated stats object.
677
+ */
678
+ static async decrementSubscriptions(id, customerId) {
679
+ const command = new import_lib_dynamodb5.UpdateCommand({
680
+ TableName: _NotiHubStats.TABLE_NAME,
681
+ Key: { id, customerId },
682
+ UpdateExpression: "ADD subscriptions :dec",
683
+ ExpressionAttributeValues: {
684
+ ":dec": -1
685
+ },
686
+ ReturnValues: "ALL_NEW"
687
+ });
688
+ const result = await ddbDocClient.send(command);
689
+ return result.Attributes;
690
+ }
656
691
  static async getStatsInDateRange(customerId, startDate, endDate) {
657
692
  const command = new import_lib_dynamodb5.QueryCommand({
658
693
  TableName: _NotiHubStats.TABLE_NAME,
@@ -1081,6 +1116,72 @@ var NotiTypeStats = class _NotiTypeStats {
1081
1116
  throw new Error("Could not delete notification type stats");
1082
1117
  }
1083
1118
  }
1119
+ /**
1120
+ * Increment the count of subscriptions for a specific notification type.
1121
+ * @param id - The ID of the notification type stats entry.
1122
+ */
1123
+ static async incrementSubscriptions(id) {
1124
+ const command = new import_lib_dynamodb8.UpdateCommand({
1125
+ TableName: _NotiTypeStats.TABLE_NAME,
1126
+ Key: { id },
1127
+ UpdateExpression: "ADD subscribed :inc",
1128
+ ExpressionAttributeValues: {
1129
+ ":inc": 1
1130
+ },
1131
+ ReturnValues: "ALL_NEW"
1132
+ });
1133
+ try {
1134
+ const result = await ddbDocClient.send(command);
1135
+ return result.Attributes;
1136
+ } catch (error) {
1137
+ console.error("Error incrementing subscriptions:", error);
1138
+ throw new Error("Could not increment subscriptions");
1139
+ }
1140
+ }
1141
+ /**
1142
+ * Decrement the count of subscriptions for a specific notification type.
1143
+ * @param id - The ID of the notification type stats entry.
1144
+ */
1145
+ static async decrementSubscriptions(id) {
1146
+ const command = new import_lib_dynamodb8.UpdateCommand({
1147
+ TableName: _NotiTypeStats.TABLE_NAME,
1148
+ Key: { id },
1149
+ UpdateExpression: "ADD subscribed :dec",
1150
+ ExpressionAttributeValues: {
1151
+ ":dec": -1
1152
+ },
1153
+ ReturnValues: "ALL_NEW"
1154
+ });
1155
+ try {
1156
+ const result = await ddbDocClient.send(command);
1157
+ return result.Attributes;
1158
+ } catch (error) {
1159
+ console.error("Error decrementing subscriptions:", error);
1160
+ throw new Error("Could not decrement subscriptions");
1161
+ }
1162
+ }
1163
+ /**
1164
+ * Increment the count of views for a specific notification type.
1165
+ * @param id - The ID of the notification type stats entry.
1166
+ */
1167
+ static async incrementViews(id) {
1168
+ const command = new import_lib_dynamodb8.UpdateCommand({
1169
+ TableName: _NotiTypeStats.TABLE_NAME,
1170
+ Key: { id },
1171
+ UpdateExpression: "ADD views :inc",
1172
+ ExpressionAttributeValues: {
1173
+ ":inc": 1
1174
+ },
1175
+ ReturnValues: "ALL_NEW"
1176
+ });
1177
+ try {
1178
+ const result = await ddbDocClient.send(command);
1179
+ return result.Attributes;
1180
+ } catch (error) {
1181
+ console.error("Error incrementing views:", error);
1182
+ throw new Error("Could not increment views");
1183
+ }
1184
+ }
1084
1185
  };
1085
1186
  var NotiTypeStats_default = NotiTypeStats;
1086
1187
 
package/dist/index.d.cts CHANGED
@@ -307,6 +307,11 @@ declare class User {
307
307
  declare class Customer {
308
308
  static ENV: string;
309
309
  static TABLE_NAME: string;
310
+ /**
311
+ * Retrieves a list of all customers.
312
+ * @returns A promise that resolves to an array of customer objects.
313
+ */
314
+ static getAllCustomers(): Promise<INotiHubCustomer[]>;
310
315
  /**
311
316
  * Retrieves a customer by their ID.
312
317
  * @param id - The ID of the customer to retrieve.
@@ -389,6 +394,13 @@ declare class NotiHubStats {
389
394
  * @returns A promise that resolves to the updated stats object.
390
395
  */
391
396
  static incrementSubscriptions(id: string, customerId: string): Promise<INotiHubStats>;
397
+ /**
398
+ * Decrement the count of subscriptions for a specific customer.
399
+ * @param id - The ID of the stats entry.
400
+ * @param customerId - The ID of the customer.
401
+ * @returns A promise that resolves to the updated stats object.
402
+ */
403
+ static decrementSubscriptions(id: string, customerId: string): Promise<INotiHubStats>;
392
404
  static getStatsInDateRange(customerId: string, startDate: string, endDate: string): Promise<INotiHubStats[]>;
393
405
  static deleteStatsById(id: string): Promise<void>;
394
406
  }
@@ -501,6 +513,21 @@ declare class NotiTypeStats {
501
513
  * @returns A promise that resolves when the deletion is complete.
502
514
  */
503
515
  static deleteNotiTypeStatsById(id: string): Promise<void>;
516
+ /**
517
+ * Increment the count of subscriptions for a specific notification type.
518
+ * @param id - The ID of the notification type stats entry.
519
+ */
520
+ static incrementSubscriptions(id: string): Promise<INotiTypeStats>;
521
+ /**
522
+ * Decrement the count of subscriptions for a specific notification type.
523
+ * @param id - The ID of the notification type stats entry.
524
+ */
525
+ static decrementSubscriptions(id: string): Promise<INotiTypeStats>;
526
+ /**
527
+ * Increment the count of views for a specific notification type.
528
+ * @param id - The ID of the notification type stats entry.
529
+ */
530
+ static incrementViews(id: string): Promise<INotiTypeStats>;
504
531
  }
505
532
 
506
533
  declare class Views {
package/dist/index.d.ts CHANGED
@@ -307,6 +307,11 @@ declare class User {
307
307
  declare class Customer {
308
308
  static ENV: string;
309
309
  static TABLE_NAME: string;
310
+ /**
311
+ * Retrieves a list of all customers.
312
+ * @returns A promise that resolves to an array of customer objects.
313
+ */
314
+ static getAllCustomers(): Promise<INotiHubCustomer[]>;
310
315
  /**
311
316
  * Retrieves a customer by their ID.
312
317
  * @param id - The ID of the customer to retrieve.
@@ -389,6 +394,13 @@ declare class NotiHubStats {
389
394
  * @returns A promise that resolves to the updated stats object.
390
395
  */
391
396
  static incrementSubscriptions(id: string, customerId: string): Promise<INotiHubStats>;
397
+ /**
398
+ * Decrement the count of subscriptions for a specific customer.
399
+ * @param id - The ID of the stats entry.
400
+ * @param customerId - The ID of the customer.
401
+ * @returns A promise that resolves to the updated stats object.
402
+ */
403
+ static decrementSubscriptions(id: string, customerId: string): Promise<INotiHubStats>;
392
404
  static getStatsInDateRange(customerId: string, startDate: string, endDate: string): Promise<INotiHubStats[]>;
393
405
  static deleteStatsById(id: string): Promise<void>;
394
406
  }
@@ -501,6 +513,21 @@ declare class NotiTypeStats {
501
513
  * @returns A promise that resolves when the deletion is complete.
502
514
  */
503
515
  static deleteNotiTypeStatsById(id: string): Promise<void>;
516
+ /**
517
+ * Increment the count of subscriptions for a specific notification type.
518
+ * @param id - The ID of the notification type stats entry.
519
+ */
520
+ static incrementSubscriptions(id: string): Promise<INotiTypeStats>;
521
+ /**
522
+ * Decrement the count of subscriptions for a specific notification type.
523
+ * @param id - The ID of the notification type stats entry.
524
+ */
525
+ static decrementSubscriptions(id: string): Promise<INotiTypeStats>;
526
+ /**
527
+ * Increment the count of views for a specific notification type.
528
+ * @param id - The ID of the notification type stats entry.
529
+ */
530
+ static incrementViews(id: string): Promise<INotiTypeStats>;
504
531
  }
505
532
 
506
533
  declare class Views {
package/dist/index.js CHANGED
@@ -315,11 +315,28 @@ import {
315
315
  GetCommand as GetCommand2,
316
316
  PutCommand as PutCommand2,
317
317
  QueryCommand as QueryCommand2,
318
- UpdateCommand as UpdateCommand2
318
+ UpdateCommand as UpdateCommand2,
319
+ ScanCommand
319
320
  } from "@aws-sdk/lib-dynamodb";
320
321
  var Customer = class _Customer {
321
322
  static ENV = process.env.ENV || "dev";
322
323
  static TABLE_NAME = `NotiHub-Customers-v1-${_Customer.ENV}`;
324
+ /**
325
+ * Retrieves a list of all customers.
326
+ * @returns A promise that resolves to an array of customer objects.
327
+ */
328
+ static async getAllCustomers() {
329
+ const command = new ScanCommand({
330
+ TableName: _Customer.TABLE_NAME
331
+ });
332
+ try {
333
+ const result = await ddbDocClient.send(command);
334
+ return result.Items || [];
335
+ } catch (error) {
336
+ console.error("Error fetching all customers:", error);
337
+ throw new Error("Could not fetch customers");
338
+ }
339
+ }
323
340
  /**
324
341
  * Retrieves a customer by their ID.
325
342
  * @param id - The ID of the customer to retrieve.
@@ -634,6 +651,25 @@ var NotiHubStats = class _NotiHubStats {
634
651
  const result = await ddbDocClient.send(command);
635
652
  return result.Attributes;
636
653
  }
654
+ /**
655
+ * Decrement the count of subscriptions for a specific customer.
656
+ * @param id - The ID of the stats entry.
657
+ * @param customerId - The ID of the customer.
658
+ * @returns A promise that resolves to the updated stats object.
659
+ */
660
+ static async decrementSubscriptions(id, customerId) {
661
+ const command = new UpdateCommand4({
662
+ TableName: _NotiHubStats.TABLE_NAME,
663
+ Key: { id, customerId },
664
+ UpdateExpression: "ADD subscriptions :dec",
665
+ ExpressionAttributeValues: {
666
+ ":dec": -1
667
+ },
668
+ ReturnValues: "ALL_NEW"
669
+ });
670
+ const result = await ddbDocClient.send(command);
671
+ return result.Attributes;
672
+ }
637
673
  static async getStatsInDateRange(customerId, startDate, endDate) {
638
674
  const command = new QueryCommand4({
639
675
  TableName: _NotiHubStats.TABLE_NAME,
@@ -671,7 +707,7 @@ import {
671
707
  DeleteCommand as DeleteCommand5,
672
708
  PutCommand as PutCommand5,
673
709
  QueryCommand as QueryCommand5,
674
- ScanCommand,
710
+ ScanCommand as ScanCommand2,
675
711
  UpdateCommand as UpdateCommand5
676
712
  } from "@aws-sdk/lib-dynamodb";
677
713
  var NotiType = class _NotiType {
@@ -802,7 +838,7 @@ var NotiType = class _NotiType {
802
838
  do {
803
839
  const scanResult = await ddbDocClient.send(
804
840
  // TODO: update type
805
- new ScanCommand({
841
+ new ScanCommand2({
806
842
  TableName: _NotiType.TABLE_NAME,
807
843
  FilterExpression: "customerId = :customerId",
808
844
  ExpressionAttributeValues: {
@@ -992,7 +1028,8 @@ import {
992
1028
  DeleteCommand as DeleteCommand7,
993
1029
  GetCommand as GetCommand7,
994
1030
  PutCommand as PutCommand7,
995
- QueryCommand as QueryCommand7
1031
+ QueryCommand as QueryCommand7,
1032
+ UpdateCommand as UpdateCommand7
996
1033
  } from "@aws-sdk/lib-dynamodb";
997
1034
  var NotiTypeStats = class _NotiTypeStats {
998
1035
  static ENV = process.env.ENV || "dev";
@@ -1079,6 +1116,72 @@ var NotiTypeStats = class _NotiTypeStats {
1079
1116
  throw new Error("Could not delete notification type stats");
1080
1117
  }
1081
1118
  }
1119
+ /**
1120
+ * Increment the count of subscriptions for a specific notification type.
1121
+ * @param id - The ID of the notification type stats entry.
1122
+ */
1123
+ static async incrementSubscriptions(id) {
1124
+ const command = new UpdateCommand7({
1125
+ TableName: _NotiTypeStats.TABLE_NAME,
1126
+ Key: { id },
1127
+ UpdateExpression: "ADD subscribed :inc",
1128
+ ExpressionAttributeValues: {
1129
+ ":inc": 1
1130
+ },
1131
+ ReturnValues: "ALL_NEW"
1132
+ });
1133
+ try {
1134
+ const result = await ddbDocClient.send(command);
1135
+ return result.Attributes;
1136
+ } catch (error) {
1137
+ console.error("Error incrementing subscriptions:", error);
1138
+ throw new Error("Could not increment subscriptions");
1139
+ }
1140
+ }
1141
+ /**
1142
+ * Decrement the count of subscriptions for a specific notification type.
1143
+ * @param id - The ID of the notification type stats entry.
1144
+ */
1145
+ static async decrementSubscriptions(id) {
1146
+ const command = new UpdateCommand7({
1147
+ TableName: _NotiTypeStats.TABLE_NAME,
1148
+ Key: { id },
1149
+ UpdateExpression: "ADD subscribed :dec",
1150
+ ExpressionAttributeValues: {
1151
+ ":dec": -1
1152
+ },
1153
+ ReturnValues: "ALL_NEW"
1154
+ });
1155
+ try {
1156
+ const result = await ddbDocClient.send(command);
1157
+ return result.Attributes;
1158
+ } catch (error) {
1159
+ console.error("Error decrementing subscriptions:", error);
1160
+ throw new Error("Could not decrement subscriptions");
1161
+ }
1162
+ }
1163
+ /**
1164
+ * Increment the count of views for a specific notification type.
1165
+ * @param id - The ID of the notification type stats entry.
1166
+ */
1167
+ static async incrementViews(id) {
1168
+ const command = new UpdateCommand7({
1169
+ TableName: _NotiTypeStats.TABLE_NAME,
1170
+ Key: { id },
1171
+ UpdateExpression: "ADD views :inc",
1172
+ ExpressionAttributeValues: {
1173
+ ":inc": 1
1174
+ },
1175
+ ReturnValues: "ALL_NEW"
1176
+ });
1177
+ try {
1178
+ const result = await ddbDocClient.send(command);
1179
+ return result.Attributes;
1180
+ } catch (error) {
1181
+ console.error("Error incrementing views:", error);
1182
+ throw new Error("Could not increment views");
1183
+ }
1184
+ }
1082
1185
  };
1083
1186
  var NotiTypeStats_default = NotiTypeStats;
1084
1187
 
@@ -1344,7 +1447,7 @@ import {
1344
1447
  GetCommand as GetCommand10,
1345
1448
  PutCommand as PutCommand11,
1346
1449
  QueryCommand as QueryCommand11,
1347
- ScanCommand as ScanCommand2
1450
+ ScanCommand as ScanCommand3
1348
1451
  } from "@aws-sdk/lib-dynamodb";
1349
1452
  var CustomerMinified = class _CustomerMinified {
1350
1453
  static ENV = process.env.ENV || "dev";
@@ -1373,7 +1476,7 @@ var CustomerMinified = class _CustomerMinified {
1373
1476
  * @returns A promise that resolves to an array of customer objects or an empty array if not found.
1374
1477
  */
1375
1478
  static async searchCustomersByUsername(username) {
1376
- const command = new ScanCommand2({
1479
+ const command = new ScanCommand3({
1377
1480
  TableName: _CustomerMinified.TABLE_NAME,
1378
1481
  FilterExpression: "begins_with(username, :uname)",
1379
1482
  ExpressionAttributeValues: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amohamud23/notihub",
3
- "version": "1.1.24",
3
+ "version": "1.1.26",
4
4
  "description": "Notihub Package",
5
5
  "main": "./dist/index.cjs",
6
6
  "types": "./dist/index.d.cts",