Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

Usage

import * as mod from "https://gitlab.com/soapbox-pub/strfry-policies/-/raw/develop/mod.ts";

§Variables

antiDuplicationPolicy

Prevent messages with the exact same content from being submitted repeatedly.

filterPolicy

Reject all events which don't match the filter.

hellthreadPolicy

Reject messages that tag too many participants.

keywordPolicy

Reject events containing any of the strings in its content.

noopPolicy

Minimal sample policy for demonstration purposes. Allows all events through.

openaiPolicy

Passes event content to OpenAI and then rejects flagged events.

powPolicy

Reject events which don't meet Proof-of-Work (NIP-13) criteria.

pubkeyBanPolicy

Ban individual pubkeys from publishing events to the relay.

rateLimitPolicy

Rate-limits users by their IP address.

readOnlyPolicy

This policy rejects all messages.

regexPolicy

Reject events whose content matches the regex.

whitelistPolicy

Allows only the listed pubkeys to post to the relay. All other events are rejected.

§Functions

pipeline

Processes messages through multiple policies.

readStdin

Parse strfy messages from stdin. strfry may batch multiple messages at once.

writeStdout

Writes the output message to stdout.

§Interfaces

AntiDuplication

Policy options for antiDuplicationPolicy.

Event

Nostr event.

Hellthread

Policy options for hellthreadPolicy.

InputMessage

strfry input message from stdin.

OpenAI

Policy options for openaiPolicy.

OutputMessage

strfry output message to be printed as JSONL (minified JSON followed by a newline) to stdout.

POW

Policy options for powPolicy.

RateLimit

Policy options for rateLimitPolicy.

§Type Aliases

Filter
IterablePubkeys

Sync or async iterable of pubkeys, designed for efficiently loading from large files.

OpenAIHandler

Callback for fine control over the policy. It contains the event and the OpenAI moderation data. Implementations should return true to reject the content, and false to accept.

Policy

A policy function in this library. It accepts an input message, opts, and returns an output message.

PolicyTuple

A policy function with opts to run it with. Used by the pipeline.