Skip to content

Commit 187a36e

Browse files
committed
Add support for legacy behavior override
1 parent 95eefea commit 187a36e

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

src/lib/seam/connect/client-options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export type SeamHttpOptions =
77
interface SeamHttpCommonOptions {
88
endpoint?: string
99
axiosOptions?: AxiosRequestConfig
10+
enableLegacyMethodBehaivor?: boolean
1011
}
1112

1213
export interface SeamHttpOptionsWithApiKey extends SeamHttpCommonOptions {

src/lib/seam/connect/client.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,23 @@ import {
99
type SeamHttpOptionsWithApiKey,
1010
type SeamHttpOptionsWithClientSessionToken,
1111
} from './client-options.js'
12+
import { LegacyWorkspaces } from './legacy/workspaces.js'
1213
import { Workspaces } from './routes/workspaces.js'
1314

1415
export class SeamHttp {
1516
client: Axios
1617

18+
#legacy: boolean
19+
1720
constructor(apiKeyOrOptions: string | SeamHttpOptions) {
1821
const options = parseOptions(
1922
typeof apiKeyOrOptions === 'string'
2023
? { apiKey: apiKeyOrOptions }
2124
: apiKeyOrOptions,
2225
)
2326

27+
this.#legacy = options.enableLegacyMethodBehaivor
28+
2429
// TODO: axiosRetry? Allow options to configure this if so
2530
this.client = axios.create({
2631
baseURL: options.endpoint,
@@ -67,7 +72,9 @@ export class SeamHttp {
6772
// makeRequest
6873

6974
get workspaces(): Workspaces {
70-
return new Workspaces(this.client)
75+
const workspaces = new Workspaces(this.client)
76+
if (this.#legacy) return new LegacyWorkspaces(this.client)
77+
return workspaces
7178
}
7279
}
7380

@@ -88,5 +95,6 @@ const parseOptions = (options: SeamHttpOptions): Required<SeamHttpOptions> => {
8895
...(apiKey != null ? { apiKey } : {}),
8996
endpoint,
9097
axiosOptions: options.axiosOptions ?? {},
98+
enableLegacyMethodBehaivor: false,
9199
}
92100
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// TODO: Example of non-generated overrides to methods to preserve legacy behavior
2+
import type { Routes } from '@seamapi/types/connect'
3+
import type { SetNonNullable } from 'type-fest'
4+
5+
import { Workspaces } from 'lib/seam/connect/routes/workspaces.js'
6+
7+
export class LegacyWorkspaces extends Workspaces {
8+
override async get(params: WorkspacesGetParams = {}): Promise<Workspace> {
9+
const {
10+
data: { workspace },
11+
} = await this.client.get<WorkspacesGetResponse>('/workspaces/get', {
12+
params,
13+
})
14+
return workspace
15+
}
16+
}
17+
18+
export type WorkspacesGetParams = SetNonNullable<
19+
Required<Routes['/workspaces/get']['commonParams']>
20+
>
21+
22+
export type WorkspacesGetResponse = SetNonNullable<
23+
Required<Routes['/workspaces/get']['jsonResponse']>
24+
>
25+
26+
// UPSTREAM: Should come from @seamapi/types/connect
27+
// import type { Workspace } from @seamapi/types
28+
// export type { Workspace } from '@seamapi/types/connect'
29+
export interface Workspace {
30+
workspace_id: string
31+
}

src/lib/seam/connect/routes/workspaces.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import type { Axios } from 'axios'
44
import type { SetNonNullable } from 'type-fest'
55

66
export class Workspaces {
7-
#client: Axios
7+
client: Axios
88

99
constructor(client: Axios) {
10-
this.#client = client
10+
this.client = client
1111
}
1212

1313
async get(params: WorkspacesGetParams = {}): Promise<Workspace> {
1414
const {
1515
data: { workspace },
16-
} = await this.#client.get<WorkspacesGetResponse>('/workspaces/get', {
16+
} = await this.client.get<WorkspacesGetResponse>('/workspaces/get', {
1717
params,
1818
})
1919
return workspace

0 commit comments

Comments
 (0)