kcommons 18.26.3 → 18.26.5

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.
@@ -17,6 +17,7 @@ import { INestedEntityApprovalChainEntryLog } from "../../entityApprovalChainEnt
17
17
  import { INestedEntityApprovalChainStageNames } from "../../entityApprovalChainStageNames.typings";
18
18
  import { INestedSupplierInvoice } from "../../supplierInvoice.typings";
19
19
  import { ISupplierInvoice } from "../../supplierInvoice.typings";
20
+ import { INestedSupplierInvoiceItem } from "../../supplierInvoice.typings";
20
21
  export declare enum VES_REQUESTING_ENTITY_TYPE {
21
22
  STORE_LOCATION = "store_location",
22
23
  CHECKPOINT = "checkpoint"
@@ -160,7 +161,8 @@ export declare enum VES_METAFIELDS_INCLUDE {
160
161
  items_data = "items_data",
161
162
  vendor_quote_item_custom_uom_data = "vendor_quote_item_custom_uom_data",
162
163
  approval_logs = "approval_logs",
163
- approval_chain_stage_names = "approval_chain_stage_names"
164
+ approval_chain_stage_names = "approval_chain_stage_names",
165
+ supplier_invoice_items = "supplier_invoice_items"
164
166
  }
165
167
  export interface IVESMetafields {
166
168
  vendor: INestedVendor | null;
@@ -168,6 +170,7 @@ export interface IVESMetafields {
168
170
  vendor_quote_item_custom_uom_data: IVESVendorQuoteItemCustomUOM[] | null;
169
171
  approval_logs: INestedEntityApprovalChainEntryLog[] | null;
170
172
  approval_chain_stage_names: INestedEntityApprovalChainStageNames[] | null;
173
+ supplier_invoice_items: INestedSupplierInvoiceItem[] | null;
171
174
  }
172
175
  /**
173
176
  * @deprecated
@@ -77,4 +77,5 @@ var VES_METAFIELDS_INCLUDE;
77
77
  VES_METAFIELDS_INCLUDE["vendor_quote_item_custom_uom_data"] = "vendor_quote_item_custom_uom_data";
78
78
  VES_METAFIELDS_INCLUDE["approval_logs"] = "approval_logs";
79
79
  VES_METAFIELDS_INCLUDE["approval_chain_stage_names"] = "approval_chain_stage_names";
80
+ VES_METAFIELDS_INCLUDE["supplier_invoice_items"] = "supplier_invoice_items";
80
81
  })(VES_METAFIELDS_INCLUDE || (exports.VES_METAFIELDS_INCLUDE = VES_METAFIELDS_INCLUDE = {}));
@@ -19,6 +19,7 @@ export interface IReportsPluginConfigCompany {
19
19
  to_emails: string[];
20
20
  cc_emails: string[];
21
21
  bcc_emails: string[];
22
+ version: string;
22
23
  last_run_at: string | null;
23
24
  next_run_at: string | null;
24
25
  created_at: string;
@@ -5,4 +5,4 @@ export type IScheduleShape = Pick<IReportsPluginConfigCompany, "frequency_type"
5
5
  * `send_time` ("HH:mm"), `day_of_week` (0-6) and `date_of_month` (1-31) are in IST.
6
6
  * MONTHLY clamps `date_of_month` to the last day of shorter months.
7
7
  */
8
- export declare const calculateNextRunAt: (scheduleConfig: IScheduleShape, after: Date) => Date | null;
8
+ export declare const calculateNextRunAt: (scheduleConfig: IScheduleShape, after: Date) => Date;
@@ -45,7 +45,7 @@ const calculateNextRunAt = (scheduleConfig, after) => {
45
45
  : getMonthlyRunAt(istYear, istMonth + 1);
46
46
  }
47
47
  default:
48
- return null;
48
+ throw new Error(`Invalid value for frequency_type: ${scheduleConfig.frequency_type}`);
49
49
  }
50
50
  };
51
51
  exports.calculateNextRunAt = calculateNextRunAt;
@@ -0,0 +1,56 @@
1
+ /**
2
+ * A point in time accepted by {@link calculateTimeDifferenceInSeconds}.
3
+ *
4
+ * - `Date` — any valid `Date` object.
5
+ * - `string` — a 24-hour time of day in strict `HH:MM` format
6
+ * (e.g. `"09:05"`, `"23:59"`). Leading zeros are required and seconds
7
+ * are not supported.
8
+ */
9
+ type TimeInput = Date | string;
10
+ /**
11
+ * Calculates the difference in seconds between two times.
12
+ *
13
+ * The behaviour depends on the input types:
14
+ *
15
+ * - **Both `Date` objects** — the signed full date-time difference
16
+ * (`end - start`) is returned via `date-fns` `differenceInSeconds`, so
17
+ * differences across days are included and the result is negative if `end`
18
+ * is before `start`. Fractional seconds are truncated.
19
+ * - **Any `string` input (or a mix of `Date` and `string`)** — only the time
20
+ * of day is compared, and the **absolute** difference is returned. The
21
+ * calendar date of any `Date` is ignored, and its local
22
+ * hours/minutes/seconds are used.
23
+ *
24
+ * The time-of-day result is **not** wrapped around midnight: `"22:00"` →
25
+ * `"02:00"` gives `72000` (the gap between the two times of day), not the
26
+ * overnight duration `14400`. Handle overnight ranges at the call site if
27
+ * needed.
28
+ *
29
+ * @param start - The start time: a `Date` or an `HH:MM` (24-hour) string.
30
+ * @param end - The end time: a `Date` or an `HH:MM` (24-hour) string.
31
+ * @returns For two `Date`s, the signed number of seconds from `start` to
32
+ * `end`. Otherwise, the absolute number of seconds between the two times
33
+ * of day (never negative).
34
+ * @throws {Error} If a string input is not in `HH:MM` format, or a `Date`
35
+ * input is invalid (in the time-of-day comparison path).
36
+ *
37
+ * @example
38
+ * calculateTimeDifferenceInSeconds("09:00", "17:30"); // 30600
39
+ *
40
+ * @example
41
+ * // Order does not matter for time-of-day comparisons
42
+ * calculateTimeDifferenceInSeconds("18:00", "09:00"); // 32400
43
+ *
44
+ * @example
45
+ * // Both Dates: full date-time difference, across days
46
+ * calculateTimeDifferenceInSeconds(
47
+ * new Date("2024-01-01T23:00:00"),
48
+ * new Date("2024-01-02T01:00:00"),
49
+ * ); // 7200
50
+ *
51
+ * @example
52
+ * // Mixed: only the Date's time of day (10:15:30) is used
53
+ * calculateTimeDifferenceInSeconds(new Date("2024-01-01T10:15:30"), "11:00"); // 2670
54
+ */
55
+ export declare function calculateTimeDifferenceInSeconds(start: TimeInput, end: TimeInput): number;
56
+ export {};
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.calculateTimeDifferenceInSeconds = calculateTimeDifferenceInSeconds;
4
+ const date_fns_1 = require("date-fns");
5
+ /**
6
+ * Converts a time input into the number of seconds elapsed since midnight.
7
+ *
8
+ * For a `Date`, only its local time of day (hours, minutes, seconds) is used;
9
+ * the calendar date and milliseconds are ignored. For a string, the `HH:MM`
10
+ * value is parsed and seconds are taken as `0`.
11
+ *
12
+ * @param input - A valid `Date` or an `HH:MM` time string.
13
+ * @returns Seconds since midnight, in the range `0`–`86399`.
14
+ * @throws {Error} If `input` is an invalid `Date` (e.g. `new Date("foo")`).
15
+ * @throws {Error} If `input` is a string not matching `HH:MM` (24-hour).
16
+ */
17
+ function toSeconds(input) {
18
+ if (input instanceof Date) {
19
+ if (!(0, date_fns_1.isValid)(input)) {
20
+ throw new Error("Invalid Date object");
21
+ }
22
+ return (input.getHours() * 3600 + input.getMinutes() * 60 + input.getSeconds());
23
+ }
24
+ const match = /^([01]\d|2[0-3]):([0-5]\d)$/.exec(input);
25
+ if (!match) {
26
+ throw new Error(`Invalid time format: ${input}. Expected HH:MM`);
27
+ }
28
+ const hours = Number(match[1]);
29
+ const minutes = Number(match[2]);
30
+ return hours * 3600 + minutes * 60;
31
+ }
32
+ /**
33
+ * Calculates the difference in seconds between two times.
34
+ *
35
+ * The behaviour depends on the input types:
36
+ *
37
+ * - **Both `Date` objects** — the signed full date-time difference
38
+ * (`end - start`) is returned via `date-fns` `differenceInSeconds`, so
39
+ * differences across days are included and the result is negative if `end`
40
+ * is before `start`. Fractional seconds are truncated.
41
+ * - **Any `string` input (or a mix of `Date` and `string`)** — only the time
42
+ * of day is compared, and the **absolute** difference is returned. The
43
+ * calendar date of any `Date` is ignored, and its local
44
+ * hours/minutes/seconds are used.
45
+ *
46
+ * The time-of-day result is **not** wrapped around midnight: `"22:00"` →
47
+ * `"02:00"` gives `72000` (the gap between the two times of day), not the
48
+ * overnight duration `14400`. Handle overnight ranges at the call site if
49
+ * needed.
50
+ *
51
+ * @param start - The start time: a `Date` or an `HH:MM` (24-hour) string.
52
+ * @param end - The end time: a `Date` or an `HH:MM` (24-hour) string.
53
+ * @returns For two `Date`s, the signed number of seconds from `start` to
54
+ * `end`. Otherwise, the absolute number of seconds between the two times
55
+ * of day (never negative).
56
+ * @throws {Error} If a string input is not in `HH:MM` format, or a `Date`
57
+ * input is invalid (in the time-of-day comparison path).
58
+ *
59
+ * @example
60
+ * calculateTimeDifferenceInSeconds("09:00", "17:30"); // 30600
61
+ *
62
+ * @example
63
+ * // Order does not matter for time-of-day comparisons
64
+ * calculateTimeDifferenceInSeconds("18:00", "09:00"); // 32400
65
+ *
66
+ * @example
67
+ * // Both Dates: full date-time difference, across days
68
+ * calculateTimeDifferenceInSeconds(
69
+ * new Date("2024-01-01T23:00:00"),
70
+ * new Date("2024-01-02T01:00:00"),
71
+ * ); // 7200
72
+ *
73
+ * @example
74
+ * // Mixed: only the Date's time of day (10:15:30) is used
75
+ * calculateTimeDifferenceInSeconds(new Date("2024-01-01T10:15:30"), "11:00"); // 2670
76
+ */
77
+ function calculateTimeDifferenceInSeconds(start, end) {
78
+ if (start instanceof Date && end instanceof Date) {
79
+ return (0, date_fns_1.differenceInSeconds)(end, start);
80
+ }
81
+ return Math.abs(toSeconds(end) - toSeconds(start));
82
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kcommons",
3
- "version": "18.26.3",
3
+ "version": "18.26.5",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",