Skip to content

Commit 3e0dda8

Browse files
authored
Merge pull request #67 from seamapi/seam-api-request
Add SeamHttpRequest
2 parents d5c5a7a + 65021e4 commit 3e0dda8

32 files changed

+1196
-982
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,21 @@ const devices = await seam.client.get<DevicesListResponse>('/devices/list')
394394
An Axios compatible client may be provided to create a `SeamHttp` instance.
395395
This API is used internally and is not directly supported.
396396

397+
#### Inspecting the Request
398+
399+
All client methods return an instance of `SeamHttpRequest`.
400+
Inspect the request before it is sent to the server by intentionally not awaiting the `SeamHttpRequest`:
401+
402+
```ts
403+
const seam = new SeamHttp('your-api-key')
404+
405+
const request = seam.devices.list()
406+
407+
console.log(`${request.method} ${request.url}`, JSON.stringify(request.body))
408+
409+
const devices = await request.execute()
410+
```
411+
397412
## Development and Testing
398413

399414
### Quickstart

generate-routes.ts

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ import {
295295
import {
296296
resolveActionAttempt,
297297
} from 'lib/seam/connect/resolve-action-attempt.js'
298+
import { SeamHttpRequest } from 'lib/seam/connect/seam-http-request.js'
298299
299300
${
300301
namespace === 'client_sessions'
@@ -354,41 +355,25 @@ const renderClassMethod = ({
354355
path,
355356
isRequestParamOptional,
356357
}: Endpoint): string => `
357-
async ${camelCase(name)}(
358+
${camelCase(name)}(
358359
${requestFormat}${isRequestParamOptional ? '?' : ''}: ${renderRequestType({
359360
name,
360361
namespace,
361362
})},
362363
${renderClassMethodOptions({ resource })}
363-
): Promise<${
364+
): SeamHttpRequest<${
364365
resource === null
365-
? 'void'
366-
: `${renderResponseType({ name, namespace })}['${resource}']`
366+
? 'void, undefined'
367+
: `${renderResponseType({ name, namespace })}, '${resource}'`
367368
}> {
368-
${
369-
resource === null ? '' : 'const { data } = '
370-
}await this.client.request<${renderResponseType({
371-
name,
372-
namespace,
373-
})}>({
374-
url: '${path}',
369+
return new SeamHttpRequest(this, {
370+
path: '${path}',
375371
method: '${snakeCase(method)}', ${
376372
requestFormat === 'params' ? 'params,' : ''
377-
} ${requestFormat === 'body' ? 'data: body,' : ''}
373+
} ${requestFormat === 'body' ? 'body,' : ''}
374+
responseKey: ${resource === null ? 'undefined' : `'${resource}'`},
375+
${resource === 'action_attempt' ? 'options' : ''}
378376
})
379-
${
380-
resource === 'action_attempt'
381-
? `const waitForActionAttempt = options.waitForActionAttempt ?? this.defaults.waitForActionAttempt
382-
if (waitForActionAttempt !== false) {
383-
return resolveActionAttempt(
384-
data.${resource},
385-
SeamHttpActionAttempts.fromClient(this.client, { ...this.defaults, waitForActionAttempt: false }),
386-
typeof waitForActionAttempt === 'boolean' ? {} : waitForActionAttempt,
387-
)
388-
}`
389-
: ''
390-
}
391-
${resource === null ? '' : `return data.${resource}`}
392377
}
393378
`
394379

src/lib/seam/connect/routes/access-codes-unmanaged.ts

Lines changed: 37 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/seam/connect/routes/access-codes.ts

Lines changed: 56 additions & 60 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)