Skip to content

Commit

Permalink
Update client
Browse files Browse the repository at this point in the history
  • Loading branch information
croct-bot committed Apr 1, 2024
1 parent ba50f32 commit 71a887f
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.3.0-SNAPSHOT
7.5.0-SNAPSHOT
67 changes: 32 additions & 35 deletions api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
*
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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<EventType>, options: AxiosRequestConfig = {}): Promise<RequestArgs> => {
exportEvents: async (start?: number, end?: number, pageSize?: number, cursor?: string, events?: Array<EventType>, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
const localVarPath = `/events`;
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
Expand Down Expand Up @@ -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<RequestArgs> => {
exportSessions: async (start?: number, end?: number, pageSize?: number, cursor?: string, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
const localVarPath = `/session`;
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
Expand Down Expand Up @@ -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<RequestArgs> => {
exportUsers: async (start?: number, end?: number, pageSize?: number, cursor?: string, options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
const localVarPath = `/user`;
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
Expand Down Expand Up @@ -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<EventType>, options?: AxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<EventResponse>> {
async exportEvents(start?: number, end?: number, pageSize?: number, cursor?: string, events?: Array<EventType>, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<EventResponse>> {
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);
},
/**
*
Expand All @@ -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<SessionResponse>> {
async exportSessions(start?: number, end?: number, pageSize?: number, cursor?: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<SessionResponse>> {
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);
},
/**
*
Expand All @@ -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<UserResponse>> {
async exportUsers(start?: number, end?: number, pageSize?: number, cursor?: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<UserResponse>> {
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);
},
}
};
Expand All @@ -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<EventType>} [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<EventType>, options?: any): AxiosPromise<EventResponse> {
return localVarFp.exportEvents(start, end, pageSize, cursor, events, options).then((request) => request(axios, basePath));
exportEvents(requestParameters: ExportApiExportEventsRequest = {}, options?: RawAxiosRequestConfig): AxiosPromise<EventResponse> {
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<SessionResponse> {
return localVarFp.exportSessions(start, end, pageSize, cursor, options).then((request) => request(axios, basePath));
exportSessions(requestParameters: ExportApiExportSessionsRequest = {}, options?: RawAxiosRequestConfig): AxiosPromise<SessionResponse> {
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<UserResponse> {
return localVarFp.exportUsers(start, end, pageSize, cursor, options).then((request) => request(axios, basePath));
exportUsers(requestParameters: ExportApiExportUsersRequest = {}, options?: RawAxiosRequestConfig): AxiosPromise<UserResponse> {
return localVarFp.exportUsers(requestParameters.start, requestParameters.end, requestParameters.pageSize, requestParameters.cursor, options).then((request) => request(axios, basePath));
},
};
};
Expand Down Expand Up @@ -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));
}

Expand All @@ -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));
}

Expand All @@ -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));
}
}



20 changes: 17 additions & 3 deletions base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(/\/+$/, "");
Expand All @@ -39,7 +39,7 @@ export const COLLECTION_FORMATS = {
*/
export interface RequestArgs {
url: string;
options: AxiosRequestConfig;
options: RawAxiosRequestConfig;
}

/**
Expand All @@ -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;
}
}
};
Expand All @@ -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 = {
}
44 changes: 42 additions & 2 deletions common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, any>): Array<[string, any]> {
return Object.keys(object).map(key => [key, object[key]]);
}

/**
* Ponyfill for Object.fromEntries
*/
function objectFromEntries(entries: any): Record<string, any> {
return [...entries].reduce((object, [key, val]) => {
object[key] = val;
return object;
}, {});
}

/**
*
* @export
Expand All @@ -144,7 +184,7 @@ export const toPathString = function (url: URL) {
*/
export const createRequestFunction = function (axiosArgs: RequestArgs, globalAxios: AxiosInstance, BASE_PATH: string, configuration?: Configuration) {
return <T = unknown, R = AxiosResponse<T>>(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<T, R>(axiosRequestArgs);
};
}
9 changes: 9 additions & 0 deletions configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface ConfigurationParameters {
password?: string;
accessToken?: string | Promise<string> | ((name?: string, scopes?: string[]) => string) | ((name?: string, scopes?: string[]) => Promise<string>);
basePath?: string;
serverIndex?: number;
baseOptions?: any;
formDataCtor?: new () => any;
}
Expand Down Expand Up @@ -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
*
Expand All @@ -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;
}
Expand Down

0 comments on commit 71a887f

Please sign in to comment.