@amohamud23/notihub 1.1.2 → 1.1.4

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
@@ -489,6 +489,44 @@ var Notifications = class _Notifications {
489
489
  }
490
490
  }
491
491
  // Additional methods can be added here as needed
492
+ /**
493
+ * Fetches and merges paginated notifications for multiple notiTypeIds, sorted by createdAt descending.
494
+ * @param notiTypeIds - Array of notiTypeIds to fetch.
495
+ * @param limitPerType - Max items to fetch per notiTypeId.
496
+ * @param exclusiveStartKeys - Optional map of pagination keys per notiTypeId.
497
+ * @returns An object with merged, sorted notifications and nextPageKeys map.
498
+ */
499
+ static async getUnifiedFeedByNotiTypeIds(notiTypeIds, limitPerType = 20, exclusiveStartKeys) {
500
+ const results = await Promise.all(
501
+ notiTypeIds.map(async (ntid) => {
502
+ const params = {
503
+ TableName: this.TABLE_NAME,
504
+ IndexName: "NotiTypeIdIndex",
505
+ // Assuming you have a GSI for notiTypeId
506
+ KeyConditionExpression: "notiTypeId = :ntid",
507
+ ExpressionAttributeValues: { ":ntid": ntid },
508
+ ScanIndexForward: false,
509
+ Limit: limitPerType,
510
+ ExclusiveStartKey: exclusiveStartKeys?.[ntid]
511
+ };
512
+ const result = await ddbDocClient.send(new import_lib_dynamodb4.QueryCommand(params));
513
+ return {
514
+ notiTypeId: ntid,
515
+ notifications: result.Items || [],
516
+ nextPageKey: result.LastEvaluatedKey
517
+ };
518
+ })
519
+ );
520
+ const mergedNotifications = results.flatMap((r) => r.notifications).sort((a, b) => b.createdAt.localeCompare(a.createdAt));
521
+ const nextPageKeys = results.reduce((acc, curr) => {
522
+ acc[curr.notiTypeId] = curr.nextPageKey;
523
+ return acc;
524
+ }, {});
525
+ return {
526
+ notifications: mergedNotifications,
527
+ nextPageKeys
528
+ };
529
+ }
492
530
  };
493
531
  var Notifications_default = Notifications;
494
532
 
@@ -589,6 +627,19 @@ var NotiHubStats = class _NotiHubStats {
589
627
  const result = await ddbDocClient.send(command);
590
628
  return result.Items || [];
591
629
  }
630
+ static async deleteStatsById(id) {
631
+ const command = new import_lib_dynamodb5.DeleteCommand({
632
+ TableName: _NotiHubStats.TABLE_NAME,
633
+ Key: { id }
634
+ });
635
+ try {
636
+ await ddbDocClient.send(command);
637
+ console.log(`Stats with ID ${id} deleted successfully.`);
638
+ } catch (error) {
639
+ console.error(`Error deleting stats with ID ${id}:`, error);
640
+ throw new Error("Could not delete stats");
641
+ }
642
+ }
592
643
  };
593
644
  var NotiHubStats_default = NotiHubStats;
594
645
 
package/dist/index.d.cts CHANGED
@@ -60,6 +60,7 @@ type INotiHubCustomer = {
60
60
  phone?: string;
61
61
  website?: string;
62
62
  location?: string;
63
+ metadata?: INotiHubCustomerMetadata;
63
64
  bio: string;
64
65
  confirmed: boolean;
65
66
  createdAt: string;
@@ -70,6 +71,7 @@ type INotiHubCustomerMetadata = {
70
71
  customerId: string;
71
72
  paymentState: "ACTIVE" | "INACTIVE";
72
73
  emailState: "VERIFIED" | "UNVERIFIED";
74
+ isOnboarded: boolean;
73
75
  notiLimit: number;
74
76
  companyName: string;
75
77
  phone: string;
@@ -159,6 +161,7 @@ type IUserSubscription = {
159
161
  updatedAt: string;
160
162
  };
161
163
  type IUserSubscribeNotifier = {
164
+ id: string;
162
165
  userId: string;
163
166
  customerId: string;
164
167
  notiTypeId: string;
@@ -347,6 +350,17 @@ declare class Notifications {
347
350
  * @returns A promise that resolves to the created notification object.
348
351
  */
349
352
  static createNotification(notification: INotiHubNotification): Promise<INotiHubNotification>;
353
+ /**
354
+ * Fetches and merges paginated notifications for multiple notiTypeIds, sorted by createdAt descending.
355
+ * @param notiTypeIds - Array of notiTypeIds to fetch.
356
+ * @param limitPerType - Max items to fetch per notiTypeId.
357
+ * @param exclusiveStartKeys - Optional map of pagination keys per notiTypeId.
358
+ * @returns An object with merged, sorted notifications and nextPageKeys map.
359
+ */
360
+ static getUnifiedFeedByNotiTypeIds(notiTypeIds: string[], limitPerType?: number, exclusiveStartKeys?: Record<string, Record<string, any>>): Promise<{
361
+ notifications: INotiHubNotification[];
362
+ nextPageKeys: Record<string, Record<string, any> | undefined>;
363
+ }>;
350
364
  }
351
365
 
352
366
  declare class NotiHubStats {
@@ -370,6 +384,7 @@ declare class NotiHubStats {
370
384
  */
371
385
  static incrementSubscriptions(id: string, customerId: string): Promise<INotiHubStats>;
372
386
  static getStatsInDateRange(customerId: string, startDate: string, endDate: string): Promise<INotiHubStats[]>;
387
+ static deleteStatsById(id: string): Promise<void>;
373
388
  }
374
389
 
375
390
  declare class NotiType {
package/dist/index.d.ts CHANGED
@@ -60,6 +60,7 @@ type INotiHubCustomer = {
60
60
  phone?: string;
61
61
  website?: string;
62
62
  location?: string;
63
+ metadata?: INotiHubCustomerMetadata;
63
64
  bio: string;
64
65
  confirmed: boolean;
65
66
  createdAt: string;
@@ -70,6 +71,7 @@ type INotiHubCustomerMetadata = {
70
71
  customerId: string;
71
72
  paymentState: "ACTIVE" | "INACTIVE";
72
73
  emailState: "VERIFIED" | "UNVERIFIED";
74
+ isOnboarded: boolean;
73
75
  notiLimit: number;
74
76
  companyName: string;
75
77
  phone: string;
@@ -159,6 +161,7 @@ type IUserSubscription = {
159
161
  updatedAt: string;
160
162
  };
161
163
  type IUserSubscribeNotifier = {
164
+ id: string;
162
165
  userId: string;
163
166
  customerId: string;
164
167
  notiTypeId: string;
@@ -347,6 +350,17 @@ declare class Notifications {
347
350
  * @returns A promise that resolves to the created notification object.
348
351
  */
349
352
  static createNotification(notification: INotiHubNotification): Promise<INotiHubNotification>;
353
+ /**
354
+ * Fetches and merges paginated notifications for multiple notiTypeIds, sorted by createdAt descending.
355
+ * @param notiTypeIds - Array of notiTypeIds to fetch.
356
+ * @param limitPerType - Max items to fetch per notiTypeId.
357
+ * @param exclusiveStartKeys - Optional map of pagination keys per notiTypeId.
358
+ * @returns An object with merged, sorted notifications and nextPageKeys map.
359
+ */
360
+ static getUnifiedFeedByNotiTypeIds(notiTypeIds: string[], limitPerType?: number, exclusiveStartKeys?: Record<string, Record<string, any>>): Promise<{
361
+ notifications: INotiHubNotification[];
362
+ nextPageKeys: Record<string, Record<string, any> | undefined>;
363
+ }>;
350
364
  }
351
365
 
352
366
  declare class NotiHubStats {
@@ -370,6 +384,7 @@ declare class NotiHubStats {
370
384
  */
371
385
  static incrementSubscriptions(id: string, customerId: string): Promise<INotiHubStats>;
372
386
  static getStatsInDateRange(customerId: string, startDate: string, endDate: string): Promise<INotiHubStats[]>;
387
+ static deleteStatsById(id: string): Promise<void>;
373
388
  }
374
389
 
375
390
  declare class NotiType {
package/dist/index.js CHANGED
@@ -465,6 +465,44 @@ var Notifications = class _Notifications {
465
465
  }
466
466
  }
467
467
  // Additional methods can be added here as needed
468
+ /**
469
+ * Fetches and merges paginated notifications for multiple notiTypeIds, sorted by createdAt descending.
470
+ * @param notiTypeIds - Array of notiTypeIds to fetch.
471
+ * @param limitPerType - Max items to fetch per notiTypeId.
472
+ * @param exclusiveStartKeys - Optional map of pagination keys per notiTypeId.
473
+ * @returns An object with merged, sorted notifications and nextPageKeys map.
474
+ */
475
+ static async getUnifiedFeedByNotiTypeIds(notiTypeIds, limitPerType = 20, exclusiveStartKeys) {
476
+ const results = await Promise.all(
477
+ notiTypeIds.map(async (ntid) => {
478
+ const params = {
479
+ TableName: this.TABLE_NAME,
480
+ IndexName: "NotiTypeIdIndex",
481
+ // Assuming you have a GSI for notiTypeId
482
+ KeyConditionExpression: "notiTypeId = :ntid",
483
+ ExpressionAttributeValues: { ":ntid": ntid },
484
+ ScanIndexForward: false,
485
+ Limit: limitPerType,
486
+ ExclusiveStartKey: exclusiveStartKeys?.[ntid]
487
+ };
488
+ const result = await ddbDocClient.send(new QueryCommand3(params));
489
+ return {
490
+ notiTypeId: ntid,
491
+ notifications: result.Items || [],
492
+ nextPageKey: result.LastEvaluatedKey
493
+ };
494
+ })
495
+ );
496
+ const mergedNotifications = results.flatMap((r) => r.notifications).sort((a, b) => b.createdAt.localeCompare(a.createdAt));
497
+ const nextPageKeys = results.reduce((acc, curr) => {
498
+ acc[curr.notiTypeId] = curr.nextPageKey;
499
+ return acc;
500
+ }, {});
501
+ return {
502
+ notifications: mergedNotifications,
503
+ nextPageKeys
504
+ };
505
+ }
468
506
  };
469
507
  var Notifications_default = Notifications;
470
508
 
@@ -472,7 +510,8 @@ var Notifications_default = Notifications;
472
510
  import {
473
511
  PutCommand as PutCommand4,
474
512
  QueryCommand as QueryCommand4,
475
- UpdateCommand as UpdateCommand4
513
+ UpdateCommand as UpdateCommand4,
514
+ DeleteCommand as DeleteCommand4
476
515
  } from "@aws-sdk/lib-dynamodb";
477
516
  var NotiHubStats = class _NotiHubStats {
478
517
  static ENV = process.env.ENV || "dev";
@@ -569,13 +608,26 @@ var NotiHubStats = class _NotiHubStats {
569
608
  const result = await ddbDocClient.send(command);
570
609
  return result.Items || [];
571
610
  }
611
+ static async deleteStatsById(id) {
612
+ const command = new DeleteCommand4({
613
+ TableName: _NotiHubStats.TABLE_NAME,
614
+ Key: { id }
615
+ });
616
+ try {
617
+ await ddbDocClient.send(command);
618
+ console.log(`Stats with ID ${id} deleted successfully.`);
619
+ } catch (error) {
620
+ console.error(`Error deleting stats with ID ${id}:`, error);
621
+ throw new Error("Could not delete stats");
622
+ }
623
+ }
572
624
  };
573
625
  var NotiHubStats_default = NotiHubStats;
574
626
 
575
627
  // src/DynamoModels/NotiType.ts
576
628
  import {
577
629
  BatchWriteCommand,
578
- DeleteCommand as DeleteCommand4,
630
+ DeleteCommand as DeleteCommand5,
579
631
  PutCommand as PutCommand5,
580
632
  QueryCommand as QueryCommand5,
581
633
  ScanCommand,
@@ -687,7 +739,7 @@ var NotiType = class _NotiType {
687
739
  * @returns A promise that resolves when the notification type is deleted.
688
740
  */
689
741
  static async deleteNotiType(id) {
690
- const command = new DeleteCommand4({
742
+ const command = new DeleteCommand5({
691
743
  TableName: _NotiType.TABLE_NAME,
692
744
  Key: { id }
693
745
  });
@@ -767,7 +819,7 @@ var NotiType_default = NotiType;
767
819
 
768
820
  // src/DynamoModels/Subscription.ts
769
821
  import {
770
- DeleteCommand as DeleteCommand5,
822
+ DeleteCommand as DeleteCommand6,
771
823
  GetCommand as GetCommand6,
772
824
  PutCommand as PutCommand6,
773
825
  QueryCommand as QueryCommand6
@@ -840,7 +892,7 @@ var Subscription = class _Subscription {
840
892
  * @returns A promise that resolves when the deletion is complete.
841
893
  */
842
894
  static async deleteSubscriptionById(id) {
843
- const command = new DeleteCommand5({
895
+ const command = new DeleteCommand6({
844
896
  TableName: _Subscription.TABLE_NAME,
845
897
  Key: { id }
846
898
  });
@@ -888,7 +940,7 @@ var Subscription_default = Subscription;
888
940
 
889
941
  // src/DynamoModels/NotiTypeStats.ts
890
942
  import {
891
- DeleteCommand as DeleteCommand6,
943
+ DeleteCommand as DeleteCommand7,
892
944
  GetCommand as GetCommand7,
893
945
  PutCommand as PutCommand7,
894
946
  QueryCommand as QueryCommand7
@@ -967,7 +1019,7 @@ var NotiTypeStats = class _NotiTypeStats {
967
1019
  * @returns A promise that resolves when the deletion is complete.
968
1020
  */
969
1021
  static async deleteNotiTypeStatsById(id) {
970
- const command = new DeleteCommand6({
1022
+ const command = new DeleteCommand7({
971
1023
  TableName: _NotiTypeStats.TABLE_NAME,
972
1024
  Key: { id }
973
1025
  });
@@ -1030,7 +1082,7 @@ var Views_default = Views;
1030
1082
 
1031
1083
  // src/DynamoModels/SubscriptionType.ts
1032
1084
  import {
1033
- DeleteCommand as DeleteCommand8,
1085
+ DeleteCommand as DeleteCommand9,
1034
1086
  GetCommand as GetCommand9,
1035
1087
  QueryCommand as QueryCommand9
1036
1088
  } from "@aws-sdk/lib-dynamodb";
@@ -1082,7 +1134,7 @@ var SubscriptionType = class _SubscriptionType {
1082
1134
  * @returns A promise that resolves when the subscription type is deleted.
1083
1135
  */
1084
1136
  static async deleteSubscriptionTypeById(id) {
1085
- const command = new DeleteCommand8({
1137
+ const command = new DeleteCommand9({
1086
1138
  TableName: _SubscriptionType.TABLE_NAME,
1087
1139
  Key: { id }
1088
1140
  });
@@ -1124,7 +1176,7 @@ var SubscriptionType_default = SubscriptionType;
1124
1176
 
1125
1177
  // src/DynamoModels/CustomerMetaData.ts
1126
1178
  import {
1127
- DeleteCommand as DeleteCommand9,
1179
+ DeleteCommand as DeleteCommand10,
1128
1180
  GetCommand as GetCommand10,
1129
1181
  PutCommand as PutCommand10,
1130
1182
  QueryCommand as QueryCommand10
@@ -1156,7 +1208,7 @@ var CustomerMetaData = class _CustomerMetaData {
1156
1208
  * @returns A promise that resolves when the customer metadata is deleted.
1157
1209
  */
1158
1210
  static async deleteCustomerMetaDataById(id) {
1159
- const command = new DeleteCommand9({
1211
+ const command = new DeleteCommand10({
1160
1212
  TableName: _CustomerMetaData.TABLE_NAME,
1161
1213
  Key: { id }
1162
1214
  });
@@ -1215,7 +1267,7 @@ var CustomerMetaData_default = CustomerMetaData;
1215
1267
 
1216
1268
  // src/DynamoModels/CustomerMinified.ts
1217
1269
  import {
1218
- DeleteCommand as DeleteCommand10,
1270
+ DeleteCommand as DeleteCommand11,
1219
1271
  GetCommand as GetCommand11,
1220
1272
  PutCommand as PutCommand11,
1221
1273
  QueryCommand as QueryCommand11
@@ -1287,7 +1339,7 @@ var CustomerMinified = class _CustomerMinified {
1287
1339
  * @returns A promise that resolves when the customer is deleted.
1288
1340
  */
1289
1341
  static async deleteCustomerMinifiedById(id) {
1290
- const command = new DeleteCommand10({
1342
+ const command = new DeleteCommand11({
1291
1343
  TableName: _CustomerMinified.TABLE_NAME,
1292
1344
  Key: { id }
1293
1345
  });
@@ -1329,7 +1381,7 @@ var CustomerMinified = class _CustomerMinified {
1329
1381
  var CustomerMinified_default = CustomerMinified;
1330
1382
 
1331
1383
  // src/DynamoModels/NotificationStats.ts
1332
- import { DeleteCommand as DeleteCommand11, GetCommand as GetCommand12, PutCommand as PutCommand12 } from "@aws-sdk/lib-dynamodb";
1384
+ import { DeleteCommand as DeleteCommand12, GetCommand as GetCommand12, PutCommand as PutCommand12 } from "@aws-sdk/lib-dynamodb";
1333
1385
  var NotificationStats = class _NotificationStats {
1334
1386
  static ENV = process.env.ENV || "dev";
1335
1387
  static TABLE_NAME = `NotiHub-NotificationStats-v1-${_NotificationStats.ENV}`;
@@ -1375,7 +1427,7 @@ var NotificationStats = class _NotificationStats {
1375
1427
  * @returns A promise that resolves when the deletion is complete.
1376
1428
  */
1377
1429
  static async deleteNotificationStatsById(id) {
1378
- const command = new DeleteCommand11({
1430
+ const command = new DeleteCommand12({
1379
1431
  TableName: _NotificationStats.TABLE_NAME,
1380
1432
  Key: { id }
1381
1433
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amohamud23/notihub",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
4
4
  "description": "Notihub Package",
5
5
  "main": "./dist/index.cjs",
6
6
  "types": "./dist/index.d.cts",