|
@@ -0,0 +1,65 @@
|
|
|
|
|
+import { resolve } from '$app/paths';
|
|
|
|
|
+
|
|
|
|
|
+import type { Secret } from '$lib/types/entities';
|
|
|
|
|
+
|
|
|
|
|
+import { handleResponse } from './types';
|
|
|
|
|
+
|
|
|
|
|
+const list = (workspaceId: string, fetch = globalThis.fetch): Promise<Secret[]> =>
|
|
|
|
|
+ fetch(
|
|
|
|
|
+ resolve('/api/workspaces/[workspaceId]/[resource=resource]', {
|
|
|
|
|
+ workspaceId,
|
|
|
|
|
+ resource: 'secrets',
|
|
|
|
|
+ }),
|
|
|
|
|
+ ).then(handleResponse<Secret[]>);
|
|
|
|
|
+
|
|
|
|
|
+const get = (workspaceId: string, id: string, fetch = globalThis.fetch): Promise<Secret> =>
|
|
|
|
|
+ fetch(
|
|
|
|
|
+ resolve('/api/workspaces/[workspaceId]/[resource=resource]/[id]', {
|
|
|
|
|
+ workspaceId,
|
|
|
|
|
+ resource: 'secrets',
|
|
|
|
|
+ id,
|
|
|
|
|
+ }),
|
|
|
|
|
+ ).then(handleResponse<Secret>);
|
|
|
|
|
+
|
|
|
|
|
+const create = (workspaceId: string, secret: Secret, fetch = globalThis.fetch): Promise<Secret> =>
|
|
|
|
|
+ fetch(
|
|
|
|
|
+ resolve('/api/workspaces/[workspaceId]/[resource=resource]', {
|
|
|
|
|
+ workspaceId,
|
|
|
|
|
+ resource: 'secrets',
|
|
|
|
|
+ }),
|
|
|
|
|
+ {
|
|
|
|
|
+ method: 'POST',
|
|
|
|
|
+ headers: { 'Content-Type': 'application/json' },
|
|
|
|
|
+ body: JSON.stringify(secret),
|
|
|
|
|
+ },
|
|
|
|
|
+ ).then(handleResponse<Secret>);
|
|
|
|
|
+
|
|
|
|
|
+const update = (workspaceId: string, secret: Secret, fetch = globalThis.fetch): Promise<Secret> =>
|
|
|
|
|
+ fetch(
|
|
|
|
|
+ resolve('/api/workspaces/[workspaceId]/[resource=resource]/[id]', {
|
|
|
|
|
+ workspaceId,
|
|
|
|
|
+ resource: 'secrets',
|
|
|
|
|
+ id: secret.id,
|
|
|
|
|
+ }),
|
|
|
|
|
+ {
|
|
|
|
|
+ method: 'PUT',
|
|
|
|
|
+ headers: { 'Content-Type': 'application/json' },
|
|
|
|
|
+ body: JSON.stringify(secret),
|
|
|
|
|
+ },
|
|
|
|
|
+ ).then(handleResponse<Secret>);
|
|
|
|
|
+
|
|
|
|
|
+const remove = (workspaceId: string, id: string, fetch = globalThis.fetch): Promise<void> =>
|
|
|
|
|
+ fetch(
|
|
|
|
|
+ resolve('/api/workspaces/[workspaceId]/[resource=resource]/[id]', {
|
|
|
|
|
+ workspaceId,
|
|
|
|
|
+ resource: 'secrets',
|
|
|
|
|
+ id,
|
|
|
|
|
+ }),
|
|
|
|
|
+ {
|
|
|
|
|
+ method: 'DELETE',
|
|
|
|
|
+ },
|
|
|
|
|
+ ).then(async (res) => {
|
|
|
|
|
+ if (!res.ok) await handleResponse<void>(res);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+export { create, get, list, remove, update };
|