@litusarchieve18/agricore-utils 1.0.27 → 1.0.28

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 CHANGED
@@ -185,7 +185,7 @@ npm publish --access public
185
185
  📝 Version History
186
186
  V1.0.29 —
187
187
 
188
- V1.0.28 —
188
+ V1.0.28 — altered the logic and added scope aware filtering and write-time validation in priceHelpers.ts
189
189
 
190
190
  V1.0.27 — adding get price helper, and adding adapter pattern to handle the conflicting price
191
191
 
@@ -242,7 +242,7 @@ interface PricingDataSource {
242
242
  }
243
243
  interface MatrixRow {
244
244
  canonicalId: string;
245
- matrixUnitPrice: number;
245
+ matrixUnitPriceCents: number;
246
246
  minimumOrderQuantity: number;
247
247
  leadTimeDays: number | null;
248
248
  }
@@ -242,7 +242,7 @@ interface PricingDataSource {
242
242
  }
243
243
  interface MatrixRow {
244
244
  canonicalId: string;
245
- matrixUnitPrice: number;
245
+ matrixUnitPriceCents: number;
246
246
  minimumOrderQuantity: number;
247
247
  leadTimeDays: number | null;
248
248
  }
@@ -1 +1 @@
1
- export { A as ACCESS_RANK, a as ACT, b as AccessLevel, e as ApprovalStatus, f as ApprovalType, g as AuditStatus, h as AuditType, B as BarcodeNamespace, l as BarcodeType, C as CAR_SUPPORTED_EVIDENCE_MIME_TYPES, p as CAR_SUPPORTED_SIGNATURE_MIME_TYPES, q as CAT, r as CATEGORY_TABS, s as CORRECTIVE_ACTION_GENERATION_SOURCES, t as CORRECTIVE_ACTION_STATUSES, y as CatalogSyncStatus, H as CropCycleStatus, I as DOCUMENT_DISPLAY_INFO, J as DOCUMENT_MENU_MAP, K as DocumentCategory, L as DocumentType, M as ERROR_DICTIONARY, N as EVERYONE, O as EmitterType, P as EnabledModule, Q as FORM_REGISTRY, R as FacilityType, U as HarvestMethod, W as LinkedStatus, X as MOD, Y as MODULE_LABELS, _ as MicroclimateZone, $ as MimeType, a0 as ModCode, a1 as NettingType, a3 as NotificationMode, a4 as OrderStatus, a6 as PhysicalState, a7 as PlantingMethod, ac as ProductType, ae as ProductUnit, ag as RESOURCE_MODULE_MAP, ah as RESOURCE_PATHS, ai as RESOURCE_REQUIREMENTS, aj as ROLE_SECTIONS_BY_KEY, ak as RelationshipType, an as ResourceRequirement, ap as RowOrientation, aq as SENTINEL_UUID, ar as SESSION_SCHEMA, as as SIGNATURE_MODES, ay as SoilTexture, az as StockPolicyTier, aB as StoragePhases, aD as TASK_TYPE_REGISTRY, aE as TEMPLATE_SCOPE_LEVELS, aG as TargetEntityType, aH as TaskStatus, aI as TaskType, aM as TransactionType, aN as TrellisType, aO as UserPrivilege, aQ as UserRole, aT as VigorRating, aU as WaterSource } from './constants-dvGSNAt_.mjs';
1
+ export { A as ACCESS_RANK, a as ACT, b as AccessLevel, e as ApprovalStatus, f as ApprovalType, g as AuditStatus, h as AuditType, B as BarcodeNamespace, l as BarcodeType, C as CAR_SUPPORTED_EVIDENCE_MIME_TYPES, p as CAR_SUPPORTED_SIGNATURE_MIME_TYPES, q as CAT, r as CATEGORY_TABS, s as CORRECTIVE_ACTION_GENERATION_SOURCES, t as CORRECTIVE_ACTION_STATUSES, y as CatalogSyncStatus, H as CropCycleStatus, I as DOCUMENT_DISPLAY_INFO, J as DOCUMENT_MENU_MAP, K as DocumentCategory, L as DocumentType, M as ERROR_DICTIONARY, N as EVERYONE, O as EmitterType, P as EnabledModule, Q as FORM_REGISTRY, R as FacilityType, U as HarvestMethod, W as LinkedStatus, X as MOD, Y as MODULE_LABELS, _ as MicroclimateZone, $ as MimeType, a0 as ModCode, a1 as NettingType, a3 as NotificationMode, a4 as OrderStatus, a6 as PhysicalState, a7 as PlantingMethod, ac as ProductType, ae as ProductUnit, ag as RESOURCE_MODULE_MAP, ah as RESOURCE_PATHS, ai as RESOURCE_REQUIREMENTS, aj as ROLE_SECTIONS_BY_KEY, ak as RelationshipType, an as ResourceRequirement, ap as RowOrientation, aq as SENTINEL_UUID, ar as SESSION_SCHEMA, as as SIGNATURE_MODES, ay as SoilTexture, az as StockPolicyTier, aB as StoragePhases, aD as TASK_TYPE_REGISTRY, aE as TEMPLATE_SCOPE_LEVELS, aG as TargetEntityType, aH as TaskStatus, aI as TaskType, aM as TransactionType, aN as TrellisType, aO as UserPrivilege, aQ as UserRole, aT as VigorRating, aU as WaterSource } from './constants-CrAPx_xU.mjs';
@@ -1 +1 @@
1
- export { A as ACCESS_RANK, a as ACT, b as AccessLevel, e as ApprovalStatus, f as ApprovalType, g as AuditStatus, h as AuditType, B as BarcodeNamespace, l as BarcodeType, C as CAR_SUPPORTED_EVIDENCE_MIME_TYPES, p as CAR_SUPPORTED_SIGNATURE_MIME_TYPES, q as CAT, r as CATEGORY_TABS, s as CORRECTIVE_ACTION_GENERATION_SOURCES, t as CORRECTIVE_ACTION_STATUSES, y as CatalogSyncStatus, H as CropCycleStatus, I as DOCUMENT_DISPLAY_INFO, J as DOCUMENT_MENU_MAP, K as DocumentCategory, L as DocumentType, M as ERROR_DICTIONARY, N as EVERYONE, O as EmitterType, P as EnabledModule, Q as FORM_REGISTRY, R as FacilityType, U as HarvestMethod, W as LinkedStatus, X as MOD, Y as MODULE_LABELS, _ as MicroclimateZone, $ as MimeType, a0 as ModCode, a1 as NettingType, a3 as NotificationMode, a4 as OrderStatus, a6 as PhysicalState, a7 as PlantingMethod, ac as ProductType, ae as ProductUnit, ag as RESOURCE_MODULE_MAP, ah as RESOURCE_PATHS, ai as RESOURCE_REQUIREMENTS, aj as ROLE_SECTIONS_BY_KEY, ak as RelationshipType, an as ResourceRequirement, ap as RowOrientation, aq as SENTINEL_UUID, ar as SESSION_SCHEMA, as as SIGNATURE_MODES, ay as SoilTexture, az as StockPolicyTier, aB as StoragePhases, aD as TASK_TYPE_REGISTRY, aE as TEMPLATE_SCOPE_LEVELS, aG as TargetEntityType, aH as TaskStatus, aI as TaskType, aM as TransactionType, aN as TrellisType, aO as UserPrivilege, aQ as UserRole, aT as VigorRating, aU as WaterSource } from './constants-dvGSNAt_.js';
1
+ export { A as ACCESS_RANK, a as ACT, b as AccessLevel, e as ApprovalStatus, f as ApprovalType, g as AuditStatus, h as AuditType, B as BarcodeNamespace, l as BarcodeType, C as CAR_SUPPORTED_EVIDENCE_MIME_TYPES, p as CAR_SUPPORTED_SIGNATURE_MIME_TYPES, q as CAT, r as CATEGORY_TABS, s as CORRECTIVE_ACTION_GENERATION_SOURCES, t as CORRECTIVE_ACTION_STATUSES, y as CatalogSyncStatus, H as CropCycleStatus, I as DOCUMENT_DISPLAY_INFO, J as DOCUMENT_MENU_MAP, K as DocumentCategory, L as DocumentType, M as ERROR_DICTIONARY, N as EVERYONE, O as EmitterType, P as EnabledModule, Q as FORM_REGISTRY, R as FacilityType, U as HarvestMethod, W as LinkedStatus, X as MOD, Y as MODULE_LABELS, _ as MicroclimateZone, $ as MimeType, a0 as ModCode, a1 as NettingType, a3 as NotificationMode, a4 as OrderStatus, a6 as PhysicalState, a7 as PlantingMethod, ac as ProductType, ae as ProductUnit, ag as RESOURCE_MODULE_MAP, ah as RESOURCE_PATHS, ai as RESOURCE_REQUIREMENTS, aj as ROLE_SECTIONS_BY_KEY, ak as RelationshipType, an as ResourceRequirement, ap as RowOrientation, aq as SENTINEL_UUID, ar as SESSION_SCHEMA, as as SIGNATURE_MODES, ay as SoilTexture, az as StockPolicyTier, aB as StoragePhases, aD as TASK_TYPE_REGISTRY, aE as TEMPLATE_SCOPE_LEVELS, aG as TargetEntityType, aH as TaskStatus, aI as TaskType, aM as TransactionType, aN as TrellisType, aO as UserPrivilege, aQ as UserRole, aT as VigorRating, aU as WaterSource } from './constants-CrAPx_xU.js';
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { d as AgriCoreSession, aR as UserRoleAssignment, aL as Tier, a8 as PriceConflictCandidate, av as ShadowedCleanMatch, ab as PricingDataSource, aa as PricingContext, a9 as PriceResolutionResult, au as ScopeType, aV as WireSession, an as ResourceRequirement, c as AccessLevelType, j as AvailableScope, V as InfrastructureFields, T as FormMeta, aF as TabConfig, al as ResolvedError } from './constants-dvGSNAt_.mjs';
2
- export { A as ACCESS_RANK, a as ACT, b as AccessLevel, e as ApprovalStatus, f as ApprovalType, g as AuditStatus, h as AuditType, i as AuthScopeFields, B as BarcodeNamespace, k as BarcodeNamespaceType, l as BarcodeType, m as BarcodeTypeType, n as Base44Id, o as BaseProductRow, C as CAR_SUPPORTED_EVIDENCE_MIME_TYPES, p as CAR_SUPPORTED_SIGNATURE_MIME_TYPES, q as CAT, r as CATEGORY_TABS, s as CORRECTIVE_ACTION_GENERATION_SOURCES, t as CORRECTIVE_ACTION_STATUSES, u as CanonicalId, v as CarSupportedEvidenceMimeType, w as CarSupportedSignatureMimeType, x as CarTemplateFileMetadata, y as CatalogSyncStatus, z as CatalogSyncStatusType, D as CompanyConfig, E as CorrectiveActionCompileTaskMetadata, F as CorrectiveActionGenerationSource, G as CorrectiveActionStatus, H as CropCycleStatus, I as DOCUMENT_DISPLAY_INFO, J as DOCUMENT_MENU_MAP, K as DocumentCategory, L as DocumentType, M as ERROR_DICTIONARY, N as EVERYONE, O as EmitterType, P as EnabledModule, Q as FORM_REGISTRY, R as FacilityType, S as FileUploadTaskType, U as HarvestMethod, W as LinkedStatus, X as MOD, Y as MODULE_LABELS, Z as MatrixRow, _ as MicroclimateZone, $ as MimeType, a0 as ModCode, a1 as NettingType, a2 as NormalizedSignatureValue, a3 as NotificationMode, a4 as OrderStatus, a5 as PermissionLevel, a6 as PhysicalState, a7 as PlantingMethod, ac as ProductType, ad as ProductTypeType, ae as ProductUnit, af as ProductUnitType, ag as RESOURCE_MODULE_MAP, ah as RESOURCE_PATHS, ai as RESOURCE_REQUIREMENTS, aj as ROLE_SECTIONS_BY_KEY, ak as RelationshipType, am as ResourceOverrides, ao as RoleAssignment, ap as RowOrientation, aq as SENTINEL_UUID, ar as SESSION_SCHEMA, as as SIGNATURE_MODES, at as SchemaField, aw as SignatureInput, ax as SignatureMode, ay as SoilTexture, az as StockPolicyTier, aA as StockPolicyTierType, aB as StoragePhases, aC as StorageType, aD as TASK_TYPE_REGISTRY, aE as TEMPLATE_SCOPE_LEVELS, aG as TargetEntityType, aH as TaskStatus, aI as TaskType, aJ as TaskTypeConfig, aK as TemplateScopeLevel, aM as TransactionType, aN as TrellisType, aO as UserPrivilege, aP as UserPrivilegeType, aQ as UserRole, aS as UserRoleType, aT as VigorRating, aU as WaterSource } from './constants-dvGSNAt_.mjs';
1
+ import { d as AgriCoreSession, aR as UserRoleAssignment, aL as Tier, a8 as PriceConflictCandidate, av as ShadowedCleanMatch, ab as PricingDataSource, aa as PricingContext, a9 as PriceResolutionResult, au as ScopeType, aV as WireSession, an as ResourceRequirement, c as AccessLevelType, j as AvailableScope, V as InfrastructureFields, T as FormMeta, aF as TabConfig, al as ResolvedError } from './constants-CrAPx_xU.mjs';
2
+ export { A as ACCESS_RANK, a as ACT, b as AccessLevel, e as ApprovalStatus, f as ApprovalType, g as AuditStatus, h as AuditType, i as AuthScopeFields, B as BarcodeNamespace, k as BarcodeNamespaceType, l as BarcodeType, m as BarcodeTypeType, n as Base44Id, o as BaseProductRow, C as CAR_SUPPORTED_EVIDENCE_MIME_TYPES, p as CAR_SUPPORTED_SIGNATURE_MIME_TYPES, q as CAT, r as CATEGORY_TABS, s as CORRECTIVE_ACTION_GENERATION_SOURCES, t as CORRECTIVE_ACTION_STATUSES, u as CanonicalId, v as CarSupportedEvidenceMimeType, w as CarSupportedSignatureMimeType, x as CarTemplateFileMetadata, y as CatalogSyncStatus, z as CatalogSyncStatusType, D as CompanyConfig, E as CorrectiveActionCompileTaskMetadata, F as CorrectiveActionGenerationSource, G as CorrectiveActionStatus, H as CropCycleStatus, I as DOCUMENT_DISPLAY_INFO, J as DOCUMENT_MENU_MAP, K as DocumentCategory, L as DocumentType, M as ERROR_DICTIONARY, N as EVERYONE, O as EmitterType, P as EnabledModule, Q as FORM_REGISTRY, R as FacilityType, S as FileUploadTaskType, U as HarvestMethod, W as LinkedStatus, X as MOD, Y as MODULE_LABELS, Z as MatrixRow, _ as MicroclimateZone, $ as MimeType, a0 as ModCode, a1 as NettingType, a2 as NormalizedSignatureValue, a3 as NotificationMode, a4 as OrderStatus, a5 as PermissionLevel, a6 as PhysicalState, a7 as PlantingMethod, ac as ProductType, ad as ProductTypeType, ae as ProductUnit, af as ProductUnitType, ag as RESOURCE_MODULE_MAP, ah as RESOURCE_PATHS, ai as RESOURCE_REQUIREMENTS, aj as ROLE_SECTIONS_BY_KEY, ak as RelationshipType, am as ResourceOverrides, ao as RoleAssignment, ap as RowOrientation, aq as SENTINEL_UUID, ar as SESSION_SCHEMA, as as SIGNATURE_MODES, at as SchemaField, aw as SignatureInput, ax as SignatureMode, ay as SoilTexture, az as StockPolicyTier, aA as StockPolicyTierType, aB as StoragePhases, aC as StorageType, aD as TASK_TYPE_REGISTRY, aE as TEMPLATE_SCOPE_LEVELS, aG as TargetEntityType, aH as TaskStatus, aI as TaskType, aJ as TaskTypeConfig, aK as TemplateScopeLevel, aM as TransactionType, aN as TrellisType, aO as UserPrivilege, aP as UserPrivilegeType, aQ as UserRole, aS as UserRoleType, aT as VigorRating, aU as WaterSource } from './constants-CrAPx_xU.mjs';
3
3
 
4
4
  declare const AgriLogger: {
5
5
  log(level: "INFO" | "WARN" | "ERROR", message: string, meta: any): void;
@@ -38,7 +38,21 @@ declare class AggregatePriceAmbiguityError extends Error {
38
38
  constructor(productId: string, conflicts: PriceAmbiguityError[], shadowedCleanMatches?: ShadowedCleanMatch[]);
39
39
  }
40
40
  declare function resolvePrice(dataSource: PricingDataSource, context: PricingContext): Promise<PriceResolutionResult>;
41
- declare function createBase44PricingAdapter(db: any): PricingDataSource;
41
+ interface PricingAdapterScope {
42
+ authScopeId: string;
43
+ companyId?: string;
44
+ }
45
+ declare function createBase44PricingAdapter(db: any, scope: PricingAdapterScope): PricingDataSource;
46
+ interface OverlapCheckScope extends PricingAdapterScope {
47
+ productId: string;
48
+ accountCode?: string;
49
+ contractReferenceNumber?: string;
50
+ matrixType?: 'procurement_buy' | 'contract_packing_charge';
51
+ }
52
+ declare function findOverlappingPriceWindows(db: any, scope: OverlapCheckScope, newRow: {
53
+ validFrom: string;
54
+ validTo: string | null;
55
+ }, excludeId?: string): Promise<PriceConflictCandidate[]>;
42
56
 
43
57
  declare const Validator: {
44
58
  /** * 1. Email: The classic. Uses a standard RFC 5322 regex.
@@ -201,4 +215,4 @@ declare function calculateFileMetadataMatch(criteria: {
201
215
  contextMatch?: string[];
202
216
  }, fileMetadata: Record<string, any>, auditContext: Record<string, any>): number;
203
217
 
204
- export { AccessLevelType, AggregatePriceAmbiguityError, AgriCoreSession, AgriLogger, AppError, AvailableScope, Converter, ErrorFactory, FormMeta, InfrastructureFields, PriceAmbiguityError, PriceConflictCandidate, PriceResolutionResult, PricingContext, PricingDataSource, ResolvedError, ResourceRequirement, ScopeType, ShadowedCleanMatch, TabConfig, Tier, UserRoleAssignment, Validator, WireSession, assertTenantBoundary, calculateFileMetadataMatch, createBase44PricingAdapter, decodeSession, encodeSession, evaluateBaseAccess, extractAppCode, findSpecificOverride, generateCanonicalId, generateDocumentPath, generateInfrastructureFields, getAcceptedMimeTypes, getApproveAction, getFormMeta, getFormsGroupedByModule, getPrivilegesAt, getRoleAt, getScopeAncestry, getTaskTypeOptions, handleAppErrorResponse, hasPrivilegeAt, hasRoleAt, isTabVisible, isTabWritable, resolveAccess, resolveAppError, resolveEffectiveAccess, resolveError, resolvePrice, transformRoleAssignments, verifyAndExtractSession, withAgriLogging };
218
+ export { AccessLevelType, AggregatePriceAmbiguityError, AgriCoreSession, AgriLogger, AppError, AvailableScope, Converter, ErrorFactory, FormMeta, InfrastructureFields, type OverlapCheckScope, PriceAmbiguityError, PriceConflictCandidate, PriceResolutionResult, type PricingAdapterScope, PricingContext, PricingDataSource, ResolvedError, ResourceRequirement, ScopeType, ShadowedCleanMatch, TabConfig, Tier, UserRoleAssignment, Validator, WireSession, assertTenantBoundary, calculateFileMetadataMatch, createBase44PricingAdapter, decodeSession, encodeSession, evaluateBaseAccess, extractAppCode, findOverlappingPriceWindows, findSpecificOverride, generateCanonicalId, generateDocumentPath, generateInfrastructureFields, getAcceptedMimeTypes, getApproveAction, getFormMeta, getFormsGroupedByModule, getPrivilegesAt, getRoleAt, getScopeAncestry, getTaskTypeOptions, handleAppErrorResponse, hasPrivilegeAt, hasRoleAt, isTabVisible, isTabWritable, resolveAccess, resolveAppError, resolveEffectiveAccess, resolveError, resolvePrice, transformRoleAssignments, verifyAndExtractSession, withAgriLogging };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { d as AgriCoreSession, aR as UserRoleAssignment, aL as Tier, a8 as PriceConflictCandidate, av as ShadowedCleanMatch, ab as PricingDataSource, aa as PricingContext, a9 as PriceResolutionResult, au as ScopeType, aV as WireSession, an as ResourceRequirement, c as AccessLevelType, j as AvailableScope, V as InfrastructureFields, T as FormMeta, aF as TabConfig, al as ResolvedError } from './constants-dvGSNAt_.js';
2
- export { A as ACCESS_RANK, a as ACT, b as AccessLevel, e as ApprovalStatus, f as ApprovalType, g as AuditStatus, h as AuditType, i as AuthScopeFields, B as BarcodeNamespace, k as BarcodeNamespaceType, l as BarcodeType, m as BarcodeTypeType, n as Base44Id, o as BaseProductRow, C as CAR_SUPPORTED_EVIDENCE_MIME_TYPES, p as CAR_SUPPORTED_SIGNATURE_MIME_TYPES, q as CAT, r as CATEGORY_TABS, s as CORRECTIVE_ACTION_GENERATION_SOURCES, t as CORRECTIVE_ACTION_STATUSES, u as CanonicalId, v as CarSupportedEvidenceMimeType, w as CarSupportedSignatureMimeType, x as CarTemplateFileMetadata, y as CatalogSyncStatus, z as CatalogSyncStatusType, D as CompanyConfig, E as CorrectiveActionCompileTaskMetadata, F as CorrectiveActionGenerationSource, G as CorrectiveActionStatus, H as CropCycleStatus, I as DOCUMENT_DISPLAY_INFO, J as DOCUMENT_MENU_MAP, K as DocumentCategory, L as DocumentType, M as ERROR_DICTIONARY, N as EVERYONE, O as EmitterType, P as EnabledModule, Q as FORM_REGISTRY, R as FacilityType, S as FileUploadTaskType, U as HarvestMethod, W as LinkedStatus, X as MOD, Y as MODULE_LABELS, Z as MatrixRow, _ as MicroclimateZone, $ as MimeType, a0 as ModCode, a1 as NettingType, a2 as NormalizedSignatureValue, a3 as NotificationMode, a4 as OrderStatus, a5 as PermissionLevel, a6 as PhysicalState, a7 as PlantingMethod, ac as ProductType, ad as ProductTypeType, ae as ProductUnit, af as ProductUnitType, ag as RESOURCE_MODULE_MAP, ah as RESOURCE_PATHS, ai as RESOURCE_REQUIREMENTS, aj as ROLE_SECTIONS_BY_KEY, ak as RelationshipType, am as ResourceOverrides, ao as RoleAssignment, ap as RowOrientation, aq as SENTINEL_UUID, ar as SESSION_SCHEMA, as as SIGNATURE_MODES, at as SchemaField, aw as SignatureInput, ax as SignatureMode, ay as SoilTexture, az as StockPolicyTier, aA as StockPolicyTierType, aB as StoragePhases, aC as StorageType, aD as TASK_TYPE_REGISTRY, aE as TEMPLATE_SCOPE_LEVELS, aG as TargetEntityType, aH as TaskStatus, aI as TaskType, aJ as TaskTypeConfig, aK as TemplateScopeLevel, aM as TransactionType, aN as TrellisType, aO as UserPrivilege, aP as UserPrivilegeType, aQ as UserRole, aS as UserRoleType, aT as VigorRating, aU as WaterSource } from './constants-dvGSNAt_.js';
1
+ import { d as AgriCoreSession, aR as UserRoleAssignment, aL as Tier, a8 as PriceConflictCandidate, av as ShadowedCleanMatch, ab as PricingDataSource, aa as PricingContext, a9 as PriceResolutionResult, au as ScopeType, aV as WireSession, an as ResourceRequirement, c as AccessLevelType, j as AvailableScope, V as InfrastructureFields, T as FormMeta, aF as TabConfig, al as ResolvedError } from './constants-CrAPx_xU.js';
2
+ export { A as ACCESS_RANK, a as ACT, b as AccessLevel, e as ApprovalStatus, f as ApprovalType, g as AuditStatus, h as AuditType, i as AuthScopeFields, B as BarcodeNamespace, k as BarcodeNamespaceType, l as BarcodeType, m as BarcodeTypeType, n as Base44Id, o as BaseProductRow, C as CAR_SUPPORTED_EVIDENCE_MIME_TYPES, p as CAR_SUPPORTED_SIGNATURE_MIME_TYPES, q as CAT, r as CATEGORY_TABS, s as CORRECTIVE_ACTION_GENERATION_SOURCES, t as CORRECTIVE_ACTION_STATUSES, u as CanonicalId, v as CarSupportedEvidenceMimeType, w as CarSupportedSignatureMimeType, x as CarTemplateFileMetadata, y as CatalogSyncStatus, z as CatalogSyncStatusType, D as CompanyConfig, E as CorrectiveActionCompileTaskMetadata, F as CorrectiveActionGenerationSource, G as CorrectiveActionStatus, H as CropCycleStatus, I as DOCUMENT_DISPLAY_INFO, J as DOCUMENT_MENU_MAP, K as DocumentCategory, L as DocumentType, M as ERROR_DICTIONARY, N as EVERYONE, O as EmitterType, P as EnabledModule, Q as FORM_REGISTRY, R as FacilityType, S as FileUploadTaskType, U as HarvestMethod, W as LinkedStatus, X as MOD, Y as MODULE_LABELS, Z as MatrixRow, _ as MicroclimateZone, $ as MimeType, a0 as ModCode, a1 as NettingType, a2 as NormalizedSignatureValue, a3 as NotificationMode, a4 as OrderStatus, a5 as PermissionLevel, a6 as PhysicalState, a7 as PlantingMethod, ac as ProductType, ad as ProductTypeType, ae as ProductUnit, af as ProductUnitType, ag as RESOURCE_MODULE_MAP, ah as RESOURCE_PATHS, ai as RESOURCE_REQUIREMENTS, aj as ROLE_SECTIONS_BY_KEY, ak as RelationshipType, am as ResourceOverrides, ao as RoleAssignment, ap as RowOrientation, aq as SENTINEL_UUID, ar as SESSION_SCHEMA, as as SIGNATURE_MODES, at as SchemaField, aw as SignatureInput, ax as SignatureMode, ay as SoilTexture, az as StockPolicyTier, aA as StockPolicyTierType, aB as StoragePhases, aC as StorageType, aD as TASK_TYPE_REGISTRY, aE as TEMPLATE_SCOPE_LEVELS, aG as TargetEntityType, aH as TaskStatus, aI as TaskType, aJ as TaskTypeConfig, aK as TemplateScopeLevel, aM as TransactionType, aN as TrellisType, aO as UserPrivilege, aP as UserPrivilegeType, aQ as UserRole, aS as UserRoleType, aT as VigorRating, aU as WaterSource } from './constants-CrAPx_xU.js';
3
3
 
4
4
  declare const AgriLogger: {
5
5
  log(level: "INFO" | "WARN" | "ERROR", message: string, meta: any): void;
@@ -38,7 +38,21 @@ declare class AggregatePriceAmbiguityError extends Error {
38
38
  constructor(productId: string, conflicts: PriceAmbiguityError[], shadowedCleanMatches?: ShadowedCleanMatch[]);
39
39
  }
40
40
  declare function resolvePrice(dataSource: PricingDataSource, context: PricingContext): Promise<PriceResolutionResult>;
41
- declare function createBase44PricingAdapter(db: any): PricingDataSource;
41
+ interface PricingAdapterScope {
42
+ authScopeId: string;
43
+ companyId?: string;
44
+ }
45
+ declare function createBase44PricingAdapter(db: any, scope: PricingAdapterScope): PricingDataSource;
46
+ interface OverlapCheckScope extends PricingAdapterScope {
47
+ productId: string;
48
+ accountCode?: string;
49
+ contractReferenceNumber?: string;
50
+ matrixType?: 'procurement_buy' | 'contract_packing_charge';
51
+ }
52
+ declare function findOverlappingPriceWindows(db: any, scope: OverlapCheckScope, newRow: {
53
+ validFrom: string;
54
+ validTo: string | null;
55
+ }, excludeId?: string): Promise<PriceConflictCandidate[]>;
42
56
 
43
57
  declare const Validator: {
44
58
  /** * 1. Email: The classic. Uses a standard RFC 5322 regex.
@@ -201,4 +215,4 @@ declare function calculateFileMetadataMatch(criteria: {
201
215
  contextMatch?: string[];
202
216
  }, fileMetadata: Record<string, any>, auditContext: Record<string, any>): number;
203
217
 
204
- export { AccessLevelType, AggregatePriceAmbiguityError, AgriCoreSession, AgriLogger, AppError, AvailableScope, Converter, ErrorFactory, FormMeta, InfrastructureFields, PriceAmbiguityError, PriceConflictCandidate, PriceResolutionResult, PricingContext, PricingDataSource, ResolvedError, ResourceRequirement, ScopeType, ShadowedCleanMatch, TabConfig, Tier, UserRoleAssignment, Validator, WireSession, assertTenantBoundary, calculateFileMetadataMatch, createBase44PricingAdapter, decodeSession, encodeSession, evaluateBaseAccess, extractAppCode, findSpecificOverride, generateCanonicalId, generateDocumentPath, generateInfrastructureFields, getAcceptedMimeTypes, getApproveAction, getFormMeta, getFormsGroupedByModule, getPrivilegesAt, getRoleAt, getScopeAncestry, getTaskTypeOptions, handleAppErrorResponse, hasPrivilegeAt, hasRoleAt, isTabVisible, isTabWritable, resolveAccess, resolveAppError, resolveEffectiveAccess, resolveError, resolvePrice, transformRoleAssignments, verifyAndExtractSession, withAgriLogging };
218
+ export { AccessLevelType, AggregatePriceAmbiguityError, AgriCoreSession, AgriLogger, AppError, AvailableScope, Converter, ErrorFactory, FormMeta, InfrastructureFields, type OverlapCheckScope, PriceAmbiguityError, PriceConflictCandidate, PriceResolutionResult, type PricingAdapterScope, PricingContext, PricingDataSource, ResolvedError, ResourceRequirement, ScopeType, ShadowedCleanMatch, TabConfig, Tier, UserRoleAssignment, Validator, WireSession, assertTenantBoundary, calculateFileMetadataMatch, createBase44PricingAdapter, decodeSession, encodeSession, evaluateBaseAccess, extractAppCode, findOverlappingPriceWindows, findSpecificOverride, generateCanonicalId, generateDocumentPath, generateInfrastructureFields, getAcceptedMimeTypes, getApproveAction, getFormMeta, getFormsGroupedByModule, getPrivilegesAt, getRoleAt, getScopeAncestry, getTaskTypeOptions, handleAppErrorResponse, hasPrivilegeAt, hasRoleAt, isTabVisible, isTabWritable, resolveAccess, resolveAppError, resolveEffectiveAccess, resolveError, resolvePrice, transformRoleAssignments, verifyAndExtractSession, withAgriLogging };
package/dist/index.js CHANGED
@@ -97,6 +97,7 @@ __export(index_exports, {
97
97
  encodeSession: () => encodeSession,
98
98
  evaluateBaseAccess: () => evaluateBaseAccess,
99
99
  extractAppCode: () => extractAppCode,
100
+ findOverlappingPriceWindows: () => findOverlappingPriceWindows,
100
101
  findSpecificOverride: () => findSpecificOverride,
101
102
  generateCanonicalId: () => generateCanonicalId,
102
103
  generateDocumentPath: () => generateDocumentPath,
@@ -287,7 +288,7 @@ var AggregatePriceAmbiguityError = class extends Error {
287
288
  };
288
289
  function fromMatrixRow(row, priceSource) {
289
290
  return {
290
- unitPriceCents: row.matrixUnitPrice,
291
+ unitPriceCents: row.matrixUnitPriceCents,
291
292
  minimumOrderQuantity: row.minimumOrderQuantity,
292
293
  leadTimeDays: row.leadTimeDays,
293
294
  priceSource,
@@ -314,7 +315,7 @@ async function resolvePrice(dataSource, context) {
314
315
  if (conflicts.length === 0) return fromMatrixRow(row, tier);
315
316
  shadowedCleanMatches.push({
316
317
  tier,
317
- unitPriceCents: row.matrixUnitPrice,
318
+ unitPriceCents: row.matrixUnitPriceCents,
318
319
  sourceRecordId: row.canonicalId,
319
320
  matchedOn
320
321
  });
@@ -376,7 +377,7 @@ function pickActiveRow(rows, targetIso, productId, tier, matchedOn) {
376
377
  tier,
377
378
  activeMatches.map((r) => ({
378
379
  sourceRecordId: r.canonicalId,
379
- unitPriceCents: r.matrixUnitPrice,
380
+ unitPriceCents: r.matrixUnitPriceCents,
380
381
  validFrom: r.validFrom,
381
382
  validTo: r.validTo
382
383
  })),
@@ -385,12 +386,17 @@ function pickActiveRow(rows, targetIso, productId, tier, matchedOn) {
385
386
  }
386
387
  return activeMatches[0] ?? null;
387
388
  }
388
- function createBase44PricingAdapter(db) {
389
+ function createBase44PricingAdapter(db, scope) {
390
+ const scopeFilter = {
391
+ authScopeId: scope.authScopeId,
392
+ ...scope.companyId ? { companyId: scope.companyId } : {}
393
+ };
389
394
  return {
390
395
  async findContractPrice({ productId, contractReferenceNumber, targetDate }) {
391
396
  const targetIso = targetDate.toISOString();
392
397
  const rows = await db.ProductPriceMatrix.filter(
393
398
  {
399
+ ...scopeFilter,
394
400
  productId,
395
401
  contractReferenceNumber,
396
402
  matrixType: "procurement_buy",
@@ -406,7 +412,7 @@ function createBase44PricingAdapter(db) {
406
412
  async findAccountPrice({ productId, accountCode, targetDate }) {
407
413
  const targetIso = targetDate.toISOString();
408
414
  const rows = await db.ProductPriceMatrix.filter(
409
- { productId, accountCode, validFrom_lte: targetIso },
415
+ { ...scopeFilter, productId, accountCode, validFrom_lte: targetIso },
410
416
  SORT_MOST_RECENT_FIRST,
411
417
  ACTIVE_ROW_LOOKBACK
412
418
  );
@@ -415,17 +421,54 @@ function createBase44PricingAdapter(db) {
415
421
  async findDefaultPrice({ productId, targetDate }) {
416
422
  const targetIso = targetDate.toISOString();
417
423
  const rows = await db.ProductPriceMatrix.filter(
418
- { productId, accountCode: "INTERNAL_DEFAULT", validFrom_lte: targetIso },
424
+ { ...scopeFilter, productId, accountCode: "INTERNAL_DEFAULT", validFrom_lte: targetIso },
419
425
  SORT_MOST_RECENT_FIRST,
420
426
  ACTIVE_ROW_LOOKBACK
421
427
  );
422
428
  return pickActiveRow(rows, targetIso, productId, "INTERNAL_DEFAULT", {});
423
429
  },
424
430
  async findBaseProduct({ productId }) {
425
- return await db.CompanyProduct.get(productId) ?? null;
431
+ const rows = await db.CompanyProduct.filter({ id: productId, authScopeId: scope.authScopeId });
432
+ return rows[0] ?? null;
426
433
  }
427
434
  };
428
435
  }
436
+ function rangesOverlap(aFrom, aTo, bFrom, bTo) {
437
+ const aStart = new Date(aFrom).getTime();
438
+ const aEnd = aTo ? new Date(aTo).getTime() : Infinity;
439
+ const bStart = new Date(bFrom).getTime();
440
+ const bEnd = bTo ? new Date(bTo).getTime() : Infinity;
441
+ return aStart <= bEnd && bStart <= aEnd;
442
+ }
443
+ async function findOverlappingPriceWindows(db, scope, newRow, excludeId) {
444
+ const { productId, accountCode, contractReferenceNumber, matrixType, authScopeId, companyId } = scope;
445
+ const scopeFilter = {
446
+ authScopeId,
447
+ ...companyId ? { companyId } : {}
448
+ };
449
+ const existingRows = await db.ProductPriceMatrix.filter(
450
+ {
451
+ ...scopeFilter,
452
+ productId,
453
+ ...accountCode ? { accountCode } : {},
454
+ ...contractReferenceNumber ? { contractReferenceNumber } : {},
455
+ ...matrixType ? { matrixType } : {}
456
+ },
457
+ SORT_MOST_RECENT_FIRST,
458
+ // Write-time validation must see the product's full pricing history in
459
+ // this scope, not just rows near "now" — ACTIVE_ROW_LOOKBACK (5) is
460
+ // read-time-specific and too shallow here.
461
+ 100
462
+ );
463
+ return existingRows.filter(
464
+ (r) => r.canonicalId !== excludeId && rangesOverlap(newRow.validFrom, newRow.validTo, r.validFrom, r.validTo)
465
+ ).map((r) => ({
466
+ sourceRecordId: r.canonicalId,
467
+ unitPriceCents: r.matrixUnitPriceCents,
468
+ validFrom: r.validFrom,
469
+ validTo: r.validTo
470
+ }));
471
+ }
429
472
 
430
473
  // src/validators.ts
431
474
  var Validator = {
@@ -1982,6 +2025,7 @@ function calculateFileMetadataMatch(criteria, fileMetadata, auditContext) {
1982
2025
  encodeSession,
1983
2026
  evaluateBaseAccess,
1984
2027
  extractAppCode,
2028
+ findOverlappingPriceWindows,
1985
2029
  findSpecificOverride,
1986
2030
  generateCanonicalId,
1987
2031
  generateDocumentPath,
package/dist/index.mjs CHANGED
@@ -228,7 +228,7 @@ var AggregatePriceAmbiguityError = class extends Error {
228
228
  };
229
229
  function fromMatrixRow(row, priceSource) {
230
230
  return {
231
- unitPriceCents: row.matrixUnitPrice,
231
+ unitPriceCents: row.matrixUnitPriceCents,
232
232
  minimumOrderQuantity: row.minimumOrderQuantity,
233
233
  leadTimeDays: row.leadTimeDays,
234
234
  priceSource,
@@ -255,7 +255,7 @@ async function resolvePrice(dataSource, context) {
255
255
  if (conflicts.length === 0) return fromMatrixRow(row, tier);
256
256
  shadowedCleanMatches.push({
257
257
  tier,
258
- unitPriceCents: row.matrixUnitPrice,
258
+ unitPriceCents: row.matrixUnitPriceCents,
259
259
  sourceRecordId: row.canonicalId,
260
260
  matchedOn
261
261
  });
@@ -317,7 +317,7 @@ function pickActiveRow(rows, targetIso, productId, tier, matchedOn) {
317
317
  tier,
318
318
  activeMatches.map((r) => ({
319
319
  sourceRecordId: r.canonicalId,
320
- unitPriceCents: r.matrixUnitPrice,
320
+ unitPriceCents: r.matrixUnitPriceCents,
321
321
  validFrom: r.validFrom,
322
322
  validTo: r.validTo
323
323
  })),
@@ -326,12 +326,17 @@ function pickActiveRow(rows, targetIso, productId, tier, matchedOn) {
326
326
  }
327
327
  return activeMatches[0] ?? null;
328
328
  }
329
- function createBase44PricingAdapter(db) {
329
+ function createBase44PricingAdapter(db, scope) {
330
+ const scopeFilter = {
331
+ authScopeId: scope.authScopeId,
332
+ ...scope.companyId ? { companyId: scope.companyId } : {}
333
+ };
330
334
  return {
331
335
  async findContractPrice({ productId, contractReferenceNumber, targetDate }) {
332
336
  const targetIso = targetDate.toISOString();
333
337
  const rows = await db.ProductPriceMatrix.filter(
334
338
  {
339
+ ...scopeFilter,
335
340
  productId,
336
341
  contractReferenceNumber,
337
342
  matrixType: "procurement_buy",
@@ -347,7 +352,7 @@ function createBase44PricingAdapter(db) {
347
352
  async findAccountPrice({ productId, accountCode, targetDate }) {
348
353
  const targetIso = targetDate.toISOString();
349
354
  const rows = await db.ProductPriceMatrix.filter(
350
- { productId, accountCode, validFrom_lte: targetIso },
355
+ { ...scopeFilter, productId, accountCode, validFrom_lte: targetIso },
351
356
  SORT_MOST_RECENT_FIRST,
352
357
  ACTIVE_ROW_LOOKBACK
353
358
  );
@@ -356,17 +361,54 @@ function createBase44PricingAdapter(db) {
356
361
  async findDefaultPrice({ productId, targetDate }) {
357
362
  const targetIso = targetDate.toISOString();
358
363
  const rows = await db.ProductPriceMatrix.filter(
359
- { productId, accountCode: "INTERNAL_DEFAULT", validFrom_lte: targetIso },
364
+ { ...scopeFilter, productId, accountCode: "INTERNAL_DEFAULT", validFrom_lte: targetIso },
360
365
  SORT_MOST_RECENT_FIRST,
361
366
  ACTIVE_ROW_LOOKBACK
362
367
  );
363
368
  return pickActiveRow(rows, targetIso, productId, "INTERNAL_DEFAULT", {});
364
369
  },
365
370
  async findBaseProduct({ productId }) {
366
- return await db.CompanyProduct.get(productId) ?? null;
371
+ const rows = await db.CompanyProduct.filter({ id: productId, authScopeId: scope.authScopeId });
372
+ return rows[0] ?? null;
367
373
  }
368
374
  };
369
375
  }
376
+ function rangesOverlap(aFrom, aTo, bFrom, bTo) {
377
+ const aStart = new Date(aFrom).getTime();
378
+ const aEnd = aTo ? new Date(aTo).getTime() : Infinity;
379
+ const bStart = new Date(bFrom).getTime();
380
+ const bEnd = bTo ? new Date(bTo).getTime() : Infinity;
381
+ return aStart <= bEnd && bStart <= aEnd;
382
+ }
383
+ async function findOverlappingPriceWindows(db, scope, newRow, excludeId) {
384
+ const { productId, accountCode, contractReferenceNumber, matrixType, authScopeId, companyId } = scope;
385
+ const scopeFilter = {
386
+ authScopeId,
387
+ ...companyId ? { companyId } : {}
388
+ };
389
+ const existingRows = await db.ProductPriceMatrix.filter(
390
+ {
391
+ ...scopeFilter,
392
+ productId,
393
+ ...accountCode ? { accountCode } : {},
394
+ ...contractReferenceNumber ? { contractReferenceNumber } : {},
395
+ ...matrixType ? { matrixType } : {}
396
+ },
397
+ SORT_MOST_RECENT_FIRST,
398
+ // Write-time validation must see the product's full pricing history in
399
+ // this scope, not just rows near "now" — ACTIVE_ROW_LOOKBACK (5) is
400
+ // read-time-specific and too shallow here.
401
+ 100
402
+ );
403
+ return existingRows.filter(
404
+ (r) => r.canonicalId !== excludeId && rangesOverlap(newRow.validFrom, newRow.validTo, r.validFrom, r.validTo)
405
+ ).map((r) => ({
406
+ sourceRecordId: r.canonicalId,
407
+ unitPriceCents: r.matrixUnitPriceCents,
408
+ validFrom: r.validFrom,
409
+ validTo: r.validTo
410
+ }));
411
+ }
370
412
 
371
413
  // src/validators.ts
372
414
  var Validator = {
@@ -963,6 +1005,7 @@ export {
963
1005
  encodeSession,
964
1006
  evaluateBaseAccess,
965
1007
  extractAppCode,
1008
+ findOverlappingPriceWindows,
966
1009
  findSpecificOverride,
967
1010
  generateCanonicalId,
968
1011
  generateDocumentPath,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@litusarchieve18/agricore-utils",
3
- "version": "1.0.27",
3
+ "version": "1.0.28",
4
4
  "description": "Canonical Backend Utility Library for AgriCore",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",