export type ApplyPolicyTriggerInventory = {classes?: Array | undefined}; export type CreateApiNodesNodeIdApplyPolicyArgs = {nodeId: unknown, body: ApplyPolicyTriggerInventory}; export type CreateApiNodesNodeIdApplyPolicyOptions = {baseUrl?: string | undefined, APITokens?: string | undefined, fetch?: typeof fetch | undefined}; /** * Trigger an agent run * * POST /nodes/{nodeId}/applyPolicy */ export const createApiNodesNodeIdApplyPolicy = async (args: CreateApiNodesNodeIdApplyPolicyArgs, options?: CreateApiNodesNodeIdApplyPolicyOptions) => { const {baseUrl = "https://rudder.example.com/rudder/api/latest", fetch: fetchFn = fetch, APITokens} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "text/plain") if (APITokens !== undefined) headers.set("X-API-Token", APITokens) const url = `${baseUrl.replace(/\/+$/, '')}/nodes/${encodeURIComponent(String(args.nodeId))}/applyPolicy${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.text() };