@litusarchieve18/agricore-utils 1.0.1 → 1.0.2

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 ADDED
@@ -0,0 +1,103 @@
1
+ # @litusarchieve18/agricore-utils
2
+
3
+ The Canonical Backend Utility Library for the **AgriCore** ecosystem.
4
+
5
+ This library provides the foundational "plumbing" for the AgriCore backend, including standardized error handling, data middleware, domain enums, and the core security session contracts. It is specifically optimized to be framework-agnostic and lightweight, with native support for the **Base44 / Deno** deployment environment.
6
+
7
+ ## 📦 Installation
8
+
9
+ Because Base44 Deno functions require module resolution at runtime without private authentication headers, this package is published to the **public NPM registry**.
10
+
11
+ ### For Node.js Environments
12
+ ```bash
13
+ npm install @litusarchieve18/agricore-utils
14
+
15
+ For Base44 / Deno Environments
16
+ You do not need a .npmrc or GITHUB_TOKEN to use this library in Base44. Import it directly using the npm: protocol:
17
+ import { AgriLogger, AppError, MOD } from 'npm:@litusarchieve18/agricore-utils@^1.0.2';
18
+
19
+ 🏗️ Core Architecture & Features
20
+ This library is designed with the "Adapter Pattern" in mind. It defines strict contracts (AgriCoreSession) so that your business logic remains completely isolated from the underlying Base44 database infrastructure.
21
+
22
+ 1. The AgriCore Session (v2)
23
+ The universal contract for authenticated users. The v2 upgrade includes injected UI-ready navigation data (availableScopes) and tenant configurations to prevent unnecessary frontend API calls.
24
+
25
+ TypeScript
26
+ import { AgriCoreSession } from 'npm:@litusarchieve18/agricore-utils@^1.0.2';
27
+
28
+ // Example of the v2 structure:
29
+ const session: AgriCoreSession = {
30
+ userId: "69e1a1...",
31
+ companyId: "69e6a3...",
32
+ activeScopeId: "660216...",
33
+ companyConfig: { isMultiEntity: true },
34
+ role: "owner",
35
+ privileges: ["finance", "hr", "auditCompliance", "admin"],
36
+ enabledModules: ["farm_management", "packhouse"],
37
+ readScopes: ["..."],
38
+ writeScopes: ["..."],
39
+ availableScopes: [
40
+ { authScopeId: "...", type: "company", name: "Acme Corp", parentId: null }
41
+ ],
42
+ resourceOverrides: { /* ... */ }
43
+ }
44
+ 2. Security Pillars & Middleware
45
+ Pure functions that enforce Row Level Security (RLS) and standardized data preparation without requiring direct database access.
46
+
47
+ assertCanWrite(session, targetScopeId)
48
+
49
+ buildRlsFilter(session)
50
+
51
+ withSaveMiddleware(data)
52
+
53
+ generateCanonicalId()
54
+
55
+ 3. Error Registry & Handling
56
+ Standardized error tracking using Module (MOD), Category (CAT), and Action (ACT) constants.
57
+
58
+ AppError class
59
+
60
+ ErrorFactory
61
+
62
+ 4. Domain Enums
63
+ The universal vocabulary of the AgriCore platform, ensuring type-safety across all microservices (e.g., UserRole, UserPrivilege, AccessLevel, FacilityType, NotificationMode, TaskStatus, RESOURCE_PATHS).
64
+
65
+ 🛠️ Development & Publishing Guide
66
+ Zero Dependencies
67
+ To keep the package ultra-lightweight (~30KB), this library has zero runtime dependencies. All build tools (tsup, typescript) are strictly kept in devDependencies, and the package.json uses the "files": ["dist"] array to ensure only compiled code is uploaded.
68
+
69
+ Building Locally
70
+ This project uses tsup for rapid, zero-config bundling into both CommonJS and ES Modules.
71
+
72
+ Bash
73
+ npm run build
74
+ The "No-PIN" Publishing Workflow (NPM 2FA Workaround)
75
+ Due to NPM's deprecation of CLI TOTP apps and Windows Security (Passkey) loop issues, publishing updates requires a Granular Access Token with 2FA Bypass.
76
+
77
+ To publish a new version:
78
+
79
+ Bump the "version" in package.json.
80
+
81
+ Ensure you have your granular token in a local (git-ignored) .npmrc file:
82
+
83
+ Ini, TOML
84
+ //registry.npmjs.org/:_authToken=npm_YOUR_GRANULAR_TOKEN
85
+ (Note: This token MUST be generated from the NPM website with the "Bypass Two-Factor Authentication" checkbox enabled for the @litusarchieve18 scope).
86
+
87
+ Run the publish command:
88
+
89
+ Bash
90
+ npm publish --access public
91
+ 📝 Version History
92
+ v1.0.2 — Breaking Change: Upgraded AgriCoreSession interface. Added companyConfig and UI-ready availableScopes arrays to support the frontend hierarchy dropdown without secondary API calls.
93
+
94
+ v1.0.1 — Migrated package from private GitHub Registry to public NPM Registry for Base44/Deno compatibility. Removed baseUrl from tsconfig.json for NodeNext compatibility. Cleaned build artifacts from dependencies.
95
+
96
+ v1.0.0 — Initial release. Core logging, error factory, and validation utilities.
97
+
98
+
99
+ ### Analyst Notes on the Process:
100
+ This README captures the entire technical journey we just completed:
101
+ 1. It explains **how** to import the code into Base44 using the `npm:` prefix.
102
+ 2. It highlights the **Adapter pattern** and the **v2 Session Object** so future developers know *why* the data is shaped that way.
103
+ 3. Most importantly, it documents the exact **Publishing Workflow** and the **2FA bypas
package/dist/index.d.mts CHANGED
@@ -1,4 +1,14 @@
1
1
  type PermissionLevel = 'WRITE' | 'READ' | 'NONE';
2
+ type ScopeType = 'company' | 'legalEntity' | 'facility';
3
+ interface AvailableScope {
4
+ authScopeId: string;
5
+ type: ScopeType;
6
+ name: string;
7
+ parentId: string | null;
8
+ }
9
+ interface CompanyConfig {
10
+ isMultiEntity: boolean;
11
+ }
2
12
  /**
3
13
  * Deep map of scope IDs to resource paths and their permission levels.
4
14
  * Example: { "uuid-123": { "farm.records": "WRITE" } }
@@ -14,11 +24,13 @@ interface AgriCoreSession {
14
24
  userId: string;
15
25
  companyId: string;
16
26
  activeScopeId: string | null;
27
+ companyConfig: CompanyConfig;
17
28
  role: string;
18
29
  privileges: string[];
19
30
  enabledModules: string[];
20
31
  readScopes: string[];
21
32
  writeScopes: string[];
33
+ availableScopes: AvailableScope[];
22
34
  resourceOverrides: ResourceOverrides;
23
35
  }
24
36
  interface ResolvedError {
@@ -312,8 +324,7 @@ declare const TargetEntityType: {
312
324
  readonly FARM: "FARM";
313
325
  readonly ZONE: "ZONE";
314
326
  readonly BLOCK: "BLOCK";
315
- readonly FUEL_SITE: "FUEL_SITE";
316
- readonly WORKSHOP: "WORKSHOP";
327
+ readonly INFRASTRUCTURE: "INFRASTRUCTURE";
317
328
  readonly AUTO: "AUTO";
318
329
  };
319
330
  declare const AuditType: {
@@ -467,4 +478,4 @@ declare const RESOURCE_PATHS: {
467
478
  teamTraining: string;
468
479
  };
469
480
 
470
- export { ACT, AccessLevel, type AgriCoreSession, AgriLogger, AppError, ApprovalStatus, ApprovalType, AuditStatus, AuditType, type AuthScopeFields, CAT, Converter, CropCycleStatus, ERROR_DICTIONARY, EmitterType, EnabledModule, ErrorFactory, FORM_REGISTRY, FacilityType, type FormMeta, HarvestMethod, LinkedStatus, MOD, MODULE_LABELS, MicroclimateZone, MimeType, type ModCode, NettingType, NotificationMode, OrderStatus, type PermissionLevel, PhysicalState, PlantingMethod, RESOURCE_PATHS, RelationshipType, type ResolvedError, type ResourceOverrides, RowOrientation, SENTINEL_UUID, SoilTexture, TASK_TYPE_REGISTRY, type TabConfig, TargetEntityType, TaskStatus, TaskType, type TaskTypeConfig, TransactionType, TrellisType, UserPrivilege, UserRole, Validator, VigorRating, WaterSource, assertCanWrite, buildRlsFilter, canRead, canWrite, extractAppCode, generateCanonicalId, getAcceptedMimeTypes, getApproveAction, getFormMeta, getFormsGroupedByModule, getTaskTypeOptions, handleAppErrorResponse, isTabVisible, isTabWritable, resolveAccess, resolveAppError, resolveAuthScopeId, resolveError, resolveMenuVisibility, withAgriLogging, withSaveMiddleware };
481
+ export { ACT, AccessLevel, type AgriCoreSession, AgriLogger, AppError, ApprovalStatus, ApprovalType, AuditStatus, AuditType, type AuthScopeFields, type AvailableScope, CAT, type CompanyConfig, Converter, CropCycleStatus, ERROR_DICTIONARY, EmitterType, EnabledModule, ErrorFactory, FORM_REGISTRY, FacilityType, type FormMeta, HarvestMethod, LinkedStatus, MOD, MODULE_LABELS, MicroclimateZone, MimeType, type ModCode, NettingType, NotificationMode, OrderStatus, type PermissionLevel, PhysicalState, PlantingMethod, RESOURCE_PATHS, RelationshipType, type ResolvedError, type ResourceOverrides, RowOrientation, SENTINEL_UUID, type ScopeType, SoilTexture, TASK_TYPE_REGISTRY, type TabConfig, TargetEntityType, TaskStatus, TaskType, type TaskTypeConfig, TransactionType, TrellisType, UserPrivilege, UserRole, Validator, VigorRating, WaterSource, assertCanWrite, buildRlsFilter, canRead, canWrite, extractAppCode, generateCanonicalId, getAcceptedMimeTypes, getApproveAction, getFormMeta, getFormsGroupedByModule, getTaskTypeOptions, handleAppErrorResponse, isTabVisible, isTabWritable, resolveAccess, resolveAppError, resolveAuthScopeId, resolveError, resolveMenuVisibility, withAgriLogging, withSaveMiddleware };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,14 @@
1
1
  type PermissionLevel = 'WRITE' | 'READ' | 'NONE';
2
+ type ScopeType = 'company' | 'legalEntity' | 'facility';
3
+ interface AvailableScope {
4
+ authScopeId: string;
5
+ type: ScopeType;
6
+ name: string;
7
+ parentId: string | null;
8
+ }
9
+ interface CompanyConfig {
10
+ isMultiEntity: boolean;
11
+ }
2
12
  /**
3
13
  * Deep map of scope IDs to resource paths and their permission levels.
4
14
  * Example: { "uuid-123": { "farm.records": "WRITE" } }
@@ -14,11 +24,13 @@ interface AgriCoreSession {
14
24
  userId: string;
15
25
  companyId: string;
16
26
  activeScopeId: string | null;
27
+ companyConfig: CompanyConfig;
17
28
  role: string;
18
29
  privileges: string[];
19
30
  enabledModules: string[];
20
31
  readScopes: string[];
21
32
  writeScopes: string[];
33
+ availableScopes: AvailableScope[];
22
34
  resourceOverrides: ResourceOverrides;
23
35
  }
24
36
  interface ResolvedError {
@@ -312,8 +324,7 @@ declare const TargetEntityType: {
312
324
  readonly FARM: "FARM";
313
325
  readonly ZONE: "ZONE";
314
326
  readonly BLOCK: "BLOCK";
315
- readonly FUEL_SITE: "FUEL_SITE";
316
- readonly WORKSHOP: "WORKSHOP";
327
+ readonly INFRASTRUCTURE: "INFRASTRUCTURE";
317
328
  readonly AUTO: "AUTO";
318
329
  };
319
330
  declare const AuditType: {
@@ -467,4 +478,4 @@ declare const RESOURCE_PATHS: {
467
478
  teamTraining: string;
468
479
  };
469
480
 
470
- export { ACT, AccessLevel, type AgriCoreSession, AgriLogger, AppError, ApprovalStatus, ApprovalType, AuditStatus, AuditType, type AuthScopeFields, CAT, Converter, CropCycleStatus, ERROR_DICTIONARY, EmitterType, EnabledModule, ErrorFactory, FORM_REGISTRY, FacilityType, type FormMeta, HarvestMethod, LinkedStatus, MOD, MODULE_LABELS, MicroclimateZone, MimeType, type ModCode, NettingType, NotificationMode, OrderStatus, type PermissionLevel, PhysicalState, PlantingMethod, RESOURCE_PATHS, RelationshipType, type ResolvedError, type ResourceOverrides, RowOrientation, SENTINEL_UUID, SoilTexture, TASK_TYPE_REGISTRY, type TabConfig, TargetEntityType, TaskStatus, TaskType, type TaskTypeConfig, TransactionType, TrellisType, UserPrivilege, UserRole, Validator, VigorRating, WaterSource, assertCanWrite, buildRlsFilter, canRead, canWrite, extractAppCode, generateCanonicalId, getAcceptedMimeTypes, getApproveAction, getFormMeta, getFormsGroupedByModule, getTaskTypeOptions, handleAppErrorResponse, isTabVisible, isTabWritable, resolveAccess, resolveAppError, resolveAuthScopeId, resolveError, resolveMenuVisibility, withAgriLogging, withSaveMiddleware };
481
+ export { ACT, AccessLevel, type AgriCoreSession, AgriLogger, AppError, ApprovalStatus, ApprovalType, AuditStatus, AuditType, type AuthScopeFields, type AvailableScope, CAT, type CompanyConfig, Converter, CropCycleStatus, ERROR_DICTIONARY, EmitterType, EnabledModule, ErrorFactory, FORM_REGISTRY, FacilityType, type FormMeta, HarvestMethod, LinkedStatus, MOD, MODULE_LABELS, MicroclimateZone, MimeType, type ModCode, NettingType, NotificationMode, OrderStatus, type PermissionLevel, PhysicalState, PlantingMethod, RESOURCE_PATHS, RelationshipType, type ResolvedError, type ResourceOverrides, RowOrientation, SENTINEL_UUID, type ScopeType, SoilTexture, TASK_TYPE_REGISTRY, type TabConfig, TargetEntityType, TaskStatus, TaskType, type TaskTypeConfig, TransactionType, TrellisType, UserPrivilege, UserRole, Validator, VigorRating, WaterSource, assertCanWrite, buildRlsFilter, canRead, canWrite, extractAppCode, generateCanonicalId, getAcceptedMimeTypes, getApproveAction, getFormMeta, getFormsGroupedByModule, getTaskTypeOptions, handleAppErrorResponse, isTabVisible, isTabWritable, resolveAccess, resolveAppError, resolveAuthScopeId, resolveError, resolveMenuVisibility, withAgriLogging, withSaveMiddleware };
package/dist/index.js CHANGED
@@ -604,8 +604,7 @@ var TargetEntityType = {
604
604
  FARM: "FARM",
605
605
  ZONE: "ZONE",
606
606
  BLOCK: "BLOCK",
607
- FUEL_SITE: "FUEL_SITE",
608
- WORKSHOP: "WORKSHOP",
607
+ INFRASTRUCTURE: "INFRASTRUCTURE",
609
608
  AUTO: "AUTO"
610
609
  };
611
610
  var AuditType = {
package/dist/index.mjs CHANGED
@@ -514,8 +514,7 @@ var TargetEntityType = {
514
514
  FARM: "FARM",
515
515
  ZONE: "ZONE",
516
516
  BLOCK: "BLOCK",
517
- FUEL_SITE: "FUEL_SITE",
518
- WORKSHOP: "WORKSHOP",
517
+ INFRASTRUCTURE: "INFRASTRUCTURE",
519
518
  AUTO: "AUTO"
520
519
  };
521
520
  var AuditType = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@litusarchieve18/agricore-utils",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Canonical Backend Utility Library for AgriCore",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",