-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathgrant.ts
47 lines (43 loc) · 986 Bytes
/
grant.ts
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
import { HttpMethod } from 'openapi'
import { RouteDeps } from '.'
import {
getASPath,
InteractiveGrant,
NonInteractiveGrant,
GrantRequest
} from '../types'
import { post } from './requests'
export interface GrantRouteDeps extends RouteDeps {
client: string
}
interface RequestGrantArgs {
url: string
request: Omit<GrantRequest, 'client'>
}
export interface GrantRoutes {
request(
args: RequestGrantArgs
): Promise<InteractiveGrant | NonInteractiveGrant>
}
export const createGrantRoutes = (deps: GrantRouteDeps): GrantRoutes => {
const requestGrantValidator = deps.openApi.createResponseValidator<
InteractiveGrant | NonInteractiveGrant
>({
path: getASPath('/'),
method: HttpMethod.POST
})
return {
request: (args: RequestGrantArgs) =>
post(
deps,
{
url: args.url,
body: {
...args,
client: deps.client
}
},
requestGrantValidator
)
}
}