Compare commits

...
5 Commits
Author SHA1 Message Date
Derek Ross e80b024b2d Merge branch 'feature/transaction-print-receipt' into 'main'
feat: add Print Receipt to completed transactions

See merge request soapbox-pub/shakespeare!111
2026-09-16 08:05:22 -04:00
Alex Gleason 2036903918 release: v9.16.4 2026-09-16 00:34:10 -05:00
Alex Gleason 1ca1a4e4ea Stop writing a relay tag NIP-5A never defined
The nsite manifest tag table has `path`, `x`, `d`, `a`, `A`, `server`,
`title`, `description`, and `source`, and nothing for saying which relays
the event went to. Ours went out with one per configured relay anyway,
apparently by symmetry with `server` — but a `server` tag answers a
question the host server actually asks when fetching a blob, and nothing
in the spec or in this codebase ever read the relay hints back.

So they are gone from the deploy path, and gone from the two places the
npanel migration re-signs somebody else's manifest: republishing no
longer strips the archive's relay tags only to write its own in their
place, and retitling no longer passes through whatever an older deploy
of ours left behind. Re-signing an event is the moment to stop carrying
a tag that does not exist.

Where to find the manifest stays the reader's problem and the author's
kind 10002, which is where NIP-5A leaves it.
2026-09-15 22:40:20 -05:00
Derek Ross 47f9edacfd fix: escape HTML in receipt print template to prevent injection 2026-04-12 12:58:57 -04:00
Derek Ross c229f40da8 feat: add Print Receipt button to completed transactions
Add a 'Print Receipt' option for completed credit purchase transactions
in the AI provider config dialog. Clicking it opens a print-friendly
receipt with Soapbox Technology, LLC business details (soapbox.pub,
[email protected]) in a standard receipt layout showing payment ID,
date, method, credits, processing fee, and total charged.

Follows the existing window.open() print pattern used by gift card QR
code printing. Adds i18n translations for all 6 supported languages.
2026-04-10 12:05:50 -04:00
15 changed files with 333 additions and 28 deletions

No files matched your search

+5
View File
@@ -1,5 +1,10 @@
# Changelog
## [9.16.4] - 2026-09-16
### Changed
- Published sites carry only the tags the nsite spec defines — the relay hints Shakespeare used to attach were read by nothing, and taking a site back no longer rewrites them
## [9.16.3] - 2026-09-14
### Added
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "shakespeare.diy",
"version": "9.16.2",
"version": "9.16.4",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "shakespeare.diy",
"version": "9.16.2",
"version": "9.16.4",
"license": "AGPL-3.0-or-later",
"dependencies": {
"@capacitor/app": "^8.1.0",
+1 -1
View File
@@ -3,7 +3,7 @@
"description": "Build custom apps with AI assistance using Shakespeare, an open-source development environment",
"homepage": "https://shakespeare.diy",
"license": "AGPL-3.0-or-later",
"version": "9.16.3",
"version": "9.16.4",
"type": "module",
"author": {
"name": "shakespeare.diy",
+5
View File
@@ -1,5 +1,10 @@
# Changelog
## [9.16.4] - 2026-09-16
### Changed
- Published sites carry only the tags the nsite spec defines — the relay hints Shakespeare used to attach were read by nothing, and taking a site back no longer rewrites them
## [9.16.3] - 2026-09-14
### Added
+236
View File
@@ -895,6 +895,231 @@ export function AIProviderConfigDialog({
}
};
const escapeHtml = (str: string): string =>
str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#39;');
const handlePrintReceipt = (payment: Payment) => {
const receiptDate = new Date((payment.completed_at ?? payment.created_at) * 1000);
const formattedDate = new Intl.DateTimeFormat('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric',
}).format(receiptDate);
const formattedTime = new Intl.DateTimeFormat('en-US', {
hour: '2-digit',
minute: '2-digit',
}).format(receiptDate);
const paymentMethodDisplay = payment.method === 'stripe' ? t('creditCard') : t('lightning');
const statusDisplay = payment.status.charAt(0).toUpperCase() + payment.status.slice(1);
const printWindow = window.open('', '_blank');
if (!printWindow) {
toast({
title: t('printFailed'),
description: t('failedToOpenPrintWindow'),
variant: 'destructive',
});
return;
}
const printHTML = `
<!DOCTYPE html>
<html>
<head>
<title>${t('receipt')} - ${escapeHtml(payment.id)}</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
padding: 40px 20px;
background: white;
color: #000;
}
.receipt {
max-width: 600px;
margin: 0 auto;
border: 1px solid #e0e0e0;
padding: 48px 40px;
}
.header {
text-align: center;
padding-bottom: 28px;
border-bottom: 2px solid #000;
margin-bottom: 28px;
}
.company-name {
font-size: 20px;
font-weight: 700;
letter-spacing: 0.5px;
margin-bottom: 6px;
}
.company-detail {
font-size: 13px;
color: #555;
line-height: 1.6;
}
.company-detail a {
color: #555;
text-decoration: none;
}
.receipt-title {
text-align: center;
font-size: 14px;
font-weight: 600;
letter-spacing: 2px;
text-transform: uppercase;
color: #333;
margin-bottom: 28px;
}
.details-grid {
display: grid;
grid-template-columns: 140px 1fr;
gap: 8px 16px;
margin-bottom: 28px;
font-size: 14px;
}
.details-grid dt {
color: #666;
font-weight: 500;
}
.details-grid dd {
color: #000;
}
.divider {
border: none;
border-top: 1px solid #e0e0e0;
margin: 0 0 28px 0;
}
.line-items {
margin-bottom: 28px;
}
.line-item {
display: flex;
justify-content: space-between;
padding: 6px 0;
font-size: 14px;
}
.line-item-label {
color: #333;
}
.line-item-value {
font-variant-numeric: tabular-nums;
}
.line-item-total {
border-top: 1px solid #000;
margin-top: 8px;
padding-top: 10px;
font-weight: 700;
font-size: 15px;
}
.footer {
text-align: center;
padding-top: 28px;
border-top: 1px solid #e0e0e0;
}
.footer p {
font-size: 13px;
color: #666;
line-height: 1.6;
}
@media print {
body {
padding: 0;
}
.receipt {
border: none;
padding: 0;
max-width: 100%;
}
}
</style>
</head>
<body>
<div class="receipt">
<div class="header">
<div class="company-name">Soapbox Technology, LLC</div>
<div class="company-detail">
<a href="https://soapbox.pub">soapbox.pub</a><br />
[email protected]
</div>
</div>
<div class="receipt-title">${t('receipt')}</div>
<dl class="details-grid">
<dt>${t('receiptNumber')}</dt>
<dd>${escapeHtml(payment.id)}</dd>
<dt>${t('date')}</dt>
<dd>${formattedDate} ${formattedTime}</dd>
<dt>${t('status')}</dt>
<dd>${escapeHtml(statusDisplay)}</dd>
<dt>${t('paymentMethodLabel')}</dt>
<dd>${paymentMethodDisplay}</dd>
${payment.description ? `<dt>${t('description')}</dt><dd>${escapeHtml(payment.description)}</dd>` : ''}
</dl>
<hr class="divider" />
<div class="line-items">
<div class="line-item">
<span class="line-item-label">${t('credits')}</span>
<span class="line-item-value">${formatCurrency(payment.amount)}</span>
</div>
${payment.fee > 0 ? `
<div class="line-item">
<span class="line-item-label">${t('processingFee')}</span>
<span class="line-item-value">${formatCurrency(payment.fee)}</span>
</div>
` : ''}
<div class="line-item line-item-total">
<span class="line-item-label">${t('totalCharged')}</span>
<span class="line-item-value">${formatCurrency(payment.total)}</span>
</div>
</div>
<div class="footer">
<p>${t('thankYouForPurchase')}</p>
</div>
</div>
</body>
</html>
`;
printWindow.document.write(printHTML);
printWindow.document.close();
printWindow.onload = () => {
setTimeout(() => {
printWindow.print();
}, 250);
};
};
const handleDownloadCSV = () => {
if (!giftcards || giftcards.length === 0) return;
@@ -1307,6 +1532,17 @@ export function AIProviderConfigDialog({
)}
</div>
)}
{payment.status === 'completed' && (
<Button
variant="ghost"
size="sm"
onClick={() => handlePrintReceipt(payment)}
className="h-6 px-2 text-xs"
>
<Printer className="h-3 w-3 mr-1" />
{t('printReceipt')}
</Button>
)}
</div>
</div>
))}
@@ -145,7 +145,7 @@ export function NpanelMigrationDialog({ open, onOpenChange, provider }: NpanelMi
kind: NAMED_SITE_KIND,
content: claim.step.manifest.content,
created_at: Math.floor(Date.now() / 1000),
tags: republishTags(claim.step.manifest, claim.step.identifier, provider.relayUrls, {
tags: republishTags(claim.step.manifest, claim.step.identifier, {
title: claim.suggestedTitle,
description: claim.suggestedDescription,
}),
+7 -5
View File
@@ -250,8 +250,8 @@ async function runConcurrent<T>(
* - HEAD-checks each file on each Blossom server before uploading
* - PUTs files to Blossom servers with pre-signed auth headers
* - Publishes a single kind-15128 (root) or kind-35128 (named) site manifest event
* containing all ["path", "/path", sha256] tags, ["server", url] Blossom hints,
* and ["relay", url] relay hints — no separate kind 10002 or kind 10063 published
* containing all ["path", "/path", sha256] tags and ["server", url] Blossom
* hints — no separate kind 10002 or kind 10063 published
*
* Named sites (kind 35128, siteIdentifier set):
* URL = https://{base36pubkey}{siteIdentifier}.{gateway}
@@ -367,8 +367,10 @@ export class NsiteAdapter implements DeployAdapter {
pathTags.push(['path', '/404.html', indexFile.sha256]);
}
// NIP-5A defines no relay-hint tag for a manifest, so the relays a site was
// published to are not written into it. Where to find the event is the
// reader's problem and the author's kind 10002, not the manifest's.
const serverTags: string[][] = serverBases.map(url => ['server', url]);
const relayTags: string[][] = this.relayUrls.map(url => ['relay', url]);
const tags: string[][] = [];
@@ -377,7 +379,7 @@ export class NsiteAdapter implements DeployAdapter {
tags.push(['d', this.siteIdentifier]);
}
tags.push(...pathTags, ...serverTags, ...relayTags);
tags.push(...pathTags, ...serverTags);
if (this.siteTitle) {
tags.push(['title', this.siteTitle]);
@@ -399,7 +401,7 @@ export class NsiteAdapter implements DeployAdapter {
});
// ── Step 5: Publish manifest ──────────────────────────────────────────────
// Relay and server hints are embedded as tags in the manifest itself —
// Blossom server hints are embedded as tags in the manifest itself —
// no separate kind 10002 or kind 10063 events are published.
//
// Relay by relay, because the site is only as findable as the relays that
+10 -7
View File
@@ -154,15 +154,15 @@ describe('republishTags', () => {
const tags = republishTags(
{ ...manifest, tags: [...manifest.tags, ['relay', 'wss://gone.example']] },
'mysite',
['wss://relay.ditto.pub'],
{ title: 'My Site', description: 'What it is for.' },
);
expect(tags[0]).toEqual(['d', 'mysite']);
expect(tags).toContainEqual(['path', '/index.html', 'c'.repeat(64)]);
expect(tags).toContainEqual(['server', 'https://blossom.ditto.pub/']);
expect(tags).toContainEqual(['relay', 'wss://relay.ditto.pub']);
expect(tags).not.toContainEqual(['relay', 'wss://gone.example']);
// NIP-5A has no relay-hint tag, so the archive's are dropped and none of
// ours take their place.
expect(tags.some(([name]) => name === 'relay' || name === 'r')).toBe(false);
expect(tags.filter(([name]) => name === 'd')).toHaveLength(1);
// The archive's title was the hostname and its `alt` says the site is
@@ -180,7 +180,7 @@ describe('republishTags', () => {
// Roughly a third of these are shells that set their title from JavaScript.
// No title is what an nsite manifest without one has always meant, and is
// better than a domain wearing a name's clothes.
const tags = republishTags(manifest, 'mysite', [], {});
const tags = republishTags(manifest, 'mysite', {});
expect(tags.some(([name]) => name === 'title')).toBe(false);
expect(tags).toContainEqual(['path', '/index.html', 'c'.repeat(64)]);
@@ -188,7 +188,7 @@ describe('republishTags', () => {
});
describe('retitleTags', () => {
it('swaps the archive’s words and passes everything else through', () => {
it('swaps the archive’s words, drops the tags NIP-5A never had, and passes the rest through', () => {
const event = {
id: 'e'.repeat(64),
pubkey: PUBKEY,
@@ -208,10 +208,13 @@ describe('retitleTags', () => {
const tags = retitleTags(event, { title: 'My Site' });
expect(tags).toContainEqual(['d', 'mysite']);
expect(tags).toContainEqual(['path', '/index.html', 'c'.repeat(64)]);
// Built from the event as relays hold it, so a site redeployed since this
// migration ran keeps whatever it has become.
expect(tags).toContainEqual(['relay', 'wss://relay.ditto.pub']);
expect(tags).toContainEqual(['path', '/index.html', 'c'.repeat(64)]);
expect(tags).toContainEqual(['server', 'https://blossom.ditto.pub/']);
// Except the relay hints an older deploy wrote, which re-signing is the
// chance to stop carrying.
expect(tags.some(([name]) => name === 'relay')).toBe(false);
expect(tags).toContainEqual(['title', 'My Site']);
expect(tags.filter(([name]) => name === 'title')).toHaveLength(1);
});
+12 -6
View File
@@ -208,13 +208,14 @@ export function planClaim(
* called gets no title, which is what an nsite manifest without one has always
* meant and is more honest than a domain.
*
* Relay hints are replaced for the same reason: the archive's say where the
* archive published, and this event is going somewhere else.
* The archive's relay hints are dropped and not replaced. NIP-5A gives a
* manifest no tag for saying where it was published, so the archive's `relay`
* and `r` tags are tags that were never part of the spec, and re-signing them
* under someone else's key would only spread them further.
*/
export function republishTags(
manifest: NpanelClaimManifest,
identifier: string,
relayUrls: string[],
identity: SiteIdentity = {},
): string[][] {
const kept = manifest.tags.filter(
@@ -226,7 +227,6 @@ export function republishTags(
['d', identifier],
...kept,
...describeTags(identity),
...relayUrls.map((url) => ['relay', url]),
];
}
@@ -237,10 +237,16 @@ export function republishTags(
* holds, because the two are not always the same thing: a site republished by
* this migration and then redeployed normally has moved on, and rebuilding it
* out of the gateway's copy would quietly restore an older version of the site.
* Everything but the archive's own words is passed through untouched.
* Everything but the archive's own words and the relay hints NIP-5A never
* defined is passed through untouched; signing an event is the moment to stop
* carrying a tag that does not exist.
*/
export function retitleTags(event: NostrEvent, identity: SiteIdentity): string[][] {
return [...event.tags.filter(([name]) => !ARCHIVE_TAGS.has(name)), ...describeTags(identity)];
const kept = event.tags.filter(
([name]) => name !== 'relay' && name !== 'r' && !ARCHIVE_TAGS.has(name),
);
return [...kept, ...describeTags(identity)];
}
/**
+9 -1
View File
@@ -573,5 +573,13 @@
"failedToDuplicateProject": "Failed to duplicate project",
"newProjectName": "New Project Name",
"duplicateProjectDescription": "Create a copy of this project with a new name",
"resume": "Resume"
"resume": "Resume",
"printReceipt": "Print Receipt",
"receipt": "Receipt",
"receiptNumber": "Receipt #",
"date": "Date",
"status": "Status",
"paymentMethodLabel": "Payment Method",
"totalCharged": "Total Charged",
"thankYouForPurchase": "Thank you for your purchase!"
}
+9 -1
View File
@@ -487,5 +487,13 @@
"failedToDuplicateProject": "An kasa kwafin aikin",
"newProjectName": "Sunan Sabon Aikin",
"duplicateProjectDescription": "Ƙirƙiri kwafin wannan aikin da sabon suna",
"resume": "Ci gaba"
"resume": "Ci gaba",
"printReceipt": "Buga Rasidi",
"receipt": "Rasidi",
"receiptNumber": "Rasidi #",
"date": "Kwanan wata",
"status": "Matsayi",
"paymentMethodLabel": "Hanyar Biyan Kuɗi",
"totalCharged": "Jimlar da aka Caji",
"thankYouForPurchase": "Mun gode da sayan ku!"
}
+9 -1
View File
@@ -484,5 +484,13 @@
"failedToDuplicateProject": "Ọ dara ada imepụta ọrụ",
"newProjectName": "Aha Ọrụ Ọhụrụ",
"duplicateProjectDescription": "Mepụta oyiri nke ọrụ a na aha ọhụrụ",
"resume": "Gaa n'ihu"
"resume": "Gaa n'ihu",
"printReceipt": "Bipụta Risịịtị",
"receipt": "Risịịtị",
"receiptNumber": "Risịịtị #",
"date": "Ụbọchị",
"status": "Ọnọdụ",
"paymentMethodLabel": "Ụzọ Ịkwụ Ụgwọ",
"totalCharged": "Nchịkọta Ego a Gbara",
"thankYouForPurchase": "Daalụ maka ịzụta gị!"
}
+9 -1
View File
@@ -496,5 +496,13 @@
"failedToDuplicateProject": "Falha ao duplicar projeto",
"newProjectName": "Nome do Novo Projeto",
"duplicateProjectDescription": "Criar uma cópia deste projeto com um novo nome",
"resume": "Retomar"
"resume": "Retomar",
"printReceipt": "Imprimir Recibo",
"receipt": "Recibo",
"receiptNumber": "Recibo Nº",
"date": "Data",
"status": "Status",
"paymentMethodLabel": "Método de Pagamento",
"totalCharged": "Total Cobrado",
"thankYouForPurchase": "Obrigado pela sua compra!"
}
+9 -1
View File
@@ -484,5 +484,13 @@
"failedToDuplicateProject": "O kuna lati ṣe ẹda iṣẹ akanṣe",
"newProjectName": "Orukọ Iṣẹ Akanṣe Tuntun",
"duplicateProjectDescription": "Ṣẹda ẹda ti iṣẹ akanṣe yii pẹlu orukọ tuntun",
"resume": "Tẹsiwaju"
"resume": "Tẹsiwaju",
"printReceipt": "Tẹ Ìwé Ẹ̀rí",
"receipt": "Ìwé Ẹ̀rí",
"receiptNumber": "Ìwé Ẹ̀rí #",
"date": "Ọjọ́",
"status": "Ipò",
"paymentMethodLabel": "Ọ̀nà Ìsanwó",
"totalCharged": "Àpapọ̀ tí a gba",
"thankYouForPurchase": "A dúpẹ́ fún rírà rẹ!"
}
+9 -1
View File
@@ -496,5 +496,13 @@
"failedToDuplicateProject": "复制项目失败",
"newProjectName": "新项目名称",
"duplicateProjectDescription": "使用新名称创建此项目的副本",
"resume": "继续"
"resume": "继续",
"printReceipt": "打印收据",
"receipt": "收据",
"receiptNumber": "收据编号",
"date": "日期",
"status": "状态",
"paymentMethodLabel": "支付方式",
"totalCharged": "总收费",
"thankYouForPurchase": "感谢您的购买!"
}