@nostrify/policies 0.36.5 → 0.36.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +24 -2
- package/.turbo/turbo-setup.log +22 -0
- package/.turbo/turbo-test.log +53 -0
- package/AntiDuplicationPolicy.test.ts +54 -41
- package/AntiDuplicationPolicy.ts +7 -3
- package/AnyPolicy.test.ts +15 -14
- package/AnyPolicy.ts +5 -2
- package/AuthorPolicy.test.ts +8 -7
- package/AuthorPolicy.ts +9 -3
- package/CHANGELOG.md +18 -0
- package/DomainPolicy.test.ts +130 -77
- package/DomainPolicy.ts +3 -3
- package/FiltersPolicy.test.ts +14 -7
- package/FiltersPolicy.ts +5 -2
- package/HashtagPolicy.test.ts +25 -14
- package/HashtagPolicy.ts +5 -2
- package/HellthreadPolicy.test.ts +10 -9
- package/HellthreadPolicy.ts +6 -3
- package/InvertPolicy.test.ts +10 -9
- package/InvertPolicy.ts +8 -2
- package/KeywordPolicy.test.ts +18 -12
- package/KeywordPolicy.ts +5 -2
- package/NoOpPolicy.test.ts +8 -7
- package/NoOpPolicy.ts +1 -1
- package/OpenAIPolicy.test.ts +22 -9
- package/OpenAIPolicy.ts +5 -2
- package/PipePolicy.test.ts +18 -17
- package/PipePolicy.ts +5 -2
- package/PowPolicy.test.ts +14 -13
- package/PowPolicy.ts +6 -3
- package/PubkeyBanPolicy.test.ts +15 -8
- package/PubkeyBanPolicy.ts +5 -2
- package/ReadOnlyPolicy.test.ts +9 -8
- package/ReadOnlyPolicy.ts +1 -1
- package/RegexPolicy.test.ts +19 -10
- package/RegexPolicy.ts +5 -2
- package/ReplyBotPolicy.test.ts +43 -27
- package/ReplyBotPolicy.ts +6 -3
- package/SizePolicy.test.ts +9 -8
- package/SizePolicy.ts +6 -2
- package/WhitelistPolicy.test.ts +15 -8
- package/WhitelistPolicy.ts +6 -2
- package/WoTPolicy.test.ts +48 -22
- package/WoTPolicy.ts +5 -2
- package/mod.ts +20 -20
- package/package.json +8 -6
- package/tsconfig.json +3 -1
- package/.turbo/daemon/7bb8240f68f7ad88-turbo.log.2025-07-29 +0 -0
- package/dist/AntiDuplicationPolicy.d.ts +0 -43
- package/dist/AntiDuplicationPolicy.d.ts.map +0 -1
- package/dist/AntiDuplicationPolicy.js +0 -59
- package/dist/AntiDuplicationPolicy.js.map +0 -1
- package/dist/AnyPolicy.d.ts +0 -8
- package/dist/AnyPolicy.d.ts.map +0 -1
- package/dist/AnyPolicy.js +0 -19
- package/dist/AnyPolicy.js.map +0 -1
- package/dist/AuthorPolicy.d.ts +0 -9
- package/dist/AuthorPolicy.d.ts.map +0 -1
- package/dist/AuthorPolicy.js +0 -23
- package/dist/AuthorPolicy.js.map +0 -1
- package/dist/DomainPolicy.d.ts +0 -21
- package/dist/DomainPolicy.d.ts.map +0 -1
- package/dist/DomainPolicy.js +0 -64
- package/dist/DomainPolicy.js.map +0 -1
- package/dist/FiltersPolicy.d.ts +0 -18
- package/dist/FiltersPolicy.d.ts.map +0 -1
- package/dist/FiltersPolicy.js +0 -26
- package/dist/FiltersPolicy.js.map +0 -1
- package/dist/HashtagPolicy.d.ts +0 -16
- package/dist/HashtagPolicy.d.ts.map +0 -1
- package/dist/HashtagPolicy.js +0 -25
- package/dist/HashtagPolicy.js.map +0 -1
- package/dist/HellthreadPolicy.d.ts +0 -14
- package/dist/HellthreadPolicy.d.ts.map +0 -1
- package/dist/HellthreadPolicy.js +0 -19
- package/dist/HellthreadPolicy.js.map +0 -1
- package/dist/InvertPolicy.d.ts +0 -9
- package/dist/InvertPolicy.d.ts.map +0 -1
- package/dist/InvertPolicy.js +0 -20
- package/dist/InvertPolicy.js.map +0 -1
- package/dist/KeywordPolicy.d.ts +0 -16
- package/dist/KeywordPolicy.d.ts.map +0 -1
- package/dist/KeywordPolicy.js +0 -25
- package/dist/KeywordPolicy.js.map +0 -1
- package/dist/NoOpPolicy.d.ts +0 -6
- package/dist/NoOpPolicy.d.ts.map +0 -1
- package/dist/NoOpPolicy.js +0 -8
- package/dist/NoOpPolicy.js.map +0 -1
- package/dist/OpenAIPolicy.d.ts +0 -80
- package/dist/OpenAIPolicy.d.ts.map +0 -1
- package/dist/OpenAIPolicy.js +0 -58
- package/dist/OpenAIPolicy.js.map +0 -1
- package/dist/PipePolicy.d.ts +0 -26
- package/dist/PipePolicy.d.ts.map +0 -1
- package/dist/PipePolicy.js +0 -35
- package/dist/PipePolicy.js.map +0 -1
- package/dist/PowPolicy.d.ts +0 -21
- package/dist/PowPolicy.d.ts.map +0 -1
- package/dist/PowPolicy.js +0 -32
- package/dist/PowPolicy.js.map +0 -1
- package/dist/PubkeyBanPolicy.d.ts +0 -15
- package/dist/PubkeyBanPolicy.d.ts.map +0 -1
- package/dist/PubkeyBanPolicy.js +0 -24
- package/dist/PubkeyBanPolicy.js.map +0 -1
- package/dist/ReadOnlyPolicy.d.ts +0 -6
- package/dist/ReadOnlyPolicy.d.ts.map +0 -1
- package/dist/ReadOnlyPolicy.js +0 -8
- package/dist/ReadOnlyPolicy.js.map +0 -1
- package/dist/RegexPolicy.d.ts +0 -15
- package/dist/RegexPolicy.d.ts.map +0 -1
- package/dist/RegexPolicy.js +0 -22
- package/dist/RegexPolicy.js.map +0 -1
- package/dist/ReplyBotPolicy.d.ts +0 -25
- package/dist/ReplyBotPolicy.d.ts.map +0 -1
- package/dist/ReplyBotPolicy.js +0 -41
- package/dist/ReplyBotPolicy.js.map +0 -1
- package/dist/SizePolicy.d.ts +0 -23
- package/dist/SizePolicy.d.ts.map +0 -1
- package/dist/SizePolicy.js +0 -27
- package/dist/SizePolicy.js.map +0 -1
- package/dist/WhitelistPolicy.d.ts +0 -16
- package/dist/WhitelistPolicy.d.ts.map +0 -1
- package/dist/WhitelistPolicy.js +0 -31
- package/dist/WhitelistPolicy.js.map +0 -1
- package/dist/WoTPolicy.d.ts +0 -26
- package/dist/WoTPolicy.d.ts.map +0 -1
- package/dist/WoTPolicy.js +0 -38
- package/dist/WoTPolicy.js.map +0 -1
- package/dist/mod.d.ts +0 -21
- package/dist/mod.d.ts.map +0 -1
- package/dist/mod.js +0 -21
- package/dist/mod.js.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
> @nostrify/policies@0.36.
|
|
4
|
-
> tsc -p tsconfig.json
|
|
3
|
+
> @nostrify/policies@0.36.6 build /home/sid/repos/nostrify/packages/policies
|
|
4
|
+
> tsc -p tsconfig.json && node ../../esbuild.config.js --package ./
|
|
5
5
|
|
|
6
|
+
|
|
7
|
+
[37mdist/[0m[1mDomainPolicy.js[0m [36m2.1kb[0m
|
|
8
|
+
[37mdist/[0m[1mReplyBotPolicy.js[0m [36m1.4kb[0m
|
|
9
|
+
[37mdist/[0m[1mmod.js[0m [36m1.3kb[0m
|
|
10
|
+
[37mdist/[0m[1mAntiDuplicationPolicy.js[0m [36m1.2kb[0m
|
|
11
|
+
[37mdist/[0m[1mWoTPolicy.js[0m [36m1.0kb[0m
|
|
12
|
+
[37mdist/[0m[1mOpenAIPolicy.js[0m [36m985b [0m
|
|
13
|
+
[37mdist/[0m[1mPowPolicy.js[0m [36m667b [0m
|
|
14
|
+
[37mdist/[0m[1mAuthorPolicy.js[0m [36m640b [0m
|
|
15
|
+
[37mdist/[0m[1mHellthreadPolicy.js[0m [36m494b [0m
|
|
16
|
+
[37mdist/[0m[1mWhitelistPolicy.js[0m [36m490b [0m
|
|
17
|
+
[37mdist/[0m[1mSizePolicy.js[0m [36m453b [0m
|
|
18
|
+
[37mdist/[0m[1mHashtagPolicy.js[0m [36m425b [0m
|
|
19
|
+
[37mdist/[0m[1mAnyPolicy.js[0m [36m412b [0m
|
|
20
|
+
[37mdist/[0m[1mKeywordPolicy.js[0m [36m411b [0m
|
|
21
|
+
[37mdist/[0m[1mFiltersPolicy.js[0m [36m410b [0m
|
|
22
|
+
[37mdist/[0m[1mInvertPolicy.js[0m [36m385b [0m
|
|
23
|
+
[37mdist/[0m[1mPipePolicy.js[0m [36m383b [0m
|
|
24
|
+
[37mdist/[0m[1mPubkeyBanPolicy.js[0m [36m367b [0m
|
|
25
|
+
[37m...and 3 more output files...[0m
|
|
26
|
+
|
|
27
|
+
⚡ [32mDone in 23ms[0m
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
> @nostrify/policies@0.36.5 setup /home/sid/repos/nostrify/packages/policies
|
|
4
|
+
> pnpm i
|
|
5
|
+
|
|
6
|
+
(node:1234136) [DEP0169] DeprecationWarning: `url.parse()` behavior is not standardized and prone to errors that have security implications. Use the WHATWG URL API instead. CVEs are not issued for `url.parse()` vulnerabilities.
|
|
7
|
+
(Use `node --trace-deprecation ...` to show where the warning was created)
|
|
8
|
+
Scope: all 9 workspace projects
|
|
9
|
+
../.. | Progress: resolved [96m1[39m, reused [96m0[39m, downloaded [96m0[39m, added [96m0[39m
|
|
10
|
+
[1A../.. | [32m+1[39m [32m+[39m[0K
|
|
11
|
+
../.. | Progress: resolved [96m1[39m, reused [96m0[39m, downloaded [96m0[39m, added [96m0[39m
|
|
12
|
+
[1A../.. | Progress: resolved [96m1[39m, reused [96m1[39m, downloaded [96m0[39m, added [96m0[39m
|
|
13
|
+
[1A../.. | Progress: resolved [96m1[39m, reused [96m1[39m, downloaded [96m0[39m, added [96m0[39m, done
|
|
14
|
+
[43m[30m WARN [39m[49m Failed to create bin at /home/sid/repos/nostrify/node_modules/.pnpm/node_modules/.bin/semver. ENOENT: no such file or directory, chmod '/home/sid/repos/nostrify/node_modules/.pnpm/node_modules/.bin/semver'
|
|
15
|
+
[43m[30m WARN [39m[49m Failed to create bin at /home/sid/repos/nostrify/node_modules/.pnpm/node_modules/.bin/arborist. ENOENT: no such file or directory, chmod '/home/sid/repos/nostrify/node_modules/.pnpm/node_modules/.bin/arborist'
|
|
16
|
+
[43m[30m WARN [39m[49m Failed to create bin at /home/sid/repos/nostrify/node_modules/.pnpm/node_modules/.bin/vite. ENOENT: no such file or directory, chmod '/home/sid/repos/nostrify/node_modules/.pnpm/node_modules/.bin/vite'
|
|
17
|
+
[43m[30m WARN [39m[49m Failed to create bin at /home/sid/repos/nostrify/node_modules/.pnpm/node_modules/.bin/color-support. ENOENT: no such file or directory, chmod '/home/sid/repos/nostrify/node_modules/.pnpm/node_modules/.bin/color-support'
|
|
18
|
+
[43m[30m WARN [39m[49m Failed to create bin at /home/sid/repos/nostrify/node_modules/.pnpm/node_modules/.bin/uglifyjs. ENOENT: no such file or directory, chmod '/home/sid/repos/nostrify/node_modules/.pnpm/node_modules/.bin/uglifyjs'
|
|
19
|
+
[43m[30m WARN [39m[49m 1 other warnings
|
|
20
|
+
[1A[43m[30m WARN [39m[49m 2 other warnings
|
|
21
|
+
[1A[43m[30m WARN [39m[49m 3 other warnings
|
|
22
|
+
[1A[43m[30m WARN [39m[49m 4 other warnings
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
> @nostrify/policies@0.36.6 test /home/sid/repos/nostrify/packages/policies
|
|
4
|
+
> node --test --test-concurrency=1 "**/*.test.ts"
|
|
5
|
+
|
|
6
|
+
✔ AntiDuplicationPolicy (319.690432ms)
|
|
7
|
+
✔ AntiDuplicationPolicy with deobfuscate (44.807015ms)
|
|
8
|
+
✔ accepts when all policies accept (64.674178ms)
|
|
9
|
+
✔ accepts when some policies reject (8.399958ms)
|
|
10
|
+
✔ rejects when all policies reject (5.373917ms)
|
|
11
|
+
✔ AuthorPolicy (48.081135ms)
|
|
12
|
+
✔ DomainPolicy allows events from authors with a valid nip05 (46.436288ms)
|
|
13
|
+
✔ DomainPolicy rejects events from authors without a kind 0 (4.13101ms)
|
|
14
|
+
✔ DomainPolicy rejects events from authors with a missing nip05 (9.361192ms)
|
|
15
|
+
✔ DomainPolicy rejects events from authors with a malformed nip05 (11.704458ms)
|
|
16
|
+
✔ DomainPolicy rejects events from authors with an invalid nip05 (9.725418ms)
|
|
17
|
+
✔ DomainPolicy rejects events from authors with a blacklisted nip05 domain (12.135733ms)
|
|
18
|
+
✔ DomainPolicy rejects events from authors who aren't on a whitelisted domain (8.181353ms)
|
|
19
|
+
✔ DomainPolicy allows events from authors who are on a whitelisted domain (9.511213ms)
|
|
20
|
+
✔ DomainPolicy rejects events from authors with a subdomain of a blacklisted domain (8.78339ms)
|
|
21
|
+
✔ DomainPolicy rejects events from authors with a deeply nested subdomain of a blacklisted domain (8.255036ms)
|
|
22
|
+
✔ DomainPolicy allows events from authors with similar but not subdomain of blacklisted domain (8.391158ms)
|
|
23
|
+
✔ FiltersPolicy (47.201126ms)
|
|
24
|
+
✔ HashtagPolicy (57.834978ms)
|
|
25
|
+
✔ HellthreadPolicy (47.231857ms)
|
|
26
|
+
✔ InvertPolicy (39.831057ms)
|
|
27
|
+
✔ KeywordPolicy (52.182532ms)
|
|
28
|
+
✔ NoOpPolicy (38.95077ms)
|
|
29
|
+
✔ rejects flagged events (95.404554ms)
|
|
30
|
+
✔ accepts unflagged events (58.128733ms)
|
|
31
|
+
✔ passes events through multiple policies (38.444137ms)
|
|
32
|
+
✔ short-circuits on the first reject (5.71684ms)
|
|
33
|
+
✔ accepts when all policies accept (4.445368ms)
|
|
34
|
+
✔ blocks events without a nonce (37.656948ms)
|
|
35
|
+
✔ accepts event with sufficient POW (0.213227ms)
|
|
36
|
+
✔ PubkeyBanPolicy (52.882068ms)
|
|
37
|
+
✔ ReadOnlyPolicy (37.273237ms)
|
|
38
|
+
✔ RegexPolicy (42.23802ms)
|
|
39
|
+
✔ ReplyBotPolicy blocks replies within the same second (44.754564ms)
|
|
40
|
+
✔ ReplyBotPolicy allows replies after 1 second (9.42384ms)
|
|
41
|
+
✔ ReplyBotPolicy allows replies within the same second from users who are tagged (11.768783ms)
|
|
42
|
+
✔ SizePolicy (47.893399ms)
|
|
43
|
+
✔ WhitelistPolicy (48.551241ms)
|
|
44
|
+
✔ WoTPolicy (74.334084ms)
|
|
45
|
+
✔ WoTPolicy constructor with error store (0.898097ms)
|
|
46
|
+
ℹ tests 40
|
|
47
|
+
ℹ suites 0
|
|
48
|
+
ℹ pass 40
|
|
49
|
+
ℹ fail 0
|
|
50
|
+
ℹ cancelled 0
|
|
51
|
+
ℹ skipped 0
|
|
52
|
+
ℹ todo 0
|
|
53
|
+
ℹ duration_ms 5386.054741
|
|
@@ -1,50 +1,63 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { test } from "node:test";
|
|
2
|
+
import { genEvent } from "@nostrify/nostrify/test";
|
|
3
|
+
import { deepStrictEqual } from "node:assert";
|
|
4
|
+
import { openKv } from "@deno/kv";
|
|
3
5
|
|
|
4
|
-
import { AntiDuplicationPolicy } from
|
|
6
|
+
import { AntiDuplicationPolicy } from "./AntiDuplicationPolicy.ts";
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
await test("AntiDuplicationPolicy", async () => {
|
|
9
|
+
const kv = await openKv(":memory:");
|
|
10
|
+
try {
|
|
11
|
+
const policy = new AntiDuplicationPolicy({ kv });
|
|
12
|
+
const content =
|
|
13
|
+
"Spicy peppermint apricot mediterranean ginger carrot spiced juice edamame hummus";
|
|
8
14
|
|
|
9
|
-
|
|
10
|
-
const content = 'Spicy peppermint apricot mediterranean ginger carrot spiced juice edamame hummus';
|
|
15
|
+
const event1 = genEvent({ kind: 1, content });
|
|
11
16
|
|
|
12
|
-
|
|
17
|
+
deepStrictEqual((await policy.call(event1))[2], true);
|
|
18
|
+
deepStrictEqual((await policy.call(event1))[2], false);
|
|
19
|
+
deepStrictEqual((await policy.call(event1))[2], false);
|
|
13
20
|
|
|
14
|
-
|
|
15
|
-
assertEquals((await policy.call(event1))[2], false);
|
|
16
|
-
assertEquals((await policy.call(event1))[2], false);
|
|
21
|
+
const event2 = genEvent({ kind: 1, content: "a" });
|
|
17
22
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
deepStrictEqual((await policy.call(event2))[2], true);
|
|
24
|
+
deepStrictEqual((await policy.call(event2))[2], true);
|
|
25
|
+
} finally {
|
|
26
|
+
await kv.close();
|
|
27
|
+
}
|
|
23
28
|
});
|
|
24
29
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
30
|
+
await test("AntiDuplicationPolicy with deobfuscate", async () => {
|
|
31
|
+
const kv = await openKv(":memory:");
|
|
32
|
+
try {
|
|
33
|
+
const policy = new AntiDuplicationPolicy({
|
|
34
|
+
kv,
|
|
35
|
+
deobfuscate: ({ content }) => (
|
|
36
|
+
content
|
|
37
|
+
.replace(
|
|
38
|
+
/[\p{Emoji}\p{Emoji_Modifier}\p{Emoji_Component}\p{Emoji_Modifier_Base}\p{Emoji_Presentation}]/gu,
|
|
39
|
+
"",
|
|
40
|
+
)
|
|
41
|
+
.replace(/\s/g, "")
|
|
42
|
+
.toLowerCase()
|
|
43
|
+
),
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const event1 = genEvent({
|
|
47
|
+
kind: 1,
|
|
48
|
+
content:
|
|
49
|
+
"Spicy peppermint apricot mediterranean ginger carrot spiced juice edamame hummus",
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const event2 = genEvent({
|
|
53
|
+
kind: 1,
|
|
54
|
+
content:
|
|
55
|
+
"Spicy 🌶️ peppermint apricot 🍑 mediterranean 🌊 ginger carrot 🥕 spiced 🌶️ juice 🥤 edamame 🌱 hummus ",
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
deepStrictEqual((await policy.call(event1))[2], true);
|
|
59
|
+
deepStrictEqual((await policy.call(event2))[2], false);
|
|
60
|
+
} finally {
|
|
61
|
+
await kv.close();
|
|
62
|
+
}
|
|
50
63
|
});
|
package/AntiDuplicationPolicy.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { NostrEvent, NostrRelayOK, NPolicy } from '@nostrify/types';
|
|
2
|
-
import { Kv, KvKey } from '@deno/kv';
|
|
1
|
+
import type { NostrEvent, NostrRelayOK, NPolicy } from '@nostrify/types';
|
|
2
|
+
import type { Kv, KvKey } from '@deno/kv';
|
|
3
3
|
|
|
4
4
|
/** Policy options for `AntiDuplicationPolicy`. */
|
|
5
5
|
interface AntiDuplicationPolicyOpts {
|
|
@@ -31,7 +31,11 @@ interface AntiDuplicationPolicyOpts {
|
|
|
31
31
|
* ```
|
|
32
32
|
*/
|
|
33
33
|
export class AntiDuplicationPolicy implements NPolicy {
|
|
34
|
-
|
|
34
|
+
private opts: AntiDuplicationPolicyOpts;
|
|
35
|
+
|
|
36
|
+
constructor(opts: AntiDuplicationPolicyOpts) {
|
|
37
|
+
this.opts = opts;
|
|
38
|
+
}
|
|
35
39
|
|
|
36
40
|
async call(event: NostrEvent): Promise<NostrRelayOK> {
|
|
37
41
|
const { id, kind } = event;
|
package/AnyPolicy.test.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { test } from "node:test";
|
|
2
|
+
import { deepStrictEqual } from "node:assert";
|
|
3
|
+
import { finalizeEvent, generateSecretKey } from "nostr-tools";
|
|
3
4
|
|
|
4
|
-
import { AnyPolicy } from
|
|
5
|
-
import { NoOpPolicy } from
|
|
6
|
-
import { ReadOnlyPolicy } from
|
|
5
|
+
import { AnyPolicy } from "./AnyPolicy.ts";
|
|
6
|
+
import { NoOpPolicy } from "./NoOpPolicy.ts";
|
|
7
|
+
import { ReadOnlyPolicy } from "./ReadOnlyPolicy.ts";
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
await test("accepts when all policies accept", async () => {
|
|
9
10
|
const policy = new AnyPolicy([
|
|
10
11
|
new NoOpPolicy(),
|
|
11
12
|
new NoOpPolicy(),
|
|
@@ -13,16 +14,16 @@ Deno.test('accepts when all policies accept', async () => {
|
|
|
13
14
|
]);
|
|
14
15
|
|
|
15
16
|
const event = finalizeEvent(
|
|
16
|
-
{ kind: 1, content:
|
|
17
|
+
{ kind: 1, content: "", tags: [], created_at: 0 },
|
|
17
18
|
generateSecretKey(),
|
|
18
19
|
);
|
|
19
20
|
|
|
20
21
|
const [_, _eventId, ok] = await policy.call(event);
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
deepStrictEqual(ok, true);
|
|
23
24
|
});
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
await test("accepts when some policies reject", async () => {
|
|
26
27
|
const policy = new AnyPolicy([
|
|
27
28
|
new NoOpPolicy(),
|
|
28
29
|
new ReadOnlyPolicy(),
|
|
@@ -30,16 +31,16 @@ Deno.test('accepts when some policies reject', async () => {
|
|
|
30
31
|
]);
|
|
31
32
|
|
|
32
33
|
const event = finalizeEvent(
|
|
33
|
-
{ kind: 1, content:
|
|
34
|
+
{ kind: 1, content: "", tags: [], created_at: 0 },
|
|
34
35
|
generateSecretKey(),
|
|
35
36
|
);
|
|
36
37
|
|
|
37
38
|
const [_, _eventId, ok] = await policy.call(event);
|
|
38
39
|
|
|
39
|
-
|
|
40
|
+
deepStrictEqual(ok, true);
|
|
40
41
|
});
|
|
41
42
|
|
|
42
|
-
|
|
43
|
+
await test("rejects when all policies reject", async () => {
|
|
43
44
|
const policy = new AnyPolicy([
|
|
44
45
|
new ReadOnlyPolicy(),
|
|
45
46
|
new ReadOnlyPolicy(),
|
|
@@ -47,11 +48,11 @@ Deno.test('rejects when all policies reject', async () => {
|
|
|
47
48
|
]);
|
|
48
49
|
|
|
49
50
|
const event = finalizeEvent(
|
|
50
|
-
{ kind: 1, content:
|
|
51
|
+
{ kind: 1, content: "", tags: [], created_at: 0 },
|
|
51
52
|
generateSecretKey(),
|
|
52
53
|
);
|
|
53
54
|
|
|
54
55
|
const [_, _eventId, ok] = await policy.call(event);
|
|
55
56
|
|
|
56
|
-
|
|
57
|
+
deepStrictEqual(ok, false);
|
|
57
58
|
});
|
package/AnyPolicy.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { NostrEvent, NostrRelayOK, NPolicy } from '@nostrify/types';
|
|
1
|
+
import type { NostrEvent, NostrRelayOK, NPolicy } from '@nostrify/types';
|
|
2
2
|
|
|
3
3
|
/** Similar to `PipePolicy`, but passes if at least one policy passes. */
|
|
4
4
|
export class AnyPolicy implements NPolicy {
|
|
5
|
-
|
|
5
|
+
private policies: NPolicy[];
|
|
6
|
+
constructor(policies: NPolicy[]) {
|
|
7
|
+
this.policies = policies;
|
|
8
|
+
}
|
|
6
9
|
|
|
7
10
|
async call(event: NostrEvent, signal?: AbortSignal): Promise<NostrRelayOK> {
|
|
8
11
|
let result: NostrRelayOK = ['OK', event.id, false, 'blocked: no policy passed'];
|
package/AuthorPolicy.test.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { test } from "node:test";
|
|
2
|
+
import { genEvent, MockRelay } from "@nostrify/nostrify/test";
|
|
3
|
+
import { deepStrictEqual } from "node:assert";
|
|
4
|
+
import { generateSecretKey } from "nostr-tools";
|
|
4
5
|
|
|
5
|
-
import { AuthorPolicy } from
|
|
6
|
+
import { AuthorPolicy } from "./AuthorPolicy.ts";
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
await test("AuthorPolicy", async () => {
|
|
8
9
|
const store = new MockRelay();
|
|
9
10
|
const policy = new AuthorPolicy(store);
|
|
10
11
|
|
|
@@ -13,11 +14,11 @@ Deno.test('AuthorPolicy', async () => {
|
|
|
13
14
|
|
|
14
15
|
const [, , ok1] = await policy.call(event);
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
deepStrictEqual(ok1, false);
|
|
17
18
|
|
|
18
19
|
await store.event(genEvent({ kind: 0 }, sk));
|
|
19
20
|
|
|
20
21
|
const [, , ok2] = await policy.call(event);
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
deepStrictEqual(ok2, true);
|
|
23
24
|
});
|
package/AuthorPolicy.ts
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
import { NostrEvent, NostrRelayOK, NPolicy, NStore } from '@nostrify/types';
|
|
1
|
+
import type { NostrEvent, NostrRelayOK, NPolicy, NStore } from '@nostrify/types';
|
|
2
2
|
|
|
3
3
|
/** Rejects events by authors without a kind 0, then optionally applies another policy to the kind 0. */
|
|
4
4
|
export class AuthorPolicy implements NPolicy {
|
|
5
|
-
|
|
5
|
+
private store: NStore;
|
|
6
|
+
private policy?: NPolicy;
|
|
7
|
+
|
|
8
|
+
constructor(store: NStore, policy?: NPolicy) {
|
|
9
|
+
this.store = store;
|
|
10
|
+
this.policy = policy;
|
|
11
|
+
}
|
|
6
12
|
|
|
7
13
|
async call(event: NostrEvent, signal?: AbortSignal): Promise<NostrRelayOK> {
|
|
8
14
|
const author: NostrEvent | undefined = event.kind === 0 ? event : await this.store
|
|
9
15
|
.query([{ kinds: [0], authors: [event.pubkey], limit: 1 }], { signal })
|
|
10
|
-
.then(([event]) => event);
|
|
16
|
+
.then(([event]: NostrEvent[]) => event);
|
|
11
17
|
|
|
12
18
|
if (!author) {
|
|
13
19
|
return ['OK', event.id, false, 'blocked: author is missing a kind 0 event'];
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.36.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- tests should pass now
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @nostrify/nostrify@0.46.9
|
|
10
|
+
- @nostrify/types@0.36.5
|
|
11
|
+
|
|
12
|
+
## 0.36.6
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Get tests passing in CI, use esbuild to build final JS files
|
|
17
|
+
- Updated dependencies
|
|
18
|
+
- @nostrify/nostrify@0.46.8
|
|
19
|
+
- @nostrify/types@0.36.4
|
|
20
|
+
|
|
3
21
|
## 0.36.5
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|