Skip to content

Commit 28a3695

Browse files
committed
feat: add conditional types to createKindeServerClient to select the type of options and client
1 parent fec06d5 commit 28a3695

File tree

4 files changed

+16
-26
lines changed

4 files changed

+16
-26
lines changed

README.md

+5-10
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ import {
7979
createKindeServerClient,
8080
GrantType,
8181
type ACClientOptions,
82-
type ACClient,
8382
} from "@kinde-oss/kinde-typescript-sdk";
8483

8584
const clientOptions: ACClientOptions = {
@@ -90,7 +89,7 @@ const clientOptions: ACClientOptions = {
9089
redirectURL: process.env.KINDE_REDIRECT_URL
9190
};
9291

93-
const client = createKindeServerClient<ACClient, ACClientOptions>(
92+
const client = createKindeServerClient(
9493
GrantType.AUTHORIZATION_CODE, clientOptions
9594
);
9695
```
@@ -101,7 +100,6 @@ import {
101100
createKindeServerClient,
102101
GrantType,
103102
type PKCEClientOptions,
104-
type ACClient,
105103
} from "@kinde-oss/kinde-typescript-sdk";
106104

107105
const clientOptions: PKCEClientOptions = {
@@ -111,7 +109,7 @@ const clientOptions: PKCEClientOptions = {
111109
redirectURL: process.env.KINDE_REDIRECT_URL
112110
};
113111

114-
const client = createKindeServerClient<ACClient, PKCEClientOptions>(
112+
const client = createKindeServerClient(
115113
GrantType.PKCE, clientOptions
116114
);
117115
```
@@ -122,7 +120,6 @@ import {
122120
createKindeServerClient,
123121
GrantType,
124122
type CCClientOptions,
125-
type CCClient,
126123
} from "@kinde-oss/kinde-typescript-sdk";
127124

128125
const clientOptions: CCClientOptions = {
@@ -132,7 +129,7 @@ const clientOptions: CCClientOptions = {
132129
logoutRedirectURL: process.env.KINDE_LOGOUT_REDIRECT_URL
133130
};
134131

135-
const client = createKindeServerClient<CCClient, CCClientOptions>(
132+
const client = createKindeServerClient(
136133
GrantType.CLIENT_CREDENTIALS, clientOptions
137134
)
138135
```
@@ -181,7 +178,6 @@ import {
181178
createKindeServerClient,
182179
GrantType,
183180
type ACClientOptions,
184-
type ACClient,
185181
} from "@kinde-oss/kinde-typescript-sdk";
186182

187183
const clientOptions: ACClientOptions = {
@@ -194,7 +190,7 @@ const clientOptions: ACClientOptions = {
194190
audience: 'api.example.com/v1'
195191
};
196192

197-
const client = createKindeServerClient<ACClient, ACClientOptions>(
193+
const client = createKindeServerClient(
198194
GrantType.AUTHORIZATION_CODE, clientOptions
199195
);
200196
```
@@ -230,7 +226,6 @@ import {
230226
createKindeServerClient,
231227
GrantType,
232228
type ACClientOptions,
233-
type ACClient,
234229
} from "@kinde-oss/kinde-typescript-sdk";
235230

236231
const clientOptions: ACClientOptions = {
@@ -243,7 +238,7 @@ const clientOptions: ACClientOptions = {
243238
framework: 'ExpressJS'
244239
};
245240

246-
const client = createKindeServerClient<ACClient, ACClientOptions>(
241+
const client = createKindeServerClient(
247242
GrantType.AUTHORIZATION_CODE, clientOptions
248243
);
249244
```

lib/apis/RolesApi.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ export interface DeleteRoleRequest {
5353

5454
export interface GetRolePermissionRequest {
5555
roleId: string;
56-
permissionId: string;
5756
sort?: GetRolePermissionSortEnum;
5857
pageSize?: number | null;
5958
nextToken?: string | null;
@@ -173,10 +172,6 @@ export class RolesApi extends runtime.BaseAPI {
173172
throw new runtime.RequiredError('roleId','Required parameter requestParameters.roleId was null or undefined when calling getRolePermission.');
174173
}
175174

176-
if (requestParameters.permissionId === null || requestParameters.permissionId === undefined) {
177-
throw new runtime.RequiredError('permissionId','Required parameter requestParameters.permissionId was null or undefined when calling getRolePermission.');
178-
}
179-
180175
const queryParameters: any = {};
181176

182177
if (requestParameters.sort !== undefined) {
@@ -202,7 +197,7 @@ export class RolesApi extends runtime.BaseAPI {
202197
}
203198
}
204199
const response = await this.request({
205-
path: `/api/v1/roles/{role_id}/permission/{permission_id}`.replace(`{${"role_id"}}`, encodeURIComponent(String(requestParameters.roleId))).replace(`{${"permission_id"}}`, encodeURIComponent(String(requestParameters.permissionId))),
200+
path: `/api/v1/roles/{role_id}/permissions`.replace(`{${"role_id"}}`, encodeURIComponent(String(requestParameters.roleId))),
206201
method: 'GET',
207202
headers: headerParameters,
208203
query: queryParameters,

lib/sdk/clients/server/index.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import type {
1111
CCClientOptions,
1212
} from '../types';
1313

14-
export const createKindeServerClient = <
15-
C extends ACClient | CCClient,
16-
O extends ACClientOptions | PKCEClientOptions | CCClientOptions
17-
>(
18-
grantType: GrantType,
19-
options: O
14+
type Options<T> = T extends GrantType.PKCE ? PKCEClientOptions : T extends GrantType.AUTHORIZATION_CODE ? ACClientOptions : T extends GrantType.CLIENT_CREDENTIALS ? CCClientOptions : never;
15+
type Client<T> = T extends PKCEClientOptions ? ACClient : T extends ACClientOptions ? ACClient : T extends CCClientOptions ? CCClient : never;
16+
17+
export const createKindeServerClient = <G extends GrantType>(
18+
grantType: G,
19+
options: Options<G>
2020
) => {
2121
if (!isNodeEnvironment()) {
2222
throw new Error('this method must be invoked in a node.js environment');
@@ -25,15 +25,15 @@ export const createKindeServerClient = <
2525
switch (grantType) {
2626
case GrantType.AUTHORIZATION_CODE: {
2727
const clientOptions = options as ACClientOptions;
28-
return createAuthCodeClient(clientOptions, false) as C;
28+
return createAuthCodeClient(clientOptions, false) as Client<Options<G>>;
2929
}
3030
case GrantType.PKCE: {
3131
const clientOptions = options as PKCEClientOptions;
32-
return createAuthCodeClient(clientOptions, true) as C;
32+
return createAuthCodeClient(clientOptions, true) as Client<Options<G>>;
3333
}
3434
case GrantType.CLIENT_CREDENTIALS: {
3535
const clientOptions = options as CCClientOptions;
36-
return createCCClient(clientOptions) as C;
36+
return createCCClient(clientOptions) as Client<Options<G>>;
3737
}
3838
default: {
3939
throw new Error('Unrecognized grant type provided');

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kinde-oss/kinde-typescript-sdk",
3-
"version": "2.0.0",
3+
"version": "2.1.0",
44
"description": "Kinde Typescript SDK",
55
"main": "dist-cjs/index.js",
66
"module": "dist/index.js",

0 commit comments

Comments
 (0)