@amohamud23/notihub 1.0.150 → 1.0.152
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 +53 -8
- package/dist/index.d.cts +25 -1
- package/dist/index.d.ts +25 -1
- package/dist/index.js +50 -7
- package/package.json +3 -1
package/dist/index.cjs
CHANGED
|
@@ -52,7 +52,9 @@ __export(src_exports, {
|
|
|
52
52
|
ViewsModel: () => ViewsModel_default,
|
|
53
53
|
addMonths: () => addMonths,
|
|
54
54
|
getDate: () => getDate,
|
|
55
|
-
getDateFormat: () => getDateFormat
|
|
55
|
+
getDateFormat: () => getDateFormat,
|
|
56
|
+
handleError: () => handleError,
|
|
57
|
+
handleSuccess: () => handleSuccess
|
|
56
58
|
});
|
|
57
59
|
module.exports = __toCommonJS(src_exports);
|
|
58
60
|
|
|
@@ -109,6 +111,41 @@ function addMonths({ date, months }) {
|
|
|
109
111
|
date.setMonth(date.getMonth() + months);
|
|
110
112
|
return date;
|
|
111
113
|
}
|
|
114
|
+
var handleError = (error, res, req) => {
|
|
115
|
+
console.error(`[${(/* @__PURE__ */ new Date()).toISOString()}] Error:`, {
|
|
116
|
+
message: error.message,
|
|
117
|
+
errorCode: error.errorCode,
|
|
118
|
+
stack: process.env.NODE_ENV !== "production" ? error.stack : void 0,
|
|
119
|
+
path: req?.path,
|
|
120
|
+
method: req?.method
|
|
121
|
+
});
|
|
122
|
+
let statusCode = 500;
|
|
123
|
+
let message = error.message || "Something went wrong";
|
|
124
|
+
if (error.errorCode === "UserNotFound" || error.message?.toLowerCase().includes("not found")) {
|
|
125
|
+
statusCode = 404;
|
|
126
|
+
} else if (error.message?.toLowerCase().includes("required") || error.message?.toLowerCase().includes("invalid")) {
|
|
127
|
+
statusCode = 400;
|
|
128
|
+
} else if (error.statusCode) {
|
|
129
|
+
statusCode = error.statusCode;
|
|
130
|
+
}
|
|
131
|
+
const response = {
|
|
132
|
+
success: false,
|
|
133
|
+
message,
|
|
134
|
+
error: error.errorCode || error.name,
|
|
135
|
+
statusCode,
|
|
136
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
137
|
+
};
|
|
138
|
+
res.status(statusCode).json(response);
|
|
139
|
+
};
|
|
140
|
+
var handleSuccess = (data, res, statusCode = 200) => {
|
|
141
|
+
const response = {
|
|
142
|
+
success: true,
|
|
143
|
+
data,
|
|
144
|
+
statusCode,
|
|
145
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
146
|
+
};
|
|
147
|
+
res.status(statusCode).json(response);
|
|
148
|
+
};
|
|
112
149
|
|
|
113
150
|
// src/models/UserModel.ts
|
|
114
151
|
var import_mongoose = require("mongoose");
|
|
@@ -527,17 +564,23 @@ var DocumentNotFoundException = class _DocumentNotFoundException extends Error {
|
|
|
527
564
|
// src/client/DynamoDBClient.ts
|
|
528
565
|
var import_client_dynamodb = require("@aws-sdk/client-dynamodb");
|
|
529
566
|
var import_lib_dynamodb = require("@aws-sdk/lib-dynamodb");
|
|
530
|
-
var
|
|
567
|
+
var isOffline = process.env.IS_OFFLINE === "true";
|
|
531
568
|
var ddbClient = new import_client_dynamodb.DynamoDBClient({
|
|
532
|
-
region:
|
|
533
|
-
|
|
534
|
-
|
|
569
|
+
region: "localhost",
|
|
570
|
+
endpoint: "http://localhost:8000",
|
|
571
|
+
credentials: {
|
|
572
|
+
accessKeyId: "DEFAULT_ACCESS_KEY",
|
|
573
|
+
// needed if you don't have aws credentials at all in env
|
|
574
|
+
secretAccessKey: "DEFAULT_SECRET"
|
|
575
|
+
// needed if you don't have aws credentials at all in env
|
|
576
|
+
}
|
|
535
577
|
});
|
|
536
578
|
var ddbDocClient = import_lib_dynamodb.DynamoDBDocumentClient.from(ddbClient, {
|
|
537
579
|
marshallOptions: {
|
|
538
580
|
removeUndefinedValues: true
|
|
539
581
|
}
|
|
540
582
|
});
|
|
583
|
+
var USER_TABLE_NAME = process.env.USER_TABLE_NAME || "NotiHub-Users-v1-dev";
|
|
541
584
|
|
|
542
585
|
// src/DynamoModels/UserModel.ts
|
|
543
586
|
var import_lib_dynamodb2 = require("@aws-sdk/lib-dynamodb");
|
|
@@ -573,11 +616,11 @@ var User = class _User {
|
|
|
573
616
|
static async getUserByEmail(email) {
|
|
574
617
|
const command = new import_lib_dynamodb2.QueryCommand({
|
|
575
618
|
TableName: _User.TABLE_NAME,
|
|
619
|
+
IndexName: "EmailIndex",
|
|
576
620
|
KeyConditionExpression: "email = :email",
|
|
577
621
|
ExpressionAttributeValues: {
|
|
578
622
|
":email": email
|
|
579
|
-
}
|
|
580
|
-
ConsistentRead: true
|
|
623
|
+
}
|
|
581
624
|
});
|
|
582
625
|
try {
|
|
583
626
|
const result = await ddbDocClient.send(command);
|
|
@@ -795,5 +838,7 @@ var InvalidPushToken = "4009";
|
|
|
795
838
|
ViewsModel,
|
|
796
839
|
addMonths,
|
|
797
840
|
getDate,
|
|
798
|
-
getDateFormat
|
|
841
|
+
getDateFormat,
|
|
842
|
+
handleError,
|
|
843
|
+
handleSuccess
|
|
799
844
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Response as Response$1 } from 'express';
|
|
1
2
|
import * as mongoose from 'mongoose';
|
|
2
3
|
import mongoose__default from 'mongoose';
|
|
3
4
|
|
|
@@ -28,6 +29,13 @@ type ICreateCustomerRequestBody = {
|
|
|
28
29
|
name: string;
|
|
29
30
|
};
|
|
30
31
|
type ICreateNotiRequestBody = {};
|
|
32
|
+
type Response = {
|
|
33
|
+
data?: any;
|
|
34
|
+
message?: string;
|
|
35
|
+
error?: any;
|
|
36
|
+
statusCode?: number;
|
|
37
|
+
timestamp?: string;
|
|
38
|
+
};
|
|
31
39
|
type INotiHubCustomerMinified = {
|
|
32
40
|
_id: string;
|
|
33
41
|
name: string;
|
|
@@ -204,6 +212,22 @@ type AddMonths = {
|
|
|
204
212
|
declare function getDate(dateStr: string): string;
|
|
205
213
|
declare function getDateFormat(dateStr: string): string;
|
|
206
214
|
declare function addMonths({ date, months }: AddMonths): Date;
|
|
215
|
+
/**
|
|
216
|
+
* Handles errors by logging them and sending a standardized error response.
|
|
217
|
+
* @param error - The error object to handle.
|
|
218
|
+
* @param res - The Express response object to send the error response.
|
|
219
|
+
* @param req - Optional Express request object for additional context.
|
|
220
|
+
* @return void
|
|
221
|
+
*/
|
|
222
|
+
declare const handleError: (error: any, res: Response$1, req?: any) => void;
|
|
223
|
+
/**
|
|
224
|
+
* Handles successful responses by sending a standardized success response.
|
|
225
|
+
* @param data - The data to include in the success response.
|
|
226
|
+
* @param res - The Express response object to send the success response.
|
|
227
|
+
* @param statusCode - Optional HTTP status code (default is 200).
|
|
228
|
+
* @return void
|
|
229
|
+
*/
|
|
230
|
+
declare const handleSuccess: <T>(data: T, res: Response$1, statusCode?: number) => void;
|
|
207
231
|
|
|
208
232
|
declare const UserModel: mongoose.Model<INotiHubUser, {}, {}, {}, mongoose.Document<unknown, {}, INotiHubUser> & INotiHubUser & {
|
|
209
233
|
_id: mongoose.Types.ObjectId;
|
|
@@ -400,4 +424,4 @@ declare namespace errorcodes {
|
|
|
400
424
|
export { errorcodes_CustomerNotFound as CustomerNotFound, errorcodes_DocumentNotFound as DocumentNotFound, errorcodes_InvalidEmail as InvalidEmail, errorcodes_InvalidName as InvalidName, errorcodes_InvalidPassword as InvalidPassword, errorcodes_InvalidPushToken as InvalidPushToken, errorcodes_UserNotFound as UserNotFound };
|
|
401
425
|
}
|
|
402
426
|
|
|
403
|
-
export { type CreateNotiRequestBody, type CreateSubscriptionRequestBody, type CreateUserRequestBody, Customer$1 as Customer, CustomerMetadata, CustomerMinified, CustomerNotiHubStats, DocumentNotFoundException, errorcodes as ErrorCode, type ICreateCustomerRequestBody, type ICreateNotiRequestBody, type INotiHubCustomer, type INotiHubCustomerMetadata, type INotiHubCustomerMinified, type INotiHubImage, type INotiHubNotification, type INotiHubNotificationStats, type INotiHubPaymentSession, type INotiHubStats, type INotiHubStatsHistory, type INotiHubStripeSubscription, type INotiHubSubscription, type INotiHubSubscriptionActivity, type INotiHubUser, type INotiHubUserView, type INotiType, type INotiTypeStats, type IUserSubscribeNotifier, type IUserSubscription, client as MongooseClient, NotiHubStatsHistory, type NotiHubTypes, NotiTypeModel, NotiTypeStatsModel, NotificationModel, NotificationStatsModel as NotificationStats, PaymentSessionModel, StripScriptionModel, Subscription, SubscriptionActivity, SubscriptionType, TABLES, UserModel, ViewsModel, addMonths, getDate, getDateFormat };
|
|
427
|
+
export { type CreateNotiRequestBody, type CreateSubscriptionRequestBody, type CreateUserRequestBody, Customer$1 as Customer, CustomerMetadata, CustomerMinified, CustomerNotiHubStats, DocumentNotFoundException, errorcodes as ErrorCode, type ICreateCustomerRequestBody, type ICreateNotiRequestBody, type INotiHubCustomer, type INotiHubCustomerMetadata, type INotiHubCustomerMinified, type INotiHubImage, type INotiHubNotification, type INotiHubNotificationStats, type INotiHubPaymentSession, type INotiHubStats, type INotiHubStatsHistory, type INotiHubStripeSubscription, type INotiHubSubscription, type INotiHubSubscriptionActivity, type INotiHubUser, type INotiHubUserView, type INotiType, type INotiTypeStats, type IUserSubscribeNotifier, type IUserSubscription, client as MongooseClient, NotiHubStatsHistory, type NotiHubTypes, NotiTypeModel, NotiTypeStatsModel, NotificationModel, NotificationStatsModel as NotificationStats, PaymentSessionModel, type Response, StripScriptionModel, Subscription, SubscriptionActivity, SubscriptionType, TABLES, UserModel, ViewsModel, addMonths, getDate, getDateFormat, handleError, handleSuccess };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Response as Response$1 } from 'express';
|
|
1
2
|
import * as mongoose from 'mongoose';
|
|
2
3
|
import mongoose__default from 'mongoose';
|
|
3
4
|
|
|
@@ -28,6 +29,13 @@ type ICreateCustomerRequestBody = {
|
|
|
28
29
|
name: string;
|
|
29
30
|
};
|
|
30
31
|
type ICreateNotiRequestBody = {};
|
|
32
|
+
type Response = {
|
|
33
|
+
data?: any;
|
|
34
|
+
message?: string;
|
|
35
|
+
error?: any;
|
|
36
|
+
statusCode?: number;
|
|
37
|
+
timestamp?: string;
|
|
38
|
+
};
|
|
31
39
|
type INotiHubCustomerMinified = {
|
|
32
40
|
_id: string;
|
|
33
41
|
name: string;
|
|
@@ -204,6 +212,22 @@ type AddMonths = {
|
|
|
204
212
|
declare function getDate(dateStr: string): string;
|
|
205
213
|
declare function getDateFormat(dateStr: string): string;
|
|
206
214
|
declare function addMonths({ date, months }: AddMonths): Date;
|
|
215
|
+
/**
|
|
216
|
+
* Handles errors by logging them and sending a standardized error response.
|
|
217
|
+
* @param error - The error object to handle.
|
|
218
|
+
* @param res - The Express response object to send the error response.
|
|
219
|
+
* @param req - Optional Express request object for additional context.
|
|
220
|
+
* @return void
|
|
221
|
+
*/
|
|
222
|
+
declare const handleError: (error: any, res: Response$1, req?: any) => void;
|
|
223
|
+
/**
|
|
224
|
+
* Handles successful responses by sending a standardized success response.
|
|
225
|
+
* @param data - The data to include in the success response.
|
|
226
|
+
* @param res - The Express response object to send the success response.
|
|
227
|
+
* @param statusCode - Optional HTTP status code (default is 200).
|
|
228
|
+
* @return void
|
|
229
|
+
*/
|
|
230
|
+
declare const handleSuccess: <T>(data: T, res: Response$1, statusCode?: number) => void;
|
|
207
231
|
|
|
208
232
|
declare const UserModel: mongoose.Model<INotiHubUser, {}, {}, {}, mongoose.Document<unknown, {}, INotiHubUser> & INotiHubUser & {
|
|
209
233
|
_id: mongoose.Types.ObjectId;
|
|
@@ -400,4 +424,4 @@ declare namespace errorcodes {
|
|
|
400
424
|
export { errorcodes_CustomerNotFound as CustomerNotFound, errorcodes_DocumentNotFound as DocumentNotFound, errorcodes_InvalidEmail as InvalidEmail, errorcodes_InvalidName as InvalidName, errorcodes_InvalidPassword as InvalidPassword, errorcodes_InvalidPushToken as InvalidPushToken, errorcodes_UserNotFound as UserNotFound };
|
|
401
425
|
}
|
|
402
426
|
|
|
403
|
-
export { type CreateNotiRequestBody, type CreateSubscriptionRequestBody, type CreateUserRequestBody, Customer$1 as Customer, CustomerMetadata, CustomerMinified, CustomerNotiHubStats, DocumentNotFoundException, errorcodes as ErrorCode, type ICreateCustomerRequestBody, type ICreateNotiRequestBody, type INotiHubCustomer, type INotiHubCustomerMetadata, type INotiHubCustomerMinified, type INotiHubImage, type INotiHubNotification, type INotiHubNotificationStats, type INotiHubPaymentSession, type INotiHubStats, type INotiHubStatsHistory, type INotiHubStripeSubscription, type INotiHubSubscription, type INotiHubSubscriptionActivity, type INotiHubUser, type INotiHubUserView, type INotiType, type INotiTypeStats, type IUserSubscribeNotifier, type IUserSubscription, client as MongooseClient, NotiHubStatsHistory, type NotiHubTypes, NotiTypeModel, NotiTypeStatsModel, NotificationModel, NotificationStatsModel as NotificationStats, PaymentSessionModel, StripScriptionModel, Subscription, SubscriptionActivity, SubscriptionType, TABLES, UserModel, ViewsModel, addMonths, getDate, getDateFormat };
|
|
427
|
+
export { type CreateNotiRequestBody, type CreateSubscriptionRequestBody, type CreateUserRequestBody, Customer$1 as Customer, CustomerMetadata, CustomerMinified, CustomerNotiHubStats, DocumentNotFoundException, errorcodes as ErrorCode, type ICreateCustomerRequestBody, type ICreateNotiRequestBody, type INotiHubCustomer, type INotiHubCustomerMetadata, type INotiHubCustomerMinified, type INotiHubImage, type INotiHubNotification, type INotiHubNotificationStats, type INotiHubPaymentSession, type INotiHubStats, type INotiHubStatsHistory, type INotiHubStripeSubscription, type INotiHubSubscription, type INotiHubSubscriptionActivity, type INotiHubUser, type INotiHubUserView, type INotiType, type INotiTypeStats, type IUserSubscribeNotifier, type IUserSubscription, client as MongooseClient, NotiHubStatsHistory, type NotiHubTypes, NotiTypeModel, NotiTypeStatsModel, NotificationModel, NotificationStatsModel as NotificationStats, PaymentSessionModel, type Response, StripScriptionModel, Subscription, SubscriptionActivity, SubscriptionType, TABLES, UserModel, ViewsModel, addMonths, getDate, getDateFormat, handleError, handleSuccess };
|
package/dist/index.js
CHANGED
|
@@ -57,6 +57,41 @@ function addMonths({ date, months }) {
|
|
|
57
57
|
date.setMonth(date.getMonth() + months);
|
|
58
58
|
return date;
|
|
59
59
|
}
|
|
60
|
+
var handleError = (error, res, req) => {
|
|
61
|
+
console.error(`[${(/* @__PURE__ */ new Date()).toISOString()}] Error:`, {
|
|
62
|
+
message: error.message,
|
|
63
|
+
errorCode: error.errorCode,
|
|
64
|
+
stack: process.env.NODE_ENV !== "production" ? error.stack : void 0,
|
|
65
|
+
path: req?.path,
|
|
66
|
+
method: req?.method
|
|
67
|
+
});
|
|
68
|
+
let statusCode = 500;
|
|
69
|
+
let message = error.message || "Something went wrong";
|
|
70
|
+
if (error.errorCode === "UserNotFound" || error.message?.toLowerCase().includes("not found")) {
|
|
71
|
+
statusCode = 404;
|
|
72
|
+
} else if (error.message?.toLowerCase().includes("required") || error.message?.toLowerCase().includes("invalid")) {
|
|
73
|
+
statusCode = 400;
|
|
74
|
+
} else if (error.statusCode) {
|
|
75
|
+
statusCode = error.statusCode;
|
|
76
|
+
}
|
|
77
|
+
const response = {
|
|
78
|
+
success: false,
|
|
79
|
+
message,
|
|
80
|
+
error: error.errorCode || error.name,
|
|
81
|
+
statusCode,
|
|
82
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
83
|
+
};
|
|
84
|
+
res.status(statusCode).json(response);
|
|
85
|
+
};
|
|
86
|
+
var handleSuccess = (data, res, statusCode = 200) => {
|
|
87
|
+
const response = {
|
|
88
|
+
success: true,
|
|
89
|
+
data,
|
|
90
|
+
statusCode,
|
|
91
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
92
|
+
};
|
|
93
|
+
res.status(statusCode).json(response);
|
|
94
|
+
};
|
|
60
95
|
|
|
61
96
|
// src/models/UserModel.ts
|
|
62
97
|
import { Schema, model } from "mongoose";
|
|
@@ -475,17 +510,23 @@ var DocumentNotFoundException = class _DocumentNotFoundException extends Error {
|
|
|
475
510
|
// src/client/DynamoDBClient.ts
|
|
476
511
|
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
|
|
477
512
|
import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";
|
|
478
|
-
var
|
|
513
|
+
var isOffline = process.env.IS_OFFLINE === "true";
|
|
479
514
|
var ddbClient = new DynamoDBClient({
|
|
480
|
-
region:
|
|
481
|
-
|
|
482
|
-
|
|
515
|
+
region: "localhost",
|
|
516
|
+
endpoint: "http://localhost:8000",
|
|
517
|
+
credentials: {
|
|
518
|
+
accessKeyId: "DEFAULT_ACCESS_KEY",
|
|
519
|
+
// needed if you don't have aws credentials at all in env
|
|
520
|
+
secretAccessKey: "DEFAULT_SECRET"
|
|
521
|
+
// needed if you don't have aws credentials at all in env
|
|
522
|
+
}
|
|
483
523
|
});
|
|
484
524
|
var ddbDocClient = DynamoDBDocumentClient.from(ddbClient, {
|
|
485
525
|
marshallOptions: {
|
|
486
526
|
removeUndefinedValues: true
|
|
487
527
|
}
|
|
488
528
|
});
|
|
529
|
+
var USER_TABLE_NAME = process.env.USER_TABLE_NAME || "NotiHub-Users-v1-dev";
|
|
489
530
|
|
|
490
531
|
// src/DynamoModels/UserModel.ts
|
|
491
532
|
import {
|
|
@@ -527,11 +568,11 @@ var User = class _User {
|
|
|
527
568
|
static async getUserByEmail(email) {
|
|
528
569
|
const command = new QueryCommand({
|
|
529
570
|
TableName: _User.TABLE_NAME,
|
|
571
|
+
IndexName: "EmailIndex",
|
|
530
572
|
KeyConditionExpression: "email = :email",
|
|
531
573
|
ExpressionAttributeValues: {
|
|
532
574
|
":email": email
|
|
533
|
-
}
|
|
534
|
-
ConsistentRead: true
|
|
575
|
+
}
|
|
535
576
|
});
|
|
536
577
|
try {
|
|
537
578
|
const result = await ddbDocClient.send(command);
|
|
@@ -753,5 +794,7 @@ export {
|
|
|
753
794
|
ViewsModel_default as ViewsModel,
|
|
754
795
|
addMonths,
|
|
755
796
|
getDate,
|
|
756
|
-
getDateFormat
|
|
797
|
+
getDateFormat,
|
|
798
|
+
handleError,
|
|
799
|
+
handleSuccess
|
|
757
800
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amohamud23/notihub",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.152",
|
|
4
4
|
"description": "Notihub Package",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"types": "./dist/index.d.cts",
|
|
@@ -21,8 +21,10 @@
|
|
|
21
21
|
"author": "Abdi Mohamud",
|
|
22
22
|
"license": "ISC",
|
|
23
23
|
"devDependencies": {
|
|
24
|
+
"@types/express": "^5.0.3",
|
|
24
25
|
"@types/jest": "^29.5.14",
|
|
25
26
|
"@types/node": "^22.8.4",
|
|
27
|
+
"express": "^5.1.0",
|
|
26
28
|
"jest": "^29.7.0",
|
|
27
29
|
"ts-jest": "^29.3.4",
|
|
28
30
|
"typescript": "^5.8.3"
|