@settlemint/sdk-utils
Advanced tools
Comparing version 0.9.9-prf74d9786 to 0.9.9-prfd0d04ff
@@ -631,3 +631,15 @@ import { ZodString, z, ZodSchema } from 'zod'; | ||
*/ | ||
declare function retryWhenFailed<T>(fn: () => Promise<T>, maxRetries?: number, initialSleepTime?: number, stopOnError?: (error: Error) => boolean): Promise<T | undefined>; | ||
declare function retryWhenFailed<T>(fn: () => Promise<T>, maxRetries?: number, initialSleepTime?: number, stopOnError?: (error: Error) => boolean): Promise<T>; | ||
/** | ||
* Retry an HTTP request with exponential backoff and jitter. | ||
* Only retries on server errors (5xx), rate limits (429), timeouts (408), and network errors. | ||
* | ||
* @param input - The URL or Request object to fetch | ||
* @param init - The fetch init options | ||
* @param maxRetries - Maximum number of retry attempts | ||
* @param initialSleepTime - Initial sleep time between retries in ms | ||
* @returns The fetch Response | ||
* @throws Error if all retries fail | ||
*/ | ||
declare function fetchWithRetry(input: RequestInfo | URL, init?: RequestInit, maxRetries?: number, initialSleepTime?: number): Promise<Response>; | ||
@@ -826,2 +838,2 @@ /** | ||
export { type AccessToken, AccessTokenSchema, type ApplicationAccessToken, ApplicationAccessTokenSchema, type DotEnv, type DotEnvPartial, DotEnvSchema, DotEnvSchemaPartial, type ExecuteCommandOptions, type Id, IdSchema, type PersonalAccessToken, PersonalAccessTokenSchema, type SpinnerOptions, type Template, UniqueNameSchema, type Url, type UrlOrPath, UrlOrPathSchema, type UrlPath, UrlPathSchema, UrlSchema, ascii, cancel, capitalizeFirstLetter, emptyDir, ensureBrowser, ensureServer, executeCommand, exists, findMonoRepoPackages, findMonoRepoRoot, formatTargetDir, getPackageManager, getPackageManagerExecutable, installDependencies, intro, isEmpty, isPackageInstalled, loadEnv, maskTokens, note, outro, projectRoot, retryWhenFailed, runsInBrowser, runsOnServer, setName, spinner, templates, tryParseJson, validate, writeEnv }; | ||
export { type AccessToken, AccessTokenSchema, type ApplicationAccessToken, ApplicationAccessTokenSchema, type DotEnv, type DotEnvPartial, DotEnvSchema, DotEnvSchemaPartial, type ExecuteCommandOptions, type Id, IdSchema, type PersonalAccessToken, PersonalAccessTokenSchema, type SpinnerOptions, type Template, UniqueNameSchema, type Url, type UrlOrPath, UrlOrPathSchema, type UrlPath, UrlPathSchema, UrlSchema, ascii, cancel, capitalizeFirstLetter, emptyDir, ensureBrowser, ensureServer, executeCommand, exists, fetchWithRetry, findMonoRepoPackages, findMonoRepoRoot, formatTargetDir, getPackageManager, getPackageManagerExecutable, installDependencies, intro, isEmpty, isPackageInstalled, loadEnv, maskTokens, note, outro, projectRoot, retryWhenFailed, runsInBrowser, runsOnServer, setName, spinner, templates, tryParseJson, validate, writeEnv }; |
{ | ||
"name": "@settlemint/sdk-utils", | ||
"description": "SettleMint SDK, integrate SettleMint into your application with ease.", | ||
"version": "0.9.9-prf74d9786", | ||
"version": "0.9.9-prfd0d04ff", | ||
"type": "module", | ||
@@ -6,0 +6,0 @@ "private": false, |
111
README.md
@@ -42,2 +42,5 @@ <p align="center"> | ||
- [exists()](#exists) | ||
- [fetchWithRetry()](#fetchwithretry) | ||
- [findMonoRepoPackages()](#findmonorepopackages) | ||
- [findMonoRepoRoot()](#findmonoreporoot) | ||
- [formatTargetDir()](#formattargetdir) | ||
@@ -55,2 +58,3 @@ - [getPackageManager()](#getpackagemanager) | ||
- [projectRoot()](#projectroot) | ||
- [retryWhenFailed()](#retrywhenfailed) | ||
- [setName()](#setname) | ||
@@ -344,2 +348,76 @@ - [spinner()](#spinner) | ||
#### fetchWithRetry() | ||
> **fetchWithRetry**(`input`, `init`?, `maxRetries`?, `initialSleepTime`?): `Promise`\<`Response`\> | ||
Defined in: [sdk/utils/src/retry.ts:52](https://github.com/settlemint/sdk/blob/v0.9.9/sdk/utils/src/retry.ts#L52) | ||
Retry an HTTP request with exponential backoff and jitter. | ||
Only retries on server errors (5xx), rate limits (429), timeouts (408), and network errors. | ||
##### Parameters | ||
| Parameter | Type | Default value | Description | | ||
| ------ | ------ | ------ | ------ | | ||
| `input` | `URL` \| `RequestInfo` | `undefined` | The URL or Request object to fetch | | ||
| `init`? | `RequestInit` | `undefined` | The fetch init options | | ||
| `maxRetries`? | `number` | `5` | Maximum number of retry attempts | | ||
| `initialSleepTime`? | `number` | `3_000` | Initial sleep time between retries in ms | | ||
##### Returns | ||
`Promise`\<`Response`\> | ||
The fetch Response | ||
##### Throws | ||
Error if all retries fail | ||
*** | ||
#### findMonoRepoPackages() | ||
> **findMonoRepoPackages**(`projectDir`): `Promise`\<`string`[]\> | ||
Defined in: [sdk/utils/src/filesystem/mono-repo.ts:49](https://github.com/settlemint/sdk/blob/v0.9.9/sdk/utils/src/filesystem/mono-repo.ts#L49) | ||
Finds all packages in a monorepo | ||
##### Parameters | ||
| Parameter | Type | Description | | ||
| ------ | ------ | ------ | | ||
| `projectDir` | `string` | The directory to start searching from | | ||
##### Returns | ||
`Promise`\<`string`[]\> | ||
An array of package directories | ||
*** | ||
#### findMonoRepoRoot() | ||
> **findMonoRepoRoot**(`startDir`): `Promise`\<`string` \| `null`\> | ||
Defined in: [sdk/utils/src/filesystem/mono-repo.ts:14](https://github.com/settlemint/sdk/blob/v0.9.9/sdk/utils/src/filesystem/mono-repo.ts#L14) | ||
Finds the root directory of a monorepo | ||
##### Parameters | ||
| Parameter | Type | Description | | ||
| ------ | ------ | ------ | | ||
| `startDir` | `string` | The directory to start searching from | | ||
##### Returns | ||
`Promise`\<`string` \| `null`\> | ||
The root directory of the monorepo or null if not found | ||
*** | ||
#### formatTargetDir() | ||
@@ -746,2 +824,33 @@ | ||
#### retryWhenFailed() | ||
> **retryWhenFailed**\<`T`\>(`fn`, `maxRetries`, `initialSleepTime`, `stopOnError`?): `Promise`\<`T`\> | ||
Defined in: [sdk/utils/src/retry.ts:9](https://github.com/settlemint/sdk/blob/v0.9.9/sdk/utils/src/retry.ts#L9) | ||
Retry a function when it fails. | ||
##### Type Parameters | ||
| Type Parameter | | ||
| ------ | | ||
| `T` | | ||
##### Parameters | ||
| Parameter | Type | Default value | Description | | ||
| ------ | ------ | ------ | ------ | | ||
| `fn` | () => `Promise`\<`T`\> | `undefined` | The function to retry. | | ||
| `maxRetries` | `number` | `5` | The maximum number of retries. | | ||
| `initialSleepTime` | `number` | `3_000` | The initial time to sleep between exponential backoff retries. | | ||
| `stopOnError`? | (`error`) => `boolean` | `undefined` | The function to stop on error. | | ||
##### Returns | ||
`Promise`\<`T`\> | ||
The result of the function or undefined if it fails. | ||
*** | ||
#### setName() | ||
@@ -922,3 +1031,3 @@ | ||
Defined in: [sdk/utils/src/environment/write-env.ts:81](https://github.com/settlemint/sdk/blob/v0.9.9/sdk/utils/src/environment/write-env.ts#L81) | ||
Defined in: [sdk/utils/src/environment/write-env.ts:30](https://github.com/settlemint/sdk/blob/v0.9.9/sdk/utils/src/environment/write-env.ts#L30) | ||
@@ -925,0 +1034,0 @@ Writes environment variables to .env files across a project or monorepo |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
647169
4952
1543
6