Skip to content

Commit

Permalink
Merge pull request #74 from yordis/add-node-pkg
Browse files Browse the repository at this point in the history
feat: add @zitadel/node pkg
  • Loading branch information
peintnermax authored May 29, 2024
2 parents df73742 + 4594f22 commit 61f890f
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/zitadel-client2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
},
"dependencies": {
"@zitadel/proto": "workspace:*",
"@bufbuild/protobuf": "^1.8.0",
"@bufbuild/protobuf": "^1.9.0",
"@connectrpc/connect": "^1.4.0"
},
"devDependencies": {
Expand Down
5 changes: 5 additions & 0 deletions packages/zitadel-node/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
root: true,
// TODO: React is not used in the server package
extends: ["zitadel"],
};
42 changes: 42 additions & 0 deletions packages/zitadel-node/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "@zitadel/node",
"version": "0.0.0",
"type": "module",
"sideEffects": false,
"license": "MIT",
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.cjs",
"types": "./dist/index.d.ts"
}
},
"files": [
"dist/**"
],
"publishConfig": {
"access": "public"
},
"scripts": {
"build": "tsup",
"test": "pnpm test:unit",
"test:watch": "pnpm test:unit:watch",
"test:unit": "vitest",
"test:unit:watch": "vitest --watch",
"dev": "tsup --watch",
"lint": "eslint \"src/**/*.ts*\"",
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist && rm -rf src/proto"
},
"peerDependencies": {
"@zitadel/client2": "workspace:*"
},
"dependencies": {
"@connectrpc/connect-node": "^1.4.0",
"jose": "^5.3.0"
},
"devDependencies": {
"@zitadel/client2": "workspace:*",
"@zitadel/tsconfig": "workspace:*",
"eslint-config-zitadel": "workspace:*"
}
}
35 changes: 35 additions & 0 deletions packages/zitadel-node/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { NewAuthorizationBearerInterceptor } from "@zitadel/client2";
import {
createGrpcWebTransport,
GrpcTransportOptions,
} from "@connectrpc/connect-node";
import { importPKCS8, SignJWT } from "jose";

/**
* Create a server transport with the given token and configuration options.
* @param token
* @param opts
*/
export function createServerTransport(
token: string,
opts: GrpcTransportOptions,
) {
return createGrpcWebTransport({
...opts,
interceptors: [
...(opts.interceptors || []),
NewAuthorizationBearerInterceptor(token),
],
});
}

export async function newSystemToken() {
return 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"));
}
5 changes: 5 additions & 0 deletions packages/zitadel-node/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "@zitadel/tsconfig/tsup.json",
"include": ["./src/**/*"],
"exclude": ["dist", "build", "node_modules"]
}
13 changes: 13 additions & 0 deletions packages/zitadel-node/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { defineConfig, Options } from "tsup";

export default defineConfig((options: Options) => ({
treeshake: false,
splitting: true,
entry: ["src/index.ts"],
format: ["esm", "cjs"],
dts: true,
minify: false,
clean: true,
sourcemap: true,
...options,
}));
11 changes: 11 additions & 0 deletions packages/zitadel-node/turbo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": [
"//"
],
"pipeline": {
"build": {
"outputs": ["dist/**"],
"dependsOn": ["@zitadel/client2#build"]
}
}
}
59 changes: 55 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 61f890f

Please sign in to comment.