Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -466,15 +466,26 @@ const seam = new SeamHttp({
```

Set `timeout` to `0` to disable the timeout entirely.
A request that times out rejects with an Axios `ETIMEDOUT` error,
and is retried according to the retry options.
A request that times out rejects with an Axios `ETIMEDOUT` error.
Timed-out idempotent requests are retried according to the retry options, with
the timeout reset for each attempt. Non-idempotent requests are not retried by
default.

#### Configuring the Axios Client

The Axios client and retry behavior may be configured with custom initiation options
via [`axiosOptions`][axiosOptions] and [`axiosRetryOptions`][axiosRetryOptions].
Options are deep merged with the default options.

By default, the SDK makes up to three attempts: the initial request and two
retries. Retries are limited to `GET`, `HEAD`, `OPTIONS`, `PUT`, and `DELETE`
requests that fail because of a transport error, timeout, HTTP 429 response, or
HTTP 5xx response. `POST` and `PATCH` requests are not retried.

Retries use exponential backoff with jitter: approximately 200–240 ms before
the first retry and 400–480 ms before the second. A longer `Retry-After` header
is honored. The request timeout is reset for each attempt.

[axiosOptions]: https://axios-http.com/docs/config_defaults
[axiosRetryOptions]: https://github.com/softonic/axios-retry

Expand Down
4 changes: 2 additions & 2 deletions codegen/lib/layouts/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export const getEndpointLayoutContext = (
}

const requestFormat = ['GET', 'DELETE'].includes(
endpoint.request.preferredMethod,
endpoint.request.semanticMethod,
)
? 'params'
: 'body'
Expand All @@ -132,7 +132,7 @@ export const getEndpointLayoutContext = (
path: endpoint.path,
methodName,
functionName: camelCase(prefix),
method: endpoint.request.preferredMethod,
method: endpoint.request.semanticMethod,
className: getClassName(route.path),
requestFormat,
returnsActionAttempt,
Expand Down
30 changes: 6 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
},
"devDependencies": {
"@seamapi/blueprint": "^1.1.0",
"@seamapi/fake-seam-connect": "^1.77.0",
"@seamapi/fake-seam-connect": "^2.0.3",
"@seamapi/smith": "^1.1.0",
"@seamapi/types": "1.983.0",
"@types/jsonwebtoken": "^9.0.6",
Expand Down
21 changes: 18 additions & 3 deletions src/lib/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { serializeUrlSearchParams } from '@seamapi/url-search-params-serializer'
import axios, { type AxiosInstance, type AxiosRequestConfig } from 'axios'
import axiosRetry, { type AxiosRetry, exponentialDelay } from 'axios-retry'
import axiosRetry, {
type AxiosRetry,
exponentialDelay,
isIdempotentRequestError,
} from 'axios-retry'

import { errorInterceptor } from './error-interceptor.js'

Expand All @@ -16,6 +20,18 @@ export interface ClientOptions {

type AxiosRetryConfig = Parameters<AxiosRetry>[1]

type RequiredAxiosRetryConfig = Required<NonNullable<AxiosRetryConfig>>

const defaultAxiosRetryOptions = {
retries: 2,
retryCondition: isIdempotentRequestError,
retryDelay: exponentialDelay,
shouldResetTimeout: true,
onRetry: () => undefined,
onMaxRetryTimesExceeded: () => undefined,
validateResponse: null,
} satisfies RequiredAxiosRetryConfig

export const createClient = (options: ClientOptions): AxiosInstance => {
const client = axios.create({
paramsSerializer: serializeUrlSearchParams,
Expand All @@ -25,8 +41,7 @@ export const createClient = (options: ClientOptions): AxiosInstance => {
})

axiosRetry(client, {
retries: 2,
retryDelay: exponentialDelay,
...defaultAxiosRetryOptions,
...options.axiosRetryOptions,
})

Expand Down
16 changes: 8 additions & 8 deletions src/lib/routes/access-codes/access-codes.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions src/lib/routes/access-codes/unmanaged/unmanaged.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions src/lib/routes/access-grants/access-grants.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/lib/routes/access-grants/unmanaged/unmanaged.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions src/lib/routes/access-methods/access-methods.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/lib/routes/access-methods/unmanaged/unmanaged.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading