diff --git a/.vscode/extensions.json b/.vscode/extensions.json index c67ec6d1be4..8e66a3f02bf 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,3 +1,3 @@ { - "recommendations": ["esbenp.prettier-vscode", "oxc.oxc-vscode"] + "recommendations": ["esbenp.prettier-vscode", "oxc.oxc-vscode", "vitest.explorer"] } diff --git a/.vscode/settings.json b/.vscode/settings.json index a074b2f651b..63abb6258a3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,6 +7,6 @@ }, "editor.tabSize": 2, "git.branchProtection": ["master"], - "typescript.tsdk": "node_modules/typescript/lib", - "vitest.disableWorkspaceWarning": true + "vitest.disableWorkspaceWarning": true, + "js/ts.tsdk.path": "node_modules/typescript/lib" } diff --git a/integrations/hubspot/integration.definition.ts b/integrations/hubspot/integration.definition.ts index 1d2855e98b6..a4b29017598 100644 --- a/integrations/hubspot/integration.definition.ts +++ b/integrations/hubspot/integration.definition.ts @@ -6,7 +6,7 @@ export default new IntegrationDefinition({ name: 'hubspot', title: 'HubSpot', description: 'Manage contacts, tickets and more from your chatbot.', - version: '6.0.0', + version: '6.0.1', readme: 'hub.md', icon: 'icon.svg', configuration: { diff --git a/integrations/hubspot/linkTemplate.vrl b/integrations/hubspot/linkTemplate.vrl index 23372049f7a..bd91eed7b39 100644 --- a/integrations/hubspot/linkTemplate.vrl +++ b/integrations/hubspot/linkTemplate.vrl @@ -1,4 +1,9 @@ webhookId = to_string!(.webhookId) webhookUrl = to_string!(.webhookUrl) +source = to_string!(.source) ?? "" -"{{ webhookUrl }}/oauth/wizard/start?state={{ webhookId }}" +if source == "desk" { + "{{ webhookUrl }}/oauth/wizard/start?state={{ webhookId }}&wizchoice=without-hitl" +} else { + "{{ webhookUrl }}/oauth/wizard/start?state={{ webhookId }}" +} diff --git a/package.json b/package.json index 145f943ccf3..f9b5d4aa381 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ }, "devDependencies": { "@aws-sdk/client-dynamodb": "^3.564.0", - "@botpress/api": "1.99.0", + "@botpress/api": "1.102.0", "@botpress/cli": "workspace:*", "@botpress/client": "workspace:*", "@botpress/sdk": "workspace:*", diff --git a/packages/common/src/entity-helpers/create-or-update-user.ts b/packages/common/src/entity-helpers/create-or-update-user.ts index 99b049aafe6..1898c3ec777 100644 --- a/packages/common/src/entity-helpers/create-or-update-user.ts +++ b/packages/common/src/entity-helpers/create-or-update-user.ts @@ -4,6 +4,8 @@ import * as sdk from '@botpress/sdk' // this type is not exported by the sdk: it's a placeholder for the integration type type BaseIntegration = sdk.DefaultIntegration +type Cast = T extends U ? T : U + /** * Creates or updates a user based on the provided input. * If a user is found with the same discriminating tags, it will be updated. @@ -15,26 +17,28 @@ type BaseIntegration = sdk.DefaultIntegration export const createOrUpdateUser = async < Client extends sdk.IntegrationSpecificClient, TIntegration extends BaseIntegration = Client extends sdk.IntegrationSpecificClient ? TI : never, - CreateProps extends Parameters[0] = Parameters[0], + CreateProps extends Parameters[0] = Parameters[0], DiscriminatingTags extends Extract = Extract, >( props: CreateProps & { client: Client; discriminateByTags?: DiscriminatingTags[] } -): Promise>> => { +): Promise>> => { const { users: matchingUsers } = await props.client.listUsers({ tags: _getFilteredTags(props) }) if (matchingUsers.length > 1) { throw new sdk.RuntimeError('Multiple users found with the same discriminating tags') } + type UserTags = keyof TIntegration['user']['tags'] + const updateTags: Partial> = { ...matchingUsers[0]!.tags, ...props.tags } return ( matchingUsers.length === 1 ? await props.client.updateUser({ ...matchingUsers[0]!, ...props, - tags: { ...matchingUsers[0]!.tags, ...props.tags }, + tags: updateTags as Cast>, }) : await props.client.createUser(props) - ) as Awaited> + ) as Awaited> } const _getFilteredTags = ({ diff --git a/packages/sdk/src/common/types.ts b/packages/sdk/src/common/types.ts index 868a15a94be..6b1094ff2cd 100644 --- a/packages/sdk/src/common/types.ts +++ b/packages/sdk/src/common/types.ts @@ -8,6 +8,11 @@ export type ToTags = typeUtils.Cast< Record > +export type ToNullableTags = typeUtils.Cast< + Partial>, + Record +> + export type SchemaTransformOptions = { useLegacyZuiTransformer?: boolean toJSONSchemaOptions?: Partial diff --git a/packages/sdk/src/integration/client/sub-types.ts b/packages/sdk/src/integration/client/sub-types.ts index 8b8ceb6b613..884b9c1f161 100644 --- a/packages/sdk/src/integration/client/sub-types.ts +++ b/packages/sdk/src/integration/client/sub-types.ts @@ -1,4 +1,3 @@ -import { commonTypes } from '../../common' import * as utils from '../../utils/type-utils' import * as common from '../common' @@ -45,9 +44,7 @@ export type MessageTags = keyof uti }> > -export type UserTags = commonTypes.ToTags< - keyof TIntegration['user']['tags'] -> +export type UserTags = keyof TIntegration['user']['tags'] export type TagsOfMessage< TIntegration extends common.BaseIntegration, diff --git a/packages/sdk/src/integration/client/types.ts b/packages/sdk/src/integration/client/types.ts index 9453afd5bd3..ba42fae8fcb 100644 --- a/packages/sdk/src/integration/client/types.ts +++ b/packages/sdk/src/integration/client/types.ts @@ -79,7 +79,7 @@ export type GetOrCreateConversation Arg, { channel: utils.Cast - tags: commonTypes.ToTags + tags: commonTypes.ToNullableTags discriminateByTags?: NoInfer> } > @@ -89,7 +89,7 @@ export type UpdateConversation = ( x: utils.Merge< Arg, { - tags?: commonTypes.ToTags> + tags?: commonTypes.ToNullableTags> } > ) => Promise> @@ -181,7 +181,7 @@ export type GetOrCreateMessage = < { type: utils.Cast payload?: GetMessageByName['payload'] - tags: commonTypes.ToTags + tags: commonTypes.ToNullableTags // TODO: find a way to restrict discriminateByTags to tags present in x.tags discriminateByTags?: NoInfer> } @@ -196,7 +196,7 @@ export type UpdateMessage = ( x: utils.Merge< Arg, { - tags: commonTypes.ToTags> + tags?: commonTypes.ToNullableTags> } > ) => Promise> @@ -216,7 +216,7 @@ type UserResponse = { user: utils.Merge< Awaited>['user'], { - tags: UserTags + tags: commonTypes.ToTags> } > } @@ -225,7 +225,7 @@ export type CreateUser = ( x: utils.Merge< Arg, { - tags: UserTags + tags: commonTypes.ToTags> } > ) => Promise> @@ -238,7 +238,7 @@ export type ListUsers = ( x: utils.Merge< Arg, { - tags?: UserTags + tags?: commonTypes.ToTags> } > ) => Res @@ -246,7 +246,12 @@ export type ListUsers = ( type GetOrCreateUserResponse = utils.Merge< Awaited>, { - user: utils.Merge>['user'], { tags: UserTags }> + user: utils.Merge< + Awaited>['user'], + { + tags: commonTypes.ToTags> + } + > } > @@ -256,7 +261,7 @@ export type GetOrCreateUser = < x: utils.Merge< Arg, { - tags: commonTypes.ToTags + tags: commonTypes.ToNullableTags discriminateByTags?: NoInfer> } > @@ -266,7 +271,7 @@ export type UpdateUser = ( x: utils.Merge< Arg, { - tags?: UserTags + tags?: commonTypes.ToNullableTags> } > ) => Promise> @@ -279,7 +284,7 @@ export type InitializeIncomingMessage['user']>, - { tags: UserTags } + { tags: commonTypes.ToTags> } > conversation?: utils.Merge< NonNullable['conversation']>, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 652bb89ec78..3f79d48bc93 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,8 +17,8 @@ importers: specifier: ^3.564.0 version: 3.709.0 '@botpress/api': - specifier: 1.99.0 - version: 1.99.0 + specifier: 1.102.0 + version: 1.102.0 '@botpress/cli': specifier: workspace:* version: link:packages/cli @@ -4179,8 +4179,8 @@ packages: '@bcoe/v8-coverage@0.2.3': resolution: {integrity: sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==} - '@botpress/api@1.99.0': - resolution: {integrity: sha512-3tKkidEQL6DU9AmxhRqhGWDhctMiRIZUbyPidkvLv64AOUjgMmFxtlTwpqHch9ECLyT2BWGwu6PP2ekE4tnXxQ==} + '@botpress/api@1.102.0': + resolution: {integrity: sha512-Qce4ZguplKIDAQJxkXwgHVLiHSm36nCsuLV4SbPvKPgBtGDOGINKbpimgHkfDhW7DCfMUmS2W0gWew/LHFqbpA==} '@bpinternal/const@0.1.0': resolution: {integrity: sha512-iIQg9oYYXOt+LSK34oNhJVQTcgRdtLmLZirEUaE+R9hnmbKONA5reR2kTewxZmekGyxej+5RtDK9xrC/0hmeAw==} @@ -13981,7 +13981,7 @@ snapshots: '@bcoe/v8-coverage@0.2.3': {} - '@botpress/api@1.99.0': + '@botpress/api@1.102.0': dependencies: '@bpinternal/opapi': 1.0.0(openapi-types@12.1.3) transitivePeerDependencies: