@botpress/sdk 3.2.0 → 3.3.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 +4 -4
- package/dist/fixtures.d.ts +49 -0
- package/dist/index.mjs +17 -17
- package/dist/index.mjs.map +3 -3
- package/dist/integration/client/sub-types.d.ts +30 -0
- package/dist/integration/client/sub-types.test.d.ts +1 -0
- package/dist/integration/client/types.d.ts +25 -32
- package/dist/integration/common/types.d.ts +1 -3
- package/package.json +7 -3
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as utils from '../../utils/type-utils';
|
|
2
|
+
import * as common from '../common';
|
|
3
|
+
export type EnumerateMessages<TIntegration extends common.BaseIntegration> = utils.UnionToIntersection<utils.ValueOf<{
|
|
4
|
+
[TChannelName in keyof TIntegration['channels']]: {
|
|
5
|
+
[TMessageName in keyof TIntegration['channels'][TChannelName]['messages']]: {
|
|
6
|
+
tags: TIntegration['channels'][TChannelName]['message']['tags'];
|
|
7
|
+
payload: TIntegration['channels'][TChannelName]['messages'][TMessageName];
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
}>>;
|
|
11
|
+
export type GetChannelByName<TIntegration extends common.BaseIntegration, TChannelName extends keyof TIntegration['channels']> = utils.Cast<TIntegration['channels'][TChannelName], common.BaseChannel>;
|
|
12
|
+
export type GetMessageByName<TIntegration extends common.BaseIntegration, TMessageName extends keyof EnumerateMessages<TIntegration>> = utils.Cast<EnumerateMessages<TIntegration>[TMessageName], {
|
|
13
|
+
tags: Record<string, any>;
|
|
14
|
+
payload: any;
|
|
15
|
+
}>;
|
|
16
|
+
export type ConversationTags<TIntegration extends common.BaseIntegration> = keyof utils.UnionToIntersection<utils.ValueOf<{
|
|
17
|
+
[TChannelName in keyof TIntegration['channels']]: TIntegration['channels'][TChannelName]['conversation']['tags'];
|
|
18
|
+
}>>;
|
|
19
|
+
export type MessageTags<TIntegration extends common.BaseIntegration> = keyof utils.UnionToIntersection<utils.ValueOf<{
|
|
20
|
+
[TChannelName in keyof TIntegration['channels']]: TIntegration['channels'][TChannelName]['message']['tags'];
|
|
21
|
+
}>>;
|
|
22
|
+
export type TagsOfMessage<TIntegration extends common.BaseIntegration, TMessageName extends keyof EnumerateMessages<TIntegration>> = keyof utils.UnionToIntersection<GetMessageByName<TIntegration, TMessageName>['tags']>;
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated Integration's should no longer use their name as prefix for event types or tags.
|
|
25
|
+
*/
|
|
26
|
+
export type WithRequiredPrefix<TTags extends string, TPrefix extends string> = string extends TTags ? string : utils.Join<[TPrefix, ':', TTags]>;
|
|
27
|
+
/**
|
|
28
|
+
* @deprecated Integration's should no longer use their name as prefix for event types or tags.
|
|
29
|
+
*/
|
|
30
|
+
export type WithOptionalPrefix<TTags extends string, TPrefix extends string> = TTags | WithRequiredPrefix<TTags, TPrefix>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,19 +1,9 @@
|
|
|
1
1
|
import * as client from '@botpress/client';
|
|
2
2
|
import * as utils from '../../utils/type-utils';
|
|
3
3
|
import * as common from '../common';
|
|
4
|
-
|
|
5
|
-
type GetChannelByName<TIntegration extends common.BaseIntegration, TChannelName extends keyof TIntegration['channels']> = utils.Cast<TIntegration['channels'][TChannelName], BaseChannelDefinition>;
|
|
6
|
-
/**
|
|
7
|
-
* @deprecated Integration's should no longer use their name as prefix for event types or tags.
|
|
8
|
-
*/
|
|
9
|
-
type WithRequiredPrefix<TTags extends string, TPrefix extends string> = string extends TTags ? string : utils.Join<[TPrefix, ':', TTags]>;
|
|
10
|
-
/**
|
|
11
|
-
* @deprecated Integration's should no longer use their name as prefix for event types or tags.
|
|
12
|
-
*/
|
|
13
|
-
type WithOptionalPrefix<TTags extends string, TPrefix extends string> = TTags | WithRequiredPrefix<TTags, TPrefix>;
|
|
4
|
+
import { EnumerateMessages, ConversationTags, GetChannelByName, GetMessageByName, MessageTags, WithOptionalPrefix, WithRequiredPrefix, TagsOfMessage } from './sub-types';
|
|
14
5
|
type Arg<F extends (...args: any[]) => any> = Parameters<F>[number];
|
|
15
6
|
type Res<F extends (...args: any[]) => any> = ReturnType<F>;
|
|
16
|
-
type AllChannels<TIntegration extends common.BaseIntegration> = utils.ValueOf<TIntegration['channels']>;
|
|
17
7
|
type ConversationResponse<TIntegration extends common.BaseIntegration, ChannelName extends keyof TIntegration['channels'] = keyof TIntegration['channels']> = {
|
|
18
8
|
conversation: utils.Merge<Awaited<Res<client.Client['getConversation']>>['conversation'], {
|
|
19
9
|
channel: ChannelName;
|
|
@@ -29,12 +19,13 @@ export type ListConversations<TIntegration extends common.BaseIntegration> = <Ch
|
|
|
29
19
|
channel?: utils.Cast<ChannelName, string>;
|
|
30
20
|
tags?: common.ToTags<keyof GetChannelByName<TIntegration, ChannelName>['conversation']['tags']>;
|
|
31
21
|
}>) => Res<client.Client['listConversations']>;
|
|
32
|
-
export type GetOrCreateConversation<TIntegration extends common.BaseIntegration> = <ChannelName extends keyof TIntegration['channels']>(x: {
|
|
22
|
+
export type GetOrCreateConversation<TIntegration extends common.BaseIntegration> = <ChannelName extends keyof TIntegration['channels'], TTags extends keyof GetChannelByName<TIntegration, ChannelName>['conversation']['tags']>(x: utils.Merge<Arg<client.Client['getOrCreateConversation']>, {
|
|
33
23
|
channel: utils.Cast<ChannelName, string>;
|
|
34
|
-
tags: common.ToTags<
|
|
35
|
-
|
|
24
|
+
tags: common.ToTags<TTags>;
|
|
25
|
+
discriminateByTags?: NoInfer<utils.Cast<TTags[], string[]>>;
|
|
26
|
+
}>) => Promise<ConversationResponse<TIntegration, ChannelName>>;
|
|
36
27
|
export type UpdateConversation<TIntegration extends common.BaseIntegration> = (x: utils.Merge<Arg<client.Client['updateConversation']>, {
|
|
37
|
-
tags?: common.ToTags<
|
|
28
|
+
tags?: common.ToTags<ConversationTags<TIntegration>>;
|
|
38
29
|
}>) => Promise<ConversationResponse<TIntegration>>;
|
|
39
30
|
export type DeleteConversation<_TIntegration extends common.BaseIntegration> = client.Client['deleteConversation'];
|
|
40
31
|
export type ListParticipants<_TIntegration extends common.BaseIntegration> = client.Client['listParticipants'];
|
|
@@ -57,29 +48,30 @@ export type GetEvent<TIntegration extends common.BaseIntegration> = (x: Arg<clie
|
|
|
57
48
|
export type ListEvents<TIntegration extends common.BaseIntegration> = (x: utils.Merge<Arg<client.Client['listEvents']>, {
|
|
58
49
|
type?: WithRequiredPrefix<utils.Cast<keyof TIntegration['events'], string>, TIntegration['name']>;
|
|
59
50
|
}>) => Res<client.Client['listEvents']>;
|
|
60
|
-
type MessageResponse<TIntegration extends common.BaseIntegration,
|
|
51
|
+
type MessageResponse<TIntegration extends common.BaseIntegration, TMessage extends keyof EnumerateMessages<TIntegration> = keyof EnumerateMessages<TIntegration>> = {
|
|
61
52
|
message: utils.Merge<Awaited<Res<client.Client['createMessage']>>['message'], {
|
|
62
53
|
type: utils.Cast<TMessage, string>;
|
|
63
|
-
payload: TIntegration['
|
|
64
|
-
tags: common.ToTags<
|
|
54
|
+
payload: GetMessageByName<TIntegration, TMessage>['payload'];
|
|
55
|
+
tags: common.ToTags<TagsOfMessage<TIntegration, TMessage>>;
|
|
65
56
|
}>;
|
|
66
57
|
};
|
|
67
|
-
export type CreateMessage<TIntegration extends common.BaseIntegration> = <
|
|
58
|
+
export type CreateMessage<TIntegration extends common.BaseIntegration> = <TMessage extends keyof EnumerateMessages<TIntegration>>(x: utils.Merge<Arg<client.Client['createMessage']>, {
|
|
68
59
|
type: utils.Cast<TMessage, string>;
|
|
69
|
-
payload: TIntegration['
|
|
70
|
-
tags: common.ToTags<keyof TIntegration['
|
|
71
|
-
}>) => Promise<MessageResponse<TIntegration,
|
|
72
|
-
export type GetOrCreateMessage<TIntegration extends common.BaseIntegration> = <
|
|
60
|
+
payload: GetMessageByName<TIntegration, TMessage>['payload'];
|
|
61
|
+
tags: common.ToTags<keyof GetMessageByName<TIntegration, TMessage>['tags']>;
|
|
62
|
+
}>) => Promise<MessageResponse<TIntegration, TMessage>>;
|
|
63
|
+
export type GetOrCreateMessage<TIntegration extends common.BaseIntegration> = <TMessage extends keyof EnumerateMessages<TIntegration>, TTags extends keyof GetMessageByName<TIntegration, TMessage>['tags']>(x: utils.Merge<Arg<client.Client['getOrCreateMessage']>, {
|
|
73
64
|
type: utils.Cast<TMessage, string>;
|
|
74
|
-
payload: TIntegration['
|
|
75
|
-
tags: common.ToTags<
|
|
76
|
-
|
|
77
|
-
|
|
65
|
+
payload: GetMessageByName<TIntegration, TMessage>['payload'];
|
|
66
|
+
tags: common.ToTags<TTags>;
|
|
67
|
+
discriminateByTags?: NoInfer<utils.Cast<TTags[], string[]>>;
|
|
68
|
+
}>) => Promise<MessageResponse<TIntegration, TMessage>>;
|
|
69
|
+
export type GetMessage<TIntegration extends common.BaseIntegration> = (x: Arg<client.Client['getMessage']>) => Promise<MessageResponse<TIntegration>>;
|
|
78
70
|
export type UpdateMessage<TIntegration extends common.BaseIntegration> = (x: utils.Merge<Arg<client.Client['updateMessage']>, {
|
|
79
|
-
tags: common.ToTags<
|
|
80
|
-
}>) => Promise<MessageResponse<TIntegration
|
|
71
|
+
tags: common.ToTags<MessageTags<TIntegration>>;
|
|
72
|
+
}>) => Promise<MessageResponse<TIntegration>>;
|
|
81
73
|
export type ListMessages<TIntegration extends common.BaseIntegration> = (x: utils.Merge<Arg<client.Client['listMessages']>, {
|
|
82
|
-
tags?: common.ToTags<
|
|
74
|
+
tags?: common.ToTags<MessageTags<TIntegration>>;
|
|
83
75
|
}>) => Res<client.Client['listMessages']>;
|
|
84
76
|
export type DeleteMessage<_TIntegration extends common.BaseIntegration> = client.Client['deleteMessage'];
|
|
85
77
|
type UserResponse<TIntegration extends common.BaseIntegration> = {
|
|
@@ -94,8 +86,9 @@ export type GetUser<TIntegration extends common.BaseIntegration> = (x: Arg<clien
|
|
|
94
86
|
export type ListUsers<TIntegration extends common.BaseIntegration> = (x: utils.Merge<Arg<client.Client['listUsers']>, {
|
|
95
87
|
tags?: common.ToTags<keyof TIntegration['user']['tags']>;
|
|
96
88
|
}>) => Res<client.Client['listUsers']>;
|
|
97
|
-
export type GetOrCreateUser<TIntegration extends common.BaseIntegration> = (x: utils.Merge<Arg<client.Client['getOrCreateUser']>, {
|
|
98
|
-
tags: common.ToTags<
|
|
89
|
+
export type GetOrCreateUser<TIntegration extends common.BaseIntegration> = <TTags extends keyof TIntegration['user']['tags']>(x: utils.Merge<Arg<client.Client['getOrCreateUser']>, {
|
|
90
|
+
tags: common.ToTags<TTags>;
|
|
91
|
+
discriminateByTags?: NoInfer<utils.Cast<TTags[], string[]>>;
|
|
99
92
|
}>) => Promise<UserResponse<TIntegration>>;
|
|
100
93
|
export type UpdateUser<TIntegration extends common.BaseIntegration> = (x: utils.Merge<Arg<client.Client['updateUser']>, {
|
|
101
94
|
tags?: common.ToTags<keyof TIntegration['user']['tags']>;
|
|
@@ -1,4 +1,2 @@
|
|
|
1
1
|
import * as utils from '../../utils/type-utils';
|
|
2
|
-
type
|
|
3
|
-
export type ToTags<TTags extends string | number | symbol> = AsTags<Partial<Record<utils.Cast<TTags, string>, string>>>;
|
|
4
|
-
export {};
|
|
2
|
+
export type ToTags<TTags extends string | number | symbol> = utils.Cast<Partial<Record<TTags, string>>, Record<string, string>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botpress/sdk",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
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.
|
|
19
|
+
"@botpress/client": "0.47.0",
|
|
20
20
|
"browser-or-node": "^2.1.1"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
@@ -32,5 +32,9 @@
|
|
|
32
32
|
"esbuild": {
|
|
33
33
|
"optional": true
|
|
34
34
|
}
|
|
35
|
-
}
|
|
35
|
+
},
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=18.0.0"
|
|
38
|
+
},
|
|
39
|
+
"packageManager": "pnpm@8.6.2"
|
|
36
40
|
}
|