diff --git a/src/components/CreateCredentialModal.svelte b/src/components/CreateCredentialModal.svelte new file mode 100644 index 0000000..e8966ac --- /dev/null +++ b/src/components/CreateCredentialModal.svelte @@ -0,0 +1,397 @@ + + +{#if isOpen} + +{/if} + + diff --git a/src/lib/credentials.ts b/src/lib/credentials.ts new file mode 100644 index 0000000..f43571d --- /dev/null +++ b/src/lib/credentials.ts @@ -0,0 +1,99 @@ +import api from "./axios"; + +export interface CredentialField { + id: string; + fieldId: string; + value: string; +} + +export interface Credential { + id: string; + name: string; + typeId: string; + companyId: string; + fields: CredentialField[]; + type?: { + id: string; + name: string; + fields: unknown[]; + permissionScope: string; + }; + company?: { + id: string; + name: string; + }; + createdAt: string; + updatedAt: string; +} + +export const credential = { + async fetchByCompany(accessToken: string, companyId: string) { + const response = await api.get( + `/v1/credential/credentials/company/${companyId}`, + { + headers: { + Authorization: `Bearer ${accessToken}`, + }, + }, + ); + return response.data; + }, + + async fetch(accessToken: string, id: string) { + const response = await api.get(`/v1/credential/credentials/${id}`, { + headers: { + Authorization: `Bearer ${accessToken}`, + }, + }); + return response.data; + }, + + async create( + accessToken: string, + data: Omit, + ) { + console.log(data); + + const response = await api.post("/v1/credential/credentials", data, { + headers: { + Authorization: `Bearer ${accessToken}`, + }, + }); + return response.data; + }, + + async update(accessToken: string, id: string, data: { name: string }) { + const response = await api.patch(`/v1/credential/credentials/${id}`, data, { + headers: { + Authorization: `Bearer ${accessToken}`, + }, + }); + return response.data; + }, + + async updateFields( + accessToken: string, + id: string, + fields: CredentialField[], + ) { + const response = await api.put( + `/v1/credential/credentials/${id}/fields`, + { fields }, + { + headers: { + Authorization: `Bearer ${accessToken}`, + }, + }, + ); + return response.data; + }, + + async delete(accessToken: string, id: string) { + const response = await api.delete(`/v1/credential/credentials/${id}`, { + headers: { + Authorization: `Bearer ${accessToken}`, + }, + }); + return response.data; + }, +}; diff --git a/src/routes/companies/[id]/+page.server.ts b/src/routes/companies/[id]/+page.server.ts index 0f63ed9..01e23c6 100644 --- a/src/routes/companies/[id]/+page.server.ts +++ b/src/routes/companies/[id]/+page.server.ts @@ -1,4 +1,5 @@ import { company } from "$lib/companies"; +import { credential } from "$lib/credentials"; import type { PageServerLoad } from "./$types"; import { error } from "@sveltejs/kit"; @@ -31,10 +32,29 @@ export const load: PageServerLoad = async ({ params, parent }) => { ); } + // attempt to load credentials but don't fail the whole page if it errors + let credentials = null; + let credentialsError = null; + try { + credentials = await credential.fetchByCompany( + session.accessToken, + params.id, + ); + } catch (credErr) { + console.error("Failed to fetch credentials:", credErr); + credentialsError = String( + credErr instanceof Error ? credErr.message : credErr, + ); + } + return { company: companyData, configurations, configurationsError, + credentials, + credentialsError, + session, + companyId: params.id, }; } catch (err) { console.error("Failed to fetch company:", err); diff --git a/src/routes/companies/[id]/+page.svelte b/src/routes/companies/[id]/+page.svelte index d8943fc..5444962 100644 --- a/src/routes/companies/[id]/+page.svelte +++ b/src/routes/companies/[id]/+page.svelte @@ -1,13 +1,25 @@ @@ -56,9 +68,40 @@

No configurations available for this company.

{/if} +
+
+

Credentials

+ +
+ {#if data.credentialsError} + + {:else if data.credentials && data.credentials.data && data.credentials.data.length > 0} +
+ Show credentials JSON +
{JSON.stringify(data.credentials, null, 2)}
+
+ {:else} +

No credentials available for this company.

+ {/if} +
{/if} + +