@botpress/sdk 4.20.2 → 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.
Files changed (42) hide show
  1. package/.turbo/turbo-build.log +5 -5
  2. package/dist/bot/definition.d.ts +45 -7
  3. package/dist/bot/server/types.d.ts +2 -5
  4. package/dist/bot/workflow-proxy/proxy.d.ts +7 -3
  5. package/dist/bot/workflow-proxy/types.d.ts +24 -23
  6. package/dist/common/index.d.ts +1 -0
  7. package/dist/common/types.d.ts +2 -0
  8. package/dist/fixtures.d.ts +84 -13
  9. package/dist/index.cjs +41 -38
  10. package/dist/index.cjs.map +4 -4
  11. package/dist/index.d.ts +2 -2
  12. package/dist/index.mjs +33 -30
  13. package/dist/index.mjs.map +4 -4
  14. package/dist/integration/client/types.d.ts +15 -14
  15. package/dist/integration/common/index.d.ts +0 -1
  16. package/dist/integration/server/types.d.ts +8 -7
  17. package/dist/message.d.ts +245 -29
  18. package/dist/plugin/common/generic.d.ts +12 -0
  19. package/dist/plugin/common/types.d.ts +17 -5
  20. package/dist/plugin/conversation-proxy/index.d.ts +2 -0
  21. package/dist/plugin/conversation-proxy/proxy.d.ts +13 -0
  22. package/dist/plugin/conversation-proxy/types.d.ts +54 -0
  23. package/dist/plugin/conversation-proxy/types.test.d.ts +1 -0
  24. package/dist/plugin/definition.d.ts +1 -1
  25. package/dist/plugin/event-proxy/proxy.d.ts +2 -2
  26. package/dist/plugin/event-proxy/types.d.ts +11 -6
  27. package/dist/plugin/implementation.d.ts +4 -4
  28. package/dist/plugin/message-proxy/index.d.ts +2 -0
  29. package/dist/plugin/message-proxy/proxy.d.ts +13 -0
  30. package/dist/plugin/message-proxy/types.d.ts +22 -0
  31. package/dist/plugin/server/types.d.ts +129 -51
  32. package/dist/plugin/tag-prefixer.d.ts +10 -0
  33. package/dist/plugin/tag-prefixer.test.d.ts +1 -0
  34. package/dist/plugin/user-proxy/index.d.ts +2 -0
  35. package/dist/plugin/user-proxy/proxy.d.ts +14 -0
  36. package/dist/plugin/user-proxy/types.d.ts +30 -0
  37. package/dist/utils/api-paging-utils.d.ts +43 -0
  38. package/dist/utils/api-paging-utils.test.d.ts +1 -0
  39. package/dist/utils/type-utils.d.ts +1 -0
  40. package/package.json +1 -1
  41. package/dist/integration/common/types.d.ts +0 -2
  42. package/dist/plugin/interface-resolution.d.ts +0 -15
@@ -1,7 +1,7 @@
1
1
  import type { MessageHandlersMap as BotMessageHandlersMap, EventHandlersMap as BotEventHandlersMap, StateExpiredHandlersMap as BotStateExpiredHandlersMap, HookHandlersMap as BotHookHandlersMap, WorkflowHandlersMap as BotWorkflowHandlersMap, ActionHandlersMap as BotActionHandlersMap, BotHandlers } from '../bot';
2
2
  import * as utils from '../utils';
3
3
  import { BasePlugin, PluginRuntimeProps } from './common';
4
- import { ActionHandlers, MessageHandlers, EventHandlers, StateExpiredHandlers, HookHandlers, WorkflowHandlers, MessageHandlersMap, EventHandlersMap, StateExpiredHandlersMap, HookHandlersMap, WorkflowHandlersMap } from './server/types';
4
+ import { ActionHandlers, MessageHandlers, EventHandlers, StateExpiredHandlers, HookHandlers, WorkflowHandlers, HookHandlersMap, WorkflowHandlersMap } from './server/types';
5
5
  export type PluginImplementationProps<TPlugin extends BasePlugin = BasePlugin> = {
6
6
  actions: ActionHandlers<TPlugin>;
7
7
  };
@@ -26,9 +26,9 @@ export declare class PluginImplementation<TPlugin extends BasePlugin = BasePlugi
26
26
  get hookHandlers(): BotHookHandlersMap<TPlugin>;
27
27
  get workflowHandlers(): BotWorkflowHandlersMap<TPlugin>;
28
28
  readonly on: {
29
- message: <T extends utils.types.StringKeys<MessageHandlersMap<TPlugin>>>(type: T, handler: MessageHandlers<TPlugin>[T]) => void;
30
- event: <T extends utils.types.StringKeys<EventHandlersMap<TPlugin>>>(type: T, handler: EventHandlers<TPlugin>[T]) => void;
31
- stateExpired: <T extends utils.types.StringKeys<StateExpiredHandlersMap<TPlugin>>>(type: T, handler: StateExpiredHandlers<TPlugin>[T]) => void;
29
+ message: <T extends utils.types.StringKeys<MessageHandlers<TPlugin>>>(type: T, handler: MessageHandlers<TPlugin>[T]) => void;
30
+ event: <T extends utils.types.StringKeys<EventHandlers<TPlugin>>>(type: T, handler: EventHandlers<TPlugin>[T]) => void;
31
+ stateExpired: <T extends utils.types.StringKeys<StateExpiredHandlers<TPlugin>>>(type: T, handler: StateExpiredHandlers<TPlugin>[T]) => void;
32
32
  beforeIncomingEvent: <T extends utils.types.StringKeys<HookHandlersMap<TPlugin>["before_incoming_event"]>>(type: T, handler: HookHandlers<TPlugin>["before_incoming_event"][T]) => void;
33
33
  beforeIncomingMessage: <T extends utils.types.StringKeys<HookHandlersMap<TPlugin>["before_incoming_message"]>>(type: T, handler: HookHandlers<TPlugin>["before_incoming_message"][T]) => void;
34
34
  beforeOutgoingMessage: <T extends utils.types.StringKeys<HookHandlersMap<TPlugin>["before_outgoing_message"]>>(type: T, handler: HookHandlers<TPlugin>["before_outgoing_message"][T]) => void;
@@ -0,0 +1,2 @@
1
+ export { proxyMessage, proxyMessages } from './proxy';
2
+ export { ActionableMessage, MessageFinder } from './types';
@@ -0,0 +1,13 @@
1
+ import type * as client from '@botpress/client';
2
+ import type { BotSpecificClient } from '../../bot';
3
+ import type { BasePlugin, PluginRuntimeProps } from '../common';
4
+ import type { ActionableMessage, AnyPluginMessage, MessageFinder } from './types';
5
+ export declare const proxyMessages: <TPlugin extends BasePlugin>(props: {
6
+ client: BotSpecificClient<TPlugin> | client.Client;
7
+ plugin?: PluginRuntimeProps<TPlugin>;
8
+ }) => MessageFinder<TPlugin>;
9
+ export declare const proxyMessage: <TPlugin extends BasePlugin, TMessage extends client.Message | AnyPluginMessage<TPlugin> = AnyPluginMessage<TPlugin>>(props: {
10
+ client: BotSpecificClient<TPlugin> | client.Client;
11
+ plugin?: PluginRuntimeProps<TPlugin>;
12
+ message: TMessage;
13
+ }) => ActionableMessage<TPlugin, TMessage>;
@@ -0,0 +1,22 @@
1
+ import type * as client from '@botpress/client';
2
+ import type { GetMessages } from '../../bot';
3
+ import type { commonTypes } from '../../common';
4
+ import type { AsyncCollection } from '../../utils/api-paging-utils';
5
+ import type * as typeUtils from '../../utils/type-utils';
6
+ import type { BasePlugin } from '../common';
7
+ import type { IncomingMessages } from '../server';
8
+ export type MessageFinder<TPlugin extends BasePlugin> = {
9
+ list: (props?: Omit<client.ClientInputs['listMessages'], 'nextToken'>) => AsyncCollection<ActionableMessage<TPlugin>>;
10
+ getById: (props: {
11
+ id: string;
12
+ }) => Promise<ActionableMessage<TPlugin>>;
13
+ };
14
+ export type AnyPluginMessage<TPlugin extends BasePlugin> = IncomingMessages<TPlugin>['*'] | IncomingMessages<TPlugin>[typeUtils.StringKeys<GetMessages<TPlugin>>];
15
+ export type ActionableMessage<TPlugin extends BasePlugin, TMessage extends client.Message | AnyPluginMessage<TPlugin> = client.Message> = typeUtils.Merge<TMessage, {
16
+ tags: commonTypes.ToTags<typeUtils.StringKeys<TPlugin['conversation']['tags']>>;
17
+ }> & {
18
+ delete: () => Promise<void>;
19
+ update: (props: typeUtils.Merge<Omit<client.ClientInputs['updateMessage'], 'id'>, {
20
+ tags: commonTypes.ToTags<typeUtils.StringKeys<TPlugin['message']['tags']>>;
21
+ }>) => Promise<ActionableMessage<TPlugin, TMessage>>;
22
+ };
@@ -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
- alias?: string;
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
- export type ExtendedHandlerProps<TPlugin extends common.BasePlugin> = CommonHandlerProps<TPlugin> & InjectedHandlerProps<TPlugin>;
129
- export type MessagePayloads<TPlugin extends common.BasePlugin> = {
130
- [TMessageName in utils.StringKeys<IncomingMessages<TPlugin>>]: ExtendedHandlerProps<TPlugin> & {
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 MessageHandlers<TPlugin extends common.BasePlugin> = {
138
- [TMessageName in utils.StringKeys<IncomingMessages<TPlugin>>]: (args: MessagePayloads<TPlugin>[TMessageName]) => Promise<void>;
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 EventPayloads<TPlugin extends common.BasePlugin> = {
141
- [TEventName in utils.StringKeys<IncomingEvents<TPlugin>>]: ExtendedHandlerProps<TPlugin> & {
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 EventHandlers<TPlugin extends common.BasePlugin> = {
146
- [TEventName in utils.StringKeys<IncomingEvents<TPlugin>>]: (args: EventPayloads<TPlugin>[TEventName]) => Promise<void>;
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 StateExpiredPayloads<TPlugin extends common.BasePlugin> = {
149
- [TSateName in utils.StringKeys<IncomingStates<TPlugin>>]: ExtendedHandlerProps<TPlugin> & {
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 StateExpiredHandlers<TPlugin extends common.BasePlugin> = {
154
- [TSateName in utils.StringKeys<IncomingStates<TPlugin>>]: (args: StateExpiredPayloads<TPlugin>[TSateName]) => Promise<void>;
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 ActionHandlerPayloads<TPlugin extends common.BasePlugin> = {
157
- [TActionName in utils.StringKeys<TPlugin['actions']>]: ExtendedHandlerProps<TPlugin> & {
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 ActionHandlers<TPlugin extends common.BasePlugin> = {
163
- [TActionName in utils.StringKeys<TPlugin['actions']>]: (props: ActionHandlerPayloads<TPlugin>[TActionName]) => Promise<TPlugin['actions'][TActionName]['output']>;
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 WorkflowPayloads<TPlugin extends common.BasePlugin> = {
166
- [TWorkflowName in utils.StringKeys<TPlugin['workflows']>]: ExtendedHandlerProps<TPlugin> & {
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.WorkflowWithUtilities<TPlugin, TWorkflowName>;
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]) => Promise<void>;
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 HookInputs<TPlugin extends common.BasePlugin> = {
335
+ export type HookInputsWithoutInjectedProps<TPlugin extends common.BasePlugin> = {
263
336
  [THookType in utils.StringKeys<HookData<TPlugin>>]: {
264
- [THookDataName in utils.StringKeys<HookData<TPlugin>[THookType]>]: ExtendedHandlerProps<TPlugin> & {
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 HookHandlers<TPlugin extends common.BasePlugin> = {
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: HookInputs<TPlugin>[THookType][THookDataName]) => Promise<HookOutputs<TPlugin>[THookType][THookDataName] | undefined>;
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 ActionHandlersMap<TPlugin extends common.BasePlugin> = {
284
- [TActionName in utils.StringKeys<TPlugin['actions']>]?: (props: Omit<Parameters<ActionHandlers<TPlugin>[TActionName]>[0], keyof InjectedHandlerProps<TPlugin>>) => Promise<Awaited<ReturnType<ActionHandlers<TPlugin>[TActionName]>>>;
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]>]?: ((props: Omit<Parameters<HookHandlers<TPlugin>[THookType][THookDataName]>[0], keyof InjectedHandlerProps<TPlugin>>) => Promise<Awaited<ReturnType<HookHandlers<TPlugin>[THookType][THookDataName]>>>)[];
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<WorkflowHandlers<TPlugin>[TWorkflowName]>[0], keyof InjectedHandlerProps<TPlugin> | 'workflow'> & {
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: ActionHandlersMap<TPlugin>;
347
- messageHandlers: MessageHandlersMap<TPlugin>;
348
- eventHandlers: EventHandlersMap<TPlugin>;
349
- stateExpiredHandlers: StateExpiredHandlersMap<TPlugin>;
350
- hookHandlers: HookHandlersMap<TPlugin>;
351
- workflowHandlers: WorkflowHandlersMap<TPlugin>;
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,2 @@
1
+ export { proxyUsers, proxyUser } from './proxy';
2
+ export { UserFinder, ActionableUser } from './types';
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "@botpress/sdk",
3
- "version": "4.20.2",
3
+ "version": "5.0.0",
4
4
  "description": "Botpress SDK",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -1,2 +0,0 @@
1
- import * as utils from '../../utils/type-utils';
2
- export type ToTags<TTags extends string | number | symbol> = utils.Cast<Partial<Record<TTags, string>>, Record<string, string>>;
@@ -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;