export type CreateApiJwtEncodeArgs = {body: {headers?: ({alg: string, typ?: string | undefined, kid?: string | undefined}) | undefined, claims?: ({iat?: boolean | undefined, nbf?: boolean | undefined, exp?: boolean | undefined, aud?: string | undefined, sub?: string | undefined, iss?: string | undefined, jti?: string | undefined}) | undefined, key?: string | undefined, output?: string | undefined, override_alg?: string | undefined}}; export type CreateApiJwtEncodeOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * JWT Encode * * POST /jwt/encode */ export const createApiJwtEncode = async (args: CreateApiJwtEncodeArgs, options?: CreateApiJwtEncodeOptions) => { const {baseUrl = "https://client.apimetrics.io/api/2", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("Authorization", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/jwt/encode${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return (await res.json()) as unknown };