export type Oauth2AuthMethodInOut = 'clientSecretJwt' | 'clientSecretBasic' | 'clientSecretPost'; export type Oauth2GrantTypeInOut = 'clientCredentials' | 'refreshToken'; export type OauthJwsSigningAlgorithm = 'RS256'; export type ClientSecretJwtParamsIn = {secretBase64: string, secretId?: (string | null) | undefined, signingAlgorithm: OauthJwsSigningAlgorithm, tokenExpirySecs?: (number | null) | undefined}; export type EndpointOauthConfigIn = {authMethod: Oauth2AuthMethodInOut, clientId: string, clientSecret?: (string | null) | undefined, extraHeaders?: ({[key: string]: string} | null) | undefined, extraParams?: ({[key: string]: string} | null) | undefined, grantType: Oauth2GrantTypeInOut, jwtParams?: ClientSecretJwtParamsIn | undefined, refreshToken?: (string | null) | undefined, scopes?: (Array | null) | undefined, tokenUrl: string}; export type UpdateApiApiV1AppAppIdEndpointEndpointIdOauthArgs = {app_id: string, endpoint_id: string, body: EndpointOauthConfigIn}; export type UpdateApiApiV1AppAppIdEndpointEndpointIdOauthOptions = {baseUrl?: string | undefined, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; /** * Set Endpoint Oauth Config * * PUT /api/v1/app/{app_id}/endpoint/{endpoint_id}/oauth */ export const updateApiApiV1AppAppIdEndpointEndpointIdOauth = async (args: UpdateApiApiV1AppAppIdEndpointEndpointIdOauthArgs, options?: UpdateApiApiV1AppAppIdEndpointEndpointIdOauthOptions) => { const {baseUrl = "https://api.eu.svix.com", fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/app/${encodeURIComponent(String(args.app_id))}/endpoint/${encodeURIComponent(String(args.endpoint_id))}/oauth${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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 undefined };