@praxium/sdk 0.2.4
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.d.ts +707 -0
- package/dist/index.js +987 -0
- package/dist/revalidation.d.ts +28 -0
- package/dist/revalidation.js +46 -0
- package/package.json +56 -0
- package/src/errors.ts +126 -0
- package/src/generated/client/client.gen.ts +288 -0
- package/src/generated/client/index.ts +25 -0
- package/src/generated/client/types.gen.ts +213 -0
- package/src/generated/client/utils.gen.ts +316 -0
- package/src/generated/client.gen.ts +16 -0
- package/src/generated/core/auth.gen.ts +41 -0
- package/src/generated/core/bodySerializer.gen.ts +84 -0
- package/src/generated/core/params.gen.ts +169 -0
- package/src/generated/core/pathSerializer.gen.ts +171 -0
- package/src/generated/core/queryKeySerializer.gen.ts +117 -0
- package/src/generated/core/serverSentEvents.gen.ts +243 -0
- package/src/generated/core/types.gen.ts +104 -0
- package/src/generated/core/utils.gen.ts +140 -0
- package/src/generated/index.ts +4 -0
- package/src/generated/sdk.gen.ts +177 -0
- package/src/generated/types.gen.ts +1263 -0
- package/src/index.ts +70 -0
- package/src/revalidation.ts +105 -0
- package/src/tenant-client.ts +180 -0
- package/src/types/next-cache.d.ts +24 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ISR Revalidation Handler for Tenant Websites
|
|
3
|
+
*
|
|
4
|
+
* When admin updates data in the platform, a webhook triggers
|
|
5
|
+
* revalidation on the tenant's public website. This handler
|
|
6
|
+
* validates the secret and calls Next.js revalidatePath().
|
|
7
|
+
*
|
|
8
|
+
* Usage in tenant website's `app/api/revalidate/route.ts`:
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { createRevalidationHandler } from '@praxium/sdk/revalidation'
|
|
12
|
+
*
|
|
13
|
+
* export const POST = createRevalidationHandler({
|
|
14
|
+
* secret: process.env.PRAXIUM_REVALIDATION_SECRET!,
|
|
15
|
+
* })
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
interface RevalidationConfig {
|
|
19
|
+
/** Shared secret for webhook authentication */
|
|
20
|
+
secret: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Creates a Next.js route handler that revalidates ISR pages
|
|
24
|
+
* when triggered by the Praxium platform webhook.
|
|
25
|
+
*/
|
|
26
|
+
declare function createRevalidationHandler(config: RevalidationConfig): (request: Request) => Promise<Response>;
|
|
27
|
+
|
|
28
|
+
export { createRevalidationHandler };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// src/revalidation.ts
|
|
2
|
+
function isSecretValid(provided, expected) {
|
|
3
|
+
const encoder = new TextEncoder();
|
|
4
|
+
const a = encoder.encode(provided);
|
|
5
|
+
const b = encoder.encode(expected);
|
|
6
|
+
if (a.length !== b.length) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
let mismatch = 0;
|
|
10
|
+
for (let i = 0; i < a.length; i++) {
|
|
11
|
+
mismatch |= a[i] ^ b[i];
|
|
12
|
+
}
|
|
13
|
+
return mismatch === 0;
|
|
14
|
+
}
|
|
15
|
+
function createRevalidationHandler(config) {
|
|
16
|
+
return async (request) => {
|
|
17
|
+
let body;
|
|
18
|
+
try {
|
|
19
|
+
body = await request.json();
|
|
20
|
+
} catch {
|
|
21
|
+
return Response.json({ error: "Invalid JSON body" }, { status: 400 });
|
|
22
|
+
}
|
|
23
|
+
if (!isSecretValid(body.secret, config.secret)) {
|
|
24
|
+
return Response.json(
|
|
25
|
+
{ error: "Invalid revalidation secret" },
|
|
26
|
+
{ status: 401 }
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
const paths = body.paths ?? ["/"];
|
|
30
|
+
try {
|
|
31
|
+
const { revalidatePath } = await import("next/cache");
|
|
32
|
+
for (const path of paths) {
|
|
33
|
+
revalidatePath(path);
|
|
34
|
+
}
|
|
35
|
+
} catch {
|
|
36
|
+
return Response.json(
|
|
37
|
+
{ error: "Revalidation failed \u2014 next/cache not available" },
|
|
38
|
+
{ status: 500 }
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
return Response.json({ revalidated: true, paths });
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export {
|
|
45
|
+
createRevalidationHandler
|
|
46
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@praxium/sdk",
|
|
3
|
+
"version": "0.2.4",
|
|
4
|
+
"description": "TypeScript SDK for Praxium public tenant API — auto-generated from OpenAPI spec",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts"
|
|
10
|
+
},
|
|
11
|
+
"./revalidation": {
|
|
12
|
+
"import": "./dist/revalidation.js",
|
|
13
|
+
"types": "./dist/revalidation.d.ts"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"src"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"generate": "openapi-ts",
|
|
22
|
+
"build": "tsup src/index.ts src/revalidation.ts --format esm --dts --clean --external next",
|
|
23
|
+
"typecheck": "tsc --noEmit",
|
|
24
|
+
"test": "vitest run",
|
|
25
|
+
"test:watch": "vitest"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@hey-api/openapi-ts": "^0.92.4",
|
|
29
|
+
"tsup": "^8.0.0",
|
|
30
|
+
"typescript": "^5.7.0",
|
|
31
|
+
"vitest": "^4.0.18"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"next": ">=14.0.0"
|
|
35
|
+
},
|
|
36
|
+
"peerDependenciesMeta": {
|
|
37
|
+
"next": {
|
|
38
|
+
"optional": true
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=20"
|
|
43
|
+
},
|
|
44
|
+
"keywords": [
|
|
45
|
+
"praxium",
|
|
46
|
+
"sdk",
|
|
47
|
+
"openapi",
|
|
48
|
+
"physiotherapy",
|
|
49
|
+
"tenant-api"
|
|
50
|
+
],
|
|
51
|
+
"license": "UNLICENSED",
|
|
52
|
+
"repository": {
|
|
53
|
+
"type": "git",
|
|
54
|
+
"url": "https://gitlab.com/praxium_platform/core/sdk.git"
|
|
55
|
+
}
|
|
56
|
+
}
|
package/src/errors.ts
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed error hierarchy for the Praxium SDK.
|
|
3
|
+
*
|
|
4
|
+
* Every method on `TenantClient` throws one of these errors when the
|
|
5
|
+
* API returns a non-2xx response. Consumers can catch a specific
|
|
6
|
+
* subclass (e.g. `PraxiumNotFoundError`) or the base `PraxiumError`.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* try {
|
|
11
|
+
* const hours = await client.getOpeningHours()
|
|
12
|
+
* } catch (err) {
|
|
13
|
+
* if (err instanceof PraxiumNotFoundError) {
|
|
14
|
+
* // tenant slug is invalid
|
|
15
|
+
* }
|
|
16
|
+
* }
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import type { ApiError } from './generated/types.gen'
|
|
21
|
+
|
|
22
|
+
/** Validation error detail from the API */
|
|
23
|
+
export type ValidationDetail = NonNullable<ApiError['details']>[number]
|
|
24
|
+
|
|
25
|
+
// ─── Base Error ──────────────────────────────────────────────────────
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Base error for all Praxium API failures.
|
|
29
|
+
*
|
|
30
|
+
* Properties mirror the `ApiError` response body from the platform:
|
|
31
|
+
* - `status` — HTTP status code
|
|
32
|
+
* - `errorCode` — Machine-readable code (e.g. `'TENANT_NOT_FOUND'`)
|
|
33
|
+
* - `message` — Human-readable explanation
|
|
34
|
+
* - `details` — Optional validation error details (400 responses only)
|
|
35
|
+
*/
|
|
36
|
+
export class PraxiumError extends Error {
|
|
37
|
+
override name: string
|
|
38
|
+
|
|
39
|
+
constructor(
|
|
40
|
+
public readonly status: number,
|
|
41
|
+
public readonly errorCode: string,
|
|
42
|
+
message: string,
|
|
43
|
+
public readonly details?: ApiError['details']
|
|
44
|
+
) {
|
|
45
|
+
super(message)
|
|
46
|
+
this.name = 'PraxiumError'
|
|
47
|
+
// Restore prototype chain broken by extending built-ins
|
|
48
|
+
Object.setPrototypeOf(this, new.target.prototype)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// ─── 400 Validation ──────────────────────────────────────────────────
|
|
53
|
+
|
|
54
|
+
/** Thrown when the server rejects the request body (HTTP 400). */
|
|
55
|
+
export class PraxiumValidationError extends PraxiumError {
|
|
56
|
+
constructor(
|
|
57
|
+
errorCode: string,
|
|
58
|
+
message: string,
|
|
59
|
+
details?: ApiError['details']
|
|
60
|
+
) {
|
|
61
|
+
super(400, errorCode, message, details)
|
|
62
|
+
this.name = 'PraxiumValidationError'
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// ─── 401 Authentication ──────────────────────────────────────────────
|
|
67
|
+
|
|
68
|
+
/** Thrown when the API key is missing or invalid (HTTP 401). */
|
|
69
|
+
export class PraxiumAuthError extends PraxiumError {
|
|
70
|
+
constructor(errorCode: string, message: string) {
|
|
71
|
+
super(401, errorCode, message)
|
|
72
|
+
this.name = 'PraxiumAuthError'
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// ─── 403 Forbidden ───────────────────────────────────────────────────
|
|
77
|
+
|
|
78
|
+
/** Thrown when the API key does not match the requested tenant (HTTP 403). */
|
|
79
|
+
export class PraxiumForbiddenError extends PraxiumError {
|
|
80
|
+
constructor(errorCode: string, message: string) {
|
|
81
|
+
super(403, errorCode, message)
|
|
82
|
+
this.name = 'PraxiumForbiddenError'
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// ─── 404 Not Found ───────────────────────────────────────────────────
|
|
87
|
+
|
|
88
|
+
/** Thrown when the tenant is not found or inactive (HTTP 404). */
|
|
89
|
+
export class PraxiumNotFoundError extends PraxiumError {
|
|
90
|
+
constructor(errorCode: string, message: string) {
|
|
91
|
+
super(404, errorCode, message)
|
|
92
|
+
this.name = 'PraxiumNotFoundError'
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// ─── 429 Rate Limit ──────────────────────────────────────────────────
|
|
97
|
+
|
|
98
|
+
/** Thrown when the rate limit is exceeded (HTTP 429). */
|
|
99
|
+
export class PraxiumRateLimitError extends PraxiumError {
|
|
100
|
+
constructor(errorCode: string, message: string) {
|
|
101
|
+
super(429, errorCode, message)
|
|
102
|
+
this.name = 'PraxiumRateLimitError'
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// ─── Status → Error Mapping ──────────────────────────────────────────
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Map of HTTP status codes to their corresponding PraxiumError subclass.
|
|
110
|
+
* Used internally by `unwrapOrThrow` to construct the correct error.
|
|
111
|
+
* @internal Not part of the public SDK API — do not re-export from index.ts
|
|
112
|
+
*/
|
|
113
|
+
export const STATUS_ERROR_MAP: Record<
|
|
114
|
+
number,
|
|
115
|
+
new (
|
|
116
|
+
errorCode: string,
|
|
117
|
+
message: string,
|
|
118
|
+
details?: ApiError['details']
|
|
119
|
+
) => PraxiumError
|
|
120
|
+
> = {
|
|
121
|
+
400: PraxiumValidationError,
|
|
122
|
+
401: PraxiumAuthError,
|
|
123
|
+
403: PraxiumForbiddenError,
|
|
124
|
+
404: PraxiumNotFoundError,
|
|
125
|
+
429: PraxiumRateLimitError,
|
|
126
|
+
}
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
|
|
3
|
+
import { createSseClient } from '../core/serverSentEvents.gen';
|
|
4
|
+
import type { HttpMethod } from '../core/types.gen';
|
|
5
|
+
import { getValidRequestBody } from '../core/utils.gen';
|
|
6
|
+
import type { Client, Config, RequestOptions, ResolvedRequestOptions } from './types.gen';
|
|
7
|
+
import {
|
|
8
|
+
buildUrl,
|
|
9
|
+
createConfig,
|
|
10
|
+
createInterceptors,
|
|
11
|
+
getParseAs,
|
|
12
|
+
mergeConfigs,
|
|
13
|
+
mergeHeaders,
|
|
14
|
+
setAuthParams,
|
|
15
|
+
} from './utils.gen';
|
|
16
|
+
|
|
17
|
+
type ReqInit = Omit<RequestInit, 'body' | 'headers'> & {
|
|
18
|
+
body?: any;
|
|
19
|
+
headers: ReturnType<typeof mergeHeaders>;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const createClient = (config: Config = {}): Client => {
|
|
23
|
+
let _config = mergeConfigs(createConfig(), config);
|
|
24
|
+
|
|
25
|
+
const getConfig = (): Config => ({ ..._config });
|
|
26
|
+
|
|
27
|
+
const setConfig = (config: Config): Config => {
|
|
28
|
+
_config = mergeConfigs(_config, config);
|
|
29
|
+
return getConfig();
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const interceptors = createInterceptors<Request, Response, unknown, ResolvedRequestOptions>();
|
|
33
|
+
|
|
34
|
+
const beforeRequest = async (options: RequestOptions) => {
|
|
35
|
+
const opts = {
|
|
36
|
+
..._config,
|
|
37
|
+
...options,
|
|
38
|
+
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
39
|
+
headers: mergeHeaders(_config.headers, options.headers),
|
|
40
|
+
serializedBody: undefined,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
if (opts.security) {
|
|
44
|
+
await setAuthParams({
|
|
45
|
+
...opts,
|
|
46
|
+
security: opts.security,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (opts.requestValidator) {
|
|
51
|
+
await opts.requestValidator(opts);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (opts.body !== undefined && opts.bodySerializer) {
|
|
55
|
+
opts.serializedBody = opts.bodySerializer(opts.body);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// remove Content-Type header if body is empty to avoid sending invalid requests
|
|
59
|
+
if (opts.body === undefined || opts.serializedBody === '') {
|
|
60
|
+
opts.headers.delete('Content-Type');
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const url = buildUrl(opts);
|
|
64
|
+
|
|
65
|
+
return { opts, url };
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const request: Client['request'] = async (options) => {
|
|
69
|
+
// @ts-expect-error
|
|
70
|
+
const { opts, url } = await beforeRequest(options);
|
|
71
|
+
const requestInit: ReqInit = {
|
|
72
|
+
redirect: 'follow',
|
|
73
|
+
...opts,
|
|
74
|
+
body: getValidRequestBody(opts),
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
let request = new Request(url, requestInit);
|
|
78
|
+
|
|
79
|
+
for (const fn of interceptors.request.fns) {
|
|
80
|
+
if (fn) {
|
|
81
|
+
request = await fn(request, opts);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// fetch must be assigned here, otherwise it would throw the error:
|
|
86
|
+
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
|
|
87
|
+
const _fetch = opts.fetch!;
|
|
88
|
+
let response: Response;
|
|
89
|
+
|
|
90
|
+
try {
|
|
91
|
+
response = await _fetch(request);
|
|
92
|
+
} catch (error) {
|
|
93
|
+
// Handle fetch exceptions (AbortError, network errors, etc.)
|
|
94
|
+
let finalError = error;
|
|
95
|
+
|
|
96
|
+
for (const fn of interceptors.error.fns) {
|
|
97
|
+
if (fn) {
|
|
98
|
+
finalError = (await fn(error, undefined as any, request, opts)) as unknown;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
finalError = finalError || ({} as unknown);
|
|
103
|
+
|
|
104
|
+
if (opts.throwOnError) {
|
|
105
|
+
throw finalError;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// Return error response
|
|
109
|
+
return opts.responseStyle === 'data'
|
|
110
|
+
? undefined
|
|
111
|
+
: {
|
|
112
|
+
error: finalError,
|
|
113
|
+
request,
|
|
114
|
+
response: undefined as any,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
for (const fn of interceptors.response.fns) {
|
|
119
|
+
if (fn) {
|
|
120
|
+
response = await fn(response, request, opts);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const result = {
|
|
125
|
+
request,
|
|
126
|
+
response,
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
if (response.ok) {
|
|
130
|
+
const parseAs =
|
|
131
|
+
(opts.parseAs === 'auto'
|
|
132
|
+
? getParseAs(response.headers.get('Content-Type'))
|
|
133
|
+
: opts.parseAs) ?? 'json';
|
|
134
|
+
|
|
135
|
+
if (response.status === 204 || response.headers.get('Content-Length') === '0') {
|
|
136
|
+
let emptyData: any;
|
|
137
|
+
switch (parseAs) {
|
|
138
|
+
case 'arrayBuffer':
|
|
139
|
+
case 'blob':
|
|
140
|
+
case 'text':
|
|
141
|
+
emptyData = await response[parseAs]();
|
|
142
|
+
break;
|
|
143
|
+
case 'formData':
|
|
144
|
+
emptyData = new FormData();
|
|
145
|
+
break;
|
|
146
|
+
case 'stream':
|
|
147
|
+
emptyData = response.body;
|
|
148
|
+
break;
|
|
149
|
+
case 'json':
|
|
150
|
+
default:
|
|
151
|
+
emptyData = {};
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
return opts.responseStyle === 'data'
|
|
155
|
+
? emptyData
|
|
156
|
+
: {
|
|
157
|
+
data: emptyData,
|
|
158
|
+
...result,
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
let data: any;
|
|
163
|
+
switch (parseAs) {
|
|
164
|
+
case 'arrayBuffer':
|
|
165
|
+
case 'blob':
|
|
166
|
+
case 'formData':
|
|
167
|
+
case 'text':
|
|
168
|
+
data = await response[parseAs]();
|
|
169
|
+
break;
|
|
170
|
+
case 'json': {
|
|
171
|
+
// Some servers return 200 with no Content-Length and empty body.
|
|
172
|
+
// response.json() would throw; read as text and parse if non-empty.
|
|
173
|
+
const text = await response.text();
|
|
174
|
+
data = text ? JSON.parse(text) : {};
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
case 'stream':
|
|
178
|
+
return opts.responseStyle === 'data'
|
|
179
|
+
? response.body
|
|
180
|
+
: {
|
|
181
|
+
data: response.body,
|
|
182
|
+
...result,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (parseAs === 'json') {
|
|
187
|
+
if (opts.responseValidator) {
|
|
188
|
+
await opts.responseValidator(data);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (opts.responseTransformer) {
|
|
192
|
+
data = await opts.responseTransformer(data);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return opts.responseStyle === 'data'
|
|
197
|
+
? data
|
|
198
|
+
: {
|
|
199
|
+
data,
|
|
200
|
+
...result,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const textError = await response.text();
|
|
205
|
+
let jsonError: unknown;
|
|
206
|
+
|
|
207
|
+
try {
|
|
208
|
+
jsonError = JSON.parse(textError);
|
|
209
|
+
} catch {
|
|
210
|
+
// noop
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const error = jsonError ?? textError;
|
|
214
|
+
let finalError = error;
|
|
215
|
+
|
|
216
|
+
for (const fn of interceptors.error.fns) {
|
|
217
|
+
if (fn) {
|
|
218
|
+
finalError = (await fn(error, response, request, opts)) as string;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
finalError = finalError || ({} as string);
|
|
223
|
+
|
|
224
|
+
if (opts.throwOnError) {
|
|
225
|
+
throw finalError;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// TODO: we probably want to return error and improve types
|
|
229
|
+
return opts.responseStyle === 'data'
|
|
230
|
+
? undefined
|
|
231
|
+
: {
|
|
232
|
+
error: finalError,
|
|
233
|
+
...result,
|
|
234
|
+
};
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
const makeMethodFn = (method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
|
|
238
|
+
request({ ...options, method });
|
|
239
|
+
|
|
240
|
+
const makeSseFn = (method: Uppercase<HttpMethod>) => async (options: RequestOptions) => {
|
|
241
|
+
const { opts, url } = await beforeRequest(options);
|
|
242
|
+
return createSseClient({
|
|
243
|
+
...opts,
|
|
244
|
+
body: opts.body as BodyInit | null | undefined,
|
|
245
|
+
headers: opts.headers as unknown as Record<string, string>,
|
|
246
|
+
method,
|
|
247
|
+
onRequest: async (url, init) => {
|
|
248
|
+
let request = new Request(url, init);
|
|
249
|
+
for (const fn of interceptors.request.fns) {
|
|
250
|
+
if (fn) {
|
|
251
|
+
request = await fn(request, opts);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return request;
|
|
255
|
+
},
|
|
256
|
+
serializedBody: getValidRequestBody(opts) as BodyInit | null | undefined,
|
|
257
|
+
url,
|
|
258
|
+
});
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
return {
|
|
262
|
+
buildUrl,
|
|
263
|
+
connect: makeMethodFn('CONNECT'),
|
|
264
|
+
delete: makeMethodFn('DELETE'),
|
|
265
|
+
get: makeMethodFn('GET'),
|
|
266
|
+
getConfig,
|
|
267
|
+
head: makeMethodFn('HEAD'),
|
|
268
|
+
interceptors,
|
|
269
|
+
options: makeMethodFn('OPTIONS'),
|
|
270
|
+
patch: makeMethodFn('PATCH'),
|
|
271
|
+
post: makeMethodFn('POST'),
|
|
272
|
+
put: makeMethodFn('PUT'),
|
|
273
|
+
request,
|
|
274
|
+
setConfig,
|
|
275
|
+
sse: {
|
|
276
|
+
connect: makeSseFn('CONNECT'),
|
|
277
|
+
delete: makeSseFn('DELETE'),
|
|
278
|
+
get: makeSseFn('GET'),
|
|
279
|
+
head: makeSseFn('HEAD'),
|
|
280
|
+
options: makeSseFn('OPTIONS'),
|
|
281
|
+
patch: makeSseFn('PATCH'),
|
|
282
|
+
post: makeSseFn('POST'),
|
|
283
|
+
put: makeSseFn('PUT'),
|
|
284
|
+
trace: makeSseFn('TRACE'),
|
|
285
|
+
},
|
|
286
|
+
trace: makeMethodFn('TRACE'),
|
|
287
|
+
} as Client;
|
|
288
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
|
|
3
|
+
export type { Auth } from '../core/auth.gen';
|
|
4
|
+
export type { QuerySerializerOptions } from '../core/bodySerializer.gen';
|
|
5
|
+
export {
|
|
6
|
+
formDataBodySerializer,
|
|
7
|
+
jsonBodySerializer,
|
|
8
|
+
urlSearchParamsBodySerializer,
|
|
9
|
+
} from '../core/bodySerializer.gen';
|
|
10
|
+
export { buildClientParams } from '../core/params.gen';
|
|
11
|
+
export { serializeQueryKeyValue } from '../core/queryKeySerializer.gen';
|
|
12
|
+
export { createClient } from './client.gen';
|
|
13
|
+
export type {
|
|
14
|
+
Client,
|
|
15
|
+
ClientOptions,
|
|
16
|
+
Config,
|
|
17
|
+
CreateClientConfig,
|
|
18
|
+
Options,
|
|
19
|
+
RequestOptions,
|
|
20
|
+
RequestResult,
|
|
21
|
+
ResolvedRequestOptions,
|
|
22
|
+
ResponseStyle,
|
|
23
|
+
TDataShape,
|
|
24
|
+
} from './types.gen';
|
|
25
|
+
export { createConfig, mergeHeaders } from './utils.gen';
|