@jsb188/mday 1.1.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.
Files changed (202) hide show
  1. package/package.json +142 -0
  2. package/src/constants/agentMemory.ts +166 -0
  3. package/src/constants/agentNote.ts +212 -0
  4. package/src/constants/aiChat.ts +10 -0
  5. package/src/constants/billing.ts +126 -0
  6. package/src/constants/campaign.ts +236 -0
  7. package/src/constants/contact.ts +72 -0
  8. package/src/constants/csvExport.ts +133 -0
  9. package/src/constants/dataTable.ts +22 -0
  10. package/src/constants/dataTableFieldTypes.generated.ts +59 -0
  11. package/src/constants/docAccess.ts +33 -0
  12. package/src/constants/dt.ts +234 -0
  13. package/src/constants/email.ts +146 -0
  14. package/src/constants/fieldDoc.ts +104 -0
  15. package/src/constants/graphqlReactivity.ts +196 -0
  16. package/src/constants/inboundContact.ts +8 -0
  17. package/src/constants/integration.ts +13 -0
  18. package/src/constants/log.ts +21 -0
  19. package/src/constants/logDisplay/README.md +88 -0
  20. package/src/constants/logDisplay/defaults.ts +39 -0
  21. package/src/constants/logDisplay/index.ts +27 -0
  22. package/src/constants/logDisplay/operations/arable.ts +16 -0
  23. package/src/constants/logDisplay/operations/farmersMarket.ts +10 -0
  24. package/src/constants/logDisplay/operations/foodManufacturing.ts +13 -0
  25. package/src/constants/logDisplay/shared/accounting.ts +13 -0
  26. package/src/constants/logDisplay/shared/interactions.ts +13 -0
  27. package/src/constants/logDisplay/shared/rackTemperatures.ts +42 -0
  28. package/src/constants/logTaxonomy.generated.ts +2199 -0
  29. package/src/constants/noteDoc.ts +77 -0
  30. package/src/constants/organization.ts +60 -0
  31. package/src/constants/pageRoute.ts +23 -0
  32. package/src/constants/qrCode.ts +30 -0
  33. package/src/constants/sheet.ts +132 -0
  34. package/src/constants/sms.ts +18 -0
  35. package/src/constants/square.ts +16 -0
  36. package/src/constants/storage.ts +85 -0
  37. package/src/constants/usage.ts +82 -0
  38. package/src/constants/workflowSteps.ts +60 -0
  39. package/src/schemas/editLogEntry.ts +879 -0
  40. package/src/schemas/inboundContact.ts +77 -0
  41. package/src/schemas/logsQuery.ts +93 -0
  42. package/src/types/account.d.ts +81 -0
  43. package/src/types/agentMemory.d.ts +100 -0
  44. package/src/types/agentNote.d.ts +441 -0
  45. package/src/types/billing.d.ts +537 -0
  46. package/src/types/campaign.d.ts +1533 -0
  47. package/src/types/contact.d.ts +15 -0
  48. package/src/types/csvExport.d.ts +213 -0
  49. package/src/types/dataAnalysis.d.ts +44 -0
  50. package/src/types/dataTable.d.ts +159 -0
  51. package/src/types/definitionElement.d.ts +35 -0
  52. package/src/types/docAccess.d.ts +96 -0
  53. package/src/types/dt.d.ts +257 -0
  54. package/src/types/email.d.ts +231 -0
  55. package/src/types/emailReplyReport.d.ts +76 -0
  56. package/src/types/fieldDoc.d.ts +702 -0
  57. package/src/types/fieldDocContract.d.ts +90 -0
  58. package/src/types/inboundContact.d.ts +65 -0
  59. package/src/types/integration.d.ts +42 -0
  60. package/src/types/log.d.ts +338 -0
  61. package/src/types/logDisplay.types.ts +85 -0
  62. package/src/types/organization.d.ts +350 -0
  63. package/src/types/pageRoute.d.ts +48 -0
  64. package/src/types/qrCode.d.ts +96 -0
  65. package/src/types/richText.d.ts +81 -0
  66. package/src/types/sheet.d.ts +847 -0
  67. package/src/types/sms.d.ts +38 -0
  68. package/src/types/storage.d.ts +481 -0
  69. package/src/types/usage.d.ts +106 -0
  70. package/src/types/workflow.d.ts +435 -0
  71. package/src/utils/agentMemory.ts +15 -0
  72. package/src/utils/agentNote.ts +850 -0
  73. package/src/utils/aiChat.ts +43 -0
  74. package/src/utils/aiChatWork.ts +64 -0
  75. package/src/utils/billing.ts +37 -0
  76. package/src/utils/campaign.ts +1173 -0
  77. package/src/utils/campaignAI.ts +72 -0
  78. package/src/utils/campaignAccess.ts +239 -0
  79. package/src/utils/campaignEmail.ts +601 -0
  80. package/src/utils/campaignEmailCompiler.ts +372 -0
  81. package/src/utils/campaignEmailImages.ts +60 -0
  82. package/src/utils/campaignEmailStyles.ts +544 -0
  83. package/src/utils/campaignLifecycle.ts +104 -0
  84. package/src/utils/campaignPreview.ts +285 -0
  85. package/src/utils/contact.ts +50 -0
  86. package/src/utils/csvExport.ts +19 -0
  87. package/src/utils/dataTable.ts +311 -0
  88. package/src/utils/dataTableFieldTypeRegistry.ts +106 -0
  89. package/src/utils/dataTableRelativeDate.ts +447 -0
  90. package/src/utils/definitionElement.ts +84 -0
  91. package/src/utils/docAccess.ts +383 -0
  92. package/src/utils/documentName.ts +53 -0
  93. package/src/utils/email.ts +379 -0
  94. package/src/utils/emailReplyReport.test.ts +187 -0
  95. package/src/utils/emailReplyReport.ts +143 -0
  96. package/src/utils/fieldDoc.ts +157 -0
  97. package/src/utils/fieldDocAnswers.ts +128 -0
  98. package/src/utils/fieldDocDefaults.ts +36 -0
  99. package/src/utils/fieldDocProgram.ts +36 -0
  100. package/src/utils/fieldDocSummary.ts +30 -0
  101. package/src/utils/log.ts +357 -0
  102. package/src/utils/logDisplay.helpers.ts +177 -0
  103. package/src/utils/logDisplay.ts +87 -0
  104. package/src/utils/logRegistryValue.ts +90 -0
  105. package/src/utils/logStoreRead.ts +262 -0
  106. package/src/utils/logTaxonomy.helpers.ts +17 -0
  107. package/src/utils/logTaxonomy.ts +76 -0
  108. package/src/utils/logTaxonomyDisplay.ts +395 -0
  109. package/src/utils/noteDoc.ts +609 -0
  110. package/src/utils/organization.ts +669 -0
  111. package/src/utils/pageRoute.ts +71 -0
  112. package/src/utils/qrCode.helpers.ts +189 -0
  113. package/src/utils/qrCode.test.ts +519 -0
  114. package/src/utils/qrCode.ts +273 -0
  115. package/src/utils/richTextHTML.ts +385 -0
  116. package/src/utils/sheet.ts +262 -0
  117. package/src/utils/sheetAxisMove.ts +616 -0
  118. package/src/utils/sheetBootstrap.ts +1402 -0
  119. package/src/utils/sheetCellLiteral.ts +101 -0
  120. package/src/utils/sheetCommand.ts +358 -0
  121. package/src/utils/sheetDesign.ts +705 -0
  122. package/src/utils/sheetExport.ts +186 -0
  123. package/src/utils/sheetFeatureReference.ts +183 -0
  124. package/src/utils/sheetFormulaArgs.ts +168 -0
  125. package/src/utils/sheetFormulaCompile.ts +475 -0
  126. package/src/utils/sheetFormulaConditionalAggregate.ts +254 -0
  127. package/src/utils/sheetFormulaCriteria.ts +656 -0
  128. package/src/utils/sheetFormulaDate.ts +444 -0
  129. package/src/utils/sheetFormulaEvaluation.ts +899 -0
  130. package/src/utils/sheetFormulaEvaluator.ts +997 -0
  131. package/src/utils/sheetFormulaFunctionHandlers.ts +403 -0
  132. package/src/utils/sheetFormulaLogical.ts +116 -0
  133. package/src/utils/sheetFormulaLookup.ts +488 -0
  134. package/src/utils/sheetFormulaMath.ts +48 -0
  135. package/src/utils/sheetFormulaParser.ts +729 -0
  136. package/src/utils/sheetFormulaRange.ts +330 -0
  137. package/src/utils/sheetFormulaReference.ts +703 -0
  138. package/src/utils/sheetFormulaReferenceAggregates.ts +313 -0
  139. package/src/utils/sheetFormulaReferenceDates.ts +237 -0
  140. package/src/utils/sheetFormulaReferenceLogical.ts +330 -0
  141. package/src/utils/sheetFormulaReferenceLookup.ts +341 -0
  142. package/src/utils/sheetFormulaReferenceMath.ts +95 -0
  143. package/src/utils/sheetFormulaReferenceRewrite.ts +220 -0
  144. package/src/utils/sheetFormulaReferenceText.ts +462 -0
  145. package/src/utils/sheetFormulaSyntax.ts +1027 -0
  146. package/src/utils/sheetFormulaText.ts +430 -0
  147. package/src/utils/sheetJournal.ts +200 -0
  148. package/src/utils/sheetNumberFormat.ts +1012 -0
  149. package/src/utils/sheetPreview.ts +68 -0
  150. package/src/utils/sheetSequence.ts +118 -0
  151. package/src/utils/sheetSnapshot.ts +739 -0
  152. package/src/utils/sheetStructureEdit.ts +914 -0
  153. package/src/utils/sheetStructureReferences.ts +389 -0
  154. package/src/utils/square.ts +32 -0
  155. package/src/utils/storage.ts +198 -0
  156. package/src/utils/table-route.ts +262 -0
  157. package/src/utils/time.ts +12 -0
  158. package/src/utils/workflow.ts +506 -0
  159. package/src/utils/workflowLogFingerprint.ts +302 -0
  160. package/src/utils/workflowLogRevisionSnapshot.ts +424 -0
  161. package/src/utils/workflowProgress.ts +280 -0
  162. package/src/utils/workflowTriggers.ts +61 -0
  163. package/tests/agentNote.test.ts +395 -0
  164. package/tests/campaignAI.test.ts +119 -0
  165. package/tests/campaignAccess.test.ts +239 -0
  166. package/tests/campaignEmail.test.ts +441 -0
  167. package/tests/campaignLifecycle.test.ts +134 -0
  168. package/tests/campaignPublication.test.ts +309 -0
  169. package/tests/dataTableFieldTypeRegistry.test.ts +111 -0
  170. package/tests/dataTableRelativeDate.test.ts +412 -0
  171. package/tests/docAccess.test.ts +525 -0
  172. package/tests/editLogEntry.test.ts +112 -0
  173. package/tests/email.test.ts +39 -0
  174. package/tests/fieldDocProgram.test.ts +114 -0
  175. package/tests/logDisplay.fixtures.ts +67 -0
  176. package/tests/logDisplay.test.ts +227 -0
  177. package/tests/noteDoc.test.ts +514 -0
  178. package/tests/richTextHTML.test.ts +185 -0
  179. package/tests/sheetAxisMove.test.ts +352 -0
  180. package/tests/sheetBootstrap.test.ts +1967 -0
  181. package/tests/sheetFeatureReference.test.ts +22 -0
  182. package/tests/sheetFormulaCriteria.test.ts +269 -0
  183. package/tests/sheetFormulaEvaluator.test.ts +468 -0
  184. package/tests/sheetFormulaFunctions.test.ts +538 -0
  185. package/tests/sheetFormulaLanguage.test.ts +361 -0
  186. package/tests/sheetFormulaParity.fixtures.ts +872 -0
  187. package/tests/sheetFormulaParity.test.ts +188 -0
  188. package/tests/sheetFormulaRange.test.ts +167 -0
  189. package/tests/sheetFormulaReference.test.ts +78 -0
  190. package/tests/sheetFormulaReferenceRewrite.test.ts +117 -0
  191. package/tests/sheetFormulaTextDate.test.ts +512 -0
  192. package/tests/sheetSequence.test.ts +22 -0
  193. package/tests/sheetSnapshot.test.ts +134 -0
  194. package/tests/sheetStructureEdit.test.ts +537 -0
  195. package/tests/sheetStructureReferences.test.ts +589 -0
  196. package/tests/workflowLifecycleStatus.test.ts +60 -0
  197. package/tests/workflowLogFingerprint.test.ts +203 -0
  198. package/tests/workflowLogRevisionSnapshot.test.ts +96 -0
  199. package/tests/workflowProgress.test.ts +180 -0
  200. package/tests/workflowTriggers.test.ts +29 -0
  201. package/tsconfig.json +12 -0
  202. package/vitest.config.ts +8 -0
@@ -0,0 +1,262 @@
1
+ export const TABLE_ROUTE_COLUMN_MIN_WIDTH = 50;
2
+ export const TABLE_ROUTE_COLUMN_MAX_WIDTH = 800;
3
+
4
+ export type TableRouteColumnWidths = Record<string, number>;
5
+ export type TableRouteColumnOrder = string[];
6
+
7
+ export interface OrganizationRouteSettingsObj {
8
+ columnWidths?: TableRouteColumnWidths | null;
9
+ columnOrder?: TableRouteColumnOrder | null;
10
+ }
11
+
12
+ /*
13
+ * Keep a user-resized route table column width inside a practical range.
14
+ */
15
+ export function clampTableRouteColumnWidth(width: number) {
16
+ return Math.min(
17
+ TABLE_ROUTE_COLUMN_MAX_WIDTH,
18
+ Math.max(TABLE_ROUTE_COLUMN_MIN_WIDTH, Math.round(width)),
19
+ );
20
+ }
21
+
22
+ /*
23
+ * Return whether a route table column key can be safely stored in settings JSONB.
24
+ */
25
+ export function isValidTableRouteColumnSettingsKey(
26
+ value: string | null | undefined,
27
+ ) {
28
+ return !!value && /^[A-Za-z0-9_-]+$/.test(value);
29
+ }
30
+
31
+ /*
32
+ * Return whether a table route id can be safely stored in settings JSONB.
33
+ */
34
+ export function isValidTableRouteIdSettingsKey(
35
+ value: string | null | undefined,
36
+ ) {
37
+ return !!value && /^[A-Za-z0-9_-]+(?:\/[A-Za-z0-9_-]+)*$/.test(value);
38
+ }
39
+
40
+ /*
41
+ * Return the app route id used for organization table settings.
42
+ */
43
+ export function getTableRouteIdFromPathname(
44
+ pathname: string,
45
+ fallbackRouteId = 'table',
46
+ ) {
47
+ const segments = pathname.split('/').filter(Boolean);
48
+ const routeSegments = segments[0] === 'app' ? segments.slice(1) : segments;
49
+ const routeId = routeSegments.join('/');
50
+
51
+ return isValidTableRouteIdSettingsKey(routeId) ? routeId : fallbackRouteId;
52
+ }
53
+
54
+ /*
55
+ * Return the route id from an OrgRoute cursor shaped as [organizationId, 0, routeId].
56
+ */
57
+ export function getTableRouteIdFromOrgRouteCursor(
58
+ cursor: string | null | undefined,
59
+ ) {
60
+ const routeId = String(cursor || '').split(':')[2];
61
+
62
+ return isValidTableRouteIdSettingsKey(routeId) ? routeId : null;
63
+ }
64
+
65
+ /*
66
+ * Convert GraphQL OrgRoute column width strings into a keyed width object.
67
+ */
68
+ export function getTableRouteColumnWidthsFromStrings(
69
+ values: string[] | null | undefined,
70
+ ) {
71
+ if (!Array.isArray(values)) {
72
+ return {};
73
+ }
74
+
75
+ const widths: TableRouteColumnWidths = {};
76
+
77
+ for (const value of values) {
78
+ const parts = String(value || '').split(':');
79
+ const [columnKey, widthValue] = parts;
80
+ const width = Number(widthValue);
81
+
82
+ if (
83
+ parts.length !== 2 ||
84
+ !isValidTableRouteColumnSettingsKey(columnKey) ||
85
+ !Number.isFinite(width)
86
+ ) {
87
+ continue;
88
+ }
89
+
90
+ widths[columnKey] = clampTableRouteColumnWidth(width);
91
+ }
92
+
93
+ return widths;
94
+ }
95
+
96
+ /*
97
+ * Convert a keyed column width object into GraphQL OrgRoute width strings.
98
+ */
99
+ export function getTableRouteColumnWidthStrings(
100
+ widths: TableRouteColumnWidths | null | undefined,
101
+ ) {
102
+ if (!widths) {
103
+ return [];
104
+ }
105
+
106
+ return Object.entries(widths).reduce((acc, [columnKey, width]) => {
107
+ if (
108
+ !isValidTableRouteColumnSettingsKey(columnKey) ||
109
+ !Number.isFinite(width)
110
+ ) {
111
+ return acc;
112
+ }
113
+
114
+ acc.push(`${columnKey}:${clampTableRouteColumnWidth(width)}`);
115
+ return acc;
116
+ }, [] as string[]);
117
+ }
118
+
119
+ /*
120
+ * Return a unique ordered column key list from GraphQL route settings values.
121
+ */
122
+ export function getTableRouteColumnOrderFromStrings(
123
+ values: string[] | null | undefined,
124
+ ) {
125
+ if (!Array.isArray(values)) {
126
+ return [];
127
+ }
128
+
129
+ const seenColumnKeys = new Set<string>();
130
+
131
+ return values.reduce((acc, value) => {
132
+ const columnKey = String(value || '');
133
+
134
+ if (
135
+ !isValidTableRouteColumnSettingsKey(columnKey) ||
136
+ seenColumnKeys.has(columnKey)
137
+ ) {
138
+ return acc;
139
+ }
140
+
141
+ seenColumnKeys.add(columnKey);
142
+ acc.push(columnKey);
143
+ return acc;
144
+ }, [] as TableRouteColumnOrder);
145
+ }
146
+
147
+ /*
148
+ * Convert an ordered column key list into GraphQL OrgRoute order strings.
149
+ */
150
+ export function getTableRouteColumnOrderStrings(
151
+ columnOrder: TableRouteColumnOrder | null | undefined,
152
+ ) {
153
+ return getTableRouteColumnOrderFromStrings(columnOrder);
154
+ }
155
+
156
+ /*
157
+ * Return a complete column order from saved keys and the current table design keys.
158
+ */
159
+ export function getTableRouteColumnOrderFromColumnKeys(
160
+ columnKeys: string[],
161
+ columnOrder: TableRouteColumnOrder | null | undefined,
162
+ ) {
163
+ const validColumnKeys = columnKeys.filter(isValidTableRouteColumnSettingsKey);
164
+ const validColumnKeySet = new Set(validColumnKeys);
165
+ const seenColumnKeys = new Set<string>();
166
+ const orderedColumnKeys = getTableRouteColumnOrderFromStrings(
167
+ columnOrder,
168
+ ).reduce((acc, columnKey) => {
169
+ if (!validColumnKeySet.has(columnKey) || seenColumnKeys.has(columnKey)) {
170
+ return acc;
171
+ }
172
+
173
+ seenColumnKeys.add(columnKey);
174
+ acc.push(columnKey);
175
+ return acc;
176
+ }, [] as TableRouteColumnOrder);
177
+
178
+ validColumnKeys.forEach((columnKey) => {
179
+ if (!seenColumnKeys.has(columnKey)) {
180
+ orderedColumnKeys.push(columnKey);
181
+ }
182
+ });
183
+
184
+ return orderedColumnKeys;
185
+ }
186
+
187
+ /*
188
+ * Convert a settings routes object into one GraphQL-friendly route settings list.
189
+ */
190
+ export function getOrganizationSettingsRoutesList(
191
+ routes: Record<string, OrganizationRouteSettingsObj> | null | undefined,
192
+ ) {
193
+ if (!routes) {
194
+ return [];
195
+ }
196
+
197
+ return Object.entries(routes)
198
+ .filter(([routeId]) => isValidTableRouteIdSettingsKey(routeId))
199
+ .map(([routeId, route]) => ({
200
+ routeId,
201
+ columnWidths: route?.columnWidths || {},
202
+ columnOrder: getTableRouteColumnOrderStrings(route?.columnOrder),
203
+ }));
204
+ }
205
+
206
+ /*
207
+ * Return route column widths from GraphQL OrganizationSettings.routes data.
208
+ */
209
+ export function getTableRouteColumnWidthsFromSettingsRoutes(
210
+ routes:
211
+ | { id?: string | null; columnWidths?: string[] | null }[]
212
+ | null
213
+ | undefined,
214
+ routeId: string,
215
+ ) {
216
+ const route = routes?.find(
217
+ (item) => getTableRouteIdFromOrgRouteCursor(item?.id) === routeId,
218
+ );
219
+
220
+ return getTableRouteColumnWidthsFromStrings(route?.columnWidths);
221
+ }
222
+
223
+ /*
224
+ * Return route column order from GraphQL OrganizationSettings.routes data.
225
+ */
226
+ export function getTableRouteColumnOrderFromSettingsRoutes(
227
+ routes:
228
+ | { id?: string | null; columnOrder?: string[] | null }[]
229
+ | null
230
+ | undefined,
231
+ routeId: string,
232
+ ) {
233
+ const route = routes?.find(
234
+ (item) => getTableRouteIdFromOrgRouteCursor(item?.id) === routeId,
235
+ );
236
+
237
+ return getTableRouteColumnOrderFromStrings(route?.columnOrder);
238
+ }
239
+
240
+ /*
241
+ * Keep only local width patches that have not been confirmed by server settings.
242
+ */
243
+ export function removeConfirmedTableRouteColumnWidthPatches(
244
+ localWidths: TableRouteColumnWidths,
245
+ serverWidths: TableRouteColumnWidths,
246
+ ) {
247
+ let nextWidths = localWidths;
248
+
249
+ Object.entries(localWidths).forEach(([columnKey, width]) => {
250
+ if (serverWidths[columnKey] !== width) {
251
+ return;
252
+ }
253
+
254
+ if (nextWidths === localWidths) {
255
+ nextWidths = { ...localWidths };
256
+ }
257
+
258
+ delete nextWidths[columnKey];
259
+ });
260
+
261
+ return nextWidths;
262
+ }
@@ -0,0 +1,12 @@
1
+ /* Recognize a minute-precision local clock time without introducing a date or timezone. */
2
+ export function isCanonicalClockTime(value: unknown): value is string {
3
+ return typeof value === 'string' && value.length === 5 && /^(?:[01]\d|2[0-3]):[0-5]\d$/.test(value);
4
+ }
5
+
6
+ /* Format canonical clock times while retaining invalid historical input visibly for review. */
7
+ export function formatClockTime(value: string, militaryTime = false): string {
8
+ if (!isCanonicalClockTime(value) || militaryTime) return value;
9
+ const [hours, minutes] = value.split(':');
10
+ const hour = Number(hours);
11
+ return `${hour % 12 || 12}:${minutes} ${hour < 12 ? 'AM' : 'PM'}`;
12
+ }