@jsb188/mday 1.1.11 → 1.1.12

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 (210) hide show
  1. package/package.json +58 -23
  2. package/src/constants/agentMemory.ts +14 -45
  3. package/src/constants/agentNote.ts +212 -0
  4. package/src/constants/aiChat.ts +5 -0
  5. package/src/constants/billing.ts +126 -0
  6. package/src/constants/campaign.ts +156 -47
  7. package/src/constants/contact.ts +72 -0
  8. package/src/constants/csvExport.ts +133 -0
  9. package/src/constants/dataTable.ts +12 -38
  10. package/src/constants/dataTableFieldTypes.generated.ts +3 -7
  11. package/src/constants/docAccess.ts +3 -2
  12. package/src/constants/dt.ts +234 -0
  13. package/src/constants/email.ts +114 -12
  14. package/src/constants/fieldDoc.ts +74 -4
  15. package/src/constants/graphqlReactivity.ts +108 -25
  16. package/src/constants/log.ts +9 -0
  17. package/src/constants/logDisplay/README.md +88 -0
  18. package/src/constants/logDisplay/defaults.ts +39 -0
  19. package/src/constants/logDisplay/index.ts +27 -0
  20. package/src/constants/logDisplay/operations/arable.ts +16 -0
  21. package/src/constants/logDisplay/operations/farmersMarket.ts +10 -0
  22. package/src/constants/logDisplay/operations/foodManufacturing.ts +13 -0
  23. package/src/constants/logDisplay/shared/accounting.ts +13 -0
  24. package/src/constants/logDisplay/shared/interactions.ts +13 -0
  25. package/src/constants/logDisplay/shared/rackTemperatures.ts +42 -0
  26. package/src/constants/logTaxonomy.generated.ts +1834 -730
  27. package/src/constants/organization.ts +13 -14
  28. package/src/constants/qrCode.ts +30 -0
  29. package/src/constants/sheet.ts +65 -101
  30. package/src/constants/sms.ts +18 -0
  31. package/src/constants/storage.ts +33 -9
  32. package/src/constants/usage.ts +3 -0
  33. package/src/constants/workflowSteps.ts +60 -0
  34. package/src/schemas/editLogEntry.ts +106 -283
  35. package/src/schemas/inboundContact.ts +5 -5
  36. package/src/types/agentMemory.d.ts +38 -14
  37. package/src/types/agentNote.d.ts +443 -0
  38. package/src/types/billing.d.ts +537 -0
  39. package/src/types/campaign.d.ts +1043 -193
  40. package/src/types/contact.d.ts +15 -0
  41. package/src/types/csvExport.d.ts +213 -0
  42. package/src/types/dataAnalysis.d.ts +44 -0
  43. package/src/types/dataTable.d.ts +102 -309
  44. package/src/types/definitionElement.d.ts +35 -0
  45. package/src/types/dt.d.ts +257 -0
  46. package/src/types/email.d.ts +144 -55
  47. package/src/types/emailReplyReport.d.ts +76 -0
  48. package/src/types/fieldDoc.d.ts +579 -150
  49. package/src/types/fieldDocContract.d.ts +90 -0
  50. package/src/types/inboundContact.d.ts +8 -0
  51. package/src/types/log.d.ts +94 -3
  52. package/src/types/logDisplay.types.ts +85 -0
  53. package/src/types/organization.d.ts +8 -3
  54. package/src/types/qrCode.d.ts +96 -0
  55. package/src/types/richText.d.ts +81 -0
  56. package/src/types/sheet.d.ts +180 -463
  57. package/src/types/sms.d.ts +38 -0
  58. package/src/types/storage.d.ts +266 -27
  59. package/src/types/workflow.d.ts +196 -66
  60. package/src/utils/agentMemory.ts +15 -0
  61. package/src/utils/agentNote.ts +850 -0
  62. package/src/utils/aiChat.ts +31 -14
  63. package/src/utils/aiChatWork.ts +64 -0
  64. package/src/utils/billing.ts +37 -0
  65. package/src/utils/campaign.ts +642 -209
  66. package/src/utils/campaignAI.ts +72 -0
  67. package/src/utils/campaignAccess.ts +239 -0
  68. package/src/utils/campaignEmail.ts +601 -0
  69. package/src/utils/campaignEmailCompiler.ts +372 -0
  70. package/src/utils/campaignEmailImages.ts +60 -0
  71. package/src/utils/campaignEmailStyles.ts +544 -0
  72. package/src/utils/campaignLifecycle.ts +104 -0
  73. package/src/utils/campaignPreview.ts +285 -0
  74. package/src/utils/contact.ts +50 -0
  75. package/src/utils/csvExport.ts +19 -0
  76. package/src/utils/dataTable.ts +18 -556
  77. package/src/utils/dataTableFieldTypeRegistry.ts +1 -0
  78. package/src/utils/dataTableRelativeDate.ts +447 -0
  79. package/src/utils/definitionElement.ts +84 -0
  80. package/src/utils/email.ts +208 -1
  81. package/src/utils/emailReplyReport.test.ts +187 -0
  82. package/src/utils/emailReplyReport.ts +143 -0
  83. package/src/utils/fieldDoc.ts +81 -37
  84. package/src/utils/fieldDocAnswers.ts +128 -0
  85. package/src/utils/fieldDocDefaults.ts +36 -0
  86. package/src/utils/fieldDocProgram.ts +36 -0
  87. package/src/utils/fieldDocSummary.ts +30 -0
  88. package/src/utils/log.ts +232 -141
  89. package/src/utils/logDisplay.helpers.ts +177 -0
  90. package/src/utils/logDisplay.ts +87 -0
  91. package/src/utils/logStoreRead.ts +9 -13
  92. package/src/utils/logTaxonomy.helpers.ts +17 -0
  93. package/src/utils/logTaxonomyDisplay.ts +80 -124
  94. package/src/utils/noteDoc.ts +66 -284
  95. package/src/utils/organization.ts +117 -283
  96. package/src/utils/qrCode.helpers.ts +189 -0
  97. package/src/utils/qrCode.test.ts +519 -0
  98. package/src/utils/qrCode.ts +273 -0
  99. package/src/utils/richTextHTML.ts +385 -0
  100. package/src/utils/sheet.ts +123 -4834
  101. package/src/utils/sheetAxisMove.ts +77 -291
  102. package/src/utils/sheetBootstrap.ts +771 -1138
  103. package/src/utils/sheetCellLiteral.ts +101 -0
  104. package/src/utils/sheetCommand.ts +23 -88
  105. package/src/utils/sheetDesign.ts +705 -0
  106. package/src/utils/sheetExport.ts +17 -69
  107. package/src/utils/sheetFeatureReference.ts +183 -0
  108. package/src/utils/sheetFormulaArgs.ts +168 -0
  109. package/src/utils/sheetFormulaCompile.ts +475 -0
  110. package/src/utils/sheetFormulaConditionalAggregate.ts +254 -0
  111. package/src/utils/sheetFormulaCriteria.ts +656 -0
  112. package/src/utils/sheetFormulaDate.ts +444 -0
  113. package/src/utils/sheetFormulaEvaluation.ts +388 -403
  114. package/src/utils/sheetFormulaEvaluator.ts +589 -444
  115. package/src/utils/sheetFormulaFunctionHandlers.ts +403 -0
  116. package/src/utils/sheetFormulaLogical.ts +116 -0
  117. package/src/utils/sheetFormulaLookup.ts +488 -0
  118. package/src/utils/sheetFormulaMath.ts +48 -0
  119. package/src/utils/sheetFormulaParser.ts +729 -0
  120. package/src/utils/sheetFormulaRange.ts +330 -0
  121. package/src/utils/sheetFormulaReference.ts +703 -0
  122. package/src/utils/sheetFormulaReferenceAggregates.ts +313 -0
  123. package/src/utils/sheetFormulaReferenceDates.ts +237 -0
  124. package/src/utils/sheetFormulaReferenceLogical.ts +330 -0
  125. package/src/utils/sheetFormulaReferenceLookup.ts +341 -0
  126. package/src/utils/sheetFormulaReferenceMath.ts +95 -0
  127. package/src/utils/sheetFormulaReferenceRewrite.ts +220 -0
  128. package/src/utils/sheetFormulaReferenceText.ts +462 -0
  129. package/src/utils/sheetFormulaSyntax.ts +1027 -0
  130. package/src/utils/sheetFormulaText.ts +430 -0
  131. package/src/utils/sheetJournal.ts +140 -18
  132. package/src/utils/sheetNumberFormat.ts +68 -267
  133. package/src/utils/sheetPreview.ts +68 -0
  134. package/src/utils/sheetSequence.ts +13 -43
  135. package/src/utils/sheetSnapshot.ts +176 -429
  136. package/src/utils/sheetStructureEdit.ts +537 -907
  137. package/src/utils/sheetStructureReferences.ts +389 -0
  138. package/src/utils/storage.ts +49 -3
  139. package/src/utils/time.ts +12 -0
  140. package/src/utils/workflow.ts +199 -73
  141. package/src/utils/workflowLogFingerprint.ts +302 -0
  142. package/src/utils/workflowLogRevisionSnapshot.ts +424 -0
  143. package/src/utils/workflowProgress.ts +280 -0
  144. package/src/utils/workflowTriggers.ts +61 -0
  145. package/tests/agentNote.test.ts +395 -0
  146. package/tests/campaignAI.test.ts +119 -0
  147. package/tests/campaignAccess.test.ts +239 -0
  148. package/tests/campaignEmail.test.ts +441 -0
  149. package/tests/campaignLifecycle.test.ts +134 -0
  150. package/tests/campaignPublication.test.ts +309 -0
  151. package/tests/dataTableFieldTypeRegistry.test.ts +2 -1
  152. package/tests/dataTableRelativeDate.test.ts +412 -0
  153. package/tests/email.test.ts +39 -0
  154. package/tests/fieldDocProgram.test.ts +114 -0
  155. package/tests/logDisplay.fixtures.ts +67 -0
  156. package/tests/logDisplay.test.ts +227 -0
  157. package/tests/noteDoc.test.ts +37 -192
  158. package/tests/richTextHTML.test.ts +185 -0
  159. package/tests/sheetAxisMove.test.ts +49 -40
  160. package/tests/sheetBootstrap.test.ts +1967 -0
  161. package/tests/sheetFeatureReference.test.ts +22 -0
  162. package/tests/sheetFormulaCriteria.test.ts +269 -0
  163. package/tests/sheetFormulaEvaluator.test.ts +93 -200
  164. package/tests/sheetFormulaFunctions.test.ts +538 -0
  165. package/tests/sheetFormulaLanguage.test.ts +361 -0
  166. package/tests/sheetFormulaParity.fixtures.ts +872 -0
  167. package/tests/sheetFormulaParity.test.ts +188 -0
  168. package/tests/sheetFormulaRange.test.ts +167 -0
  169. package/tests/sheetFormulaReference.test.ts +78 -0
  170. package/tests/sheetFormulaReferenceRewrite.test.ts +117 -0
  171. package/tests/sheetFormulaTextDate.test.ts +512 -0
  172. package/tests/sheetSequence.test.ts +4 -23
  173. package/tests/sheetSnapshot.test.ts +134 -0
  174. package/tests/sheetStructureEdit.test.ts +492 -37
  175. package/tests/sheetStructureReferences.test.ts +589 -0
  176. package/tests/workflowLifecycleStatus.test.ts +60 -0
  177. package/tests/workflowLogFingerprint.test.ts +203 -0
  178. package/tests/workflowLogRevisionSnapshot.test.ts +96 -0
  179. package/tests/workflowProgress.test.ts +180 -0
  180. package/tests/workflowTriggers.test.ts +29 -0
  181. package/src/constants/agentDoc.ts +0 -12
  182. package/src/constants/logActivityGroupColors.generated.ts +0 -19
  183. package/src/constants/schedule.ts +0 -220
  184. package/src/constants/scheduleRuleTemplateSeed.ts +0 -138
  185. package/src/constants/scheduleRuleTemplates.generated.ts +0 -145
  186. package/src/constants/sheetRegionSources.generated.ts +0 -578
  187. package/src/schemas/fieldDocsQuery.ts +0 -12
  188. package/src/schemas/organization.ts +0 -68
  189. package/src/types/agentDoc.d.ts +0 -64
  190. package/src/types/noteDoc.d.ts +0 -86
  191. package/src/types/schedule.d.ts +0 -391
  192. package/src/utils/agentDoc.ts +0 -109
  193. package/src/utils/campaignFormEditor.ts +0 -871
  194. package/src/utils/dataTableRealtimeAuthority.ts +0 -209
  195. package/src/utils/dataTableRealtimeSelection.ts +0 -134
  196. package/src/utils/dataTableRowDocument.ts +0 -508
  197. package/src/utils/dataTableSource.ts +0 -230
  198. package/src/utils/schedule.ts +0 -799
  199. package/src/utils/scheduleEvaluation.ts +0 -1994
  200. package/src/utils/scheduleICS.ts +0 -246
  201. package/src/utils/scheduleRuleTemplates.ts +0 -188
  202. package/src/utils/sheetRegion.ts +0 -374
  203. package/src/utils/sheetRegionFilter.ts +0 -1259
  204. package/src/utils/sheetRegionSourceRegistry.ts +0 -594
  205. package/tests/schedule.test.ts +0 -693
  206. package/tests/scheduleEvaluation.test.ts +0 -1970
  207. package/tests/scheduleICS.test.ts +0 -208
  208. package/tests/scheduleRuleTemplates.test.ts +0 -176
  209. package/tests/scheduleSweepInvariants.test.ts +0 -428
  210. package/tests/sheetRegionFilter.test.ts +0 -1135
@@ -1,11 +1,11 @@
1
- import { COLORS } from '@jsb188/app/constants/app.ts';
1
+ import type { SupportedLogLanguage } from '@jsb188/app/constants/app.ts';
2
+ import { COLORS, isSupportedLogLanguage } from '@jsb188/app/constants/app.ts';
2
3
  import { shortenToSpace } from '@jsb188/app/utils/string.ts';
3
4
  import { DEFAULT_TIMEZONE } from '@jsb188/app/utils/timeZone.ts';
4
5
  import { ORG_CONTACTS } from '../constants/organization.ts';
5
6
  import type {
6
7
  ACLPermissionEnum,
7
8
  MergedOrgContact,
8
- OrgContact,
9
9
  OrganizationChildData,
10
10
  OrganizationChildGQL,
11
11
  OrganizationContactData,
@@ -15,23 +15,15 @@ import type {
15
15
  OrganizationRelGQL,
16
16
  OrganizationRoleEnum,
17
17
  OrganizationSettingsObj,
18
+ OrgContact,
18
19
  } from '../types/organization.d.ts';
19
- import type { SheetCustomRegionSourceColumnFormulaValueSourceEnum } from '../types/sheet.d.ts';
20
20
 
21
21
  // Placeholder to match Server import
22
22
  type ViewerOrganization = any;
23
23
 
24
- type OperationPermissionTuple = readonly [
25
- PermissionCheckFor,
26
- ACLPermissionEnum,
27
- string,
28
- ];
24
+ type OperationPermissionTuple = readonly [PermissionCheckFor, ACLPermissionEnum, string];
29
25
  type OperationPermissionsMap = Record<string, OperationPermissionTuple>;
30
- type OrganizationChildPreferredContacts =
31
- | OrgContact[]
32
- | Record<string, Partial<OrgContact> | null | undefined>
33
- | null
34
- | undefined;
26
+ type OrganizationChildPreferredContacts = OrgContact[] | Record<string, Partial<OrgContact> | null | undefined> | null | undefined;
35
27
  type OrganizationChildContactSource = {
36
28
  organization?: {
37
29
  id?: string | number | bigint | null;
@@ -44,81 +36,24 @@ type OrganizationChildContactSource = {
44
36
  };
45
37
 
46
38
  export const OPERATION_PERMISSIONS = {
47
- billing_read: [
48
- 'billing',
49
- 'READ',
50
- "You do not have permission to view this organization's billing usage.",
51
- ],
52
- chat: [
53
- 'viewData',
54
- 'READ',
55
- 'You do not have permission to chat with AI in this organization.',
56
- ],
57
- general_read: [
58
- 'viewData',
59
- 'READ',
60
- "You do not have permission to view this organization's data.",
61
- ],
62
- general_write: [
63
- 'viewData',
64
- 'WRITE',
65
- 'You do not have permission to write data in this organization.',
66
- ],
67
- integrations_update: [
68
- 'integrations',
69
- 'MANAGE',
70
- "You do not have permission to manage this organization's app connections.",
71
- ],
72
- ai_inbox_management: [
73
- 'orgManagement',
74
- 'MANAGE',
75
- "You do not have permission to manage this organization's AI inbox.",
76
- ],
77
- ai_inbox_read: [
78
- 'orgManagement',
79
- 'READ',
80
- "You do not have permission to read this organization's AI inbox.",
81
- ],
82
- logs_write: [
83
- 'logs',
84
- 'WRITE',
85
- 'You do not have permission to write logs in this organization.',
86
- ],
87
- member_sessions_manage: [
88
- 'members',
89
- 'MANAGE',
90
- 'You do not have permission to manage member sessions in this organization.',
91
- ],
92
- org_directory: [
93
- 'logs',
94
- 'WRITE',
95
- "You do not have permission to manage this organization's directory book.",
96
- ],
97
- agent_docs_edit: [
98
- 'viewData',
99
- 'MANAGE',
100
- 'You do not have permission to edit agent docs in this organization.',
101
- ],
102
- org_management: [
103
- 'orgManagement',
104
- 'WRITE',
105
- "You do not have permission to edit this organization's data.",
106
- ],
107
- org_sites_update: [
108
- 'logs',
109
- 'WRITE',
110
- 'You do not have permission to update organization sites.',
111
- ],
112
- schedule_edit: [
113
- 'viewData',
114
- 'MANAGE',
115
- 'You do not have permission to edit schedules in this organization.',
116
- ],
117
- sheets_edit: [
118
- 'viewData',
119
- 'MANAGE',
120
- 'You do not have permission to edit sheets & data tables in this organization.',
121
- ],
39
+ billing_read: ['billing', 'READ', "You do not have permission to view this organization's billing usage."],
40
+ billing_manage: ['billing', 'MANAGE', "You do not have permission to manage this organization's billing."],
41
+ chat: ['viewData', 'READ', 'You do not have permission to chat with AI in this organization.'],
42
+ campaign_edit: ['products', 'WRITE', 'You do not have permission to edit campaigns in this organization.'],
43
+ general_read: ['viewData', 'READ', "You do not have permission to view this organization's data."],
44
+ general_write: ['viewData', 'WRITE', 'You do not have permission to write data in this organization.'],
45
+ integrations_update: ['integrations', 'MANAGE', "You do not have permission to manage this organization's app connections."],
46
+ ai_inbox_management: ['orgManagement', 'MANAGE', "You do not have permission to manage this organization's AI inbox."],
47
+ ai_inbox_read: ['orgManagement', 'READ', "You do not have permission to read this organization's AI inbox."],
48
+ logs_write: ['logs', 'WRITE', 'You do not have permission to write logs in this organization.'],
49
+ member_sessions_manage: ['members', 'MANAGE', 'You do not have permission to manage member sessions in this organization.'],
50
+ org_directory: ['logs', 'WRITE', "You do not have permission to manage this organization's directory book."],
51
+ agent_notes_manage: ['viewData', 'MANAGE', 'You do not have permission to manage AI notes in this organization.'],
52
+ org_management: ['orgManagement', 'WRITE', "You do not have permission to edit this organization's data."],
53
+ org_settings_manage: ['settings', 'MANAGE', "You do not have permission to manage this organization's settings."],
54
+ org_sites_update: ['logs', 'WRITE', 'You do not have permission to update organization sites.'],
55
+ schedule_edit: ['viewData', 'MANAGE', 'You do not have permission to edit schedules in this organization.'],
56
+ sheets_edit: ['viewData', 'MANAGE', 'You do not have permission to edit sheets & data tables in this organization.'],
122
57
  } as const satisfies OperationPermissionsMap;
123
58
 
124
59
  export type OperationName = keyof typeof OPERATION_PERMISSIONS;
@@ -138,9 +73,7 @@ const ORGANIZATION_INBOUND_EMAIL_ALLOWED_REGEX = /^[a-z0-9_-]+$/;
138
73
  * Convert free-form input into the closest inbound email handle candidate.
139
74
  */
140
75
 
141
- export function normalizeOrganizationInboundEmailHandle(
142
- value?: string | null,
143
- ): string {
76
+ export function normalizeOrganizationInboundEmailHandle(value?: string | null): string {
144
77
  return String(value || '')
145
78
  .trim()
146
79
  .toLowerCase()
@@ -153,21 +86,15 @@ export function normalizeOrganizationInboundEmailHandle(
153
86
  * Build the default inbound email handle placeholder from an organization name.
154
87
  */
155
88
 
156
- export function buildOrganizationInboundEmailPlaceholder(
157
- orgName?: string | null,
158
- ): string {
159
- return normalizeOrganizationInboundEmailHandle(
160
- shortenToSpace(String(orgName || ''), 20),
161
- );
89
+ export function buildOrganizationInboundEmailPlaceholder(orgName?: string | null): string {
90
+ return normalizeOrganizationInboundEmailHandle(shortenToSpace(String(orgName || ''), 20));
162
91
  }
163
92
 
164
93
  /*
165
94
  * Keep typed input limited to the inbound email handle character set.
166
95
  */
167
96
 
168
- export function sanitizeOrganizationInboundEmailHandleInput(
169
- value?: string | null,
170
- ): string {
97
+ export function sanitizeOrganizationInboundEmailHandleInput(value?: string | null): string {
171
98
  return String(value || '')
172
99
  .toLowerCase()
173
100
  .replace(/[^a-z0-9_-]+/g, '')
@@ -179,16 +106,10 @@ export function sanitizeOrganizationInboundEmailHandleInput(
179
106
  * Check whether a normalized inbound email handle is valid to store.
180
107
  */
181
108
 
182
- export function isValidOrganizationInboundEmailHandle(
183
- value?: string | null,
184
- ): boolean {
109
+ export function isValidOrganizationInboundEmailHandle(value?: string | null): boolean {
185
110
  const handle = String(value || '');
186
111
 
187
- return !!(
188
- handle &&
189
- handle.length <= ORGANIZATION_INBOUND_EMAIL_MAX_LENGTH &&
190
- ORGANIZATION_INBOUND_EMAIL_ALLOWED_REGEX.test(handle)
191
- );
112
+ return !!(handle && handle.length <= ORGANIZATION_INBOUND_EMAIL_MAX_LENGTH && ORGANIZATION_INBOUND_EMAIL_ALLOWED_REGEX.test(handle));
192
113
  }
193
114
 
194
115
  const INT_TO_PERMISSION = Object.keys(PERMISSION_TO_INT);
@@ -206,9 +127,7 @@ export function getRoleValue(role: OrganizationRoleEnum): number {
206
127
  * Get default permissions by role
207
128
  */
208
129
 
209
- export function getDefaultPermissionsByRole(
210
- orgRel: OrganizationRelGQL | OrganizationRelData | ViewerOrganization,
211
- ) {
130
+ export function getDefaultPermissionsByRole(orgRel: OrganizationRelGQL | OrganizationRelData | ViewerOrganization) {
212
131
  const role = orgRel?.role || 'MEMBER';
213
132
  const acl: Record<string, any> = { ...orgRel?.acl };
214
133
 
@@ -227,8 +146,21 @@ export function getDefaultPermissionsByRole(
227
146
  // 0 = "NONE"
228
147
 
229
148
  switch (role) {
230
- case 'ADMIN':
231
149
  case 'OWNER':
150
+ return {
151
+ billing: 'MANAGE',
152
+ compliance: 'MANAGE',
153
+ digests: 'MANAGE',
154
+ finances: 'MANAGE',
155
+ integrations: 'MANAGE',
156
+ logs: 'MANAGE',
157
+ members: 'MANAGE',
158
+ orgManagement: 'MANAGE',
159
+ products: 'MANAGE',
160
+ settings: 'MANAGE',
161
+ viewData: 'MANAGE',
162
+ };
163
+ case 'ADMIN':
232
164
  return {
233
165
  billing: acl.billing || 'MANAGE',
234
166
  compliance: acl.compliance || 'MANAGE',
@@ -293,18 +225,11 @@ export function getDefaultPermissionsByRole(
293
225
  * Check if this account's ACL has required permissions for an action
294
226
  */
295
227
 
296
- export type PermissionCheckFor = keyof ReturnType<
297
- typeof getDefaultPermissionsByRole
298
- >;
228
+ export type PermissionCheckFor = keyof ReturnType<typeof getDefaultPermissionsByRole>;
299
229
  export type ACLPermissionCheck = 'READ' | 'WRITE' | 'MANAGE';
300
230
 
301
231
  export function checkACLPermission(
302
- orgRel:
303
- | OrganizationRelGQL
304
- | OrganizationRelData
305
- | ViewerOrganization
306
- | null
307
- | undefined,
232
+ orgRel: OrganizationRelGQL | OrganizationRelData | ViewerOrganization | null | undefined,
308
233
  check: PermissionCheckFor,
309
234
  requiredPermission: ACLPermissionCheck,
310
235
  ): boolean | null {
@@ -325,16 +250,10 @@ export function checkACLPermission(
325
250
  */
326
251
 
327
252
  export function checkACL(
328
- orgRel:
329
- | OrganizationRelGQL
330
- | OrganizationRelData
331
- | ViewerOrganization
332
- | null
333
- | undefined,
253
+ orgRel: OrganizationRelGQL | OrganizationRelData | ViewerOrganization | null | undefined,
334
254
  opName: OperationName,
335
255
  ) {
336
- const [permissionCheckFor, requiredPermission] =
337
- OPERATION_PERMISSIONS[opName] || [];
256
+ const [permissionCheckFor, requiredPermission] = OPERATION_PERMISSIONS[opName] || [];
338
257
  if (!permissionCheckFor || !requiredPermission) {
339
258
  console.warn(`Operation ${opName} not found in permissions map.`);
340
259
  return null;
@@ -347,14 +266,7 @@ export function checkACL(
347
266
  * @returns true if at least one ACL permission differs from default role ACL
348
267
  */
349
268
 
350
- export function isCustomACLForRole(
351
- orgRel:
352
- | OrganizationRelGQL
353
- | OrganizationRelData
354
- | ViewerOrganization
355
- | null
356
- | undefined,
357
- ): boolean {
269
+ export function isCustomACLForRole(orgRel: OrganizationRelGQL | OrganizationRelData | ViewerOrganization | null | undefined): boolean {
358
270
  if (!orgRel) {
359
271
  return false;
360
272
  }
@@ -369,10 +281,7 @@ export function isCustomACLForRole(
369
281
 
370
282
  const effectiveACL = getDefaultPermissionsByRole(orgRel);
371
283
  for (const aclKey in roleDefaultACL) {
372
- if (
373
- effectiveACL[aclKey as PermissionCheckFor] !==
374
- roleDefaultACL[aclKey as PermissionCheckFor]
375
- ) {
284
+ if (effectiveACL[aclKey as PermissionCheckFor] !== roleDefaultACL[aclKey as PermissionCheckFor]) {
376
285
  return true;
377
286
  }
378
287
  }
@@ -392,16 +301,53 @@ export function getDefaultOrganizationSettings(
392
301
  ): Partial<OrganizationSettingsObj> {
393
302
  return {
394
303
  timeZone: timeZone || DEFAULT_TIMEZONE,
304
+ displayTranslatedLogs: true,
305
+ translateLanguage: 'en',
395
306
  color: COLORS[Math.floor(Math.random() * COLORS.length)],
396
307
  };
397
308
  }
398
309
 
310
+ /*
311
+ * Return one effective organization log-language setting while preserving an explicit disabled value.
312
+ */
313
+ export function getOrganizationLogLanguageSetting(
314
+ settings: Partial<OrganizationSettingsObj> | Record<string, unknown> | null | undefined,
315
+ settingName: 'translateLanguage',
316
+ ): SupportedLogLanguage | null {
317
+ const value = settings?.[settingName];
318
+
319
+ if (value === null) {
320
+ return null;
321
+ }
322
+
323
+ return isSupportedLogLanguage(value) ? value : 'en';
324
+ }
325
+
326
+ /*
327
+ * Return whether organization log views should prefer available translated text.
328
+ */
329
+ export function getOrganizationDisplayTranslatedLogsSetting(
330
+ settings: Partial<OrganizationSettingsObj> | Record<string, unknown> | null | undefined,
331
+ ): boolean {
332
+ return typeof settings?.displayTranslatedLogs === 'boolean' ? settings.displayTranslatedLogs : true;
333
+ }
334
+
335
+ /*
336
+ * Resolve the translation locale used by read-only log views, or null when
337
+ * the organization prefers original text or has translation disabled.
338
+ */
339
+ export function getOrganizationLogDisplayLanguage(
340
+ settings: Partial<OrganizationSettingsObj> | Record<string, unknown> | null | undefined,
341
+ ): SupportedLogLanguage | null {
342
+ return getOrganizationDisplayTranslatedLogsSetting(settings)
343
+ ? getOrganizationLogLanguageSetting(settings, 'translateLanguage')
344
+ : null;
345
+ }
346
+
399
347
  /*
400
348
  * Map organization_contacts rows to plain directory contacts, ordered by department.
401
349
  */
402
- export function mapOrgContactRowsToContacts(
403
- rows?: Array<Partial<OrganizationContactData>> | null,
404
- ): OrgContact[] {
350
+ export function mapOrgContactRowsToContacts(rows?: Array<Partial<OrganizationContactData>> | null): OrgContact[] {
405
351
  return (rows || [])
406
352
  .filter((row) => row.department)
407
353
  .map((row) => ({
@@ -410,10 +356,7 @@ export function mapOrgContactRowsToContacts(
410
356
  phoneNumber: row.phoneNumber || null,
411
357
  emailAddress: row.emailAddress || null,
412
358
  }))
413
- .sort(
414
- (a, b) =>
415
- ORG_CONTACTS.indexOf(a.department) - ORG_CONTACTS.indexOf(b.department),
416
- );
359
+ .sort((a, b) => ORG_CONTACTS.indexOf(a.department) - ORG_CONTACTS.indexOf(b.department));
417
360
  }
418
361
 
419
362
  /*
@@ -466,10 +409,8 @@ function hasPreferredOverride(dirContact: OrgContact, preferred?: OrgContact) {
466
409
 
467
410
  return (
468
411
  (preferred.name !== undefined && preferred.name !== dirContact.name) ||
469
- (preferred.phoneNumber !== undefined &&
470
- preferred.phoneNumber !== dirContact.phoneNumber) ||
471
- (preferred.emailAddress !== undefined &&
472
- preferred.emailAddress !== dirContact.emailAddress)
412
+ (preferred.phoneNumber !== undefined && preferred.phoneNumber !== dirContact.phoneNumber) ||
413
+ (preferred.emailAddress !== undefined && preferred.emailAddress !== dirContact.emailAddress)
473
414
  );
474
415
  }
475
416
 
@@ -565,9 +506,7 @@ export function upsertOrgPreferredContactByDepartment(
565
506
  return [...source, nextContact];
566
507
  }
567
508
 
568
- return source.map((contact) =>
569
- contact.department === department ? nextContact : contact,
570
- );
509
+ return source.map((contact) => (contact.department === department ? nextContact : contact));
571
510
  }
572
511
 
573
512
  /*
@@ -577,9 +516,7 @@ export function removeOrgPreferredContactByDepartment(
577
516
  preferredContacts: OrgContact[] | undefined,
578
517
  department: OrgContact['department'],
579
518
  ): OrgContact[] {
580
- return (preferredContacts || []).filter(
581
- (contact) => contact.department !== department,
582
- );
519
+ return (preferredContacts || []).filter((contact) => contact.department !== department);
583
520
  }
584
521
 
585
522
  /*
@@ -590,16 +527,10 @@ export function restoreOrgPreferredContactByDepartment(
590
527
  savedPreferredContacts: OrgContact[] | undefined,
591
528
  department: OrgContact['department'],
592
529
  ): OrgContact[] {
593
- const savedContact = (savedPreferredContacts || []).find(
594
- (contact) => contact.department === department,
595
- );
596
- const withoutDepartment = (currentPreferredContacts || []).filter(
597
- (contact) => contact.department !== department,
598
- );
530
+ const savedContact = (savedPreferredContacts || []).find((contact) => contact.department === department);
531
+ const withoutDepartment = (currentPreferredContacts || []).filter((contact) => contact.department !== department);
599
532
 
600
- return savedContact
601
- ? [...withoutDepartment, savedContact]
602
- : withoutDepartment;
533
+ return savedContact ? [...withoutDepartment, savedContact] : withoutDepartment;
603
534
  }
604
535
 
605
536
  /*
@@ -609,18 +540,13 @@ export function getEditableOrgContactByDepartment(
609
540
  list: MergedOrgContact[],
610
541
  department: OrgContact['department'],
611
542
  ): MergedOrgContact | null {
612
- return (
613
- list.find((item) => item.department === department && !item.locked) || null
614
- );
543
+ return list.find((item) => item.department === department && !item.locked) || null;
615
544
  }
616
545
 
617
546
  /*
618
547
  * Compare preferred-contact lists by normalized department and value pairs.
619
548
  */
620
- export function areOrgPreferredContactsEqual(
621
- a?: OrgContact[] | null,
622
- b?: OrgContact[] | null,
623
- ) {
549
+ export function areOrgPreferredContactsEqual(a?: OrgContact[] | null, b?: OrgContact[] | null) {
624
550
  const sourceA = a || [];
625
551
  const sourceB = b || [];
626
552
 
@@ -628,12 +554,8 @@ export function areOrgPreferredContactsEqual(
628
554
  return false;
629
555
  }
630
556
 
631
- const normalizedA = [...sourceA].sort((x, y) =>
632
- x.department.localeCompare(y.department),
633
- );
634
- const normalizedB = [...sourceB].sort((x, y) =>
635
- x.department.localeCompare(y.department),
636
- );
557
+ const normalizedA = [...sourceA].sort((x, y) => x.department.localeCompare(y.department));
558
+ const normalizedB = [...sourceB].sort((x, y) => x.department.localeCompare(y.department));
637
559
 
638
560
  return normalizedA.every((item, index) => {
639
561
  const other = normalizedB[index];
@@ -650,16 +572,12 @@ export function areOrgPreferredContactsEqual(
650
572
  /*
651
573
  * Return one preferred contact with a department supplied from the map key when needed.
652
574
  */
653
- function normalizeOrganizationChildPreferredContact(
654
- department: string,
655
- contact?: Partial<OrgContact> | null,
656
- ): OrgContact | null {
575
+ function normalizeOrganizationChildPreferredContact(department: string, contact?: Partial<OrgContact> | null): OrgContact | null {
657
576
  if (!contact) {
658
577
  return null;
659
578
  }
660
579
 
661
- const contactDepartment =
662
- contact.department || (department as OrganizationDepartmentEnum);
580
+ const contactDepartment = contact.department || (department as OrganizationDepartmentEnum);
663
581
 
664
582
  if (!contactDepartment) {
665
583
  return null;
@@ -676,38 +594,27 @@ function normalizeOrganizationChildPreferredContact(
676
594
  /*
677
595
  * Return preferred child-organization contacts in the array shape expected by directory helpers.
678
596
  */
679
- export function getOrganizationChildPreferredContacts(
680
- childOrganization?: OrganizationChildContactSource | null,
681
- ): OrgContact[] {
597
+ export function getOrganizationChildPreferredContacts(childOrganization?: OrganizationChildContactSource | null): OrgContact[] {
682
598
  const preferredContacts = childOrganization?.preferredContacts;
683
599
 
684
600
  if (Array.isArray(preferredContacts)) {
685
601
  return preferredContacts
686
- .map((contact) =>
687
- normalizeOrganizationChildPreferredContact(contact.department, contact),
688
- )
602
+ .map((contact) => normalizeOrganizationChildPreferredContact(contact.department, contact))
689
603
  .filter(Boolean) as OrgContact[];
690
604
  }
691
605
 
692
606
  return Object.entries(preferredContacts || {})
693
- .map(([department, contact]) =>
694
- normalizeOrganizationChildPreferredContact(department, contact),
695
- )
607
+ .map(([department, contact]) => normalizeOrganizationChildPreferredContact(department, contact))
696
608
  .filter(Boolean) as OrgContact[];
697
609
  }
698
610
 
699
611
  /*
700
612
  * Return the child organization's directory with parent-specific preferred contacts applied.
701
613
  */
702
- export function getOrganizationChildMergedDirectory(
703
- childOrganization?: OrganizationChildContactSource | null,
704
- ): MergedOrgContact[] {
614
+ export function getOrganizationChildMergedDirectory(childOrganization?: OrganizationChildContactSource | null): MergedOrgContact[] {
705
615
  const organization = childOrganization?.organization;
706
616
 
707
- return mergeOrgDirectory(
708
- organization?.directory || [],
709
- getOrganizationChildPreferredContacts(childOrganization),
710
- );
617
+ return mergeOrgDirectory(organization?.directory || [], getOrganizationChildPreferredContacts(childOrganization));
711
618
  }
712
619
 
713
620
  /*
@@ -718,34 +625,21 @@ export function getOrganizationChildPrimaryContact(
718
625
  ): MergedOrgContact | null {
719
626
  const directory = getOrganizationChildMergedDirectory(childOrganization);
720
627
 
721
- return (
722
- directory.find((contact) => contact.department === 'PRIMARY_CONTACT') ||
723
- directory[0] ||
724
- null
725
- );
628
+ return directory.find((contact) => contact.department === 'PRIMARY_CONTACT') || directory[0] || null;
726
629
  }
727
630
 
728
631
  /*
729
632
  * Return whether one child-organization list cell should open the organization profile.
730
633
  */
731
634
  export function isOrganizationChildProfileLinkCellKey(cellKey: string) {
732
- return (
733
- cellKey === 'organizationId' ||
734
- cellKey === 'vendorName' ||
735
- cellKey === 'name'
736
- );
635
+ return cellKey === 'organizationId' || cellKey === 'vendorName' || cellKey === 'name';
737
636
  }
738
637
 
739
638
  /*
740
- * Return the display text used by child-organization lists and Sheet custom source cells.
639
+ * Return the display text used by child-organization lists.
741
640
  */
742
641
  export function getOrganizationChildListCellValue(
743
- childOrganization:
744
- | OrganizationChildData
745
- | OrganizationChildGQL
746
- | OrganizationChildContactSource
747
- | null
748
- | undefined,
642
+ childOrganization: OrganizationChildData | OrganizationChildGQL | OrganizationChildContactSource | null | undefined,
749
643
  cellKey: string,
750
644
  ): string {
751
645
  const organization = childOrganization?.organization;
@@ -753,24 +647,12 @@ export function getOrganizationChildListCellValue(
753
647
 
754
648
  switch (cellKey) {
755
649
  case 'organizationId': {
756
- const organizationReadableId =
757
- organization && 'readableId' in organization
758
- ? organization.readableId
759
- : null;
760
- const organizationId =
761
- organization && 'id' in organization ? organization.id : null;
762
- const childOrganizationId =
763
- childOrganization && 'childId' in childOrganization
764
- ? childOrganization.childId
765
- : null;
650
+ const organizationReadableId = organization && 'readableId' in organization ? organization.readableId : null;
651
+ const organizationId = organization && 'id' in organization ? organization.id : null;
652
+ const childOrganizationId = childOrganization && 'childId' in childOrganization ? childOrganization.childId : null;
766
653
 
767
654
  return (
768
- organizationReadableId ||
769
- (organizationId
770
- ? String(organizationId)
771
- : childOrganizationId
772
- ? String(childOrganizationId)
773
- : '')
655
+ organizationReadableId || (organizationId ? String(organizationId) : childOrganizationId ? String(childOrganizationId) : '')
774
656
  );
775
657
  }
776
658
  case 'name':
@@ -785,51 +667,3 @@ export function getOrganizationChildListCellValue(
785
667
  return '';
786
668
  }
787
669
  }
788
-
789
- /*
790
- * Return the organization id that backs formula comparisons for a child-organization list cell.
791
- */
792
- export function getOrganizationChildListCellFormulaValue(
793
- childOrganization:
794
- | OrganizationChildData
795
- | OrganizationChildGQL
796
- | OrganizationChildContactSource
797
- | null
798
- | undefined,
799
- formulaValueSource?:
800
- | SheetCustomRegionSourceColumnFormulaValueSourceEnum
801
- | string
802
- | null,
803
- ): string | null {
804
- if (formulaValueSource !== 'CHILD_ORGANIZATION_ID') {
805
- return null;
806
- }
807
-
808
- const organization = childOrganization?.organization;
809
- const organizationId =
810
- organization && 'id' in organization ? organization.id : null;
811
- const childOrganizationId =
812
- childOrganization && 'childId' in childOrganization
813
- ? childOrganization.childId
814
- : null;
815
- const formulaValue = organizationId ?? childOrganizationId ?? null;
816
-
817
- return formulaValue !== null ? String(formulaValue) : null;
818
- }
819
-
820
- /*
821
- * Return the formula comparison value for a child-organization list cell when only its row id is available.
822
- */
823
- export function getOrganizationChildListCellFormulaValueFromId(
824
- childOrganizationId: string | number | bigint | null | undefined,
825
- formulaValueSource?:
826
- | SheetCustomRegionSourceColumnFormulaValueSourceEnum
827
- | string
828
- | null,
829
- ): string | null {
830
- return formulaValueSource === 'CHILD_ORGANIZATION_ID' &&
831
- childOrganizationId !== null &&
832
- childOrganizationId !== undefined
833
- ? String(childOrganizationId)
834
- : null;
835
- }