applesauce-core 0.0.0-next-20250211165042 → 0.0.0-next-20250211174631

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.
@@ -0,0 +1,9 @@
1
+ export declare const BLOSSOM_SERVER_LIST_KIND = 10063;
2
+ /** Check if two servers are the same */
3
+ export declare function areBlossomServersEqual(a: string | URL, b: string | URL): boolean;
4
+ /** Checks if a string is a sha256 hash */
5
+ export declare function isSha256(str: string): boolean;
6
+ /** Returns an ordered array of servers found in a server list event (10063) */
7
+ export declare function getBlossomServersFromList(event: {
8
+ tags: string[][];
9
+ } | string[][]): URL[];
@@ -0,0 +1,22 @@
1
+ import { isNameValueTag, processTags } from "./tags.js";
2
+ export const BLOSSOM_SERVER_LIST_KIND = 10063;
3
+ /** Check if two servers are the same */
4
+ export function areBlossomServersEqual(a, b) {
5
+ const hostnameA = new URL("/", a).toString();
6
+ const hostnameB = new URL("/", b).toString();
7
+ return hostnameA === hostnameB;
8
+ }
9
+ /** Checks if a string is a sha256 hash */
10
+ export function isSha256(str) {
11
+ return !!str.match(/^[0-9a-f]{64}$/);
12
+ }
13
+ /** Returns an ordered array of servers found in a server list event (10063) */
14
+ export function getBlossomServersFromList(event) {
15
+ const tags = Array.isArray(event) ? event : event.tags;
16
+ return processTags(tags, (tag) => {
17
+ if (isNameValueTag(tag, "server") && URL.canParse(tag[1]))
18
+ return new URL("/", tag[1]);
19
+ else
20
+ return undefined;
21
+ });
22
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { areBlossomServersEqual } from "./blossom.js";
3
+ describe("areBlossomServersEqual", () => {
4
+ it("should ignore path", () => {
5
+ expect(areBlossomServersEqual("https://cdn.server.com/pathname", "https://cdn.server.com")).toBe(true);
6
+ });
7
+ it("should not ignore protocol", () => {
8
+ expect(areBlossomServersEqual("http://cdn.server.com", "https://cdn.server.com")).toBe(false);
9
+ });
10
+ it("should not ignore port", () => {
11
+ expect(areBlossomServersEqual("http://cdn.server.com:4658", "https://cdn.server.com")).toBe(false);
12
+ });
13
+ });
@@ -52,4 +52,4 @@ export declare function getMediaAttachments(event: NostrEvent): FileMetadata[];
52
52
  */
53
53
  export declare function getFileMetadata(file: NostrEvent): FileMetadata;
54
54
  /** Returns the last 64 length hex string in a URL */
55
- export declare function getSha256FromURL(url: string | URL): string | null;
55
+ export declare function getSha256FromURL(url: string | URL): string | undefined;
@@ -95,5 +95,5 @@ export function getSha256FromURL(url) {
95
95
  const hashes = Array.from(url.pathname.matchAll(/[0-9a-f]{64}/gi));
96
96
  if (hashes.length > 0)
97
97
  return hashes[hashes.length - 1][0];
98
- return null;
98
+ return;
99
99
  }
@@ -1,3 +1,4 @@
1
+ export * from "./blossom.js";
1
2
  export * from "./bolt11.js";
2
3
  export * from "./bookmarks.js";
3
4
  export * from "./cache.js";
@@ -1,3 +1,4 @@
1
+ export * from "./blossom.js";
1
2
  export * from "./bolt11.js";
2
3
  export * from "./bookmarks.js";
3
4
  export * from "./cache.js";
@@ -44,13 +44,12 @@ export function isSameURL(a, b) {
44
44
  * Does not remove the trailing slash
45
45
  */
46
46
  export function normalizeURL(url) {
47
- if (typeof url === "string" && url.indexOf("://") === -1)
48
- url = "wss://" + url;
49
47
  let p = new URL(url);
50
48
  // remove any double slashes
51
49
  p.pathname = p.pathname.replace(/\/+/g, "/");
52
50
  // drop the port if its not needed
53
- if ((p.port === "80" && p.protocol === "ws:") || (p.port === "443" && p.protocol === "wss:"))
51
+ if ((p.port === "80" && (p.protocol === "ws:" || p.protocol === "http:")) ||
52
+ (p.port === "443" && (p.protocol === "wss:" || p.protocol === "https:")))
54
53
  p.port = "";
55
54
  // sort the query params
56
55
  p.searchParams.sort();
@@ -0,0 +1,2 @@
1
+ import { Query } from "../query-store/index.js";
2
+ export declare function UserBlossomServersQuery(pubkey: string): Query<URL[] | undefined>;
@@ -0,0 +1,10 @@
1
+ import { map } from "rxjs/operators";
2
+ import { BLOSSOM_SERVER_LIST_KIND, getBlossomServersFromList } from "../helpers/blossom.js";
3
+ export function UserBlossomServersQuery(pubkey) {
4
+ return {
5
+ key: pubkey,
6
+ run: (store) => store
7
+ .replaceable(BLOSSOM_SERVER_LIST_KIND, pubkey)
8
+ .pipe(map((event) => event && getBlossomServersFromList(event))),
9
+ };
10
+ }
@@ -1,3 +1,4 @@
1
+ export * from "./blossom.js";
1
2
  export * from "./bookmarks.js";
2
3
  export * from "./channels.js";
3
4
  export * from "./comments.js";
@@ -1,3 +1,4 @@
1
+ export * from "./blossom.js";
1
2
  export * from "./bookmarks.js";
2
3
  export * from "./channels.js";
3
4
  export * from "./comments.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "applesauce-core",
3
- "version": "0.0.0-next-20250211165042",
3
+ "version": "0.0.0-next-20250211174631",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",