mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-10 22:22:28 +00:00
fix: remove old zitadel client
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -14,7 +14,6 @@ server/dist
|
||||
public/dist
|
||||
.turbo
|
||||
packages/zitadel-server/src/app/proto
|
||||
packages/zitadel-client/src/app/proto
|
||||
.vscode
|
||||
.idea
|
||||
.vercel
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
.next/
|
||||
dist/
|
||||
packages/zitadel-proto/zitadel
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
"@tailwindcss/forms": "0.5.7",
|
||||
"@vercel/analytics": "^1.2.2",
|
||||
"@zitadel/proto": "workspace:*",
|
||||
"@zitadel/client2": "workspace:*",
|
||||
"@zitadel/client": "workspace:*",
|
||||
"@zitadel/react": "workspace:*",
|
||||
"@zitadel/node": "workspace:*",
|
||||
"clsx": "1.2.1",
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
IDPInformation,
|
||||
IDPLink,
|
||||
} from "@zitadel/proto/zitadel/user/v2beta/idp_pb";
|
||||
import { PartialMessage } from "@zitadel/client2";
|
||||
import { PartialMessage } from "@zitadel/client";
|
||||
|
||||
const PROVIDER_MAPPING: {
|
||||
[provider: string]: (
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
} from "@/lib/zitadel";
|
||||
import DynamicTheme from "@/ui/DynamicTheme";
|
||||
import { SignInWithIDP } from "@/ui/SignInWithIDP";
|
||||
import { makeReqCtx } from "@zitadel/client2/v2beta";
|
||||
import { makeReqCtx } from "@zitadel/client/v2beta";
|
||||
|
||||
function getIdentityProviders(orgId?: string) {
|
||||
return settingsService
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
import DynamicTheme from "@/ui/DynamicTheme";
|
||||
import { SignInWithIDP } from "@/ui/SignInWithIDP";
|
||||
import UsernameForm from "@/ui/UsernameForm";
|
||||
import { makeReqCtx } from "@zitadel/client2/v2beta";
|
||||
import { makeReqCtx } from "@zitadel/client/v2beta";
|
||||
|
||||
function getIdentityProviders(orgId?: string) {
|
||||
return settingsService
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
import { setSessionAndUpdateCookie } from "@/utils/session";
|
||||
import { NextRequest, NextResponse, userAgent } from "next/server";
|
||||
import { Checks } from "@zitadel/proto/zitadel/session/v2beta/session_service_pb";
|
||||
import { PlainMessage } from "@zitadel/client2";
|
||||
import { PlainMessage } from "@zitadel/client";
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
const body = await request.json();
|
||||
|
||||
@@ -2,7 +2,7 @@ import { getSession, verifyU2FRegistration } from "@/lib/zitadel";
|
||||
import { getSessionCookieById } from "@/utils/cookies";
|
||||
import { NextRequest, NextResponse, userAgent } from "next/server";
|
||||
import { VerifyU2FRegistrationRequest } from "@zitadel/proto/zitadel/user/v2beta/user_service_pb";
|
||||
import { PlainMessage } from "@zitadel/client2";
|
||||
import { PlainMessage } from "@zitadel/client";
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
const body = await request.json();
|
||||
|
||||
@@ -4,8 +4,8 @@ import {
|
||||
createSettingsServiceClient,
|
||||
createUserServiceClient,
|
||||
makeReqCtx,
|
||||
} from "@zitadel/client2/v2beta";
|
||||
import { createManagementServiceClient } from "@zitadel/client2/v1";
|
||||
} from "@zitadel/client/v2beta";
|
||||
import { createManagementServiceClient } from "@zitadel/client/v1";
|
||||
import { createServerTransport } from "@zitadel/node";
|
||||
import { Checks } from "@zitadel/proto/zitadel/session/v2beta/session_service_pb";
|
||||
import { RequestChallenges } from "@zitadel/proto/zitadel/session/v2beta/challenge_pb";
|
||||
@@ -16,7 +16,7 @@ import {
|
||||
import { CreateCallbackRequest } from "@zitadel/proto/zitadel/oidc/v2beta/oidc_service_pb";
|
||||
import { TextQueryMethod } from "@zitadel/proto/zitadel/object/v2beta/object_pb";
|
||||
import type { RedirectURLs } from "@zitadel/proto/zitadel/user/v2beta/idp_pb";
|
||||
import { PlainMessage } from "@zitadel/client2";
|
||||
import { PlainMessage } from "@zitadel/client";
|
||||
|
||||
const SESSION_LIFETIME_S = 3000;
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import { useForm } from "react-hook-form";
|
||||
import { TextInput } from "./Input";
|
||||
import BackButton from "./BackButton";
|
||||
import { Checks } from "@zitadel/proto/zitadel/session/v2beta/session_service_pb";
|
||||
import { PlainMessage } from "@zitadel/client2";
|
||||
import { PlainMessage } from "@zitadel/client";
|
||||
import { Challenges } from "@zitadel/proto/zitadel/session/v2beta/challenge_pb";
|
||||
|
||||
// either loginName or sessionId must be provided
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import { setTheme } from "@/utils/colors";
|
||||
import { useEffect } from "react";
|
||||
import { BrandingSettings } from "@zitadel/proto/zitadel/settings/v2beta/branding_settings_pb";
|
||||
import { PartialMessage } from "@zitadel/client2";
|
||||
import { PartialMessage } from "@zitadel/client";
|
||||
|
||||
type Props = {
|
||||
branding: PartialMessage<BrandingSettings> | undefined;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import tinycolor from "tinycolor2";
|
||||
import { BrandingSettings } from "@zitadel/proto/zitadel/settings/v2beta/branding_settings_pb";
|
||||
import { PartialMessage } from "@zitadel/client2";
|
||||
import { PartialMessage } from "@zitadel/client";
|
||||
|
||||
export interface Color {
|
||||
name: string;
|
||||
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
} from "@zitadel/proto/zitadel/session/v2beta/challenge_pb";
|
||||
import { Session } from "@zitadel/proto/zitadel/session/v2beta/session_pb";
|
||||
import { Checks } from "@zitadel/proto/zitadel/session/v2beta/session_service_pb";
|
||||
import { PlainMessage } from "@zitadel/client2";
|
||||
import { PlainMessage } from "@zitadel/client";
|
||||
|
||||
export async function createSessionAndUpdateCookie(
|
||||
loginName: string,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"extends": ["//"],
|
||||
"pipeline": {
|
||||
"tasks": {
|
||||
"build": {
|
||||
"outputs": ["dist/**", ".next/**", "!.next/cache/**"],
|
||||
"dependsOn": ["^build"]
|
||||
@@ -8,28 +8,28 @@
|
||||
"test": {
|
||||
"dependsOn": [
|
||||
"@zitadel/node#build",
|
||||
"@zitadel/client2#build",
|
||||
"@zitadel/client#build",
|
||||
"@zitadel/react#build"
|
||||
]
|
||||
},
|
||||
"test:integration": {
|
||||
"dependsOn": [
|
||||
"@zitadel/node#build",
|
||||
"@zitadel/client2#build",
|
||||
"@zitadel/client#build",
|
||||
"@zitadel/react#build"
|
||||
]
|
||||
},
|
||||
"test:unit": {
|
||||
"dependsOn": [
|
||||
"@zitadel/node#build",
|
||||
"@zitadel/client2#build",
|
||||
"@zitadel/client#build",
|
||||
"@zitadel/react#build"
|
||||
]
|
||||
},
|
||||
"test:watch": {
|
||||
"dependsOn": [
|
||||
"@zitadel/node#build",
|
||||
"@zitadel/client2#build",
|
||||
"@zitadel/client#build",
|
||||
"@zitadel/react#build"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
{
|
||||
"packageManager": "pnpm@9.1.2+sha256.19c17528f9ca20bd442e4ca42f00f1b9808a9cb419383cd04ba32ef19322aba7",
|
||||
"private": true,
|
||||
"name": "typescript-monorepo",
|
||||
"scripts": {
|
||||
"generate": "turbo run generate",
|
||||
"build": "turbo run build",
|
||||
@@ -29,7 +30,7 @@
|
||||
"eslint-config-zitadel": "workspace:*",
|
||||
"prettier": "^3.2.5",
|
||||
"tsup": "^8.0.2",
|
||||
"turbo": "^1.13.3",
|
||||
"turbo": "2.0.9",
|
||||
"typescript": "^5.4.5",
|
||||
"vite-tsconfig-paths": "^4.3.2",
|
||||
"vitest": "^1.6.0"
|
||||
|
||||
@@ -11,6 +11,6 @@
|
||||
"@typescript-eslint/parser": "^7.9.0",
|
||||
"eslint-config-prettier": "^9.1.0",
|
||||
"eslint-plugin-react": "^7.34.1",
|
||||
"eslint-config-turbo": "^1.13.3"
|
||||
"eslint-config-turbo": "^2.0.9"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
extends: ["zitadel"],
|
||||
};
|
||||
1
packages/zitadel-client/.gitignore
vendored
1
packages/zitadel-client/.gitignore
vendored
@@ -1 +0,0 @@
|
||||
src/proto
|
||||
@@ -1,14 +0,0 @@
|
||||
# buf.gen.yaml
|
||||
version: v1
|
||||
managed:
|
||||
enabled: true
|
||||
plugins:
|
||||
# - plugin: buf.build/protocolbuffers/js
|
||||
# out: src/app/proto/generated
|
||||
# opt: import_style=commonjs,binary
|
||||
- plugin: buf.build/grpc/web
|
||||
out: src/proto/client
|
||||
opt: import_style=typescript,mode=grpcweb
|
||||
# - plugin: buf.build/grpc-ecosystem/openapiv2
|
||||
# out: src/app/proto/generated
|
||||
# opt: allow_delete_body
|
||||
@@ -1,37 +1,55 @@
|
||||
{
|
||||
"name": "@zitadel/client",
|
||||
"version": "0.0.0",
|
||||
"main": "./dist/index.js",
|
||||
"module": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"sideEffects": false,
|
||||
"license": "MIT",
|
||||
"private": true,
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/index.js",
|
||||
"require": "./dist/index.cjs",
|
||||
"types": "./dist/index.d.ts"
|
||||
},
|
||||
"./v1": {
|
||||
"import": "./dist/v1.js",
|
||||
"require": "./dist/v1.cjs",
|
||||
"types": "./dist/v1.d.ts"
|
||||
},
|
||||
"./v2beta": {
|
||||
"import": "./dist/v2beta.js",
|
||||
"require": "./dist/v2beta.cjs",
|
||||
"types": "./dist/v2beta.d.ts"
|
||||
},
|
||||
"./v3alpha": {
|
||||
"import": "./dist/v3alpha.js",
|
||||
"require": "./dist/v3alpha.cjs",
|
||||
"types": "./dist/v3alpha.d.ts"
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"dist/**"
|
||||
],
|
||||
"sideEffects": false,
|
||||
"scripts": {
|
||||
"generate": "buf generate https://github.com/zitadel/zitadel.git --path ./proto/zitadel",
|
||||
"build": "tsup --dts",
|
||||
"build": "tsup",
|
||||
"test": "pnpm test:unit",
|
||||
"test:watch": "pnpm test:unit:watch",
|
||||
"test:unit": "vitest",
|
||||
"test:unit:watch": "vitest --watch",
|
||||
"dev": "tsup --watch --dts",
|
||||
"lint": "eslint \"src/**/*.ts*\"",
|
||||
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist && rm -rf src/proto"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@bufbuild/buf": "^1.14.0",
|
||||
"@zitadel/tsconfig": "workspace:*",
|
||||
"eslint-config-zitadel": "workspace:*",
|
||||
"ts-proto": "^1.139.0"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
|
||||
},
|
||||
"dependencies": {
|
||||
"jose": "^4.13.1",
|
||||
"nice-grpc-web": "^3.2.3",
|
||||
"protobufjs": "^7.2.3"
|
||||
"@zitadel/proto": "workspace:*",
|
||||
"@bufbuild/protobuf": "^1.10.0",
|
||||
"@connectrpc/connect": "^1.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@zitadel/tsconfig": "workspace:*",
|
||||
"eslint-config-zitadel": "workspace:*"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
/**
|
||||
* Return a slugified copy of a string.
|
||||
*
|
||||
* @param {CoreProps} str The ZITADEL client configuration
|
||||
* @return {Core} The client implementation.
|
||||
*/
|
||||
|
||||
let apps: ZitadelApp[] = [];
|
||||
|
||||
export interface ZitadelCoreProps {
|
||||
clientId: string;
|
||||
apiUrl: string; // process.env.ZITADEL_API_URL
|
||||
token: string;
|
||||
adminToken?: string;
|
||||
managementToken?: string;
|
||||
}
|
||||
|
||||
export interface ZitadelOptions extends ZitadelCoreProps {
|
||||
name?: string;
|
||||
}
|
||||
|
||||
export interface ZitadelApp {
|
||||
name: string | undefined;
|
||||
config: ZitadelCoreProps;
|
||||
}
|
||||
|
||||
export async function initializeApp(
|
||||
config: ZitadelCoreProps,
|
||||
name?: string,
|
||||
): Promise<ZitadelApp> {
|
||||
const app = { config, name };
|
||||
return app;
|
||||
}
|
||||
|
||||
export function getApps(): ZitadelApp[] {
|
||||
return apps;
|
||||
}
|
||||
|
||||
export function getApp(name?: string): ZitadelApp | undefined {
|
||||
return name
|
||||
? apps.find((a) => a.name === name)
|
||||
: apps.length === 1
|
||||
? apps[0]
|
||||
: undefined;
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
import { ZitadelApp } from "./app";
|
||||
import { authMiddleware } from "./middleware";
|
||||
|
||||
// const createClient = <Client>(
|
||||
// definition: CompatServiceDefinition,
|
||||
// accessToken: string
|
||||
// ) => {
|
||||
// const channel = createChannel(process.env.ZITADEL_API_URL ?? "");
|
||||
// return createClientFactory()
|
||||
// .use(authMiddleware(accessToken))
|
||||
// .create(definition, channel) as Client;
|
||||
// };
|
||||
|
||||
export async function getAuth(app?: ZitadelApp) {
|
||||
// return createClient<AuthServiceClient>(
|
||||
// AuthServiceDefinition as CompatServiceDefinition,
|
||||
// ""
|
||||
// );
|
||||
}
|
||||
@@ -1,5 +1,2 @@
|
||||
export { initializeApp, getApps } from "./app";
|
||||
|
||||
export { getAuth } from "./auth";
|
||||
|
||||
export type { ZitadelOptions } from "./app";
|
||||
export { NewAuthorizationBearerInterceptor } from "./interceptors";
|
||||
export type { PartialMessage, PlainMessage } from "@bufbuild/protobuf";
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
import { describe, expect, test, vitest } from "vitest";
|
||||
|
||||
import {
|
||||
CallOptions,
|
||||
ClientMiddlewareCall,
|
||||
Metadata,
|
||||
MethodDescriptor,
|
||||
} from "nice-grpc-web";
|
||||
import { authMiddleware } from "./middleware";
|
||||
|
||||
describe("authMiddleware", () => {
|
||||
const scenarios = [
|
||||
{
|
||||
name: "should add authorization if metadata is undefined",
|
||||
initialMetadata: undefined,
|
||||
expectedMetadata: new Metadata().set(
|
||||
"authorization",
|
||||
"Bearer mock-token",
|
||||
),
|
||||
token: "mock-token",
|
||||
},
|
||||
{
|
||||
name: "should add authorization if metadata exists but no authorization",
|
||||
initialMetadata: new Metadata().set("other-key", "other-value"),
|
||||
expectedMetadata: new Metadata()
|
||||
.set("other-key", "other-value")
|
||||
.set("authorization", "Bearer mock-token"),
|
||||
token: "mock-token",
|
||||
},
|
||||
{
|
||||
name: "should not modify authorization if it already exists",
|
||||
initialMetadata: new Metadata().set(
|
||||
"authorization",
|
||||
"Bearer initial-token",
|
||||
),
|
||||
expectedMetadata: new Metadata().set(
|
||||
"authorization",
|
||||
"Bearer initial-token",
|
||||
),
|
||||
token: "mock-token",
|
||||
},
|
||||
];
|
||||
|
||||
scenarios.forEach(({ name, initialMetadata, expectedMetadata, token }) => {
|
||||
test(name, async () => {
|
||||
const mockNext = vitest.fn().mockImplementation(async function* () {});
|
||||
const mockRequest = {};
|
||||
|
||||
const mockMethodDescriptor: MethodDescriptor = {
|
||||
options: { idempotencyLevel: undefined },
|
||||
path: "",
|
||||
requestStream: false,
|
||||
responseStream: false,
|
||||
};
|
||||
|
||||
const mockCall: ClientMiddlewareCall<unknown, unknown> = {
|
||||
method: mockMethodDescriptor,
|
||||
requestStream: false,
|
||||
responseStream: false,
|
||||
request: mockRequest,
|
||||
next: mockNext,
|
||||
};
|
||||
const options: CallOptions = {
|
||||
metadata: initialMetadata,
|
||||
};
|
||||
|
||||
await authMiddleware(token)(mockCall, options).next();
|
||||
|
||||
expect(mockNext).toHaveBeenCalledTimes(1);
|
||||
const actualMetadata = mockNext.mock.calls[0][1].metadata;
|
||||
expect(actualMetadata?.get("authorization")).toEqual(
|
||||
expectedMetadata.get("authorization"),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,14 +0,0 @@
|
||||
import { CallOptions, ClientMiddlewareCall, Metadata } from "nice-grpc-web";
|
||||
|
||||
export const authMiddleware = (token: string) =>
|
||||
async function* <Request, Response>(
|
||||
call: ClientMiddlewareCall<Request, Response>,
|
||||
options: CallOptions,
|
||||
) {
|
||||
if (!options.metadata?.has("authorization")) {
|
||||
options.metadata ??= new Metadata();
|
||||
options.metadata?.set("authorization", `Bearer ${token}`);
|
||||
}
|
||||
|
||||
return yield* call.next(call.request, options);
|
||||
};
|
||||
@@ -1,13 +1,13 @@
|
||||
import { defineConfig, Options } from "tsup";
|
||||
|
||||
export default defineConfig((options: Options) => ({
|
||||
treeshake: true,
|
||||
splitting: true,
|
||||
publicDir: true,
|
||||
entry: ["src/index.ts", "src/**/index.ts"],
|
||||
entry: ["src/index.ts", "src/v1.ts", "src/v2beta.ts", "src/v3alpha.ts"],
|
||||
format: ["esm", "cjs"],
|
||||
treeshake: false,
|
||||
splitting: true,
|
||||
dts: true,
|
||||
minify: true,
|
||||
minify: false,
|
||||
clean: true,
|
||||
sourcemap: true,
|
||||
...options,
|
||||
}));
|
||||
|
||||
@@ -2,20 +2,14 @@
|
||||
"extends": [
|
||||
"//"
|
||||
],
|
||||
"pipeline": {
|
||||
"generate": {
|
||||
"outputs": [
|
||||
"src/proto/**"
|
||||
],
|
||||
"cache": true
|
||||
},
|
||||
"tasks": {
|
||||
"build": {
|
||||
"outputs": [
|
||||
"dist/**"
|
||||
],
|
||||
"dependsOn": [
|
||||
"generate"
|
||||
"@zitadel/proto#generate"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
{
|
||||
"name": "@zitadel/client2",
|
||||
"version": "0.0.0",
|
||||
"license": "MIT",
|
||||
"private": true,
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"type": "module",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/index.js",
|
||||
"require": "./dist/index.cjs",
|
||||
"types": "./dist/index.d.ts"
|
||||
},
|
||||
"./v1": {
|
||||
"import": "./dist/v1.js",
|
||||
"require": "./dist/v1.cjs",
|
||||
"types": "./dist/v1.d.ts"
|
||||
},
|
||||
"./v2beta": {
|
||||
"import": "./dist/v2beta.js",
|
||||
"require": "./dist/v2beta.cjs",
|
||||
"types": "./dist/v2beta.d.ts"
|
||||
},
|
||||
"./v3alpha": {
|
||||
"import": "./dist/v3alpha.js",
|
||||
"require": "./dist/v3alpha.cjs",
|
||||
"types": "./dist/v3alpha.d.ts"
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"dist/**"
|
||||
],
|
||||
"sideEffects": false,
|
||||
"scripts": {
|
||||
"build": "tsup",
|
||||
"test": "pnpm test:unit",
|
||||
"test:watch": "pnpm test:unit:watch",
|
||||
"test:unit": "vitest",
|
||||
"test:unit:watch": "vitest --watch",
|
||||
"dev": "tsup --watch --dts",
|
||||
"lint": "eslint \"src/**/*.ts*\"",
|
||||
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
|
||||
},
|
||||
"dependencies": {
|
||||
"@zitadel/proto": "workspace:*",
|
||||
"@bufbuild/protobuf": "^1.9.0",
|
||||
"@connectrpc/connect": "^1.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@zitadel/tsconfig": "workspace:*",
|
||||
"eslint-config-zitadel": "workspace:*"
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
export { NewAuthorizationBearerInterceptor } from "./interceptors";
|
||||
export type { PartialMessage, PlainMessage } from "@bufbuild/protobuf";
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"extends": "@zitadel/tsconfig/tsup.json",
|
||||
"include": ["./src/**/*"],
|
||||
"exclude": ["dist", "build", "node_modules"]
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
import { defineConfig, Options } from "tsup";
|
||||
|
||||
export default defineConfig((options: Options) => ({
|
||||
entry: ["src/index.ts", "src/v1.ts", "src/v2beta.ts", "src/v3alpha.ts"],
|
||||
format: ["esm", "cjs"],
|
||||
treeshake: false,
|
||||
splitting: true,
|
||||
dts: true,
|
||||
minify: false,
|
||||
clean: true,
|
||||
sourcemap: true,
|
||||
...options,
|
||||
}));
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"extends": ["//"],
|
||||
"pipeline": {
|
||||
"build": {
|
||||
"outputs": ["dist/**"],
|
||||
"dependsOn": ["@zitadel/proto#generate"]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,20 @@
|
||||
{
|
||||
"extends": ["//"],
|
||||
"pipeline": {
|
||||
"extends": [
|
||||
"//"
|
||||
],
|
||||
"tasks": {
|
||||
"dev": {
|
||||
"dependsOn": ["@zitadel/react#build"]
|
||||
"dependsOn": [
|
||||
"@zitadel/react#build"
|
||||
]
|
||||
},
|
||||
"build": {
|
||||
"outputs": ["dist/**"],
|
||||
"dependsOn": ["@zitadel/react#build"]
|
||||
"outputs": [
|
||||
"dist/**"
|
||||
],
|
||||
"dependsOn": [
|
||||
"@zitadel/react#build"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist && rm -rf src/proto"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@zitadel/client2": "workspace:*"
|
||||
"@zitadel/client": "workspace:*"
|
||||
},
|
||||
"dependencies": {
|
||||
"@connectrpc/connect-node": "^1.4.0",
|
||||
@@ -37,7 +37,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.14.2",
|
||||
"@zitadel/client2": "workspace:*",
|
||||
"@zitadel/client": "workspace:*",
|
||||
"@zitadel/tsconfig": "workspace:*",
|
||||
"eslint-config-zitadel": "workspace:*"
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { NewAuthorizationBearerInterceptor } from "@zitadel/client2";
|
||||
import { NewAuthorizationBearerInterceptor } from "@zitadel/client";
|
||||
import {
|
||||
createGrpcTransport,
|
||||
GrpcTransportOptions,
|
||||
|
||||
@@ -2,10 +2,14 @@
|
||||
"extends": [
|
||||
"//"
|
||||
],
|
||||
"pipeline": {
|
||||
"tasks": {
|
||||
"build": {
|
||||
"outputs": ["dist/**"],
|
||||
"dependsOn": ["@zitadel/client2#build"]
|
||||
"outputs": [
|
||||
"dist/**"
|
||||
],
|
||||
"dependsOn": [
|
||||
"@zitadel/client#build"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
"clean": "rm -rf .turbo && rm -rf node_modules"
|
||||
},
|
||||
"dependencies": {
|
||||
"@bufbuild/protobuf": "^1.9.0"
|
||||
"@bufbuild/protobuf": "^1.10.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@bufbuild/buf": "^1.32.1"
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
"extends": [
|
||||
"//"
|
||||
],
|
||||
"pipeline": {
|
||||
"tasks": {
|
||||
"generate": {
|
||||
"outputs": ["zitadel/**"],
|
||||
"outputs": [
|
||||
"zitadel/**"
|
||||
],
|
||||
"cache": true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
{
|
||||
"extends": ["//"],
|
||||
"pipeline": {
|
||||
"extends": [
|
||||
"//"
|
||||
],
|
||||
"tasks": {
|
||||
"build": {
|
||||
"outputs": ["dist/**"]
|
||||
"outputs": [
|
||||
"dist/**"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
extends: ["zitadel"],
|
||||
};
|
||||
1
packages/zitadel-server/.gitignore
vendored
1
packages/zitadel-server/.gitignore
vendored
@@ -1 +0,0 @@
|
||||
src/proto
|
||||
@@ -1,18 +0,0 @@
|
||||
# buf.gen.yaml
|
||||
version: v1
|
||||
managed:
|
||||
enabled: true
|
||||
plugins:
|
||||
- name: ts
|
||||
strategy: all
|
||||
path: node_modules/ts-proto/protoc-gen-ts_proto
|
||||
out: src/proto/server
|
||||
opt:
|
||||
- esModuleInterop=true
|
||||
- env=node
|
||||
- outputServices=nice-grpc
|
||||
- outputServices=generic-definitions
|
||||
- useExactTypes=false
|
||||
# - plugin: buf.build/protocolbuffers/js
|
||||
# out: src/app/proto/generated
|
||||
# opt: import_style=commonjs,binary
|
||||
@@ -1,28 +0,0 @@
|
||||
import {
|
||||
ZitadelServerOptions,
|
||||
getServer,
|
||||
getServers,
|
||||
initializeServer,
|
||||
} from "#";
|
||||
import { GetMyUserResponse, getAuth } from "#/auth";
|
||||
|
||||
async function getMyUser(): Promise<GetMyUserResponse> {
|
||||
const auth = await getAuth();
|
||||
const response = await auth.getMyUser({});
|
||||
return response;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const zitadelConfig: ZitadelServerOptions = {
|
||||
apiUrl: "https://dev-mfhquc.zitadel.cloud/",
|
||||
token: "123",
|
||||
};
|
||||
|
||||
if (!getServers().length) {
|
||||
initializeServer(zitadelConfig);
|
||||
}
|
||||
|
||||
const app = getServer();
|
||||
}
|
||||
|
||||
main();
|
||||
@@ -1,40 +0,0 @@
|
||||
{
|
||||
"name": "@zitadel/server",
|
||||
"version": "0.0.0",
|
||||
"main": "./dist/index.js",
|
||||
"module": "./dist/index.mjs",
|
||||
"types": "./dist/index.d.ts",
|
||||
"type": "commonjs",
|
||||
"sideEffects": false,
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
"dist/**"
|
||||
],
|
||||
"scripts": {
|
||||
"generate": "buf generate https://github.com/zitadel/zitadel.git --path ./proto/zitadel",
|
||||
"build": "tsup --dts",
|
||||
"test": "pnpm test:unit",
|
||||
"test:watch": "pnpm test:unit:watch",
|
||||
"test:unit": "vitest",
|
||||
"test:unit:watch": "vitest --watch",
|
||||
"dev": "tsup --dts --watch",
|
||||
"lint": "eslint \"src/**/*.ts*\"",
|
||||
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist && rm -rf src/proto"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@bufbuild/buf": "^1.14.0",
|
||||
"@zitadel/tsconfig": "workspace:*",
|
||||
"eslint-config-zitadel": "workspace:*",
|
||||
"ts-proto": "^1.139.0"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"dependencies": {
|
||||
"jose": "^4.13.1",
|
||||
"long": "^5.2.1",
|
||||
"nice-grpc": "2.0.1",
|
||||
"nice-grpc-common": "^2.0.2",
|
||||
"protobufjs": "^7.2.3"
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
import { CompatServiceDefinition } from "nice-grpc/lib/service-definitions";
|
||||
|
||||
import { createChannel, createClientFactory } from "nice-grpc";
|
||||
import {
|
||||
AdminServiceClient,
|
||||
AdminServiceDefinition,
|
||||
} from "../proto/server/zitadel/admin";
|
||||
import { authMiddleware } from "../middleware";
|
||||
|
||||
const createClient = <Client>(
|
||||
definition: CompatServiceDefinition,
|
||||
accessToken: string,
|
||||
) => {
|
||||
const channel = createChannel(process.env.ZITADEL_API_URL ?? "");
|
||||
return createClientFactory()
|
||||
.use(authMiddleware(accessToken))
|
||||
.create(definition, channel) as Client;
|
||||
};
|
||||
|
||||
export const getAdmin = () =>
|
||||
createClient<AdminServiceClient>(
|
||||
AdminServiceDefinition as CompatServiceDefinition,
|
||||
process.env.ZITADEL_ADMIN_TOKEN ?? "",
|
||||
);
|
||||
@@ -1 +0,0 @@
|
||||
export * from "./admin";
|
||||
@@ -1,50 +0,0 @@
|
||||
import { CompatServiceDefinition } from "nice-grpc/lib/service-definitions";
|
||||
import { createChannel, createClientFactory } from "nice-grpc";
|
||||
import {
|
||||
AuthServiceClient,
|
||||
AuthServiceDefinition,
|
||||
GetMyUserResponse,
|
||||
} from "../proto/server/zitadel/auth";
|
||||
import { ZitadelServer, getServers } from "../server";
|
||||
import { authMiddleware } from "../middleware";
|
||||
|
||||
const createClient = <Client>(
|
||||
definition: CompatServiceDefinition,
|
||||
apiUrl: string,
|
||||
token: string,
|
||||
) => {
|
||||
if (!apiUrl) {
|
||||
throw Error("ZITADEL_API_URL not set");
|
||||
}
|
||||
|
||||
const channel = createChannel(process.env.ZITADEL_API_URL ?? "");
|
||||
return createClientFactory()
|
||||
.use(authMiddleware(token))
|
||||
.create(definition, channel) as Client;
|
||||
};
|
||||
|
||||
export const getAuth = (app?: string | ZitadelServer) => {
|
||||
let config;
|
||||
if (app && typeof app === "string") {
|
||||
const apps = getServers();
|
||||
config = apps.find((a) => a.name === app)?.config;
|
||||
} else if (app && typeof app === "object") {
|
||||
config = app.config;
|
||||
}
|
||||
|
||||
if (!config) {
|
||||
throw Error("No ZITADEL app found");
|
||||
}
|
||||
|
||||
return createClient<AuthServiceClient>(
|
||||
AuthServiceDefinition as CompatServiceDefinition,
|
||||
config.apiUrl,
|
||||
config.token,
|
||||
);
|
||||
};
|
||||
|
||||
export async function getMyUser(): Promise<GetMyUserResponse> {
|
||||
const auth = await getAuth();
|
||||
const response = await auth.getMyUser({});
|
||||
return response;
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
export * from "./auth";
|
||||
export * as auth from "../proto/server/zitadel/auth";
|
||||
@@ -1,142 +0,0 @@
|
||||
import * as settings from "./v2/settings";
|
||||
import * as session from "./v2/session";
|
||||
import * as user from "./v2/user";
|
||||
import * as oidc from "./v2/oidc";
|
||||
import * as management from "./management";
|
||||
import * as auth from "./auth";
|
||||
|
||||
import * as login from "./proto/server/zitadel/settings/v2beta/login_settings";
|
||||
import * as password from "./proto/server/zitadel/settings/v2beta/password_settings";
|
||||
import * as legal from "./proto/server/zitadel/settings/v2beta/legal_settings";
|
||||
|
||||
export {
|
||||
BrandingSettings,
|
||||
Theme,
|
||||
} from "./proto/server/zitadel/settings/v2beta/branding_settings";
|
||||
|
||||
export {
|
||||
LoginSettings,
|
||||
IdentityProvider,
|
||||
IdentityProviderType,
|
||||
} from "./proto/server/zitadel/settings/v2beta/login_settings";
|
||||
|
||||
export {
|
||||
RequestChallenges,
|
||||
Challenges,
|
||||
Challenges_WebAuthN,
|
||||
} from "./proto/server/zitadel/session/v2beta/challenge";
|
||||
|
||||
export {
|
||||
GetAuthRequestRequest,
|
||||
GetAuthRequestResponse,
|
||||
CreateCallbackRequest,
|
||||
CreateCallbackResponse,
|
||||
} from "./proto/server/zitadel/oidc/v2beta/oidc_service";
|
||||
|
||||
export {
|
||||
AuthRequest,
|
||||
Prompt,
|
||||
} from "./proto/server/zitadel/oidc/v2beta/authorization";
|
||||
|
||||
export {
|
||||
Session,
|
||||
Factors,
|
||||
} from "./proto/server/zitadel/session/v2beta/session";
|
||||
export {
|
||||
IDPInformation,
|
||||
IDPLink,
|
||||
} from "./proto/server/zitadel/user/v2beta/idp";
|
||||
export {
|
||||
ListSessionsResponse,
|
||||
GetSessionResponse,
|
||||
CreateSessionResponse,
|
||||
SetSessionResponse,
|
||||
SetSessionRequest,
|
||||
Checks,
|
||||
DeleteSessionResponse,
|
||||
} from "./proto/server/zitadel/session/v2beta/session_service";
|
||||
export {
|
||||
GetPasswordComplexitySettingsResponse,
|
||||
GetBrandingSettingsResponse,
|
||||
GetLegalAndSupportSettingsResponse,
|
||||
GetGeneralSettingsResponse,
|
||||
GetLoginSettingsResponse,
|
||||
GetLoginSettingsRequest,
|
||||
GetActiveIdentityProvidersResponse,
|
||||
GetActiveIdentityProvidersRequest,
|
||||
} from "./proto/server/zitadel/settings/v2beta/settings_service";
|
||||
export { TextQueryMethod } from "./proto/server/zitadel/object/v2beta/object";
|
||||
export {
|
||||
AddHumanUserResponse,
|
||||
AddHumanUserRequest,
|
||||
GetUserByIDResponse,
|
||||
VerifyEmailResponse,
|
||||
VerifyPasskeyRegistrationRequest,
|
||||
VerifyPasskeyRegistrationResponse,
|
||||
RegisterPasskeyRequest,
|
||||
RegisterPasskeyResponse,
|
||||
CreatePasskeyRegistrationLinkResponse,
|
||||
CreatePasskeyRegistrationLinkRequest,
|
||||
ListAuthenticationMethodTypesResponse,
|
||||
ListAuthenticationMethodTypesRequest,
|
||||
AuthenticationMethodType,
|
||||
StartIdentityProviderIntentRequest,
|
||||
StartIdentityProviderIntentResponse,
|
||||
RetrieveIdentityProviderIntentRequest,
|
||||
RetrieveIdentityProviderIntentResponse,
|
||||
ListUsersRequest,
|
||||
ListUsersResponse,
|
||||
AddOTPEmailResponse,
|
||||
AddOTPEmailRequest,
|
||||
AddOTPSMSResponse,
|
||||
AddOTPSMSRequest,
|
||||
RegisterTOTPRequest,
|
||||
RegisterTOTPResponse,
|
||||
VerifyTOTPRegistrationRequest,
|
||||
VerifyTOTPRegistrationResponse,
|
||||
VerifyU2FRegistrationRequest,
|
||||
VerifyU2FRegistrationResponse,
|
||||
RegisterU2FResponse,
|
||||
RegisterU2FRequest,
|
||||
} from "./proto/server/zitadel/user/v2beta/user_service";
|
||||
|
||||
export { AuthFactor } from "./proto/server/zitadel/user";
|
||||
|
||||
export {
|
||||
SetHumanPasswordResponse,
|
||||
SetHumanPasswordRequest,
|
||||
GetOrgByDomainGlobalResponse,
|
||||
ListHumanAuthFactorsResponse,
|
||||
} from "./proto/server/zitadel/management";
|
||||
|
||||
export * from "./proto/server/zitadel/idp";
|
||||
export { type LegalAndSupportSettings } from "./proto/server/zitadel/settings/v2beta/legal_settings";
|
||||
export { type PasswordComplexitySettings } from "./proto/server/zitadel/settings/v2beta/password_settings";
|
||||
export { type ResourceOwnerType } from "./proto/server/zitadel/settings/v2beta/settings";
|
||||
export {
|
||||
type VerifyMyAuthFactorOTPResponse,
|
||||
AddMyAuthFactorOTPResponse,
|
||||
} from "./proto/server/zitadel/auth";
|
||||
import {
|
||||
getServers,
|
||||
initializeServer,
|
||||
ZitadelServer,
|
||||
ZitadelServerOptions,
|
||||
} from "./server";
|
||||
export * from "./middleware";
|
||||
|
||||
export {
|
||||
getServers,
|
||||
ZitadelServer,
|
||||
type ZitadelServerOptions,
|
||||
initializeServer,
|
||||
user,
|
||||
management,
|
||||
session,
|
||||
settings,
|
||||
login,
|
||||
password,
|
||||
legal,
|
||||
oidc,
|
||||
auth,
|
||||
};
|
||||
@@ -1,3 +0,0 @@
|
||||
import { ZitadelServer } from "./server";
|
||||
|
||||
export const _servers = new Map<string, ZitadelServer>();
|
||||
@@ -1,3 +0,0 @@
|
||||
export * from "./management";
|
||||
export * as management from "../proto/server/zitadel/management";
|
||||
export * as policy from "../proto/server/zitadel/policy";
|
||||
@@ -1,45 +0,0 @@
|
||||
import { CompatServiceDefinition } from "nice-grpc/lib/service-definitions";
|
||||
|
||||
import { createChannel, createClientFactory } from "nice-grpc";
|
||||
import {
|
||||
ManagementServiceClient,
|
||||
ManagementServiceDefinition,
|
||||
} from "../proto/server/zitadel/management";
|
||||
|
||||
import { authMiddleware } from "../middleware";
|
||||
import { ZitadelServer, getServers } from "../server";
|
||||
|
||||
const createClient = <Client>(
|
||||
definition: CompatServiceDefinition,
|
||||
apiUrl: string,
|
||||
token: string,
|
||||
) => {
|
||||
if (!apiUrl) {
|
||||
throw Error("ZITADEL_API_URL not set");
|
||||
}
|
||||
|
||||
const channel = createChannel(process.env.ZITADEL_API_URL ?? "");
|
||||
return createClientFactory()
|
||||
.use(authMiddleware(token))
|
||||
.create(definition, channel) as Client;
|
||||
};
|
||||
|
||||
export const getManagement = (app?: string | ZitadelServer) => {
|
||||
let config;
|
||||
if (app && typeof app === "string") {
|
||||
const apps = getServers();
|
||||
config = apps.find((a) => a.name === app)?.config;
|
||||
} else if (app && typeof app === "object") {
|
||||
config = app.config;
|
||||
}
|
||||
|
||||
if (!config) {
|
||||
throw Error("No ZITADEL app found");
|
||||
}
|
||||
|
||||
return createClient<ManagementServiceClient>(
|
||||
ManagementServiceDefinition as CompatServiceDefinition,
|
||||
config.apiUrl,
|
||||
config.token,
|
||||
);
|
||||
};
|
||||
@@ -1,76 +0,0 @@
|
||||
import { describe, expect, test, vitest } from "vitest";
|
||||
|
||||
import {
|
||||
CallOptions,
|
||||
ClientMiddlewareCall,
|
||||
Metadata,
|
||||
MethodDescriptor,
|
||||
} from "nice-grpc";
|
||||
import { authMiddleware } from "./middleware";
|
||||
|
||||
describe("authMiddleware", () => {
|
||||
const scenarios = [
|
||||
{
|
||||
name: "should add authorization if metadata is undefined",
|
||||
initialMetadata: undefined,
|
||||
expectedMetadata: new Metadata().set(
|
||||
"authorization",
|
||||
"Bearer mock-token",
|
||||
),
|
||||
token: "mock-token",
|
||||
},
|
||||
{
|
||||
name: "should add authorization if metadata exists but no authorization",
|
||||
initialMetadata: new Metadata().set("other-key", "other-value"),
|
||||
expectedMetadata: new Metadata()
|
||||
.set("other-key", "other-value")
|
||||
.set("authorization", "Bearer mock-token"),
|
||||
token: "mock-token",
|
||||
},
|
||||
{
|
||||
name: "should not modify authorization if it already exists",
|
||||
initialMetadata: new Metadata().set(
|
||||
"authorization",
|
||||
"Bearer initial-token",
|
||||
),
|
||||
expectedMetadata: new Metadata().set(
|
||||
"authorization",
|
||||
"Bearer initial-token",
|
||||
),
|
||||
token: "mock-token",
|
||||
},
|
||||
];
|
||||
|
||||
scenarios.forEach(({ name, initialMetadata, expectedMetadata, token }) => {
|
||||
test(name, async () => {
|
||||
const mockNext = vitest.fn().mockImplementation(async function* () {});
|
||||
const mockRequest = {};
|
||||
|
||||
const mockMethodDescriptor: MethodDescriptor = {
|
||||
options: { idempotencyLevel: undefined },
|
||||
path: "",
|
||||
requestStream: false,
|
||||
responseStream: false,
|
||||
};
|
||||
|
||||
const mockCall: ClientMiddlewareCall<unknown, unknown> = {
|
||||
method: mockMethodDescriptor,
|
||||
requestStream: false,
|
||||
responseStream: false,
|
||||
request: mockRequest,
|
||||
next: mockNext,
|
||||
};
|
||||
const options: CallOptions = {
|
||||
metadata: initialMetadata,
|
||||
};
|
||||
|
||||
await authMiddleware(token)(mockCall, options).next();
|
||||
|
||||
expect(mockNext).toHaveBeenCalledTimes(1);
|
||||
const actualMetadata = mockNext.mock.calls[0][1].metadata;
|
||||
expect(actualMetadata?.get("authorization")).toEqual(
|
||||
expectedMetadata.get("authorization"),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,23 +0,0 @@
|
||||
import {
|
||||
CallOptions,
|
||||
ClientMiddleware,
|
||||
ClientMiddlewareCall,
|
||||
Metadata,
|
||||
} from "nice-grpc";
|
||||
|
||||
export function authMiddleware(token: string): ClientMiddleware {
|
||||
return async function* <Request, Response>(
|
||||
call: ClientMiddlewareCall<Request, Response>,
|
||||
options: CallOptions,
|
||||
) {
|
||||
if (!options.metadata?.has("authorization")) {
|
||||
options.metadata ??= new Metadata();
|
||||
options.metadata?.set("authorization", `Bearer ${token}`);
|
||||
}
|
||||
|
||||
return yield* call.next(call.request, options);
|
||||
};
|
||||
}
|
||||
|
||||
export const orgMetadata = (orgId: string) =>
|
||||
new Metadata({ "x-zitadel-orgid": orgId });
|
||||
@@ -1,70 +0,0 @@
|
||||
import { createChannel, createClientFactory } from "nice-grpc";
|
||||
import { authMiddleware } from "./middleware";
|
||||
import { CompatServiceDefinition } from "nice-grpc/lib/service-definitions";
|
||||
|
||||
let apps: ZitadelServer[] = [];
|
||||
|
||||
export interface ZitadelServerProps {
|
||||
apiUrl: string; // process.env.ZITADEL_API_URL
|
||||
token: string;
|
||||
}
|
||||
|
||||
export interface ZitadelServerOptions extends ZitadelServerProps {
|
||||
name?: string;
|
||||
}
|
||||
|
||||
export function initializeServer(
|
||||
config: ZitadelServerProps,
|
||||
name?: string,
|
||||
): ZitadelServer {
|
||||
const server = new ZitadelServer(config, name);
|
||||
return server;
|
||||
}
|
||||
|
||||
export class ZitadelServer {
|
||||
name: string | undefined;
|
||||
config: ZitadelServerProps;
|
||||
|
||||
constructor(config: ZitadelServerProps, name?: string) {
|
||||
if (name) {
|
||||
this.name = name;
|
||||
}
|
||||
this.config = config;
|
||||
}
|
||||
}
|
||||
|
||||
export function getServers(): ZitadelServer[] {
|
||||
return apps;
|
||||
}
|
||||
|
||||
export function getServer(name?: string): ZitadelServer {
|
||||
if (name) {
|
||||
const found = apps.find((a) => a.name === name);
|
||||
if (found) {
|
||||
return found;
|
||||
} else {
|
||||
throw new Error("No server found");
|
||||
}
|
||||
} else {
|
||||
if (apps.length) {
|
||||
return apps[0];
|
||||
} else {
|
||||
throw new Error("No server found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const createClient = <Client>(
|
||||
definition: CompatServiceDefinition,
|
||||
apiUrl: string,
|
||||
token: string,
|
||||
) => {
|
||||
if (!apiUrl) {
|
||||
throw Error("ZITADEL_API_URL not set");
|
||||
}
|
||||
|
||||
const channel = createChannel(process.env.ZITADEL_API_URL ?? "");
|
||||
return createClientFactory()
|
||||
.use(authMiddleware(token))
|
||||
.create(definition, channel) as Client;
|
||||
};
|
||||
@@ -1 +0,0 @@
|
||||
export * from "./system";
|
||||
@@ -1,35 +0,0 @@
|
||||
import { CompatServiceDefinition } from "nice-grpc/lib/service-definitions";
|
||||
import { importPKCS8, SignJWT } from "jose";
|
||||
|
||||
import { createChannel, createClientFactory } from "nice-grpc";
|
||||
import {
|
||||
SystemServiceClient,
|
||||
SystemServiceDefinition,
|
||||
} from "../proto/server/zitadel/system";
|
||||
import { authMiddleware } from "../middleware";
|
||||
|
||||
const createSystemClient = <Client>(
|
||||
definition: CompatServiceDefinition,
|
||||
accessToken: string,
|
||||
) => {
|
||||
const channel = createChannel(process.env.ZITADEL_SYSTEM_API_URL ?? "");
|
||||
return createClientFactory()
|
||||
.use(authMiddleware(accessToken))
|
||||
.create(definition, channel) as Client;
|
||||
};
|
||||
|
||||
export const getSystem = async () => {
|
||||
const token = await new SignJWT({})
|
||||
.setProtectedHeader({ alg: "RS256" })
|
||||
.setIssuedAt()
|
||||
.setExpirationTime("1h")
|
||||
.setIssuer(process.env.ZITADEL_SYSTEM_API_USERID ?? "")
|
||||
.setSubject(process.env.ZITADEL_SYSTEM_API_USERID ?? "")
|
||||
.setAudience(process.env.ZITADEL_ISSUER ?? "")
|
||||
.sign(await importPKCS8(process.env.ZITADEL_SYSTEM_API_KEY ?? "", "RS256"));
|
||||
|
||||
return createSystemClient<SystemServiceClient>(
|
||||
SystemServiceDefinition as CompatServiceDefinition,
|
||||
token,
|
||||
);
|
||||
};
|
||||
@@ -1,2 +0,0 @@
|
||||
export * from "./oidc";
|
||||
export * from "../../proto/server/zitadel/oidc/v2beta/oidc_service";
|
||||
@@ -1,24 +0,0 @@
|
||||
import { CompatServiceDefinition } from "nice-grpc/lib/service-definitions";
|
||||
|
||||
import { ZitadelServer, createClient, getServers } from "../../server";
|
||||
import { OIDCServiceClient, OIDCServiceDefinition } from ".";
|
||||
|
||||
export const getOidc = (server?: string | ZitadelServer) => {
|
||||
let config;
|
||||
if (server && typeof server === "string") {
|
||||
const apps = getServers();
|
||||
config = apps.find((a) => a.name === server)?.config;
|
||||
} else if (server && typeof server === "object") {
|
||||
config = server.config;
|
||||
}
|
||||
|
||||
if (!config) {
|
||||
throw Error("No ZITADEL server found");
|
||||
}
|
||||
|
||||
return createClient<OIDCServiceClient>(
|
||||
OIDCServiceDefinition as CompatServiceDefinition,
|
||||
config.apiUrl,
|
||||
config.token,
|
||||
);
|
||||
};
|
||||
@@ -1,2 +0,0 @@
|
||||
export * from "./session";
|
||||
export * from "../../proto/server/zitadel/session/v2beta/session";
|
||||
@@ -1,28 +0,0 @@
|
||||
import { CompatServiceDefinition } from "nice-grpc/lib/service-definitions";
|
||||
|
||||
import {
|
||||
SessionServiceClient,
|
||||
SessionServiceDefinition,
|
||||
} from "../../proto/server/zitadel/session/v2beta/session_service";
|
||||
|
||||
import { ZitadelServer, createClient, getServers } from "../../server";
|
||||
|
||||
export const getSession = (server?: string | ZitadelServer) => {
|
||||
let config;
|
||||
if (server && typeof server === "string") {
|
||||
const apps = getServers();
|
||||
config = apps.find((a) => a.name === server)?.config;
|
||||
} else if (server && typeof server === "object") {
|
||||
config = server.config;
|
||||
}
|
||||
|
||||
if (!config) {
|
||||
throw Error("No ZITADEL server found");
|
||||
}
|
||||
|
||||
return createClient<SessionServiceClient>(
|
||||
SessionServiceDefinition as CompatServiceDefinition,
|
||||
config.apiUrl,
|
||||
config.token,
|
||||
);
|
||||
};
|
||||
@@ -1,2 +0,0 @@
|
||||
export * from "./settings";
|
||||
export * from "../../proto/server/zitadel/settings/v2beta/settings";
|
||||
@@ -1,28 +0,0 @@
|
||||
import { CompatServiceDefinition } from "nice-grpc/lib/service-definitions";
|
||||
|
||||
import {
|
||||
SettingsServiceClient,
|
||||
SettingsServiceDefinition,
|
||||
} from "../../proto/server/zitadel/settings/v2beta/settings_service";
|
||||
|
||||
import { ZitadelServer, createClient, getServers } from "../../server";
|
||||
|
||||
export const getSettings = (server?: string | ZitadelServer) => {
|
||||
let config;
|
||||
if (server && typeof server === "string") {
|
||||
const apps = getServers();
|
||||
config = apps.find((a) => a.name === server)?.config;
|
||||
} else if (server && typeof server === "object") {
|
||||
config = server.config;
|
||||
}
|
||||
|
||||
if (!config) {
|
||||
throw Error("No ZITADEL server found");
|
||||
}
|
||||
|
||||
return createClient<SettingsServiceClient>(
|
||||
SettingsServiceDefinition as CompatServiceDefinition,
|
||||
config.apiUrl,
|
||||
config.token,
|
||||
);
|
||||
};
|
||||
@@ -1,2 +0,0 @@
|
||||
export * from "./user";
|
||||
export * from "../../proto/server/zitadel/user/v2beta/user";
|
||||
@@ -1,28 +0,0 @@
|
||||
import { CompatServiceDefinition } from "nice-grpc/lib/service-definitions";
|
||||
|
||||
import {
|
||||
UserServiceClient,
|
||||
UserServiceDefinition,
|
||||
} from "../../proto/server/zitadel/user/v2beta/user_service";
|
||||
|
||||
import { ZitadelServer, createClient, getServers } from "../../server";
|
||||
|
||||
export const getUser = (server?: string | ZitadelServer) => {
|
||||
let config;
|
||||
if (server && typeof server === "string") {
|
||||
const apps = getServers();
|
||||
config = apps.find((a) => a.name === server)?.config;
|
||||
} else if (server && typeof server === "object") {
|
||||
config = server.config;
|
||||
}
|
||||
|
||||
if (!config) {
|
||||
throw Error("No ZITADEL server found");
|
||||
}
|
||||
|
||||
return createClient<UserServiceClient>(
|
||||
UserServiceDefinition as CompatServiceDefinition,
|
||||
config.apiUrl,
|
||||
config.token,
|
||||
);
|
||||
};
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"extends": "@zitadel/tsconfig/tsup.json",
|
||||
"include": ["./src/**/*"],
|
||||
"exclude": ["dist", "build", "node_modules"]
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
import { defineConfig, Options } from "tsup";
|
||||
|
||||
export default defineConfig((options: Options) => ({
|
||||
treeshake: true,
|
||||
splitting: true,
|
||||
publicDir: true,
|
||||
entry: ["src/index.ts", "src/**/index.ts"],
|
||||
format: ["esm", "cjs"],
|
||||
dts: true,
|
||||
minify: true,
|
||||
clean: true,
|
||||
...options,
|
||||
}));
|
||||
@@ -1,21 +0,0 @@
|
||||
{
|
||||
"extends": [
|
||||
"//"
|
||||
],
|
||||
"pipeline": {
|
||||
"generate": {
|
||||
"outputs": [
|
||||
"src/proto/**"
|
||||
],
|
||||
"cache": true
|
||||
},
|
||||
"build": {
|
||||
"outputs": [
|
||||
"dist/**"
|
||||
],
|
||||
"dependsOn": [
|
||||
"generate"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
10506
pnpm-lock.yaml
generated
10506
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
33
turbo.json
33
turbo.json
@@ -1,6 +1,22 @@
|
||||
{
|
||||
"$schema": "https://turbo.build/schema.json",
|
||||
"pipeline": {
|
||||
"ui": "tui",
|
||||
"globalDependencies": [
|
||||
"**/.env.*local"
|
||||
],
|
||||
"globalEnv": [
|
||||
"DEBUG",
|
||||
"ZITADEL_API_URL",
|
||||
"ZITADEL_SERVICE_USER_ID",
|
||||
"ZITADEL_SERVICE_USER_TOKEN",
|
||||
"ZITADEL_SYSTEM_API_URL",
|
||||
"ZITADEL_SYSTEM_API_USERID",
|
||||
"ZITADEL_SYSTEM_API_KEY",
|
||||
"ZITADEL_ISSUER",
|
||||
"ZITADEL_ADMIN_TOKEN",
|
||||
"VERCEL_URL"
|
||||
],
|
||||
"tasks": {
|
||||
"generate": {
|
||||
"cache": true
|
||||
},
|
||||
@@ -20,18 +36,5 @@
|
||||
"clean": {
|
||||
"cache": false
|
||||
}
|
||||
},
|
||||
"globalDependencies": ["**/.env.*local"],
|
||||
"globalEnv": [
|
||||
"DEBUG",
|
||||
"ZITADEL_API_URL",
|
||||
"ZITADEL_SERVICE_USER_ID",
|
||||
"ZITADEL_SERVICE_USER_TOKEN",
|
||||
"ZITADEL_SYSTEM_API_URL",
|
||||
"ZITADEL_SYSTEM_API_USERID",
|
||||
"ZITADEL_SYSTEM_API_KEY",
|
||||
"ZITADEL_ISSUER",
|
||||
"ZITADEL_ADMIN_TOKEN",
|
||||
"VERCEL_URL"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user