1
- import type { AxiosRequestConfig } from 'axios'
1
+ import type { Method } from 'axios'
2
2
3
3
import type { Client } from './client.js'
4
4
import { SeamHttpActionAttempts } from './index.js'
@@ -10,6 +10,13 @@ export interface SeamHttpRequestParent {
10
10
readonly defaults : Required < SeamHttpRequestOptions >
11
11
}
12
12
13
+ export interface SeamHttpRequestConfig < TBody > {
14
+ url ?: string
15
+ method ?: Method
16
+ params ?: any
17
+ data ?: TBody
18
+ }
19
+
13
20
export type ResponseFromSeamHttpRequest < T > =
14
21
T extends SeamHttpRequest < any , infer TResponse , infer TResourceKey >
15
22
? TResourceKey extends keyof TResponse
@@ -27,27 +34,39 @@ export class SeamHttpRequest<
27
34
>
28
35
{
29
36
readonly parent : SeamHttpRequestParent
30
- readonly requestConfig : AxiosRequestConfig < TBody >
37
+ readonly config : SeamHttpRequestConfig < TBody >
31
38
readonly resourceKey : TResourceKey
32
39
readonly options : Pick < SeamHttpRequestOptions , 'waitForActionAttempt' >
33
40
34
41
constructor (
35
42
parent : SeamHttpRequestParent ,
36
- requestConfig : AxiosRequestConfig < TBody > ,
43
+ config : SeamHttpRequestConfig < TBody > ,
37
44
resourceKey : TResourceKey ,
38
45
options : Pick < SeamHttpRequestOptions , 'waitForActionAttempt' > = { } ,
39
46
) {
40
47
this . parent = parent
41
- this . requestConfig = requestConfig
48
+ this . config = config
42
49
this . resourceKey = resourceKey
43
50
this . options = options
44
51
}
45
52
53
+ public get url ( ) : string {
54
+ return this . config . url ?? ''
55
+ }
56
+
57
+ public get method ( ) : Method {
58
+ return this . config . method ?? 'get'
59
+ }
60
+
61
+ public get data ( ) : TBody {
62
+ return this . config . data as TBody
63
+ }
64
+
46
65
async execute ( ) : Promise <
47
66
TResourceKey extends keyof TResponse ? TResponse [ TResourceKey ] : undefined
48
67
> {
49
68
const { client } = this . parent
50
- const response = await client . request ( this . requestConfig )
69
+ const response = await client . request ( this . config )
51
70
if ( this . resourceKey === undefined ) {
52
71
return undefined as TResourceKey extends keyof TResponse
53
72
? TResponse [ TResourceKey ]
0 commit comments