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

feat: add support for onExistingPasswordProvided workflow event #35

Merged
merged 2 commits into from
Jan 16, 2025

Conversation

DanielRivers
Copy link
Contributor

Explain your changes

Add support for onExistingPasswordProvided which includes

kinde.secureFetch and kinde.widget support

Checklist

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

Copy link

coderabbitai bot commented Jan 15, 2025

Walkthrough

This pull request introduces new functionalities to the Kinde library by adding two key methods in lib/main.ts: secureFetch and invalidateFormField. The secureFetch method provides a secure way to fetch data from external APIs with error handling, while invalidateFormField allows invalidating form fields in Kinde widgets. Simultaneously, lib/types.ts is updated to support these new features by adding new optional bindings, an enum value for WorkflowTrigger, and a new event type onExistingPasswordProvided.

Changes

File Changes
lib/main.ts - Added secureFetch method with error handling for secure API calls
- Added invalidateFormField function to invalidate Kinde widget form fields
- Updated documentation for existing fetch function
lib/types.ts - Added optional bindings "kinde.secureFetch" and "kinde.widget"
- Added ExistingPasswordProvided enum value to WorkflowTrigger
- Introduced new onExistingPasswordProvided event type

Possibly related PRs

  • feat: add support for pages #20: The changes in lib/main.ts regarding the kinde namespace and the addition of new functions may relate to the modifications in the same file, particularly since both PRs involve enhancements to the API functionalities.
  • types: include page event #25: The updates to the lib/types.ts file in this PR, which include new properties in the WorkflowSettings type, are relevant as they complement the changes made in the main PR that also modifies lib/types.ts with new properties related to kinde.
  • feat: custom UI updates #28: This PR also modifies lib/main.ts, adding new functions and constants that may interact with the functionalities introduced in the main PR, particularly those related to the kinde namespace.

Suggested reviewers

  • DaveOrDead

Finishing Touches

  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@DanielRivers DanielRivers force-pushed the feat/existing_password_workflow branch from 02f2be6 to 30c5918 Compare January 15, 2025 20:35
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.

Caution

Inline review comments failed to post. This is likely due to GitHub's limits when posting large numbers of comments.

Actionable comments posted: 3

🛑 Comments failed to post (3)
lib/types.ts (1)

58-65: 🛠️ Refactor suggestion

Fix typos in documentation comments and define binding interfaces.

The documentation comments contain typos and the binding types should be explicitly defined:

  1. "extenal" should be "external" in the documentation
  2. Empty object types ({}) should be replaced with explicit interfaces
    /**
-     * Exposes the fetch method to call signed extenal APIs to the workflow
+     * Exposes the fetch method to call signed external APIs to the workflow
     */
-    "kinde.secureFetch"?: {},
+    "kinde.secureFetch"?: {
+      readonly signedRequests: boolean;
+    };
    /**
-     * Exposes the fetch method to call access the manipulate the Kinde widget
+     * Exposes methods to manipulate the Kinde widget
     */
-    "kinde.widget"?: {},
+    "kinde.widget"?: {
+      readonly formValidation: boolean;
+    };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

    /**
     * Exposes the fetch method to call signed external APIs to the workflow
     */
    "kinde.secureFetch"?: {
      readonly signedRequests: boolean;
    };
    /**
     * Exposes methods to manipulate the Kinde widget
     */
    "kinde.widget"?: {
      readonly formValidation: boolean;
    };
🧰 Tools
🪛 Biome (1.9.4)

[error] 61-61: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)


[error] 65-65: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)

🪛 GitHub Actions: Build and test

[warning] Code formatting issues detected. Run Prettier with --write to fix.

lib/main.ts (2)

276-301: ⚠️ Potential issue

Fix incorrect fetch method call.

There's a bug in the implementation: the function checks for kinde.secureFetch but uses kinde.fetch.

-  const result = await kinde.fetch(url, options);
+  const result = await kinde.secureFetch(url, options);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

/**
 * Fetch data from a secure external API
 * 
 * Encryption keys can be setup in the Kinde dashboard under workflows > encryption keys
 * @param url URL of the API
 * @param options Fetch options
 */
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export async function secureFetch<T = any>(
  url: string,
  options: KindeFetchOptions,
): Promise<T> {
  if (!kinde.secureFetch) {
    throw new Error("secureFetch binding not available");
  }

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

  const result = await kinde.secureFetch(url, options);

  return {
    data: result?.json,
  } as T;
}
🧰 Tools
🪛 GitHub Actions: Build and test

[warning] Code formatting issues detected. Run Prettier with --write to fix.


31-41: 🛠️ Refactor suggestion

Improve type safety in namespace declarations.

The function signatures use any type which is flagged by eslint. Consider using generic types for better type safety.

-  export function secureFetch(url: string, options: unknown): Promise<any>;
+  export function secureFetch<T = unknown>(url: string, options: KindeFetchOptions): Promise<T>;

  namespace widget {
-    export function invalidateFormField(fieldName: string, message: string): void;
+    export function invalidateFormField(fieldName: keyof HTMLFormControlsCollection, message: string): void;
  }

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 eslint

[error] 31-31: Unexpected any. Specify a different type.

(@typescript-eslint/no-explicit-any)

🪛 GitHub Actions: Build and test

[warning] Code formatting issues detected. Run Prettier with --write to fix.

@DanielRivers DanielRivers force-pushed the feat/existing_password_workflow branch from 30c5918 to 3e5c203 Compare January 15, 2025 20:37
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: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 02f2be6 and 3e5c203.

📒 Files selected for processing (2)
  • lib/main.ts (3 hunks)
  • lib/types.ts (3 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
lib/types.ts

[error] 61-61: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)


[error] 65-65: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)

🔇 Additional comments (5)
lib/types.ts (3)

88-88: LGTM!

The new enum value follows the established naming pattern and is self-documenting.


93-94: LGTM!

The WorkflowEvents union type is correctly updated to include the new event type.


135-147: Review security implications of password handling.

Storing passwords in the event context could pose security risks. Consider:

  1. Using a one-time token instead of the actual password
  2. Adding documentation about secure password handling
  3. Implementing automatic cleanup of sensitive data

Run this script to check for other instances of password handling:

lib/main.ts (2)

31-32: LGTM!

The secureFetch declaration follows the established pattern of the fetch method.


39-46: LGTM!

The widget namespace and invalidateFormField implementation follow the established patterns with proper error handling.

Also applies to: 243-253

lib/types.ts Outdated Show resolved Hide resolved
lib/main.ts Outdated Show resolved Hide resolved
lib/types.ts Show resolved Hide resolved
lib/types.ts Show resolved Hide resolved
lib/types.ts Show resolved Hide resolved
@DanielRivers DanielRivers mentioned this pull request Jan 15, 2025
2 tasks
@DanielRivers
Copy link
Contributor Author

@coderabbitai review

Copy link

coderabbitai bot commented Jan 16, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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

🧹 Nitpick comments (2)
lib/types.ts (1)

63-64: Fix typo in comment.

The comment has grammatical errors.

-     * Exposes the fetch method to call access the manipulate the Kinde widget
+     * Exposes methods to manipulate the Kinde widget
lib/main.ts (1)

280-305: Consider enhancing encryption key setup documentation.

The implementation looks good, but the documentation could be more helpful.

  /**
   * Fetch data from a secure external API
   *
-  * Encryption keys can be setup in the Kinde dashboard under workflows > encryption keys
+  * To use this feature:
+  * 1. Set up encryption keys in the Kinde dashboard: Workflows > Encryption Keys
+  * 2. Add the "kinde.secureFetch" binding to your workflow settings
   * @param url URL of the API
   * @param options Fetch options
   */
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3e5c203 and a907191.

📒 Files selected for processing (2)
  • lib/main.ts (3 hunks)
  • lib/types.ts (3 hunks)
🧰 Additional context used
📓 Learnings (1)
lib/types.ts (1)
Learnt from: DanielRivers
PR: kinde-oss/infrastructure#35
File: lib/types.ts:58-65
Timestamp: 2025-01-15T20:41:03.218Z
Learning: In the Kinde infrastructure, the `kinde.secureFetch` and `kinde.widget` bindings in `WorkflowSettings` are designed as simple feature flags using empty object types `{}`. They should not contain additional configuration properties.
🪛 Biome (1.9.4)
lib/types.ts

[error] 57-57: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)


[error] 61-61: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)


[error] 65-65: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)

🔇 Additional comments (7)
lib/types.ts (4)

55-55: LGTM!

Fixed typo in comment from "extenal" to "external".


88-88: LGTM!

The new enum value follows the existing naming pattern and is descriptive.


93-94: LGTM!

The new event type is correctly added to the union type, maintaining type safety.


135-147: Review security implications of password handling.

The event includes the password in its context. While this might be necessary for the workflow, ensure that:

  1. The password is not logged or persisted anywhere
  2. The password is transmitted securely
  3. The password is cleared from memory after use

Run this script to check for potential password logging:

✅ Verification successful

Type definition appears to be safely structured

The onExistingPasswordProvided type is only used in type definitions and follows the standard event structure pattern in the codebase. No actual implementation code was found that could potentially mishandle the password. The password field is properly scoped within the auth context of the event.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential password logging in the codebase
# Test: Search for logging of password or context. Expect: No instances of password being logged.

echo "Checking for direct password logging..."
rg -i "console\.(log|info|debug|warn|error).*password"

echo "Checking for context logging that might expose password..."
rg -i "console\.(log|info|debug|warn|error).*context"

Length of output: 328


Script:

#!/bin/bash
# Expand search for password handling patterns

echo "Checking for logging library imports..."
rg -i "import.*log|require.*log"

echo "Checking password-related function calls..."
ast-grep --pattern 'password'

echo "Checking for password cleanup patterns..."
rg -i "password.*=.*null|password.*=.*undefined"

echo "Checking for secure transmission patterns..."
rg -i "https|ssl|tls|secure|encrypt"

Length of output: 73926


Script:

#!/bin/bash
# Search for usage of the event type and password handling

echo "Checking for event type usage..."
rg -l "onExistingPasswordProvided"

echo "Checking for password-related functions..."
ast-grep --pattern 'function $FNAME($$$) { $$$ password $$$ }'

echo "Checking for event handlers..."
rg -A 5 "ExistingPasswordProvided"

Length of output: 1217

lib/main.ts (3)

31-32: LGTM!

The secureFetch declaration follows the same pattern as the existing fetch declaration.


39-46: LGTM!

The widget namespace declaration is well-structured and follows the existing pattern.


243-253: LGTM!

The implementation is well-documented and includes proper error handling.

@DanielRivers DanielRivers merged commit 94035c6 into main Jan 16, 2025
5 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Jan 16, 2025
2 tasks
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.

2 participants