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/new password provided #38

Merged
merged 1 commit into from
Jan 16, 2025
Merged

Conversation

DanielRivers
Copy link
Contributor

@DanielRivers DanielRivers commented Jan 15, 2025

Explain your changes

Add new_password_provided

Checklist

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

Copy link

coderabbitai bot commented Jan 15, 2025

Walkthrough

The pull request introduces enhancements to the lib/types.ts file, focusing on password management and workflow event capabilities. New properties are added to the WorkflowSettings type, including "kinde.secureFetch" and "kinde.widget", which enable secure external API fetching and widget manipulation. A new workflow trigger NewPasswordProvided is introduced in the WorkflowTrigger enum, and a corresponding onNewPasswordProvided type is created to capture password change context.

Changes

File Change Summary
lib/types.ts - Added optional "kinde.secureFetch" property to WorkflowSettings
- Added optional "kinde.widget" property to WorkflowSettings
- Introduced NewPasswordProvided enum value in WorkflowTrigger
- Updated WorkflowEvents type with onNewPasswordProvided
- Created new onNewPasswordProvided type for password change events

Possibly related PRs

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/new_password_provided branch 2 times, most recently from d9ae7fe to 8104fa1 Compare January 15, 2025 22:44
@DanielRivers DanielRivers marked this pull request as ready for review January 16, 2025 10:22
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 (3)
lib/types.ts (2)

55-65: Consider defining explicit binding interfaces.

While the empty object type {} is used consistently throughout the file for bindings, it's generally recommended to define explicit interfaces for better type safety and documentation.

-    "kinde.secureFetch"?: {};
+    "kinde.secureFetch"?: {
+      readonly fetch: (url: string, options: KindeFetchOptions) => Promise<unknown>;
+    };

-    "kinde.widget"?: {};
+    "kinde.widget"?: {
+      readonly invalidateFormField: (fieldName: string, message: string) => void;
+    };
🧰 Tools
🪛 Biome (1.9.4)

[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)


151-165: Enhance password validation context.

The type properly captures password change scenarios, but consider:

  1. Adding validation rules as constants (e.g., minimum length, complexity)
  2. Including additional context like password policy version
  3. Adding JSDoc to document security requirements
 export type onNewPasswordProvided = EventBase & {
   context: {
     auth: {
       firstPassword: string;
       secondPassword: string;
       newPasswordReason: "reset" | "initial";
+      passwordPolicyVersion?: string; // Track which password rules were in effect
+      passwordValidationRules?: {
+        minLength: number;
+        requiresUppercase: boolean;
+        requiresNumbers: boolean;
+        requiresSpecialChars: boolean;
+      };
     };
     user: {
       id: string;
     };
     workflow: {
       trigger: WorkflowTrigger.NewPasswordProvided;
     };
   };
 };
lib/main.ts (1)

280-305: Reduce code duplication in fetch implementations.

The secureFetch function largely duplicates the logic from the regular fetch function. Consider extracting the common logic into a shared helper function.

+async function baseFetch<T>(
+  fetchFn: typeof kinde.fetch | typeof kinde.secureFetch,
+  url: string,
+  options: KindeFetchOptions
+): Promise<T> {
+  if (!options.responseFormat) {
+    options.responseFormat = "json";
+  }
+
+  const result = await fetchFn(url, options);
+
+  return {
+    data: result?.json,
+  } as T;
+}
+
 export async function fetch<T = any>(
   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);
-  return {
-    data: result?.json,
-  } as T;
+  return baseFetch(kinde.fetch, url, options);
 }

 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;
+  return baseFetch(kinde.secureFetch, url, 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 3d9f966 and 8104fa1.

📒 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] 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 (5)
lib/types.ts (3)

88-89: LGTM! New workflow triggers follow consistent naming patterns.

The new password-related triggers maintain the established naming convention and domain prefix pattern.


94-96: LGTM! Event types properly integrated.

The new password-related events are correctly added to the WorkflowEvents union type.


137-149: Review security implications of password handling.

The type includes plain text password data. While this might be necessary for validation, ensure that:

  1. The password is never logged or persisted
  2. The data is handled securely in memory
  3. The password field is cleared as soon as possible after validation

Consider adding JSDoc comments to document these security requirements.

lib/main.ts (2)

31-45: LGTM! Namespace declarations are consistent.

The new namespace declarations follow the established pattern and maintain type safety.


243-253: LGTM! Clean implementation of form field validation.

The function follows the established patterns for binding checks and error handling.

@DanielRivers DanielRivers force-pushed the feat/new_password_provided branch from 8104fa1 to df220ad Compare January 16, 2025 14:04
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

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

Line range hint 42-43: Fix typo in documentation comment.

The documentation comment for "kinde.widget" contains a grammatical error.

-     * Exposes the fetch method to call access the manipulate the Kinde widget
+     * Exposes methods to manipulate the Kinde widget
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8104fa1 and df220ad.

📒 Files selected for processing (1)
  • lib/types.ts (2 hunks)
🔇 Additional comments (2)
lib/types.ts (2)

89-89: LGTM!

The new workflow trigger follows the established naming pattern and is appropriately prefixed with "user:" for user-related events.


95-96: LGTM!

The WorkflowEvents type is correctly updated to include the new event type while maintaining consistency.

lib/types.ts Show resolved Hide resolved
@DanielRivers DanielRivers merged commit cb97223 into main Jan 16, 2025
5 checks 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.

2 participants