Azure D365 BYOD API Bridge - Node.js
====================================

Purpose
-------
This bridge connects to Azure SQL BYOD using Node.js and exposes JSON endpoints.
Your cPanel PHP portal then calls this bridge using cURL, so cPanel does NOT need sqlsrv or Composer.

Endpoints
---------
GET /health
GET /customers?mode=full&pageSize=2000&offset=0
GET /customers?mode=incremental&since=2026-06-09%2010:00:00&pageSize=2000&offset=0

Security
--------
Every request must include:
x-api-key: YOUR_API_KEY

Azure App Service setup
-----------------------
1. Create an Azure App Service.
   Runtime: Node 18 LTS or Node 20 LTS.
   OS: Linux is recommended.

2. Deploy this folder to Azure App Service.
   You can use VS Code, Azure Portal Deployment Center, ZIP deploy, or GitHub.

3. In Azure App Service -> Settings -> Environment variables / Configuration, add:

   API_KEY=UseALongRandomSecretKeyHere
   AZURE_SQL_SERVER=d365-php.database.windows.net
   AZURE_SQL_DATABASE=free-sql-db-1808495
   AZURE_SQL_USER=byodphp
   AZURE_SQL_PASSWORD=YourAzureSqlPassword
   AZURE_SQL_ENCRYPT=true
   AZURE_SQL_TRUST_CERT=false
   BYOD_CUSTOMER_TABLE=dbo.CustCustomerV3Staging
   MAX_PAGE_SIZE=5000

4. Restart the App Service.

5. Test in browser or Postman:
   https://YOUR-APP-NAME.azurewebsites.net/health

   Add header:
   x-api-key: UseALongRandomSecretKeyHere

6. Test customers:
   https://YOUR-APP-NAME.azurewebsites.net/customers?mode=full&pageSize=10&offset=0

7. Copy the app URL and API key into cPanel file:
   /home/YOUR_CPANEL_USERNAME/d365_private/config.php

   $bridgeApiBaseUrl = "https://YOUR-APP-NAME.azurewebsites.net";
   $bridgeApiKey = "UseALongRandomSecretKeyHere";

Notes
-----
- Do not expose your Azure SQL password in cPanel when using this bridge.
- Restrict Azure SQL firewall to Azure services where possible.
- Change the API key before production.
