|
| 1 | +import { filterUndefined } from '@sim/utils/object' |
| 2 | +import { ErrorExtractorId } from '@/tools/error-extractors' |
| 3 | +import { QUICKBOOKS_MAX_RESPONSE_BYTES } from '@/tools/quickbooks/client' |
| 4 | +import type { |
| 5 | + QuickBooksCreateEmployeeParams, |
| 6 | + QuickBooksEmployee, |
| 7 | + QuickBooksMutationResponse, |
| 8 | +} from '@/tools/quickbooks/types' |
| 9 | +import { |
| 10 | + QUICKBOOKS_EMPLOYEE_PROPERTIES, |
| 11 | + QUICKBOOKS_MUTATION_OUTPUTS, |
| 12 | +} from '@/tools/quickbooks/types' |
| 13 | +import { |
| 14 | + addQuickBooksRequestId, |
| 15 | + buildQuickBooksEntityUrl, |
| 16 | + getQuickBooksToolHeaders, |
| 17 | + optionalQuickBooksString, |
| 18 | + parseQuickBooksAddress, |
| 19 | + quickBooksEmailAddress, |
| 20 | + quickBooksPhoneNumber, |
| 21 | + requiredQuickBooksString, |
| 22 | + sanitizeQuickBooksEmployee, |
| 23 | + transformQuickBooksMutationResponse, |
| 24 | +} from '@/tools/quickbooks/utils' |
| 25 | +import type { ToolConfig } from '@/tools/types' |
| 26 | + |
| 27 | +export const quickbooksCreateEmployeeTool: ToolConfig< |
| 28 | + QuickBooksCreateEmployeeParams, |
| 29 | + QuickBooksMutationResponse<QuickBooksEmployee> |
| 30 | +> = { |
| 31 | + id: 'quickbooks_create_employee', |
| 32 | + name: 'QuickBooks Create Employee', |
| 33 | + description: 'Create a non-payroll employee profile in the connected QuickBooks Online company', |
| 34 | + version: '1.0.0', |
| 35 | + params: { |
| 36 | + accessToken: { |
| 37 | + type: 'string', |
| 38 | + required: true, |
| 39 | + visibility: 'hidden', |
| 40 | + description: 'QuickBooks OAuth access token', |
| 41 | + }, |
| 42 | + realmId: { |
| 43 | + type: 'string', |
| 44 | + required: true, |
| 45 | + visibility: 'hidden', |
| 46 | + description: 'QuickBooks company ID derived from the connected credential', |
| 47 | + }, |
| 48 | + displayName: { |
| 49 | + type: 'string', |
| 50 | + required: true, |
| 51 | + visibility: 'user-or-llm', |
| 52 | + description: 'Unique employee display name', |
| 53 | + }, |
| 54 | + givenName: { |
| 55 | + type: 'string', |
| 56 | + required: false, |
| 57 | + visibility: 'user-or-llm', |
| 58 | + description: 'Employee given name', |
| 59 | + }, |
| 60 | + familyName: { |
| 61 | + type: 'string', |
| 62 | + required: false, |
| 63 | + visibility: 'user-or-llm', |
| 64 | + description: 'Employee family name', |
| 65 | + }, |
| 66 | + primaryEmail: { |
| 67 | + type: 'string', |
| 68 | + required: false, |
| 69 | + visibility: 'user-or-llm', |
| 70 | + description: 'Employee primary email address', |
| 71 | + }, |
| 72 | + primaryPhone: { |
| 73 | + type: 'string', |
| 74 | + required: false, |
| 75 | + visibility: 'user-or-llm', |
| 76 | + description: 'Employee primary phone number', |
| 77 | + }, |
| 78 | + primaryAddress: { |
| 79 | + type: 'json', |
| 80 | + required: false, |
| 81 | + visibility: 'user-or-llm', |
| 82 | + description: 'Employee primary address', |
| 83 | + }, |
| 84 | + printOnCheckName: { |
| 85 | + type: 'string', |
| 86 | + required: false, |
| 87 | + visibility: 'user-or-llm', |
| 88 | + description: 'Employee name printed on checks', |
| 89 | + }, |
| 90 | + billableTime: { |
| 91 | + type: 'boolean', |
| 92 | + required: false, |
| 93 | + visibility: 'user-or-llm', |
| 94 | + description: 'Whether employee time is billable', |
| 95 | + }, |
| 96 | + requestId: { |
| 97 | + type: 'string', |
| 98 | + required: false, |
| 99 | + visibility: 'user-or-llm', |
| 100 | + description: 'Optional Intuit idempotency request ID, up to 50 characters', |
| 101 | + }, |
| 102 | + }, |
| 103 | + oauth: { |
| 104 | + required: true, |
| 105 | + provider: 'quickbooks', |
| 106 | + requiredScopes: ['com.intuit.quickbooks.accounting'], |
| 107 | + }, |
| 108 | + errorExtractor: ErrorExtractorId.QUICKBOOKS_FAULT, |
| 109 | + request: { |
| 110 | + url: (params) => |
| 111 | + addQuickBooksRequestId( |
| 112 | + buildQuickBooksEntityUrl(params.realmId, 'employee'), |
| 113 | + params.requestId |
| 114 | + ).toString(), |
| 115 | + method: 'POST', |
| 116 | + headers: (params) => getQuickBooksToolHeaders(params.accessToken, 'application/json'), |
| 117 | + body: (params) => |
| 118 | + filterUndefined({ |
| 119 | + DisplayName: requiredQuickBooksString(params.displayName, 'displayName'), |
| 120 | + GivenName: optionalQuickBooksString(params.givenName), |
| 121 | + FamilyName: optionalQuickBooksString(params.familyName), |
| 122 | + PrimaryEmailAddr: quickBooksEmailAddress(params.primaryEmail), |
| 123 | + PrimaryPhone: quickBooksPhoneNumber(params.primaryPhone), |
| 124 | + PrimaryAddr: parseQuickBooksAddress(params.primaryAddress, 'primaryAddress'), |
| 125 | + PrintOnCheckName: optionalQuickBooksString(params.printOnCheckName), |
| 126 | + BillableTime: params.billableTime, |
| 127 | + }), |
| 128 | + retry: { enabled: false }, |
| 129 | + maxResponseBytes: QUICKBOOKS_MAX_RESPONSE_BYTES, |
| 130 | + }, |
| 131 | + transformResponse: (response) => |
| 132 | + transformQuickBooksMutationResponse<QuickBooksEmployee>( |
| 133 | + response, |
| 134 | + 'Employee', |
| 135 | + sanitizeQuickBooksEmployee |
| 136 | + ), |
| 137 | + outputs: { |
| 138 | + record: { |
| 139 | + type: 'json', |
| 140 | + description: 'Created QuickBooks Employee record', |
| 141 | + properties: QUICKBOOKS_EMPLOYEE_PROPERTIES, |
| 142 | + }, |
| 143 | + ...QUICKBOOKS_MUTATION_OUTPUTS, |
| 144 | + }, |
| 145 | +} |
0 commit comments