Skip to content

Commit

Permalink
Publishing stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Wundero committed Dec 1, 2024
1 parent d8b78af commit 0a091cd
Show file tree
Hide file tree
Showing 14 changed files with 182 additions and 3 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Publish

on:
push:
branches:
- main

jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write # The OIDC ID token is used for authentication with JSR.
steps:
- uses: actions/checkout@v4
- run: npx jsr publish
working-directory: ./packages/validators
- run: npx jsr publish
working-directory: ./packages/core
- run: npx jsr publish
working-directory: ./packages/react
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,41 @@
# Sinkr
Synchronize data to your clients in real time with websockets. Deploy on your own infrastructure!

## How to use
To deploy your own Sinkr instance, follow these steps:

1. Clone this repository
2. Run `pnpm install` in the root directory
3. In Cloudflare, ensure you have a domain you want to deploy to.
4. In GitHub, create a new GitHub OAuth app
1. Make sure the app has the callback URL set to `<your domain>/api/auth/callback/github`
2. Save your client ID and secret
5. Setup your Cloudflare workers
1. Run `cd apps/app-manager`
2. Run `pnpm wrangler login` to authenticate Wrangler
3. Run `pnpm wrangler d1 create <your-database-name>` to create a D1 database.
1. Copy the resulting database info (ID and name) into **BOTH** `apps/app-manager/wrangler.toml` AND `apps/deployment/wrangler.toml`
4. In Cloudflare, create a new API token with `d1:write`
5. Add the following environment variables to your environment:
1. `CLOUDFLARE_ACCOUNT_ID`: your Cloudflare account ID
2. `CLOUDFLARE_DATABASE_ID`: the Database ID of your D1 databasae
3. `CLOUDFLARE_D1_TOKEN`: the API token created in step 4
6. Run `pnpm drizzle-kit push` to push the database schema to your database
7. Update `apps/app-manager/src/server/auth.ts:32` to add your own GitHub login as an administrator
8. Add the following Cloudflare secrets:
1. Run `pnpm wrangler secret put AUTH_SECRET`
2. Paste a random, securely generated string of characters. I recommend using `openssl rand -base64 32`
3. Run `pnpm wrangler secret put AUTH_GITHUB_ID`
4. Paste your GitHub OAuth client ID from the app created in step 3
5. Run `pnpm wrangler secret put AUTH_GITHUB_SECRET`
6. Paste your GitHub OAuth client secret from the app created in step 3
9. Run `pnpm deploy` to deploy your App Manager
10. Run `cd ../deployment`
11. Run `pnpm deploy` to deploy your Websocket manager
12. Link your app manager and worker to your domain.
1. Make sure the subdomain you choose for your app manager matches the url you put into GitHub
6. Install the SDK in your app code
1. For TypeScript apps of any kind, simply install `@sinkr/core` from JSR.
2. For React apps, install `@sinkr/react` from JSR. This also exports `@sinkr/core` so installing both is not strictly necessary.
3. For Python apps of any kind, install `sinkr` from PyPI
7. Done! Start sending and receiving messages!
2 changes: 1 addition & 1 deletion apps/app-manager/src/server/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const { handlers, signIn, signOut, auth } = NextAuth({
profile(profile) {
let role: "USER" | "ADMIN" = "USER";
switch (profile.login) {
case "wundero": // Change this to your GitHub username
case "Wundero": // Change this to your GitHub username
role = "ADMIN";
break;
default:
Expand Down
35 changes: 35 additions & 0 deletions packages/core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Sinkr

TypeScript SDK for Sinkr.

Server-side usage:
```ts
import { source } from "@sinkr/core";

const mySource = source();
await mySource.sendToChannel("my-channel", "my-event", {
myData: 123;
});
```

Client-side usage:
```ts
import { sink } from "@sinkr/core";

const mySink = sink();
mySink.on("my-event", (eventData) => {
console.log(eventData);
});
```

Module augmentation is recommended to make types stronger.

```ts
declare module "@sinkr/core" {
interface EventMap {
"my-event": {
myData: number;
}
}
}
```
6 changes: 6 additions & 0 deletions packages/core/jsr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@sinkr/core",
"license": "MIT",
"version": "0.1.0",
"exports": "./mod.ts"
}
1 change: 1 addition & 0 deletions packages/core/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./src/index";
14 changes: 14 additions & 0 deletions packages/python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Python SDK for `Sinkr`.

Usage:

```py

from sinkr import SinkrSource


my_source = SinkrSource()
my_source.send_to_channel("my-channel", "my-event", {
"my-data": 123
})
```
6 changes: 4 additions & 2 deletions packages/python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
[tool.poetry]
name = "sinkr"
version = "0.1.0"
description = ""
version = "0.1.1"
description = "Sinkr Python SDK"
authors = ["Wundero <[email protected]>"]
readme = "README.md"
license = "MIT"
repository = "https://github.com/Wundero/sinkr"

[tool.poetry.dependencies]
python = "^3.12"
Expand Down
45 changes: 45 additions & 0 deletions packages/react/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Sinkr

React SDK for Sinkr.

Jsage:
```tsx
import { SinkrProvider, useSinkr } from "@sinkr/react";


// Parent component of some kind, e.g. nextjs root layout
function MyParentComponent() {

return <SinkrProvider url={"wss://my-sinkr-url.com/my-app-id"}>
{children}
</SinkrProvider>
}

// Child component
function MyChildComponent() {
const eventListener = useSinkr();

useEffect(() => {
const unsub = eventListener.on("my-event", (data) => {
console.log(data);
});
return () => {
unsub();
}
}, [eventListener]);
}

```


Module augmentation is recommended to make types stronger.

```ts
declare module "@sinkr/core" {
interface EventMap {
"my-event": {
myData: number;
}
}
}
```
6 changes: 6 additions & 0 deletions packages/react/jsr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@sinkr/react",
"version": "0.1.0",
"license": "MIT",
"exports": "./mod.ts"
}
1 change: 1 addition & 0 deletions packages/react/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./src/index";
2 changes: 2 additions & 0 deletions packages/validators/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Sinkr
Validators for Sinkr. Used by the core app, not recommended to install directly.
6 changes: 6 additions & 0 deletions packages/validators/jsr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@sinkr/validators",
"version": "0.1.0",
"license": "MIT",
"exports": "./mod.ts"
}
1 change: 1 addition & 0 deletions packages/validators/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./src/index";

0 comments on commit 0a091cd

Please sign in to comment.