@jsb188/mday 1.1.8 → 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 (123) hide show
  1. package/package.json +105 -35
  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 +48 -0
  7. package/src/constants/dataTableFieldTypes.generated.ts +63 -0
  8. package/src/constants/docAccess.ts +32 -0
  9. package/src/constants/email.ts +44 -0
  10. package/src/constants/fieldDoc.ts +34 -0
  11. package/src/constants/graphqlReactivity.ts +113 -0
  12. package/src/constants/inboundContact.ts +8 -0
  13. package/src/constants/integration.ts +13 -0
  14. package/src/constants/log.ts +7 -366
  15. package/src/constants/logActivityGroupColors.generated.ts +19 -0
  16. package/src/constants/logTaxonomy.generated.ts +1103 -0
  17. package/src/constants/noteDoc.ts +77 -0
  18. package/src/constants/organization.ts +18 -11
  19. package/src/constants/pageRoute.ts +23 -0
  20. package/src/constants/schedule.ts +220 -0
  21. package/src/constants/scheduleRuleTemplateSeed.ts +138 -0
  22. package/src/constants/scheduleRuleTemplates.generated.ts +145 -0
  23. package/src/constants/sheet.ts +168 -0
  24. package/src/constants/sheetRegionSources.generated.ts +578 -0
  25. package/src/constants/square.ts +16 -0
  26. package/src/constants/storage.ts +61 -0
  27. package/src/constants/usage.ts +79 -0
  28. package/src/schemas/editLogEntry.ts +1017 -738
  29. package/src/schemas/fieldDocsQuery.ts +12 -0
  30. package/src/schemas/inboundContact.ts +77 -0
  31. package/src/schemas/logsQuery.ts +57 -316
  32. package/src/schemas/organization.ts +53 -213
  33. package/src/types/account.d.ts +81 -0
  34. package/src/types/agentDoc.d.ts +64 -0
  35. package/src/types/agentMemory.d.ts +74 -0
  36. package/src/types/campaign.d.ts +683 -0
  37. package/src/types/dataTable.d.ts +366 -0
  38. package/src/types/docAccess.d.ts +96 -0
  39. package/src/types/email.d.ts +142 -0
  40. package/src/types/fieldDoc.d.ts +273 -0
  41. package/src/types/inboundContact.d.ts +57 -0
  42. package/src/types/integration.d.ts +42 -0
  43. package/src/types/log.d.ts +169 -190
  44. package/src/types/noteDoc.d.ts +86 -0
  45. package/src/types/organization.d.ts +175 -76
  46. package/src/types/pageRoute.d.ts +48 -0
  47. package/src/types/schedule.d.ts +391 -0
  48. package/src/types/sheet.d.ts +1130 -0
  49. package/src/types/storage.d.ts +242 -0
  50. package/src/types/usage.d.ts +106 -0
  51. package/src/types/workflow.d.ts +305 -0
  52. package/src/utils/agentDoc.ts +109 -0
  53. package/src/utils/aiChat.ts +26 -0
  54. package/src/utils/campaign.ts +741 -0
  55. package/src/utils/campaignFormEditor.ts +871 -0
  56. package/src/utils/dataTable.ts +849 -0
  57. package/src/utils/dataTableFieldTypeRegistry.ts +105 -0
  58. package/src/utils/dataTableRealtimeAuthority.ts +209 -0
  59. package/src/utils/dataTableRealtimeSelection.ts +134 -0
  60. package/src/utils/dataTableRowDocument.ts +508 -0
  61. package/src/utils/dataTableSource.ts +230 -0
  62. package/src/utils/docAccess.ts +383 -0
  63. package/src/utils/documentName.ts +53 -0
  64. package/src/utils/email.ts +172 -0
  65. package/src/utils/fieldDoc.ts +113 -0
  66. package/src/utils/log.ts +173 -778
  67. package/src/utils/logRegistryValue.ts +90 -0
  68. package/src/utils/logStoreRead.ts +266 -0
  69. package/src/utils/logTaxonomy.ts +76 -0
  70. package/src/utils/logTaxonomyDisplay.ts +439 -0
  71. package/src/utils/noteDoc.ts +827 -0
  72. package/src/utils/organization.ts +683 -81
  73. package/src/utils/pageRoute.ts +71 -0
  74. package/src/utils/schedule.ts +799 -0
  75. package/src/utils/scheduleEvaluation.ts +1994 -0
  76. package/src/utils/scheduleICS.ts +246 -0
  77. package/src/utils/scheduleRuleTemplates.ts +188 -0
  78. package/src/utils/sheet.ts +4973 -0
  79. package/src/utils/sheetAxisMove.ts +830 -0
  80. package/src/utils/sheetBootstrap.ts +1769 -0
  81. package/src/utils/sheetCommand.ts +423 -0
  82. package/src/utils/sheetExport.ts +238 -0
  83. package/src/utils/sheetFormulaEvaluation.ts +914 -0
  84. package/src/utils/sheetFormulaEvaluator.ts +852 -0
  85. package/src/utils/sheetJournal.ts +78 -0
  86. package/src/utils/sheetNumberFormat.ts +1211 -0
  87. package/src/utils/sheetRegion.ts +374 -0
  88. package/src/utils/sheetRegionFilter.ts +1259 -0
  89. package/src/utils/sheetRegionSourceRegistry.ts +594 -0
  90. package/src/utils/sheetSequence.ts +148 -0
  91. package/src/utils/sheetSnapshot.ts +992 -0
  92. package/src/utils/sheetStructureEdit.ts +1284 -0
  93. package/src/utils/square.ts +32 -0
  94. package/src/utils/storage.ts +152 -0
  95. package/src/utils/table-route.ts +262 -0
  96. package/src/utils/workflow.ts +380 -0
  97. package/tests/dataTableFieldTypeRegistry.test.ts +110 -0
  98. package/tests/docAccess.test.ts +525 -0
  99. package/tests/editLogEntry.test.ts +112 -0
  100. package/tests/noteDoc.test.ts +669 -0
  101. package/tests/schedule.test.ts +693 -0
  102. package/tests/scheduleEvaluation.test.ts +1970 -0
  103. package/tests/scheduleICS.test.ts +208 -0
  104. package/tests/scheduleRuleTemplates.test.ts +176 -0
  105. package/tests/scheduleSweepInvariants.test.ts +428 -0
  106. package/tests/sheetAxisMove.test.ts +343 -0
  107. package/tests/sheetFormulaEvaluator.test.ts +575 -0
  108. package/tests/sheetRegionFilter.test.ts +1135 -0
  109. package/tests/sheetSequence.test.ts +41 -0
  110. package/tests/sheetStructureEdit.test.ts +82 -0
  111. package/tsconfig.json +12 -0
  112. package/vitest.config.ts +8 -0
  113. package/src/constants/log-activityTexts.ts +0 -209
  114. package/src/constants/product.ts +0 -66
  115. package/src/constants/report.ts +0 -25
  116. package/src/schemas/childOrganizationsQuery.ts +0 -44
  117. package/src/schemas/productsQuery.ts +0 -145
  118. package/src/schemas/reportsQuery.ts +0 -107
  119. package/src/types/action.d.ts +0 -42
  120. package/src/types/product.d.ts +0 -173
  121. package/src/types/report.d.ts +0 -203
  122. package/src/utils/product-calEvent.ts +0 -508
  123. package/src/utils/route-helpers.ts +0 -583
@@ -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 ADDED
@@ -0,0 +1,12 @@
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/**/*"]
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,209 +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
- TRANSPLANTING: 'transplanting crops',
21
- SEED_COMPLIANCE_NOTE: 'seed compliance notes',
22
- OTHER_TRANSPLANT_ACTIVITY: 'other seeding or transplanting activities',
23
-
24
- // # Field activities
25
- PREPARE_SOIL: 'soil, beds preparation',
26
- IRRIGATION: 'irrigation management',
27
- FERTILIZATION_COMPOST: 'fertilization, compost application',
28
- PROTECT_CROP: 'hand pulling weed, hoeing, and cultivation work',
29
- MONITOR_CROP: 'crop monitoring',
30
- PRUNING: 'pruning',
31
- STRUCTURE_MAINTENANCE: 'trellising, structure maintenance',
32
- PREPARE_HARVEST: 'preparing crops for harvest',
33
- OTHER_FIELD_ACTIVITY: 'other field activities or farm operation notes',
34
-
35
- // # Harvest activities
36
- HARVEST_CROP: 'harvesting crops',
37
- HARVEST_COUNT: 'counting, weighing harvested crops',
38
- SORT_GRADE: 'sorting, grading crops',
39
- YIELD_LOSS_ESTIMATE: 'estimating yield or loss',
40
- OTHER_HARVEST_ACTIVITY: 'other harvest activities',
41
-
42
- // # Post-harvest activities
43
- POST_HARVEST_HANDLING: 'washing, drying, trimming, sorting, or grading produce',
44
- POST_HARVEST_PACKAGING: 'packaging, cooling, or moving produce to storage',
45
- OTHER_POST_HARVEST_ACTIVITY: 'other post-harvest activities such as cleaning, storage, and maintenance',
46
- };
47
-
48
- export const ARABLE_TRANSACTIONS_TO_TEXT = {
49
- // # Seed purchase activities
50
- SEED_PURCHASE_INFO: 'seed purchase',
51
- OTHER_SUPPLY_PURCHASE_ACTIVITY: 'other supply purchase',
52
-
53
- // # Sales activities
54
- SALE_PRODUCE_ORDER: 'purchase order (produce)',
55
- OTHER_SALE_ORDER: 'purchase order (other)',
56
- };
57
-
58
- export const ARABLE_SEED_TO_SALE_TO_TEXT = {
59
- COLD_STORAGE_TEMPERATURE: 'checking or changing temperature (cold storage)',
60
- ...ARABLE_TRANSACTIONS_TO_TEXT,
61
- ...ARABLE_FARMING_TO_TEXT,
62
- ...WATER_TESTING_ACTIVITY_TO_TEXT,
63
- };
64
-
65
- // Food Safety is separate from arable farming
66
-
67
- export const ARABLE_FOOD_SAFETY_TO_TEXT = {
68
- // # Hygiene
69
- HYGIENE_PROCEDURE: 'hygiene procedures',
70
- CONTAMINANT_RISK: 'contaminant risk assessment and mitigation (physical, chemical, microbial)',
71
- BODILY_FLUID_CONTAMINATION: 'vomitting/bodily fluid decontamination',
72
- SMOKING_EATING_DRINKING_CONTROL: 'smoking, eating, and drinking control actions',
73
- PPE_USAGE: 'personal protective equipment (PPE) usage',
74
-
75
- // # Sanitation
76
- SANITATION_RISK: 'sanitation risk assessment and mitigation',
77
- SANITATION_CONSTRUCTION_MAINTENANCE: 'sanitation facilities construction, repairs, or maintenance',
78
- SANITATION_CLEANING: 'sanitation facilities cleaning activities',
79
- SANITATION_PEST_CONTROL: 'pest control in sanitation facilities',
80
-
81
- // # Equpiments & Materials
82
- EQUIPMENTS_MATERIALS_RISK: 'Materials, food containers/equipments - safety assessment and mitigation',
83
- EQUIPMENTS_MATERIALS_CLEANING: 'Materials, food containers/equipments - cleaning activities',
84
-
85
- // # Environment & Biosecurity
86
- ENVIRONMENT_RISK: 'environmental food safety risk assessment and mitigation',
87
-
88
- // # Employees
89
- EMPLOYEE_ORIENTATION: 'new employee orientation',
90
- EMPLOYEE_TRAINING: 'employee training',
91
- SICK_EMPLOYEE: 'employee sick report',
92
- EMPLOYEE_INJURED: 'employee injury report',
93
- // All texts for same activity names must be same across all operations
94
- // ie. ARABLE vs FARMERS_MARKET
95
- EMPLOYEE_NOTES: 'notes about an employee',
96
- OPERATION_NOTES: 'general operation notes',
97
- };
98
-
99
- export const ARABLE_ACTIVITIES_TO_TEXT = {
100
- ...ARABLE_SEED_TO_SALE_TO_TEXT,
101
- ...ARABLE_FOOD_SAFETY_TO_TEXT,
102
- };
103
-
104
- /**
105
- * #### #### #### ####
106
- * Farmers Market
107
- * #### #### #### ####
108
- */
109
-
110
- export const FARMERS_MARKET_RECEIPT_TO_TEXT = {
111
- MARKET_CREDIT_RECEIPT: 'market credits, coins, or voucher receipts',
112
- };
113
-
114
- export const FARMERS_MARKET_OPERATION_TO_TEXT = {
115
- MARKET_ATTENDANCE: 'attendance for vendor',
116
- MARKET_LOAD_LIST: 'vendor load list',
117
- VENDOR_NOTES: 'notes about a vendor',
118
- // All texts for same activity names must be same across all operations
119
- // ie. ARABLE vs FARMERS_MARKET
120
- EMPLOYEE_NOTES: 'notes about an employee',
121
- FARMERS_MARKET_NOTES: 'notes about farmers market',
122
- };
123
-
124
- export const FARMERS_MARKET_ACTIVITIES_TO_TEXT = {
125
- ...FARMERS_MARKET_RECEIPT_TO_TEXT,
126
- ...FARMERS_MARKET_OPERATION_TO_TEXT,
127
- };
128
-
129
- /**
130
- * #### #### #### ####
131
- * Livestock ranching
132
- * #### #### #### ####
133
- */
134
-
135
- export const LIVESTOCK_LIFECYCLE_TO_TEXT = {
136
- // # Livestock life cycle
137
- LIVESTOCK_PURCHASE: 'livestock purchase',
138
- LIVESTOCK_BIRTH: 'livestock birth',
139
- LIVESTOCK_REPRODUCTION: 'livestock reproduction',
140
- LIVESTOCK_DEATH: 'livestock death',
141
- OTHER_LIVESTOCK_LIFE_CYCLE_ACTIVITY: 'other livestock life cycle notes',
142
-
143
- // # Livestock tracking
144
- LIVESTOCK_GROUP_TRACKING: 'livestock group tracking/movement based on age or other criteria',
145
- LIVESTOCK_PASTURE_TRACKING: 'livestock pasture tracking/movement', // where they are in pasture
146
- LIVESTOCK_ROTATIONAL_GRAZING: 'livestock rotational grazing/movement',
147
- OTHER_LIVESTOCK_TRACKING_ACTIVITY: 'other livestock tracking notes',
148
-
149
- // # Livestock healthcare
150
- LIVESTOCK_VACCINATION: 'livestock vaccination',
151
- LIVESTOCK_SICK: 'livestock sickness',
152
- LIVESTOCK_INJURY: 'livestock injury',
153
- LIVESTOCK_CULL: 'livestock culling',
154
- LIVESTOCK_TREATMENT: 'livestock treatment and recovery',
155
- OTHER_LIVESTOCK_HEALTHCARE_ACTIVITY: 'other livestock healthcare notes',
156
-
157
- // # Livestock sale
158
- LIVESTOCK_SALE: 'livestock sale',
159
- OTHER_LIVESTOCK_SALE_ACTIVITY: 'other sales activities',
160
- };
161
-
162
- export const LIVESTOCK_RANCH_MANAGEMENT_TO_TEXT = {
163
- // # Ranch management activities
164
- PASTURE_SEEDING: 'pasture seeding',
165
- FENCE_MAINTENANCE: 'fence maintenance and buffer management', // buffer zones/buffer management
166
- WATER_SOURCE_MAINTENANCE: 'water source maintenance',
167
- OTHER_PASTURE_LAND_MANAGEMENT_ACTIVITY: 'other pasture or ranch operation notes',
168
- };
169
-
170
- export const LIVESTOCK_TRANSACTIONS_TO_TEXT = {
171
- // # Supply purchases
172
- FEED_PURCHASE: 'feed purchase',
173
- OTHER_SUPPLY_PURCHASE_ACTIVITY: 'other supply purchase',
174
- };
175
-
176
- export const LIVESTOCK_ACTIVITIES_TO_TEXT = {
177
- ...LIVESTOCK_LIFECYCLE_TO_TEXT,
178
- ...LIVESTOCK_RANCH_MANAGEMENT_TO_TEXT,
179
- ...LIVESTOCK_TRANSACTIONS_TO_TEXT,
180
- };
181
-
182
- /**
183
- * #### #### #### ####
184
- * AI tasks
185
- * #### #### #### ####
186
- */
187
-
188
- export const AI_TASKS_TO_TEXT = {
189
- // NOTE: If updating this, update [functions-aiTasks.ts] too
190
- AI_SEND_MESSAGE: 'message',
191
- AI_REMINDER: 'reminder message',
192
- AI_CHECK_IN: 'check-in message',
193
- AI_SCHEDULED_TASK: 'scheduled task',
194
- };
195
-
196
- /**
197
- * Combine all activity texts;
198
- * NOTE: If one of these Objects have same key and different value,
199
- * That would cause a *huge* problem in the agent functions.
200
- */
201
-
202
- export const AGENT_TEXT_TO_ACTIVITIES: Record<string, string> = Object.fromEntries(
203
- Object.entries({
204
- ...ARABLE_ACTIVITIES_TO_TEXT,
205
- ...FARMERS_MARKET_ACTIVITIES_TO_TEXT,
206
- ...LIVESTOCK_ACTIVITIES_TO_TEXT,
207
- ...AI_TASKS_TO_TEXT,
208
- }).map(([key, value]) => [value, key]),
209
- );
@@ -1,66 +0,0 @@
1
- /**
2
- * Products; all types
3
- */
4
-
5
- export const PRODUCT_TYPES = [
6
- 'LIVESTOCK',
7
- 'CAL_EVENTS',
8
- 'FOOD_SAFETY',
9
- 'GLOBAL_GAP',
10
- ];
11
-
12
- /**
13
- * Product features
14
- */
15
-
16
- export const FEATURES_BY_OPERATION = {
17
- ARABLE: [
18
- 'NORMAL_LOGGING', // First item is always the default
19
- 'FOOD_SAFETY',
20
- 'GLOBAL_GAP',
21
- 'ORGANIC_CERTIFICATION',
22
- ],
23
- FARMERS_MARKET: [
24
- 'NORMAL_LOGGING',
25
- 'CAL_EVENTS',
26
- 'CAL_EVENTS_ATTENDANCE',
27
- 'CAL_EVENTS_LOAD_LIST',
28
- ],
29
- LIVESTOCK: [
30
- 'NORMAL_LOGGING',
31
- 'LIVESTOCK', // DEPRECATED
32
- 'LIVESTOCK_MANAGEMENT',
33
- ],
34
- };
35
-
36
- export const PRODUCT_FEATURES = [
37
- ...FEATURES_BY_OPERATION.ARABLE,
38
- ...FEATURES_BY_OPERATION.FARMERS_MARKET,
39
- ...FEATURES_BY_OPERATION.LIVESTOCK,
40
- ].filter((value, index, self) => self.indexOf(value) === index);
41
-
42
- export const ACTIVITY_TO_FEATURE_MAP = {
43
- CAL_EVENTS_ATTENDANCE: ['MARKET_ATTENDANCE'],
44
- CAL_EVENTS_LOAD_LIST: ['MARKET_LOAD_LIST'],
45
- };
46
-
47
- /**
48
- * Products; Livestock
49
- */
50
-
51
- export const PRODUCT_LIVESTOCK_TYPES = [
52
- 'CATTLE',
53
- 'HORSE',
54
- 'GOAT',
55
- 'SHEEP',
56
- 'POULTRY',
57
- 'PIG',
58
- 'OTHER_LIVESTOCK',
59
- ];
60
-
61
- export const PRODUCT_LIVESTOCK_STATUS = [
62
- 'ALIVE',
63
- 'SICK',
64
- 'SOLD',
65
- 'DECEASED',
66
- ];
@@ -1,25 +0,0 @@
1
- /**
2
- * Reports; all types
3
- */
4
-
5
- export const REPORT_SORT_OPTS = [
6
- 'PERIOD_HAPPENED',
7
- ];
8
-
9
- export const REPORT_TYPES = [
10
- 'GLOBAL_GAP',
11
- 'CLEANING',
12
- 'ORGANIC_CERTIFICATION',
13
- ];
14
-
15
- export const REPORT_ROW_PRESETS = [
16
- 'LABELS',
17
- 'MONTH',
18
- 'BREAK',
19
- 'Q_AND_A',
20
- 'TEXTS',
21
- 'LONG_TEXTS', // Same as "TEXTS" but has a different function in <FileBrowserPlus>
22
- 'HEADINGS',
23
- 'REPORT_STATEMENTS_OVERVIEW',
24
- 'EVIDENCES',
25
- ];
@@ -1,44 +0,0 @@
1
- import type { ChildOrgsFilterArgs, OrganizationOperationEnum } from '../types/organization.d';
2
-
3
- /**
4
- * Create a filter object for productsList() query from the URL search query.
5
- * @param operationType - The organization operation type
6
- * @param searchQuery - The search query string from the URL
7
- * @param otherFiltersObj - Additional filter properties to merge into the result
8
- * @returns ProductsFilterArgs - The filter object to be used in the productsList() query
9
- */
10
-
11
- export function getChildOrgsFilterFromURL(
12
- _operationType: OrganizationOperationEnum | null,
13
- searchQuery: string,
14
- otherFiltersObj?: {
15
- withoutPreset?: Partial<ChildOrgsFilterArgs>;
16
- withPreset?: Partial<ChildOrgsFilterArgs>;
17
- }
18
- ) {
19
- if (!searchQuery && otherFiltersObj?.withPreset) {
20
- return otherFiltersObj.withPreset;
21
- } else if (searchQuery === '?preset=none' && otherFiltersObj?.withoutPreset) {
22
- return otherFiltersObj.withoutPreset;
23
- }
24
-
25
- const urlParams = new URLSearchParams(searchQuery);
26
-
27
- // let startDate = urlParams.get('sd');
28
- // let endDate = urlParams.get('ed');
29
- // if (startDate && !endDate) {
30
- // endDate = startDate;
31
- // } else if (endDate && !startDate) {
32
- // startDate = endDate;
33
- // }
34
-
35
- const filter: ChildOrgsFilterArgs = {
36
- // startDate,
37
- // endDate,
38
- // timeZone: indexToTimeZone(urlParams.get('z')),
39
- // query: urlParams.get('q') || '',
40
- ...otherFiltersObj?.withoutPreset,
41
- };
42
-
43
- return filter;
44
- }
@@ -1,145 +0,0 @@
1
- import { PRODUCT_TYPES } from '@jsb188/mday/constants/product';
2
- import type { OrganizationOperationEnum } from '../types/organization.d';
3
- import { z } from 'zod';
4
- import type { ProductsFilterArgs, ProductTypeEnum } from '../types/product.d';
5
-
6
- /**
7
- * Zod schema for query params to filter
8
- */
9
-
10
- export const ProductsFilterSchema = z.object({
11
- preset: z.string()
12
- .optional()
13
- .nullable(),
14
- productType: z.enum(PRODUCT_TYPES as [string]),
15
- // startDate: z.string()
16
- // .refine((sd) => isValidCalDate(sd), { message: 'START_DATE_INVALID' })
17
- // .refine((sd) => !isFutureCalDate(sd, 1), { message: 'START_DATE_FUTURE_NOT_ALLOWED' })
18
- // .nullable(),
19
- // endDate: z.string()
20
- // .refine((ed) => isValidCalDate(ed), { message: 'END_DATE_INVALID' })
21
- // .nullable(),
22
- // timeZone: z.string()
23
- // .refine((tz) => isValidTimeZone(tz), { message: 'INVALID_TIMEZONE' })
24
- // .nullable(),
25
- query: z.string()
26
- .nullable(),
27
- });
28
- // }).refine((data) => {
29
- // if (!data.endDate) {
30
- // // No need to validate if endDate is not provided
31
- // return true;
32
- // } else if (!data.startDate) {
33
- // // If endDate is provided, startDate is required
34
- // return false;
35
- // }
36
- // // End date must be after or equal to start date
37
- // return data.endDate >= data.startDate;
38
- // }, {
39
- // message: 'END_DATE_MUST_BE_AFTER_START_DATE',
40
- // path: ['endDate'], // where to attach the error
41
- // });
42
-
43
- /**
44
- * Convert list of digits to product type enums
45
- * @param digit - Index digit string from URL param
46
- * @returns Array of product type enums or null
47
- */
48
-
49
- export function convertDigitToProductType(digit?: string | null): ProductTypeEnum | null {
50
- if (!digit) {
51
- return null;
52
- }
53
- return PRODUCT_TYPES[Number(digit)] || null;
54
- }
55
-
56
- /**
57
- * Create a filter object for productsList() query from the URL search query.
58
- * @param operationType - The organization operation type
59
- * @param searchQuery - The search query string from the URL
60
- * @param otherFiltersObj - Additional filter properties to merge into the result
61
- * @returns ProductsFilterArgs - The filter object to be used in the productsList() query
62
- */
63
-
64
- export function getProductsFilterFromURL(
65
- _operationType: OrganizationOperationEnum | null,
66
- searchQuery: string,
67
- otherFiltersObj?: {
68
- withoutPreset?: Partial<ProductsFilterArgs>,
69
- withPreset?: Partial<ProductsFilterArgs>
70
- }
71
- ) {
72
- if (!searchQuery && otherFiltersObj?.withPreset) {
73
- return otherFiltersObj.withPreset;
74
- } else if (searchQuery === '?preset=none' && otherFiltersObj?.withoutPreset) {
75
- return otherFiltersObj.withoutPreset;
76
- }
77
-
78
- const urlParams = new URLSearchParams(searchQuery);
79
-
80
- // let startDate = urlParams.get('sd');
81
- // let endDate = urlParams.get('ed');
82
- // if (startDate && !endDate) {
83
- // endDate = startDate;
84
- // } else if (endDate && !startDate) {
85
- // startDate = endDate;
86
- // }
87
-
88
- const filter: ProductsFilterArgs = {
89
- productType: convertDigitToProductType(urlParams.get('t'))!,
90
- // startDate,
91
- // endDate,
92
- // timeZone: indexToTimeZone(urlParams.get('z')),
93
- query: urlParams.get('q') || '',
94
- ...otherFiltersObj?.withoutPreset,
95
- };
96
-
97
- const validation = ProductsFilterSchema.safeParse(filter);
98
-
99
- // console.log(otherFiltersObj);
100
- // console.log('filter', filter);
101
- // console.log('validation', validation);
102
-
103
- if (!validation.success) {
104
- // console.log('validation error', validation.error);
105
- // Return null and force the client to go to a valid page
106
- return null;
107
- }
108
-
109
- return filter;
110
- }
111
-
112
- /**
113
- * Test if URL search query is valid against actual filter object
114
- */
115
-
116
- export function productsSearchQueryIsValid(
117
- searchQuery: string,
118
- filter: ProductsFilterArgs | null
119
- ) {
120
- if (!filter) {
121
- return !searchQuery; // If no filter, searchQuery must be empty to be valid
122
- } else if (!searchQuery || searchQuery === '?preset=none') {
123
- return true; // If no searchQuery, any filter is valid
124
- }
125
-
126
- const urlParams = new URLSearchParams(searchQuery);
127
- // const operation = urlParams.get('o');
128
- const productType = urlParams.get('t');
129
- // const accountId = urlParams.get('a');
130
- // const startDate = urlParams.get('sd');
131
- // const endDate = urlParams.get('ed');
132
- // const timeZone = urlParams.get('z');
133
- const query = urlParams.get('q');
134
-
135
- return (
136
- // operation is allowed to pass through
137
- // !!filter.operation === !!operation &&
138
- !!filter.productType === !!productType &&
139
- // !!filter.accountId === !!accountId &&
140
- // !!filter.startDate === !!startDate &&
141
- // !!filter.endDate === !!endDate &&
142
- // !!filter.timeZone === !!timeZone &&
143
- !!filter.query === !!query
144
- );
145
- }