@amohamud23/notihub 1.0.181 → 1.0.183
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 +72 -0
- package/dist/index.d.cts +16 -2
- package/dist/index.d.ts +16 -2
- package/dist/index.js +72 -0
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -975,6 +975,7 @@ var Views_default = Views;
|
|
|
975
975
|
|
|
976
976
|
// src/DynamoModels/SubscriptionType.ts
|
|
977
977
|
var import_lib_dynamodb10 = require("@aws-sdk/lib-dynamodb");
|
|
978
|
+
var import_date_fns = require("date-fns");
|
|
978
979
|
var SubscriptionType = class _SubscriptionType {
|
|
979
980
|
static ENV = process.env.ENV || "dev";
|
|
980
981
|
static TABLE_NAME = `NotiHub-SubscriptionTypes-v1-${_SubscriptionType.ENV}`;
|
|
@@ -1034,6 +1035,43 @@ var SubscriptionType = class _SubscriptionType {
|
|
|
1034
1035
|
throw new Error("Could not delete subscription type");
|
|
1035
1036
|
}
|
|
1036
1037
|
}
|
|
1038
|
+
/**
|
|
1039
|
+
* Get subscription types chart by customerId.
|
|
1040
|
+
* @param customerId - The ID of the customer to retrieve subscription types for.
|
|
1041
|
+
* @returns A promise that resolves to an array of subscription type objects or null if not found.
|
|
1042
|
+
*/
|
|
1043
|
+
static async getSubscriptionTypesChartByCustomerId(customerId) {
|
|
1044
|
+
let lastKey;
|
|
1045
|
+
const dateMap = {};
|
|
1046
|
+
const command = new import_lib_dynamodb10.QueryCommand({
|
|
1047
|
+
TableName: _SubscriptionType.TABLE_NAME,
|
|
1048
|
+
IndexName: "CustomerIdIndex",
|
|
1049
|
+
KeyConditionExpression: "customerId = :customerId",
|
|
1050
|
+
ExpressionAttributeValues: {
|
|
1051
|
+
":customerId": customerId
|
|
1052
|
+
},
|
|
1053
|
+
ExclusiveStartKey: lastKey
|
|
1054
|
+
});
|
|
1055
|
+
try {
|
|
1056
|
+
do {
|
|
1057
|
+
const result = await ddbDocClient.send(command);
|
|
1058
|
+
const items = result.Items;
|
|
1059
|
+
items.forEach((item) => {
|
|
1060
|
+
const date = (0, import_date_fns.format)((0, import_date_fns.parseISO)(item.createdAt), "yyyy-MM-dd");
|
|
1061
|
+
dateMap[date] = (dateMap[date] || 0) + 1;
|
|
1062
|
+
});
|
|
1063
|
+
lastKey = result.LastEvaluatedKey;
|
|
1064
|
+
} while (lastKey);
|
|
1065
|
+
const chartData = Object.entries(dateMap).sort(([a], [b]) => a > b ? 1 : -1).map(([date, count]) => ({ date, count }));
|
|
1066
|
+
return chartData.length > 0 ? chartData : null;
|
|
1067
|
+
} catch (error) {
|
|
1068
|
+
console.error(
|
|
1069
|
+
`Error fetching subscription types by customerId: ${customerId}`,
|
|
1070
|
+
error
|
|
1071
|
+
);
|
|
1072
|
+
throw new Error("Could not fetch subscription types by customerId");
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1037
1075
|
};
|
|
1038
1076
|
var SubscriptionType_default = SubscriptionType;
|
|
1039
1077
|
|
|
@@ -1324,6 +1362,40 @@ var NotiHubStatsHistory = class _NotiHubStatsHistory {
|
|
|
1324
1362
|
throw new Error("Could not fetch NotiHub stats history by customerId");
|
|
1325
1363
|
}
|
|
1326
1364
|
}
|
|
1365
|
+
/**
|
|
1366
|
+
* Get last stats history by customerId
|
|
1367
|
+
* @param customerId - The ID of the customer to retrieve stats history for.
|
|
1368
|
+
* @returns A promise that resolves to the last statistics history object or null if not found.
|
|
1369
|
+
*/
|
|
1370
|
+
static async getLastStatsHistoryByCustomerId(customerId) {
|
|
1371
|
+
const command = new import_lib_dynamodb14.QueryCommand({
|
|
1372
|
+
TableName: _NotiHubStatsHistory.TABLE_NAME,
|
|
1373
|
+
IndexName: "CustomerIdIndex",
|
|
1374
|
+
KeyConditionExpression: "customerId = :customerId",
|
|
1375
|
+
ExpressionAttributeValues: {
|
|
1376
|
+
":customerId": customerId
|
|
1377
|
+
},
|
|
1378
|
+
ScanIndexForward: false,
|
|
1379
|
+
// Get the latest entry first
|
|
1380
|
+
Limit: 1
|
|
1381
|
+
// Only get the last entry
|
|
1382
|
+
});
|
|
1383
|
+
try {
|
|
1384
|
+
const result = await ddbDocClient.send(command);
|
|
1385
|
+
if (result.Items && result.Items.length > 0) {
|
|
1386
|
+
return result.Items[0];
|
|
1387
|
+
}
|
|
1388
|
+
return null;
|
|
1389
|
+
} catch (error) {
|
|
1390
|
+
console.error(
|
|
1391
|
+
`Error fetching last NotiHub stats history by customerId: ${customerId}`,
|
|
1392
|
+
error
|
|
1393
|
+
);
|
|
1394
|
+
throw new Error(
|
|
1395
|
+
"Could not fetch last NotiHub stats history by customerId"
|
|
1396
|
+
);
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1327
1399
|
};
|
|
1328
1400
|
var NotiHubStatsHistory_default = NotiHubStatsHistory;
|
|
1329
1401
|
|
package/dist/index.d.cts
CHANGED
|
@@ -161,11 +161,10 @@ type IUserSubscription = {
|
|
|
161
161
|
};
|
|
162
162
|
type IUserSubscribeNotifier = {
|
|
163
163
|
userId: string;
|
|
164
|
-
userRef: INotiHubUser;
|
|
165
164
|
customerId: string;
|
|
166
165
|
customer: INotiHubCustomer;
|
|
167
166
|
notiTypeId: string;
|
|
168
|
-
|
|
167
|
+
notiType: INotiType;
|
|
169
168
|
subscriptionId: string;
|
|
170
169
|
createdAt: string;
|
|
171
170
|
updatedAt: string;
|
|
@@ -503,6 +502,15 @@ declare class SubscriptionType {
|
|
|
503
502
|
* @returns A promise that resolves when the subscription type is deleted.
|
|
504
503
|
*/
|
|
505
504
|
static deleteSubscriptionTypeById(id: string): Promise<void>;
|
|
505
|
+
/**
|
|
506
|
+
* Get subscription types chart by customerId.
|
|
507
|
+
* @param customerId - The ID of the customer to retrieve subscription types for.
|
|
508
|
+
* @returns A promise that resolves to an array of subscription type objects or null if not found.
|
|
509
|
+
*/
|
|
510
|
+
static getSubscriptionTypesChartByCustomerId(customerId: string): Promise<{
|
|
511
|
+
date: string;
|
|
512
|
+
count: number;
|
|
513
|
+
}[] | null>;
|
|
506
514
|
}
|
|
507
515
|
|
|
508
516
|
declare class CustomerMetaData {
|
|
@@ -601,6 +609,12 @@ declare class NotiHubStatsHistory {
|
|
|
601
609
|
* @returns A promise that resolves to an array of statistics history objects or null if not found.
|
|
602
610
|
*/
|
|
603
611
|
static getStatsHistoryPastSixMonthsByCustomerId(customerId: string): Promise<INotiHubStatsHistory[] | null>;
|
|
612
|
+
/**
|
|
613
|
+
* Get last stats history by customerId
|
|
614
|
+
* @param customerId - The ID of the customer to retrieve stats history for.
|
|
615
|
+
* @returns A promise that resolves to the last statistics history object or null if not found.
|
|
616
|
+
*/
|
|
617
|
+
static getLastStatsHistoryByCustomerId(customerId: string): Promise<INotiHubStatsHistory | null>;
|
|
604
618
|
}
|
|
605
619
|
|
|
606
620
|
declare const TABLES: {
|
package/dist/index.d.ts
CHANGED
|
@@ -161,11 +161,10 @@ type IUserSubscription = {
|
|
|
161
161
|
};
|
|
162
162
|
type IUserSubscribeNotifier = {
|
|
163
163
|
userId: string;
|
|
164
|
-
userRef: INotiHubUser;
|
|
165
164
|
customerId: string;
|
|
166
165
|
customer: INotiHubCustomer;
|
|
167
166
|
notiTypeId: string;
|
|
168
|
-
|
|
167
|
+
notiType: INotiType;
|
|
169
168
|
subscriptionId: string;
|
|
170
169
|
createdAt: string;
|
|
171
170
|
updatedAt: string;
|
|
@@ -503,6 +502,15 @@ declare class SubscriptionType {
|
|
|
503
502
|
* @returns A promise that resolves when the subscription type is deleted.
|
|
504
503
|
*/
|
|
505
504
|
static deleteSubscriptionTypeById(id: string): Promise<void>;
|
|
505
|
+
/**
|
|
506
|
+
* Get subscription types chart by customerId.
|
|
507
|
+
* @param customerId - The ID of the customer to retrieve subscription types for.
|
|
508
|
+
* @returns A promise that resolves to an array of subscription type objects or null if not found.
|
|
509
|
+
*/
|
|
510
|
+
static getSubscriptionTypesChartByCustomerId(customerId: string): Promise<{
|
|
511
|
+
date: string;
|
|
512
|
+
count: number;
|
|
513
|
+
}[] | null>;
|
|
506
514
|
}
|
|
507
515
|
|
|
508
516
|
declare class CustomerMetaData {
|
|
@@ -601,6 +609,12 @@ declare class NotiHubStatsHistory {
|
|
|
601
609
|
* @returns A promise that resolves to an array of statistics history objects or null if not found.
|
|
602
610
|
*/
|
|
603
611
|
static getStatsHistoryPastSixMonthsByCustomerId(customerId: string): Promise<INotiHubStatsHistory[] | null>;
|
|
612
|
+
/**
|
|
613
|
+
* Get last stats history by customerId
|
|
614
|
+
* @param customerId - The ID of the customer to retrieve stats history for.
|
|
615
|
+
* @returns A promise that resolves to the last statistics history object or null if not found.
|
|
616
|
+
*/
|
|
617
|
+
static getLastStatsHistoryByCustomerId(customerId: string): Promise<INotiHubStatsHistory | null>;
|
|
604
618
|
}
|
|
605
619
|
|
|
606
620
|
declare const TABLES: {
|
package/dist/index.js
CHANGED
|
@@ -981,6 +981,7 @@ import {
|
|
|
981
981
|
GetCommand as GetCommand9,
|
|
982
982
|
QueryCommand as QueryCommand9
|
|
983
983
|
} from "@aws-sdk/lib-dynamodb";
|
|
984
|
+
import { format, parseISO } from "date-fns";
|
|
984
985
|
var SubscriptionType = class _SubscriptionType {
|
|
985
986
|
static ENV = process.env.ENV || "dev";
|
|
986
987
|
static TABLE_NAME = `NotiHub-SubscriptionTypes-v1-${_SubscriptionType.ENV}`;
|
|
@@ -1040,6 +1041,43 @@ var SubscriptionType = class _SubscriptionType {
|
|
|
1040
1041
|
throw new Error("Could not delete subscription type");
|
|
1041
1042
|
}
|
|
1042
1043
|
}
|
|
1044
|
+
/**
|
|
1045
|
+
* Get subscription types chart by customerId.
|
|
1046
|
+
* @param customerId - The ID of the customer to retrieve subscription types for.
|
|
1047
|
+
* @returns A promise that resolves to an array of subscription type objects or null if not found.
|
|
1048
|
+
*/
|
|
1049
|
+
static async getSubscriptionTypesChartByCustomerId(customerId) {
|
|
1050
|
+
let lastKey;
|
|
1051
|
+
const dateMap = {};
|
|
1052
|
+
const command = new QueryCommand9({
|
|
1053
|
+
TableName: _SubscriptionType.TABLE_NAME,
|
|
1054
|
+
IndexName: "CustomerIdIndex",
|
|
1055
|
+
KeyConditionExpression: "customerId = :customerId",
|
|
1056
|
+
ExpressionAttributeValues: {
|
|
1057
|
+
":customerId": customerId
|
|
1058
|
+
},
|
|
1059
|
+
ExclusiveStartKey: lastKey
|
|
1060
|
+
});
|
|
1061
|
+
try {
|
|
1062
|
+
do {
|
|
1063
|
+
const result = await ddbDocClient.send(command);
|
|
1064
|
+
const items = result.Items;
|
|
1065
|
+
items.forEach((item) => {
|
|
1066
|
+
const date = format(parseISO(item.createdAt), "yyyy-MM-dd");
|
|
1067
|
+
dateMap[date] = (dateMap[date] || 0) + 1;
|
|
1068
|
+
});
|
|
1069
|
+
lastKey = result.LastEvaluatedKey;
|
|
1070
|
+
} while (lastKey);
|
|
1071
|
+
const chartData = Object.entries(dateMap).sort(([a], [b]) => a > b ? 1 : -1).map(([date, count]) => ({ date, count }));
|
|
1072
|
+
return chartData.length > 0 ? chartData : null;
|
|
1073
|
+
} catch (error) {
|
|
1074
|
+
console.error(
|
|
1075
|
+
`Error fetching subscription types by customerId: ${customerId}`,
|
|
1076
|
+
error
|
|
1077
|
+
);
|
|
1078
|
+
throw new Error("Could not fetch subscription types by customerId");
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1043
1081
|
};
|
|
1044
1082
|
var SubscriptionType_default = SubscriptionType;
|
|
1045
1083
|
|
|
@@ -1341,6 +1379,40 @@ var NotiHubStatsHistory = class _NotiHubStatsHistory {
|
|
|
1341
1379
|
throw new Error("Could not fetch NotiHub stats history by customerId");
|
|
1342
1380
|
}
|
|
1343
1381
|
}
|
|
1382
|
+
/**
|
|
1383
|
+
* Get last stats history by customerId
|
|
1384
|
+
* @param customerId - The ID of the customer to retrieve stats history for.
|
|
1385
|
+
* @returns A promise that resolves to the last statistics history object or null if not found.
|
|
1386
|
+
*/
|
|
1387
|
+
static async getLastStatsHistoryByCustomerId(customerId) {
|
|
1388
|
+
const command = new QueryCommand10({
|
|
1389
|
+
TableName: _NotiHubStatsHistory.TABLE_NAME,
|
|
1390
|
+
IndexName: "CustomerIdIndex",
|
|
1391
|
+
KeyConditionExpression: "customerId = :customerId",
|
|
1392
|
+
ExpressionAttributeValues: {
|
|
1393
|
+
":customerId": customerId
|
|
1394
|
+
},
|
|
1395
|
+
ScanIndexForward: false,
|
|
1396
|
+
// Get the latest entry first
|
|
1397
|
+
Limit: 1
|
|
1398
|
+
// Only get the last entry
|
|
1399
|
+
});
|
|
1400
|
+
try {
|
|
1401
|
+
const result = await ddbDocClient.send(command);
|
|
1402
|
+
if (result.Items && result.Items.length > 0) {
|
|
1403
|
+
return result.Items[0];
|
|
1404
|
+
}
|
|
1405
|
+
return null;
|
|
1406
|
+
} catch (error) {
|
|
1407
|
+
console.error(
|
|
1408
|
+
`Error fetching last NotiHub stats history by customerId: ${customerId}`,
|
|
1409
|
+
error
|
|
1410
|
+
);
|
|
1411
|
+
throw new Error(
|
|
1412
|
+
"Could not fetch last NotiHub stats history by customerId"
|
|
1413
|
+
);
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1344
1416
|
};
|
|
1345
1417
|
var NotiHubStatsHistory_default = NotiHubStatsHistory;
|
|
1346
1418
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amohamud23/notihub",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.183",
|
|
4
4
|
"description": "Notihub Package",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"types": "./dist/index.d.cts",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"@aws-sdk/client-dynamodb": "^3.821.0",
|
|
34
34
|
"@aws-sdk/lib-dynamodb": "^3.821.0",
|
|
35
35
|
"aws-sdk-client-mock": "^4.1.0",
|
|
36
|
+
"date-fns": "^4.1.0",
|
|
36
37
|
"mongoose": "^8.7.2",
|
|
37
38
|
"ts-node": "^10.9.2",
|
|
38
39
|
"tsup": "^8.3.5",
|