@coretext-ai/public-gusto-mcp-c0d1e2f3-a4b5-4678-b901-012345678901
Version:
MCP server with full gusto capabilities (29 endpoints)
3,131 lines • 152 kB
JavaScript
import axios from 'axios';
import { Logger } from '../services/logger.js';
export class GustoClient {
constructor(config) {
this.config = config;
// Generate unique session ID for this client instance
this.sessionId = `gusto-${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
// Initialize logger (fallback to console if not provided)
this.logger = config.logger || new Logger({
logLevel: 'ERROR',
component: 'client',
enableConsole: true,
enableShipping: false,
serverName: 'public-gusto-mcp'
});
this.logger.info('CLIENT_INIT', 'Client instance created', {
baseUrl: this.resolveBaseUrl(),
timeout: this.config.timeout || 30000,
hasRateLimit: !!this.config.rateLimit,
configKeys: Object.keys(config)
});
this.httpClient = axios.create({
baseURL: this.resolveBaseUrl(),
timeout: this.config.timeout || 30000,
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'User-Agent': 'public-gusto-mcp/1.0.0',
...this.getAuthHeaders()
},
});
// Add request interceptor for rate limiting
if (this.config.rateLimit) {
this.setupRateLimit(this.config.rateLimit);
}
// Add request interceptor for logging
this.httpClient.interceptors.request.use((config) => {
this.logger.logRequestStart(config.method?.toUpperCase() || 'GET', `${config.baseURL}${config.url}`, {
hasData: !!config.data,
hasParams: !!(config.params && Object.keys(config.params).length > 0),
headers: Object.keys(config.headers || {})
});
if (config.data) {
this.logger.debug('HTTP_REQUEST_BODY', 'Request body data', {
dataType: typeof config.data,
dataSize: JSON.stringify(config.data).length
});
}
if (config.params && Object.keys(config.params).length > 0) {
this.logger.debug('HTTP_REQUEST_PARAMS', 'Query parameters', {
paramCount: Object.keys(config.params).length,
paramKeys: Object.keys(config.params)
});
}
return config;
}, (error) => {
this.logger.error('HTTP_REQUEST_ERROR', 'Request interceptor error', {
error: error.message,
code: error.code
});
return Promise.reject(error);
});
// Add response interceptor for logging and error handling
this.httpClient.interceptors.response.use((response) => {
this.logger.logRequestSuccess(response.config?.method?.toUpperCase() || 'GET', `${response.config?.baseURL}${response.config?.url}`, response.status, 0, // Duration will be calculated in endpoint methods
{
statusText: response.statusText,
responseSize: JSON.stringify(response.data).length,
headers: Object.keys(response.headers || {})
});
return response;
}, (error) => {
this.logger.logRequestError(error.config?.method?.toUpperCase() || 'GET', `${error.config?.baseURL}${error.config?.url}`, error, 0, // Duration will be calculated in endpoint methods
{
hasResponseData: !!error.response?.data
});
throw error;
});
}
setupRateLimit(requestsPerMinute) {
const interval = 60000 / requestsPerMinute; // ms between requests
let lastRequestTime = 0;
this.logger.info('RATE_LIMIT_SETUP', 'Rate limiting configured', {
requestsPerMinute,
intervalMs: interval
});
this.httpClient.interceptors.request.use(async (config) => {
const now = Date.now();
const timeSinceLastRequest = now - lastRequestTime;
if (timeSinceLastRequest < interval) {
const delayMs = interval - timeSinceLastRequest;
this.logger.logRateLimit('HTTP_REQUEST', delayMs, {
timeSinceLastRequest,
requiredInterval: interval
});
await new Promise(resolve => setTimeout(resolve, delayMs));
}
lastRequestTime = Date.now();
return config;
});
}
resolveBaseUrl() {
let baseUrl = 'https://api.gusto-demo.com/v1';
// Handle dynamic domain replacement (e.g., YOUR_DOMAIN placeholder)
if (baseUrl.includes('YOUR_DOMAIN')) {
const domainEnvVar = `GUSTO_DOMAIN`;
const domain = process.env[domainEnvVar];
if (!domain) {
throw new Error(`Missing domain configuration. Please set ${domainEnvVar} environment variable.`);
}
baseUrl = baseUrl.replace('YOUR_DOMAIN', domain);
console.error(`[GUSTO] Resolved base URL: ${baseUrl}`);
}
return baseUrl;
}
getAuthHeaders() {
// Bearer/API key authentication (static tokens)
const token = this.config.authToken || this.config['gUSTOAPITOKEN'] || process.env.GUSTO_API_TOKEN;
if (token) {
this.logger.logAuthEvent('static_token_auth_setup', true, {
authType: 'bearer',
tokenPreview: token.substring(0, 8) + '...',
header: 'authorization',
source: 'static_configuration'
});
return {
'authorization': `Bearer ${token}`
};
}
this.logger.warn('AUTH_WARNING', 'No authentication token found', {
authType: 'bearer',
warning: 'API calls may be rate limited',
checkedSources: ['config.authToken', 'environment variables']
});
return {};
}
/**
* Initialize the client (for OAuth clients that need initialization)
*/
async initialize() {
this.logger.debug('CLIENT_INITIALIZE', 'No initialization required for this auth type');
}
/**
* Get the session ID for this client instance
*/
getSessionId() {
return this.sessionId;
}
/**
* Make an authenticated request with proper headers
*/
async makeAuthenticatedRequest(config) {
// For non-OAuth requests, log what auth headers are being used
this.logger.info('REQUEST_AUTH', 'Using pre-configured authentication headers', {
authType: 'static',
requestUrl: config.url,
authHeaders: config.headers?.Authorization ? 'present' : 'missing',
headerKeys: Object.keys(config.headers || {})
});
return this.httpClient.request(config);
}
buildPath(template, params) {
let path = template;
// Custom encoding that preserves forward slashes for API paths
const encodePathComponent = (value) => {
// For Google API resource names like "people/c123", preserve the forward slash
return encodeURIComponent(value).replace(/%2F/g, '/');
};
// Handle Google-style path templates: {resourceName=people/*} and {person.resourceName=people/*}
const googlePathTemplateRegex = /{([^}=]+)=[^}]*}/g;
let match;
const processedParams = [];
while ((match = googlePathTemplateRegex.exec(template)) !== null) {
const fullMatch = match[0]; // e.g., "{resourceName=people/*}"
const paramName = match[1]; // e.g., "resourceName" or "person.resourceName"
if (paramName && params[paramName] !== undefined) {
path = path.replace(fullMatch, encodePathComponent(String(params[paramName])));
processedParams.push(paramName);
}
}
// Handle standard path templates: {resourceName}
for (const [key, value] of Object.entries(params)) {
if (!processedParams.includes(key)) {
const standardTemplate = `{${key}}`;
if (path.includes(standardTemplate)) {
path = path.replace(standardTemplate, encodePathComponent(String(value)));
processedParams.push(key);
}
}
}
this.logger.debug('PATH_BUILD', 'Built API path from template', {
template,
resultPath: path,
paramCount: Object.keys(params).length,
paramKeys: Object.keys(params),
processedParams,
hasGoogleTemplates: googlePathTemplateRegex.test(template)
});
return path;
}
async createCompany(params) {
const startTime = Date.now();
this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
endpoint: 'create_company',
method: 'POST',
path: '/partner_managed_companies',
paramCount: Object.keys(params || {}).length,
paramKeys: Object.keys(params || {})
});
try {
// Extract and separate parameters by location: path, query, body
const pathTemplate = '/partner_managed_companies';
const pathParams = {};
const queryParams = {};
const bodyParams = {};
const extractedParams = [];
// Handle Google-style path templates: {resourceName=people/*} and {person.resourceName=people/*}
const googlePathTemplateRegex = /{([^}=]+)=[^}]*}/g;
let match;
while ((match = googlePathTemplateRegex.exec(pathTemplate)) !== null) {
const paramName = match[1]; // e.g., "resourceName" or "person.resourceName"
if (paramName && params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
}
// Handle standard path templates: {resourceName}
const standardPathParams = pathTemplate.match(/{([^}=]+)}/g) || [];
standardPathParams.forEach(paramTemplate => {
const paramName = paramTemplate.slice(1, -1); // Remove { }
// Only process if not already handled by Google template logic
if (!extractedParams.includes(paramName)) {
if (params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
else {
// Provide default values for optional path parameters
if (paramName === 'userId') {
pathParams[paramName] = 'me'; // Default to authenticated user
extractedParams.push(paramName);
}
}
}
});
// Separate remaining parameters by location (query vs body)
if (params["name"] !== undefined) {
bodyParams["name"] = params["name"];
extractedParams.push("name");
}
if (params["trade_name"] !== undefined) {
bodyParams["trade_name"] = params["trade_name"];
extractedParams.push("trade_name");
}
if (params["ein"] !== undefined) {
bodyParams["ein"] = params["ein"];
extractedParams.push("ein");
}
if (params["entity_type"] !== undefined) {
bodyParams["entity_type"] = params["entity_type"];
extractedParams.push("entity_type");
}
if (params["company_uuid"] !== undefined) {
bodyParams["company_uuid"] = params["company_uuid"];
extractedParams.push("company_uuid");
}
// Any remaining unprocessed parameters default to body for backward compatibility
for (const [key, value] of Object.entries(params)) {
if (!extractedParams.includes(key)) {
bodyParams[key] = value;
}
}
// Validate required parameters
if (!params.name) {
throw new Error(`Missing required parameter: name`);
}
const path = this.buildPath('/partner_managed_companies', pathParams);
// Use standard HTTP client for other auth types
const response = await this.httpClient.post(path, Object.keys(bodyParams).length > 0 ? bodyParams : undefined, { params: queryParams });
const duration = Date.now() - startTime;
this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
endpoint: 'create_company',
method: 'POST',
path: '/partner_managed_companies',
duration_ms: duration,
responseDataSize: JSON.stringify(response.data).length
});
return {
content: [
{
type: 'text',
text: JSON.stringify(response.data, null, 2)
}
]
};
}
catch (error) {
const duration = Date.now() - startTime;
this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
endpoint: 'create_company',
method: 'POST',
path: '/partner_managed_companies',
duration_ms: duration,
error: error instanceof Error ? error.message : String(error),
errorType: error instanceof Error ? error.constructor.name : 'unknown'
});
throw new Error(`Failed to execute create_company: ${error instanceof Error ? error.message : String(error)}`);
}
}
async getCompany(params) {
const startTime = Date.now();
this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
endpoint: 'get_company',
method: 'GET',
path: '/companies/{company_uuid}',
paramCount: Object.keys(params || {}).length,
paramKeys: Object.keys(params || {})
});
try {
// Extract and separate parameters by location: path, query, body
const pathTemplate = '/companies/{company_uuid}';
const pathParams = {};
const queryParams = {};
const bodyParams = {};
const extractedParams = [];
// Handle Google-style path templates: {resourceName=people/*} and {person.resourceName=people/*}
const googlePathTemplateRegex = /{([^}=]+)=[^}]*}/g;
let match;
while ((match = googlePathTemplateRegex.exec(pathTemplate)) !== null) {
const paramName = match[1]; // e.g., "resourceName" or "person.resourceName"
if (paramName && params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
}
// Handle standard path templates: {resourceName}
const standardPathParams = pathTemplate.match(/{([^}=]+)}/g) || [];
standardPathParams.forEach(paramTemplate => {
const paramName = paramTemplate.slice(1, -1); // Remove { }
// Only process if not already handled by Google template logic
if (!extractedParams.includes(paramName)) {
if (params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
else {
// Provide default values for optional path parameters
if (paramName === 'userId') {
pathParams[paramName] = 'me'; // Default to authenticated user
extractedParams.push(paramName);
}
}
}
});
// Separate remaining parameters by location (query vs body)
// Any remaining unprocessed parameters default to body for backward compatibility
for (const [key, value] of Object.entries(params)) {
if (!extractedParams.includes(key)) {
bodyParams[key] = value;
}
}
// Validate required parameters
if (!params.company_uuid) {
throw new Error(`Missing required parameter: company_uuid`);
}
const path = this.buildPath('/companies/{company_uuid}', pathParams);
// Use standard HTTP client for other auth types
const response = await this.httpClient.get(path, { params: queryParams });
const duration = Date.now() - startTime;
this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
endpoint: 'get_company',
method: 'GET',
path: '/companies/{company_uuid}',
duration_ms: duration,
responseDataSize: JSON.stringify(response.data).length
});
return {
content: [
{
type: 'text',
text: JSON.stringify(response.data, null, 2)
}
]
};
}
catch (error) {
const duration = Date.now() - startTime;
this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
endpoint: 'get_company',
method: 'GET',
path: '/companies/{company_uuid}',
duration_ms: duration,
error: error instanceof Error ? error.message : String(error),
errorType: error instanceof Error ? error.constructor.name : 'unknown'
});
throw new Error(`Failed to execute get_company: ${error instanceof Error ? error.message : String(error)}`);
}
}
async updateCompany(params) {
const startTime = Date.now();
this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
endpoint: 'update_company',
method: 'PUT',
path: '/companies/{company_uuid}',
paramCount: Object.keys(params || {}).length,
paramKeys: Object.keys(params || {})
});
try {
// Extract and separate parameters by location: path, query, body
const pathTemplate = '/companies/{company_uuid}';
const pathParams = {};
const queryParams = {};
const bodyParams = {};
const extractedParams = [];
// Handle Google-style path templates: {resourceName=people/*} and {person.resourceName=people/*}
const googlePathTemplateRegex = /{([^}=]+)=[^}]*}/g;
let match;
while ((match = googlePathTemplateRegex.exec(pathTemplate)) !== null) {
const paramName = match[1]; // e.g., "resourceName" or "person.resourceName"
if (paramName && params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
}
// Handle standard path templates: {resourceName}
const standardPathParams = pathTemplate.match(/{([^}=]+)}/g) || [];
standardPathParams.forEach(paramTemplate => {
const paramName = paramTemplate.slice(1, -1); // Remove { }
// Only process if not already handled by Google template logic
if (!extractedParams.includes(paramName)) {
if (params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
else {
// Provide default values for optional path parameters
if (paramName === 'userId') {
pathParams[paramName] = 'me'; // Default to authenticated user
extractedParams.push(paramName);
}
}
}
});
// Separate remaining parameters by location (query vs body)
if (params["name"] !== undefined) {
bodyParams["name"] = params["name"];
extractedParams.push("name");
}
if (params["trade_name"] !== undefined) {
bodyParams["trade_name"] = params["trade_name"];
extractedParams.push("trade_name");
}
if (params["ein"] !== undefined) {
bodyParams["ein"] = params["ein"];
extractedParams.push("ein");
}
// Any remaining unprocessed parameters default to body for backward compatibility
for (const [key, value] of Object.entries(params)) {
if (!extractedParams.includes(key)) {
bodyParams[key] = value;
}
}
// Validate required parameters
if (!params.company_uuid) {
throw new Error(`Missing required parameter: company_uuid`);
}
const path = this.buildPath('/companies/{company_uuid}', pathParams);
// Use standard HTTP client for other auth types
const response = await this.httpClient.put(path, Object.keys(bodyParams).length > 0 ? bodyParams : undefined, { params: queryParams });
const duration = Date.now() - startTime;
this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
endpoint: 'update_company',
method: 'PUT',
path: '/companies/{company_uuid}',
duration_ms: duration,
responseDataSize: JSON.stringify(response.data).length
});
return {
content: [
{
type: 'text',
text: JSON.stringify(response.data, null, 2)
}
]
};
}
catch (error) {
const duration = Date.now() - startTime;
this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
endpoint: 'update_company',
method: 'PUT',
path: '/companies/{company_uuid}',
duration_ms: duration,
error: error instanceof Error ? error.message : String(error),
errorType: error instanceof Error ? error.constructor.name : 'unknown'
});
throw new Error(`Failed to execute update_company: ${error instanceof Error ? error.message : String(error)}`);
}
}
async createLocation(params) {
const startTime = Date.now();
this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
endpoint: 'create_location',
method: 'POST',
path: '/companies/{company_uuid}/locations',
paramCount: Object.keys(params || {}).length,
paramKeys: Object.keys(params || {})
});
try {
// Extract and separate parameters by location: path, query, body
const pathTemplate = '/companies/{company_uuid}/locations';
const pathParams = {};
const queryParams = {};
const bodyParams = {};
const extractedParams = [];
// Handle Google-style path templates: {resourceName=people/*} and {person.resourceName=people/*}
const googlePathTemplateRegex = /{([^}=]+)=[^}]*}/g;
let match;
while ((match = googlePathTemplateRegex.exec(pathTemplate)) !== null) {
const paramName = match[1]; // e.g., "resourceName" or "person.resourceName"
if (paramName && params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
}
// Handle standard path templates: {resourceName}
const standardPathParams = pathTemplate.match(/{([^}=]+)}/g) || [];
standardPathParams.forEach(paramTemplate => {
const paramName = paramTemplate.slice(1, -1); // Remove { }
// Only process if not already handled by Google template logic
if (!extractedParams.includes(paramName)) {
if (params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
else {
// Provide default values for optional path parameters
if (paramName === 'userId') {
pathParams[paramName] = 'me'; // Default to authenticated user
extractedParams.push(paramName);
}
}
}
});
// Separate remaining parameters by location (query vs body)
if (params["street_1"] !== undefined) {
bodyParams["street_1"] = params["street_1"];
extractedParams.push("street_1");
}
if (params["street_2"] !== undefined) {
bodyParams["street_2"] = params["street_2"];
extractedParams.push("street_2");
}
if (params["city"] !== undefined) {
bodyParams["city"] = params["city"];
extractedParams.push("city");
}
if (params["state"] !== undefined) {
bodyParams["state"] = params["state"];
extractedParams.push("state");
}
if (params["zip"] !== undefined) {
bodyParams["zip"] = params["zip"];
extractedParams.push("zip");
}
if (params["country"] !== undefined) {
bodyParams["country"] = params["country"];
extractedParams.push("country");
}
// Any remaining unprocessed parameters default to body for backward compatibility
for (const [key, value] of Object.entries(params)) {
if (!extractedParams.includes(key)) {
bodyParams[key] = value;
}
}
// Validate required parameters
if (!params.company_uuid) {
throw new Error(`Missing required parameter: company_uuid`);
}
if (!params.street_1) {
throw new Error(`Missing required parameter: street_1`);
}
if (!params.city) {
throw new Error(`Missing required parameter: city`);
}
if (!params.state) {
throw new Error(`Missing required parameter: state`);
}
if (!params.zip) {
throw new Error(`Missing required parameter: zip`);
}
const path = this.buildPath('/companies/{company_uuid}/locations', pathParams);
// Use standard HTTP client for other auth types
const response = await this.httpClient.post(path, Object.keys(bodyParams).length > 0 ? bodyParams : undefined, { params: queryParams });
const duration = Date.now() - startTime;
this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
endpoint: 'create_location',
method: 'POST',
path: '/companies/{company_uuid}/locations',
duration_ms: duration,
responseDataSize: JSON.stringify(response.data).length
});
return {
content: [
{
type: 'text',
text: JSON.stringify(response.data, null, 2)
}
]
};
}
catch (error) {
const duration = Date.now() - startTime;
this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
endpoint: 'create_location',
method: 'POST',
path: '/companies/{company_uuid}/locations',
duration_ms: duration,
error: error instanceof Error ? error.message : String(error),
errorType: error instanceof Error ? error.constructor.name : 'unknown'
});
throw new Error(`Failed to execute create_location: ${error instanceof Error ? error.message : String(error)}`);
}
}
async listLocations(params) {
const startTime = Date.now();
this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
endpoint: 'list_locations',
method: 'GET',
path: '/companies/{company_uuid}/locations',
paramCount: Object.keys(params || {}).length,
paramKeys: Object.keys(params || {})
});
try {
// Extract and separate parameters by location: path, query, body
const pathTemplate = '/companies/{company_uuid}/locations';
const pathParams = {};
const queryParams = {};
const bodyParams = {};
const extractedParams = [];
// Handle Google-style path templates: {resourceName=people/*} and {person.resourceName=people/*}
const googlePathTemplateRegex = /{([^}=]+)=[^}]*}/g;
let match;
while ((match = googlePathTemplateRegex.exec(pathTemplate)) !== null) {
const paramName = match[1]; // e.g., "resourceName" or "person.resourceName"
if (paramName && params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
}
// Handle standard path templates: {resourceName}
const standardPathParams = pathTemplate.match(/{([^}=]+)}/g) || [];
standardPathParams.forEach(paramTemplate => {
const paramName = paramTemplate.slice(1, -1); // Remove { }
// Only process if not already handled by Google template logic
if (!extractedParams.includes(paramName)) {
if (params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
else {
// Provide default values for optional path parameters
if (paramName === 'userId') {
pathParams[paramName] = 'me'; // Default to authenticated user
extractedParams.push(paramName);
}
}
}
});
// Separate remaining parameters by location (query vs body)
// Any remaining unprocessed parameters default to body for backward compatibility
for (const [key, value] of Object.entries(params)) {
if (!extractedParams.includes(key)) {
bodyParams[key] = value;
}
}
// Validate required parameters
if (!params.company_uuid) {
throw new Error(`Missing required parameter: company_uuid`);
}
const path = this.buildPath('/companies/{company_uuid}/locations', pathParams);
// Use standard HTTP client for other auth types
const response = await this.httpClient.get(path, { params: queryParams });
const duration = Date.now() - startTime;
this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
endpoint: 'list_locations',
method: 'GET',
path: '/companies/{company_uuid}/locations',
duration_ms: duration,
responseDataSize: JSON.stringify(response.data).length
});
return {
content: [
{
type: 'text',
text: JSON.stringify(response.data, null, 2)
}
]
};
}
catch (error) {
const duration = Date.now() - startTime;
this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
endpoint: 'list_locations',
method: 'GET',
path: '/companies/{company_uuid}/locations',
duration_ms: duration,
error: error instanceof Error ? error.message : String(error),
errorType: error instanceof Error ? error.constructor.name : 'unknown'
});
throw new Error(`Failed to execute list_locations: ${error instanceof Error ? error.message : String(error)}`);
}
}
async createEmployee(params) {
const startTime = Date.now();
this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
endpoint: 'create_employee',
method: 'POST',
path: '/companies/{company_uuid}/employees',
paramCount: Object.keys(params || {}).length,
paramKeys: Object.keys(params || {})
});
try {
// Extract and separate parameters by location: path, query, body
const pathTemplate = '/companies/{company_uuid}/employees';
const pathParams = {};
const queryParams = {};
const bodyParams = {};
const extractedParams = [];
// Handle Google-style path templates: {resourceName=people/*} and {person.resourceName=people/*}
const googlePathTemplateRegex = /{([^}=]+)=[^}]*}/g;
let match;
while ((match = googlePathTemplateRegex.exec(pathTemplate)) !== null) {
const paramName = match[1]; // e.g., "resourceName" or "person.resourceName"
if (paramName && params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
}
// Handle standard path templates: {resourceName}
const standardPathParams = pathTemplate.match(/{([^}=]+)}/g) || [];
standardPathParams.forEach(paramTemplate => {
const paramName = paramTemplate.slice(1, -1); // Remove { }
// Only process if not already handled by Google template logic
if (!extractedParams.includes(paramName)) {
if (params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
else {
// Provide default values for optional path parameters
if (paramName === 'userId') {
pathParams[paramName] = 'me'; // Default to authenticated user
extractedParams.push(paramName);
}
}
}
});
// Separate remaining parameters by location (query vs body)
if (params["first_name"] !== undefined) {
bodyParams["first_name"] = params["first_name"];
extractedParams.push("first_name");
}
if (params["last_name"] !== undefined) {
bodyParams["last_name"] = params["last_name"];
extractedParams.push("last_name");
}
if (params["email"] !== undefined) {
bodyParams["email"] = params["email"];
extractedParams.push("email");
}
if (params["date_of_birth"] !== undefined) {
bodyParams["date_of_birth"] = params["date_of_birth"];
extractedParams.push("date_of_birth");
}
if (params["ssn"] !== undefined) {
bodyParams["ssn"] = params["ssn"];
extractedParams.push("ssn");
}
if (params["work_location_uuid"] !== undefined) {
bodyParams["work_location_uuid"] = params["work_location_uuid"];
extractedParams.push("work_location_uuid");
}
if (params["home_address"] !== undefined) {
bodyParams["home_address"] = params["home_address"];
extractedParams.push("home_address");
}
if (params["phone"] !== undefined) {
bodyParams["phone"] = params["phone"];
extractedParams.push("phone");
}
// Any remaining unprocessed parameters default to body for backward compatibility
for (const [key, value] of Object.entries(params)) {
if (!extractedParams.includes(key)) {
bodyParams[key] = value;
}
}
// Validate required parameters
if (!params.company_uuid) {
throw new Error(`Missing required parameter: company_uuid`);
}
if (!params.first_name) {
throw new Error(`Missing required parameter: first_name`);
}
if (!params.last_name) {
throw new Error(`Missing required parameter: last_name`);
}
if (!params.email) {
throw new Error(`Missing required parameter: email`);
}
if (!params.work_location_uuid) {
throw new Error(`Missing required parameter: work_location_uuid`);
}
const path = this.buildPath('/companies/{company_uuid}/employees', pathParams);
// Use standard HTTP client for other auth types
const response = await this.httpClient.post(path, Object.keys(bodyParams).length > 0 ? bodyParams : undefined, { params: queryParams });
const duration = Date.now() - startTime;
this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
endpoint: 'create_employee',
method: 'POST',
path: '/companies/{company_uuid}/employees',
duration_ms: duration,
responseDataSize: JSON.stringify(response.data).length
});
return {
content: [
{
type: 'text',
text: JSON.stringify(response.data, null, 2)
}
]
};
}
catch (error) {
const duration = Date.now() - startTime;
this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
endpoint: 'create_employee',
method: 'POST',
path: '/companies/{company_uuid}/employees',
duration_ms: duration,
error: error instanceof Error ? error.message : String(error),
errorType: error instanceof Error ? error.constructor.name : 'unknown'
});
throw new Error(`Failed to execute create_employee: ${error instanceof Error ? error.message : String(error)}`);
}
}
async getEmployee(params) {
const startTime = Date.now();
this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
endpoint: 'get_employee',
method: 'GET',
path: '/employees/{employee_uuid}',
paramCount: Object.keys(params || {}).length,
paramKeys: Object.keys(params || {})
});
try {
// Extract and separate parameters by location: path, query, body
const pathTemplate = '/employees/{employee_uuid}';
const pathParams = {};
const queryParams = {};
const bodyParams = {};
const extractedParams = [];
// Handle Google-style path templates: {resourceName=people/*} and {person.resourceName=people/*}
const googlePathTemplateRegex = /{([^}=]+)=[^}]*}/g;
let match;
while ((match = googlePathTemplateRegex.exec(pathTemplate)) !== null) {
const paramName = match[1]; // e.g., "resourceName" or "person.resourceName"
if (paramName && params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
}
// Handle standard path templates: {resourceName}
const standardPathParams = pathTemplate.match(/{([^}=]+)}/g) || [];
standardPathParams.forEach(paramTemplate => {
const paramName = paramTemplate.slice(1, -1); // Remove { }
// Only process if not already handled by Google template logic
if (!extractedParams.includes(paramName)) {
if (params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
else {
// Provide default values for optional path parameters
if (paramName === 'userId') {
pathParams[paramName] = 'me'; // Default to authenticated user
extractedParams.push(paramName);
}
}
}
});
// Separate remaining parameters by location (query vs body)
// Any remaining unprocessed parameters default to body for backward compatibility
for (const [key, value] of Object.entries(params)) {
if (!extractedParams.includes(key)) {
bodyParams[key] = value;
}
}
// Validate required parameters
if (!params.employee_uuid) {
throw new Error(`Missing required parameter: employee_uuid`);
}
const path = this.buildPath('/employees/{employee_uuid}', pathParams);
// Use standard HTTP client for other auth types
const response = await this.httpClient.get(path, { params: queryParams });
const duration = Date.now() - startTime;
this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
endpoint: 'get_employee',
method: 'GET',
path: '/employees/{employee_uuid}',
duration_ms: duration,
responseDataSize: JSON.stringify(response.data).length
});
return {
content: [
{
type: 'text',
text: JSON.stringify(response.data, null, 2)
}
]
};
}
catch (error) {
const duration = Date.now() - startTime;
this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
endpoint: 'get_employee',
method: 'GET',
path: '/employees/{employee_uuid}',
duration_ms: duration,
error: error instanceof Error ? error.message : String(error),
errorType: error instanceof Error ? error.constructor.name : 'unknown'
});
throw new Error(`Failed to execute get_employee: ${error instanceof Error ? error.message : String(error)}`);
}
}
async updateEmployee(params) {
const startTime = Date.now();
this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
endpoint: 'update_employee',
method: 'PUT',
path: '/employees/{employee_uuid}',
paramCount: Object.keys(params || {}).length,
paramKeys: Object.keys(params || {})
});
try {
// Extract and separate parameters by location: path, query, body
const pathTemplate = '/employees/{employee_uuid}';
const pathParams = {};
const queryParams = {};
const bodyParams = {};
const extractedParams = [];
// Handle Google-style path templates: {resourceName=people/*} and {person.resourceName=people/*}
const googlePathTemplateRegex = /{([^}=]+)=[^}]*}/g;
let match;
while ((match = googlePathTemplateRegex.exec(pathTemplate)) !== null) {
const paramName = match[1]; // e.g., "resourceName" or "person.resourceName"
if (paramName && params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
}
// Handle standard path templates: {resourceName}
const standardPathParams = pathTemplate.match(/{([^}=]+)}/g) || [];
standardPathParams.forEach(paramTemplate => {
const paramName = paramTemplate.slice(1, -1); // Remove { }
// Only process if not already handled by Google template logic
if (!extractedParams.includes(paramName)) {
if (params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
else {
// Provide default values for optional path parameters
if (paramName === 'userId') {
pathParams[paramName] = 'me'; // Default to authenticated user
extractedParams.push(paramName);
}
}
}
});
// Separate remaining parameters by location (query vs body)
if (params["first_name"] !== undefined) {
bodyParams["first_name"] = params["first_name"];
extractedParams.push("first_name");
}
if (params["last_name"] !== undefined) {
bodyParams["last_name"] = params["last_name"];
extractedParams.push("last_name");
}
if (params["email"] !== undefined) {
bodyParams["email"] = params["email"];
extractedParams.push("email");
}
if (params["phone"] !== undefined) {
bodyParams["phone"] = params["phone"];
extractedParams.push("phone");
}
if (params["home_address"] !== undefined) {
bodyParams["home_address"] = params["home_address"];
extractedParams.push("home_address");
}
// Any remaining unprocessed parameters default to body for backward compatibility
for (const [key, value] of Object.entries(params)) {
if (!extractedParams.includes(key)) {
bodyParams[key] = value;
}
}
// Validate required parameters
if (!params.employee_uuid) {
throw new Error(`Missing required parameter: employee_uuid`);
}
const path = this.buildPath('/employees/{employee_uuid}', pathParams);
// Use standard HTTP client for other auth types
const response = await this.httpClient.put(path, Object.keys(bodyParams).length > 0 ? bodyParams : undefined, { params: queryParams });
const duration = Date.now() - startTime;
this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
endpoint: 'update_employee',
method: 'PUT',
path: '/employees/{employee_uuid}',
duration_ms: duration,
responseDataSize: JSON.stringify(response.data).length
});
return {
content: [
{
type: 'text',
text: JSON.stringify(response.data, null, 2)
}
]
};
}
catch (error) {
const duration = Date.now() - startTime;
this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
endpoint: 'update_employee',
method: 'PUT',
path: '/employees/{employee_uuid}',
duration_ms: duration,
error: error instanceof Error ? error.message : String(error),
errorType: error instanceof Error ? error.constructor.name : 'unknown'
});
throw new Error(`Failed to execute update_employee: ${error instanceof Error ? error.message : String(error)}`);
}
}
async listEmployees(params) {
const startTime = Date.now();
this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
endpoint: 'list_employees',
method: 'GET',
path: '/companies/{company_uuid}/employees',
paramCount: Object.keys(params || {}).length,
paramKeys: Object.keys(params || {})
});
try {
// Extract and separate parameters by location: path, query, body
const pathTemplate = '/companies/{company_uuid}/employees';
const pathParams = {};
const queryParams = {};
const bodyParams = {};
const extractedParams = [];
// Handle Google-style path templates: {resourceName=people/*} and {person.resourceName=people/*}
const googlePathTemplateRegex = /{([^}=]+)=[^}]*}/g;
let match;
while ((match = googlePathTemplateRegex.exec(pathTemplate)) !== null) {
const paramName = match[1]; // e.g., "resourceName" or "person.resourceName"
if (paramName && params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
}
// Handle standard path templates: {resourceName}
const standardPathParams = pathTemplate.match(/{([^}=]+)}/g) || [];
standardPathParams.forEach(paramTemplate => {
const paramName = paramTemplate.slice(1, -1); // Remove { }
// Only process if not already handled by Google template logic
if (!extractedParams.includes(paramName)) {
if (params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
else {
// Provide default values for optional path parameters
if (paramName === 'userId') {
pathParams[paramName] = 'me'; // Default to authenticated user
extractedParams.push(paramName);
}
}
}
});
// Separate remaining parameters by location (query vs body)
if (params["page"] !== undefined) {
queryParams["page"] = params["page"];
extractedParams.push("page");
}
if (params["per"] !== undefined) {
queryParams["per"] = params["per"];
extractedParams.push("per");
}
// Any remaining unprocessed parameters default to body for backward compatibility
for (const [key, value] of Object.entries(params)) {
if (!extractedParams.includes(key)) {
bodyParams[key] = value;
}
}
// Validate required parameters
if (!params.company_uuid) {
throw new Error(`Missing required parameter: company_uuid`);
}
const path = this.buildPath('/companies/{company_uuid}/employees', pathParams);
// Use standard HTTP client for other auth types
const response = await this.httpClient.get(path, { params: queryParams });
const duration = Date.now() - startTime;
this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
endpoint: 'list_employees',
method: 'GET',
path: '/companies/{company_uuid}/employees',
duration_ms: duration,
responseDataSize: JSON.stringify(response.data).length
});
return {
content: [
{
type: 'text',
text: JSON.stringify(response.data, null, 2)
}
]
};
}
catch (error) {
const duration = Date.now() - startTime;
this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
endpoint: 'list_employees',
method: 'GET',
path: '/companies/{company_uuid}/employees',
duration_ms: duration,
error: error instanceof Error ? error.message : String(error),
errorType: error instanceof Error ? error.constructor.name : 'unknown'
});
throw new Error(`Failed to execute list_employees: ${error instanceof Error ? error.message : String(error)}`);
}
}
async createJob(params) {
const startTime = Date.now();
this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
endpoint: 'create_job',
method: 'POST',
path: '/employees/{employee_uuid}/jobs',
paramCount: Object.keys(params || {}).length,
paramKeys: Object.keys(params || {})
});
try {
// Extract and separate parameters by location: path, query, body
const pathTemplate = '/employees/{employee_uuid}/jobs';
const pathParams = {};
const queryParams = {};
const bodyParams = {};
const extractedParams = [];
// Handle Google-style path templates: {resourceName=people/*} and {person.resourceName=people/*}
const googlePathTemplateRegex = /{([^}=]+)=[^}]*}/g;
let match;
while ((match = googlePathTemplateRegex.exec(pathTemplate)) !== null) {
const paramName = match[1]; // e.g., "resourceName" or "person.resourceName"
if (paramName && params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
}
// Handle standard path templates: {resourceName}
const standardPathParams = pathTemplate.match(/{([^}=]+)}/g) || [];
standardPathParams.forEach(paramTemplate => {
const paramName = paramTemplate.slice(1, -1); // Remove { }
// Only process if not already handled by Google template logic
if (!extractedParams.includes(paramName)) {
if (params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
else {
// Provide default values for optional path parameters
if (paramName === 'userId') {
pathParams[paramName] = 'me'; // Default to authenticated user
extractedParams.push(paramName);
}
}
}
});
// Separate remaining parameters by location (query vs body)
if (params["title"] !== undefined) {
bodyParams["title"] = params["title"];
extractedParams.push("title");
}
if (params["hire_date"] !== undefined) {
bodyParams["hire_date"] = params["hire_date"];
extractedParams.push("hire_date");
}
if (params["location_uuid"] !== undefined) {
bodyParams["location_uuid"] = params["location_uuid"];
extractedParams.push("location_uuid");
}
if (params["rate"] !== undefined) {
bodyParams["rate"] = params["rate"];
extractedParams.push("rate");
}
if (params["payment_unit"] !== undefined) {
bodyParams["payment_unit"] = params["payment_unit"];
extractedParams.push("payment_unit");
}
if (params["flsa_status"] !== undefined) {
bodyParams["flsa_status"] = params["flsa_status"];
extractedParams.push("flsa_status");
}
// Any remaining unprocessed parameters default to body for backward compatibility
for (const [key, value] of Object.entries(params)) {
if (!extractedParams.includes(key)) {
bodyParams[key] = value;
}
}
// Validate required parameters
if (!params.employee_uuid) {
throw new Error(`Missing required parameter: employee_uuid`);
}
if (!params.title) {
throw new Error(`Missing required parameter: title`);
}
if (!params.hire_date) {
throw new Error(`Missing required parameter: hire_date`);
}
if (!params.location_uuid) {
throw new Error(`Missing required parameter: location_uuid`);
}
if (!params.rate) {
throw new Error(`Missing required parameter: rate`);
}
if (!params.payment_unit) {
throw new Error(`Missing required parameter: payment_unit`);
}
const path = this.buildPath('/employees/{employee_uuid}/jobs', pathParams);
// Use standard HTTP client for other auth types
const response = await this.httpClient.post(path, Object.keys(bodyParams).length > 0 ? bodyParams : undefined, { params: queryParams });
const duration = Date.now() - startTime;
this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
endpoint: 'create_job',
method: 'POST',
path: '/employees/{employee_uuid}/jobs',
duration_ms: duration,
responseDataSize: JSON.stringify(response.data).length
});
return {
content: [
{
type: 'text',
text: JSON.stringify(response.data, null, 2)
}
]
};
}
catch (error) {
const duration = Date.now() - startTime;
this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
endpoint: 'create_job',
method: 'POST',
path: '/employees/{employee_uuid}/jobs',
duration_ms: duration,
error: error instanceof Error ? error.message : String(error),
errorType: error instanceof Error ? error.constructor.name : 'unknown'
});
throw new Error(`Failed to execute create_job: ${error instanceof Error ? error.message : String(error)}`);
}
}
async getJob(params) {
const startTime = Date.now();
this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
endpoint: 'get_job',
method: 'GET',
path: '/jobs/{job_uuid}',
paramCount: Object.keys(params || {}).length,
paramKeys: Object.keys(params || {})
});
try {
// Extract and separate parameters by location: path, query, body
const pathTemplate = '/jobs/{job_uuid}';
const pathParams = {};
const queryParams = {};
const bodyParams = {};
const extractedParams = [];
// Handle Google-style path templates: {resourceName=people/*} and {person.resourceName=people/*}
const googlePathTemplateRegex = /{([^}=]+)=[^}]*}/g;
let match;
while ((match = googlePathTemplateRegex.exec(pathTemplate)) !== null) {
const paramName = match[1]; // e.g., "resourceName" or "person.resourceName"
if (paramName && params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
}
// Handle standard path templates: {resourceName}
const standardPathParams = pathTemplate.match(/{([^}=]+)}/g) || [];
standardPathParams.forEach(paramTemplate => {
const paramName = paramTemplate.slice(1, -1); // Remove { }
// Only process if not already handled by Google template logic
if (!extractedParams.includes(paramName)) {
if (params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
else {
// Provide default values for optional path parameters
if (paramName === 'userId') {
pathParams[paramName] = 'me'; // Default to authenticated user
extractedParams.push(paramName);
}
}
}
});
// Separate remaining parameters by location (query vs body)
// Any remaining unprocessed parameters default to body for backward compatibility
for (const [key, value] of Object.entries(params)) {
if (!extractedParams.includes(key)) {
bodyParams[key] = value;
}
}
// Validate required parameters
if (!params.job_uuid) {
throw new Error(`Missing required parameter: job_uuid`);
}
const path = this.buildPath('/jobs/{job_uuid}', pathParams);
// Use standard HTTP client for other auth types
const response = await this.httpClient.get(path, { params: queryParams });
const duration = Date.now() - startTime;
this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
endpoint: 'get_job',
method: 'GET',
path: '/jobs/{job_uuid}',
duration_ms: duration,
responseDataSize: JSON.stringify(response.data).length
});
return {
content: [
{
type: 'text',
text: JSON.stringify(response.data, null, 2)
}
]
};
}
catch (error) {
const duration = Date.now() - startTime;
this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
endpoint: 'get_job',
method: 'GET',
path: '/jobs/{job_uuid}',
duration_ms: duration,
error: error instanceof Error ? error.message : String(error),
errorType: error instanceof Error ? error.constructor.name : 'unknown'
});
throw new Error(`Failed to execute get_job: ${error instanceof Error ? error.message : String(error)}`);
}
}
async updateJob(params) {
const startTime = Date.now();
this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
endpoint: 'update_job',
method: 'PUT',
path: '/jobs/{job_uuid}',
paramCount: Object.keys(params || {}).length,
paramKeys: Object.keys(params || {})
});
try {
// Extract and separate parameters by location: path, query, body
const pathTemplate = '/jobs/{job_uuid}';
const pathParams = {};
const queryParams = {};
const bodyParams = {};
const extractedParams = [];
// Handle Google-style path templates: {resourceName=people/*} and {person.resourceName=people/*}
const googlePathTemplateRegex = /{([^}=]+)=[^}]*}/g;
let match;
while ((match = googlePathTemplateRegex.exec(pathTemplate)) !== null) {
const paramName = match[1]; // e.g., "resourceName" or "person.resourceName"
if (paramName && params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
}
// Handle standard path templates: {resourceName}
const standardPathParams = pathTemplate.match(/{([^}=]+)}/g) || [];
standardPathParams.forEach(paramTemplate => {
const paramName = paramTemplate.slice(1, -1); // Remove { }
// Only process if not already handled by Google template logic
if (!extractedParams.includes(paramName)) {
if (params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
else {
// Provide default values for optional path parameters
if (paramName === 'userId') {
pathParams[paramName] = 'me'; // Default to authenticated user
extractedParams.push(paramName);
}
}
}
});
// Separate remaining parameters by location (query vs body)
if (params["title"] !== undefined) {
bodyParams["title"] = params["title"];
extractedParams.push("title");
}
if (params["rate"] !== undefined) {
bodyParams["rate"] = params["rate"];
extractedParams.push("rate");
}
if (params["payment_unit"] !== undefined) {
bodyParams["payment_unit"] = params["payment_unit"];
extractedParams.push("payment_unit");
}
if (params["flsa_status"] !== undefined) {
bodyParams["flsa_status"] = params["flsa_status"];
extractedParams.push("flsa_status");
}
// Any remaining unprocessed parameters default to body for backward compatibility
for (const [key, value] of Object.entries(params)) {
if (!extractedParams.includes(key)) {
bodyParams[key] = value;
}
}
// Validate required parameters
if (!params.job_uuid) {
throw new Error(`Missing required parameter: job_uuid`);
}
const path = this.buildPath('/jobs/{job_uuid}', pathParams);
// Use standard HTTP client for other auth types
const response = await this.httpClient.put(path, Object.keys(bodyParams).length > 0 ? bodyParams : undefined, { params: queryParams });
const duration = Date.now() - startTime;
this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
endpoint: 'update_job',
method: 'PUT',
path: '/jobs/{job_uuid}',
duration_ms: duration,
responseDataSize: JSON.stringify(response.data).length
});
return {
content: [
{
type: 'text',
text: JSON.stringify(response.data, null, 2)
}
]
};
}
catch (error) {
const duration = Date.now() - startTime;
this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
endpoint: 'update_job',
method: 'PUT',
path: '/jobs/{job_uuid}',
duration_ms: duration,
error: error instanceof Error ? error.message : String(error),
errorType: error instanceof Error ? error.constructor.name : 'unknown'
});
throw new Error(`Failed to execute update_job: ${error instanceof Error ? error.message : String(error)}`);
}
}
async listPayrolls(params) {
const startTime = Date.now();
this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
endpoint: 'list_payrolls',
method: 'GET',
path: '/companies/{company_uuid}/payrolls',
paramCount: Object.keys(params || {}).length,
paramKeys: Object.keys(params || {})
});
try {
// Extract and separate parameters by location: path, query, body
const pathTemplate = '/companies/{company_uuid}/payrolls';
const pathParams = {};
const queryParams = {};
const bodyParams = {};
const extractedParams = [];
// Handle Google-style path templates: {resourceName=people/*} and {person.resourceName=people/*}
const googlePathTemplateRegex = /{([^}=]+)=[^}]*}/g;
let match;
while ((match = googlePathTemplateRegex.exec(pathTemplate)) !== null) {
const paramName = match[1]; // e.g., "resourceName" or "person.resourceName"
if (paramName && params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
}
// Handle standard path templates: {resourceName}
const standardPathParams = pathTemplate.match(/{([^}=]+)}/g) || [];
standardPathParams.forEach(paramTemplate => {
const paramName = paramTemplate.slice(1, -1); // Remove { }
// Only process if not already handled by Google template logic
if (!extractedParams.includes(paramName)) {
if (params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
else {
// Provide default values for optional path parameters
if (paramName === 'userId') {
pathParams[paramName] = 'me'; // Default to authenticated user
extractedParams.push(paramName);
}
}
}
});
// Separate remaining parameters by location (query vs body)
if (params["start_date"] !== undefined) {
queryParams["start_date"] = params["start_date"];
extractedParams.push("start_date");
}
if (params["end_date"] !== undefined) {
queryParams["end_date"] = params["end_date"];
extractedParams.push("end_date");
}
if (params["processed"] !== undefined) {
queryParams["processed"] = params["processed"];
extractedParams.push("processed");
}
// Any remaining unprocessed parameters default to body for backward compatibility
for (const [key, value] of Object.entries(params)) {
if (!extractedParams.includes(key)) {
bodyParams[key] = value;
}
}
// Validate required parameters
if (!params.company_uuid) {
throw new Error(`Missing required parameter: company_uuid`);
}
const path = this.buildPath('/companies/{company_uuid}/payrolls', pathParams);
// Use standard HTTP client for other auth types
const response = await this.httpClient.get(path, { params: queryParams });
const duration = Date.now() - startTime;
this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
endpoint: 'list_payrolls',
method: 'GET',
path: '/companies/{company_uuid}/payrolls',
duration_ms: duration,
responseDataSize: JSON.stringify(response.data).length
});
return {
content: [
{
type: 'text',
text: JSON.stringify(response.data, null, 2)
}
]
};
}
catch (error) {
const duration = Date.now() - startTime;
this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
endpoint: 'list_payrolls',
method: 'GET',
path: '/companies/{company_uuid}/payrolls',
duration_ms: duration,
error: error instanceof Error ? error.message : String(error),
errorType: error instanceof Error ? error.constructor.name : 'unknown'
});
throw new Error(`Failed to execute list_payrolls: ${error instanceof Error ? error.message : String(error)}`);
}
}
async getPayroll(params) {
const startTime = Date.now();
this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
endpoint: 'get_payroll',
method: 'GET',
path: '/payrolls/{payroll_uuid}',
paramCount: Object.keys(params || {}).length,
paramKeys: Object.keys(params || {})
});
try {
// Extract and separate parameters by location: path, query, body
const pathTemplate = '/payrolls/{payroll_uuid}';
const pathParams = {};
const queryParams = {};
const bodyParams = {};
const extractedParams = [];
// Handle Google-style path templates: {resourceName=people/*} and {person.resourceName=people/*}
const googlePathTemplateRegex = /{([^}=]+)=[^}]*}/g;
let match;
while ((match = googlePathTemplateRegex.exec(pathTemplate)) !== null) {
const paramName = match[1]; // e.g., "resourceName" or "person.resourceName"
if (paramName && params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
}
// Handle standard path templates: {resourceName}
const standardPathParams = pathTemplate.match(/{([^}=]+)}/g) || [];
standardPathParams.forEach(paramTemplate => {
const paramName = paramTemplate.slice(1, -1); // Remove { }
// Only process if not already handled by Google template logic
if (!extractedParams.includes(paramName)) {
if (params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
else {
// Provide default values for optional path parameters
if (paramName === 'userId') {
pathParams[paramName] = 'me'; // Default to authenticated user
extractedParams.push(paramName);
}
}
}
});
// Separate remaining parameters by location (query vs body)
// Any remaining unprocessed parameters default to body for backward compatibility
for (const [key, value] of Object.entries(params)) {
if (!extractedParams.includes(key)) {
bodyParams[key] = value;
}
}
// Validate required parameters
if (!params.payroll_uuid) {
throw new Error(`Missing required parameter: payroll_uuid`);
}
const path = this.buildPath('/payrolls/{payroll_uuid}', pathParams);
// Use standard HTTP client for other auth types
const response = await this.httpClient.get(path, { params: queryParams });
const duration = Date.now() - startTime;
this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
endpoint: 'get_payroll',
method: 'GET',
path: '/payrolls/{payroll_uuid}',
duration_ms: duration,
responseDataSize: JSON.stringify(response.data).length
});
return {
content: [
{
type: 'text',
text: JSON.stringify(response.data, null, 2)
}
]
};
}
catch (error) {
const duration = Date.now() - startTime;
this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
endpoint: 'get_payroll',
method: 'GET',
path: '/payrolls/{payroll_uuid}',
duration_ms: duration,
error: error instanceof Error ? error.message : String(error),
errorType: error instanceof Error ? error.constructor.name : 'unknown'
});
throw new Error(`Failed to execute get_payroll: ${error instanceof Error ? error.message : String(error)}`);
}
}
async createPayroll(params) {
const startTime = Date.now();
this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
endpoint: 'create_payroll',
method: 'POST',
path: '/companies/{company_uuid}/payrolls',
paramCount: Object.keys(params || {}).length,
paramKeys: Object.keys(params || {})
});
try {
// Extract and separate parameters by location: path, query, body
const pathTemplate = '/companies/{company_uuid}/payrolls';
const pathParams = {};
const queryParams = {};
const bodyParams = {};
const extractedParams = [];
// Handle Google-style path templates: {resourceName=people/*} and {person.resourceName=people/*}
const googlePathTemplateRegex = /{([^}=]+)=[^}]*}/g;
let match;
while ((match = googlePathTemplateRegex.exec(pathTemplate)) !== null) {
const paramName = match[1]; // e.g., "resourceName" or "person.resourceName"
if (paramName && params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
}
// Handle standard path templates: {resourceName}
const standardPathParams = pathTemplate.match(/{([^}=]+)}/g) || [];
standardPathParams.forEach(paramTemplate => {
const paramName = paramTemplate.slice(1, -1); // Remove { }
// Only process if not already handled by Google template logic
if (!extractedParams.includes(paramName)) {
if (params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
else {
// Provide default values for optional path parameters
if (paramName === 'userId') {
pathParams[paramName] = 'me'; // Default to authenticated user
extractedParams.push(paramName);
}
}
}
});
// Separate remaining parameters by location (query vs body)
if (params["start_date"] !== undefined) {
bodyParams["start_date"] = params["start_date"];
extractedParams.push("start_date");
}
if (params["end_date"] !== undefined) {
bodyParams["end_date"] = params["end_date"];
extractedParams.push("end_date");
}
if (params["check_date"] !== undefined) {
bodyParams["check_date"] = params["check_date"];
extractedParams.push("check_date");
}
// Any remaining unprocessed parameters default to body for backward compatibility
for (const [key, value] of Object.entries(params)) {
if (!extractedParams.includes(key)) {
bodyParams[key] = value;
}
}
// Validate required parameters
if (!params.company_uuid) {
throw new Error(`Missing required parameter: company_uuid`);
}
if (!params.start_date) {
throw new Error(`Missing required parameter: start_date`);
}
if (!params.end_date) {
throw new Error(`Missing required parameter: end_date`);
}
if (!params.check_date) {
throw new Error(`Missing required parameter: check_date`);
}
const path = this.buildPath('/companies/{company_uuid}/payrolls', pathParams);
// Use standard HTTP client for other auth types
const response = await this.httpClient.post(path, Object.keys(bodyParams).length > 0 ? bodyParams : undefined, { params: queryParams });
const duration = Date.now() - startTime;
this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
endpoint: 'create_payroll',
method: 'POST',
path: '/companies/{company_uuid}/payrolls',
duration_ms: duration,
responseDataSize: JSON.stringify(response.data).length
});
return {
content: [
{
type: 'text',
text: JSON.stringify(response.data, null, 2)
}
]
};
}
catch (error) {
const duration = Date.now() - startTime;
this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
endpoint: 'create_payroll',
method: 'POST',
path: '/companies/{company_uuid}/payrolls',
duration_ms: duration,
error: error instanceof Error ? error.message : String(error),
errorType: error instanceof Error ? error.constructor.name : 'unknown'
});
throw new Error(`Failed to execute create_payroll: ${error instanceof Error ? error.message : String(error)}`);
}
}
async submitPayroll(params) {
const startTime = Date.now();
this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
endpoint: 'submit_payroll',
method: 'PUT',
path: '/payrolls/{payroll_uuid}/submit',
paramCount: Object.keys(params || {}).length,
paramKeys: Object.keys(params || {})
});
try {
// Extract and separate parameters by location: path, query, body
const pathTemplate = '/payrolls/{payroll_uuid}/submit';
const pathParams = {};
const queryParams = {};
const bodyParams = {};
const extractedParams = [];
// Handle Google-style path templates: {resourceName=people/*} and {person.resourceName=people/*}
const googlePathTemplateRegex = /{([^}=]+)=[^}]*}/g;
let match;
while ((match = googlePathTemplateRegex.exec(pathTemplate)) !== null) {
const paramName = match[1]; // e.g., "resourceName" or "person.resourceName"
if (paramName && params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
}
// Handle standard path templates: {resourceName}
const standardPathParams = pathTemplate.match(/{([^}=]+)}/g) || [];
standardPathParams.forEach(paramTemplate => {
const paramName = paramTemplate.slice(1, -1); // Remove { }
// Only process if not already handled by Google template logic
if (!extractedParams.includes(paramName)) {
if (params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
else {
// Provide default values for optional path parameters
if (paramName === 'userId') {
pathParams[paramName] = 'me'; // Default to authenticated user
extractedParams.push(paramName);
}
}
}
});
// Separate remaining parameters by location (query vs body)
// Any remaining unprocessed parameters default to body for backward compatibility
for (const [key, value] of Object.entries(params)) {
if (!extractedParams.includes(key)) {
bodyParams[key] = value;
}
}
// Validate required parameters
if (!params.payroll_uuid) {
throw new Error(`Missing required parameter: payroll_uuid`);
}
const path = this.buildPath('/payrolls/{payroll_uuid}/submit', pathParams);
// Use standard HTTP client for other auth types
const response = await this.httpClient.put(path, Object.keys(bodyParams).length > 0 ? bodyParams : undefined, { params: queryParams });
const duration = Date.now() - startTime;
this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
endpoint: 'submit_payroll',
method: 'PUT',
path: '/payrolls/{payroll_uuid}/submit',
duration_ms: duration,
responseDataSize: JSON.stringify(response.data).length
});
return {
content: [
{
type: 'text',
text: JSON.stringify(response.data, null, 2)
}
]
};
}
catch (error) {
const duration = Date.now() - startTime;
this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
endpoint: 'submit_payroll',
method: 'PUT',
path: '/payrolls/{payroll_uuid}/submit',
duration_ms: duration,
error: error instanceof Error ? error.message : String(error),
errorType: error instanceof Error ? error.constructor.name : 'unknown'
});
throw new Error(`Failed to execute submit_payroll: ${error instanceof Error ? error.message : String(error)}`);
}
}
async listPaySchedules(params) {
const startTime = Date.now();
this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
endpoint: 'list_pay_schedules',
method: 'GET',
path: '/companies/{company_uuid}/pay_schedules',
paramCount: Object.keys(params || {}).length,
paramKeys: Object.keys(params || {})
});
try {
// Extract and separate parameters by location: path, query, body
const pathTemplate = '/companies/{company_uuid}/pay_schedules';
const pathParams = {};
const queryParams = {};
const bodyParams = {};
const extractedParams = [];
// Handle Google-style path templates: {resourceName=people/*} and {person.resourceName=people/*}
const googlePathTemplateRegex = /{([^}=]+)=[^}]*}/g;
let match;
while ((match = googlePathTemplateRegex.exec(pathTemplate)) !== null) {
const paramName = match[1]; // e.g., "resourceName" or "person.resourceName"
if (paramName && params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
}
// Handle standard path templates: {resourceName}
const standardPathParams = pathTemplate.match(/{([^}=]+)}/g) || [];
standardPathParams.forEach(paramTemplate => {
const paramName = paramTemplate.slice(1, -1); // Remove { }
// Only process if not already handled by Google template logic
if (!extractedParams.includes(paramName)) {
if (params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
else {
// Provide default values for optional path parameters
if (paramName === 'userId') {
pathParams[paramName] = 'me'; // Default to authenticated user
extractedParams.push(paramName);
}
}
}
});
// Separate remaining parameters by location (query vs body)
// Any remaining unprocessed parameters default to body for backward compatibility
for (const [key, value] of Object.entries(params)) {
if (!extractedParams.includes(key)) {
bodyParams[key] = value;
}
}
// Validate required parameters
if (!params.company_uuid) {
throw new Error(`Missing required parameter: company_uuid`);
}
const path = this.buildPath('/companies/{company_uuid}/pay_schedules', pathParams);
// Use standard HTTP client for other auth types
const response = await this.httpClient.get(path, { params: queryParams });
const duration = Date.now() - startTime;
this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
endpoint: 'list_pay_schedules',
method: 'GET',
path: '/companies/{company_uuid}/pay_schedules',
duration_ms: duration,
responseDataSize: JSON.stringify(response.data).length
});
return {
content: [
{
type: 'text',
text: JSON.stringify(response.data, null, 2)
}
]
};
}
catch (error) {
const duration = Date.now() - startTime;
this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
endpoint: 'list_pay_schedules',
method: 'GET',
path: '/companies/{company_uuid}/pay_schedules',
duration_ms: duration,
error: error instanceof Error ? error.message : String(error),
errorType: error instanceof Error ? error.constructor.name : 'unknown'
});
throw new Error(`Failed to execute list_pay_schedules: ${error instanceof Error ? error.message : String(error)}`);
}
}
async createPaySchedule(params) {
const startTime = Date.now();
this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
endpoint: 'create_pay_schedule',
method: 'POST',
path: '/companies/{company_uuid}/pay_schedules',
paramCount: Object.keys(params || {}).length,
paramKeys: Object.keys(params || {})
});
try {
// Extract and separate parameters by location: path, query, body
const pathTemplate = '/companies/{company_uuid}/pay_schedules';
const pathParams = {};
const queryParams = {};
const bodyParams = {};
const extractedParams = [];
// Handle Google-style path templates: {resourceName=people/*} and {person.resourceName=people/*}
const googlePathTemplateRegex = /{([^}=]+)=[^}]*}/g;
let match;
while ((match = googlePathTemplateRegex.exec(pathTemplate)) !== null) {
const paramName = match[1]; // e.g., "resourceName" or "person.resourceName"
if (paramName && params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
}
// Handle standard path templates: {resourceName}
const standardPathParams = pathTemplate.match(/{([^}=]+)}/g) || [];
standardPathParams.forEach(paramTemplate => {
const paramName = paramTemplate.slice(1, -1); // Remove { }
// Only process if not already handled by Google template logic
if (!extractedParams.includes(paramName)) {
if (params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
else {
// Provide default values for optional path parameters
if (paramName === 'userId') {
pathParams[paramName] = 'me'; // Default to authenticated user
extractedParams.push(paramName);
}
}
}
});
// Separate remaining parameters by location (query vs body)
if (params["frequency"] !== undefined) {
bodyParams["frequency"] = params["frequency"];
extractedParams.push("frequency");
}
if (params["anchor_pay_date"] !== undefined) {
bodyParams["anchor_pay_date"] = params["anchor_pay_date"];
extractedParams.push("anchor_pay_date");
}
if (params["anchor_end_of_pay_period"] !== undefined) {
bodyParams["anchor_end_of_pay_period"] = params["anchor_end_of_pay_period"];
extractedParams.push("anchor_end_of_pay_period");
}
// Any remaining unprocessed parameters default to body for backward compatibility
for (const [key, value] of Object.entries(params)) {
if (!extractedParams.includes(key)) {
bodyParams[key] = value;
}
}
// Validate required parameters
if (!params.company_uuid) {
throw new Error(`Missing required parameter: company_uuid`);
}
if (!params.frequency) {
throw new Error(`Missing required parameter: frequency`);
}
if (!params.anchor_pay_date) {
throw new Error(`Missing required parameter: anchor_pay_date`);
}
if (!params.anchor_end_of_pay_period) {
throw new Error(`Missing required parameter: anchor_end_of_pay_period`);
}
const path = this.buildPath('/companies/{company_uuid}/pay_schedules', pathParams);
// Use standard HTTP client for other auth types
const response = await this.httpClient.post(path, Object.keys(bodyParams).length > 0 ? bodyParams : undefined, { params: queryParams });
const duration = Date.now() - startTime;
this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
endpoint: 'create_pay_schedule',
method: 'POST',
path: '/companies/{company_uuid}/pay_schedules',
duration_ms: duration,
responseDataSize: JSON.stringify(response.data).length
});
return {
content: [
{
type: 'text',
text: JSON.stringify(response.data, null, 2)
}
]
};
}
catch (error) {
const duration = Date.now() - startTime;
this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
endpoint: 'create_pay_schedule',
method: 'POST',
path: '/companies/{company_uuid}/pay_schedules',
duration_ms: duration,
error: error instanceof Error ? error.message : String(error),
errorType: error instanceof Error ? error.constructor.name : 'unknown'
});
throw new Error(`Failed to execute create_pay_schedule: ${error instanceof Error ? error.message : String(error)}`);
}
}
async listContractors(params) {
const startTime = Date.now();
this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
endpoint: 'list_contractors',
method: 'GET',
path: '/companies/{company_uuid}/contractors',
paramCount: Object.keys(params || {}).length,
paramKeys: Object.keys(params || {})
});
try {
// Extract and separate parameters by location: path, query, body
const pathTemplate = '/companies/{company_uuid}/contractors';
const pathParams = {};
const queryParams = {};
const bodyParams = {};
const extractedParams = [];
// Handle Google-style path templates: {resourceName=people/*} and {person.resourceName=people/*}
const googlePathTemplateRegex = /{([^}=]+)=[^}]*}/g;
let match;
while ((match = googlePathTemplateRegex.exec(pathTemplate)) !== null) {
const paramName = match[1]; // e.g., "resourceName" or "person.resourceName"
if (paramName && params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
}
// Handle standard path templates: {resourceName}
const standardPathParams = pathTemplate.match(/{([^}=]+)}/g) || [];
standardPathParams.forEach(paramTemplate => {
const paramName = paramTemplate.slice(1, -1); // Remove { }
// Only process if not already handled by Google template logic
if (!extractedParams.includes(paramName)) {
if (params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
else {
// Provide default values for optional path parameters
if (paramName === 'userId') {
pathParams[paramName] = 'me'; // Default to authenticated user
extractedParams.push(paramName);
}
}
}
});
// Separate remaining parameters by location (query vs body)
// Any remaining unprocessed parameters default to body for backward compatibility
for (const [key, value] of Object.entries(params)) {
if (!extractedParams.includes(key)) {
bodyParams[key] = value;
}
}
// Validate required parameters
if (!params.company_uuid) {
throw new Error(`Missing required parameter: company_uuid`);
}
const path = this.buildPath('/companies/{company_uuid}/contractors', pathParams);
// Use standard HTTP client for other auth types
const response = await this.httpClient.get(path, { params: queryParams });
const duration = Date.now() - startTime;
this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
endpoint: 'list_contractors',
method: 'GET',
path: '/companies/{company_uuid}/contractors',
duration_ms: duration,
responseDataSize: JSON.stringify(response.data).length
});
return {
content: [
{
type: 'text',
text: JSON.stringify(response.data, null, 2)
}
]
};
}
catch (error) {
const duration = Date.now() - startTime;
this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
endpoint: 'list_contractors',
method: 'GET',
path: '/companies/{company_uuid}/contractors',
duration_ms: duration,
error: error instanceof Error ? error.message : String(error),
errorType: error instanceof Error ? error.constructor.name : 'unknown'
});
throw new Error(`Failed to execute list_contractors: ${error instanceof Error ? error.message : String(error)}`);
}
}
async createContractor(params) {
const startTime = Date.now();
this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
endpoint: 'create_contractor',
method: 'POST',
path: '/companies/{company_uuid}/contractors',
paramCount: Object.keys(params || {}).length,
paramKeys: Object.keys(params || {})
});
try {
// Extract and separate parameters by location: path, query, body
const pathTemplate = '/companies/{company_uuid}/contractors';
const pathParams = {};
const queryParams = {};
const bodyParams = {};
const extractedParams = [];
// Handle Google-style path templates: {resourceName=people/*} and {person.resourceName=people/*}
const googlePathTemplateRegex = /{([^}=]+)=[^}]*}/g;
let match;
while ((match = googlePathTemplateRegex.exec(pathTemplate)) !== null) {
const paramName = match[1]; // e.g., "resourceName" or "person.resourceName"
if (paramName && params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
}
// Handle standard path templates: {resourceName}
const standardPathParams = pathTemplate.match(/{([^}=]+)}/g) || [];
standardPathParams.forEach(paramTemplate => {
const paramName = paramTemplate.slice(1, -1); // Remove { }
// Only process if not already handled by Google template logic
if (!extractedParams.includes(paramName)) {
if (params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
else {
// Provide default values for optional path parameters
if (paramName === 'userId') {
pathParams[paramName] = 'me'; // Default to authenticated user
extractedParams.push(paramName);
}
}
}
});
// Separate remaining parameters by location (query vs body)
if (params["first_name"] !== undefined) {
bodyParams["first_name"] = params["first_name"];
extractedParams.push("first_name");
}
if (params["last_name"] !== undefined) {
bodyParams["last_name"] = params["last_name"];
extractedParams.push("last_name");
}
if (params["email"] !== undefined) {
bodyParams["email"] = params["email"];
extractedParams.push("email");
}
if (params["business_name"] !== undefined) {
bodyParams["business_name"] = params["business_name"];
extractedParams.push("business_name");
}
if (params["ein"] !== undefined) {
bodyParams["ein"] = params["ein"];
extractedParams.push("ein");
}
if (params["ssn"] !== undefined) {
bodyParams["ssn"] = params["ssn"];
extractedParams.push("ssn");
}
if (params["start_date"] !== undefined) {
bodyParams["start_date"] = params["start_date"];
extractedParams.push("start_date");
}
// Any remaining unprocessed parameters default to body for backward compatibility
for (const [key, value] of Object.entries(params)) {
if (!extractedParams.includes(key)) {
bodyParams[key] = value;
}
}
// Validate required parameters
if (!params.company_uuid) {
throw new Error(`Missing required parameter: company_uuid`);
}
if (!params.first_name) {
throw new Error(`Missing required parameter: first_name`);
}
if (!params.last_name) {
throw new Error(`Missing required parameter: last_name`);
}
if (!params.email) {
throw new Error(`Missing required parameter: email`);
}
if (!params.start_date) {
throw new Error(`Missing required parameter: start_date`);
}
const path = this.buildPath('/companies/{company_uuid}/contractors', pathParams);
// Use standard HTTP client for other auth types
const response = await this.httpClient.post(path, Object.keys(bodyParams).length > 0 ? bodyParams : undefined, { params: queryParams });
const duration = Date.now() - startTime;
this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
endpoint: 'create_contractor',
method: 'POST',
path: '/companies/{company_uuid}/contractors',
duration_ms: duration,
responseDataSize: JSON.stringify(response.data).length
});
return {
content: [
{
type: 'text',
text: JSON.stringify(response.data, null, 2)
}
]
};
}
catch (error) {
const duration = Date.now() - startTime;
this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
endpoint: 'create_contractor',
method: 'POST',
path: '/companies/{company_uuid}/contractors',
duration_ms: duration,
error: error instanceof Error ? error.message : String(error),
errorType: error instanceof Error ? error.constructor.name : 'unknown'
});
throw new Error(`Failed to execute create_contractor: ${error instanceof Error ? error.message : String(error)}`);
}
}
async getContractor(params) {
const startTime = Date.now();
this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
endpoint: 'get_contractor',
method: 'GET',
path: '/contractors/{contractor_uuid}',
paramCount: Object.keys(params || {}).length,
paramKeys: Object.keys(params || {})
});
try {
// Extract and separate parameters by location: path, query, body
const pathTemplate = '/contractors/{contractor_uuid}';
const pathParams = {};
const queryParams = {};
const bodyParams = {};
const extractedParams = [];
// Handle Google-style path templates: {resourceName=people/*} and {person.resourceName=people/*}
const googlePathTemplateRegex = /{([^}=]+)=[^}]*}/g;
let match;
while ((match = googlePathTemplateRegex.exec(pathTemplate)) !== null) {
const paramName = match[1]; // e.g., "resourceName" or "person.resourceName"
if (paramName && params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
}
// Handle standard path templates: {resourceName}
const standardPathParams = pathTemplate.match(/{([^}=]+)}/g) || [];
standardPathParams.forEach(paramTemplate => {
const paramName = paramTemplate.slice(1, -1); // Remove { }
// Only process if not already handled by Google template logic
if (!extractedParams.includes(paramName)) {
if (params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
else {
// Provide default values for optional path parameters
if (paramName === 'userId') {
pathParams[paramName] = 'me'; // Default to authenticated user
extractedParams.push(paramName);
}
}
}
});
// Separate remaining parameters by location (query vs body)
// Any remaining unprocessed parameters default to body for backward compatibility
for (const [key, value] of Object.entries(params)) {
if (!extractedParams.includes(key)) {
bodyParams[key] = value;
}
}
// Validate required parameters
if (!params.contractor_uuid) {
throw new Error(`Missing required parameter: contractor_uuid`);
}
const path = this.buildPath('/contractors/{contractor_uuid}', pathParams);
// Use standard HTTP client for other auth types
const response = await this.httpClient.get(path, { params: queryParams });
const duration = Date.now() - startTime;
this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
endpoint: 'get_contractor',
method: 'GET',
path: '/contractors/{contractor_uuid}',
duration_ms: duration,
responseDataSize: JSON.stringify(response.data).length
});
return {
content: [
{
type: 'text',
text: JSON.stringify(response.data, null, 2)
}
]
};
}
catch (error) {
const duration = Date.now() - startTime;
this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
endpoint: 'get_contractor',
method: 'GET',
path: '/contractors/{contractor_uuid}',
duration_ms: duration,
error: error instanceof Error ? error.message : String(error),
errorType: error instanceof Error ? error.constructor.name : 'unknown'
});
throw new Error(`Failed to execute get_contractor: ${error instanceof Error ? error.message : String(error)}`);
}
}
async createContractorPayment(params) {
const startTime = Date.now();
this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
endpoint: 'create_contractor_payment',
method: 'POST',
path: '/companies/{company_uuid}/contractor_payments',
paramCount: Object.keys(params || {}).length,
paramKeys: Object.keys(params || {})
});
try {
// Extract and separate parameters by location: path, query, body
const pathTemplate = '/companies/{company_uuid}/contractor_payments';
const pathParams = {};
const queryParams = {};
const bodyParams = {};
const extractedParams = [];
// Handle Google-style path templates: {resourceName=people/*} and {person.resourceName=people/*}
const googlePathTemplateRegex = /{([^}=]+)=[^}]*}/g;
let match;
while ((match = googlePathTemplateRegex.exec(pathTemplate)) !== null) {
const paramName = match[1]; // e.g., "resourceName" or "person.resourceName"
if (paramName && params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
}
// Handle standard path templates: {resourceName}
const standardPathParams = pathTemplate.match(/{([^}=]+)}/g) || [];
standardPathParams.forEach(paramTemplate => {
const paramName = paramTemplate.slice(1, -1); // Remove { }
// Only process if not already handled by Google template logic
if (!extractedParams.includes(paramName)) {
if (params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
else {
// Provide default values for optional path parameters
if (paramName === 'userId') {
pathParams[paramName] = 'me'; // Default to authenticated user
extractedParams.push(paramName);
}
}
}
});
// Separate remaining parameters by location (query vs body)
if (params["contractor_uuid"] !== undefined) {
bodyParams["contractor_uuid"] = params["contractor_uuid"];
extractedParams.push("contractor_uuid");
}
if (params["wage"] !== undefined) {
bodyParams["wage"] = params["wage"];
extractedParams.push("wage");
}
if (params["start_date"] !== undefined) {
bodyParams["start_date"] = params["start_date"];
extractedParams.push("start_date");
}
if (params["end_date"] !== undefined) {
bodyParams["end_date"] = params["end_date"];
extractedParams.push("end_date");
}
if (params["payment_date"] !== undefined) {
bodyParams["payment_date"] = params["payment_date"];
extractedParams.push("payment_date");
}
// Any remaining unprocessed parameters default to body for backward compatibility
for (const [key, value] of Object.entries(params)) {
if (!extractedParams.includes(key)) {
bodyParams[key] = value;
}
}
// Validate required parameters
if (!params.company_uuid) {
throw new Error(`Missing required parameter: company_uuid`);
}
if (!params.contractor_uuid) {
throw new Error(`Missing required parameter: contractor_uuid`);
}
if (!params.wage) {
throw new Error(`Missing required parameter: wage`);
}
if (!params.start_date) {
throw new Error(`Missing required parameter: start_date`);
}
if (!params.end_date) {
throw new Error(`Missing required parameter: end_date`);
}
if (!params.payment_date) {
throw new Error(`Missing required parameter: payment_date`);
}
const path = this.buildPath('/companies/{company_uuid}/contractor_payments', pathParams);
// Use standard HTTP client for other auth types
const response = await this.httpClient.post(path, Object.keys(bodyParams).length > 0 ? bodyParams : undefined, { params: queryParams });
const duration = Date.now() - startTime;
this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
endpoint: 'create_contractor_payment',
method: 'POST',
path: '/companies/{company_uuid}/contractor_payments',
duration_ms: duration,
responseDataSize: JSON.stringify(response.data).length
});
return {
content: [
{
type: 'text',
text: JSON.stringify(response.data, null, 2)
}
]
};
}
catch (error) {
const duration = Date.now() - startTime;
this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
endpoint: 'create_contractor_payment',
method: 'POST',
path: '/companies/{company_uuid}/contractor_payments',
duration_ms: duration,
error: error instanceof Error ? error.message : String(error),
errorType: error instanceof Error ? error.constructor.name : 'unknown'
});
throw new Error(`Failed to execute create_contractor_payment: ${error instanceof Error ? error.message : String(error)}`);
}
}
async getContractorPayment(params) {
const startTime = Date.now();
this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
endpoint: 'get_contractor_payment',
method: 'GET',
path: '/companies/{company_uuid}/contractor_payments/{contractor_payment_uuid}',
paramCount: Object.keys(params || {}).length,
paramKeys: Object.keys(params || {})
});
try {
// Extract and separate parameters by location: path, query, body
const pathTemplate = '/companies/{company_uuid}/contractor_payments/{contractor_payment_uuid}';
const pathParams = {};
const queryParams = {};
const bodyParams = {};
const extractedParams = [];
// Handle Google-style path templates: {resourceName=people/*} and {person.resourceName=people/*}
const googlePathTemplateRegex = /{([^}=]+)=[^}]*}/g;
let match;
while ((match = googlePathTemplateRegex.exec(pathTemplate)) !== null) {
const paramName = match[1]; // e.g., "resourceName" or "person.resourceName"
if (paramName && params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
}
// Handle standard path templates: {resourceName}
const standardPathParams = pathTemplate.match(/{([^}=]+)}/g) || [];
standardPathParams.forEach(paramTemplate => {
const paramName = paramTemplate.slice(1, -1); // Remove { }
// Only process if not already handled by Google template logic
if (!extractedParams.includes(paramName)) {
if (params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
else {
// Provide default values for optional path parameters
if (paramName === 'userId') {
pathParams[paramName] = 'me'; // Default to authenticated user
extractedParams.push(paramName);
}
}
}
});
// Separate remaining parameters by location (query vs body)
// Any remaining unprocessed parameters default to body for backward compatibility
for (const [key, value] of Object.entries(params)) {
if (!extractedParams.includes(key)) {
bodyParams[key] = value;
}
}
// Validate required parameters
if (!params.company_uuid) {
throw new Error(`Missing required parameter: company_uuid`);
}
if (!params.contractor_payment_uuid) {
throw new Error(`Missing required parameter: contractor_payment_uuid`);
}
const path = this.buildPath('/companies/{company_uuid}/contractor_payments/{contractor_payment_uuid}', pathParams);
// Use standard HTTP client for other auth types
const response = await this.httpClient.get(path, { params: queryParams });
const duration = Date.now() - startTime;
this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
endpoint: 'get_contractor_payment',
method: 'GET',
path: '/companies/{company_uuid}/contractor_payments/{contractor_payment_uuid}',
duration_ms: duration,
responseDataSize: JSON.stringify(response.data).length
});
return {
content: [
{
type: 'text',
text: JSON.stringify(response.data, null, 2)
}
]
};
}
catch (error) {
const duration = Date.now() - startTime;
this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
endpoint: 'get_contractor_payment',
method: 'GET',
path: '/companies/{company_uuid}/contractor_payments/{contractor_payment_uuid}',
duration_ms: duration,
error: error instanceof Error ? error.message : String(error),
errorType: error instanceof Error ? error.constructor.name : 'unknown'
});
throw new Error(`Failed to execute get_contractor_payment: ${error instanceof Error ? error.message : String(error)}`);
}
}
async listCompanyBenefits(params) {
const startTime = Date.now();
this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
endpoint: 'list_company_benefits',
method: 'GET',
path: '/companies/{company_uuid}/company_benefits',
paramCount: Object.keys(params || {}).length,
paramKeys: Object.keys(params || {})
});
try {
// Extract and separate parameters by location: path, query, body
const pathTemplate = '/companies/{company_uuid}/company_benefits';
const pathParams = {};
const queryParams = {};
const bodyParams = {};
const extractedParams = [];
// Handle Google-style path templates: {resourceName=people/*} and {person.resourceName=people/*}
const googlePathTemplateRegex = /{([^}=]+)=[^}]*}/g;
let match;
while ((match = googlePathTemplateRegex.exec(pathTemplate)) !== null) {
const paramName = match[1]; // e.g., "resourceName" or "person.resourceName"
if (paramName && params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
}
// Handle standard path templates: {resourceName}
const standardPathParams = pathTemplate.match(/{([^}=]+)}/g) || [];
standardPathParams.forEach(paramTemplate => {
const paramName = paramTemplate.slice(1, -1); // Remove { }
// Only process if not already handled by Google template logic
if (!extractedParams.includes(paramName)) {
if (params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
else {
// Provide default values for optional path parameters
if (paramName === 'userId') {
pathParams[paramName] = 'me'; // Default to authenticated user
extractedParams.push(paramName);
}
}
}
});
// Separate remaining parameters by location (query vs body)
// Any remaining unprocessed parameters default to body for backward compatibility
for (const [key, value] of Object.entries(params)) {
if (!extractedParams.includes(key)) {
bodyParams[key] = value;
}
}
// Validate required parameters
if (!params.company_uuid) {
throw new Error(`Missing required parameter: company_uuid`);
}
const path = this.buildPath('/companies/{company_uuid}/company_benefits', pathParams);
// Use standard HTTP client for other auth types
const response = await this.httpClient.get(path, { params: queryParams });
const duration = Date.now() - startTime;
this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
endpoint: 'list_company_benefits',
method: 'GET',
path: '/companies/{company_uuid}/company_benefits',
duration_ms: duration,
responseDataSize: JSON.stringify(response.data).length
});
return {
content: [
{
type: 'text',
text: JSON.stringify(response.data, null, 2)
}
]
};
}
catch (error) {
const duration = Date.now() - startTime;
this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
endpoint: 'list_company_benefits',
method: 'GET',
path: '/companies/{company_uuid}/company_benefits',
duration_ms: duration,
error: error instanceof Error ? error.message : String(error),
errorType: error instanceof Error ? error.constructor.name : 'unknown'
});
throw new Error(`Failed to execute list_company_benefits: ${error instanceof Error ? error.message : String(error)}`);
}
}
async getCompanyBenefit(params) {
const startTime = Date.now();
this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
endpoint: 'get_company_benefit',
method: 'GET',
path: '/company_benefits/{company_benefit_uuid}',
paramCount: Object.keys(params || {}).length,
paramKeys: Object.keys(params || {})
});
try {
// Extract and separate parameters by location: path, query, body
const pathTemplate = '/company_benefits/{company_benefit_uuid}';
const pathParams = {};
const queryParams = {};
const bodyParams = {};
const extractedParams = [];
// Handle Google-style path templates: {resourceName=people/*} and {person.resourceName=people/*}
const googlePathTemplateRegex = /{([^}=]+)=[^}]*}/g;
let match;
while ((match = googlePathTemplateRegex.exec(pathTemplate)) !== null) {
const paramName = match[1]; // e.g., "resourceName" or "person.resourceName"
if (paramName && params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
}
// Handle standard path templates: {resourceName}
const standardPathParams = pathTemplate.match(/{([^}=]+)}/g) || [];
standardPathParams.forEach(paramTemplate => {
const paramName = paramTemplate.slice(1, -1); // Remove { }
// Only process if not already handled by Google template logic
if (!extractedParams.includes(paramName)) {
if (params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
else {
// Provide default values for optional path parameters
if (paramName === 'userId') {
pathParams[paramName] = 'me'; // Default to authenticated user
extractedParams.push(paramName);
}
}
}
});
// Separate remaining parameters by location (query vs body)
// Any remaining unprocessed parameters default to body for backward compatibility
for (const [key, value] of Object.entries(params)) {
if (!extractedParams.includes(key)) {
bodyParams[key] = value;
}
}
// Validate required parameters
if (!params.company_benefit_uuid) {
throw new Error(`Missing required parameter: company_benefit_uuid`);
}
const path = this.buildPath('/company_benefits/{company_benefit_uuid}', pathParams);
// Use standard HTTP client for other auth types
const response = await this.httpClient.get(path, { params: queryParams });
const duration = Date.now() - startTime;
this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
endpoint: 'get_company_benefit',
method: 'GET',
path: '/company_benefits/{company_benefit_uuid}',
duration_ms: duration,
responseDataSize: JSON.stringify(response.data).length
});
return {
content: [
{
type: 'text',
text: JSON.stringify(response.data, null, 2)
}
]
};
}
catch (error) {
const duration = Date.now() - startTime;
this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
endpoint: 'get_company_benefit',
method: 'GET',
path: '/company_benefits/{company_benefit_uuid}',
duration_ms: duration,
error: error instanceof Error ? error.message : String(error),
errorType: error instanceof Error ? error.constructor.name : 'unknown'
});
throw new Error(`Failed to execute get_company_benefit: ${error instanceof Error ? error.message : String(error)}`);
}
}
async getCompanyBenefitSummary(params) {
const startTime = Date.now();
this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
endpoint: 'get_company_benefit_summary',
method: 'GET',
path: '/company_benefits/{company_benefit_uuid}/summary',
paramCount: Object.keys(params || {}).length,
paramKeys: Object.keys(params || {})
});
try {
// Extract and separate parameters by location: path, query, body
const pathTemplate = '/company_benefits/{company_benefit_uuid}/summary';
const pathParams = {};
const queryParams = {};
const bodyParams = {};
const extractedParams = [];
// Handle Google-style path templates: {resourceName=people/*} and {person.resourceName=people/*}
const googlePathTemplateRegex = /{([^}=]+)=[^}]*}/g;
let match;
while ((match = googlePathTemplateRegex.exec(pathTemplate)) !== null) {
const paramName = match[1]; // e.g., "resourceName" or "person.resourceName"
if (paramName && params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
}
// Handle standard path templates: {resourceName}
const standardPathParams = pathTemplate.match(/{([^}=]+)}/g) || [];
standardPathParams.forEach(paramTemplate => {
const paramName = paramTemplate.slice(1, -1); // Remove { }
// Only process if not already handled by Google template logic
if (!extractedParams.includes(paramName)) {
if (params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
else {
// Provide default values for optional path parameters
if (paramName === 'userId') {
pathParams[paramName] = 'me'; // Default to authenticated user
extractedParams.push(paramName);
}
}
}
});
// Separate remaining parameters by location (query vs body)
// Any remaining unprocessed parameters default to body for backward compatibility
for (const [key, value] of Object.entries(params)) {
if (!extractedParams.includes(key)) {
bodyParams[key] = value;
}
}
// Validate required parameters
if (!params.company_benefit_uuid) {
throw new Error(`Missing required parameter: company_benefit_uuid`);
}
const path = this.buildPath('/company_benefits/{company_benefit_uuid}/summary', pathParams);
// Use standard HTTP client for other auth types
const response = await this.httpClient.get(path, { params: queryParams });
const duration = Date.now() - startTime;
this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
endpoint: 'get_company_benefit_summary',
method: 'GET',
path: '/company_benefits/{company_benefit_uuid}/summary',
duration_ms: duration,
responseDataSize: JSON.stringify(response.data).length
});
return {
content: [
{
type: 'text',
text: JSON.stringify(response.data, null, 2)
}
]
};
}
catch (error) {
const duration = Date.now() - startTime;
this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
endpoint: 'get_company_benefit_summary',
method: 'GET',
path: '/company_benefits/{company_benefit_uuid}/summary',
duration_ms: duration,
error: error instanceof Error ? error.message : String(error),
errorType: error instanceof Error ? error.constructor.name : 'unknown'
});
throw new Error(`Failed to execute get_company_benefit_summary: ${error instanceof Error ? error.message : String(error)}`);
}
}
async createTimeOffPolicy(params) {
const startTime = Date.now();
this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
endpoint: 'create_time_off_policy',
method: 'POST',
path: '/companies/{company_uuid}/time_off_policies',
paramCount: Object.keys(params || {}).length,
paramKeys: Object.keys(params || {})
});
try {
// Extract and separate parameters by location: path, query, body
const pathTemplate = '/companies/{company_uuid}/time_off_policies';
const pathParams = {};
const queryParams = {};
const bodyParams = {};
const extractedParams = [];
// Handle Google-style path templates: {resourceName=people/*} and {person.resourceName=people/*}
const googlePathTemplateRegex = /{([^}=]+)=[^}]*}/g;
let match;
while ((match = googlePathTemplateRegex.exec(pathTemplate)) !== null) {
const paramName = match[1]; // e.g., "resourceName" or "person.resourceName"
if (paramName && params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
}
// Handle standard path templates: {resourceName}
const standardPathParams = pathTemplate.match(/{([^}=]+)}/g) || [];
standardPathParams.forEach(paramTemplate => {
const paramName = paramTemplate.slice(1, -1); // Remove { }
// Only process if not already handled by Google template logic
if (!extractedParams.includes(paramName)) {
if (params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
else {
// Provide default values for optional path parameters
if (paramName === 'userId') {
pathParams[paramName] = 'me'; // Default to authenticated user
extractedParams.push(paramName);
}
}
}
});
// Separate remaining parameters by location (query vs body)
if (params["name"] !== undefined) {
bodyParams["name"] = params["name"];
extractedParams.push("name");
}
if (params["policy_type"] !== undefined) {
bodyParams["policy_type"] = params["policy_type"];
extractedParams.push("policy_type");
}
if (params["accrual_unit"] !== undefined) {
bodyParams["accrual_unit"] = params["accrual_unit"];
extractedParams.push("accrual_unit");
}
if (params["accrual_rate"] !== undefined) {
bodyParams["accrual_rate"] = params["accrual_rate"];
extractedParams.push("accrual_rate");
}
if (params["accrual_period"] !== undefined) {
bodyParams["accrual_period"] = params["accrual_period"];
extractedParams.push("accrual_period");
}
// Any remaining unprocessed parameters default to body for backward compatibility
for (const [key, value] of Object.entries(params)) {
if (!extractedParams.includes(key)) {
bodyParams[key] = value;
}
}
// Validate required parameters
if (!params.company_uuid) {
throw new Error(`Missing required parameter: company_uuid`);
}
if (!params.name) {
throw new Error(`Missing required parameter: name`);
}
if (!params.policy_type) {
throw new Error(`Missing required parameter: policy_type`);
}
const path = this.buildPath('/companies/{company_uuid}/time_off_policies', pathParams);
// Use standard HTTP client for other auth types
const response = await this.httpClient.post(path, Object.keys(bodyParams).length > 0 ? bodyParams : undefined, { params: queryParams });
const duration = Date.now() - startTime;
this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
endpoint: 'create_time_off_policy',
method: 'POST',
path: '/companies/{company_uuid}/time_off_policies',
duration_ms: duration,
responseDataSize: JSON.stringify(response.data).length
});
return {
content: [
{
type: 'text',
text: JSON.stringify(response.data, null, 2)
}
]
};
}
catch (error) {
const duration = Date.now() - startTime;
this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
endpoint: 'create_time_off_policy',
method: 'POST',
path: '/companies/{company_uuid}/time_off_policies',
duration_ms: duration,
error: error instanceof Error ? error.message : String(error),
errorType: error instanceof Error ? error.constructor.name : 'unknown'
});
throw new Error(`Failed to execute create_time_off_policy: ${error instanceof Error ? error.message : String(error)}`);
}
}
async listTimeOffPolicies(params) {
const startTime = Date.now();
this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
endpoint: 'list_time_off_policies',
method: 'GET',
path: '/companies/{company_uuid}/time_off_policies',
paramCount: Object.keys(params || {}).length,
paramKeys: Object.keys(params || {})
});
try {
// Extract and separate parameters by location: path, query, body
const pathTemplate = '/companies/{company_uuid}/time_off_policies';
const pathParams = {};
const queryParams = {};
const bodyParams = {};
const extractedParams = [];
// Handle Google-style path templates: {resourceName=people/*} and {person.resourceName=people/*}
const googlePathTemplateRegex = /{([^}=]+)=[^}]*}/g;
let match;
while ((match = googlePathTemplateRegex.exec(pathTemplate)) !== null) {
const paramName = match[1]; // e.g., "resourceName" or "person.resourceName"
if (paramName && params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
}
// Handle standard path templates: {resourceName}
const standardPathParams = pathTemplate.match(/{([^}=]+)}/g) || [];
standardPathParams.forEach(paramTemplate => {
const paramName = paramTemplate.slice(1, -1); // Remove { }
// Only process if not already handled by Google template logic
if (!extractedParams.includes(paramName)) {
if (params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
else {
// Provide default values for optional path parameters
if (paramName === 'userId') {
pathParams[paramName] = 'me'; // Default to authenticated user
extractedParams.push(paramName);
}
}
}
});
// Separate remaining parameters by location (query vs body)
// Any remaining unprocessed parameters default to body for backward compatibility
for (const [key, value] of Object.entries(params)) {
if (!extractedParams.includes(key)) {
bodyParams[key] = value;
}
}
// Validate required parameters
if (!params.company_uuid) {
throw new Error(`Missing required parameter: company_uuid`);
}
const path = this.buildPath('/companies/{company_uuid}/time_off_policies', pathParams);
// Use standard HTTP client for other auth types
const response = await this.httpClient.get(path, { params: queryParams });
const duration = Date.now() - startTime;
this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
endpoint: 'list_time_off_policies',
method: 'GET',
path: '/companies/{company_uuid}/time_off_policies',
duration_ms: duration,
responseDataSize: JSON.stringify(response.data).length
});
return {
content: [
{
type: 'text',
text: JSON.stringify(response.data, null, 2)
}
]
};
}
catch (error) {
const duration = Date.now() - startTime;
this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
endpoint: 'list_time_off_policies',
method: 'GET',
path: '/companies/{company_uuid}/time_off_policies',
duration_ms: duration,
error: error instanceof Error ? error.message : String(error),
errorType: error instanceof Error ? error.constructor.name : 'unknown'
});
throw new Error(`Failed to execute list_time_off_policies: ${error instanceof Error ? error.message : String(error)}`);
}
}
async getCurrentUser(params) {
const startTime = Date.now();
this.logger.info('ENDPOINT_START', 'Endpoint execution started', {
endpoint: 'get_current_user',
method: 'GET',
path: '/me',
paramCount: Object.keys(params || {}).length,
paramKeys: Object.keys(params || {})
});
try {
// Extract and separate parameters by location: path, query, body
const pathTemplate = '/me';
const pathParams = {};
const queryParams = {};
const bodyParams = {};
const extractedParams = [];
// Handle Google-style path templates: {resourceName=people/*} and {person.resourceName=people/*}
const googlePathTemplateRegex = /{([^}=]+)=[^}]*}/g;
let match;
while ((match = googlePathTemplateRegex.exec(pathTemplate)) !== null) {
const paramName = match[1]; // e.g., "resourceName" or "person.resourceName"
if (paramName && params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
}
// Handle standard path templates: {resourceName}
const standardPathParams = pathTemplate.match(/{([^}=]+)}/g) || [];
standardPathParams.forEach(paramTemplate => {
const paramName = paramTemplate.slice(1, -1); // Remove { }
// Only process if not already handled by Google template logic
if (!extractedParams.includes(paramName)) {
if (params[paramName] !== undefined) {
pathParams[paramName] = params[paramName];
extractedParams.push(paramName);
}
else {
// Provide default values for optional path parameters
if (paramName === 'userId') {
pathParams[paramName] = 'me'; // Default to authenticated user
extractedParams.push(paramName);
}
}
}
});
// Any remaining unprocessed parameters default to body for backward compatibility
for (const [key, value] of Object.entries(params)) {
if (!extractedParams.includes(key)) {
bodyParams[key] = value;
}
}
const path = this.buildPath('/me', pathParams);
// Use standard HTTP client for other auth types
const response = await this.httpClient.get(path, { params: queryParams });
const duration = Date.now() - startTime;
this.logger.info('ENDPOINT_SUCCESS', 'Endpoint execution completed successfully', {
endpoint: 'get_current_user',
method: 'GET',
path: '/me',
duration_ms: duration,
responseDataSize: JSON.stringify(response.data).length
});
return {
content: [
{
type: 'text',
text: JSON.stringify(response.data, null, 2)
}
]
};
}
catch (error) {
const duration = Date.now() - startTime;
this.logger.error('ENDPOINT_ERROR', 'Endpoint execution failed', {
endpoint: 'get_current_user',
method: 'GET',
path: '/me',
duration_ms: duration,
error: error instanceof Error ? error.message : String(error),
errorType: error instanceof Error ? error.constructor.name : 'unknown'
});
throw new Error(`Failed to execute get_current_user: ${error instanceof Error ? error.message : String(error)}`);
}
}
}
//# sourceMappingURL=gusto-client.js.map