-
Notifications
You must be signed in to change notification settings - Fork 448
Expand file tree
/
Copy pathJwtTemplatesApi.ts
More file actions
95 lines (82 loc) · 2.34 KB
/
JwtTemplatesApi.ts
File metadata and controls
95 lines (82 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import type { ClerkPaginationRequest } from '@clerk/shared/types';
import { joinPaths } from '../../util/path';
import type { DeletedObject, JwtTemplate } from '../resources';
import type { PaginatedResourceResponse } from '../resources/Deserializer';
import { AbstractAPI } from './AbstractApi';
const basePath = '/jwt_templates';
type Claims = object;
type CreateJWTTemplateParams = {
/**
* JWT template name
*/
name: string;
/**
* JWT template claims in JSON format
*/
claims: Claims;
/**
* JWT token lifetime
*/
lifetime?: number | null | undefined;
/**
* JWT token allowed clock skew
*/
allowedClockSkew?: number | null | undefined;
/**
* Whether a custom signing key/algorithm is also provided for this template
*/
customSigningKey?: boolean | undefined;
/**
* The custom signing algorithm to use when minting JWTs. Required if `custom_signing_key` is `true`.
*/
signingAlgorithm?: string | null | undefined;
/**
* The custom signing private key to use when minting JWTs. Required if `custom_signing_key` is `true`.
*/
signingKey?: string | null | undefined;
};
type UpdateJWTTemplateParams = CreateJWTTemplateParams & {
/**
* JWT template ID
*/
templateId: string;
};
export class JwtTemplatesApi extends AbstractAPI {
public async list(params: ClerkPaginationRequest = {}) {
return this.request<PaginatedResourceResponse<JwtTemplate[]>>({
method: 'GET',
path: basePath,
queryParams: { ...params, paginated: true },
});
}
public async get(templateId: string) {
this.requireId(templateId);
return this.request<JwtTemplate>({
method: 'GET',
path: joinPaths(basePath, templateId),
});
}
public async create(params: CreateJWTTemplateParams) {
return this.request<JwtTemplate>({
method: 'POST',
path: basePath,
bodyParams: params,
});
}
public async update(params: UpdateJWTTemplateParams) {
const { templateId, ...bodyParams } = params;
this.requireId(templateId);
return this.request<JwtTemplate>({
method: 'PATCH',
path: joinPaths(basePath, templateId),
bodyParams,
});
}
public async delete(templateId: string) {
this.requireId(templateId);
return this.request<DeletedObject>({
method: 'DELETE',
path: joinPaths(basePath, templateId),
});
}
}