@amohamud23/notihub 1.1.64 → 1.1.66

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
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/index.ts
@@ -22,6 +32,7 @@ var index_exports = {};
22
32
  __export(index_exports, {
23
33
  DocumentNotFoundException: () => DocumentNotFoundException,
24
34
  ErrorCode: () => errorcodes_exports,
35
+ Logger: () => Logger,
25
36
  ParameterStoreClient: () => ParameterStoreClient_default,
26
37
  TABLES: () => TABLES,
27
38
  addMonths: () => addMonths,
@@ -461,21 +472,13 @@ var Notifications = class _Notifications {
461
472
  * @returns A promise that resolves to the notification object or null if not found.
462
473
  */
463
474
  static async getNotificationById(id) {
464
- const params = {
475
+ const command = new import_lib_dynamodb4.GetCommand({
465
476
  TableName: _Notifications.TABLE_NAME,
466
- IndexName: "NotificationIdIndex",
467
- KeyConditionExpression: "id = :id",
468
- ExpressionAttributeValues: {
469
- ":id": id
470
- }
471
- };
472
- const command = new import_lib_dynamodb4.QueryCommand(params);
477
+ Key: { id }
478
+ });
473
479
  try {
474
480
  const response = await ddbDocClient.send(command);
475
- if (!response.Items || response.Items.length === 0) {
476
- return null;
477
- }
478
- return response.Items[0] ?? null;
481
+ return response.Item || null;
479
482
  } catch (error) {
480
483
  console.error("Error fetching notification:", error);
481
484
  throw new Error("Could not fetch notification");
@@ -2046,6 +2049,108 @@ var ParameterStore = class {
2046
2049
  };
2047
2050
  var ParameterStoreClient_default = new ParameterStore();
2048
2051
 
2052
+ // src/logger.ts
2053
+ var import_pino = __toESM(require("pino"), 1);
2054
+ var Logger = class _Logger {
2055
+ logger;
2056
+ static instance;
2057
+ constructor() {
2058
+ this.logger = (0, import_pino.default)({
2059
+ level: process.env.LOG_LEVEL || "info",
2060
+ transport: process.env.ENV !== "production" ? {
2061
+ target: "pino-pretty",
2062
+ options: {
2063
+ colorize: true,
2064
+ translateTime: "SYS:standard",
2065
+ ignore: "pid,hostname"
2066
+ }
2067
+ } : void 0
2068
+ });
2069
+ }
2070
+ /**
2071
+ * Get singleton instance of Logger
2072
+ */
2073
+ static getInstance() {
2074
+ if (!_Logger.instance) {
2075
+ _Logger.instance = new _Logger();
2076
+ }
2077
+ return _Logger.instance;
2078
+ }
2079
+ /**
2080
+ * Log informational message
2081
+ */
2082
+ info(message, data) {
2083
+ if (data) {
2084
+ this.logger.info(data, message);
2085
+ } else {
2086
+ this.logger.info(message);
2087
+ }
2088
+ }
2089
+ /**
2090
+ * Log error message
2091
+ */
2092
+ error(message, error) {
2093
+ if (error instanceof Error) {
2094
+ this.logger.error({ err: error }, message);
2095
+ } else if (error) {
2096
+ this.logger.error(error, message);
2097
+ } else {
2098
+ this.logger.error(message);
2099
+ }
2100
+ }
2101
+ /**
2102
+ * Log warning message
2103
+ */
2104
+ warn(message, data) {
2105
+ if (data) {
2106
+ this.logger.warn(data, message);
2107
+ } else {
2108
+ this.logger.warn(message);
2109
+ }
2110
+ }
2111
+ /**
2112
+ * Log debug message
2113
+ */
2114
+ debug(message, data) {
2115
+ if (data) {
2116
+ this.logger.debug(data, message);
2117
+ } else {
2118
+ this.logger.debug(message);
2119
+ }
2120
+ }
2121
+ /**
2122
+ * Log trace message
2123
+ */
2124
+ trace(message, data) {
2125
+ if (data) {
2126
+ this.logger.trace(data, message);
2127
+ } else {
2128
+ this.logger.trace(message);
2129
+ }
2130
+ }
2131
+ /**
2132
+ * Log fatal message
2133
+ */
2134
+ fatal(message, error) {
2135
+ if (error instanceof Error) {
2136
+ this.logger.fatal({ err: error }, message);
2137
+ } else if (error) {
2138
+ this.logger.fatal(error, message);
2139
+ } else {
2140
+ this.logger.fatal(message);
2141
+ }
2142
+ }
2143
+ /**
2144
+ * Create a child logger with additional context
2145
+ */
2146
+ child(bindings) {
2147
+ const childLogger = new _Logger();
2148
+ childLogger.logger = this.logger.child(bindings);
2149
+ return childLogger;
2150
+ }
2151
+ };
2152
+ var logger_default = Logger.getInstance();
2153
+
2049
2154
  // src/errorcodes.ts
2050
2155
  var errorcodes_exports = {};
2051
2156
  __export(errorcodes_exports, {
@@ -2072,6 +2177,7 @@ var InvalidDate = "4011";
2072
2177
  0 && (module.exports = {
2073
2178
  DocumentNotFoundException,
2074
2179
  ErrorCode,
2180
+ Logger,
2075
2181
  ParameterStoreClient,
2076
2182
  TABLES,
2077
2183
  addMonths,
package/dist/index.d.cts CHANGED
@@ -802,6 +802,47 @@ declare class ParameterStore {
802
802
  }
803
803
  declare const _default: ParameterStore;
804
804
 
805
+ /**
806
+ * Reusable Logger class using Pino for structured logging
807
+ */
808
+ declare class Logger {
809
+ private logger;
810
+ private static instance;
811
+ private constructor();
812
+ /**
813
+ * Get singleton instance of Logger
814
+ */
815
+ static getInstance(): Logger;
816
+ /**
817
+ * Log informational message
818
+ */
819
+ info(message: string, data?: Record<string, any>): void;
820
+ /**
821
+ * Log error message
822
+ */
823
+ error(message: string, error?: Error | Record<string, any>): void;
824
+ /**
825
+ * Log warning message
826
+ */
827
+ warn(message: string, data?: Record<string, any>): void;
828
+ /**
829
+ * Log debug message
830
+ */
831
+ debug(message: string, data?: Record<string, any>): void;
832
+ /**
833
+ * Log trace message
834
+ */
835
+ trace(message: string, data?: Record<string, any>): void;
836
+ /**
837
+ * Log fatal message
838
+ */
839
+ fatal(message: string, error?: Error | Record<string, any>): void;
840
+ /**
841
+ * Create a child logger with additional context
842
+ */
843
+ child(bindings: Record<string, any>): Logger;
844
+ }
845
+
805
846
  declare const DocumentNotFound = "4001";
806
847
  declare const UserNotFound = "4002";
807
848
  declare const CustomerNotFound = "4003";
@@ -825,4 +866,4 @@ declare namespace errorcodes {
825
866
  export { errorcodes_CustomerNotFound as CustomerNotFound, errorcodes_DocumentNotFound as DocumentNotFound, errorcodes_InvalidDate as InvalidDate, errorcodes_InvalidEmail as InvalidEmail, errorcodes_InvalidName as InvalidName, errorcodes_InvalidPassword as InvalidPassword, errorcodes_InvalidPhoneNumber as InvalidPhoneNumber, errorcodes_InvalidPushToken as InvalidPushToken, errorcodes_UserNotFound as UserNotFound };
826
867
  }
827
868
 
828
- export { type CreateNotiRequestBody, type CreateSubscriptionRequestBody, type CreateUserRequestBody, type DBMetaData, 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, type NotiHubTypes, _default as ParameterStoreClient, type Response, TABLES, addMonths, formatResponse, getDate, getDateFormat, handleError, handleSuccess };
869
+ export { type CreateNotiRequestBody, type CreateSubscriptionRequestBody, type CreateUserRequestBody, type DBMetaData, 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, Logger, type NotiHubTypes, _default as ParameterStoreClient, type Response, TABLES, addMonths, formatResponse, getDate, getDateFormat, handleError, handleSuccess };
package/dist/index.d.ts CHANGED
@@ -802,6 +802,47 @@ declare class ParameterStore {
802
802
  }
803
803
  declare const _default: ParameterStore;
804
804
 
805
+ /**
806
+ * Reusable Logger class using Pino for structured logging
807
+ */
808
+ declare class Logger {
809
+ private logger;
810
+ private static instance;
811
+ private constructor();
812
+ /**
813
+ * Get singleton instance of Logger
814
+ */
815
+ static getInstance(): Logger;
816
+ /**
817
+ * Log informational message
818
+ */
819
+ info(message: string, data?: Record<string, any>): void;
820
+ /**
821
+ * Log error message
822
+ */
823
+ error(message: string, error?: Error | Record<string, any>): void;
824
+ /**
825
+ * Log warning message
826
+ */
827
+ warn(message: string, data?: Record<string, any>): void;
828
+ /**
829
+ * Log debug message
830
+ */
831
+ debug(message: string, data?: Record<string, any>): void;
832
+ /**
833
+ * Log trace message
834
+ */
835
+ trace(message: string, data?: Record<string, any>): void;
836
+ /**
837
+ * Log fatal message
838
+ */
839
+ fatal(message: string, error?: Error | Record<string, any>): void;
840
+ /**
841
+ * Create a child logger with additional context
842
+ */
843
+ child(bindings: Record<string, any>): Logger;
844
+ }
845
+
805
846
  declare const DocumentNotFound = "4001";
806
847
  declare const UserNotFound = "4002";
807
848
  declare const CustomerNotFound = "4003";
@@ -825,4 +866,4 @@ declare namespace errorcodes {
825
866
  export { errorcodes_CustomerNotFound as CustomerNotFound, errorcodes_DocumentNotFound as DocumentNotFound, errorcodes_InvalidDate as InvalidDate, errorcodes_InvalidEmail as InvalidEmail, errorcodes_InvalidName as InvalidName, errorcodes_InvalidPassword as InvalidPassword, errorcodes_InvalidPhoneNumber as InvalidPhoneNumber, errorcodes_InvalidPushToken as InvalidPushToken, errorcodes_UserNotFound as UserNotFound };
826
867
  }
827
868
 
828
- export { type CreateNotiRequestBody, type CreateSubscriptionRequestBody, type CreateUserRequestBody, type DBMetaData, 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, type NotiHubTypes, _default as ParameterStoreClient, type Response, TABLES, addMonths, formatResponse, getDate, getDateFormat, handleError, handleSuccess };
869
+ export { type CreateNotiRequestBody, type CreateSubscriptionRequestBody, type CreateUserRequestBody, type DBMetaData, 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, Logger, type NotiHubTypes, _default as ParameterStoreClient, type Response, TABLES, addMonths, formatResponse, getDate, getDateFormat, handleError, handleSuccess };
package/dist/index.js CHANGED
@@ -437,6 +437,7 @@ var Customer_default = Customer;
437
437
  // src/DynamoModels/Notifications.ts
438
438
  import {
439
439
  DeleteCommand as DeleteCommand3,
440
+ GetCommand as GetCommand3,
440
441
  PutCommand as PutCommand3,
441
442
  QueryCommand as QueryCommand3
442
443
  } from "@aws-sdk/lib-dynamodb";
@@ -449,21 +450,13 @@ var Notifications = class _Notifications {
449
450
  * @returns A promise that resolves to the notification object or null if not found.
450
451
  */
451
452
  static async getNotificationById(id) {
452
- const params = {
453
+ const command = new GetCommand3({
453
454
  TableName: _Notifications.TABLE_NAME,
454
- IndexName: "NotificationIdIndex",
455
- KeyConditionExpression: "id = :id",
456
- ExpressionAttributeValues: {
457
- ":id": id
458
- }
459
- };
460
- const command = new QueryCommand3(params);
455
+ Key: { id }
456
+ });
461
457
  try {
462
458
  const response = await ddbDocClient.send(command);
463
- if (!response.Items || response.Items.length === 0) {
464
- return null;
465
- }
466
- return response.Items[0] ?? null;
459
+ return response.Item || null;
467
460
  } catch (error) {
468
461
  console.error("Error fetching notification:", error);
469
462
  throw new Error("Could not fetch notification");
@@ -2091,6 +2084,108 @@ var ParameterStore = class {
2091
2084
  };
2092
2085
  var ParameterStoreClient_default = new ParameterStore();
2093
2086
 
2087
+ // src/logger.ts
2088
+ import pino from "pino";
2089
+ var Logger = class _Logger {
2090
+ logger;
2091
+ static instance;
2092
+ constructor() {
2093
+ this.logger = pino({
2094
+ level: process.env.LOG_LEVEL || "info",
2095
+ transport: process.env.ENV !== "production" ? {
2096
+ target: "pino-pretty",
2097
+ options: {
2098
+ colorize: true,
2099
+ translateTime: "SYS:standard",
2100
+ ignore: "pid,hostname"
2101
+ }
2102
+ } : void 0
2103
+ });
2104
+ }
2105
+ /**
2106
+ * Get singleton instance of Logger
2107
+ */
2108
+ static getInstance() {
2109
+ if (!_Logger.instance) {
2110
+ _Logger.instance = new _Logger();
2111
+ }
2112
+ return _Logger.instance;
2113
+ }
2114
+ /**
2115
+ * Log informational message
2116
+ */
2117
+ info(message, data) {
2118
+ if (data) {
2119
+ this.logger.info(data, message);
2120
+ } else {
2121
+ this.logger.info(message);
2122
+ }
2123
+ }
2124
+ /**
2125
+ * Log error message
2126
+ */
2127
+ error(message, error) {
2128
+ if (error instanceof Error) {
2129
+ this.logger.error({ err: error }, message);
2130
+ } else if (error) {
2131
+ this.logger.error(error, message);
2132
+ } else {
2133
+ this.logger.error(message);
2134
+ }
2135
+ }
2136
+ /**
2137
+ * Log warning message
2138
+ */
2139
+ warn(message, data) {
2140
+ if (data) {
2141
+ this.logger.warn(data, message);
2142
+ } else {
2143
+ this.logger.warn(message);
2144
+ }
2145
+ }
2146
+ /**
2147
+ * Log debug message
2148
+ */
2149
+ debug(message, data) {
2150
+ if (data) {
2151
+ this.logger.debug(data, message);
2152
+ } else {
2153
+ this.logger.debug(message);
2154
+ }
2155
+ }
2156
+ /**
2157
+ * Log trace message
2158
+ */
2159
+ trace(message, data) {
2160
+ if (data) {
2161
+ this.logger.trace(data, message);
2162
+ } else {
2163
+ this.logger.trace(message);
2164
+ }
2165
+ }
2166
+ /**
2167
+ * Log fatal message
2168
+ */
2169
+ fatal(message, error) {
2170
+ if (error instanceof Error) {
2171
+ this.logger.fatal({ err: error }, message);
2172
+ } else if (error) {
2173
+ this.logger.fatal(error, message);
2174
+ } else {
2175
+ this.logger.fatal(message);
2176
+ }
2177
+ }
2178
+ /**
2179
+ * Create a child logger with additional context
2180
+ */
2181
+ child(bindings) {
2182
+ const childLogger = new _Logger();
2183
+ childLogger.logger = this.logger.child(bindings);
2184
+ return childLogger;
2185
+ }
2186
+ };
2187
+ var logger_default = Logger.getInstance();
2188
+
2094
2189
  // src/errorcodes.ts
2095
2190
  var errorcodes_exports = {};
2096
2191
  __export(errorcodes_exports, {
@@ -2116,6 +2211,7 @@ var InvalidDate = "4011";
2116
2211
  export {
2117
2212
  DocumentNotFoundException,
2118
2213
  errorcodes_exports as ErrorCode,
2214
+ Logger,
2119
2215
  ParameterStoreClient_default as ParameterStoreClient,
2120
2216
  TABLES,
2121
2217
  addMonths,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amohamud23/notihub",
3
- "version": "1.1.64",
3
+ "version": "1.1.66",
4
4
  "description": "Notihub Package",
5
5
  "main": "./dist/index.cjs",
6
6
  "types": "./dist/index.d.cts",
@@ -36,6 +36,7 @@
36
36
  "@aws-sdk/lib-dynamodb": "^3.821.0",
37
37
  "aws-sdk-client-mock": "^4.1.0",
38
38
  "date-fns": "^4.1.0",
39
+ "pino": "^10.1.0",
39
40
  "ts-node": "^10.9.2",
40
41
  "uuid": "^11.0.2"
41
42
  }