Skip to content

Commit

Permalink
init nodejs sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
jsbroks committed Aug 25, 2024
1 parent 8dced60 commit e5c46e9
Show file tree
Hide file tree
Showing 49 changed files with 3,283 additions and 40 deletions.
9 changes: 8 additions & 1 deletion apps/docs/pages/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,12 @@
"variables": "Variables",
"runbooks": "Runbooks",
"advanced": "Advanced",
"glossary": "Glossary"
"glossary": "Glossary",

"-- Integrations": {
"type": "separator",
"title": "Integrations"
},
"github": "GitHub",
"google-cloud": "Google Cloud"
}
6 changes: 6 additions & 0 deletions apps/docs/pages/github/actions-dispatcher.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Actions Dispatcher

GitHub Actions Dispatcher is allows you to trigger other GitHub Actions
workflows from a single workflow. This is useful when you want to run multiple
workflows in parallel or when you want to trigger a workflow from another
repository.
6 changes: 6 additions & 0 deletions apps/docs/pages/github/deployment-configs.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Deployment Configs

Deployment configs allow you to create deployments via YAML configuration files.
This approach is useful for defining deployments in a declarative manner,
enabling you to version control your deployment configurations and create better
templates for other application development teams.
4 changes: 4 additions & 0 deletions apps/docs/pages/github/release-scanner.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Release Scanner

The Release Scanner is a tool that scans GitHub repositories for new releases
and creates them for related deployments automatically.
4 changes: 4 additions & 0 deletions apps/docs/pages/google-cloud/compute-scanner.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Compute Scanner

The Compute Scanner is a tool that scans Google Cloud projects for new instances
and creates them for related deployments automatically.
3 changes: 3 additions & 0 deletions apps/docs/theme.config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const config: DocsThemeConfig = {
},
project: {},
chat: {},
sidebar: {
defaultMenuCollapseLevel: 0,
},
editLink: { component: null },
feedback: { content: null },
footer: {
Expand Down
2 changes: 1 addition & 1 deletion apps/provider/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const run = async () => {
}
};

const job = new CronJob("* * * * *", () => run().catch(console.log));
const job = new CronJob("* * * * *", run);

console.log("Starting managed providers cronjob");
run();
Expand Down
1 change: 0 additions & 1 deletion apps/webservice/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const config = {
"@ctrlplane/db",
"@ctrlplane/ui",
"@ctrlplane/validators",
"@ctrlplane/webshell",
"@ctrlplane/job-dispatch",
],

Expand Down
4 changes: 4 additions & 0 deletions apps/webservice/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@
"@internationalized/date": "^3.5.4",
"@monaco-editor/react": "^4.6.0",
"@octokit/auth-app": "^7.1.0",
"@opentelemetry/api-logs": "^0.52.1",
"@opentelemetry/instrumentation": "^0.52.1",
"@opentelemetry/sdk-logs": "^0.52.1",
"@t3-oss/env-nextjs": "^0.10.1",
"@tailwindcss/typography": "^0.5.13",
"@tanstack/react-query": "^5.35.5",
"@tanstack/react-table": "^8.17.3",
"@trpc/client": "11.0.0-rc.364",
"@trpc/react-query": "11.0.0-rc.364",
"@trpc/server": "11.0.0-rc.364",
"@vercel/otel": "^1.10.0",
"@xterm/addon-clipboard": "^0.1.0",
"@xterm/addon-fit": "^0.10.0",
"@xterm/addon-search": "^0.15.0",
Expand Down
5 changes: 5 additions & 0 deletions apps/webservice/src/instrumentation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { registerOTel } from "@vercel/otel";

export function register() {
registerOTel({ serviceName: "ctrlplane/webservice" });
}
2 changes: 1 addition & 1 deletion apps/webshell-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "module",
"scripts": {
"clean": "rm -rf .turbo node_modules",
"dev": "tsx watch --clear-screen=false src/index.ts",
"dev:new": "tsx watch --clear-screen=false src/index.ts",
"lint": "eslint",
"format": "prettier --check . --ignore-path ../../.gitignore"
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"clean:workspaces": "turbo clean",
"db:push": "pnpm -F db push",
"db:studio": "pnpm -F db studio",
"dev": "turbo dev --parallel --concurrency 30",
"dev": "turbo dev --parallel --concurrency 30 --filter=!./providers/**/*",
"format": "turbo format --continue -- --cache --cache-location node_modules/.cache/.prettiercache",
"format:fix": "turbo format --continue -- --write --cache --cache-location node_modules/.cache/.prettiercache",
"lint": "turbo lint --continue -- --cache --cache-location node_modules/.cache/.eslintcache",
Expand Down
7 changes: 5 additions & 2 deletions packages/api/src/router/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const integrationsRouter = createTRPCRouter({

const projectId = await auth.getProjectId();

await google.iam("v1").projects.serviceAccounts.create({
const sa = await google.iam("v1").projects.serviceAccounts.create({
name: `projects/${projectId}`,
auth,
requestBody: {
Expand All @@ -75,10 +75,13 @@ const integrationsRouter = createTRPCRouter({
},
});

if (sa.data.email == null)
throw new Error("No email server account response");

return ctx.db
.update(workspace)
.set({
googleServiceAccountEmail: `tp-${ws.slug}@${process.env.GOOGLE_PROJECT_ID}.iam.gserviceaccount.com`,
googleServiceAccountEmail: sa.data.email,
})
.where(eq(workspace.id, input))
.returning()
Expand Down
2 changes: 1 addition & 1 deletion packages/job-dispatch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"default": "./dist/queue/index.js"
}
},
"license": "MIT",
"license": "",
"scripts": {
"build": "tsc",
"dev": "tsc --watch",
Expand Down
10 changes: 10 additions & 0 deletions packages/logger/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import baseConfig, { requireJsSuffix } from "@ctrlplane/eslint-config/base";

/** @type {import('typescript-eslint').Config} */
export default [
{
ignores: ["dist/**"],
},
...requireJsSuffix,
...baseConfig,
];
35 changes: 35 additions & 0 deletions packages/logger/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "@ctrlplane/logger",
"private": true,
"version": "0.1.0",
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./src/index.ts"
}
},
"license": "MIT",
"scripts": {
"build": "tsc",
"dev": "tsc --watch",
"clean": "rm -rf .turbo node_modules",
"format": "prettier --check . --ignore-path ../../.gitignore",
"lint": "eslint",
"typecheck": "tsc --noEmit --emitDeclarationOnly false"
},
"dependencies": {
"@colors/colors": "^1.6.0",
"winston": "^3.14.2",
"zod": "catalog:"
},
"devDependencies": {
"@ctrlplane/eslint-config": "workspace:*",
"@ctrlplane/prettier-config": "workspace:*",
"@ctrlplane/tsconfig": "workspace:*",
"eslint": "catalog:",
"prettier": "catalog:",
"typescript": "^5.4.5"
},
"prettier": "@ctrlplane/prettier-config"
}
35 changes: 35 additions & 0 deletions packages/logger/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import colors from "@colors/colors/safe";
import * as winston from "winston";

const { LOG_LEVEL, NODE_ENV } = process.env;

function createLogger(level: string) {
const format = [
winston.format.timestamp(),
winston.format.align(),
winston.format.printf((info) => {
const { timestamp, level, message, durationMs } = info;
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
const ts = timestamp?.slice(0, 19).replace("T", " ");
const duration = durationMs != null ? `(Timer: ${durationMs}ms)` : "";
const hasLabel = info.label != null;
const appendLabel = info.label?.length < 5 ? " " : "";
const label = hasLabel ? `\t[${info.label}]${appendLabel} ` : "\t\t";

return NODE_ENV === "production"
? `${ts} ${duration} [${level}]: ${label} ${message} ${duration}`
: `[${level}]: ${colors.gray(label)}${message} ${duration}`;
}),
];

// We dont want colors in production. They do not display correctly in cloud run console.
if (NODE_ENV !== "production") format.unshift(winston.format.colorize());

return winston.createLogger({
level,
format: winston.format.combine(...format),
transports: [new winston.transports.Console()],
});
}

export const logger = createLogger(LOG_LEVEL ?? "verbose");
11 changes: 11 additions & 0 deletions packages/logger/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "@ctrlplane/tsconfig/internal-package.json",
"compilerOptions": {
"outDir": "dist",
"baseUrl": ".",
"incremental": true,
"tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json"
},
"include": ["*.ts", "src"],
"exclude": ["node_modules"]
}
10 changes: 10 additions & 0 deletions packages/node-sdk/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import baseConfig, { requireJsSuffix } from "@ctrlplane/eslint-config/base";

/** @type {import('typescript-eslint').Config} */
export default [
{
ignores: ["dist/**"],
},
...requireJsSuffix,
...baseConfig,
];
Loading

0 comments on commit e5c46e9

Please sign in to comment.