@amohamud23/notihub 1.0.155 → 1.0.157
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 +535 -4
- package/dist/index.d.cts +215 -39
- package/dist/index.d.ts +215 -39
- package/dist/index.js +565 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -595,7 +595,7 @@ var ddbDocClient = import_lib_dynamodb.DynamoDBDocumentClient.from(ddbClient, {
|
|
|
595
595
|
});
|
|
596
596
|
var USER_TABLE_NAME = process.env.USER_TABLE_NAME || "NotiHub-Users-v1-dev";
|
|
597
597
|
|
|
598
|
-
// src/DynamoModels/
|
|
598
|
+
// src/DynamoModels/User.ts
|
|
599
599
|
var import_lib_dynamodb2 = require("@aws-sdk/lib-dynamodb");
|
|
600
600
|
var User = class _User {
|
|
601
601
|
static ENV = process.env.ENV || "dev";
|
|
@@ -694,7 +694,7 @@ var User = class _User {
|
|
|
694
694
|
}
|
|
695
695
|
}
|
|
696
696
|
};
|
|
697
|
-
var
|
|
697
|
+
var User_default = User;
|
|
698
698
|
|
|
699
699
|
// src/DynamoModels/Customer.ts
|
|
700
700
|
var import_lib_dynamodb3 = require("@aws-sdk/lib-dynamodb");
|
|
@@ -803,10 +803,541 @@ var Customer2 = class _Customer {
|
|
|
803
803
|
};
|
|
804
804
|
var Customer_default = Customer2;
|
|
805
805
|
|
|
806
|
+
// src/DynamoModels/Notifications.ts
|
|
807
|
+
var import_lib_dynamodb4 = require("@aws-sdk/lib-dynamodb");
|
|
808
|
+
var Notifications = class _Notifications {
|
|
809
|
+
static ENV = process.env.ENV || "dev";
|
|
810
|
+
static TABLE_NAME = `NotiHub-Notifications-${_Notifications.ENV}`;
|
|
811
|
+
/**
|
|
812
|
+
* Retrieves a notification by its ID.
|
|
813
|
+
* @param id - The ID of the notification to retrieve.
|
|
814
|
+
* @returns A promise that resolves to the notification object or null if not found.
|
|
815
|
+
*/
|
|
816
|
+
static async getNotificationById(id) {
|
|
817
|
+
const command = new import_lib_dynamodb4.GetCommand({
|
|
818
|
+
TableName: _Notifications.TABLE_NAME,
|
|
819
|
+
Key: { id }
|
|
820
|
+
});
|
|
821
|
+
try {
|
|
822
|
+
const result = await ddbDocClient.send(command);
|
|
823
|
+
return result.Item || null;
|
|
824
|
+
} catch (error) {
|
|
825
|
+
console.error("Error fetching notification:", error);
|
|
826
|
+
throw new Error("Could not fetch notification");
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
static async getNotificationsByEntityId(entityId) {
|
|
830
|
+
const command = new import_lib_dynamodb4.QueryCommand({
|
|
831
|
+
TableName: _Notifications.TABLE_NAME,
|
|
832
|
+
IndexName: "EntityIdIndex",
|
|
833
|
+
// Assuming you have a GSI for entityId
|
|
834
|
+
KeyConditionExpression: "entityId = :entityId",
|
|
835
|
+
ExpressionAttributeValues: {
|
|
836
|
+
":entityId": entityId
|
|
837
|
+
}
|
|
838
|
+
});
|
|
839
|
+
try {
|
|
840
|
+
const result = await ddbDocClient.send(command);
|
|
841
|
+
return result.Items || null;
|
|
842
|
+
} catch (error) {
|
|
843
|
+
console.error(
|
|
844
|
+
`Error fetching notifications by entityId: ${entityId}`,
|
|
845
|
+
error
|
|
846
|
+
);
|
|
847
|
+
throw new Error("Could not fetch notifications by entityId");
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
/**
|
|
851
|
+
* Creates a new notification.
|
|
852
|
+
* @param notification - The notification object to create.
|
|
853
|
+
* @returns A promise that resolves to the created notification object.
|
|
854
|
+
*/
|
|
855
|
+
static async createNotification(notification) {
|
|
856
|
+
const command = new import_lib_dynamodb4.PutCommand({
|
|
857
|
+
TableName: _Notifications.TABLE_NAME,
|
|
858
|
+
Item: notification
|
|
859
|
+
});
|
|
860
|
+
try {
|
|
861
|
+
await ddbDocClient.send(command);
|
|
862
|
+
return notification;
|
|
863
|
+
} catch (error) {
|
|
864
|
+
console.error("Error creating notification:", error);
|
|
865
|
+
throw new Error("Could not create notification");
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
// Additional methods can be added here as needed
|
|
869
|
+
};
|
|
870
|
+
var Notifications_default = Notifications;
|
|
871
|
+
|
|
872
|
+
// src/DynamoModels/NotiHubStats.ts
|
|
873
|
+
var import_lib_dynamodb5 = require("@aws-sdk/lib-dynamodb");
|
|
874
|
+
var NotiHubStats = class _NotiHubStats {
|
|
875
|
+
static ENV = process.env.ENV || "dev";
|
|
876
|
+
static TABLE_NAME = `NotiHub-Stats-${_NotiHubStats.ENV}`;
|
|
877
|
+
/**
|
|
878
|
+
* Retrieves the statistics for NotiHub.
|
|
879
|
+
* @returns A promise that resolves to the statistics object or null if not found.
|
|
880
|
+
*/
|
|
881
|
+
static async getStats(notificationId) {
|
|
882
|
+
const command = new import_lib_dynamodb5.GetCommand({
|
|
883
|
+
TableName: _NotiHubStats.TABLE_NAME,
|
|
884
|
+
Key: { notificationId }
|
|
885
|
+
});
|
|
886
|
+
try {
|
|
887
|
+
const result = await ddbDocClient.send(command);
|
|
888
|
+
return result.Item || null;
|
|
889
|
+
} catch (error) {
|
|
890
|
+
console.error("Error fetching NotiHub stats:", error);
|
|
891
|
+
throw new Error("Could not fetch NotiHub stats");
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
/**
|
|
895
|
+
* Updates the statistics for NotiHub.
|
|
896
|
+
* @param notificationId - The ID of the notification to update the stats for.
|
|
897
|
+
* @returns A promise that resolves to the updated statistics object.
|
|
898
|
+
*/
|
|
899
|
+
static async updateViewsStats(notificationId) {
|
|
900
|
+
const command = new import_lib_dynamodb5.UpdateCommand({
|
|
901
|
+
TableName: _NotiHubStats.TABLE_NAME,
|
|
902
|
+
Key: { notificationId },
|
|
903
|
+
UpdateExpression: "ADD views :inc",
|
|
904
|
+
ExpressionAttributeValues: {
|
|
905
|
+
":inc": 1
|
|
906
|
+
},
|
|
907
|
+
ReturnValues: "ALL_NEW"
|
|
908
|
+
});
|
|
909
|
+
try {
|
|
910
|
+
const result = await ddbDocClient.send(command);
|
|
911
|
+
return result.Attributes;
|
|
912
|
+
} catch (error) {
|
|
913
|
+
console.error("Error updating NotiHub stats:", error);
|
|
914
|
+
throw new Error("Could not update NotiHub stats");
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
};
|
|
918
|
+
var NotiHubStats_default = NotiHubStats;
|
|
919
|
+
|
|
920
|
+
// src/DynamoModels/NotiType.ts
|
|
921
|
+
var import_lib_dynamodb6 = require("@aws-sdk/lib-dynamodb");
|
|
922
|
+
var NotiType = class _NotiType {
|
|
923
|
+
static ENV = process.env.ENV || "dev";
|
|
924
|
+
static TABLE_NAME = `NotiHub-NotiTypes-${_NotiType.ENV}`;
|
|
925
|
+
/**
|
|
926
|
+
* Retrieves a notification type by its ID.
|
|
927
|
+
* @param id - The ID of the notification type to retrieve.
|
|
928
|
+
* @returns A promise that resolves to the notification type object or null if not found.
|
|
929
|
+
*/
|
|
930
|
+
static async getNotiTypeById(id) {
|
|
931
|
+
const command = new import_lib_dynamodb6.GetCommand({
|
|
932
|
+
TableName: _NotiType.TABLE_NAME,
|
|
933
|
+
Key: { id }
|
|
934
|
+
});
|
|
935
|
+
try {
|
|
936
|
+
const result = await ddbDocClient.send(command);
|
|
937
|
+
return result.Item || null;
|
|
938
|
+
} catch (error) {
|
|
939
|
+
console.error("Error fetching notification type:", error);
|
|
940
|
+
throw new Error("Could not fetch notification type");
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
/**
|
|
944
|
+
* Retrieves all notification types.
|
|
945
|
+
* @returns A promise that resolves to an array of notification type objects.
|
|
946
|
+
*/
|
|
947
|
+
static async getAllNotiTypesByEntityId(entityId) {
|
|
948
|
+
const command = new import_lib_dynamodb6.QueryCommand({
|
|
949
|
+
TableName: _NotiType.TABLE_NAME,
|
|
950
|
+
IndexName: "EntityIdIndex",
|
|
951
|
+
// Assuming you have a GSI for entityId
|
|
952
|
+
KeyConditionExpression: "entityId = :entityId",
|
|
953
|
+
ExpressionAttributeValues: {
|
|
954
|
+
":entityId": entityId
|
|
955
|
+
}
|
|
956
|
+
});
|
|
957
|
+
try {
|
|
958
|
+
const result = await ddbDocClient.send(command);
|
|
959
|
+
return result.Items || null;
|
|
960
|
+
} catch (error) {
|
|
961
|
+
console.error(
|
|
962
|
+
`Error fetching notification types by entityId: ${entityId}`,
|
|
963
|
+
error
|
|
964
|
+
);
|
|
965
|
+
throw new Error("Could not fetch notification types by entityId");
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
/**
|
|
969
|
+
* Creates a new notification type.
|
|
970
|
+
* @param notiType - The notification type object to create.
|
|
971
|
+
* @returns A promise that resolves to the created notification type object.
|
|
972
|
+
*/
|
|
973
|
+
static async createNotiType(notiType) {
|
|
974
|
+
const command = new import_lib_dynamodb6.PutCommand({
|
|
975
|
+
TableName: _NotiType.TABLE_NAME,
|
|
976
|
+
Item: notiType
|
|
977
|
+
});
|
|
978
|
+
try {
|
|
979
|
+
await ddbDocClient.send(command);
|
|
980
|
+
return notiType;
|
|
981
|
+
} catch (error) {
|
|
982
|
+
console.error("Error creating notification type:", error);
|
|
983
|
+
throw new Error("Could not create notification type");
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
/**
|
|
987
|
+
* Updates an existing notification type.
|
|
988
|
+
* @param id - The ID of the notification type to update.
|
|
989
|
+
* @param updates - An object containing the fields to update.
|
|
990
|
+
* @returns A promise that resolves to the updated notification type object.
|
|
991
|
+
*/
|
|
992
|
+
static async updateNotiType(id, updates) {
|
|
993
|
+
const command = new import_lib_dynamodb6.UpdateCommand({
|
|
994
|
+
TableName: _NotiType.TABLE_NAME,
|
|
995
|
+
Key: { id },
|
|
996
|
+
UpdateExpression: "set #type = :type, updatedAt = :updatedAt",
|
|
997
|
+
ExpressionAttributeNames: {
|
|
998
|
+
"#type": "type",
|
|
999
|
+
"#updatedAt": "updatedAt"
|
|
1000
|
+
},
|
|
1001
|
+
ExpressionAttributeValues: {
|
|
1002
|
+
":type": updates.type,
|
|
1003
|
+
":updatedAt": (/* @__PURE__ */ new Date()).toISOString()
|
|
1004
|
+
},
|
|
1005
|
+
ReturnValues: "ALL_NEW"
|
|
1006
|
+
});
|
|
1007
|
+
try {
|
|
1008
|
+
const result = await ddbDocClient.send(command);
|
|
1009
|
+
return result.Attributes;
|
|
1010
|
+
} catch (error) {
|
|
1011
|
+
console.error("Error updating notification type:", error);
|
|
1012
|
+
throw new Error("Could not update notification type");
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
};
|
|
1016
|
+
var NotiType_default = NotiType;
|
|
1017
|
+
|
|
1018
|
+
// src/DynamoModels/Subscription.ts
|
|
1019
|
+
var import_lib_dynamodb7 = require("@aws-sdk/lib-dynamodb");
|
|
1020
|
+
var Subscription2 = class _Subscription {
|
|
1021
|
+
static ENV = process.env.ENV || "dev";
|
|
1022
|
+
static TABLE_NAME = `NotiHub-Subscriptions-${_Subscription.ENV}`;
|
|
1023
|
+
/**
|
|
1024
|
+
* Retrieves a subscription by its ID.
|
|
1025
|
+
* @param id - The ID of the subscription to retrieve.
|
|
1026
|
+
* @returns A promise that resolves to the subscription object or null if not found.
|
|
1027
|
+
*/
|
|
1028
|
+
static async getSubscriptionById(id) {
|
|
1029
|
+
const command = new import_lib_dynamodb7.GetCommand({
|
|
1030
|
+
TableName: _Subscription.TABLE_NAME,
|
|
1031
|
+
Key: { id }
|
|
1032
|
+
});
|
|
1033
|
+
try {
|
|
1034
|
+
const result = await ddbDocClient.send(command);
|
|
1035
|
+
return result.Item || null;
|
|
1036
|
+
} catch (error) {
|
|
1037
|
+
console.error("Error fetching subscription:", error);
|
|
1038
|
+
throw new Error("Could not fetch subscription");
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
/**
|
|
1042
|
+
* Retrieves subscriptions by user ID.
|
|
1043
|
+
* @param userId - The ID of the user whose subscriptions to retrieve.
|
|
1044
|
+
* @returns A promise that resolves to an array of subscription objects or null if not found.
|
|
1045
|
+
*/
|
|
1046
|
+
static async getSubscriptionsByUserId(userId) {
|
|
1047
|
+
const command = new import_lib_dynamodb7.QueryCommand({
|
|
1048
|
+
TableName: _Subscription.TABLE_NAME,
|
|
1049
|
+
IndexName: "UserIdIndex",
|
|
1050
|
+
// Assuming you have a GSI for userId
|
|
1051
|
+
KeyConditionExpression: "userId = :userId",
|
|
1052
|
+
ExpressionAttributeValues: {
|
|
1053
|
+
":userId": userId
|
|
1054
|
+
}
|
|
1055
|
+
});
|
|
1056
|
+
try {
|
|
1057
|
+
const result = await ddbDocClient.send(command);
|
|
1058
|
+
return result.Items || null;
|
|
1059
|
+
} catch (error) {
|
|
1060
|
+
console.error(`Error fetching subscriptions by userId: ${userId}`, error);
|
|
1061
|
+
throw new Error("Could not fetch subscriptions by userId");
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
/**
|
|
1065
|
+
* Creates or updates a subscription.
|
|
1066
|
+
* @param subscription - The subscription object to create or update.
|
|
1067
|
+
* @returns A promise that resolves to the created or updated subscription object.
|
|
1068
|
+
*/
|
|
1069
|
+
static async createOrUpdateSubscription(subscription) {
|
|
1070
|
+
const command = new import_lib_dynamodb7.PutCommand({
|
|
1071
|
+
TableName: _Subscription.TABLE_NAME,
|
|
1072
|
+
Item: subscription
|
|
1073
|
+
});
|
|
1074
|
+
try {
|
|
1075
|
+
await ddbDocClient.send(command);
|
|
1076
|
+
return subscription;
|
|
1077
|
+
} catch (error) {
|
|
1078
|
+
console.error("Error creating or updating subscription:", error);
|
|
1079
|
+
throw new Error("Could not create or update subscription");
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
/**
|
|
1083
|
+
* Deletes a subscription by its ID.
|
|
1084
|
+
* @param id - The ID of the subscription to delete.
|
|
1085
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
1086
|
+
*/
|
|
1087
|
+
static async deleteSubscriptionById(id) {
|
|
1088
|
+
const command = new import_lib_dynamodb7.DeleteCommand({
|
|
1089
|
+
TableName: _Subscription.TABLE_NAME,
|
|
1090
|
+
Key: { id }
|
|
1091
|
+
});
|
|
1092
|
+
try {
|
|
1093
|
+
await ddbDocClient.send(command);
|
|
1094
|
+
} catch (error) {
|
|
1095
|
+
console.error("Error deleting subscription:", error);
|
|
1096
|
+
throw new Error("Could not delete subscription");
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
/**
|
|
1100
|
+
* Fetch subscription by SubscriptionId.
|
|
1101
|
+
* @param subscriptionId - The ID of the subscription to retrieve.
|
|
1102
|
+
* @returns A promise that resolves to the subscription object or null if not found.
|
|
1103
|
+
*/
|
|
1104
|
+
static async getSubscriptionBySubscriptionId(subscriptionId) {
|
|
1105
|
+
const command = new import_lib_dynamodb7.GetCommand({
|
|
1106
|
+
TableName: _Subscription.TABLE_NAME,
|
|
1107
|
+
Key: { subscriptionId }
|
|
1108
|
+
});
|
|
1109
|
+
try {
|
|
1110
|
+
const result = await ddbDocClient.send(command);
|
|
1111
|
+
return result.Item || null;
|
|
1112
|
+
} catch (error) {
|
|
1113
|
+
console.error("Error fetching subscription by SubscriptionId:", error);
|
|
1114
|
+
throw new Error("Could not fetch subscription by SubscriptionId");
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
};
|
|
1118
|
+
var Subscription_default = Subscription2;
|
|
1119
|
+
|
|
1120
|
+
// src/DynamoModels/NotiTypeStats.ts
|
|
1121
|
+
var import_lib_dynamodb8 = require("@aws-sdk/lib-dynamodb");
|
|
1122
|
+
var NotiTypeStats = class _NotiTypeStats {
|
|
1123
|
+
static ENV = process.env.ENV || "dev";
|
|
1124
|
+
static TABLE_NAME = `NotiHub-NotiTypeStats-${_NotiTypeStats.ENV}`;
|
|
1125
|
+
/**
|
|
1126
|
+
* Retrieves notification type stats by their ID.
|
|
1127
|
+
* @param id - The ID of the notification type stats to retrieve.
|
|
1128
|
+
* @returns A promise that resolves to the notification type stats object or null if not found.
|
|
1129
|
+
*/
|
|
1130
|
+
static async getNotiTypeStatsById(id) {
|
|
1131
|
+
const command = new import_lib_dynamodb8.GetCommand({
|
|
1132
|
+
TableName: _NotiTypeStats.TABLE_NAME,
|
|
1133
|
+
Key: { id }
|
|
1134
|
+
});
|
|
1135
|
+
try {
|
|
1136
|
+
const result = await ddbDocClient.send(command);
|
|
1137
|
+
return result.Item || null;
|
|
1138
|
+
} catch (error) {
|
|
1139
|
+
console.error("Error fetching notification type stats:", error);
|
|
1140
|
+
throw new Error("Could not fetch notification type stats");
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
/**
|
|
1144
|
+
* Retrieves all notification type stats by entity ID.
|
|
1145
|
+
* @param notiTypeId - The ID of the notification type to retrieve stats for.
|
|
1146
|
+
* @returns A promise that resolves to an array of notification type stats objects or null if not found.
|
|
1147
|
+
*/
|
|
1148
|
+
static async getNotiTypeStatsByNotiTypeId(notiTypeId) {
|
|
1149
|
+
const command = new import_lib_dynamodb8.QueryCommand({
|
|
1150
|
+
TableName: _NotiTypeStats.TABLE_NAME,
|
|
1151
|
+
IndexName: "NotiTypeIdIndex",
|
|
1152
|
+
// Assuming you have a GSI for notiTypeId
|
|
1153
|
+
KeyConditionExpression: "notiTypeId = :notiTypeId",
|
|
1154
|
+
ExpressionAttributeValues: {
|
|
1155
|
+
":notiTypeId": notiTypeId
|
|
1156
|
+
}
|
|
1157
|
+
});
|
|
1158
|
+
try {
|
|
1159
|
+
const result = await ddbDocClient.send(command);
|
|
1160
|
+
return result.Items || null;
|
|
1161
|
+
} catch (error) {
|
|
1162
|
+
console.error(
|
|
1163
|
+
`Error fetching notification type stats by notiTypeId: ${notiTypeId}`,
|
|
1164
|
+
error
|
|
1165
|
+
);
|
|
1166
|
+
throw new Error("Could not fetch notification type stats by notiTypeId");
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
/**
|
|
1170
|
+
* Creates or updates notification type stats.
|
|
1171
|
+
* @param notiTypeStats - The notification type stats object to create or update.
|
|
1172
|
+
* @returns A promise that resolves to the created or updated notification type stats object.
|
|
1173
|
+
*/
|
|
1174
|
+
static async createOrUpdateNotiTypeStats(notiTypeStats) {
|
|
1175
|
+
const command = new import_lib_dynamodb8.PutCommand({
|
|
1176
|
+
TableName: _NotiTypeStats.TABLE_NAME,
|
|
1177
|
+
Item: notiTypeStats
|
|
1178
|
+
});
|
|
1179
|
+
try {
|
|
1180
|
+
await ddbDocClient.send(command);
|
|
1181
|
+
return notiTypeStats;
|
|
1182
|
+
} catch (error) {
|
|
1183
|
+
console.error(
|
|
1184
|
+
"Error creating or updating notification type stats:",
|
|
1185
|
+
error
|
|
1186
|
+
);
|
|
1187
|
+
throw new Error("Could not create or update notification type stats");
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
};
|
|
1191
|
+
var NotiTypeStats_default = NotiTypeStats;
|
|
1192
|
+
|
|
1193
|
+
// src/DynamoModels/Views.ts
|
|
1194
|
+
var import_lib_dynamodb9 = require("@aws-sdk/lib-dynamodb");
|
|
1195
|
+
var Views = class _Views {
|
|
1196
|
+
static ENV = process.env.ENV || "dev";
|
|
1197
|
+
static TABLE_NAME = `NotiHub-Views-${_Views.ENV}`;
|
|
1198
|
+
/**
|
|
1199
|
+
* Retrieves a view by its ID.
|
|
1200
|
+
* @param id - The ID of the view to retrieve.
|
|
1201
|
+
* @returns A promise that resolves to the view object or null if not found.
|
|
1202
|
+
*/
|
|
1203
|
+
static async getViewById(id) {
|
|
1204
|
+
const command = new import_lib_dynamodb9.GetCommand({
|
|
1205
|
+
TableName: _Views.TABLE_NAME,
|
|
1206
|
+
Key: { id }
|
|
1207
|
+
});
|
|
1208
|
+
try {
|
|
1209
|
+
const result = await ddbDocClient.send(command);
|
|
1210
|
+
return result.Item || null;
|
|
1211
|
+
} catch (error) {
|
|
1212
|
+
console.error("Error fetching view:", error);
|
|
1213
|
+
throw new Error("Could not fetch view");
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
/**
|
|
1217
|
+
* Creates or updates a view.
|
|
1218
|
+
* @param view - The view object to create or update.
|
|
1219
|
+
* @returns A promise that resolves to the created or updated view object.
|
|
1220
|
+
*/
|
|
1221
|
+
static async createView(view) {
|
|
1222
|
+
const command = new import_lib_dynamodb9.PutCommand({
|
|
1223
|
+
TableName: _Views.TABLE_NAME,
|
|
1224
|
+
Item: view
|
|
1225
|
+
});
|
|
1226
|
+
try {
|
|
1227
|
+
await ddbDocClient.send(command);
|
|
1228
|
+
return view;
|
|
1229
|
+
} catch (error) {
|
|
1230
|
+
console.error("Error creating or updating view:", error);
|
|
1231
|
+
throw new Error("Could not create or update view");
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
};
|
|
1235
|
+
var Views_default = Views;
|
|
1236
|
+
|
|
1237
|
+
// src/DynamoModels/SubscriptionType.ts
|
|
1238
|
+
var import_lib_dynamodb10 = require("@aws-sdk/lib-dynamodb");
|
|
1239
|
+
var SubscriptionType2 = class _SubscriptionType {
|
|
1240
|
+
static ENV = process.env.ENV || "dev";
|
|
1241
|
+
static TABLE_NAME = `NotiHub-SubscriptionTypes-${_SubscriptionType.ENV}`;
|
|
1242
|
+
/**
|
|
1243
|
+
* Retrieves a subscription type by its ID.
|
|
1244
|
+
* @param id - The ID of the subscription type to retrieve.
|
|
1245
|
+
* @returns A promise that resolves to the subscription type object or null if not found.
|
|
1246
|
+
*/
|
|
1247
|
+
static async getSubscriptionTypeById(id) {
|
|
1248
|
+
const command = new import_lib_dynamodb10.GetCommand({
|
|
1249
|
+
TableName: _SubscriptionType.TABLE_NAME,
|
|
1250
|
+
Key: { id }
|
|
1251
|
+
});
|
|
1252
|
+
try {
|
|
1253
|
+
const result = await ddbDocClient.send(command);
|
|
1254
|
+
return result.Item || null;
|
|
1255
|
+
} catch (error) {
|
|
1256
|
+
console.error("Error fetching subscription type:", error);
|
|
1257
|
+
throw new Error("Could not fetch subscription type");
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
static async getSubscriptionTypesByUserId(userId) {
|
|
1261
|
+
const command = new import_lib_dynamodb10.QueryCommand({
|
|
1262
|
+
TableName: _SubscriptionType.TABLE_NAME,
|
|
1263
|
+
IndexName: "UserIdIndex",
|
|
1264
|
+
// Assuming you have a GSI for userId
|
|
1265
|
+
KeyConditionExpression: "userId = :userId",
|
|
1266
|
+
ExpressionAttributeValues: {
|
|
1267
|
+
":userId": userId
|
|
1268
|
+
}
|
|
1269
|
+
});
|
|
1270
|
+
try {
|
|
1271
|
+
const result = await ddbDocClient.send(command);
|
|
1272
|
+
return result.Items || null;
|
|
1273
|
+
} catch (error) {
|
|
1274
|
+
console.error(
|
|
1275
|
+
`Error fetching subscription types by userId: ${userId}`,
|
|
1276
|
+
error
|
|
1277
|
+
);
|
|
1278
|
+
throw new Error("Could not fetch subscription types by userId");
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
// Additional methods for creating, updating, and deleting subscription types can be added here
|
|
1282
|
+
};
|
|
1283
|
+
var SubscriptionType_default = SubscriptionType2;
|
|
1284
|
+
|
|
1285
|
+
// src/DynamoModels/CustomerMetaData.ts
|
|
1286
|
+
var import_lib_dynamodb11 = require("@aws-sdk/lib-dynamodb");
|
|
1287
|
+
var CustomerMetaData = class _CustomerMetaData {
|
|
1288
|
+
static ENV = process.env.ENV || "dev";
|
|
1289
|
+
static TABLE_NAME = `NotiHub-CustomerMetaData-${_CustomerMetaData.ENV}`;
|
|
1290
|
+
/**
|
|
1291
|
+
* Retrieves customer metadata by its ID.
|
|
1292
|
+
* @param id - The ID of the customer metadata to retrieve.
|
|
1293
|
+
* @returns A promise that resolves to the customer metadata object or null if not found.
|
|
1294
|
+
*/
|
|
1295
|
+
static async getCustomerMetaDataById(id) {
|
|
1296
|
+
const command = new import_lib_dynamodb11.GetCommand({
|
|
1297
|
+
TableName: _CustomerMetaData.TABLE_NAME,
|
|
1298
|
+
Key: { id }
|
|
1299
|
+
});
|
|
1300
|
+
try {
|
|
1301
|
+
const result = await ddbDocClient.send(command);
|
|
1302
|
+
return result.Item || null;
|
|
1303
|
+
} catch (error) {
|
|
1304
|
+
console.error("Error fetching customer metadata:", error);
|
|
1305
|
+
throw new Error("Could not fetch customer metadata");
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
/**
|
|
1309
|
+
* Creates or updates customer metadata.
|
|
1310
|
+
* @param customerMetaData - The customer metadata object to create or update.
|
|
1311
|
+
* @returns A promise that resolves to the created or updated customer metadata object.
|
|
1312
|
+
*/
|
|
1313
|
+
static async createOrUpdateCustomerMetaData(customerMetaData) {
|
|
1314
|
+
const command = new import_lib_dynamodb11.PutCommand({
|
|
1315
|
+
TableName: _CustomerMetaData.TABLE_NAME,
|
|
1316
|
+
Item: customerMetaData
|
|
1317
|
+
});
|
|
1318
|
+
try {
|
|
1319
|
+
await ddbDocClient.send(command);
|
|
1320
|
+
return customerMetaData;
|
|
1321
|
+
} catch (error) {
|
|
1322
|
+
console.error("Error creating or updating customer metadata:", error);
|
|
1323
|
+
throw new Error("Could not create or update customer metadata");
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
};
|
|
1327
|
+
var CustomerMetaData_default = CustomerMetaData;
|
|
1328
|
+
|
|
806
1329
|
// src/DynamoModels/index.ts
|
|
807
1330
|
var TABLES = {
|
|
808
|
-
User:
|
|
809
|
-
Customer: Customer_default
|
|
1331
|
+
User: User_default,
|
|
1332
|
+
Customer: Customer_default,
|
|
1333
|
+
Notifications: Notifications_default,
|
|
1334
|
+
NotiHubStats: NotiHubStats_default,
|
|
1335
|
+
NotiType: NotiType_default,
|
|
1336
|
+
Subscription: Subscription_default,
|
|
1337
|
+
NotiTypeStats: NotiTypeStats_default,
|
|
1338
|
+
Views: Views_default,
|
|
1339
|
+
SubscriptionType: SubscriptionType_default,
|
|
1340
|
+
CustomerMetaData: CustomerMetaData_default
|
|
810
1341
|
};
|
|
811
1342
|
|
|
812
1343
|
// src/errorcodes.ts
|