add server to monorepo.

This commit is contained in:
a.bouhuolia
2023-02-03 11:57:50 +02:00
parent 28e309981b
commit 80b97b5fdc
1303 changed files with 137049 additions and 0 deletions

View File

@@ -0,0 +1,181 @@
import dotenv from 'dotenv';
// Set the NODE_ENV to 'development' by default
// process.env.NODE_ENV = process.env.NODE_ENV || 'development';
const envFound = dotenv.config();
if (envFound.error) {
// This error should crash whole process
throw new Error("⚠️ Couldn't find .env file ⚠️");
}
export default {
/**
* Your favorite port
*/
port: parseInt(process.env.PORT, 10),
/**
* System database configuration.
*/
system: {
db_client: process.env.SYSTEM_DB_CLIENT,
db_host: process.env.SYSTEM_DB_HOST,
db_user: process.env.SYSTEM_DB_USER,
db_password: process.env.SYSTEM_DB_PASSWORD,
db_name: process.env.SYSTEM_DB_NAME,
charset: process.env.SYSTEM_DB_CHARSET,
migrations_dir: process.env.SYSTEM_MIGRATIONS_DIR,
seeds_dir: process.env.SYSTEM_SEEDS_DIR,
},
/**
* Tenant database configuration.
*/
tenant: {
db_client: process.env.TENANT_DB_CLIENT,
db_name_prefix: process.env.TENANT_DB_NAME_PERFIX,
db_host: process.env.TENANT_DB_HOST,
db_user: process.env.TENANT_DB_USER,
db_password: process.env.TENANT_DB_PASSWORD,
charset: process.env.TENANT_DB_CHARSET,
migrations_dir: process.env.TENANT_MIGRATIONS_DIR,
seeds_dir: process.env.TENANT_SEEDS_DIR,
},
/**
* Databases manager config.
*/
manager: {
superUser: process.env.DB_MANAGER_SUPER_USER,
superPassword: process.env.DB_MANAGER_SUPER_PASSWORD,
},
/**
* Mail.
*/
mail: {
host: process.env.MAIL_HOST,
port: process.env.MAIL_PORT,
secure: !!parseInt(process.env.MAIL_SECURE, 10),
username: process.env.MAIL_USERNAME,
password: process.env.MAIL_PASSWORD,
},
/**
* Mongo DB.
*/
mongoDb: {
/**
* That long string from mlab
*/
databaseURL: process.env.MONGODB_DATABASE_URL,
},
/**
* Agenda
*/
agenda: {
dbCollection: process.env.AGENDA_DB_COLLECTION,
pooltime: process.env.AGENDA_POOL_TIME,
concurrency: parseInt(process.env.AGENDA_CONCURRENCY, 10),
},
/**
* Agendash.
*/
agendash: {
user: process.env.AGENDASH_AUTH_USER,
password: process.env.AGENDASH_AUTH_PASSWORD,
},
/**
* Easy SMS gateway.
*/
easySMSGateway: {
api_key: process.env.EASY_SMS_TOKEN,
},
/**
* JWT secret.
*/
jwtSecret: process.env.JWT_SECRET,
resetPasswordSeconds: 600,
/**
*
*/
customerSuccess: {
email: 'success@bigcapital.ly',
phoneNumber: '(218) 92 791 8381',
},
baseURL: process.env.BASE_URL,
/**
* General API prefix.
*/
api: {
prefix: '/api',
},
/**
* Licenses api basic authentication.
*/
licensesAuth: {
user: process.env.LICENSES_AUTH_USER,
password: process.env.LICENSES_AUTH_PASSWORD,
},
/**
* Redis storage configuration.
*/
redis: {
port: 6379,
},
/**
* Throttler configuration.
*/
throttler: {
login: {
points: 5,
duration: 60 * 60 * 24 * 1, // Store number for 90 days since first fail
blockDuration: 60 * 15,
},
requests: {
points: 60,
duration: 60,
blockDuration: 60 * 10,
},
},
/**
* Users registeration configuration.
*/
registration: {
countries: {
whitelist: ['LY'],
blacklist: [],
},
},
/**
* Puppeteer remote browserless connection.
*/
puppeteer: {
browserWSEndpoint: process.env.BROWSER_WS_ENDPOINT,
},
protocol: '',
hostname: '',
scheduleComputeItemCost: 'in 5 seconds',
/**
* Latest tenant database batch number.
*
* Should increment the batch number once you create a new migrations or seeds
* to application detarmines to upgrade.
*/
databaseBatch: 4,
};

View File

@@ -0,0 +1,59 @@
import config from '@/config';
import { ITenant } from '@/interfaces';
export const tenantKnexConfig = (tenant: ITenant) => {
const { organizationId, id } = tenant;
return {
client: config.tenant.db_client,
connection: {
host: config.tenant.db_host,
user: config.tenant.db_user,
password: config.tenant.db_password,
database: `${config.tenant.db_name_prefix}${organizationId}`,
charset: config.tenant.charset,
},
migrations: {
directory: config.tenant.migrations_dir,
},
seeds: {
tableName: 'bigcapital_seeds',
directory: config.tenant.seeds_dir,
},
pool: { min: 0, max: 5 },
userParams: {
tenantId: id,
organizationId
}
};
};
export const systemKnexConfig = {
client: config.system.db_client,
connection: {
host: config.system.db_host,
user: config.system.db_user,
password: config.system.db_password,
database: config.system.db_name,
charset: 'utf8',
},
migrations: {
directory: config.system.migrations_dir,
},
seeds: {
directory: config.system.seeds_dir,
},
pool: { min: 0, max: 7 },
};
export const systemDbManager = {
collate: [],
superUser: config.manager.superUser,
superPassword: config.manager.superPassword,
};
export const tenantSeedConfig = (tenant: ITenant) => {
return {
directory: config.tenant.seeds_dir,
};
}

View File

@@ -0,0 +1,207 @@
import { ISmsNotificationDefined, SMS_NOTIFICATION_KEY } from '@/interfaces';
export default [
{
notificationLabel: 'sms_notification.invoice_details.label',
notificationDescription: 'sms_notification.invoice_details.description',
key: SMS_NOTIFICATION_KEY.SALE_INVOICE_DETAILS,
module: 'sale-invoice',
moduleFormatted: 'module.sale_invoices.label',
allowedVariables: [
{
variable: 'InvoiceNumber',
description: 'sms_notification.invoice.var.invoice_number',
},
{
variable: 'ReferenceNumber',
description: 'sms_notification.invoice.var.reference_number',
},
{
variable: 'CustomerName',
description: 'sms_notification.invoice.var.customer_name',
},
{
variable: 'DueAmount',
description: 'sms_notification.invoice.var.due_amount',
},
{
variable: 'DueDate',
description: 'sms_notification.invoice.var.due_date',
},
{
variable: 'Amount',
description: 'sms_notification.invoice.var.amount',
},
{
variable: 'CompanyName',
description: 'sms_notification.invoice.var.company_name',
},
],
defaultSmsMessage: 'sms_notification.invoice_details.default_message',
defaultIsNotificationEnabled: true,
},
{
notificationLabel: 'sms_notification.invoice_reminder.label',
notificationDescription: 'sms_notification.invoice_reminder.description',
key: SMS_NOTIFICATION_KEY.SALE_INVOICE_REMINDER,
module: 'sale-invoice',
moduleFormatted: 'module.sale_invoices.label',
allowedVariables: [
{
variable: 'InvoiceNumber',
description: 'sms_notification.invoice.var.invoice_number',
},
{
variable: 'ReferenceNumber',
description: 'sms_notification.invoice.var.reference_number',
},
{
variable: 'CustomerName',
description: 'sms_notification.invoice.var.customer_name',
},
{
variable: 'DueAmount',
description: 'sms_notification.invoice.var.due_amount',
},
{
variable: 'DueDate',
description: 'sms_notification.invoice.var.due_date',
},
{
variable: 'Amount',
description: 'sms_notification.invoice.var.amount',
},
{
variable: 'CompanyName',
description: 'sms_notification.invoice.var.company_name',
},
],
defaultSmsMessage: 'sms_notification.invoice_reminder.default_message',
defaultIsNotificationEnabled: true,
},
{
notificationLabel: 'sms_notification.receipt_details.label',
notificationDescription: 'sms_notification.receipt_details.description',
key: SMS_NOTIFICATION_KEY.SALE_RECEIPT_DETAILS,
module: 'sale-receipt',
moduleFormatted: 'module.sale_receipts.label',
allowedVariables: [
{
variable: 'CustomerName',
description: 'sms_notification.receipt.var.customer_name',
},
{
variable: 'ReceiptNumber',
description: 'sms_notification.receipt.var.receipt_number',
},
{
variable: 'ReferenceNumber',
description: 'sms_notification.receipt.var.reference_number',
},
{
variable: 'Amount',
description: 'sms_notification.receipt.var.amount',
},
{
variable: 'CompanyName',
description: 'sms_notification.receipt.var.company_name',
},
],
defaultSmsMessage: 'sms_notification.receipt_details.default_message',
},
{
notificationLabel: 'sms_notification.sale_estimate_details.label',
notificationDescription: 'sms_notification.estimate_details.description',
key: SMS_NOTIFICATION_KEY.SALE_ESTIMATE_DETAILS,
module: 'sale-estimate',
moduleFormatted: 'module.sale_estimates.label',
allowedVariables: [
{
variable: 'EstimateNumber',
description: 'sms_notification.estimate.var.estimate_number',
},
{
variable: 'EstimateDate',
description: 'sms_notification.estimate.var.estimate_date',
},
{
variable: 'ExpirationDate',
description: 'sms_notification.estimate.var.expiration_date'
},
{
variable: 'ReferenceNumber',
description: 'sms_notification.estimate.var.reference_number',
},
{
variable: 'CustomerName',
description: 'sms_notification.estimate.var.customer_name',
},
{
variable: 'Amount',
description: 'sms_notification.estimate.var.amount',
},
{
variable: 'CompanyName',
description: 'sms_notification.estimate.var.company_name',
},
],
defaultSmsMessage: 'sms_notification.estimate.default_message',
},
{
notificationLabel: 'sms_notification.payment_receive_details.label',
notificationDescription: 'sms_notification.payment_receive.description',
key: SMS_NOTIFICATION_KEY.PAYMENT_RECEIVE_DETAILS,
module: 'payment-receive',
moduleFormatted: 'module.payment_receives.label',
allowedVariables: [
{
variable: 'PaymentNumber',
description: 'sms_notification.payment.var.payment_number',
},
{
variable: 'ReferenceNumber',
description: 'sms_notification.payment.var.reference_number',
},
{
variable: 'CustomerName',
description: 'sms_notification.payment.var.customer_name',
},
{
variable: 'Amount',
description: 'sms_notification.payment.var.amount',
},
{
variable: 'InvoiceNumber',
description: 'sms_notification.payment.var.invoice_number',
},
{
variable: 'CompanyName',
description: 'sms_notification.payment.company_name',
},
],
defaultSmsMessage: 'sms_notification.payment_receive.default_message',
defaultIsNotificationEnabled: true,
},
{
notificationLabel: 'sms_notification.customer_balance.label',
notificationDescription: 'sms_notification.customer_balance.description',
key: SMS_NOTIFICATION_KEY.CUSTOMER_BALANCE,
module: 'customer',
moduleFormatted: 'module.customers.label',
defaultSmsMessage: 'sms_notification.customer_balance.default_message',
allowedVariables: [
{
variable: 'CustomerName',
description: 'sms_notification.customer.var.customer_name',
},
{
variable: 'Balance',
description: 'sms_notification.customer.var.balance',
},
{
variable: 'CompanyName',
description: 'sms_notification.customer.var.company_name',
},
],
},
] as ISmsNotificationDefined[];