Skip to content

Commit b9c4b45

Browse files
committed
Initial commit
0 parents  commit b9c4b45

21 files changed

+8950
-0
lines changed

.cargo-ok

Whitespace-only changes.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
dist
3+
.mf

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Webhook Typer
2+
3+
This app runs on [Cloudflare Workers](https://workers.cloudflare.com/) to allow a user to visit
4+
the website and get a unique webhook URL to which they can send events. We then push each event
5+
to the browser immediately parsing the payload structure and providing various language types
6+
and schemas for that given payload.
7+
8+
## Development
9+
10+
```shell
11+
# Install dependencies
12+
$ npm install
13+
# Start local development server with live reload
14+
$ npm run dev
15+
# Run tests
16+
$ npm test
17+
# Run type checking
18+
$ npm run types:check
19+
```

bindings.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
interface Bindings {
2+
SESSIONS: KVNamespace
3+
WEBSOCKETS: DurableObjectNamespace
4+
}

build.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import path from "path";
2+
import { fileURLToPath } from "url";
3+
import { build } from "esbuild";
4+
5+
const __filename = fileURLToPath(import.meta.url);
6+
const __dirname = path.dirname(__filename);
7+
8+
try {
9+
await build({
10+
bundle: true,
11+
sourcemap: true,
12+
format: "esm",
13+
target: "esnext",
14+
entryPoints: [path.join(__dirname, "src", "index.ts")],
15+
outdir: path.join(__dirname, "dist"),
16+
outExtension: { ".js": ".mjs" },
17+
});
18+
} catch {
19+
process.exitCode = 1;
20+
}

client/websocket.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
let websocket = new WebSocket("ws://localhost:8787/ws")
2+
if (!websocket) {
3+
throw new Error("Server didn't accept WebSocket")
4+
}
5+
6+
websocket.addEventListener("open", () => {
7+
console.log("Opened websocket")
8+
})
9+
10+
websocket.addEventListener("message", (message) => {
11+
console.log(message)
12+
})
13+
14+
websocket.addEventListener("close", (message) => {
15+
console.log(`Closed websocket`)
16+
})
17+
18+
websocket.addEventListener("error", (message) => {
19+
console.log(`Something went wrong with the WebSocket`)
20+
21+
// Potentially reconnect the WebSocket connection, by instantiating a
22+
// new WebSocket as seen above, and connecting new events
23+
// websocket = new WebSocket(url)
24+
// websocket.addEventListener(...)
25+
})
26+
27+
// Close WebSocket connection at a later point
28+
const closeConnection = () => websocket.close()

jest.config.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export default {
2+
preset: "ts-jest/presets/default-esm",
3+
globals: {
4+
"ts-jest": {
5+
tsconfig: "test/tsconfig.json",
6+
useESM: true,
7+
},
8+
},
9+
moduleNameMapper: {
10+
"^@/(.*)$": "<rootDir>/src/$1",
11+
"^(\\.{1,2}/.*)\\.js$": "$1",
12+
},
13+
testEnvironment: "miniflare",
14+
};

0 commit comments

Comments
 (0)