@amohamud23/notihub 1.0.167 → 1.0.169

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
@@ -1208,6 +1208,155 @@ var CustomerMinified = class _CustomerMinified {
1208
1208
  };
1209
1209
  var CustomerMinified_default = CustomerMinified;
1210
1210
 
1211
+ // src/DynamoModels/NotificationStats.ts
1212
+ var import_lib_dynamodb13 = require("@aws-sdk/lib-dynamodb");
1213
+ var NotificationStats = class _NotificationStats {
1214
+ static ENV = process.env.ENV || "dev";
1215
+ static TABLE_NAME = `NotiHub-NotificationStats-${_NotificationStats.ENV}`;
1216
+ /**
1217
+ * Retrieves notification stats by their ID.
1218
+ * @param id - The ID of the notification stats to retrieve.
1219
+ * @returns A promise that resolves to the notification stats object or null if not found.
1220
+ */
1221
+ static async getNotificationStatsById(id) {
1222
+ const command = new import_lib_dynamodb13.GetCommand({
1223
+ TableName: _NotificationStats.TABLE_NAME,
1224
+ Key: { id }
1225
+ });
1226
+ try {
1227
+ const result = await ddbDocClient.send(command);
1228
+ return result.Item || null;
1229
+ } catch (error) {
1230
+ console.error("Error fetching notification stats:", error);
1231
+ throw new Error("Could not fetch notification stats");
1232
+ }
1233
+ }
1234
+ /**
1235
+ * Creates a new notification stats entry.
1236
+ * @param stats - The notification stats object to create.
1237
+ * @returns A promise that resolves to the created notification stats object.
1238
+ */
1239
+ static async createNotificationStats(stats) {
1240
+ const command = new import_lib_dynamodb13.PutCommand({
1241
+ TableName: _NotificationStats.TABLE_NAME,
1242
+ Item: stats
1243
+ });
1244
+ try {
1245
+ const result = await ddbDocClient.send(command);
1246
+ return result.Attributes;
1247
+ } catch (error) {
1248
+ console.error("Error creating notification stats:", error);
1249
+ throw new Error("Could not create notification stats");
1250
+ }
1251
+ }
1252
+ /**
1253
+ * Deletes a notification stats entry by its ID.
1254
+ * @param id - The ID of the notification stats to delete.
1255
+ * @returns A promise that resolves when the deletion is complete.
1256
+ */
1257
+ static async deleteNotificationStatsById(id) {
1258
+ const command = new import_lib_dynamodb13.DeleteCommand({
1259
+ TableName: _NotificationStats.TABLE_NAME,
1260
+ Key: { id }
1261
+ });
1262
+ try {
1263
+ await ddbDocClient.send(command);
1264
+ } catch (error) {
1265
+ console.error("Error deleting notification stats:", error);
1266
+ throw new Error("Could not delete notification stats");
1267
+ }
1268
+ }
1269
+ };
1270
+ var NotificationStats_default = NotificationStats;
1271
+
1272
+ // src/DynamoModels/NotiHubStatsHistory.ts
1273
+ var import_lib_dynamodb14 = require("@aws-sdk/lib-dynamodb");
1274
+ var NotiHubStatsHistory = class _NotiHubStatsHistory {
1275
+ static ENV = process.env.ENV || "dev";
1276
+ static TABLE_NAME = `NotiHub-StatsHistory-${_NotiHubStatsHistory.ENV}`;
1277
+ /**
1278
+ * Creates a new NotiHub stats history entry.
1279
+ * @param statsHistory - The statistics history object to create.
1280
+ * @returns A promise that resolves to the created statistics history object.
1281
+ */
1282
+ static async createStatsHistory(statsHistory) {
1283
+ const command = new import_lib_dynamodb14.PutCommand({
1284
+ TableName: _NotiHubStatsHistory.TABLE_NAME,
1285
+ Item: statsHistory
1286
+ });
1287
+ try {
1288
+ const result = await ddbDocClient.send(command);
1289
+ return result.Attributes;
1290
+ } catch (error) {
1291
+ console.error("Error creating NotiHub stats history:", error);
1292
+ throw new Error("Could not create NotiHub stats history");
1293
+ }
1294
+ }
1295
+ /**
1296
+ * Gets stats history by customerId in the last year
1297
+ * @param customerId - The ID of the customer to retrieve stats history for.
1298
+ * @returns A promise that resolves to an array of statistics history objects or null if not found.
1299
+ */
1300
+ static async getStatsHistoryPastYearByCustomerId(customerId) {
1301
+ const oneYearAgo = new Date(
1302
+ Date.now() - 365 * 24 * 60 * 60 * 1e3
1303
+ ).toISOString();
1304
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1305
+ const command = new import_lib_dynamodb14.QueryCommand({
1306
+ TableName: _NotiHubStatsHistory.TABLE_NAME,
1307
+ IndexName: "CustomerIdIndex",
1308
+ KeyConditionExpression: "customerId = :customerId AND createdAt BETWEEN :start AND :end",
1309
+ ExpressionAttributeValues: {
1310
+ ":customerId": customerId,
1311
+ ":start": oneYearAgo,
1312
+ ":end": now
1313
+ }
1314
+ });
1315
+ try {
1316
+ const result = await ddbDocClient.send(command);
1317
+ return result.Items || null;
1318
+ } catch (error) {
1319
+ console.error(
1320
+ `Error fetching NotiHub stats history by customerId: ${customerId}`,
1321
+ error
1322
+ );
1323
+ throw new Error("Could not fetch NotiHub stats history by customerId");
1324
+ }
1325
+ }
1326
+ /**
1327
+ * Gets stats history by customerId from last 6 months
1328
+ * @param customerId - The ID of the customer to retrieve stats history for.
1329
+ * @returns A promise that resolves to an array of statistics history objects or null if not found.
1330
+ */
1331
+ static async getStatsHistoryPastSixMonthsByCustomerId(customerId) {
1332
+ const sixMonthsAgo = new Date(
1333
+ Date.now() - 182 * 24 * 60 * 60 * 1e3
1334
+ ).toISOString();
1335
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1336
+ const command = new import_lib_dynamodb14.QueryCommand({
1337
+ TableName: _NotiHubStatsHistory.TABLE_NAME,
1338
+ IndexName: "CustomerIdIndex",
1339
+ KeyConditionExpression: "customerId = :customerId AND createdAt BETWEEN :start AND :end",
1340
+ ExpressionAttributeValues: {
1341
+ ":customerId": customerId,
1342
+ ":start": sixMonthsAgo,
1343
+ ":end": now
1344
+ }
1345
+ });
1346
+ try {
1347
+ const result = await ddbDocClient.send(command);
1348
+ return result.Items || null;
1349
+ } catch (error) {
1350
+ console.error(
1351
+ `Error fetching NotiHub stats history by customerId: ${customerId}`,
1352
+ error
1353
+ );
1354
+ throw new Error("Could not fetch NotiHub stats history by customerId");
1355
+ }
1356
+ }
1357
+ };
1358
+ var NotiHubStatsHistory_default = NotiHubStatsHistory;
1359
+
1211
1360
  // src/DynamoModels/index.ts
1212
1361
  var TABLES = {
1213
1362
  User: User_default,
@@ -1220,7 +1369,9 @@ var TABLES = {
1220
1369
  Views: Views_default,
1221
1370
  SubscriptionType: SubscriptionType_default,
1222
1371
  CustomerMetaData: CustomerMetaData_default,
1223
- CustomerMinified: CustomerMinified_default
1372
+ CustomerMinified: CustomerMinified_default,
1373
+ NotificationStats: NotificationStats_default,
1374
+ NotiHubStatsHistory: NotiHubStatsHistory_default
1224
1375
  };
1225
1376
 
1226
1377
  // src/errorcodes.ts
package/dist/index.d.cts CHANGED
@@ -577,6 +577,52 @@ declare class CustomerMinified {
577
577
  static deleteCustomerMinifiedById(id: string): Promise<void>;
578
578
  }
579
579
 
580
+ declare class NotificationStats {
581
+ static ENV: string;
582
+ static TABLE_NAME: string;
583
+ /**
584
+ * Retrieves notification stats by their ID.
585
+ * @param id - The ID of the notification stats to retrieve.
586
+ * @returns A promise that resolves to the notification stats object or null if not found.
587
+ */
588
+ static getNotificationStatsById(id: string): Promise<INotiHubNotificationStats | null>;
589
+ /**
590
+ * Creates a new notification stats entry.
591
+ * @param stats - The notification stats object to create.
592
+ * @returns A promise that resolves to the created notification stats object.
593
+ */
594
+ static createNotificationStats(stats: INotiHubNotificationStats): Promise<INotiHubNotificationStats>;
595
+ /**
596
+ * Deletes a notification stats entry by its ID.
597
+ * @param id - The ID of the notification stats to delete.
598
+ * @returns A promise that resolves when the deletion is complete.
599
+ */
600
+ static deleteNotificationStatsById(id: string): Promise<void>;
601
+ }
602
+
603
+ declare class NotiHubStatsHistory {
604
+ static ENV: string;
605
+ static TABLE_NAME: string;
606
+ /**
607
+ * Creates a new NotiHub stats history entry.
608
+ * @param statsHistory - The statistics history object to create.
609
+ * @returns A promise that resolves to the created statistics history object.
610
+ */
611
+ static createStatsHistory(statsHistory: INotiHubStatsHistory): Promise<INotiHubStatsHistory>;
612
+ /**
613
+ * Gets stats history by customerId in the last year
614
+ * @param customerId - The ID of the customer to retrieve stats history for.
615
+ * @returns A promise that resolves to an array of statistics history objects or null if not found.
616
+ */
617
+ static getStatsHistoryPastYearByCustomerId(customerId: string): Promise<INotiHubStatsHistory[] | null>;
618
+ /**
619
+ * Gets stats history by customerId from last 6 months
620
+ * @param customerId - The ID of the customer to retrieve stats history for.
621
+ * @returns A promise that resolves to an array of statistics history objects or null if not found.
622
+ */
623
+ static getStatsHistoryPastSixMonthsByCustomerId(customerId: string): Promise<INotiHubStatsHistory[] | null>;
624
+ }
625
+
580
626
  declare const TABLES: {
581
627
  User: typeof User;
582
628
  Customer: typeof Customer;
@@ -589,6 +635,8 @@ declare const TABLES: {
589
635
  SubscriptionType: typeof SubscriptionType;
590
636
  CustomerMetaData: typeof CustomerMetaData;
591
637
  CustomerMinified: typeof CustomerMinified;
638
+ NotificationStats: typeof NotificationStats;
639
+ NotiHubStatsHistory: typeof NotiHubStatsHistory;
592
640
  };
593
641
 
594
642
  declare const DocumentNotFound = "4001";
package/dist/index.d.ts CHANGED
@@ -577,6 +577,52 @@ declare class CustomerMinified {
577
577
  static deleteCustomerMinifiedById(id: string): Promise<void>;
578
578
  }
579
579
 
580
+ declare class NotificationStats {
581
+ static ENV: string;
582
+ static TABLE_NAME: string;
583
+ /**
584
+ * Retrieves notification stats by their ID.
585
+ * @param id - The ID of the notification stats to retrieve.
586
+ * @returns A promise that resolves to the notification stats object or null if not found.
587
+ */
588
+ static getNotificationStatsById(id: string): Promise<INotiHubNotificationStats | null>;
589
+ /**
590
+ * Creates a new notification stats entry.
591
+ * @param stats - The notification stats object to create.
592
+ * @returns A promise that resolves to the created notification stats object.
593
+ */
594
+ static createNotificationStats(stats: INotiHubNotificationStats): Promise<INotiHubNotificationStats>;
595
+ /**
596
+ * Deletes a notification stats entry by its ID.
597
+ * @param id - The ID of the notification stats to delete.
598
+ * @returns A promise that resolves when the deletion is complete.
599
+ */
600
+ static deleteNotificationStatsById(id: string): Promise<void>;
601
+ }
602
+
603
+ declare class NotiHubStatsHistory {
604
+ static ENV: string;
605
+ static TABLE_NAME: string;
606
+ /**
607
+ * Creates a new NotiHub stats history entry.
608
+ * @param statsHistory - The statistics history object to create.
609
+ * @returns A promise that resolves to the created statistics history object.
610
+ */
611
+ static createStatsHistory(statsHistory: INotiHubStatsHistory): Promise<INotiHubStatsHistory>;
612
+ /**
613
+ * Gets stats history by customerId in the last year
614
+ * @param customerId - The ID of the customer to retrieve stats history for.
615
+ * @returns A promise that resolves to an array of statistics history objects or null if not found.
616
+ */
617
+ static getStatsHistoryPastYearByCustomerId(customerId: string): Promise<INotiHubStatsHistory[] | null>;
618
+ /**
619
+ * Gets stats history by customerId from last 6 months
620
+ * @param customerId - The ID of the customer to retrieve stats history for.
621
+ * @returns A promise that resolves to an array of statistics history objects or null if not found.
622
+ */
623
+ static getStatsHistoryPastSixMonthsByCustomerId(customerId: string): Promise<INotiHubStatsHistory[] | null>;
624
+ }
625
+
580
626
  declare const TABLES: {
581
627
  User: typeof User;
582
628
  Customer: typeof Customer;
@@ -589,6 +635,8 @@ declare const TABLES: {
589
635
  SubscriptionType: typeof SubscriptionType;
590
636
  CustomerMetaData: typeof CustomerMetaData;
591
637
  CustomerMinified: typeof CustomerMinified;
638
+ NotificationStats: typeof NotificationStats;
639
+ NotiHubStatsHistory: typeof NotiHubStatsHistory;
592
640
  };
593
641
 
594
642
  declare const DocumentNotFound = "4001";
package/dist/index.js CHANGED
@@ -1221,6 +1221,158 @@ var CustomerMinified = class _CustomerMinified {
1221
1221
  };
1222
1222
  var CustomerMinified_default = CustomerMinified;
1223
1223
 
1224
+ // src/DynamoModels/NotificationStats.ts
1225
+ import { DeleteCommand as DeleteCommand12, GetCommand as GetCommand12, PutCommand as PutCommand12 } from "@aws-sdk/lib-dynamodb";
1226
+ var NotificationStats = class _NotificationStats {
1227
+ static ENV = process.env.ENV || "dev";
1228
+ static TABLE_NAME = `NotiHub-NotificationStats-${_NotificationStats.ENV}`;
1229
+ /**
1230
+ * Retrieves notification stats by their ID.
1231
+ * @param id - The ID of the notification stats to retrieve.
1232
+ * @returns A promise that resolves to the notification stats object or null if not found.
1233
+ */
1234
+ static async getNotificationStatsById(id) {
1235
+ const command = new GetCommand12({
1236
+ TableName: _NotificationStats.TABLE_NAME,
1237
+ Key: { id }
1238
+ });
1239
+ try {
1240
+ const result = await ddbDocClient.send(command);
1241
+ return result.Item || null;
1242
+ } catch (error) {
1243
+ console.error("Error fetching notification stats:", error);
1244
+ throw new Error("Could not fetch notification stats");
1245
+ }
1246
+ }
1247
+ /**
1248
+ * Creates a new notification stats entry.
1249
+ * @param stats - The notification stats object to create.
1250
+ * @returns A promise that resolves to the created notification stats object.
1251
+ */
1252
+ static async createNotificationStats(stats) {
1253
+ const command = new PutCommand12({
1254
+ TableName: _NotificationStats.TABLE_NAME,
1255
+ Item: stats
1256
+ });
1257
+ try {
1258
+ const result = await ddbDocClient.send(command);
1259
+ return result.Attributes;
1260
+ } catch (error) {
1261
+ console.error("Error creating notification stats:", error);
1262
+ throw new Error("Could not create notification stats");
1263
+ }
1264
+ }
1265
+ /**
1266
+ * Deletes a notification stats entry by its ID.
1267
+ * @param id - The ID of the notification stats to delete.
1268
+ * @returns A promise that resolves when the deletion is complete.
1269
+ */
1270
+ static async deleteNotificationStatsById(id) {
1271
+ const command = new DeleteCommand12({
1272
+ TableName: _NotificationStats.TABLE_NAME,
1273
+ Key: { id }
1274
+ });
1275
+ try {
1276
+ await ddbDocClient.send(command);
1277
+ } catch (error) {
1278
+ console.error("Error deleting notification stats:", error);
1279
+ throw new Error("Could not delete notification stats");
1280
+ }
1281
+ }
1282
+ };
1283
+ var NotificationStats_default = NotificationStats;
1284
+
1285
+ // src/DynamoModels/NotiHubStatsHistory.ts
1286
+ import {
1287
+ PutCommand as PutCommand13,
1288
+ QueryCommand as QueryCommand9
1289
+ } from "@aws-sdk/lib-dynamodb";
1290
+ var NotiHubStatsHistory = class _NotiHubStatsHistory {
1291
+ static ENV = process.env.ENV || "dev";
1292
+ static TABLE_NAME = `NotiHub-StatsHistory-${_NotiHubStatsHistory.ENV}`;
1293
+ /**
1294
+ * Creates a new NotiHub stats history entry.
1295
+ * @param statsHistory - The statistics history object to create.
1296
+ * @returns A promise that resolves to the created statistics history object.
1297
+ */
1298
+ static async createStatsHistory(statsHistory) {
1299
+ const command = new PutCommand13({
1300
+ TableName: _NotiHubStatsHistory.TABLE_NAME,
1301
+ Item: statsHistory
1302
+ });
1303
+ try {
1304
+ const result = await ddbDocClient.send(command);
1305
+ return result.Attributes;
1306
+ } catch (error) {
1307
+ console.error("Error creating NotiHub stats history:", error);
1308
+ throw new Error("Could not create NotiHub stats history");
1309
+ }
1310
+ }
1311
+ /**
1312
+ * Gets stats history by customerId in the last year
1313
+ * @param customerId - The ID of the customer to retrieve stats history for.
1314
+ * @returns A promise that resolves to an array of statistics history objects or null if not found.
1315
+ */
1316
+ static async getStatsHistoryPastYearByCustomerId(customerId) {
1317
+ const oneYearAgo = new Date(
1318
+ Date.now() - 365 * 24 * 60 * 60 * 1e3
1319
+ ).toISOString();
1320
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1321
+ const command = new QueryCommand9({
1322
+ TableName: _NotiHubStatsHistory.TABLE_NAME,
1323
+ IndexName: "CustomerIdIndex",
1324
+ KeyConditionExpression: "customerId = :customerId AND createdAt BETWEEN :start AND :end",
1325
+ ExpressionAttributeValues: {
1326
+ ":customerId": customerId,
1327
+ ":start": oneYearAgo,
1328
+ ":end": now
1329
+ }
1330
+ });
1331
+ try {
1332
+ const result = await ddbDocClient.send(command);
1333
+ return result.Items || null;
1334
+ } catch (error) {
1335
+ console.error(
1336
+ `Error fetching NotiHub stats history by customerId: ${customerId}`,
1337
+ error
1338
+ );
1339
+ throw new Error("Could not fetch NotiHub stats history by customerId");
1340
+ }
1341
+ }
1342
+ /**
1343
+ * Gets stats history by customerId from last 6 months
1344
+ * @param customerId - The ID of the customer to retrieve stats history for.
1345
+ * @returns A promise that resolves to an array of statistics history objects or null if not found.
1346
+ */
1347
+ static async getStatsHistoryPastSixMonthsByCustomerId(customerId) {
1348
+ const sixMonthsAgo = new Date(
1349
+ Date.now() - 182 * 24 * 60 * 60 * 1e3
1350
+ ).toISOString();
1351
+ const now = (/* @__PURE__ */ new Date()).toISOString();
1352
+ const command = new QueryCommand9({
1353
+ TableName: _NotiHubStatsHistory.TABLE_NAME,
1354
+ IndexName: "CustomerIdIndex",
1355
+ KeyConditionExpression: "customerId = :customerId AND createdAt BETWEEN :start AND :end",
1356
+ ExpressionAttributeValues: {
1357
+ ":customerId": customerId,
1358
+ ":start": sixMonthsAgo,
1359
+ ":end": now
1360
+ }
1361
+ });
1362
+ try {
1363
+ const result = await ddbDocClient.send(command);
1364
+ return result.Items || null;
1365
+ } catch (error) {
1366
+ console.error(
1367
+ `Error fetching NotiHub stats history by customerId: ${customerId}`,
1368
+ error
1369
+ );
1370
+ throw new Error("Could not fetch NotiHub stats history by customerId");
1371
+ }
1372
+ }
1373
+ };
1374
+ var NotiHubStatsHistory_default = NotiHubStatsHistory;
1375
+
1224
1376
  // src/DynamoModels/index.ts
1225
1377
  var TABLES = {
1226
1378
  User: User_default,
@@ -1233,7 +1385,9 @@ var TABLES = {
1233
1385
  Views: Views_default,
1234
1386
  SubscriptionType: SubscriptionType_default,
1235
1387
  CustomerMetaData: CustomerMetaData_default,
1236
- CustomerMinified: CustomerMinified_default
1388
+ CustomerMinified: CustomerMinified_default,
1389
+ NotificationStats: NotificationStats_default,
1390
+ NotiHubStatsHistory: NotiHubStatsHistory_default
1237
1391
  };
1238
1392
 
1239
1393
  // src/errorcodes.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amohamud23/notihub",
3
- "version": "1.0.167",
3
+ "version": "1.0.169",
4
4
  "description": "Notihub Package",
5
5
  "main": "./dist/index.cjs",
6
6
  "types": "./dist/index.d.cts",