@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
@@ -1,66 +1,142 @@
1
+ import { convertHTMLToMarkdown } from '../../../@jsb188:react-web/utils/markdown.ts';
1
2
  import type { InboundEmailBodyFormatEnum } from '../types/email.d.ts';
2
3
 
3
- type PostmarkAttachmentLike = {
4
- Name?: string | null;
5
- ContentType?: string | null;
6
- ContentLength?: number | null;
7
- };
8
-
9
4
  type PostmarkInboundPayloadLike = {
5
+ HtmlBody?: string | null;
10
6
  TextBody?: string | null;
11
7
  StrippedTextReply?: string | null;
12
- HtmlBody?: string | null;
13
- Attachments?: PostmarkAttachmentLike[] | null;
14
8
  };
15
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
+
16
46
  /**
17
47
  * Limit optional Postmark text fields before displaying them.
18
48
  */
19
- export function limitInboundEmailTextValue(value: string | null | undefined, maxLength: number): string | null {
49
+ export function limitInboundEmailTextValue(
50
+ value: string | null | undefined,
51
+ maxLength: number,
52
+ ): string | null {
20
53
  return value ? value.substring(0, maxLength) : null;
21
54
  }
22
55
 
23
56
  /**
24
- * Strip HTML tags from an inbound email HTML body for plain-text display.
57
+ * Replace ASCII control characters in provider-owned email metadata.
25
58
  */
26
- export function stripInboundEmailHtmlBody(value: string | null | undefined): string | null {
27
- return value ? value.replace(/<[^>]*>/g, ' ').replace(/\s+/g, ' ').trim() : null;
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('');
28
69
  }
29
70
 
30
71
  /**
31
- * Return the preferred raw text source from a saved inbound email payload.
72
+ * Return one limited Postmark text payload field.
32
73
  */
33
- export function getInboundEmailPayloadTextBody(
34
- payload?: PostmarkInboundPayloadLike | null,
35
- maxBodyLength = 12000,
36
- ): string | null {
37
- const textBody = limitInboundEmailTextValue(
38
- typeof payload?.TextBody === 'string' ? payload.TextBody : null,
39
- maxBodyLength,
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,
40
82
  );
41
-
42
- return textBody ||
43
- limitInboundEmailTextValue(
44
- typeof payload?.StrippedTextReply === 'string' ? payload.StrippedTextReply : null,
45
- maxBodyLength,
46
- );
47
83
  }
48
84
 
49
85
  /**
50
- * Return the fallback HTML-derived text from a saved inbound email payload.
86
+ * Return markdown converted from one HTML email body.
51
87
  */
52
- export function getInboundEmailPayloadHtmlText(
88
+ function getInboundEmailPayloadHtmlMarkdownText(
53
89
  payload?: PostmarkInboundPayloadLike | null,
54
- maxBodyLength = 12000,
55
- ): string | null {
90
+ maxBodyLength = INBOUND_EMAIL_DEFAULT_BODY_LENGTH,
91
+ ) {
56
92
  return limitInboundEmailTextValue(
57
93
  typeof payload?.HtmlBody === 'string'
58
- ? stripInboundEmailHtmlBody(payload.HtmlBody)
94
+ ? convertHTMLToMarkdown(payload.HtmlBody)
59
95
  : null,
60
96
  maxBodyLength,
61
97
  );
62
98
  }
63
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
+
64
140
  /**
65
141
  * Return the display body format derived from a saved inbound email payload.
66
142
  */
@@ -71,10 +147,6 @@ export function getInboundEmailBodyFormat(
71
147
  return 'TEXT';
72
148
  }
73
149
 
74
- if (getInboundEmailPayloadHtmlText(payload)) {
75
- return 'HTML_TEXT';
76
- }
77
-
78
150
  return null;
79
151
  }
80
152
 
@@ -83,11 +155,9 @@ export function getInboundEmailBodyFormat(
83
155
  */
84
156
  export function getInboundEmailBodyText(
85
157
  payload?: PostmarkInboundPayloadLike | null,
86
- maxBodyLength = 12000,
158
+ maxBodyLength = INBOUND_EMAIL_DEFAULT_BODY_LENGTH,
87
159
  ): string {
88
- return getInboundEmailPayloadTextBody(payload, maxBodyLength) ||
89
- getInboundEmailPayloadHtmlText(payload, maxBodyLength) ||
90
- '';
160
+ return getInboundEmailPayloadTextBody(payload, maxBodyLength) || '';
91
161
  }
92
162
 
93
163
  /**
@@ -96,18 +166,7 @@ export function getInboundEmailBodyText(
96
166
  export function getInboundEmailPreviewText(
97
167
  payload?: PostmarkInboundPayloadLike | null,
98
168
  ): string {
99
- return getInboundEmailBodyText(payload, 240).replace(/\s+/g, ' ').trim();
100
- }
101
-
102
- /**
103
- * Return safe attachment metadata from a saved inbound email payload.
104
- */
105
- export function getInboundEmailAttachments(payload?: PostmarkInboundPayloadLike | null) {
106
- return Array.isArray(payload?.Attachments)
107
- ? payload.Attachments.map((attachment) => ({
108
- name: attachment?.Name || null,
109
- contentType: attachment?.ContentType || null,
110
- contentLength: attachment?.ContentLength || null,
111
- }))
112
- : [];
169
+ return getInboundEmailBodyText(payload, INBOUND_EMAIL_PREVIEW_LENGTH)
170
+ .replace(/\s+/g, ' ')
171
+ .trim();
113
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
+ */