@socketsecurity/sdk 1.11.2 → 2.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.
@@ -1,61 +1,69 @@
1
1
  /**
2
- * @fileoverview TypeScript type helpers for OpenAPI operation responses.
3
- * Utility types for extracting return types and error types from OpenAPI operations.
4
- * Based on openapi-typescript-fetch patterns.
2
+ * @fileoverview Helper types for working with generated OpenAPI types.
5
3
  */
6
- declare type ValueOf<
7
- ObjectType,
8
- ValueType extends keyof ObjectType = keyof ObjectType,
9
- > = ObjectType[ValueType]
10
4
 
11
- // Based on openapi-typescript-fetch.
12
- // https://socket.dev/npm/package/openapi-typescript-fetch/overview/2.2.1
13
- // MIT License
14
- // Copyright 2021 Ajai Shankar
15
- declare type Coalesce<T, D> = [T] extends [never] ? D : T
16
-
17
- declare type OpResponseTypes<OP> = OP extends {
18
- responses: infer R
5
+ /**
6
+ * Extract the successful response type from an operation.
7
+ * Maps to the data property of the success result.
8
+ */
9
+ export type OpReturnType<T> = T extends {
10
+ responses: {
11
+ 200?: { content?: { 'application/json': infer U } }
12
+ }
19
13
  }
20
- ? {
21
- [S in keyof R]: R[S] extends {
22
- schema?: infer S
14
+ ? U
15
+ : T extends {
16
+ responses: {
17
+ 201?: { content?: { 'application/json': infer U } }
18
+ }
23
19
  }
24
- ? S
25
- : R[S] extends {
26
- content: {
27
- 'application/json': infer C
28
- }
29
- }
30
- ? C
31
- : S extends 'default'
32
- ? R[S]
33
- : unknown
34
- }
35
- : never
36
-
37
- declare type _OpReturnType<T> = 200 extends keyof T
38
- ? T[200]
39
- : 201 extends keyof T
40
- ? T[201]
41
- : 'default' extends keyof T
42
- ? T['default']
20
+ ? U
21
+ : T extends {
22
+ responses: {
23
+ 204?: unknown
24
+ }
25
+ }
26
+ ? undefined
43
27
  : unknown
44
28
 
45
- declare type _OpErrorType<T> = {
46
- [S in Exclude<keyof T, 200 | 201>]: T[S] & {
47
- success: false
48
- status: S extends 'default' ? never : S
49
- }
50
- }
51
-
52
- export declare type OpReturnType<OP> = {
53
- success: true
54
- status: 200
55
- data: _OpReturnType<OpResponseTypes<OP>>
29
+ /**
30
+ * Extract the error response type from an operation.
31
+ * Maps to the error structure of the error result.
32
+ */
33
+ export type OpErrorType<T> = T extends {
34
+ responses: infer R
56
35
  }
57
-
58
- type OpErrorType<OP> = Coalesce<
59
- ValueOf<_OpErrorType<OpResponseTypes<OP>>>,
60
- { success: false; status: number }
61
- >
36
+ ? R extends Record<string | number, unknown>
37
+ ? {
38
+ [K in keyof R as K extends
39
+ | 400
40
+ | 401
41
+ | 403
42
+ | 404
43
+ | 409
44
+ | 422
45
+ | 429
46
+ | 500
47
+ | 502
48
+ | 503
49
+ ? K
50
+ : never]: R[K]
51
+ }[keyof {
52
+ [K in keyof R as K extends
53
+ | 400
54
+ | 401
55
+ | 403
56
+ | 404
57
+ | 409
58
+ | 422
59
+ | 429
60
+ | 500
61
+ | 502
62
+ | 503
63
+ ? K
64
+ : never]: R[K]
65
+ }] extends { content?: { 'application/json': infer E } }
66
+ ? E
67
+ : { error?: string }
68
+ : { error?: string }
69
+ : { error?: string }