Files
bodyshop/server/rr/rr-constants.js

78 lines
3.0 KiB
JavaScript

/**
* STAR-only constants for Reynolds & Reynolds (Rome/RCI)
* Used by rr-helpers.js to build and send SOAP requests.
*
* IMPORTANT:
* - Only rr-test.js should fall back to ENV for dealer/store/branch.
* - All runtime code (sockets/routes/jobs) must pass per-bodyshop
* values from the database (see rr-config.js#getRRConfigForBodyshop).
*/
exports.RR_NS = Object.freeze({
SOAP_ENV: "http://schemas.xmlsoap.org/soap/envelope/",
SOAP_ENC: "http://schemas.xmlsoap.org/soap/encoding/",
XSD: "http://www.w3.org/2001/XMLSchema",
XSI: "http://www.w3.org/2001/XMLSchema-instance",
WSSE: "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",
WSU: "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd",
STAR_TRANSPORT: "http://www.starstandards.org/webservices/2005/10/transport",
STAR_BUSINESS: "http://www.starstandards.org/STAR"
});
const RR_STAR_SOAP_ACTION = "http://www.starstandards.org/webservices/2005/10/transport/ProcessMessage";
exports.RR_SOAP_ACTION = RR_STAR_SOAP_ACTION;
const RR_SOAP_HEADERS = {
"Content-Type": "text/xml; charset=utf-8",
SOAPAction: RR_STAR_SOAP_ACTION
};
// Export if other modules need default STAR headers
exports.RR_SOAP_HEADERS = RR_SOAP_HEADERS;
// All STAR-supported actions (mapped to Mustache templates)
exports.RR_ACTIONS = Object.freeze({
CombinedSearch: { template: "CombinedSearch" },
GetAdvisors: { template: "GetAdvisors" },
GetParts: { template: "GetParts" },
InsertCustomer: { template: "InsertCustomer" },
InsertServiceVehicle: { template: "InsertServiceVehicle" },
CreateRepairOrder: { template: "CreateRepairOrder" },
UpdateCustomer: { template: "UpdateCustomer" },
UpdateRepairOrder: { template: "UpdateRepairOrder" }
});
/**
* Base config loader (environment-driven)
*
* ⚠️ Policy:
* - Only rr-test.js should rely on the ENV values for dealer/store/branch.
* - All other call sites must inject per-bodyshop values from DB.
*/
exports.getBaseRRConfig = function getBaseRRConfig() {
return {
baseUrl: process.env.RR_BASE_URL,
username: process.env.RR_USERNAME,
password: process.env.RR_PASSWORD,
ppsysId: process.env.RR_PPSYSID, // optional legacy identifier
// ❗ These are ONLY for rr-test.js fallback.
dealerNumber: process.env.RR_DEALER_NUMBER,
storeNumber: process.env.RR_STORE_NUMBER,
branchNumber: process.env.RR_BRANCH_NUMBER || "01",
wssePasswordType: process.env.RR_WSSE_PASSWORD_TYPE || "Text",
timeout: Number(process.env.RR_TIMEOUT_MS || 30000)
};
};
/**
* Normalize dealer/store/branch field names (camelCase vs snake_case).
* Safe to use in helpers to tolerate mixed callers during migration.
*/
exports.normalizeRRDealerFields = function normalizeRRDealerFields(cfg = {}) {
const dealerNumber = cfg.dealerNumber ?? cfg.dealer_number;
const storeNumber = cfg.storeNumber ?? cfg.store_number;
const branchNumber = cfg.branchNumber ?? cfg.branch_number;
return { dealerNumber, storeNumber, branchNumber };
};