@botpress/sdk 3.6.3 → 4.0.1

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.
@@ -96,26 +96,32 @@ export type UpdateUser<TIntegration extends common.BaseIntegration> = (x: utils.
96
96
  export type DeleteUser<_TIntegration extends common.BaseIntegration> = client.Client['deleteUser'];
97
97
  type StateResponse<TIntegration extends common.BaseIntegration, TState extends keyof TIntegration['states']> = {
98
98
  state: utils.Merge<Awaited<Res<client.Client['getState']>>['state'], {
99
- payload: TIntegration['states'][TState];
99
+ name: utils.Cast<TState, string>;
100
+ type: utils.Cast<TIntegration['states'][TState]['type'], string>;
101
+ payload: TIntegration['states'][TState]['payload'];
100
102
  }>;
101
103
  meta: {
102
104
  cached: boolean;
103
105
  };
104
106
  };
105
107
  export type GetState<TIntegration extends common.BaseIntegration> = <TState extends keyof TIntegration['states']>(x: utils.Merge<Arg<client.Client['getState']>, {
108
+ type: utils.Cast<TIntegration['states'][TState]['type'], string>;
106
109
  name: utils.Cast<TState, string>;
107
110
  }>) => Promise<StateResponse<TIntegration, TState>>;
108
111
  export type SetState<TIntegration extends common.BaseIntegration> = <TState extends keyof TIntegration['states']>(x: utils.Merge<Arg<client.Client['setState']>, {
109
112
  name: utils.Cast<TState, string>;
110
- payload: TIntegration['states'][TState] | null;
113
+ type: utils.Cast<TIntegration['states'][TState]['type'], string>;
114
+ payload: TIntegration['states'][TState]['payload'] | null;
111
115
  }>) => Promise<StateResponse<TIntegration, TState>>;
112
116
  export type GetOrSetState<TIntegration extends common.BaseIntegration> = <TState extends keyof TIntegration['states']>(x: utils.Merge<Arg<client.Client['getOrSetState']>, {
113
117
  name: utils.Cast<TState, string>;
114
- payload: TIntegration['states'][TState];
118
+ type: utils.Cast<TIntegration['states'][TState]['type'], string>;
119
+ payload: TIntegration['states'][TState]['payload'];
115
120
  }>) => Promise<StateResponse<TIntegration, TState>>;
116
121
  export type PatchState<TIntegration extends common.BaseIntegration> = <TState extends keyof TIntegration['states']>(x: utils.Merge<Arg<client.Client['patchState']>, {
117
122
  name: utils.Cast<TState, string>;
118
- payload: Partial<TIntegration['states'][TState]>;
123
+ type: utils.Cast<TIntegration['states'][TState]['type'], string>;
124
+ payload: Partial<TIntegration['states'][TState]['payload']>;
119
125
  }>) => Promise<StateResponse<TIntegration, TState>>;
120
126
  export type ConfigureIntegration<_TIntegration extends common.BaseIntegration> = client.Client['configureIntegration'];
121
127
  export type UploadFile<_TIntegration extends common.BaseIntegration> = client.Client['uploadFile'];
@@ -1,4 +1,5 @@
1
1
  import * as utils from '../../utils/type-utils';
2
+ import * as def from '../definition';
2
3
  export type BaseMessage = {
3
4
  tags: Record<string, any>;
4
5
  };
@@ -17,6 +18,10 @@ export type BaseAction = {
17
18
  input: any;
18
19
  output: any;
19
20
  };
21
+ export type BaseState = {
22
+ type: def.StateType;
23
+ payload: any;
24
+ };
20
25
  export type BaseIntegration = {
21
26
  name: string;
22
27
  version: string;
@@ -25,7 +30,7 @@ export type BaseIntegration = {
25
30
  actions: Record<string, BaseAction>;
26
31
  channels: Record<string, BaseChannel>;
27
32
  events: Record<string, any>;
28
- states: Record<string, any>;
33
+ states: Record<string, BaseState>;
29
34
  user: BaseUser;
30
35
  entities: Record<string, any>;
31
36
  };
@@ -48,8 +48,9 @@ export type ActionDefinition<TAction extends BaseActions[string] = BaseActions[s
48
48
  billable?: boolean;
49
49
  cacheable?: boolean;
50
50
  };
51
+ export type StateType = 'integration' | 'conversation' | 'user';
51
52
  export type StateDefinition<TState extends BaseStates[string] = BaseStates[string]> = SchemaDefinition<TState> & {
52
- type: 'integration' | 'conversation' | 'user';
53
+ type: StateType;
53
54
  };
54
55
  export type UserDefinition = Partial<{
55
56
  tags: Record<string, TagDefinition>;
package/dist/message.d.ts CHANGED
@@ -89,53 +89,53 @@ export declare const defaults: {
89
89
  value: import("@bpinternal/zui").ZodString;
90
90
  }, "strip", import("@bpinternal/zui").ZodTypeAny, {
91
91
  value: string;
92
- action: "postback" | "url" | "say";
92
+ action: "url" | "postback" | "say";
93
93
  label: string;
94
94
  }, {
95
95
  value: string;
96
- action: "postback" | "url" | "say";
96
+ action: "url" | "postback" | "say";
97
97
  label: string;
98
98
  }>, "many">;
99
99
  }, "strip", import("@bpinternal/zui").ZodTypeAny, {
100
100
  actions: {
101
101
  value: string;
102
- action: "postback" | "url" | "say";
102
+ action: "url" | "postback" | "say";
103
103
  label: string;
104
104
  }[];
105
105
  title: string;
106
- imageUrl?: string | undefined;
107
106
  subtitle?: string | undefined;
107
+ imageUrl?: string | undefined;
108
108
  }, {
109
109
  actions: {
110
110
  value: string;
111
- action: "postback" | "url" | "say";
111
+ action: "url" | "postback" | "say";
112
112
  label: string;
113
113
  }[];
114
114
  title: string;
115
- imageUrl?: string | undefined;
116
115
  subtitle?: string | undefined;
116
+ imageUrl?: string | undefined;
117
117
  }>, "many">;
118
118
  }, "strip", import("@bpinternal/zui").ZodTypeAny, {
119
119
  items: {
120
120
  actions: {
121
121
  value: string;
122
- action: "postback" | "url" | "say";
122
+ action: "url" | "postback" | "say";
123
123
  label: string;
124
124
  }[];
125
125
  title: string;
126
- imageUrl?: string | undefined;
127
126
  subtitle?: string | undefined;
127
+ imageUrl?: string | undefined;
128
128
  }[];
129
129
  }, {
130
130
  items: {
131
131
  actions: {
132
132
  value: string;
133
- action: "postback" | "url" | "say";
133
+ action: "url" | "postback" | "say";
134
134
  label: string;
135
135
  }[];
136
136
  title: string;
137
- imageUrl?: string | undefined;
138
137
  subtitle?: string | undefined;
138
+ imageUrl?: string | undefined;
139
139
  }[];
140
140
  }>;
141
141
  };
@@ -150,31 +150,31 @@ export declare const defaults: {
150
150
  value: import("@bpinternal/zui").ZodString;
151
151
  }, "strip", import("@bpinternal/zui").ZodTypeAny, {
152
152
  value: string;
153
- action: "postback" | "url" | "say";
153
+ action: "url" | "postback" | "say";
154
154
  label: string;
155
155
  }, {
156
156
  value: string;
157
- action: "postback" | "url" | "say";
157
+ action: "url" | "postback" | "say";
158
158
  label: string;
159
159
  }>, "many">;
160
160
  }, "strip", import("@bpinternal/zui").ZodTypeAny, {
161
161
  actions: {
162
162
  value: string;
163
- action: "postback" | "url" | "say";
163
+ action: "url" | "postback" | "say";
164
164
  label: string;
165
165
  }[];
166
166
  title: string;
167
- imageUrl?: string | undefined;
168
167
  subtitle?: string | undefined;
168
+ imageUrl?: string | undefined;
169
169
  }, {
170
170
  actions: {
171
171
  value: string;
172
- action: "postback" | "url" | "say";
172
+ action: "url" | "postback" | "say";
173
173
  label: string;
174
174
  }[];
175
175
  title: string;
176
- imageUrl?: string | undefined;
177
176
  subtitle?: string | undefined;
177
+ imageUrl?: string | undefined;
178
178
  }>;
179
179
  };
180
180
  readonly dropdown: {
@@ -243,15 +243,15 @@ export declare const defaults: {
243
243
  text: string;
244
244
  }>;
245
245
  }, "strip", import("@bpinternal/zui").ZodTypeAny, {
246
- type: "text";
247
246
  payload: {
248
247
  text: string;
249
248
  };
250
- }, {
251
249
  type: "text";
250
+ }, {
252
251
  payload: {
253
252
  text: string;
254
253
  };
254
+ type: "text";
255
255
  }>, import("@bpinternal/zui").ZodObject<{
256
256
  type: import("@bpinternal/zui").ZodLiteral<"markdown">;
257
257
  payload: import("@bpinternal/zui").ZodObject<{
@@ -262,15 +262,15 @@ export declare const defaults: {
262
262
  markdown: string;
263
263
  }>;
264
264
  }, "strip", import("@bpinternal/zui").ZodTypeAny, {
265
- type: "markdown";
266
265
  payload: {
267
266
  markdown: string;
268
267
  };
269
- }, {
270
268
  type: "markdown";
269
+ }, {
271
270
  payload: {
272
271
  markdown: string;
273
272
  };
273
+ type: "markdown";
274
274
  }>, import("@bpinternal/zui").ZodObject<{
275
275
  type: import("@bpinternal/zui").ZodLiteral<"image">;
276
276
  payload: import("@bpinternal/zui").ZodObject<{
@@ -281,15 +281,15 @@ export declare const defaults: {
281
281
  imageUrl: string;
282
282
  }>;
283
283
  }, "strip", import("@bpinternal/zui").ZodTypeAny, {
284
- type: "image";
285
284
  payload: {
286
285
  imageUrl: string;
287
286
  };
288
- }, {
289
287
  type: "image";
288
+ }, {
290
289
  payload: {
291
290
  imageUrl: string;
292
291
  };
292
+ type: "image";
293
293
  }>, import("@bpinternal/zui").ZodObject<{
294
294
  type: import("@bpinternal/zui").ZodLiteral<"audio">;
295
295
  payload: import("@bpinternal/zui").ZodObject<{
@@ -300,15 +300,15 @@ export declare const defaults: {
300
300
  audioUrl: string;
301
301
  }>;
302
302
  }, "strip", import("@bpinternal/zui").ZodTypeAny, {
303
- type: "audio";
304
303
  payload: {
305
304
  audioUrl: string;
306
305
  };
307
- }, {
308
306
  type: "audio";
307
+ }, {
309
308
  payload: {
310
309
  audioUrl: string;
311
310
  };
311
+ type: "audio";
312
312
  }>, import("@bpinternal/zui").ZodObject<{
313
313
  type: import("@bpinternal/zui").ZodLiteral<"video">;
314
314
  payload: import("@bpinternal/zui").ZodObject<{
@@ -319,15 +319,15 @@ export declare const defaults: {
319
319
  videoUrl: string;
320
320
  }>;
321
321
  }, "strip", import("@bpinternal/zui").ZodTypeAny, {
322
- type: "video";
323
322
  payload: {
324
323
  videoUrl: string;
325
324
  };
326
- }, {
327
325
  type: "video";
326
+ }, {
328
327
  payload: {
329
328
  videoUrl: string;
330
329
  };
330
+ type: "video";
331
331
  }>, import("@bpinternal/zui").ZodObject<{
332
332
  type: import("@bpinternal/zui").ZodLiteral<"file">;
333
333
  payload: import("@bpinternal/zui").ZodObject<{
@@ -341,17 +341,17 @@ export declare const defaults: {
341
341
  title?: string | undefined;
342
342
  }>;
343
343
  }, "strip", import("@bpinternal/zui").ZodTypeAny, {
344
- type: "file";
345
344
  payload: {
346
345
  fileUrl: string;
347
346
  title?: string | undefined;
348
347
  };
349
- }, {
350
348
  type: "file";
349
+ }, {
351
350
  payload: {
352
351
  fileUrl: string;
353
352
  title?: string | undefined;
354
353
  };
354
+ type: "file";
355
355
  }>, import("@bpinternal/zui").ZodObject<{
356
356
  type: import("@bpinternal/zui").ZodLiteral<"location">;
357
357
  payload: import("@bpinternal/zui").ZodObject<{
@@ -371,103 +371,103 @@ export declare const defaults: {
371
371
  address?: string | undefined;
372
372
  }>;
373
373
  }, "strip", import("@bpinternal/zui").ZodTypeAny, {
374
- type: "location";
375
374
  payload: {
376
375
  latitude: number;
377
376
  longitude: number;
378
377
  title?: string | undefined;
379
378
  address?: string | undefined;
380
379
  };
381
- }, {
382
380
  type: "location";
381
+ }, {
383
382
  payload: {
384
383
  latitude: number;
385
384
  longitude: number;
386
385
  title?: string | undefined;
387
386
  address?: string | undefined;
388
387
  };
388
+ type: "location";
389
389
  }>]>, "many">;
390
390
  }, "strip", import("@bpinternal/zui").ZodTypeAny, {
391
391
  items: ({
392
- type: "text";
393
392
  payload: {
394
393
  text: string;
395
394
  };
395
+ type: "text";
396
396
  } | {
397
- type: "markdown";
398
397
  payload: {
399
398
  markdown: string;
400
399
  };
400
+ type: "markdown";
401
401
  } | {
402
- type: "image";
403
402
  payload: {
404
403
  imageUrl: string;
405
404
  };
405
+ type: "image";
406
406
  } | {
407
- type: "audio";
408
407
  payload: {
409
408
  audioUrl: string;
410
409
  };
410
+ type: "audio";
411
411
  } | {
412
- type: "video";
413
412
  payload: {
414
413
  videoUrl: string;
415
414
  };
415
+ type: "video";
416
416
  } | {
417
- type: "file";
418
417
  payload: {
419
418
  fileUrl: string;
420
419
  title?: string | undefined;
421
420
  };
421
+ type: "file";
422
422
  } | {
423
- type: "location";
424
423
  payload: {
425
424
  latitude: number;
426
425
  longitude: number;
427
426
  title?: string | undefined;
428
427
  address?: string | undefined;
429
428
  };
429
+ type: "location";
430
430
  })[];
431
431
  }, {
432
432
  items: ({
433
- type: "text";
434
433
  payload: {
435
434
  text: string;
436
435
  };
436
+ type: "text";
437
437
  } | {
438
- type: "markdown";
439
438
  payload: {
440
439
  markdown: string;
441
440
  };
441
+ type: "markdown";
442
442
  } | {
443
- type: "image";
444
443
  payload: {
445
444
  imageUrl: string;
446
445
  };
446
+ type: "image";
447
447
  } | {
448
- type: "audio";
449
448
  payload: {
450
449
  audioUrl: string;
451
450
  };
451
+ type: "audio";
452
452
  } | {
453
- type: "video";
454
453
  payload: {
455
454
  videoUrl: string;
456
455
  };
456
+ type: "video";
457
457
  } | {
458
- type: "file";
459
458
  payload: {
460
459
  fileUrl: string;
461
460
  title?: string | undefined;
462
461
  };
462
+ type: "file";
463
463
  } | {
464
- type: "location";
465
464
  payload: {
466
465
  latitude: number;
467
466
  longitude: number;
468
467
  title?: string | undefined;
469
468
  address?: string | undefined;
470
469
  };
470
+ type: "location";
471
471
  })[];
472
472
  }>;
473
473
  };
@@ -1,5 +1,5 @@
1
1
  import { Client } from '@botpress/client';
2
2
  import { BotSpecificClient } from '../../bot';
3
- import { BasePlugin, PluginInterfaceExtensions } from '../common';
3
+ import { BasePlugin, PluginRuntimeProps } from '../common';
4
4
  import { ActionProxy } from './types';
5
- export declare const proxyActions: <TPlugin extends BasePlugin>(client: BotSpecificClient<TPlugin> | Client, interfaces: PluginInterfaceExtensions<TPlugin>) => ActionProxy<TPlugin>;
5
+ export declare const proxyActions: <TPlugin extends BasePlugin>(client: BotSpecificClient<TPlugin> | Client, props: PluginRuntimeProps<TPlugin>) => ActionProxy<TPlugin>;
@@ -1,3 +1,4 @@
1
+ import * as bot from '../../bot';
1
2
  import { BaseIntegration, DefaultIntegration, InputBaseIntegration } from '../../integration/common/generic';
2
3
  import { BaseInterface, InputBaseInterface, DefaultInterface } from '../../interface/common/generic';
3
4
  import * as utils from '../../utils/type-utils';
@@ -15,6 +16,10 @@ export type BaseWorkflow = {
15
16
  [k: string]: string;
16
17
  };
17
18
  };
19
+ export type BaseState = {
20
+ type: bot.StateType;
21
+ payload: any;
22
+ };
18
23
  export type BasePlugin = {
19
24
  name: string;
20
25
  version: string;
@@ -22,7 +27,7 @@ export type BasePlugin = {
22
27
  integrations: Record<string, BaseIntegration>;
23
28
  interfaces: Record<string, BaseInterface>;
24
29
  events: Record<string, any>;
25
- states: Record<string, any>;
30
+ states: Record<string, BaseState>;
26
31
  actions: Record<string, BaseAction>;
27
32
  tables: Record<string, BaseTable>;
28
33
  workflows: Record<string, BaseWorkflow>;
@@ -38,4 +38,10 @@ export type PluginInterfaceExtension<TInterface extends BaseInterface = BaseInte
38
38
  export type PluginInterfaceExtensions<TPlugin extends BasePlugin = BasePlugin> = {
39
39
  [K in keyof TPlugin['interfaces']]: PluginInterfaceExtension<TPlugin['interfaces'][K]>;
40
40
  };
41
+ export type PluginConfiguration<TPlugin extends BasePlugin> = TPlugin['configuration'];
42
+ export type PluginRuntimeProps<TPlugin extends BasePlugin = BasePlugin> = {
43
+ alias?: string;
44
+ configuration: PluginConfiguration<TPlugin>;
45
+ interfaces: PluginInterfaceExtensions<TPlugin>;
46
+ };
41
47
  export {};
@@ -1,15 +1,10 @@
1
1
  import type { MessageHandlersMap as BotMessageHandlersMap, EventHandlersMap as BotEventHandlersMap, StateExpiredHandlersMap as BotStateExpiredHandlersMap, HookHandlersMap as BotHookHandlersMap, WorkflowHandlersMap as BotWorkflowHandlersMap, ActionHandlers as BotActionHandlers, BotHandlers } from '../bot';
2
2
  import * as utils from '../utils';
3
- import { BasePlugin, PluginInterfaceExtensions } from './common';
4
- import { ActionHandlers, MessageHandlers, EventHandlers, StateExpiredHandlers, HookHandlers, WorkflowHandlers, MessageHandlersMap, EventHandlersMap, StateExpiredHandlersMap, HookHandlersMap, WorkflowHandlersMap, PluginConfiguration } from './server/types';
3
+ import { BasePlugin, PluginRuntimeProps } from './common';
4
+ import { ActionHandlers, MessageHandlers, EventHandlers, StateExpiredHandlers, HookHandlers, WorkflowHandlers, MessageHandlersMap, EventHandlersMap, StateExpiredHandlersMap, HookHandlersMap, WorkflowHandlersMap } from './server/types';
5
5
  export type PluginImplementationProps<TPlugin extends BasePlugin = BasePlugin> = {
6
6
  actions: ActionHandlers<TPlugin>;
7
7
  };
8
- export type PluginRuntimeProps<TPlugin extends BasePlugin = BasePlugin> = {
9
- alias?: string;
10
- configuration: PluginConfiguration<TPlugin>;
11
- interfaces: PluginInterfaceExtensions<TPlugin>;
12
- };
13
8
  export declare class PluginImplementation<TPlugin extends BasePlugin = BasePlugin> implements BotHandlers<TPlugin> {
14
9
  readonly props: PluginImplementationProps<TPlugin>;
15
10
  private _runtimeProps;
@@ -4,6 +4,7 @@ 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 stateProxy from '../state-proxy';
7
8
  type EnumeratePluginEvents<TPlugin extends common.BasePlugin> = bot.EnumerateEvents<TPlugin> & common.EnumerateInterfaceEvents<TPlugin>;
8
9
  type _IncomingEvents<TPlugin extends common.BasePlugin> = {
9
10
  [K in utils.StringKeys<EnumeratePluginEvents<TPlugin>>]: utils.Merge<client.Event, {
@@ -76,14 +77,14 @@ export type OutgoingCallActionResponses<TPlugin extends common.BasePlugin> = _Ou
76
77
  '*': AnyOutgoingCallActionResponse<TPlugin>;
77
78
  };
78
79
  export type PluginClient<_TPlugin extends common.BasePlugin> = bot.BotSpecificClient<common.BasePlugin>;
79
- export type PluginConfiguration<TPlugin extends common.BasePlugin> = TPlugin['configuration'];
80
80
  export type CommonHandlerProps<TPlugin extends common.BasePlugin> = {
81
81
  ctx: bot.BotContext;
82
82
  logger: bot.BotLogger;
83
83
  client: PluginClient<TPlugin>;
84
- configuration: PluginConfiguration<TPlugin>;
84
+ configuration: common.PluginConfiguration<TPlugin>;
85
85
  interfaces: common.PluginInterfaceExtensions<TPlugin>;
86
86
  actions: actionProxy.ActionProxy<TPlugin>;
87
+ states: stateProxy.StateProxy<TPlugin>;
87
88
  /**
88
89
  * # EXPERIMENTAL
89
90
  * This API is experimental and may change in the future.
@@ -96,12 +97,6 @@ export type MessagePayloads<TPlugin extends common.BasePlugin> = {
96
97
  user: client.User;
97
98
  conversation: client.Conversation;
98
99
  event: client.Event;
99
- states: {
100
- [TState in utils.StringKeys<TPlugin['states']>]: {
101
- type: 'user' | 'conversation' | 'bot';
102
- payload: TPlugin['states'][TState];
103
- };
104
- };
105
100
  };
106
101
  };
107
102
  export type MessageHandlers<TPlugin extends common.BasePlugin> = {
@@ -0,0 +1,2 @@
1
+ export * from './proxy';
2
+ export * from './types';
@@ -0,0 +1,5 @@
1
+ import { Client } from '@botpress/client';
2
+ import { BotSpecificClient } from '../../bot';
3
+ import { BasePlugin, PluginRuntimeProps } from '../common';
4
+ import { StateProxy } from './types';
5
+ export declare const proxyStates: <TPlugin extends BasePlugin>(client: BotSpecificClient<TPlugin> | Client, props: PluginRuntimeProps<TPlugin>) => StateProxy<TPlugin>;
@@ -0,0 +1,25 @@
1
+ import * as bot from '../../bot';
2
+ import * as utils from '../../utils/type-utils';
3
+ import { BasePlugin } from '../common';
4
+ type _EnumerateStates<TPlugin extends BasePlugin> = {
5
+ [TStateName in keyof TPlugin['states']]: TPlugin['states'][TStateName] & {
6
+ name: TStateName;
7
+ };
8
+ };
9
+ type _FilterStates<TPlugin extends BasePlugin, TStateType extends bot.StateType> = Extract<utils.ValueOf<_EnumerateStates<TPlugin>>, {
10
+ type: TStateType;
11
+ }>['name'];
12
+ type _GetStatePayload<TPlugin extends BasePlugin, TStateName extends string | number | symbol> = TPlugin['states'][utils.Cast<TStateName, keyof TPlugin['states']>]['payload'];
13
+ export type StateRepo<TPayload> = {
14
+ get: (id: string) => Promise<TPayload>;
15
+ set: (id: string, payload: TPayload) => Promise<void>;
16
+ getOrSet: (id: string, payload: TPayload) => Promise<TPayload>;
17
+ delete: (id: string) => Promise<void>;
18
+ patch: (id: string, payload: Partial<TPayload>) => Promise<void>;
19
+ };
20
+ export type StateProxy<TPlugin extends BasePlugin> = utils.Normalize<{
21
+ [TStateType in bot.StateType]: {
22
+ [TStateName in _FilterStates<TPlugin, TStateType>]: StateRepo<_GetStatePayload<TPlugin, TStateName>>;
23
+ };
24
+ }>;
25
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,3 +1,4 @@
1
+ export type Function<I extends any[] = any, O extends any = any> = (...args: I) => O;
1
2
  export type ValueOf<T> = T[keyof T];
2
3
  export type Merge<A extends object, B extends object> = Omit<A, keyof B> & B;
3
4
  export type Cast<T, U> = T extends U ? T : U;
@@ -6,6 +7,9 @@ export type Writable<T> = {
6
7
  -readonly [K in keyof T]: T[K];
7
8
  };
8
9
  export type Default<T, U> = undefined extends T ? U : T;
10
+ export type Not<X extends boolean> = X extends true ? false : true;
11
+ export type And<X extends boolean, Y extends boolean> = X extends true ? (Y extends true ? true : false) : false;
12
+ export type Or<X extends boolean, Y extends boolean> = X extends true ? true : Y extends true ? true : false;
9
13
  export type AtLeastOne<T> = [T, ...T[]];
10
14
  export type AtLeastOneProperty<T> = T extends undefined ? {} : {
11
15
  [K in keyof T]?: T[K];
@@ -23,6 +27,12 @@ export type IsExtend<X, Y> = X extends Y ? true : false;
23
27
  export type IsEquivalent<X, Y> = IsExtend<X, Y> extends true ? IsExtend<Y, X> : false;
24
28
  export type IsIdentical<X, Y> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? true : false;
25
29
  export type IsEqual<X, Y> = IsIdentical<Normalize<X>, Normalize<Y>>;
30
+ /**
31
+ * For F1 function to extend F2 function,
32
+ * F2 input should extend F1 input so that if you call F1 thinking it is F2, it still works.
33
+ * IsStricterFunction is not an extension check as it allows F1 to require a stricter input than F2.
34
+ */
35
+ export type IsStricterFunction<F1 extends Function, F2 extends Function> = And<IsExtend<ReturnType<F1>, ReturnType<F2>>, IsExtend<Parameters<F1>, Parameters<F2>>>;
26
36
  export type AssertExtends<_A extends B, B> = true;
27
37
  export type AssertNotExtends<A, B> = A extends B ? false : true;
28
38
  export type AssertTrue<_T extends true> = true;
@@ -36,10 +46,13 @@ export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) ex
36
46
  export type ToSealedRecord<R extends Record<string, any>> = {
37
47
  [K in keyof R as string extends K ? never : K]: R[K];
38
48
  };
49
+ type NormalizeTuple<T> = T extends [...infer A] ? {
50
+ [K in keyof A]: Normalize<A[K]>;
51
+ } : never;
39
52
  type NormalizeObject<T extends object> = T extends infer O ? {
40
53
  [K in keyof O]: Normalize<O[K]>;
41
54
  } : never;
42
- export type Normalize<T> = T extends (...args: infer A) => infer R ? (...args: Normalize<A>) => Normalize<R> : T extends Array<infer E> ? Array<Normalize<E>> : T extends ReadonlyArray<infer E> ? ReadonlyArray<Normalize<E>> : T extends Promise<infer R> ? Promise<Normalize<R>> : T extends Buffer ? Buffer : T extends object ? NormalizeObject<T> : T;
55
+ export type Normalize<T> = T extends (...args: infer A) => infer R ? (...args: NormalizeTuple<A>) => Normalize<R> : T extends Array<infer E> ? Array<Normalize<E>> : T extends ReadonlyArray<infer E> ? ReadonlyArray<Normalize<E>> : T extends Promise<infer R> ? Promise<Normalize<R>> : T extends Buffer ? Buffer : T extends object ? NormalizeObject<T> : T;
43
56
  type DeepPartialObject<T extends object> = T extends infer O ? {
44
57
  [K in keyof O]?: DeepPartial<O[K]>;
45
58
  } : never;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botpress/sdk",
3
- "version": "3.6.3",
3
+ "version": "4.0.1",
4
4
  "description": "Botpress SDK",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -16,7 +16,7 @@
16
16
  "author": "",
17
17
  "license": "MIT",
18
18
  "dependencies": {
19
- "@botpress/client": "0.48.3",
19
+ "@botpress/client": "1.0.0",
20
20
  "browser-or-node": "^2.1.1"
21
21
  },
22
22
  "devDependencies": {