Skip to content

Commit

Permalink
⏪ app: roll back api response handling
Browse files Browse the repository at this point in the history
  • Loading branch information
dieguezguille authored and cruzdanilo committed Dec 27, 2024
1 parent 6e294ff commit 6f8f79d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 28 deletions.
5 changes: 5 additions & 0 deletions .changeset/soft-ads-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@exactly/mobile": patch
---

⏪ roll back api response handling
45 changes: 17 additions & 28 deletions src/utils/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ export async function registrationOptions() {

export async function verifyRegistration(attestation: RegistrationResponseJSON) {
const response = await client.api.auth.registration.$post({ json: attestation });
if (!response.ok) {
const raw = response.clone();
throw new APIError(response.status, await response.json().catch(() => raw.text()));
}
if (!response.ok) throw new APIError(response.status, await response.json());
const { auth: expires, ...passkey } = await response.json();
await queryClient.setQueryData(["auth"], parse(Auth, expires));
return parse(Passkey, passkey);
Expand All @@ -67,67 +64,59 @@ export async function verifyRegistration(attestation: RegistrationResponseJSON)
export async function getCard() {
await auth();
const response = await client.api.card.$get();
const text = await response.text();
if (!response.ok) throw new APIError(response.status, text);
return JSON.parse(text) as Awaited<ReturnType<typeof response.json>>;
if (!response.ok) throw new APIError(response.status, await response.json());
return response.json();
}

export async function createCard() {
await auth();
const response = await client.api.card.$post();
const text = await response.text();
if (!response.ok) throw new APIError(response.status, text);
return JSON.parse(text) as Awaited<ReturnType<typeof response.json>>;
if (!response.ok) throw new APIError(response.status, await response.json());
return response.json();
}

export async function setCardStatus(status: "ACTIVE" | "FROZEN") {
await auth();
const response = await client.api.card.$patch({ json: { status } });
const text = await response.text();
if (!response.ok) throw new APIError(response.status, text);
return JSON.parse(text) as Awaited<ReturnType<typeof response.json>>;
if (!response.ok) throw new APIError(response.status, await response.json());
return response.json();
}

export async function setCardMode(mode: number) {
await auth();
const response = await client.api.card.$patch({ json: { mode } });
const text = await response.text();
if (!response.ok) throw new APIError(response.status, text);
return JSON.parse(text) as Awaited<ReturnType<typeof response.json>>;
if (!response.ok) throw new APIError(response.status, await response.json());
return response.json();
}

export async function getKYCLink() {
await auth();
const response = await client.api.kyc.$post();
const text = await response.text();
if (!response.ok) throw new APIError(response.status, text);
return JSON.parse(text) as Awaited<ReturnType<typeof response.json>>;
if (!response.ok) throw new APIError(response.status, await response.json());
return response.json();
}

export async function getKYCStatus() {
await auth();
const response = await client.api.kyc.$get();
const text = await response.text();
if (!response.ok) throw new APIError(response.status, text);
return JSON.parse(text) as Awaited<ReturnType<typeof response.json>>;
if (!response.ok) throw new APIError(response.status, await response.json());
return response.json();
}

export async function getPasskey() {
await auth();
const response = await client.api.passkey.$get();
const text = await response.text();
if (!response.ok) throw new APIError(response.status, text);
return JSON.parse(text) as Awaited<ReturnType<typeof response.json>>;
if (!response.ok) throw new APIError(response.status, await response.json());
return response.json();
}

export async function getActivity(parameters?: NonNullable<Parameters<typeof client.api.activity.$get>[0]>["query"]) {
await auth();
const response = await client.api.activity.$get(
parameters?.include === undefined ? undefined : { query: { include: parameters.include } },
);
const text = await response.text();
if (!response.ok) throw new APIError(response.status, text);
return JSON.parse(text) as Awaited<ReturnType<typeof response.json>>;
if (!response.ok) throw new APIError(response.status, await response.json());
return response.json();
}

export async function auth() {
Expand Down

0 comments on commit 6f8f79d

Please sign in to comment.