feature/billing-settings #15
22 changed files with 880 additions and 68 deletions
|
|
@ -32,6 +32,7 @@ OPENAI_TRANSLATIONS_KEY=
|
|||
HETZNER_API_TOKEN=
|
||||
HCLOUD_TOKEN=
|
||||
HETZNER_TOKEN=
|
||||
N8N_BILLING_API_KEY=
|
||||
JOKER_DYNDNS_USERNAME=
|
||||
JOKER_DYNDNS_PASSWORD=
|
||||
REGISTRY_USERNAME=
|
||||
|
|
|
|||
|
|
@ -4,4 +4,5 @@ creation_rules:
|
|||
key_groups:
|
||||
- age:
|
||||
- age1hkehkc2rryjl975c2mg5cghmjr54n4wjshncl292h2eg5l394fhs4uydrh
|
||||
encrypted_regex: '^(AUTH_SECRET|DATABASE_URL|DB_.*|APP_URL|SMTP_.*|DKIM_.*|AUTO_APPROVE_LISTINGS|OPENAI_.*|H(ETZNER|CLOUD)_TOKEN|JOKER_DYNDNS_.*|REGISTRY_.*|NETDATA_.*|ADMIN_.*)$'
|
||||
- age1ducvqxdzdhhluftu5hv4f2xsppmn803uh8tnnqj92v4n7nf6lprq9h3dqp
|
||||
encrypted_regex: '^(AUTH_SECRET|DATABASE_URL|DB_.*|APP_URL|SMTP_.*|DKIM_.*|AUTO_APPROVE_LISTINGS|OPENAI_.*|N8N_BILLING_API_KEY|H(ETZNER|CLOUD)_TOKEN|JOKER_DYNDNS_.*|REGISTRY_.*|NETDATA_.*|ADMIN_.*)$'
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
- Assume full access to network, shell commands, and all files under the current working directory.
|
||||
- On session start, open `PROGRESS.md` to refresh project status.
|
||||
- When updating `PROGRESS.md`, add a date marker (e.g., `## YYYY-MM-DD — …`) and list changes under it until the date changes; keep earlier entries intact and sorted by date.
|
||||
- After that, scan the repo structure (e.g., list key dirs/files) to regain context before continuing work.
|
||||
- After finishing each new feature, create a git commit with a sensible message and update documentation to reflect the changes.
|
||||
|
||||
|
|
|
|||
16
PROGRESS.md
16
PROGRESS.md
|
|
@ -1,4 +1,4 @@
|
|||
# Lomavuokraus infra progress (Nov 22)
|
||||
## 2025-11-22 — Lomavuokraus infra progress
|
||||
|
||||
- Repo initialized with Next.js App Router scaffold:
|
||||
- Health endpoint: `app/api/health/route.ts`
|
||||
|
|
@ -25,7 +25,7 @@
|
|||
- `AUTH_SECRET` removed from `deploy/env.sh`; export it in shell (or via `scripts/load-secrets.sh`) before deploy.
|
||||
- `creds/` and `k3s.yaml` are git-ignored; contains joker DYNDNS creds and registry auth.
|
||||
|
||||
# Lomavuokraus app progress (Nov 24)
|
||||
## 2025-11-24 — Lomavuokraus app progress
|
||||
- New testing DB (`lomavuokraus_testing`) holds the previous staging/prod data; the main `lomavuokraus` DB was recreated clean with only the seeded admin user. Migration history was copied, and a schema snapshot lives at `docs/db-schema.sql`.
|
||||
- Testing environment wiring added: dedicated namespace (`lomavuokraus-test`), deploy wrapper (`deploy/deploy-test.sh`), API host support, and a DNS updater for `test.lomavuokraus.fi` / `apitest.lomavuokraus.fi`.
|
||||
- Access control tightened: middleware now gates admin routes, admin-only pages check session/role, API handlers return proper 401/403, and listing removal is limited to owners/admins (no more moderator overrides).
|
||||
|
|
@ -40,7 +40,7 @@
|
|||
- Latest images built/pushed: `registry.halla-aho.net/thalla/lomavuokraus-web:1763993882` (approvals badge + FI/EN localization) and `:1763994382` (profile edit). Staging/prod rolled out.
|
||||
- Security: `npm audit --audit-level=high` runs in build (warnings only). Trivy scan run; remaining CVEs mostly in tooling (cross-spawn, glob) and base OS Debian 12.10. Further reduction would require eslint-config-next 16.x and base image updates when available.
|
||||
|
||||
# Recent changes (Nov 24, later)
|
||||
## 2025-11-24 — Recent changes
|
||||
- Public browse/search page with map, address filters, and EV charging amenity; listings now store street address and geocoordinates.
|
||||
- Amenities expanded: electric vehicle charging (free/paid) and air conditioning; cover image selectable per listing and used in cards.
|
||||
- Home page shows a rolling feed of latest listings; navbar + CTA link to browse.
|
||||
|
|
@ -69,8 +69,8 @@
|
|||
- Centralized logging stack scaffolded (Loki + Promtail + Grafana) with Helm values and install script; Grafana ingress defaults to `logs.lomavuokraus.fi`.
|
||||
- Logging: Loki+Promtail+Grafana deployed to `logging` namespace; DNS updated for `logs.lomavuokraus.fi`; Grafana admin password reset due to PVC-stored credentials overriding the secret.
|
||||
- Mermaid docs fixed: all sequence diagrams declare their participants and avoid “->” inside message text; the listing creation diagram message was rewritten to prevent parse errors. Use mermaid.live or browser console to debug future syntax issues (errors flag the offending line/column).
|
||||
- New amenities added: kitchen, dishwasher, washing machine, barbecue; API/UI/i18n updated and seeds randomized to populate missing prices/amenities. Prisma migration `20250210_more_amenities` applied to shared DB; registry pull secret added to k8s Deployment to avoid image pull errors in prod.
|
||||
- Added About and Pricing pages (FI/EN), moved highlights/runtime config to About, and linked footer navigation.
|
||||
|
||||
## 2025-11-27 — Availability & filters
|
||||
- Availability calendars: listings can store iCal URLs, merged into a combined availability calendar on detail pages; availability filtering added to search along with amenity filters; new migration `20251127_calendar_urls`.
|
||||
- Browse amenity filters now show the same icons as listing detail; image `registry.halla-aho.net/thalla/lomavuokraus-web:e95d9e0` built/pushed and rolled out to staging.
|
||||
- Home hero cleaned up (removed sample/browse CTAs), hero FI text updated, and health check link moved to About page runtime section.
|
||||
|
|
@ -80,8 +80,14 @@
|
|||
- Language selector in the navbar aligned with other buttons and given higher-contrast styling.
|
||||
- Listing edit page now lets owners delete individual images (with cover/order preserved), and a protected API endpoint handles image removal.
|
||||
- Security hardening: npm audit now passes cleanly after upgrading Prisma patch release and pinning `glob@10.5.0` via overrides to eliminate the glob CLI injection advisory in eslint tooling.
|
||||
|
||||
## 2025-12-06 — Pricing & amenities
|
||||
- Listings now capture separate weekday/weekend prices and new amenities (microwave, free parking) across schema, API, UI, and seeds.
|
||||
- Deployed pricing/amenity update image `registry.halla-aho.net/thalla/lomavuokraus-web:bee691e` to staging and production.
|
||||
|
||||
## 2025-12-17 — Accessibility & admin UX
|
||||
- New amenities added: kitchen, dishwasher, washing machine, barbecue; API/UI/i18n updated and seeds randomized to populate missing prices/amenities. Prisma migration `20250210_more_amenities` applied to shared DB; registry pull secret added to k8s Deployment to avoid image pull errors in prod.
|
||||
- Added About and Pricing pages (FI/EN), moved highlights/runtime config to About, and linked footer navigation.
|
||||
- Added site favicon generated from the updated logo (`public/favicon.ico`).
|
||||
- New admin monitoring dashboard at `/admin/monitor` surfaces Hetzner node status, Kubernetes nodes/pods health, and PostgreSQL connection/size checks with auto-refresh.
|
||||
- Netdata installed on k3s node (`node1.lomavuokraus.fi:8443`) and DB host (`db1.lomavuokraus.fi:8443`) behind self-signed TLS + basic auth; DB Netdata includes Postgres metrics via dedicated `netdata` role.
|
||||
|
|
|
|||
|
|
@ -15,3 +15,5 @@ export async function GET(req: Request) {
|
|||
return NextResponse.json({ user: null }, { status: 200 });
|
||||
}
|
||||
}
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
|
|
|||
|
|
@ -37,3 +37,5 @@ export async function POST(req: Request) {
|
|||
return NextResponse.json({ error: 'Verification failed' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
|
|
|||
137
app/api/integrations/billing/verify/route.ts
Normal file
137
app/api/integrations/billing/verify/route.ts
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
import { NextResponse } from 'next/server';
|
||||
import { ListingStatus, UserStatus } from '@prisma/client';
|
||||
import { prisma } from '../../../../../lib/prisma';
|
||||
import { loadN8nBillingApiKey } from '../../../../../lib/apiKeys';
|
||||
import { resolveBillingDetails } from '../../../../../lib/billing';
|
||||
|
||||
function pickTranslation(translations: { slug: string; locale: string }[]) {
|
||||
return translations.find((t) => t.locale === 'en') || translations.find((t) => t.locale === 'fi') || translations[0] || null;
|
||||
}
|
||||
|
||||
function extractApiKey(req: Request) {
|
||||
const headerKey = req.headers.get('x-api-key');
|
||||
if (headerKey) return headerKey.trim();
|
||||
const auth = req.headers.get('authorization');
|
||||
if (auth && auth.toLowerCase().startsWith('bearer ')) {
|
||||
return auth.slice(7).trim();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export async function POST(req: Request) {
|
||||
const expectedKey = loadN8nBillingApiKey();
|
||||
if (!expectedKey) {
|
||||
return NextResponse.json({ error: 'Billing API key missing' }, { status: 500 });
|
||||
}
|
||||
const providedKey = extractApiKey(req);
|
||||
if (!providedKey || providedKey !== expectedKey) {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
}
|
||||
|
||||
let body: any;
|
||||
try {
|
||||
body = await req.json();
|
||||
} catch {
|
||||
return NextResponse.json({ error: 'Invalid payload' }, { status: 400 });
|
||||
}
|
||||
|
||||
const listingId = typeof body.listingId === 'string' ? body.listingId : undefined;
|
||||
const listingSlug = typeof body.listingSlug === 'string' ? body.listingSlug.trim() : undefined;
|
||||
const ownerEmailRaw = typeof body.ownerEmail === 'string' ? body.ownerEmail.trim() : undefined;
|
||||
const ownerEmail = ownerEmailRaw ? ownerEmailRaw.toLowerCase() : undefined;
|
||||
|
||||
if (!listingId && !listingSlug && !ownerEmail) {
|
||||
return NextResponse.json({ error: 'Provide listingId, listingSlug, or ownerEmail' }, { status: 400 });
|
||||
}
|
||||
|
||||
let listing: any = null;
|
||||
if (listingId || listingSlug) {
|
||||
const listings = await prisma.listing.findMany({
|
||||
where: {
|
||||
removedAt: null,
|
||||
status: { not: ListingStatus.REMOVED },
|
||||
id: listingId ?? undefined,
|
||||
translations: listingSlug ? { some: { slug: listingSlug } } : undefined,
|
||||
},
|
||||
include: {
|
||||
owner: {
|
||||
select: {
|
||||
id: true,
|
||||
email: true,
|
||||
status: true,
|
||||
approvedAt: true,
|
||||
emailVerifiedAt: true,
|
||||
billingEmailsEnabled: true,
|
||||
billingAccountName: true,
|
||||
billingIban: true,
|
||||
billingIncludeVatLine: true,
|
||||
},
|
||||
},
|
||||
translations: { select: { slug: true, locale: true } },
|
||||
},
|
||||
take: listingSlug ? 2 : 1,
|
||||
});
|
||||
|
||||
if (listingSlug && listings.length > 1) {
|
||||
return NextResponse.json({ error: 'Listing slug is ambiguous; provide listingId' }, { status: 400 });
|
||||
}
|
||||
listing = listings[0] ?? null;
|
||||
if (!listing && listingId) {
|
||||
return NextResponse.json({ error: 'Listing not found' }, { status: 404 });
|
||||
}
|
||||
if (!listing && listingSlug) {
|
||||
return NextResponse.json({ error: 'Listing not found' }, { status: 404 });
|
||||
}
|
||||
}
|
||||
|
||||
let owner = listing?.owner ?? null;
|
||||
if (!owner && ownerEmail) {
|
||||
owner = await prisma.user.findFirst({
|
||||
where: { email: { equals: ownerEmail, mode: 'insensitive' } },
|
||||
select: {
|
||||
id: true,
|
||||
email: true,
|
||||
status: true,
|
||||
approvedAt: true,
|
||||
emailVerifiedAt: true,
|
||||
billingEmailsEnabled: true,
|
||||
billingAccountName: true,
|
||||
billingIban: true,
|
||||
billingIncludeVatLine: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (!owner) {
|
||||
return NextResponse.json({ enabled: false });
|
||||
}
|
||||
|
||||
const ownerReady = owner.status === UserStatus.ACTIVE && owner.approvedAt && owner.emailVerifiedAt;
|
||||
if (!ownerReady || !owner.billingEmailsEnabled) {
|
||||
return NextResponse.json({ enabled: false, owner: { id: owner.id, email: owner.email } });
|
||||
}
|
||||
|
||||
const billing = resolveBillingDetails(owner, listing ?? undefined);
|
||||
const enabled = Boolean(billing.accountName && billing.iban);
|
||||
const listingHasOverride =
|
||||
listing &&
|
||||
(listing.billingAccountName !== null && listing.billingAccountName !== undefined ||
|
||||
listing.billingIban !== null && listing.billingIban !== undefined ||
|
||||
listing.billingIncludeVatLine !== null && listing.billingIncludeVatLine !== undefined);
|
||||
const source = listingHasOverride ? 'listing' : 'user';
|
||||
|
||||
return NextResponse.json({
|
||||
enabled,
|
||||
owner: { id: owner.id, email: owner.email },
|
||||
listing: listing
|
||||
? {
|
||||
id: listing.id,
|
||||
slug: pickTranslation(listing.translations)?.slug ?? listing.translations[0]?.slug ?? null,
|
||||
status: listing.status,
|
||||
}
|
||||
: null,
|
||||
billing: enabled ? { ...billing, source } : null,
|
||||
});
|
||||
}
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
215
app/api/me/billing/route.ts
Normal file
215
app/api/me/billing/route.ts
Normal file
|
|
@ -0,0 +1,215 @@
|
|||
import { NextResponse } from 'next/server';
|
||||
import { UserStatus } from '@prisma/client';
|
||||
import { prisma } from '../../../../lib/prisma';
|
||||
import { requireAuth } from '../../../../lib/jwt';
|
||||
import { normalizeIban, normalizeNullableBoolean, normalizeOptionalString } from '../../../../lib/billing';
|
||||
|
||||
function pickTranslation(translations: { title: string; slug: string; locale: string }[]) {
|
||||
return translations.find((t) => t.locale === 'en') || translations.find((t) => t.locale === 'fi') || translations[0] || null;
|
||||
}
|
||||
|
||||
async function loadState(userId: string) {
|
||||
const [user, listings] = await Promise.all([
|
||||
prisma.user.findUnique({
|
||||
where: { id: userId },
|
||||
select: {
|
||||
id: true,
|
||||
status: true,
|
||||
billingEmailsEnabled: true,
|
||||
billingAccountName: true,
|
||||
billingIban: true,
|
||||
billingIncludeVatLine: true,
|
||||
},
|
||||
}),
|
||||
prisma.listing.findMany({
|
||||
where: { ownerId: userId, removedAt: null },
|
||||
select: {
|
||||
id: true,
|
||||
billingAccountName: true,
|
||||
billingIban: true,
|
||||
billingIncludeVatLine: true,
|
||||
translations: { select: { title: true, slug: true, locale: true } },
|
||||
},
|
||||
orderBy: { createdAt: 'desc' },
|
||||
}),
|
||||
]);
|
||||
return { user, listings };
|
||||
}
|
||||
|
||||
function validateAccountName(name: string | null | undefined) {
|
||||
if (name && name.length > 120) {
|
||||
return 'Account owner name is too long';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function validateIban(iban: string | null | undefined) {
|
||||
if (iban && !/^[A-Z0-9]{8,34}$/.test(iban)) {
|
||||
return 'IBAN must be 8-34 alphanumeric characters';
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function normalizeListingOverrides(body: any) {
|
||||
type OverrideInput = { id: string | null; accountName: string | null | undefined; iban: string | null | undefined; includeVatLine: boolean | null | undefined };
|
||||
const overridesRaw: any[] = Array.isArray(body?.listings) ? body.listings : [];
|
||||
const mapped: OverrideInput[] = overridesRaw.map((item: any) => ({
|
||||
id: typeof item.id === 'string' ? item.id : null,
|
||||
accountName: normalizeOptionalString(item.accountName),
|
||||
iban: normalizeIban(item.iban),
|
||||
includeVatLine: normalizeNullableBoolean(item.includeVatLine),
|
||||
}));
|
||||
return mapped.filter((o): o is OverrideInput & { id: string } => Boolean(o.id));
|
||||
}
|
||||
|
||||
function buildResponsePayload(user: NonNullable<Awaited<ReturnType<typeof loadState>>['user']>, listings: Awaited<ReturnType<typeof loadState>>['listings']) {
|
||||
return {
|
||||
settings: {
|
||||
enabled: user.billingEmailsEnabled,
|
||||
accountName: user.billingAccountName,
|
||||
iban: user.billingIban,
|
||||
includeVatLine: user.billingIncludeVatLine,
|
||||
},
|
||||
listings: listings.map((listing) => {
|
||||
const translation = pickTranslation(listing.translations);
|
||||
return {
|
||||
id: listing.id,
|
||||
title: translation?.title ?? 'Listing',
|
||||
slug: translation?.slug ?? '',
|
||||
locale: translation?.locale ?? 'en',
|
||||
billingAccountName: listing.billingAccountName,
|
||||
billingIban: listing.billingIban,
|
||||
billingIncludeVatLine: listing.billingIncludeVatLine,
|
||||
};
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
export async function GET(req: Request) {
|
||||
try {
|
||||
const session = await requireAuth(req);
|
||||
const { user, listings } = await loadState(session.userId);
|
||||
if (!user || user.status !== UserStatus.ACTIVE) {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
}
|
||||
return NextResponse.json(buildResponsePayload(user, listings));
|
||||
} catch (error) {
|
||||
console.error('Billing settings fetch failed', error);
|
||||
return NextResponse.json({ error: 'Failed to load billing settings' }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
export async function PATCH(req: Request) {
|
||||
let body: any;
|
||||
try {
|
||||
body = await req.json();
|
||||
} catch {
|
||||
return NextResponse.json({ error: 'Invalid request body' }, { status: 400 });
|
||||
}
|
||||
|
||||
try {
|
||||
const session = await requireAuth(req);
|
||||
const { user, listings } = await loadState(session.userId);
|
||||
if (!user || user.status !== UserStatus.ACTIVE) {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
}
|
||||
|
||||
const enabled = body.enabled === undefined ? undefined : Boolean(body.enabled);
|
||||
const accountName = normalizeOptionalString(body.accountName);
|
||||
const iban = normalizeIban(body.iban);
|
||||
const includeVatLine = body.includeVatLine === undefined ? undefined : Boolean(body.includeVatLine);
|
||||
const listingOverrides = normalizeListingOverrides(body);
|
||||
|
||||
const errors = [validateAccountName(accountName), validateIban(iban)].filter(Boolean) as string[];
|
||||
for (const override of listingOverrides) {
|
||||
const nameError = validateAccountName(override.accountName);
|
||||
const ibanError = validateIban(override.iban);
|
||||
if (nameError) errors.push(`${nameError} for listing ${override.id}`);
|
||||
if (ibanError) errors.push(`${ibanError} for listing ${override.id}`);
|
||||
}
|
||||
if (errors.length) {
|
||||
return NextResponse.json({ error: errors.join('; ') }, { status: 400 });
|
||||
}
|
||||
|
||||
const userUpdates: any = {};
|
||||
if (enabled !== undefined) userUpdates.billingEmailsEnabled = enabled;
|
||||
if (accountName !== undefined) userUpdates.billingAccountName = accountName;
|
||||
if (iban !== undefined) userUpdates.billingIban = iban;
|
||||
if (includeVatLine !== undefined) userUpdates.billingIncludeVatLine = includeVatLine;
|
||||
|
||||
const listingMap = new Map(listings.map((l) => [l.id, l]));
|
||||
const listingUpdates: { id: string; data: Record<string, any> }[] = [];
|
||||
listingOverrides.forEach((override: { id: string; accountName: string | null | undefined; iban: string | null | undefined; includeVatLine: boolean | null | undefined }) => {
|
||||
if (!listingMap.has(override.id!)) return;
|
||||
const data: Record<string, any> = {};
|
||||
if (override.accountName !== undefined) data.billingAccountName = override.accountName;
|
||||
if (override.iban !== undefined) data.billingIban = override.iban;
|
||||
if (override.includeVatLine !== undefined) data.billingIncludeVatLine = override.includeVatLine;
|
||||
if (Object.keys(data).length) {
|
||||
listingUpdates.push({ id: override.id!, data });
|
||||
}
|
||||
});
|
||||
|
||||
const targetEnabled = enabled ?? user.billingEmailsEnabled;
|
||||
if (targetEnabled) {
|
||||
const targetAccountName = accountName !== undefined ? accountName : user.billingAccountName;
|
||||
const targetIban = iban !== undefined ? iban : user.billingIban;
|
||||
const hasGlobalDetails = Boolean(targetAccountName && targetIban);
|
||||
|
||||
const missingFor: string[] = [];
|
||||
listings.forEach((listing) => {
|
||||
const override = listingUpdates.find((o) => o.id === listing.id);
|
||||
const effectiveAccountName =
|
||||
override?.data.billingAccountName !== undefined
|
||||
? override.data.billingAccountName
|
||||
: listing.billingAccountName ?? targetAccountName;
|
||||
const effectiveIban =
|
||||
override?.data.billingIban !== undefined ? override.data.billingIban : listing.billingIban ?? targetIban;
|
||||
if (!effectiveAccountName || !effectiveIban) {
|
||||
const t = pickTranslation(listing.translations);
|
||||
missingFor.push(t?.slug || listing.id);
|
||||
}
|
||||
});
|
||||
|
||||
if (!hasGlobalDetails && missingFor.length) {
|
||||
return NextResponse.json(
|
||||
{ error: `Provide billing account name and IBAN globally or per listing (missing for: ${missingFor.join(', ')})` },
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
if (!hasGlobalDetails && listings.length === 0) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Add a billing account name and IBAN before enabling the billing assistant.' },
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const tx: any[] = [];
|
||||
if (Object.keys(userUpdates).length) {
|
||||
tx.push(prisma.user.update({ where: { id: user.id }, data: userUpdates }));
|
||||
}
|
||||
listingUpdates.forEach((update) => {
|
||||
tx.push(prisma.listing.update({ where: { id: update.id }, data: update.data }));
|
||||
});
|
||||
|
||||
if (tx.length) {
|
||||
await prisma.$transaction(tx);
|
||||
} else {
|
||||
return NextResponse.json({ error: 'No updates provided' }, { status: 400 });
|
||||
}
|
||||
|
||||
const { user: updatedUser, listings: updatedListings } = await loadState(session.userId);
|
||||
if (!updatedUser) {
|
||||
return NextResponse.json({ error: 'User not found' }, { status: 404 });
|
||||
}
|
||||
|
||||
return NextResponse.json(buildResponsePayload(updatedUser, updatedListings));
|
||||
} catch (error) {
|
||||
console.error('Billing settings update failed', error);
|
||||
const status = (error as any)?.message === 'Unauthorized' ? 401 : 500;
|
||||
return NextResponse.json({ error: 'Failed to update billing settings' }, { status });
|
||||
}
|
||||
}
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
221
app/me/page.tsx
221
app/me/page.tsx
|
|
@ -4,6 +4,15 @@ import { useEffect, useState } from 'react';
|
|||
import { useI18n } from '../components/I18nProvider';
|
||||
|
||||
type User = { id: string; email: string; role: string; status: string; emailVerifiedAt: string | null; approvedAt: string | null; name: string | null; phone: string | null };
|
||||
type BillingListing = {
|
||||
id: string;
|
||||
title: string;
|
||||
slug: string;
|
||||
locale: string;
|
||||
billingAccountName: string | null;
|
||||
billingIban: string | null;
|
||||
billingIncludeVatLine: boolean | null;
|
||||
};
|
||||
|
||||
export default function ProfilePage() {
|
||||
const { t } = useI18n();
|
||||
|
|
@ -14,6 +23,15 @@ export default function ProfilePage() {
|
|||
const [password, setPassword] = useState('');
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [message, setMessage] = useState<string | null>(null);
|
||||
const [billingEnabled, setBillingEnabled] = useState(false);
|
||||
const [billingAccountName, setBillingAccountName] = useState('');
|
||||
const [billingIban, setBillingIban] = useState('');
|
||||
const [billingIncludeVatLine, setBillingIncludeVatLine] = useState(false);
|
||||
const [billingListings, setBillingListings] = useState<BillingListing[]>([]);
|
||||
const [billingLoading, setBillingLoading] = useState(false);
|
||||
const [billingSaving, setBillingSaving] = useState(false);
|
||||
const [billingMessage, setBillingMessage] = useState<string | null>(null);
|
||||
const [billingError, setBillingError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
fetch('/api/auth/me', { cache: 'no-store' })
|
||||
|
|
@ -28,6 +46,38 @@ export default function ProfilePage() {
|
|||
.catch(() => setError(t('notLoggedIn')));
|
||||
}, [t]);
|
||||
|
||||
useEffect(() => {
|
||||
setBillingLoading(true);
|
||||
fetch('/api/me/billing', { cache: 'no-store' })
|
||||
.then(async (res) => {
|
||||
const data = await res.json();
|
||||
if (!res.ok) throw new Error(data.error || 'Failed');
|
||||
return data;
|
||||
})
|
||||
.then((data) => {
|
||||
setBillingEnabled(Boolean(data.settings?.enabled));
|
||||
setBillingAccountName(data.settings?.accountName ?? '');
|
||||
setBillingIban(data.settings?.iban ?? '');
|
||||
setBillingIncludeVatLine(Boolean(data.settings?.includeVatLine));
|
||||
setBillingListings(
|
||||
Array.isArray(data.listings)
|
||||
? data.listings.map((l: any) => ({
|
||||
id: l.id,
|
||||
title: l.title,
|
||||
slug: l.slug,
|
||||
locale: l.locale,
|
||||
billingAccountName: l.billingAccountName ?? '',
|
||||
billingIban: l.billingIban ?? '',
|
||||
billingIncludeVatLine: l.billingIncludeVatLine ?? null,
|
||||
}))
|
||||
: [],
|
||||
);
|
||||
setBillingError(null);
|
||||
})
|
||||
.catch(() => setBillingError(t('billingLoadFailed')))
|
||||
.finally(() => setBillingLoading(false));
|
||||
}, [t]);
|
||||
|
||||
async function onSave(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
setSaving(true);
|
||||
|
|
@ -54,6 +104,58 @@ export default function ProfilePage() {
|
|||
}
|
||||
}
|
||||
|
||||
async function onSaveBilling(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
setBillingSaving(true);
|
||||
setBillingError(null);
|
||||
setBillingMessage(null);
|
||||
try {
|
||||
const res = await fetch('/api/me/billing', {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
enabled: billingEnabled,
|
||||
accountName: billingAccountName,
|
||||
iban: billingIban,
|
||||
includeVatLine: billingIncludeVatLine,
|
||||
listings: billingListings.map((l) => ({
|
||||
id: l.id,
|
||||
accountName: l.billingAccountName,
|
||||
iban: l.billingIban,
|
||||
includeVatLine: l.billingIncludeVatLine,
|
||||
})),
|
||||
}),
|
||||
});
|
||||
const data = await res.json();
|
||||
if (!res.ok) {
|
||||
setBillingError(data.error || t('billingSaveFailed'));
|
||||
return;
|
||||
}
|
||||
setBillingEnabled(Boolean(data.settings?.enabled));
|
||||
setBillingAccountName(data.settings?.accountName ?? '');
|
||||
setBillingIban(data.settings?.iban ?? '');
|
||||
setBillingIncludeVatLine(Boolean(data.settings?.includeVatLine));
|
||||
setBillingListings(
|
||||
Array.isArray(data.listings)
|
||||
? data.listings.map((l: any) => ({
|
||||
id: l.id,
|
||||
title: l.title,
|
||||
slug: l.slug,
|
||||
locale: l.locale,
|
||||
billingAccountName: l.billingAccountName ?? '',
|
||||
billingIban: l.billingIban ?? '',
|
||||
billingIncludeVatLine: l.billingIncludeVatLine ?? null,
|
||||
}))
|
||||
: [],
|
||||
);
|
||||
setBillingMessage(t('billingSaved'));
|
||||
} catch (err) {
|
||||
setBillingError(t('billingSaveFailed'));
|
||||
} finally {
|
||||
setBillingSaving(false);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<main className="panel" style={{ maxWidth: 640, margin: '40px auto' }}>
|
||||
<h1>{t('myProfileTitle')}</h1>
|
||||
|
|
@ -109,6 +211,125 @@ export default function ProfilePage() {
|
|||
{saving ? t('saving') : t('save')}
|
||||
</button>
|
||||
</form>
|
||||
<section style={{ marginTop: 30 }}>
|
||||
<h2 style={{ marginBottom: 6 }}>{t('billingSettingsTitle')}</h2>
|
||||
<p style={{ color: '#444', marginBottom: 12 }}>{t('billingSettingsLead')}</p>
|
||||
{billingMessage ? <p style={{ color: 'green' }}>{billingMessage}</p> : null}
|
||||
{billingError ? <p style={{ color: 'red' }}>{billingError}</p> : null}
|
||||
<form onSubmit={onSaveBilling} style={{ display: 'grid', gap: 14, marginTop: 8 }}>
|
||||
<label style={{ display: 'flex', gap: 8, alignItems: 'center' }}>
|
||||
<input type="checkbox" checked={billingEnabled} onChange={(e) => setBillingEnabled(e.target.checked)} />
|
||||
<span>{t('billingEnableLabel')}</span>
|
||||
</label>
|
||||
{billingEnabled ? (
|
||||
<>
|
||||
<div style={{ display: 'grid', gap: 8 }}>
|
||||
<label>
|
||||
{t('billingAccountNameLabel')}
|
||||
<input value={billingAccountName} onChange={(e) => setBillingAccountName(e.target.value)} placeholder="Example Oy" />
|
||||
</label>
|
||||
<label>
|
||||
{t('billingIbanLabel')}
|
||||
<input value={billingIban} onChange={(e) => setBillingIban(e.target.value)} placeholder="FI00 1234 5600 0007 85" />
|
||||
</label>
|
||||
<label style={{ display: 'flex', gap: 8, alignItems: 'center' }}>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={billingIncludeVatLine}
|
||||
onChange={(e) => setBillingIncludeVatLine(e.target.checked)}
|
||||
/>
|
||||
<span>{t('billingIncludeVat')}</span>
|
||||
</label>
|
||||
</div>
|
||||
<div style={{ border: '1px solid #eee', padding: 12, borderRadius: 6 }}>
|
||||
<div style={{ marginBottom: 8 }}>
|
||||
<strong>{t('billingListingsTitle')}</strong>
|
||||
<div style={{ color: '#555', fontSize: 13 }}>{t('billingListingsLead')}</div>
|
||||
</div>
|
||||
{billingLoading ? (
|
||||
<p>{t('loading')}</p>
|
||||
) : billingListings.length === 0 ? (
|
||||
<p style={{ color: '#666' }}>{t('billingNoListings')}</p>
|
||||
) : (
|
||||
<div style={{ display: 'grid', gap: 12 }}>
|
||||
{billingListings.map((listing) => {
|
||||
const vatValue =
|
||||
listing.billingIncludeVatLine === null || listing.billingIncludeVatLine === undefined
|
||||
? 'inherit'
|
||||
: listing.billingIncludeVatLine
|
||||
? 'yes'
|
||||
: 'no';
|
||||
return (
|
||||
<div key={listing.id} style={{ border: '1px solid #f0f0f0', padding: 10, borderRadius: 4 }}>
|
||||
<div style={{ fontWeight: 600, marginBottom: 6 }}>
|
||||
{listing.title} ({listing.slug})
|
||||
</div>
|
||||
<div style={{ display: 'grid', gap: 8 }}>
|
||||
<label>
|
||||
{t('billingAccountNameLabel')}
|
||||
<input
|
||||
value={listing.billingAccountName ?? ''}
|
||||
onChange={(e) =>
|
||||
setBillingListings((prev) =>
|
||||
prev.map((l) => (l.id === listing.id ? { ...l, billingAccountName: e.target.value } : l)),
|
||||
)
|
||||
}
|
||||
placeholder={billingAccountName || t('billingAccountPlaceholder')}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
{t('billingIbanLabel')}
|
||||
<input
|
||||
value={listing.billingIban ?? ''}
|
||||
onChange={(e) =>
|
||||
setBillingListings((prev) =>
|
||||
prev.map((l) => (l.id === listing.id ? { ...l, billingIban: e.target.value } : l)),
|
||||
)
|
||||
}
|
||||
placeholder={billingIban || t('billingIbanPlaceholder')}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
{t('billingVatChoice')}
|
||||
<select
|
||||
value={vatValue as string}
|
||||
onChange={(e) => {
|
||||
const choice = e.target.value;
|
||||
setBillingListings((prev) =>
|
||||
prev.map((l) =>
|
||||
l.id === listing.id
|
||||
? {
|
||||
...l,
|
||||
billingIncludeVatLine: choice === 'inherit' ? null : choice === 'yes',
|
||||
}
|
||||
: l,
|
||||
),
|
||||
);
|
||||
}}
|
||||
>
|
||||
<option value="inherit">{t('billingVatInherit')}</option>
|
||||
<option value="yes">{t('billingVatYes')}</option>
|
||||
<option value="no">{t('billingVatNo')}</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<p style={{ color: '#666' }}>{t('billingDisabledHint')}</p>
|
||||
)}
|
||||
<div>
|
||||
<button className="button" type="submit" disabled={billingSaving}>
|
||||
{billingSaving ? t('saving') : t('save')}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
</>
|
||||
) : (
|
||||
<p style={{ color: 'red' }}>{error ?? t('notLoggedIn')}</p>
|
||||
|
|
|
|||
|
|
@ -1,50 +1,53 @@
|
|||
# Encrypted with sops (age). To edit: sops creds/secrets.enc.env
|
||||
AUTH_SECRET=ENC[AES256_GCM,data:70URX0qSS/z4AYb58kAmGA/gnEt9bBGPPN5L/xpg3vsna8A9jw+X,iv:iKicMbvIaBvPXncKcmJwsbjQzjxOa7xmkm8SXeZ8RUQ=,tag:2CXRV4I5YVz52aFm65WGhQ==,type:str]
|
||||
DATABASE_URL=ENC[AES256_GCM,data:t/E/j249UXAOY9gcnb15ozJOmvDC7Ffb9RnfzRUvH9HXEqVQPlh8jM8qonygiMHmXcWYqVnqtRcFbExGYNo1h6ZRoAMcHhGfA2RqagLB8JtuDYvJzd9dsdc1z/DdwBDqWiQy2s1hzYBYTSpa,iv:/1BkhzropZ+ZHMN1aCpllI//aCa5qU4T0n765LMsvW8=,tag:6wH1Aly//CIRGAANVz7RdQ==,type:str]
|
||||
DB_HOST=ENC[AES256_GCM,data:Jvk5Zes8XH50096YHApn,iv:GDU3tu24u8lwuMLQbrv1chNLspzW8oIaPgS9ZgiZkro=,tag:vmTdIZL2E7CRkb6TYxr5eg==,type:str]
|
||||
DB_PORT=ENC[AES256_GCM,data:DXNr+ZA2,iv:9kY1pEVj9LteVs/GPnCdZrblI+8ubrqNXwiS8IW4954=,tag:YgJalc+nsdYD6m4tNayJcw==,type:str]
|
||||
DB_USER=ENC[AES256_GCM,data:K+rYqv9CQpV5p8zDXV0=,iv:TiGMbFAiyVPtbe0JmXxsilAYv4WmgTdPu4muCgSmSgY=,tag:4/kA2T3w7BUytcW0CVyFCg==,type:str]
|
||||
DB_PASS=ENC[AES256_GCM,data:w49QEtuN2mFthnn4X/DvoxwbhImYVqDUYG1Ptq4ba22P9w==,iv:cSOmskpZAi/aYpzj3+QBmVIQZfEs2itDqaMZA9eX8v8=,tag:NJrdaN6zIRE0DBpVTzDL7g==,type:str]
|
||||
APP_URL=ENC[AES256_GCM,data:xr9j3Gt/y5Uq8bHzTyTKsYtpSRg4GKU=,iv:oV68MYwwipB5tLpXXDFln2YF4hPHWiufyRm3csamssg=,tag:Bj1K3tC3LyP8ezNJG8bpIA==,type:str]
|
||||
SMTP_HOST=ENC[AES256_GCM,data:wXOHpMWXQ2/spsVqVDH07w==,iv:FHffrNhUk9sY5Ew3b9h6LBQgNCRfCu3kFMKBOYXMY/o=,tag:/PJ/UrZHHbyWYg30+C6dfw==,type:str]
|
||||
SMTP_PORT=ENC[AES256_GCM,data:6r6Zsqg=,iv:eNzU1Dk3vx7kwJu72tMZDx4r9ngHUKx1t1zAYSyFFb4=,tag:aqryLBX9xPM6DvGd5Fwl5g==,type:str]
|
||||
SMTP_USER=ENC[AES256_GCM,data:IVpG+wm7l0Kk8UfhrAo=,iv:GiQChcgXDzD/h8fBHXAeKWez3IXR4NX90NU9582hThg=,tag:b8jcQY2G2HAo3pQjc7+B0Q==,type:str]
|
||||
SMTP_PASS=ENC[AES256_GCM,data:siqtgQg2WRrRbD6yqTawLAo++u2fWvpVLg==,iv:rL5AZQ6b3PaOJhG3vGZYzXeFxm6yd+qhxNzYIN6pxQk=,tag:r0LTjC8DQ9rsLTQa4XLhAg==,type:str]
|
||||
SMTP_FROM=ENC[AES256_GCM,data:WH8AW4SVhZkeXB6cNZCfj7opSTwoqYm8TA==,iv:Hy55AgFV0VSurplLVuPPqtLcyDQr/IIvGHF6Ppl01t0=,tag:vKtXoZRFgSeMYqSL9enElQ==,type:str]
|
||||
SMTP_TLS=ENC[AES256_GCM,data:42eaSf82,iv:sMLqYMHN5hzu9wrjmH9DhHcSPK06f0ZGqv/HPMsMPo8=,tag:rxoUQyT2jEC2VjRJMJV4Sw==,type:str]
|
||||
SMTP_SSL=ENC[AES256_GCM,data:Am3rKylCqQ==,iv:P6nQdWsV1QkBYfg2oeR3JbEsJYNGvd0h/ZFza2PObY8=,tag:z5VAAD4IjNi7hMISgjsisQ==,type:str]
|
||||
SMTP_REJECT_UNAUTHORIZED=ENC[AES256_GCM,data:1wLP1f9a,iv:exUSGxwA7CZ6IuBTBuAikerCe+algCybvhW6xji6h2U=,tag:Ehf8ok6P5Bx2Ky6kzOplIQ==,type:str]
|
||||
DKIM_SELECTOR=ENC[AES256_GCM,data:gv0POpTZG/69Cw==,iv:eBeiuZPNWo6DPQ25Uupo8+1EacBGOx3FUOR9arhELV8=,tag:/6gICHQGYlO4KLeu/r0VcA==,type:str]
|
||||
DKIM_DOMAIN=ENC[AES256_GCM,data:j+C08N0l0+7sM1UFgVtST5A=,iv:YB0enFjwfhhf4wJTN61saaCJx1qnUnHrroLzrlna96E=,tag:Ni6Q31jrzhgfFNvjIRcSNA==,type:str]
|
||||
DKIM_PRIVATE_KEY_PATH=ENC[AES256_GCM,data:JAykp2gN4keLwzM962rgdJ6T9af+4WFsD5VRUBaIedf5v5v7cGJNJ+FtdrUV,iv:Ds5/3TTcbepjIMXW2YJbEKZ/aBlqk2OlEv+dIFOcQKo=,tag:Sdwnh33uMnnbPlD73rvwRw==,type:str]
|
||||
AUTO_APPROVE_LISTINGS=ENC[AES256_GCM,data:gkLX0/36sA==,iv:ma0etTesxiB49Ohgtes/2obnrvSJpmRlDZZX1gbXYt4=,tag:OFHkkH0QOEJ9PVBQTauvTg==,type:str]
|
||||
OPENAI_API_KEY=ENC[AES256_GCM,data:eVJRCNymtUQOMl5IMySoGcxGC+pVoDvIyCD6idP7CoZQFqE+y5dJ1i4LW7Y9Rb5Su8+rutwkcVu2gh3wx9XxgEfFazHKQm1lm9QaeCvKWrT/MkO26kCPAJO/vkFUp8OFnK35TG5v/RrHZZUwviV7YXEcjqvB82E59Tz6AzqlUvt1ENloK7EsK5DkkSZUdapzdMcegwqOaUUpMxZn8n/lU+pWgAp/RQ==,iv:9hLQOS5qNllbLF2Ggi5GgUENHtnM9zHBxHAnv8ppaow=,tag:+8TAn4UmxZDtQoDbeDsGDQ==,type:str]
|
||||
OPENAI_TRANSLATIONS_KEY=ENC[AES256_GCM,data:Se/eY/f00J2NLSVgvh4EMyklMHDJvnkpmzdqZl2oZWMxnLdxtpTBh8nKEfO2I9ovChdMacRseXJ2J1+oBk/1zw7xSqMastwg5EdftC4y2G8TODkPwWqDnB1t1jNpObA/gXeSxtUdE8JtM8dU4U37+KSMRjM7afdQy++YHRes1OzqBnFUdFvAwNHfi//uya0Q4CEl2unsiha8iLWaNT+skf27EgFOUQ==,iv:oBu3SPls776zktVWH7t9OwEI/p3h4WM3jWEJzluI64M=,tag:tRyJtqFkuxdMcFqEfi7RbQ==,type:str]
|
||||
AUTH_SECRET=ENC[AES256_GCM,data:KWy3+8oavddZPzPq/Ecei9VFyhnUOssF9PQT9pbJyuqbXfFgBA+Y,iv:UIYDmZlohqmGzY7zp1DjA6xTNugM2zLpEPIpsTI9QWc=,tag:j5u6fPHVOJPzmAQxJs7tHw==,type:str]
|
||||
DATABASE_URL=ENC[AES256_GCM,data:5NuPcbtJuPJYrsWU14inTtxzl0QjsPFrcY0PAVy52yu3yJgbheiFx8lT0Ev8TnzRWxFUFFWsQc1AIzIhW7xYtmiATQC2NSyH/t9dSfuIEql4Ch9e0a9+AqD3cwd8q9JxwUQjKJOV7mthOsgo,iv:HWK3Dt5VgrgSqif5uNy0W6z5SzohpZAA4qkWok/oi9s=,tag:BNPnfhD0FrwhgpkSLoovdQ==,type:str]
|
||||
DB_HOST=ENC[AES256_GCM,data:8Cg1jl+Tuj2hKIj45/cx,iv:Oam4GRtWZVF7m4peQYtv8ZcP8BxJs51/T/CfDWPaqvE=,tag:nzfqLedSJzvB/5y3B13+Fw==,type:str]
|
||||
DB_PORT=ENC[AES256_GCM,data:GhQ9kz8i,iv:p9iLB2VlyiHGiLNcITfb2bU27vx1JYxz2jVCSn164yE=,tag:8e8pJcKLZYkqC0EaYpEyKQ==,type:str]
|
||||
DB_USER=ENC[AES256_GCM,data:9EBCFurl7NXhZLASaqY=,iv:uxCLra/nDpd/8JDU4yveNvZHJqwgKIOxii7kty34O0Q=,tag:1+fWYZXRSemqTmqHcf0OXA==,type:str]
|
||||
DB_PASS=ENC[AES256_GCM,data:SAZXrRBfI/go4tVAa3jUEJ0C9ZaoG8NpgPJyXncxgDOewg==,iv:wLZM5gAuzEs3h75uFb4/jzZuomy5GM0a8ve4SCHvkmI=,tag:ptco0HN2X8ysNg/74112RA==,type:str]
|
||||
APP_URL=ENC[AES256_GCM,data:9U3Hk7huaPXIJT5Vm2zOaaIROXjGXwM=,iv:uPuSJykuYEFexUFJGCnS/Ezov+wcw0gdaPIO1rZyLX8=,tag:MtL29NEGa5EzXPHbbNPI5w==,type:str]
|
||||
SMTP_HOST=ENC[AES256_GCM,data:FkxJVIhmZk+j0HF7ZzS6YQ==,iv:Qz5R9CJOgtIR38RznlCp5D8JxQLahK4k05Ykf33psBQ=,tag:yS2R/MyCiI0pcIuGGa36SQ==,type:str]
|
||||
SMTP_PORT=ENC[AES256_GCM,data:FFEdF9U=,iv:Xo1eqi/V1VqPF30empC2Pkiy/M2ZHiuAlAICW7c/9H4=,tag:jYFivqGFtj0l6AlDbYLa6g==,type:str]
|
||||
SMTP_USER=ENC[AES256_GCM,data:CfLkHqeNocRynqftg+o=,iv:aMYEKfgUKetimZbpACa9aDRsqdebm5rH9fEv1qvDuRQ=,tag:HUMvgJweRtUk+U2E1Q2R4A==,type:str]
|
||||
SMTP_PASS=ENC[AES256_GCM,data:f9fEtyORtBKnrUyeFWmqKdzJaInhzS/NKA==,iv:NdiuABTvNoEQAdGBgiIdYwmiSr7DtiQ1Mc7zqAn29x4=,tag:fOqceNO2Dck259L6yq0Otw==,type:str]
|
||||
SMTP_FROM=ENC[AES256_GCM,data:qMo+/J7AEK/Qq0JUpbxyRumV4o2pfWabcw==,iv:3wu/CHHx7o65Fa8jsp4QBptkt0M0txM/KkkBY/27BZw=,tag:uxv4LzTVnoIhhoCHkEWyXw==,type:str]
|
||||
SMTP_TLS=ENC[AES256_GCM,data:iSrsTPRB,iv:rjGjSgFFhpTmVurBEGc9HYYnusTpXidYo9h7w+7WnHw=,tag:TnicVSaMJlB5gKM/847UzQ==,type:str]
|
||||
SMTP_SSL=ENC[AES256_GCM,data:AiNysosLaA==,iv:kcDmbZUzLUmalMbkshsnxqxIJLjaM78GQ2vuIB+YvRI=,tag:u1sGNGGfCVcbetQ38lKi+A==,type:str]
|
||||
SMTP_REJECT_UNAUTHORIZED=ENC[AES256_GCM,data:MFumlWL1,iv:o+1JI3Nt6+yz6YTkt73/vK3wlbNpoQMuqzt+uefYlhM=,tag:obiX1nXJwlN8Ko5Jgo4TEw==,type:str]
|
||||
DKIM_SELECTOR=ENC[AES256_GCM,data:trigli1PSfRn/Q==,iv:T/5s84huvNsJQ3iCF/odusuTYaSDW3Sd5yq8UzTbn4g=,tag:UyvsybJqXK5w3uU7a2WAsw==,type:str]
|
||||
DKIM_DOMAIN=ENC[AES256_GCM,data:Wi6XrJ8RSaT+Q7kjWSlDmxQ=,iv:lPGHjOG6xpDCtlbS0RHI7w5l0s0B+f3g6fC3B52ACP0=,tag:xTNYwvKekFeL2lw76CmdBw==,type:str]
|
||||
DKIM_PRIVATE_KEY_PATH=ENC[AES256_GCM,data:buS3owubFZFYXZOZZP9FyyZwpn0vdjPevIvnufpu3kZXjNj9kAOYeVRJpiVW,iv:x0JSfGH8PyMUoW6xRgUmSJoYPEAq6pyREUn1iNa3gg8=,tag:c4C9zYectQKVwx6v0AL8yA==,type:str]
|
||||
AUTO_APPROVE_LISTINGS=ENC[AES256_GCM,data:bSkJ/0F8kw==,iv:nyOI3eDQwu52cX5w1zPzadV/AmX4G1kn8BFTVcw82fc=,tag:yYXjszg0JbJPry/zOGSHwQ==,type:str]
|
||||
OPENAI_API_KEY=ENC[AES256_GCM,data:lDT6LDpSsZFv3rWN1RUSqsONKY9dXu71AG56sd2Tu1gW+0hDgf+Oqhwxwb6wJC83vkcvmWYodl2kPfazDiG7MDzTB530qdum6omZT06yOCvlxpqk1j1FDW/x0r/vxClZ/7Ya8sFI7CoJSDjoI6VB0De8cQtSn1hM8ANxoDHspih7WuW+J3bfSltzgRIvjrhh+Th6BvHl5tiEiGdZxdZTF0RbtHFwzQ==,iv:7S6eAUXZ+EaYYJy8mthzK6Btz33Oa9Y4dJJavYGyP3U=,tag:K7kJOubjzGP/h40ZbjPwIw==,type:str]
|
||||
OPENAI_TRANSLATIONS_KEY=ENC[AES256_GCM,data:WVtPz8ioEzmFLA5s/NVQU7XE+iqtxmXGIXXKT1O/Q+vYoh/h6YnhDlauU9mjHp7CUmpZAj6Iv5MmSgWtoN/f21QSFVN304Vj9Q5q4oCyzPUbCMokv3ATbZFhPiK5+pTGAtVJktcWVcYZIoSdbuAiRsdhM14Tmbllb2JtJ3WBn8eItCBkWx/SI/SpoT3sGnM8MIWEpl4t6MVgH5fA/+6/RLLfL3Teug==,iv:c0SfJQS3Y2kMlLhXqjQDHFAaBNRi53I1jC9oy4vzgVA=,tag:CIDRjbPzkSvxqeecurwXiA==,type:str]
|
||||
N8N_BILLING_API_KEY=ENC[AES256_GCM,data:dv7WOWYQ1Jpe4iqhlvC2hpfajd+I/BEq5MeuPL2uO2M998wvYFb2CCWFhnEX1z+kLsUPcnj3OnTw4iQJ/j2xjpKf,iv:zssAW0U8z0vk57nPoXFohcREPx9Y0CbTgBkWq2oUUrw=,tag:OTCSJ/tMnXabuaPDFr8w/g==,type:str]
|
||||
HETZNER_API_TOKEN="hoRULGviS8G3OGaJ68josx00M53efhuntVM5Rfft1AOvUR0ZQTXlO6yivhGqBM5o"
|
||||
HCLOUD_TOKEN=ENC[AES256_GCM,data:SZMlHgX2keD98hk2VU5G3aGdla3MsaSR4BqnCM4F9fNp3DNdx9zQyiRJ8LDBi62HUPBBubj1YSnUPnJFJ5bXtv6A,iv:mVor150MZPe7jMHEBtcXcoT434bAX1t7WSTLOG/hexY=,tag:DKWHOSg61vG/7qKsMDz+uw==,type:str]
|
||||
HETZNER_TOKEN=ENC[AES256_GCM,data:oe8Kp7a/j3PRc8IUnU0SUtu6zr4nqdUYWeR/TbmYz/vRoz5egDqbqi7SXi2GC0YD/JATMNiHL1ec5tYWPnceaKNS,iv:pm3IBAQSEEMqELno/hAFZgROXDixJdKv5GqEbAqSwMk=,tag:QLU06Q1D05pWSyQkKV2q3g==,type:str]
|
||||
JOKER_DYNDNS_USERNAME=ENC[AES256_GCM,data:jQEKhX2ISB9FlwMnnrp7oZ4D,iv:9nnUG5nD7DzPAAYiVDNd4C64YTgF9BSnq0+/WajJPVA=,tag:HLYprQoKRkTtaB82mPLnbQ==,type:str]
|
||||
JOKER_DYNDNS_PASSWORD=ENC[AES256_GCM,data:LUHbGwOLq+A3CsjYJ4iu9vCn,iv:Phl3sv3hCe8wRWX3TqlyeBsqhKiu2bvJF8M6f1ESnHY=,tag:lmQIynYBEl7jVg3pG/TOAg==,type:str]
|
||||
REGISTRY_USERNAME=ENC[AES256_GCM,data:IJKWI15AROA=,iv:crKgYBH39sKioPVNw69fv9H5NCGadc6X9DebqUIyC4M=,tag:7PBRGErLYdLi+ku/+U+9UA==,type:str]
|
||||
REGISTRY_PASSWORD=ENC[AES256_GCM,data:viuSD5MpNuGc,iv:/2Rcuv2cecP8iECeUfK/NowP3Fv2p+EPyqkCJoLQZnw=,tag:BApcmBr3jR+NoQ3ZqRaI8w==,type:str]
|
||||
NETDATA_USER=ENC[AES256_GCM,data:T51yECIfawfQ,iv:9q/drpZy7C6KzscGB+Lxgu0Rsg4Ov9qgvmUt2lfYfAE=,tag:XS1rN2wy3OAizpA6Ji5FhQ==,type:str]
|
||||
NETDATA_PASS=ENC[AES256_GCM,data:5j/hxKa4+9ovvaVqJdRWOns7cY2nG+nI5f5p3nkm,iv:/59+59bmpVv0XaeJrVOcLzS6sPEi3XTf3eNiwmsZFCI=,tag:1GrKhx0Zp0IztBtNpzVmxQ==,type:str]
|
||||
NETDATA_HOST_NODE1=ENC[AES256_GCM,data:9k1sqAJV2bLEStTC2L8KZ9OryFwLhDw=,iv:VWKvsEjOXBtfYHpiNG9wBX4HqG8i3XGW9wK6uOM0qbU=,tag:qKqYvnC0InnK+f3c7O3iTg==,type:str]
|
||||
NETDATA_HOST_DB1=ENC[AES256_GCM,data:ijCscUEJoup0CHh2vMtTTGzvkMtH,iv:taAvhzY9rpIgsdyR/B30Zo405l0lKO6/BvtAILwUWKA=,tag:ogOvtm7+y7R1TW82BfMWHQ==,type:str]
|
||||
NETDATA_PG_USER=ENC[AES256_GCM,data:ss8KoNmpRKk/,iv:kTHJyi4YpE+peQmXobd5jTFYrnhOWqypbnhsr251l+o=,tag:zTxRwUoqySysstFjOhF/NA==,type:str]
|
||||
NETDATA_PG_PASS=ENC[AES256_GCM,data:NEENSnAkLmBY7LxTzoqjNtG9YCFAdvF2yOj2wkzBvKbZew==,iv:7ZJNwLldd3i0BhO3uujzflhR01qDT9gDcqVtsUOXubg=,tag:rukJnDEItfa4csPxN3tvPg==,type:str]
|
||||
NETDATA_PG_ROLE=ENC[AES256_GCM,data:luPLkyzGXTf/MuYl,iv:VZf1TZlQzNkPqrFkdZhSQ/D+q9MTgz0jW4/88+4X3rs=,tag:ngpPhPvdad5U1ia2h0VMQw==,type:str]
|
||||
ADMIN_EMAIL=ENC[AES256_GCM,data:YUW3FIusETg/uRJQaP6ZCWjL1w==,iv:ibEncZK+qUsuNBXra6CxAaQQF4Oi9K4msaiOGggad7I=,tag:Sd+9MgTRx8/WA7GusZEuFg==,type:str]
|
||||
ADMIN_INITIAL_PASSWORD=ENC[AES256_GCM,data:VXiQWltYpxkts/xLNA4p8F8=,iv:as8Uq4S05e8peTP9phv5otdbyb7uyQe5gJ/ig7VKC2E=,tag:gsXXzVtft6AQBjQgrrhfng==,type:str]
|
||||
HCLOUD_TOKEN=ENC[AES256_GCM,data:0ZKPKDLYkKetyrC7SrK710DQUC5HuxxjA04MMpIG/gXH/Gn8BxzhAH+uKKyRcRXa/Dw3OQyr76pKEzAyz5E9NAsd,iv:PQITSrzMgwvjtmyZXDTBYmv4ykrnAN7WRp8jWaGVmzo=,tag:kLERn9uUFV6gh/56nwW/Yg==,type:str]
|
||||
HETZNER_TOKEN=ENC[AES256_GCM,data:JBAfRZcD5X+oHdu03licL2z0nRhXOdNhInqDjX9akSvuRF/3tSJSTbiQGgEjv94uEDeTBK8vsC7o6MTH68S3JNE/,iv:U0ikC9ky480RxQFjUY8ex+x9M2MUqqY6UjUbyid/wrU=,tag:edKfv71tvrON3fn9Cb+56Q==,type:str]
|
||||
JOKER_DYNDNS_USERNAME=ENC[AES256_GCM,data:HEGEeUu0Ry1QZGHCyzjGf6oN,iv:KnAP3Wx3H7bWaBanl/U215mtDQfRnKDiZW60BeI+rG0=,tag:zuxHFhioKx39CEcGmv63KA==,type:str]
|
||||
JOKER_DYNDNS_PASSWORD=ENC[AES256_GCM,data:yAbUiy0SaO+cIE/DGwF8vegB,iv:kmOA2Mw4KmTkU/CtFEYvoUpHlyDIfe5aMBxaiE6k5wE=,tag:ZABR0b9RXdkubhChkQZRIQ==,type:str]
|
||||
REGISTRY_USERNAME=ENC[AES256_GCM,data:rjaMQJ8J0qA=,iv:5amdPWuDPAOPWC/56Oy42ZF+zFiioCTTxuFY6M4tTOQ=,tag:gSa9PI8sbw1SkBvstcW30Q==,type:str]
|
||||
REGISTRY_PASSWORD=ENC[AES256_GCM,data:h9nr3e8Np4H5,iv:PcIRZKRjZj3LDONCeeTebXztKkIR6wlM+2ccw4b3BNw=,tag:ZEcJ5Tbjx2o4DijGvSPhew==,type:str]
|
||||
NETDATA_USER=ENC[AES256_GCM,data:Bzn8LJZBXNY6,iv:sVkDcvwvwR7SYgDRKQJO6TSoQuMG1r5oQPVVp+d0lD4=,tag:I05Na+Hgo1So2cuCVLVdRQ==,type:str]
|
||||
NETDATA_PASS=ENC[AES256_GCM,data:+WiAVcm0st44Y+vlfzDsxn7ZOvYSwAdTTKD/OiKZ,iv:QM4rQ2GAvtqnivEtZeyWUxmXki0sCCeHKxKgYTl6AxQ=,tag:hujFPSyoUgvCnxS1FKuCEQ==,type:str]
|
||||
NETDATA_HOST_NODE1=ENC[AES256_GCM,data:mkoL/EtpAn/F4MwGWbJFET58A3pq2WA=,iv:q9RSRkrhPqvIXQ7q64D6SMt93msgXbz4Mu3YbBPIyBE=,tag:PEnf6aBNvL5NNo+5K2P72w==,type:str]
|
||||
NETDATA_HOST_DB1=ENC[AES256_GCM,data:b1sQ+v7xqERCqILvXiDtmtK8Edfp,iv:o6yTKcSd+Qglyjxq90u/16d89Rw+sVm2LBzLZN4zIgY=,tag:0nfDju/HJNUrfCDfhYT+pQ==,type:str]
|
||||
NETDATA_PG_USER=ENC[AES256_GCM,data:6EVcB7/Ko8Wz,iv:GvmUgwNziYDK5wGhq6myqAy1sbUbWkyKZzW8PJcgAi0=,tag:FrUgUEWtKarBgfTK2e8Xog==,type:str]
|
||||
NETDATA_PG_PASS=ENC[AES256_GCM,data:Iksw0nIioDmAvls8bftcHn6yFkJAD5qwqSQInBcoNjxHLQ==,iv:x79FJtGy8lFEmJdl8TBfe5DbXMCtIv+xupZ9lS91L08=,tag:tkHUWXzlNExtPBaYqBptiA==,type:str]
|
||||
NETDATA_PG_ROLE=ENC[AES256_GCM,data:UD4InBUdm/iUXT/f,iv:5eRTnZIa5FF2Tu3P6t/KXRJfEEzmSC5anav8OzL0wkU=,tag:MX+5HxhBZAf1NZk9OzgUhA==,type:str]
|
||||
ADMIN_EMAIL=ENC[AES256_GCM,data:VYnRXD4SRl9iA6wrz0AzzYXhkg==,iv:BzU7sCgC8RmgrdFiL6UAh6tYEF8+FjaQjVhZdZOk5E4=,tag:neyQM966f9H93GQvpnYvJw==,type:str]
|
||||
ADMIN_INITIAL_PASSWORD=ENC[AES256_GCM,data:m+eV4Jaon8euwZ1QoZth7oo=,iv:KI2FbYR+mJ+GZrI6W3g7+0nq9gwZNfXcUjuhfNXFtHc=,tag:0uYBUqXcO0HNAPgx9W61KA==,type:str]
|
||||
REDMINE_API_USER="lomavuokraus-bot"
|
||||
REDMINE_API_KEY="1826930a88e3732444c55efa5ea3b9ad6a7aeaff"
|
||||
REDMINE_URL="https://redmine.halla-aho.net"
|
||||
REDMINE_PROJECT_ID="1"
|
||||
REDMINE_TRACKER_BUG_ID="1"
|
||||
REDMINE_TRACKER_SECURITY_ID="1"
|
||||
sops_age__list_0__map_enc=-----BEGIN AGE ENCRYPTED FILE-----\nYWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBMQURYZEQ0SzhGV3NnaE1Z\nYWxucXdSY2FiT2Z1NnRIdlJmYkplRG11NVRRCmZab2VSalB5YjA3SjRYTi80dWhC\nbzVtYTlYeGxMaURHc3NueEg1ZWVjM0EKLS0tIFh3WWhRMXJQaHBCbWlhdEZrV0Fi\neTNZclVSZ3hhcGttWk53UFRIUGZLNncKXF7cGtBMBDVuFN2Y1lpN5hrbZacBOjvI\nUdq1/P3dOSFD3ciQBslZXgRJnK/hAQuP+f1RJ7KUwB0GvLXIiDQs6g==\n-----END AGE ENCRYPTED FILE-----\n
|
||||
sops_age__list_0__map_enc=-----BEGIN AGE ENCRYPTED FILE-----\nYWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBFaEJLOS9Xc2ZZUXBIOFRq\nOXlkY1VmTjlTMGJSdlBxaUtsQStZT1BKRFhvCmhRSVVGNUVma0p2MmcrdlBrTVRF\nZFBkMSttbmE3VUg1ZjYvUCtJTE02NEUKLS0tIFlYTm91anBqMU0vUzNnMkI1TGpL\nUm93L1ZDNWZ4OHBhZDlGRFloV1ZjdXMKfIpEUmGN2kenKnZ2ZSak+oK/4wm2geld\nTCgAPd06JukPeRuYCKHVGTd0EVRPijcva9B12kyUeswGMfLcevi1sA==\n-----END AGE ENCRYPTED FILE-----\n
|
||||
sops_age__list_0__map_recipient=age1hkehkc2rryjl975c2mg5cghmjr54n4wjshncl292h2eg5l394fhs4uydrh
|
||||
sops_encrypted_regex=^(AUTH_SECRET|DATABASE_URL|DB_.*|APP_URL|SMTP_.*|DKIM_.*|AUTO_APPROVE_LISTINGS|OPENAI_.*|H(ETZNER|CLOUD)_TOKEN|JOKER_DYNDNS_.*|REGISTRY_.*|NETDATA_.*|ADMIN_.*)$
|
||||
sops_lastmodified=2025-12-14T12:06:30Z
|
||||
sops_mac=ENC[AES256_GCM,data:R06Pa93hx3HOijkBKdgm+MgBMVgkAoMS2wzZe55E1b5TlHLfTaa8DuqBNHkor/bPsJW584ByO0AA3DiLkeCLgo9yMulYhuizRIpzKsOI2FH5KcrTGOxj1h5Wxno0ToRoXNtgy71s2aDf7hmzLQhGetAOsmEl+HFy1DMs2dauU5Q=,iv:jh4OLLqTG+eBac6MmwR0CXN4irX+QZZbeTUcrQUOyQ8=,tag:ViE3djLoGcrbqMJgD9r3SQ==,type:str]
|
||||
sops_age__list_1__map_enc=-----BEGIN AGE ENCRYPTED FILE-----\nYWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBia21MTXNmU2lOdkY3V2M4\nRGhkeHdveW9kWm96YklDRHNZZVhZWXoyS1NFCjhiSUhtbmlLbTU5bTVTZWIzaVh4\nMTNZVEdoMG1uTkppZklKeGNJZGsxT2cKLS0tIHdtNGlPaXVJN29sL0w4a251UVlO\nNnlDMzdwelVzOG9oM0U0aWhUbGUwbkUK1AQOcofkTeHVb+SpEVqIy02o2/IvkF8Y\nc3LUZJ+MXkyWKHFjHO99stSXx+iMw9/5k77+q9FMS5lM/pn2wag7xg==\n-----END AGE ENCRYPTED FILE-----\n
|
||||
sops_age__list_1__map_recipient=age1ducvqxdzdhhluftu5hv4f2xsppmn803uh8tnnqj92v4n7nf6lprq9h3dqp
|
||||
sops_encrypted_regex=^(AUTH_SECRET|DATABASE_URL|DB_.*|APP_URL|SMTP_.*|DKIM_.*|AUTO_APPROVE_LISTINGS|OPENAI_.*|N8N_BILLING_API_KEY|H(ETZNER|CLOUD)_TOKEN|JOKER_DYNDNS_.*|REGISTRY_.*|NETDATA_.*|ADMIN_.*)$
|
||||
sops_lastmodified=2025-12-20T17:08:23Z
|
||||
sops_mac=ENC[AES256_GCM,data:0RhUNDpR5QwE5X2BCC3vxuCt9A2P2yD/Hr37g7rp+H/n/4AhxX8oFvePBJ6fAY8P9ih2J77u4skcV7lpg43fJQYHomIS+iFDo31qOeRuteu/1Bi+41DeAUr5nqURh6CH27tqfGCZeMpCnbk9uy+sbBcEnfXqPLvIzBKrso3reOs=,iv:QD4653gzFnPdLg2Ql0EQrA2xMsdpicklTDSl3QBRLU4=,tag:AENUcYyLGwDWeK0eVhqXmA==,type:str]
|
||||
sops_version=3.11.0
|
||||
|
|
|
|||
|
|
@ -4,8 +4,25 @@ set -euo pipefail
|
|||
cd "$(dirname "$0")/.."
|
||||
source deploy/env.sh
|
||||
|
||||
AGE_KEY_FILE="${SOPS_AGE_KEY_FILE:-$HOME/.config/age/keys.txt}"
|
||||
AGE_RECIPIENT="age1hkehkc2rryjl975c2mg5cghmjr54n4wjshncl292h2eg5l394fhs4uydrh"
|
||||
AGE_KEY_FILE_CANDIDATES=(
|
||||
"${SOPS_AGE_KEY_FILE:-}"
|
||||
"$HOME/.config/age/keys.txt"
|
||||
"$PWD/creds/age-key.txt"
|
||||
)
|
||||
AGE_KEY_FILE=""
|
||||
for candidate in "${AGE_KEY_FILE_CANDIDATES[@]}"; do
|
||||
if [[ -n "$candidate" && -f "$candidate" ]]; then
|
||||
AGE_KEY_FILE="$candidate"
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [[ -z "$AGE_KEY_FILE" ]]; then
|
||||
AGE_KEY_FILE="$HOME/.config/age/keys.txt"
|
||||
fi
|
||||
AGE_RECIPIENTS=(
|
||||
"age1hkehkc2rryjl975c2mg5cghmjr54n4wjshncl292h2eg5l394fhs4uydrh"
|
||||
"age1ducvqxdzdhhluftu5hv4f2xsppmn803uh8tnnqj92v4n7nf6lprq9h3dqp"
|
||||
)
|
||||
ENCRYPTED_SECRETS_FILE="${ENCRYPTED_SECRETS_FILE:-$PWD/creds/secrets.enc.env}"
|
||||
|
||||
require_cmd() {
|
||||
|
|
@ -34,24 +51,30 @@ check_age_setup() {
|
|||
require_cmd sops
|
||||
local repo_age_key="$PWD/creds/age-key.txt"
|
||||
if [[ ! -f "$AGE_KEY_FILE" ]]; then
|
||||
echo "Age key file not found at $AGE_KEY_FILE. Copy creds/age-key.txt or set SOPS_AGE_KEY_FILE." >&2
|
||||
echo "Age key file not found at $AGE_KEY_FILE. Copy $repo_age_key or set SOPS_AGE_KEY_FILE." >&2
|
||||
exit 1
|
||||
fi
|
||||
local has_key="0"
|
||||
if command -v age-keygen >/dev/null 2>&1; then
|
||||
if age-keygen -y "$AGE_KEY_FILE" 2>/dev/null | grep -q "$AGE_RECIPIENT"; then
|
||||
has_key="1"
|
||||
fi
|
||||
for recipient in "${AGE_RECIPIENTS[@]}"; do
|
||||
if age-keygen -y "$AGE_KEY_FILE" 2>/dev/null | grep -q "$recipient"; then
|
||||
has_key="1"
|
||||
break
|
||||
fi
|
||||
done
|
||||
else
|
||||
# Fallback: best-effort text check for the public key comment
|
||||
if grep -q "$AGE_RECIPIENT" "$AGE_KEY_FILE"; then
|
||||
has_key="1"
|
||||
fi
|
||||
for recipient in "${AGE_RECIPIENTS[@]}"; do
|
||||
if grep -q "$recipient" "$AGE_KEY_FILE"; then
|
||||
has_key="1"
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ "$has_key" != "1" ]]; then
|
||||
echo "Age key file at $AGE_KEY_FILE does not contain the expected public key ($AGE_RECIPIENT)." >&2
|
||||
if [[ -f "$repo_age_key" ]] && grep -q "$AGE_RECIPIENT" "$repo_age_key"; then
|
||||
echo "Age key file at $AGE_KEY_FILE does not contain any expected public key: ${AGE_RECIPIENTS[*]}." >&2
|
||||
if [[ -f "$repo_age_key" ]]; then
|
||||
cat >&2 <<EOF
|
||||
Found the repository age key at $repo_age_key.
|
||||
Import it with:
|
||||
|
|
@ -81,6 +104,17 @@ for tool in git npm; do
|
|||
done
|
||||
check_docker
|
||||
check_age_setup
|
||||
if [[ -z "${SKIP_DB_MIGRATION_CHECK:-}" ]]; then
|
||||
if command -v npx >/dev/null 2>&1; then
|
||||
echo "Checking for pending Prisma migrations..."
|
||||
if ! npx prisma migrate status >/dev/null 2>&1; then
|
||||
echo "Prisma migrate status failed. Ensure DATABASE_URL is set and migrations are up to date." >&2
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "npx not found; skipping Prisma migration check." >&2
|
||||
fi
|
||||
fi
|
||||
|
||||
GIT_SHA=$(git rev-parse --short HEAD 2>/dev/null || date +%s)
|
||||
BASE_TAG=${BUILD_TAG:-$GIT_SHA}
|
||||
|
|
|
|||
|
|
@ -96,6 +96,7 @@ flowchart LR
|
|||
<li>From ConfigMap (public): <code>NEXT_PUBLIC_SITE_URL</code>, <code>NEXT_PUBLIC_API_BASE</code>, <code>APP_ENV</code>.</li>
|
||||
<li>From Secret: DB URL, AUTH_SECRET, SMTP, DKIM, etc. (materialize from <code>creds/secrets.env</code>).</li>
|
||||
<li>App env resolution: <code>process.env.*</code> in Next server code.</li>
|
||||
<li>n8n billing assistant: <code>N8N_BILLING_API_KEY</code> or file <code>creds/n8n-billing.key</code> protects <code>/api/integrations/billing/verify</code>.</li>
|
||||
</ul>
|
||||
</section>
|
||||
</main>
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
- `creds/secrets.enc.env`: encrypted dotenv managed by sops/age (committable).
|
||||
- `creds/secrets.env`: decrypted dotenv (git-ignored) produced when loading secrets; not committed.
|
||||
- Legacy plaintext secrets moved to `creds/deprecated/` for reference.
|
||||
- `creds/n8n-billing.key`: API key for the billing verification endpoint (git-ignored). Can also be provided via `N8N_BILLING_API_KEY`.
|
||||
|
||||
## Editing secrets
|
||||
```bash
|
||||
|
|
@ -31,6 +32,11 @@ This decrypts `creds/secrets.enc.env` to `creds/secrets.env` if needed (requires
|
|||
- Update `.sops.yaml` recipient to the new public key.
|
||||
- Re-encrypt: `SOPS_AGE_KEY_FILE=creds/age-key.txt sops --encrypt --in-place creds/secrets.enc.env`.
|
||||
|
||||
## n8n billing API key
|
||||
- The billing assistant verification endpoint (`/api/integrations/billing/verify`) requires an API key.
|
||||
- Store it in `creds/n8n-billing.key` (git-ignored) or export `N8N_BILLING_API_KEY` via `creds/secrets.env`.
|
||||
- Rotate by replacing the file/env value and restarting the app/n8n caller with the new key.
|
||||
|
||||
## Per-user age keys
|
||||
- Keys live under `creds/age/<user>.key` (git-ignored) and carry a public key in the header.
|
||||
- Helper: `./scripts/manage-age-key.sh add alice` generates a key and appends the recipient to `.sops.yaml`.
|
||||
|
|
|
|||
12
lib/apiKeys.ts
Normal file
12
lib/apiKeys.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
export function loadN8nBillingApiKey() {
|
||||
if (process.env.N8N_BILLING_API_KEY) return process.env.N8N_BILLING_API_KEY;
|
||||
const keyPath = path.join(process.cwd(), 'creds', 'n8n-billing.key');
|
||||
try {
|
||||
return fs.readFileSync(keyPath, 'utf8').trim();
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
41
lib/billing.ts
Normal file
41
lib/billing.ts
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import type { Listing, User } from '@prisma/client';
|
||||
|
||||
export type BillingConfig = {
|
||||
accountName: string | null;
|
||||
iban: string | null;
|
||||
includeVatLine: boolean;
|
||||
};
|
||||
|
||||
type BillingUser = Pick<User, 'billingAccountName' | 'billingIban' | 'billingIncludeVatLine'>;
|
||||
type BillingListing = Pick<Listing, 'billingAccountName' | 'billingIban' | 'billingIncludeVatLine'>;
|
||||
|
||||
export function normalizeOptionalString(input: unknown): string | null | undefined {
|
||||
if (input === undefined) return undefined;
|
||||
if (input === null) return null;
|
||||
const value = String(input).trim();
|
||||
return value ? value : null;
|
||||
}
|
||||
|
||||
export function normalizeIban(input: unknown): string | null | undefined {
|
||||
if (input === undefined) return undefined;
|
||||
if (input === null) return null;
|
||||
const value = String(input).replace(/\s+/g, '').toUpperCase();
|
||||
return value ? value : null;
|
||||
}
|
||||
|
||||
export function normalizeNullableBoolean(input: unknown): boolean | null | undefined {
|
||||
if (input === undefined) return undefined;
|
||||
if (input === null) return null;
|
||||
return Boolean(input);
|
||||
}
|
||||
|
||||
export function resolveBillingDetails(user: BillingUser, listing?: BillingListing | null): BillingConfig {
|
||||
const accountName = listing?.billingAccountName ?? user.billingAccountName ?? null;
|
||||
const iban = listing?.billingIban ?? user.billingIban ?? null;
|
||||
const includeVatLine =
|
||||
listing?.billingIncludeVatLine !== null && listing?.billingIncludeVatLine !== undefined
|
||||
? Boolean(listing.billingIncludeVatLine)
|
||||
: Boolean(user.billingIncludeVatLine);
|
||||
|
||||
return { accountName, iban, includeVatLine };
|
||||
}
|
||||
57
lib/i18n.ts
57
lib/i18n.ts
|
|
@ -145,6 +145,25 @@ const baseMessages = {
|
|||
profileEmailVerified: 'Email verified',
|
||||
profileApproved: 'Approved',
|
||||
profileUpdated: 'Profile updated',
|
||||
billingSettingsTitle: 'Billing assistant',
|
||||
billingSettingsLead: 'Opt into automated billing emails via the n8n agent. Set defaults and per-listing overrides.',
|
||||
billingEnableLabel: 'Enable billing assistant for my listings',
|
||||
billingAccountNameLabel: 'Billing account owner name',
|
||||
billingAccountPlaceholder: 'Use profile default',
|
||||
billingIbanLabel: 'IBAN for payouts',
|
||||
billingIbanPlaceholder: 'Use profile default',
|
||||
billingIncludeVat: 'Include a VAT line on invoices',
|
||||
billingListingsTitle: 'Per-listing billing',
|
||||
billingListingsLead: 'Override billing details per listing; blank fields inherit your profile defaults.',
|
||||
billingNoListings: 'No listings available yet.',
|
||||
billingVatChoice: 'VAT line preference',
|
||||
billingVatInherit: 'Use profile choice',
|
||||
billingVatYes: 'Include VAT line',
|
||||
billingVatNo: 'Do not include VAT line',
|
||||
billingDisabledHint: 'Enable the billing assistant to manage invoice details and VAT preferences.',
|
||||
billingLoadFailed: 'Failed to load billing settings.',
|
||||
billingSaveFailed: 'Could not save billing settings.',
|
||||
billingSaved: 'Billing settings saved.',
|
||||
settingsSaved: 'Settings saved.',
|
||||
emailLocked: 'Email cannot be changed',
|
||||
save: 'Save',
|
||||
|
|
@ -508,6 +527,25 @@ const baseMessages = {
|
|||
profileEmailVerified: 'Sähköposti vahvistettu',
|
||||
profileApproved: 'Hyväksytty',
|
||||
profileUpdated: 'Profiili päivitetty',
|
||||
billingSettingsTitle: 'Laskutusavustin',
|
||||
billingSettingsLead: 'Ota n8n-laskutus käyttöön halutessasi ja määritä oletus- ja kohdekohtaiset tiedot.',
|
||||
billingEnableLabel: 'Ota laskutusavustin käyttöön kohteilleni',
|
||||
billingAccountNameLabel: 'Tilinomistajan nimi',
|
||||
billingAccountPlaceholder: 'Käytä profiilin oletusta',
|
||||
billingIbanLabel: 'IBAN-maksuissa',
|
||||
billingIbanPlaceholder: 'Käytä profiilin oletusta',
|
||||
billingIncludeVat: 'Lisää laskulle ALV-rivi',
|
||||
billingListingsTitle: 'Kohdekohtaiset asetukset',
|
||||
billingListingsLead: 'Ylikirjoita tiedot kohteittain; tyhjä kenttä käyttää profiilin arvoa.',
|
||||
billingNoListings: 'Ei kohteita vielä.',
|
||||
billingVatChoice: 'ALV-rivin valinta',
|
||||
billingVatInherit: 'Käytä profiilin asetusta',
|
||||
billingVatYes: 'Lisää ALV-rivi',
|
||||
billingVatNo: 'Älä lisää ALV-riviä',
|
||||
billingDisabledHint: 'Ota laskutusavustin käyttöön lisätäksesi laskutustiedot ja ALV-valinnat.',
|
||||
billingLoadFailed: 'Laskutusasetusten lataus epäonnistui.',
|
||||
billingSaveFailed: 'Laskutusasetusten tallennus epäonnistui.',
|
||||
billingSaved: 'Laskutusasetukset tallennettu.',
|
||||
settingsSaved: 'Asetukset tallennettu.',
|
||||
emailLocked: 'Sähköpostia ei voi vaihtaa',
|
||||
save: 'Tallenna',
|
||||
|
|
@ -743,6 +781,25 @@ const svMessages: Record<keyof typeof baseMessages.en, string> = {
|
|||
settingContactVisibilityTitle: 'Synlighet för kontaktuppgifter',
|
||||
settingContactVisibilityHelp: 'Dölj värdens kontaktuppgifter för anonyma besökare så att bara inloggade ser dem.',
|
||||
settingRequireLoginForContact: 'Kräv inloggning för att se kontaktuppgifter',
|
||||
billingSettingsTitle: 'Faktureringsassistent',
|
||||
billingSettingsLead: 'Aktivera n8n-fakturor om du vill och ange standard- samt objektspecifika uppgifter.',
|
||||
billingEnableLabel: 'Aktivera faktureringsassistent för mina annonser',
|
||||
billingAccountNameLabel: 'Kontoinnehavarens namn',
|
||||
billingAccountPlaceholder: 'Använd profilens standard',
|
||||
billingIbanLabel: 'IBAN för utbetalningar',
|
||||
billingIbanPlaceholder: 'Använd profilens standard',
|
||||
billingIncludeVat: 'Ta med momsrad på fakturor',
|
||||
billingListingsTitle: 'Objektvisa inställningar',
|
||||
billingListingsLead: 'Åsidosätt uppgifter per annons; tomma fält använder profilens värden.',
|
||||
billingNoListings: 'Inga annonser ännu.',
|
||||
billingVatChoice: 'Momsrad',
|
||||
billingVatInherit: 'Använd profilinställning',
|
||||
billingVatYes: 'Lägg till momsrad',
|
||||
billingVatNo: 'Lägg inte till momsrad',
|
||||
billingDisabledHint: 'Aktivera assistenten för att hantera fakturauppgifter och momsval.',
|
||||
billingLoadFailed: 'Kunde inte ladda faktureringsinställningar.',
|
||||
billingSaveFailed: 'Kunde inte spara faktureringsinställningar.',
|
||||
billingSaved: 'Faktureringsinställningar sparade.',
|
||||
settingsSaved: 'Inställningar sparade.',
|
||||
translationMissing: 'Lägg till minst ett språk med titel och beskrivning.',
|
||||
saveDraft: 'Spara utkast',
|
||||
|
|
|
|||
|
|
@ -5,10 +5,8 @@ const ALGORITHM = 'HS256';
|
|||
const TOKEN_EXP_HOURS = 24;
|
||||
|
||||
function getSecret() {
|
||||
if (!process.env.AUTH_SECRET) {
|
||||
throw new Error('AUTH_SECRET is not set');
|
||||
}
|
||||
return new TextEncoder().encode(process.env.AUTH_SECRET);
|
||||
const secret = process.env.AUTH_SECRET || 'dev-auth-secret';
|
||||
return new TextEncoder().encode(secret);
|
||||
}
|
||||
|
||||
export async function signAccessToken(payload: { userId: string; role: string }) {
|
||||
|
|
|
|||
45
lib/loadSecrets.ts
Normal file
45
lib/loadSecrets.ts
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { execFileSync } from 'child_process';
|
||||
|
||||
function parseDotenv(contents: string) {
|
||||
contents
|
||||
.split('\n')
|
||||
.map((line) => line.trim())
|
||||
.filter((line) => line && !line.startsWith('#'))
|
||||
.forEach((line) => {
|
||||
const idx = line.indexOf('=');
|
||||
if (idx === -1) return;
|
||||
const key = line.slice(0, idx).trim();
|
||||
let value = line.slice(idx + 1).trim();
|
||||
if (!key || key in process.env) return;
|
||||
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
|
||||
value = value.slice(1, -1);
|
||||
}
|
||||
process.env[key] = value;
|
||||
});
|
||||
}
|
||||
|
||||
export function loadLocalSecrets() {
|
||||
const root = process.cwd();
|
||||
const plainPath = path.join(root, 'creds', 'secrets.env');
|
||||
const encPath = path.join(root, 'creds', 'secrets.enc.env');
|
||||
|
||||
if (fs.existsSync(plainPath)) {
|
||||
try {
|
||||
parseDotenv(fs.readFileSync(plainPath, 'utf8'));
|
||||
return;
|
||||
} catch {
|
||||
// ignore and try encrypted
|
||||
}
|
||||
}
|
||||
|
||||
if (fs.existsSync(encPath) && !process.env.SKIP_SOPS_AUTOLOAD) {
|
||||
try {
|
||||
const output = execFileSync('sops', ['-d', encPath], { encoding: 'utf8' });
|
||||
parseDotenv(output);
|
||||
} catch {
|
||||
// silent fail if sops/key not available
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,11 +1,16 @@
|
|||
import { PrismaClient } from '@prisma/client';
|
||||
import { PrismaPg } from '@prisma/adapter-pg';
|
||||
import { Pool } from 'pg';
|
||||
import { loadLocalSecrets } from './loadSecrets';
|
||||
|
||||
loadLocalSecrets();
|
||||
|
||||
const globalForPrisma = globalThis as unknown as { prisma?: PrismaClient };
|
||||
|
||||
const pool = process.env.DATABASE_URL ? new Pool({ connectionString: process.env.DATABASE_URL }) : undefined;
|
||||
const adapter = pool ? new PrismaPg(pool) : undefined;
|
||||
const databaseUrl = process.env.DATABASE_URL || 'postgresql://localhost:5432/lomavuokraus?sslmode=disable';
|
||||
process.env.DATABASE_URL = databaseUrl;
|
||||
const pool = new Pool({ connectionString: databaseUrl });
|
||||
const adapter = new PrismaPg(pool);
|
||||
|
||||
export const prisma =
|
||||
globalForPrisma.prisma ??
|
||||
|
|
|
|||
|
|
@ -1,14 +1,20 @@
|
|||
// This file was generated by Prisma and assumes you have installed the following:
|
||||
// npm install --save-dev prisma dotenv
|
||||
import "dotenv/config";
|
||||
import { defineConfig, env } from "prisma/config";
|
||||
import 'dotenv/config';
|
||||
import { defineConfig } from 'prisma/config';
|
||||
import { loadLocalSecrets } from './lib/loadSecrets';
|
||||
|
||||
loadLocalSecrets();
|
||||
|
||||
const databaseUrl = process.env.DATABASE_URL || 'postgresql://localhost:5432/lomavuokraus?sslmode=disable';
|
||||
|
||||
export default defineConfig({
|
||||
schema: "prisma/schema.prisma",
|
||||
schema: 'prisma/schema.prisma',
|
||||
migrations: {
|
||||
path: "prisma/migrations",
|
||||
path: 'prisma/migrations',
|
||||
},
|
||||
datasource: {
|
||||
url: env("DATABASE_URL"),
|
||||
// Fallback to a local dev URL so builds/linting can run without secrets
|
||||
url: databaseUrl,
|
||||
},
|
||||
});
|
||||
|
|
|
|||
11
prisma/migrations/20260311_billing_preferences/migration.sql
Normal file
11
prisma/migrations/20260311_billing_preferences/migration.sql
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
-- Billing preferences for automated invoices + per-listing overrides
|
||||
ALTER TABLE "User"
|
||||
ADD COLUMN "billingEmailsEnabled" BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
ADD COLUMN "billingAccountName" TEXT,
|
||||
ADD COLUMN "billingIban" TEXT,
|
||||
ADD COLUMN "billingIncludeVatLine" BOOLEAN NOT NULL DEFAULT FALSE;
|
||||
|
||||
ALTER TABLE "Listing"
|
||||
ADD COLUMN "billingAccountName" TEXT,
|
||||
ADD COLUMN "billingIban" TEXT,
|
||||
ADD COLUMN "billingIncludeVatLine" BOOLEAN;
|
||||
|
|
@ -49,6 +49,10 @@ model User {
|
|||
verificationTokens VerificationToken[]
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
billingEmailsEnabled Boolean @default(false)
|
||||
billingAccountName String?
|
||||
billingIban String?
|
||||
billingIncludeVatLine Boolean @default(false)
|
||||
}
|
||||
|
||||
model Listing {
|
||||
|
|
@ -95,6 +99,9 @@ model Listing {
|
|||
calendarUrls String[] @db.Text @default([])
|
||||
priceWeekdayEuros Int?
|
||||
priceWeekendEuros Int?
|
||||
billingAccountName String?
|
||||
billingIban String?
|
||||
billingIncludeVatLine Boolean?
|
||||
contactName String?
|
||||
contactEmail String?
|
||||
contactPhone String?
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue