Any co-dependencies will be installed automatically.
Install CommTrackr
npm install commtrackr
Quick Start
This example demonstrates how to set up CommTrackr in an Express.js application using a MySQL session store.
server.js
constexpress =require('express');constsession =require("express-session");constMySQLStore =require('express-mysql-session')(session); // Use a MySQL session storeconstsessionStore = newMySQLStore({host: '',port: 3306,user: '',password: '',database: ''});app.use(session({name: '',key: '',secret: '',store:sessionStore,resave: false,saveUninitialized: false}));constapp =express();constcommtrackr =require('commtrackr'); // Import the commtrackr packageapp.use('/commtrackr', commtrackr.routes); // Mount routes to /commtrackr pathcommtrackr.init({ // Initialize CommTracker with configurationstenant: {slug: 'commtrackr', // Unique identifier for the tenantname: 'CommTrackr', // Name of the tenantmetaTitle: 'CommTrackr', // Name of the tenant for meta title tagsdescription: 'Easily plan, manage, and track client commissions.', // Description of the tenantlogo: 'http://localhost:3000/commtrackr/logo.png', // Tenant logo imagethemeColor: '#ffffff', // Tenant theme color (optional)forceDarkMode: false, // Force dark mode for the tenant (optional)banner: 'http://localhost:3000/commtrackr/banner_public.png', // Tenant banner imagedomain: 'http://localhost:3000', // Domain for the tenant, including protocolpath: '/commtrackr', // Path that CommTracker is mounted onauth: {enabled: false, // Enable or disable authenticationprovider: '', // Recognizable name of authentication providerurl: '', // URL to redirect to for authentication },stylesheets: [], // Additional stylesheets to includescripts: [], // Additional scripts to includecustomText: {} // Custom text overrides for the tenant; see "Custom Text" section below },vars: {userId: 'username', // req.session object variable for unique user identificationuserName: 'Name', // req.session object variable for user namerole: 'role', // req.session object variable for user roleroleAliases: { // Use if your role names differ from 'admin', 'dev', or 'user'user: ['user', 'standard', 'basic'], // Aliases for user rolesdev: ['dev', 'developer'], // Aliases for developer rolesadmin: ['admin', 'administrator', 'superuser'] // Aliases for admin roles },access: { // Alternative access control using numeric levelsvar: 'access', // req.session object variable for access leveluser: [0], // Access levels for standard usersdev: [1], // Access levels for developersadmin: [2] // Access levels for admins },commissions: 'commissions', // req.session object variable for user commissions arraypossibleStatuses: [ // Possible commission status strings {label: 'Completed', // Status labelvalue: 'Completed' // Status value }, {label: 'In Progress',value: 'In Progress' }, {label: 'On Hold',value: 'On Hold' }, {label: 'Cancelled',value: 'Cancelled' } ],disableFieldEditing: ['amount', 'currency'], // Array of field IDs that admins cannot editusers: 'users' // req.session object variable for all users array },fields: [ {id: 'name', // Unique identifier for the field. ID 'user' is reserved by the system and may not be used heretype: 'text', // Field type ('text', 'number', 'date', 'textarea', 'checkbox', 'radio', 'select', 'multiselect')label: 'Website Name', // Field labeldescription: 'The name of the website or project.', // Field descriptionplaceholder: 'e.g. My Website', // Placeholder text for the fieldrequired: true, // Whether the field is requiredoptions: [ // Options for select, radio, and multiselect fields {label: 'Option 1', // Option labelvalue: 'option1' // Option value } ], }, ],handlers: {create: (req, data) => { // Custom handler function for processing commission data // This function is called when a commission is created // You can implement your own logic here, such as saving to a database // data contains the commission fields data array // Action metadata can be accessed via data.createdAt and data.createdBy },update: (req, data) => { // Custom handler function for updating commission data // This function is called when a commission is updated // You can implement your own logic here, such as saving to a database // data contains the updated commission object // The constant data.id contains the unique commission ID // Action metadata can be accessed via data.updatedAt, data.updatedBy, and data.sendEmail // Updated metadata can be accessed via data.user, data.amount, data.currency, data.date, data.status, data.locked, and data.assignedTo // Updated fields can be accessed via data.fields // Updated tasks can be accessed via data.tasks },sync: (req) => { // Custom handler function for syncing user's commissions // This function is called when the user manually triggers a sync // You can implement your own logic here, such as syncing your commissions session variable }, },});app.listen(3000, () => {console.log('Server is running on http://localhost:3000');});
More detail on how to configure each option can be found in Set Up.