sgerp-frontend-lib 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../sgerplib/sgerp/routing/index.ts"],"names":[],"mappings":"AAIA,UAAU,WAAW;IACnB,IAAI,EAAE,YAAY,CAAC;IACnB,WAAW,EAAE,MAAM,EAAE,EAAE,CAAC;CACzB;AAED,qBAAa,IAAI;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,WAAW,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;gBAEL,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;CASrF;AAED,qBAAa,GAAG;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,GAAG,EAAE,MAAM,EAAE,CAAC;IACd,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,WAAW,CAAC;gBAGnB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EAAE,EACf,GAAG,EAAE,MAAM,EAAE,EACb,KAAK,EAAE,IAAI,EAAE,EACb,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM;CAoBnB;AAED,wBAAgB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,GAAG,CAUpE;AAED,qBAAa,KAAK;IAChB,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,WAAW,CAAC;gBAET,IAAI,EAAE,GAAG,EAAE,EAAE,W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,CAAC;AAEV,qBAAa,aAAa;IACxB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,eAAe,GAAG,IAAI,CAAC;IACjC,cAAc,EAAE,OAAO,CAAC;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,EAAE,MAAM,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAGpC,mBAAmB,EAAE,MAAM,EAC3B,GAAG,EAAE,MAAM,EACX,YAAY,EAAE,MAAM,EACpB,GAAG,EAAE,MAAM,EACX,eAAe,GAAE,MAAsC,EACvD,QAAQ,GAAE,eAAe,GAAG,IAAW;IAoDzC,MAAM,IAAI,MAAM;IA+BV,KAAK,CACT,MAAM,EAAE,MAAM,EAAE,EAAE,EAClB,IAAI,EAAE,OAAO,EACb,QAAQ,EAAE,aAAa,EACvB,eAAe,GAAE,OAAe,GAC/B,OAAO,CAAC,IAAI,CAAC;IAqHhB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM;CAgBhE"}
@@ -7,6 +7,70 @@ exports.RoutingEngine = exports.Route = exports.Leg = exports.Step = void 0;
7
7
  exports.airLeg = airLeg;
8
8
  const polyline_1 = __importDefault(require("@mapbox/polyline"));
9
9
  const domains_1 = require("../domains");
10
+ /**
11
+ * Get OSRM proxy URL from environment variable mapping
12
+ * Expects NEXT_PUBLIC_OSRM_PROXY_URL_MAPPING env var with JSON format:
13
+ * {
14
+ * "vrptoolbox.d.gcdev.swatrider.com": "https://osrm-proxy-gcdev.swatrider.com",
15
+ * "vrptoolbox.d.gcprod.swatrider.com": "https://osrm-proxy-gcprod.swatrider.com",
16
+ * "vrptoolbox-ppe-tms-planning.lotuss.com": "https://osrm-proxy-ppe-tms-planning.lotuss.com",
17
+ * "vrptoolbox-tms-planning.lotuss.com": "https://osrm-proxy-tms-planning.lotuss.com"
18
+ * }
19
+ * @returns OSRM proxy URL or null if not found in mapping
20
+ */
21
+ function getOSRMProxyFromEnvMapping() {
22
+ if (typeof window === 'undefined')
23
+ return null;
24
+ const mappingJson = process.env.NEXT_PUBLIC_OSRM_PROXY_URL_MAPPING;
25
+ if (!mappingJson)
26
+ return null;
27
+ try {
28
+ const mapping = JSON.parse(mappingJson);
29
+ const hostname = window.location.hostname;
30
+ // Direct hostname match
31
+ if (mapping[hostname]) {
32
+ return mapping[hostname];
33
+ }
34
+ // Pattern matching - check if any key is contained in hostname
35
+ for (const [pattern, url] of Object.entries(mapping)) {
36
+ if (hostname.includes(pattern) || pattern.includes(hostname)) {
37
+ return url;
38
+ }
39
+ }
40
+ return null;
41
+ }
42
+ catch (error) {
43
+ console.error('Error parsing OSRM proxy URL mapping:', error);
44
+ return null;
45
+ }
46
+ }
47
+ /**
48
+ * Auto-detect backend from deployment URL
49
+ * Falls back to standard detection if env mapping is not available
50
+ */
51
+ function detectBackendFromDeployment() {
52
+ if (typeof window === 'undefined')
53
+ return 'production';
54
+ const hostname = window.location.hostname;
55
+ // Development/staging environments
56
+ if (hostname.includes('gcdev.swatrider.com') || hostname.includes('localhost')) {
57
+ return 'development';
58
+ }
59
+ // Production environment
60
+ if (hostname.includes('gcprod.swatrider.com')) {
61
+ return 'production';
62
+ }
63
+ // PPE environment (Lotus)
64
+ if (hostname.includes('ppe-tms-planning.lotuss.com')) {
65
+ return 'ppe';
66
+ }
67
+ // TCP environment (Lotus production)
68
+ if (hostname.includes('tms-planning.lotuss.com') && !hostname.includes('ppe')) {
69
+ return 'tcp';
70
+ }
71
+ // Default to production
72
+ return 'production';
73
+ }
10
74
  class Step {
11
75
  constructor(key, coordinates, duration, distance) {
12
76
  this.key = key;
@@ -211,7 +275,7 @@ const fetchData = async (url) => {
211
275
  }
212
276
  };
213
277
  class RoutingEngine {
214
- constructor(routing_engine_name, url, road_network, key, default_backend = 'production', settings = null) {
278
+ constructor(routing_engine_name, url, road_network, key, default_backend = detectBackendFromDeployment(), settings = null) {
215
279
  this.routing_engine_name = routing_engine_name;
216
280
  this.default_backend = default_backend;
217
281
  console.log(`default backend in routing engine ${default_backend}`);
@@ -252,7 +316,19 @@ class RoutingEngine {
252
316
  this.requestCache = {};
253
317
  }
254
318
  getUrl() {
319
+ // If URL is a full URL (starts with http:// or https://), use it as-is
320
+ // This respects URLs from payloads that specify their own routing endpoint
321
+ if (this.url.startsWith('http://') || this.url.startsWith('https://')) {
322
+ return this.url;
323
+ }
324
+ // Only apply env mapping or SGERP_DOMAINS for placeholder/relative URLs
255
325
  if (this.url === 'http://mapbox-osrm-proxy') {
326
+ // First, check if there's an env-based mapping
327
+ const envMappedUrl = getOSRMProxyFromEnvMapping();
328
+ if (envMappedUrl) {
329
+ return envMappedUrl;
330
+ }
331
+ // Fall back to SGERP_DOMAINS based on detected backend
256
332
  if (this.default_backend === 'production') {
257
333
  return domains_1.SGERP_DOMAINS.osrm.production;
258
334
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sgerp-frontend-lib",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "TypeScript/React library for interacting with the SGERP API, providing client SDK, Backbone.js-style Collections, and pre-built React components",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",