-
Notifications
You must be signed in to change notification settings - Fork 2
[sc-208287] Add JWT and security classes to SDK #112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[sc-208287] Add JWT and security classes to SDK #112
Conversation
Reviewer's GuideAdds a security abstraction to the Deskpro SDK client, exposing JWT minting via a new Security API that delegates to parent window methods when available and falls back to safe no-op defaults. Sequence diagram for JWT minting via DeskproClient security APIsequenceDiagram
actor IntegrationApp
participant DeskproClient
participant Security
participant JWT
participant ParentWindow
IntegrationApp->>DeskproClient: security()
DeskproClient-->>IntegrationApp: Security
IntegrationApp->>Security: jwt(strategyName)
Security-->>IntegrationApp: JWT
IntegrationApp->>JWT: mint(context)
JWT->>DeskproClient: securityJwtMint(strategyName, context)
alt parent _securityJwtMint available
DeskproClient->>ParentWindow: _securityJwtMint(strategyName, context)
ParentWindow-->>DeskproClient: JwtMintResult
else no parent _securityJwtMint
DeskproClient-->>DeskproClient: use default securityJwtMint implementation
end
DeskproClient-->>JWT: JwtMintResult
JWT-->>IntegrationApp: JwtMintResult
Class diagram for new DeskproClient security and JWT abstractionsclassDiagram
class IDeskproClient {
<<interface>>
+securityJwtMint(strategyName: string, context: Context) JwtMintResult
+security() ISecurity
}
class DeskproClient {
+securityJwtMint(strategyName: string, context: Context) JwtMintResult
+security() ISecurity
}
class CoreCallSender {
<<interface>>
+_securityJwtMint(strategyName: string, context: Context) JwtMintResult
}
class ISecurity {
<<interface>>
+jwt(strategyName: string) IJWT
}
class Security {
-client IDeskproClient
+Security(client: IDeskproClient)
+jwt(strategyName: string) IJWT
}
class IJWT {
<<interface>>
+mint(context: Context) JwtMintResult
}
class JWT {
-client IDeskproClient
-strategyName string
+JWT(client: IDeskproClient, strategyName: string)
+mint(context: Context) JwtMintResult
}
class JwtMintResult {
+token string
+expiresAt string
}
DeskproClient ..|> IDeskproClient
Security ..|> ISecurity
JWT ..|> IJWT
DeskproClient --> Security : creates
Security --> JWT : creates
DeskproClient ..> CoreCallSender : delegates _securityJwtMint
DeskproClient --> JwtMintResult
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
5286116 to
f3e0331
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes - here's some feedback:
- The default implementation of
securityJwtMintin theDeskproClientconstructor returns a string, which does not match the declaredPromise<JwtMintResult>type; consider either returning aJwtMintResultstub or throwing an explicit error for unsupported environments. - The
securityJwtMintwrapper insideregisterParentMethodswraps the call in atry/catchthat simply rethrows the error; you can remove thetry/catchand directly returnparent._securityJwtMint(strategyName, context)for simpler code.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The default implementation of `securityJwtMint` in the `DeskproClient` constructor returns a string, which does not match the declared `Promise<JwtMintResult>` type; consider either returning a `JwtMintResult` stub or throwing an explicit error for unsupported environments.
- The `securityJwtMint` wrapper inside `registerParentMethods` wraps the call in a `try/catch` that simply rethrows the error; you can remove the `try/catch` and directly return `parent._securityJwtMint(strategyName, context)` for simpler code.
## Individual Comments
### Comment 1
<location> `src/client/client.ts:251` </location>
<code_context>
this.sendDeskproUIMessage = async () => { };
+ this.securityJwtMint = async () => "";
+
if (this.options.runAfterPageLoad) {
</code_context>
<issue_to_address>
**issue (bug_risk):** Default `securityJwtMint` implementation returns a string, which is inconsistent with the declared `Promise<JwtMintResult>` type.
This implementation should return a `JwtMintResult`-shaped object rather than a string to match the `Promise<JwtMintResult>` signature and avoid type or runtime mismatches for callers expecting `{ token, expiresAt }`.
</issue_to_address>
### Comment 2
<location> `src/client/client.ts:438-439` </location>
<code_context>
const result = await parent._securityJwtMint(strategyName, context);
return result;
</code_context>
<issue_to_address>
**suggestion (code-quality):** Inline variable that is immediately returned ([`inline-immediately-returned-variable`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/TypeScript/Default-Rules/inline-immediately-returned-variable))
```suggestion
return await parent._securityJwtMint(strategyName, context);
```
<br/><details><summary>Explanation</summary>Something that we often see in people's code is assigning to a result variable
and then immediately returning it.
Returning the result directly shortens the code and removes an unnecessary
variable, reducing the mental load of reading the function.
Where intermediate variables can be useful is if they then get used as a
parameter or a condition, and the name can act like a comment on what the
variable represents. In the case where you're returning it from a function, the
function name is there to tell you what the result is, so the variable name
is unnecessary.
</details>
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
AshleyDawson
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One tiny thing
f3e0331 to
e440dfc
Compare
Summary by Sourcery
Introduce SDK support for security-related operations centered around JWT minting.
New Features:
Enhancements: