-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(shared): Move share-able code from backend to shared package
This is a preparation step to remove the share-able dependencies from backend package and import them from shared package
- Loading branch information
Showing
5 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
function wait(ms: number) { | ||
return new Promise(res => setTimeout(res, ms)); | ||
} | ||
|
||
const MAX_NUMBER_OF_RETRIES = 5; | ||
|
||
export async function callWithRetry<T>( | ||
fn: (...args: unknown[]) => Promise<T>, | ||
attempt = 1, | ||
maxAttempts = MAX_NUMBER_OF_RETRIES, | ||
): Promise<T> { | ||
try { | ||
return await fn(); | ||
} catch (e) { | ||
if (attempt >= maxAttempts) { | ||
throw e; | ||
} | ||
await wait(2 ** attempt * 100); | ||
|
||
return callWithRetry(fn, attempt + 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export function isDevelopmentFromApiKey(apiKey: string): boolean { | ||
return apiKey.startsWith('test_') || apiKey.startsWith('sk_test_'); | ||
} | ||
|
||
export function isProductionFromApiKey(apiKey: string): boolean { | ||
return apiKey.startsWith('live_') || apiKey.startsWith('sk_live_'); | ||
} | ||
|
||
export function isStaging(frontendApi: string): boolean { | ||
return ( | ||
frontendApi.endsWith('.lclstage.dev') || | ||
frontendApi.endsWith('.stgstage.dev') || | ||
frontendApi.endsWith('.clerkstage.dev') || | ||
frontendApi.endsWith('.accountsstage.dev') | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters