@amohamud23/notihub 1.0.172 → 1.0.174

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
@@ -481,95 +481,50 @@ var Notifications_default = Notifications;
481
481
  var import_lib_dynamodb5 = require("@aws-sdk/lib-dynamodb");
482
482
  var NotiHubStats = class _NotiHubStats {
483
483
  static ENV = process.env.ENV || "dev";
484
- static TABLE_NAME = `NotiHub-Stats-${_NotiHubStats.ENV}`;
485
- /**
486
- * Creates a new NotiHub stats entry.
487
- * @param stats - The statistics object to create.
488
- * @returns A promise that resolves to the created statistics object.
489
- */
484
+ static TABLE_NAME = `NotiHub-NotiHubStats-v1-${_NotiHubStats.ENV}`;
490
485
  static async createStats(stats) {
491
486
  const command = new import_lib_dynamodb5.PutCommand({
492
487
  TableName: _NotiHubStats.TABLE_NAME,
493
488
  Item: stats
494
489
  });
495
- try {
496
- const result = await ddbDocClient.send(command);
497
- return result.Attributes;
498
- } catch (error) {
499
- console.error("Error creating NotiHub stats:", error);
500
- throw new Error("Could not create NotiHub stats");
501
- }
490
+ await ddbDocClient.send(command);
491
+ return stats;
502
492
  }
503
- /**
504
- * Retrieves the statistics for NotiHub.
505
- * @returns A promise that resolves to the statistics object or null if not found.
506
- */
507
- static async getStatsBy(customerId) {
493
+ static async getStatsByCustomerId(customerId) {
508
494
  const command = new import_lib_dynamodb5.GetCommand({
509
495
  TableName: _NotiHubStats.TABLE_NAME,
510
496
  Key: { customerId }
511
497
  });
512
- try {
513
- const result = await ddbDocClient.send(command);
514
- return result.Item || null;
515
- } catch (error) {
516
- console.error("Error fetching NotiHub stats:", error);
517
- throw new Error("Could not fetch NotiHub stats");
518
- }
498
+ const result = await ddbDocClient.send(command);
499
+ return result.Item || null;
519
500
  }
520
- /**
521
- * Updates the statistics for NotiHub.
522
- * @param notificationId - The ID of the notification to update the stats for.
523
- * @returns A promise that resolves to the updated statistics object.
524
- */
525
- static async updateViewsStats(notificationId) {
501
+ static async incrementViews(id, customerId) {
526
502
  const command = new import_lib_dynamodb5.UpdateCommand({
527
503
  TableName: _NotiHubStats.TABLE_NAME,
528
- Key: { notificationId },
504
+ Key: { id, customerId },
529
505
  UpdateExpression: "ADD views :inc",
530
506
  ExpressionAttributeValues: {
531
507
  ":inc": 1
532
508
  },
533
509
  ReturnValues: "ALL_NEW"
534
510
  });
535
- try {
536
- const result = await ddbDocClient.send(command);
537
- return result.Attributes;
538
- } catch (error) {
539
- console.error("Error updating NotiHub stats:", error);
540
- throw new Error("Could not update NotiHub stats");
541
- }
511
+ const result = await ddbDocClient.send(command);
512
+ return result.Attributes;
542
513
  }
543
- /**
544
- * Get all stats with in a date range.
545
- * @param startDate - The start date of the range.
546
- * @param endDate - The end date of the range.
547
- * @returns A promise that resolves to an array of statistics objects.
548
- */
549
- static async getStatsInDateRange(startDate, endDate) {
514
+ static async getStatsInDateRange(customerId, startDate, endDate) {
550
515
  const command = new import_lib_dynamodb5.QueryCommand({
551
516
  TableName: _NotiHubStats.TABLE_NAME,
552
- IndexName: "DateIndex",
553
- // Assuming you have a GSI for date
554
- KeyConditionExpression: "#date BETWEEN :start_date AND :end_date",
555
- ExpressionAttributeNames: {
556
- "#date": "date"
557
- },
517
+ IndexName: "CustomerCreatedAtIndex",
518
+ KeyConditionExpression: "customerId = :customerId AND createdAt BETWEEN :start_date AND :end_date",
558
519
  ExpressionAttributeValues: {
520
+ ":customerId": customerId,
559
521
  ":start_date": startDate,
560
522
  ":end_date": endDate
561
- }
523
+ },
524
+ ScanIndexForward: true
562
525
  });
563
- try {
564
- const result = await ddbDocClient.send(command);
565
- return result.Items || [];
566
- } catch (error) {
567
- console.error(
568
- `Error fetching NotiHub stats between dates: ${startDate} and ${endDate}`,
569
- error
570
- );
571
- throw new Error("Could not fetch NotiHub stats in date range");
572
- }
526
+ const result = await ddbDocClient.send(command);
527
+ return result.Items || [];
573
528
  }
574
529
  };
575
530
  var NotiHubStats_default = NotiHubStats;
package/dist/index.d.cts CHANGED
@@ -129,7 +129,7 @@ type INotiHubStats = {
129
129
  type INotiHubStatsHistory = {
130
130
  id: string;
131
131
  customerId: string;
132
- type: "MONTH" | "YEAR";
132
+ type: "DAY" | "MONTH" | "YEAR";
133
133
  subscription: number;
134
134
  notifications: number;
135
135
  views: number;
@@ -356,30 +356,10 @@ declare class Notifications {
356
356
  declare class NotiHubStats {
357
357
  static ENV: string;
358
358
  static TABLE_NAME: string;
359
- /**
360
- * Creates a new NotiHub stats entry.
361
- * @param stats - The statistics object to create.
362
- * @returns A promise that resolves to the created statistics object.
363
- */
364
359
  static createStats(stats: INotiHubStats): Promise<INotiHubStats>;
365
- /**
366
- * Retrieves the statistics for NotiHub.
367
- * @returns A promise that resolves to the statistics object or null if not found.
368
- */
369
- static getStatsBy(customerId: string): Promise<INotiHubStats | null>;
370
- /**
371
- * Updates the statistics for NotiHub.
372
- * @param notificationId - The ID of the notification to update the stats for.
373
- * @returns A promise that resolves to the updated statistics object.
374
- */
375
- static updateViewsStats(notificationId: string): Promise<INotiHubStats>;
376
- /**
377
- * Get all stats with in a date range.
378
- * @param startDate - The start date of the range.
379
- * @param endDate - The end date of the range.
380
- * @returns A promise that resolves to an array of statistics objects.
381
- */
382
- static getStatsInDateRange(startDate: string, endDate: string): Promise<INotiHubStats[]>;
360
+ static getStatsByCustomerId(customerId: string): Promise<INotiHubStats | null>;
361
+ static incrementViews(id: string, customerId: string): Promise<INotiHubStats>;
362
+ static getStatsInDateRange(customerId: string, startDate: string, endDate: string): Promise<INotiHubStats[]>;
383
363
  }
384
364
 
385
365
  declare class NotiType {
package/dist/index.d.ts CHANGED
@@ -129,7 +129,7 @@ type INotiHubStats = {
129
129
  type INotiHubStatsHistory = {
130
130
  id: string;
131
131
  customerId: string;
132
- type: "MONTH" | "YEAR";
132
+ type: "DAY" | "MONTH" | "YEAR";
133
133
  subscription: number;
134
134
  notifications: number;
135
135
  views: number;
@@ -356,30 +356,10 @@ declare class Notifications {
356
356
  declare class NotiHubStats {
357
357
  static ENV: string;
358
358
  static TABLE_NAME: string;
359
- /**
360
- * Creates a new NotiHub stats entry.
361
- * @param stats - The statistics object to create.
362
- * @returns A promise that resolves to the created statistics object.
363
- */
364
359
  static createStats(stats: INotiHubStats): Promise<INotiHubStats>;
365
- /**
366
- * Retrieves the statistics for NotiHub.
367
- * @returns A promise that resolves to the statistics object or null if not found.
368
- */
369
- static getStatsBy(customerId: string): Promise<INotiHubStats | null>;
370
- /**
371
- * Updates the statistics for NotiHub.
372
- * @param notificationId - The ID of the notification to update the stats for.
373
- * @returns A promise that resolves to the updated statistics object.
374
- */
375
- static updateViewsStats(notificationId: string): Promise<INotiHubStats>;
376
- /**
377
- * Get all stats with in a date range.
378
- * @param startDate - The start date of the range.
379
- * @param endDate - The end date of the range.
380
- * @returns A promise that resolves to an array of statistics objects.
381
- */
382
- static getStatsInDateRange(startDate: string, endDate: string): Promise<INotiHubStats[]>;
360
+ static getStatsByCustomerId(customerId: string): Promise<INotiHubStats | null>;
361
+ static incrementViews(id: string, customerId: string): Promise<INotiHubStats>;
362
+ static getStatsInDateRange(customerId: string, startDate: string, endDate: string): Promise<INotiHubStats[]>;
383
363
  }
384
364
 
385
365
  declare class NotiType {
package/dist/index.js CHANGED
@@ -461,95 +461,50 @@ import {
461
461
  } from "@aws-sdk/lib-dynamodb";
462
462
  var NotiHubStats = class _NotiHubStats {
463
463
  static ENV = process.env.ENV || "dev";
464
- static TABLE_NAME = `NotiHub-Stats-${_NotiHubStats.ENV}`;
465
- /**
466
- * Creates a new NotiHub stats entry.
467
- * @param stats - The statistics object to create.
468
- * @returns A promise that resolves to the created statistics object.
469
- */
464
+ static TABLE_NAME = `NotiHub-NotiHubStats-v1-${_NotiHubStats.ENV}`;
470
465
  static async createStats(stats) {
471
466
  const command = new PutCommand4({
472
467
  TableName: _NotiHubStats.TABLE_NAME,
473
468
  Item: stats
474
469
  });
475
- try {
476
- const result = await ddbDocClient.send(command);
477
- return result.Attributes;
478
- } catch (error) {
479
- console.error("Error creating NotiHub stats:", error);
480
- throw new Error("Could not create NotiHub stats");
481
- }
470
+ await ddbDocClient.send(command);
471
+ return stats;
482
472
  }
483
- /**
484
- * Retrieves the statistics for NotiHub.
485
- * @returns A promise that resolves to the statistics object or null if not found.
486
- */
487
- static async getStatsBy(customerId) {
473
+ static async getStatsByCustomerId(customerId) {
488
474
  const command = new GetCommand4({
489
475
  TableName: _NotiHubStats.TABLE_NAME,
490
476
  Key: { customerId }
491
477
  });
492
- try {
493
- const result = await ddbDocClient.send(command);
494
- return result.Item || null;
495
- } catch (error) {
496
- console.error("Error fetching NotiHub stats:", error);
497
- throw new Error("Could not fetch NotiHub stats");
498
- }
478
+ const result = await ddbDocClient.send(command);
479
+ return result.Item || null;
499
480
  }
500
- /**
501
- * Updates the statistics for NotiHub.
502
- * @param notificationId - The ID of the notification to update the stats for.
503
- * @returns A promise that resolves to the updated statistics object.
504
- */
505
- static async updateViewsStats(notificationId) {
481
+ static async incrementViews(id, customerId) {
506
482
  const command = new UpdateCommand4({
507
483
  TableName: _NotiHubStats.TABLE_NAME,
508
- Key: { notificationId },
484
+ Key: { id, customerId },
509
485
  UpdateExpression: "ADD views :inc",
510
486
  ExpressionAttributeValues: {
511
487
  ":inc": 1
512
488
  },
513
489
  ReturnValues: "ALL_NEW"
514
490
  });
515
- try {
516
- const result = await ddbDocClient.send(command);
517
- return result.Attributes;
518
- } catch (error) {
519
- console.error("Error updating NotiHub stats:", error);
520
- throw new Error("Could not update NotiHub stats");
521
- }
491
+ const result = await ddbDocClient.send(command);
492
+ return result.Attributes;
522
493
  }
523
- /**
524
- * Get all stats with in a date range.
525
- * @param startDate - The start date of the range.
526
- * @param endDate - The end date of the range.
527
- * @returns A promise that resolves to an array of statistics objects.
528
- */
529
- static async getStatsInDateRange(startDate, endDate) {
494
+ static async getStatsInDateRange(customerId, startDate, endDate) {
530
495
  const command = new QueryCommand3({
531
496
  TableName: _NotiHubStats.TABLE_NAME,
532
- IndexName: "DateIndex",
533
- // Assuming you have a GSI for date
534
- KeyConditionExpression: "#date BETWEEN :start_date AND :end_date",
535
- ExpressionAttributeNames: {
536
- "#date": "date"
537
- },
497
+ IndexName: "CustomerCreatedAtIndex",
498
+ KeyConditionExpression: "customerId = :customerId AND createdAt BETWEEN :start_date AND :end_date",
538
499
  ExpressionAttributeValues: {
500
+ ":customerId": customerId,
539
501
  ":start_date": startDate,
540
502
  ":end_date": endDate
541
- }
503
+ },
504
+ ScanIndexForward: true
542
505
  });
543
- try {
544
- const result = await ddbDocClient.send(command);
545
- return result.Items || [];
546
- } catch (error) {
547
- console.error(
548
- `Error fetching NotiHub stats between dates: ${startDate} and ${endDate}`,
549
- error
550
- );
551
- throw new Error("Could not fetch NotiHub stats in date range");
552
- }
506
+ const result = await ddbDocClient.send(command);
507
+ return result.Items || [];
553
508
  }
554
509
  };
555
510
  var NotiHubStats_default = NotiHubStats;
@@ -557,7 +512,7 @@ var NotiHubStats_default = NotiHubStats;
557
512
  // src/DynamoModels/NotiType.ts
558
513
  import {
559
514
  BatchWriteCommand,
560
- DeleteCommand as DeleteCommand5,
515
+ DeleteCommand as DeleteCommand4,
561
516
  GetCommand as GetCommand5,
562
517
  PutCommand as PutCommand5,
563
518
  QueryCommand as QueryCommand4,
@@ -663,7 +618,7 @@ var NotiType = class _NotiType {
663
618
  * @returns A promise that resolves when the notification type is deleted.
664
619
  */
665
620
  static async deleteNotiType(id) {
666
- const command = new DeleteCommand5({
621
+ const command = new DeleteCommand4({
667
622
  TableName: _NotiType.TABLE_NAME,
668
623
  Key: { id }
669
624
  });
@@ -743,7 +698,7 @@ var NotiType_default = NotiType;
743
698
 
744
699
  // src/DynamoModels/Subscription.ts
745
700
  import {
746
- DeleteCommand as DeleteCommand6,
701
+ DeleteCommand as DeleteCommand5,
747
702
  GetCommand as GetCommand6,
748
703
  PutCommand as PutCommand6,
749
704
  QueryCommand as QueryCommand5
@@ -816,7 +771,7 @@ var Subscription = class _Subscription {
816
771
  * @returns A promise that resolves when the deletion is complete.
817
772
  */
818
773
  static async deleteSubscriptionById(id) {
819
- const command = new DeleteCommand6({
774
+ const command = new DeleteCommand5({
820
775
  TableName: _Subscription.TABLE_NAME,
821
776
  Key: { id }
822
777
  });
@@ -864,7 +819,7 @@ var Subscription_default = Subscription;
864
819
 
865
820
  // src/DynamoModels/NotiTypeStats.ts
866
821
  import {
867
- DeleteCommand as DeleteCommand7,
822
+ DeleteCommand as DeleteCommand6,
868
823
  GetCommand as GetCommand7,
869
824
  PutCommand as PutCommand7,
870
825
  QueryCommand as QueryCommand6
@@ -943,7 +898,7 @@ var NotiTypeStats = class _NotiTypeStats {
943
898
  * @returns A promise that resolves when the deletion is complete.
944
899
  */
945
900
  static async deleteNotiTypeStatsById(id) {
946
- const command = new DeleteCommand7({
901
+ const command = new DeleteCommand6({
947
902
  TableName: _NotiTypeStats.TABLE_NAME,
948
903
  Key: { id }
949
904
  });
@@ -1006,7 +961,7 @@ var Views_default = Views;
1006
961
 
1007
962
  // src/DynamoModels/SubscriptionType.ts
1008
963
  import {
1009
- DeleteCommand as DeleteCommand9,
964
+ DeleteCommand as DeleteCommand8,
1010
965
  GetCommand as GetCommand9,
1011
966
  QueryCommand as QueryCommand8
1012
967
  } from "@aws-sdk/lib-dynamodb";
@@ -1058,7 +1013,7 @@ var SubscriptionType = class _SubscriptionType {
1058
1013
  * @returns A promise that resolves when the subscription type is deleted.
1059
1014
  */
1060
1015
  static async deleteSubscriptionTypeById(id) {
1061
- const command = new DeleteCommand9({
1016
+ const command = new DeleteCommand8({
1062
1017
  TableName: _SubscriptionType.TABLE_NAME,
1063
1018
  Key: { id }
1064
1019
  });
@@ -1074,7 +1029,7 @@ var SubscriptionType_default = SubscriptionType;
1074
1029
 
1075
1030
  // src/DynamoModels/CustomerMetaData.ts
1076
1031
  import {
1077
- DeleteCommand as DeleteCommand10,
1032
+ DeleteCommand as DeleteCommand9,
1078
1033
  GetCommand as GetCommand10,
1079
1034
  PutCommand as PutCommand10
1080
1035
  } from "@aws-sdk/lib-dynamodb";
@@ -1105,7 +1060,7 @@ var CustomerMetaData = class _CustomerMetaData {
1105
1060
  * @returns A promise that resolves when the customer metadata is deleted.
1106
1061
  */
1107
1062
  static async deleteCustomerMetaDataById(id) {
1108
- const command = new DeleteCommand10({
1063
+ const command = new DeleteCommand9({
1109
1064
  TableName: _CustomerMetaData.TABLE_NAME,
1110
1065
  Key: { id }
1111
1066
  });
@@ -1157,7 +1112,7 @@ var CustomerMetaData_default = CustomerMetaData;
1157
1112
 
1158
1113
  // src/DynamoModels/CustomerMinified.ts
1159
1114
  import {
1160
- DeleteCommand as DeleteCommand11,
1115
+ DeleteCommand as DeleteCommand10,
1161
1116
  GetCommand as GetCommand11,
1162
1117
  PutCommand as PutCommand11
1163
1118
  } from "@aws-sdk/lib-dynamodb";
@@ -1206,7 +1161,7 @@ var CustomerMinified = class _CustomerMinified {
1206
1161
  * @returns A promise that resolves when the customer is deleted.
1207
1162
  */
1208
1163
  static async deleteCustomerMinifiedById(id) {
1209
- const command = new DeleteCommand11({
1164
+ const command = new DeleteCommand10({
1210
1165
  TableName: _CustomerMinified.TABLE_NAME,
1211
1166
  Key: { id }
1212
1167
  });
@@ -1222,7 +1177,7 @@ var CustomerMinified = class _CustomerMinified {
1222
1177
  var CustomerMinified_default = CustomerMinified;
1223
1178
 
1224
1179
  // src/DynamoModels/NotificationStats.ts
1225
- import { DeleteCommand as DeleteCommand12, GetCommand as GetCommand12, PutCommand as PutCommand12 } from "@aws-sdk/lib-dynamodb";
1180
+ import { DeleteCommand as DeleteCommand11, GetCommand as GetCommand12, PutCommand as PutCommand12 } from "@aws-sdk/lib-dynamodb";
1226
1181
  var NotificationStats = class _NotificationStats {
1227
1182
  static ENV = process.env.ENV || "dev";
1228
1183
  static TABLE_NAME = `NotiHub-NotificationStats-${_NotificationStats.ENV}`;
@@ -1268,7 +1223,7 @@ var NotificationStats = class _NotificationStats {
1268
1223
  * @returns A promise that resolves when the deletion is complete.
1269
1224
  */
1270
1225
  static async deleteNotificationStatsById(id) {
1271
- const command = new DeleteCommand12({
1226
+ const command = new DeleteCommand11({
1272
1227
  TableName: _NotificationStats.TABLE_NAME,
1273
1228
  Key: { id }
1274
1229
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amohamud23/notihub",
3
- "version": "1.0.172",
3
+ "version": "1.0.174",
4
4
  "description": "Notihub Package",
5
5
  "main": "./dist/index.cjs",
6
6
  "types": "./dist/index.d.cts",