zitadel / typescript

Typescript packages and application to showcase the ZITADEL resource API
https://typescript-login.vercel.app
MIT License
56 stars 27 forks source link

Export Generated Types #252

Open wodka opened 3 weeks ago

wodka commented 3 weeks ago

Preflight Checklist

Describe your problem

I would like to type function that use part of the api response. when ie importing Profile the compile will crash:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './dist/commonjs/api/generated/zitadel/user' is not defined by "exports"

Describe your ideal solution

export the generated types

    "./api/generated/*": {
      "import": "./dist/esm/api/generated/",
      "require": "./dist/commonjs/api/generated"
    },

Version

No response

Environment

Self-hosted

Additional Context

No response

livio-a commented 4 days ago

@peintnermax can you please have a look at this

peintnermax commented 4 days ago

@wodka can you describe a little better what you try to achieve? How are you importing the types right now?

wodka commented 4 days ago

@peintnermax I would like to consume the generated types from the package as part of my implementation.

// this is the path where the file resides, but cannot import it
// import { Profile } from '@zitadel/node/dist/commonjs/api/generated/zitadel/user'

// this would be a nice import path that decides itself between commonjs and esm
// import { Profile } from '@zitadel/node/api/generated/zitadel/user'

function somewhere() {
  const response = await this.zitadel.getForOrg(user.zitadelResourceOwner).getHumanProfile({ userId: user.zitadel });

  return new UserDto(user, response.profile!);
}

class UserDto {
  constructor(user: UserEntity, p: Profile) {
    // beeing able to use the typed data in here!
  }
}

currently I am adding a copy of the zitadel profile type in my own code base, but it would be great to be able to use it from the package

peintnermax commented 4 days ago

@peintnermax I would like to consume the generated types from the package as part of my implementation.

// this is the path where the file resides, but cannot import it // import { Profile } from '@zitadel/node/dist/commonjs/api/generated/zitadel/user'

// this would be a nice import path that decides itself between commonjs and esm // import { Profile } from '@zitadel/node/api/generated/zitadel/user'

function somewhere() { const response = await this.zitadel.getForOrg(user.zitadelResourceOwner).getHumanProfile({ userId: user.zitadel });

return new UserDto(user, response.profile!); }

class UserDto { constructor(user: UserEntity, p: Profile) { // beeing able to use the typed data in here! } } currently I am adding a copy of the zitadel profile type in my own code base, but it would be great to be able to use it from the package

Got it.. Types are exported by the package @zitadel/proto. Can you try if this fixes your issue?

import { User, UserState } from "@zitadel/proto/zitadel/user/v2/user_pb";