Skip to content

Commit

Permalink
chore(shared): Add JSDoc to helpers moved to shared package
Browse files Browse the repository at this point in the history
`callWithRetry`, `getClerkJsMajorVersionOrTag`, `getScriptUrl`
  • Loading branch information
dimkl committed Sep 27, 2023
1 parent dfbc1b5 commit 2d79433
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/shared/src/utils/callWithRetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ function wait(ms: number) {

const MAX_NUMBER_OF_RETRIES = 5;

/**
* Retry callback function every few hundred ms (with an exponential backoff
* based on the current attempt) until the maximum attempts has reached or
* the callback is executed successfully. The default number of maximum
* attempts is 5 and retries are triggered when callback throws an error.
*/
export async function callWithRetry<T>(
fn: (...args: unknown[]) => Promise<T>,
attempt = 1,
Expand Down
12 changes: 12 additions & 0 deletions packages/shared/src/utils/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ export function addClerkPrefix(str: string | undefined) {
return `clerk.${stripped}`;
}

/**
*
* Retrieve the clerk-js major tag using the major version from the pkgVersion
* param or use the frontendApi to determine if the staging tag should be used.
* The default tag is `latest` and a `next` pkgVersion also exists to retrieve
* the next canary release.
*/
export const getClerkJsMajorVersionOrTag = (frontendApi: string, pkgVersion?: string) => {
if (!pkgVersion && isStaging(frontendApi)) {
return 'staging';
Expand All @@ -44,6 +51,11 @@ export const getClerkJsMajorVersionOrTag = (frontendApi: string, pkgVersion?: st
return pkgVersion.split('.')[0] || 'latest';
};

/**
*
* Retrieve the clerk-js script url from the frontendApi and the major tag
* using the {@link getClerkJsMajorVersionOrTag} or a provided clerkJSVersion tag.
*/
export const getScriptUrl = (
frontendApi: string,
{ pkgVersion, clerkJSVersion }: { pkgVersion?: string; clerkJSVersion?: string },
Expand Down

0 comments on commit 2d79433

Please sign in to comment.