2023-03-25 01:17:51 +00:00
|
|
|
/**
|
|
|
|
* strfry input message from stdin.
|
|
|
|
* https://github.com/hoytech/strfry/blob/master/docs/plugins.md#input-messages
|
|
|
|
*/
|
2023-03-24 18:19:35 +00:00
|
|
|
interface InputMessage {
|
2023-03-25 01:17:51 +00:00
|
|
|
/** Either `new` or `lookback`. */
|
2023-03-24 18:19:35 +00:00
|
|
|
type: 'new' | 'lookback';
|
2023-03-25 01:17:51 +00:00
|
|
|
/** The event posted by the client, with all the required fields such as `id`, `pubkey`, etc. */
|
2023-03-24 18:19:35 +00:00
|
|
|
event: Event;
|
2023-03-25 01:17:51 +00:00
|
|
|
/** Unix timestamp of when this event was received by the relay. */
|
2023-03-24 18:19:35 +00:00
|
|
|
receivedAt: number;
|
2023-03-25 01:17:51 +00:00
|
|
|
/** Where this event came from. Typically will be `IP4` or `IP6`, but in lookback can also be `Import`, `Stream`, or `Sync`. */
|
2023-03-24 18:19:35 +00:00
|
|
|
sourceType: 'IP4' | 'IP6' | 'Import' | 'Stream' | 'Sync';
|
2023-03-25 01:17:51 +00:00
|
|
|
/** Specifics of the event's source. Either an IP address or a relay URL (for stream/sync). */
|
2023-03-24 18:19:35 +00:00
|
|
|
sourceInfo: string;
|
|
|
|
}
|
|
|
|
|
2023-03-25 01:17:51 +00:00
|
|
|
/**
|
|
|
|
* strfry output message to be printed as JSONL (minified JSON followed by a newline) to stdout.
|
|
|
|
* https://github.com/hoytech/strfry/blob/master/docs/plugins.md#output-messages
|
|
|
|
*/
|
2023-03-24 18:19:35 +00:00
|
|
|
interface OutputMessage {
|
2023-03-25 01:17:51 +00:00
|
|
|
/** The event ID taken from the `event.id` field of the input message. */
|
2023-03-24 18:19:35 +00:00
|
|
|
id: string;
|
2023-03-25 01:17:51 +00:00
|
|
|
/** Either `accept`, `reject`, or `shadowReject`. */
|
2023-03-24 18:19:35 +00:00
|
|
|
action: 'accept' | 'reject' | 'shadowReject';
|
2023-03-25 01:17:51 +00:00
|
|
|
/** The NIP-20 response message to be sent to the client. Only used for `reject`. */
|
2023-03-24 18:19:35 +00:00
|
|
|
msg: string;
|
|
|
|
}
|
|
|
|
|
2023-03-25 01:17:51 +00:00
|
|
|
/**
|
|
|
|
* Nostr event.
|
|
|
|
* https://github.com/nostr-protocol/nips/blob/master/01.md
|
|
|
|
*/
|
2023-03-24 18:19:35 +00:00
|
|
|
interface Event<K extends number = number> {
|
|
|
|
id: string;
|
|
|
|
sig: string;
|
|
|
|
kind: K;
|
|
|
|
tags: string[][];
|
|
|
|
pubkey: string;
|
|
|
|
content: string;
|
|
|
|
created_at: number;
|
|
|
|
}
|
|
|
|
|
2023-03-25 01:17:51 +00:00
|
|
|
/**
|
|
|
|
* A policy function in this library.
|
|
|
|
* It accepts an input message, opts, and returns an output message.
|
|
|
|
*/
|
2023-03-25 00:55:58 +00:00
|
|
|
type Policy<Opts = unknown> = (msg: InputMessage, opts?: Opts) => Promise<OutputMessage> | OutputMessage;
|
2023-03-24 19:36:11 +00:00
|
|
|
|
|
|
|
export type { Event, InputMessage, OutputMessage, Policy };
|