@botpress/sdk 4.21.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +5 -5
- package/dist/bot/definition.d.ts +45 -7
- package/dist/bot/server/types.d.ts +2 -5
- package/dist/bot/workflow-proxy/proxy.d.ts +7 -3
- package/dist/bot/workflow-proxy/types.d.ts +24 -23
- package/dist/common/index.d.ts +1 -0
- package/dist/common/types.d.ts +2 -0
- package/dist/fixtures.d.ts +84 -13
- package/dist/index.cjs +41 -38
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +33 -30
- package/dist/index.mjs.map +4 -4
- package/dist/integration/client/types.d.ts +15 -14
- package/dist/integration/common/index.d.ts +0 -1
- package/dist/integration/server/types.d.ts +8 -7
- package/dist/plugin/common/generic.d.ts +12 -0
- package/dist/plugin/common/types.d.ts +17 -5
- package/dist/plugin/conversation-proxy/index.d.ts +2 -0
- package/dist/plugin/conversation-proxy/proxy.d.ts +13 -0
- package/dist/plugin/conversation-proxy/types.d.ts +54 -0
- package/dist/plugin/conversation-proxy/types.test.d.ts +1 -0
- package/dist/plugin/definition.d.ts +1 -1
- package/dist/plugin/event-proxy/proxy.d.ts +2 -2
- package/dist/plugin/event-proxy/types.d.ts +11 -6
- package/dist/plugin/implementation.d.ts +4 -4
- package/dist/plugin/message-proxy/index.d.ts +2 -0
- package/dist/plugin/message-proxy/proxy.d.ts +13 -0
- package/dist/plugin/message-proxy/types.d.ts +22 -0
- package/dist/plugin/server/types.d.ts +129 -51
- package/dist/plugin/tag-prefixer.d.ts +10 -0
- package/dist/plugin/tag-prefixer.test.d.ts +1 -0
- package/dist/plugin/user-proxy/index.d.ts +2 -0
- package/dist/plugin/user-proxy/proxy.d.ts +14 -0
- package/dist/plugin/user-proxy/types.d.ts +30 -0
- package/dist/utils/api-paging-utils.d.ts +43 -0
- package/dist/utils/api-paging-utils.test.d.ts +1 -0
- package/dist/utils/type-utils.d.ts +1 -0
- package/package.json +1 -1
- package/dist/integration/common/types.d.ts +0 -2
- package/dist/plugin/interface-resolution.d.ts +0 -15
|
@@ -4,8 +4,11 @@ import * as workflowProxy from '../../bot/workflow-proxy';
|
|
|
4
4
|
import * as utils from '../../utils/type-utils';
|
|
5
5
|
import * as actionProxy from '../action-proxy';
|
|
6
6
|
import * as common from '../common';
|
|
7
|
+
import * as conversationProxy from '../conversation-proxy';
|
|
7
8
|
import * as eventProxy from '../event-proxy';
|
|
9
|
+
import * as messageProxy from '../message-proxy';
|
|
8
10
|
import * as stateProxy from '../state-proxy';
|
|
11
|
+
import * as userProxy from '../user-proxy';
|
|
9
12
|
type EnumeratePluginEvents<TPlugin extends common.BasePlugin> = bot.EnumerateEvents<TPlugin> & common.EnumerateInterfaceEvents<TPlugin>;
|
|
10
13
|
type _IncomingEvents<TPlugin extends common.BasePlugin> = {
|
|
11
14
|
[K in utils.StringKeys<EnumeratePluginEvents<TPlugin>>]: utils.Merge<client.Event, {
|
|
@@ -15,7 +18,7 @@ type _IncomingEvents<TPlugin extends common.BasePlugin> = {
|
|
|
15
18
|
};
|
|
16
19
|
type _IncomingMessages<TPlugin extends common.BasePlugin> = {
|
|
17
20
|
[K in utils.StringKeys<bot.GetMessages<TPlugin>>]: utils.Merge<client.Message, {
|
|
18
|
-
type: K
|
|
21
|
+
type: Extract<K, string>;
|
|
19
22
|
payload: bot.GetMessages<TPlugin>[K];
|
|
20
23
|
}>;
|
|
21
24
|
};
|
|
@@ -110,72 +113,142 @@ export type PluginClient<_TPlugin extends common.BasePlugin> = bot.BotSpecificCl
|
|
|
110
113
|
export type CommonHandlerProps<TPlugin extends common.BasePlugin> = {
|
|
111
114
|
ctx: bot.BotContext;
|
|
112
115
|
logger: bot.BotLogger;
|
|
116
|
+
/**
|
|
117
|
+
* Please use the `users`, `conversations`, `actions`, `messages`, `states`,
|
|
118
|
+
* `events`, `workflows` utilities instead of accessing the client directly.
|
|
119
|
+
*
|
|
120
|
+
* For example, you can replace `props.client.listUsers(...)` with
|
|
121
|
+
* `props.users.list(...).take(n)`
|
|
122
|
+
*/
|
|
113
123
|
client: PluginClient<TPlugin>;
|
|
114
124
|
};
|
|
115
125
|
export type InjectedHandlerProps<TPlugin extends common.BasePlugin> = {
|
|
116
126
|
configuration: common.PluginConfiguration<TPlugin>;
|
|
127
|
+
/**
|
|
128
|
+
* Mapping of plugin interface dependencies to the integrations that
|
|
129
|
+
* implement them.
|
|
130
|
+
*/
|
|
117
131
|
interfaces: common.PluginInterfaceExtensions<TPlugin>;
|
|
118
|
-
|
|
132
|
+
/**
|
|
133
|
+
* Mapping of plugin integration dependencies to the integrations that
|
|
134
|
+
* implement them.
|
|
135
|
+
*/
|
|
136
|
+
integrations: common.PluginIntegrationExtensions<TPlugin>;
|
|
137
|
+
/**
|
|
138
|
+
* Alias of the plugin within the bot. This is usually equal to the plugin's
|
|
139
|
+
* name, but may be different if the bot has multiple instances of the same
|
|
140
|
+
* plugin installed.
|
|
141
|
+
*/
|
|
142
|
+
alias: string;
|
|
143
|
+
/**
|
|
144
|
+
* Allows calling actions defined by the plugins's integration and interface
|
|
145
|
+
* dependencies.
|
|
146
|
+
*/
|
|
119
147
|
actions: actionProxy.ActionProxy<TPlugin>;
|
|
148
|
+
/**
|
|
149
|
+
* Allows querying and mutating states defined by the plugin.
|
|
150
|
+
*/
|
|
120
151
|
states: stateProxy.StateProxy<TPlugin>;
|
|
152
|
+
/**
|
|
153
|
+
* Allows emitting events defined by the plugin.
|
|
154
|
+
*/
|
|
121
155
|
events: eventProxy.EventProxy<TPlugin>;
|
|
156
|
+
/**
|
|
157
|
+
* Allows querying and mutating users.
|
|
158
|
+
*/
|
|
159
|
+
users: userProxy.UserFinder<TPlugin>;
|
|
160
|
+
/**
|
|
161
|
+
* Allows querying and mutating conversations on channels defined by the
|
|
162
|
+
* plugin's integration and interface dependencies.
|
|
163
|
+
*/
|
|
164
|
+
conversations: conversationProxy.ConversationFinder<TPlugin>;
|
|
165
|
+
/**
|
|
166
|
+
* Allows querying and mutating individual messages.
|
|
167
|
+
*/
|
|
168
|
+
messages: messageProxy.MessageFinder<TPlugin>;
|
|
122
169
|
/**
|
|
123
170
|
* # EXPERIMENTAL
|
|
124
171
|
* This API is experimental and may change in the future.
|
|
125
172
|
*/
|
|
126
173
|
workflows: workflowProxy.WorkflowProxy<TPlugin>;
|
|
127
174
|
};
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
175
|
+
type _WithInjectedProps<T extends Record<string, Record<string, any>>, TPlugin extends common.BasePlugin, TMerge extends object = {}> = {
|
|
176
|
+
[K in keyof T]: utils.Merge<T[K], TMerge> & InjectedHandlerProps<TPlugin>;
|
|
177
|
+
};
|
|
178
|
+
type _WithInjectedPropsFn<T extends Record<string, (args: any) => any>, TPlugin extends common.BasePlugin, TMerge extends object = {}> = {
|
|
179
|
+
[K in keyof T]: (args: utils.Merge<Parameters<T[K]>[0], TMerge> & InjectedHandlerProps<TPlugin>) => ReturnType<T[K]>;
|
|
180
|
+
};
|
|
181
|
+
export type MessagePayloadsWithoutInjectedProps<TPlugin extends common.BasePlugin> = {
|
|
182
|
+
[TMessageName in utils.StringKeys<IncomingMessages<TPlugin>>]: CommonHandlerProps<TPlugin> & {
|
|
131
183
|
message: IncomingMessages<TPlugin>[TMessageName];
|
|
132
184
|
user: client.User;
|
|
133
185
|
conversation: client.Conversation;
|
|
134
186
|
event: client.Event;
|
|
135
187
|
};
|
|
136
188
|
};
|
|
137
|
-
export type
|
|
138
|
-
[TMessageName in utils.StringKeys<IncomingMessages<TPlugin>>]: (args:
|
|
189
|
+
export type MessageHandlersWithoutInjectedProps<TPlugin extends common.BasePlugin> = {
|
|
190
|
+
[TMessageName in utils.StringKeys<IncomingMessages<TPlugin>>]: (args: MessagePayloadsWithoutInjectedProps<TPlugin>[TMessageName]) => Promise<void>;
|
|
139
191
|
};
|
|
140
|
-
export type
|
|
141
|
-
|
|
192
|
+
export type MessageHandlers<TPlugin extends common.BasePlugin> = _WithInjectedPropsFn<MessageHandlersWithoutInjectedProps<TPlugin>, TPlugin, {
|
|
193
|
+
user: userProxy.ActionableUser<TPlugin, string>;
|
|
194
|
+
conversation: conversationProxy.ActionableConversation<TPlugin>;
|
|
195
|
+
message: messageProxy.ActionableMessage<TPlugin>;
|
|
196
|
+
}>;
|
|
197
|
+
export type EventPayloadsWithoutInjectedProps<TPlugin extends common.BasePlugin> = {
|
|
198
|
+
[TEventName in utils.StringKeys<IncomingEvents<TPlugin>>]: CommonHandlerProps<TPlugin> & {
|
|
142
199
|
event: IncomingEvents<TPlugin>[TEventName];
|
|
143
200
|
};
|
|
144
201
|
};
|
|
145
|
-
export type
|
|
146
|
-
|
|
202
|
+
export type EventPayloads<TPlugin extends common.BasePlugin> = _WithInjectedProps<EventPayloadsWithoutInjectedProps<TPlugin>, TPlugin>;
|
|
203
|
+
export type EventHandlersWithoutInjectedProps<TPlugin extends common.BasePlugin> = {
|
|
204
|
+
[TEventName in utils.StringKeys<IncomingEvents<TPlugin>>]: (args: EventPayloadsWithoutInjectedProps<TPlugin>[TEventName]) => Promise<void>;
|
|
147
205
|
};
|
|
148
|
-
export type
|
|
149
|
-
|
|
206
|
+
export type EventHandlers<TPlugin extends common.BasePlugin> = _WithInjectedPropsFn<EventHandlersWithoutInjectedProps<TPlugin>, TPlugin>;
|
|
207
|
+
export type StateExpiredPayloadsWithoutInjectedProps<TPlugin extends common.BasePlugin> = {
|
|
208
|
+
[TSateName in utils.StringKeys<IncomingStates<TPlugin>>]: CommonHandlerProps<TPlugin> & {
|
|
150
209
|
state: IncomingStates<TPlugin>[TSateName];
|
|
151
210
|
};
|
|
152
211
|
};
|
|
153
|
-
export type
|
|
154
|
-
|
|
212
|
+
export type StateExpiredPayloads<TPlugin extends common.BasePlugin> = _WithInjectedProps<StateExpiredPayloadsWithoutInjectedProps<TPlugin>, TPlugin>;
|
|
213
|
+
export type StateExpiredHandlersWithoutInjectedProps<TPlugin extends common.BasePlugin> = {
|
|
214
|
+
[TSateName in utils.StringKeys<IncomingStates<TPlugin>>]: (args: StateExpiredPayloadsWithoutInjectedProps<TPlugin>[TSateName]) => Promise<void>;
|
|
155
215
|
};
|
|
156
|
-
export type
|
|
157
|
-
|
|
216
|
+
export type StateExpiredHandlers<TPlugin extends common.BasePlugin> = _WithInjectedPropsFn<StateExpiredHandlersWithoutInjectedProps<TPlugin>, TPlugin>;
|
|
217
|
+
export type ActionHandlerPayloadsWithoutInjectedProps<TPlugin extends common.BasePlugin> = {
|
|
218
|
+
[TActionName in utils.StringKeys<TPlugin['actions']>]: CommonHandlerProps<TPlugin> & {
|
|
158
219
|
type?: TActionName;
|
|
159
220
|
input: TPlugin['actions'][TActionName]['input'];
|
|
160
221
|
};
|
|
161
222
|
};
|
|
162
|
-
export type
|
|
163
|
-
|
|
223
|
+
export type ActionHandlerPayloads<TPlugin extends common.BasePlugin> = _WithInjectedProps<ActionHandlerPayloadsWithoutInjectedProps<TPlugin>, TPlugin>;
|
|
224
|
+
export type ActionHandlersWithoutInjectedProps<TPlugin extends common.BasePlugin> = {
|
|
225
|
+
[TActionName in utils.StringKeys<TPlugin['actions']>]: (props: ActionHandlerPayloadsWithoutInjectedProps<TPlugin>[TActionName]) => Promise<TPlugin['actions'][TActionName]['output']>;
|
|
164
226
|
};
|
|
165
|
-
export type
|
|
166
|
-
|
|
227
|
+
export type ActionHandlers<TPlugin extends common.BasePlugin> = _WithInjectedPropsFn<ActionHandlersWithoutInjectedProps<TPlugin>, TPlugin>;
|
|
228
|
+
export type WorkflowPayloadsWithoutInjectedProps<TPlugin extends common.BasePlugin> = {
|
|
229
|
+
[TWorkflowName in utils.StringKeys<TPlugin['workflows']>]: CommonHandlerProps<TPlugin> & {
|
|
167
230
|
conversation?: client.Conversation;
|
|
168
231
|
user?: client.User;
|
|
169
232
|
event: bot.WorkflowUpdateEvent;
|
|
233
|
+
workflow: client.Workflow;
|
|
234
|
+
};
|
|
235
|
+
};
|
|
236
|
+
export type WorkflowPayloads<TPlugin extends common.BasePlugin> = _WithInjectedProps<{
|
|
237
|
+
[TWorkflowName in keyof WorkflowPayloadsWithoutInjectedProps<TPlugin>]: utils.Merge<WorkflowPayloadsWithoutInjectedProps<TPlugin>[TWorkflowName], {
|
|
170
238
|
/**
|
|
171
239
|
* # EXPERIMENTAL
|
|
172
240
|
* This API is experimental and may change in the future.
|
|
173
241
|
*/
|
|
174
|
-
workflow: workflowProxy.
|
|
175
|
-
}
|
|
242
|
+
workflow: workflowProxy.ActionableWorkflow<TPlugin, TWorkflowName>;
|
|
243
|
+
}>;
|
|
244
|
+
}, TPlugin>;
|
|
245
|
+
export type WorkflowHandlersWithoutInjectedProps<TPlugin extends common.BasePlugin> = {
|
|
246
|
+
[TWorkflowName in utils.StringKeys<TPlugin['workflows']>]: (props: WorkflowPayloadsWithoutInjectedProps<TPlugin>[TWorkflowName]) => Promise<void>;
|
|
176
247
|
};
|
|
177
248
|
export type WorkflowHandlers<TPlugin extends common.BasePlugin> = {
|
|
178
|
-
[TWorkflowName in utils.StringKeys<TPlugin['workflows']>]: (props: WorkflowPayloads<TPlugin>[TWorkflowName]
|
|
249
|
+
[TWorkflowName in utils.StringKeys<TPlugin['workflows']>]: (props: utils.Merge<WorkflowPayloads<TPlugin>[TWorkflowName], {
|
|
250
|
+
workflow: workflowProxy.ActionableWorkflow<TPlugin, TWorkflowName>;
|
|
251
|
+
}>) => Promise<void>;
|
|
179
252
|
};
|
|
180
253
|
type BaseHookDefinition = {
|
|
181
254
|
stoppable?: boolean;
|
|
@@ -259,13 +332,16 @@ export type HookData<TPlugin extends common.BasePlugin> = {
|
|
|
259
332
|
[THookDataName in utils.StringKeys<HookDefinitions<TPlugin>[THookType]['data']>]: HookDefinitions<TPlugin>[THookType]['data'][THookDataName];
|
|
260
333
|
};
|
|
261
334
|
};
|
|
262
|
-
export type
|
|
335
|
+
export type HookInputsWithoutInjectedProps<TPlugin extends common.BasePlugin> = {
|
|
263
336
|
[THookType in utils.StringKeys<HookData<TPlugin>>]: {
|
|
264
|
-
[THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]:
|
|
337
|
+
[THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]: CommonHandlerProps<TPlugin> & {
|
|
265
338
|
data: HookData<TPlugin>[THookType][THookDataName];
|
|
266
339
|
};
|
|
267
340
|
};
|
|
268
341
|
};
|
|
342
|
+
export type HookInputs<TPlugin extends common.BasePlugin> = {
|
|
343
|
+
[THookType in utils.StringKeys<HookData<TPlugin>>]: _WithInjectedProps<HookInputsWithoutInjectedProps<TPlugin>[THookType], TPlugin>;
|
|
344
|
+
};
|
|
269
345
|
export type HookOutputs<TPlugin extends common.BasePlugin> = {
|
|
270
346
|
[THookType in utils.StringKeys<HookData<TPlugin>>]: {
|
|
271
347
|
[THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]: {
|
|
@@ -275,32 +351,23 @@ export type HookOutputs<TPlugin extends common.BasePlugin> = {
|
|
|
275
351
|
} : {});
|
|
276
352
|
};
|
|
277
353
|
};
|
|
278
|
-
export type
|
|
354
|
+
export type HookHandlersWithoutInjectedProps<TPlugin extends common.BasePlugin> = {
|
|
279
355
|
[THookType in utils.StringKeys<HookData<TPlugin>>]: {
|
|
280
|
-
[THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]: (input:
|
|
356
|
+
[THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]: (input: HookInputsWithoutInjectedProps<TPlugin>[THookType][THookDataName]) => Promise<HookOutputs<TPlugin>[THookType][THookDataName] | undefined>;
|
|
281
357
|
};
|
|
282
358
|
};
|
|
283
|
-
export type
|
|
284
|
-
[
|
|
285
|
-
};
|
|
286
|
-
export type MessageHandlersMap<TPlugin extends common.BasePlugin> = {
|
|
287
|
-
[TMessageName in utils.StringKeys<IncomingMessages<TPlugin>>]?: ((props: Omit<Parameters<MessageHandlers<TPlugin>[TMessageName]>[0], keyof InjectedHandlerProps<TPlugin>>) => Promise<void>)[];
|
|
288
|
-
};
|
|
289
|
-
export type EventHandlersMap<TPlugin extends common.BasePlugin> = {
|
|
290
|
-
[TEventName in utils.StringKeys<IncomingEvents<TPlugin>>]?: ((props: Omit<Parameters<EventHandlers<TPlugin>[TEventName]>[0], keyof InjectedHandlerProps<TPlugin>>) => Promise<void>)[];
|
|
291
|
-
};
|
|
292
|
-
export type StateExpiredHandlersMap<TPlugin extends common.BasePlugin> = {
|
|
293
|
-
[TStateName in utils.StringKeys<IncomingStates<TPlugin>>]?: ((props: Omit<Parameters<StateExpiredHandlers<TPlugin>[TStateName]>[0], keyof InjectedHandlerProps<TPlugin>>) => Promise<void>)[];
|
|
359
|
+
export type HookHandlers<TPlugin extends common.BasePlugin> = {
|
|
360
|
+
[THookType in utils.StringKeys<HookData<TPlugin>>]: _WithInjectedPropsFn<HookHandlersWithoutInjectedProps<TPlugin>[THookType], TPlugin>;
|
|
294
361
|
};
|
|
295
362
|
export type HookHandlersMap<TPlugin extends common.BasePlugin> = {
|
|
296
363
|
[THookType in utils.StringKeys<HookData<TPlugin>>]: {
|
|
297
|
-
[THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]?:
|
|
364
|
+
[THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]?: HookHandlersWithoutInjectedProps<TPlugin>[THookType][THookDataName][];
|
|
298
365
|
};
|
|
299
366
|
};
|
|
300
367
|
export type WorkflowHandlersMap<TPlugin extends common.BasePlugin> = {
|
|
301
368
|
[TWorkflowUpdateType in bot.WorkflowUpdateType]: {
|
|
302
369
|
[TWorkflowName in utils.StringKeys<TPlugin['workflows']>]?: {
|
|
303
|
-
handler: (props: Omit<Parameters<
|
|
370
|
+
handler: (props: Omit<Parameters<WorkflowHandlersWithoutInjectedProps<TPlugin>[TWorkflowName]>[0], 'workflow'> & {
|
|
304
371
|
workflow: client.Workflow;
|
|
305
372
|
}) => Promise<client.Workflow>;
|
|
306
373
|
order: number;
|
|
@@ -343,12 +410,26 @@ export type OrderedWorkflowHandlersMap<TPlugin extends common.BasePlugin> = {
|
|
|
343
410
|
};
|
|
344
411
|
/** Plugin handlers without InjectedHandlerProps */
|
|
345
412
|
export type PluginHandlers<TPlugin extends common.BasePlugin> = {
|
|
346
|
-
actionHandlers:
|
|
347
|
-
messageHandlers:
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
413
|
+
actionHandlers: ActionHandlersWithoutInjectedProps<TPlugin>;
|
|
414
|
+
messageHandlers: {
|
|
415
|
+
[TMessageName in utils.StringKeys<IncomingMessages<TPlugin>>]?: MessageHandlersWithoutInjectedProps<TPlugin>[TMessageName][];
|
|
416
|
+
};
|
|
417
|
+
eventHandlers: {
|
|
418
|
+
[TEventName in utils.StringKeys<IncomingEvents<TPlugin>>]?: EventHandlersWithoutInjectedProps<TPlugin>[TEventName][];
|
|
419
|
+
};
|
|
420
|
+
stateExpiredHandlers: {
|
|
421
|
+
[TStateName in utils.StringKeys<IncomingStates<TPlugin>>]?: StateExpiredHandlersWithoutInjectedProps<TPlugin>[TStateName][];
|
|
422
|
+
};
|
|
423
|
+
hookHandlers: {
|
|
424
|
+
[THookType in utils.StringKeys<HookData<TPlugin>>]: {
|
|
425
|
+
[THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]?: HookHandlersWithoutInjectedProps<TPlugin>[THookType][THookDataName][];
|
|
426
|
+
};
|
|
427
|
+
};
|
|
428
|
+
workflowHandlers: {
|
|
429
|
+
[TWorkflowUpdateType in bot.WorkflowUpdateType]: {
|
|
430
|
+
[TWorkflowName in utils.StringKeys<TPlugin['workflows']>]?: WorkflowHandlersWithoutInjectedProps<TPlugin>[TWorkflowName][];
|
|
431
|
+
};
|
|
432
|
+
};
|
|
352
433
|
};
|
|
353
434
|
/** identical to PluginHandlers, but contains the injected properties */
|
|
354
435
|
export type InjectedPluginHandlers<TPlugin extends common.BasePlugin> = {
|
|
@@ -369,10 +450,7 @@ export type InjectedPluginHandlers<TPlugin extends common.BasePlugin> = {
|
|
|
369
450
|
};
|
|
370
451
|
workflowHandlers: {
|
|
371
452
|
[TWorkflowUpdateType in bot.WorkflowUpdateType]: {
|
|
372
|
-
[TWorkflowName in utils.StringKeys<TPlugin['workflows']>]?:
|
|
373
|
-
handler: WorkflowHandlers<TPlugin>[TWorkflowName];
|
|
374
|
-
order: number;
|
|
375
|
-
}[];
|
|
453
|
+
[TWorkflowName in utils.StringKeys<TPlugin['workflows']>]?: WorkflowHandlers<TPlugin>[TWorkflowName][];
|
|
376
454
|
};
|
|
377
455
|
};
|
|
378
456
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const unprefixTagsOwnedByPlugin: <T extends {} | {
|
|
2
|
+
tags?: Record<string, string>;
|
|
3
|
+
}>(obj: T, { alias }: {
|
|
4
|
+
alias?: string;
|
|
5
|
+
}) => T;
|
|
6
|
+
export declare const prefixTagsIfNeeded: <T extends {} | {
|
|
7
|
+
tags?: Record<string, string>;
|
|
8
|
+
}>(obj: T, { alias }: {
|
|
9
|
+
alias?: string;
|
|
10
|
+
}) => T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type * as client from '@botpress/client';
|
|
2
|
+
import type { BotSpecificClient } from '../../bot';
|
|
3
|
+
import type { BasePlugin } from '../common';
|
|
4
|
+
import type { UserFinder, ActionableUser } from './types';
|
|
5
|
+
export declare const proxyUsers: <TPlugin extends BasePlugin>(props: {
|
|
6
|
+
client: BotSpecificClient<TPlugin> | client.Client;
|
|
7
|
+
pluginAlias?: string;
|
|
8
|
+
}) => UserFinder<TPlugin>;
|
|
9
|
+
export declare const proxyUser: <TPlugin extends BasePlugin, TConversationId extends string | undefined>(props: {
|
|
10
|
+
client: BotSpecificClient<TPlugin> | client.Client;
|
|
11
|
+
conversationId?: TConversationId;
|
|
12
|
+
pluginAlias?: string;
|
|
13
|
+
user: client.User;
|
|
14
|
+
}) => ActionableUser<TPlugin, TConversationId>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ClientInputs, User } from '@botpress/client';
|
|
2
|
+
import type { commonTypes } from '../../common';
|
|
3
|
+
import type { AsyncCollection } from '../../utils/api-paging-utils';
|
|
4
|
+
import type * as typeUtils from '../../utils/type-utils';
|
|
5
|
+
import { BasePlugin } from '../common';
|
|
6
|
+
export type UserFinder<TPlugin extends BasePlugin> = {
|
|
7
|
+
list: <TConversationId extends string | undefined = undefined>(props?: {
|
|
8
|
+
conversationId?: TConversationId;
|
|
9
|
+
tags?: commonTypes.ToTags<typeUtils.StringKeys<TPlugin['user']['tags']>>;
|
|
10
|
+
}) => AsyncCollection<ActionableUser<TPlugin, TConversationId>>;
|
|
11
|
+
getById: (props: {
|
|
12
|
+
id: string;
|
|
13
|
+
}) => Promise<ActionableUser<TPlugin>>;
|
|
14
|
+
};
|
|
15
|
+
export type ActionableUser<TPlugin extends BasePlugin, TConversationId extends string | undefined = undefined> = TConversationId extends string ? ActionableUserWithConversation<TPlugin, TConversationId> : ActionableUserWithoutConversation<TPlugin, TConversationId>;
|
|
16
|
+
export type ActionableUserWithConversation<TPlugin extends BasePlugin, TConversationId extends string | undefined> = BaseActionableUser<TPlugin, TConversationId> & {
|
|
17
|
+
removeFromConversation: () => Promise<ActionableUser<TPlugin, undefined>>;
|
|
18
|
+
};
|
|
19
|
+
export type ActionableUserWithoutConversation<TPlugin extends BasePlugin, TConversationId extends string | undefined> = BaseActionableUser<TPlugin, TConversationId> & {
|
|
20
|
+
addToConversation: <TNewConversationId extends string>(props: {
|
|
21
|
+
conversationId: TNewConversationId;
|
|
22
|
+
}) => Promise<ActionableUser<TPlugin, TNewConversationId>>;
|
|
23
|
+
};
|
|
24
|
+
export type BaseActionableUser<TPlugin extends BasePlugin, TConversationId extends string | undefined = undefined> = typeUtils.Merge<User, {
|
|
25
|
+
tags: commonTypes.ToTags<typeUtils.StringKeys<TPlugin['user']['tags']>>;
|
|
26
|
+
}> & {
|
|
27
|
+
update: (props: typeUtils.Merge<Omit<ClientInputs['updateUser'], 'id'>, {
|
|
28
|
+
tags?: commonTypes.ToTags<typeUtils.StringKeys<TPlugin['user']['tags']>>;
|
|
29
|
+
}>) => Promise<ActionableUser<TPlugin, TConversationId>>;
|
|
30
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
type _PageLister<R> = (t: {
|
|
2
|
+
nextToken?: string;
|
|
3
|
+
}) => Promise<{
|
|
4
|
+
items: R[];
|
|
5
|
+
meta: {
|
|
6
|
+
nextToken?: string;
|
|
7
|
+
};
|
|
8
|
+
}>;
|
|
9
|
+
declare class AsyncCollection<T> implements AsyncIterableIterator<T> {
|
|
10
|
+
private _list;
|
|
11
|
+
private _nextToken?;
|
|
12
|
+
private _elementsBuffer;
|
|
13
|
+
private _isExhausted;
|
|
14
|
+
constructor(_list: _PageLister<T>);
|
|
15
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<T>;
|
|
16
|
+
/**
|
|
17
|
+
* Get the next element from the collection and advance the iterator.
|
|
18
|
+
*/
|
|
19
|
+
next(): Promise<IteratorResult<T, undefined>>;
|
|
20
|
+
/**
|
|
21
|
+
* Take the next n elements from the collection, advancing the iterator, and
|
|
22
|
+
* return them as an array.
|
|
23
|
+
*/
|
|
24
|
+
take(amount: number): Promise<T[]>;
|
|
25
|
+
/**
|
|
26
|
+
* Take the next n pages of elements from the collection, advancing the
|
|
27
|
+
* iterator, and return the elements as an array.
|
|
28
|
+
*/
|
|
29
|
+
takePage(amount: number): Promise<T[]>;
|
|
30
|
+
/**
|
|
31
|
+
* Take all remaining elements from in collection, moving the iterator to the
|
|
32
|
+
* end, and return them as an array.
|
|
33
|
+
*/
|
|
34
|
+
takeAll(): Promise<T[]>;
|
|
35
|
+
/**
|
|
36
|
+
* Returns true if there are no more elements to fetch in the collection.
|
|
37
|
+
*/
|
|
38
|
+
get isExhausted(): boolean;
|
|
39
|
+
private _fetchNextPageIntoBuffer;
|
|
40
|
+
private get _bufferIsEmpty();
|
|
41
|
+
}
|
|
42
|
+
export type { AsyncCollection };
|
|
43
|
+
export declare const createAsyncCollection: <T>(listFn: _PageLister<T>) => AsyncCollection<T>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -59,4 +59,5 @@ type DeepPartialObject<T extends object> = T extends infer O ? {
|
|
|
59
59
|
export type DeepPartial<T> = T extends (...args: infer A) => infer R ? (...args: DeepPartial<A>) => DeepPartial<R> : T extends Array<infer E> ? Array<DeepPartial<E>> : T extends ReadonlyArray<infer E> ? ReadonlyArray<DeepPartial<E>> : T extends Promise<infer R> ? Promise<DeepPartial<R>> : T extends Buffer ? Buffer : T extends object ? DeepPartialObject<T> : T;
|
|
60
60
|
export type SafeOmit<T, K extends keyof T> = Omit<T, K>;
|
|
61
61
|
export type StringKeys<T> = Extract<keyof T, string>;
|
|
62
|
+
export type DistributivePick<T, K extends keyof T> = T extends any ? Pick<T, K> : never;
|
|
62
63
|
export {};
|
package/package.json
CHANGED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { PluginInterfaceExtensions } from './common';
|
|
2
|
-
export type ParsedActionRef = {
|
|
3
|
-
namespace: string;
|
|
4
|
-
actionName: string;
|
|
5
|
-
};
|
|
6
|
-
export type ParsedEventRef = {
|
|
7
|
-
namespace: string;
|
|
8
|
-
eventName: string;
|
|
9
|
-
};
|
|
10
|
-
export declare const parseActionRef: (actionRef: string) => ParsedActionRef | null;
|
|
11
|
-
export declare const parseEventRef: (eventRef: string) => ParsedEventRef | null;
|
|
12
|
-
export declare const formatActionRef: (actionRef: ParsedActionRef) => string;
|
|
13
|
-
export declare const formatEventRef: (eventRef: ParsedEventRef) => string;
|
|
14
|
-
export declare const resolveAction: (actionRef: ParsedActionRef, interfaces: PluginInterfaceExtensions<any>) => ParsedActionRef;
|
|
15
|
-
export declare const resolveEvent: (eventRef: ParsedEventRef, interfaces: PluginInterfaceExtensions<any>) => ParsedEventRef;
|