@amohamud23/notihub 1.1.26 → 1.1.28

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
@@ -909,7 +909,7 @@ var NotiType_default = NotiType;
909
909
  var import_lib_dynamodb7 = require("@aws-sdk/lib-dynamodb");
910
910
  var Subscription = class _Subscription {
911
911
  static ENV = process.env.ENV || "dev";
912
- static TABLE_NAME = `NotiHub-Subscriptions-v1-${_Subscription.ENV}`;
912
+ static TABLE_NAME = `NotiHub-Subscriptions-v2-${_Subscription.ENV}`;
913
913
  /**
914
914
  * Retrieves a subscription by its ID.
915
915
  * @param id - The ID of the subscription to retrieve.
@@ -1026,6 +1026,32 @@ var Subscription = class _Subscription {
1026
1026
  await Promise.all(deletePromises);
1027
1027
  }
1028
1028
  }
1029
+ /**
1030
+ * Fetch all subscriptions by customer ID.
1031
+ * @param customerId - The ID of the customer whose subscriptions to retrieve.
1032
+ * @returns A promise that resolves to an array of subscription objects or null if not found.
1033
+ */
1034
+ static async getSubscriptionsByCustomerId(customerId) {
1035
+ const command = new import_lib_dynamodb7.QueryCommand({
1036
+ TableName: _Subscription.TABLE_NAME,
1037
+ IndexName: "CustomerIdIndex",
1038
+ // Assuming you have a GSI for customerId
1039
+ KeyConditionExpression: "customerId = :customerId",
1040
+ ExpressionAttributeValues: {
1041
+ ":customerId": customerId
1042
+ }
1043
+ });
1044
+ try {
1045
+ const result = await ddbDocClient.send(command);
1046
+ return result.Items || null;
1047
+ } catch (error) {
1048
+ console.error(
1049
+ `Error fetching subscriptions by customerId: ${customerId}`,
1050
+ error
1051
+ );
1052
+ throw new Error("Could not fetch subscriptions by customerId");
1053
+ }
1054
+ }
1029
1055
  };
1030
1056
  var Subscription_default = Subscription;
1031
1057
 
package/dist/index.d.cts CHANGED
@@ -484,6 +484,12 @@ declare class Subscription {
484
484
  * @returns A promise that resolves when all subscriptions are deleted.
485
485
  */
486
486
  static deleteAllSubscriptionsByUserId(userId: string): Promise<void>;
487
+ /**
488
+ * Fetch all subscriptions by customer ID.
489
+ * @param customerId - The ID of the customer whose subscriptions to retrieve.
490
+ * @returns A promise that resolves to an array of subscription objects or null if not found.
491
+ */
492
+ static getSubscriptionsByCustomerId(customerId: string): Promise<INotiHubSubscription[] | null>;
487
493
  }
488
494
 
489
495
  declare class NotiTypeStats {
package/dist/index.d.ts CHANGED
@@ -484,6 +484,12 @@ declare class Subscription {
484
484
  * @returns A promise that resolves when all subscriptions are deleted.
485
485
  */
486
486
  static deleteAllSubscriptionsByUserId(userId: string): Promise<void>;
487
+ /**
488
+ * Fetch all subscriptions by customer ID.
489
+ * @param customerId - The ID of the customer whose subscriptions to retrieve.
490
+ * @returns A promise that resolves to an array of subscription objects or null if not found.
491
+ */
492
+ static getSubscriptionsByCustomerId(customerId: string): Promise<INotiHubSubscription[] | null>;
487
493
  }
488
494
 
489
495
  declare class NotiTypeStats {
package/dist/index.js CHANGED
@@ -903,7 +903,7 @@ import {
903
903
  } from "@aws-sdk/lib-dynamodb";
904
904
  var Subscription = class _Subscription {
905
905
  static ENV = process.env.ENV || "dev";
906
- static TABLE_NAME = `NotiHub-Subscriptions-v1-${_Subscription.ENV}`;
906
+ static TABLE_NAME = `NotiHub-Subscriptions-v2-${_Subscription.ENV}`;
907
907
  /**
908
908
  * Retrieves a subscription by its ID.
909
909
  * @param id - The ID of the subscription to retrieve.
@@ -1020,6 +1020,32 @@ var Subscription = class _Subscription {
1020
1020
  await Promise.all(deletePromises);
1021
1021
  }
1022
1022
  }
1023
+ /**
1024
+ * Fetch all subscriptions by customer ID.
1025
+ * @param customerId - The ID of the customer whose subscriptions to retrieve.
1026
+ * @returns A promise that resolves to an array of subscription objects or null if not found.
1027
+ */
1028
+ static async getSubscriptionsByCustomerId(customerId) {
1029
+ const command = new QueryCommand6({
1030
+ TableName: _Subscription.TABLE_NAME,
1031
+ IndexName: "CustomerIdIndex",
1032
+ // Assuming you have a GSI for customerId
1033
+ KeyConditionExpression: "customerId = :customerId",
1034
+ ExpressionAttributeValues: {
1035
+ ":customerId": customerId
1036
+ }
1037
+ });
1038
+ try {
1039
+ const result = await ddbDocClient.send(command);
1040
+ return result.Items || null;
1041
+ } catch (error) {
1042
+ console.error(
1043
+ `Error fetching subscriptions by customerId: ${customerId}`,
1044
+ error
1045
+ );
1046
+ throw new Error("Could not fetch subscriptions by customerId");
1047
+ }
1048
+ }
1023
1049
  };
1024
1050
  var Subscription_default = Subscription;
1025
1051
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amohamud23/notihub",
3
- "version": "1.1.26",
3
+ "version": "1.1.28",
4
4
  "description": "Notihub Package",
5
5
  "main": "./dist/index.cjs",
6
6
  "types": "./dist/index.d.cts",