Skip to content

fix(javascript): provide requestOptions to helper methods #797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 6, 2022
Merged
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
12 changes: 7 additions & 5 deletions templates/javascript/clients/client/api/helpers.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
* @param waitForTaskOptions - The waitForTaskOptions object.
* @param waitForTaskOptions.indexName - The `indexName` where the operation was performed.
* @param waitForTaskOptions.taskID - The `taskID` returned in the method response.
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getTask` method and merged with the transporter requestOptions.
*/
waitForTask({
indexName,
taskID,
...createRetryablePromiseOptions
}: WaitForTaskOptions): Promise<GetTaskResponse> {
}: WaitForTaskOptions, requestOptions?: RequestOptions): Promise<GetTaskResponse> {
return createRetryablePromise({
...createRetryablePromiseOptions,
func: () => this.getTask({ indexName, taskID }),
func: () => this.getTask({ indexName, taskID }, requestOptions),
validate: (response) => response.status === 'published',
});
},
Expand All @@ -26,13 +27,14 @@ waitForTask({
* @param waitForApiKeyOptions.operation - The `operation` that was done on a `key`.
* @param waitForApiKeyOptions.key - The `key` that has been added, deleted or updated.
* @param waitForApiKeyOptions.apiKey - Necessary to know if an `update` operation has been processed, compare fields of the response with it.
* @param requestOptions - The requestOptions to send along with the query, they will be forwarded to the `getApikey` method and merged with the transporter requestOptions.
*/
waitForApiKey({
operation,
key,
apiKey,
...createRetryablePromiseOptions
}: WaitForApiKeyOptions): Promise<ApiError | Key> {
}: WaitForApiKeyOptions, requestOptions?: RequestOptions): Promise<ApiError | Key> {
if (operation === 'update') {
if (!apiKey) {
throw new Error(
Expand All @@ -42,7 +44,7 @@ waitForApiKey({

return createRetryablePromise({
...createRetryablePromiseOptions,
func: () => this.getApiKey({ key }),
func: () => this.getApiKey({ key }, requestOptions),
validate: (response) => {
for (const field of Object.keys(apiKey)) {
if (Array.isArray(apiKey[field])) {
Expand All @@ -65,7 +67,7 @@ waitForApiKey({

return createRetryablePromise({
...createRetryablePromiseOptions,
func: () => this.getApiKey({ key }).catch((error) => error),
func: () => this.getApiKey({ key }, requestOptions).catch((error) => error),
validate: (error: ApiError) =>
operation === 'add' ? error.status !== 404 : error.status === 404,
});
Expand Down