@@ -29,39 +29,37 @@ type RevokeMachineTokenParams = WithMachineTokenSecret<{
29
29
} > ;
30
30
31
31
export class MachineTokensApi extends AbstractAPI {
32
- /**
33
- * Attaches the machine token secret as an Authorization header if present.
34
- */
35
- #withMachineTokenSecretHeader< T extends WithMachineTokenSecret < unknown > > (
32
+ #withMachineTokenSecretHeader(
36
33
options : ClerkBackendApiRequestOptions ,
37
- params : T ,
34
+ machineTokenSecret ?: string | null ,
38
35
) : ClerkBackendApiRequestOptions {
39
- if ( params . machineTokenSecret ) {
36
+ if ( machineTokenSecret ) {
40
37
return {
41
38
...options ,
42
39
headerParams : {
43
- Authorization : `Bearer ${ params . machineTokenSecret } ` ,
40
+ Authorization : `Bearer ${ machineTokenSecret } ` ,
44
41
} ,
45
42
} ;
46
43
}
47
44
return options ;
48
45
}
49
46
50
47
async create ( params : CreateMachineTokenParams ) {
48
+ const { machineTokenSecret, ...bodyParams } = params ;
51
49
return this . request < MachineToken > (
52
50
this . #withMachineTokenSecretHeader(
53
51
{
54
52
method : 'POST' ,
55
53
path : basePath ,
56
- bodyParams : params ,
54
+ bodyParams,
57
55
} ,
58
- params ,
56
+ machineTokenSecret ,
59
57
) ,
60
58
) ;
61
59
}
62
60
63
61
async update ( params : UpdateMachineTokenParams ) {
64
- const { m2mTokenId, ...bodyParams } = params ;
62
+ const { m2mTokenId, machineTokenSecret , ...bodyParams } = params ;
65
63
this . requireId ( m2mTokenId ) ;
66
64
return this . request < MachineToken > (
67
65
this . #withMachineTokenSecretHeader(
@@ -70,13 +68,13 @@ export class MachineTokensApi extends AbstractAPI {
70
68
path : joinPaths ( basePath , m2mTokenId ) ,
71
69
bodyParams,
72
70
} ,
73
- params ,
71
+ machineTokenSecret ,
74
72
) ,
75
73
) ;
76
74
}
77
75
78
76
async revoke ( params : RevokeMachineTokenParams ) {
79
- const { m2mTokenId, ...bodyParams } = params ;
77
+ const { m2mTokenId, machineTokenSecret , ...bodyParams } = params ;
80
78
this . requireId ( m2mTokenId ) ;
81
79
return this . request < MachineToken > (
82
80
this . #withMachineTokenSecretHeader(
@@ -85,7 +83,7 @@ export class MachineTokensApi extends AbstractAPI {
85
83
path : joinPaths ( basePath , m2mTokenId , 'revoke' ) ,
86
84
bodyParams,
87
85
} ,
88
- params ,
86
+ machineTokenSecret ,
89
87
) ,
90
88
) ;
91
89
}
0 commit comments