@nhost/nhost-js
Version:
Nhost JavaScript SDK
1,657 lines • 60.3 kB
JavaScript
/**
* This file is auto-generated. Do not edit manually.
*/
import { createEnhancedFetch, FetchError } from '../fetch';
export const createAPIClient = (baseURL, chainFunctions = []) => {
let fetch = createEnhancedFetch(chainFunctions);
const pushChainFunction = (chainFunction) => {
chainFunctions.push(chainFunction);
fetch = createEnhancedFetch(chainFunctions);
};
const getJWKs = async (options) => {
const url = `${baseURL}/.well-known/jwks.json`;
const res = await fetch(url, {
...options,
method: 'GET',
headers: {
...options?.headers,
},
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const elevateWebauthn = async (options) => {
const url = `${baseURL}/elevate/webauthn`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
...options?.headers,
},
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody
? JSON.parse(responseBody)
: {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const verifyElevateWebauthn = async (body, options) => {
const url = `${baseURL}/elevate/webauthn/verify`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
body: JSON.stringify(body),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody
? JSON.parse(responseBody)
: {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const healthCheckGet = async (options) => {
const url = `${baseURL}/healthz`;
const res = await fetch(url, {
...options,
method: 'GET',
headers: {
...options?.headers,
},
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const healthCheckHead = async (options) => {
const url = `${baseURL}/healthz`;
const res = await fetch(url, {
...options,
method: 'HEAD',
headers: {
...options?.headers,
},
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const payload = undefined;
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const linkIdToken = async (body, options) => {
const url = `${baseURL}/link/idtoken`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
body: JSON.stringify(body),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const changeUserMfa = async (options) => {
const url = `${baseURL}/mfa/totp/generate`;
const res = await fetch(url, {
...options,
method: 'GET',
headers: {
...options?.headers,
},
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody
? JSON.parse(responseBody)
: {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const createPAT = async (body, options) => {
const url = `${baseURL}/pat`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
body: JSON.stringify(body),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody
? JSON.parse(responseBody)
: {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const signInAnonymous = async (body, options) => {
const url = `${baseURL}/signin/anonymous`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
body: JSON.stringify(body),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody
? JSON.parse(responseBody)
: {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const signInEmailPassword = async (body, options) => {
const url = `${baseURL}/signin/email-password`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
body: JSON.stringify(body),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody
? JSON.parse(responseBody)
: {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const signInIdToken = async (body, options) => {
const url = `${baseURL}/signin/idtoken`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
body: JSON.stringify(body),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody
? JSON.parse(responseBody)
: {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const verifySignInMfaTotp = async (body, options) => {
const url = `${baseURL}/signin/mfa/totp`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
body: JSON.stringify(body),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody
? JSON.parse(responseBody)
: {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const signInOTPEmail = async (body, options) => {
const url = `${baseURL}/signin/otp/email`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
body: JSON.stringify(body),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const verifySignInOTPEmail = async (body, options) => {
const url = `${baseURL}/signin/otp/email/verify`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
body: JSON.stringify(body),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody
? JSON.parse(responseBody)
: {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const signInPasswordlessEmail = async (body, options) => {
const url = `${baseURL}/signin/passwordless/email`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
body: JSON.stringify(body),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const signInPasswordlessSms = async (body, options) => {
const url = `${baseURL}/signin/passwordless/sms`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
body: JSON.stringify(body),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const verifySignInPasswordlessSms = async (body, options) => {
const url = `${baseURL}/signin/passwordless/sms/otp`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
body: JSON.stringify(body),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody
? JSON.parse(responseBody)
: {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const signInPAT = async (body, options) => {
const url = `${baseURL}/signin/pat`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
body: JSON.stringify(body),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody
? JSON.parse(responseBody)
: {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const signInProviderURL = (provider, params) => {
const encodedParameters = params &&
Object.entries(params)
.flatMap(([key, value]) => {
if (key === 'providerSpecificParams') {
// Object with explode: true - each property as separate parameter
if (typeof value === 'object' &&
value !== null &&
!Array.isArray(value)) {
return Object.entries(value).map(([k, v]) => `${k}=${encodeURIComponent(String(v))}`);
}
return [`${key}=${encodeURIComponent(String(value))}`];
}
if (key === 'upstreamParams') {
// deepObject with explode: true - upstreamParams[prop]=value
if (typeof value === 'object' &&
value !== null &&
!Array.isArray(value)) {
return Object.entries(value).map(([k, v]) => `upstreamParams[${encodeURIComponent(k)}]=${encodeURIComponent(String(v))}`);
}
return [];
}
// Default handling (scalars or explode: false)
const stringValue = Array.isArray(value)
? value.join(',')
: typeof value === 'object' && value !== null
? JSON.stringify(value)
: String(value);
return [`${key}=${encodeURIComponent(stringValue)}`];
})
.join('&');
const url = encodedParameters
? `${baseURL}/signin/provider/${provider}?${encodedParameters}`
: `${baseURL}/signin/provider/${provider}`;
return url;
};
const getProviderTokens = async (provider, options) => {
const url = `${baseURL}/signin/provider/${provider}/callback/tokens`;
const res = await fetch(url, {
...options,
method: 'GET',
headers: {
...options?.headers,
},
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody
? JSON.parse(responseBody)
: {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const signInWebauthn = async (body, options) => {
const url = `${baseURL}/signin/webauthn`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
body: JSON.stringify(body),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody
? JSON.parse(responseBody)
: {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const verifySignInWebauthn = async (body, options) => {
const url = `${baseURL}/signin/webauthn/verify`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
body: JSON.stringify(body),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody
? JSON.parse(responseBody)
: {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const signOut = async (body, options) => {
const url = `${baseURL}/signout`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
body: JSON.stringify(body),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const signUpEmailPassword = async (body, options) => {
const url = `${baseURL}/signup/email-password`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
body: JSON.stringify(body),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody
? JSON.parse(responseBody)
: {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const signUpWebauthn = async (body, options) => {
const url = `${baseURL}/signup/webauthn`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
body: JSON.stringify(body),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody
? JSON.parse(responseBody)
: {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const verifySignUpWebauthn = async (body, options) => {
const url = `${baseURL}/signup/webauthn/verify`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
body: JSON.stringify(body),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody
? JSON.parse(responseBody)
: {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const signUpPasswordlessEmail = async (body, options) => {
const url = `${baseURL}/signup/passwordless/email`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
body: JSON.stringify(body),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const signUpOTPEmail = async (body, options) => {
const url = `${baseURL}/signup/otp/email`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
body: JSON.stringify(body),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const signUpPasswordlessSms = async (body, options) => {
const url = `${baseURL}/signup/passwordless/sms`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
body: JSON.stringify(body),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const signUpIdToken = async (body, options) => {
const url = `${baseURL}/signup/idtoken`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
body: JSON.stringify(body),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody
? JSON.parse(responseBody)
: {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const signUpProviderURL = (provider, params) => {
const encodedParameters = params &&
Object.entries(params)
.flatMap(([key, value]) => {
if (key === 'providerSpecificParams') {
// Object with explode: true - each property as separate parameter
if (typeof value === 'object' &&
value !== null &&
!Array.isArray(value)) {
return Object.entries(value).map(([k, v]) => `${k}=${encodeURIComponent(String(v))}`);
}
return [`${key}=${encodeURIComponent(String(value))}`];
}
if (key === 'upstreamParams') {
// deepObject with explode: true - upstreamParams[prop]=value
if (typeof value === 'object' &&
value !== null &&
!Array.isArray(value)) {
return Object.entries(value).map(([k, v]) => `upstreamParams[${encodeURIComponent(k)}]=${encodeURIComponent(String(v))}`);
}
return [];
}
// Default handling (scalars or explode: false)
const stringValue = Array.isArray(value)
? value.join(',')
: typeof value === 'object' && value !== null
? JSON.stringify(value)
: String(value);
return [`${key}=${encodeURIComponent(stringValue)}`];
})
.join('&');
const url = encodedParameters
? `${baseURL}/signup/provider/${provider}?${encodedParameters}`
: `${baseURL}/signup/provider/${provider}`;
return url;
};
const refreshToken = async (body, options) => {
const url = `${baseURL}/token`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
body: JSON.stringify(body),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const refreshProviderToken = async (provider, body, options) => {
const url = `${baseURL}/token/provider/${provider}`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
body: JSON.stringify(body),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody
? JSON.parse(responseBody)
: {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const verifyToken = async (body, options) => {
const url = `${baseURL}/token/verify`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
body: JSON.stringify(body),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const getUser = async (options) => {
const url = `${baseURL}/user`;
const res = await fetch(url, {
...options,
method: 'GET',
headers: {
...options?.headers,
},
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const deanonymizeUser = async (body, options) => {
const url = `${baseURL}/user/deanonymize`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
body: JSON.stringify(body),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const changeUserEmail = async (body, options) => {
const url = `${baseURL}/user/email/change`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
body: JSON.stringify(body),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const sendVerificationEmail = async (body, options) => {
const url = `${baseURL}/user/email/send-verification-email`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
body: JSON.stringify(body),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const verifyChangeUserMfa = async (body, options) => {
const url = `${baseURL}/user/mfa`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
body: JSON.stringify(body),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const changeUserPassword = async (body, options) => {
const url = `${baseURL}/user/password`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
body: JSON.stringify(body),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const sendPasswordResetEmail = async (body, options) => {
const url = `${baseURL}/user/password/reset`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
body: JSON.stringify(body),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const addSecurityKey = async (options) => {
const url = `${baseURL}/user/webauthn/add`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
...options?.headers,
},
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody
? JSON.parse(responseBody)
: {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const verifyAddSecurityKey = async (body, options) => {
const url = `${baseURL}/user/webauthn/verify`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
body: JSON.stringify(body),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody
? JSON.parse(responseBody)
: {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const tokenExchange = async (body, options) => {
const url = `${baseURL}/token/exchange`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
body: JSON.stringify(body),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody
? JSON.parse(responseBody)
: {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const verifyTicketURL = (params) => {
const encodedParameters = params &&
Object.entries(params)
.flatMap(([key, value]) => {
// Default handling (scalars or explode: false)
const stringValue = Array.isArray(value)
? value.join(',')
: typeof value === 'object' && value !== null
? JSON.stringify(value)
: String(value);
return [`${key}=${encodeURIComponent(stringValue)}`];
})
.join('&');
const url = encodedParameters
? `${baseURL}/verify?${encodedParameters}`
: `${baseURL}/verify`;
return url;
};
const getVersion = async (options) => {
const url = `${baseURL}/version`;
const res = await fetch(url, {
...options,
method: 'GET',
headers: {
...options?.headers,
},
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody
? JSON.parse(responseBody)
: {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const getOpenIDConfiguration = async (options) => {
const url = `${baseURL}/.well-known/openid-configuration`;
const res = await fetch(url, {
...options,
method: 'GET',
headers: {
...options?.headers,
},
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody
? JSON.parse(responseBody)
: {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const getOAuthAuthorizationServer = async (options) => {
const url = `${baseURL}/.well-known/oauth-authorization-server`;
const res = await fetch(url, {
...options,
method: 'GET',
headers: {
...options?.headers,
},
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody
? JSON.parse(responseBody)
: {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const oauth2AuthorizeURL = (params) => {
const encodedParameters = params &&
Object.entries(params)
.flatMap(([key, value]) => {
// Default handling (scalars or explode: false)
const stringValue = Array.isArray(value)
? value.join(',')
: typeof value === 'object' && value !== null
? JSON.stringify(value)
: String(value);
return [`${key}=${encodeURIComponent(stringValue)}`];
})
.join('&');
const url = encodedParameters
? `${baseURL}/oauth2/authorize?${encodedParameters}`
: `${baseURL}/oauth2/authorize`;
return url;
};
const oauth2AuthorizePostURL = () => {
const url = `${baseURL}/oauth2/authorize`;
return url;
};
const oauth2Token = async (body, options) => {
const url = `${baseURL}/oauth2/token`;
const params = new URLSearchParams();
if (body['grant_type'] !== undefined) {
params.append('grant_type', String(body['grant_type']));
}
if (body['code'] !== undefined) {
params.append('code', String(body['code']));
}
if (body['redirect_uri'] !== undefined) {
params.append('redirect_uri', String(body['redirect_uri']));
}
if (body['client_id'] !== undefined) {
params.append('client_id', String(body['client_id']));
}
if (body['client_secret'] !== undefined) {
params.append('client_secret', String(body['client_secret']));
}
if (body['code_verifier'] !== undefined) {
params.append('code_verifier', String(body['code_verifier']));
}
if (body['refresh_token'] !== undefined) {
params.append('refresh_token', String(body['refresh_token']));
}
if (body['resource'] !== undefined) {
params.append('resource', String(body['resource']));
}
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
...options?.headers,
},
body: params.toString(),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody
? JSON.parse(responseBody)
: {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const oauth2UserinfoGet = async (options) => {
const url = `${baseURL}/oauth2/userinfo`;
const res = await fetch(url, {
...options,
method: 'GET',
headers: {
...options?.headers,
},
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody
? JSON.parse(responseBody)
: {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const oauth2UserinfoPost = async (options) => {
const url = `${baseURL}/oauth2/userinfo`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
...options?.headers,
},
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody
? JSON.parse(responseBody)
: {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const oauth2Jwks = async (options) => {
const url = `${baseURL}/oauth2/jwks`;
const res = await fetch(url, {
...options,
method: 'GET',
headers: {
...options?.headers,
},
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody
? JSON.parse(responseBody)
: {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const oauth2Revoke = async (body, options) => {
const url = `${baseURL}/oauth2/revoke`;
const params = new URLSearchParams();
if (body['token'] !== undefined) {
params.append('token', String(body['token']));
}
if (body['token_type_hint'] !== undefined) {
params.append('token_type_hint', String(body['token_type_hint']));
}
if (body['client_id'] !== undefined) {
params.append('client_id', String(body['client_id']));
}
if (body['client_secret'] !== undefined) {
params.append('client_secret', String(body['client_secret']));
}
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
...options?.headers,
},
body: params.toString(),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const payload = undefined;
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const oauth2Introspect = async (body, options) => {
const url = `${baseURL}/oauth2/introspect`;
const params = new URLSearchParams();
if (body['token'] !== undefined) {
params.append('token', String(body['token']));
}
if (body['token_type_hint'] !== undefined) {
params.append('token_type_hint', String(body['token_type_hint']));
}
if (body['client_id'] !== undefined) {
params.append('client_id', String(body['client_id']));
}
if (body['client_secret'] !== undefined) {
params.append('client_secret', String(body['client_secret']));
}
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
...options?.headers,
},
body: params.toString(),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody
? JSON.parse(responseBody)
: {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const oauth2LoginGet = async (params, options) => {
const encodedParameters = params &&
Object.entries(params)
.flatMap(([key, value]) => {
// Default handling (scalars or explode: false)
const stringValue = Array.isArray(value)
? value.join(',')
: typeof value === 'object' && value !== null
? JSON.stringify(value)
: String(value);
return [`${key}=${encodeURIComponent(stringValue)}`];
})
.join('&');
const url = encodedParameters
? `${baseURL}/oauth2/login?${encodedParameters}`
: `${baseURL}/oauth2/login`;
const res = await fetch(url, {
...options,
method: 'GET',
headers: {
...options?.headers,
},
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody
? JSON.parse(responseBody)
: {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
const oauth2LoginPost = async (body, options) => {
const url = `${baseURL}/oauth2/login`;
const res = await fetch(url, {
...options,
method: 'POST',
headers: {
'Content-Type': 'application/json',
...options?.headers,
},
body: JSON.stringify(body),
});
if (res.status >= 300) {
const responseBody = [412].includes(res.status) ? null : await res.text();
const payload = responseBody ? JSON.parse(responseBody) : {};
throw new FetchError(payload, res.status, res.headers);
}
const responseBody = [204, 205, 304].includes(res.status)
? null
: await res.text();
const payload = responseBody
? JSON.parse(responseBody)
: {};
return {
body: payload,
status: res.status,
headers: res.headers,
};
};
return {
baseURL,
pushChainFunction,
getJWKs,
elevateWebauthn,
verifyElevateWebauthn,
healthCheckGet,
healthCheckHead,
linkIdToken,
changeUserMfa,
createPAT,
signInAnonymous,
signInEmailPassword,
signInIdToken,
verifySignInMfaTotp,
signInOTPEmail,
verifySignInOTPEmail,
signInPasswordlessEmail,
signInPasswordlessSms,
verifySignInPasswordlessSms,
signInPAT,
signInProviderURL,
getProviderTokens,
signInWebauthn,
verifySignInWebauthn,
signOut,
signUpEmailPassword,
signUpWebauthn,
verifySignUpWebauthn,
signUpPasswordlessEmail,
signUpOTPEmail,
signUpPasswordlessSms,
signUpIdToken,
signUpProviderURL,
refreshToken,
refreshProviderToken,
verifyToken,
getUser,
deanonymizeUser,
changeUserEmail,
sendVerificationEmail,
verifyChangeUserMfa,
changeUserPassword,
sendPasswordResetEmail,
addSecurityKey,
verifyAddSecurityKey,
tokenExchange,
verifyTicketURL,
getVersion,
getOpenIDConfiguration,
getOAuthAuthorizationServer,
oauth2AuthorizeURL,
oauth2AuthorizePostURL,
oauth2Token,
oauth2UserinfoGet,
oauth2UserinfoPost,
oauth2Jwks,
oauth2Revoke,
oauth2Introspect,
oauth2LoginGet,
oauth2LoginPost,
};
};
//# sourceMappingURL=client.js.map