Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions resources/sdk/purecloudjavascript/templates/ApiClient.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class ApiClient {
MULTI: 'multi'
};

this.useLegacyParameterFilter = true;

/**
* @description Value is `true` if local storage exists. Otherwise, false.
*/
Expand Down Expand Up @@ -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 <code>param</code>.
*/
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 '';
}
Expand Down Expand Up @@ -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}`);
}
Expand Down
19 changes: 19 additions & 0 deletions resources/sdk/purecloudjavascript/templates/README.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down