Skip to content

Commit

Permalink
fix(javascript): provide requestOptions to helper methods (#797)
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts committed Jul 6, 2022
1 parent 576854c commit 750721d
Showing 1 changed file with 7 additions and 5 deletions.
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

0 comments on commit 750721d

Please sign in to comment.