forked from NangoHQ/nango
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.d.ts
212 lines (189 loc) · 4.59 KB
/
types.d.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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import { Request } from 'express'
import { TWithInstrument } from './instrumentation/middleware'
import { Integration } from './legacy/functions/integration'
import { AuthDetails } from './legacy/auth/v3/types'
import Knex from 'knex'
import { BodyFormat } from './legacy/auth/clients/oauth2'
export type Omit<T, K> = Pick<T, Exclude<keyof T, K>>
export interface IntegrationServiceRequest extends Request {
environmentIdentifier: string
organizationIdentifier: string
}
export type TRequest = Request & {
clientId: string
authId: string
organizationIdentifier?: any
environmentIdentifier?: any
bearerOverhead?: number
} & TWithInstrument
export type TServerResponse = {
data: {
data: {
organization?: {
identifier?: string
id: string
clientId: string
user?: {
auth0uuid: string
}
}
errors?: {
field: string
messages: string[]
}
}
}
}
export type TBackendRequestV4 = TRequest & {
userId: string
authId: string
auth: any
bearerResponse: {
StatusCode: number
Payload: any
}
userDefinedData: any
functionArn?: string
organizationIdentifier?: any
environmentIdentifier?: any
isBackend: string
setupId: string
integration: Integration
functionName: string
internalCorrelationId?: string
userCorrelationId?: string
fullLogs: boolean
}
type TRequestLog = {
endedAt?: number
duration?: number
} & TRequest
export type TIdentifiersRequest = Request & {
clientId: string
environmentIdentifier: string
organizationIdentifier: string
buid?: string
uuid?: string
alias?: string
webhookConfig?: any
fullLogs?: boolean
}
/**********************/
declare global {
namespace Express {
export interface Request {
store?: Knex
}
}
}
export namespace Types {
export interface Integration<Config = OAuth2Config | OAuth1Config> {
id: string
image: string
name: string
// TODO - Type the config (and rename config to auth?)
auth: Config
request: {
baseURL: string
headers?: { [key: string]: string }
params?: { [key: string]: string }
}
}
type OAuth2Config = {
authorizationMethod: AuthorizationMethod
authorizationParams: Record<string, string> //{ prompt: 'consent'; access_type: 'offline' }
authorizationURL: string
authType: 'OAUTH2'
bodyFormat: BodyFormat
config: {
response_type: 'code'
scope: string[]
}
idToken?: string // TODO explain how it is possible to have this in the config
hint: string
provider: string
refreshURL?: string
setupKeyLabel?: string
setupSecretLabel?: string
tokenParams: {
grant_type: 'authorization_code' | 'client_credentials'
}
tokenURL: string
}
type OAuth1Config = {
accessTokenURL: string
authorizationParams: Record<string, string> //{ "expiration": "never" },
authType: 'OAUTH1'
callbackURL: string
config: Record<string, string> //{ "scope": ["read"] },
hint: string
provider: string
requestTokenURL: string
setupKeyLabel?: string
setupSecretLabel?: string
signatureMethod: 'HMAC-SHA1' | 'PLAINTEXT' | 'RSA-SHA1'
tokenParams: {}
userAuthorizationURL: string
}
export interface OAuth2Credentials {
clientId: string
clientSecret: string
}
export interface OAuth1Credentials {
consumerKey: string
consumerSecret: string
}
export interface Configuration {
object: string
id: string
setup_id: string
scopes: string[]
credentials: OAuth1Credentials | OAuth2Credentials
createdAt?: string
modifiedAt?: string
}
export interface Authentication {
object: string
id: string
auth_id: string
setup_id: string
payload: OAuthPayload
created_at: string
updated_at: string
}
/**
* OAuth payload types
*/
enum AuthType {
NoAuth = 'NO_AUTH',
OAuth1 = 'OAUTH1',
OAuth2 = 'OAUTH2'
}
interface CommonOAuthPayload {
serviceName: string
userId: string
updatedAt: number
setupId: string
scopes?: any
tokenResponseJSON?: string
callbackParamsJSON?: string
connectParams?: any
}
export interface OAuth1Payload extends CommonOAuthPayload {
accessToken: string
tokenSecret: string
consumerKey?: string
consumerSecret?: string
expiresIn: number
}
export interface OAuth2Payload extends CommonOAuthPayload {
accessToken: string
refreshToken?: string
clientId?: string
clientSecret?: string
expiresIn?: number
idToken?: string
idTokenJwt?: any
}
type OAuthPayload = OAuth1Payload | OAuth2Payload
}