blossom-client-sdk 1.1.0 → 2.0.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/README.md +12 -33
- package/lib/actions/delete.d.ts +11 -0
- package/lib/actions/delete.js +42 -0
- package/lib/actions/download.d.ts +11 -0
- package/lib/actions/download.js +40 -0
- package/lib/actions/index.d.ts +5 -0
- package/lib/actions/index.js +5 -0
- package/lib/actions/list.d.ts +13 -0
- package/lib/actions/list.js +44 -0
- package/lib/actions/mirror.d.ts +11 -0
- package/lib/actions/mirror.js +55 -0
- package/lib/actions/upload.d.ts +24 -0
- package/lib/actions/upload.js +145 -0
- package/lib/auth.d.ts +27 -0
- package/lib/auth.js +113 -0
- package/lib/client.d.ts +45 -80
- package/lib/client.js +107 -226
- package/lib/const.d.ts +1 -0
- package/lib/const.js +1 -0
- package/lib/error.d.ts +11 -0
- package/lib/error.js +22 -0
- package/lib/helpers.d.ts +17 -0
- package/lib/helpers.js +61 -0
- package/lib/index.d.ts +4 -1
- package/lib/index.js +4 -1
- package/lib/nostr.d.ts +3 -6
- package/lib/nostr.js +0 -5
- package/lib/types.d.ts +40 -0
- package/lib/types.js +1 -0
- package/package.json +21 -11
- package/CHANGELOG.md +0 -62
- package/lib/upload.d.ts +0 -13
- package/lib/upload.js +0 -37
package/lib/nostr.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
type NostrEvent = {
|
|
2
|
-
tags: string[][];
|
|
3
|
-
};
|
|
4
1
|
export declare const USER_BLOSSOM_SERVER_LIST_KIND = 10063;
|
|
5
|
-
export declare function areServersEqual(a: string | URL, b: string | URL): boolean;
|
|
6
2
|
/** Returns an ordered array of servers found in a server list event (10063) */
|
|
7
|
-
export declare function getServersFromServerListEvent(event:
|
|
8
|
-
|
|
3
|
+
export declare function getServersFromServerListEvent(event: {
|
|
4
|
+
tags: string[][];
|
|
5
|
+
}): URL[];
|
package/lib/nostr.js
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
1
|
export const USER_BLOSSOM_SERVER_LIST_KIND = 10063;
|
|
2
|
-
export function areServersEqual(a, b) {
|
|
3
|
-
const hostnameA = a instanceof URL ? a.hostname : new URL(a).hostname;
|
|
4
|
-
const hostnameB = b instanceof URL ? b.hostname : new URL(b).hostname;
|
|
5
|
-
return hostnameA === hostnameB;
|
|
6
|
-
}
|
|
7
2
|
/** Returns an ordered array of servers found in a server list event (10063) */
|
|
8
3
|
export function getServersFromServerListEvent(event) {
|
|
9
4
|
const servers = [];
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { DeleteOptions } from "./actions/delete.js";
|
|
2
|
+
import { DownloadOptions } from "./actions/download.js";
|
|
3
|
+
import { ListOptions } from "./actions/list.js";
|
|
4
|
+
import { MirrorOptions } from "./actions/mirror.js";
|
|
5
|
+
import { UploadOptions } from "./actions/upload.js";
|
|
6
|
+
import { ServerType, UploadType } from "./client.js";
|
|
7
|
+
export type EventTemplate = {
|
|
8
|
+
created_at: number;
|
|
9
|
+
kind: number;
|
|
10
|
+
content: string;
|
|
11
|
+
tags: string[][];
|
|
12
|
+
};
|
|
13
|
+
export type SignedEvent = EventTemplate & {
|
|
14
|
+
id: string;
|
|
15
|
+
sig: string;
|
|
16
|
+
pubkey: string;
|
|
17
|
+
};
|
|
18
|
+
/** An async method used to sign nostr events */
|
|
19
|
+
export type Signer = (draft: EventTemplate) => Promise<SignedEvent>;
|
|
20
|
+
/** interface for handling payment requests */
|
|
21
|
+
export interface PaymentHandlers<S extends ServerType = ServerType> {
|
|
22
|
+
upload?: UploadOptions<S, UploadType>["onPayment"];
|
|
23
|
+
download?: DownloadOptions<S>["onPayment"];
|
|
24
|
+
list?: ListOptions<S>["onPayment"];
|
|
25
|
+
mirror?: MirrorOptions<S>["onPayment"];
|
|
26
|
+
delete?: DeleteOptions<S>["onPayment"];
|
|
27
|
+
}
|
|
28
|
+
export type BlobDescriptor = {
|
|
29
|
+
uploaded: number;
|
|
30
|
+
type?: string;
|
|
31
|
+
sha256: string;
|
|
32
|
+
size: number;
|
|
33
|
+
url: string;
|
|
34
|
+
};
|
|
35
|
+
export type PaymentRequest = {
|
|
36
|
+
amount: number;
|
|
37
|
+
unit: string;
|
|
38
|
+
mints: string[];
|
|
39
|
+
pubkey: string;
|
|
40
|
+
};
|
package/lib/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "blossom-client-sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "A simple client for manage blobs on blossom servers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
7
7
|
"typings": "./lib/index.d.ts",
|
|
8
8
|
"author": "hzrd149",
|
|
9
9
|
"license": "MIT",
|
|
10
|
-
"scripts": {
|
|
11
|
-
"build": "tsc",
|
|
12
|
-
"prepublish": "npm run build",
|
|
13
|
-
"format": "prettier -w .",
|
|
14
|
-
"docs": "typedoc src/index.ts"
|
|
15
|
-
},
|
|
16
10
|
"files": [
|
|
17
11
|
"lib"
|
|
18
12
|
],
|
|
@@ -37,21 +31,37 @@
|
|
|
37
31
|
"import": "./lib/nostr.js",
|
|
38
32
|
"types": "./lib/nostr.d.ts"
|
|
39
33
|
},
|
|
40
|
-
"./
|
|
41
|
-
"import": "./lib/
|
|
42
|
-
"types": "./lib/
|
|
34
|
+
"./auth": {
|
|
35
|
+
"import": "./lib/auth.js",
|
|
36
|
+
"types": "./lib/auth.d.ts"
|
|
37
|
+
},
|
|
38
|
+
"./actions": {
|
|
39
|
+
"import": "./lib/actions.js",
|
|
40
|
+
"types": "./lib/actions.d.ts"
|
|
41
|
+
},
|
|
42
|
+
"./actions/*": {
|
|
43
|
+
"import": "./lib/actions/*.js",
|
|
44
|
+
"types": "./lib/actions/*.d.ts"
|
|
43
45
|
}
|
|
44
46
|
},
|
|
45
47
|
"engines": {
|
|
46
48
|
"node": ">=18"
|
|
47
49
|
},
|
|
48
50
|
"dependencies": {
|
|
51
|
+
"@cashu/cashu-ts": "2.0.0-rc1",
|
|
49
52
|
"@noble/hashes": "^1.4.0"
|
|
50
53
|
},
|
|
51
54
|
"devDependencies": {
|
|
52
55
|
"@changesets/cli": "^2.27.1",
|
|
56
|
+
"@types/node": "^22.5.5",
|
|
53
57
|
"prettier": "^3.3.3",
|
|
54
58
|
"typedoc": "^0.25.12",
|
|
55
59
|
"typescript": "^5.3.3"
|
|
60
|
+
},
|
|
61
|
+
"scripts": {
|
|
62
|
+
"build": "tsc",
|
|
63
|
+
"prepublish": "npm run build",
|
|
64
|
+
"format": "prettier -w .",
|
|
65
|
+
"docs": "typedoc src/index.ts"
|
|
56
66
|
}
|
|
57
|
-
}
|
|
67
|
+
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
# blossom-client-sdk
|
|
2
|
-
|
|
3
|
-
## 1.1.0
|
|
4
|
-
|
|
5
|
-
### Minor Changes
|
|
6
|
-
|
|
7
|
-
- Add support for multiple hashes when creating auth events
|
|
8
|
-
|
|
9
|
-
### Patch Changes
|
|
10
|
-
|
|
11
|
-
- Allow auth to be passed into multiServerUpload
|
|
12
|
-
|
|
13
|
-
## 1.0.1
|
|
14
|
-
|
|
15
|
-
### Patch Changes
|
|
16
|
-
|
|
17
|
-
- Add upload exports to package.json
|
|
18
|
-
|
|
19
|
-
## 1.0.0
|
|
20
|
-
|
|
21
|
-
### Major Changes
|
|
22
|
-
|
|
23
|
-
- 8350d95: Remove dependency on cross-fetch and require NodeJS >= 18 for native `fetch` API
|
|
24
|
-
|
|
25
|
-
### Minor Changes
|
|
26
|
-
|
|
27
|
-
- 383a13b: Add `multiServerUpload` method
|
|
28
|
-
|
|
29
|
-
## 0.9.1
|
|
30
|
-
|
|
31
|
-
### Patch Changes
|
|
32
|
-
|
|
33
|
-
- Add support for nodejs Buffer type
|
|
34
|
-
|
|
35
|
-
## 0.9.0
|
|
36
|
-
|
|
37
|
-
### Minor Changes
|
|
38
|
-
|
|
39
|
-
- 1a5342b: Add mirror blob methods
|
|
40
|
-
- 24f4e57: add "x" or "server" tag on get auth
|
|
41
|
-
|
|
42
|
-
## 0.8.0
|
|
43
|
-
|
|
44
|
-
### Minor Changes
|
|
45
|
-
|
|
46
|
-
- Add `handleBrokenImages` method for repairing any broken images in an app
|
|
47
|
-
|
|
48
|
-
## 0.7.0
|
|
49
|
-
|
|
50
|
-
### Minor Changes
|
|
51
|
-
|
|
52
|
-
- Include "x" tag with sha256 in upload auth
|
|
53
|
-
|
|
54
|
-
### Patch Changes
|
|
55
|
-
|
|
56
|
-
- Allow URL class for server
|
|
57
|
-
|
|
58
|
-
## 0.7.0
|
|
59
|
-
|
|
60
|
-
### Minor Changes
|
|
61
|
-
|
|
62
|
-
- e2e93f5: Add `handleImageFallbacks` method
|
package/lib/upload.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { BlobDescriptor, ServerType, SignedEvent, Signer, UploadType } from "./client.js";
|
|
2
|
-
/**
|
|
3
|
-
* Creates an AsyncGenerator that can be used to upload a blob to multiple servers
|
|
4
|
-
* @param servers A Set or Array of servers to upload to
|
|
5
|
-
* @param file The blob to be uploaded
|
|
6
|
-
* @param signer An async function used for signing nostr events
|
|
7
|
-
* @returns The BlobDescriptor if successful
|
|
8
|
-
*/
|
|
9
|
-
export declare function multiServerUpload(servers: Iterable<ServerType>, file: UploadType, signer: Signer, auth?: SignedEvent): AsyncGenerator<{
|
|
10
|
-
blob: BlobDescriptor;
|
|
11
|
-
progress: number;
|
|
12
|
-
server: ServerType;
|
|
13
|
-
}, BlobDescriptor | undefined, unknown>;
|
package/lib/upload.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { BlossomClient } from "./client.js";
|
|
2
|
-
/**
|
|
3
|
-
* Creates an AsyncGenerator that can be used to upload a blob to multiple servers
|
|
4
|
-
* @param servers A Set or Array of servers to upload to
|
|
5
|
-
* @param file The blob to be uploaded
|
|
6
|
-
* @param signer An async function used for signing nostr events
|
|
7
|
-
* @returns The BlobDescriptor if successful
|
|
8
|
-
*/
|
|
9
|
-
export async function* multiServerUpload(servers, file, signer, auth) {
|
|
10
|
-
auth = auth || (await BlossomClient.getUploadAuth(file, signer));
|
|
11
|
-
let blob = undefined;
|
|
12
|
-
let total = Array.from(servers).length;
|
|
13
|
-
let uploaded = 0;
|
|
14
|
-
for (const server of servers) {
|
|
15
|
-
if (blob) {
|
|
16
|
-
// mirror blob to server
|
|
17
|
-
try {
|
|
18
|
-
let b = await BlossomClient.mirrorBlob(server, blob.url, auth);
|
|
19
|
-
uploaded++;
|
|
20
|
-
yield { blob: b, progress: uploaded / total, server };
|
|
21
|
-
}
|
|
22
|
-
catch (error) {
|
|
23
|
-
// not all servers support mirroring, attempt to upload
|
|
24
|
-
let b = await BlossomClient.uploadBlob(server, file, auth);
|
|
25
|
-
uploaded++;
|
|
26
|
-
yield { blob: b, progress: uploaded / total, server };
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
// attempt initial upload
|
|
31
|
-
blob = await BlossomClient.uploadBlob(server, file, auth);
|
|
32
|
-
uploaded++;
|
|
33
|
-
yield { blob, progress: uploaded / total, server };
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return blob;
|
|
37
|
-
}
|