Skip to content

Commit

Permalink
Merge pull request #67 from seamapi/seam-api-request
Browse files Browse the repository at this point in the history
Add SeamHttpRequest
  • Loading branch information
phpnode authored Mar 27, 2024
2 parents d5c5a7a + 65021e4 commit 3e0dda8
Show file tree
Hide file tree
Showing 32 changed files with 1,196 additions and 982 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,21 @@ const devices = await seam.client.get<DevicesListResponse>('/devices/list')
An Axios compatible client may be provided to create a `SeamHttp` instance.
This API is used internally and is not directly supported.

#### Inspecting the Request

All client methods return an instance of `SeamHttpRequest`.
Inspect the request before it is sent to the server by intentionally not awaiting the `SeamHttpRequest`:

```ts
const seam = new SeamHttp('your-api-key')

const request = seam.devices.list()

console.log(`${request.method} ${request.url}`, JSON.stringify(request.body))

const devices = await request.execute()
```

## Development and Testing

### Quickstart
Expand Down
35 changes: 10 additions & 25 deletions generate-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ import {
import {
resolveActionAttempt,
} from 'lib/seam/connect/resolve-action-attempt.js'
import { SeamHttpRequest } from 'lib/seam/connect/seam-http-request.js'
${
namespace === 'client_sessions'
Expand Down Expand Up @@ -354,41 +355,25 @@ const renderClassMethod = ({
path,
isRequestParamOptional,
}: Endpoint): string => `
async ${camelCase(name)}(
${camelCase(name)}(
${requestFormat}${isRequestParamOptional ? '?' : ''}: ${renderRequestType({
name,
namespace,
})},
${renderClassMethodOptions({ resource })}
): Promise<${
): SeamHttpRequest<${
resource === null
? 'void'
: `${renderResponseType({ name, namespace })}['${resource}']`
? 'void, undefined'
: `${renderResponseType({ name, namespace })}, '${resource}'`
}> {
${
resource === null ? '' : 'const { data } = '
}await this.client.request<${renderResponseType({
name,
namespace,
})}>({
url: '${path}',
return new SeamHttpRequest(this, {
path: '${path}',
method: '${snakeCase(method)}', ${
requestFormat === 'params' ? 'params,' : ''
} ${requestFormat === 'body' ? 'data: body,' : ''}
} ${requestFormat === 'body' ? 'body,' : ''}
responseKey: ${resource === null ? 'undefined' : `'${resource}'`},
${resource === 'action_attempt' ? 'options' : ''}
})
${
resource === 'action_attempt'
? `const waitForActionAttempt = options.waitForActionAttempt ?? this.defaults.waitForActionAttempt
if (waitForActionAttempt !== false) {
return resolveActionAttempt(
data.${resource},
SeamHttpActionAttempts.fromClient(this.client, { ...this.defaults, waitForActionAttempt: false }),
typeof waitForActionAttempt === 'boolean' ? {} : waitForActionAttempt,
)
}`
: ''
}
${resource === null ? '' : `return data.${resource}`}
}
`

Expand Down
71 changes: 37 additions & 34 deletions src/lib/seam/connect/routes/access-codes-unmanaged.ts

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

116 changes: 56 additions & 60 deletions src/lib/seam/connect/routes/access-codes.ts

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

Loading

0 comments on commit 3e0dda8

Please sign in to comment.