@threenine/nuxstr-comments 1.0.12 → 1.0.14

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/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@threenine/nuxstr-comments",
3
3
  "configKey": "nuxstrComments",
4
- "version": "1.0.12",
4
+ "version": "1.0.14",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -8,7 +8,7 @@ const module = defineNuxtModule({
8
8
  },
9
9
  // Default configuration options of the Nuxt module
10
10
  defaults: {
11
- relays: ["wss://relay.damus.io", "wss://relay.nostr.band", "wss://nos.lol"],
11
+ relays: ["wss://relay.damus.io", "wss://relay.nostr.band", "wss://relay.primal.net"],
12
12
  tagStrategy: "path",
13
13
  tagPrefix: "comment:"
14
14
  },
@@ -17,9 +17,9 @@ const module = defineNuxtModule({
17
17
  nuxt.hook("vite:extendConfig", (config) => {
18
18
  config.optimizeDeps = config.optimizeDeps || {};
19
19
  config.optimizeDeps.include = config.optimizeDeps.include || [];
20
- config.optimizeDeps.include.push("tseep", "@nostr-dev-kit/ndk");
20
+ config.optimizeDeps.include.push("tseep", "@nostr-dev-kit/ndk", "nostr-tools", "defu");
21
21
  config.ssr = config.ssr || {};
22
- const packagesToInclude = ["tseep", "@nostr-dev-kit/ndk"];
22
+ const packagesToInclude = ["tseep", "@nostr-dev-kit/ndk", "nostr-tools", "defu"];
23
23
  if (!config.ssr.noExternal) {
24
24
  config.ssr.noExternal = packagesToInclude;
25
25
  } else if (Array.isArray(config.ssr.noExternal)) {
@@ -31,10 +31,10 @@ const module = defineNuxtModule({
31
31
  nuxt.hook("nitro:config", (nitroConfig) => {
32
32
  nitroConfig.externals = nitroConfig.externals || {};
33
33
  nitroConfig.externals.inline = nitroConfig.externals.inline || [];
34
- nitroConfig.externals.inline.push("tseep", "@nostr-dev-kit/ndk");
34
+ nitroConfig.externals.inline.push("tseep", "@nostr-dev-kit/ndk", "nostr-tools", "defu");
35
35
  });
36
36
  nuxt.options.build.transpile = nuxt.options.build.transpile || [];
37
- nuxt.options.build.transpile.push("tseep", "@nostr-dev-kit/ndk");
37
+ nuxt.options.build.transpile.push("tseep", "@nostr-dev-kit/ndk", "nostr-tools", "defu");
38
38
  nuxt.options.runtimeConfig.public.nuxstrComments = defu(nuxt.options.runtimeConfig.public.nuxstrComments || {}, options);
39
39
  addPlugin(resolver.resolve("./runtime/plugin"));
40
40
  addImports([
@@ -25,11 +25,14 @@ export function useNuxstr() {
25
25
  const isLoggedIn = computed(() => !!state.pubkey.value);
26
26
  async function connect() {
27
27
  const ndk = initializeNDK();
28
+ console.log("NDK relays:", ndk.explicitRelayUrls);
29
+ console.log("NDK connected:", state.isConnected.value);
28
30
  if (state.isConnected.value) return ndk;
29
31
  if (state.isConnecting.value) return ndk;
30
32
  state.isConnecting.value = true;
31
33
  try {
32
34
  await ndk.connect();
35
+ console.log("NDK connected:", state.isConnected.value);
33
36
  state.isConnected.value = true;
34
37
  return ndk;
35
38
  } finally {
@@ -54,6 +57,10 @@ export function useNuxstr() {
54
57
  const user = await signer.user();
55
58
  state.signer = signer;
56
59
  state.pubkey.value = user.pubkey;
60
+ const poo = ndk.getUser({ pubkey: user.pubkey });
61
+ console.log(poo);
62
+ await poo.fetchProfile();
63
+ console.log(poo);
57
64
  await connect();
58
65
  }
59
66
  }
@@ -37,13 +37,22 @@ export function useNuxstrComments(customContentId) {
37
37
  return void 0;
38
38
  }
39
39
  }
40
+ async function getEventsByTag(tag) {
41
+ try {
42
+ await connect();
43
+ const filter = { kinds: [NDKKind.GenericReply], ["#t"]: [tag], limit: 30 };
44
+ const events = await ndk.fetchEvents(filter);
45
+ return Array.from(events);
46
+ } catch (error2) {
47
+ console.warn("Failed to fetch events by tag", tag, error2);
48
+ return [];
49
+ }
50
+ }
40
51
  async function fetchComments() {
41
52
  loading.value = true;
42
53
  error.value = null;
43
54
  try {
44
- await connect();
45
- const filter = { kinds: [NDKKind.GenericReply], ["#t"]: [tagValue()] };
46
- const events = await ndk.fetchEvents(filter);
55
+ const events = await getEventsByTag(tagValue());
47
56
  const list = Array.from(events).sort((a, b) => (a.created_at || 0) - (b.created_at || 0));
48
57
  const pubkeys = [...new Set(list.map((e) => e.pubkey))];
49
58
  const profilePromises = pubkeys.map(async (pubkey) => {
@@ -1,26 +1,30 @@
1
1
  export type NuxstrProfile = {
2
- name?: string;
3
- display_name?: string;
4
- about?: string;
5
- picture?: string;
6
- nip05?: string;
7
- };
2
+ name?: string
3
+ display_name?: string
4
+ about?: string
5
+ picture?: string
6
+ nip05?: string
7
+ }
8
+
8
9
  export type NuxstrComment = {
9
- id: string;
10
- pubkey: string;
11
- created_at: number;
12
- content: string;
13
- profile?: NuxstrProfile;
14
- };
10
+ id: string
11
+ pubkey: string
12
+ created_at: number
13
+ content: string
14
+ profile?: NuxstrProfile
15
+ }
16
+
15
17
  export interface ElementNode {
16
- type: 'element';
17
- tag: string;
18
- props?: Record<string, unknown>;
18
+ type: 'element'
19
+ tag: string
20
+ props?: Record<string, unknown>
19
21
  }
22
+
20
23
  export interface RootNode {
21
- type: 'root';
22
- children: ElementNode[];
24
+ type: 'root'
25
+ children: ElementNode[]
23
26
  }
27
+
24
28
  export interface HtmlAst {
25
- body: RootNode;
29
+ body: RootNode
26
30
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threenine/nuxstr-comments",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "description": "Nuxstr Comments",
5
5
  "repository": "threenine/nuxstr-comments",
6
6
  "license": "MIT",
File without changes