Edits history of script submission #15456 for ' External HR Time Off Synchronization (deel)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    /**
     * External HR Time Off Synchronization
     * Synchronize time off requests from an external HRIS to Deel.
     */
    export async function main(auth: RT.Deel, body: Body) {
    	const url = new URL(`https://api.letsdeel.com/rest/v2/time_offs/global-payroll/sync`)
    
    	const response = await fetch(url, {
    		method: 'POST',
    		headers: {
    			'Content-Type': 'application/json',
    			Authorization: 'Bearer ' + auth.apiKey
    		},
    		body: JSON.stringify(body)
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    
    /* eslint-disable */
    /**
     * This file was automatically generated by json-schema-to-typescript.
     * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
     * and run json-schema-to-typescript to regenerate this file.
     */
    
    export interface Body {
    	data?: {
    		time_offs: (
    			| {
    					/**
    					 * The amount in time units for this time off. When no amount is informed, it will be calculated using work schedules and public holidays defined at Deel.
    					 */
    					amount?: number
    					/**
    					 * Allows the consumer to specify whether the time off is considered as paid (at statutory) or unpaid based on the configuration of the policy in the external HRIS.
    					 */
    					is_paid?: boolean
    					/**
    					 * The end date of the time off.
    					 */
    					end_date: string
    					/**
    					 * The start date of the time off.
    					 */
    					start_date: string
    					/**
    					 * The approval date of the time off. If no approval date is informed, the start date of this request will be used as the approval date. Note: use this field in order to support retrospective leaves so Deel can identify requests made after the payroll cycle.
    					 */
    					approved_at?: string
    					/**
    					 * The description of the time off.
    					 */
    					description?: string
    					/**
    					 * External ID to link a Deel time off object with an external time off object. It will be used to determine which operation should be done: INSERT, UPDATE or DELETE.
    					 */
    					external_id: string
    					/**
    					 * The policy name the time off is being requested for. If not informed, a default name will be generated using the policy type and contract's country (eg: Vacation - US).
    					 */
    					policy_name?: string
    					/**
    					 * The Deel policy type of the policy the time off is being requested for.
    					 */
    					policy_type:
    						| 'Adoption leave'
    						| 'Advanced vacation'
    						| 'Bereavement leave'
    						| 'Blood donation leave'
    						| 'Breastfeeding leave'
    						| 'Childbirth leave'
    						| 'Childcare leave'
    						| 'Civic/public duty leave'
    						| 'Disability leave'
    						| "Doctor's appointment leave"
    						| 'Family & domestic violence leave'
    						| 'Floating Holiday Allowance'
    						| 'Hajj leave'
    						| 'Marriage/wedding leave'
    						| 'Maternity leave'
    						| 'Military leave'
    						| 'Moving leave'
    						| 'Other leave'
    						| 'Paid leave'
    						| 'Parental leave'
    						| 'Paternity leave'
    						| 'Personal leave'
    						| 'Pregnancy leave'
    						| 'Regional holiday'
    						| 'RTT'
    						| 'Sick leave'
    						| 'Study leave'
    						| 'Supplementary Leave'
    						| 'Unpaid leave'
    						| 'Vacation'
    						| 'Volunteer leave'
    						| 'Work accident leave'
    					/**
    					 * The contract id that has requested the time off.
    					 */
    					contract_oid: string
    					/**
    					 * The request date of the time off.
    					 */
    					requested_at?: string
    					/**
    					 * The time unit for this time off. *Mandatory when amount parameter is informed*. If no amount and no entitlement_unit are informed, it will be calculated using Deel's internal country templates for compliant time off policies.
    					 */
    					entitlement_unit?: 'HOUR' | 'BUSINESS_DAY' | 'CALENDAR_DAY' | 'WEEK' | 'MONTH' | 'YEAR'
    					[k: string]: unknown
    			  }
    			| {
    					/**
    					 * Indicates this time off request must be deleted
    					 */
    					deleted: true
    					/**
    					 * External ID to link a Deel time off object with an external time off object. It will be used to determine which operation should be done: INSERT, UPDATE or DELETE.
    					 */
    					external_id: string
    					/**
    					 * The contract id that has requested the time off.
    					 */
    					contract_oid: string
    					[k: string]: unknown
    			  }
    		)[]
    		[k: string]: unknown
    	}
    	[k: string]: unknown
    }
    

    Submitted by hugo697 235 days ago