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

types: webhook event types #58

Closed
wants to merge 3 commits into from
Closed

Conversation

peterphanouvong
Copy link
Contributor

@peterphanouvong peterphanouvong commented Apr 3, 2024

Explain your changes

  • add webhook types
    Suppose there is a related issue with enough detail for a reviewer to understand your changes fully. In that case, you can omit an explanation and instead include either “Fixes #XX” or “Updates #XX” where “XX” is the issue number.

Checklist

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

Summary by CodeRabbit

  • New Features
    • Introduced new webhook events for enhanced integration capabilities, covering user actions, access requests, organization changes, permission modifications, role updates, and subscriber additions.

Copy link

coderabbitai bot commented Apr 3, 2024

Walkthrough

The recent update enriches the system with a diverse range of webhook event interfaces to manage various user actions, access requests, organization and permission updates, role changes, and subscriber additions. Additionally, a new type called WebhookSource has been introduced to classify the source of these events, enhancing event handling and integration.

Changes

File Path Change Summary
lib/sdk/utilities/types.ts Introduced multiple webhook event interfaces and incorporated WebhookSource type.

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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/coderabbit-overrides.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: 8

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 6cc94ab and 47df36f.
Files selected for processing (1)
  • lib/sdk/utilities/types.ts (1 hunks)
Additional Context Used
GitHub Check Runs (1)
main (18.x) failure (11)

lib/sdk/utilities/types.ts: [failure] 44-44:
Strings must use singlequote


lib/sdk/utilities/types.ts: [failure] 44-44:
Strings must use singlequote


lib/sdk/utilities/types.ts: [failure] 44-44:
Strings must use singlequote


lib/sdk/utilities/types.ts: [failure] 59-59:
Strings must use singlequote


lib/sdk/utilities/types.ts: [failure] 71-71:
Array type using 'T[]' is forbidden for non-simple types. Use 'Array' instead


lib/sdk/utilities/types.ts: [failure] 73-73:
Array type using 'T[]' is forbidden for non-simple types. Use 'Array' instead


lib/sdk/utilities/types.ts: [failure] 85-85:
Strings must use singlequote


lib/sdk/utilities/types.ts: [failure] 97-97:
Strings must use singlequote


lib/sdk/utilities/types.ts: [failure] 109-109:
Strings must use singlequote


lib/sdk/utilities/types.ts: [failure] 121-121:
Strings must use singlequote

lib/sdk/utilities/types.ts Outdated Show resolved Hide resolved
lib/sdk/utilities/types.ts Outdated Show resolved Hide resolved
lib/sdk/utilities/types.ts Outdated Show resolved Hide resolved
lib/sdk/utilities/types.ts Outdated Show resolved Hide resolved
lib/sdk/utilities/types.ts Outdated Show resolved Hide resolved
lib/sdk/utilities/types.ts Outdated Show resolved Hide resolved
Change quotes

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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: 3

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 47df36f and fc7ac45.
Files selected for processing (1)
  • lib/sdk/utilities/types.ts (1 hunks)
Additional Context Used
GitHub Check Runs (1)
main (18.x) failure (11)

lib/sdk/utilities/types.ts: [failure] 71-71:
Array type using 'T[]' is forbidden for non-simple types. Use 'Array' instead


lib/sdk/utilities/types.ts: [failure] 73-73:
Array type using 'T[]' is forbidden for non-simple types. Use 'Array' instead


lib/sdk/utilities/types.ts: [failure] 136-136:
Strings must use singlequote


lib/sdk/utilities/types.ts: [failure] 151-151:
Strings must use singlequote


lib/sdk/utilities/types.ts: [failure] 167-167:
Strings must use singlequote


lib/sdk/utilities/types.ts: [failure] 179-179:
Strings must use singlequote


lib/sdk/utilities/types.ts: [failure] 194-194:
Strings must use singlequote


lib/sdk/utilities/types.ts: [failure] 209-209:
Strings must use singlequote


lib/sdk/utilities/types.ts: [failure] 221-221:
Strings must use singlequote


lib/sdk/utilities/types.ts: [failure] 237-237:
Strings must use singlequote

lib/sdk/utilities/types.ts Show resolved Hide resolved
lib/sdk/utilities/types.ts Outdated Show resolved Hide resolved
lib/sdk/utilities/types.ts Outdated 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: 12

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between fc7ac45 and 2e4d23e.
Files selected for processing (1)
  • lib/sdk/utilities/types.ts (1 hunks)
Additional Context Used
GitHub Check Runs (1)
main (18.x) failure (3)

lib/sdk/utilities/types.ts: [failure] 90-90:
Declaration or statement expected.

lib/sdk/utilities/types.ts Outdated Show resolved Hide resolved
lib/sdk/utilities/types.ts Outdated Show resolved Hide resolved
lib/sdk/utilities/types.ts Outdated Show resolved Hide resolved
lib/sdk/utilities/types.ts Outdated Show resolved Hide resolved
lib/sdk/utilities/types.ts Outdated Show resolved Hide resolved
lib/sdk/utilities/types.ts Outdated Show resolved Hide resolved
lib/sdk/utilities/types.ts Outdated Show resolved Hide resolved
lib/sdk/utilities/types.ts Outdated Show resolved Hide resolved
lib/sdk/utilities/types.ts Outdated Show resolved Hide resolved
lib/sdk/utilities/types.ts Show resolved Hide resolved
chore: update array structure

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@DanielRivers DanielRivers force-pushed the peter/webhook-types branch from 2e4d23e to 12be199 Compare April 4, 2024 10:50
@DanielRivers
Copy link
Contributor

@coderabbitai review

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

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between fc7ac45 and 12be199.
Files selected for processing (1)
  • lib/sdk/utilities/types.ts (1 hunks)
Additional comments not posted (4)
lib/sdk/utilities/types.ts (4)

44-44: Consider documenting the WebhookSource type to provide clarity on the context in which each source value is used.


46-60: Ensure consistency in the use of nullable types across all interfaces. For example, email and phone fields in UserCreatedWebhookEvent are nullable, which is appropriate. Apply this consideration consistently across all user-related fields in other interfaces.


62-86: For the UserUpdatedWebhookEvent interface, consider adding documentation comments to explain the purpose of fields like is_password_reset_requested and is_suspended, as their implications on the user's state are significant.


124-137: In the AccessRequestCreatedWebhookEvent interface, ensure that the user_id field is consistently named across all event interfaces to maintain uniformity and avoid confusion.

@BrennenRocks
Copy link

BrennenRocks commented Jun 2, 2024

I would suggest doing something more along these lines. This way will have a "base" type that the rest can pull from. That way if the base type changes or more webhook events are added we can add it in just 1 place and the rest will fall into place. I also prefer to use type instead of interface because of declaration merging.

type WebhookEventDataMap = {
  'user.created': {
    user: {
      email: string | null;
      first_name: string;
      id: string;
      last_name: string;
      phone: string | null;
    };
  };
  'user.updated': {
    user: {
      email: string;
      first_name: string;
      id: string;
      is_password_reset_requested: boolean;
      is_suspended: boolean;
      last_name: string;
      organizations: Array<{
        roles: string[] | null;
        code: string;
        permissions: Array<{
          id: string;
          key: string;
        }> | null;
      }>;
      phone: string | null;
    };
  };
  'user.deleted': {
    user: {
      id: string;
    };
  };
  'user.authenticated': {
    user: {
      id: string;
    };
  };
  'user.authentication_failed': {
    user: {
      id: string;
    };
  };
  'access_request.created': {
    access_request: {
      email: string;
      first_name: string;
      last_name: string;
      user_id: string;
    };
  };
  'organization.created': {
    organization: {
      code: string;
      external_id: string | null;
      handle: string;
      name: string;
    };
  };
  'organization.updated': {
    organization: {
      code: string;
      external_id: string | null;
      handle: string;
      is_allow_registrations: boolean;
      name: string;
    };
  };
  'organization.deleted': {
    organization: {
      code: string;
    };
  };
  'permission.created': {
    permission: {
      description: string;
      id: string;
      key: string;
      name: string;
    };
  };
  'permission.updated': {
    permission: {
      description: string;
      id: string;
      key: string;
      name: string;
    };
  };
  'permission.deleted': {
    permission: {
      id: string;
    };
  };
  'role.created': {
    role: {
      description: string;
      id: string;
      is_default_role: boolean;
      key: string;
      name: string;
    };
  };
  'role.updated': {
    role: {
      description: string;
      id: string;
      is_default_role: boolean;
      key: string;
      name: string;
    };
  };
  'role.deleted': {
    role: {
      id: string;
    };
  };
  'subscriber.created': {
    subscriber: {
      email: string;
      first_name: string;
      id: string;
      last_name: string;
      user_id: string;
    };
  };
}

type WebhookEvent<TType extends keyof WebhookEventDataMap> = {
  data: WebhookEventDataMap[TType];
  event_id: string;
  source: WebhookSource;
  timestamp: string;
  type: TType;
}

export type UserCreatedWebhookEvent = WebhookEvent<'user.created'>;
export type UserUpdatedWebhookEvent = WebhookEvent<'user.updated'>;
...
export type RoleDeletedWebhookEvent = WebhookEvent<'role.deleted'>;
export type SubscriberCreatedWebhookEvent = WebhookEvent<'subscriber.created'>;

@DanielRivers
Copy link
Contributor

Hi, @BrennenRocks

Agree, the main reason this has not been merged as we have another solution in the works to handle webhooks. I hope to be able to share soon!

@DanielRivers
Copy link
Contributor

Hi @BrennenRocks ,

We have released the @kinde-oss/webhooks package which has types and handing.

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.

3 participants