@amohamud23/notihub 1.1.34 → 1.1.36

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
@@ -1556,10 +1556,9 @@ var CustomerMinified = class _CustomerMinified {
1556
1556
  * @returns A promise that resolves to the customer object or null if not found.
1557
1557
  */
1558
1558
  static async getCustomerMinifiedByUsername(username) {
1559
- const command = new import_lib_dynamodb12.QueryCommand({
1559
+ const command = new import_lib_dynamodb12.ScanCommand({
1560
1560
  TableName: _CustomerMinified.TABLE_NAME,
1561
- // IndexName: "UsernameIndex", // Assuming you have a GSI for username
1562
- KeyConditionExpression: "username = :username",
1561
+ FilterExpression: "username = :username",
1563
1562
  ExpressionAttributeValues: {
1564
1563
  ":username": username
1565
1564
  }
@@ -1790,6 +1789,136 @@ var NotiHubStatsHistory = class _NotiHubStatsHistory {
1790
1789
  };
1791
1790
  var NotiHubStatsHistory_default = NotiHubStatsHistory;
1792
1791
 
1792
+ // src/DynamoModels/StripeSubscriptions.ts
1793
+ var import_lib_dynamodb15 = require("@aws-sdk/lib-dynamodb");
1794
+ var StripeSubscription = class _StripeSubscription {
1795
+ static ENV = process.env.ENV || "dev";
1796
+ static TABLE_NAME = `NotiHub-StripeSubscriptions-v1-${_StripeSubscription.ENV}`;
1797
+ /**
1798
+ * Retrieves all stripe subscriptions.
1799
+ * @returns A promise that resolves to an array of stripe subscription objects.
1800
+ */
1801
+ static async getAllStripeSubscriptions() {
1802
+ const command = new import_lib_dynamodb15.ScanCommand({
1803
+ TableName: _StripeSubscription.TABLE_NAME
1804
+ });
1805
+ try {
1806
+ const result = await ddbDocClient.send(command);
1807
+ return result.Items || [];
1808
+ } catch (error) {
1809
+ console.error("Error fetching all stripe subscriptions:", error);
1810
+ throw new Error("Could not fetch stripe subscriptions");
1811
+ }
1812
+ }
1813
+ /**
1814
+ * Retrieves a stripe subscription by its ID.
1815
+ * @param id - The ID of the stripe subscription to retrieve.
1816
+ * @returns A promise that resolves to the stripe subscription object or null if not found.
1817
+ */
1818
+ static async getStripeSubscriptionById(id) {
1819
+ const command = new import_lib_dynamodb15.GetCommand({
1820
+ TableName: _StripeSubscription.TABLE_NAME,
1821
+ Key: { id }
1822
+ });
1823
+ try {
1824
+ const result = await ddbDocClient.send(command);
1825
+ return result.Item || null;
1826
+ } catch (error) {
1827
+ console.error("Error fetching stripe subscription:", error);
1828
+ throw new Error("Could not fetch stripe subscription");
1829
+ }
1830
+ }
1831
+ /**
1832
+ * Retrieves stripe subscriptions by customer ID.
1833
+ * @param customer - The customer ID to retrieve subscriptions for.
1834
+ * @returns A promise that resolves to an array of stripe subscription objects.
1835
+ */
1836
+ static async getStripeSubscriptionsByCustomerId(customerId) {
1837
+ const command = new import_lib_dynamodb15.QueryCommand({
1838
+ TableName: _StripeSubscription.TABLE_NAME,
1839
+ IndexName: "CustomerIndex",
1840
+ KeyConditionExpression: "customerId = :customerId",
1841
+ ExpressionAttributeValues: {
1842
+ ":customerId": customerId
1843
+ }
1844
+ });
1845
+ try {
1846
+ const result = await ddbDocClient.send(command);
1847
+ return result.Items || [];
1848
+ } catch (error) {
1849
+ console.error(
1850
+ `Error fetching stripe subscriptions for customerId: ${customerId}`,
1851
+ error
1852
+ );
1853
+ throw new Error("Could not fetch stripe subscriptions by customerId");
1854
+ }
1855
+ }
1856
+ /**
1857
+ * Creates a new stripe subscription.
1858
+ * @param stripeSubscription - The stripe subscription object to create.
1859
+ * @returns A promise that resolves to the created stripe subscription object.
1860
+ */
1861
+ static async createStripeSubscription(stripeSubscription) {
1862
+ const command = new import_lib_dynamodb15.PutCommand({
1863
+ TableName: _StripeSubscription.TABLE_NAME,
1864
+ Item: stripeSubscription
1865
+ });
1866
+ try {
1867
+ await ddbDocClient.send(command);
1868
+ return stripeSubscription;
1869
+ } catch (error) {
1870
+ console.error("Error creating stripe subscription:", error);
1871
+ throw new Error("Could not create stripe subscription");
1872
+ }
1873
+ }
1874
+ /**
1875
+ * Deletes a stripe subscription by its ID.
1876
+ * @param id - The ID of the stripe subscription to delete.
1877
+ * @returns A promise that resolves when the stripe subscription is deleted.
1878
+ */
1879
+ static async deleteStripeSubscription(id) {
1880
+ const command = new import_lib_dynamodb15.DeleteCommand({
1881
+ TableName: _StripeSubscription.TABLE_NAME,
1882
+ Key: { id }
1883
+ });
1884
+ try {
1885
+ await ddbDocClient.send(command);
1886
+ } catch (error) {
1887
+ console.error("Error deleting stripe subscription:", error);
1888
+ throw new Error("Could not delete stripe subscription");
1889
+ }
1890
+ }
1891
+ /**
1892
+ * Updates an existing stripe subscription.
1893
+ * @param id - The ID of the stripe subscription to update.
1894
+ * @param updates - The updates to apply to the stripe subscription.
1895
+ * @returns A promise that resolves to the updated stripe subscription object.
1896
+ */
1897
+ static async updateStripeSubscription(id, updates) {
1898
+ const updateExpressions = [];
1899
+ const expressionAttributeValues = {};
1900
+ for (const [key, value] of Object.entries(updates)) {
1901
+ updateExpressions.push(`${key} = :${key}`);
1902
+ expressionAttributeValues[`:${key}`] = value;
1903
+ }
1904
+ const command = new import_lib_dynamodb15.UpdateCommand({
1905
+ TableName: _StripeSubscription.TABLE_NAME,
1906
+ Key: { id },
1907
+ UpdateExpression: `SET ${updateExpressions.join(", ")}`,
1908
+ ExpressionAttributeValues: expressionAttributeValues,
1909
+ ReturnValues: "ALL_NEW"
1910
+ });
1911
+ try {
1912
+ const result = await ddbDocClient.send(command);
1913
+ return result.Attributes;
1914
+ } catch (error) {
1915
+ console.error("Error updating stripe subscription:", error);
1916
+ throw new Error("Could not update stripe subscription");
1917
+ }
1918
+ }
1919
+ };
1920
+ var StripeSubscriptions_default = StripeSubscription;
1921
+
1793
1922
  // src/DynamoModels/index.ts
1794
1923
  var TABLES = {
1795
1924
  User: User_default,
@@ -1804,7 +1933,8 @@ var TABLES = {
1804
1933
  CustomerMetaData: CustomerMetaData_default,
1805
1934
  CustomerMinified: CustomerMinified_default,
1806
1935
  NotificationStats: NotificationStats_default,
1807
- NotiHubStatsHistory: NotiHubStatsHistory_default
1936
+ NotiHubStatsHistory: NotiHubStatsHistory_default,
1937
+ StripeSubscription: StripeSubscriptions_default
1808
1938
  };
1809
1939
 
1810
1940
  // src/errorcodes.ts
package/dist/index.d.cts CHANGED
@@ -173,11 +173,13 @@ type IUserSubscribeNotifier = {
173
173
  };
174
174
  type INotiHubUserView = {
175
175
  id: string;
176
- userId: string;
176
+ userId: string | null;
177
+ email?: string;
177
178
  customerId: string;
178
179
  notificationId: string;
179
180
  viewId: string;
180
181
  createdAt: string;
182
+ type: "EMAIL" | "MOBILE";
181
183
  };
182
184
  type INotiHubSubscription = {
183
185
  id: string;
@@ -198,8 +200,7 @@ type INotiHubSubscriptionActivity = {
198
200
  };
199
201
  type INotiHubStripeSubscription = {
200
202
  id: string;
201
- customer: string;
202
- customerRef: INotiHubCustomer;
203
+ customerId: string;
203
204
  stripe_subscription: string;
204
205
  };
205
206
  type INotiHubPaymentSession = {
@@ -704,6 +705,47 @@ declare class NotiHubStatsHistory {
704
705
  static getLastStatsHistoryByCustomerId(customerId: string): Promise<INotiHubStatsHistory | null>;
705
706
  }
706
707
 
708
+ declare class StripeSubscription {
709
+ static ENV: string;
710
+ static TABLE_NAME: string;
711
+ /**
712
+ * Retrieves all stripe subscriptions.
713
+ * @returns A promise that resolves to an array of stripe subscription objects.
714
+ */
715
+ static getAllStripeSubscriptions(): Promise<INotiHubStripeSubscription[]>;
716
+ /**
717
+ * Retrieves a stripe subscription by its ID.
718
+ * @param id - The ID of the stripe subscription to retrieve.
719
+ * @returns A promise that resolves to the stripe subscription object or null if not found.
720
+ */
721
+ static getStripeSubscriptionById(id: string): Promise<INotiHubStripeSubscription | null>;
722
+ /**
723
+ * Retrieves stripe subscriptions by customer ID.
724
+ * @param customer - The customer ID to retrieve subscriptions for.
725
+ * @returns A promise that resolves to an array of stripe subscription objects.
726
+ */
727
+ static getStripeSubscriptionsByCustomerId(customerId: string): Promise<INotiHubStripeSubscription[]>;
728
+ /**
729
+ * Creates a new stripe subscription.
730
+ * @param stripeSubscription - The stripe subscription object to create.
731
+ * @returns A promise that resolves to the created stripe subscription object.
732
+ */
733
+ static createStripeSubscription(stripeSubscription: INotiHubStripeSubscription): Promise<INotiHubStripeSubscription>;
734
+ /**
735
+ * Deletes a stripe subscription by its ID.
736
+ * @param id - The ID of the stripe subscription to delete.
737
+ * @returns A promise that resolves when the stripe subscription is deleted.
738
+ */
739
+ static deleteStripeSubscription(id: string): Promise<void>;
740
+ /**
741
+ * Updates an existing stripe subscription.
742
+ * @param id - The ID of the stripe subscription to update.
743
+ * @param updates - The updates to apply to the stripe subscription.
744
+ * @returns A promise that resolves to the updated stripe subscription object.
745
+ */
746
+ static updateStripeSubscription(id: string, updates: Partial<INotiHubStripeSubscription>): Promise<INotiHubStripeSubscription>;
747
+ }
748
+
707
749
  declare const TABLES: {
708
750
  User: typeof User;
709
751
  Customer: typeof Customer;
@@ -718,6 +760,7 @@ declare const TABLES: {
718
760
  CustomerMinified: typeof CustomerMinified;
719
761
  NotificationStats: typeof NotificationStats;
720
762
  NotiHubStatsHistory: typeof NotiHubStatsHistory;
763
+ StripeSubscription: typeof StripeSubscription;
721
764
  };
722
765
 
723
766
  declare const DocumentNotFound = "4001";
package/dist/index.d.ts CHANGED
@@ -173,11 +173,13 @@ type IUserSubscribeNotifier = {
173
173
  };
174
174
  type INotiHubUserView = {
175
175
  id: string;
176
- userId: string;
176
+ userId: string | null;
177
+ email?: string;
177
178
  customerId: string;
178
179
  notificationId: string;
179
180
  viewId: string;
180
181
  createdAt: string;
182
+ type: "EMAIL" | "MOBILE";
181
183
  };
182
184
  type INotiHubSubscription = {
183
185
  id: string;
@@ -198,8 +200,7 @@ type INotiHubSubscriptionActivity = {
198
200
  };
199
201
  type INotiHubStripeSubscription = {
200
202
  id: string;
201
- customer: string;
202
- customerRef: INotiHubCustomer;
203
+ customerId: string;
203
204
  stripe_subscription: string;
204
205
  };
205
206
  type INotiHubPaymentSession = {
@@ -704,6 +705,47 @@ declare class NotiHubStatsHistory {
704
705
  static getLastStatsHistoryByCustomerId(customerId: string): Promise<INotiHubStatsHistory | null>;
705
706
  }
706
707
 
708
+ declare class StripeSubscription {
709
+ static ENV: string;
710
+ static TABLE_NAME: string;
711
+ /**
712
+ * Retrieves all stripe subscriptions.
713
+ * @returns A promise that resolves to an array of stripe subscription objects.
714
+ */
715
+ static getAllStripeSubscriptions(): Promise<INotiHubStripeSubscription[]>;
716
+ /**
717
+ * Retrieves a stripe subscription by its ID.
718
+ * @param id - The ID of the stripe subscription to retrieve.
719
+ * @returns A promise that resolves to the stripe subscription object or null if not found.
720
+ */
721
+ static getStripeSubscriptionById(id: string): Promise<INotiHubStripeSubscription | null>;
722
+ /**
723
+ * Retrieves stripe subscriptions by customer ID.
724
+ * @param customer - The customer ID to retrieve subscriptions for.
725
+ * @returns A promise that resolves to an array of stripe subscription objects.
726
+ */
727
+ static getStripeSubscriptionsByCustomerId(customerId: string): Promise<INotiHubStripeSubscription[]>;
728
+ /**
729
+ * Creates a new stripe subscription.
730
+ * @param stripeSubscription - The stripe subscription object to create.
731
+ * @returns A promise that resolves to the created stripe subscription object.
732
+ */
733
+ static createStripeSubscription(stripeSubscription: INotiHubStripeSubscription): Promise<INotiHubStripeSubscription>;
734
+ /**
735
+ * Deletes a stripe subscription by its ID.
736
+ * @param id - The ID of the stripe subscription to delete.
737
+ * @returns A promise that resolves when the stripe subscription is deleted.
738
+ */
739
+ static deleteStripeSubscription(id: string): Promise<void>;
740
+ /**
741
+ * Updates an existing stripe subscription.
742
+ * @param id - The ID of the stripe subscription to update.
743
+ * @param updates - The updates to apply to the stripe subscription.
744
+ * @returns A promise that resolves to the updated stripe subscription object.
745
+ */
746
+ static updateStripeSubscription(id: string, updates: Partial<INotiHubStripeSubscription>): Promise<INotiHubStripeSubscription>;
747
+ }
748
+
707
749
  declare const TABLES: {
708
750
  User: typeof User;
709
751
  Customer: typeof Customer;
@@ -718,6 +760,7 @@ declare const TABLES: {
718
760
  CustomerMinified: typeof CustomerMinified;
719
761
  NotificationStats: typeof NotificationStats;
720
762
  NotiHubStatsHistory: typeof NotiHubStatsHistory;
763
+ StripeSubscription: typeof StripeSubscription;
721
764
  };
722
765
 
723
766
  declare const DocumentNotFound = "4001";
package/dist/index.js CHANGED
@@ -1485,7 +1485,6 @@ import {
1485
1485
  DeleteCommand as DeleteCommand10,
1486
1486
  GetCommand as GetCommand10,
1487
1487
  PutCommand as PutCommand11,
1488
- QueryCommand as QueryCommand11,
1489
1488
  ScanCommand as ScanCommand3
1490
1489
  } from "@aws-sdk/lib-dynamodb";
1491
1490
  var CustomerMinified = class _CustomerMinified {
@@ -1572,10 +1571,9 @@ var CustomerMinified = class _CustomerMinified {
1572
1571
  * @returns A promise that resolves to the customer object or null if not found.
1573
1572
  */
1574
1573
  static async getCustomerMinifiedByUsername(username) {
1575
- const command = new QueryCommand11({
1574
+ const command = new ScanCommand3({
1576
1575
  TableName: _CustomerMinified.TABLE_NAME,
1577
- // IndexName: "UsernameIndex", // Assuming you have a GSI for username
1578
- KeyConditionExpression: "username = :username",
1576
+ FilterExpression: "username = :username",
1579
1577
  ExpressionAttributeValues: {
1580
1578
  ":username": username
1581
1579
  }
@@ -1814,6 +1812,143 @@ var NotiHubStatsHistory = class _NotiHubStatsHistory {
1814
1812
  };
1815
1813
  var NotiHubStatsHistory_default = NotiHubStatsHistory;
1816
1814
 
1815
+ // src/DynamoModels/StripeSubscriptions.ts
1816
+ import {
1817
+ DeleteCommand as DeleteCommand13,
1818
+ GetCommand as GetCommand13,
1819
+ PutCommand as PutCommand14,
1820
+ QueryCommand as QueryCommand13,
1821
+ UpdateCommand as UpdateCommand13,
1822
+ ScanCommand as ScanCommand4
1823
+ } from "@aws-sdk/lib-dynamodb";
1824
+ var StripeSubscription = class _StripeSubscription {
1825
+ static ENV = process.env.ENV || "dev";
1826
+ static TABLE_NAME = `NotiHub-StripeSubscriptions-v1-${_StripeSubscription.ENV}`;
1827
+ /**
1828
+ * Retrieves all stripe subscriptions.
1829
+ * @returns A promise that resolves to an array of stripe subscription objects.
1830
+ */
1831
+ static async getAllStripeSubscriptions() {
1832
+ const command = new ScanCommand4({
1833
+ TableName: _StripeSubscription.TABLE_NAME
1834
+ });
1835
+ try {
1836
+ const result = await ddbDocClient.send(command);
1837
+ return result.Items || [];
1838
+ } catch (error) {
1839
+ console.error("Error fetching all stripe subscriptions:", error);
1840
+ throw new Error("Could not fetch stripe subscriptions");
1841
+ }
1842
+ }
1843
+ /**
1844
+ * Retrieves a stripe subscription by its ID.
1845
+ * @param id - The ID of the stripe subscription to retrieve.
1846
+ * @returns A promise that resolves to the stripe subscription object or null if not found.
1847
+ */
1848
+ static async getStripeSubscriptionById(id) {
1849
+ const command = new GetCommand13({
1850
+ TableName: _StripeSubscription.TABLE_NAME,
1851
+ Key: { id }
1852
+ });
1853
+ try {
1854
+ const result = await ddbDocClient.send(command);
1855
+ return result.Item || null;
1856
+ } catch (error) {
1857
+ console.error("Error fetching stripe subscription:", error);
1858
+ throw new Error("Could not fetch stripe subscription");
1859
+ }
1860
+ }
1861
+ /**
1862
+ * Retrieves stripe subscriptions by customer ID.
1863
+ * @param customer - The customer ID to retrieve subscriptions for.
1864
+ * @returns A promise that resolves to an array of stripe subscription objects.
1865
+ */
1866
+ static async getStripeSubscriptionsByCustomerId(customerId) {
1867
+ const command = new QueryCommand13({
1868
+ TableName: _StripeSubscription.TABLE_NAME,
1869
+ IndexName: "CustomerIndex",
1870
+ KeyConditionExpression: "customerId = :customerId",
1871
+ ExpressionAttributeValues: {
1872
+ ":customerId": customerId
1873
+ }
1874
+ });
1875
+ try {
1876
+ const result = await ddbDocClient.send(command);
1877
+ return result.Items || [];
1878
+ } catch (error) {
1879
+ console.error(
1880
+ `Error fetching stripe subscriptions for customerId: ${customerId}`,
1881
+ error
1882
+ );
1883
+ throw new Error("Could not fetch stripe subscriptions by customerId");
1884
+ }
1885
+ }
1886
+ /**
1887
+ * Creates a new stripe subscription.
1888
+ * @param stripeSubscription - The stripe subscription object to create.
1889
+ * @returns A promise that resolves to the created stripe subscription object.
1890
+ */
1891
+ static async createStripeSubscription(stripeSubscription) {
1892
+ const command = new PutCommand14({
1893
+ TableName: _StripeSubscription.TABLE_NAME,
1894
+ Item: stripeSubscription
1895
+ });
1896
+ try {
1897
+ await ddbDocClient.send(command);
1898
+ return stripeSubscription;
1899
+ } catch (error) {
1900
+ console.error("Error creating stripe subscription:", error);
1901
+ throw new Error("Could not create stripe subscription");
1902
+ }
1903
+ }
1904
+ /**
1905
+ * Deletes a stripe subscription by its ID.
1906
+ * @param id - The ID of the stripe subscription to delete.
1907
+ * @returns A promise that resolves when the stripe subscription is deleted.
1908
+ */
1909
+ static async deleteStripeSubscription(id) {
1910
+ const command = new DeleteCommand13({
1911
+ TableName: _StripeSubscription.TABLE_NAME,
1912
+ Key: { id }
1913
+ });
1914
+ try {
1915
+ await ddbDocClient.send(command);
1916
+ } catch (error) {
1917
+ console.error("Error deleting stripe subscription:", error);
1918
+ throw new Error("Could not delete stripe subscription");
1919
+ }
1920
+ }
1921
+ /**
1922
+ * Updates an existing stripe subscription.
1923
+ * @param id - The ID of the stripe subscription to update.
1924
+ * @param updates - The updates to apply to the stripe subscription.
1925
+ * @returns A promise that resolves to the updated stripe subscription object.
1926
+ */
1927
+ static async updateStripeSubscription(id, updates) {
1928
+ const updateExpressions = [];
1929
+ const expressionAttributeValues = {};
1930
+ for (const [key, value] of Object.entries(updates)) {
1931
+ updateExpressions.push(`${key} = :${key}`);
1932
+ expressionAttributeValues[`:${key}`] = value;
1933
+ }
1934
+ const command = new UpdateCommand13({
1935
+ TableName: _StripeSubscription.TABLE_NAME,
1936
+ Key: { id },
1937
+ UpdateExpression: `SET ${updateExpressions.join(", ")}`,
1938
+ ExpressionAttributeValues: expressionAttributeValues,
1939
+ ReturnValues: "ALL_NEW"
1940
+ });
1941
+ try {
1942
+ const result = await ddbDocClient.send(command);
1943
+ return result.Attributes;
1944
+ } catch (error) {
1945
+ console.error("Error updating stripe subscription:", error);
1946
+ throw new Error("Could not update stripe subscription");
1947
+ }
1948
+ }
1949
+ };
1950
+ var StripeSubscriptions_default = StripeSubscription;
1951
+
1817
1952
  // src/DynamoModels/index.ts
1818
1953
  var TABLES = {
1819
1954
  User: User_default,
@@ -1828,7 +1963,8 @@ var TABLES = {
1828
1963
  CustomerMetaData: CustomerMetaData_default,
1829
1964
  CustomerMinified: CustomerMinified_default,
1830
1965
  NotificationStats: NotificationStats_default,
1831
- NotiHubStatsHistory: NotiHubStatsHistory_default
1966
+ NotiHubStatsHistory: NotiHubStatsHistory_default,
1967
+ StripeSubscription: StripeSubscriptions_default
1832
1968
  };
1833
1969
 
1834
1970
  // src/errorcodes.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amohamud23/notihub",
3
- "version": "1.1.34",
3
+ "version": "1.1.36",
4
4
  "description": "Notihub Package",
5
5
  "main": "./dist/index.cjs",
6
6
  "types": "./dist/index.d.cts",