tailwind package

This commit is contained in:
Max Peintner
2023-04-14 13:35:27 +02:00
parent b275a0de62
commit 2c04b79f1b
27 changed files with 264 additions and 221 deletions

View File

@@ -1,28 +0,0 @@
import { CompatServiceDefinition } from "nice-grpc/lib/service-definitions";
import { createChannel, createClientFactory } from "nice-grpc";
import {
AuthServiceClient,
AuthServiceDefinition,
} from "./proto/server/zitadel/auth";
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 ?? ""
);

View File

@@ -1,25 +1,19 @@
import { CompatServiceDefinition } from "nice-grpc/lib/service-definitions";
import { createChannel, createClientFactory } from "nice-grpc";
import {
AuthServiceClient,
AuthServiceDefinition,
} from "./proto/server/zitadel/auth";
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;
};
// 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): Promise<AuthServiceClient> {
return createClient<AuthServiceClient>(
AuthServiceDefinition as CompatServiceDefinition,
""
);
export async function getAuth(app?: ZitadelApp) {
// return createClient<AuthServiceClient>(
// AuthServiceDefinition as CompatServiceDefinition,
// ""
// );
}

View File

@@ -1,8 +1,5 @@
export { initializeApp, getApps } from "./app";
export { getAuth } from "./auth";
export { getManagement } from "./management";
export { getAdmin } from "./admin";
export { getSystem } from "./system";
export type { ZitadelOptions } from "./app";

View File

@@ -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 { ZitadelApp, getApps } from "./app";
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 | ZitadelApp) => {
let config;
if (app && typeof app === "string") {
const apps = getApps();
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
);
};

View File

@@ -1,4 +1,4 @@
import { CallOptions, ClientMiddlewareCall, Metadata } from "nice-grpc";
import { CallOptions, ClientMiddlewareCall, Metadata } from "nice-grpc-web";
export const authMiddleware = (token: string) =>
async function* <Request, Response>(

View File

@@ -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
);
};