-
Notifications
You must be signed in to change notification settings - Fork 130
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
Throttle access to Management APIs #4260
Conversation
It now expects a function that makes a request, rather than the promised _result_ of a request. Retries are based on 429 statuses on the response header, or in a GraphQL errors/extensions payload.
This comment has been minimized.
This comment has been minimized.
Coverage report
Show new covered files 🐣
Show files with reduced coverage 🔻
Test suite run success1803 tests passing in 824 suites. Report generated by 🧪jest coverage report action from 40a7b12 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this PR, @shauns! Excellent refactoring 🔥🚀 LGTM and works as expected on themes as well!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
Differences in type declarationsWe detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:
New type declarationspackages/cli-kit/dist/public/node/api/rest-api-throttler.d.tsimport { RestResponse } from './admin.js';
/**
* Throttles a provided action, limiting the number of globally parallel requests, or by the last seen API limit
* headers.
*
* @param request - A function performing a request.
* @returns - The result of the request, once it eventually runs.
*/
export declare function throttle<T>(request: () => T): Promise<T>;
/**
* Keep track of the latest API call limit data from a response.
*
* @param response - The response object.
*/
export declare function updateApiCallLimitFromResponse(response: RestResponse): void;
/**
* Retries an operation after a delay specified in the response headers.
*
* @param response - The response object.
* @param operation - The operation to retry.
* @returns - The response of the operation.
*/
export declare function delayAwareRetry(response: RestResponse, operation: () => Promise<RestResponse>): Promise<RestResponse>;
Existing type declarationspackages/cli-kit/dist/private/node/api.d.ts@@ -2,11 +2,19 @@ import { Headers } from 'form-data';
export type API = 'admin' | 'storefront-renderer' | 'partners' | 'business-platform' | 'app-management';
export declare const allAPIs: API[];
interface RequestOptions<T> {
- request: Promise<T>;
+ request: () => Promise<T>;
url: string;
}
-export declare function debugLogResponseInfo<T extends {
+export declare function simpleRequestWithDebugLog<T extends {
headers: Headers;
status: number;
}>({ request, url }: RequestOptions<T>, errorHandler?: (error: unknown, requestId: string | undefined) => Error | unknown): Promise<T>;
+export declare function retryAwareRequest<T extends {
+ headers: Headers;
+ status: number;
+}>({ request, url }: RequestOptions<T>, errorHandler?: (error: unknown, requestId: string | undefined) => Error | unknown, retryOptions?: {
+ limitRetriesTo?: number;
+ defaultDelayMs?: number;
+ scheduleDelay: (fn: () => void, delay: number) => void;
+}): Promise<T>;
export {};
\ No newline at end of file
|
WHY are these changes introduced?
Fixes https://github.com/Shopify/develop-app-inner-loop/issues/1996
WHAT is this pull request doing?
public
but not exported codeHow to test your changes?
The most effective approach I've found is get a very big app and do a before/after comparison with these changes.
Post-release steps
n/a
Measuring impact
How do we know this change was effective? Please choose one:
Checklist