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
13 changes: 10 additions & 3 deletions .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
name: Release Drafter

# Manual only. Release notes are written by hand in the vX.Y.Z draft release,
# which version-release.yml publishes when VERSION changes. Running this on
# every push to main would overwrite that draft. Run it from the Actions tab
# to generate a starting draft from merged pull requests.
on:
push:
branches:
- main
workflow_dispatch:
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

# Two manual runs at once would both rewrite the same draft.
concurrency:
group: release-drafter
cancel-in-progress: false

permissions:
contents: write
Expand Down
31 changes: 26 additions & 5 deletions .github/workflows/version-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,38 +97,59 @@ jobs:
const version = process.env.VERSION;

// Get all releases
const { data: releases } = await github.rest.repos.listReleases({
const releases = await github.paginate(github.rest.repos.listReleases, {
owner: context.repo.owner,
repo: context.repo.repo,
});

// Find the draft release
const draftRelease = releases.find(release => release.draft === true);
// GitHub's generated "What's Changed" list since the last release.
const previous = releases.find(r => !r.draft && !r.prerelease);
const { data: generated } = await github.rest.repos.generateReleaseNotes({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: version,
...(previous ? { previous_tag_name: previous.tag_name } : {}),
});

// Prefer the draft written for this version (named or tagged
// vX.Y.Z); otherwise fall back to any draft, such as one from
// Release Drafter.
const draftRelease =
releases.find(r => r.draft && (r.name === version || r.tag_name === version)) ||
releases.find(r => r.draft);

if (draftRelease) {
console.log(`Found draft release: ${draftRelease.name}`);

// Keep the draft's own notes, but always use a freshly generated
// list: a "What's Changed" section already in the draft (such
// as one from Release Drafter) may be stale, so drop it.
const notes = (draftRelease.body || '').split(/^## What's Changed/m)[0].trim();
const body = `${notes}\n\n${generated.body}`.trim();

// Update and publish the draft release
await github.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: draftRelease.id,
tag_name: version,
name: version,
body,
draft: false,
make_latest: 'true',
});

console.log(`✓ Published draft release as ${version}`);
core.setOutput('released', 'true');
} else {
console.log('⚠️ No draft release found. Creating release automatically.');
console.log('⚠️ No draft release found. Creating release with generated notes.');

await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: version,
name: version,
body: `## Release ${version}\n\nThis release was automatically created when the VERSION file was updated.`,
body: generated.body,
draft: false,
prerelease: false,
});
Expand Down
33 changes: 27 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ await relay.send({
// Receive messages
const messages = await relay.receive('0xMyWallet');

// Later, fetch only what arrived since
const lastSeq = messages.at(-1)?.seq ?? 0;
const fresh = await relay.receive('0xMyWallet', { after: lastSeq });

// Delete a message after reading
await relay.delete(messages[0].id);
```
Expand Down Expand Up @@ -144,11 +148,18 @@ npm run lint # ESLint

### `relay.send(params): Promise<Message>`

Send an encrypted message to the relay.
Send an encrypted message to the relay. The returned message carries the server-assigned `id` and, on ThruBox Server 1.0 or later, its `seq`. On those servers sending an identical message twice is safe: it is stored once and the existing message is returned.

### `relay.receive(address, options?): Promise<Message[]>`

### `relay.receive(address): Promise<Message[]>`
Fetch messages for a wallet address, oldest first.

Fetch all messages for a wallet address.
| Option | Type | Description |
|--------|------|-------------|
| `after` | `number` | Only return messages whose `seq` is greater than this |
| `limit` | `number` | Return at most this many messages (1–1000). A full page means there may be more: ask again with `after` set to the last `seq` |

On ThruBox Server 1.0 or later, every message has a `seq`: its position in the mailbox (1, 2, 3, …). It only increases and is never reused, so remembering the highest `seq` you have handled and passing it as `after` gives you exactly the new messages. Each device keeps its own cursor. Older servers send no `seq` and ignore `after` and `limit`, returning the whole mailbox.

### `relay.delete(id): Promise<void>`

Expand All @@ -158,15 +169,25 @@ Delete a specific message by ID.

Auto-poll for new messages. Returns a stop function.

| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `intervalMs` | `number` | `10000` | Time between polls |
| `onError` | `(error) => void` | logs | Called when a poll or the callback fails |
| `after` | `number` | — | Turns on cursor tracking, starting from this `seq` (`0` for the whole mailbox) |

Without `after`, every poll passes the whole mailbox to the callback. With `after`, each poll fetches only messages newer than the cursor, and the cursor moves forward once the callback returns (or its promise resolves). If the callback throws or rejects, the cursor stays put and the same messages are delivered again on the next poll, so a failed save is retried rather than lost.

```typescript
const stop = relay.poll('0xMyWallet', (messages) => {
console.log('New messages:', messages);
}, { intervalMs: 5000 });
const stop = relay.poll('0xMyWallet', async (messages) => {
await saveLocally(messages); // throw to have them delivered again
}, { intervalMs: 5000, after: 0 });

// Later: stop polling
stop();
```

The next poll is scheduled after the callback finishes, so polls never overlap.

### `relay.health(): Promise<HealthResponse>`

Check server health.
Expand Down
Loading
Loading