diff --git a/.openapi-generator/VERSION b/.openapi-generator/VERSION index d6b4ec4..08bfd06 100644 --- a/.openapi-generator/VERSION +++ b/.openapi-generator/VERSION @@ -1 +1 @@ -6.3.0-SNAPSHOT \ No newline at end of file +7.5.0-SNAPSHOT diff --git a/api.ts b/api.ts index be46097..099848c 100644 --- a/api.ts +++ b/api.ts @@ -14,14 +14,14 @@ import type { Configuration } from './configuration'; -import type { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios'; +import type { AxiosPromise, AxiosInstance, RawAxiosRequestConfig } from 'axios'; import globalAxios from 'axios'; // Some imports not used depending on template conditions // @ts-ignore import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObject, setBearerAuthToObject, setOAuthToObject, setSearchParams, serializeDataIfNeeded, toPathString, createRequestFunction } from './common'; import type { RequestArgs } from './base'; // @ts-ignore -import { BASE_PATH, COLLECTION_FORMATS, BaseAPI, RequiredError } from './base'; +import { BASE_PATH, COLLECTION_FORMATS, BaseAPI, RequiredError, operationServerMap } from './base'; /** * @@ -1131,10 +1131,10 @@ export interface Session { 'client'?: WebClient; /** * The custom attributes. - * @type {{ [key: string]: any | undefined; }} + * @type {{ [key: string]: any | undefined | null; }} * @memberof Session */ - 'attributes'?: { [key: string]: any | undefined; }; + 'attributes'?: { [key: string]: any | undefined | null; }; /** * * @type {SessionStatistics} @@ -1721,7 +1721,7 @@ export const ExportApiAxiosParamCreator = function (configuration?: Configuratio * @param {*} [options] Override http request option. * @throws {RequiredError} */ - exportEvents: async (start?: number, end?: number, pageSize?: number, cursor?: string, events?: Array, options: AxiosRequestConfig = {}): Promise => { + exportEvents: async (start?: number, end?: number, pageSize?: number, cursor?: string, events?: Array, options: RawAxiosRequestConfig = {}): Promise => { const localVarPath = `/events`; // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); @@ -1777,7 +1777,7 @@ export const ExportApiAxiosParamCreator = function (configuration?: Configuratio * @param {*} [options] Override http request option. * @throws {RequiredError} */ - exportSessions: async (start?: number, end?: number, pageSize?: number, cursor?: string, options: AxiosRequestConfig = {}): Promise => { + exportSessions: async (start?: number, end?: number, pageSize?: number, cursor?: string, options: RawAxiosRequestConfig = {}): Promise => { const localVarPath = `/session`; // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); @@ -1829,7 +1829,7 @@ export const ExportApiAxiosParamCreator = function (configuration?: Configuratio * @param {*} [options] Override http request option. * @throws {RequiredError} */ - exportUsers: async (start?: number, end?: number, pageSize?: number, cursor?: string, options: AxiosRequestConfig = {}): Promise => { + exportUsers: async (start?: number, end?: number, pageSize?: number, cursor?: string, options: RawAxiosRequestConfig = {}): Promise => { const localVarPath = `/user`; // use dummy base URL string because the URL constructor only accepts absolute URLs. const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); @@ -1892,9 +1892,11 @@ export const ExportApiFp = function(configuration?: Configuration) { * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async exportEvents(start?: number, end?: number, pageSize?: number, cursor?: string, events?: Array, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + async exportEvents(start?: number, end?: number, pageSize?: number, cursor?: string, events?: Array, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { const localVarAxiosArgs = await localVarAxiosParamCreator.exportEvents(start, end, pageSize, cursor, events, options); - return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = operationServerMap['ExportApi.exportEvents']?.[localVarOperationServerIndex]?.url; + return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); }, /** * @@ -1905,9 +1907,11 @@ export const ExportApiFp = function(configuration?: Configuration) { * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async exportSessions(start?: number, end?: number, pageSize?: number, cursor?: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + async exportSessions(start?: number, end?: number, pageSize?: number, cursor?: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { const localVarAxiosArgs = await localVarAxiosParamCreator.exportSessions(start, end, pageSize, cursor, options); - return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = operationServerMap['ExportApi.exportSessions']?.[localVarOperationServerIndex]?.url; + return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); }, /** * @@ -1918,9 +1922,11 @@ export const ExportApiFp = function(configuration?: Configuration) { * @param {*} [options] Override http request option. * @throws {RequiredError} */ - async exportUsers(start?: number, end?: number, pageSize?: number, cursor?: string, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + async exportUsers(start?: number, end?: number, pageSize?: number, cursor?: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { const localVarAxiosArgs = await localVarAxiosParamCreator.exportUsers(start, end, pageSize, cursor, options); - return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = operationServerMap['ExportApi.exportUsers']?.[localVarOperationServerIndex]?.url; + return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); }, } }; @@ -1934,40 +1940,30 @@ export const ExportApiFactory = function (configuration?: Configuration, basePat return { /** * - * @param {number} [start] - * @param {number} [end] - * @param {number} [pageSize] - * @param {string} [cursor] - * @param {Array} [events] + * @param {ExportApiExportEventsRequest} requestParameters Request parameters. * @param {*} [options] Override http request option. * @throws {RequiredError} */ - exportEvents(start?: number, end?: number, pageSize?: number, cursor?: string, events?: Array, options?: any): AxiosPromise { - return localVarFp.exportEvents(start, end, pageSize, cursor, events, options).then((request) => request(axios, basePath)); + exportEvents(requestParameters: ExportApiExportEventsRequest = {}, options?: RawAxiosRequestConfig): AxiosPromise { + return localVarFp.exportEvents(requestParameters.start, requestParameters.end, requestParameters.pageSize, requestParameters.cursor, requestParameters.events, options).then((request) => request(axios, basePath)); }, /** * - * @param {number} [start] - * @param {number} [end] - * @param {number} [pageSize] - * @param {string} [cursor] + * @param {ExportApiExportSessionsRequest} requestParameters Request parameters. * @param {*} [options] Override http request option. * @throws {RequiredError} */ - exportSessions(start?: number, end?: number, pageSize?: number, cursor?: string, options?: any): AxiosPromise { - return localVarFp.exportSessions(start, end, pageSize, cursor, options).then((request) => request(axios, basePath)); + exportSessions(requestParameters: ExportApiExportSessionsRequest = {}, options?: RawAxiosRequestConfig): AxiosPromise { + return localVarFp.exportSessions(requestParameters.start, requestParameters.end, requestParameters.pageSize, requestParameters.cursor, options).then((request) => request(axios, basePath)); }, /** * - * @param {number} [start] - * @param {number} [end] - * @param {number} [pageSize] - * @param {string} [cursor] + * @param {ExportApiExportUsersRequest} requestParameters Request parameters. * @param {*} [options] Override http request option. * @throws {RequiredError} */ - exportUsers(start?: number, end?: number, pageSize?: number, cursor?: string, options?: any): AxiosPromise { - return localVarFp.exportUsers(start, end, pageSize, cursor, options).then((request) => request(axios, basePath)); + exportUsers(requestParameters: ExportApiExportUsersRequest = {}, options?: RawAxiosRequestConfig): AxiosPromise { + return localVarFp.exportUsers(requestParameters.start, requestParameters.end, requestParameters.pageSize, requestParameters.cursor, options).then((request) => request(axios, basePath)); }, }; }; @@ -2098,7 +2094,7 @@ export class ExportApi extends BaseAPI { * @throws {RequiredError} * @memberof ExportApi */ - public exportEvents(requestParameters: ExportApiExportEventsRequest = {}, options?: AxiosRequestConfig) { + public exportEvents(requestParameters: ExportApiExportEventsRequest = {}, options?: RawAxiosRequestConfig) { return ExportApiFp(this.configuration).exportEvents(requestParameters.start, requestParameters.end, requestParameters.pageSize, requestParameters.cursor, requestParameters.events, options).then((request) => request(this.axios, this.basePath)); } @@ -2109,7 +2105,7 @@ export class ExportApi extends BaseAPI { * @throws {RequiredError} * @memberof ExportApi */ - public exportSessions(requestParameters: ExportApiExportSessionsRequest = {}, options?: AxiosRequestConfig) { + public exportSessions(requestParameters: ExportApiExportSessionsRequest = {}, options?: RawAxiosRequestConfig) { return ExportApiFp(this.configuration).exportSessions(requestParameters.start, requestParameters.end, requestParameters.pageSize, requestParameters.cursor, options).then((request) => request(this.axios, this.basePath)); } @@ -2120,9 +2116,10 @@ export class ExportApi extends BaseAPI { * @throws {RequiredError} * @memberof ExportApi */ - public exportUsers(requestParameters: ExportApiExportUsersRequest = {}, options?: AxiosRequestConfig) { + public exportUsers(requestParameters: ExportApiExportUsersRequest = {}, options?: RawAxiosRequestConfig) { return ExportApiFp(this.configuration).exportUsers(requestParameters.start, requestParameters.end, requestParameters.pageSize, requestParameters.cursor, options).then((request) => request(this.axios, this.basePath)); } } + diff --git a/base.ts b/base.ts index a773e1e..ab97d93 100644 --- a/base.ts +++ b/base.ts @@ -16,7 +16,7 @@ import type { Configuration } from './configuration'; // Some imports not used depending on template conditions // @ts-ignore -import type { AxiosPromise, AxiosInstance, AxiosRequestConfig } from 'axios'; +import type { AxiosPromise, AxiosInstance, RawAxiosRequestConfig } from 'axios'; import globalAxios from 'axios'; export const BASE_PATH = "https://api.croct.io/export".replace(/\/+$/, ""); @@ -39,7 +39,7 @@ export const COLLECTION_FORMATS = { */ export interface RequestArgs { url: string; - options: AxiosRequestConfig; + options: RawAxiosRequestConfig; } /** @@ -53,7 +53,7 @@ export class BaseAPI { constructor(configuration?: Configuration, protected basePath: string = BASE_PATH, protected axios: AxiosInstance = globalAxios) { if (configuration) { this.configuration = configuration; - this.basePath = configuration.basePath || this.basePath; + this.basePath = configuration.basePath ?? basePath; } } }; @@ -70,3 +70,17 @@ export class RequiredError extends Error { this.name = "RequiredError" } } + +interface ServerMap { + [key: string]: { + url: string, + description: string, + }[]; +} + +/** + * + * @export + */ +export const operationServerMap: ServerMap = { +} diff --git a/common.ts b/common.ts index 22d6fb4..da40213 100644 --- a/common.ts +++ b/common.ts @@ -126,10 +126,50 @@ export const serializeDataIfNeeded = function (value: any, requestOptions: any, ? configuration.isJsonMime(requestOptions.headers['Content-Type']) : nonString; return needsSerialization - ? JSON.stringify(value !== undefined ? value : {}) + ? JSON.stringify(value !== undefined ? convertMapsAndSetsToPlain(value) : {}) : (value || ""); } +function convertMapsAndSetsToPlain(value: any): any { + if (typeof Set === "undefined") return value; + if (typeof Map === "undefined") return value; + if (typeof value !== "object" || !value) { + return value; + } + if (value instanceof Set) { + return Array.from(value).map(item => convertMapsAndSetsToPlain(item)); + } + if (value instanceof Map) { + const entries: Array<[string, any]> = []; + value.forEach((value: any, key: any) => { + entries.push([key, convertMapsAndSetsToPlain(value)]) + }); + return objectFromEntries(entries); + } + if (Array.isArray(value)) { + return value.map(it => convertMapsAndSetsToPlain(it)); + } + return objectFromEntries(objectEntries(value) + .map(([k, v]) => [k, convertMapsAndSetsToPlain(v)])); +} + +/** + * Ponyfill for Object.entries + */ +function objectEntries(object: Record): Array<[string, any]> { + return Object.keys(object).map(key => [key, object[key]]); +} + +/** + * Ponyfill for Object.fromEntries + */ +function objectFromEntries(entries: any): Record { + return [...entries].reduce((object, [key, val]) => { + object[key] = val; + return object; + }, {}); +} + /** * * @export @@ -144,7 +184,7 @@ export const toPathString = function (url: URL) { */ export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) { return >(axios: AxiosInstance = globalAxios, basePath: string = BASE_PATH) => { - const axiosRequestArgs = {...axiosArgs.options, url: (configuration?.basePath || basePath) + axiosArgs.url}; + const axiosRequestArgs = {...axiosArgs.options, url: (axios.defaults.baseURL ? '' : configuration?.basePath ?? basePath) + axiosArgs.url}; return axios.request(axiosRequestArgs); }; } diff --git a/configuration.ts b/configuration.ts index c1a80db..1490244 100644 --- a/configuration.ts +++ b/configuration.ts @@ -19,6 +19,7 @@ export interface ConfigurationParameters { password?: string; accessToken?: string | Promise | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise); basePath?: string; + serverIndex?: number; baseOptions?: any; formDataCtor?: new () => any; } @@ -58,6 +59,13 @@ export class Configuration { * @memberof Configuration */ basePath?: string; + /** + * override server index + * + * @type {number} + * @memberof Configuration + */ + serverIndex?: number; /** * base options for axios calls * @@ -80,6 +88,7 @@ export class Configuration { this.password = param.password; this.accessToken = param.accessToken; this.basePath = param.basePath; + this.serverIndex = param.serverIndex; this.baseOptions = param.baseOptions; this.formDataCtor = param.formDataCtor; }