Skip to main content

EOR Portal Constants

Configuration constants for EOR (Employer of Record) portal endpoint exclusions and parameter modifications.

Overview

The EOR Portal Constants define endpoints that should be excluded from EOR-specific parameter modifications. These constants ensure that certain API requests bypass additional EOR processing, maintaining proper functionality for core system operations.

Constants

Excluded EOR Endpoints

Array of endpoints that should bypass EOR-specific parameter modifications:

/**
* A constant array of endpoints that should be excluded from EOR-specific parameter modifications.
* Requests to these URLs will bypass additional EOR processing.
*/
export const EXCLUDED_EOR_ENDPOINTS = [
'/user/role',
'/home/company/account-settings',
'/home/user/profile',
'/user/subscription',
] as const;

Usage Examples

API Request Interceptor

import { EXCLUDED_EOR_ENDPOINTS } from '@/utils/constants/eor-portal';

// Check if endpoint should bypass EOR processing
const shouldExcludeFromEOR = (url: string): boolean => {
return EXCLUDED_EOR_ENDPOINTS.some(endpoint => url.includes(endpoint));
};

// Axios interceptor example
axios.interceptors.request.use(config => {
const { url } = config;

if (!shouldExcludeFromEOR(url)) {
// Apply EOR-specific modifications
config.params = {
...config.params,
eor_context: true,
portal_type: 'eor',
};
}

return config;
});

EOR Context Hook

import { useState, useEffect } from 'react';
import { EXCLUDED_EOR_ENDPOINTS } from '@/utils/constants/eor-portal';

interface EORContextState {
isEOREnabled: boolean;
shouldApplyEORParams: boolean;
excludedEndpoints: readonly string[];
}

export const useEORContext = (currentEndpoint?: string) => {
const [eorState, setEORState] = useState<EORContextState>({
isEOREnabled: false,
shouldApplyEORParams: true,
excludedEndpoints: EXCLUDED_EOR_ENDPOINTS,
});

useEffect(() => {
// Check if current endpoint should be excluded
const isExcluded =
currentEndpoint &&
EXCLUDED_EOR_ENDPOINTS.some(endpoint =>
currentEndpoint.includes(endpoint),
);

setEORState(prev => ({
...prev,
shouldApplyEORParams: !isExcluded,
}));
}, [currentEndpoint]);

const checkEndpointExclusion = (endpoint: string): boolean => {
return EXCLUDED_EOR_ENDPOINTS.some(excludedEndpoint =>
endpoint.includes(excludedEndpoint),
);
};

return {
...eorState,
checkEndpointExclusion,
};
};

EOR API Service

import { EXCLUDED_EOR_ENDPOINTS } from '@/utils/constants/eor-portal';

class EORAPIService {
private baseURL: string;
private eorParams: Record<string, any>;

constructor(baseURL: string) {
this.baseURL = baseURL;
this.eorParams = {
portal_type: 'eor',
eor_context: true,
};
}

private shouldApplyEORParams(endpoint: string): boolean {
return !EXCLUDED_EOR_ENDPOINTS.some(excludedEndpoint =>
endpoint.includes(excludedEndpoint),
);
}

private buildURL(endpoint: string, params?: Record<string, any>): string {
const url = new URL(endpoint, this.baseURL);

// Apply EOR params if endpoint is not excluded
if (this.shouldApplyEORParams(endpoint)) {
Object.entries(this.eorParams).forEach(([key, value]) => {
url.searchParams.set(key, String(value));
});
}

// Add additional params
if (params) {
Object.entries(params).forEach(([key, value]) => {
url.searchParams.set(key, String(value));
});
}

return url.toString();
}

async get(endpoint: string, params?: Record<string, any>) {
const url = this.buildURL(endpoint, params);
const response = await fetch(url);
return response.json();
}

async post(endpoint: string, data: any, params?: Record<string, any>) {
const url = this.buildURL(endpoint, params);
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
});
return response.json();
}
}

export default EORAPIService;

EOR Route Guard Component

import React from 'react';
import { EXCLUDED_EOR_ENDPOINTS } from '@/utils/constants/eor-portal';

interface EORRouteGuardProps {
currentPath: string;
children: React.ReactNode;
fallback?: React.ReactNode;
}

const EORRouteGuard: React.FC&lt;EORRouteGuardProps&gt; = ({
currentPath,
children,
fallback = null,
}) => {
const isExcludedRoute = EXCLUDED_EOR_ENDPOINTS.some(endpoint =>
currentPath.includes(endpoint),
);

// For excluded routes, render without EOR context
if (isExcludedRoute) {
return <>{children}</>;
}

// For non-excluded routes, wrap with EOR context
return (
<div className='eor-context' data-eor-enabled='true'>
{children}
</div>
);
};

export default EORRouteGuard;

EOR Configuration Manager

import { EXCLUDED_EOR_ENDPOINTS } from '@/utils/constants/eor-portal';

interface EORConfig {
enabled: boolean;
portalType: 'eor' | 'standard';
excludedEndpoints: readonly string[];
additionalParams: Record<string, any>;
}

class EORConfigManager {
private config: EORConfig;

constructor(initialConfig?: Partial&lt;EORConfig&gt;) {
this.config = {
enabled: true,
portalType: 'eor',
excludedEndpoints: EXCLUDED_EOR_ENDPOINTS,
additionalParams: {},
...initialConfig,
};
}

isEndpointExcluded(endpoint: string): boolean {
return this.config.excludedEndpoints.some(excludedEndpoint =>
endpoint.includes(excludedEndpoint),
);
}

getEORParams(endpoint: string): Record<string, any> {
if (!this.config.enabled || this.isEndpointExcluded(endpoint)) {
return {};
}

return {
portal_type: this.config.portalType,
eor_context: true,
...this.config.additionalParams,
};
}

updateConfig(updates: Partial&lt;EORConfig&gt;): void {
this.config = { ...this.config, ...updates };
}

getConfig(): EORConfig {
return { ...this.config };
}

addExcludedEndpoint(endpoint: string): void {
if (!this.config.excludedEndpoints.includes(endpoint)) {
this.config = {
...this.config,
excludedEndpoints: [...this.config.excludedEndpoints, endpoint],
};
}
}

removeExcludedEndpoint(endpoint: string): void {
this.config = {
...this.config,
excludedEndpoints: this.config.excludedEndpoints.filter(
excludedEndpoint => excludedEndpoint !== endpoint,
),
};
}
}

export default EORConfigManager;

EOR Middleware

import { EXCLUDED_EOR_ENDPOINTS } from '@/utils/constants/eor-portal';

interface RequestConfig {
url: string;
method: string;
params?: Record<string, any>;
data?: any;
}

export const eorMiddleware = (config: RequestConfig): RequestConfig => {
const { url } = config;

// Check if endpoint should be excluded from EOR processing
const isExcluded = EXCLUDED_EOR_ENDPOINTS.some(endpoint =>
url.includes(endpoint),
);

if (isExcluded) {
return config; // Return unchanged config
}

// Apply EOR-specific modifications
return {
...config,
params: {
...config.params,
portal_type: 'eor',
eor_context: true,
},
};
};

// Usage with fetch wrapper
export const eorFetch = async (
url: string,
options: RequestInit = {},
): Promise&lt;Response&gt; => {
const config = eorMiddleware({
url,
method: options.method || 'GET',
params: {},
});

// Build URL with EOR params if applicable
const finalUrl = new URL(url);
if (config.params) {
Object.entries(config.params).forEach(([key, value]) => {
finalUrl.searchParams.set(key, String(value));
});
}

return fetch(finalUrl.toString(), options);
};

EOR Context Provider

import React, { createContext, useContext, ReactNode } from 'react';
import { EXCLUDED_EOR_ENDPOINTS } from '@/utils/constants/eor-portal';

interface EORContextValue {
isEOREnabled: boolean;
excludedEndpoints: readonly string[];
checkEndpointExclusion: (endpoint: string) => boolean;
getEORParams: (endpoint: string) => Record<string, any>;
}

const EORContext = createContext<EORContextValue | undefined>(undefined);

interface EORProviderProps {
children: ReactNode;
enabled?: boolean;
}

export const EORProvider: React.FC&lt;EORProviderProps&gt; = ({
children,
enabled = true,
}) => {
const checkEndpointExclusion = (endpoint: string): boolean => {
return EXCLUDED_EOR_ENDPOINTS.some(excludedEndpoint =>
endpoint.includes(excludedEndpoint),
);
};

const getEORParams = (endpoint: string): Record<string, any> => {
if (!enabled || checkEndpointExclusion(endpoint)) {
return {};
}

return {
portal_type: 'eor',
eor_context: true,
};
};

const value: EORContextValue = {
isEOREnabled: enabled,
excludedEndpoints: EXCLUDED_EOR_ENDPOINTS,
checkEndpointExclusion,
getEORParams,
};

return <EORContext.Provider value={value}>{children}</EORContext.Provider>;
};

export const useEOR = (): EORContextValue => {
const context = useContext(EORContext);
if (!context) {
throw new Error('useEOR must be used within an EORProvider');
}
return context;
};

TypeScript Definitions

// EOR endpoint type
export type EOREndpoint = (typeof EXCLUDED_EOR_ENDPOINTS)[number];

// EOR configuration interface
export interface EORConfiguration {
enabled: boolean;
portalType: 'eor' | 'standard';
excludedEndpoints: readonly string[];
additionalParams?: Record<string, any>;
}

// EOR request parameters
export interface EORRequestParams {
portal_type?: 'eor' | 'standard';
eor_context?: boolean;
[key: string]: any;
}

// EOR middleware function type
export type EORMiddleware = (config: RequestConfig) => RequestConfig;

// EOR context state
export interface EORContextState {
isEOREnabled: boolean;
shouldApplyEORParams: boolean;
excludedEndpoints: readonly string[];
}

Best Practices

1. Endpoint Validation

// ✅ Good - validate endpoint format
const isValidEndpoint = (endpoint: string): boolean => {
return endpoint.startsWith('/') && endpoint.length > 1;
};

const checkExclusion = (endpoint: string): boolean => {
if (!isValidEndpoint(endpoint)) {
console.warn(`Invalid endpoint format: ${endpoint}`);
return false;
}

return EXCLUDED_EOR_ENDPOINTS.some(excluded => endpoint.includes(excluded));
};

2. Case-Insensitive Matching

// ✅ Good - case-insensitive endpoint matching
const isEndpointExcluded = (endpoint: string): boolean => {
const normalizedEndpoint = endpoint.toLowerCase();
return EXCLUDED_EOR_ENDPOINTS.some(excluded =>
normalizedEndpoint.includes(excluded.toLowerCase()),
);
};

3. Performance Optimization

// ✅ Good - cache exclusion results
const exclusionCache = new Map<string, boolean>();

const isEndpointExcludedCached = (endpoint: string): boolean => {
if (exclusionCache.has(endpoint)) {
return exclusionCache.get(endpoint)!;
}

const isExcluded = EXCLUDED_EOR_ENDPOINTS.some(excluded =>
endpoint.includes(excluded),
);

exclusionCache.set(endpoint, isExcluded);
return isExcluded;
};

Performance Considerations

1. Memoization

// Memoize endpoint exclusion checks
import { useMemo } from 'react';

export const useEORExclusion = (endpoint: string) => {
return useMemo(() => {
return EXCLUDED_EOR_ENDPOINTS.some(excluded => endpoint.includes(excluded));
}, [endpoint]);
};

2. Batch Processing

// Process multiple endpoints efficiently
export const checkMultipleEndpoints = (
endpoints: string[],
): Record<string, boolean> => {
return endpoints.reduce(
(acc, endpoint) => {
acc[endpoint] = EXCLUDED_EOR_ENDPOINTS.some(excluded =>
endpoint.includes(excluded),
);
return acc;
},
{} as Record<string, boolean>,
);
};

Migration Notes

When updating EOR portal constants:

  1. Test endpoint exclusions thoroughly after changes
  2. Maintain backward compatibility for existing integrations
  3. Update API documentation when adding new exclusions
  4. Consider impact on authentication flows for excluded endpoints
  5. Validate EOR parameter application across all non-excluded endpoints

Security Considerations

1. Sensitive Endpoints

// Ensure sensitive endpoints are properly excluded
const SENSITIVE_ENDPOINTS = [
'/user/role',
'/home/user/profile',
'/user/subscription',
] as const;

// Verify all sensitive endpoints are in exclusion list
const validateExclusions = (): boolean => {
return SENSITIVE_ENDPOINTS.every(endpoint =>
EXCLUDED_EOR_ENDPOINTS.includes(endpoint),
);
};

2. Parameter Sanitization

// Sanitize EOR parameters before applying
const sanitizeEORParams = (
params: Record<string, any>,
): Record<string, any> => {
const allowedParams = ['portal_type', 'eor_context'];

return Object.keys(params)
.filter(key => allowedParams.includes(key))
.reduce(
(acc, key) => {
acc[key] = params[key];
return acc;
},
{} as Record<string, any>,
);
};