mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-12 05:12:20 +00:00
move server to root, path, example
This commit is contained in:
28
packages/zitadel-server/examples/app.ts
Normal file
28
packages/zitadel-server/examples/app.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import {
|
||||
ZitadelServerOptions,
|
||||
getServer,
|
||||
getServers,
|
||||
initializeServer,
|
||||
} from "#/server";
|
||||
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();
|
||||
@@ -9,9 +9,13 @@
|
||||
"files": [
|
||||
"dist/**"
|
||||
],
|
||||
"exports": {
|
||||
".": "./index.js",
|
||||
"./auth": "./jwt/auth.js"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsup src/index.ts src/auth/index.ts src/app/index.ts --format esm,cjs --dts",
|
||||
"dev": "tsup src/index.ts src/auth/index.ts src/app/index.ts --format esm,cjs --watch --dts",
|
||||
"build": "tsup src/index.ts src/*/index.ts --format esm,cjs --dts",
|
||||
"dev": "tsup src/index.ts src/*/index.ts --format esm,cjs --watch --dts",
|
||||
"lint": "eslint \"src/**/*.ts*\"",
|
||||
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
|
||||
"prebuild": "pnpm run generate",
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
let apps: ZitadelApp[] = [];
|
||||
|
||||
export interface ZitadelClientProps {
|
||||
appId: string;
|
||||
projectId: string;
|
||||
apiUrl: string; // process.env.ZITADEL_API_URL
|
||||
token: string;
|
||||
adminToken?: string;
|
||||
managementToken?: string;
|
||||
}
|
||||
|
||||
export interface ZitadelOptions extends ZitadelClientProps {
|
||||
name?: string;
|
||||
}
|
||||
|
||||
export interface ZitadelApp {
|
||||
name: string | undefined;
|
||||
config: ZitadelClientProps;
|
||||
}
|
||||
|
||||
export async function initializeApp(
|
||||
config: ZitadelClientProps,
|
||||
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 +0,0 @@
|
||||
export * from "./app";
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
AuthServiceDefinition,
|
||||
GetMyUserResponse,
|
||||
} from "../proto/server/zitadel/auth";
|
||||
import { ZitadelApp } from "../app/app";
|
||||
import { ZitadelServer } from "../server";
|
||||
import { authMiddleware } from "../middleware";
|
||||
|
||||
const createClient = <Client>(
|
||||
@@ -18,7 +18,7 @@ const createClient = <Client>(
|
||||
.create(definition, channel) as Client;
|
||||
};
|
||||
|
||||
export async function getAuth(app?: ZitadelApp): Promise<AuthServiceClient> {
|
||||
export async function getAuth(app?: ZitadelServer): Promise<AuthServiceClient> {
|
||||
return createClient<AuthServiceClient>(
|
||||
AuthServiceDefinition as CompatServiceDefinition,
|
||||
""
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
export * from "./app/app";
|
||||
export * from "./server";
|
||||
export * from "./middleware";
|
||||
|
||||
export * as auth from "./auth";
|
||||
export * as management from "./management";
|
||||
export * as admin from "./admin";
|
||||
export * as system from "./system";
|
||||
// export * as auth from "./auth";
|
||||
// export * as management from "./management";
|
||||
// export * as admin from "./admin";
|
||||
// export * as system from "./system";
|
||||
|
||||
// export * as proto from "./proto/server/zitadel/*";
|
||||
// export * from "./proto/server/zitadel/management";
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
} from "../proto/server/zitadel/management";
|
||||
|
||||
import { authMiddleware } from "../middleware";
|
||||
import { ZitadelApp, getApps } from "../app/app";
|
||||
import { ZitadelServer, getServers } from "../server";
|
||||
|
||||
const createClient = <Client>(
|
||||
definition: CompatServiceDefinition,
|
||||
@@ -24,10 +24,10 @@ const createClient = <Client>(
|
||||
.create(definition, channel) as Client;
|
||||
};
|
||||
|
||||
export const getManagement = (app?: string | ZitadelApp) => {
|
||||
export const getManagement = (app?: string | ZitadelServer) => {
|
||||
let config;
|
||||
if (app && typeof app === "string") {
|
||||
const apps = getApps();
|
||||
const apps = getServers();
|
||||
config = apps.find((a) => a.name === app)?.config;
|
||||
} else if (app && typeof app === "object") {
|
||||
config = app.config;
|
||||
|
||||
35
packages/zitadel-server/src/server.ts
Normal file
35
packages/zitadel-server/src/server.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
let apps: ZitadelServer[] = [];
|
||||
|
||||
export interface ZitadelServerProps {
|
||||
apiUrl: string; // process.env.ZITADEL_API_URL
|
||||
token: string;
|
||||
}
|
||||
|
||||
export interface ZitadelServerOptions extends ZitadelServerProps {
|
||||
name?: string;
|
||||
}
|
||||
|
||||
export interface ZitadelServer {
|
||||
name: string | undefined;
|
||||
config: ZitadelServerProps;
|
||||
}
|
||||
|
||||
export async function initializeServer(
|
||||
config: ZitadelServerProps,
|
||||
name?: string
|
||||
): Promise<ZitadelServer> {
|
||||
const app = { config, name };
|
||||
return app;
|
||||
}
|
||||
|
||||
export function getServers(): ZitadelServer[] {
|
||||
return apps;
|
||||
}
|
||||
|
||||
export function getServer(name?: string): ZitadelServer | undefined {
|
||||
return name
|
||||
? apps.find((a) => a.name === name)
|
||||
: apps.length === 1
|
||||
? apps[0]
|
||||
: undefined;
|
||||
}
|
||||
@@ -1,8 +1,12 @@
|
||||
{
|
||||
"extends": "@zitadel/tsconfig/node14.json",
|
||||
"include": ["src/**/*"],
|
||||
"include": ["src/**/*.ts"],
|
||||
"compilerOptions": {
|
||||
"baseUrl": "."
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"*": ["./src/*"],
|
||||
"#/*": ["./src/*"]
|
||||
}
|
||||
},
|
||||
"exclude": ["dist", "build", "node_modules"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user