@saeeol/sdk 7.3.3 → 7.3.5

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 +6 -3
  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
@@ -0,0 +1,287 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+
3
+ import { getAuthToken } from "../core/auth.gen.js"
4
+ import type { QuerySerializerOptions } from "../core/bodySerializer.gen.js"
5
+ import { jsonBodySerializer } from "../core/bodySerializer.gen.js"
6
+ import { serializeArrayParam, serializeObjectParam, serializePrimitiveParam } from "../core/pathSerializer.gen.js"
7
+ import { getUrl } from "../core/utils.gen.js"
8
+ import type { Client, ClientOptions, Config, RequestOptions } from "./types.gen.js"
9
+
10
+ export const createQuerySerializer = <T = unknown>({ allowReserved, array, object }: QuerySerializerOptions = {}) => {
11
+ const querySerializer = (queryParams: T) => {
12
+ const search: string[] = []
13
+ if (queryParams && typeof queryParams === "object") {
14
+ for (const name in queryParams) {
15
+ const value = queryParams[name]
16
+
17
+ if (value === undefined || value === null) {
18
+ continue
19
+ }
20
+
21
+ if (Array.isArray(value)) {
22
+ const serializedArray = serializeArrayParam({
23
+ allowReserved,
24
+ explode: true,
25
+ name,
26
+ style: "form",
27
+ value,
28
+ ...array,
29
+ })
30
+ if (serializedArray) search.push(serializedArray)
31
+ } else if (typeof value === "object") {
32
+ const serializedObject = serializeObjectParam({
33
+ allowReserved,
34
+ explode: true,
35
+ name,
36
+ style: "deepObject",
37
+ value: value as Record<string, unknown>,
38
+ ...object,
39
+ })
40
+ if (serializedObject) search.push(serializedObject)
41
+ } else {
42
+ const serializedPrimitive = serializePrimitiveParam({
43
+ allowReserved,
44
+ name,
45
+ value: value as string,
46
+ })
47
+ if (serializedPrimitive) search.push(serializedPrimitive)
48
+ }
49
+ }
50
+ }
51
+ return search.join("&")
52
+ }
53
+ return querySerializer
54
+ }
55
+
56
+ /**
57
+ * Infers parseAs value from provided Content-Type header.
58
+ */
59
+ export const getParseAs = (contentType: string | null): Exclude<Config["parseAs"], "auto"> => {
60
+ if (!contentType) {
61
+ // If no Content-Type header is provided, the best we can do is return the raw response body,
62
+ // which is effectively the same as the 'stream' option.
63
+ return "stream"
64
+ }
65
+
66
+ const cleanContent = contentType.split(";")[0]?.trim()
67
+
68
+ if (!cleanContent) {
69
+ return
70
+ }
71
+
72
+ if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) {
73
+ return "json"
74
+ }
75
+
76
+ if (cleanContent === "multipart/form-data") {
77
+ return "formData"
78
+ }
79
+
80
+ if (["application/", "audio/", "image/", "video/"].some((type) => cleanContent.startsWith(type))) {
81
+ return "blob"
82
+ }
83
+
84
+ if (cleanContent.startsWith("text/")) {
85
+ return "text"
86
+ }
87
+
88
+ return
89
+ }
90
+
91
+ const checkForExistence = (
92
+ options: Pick<RequestOptions, "auth" | "query"> & {
93
+ headers: Headers
94
+ },
95
+ name?: string,
96
+ ): boolean => {
97
+ if (!name) {
98
+ return false
99
+ }
100
+ if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) {
101
+ return true
102
+ }
103
+ return false
104
+ }
105
+
106
+ export const setAuthParams = async ({
107
+ security,
108
+ ...options
109
+ }: Pick<Required<RequestOptions>, "security"> &
110
+ Pick<RequestOptions, "auth" | "query"> & {
111
+ headers: Headers
112
+ }) => {
113
+ for (const auth of security) {
114
+ if (checkForExistence(options, auth.name)) {
115
+ continue
116
+ }
117
+
118
+ const token = await getAuthToken(auth, options.auth)
119
+
120
+ if (!token) {
121
+ continue
122
+ }
123
+
124
+ const name = auth.name ?? "Authorization"
125
+
126
+ switch (auth.in) {
127
+ case "query":
128
+ if (!options.query) {
129
+ options.query = {}
130
+ }
131
+ options.query[name] = token
132
+ break
133
+ case "cookie":
134
+ options.headers.append("Cookie", `${name}=${token}`)
135
+ break
136
+ case "header":
137
+ default:
138
+ options.headers.set(name, token)
139
+ break
140
+ }
141
+ }
142
+ }
143
+
144
+ export const buildUrl: Client["buildUrl"] = (options) =>
145
+ getUrl({
146
+ baseUrl: options.baseUrl as string,
147
+ path: options.path,
148
+ query: options.query,
149
+ querySerializer:
150
+ typeof options.querySerializer === "function"
151
+ ? options.querySerializer
152
+ : createQuerySerializer(options.querySerializer),
153
+ url: options.url,
154
+ })
155
+
156
+ export const mergeConfigs = (a: Config, b: Config): Config => {
157
+ const config = { ...a, ...b }
158
+ if (config.baseUrl?.endsWith("/")) {
159
+ config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1)
160
+ }
161
+ config.headers = mergeHeaders(a.headers, b.headers)
162
+ return config
163
+ }
164
+
165
+ export const mergeHeaders = (...headers: Array<Required<Config>["headers"] | undefined>): Headers => {
166
+ const mergedHeaders = new Headers()
167
+ for (const header of headers) {
168
+ if (!header || typeof header !== "object") {
169
+ continue
170
+ }
171
+
172
+ const iterator = header instanceof Headers ? header.entries() : Object.entries(header)
173
+
174
+ for (const [key, value] of iterator) {
175
+ if (value === null) {
176
+ mergedHeaders.delete(key)
177
+ } else if (Array.isArray(value)) {
178
+ for (const v of value) {
179
+ mergedHeaders.append(key, v as string)
180
+ }
181
+ } else if (value !== undefined) {
182
+ // assume object headers are meant to be JSON stringified, i.e. their
183
+ // content value in OpenAPI specification is 'application/json'
184
+ mergedHeaders.set(key, typeof value === "object" ? JSON.stringify(value) : (value as string))
185
+ }
186
+ }
187
+ }
188
+ return mergedHeaders
189
+ }
190
+
191
+ type ErrInterceptor<Err, Res, Req, Options> = (
192
+ error: Err,
193
+ response: Res,
194
+ request: Req,
195
+ options: Options,
196
+ ) => Err | Promise<Err>
197
+
198
+ type ReqInterceptor<Req, Options> = (request: Req, options: Options) => Req | Promise<Req>
199
+
200
+ type ResInterceptor<Res, Req, Options> = (response: Res, request: Req, options: Options) => Res | Promise<Res>
201
+
202
+ class Interceptors<Interceptor> {
203
+ _fns: (Interceptor | null)[]
204
+
205
+ constructor() {
206
+ this._fns = []
207
+ }
208
+
209
+ clear() {
210
+ this._fns = []
211
+ }
212
+
213
+ getInterceptorIndex(id: number | Interceptor): number {
214
+ if (typeof id === "number") {
215
+ return this._fns[id] ? id : -1
216
+ } else {
217
+ return this._fns.indexOf(id)
218
+ }
219
+ }
220
+ exists(id: number | Interceptor) {
221
+ const index = this.getInterceptorIndex(id)
222
+ return !!this._fns[index]
223
+ }
224
+
225
+ eject(id: number | Interceptor) {
226
+ const index = this.getInterceptorIndex(id)
227
+ if (this._fns[index]) {
228
+ this._fns[index] = null
229
+ }
230
+ }
231
+
232
+ update(id: number | Interceptor, fn: Interceptor) {
233
+ const index = this.getInterceptorIndex(id)
234
+ if (this._fns[index]) {
235
+ this._fns[index] = fn
236
+ return id
237
+ } else {
238
+ return false
239
+ }
240
+ }
241
+
242
+ use(fn: Interceptor) {
243
+ this._fns = [...this._fns, fn]
244
+ return this._fns.length - 1
245
+ }
246
+ }
247
+
248
+ // `createInterceptors()` response, meant for external use as it does not
249
+ // expose internals
250
+ export interface Middleware<Req, Res, Err, Options> {
251
+ error: Pick<Interceptors<ErrInterceptor<Err, Res, Req, Options>>, "eject" | "use">
252
+ request: Pick<Interceptors<ReqInterceptor<Req, Options>>, "eject" | "use">
253
+ response: Pick<Interceptors<ResInterceptor<Res, Req, Options>>, "eject" | "use">
254
+ }
255
+
256
+ // do not add `Middleware` as return type so we can use _fns internally
257
+ export const createInterceptors = <Req, Res, Err, Options>() => ({
258
+ error: new Interceptors<ErrInterceptor<Err, Res, Req, Options>>(),
259
+ request: new Interceptors<ReqInterceptor<Req, Options>>(),
260
+ response: new Interceptors<ResInterceptor<Res, Req, Options>>(),
261
+ })
262
+
263
+ const defaultQuerySerializer = createQuerySerializer({
264
+ allowReserved: false,
265
+ array: {
266
+ explode: true,
267
+ style: "form",
268
+ },
269
+ object: {
270
+ explode: true,
271
+ style: "deepObject",
272
+ },
273
+ })
274
+
275
+ const defaultHeaders = {
276
+ "Content-Type": "application/json",
277
+ }
278
+
279
+ export const createConfig = <T extends ClientOptions = ClientOptions>(
280
+ override: Config<Omit<ClientOptions, keyof T> & T> = {},
281
+ ): Config<Omit<ClientOptions, keyof T> & T> => ({
282
+ ...jsonBodySerializer,
283
+ headers: defaultHeaders,
284
+ parseAs: "auto",
285
+ querySerializer: defaultQuerySerializer,
286
+ ...override,
287
+ })
@@ -0,0 +1,22 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+
3
+ import type { ClientOptions } from "./types.gen.js"
4
+ import { type Config, type ClientOptions as DefaultClientOptions, createClient, createConfig } from "./client/index.js"
5
+
6
+ /**
7
+ * The `createClientConfig()` function will be called on client initialization
8
+ * and the returned object will become the client's initial configuration.
9
+ *
10
+ * You may want to initialize your client this way instead of calling
11
+ * `setConfig()`. This is useful for example if you're using Next.js
12
+ * to ensure your client always has the correct values.
13
+ */
14
+ export type CreateClientConfig<T extends DefaultClientOptions = ClientOptions> = (
15
+ override?: Config<DefaultClientOptions & T>,
16
+ ) => Config<Required<DefaultClientOptions> & T>
17
+
18
+ export const client = createClient(
19
+ createConfig<ClientOptions>({
20
+ baseUrl: "http://localhost:4096",
21
+ }),
22
+ )
@@ -0,0 +1,41 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+
3
+ export type AuthToken = string | undefined
4
+
5
+ export interface Auth {
6
+ /**
7
+ * Which part of the request do we use to send the auth?
8
+ *
9
+ * @default 'header'
10
+ */
11
+ in?: "header" | "query" | "cookie"
12
+ /**
13
+ * Header or query parameter name.
14
+ *
15
+ * @default 'Authorization'
16
+ */
17
+ name?: string
18
+ scheme?: "basic" | "bearer"
19
+ type: "apiKey" | "http"
20
+ }
21
+
22
+ export const getAuthToken = async (
23
+ auth: Auth,
24
+ callback: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken,
25
+ ): Promise<string | undefined> => {
26
+ const token = typeof callback === "function" ? await callback(auth) : callback
27
+
28
+ if (!token) {
29
+ return
30
+ }
31
+
32
+ if (auth.scheme === "bearer") {
33
+ return `Bearer ${token}`
34
+ }
35
+
36
+ if (auth.scheme === "basic") {
37
+ return `Basic ${btoa(token)}`
38
+ }
39
+
40
+ return token
41
+ }
@@ -0,0 +1,74 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+
3
+ import type { ArrayStyle, ObjectStyle, SerializerOptions } from "./pathSerializer.gen.js"
4
+
5
+ export type QuerySerializer = (query: Record<string, unknown>) => string
6
+
7
+ export type BodySerializer = (body: any) => any
8
+
9
+ export interface QuerySerializerOptions {
10
+ allowReserved?: boolean
11
+ array?: SerializerOptions<ArrayStyle>
12
+ object?: SerializerOptions<ObjectStyle>
13
+ }
14
+
15
+ const serializeFormDataPair = (data: FormData, key: string, value: unknown): void => {
16
+ if (typeof value === "string" || value instanceof Blob) {
17
+ data.append(key, value)
18
+ } else if (value instanceof Date) {
19
+ data.append(key, value.toISOString())
20
+ } else {
21
+ data.append(key, JSON.stringify(value))
22
+ }
23
+ }
24
+
25
+ const serializeUrlSearchParamsPair = (data: URLSearchParams, key: string, value: unknown): void => {
26
+ if (typeof value === "string") {
27
+ data.append(key, value)
28
+ } else {
29
+ data.append(key, JSON.stringify(value))
30
+ }
31
+ }
32
+
33
+ export const formDataBodySerializer = {
34
+ bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T): FormData => {
35
+ const data = new FormData()
36
+
37
+ Object.entries(body).forEach(([key, value]) => {
38
+ if (value === undefined || value === null) {
39
+ return
40
+ }
41
+ if (Array.isArray(value)) {
42
+ value.forEach((v) => serializeFormDataPair(data, key, v))
43
+ } else {
44
+ serializeFormDataPair(data, key, value)
45
+ }
46
+ })
47
+
48
+ return data
49
+ },
50
+ }
51
+
52
+ export const jsonBodySerializer = {
53
+ bodySerializer: <T>(body: T): string =>
54
+ JSON.stringify(body, (_key, value) => (typeof value === "bigint" ? value.toString() : value)),
55
+ }
56
+
57
+ export const urlSearchParamsBodySerializer = {
58
+ bodySerializer: <T extends Record<string, any> | Array<Record<string, any>>>(body: T): string => {
59
+ const data = new URLSearchParams()
60
+
61
+ Object.entries(body).forEach(([key, value]) => {
62
+ if (value === undefined || value === null) {
63
+ return
64
+ }
65
+ if (Array.isArray(value)) {
66
+ value.forEach((v) => serializeUrlSearchParamsPair(data, key, v))
67
+ } else {
68
+ serializeUrlSearchParamsPair(data, key, value)
69
+ }
70
+ })
71
+
72
+ return data.toString()
73
+ },
74
+ }
@@ -0,0 +1,144 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+
3
+ type Slot = "body" | "headers" | "path" | "query"
4
+
5
+ export type Field =
6
+ | {
7
+ in: Exclude<Slot, "body">
8
+ /**
9
+ * Field name. This is the name we want the user to see and use.
10
+ */
11
+ key: string
12
+ /**
13
+ * Field mapped name. This is the name we want to use in the request.
14
+ * If omitted, we use the same value as `key`.
15
+ */
16
+ map?: string
17
+ }
18
+ | {
19
+ in: Extract<Slot, "body">
20
+ /**
21
+ * Key isn't required for bodies.
22
+ */
23
+ key?: string
24
+ map?: string
25
+ }
26
+
27
+ export interface Fields {
28
+ allowExtra?: Partial<Record<Slot, boolean>>
29
+ args?: ReadonlyArray<Field>
30
+ }
31
+
32
+ export type FieldsConfig = ReadonlyArray<Field | Fields>
33
+
34
+ const extraPrefixesMap: Record<string, Slot> = {
35
+ $body_: "body",
36
+ $headers_: "headers",
37
+ $path_: "path",
38
+ $query_: "query",
39
+ }
40
+ const extraPrefixes = Object.entries(extraPrefixesMap)
41
+
42
+ type KeyMap = Map<
43
+ string,
44
+ {
45
+ in: Slot
46
+ map?: string
47
+ }
48
+ >
49
+
50
+ const buildKeyMap = (fields: FieldsConfig, map?: KeyMap): KeyMap => {
51
+ if (!map) {
52
+ map = new Map()
53
+ }
54
+
55
+ for (const config of fields) {
56
+ if ("in" in config) {
57
+ if (config.key) {
58
+ map.set(config.key, {
59
+ in: config.in,
60
+ map: config.map,
61
+ })
62
+ }
63
+ } else if (config.args) {
64
+ buildKeyMap(config.args, map)
65
+ }
66
+ }
67
+
68
+ return map
69
+ }
70
+
71
+ interface Params {
72
+ body: unknown
73
+ headers: Record<string, unknown>
74
+ path: Record<string, unknown>
75
+ query: Record<string, unknown>
76
+ }
77
+
78
+ const stripEmptySlots = (params: Params) => {
79
+ for (const [slot, value] of Object.entries(params)) {
80
+ if (value && typeof value === "object" && !Object.keys(value).length) {
81
+ delete params[slot as Slot]
82
+ }
83
+ }
84
+ }
85
+
86
+ export const buildClientParams = (args: ReadonlyArray<unknown>, fields: FieldsConfig) => {
87
+ const params: Params = {
88
+ body: {},
89
+ headers: {},
90
+ path: {},
91
+ query: {},
92
+ }
93
+
94
+ const map = buildKeyMap(fields)
95
+
96
+ let config: FieldsConfig[number] | undefined
97
+
98
+ for (const [index, arg] of args.entries()) {
99
+ if (fields[index]) {
100
+ config = fields[index]
101
+ }
102
+
103
+ if (!config) {
104
+ continue
105
+ }
106
+
107
+ if ("in" in config) {
108
+ if (config.key) {
109
+ const field = map.get(config.key)!
110
+ const name = field.map || config.key
111
+ ;(params[field.in] as Record<string, unknown>)[name] = arg
112
+ } else {
113
+ params.body = arg
114
+ }
115
+ } else {
116
+ for (const [key, value] of Object.entries(arg ?? {})) {
117
+ const field = map.get(key)
118
+
119
+ if (field) {
120
+ const name = field.map || key
121
+ ;(params[field.in] as Record<string, unknown>)[name] = value
122
+ } else {
123
+ const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix))
124
+
125
+ if (extra) {
126
+ const [prefix, slot] = extra
127
+ ;(params[slot] as Record<string, unknown>)[key.slice(prefix.length)] = value
128
+ } else {
129
+ for (const [slot, allowed] of Object.entries(config.allowExtra ?? {})) {
130
+ if (allowed) {
131
+ ;(params[slot as Slot] as Record<string, unknown>)[key] = value
132
+ break
133
+ }
134
+ }
135
+ }
136
+ }
137
+ }
138
+ }
139
+ }
140
+
141
+ stripEmptySlots(params)
142
+
143
+ return params
144
+ }