-
Notifications
You must be signed in to change notification settings - Fork 12
/
plugin-types.d.ts
169 lines (145 loc) · 4.93 KB
/
plugin-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
import {
IPBReq,
IPBApp,
IPBUser,
IFormRequest,
IBotComponents,
IConfComponents,
ResourceStub,
ITradleCheck,
ITradleObject,
Registry,
Logger,
Bot,
Applications
} from './types'
declare namespace PluginLifecycle {
// synchronous, attach conditioned on handleMessages
export type onmessage = (req:IPBReq) => boolean|void | Promise<boolean|void>
export type willSend = (opts:IWillSendArg) => void | Promise<void>
export type willRequestForm = (opts:IWillRequestFormArg) => void | Promise<void>
export type willApproveApplication = (opts:IWillJudgeAppArg) => void | Promise<void>
export type didApproveApplication = (opts:IWillJudgeAppArg, signedObject: ITradleObject) => void | Promise<void>
export type willIssueCertificate = (opts:WillIssueCertificateArg) => void | Promise<void>
export type willDenyApplication = (opts:IWillJudgeAppArg) => void | Promise<void>
export type onFormsCollected = (opts:IOnFormsCollectedArg) => void | Promise<void>
export type onPendingApplicationCollision = (opts:IOnPendingApplicationCollisionArg) => void | Promise<void>
export type onRequestForExistingProduct = (req:IPBReq) => void | Promise<void>
export type onCommand = ({ req: IPBReq, command: string }) => void | Promise<void>
export type getRequiredForms = (opts: IGetRequiredFormsArg) => Promise<void|string[]>
export type validateForm = (opts: IValidateFormArg) => Promise<void|IValidateFormOutput>
export type replay = (obj: ITradleObject, applications: Applications) => Promise<void>
// asynchronous, attach conditioned on runAsyncHandlers
export type onCheckStatusChanged = (check: ITradleCheck) => Promise<void>
export type onResourceChanged = (opts: OnResourceChangedArg) => Promise<void>
export type onResourceCreated = (obj: ITradleObject) => Promise<void>
export type onResourceDeleted = (obj: ITradleObject) => Promise<void>
export interface Methods {
onmessage?: onmessage
willSend?: willSend
willRequestForm?: willRequestForm
willApproveApplication?: willApproveApplication
willIssueCertificate?: willIssueCertificate
didApproveApplication?: didApproveApplication
willDenyApplication?: willDenyApplication
onFormsCollected?: onFormsCollected
onPendingApplicationCollision?: onPendingApplicationCollision
onRequestForExistingProduct?: onRequestForExistingProduct
onCommand?: onCommand
getRequiredForms?: getRequiredForms
validateForm?: validateForm
replay?: replay
onCheckStatusChanged?: onCheckStatusChanged
onResourceChanged?: onResourceChanged
onResourceCreated?: onResourceCreated
onResourceDeleted?: onResourceDeleted
[toBeDefined: string]: any
}
}
interface MayHaveReq {
req?: IPBReq
}
interface MayHaveReqAndApp extends MayHaveReq {
application?: IPBApp
}
export interface IWillSendArg extends MayHaveReqAndApp {
to: string|IPBUser
object?: ITradleObject
link?: string
}
export interface IWillRequestFormArg extends MayHaveReqAndApp {
user: IPBUser
formRequest: IFormRequest
}
export interface IWillJudgeAppArg extends MayHaveReq {
user: IPBUser
application: IPBApp
judge?: IPBUser
}
export interface IOnFormsCollectedArg {
req: IPBReq
user: IPBUser
application: IPBApp
}
export interface IOnPendingApplicationCollisionArg {
req: IPBReq
pending: ResourceStub[]
}
export interface IGetRequiredFormsArg {
user: IPBUser
application: IPBApp
productModel: any
req?: IPBApp
}
export interface OnResourceChangedArg {
old: ITradleObject
value: ITradleObject
}
export interface IValidateFormArg extends MayHaveReqAndApp {
form: ITradleObject
}
type ValidationError = {
name: string
message?: string
}
export interface IValidateFormOutput {
message: string
// e.g. if you want to dynamically request more properties based on input
requestedProperties?: ValidationError[]
// if the user entered some invalid values
errors?: ValidationError[]
}
export interface WillIssueCertificateArg {
req: IPBReq
user: IPBUser
application: IPBApp
certificate: ITradleObject
judge: IPBUser
}
export interface IPluginExports<BotComponent> {
plugin: PluginLifecycle.Methods
api?: BotComponent
[customExport: string]: any
}
export interface IPluginOpts {
logger: Logger
conf?: any
}
export type CreatePlugin<BotComponent> = (components:IBotComponents, opts:IPluginOpts) => IPluginExports<BotComponent>
export type ValidatePluginConfOpts = {
bot: Bot
conf: IConfComponents
pluginConf: any
[other:string]: any
}
export type UpdatePluginConfOpts = ValidatePluginConfOpts
export type ValidatePluginConf = (opts:ValidatePluginConfOpts) => Promise<void>
export type UpdatePluginConf = (opts:UpdatePluginConfOpts) => Promise<void>
export interface IPlugin<BotComponent> {
name?: string
createPlugin: CreatePlugin<BotComponent>
validateConf?: ValidatePluginConf
updateConf?: UpdatePluginConf
}
export type IPlugins = Registry<IPlugin<any>>
export interface IPluginLifecycleMethods extends PluginLifecycle.Methods {}