diff --git a/resources/sdk/purecloudjavascript/templates/ApiClient.mustache b/resources/sdk/purecloudjavascript/templates/ApiClient.mustache index 250513a0..23f12b0e 100644 --- a/resources/sdk/purecloudjavascript/templates/ApiClient.mustache +++ b/resources/sdk/purecloudjavascript/templates/ApiClient.mustache @@ -72,6 +72,8 @@ class ApiClient { MULTI: 'multi' }; + this.useLegacyParameterFilter = true; + /** * @description Value is `true` if local storage exists. Otherwise, false. */ @@ -1192,12 +1194,35 @@ class ApiClient { return Object.keys(query).reduce((url, key) => !query[key] ? url : `${url}&${key}=${query[key]}`, `${loginBasePath}/${path}?`); } + /** + * @description If set to `true`, the ApiClient will continue to use its legacy approach for filtering method parameters (mapped to an API Endpoint's query parameter). This is option is meant to facilitate transition from legacy to current and accurate parameters filtering. + * @param {boolean} useLegacyParameterFilter - `false` to use modern/accurate approach (default value), `true` to use legacy approach (i.e. parameters of boolean type and equal to false are ignored/filtered, parameters of type integer/number and equal to 0 are ignored/filtered) + */ + setUseLegacyParameterFilter(useLegacyParameterFilter) { + this.useLegacyParameterFilter = useLegacyParameterFilter; + } + + getUseLegacyParameterFilter() { + return this.useLegacyParameterFilter; + } + /** * Returns a string representation for an actual parameter. * @param param The actual parameter. * @returns {String} The string representation of param. */ paramToString(param) { + if (this.useLegacyParameterFilter !== true) { + if (param !== null && param !== undefined) { + if (typeof param === "boolean") { + return param.toString().toLowerCase(); + } else if (param instanceof Boolean) { + return param.toString().toLowerCase(); + } else if (typeof param === "number") { + return param.toString(); + } + } + } if (!param) { return ''; } @@ -1361,16 +1386,16 @@ class ApiClient { switch (collectionFormat) { case 'csv': - return param.map(this.paramToString).join(','); + return param.map((x) => this.paramToString(x)).join(','); case 'ssv': - return param.map(this.paramToString).join(' '); + return param.map((x) => this.paramToString(x)).join(' '); case 'tsv': - return param.map(this.paramToString).join('\t'); + return param.map((x) => this.paramToString(x)).join('\t'); case 'pipes': - return param.map(this.paramToString).join('|'); + return param.map((x) => this.paramToString(x)).join('|'); case 'multi': // return the array directly as axios will handle it as expected - return param.map(this.paramToString); + return param.map((x) => this.paramToString(x)); default: throw new Error(`Unknown collection format: ${collectionFormat}`); } diff --git a/resources/sdk/purecloudjavascript/templates/README.mustache b/resources/sdk/purecloudjavascript/templates/README.mustache index 5bfcda1b..83b14052 100644 --- a/resources/sdk/purecloudjavascript/templates/README.mustache +++ b/resources/sdk/purecloudjavascript/templates/README.mustache @@ -428,6 +428,25 @@ const client = {{moduleName}}.ApiClient.instance; client.setEnvironment({{moduleName}}.PureCloudRegionHosts.eu_west_1); ``` +## Filtering of Query Parameters + +The SDK is implemented so that when one of its API method is invoked, it filters out null or undefined method parameters (mapped to an API Endpoint's query parameter). +- In its legacy state, the SDK will also filter parameters of boolean type and equal to false, and parameters of type integer/number and equal to 0. +- In its modern state, the SDK will keep and send such parameters. + +A new ApiClient property (accessed using getUseLegacyParameterFilter and setUseLegacyParameterFilter) is introduced to control the method used to filter out such parameters. + +When UseLegacyParameterFilter is true, the SDK will use the legacy filter method. + +*The UseLegacyParameterFilter default value is currently equal to true.* You will need to change the UseLegacyParameterFilter value so that the SDK uses modern filter method. +This choice of default value has been made to facilitate the transition from legacy to modern and accurate parameter filtering, without running the risk to affect existing applications with a change of behavior. + +```javascript +const client = {{moduleName}}.ApiClient.instance; +// To use modern and accurate parameter filtering, set UseLegacyParameterFilter to false +client.setUseLegacyParameterFilter(false); +``` + ### Setting an intermediate Gateway The Genesys Cloud Login and API URL path can be overridden if necessary (i.e. if the Genesys Cloud requests must be sent through to an intermediate API gateway or equivalent). diff --git a/resources/sdk/purecloudjavascript/templates/index.d.ts.mustache b/resources/sdk/purecloudjavascript/templates/index.d.ts.mustache index 65581837..2355a07d 100644 --- a/resources/sdk/purecloudjavascript/templates/index.d.ts.mustache +++ b/resources/sdk/purecloudjavascript/templates/index.d.ts.mustache @@ -28,6 +28,9 @@ declare class ApiClientClass { setReturnExtendedResponses(returnExtended: boolean): void; setStorageKey(storageKey: string): void; setProxyAgent(agent: any): void; + getUseLegacyParameterFilter(): boolean; + setUseLegacyParameterFilter(useLegacyParameterFilter: boolean): void; + buildCollectionParam(param: any, collectionFormat: string): any; setHttpClient(httpClient: AbstractHttpClient): void; getHttpClient(): AbstractHttpClient;