New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

minitel-cloudflare-worker

Package Overview
Dependencies
Maintainers
0
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

minitel-cloudflare-worker - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

3

dist/examples/helloworld.d.ts

@@ -1,1 +0,2 @@

export {};
declare const _default: Promise<void>;
export default _default;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const minitel_standalone_1 = require("minitel-standalone");
const ws_duplex_bridge_1 = require("ws-duplex-bridge");
const __1 = require("..");
(0, __1.createMinipaviHandler)((ws) => {
const stream = new ws_duplex_bridge_1.DuplexBridge(ws, { decodeStrings: false });
exports.default = (0, __1.createMinipaviHandler)((stream) => {
const minitel = new minitel_standalone_1.Minitel(stream, {});
minitel.appendChild(new minitel_standalone_1.TextNode('Hello world!', {}, minitel));
minitel.renderToStream();
setTimeout(() => stream.end(), 10000);
}, {
host: '0.0.0.0',
port: 4545,
setTimeout(() => stream.end(), 10_000);
}).then(() => console.log('MiniPavi handler ready!'));

@@ -1,14 +0,10 @@

import { FastifyInstance, FastifyServerFactory } from 'fastify';
import { WebSocket } from 'ws';
import { Duplex } from 'node:stream';
interface MinipaviHandlerOptions {
version?: string;
port: number;
host: string;
providePavi?: boolean;
provideDirectUrl?: boolean;
https?: boolean;
serverFactory?: FastifyServerFactory;
withFastify?: (server: FastifyInstance) => any;
}
export declare function createMinipaviHandler(minitelFactory: (ws: WebSocket) => any, options: MinipaviHandlerOptions): Promise<void>;
export declare function createMinipaviHandler(minitelFactory: (ws: Duplex, req: Request) => any, options?: MinipaviHandlerOptions): Promise<{
fetch(request: Request): Promise<Response | undefined>;
}>;
export {};
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createMinipaviHandler = createMinipaviHandler;
const http_1 = __importDefault(require("http"));
const fastify_1 = require("fastify");
const zod_1 = require("zod");
const ws_1 = require("ws");
async function createMinipaviHandler(minitelFactory, options) {
if (!options.port)
throw new Error('Port is required');
if (!options.host)
throw new Error('Host is required');
const node_stream_1 = require("node:stream");
const paviSchema = zod_1.z.object({
PAVI: zod_1.z.object({
version: zod_1.z.string().regex(/^(\d+\.)*\d+$/g),
uniqueId: zod_1.z.string().regex(/^\d+$/g),
remoteAddr: zod_1.z.string(),
typesocket: zod_1.z.enum(['websocketssl', 'websocket', 'other']),
versionminitel: zod_1.z.string().regex(/^\x01.{3}\x04$/g),
content: zod_1.z.array(zod_1.z.string()),
context: zod_1.z.any(),
fctn: zod_1.z.enum([
'ENVOI',
'SUITE',
'RETOUR',
'ANNULATION',
'CORRECTION',
'GUIDE',
'REPETITION',
'SOMMAIRE',
'CNX',
'FIN',
'DIRECT',
'DIRECTCNX',
'DIRECTCALLFAILED',
'DIRECTCALLENDED',
'BGCALL',
'BGCALL-SIMU',
]),
}),
URLPARAMS: zod_1.z.record(zod_1.z.string(), zod_1.z.string()).optional(),
});
async function createMinipaviHandler(minitelFactory, options = {}) {
const fullOptions = {

@@ -20,106 +41,79 @@ version: '1.0',

provideDirectUrl: false,
serverFactory: (handler, opts) => {
return http_1.default.createServer((req, res) => {
handler(req, res);
});
},
withFastify: () => { },
https: false,
...options,
};
const server = (0, fastify_1.fastify)({
serverFactory: (...args) => {
const server = fullOptions.serverFactory(...args);
const wss = new ws_1.WebSocketServer({ server });
wss.on('connection', minitelFactory);
return server;
return {
async fetch(request) {
const reqUrl = new URL(request.url);
const upgradeHeader = request.headers.get('Upgrade');
if (reqUrl.pathname === '/websocket') {
if (!upgradeHeader || upgradeHeader !== 'websocket') {
return new Response('Upgrade required', { status: 426 });
}
const webSocketPair = new WebSocketPair();
const client = webSocketPair[0];
const server = webSocketPair[1];
(async () => {
server.accept();
const stream = new node_stream_1.Duplex();
server.addEventListener('message', (event) => stream.write(event.data));
stream.on('data', (data) => server.send(data));
server.addEventListener('close', () => stream.end());
stream.on('close', () => server.close());
server.addEventListener('open', () => minitelFactory(stream, request));
})();
return new Response(null, {
status: 101,
webSocket: client,
});
}
if (request.method !== 'POST') {
return new Response('Method not allowed', { status: 405 });
}
const { success, data, error } = paviSchema.safeParse(await request.json());
if (!success) {
return new Response(`Malformed request: ${JSON.stringify(error)}`, {
status: 400,
});
}
if (reqUrl.pathname === '/') {
const newParams = new URLSearchParams();
if (fullOptions.providePavi)
newParams.append('pavi', JSON.stringify(data.PAVI));
if (fullOptions.provideDirectUrl && 'DIRECTURL' in data)
newParams.append('directUrl', JSON.stringify(data.DIRECTURL));
return new Response(JSON.stringify({
version: fullOptions.version,
content: '',
context: '',
echo: 'off',
next: `https://${reqUrl.hostname}/disconnect`,
directcall: 'no',
COMMAND: {
name: 'connectToWs',
param: {
key: 'Same host <https://npmjs.com/packages/minitel-minipavi>',
host: reqUrl.hostname,
path: `/websocket${newParams.toString()}`,
echo: 'off',
case: 'lower',
proto: 'wss',
},
},
}), { headers: { 'Content-Type': 'application/json' } });
}
else if (reqUrl.pathname === '/disconnect') {
return new Response(JSON.stringify({
version: fullOptions.version,
content: '',
context: '',
echo: 'off',
next: `https://${reqUrl.hostname}/disconnect`,
directcall: 'no',
COMMAND: {
name: 'libCnx',
},
}), { headers: { 'Content-Type': 'application/json' } });
}
},
});
const paviSchema = zod_1.z.object({
PAVI: zod_1.z.object({
version: zod_1.z.string().regex(/^(\d+\.)*\d+$/g),
uniqueId: zod_1.z.string().regex(/^\d+$/g),
remoteAddr: zod_1.z.string(),
typesocket: zod_1.z.enum(['websocketssl', 'websocket', 'other']),
versionminitel: zod_1.z.string().regex(/^\x01.{3}\x04$/g),
content: zod_1.z.array(zod_1.z.string()),
context: zod_1.z.any(),
fctn: zod_1.z.enum([
'ENVOI',
'SUITE',
'RETOUR',
'ANNULATION',
'CORRECTION',
'GUIDE',
'REPETITION',
'SOMMAIRE',
'CNX',
'FIN',
'DIRECT',
'DIRECTCNX',
'DIRECTCALLFAILED',
'DIRECTCALLENDED',
'BGCALL',
'BGCALL-SIMU',
]),
}),
URLPARAMS: zod_1.z.record(zod_1.z.string(), zod_1.z.string()).optional(),
});
server.post('/', (req, res) => {
const { success, data, error } = paviSchema.safeParse(req.body);
if (!success)
return res
.status(400)
.send(`Malformed request: ${JSON.stringify(error)}`);
const newParams = new URLSearchParams();
if (fullOptions.providePavi)
newParams.append('pavi', JSON.stringify(data.PAVI));
if (fullOptions.provideDirectUrl && 'DIRECTURL' in data)
newParams.append('directUrl', JSON.stringify(data.DIRECTURL));
res.header('Content-Type', 'application/json');
return res.send(JSON.stringify({
version: fullOptions.version,
content: '',
context: '',
echo: 'off',
next: `http://${req.hostname}/disconnect`,
directcall: 'no',
COMMAND: {
name: 'connectToWs',
param: {
key: 'Same host <https://npmjs.com/packages/minitel-minipavi>',
host: req.hostname,
path: `/websocket${newParams.toString()}`,
echo: 'off',
case: 'lower',
proto: fullOptions.https ? 'wss' : 'ws',
},
},
}));
});
server.post('/disconnect', (req, res) => {
const { success, data, error } = paviSchema.safeParse(req.body);
if (!success)
return res
.status(400)
.send(`Malformed request: ${JSON.stringify(error)}`);
res.send(JSON.stringify({
version: fullOptions.version,
content: '',
context: '',
echo: 'off',
next: `http://${req.hostname}/disconnect`,
directcall: 'no',
COMMAND: {
name: 'libCnx',
},
}));
});
await fullOptions.withFastify(server);
return new Promise((resolve) => {
server.listen({
port: fullOptions.port,
host: fullOptions.host,
}, () => resolve());
});
};
}
{
"name": "minitel-cloudflare-worker",
"version": "1.0.0",
"version": "1.1.0",
"description": "A cloudflare worker for access through MiniPAVI",

@@ -24,5 +24,3 @@ "main": "dist/index.js",

"dependencies": {
"fastify": "^4.28.1",
"minitel-standalone": "^1.9.4",
"ws": "^8.18.0",
"zod": "^3.23.8"

@@ -32,7 +30,5 @@ },

"@cloudflare/workers-types": "^4.20240725.0",
"@types/ws": "^8.5.11",
"prettier": "3.3.3",
"typescript": "^5.5.4",
"ws-duplex-bridge": "^1.0.1"
"typescript": "^5.5.4"
}
}

@@ -22,3 +22,2 @@ # `minitel-cloudflare-worker`

import { Minitel, TextNode } from 'minitel-standalone';
import { DuplexBridge } from 'ws-duplex-bridge';
import { createMinipaviHandler } from 'minitel-cloudflare-worker';

@@ -35,6 +34,2 @@

},
{
host: '0.0.0.0',
port: 4545,
},
).then(() => console.log('MiniPavi handler ready!'));

@@ -41,0 +36,0 @@ ```

import { Minitel, TextNode } from 'minitel-standalone';
import { DuplexBridge } from 'ws-duplex-bridge';
import { createMinipaviHandler } from '..';
createMinipaviHandler(
(ws) => {
const stream = new DuplexBridge(ws, { decodeStrings: false });
export default createMinipaviHandler(
(stream) => {
const minitel = new Minitel(stream, {});

@@ -15,6 +13,2 @@ minitel.appendChild(new TextNode('Hello world!', {}, minitel));

},
{
host: '0.0.0.0',
port: 4545,
},
).then(() => console.log('MiniPavi handler ready!'));

@@ -43,3 +43,3 @@ import { z } from 'zod';

minitelFactory: (ws: Duplex, req: Request) => any,
options: MinipaviHandlerOptions,
options: MinipaviHandlerOptions = {},
) {

@@ -46,0 +46,0 @@ const fullOptions: Required<MinipaviHandlerOptions> = {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc