@konplit-services/common 1.25.8 → 1.26.1

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.
@@ -388,6 +388,7 @@ declare class AppConfigs {
388
388
  isStaging(): boolean;
389
389
  isProduction(): boolean;
390
390
  getDSN_Key(): DSN;
391
+ getComplianceEmail(): string;
391
392
  }
392
393
  declare const appConfigs: AppConfigs;
393
394
  export { appConfigs };
@@ -1024,6 +1024,12 @@ class AppConfigs {
1024
1024
  dsn: this.env.SENTRY_LOG_DNS,
1025
1025
  };
1026
1026
  }
1027
+ getComplianceEmail() {
1028
+ if (!this.env.COMPLIANCE_EMAIL) {
1029
+ throw new Error("COMPLIANCE_EMAIL is required");
1030
+ }
1031
+ return this.env.COMPLIANCE_EMAIL;
1032
+ }
1027
1033
  }
1028
1034
  // make sure all keys are available on startup
1029
1035
  const appConfigs = new AppConfigs(process.env);
@@ -0,0 +1,8 @@
1
+ import { ComplianceTransactionNotificationTemplateData } from "../../../../notification";
2
+ import { StreamEvent, StreamName, Subjects } from "../../../subjects";
3
+ export interface ComplianceTransactionNotificationEmailCreatedEvent {
4
+ subject: Subjects.ComplianceTransactionNotificationEmailCreated;
5
+ streamName: StreamName.name;
6
+ streamEvents: StreamEvent.Event;
7
+ data: ComplianceTransactionNotificationTemplateData;
8
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -19,3 +19,4 @@ export * from "./sub-payment-fail-notify.interface";
19
19
  export * from "./token-verification-notify.interface";
20
20
  export * from "./two2factor-auth-notify.interface";
21
21
  export * from "./merchant-settlement-notification.event";
22
+ export * from "./compliance-monitorying.interface";
@@ -35,3 +35,4 @@ __exportStar(require("./sub-payment-fail-notify.interface"), exports);
35
35
  __exportStar(require("./token-verification-notify.interface"), exports);
36
36
  __exportStar(require("./two2factor-auth-notify.interface"), exports);
37
37
  __exportStar(require("./merchant-settlement-notification.event"), exports);
38
+ __exportStar(require("./compliance-monitorying.interface"), exports);
@@ -49,6 +49,7 @@ export declare enum Subjects {
49
49
  TokenVerificationNotificationEmailCreated = "events.token.verification.notification",
50
50
  MerchantUserInviteNotificationEmailCreated = "events.merchant.user.invite.notification",
51
51
  CustomerWelcomeNotificationEmailCreated = "events.customer.welcome.notification",
52
+ ComplianceTransactionNotificationEmailCreated = "events.compliance.transaction.notification",
52
53
  UserRoleUpdated = "events.user.role.updated",
53
54
  AdminLogCreated = "events.admin.log.created",
54
55
  WalletCreated = "events.wallet.created",
@@ -63,6 +63,7 @@ var Subjects;
63
63
  Subjects["TokenVerificationNotificationEmailCreated"] = "events.token.verification.notification";
64
64
  Subjects["MerchantUserInviteNotificationEmailCreated"] = "events.merchant.user.invite.notification";
65
65
  Subjects["CustomerWelcomeNotificationEmailCreated"] = "events.customer.welcome.notification";
66
+ Subjects["ComplianceTransactionNotificationEmailCreated"] = "events.compliance.transaction.notification";
66
67
  // Roles
67
68
  Subjects["UserRoleUpdated"] = "events.user.role.updated";
68
69
  Subjects["AdminLogCreated"] = "events.admin.log.created";
@@ -1,4 +1,10 @@
1
+ import dayjs from "dayjs";
1
2
  import { PLAN_INTERVAL } from "./plan-types";
3
+ type Period = "day" | "week" | "month" | "year";
4
+ interface DateRange {
5
+ startOfPeriod: Date;
6
+ endOfPeriod: Date;
7
+ }
2
8
  export declare const formatDate: (dateInput: string | Date | number, // support more input types
3
9
  format?: string, tz?: string) => string;
4
10
  export declare const interswitchRefundDateFormat: (dataString: string) => string;
@@ -12,10 +18,15 @@ export declare const getCurrentDayRange: () => {
12
18
  startOfCurrentDay: Date;
13
19
  endOfCurrentDay: Date;
14
20
  };
15
- export declare const getStartAndEndDate: (date: string | Date) => {
16
- startOfDate: Date;
17
- endOfDate: Date;
18
- };
21
+ /**
22
+ * Returns the start and end of a given period for the provided date
23
+ *
24
+ * @param date - Input date (string, Date, or dayjs object)
25
+ * @param period - The time period to calculate range for ("day" | "week" | "month" | "year")
26
+ * @param timezone - Optional timezone (defaults to Africa/Lagos)
27
+ * @returns Object containing startOfPeriod and endOfPeriod as native Date objects (in UTC)
28
+ */
29
+ export declare const getStartAndEndOfPeriod: (date: string | Date | dayjs.Dayjs, period?: Period, tz?: string) => DateRange;
19
30
  export declare const isTodayOrFuture: (dateInput: string | Date) => boolean;
20
31
  export declare const convertDateToUTCRangeString: (startDateTime: string, endDateTime: string) => {
21
32
  startUTC: string;
@@ -3,18 +3,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.calculateDelay = exports.getFutureDateFromPlan = exports.getDuration = exports.convertDateToUTC = exports.convertDateToUTCString = exports.convertDateToUTCRange = exports.convertDateToUTCRangeString = exports.isTodayOrFuture = exports.getStartAndEndDate = exports.getCurrentDayRange = exports.getPreviousDayRange = exports.convertToDate = exports.formatDateTime = exports.interswitchRefundDateFormat = exports.formatDate = void 0;
6
+ exports.calculateDelay = exports.getFutureDateFromPlan = exports.getDuration = exports.convertDateToUTC = exports.convertDateToUTCString = exports.convertDateToUTCRange = exports.convertDateToUTCRangeString = exports.isTodayOrFuture = exports.getStartAndEndOfPeriod = exports.getCurrentDayRange = exports.getPreviousDayRange = exports.convertToDate = exports.formatDateTime = exports.interswitchRefundDateFormat = exports.formatDate = void 0;
7
7
  exports.canRefundFromSettlementLedgerByDay = canRefundFromSettlementLedgerByDay;
8
8
  exports.getSettlementDate = getSettlementDate;
9
9
  const dayjs_1 = __importDefault(require("dayjs"));
10
10
  const utc_1 = __importDefault(require("dayjs/plugin/utc"));
11
11
  const timezone_1 = __importDefault(require("dayjs/plugin/timezone"));
12
+ const plan_types_1 = require("./plan-types");
12
13
  // Extend dayjs with the UTC plugin
13
14
  dayjs_1.default.extend(utc_1.default);
14
15
  dayjs_1.default.extend(timezone_1.default);
15
16
  const DEFAULT_TZ = "Africa/Lagos";
16
17
  const DEFAULT_FORMAT = "YYYY-MM-DD";
17
- const plan_types_1 = require("./plan-types");
18
18
  const formatDate = (dateInput, // support more input types
19
19
  format = DEFAULT_FORMAT, tz = DEFAULT_TZ) => {
20
20
  if (!dateInput) {
@@ -59,15 +59,49 @@ const getCurrentDayRange = () => {
59
59
  return { startOfCurrentDay, endOfCurrentDay };
60
60
  };
61
61
  exports.getCurrentDayRange = getCurrentDayRange;
62
- const getStartAndEndDate = (date) => {
63
- const startTime = (0, dayjs_1.default)(`${date}`, "YYYY-MM-DD HH:mm");
64
- // Get the start of day
65
- const startOfDate = startTime.utc().startOf("day").toDate();
66
- // Get the end of the previous day in UTC (23:59:59.999)
67
- const endOfDate = startTime.utc().endOf("day").toDate();
68
- return { startOfDate, endOfDate };
62
+ /**
63
+ * Returns the start and end of a given period for the provided date
64
+ *
65
+ * @param date - Input date (string, Date, or dayjs object)
66
+ * @param period - The time period to calculate range for ("day" | "week" | "month" | "year")
67
+ * @param timezone - Optional timezone (defaults to Africa/Lagos)
68
+ * @returns Object containing startOfPeriod and endOfPeriod as native Date objects (in UTC)
69
+ */
70
+ const getStartAndEndOfPeriod = (date, period = "day", tz = DEFAULT_TZ) => {
71
+ // Normalize input to dayjs object in the target timezone
72
+ const inputDate = (0, dayjs_1.default)(date).tz(tz);
73
+ let start;
74
+ let end;
75
+ switch (period) {
76
+ case "day":
77
+ start = inputDate.startOf("day");
78
+ end = inputDate.endOf("day");
79
+ break;
80
+ case "week":
81
+ // Most common: week starts on Monday in many African/business contexts
82
+ // but we are using Sunday start → but can be changed to isoWeek
83
+ start = inputDate.startOf("week");
84
+ end = inputDate.endOf("week");
85
+ break;
86
+ case "month":
87
+ start = inputDate.startOf("month");
88
+ end = inputDate.endOf("month");
89
+ break;
90
+ case "year":
91
+ start = inputDate.startOf("year");
92
+ end = inputDate.endOf("year");
93
+ break;
94
+ default:
95
+ // This should never happen with TypeScript + union type, but good safety net
96
+ throw new Error(`Unsupported period: ${period}`);
97
+ }
98
+ // Return as UTC Dates (most backend systems & databases expect UTC)
99
+ return {
100
+ startOfPeriod: start.utc().toDate(),
101
+ endOfPeriod: end.utc().toDate(),
102
+ };
69
103
  };
70
- exports.getStartAndEndDate = getStartAndEndDate;
104
+ exports.getStartAndEndOfPeriod = getStartAndEndOfPeriod;
71
105
  const isTodayOrFuture = (dateInput) => {
72
106
  const input = dayjs_1.default.utc(dateInput);
73
107
  if (!input.isValid())
@@ -1,4 +1,4 @@
1
- import { Usage } from "../helper";
1
+ import { PaymentOptions, Usage } from "../helper";
2
2
  export interface EmailBase {
3
3
  merchant_id?: string;
4
4
  business_logo?: string;
@@ -193,3 +193,16 @@ export interface CustomerWelcomeTemplateData extends EmailBase {
193
193
  login_url: string;
194
194
  to: string;
195
195
  }
196
+ export interface ComplianceTransactionNotificationTemplateData extends EmailBase {
197
+ customer_name: string;
198
+ customer_email: string;
199
+ merchant_name: string;
200
+ merchant_email: string;
201
+ amount: number;
202
+ reference: string;
203
+ providerId: string;
204
+ transaction_date: string;
205
+ completed_date?: string;
206
+ payment_method: PaymentOptions;
207
+ [key: string]: any;
208
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konplit-services/common",
3
- "version": "1.25.8",
3
+ "version": "1.26.1",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",