@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,208 @@
1
+ import {
2
+ foldICSLine,
3
+ renderScheduleICS,
4
+ } from '@jsb188/mday/utils/scheduleICS.ts';
5
+ import { describe, expect, it } from 'vitest';
6
+
7
+ /*
8
+ * A malformed calendar feed does not error — it shows nothing, in somebody
9
+ * else's calendar app, with no way for us to see why. These cases pin the
10
+ * three details that cause that: line endings, octet-accurate folding, and
11
+ * escaping.
12
+ */
13
+
14
+ const NOW = new Date('2026-08-01T12:00:00Z');
15
+ const LA = 'America/Los_Angeles';
16
+
17
+ function render(
18
+ events: Parameters<typeof renderScheduleICS>[0]['events'],
19
+ timeZone = LA,
20
+ ) {
21
+ return renderScheduleICS({ name: 'My Shifts', timeZone, events }, NOW);
22
+ }
23
+
24
+ const baseEvent = {
25
+ uid: 'occurrence-1@marketday',
26
+ sequence: 1,
27
+ summary: 'Room A opening',
28
+ startAt: new Date('2026-08-03T14:00:00Z'),
29
+ endAt: new Date('2026-08-03T18:00:00Z'),
30
+ };
31
+
32
+ describe('feed structure', () => {
33
+ it('wraps events in a VCALENDAR and ends with CRLF', () => {
34
+ const ics = render([baseEvent]);
35
+
36
+ expect(ics.startsWith('BEGIN:VCALENDAR\r\n')).toBe(true);
37
+ expect(ics.endsWith('END:VCALENDAR\r\n')).toBe(true);
38
+ expect(ics).toContain('BEGIN:VEVENT\r\n');
39
+ expect(ics).toContain('END:VEVENT\r\n');
40
+ });
41
+
42
+ it('uses CRLF everywhere, never a bare newline', () => {
43
+ const ics = render([baseEvent]);
44
+
45
+ expect(ics.replace(/\r\n/g, '')).not.toContain('\n');
46
+ });
47
+
48
+ it('declares PUBLISH so clients do not treat entries as invitations', () => {
49
+ expect(render([baseEvent])).toContain('METHOD:PUBLISH');
50
+ });
51
+
52
+ it('emits an empty but valid feed when there is nothing scheduled', () => {
53
+ const ics = render([]);
54
+
55
+ expect(ics).toContain('BEGIN:VCALENDAR');
56
+ expect(ics).not.toContain('BEGIN:VEVENT');
57
+ });
58
+ });
59
+
60
+ describe('timed events', () => {
61
+ it('emits UTC instants so no VTIMEZONE is needed', () => {
62
+ const ics = render([baseEvent]);
63
+
64
+ expect(ics).toContain('DTSTART:20260803T140000Z');
65
+ expect(ics).toContain('DTEND:20260803T180000Z');
66
+ expect(ics).not.toContain('BEGIN:VTIMEZONE');
67
+ });
68
+
69
+ it('carries the identity a client needs to replace rather than duplicate', () => {
70
+ const ics = render([{ ...baseEvent, sequence: 4 }]);
71
+
72
+ expect(ics).toContain('UID:occurrence-1@marketday');
73
+ expect(ics).toContain('SEQUENCE:4');
74
+ expect(ics).toContain('DTSTAMP:20260801T120000Z');
75
+ });
76
+
77
+ it('marks a cancelled entry so subscribers see it disappear', () => {
78
+ expect(render([{ ...baseEvent, status: 'CANCELLED' }])).toContain(
79
+ 'STATUS:CANCELLED',
80
+ );
81
+ });
82
+ });
83
+
84
+ describe('all-day events', () => {
85
+ it('uses local DATE values, because a day is a local fact', () => {
86
+ const ics = render([
87
+ {
88
+ ...baseEvent,
89
+ allDay: true,
90
+ // Local midnight in Los Angeles on the 3rd
91
+ startAt: new Date('2026-08-03T07:00:00Z'),
92
+ endAt: new Date('2026-08-04T07:00:00Z'),
93
+ },
94
+ ]);
95
+
96
+ expect(ics).toContain('DTSTART;VALUE=DATE:20260803');
97
+ expect(ics).toContain('DTEND;VALUE=DATE:20260804');
98
+ // A UTC instant here would land the entry on the wrong day for anyone
99
+ // west of Greenwich
100
+ expect(ics).not.toContain('DTSTART:20260803T070000Z');
101
+ });
102
+ });
103
+
104
+ describe('escaping', () => {
105
+ it('escapes the characters that would otherwise truncate a title', () => {
106
+ const ics = render([
107
+ {
108
+ ...baseEvent,
109
+ summary: 'Room A, B; and C \\ D',
110
+ },
111
+ ]);
112
+
113
+ expect(ics).toContain('SUMMARY:Room A\\, B\\; and C \\\\ D');
114
+ });
115
+
116
+ it('escapes newlines inside a note rather than breaking the line', () => {
117
+ const ics = render([
118
+ {
119
+ ...baseEvent,
120
+ description: 'First line\nSecond line',
121
+ },
122
+ ]);
123
+
124
+ expect(ics).toContain('DESCRIPTION:First line\\nSecond line');
125
+ // The literal newline must not have survived into the output
126
+ expect(ics.split('\r\n').some((line) => line === 'Second line')).toBe(
127
+ false,
128
+ );
129
+ });
130
+ });
131
+
132
+ describe('line folding', () => {
133
+ it('leaves a short line alone', () => {
134
+ expect(foldICSLine('SUMMARY:Short')).toBe('SUMMARY:Short');
135
+ });
136
+
137
+ it('folds a long line with a leading space on continuations', () => {
138
+ const folded = foldICSLine(`SUMMARY:${'a'.repeat(200)}`);
139
+ const lines = folded.split('\r\n');
140
+
141
+ expect(lines.length).toBeGreaterThan(1);
142
+ expect(lines[0].length).toBeLessThanOrEqual(75);
143
+ for (const line of lines.slice(1)) {
144
+ expect(line.startsWith(' ')).toBe(true);
145
+ }
146
+ });
147
+
148
+ it('measures the limit in octets, not characters', () => {
149
+ // Each emoji is 4 UTF-8 bytes; folding by string index would allow a
150
+ // line four times over the octet limit
151
+ const folded = foldICSLine(`SUMMARY:${'😀'.repeat(40)}`);
152
+ const encoder = new TextEncoder();
153
+
154
+ for (const line of folded.split('\r\n')) {
155
+ expect(encoder.encode(line).length).toBeLessThanOrEqual(75);
156
+ }
157
+ });
158
+
159
+ it('never splits a multi-byte character across a fold', () => {
160
+ const folded = foldICSLine(`SUMMARY:${'é😀ü'.repeat(30)}`);
161
+
162
+ // A split code point decodes to U+FFFD; its absence proves every
163
+ // boundary landed on a character edge
164
+ expect(folded).not.toContain('�');
165
+ expect(folded.replace(/\r\n /g, '')).toBe(`SUMMARY:${'é😀ü'.repeat(30)}`);
166
+ });
167
+
168
+ it('folds long values inside a rendered feed', () => {
169
+ const ics = render([
170
+ { ...baseEvent, summary: 'Very long shift name '.repeat(20) },
171
+ ]);
172
+ const encoder = new TextEncoder();
173
+
174
+ for (const line of ics.split('\r\n')) {
175
+ expect(encoder.encode(line).length).toBeLessThanOrEqual(75);
176
+ }
177
+ });
178
+ });
179
+
180
+ describe('recurrence export', () => {
181
+ it('emits an RRULE when the feed carries the rule itself', () => {
182
+ const ics = render([
183
+ {
184
+ ...baseEvent,
185
+ recurrence: { freq: 'WEEKLY', interval: 1, byWeekday: [1, 3, 5] },
186
+ },
187
+ ]);
188
+
189
+ expect(ics).toContain('RRULE:FREQ=WEEKLY;BYDAY=MO,WE,FR');
190
+ });
191
+ });
192
+
193
+ describe('refresh hint', () => {
194
+ it('emits both spellings, because Outlook only reads the non-standard one', () => {
195
+ const ics = renderScheduleICS(
196
+ {
197
+ name: 'My Shifts',
198
+ timeZone: LA,
199
+ refreshIntervalMinutes: 60,
200
+ events: [],
201
+ },
202
+ NOW,
203
+ );
204
+
205
+ expect(ics).toContain('REFRESH-INTERVAL;VALUE=DURATION:PT60M');
206
+ expect(ics).toContain('X-PUBLISHED-TTL:PT60M');
207
+ });
208
+ });
@@ -0,0 +1,176 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { SCHEDULE_RULE_TEMPLATE_DEFAULTS } from '../src/constants/scheduleRuleTemplates.generated.ts';
3
+ import type { ScheduleRuleTemplateObj } from '../src/types/schedule.d.ts';
4
+ import {
5
+ getScheduleRuleTemplateLookupKey,
6
+ getScheduleViolationMessage,
7
+ renderScheduleRuleTemplateMessage,
8
+ resolveScheduleRuleTemplate,
9
+ } from '../src/utils/scheduleRuleTemplates.ts';
10
+
11
+ /*
12
+ * Build one organization-scoped override for the resolution tests.
13
+ */
14
+
15
+ function buildOverride(
16
+ overrides: Partial<ScheduleRuleTemplateObj>,
17
+ ): ScheduleRuleTemplateObj {
18
+ return {
19
+ kind: 'REQUIRED_COUNT',
20
+ key: 'STAFF_MINIMUM',
21
+ label: 'Infant room minimum',
22
+ description: null,
23
+ messageTemplate: 'Infant room is {shortfall} teacher short.',
24
+ defaultConfig: {},
25
+ defaultSeverity: 'BLOCK',
26
+ ordinal: 10,
27
+ ...overrides,
28
+ };
29
+ }
30
+
31
+ describe('renderScheduleRuleTemplateMessage', () => {
32
+ it('fills tokens from the violation detail', () => {
33
+ expect(
34
+ renderScheduleRuleTemplateMessage(
35
+ '{slotKey} is {shortfall} short — {actual} of {required} assigned.',
36
+ {
37
+ slotKey: 'Infant room',
38
+ shortfall: 1,
39
+ actual: 1,
40
+ required: 2,
41
+ },
42
+ ),
43
+ ).toBe('Infant room is 1 short — 1 of 2 assigned.');
44
+ });
45
+
46
+ it('renders an unknown token as an em dash rather than leaving it in place', () => {
47
+ // A scheduler reading "{shortfall} short" cannot tell whether the number
48
+ // is missing or the rule is broken
49
+ expect(renderScheduleRuleTemplateMessage('{shortfall} short', {})).toBe(
50
+ '— short',
51
+ );
52
+ expect(renderScheduleRuleTemplateMessage('{shortfall} short', null)).toBe(
53
+ '— short',
54
+ );
55
+ });
56
+
57
+ it('trims float noise out of rolling totals', () => {
58
+ expect(
59
+ renderScheduleRuleTemplateMessage('{total}h worked', {
60
+ total: 37.470000000000006,
61
+ }),
62
+ ).toBe('37.47h worked');
63
+ });
64
+
65
+ it('renders an array token as its length', () => {
66
+ expect(
67
+ renderScheduleRuleTemplateMessage('{occurrenceIds} booked', {
68
+ occurrenceIds: ['1', '2', '3'],
69
+ }),
70
+ ).toBe('3 booked');
71
+ });
72
+
73
+ it('leaves non-token braces alone', () => {
74
+ expect(renderScheduleRuleTemplateMessage('{ not a token }', { a: 1 })).toBe(
75
+ '{ not a token }',
76
+ );
77
+ });
78
+ });
79
+
80
+ describe('resolveScheduleRuleTemplate', () => {
81
+ it('prefers an organization override over the platform default', () => {
82
+ const organizationTemplates = {
83
+ [getScheduleRuleTemplateLookupKey('REQUIRED_COUNT', 'STAFF_MINIMUM')]:
84
+ buildOverride({}),
85
+ };
86
+
87
+ const resolved = resolveScheduleRuleTemplate(
88
+ 'REQUIRED_COUNT',
89
+ 'STAFF_MINIMUM',
90
+ { organizationTemplates },
91
+ );
92
+
93
+ expect(resolved?.messageTemplate).toBe(
94
+ 'Infant room is {shortfall} teacher short.',
95
+ );
96
+ });
97
+
98
+ it('falls back to the platform default when no override exists', () => {
99
+ const resolved = resolveScheduleRuleTemplate(
100
+ 'REQUIRED_COUNT',
101
+ 'STAFF_MINIMUM',
102
+ );
103
+
104
+ expect(resolved).toEqual(
105
+ SCHEDULE_RULE_TEMPLATE_DEFAULTS['REQUIRED_COUNT:STAFF_MINIMUM'],
106
+ );
107
+ });
108
+
109
+ it('falls back to the kind when the rule names no template', () => {
110
+ // A hand-written rule still has to say something
111
+ const resolved = resolveScheduleRuleTemplate('RESOURCE_CAPACITY', null);
112
+
113
+ expect(resolved?.kind).toBe('RESOURCE_CAPACITY');
114
+ });
115
+
116
+ it('falls back to the kind when the named template does not exist', () => {
117
+ const resolved = resolveScheduleRuleTemplate(
118
+ 'RESOURCE_CAPACITY',
119
+ 'NO_SUCH_TEMPLATE',
120
+ );
121
+
122
+ expect(resolved?.kind).toBe('RESOURCE_CAPACITY');
123
+ });
124
+
125
+ it('picks the lowest-ordinal template of a kind that has several', () => {
126
+ // ACTOR_WINDOW_AGGREGATE seeds both a weekly cap and a rest rule
127
+ const resolved = resolveScheduleRuleTemplate(
128
+ 'ACTOR_WINDOW_AGGREGATE',
129
+ null,
130
+ );
131
+
132
+ expect(resolved?.key).toBe('MAX_HOURS_PER_WEEK');
133
+ });
134
+
135
+ it('returns null for a kind nothing is registered for', () => {
136
+ expect(resolveScheduleRuleTemplate('NOT_A_KIND', null)).toBeNull();
137
+ });
138
+ });
139
+
140
+ describe('getScheduleViolationMessage', () => {
141
+ it('renders a violation in the organization own language', () => {
142
+ const organizationTemplates = {
143
+ [getScheduleRuleTemplateLookupKey('REQUIRED_COUNT', 'STAFF_MINIMUM')]:
144
+ buildOverride({}),
145
+ };
146
+
147
+ const message = getScheduleViolationMessage(
148
+ {
149
+ kind: 'REQUIRED_COUNT',
150
+ templateKey: 'STAFF_MINIMUM',
151
+ detail: { shortfall: 2 },
152
+ },
153
+ { organizationTemplates },
154
+ );
155
+
156
+ expect(message).toBe('Infant room is 2 teacher short.');
157
+ });
158
+
159
+ it('renders the platform wording when the organization has no override', () => {
160
+ const message = getScheduleViolationMessage({
161
+ kind: 'REQUIRED_COUNT',
162
+ templateKey: 'STAFF_MINIMUM',
163
+ detail: { slotKey: 'Front desk', shortfall: 1, actual: 0, required: 1 },
164
+ });
165
+
166
+ expect(message).toBe('Front desk is 1 short — 0 of 1 assigned.');
167
+ });
168
+
169
+ it('returns null rather than an empty string when nothing is registered', () => {
170
+ // The caller falls back to its own generic copy; an empty violation row
171
+ // would read as "no problem here"
172
+ expect(
173
+ getScheduleViolationMessage({ kind: 'NOT_A_KIND', detail: {} }),
174
+ ).toBeNull();
175
+ });
176
+ });