v0-api 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
36
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.Types = exports.Schemas = exports.Helpers = exports.Fetchers = void 0;
40
+ const Components = __importStar(require("./generated/components.js"));
41
+ const Schemas = __importStar(require("./generated/schemas.js"));
42
+ exports.Schemas = Schemas;
43
+ const Types = __importStar(require("./generated/types.js"));
44
+ exports.Types = Types;
45
+ const { operationsByPath, operationsByTag, tagDictionary, ...Fetchers } = Components;
46
+ exports.Fetchers = Fetchers;
47
+ const Helpers = { operationsByPath, operationsByTag, tagDictionary };
48
+ exports.Helpers = Helpers;
49
+ __exportStar(require("./client.js"), exports);
package/dist/index.mjs ADDED
@@ -0,0 +1,7 @@
1
+ import * as Components from "./generated/components.mjs";
2
+ import * as Schemas from "./generated/schemas.mjs";
3
+ import * as Types from "./generated/types.mjs";
4
+ const { operationsByPath, operationsByTag, tagDictionary, ...Fetchers } = Components;
5
+ const Helpers = { operationsByPath, operationsByTag, tagDictionary };
6
+ export * from "./client.mjs";
7
+ export { Fetchers, Helpers, Schemas, Types };
@@ -0,0 +1,18 @@
1
+ export type RequestInit = {
2
+ body?: string | FormData | undefined;
3
+ headers?: Record<string, string> | undefined;
4
+ method?: string | undefined;
5
+ signal?: any | undefined;
6
+ };
7
+ export type Response = {
8
+ ok: boolean;
9
+ status: number;
10
+ url: string;
11
+ json(): Promise<any>;
12
+ text(): Promise<string>;
13
+ headers?: {
14
+ get(name: string): string | null;
15
+ } | undefined;
16
+ };
17
+ export type FetchImpl = (url: string, init?: RequestInit) => Promise<Response>;
18
+ export declare function formEncoded<T extends Record<string, string>>(data: T): string;
@@ -0,0 +1,18 @@
1
+ export type RequestInit = {
2
+ body?: string | FormData | undefined;
3
+ headers?: Record<string, string> | undefined;
4
+ method?: string | undefined;
5
+ signal?: any | undefined;
6
+ };
7
+ export type Response = {
8
+ ok: boolean;
9
+ status: number;
10
+ url: string;
11
+ json(): Promise<any>;
12
+ text(): Promise<string>;
13
+ headers?: {
14
+ get(name: string): string | null;
15
+ } | undefined;
16
+ };
17
+ export type FetchImpl = (url: string, init?: RequestInit) => Promise<Response>;
18
+ export declare function formEncoded<T extends Record<string, string>>(data: T): string;
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formEncoded = formEncoded;
4
+ function formEncoded(data) {
5
+ return Object.entries(data)
6
+ .map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
7
+ .join('&');
8
+ }
@@ -0,0 +1,5 @@
1
+ export function formEncoded(data) {
2
+ return Object.entries(data)
3
+ .map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
4
+ .join('&');
5
+ }
@@ -0,0 +1,22 @@
1
+ import { FetchImpl } from "./fetch.mjs";
2
+ export type FetcherConfig = {
3
+ baseUrl?: string;
4
+ token?: string | null;
5
+ fetchImpl?: FetchImpl;
6
+ headers?: Record<string, any>;
7
+ };
8
+ export type ErrorWrapper<TError> = TError | {
9
+ status: 'unknown';
10
+ payload: string;
11
+ };
12
+ export type FetcherOptions<TBody, THeaders, TQueryParams, TPathParams> = {
13
+ url: string;
14
+ method: string;
15
+ body?: TBody | undefined;
16
+ headers?: THeaders | undefined;
17
+ queryParams?: TQueryParams | undefined;
18
+ pathParams?: TPathParams | undefined;
19
+ signal?: AbortSignal | undefined;
20
+ } & FetcherConfig;
21
+ export declare function client<TData, TError, TBody, THeaders, TQueryParams, TPathParams>({ url, method, body, headers, queryParams, signal, token, baseUrl, fetchImpl }: FetcherOptions<TBody, THeaders, TQueryParams, TPathParams>): Promise<TData>;
22
+ export default client;
@@ -0,0 +1,22 @@
1
+ import { FetchImpl } from "./fetch.js";
2
+ export type FetcherConfig = {
3
+ baseUrl?: string;
4
+ token?: string | null;
5
+ fetchImpl?: FetchImpl;
6
+ headers?: Record<string, any>;
7
+ };
8
+ export type ErrorWrapper<TError> = TError | {
9
+ status: 'unknown';
10
+ payload: string;
11
+ };
12
+ export type FetcherOptions<TBody, THeaders, TQueryParams, TPathParams> = {
13
+ url: string;
14
+ method: string;
15
+ body?: TBody | undefined;
16
+ headers?: THeaders | undefined;
17
+ queryParams?: TQueryParams | undefined;
18
+ pathParams?: TPathParams | undefined;
19
+ signal?: AbortSignal | undefined;
20
+ } & FetcherConfig;
21
+ export declare function client<TData, TError, TBody, THeaders, TQueryParams, TPathParams>({ url, method, body, headers, queryParams, signal, token, baseUrl, fetchImpl }: FetcherOptions<TBody, THeaders, TQueryParams, TPathParams>): Promise<TData>;
22
+ export default client;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.client = client;
4
+ const lang_1 = require("./lang.js");
5
+ async function client({ url, method, body, headers, queryParams, signal, token = null, baseUrl = '', fetchImpl = fetch }) {
6
+ try {
7
+ const requestHeaders = (0, lang_1.compactObject)({
8
+ 'Content-Type': 'application/json',
9
+ Authorization: token ? `Bearer ${token}` : undefined,
10
+ ...headers
11
+ });
12
+ /**
13
+ * As the fetch API is being used, when multipart/form-data is specified
14
+ * the Content-Type header must be deleted so that the browser can set
15
+ * the correct boundary.
16
+ * https://developer.mozilla.org/en-US/docs/Web/API/FormData/Using_FormData_Objects#sending_files_using_a_formdata_object
17
+ */
18
+ if (requestHeaders['Content-Type']?.toLowerCase().includes('multipart/form-data')) {
19
+ delete requestHeaders['Content-Type'];
20
+ }
21
+ const payload = body instanceof FormData
22
+ ? body
23
+ : requestHeaders['Content-Type'] === 'application/json'
24
+ ? JSON.stringify(body)
25
+ : body;
26
+ const fullUrl = `${baseUrl}${resolveUrl(url, queryParams)}`;
27
+ const response = await fetchImpl(fullUrl, {
28
+ signal,
29
+ method: method.toUpperCase(),
30
+ body: payload,
31
+ headers: requestHeaders
32
+ });
33
+ if (!response.ok) {
34
+ let error;
35
+ try {
36
+ error = await response.json();
37
+ }
38
+ catch (e) {
39
+ error = {
40
+ status: 'unknown',
41
+ payload: e instanceof Error ? `Unexpected error (${e.message})` : 'Unexpected error'
42
+ };
43
+ }
44
+ throw error;
45
+ }
46
+ if (response.headers?.get('content-type')?.includes('json')) {
47
+ return await response.json();
48
+ }
49
+ else {
50
+ // if it is not a json response, assume it is a blob and cast it to TData
51
+ return (await response.text());
52
+ }
53
+ }
54
+ catch (e) {
55
+ const errorObject = {
56
+ name: 'unknown',
57
+ message: e?.message ? `${e?.message}` : 'Network error'
58
+ };
59
+ throw errorObject;
60
+ }
61
+ }
62
+ const resolveUrl = (url, queryParams = {}) => {
63
+ let query = new URLSearchParams(queryParams).toString();
64
+ if (query)
65
+ query = `?${query}`;
66
+ return url + query;
67
+ };
68
+ exports.default = client;
@@ -0,0 +1,65 @@
1
+ import { compactObject } from "./lang.mjs";
2
+ export async function client({ url, method, body, headers, queryParams, signal, token = null, baseUrl = '', fetchImpl = fetch }) {
3
+ try {
4
+ const requestHeaders = compactObject({
5
+ 'Content-Type': 'application/json',
6
+ Authorization: token ? `Bearer ${token}` : undefined,
7
+ ...headers
8
+ });
9
+ /**
10
+ * As the fetch API is being used, when multipart/form-data is specified
11
+ * the Content-Type header must be deleted so that the browser can set
12
+ * the correct boundary.
13
+ * https://developer.mozilla.org/en-US/docs/Web/API/FormData/Using_FormData_Objects#sending_files_using_a_formdata_object
14
+ */
15
+ if (requestHeaders['Content-Type']?.toLowerCase().includes('multipart/form-data')) {
16
+ delete requestHeaders['Content-Type'];
17
+ }
18
+ const payload = body instanceof FormData
19
+ ? body
20
+ : requestHeaders['Content-Type'] === 'application/json'
21
+ ? JSON.stringify(body)
22
+ : body;
23
+ const fullUrl = `${baseUrl}${resolveUrl(url, queryParams)}`;
24
+ const response = await fetchImpl(fullUrl, {
25
+ signal,
26
+ method: method.toUpperCase(),
27
+ body: payload,
28
+ headers: requestHeaders
29
+ });
30
+ if (!response.ok) {
31
+ let error;
32
+ try {
33
+ error = await response.json();
34
+ }
35
+ catch (e) {
36
+ error = {
37
+ status: 'unknown',
38
+ payload: e instanceof Error ? `Unexpected error (${e.message})` : 'Unexpected error'
39
+ };
40
+ }
41
+ throw error;
42
+ }
43
+ if (response.headers?.get('content-type')?.includes('json')) {
44
+ return await response.json();
45
+ }
46
+ else {
47
+ // if it is not a json response, assume it is a blob and cast it to TData
48
+ return (await response.text());
49
+ }
50
+ }
51
+ catch (e) {
52
+ const errorObject = {
53
+ name: 'unknown',
54
+ message: e?.message ? `${e?.message}` : 'Network error'
55
+ };
56
+ throw errorObject;
57
+ }
58
+ }
59
+ const resolveUrl = (url, queryParams = {}) => {
60
+ let query = new URLSearchParams(queryParams).toString();
61
+ if (query)
62
+ query = `?${query}`;
63
+ return url + query;
64
+ };
65
+ export default client;
@@ -0,0 +1 @@
1
+ export declare function compactObject<T>(obj: Record<string, T | null | undefined>): Record<string, T>;
@@ -0,0 +1 @@
1
+ export declare function compactObject<T>(obj: Record<string, T | null | undefined>): Record<string, T>;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.compactObject = compactObject;
4
+ function notEmpty(value) {
5
+ return value !== null && value !== undefined;
6
+ }
7
+ function compactObject(obj) {
8
+ return Object.fromEntries(Object.entries(obj).filter(([, value]) => notEmpty(value)));
9
+ }
@@ -0,0 +1,6 @@
1
+ function notEmpty(value) {
2
+ return value !== null && value !== undefined;
3
+ }
4
+ export function compactObject(obj) {
5
+ return Object.fromEntries(Object.entries(obj).filter(([, value]) => notEmpty(value)));
6
+ }
@@ -0,0 +1,3 @@
1
+ export type RequiredKeys<T> = {
2
+ [K in keyof T]-?: {} extends Pick<T, K> ? never : K;
3
+ }[keyof T];
@@ -0,0 +1,3 @@
1
+ export type RequiredKeys<T> = {
2
+ [K in keyof T]-?: {} extends Pick<T, K> ? never : K;
3
+ }[keyof T];
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "v0-api",
3
+ "version": "0.0.2",
4
+ "description": "Vercel v0 auto-generated type-safe API client",
5
+ "author": "SferaDev",
6
+ "license": "ISC",
7
+ "bugs": {
8
+ "url": "https://github.com/SferaDev/openapi-clients/issues"
9
+ },
10
+ "homepage": "https://github.com/SferaDev/openapi-clients#readme",
11
+ "zshy": "./src/index.ts",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/SferaDev/openapi-clients.git"
15
+ },
16
+ "devDependencies": {
17
+ "@kubb/cli": "^3.16.0",
18
+ "@kubb/core": "^3.16.0",
19
+ "@modelcontextprotocol/sdk": "^1.15.1",
20
+ "openapi-utils": "0.0.1"
21
+ },
22
+ "peerDependencies": {
23
+ "@modelcontextprotocol/sdk": "^1.15.1"
24
+ },
25
+ "dependencies": {
26
+ "zod": "^4.0.5"
27
+ },
28
+ "files": [
29
+ "dist"
30
+ ],
31
+ "main": "./dist/index.js",
32
+ "module": "./dist/index.mjs",
33
+ "types": "./dist/index.d.ts",
34
+ "exports": {
35
+ ".": {
36
+ "types": "./dist/index.d.ts",
37
+ "import": "./dist/index.mjs",
38
+ "require": "./dist/index.js"
39
+ }
40
+ },
41
+ "scripts": {
42
+ "tsc": "tsc --noEmit",
43
+ "build": "zshy",
44
+ "generate": "rimraf ./src/generated && kubb generate"
45
+ }
46
+ }