Skip to content
This repository was archived by the owner on Nov 15, 2024. It is now read-only.

Commit cb8c00e

Browse files
committed
Move getAuthHeaders down
1 parent 2bd1a40 commit cb8c00e

2 files changed

Lines changed: 42 additions & 42 deletions

File tree

docs/classes/Seam.md

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

src/seam-connect/client.ts

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -58,44 +58,6 @@ export const getSeamClientOptionsWithDefaults = (
5858
}
5959
}
6060

61-
const getAuthHeaders = ({
62-
clientSessionToken,
63-
apiKey,
64-
workspaceId,
65-
}: {
66-
clientSessionToken?: string
67-
apiKey?: string
68-
workspaceId?: string
69-
}): Record<string, string> => {
70-
if (apiKey && clientSessionToken) {
71-
throw new Error("You can't use clientSessionToken AND specify apiKey.")
72-
}
73-
74-
if (clientSessionToken) {
75-
if (!clientSessionToken.startsWith("seam_cst")) {
76-
throw new Error("clientSessionToken must start with seam_cst")
77-
}
78-
return { "client-session-token": clientSessionToken }
79-
}
80-
81-
if (apiKey) {
82-
if (apiKey.startsWith("seam_cst")) {
83-
console.warn(
84-
"Using API Key as Client Session Token is deprecated. Please use the clientSessionToken option instead."
85-
)
86-
return { "client-session-token": apiKey }
87-
}
88-
if (!apiKey.startsWith("seam_at") && workspaceId)
89-
throw new Error(
90-
"You can't use API Key Authentication AND specify a workspace. Your API Key only works for the workspace it was created in. To use Session Key Authentication with multi-workspace support, contact Seam support."
91-
)
92-
return { authorization: `Bearer ${apiKey}` }
93-
}
94-
throw new Error(
95-
"Must provide either clientSessionToken or apiKey (API Key or Access Token with Workspace ID)."
96-
)
97-
}
98-
9961
export class Seam extends Routes {
10062
public client: AxiosInstance
10163

@@ -217,3 +179,41 @@ const makeRequest = async <T>(
217179
throw error
218180
}
219181
}
182+
183+
const getAuthHeaders = ({
184+
clientSessionToken,
185+
apiKey,
186+
workspaceId,
187+
}: {
188+
clientSessionToken?: string
189+
apiKey?: string
190+
workspaceId?: string
191+
}): Record<string, string> => {
192+
if (apiKey && clientSessionToken) {
193+
throw new Error("You can't use clientSessionToken AND specify apiKey.")
194+
}
195+
196+
if (clientSessionToken) {
197+
if (!clientSessionToken.startsWith("seam_cst")) {
198+
throw new Error("clientSessionToken must start with seam_cst")
199+
}
200+
return { "client-session-token": clientSessionToken }
201+
}
202+
203+
if (apiKey) {
204+
if (apiKey.startsWith("seam_cst")) {
205+
console.warn(
206+
"Using API Key as Client Session Token is deprecated. Please use the clientSessionToken option instead."
207+
)
208+
return { "client-session-token": apiKey }
209+
}
210+
if (!apiKey.startsWith("seam_at") && workspaceId)
211+
throw new Error(
212+
"You can't use API Key Authentication AND specify a workspace. Your API Key only works for the workspace it was created in. To use Session Key Authentication with multi-workspace support, contact Seam support."
213+
)
214+
return { authorization: `Bearer ${apiKey}` }
215+
}
216+
throw new Error(
217+
"Must provide either clientSessionToken or apiKey (API Key or Access Token with Workspace ID)."
218+
)
219+
}

0 commit comments

Comments
 (0)