import { resolve } from '$app/paths'; import type { StackCR } from '$lib/types/custom-resources/stack'; import type { Stack } from '$lib/types/entities'; import { handleResponse } from './types'; const list = (workspaceId: string, fetch = globalThis.fetch): Promise => fetch( resolve('/api/workspaces/[workspaceId]/[resource=resource]', { workspaceId, resource: 'stacks', }), ).then(handleResponse); const get = (workspaceId: string, id: string, fetch = globalThis.fetch): Promise => fetch( resolve('/api/workspaces/[workspaceId]/[resource=resource]/[id]', { workspaceId, resource: 'stacks', id, }), ).then(handleResponse); const getStatus = ( workspaceId: string, id: string, fetch = globalThis.fetch, ): Promise => fetch( resolve('/api/workspaces/[workspaceId]/[resource=resource]/[id]/status', { workspaceId, resource: 'stacks', id, }), ).then(handleResponse); const create = (workspaceId: string, stack: Stack, fetch = globalThis.fetch): Promise => fetch( resolve('/api/workspaces/[workspaceId]/[resource=resource]', { workspaceId, resource: 'stacks', }), { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(stack), }, ).then(handleResponse); const update = (workspaceId: string, stack: Stack, fetch = globalThis.fetch): Promise => fetch( resolve('/api/workspaces/[workspaceId]/[resource=resource]/[id]', { workspaceId, resource: 'stacks', id: stack.id, }), { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(stack), }, ).then(handleResponse); const remove = (workspaceId: string, id: string, fetch = globalThis.fetch): Promise => fetch( resolve('/api/workspaces/[workspaceId]/[resource=resource]/[id]', { workspaceId, resource: 'stacks', id, }), { method: 'DELETE', }, ).then(async (res) => { if (!res.ok) await handleResponse(res); }); export { create, get, getStatus, list, remove, update };