export type ForecastDataIngestionExternalShiftType = {externalShiftTypeId: string, amount: number}; export type ForecastDataIngestionExternalDynamicRule = {forecastExternalVariableId: string, amount: number, weekdays: Array<0 | 1 | 2 | 3 | 4 | 5 | 6>, startTime: string, endTime: string, shiftTypes: Array}; export type CreateApiV2ForecastsDynamicRulesArgs = {externalUnitId: string, externalSectionId?: string | undefined, body: ForecastDataIngestionExternalDynamicRule}; export type CreateApiV2ForecastsDynamicRulesOptions = {baseUrl?: string | undefined, OAuth2ClientCredentials?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create a new dynamic rule * * POST /v2/forecasts/dynamic-rules * * Also accepts auth: OAuth2ClientCredentials */ export const createApiV2ForecastsDynamicRules = async (args: CreateApiV2ForecastsDynamicRulesArgs, options?: CreateApiV2ForecastsDynamicRulesOptions) => { 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/dynamic-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() };