feat Support seam components#176
Conversation
|
|
||
| export type Event = Flatten<SeamEvent["event_type"]> | ||
|
|
||
| export interface ClientSessionI { |
There was a problem hiding this comment.
🐧 we don't generally add I/T suffixes in this repo
There was a problem hiding this comment.
It's a good practice to distinguish interface from a type.
There was a problem hiding this comment.
If we are going to introduce this, I think we should rename all interfaces to be consistent then.
There was a problem hiding this comment.
- Most importantly: we should match existing repo convention to avoid bikeshedding (same rules as open source), so shouldn't be there
RE: general rule
- should be prefix rather than suffix to match other Seam repos that use this convention
- not sure there's a meaningful enough difference between the interface and a type, the convention makes the most sense where classes are used. Since we almost never use classes (this SDK is a bit of an exception), it's usually unnecessary. Would be strongly opposed to adding a T prefix to types and to a lesser extent the I prefix, since it's typically already distinguished by PascalCase and there are no classes so that's enough
- If this comes up more often, having linter is better
There was a problem hiding this comment.
@codetheweb @razor-x @seveibar done ✅ 8cddcd7
| Authorization: `Bearer ${apiKey}`, | ||
| ["User-Agent"]: `Javascript SDK v${version} (https://github.com/seamapi/javascript)`, | ||
| Authorization: `Bearer ${apiKey || clientAccessToken}`, | ||
| // ["User-Agent"]: `Javascript SDK v${version} (https://github.com/seamapi/javascript)`, |
There was a problem hiding this comment.
| // ["User-Agent"]: `Javascript SDK v${version} (https://github.com/seamapi/javascript)`, | |
| ["User-Agent"]: `Javascript SDK v${version} (https://github.com/seamapi/javascript)`, |
There was a problem hiding this comment.
@codetheweb this line is causing browser errors
There was a problem hiding this comment.
@codetheweb are you sure you want it back?
There was a problem hiding this comment.
What are the errors? I'm assuming the browser doesn't like when JavaScript tries to override the user agent header. If so we probably need to selectively disable this in the browser environment.
There was a problem hiding this comment.
yeah we use the user agent in general to track SDK usage
maybe we could do a typeof window === "undefined" check?
There was a problem hiding this comment.
maybe we could
- keep
user-agentfor now until tooling is updated - disable
user-agentwhen in a browser - always send a second header like
x-seam-sdk-versionwith the same info
There was a problem hiding this comment.
@codetheweb okay, so I left it for Node but removed for window for backwards compatibility
f55f201 ✅
with seam-sdk-version we have an error I'll open a new issue
Access to XMLHttpRequest at 'http://localhost:3020/devices/list' from origin 'http://localhost:5173' has been blocked by CORS policy: Request header field seam-sdk-version is not allowed by Access-Control-Allow-Headers in preflight response.
| }, | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
I think we generally throw instead of directly returning the error
|
@seveibar any feedback would be appreciated. |
| } | ||
| } | ||
|
|
||
| type catParams = { |
There was a problem hiding this comment.
PascalCase types, need linter here
| type catParams = { | |
| type CATParams = { |
| params["user_identifier_key"] = ops.userIdentifierKey | ||
| try { | ||
| const response = await axios.post( | ||
| ops.endpoint + "internal/client_access_tokens/create", |
There was a problem hiding this comment.
| ops.endpoint + "internal/client_access_tokens/create", | |
| ops.endpoint + "internal/client_access_tokens/get_or_create_empty", |
There was a problem hiding this comment.
it's more clear that it will reuse an existing client session this way
There was a problem hiding this comment.
we had this thread in the connect repo
|
I think the overall approach is good! |
| "device" | ||
| ], | ||
| "version": "5.12.0", | ||
| "version": "5.12.1", |
There was a problem hiding this comment.
How did this version change in this PR branch? This doesn't seems right.
There was a problem hiding this comment.
@razor-x the PR bumps the version npm version patch
There was a problem hiding this comment.
We should revert this. It will confuse semantic release. Versions are automatically released off of main when PRs are merged
razor-x
left a comment
There was a problem hiding this comment.
Some questions on the option passing
| /* Seam API Key */ | ||
| apiKey?: string | ||
| /* Seam Client Access Token */ | ||
| clientAccessToken?: string |
There was a problem hiding this comment.
I noticed in the new seam provider, we just pass all the keys as apiKey even if it's a clientAccessToken.
Do we still want a new option? Or just have apiKey, let the user pass whatever token they have, and then use the prefix if we need to do special logic?
There was a problem hiding this comment.
i think we should be generous in acceptance (since it's detectable) but we shouldn't conflate the options
There was a problem hiding this comment.
| } | ||
|
|
||
| type CSTParams = { | ||
| publishedKey?: string |
There was a problem hiding this comment.
Needs updates to match
| publishedKey?: string | |
| publishableKey?: string |
There was a problem hiding this comment.
@razor-x done ✅ seamapi/react@ce81deb and d9a2278
|
@azat-co To make it easier to grok so we can discuss, here are my proposed interface changes illustrated visually. |
|
@razor-x disagree with making |
| export type Event = Flatten<SeamEvent["event_type"]> | ||
|
|
||
| export interface ClientSession { | ||
| client_access_token_id: string |
There was a problem hiding this comment.
/client access token/client session token/g
| events: Event[] | ||
| } | ||
|
|
||
| export interface ClientSessionResponseInterface { |
There was a problem hiding this comment.
Is there a reason for the Interface suffix? Not our usual convention
| /* Seam API Key */ | ||
| apiKey?: string | ||
| /* Seam Client Access Token */ | ||
| clientAccessToken?: string |
There was a problem hiding this comment.
i think we should be generous in acceptance (since it's detectable) but we shouldn't conflate the options
Yes so I think we should either avoid a new option and only have apiKey, or add a new option but not conflate them. So in that case if they try to provide both maybe that is an error, or if they pass in something with a mismatched prefix we should warn them. |
@razor-x yep agree, a warning/error that they need to use a different parameter is good. Could create an issue from this comment? |
This reverts commit 5ab0dea.
…nflate the options be generous in acceptance (since it's detectable) but we shouldn't conflate the options
Co-authored-by: Severin Ibarluzea <seveibar@gmail.com>
|
For reference, this is the branch with the current alpha version https://github.com/seamapi/javascript/tree/ver/5.15.0-alpha |
| clientAccessToken, | ||
| clientSessionToken, | ||
| } = getSeamClientOptionsWithDefaults(apiKeyOrOptions) | ||
| let bearer = `Bearer ` |
There was a problem hiding this comment.
This large nested if/else block is hard to parse. Perhaps easier to maintain if we move this to a function, then we can do early return. 🐧 E.g.,
const getBearerToken({ clientSessionToken, apiKey }) => {
if (apiKey || clientAccessToken) {
throw new Error(
"You can't use clientSessionToken AND specify apiKey or clientAccessToken."
)
}
if (clientSessionToken} {
if (!clientSessionToken?.startsWith("seam_cst")) throw
return clientSessionToken
}
There was a problem hiding this comment.
agree that this function is a bit hard to parse and early return would work better (especially because this bearer var is being mutated)
| const response: AxiosResponse & { | ||
| data: { client_session: ClientSession } | ||
| } = await axios.post( | ||
| (ops.endpoint ?? "https://connect.getseam.com") + |
There was a problem hiding this comment.
Can we re-use getSeamClientOptionsWithDefaults here? We are missing the fallback to SEAM_API_URL.
| const response: AxiosResponse & { | ||
| data: { client_session: ClientSession } | ||
| } = await axios.post( | ||
| (ops.endpoint ?? "https://connect.getseam.com") + |
There was a problem hiding this comment.
Can we normalize endpoint so we always strip any trailing slashes?
| // backend mode | ||
| headers["seam-api-key"] = ops.apiKey | ||
| } | ||
| headers["seam-user-identifier-key"] = ops.userIdentifierKey |
There was a problem hiding this comment.
| headers["seam-user-identifier-key"] = ops.userIdentifierKey | |
| if (ops.userIdentifierKey) { | |
| headers["seam-user-identifier-key"] = ops.userIdentifierKey | |
| } |
There was a problem hiding this comment.
I can't remember exactly but without the conditional this was either generating a type error or a runtime error upstream when userIdentifierKey was null or undefined.
| /* Seam API Key */ | ||
| apiKey?: string | ||
| /* Seam Client Access Token */ | ||
| clientAccessToken?: string |
There was a problem hiding this comment.
clientAccessToken is mislabeled, seam_at should never be used on a client. Maybe personalAccessToken or just accessToken?
(the only thing that should be used on clients are seam_cst)
There was a problem hiding this comment.
@seveibar It (AT) can be used on the backend which is the same code, right? We supported AT before this PR.
There was a problem hiding this comment.
I think this is just the old name right? Should be clientSessionToken?
razor-x
left a comment
There was a problem hiding this comment.
Looks good, just noted the one issue with not passing though the axiosOptions.
| throw new Error("userIdentifierKey is required") | ||
| } | ||
| try { | ||
| const response: AxiosResponse & { |
There was a problem hiding this comment.
@azat-co I didn't save my comment 😭
Anyway, was just going to say we should make sure to respect axiosOptions, so following the constructor, something like would work
const client = axios.create({
...axiosOptions,
baseURL: endpoint,
headers,
})
await client.post(...)Looking closer, I just realized the normal client behavior does a bit more, like always throw SeamAPIError. We should factor out the makeRequest method and use it both places. I will make an issue for that.
There was a problem hiding this comment.
@razor-x so do you mean instead of using axios directly, create a new instance with options? Makes sense!
There was a problem hiding this comment.
Yes, basically we should follow the same logic as the constructor for how we use axios. I created a new issue that better explains the desired behavior. It's ok if we resolve that issue in a follow-up PR.
fd6ca02 to
6da07a1
Compare
|
🎉 This PR is included in version 5.15.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |


No description provided.