@botpress/api 0.29.1 → 0.29.2
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/dist/index.js +40 -26
- package/package.json +2 -2
- package/src/gen/openapi.json +1 -1
- package/src/gen/state.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -251507,7 +251507,7 @@ __export(src_exports, {
|
|
|
251507
251507
|
});
|
|
251508
251508
|
module.exports = __toCommonJS(src_exports);
|
|
251509
251509
|
|
|
251510
|
-
// ../../node_modules/.pnpm/@bpinternal+opapi@0.10.
|
|
251510
|
+
// ../../node_modules/.pnpm/@bpinternal+opapi@0.10.17_openapi-types@12.1.3/node_modules/@bpinternal/opapi/dist/index.mjs
|
|
251511
251511
|
var import_zod_openapi = __toESM(require_src(), 1);
|
|
251512
251512
|
var import_zod_openapi2 = __toESM(require_src(), 1);
|
|
251513
251513
|
var import_path = __toESM(require("path"), 1);
|
|
@@ -251553,7 +251553,7 @@ var title = (str2) => {
|
|
|
251553
251553
|
return str2.split(/(?=[A-Z])|[\.\-\s_]/).map((s2) => s2.trim()).filter((s2) => !!s2).map((s2) => capitalize(s2.toLowerCase())).join(" ");
|
|
251554
251554
|
};
|
|
251555
251555
|
|
|
251556
|
-
// ../../node_modules/.pnpm/@bpinternal+opapi@0.10.
|
|
251556
|
+
// ../../node_modules/.pnpm/@bpinternal+opapi@0.10.17_openapi-types@12.1.3/node_modules/@bpinternal/opapi/dist/index.mjs
|
|
251557
251557
|
var import_decompress = __toESM(require_decompress(), 1);
|
|
251558
251558
|
var import_fs3 = __toESM(require("fs"), 1);
|
|
251559
251559
|
var import_promises = __toESM(require("fs/promises"), 1);
|
|
@@ -254470,7 +254470,7 @@ var {
|
|
|
254470
254470
|
mergeConfig: mergeConfig2
|
|
254471
254471
|
} = axios_default;
|
|
254472
254472
|
|
|
254473
|
-
// ../../node_modules/.pnpm/@bpinternal+opapi@0.10.
|
|
254473
|
+
// ../../node_modules/.pnpm/@bpinternal+opapi@0.10.17_openapi-types@12.1.3/node_modules/@bpinternal/opapi/dist/index.mjs
|
|
254474
254474
|
var import_json_schema_to_typescript = __toESM(require_src3(), 1);
|
|
254475
254475
|
var import_fs4 = __toESM(require("fs"), 1);
|
|
254476
254476
|
var import_path3 = __toESM(require("path"), 1);
|
|
@@ -258806,7 +258806,7 @@ async function openapiTS(schema3, options = {}) {
|
|
|
258806
258806
|
}
|
|
258807
258807
|
var dist_default = openapiTS;
|
|
258808
258808
|
|
|
258809
|
-
// ../../node_modules/.pnpm/@bpinternal+opapi@0.10.
|
|
258809
|
+
// ../../node_modules/.pnpm/@bpinternal+opapi@0.10.17_openapi-types@12.1.3/node_modules/@bpinternal/opapi/dist/index.mjs
|
|
258810
258810
|
var import_openapi3_ts = __toESM(require_dist3(), 1);
|
|
258811
258811
|
var import_verror2 = __toESM(require_verror(), 1);
|
|
258812
258812
|
var import_verror3 = __toESM(require_verror(), 1);
|
|
@@ -262447,7 +262447,7 @@ var z = /* @__PURE__ */ Object.freeze({
|
|
|
262447
262447
|
ZodError
|
|
262448
262448
|
});
|
|
262449
262449
|
|
|
262450
|
-
// ../../node_modules/.pnpm/@bpinternal+opapi@0.10.
|
|
262450
|
+
// ../../node_modules/.pnpm/@bpinternal+opapi@0.10.17_openapi-types@12.1.3/node_modules/@bpinternal/opapi/dist/index.mjs
|
|
262451
262451
|
var import_openapi_parser = __toESM(require_lib10(), 1);
|
|
262452
262452
|
var import_json_schema_to_typescript2 = __toESM(require_src3(), 1);
|
|
262453
262453
|
var import_zod_openapi4 = __toESM(require_src(), 1);
|
|
@@ -262904,7 +262904,8 @@ var client_node_exports = {};
|
|
|
262904
262904
|
__export2(client_node_exports, {
|
|
262905
262905
|
generateIndex: () => generateIndex,
|
|
262906
262906
|
generateModels: () => generateModels,
|
|
262907
|
-
generateOperations: () => generateOperations
|
|
262907
|
+
generateOperations: () => generateOperations,
|
|
262908
|
+
generateToAxios: () => generateToAxios
|
|
262908
262909
|
});
|
|
262909
262910
|
var entries = (obj) => Object.entries(obj);
|
|
262910
262911
|
function filterObject(obj, fn) {
|
|
@@ -263239,16 +263240,18 @@ function getError(err: Error) {
|
|
|
263239
263240
|
return errorFrom(err)
|
|
263240
263241
|
}
|
|
263241
263242
|
`;
|
|
263242
|
-
var GET_AXIOS_REQ_FUNCTION =
|
|
263243
|
-
|
|
263244
|
-
|
|
263245
|
-
type QueryValue = Value<string> | Value<boolean> | Value<number> | undefined
|
|
263246
|
-
type AnyQueryParams = Record<string, QueryValue>
|
|
263247
|
-
type HeaderValue = string | undefined
|
|
263248
|
-
type AnyHeaderParams = Record<string, HeaderValue>
|
|
263249
|
-
type AnyBodyParams = Record<string, any>
|
|
263243
|
+
var GET_AXIOS_REQ_FUNCTION = `
|
|
263244
|
+
import { AxiosRequestConfig } from "axios"
|
|
263245
|
+
import qs from "qs"
|
|
263250
263246
|
|
|
263251
|
-
type
|
|
263247
|
+
export type Primitive = string | number | boolean
|
|
263248
|
+
export type Value<P extends Primitive> = P | P[] | Record<string, P>
|
|
263249
|
+
export type QueryValue = Value<string> | Value<boolean> | Value<number> | undefined
|
|
263250
|
+
export type AnyQueryParams = Record<string, QueryValue>
|
|
263251
|
+
export type HeaderValue = string | undefined
|
|
263252
|
+
export type AnyHeaderParams = Record<string, HeaderValue>
|
|
263253
|
+
export type AnyBodyParams = Record<string, any>
|
|
263254
|
+
export type ParsedRequest = {
|
|
263252
263255
|
method: string
|
|
263253
263256
|
path: string
|
|
263254
263257
|
query: AnyQueryParams
|
|
@@ -263259,7 +263262,7 @@ type ParsedRequest = {
|
|
|
263259
263262
|
const isDefined = <T>(pair: [string, T | undefined]): pair is [string, T] => pair[1] !== undefined
|
|
263260
263263
|
|
|
263261
263264
|
export const toAxiosRequest = (req: ParsedRequest): AxiosRequestConfig => {
|
|
263262
|
-
const { method, path
|
|
263265
|
+
const { method, path, query, headers: headerParams, body: data } = req
|
|
263263
263266
|
|
|
263264
263267
|
// prepare headers
|
|
263265
263268
|
const headerEntries: [string, string][] = Object.entries(headerParams).filter(isDefined)
|
|
@@ -263267,13 +263270,13 @@ export const toAxiosRequest = (req: ParsedRequest): AxiosRequestConfig => {
|
|
|
263267
263270
|
|
|
263268
263271
|
// prepare query params
|
|
263269
263272
|
const queryString = qs.stringify(query, { encode: true, arrayFormat: 'repeat', allowDots: true })
|
|
263270
|
-
|
|
263273
|
+
|
|
263274
|
+
const url = queryString ? [path, queryString].join('?') : path
|
|
263271
263275
|
|
|
263272
263276
|
return {
|
|
263273
263277
|
method,
|
|
263274
263278
|
url,
|
|
263275
263279
|
headers,
|
|
263276
|
-
params,
|
|
263277
263280
|
data,
|
|
263278
263281
|
}
|
|
263279
263282
|
}
|
|
@@ -263389,13 +263392,16 @@ ${responseCode}`;
|
|
|
263389
263392
|
await writeTs(file, code);
|
|
263390
263393
|
}
|
|
263391
263394
|
};
|
|
263395
|
+
var generateToAxios = async (toAxiosFile) => {
|
|
263396
|
+
await writeTs(toAxiosFile, GET_AXIOS_REQ_FUNCTION);
|
|
263397
|
+
};
|
|
263392
263398
|
var generateIndex = async (state2, indexFile) => {
|
|
263393
263399
|
const operationsByName = import_lodash.default.mapKeys(state2.operations, (v) => v.name);
|
|
263394
263400
|
let indexCode = [
|
|
263395
263401
|
`${HEADER}`,
|
|
263396
|
-
"import
|
|
263397
|
-
"import axios, { AxiosInstance, AxiosRequestConfig } from 'axios'",
|
|
263402
|
+
"import axios, { AxiosInstance } from 'axios'",
|
|
263398
263403
|
"import { errorFrom } from './errors'",
|
|
263404
|
+
"import { toAxiosRequest } from './to-axios'",
|
|
263399
263405
|
""
|
|
263400
263406
|
].join("\n");
|
|
263401
263407
|
for (const [name] of Object.entries(operationsByName)) {
|
|
@@ -263409,14 +263415,21 @@ var generateIndex = async (state2, indexFile) => {
|
|
|
263409
263415
|
`;
|
|
263410
263416
|
}
|
|
263411
263417
|
indexCode += "\n";
|
|
263418
|
+
indexCode += [
|
|
263419
|
+
"export type ClientProps = {",
|
|
263420
|
+
" toAxiosRequest: typeof toAxiosRequest",
|
|
263421
|
+
"}"
|
|
263422
|
+
].join("\n");
|
|
263423
|
+
indexCode += "\n\n";
|
|
263412
263424
|
indexCode += "export class Client {\n\n";
|
|
263413
|
-
indexCode += "constructor(private axiosInstance: AxiosInstance) {}\n\n";
|
|
263425
|
+
indexCode += " public constructor(private axiosInstance: AxiosInstance, private props: Partial<ClientProps> = {}) {}\n\n";
|
|
263414
263426
|
for (const [name, operation] of Object.entries(operationsByName)) {
|
|
263415
263427
|
const { inputName, resName } = Names.of(name);
|
|
263416
263428
|
indexCode += [
|
|
263417
263429
|
` public readonly ${name} = async (input: ${name}.${inputName}): Promise<${name}.${resName}> => {`,
|
|
263418
263430
|
` const { path, headers, query, body } = ${name}.parseReq(input)`,
|
|
263419
|
-
` const
|
|
263431
|
+
` const mapper = this.props.toAxiosRequest ?? toAxiosRequest`,
|
|
263432
|
+
` const axiosReq = mapper({`,
|
|
263420
263433
|
` method: "${operation.method}",`,
|
|
263421
263434
|
" path,",
|
|
263422
263435
|
" headers: { ...headers },",
|
|
@@ -263431,8 +263444,6 @@ var generateIndex = async (state2, indexFile) => {
|
|
|
263431
263444
|
}
|
|
263432
263445
|
indexCode += "}\n\n";
|
|
263433
263446
|
indexCode += `${GET_ERROR_FUNCTION}
|
|
263434
|
-
`;
|
|
263435
|
-
indexCode += `${GET_AXIOS_REQ_FUNCTION}
|
|
263436
263447
|
`;
|
|
263437
263448
|
await writeTs(indexFile, indexCode);
|
|
263438
263449
|
};
|
|
@@ -264208,14 +264219,17 @@ var generateClientWithOpapi = async (state2, dir) => {
|
|
|
264208
264219
|
const errorsFile = import_path.default.join(dir, "errors.ts");
|
|
264209
264220
|
const indexFile = import_path.default.join(dir, "index.ts");
|
|
264210
264221
|
const operationsDir = import_path.default.join(dir, "operations");
|
|
264222
|
+
const toAxiosFile = import_path.default.join(dir, "to-axios.ts");
|
|
264211
264223
|
import_fs.default.mkdirSync(operationsDir, { recursive: true });
|
|
264212
264224
|
log_default.info("Generating models");
|
|
264213
264225
|
await client_node_exports.generateModels(state2, modelsFile);
|
|
264214
264226
|
log_default.info("Generating operations");
|
|
264215
264227
|
await client_node_exports.generateOperations(state2, operationsDir);
|
|
264216
|
-
log_default.info("
|
|
264228
|
+
log_default.info("Generating errors file");
|
|
264217
264229
|
const errorsFileContent = generateErrors(state2.errors ?? []);
|
|
264218
264230
|
await import_fs.default.promises.writeFile(errorsFile, errorsFileContent);
|
|
264231
|
+
log_default.info("Generating to-axios file");
|
|
264232
|
+
await client_node_exports.generateToAxios(toAxiosFile);
|
|
264219
264233
|
log_default.info("Generating index file");
|
|
264220
264234
|
await client_node_exports.generateIndex(state2, indexFile);
|
|
264221
264235
|
};
|
|
@@ -274693,7 +274707,7 @@ var state = {
|
|
|
274693
274707
|
"title": "Botpress API",
|
|
274694
274708
|
"description": "API for Botpress Cloud",
|
|
274695
274709
|
"server": "https://api.botpress.cloud",
|
|
274696
|
-
"version": "0.29.
|
|
274710
|
+
"version": "0.29.2",
|
|
274697
274711
|
"prefix": "v1"
|
|
274698
274712
|
},
|
|
274699
274713
|
"errors": [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botpress/api",
|
|
3
|
-
"version": "0.29.
|
|
3
|
+
"version": "0.29.2",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/src/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -23,6 +23,6 @@
|
|
|
23
23
|
"zod": "^3.22.4"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@bpinternal/opapi": "0.10.
|
|
26
|
+
"@bpinternal/opapi": "0.10.17"
|
|
27
27
|
}
|
|
28
28
|
}
|