Compare commits
18
Commits
321251daf4
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c2933734ee | ||
|
|
1d512bf582 | ||
|
|
9e33aab9f9 | ||
|
|
32b3a83cd6 | ||
|
|
1e7edda6f2 | ||
|
|
8b56a9a5a9 | ||
|
|
e0e06eefa4 | ||
|
|
cccc8596e6 | ||
|
|
35feda1278 | ||
|
|
a6e60408d6 | ||
|
|
6ebb8161b9 | ||
|
|
ba0af1afd9 | ||
|
|
3577c9dc16 | ||
|
|
bf422b8529 | ||
|
|
ff5fbb649f | ||
|
|
633099371d | ||
|
|
ded7407090 | ||
|
|
f60fb7bbaf |
+1
-1
@@ -114,7 +114,7 @@ BITCOIN_MIN_INCOMING_ATOMIC=7 # 0.00000007 BTC (~half a USD cent at that moment)
|
|||||||
|
|
||||||
ELECTRUM_VERSION=4.8.1
|
ELECTRUM_VERSION=4.8.1
|
||||||
ELECTRUM_NETWORK=testnet4
|
ELECTRUM_NETWORK=testnet4
|
||||||
ELECTRUM_SERVER=testnet4-electrumx.wakiyamap.dev:51002:s
|
ELECTRUM_SERVER=blackie.c3-soft.com:57010:s
|
||||||
ELECTRUM_DAEMON_HOST=electrum-daemon
|
ELECTRUM_DAEMON_HOST=electrum-daemon
|
||||||
ELECTRUM_DAEMON_PORT=7777
|
ELECTRUM_DAEMON_PORT=7777
|
||||||
ELECTRUM_DAEMON_RPC_USER=electrum
|
ELECTRUM_DAEMON_RPC_USER=electrum
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
/deploy/certs
|
/deploy/certs
|
||||||
/deploy/certbot/www
|
/deploy/certbot/www
|
||||||
|
/deploy/backups
|
||||||
|
|
||||||
/monero-wallet-rpc/wallet
|
/monero-wallet-rpc/wallet
|
||||||
/electrum-daemon/wallet
|
/electrum-daemon/wallet
|
||||||
|
|||||||
@@ -53,6 +53,43 @@ npm run typeorm:revert-migration
|
|||||||
npm run typeorm:create-migration --name=<migration_name>
|
npm run typeorm:create-migration --name=<migration_name>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Development on Whonix
|
||||||
|
|
||||||
|
Bridge networking needs a one-time Workstation firewall allow for `nullcart0` + `docker0` (sudo required).
|
||||||
|
|
||||||
|
`/usr/bin/user-firewall-script`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# nullcart0: running compose stack
|
||||||
|
nft insert rule inet filter forward iifname "nullcart0" counter accept
|
||||||
|
nft insert rule inet filter forward oifname "nullcart0" counter accept
|
||||||
|
|
||||||
|
# docker0: image builds (apk/apt/npm)
|
||||||
|
nft insert rule inet filter forward iifname "docker0" counter accept
|
||||||
|
nft insert rule inet filter forward oifname "docker0" counter accept
|
||||||
|
```
|
||||||
|
|
||||||
|
`/lib/systemd/system/whonix-firewall.service.d/50_user.conf`:
|
||||||
|
|
||||||
|
```
|
||||||
|
[Service]
|
||||||
|
ExecStartPost=/usr/bin/user-firewall-script
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo chmod +x /usr/bin/user-firewall-script
|
||||||
|
sudo systemctl daemon-reload
|
||||||
|
sudo whonix_firewall
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Build and start docker containers
|
||||||
|
docker compose --env-file .env.dev -f docker-compose.dev.yml -f docker-compose.dev.whonix.yml build --no-cache
|
||||||
|
docker compose --env-file .env.dev -f docker-compose.dev.yml -f docker-compose.dev.whonix.yml up --force-recreate
|
||||||
|
```
|
||||||
|
|
||||||
## Tests
|
## Tests
|
||||||
|
|
||||||
### Backend unit tests
|
### Backend unit tests
|
||||||
|
|||||||
Generated
+1053
-1053
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,105 @@
|
|||||||
|
import 'reflect-metadata';
|
||||||
|
import { validate } from './validate';
|
||||||
|
|
||||||
|
const validConfig = (overrides: Record<string, unknown> = {}): Record<string, unknown> => ({
|
||||||
|
NODE_ENV: 'development',
|
||||||
|
BACKEND_PORT: 3000,
|
||||||
|
POSTGRES_USER: 'postgres',
|
||||||
|
POSTGRES_PASSWORD: 'postgres',
|
||||||
|
POSTGRES_DB: 'nullcart',
|
||||||
|
POSTGRES_HOST: 'postgres',
|
||||||
|
POSTGRES_PORT: 5432,
|
||||||
|
POSTGRES_MIGRATIONS_RUN: 'false',
|
||||||
|
CORS_ORIGINS: 'http://localhost:5173',
|
||||||
|
JWT_SECRET: 'secret',
|
||||||
|
JWT_EXPIRES_IN_MS: 604800000,
|
||||||
|
CMS_PASSWORD: 'change-me',
|
||||||
|
SHOP_NAME: 'NullCart',
|
||||||
|
SHOP_FIAT_CURRENCY: 'USD',
|
||||||
|
MULTER_PRODUCT_THUMB_ALLOWED_MIMES: 'image/jpeg',
|
||||||
|
MULTER_PRODUCT_THUMB_MAX_FILE_BYTES: 1048576,
|
||||||
|
MULTER_BLOG_IMAGE_ALLOWED_MIMES: 'image/jpeg',
|
||||||
|
MULTER_BLOG_IMAGE_MAX_FILE_BYTES: 1048576,
|
||||||
|
MULTER_SHOP_LOGO_ALLOWED_MIMES: 'image/jpeg',
|
||||||
|
MULTER_SHOP_LOGO_MAX_FILE_BYTES: 1048576,
|
||||||
|
MULTER_SHOP_FAVICON_ALLOWED_MIMES: 'image/png',
|
||||||
|
MULTER_SHOP_FAVICON_MAX_FILE_BYTES: 262144,
|
||||||
|
VALIDATION_PRODUCT_TITLE_MAX_LENGTH: 100,
|
||||||
|
VALIDATION_BLOG_POST_TITLE_MAX_LENGTH: 200,
|
||||||
|
VALIDATION_CATEGORY_NAME_MAX_LENGTH: 50,
|
||||||
|
VALIDATION_DISCOUNT_CODE_MAX_LENGTH: 32,
|
||||||
|
VALIDATION_VARIANT_IMAGES_MAX: 10,
|
||||||
|
MULTER_DIGITAL_STOCK_ATTACHMENT_ALLOWED_MIMES: 'application/pdf',
|
||||||
|
MULTER_DIGITAL_STOCK_ATTACHMENT_MAX_FILE_BYTES: 5242880,
|
||||||
|
VALIDATION_DIGITAL_STOCK_ATTACHMENTS_MAX: 5,
|
||||||
|
VALIDATION_SHIPPING_NOTE_MIN_LENGTH: 20,
|
||||||
|
VALIDATION_SHIPPING_NOTE_MAX_LENGTH: 4000,
|
||||||
|
VALIDATION_ORDER_MESSAGE_MAX_LENGTH: 2000,
|
||||||
|
VALIDATION_BITCOIN_WITHDRAW_MAX_FEE_RATE_SAT_VBYTE: 500,
|
||||||
|
CAPTCHA_LENGTH: 5,
|
||||||
|
THROTTLE_TTL_MS: 60000,
|
||||||
|
THROTTLE_LIMIT: 120,
|
||||||
|
SIGNED_COOKIE_JWT_SECRET: 'secret',
|
||||||
|
SIGNED_COOKIE_FEEDBACK_NAME: 'storefront_feedback',
|
||||||
|
SIGNED_COOKIE_FEEDBACK_EXPIRES_IN_MS: 120000,
|
||||||
|
SIGNED_COOKIE_CART_NAME: 'storefront_cart',
|
||||||
|
SIGNED_COOKIE_CART_EXPIRES_IN_MS: 2592000000,
|
||||||
|
SIGNED_COOKIE_CAPTCHA_NAME: 'storefront_captcha',
|
||||||
|
SIGNED_COOKIE_CAPTCHA_EXPIRES_IN_MS: 300000,
|
||||||
|
SIGNED_COOKIE_DISCOUNT_NAME: 'storefront_discount',
|
||||||
|
SIGNED_COOKIE_DISCOUNT_EXPIRES_IN_MS: 2592000000,
|
||||||
|
SIGNED_COOKIE_ERROR_NAME: 'storefront_error',
|
||||||
|
SIGNED_COOKIE_ERROR_EXPIRES_IN_MS: 120000,
|
||||||
|
SIGNED_COOKIE_CHECKOUT_SESSION_NAME: 'storefront_checkout_session',
|
||||||
|
SIGNED_COOKIE_ORDER_AUTH_NAME: 'storefront_order_auth',
|
||||||
|
SIGNED_COOKIE_ORDER_AUTH_EXPIRES_IN_MS: 604800000,
|
||||||
|
SIGNED_COOKIE_THEME_NAME: 'storefront_theme',
|
||||||
|
SIGNED_COOKIE_THEME_EXPIRES_IN_MS: 31536000000,
|
||||||
|
COINGECKO_API_BASE_URL: 'https://api.coingecko.com/api/v3',
|
||||||
|
COINPAPRIKA_API_BASE_URL: 'https://api.coinpaprika.com/v1',
|
||||||
|
COINPAPRIKA_RATE_FETCH_TIMEOUT_MS: 5000,
|
||||||
|
COINGECKO_RATE_FETCH_TIMEOUT_MS: 5000,
|
||||||
|
BASE64_ENCRYPTION_KEY: 'nyRya1KpYSQ+drpO132mkOEMUR+uq6K7tWvpMfppIME=',
|
||||||
|
MONERO_CONFIRMATION_TIERS:
|
||||||
|
'[{"upToTotalFiat":"30","minConfirmations":1},{"upToTotalFiat":"100","minConfirmations":3},{"minConfirmations":10}]',
|
||||||
|
BITCOIN_CONFIRMATION_TIERS:
|
||||||
|
'[{"upToTotalFiat":"200","minConfirmations":1},{"upToTotalFiat":"1000","minConfirmations":2},{"minConfirmations":6}]',
|
||||||
|
PAYMENT_METHODS_ENABLED: 'xmr,btc',
|
||||||
|
ORDER_CHECKOUT_VALIDITY_MS: 3600000,
|
||||||
|
ORDER_CHECKOUT_STATUS_REFRESH_SEC: 15,
|
||||||
|
ORDER_SHIPPING_PAYMENT_VALIDITY_MS: 259200000,
|
||||||
|
ORDER_DATA_RETENTION_DAYS: 30,
|
||||||
|
MONERO_MIN_INCOMING_ATOMIC: 10000000,
|
||||||
|
BITCOIN_MIN_INCOMING_ATOMIC: 7,
|
||||||
|
MONERO_DAEMON_ADDRESS: 'xmr-lux.boldsuck.org:38081',
|
||||||
|
MONERO_NETWORK: 'stagenet',
|
||||||
|
MONERO_WALLET_RPC_HOST: 'monero-wallet-rpc',
|
||||||
|
MONERO_WALLET_RPC_PORT: 18083,
|
||||||
|
MONERO_WALLET_RPC_USERNAME: 'monero',
|
||||||
|
MONERO_WALLET_RPC_PASSWORD: 'monero',
|
||||||
|
MONERO_WALLET_RPC_TIMEOUT_MS: 10000,
|
||||||
|
ELECTRUM_NETWORK: 'testnet4',
|
||||||
|
ELECTRUM_SERVER: 'blackie.c3-soft.com:57010:s',
|
||||||
|
ELECTRUM_DAEMON_HOST: 'electrum-daemon',
|
||||||
|
ELECTRUM_DAEMON_PORT: 7777,
|
||||||
|
ELECTRUM_DAEMON_RPC_USER: 'electrum',
|
||||||
|
ELECTRUM_DAEMON_RPC_PASSWORD: 'change-me',
|
||||||
|
ELECTRUM_DAEMON_RPC_TIMEOUT_MS: 10000,
|
||||||
|
ELECTRUM_WALLET_PASSWORD: 'change-me',
|
||||||
|
SIMPLEX_WS_URL: 'ws://simplex-cli:5225',
|
||||||
|
SIMPLEX_BOT_DISPLAY_NAME: 'NullCartBot',
|
||||||
|
...overrides
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('validate', () => {
|
||||||
|
it('accepts true and false for POSTGRES_MIGRATIONS_RUN', () => {
|
||||||
|
expect(() => validate(validConfig({ POSTGRES_MIGRATIONS_RUN: 'true' }))).not.toThrow();
|
||||||
|
expect(() => validate(validConfig({ POSTGRES_MIGRATIONS_RUN: 'false' }))).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('rejects non-literal boolean env values', () => {
|
||||||
|
expect(() => validate(validConfig({ POSTGRES_MIGRATIONS_RUN: 'yes' }))).toThrow();
|
||||||
|
expect(() => validate(validConfig({ POSTGRES_MIGRATIONS_RUN: '1' }))).toThrow();
|
||||||
|
expect(() => validate(validConfig({ POSTGRES_MIGRATIONS_RUN: '' }))).toThrow();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,6 +1,18 @@
|
|||||||
import { plainToClass } from 'class-transformer';
|
import { plainToClass } from 'class-transformer';
|
||||||
import { IsBoolean, IsEnum, IsNotEmpty, IsNumber, IsString, Max, Min, validateSync } from 'class-validator';
|
import {
|
||||||
|
IsEnum,
|
||||||
|
IsIn,
|
||||||
|
IsNotEmpty,
|
||||||
|
IsNumber,
|
||||||
|
IsString,
|
||||||
|
Max,
|
||||||
|
Min,
|
||||||
|
ValidateIf,
|
||||||
|
validateSync
|
||||||
|
} from 'class-validator';
|
||||||
|
import { BOOLEAN_STRING_VALUES } from '../consts/booleanStringValues';
|
||||||
import { NodeEnv } from '../types/NodeEnv';
|
import { NodeEnv } from '../types/NodeEnv';
|
||||||
|
import type { BooleanStringValue } from '../types/BooleanStringValue';
|
||||||
import { ShopFiatCurrency } from '../types/ShopFiatCurrency';
|
import { ShopFiatCurrency } from '../types/ShopFiatCurrency';
|
||||||
import { IsBase64 } from '../validation/decorators/isBase64';
|
import { IsBase64 } from '../validation/decorators/isBase64';
|
||||||
import { IsConfirmationTiers } from '../validation/decorators/isConfirmationTiers';
|
import { IsConfirmationTiers } from '../validation/decorators/isConfirmationTiers';
|
||||||
@@ -38,9 +50,10 @@ class EnvironmentVariables {
|
|||||||
POSTGRES_PORT: number;
|
POSTGRES_PORT: number;
|
||||||
|
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
@IsBoolean()
|
@IsIn(BOOLEAN_STRING_VALUES)
|
||||||
POSTGRES_MIGRATIONS_RUN: boolean;
|
POSTGRES_MIGRATIONS_RUN: BooleanStringValue;
|
||||||
|
|
||||||
|
@ValidateIf((config: EnvironmentVariables) => config.NODE_ENV === NodeEnv.Development)
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
@IsString()
|
@IsString()
|
||||||
CORS_ORIGINS: string;
|
CORS_ORIGINS: string;
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
export const BOOLEAN_STRING_VALUES = ['true', 'false'] as const;
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||||
|
|
||||||
|
export class AddProductSortOrder1785000000000 implements MigrationInterface {
|
||||||
|
name = 'AddProductSortOrder1785000000000';
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`ALTER TABLE "products" ADD "sortOrder" integer NOT NULL DEFAULT '0'`);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`ALTER TABLE "products" DROP COLUMN "sortOrder"`);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -106,10 +106,12 @@ async function bootstrap() {
|
|||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (nodeEnv === NodeEnv.Development) {
|
||||||
app.enableCors({
|
app.enableCors({
|
||||||
origin: corsOrigins,
|
origin: corsOrigins,
|
||||||
credentials: true
|
credentials: true
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
await app.listen(port);
|
await app.listen(port);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { IsArray, IsBoolean, IsNotEmpty, IsString, IsUUID, MaxLength } from 'class-validator';
|
import { IsArray, IsBoolean, IsInt, IsNotEmpty, IsString, IsUUID, MaxLength, Min } from 'class-validator';
|
||||||
|
|
||||||
import { getAppConfig } from '../../../config';
|
import { getAppConfig } from '../../../config';
|
||||||
|
|
||||||
@@ -22,4 +22,9 @@ export class UpdateProductDto {
|
|||||||
@IsArray()
|
@IsArray()
|
||||||
@IsUUID('4', { each: true })
|
@IsUUID('4', { each: true })
|
||||||
categoryIds: string[];
|
categoryIds: string[];
|
||||||
|
|
||||||
|
@IsNotEmpty()
|
||||||
|
@IsInt()
|
||||||
|
@Min(0)
|
||||||
|
sortOrder: number;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,9 @@ export class Product {
|
|||||||
@Column({ type: 'text', default: '' })
|
@Column({ type: 'text', default: '' })
|
||||||
descriptionHtml: string;
|
descriptionHtml: string;
|
||||||
|
|
||||||
|
@Column({ type: 'integer', default: 0 })
|
||||||
|
sortOrder: number;
|
||||||
|
|
||||||
@OneToMany(() => ProductVariant, variant => variant.product)
|
@OneToMany(() => ProductVariant, variant => variant.product)
|
||||||
variants: ProductVariant[];
|
variants: ProductVariant[];
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ export class ProductsService {
|
|||||||
|
|
||||||
const [products, total] = await this.productRepo.findAndCount({
|
const [products, total] = await this.productRepo.findAndCount({
|
||||||
where: trimmedSearch ? { title: ILike(`%${trimmedSearch}%`) } : {},
|
where: trimmedSearch ? { title: ILike(`%${trimmedSearch}%`) } : {},
|
||||||
order: { createdAt: 'DESC' },
|
order: { sortOrder: 'ASC', createdAt: 'DESC' },
|
||||||
skip: (page - 1) * limit,
|
skip: (page - 1) * limit,
|
||||||
take: limit
|
take: limit
|
||||||
});
|
});
|
||||||
@@ -56,6 +56,7 @@ export class ProductsService {
|
|||||||
where: { id: In(productIds) },
|
where: { id: In(productIds) },
|
||||||
relations: ['categories', 'variants'],
|
relations: ['categories', 'variants'],
|
||||||
order: {
|
order: {
|
||||||
|
sortOrder: 'ASC',
|
||||||
createdAt: 'DESC',
|
createdAt: 'DESC',
|
||||||
variants: { sortOrder: 'ASC', createdAt: 'ASC' }
|
variants: { sortOrder: 'ASC', createdAt: 'ASC' }
|
||||||
}
|
}
|
||||||
@@ -125,6 +126,7 @@ export class ProductsService {
|
|||||||
where: { id: In(uniqueIds) },
|
where: { id: In(uniqueIds) },
|
||||||
relations: ['variants'],
|
relations: ['variants'],
|
||||||
order: {
|
order: {
|
||||||
|
sortOrder: 'ASC',
|
||||||
createdAt: 'DESC',
|
createdAt: 'DESC',
|
||||||
variants: { sortOrder: 'ASC', createdAt: 'ASC' }
|
variants: { sortOrder: 'ASC', createdAt: 'ASC' }
|
||||||
}
|
}
|
||||||
@@ -164,7 +166,7 @@ export class ProductsService {
|
|||||||
|
|
||||||
async update(
|
async update(
|
||||||
id: string,
|
id: string,
|
||||||
{ title, descriptionHtml, isDraft, categoryIds }: UpdateProductDto
|
{ title, descriptionHtml, isDraft, categoryIds, sortOrder }: UpdateProductDto
|
||||||
): Promise<ProductWithVariantsExtended> {
|
): Promise<ProductWithVariantsExtended> {
|
||||||
const existing = await this.productRepo.findOne({
|
const existing = await this.productRepo.findOne({
|
||||||
where: { id }
|
where: { id }
|
||||||
@@ -177,6 +179,7 @@ export class ProductsService {
|
|||||||
existing.title = title.trim();
|
existing.title = title.trim();
|
||||||
existing.isDraft = isDraft;
|
existing.isDraft = isDraft;
|
||||||
existing.descriptionHtml = descriptionHtml;
|
existing.descriptionHtml = descriptionHtml;
|
||||||
|
existing.sortOrder = sortOrder;
|
||||||
existing.categories = await this.categoriesService.findByIds(categoryIds);
|
existing.categories = await this.categoriesService.findByIds(categoryIds);
|
||||||
|
|
||||||
await this.productRepo.save(existing);
|
await this.productRepo.save(existing);
|
||||||
|
|||||||
@@ -531,6 +531,14 @@ a:hover {
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.sf-user-text {
|
||||||
|
max-width: 100%;
|
||||||
|
min-width: 0;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
word-break: break-word;
|
||||||
|
}
|
||||||
|
|
||||||
.sf-info-box p + p,
|
.sf-info-box p + p,
|
||||||
.sf-info-box p + .sf-info-box__title {
|
.sf-info-box p + .sf-info-box__title {
|
||||||
margin-top: var(--sf-space-3);
|
margin-top: var(--sf-space-3);
|
||||||
@@ -1237,6 +1245,11 @@ a:hover {
|
|||||||
margin: 0 0 var(--sf-space-3);
|
margin: 0 0 var(--sf-space-3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.sf-prose p:empty {
|
||||||
|
min-height: 1lh;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.sf-payment-status {
|
.sf-payment-status {
|
||||||
margin: 0 0 var(--sf-space-3);
|
margin: 0 0 var(--sf-space-3);
|
||||||
font-size: 1.1rem;
|
font-size: 1.1rem;
|
||||||
@@ -1448,8 +1461,11 @@ a:hover {
|
|||||||
|
|
||||||
.sf-delivery-item__content {
|
.sf-delivery-item__content {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
max-width: 100%;
|
||||||
|
min-width: 0;
|
||||||
font-size: 0.85rem;
|
font-size: 0.85rem;
|
||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
word-break: break-word;
|
word-break: break-word;
|
||||||
line-height: 1.45;
|
line-height: 1.45;
|
||||||
}
|
}
|
||||||
@@ -1510,6 +1526,8 @@ a:hover {
|
|||||||
|
|
||||||
.sf-chat-bubble {
|
.sf-chat-bubble {
|
||||||
position: relative;
|
position: relative;
|
||||||
|
max-width: 100%;
|
||||||
|
min-width: 0;
|
||||||
border-radius: 0.875rem;
|
border-radius: 0.875rem;
|
||||||
padding: var(--sf-space-3);
|
padding: var(--sf-space-3);
|
||||||
line-height: 1.45;
|
line-height: 1.45;
|
||||||
@@ -1525,7 +1543,11 @@ a:hover {
|
|||||||
|
|
||||||
.sf-chat-bubble p {
|
.sf-chat-bubble p {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
max-width: 100%;
|
||||||
|
min-width: 0;
|
||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
word-break: break-word;
|
||||||
}
|
}
|
||||||
|
|
||||||
.sf-chat-meta {
|
.sf-chat-meta {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
</p>
|
</p>
|
||||||
{{#if shippingNote}}
|
{{#if shippingNote}}
|
||||||
<p class='sf-info-box__title'>Typical shipping costs</p>
|
<p class='sf-info-box__title'>Typical shipping costs</p>
|
||||||
<p>{{shippingNote}}</p>
|
<p class='sf-user-text'>{{shippingNote}}</p>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
|
import { DeliveryMode } from '../../product/types/DeliveryMode';
|
||||||
import type { CategoriesService } from '../../product/services/CategoriesService';
|
import type { CategoriesService } from '../../product/services/CategoriesService';
|
||||||
|
import type { StorefrontProduct } from '../types/StorefrontProduct';
|
||||||
import { StorefrontProductViewService } from './StorefrontProductViewService';
|
import { StorefrontProductViewService } from './StorefrontProductViewService';
|
||||||
|
|
||||||
describe('StorefrontProductViewService', () => {
|
describe('StorefrontProductViewService', () => {
|
||||||
@@ -19,4 +21,46 @@ describe('StorefrontProductViewService', () => {
|
|||||||
{ id: 'category-2', name: 'Physical', href: '/shop/categories/category-2' }
|
{ id: 'category-2', name: 'Physical', href: '/shop/categories/category-2' }
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('appends product-card anchors to index variant selection hrefs', () => {
|
||||||
|
const product: StorefrontProduct = {
|
||||||
|
id: 'product-1',
|
||||||
|
title: 'Widget',
|
||||||
|
deliveryMode: DeliveryMode.Auto,
|
||||||
|
descriptionHtml: null,
|
||||||
|
variants: [
|
||||||
|
{
|
||||||
|
id: 'variant-1',
|
||||||
|
productId: 'product-1',
|
||||||
|
productTitle: 'Widget',
|
||||||
|
title: 'Default',
|
||||||
|
price: 10,
|
||||||
|
deliveryMode: DeliveryMode.Auto,
|
||||||
|
stockAvailable: 1,
|
||||||
|
stockForSession: 1,
|
||||||
|
thumbnailUrl: null,
|
||||||
|
images: []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'variant-2',
|
||||||
|
productId: 'product-1',
|
||||||
|
productTitle: 'Widget',
|
||||||
|
title: 'Alt',
|
||||||
|
price: 12,
|
||||||
|
deliveryMode: DeliveryMode.Auto,
|
||||||
|
stockAvailable: 1,
|
||||||
|
stockForSession: 1,
|
||||||
|
thumbnailUrl: null,
|
||||||
|
images: []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
const [view] = service.toProductsIndexView([product], {});
|
||||||
|
|
||||||
|
expect(view.variants.map(variant => variant.selectionHref)).toEqual([
|
||||||
|
'/#product-card-variant-1',
|
||||||
|
'/?sel=product-1%3Avariant-2#product-card-variant-2'
|
||||||
|
]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -220,11 +220,15 @@ export class StorefrontProductViewService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private buildIndexUrl(basePath: string, product: StorefrontProduct, variantId: string): string {
|
private buildIndexUrl(basePath: string, product: StorefrontProduct, variantId: string): string {
|
||||||
|
const anchor = `#product-card-${variantId}`;
|
||||||
|
|
||||||
if (variantId === product.variants[0].id) {
|
if (variantId === product.variants[0].id) {
|
||||||
return basePath;
|
return `${basePath}${anchor}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return `${basePath}?${new URLSearchParams({ sel: `${product.id}:${variantId}` }).toString()}`;
|
const params = new URLSearchParams({ sel: `${product.id}:${variantId}` });
|
||||||
|
|
||||||
|
return `${basePath}?${params.toString()}${anchor}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
async resolveProductBackLink(categoryId?: string): Promise<{ backHref: string; backLabel: string }> {
|
async resolveProductBackLink(categoryId?: string): Promise<{ backHref: string; backLabel: string }> {
|
||||||
|
|||||||
@@ -42,6 +42,19 @@ describe('StorefrontProductsService', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('orders storefront products by sortOrder then createdAt desc', async () => {
|
||||||
|
await service.listStorefrontProducts(new Map(), undefined);
|
||||||
|
|
||||||
|
expect(productRepo.find).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
order: expect.objectContaining({
|
||||||
|
sortOrder: 'ASC',
|
||||||
|
createdAt: 'DESC'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('returns an empty map when no variant ids are requested', async () => {
|
it('returns an empty map when no variant ids are requested', async () => {
|
||||||
await expect(service.getStorefrontVariantsByIds([], new Map())).resolves.toEqual(new Map());
|
await expect(service.getStorefrontVariantsByIds([], new Map())).resolves.toEqual(new Map());
|
||||||
expect(variantRepo.find).not.toHaveBeenCalled();
|
expect(variantRepo.find).not.toHaveBeenCalled();
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ export class StorefrontProductsService {
|
|||||||
where: categoryId ? { isDraft: false, categories: { id: categoryId } } : { isDraft: false },
|
where: categoryId ? { isDraft: false, categories: { id: categoryId } } : { isDraft: false },
|
||||||
relations: ['variants', 'variants.images'],
|
relations: ['variants', 'variants.images'],
|
||||||
order: {
|
order: {
|
||||||
|
sortOrder: 'ASC',
|
||||||
createdAt: 'DESC',
|
createdAt: 'DESC',
|
||||||
variants: {
|
variants: {
|
||||||
sortOrder: 'ASC',
|
sortOrder: 'ASC',
|
||||||
@@ -87,7 +88,6 @@ export class StorefrontProductsService {
|
|||||||
where: { id, isDraft: false },
|
where: { id, isDraft: false },
|
||||||
relations: ['variants', 'variants.images'],
|
relations: ['variants', 'variants.images'],
|
||||||
order: {
|
order: {
|
||||||
createdAt: 'DESC',
|
|
||||||
variants: {
|
variants: {
|
||||||
sortOrder: 'ASC',
|
sortOrder: 'ASC',
|
||||||
createdAt: 'ASC',
|
createdAt: 'ASC',
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
import { BOOLEAN_STRING_VALUES } from '../consts/booleanStringValues';
|
||||||
|
|
||||||
|
export type BooleanStringValue = (typeof BOOLEAN_STRING_VALUES)[number];
|
||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
<link rel="icon" type="image/png" href="/favicon.png" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>cms</title>
|
<title>cms</title>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
Generated
+474
-443
File diff suppressed because it is too large
Load Diff
+4
-4
@@ -11,10 +11,10 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@element-plus/icons-vue": "^2.3.2",
|
"@element-plus/icons-vue": "^2.3.2",
|
||||||
"@tiptap/extension-link": "^3.22.5",
|
"@tiptap/extension-link": "^3.35.0",
|
||||||
"@tiptap/extension-placeholder": "^3.22.5",
|
"@tiptap/extension-placeholder": "^3.35.0",
|
||||||
"@tiptap/starter-kit": "^3.22.5",
|
"@tiptap/starter-kit": "^3.35.0",
|
||||||
"@tiptap/vue-3": "^3.22.5",
|
"@tiptap/vue-3": "^3.35.0",
|
||||||
"axios": "^1.15.1",
|
"axios": "^1.15.1",
|
||||||
"dayjs": "^1.11.19",
|
"dayjs": "^1.11.19",
|
||||||
"decimal.js": "^10.6.0",
|
"decimal.js": "^10.6.0",
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 163 KiB |
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 9.3 KiB |
@@ -224,6 +224,7 @@ const scrollToBottom = async (): Promise<void> => {
|
|||||||
border-radius: 14px;
|
border-radius: 14px;
|
||||||
line-height: 1.45;
|
line-height: 1.45;
|
||||||
max-width: min(100%, 560px);
|
max-width: min(100%, 560px);
|
||||||
|
min-width: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.order-chat-message--buyer .order-chat-bubble {
|
.order-chat-message--buyer .order-chat-bubble {
|
||||||
@@ -237,7 +238,11 @@ const scrollToBottom = async (): Promise<void> => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.order-chat-body {
|
.order-chat-body {
|
||||||
|
max-width: 100%;
|
||||||
|
min-width: 0;
|
||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
word-break: break-word;
|
||||||
}
|
}
|
||||||
|
|
||||||
.order-chat-delete {
|
.order-chat-delete {
|
||||||
|
|||||||
@@ -145,9 +145,11 @@ const downloadAttachment = async (
|
|||||||
}
|
}
|
||||||
|
|
||||||
.auto-delivery-item__content {
|
.auto-delivery-item__content {
|
||||||
|
max-width: 100%;
|
||||||
|
min-width: 0;
|
||||||
font-size: var(--el-font-size-small);
|
font-size: var(--el-font-size-small);
|
||||||
white-space: pre-wrap;
|
white-space: pre-wrap;
|
||||||
overflow-wrap: break-word;
|
overflow-wrap: anywhere;
|
||||||
word-break: break-word;
|
word-break: break-word;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -211,6 +211,7 @@ onBeforeUnmount(() => {
|
|||||||
|
|
||||||
.rich-text-editor-body :deep(.ProseMirror p) {
|
.rich-text-editor-body :deep(.ProseMirror p) {
|
||||||
margin: 0.35em 0;
|
margin: 0.35em 0;
|
||||||
|
min-height: 1lh;
|
||||||
}
|
}
|
||||||
|
|
||||||
.rich-text-editor-body :deep(.ProseMirror h2) {
|
.rich-text-editor-body :deep(.ProseMirror h2) {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ export interface Product {
|
|||||||
title: string;
|
title: string;
|
||||||
deliveryMode: DeliveryMode;
|
deliveryMode: DeliveryMode;
|
||||||
isDraft: boolean;
|
isDraft: boolean;
|
||||||
|
sortOrder: number;
|
||||||
descriptionHtml: string;
|
descriptionHtml: string;
|
||||||
variants?: ProductVariantExtended[];
|
variants?: ProductVariantExtended[];
|
||||||
categories?: Category[];
|
categories?: Category[];
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
export interface UpdateProductPayload {
|
export interface UpdateProductPayload {
|
||||||
title: string;
|
title: string;
|
||||||
isDraft: boolean;
|
isDraft: boolean;
|
||||||
|
sortOrder: number;
|
||||||
descriptionHtml: string;
|
descriptionHtml: string;
|
||||||
categoryIds: string[];
|
categoryIds: string[];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,15 @@
|
|||||||
/>
|
/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
|
<el-form-item label="Sort order" prop="sortOrder">
|
||||||
|
<el-input-number
|
||||||
|
v-model="productForm.sortOrder"
|
||||||
|
:min="0"
|
||||||
|
:step="1"
|
||||||
|
@update:model-value="productFormRef?.clearValidate('sortOrder')"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
<el-form-item label="Categories">
|
<el-form-item label="Categories">
|
||||||
<el-select
|
<el-select
|
||||||
v-model="selectedCategoryIds"
|
v-model="selectedCategoryIds"
|
||||||
@@ -161,7 +170,8 @@ const productFormRef = ref<FormInstance>();
|
|||||||
const productForm = reactive({
|
const productForm = reactive({
|
||||||
title: '',
|
title: '',
|
||||||
descriptionHtml: '',
|
descriptionHtml: '',
|
||||||
isDraft: true
|
isDraft: true,
|
||||||
|
sortOrder: 0
|
||||||
});
|
});
|
||||||
|
|
||||||
const productSaving = ref(false);
|
const productSaving = ref(false);
|
||||||
@@ -175,6 +185,10 @@ const productRules: FormRules = {
|
|||||||
message: `At most ${validationProductTitleMaxLength} characters`,
|
message: `At most ${validationProductTitleMaxLength} characters`,
|
||||||
trigger: 'blur'
|
trigger: 'blur'
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
sortOrder: [
|
||||||
|
{ required: true, message: 'Sort order is required', trigger: 'change' },
|
||||||
|
{ type: 'integer', message: 'Sort order must be a whole number', trigger: 'change' }
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -200,6 +214,7 @@ onBeforeMount(async () => {
|
|||||||
productForm.title = currentProduct.value.title;
|
productForm.title = currentProduct.value.title;
|
||||||
productForm.descriptionHtml = currentProduct.value.descriptionHtml;
|
productForm.descriptionHtml = currentProduct.value.descriptionHtml;
|
||||||
productForm.isDraft = currentProduct.value.isDraft;
|
productForm.isDraft = currentProduct.value.isDraft;
|
||||||
|
productForm.sortOrder = currentProduct.value.sortOrder;
|
||||||
selectedCategoryIds.value = (currentProduct.value.categories ?? []).map(c => c.id);
|
selectedCategoryIds.value = (currentProduct.value.categories ?? []).map(c => c.id);
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
@@ -236,6 +251,7 @@ const submitProduct = async (): Promise<void> => {
|
|||||||
title: productForm.title.trim(),
|
title: productForm.title.trim(),
|
||||||
descriptionHtml: productForm.descriptionHtml,
|
descriptionHtml: productForm.descriptionHtml,
|
||||||
isDraft: productForm.isDraft,
|
isDraft: productForm.isDraft,
|
||||||
|
sortOrder: productForm.sortOrder,
|
||||||
categoryIds: selectedCategoryIds.value
|
categoryIds: selectedCategoryIds.value
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,8 @@
|
|||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
|
|
||||||
|
<el-table-column prop="sortOrder" label="Order" width="80" />
|
||||||
|
|
||||||
<el-table-column label="Categories" min-width="160" show-overflow-tooltip>
|
<el-table-column label="Categories" min-width="160" show-overflow-tooltip>
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
{{ formatProductCategories(row.categories) }}
|
{{ formatProductCategories(row.categories) }}
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ Edit `.env.prod`. Mandatory configuration:
|
|||||||
| `POSTGRES_MIGRATIONS_RUN` | `true` |
|
| `POSTGRES_MIGRATIONS_RUN` | `true` |
|
||||||
| `PGADMIN_DEFAULT_PASSWORD` | strong random password |
|
| `PGADMIN_DEFAULT_PASSWORD` | strong random password |
|
||||||
| `NODE_ENV` | `production` |
|
| `NODE_ENV` | `production` |
|
||||||
| `CORS_ORIGINS` | `https://your-domain.com` |
|
|
||||||
| `CLEARNET_DOMAIN` | `your-domain.com` |
|
| `CLEARNET_DOMAIN` | `your-domain.com` |
|
||||||
| `JWT_SECRET` | strong random secret |
|
| `JWT_SECRET` | strong random secret |
|
||||||
| `CMS_PASSWORD` | strong admin password |
|
| `CMS_PASSWORD` | strong admin password |
|
||||||
@@ -56,8 +55,8 @@ Edit `.env.prod`. Mandatory configuration:
|
|||||||
| `MONERO_WALLET_PASSWORD` | strong wallet password |
|
| `MONERO_WALLET_PASSWORD` | strong wallet password |
|
||||||
| `ELECTRUM_NETWORK` | `mainnet` |
|
| `ELECTRUM_NETWORK` | `mainnet` |
|
||||||
| `ELECTRUM_SERVER` | Electrum peer as `host:port:s` (SSL) or `host:port:t` (TCP), e.g. `electrum.blockstream.info:50002:s` |
|
| `ELECTRUM_SERVER` | Electrum peer as `host:port:s` (SSL) or `host:port:t` (TCP), e.g. `electrum.blockstream.info:50002:s` |
|
||||||
| `ELECTRUM_WALLET_PASSWORD` | strong wallet password |
|
|
||||||
| `ELECTRUM_DAEMON_RPC_PASSWORD` | strong random password |
|
| `ELECTRUM_DAEMON_RPC_PASSWORD` | strong random password |
|
||||||
|
| `ELECTRUM_WALLET_PASSWORD` | strong wallet password |
|
||||||
| `VITE_API_BASE_URL` | `/api` |
|
| `VITE_API_BASE_URL` | `/api` |
|
||||||
| `VITE_SHOP_FIAT_CURRENCY` | same as `SHOP_FIAT_CURRENCY` |
|
| `VITE_SHOP_FIAT_CURRENCY` | same as `SHOP_FIAT_CURRENCY` |
|
||||||
|
|
||||||
@@ -159,10 +158,18 @@ Tor Browser will then show ".onion available" when visitors open the clearnet si
|
|||||||
3. Finish the setup checklist in settings.
|
3. Finish the setup checklist in settings.
|
||||||
4. Connect SimpleX notifications in shop settings.
|
4. Connect SimpleX notifications in shop settings.
|
||||||
|
|
||||||
## 10. Updates
|
## Updates
|
||||||
|
|
||||||
|
This pulls the latest code and rebuilds the stack (`deploy.sh`).
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
./deploy/scripts/update.sh
|
./deploy/scripts/update.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
This pulls the latest code and rebuilds the stack (`deploy.sh`).
|
## Backups
|
||||||
|
|
||||||
|
This creates a full disaster-recovery archive.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./deploy/scripts/backup.sh
|
||||||
|
```
|
||||||
|
|||||||
Executable
+337
@@ -0,0 +1,337 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||||
|
ENV_FILE="${ROOT_DIR}/.env.prod"
|
||||||
|
COMPOSE_FILE="${ROOT_DIR}/docker-compose.prod.yml"
|
||||||
|
BACKUP_DIR="${ROOT_DIR}/deploy/backups"
|
||||||
|
|
||||||
|
cd "$ROOT_DIR"
|
||||||
|
|
||||||
|
if [[ ! -f "$ENV_FILE" ]]; then
|
||||||
|
echo "Missing ${ENV_FILE}. Copy .env.example to .env.prod and configure it." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# shellcheck disable=SC1090
|
||||||
|
set -a
|
||||||
|
source "$ENV_FILE"
|
||||||
|
set +a
|
||||||
|
|
||||||
|
if [[ -z "${COMPOSE_PROJECT_NAME:-}" ]]; then
|
||||||
|
echo "COMPOSE_PROJECT_NAME is not set in .env.prod" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "${POSTGRES_USER:-}" || -z "${POSTGRES_DB:-}" ]]; then
|
||||||
|
echo "POSTGRES_USER and POSTGRES_DB must be set in .env.prod" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "${MONERO_WALLET_DIR:-}" ]]; then
|
||||||
|
echo "MONERO_WALLET_DIR is not set in .env.prod" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "${ELECTRUM_WALLET_DIR:-}" ]]; then
|
||||||
|
echo "ELECTRUM_WALLET_DIR is not set in .env.prod" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
compose() {
|
||||||
|
docker compose --env-file "$ENV_FILE" -f "$COMPOSE_FILE" "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve_host_path() {
|
||||||
|
local rel="${1:-}"
|
||||||
|
local label="$2"
|
||||||
|
|
||||||
|
if [[ -z "$rel" ]]; then
|
||||||
|
echo "Cannot resolve empty path for ${label}" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$rel" == /* ]]; then
|
||||||
|
echo "$rel"
|
||||||
|
else
|
||||||
|
echo "${ROOT_DIR}/${rel#./}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
build_compose_volume_name() {
|
||||||
|
local vol_key="$1"
|
||||||
|
echo "${COMPOSE_PROJECT_NAME}_${vol_key}"
|
||||||
|
}
|
||||||
|
|
||||||
|
require_min_bytes() {
|
||||||
|
local file="$1"
|
||||||
|
local min_bytes="$2"
|
||||||
|
local label="$3"
|
||||||
|
|
||||||
|
if [[ ! -f "$file" ]] || (( $(stat -c%s "$file") < min_bytes )); then
|
||||||
|
echo "Backup failed: ${label} is missing or empty." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
require_tar_entries() {
|
||||||
|
local file="$1"
|
||||||
|
local label="$2"
|
||||||
|
local entry_count
|
||||||
|
|
||||||
|
if [[ ! -f "$file" ]]; then
|
||||||
|
echo "Backup failed: ${label} is missing or has no archive entries." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
entry_count="$(tar tf "$file" 2>/dev/null | wc -l)"
|
||||||
|
|
||||||
|
if (( entry_count < 1 )); then
|
||||||
|
echo "Backup failed: ${label} is missing or has no archive entries." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
tar_volume() {
|
||||||
|
local vol_key="$1"
|
||||||
|
local archive_name="$2"
|
||||||
|
local vol_name
|
||||||
|
|
||||||
|
vol_name="$(build_compose_volume_name "$vol_key")"
|
||||||
|
|
||||||
|
if ! docker volume inspect "$vol_name" >/dev/null 2>&1; then
|
||||||
|
echo "Backup failed: Docker volume ${vol_name} not found. Is the stack deployed?" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
docker run --rm \
|
||||||
|
-v "${vol_name}:/data:ro" \
|
||||||
|
-v "${STAGING_TMP}:/backup" \
|
||||||
|
alpine tar -cf "/backup/${archive_name}" -C /data .
|
||||||
|
}
|
||||||
|
|
||||||
|
SHOULD_STOP=false
|
||||||
|
STOPPED=false
|
||||||
|
STAGING_TMP=""
|
||||||
|
ARCHIVE_TMP=""
|
||||||
|
|
||||||
|
on_exit() {
|
||||||
|
if [[ -n "$STAGING_TMP" && -d "$STAGING_TMP" ]]; then
|
||||||
|
rm -rf "$STAGING_TMP"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -n "$ARCHIVE_TMP" && -f "$ARCHIVE_TMP" ]]; then
|
||||||
|
rm -f "$ARCHIVE_TMP"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "$STOPPED" == true ]]; then
|
||||||
|
echo "Restarting NullCart..."
|
||||||
|
|
||||||
|
compose start
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
trap on_exit EXIT
|
||||||
|
trap 'exit 130' INT
|
||||||
|
trap 'exit 143' TERM
|
||||||
|
|
||||||
|
echo "Checking if PostgreSQL is running and accepting connections..."
|
||||||
|
|
||||||
|
cid="$(compose ps --status running -q postgres 2>/dev/null | head -n1)"
|
||||||
|
|
||||||
|
if [[ -z "$cid" ]]; then
|
||||||
|
echo "Backup failed: PostgreSQL is not running. Start the stack (for example: docker compose --env-file \"${ENV_FILE}\" -f \"${COMPOSE_FILE}\" up -d postgres)." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! compose exec -T postgres pg_isready -U "$POSTGRES_USER" -d "$POSTGRES_DB" >/dev/null 2>&1; then
|
||||||
|
echo "Backup failed: PostgreSQL is not accepting connections. Check container logs or wait until the database is healthy." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "PostgreSQL is running and accepting connections."
|
||||||
|
|
||||||
|
# Check if the script is running from an interactive terminal
|
||||||
|
if [[ ! -r /dev/tty ]]; then
|
||||||
|
echo "Run this script from an interactive terminal (for example: ssh -t)." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf 'Would you like to stop NullCart before doing backup? Doing backup while NullCart is running may lead to backup data corruption [y/n] (recommended y): '
|
||||||
|
|
||||||
|
read -n 1 -r STOP_ANSWER </dev/tty || {
|
||||||
|
echo "Backup failed: could not read answer from the terminal." >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
printf '\n'
|
||||||
|
|
||||||
|
case "$STOP_ANSWER" in
|
||||||
|
y)
|
||||||
|
SHOULD_STOP=true
|
||||||
|
;;
|
||||||
|
n)
|
||||||
|
echo "Continuing backup with NullCart running..."
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Invalid answer. Use y or n." >&2
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
STAGING_TMP="$(mktemp -d)"
|
||||||
|
|
||||||
|
mkdir -p "$BACKUP_DIR"
|
||||||
|
|
||||||
|
TIMESTAMP="$(date -u +%Y%m%d-%H%M%S)"
|
||||||
|
ARCHIVE_PATH="${BACKUP_DIR}/nullcart-backup-${TIMESTAMP}.tar.gz"
|
||||||
|
ARCHIVE_TMP="${ARCHIVE_PATH}.tmp"
|
||||||
|
|
||||||
|
if [[ "$SHOULD_STOP" == true ]]; then
|
||||||
|
stop_services=()
|
||||||
|
compose_services="$(compose config --services)"
|
||||||
|
|
||||||
|
while IFS= read -r svc; do
|
||||||
|
if [[ -z "$svc" || "$svc" == "postgres" ]]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
stop_services+=("$svc")
|
||||||
|
done <<<"$compose_services"
|
||||||
|
|
||||||
|
if ((${#stop_services[@]} == 0)); then
|
||||||
|
echo "Backup failed: no application services found to stop in ${COMPOSE_FILE}." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Stopping NullCart application services (PostgreSQL stays up for dump)..."
|
||||||
|
|
||||||
|
compose stop "${stop_services[@]}"
|
||||||
|
STOPPED=true
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Backing up PostgreSQL..."
|
||||||
|
|
||||||
|
compose exec -T postgres pg_dump -U "$POSTGRES_USER" -d "$POSTGRES_DB" -Fc > "${STAGING_TMP}/postgres.dump"
|
||||||
|
require_min_bytes "${STAGING_TMP}/postgres.dump" 64 "postgres.dump"
|
||||||
|
|
||||||
|
echo "Backing up environment file..."
|
||||||
|
|
||||||
|
cp "$ENV_FILE" "${STAGING_TMP}/env.prod"
|
||||||
|
require_min_bytes "${STAGING_TMP}/env.prod" 1 "env.prod"
|
||||||
|
|
||||||
|
echo "Backing up uploads..."
|
||||||
|
|
||||||
|
UPLOADS_DIR="${ROOT_DIR}/backend/uploads"
|
||||||
|
|
||||||
|
if [[ ! -d "$UPLOADS_DIR" ]]; then
|
||||||
|
echo "Backup failed: uploads directory not found at ${UPLOADS_DIR}" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
tar -cf "${STAGING_TMP}/uploads.tar" -C "${ROOT_DIR}/backend" uploads
|
||||||
|
require_tar_entries "${STAGING_TMP}/uploads.tar" "uploads.tar"
|
||||||
|
|
||||||
|
echo "Backing up Monero wallet..."
|
||||||
|
|
||||||
|
MONERO_WALLET_PATH="$(resolve_host_path "$MONERO_WALLET_DIR" "Monero wallet")"
|
||||||
|
|
||||||
|
if [[ ! -d "$MONERO_WALLET_PATH" ]]; then
|
||||||
|
echo "Backup failed: Monero wallet directory not found at ${MONERO_WALLET_PATH}" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "$(ls -A "$MONERO_WALLET_PATH" 2>/dev/null || true)" ]]; then
|
||||||
|
echo "Backup failed: Monero wallet directory is empty at ${MONERO_WALLET_PATH}" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
tar -cf "${STAGING_TMP}/monero-wallet.tar" -C "$(dirname "$MONERO_WALLET_PATH")" "$(basename "$MONERO_WALLET_PATH")"
|
||||||
|
require_tar_entries "${STAGING_TMP}/monero-wallet.tar" "monero-wallet.tar"
|
||||||
|
|
||||||
|
echo "Backing up Electrum wallet..."
|
||||||
|
|
||||||
|
ELECTRUM_WALLET_PATH="$(resolve_host_path "$ELECTRUM_WALLET_DIR" "Electrum wallet")"
|
||||||
|
|
||||||
|
if [[ ! -d "$ELECTRUM_WALLET_PATH" ]]; then
|
||||||
|
echo "Backup failed: Electrum wallet directory not found at ${ELECTRUM_WALLET_PATH}" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -z "$(ls -A "$ELECTRUM_WALLET_PATH" 2>/dev/null || true)" ]]; then
|
||||||
|
echo "Backup failed: Electrum wallet directory is empty at ${ELECTRUM_WALLET_PATH}" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
tar -cf "${STAGING_TMP}/electrum-wallet.tar" -C "$(dirname "$ELECTRUM_WALLET_PATH")" "$(basename "$ELECTRUM_WALLET_PATH")"
|
||||||
|
require_tar_entries "${STAGING_TMP}/electrum-wallet.tar" "electrum-wallet.tar"
|
||||||
|
|
||||||
|
echo "Backing up Docker volumes..."
|
||||||
|
|
||||||
|
echo "Backing up Tor hidden service volume..."
|
||||||
|
|
||||||
|
tar_volume "nullcart.tor.prod.data" "volume-tor.tar"
|
||||||
|
require_tar_entries "${STAGING_TMP}/volume-tor.tar" "volume-tor.tar"
|
||||||
|
|
||||||
|
echo "Backing up SimpleX volume..."
|
||||||
|
|
||||||
|
tar_volume "nullcart.simplex.prod.data" "volume-simplex.tar"
|
||||||
|
require_tar_entries "${STAGING_TMP}/volume-simplex.tar" "volume-simplex.tar"
|
||||||
|
|
||||||
|
echo "Backing up pgAdmin volume..."
|
||||||
|
|
||||||
|
tar_volume "nullcart.pgadmin.prod.data" "volume-pgadmin.tar"
|
||||||
|
require_tar_entries "${STAGING_TMP}/volume-pgadmin.tar" "volume-pgadmin.tar"
|
||||||
|
|
||||||
|
echo "Backing up TLS certs directory..."
|
||||||
|
|
||||||
|
CERTS_DIR="${ROOT_DIR}/deploy/certs"
|
||||||
|
|
||||||
|
if [[ ! -d "$CERTS_DIR" ]]; then
|
||||||
|
echo "Backup failed: TLS certs directory not found at ${CERTS_DIR}" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
tar -cf "${STAGING_TMP}/certs.tar" -C "${ROOT_DIR}/deploy" certs
|
||||||
|
require_tar_entries "${STAGING_TMP}/certs.tar" "certs.tar"
|
||||||
|
|
||||||
|
echo "Backing up Git commit..."
|
||||||
|
|
||||||
|
GIT_REV=""
|
||||||
|
|
||||||
|
if git -C "$ROOT_DIR" rev-parse HEAD >/dev/null 2>&1; then
|
||||||
|
GIT_REV="$(git -C "$ROOT_DIR" rev-parse HEAD)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
{
|
||||||
|
echo "NullCart backup"
|
||||||
|
echo "Created (UTC): $(date -u +"%Y-%m-%dT%H:%M:%SZ")"
|
||||||
|
echo "Compose project: ${COMPOSE_PROJECT_NAME}"
|
||||||
|
echo "Stopped application services before pg_dump: $([[ "$STOPPED" == true ]] && echo yes || echo no)"
|
||||||
|
|
||||||
|
if [[ -n "$GIT_REV" ]]; then
|
||||||
|
echo "Git commit: ${GIT_REV}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "Contents:"
|
||||||
|
echo " postgres.dump PostgreSQL custom-format dump (pg_restore)"
|
||||||
|
echo " env.prod Production environment file"
|
||||||
|
echo " uploads.tar backend/uploads"
|
||||||
|
echo " monero-wallet.tar Monero wallet directory"
|
||||||
|
echo " electrum-wallet.tar Electrum wallet directory"
|
||||||
|
echo " volume-tor.tar Tor hidden service keys"
|
||||||
|
echo " volume-simplex.tar SimpleX CLI data"
|
||||||
|
echo " volume-pgadmin.tar pgAdmin data"
|
||||||
|
echo " certs.tar deploy/certs (TLS)"
|
||||||
|
} > "${STAGING_TMP}/MANIFEST.txt"
|
||||||
|
|
||||||
|
require_min_bytes "${STAGING_TMP}/MANIFEST.txt" 1 "MANIFEST.txt"
|
||||||
|
|
||||||
|
rm -f "$ARCHIVE_TMP"
|
||||||
|
tar czf "$ARCHIVE_TMP" -C "$STAGING_TMP" .
|
||||||
|
tar tzf "$ARCHIVE_TMP" >/dev/null
|
||||||
|
chmod 600 "$ARCHIVE_TMP"
|
||||||
|
mv -f "$ARCHIVE_TMP" "$ARCHIVE_PATH"
|
||||||
|
|
||||||
|
echo "Backup complete: ${ARCHIVE_PATH}"
|
||||||
|
echo "This archive contains secrets. It is recommended to store it encrypted on an external storage."
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
networks:
|
||||||
|
default:
|
||||||
|
driver: bridge
|
||||||
|
ipam:
|
||||||
|
config:
|
||||||
|
- subnet: 172.30.0.0/16
|
||||||
|
gateway: 172.30.0.1
|
||||||
|
driver_opts:
|
||||||
|
com.docker.network.bridge.name: nullcart0
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
services:
|
services:
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:16
|
image: postgres:16.16
|
||||||
container_name: ${COMPOSE_PROJECT_NAME}_postgres
|
container_name: ${COMPOSE_PROJECT_NAME}_postgres
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
environment:
|
environment:
|
||||||
@@ -16,7 +16,7 @@ services:
|
|||||||
retries: 10
|
retries: 10
|
||||||
|
|
||||||
pgadmin:
|
pgadmin:
|
||||||
image: dpage/pgadmin4
|
image: dpage/pgadmin4:9.19.0
|
||||||
container_name: ${COMPOSE_PROJECT_NAME}_pgadmin
|
container_name: ${COMPOSE_PROJECT_NAME}_pgadmin
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
environment:
|
environment:
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
services:
|
services:
|
||||||
postgres:
|
postgres:
|
||||||
image: postgres:16
|
image: postgres:16.16
|
||||||
container_name: ${COMPOSE_PROJECT_NAME}_postgres
|
container_name: ${COMPOSE_PROJECT_NAME}_postgres
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
environment:
|
environment:
|
||||||
@@ -16,7 +16,7 @@ services:
|
|||||||
retries: 10
|
retries: 10
|
||||||
|
|
||||||
pgadmin:
|
pgadmin:
|
||||||
image: dpage/pgadmin4
|
image: dpage/pgadmin4:9.19.0
|
||||||
container_name: ${COMPOSE_PROJECT_NAME}_pgadmin
|
container_name: ${COMPOSE_PROJECT_NAME}_pgadmin
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
environment:
|
environment:
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ run_electrum_offline setconfig rpcpassword "${ELECTRUM_DAEMON_RPC_PASSWORD}"
|
|||||||
run_electrum_offline setconfig rpchost 0.0.0.0
|
run_electrum_offline setconfig rpchost 0.0.0.0
|
||||||
run_electrum_offline setconfig rpcport "${ELECTRUM_DAEMON_PORT}"
|
run_electrum_offline setconfig rpcport "${ELECTRUM_DAEMON_PORT}"
|
||||||
run_electrum_offline setconfig server "${ELECTRUM_SERVER}"
|
run_electrum_offline setconfig server "${ELECTRUM_SERVER}"
|
||||||
|
run_electrum_offline setconfig oneserver true
|
||||||
|
run_electrum_offline setconfig auto_connect false
|
||||||
|
|
||||||
trap 'run_electrum stop || true' SIGTERM SIGINT
|
trap 'run_electrum stop || true' SIGTERM SIGINT
|
||||||
|
|
||||||
|
|||||||
@@ -57,12 +57,13 @@ ENV VITE_API_BASE_URL=$VITE_API_BASE_URL \
|
|||||||
|
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
FROM nginx:alpine
|
FROM nginx:1.30.8-alpine3.24
|
||||||
|
|
||||||
RUN apk add --no-cache gettext
|
RUN apk add --no-cache gettext
|
||||||
|
|
||||||
COPY --from=cms-builder /cms/dist /usr/share/nginx/html/cms
|
COPY --from=cms-builder /cms/dist /usr/share/nginx/html/cms
|
||||||
|
|
||||||
|
COPY nginx/logging.conf /etc/nginx/conf.d/logging.conf
|
||||||
COPY nginx/conf.d/ /etc/nginx/templates/conf.d/
|
COPY nginx/conf.d/ /etc/nginx/templates/conf.d/
|
||||||
COPY nginx/snippets/ /etc/nginx/templates/snippets/
|
COPY nginx/snippets/ /etc/nginx/templates/snippets/
|
||||||
COPY nginx/docker-entrypoint.sh /docker-entrypoint.sh
|
COPY nginx/docker-entrypoint.sh /docker-entrypoint.sh
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
access_log off;
|
||||||
|
error_log /dev/null;
|
||||||
@@ -31,13 +31,9 @@ location /api {
|
|||||||
proxy_pass http://backend:${BACKEND_PORT};
|
proxy_pass http://backend:${BACKEND_PORT};
|
||||||
}
|
}
|
||||||
|
|
||||||
location = /cms {
|
location /cms {
|
||||||
return 301 /cms/;
|
|
||||||
}
|
|
||||||
|
|
||||||
location /cms/ {
|
|
||||||
root /usr/share/nginx/html;
|
root /usr/share/nginx/html;
|
||||||
try_files $uri $uri/ /cms/index.html;
|
try_files $uri /cms/index.html;
|
||||||
}
|
}
|
||||||
|
|
||||||
location /pgadmin {
|
location /pgadmin {
|
||||||
|
|||||||
Reference in New Issue
Block a user