mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-11 19:42:16 +00:00
chore!: use buf v2 generators
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
import type { DescService } from "@bufbuild/protobuf";
|
||||
import { Timestamp, timestampDate } from "@bufbuild/protobuf/wkt";
|
||||
import { createPromiseClient, Transport } from "@connectrpc/connect";
|
||||
import type { ServiceType } from "@bufbuild/protobuf";
|
||||
|
||||
export function createClientFor<TService extends ServiceType>(
|
||||
service: TService,
|
||||
) {
|
||||
export function createClientFor<TService extends DescService>(service: TService) {
|
||||
return (transport: Transport) => createPromiseClient(service, transport);
|
||||
}
|
||||
|
||||
export function toDate(timestamp: Timestamp | undefined): Date | undefined {
|
||||
return timestamp ? timestampDate(timestamp) : undefined;
|
||||
}
|
||||
|
||||
@@ -1,2 +1,7 @@
|
||||
export { toDate } from "./helpers";
|
||||
export { NewAuthorizationBearerInterceptor } from "./interceptors";
|
||||
export type { PartialMessage, PlainMessage } from "@bufbuild/protobuf";
|
||||
|
||||
// TODO: Move this to `./protobuf.ts` and export it from there
|
||||
export { create as createMessage, fromJson, toJson } from "@bufbuild/protobuf";
|
||||
export { TimestampSchema, timestampDate } from "@bufbuild/protobuf/wkt";
|
||||
export type { Timestamp } from "@bufbuild/protobuf/wkt";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, test, vitest } from "vitest";
|
||||
import { Int32Value, MethodKind, StringValue } from "@bufbuild/protobuf";
|
||||
import { createRouterTransport, HandlerContext } from "@connectrpc/connect";
|
||||
import { describe, expect, test, vitest } from "vitest";
|
||||
import { NewAuthorizationBearerInterceptor } from "./interceptors";
|
||||
|
||||
const TestService = {
|
||||
@@ -21,11 +21,9 @@ describe("NewAuthorizationBearerInterceptor", () => {
|
||||
};
|
||||
|
||||
test("injects the authorization token", async () => {
|
||||
const handler = vitest.fn(
|
||||
(request: Int32Value, context: HandlerContext) => {
|
||||
return { value: request.value.toString() };
|
||||
},
|
||||
);
|
||||
const handler = vitest.fn((request: Int32Value, context: HandlerContext) => {
|
||||
return { value: request.value.toString() };
|
||||
});
|
||||
|
||||
const service = createRouterTransport(
|
||||
({ service }) => {
|
||||
@@ -34,27 +32,16 @@ describe("NewAuthorizationBearerInterceptor", () => {
|
||||
{ transport },
|
||||
);
|
||||
|
||||
await service.unary(
|
||||
TestService,
|
||||
TestService.methods.unary,
|
||||
undefined,
|
||||
undefined,
|
||||
{},
|
||||
{ value: 9001 },
|
||||
);
|
||||
await service.unary(TestService, TestService.methods.unary, undefined, undefined, {}, { value: 9001 });
|
||||
|
||||
expect(handler).toBeCalled();
|
||||
expect(handler.mock.calls[0][1].requestHeader.get("Authorization")).toBe(
|
||||
"Bearer mytoken",
|
||||
);
|
||||
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 handler = vitest.fn((request: Int32Value, context: HandlerContext) => {
|
||||
return { value: request.value.toString() };
|
||||
});
|
||||
|
||||
const service = createRouterTransport(
|
||||
({ service }) => {
|
||||
@@ -73,8 +60,6 @@ describe("NewAuthorizationBearerInterceptor", () => {
|
||||
);
|
||||
|
||||
expect(handler).toBeCalled();
|
||||
expect(handler.mock.calls[0][1].requestHeader.get("Authorization")).toBe(
|
||||
"Bearer somethingelse",
|
||||
);
|
||||
expect(handler.mock.calls[0][1].requestHeader.get("Authorization")).toBe("Bearer somethingelse");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { createClientFor } from "./helpers";
|
||||
|
||||
import { AdminService } from "@zitadel/proto/zitadel/admin_connect";
|
||||
import { AuthService } from "@zitadel/proto/zitadel/auth_connect";
|
||||
import { ManagementService } from "@zitadel/proto/zitadel/management_connect";
|
||||
import { SystemService } from "@zitadel/proto/zitadel/system_connect";
|
||||
import { AdminService } from "@zitadel/proto/zitadel/admin_pb";
|
||||
import { AuthService } from "@zitadel/proto/zitadel/auth_pb";
|
||||
import { ManagementService } from "@zitadel/proto/zitadel/management_pb";
|
||||
import { SystemService } from "@zitadel/proto/zitadel/system_pb";
|
||||
|
||||
export const createAdminServiceClient = createClientFor(AdminService);
|
||||
export const createAuthServiceClient = createClientFor(AuthService);
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { FeatureService } from "@zitadel/proto/zitadel/feature/v2/feature_service_connect";
|
||||
import { IdentityProviderService } from "@zitadel/proto/zitadel/idp/v2/idp_service_connect";
|
||||
import { FeatureService } from "@zitadel/proto/zitadel/feature/v2/feature_service_pb";
|
||||
import { IdentityProviderService } from "@zitadel/proto/zitadel/idp/v2/idp_service_pb";
|
||||
import { RequestContext } from "@zitadel/proto/zitadel/object/v2/object_pb";
|
||||
import { OIDCService } from "@zitadel/proto/zitadel/oidc/v2/oidc_service_connect";
|
||||
import { OrganizationService } from "@zitadel/proto/zitadel/org/v2/org_service_connect";
|
||||
import { SessionService } from "@zitadel/proto/zitadel/session/v2/session_service_connect";
|
||||
import { SettingsService } from "@zitadel/proto/zitadel/settings/v2/settings_service_connect";
|
||||
import { UserService } from "@zitadel/proto/zitadel/user/v2/user_service_connect";
|
||||
import { OIDCService } from "@zitadel/proto/zitadel/oidc/v2/oidc_service_pb";
|
||||
import { OrganizationService } from "@zitadel/proto/zitadel/org/v2/org_service_pb";
|
||||
import { SessionService } from "@zitadel/proto/zitadel/session/v2/session_service_pb";
|
||||
import { SettingsService } from "@zitadel/proto/zitadel/settings/v2/settings_service_pb";
|
||||
import { UserService } from "@zitadel/proto/zitadel/user/v2/user_service_pb";
|
||||
|
||||
import { createClientFor } from "./helpers";
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { UserSchemaService } from "@zitadel/proto/zitadel/user/schema/v3alpha/user_schema_service_connect";
|
||||
import { UserService } from "@zitadel/proto/zitadel/user/v3alpha/user_service_connect";
|
||||
import { UserSchemaService } from "@zitadel/proto/zitadel/user/schema/v3alpha/user_schema_service_pb";
|
||||
import { UserService } from "@zitadel/proto/zitadel/user/v3alpha/user_service_pb";
|
||||
import { createClientFor } from "./helpers";
|
||||
|
||||
export const createUserSchemaServiceClient = createClientFor(UserSchemaService);
|
||||
|
||||
Reference in New Issue
Block a user