-
Notifications
You must be signed in to change notification settings - Fork 0
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
fix: edge runtime support for crypto #184
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
Warning Rate limit exceeded@nadilas has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 40 minutes and 55 seconds before requesting another review. How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughThe recent changes streamline the Changes
Sequence Diagram(s) (Beta)sequenceDiagram
participant User
participant DigestFunction
participant Utils
User->>DigestFunction: Call digest(obj, algorithm)
DigestFunction->>Utils: Call isBrowser()
Utils-->>DigestFunction: Return true/false
DigestFunction-->>User: Return hash string
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
This stack of pull requests is managed by Graphite. Learn more about stacking. |
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.
Actionable comments posted: 3
Outside diff range and nitpick comments (3)
packages/ogre/src/hash.ts (2)
Line range hint
47-47
: Import Node.js built-in modules using thenode:
protocol for clarity and consistency.digest = (await import("node:crypto")) .createHash(nodeAlg) .update(Buffer.from(hashInput)) .digest("hex");
Line range hint
34-54
: Refactor the anonymous function to an arrow function for better readability and to follow modern JavaScript practices.return (async (obj, algorithm) => { // function body remains the same })(obj, algorithm);packages/ogre/src/utils.ts (1)
Line range hint
53-53
: Specify a more precise type thanany
for thetree
parameter to enhance type safety.export const treeToObject = <T = Record<string, unknown>>(tree: string): T => { // function body remains the same }
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- packages/ogre/src/hash.ts (3 hunks)
- packages/ogre/src/utils.ts (1 hunks)
Additional context used
Biome
packages/ogre/src/hash.ts
[error] 26-26: Unexpected any. Specify a different type.
[error] 42-44: Prefer for...of instead of forEach.
[error] 47-47: A Node.js builtin module should be imported with the node: protocol.
[error] 34-54: This function expression can be turned into an arrow function.
[error] 57-57: Unexpected any. Specify a different type.
[error] 61-61: Unexpected any. Specify a different type.
[error] 61-61: Unexpected any. Specify a different type.
packages/ogre/src/utils.ts
[error] 13-13: Invalid
typeof
comparison value: this expression is not a string literal
[error] 16-16: Do not use template literals if interpolation and special-character handling are not needed.
[error] 36-36: Do not use template literals if interpolation and special-character handling are not needed.
[error] 37-37: Do not use template literals if interpolation and special-character handling are not needed.
[error] 53-53: Unexpected any. Specify a different type.
[error] 106-106: This variable implicitly has the any type.
[error] 177-177: Do not use template literals if interpolation and special-character handling are not needed.
[error] 196-196: Do not use template literals if interpolation and special-character handling are not needed.
[error] 199-199: This type annotation is trivially inferred from its initialization.
[error] 201-201: Do not use template literals if interpolation and special-character handling are not needed.
[error] 208-208: Unexpected any. Specify a different type.
[error] 217-217: Do not use template literals if interpolation and special-character handling are not needed.
[error] 265-265: Constraining a type parameter to any or unknown is useless.
[error] 1-2: All these imports are only used as types.
[error] 2-3: All these imports are only used as types.
[error] 5-6: Some named imports are only used as types.
[error] 6-7: All these imports are only used as types.
Additional comments not posted (4)
packages/ogre/src/hash.ts (2)
10-10
: Import statement updated to includeisBrowser
fromutils.js
.
26-26
: The function signature has been simplified by removing theisBrowser
parameter.packages/ogre/src/utils.ts (2)
12-13
: TheisBrowser
function has been introduced to determine if the runtime environment is a browser.
12-12
: ThecleanAuthor
function now returns a tuple with the author's name and email, enhancing the function's utility by providing more structured data.
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.
Actionable comments posted: 2
Outside diff range and nitpick comments (1)
packages/ogre/src/utils.ts (1)
14-14
: Avoid using template literals where not necessary.// Replace template literals with simple strings where interpolation is not used. return [strings[0], strings[1].replace(">", "")];
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- .github/workflows/coverage.yml (1 hunks)
- packages/ogre/src/hash.ts (3 hunks)
- packages/ogre/src/utils.ts (1 hunks)
Additional context used
Biome
packages/ogre/src/hash.ts
[error] 26-26: Unexpected any. Specify a different type.
[error] 34-54: This function expression can be turned into an arrow function.
[error] 57-57: Unexpected any. Specify a different type.
[error] 61-61: Unexpected any. Specify a different type.
[error] 61-61: Unexpected any. Specify a different type.
packages/ogre/src/utils.ts
[error] 17-17: Do not use template literals if interpolation and special-character handling are not needed.
[error] 37-37: Do not use template literals if interpolation and special-character handling are not needed.
[error] 38-38: Do not use template literals if interpolation and special-character handling are not needed.
[error] 54-54: Unexpected any. Specify a different type.
[error] 107-107: This variable implicitly has the any type.
[error] 178-178: Do not use template literals if interpolation and special-character handling are not needed.
[error] 197-197: Do not use template literals if interpolation and special-character handling are not needed.
[error] 200-200: This type annotation is trivially inferred from its initialization.
[error] 202-202: Do not use template literals if interpolation and special-character handling are not needed.
[error] 209-209: Unexpected any. Specify a different type.
[error] 218-218: Do not use template literals if interpolation and special-character handling are not needed.
[error] 266-266: Constraining a type parameter to any or unknown is useless.
[error] 1-2: All these imports are only used as types.
[error] 2-3: All these imports are only used as types.
[error] 5-6: Some named imports are only used as types.
[error] 6-7: All these imports are only used as types.
Additional comments not posted (4)
packages/ogre/src/hash.ts (2)
10-10
: Import addition looks good.
39-47
: Ensure correct environment handling in thedigest
function.Verification successful
The
isBrowser
function is correctly implemented inpackages/ogre/src/utils.ts
to identify the browser environment by checking for the presence ofwindow
andwindow.document
. The environment handling in thedigest
function inpackages/ogre/src/hash.ts
appears to be correctly switching between browser and Node.js environments based on this function.
isBrowser
function implementation:export const isBrowser = () => typeof window !== "undefined" && typeof window.document !== "undefined";Environment handling in
digest
function:if (isBrowser()) { const buf = await crypto.subtle.digest(algorithm, hashInput); const h = "0123456789abcdef"; for (const v of new Uint8Array(buf)) { digest += h[v >> 4] + h[v & 15]; } } else { const nodeAlg = algorithm.toLowerCase().replace("-", ""); digest = (await import("node:crypto")) .createHash(nodeAlg) .update(Buffer.from(hashInput)) .digest("hex"); }The code correctly handles different environments, ensuring the appropriate cryptographic operations are performed based on whether the code is running in a browser or Node.js environment.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that the environment handling in the `digest` function correctly switches between browser and Node.js environments. # Test: Search for environment-specific code paths. Expect: Correct usage of `isBrowser()` and appropriate handling in both environments. ast-grep --lang typescript --pattern $'if (isBrowser()) { $$$ } else { $$$ }' packages/ogre/src/hash.tsLength of output: 946
Script:
#!/bin/bash # Description: Locate and inspect the implementation of the `isBrowser()` function to ensure it correctly identifies the environment. # Find the implementation of `isBrowser` function ast-grep --lang typescript --pattern 'function isBrowser() { $$$ }'Length of output: 69
Script:
#!/bin/bash # Description: Search for the `isBrowser` keyword to locate its definition or import statement. # Search for `isBrowser` keyword in the codebase rg 'isBrowser'Length of output: 233
Script:
#!/bin/bash # Description: Display the content of `packages/ogre/src/utils.ts` to verify the `isBrowser` function implementation. # Display the content of `packages/ogre/src/utils.ts` cat packages/ogre/src/utils.tsLength of output: 8854
packages/ogre/src/utils.ts (2)
12-13
: Addition ofisBrowser
function is appropriate for environment checks.
14-14
: Change incleanAuthor
function to return a tuple enhances data structure.
…ypto" is not handled by plugins
🚀 PR was released in |
Summary by CodeRabbit
New Features
Bug Fixes
digest
function to simplify its usage and improve reliability.Chores
📦 Published PR as canary version:
Canary Versions
✨ Test out this PR locally via: