Skip to content

Commit 2f63c34

Browse files
committed
Add SeamPaginator
1 parent b72f3bb commit 2f63c34

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/lib/seam/connect/seam-http-request.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ interface SeamHttpRequestConfig<TResponseKey> {
2020
readonly options?: Pick<SeamHttpRequestOptions, 'waitForActionAttempt'>
2121
}
2222

23+
interface Pagination {
24+
readonly hasNextPage: boolean
25+
readonly nextPageCursor: string | null
26+
}
27+
2328
export class SeamHttpRequest<
2429
const TResponse,
2530
const TResponseKey extends keyof TResponse | undefined,
@@ -33,6 +38,8 @@ export class SeamHttpRequest<
3338
readonly #parent: SeamHttpRequestParent
3439
readonly #config: SeamHttpRequestConfig<TResponseKey>
3540

41+
#pagination: Pagination | null = null
42+
3643
constructor(
3744
parent: SeamHttpRequestParent,
3845
config: SeamHttpRequestConfig<TResponseKey>,
@@ -56,15 +63,18 @@ export class SeamHttpRequest<
5663

5764
const origin = getUrlPrefix(client.defaults.baseURL ?? '')
5865

59-
const pathname = this.#config.path.startsWith('/')
60-
? this.#config.path
61-
: `/${this.#config.path}`
62-
63-
const path = params == null ? pathname : `${pathname}?${serializer(params)}`
66+
const path =
67+
params == null ? this.pathname : `${this.pathname}?${serializer(params)}`
6468

6569
return new URL(`${origin}${path}`)
6670
}
6771

72+
public get pathname(): string {
73+
return this.#config.path.startsWith('/')
74+
? this.#config.path
75+
: `/${this.#config.path}`
76+
}
77+
6878
public get method(): Method {
6979
return this.#config.method
7080
}
@@ -73,6 +83,10 @@ export class SeamHttpRequest<
7383
return this.#config.body
7484
}
7585

86+
public get pagination(): Pagination | null {
87+
return this.#pagination
88+
}
89+
7690
async execute(): Promise<
7791
TResponseKey extends keyof TResponse ? TResponse[TResponseKey] : undefined
7892
> {
@@ -88,6 +102,7 @@ export class SeamHttpRequest<
88102
? TResponse[TResponseKey]
89103
: undefined
90104
}
105+
if ('pagination' in response.data) this.#pagination = this.pagination
91106
const data = response.data[this.responseKey]
92107
if (this.responseKey === 'action_attempt') {
93108
const waitForActionAttempt =

src/lib/seam/connect/seam-http.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ import {
4040
SeamHttpWebhooks,
4141
SeamHttpWorkspaces,
4242
} from './routes/index.js'
43+
import type { SeamHttpRequest } from './seam-http-request.js'
44+
import { SeamPaginator } from './seam-paginator.js'
4345

4446
export class SeamHttp {
4547
client: Client
@@ -143,6 +145,10 @@ export class SeamHttp {
143145
return new SeamHttp(constructorOptions)
144146
}
145147

148+
createPaginator(page: SeamHttpRequest<any, any>): SeamPaginator {
149+
return new SeamPaginator(this, page)
150+
}
151+
146152
async updateClientSessionToken(
147153
clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'],
148154
): Promise<void> {

0 commit comments

Comments
 (0)