mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
store schemas alongside registry
This commit is contained in:
parent
5a6e7c5a11
commit
abe3c44891
1 changed files with 17 additions and 0 deletions
|
|
@ -17,6 +17,7 @@ import {
|
||||||
} from '@nostrify/policies';
|
} from '@nostrify/policies';
|
||||||
import { FieldItem, zodSchemaToFields } from './parameters.ts';
|
import { FieldItem, zodSchemaToFields } from './parameters.ts';
|
||||||
import { NPolicy, NStore } from '@nostrify/types';
|
import { NPolicy, NStore } from '@nostrify/types';
|
||||||
|
import { z } from 'zod';
|
||||||
import {
|
import {
|
||||||
AntiDuplicationPolicyOpts,
|
AntiDuplicationPolicyOpts,
|
||||||
AntiDuplicationPolicyOptsSchema,
|
AntiDuplicationPolicyOptsSchema,
|
||||||
|
|
@ -41,6 +42,7 @@ export interface PolicyItem {
|
||||||
name: string;
|
name: string;
|
||||||
parameters: Record<string, FieldItem>;
|
parameters: Record<string, FieldItem>;
|
||||||
description: string;
|
description: string;
|
||||||
|
schema: z.ZodSchema;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PolicyRegistryOpts {
|
export interface PolicyRegistryOpts {
|
||||||
|
|
@ -66,6 +68,7 @@ export class PolicyRegistry {
|
||||||
description: 'Prevent messages with the exact same content from being submitted repeatedly.',
|
description: 'Prevent messages with the exact same content from being submitted repeatedly.',
|
||||||
name: 'Deduplicate messages',
|
name: 'Deduplicate messages',
|
||||||
parameters: zodSchemaToFields(AntiDuplicationPolicyOptsSchema),
|
parameters: zodSchemaToFields(AntiDuplicationPolicyOptsSchema),
|
||||||
|
schema: AntiDuplicationPolicyOptsSchema,
|
||||||
},
|
},
|
||||||
'AuthorPolicy': {
|
'AuthorPolicy': {
|
||||||
instantiate: () => {
|
instantiate: () => {
|
||||||
|
|
@ -74,6 +77,7 @@ export class PolicyRegistry {
|
||||||
description: 'Rejects events by authors without a kind 0 event associated with their pubkey.',
|
description: 'Rejects events by authors without a kind 0 event associated with their pubkey.',
|
||||||
name: 'Block events without associated profiles',
|
name: 'Block events without associated profiles',
|
||||||
parameters: {},
|
parameters: {},
|
||||||
|
schema: z.object({}), // Empty schema since no params are used
|
||||||
},
|
},
|
||||||
'DomainPolicy': {
|
'DomainPolicy': {
|
||||||
instantiate: (params) => {
|
instantiate: (params) => {
|
||||||
|
|
@ -83,6 +87,7 @@ export class PolicyRegistry {
|
||||||
description: 'Ban events by pubkeys without a valid NIP-05 domain. Domains can also be whitelisted/blacklisted',
|
description: 'Ban events by pubkeys without a valid NIP-05 domain. Domains can also be whitelisted/blacklisted',
|
||||||
name: 'Filter by NIP-05',
|
name: 'Filter by NIP-05',
|
||||||
parameters: zodSchemaToFields(DomainPolicyOptsSchema),
|
parameters: zodSchemaToFields(DomainPolicyOptsSchema),
|
||||||
|
schema: DomainPolicyOptsSchema,
|
||||||
},
|
},
|
||||||
'FiltersPolicy': {
|
'FiltersPolicy': {
|
||||||
instantiate: (params) => {
|
instantiate: (params) => {
|
||||||
|
|
@ -101,6 +106,7 @@ export class PolicyRegistry {
|
||||||
description: 'Only allow events matching a given Nostr filter',
|
description: 'Only allow events matching a given Nostr filter',
|
||||||
name: 'Filter by Nostr filter',
|
name: 'Filter by Nostr filter',
|
||||||
parameters: zodSchemaToFields(FiltersPolicyOptsSchema),
|
parameters: zodSchemaToFields(FiltersPolicyOptsSchema),
|
||||||
|
schema: FiltersPolicyOptsSchema,
|
||||||
},
|
},
|
||||||
'HashtagPolicy': {
|
'HashtagPolicy': {
|
||||||
instantiate: (params) => {
|
instantiate: (params) => {
|
||||||
|
|
@ -110,6 +116,7 @@ export class PolicyRegistry {
|
||||||
description: 'Ban events containing the specified hashtags',
|
description: 'Ban events containing the specified hashtags',
|
||||||
name: 'Ban hashtags',
|
name: 'Ban hashtags',
|
||||||
parameters: zodSchemaToFields(HashtagPolicyOptsSchema),
|
parameters: zodSchemaToFields(HashtagPolicyOptsSchema),
|
||||||
|
schema: HashtagPolicyOptsSchema,
|
||||||
},
|
},
|
||||||
'HellthreadPolicy': {
|
'HellthreadPolicy': {
|
||||||
instantiate: (params) => {
|
instantiate: (params) => {
|
||||||
|
|
@ -121,6 +128,7 @@ export class PolicyRegistry {
|
||||||
description: "Prevent 'hellthreads' - notes that tag hundreds of people to cause a nuisance and server load.",
|
description: "Prevent 'hellthreads' - notes that tag hundreds of people to cause a nuisance and server load.",
|
||||||
name: 'Limit events with excessive mentions',
|
name: 'Limit events with excessive mentions',
|
||||||
parameters: zodSchemaToFields(HellthreadPolicyOptsSchema),
|
parameters: zodSchemaToFields(HellthreadPolicyOptsSchema),
|
||||||
|
schema: HellthreadPolicyOptsSchema,
|
||||||
},
|
},
|
||||||
'KeywordPolicy': {
|
'KeywordPolicy': {
|
||||||
instantiate: (params) => {
|
instantiate: (params) => {
|
||||||
|
|
@ -130,6 +138,7 @@ export class PolicyRegistry {
|
||||||
description: 'Ban events that contain specified keywords.',
|
description: 'Ban events that contain specified keywords.',
|
||||||
name: 'Block certain words',
|
name: 'Block certain words',
|
||||||
parameters: zodSchemaToFields(KeywordPolicyOptsSchema),
|
parameters: zodSchemaToFields(KeywordPolicyOptsSchema),
|
||||||
|
schema: KeywordPolicyOptsSchema,
|
||||||
},
|
},
|
||||||
'OpenAIPolicy': {
|
'OpenAIPolicy': {
|
||||||
instantiate: (params) => {
|
instantiate: (params) => {
|
||||||
|
|
@ -141,6 +150,7 @@ export class PolicyRegistry {
|
||||||
description: "Use OpenAI moderation integration to block posts that don't meet your community guidelines.",
|
description: "Use OpenAI moderation integration to block posts that don't meet your community guidelines.",
|
||||||
name: 'Use OpenAI moderation',
|
name: 'Use OpenAI moderation',
|
||||||
parameters: zodSchemaToFields(OpenAIPolicyOptsSchema),
|
parameters: zodSchemaToFields(OpenAIPolicyOptsSchema),
|
||||||
|
schema: OpenAIPolicyOptsSchema,
|
||||||
},
|
},
|
||||||
'PowPolicy': {
|
'PowPolicy': {
|
||||||
instantiate: (params) => {
|
instantiate: (params) => {
|
||||||
|
|
@ -152,6 +162,7 @@ export class PolicyRegistry {
|
||||||
description: 'Use proof-of-work to limit events from spammers.',
|
description: 'Use proof-of-work to limit events from spammers.',
|
||||||
name: 'Require proof-of-work for events',
|
name: 'Require proof-of-work for events',
|
||||||
parameters: zodSchemaToFields(PowPolicyOptsSchema),
|
parameters: zodSchemaToFields(PowPolicyOptsSchema),
|
||||||
|
schema: PowPolicyOptsSchema,
|
||||||
},
|
},
|
||||||
'PubkeyBanPolicy': {
|
'PubkeyBanPolicy': {
|
||||||
instantiate: (params) => {
|
instantiate: (params) => {
|
||||||
|
|
@ -161,6 +172,7 @@ export class PolicyRegistry {
|
||||||
description: 'Ban events from certain pubkeys',
|
description: 'Ban events from certain pubkeys',
|
||||||
name: 'Ban certain pubkeys',
|
name: 'Ban certain pubkeys',
|
||||||
parameters: zodSchemaToFields(PubkeyBanPolicyOptsSchema),
|
parameters: zodSchemaToFields(PubkeyBanPolicyOptsSchema),
|
||||||
|
schema: PubkeyBanPolicyOptsSchema,
|
||||||
},
|
},
|
||||||
'RegexPolicy': {
|
'RegexPolicy': {
|
||||||
instantiate: (params) => {
|
instantiate: (params) => {
|
||||||
|
|
@ -170,6 +182,7 @@ export class PolicyRegistry {
|
||||||
description: 'Ban events that match a certain regular expression.',
|
description: 'Ban events that match a certain regular expression.',
|
||||||
name: 'Filter by regex',
|
name: 'Filter by regex',
|
||||||
parameters: zodSchemaToFields(RegexPolicyOptsSchema),
|
parameters: zodSchemaToFields(RegexPolicyOptsSchema),
|
||||||
|
schema: RegexPolicyOptsSchema,
|
||||||
},
|
},
|
||||||
'ReplyBotPolicy': {
|
'ReplyBotPolicy': {
|
||||||
instantiate: (params) => {
|
instantiate: (params) => {
|
||||||
|
|
@ -182,6 +195,7 @@ export class PolicyRegistry {
|
||||||
description: 'Block events that reply too quickly to other events.',
|
description: 'Block events that reply too quickly to other events.',
|
||||||
name: 'Block reply spambots',
|
name: 'Block reply spambots',
|
||||||
parameters: zodSchemaToFields(ReplyBotPolicyOptsSchema),
|
parameters: zodSchemaToFields(ReplyBotPolicyOptsSchema),
|
||||||
|
schema: ReplyBotPolicyOptsSchema,
|
||||||
},
|
},
|
||||||
'SizePolicy': {
|
'SizePolicy': {
|
||||||
instantiate: (params) => {
|
instantiate: (params) => {
|
||||||
|
|
@ -193,6 +207,7 @@ export class PolicyRegistry {
|
||||||
description: 'Restrict events that are too big in size.',
|
description: 'Restrict events that are too big in size.',
|
||||||
name: 'Block events by size',
|
name: 'Block events by size',
|
||||||
parameters: zodSchemaToFields(SizePolicyOptsSchema),
|
parameters: zodSchemaToFields(SizePolicyOptsSchema),
|
||||||
|
schema: SizePolicyOptsSchema,
|
||||||
},
|
},
|
||||||
'WhitelistPolicy': {
|
'WhitelistPolicy': {
|
||||||
instantiate: (params) => {
|
instantiate: (params) => {
|
||||||
|
|
@ -202,6 +217,7 @@ export class PolicyRegistry {
|
||||||
description: 'Allow only whitelisted pubkeys to post. All other events are rejected.',
|
description: 'Allow only whitelisted pubkeys to post. All other events are rejected.',
|
||||||
name: 'Whitelist people',
|
name: 'Whitelist people',
|
||||||
parameters: zodSchemaToFields(WhitelistPolicyOptsSchema),
|
parameters: zodSchemaToFields(WhitelistPolicyOptsSchema),
|
||||||
|
schema: WhitelistPolicyOptsSchema,
|
||||||
},
|
},
|
||||||
'WoTPolicy': {
|
'WoTPolicy': {
|
||||||
instantiate: (params) => {
|
instantiate: (params) => {
|
||||||
|
|
@ -214,6 +230,7 @@ export class PolicyRegistry {
|
||||||
description: 'Use a web-of-trust to only allow users a certain distance from trusted users to publish posts.',
|
description: 'Use a web-of-trust to only allow users a certain distance from trusted users to publish posts.',
|
||||||
name: 'Build a web-of-trust',
|
name: 'Build a web-of-trust',
|
||||||
parameters: zodSchemaToFields(WoTPolicyOptsSchema),
|
parameters: zodSchemaToFields(WoTPolicyOptsSchema),
|
||||||
|
schema: WoTPolicyOptsSchema,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue