export type RetentionSelector = {kind?: string | undefined, decoration?: string | undefined, pattern?: string | undefined, extras?: string | undefined}; export type RetentionRule = {id?: number | undefined, priority?: number | undefined, disabled?: boolean | undefined, action?: string | undefined, template?: string | undefined, params?: {[key: string]: Record} | undefined, tag_selectors?: Array | undefined, scope_selectors?: {[key: string]: Array} | undefined}; export type RetentionRuleTrigger = {kind?: string | undefined, settings?: Record | undefined, references?: Record | undefined}; export type RetentionPolicyScope = {level?: string | undefined, ref?: number | undefined}; export type RetentionPolicy = {id?: number | undefined, algorithm?: string | undefined, rules?: Array | undefined, trigger?: RetentionRuleTrigger | undefined, scope?: RetentionPolicyScope | undefined}; export type CreateApiRetentionsArgs = {'X-Request-Id'?: string | undefined, body: RetentionPolicy}; export type CreateApiRetentionsOptions = {baseUrl?: string | undefined, basic?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Create Retention Policy * * POST /retentions */ export const createApiRetentions = async (args: CreateApiRetentionsArgs, options?: CreateApiRetentionsOptions) => { const {baseUrl = "http://localhost/api/v2.0", fetch: fetchFn = fetch, basic} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args['X-Request-Id'] != null) headers.set("X-Request-Id", String(args['X-Request-Id'])) if (basic !== undefined) headers.set('authorization', `Basic ${btoa(`${basic.username}:${basic.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/retentions${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 };