@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,172 @@
1
+ import { convertHTMLToMarkdown } from '../../../@jsb188:react-web/utils/markdown.ts';
2
+ import type { InboundEmailBodyFormatEnum } from '../types/email.d.ts';
3
+
4
+ type PostmarkInboundPayloadLike = {
5
+ HtmlBody?: string | null;
6
+ TextBody?: string | null;
7
+ StrippedTextReply?: string | null;
8
+ };
9
+
10
+ const INBOUND_EMAIL_PAYLOAD_OMIT_KEYS = [
11
+ 'HtmlBody',
12
+ 'Attachments',
13
+ // These keys are server-owned processing metadata, never provider input.
14
+ 'storedAttachments',
15
+ 'queuePublishedAt',
16
+ 'postmasterMutationCheckpoint',
17
+ ];
18
+ const INBOUND_EMAIL_DEFAULT_BODY_LENGTH = 12000;
19
+ const INBOUND_EMAIL_PREVIEW_LENGTH = 240;
20
+
21
+ /**
22
+ * Return a Postmark inbound payload safe to store on the email row.
23
+ */
24
+ export function getInboundEmailPayloadForStorage(payload?: object | null) {
25
+ const storagePayload: Record<string, unknown> = { ...(payload || {}) };
26
+ const hasTextBody =
27
+ typeof storagePayload.TextBody === 'string' && !!storagePayload.TextBody;
28
+ const hasStrippedTextReply =
29
+ typeof storagePayload.StrippedTextReply === 'string' &&
30
+ !!storagePayload.StrippedTextReply;
31
+ const htmlBodyMarkdown = getInboundEmailPayloadHtmlMarkdownText(
32
+ storagePayload as PostmarkInboundPayloadLike,
33
+ );
34
+
35
+ if (!hasTextBody && !hasStrippedTextReply && htmlBodyMarkdown) {
36
+ storagePayload.TextBody = htmlBodyMarkdown;
37
+ }
38
+
39
+ for (const key of INBOUND_EMAIL_PAYLOAD_OMIT_KEYS) {
40
+ delete storagePayload[key];
41
+ }
42
+
43
+ return storagePayload;
44
+ }
45
+
46
+ /**
47
+ * Limit optional Postmark text fields before displaying them.
48
+ */
49
+ export function limitInboundEmailTextValue(
50
+ value: string | null | undefined,
51
+ maxLength: number,
52
+ ): string | null {
53
+ return value ? value.substring(0, maxLength) : null;
54
+ }
55
+
56
+ /**
57
+ * Replace ASCII control characters in provider-owned email metadata.
58
+ */
59
+ export function replaceEmailControlCharacters(
60
+ value: string,
61
+ replacement: string,
62
+ ) {
63
+ return Array.from(value, (character) => {
64
+ const characterCode = character.charCodeAt(0);
65
+ return characterCode <= 31 || characterCode === 127
66
+ ? replacement
67
+ : character;
68
+ }).join('');
69
+ }
70
+
71
+ /**
72
+ * Return one limited Postmark text payload field.
73
+ */
74
+ function getInboundEmailPayloadTextValue(
75
+ payload: PostmarkInboundPayloadLike | null | undefined,
76
+ key: keyof PostmarkInboundPayloadLike,
77
+ maxLength: number,
78
+ ) {
79
+ return limitInboundEmailTextValue(
80
+ typeof payload?.[key] === 'string' ? payload[key] : null,
81
+ maxLength,
82
+ );
83
+ }
84
+
85
+ /**
86
+ * Return markdown converted from one HTML email body.
87
+ */
88
+ function getInboundEmailPayloadHtmlMarkdownText(
89
+ payload?: PostmarkInboundPayloadLike | null,
90
+ maxBodyLength = INBOUND_EMAIL_DEFAULT_BODY_LENGTH,
91
+ ) {
92
+ return limitInboundEmailTextValue(
93
+ typeof payload?.HtmlBody === 'string'
94
+ ? convertHTMLToMarkdown(payload.HtmlBody)
95
+ : null,
96
+ maxBodyLength,
97
+ );
98
+ }
99
+
100
+ /**
101
+ * Return the preferred raw text source from a saved inbound email payload.
102
+ */
103
+ export function getInboundEmailPayloadTextBody(
104
+ payload?: PostmarkInboundPayloadLike | null,
105
+ maxBodyLength = INBOUND_EMAIL_DEFAULT_BODY_LENGTH,
106
+ ): string | null {
107
+ return (
108
+ getInboundEmailPayloadTextValue(
109
+ payload,
110
+ 'StrippedTextReply',
111
+ maxBodyLength,
112
+ ) ||
113
+ getInboundEmailPayloadTextValue(payload, 'TextBody', maxBodyLength) ||
114
+ getInboundEmailPayloadHtmlMarkdownText(payload, maxBodyLength)
115
+ );
116
+ }
117
+
118
+ /**
119
+ * Return role-safe plain text for an inbound email agent message. Campaign
120
+ * replies never fall back to TextBody because it can contain the quoted
121
+ * organization-authored campaign that belongs in the assistant message.
122
+ */
123
+ export function getInboundEmailAgentBodyText(
124
+ payload: PostmarkInboundPayloadLike | null | undefined,
125
+ options: { campaignReply: boolean },
126
+ maxBodyLength = INBOUND_EMAIL_DEFAULT_BODY_LENGTH,
127
+ ): string {
128
+ const strippedReply =
129
+ typeof payload?.StrippedTextReply === 'string'
130
+ ? payload.StrippedTextReply.trim()
131
+ : '';
132
+ const textBody =
133
+ !options.campaignReply && typeof payload?.TextBody === 'string'
134
+ ? payload.TextBody.trim()
135
+ : '';
136
+
137
+ return (strippedReply || textBody).substring(0, maxBodyLength);
138
+ }
139
+
140
+ /**
141
+ * Return the display body format derived from a saved inbound email payload.
142
+ */
143
+ export function getInboundEmailBodyFormat(
144
+ payload?: PostmarkInboundPayloadLike | null,
145
+ ): InboundEmailBodyFormatEnum | null {
146
+ if (getInboundEmailPayloadTextBody(payload)) {
147
+ return 'TEXT';
148
+ }
149
+
150
+ return null;
151
+ }
152
+
153
+ /**
154
+ * Return the display body text derived from a saved inbound email payload.
155
+ */
156
+ export function getInboundEmailBodyText(
157
+ payload?: PostmarkInboundPayloadLike | null,
158
+ maxBodyLength = INBOUND_EMAIL_DEFAULT_BODY_LENGTH,
159
+ ): string {
160
+ return getInboundEmailPayloadTextBody(payload, maxBodyLength) || '';
161
+ }
162
+
163
+ /**
164
+ * Return a compact preview text derived from a saved inbound email payload.
165
+ */
166
+ export function getInboundEmailPreviewText(
167
+ payload?: PostmarkInboundPayloadLike | null,
168
+ ): string {
169
+ return getInboundEmailBodyText(payload, INBOUND_EMAIL_PREVIEW_LENGTH)
170
+ .replace(/\s+/g, ' ')
171
+ .trim();
172
+ }
@@ -0,0 +1,113 @@
1
+ import type { LogEntryGQL } from '@jsb188/mday/types/log.d.ts';
2
+ import type {
3
+ FieldDocElementData,
4
+ FieldDocElementGQL,
5
+ } from '@jsb188/mday/types/fieldDoc.d.ts';
6
+ import type { StorageGQL } from '@jsb188/mday/types/storage.d.ts';
7
+ import {
8
+ DOMAIN_TO_INBOX,
9
+ FIELD_DOC_REPLY_TO_AGENT_DOMAINS,
10
+ } from '@jsb188/app/constants/agent.ts';
11
+ import { isEmail } from '@jsb188/app/utils/string.ts';
12
+ import { FIELD_DOC_QUESTION_ELEMENT_KINDS } from '../constants/fieldDoc.ts';
13
+
14
+ /*
15
+ * Check whether one fieldDoc element holds an answerable question key.
16
+ */
17
+
18
+ export function isFieldDocQuestionElement(
19
+ element?: Pick<FieldDocElementData | FieldDocElementGQL, 'kind'> | null,
20
+ ): boolean {
21
+ return !!element && FIELD_DOC_QUESTION_ELEMENT_KINDS.includes(element.kind);
22
+ }
23
+
24
+ /*
25
+ * Map one outbound route type to its campaign query kind.
26
+ */
27
+ /*
28
+ * Build one fieldDoc line number from the numbered group index and the
29
+ * item index inside that group.
30
+ */
31
+
32
+ export function getFieldDocLineNumber(
33
+ groupIndex?: number | null,
34
+ itemIndex?: number | null,
35
+ ): string | null {
36
+ if (!groupIndex || itemIndex == null) {
37
+ return null;
38
+ }
39
+
40
+ return `${groupIndex}.${itemIndex + 1}`;
41
+ }
42
+
43
+ /*
44
+ * Build the stable element identifier used by fieldDoc answers and element
45
+ * fragment keys ("answerKey.elementKey").
46
+ */
47
+
48
+ export function getFieldDocElementIdentifier(
49
+ answerKey?: string | null,
50
+ elementKey?: string | null,
51
+ ): string {
52
+ return `${answerKey || '__'}.${elementKey || 'ERROR'}`;
53
+ }
54
+
55
+ /*
56
+ * Build the realtime fragment data ID for one fieldDoc submission question element.
57
+ */
58
+
59
+ export function getFieldDocElementFragmentDataId(
60
+ fieldDocSubmissionIdKey: string | number | bigint,
61
+ elementKey: string,
62
+ ): string {
63
+ return `${fieldDocSubmissionIdKey}:${getFieldDocElementIdentifier('__latest', elementKey)}`;
64
+ }
65
+
66
+ /*
67
+ * Check whether a fieldDoc file can render as an image preview.
68
+ */
69
+
70
+ export function isFieldDocReferenceImageFile(file?: StorageGQL | null) {
71
+ return (
72
+ !file?.__deleted &&
73
+ !file?.uploadStatus &&
74
+ !!file?.uri &&
75
+ file.contentType?.startsWith('image/')
76
+ );
77
+ }
78
+
79
+ /*
80
+ * Resolve the logs and files referenced by one fieldDoc element.
81
+ */
82
+
83
+ export function getFieldDocReferenceContent(
84
+ logEntriesForFieldDoc?: LogEntryGQL[] | null,
85
+ referenceIds?: (string | null | undefined)[] | null,
86
+ ) {
87
+ if (!logEntriesForFieldDoc?.length || !referenceIds?.length) {
88
+ return null;
89
+ }
90
+
91
+ const referenceIdSet = new Set(
92
+ referenceIds.filter((referenceId): referenceId is string => !!referenceId),
93
+ );
94
+ if (!referenceIdSet.size) {
95
+ return null;
96
+ }
97
+
98
+ const logs = logEntriesForFieldDoc.filter((log) =>
99
+ referenceIdSet.has(log.id),
100
+ );
101
+ if (!logs.length) {
102
+ return null;
103
+ }
104
+
105
+ return {
106
+ files: logs.flatMap((log) => log.files || []),
107
+ logs,
108
+ };
109
+ }
110
+
111
+ /**
112
+ * Create-campaign draft
113
+ */