@jsb188/mday 1.1.10 → 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.
- package/package.json +140 -54
- package/src/constants/agentMemory.ts +123 -0
- package/src/constants/agentNote.ts +212 -0
- package/src/constants/aiChat.ts +10 -0
- package/src/constants/billing.ts +126 -0
- package/src/constants/campaign.ts +236 -0
- package/src/constants/contact.ts +72 -0
- package/src/constants/csvExport.ts +133 -0
- package/src/constants/dataTable.ts +21 -21
- package/src/constants/dataTableFieldTypes.generated.ts +59 -0
- package/src/constants/docAccess.ts +33 -0
- package/src/constants/dt.ts +234 -0
- package/src/constants/email.ts +125 -7
- package/src/constants/fieldDoc.ts +104 -0
- package/src/constants/graphqlReactivity.ts +196 -0
- package/src/constants/integration.ts +8 -9
- package/src/constants/log.ts +14 -408
- package/src/constants/logDisplay/README.md +88 -0
- package/src/constants/logDisplay/defaults.ts +39 -0
- package/src/constants/logDisplay/index.ts +27 -0
- package/src/constants/logDisplay/operations/arable.ts +16 -0
- package/src/constants/logDisplay/operations/farmersMarket.ts +10 -0
- package/src/constants/logDisplay/operations/foodManufacturing.ts +13 -0
- package/src/constants/logDisplay/shared/accounting.ts +13 -0
- package/src/constants/logDisplay/shared/interactions.ts +13 -0
- package/src/constants/logDisplay/shared/rackTemperatures.ts +42 -0
- package/src/constants/logTaxonomy.generated.ts +2207 -0
- package/src/constants/noteDoc.ts +77 -0
- package/src/constants/organization.ts +18 -21
- package/src/constants/pageRoute.ts +23 -0
- package/src/constants/qrCode.ts +30 -0
- package/src/constants/sheet.ts +126 -14
- package/src/constants/sms.ts +18 -0
- package/src/constants/square.ts +6 -6
- package/src/constants/storage.ts +80 -7
- package/src/constants/usage.ts +82 -0
- package/src/constants/workflowSteps.ts +60 -0
- package/src/schemas/editLogEntry.ts +836 -780
- package/src/schemas/inboundContact.ts +60 -55
- package/src/schemas/logsQuery.ts +55 -49
- package/src/types/account.d.ts +4 -1
- package/src/types/agentMemory.d.ts +98 -0
- package/src/types/agentNote.d.ts +443 -0
- package/src/types/billing.d.ts +537 -0
- package/src/types/campaign.d.ts +1533 -0
- package/src/types/contact.d.ts +15 -0
- package/src/types/csvExport.d.ts +213 -0
- package/src/types/dataAnalysis.d.ts +44 -0
- package/src/types/dataTable.d.ts +115 -403
- package/src/types/definitionElement.d.ts +35 -0
- package/src/types/docAccess.d.ts +96 -0
- package/src/types/dt.d.ts +257 -0
- package/src/types/email.d.ts +184 -24
- package/src/types/emailReplyReport.d.ts +76 -0
- package/src/types/fieldDoc.d.ts +702 -0
- package/src/types/fieldDocContract.d.ts +90 -0
- package/src/types/inboundContact.d.ts +10 -1
- package/src/types/log.d.ts +254 -295
- package/src/types/logDisplay.types.ts +85 -0
- package/src/types/organization.d.ts +91 -43
- package/src/types/pageRoute.d.ts +48 -0
- package/src/types/qrCode.d.ts +96 -0
- package/src/types/richText.d.ts +81 -0
- package/src/types/sheet.d.ts +678 -129
- package/src/types/sms.d.ts +38 -0
- package/src/types/storage.d.ts +449 -129
- package/src/types/usage.d.ts +106 -0
- package/src/types/workflow.d.ts +315 -54
- package/src/utils/agentMemory.ts +15 -0
- package/src/utils/agentNote.ts +850 -0
- package/src/utils/aiChat.ts +43 -0
- package/src/utils/aiChatWork.ts +64 -0
- package/src/utils/billing.ts +37 -0
- package/src/utils/campaign.ts +1174 -0
- package/src/utils/campaignAI.ts +72 -0
- package/src/utils/campaignAccess.ts +239 -0
- package/src/utils/campaignEmail.ts +601 -0
- package/src/utils/campaignEmailCompiler.ts +372 -0
- package/src/utils/campaignEmailImages.ts +60 -0
- package/src/utils/campaignEmailStyles.ts +544 -0
- package/src/utils/campaignLifecycle.ts +104 -0
- package/src/utils/campaignPreview.ts +285 -0
- package/src/utils/contact.ts +50 -0
- package/src/utils/csvExport.ts +19 -0
- package/src/utils/dataTable.ts +95 -618
- package/src/utils/dataTableFieldTypeRegistry.ts +106 -0
- package/src/utils/dataTableRelativeDate.ts +447 -0
- package/src/utils/definitionElement.ts +84 -0
- package/src/utils/docAccess.ts +383 -0
- package/src/utils/documentName.ts +53 -0
- package/src/utils/email.ts +317 -51
- package/src/utils/emailReplyReport.test.ts +187 -0
- package/src/utils/emailReplyReport.ts +143 -0
- package/src/utils/fieldDoc.ts +157 -0
- package/src/utils/fieldDocAnswers.ts +128 -0
- package/src/utils/fieldDocDefaults.ts +36 -0
- package/src/utils/fieldDocProgram.ts +36 -0
- package/src/utils/fieldDocSummary.ts +30 -0
- package/src/utils/log.ts +276 -192
- package/src/utils/logDisplay.helpers.ts +177 -0
- package/src/utils/logDisplay.ts +87 -0
- package/src/utils/logRegistryValue.ts +90 -0
- package/src/utils/logStoreRead.ts +262 -0
- package/src/utils/logTaxonomy.helpers.ts +17 -0
- package/src/utils/logTaxonomy.ts +76 -0
- package/src/utils/logTaxonomyDisplay.ts +395 -0
- package/src/utils/noteDoc.ts +609 -0
- package/src/utils/organization.ts +337 -84
- package/src/utils/pageRoute.ts +71 -0
- package/src/utils/qrCode.helpers.ts +189 -0
- package/src/utils/qrCode.test.ts +519 -0
- package/src/utils/qrCode.ts +273 -0
- package/src/utils/richTextHTML.ts +385 -0
- package/src/utils/sheet.ts +199 -107
- package/src/utils/sheetAxisMove.ts +616 -0
- package/src/utils/sheetBootstrap.ts +1402 -0
- package/src/utils/sheetCellLiteral.ts +101 -0
- package/src/utils/sheetCommand.ts +358 -0
- package/src/utils/sheetDesign.ts +705 -0
- package/src/utils/sheetExport.ts +186 -0
- package/src/utils/sheetFeatureReference.ts +183 -0
- package/src/utils/sheetFormulaArgs.ts +168 -0
- package/src/utils/sheetFormulaCompile.ts +475 -0
- package/src/utils/sheetFormulaConditionalAggregate.ts +254 -0
- package/src/utils/sheetFormulaCriteria.ts +656 -0
- package/src/utils/sheetFormulaDate.ts +444 -0
- package/src/utils/sheetFormulaEvaluation.ts +899 -0
- package/src/utils/sheetFormulaEvaluator.ts +997 -0
- package/src/utils/sheetFormulaFunctionHandlers.ts +403 -0
- package/src/utils/sheetFormulaLogical.ts +116 -0
- package/src/utils/sheetFormulaLookup.ts +488 -0
- package/src/utils/sheetFormulaMath.ts +48 -0
- package/src/utils/sheetFormulaParser.ts +729 -0
- package/src/utils/sheetFormulaRange.ts +330 -0
- package/src/utils/sheetFormulaReference.ts +703 -0
- package/src/utils/sheetFormulaReferenceAggregates.ts +313 -0
- package/src/utils/sheetFormulaReferenceDates.ts +237 -0
- package/src/utils/sheetFormulaReferenceLogical.ts +330 -0
- package/src/utils/sheetFormulaReferenceLookup.ts +341 -0
- package/src/utils/sheetFormulaReferenceMath.ts +95 -0
- package/src/utils/sheetFormulaReferenceRewrite.ts +220 -0
- package/src/utils/sheetFormulaReferenceText.ts +462 -0
- package/src/utils/sheetFormulaSyntax.ts +1027 -0
- package/src/utils/sheetFormulaText.ts +430 -0
- package/src/utils/sheetJournal.ts +200 -0
- package/src/utils/sheetNumberFormat.ts +1012 -0
- package/src/utils/sheetPreview.ts +68 -0
- package/src/utils/sheetSequence.ts +118 -0
- package/src/utils/sheetSnapshot.ts +739 -0
- package/src/utils/sheetStructureEdit.ts +914 -0
- package/src/utils/sheetStructureReferences.ts +389 -0
- package/src/utils/square.ts +22 -12
- package/src/utils/storage.ts +198 -0
- package/src/utils/table-route.ts +127 -11
- package/src/utils/time.ts +12 -0
- package/src/utils/workflow.ts +334 -40
- package/src/utils/workflowLogFingerprint.ts +302 -0
- package/src/utils/workflowLogRevisionSnapshot.ts +424 -0
- package/src/utils/workflowProgress.ts +280 -0
- package/src/utils/workflowTriggers.ts +61 -0
- package/tests/agentNote.test.ts +395 -0
- package/tests/campaignAI.test.ts +119 -0
- package/tests/campaignAccess.test.ts +239 -0
- package/tests/campaignEmail.test.ts +441 -0
- package/tests/campaignLifecycle.test.ts +134 -0
- package/tests/campaignPublication.test.ts +309 -0
- package/tests/dataTableFieldTypeRegistry.test.ts +111 -0
- package/tests/dataTableRelativeDate.test.ts +412 -0
- package/tests/docAccess.test.ts +525 -0
- package/tests/editLogEntry.test.ts +112 -0
- package/tests/email.test.ts +39 -0
- package/tests/fieldDocProgram.test.ts +114 -0
- package/tests/logDisplay.fixtures.ts +67 -0
- package/tests/logDisplay.test.ts +227 -0
- package/tests/noteDoc.test.ts +514 -0
- package/tests/richTextHTML.test.ts +185 -0
- package/tests/sheetAxisMove.test.ts +352 -0
- package/tests/sheetBootstrap.test.ts +1967 -0
- package/tests/sheetFeatureReference.test.ts +22 -0
- package/tests/sheetFormulaCriteria.test.ts +269 -0
- package/tests/sheetFormulaEvaluator.test.ts +468 -0
- package/tests/sheetFormulaFunctions.test.ts +538 -0
- package/tests/sheetFormulaLanguage.test.ts +361 -0
- package/tests/sheetFormulaParity.fixtures.ts +872 -0
- package/tests/sheetFormulaParity.test.ts +188 -0
- package/tests/sheetFormulaRange.test.ts +167 -0
- package/tests/sheetFormulaReference.test.ts +78 -0
- package/tests/sheetFormulaReferenceRewrite.test.ts +117 -0
- package/tests/sheetFormulaTextDate.test.ts +512 -0
- package/tests/sheetSequence.test.ts +22 -0
- package/tests/sheetSnapshot.test.ts +134 -0
- package/tests/sheetStructureEdit.test.ts +537 -0
- package/tests/sheetStructureReferences.test.ts +589 -0
- package/tests/workflowLifecycleStatus.test.ts +60 -0
- package/tests/workflowLogFingerprint.test.ts +203 -0
- package/tests/workflowLogRevisionSnapshot.test.ts +96 -0
- package/tests/workflowProgress.test.ts +180 -0
- package/tests/workflowTriggers.test.ts +29 -0
- package/tsconfig.json +10 -10
- package/vitest.config.ts +8 -0
- package/src/constants/log-activityTexts.ts +0 -235
- package/src/constants/product.ts +0 -42
- package/src/constants/report.ts +0 -44
- package/src/schemas/organization.ts +0 -65
- package/src/schemas/productsQuery.ts +0 -53
- package/src/schemas/reportsQuery.ts +0 -20
- package/src/types/product.d.ts +0 -84
- package/src/types/report.d.ts +0 -290
- package/src/utils/product-calEvent.ts +0 -455
- package/src/utils/report.ts +0 -158
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import type { SupportedLogLanguage } from '@jsb188/app/constants/app.ts';
|
|
2
|
+
import { COLORS, isSupportedLogLanguage } from '@jsb188/app/constants/app.ts';
|
|
3
3
|
import { shortenToSpace } from '@jsb188/app/utils/string.ts';
|
|
4
4
|
import { DEFAULT_TIMEZONE } from '@jsb188/app/utils/timeZone.ts';
|
|
5
|
-
import {
|
|
5
|
+
import { ORG_CONTACTS } from '../constants/organization.ts';
|
|
6
6
|
import type {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
ACLPermissionEnum,
|
|
8
|
+
MergedOrgContact,
|
|
9
|
+
OrganizationChildData,
|
|
10
|
+
OrganizationChildGQL,
|
|
11
|
+
OrganizationContactData,
|
|
12
|
+
OrganizationDepartmentEnum,
|
|
13
|
+
OrganizationOperationEnum,
|
|
14
|
+
OrganizationRelData,
|
|
15
|
+
OrganizationRelGQL,
|
|
16
|
+
OrganizationRoleEnum,
|
|
17
|
+
OrganizationSettingsObj,
|
|
18
|
+
OrgContact,
|
|
16
19
|
} from '../types/organization.d.ts';
|
|
17
20
|
|
|
18
21
|
// Placeholder to match Server import
|
|
@@ -20,19 +23,37 @@ type ViewerOrganization = any;
|
|
|
20
23
|
|
|
21
24
|
type OperationPermissionTuple = readonly [PermissionCheckFor, ACLPermissionEnum, string];
|
|
22
25
|
type OperationPermissionsMap = Record<string, OperationPermissionTuple>;
|
|
26
|
+
type OrganizationChildPreferredContacts = OrgContact[] | Record<string, Partial<OrgContact> | null | undefined> | null | undefined;
|
|
27
|
+
type OrganizationChildContactSource = {
|
|
28
|
+
organization?: {
|
|
29
|
+
id?: string | number | bigint | null;
|
|
30
|
+
readableId?: string | null;
|
|
31
|
+
directory?: OrgContact[] | null;
|
|
32
|
+
name?: string | null;
|
|
33
|
+
operation?: OrganizationOperationEnum | string | null;
|
|
34
|
+
} | null;
|
|
35
|
+
preferredContacts?: OrganizationChildPreferredContacts;
|
|
36
|
+
};
|
|
23
37
|
|
|
24
38
|
export const OPERATION_PERMISSIONS = {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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."],
|
|
34
54
|
org_sites_update: ['logs', 'WRITE', 'You do not have permission to update organization sites.'],
|
|
35
|
-
|
|
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.'],
|
|
36
57
|
} as const satisfies OperationPermissionsMap;
|
|
37
58
|
|
|
38
59
|
export type OperationName = keyof typeof OPERATION_PERMISSIONS;
|
|
@@ -88,11 +109,7 @@ export function sanitizeOrganizationInboundEmailHandleInput(value?: string | nul
|
|
|
88
109
|
export function isValidOrganizationInboundEmailHandle(value?: string | null): boolean {
|
|
89
110
|
const handle = String(value || '');
|
|
90
111
|
|
|
91
|
-
return !!(
|
|
92
|
-
handle &&
|
|
93
|
-
handle.length <= ORGANIZATION_INBOUND_EMAIL_MAX_LENGTH &&
|
|
94
|
-
ORGANIZATION_INBOUND_EMAIL_ALLOWED_REGEX.test(handle)
|
|
95
|
-
);
|
|
112
|
+
return !!(handle && handle.length <= ORGANIZATION_INBOUND_EMAIL_MAX_LENGTH && ORGANIZATION_INBOUND_EMAIL_ALLOWED_REGEX.test(handle));
|
|
96
113
|
}
|
|
97
114
|
|
|
98
115
|
const INT_TO_PERMISSION = Object.keys(PERMISSION_TO_INT);
|
|
@@ -103,13 +120,7 @@ const INT_TO_PERMISSION = Object.keys(PERMISSION_TO_INT);
|
|
|
103
120
|
*/
|
|
104
121
|
|
|
105
122
|
export function getRoleValue(role: OrganizationRoleEnum): number {
|
|
106
|
-
return [
|
|
107
|
-
'GUEST',
|
|
108
|
-
'MEMBER',
|
|
109
|
-
'MANAGER',
|
|
110
|
-
'ADMIN',
|
|
111
|
-
'OWNER',
|
|
112
|
-
].indexOf(role);
|
|
123
|
+
return ['GUEST', 'MEMBER', 'MANAGER', 'ADMIN', 'OWNER'].indexOf(role);
|
|
113
124
|
}
|
|
114
125
|
|
|
115
126
|
/**
|
|
@@ -135,8 +146,21 @@ export function getDefaultPermissionsByRole(orgRel: OrganizationRelGQL | Organiz
|
|
|
135
146
|
// 0 = "NONE"
|
|
136
147
|
|
|
137
148
|
switch (role) {
|
|
138
|
-
case 'ADMIN':
|
|
139
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':
|
|
140
164
|
return {
|
|
141
165
|
billing: acl.billing || 'MANAGE',
|
|
142
166
|
compliance: acl.compliance || 'MANAGE',
|
|
@@ -146,7 +170,7 @@ export function getDefaultPermissionsByRole(orgRel: OrganizationRelGQL | Organiz
|
|
|
146
170
|
logs: acl.logs || 'MANAGE', // "READ" for logs does nothing
|
|
147
171
|
members: acl.members || 'MANAGE',
|
|
148
172
|
orgManagement: acl.orgManagement || 'MANAGE',
|
|
149
|
-
products: acl.products || 'MANAGE', // products =
|
|
173
|
+
products: acl.products || 'MANAGE', // products = field docs
|
|
150
174
|
settings: acl.settings || 'MANAGE',
|
|
151
175
|
viewData: acl.viewData || 'MANAGE', // This blocks access from users being able to read other people's logs
|
|
152
176
|
};
|
|
@@ -174,7 +198,7 @@ export function getDefaultPermissionsByRole(orgRel: OrganizationRelGQL | Organiz
|
|
|
174
198
|
logs: acl.logs || 'NONE',
|
|
175
199
|
members: acl.members || 'NONE',
|
|
176
200
|
orgManagement: acl.orgManagement || 'NONE',
|
|
177
|
-
products: acl.products || 'READ', // products =
|
|
201
|
+
products: acl.products || 'READ', // products = field docs
|
|
178
202
|
settings: acl.settings || 'NONE',
|
|
179
203
|
viewData: acl.viewData || 'READ',
|
|
180
204
|
};
|
|
@@ -191,7 +215,7 @@ export function getDefaultPermissionsByRole(orgRel: OrganizationRelGQL | Organiz
|
|
|
191
215
|
logs: acl.logs || 'WRITE', // "READ" for logs does nothing, also "WRITE" is required for directory/site management
|
|
192
216
|
members: acl.members || 'READ',
|
|
193
217
|
orgManagement: acl.orgManagement || 'READ',
|
|
194
|
-
products: acl.products || 'READ', // products =
|
|
218
|
+
products: acl.products || 'READ', // products = field docs
|
|
195
219
|
settings: acl.settings || 'READ',
|
|
196
220
|
viewData: acl.viewData || 'WRITE',
|
|
197
221
|
};
|
|
@@ -227,14 +251,14 @@ export function checkACLPermission(
|
|
|
227
251
|
|
|
228
252
|
export function checkACL(
|
|
229
253
|
orgRel: OrganizationRelGQL | OrganizationRelData | ViewerOrganization | null | undefined,
|
|
230
|
-
|
|
254
|
+
opName: OperationName,
|
|
231
255
|
) {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
256
|
+
const [permissionCheckFor, requiredPermission] = OPERATION_PERMISSIONS[opName] || [];
|
|
257
|
+
if (!permissionCheckFor || !requiredPermission) {
|
|
258
|
+
console.warn(`Operation ${opName} not found in permissions map.`);
|
|
259
|
+
return null;
|
|
260
|
+
}
|
|
261
|
+
return checkACLPermission(orgRel, permissionCheckFor, requiredPermission);
|
|
238
262
|
}
|
|
239
263
|
|
|
240
264
|
/**
|
|
@@ -242,9 +266,7 @@ export function checkACL(
|
|
|
242
266
|
* @returns true if at least one ACL permission differs from default role ACL
|
|
243
267
|
*/
|
|
244
268
|
|
|
245
|
-
export function isCustomACLForRole(
|
|
246
|
-
orgRel: OrganizationRelGQL | OrganizationRelData | ViewerOrganization | null | undefined,
|
|
247
|
-
): boolean {
|
|
269
|
+
export function isCustomACLForRole(orgRel: OrganizationRelGQL | OrganizationRelData | ViewerOrganization | null | undefined): boolean {
|
|
248
270
|
if (!orgRel) {
|
|
249
271
|
return false;
|
|
250
272
|
}
|
|
@@ -275,54 +297,105 @@ export function isCustomACLForRole(
|
|
|
275
297
|
|
|
276
298
|
export function getDefaultOrganizationSettings(
|
|
277
299
|
timeZone: string | null,
|
|
278
|
-
contacts?: OrgContact[],
|
|
279
300
|
// do params here for priority service + manage roles
|
|
280
301
|
): Partial<OrganizationSettingsObj> {
|
|
281
|
-
|
|
302
|
+
return {
|
|
282
303
|
timeZone: timeZone || DEFAULT_TIMEZONE,
|
|
304
|
+
displayTranslatedLogs: true,
|
|
305
|
+
translateLanguage: 'en',
|
|
283
306
|
color: COLORS[Math.floor(Math.random() * COLORS.length)],
|
|
284
307
|
};
|
|
308
|
+
}
|
|
285
309
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
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;
|
|
293
321
|
}
|
|
294
322
|
|
|
295
|
-
return
|
|
323
|
+
return isSupportedLogLanguage(value) ? value : 'en';
|
|
296
324
|
}
|
|
297
325
|
|
|
298
|
-
|
|
299
|
-
*
|
|
300
|
-
* If none or empty, return the default features based on operation
|
|
326
|
+
/*
|
|
327
|
+
* Return whether organization log views should prefer available translated text.
|
|
301
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
|
+
}
|
|
302
334
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
return
|
|
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;
|
|
311
345
|
}
|
|
312
346
|
|
|
313
|
-
|
|
314
|
-
* Map
|
|
315
|
-
|
|
316
|
-
|
|
347
|
+
/*
|
|
348
|
+
* Map organization_contacts rows to plain directory contacts, ordered by department.
|
|
349
|
+
*/
|
|
350
|
+
export function mapOrgContactRowsToContacts(rows?: Array<Partial<OrganizationContactData>> | null): OrgContact[] {
|
|
351
|
+
return (rows || [])
|
|
352
|
+
.filter((row) => row.department)
|
|
353
|
+
.map((row) => ({
|
|
354
|
+
department: row.department as OrganizationDepartmentEnum,
|
|
355
|
+
name: row.name || null,
|
|
356
|
+
phoneNumber: row.phoneNumber || null,
|
|
357
|
+
emailAddress: row.emailAddress || null,
|
|
358
|
+
}))
|
|
359
|
+
.sort((a, b) => ORG_CONTACTS.indexOf(a.department) - ORG_CONTACTS.indexOf(b.department));
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/*
|
|
363
|
+
* Map parent-override organization_contacts rows to the department-keyed preferred contacts shape.
|
|
317
364
|
*/
|
|
365
|
+
export function mapOrgContactRowsToPreferredContactsMap(
|
|
366
|
+
rows?: Array<Partial<OrganizationContactData>> | null,
|
|
367
|
+
): Record<string, OrgContact> {
|
|
368
|
+
return mapOrgContactRowsToContacts(rows).reduce(
|
|
369
|
+
(acc, contact) => {
|
|
370
|
+
acc[contact.department] = contact;
|
|
371
|
+
return acc;
|
|
372
|
+
},
|
|
373
|
+
{} as Record<string, OrgContact>,
|
|
374
|
+
);
|
|
375
|
+
}
|
|
318
376
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
377
|
+
/*
|
|
378
|
+
* Split one org's contact rows into own-directory rows and one parent's override rows.
|
|
379
|
+
*/
|
|
380
|
+
export function splitOrgContactRowsByScope(
|
|
381
|
+
rows: Array<Partial<OrganizationContactData>>,
|
|
382
|
+
ownerOrgId?: number | bigint | null,
|
|
383
|
+
): {
|
|
384
|
+
ownRows: Array<Partial<OrganizationContactData>>;
|
|
385
|
+
overrideRows: Array<Partial<OrganizationContactData>>;
|
|
386
|
+
} {
|
|
387
|
+
const ownRows: Array<Partial<OrganizationContactData>> = [];
|
|
388
|
+
const overrideRows: Array<Partial<OrganizationContactData>> = [];
|
|
389
|
+
|
|
390
|
+
for (const row of rows) {
|
|
391
|
+
if (row.ownerOrgId == null) {
|
|
392
|
+
ownRows.push(row);
|
|
393
|
+
} else if (ownerOrgId != null && row.ownerOrgId == ownerOrgId) {
|
|
394
|
+
overrideRows.push(row);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
324
397
|
|
|
325
|
-
return
|
|
398
|
+
return { ownRows, overrideRows };
|
|
326
399
|
}
|
|
327
400
|
|
|
328
401
|
/**
|
|
@@ -335,11 +408,9 @@ function hasPreferredOverride(dirContact: OrgContact, preferred?: OrgContact) {
|
|
|
335
408
|
}
|
|
336
409
|
|
|
337
410
|
return (
|
|
338
|
-
preferred.name !== undefined && preferred.name !== dirContact.name
|
|
339
|
-
|
|
340
|
-
preferred.
|
|
341
|
-
) || (
|
|
342
|
-
preferred.emailAddress !== undefined && preferred.emailAddress !== dirContact.emailAddress
|
|
411
|
+
(preferred.name !== undefined && preferred.name !== dirContact.name) ||
|
|
412
|
+
(preferred.phoneNumber !== undefined && preferred.phoneNumber !== dirContact.phoneNumber) ||
|
|
413
|
+
(preferred.emailAddress !== undefined && preferred.emailAddress !== dirContact.emailAddress)
|
|
343
414
|
);
|
|
344
415
|
}
|
|
345
416
|
|
|
@@ -414,3 +485,185 @@ export function mergeOrgDirectory(
|
|
|
414
485
|
|
|
415
486
|
return merged;
|
|
416
487
|
}
|
|
488
|
+
|
|
489
|
+
/*
|
|
490
|
+
* Upsert one preferred contact by department without mutating the source list.
|
|
491
|
+
*/
|
|
492
|
+
export function upsertOrgPreferredContactByDepartment(
|
|
493
|
+
preferredContacts: OrgContact[] | undefined,
|
|
494
|
+
department: OrgContact['department'],
|
|
495
|
+
values: Partial<Pick<OrgContact, 'emailAddress' | 'name' | 'phoneNumber'>>,
|
|
496
|
+
): OrgContact[] {
|
|
497
|
+
const source = preferredContacts || [];
|
|
498
|
+
const nextContact: OrgContact = {
|
|
499
|
+
department,
|
|
500
|
+
name: values.name || null,
|
|
501
|
+
phoneNumber: values.phoneNumber || null,
|
|
502
|
+
emailAddress: values.emailAddress || null,
|
|
503
|
+
};
|
|
504
|
+
|
|
505
|
+
if (!source.some((contact) => contact.department === department)) {
|
|
506
|
+
return [...source, nextContact];
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
return source.map((contact) => (contact.department === department ? nextContact : contact));
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/*
|
|
513
|
+
* Remove one preferred contact department without mutating the source list.
|
|
514
|
+
*/
|
|
515
|
+
export function removeOrgPreferredContactByDepartment(
|
|
516
|
+
preferredContacts: OrgContact[] | undefined,
|
|
517
|
+
department: OrgContact['department'],
|
|
518
|
+
): OrgContact[] {
|
|
519
|
+
return (preferredContacts || []).filter((contact) => contact.department !== department);
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/*
|
|
523
|
+
* Restore one preferred contact department from a saved contact snapshot.
|
|
524
|
+
*/
|
|
525
|
+
export function restoreOrgPreferredContactByDepartment(
|
|
526
|
+
currentPreferredContacts: OrgContact[] | undefined,
|
|
527
|
+
savedPreferredContacts: OrgContact[] | undefined,
|
|
528
|
+
department: OrgContact['department'],
|
|
529
|
+
): OrgContact[] {
|
|
530
|
+
const savedContact = (savedPreferredContacts || []).find((contact) => contact.department === department);
|
|
531
|
+
const withoutDepartment = (currentPreferredContacts || []).filter((contact) => contact.department !== department);
|
|
532
|
+
|
|
533
|
+
return savedContact ? [...withoutDepartment, savedContact] : withoutDepartment;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/*
|
|
537
|
+
* Find the editable version of a merged contact department.
|
|
538
|
+
*/
|
|
539
|
+
export function getEditableOrgContactByDepartment(
|
|
540
|
+
list: MergedOrgContact[],
|
|
541
|
+
department: OrgContact['department'],
|
|
542
|
+
): MergedOrgContact | null {
|
|
543
|
+
return list.find((item) => item.department === department && !item.locked) || null;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/*
|
|
547
|
+
* Compare preferred-contact lists by normalized department and value pairs.
|
|
548
|
+
*/
|
|
549
|
+
export function areOrgPreferredContactsEqual(a?: OrgContact[] | null, b?: OrgContact[] | null) {
|
|
550
|
+
const sourceA = a || [];
|
|
551
|
+
const sourceB = b || [];
|
|
552
|
+
|
|
553
|
+
if (sourceA.length !== sourceB.length) {
|
|
554
|
+
return false;
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
const normalizedA = [...sourceA].sort((x, y) => x.department.localeCompare(y.department));
|
|
558
|
+
const normalizedB = [...sourceB].sort((x, y) => x.department.localeCompare(y.department));
|
|
559
|
+
|
|
560
|
+
return normalizedA.every((item, index) => {
|
|
561
|
+
const other = normalizedB[index];
|
|
562
|
+
|
|
563
|
+
return (
|
|
564
|
+
item.department === other.department &&
|
|
565
|
+
(item.name || null) === (other.name || null) &&
|
|
566
|
+
(item.phoneNumber || null) === (other.phoneNumber || null) &&
|
|
567
|
+
(item.emailAddress || null) === (other.emailAddress || null)
|
|
568
|
+
);
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/*
|
|
573
|
+
* Return one preferred contact with a department supplied from the map key when needed.
|
|
574
|
+
*/
|
|
575
|
+
function normalizeOrganizationChildPreferredContact(department: string, contact?: Partial<OrgContact> | null): OrgContact | null {
|
|
576
|
+
if (!contact) {
|
|
577
|
+
return null;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
const contactDepartment = contact.department || (department as OrganizationDepartmentEnum);
|
|
581
|
+
|
|
582
|
+
if (!contactDepartment) {
|
|
583
|
+
return null;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
return {
|
|
587
|
+
department: contactDepartment,
|
|
588
|
+
name: contact.name,
|
|
589
|
+
phoneNumber: contact.phoneNumber,
|
|
590
|
+
emailAddress: contact.emailAddress,
|
|
591
|
+
};
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
/*
|
|
595
|
+
* Return preferred child-organization contacts in the array shape expected by directory helpers.
|
|
596
|
+
*/
|
|
597
|
+
export function getOrganizationChildPreferredContacts(childOrganization?: OrganizationChildContactSource | null): OrgContact[] {
|
|
598
|
+
const preferredContacts = childOrganization?.preferredContacts;
|
|
599
|
+
|
|
600
|
+
if (Array.isArray(preferredContacts)) {
|
|
601
|
+
return preferredContacts
|
|
602
|
+
.map((contact) => normalizeOrganizationChildPreferredContact(contact.department, contact))
|
|
603
|
+
.filter(Boolean) as OrgContact[];
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
return Object.entries(preferredContacts || {})
|
|
607
|
+
.map(([department, contact]) => normalizeOrganizationChildPreferredContact(department, contact))
|
|
608
|
+
.filter(Boolean) as OrgContact[];
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
/*
|
|
612
|
+
* Return the child organization's directory with parent-specific preferred contacts applied.
|
|
613
|
+
*/
|
|
614
|
+
export function getOrganizationChildMergedDirectory(childOrganization?: OrganizationChildContactSource | null): MergedOrgContact[] {
|
|
615
|
+
const organization = childOrganization?.organization;
|
|
616
|
+
|
|
617
|
+
return mergeOrgDirectory(organization?.directory || [], getOrganizationChildPreferredContacts(childOrganization));
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
/*
|
|
621
|
+
* Return the primary contact shown for one child organization relationship.
|
|
622
|
+
*/
|
|
623
|
+
export function getOrganizationChildPrimaryContact(
|
|
624
|
+
childOrganization?: OrganizationChildContactSource | null,
|
|
625
|
+
): MergedOrgContact | null {
|
|
626
|
+
const directory = getOrganizationChildMergedDirectory(childOrganization);
|
|
627
|
+
|
|
628
|
+
return directory.find((contact) => contact.department === 'PRIMARY_CONTACT') || directory[0] || null;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
/*
|
|
632
|
+
* Return whether one child-organization list cell should open the organization profile.
|
|
633
|
+
*/
|
|
634
|
+
export function isOrganizationChildProfileLinkCellKey(cellKey: string) {
|
|
635
|
+
return cellKey === 'organizationId' || cellKey === 'vendorName' || cellKey === 'name';
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
/*
|
|
639
|
+
* Return the display text used by child-organization lists.
|
|
640
|
+
*/
|
|
641
|
+
export function getOrganizationChildListCellValue(
|
|
642
|
+
childOrganization: OrganizationChildData | OrganizationChildGQL | OrganizationChildContactSource | null | undefined,
|
|
643
|
+
cellKey: string,
|
|
644
|
+
): string {
|
|
645
|
+
const organization = childOrganization?.organization;
|
|
646
|
+
const primaryContact = getOrganizationChildPrimaryContact(childOrganization);
|
|
647
|
+
|
|
648
|
+
switch (cellKey) {
|
|
649
|
+
case 'organizationId': {
|
|
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;
|
|
653
|
+
|
|
654
|
+
return (
|
|
655
|
+
organizationReadableId || (organizationId ? String(organizationId) : childOrganizationId ? String(childOrganizationId) : '')
|
|
656
|
+
);
|
|
657
|
+
}
|
|
658
|
+
case 'name':
|
|
659
|
+
return organization?.name || '';
|
|
660
|
+
case 'phone':
|
|
661
|
+
return primaryContact?.phoneNumber || '';
|
|
662
|
+
case 'email':
|
|
663
|
+
return primaryContact?.emailAddress || '';
|
|
664
|
+
case 'type':
|
|
665
|
+
return organization?.operation || '';
|
|
666
|
+
default:
|
|
667
|
+
return '';
|
|
668
|
+
}
|
|
669
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PAGE_ROUTE_MAX_COLUMNS,
|
|
3
|
+
PAGE_ROUTE_QUERY_ENUMS,
|
|
4
|
+
PAGE_ROUTE_RESERVED_SLUGS,
|
|
5
|
+
PAGE_ROUTE_SLUG_MAX_LENGTH,
|
|
6
|
+
PAGE_ROUTE_SLUG_MIN_LENGTH,
|
|
7
|
+
} from '../constants/pageRoute.ts';
|
|
8
|
+
import { isValidTableRouteColumnSettingsKey } from './table-route.ts';
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
* Normalize free-form input into a page route slug candidate.
|
|
12
|
+
*/
|
|
13
|
+
export function normalizePageRouteSlug(value?: string | null) {
|
|
14
|
+
return String(value || '')
|
|
15
|
+
.trim()
|
|
16
|
+
.toLowerCase();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/*
|
|
20
|
+
* Return whether a normalized page route slug is valid and not reserved.
|
|
21
|
+
*/
|
|
22
|
+
export function isValidPageRouteSlug(slug?: string | null) {
|
|
23
|
+
return (
|
|
24
|
+
!!slug &&
|
|
25
|
+
slug.length >= PAGE_ROUTE_SLUG_MIN_LENGTH &&
|
|
26
|
+
slug.length <= PAGE_ROUTE_SLUG_MAX_LENGTH &&
|
|
27
|
+
/^[a-z0-9_-]+$/.test(slug) &&
|
|
28
|
+
!PAGE_ROUTE_RESERVED_SLUGS.includes(slug)
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/*
|
|
33
|
+
* Return whether a value is a supported page route query name.
|
|
34
|
+
*/
|
|
35
|
+
export function isValidPageRouteQuery(value?: string | null) {
|
|
36
|
+
return !!value && PAGE_ROUTE_QUERY_ENUMS.includes(value);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/*
|
|
40
|
+
* Return a unique, charset-validated page route column key list; null when any key is invalid.
|
|
41
|
+
*/
|
|
42
|
+
export function getPageRouteColumnsFromInput(columns?: string[] | null) {
|
|
43
|
+
if (!Array.isArray(columns)) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const seenColumnKeys = new Set<string>();
|
|
48
|
+
const columnKeys = columns.reduce((acc, value) => {
|
|
49
|
+
const columnKey = String(value || '');
|
|
50
|
+
|
|
51
|
+
if (
|
|
52
|
+
!isValidTableRouteColumnSettingsKey(columnKey) ||
|
|
53
|
+
seenColumnKeys.has(columnKey)
|
|
54
|
+
) {
|
|
55
|
+
return acc;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
seenColumnKeys.add(columnKey);
|
|
59
|
+
acc.push(columnKey);
|
|
60
|
+
return acc;
|
|
61
|
+
}, [] as string[]);
|
|
62
|
+
|
|
63
|
+
if (
|
|
64
|
+
columnKeys.length !== columns.length ||
|
|
65
|
+
columnKeys.length > PAGE_ROUTE_MAX_COLUMNS
|
|
66
|
+
) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return columnKeys;
|
|
71
|
+
}
|