Skip to content

Commit 8653df6

Browse files
chore(client): use new client generator (botpress#13103)
1 parent 15f38f5 commit 8653df6

File tree

16 files changed

+78
-372
lines changed

16 files changed

+78
-372
lines changed

.eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = {
99
},
1010
extends: ['prettier'],
1111
parser: '@typescript-eslint/parser',
12-
ignorePatterns: ['*.d.ts', '*.test.ts', '*.js', 'cdk.out/', 'dist/', 'node_modules/', '.botpress/'],
12+
ignorePatterns: ['*.d.ts', '*.test.ts', '*.js', 'cdk.out/', 'dist/', 'node_modules/', '.botpress/', '**/src/gen/'],
1313
plugins: [
1414
'eslint-plugin-import',
1515
'eslint-plugin-jsdoc',

.github/actions/deploy-integrations/action.yml

+8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ input:
99
options:
1010
- staging
1111
- production
12+
force:
13+
type: boolean
14+
description: 'Force re-deploying integrations'
15+
required: false
1216
sentry_auth_token:
1317
description: 'Sentry auth token'
1418
required: true
@@ -97,9 +101,13 @@ runs:
97101
base_command="$base_command --secrets CLIENT_ID=${{ inputs.slack_client_id }} --secrets CLIENT_SECRET=${{ inputs.slack_client_secret }} --secrets SIGNING_SECRET=${{ inputs.slack_signing_secret }}"
98102
fi
99103
104+
redeploy=${{ inputs.force && 1 || 0 }}
100105
if [ $exists -eq 0 ]; then
101106
echo -e "\nDeploying integration: ### $integration ###\n"
102107
pnpm retry -n 2 -- pnpm -F $integration -c exec -- "$base_command"
108+
elif [ $redeploy -eq 1 ]; then
109+
echo -e "\nRe-deploying integration: ### $integration ###\n"
110+
pnpm retry -n 2 -- pnpm -F $integration -c exec -- "$base_command"
103111
else
104112
echo -e "\nSkipping integration: ### $integration ###\n"
105113
fi

.github/workflows/deploy-integrations-production.yml

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
name: Deploy Integrations Production
22

3-
on: workflow_dispatch
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
force:
7+
description: 'Force re-deploying integrations'
8+
type: boolean
9+
required: false
10+
default: false
411

512
permissions:
613
id-token: write
@@ -17,6 +24,7 @@ jobs:
1724
uses: ./.github/actions/deploy-integrations
1825
with:
1926
environment: 'production'
27+
force: ${{ github.event.inputs.force == 'true' }}
2028
sentry_auth_token: ${{ secrets.SENTRY_AUTH_TOKEN }}
2129
token_cloud_ops_account: ${{ secrets.PRODUCTION_TOKEN_CLOUD_OPS_ACCOUNT }}
2230
cloud_ops_workspace_id: ${{ secrets.PRODUCTION_CLOUD_OPS_WORKSPACE_ID }}

.github/workflows/deploy-integrations-staging.yml

+8-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ on:
55
branches:
66
- master
77

8-
workflow_dispatch: {}
8+
workflow_dispatch:
9+
inputs:
10+
force:
11+
description: 'Force re-deploying integrations'
12+
type: boolean
13+
required: false
14+
default: false
915

1016
permissions:
1117
id-token: write
@@ -22,6 +28,7 @@ jobs:
2228
uses: ./.github/actions/deploy-integrations
2329
with:
2430
environment: 'staging'
31+
force: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.force == 'true' }}
2532
sentry_auth_token: ${{ secrets.SENTRY_AUTH_TOKEN }}
2633
token_cloud_ops_account: ${{ secrets.STAGING_TOKEN_CLOUD_OPS_ACCOUNT }}
2734
cloud_ops_workspace_id: ${{ secrets.STAGING_CLOUD_OPS_WORKSPACE_ID }}

Tiltfile

+1-50
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
# constants
22

3-
## ports
4-
5-
OPENAPI_GENERATOR_SERVER_PORT = 8081
6-
READINESS_PORT = 8082
7-
8-
## commands
9-
10-
GENERATE_CLIENT_RESSOURCES = ['pnpm-install', 'openapi-generator-server', 'readiness', 'generate-client']
3+
GENERATE_CLIENT_RESSOURCES = ['pnpm-install', 'generate-client']
114
BUILD_PACKAGES_RESSOURCES = GENERATE_CLIENT_RESSOURCES + ['build-client', 'build-sdk', 'build-cli']
125
BUILD_ALL_RESSOURCES = BUILD_PACKAGES_RESSOURCES + ['build-integrations', 'add-integrations', 'build-bots']
136

@@ -41,56 +34,14 @@ local_resource(
4134
labels=['scripts'],
4235
)
4336

44-
## openapi-generator-server
45-
46-
openapi_generator_resource = {
47-
'image': 'botpress/openapi-generator-online',
48-
'ports': ['%s:8080' % OPENAPI_GENERATOR_SERVER_PORT],
49-
'restart': 'always',
50-
}
51-
52-
docker_compose(encode_yaml({
53-
'version': '3.5',
54-
'services': {
55-
'openapi-generator-server': openapi_generator_resource,
56-
},
57-
}))
58-
59-
dc_resource(name='openapi-generator-server', labels=['utils'])
60-
61-
## readiness
62-
63-
local_resource(
64-
name="readiness",
65-
allow_parallel=True,
66-
serve_cmd='pnpm ready',
67-
serve_env={
68-
'PORT': '%s' % READINESS_PORT,
69-
'LOG_LEVEL': 'info',
70-
'CONFIG': encode_json([
71-
{ 'type': 'http', 'name': 'openapi-generator-server', 'url': 'http://localhost:%s' % OPENAPI_GENERATOR_SERVER_PORT },
72-
]),
73-
},
74-
labels=['utils'],
75-
readiness_probe=probe(http_get=http_get_action(port=READINESS_PORT, path='/ready'), period_secs=1, failure_threshold=10),
76-
resource_deps=[
77-
'openapi-generator-server',
78-
'pnpm-install',
79-
]
80-
)
81-
8237
## generate client
8338

8439
local_resource(
8540
name='generate-client',
8641
allow_parallel=True,
8742
dir='packages/client',
8843
cmd='pnpm generate',
89-
env={
90-
'OPENAPI_GENERATOR_ENDPOINT': 'http://localhost:%s' % OPENAPI_GENERATOR_SERVER_PORT,
91-
},
9244
labels=['client'],
93-
resource_deps=['readiness']
9445
)
9546

9647
## build client

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"@botpress/cli": "workspace:*",
1919
"@botpress/sdk": "workspace:^",
2020
"@bpinternal/depsynky": "^0.0.1",
21-
"@bpinternal/readiness": "0.0.1",
2221
"@types/node": "^18.11.18",
2322
"@typescript-eslint/eslint-plugin": "^5.47.0",
2423
"@typescript-eslint/parser": "^5.47.0",

packages/cli/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@botpress/cli",
3-
"version": "0.8.14",
3+
"version": "0.8.15",
44
"description": "Botpress CLI",
55
"scripts": {
66
"build": "pnpm run bundle && pnpm run template:gen",
@@ -20,8 +20,8 @@
2020
},
2121
"main": "dist/index.js",
2222
"dependencies": {
23-
"@botpress/client": "0.17.0",
24-
"@botpress/sdk": "0.8.10",
23+
"@botpress/client": "0.18.0",
24+
"@botpress/sdk": "0.8.11",
2525
"@bpinternal/const": "^0.0.20",
2626
"@bpinternal/tunnel": "^0.1.1",
2727
"@bpinternal/yargs-extra": "^0.0.3",

packages/cli/templates/echo-bot/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
},
66
"private": true,
77
"dependencies": {
8-
"@botpress/client": "0.17.0",
9-
"@botpress/sdk": "0.8.10"
8+
"@botpress/client": "0.18.0",
9+
"@botpress/sdk": "0.8.11"
1010
},
1111
"devDependencies": {
1212
"@types/node": "^18.11.17",

packages/cli/templates/empty-integration/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
},
77
"private": true,
88
"dependencies": {
9-
"@botpress/client": "0.17.0",
10-
"@botpress/sdk": "0.8.10"
9+
"@botpress/client": "0.18.0",
10+
"@botpress/sdk": "0.8.11"
1111
},
1212
"devDependencies": {
1313
"@types/node": "^18.11.17",

packages/cli/templates/hello-world/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
},
77
"private": true,
88
"dependencies": {
9-
"@botpress/client": "0.17.0",
10-
"@botpress/sdk": "0.8.10"
9+
"@botpress/client": "0.18.0",
10+
"@botpress/sdk": "0.8.11"
1111
},
1212
"devDependencies": {
1313
"@types/node": "^18.11.17",

packages/cli/templates/webhook-message/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
},
77
"private": true,
88
"dependencies": {
9-
"@botpress/client": "0.17.0",
10-
"@botpress/sdk": "0.8.10",
9+
"@botpress/client": "0.18.0",
10+
"@botpress/sdk": "0.8.11",
1111
"axios": "^1.6.8"
1212
},
1313
"devDependencies": {

packages/client/openapi.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { api as publicOpenapi } from '@botpress/api'
22

3-
const openapiGeneratorEndpoint = process.env.OPENAPI_GENERATOR_ENDPOINT ?? 'http://api.openapi-generator.tech'
4-
5-
void publicOpenapi.exportClient('./src/gen', openapiGeneratorEndpoint)
3+
void publicOpenapi.exportClient('./src/gen', {
4+
generator: 'opapi',
5+
})

packages/client/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@botpress/client",
3-
"version": "0.17.0",
3+
"version": "0.18.0",
44
"description": "Botpress Client",
55
"main": "./dist/index.cjs",
66
"module": "./dist/index.mjs",
@@ -26,10 +26,12 @@
2626
"dependencies": {
2727
"axios": "^1.6.1",
2828
"browser-or-node": "^2.1.1",
29+
"qs": "^6.11.0",
2930
"type-fest": "^3.4.0"
3031
},
3132
"devDependencies": {
3233
"@botpress/api": "0.27.15",
34+
"@types/qs": "^6.9.7",
3335
"esbuild": "^0.16.12",
3436
"lodash": "^4.17.21",
3537
"puppeteer": "^22.0.0",

packages/client/src/index.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import axios, { AxiosError, AxiosInstance } from 'axios'
1+
import axios, { AxiosError } from 'axios'
22
import { isNode } from 'browser-or-node'
33
import http from 'http'
44
import https from 'https'
55
import { getClientConfig, ClientProps, ClientConfig } from './config'
6-
import { CreateFileResponse, GetFileResponse } from './gen'
7-
import { ApiClient as AutoGeneratedClient, CreateFileProps } from './gen/client'
6+
import { Client as AutoGeneratedClient } from './gen'
7+
8+
import { CreateFileInput, CreateFileResponse } from './gen/operations/createFile'
9+
import { GetFileResponse } from './gen/operations/getFile'
810

911
export { isApiError } from './gen/errors'
1012

@@ -15,15 +17,15 @@ export type {
1517
User,
1618
State,
1719
Event,
18-
ModelFile as File,
20+
File,
1921
Bot,
2022
Integration,
2123
Issue,
2224
IssueEvent,
2325
Account,
2426
Workspace,
2527
Usage,
26-
} from './gen'
28+
} from './gen/models'
2729
export * from './gen/errors'
2830

2931
const _100mb = 100 * 1024 * 1024
@@ -32,16 +34,13 @@ const maxContentLength = _100mb
3234

3335
export class Client extends AutoGeneratedClient {
3436
public readonly config: Readonly<ClientConfig>
35-
private readonly axiosClient: AxiosInstance
3637

3738
public constructor(clientProps: ClientProps = {}) {
3839
const clientConfig = getClientConfig(clientProps)
3940
const axiosClient = createAxiosClient(clientConfig)
40-
41-
super(undefined, clientConfig.apiUrl, axiosClient)
41+
super(axiosClient)
4242

4343
this.config = clientConfig
44-
this.axiosClient = axiosClient
4544
}
4645

4746
/**
@@ -54,7 +53,7 @@ export class Client extends AutoGeneratedClient {
5453
tags,
5554
contentType,
5655
accessPolicies,
57-
}: Omit<CreateFileProps, 'size'> & { data: Buffer }): Promise<GetFileResponse> => {
56+
}: Omit<CreateFileInput, 'size'> & { data: Buffer }): Promise<GetFileResponse> => {
5857
const { file } = await this.createFile({
5958
name,
6059
tags,
@@ -88,8 +87,9 @@ export class FileUploadError extends Error {
8887
}
8988

9089
function createAxiosClient(config: ClientConfig) {
91-
const { headers, withCredentials, timeout } = config
90+
const { apiUrl, headers, withCredentials, timeout } = config
9291
return axios.create({
92+
baseURL: apiUrl,
9393
headers,
9494
withCredentials,
9595
timeout,

packages/sdk/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@botpress/sdk",
3-
"version": "0.8.10",
3+
"version": "0.8.11",
44
"description": "Botpress SDK",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",
@@ -15,7 +15,7 @@
1515
"license": "MIT",
1616
"dependencies": {
1717
"@bpinternal/zui": "0.7.4",
18-
"@botpress/client": "0.17.0"
18+
"@botpress/client": "0.18.0"
1919
},
2020
"devDependencies": {
2121
"@types/node": "^18.11.17",

0 commit comments

Comments
 (0)