PSA/shared/workflow/streams/domainEventBuilders/crmInteractionNoteEventBuilders.ts
Hermes 284313f908
Some checks are pending
Bidi Control Character Guard / bidi-control-guard (push) Waiting to run
Circular Dependency Check / Check for new circular dependencies (push) Waiting to run
Citus Migration Smoke / Combined migrations on single-node Citus (push) Waiting to run
E2E Fresh Install Tests / fresh-install-e2e (push) Waiting to run
ext-v2 guardrails / Run ext-v2 guard and ESLint (push) Waiting to run
Integration Tests / Check for relevant changes (push) Waiting to run
Integration Tests / ${{ (github.event_name == 'schedule' || github.event.inputs.suite == 'full') && 'Full integration suite' || 'Tier-1 integration subset' }} (push) Blocked by required conditions
Mobile checks / Mobile lint + typecheck (push) Waiting to run
Mobile checks / Mobile unit tests (push) Waiting to run
Mobile checks / Mobile dependency audit (report) (push) Waiting to run
Mobile checks / Mobile reproducibility checks (push) Waiting to run
Secrets guard (env backups) / Ensure no tracked env backup files (push) Waiting to run
Temporal Readiness / fast-readiness (push) Waiting to run
Temporal Readiness / docker-parity (push) Waiting to run
TypeScript Type Check / Nx affected typecheck (push) Waiting to run
Unit Tests / Skipped-test budget (push) Waiting to run
Unit Tests / Nx affected unit tests (push) Waiting to run
Unit Tests / Server unit coverage (informational) (push) Waiting to run
Validate Tenant Management Schema / Check for relevant changes (push) Waiting to run
Validate Tenant Management Schema / Validate Tenant Management Schema (push) Blocked by required conditions
EE Workflows Build Guard / ee-workflows-build-guard (push) Waiting to run
Initial import of AlgaPSA codebase from PSA server
Excluded: .git, node_modules, secrets/, compose.env, assemblyscript tgz

Source: /opt/alga-psa on psa.joliet.tech
2026-06-22 16:12:17 -05:00

88 lines
3.0 KiB
TypeScript

function normalizeDate(value?: Date | string): string | undefined {
if (!value) return undefined;
if (value instanceof Date) return value.toISOString();
return value;
}
function normalizeString(value: unknown): string | undefined {
if (typeof value !== 'string') return undefined;
const trimmed = value.trim();
return trimmed ? trimmed : undefined;
}
export function deriveInteractionChannel(interactionType: string): string {
const normalized = interactionType.trim().toLowerCase();
if (!normalized) return 'other';
if (normalized.includes('email')) return 'email';
if (normalized.includes('call') || normalized.includes('phone')) return 'phone';
if (normalized.includes('meeting')) return 'meeting';
if (normalized.includes('note')) return 'note';
return 'other';
}
function buildBodyPreview(value: unknown, maxLength: number): string | undefined {
let str: string;
if (typeof value === 'string') {
str = value;
} else {
try {
str = JSON.stringify(value);
} catch {
return undefined;
}
}
const normalized = normalizeString(str)?.replace(/\s+/g, ' ');
if (!normalized) return undefined;
if (normalized.length <= maxLength) return normalized;
return `${normalized.slice(0, maxLength)}`;
}
export function buildInteractionLoggedPayload(params: {
interactionId: string;
clientId: string;
contactId?: string;
interactionType: string;
channel?: string;
interactionOccurredAt?: Date | string;
loggedByUserId?: string;
subject?: string;
outcome?: string;
}): Record<string, unknown> {
const interactionType = normalizeString(params.interactionType) ?? 'interaction';
const channel = normalizeString(params.channel) ?? deriveInteractionChannel(interactionType);
return {
interactionId: params.interactionId,
clientId: params.clientId,
...(params.contactId ? { contactId: params.contactId } : {}),
interactionType,
channel,
...(params.interactionOccurredAt ? { interactionOccurredAt: normalizeDate(params.interactionOccurredAt) } : {}),
...(params.loggedByUserId ? { loggedByUserId: params.loggedByUserId } : {}),
...(normalizeString(params.subject) ? { subject: normalizeString(params.subject) } : {}),
...(normalizeString(params.outcome) ? { outcome: normalizeString(params.outcome) } : {}),
};
}
export function buildNoteCreatedPayload(params: {
noteId: string;
entityType: 'client' | 'contact';
entityId: string;
createdByUserId?: string;
createdAt?: Date | string;
visibility?: 'public' | 'internal';
bodyPreview?: unknown;
}): Record<string, unknown> {
return {
noteId: params.noteId,
entityType: params.entityType,
entityId: params.entityId,
...(params.createdByUserId ? { createdByUserId: params.createdByUserId } : {}),
...(params.createdAt ? { createdAt: normalizeDate(params.createdAt) } : {}),
...(params.visibility ? { visibility: params.visibility } : {}),
...(params.bodyPreview !== undefined ? { bodyPreview: buildBodyPreview(params.bodyPreview, 200) } : {}),
};
}