New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@opensdks/runtime

Package Overview
Dependencies
Maintainers
0
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@opensdks/runtime - npm Package Compare versions

Comparing version 0.0.20 to 0.0.21

types/package.json

104

cjs/createClient.js
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createFormUrlEncodedBodySerializer = exports.formDataBodySerializer = exports.throwIfNotOk = exports.createClient = exports.defaultLinks = void 0;
const openapi_fetch_1 = __importDefault(require("openapi-fetch"));
exports.throwIfNotOk = exports.createFormUrlEncodedBodySerializer = exports.formDataBodySerializer = exports.createClient = void 0;
const openapi_fetch_1 = __importStar(require("openapi-fetch"));
const fetch_links_1 = require("@opensdks/fetch-links");

@@ -15,34 +35,47 @@ const HTTPError_js_1 = require("./HTTPError.js");

// Really do feel that they should be generated as well..
exports.defaultLinks = [(0, fetch_links_1.fetchLink)()];
function createClient({ links: _links = exports.defaultLinks, ...clientOptions } = {}) {
const links = typeof _links === 'function' ? _links(exports.defaultLinks) : _links;
function createClient({ links: _links, ...clientOptions } = {}) {
const defaultLinks = [
...(clientOptions.auth
? [(0, fetch_links_1.authLink)(clientOptions.auth, clientOptions.baseUrl ?? '')]
: []),
(0, fetch_links_1.fetchLink)(),
];
const links = typeof _links === 'function' ? _links(defaultLinks) : _links ?? defaultLinks;
const customFetch = (url, init) => (0, fetch_links_1.applyLinks)(new Request(url, init), links);
const client = (0, openapi_fetch_1.default)({ ...clientOptions, fetch: customFetch });
return {
const fetchClient = (0, openapi_fetch_1.default)({
...clientOptions,
fetch: customFetch,
});
const pathBasedClient = (0, openapi_fetch_1.wrapAsPathBasedClient)(fetchClient);
const clientThatThrows = Object.fromEntries(fetch_links_1.HTTP_METHODS.map((method) => [
method,
/* eslint-disable */
(...args) => fetchClient[method](...args).then(throwIfNotOk(method)),
/* eslint-enable */
]));
const pathBasecClientThatThrows = new Proxy(pathBasedClient, {
/* eslint-disable */
get(target, prop) {
if (prop in target) {
return target[prop];
}
return Object.fromEntries(fetch_links_1.HTTP_METHODS.map((method) => [
method,
(...args) => target[prop][method](...args).then(throwIfNotOk(method)),
]));
},
/* eslint-enable */
});
const _ret = {
fetchClient,
clientOptions,
links,
client,
/** Untyped request */
request: (method, url, options) => client[method](url, options).then(throwIfNotOk(method)),
GET: (...args) => client.GET(...args).then(throwIfNotOk('GET')),
PUT: (...args) => client.PUT(...args).then(throwIfNotOk('PUT')),
POST: (...args) => client.POST(...args).then(throwIfNotOk('POST')),
DELETE: (...args) => client.DELETE(...args).then(throwIfNotOk('DELETE')),
OPTIONS: (...args) => client.OPTIONS(...args).then(throwIfNotOk('OPTIONS')),
HEAD: (...args) => client.HEAD(...args).then(throwIfNotOk('HEAD')),
PATCH: (...args) => client.PATCH(...args).then(throwIfNotOk('PATCH')),
TRACE: (...args) => client.TRACE(...args).then(throwIfNotOk('TRACE')),
request: (method, url, options) => fetchClient[method](url, options).then(throwIfNotOk(method)),
};
Object.assign(pathBasecClientThatThrows, clientThatThrows);
Object.assign(pathBasecClientThatThrows, _ret);
return pathBasecClientThatThrows;
}
exports.createClient = createClient;
function throwIfNotOk(method) {
return (res) => {
if (res.error) {
throw new HTTPError_js_1.HTTPError({ method, error: res.error, response: res.response });
}
// error is not set, so safely casting..
return res;
};
}
exports.throwIfNotOk = throwIfNotOk;
/**

@@ -70,2 +103,15 @@ * Would be nice if we got this automatically, but openapi ts is types only...

exports.createFormUrlEncodedBodySerializer = createFormUrlEncodedBodySerializer;
// MARK: - Type helpers to handle throwing
/* eslint-disable @typescript-eslint/no-explicit-any */
function throwIfNotOk(method) {
return (res) => {
if (res.error) {
throw new HTTPError_js_1.HTTPError({ method, error: res.error, response: res.response });
}
// error is not set, so safely casting..
return res;
};
}
exports.throwIfNotOk = throwIfNotOk;
/* eslint-enable @typescript-eslint/no-explicit-any */
//# sourceMappingURL=createClient.js.map

@@ -35,6 +35,8 @@ "use strict";

(0, createClient_js_1.createClient)(clientOptions);
// make sure this works with proxy based client
Object.assign(client, { def: sdkDef });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return { ...client, def: sdkDef };
return client;
}
exports.initSDK = initSDK;
//# sourceMappingURL=index.js.map

@@ -1,12 +0,26 @@

import type {BodySerializer, FetchOptions, FetchResponse} from 'openapi-fetch'
import _createClient from 'openapi-fetch'
import type {PathsWithMethod} from 'openapi-typescript-helpers'
import type {
BodySerializer,
FetchOptions,
FetchResponse,
InitParam,
MaybeOptionalInit,
} from 'openapi-fetch'
import _createClient, {wrapAsPathBasedClient} from 'openapi-fetch'
import type {
HttpMethod,
MediaType,
PathsWithMethod,
} from 'openapi-typescript-helpers'
import type {ClientAuthOptions} from '@opensdks/fetch-links'
import {
applyLinks,
authLink,
fetchLink,
type HTTPMethod,
HTTP_METHODS,
// type HTTPMethod,
type Link,
} from '@opensdks/fetch-links'
import {HTTPError} from './HTTPError.js'
import {flattenNestedObject, FlattenOptions} from './utils.js'
import type {FlattenOptions} from './utils.js'
import {flattenNestedObject} from './utils.js'

@@ -17,2 +31,3 @@ type _ClientOptions = NonNullable<Parameters<typeof _createClient>[0]>

links?: Link[] | ((defaultLinks: Link[]) => Link[])
auth?: ClientAuthOptions
}

@@ -29,65 +44,81 @@

export const defaultLinks = [fetchLink()]
export function createClient<
Paths extends {},
Media extends MediaType = MediaType,
>({links: _links, ...clientOptions}: ClientOptions = {}) {
const defaultLinks = [
...(clientOptions.auth
? [authLink(clientOptions.auth, clientOptions.baseUrl ?? '')]
: []),
fetchLink(),
]
const links =
typeof _links === 'function' ? _links(defaultLinks) : _links ?? defaultLinks
export function createClient<Paths extends {}>({
links: _links = defaultLinks,
...clientOptions
}: ClientOptions = {}) {
const links = typeof _links === 'function' ? _links(defaultLinks) : _links
const customFetch: typeof fetch = (url, init) =>
applyLinks(new Request(url, init), links)
const client = _createClient<Paths>({...clientOptions, fetch: customFetch})
return {
const fetchClient = _createClient<Paths, Media>({
...clientOptions,
fetch: customFetch,
})
const pathBasedClient = wrapAsPathBasedClient(fetchClient)
const clientThatThrows = Object.fromEntries(
HTTP_METHODS.map((method) => [
method,
/* eslint-disable */
(...args: unknown[]) =>
(fetchClient as any)[method](...args).then(throwIfNotOk(method)),
/* eslint-enable */
]),
) as {
[K in Uppercase<HttpMethod>]: ClientMethodThatThrows<
Paths,
Lowercase<K>,
Media
>
}
const pathBasecClientThatThrows = new Proxy(pathBasedClient, {
/* eslint-disable */
get(target, prop) {
if (prop in target) {
return (target as any)[prop]
}
return Object.fromEntries(
HTTP_METHODS.map((method) => [
method,
(...args: unknown[]) =>
(target as any)[prop][method](...args).then(throwIfNotOk(method)),
]),
)
},
/* eslint-enable */
}) as PathBasedClientThatThrows<Paths, Media>
const _ret = {
fetchClient,
clientOptions,
links,
client,
/** Untyped request */
request: <T>(
method: HTTPMethod,
method: Uppercase<HttpMethod>,
url: string,
options?: Omit<FetchOptions<unknown>, 'body'> & {body?: unknown},
) =>
client[method as 'GET'](url as never, options as never).then(
fetchClient[method as 'GET'](url as never, options as never).then(
throwIfNotOk(method),
) as Promise<{
data: T
response: FetchResponse<unknown>['response']
response: FetchResponse<{}, {}, MediaType>['response']
}>,
GET: <P extends PathsWithMethod<Paths, 'get'>>(
...args: Parameters<typeof client.GET<P>>
) => client.GET<P>(...args).then(throwIfNotOk('GET')),
PUT: <P extends PathsWithMethod<Paths, 'put'>>(
...args: Parameters<typeof client.PUT<P>>
) => client.PUT(...args).then(throwIfNotOk('PUT')),
POST: <P extends PathsWithMethod<Paths, 'post'>>(
...args: Parameters<typeof client.POST<P>>
) => client.POST(...args).then(throwIfNotOk('POST')),
DELETE: <P extends PathsWithMethod<Paths, 'delete'>>(
...args: Parameters<typeof client.DELETE<P>>
) => client.DELETE(...args).then(throwIfNotOk('DELETE')),
OPTIONS: <P extends PathsWithMethod<Paths, 'options'>>(
...args: Parameters<typeof client.OPTIONS<P>>
) => client.OPTIONS(...args).then(throwIfNotOk('OPTIONS')),
HEAD: <P extends PathsWithMethod<Paths, 'head'>>(
...args: Parameters<typeof client.HEAD<P>>
) => client.HEAD(...args).then(throwIfNotOk('HEAD')),
PATCH: <P extends PathsWithMethod<Paths, 'patch'>>(
...args: Parameters<typeof client.PATCH<P>>
) => client.PATCH(...args).then(throwIfNotOk('PATCH')),
TRACE: <P extends PathsWithMethod<Paths, 'trace'>>(
...args: Parameters<typeof client.TRACE<P>>
) => client.TRACE(...args).then(throwIfNotOk('TRACE')),
}
}
Object.assign(pathBasecClientThatThrows, clientThatThrows)
Object.assign(pathBasecClientThatThrows, _ret)
export function throwIfNotOk<T>(method: HTTPMethod) {
return (res: FetchResponse<T>) => {
if (res.error) {
throw new HTTPError<T>({method, error: res.error, response: res.response})
}
// error is not set, so safely casting..
return res as Extract<typeof res, {data: unknown}>
}
return pathBasecClientThatThrows as typeof pathBasecClientThatThrows &
typeof clientThatThrows &
typeof _ret
}

@@ -120,1 +151,52 @@

}
// MARK: - Type helpers to handle throwing
/* eslint-disable @typescript-eslint/no-explicit-any */
export function throwIfNotOk<T extends Record<string | number, any>>(
method: Uppercase<HttpMethod>,
) {
return (res: FetchResponse<T, {}, MediaType>) => {
if (res.error) {
throw new HTTPError<T>({method, error: res.error, response: res.response})
}
// error is not set, so safely casting..
return res as Extract<typeof res, {data: unknown}>
}
}
export type ClientMethodThatThrows<
Paths extends Record<string, Record<HttpMethod, {}>>,
Method extends HttpMethod,
Media extends MediaType,
> = <
Path extends PathsWithMethod<Paths, Method>,
Init extends MaybeOptionalInit<Paths[Path], Method>,
>(
url: Path,
...init: InitParam<Init>
) => Promise<
Extract<FetchResponse<Paths[Path][Method], Init, Media>, {data: unknown}>
>
export type PathBasedClientThatThrows<
Paths extends Record<string | number, any>,
Media extends MediaType = MediaType,
> = {
[Path in keyof Paths]: ClientThatThrowsForPath<Paths[Path], Media>
}
export type ClientThatThrowsForPath<
PathInfo extends Record<string | number, any>,
Media extends MediaType,
> = {
[Method in keyof PathInfo as Uppercase<string & Method>]: <
Init extends MaybeOptionalInit<PathInfo, Method>,
>(
...init: InitParam<Init>
) => Promise<
Extract<FetchResponse<PathInfo[Method], Init, Media>, {data: unknown}>
>
}
/* eslint-enable @typescript-eslint/no-explicit-any */

@@ -1,3 +0,3 @@

import _createClient from 'openapi-fetch';
import { applyLinks, fetchLink, } from '@opensdks/fetch-links';
import _createClient, { wrapAsPathBasedClient } from 'openapi-fetch';
import { applyLinks, authLink, fetchLink, HTTP_METHODS, } from '@opensdks/fetch-links';
import { HTTPError } from './HTTPError.js';

@@ -9,32 +9,46 @@ import { flattenNestedObject } from './utils.js';

// Really do feel that they should be generated as well..
export const defaultLinks = [fetchLink()];
export function createClient({ links: _links = defaultLinks, ...clientOptions } = {}) {
const links = typeof _links === 'function' ? _links(defaultLinks) : _links;
export function createClient({ links: _links, ...clientOptions } = {}) {
const defaultLinks = [
...(clientOptions.auth
? [authLink(clientOptions.auth, clientOptions.baseUrl ?? '')]
: []),
fetchLink(),
];
const links = typeof _links === 'function' ? _links(defaultLinks) : _links ?? defaultLinks;
const customFetch = (url, init) => applyLinks(new Request(url, init), links);
const client = _createClient({ ...clientOptions, fetch: customFetch });
return {
const fetchClient = _createClient({
...clientOptions,
fetch: customFetch,
});
const pathBasedClient = wrapAsPathBasedClient(fetchClient);
const clientThatThrows = Object.fromEntries(HTTP_METHODS.map((method) => [
method,
/* eslint-disable */
(...args) => fetchClient[method](...args).then(throwIfNotOk(method)),
/* eslint-enable */
]));
const pathBasecClientThatThrows = new Proxy(pathBasedClient, {
/* eslint-disable */
get(target, prop) {
if (prop in target) {
return target[prop];
}
return Object.fromEntries(HTTP_METHODS.map((method) => [
method,
(...args) => target[prop][method](...args).then(throwIfNotOk(method)),
]));
},
/* eslint-enable */
});
const _ret = {
fetchClient,
clientOptions,
links,
client,
/** Untyped request */
request: (method, url, options) => client[method](url, options).then(throwIfNotOk(method)),
GET: (...args) => client.GET(...args).then(throwIfNotOk('GET')),
PUT: (...args) => client.PUT(...args).then(throwIfNotOk('PUT')),
POST: (...args) => client.POST(...args).then(throwIfNotOk('POST')),
DELETE: (...args) => client.DELETE(...args).then(throwIfNotOk('DELETE')),
OPTIONS: (...args) => client.OPTIONS(...args).then(throwIfNotOk('OPTIONS')),
HEAD: (...args) => client.HEAD(...args).then(throwIfNotOk('HEAD')),
PATCH: (...args) => client.PATCH(...args).then(throwIfNotOk('PATCH')),
TRACE: (...args) => client.TRACE(...args).then(throwIfNotOk('TRACE')),
request: (method, url, options) => fetchClient[method](url, options).then(throwIfNotOk(method)),
};
Object.assign(pathBasecClientThatThrows, clientThatThrows);
Object.assign(pathBasecClientThatThrows, _ret);
return pathBasecClientThatThrows;
}
export function throwIfNotOk(method) {
return (res) => {
if (res.error) {
throw new HTTPError({ method, error: res.error, response: res.response });
}
// error is not set, so safely casting..
return res;
};
}
/**

@@ -60,2 +74,14 @@ * Would be nice if we got this automatically, but openapi ts is types only...

};
// MARK: - Type helpers to handle throwing
/* eslint-disable @typescript-eslint/no-explicit-any */
export function throwIfNotOk(method) {
return (res) => {
if (res.error) {
throw new HTTPError({ method, error: res.error, response: res.response });
}
// error is not set, so safely casting..
return res;
};
}
/* eslint-enable @typescript-eslint/no-explicit-any */
//# sourceMappingURL=createClient.js.map

@@ -18,5 +18,7 @@ import { createClient } from './createClient.js';

createClient(clientOptions);
// make sure this works with proxy based client
Object.assign(client, { def: sdkDef });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return { ...client, def: sdkDef };
return client;
}
//# sourceMappingURL=index.js.map
import type {FetchResponse} from 'openapi-fetch'
import type {HTTPMethod} from '@opensdks/fetch-links'
import type {HttpMethod, MediaType} from 'openapi-typescript-helpers'
export class HTTPError<T> extends Error {
export class HTTPError<T extends Record<string | number, any>> extends Error {
override name = 'HTTPError'
readonly method: HTTPMethod
readonly error: Extract<FetchResponse<T>, {error: unknown}>['error']
readonly response: FetchResponse<T>['response']
readonly method: Uppercase<HttpMethod>
readonly error: Extract<
FetchResponse<T, {}, MediaType>,
{error: unknown}
>['error']
readonly response: FetchResponse<T, {}, MediaType>['response']

@@ -18,3 +21,5 @@ get code() {

response: r,
}: Extract<FetchResponse<T>, {error: unknown}> & {method: HTTPMethod}) {
}: Extract<FetchResponse<T, {}, MediaType>, {error: unknown}> & {
method: Uppercase<HttpMethod>
}) {
super(

@@ -21,0 +26,0 @@ [

@@ -77,4 +77,7 @@ import type {oas30, oas31} from 'openapi3-ts'

// make sure this works with proxy based client
Object.assign(client, {def: sdkDef})
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return {...client, def: sdkDef} as any
return client as any
}

@@ -81,0 +84,0 @@

{
"name": "@opensdks/runtime",
"version": "0.0.20",
"version": "0.0.21",
"type": "module",

@@ -34,6 +34,6 @@ "exports": {

"dependencies": {
"openapi-fetch": "0.8.1",
"openapi-typescript-helpers": "0.0.4",
"openapi3-ts": "4.1.2",
"@opensdks/fetch-links": "0.0.19"
"openapi-fetch": "^0.13.3",
"openapi-typescript-helpers": "^0.0.15",
"openapi3-ts": "^4.4.0",
"@opensdks/fetch-links": "0.0.20"
},

@@ -49,3 +49,3 @@ "devDependencies": {

"build:cjs": "tsc -p ./tsconfig.build.json --declaration false --declarationMap false --module CommonJS --moduleResolution Node10 --outDir ./cjs",
"build:cjs-pkgjson": "mkdir -p ./cjs && echo '{\"type\": \"commonjs\"}' > ./cjs/package.json",
"build:cjs-pkgjson": "mkdir -p ./cjs && mkdir -p ./types && echo '{\"type\": \"commonjs\"}' | tee ./cjs/package.json ./types/package.json",
"build:esm": "tsc -p ./tsconfig.build.json --declaration false --declarationMap false --outDir ./esm",

@@ -52,0 +52,0 @@ "build:types": "tsc -p ./tsconfig.build.json --emitDeclarationOnly --outDir ./types",

@@ -1,19 +0,36 @@

import type { BodySerializer, FetchOptions, FetchResponse } from 'openapi-fetch';
import type { BodySerializer, FetchOptions, FetchResponse, InitParam, MaybeOptionalInit } from 'openapi-fetch';
import _createClient from 'openapi-fetch';
import type { PathsWithMethod } from 'openapi-typescript-helpers';
import { type HTTPMethod, type Link } from '@opensdks/fetch-links';
import { FlattenOptions } from './utils.js';
import type { HttpMethod, MediaType, PathsWithMethod } from 'openapi-typescript-helpers';
import type { ClientAuthOptions } from '@opensdks/fetch-links';
import { type Link } from '@opensdks/fetch-links';
import type { FlattenOptions } from './utils.js';
type _ClientOptions = NonNullable<Parameters<typeof _createClient>[0]>;
export interface ClientOptions extends _ClientOptions {
links?: Link[] | ((defaultLinks: Link[]) => Link[]);
auth?: ClientAuthOptions;
}
export type OpenAPIClient<Paths extends {}> = ReturnType<typeof createClient<Paths>>;
export declare const defaultLinks: Link[];
export declare function createClient<Paths extends {}>({ links: _links, ...clientOptions }?: ClientOptions): {
export declare function createClient<Paths extends {}, Media extends MediaType = MediaType>({ links: _links, ...clientOptions }?: ClientOptions): PathBasedClientThatThrows<Paths, Media> & {
GET: ClientMethodThatThrows<Paths, "get", Media>;
PUT: ClientMethodThatThrows<Paths, "put", Media>;
POST: ClientMethodThatThrows<Paths, "post", Media>;
DELETE: ClientMethodThatThrows<Paths, "delete", Media>;
OPTIONS: ClientMethodThatThrows<Paths, "options", Media>;
HEAD: ClientMethodThatThrows<Paths, "head", Media>;
PATCH: ClientMethodThatThrows<Paths, "patch", Media>;
TRACE: ClientMethodThatThrows<Paths, "trace", Media>;
} & {
fetchClient: import("openapi-fetch").Client<Paths, Media>;
clientOptions: {
auth?: ClientAuthOptions | undefined;
baseUrl?: string | undefined;
fetch?: typeof fetch | undefined;
querySerializer?: import("openapi-fetch").QuerySerializer<unknown> | undefined;
fetch?: ((input: Request) => Promise<Response>) | undefined;
Request?: {
new (input: RequestInfo | URL, init?: RequestInit | undefined): Request;
prototype: Request;
} | undefined;
querySerializer?: import("openapi-fetch").QuerySerializer<unknown> | import("openapi-fetch").QuerySerializerOptions | undefined;
bodySerializer?: BodySerializer<unknown> | undefined;
headers?: import("openapi-fetch").HeadersOptions | undefined;
requestInitExt?: Record<string, unknown> | undefined;
method?: string | undefined;

@@ -33,65 +50,10 @@ body?: BodyInit | null | undefined;

links: Link[];
client: {
GET<P extends PathsWithMethod<Paths, "get">>(url: P, ...init: import("openapi-typescript-helpers").HasRequiredKeys<FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P], "get">>> extends never ? [(FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P], "get">> | undefined)?] : [FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P], "get">>]): Promise<FetchResponse<"get" extends keyof Paths[P] ? Paths[P][keyof Paths[P] & "get"] : unknown>>;
PUT<P_1 extends PathsWithMethod<Paths, "put">>(url: P_1, ...init: import("openapi-typescript-helpers").HasRequiredKeys<FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_1], "put">>> extends never ? [(FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_1], "put">> | undefined)?] : [FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_1], "put">>]): Promise<FetchResponse<"put" extends keyof Paths[P_1] ? Paths[P_1][keyof Paths[P_1] & "put"] : unknown>>;
POST<P_2 extends PathsWithMethod<Paths, "post">>(url: P_2, ...init: import("openapi-typescript-helpers").HasRequiredKeys<FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_2], "post">>> extends never ? [(FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_2], "post">> | undefined)?] : [FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_2], "post">>]): Promise<FetchResponse<"post" extends keyof Paths[P_2] ? Paths[P_2][keyof Paths[P_2] & "post"] : unknown>>;
DELETE<P_3 extends PathsWithMethod<Paths, "delete">>(url: P_3, ...init: import("openapi-typescript-helpers").HasRequiredKeys<FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_3], "delete">>> extends never ? [(FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_3], "delete">> | undefined)?] : [FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_3], "delete">>]): Promise<FetchResponse<"delete" extends keyof Paths[P_3] ? Paths[P_3][keyof Paths[P_3] & "delete"] : unknown>>;
OPTIONS<P_4 extends PathsWithMethod<Paths, "options">>(url: P_4, ...init: import("openapi-typescript-helpers").HasRequiredKeys<FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_4], "options">>> extends never ? [(FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_4], "options">> | undefined)?] : [FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_4], "options">>]): Promise<FetchResponse<"options" extends keyof Paths[P_4] ? Paths[P_4][keyof Paths[P_4] & "options"] : unknown>>;
HEAD<P_5 extends PathsWithMethod<Paths, "head">>(url: P_5, ...init: import("openapi-typescript-helpers").HasRequiredKeys<FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_5], "head">>> extends never ? [(FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_5], "head">> | undefined)?] : [FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_5], "head">>]): Promise<FetchResponse<"head" extends keyof Paths[P_5] ? Paths[P_5][keyof Paths[P_5] & "head"] : unknown>>;
PATCH<P_6 extends PathsWithMethod<Paths, "patch">>(url: P_6, ...init: import("openapi-typescript-helpers").HasRequiredKeys<FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_6], "patch">>> extends never ? [(FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_6], "patch">> | undefined)?] : [FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_6], "patch">>]): Promise<FetchResponse<"patch" extends keyof Paths[P_6] ? Paths[P_6][keyof Paths[P_6] & "patch"] : unknown>>;
TRACE<P_7 extends PathsWithMethod<Paths, "trace">>(url: P_7, ...init: import("openapi-typescript-helpers").HasRequiredKeys<FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_7], "trace">>> extends never ? [(FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_7], "trace">> | undefined)?] : [FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_7], "trace">>]): Promise<FetchResponse<"trace" extends keyof Paths[P_7] ? Paths[P_7][keyof Paths[P_7] & "trace"] : unknown>>;
};
/** Untyped request */
request: <T>(method: HTTPMethod, url: string, options?: Omit<FetchOptions<unknown>, 'body'> & {
request: <T>(method: Uppercase<HttpMethod>, url: string, options?: Omit<FetchOptions<unknown>, 'body'> & {
body?: unknown;
}) => Promise<{
data: T;
response: FetchResponse<unknown>['response'];
response: FetchResponse<{}, {}, MediaType>['response'];
}>;
GET: <P_8 extends PathsWithMethod<Paths, "get">>(url: P_8, ...init: import("openapi-typescript-helpers").HasRequiredKeys<FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_8], "get">>> extends never ? [(FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_8], "get">> | undefined)?] : [FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_8], "get">>]) => Promise<{
data: import("openapi-typescript-helpers").FilterKeys<import("openapi-typescript-helpers").SuccessResponse<import("openapi-typescript-helpers").ResponseObjectMap<"get" extends keyof Paths[P_8] ? Paths[P_8][keyof Paths[P_8] & "get"] : unknown>>, `${string}/${string}`>;
error?: undefined;
response: Response;
}>;
PUT: <P_9 extends PathsWithMethod<Paths, "put">>(url: P_9, ...init: import("openapi-typescript-helpers").HasRequiredKeys<FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_9], "put">>> extends never ? [(FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_9], "put">> | undefined)?] : [FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_9], "put">>]) => Promise<{
data: import("openapi-typescript-helpers").FilterKeys<import("openapi-typescript-helpers").SuccessResponse<import("openapi-typescript-helpers").ResponseObjectMap<"put" extends keyof Paths[P_9] ? Paths[P_9][keyof Paths[P_9] & "put"] : unknown>>, `${string}/${string}`>;
error?: undefined;
response: Response;
}>;
POST: <P_10 extends PathsWithMethod<Paths, "post">>(url: P_10, ...init: import("openapi-typescript-helpers").HasRequiredKeys<FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_10], "post">>> extends never ? [(FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_10], "post">> | undefined)?] : [FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_10], "post">>]) => Promise<{
data: import("openapi-typescript-helpers").FilterKeys<import("openapi-typescript-helpers").SuccessResponse<import("openapi-typescript-helpers").ResponseObjectMap<"post" extends keyof Paths[P_10] ? Paths[P_10][keyof Paths[P_10] & "post"] : unknown>>, `${string}/${string}`>;
error?: undefined;
response: Response;
}>;
DELETE: <P_11 extends PathsWithMethod<Paths, "delete">>(url: P_11, ...init: import("openapi-typescript-helpers").HasRequiredKeys<FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_11], "delete">>> extends never ? [(FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_11], "delete">> | undefined)?] : [FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_11], "delete">>]) => Promise<{
data: import("openapi-typescript-helpers").FilterKeys<import("openapi-typescript-helpers").SuccessResponse<import("openapi-typescript-helpers").ResponseObjectMap<"delete" extends keyof Paths[P_11] ? Paths[P_11][keyof Paths[P_11] & "delete"] : unknown>>, `${string}/${string}`>;
error?: undefined;
response: Response;
}>;
OPTIONS: <P_12 extends PathsWithMethod<Paths, "options">>(url: P_12, ...init: import("openapi-typescript-helpers").HasRequiredKeys<FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_12], "options">>> extends never ? [(FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_12], "options">> | undefined)?] : [FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_12], "options">>]) => Promise<{
data: import("openapi-typescript-helpers").FilterKeys<import("openapi-typescript-helpers").SuccessResponse<import("openapi-typescript-helpers").ResponseObjectMap<"options" extends keyof Paths[P_12] ? Paths[P_12][keyof Paths[P_12] & "options"] : unknown>>, `${string}/${string}`>;
error?: undefined;
response: Response;
}>;
HEAD: <P_13 extends PathsWithMethod<Paths, "head">>(url: P_13, ...init: import("openapi-typescript-helpers").HasRequiredKeys<FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_13], "head">>> extends never ? [(FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_13], "head">> | undefined)?] : [FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_13], "head">>]) => Promise<{
data: import("openapi-typescript-helpers").FilterKeys<import("openapi-typescript-helpers").SuccessResponse<import("openapi-typescript-helpers").ResponseObjectMap<"head" extends keyof Paths[P_13] ? Paths[P_13][keyof Paths[P_13] & "head"] : unknown>>, `${string}/${string}`>;
error?: undefined;
response: Response;
}>;
PATCH: <P_14 extends PathsWithMethod<Paths, "patch">>(url: P_14, ...init: import("openapi-typescript-helpers").HasRequiredKeys<FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_14], "patch">>> extends never ? [(FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_14], "patch">> | undefined)?] : [FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_14], "patch">>]) => Promise<{
data: import("openapi-typescript-helpers").FilterKeys<import("openapi-typescript-helpers").SuccessResponse<import("openapi-typescript-helpers").ResponseObjectMap<"patch" extends keyof Paths[P_14] ? Paths[P_14][keyof Paths[P_14] & "patch"] : unknown>>, `${string}/${string}`>;
error?: undefined;
response: Response;
}>;
TRACE: <P_15 extends PathsWithMethod<Paths, "trace">>(url: P_15, ...init: import("openapi-typescript-helpers").HasRequiredKeys<FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_15], "trace">>> extends never ? [(FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_15], "trace">> | undefined)?] : [FetchOptions<import("openapi-typescript-helpers").FilterKeys<Paths[P_15], "trace">>]) => Promise<{
data: import("openapi-typescript-helpers").FilterKeys<import("openapi-typescript-helpers").SuccessResponse<import("openapi-typescript-helpers").ResponseObjectMap<"trace" extends keyof Paths[P_15] ? Paths[P_15][keyof Paths[P_15] & "trace"] : unknown>>, `${string}/${string}`>;
error?: undefined;
response: Response;
}>;
};
export declare function throwIfNotOk<T>(method: HTTPMethod): (res: FetchResponse<T>) => {
data: import("openapi-typescript-helpers").FilterKeys<import("openapi-typescript-helpers").SuccessResponse<import("openapi-typescript-helpers").ResponseObjectMap<T>>, `${string}/${string}`>;
error?: undefined;
response: Response;
};
/**

@@ -102,3 +64,19 @@ * Would be nice if we got this automatically, but openapi ts is types only...

export declare const createFormUrlEncodedBodySerializer: (options?: FlattenOptions) => BodySerializer<unknown>;
export declare function throwIfNotOk<T extends Record<string | number, any>>(method: Uppercase<HttpMethod>): (res: FetchResponse<T, {}, MediaType>) => {
data: import("openapi-typescript-helpers").SuccessResponse<import("openapi-typescript-helpers").ResponseObjectMap<T>, `${string}/${string}`>;
error?: undefined;
response: Response;
};
export type ClientMethodThatThrows<Paths extends Record<string, Record<HttpMethod, {}>>, Method extends HttpMethod, Media extends MediaType> = <Path extends PathsWithMethod<Paths, Method>, Init extends MaybeOptionalInit<Paths[Path], Method>>(url: Path, ...init: InitParam<Init>) => Promise<Extract<FetchResponse<Paths[Path][Method], Init, Media>, {
data: unknown;
}>>;
export type PathBasedClientThatThrows<Paths extends Record<string | number, any>, Media extends MediaType = MediaType> = {
[Path in keyof Paths]: ClientThatThrowsForPath<Paths[Path], Media>;
};
export type ClientThatThrowsForPath<PathInfo extends Record<string | number, any>, Media extends MediaType> = {
[Method in keyof PathInfo as Uppercase<string & Method>]: <Init extends MaybeOptionalInit<PathInfo, Method>>(...init: InitParam<Init>) => Promise<Extract<FetchResponse<PathInfo[Method], Init, Media>, {
data: unknown;
}>>;
};
export {};
//# sourceMappingURL=createClient.d.ts.map
import type { FetchResponse } from 'openapi-fetch';
import type { HTTPMethod } from '@opensdks/fetch-links';
export declare class HTTPError<T> extends Error {
import type { HttpMethod, MediaType } from 'openapi-typescript-helpers';
export declare class HTTPError<T extends Record<string | number, any>> extends Error {
name: string;
readonly method: HTTPMethod;
readonly error: Extract<FetchResponse<T>, {
readonly method: Uppercase<HttpMethod>;
readonly error: Extract<FetchResponse<T, {}, MediaType>, {
error: unknown;
}>['error'];
readonly response: FetchResponse<T>['response'];
readonly response: FetchResponse<T, {}, MediaType>['response'];
get code(): number;
constructor({ method, error, response: r, }: Extract<FetchResponse<T>, {
constructor({ method, error, response: r, }: Extract<FetchResponse<T, {}, MediaType>, {
error: unknown;
}> & {
method: HTTPMethod;
method: Uppercase<HttpMethod>;
});
}
//# sourceMappingURL=HTTPError.d.ts.map

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc