refactor: restructure storage and environment modules; remove unused code

- Deleted unused PouchDB configuration and types from core storage.
- Removed Electron-related hooks and utilities that are no longer needed.
- Introduced new local storage management for application keys.
- Created a new environment wrapper for landing application.
- Added public HTTP client for landing application with minimal configuration.
- Implemented new PouchDB entities for items and POS configurations.
- Updated main application entry point to reflect new storage structure.
This commit is contained in:
Firman Ramdhani
2026-05-29 17:36:34 +07:00
parent b2e622c57e
commit 5d9f0f6d94
26 changed files with 233 additions and 197 deletions
@@ -0,0 +1,2 @@
export * from './item.pouchdb.entity';
export * from './pos-configuration.pouchdb.entity';
@@ -0,0 +1,27 @@
interface ItemRateEntity {
season_period?: string | null;
price: string | number;
}
interface ItemCategoryEntity {
_id?: string;
name?: string;
[key: string]: any;
}
/**
* Represents a sellable product or service.
*/
export interface ItemEntity {
_id: string;
_rev?: string;
name: string;
base_price: string | number;
item_type: string;
usage_type?: string;
item_category?: ItemCategoryEntity[] | ItemCategoryEntity | string;
item_rates?: ItemRateEntity[];
// Allow for other ERP-specific fields
[key: string]: any;
}
@@ -0,0 +1,16 @@
import { ItemEntity } from './item.pouchdb.entity';
/**
* Represents the configuration and assigned data for a specific Point of Sale terminal.
*/
export interface POSConfigurationEntity {
_id: string;
_rev?: string;
pos_number: string;
pos_name: string;
items: ItemEntity[];
payment_methods?: any[];
// Allow for other ERP-specific fields
[key: string]: any;
}
@@ -0,0 +1,56 @@
/**
* Multi-Database PouchDB Configuration for apps/web.
*
* This module demonstrates the IoC pattern: the consuming app decides
* which databases to create and where they sync to. The core engine
* (`PouchDatabaseManager`) has zero knowledge of business domains.
*/
import { ENV } from '../../environment';
import { PouchDatabaseManager } from '@repo/core-storage';
import { ItemEntity, POSConfigurationEntity } from './entities';
// ─── Manager Singleton ──────────────────────────────────────────
export const dbManager = new PouchDatabaseManager();
// ─── Helper: Build Secure Remote URL ────────────────────────────
function buildRemoteUrl(dbName: string): string | undefined {
const { COUCHDB_BASE_URL, COUCHDB_USERNAME, COUCHDB_PASSWORD } = ENV;
if (!COUCHDB_BASE_URL || !COUCHDB_USERNAME || !COUCHDB_PASSWORD) {
console.warn(`[DB Config] CouchDB credentials missing — "${dbName}" will run in offline-only mode.`);
return undefined;
}
// 1. Tambahkan http:// secara otomatis jika DevOps hanya mengisi IP Address di .env
const safeBaseUrl = COUCHDB_BASE_URL.startsWith('http') ? COUCHDB_BASE_URL : `http://${COUCHDB_BASE_URL}`;
try {
// 2. Gunakan URL parser yang aman dari karakter aneh pada password
const url = new URL(safeBaseUrl);
url.username = encodeURIComponent(COUCHDB_USERNAME);
url.password = encodeURIComponent(COUCHDB_PASSWORD);
url.pathname = `/${dbName}`;
return url.toString();
} catch (error) {
console.error(`[DB Config] Invalid URL format for CouchDB:`, safeBaseUrl);
return undefined;
}
}
// ─── Register Application Databases ─────────────────────────────
/** POS Configuration database — stores device settings, theme, etc. */
export const posConfigDB = dbManager.register<POSConfigurationEntity>({
localName: 'pos_configuration',
remoteUrl: buildRemoteUrl('pos_configuration'),
});
/** Items database — products available for sale in POS. */
export const itemDB = dbManager.register<ItemEntity>({
localName: 'item',
remoteUrl: buildRemoteUrl('item'),
});