Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ See [pg-sveltekit/README.md](pg-sveltekit/README.md) for environment variables a

### Node.js example

Requires Node.js 20.6+ and a PostGuard API key.
Requires Node.js 22+ and a PostGuard API key.

```bash
cd pg-node
Expand Down
18 changes: 10 additions & 8 deletions pg-node/README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
# pg-node: PostGuard Node.js example

Node.js example demonstrating how to use the [@e4a/pg-js](https://www.npmjs.com/package/@e4a/pg-js) SDK from a server runtime. Mirrors the [pg-sveltekit](../pg-sveltekit) example's "Informatierijk notificeren" flow (citizen + organisation recipients) but as a CLI script — drop-in starting point for backend integrations.
Node.js example demonstrating how to use the [@e4a/pg-js](https://www.npmjs.com/package/@e4a/pg-js) SDK from a server runtime. Mirrors the [pg-sveltekit](../pg-sveltekit) example's "Informatierijk notificeren" flow (citizen + organisation recipients) as a CLI script. Drop-in starting point for backend integrations.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Code review + Rule: writing-rules #33] Drop-in starting point for backend integrations is borderline promotional and pattern-matches what writing-rules calls AI-slop (press-release voice / vague aspirational uplift). Not banned and pre-existing from #46, but the PR touched this line — replacement candidate: Use as a starting point when integrating PostGuard from a backend.


## What it does

Two modes, selected by the script flag:
Two modes, selected by an npm script:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Code review] Wording changed from selected by the script flag to selected by an npm script. The npm scripts are thin wrappers that pass --upload-only (see pg-node/package.json + pg-node/index.mjs:28) — i.e. the script flag is the actual mode-selector and the npm script just sets it. The original phrasing was more accurate; the new one papers over the mechanism. If you don't want to mention the flag, at least pick a phrasing that doesn't imply two distinct binaries (e.g. Two modes, one per npm script:).


1. **Send** (`npm run send`) — encrypts the input files for a citizen (exact email) and an organisation (email domain), uploads to Cryptify, and asks Cryptify to email each recipient a download link.
2. **Upload-only** (`npm run upload`) — same encryption + upload, but silent. Cryptify returns a UUID you can distribute through some other channel.
| Mode | Command | What it does |
| ----------- | ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Send | `npm run send` | Encrypts the input files for a citizen (exact email) and an organisation (email domain), uploads to Cryptify, and asks Cryptify to email each recipient. |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Code review] Two-row Markdown table whose content rows are 220–250 chars wide. Renders fine on GitHub but the raw markdown is awkward to read and edit (and the existing Configuration table further down doesn't need to be this wide). Consider either dropping back to a list (without the inline-header pattern) or keeping commands+modes as one column and moving the descriptions to prose.

| Upload-only | `npm run upload` | Same encryption and upload, but silent. Cryptify returns a UUID you can distribute through some other channel. |

Files come from `PG_INPUT_FILES` (comma-separated paths) or two in-memory demo files if that is unset.
Files come from `PG_INPUT_FILES` (comma-separated paths), or two in-memory demo files if that is unset.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Code review] Diff inserts a comma here: Files come from PG_INPUT_FILES (comma-separated paths), or two in-memory demo files if that is unset. This coordinates two simple objects of the same verb (come from X or Y), so the comma before or is incorrect under standard prose rules — it reads as a stray pause. The pre-diff version (no comma) was right. Either revert the comma or restructure into two sentences.


## Prerequisites

- **Node.js 22+** — matches `@e4a/pg-js`'s `engines.node`. The SDK also supports Bun and Deno; the same encryption code in `src/encryption.mjs` works there too.
- **Node.js 22+**, matching `@e4a/pg-js`'s `engines.node`. The SDK also supports Bun and Deno; the same encryption code in `src/encryption.mjs` works there too.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Code review + Rule: writing-rules #48] PR claims to eliminate the writing-rules #48 inline-header + sentence list pattern, but this line still has it: - **Node.js 22+**, matching …. Swapping the em-dash for a comma keeps the exact structural pattern (bold inline header functioning as a sub-title for the sentence after it). To fix #48 properly, drop the bold inline header or move it into a sentence-level subject — e.g. Node.js 22+ (matches @e4a/pg-js's engines.node). The SDK also supports Bun and Deno; ….

- A PostGuard for Business API key.

## Setup
Expand All @@ -38,7 +40,7 @@ The script prints the resulting `uuid` and the corresponding `…/download?uuid=

## Staging Cryptify does not send email

The default `PG_CRYPTIFY_URL` is `storage.staging.postguard.eu` the staging deployment. It **does not actually deliver notification emails**, so you can exercise the full upload + notify flow without spamming real inboxes while you integrate.
The default `PG_CRYPTIFY_URL` is `storage.staging.postguard.eu`, the staging deployment. It **does not actually deliver notification emails**, so you can exercise the full upload + notify flow without spamming real inboxes while you integrate.

- The upload itself works. You get back a real UUID and the download URL is usable.
- `npm run send` succeeds, but no recipient mail is sent. Open the printed URL yourself to verify the decrypt flow end-to-end.
Expand Down Expand Up @@ -72,4 +74,4 @@ const sealed = pg.encrypt({
const { uuid } = await sealed.upload({ notify: { recipients: true, message, language: 'EN' } });
```

`notify` must be nested under an object — the SDK validates the shape and throws a clear `TypeError` if you pass `{ notify: true }` or forget to nest. See the [SDK README](https://github.com/encryption4all/postguard-js#server-side-usage-node-bun-deno) for the full server-side surface.
`notify` must be nested under an object. The SDK validates the shape and throws a clear `TypeError` if you pass `{ notify: true }` or forget to nest. See the [SDK README](https://github.com/encryption4all/postguard-js#server-side-usage-node-bun-deno) for the full server-side surface.
4 changes: 2 additions & 2 deletions pg-node/src/config.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Env-driven config. Run with `node --env-file=.env index.mjs` to load
// from .env (Node 20.6+). Mirrors pg-sveltekit's config.ts.
// Env-driven config. `.env` is loaded automatically by the npm scripts
// via Node's `--env-file-if-exists`. Mirrors pg-sveltekit's config.ts.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Code review] Comment now says .env is loaded automatically by the npm scripts via Node's --env-file-if-exists. Accurate, but --env-file-if-exists requires Node 21.7+ — fine because engines.node is >=22, but a future reader who runs node src/config.mjs directly under an older Node will be confused. Either leave alone (current state is acceptable) or add a one-clause note that the flag is wired in package.json and only matters when you use the npm scripts.


export const PKG_URL = process.env.PG_PKG_URL || 'https://pkg.staging.postguard.eu';
export const CRYPTIFY_URL = process.env.PG_CRYPTIFY_URL || 'https://storage.staging.postguard.eu';
Expand Down