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

Commit 8544e27

Browse files
seveibarrazor-x
andauthored
fix: Treat undefined and missing options passed to Seam the same way
BREAKING CHANGE: Passing undefined to the Seam constructor will now use a default value instead of undefined. If you are explicitly passing any options as undefined and expecting them to be unset, instead pass them explicitly as null. Co-authored-by: Evan Sosenko <[email protected]>
1 parent 6c78c9d commit 8544e27

File tree

3 files changed

+34
-20
lines changed

3 files changed

+34
-20
lines changed

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.

docs/interfaces/SeamClientOptions.md

Lines changed: 2 additions & 2 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: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import { ClientSessionsResponse } from "../types"
1717

1818
export interface SeamClientOptions {
1919
/* Seam API Key */
20-
apiKey?: string
20+
apiKey?: string | null
2121
/* Seam Client Session Token */
22-
clientSessionToken?: string
22+
clientSessionToken?: string | null
2323
/**
2424
* Seam Endpoint to use, defaults to https://connect.getseam.com
2525
**/
@@ -38,17 +38,31 @@ export interface SeamClientOptions {
3838
export const getSeamClientOptionsWithDefaults = (
3939
apiKeyOrOptions?: string | SeamClientOptions
4040
): SeamClientOptions => {
41-
const seamClientDefaults = {
42-
apiKey: globalThis?.process?.env?.SEAM_API_KEY ?? undefined,
41+
const providedOptions =
42+
typeof apiKeyOrOptions === "string"
43+
? { apiKey: apiKeyOrOptions }
44+
: apiKeyOrOptions ?? {}
45+
46+
return {
47+
apiKey:
48+
providedOptions.apiKey === null
49+
? null
50+
: providedOptions.apiKey ??
51+
globalThis?.process?.env?.SEAM_API_KEY ??
52+
null,
4353
endpoint:
44-
globalThis?.process?.env?.SEAM_API_URL ?? "https://connect.getseam.com",
45-
workspaceId: globalThis?.process?.env?.SEAM_WORKSPACE_ID ?? undefined,
46-
}
47-
if (typeof apiKeyOrOptions === "string") {
48-
// for both browser and server, if apiKeyOrOptions is a string, use it as the apiKey, and merge with defaults
49-
return { ...seamClientDefaults, apiKey: apiKeyOrOptions }
50-
} else {
51-
return { ...seamClientDefaults, ...apiKeyOrOptions }
54+
providedOptions.endpoint ??
55+
globalThis?.process?.env?.SEAM_API_URL ??
56+
"https://connect.getseam.com",
57+
workspaceId:
58+
providedOptions.workspaceId ??
59+
globalThis?.process?.env?.SEAM_WORKSPACE_ID ??
60+
undefined,
61+
axiosOptions: providedOptions.axiosOptions ?? {},
62+
clientSessionToken:
63+
providedOptions.clientSessionToken === null
64+
? null
65+
: providedOptions.clientSessionToken ?? null,
5266
}
5367
}
5468

@@ -190,8 +204,8 @@ const getAuthHeaders = ({
190204
apiKey,
191205
workspaceId,
192206
}: {
193-
clientSessionToken?: string
194-
apiKey?: string
207+
clientSessionToken?: string | null
208+
apiKey?: string | null
195209
workspaceId?: string
196210
}): Record<string, string> => {
197211
if (apiKey && clientSessionToken) {

0 commit comments

Comments
 (0)