@konplit-services/common 1.0.188 → 1.0.190

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.
@@ -6,6 +6,7 @@ export interface OpayCashierCreatedEvent {
6
6
  merchantId: string;
7
7
  accountId: string;
8
8
  transactionType: TRANSACTION_CHARGES_TYPE;
9
+ transactionDate: Date;
9
10
  customer: {
10
11
  email: string;
11
12
  business_name: string;
@@ -44,3 +44,4 @@ export * from "./timestamp";
44
44
  export * from "./keys";
45
45
  export * from "./wallet-transaction.types";
46
46
  export * from "./generate-query-params";
47
+ export * from "./subscription-cron-expression";
@@ -60,3 +60,4 @@ __exportStar(require("./timestamp"), exports);
60
60
  __exportStar(require("./keys"), exports);
61
61
  __exportStar(require("./wallet-transaction.types"), exports);
62
62
  __exportStar(require("./generate-query-params"), exports);
63
+ __exportStar(require("./subscription-cron-expression"), exports);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const dayjs_1 = __importDefault(require("dayjs"));
7
+ const utc_1 = __importDefault(require("dayjs/plugin/utc"));
8
+ const plan_types_1 = require("./plan-types");
9
+ dayjs_1.default.extend(utc_1.default);
10
+ /**
11
+ * Generates a cron expression based on the current date and selected interval.
12
+ *
13
+ * @param {PLAN_INTERVAL} interval - The subscription interval.
14
+ * @returns {string} - The generated cron expression with seconds.
15
+ */
16
+ const generateCronExpression = (interval) => {
17
+ const currentDate = (0, dayjs_1.default)().utc(); // Get current date in UTC
18
+ let cronExpression = "";
19
+ switch (interval) {
20
+ case plan_types_1.PLAN_INTERVAL.HOURLY: {
21
+ // Run every hour at the same minute and second
22
+ cronExpression = `0 ${currentDate.minute()} ${currentDate.hour()} * * *`;
23
+ break;
24
+ }
25
+ case plan_types_1.PLAN_INTERVAL.DAILY: {
26
+ // Run at the same time every day
27
+ cronExpression = `0 ${currentDate.minute()} ${currentDate.hour()} * * *`;
28
+ break;
29
+ }
30
+ case plan_types_1.PLAN_INTERVAL.WEEKLY: {
31
+ // Run at the same time, same day of the week
32
+ cronExpression = `0 ${currentDate.minute()} ${currentDate.hour()} * * ${currentDate.day()}`;
33
+ break;
34
+ }
35
+ case plan_types_1.PLAN_INTERVAL.MONTHLY: {
36
+ const dayOfMonth = currentDate.date();
37
+ // If day > 28, fallback to the 28th
38
+ const adjustedDay = dayOfMonth > 28 ? 28 : dayOfMonth;
39
+ // Run at the same time on the same day every month
40
+ cronExpression = `0 ${currentDate.minute()} ${currentDate.hour()} ${adjustedDay} * *`;
41
+ break;
42
+ }
43
+ case plan_types_1.PLAN_INTERVAL.QUARTERLY: {
44
+ const dayOfMonth = currentDate.date();
45
+ // If day > 28, fallback to the 28th
46
+ const adjustedDay = dayOfMonth > 28 ? 28 : dayOfMonth;
47
+ // Every 3rd month
48
+ cronExpression = `0 ${currentDate.minute()} ${currentDate.hour()} ${adjustedDay} */3 *`;
49
+ break;
50
+ }
51
+ case plan_types_1.PLAN_INTERVAL["6MONTHS"]: {
52
+ const dayOfMonth = currentDate.date();
53
+ // If day > 28, fallback to the 28th
54
+ const adjustedDay = dayOfMonth > 28 ? 28 : dayOfMonth;
55
+ // Every 6th month
56
+ cronExpression = `0 ${currentDate.minute()} ${currentDate.hour()} ${adjustedDay} */6 *`;
57
+ break;
58
+ }
59
+ case plan_types_1.PLAN_INTERVAL.YEARLY: {
60
+ const dayOfMonth = currentDate.date();
61
+ // If day > 28, fallback to the 28th
62
+ const adjustedDay = dayOfMonth > 28 ? 28 : dayOfMonth;
63
+ // Run at the same time, same day, same month every year
64
+ cronExpression = `0 ${currentDate.minute()} ${currentDate.hour()} ${adjustedDay} ${currentDate.month() + 1} *`;
65
+ break;
66
+ }
67
+ default:
68
+ throw new Error("Invalid interval for generating cron expression");
69
+ }
70
+ return cronExpression;
71
+ };
@@ -32,10 +32,10 @@ const configureSwagger = (app, paths) => {
32
32
  url: "https://konplit.com",
33
33
  },
34
34
  {
35
- url: "http://konplit.com",
35
+ url: "https://www.konplit.com",
36
36
  },
37
37
  {
38
- url: "https://ad86418ffa127478d9826347c8a84e0a-1496452414.eu-west-2.elb.amazonaws.com",
38
+ url: "http://konplit.com",
39
39
  },
40
40
  ],
41
41
  components: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konplit-services/common",
3
- "version": "1.0.188",
3
+ "version": "1.0.190",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",