@saeeol/sdk 7.3.3 → 7.3.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.
Files changed (39) hide show
  1. package/package.json +2 -2
  2. package/src/client.ts +64 -0
  3. package/src/gen/client/client.gen.ts +215 -0
  4. package/src/gen/client/index.ts +25 -0
  5. package/src/gen/client/types.gen.ts +222 -0
  6. package/src/gen/client/utils.gen.ts +287 -0
  7. package/src/gen/client.gen.ts +22 -0
  8. package/src/gen/core/auth.gen.ts +41 -0
  9. package/src/gen/core/bodySerializer.gen.ts +74 -0
  10. package/src/gen/core/params.gen.ts +144 -0
  11. package/src/gen/core/pathSerializer.gen.ts +167 -0
  12. package/src/gen/core/queryKeySerializer.gen.ts +111 -0
  13. package/src/gen/core/serverSentEvents.gen.ts +210 -0
  14. package/src/gen/core/types.gen.ts +91 -0
  15. package/src/gen/core/utils.gen.ts +109 -0
  16. package/src/gen/sdk.gen.ts +1197 -0
  17. package/src/gen/types.gen.ts +3905 -0
  18. package/src/index.ts +21 -0
  19. package/src/process.ts +31 -0
  20. package/src/server.ts +165 -0
  21. package/src/v2/client.ts +97 -0
  22. package/src/v2/data.ts +32 -0
  23. package/src/v2/gen/client/client.gen.ts +285 -0
  24. package/src/v2/gen/client/index.ts +25 -0
  25. package/src/v2/gen/client/types.gen.ts +202 -0
  26. package/src/v2/gen/client/utils.gen.ts +289 -0
  27. package/src/v2/gen/client.gen.ts +18 -0
  28. package/src/v2/gen/core/auth.gen.ts +41 -0
  29. package/src/v2/gen/core/bodySerializer.gen.ts +82 -0
  30. package/src/v2/gen/core/params.gen.ts +169 -0
  31. package/src/v2/gen/core/pathSerializer.gen.ts +167 -0
  32. package/src/v2/gen/core/queryKeySerializer.gen.ts +111 -0
  33. package/src/v2/gen/core/serverSentEvents.gen.ts +239 -0
  34. package/src/v2/gen/core/types.gen.ts +86 -0
  35. package/src/v2/gen/core/utils.gen.ts +137 -0
  36. package/src/v2/gen/sdk.gen.ts +6316 -0
  37. package/src/v2/gen/types.gen.ts +7495 -0
  38. package/src/v2/index.ts +23 -0
  39. package/src/v2/server.ts +163 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@saeeol/sdk",
4
- "version": "7.3.3",
4
+ "version": "7.3.4",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
7
7
  "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org" },
@@ -19,7 +19,7 @@
19
19
  "./v2/server": "./src/v2/server.ts"
20
20
  },
21
21
  "files": [
22
- "dist"
22
+ "src"
23
23
  ],
24
24
  "devDependencies": {
25
25
  "@hey-api/openapi-ts": "0.90.10",
package/src/client.ts ADDED
@@ -0,0 +1,64 @@
1
+ export * from "./gen/types.gen.js"
2
+
3
+ import { createClient } from "./gen/client/client.gen.js"
4
+ import { type Config } from "./gen/client/types.gen.js"
5
+ import { SaeeolClient } from "./gen/sdk.gen.js"
6
+ export { type Config as SaeeolClientConfig, SaeeolClient }
7
+
8
+ function pick(value: string | null, fallback?: string) {
9
+ if (!value) return
10
+ if (!fallback) return value
11
+ if (value === fallback) return fallback
12
+ if (value === encodeURIComponent(fallback)) return fallback
13
+ return value
14
+ }
15
+
16
+ function rewrite(request: Request, directory?: string) {
17
+ if (request.method !== "GET" && request.method !== "HEAD") return request
18
+
19
+ const value = pick(request.headers.get("x-saeeol-directory"), directory)
20
+ if (!value) return request
21
+
22
+ const url = new URL(request.url)
23
+ if (!url.searchParams.has("directory")) {
24
+ url.searchParams.set("directory", value)
25
+ }
26
+
27
+ const next = new Request(url.href, request)
28
+ next.headers.delete("x-saeeol-directory")
29
+ return next
30
+ }
31
+
32
+ export function createSaeeolClient(config?: Config & { directory?: string }) {
33
+ if (!config?.fetch) {
34
+ const customFetch: any = (req: any) => {
35
+ // Pass duplex in the init arg so it survives VS Code's proxy-agent
36
+ // fetch wrapper, which calls originalFetch(request, { ...init, dispatcher })
37
+ // and would otherwise drop duplex from the cloned Request.
38
+ // timeout: false disables Bun's default request timeout for long-running
39
+ // streaming calls (replaces the old req.timeout = false assignment which
40
+ // wouldn't survive the clone triggered by passing an init object).
41
+ return fetch(req, { duplex: "half", timeout: false } as any)
42
+ }
43
+ config = {
44
+ ...config,
45
+ fetch: customFetch,
46
+ }
47
+ }
48
+
49
+ if (config?.directory) {
50
+ config.headers = {
51
+ ...config.headers,
52
+ "x-saeeol-directory": encodeURIComponent(config.directory),
53
+ }
54
+ }
55
+
56
+ // Node.js/Electron require duplex: "half" when creating Request objects
57
+ // with a body. The option propagates through config → opts → requestInit
58
+ // and is harmless in environments that don't need it (Bun, browsers).
59
+ ;(config as any).duplex = "half"
60
+
61
+ const client = createClient(config)
62
+ client.interceptors.request.use((request) => rewrite(request, config?.directory))
63
+ return new SaeeolClient({ client })
64
+ }
@@ -0,0 +1,215 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+
3
+ // Type declaration for BodyInit
4
+ type BodyInit = any
5
+
6
+ import { createSseClient } from "../core/serverSentEvents.gen.js"
7
+ import type { Client, Config, RequestOptions, ResolvedRequestOptions } from "./types.gen.js"
8
+ import {
9
+ buildUrl,
10
+ createConfig,
11
+ createInterceptors,
12
+ getParseAs,
13
+ mergeConfigs,
14
+ mergeHeaders,
15
+ setAuthParams,
16
+ } from "./utils.gen.js"
17
+
18
+ type ReqInit = Omit<RequestInit, "body" | "headers"> & {
19
+ body?: any
20
+ headers: ReturnType<typeof mergeHeaders>
21
+ }
22
+
23
+ export const createClient = (config: Config = {}): Client => {
24
+ let _config = mergeConfigs(createConfig(), config)
25
+
26
+ const getConfig = (): Config => ({ ..._config })
27
+
28
+ const setConfig = (config: Config): Config => {
29
+ _config = mergeConfigs(_config, config)
30
+ return getConfig()
31
+ }
32
+
33
+ const interceptors = createInterceptors<Request, Response, unknown, ResolvedRequestOptions>()
34
+
35
+ const beforeRequest = async (options: RequestOptions) => {
36
+ const opts = {
37
+ ..._config,
38
+ ...options,
39
+ fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
40
+ headers: mergeHeaders(_config.headers, options.headers),
41
+ serializedBody: undefined,
42
+ }
43
+
44
+ if (opts.security) {
45
+ await setAuthParams({
46
+ ...opts,
47
+ security: opts.security,
48
+ })
49
+ }
50
+
51
+ if (opts.requestValidator) {
52
+ await opts.requestValidator(opts)
53
+ }
54
+
55
+ if (opts.body && opts.bodySerializer) {
56
+ opts.serializedBody = opts.bodySerializer(opts.body)
57
+ }
58
+
59
+ // remove Content-Type header if body is empty to avoid sending invalid requests
60
+ if (opts.serializedBody === undefined || opts.serializedBody === "") {
61
+ opts.headers.delete("Content-Type")
62
+ }
63
+
64
+ const url = buildUrl(opts)
65
+
66
+ return { opts, url }
67
+ }
68
+
69
+ const request: Client["request"] = async (options) => {
70
+ // @ts-expect-error
71
+ const { opts, url } = await beforeRequest(options)
72
+ const requestInit: ReqInit = {
73
+ redirect: "follow",
74
+ ...opts,
75
+ body: opts.serializedBody,
76
+ }
77
+
78
+ let request = new Request(url, requestInit)
79
+
80
+ for (const fn of interceptors.request._fns) {
81
+ if (fn) {
82
+ request = await fn(request, opts)
83
+ }
84
+ }
85
+
86
+ // fetch must be assigned here, otherwise it would throw the error:
87
+ // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
88
+ const _fetch = opts.fetch!
89
+ let response = await _fetch(request)
90
+
91
+ for (const fn of interceptors.response._fns) {
92
+ if (fn) {
93
+ response = await fn(response, request, opts)
94
+ }
95
+ }
96
+
97
+ const result = {
98
+ request,
99
+ response,
100
+ }
101
+
102
+ if (response.ok) {
103
+ if (response.status === 204 || response.headers.get("Content-Length") === "0") {
104
+ return opts.responseStyle === "data"
105
+ ? {}
106
+ : {
107
+ data: {},
108
+ ...result,
109
+ }
110
+ }
111
+
112
+ const parseAs =
113
+ (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json"
114
+
115
+ let data: any
116
+ switch (parseAs) {
117
+ case "arrayBuffer":
118
+ case "blob":
119
+ case "formData":
120
+ case "json":
121
+ case "text":
122
+ data = await response[parseAs]()
123
+ break
124
+ case "stream":
125
+ return opts.responseStyle === "data"
126
+ ? response.body
127
+ : {
128
+ data: response.body,
129
+ ...result,
130
+ }
131
+ }
132
+
133
+ if (parseAs === "json") {
134
+ if (opts.responseValidator) {
135
+ await opts.responseValidator(data)
136
+ }
137
+
138
+ if (opts.responseTransformer) {
139
+ data = await opts.responseTransformer(data)
140
+ }
141
+ }
142
+
143
+ return opts.responseStyle === "data"
144
+ ? data
145
+ : {
146
+ data,
147
+ ...result,
148
+ }
149
+ }
150
+
151
+ const textError = await response.text()
152
+ let jsonError: unknown
153
+
154
+ try {
155
+ jsonError = JSON.parse(textError)
156
+ } catch {
157
+ // noop
158
+ }
159
+
160
+ const error = jsonError ?? textError
161
+ let finalError = error
162
+
163
+ for (const fn of interceptors.error._fns) {
164
+ if (fn) {
165
+ finalError = (await fn(error, response, request, opts)) as string
166
+ }
167
+ }
168
+
169
+ finalError = finalError || ({} as string)
170
+
171
+ if (opts.throwOnError) {
172
+ throw finalError
173
+ }
174
+
175
+ // TODO: we probably want to return error and improve types
176
+ return opts.responseStyle === "data"
177
+ ? undefined
178
+ : {
179
+ error: finalError,
180
+ ...result,
181
+ }
182
+ }
183
+
184
+ const makeMethod = (method: Required<Config>["method"]) => {
185
+ const fn = (options: RequestOptions) => request({ ...options, method })
186
+ fn.sse = async (options: RequestOptions) => {
187
+ const { opts, url } = await beforeRequest(options)
188
+ return createSseClient({
189
+ ...opts,
190
+ body: opts.body as BodyInit | null | undefined,
191
+ headers: opts.headers as unknown as Record<string, string>,
192
+ method,
193
+ url,
194
+ })
195
+ }
196
+ return fn
197
+ }
198
+
199
+ return {
200
+ buildUrl,
201
+ connect: makeMethod("CONNECT"),
202
+ delete: makeMethod("DELETE"),
203
+ get: makeMethod("GET"),
204
+ getConfig,
205
+ head: makeMethod("HEAD"),
206
+ interceptors,
207
+ options: makeMethod("OPTIONS"),
208
+ patch: makeMethod("PATCH"),
209
+ post: makeMethod("POST"),
210
+ put: makeMethod("PUT"),
211
+ request,
212
+ setConfig,
213
+ trace: makeMethod("TRACE"),
214
+ } as Client
215
+ }
@@ -0,0 +1,25 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+
3
+ export type { Auth } from "../core/auth.gen.js"
4
+ export type { QuerySerializerOptions } from "../core/bodySerializer.gen.js"
5
+ export {
6
+ formDataBodySerializer,
7
+ jsonBodySerializer,
8
+ urlSearchParamsBodySerializer,
9
+ } from "../core/bodySerializer.gen.js"
10
+ export { buildClientParams } from "../core/params.gen.js"
11
+ export { createClient } from "./client.gen.js"
12
+ export type {
13
+ Client,
14
+ ClientOptions,
15
+ Config,
16
+ CreateClientConfig,
17
+ Options,
18
+ OptionsLegacyParser,
19
+ RequestOptions,
20
+ RequestResult,
21
+ ResolvedRequestOptions,
22
+ ResponseStyle,
23
+ TDataShape,
24
+ } from "./types.gen.js"
25
+ export { createConfig, mergeHeaders } from "./utils.gen.js"
@@ -0,0 +1,222 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+
3
+ import type { Auth } from "../core/auth.gen.js"
4
+ import type { ServerSentEventsOptions, ServerSentEventsResult } from "../core/serverSentEvents.gen.js"
5
+ import type { Client as CoreClient, Config as CoreConfig } from "../core/types.gen.js"
6
+ import type { Middleware } from "./utils.gen.js"
7
+
8
+ export type ResponseStyle = "data" | "fields"
9
+
10
+ export interface Config<T extends ClientOptions = ClientOptions>
11
+ extends Omit<RequestInit, "body" | "headers" | "method">,
12
+ CoreConfig {
13
+ /**
14
+ * Base URL for all requests made by this client.
15
+ */
16
+ baseUrl?: T["baseUrl"]
17
+ /**
18
+ * Fetch API implementation. You can use this option to provide a custom
19
+ * fetch instance.
20
+ *
21
+ * @default globalThis.fetch
22
+ */
23
+ fetch?: (request: Request) => ReturnType<typeof fetch>
24
+ /**
25
+ * Please don't use the Fetch client for Next.js applications. The `next`
26
+ * options won't have any effect.
27
+ *
28
+ * Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead.
29
+ */
30
+ next?: never
31
+ /**
32
+ * Return the response data parsed in a specified format. By default, `auto`
33
+ * will infer the appropriate method from the `Content-Type` response header.
34
+ * You can override this behavior with any of the {@link Body} methods.
35
+ * Select `stream` if you don't want to parse response data at all.
36
+ *
37
+ * @default 'auto'
38
+ */
39
+ parseAs?: "arrayBuffer" | "auto" | "blob" | "formData" | "json" | "stream" | "text"
40
+ /**
41
+ * Should we return only data or multiple fields (data, error, response, etc.)?
42
+ *
43
+ * @default 'fields'
44
+ */
45
+ responseStyle?: ResponseStyle
46
+ /**
47
+ * Throw an error instead of returning it in the response?
48
+ *
49
+ * @default false
50
+ */
51
+ throwOnError?: T["throwOnError"]
52
+ }
53
+
54
+ export interface RequestOptions<
55
+ TData = unknown,
56
+ TResponseStyle extends ResponseStyle = "fields",
57
+ ThrowOnError extends boolean = boolean,
58
+ Url extends string = string,
59
+ > extends Config<{
60
+ responseStyle: TResponseStyle
61
+ throwOnError: ThrowOnError
62
+ }>,
63
+ Pick<
64
+ ServerSentEventsOptions<TData>,
65
+ "onSseError" | "onSseEvent" | "sseDefaultRetryDelay" | "sseMaxRetryAttempts" | "sseMaxRetryDelay"
66
+ > {
67
+ /**
68
+ * Any body that you want to add to your request.
69
+ *
70
+ * {@link https://developer.mozilla.org/docs/Web/API/fetch#body}
71
+ */
72
+ body?: unknown
73
+ path?: Record<string, unknown>
74
+ query?: Record<string, unknown>
75
+ /**
76
+ * Security mechanism(s) to use for the request.
77
+ */
78
+ security?: ReadonlyArray<Auth>
79
+ url: Url
80
+ }
81
+
82
+ export interface ResolvedRequestOptions<
83
+ TResponseStyle extends ResponseStyle = "fields",
84
+ ThrowOnError extends boolean = boolean,
85
+ Url extends string = string,
86
+ > extends RequestOptions<unknown, TResponseStyle, ThrowOnError, Url> {
87
+ serializedBody?: string
88
+ }
89
+
90
+ export type RequestResult<
91
+ TData = unknown,
92
+ TError = unknown,
93
+ ThrowOnError extends boolean = boolean,
94
+ TResponseStyle extends ResponseStyle = "fields",
95
+ > = ThrowOnError extends true
96
+ ? Promise<
97
+ TResponseStyle extends "data"
98
+ ? TData extends Record<string, unknown>
99
+ ? TData[keyof TData]
100
+ : TData
101
+ : {
102
+ data: TData extends Record<string, unknown> ? TData[keyof TData] : TData
103
+ request: Request
104
+ response: Response
105
+ }
106
+ >
107
+ : Promise<
108
+ TResponseStyle extends "data"
109
+ ? (TData extends Record<string, unknown> ? TData[keyof TData] : TData) | undefined
110
+ : (
111
+ | {
112
+ data: TData extends Record<string, unknown> ? TData[keyof TData] : TData
113
+ error: undefined
114
+ }
115
+ | {
116
+ data: undefined
117
+ error: TError extends Record<string, unknown> ? TError[keyof TError] : TError
118
+ }
119
+ ) & {
120
+ request: Request
121
+ response: Response
122
+ }
123
+ >
124
+
125
+ export interface ClientOptions {
126
+ baseUrl?: string
127
+ responseStyle?: ResponseStyle
128
+ throwOnError?: boolean
129
+ }
130
+
131
+ type MethodFnBase = <
132
+ TData = unknown,
133
+ TError = unknown,
134
+ ThrowOnError extends boolean = false,
135
+ TResponseStyle extends ResponseStyle = "fields",
136
+ >(
137
+ options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, "method">,
138
+ ) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>
139
+
140
+ type MethodFnServerSentEvents = <
141
+ TData = unknown,
142
+ TError = unknown,
143
+ ThrowOnError extends boolean = false,
144
+ TResponseStyle extends ResponseStyle = "fields",
145
+ >(
146
+ options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, "method">,
147
+ ) => Promise<ServerSentEventsResult<TData, TError>>
148
+
149
+ type MethodFn = MethodFnBase & {
150
+ sse: MethodFnServerSentEvents
151
+ }
152
+
153
+ type RequestFn = <
154
+ TData = unknown,
155
+ TError = unknown,
156
+ ThrowOnError extends boolean = false,
157
+ TResponseStyle extends ResponseStyle = "fields",
158
+ >(
159
+ options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, "method"> &
160
+ Pick<Required<RequestOptions<TData, TResponseStyle, ThrowOnError>>, "method">,
161
+ ) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>
162
+
163
+ type BuildUrlFn = <
164
+ TData extends {
165
+ body?: unknown
166
+ path?: Record<string, unknown>
167
+ query?: Record<string, unknown>
168
+ url: string
169
+ },
170
+ >(
171
+ options: Pick<TData, "url"> & Options<TData>,
172
+ ) => string
173
+
174
+ export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn> & {
175
+ interceptors: Middleware<Request, Response, unknown, ResolvedRequestOptions>
176
+ }
177
+
178
+ /**
179
+ * The `createClientConfig()` function will be called on client initialization
180
+ * and the returned object will become the client's initial configuration.
181
+ *
182
+ * You may want to initialize your client this way instead of calling
183
+ * `setConfig()`. This is useful for example if you're using Next.js
184
+ * to ensure your client always has the correct values.
185
+ */
186
+ export type CreateClientConfig<T extends ClientOptions = ClientOptions> = (
187
+ override?: Config<ClientOptions & T>,
188
+ ) => Config<Required<ClientOptions> & T>
189
+
190
+ export interface TDataShape {
191
+ body?: unknown
192
+ headers?: unknown
193
+ path?: unknown
194
+ query?: unknown
195
+ url: string
196
+ }
197
+
198
+ type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>
199
+
200
+ export type Options<
201
+ TData extends TDataShape = TDataShape,
202
+ ThrowOnError extends boolean = boolean,
203
+ TResponse = unknown,
204
+ TResponseStyle extends ResponseStyle = "fields",
205
+ > = OmitKeys<RequestOptions<TResponse, TResponseStyle, ThrowOnError>, "body" | "path" | "query" | "url"> &
206
+ Omit<TData, "url">
207
+
208
+ export type OptionsLegacyParser<
209
+ TData = unknown,
210
+ ThrowOnError extends boolean = boolean,
211
+ TResponseStyle extends ResponseStyle = "fields",
212
+ > = TData extends { body?: any }
213
+ ? TData extends { headers?: any }
214
+ ? OmitKeys<RequestOptions<unknown, TResponseStyle, ThrowOnError>, "body" | "headers" | "url"> & TData
215
+ : OmitKeys<RequestOptions<unknown, TResponseStyle, ThrowOnError>, "body" | "url"> &
216
+ TData &
217
+ Pick<RequestOptions<unknown, TResponseStyle, ThrowOnError>, "headers">
218
+ : TData extends { headers?: any }
219
+ ? OmitKeys<RequestOptions<unknown, TResponseStyle, ThrowOnError>, "headers" | "url"> &
220
+ TData &
221
+ Pick<RequestOptions<unknown, TResponseStyle, ThrowOnError>, "body">
222
+ : OmitKeys<RequestOptions<unknown, TResponseStyle, ThrowOnError>, "url"> & TData