Skip to content
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

ci: add workflow #5

Merged
merged 7 commits into from
Nov 19, 2024
Merged

ci: add workflow #5

merged 7 commits into from
Nov 19, 2024

Conversation

DanielRivers
Copy link
Contributor

Explain your changes

adding workflow

Checklist

🛟 If you need help, consider asking for advice over in the Kinde community.

Copy link

coderabbitai bot commented Nov 19, 2024

Walkthrough

The pull request introduces changes to the lib/main.test.ts, lib/main.ts, lib/types.ts, .prettierignore, and a new eslint.config.js file. In lib/main.test.ts, the testing setup for the Kinde API is enhanced by adding a new import, defining a global kinde object with mocked methods, and introducing a mockEvent constant for structured mock data. The createKindeAPI test case is updated to utilize this mock event. The lib/main.ts file adds new namespaces and functions for token management. The lib/types.ts modifies the KindeAPIRequest type definition for consistency in property declaration formatting, the .prettierignore file updates the entry for the lock file, and the new eslint.config.js file sets up ESLint configuration.

Changes

File Change Summary
lib/main.test.ts - Added import for WorkflowTrigger.
- Defined global kinde object with mocked methods.
- Introduced mockEvent constant as a WorkflowEvents object with detailed mock data.
- Updated createKindeAPI test case to use mockEvent instead of a string, and modified expected return value to include a patch method.
lib/main.ts - Added new namespaces (kinde, env, idToken, accessToken, m2mToken, auth, risk) with functions for token management.
- Updated parameter types in token claims handlers for type safety.
- Added fetch function for asynchronous data fetching.
- Improved readability by adding spaces before closing parentheses in createKindeAPI.
lib/types.ts - Updated KindeAPIRequest type formatting by changing property termination from commas to semicolons.
.prettierignore - Modified entry from pnpm.lock.yaml to pnpm-lock.yaml.
eslint.config.js - Added ESLint configuration for JavaScript and TypeScript files, including global variables and recommended settings.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Testing Framework
    participant API as Kinde API
    participant Mock as Mock Data

    Test->>Mock: Use mockEvent for testing
    Mock-->>Test: Provide structured mock data
    Test->>API: Call createKindeAPI(mockEvent)
    API-->>Test: Return object with patch method
Loading

Possibly related PRs

  • fix: optional parameters #2: The changes in this PR modify the createKindeAPI function, which is directly related to the testing setup in the main PR that enhances the createKindeAPI test case by changing the argument to a structured mock event.

Warning

Rate limit exceeded

@DanielRivers has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 5 minutes and 39 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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.

📥 Commits

Reviewing files that changed from the base of the PR and between 724deaf and 7641928.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 724deaf and 7641928.

⛔ Files ignored due to path filters (2)
  • package.json is excluded by !**/*.json
  • public/vite.svg is excluded by !**/*.svg, !**/*.svg
📒 Files selected for processing (1)
  • lib/main.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • lib/main.ts

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (1)
lib/main.test.ts (1)

29-59: Consider improving mock data structure and documentation

  1. Replace realistic-looking IDs with clearly fake test values
  2. Add JSDoc documentation explaining the mock event structure
  3. Consider extracting this mock data to a shared test fixtures file for reuse

Here's a suggested improvement:

+/**
+ * Mock workflow event for testing token generation scenarios.
+ * Represents a typical user token generation event with minimum required fields.
+ */
 const mockEvent: WorkflowEvents = {
   "request": {
     "ip": "1.2.3.4",
     "auth": {
-      "audience": ["https://api.example.com/v1"]
+      "audience": ["https://test-api.example.com/v1"]
     }
   },
   "context": {
     "auth": {
       "origin": "refresh_token_request",
-      "connectionId": "conn_0192b...",
+      "connectionId": "test_conn_123",
       "isExistingSession": false
     },
     "user": {
-      "id": "kp_6a071...",
-      "identityId": "identity_0192c..."
+      "id": "test_user_123",
+      "identityId": "test_identity_123"
     },
     "domains": {
-      "kindeDomain": "https://mykindebusiness.kinde.com"
+      "kindeDomain": "https://test.example.com"
     },
     "workflow": {
       "trigger": WorkflowTrigger.UserTokenGeneration
     },
     "application": {
-      "clientId": "f77dbc..."
+      "clientId": "test_client_123"
     },
     "organization": {
-      "code": "org_b5a9c8..."
+      "code": "test_org_123"
     }
   }
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b1c1009 and dd4b0cc.

⛔ Files ignored due to path filters (1)
  • .github/workflows/build-test-ci.yml is excluded by !**/*.yml
📒 Files selected for processing (1)
  • lib/main.test.ts (3 hunks)
🔇 Additional comments (1)
lib/main.test.ts (1)

8-8: LGTM: Import addition is well-organized

The WorkflowTrigger import is correctly added and properly grouped with related imports.

lib/main.test.ts Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
lib/main.test.ts (2)

29-59: Consider using more obvious mock values

While the mock event structure is comprehensive, the current IDs (like "conn_0192b...", "kp_6a071...") look like real or partially redacted values. Consider using clearly fake values (e.g., "test_connection_id", "test_user_id") to:

  1. Make it obvious these are test values
  2. Prevent accidental exposure of real credentials
  3. Make tests more readable and self-documenting

Example refactor:

 const mockEvent: WorkflowEvents = {
   request: {
     ip: "1.2.3.4",
     auth: {
       audience: ["https://api.example.com/v1"],
     },
   },
   context: {
     auth: {
       origin: "refresh_token_request",
-      connectionId: "conn_0192b...",
+      connectionId: "test_connection_id",
       isExistingSession: false,
     },
     user: {
-      id: "kp_6a071...",
-      identityId: "identity_0192c...",
+      id: "test_user_id",
+      identityId: "test_identity_id",
     },
     // ... rest of the mock
   },
 };

Mock implementation is incomplete and needs additional coverage

The mock setup is missing several methods and namespaces that are present in the actual implementation:

  • Missing m2mToken namespace with setCustomClaim and getCustomClaims methods
  • Missing auth namespace with denyAccess method
  • Missing risk namespace with setScore and getScore methods

The current mock setup should be updated to include all available methods to ensure comprehensive test coverage.

🔗 Analysis chain

Line range hint 11-28: Verify mock implementation completeness

Let's ensure the global mock setup is complete and matches the actual implementation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for actual Kinde API method implementations to verify mock coverage
ast-grep --pattern 'export class $_ {
  $$$
  fetch($$$) {
    $$$
  }
  $$$
}'

# Search for any additional methods that might need mocking
rg -t typescript "kinde\." --no-filename

Length of output: 159


Script:

#!/bin/bash
# Search for TypeScript/JavaScript files that might contain Kinde API implementations
fd -e ts -e js

# Then search for Kinde-related code patterns in those files
fd -e ts -e js -x rg -l "kinde"

# Look for class definitions and method implementations
fd -e ts -e js -x rg -A 5 "class.*\{|function.*\{"

Length of output: 628


Script:

#!/bin/bash
# Let's examine the actual implementation in main.ts
cat lib/main.ts

# And check the types definition
cat lib/types.ts

Length of output: 10472

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between dd4b0cc and d0efa4f.

⛔ Files ignored due to path filters (1)
  • package.json is excluded by !**/*.json
📒 Files selected for processing (3)
  • lib/main.test.ts (3 hunks)
  • lib/main.ts (1 hunks)
  • lib/types.ts (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • lib/main.ts
  • lib/types.ts
🔇 Additional comments (2)
lib/main.test.ts (2)

8-8: LGTM: Import addition is appropriate

The WorkflowTrigger import is correctly added and properly used in the mock event definition.


101-108: Previous review comment is still applicable

The concerns about test description mismatch and limited test coverage raised in the previous review are still valid and should be addressed.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (2)
lib/main.ts (2)

12-50: LGTM! Consider adding JSDoc documentation.

The namespace structure is well-organized with clear separation of concerns. Each sub-namespace (env, idToken, accessToken, m2mToken, auth, risk) has well-defined functionality.

Consider adding JSDoc documentation for each namespace to describe its purpose and usage examples.


Line range hint 205-222: Improve fetch function robustness and error handling.

The current implementation has several potential issues:

  1. Unsafe type assertion
  2. Missing error handling
  3. Assumes JSON response availability

Consider this safer implementation:

- export async function fetch<T = any>(
+ export async function fetch<T>(
  url: string,
  options: KindeFetchOptions,
): Promise<T> {
  if (!kinde.fetch) {
    throw new Error("fetch binding not available");
  }

  if (!options.responseFormat) {
    options.responseFormat = "json";
  }

  const result = await kinde.fetch(url, options);
+ 
+ if (!result?.json) {
+   throw new Error('Invalid response format');
+ }
+ 
+ try {
+   return {
+     data: result.json as T,
+   };
+ } catch (error) {
+   throw new Error(`Failed to parse response: ${error.message}`);
+ }

- return {
-   data: result?.json,
- } as T;
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 6018b30 and 724deaf.

⛔ Files ignored due to path filters (2)
  • package.json is excluded by !**/*.json
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml, !**/*.yaml
📒 Files selected for processing (3)
  • eslint.config.js (1 hunks)
  • lib/main.ts (3 hunks)
  • lib/types.ts (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • eslint.config.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • lib/types.ts
🔇 Additional comments (1)
lib/main.ts (1)

314-322: LGTM! Consistent formatting improvements.

The formatting changes improve readability while maintaining functionality.

lib/main.ts Outdated Show resolved Hide resolved
@DanielRivers DanielRivers merged commit 3424cab into main Nov 19, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant