@litusarchieve18/agricore-utils 1.0.30 → 1.0.32
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/README.md +4 -0
- package/dist/{chunk-Y5KVDVNY.mjs → chunk-U332M2N6.mjs} +83 -6
- package/dist/{constants-CrAPx_xU.d.mts → constants-x8gYRJIw.d.mts} +154 -6
- package/dist/{constants-CrAPx_xU.d.ts → constants-x8gYRJIw.d.ts} +154 -6
- package/dist/constants.d.mts +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +88 -6
- package/dist/constants.mjs +13 -3
- package/dist/index.d.mts +49 -3
- package/dist/index.d.ts +49 -3
- package/dist/index.js +267 -14
- package/dist/index.mjs +186 -11
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -35,16 +35,21 @@ import {
|
|
|
35
35
|
NettingType,
|
|
36
36
|
NotificationMode,
|
|
37
37
|
OrderStatus,
|
|
38
|
+
PO_STATUSES,
|
|
39
|
+
PREFLIGHT_CHECK_STATUSES,
|
|
40
|
+
PRODUCT_TYPE_TO_BUDGET_CATEGORY,
|
|
38
41
|
PhysicalState,
|
|
39
42
|
PlantingMethod,
|
|
40
43
|
ProductType,
|
|
41
44
|
ProductUnit,
|
|
45
|
+
REQUISITION_STATUSES,
|
|
42
46
|
RESOURCE_MODULE_MAP,
|
|
43
47
|
RESOURCE_PATHS,
|
|
44
48
|
RESOURCE_REQUIREMENTS,
|
|
45
49
|
ROLE_SECTIONS_BY_KEY,
|
|
46
50
|
RelationshipType,
|
|
47
51
|
RowOrientation,
|
|
52
|
+
SCOPE_LEVELS,
|
|
48
53
|
SENTINEL_UUID,
|
|
49
54
|
SESSION_SCHEMA,
|
|
50
55
|
SIGNATURE_MODES,
|
|
@@ -52,7 +57,7 @@ import {
|
|
|
52
57
|
StockPolicyTier,
|
|
53
58
|
StoragePhases,
|
|
54
59
|
TASK_TYPE_REGISTRY,
|
|
55
|
-
|
|
60
|
+
TERM_RESOLUTION_MODES,
|
|
56
61
|
TargetEntityType,
|
|
57
62
|
TaskStatus,
|
|
58
63
|
TaskType,
|
|
@@ -62,7 +67,7 @@ import {
|
|
|
62
67
|
UserRole,
|
|
63
68
|
VigorRating,
|
|
64
69
|
WaterSource
|
|
65
|
-
} from "./chunk-
|
|
70
|
+
} from "./chunk-U332M2N6.mjs";
|
|
66
71
|
|
|
67
72
|
// src/index.ts
|
|
68
73
|
import { jwtVerify } from "jose";
|
|
@@ -410,6 +415,165 @@ async function findOverlappingPriceWindows(db, scope, newRow, excludeId) {
|
|
|
410
415
|
}));
|
|
411
416
|
}
|
|
412
417
|
|
|
418
|
+
// src/paymentDueDateHelpers.ts
|
|
419
|
+
function toUtcMidnight(date) {
|
|
420
|
+
return new Date(
|
|
421
|
+
Date.UTC(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate())
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
function addDaysUtc(date, days) {
|
|
425
|
+
const result = new Date(date);
|
|
426
|
+
result.setUTCDate(result.getUTCDate() + days);
|
|
427
|
+
return result;
|
|
428
|
+
}
|
|
429
|
+
function lastDayOfNextMonthUtc(date) {
|
|
430
|
+
return new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth() + 2, 0));
|
|
431
|
+
}
|
|
432
|
+
function nthDayOfNextMonthUtc(date, day) {
|
|
433
|
+
return new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth() + 1, day));
|
|
434
|
+
}
|
|
435
|
+
function lastDayOfMonthUtc(date) {
|
|
436
|
+
return new Date(Date.UTC(date.getUTCFullYear(), date.getUTCMonth() + 1, 0));
|
|
437
|
+
}
|
|
438
|
+
function calculateSupplierTradeCreditDueDate(transactionDate, window) {
|
|
439
|
+
if (!window) {
|
|
440
|
+
throw new Error(
|
|
441
|
+
"creditDaysWindow is required when paymentTerm is 'supplierTradeCredit'"
|
|
442
|
+
);
|
|
443
|
+
}
|
|
444
|
+
switch (window.type) {
|
|
445
|
+
case "NET":
|
|
446
|
+
if (!Number.isInteger(window.days) || window.days < 0) {
|
|
447
|
+
throw new Error(`Invalid NET days: ${window.days}`);
|
|
448
|
+
}
|
|
449
|
+
return addDaysUtc(transactionDate, window.days);
|
|
450
|
+
case "EOM":
|
|
451
|
+
if (window.days === void 0) {
|
|
452
|
+
return lastDayOfNextMonthUtc(transactionDate);
|
|
453
|
+
}
|
|
454
|
+
if (!Number.isInteger(window.days) || window.days < 1 || window.days > 31) {
|
|
455
|
+
throw new Error(`Invalid EOM day-of-month: ${window.days}`);
|
|
456
|
+
}
|
|
457
|
+
return nthDayOfNextMonthUtc(transactionDate, window.days);
|
|
458
|
+
default: {
|
|
459
|
+
const exhaustiveCheck = window;
|
|
460
|
+
throw new Error(`Unknown creditDaysWindow type: ${JSON.stringify(exhaustiveCheck)}`);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
function calculateForwardOrderingContractDueDate(transactionDate, window) {
|
|
465
|
+
if (!window) {
|
|
466
|
+
throw new Error(
|
|
467
|
+
"forwardOrderingContractWindow is required when paymentTerm is 'forwardOrderingContract'"
|
|
468
|
+
);
|
|
469
|
+
}
|
|
470
|
+
switch (window.frequencyType) {
|
|
471
|
+
case "FIXED_DATE":
|
|
472
|
+
return toUtcMidnight(window.dueDate);
|
|
473
|
+
case "FIXED_DAY": {
|
|
474
|
+
if (!Number.isInteger(window.dayOfMonth) || window.dayOfMonth < 1 || window.dayOfMonth > 31) {
|
|
475
|
+
throw new Error(`Invalid dayOfMonth: ${window.dayOfMonth}`);
|
|
476
|
+
}
|
|
477
|
+
const trigger = window.triggerDate ? toUtcMidnight(window.triggerDate) : transactionDate;
|
|
478
|
+
const candidateThisMonth = new Date(
|
|
479
|
+
Date.UTC(trigger.getUTCFullYear(), trigger.getUTCMonth(), window.dayOfMonth)
|
|
480
|
+
);
|
|
481
|
+
if (trigger.getUTCDate() <= window.dayOfMonth) {
|
|
482
|
+
return candidateThisMonth;
|
|
483
|
+
}
|
|
484
|
+
return new Date(
|
|
485
|
+
Date.UTC(trigger.getUTCFullYear(), trigger.getUTCMonth() + 1, window.dayOfMonth)
|
|
486
|
+
);
|
|
487
|
+
}
|
|
488
|
+
case "END_OF_MONTH": {
|
|
489
|
+
const trigger = window.triggerDate ? toUtcMidnight(window.triggerDate) : transactionDate;
|
|
490
|
+
const eom = lastDayOfMonthUtc(trigger);
|
|
491
|
+
return window.offsetDays ? addDaysUtc(eom, window.offsetDays) : eom;
|
|
492
|
+
}
|
|
493
|
+
case "DELIVERY_BASED": {
|
|
494
|
+
if (!window.triggerDate) {
|
|
495
|
+
throw new Error("triggerDate is required for DELIVERY_BASED forward ordering contracts");
|
|
496
|
+
}
|
|
497
|
+
const trigger = toUtcMidnight(window.triggerDate);
|
|
498
|
+
return addDaysUtc(trigger, window.offsetDays);
|
|
499
|
+
}
|
|
500
|
+
default: {
|
|
501
|
+
const exhaustiveCheck = window;
|
|
502
|
+
throw new Error(`Unknown frequencyType: ${JSON.stringify(exhaustiveCheck)}`);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
function calculateInstallmentSchedule(transactionDate, window) {
|
|
507
|
+
if (!window) {
|
|
508
|
+
throw new Error(
|
|
509
|
+
"installmentWindow is required when paymentTerm is 'thirdPartyInputFinance'"
|
|
510
|
+
);
|
|
511
|
+
}
|
|
512
|
+
if (!Number.isInteger(window.numberOfInstallments) || window.numberOfInstallments < 1) {
|
|
513
|
+
throw new Error(`Invalid numberOfInstallments: ${window.numberOfInstallments}`);
|
|
514
|
+
}
|
|
515
|
+
if (!Number.isInteger(window.periodInterval) || window.periodInterval < 1) {
|
|
516
|
+
throw new Error(`Invalid periodInterval: ${window.periodInterval}`);
|
|
517
|
+
}
|
|
518
|
+
const start = window.startDate ? toUtcMidnight(window.startDate) : transactionDate;
|
|
519
|
+
const dueDates = [];
|
|
520
|
+
for (let installmentNumber = 1; installmentNumber <= window.numberOfInstallments; installmentNumber++) {
|
|
521
|
+
if (window.periodType === "DAYS") {
|
|
522
|
+
dueDates.push(addDaysUtc(start, window.periodInterval * installmentNumber));
|
|
523
|
+
} else {
|
|
524
|
+
if (window.dayOfMonth == null) {
|
|
525
|
+
throw new Error("dayOfMonth is required when periodType is 'MONTHS'");
|
|
526
|
+
}
|
|
527
|
+
const monthOffset = window.periodInterval * installmentNumber;
|
|
528
|
+
dueDates.push(
|
|
529
|
+
new Date(Date.UTC(start.getUTCFullYear(), start.getUTCMonth() + monthOffset, window.dayOfMonth))
|
|
530
|
+
);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
return dueDates;
|
|
534
|
+
}
|
|
535
|
+
function calculatePaymentDueDate(input) {
|
|
536
|
+
const { transactionDate, paymentTerm } = input;
|
|
537
|
+
const normalizedTransactionDate = toUtcMidnight(transactionDate);
|
|
538
|
+
switch (paymentTerm) {
|
|
539
|
+
case "cashOnDelivery":
|
|
540
|
+
if (!input.deliveryDate) {
|
|
541
|
+
return null;
|
|
542
|
+
}
|
|
543
|
+
return toUtcMidnight(input.deliveryDate);
|
|
544
|
+
case "prePaymentProgram":
|
|
545
|
+
return normalizedTransactionDate;
|
|
546
|
+
case "supplierTradeCredit":
|
|
547
|
+
return calculateSupplierTradeCreditDueDate(
|
|
548
|
+
normalizedTransactionDate,
|
|
549
|
+
input.creditDaysWindow
|
|
550
|
+
);
|
|
551
|
+
case "forwardOrderingContract":
|
|
552
|
+
return calculateForwardOrderingContractDueDate(
|
|
553
|
+
normalizedTransactionDate,
|
|
554
|
+
input.forwardOrderingContractWindow
|
|
555
|
+
);
|
|
556
|
+
case "thirdPartyInputFinance":
|
|
557
|
+
return calculateInstallmentSchedule(
|
|
558
|
+
normalizedTransactionDate,
|
|
559
|
+
input.installmentWindow
|
|
560
|
+
);
|
|
561
|
+
default: {
|
|
562
|
+
const exhaustiveCheck = paymentTerm;
|
|
563
|
+
throw new Error(`Unknown paymentTerm: ${JSON.stringify(exhaustiveCheck)}`);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
function isDueDatePending(result) {
|
|
568
|
+
return result === null;
|
|
569
|
+
}
|
|
570
|
+
function isSingleDueDate(result) {
|
|
571
|
+
return result instanceof Date;
|
|
572
|
+
}
|
|
573
|
+
function isInstallmentSchedule(result) {
|
|
574
|
+
return Array.isArray(result);
|
|
575
|
+
}
|
|
576
|
+
|
|
413
577
|
// src/validators.ts
|
|
414
578
|
var Validator = {
|
|
415
579
|
/** * 1. Email: The classic. Uses a standard RFC 5322 regex.
|
|
@@ -903,15 +1067,15 @@ var getAcceptedMimeTypes = (taskType) => {
|
|
|
903
1067
|
var getApproveAction = (taskType) => {
|
|
904
1068
|
return TASK_TYPE_REGISTRY[taskType]?.approveAction ?? null;
|
|
905
1069
|
};
|
|
1070
|
+
function sanitizeSiteName(name) {
|
|
1071
|
+
return name.replace(/[^a-z0-9]/gi, "_");
|
|
1072
|
+
}
|
|
906
1073
|
function generateDocumentPath(params) {
|
|
907
|
-
const
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
const folderCrop = params.crop ? `/${params.crop.toUpperCase()}` : "";
|
|
913
|
-
return `${sanitizedName}/_SEASONAL/${folderYear}/${params.docType}${folderCrop}`;
|
|
914
|
-
}
|
|
1074
|
+
const sanitized = sanitizeSiteName(params.siteName);
|
|
1075
|
+
return params.isStatic ? `${sanitized}/_CORE/${params.docType}` : `${sanitized}/_SEASONAL/${params.year || (/* @__PURE__ */ new Date()).getUTCFullYear()}/${params.docType}${params.crop ? `/${params.crop.toUpperCase()}` : ""}`;
|
|
1076
|
+
}
|
|
1077
|
+
function generateSystemFolderPath(siteName, systemFolderKey) {
|
|
1078
|
+
return `${sanitizeSiteName(siteName)}/.system/${systemFolderKey}`;
|
|
915
1079
|
}
|
|
916
1080
|
function isValueMatch(fileValue, expectedValue) {
|
|
917
1081
|
if (Array.isArray(expectedValue)) return expectedValue.includes(fileValue);
|
|
@@ -982,17 +1146,22 @@ export {
|
|
|
982
1146
|
NettingType,
|
|
983
1147
|
NotificationMode,
|
|
984
1148
|
OrderStatus,
|
|
1149
|
+
PO_STATUSES,
|
|
1150
|
+
PREFLIGHT_CHECK_STATUSES,
|
|
1151
|
+
PRODUCT_TYPE_TO_BUDGET_CATEGORY,
|
|
985
1152
|
PhysicalState,
|
|
986
1153
|
PlantingMethod,
|
|
987
1154
|
PriceAmbiguityError,
|
|
988
1155
|
ProductType,
|
|
989
1156
|
ProductUnit,
|
|
1157
|
+
REQUISITION_STATUSES,
|
|
990
1158
|
RESOURCE_MODULE_MAP,
|
|
991
1159
|
RESOURCE_PATHS,
|
|
992
1160
|
RESOURCE_REQUIREMENTS,
|
|
993
1161
|
ROLE_SECTIONS_BY_KEY,
|
|
994
1162
|
RelationshipType,
|
|
995
1163
|
RowOrientation,
|
|
1164
|
+
SCOPE_LEVELS,
|
|
996
1165
|
SENTINEL_UUID,
|
|
997
1166
|
SESSION_SCHEMA,
|
|
998
1167
|
SIGNATURE_MODES,
|
|
@@ -1000,7 +1169,7 @@ export {
|
|
|
1000
1169
|
StockPolicyTier,
|
|
1001
1170
|
StoragePhases,
|
|
1002
1171
|
TASK_TYPE_REGISTRY,
|
|
1003
|
-
|
|
1172
|
+
TERM_RESOLUTION_MODES,
|
|
1004
1173
|
TargetEntityType,
|
|
1005
1174
|
TaskStatus,
|
|
1006
1175
|
TaskType,
|
|
@@ -1013,6 +1182,7 @@ export {
|
|
|
1013
1182
|
WaterSource,
|
|
1014
1183
|
assertTenantBoundary,
|
|
1015
1184
|
calculateFileMetadataMatch,
|
|
1185
|
+
calculatePaymentDueDate,
|
|
1016
1186
|
createBase44PricingAdapter,
|
|
1017
1187
|
decodeSession,
|
|
1018
1188
|
encodeSession,
|
|
@@ -1023,6 +1193,7 @@ export {
|
|
|
1023
1193
|
generateCanonicalId,
|
|
1024
1194
|
generateDocumentPath,
|
|
1025
1195
|
generateInfrastructureFields,
|
|
1196
|
+
generateSystemFolderPath,
|
|
1026
1197
|
getAcceptedMimeTypes,
|
|
1027
1198
|
getApproveAction,
|
|
1028
1199
|
getFormMeta,
|
|
@@ -1034,6 +1205,9 @@ export {
|
|
|
1034
1205
|
handleAppErrorResponse,
|
|
1035
1206
|
hasPrivilegeAt,
|
|
1036
1207
|
hasRoleAt,
|
|
1208
|
+
isDueDatePending,
|
|
1209
|
+
isInstallmentSchedule,
|
|
1210
|
+
isSingleDueDate,
|
|
1037
1211
|
isTabVisible,
|
|
1038
1212
|
isTabWritable,
|
|
1039
1213
|
resolveAccess,
|
|
@@ -1041,6 +1215,7 @@ export {
|
|
|
1041
1215
|
resolveEffectiveAccess,
|
|
1042
1216
|
resolveError,
|
|
1043
1217
|
resolvePrice,
|
|
1218
|
+
sanitizeSiteName,
|
|
1044
1219
|
transformRoleAssignments,
|
|
1045
1220
|
verifyAndExtractSession,
|
|
1046
1221
|
withAgriLogging
|