@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,32 @@
1
+ import type { SquareOAuthScope } from '../constants/square.ts';
2
+
3
+ export type SquareConnectionCapabilities = {
4
+ canReadMerchant: boolean;
5
+ canReadLocations: boolean;
6
+ canViewSalesData: boolean;
7
+ canCreatePaymentRequests: boolean;
8
+ };
9
+
10
+ /*
11
+ * Convert Square OAuth scopes into app-level capabilities used by UI and agents.
12
+ */
13
+ export function getSquareConnectionCapabilities(
14
+ scopes?: string[] | null,
15
+ ): SquareConnectionCapabilities {
16
+ const grantedScopes = new Set(scopes || []);
17
+
18
+ return {
19
+ canReadMerchant: grantedScopes.has(
20
+ 'MERCHANT_PROFILE_READ' satisfies SquareOAuthScope,
21
+ ),
22
+ canReadLocations: grantedScopes.has(
23
+ 'MERCHANT_PROFILE_READ' satisfies SquareOAuthScope,
24
+ ),
25
+ canViewSalesData:
26
+ grantedScopes.has('PAYMENTS_READ' satisfies SquareOAuthScope) ||
27
+ grantedScopes.has('ORDERS_READ' satisfies SquareOAuthScope),
28
+ canCreatePaymentRequests:
29
+ grantedScopes.has('ORDERS_WRITE' satisfies SquareOAuthScope) &&
30
+ grantedScopes.has('PAYMENTS_WRITE' satisfies SquareOAuthScope),
31
+ };
32
+ }
@@ -0,0 +1,152 @@
1
+ import {
2
+ CAMPAIGN_HEADER_IMAGE_CONTENT_TYPES,
3
+ CAMPAIGN_HEADER_IMAGE_MAX_FILE_SIZE,
4
+ } from '../constants/storage.ts';
5
+ import type { StorageGQL, StorageIntentEnum } from '../types/storage.d.ts';
6
+
7
+ export interface OptimisticAIChatAttachmentInput {
8
+ id?: string | null;
9
+ uri: string;
10
+ name: string;
11
+ contentType: string;
12
+ }
13
+
14
+ /*
15
+ * Adapt pending AI chat attachments into the normalized relationship shape
16
+ * used by the message renderer before the canonical message query arrives.
17
+ */
18
+
19
+ export function getOptimisticAIChatMessageAttachments(
20
+ attachments: OptimisticAIChatAttachmentInput[],
21
+ at: string,
22
+ ) {
23
+ return attachments.map((attachment, ordinal) => ({
24
+ ordinal,
25
+ file: {
26
+ id: attachment.id || attachment.uri,
27
+ uri: attachment.uri,
28
+ size: 0,
29
+ contentType: attachment.contentType,
30
+ at,
31
+ intent: null,
32
+ name: attachment.name,
33
+ description: null,
34
+ aiNote: null,
35
+ uploadStatus: null,
36
+ },
37
+ }));
38
+ }
39
+
40
+ /*
41
+ * Parse the semicolon-delimited attachment value stored on an AI chat message.
42
+ */
43
+
44
+ export function parseAIChatAttachmentText(text: string) {
45
+ const [oaiFileId = '', fileUri = '', ...nameParts] = (text || '').split(';');
46
+ const fileName = nameParts.join(';');
47
+
48
+ return {
49
+ oaiFileId,
50
+ fileUri,
51
+ fileName,
52
+ };
53
+ }
54
+
55
+ /*
56
+ * Infer the content type needed by the asset viewer from an attachment name.
57
+ */
58
+
59
+ function getAIChatAttachmentContentType(fileName: string, isImage: boolean) {
60
+ const extension = fileName.split('.').pop()?.toLowerCase();
61
+ const contentTypes: Record<string, string> = {
62
+ gif: 'image/gif',
63
+ jpeg: 'image/jpeg',
64
+ jpg: 'image/jpeg',
65
+ pdf: 'application/pdf',
66
+ png: 'image/png',
67
+ webp: 'image/webp',
68
+ };
69
+
70
+ return (
71
+ (extension && contentTypes[extension]) ||
72
+ (isImage ? 'image/jpeg' : 'application/octet-stream')
73
+ );
74
+ }
75
+
76
+ /*
77
+ * Adapt one AI chat attachment into the storage-file shape used by the asset
78
+ * viewer modal.
79
+ */
80
+
81
+ export function getAIChatAttachmentStorageFile(
82
+ text: string,
83
+ isImage: boolean,
84
+ ): StorageGQL | null {
85
+ const { oaiFileId, fileUri, fileName } = parseAIChatAttachmentText(text);
86
+ if (!fileUri) {
87
+ return null;
88
+ }
89
+
90
+ const displayName =
91
+ fileName || fileUri.substring(fileUri.lastIndexOf('/') + 1);
92
+
93
+ return {
94
+ id: oaiFileId || fileUri,
95
+ organizationId: null,
96
+ accountId: null,
97
+ uri: fileUri,
98
+ size: 0,
99
+ checked: true,
100
+ at: '',
101
+ contentType: getAIChatAttachmentContentType(displayName, isImage),
102
+ intent: null,
103
+ name: displayName,
104
+ };
105
+ }
106
+
107
+ /*
108
+ * Check whether a GCS object name or public asset URL contains a permanent
109
+ * application asset path segment: static/ or fonts/.
110
+ */
111
+
112
+ export function isStaticStorageUri(fileUri?: string | null): boolean {
113
+ if (!fileUri) {
114
+ return false;
115
+ }
116
+
117
+ const pathWithoutQuery = fileUri.trim().split(/[?#]/, 1)[0];
118
+ return /(^|\/)(?:static|fonts)\//.test(pathWithoutQuery);
119
+ }
120
+
121
+ /*
122
+ * Preserve an explicit storage intent, otherwise classify permanent static
123
+ * asset paths so cleanup code can exclude them.
124
+ */
125
+
126
+ export function resolveStorageIntentForUri(
127
+ fileUri: string,
128
+ intent?: StorageIntentEnum | null,
129
+ ): StorageIntentEnum | undefined {
130
+ return intent || (isStaticStorageUri(fileUri) ? 'STATIC' : undefined);
131
+ }
132
+
133
+ /*
134
+ * Check whether one storage object is safe and small enough to use as a
135
+ * public Field Doc form header image.
136
+ */
137
+
138
+ export function isValidCampaignHeaderImageFile(
139
+ file?: {
140
+ contentType?: string | null;
141
+ size?: number | null;
142
+ } | null,
143
+ ): boolean {
144
+ return (
145
+ !!file?.contentType &&
146
+ CAMPAIGN_HEADER_IMAGE_CONTENT_TYPES.some(
147
+ (contentType) => contentType === file.contentType,
148
+ ) &&
149
+ !!file.size &&
150
+ file.size <= CAMPAIGN_HEADER_IMAGE_MAX_FILE_SIZE
151
+ );
152
+ }
@@ -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
+ }