clerk/javascript

UserJSON - two incompatible versions in Core 2 Beta

stx-chris opened this issue · 2 comments

@clerk/types/dist/JSON.d.ts - with deprecations (e.g. profile_image_url)
@clerk/backend/dist/api/resources/JSON.d.ts - used by WebhookEvent

are two incompatible versions of the type UserJSON. When imported as import { UserJSON } from @clerk/types, it raises a type error when used in a Webhook response.

CleanShot 2024-03-08 at 20 36 05@2x

Example (Webhook handler):

import { WebhookEvent } from "@clerk/nextjs/server";
import { UserJSON } from "@clerk/types";

export async function POST(request: NextRequest) {
  let event: WebhookEvent = ...;

  // Get the ID and type
  const { data, type } = event;

  try {
    switch (type) {
      case "user.created":
        await processEvent(data as UserJSON);  // <- casting does not work
        ...
   }
}

Originally posted by @stx-chris in #2900 (reply in thread)

This seems to extend to OrganizationJSON and others as well. For example, we have webhooks that use private_metadata on the organization, but the OrganizationJSON type exported does not include this private metadata, and the Organization in backend resources api has only the type exported, so the Organization.fromJSON(json) method that processes a JSON object that includes private_metadata is essentially a private method and cannot be accessed.

Hi!

We'll collect all Core 2 Beta feedback in the GitHub discussion so please continue your thread with my colleagues there: https://github.com/orgs/clerk/discussions/2900

Thanks!