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

Commit 3168495

Browse files
authored
Merge pull request #173 from seamapi/make-browser-compatible
make browser compatible
2 parents f596b9a + dc2c768 commit 3168495

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

docs/classes/Seam.md

Lines changed: 3 additions & 3 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: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,20 @@ export interface SeamClientOptions {
2626
export const getSeamClientOptionsWithDefaults = (
2727
apiKeyOrOptions?: string | SeamClientOptions
2828
): SeamClientOptions => {
29-
const seamClientDefaults: SeamClientOptions = {
30-
apiKey: process?.env?.SEAM_API_KEY,
31-
endpoint: process?.env?.SEAM_API_URL || "https://connect.getseam.com",
32-
workspaceId: process?.env?.SEAM_WORKSPACE_ID,
29+
let seamClientDefaults: SeamClientOptions = {}
30+
try {
31+
// try to get defaults from environment (for server-side use)
32+
seamClientDefaults = {
33+
apiKey: process?.env?.SEAM_API_KEY,
34+
endpoint: process?.env?.SEAM_API_URL || "https://connect.getseam.com",
35+
workspaceId: process?.env?.SEAM_WORKSPACE_ID,
36+
}
37+
} catch (error) {
38+
// we are in a browser, so use the apiKeyOrOptions
39+
// do nothing
3340
}
3441
if (typeof apiKeyOrOptions === "string") {
42+
// for both browser and server, if apiKeyOrOptions is a string, use it as the apiKey, and merge with defaults
3543
return { ...seamClientDefaults, apiKey: apiKeyOrOptions }
3644
} else {
3745
return { ...seamClientDefaults, ...apiKeyOrOptions }

0 commit comments

Comments
 (0)