nappup 1.8.1 → 1.8.2

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 CHANGED
@@ -27,8 +27,7 @@ nappup [directory] [options]
27
27
  | Flag | Description |
28
28
  |------|-------------|
29
29
  | `-s <secret_key>` | Your Nostr secret key (hex or nsec format) used to sign the application event. See [Authentication](#authentication) for alternatives. |
30
- | `-D <name>` | **Recommended**: A string to derive the identifier (`d` tag) from. This is the preferred way to set your app's identifier since you don't need to worry about the format - we'll handle the conversion for you. Just provide the application name and we'll ensure it's safely converted to a valid `d` tag. |
31
- | `-d <d_tag>` | The exact identifier (`d` tag) for your application. Only use this if you know the exact `d` tag you want. Otherwise, use `-D`. If both are omitted, defaults to deriving the identifier from the directory name. Avoid generic names like `dist` or `build` - use something unique among your other apps like `mycoolapp`. |
30
+ | `-d <d_tag>` | The identifier (`d` tag) for your application. Any UTF-8 text up to 260 characters. If omitted, defaults to the directory name. Avoid generic names like `dist` or `build` - use something unique among your other apps like `mycoolapp`. |
32
31
  | `-y` | Skip confirmation prompt. Useful for CI/CD pipelines or automated scripts. |
33
32
  | `-r` | Force re-upload. By default, Napp Up! might skip files that haven't changed. Use this flag to ensure everything is pushed fresh. |
34
33
  | `--main` | Publish to the **main** release channel. This is the default behavior. |
@@ -66,10 +65,31 @@ NOSTR_SECRET_KEY=nsec1... nappup
66
65
 
67
66
  Upload a specific `dist` folder with a custom identifier to the `next` channel:
68
67
  ```bash
69
- nappup ./dist -s nsec1... -D "My App #1" --next
68
+ nappup ./dist -s nsec1... -d "My App #1" --next
70
69
  ```
71
70
 
72
71
  Force re-upload a draft:
73
72
  ```bash
74
73
  nappup ~/my-repos/projectx/build/projectx --draft -r
75
74
  ```
75
+
76
+ ## Programmatic Usage
77
+
78
+ Napp Up! also exports a function that works in both Node.js and the browser, so you can integrate app uploads directly into your own tooling:
79
+
80
+ ```js
81
+ import publishApp from 'nappup'
82
+
83
+ await publishApp(fileList, signer, {
84
+ dTag: 'my-app',
85
+ channel: 'main', // 'main' | 'next' | 'draft'
86
+ shouldReupload: false,
87
+ onEvent ({ type, progress }) {
88
+ console.log(`${type} — ${progress}%`)
89
+ }
90
+ })
91
+ ```
92
+
93
+ - **`fileList`** — a `FileList` or array of `File` objects (each needs `webkitRelativePath`).
94
+ - **`signer`** — a [NIP-07](https://github.com/nostr-protocol/nips/blob/master/07.md)-compatible signer. In the browser, `window.nostr` is used automatically if omitted.
95
+ - **`onEvent`** — optional callback that receives progress events with a `type` (`'init'`, `'file-uploaded'`, `'complete'`, `'error'`, …) and `progress` (0–100).
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "url": "git+https://github.com/44billion/nappup.git"
7
7
  },
8
8
  "license": "MIT",
9
- "version": "1.8.1",
9
+ "version": "1.8.2",
10
10
  "description": "Nostr App Uploader",
11
11
  "type": "module",
12
12
  "scripts": {
@@ -1,3 +1,4 @@
1
+ import { sha256 } from '@noble/hashes/sha2.js'
1
2
  import { BlossomClient } from 'nostr-tools/nipb7'
2
3
  import nostrRelays from '#services/nostr-relays.js'
3
4
  import { bytesToBase16 } from '#helpers/base16.js'
@@ -67,12 +68,17 @@ export async function healthCheckServers (servers, signer, { log = () => {} } =
67
68
  }
68
69
 
69
70
  /**
70
- * Computes the sha256 hex hash of a File/Blob.
71
+ * Computes the sha256 hex hash of a File/Blob using streaming for memory efficiency.
71
72
  */
72
73
  export async function computeFileHash (file) {
73
- const bytes = new Uint8Array(await file.arrayBuffer())
74
- const hashBuffer = await crypto.subtle.digest('SHA-256', bytes)
75
- return bytesToBase16(new Uint8Array(hashBuffer))
74
+ const hash = sha256.create()
75
+ const reader = file.stream().getReader()
76
+ while (true) {
77
+ const { done, value } = await reader.read()
78
+ if (done) break
79
+ hash.update(value)
80
+ }
81
+ return bytesToBase16(hash.digest())
76
82
  }
77
83
 
78
84
  /**