Edits history of script submission #15390 for ' Create a new contract (deel)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    /**
     * Create a new contract
     * Create a new Deel contract.
     **Token scopes**: `contracts:write`
     */
    export async function main(auth: RT.Deel, body: Body) {
    	const url = new URL(`https://api.letsdeel.com/rest/v2/contracts`)
    
    	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 type PAY_AS_YOU_GO_TIME_BASED = {
    	/**
    	 * Additional custom info about a contract
    	 */
    	meta: {
    		/**
    		 * Flag to indicate if the contract is the main income for the contractor.
    		 */
    		is_main_income?: boolean
    		/**
    		 * Require the contractor to upload necessary compliance documents as per their country’s labor laws.
    		 */
    		documents_required: boolean
    		[k: string]: unknown
    	}
    	/**
    	 * The title of the contract.
    	 */
    	title: string
    	client: {
    		/**
    		 * Choose the Deel team for this contract. Use teams endpoint to retrieve a list of teams in your organization.
    		 */
    		team: {
    			/**
    			 * Unique identifier of this resource.
    			 */
    			id: string | number
    			[k: string]: unknown
    		}
    		/**
    		 * Choose the Deel legal entity for this contract. Use legal entity endpoint to retrieve a list of legal entities in your organization.
    		 */
    		legal_entity: {
    			/**
    			 * Unique identifier of this resource.
    			 */
    			id: string | number
    			[k: string]: unknown
    		}
    		[k: string]: unknown
    	}
    	/**
    	 * Worker properties
    	 */
    	worker?: {
    		/**
    		 * Worker's last name
    		 */
    		last_name?: string
    		/**
    		 * Worker's first name
    		 */
    		first_name: string
    		/**
    		 * Worker's email address.
    		 */
    		expected_email: string
    		[k: string]: unknown
    	}
    	/**
    	 * Worker's job title. You can enter a custom job title or use a pre-defined job title using the Id retrieved in job-titles endpoint.
    	 */
    	job_title: {
    		/**
    		 * Unique identifier of this resource.
    		 */
    		id?: string | number
    		/**
    		 * Job title. Please leave it blank when entering an Id.
    		 */
    		name?: string
    		[k: string]: unknown
    	}
    	/**
    	 * Job seniority level. Please use the seniority levels endpoint to retrieve the list of seniority levels.
    	 */
    	seniority?: {
    		/**
    		 * Unique identifier of this resource.
    		 */
    		id?: string | number
    		[k: string]: unknown
    	}
    	/**
    	 * The state or province code. Use country lookup endpoint to retrieve state codes.
    	 */
    	state_code?: string
    	/**
    	 * External Id.
    	 */
    	external_id?: string
    	/**
    	 * Flag to indicate who is supposed to provide regular reports
    	 */
    	who_reports?: 'both' | 'client' | 'contractor'
    	/**
    	 * Country code.
    	 */
    	country_code?: string
    	/**
    	 * Days before to notice the termination of contract for either party.
    	 */
    	notice_period?: number
    	/**
    	 * Describe the work to be performed.
    	 */
    	scope_of_work?: string
    	/**
    	 * Enter any special clause you may have.
    	 */
    	special_clause?: string
    	/**
    	 * Short date in format ISO-8601 (YYYY-MM-DD). For example: 2022-12-31.
    	 */
    	termination_date?: string
    	/**
    	 * Contract Template Id.
    	 */
    	contract_template_id?: string
    	[k: string]: unknown
    } & {
    	/**
    	 * Type of contract
    	 */
    	type: 'pay_as_you_go_time_based'
    	/**
    	 * Short date in format ISO-8601 (YYYY-MM-DD). For example: 2022-12-31.
    	 */
    	start_date: string
    	[k: string]: unknown
    } & {
    	compensation_details: {
    		/**
    		 * Amount to be paid. This field can be excluded when creating a Pay-as-you-go task-based or Milestone contracts.
    		 */
    		amount?: number
    		/**
    		 * Date invoice cycle ends.
    		 */
    		cycle_end: number
    		/**
    		 * Scale of the invoice cycle.
    		 */
    		frequency: 'weekly' | 'monthly' | 'biweekly' | 'semimonthly' | 'calendar-month'
    		/**
    		 * Currency code.
    		 */
    		currency_code: string
    		/**
    		 * First payment amount.
    		 */
    		first_payment?: number
    		/**
    		 * Days before to notice the termination of contract for either party.
    		 */
    		notice_period?: number
    		/**
    		 * Cycle end can be weekly 1-7 (Monday = 1) or monthly 1-31.
    		 */
    		cycle_end_type: 'DAY_OF_WEEK' | 'DAY_OF_LAST_WEEK' | 'DAY_OF_MONTH'
    		/**
    		 * Number of days to pay the invoice.
    		 */
    		payment_due_days: number
    		/**
    		 * Type of payment due. If the payment is due on the last day of month, enter 'WITHIN_MONTH'.
    		 */
    		payment_due_type: 'REGULAR' | 'WITHIN_MONTH'
    		/**
    		 * Short date in format ISO-8601 (YYYY-MM-DD). For example: 2022-12-31.
    		 */
    		first_payment_date?: string
    		/**
    		 * If the payment due is on a weekend, pay on Friday.
    		 */
    		pay_before_weekends?: boolean
    		[k: string]: unknown
    	} & {
    		/**
    		 * Defines the scale at which the amount is paid. For example, enter 'hourly' to define the amount per hour. This field can be excluded when creating a Pay-as-you-go task-based or Milestone contracts.
    		 */
    		scale: 'hourly' | 'daily' | 'weekly' | 'monthly' | 'biweekly' | 'semimonthly' | 'custom'
    		/**
    		 * Amount to be paid. This field can be excluded when creating a Pay-as-you-go task-based or Milestone contracts.
    		 */
    		amount: number
    		[k: string]: unknown
    	}
    	[k: string]: unknown
    }
    export type PAYG_TASKS = {
    	/**
    	 * Additional custom info about a contract
    	 */
    	meta: {
    		/**
    		 * Flag to indicate if the contract is the main income for the contractor.
    		 */
    		is_main_income?: boolean
    		/**
    		 * Require the contractor to upload necessary compliance documents as per their country’s labor laws.
    		 */
    		documents_required: boolean
    		[k: string]: unknown
    	}
    	/**
    	 * The title of the contract.
    	 */
    	title: string
    	client: {
    		/**
    		 * Choose the Deel team for this contract. Use teams endpoint to retrieve a list of teams in your organization.
    		 */
    		team: {
    			/**
    			 * Unique identifier of this resource.
    			 */
    			id: string | number
    			[k: string]: unknown
    		}
    		/**
    		 * Choose the Deel legal entity for this contract. Use legal entity endpoint to retrieve a list of legal entities in your organization.
    		 */
    		legal_entity: {
    			/**
    			 * Unique identifier of this resource.
    			 */
    			id: string | number
    			[k: string]: unknown
    		}
    		[k: string]: unknown
    	}
    	/**
    	 * Worker properties
    	 */
    	worker?: {
    		/**
    		 * Worker's last name
    		 */
    		last_name?: string
    		/**
    		 * Worker's first name
    		 */
    		first_name: string
    		/**
    		 * Worker's email address.
    		 */
    		expected_email: string
    		[k: string]: unknown
    	}
    	/**
    	 * Worker's job title. You can enter a custom job title or use a pre-defined job title using the Id retrieved in job-titles endpoint.
    	 */
    	job_title: {
    		/**
    		 * Unique identifier of this resource.
    		 */
    		id?: string | number
    		/**
    		 * Job title. Please leave it blank when entering an Id.
    		 */
    		name?: string
    		[k: string]: unknown
    	}
    	/**
    	 * Job seniority level. Please use the seniority levels endpoint to retrieve the list of seniority levels.
    	 */
    	seniority?: {
    		/**
    		 * Unique identifier of this resource.
    		 */
    		id?: string | number
    		[k: string]: unknown
    	}
    	/**
    	 * The state or province code. Use country lookup endpoint to retrieve state codes.
    	 */
    	state_code?: string
    	/**
    	 * External Id.
    	 */
    	external_id?: string
    	/**
    	 * Flag to indicate who is supposed to provide regular reports
    	 */
    	who_reports?: 'both' | 'client' | 'contractor'
    	/**
    	 * Country code.
    	 */
    	country_code?: string
    	/**
    	 * Days before to notice the termination of contract for either party.
    	 */
    	notice_period?: number
    	/**
    	 * Describe the work to be performed.
    	 */
    	scope_of_work?: string
    	/**
    	 * Enter any special clause you may have.
    	 */
    	special_clause?: string
    	/**
    	 * Short date in format ISO-8601 (YYYY-MM-DD). For example: 2022-12-31.
    	 */
    	termination_date?: string
    	/**
    	 * Contract Template Id.
    	 */
    	contract_template_id?: string
    	[k: string]: unknown
    } & {
    	/**
    	 * Type of contract
    	 */
    	type: 'payg_tasks'
    	/**
    	 * Short date in format ISO-8601 (YYYY-MM-DD). For example: 2022-12-31.
    	 */
    	start_date: string
    	[k: string]: unknown
    } & {
    	compensation_details: {
    		/**
    		 * Amount to be paid. This field can be excluded when creating a Pay-as-you-go task-based or Milestone contracts.
    		 */
    		amount?: number
    		/**
    		 * Date invoice cycle ends.
    		 */
    		cycle_end: number
    		/**
    		 * Scale of the invoice cycle.
    		 */
    		frequency: 'weekly' | 'monthly' | 'biweekly' | 'semimonthly' | 'calendar-month'
    		/**
    		 * Currency code.
    		 */
    		currency_code: string
    		/**
    		 * First payment amount.
    		 */
    		first_payment?: number
    		/**
    		 * Days before to notice the termination of contract for either party.
    		 */
    		notice_period?: number
    		/**
    		 * Cycle end can be weekly 1-7 (Monday = 1) or monthly 1-31.
    		 */
    		cycle_end_type: 'DAY_OF_WEEK' | 'DAY_OF_LAST_WEEK' | 'DAY_OF_MONTH'
    		/**
    		 * Number of days to pay the invoice.
    		 */
    		payment_due_days: number
    		/**
    		 * Type of payment due. If the payment is due on the last day of month, enter 'WITHIN_MONTH'.
    		 */
    		payment_due_type: 'REGULAR' | 'WITHIN_MONTH'
    		/**
    		 * Short date in format ISO-8601 (YYYY-MM-DD). For example: 2022-12-31.
    		 */
    		first_payment_date?: string
    		/**
    		 * If the payment due is on a weekend, pay on Friday.
    		 */
    		pay_before_weekends?: boolean
    		[k: string]: unknown
    	}
    	[k: string]: unknown
    }
    export type PAYG_MILESTONES = {
    	/**
    	 * Additional custom info about a contract
    	 */
    	meta: {
    		/**
    		 * Flag to indicate if the contract is the main income for the contractor.
    		 */
    		is_main_income?: boolean
    		/**
    		 * Require the contractor to upload necessary compliance documents as per their country’s labor laws.
    		 */
    		documents_required: boolean
    		[k: string]: unknown
    	}
    	/**
    	 * The title of the contract.
    	 */
    	title: string
    	client: {
    		/**
    		 * Choose the Deel team for this contract. Use teams endpoint to retrieve a list of teams in your organization.
    		 */
    		team: {
    			/**
    			 * Unique identifier of this resource.
    			 */
    			id: string | number
    			[k: string]: unknown
    		}
    		/**
    		 * Choose the Deel legal entity for this contract. Use legal entity endpoint to retrieve a list of legal entities in your organization.
    		 */
    		legal_entity: {
    			/**
    			 * Unique identifier of this resource.
    			 */
    			id: string | number
    			[k: string]: unknown
    		}
    		[k: string]: unknown
    	}
    	/**
    	 * Worker properties
    	 */
    	worker?: {
    		/**
    		 * Worker's last name
    		 */
    		last_name?: string
    		/**
    		 * Worker's first name
    		 */
    		first_name: string
    		/**
    		 * Worker's email address.
    		 */
    		expected_email: string
    		[k: string]: unknown
    	}
    	/**
    	 * Worker's job title. You can enter a custom job title or use a pre-defined job title using the Id retrieved in job-titles endpoint.
    	 */
    	job_title: {
    		/**
    		 * Unique identifier of this resource.
    		 */
    		id?: string | number
    		/**
    		 * Job title. Please leave it blank when entering an Id.
    		 */
    		name?: string
    		[k: string]: unknown
    	}
    	/**
    	 * Job seniority level. Please use the seniority levels endpoint to retrieve the list of seniority levels.
    	 */
    	seniority?: {
    		/**
    		 * Unique identifier of this resource.
    		 */
    		id?: string | number
    		[k: string]: unknown
    	}
    	/**
    	 * The state or province code. Use country lookup endpoint to retrieve state codes.
    	 */
    	state_code?: string
    	/**
    	 * External Id.
    	 */
    	external_id?: string
    	/**
    	 * Flag to indicate who is supposed to provide regular reports
    	 */
    	who_reports?: 'both' | 'client' | 'contractor'
    	/**
    	 * Country code.
    	 */
    	country_code?: string
    	/**
    	 * Days before to notice the termination of contract for either party.
    	 */
    	notice_period?: number
    	/**
    	 * Describe the work to be performed.
    	 */
    	scope_of_work?: string
    	/**
    	 * Enter any special clause you may have.
    	 */
    	special_clause?: string
    	/**
    	 * Short date in format ISO-8601 (YYYY-MM-DD). For example: 2022-12-31.
    	 */
    	termination_date?: string
    	/**
    	 * Contract Template Id.
    	 */
    	contract_template_id?: string
    	[k: string]: unknown
    } & {
    	/**
    	 * Type of contract
    	 */
    	type: 'payg_milestones'
    	/**
    	 * Short date in format ISO-8601 (YYYY-MM-DD). For example: 2022-12-31.
    	 */
    	start_date?: string
    	[k: string]: unknown
    } & {
    	compensation_details: {
    		/**
    		 * Amount to be paid. This field can be excluded when creating a Pay-as-you-go task-based or Milestone contracts.
    		 */
    		amount?: number
    		/**
    		 * Date invoice cycle ends.
    		 */
    		cycle_end: number
    		/**
    		 * Scale of the invoice cycle.
    		 */
    		frequency: 'weekly' | 'monthly' | 'biweekly' | 'semimonthly' | 'calendar-month'
    		/**
    		 * Currency code.
    		 */
    		currency_code: string
    		/**
    		 * First payment amount.
    		 */
    		first_payment?: number
    		/**
    		 * Days before to notice the termination of contract for either party.
    		 */
    		notice_period?: number
    		/**
    		 * Cycle end can be weekly 1-7 (Monday = 1) or monthly 1-31.
    		 */
    		cycle_end_type: 'DAY_OF_WEEK' | 'DAY_OF_LAST_WEEK' | 'DAY_OF_MONTH'
    		/**
    		 * Number of days to pay the invoice.
    		 */
    		payment_due_days: number
    		/**
    		 * Type of payment due. If the payment is due on the last day of month, enter 'WITHIN_MONTH'.
    		 */
    		payment_due_type: 'REGULAR' | 'WITHIN_MONTH'
    		/**
    		 * Short date in format ISO-8601 (YYYY-MM-DD). For example: 2022-12-31.
    		 */
    		first_payment_date?: string
    		/**
    		 * If the payment due is on a weekend, pay on Friday.
    		 */
    		pay_before_weekends?: boolean
    		[k: string]: unknown
    	}
    	[k: string]: unknown
    }
    export type ONGOING_TIME_BASED = {
    	/**
    	 * Additional custom info about a contract
    	 */
    	meta: {
    		/**
    		 * Flag to indicate if the contract is the main income for the contractor.
    		 */
    		is_main_income?: boolean
    		/**
    		 * Require the contractor to upload necessary compliance documents as per their country’s labor laws.
    		 */
    		documents_required: boolean
    		[k: string]: unknown
    	}
    	/**
    	 * The title of the contract.
    	 */
    	title: string
    	client: {
    		/**
    		 * Choose the Deel team for this contract. Use teams endpoint to retrieve a list of teams in your organization.
    		 */
    		team: {
    			/**
    			 * Unique identifier of this resource.
    			 */
    			id: string | number
    			[k: string]: unknown
    		}
    		/**
    		 * Choose the Deel legal entity for this contract. Use legal entity endpoint to retrieve a list of legal entities in your organization.
    		 */
    		legal_entity: {
    			/**
    			 * Unique identifier of this resource.
    			 */
    			id: string | number
    			[k: string]: unknown
    		}
    		[k: string]: unknown
    	}
    	/**
    	 * Worker properties
    	 */
    	worker?: {
    		/**
    		 * Worker's last name
    		 */
    		last_name?: string
    		/**
    		 * Worker's first name
    		 */
    		first_name: string
    		/**
    		 * Worker's email address.
    		 */
    		expected_email: string
    		[k: string]: unknown
    	}
    	/**
    	 * Worker's job title. You can enter a custom job title or use a pre-defined job title using the Id retrieved in job-titles endpoint.
    	 */
    	job_title: {
    		/**
    		 * Unique identifier of this resource.
    		 */
    		id?: string | number
    		/**
    		 * Job title. Please leave it blank when entering an Id.
    		 */
    		name?: string
    		[k: string]: unknown
    	}
    	/**
    	 * Job seniority level. Please use the seniority levels endpoint to retrieve the list of seniority levels.
    	 */
    	seniority?: {
    		/**
    		 * Unique identifier of this resource.
    		 */
    		id?: string | number
    		[k: string]: unknown
    	}
    	/**
    	 * The state or province code. Use country lookup endpoint to retrieve state codes.
    	 */
    	state_code?: string
    	/**
    	 * External Id.
    	 */
    	external_id?: string
    	/**
    	 * Flag to indicate who is supposed to provide regular reports
    	 */
    	who_reports?: 'both' | 'client' | 'contractor'
    	/**
    	 * Country code.
    	 */
    	country_code?: string
    	/**
    	 * Days before to notice the termination of contract for either party.
    	 */
    	notice_period?: number
    	/**
    	 * Describe the work to be performed.
    	 */
    	scope_of_work?: string
    	/**
    	 * Enter any special clause you may have.
    	 */
    	special_clause?: string
    	/**
    	 * Short date in format ISO-8601 (YYYY-MM-DD). For example: 2022-12-31.
    	 */
    	termination_date?: string
    	/**
    	 * Contract Template Id.
    	 */
    	contract_template_id?: string
    	[k: string]: unknown
    } & {
    	/**
    	 * Type of contract
    	 */
    	type: 'ongoing_time_based'
    	/**
    	 * Short date in format ISO-8601 (YYYY-MM-DD). For example: 2022-12-31.
    	 */
    	start_date: string
    	[k: string]: unknown
    } & {
    	compensation_details: {
    		/**
    		 * Amount to be paid. This field can be excluded when creating a Pay-as-you-go task-based or Milestone contracts.
    		 */
    		amount?: number
    		/**
    		 * Date invoice cycle ends.
    		 */
    		cycle_end: number
    		/**
    		 * Scale of the invoice cycle.
    		 */
    		frequency: 'weekly' | 'monthly' | 'biweekly' | 'semimonthly' | 'calendar-month'
    		/**
    		 * Currency code.
    		 */
    		currency_code: string
    		/**
    		 * First payment amount.
    		 */
    		first_payment?: number
    		/**
    		 * Days before to notice the termination of contract for either party.
    		 */
    		notice_period?: number
    		/**
    		 * Cycle end can be weekly 1-7 (Monday = 1) or monthly 1-31.
    		 */
    		cycle_end_type: 'DAY_OF_WEEK' | 'DAY_OF_LAST_WEEK' | 'DAY_OF_MONTH'
    		/**
    		 * Number of days to pay the invoice.
    		 */
    		payment_due_days: number
    		/**
    		 * Type of payment due. If the payment is due on the last day of month, enter 'WITHIN_MONTH'.
    		 */
    		payment_due_type: 'REGULAR' | 'WITHIN_MONTH'
    		/**
    		 * Short date in format ISO-8601 (YYYY-MM-DD). For example: 2022-12-31.
    		 */
    		first_payment_date?: string
    		/**
    		 * If the payment due is on a weekend, pay on Friday.
    		 */
    		pay_before_weekends?: boolean
    		[k: string]: unknown
    	} & {
    		/**
    		 * Defines the scale at which the amount is paid. For example, enter 'hourly' to define the amount per hour. This field can be excluded when creating a Pay-as-you-go task-based or Milestone contracts.
    		 */
    		scale: 'hourly' | 'daily' | 'weekly' | 'monthly' | 'biweekly' | 'semimonthly' | 'custom'
    		/**
    		 * Amount to be paid. This field can be excluded when creating a Pay-as-you-go task-based or Milestone contracts.
    		 */
    		amount: number
    		[k: string]: unknown
    	}
    	[k: string]: unknown
    }
    
    export interface Body {
    	data: PAY_AS_YOU_GO_TIME_BASED | PAYG_TASKS | PAYG_MILESTONES | ONGOING_TIME_BASED
    	[k: string]: unknown
    }
    

    Submitted by hugo697 235 days ago