Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .github/workflows/pingrip.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Pingrip

on:
push:
branches:
- master
paths:
- 'pingrip/**'

pull_request:
paths:
- 'pingrip/**'
- .github/workflows/pingrip.yml

workflow_dispatch: {}

defaults:
run:
working-directory: ./pingrip

permissions:
id-token: write
contents: read

jobs:
pingrip:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3.0.0
with:
version: 8.6.2
- uses: actions/setup-node@v3
with:
node-version: '22.17.0'
check-latest: true
- run: pnpm install --frozen-lockfile
- run: pnpm build
- run: pnpm check:type
- run: pnpm check:format
- run: pnpm test
- name: Publish
if: github.ref == 'refs/heads/master' || github.event_name == 'workflow_dispatch'
uses: botpress/gh-actions/publish-if-not-exists@master
with:
path: './pingrip'

22 changes: 22 additions & 0 deletions pingrip/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# based on https://gist.github.com/thinkricardo/74f37d82b686de371b0853a5d66d559c

# ignore all files
*

# include all folders
!**/

# include files to format
!*.ts
!*.tsx
!*.json
!*.yaml
!*.yml
!*.md

# exclusions
# **/*.d.ts
pnpm-lock.yaml
gen
dist
.botpress
56 changes: 56 additions & 0 deletions pingrip/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# PinGrip

PinGrip is an implementation of the [Pushpin](https://pushpin.org) GRIP for WebSocket-over-HTTP tunneling. It provides
utilities for serializing and parsing WebSocket messages in the GRIP protocol format, and includes a fluent
ResponseBuilder API for constructing WebSocket responses with support for opening/closing connections, sending
text/binary messages, subscribing to channels, and configuring keep-alive behavior.

## Usage

```js
import * as pingrip from '@bpinternal/pingrip'

const grip = new pingrip.outputs.GripPublisher({
signalUrl: 'http://localhost:7999',
})

function onDataUpdate(channels: string[]) {
const payload = "myPayloadToSendToAClient"
grip.publish(channels, payload)
}

/**
* A handler that receive requests and generate responses
*/
function handler(body: string) {
const channels = ['channel1', 'channel2'] // extract channels from the body for example
const { messages: _messages, error } = pingrip.messages.safeParse(Buffer.from(body))
if (error) {
console.error(error)
return
}
for (const message of _messages) {
if (message.type === 'open') {
const response = new pingrip.outputs.ResponseBuilder()
.open()
.subscribe(channels)
.keepAlive('ping', 30)
.toResponse()
return response
}
if (message.type === 'close') {
const response = new pingrip.outputs.ResponseBuilder()
.close(message.code)
.unsubscribe(channels)
.toResponse()
return response
}
}
}
```

## Disclaimer ⚠️

This package is published under the `@bpinternal` organization. All packages of this organization are meant to be used by the [Botpress](https://github.com/botpress/botpress) team internally and are not meant for our community. Since the packages are catered to our own use-cases, they might have less stable APIs, receive breaking changes without much warning, have minimal documentation and lack community-focused support. However, these packages were still left intentionally public for an important reason : We Love Open-Source. Therefore, if you wish to install or fork this package feel absolutly free to do it. We strongly recommend that you tag your versions properly.

The Botpress Engineering team.
43 changes: 43 additions & 0 deletions pingrip/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "@bpinternal/pingrip",
"version": "0.1.0",
"description": "Pushpin GRIP Websocket-over-HTTP",
"keywords": [
"pushpin",
"grip",
"websocket"
],
"author": "Botpress, Inc.",
"license": "MIT",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"repository": {
"url": "https://github.com/botpress/packages"
},
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
}
},
"scripts": {
"build": "tsup src/index.ts --dts --format cjs,esm --clean",
"check:format": "prettier --check .",
"fix:format": "prettier --write .",
"check:type": "tsc --noEmit",
"test": "vitest"
},
"devDependencies": {
"@types/node": "^24.10.1",
"ts-node": "^10.9.2",
"typescript": "^5.9.3",
"tsup": "8.3.5",
"vitest": "^4.0.13",
"prettier": "3.4.1"
},
"dependencies": {
"axios": "^1.13.2"
}
}
Loading