mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-15 18:22:19 +00:00
feat(zitadel-proto): add CJS and ESM support; export in Zitadel api structure; add build configuration
This commit is contained in:
@@ -8,22 +8,87 @@ To install the package, use npm or yarn:
|
||||
|
||||
```sh
|
||||
npm install @zitadel/proto
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```sh
|
||||
# or
|
||||
yarn add @zitadel/proto
|
||||
# or
|
||||
pnpm add @zitadel/proto
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
To use the proto definitions in your project, import the generated code:
|
||||
This package supports both ESM and CommonJS imports. The API is organized into version-specific namespaces: `v1`, `v2`, and `v3alpha`.
|
||||
|
||||
```ts
|
||||
import { Organization } from "@zitadel/proto/zitadel/org/v2/org_pb";
|
||||
### ESM (ECMAScript Modules)
|
||||
|
||||
const org: Organization | null = await getDefaultOrg();
|
||||
```typescript
|
||||
// Import the entire package
|
||||
import * as zitadel from "@zitadel/proto";
|
||||
|
||||
// Use the version-specific namespaces
|
||||
const userRequest = new zitadel.v1.user.GetUserRequest();
|
||||
|
||||
// Or import specific versions
|
||||
import { v2 } from "@zitadel/proto";
|
||||
const userServiceRequest = new v2.user_service.GetUserRequest();
|
||||
```
|
||||
|
||||
### CommonJS
|
||||
|
||||
```typescript
|
||||
// Import the entire package
|
||||
const zitadel = require("@zitadel/proto");
|
||||
|
||||
// Use the version-specific namespaces
|
||||
const userRequest = new zitadel.v1.user.GetUserRequest();
|
||||
```
|
||||
|
||||
## API Structure
|
||||
|
||||
The package is organized into version-specific namespaces:
|
||||
|
||||
- `v1`: Contains the original ZITADEL API
|
||||
- `v2`: Contains the newer version of the API with improved organization
|
||||
- `v3alpha`: Contains the alpha version of the upcoming API
|
||||
|
||||
## Package Structure
|
||||
|
||||
The package is organized as follows:
|
||||
|
||||
- `index.ts`: Main entry point that exports the version-specific APIs
|
||||
- `v1.ts`: Exports all v1 API modules
|
||||
- `v2.ts`: Exports all v2 API modules
|
||||
- `v3alpha.ts`: Exports all v3alpha API modules
|
||||
- `zitadel/`: Contains the generated proto files
|
||||
|
||||
## Development
|
||||
|
||||
### Generating the proto files
|
||||
|
||||
The proto files are generated from the ZITADEL API definitions using [buf](https://buf.build/).
|
||||
|
||||
```sh
|
||||
pnpm generate
|
||||
```
|
||||
|
||||
### Building the package
|
||||
|
||||
```sh
|
||||
pnpm build
|
||||
```
|
||||
|
||||
### Testing
|
||||
|
||||
To test both ESM and CommonJS imports:
|
||||
|
||||
```sh
|
||||
pnpm test
|
||||
```
|
||||
|
||||
Or test them individually:
|
||||
|
||||
```bash
|
||||
pnpm test:cjs # Test CommonJS imports
|
||||
pnpm test:esm # Test ESM imports
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
Reference in New Issue
Block a user