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
Excluded: .git, node_modules, secrets/, compose.env, assemblyscript tgz Source: /opt/alga-psa on psa.joliet.tech
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
const TENANT_ID_HEX_LENGTH = 32;
|
|
const TENANT_SLUG_LENGTH = 12;
|
|
const TENANT_SLUG_REGEX = /^[a-f0-9]{12}$/;
|
|
|
|
function normalizeTenantId(tenantId: string): string {
|
|
if (!tenantId) {
|
|
throw new Error('Tenant ID is required to build a portal slug');
|
|
}
|
|
|
|
const normalized = tenantId.replace(/-/g, '').toLowerCase();
|
|
if (normalized.length !== TENANT_ID_HEX_LENGTH) {
|
|
throw new Error(`Tenant ID must be a UUID with ${TENANT_ID_HEX_LENGTH} hex characters`);
|
|
}
|
|
return normalized;
|
|
}
|
|
|
|
export function buildTenantPortalSlug(tenantId: string): string {
|
|
const normalized = normalizeTenantId(tenantId);
|
|
return `${normalized.slice(0, 6)}${normalized.slice(-6)}`;
|
|
}
|
|
|
|
export function isValidTenantSlug(slug: string | null | undefined): slug is string {
|
|
if (!slug) {
|
|
return false;
|
|
}
|
|
return TENANT_SLUG_REGEX.test(slug.trim().toLowerCase());
|
|
}
|
|
|
|
export function getSlugParts(slug: string): { prefix: string; suffix: string } {
|
|
if (!isValidTenantSlug(slug)) {
|
|
throw new Error('Invalid tenant slug');
|
|
}
|
|
const normalized = slug.trim().toLowerCase();
|
|
return {
|
|
prefix: normalized.slice(0, 6),
|
|
suffix: normalized.slice(-6),
|
|
};
|
|
}
|
|
|
|
export { TENANT_SLUG_REGEX };
|