Initial commit
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
import type { Session } from '../types/kanban'
|
||||
|
||||
export type CanonicalSessionExecMode = 'task' | 'company' | 'org'
|
||||
export type CanonicalCompanyProfile = 'corporate' | 'custom'
|
||||
|
||||
export function normalizeSessionExecMode(value?: string | null): CanonicalSessionExecMode {
|
||||
const normalized = String(value ?? '').trim().toLowerCase()
|
||||
if (normalized === 'company') return 'company'
|
||||
if (normalized === 'org' || normalized === 'custom') return 'org'
|
||||
return 'task'
|
||||
}
|
||||
|
||||
export function normalizeSessionCompanyProfile(value?: string | null): CanonicalCompanyProfile {
|
||||
return String(value ?? '').trim().toLowerCase() === 'custom' ? 'custom' : 'corporate'
|
||||
}
|
||||
|
||||
export function canonicalizeSessionExecutionIdentity<T extends Partial<Session>>(session: T): T {
|
||||
const rawMode = String(session.execMode ?? '').trim().toLowerCase()
|
||||
const rawProfile = String(session.companyProfile ?? '').trim().toLowerCase()
|
||||
const rawOrgId = String(session.orgId ?? '').trim()
|
||||
const hasExplicitMode = rawMode.length > 0
|
||||
|
||||
const execMode: CanonicalSessionExecMode = hasExplicitMode
|
||||
? normalizeSessionExecMode(rawMode)
|
||||
: (rawProfile === 'custom' || rawOrgId ? 'org' : normalizeSessionExecMode(rawMode))
|
||||
|
||||
if (execMode === 'org') {
|
||||
return {
|
||||
...session,
|
||||
execMode: 'org',
|
||||
companyProfile: 'custom',
|
||||
orgId: rawOrgId || undefined,
|
||||
}
|
||||
}
|
||||
|
||||
if (execMode === 'company') {
|
||||
return {
|
||||
...session,
|
||||
execMode: 'company',
|
||||
companyProfile: 'corporate',
|
||||
orgId: undefined,
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
...session,
|
||||
execMode: 'task',
|
||||
companyProfile: undefined,
|
||||
orgId: undefined,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user