SAGECONNECT is an automation software that streamlines the process of interconnecting the SAGE 300 ERP with the portaldeproveedores.mx API. The software simplifies administrative processes such as supplier registration, invoice management, payment processing, and payment supplements in both systems. By maintaining data atomicity in both systems, SAGECONNECT ensures that all changes made in one system are accurately reflected in the other, thereby reducing errors and increasing efficiency. With SAGECONNECT, businesses can seamlessly manage their financial operations while reducing manual effort and minimizing the risk of errors.
-
Node.js (Stable version)
The system was created on Node v18.12.1
-
npm (Stable version)
The system was created using npm v8.19.2
This package manager for JavaScript is automatically installed when you installed Node.js
-
Git
The system was created using git v2.41.0.windows.3
The following is a series of instructions for installing the necessary programs and downloading the packages for this implementation.
To download Git you must do it from the following Download Git for Windows
- Select your preferred installation option
- Click next until the installation start
To download Node.js you must do it from the following Node.js download page
- Select your corresponding version | Windows Installer 32-bit or 64-bit
- Execute the intaller
- Read and accept the terms of the license agreement.
- Click next until you found the Custom Setup and click all the icons to perfom a correct installation
- Accept the automatically installation for native modules in the Tools for Native Modules screen
- Click on the install button to install the application.
After you have downloaded and installed the previous applications you will need to run the following command in a terminal so that you can clone this repository:
git clone https://github.com/FReptar0/sageconnect
‼️ Make sure you are cloning the program to the desired path.
Once you have cloned the repository, you will need to run the following command in a terminal to install the necessary packages for the program to run correctly:
npm install
‼️ Make sure that you are running the command in the program folder
After installing the dependencies, you need to configure the environment file. All configuration is in a single .env file (unified since v1.1).
cp .env.example .envOpen .env and replace the example values with your actual credentials and settings. The file is organized by sections:
- DATABASE — SQL Server connection credentials
- PORTAL (Focaltec) — Portal de Proveedores API credentials
- MAILING — Email configuration (optional)
- PATHS — File system paths for logs and downloads
- APP — Application settings, company info, address defaults
⚠️ Security Notice: Never commit the actual.envfile to version control. Only.env.exampleshould be tracked in Git.
‼️ Important: The application validates all required environment variables at startup. If any required variable is missing or empty, the process will print a list of missing variables and exit before running any business logic.
‼️ Migrating from v1.0 (5 separate .env files)? Run the migration script:node scripts/migrate-env.js. It reads your old files, shows a preview, and creates the unified.envon confirmation. See Migrating from v1.0 for details.
All configuration lives in a single .env file organized by sections. See .env.example for the full template with inline documentation.
| Variable | Description | Example |
|---|---|---|
| DB_USER | SQL Server username | your_db_user |
| DB_PASSWORD | SQL Server password | your_db_password |
| SERVER | SQL Server hostname | your_sql_server_host |
| DATABASE | Default database name | YOUR_DATABASE_NAME |
‼️ DB_USERandDB_PASSWORDwere renamed fromUSERandPASSWORDin v1.1 to avoid collision with OS environment variables.
| Variable | Description | Example |
|---|---|---|
| URL | Portal de Proveedores API URL | https://api.portaldeproveedores.mx |
| TENANT_ID | Company identifiers (comma-separated for multi-tenant) | tenant1,tenant2 |
| API_KEY | API keys (comma-separated, same index as TENANT_ID) | key1,key2 |
| API_SECRET | API secrets (comma-separated, same index as TENANT_ID) | secret1,secret2 |
| DATABASES | Database names per tenant (comma-separated) | DB1,DB2 |
| EXTERNAL_IDS | External IDs/RFCs per tenant (comma-separated) | RFC1,RFC2 |
‼️ Multi-tenant values must correspond by position. If the first TENANT_ID is for Company A, then the first API_KEY, API_SECRET, DATABASES, and EXTERNAL_IDS must also be for Company A.
Email configuration is optional. If MAIL_TRANSPORT is not set, the mailing section is skipped entirely.
| Variable | Description | Example |
|---|---|---|
| MAIL_TRANSPORT | Transport type: smtp or gmail |
smtp |
For SMTP:
| Variable | Description | Example |
|---|---|---|
| eFrom | Sender email address | notificaciones@tuempresa.com |
| ePass | SMTP password (leave empty if not needed) | tu_password |
| eServer | SMTP server address | mail.tuempresa.com |
| ePuerto | SMTP port | 587 |
| eSSL | TRUE for SSL/TLS, FALSE otherwise | TRUE |
| MAILING_NOTICES | Comma-separated recipient emails | admin@tuempresa.com |
| MAILING_CC | Comma-separated CC emails | backup@tuempresa.com |
For Gmail OAuth:
| Variable | Description | Example |
|---|---|---|
| CLIENT_ID | Google API client ID | your-client-id.apps.googleusercontent.com |
| SECRET_CLIENT | Google API client secret | GOCSPX-your_client_secret |
| REFRESH_TOKEN | Google API refresh token | 1//your_refresh_token |
| REDIRECT_URI | OAuth redirect URI | https://developers.google.com/oauthplayground |
How to get Gmail OAuth credentials (CLIENT_ID, SECRET_CLIENT, REFRESH_TOKEN)
- Go to Google Cloud Console APIs
- Create a new project
- Enable the Gmail API
- Go to Consent screen → select External → create
- Fill in app name, assistance email, developer email
- Save and Continue until summary → Return to Panel
- Publish the application → Confirm
- Go to Credentials → Create Credentials → OAuth client ID
- Select Web app, add redirect URI:
https://developers.google.com/oauthplayground - Copy Client ID and Client Secret
- Go to Google OAuth Playground
- Click Settings → Use your own OAuth credentials → paste Client ID and Secret
- In Select & authorize APIs, type
https://mail.google.com→ Authorize APIs → Allow - Click Exchange authorization code for tokens → copy the Refresh token
| Variable | Description | Example |
|---|---|---|
| DOWNLOADS_PATH | Directory for downloaded CFDI files | ./downloads |
| PROVIDERS_PATH | Directory for provider data | ./downloads/providers |
| LOG_PATH | Base directory for log files (creates sageconnect/ subdirectory) |
./logs |
‼️ DOWNLOADS_PATHwas renamed fromPATHin v1.1 to avoid collision with the OS PATH environment variable.
| Variable | Description | Example |
|---|---|---|
| IMPORT_CFDIS_ROUTE | Path to Sage CFDI import executable | C:\Program Files (x86)\Importa CFDIs AP - Focaltec\ImportaFacturasFocaltec.exe |
| ARG | Sage 300 database name for the executable | YOUR_DATABASE_NAME |
| NOMBRE | Company name for CFDI fiscal information | Tu Empresa SA de CV |
| RFC | Company RFC (tax ID) | ABC123456DEF |
| REGIMEN | SAT tax regime code | 601 |
| TIMEZONE | IANA timezone identifier | America/Mexico_City |
| DEFAULT_ADDRESS_CITY | Default city for purchase orders | TU_CIUDAD |
| DEFAULT_ADDRESS_COUNTRY | Default country | MEXICO |
| DEFAULT_ADDRESS_IDENTIFIER | Default location identifier | ID_EXAMPLE |
| DEFAULT_ADDRESS_MUNICIPALITY | Default municipality | TU_MUNICIPIO |
| DEFAULT_ADDRESS_STATE | Default state | TU_ESTADO |
| DEFAULT_ADDRESS_STREET | Default street | CALLE EJEMPLO |
| DEFAULT_ADDRESS_ZIP | Default ZIP code | 12345 |
| ADDRESS_IDENTIFIERS_SKIP | Location IDs to exclude (comma-separated) | LOCATION1,LOCATION2 |
| AUTO_TERMINATE | Auto-exit after tasks complete (for scheduled tasks) | false |
‼️ AUTO_TERMINATE: Set totruefor Windows Server scheduled tasks (every 15 minutes). The app exits cleanly after processing. For normal operation with PM2, keepfalse.
The .env file is tracked in the repo. To prevent your local values from being overwritten on git pull or git merge, mark it as skip-worktree:
git update-index --skip-worktree .envIf you need to run SageConnect as a scheduled task on Windows Server (every 15 minutes), use the provided RunSageconnect.bat script instead of npm run start:
Configure your Windows Task Scheduler to run:
C:\path\to\sageconnect\RunSageconnect.batThis script automatically:
- Sets
AUTO_TERMINATE=trueenvironment variable - Changes to the correct directory (update the path in the script as needed)
- Runs the application with proper termination
- Logs execution times for monitoring
- Exits cleanly to prevent port conflicts
‼️ Important:
- Update the path
E:\sageconnectinRunSageconnect.batto match your installation directory- Do not use
npm run startdirectly for scheduled tasks as the process will never terminate and cause port conflicts with subsequent executions
After all the previous actions have been performed you will need to install some npm dependencies globally with the following commands:
npm install -g pm2
npm install pm2-windows-startup -g
npx pm2-startup installThen, you must execute the following commands in order to keep the program process always running
npx pm2 start src/index.js --watch --ignore-watch="node_modules" --name sageconnect
npx pm2 saveIf you need more information on the use of PM2 you can visit the following PM2 Quick Start Guide
The production code is obfuscated and pushed to a separate repository. The production repo has no shared git history with this source repo.
-
On your development machine:
git checkout master git pull origin master node scripts/obfuscate.js # Push obfuscated code to the production repository -
On the Windows production server:
REM Stop the app pm2 stop sageconnect REM Reset to latest (no shared history — always reset) git fetch origin git reset --hard origin/master REM Install dependencies npm install REM If migrating from v1.0 (5 separate .env files), run: node scripts/migrate-env.js REM Verify config loads correctly node -e "const c = require('./src/config'); console.log('OK:', c.database.server, c.portal.url)" REM Start the app pm2 start sageconnect
‼️ Important: The production repo contains obfuscated code with no shared git history. Each deployment usesgit reset --hard origin/masterto get the latest version. The.envfile is not affected by the reset.
If the server currently has the old 5 separate .env files, run the migration script before starting the app after updating to v1.1+:
node scripts/migrate-env.jsThe script will:
- Scan for old
.envfiles (.env,.env.path,.env.credentials.database,.env.credentials.focaltec,.env.credentials.mailing) - Read all variables from each file
- Apply renames:
USER→DB_USER,PASSWORD→DB_PASSWORD,PATH→DOWNLOADS_PATH - Add new variable:
MAIL_TRANSPORT=smtp - Show a full preview of the unified
.envfor review - On confirmation: write the unified
.env, back up originals to.env.legacy/, remove old separate files
‼️ Rollback: If something goes wrong after migration, the original files are in.env.legacy/. Copy them back to the root directory and revert the code to the previous version.