coveo/platform-client

Possible bug/issue in the send parameters Fields.search JSON request body

equinncov opened this issue · 1 comments

As shared by a partner working for a Coveo customer --> we did found a little bug in the TypeScript NPM client library “@coveo/platform-client” and we would have also a suggestion how to fix it.

The Bug in a nutshell:

library: npm module “@coveo/platform-client” version 44.5.1 (last release)

library repository: https://github.com/coveo/platform-client

client API method: platformClient.field.search (resources/Fields/Fields.ts)

related REST API method: https://platform.cloud.coveo.com/rest/organizations/{organizationId}/indexes/fields/search

current behaviour: all given “search” method parameters are sent to server as URL parameters, URL parameters are ignored on REST API – so no paging is possible (paging is required to allow getting all fields if more than fields 1000 exists)

expected behaviour: all given “search” method parameters are sent to server in a POST JSON body, so given paging parameters can be handled accordingly by REST API

More details:

We use the client library “@coveo/platform-client” in our Coveo deployment script, which is receiving the list of all defined index fields of appropriate environment specific Coveo organization.

To get the list of all fields we use field resource method “Fields.list

This method is now tagged as deprecated at the library and should be replaced by using “Fields.search”.

We did switch our implementation to using “Fields.search” but this method ignores at the moment the paging parameters.

Due to:

maximum number of fields getting per request is limited to 1000
our "dev environment Coveo organization" has 1562 fields (for test reasons – only on dev environment)
field resource method “Fields.search” is ignoring paging parameters
it is not possible to get a complete list of fields (not possible to get the fields after the first 1000 ones).

Looking at the related library implementation in their repository, I think, we saw the reason.

The parameters given to “Fields.search” method will be encoded as URL parameters when sending HTTP request to Coveo REST API - which ignores the URL parameters.

maybe problematic code part: see at client lib repository

search(params?: FieldListingOptions) {

    return this.api.post<PageModel<FieldModel>>(this.buildPath(`${Field.baseUrl}/search`, params));

}

This could maybe be fixed, by avoid sending the given parameters to URL encoding method “buildPath” but as body argument to the “post” method.

fix suggestion (tested by fixing library locally): move “)” to set “params” argument as 2nd argument of “post” method

search(params?: FieldListingOptions) {

    return this.api.post<PageModel<FieldModel>>(this.buildPath(`${Field.baseUrl}/search`), params);

}

We cannot fix the external Coveo client library locally, so we would wait for changing our implementation (switch usage of deprecated “Fields.list” to new “Fields.search” method)

until this issue could be fixed on Coveo client library.

🎉 This issue has been resolved in version 44.7.0 🎉

The release is available on:

Your semantic-release bot 📦🚀