export type ForecastDataIngestionExternalShiftType = {externalShiftTypeId: string, amount: number}; export type ForecastDataIngestionExternalStaticRule = {weekdays: Array<0 | 1 | 2 | 3 | 4 | 5 | 6>, repeatPeriod: number, shiftType: ForecastDataIngestionExternalShiftType, startTime: string, endTime: string, startDate: string, endDate?: string | undefined, comment?: string | undefined}; export type CreateApiV2ForecastsStaticRulesArgs = {externalUnitId: string, externalSectionId?: string | undefined, body: ForecastDataIngestionExternalStaticRule}; export type CreateApiV2ForecastsStaticRulesOptions = {baseUrl?: string | undefined, OAuth2ClientCredentials?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create a new static rule * * POST /v2/forecasts/static-rules * * Also accepts auth: OAuth2ClientCredentials */ export const createApiV2ForecastsStaticRules = async (args: CreateApiV2ForecastsStaticRulesArgs, options?: CreateApiV2ForecastsStaticRulesOptions) => { const {baseUrl = "https://api.quinyx.com", fetch: fetchFn = fetch, OAuth2ClientCredentials} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "*/*") if (args.externalUnitId != null) query.append("externalUnitId", String(args.externalUnitId)) if (args.externalSectionId != null) query.append("externalSectionId", String(args.externalSectionId)) if (OAuth2ClientCredentials !== undefined) headers.set('authorization', `Bearer ${OAuth2ClientCredentials}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/forecasts/static-rules${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.blob() };