import {z} from 'zod' export type GetApiV2OrganizationsOrganizationIdInsightsToolClassificationsArgs = {organization_id: number, page_start_id?: number | undefined, page_limit?: number | undefined, tool_type: 'application' | 'url', name?: string | undefined, job_type?: string | undefined, productivity?: ('core' | 'non_core' | 'unproductive') | undefined}; export type GetApiV2OrganizationsOrganizationIdInsightsToolClassificationsOptions = {baseUrl?: string | undefined, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const toolClassification = z.object({id: z.number().int(), tool_type: z.string(), name: z.string(), productivity: z.string(), job_type: z.string(), category: z.string()}); export const getApiV2OrganizationsOrganizationIdInsightsToolClassificationsResponse = z.object({tool_classifications: z.array(toolClassification).optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * List tool classifications * * GET /v2/organizations/{organization_id}/insights/tool_classifications */ export const getApiV2OrganizationsOrganizationIdInsightsToolClassifications = async (args: GetApiV2OrganizationsOrganizationIdInsightsToolClassificationsArgs, options?: GetApiV2OrganizationsOrganizationIdInsightsToolClassificationsOptions) => { const {baseUrl = "https://api.hubstaff.com", fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page_start_id != null) query.append("page_start_id", String(args.page_start_id)) if (args.page_limit != null) query.append("page_limit", String(args.page_limit)) if (args.tool_type != null) query.append("tool_type", String(args.tool_type)) if (args.name != null) query.append("name", String(args.name)) if (args.job_type != null) query.append("job_type", String(args.job_type)) if (args.productivity != null) query.append("productivity", String(args.productivity)) if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/organizations/${encodeURIComponent(String(args.organization_id))}/insights/tool_classifications${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiV2OrganizationsOrganizationIdInsightsToolClassificationsResponse, await res.json()) };