-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
182 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./src/index"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./src/index"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./src/index"; |