@nostrify/nostrify 0.49.2 → 0.50.0
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 +22 -22
- package/.turbo/turbo-test.log +113 -113
- package/.turbo/turbo-typecheck.log +1 -1
- package/CHANGELOG.md +6 -0
- package/NRelay1.test.ts +32 -0
- package/NRelay1.ts +76 -3
- package/NSchema.ts +45 -0
- package/dist/NRelay1.d.ts +10 -1
- package/dist/NRelay1.d.ts.map +1 -1
- package/dist/NRelay1.js +64 -2
- package/dist/NSchema.d.ts +42 -0
- package/dist/NSchema.d.ts.map +1 -1
- package/dist/NSchema.js +44 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
package/dist/NRelay1.js
CHANGED
|
@@ -11,6 +11,7 @@ class NRelay1 {
|
|
|
11
11
|
controller = new AbortController();
|
|
12
12
|
url;
|
|
13
13
|
opts;
|
|
14
|
+
relayInfoPromise;
|
|
14
15
|
ee = new EventTarget();
|
|
15
16
|
get subscriptions() {
|
|
16
17
|
return [...this.subs.values()];
|
|
@@ -24,6 +25,62 @@ class NRelay1 {
|
|
|
24
25
|
this.socket = this.createSocket();
|
|
25
26
|
this.maybeStartIdleTimer();
|
|
26
27
|
}
|
|
28
|
+
/** Fetch the NIP-11 relay information document. */
|
|
29
|
+
async fetchRelayInfo(opts) {
|
|
30
|
+
try {
|
|
31
|
+
const { fetch: fetchFn = globalThis.fetch } = this.opts;
|
|
32
|
+
const { signal } = opts || {};
|
|
33
|
+
const httpUrl = this.url.replace(
|
|
34
|
+
/^wss?:\/\//,
|
|
35
|
+
(match) => match === "ws://" ? "http://" : "https://"
|
|
36
|
+
);
|
|
37
|
+
const response = await fetchFn(httpUrl, {
|
|
38
|
+
headers: { Accept: "application/nostr+json" },
|
|
39
|
+
signal
|
|
40
|
+
});
|
|
41
|
+
if (!response.ok) {
|
|
42
|
+
this.log({
|
|
43
|
+
level: "warn",
|
|
44
|
+
ns: "relay.nip11",
|
|
45
|
+
status: response.status,
|
|
46
|
+
message: "Failed to fetch relay info"
|
|
47
|
+
});
|
|
48
|
+
return void 0;
|
|
49
|
+
}
|
|
50
|
+
const data = await response.json();
|
|
51
|
+
const result = n.relayInfo().safeParse(data);
|
|
52
|
+
if (!result.success) {
|
|
53
|
+
this.log({
|
|
54
|
+
level: "warn",
|
|
55
|
+
ns: "relay.nip11",
|
|
56
|
+
error: result.error,
|
|
57
|
+
message: "Invalid relay info format"
|
|
58
|
+
});
|
|
59
|
+
return void 0;
|
|
60
|
+
}
|
|
61
|
+
this.log({
|
|
62
|
+
level: "debug",
|
|
63
|
+
ns: "relay.nip11",
|
|
64
|
+
message: "Successfully fetched relay info"
|
|
65
|
+
});
|
|
66
|
+
return result.data;
|
|
67
|
+
} catch (error) {
|
|
68
|
+
this.log({
|
|
69
|
+
level: "warn",
|
|
70
|
+
ns: "relay.nip11",
|
|
71
|
+
error: error instanceof Error ? error : new Error(String(error)),
|
|
72
|
+
message: "Error fetching relay info"
|
|
73
|
+
});
|
|
74
|
+
return void 0;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/** Get the NIP-11 relay information document. Fetches on first call and caches the result. */
|
|
78
|
+
async getRelayInfo(opts) {
|
|
79
|
+
if (!this.relayInfoPromise) {
|
|
80
|
+
this.relayInfoPromise = this.fetchRelayInfo(opts);
|
|
81
|
+
}
|
|
82
|
+
return this.relayInfoPromise;
|
|
83
|
+
}
|
|
27
84
|
/** Create (and open) a WebSocket connection with automatic reconnect. */
|
|
28
85
|
createSocket() {
|
|
29
86
|
const { backoff = new ExponentialBackoff(1e3) } = this.opts;
|
|
@@ -175,7 +232,8 @@ class NRelay1 {
|
|
|
175
232
|
}
|
|
176
233
|
}
|
|
177
234
|
async query(filters, opts) {
|
|
178
|
-
const
|
|
235
|
+
const map = /* @__PURE__ */ new Map();
|
|
236
|
+
const events = new NSet(map);
|
|
179
237
|
const limit = filters.reduce(
|
|
180
238
|
(result, filter) => result + getFilterLimit(filter),
|
|
181
239
|
0
|
|
@@ -189,7 +247,11 @@ class NRelay1 {
|
|
|
189
247
|
break;
|
|
190
248
|
}
|
|
191
249
|
}
|
|
192
|
-
|
|
250
|
+
if (filters.some((filter) => typeof filter.search === "string")) {
|
|
251
|
+
return [...map.values()];
|
|
252
|
+
} else {
|
|
253
|
+
return [...events];
|
|
254
|
+
}
|
|
193
255
|
}
|
|
194
256
|
async event(event, opts) {
|
|
195
257
|
const result = this.once(`ok:${event.id}`, opts?.signal);
|
package/dist/NSchema.d.ts
CHANGED
|
@@ -214,6 +214,48 @@ declare class NSchema {
|
|
|
214
214
|
picture: z.ZodCatch<z.ZodOptional<z.ZodURL>>;
|
|
215
215
|
website: z.ZodCatch<z.ZodOptional<z.ZodURL>>;
|
|
216
216
|
}, z.core.$loose>;
|
|
217
|
+
/** NIP-11 Relay Information Document schema. */
|
|
218
|
+
static relayInfo(): z.ZodObject<{
|
|
219
|
+
name: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
220
|
+
description: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
221
|
+
pubkey: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
222
|
+
contact: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
223
|
+
supported_nips: z.ZodCatch<z.ZodOptional<z.ZodArray<z.ZodNumber>>>;
|
|
224
|
+
software: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
225
|
+
version: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
226
|
+
limitation: z.ZodCatch<z.ZodOptional<z.ZodObject<{
|
|
227
|
+
max_message_length: z.ZodCatch<z.ZodOptional<z.ZodNumber>>;
|
|
228
|
+
max_subscriptions: z.ZodCatch<z.ZodOptional<z.ZodNumber>>;
|
|
229
|
+
max_filters: z.ZodCatch<z.ZodOptional<z.ZodNumber>>;
|
|
230
|
+
max_limit: z.ZodCatch<z.ZodOptional<z.ZodNumber>>;
|
|
231
|
+
max_subid_length: z.ZodCatch<z.ZodOptional<z.ZodNumber>>;
|
|
232
|
+
max_event_tags: z.ZodCatch<z.ZodOptional<z.ZodNumber>>;
|
|
233
|
+
max_content_length: z.ZodCatch<z.ZodOptional<z.ZodNumber>>;
|
|
234
|
+
min_pow_difficulty: z.ZodCatch<z.ZodOptional<z.ZodNumber>>;
|
|
235
|
+
auth_required: z.ZodCatch<z.ZodOptional<z.ZodBoolean>>;
|
|
236
|
+
payment_required: z.ZodCatch<z.ZodOptional<z.ZodBoolean>>;
|
|
237
|
+
restricted_writes: z.ZodCatch<z.ZodOptional<z.ZodBoolean>>;
|
|
238
|
+
created_at_lower_limit: z.ZodCatch<z.ZodOptional<z.ZodNumber>>;
|
|
239
|
+
created_at_upper_limit: z.ZodCatch<z.ZodOptional<z.ZodNumber>>;
|
|
240
|
+
}, z.core.$loose>>>;
|
|
241
|
+
retention: z.ZodCatch<z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
242
|
+
time: z.ZodNullable<z.ZodNumber>;
|
|
243
|
+
count: z.ZodOptional<z.ZodNumber>;
|
|
244
|
+
kinds: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
|
|
245
|
+
}, z.core.$strip>>>>;
|
|
246
|
+
relay_countries: z.ZodCatch<z.ZodOptional<z.ZodArray<z.ZodString>>>;
|
|
247
|
+
language_tags: z.ZodCatch<z.ZodOptional<z.ZodArray<z.ZodString>>>;
|
|
248
|
+
tags: z.ZodCatch<z.ZodOptional<z.ZodArray<z.ZodString>>>;
|
|
249
|
+
posting_policy: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
250
|
+
payments_url: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
251
|
+
fees: z.ZodCatch<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodObject<{
|
|
252
|
+
amount: z.ZodNumber;
|
|
253
|
+
unit: z.ZodString;
|
|
254
|
+
period: z.ZodOptional<z.ZodNumber>;
|
|
255
|
+
kinds: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
|
|
256
|
+
}, z.core.$strip>>>>>;
|
|
257
|
+
icon: z.ZodCatch<z.ZodOptional<z.ZodString>>;
|
|
258
|
+
}, z.core.$loose>;
|
|
217
259
|
/** NIP-46 request content schema. */
|
|
218
260
|
static connectRequest(): z.ZodObject<{
|
|
219
261
|
id: z.ZodString;
|
package/dist/NSchema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NSchema.d.ts","sourceRoot":"","sources":["../NSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD;;;;;;;;;;;GAWG;AACH,cAAM,OAAO;IACX,sEAAsE;IACtE,MAAM,CAAC,EAAE;IAIT,0BAA0B;IAC1B,MAAM,CAAC,KAAK;;;;;;;;;IAoBZ,2BAA2B;IAC3B,MAAM,CAAC,MAAM;;;;;;;;;;;;;;;;;;IA6Bb;;;OAGG;IACH,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;IAS1C,uDAAuD;IACvD,MAAM,CAAC,QAAQ;IAMf,mDAAmD;IACnD,MAAM,CAAC,WAAW;;;;;;;;;IAOlB,iDAAiD;IACjD,MAAM,CAAC,SAAS;;;;;;;;;;;;;;;;;;IAIhB,mDAAmD;IACnD,MAAM,CAAC,WAAW;;;;;;;;;;;;;;;;;;IAIlB,mDAAmD;IACnD,MAAM,CAAC,WAAW;IAIlB,kDAAkD;IAClD,MAAM,CAAC,UAAU;;;;;;;;;IAOjB,2CAA2C;IAC3C,MAAM,CAAC,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAUhB,mDAAmD;IACnD,MAAM,CAAC,UAAU;;;;;;;;;IAQjB,gDAAgD;IAChD,MAAM,CAAC,OAAO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,MAAM,CAAC,UAAU;;;;;;;;;IAOjB,2CAA2C;IAC3C,MAAM,CAAC,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAUhB,mDAAmD;IACnD,MAAM,CAAC,UAAU;;;;;;;;;IAQjB,gDAAgD;IAChD,MAAM,CAAC,OAAO;IASd,kDAAkD;IAClD,MAAM,CAAC,SAAS;IAIhB,oDAAoD;IACpD,MAAM,CAAC,WAAW;IAIlB,oDAAoD;IACpD,MAAM,CAAC,WAAW;IAQlB,kDAAkD;IAClD,MAAM,CAAC,SAAS;IAIhB,mDAAmD;IACnD,MAAM,CAAC,UAAU;;;;IAWjB,2CAA2C;IAC3C,MAAM,CAAC,QAAQ;;;;;;;;;;;;IAYf,6BAA6B;IAC7B,MAAM,CAAC,QAAQ;;;;;;;;;;;;IAef,gDAAgD;IAChD,MAAM,CAAC,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA4ChB,qCAAqC;IACrC,MAAM,CAAC,cAAc;;;;;IAQrB,sCAAsC;IACtC,MAAM,CAAC,eAAe;;;;;IAQtB;;;;;;OAMG;IACH,MAAM,CAAC,IAAI;CAUZ;AAED,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC"}
|
package/dist/NSchema.js
CHANGED
|
@@ -176,6 +176,50 @@ class NSchema {
|
|
|
176
176
|
website: z.url().optional().catch(void 0)
|
|
177
177
|
});
|
|
178
178
|
}
|
|
179
|
+
/** NIP-11 Relay Information Document schema. */
|
|
180
|
+
static relayInfo() {
|
|
181
|
+
return z.looseObject({
|
|
182
|
+
name: z.string().optional().catch(void 0),
|
|
183
|
+
description: z.string().optional().catch(void 0),
|
|
184
|
+
pubkey: NSchema.id().optional().catch(void 0),
|
|
185
|
+
contact: z.string().optional().catch(void 0),
|
|
186
|
+
supported_nips: z.number().int().nonnegative().array().optional().catch(void 0),
|
|
187
|
+
software: z.string().optional().catch(void 0),
|
|
188
|
+
version: z.string().optional().catch(void 0),
|
|
189
|
+
limitation: z.looseObject({
|
|
190
|
+
max_message_length: z.number().int().nonnegative().optional().catch(void 0),
|
|
191
|
+
max_subscriptions: z.number().int().nonnegative().optional().catch(void 0),
|
|
192
|
+
max_filters: z.number().int().nonnegative().optional().catch(void 0),
|
|
193
|
+
max_limit: z.number().int().nonnegative().optional().catch(void 0),
|
|
194
|
+
max_subid_length: z.number().int().nonnegative().optional().catch(void 0),
|
|
195
|
+
max_event_tags: z.number().int().nonnegative().optional().catch(void 0),
|
|
196
|
+
max_content_length: z.number().int().nonnegative().optional().catch(void 0),
|
|
197
|
+
min_pow_difficulty: z.number().int().nonnegative().optional().catch(void 0),
|
|
198
|
+
auth_required: z.boolean().optional().catch(void 0),
|
|
199
|
+
payment_required: z.boolean().optional().catch(void 0),
|
|
200
|
+
restricted_writes: z.boolean().optional().catch(void 0),
|
|
201
|
+
created_at_lower_limit: z.number().int().nonnegative().optional().catch(void 0),
|
|
202
|
+
created_at_upper_limit: z.number().int().nonnegative().optional().catch(void 0)
|
|
203
|
+
}).optional().catch(void 0),
|
|
204
|
+
retention: z.array(z.object({
|
|
205
|
+
time: z.number().int().nullable(),
|
|
206
|
+
count: z.number().int().nonnegative().optional(),
|
|
207
|
+
kinds: z.number().int().nonnegative().array().optional()
|
|
208
|
+
})).optional().catch(void 0),
|
|
209
|
+
relay_countries: z.string().array().optional().catch(void 0),
|
|
210
|
+
language_tags: z.string().array().optional().catch(void 0),
|
|
211
|
+
tags: z.string().array().optional().catch(void 0),
|
|
212
|
+
posting_policy: z.string().optional().catch(void 0),
|
|
213
|
+
payments_url: z.string().optional().catch(void 0),
|
|
214
|
+
fees: z.record(z.string(), z.array(z.object({
|
|
215
|
+
amount: z.number(),
|
|
216
|
+
unit: z.string(),
|
|
217
|
+
period: z.number().int().nonnegative().optional(),
|
|
218
|
+
kinds: z.number().int().nonnegative().array().optional()
|
|
219
|
+
}))).optional().catch(void 0),
|
|
220
|
+
icon: z.string().optional().catch(void 0)
|
|
221
|
+
});
|
|
222
|
+
}
|
|
179
223
|
/** NIP-46 request content schema. */
|
|
180
224
|
static connectRequest() {
|
|
181
225
|
return z.object({
|