mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-11 20:52:43 +00:00
chore: add client2 tmp pkg
This commit is contained in:
4
packages/zitadel-client2/.eslintrc.cjs
Normal file
4
packages/zitadel-client2/.eslintrc.cjs
Normal file
@@ -0,0 +1,4 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
extends: ["zitadel"],
|
||||
};
|
||||
55
packages/zitadel-client2/package.json
Normal file
55
packages/zitadel-client2/package.json
Normal file
@@ -0,0 +1,55 @@
|
||||
{
|
||||
"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.8.0",
|
||||
"@connectrpc/connect": "^1.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@zitadel/tsconfig": "workspace:*",
|
||||
"eslint-config-zitadel": "workspace:*"
|
||||
}
|
||||
}
|
||||
8
packages/zitadel-client2/src/helpers.ts
Normal file
8
packages/zitadel-client2/src/helpers.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { createPromiseClient, Transport } from "@connectrpc/connect";
|
||||
import type { ServiceType } from "@bufbuild/protobuf";
|
||||
|
||||
export function createClientFor<TService extends ServiceType>(
|
||||
service: TService,
|
||||
) {
|
||||
return (transport: Transport) => createPromiseClient(service, transport);
|
||||
}
|
||||
2
packages/zitadel-client2/src/index.ts
Normal file
2
packages/zitadel-client2/src/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export { NewAuthorizationBearerInterceptor } from "./interceptors";
|
||||
export type { PartialMessage, PlainMessage } from "@bufbuild/protobuf";
|
||||
80
packages/zitadel-client2/src/interceptors.test.ts
Normal file
80
packages/zitadel-client2/src/interceptors.test.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
import { describe, expect, test, vitest } from "vitest";
|
||||
import { Int32Value, MethodKind, StringValue } from "@bufbuild/protobuf";
|
||||
import { createRouterTransport, HandlerContext } from "@connectrpc/connect";
|
||||
import { NewAuthorizationBearerInterceptor } from "./interceptors";
|
||||
|
||||
const TestService = {
|
||||
typeName: "handwritten.TestService",
|
||||
methods: {
|
||||
unary: {
|
||||
name: "Unary",
|
||||
I: Int32Value,
|
||||
O: StringValue,
|
||||
kind: MethodKind.Unary,
|
||||
},
|
||||
},
|
||||
} as const;
|
||||
|
||||
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(
|
||||
({ service }) => {
|
||||
service(TestService, { unary: handler });
|
||||
},
|
||||
{ transport },
|
||||
);
|
||||
|
||||
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",
|
||||
);
|
||||
});
|
||||
|
||||
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(
|
||||
({ service }) => {
|
||||
service(TestService, { unary: handler });
|
||||
},
|
||||
{ transport },
|
||||
);
|
||||
|
||||
await service.unary(
|
||||
TestService,
|
||||
TestService.methods.unary,
|
||||
undefined,
|
||||
undefined,
|
||||
{ Authorization: "Bearer somethingelse" },
|
||||
{ value: 9001 },
|
||||
);
|
||||
|
||||
expect(handler).toBeCalled();
|
||||
expect(handler.mock.calls[0][1].requestHeader.get("Authorization")).toBe(
|
||||
"Bearer somethingelse",
|
||||
);
|
||||
});
|
||||
});
|
||||
16
packages/zitadel-client2/src/interceptors.ts
Normal file
16
packages/zitadel-client2/src/interceptors.ts
Normal 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);
|
||||
};
|
||||
}
|
||||
11
packages/zitadel-client2/src/v1.ts
Normal file
11
packages/zitadel-client2/src/v1.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
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";
|
||||
|
||||
export const createAdminServiceClient = createClientFor(AdminService);
|
||||
export const createAuthServiceClient = createClientFor(AuthService);
|
||||
export const createManagementServiceClient = createClientFor(ManagementService);
|
||||
export const createSystemServiceClient = createClientFor(SystemService);
|
||||
28
packages/zitadel-client2/src/v2beta.ts
Normal file
28
packages/zitadel-client2/src/v2beta.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import type { PartialMessage } from "@bufbuild/protobuf";
|
||||
|
||||
import { createClientFor } from "./helpers";
|
||||
import { UserService } from "@zitadel/proto/zitadel/user/v2beta/user_service_connect";
|
||||
import { SettingsService } from "@zitadel/proto/zitadel/settings/v2beta/settings_service_connect";
|
||||
import { SessionService } from "@zitadel/proto/zitadel/session/v2beta/session_service_connect";
|
||||
import { OIDCService } from "@zitadel/proto/zitadel/oidc/v2beta/oidc_service_connect";
|
||||
import { OrganizationService } from "@zitadel/proto/zitadel/org/v2beta/org_service_connect";
|
||||
import { FeatureService } from "@zitadel/proto/zitadel/feature/v2beta/feature_service_connect";
|
||||
import type { RequestContext } from "@zitadel/proto/zitadel/object/v2beta/object_pb";
|
||||
|
||||
export const createUserServiceClient = createClientFor(UserService);
|
||||
export const createSettingsServiceClient = createClientFor(SettingsService);
|
||||
export const createSessionServiceClient = createClientFor(SessionService);
|
||||
export const createOIDCServiceClient = createClientFor(OIDCService);
|
||||
export const createOrganizationServiceClient =
|
||||
createClientFor(OrganizationService);
|
||||
export const createFeatureServiceClient = createClientFor(FeatureService);
|
||||
|
||||
export function makeReqCtx(
|
||||
orgId: string | undefined,
|
||||
): PartialMessage<RequestContext> {
|
||||
return {
|
||||
resourceOwner: orgId
|
||||
? { case: "orgId", value: orgId }
|
||||
: { case: "instance", value: true },
|
||||
};
|
||||
}
|
||||
8
packages/zitadel-client2/src/v3alpha.ts
Normal file
8
packages/zitadel-client2/src/v3alpha.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { createClientFor } from "./helpers";
|
||||
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 { ActionService } from "@zitadel/proto/zitadel/action/v3alpha/action_service_connect";
|
||||
|
||||
export const createUserSchemaServiceClient = createClientFor(UserSchemaService);
|
||||
export const createUserServiceClient = createClientFor(UserService);
|
||||
export const createActionServiceClient = createClientFor(ActionService);
|
||||
5
packages/zitadel-client2/tsconfig.json
Normal file
5
packages/zitadel-client2/tsconfig.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"extends": "@zitadel/tsconfig/tsup.json",
|
||||
"include": ["./src/**/*"],
|
||||
"exclude": ["dist", "build", "node_modules"]
|
||||
}
|
||||
13
packages/zitadel-client2/tsup.config.ts
Normal file
13
packages/zitadel-client2/tsup.config.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
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,
|
||||
}));
|
||||
15
packages/zitadel-client2/turbo.json
Normal file
15
packages/zitadel-client2/turbo.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"extends": [
|
||||
"//"
|
||||
],
|
||||
"pipeline": {
|
||||
"build": {
|
||||
"outputs": [
|
||||
"dist/**"
|
||||
],
|
||||
"dependsOn": [
|
||||
"generate"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
28
pnpm-lock.yaml
generated
28
pnpm-lock.yaml
generated
@@ -236,6 +236,25 @@ importers:
|
||||
specifier: ^1.139.0
|
||||
version: 1.146.0
|
||||
|
||||
packages/zitadel-client2:
|
||||
dependencies:
|
||||
'@bufbuild/protobuf':
|
||||
specifier: ^1.8.0
|
||||
version: 1.9.0
|
||||
'@connectrpc/connect':
|
||||
specifier: ^1.4.0
|
||||
version: 1.4.0(@bufbuild/protobuf@1.9.0)
|
||||
'@zitadel/proto':
|
||||
specifier: workspace:*
|
||||
version: link:../zitadel-proto
|
||||
devDependencies:
|
||||
'@zitadel/tsconfig':
|
||||
specifier: workspace:*
|
||||
version: link:../zitadel-tsconfig
|
||||
eslint-config-zitadel:
|
||||
specifier: workspace:*
|
||||
version: link:../eslint-config-zitadel
|
||||
|
||||
packages/zitadel-next:
|
||||
dependencies:
|
||||
'@zitadel/react':
|
||||
@@ -653,6 +672,11 @@ packages:
|
||||
resolution: {integrity: sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==, tarball: https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz}
|
||||
engines: {node: '>=0.1.90'}
|
||||
|
||||
'@connectrpc/connect@1.4.0':
|
||||
resolution: {integrity: sha512-vZeOkKaAjyV4+RH3+rJZIfDFJAfr+7fyYr6sLDKbYX3uuTVszhFe9/YKf5DNqrDb5cKdKVlYkGn6DTDqMitAnA==, tarball: https://registry.npmjs.org/@connectrpc/connect/-/connect-1.4.0.tgz}
|
||||
peerDependencies:
|
||||
'@bufbuild/protobuf': ^1.4.2
|
||||
|
||||
'@cypress/request@3.0.1':
|
||||
resolution: {integrity: sha512-TWivJlJi8ZDx2wGOw1dbLuHJKUYX7bWySw377nlnGOW3hP9/MUKIsEdXT/YngWxVdgNCHRBmFlBipE+5/2ZZlQ==, tarball: https://registry.npmjs.org/@cypress/request/-/request-3.0.1.tgz}
|
||||
engines: {node: '>= 6'}
|
||||
@@ -5293,6 +5317,10 @@ snapshots:
|
||||
'@colors/colors@1.5.0':
|
||||
optional: true
|
||||
|
||||
'@connectrpc/connect@1.4.0(@bufbuild/protobuf@1.9.0)':
|
||||
dependencies:
|
||||
'@bufbuild/protobuf': 1.9.0
|
||||
|
||||
'@cypress/request@3.0.1':
|
||||
dependencies:
|
||||
aws-sign2: 0.7.0
|
||||
|
||||
Reference in New Issue
Block a user