use turbo convention

This commit is contained in:
Elio Bischof
2025-07-17 13:20:50 +02:00
parent 028a657fd0
commit 706a966f22
381 changed files with 591 additions and 1260 deletions

View File

@@ -0,0 +1,8 @@
# Changesets
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)

View File

@@ -0,0 +1,10 @@
{
"$schema": "https://unpkg.com/@changesets/config@3.0.3/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch"
}

View File

@@ -0,0 +1,14 @@
module.exports = {
root: true,
extends: ["eslint:recommended", "@typescript-eslint/recommended"],
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
env: {
node: true,
es2022: true,
},
parserOptions: {
ecmaVersion: 2022,
sourceType: "module",
},
};

4
packages/zitadel-client/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
src/proto
node_modules
dist
.turbo

View File

@@ -0,0 +1,77 @@
# @zitadel/client
## 1.2.0
### Minor Changes
- 62ad388: revert CJS support
## 1.1.0
### Minor Changes
- 9692297: add CJS and ESM support
## 1.0.7
### Patch Changes
- Updated dependencies [97b0332]
- @zitadel/proto@1.0.4
## 1.0.6
### Patch Changes
- 90fbdd1: use node16/nodenext module resolution
- Updated dependencies [90fbdd1]
- @zitadel/proto@1.0.3
## 1.0.5
### Patch Changes
- 4fa22c0: fix export for grpcweb transport
## 1.0.4
### Patch Changes
- 28dc956: dynamic properties for system token utility
## 1.0.3
### Patch Changes
- ef1c801: add missing client transport utility
## 1.0.2
### Patch Changes
- Updated dependencies
- @zitadel/proto@1.0.2
## 1.0.1
### Patch Changes
- README updates
- Updated dependencies
- @zitadel/proto@1.0.1
## 1.0.0
### Major Changes
- 32e1199: Initial Release
### Minor Changes
- f32ab7f: Initial release
### Patch Changes
- Updated dependencies [f32ab7f]
- Updated dependencies [32e1199]
- @zitadel/proto@1.0.0

View File

@@ -0,0 +1,53 @@
# ZITADEL Client
This package exports services and utilities to interact with ZITADEL
## Installation
To install the package, use npm or yarn:
```sh
npm install @zitadel/client
```
or
```sh
yarn add @zitadel/client
```
## Usage
### Importing Services
You can import and use the services provided by this package to interact with ZITADEL.
```ts
import { createSettingsServiceClient, makeReqCtx } from "@zitadel/client/v2";
// Example usage
const transport = createServerTransport(process.env.ZITADEL_SERVICE_USER_TOKEN!, { baseUrl: process.env.ZITADEL_API_URL! });
const settingsService = createSettingsServiceClient(transport);
settingsService.getBrandingSettings({ ctx: makeReqCtx("orgId") }, {});
```
### Utilities
This package also provides various utilities to work with ZITADEL
```ts
import { timestampMs } from "@zitadel/client";
// Example usage
console.log(`${timestampMs(session.creationDate)}`);
```
## Documentation
For detailed documentation and API references, please visit the [ZITADEL documentation](https://zitadel.com/docs).
## Contributing
Contributions are welcome! Please read the contributing guidelines before getting started.

View File

@@ -0,0 +1,71 @@
{
"name": "@zitadel/client",
"version": "1.2.0",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"require": "./dist/index.cjs"
},
"./v1": {
"types": "./dist/v1.d.ts",
"import": "./dist/v1.js",
"require": "./dist/v1.cjs"
},
"./v2": {
"types": "./dist/v2.d.ts",
"import": "./dist/v2.js",
"require": "./dist/v2.cjs"
},
"./v3alpha": {
"types": "./dist/v3alpha.d.ts",
"import": "./dist/v3alpha.js",
"require": "./dist/v3alpha.cjs"
},
"./node": {
"types": "./dist/node.d.ts",
"import": "./dist/node.js",
"require": "./dist/node.cjs"
},
"./web": {
"types": "./dist/web.d.ts",
"import": "./dist/web.js",
"require": "./dist/web.cjs"
}
},
"files": [
"dist/**"
],
"sideEffects": false,
"scripts": {
"build": "pnpm exec tsup",
"build:client:standalone": "pnpm build",
"test": "pnpm test:unit",
"test:unit": "pnpm exec vitest --run",
"test:unit:standalone": "pnpm test:unit",
"lint": "eslint \"src/**/*.ts*\"",
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
},
"dependencies": {
"@bufbuild/protobuf": "^2.2.2",
"@connectrpc/connect": "^2.0.0",
"@connectrpc/connect-node": "^2.0.0",
"@connectrpc/connect-web": "^2.0.0",
"@zitadel/proto": "workspace:*",
"jose": "^5.3.0"
},
"devDependencies": {
"@bufbuild/buf": "^1.53.0",
"@bufbuild/protocompile": "^0.0.1",
"@typescript-eslint/eslint-plugin": "^8.15.0",
"@typescript-eslint/parser": "^8.15.0",
"eslint": "^8.57.0",
"tsup": "^8.4.0",
"vitest": "^2.0.0"
}
}

View File

@@ -0,0 +1,11 @@
import type { DescService } from "@bufbuild/protobuf";
import { Timestamp, timestampDate } from "@bufbuild/protobuf/wkt";
import { createClient, Transport } from "@connectrpc/connect";
export function createClientFor<TService extends DescService>(service: TService) {
return (transport: Transport) => createClient(service, transport);
}
export function toDate(timestamp: Timestamp | undefined): Date | undefined {
return timestamp ? timestampDate(timestamp) : undefined;
}

View File

@@ -0,0 +1,10 @@
export { createClientFor, toDate } from "./helpers.js";
export { NewAuthorizationBearerInterceptor } from "./interceptors.js";
// TODO: Move this to `./protobuf.ts` and export it from there
export { create, fromJson, toJson } from "@bufbuild/protobuf";
export type { JsonObject } from "@bufbuild/protobuf";
export type { GenService } from "@bufbuild/protobuf/codegenv1";
export { TimestampSchema, timestampDate, timestampFromDate, timestampFromMs, timestampMs } from "@bufbuild/protobuf/wkt";
export type { Duration, Timestamp } from "@bufbuild/protobuf/wkt";
export type { Client, Code, ConnectError } from "@connectrpc/connect";

View File

@@ -0,0 +1,67 @@
import { Int32Value } from "@bufbuild/protobuf/wkt";
import { compileService } from "@bufbuild/protocompile";
import { createRouterTransport, HandlerContext } from "@connectrpc/connect";
import { describe, expect, test, vitest } from "vitest";
import { NewAuthorizationBearerInterceptor } from "./interceptors.js";
const TestService = compileService(`
syntax = "proto3";
package handwritten;
service TestService {
rpc Unary(Int32Value) returns (StringValue);
}
message Int32Value {
int32 value = 1;
}
message StringValue {
string value = 1;
}
`);
describe("NewAuthorizationBearerInterceptor", () => {
const transport = {
interceptors: [NewAuthorizationBearerInterceptor("mytoken")],
};
test("injects the authorization token", async () => {
const handler = vitest.fn((request: Int32Value, context: HandlerContext) => {
return { value: request.value.toString() };
});
const service = createRouterTransport(
({ rpc }) => {
rpc(TestService.method.unary, handler);
},
{ transport },
);
await service.unary(TestService.method.unary, undefined, undefined, {}, { value: 9001 });
expect(handler).toBeCalled();
expect(handler.mock.calls[0][1].requestHeader.get("Authorization")).toBe("Bearer mytoken");
});
test("do not overwrite the previous authorization token", async () => {
const handler = vitest.fn((request: Int32Value, context: HandlerContext) => {
return { value: request.value.toString() };
});
const service = createRouterTransport(
({ rpc }) => {
rpc(TestService.method.unary, handler);
},
{ transport },
);
await service.unary(
TestService.method.unary,
undefined,
undefined,
{ Authorization: "Bearer somethingelse" },
{ value: 9001 },
);
expect(handler).toBeCalled();
expect(handler.mock.calls[0][1].requestHeader.get("Authorization")).toBe("Bearer somethingelse");
});
});

View File

@@ -0,0 +1,16 @@
import type { Interceptor } from "@connectrpc/connect";
/**
* Creates an interceptor that adds an Authorization header with a Bearer token.
* @param token
*/
export function NewAuthorizationBearerInterceptor(token: string): Interceptor {
return (next) => (req) => {
// TODO: I am not what is the intent of checking for the Authorization header
// and setting it if it is not present.
if (!req.header.get("Authorization")) {
req.header.set("Authorization", `Bearer ${token}`);
}
return next(req);
};
}

View File

@@ -0,0 +1,36 @@
import { createGrpcTransport, GrpcTransportOptions } from "@connectrpc/connect-node";
import { importPKCS8, SignJWT } from "jose";
import { NewAuthorizationBearerInterceptor } from "./interceptors.js";
/**
* Create a server transport using grpc with the given token and configuration options.
* @param token
* @param opts
*/
export function createServerTransport(token: string, opts: GrpcTransportOptions) {
return createGrpcTransport({
...opts,
interceptors: [...(opts.interceptors || []), NewAuthorizationBearerInterceptor(token)],
});
}
export async function newSystemToken({
audience,
subject,
key,
expirationTime,
}: {
audience: string;
subject: string;
key: string;
expirationTime?: number | string | Date;
}) {
return await new SignJWT({})
.setProtectedHeader({ alg: "RS256" })
.setIssuedAt()
.setExpirationTime(expirationTime ?? "1h")
.setIssuer(subject)
.setSubject(subject)
.setAudience(audience)
.sign(await importPKCS8(key, "RS256"));
}

View File

@@ -0,0 +1,11 @@
import { createClientFor } from "./helpers.js";
import { AdminService } from "@zitadel/proto/zitadel/admin_pb.js";
import { AuthService } from "@zitadel/proto/zitadel/auth_pb.js";
import { ManagementService } from "@zitadel/proto/zitadel/management_pb.js";
import { SystemService } from "@zitadel/proto/zitadel/system_pb.js";
export const createAdminServiceClient = createClientFor(AdminService);
export const createAuthServiceClient = createClientFor(AuthService);
export const createManagementServiceClient = createClientFor(ManagementService);
export const createSystemServiceClient = createClientFor(SystemService);

View File

@@ -0,0 +1,27 @@
import { create } from "@bufbuild/protobuf";
import { FeatureService } from "@zitadel/proto/zitadel/feature/v2/feature_service_pb.js";
import { IdentityProviderService } from "@zitadel/proto/zitadel/idp/v2/idp_service_pb.js";
import { RequestContextSchema } from "@zitadel/proto/zitadel/object/v2/object_pb.js";
import { OIDCService } from "@zitadel/proto/zitadel/oidc/v2/oidc_service_pb.js";
import { OrganizationService } from "@zitadel/proto/zitadel/org/v2/org_service_pb.js";
import { SAMLService } from "@zitadel/proto/zitadel/saml/v2/saml_service_pb.js";
import { SessionService } from "@zitadel/proto/zitadel/session/v2/session_service_pb.js";
import { SettingsService } from "@zitadel/proto/zitadel/settings/v2/settings_service_pb.js";
import { UserService } from "@zitadel/proto/zitadel/user/v2/user_service_pb.js";
import { createClientFor } from "./helpers.js";
export const createUserServiceClient = createClientFor(UserService);
export const createSettingsServiceClient = createClientFor(SettingsService);
export const createSessionServiceClient = createClientFor(SessionService);
export const createOIDCServiceClient = createClientFor(OIDCService);
export const createSAMLServiceClient = createClientFor(SAMLService);
export const createOrganizationServiceClient = createClientFor(OrganizationService);
export const createFeatureServiceClient = createClientFor(FeatureService);
export const createIdpServiceClient = createClientFor(IdentityProviderService);
export function makeReqCtx(orgId: string | undefined) {
return create(RequestContextSchema, {
resourceOwner: orgId ? { case: "orgId", value: orgId } : { case: "instance", value: true },
});
}

View File

@@ -0,0 +1,6 @@
import { ZITADELUsers } from "@zitadel/proto/zitadel/resources/user/v3alpha/user_service_pb.js";
import { ZITADELUserSchemas } from "@zitadel/proto/zitadel/resources/userschema/v3alpha/user_schema_service_pb.js";
import { createClientFor } from "./helpers.js";
export const createUserSchemaServiceClient = createClientFor(ZITADELUserSchemas);
export const createUserServiceClient = createClientFor(ZITADELUsers);

View File

@@ -0,0 +1,15 @@
import { GrpcTransportOptions } from "@connectrpc/connect-node";
import { createGrpcWebTransport } from "@connectrpc/connect-web";
import { NewAuthorizationBearerInterceptor } from "./interceptors.js";
/**
* Create a client transport using grpc web with the given token and configuration options.
* @param token
* @param opts
*/
export function createClientTransport(token: string, opts: GrpcTransportOptions) {
return createGrpcWebTransport({
...opts,
interceptors: [...(opts.interceptors || []), NewAuthorizationBearerInterceptor(token)],
});
}

View File

@@ -0,0 +1,23 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"composite": false,
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"inlineSources": false,
"isolatedModules": true,
"moduleResolution": "node16",
"noUnusedLocals": false,
"noUnusedParameters": false,
"preserveWatchOutput": true,
"skipLibCheck": true,
"strict": true,
"lib": ["es2023"],
"module": "node16",
"target": "es2022"
},
"include": ["./src/**/*"],
"exclude": ["dist", "build", "node_modules"]
}

View File

@@ -0,0 +1,13 @@
import { defineConfig, Options } from "tsup";
export default defineConfig((options: Options) => ({
entry: ["src/index.ts", "src/v1.ts", "src/v2.ts", "src/v3alpha.ts", "src/node.ts", "src/web.ts"],
format: ["esm", "cjs"],
treeshake: false,
splitting: true,
dts: true,
minify: false,
clean: true,
sourcemap: true,
...options,
}));

View File

@@ -0,0 +1,12 @@
{
"extends": ["//"],
"tasks": {
"build": {
"outputs": ["dist/**"],
"dependsOn": ["@zitadel/proto#generate"]
},
"build:client:standalone": {
"outputs": ["dist/**"]
}
}
}

5
packages/zitadel-proto/.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
zitadel
google
protoc-gen-openapiv2
validate
node_modules

View File

@@ -0,0 +1,47 @@
# @zitadel/proto
## 1.2.0
### Minor Changes
- 62ad388: revert CJS support
## 1.1.0
### Minor Changes
- 9692297: add CJS and ESM support
## 1.0.4
### Patch Changes
- 97b0332: bind @zitadel/proto version to zitadel tag
## 1.0.3
### Patch Changes
- 90fbdd1: use node16/nodenext module resolution
## 1.0.2
### Patch Changes
- include validate, google and protoc-gen-openapiv2
## 1.0.1
### Patch Changes
- README updates
## 1.0.0
### Major Changes
- 32e1199: Initial Release
### Minor Changes
- f32ab7f: Initial release

View File

@@ -0,0 +1,35 @@
# ZITADEL Proto
This package provides the Protocol Buffers (proto) definitions used by ZITADEL projects. It includes the proto files and generated code for interacting with ZITADEL's gRPC APIs.
## Installation
To install the package, use npm or yarn:
```sh
npm install @zitadel/proto
```
or
```sh
yarn add @zitadel/proto
```
## Usage
To use the proto definitions in your project, import the generated code:
```ts
import { Organization } from "@zitadel/proto/zitadel/org/v2/org_pb";
const org: Organization | null = await getDefaultOrg();
```
## Documentation
For detailed documentation and API references, please visit the [ZITADEL documentation](https://zitadel.com/docs).
## Contributing
Contributions are welcome! Please read the contributing guidelines before getting started.

View File

@@ -0,0 +1,10 @@
version: v2
managed:
enabled: true
plugins:
- remote: buf.build/bufbuild/es:v2.2.0
out: .
include_imports: true
opt:
- json_types=true
- import_extension=js

View File

@@ -0,0 +1,26 @@
{
"name": "@zitadel/proto",
"version": "1.2.0",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"type": "module",
"files": [
"zitadel/**",
"validate/**",
"google/**",
"protoc-gen-openapiv2/**"
],
"sideEffects": false,
"scripts": {
"generate": "pnpm exec buf generate ../../../proto --path ../../../proto/zitadel",
"clean": "rm -rf zitadel .turbo node_modules google protoc-gen-openapiv2 validate"
},
"dependencies": {
"@bufbuild/protobuf": "^2.2.2"
},
"devDependencies": {
"@bufbuild/buf": "^1.53.0"
}
}

View File

@@ -0,0 +1,8 @@
{
"extends": ["//"],
"tasks": {
"generate": {
"outputs": ["zitadel/**"]
}
}
}