@jsb188/mday 1.1.10 → 1.1.11

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.
Files changed (119) hide show
  1. package/package.json +105 -54
  2. package/src/constants/agentDoc.ts +12 -0
  3. package/src/constants/agentMemory.ts +154 -0
  4. package/src/constants/aiChat.ts +5 -0
  5. package/src/constants/campaign.ts +127 -0
  6. package/src/constants/dataTable.ts +35 -9
  7. package/src/constants/dataTableFieldTypes.generated.ts +63 -0
  8. package/src/constants/docAccess.ts +32 -0
  9. package/src/constants/email.ts +20 -4
  10. package/src/constants/fieldDoc.ts +34 -0
  11. package/src/constants/graphqlReactivity.ts +113 -0
  12. package/src/constants/integration.ts +8 -9
  13. package/src/constants/log.ts +7 -410
  14. package/src/constants/logActivityGroupColors.generated.ts +19 -0
  15. package/src/constants/logTaxonomy.generated.ts +1103 -0
  16. package/src/constants/noteDoc.ts +77 -0
  17. package/src/constants/organization.ts +13 -15
  18. package/src/constants/pageRoute.ts +23 -0
  19. package/src/constants/schedule.ts +220 -0
  20. package/src/constants/scheduleRuleTemplateSeed.ts +138 -0
  21. package/src/constants/scheduleRuleTemplates.generated.ts +145 -0
  22. package/src/constants/sheet.ts +154 -6
  23. package/src/constants/sheetRegionSources.generated.ts +578 -0
  24. package/src/constants/square.ts +6 -6
  25. package/src/constants/storage.ts +56 -7
  26. package/src/constants/usage.ts +79 -0
  27. package/src/schemas/editLogEntry.ts +1010 -777
  28. package/src/schemas/fieldDocsQuery.ts +12 -0
  29. package/src/schemas/inboundContact.ts +60 -55
  30. package/src/schemas/logsQuery.ts +55 -49
  31. package/src/schemas/organization.ts +49 -46
  32. package/src/types/account.d.ts +4 -1
  33. package/src/types/agentDoc.d.ts +64 -0
  34. package/src/types/agentMemory.d.ts +74 -0
  35. package/src/types/campaign.d.ts +683 -0
  36. package/src/types/dataTable.d.ts +175 -256
  37. package/src/types/docAccess.d.ts +96 -0
  38. package/src/types/email.d.ts +83 -12
  39. package/src/types/fieldDoc.d.ts +273 -0
  40. package/src/types/inboundContact.d.ts +2 -1
  41. package/src/types/log.d.ts +209 -341
  42. package/src/types/noteDoc.d.ts +86 -0
  43. package/src/types/organization.d.ts +83 -40
  44. package/src/types/pageRoute.d.ts +48 -0
  45. package/src/types/schedule.d.ts +391 -0
  46. package/src/types/sheet.d.ts +862 -30
  47. package/src/types/storage.d.ts +206 -125
  48. package/src/types/usage.d.ts +106 -0
  49. package/src/types/workflow.d.ts +149 -18
  50. package/src/utils/agentDoc.ts +109 -0
  51. package/src/utils/aiChat.ts +26 -0
  52. package/src/utils/campaign.ts +741 -0
  53. package/src/utils/campaignFormEditor.ts +871 -0
  54. package/src/utils/dataTable.ts +425 -410
  55. package/src/utils/dataTableFieldTypeRegistry.ts +105 -0
  56. package/src/utils/dataTableRealtimeAuthority.ts +209 -0
  57. package/src/utils/dataTableRealtimeSelection.ts +134 -0
  58. package/src/utils/dataTableRowDocument.ts +508 -0
  59. package/src/utils/dataTableSource.ts +230 -0
  60. package/src/utils/docAccess.ts +383 -0
  61. package/src/utils/documentName.ts +53 -0
  62. package/src/utils/email.ts +112 -53
  63. package/src/utils/fieldDoc.ts +113 -0
  64. package/src/utils/log.ts +169 -176
  65. package/src/utils/logRegistryValue.ts +90 -0
  66. package/src/utils/logStoreRead.ts +266 -0
  67. package/src/utils/logTaxonomy.ts +76 -0
  68. package/src/utils/logTaxonomyDisplay.ts +439 -0
  69. package/src/utils/noteDoc.ts +827 -0
  70. package/src/utils/organization.ts +510 -91
  71. package/src/utils/pageRoute.ts +71 -0
  72. package/src/utils/schedule.ts +799 -0
  73. package/src/utils/scheduleEvaluation.ts +1994 -0
  74. package/src/utils/scheduleICS.ts +246 -0
  75. package/src/utils/scheduleRuleTemplates.ts +188 -0
  76. package/src/utils/sheet.ts +4842 -39
  77. package/src/utils/sheetAxisMove.ts +830 -0
  78. package/src/utils/sheetBootstrap.ts +1769 -0
  79. package/src/utils/sheetCommand.ts +423 -0
  80. package/src/utils/sheetExport.ts +238 -0
  81. package/src/utils/sheetFormulaEvaluation.ts +914 -0
  82. package/src/utils/sheetFormulaEvaluator.ts +852 -0
  83. package/src/utils/sheetJournal.ts +78 -0
  84. package/src/utils/sheetNumberFormat.ts +1211 -0
  85. package/src/utils/sheetRegion.ts +374 -0
  86. package/src/utils/sheetRegionFilter.ts +1259 -0
  87. package/src/utils/sheetRegionSourceRegistry.ts +594 -0
  88. package/src/utils/sheetSequence.ts +148 -0
  89. package/src/utils/sheetSnapshot.ts +992 -0
  90. package/src/utils/sheetStructureEdit.ts +1284 -0
  91. package/src/utils/square.ts +22 -12
  92. package/src/utils/storage.ts +152 -0
  93. package/src/utils/table-route.ts +127 -11
  94. package/src/utils/workflow.ts +191 -23
  95. package/tests/dataTableFieldTypeRegistry.test.ts +110 -0
  96. package/tests/docAccess.test.ts +525 -0
  97. package/tests/editLogEntry.test.ts +112 -0
  98. package/tests/noteDoc.test.ts +669 -0
  99. package/tests/schedule.test.ts +693 -0
  100. package/tests/scheduleEvaluation.test.ts +1970 -0
  101. package/tests/scheduleICS.test.ts +208 -0
  102. package/tests/scheduleRuleTemplates.test.ts +176 -0
  103. package/tests/scheduleSweepInvariants.test.ts +428 -0
  104. package/tests/sheetAxisMove.test.ts +343 -0
  105. package/tests/sheetFormulaEvaluator.test.ts +575 -0
  106. package/tests/sheetRegionFilter.test.ts +1135 -0
  107. package/tests/sheetSequence.test.ts +41 -0
  108. package/tests/sheetStructureEdit.test.ts +82 -0
  109. package/tsconfig.json +10 -10
  110. package/vitest.config.ts +8 -0
  111. package/src/constants/log-activityTexts.ts +0 -235
  112. package/src/constants/product.ts +0 -42
  113. package/src/constants/report.ts +0 -44
  114. package/src/schemas/productsQuery.ts +0 -53
  115. package/src/schemas/reportsQuery.ts +0 -20
  116. package/src/types/product.d.ts +0 -84
  117. package/src/types/report.d.ts +0 -290
  118. package/src/utils/product-calEvent.ts +0 -455
  119. package/src/utils/report.ts +0 -158
@@ -0,0 +1,41 @@
1
+ import {
2
+ requireSheetDesignRevision,
3
+ requireSheetJournalSeq,
4
+ } from '@jsb188/mday/utils/sheetSequence.ts';
5
+ import { describe, expect, it } from 'vitest';
6
+
7
+ describe('requireSheetDesignRevision', () => {
8
+ it('accepts canonical non-negative BIGINT identities including zero', () => {
9
+ expect(requireSheetDesignRevision('0')).toBe('0');
10
+ expect(requireSheetDesignRevision(7n)).toBe('7');
11
+ expect(requireSheetDesignRevision('9223372036854775807')).toBe(
12
+ '9223372036854775807',
13
+ );
14
+ });
15
+
16
+ it('rejects missing, numeric, malformed, negative, and overflowing values', () => {
17
+ for (const revision of [
18
+ null,
19
+ undefined,
20
+ 0,
21
+ Number.MAX_SAFE_INTEGER,
22
+ '',
23
+ ' 1',
24
+ '1 ',
25
+ '01',
26
+ '-1',
27
+ '1.5',
28
+ '9223372036854775808',
29
+ ]) {
30
+ expect(() => requireSheetDesignRevision(revision as never)).toThrow(
31
+ TypeError,
32
+ );
33
+ }
34
+ });
35
+ });
36
+
37
+ describe('requireSheetJournalSeq', () => {
38
+ it('rejects numeric mixed-version payloads at runtime', () => {
39
+ expect(() => requireSheetJournalSeq(1 as never)).toThrow(TypeError);
40
+ });
41
+ });
@@ -0,0 +1,82 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { getSheetStructureRangeAfterEdit } from '../src/utils/sheetStructureEdit.ts';
3
+
4
+ const BASE_RANGE = {
5
+ id: 'range-1',
6
+ startRowIndex: 2,
7
+ endRowIndex: 4,
8
+ startColumnIndex: 2,
9
+ endColumnIndex: 4,
10
+ };
11
+
12
+ /*
13
+ * Verify range deletions remove the selected axis at every range boundary.
14
+ */
15
+ describe('sheet structure range deletion', () => {
16
+ it.each([
17
+ [2, 2, 3],
18
+ [3, 2, 3],
19
+ [4, 2, 3],
20
+ ])(
21
+ 'shrinks row ranges when deleting row %i',
22
+ (targetIndex, expectedStart, expectedEnd) => {
23
+ const next = getSheetStructureRangeAfterEdit(
24
+ BASE_RANGE,
25
+ 'DELETE_ROW',
26
+ targetIndex,
27
+ );
28
+
29
+ expect(next).toMatchObject({
30
+ startRowIndex: expectedStart,
31
+ endRowIndex: expectedEnd,
32
+ });
33
+ },
34
+ );
35
+
36
+ it.each([
37
+ [2, 2, 3],
38
+ [3, 2, 3],
39
+ [4, 2, 3],
40
+ ])(
41
+ 'shrinks column ranges when deleting column %i',
42
+ (targetIndex, expectedStart, expectedEnd) => {
43
+ const next = getSheetStructureRangeAfterEdit(
44
+ BASE_RANGE,
45
+ 'DELETE_COLUMN',
46
+ targetIndex,
47
+ );
48
+
49
+ expect(next).toMatchObject({
50
+ startColumnIndex: expectedStart,
51
+ endColumnIndex: expectedEnd,
52
+ });
53
+ },
54
+ );
55
+
56
+ it('deletes a singleton range on the selected row', () => {
57
+ expect(
58
+ getSheetStructureRangeAfterEdit(
59
+ {
60
+ ...BASE_RANGE,
61
+ startRowIndex: 4,
62
+ endRowIndex: 4,
63
+ },
64
+ 'DELETE_ROW',
65
+ 4,
66
+ ),
67
+ ).toBeNull();
68
+ });
69
+
70
+ it('keeps protected ranges fixed', () => {
71
+ const next = getSheetStructureRangeAfterEdit(BASE_RANGE, 'DELETE_ROW', 4, [
72
+ {
73
+ startRowIndex: 1,
74
+ endRowIndex: 5,
75
+ startColumnIndex: 1,
76
+ endColumnIndex: 5,
77
+ },
78
+ ]);
79
+
80
+ expect(next).toEqual(BASE_RANGE);
81
+ });
82
+ });
package/tsconfig.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
- "compilerOptions": {
3
- "target": "ESNext",
4
- "module": "ESNext",
5
- "moduleResolution": "Bundler",
6
- "allowImportingTsExtensions": true,
7
- "noEmit": true,
8
- "strict": true,
9
- "esModuleInterop": true
10
- },
11
- "include": ["src/**/*"]
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "module": "ESNext",
5
+ "moduleResolution": "Bundler",
6
+ "allowImportingTsExtensions": true,
7
+ "noEmit": true,
8
+ "strict": true,
9
+ "esModuleInterop": true
10
+ },
11
+ "include": ["src/**/*"]
12
12
  }
@@ -0,0 +1,8 @@
1
+ import { defineConfig } from 'vitest/config';
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ environment: 'node',
6
+ include: ['tests/**/*.test.ts?(x)'],
7
+ },
8
+ });
@@ -1,235 +0,0 @@
1
- /**
2
- * *Not* operation-specific activities that could be used for many farming operations
3
- */
4
-
5
- export const WATER_TESTING_ACTIVITY_TO_TEXT = {
6
- WATER_TESTING: 'checking chlorine levels in water',
7
- OTHER_WATER_TESTING_ACTIVITY: 'other water testing related activities',
8
- };
9
-
10
- /**
11
- * #### #### #### ####
12
- * Arable farming
13
- * #### #### #### ####
14
- */
15
-
16
- export const ARABLE_FARMING_TO_TEXT = {
17
- // # Seeding & transplanting activities
18
- SEEDING: 'seeding crops',
19
- DIRECT_SEEDING: 'direct seeding crops',
20
- GREENHOUSE_SEEDING: 'greenhouse seeding crops',
21
- TRANSPLANTING: 'transplanting crops',
22
- SEED_COMPLIANCE_NOTE: 'seeding compliance notes',
23
- OTHER_TRANSPLANT_ACTIVITY: 'other seeding or transplanting activities',
24
-
25
- // # Field activities
26
- PREPARE_SOIL: 'soil, beds preparation',
27
- IRRIGATION: 'irrigation management',
28
- FERTILIZATION_COMPOST: 'fertilization, compost application',
29
- PROTECT_CROP: 'hand pulling weed, hoeing, and cultivation work',
30
- MONITOR_CROP: 'crop monitoring',
31
- PRUNING: 'pruning',
32
- STRUCTURE_MAINTENANCE: 'trellising, structure maintenance',
33
- PREPARE_HARVEST: 'preparing crops for harvest',
34
- OTHER_FIELD_ACTIVITY: 'other field activities or farm operation notes',
35
-
36
- // # Harvest activities
37
- HARVEST_CROP: 'harvesting crops',
38
- HARVEST_COUNT: 'counting, weighing harvested crops',
39
- SORT_GRADE: 'sorting, grading crops',
40
- YIELD_LOSS_ESTIMATE: 'estimating yield or loss',
41
- OTHER_HARVEST_ACTIVITY: 'other harvest activities',
42
-
43
- // # Post-harvest activities
44
- POST_HARVEST_HANDLING: 'washing, drying, trimming, sorting, or grading produce',
45
- POST_HARVEST_PACKAGING: 'packaging, cooling, or moving produce to storage',
46
- OTHER_POST_HARVEST_ACTIVITY: 'other post-harvest activities such as cleaning, storage, and maintenance',
47
- };
48
-
49
- export const ARABLE_PURCHASES_TO_TEXT = {
50
- // # Seed purchase activities
51
- SEED_PURCHASE_INFO: 'seed purchase',
52
- OTHER_SUPPLY_PURCHASE_ACTIVITY: 'other supply purchase',
53
- };
54
-
55
- export const ARABLE_SALES_TO_TEXT = {
56
- // # Sales activities
57
- SALE_PRODUCE_ORDER: 'sales order (produce)',
58
- OTHER_SALE_ORDER: 'sales order (other)',
59
- };
60
-
61
- export const ARABLE_SEED_TO_SALE_TO_TEXT = {
62
- COLD_STORAGE_TEMPERATURE: 'checking or changing temperature (cold storage)',
63
- ...ARABLE_PURCHASES_TO_TEXT,
64
- ...ARABLE_SALES_TO_TEXT,
65
- ...ARABLE_FARMING_TO_TEXT,
66
- ...WATER_TESTING_ACTIVITY_TO_TEXT,
67
- };
68
-
69
- // Food Safety is separate from arable farming
70
-
71
- export const ARABLE_FOOD_SAFETY_TO_TEXT = {
72
- // # Hygiene
73
- HYGIENE_PROCEDURE: 'hygiene procedures',
74
- CONTAMINANT_RISK: 'contaminant risk assessment and mitigation (physical, chemical, microbial)',
75
- BODILY_FLUID_CONTAMINATION: 'vomitting/bodily fluid decontamination',
76
- SMOKING_EATING_DRINKING_CONTROL: 'smoking, eating, and drinking control actions',
77
- PPE_USAGE: 'personal protective equipment (PPE) usage',
78
-
79
- // # Sanitation
80
- SANITATION_RISK: 'sanitation risk assessment and mitigation',
81
- SANITATION_CONSTRUCTION_MAINTENANCE: 'sanitation facilities construction, repairs, or maintenance',
82
- SANITATION_CLEANING: 'sanitation facilities cleaning activities',
83
- SANITATION_PEST_CONTROL: 'pest control in sanitation facilities',
84
-
85
- // # Equpiments & Materials
86
- EQUIPMENTS_MATERIALS_RISK: 'Materials, food containers/equipments - safety assessment and mitigation',
87
- EQUIPMENTS_MATERIALS_CLEANING: 'Materials, food containers/equipments - cleaning activities',
88
-
89
- // # Environment & Biosecurity
90
- ENVIRONMENT_RISK: 'environmental food safety risk assessment and mitigation',
91
-
92
- // # Employees
93
- EMPLOYEE_ORIENTATION: 'new employee orientation',
94
- EMPLOYEE_TRAINING: 'employee training',
95
- SICK_EMPLOYEE: 'employee sick report',
96
- EMPLOYEE_INJURED: 'employee injury report',
97
- // All texts for same activity names must be same across all operations
98
- // ie. ARABLE vs FARMERS_MARKET
99
- EMPLOYEE_NOTES: 'notes about an employee',
100
- OPERATION_NOTES: 'general operation notes',
101
- };
102
-
103
- export const ARABLE_ACTIVITIES_TO_TEXT = {
104
- ...ARABLE_SEED_TO_SALE_TO_TEXT,
105
- ...ARABLE_FOOD_SAFETY_TO_TEXT,
106
- };
107
-
108
- /**
109
- * #### #### #### ####
110
- * Farmers Market
111
- * #### #### #### ####
112
- */
113
-
114
- export const FARMERS_MARKET_RECEIPT_TO_TEXT = {
115
- MARKET_CREDIT_RECEIPT: 'receipts for market credits, coins, or voucher redemption',
116
- };
117
-
118
- export const FARMERS_MARKET_MANAGEMENT_TO_TEXT = {
119
- MARKET_ATTENDANCE: 'attendance for vendor',
120
- MARKET_LOAD_LIST: 'vendor load list',
121
- };
122
-
123
- export const FARMERS_MARKET_NOTE_TO_TEXT = {
124
- OPERATION_NOTE: 'general operation notes',
125
- };
126
-
127
- export const FARMERS_MARKET_ACTIVITIES_TO_TEXT = {
128
- ...FARMERS_MARKET_RECEIPT_TO_TEXT,
129
- ...FARMERS_MARKET_MANAGEMENT_TO_TEXT,
130
- ...FARMERS_MARKET_NOTE_TO_TEXT,
131
- };
132
-
133
- /**
134
- * #### #### #### ####
135
- * Grower Network
136
- * #### #### #### ####
137
- */
138
-
139
- export const GROWER_NETWORK_INSPECTION_TO_TEXT = {
140
- // # WORKER_PRACTICE
141
- HYGIENE_PROCEDURE: 'worker hygiene procedures',
142
- SANITATION_PRACTICE: 'sanitation conditions and cleanliness',
143
- PERSONNEL_PRACTICE: 'PPE compliance, worker practices, training, illness',
144
-
145
- // # EQUIPMENT
146
- EQUIPMENT_MATERIAL: 'production and harvest equipments/tools/materials',
147
- PACKAGING_STORAGE: 'packaging and storage of produce',
148
-
149
- // # FIELD
150
- ENVIRONMENT: 'environmental exposure and wildlife activity',
151
- FIELD_CONDITION: 'field conditions, flood zones, erosion',
152
- ADJACENT_LAND: 'adjacent land observations, risks',
153
-
154
- // # PRODUCTION_INPUT
155
- WATER_INPUT: 'water source, quality, treatment, testing, and application',
156
- CHEMICAL_INPUT: 'chemical inputs handling and application',
157
- FERTILIZER_INPUT: 'fertilizer inputs handling and application',
158
-
159
- // # OPERATION
160
- RECORDKEEPING: 'document control, record availability, and accuracy',
161
- FACILITIES: 'facilities, physical infrastructure, and maintenance',
162
- OPERATION_NOTE: 'general operation notes',
163
- };
164
-
165
- export const GROWER_NETWORK_ACTIVITIES_TO_TEXT = {
166
- ...GROWER_NETWORK_INSPECTION_TO_TEXT,
167
- };
168
-
169
- /**
170
- * #### #### #### ####
171
- * Livestock ranching
172
- * #### #### #### ####
173
- */
174
-
175
- export const LIVESTOCK_LIFECYCLE_TO_TEXT = {
176
- // # Livestock life cycle
177
- LIVESTOCK_PURCHASE: 'livestock purchase',
178
- LIVESTOCK_BIRTH: 'livestock birth',
179
- LIVESTOCK_REPRODUCTION: 'livestock reproduction',
180
- LIVESTOCK_DEATH: 'livestock death',
181
- OTHER_LIVESTOCK_LIFE_CYCLE_ACTIVITY: 'other livestock life cycle notes',
182
-
183
- // # Livestock tracking
184
- LIVESTOCK_GROUP_TRACKING: 'livestock group tracking/movement based on age or other criteria',
185
- LIVESTOCK_PASTURE_TRACKING: 'livestock pasture tracking/movement', // where they are in pasture
186
- LIVESTOCK_ROTATIONAL_GRAZING: 'livestock rotational grazing/movement',
187
- OTHER_LIVESTOCK_TRACKING_ACTIVITY: 'other livestock tracking notes',
188
-
189
- // # Livestock healthcare
190
- LIVESTOCK_VACCINATION: 'livestock vaccination',
191
- LIVESTOCK_SICK: 'livestock sickness',
192
- LIVESTOCK_INJURY: 'livestock injury',
193
- LIVESTOCK_CULL: 'livestock culling',
194
- LIVESTOCK_TREATMENT: 'livestock treatment and recovery',
195
- OTHER_LIVESTOCK_HEALTHCARE_ACTIVITY: 'other livestock healthcare notes',
196
-
197
- // # Livestock sale
198
- LIVESTOCK_SALE: 'livestock sale',
199
- OTHER_LIVESTOCK_SALE_ACTIVITY: 'other sales activities',
200
- };
201
-
202
- export const LIVESTOCK_RANCH_MANAGEMENT_TO_TEXT = {
203
- // # Ranch management activities
204
- PASTURE_SEEDING: 'pasture seeding',
205
- FENCE_MAINTENANCE: 'fence maintenance and buffer management', // buffer zones/buffer management
206
- WATER_SOURCE_MAINTENANCE: 'water source maintenance',
207
- OTHER_PASTURE_LAND_MANAGEMENT_ACTIVITY: 'other pasture or ranch operation notes',
208
- };
209
-
210
- export const LIVESTOCK_TRANSACTIONS_TO_TEXT = {
211
- // # Supply purchases
212
- FEED_PURCHASE: 'feed purchase',
213
- OTHER_SUPPLY_PURCHASE_ACTIVITY: 'other supply purchase',
214
- };
215
-
216
- export const LIVESTOCK_ACTIVITIES_TO_TEXT = {
217
- ...LIVESTOCK_LIFECYCLE_TO_TEXT,
218
- ...LIVESTOCK_RANCH_MANAGEMENT_TO_TEXT,
219
- ...LIVESTOCK_TRANSACTIONS_TO_TEXT,
220
- };
221
-
222
- /**
223
- * Combine all activity texts;
224
- * NOTE: If one of these Objects have same key and different value,
225
- * That would cause a *huge* problem in the agent functions.
226
- */
227
-
228
- export const AGENT_TEXT_TO_ACTIVITIES: Record<string, string> = Object.fromEntries(
229
- Object.entries({
230
- ...ARABLE_ACTIVITIES_TO_TEXT,
231
- ...FARMERS_MARKET_ACTIVITIES_TO_TEXT,
232
- ...GROWER_NETWORK_ACTIVITIES_TO_TEXT,
233
- ...LIVESTOCK_ACTIVITIES_TO_TEXT,
234
- }).map(([key, value]) => [value, key]),
235
- );
@@ -1,42 +0,0 @@
1
- /**
2
- * Products; all types
3
- */
4
-
5
- export const PRODUCT_TYPES = [
6
- 'FOOD_SAFETY',
7
- 'GLOBAL_GAP',
8
- ];
9
-
10
- /**
11
- * Product features
12
- */
13
-
14
- export const FEATURES_BY_OPERATION = {
15
- ARABLE: [
16
- 'NORMAL_LOGGING', // First item is always the default
17
- 'FOOD_SAFETY',
18
- 'GLOBAL_GAP',
19
- ],
20
- FARMERS_MARKET: [
21
- 'NORMAL_LOGGING',
22
- 'MARKET_ATTENDANCE',
23
- ],
24
- LIVESTOCK: [
25
- 'NORMAL_LOGGING',
26
- ],
27
- GROWER_NETWORK: [
28
- 'NORMAL_LOGGING',
29
- 'SITE_INSPECTION'
30
- ]
31
- };
32
-
33
- export const PRODUCT_FEATURES = [
34
- ...FEATURES_BY_OPERATION.ARABLE,
35
- ...FEATURES_BY_OPERATION.FARMERS_MARKET,
36
- ...FEATURES_BY_OPERATION.LIVESTOCK,
37
- ...FEATURES_BY_OPERATION.GROWER_NETWORK,
38
- ].filter((value, index, self) => self.indexOf(value) === index);
39
-
40
- export const PRODUCT_FEATURES_WORKFLOW = PRODUCT_FEATURES.filter((feature) =>
41
- !['NORMAL_LOGGING'].includes(feature)
42
- );
@@ -1,44 +0,0 @@
1
- /**
2
- * Reports; all types
3
- */
4
-
5
- export const REPORT_SORT_OPTS = [
6
- 'PERIOD_DESC',
7
- 'ACTIVITY_DESC',
8
- ];
9
-
10
- export const REPORT_ROW_PRESETS = [
11
-
12
- 'REPORT_SUMMARY',
13
- 'LINE_TITLE',
14
- 'LINE_ITEMS',
15
- 'ORGS_LIST',
16
- 'TEXTS',
17
-
18
- // All deprecated below
19
- 'LABELS',
20
- 'BREAK',
21
- 'Q_AND_A',
22
- 'LONG_TEXTS', // Same as "TEXTS" but has a different function in <FileBrowserPlus>
23
- 'HEADINGS',
24
- 'EVIDENCES',
25
- ];
26
-
27
- export const REPORT_NUMBERED_PRESETS = [
28
- 'LINE_ITEMS',
29
- 'ORGS_LIST',
30
- ];
31
-
32
- export const REPORT_FREQUENCY_ENUMS = [
33
- 'DAILY',
34
- 'WEEKLY',
35
- 'MONTHLY',
36
- 'QUARTERLY',
37
- 'ANNUALLY',
38
- ];
39
-
40
- export const REPORT_STATUS_ENUMS = [
41
- 'PASS',
42
- 'WARNING',
43
- 'FAIL',
44
- ];
@@ -1,53 +0,0 @@
1
- import { PRODUCT_TYPES } from '@jsb188/mday/constants/product.ts';
2
- import { z } from 'zod';
3
- import type { ProductTypeEnum } from '../types/product.d.ts';
4
-
5
- /**
6
- * Zod schema for query params to filter
7
- */
8
-
9
- export const ProductsFilterSchema = z.object({
10
- preset: z.string()
11
- .optional()
12
- .nullable(),
13
- productType: z.enum(PRODUCT_TYPES as [string]),
14
- // startDate: z.string()
15
- // .refine((sd) => isValidCalDate(sd), { message: 'START_DATE_INVALID' })
16
- // .refine((sd) => !isFutureCalDate(sd, 1), { message: 'START_DATE_FUTURE_NOT_ALLOWED' })
17
- // .nullable(),
18
- // endDate: z.string()
19
- // .refine((ed) => isValidCalDate(ed), { message: 'END_DATE_INVALID' })
20
- // .nullable(),
21
- // timeZone: z.string()
22
- // .refine((tz) => isValidTimeZone(tz), { message: 'INVALID_TIMEZONE' })
23
- // .nullable(),
24
- query: z.string()
25
- .nullable(),
26
- });
27
- // }).refine((data) => {
28
- // if (!data.endDate) {
29
- // // No need to validate if endDate is not provided
30
- // return true;
31
- // } else if (!data.startDate) {
32
- // // If endDate is provided, startDate is required
33
- // return false;
34
- // }
35
- // // End date must be after or equal to start date
36
- // return data.endDate >= data.startDate;
37
- // }, {
38
- // message: 'END_DATE_MUST_BE_AFTER_START_DATE',
39
- // path: ['endDate'], // where to attach the error
40
- // });
41
-
42
- /**
43
- * Convert list of digits to product type enums
44
- * @param digit - Index digit string from URL param
45
- * @returns Array of product type enums or null
46
- */
47
-
48
- export function convertDigitToProductType(digit?: string | null): ProductTypeEnum | null {
49
- if (!digit) {
50
- return null;
51
- }
52
- return PRODUCT_TYPES[Number(digit)] || null;
53
- }
@@ -1,20 +0,0 @@
1
- import z from 'zod';
2
-
3
- /**
4
- * Zod schema for query params to filter
5
- */
6
-
7
- export const ReportsFilterSchema = z.object({
8
- preset: z.string()
9
- .optional()
10
- .nullable(),
11
- reportGroupId: z.string()
12
- .optional()
13
- .nullable(),
14
- startPeriod: z.string()
15
- .optional()
16
- .nullable(),
17
- endPeriod: z.string()
18
- .optional()
19
- .nullable(),
20
- });
@@ -1,84 +0,0 @@
1
- import type { AccountData } from './account.d.ts';
2
- import type { AddressObj, ScheduleObj } from '@jsb188/app/types/other.d.ts';
3
- import { PRODUCT_TYPES } from '../constants/product.ts';
4
- import type { OrganizationData, OrganizationGQL } from './organization.d.ts';
5
-
6
- /**
7
- * Enums
8
- */
9
-
10
- export type ProductTypeEnum = typeof PRODUCT_TYPES[number];
11
-
12
- /**
13
- * Filters
14
- */
15
-
16
- export interface ProductsFilterArgs {
17
- preset?: '?' | null;
18
- productType: ProductTypeEnum;
19
- query?: string | null;
20
- calDate?: string | null; // "YYYY-MM-DD"
21
- timeZone?: string | null; // Server only for now
22
- }
23
-
24
- /**
25
- * Product details; Calendar event
26
- */
27
-
28
- export interface ProductCalEventObj {
29
- name: string;
30
- metadata: Partial<{
31
- schedule: ScheduleObj | null;
32
- address: Partial<AddressObj> | null;
33
- }>;
34
-
35
- startAt: Date | string; // ISO Date string
36
- endAt?: Date | string | null; // ISO Date string
37
- }
38
-
39
- export interface ProductCalEventData extends ProductCalEventObj {
40
- __table: 'products_calendar_events';
41
- productId: number | bigint;
42
- }
43
-
44
- export interface ProductCalEventGQL {
45
- __typename: 'ProductCalEvent';
46
-
47
- id: string;
48
- organizationId: string;
49
-
50
- name: string;
51
- schedule: ScheduleObj | null;
52
- address: AddressObj | null;
53
- startAt: Date;
54
- endAt: Date;
55
- }
56
-
57
- export type ProductDetailsObj = ProductCalEventObj;
58
- export type ProductDetailsData = ProductCalEventData;
59
- export type ProductDetailsGQL = ProductCalEventGQL;
60
-
61
- /**
62
- * Product data objects
63
- */
64
-
65
- export interface ProductData {
66
- __table: 'products';
67
- productId: number | bigint;
68
- organizationId: number | bigint;
69
- details: ProductDetailsData;
70
- createdAt: Date;
71
- updatedAt: Date;
72
- }
73
-
74
- export interface ProductGQL {
75
- __deleted?: boolean; // For client-side only
76
-
77
- id: string;
78
- organizationId: string;
79
- cursor: string | null; // Cursor for pagination
80
- details: ProductDetailsGQL | null;
81
-
82
- createdAt: string; // ISO Date
83
- updatedAt: string; // ISO Date
84
- }