Skip to content

Commit 148e1c2

Browse files
authored
Merge pull request #2 from rshelekhov/dev
Init SDK
2 parents 43e185a + 06ce8f3 commit 148e1c2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+7127
-0
lines changed

.claude/rules/bun.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
---
2+
description: Use Bun instead of Node.js, npm, pnpm, or vite.
3+
globs: "*.ts, *.tsx, *.html, *.css, *.js, *.jsx, package.json"
4+
alwaysApply: false
5+
---
6+
7+
Default to using Bun instead of Node.js.
8+
9+
- Use `bun <file>` instead of `node <file>` or `ts-node <file>`
10+
- Use `bun test` instead of `jest` or `vitest`
11+
- Use `bun build <file.html|file.ts|file.css>` instead of `webpack` or `esbuild`
12+
- Use `bun install` instead of `npm install` or `yarn install` or `pnpm install`
13+
- Use `bun run <script>` instead of `npm run <script>` or `yarn run <script>` or `pnpm run <script>`
14+
- Bun automatically loads .env, so don't use dotenv.
15+
16+
## APIs
17+
18+
- `Bun.serve()` supports WebSockets, HTTPS, and routes. Don't use `express`.
19+
- `bun:sqlite` for SQLite. Don't use `better-sqlite3`.
20+
- `Bun.redis` for Redis. Don't use `ioredis`.
21+
- `Bun.sql` for Postgres. Don't use `pg` or `postgres.js`.
22+
- `WebSocket` is built-in. Don't use `ws`.
23+
- Prefer `Bun.file` over `node:fs`'s readFile/writeFile
24+
- Bun.$`ls` instead of execa.
25+
26+
## Testing
27+
28+
Use `bun test` to run tests.
29+
30+
```ts#index.test.ts
31+
import { test, expect } from "bun:test";
32+
33+
test("hello world", () => {
34+
expect(1).toBe(1);
35+
});
36+
```
37+
38+
## Frontend
39+
40+
Use HTML imports with `Bun.serve()`. Don't use `vite`. HTML imports fully support React, CSS, Tailwind.
41+
42+
Server:
43+
44+
```ts#index.ts
45+
import index from "./index.html"
46+
47+
Bun.serve({
48+
routes: {
49+
"/": index,
50+
"/api/users/:id": {
51+
GET: (req) => {
52+
return new Response(JSON.stringify({ id: req.params.id }));
53+
},
54+
},
55+
},
56+
// optional websocket support
57+
websocket: {
58+
open: (ws) => {
59+
ws.send("Hello, world!");
60+
},
61+
message: (ws, message) => {
62+
ws.send(message);
63+
},
64+
close: (ws) => {
65+
// handle close
66+
}
67+
},
68+
development: {
69+
hmr: true,
70+
console: true,
71+
}
72+
})
73+
```
74+
75+
HTML files can import .tsx, .jsx or .js files directly and Bun's bundler will transpile & bundle automatically. `<link>` tags can point to stylesheets and Bun's CSS bundler will bundle.
76+
77+
```html#index.html
78+
<html>
79+
<body>
80+
<h1>Hello, world!</h1>
81+
<script type="module" src="./frontend.tsx"></script>
82+
</body>
83+
</html>
84+
```
85+
86+
With the following `frontend.tsx`:
87+
88+
```tsx#frontend.tsx
89+
import React from "react";
90+
91+
// import .css files directly and it works
92+
import './index.css';
93+
94+
import { createRoot } from "react-dom/client";
95+
96+
const root = createRoot(document.body);
97+
98+
export default function Frontend() {
99+
return <h1>Hello, world!</h1>;
100+
}
101+
102+
root.render(<Frontend />);
103+
```
104+
105+
Then, run index.ts
106+
107+
```sh
108+
bun --hot ./index.ts
109+
```
110+
111+
For more information, read the Bun API docs in `node_modules/bun-types/docs/**.md`.

.github/workflows/lint.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Lint
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [dev, main]
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
lint:
14+
name: Lint & Type Check
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
21+
- name: Setup Bun
22+
uses: oven-sh/setup-bun@v1
23+
with:
24+
bun-version: latest
25+
26+
- name: Install dependencies
27+
run: bun install
28+
29+
- name: Run type checking
30+
run: bun run typecheck
31+
32+
- name: Check formatting
33+
run: bun run format:check

.github/workflows/test.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Tests
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [dev, main]
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
# Unit tests - fast feedback
14+
unit-tests:
15+
name: Unit Tests
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
22+
- name: Setup Bun
23+
uses: oven-sh/setup-bun@v1
24+
with:
25+
bun-version: latest
26+
27+
- name: Install dependencies
28+
run: bun install
29+
30+
- name: Build SDK
31+
run: bun run build
32+
33+
- name: Run unit tests
34+
run: bun run test:unit
35+
36+
# Integration tests - with real SSO server
37+
integration-tests:
38+
name: Integration Tests
39+
runs-on: ubuntu-latest
40+
needs: unit-tests
41+
42+
steps:
43+
- name: Checkout SDK code
44+
uses: actions/checkout@v4
45+
46+
- name: Setup Bun
47+
uses: oven-sh/setup-bun@v1
48+
with:
49+
bun-version: latest
50+
51+
- name: Install dependencies
52+
run: make install
53+
54+
- name: Build SDK
55+
run: make build
56+
57+
- name: Start SSO Server
58+
run: make test-up
59+
60+
- name: Run integration tests
61+
run: make test-integration
62+
env:
63+
SSO_BASE_URL: http://localhost:8080
64+
TEST_CLIENT_ID: test-client-id
65+
TEST_ISSUER: sso-service
66+
67+
- name: Show SSO Server logs on failure
68+
if: failure()
69+
run: make test-logs
70+
71+
- name: Stop Docker services
72+
if: always()
73+
run: make test-down

.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# dependencies (bun install)
2+
node_modules
3+
4+
# output
5+
out
6+
dist
7+
*.tgz
8+
9+
# code coverage
10+
coverage
11+
*.lcov
12+
13+
# logs
14+
logs
15+
_.log
16+
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
17+
18+
# dotenv environment variable files
19+
.env
20+
.env.development.local
21+
.env.test.local
22+
.env.production.local
23+
.env.local
24+
25+
# caches
26+
.eslintcache
27+
.cache
28+
*.tsbuildinfo
29+
30+
# IntelliJ based IDEs
31+
.idea
32+
33+
# Finder (MacOS) folder config
34+
.DS_Store

.prettierrc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"semi": true,
3+
"singleQuote": true,
4+
"tabWidth": 2,
5+
"trailingComma": "es5",
6+
"printWidth": 100,
7+
"plugins": ["@trivago/prettier-plugin-sort-imports"],
8+
"importOrder": [
9+
"^node:",
10+
"<THIRD_PARTY_MODULES>",
11+
"^../types/(.*)$",
12+
"^./(.*)$",
13+
"^[./]"
14+
],
15+
"importOrderSeparation": true,
16+
"importOrderSortSpecifiers": true
17+
}

Makefile

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
.PHONY: help test test-unit test-integration test-up test-down test-logs test-logs-follow install build typecheck format
2+
3+
# Default target - show help
4+
help:
5+
@echo "SSO TypeScript SDK - Available Commands"
6+
@echo ""
7+
@echo "Testing:"
8+
@echo " make test - Run all tests (starts server, runs tests, stops server)"
9+
@echo " make test-unit - Run unit tests only (fast, no server needed)"
10+
@echo " make test-integration - Run integration tests (server must be running)"
11+
@echo ""
12+
@echo "Test Server:"
13+
@echo " make test-up - Start SSO server"
14+
@echo " make test-down - Stop SSO server"
15+
@echo " make test-logs - View server logs (last 100 lines)"
16+
@echo " make test-logs-follow - Follow server logs (interactive)"
17+
@echo ""
18+
@echo "Development:"
19+
@echo " make install - Install dependencies"
20+
@echo " make build - Build the SDK"
21+
@echo " make typecheck - Run type checking"
22+
@echo " make format - Format code"
23+
24+
# Run all tests (starts server, runs tests, stops server)
25+
test:
26+
@echo "▶ Starting SSO server..."
27+
@docker compose -f docker-compose.test.yml up -d
28+
@echo "⏳ Waiting for services (30s)..."
29+
@sleep 30
30+
@echo "▶ Running unit tests..."
31+
@bun run test:unit || (docker compose -f docker-compose.test.yml down && exit 1)
32+
@echo "▶ Running integration tests..."
33+
@bun run test:integration || (docker compose -f docker-compose.test.yml down && exit 1)
34+
@echo "▶ Stopping server..."
35+
@docker compose -f docker-compose.test.yml down
36+
@echo "✅ All tests passed!"
37+
38+
# Run unit tests only
39+
test-unit:
40+
@echo "▶ Running unit tests..."
41+
@bun run test:unit
42+
43+
# Run integration tests (requires running server)
44+
test-integration:
45+
@echo "▶ Running integration tests..."
46+
@bun run test:integration
47+
48+
# Start SSO server and dependencies
49+
test-up:
50+
@echo "▶ Starting SSO server..."
51+
@docker compose -f docker-compose.test.yml up -d
52+
@echo "⏳ Waiting 30s for services to be ready..."
53+
@sleep 30
54+
@echo "✅ Server ready! Use 'make test-integration' to run tests"
55+
56+
# Stop SSO server
57+
test-down:
58+
@echo "▶ Stopping SSO server..."
59+
@docker compose -f docker-compose.test.yml down -v
60+
@echo "✅ Server stopped"
61+
62+
# View SSO server logs (use test-logs-follow for interactive mode)
63+
test-logs:
64+
@docker compose -f docker-compose.test.yml logs --tail=100 sso
65+
66+
# Follow SSO server logs (interactive)
67+
test-logs-follow:
68+
@docker compose -f docker-compose.test.yml logs -f sso
69+
70+
# Install dependencies
71+
install:
72+
@bun install
73+
74+
# Build the SDK
75+
build:
76+
@bun run build
77+
78+
# Run TypeScript type checking
79+
typecheck:
80+
@bun run typecheck
81+
82+
# Format code
83+
format:
84+
@bun run format

0 commit comments

Comments
 (0)