Azure API Bridge Method - No sqlsrv Needed on cPanel
====================================================

This version uses:
D365 F&O -> BYOD Azure SQL -> Azure Node.js API Bridge -> cPanel PHP cURL -> cPanel MySQL -> Portal

Why this method
---------------
Your cPanel does not need sqlsrv, pdo_sqlsrv, Composer, or Microsoft ODBC drivers.
It only needs PHP cURL and MySQLi, which most cPanel hosting already has.

Part 1 - Deploy Azure API bridge
--------------------------------
1. Open the folder:
   azure_api_bridge_nodejs

2. Deploy it to Azure App Service.
   Recommended App Service runtime:
   - Node 18 LTS or Node 20 LTS
   - Linux

3. In Azure App Service -> Configuration / Environment variables, 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 App Service.

5. Test:
   https://YOUR-APP-NAME.azurewebsites.net/health

   Header:
   x-api-key: UseALongRandomSecretKeyHere

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

   Header:
   x-api-key: UseALongRandomSecretKeyHere

Part 2 - Configure cPanel project
---------------------------------
1. Upload d365_private outside public_html:
   /home/YOUR_CPANEL_USERNAME/d365_private

2. Upload public_html/d365_portal into:
   /home/YOUR_CPANEL_USERNAME/public_html/d365_portal

3. Edit:
   /home/YOUR_CPANEL_USERNAME/d365_private/config.php

4. Update these values:

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

5. Import SQL file into cPanel phpMyAdmin:
   sql/Azure_D365_schema.sql

Part 3 - Run sync
-----------------
Full first sync:
https://YOURDOMAIN.com/d365_portal/api/sync_customers.php?mode=full

Later incremental sync:
https://YOURDOMAIN.com/d365_portal/api/sync_customers.php?mode=incremental

Cron job example every 2 hours:
0 */2 * * * /usr/local/bin/php /home/YOUR_CPANEL_USERNAME/public_html/d365_portal/api/sync_customers.php >/dev/null 2>&1

Portal pages
------------
Dashboard:
https://YOURDOMAIN.com/d365_portal/index.php

Customers:
https://YOURDOMAIN.com/d365_portal/customers.php

Sync status:
https://YOURDOMAIN.com/d365_portal/sync_status.php

Security checklist
------------------
- Change API_KEY before production.
- Change exposed passwords after testing.
- Do not keep phpinfo files on hosting.
- Do not expose d365_private inside public_html.
- Keep Azure App Service HTTPS only.
