export type OptimisationActionName = 'reenable' | 'disable'; export type CreateRuleRequest = {optimisationActionName: OptimisationActionName, ruleName: string, reportFilterId: unknown, startUtcDate?: string | undefined, endUtcDate?: string | undefined}; export type CreateApiV2UserAnalyticsStoreIdRulesArgs = {storeId: unknown, body: CreateRuleRequest}; export type CreateApiV2UserAnalyticsStoreIdRulesOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Rule creation * * POST /v2/user/analytics/{storeId}/rules */ export const createApiV2UserAnalyticsStoreIdRules = async (args: CreateApiV2UserAnalyticsStoreIdRulesArgs, options?: CreateApiV2UserAnalyticsStoreIdRulesOptions) => { const {baseUrl = "https://api.beezup.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v2/user/analytics/${encodeURIComponent(String(args.storeId))}/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 undefined };