@microbt/environment 1.2.12 → 1.2.13

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.
@@ -0,0 +1,5 @@
1
+ export declare const SUPPORTED_DOMAINS: string[];
2
+ export declare function getBusinessHost(): string;
3
+ export declare function getBusinessHostname(): string;
4
+ export declare function getBusinessOrigin(): string;
5
+ export declare function isOriginalHostInjected(): boolean;
@@ -0,0 +1,90 @@
1
+ // src/business-host.ts
2
+ var SUPPORTED_DOMAINS = [
3
+ "superacme.com",
4
+ "eu-cinmoore.com",
5
+ "cinmoore.com",
6
+ "cinmoore.cn",
7
+ "safio365.com",
8
+ "sensforge.com",
9
+ "fronai.cn",
10
+ "superacmeglobal.com",
11
+ "cinvue.com",
12
+ "0.0.0.0",
13
+ "127.0.0.1",
14
+ "localhost"
15
+ ];
16
+ var ORIGINAL_HOST_REGEX = /(?:^|[\s;(])originalHost\s*:\s*([^;\s)]+)/i;
17
+ var HOST_PATTERN = /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?::\d{1,5})?$/i;
18
+ function getLocationHost() {
19
+ if (typeof location === "undefined") {
20
+ throw new Error("location is not defined");
21
+ }
22
+ return location.host;
23
+ }
24
+ function getUserAgent() {
25
+ if (typeof navigator === "undefined") {
26
+ return "";
27
+ }
28
+ return navigator.userAgent || "";
29
+ }
30
+ function getHostnameFromHost(host) {
31
+ return host.replace(/:\d+$/, "");
32
+ }
33
+ function isSupportedDomain(hostname) {
34
+ const normalizedHostname = hostname.toLowerCase();
35
+ return SUPPORTED_DOMAINS.some(
36
+ (domain) => normalizedHostname === domain || normalizedHostname.endsWith(`.${domain}`)
37
+ );
38
+ }
39
+ function normalizeOriginalHost(rawHost) {
40
+ const host = rawHost == null ? void 0 : rawHost.trim().toLowerCase();
41
+ if (!host || !HOST_PATTERN.test(host)) {
42
+ return void 0;
43
+ }
44
+ const portMatch = host.match(/:(\d+)$/);
45
+ if (portMatch) {
46
+ const port = Number(portMatch[1]);
47
+ if (port < 1 || port > 65535) {
48
+ return void 0;
49
+ }
50
+ }
51
+ const hostname = getHostnameFromHost(host);
52
+ if (!isSupportedDomain(hostname)) {
53
+ return void 0;
54
+ }
55
+ return host;
56
+ }
57
+ function resolveOriginalHost() {
58
+ const match = getUserAgent().match(ORIGINAL_HOST_REGEX);
59
+ return normalizeOriginalHost(match == null ? void 0 : match[1]);
60
+ }
61
+ function getBusinessHost() {
62
+ var _a;
63
+ return (_a = resolveOriginalHost()) != null ? _a : getLocationHost();
64
+ }
65
+ function getBusinessHostname() {
66
+ return getHostnameFromHost(getBusinessHost());
67
+ }
68
+ function getBusinessOrigin() {
69
+ const originalHost = resolveOriginalHost();
70
+ if (originalHost) {
71
+ return `https://${originalHost}`;
72
+ }
73
+ if (typeof location === "undefined") {
74
+ throw new Error("location is not defined");
75
+ }
76
+ if (location.origin) {
77
+ return location.origin;
78
+ }
79
+ return `${location.protocol}//${location.host}`;
80
+ }
81
+ function isOriginalHostInjected() {
82
+ return Boolean(resolveOriginalHost());
83
+ }
84
+ export {
85
+ SUPPORTED_DOMAINS,
86
+ getBusinessHost,
87
+ getBusinessHostname,
88
+ getBusinessOrigin,
89
+ isOriginalHostInjected
90
+ };
@@ -1,4 +1,5 @@
1
1
  // src/cookie.ts
2
+ import { getBusinessHostname } from "./business-host";
2
3
  var COOKIE_REGEX = (name) => new RegExp("(^| )" + name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + "=([^;]*)");
3
4
  function getCookie(name) {
4
5
  try {
@@ -12,7 +13,7 @@ function getCookie(name) {
12
13
  }
13
14
  }
14
15
  function getRUID() {
15
- return getCookie(`RUID_${location.hostname}`);
16
+ return getCookie(`RUID_${getBusinessHostname()}`);
16
17
  }
17
18
  export {
18
19
  getCookie,
@@ -1,4 +1,5 @@
1
- export declare const SUPPORTED_DOMAINS: string[];
1
+ import { SUPPORTED_DOMAINS } from '../business-host';
2
+ export { SUPPORTED_DOMAINS };
2
3
  export declare function environment(): string;
3
4
  export declare function region(): string;
4
5
  export declare function isAWSDomain(): boolean;
@@ -1,25 +1,10 @@
1
1
  // src/environment/index.ts
2
+ import { getBusinessHost, SUPPORTED_DOMAINS } from "../business-host";
2
3
  import { EnvironmentStrategyFactory } from "./factory";
3
- var SUPPORTED_DOMAINS = [
4
- "superacme.com",
5
- "eu-cinmoore.com",
6
- "cinmoore.com",
7
- "cinmoore.cn",
8
- "safio365.com",
9
- "sensforge.com",
10
- "fronai.cn",
11
- "superacmeglobal.com",
12
- "cinvue.com",
13
- "0.0.0.0",
14
- "127.0.0.1",
15
- "localhost"
16
- ];
17
4
  function getCurrentDomain() {
18
- if (typeof location === "undefined") {
19
- throw new Error("location is not defined");
20
- }
21
- const host = location.host;
22
- const domain = SUPPORTED_DOMAINS.find((d) => host.endsWith(d));
5
+ const host = getBusinessHost();
6
+ const hostname = host.replace(/:\d+$/, "").toLowerCase();
7
+ const domain = SUPPORTED_DOMAINS.find((d) => hostname === d || hostname.endsWith(`.${d}`));
23
8
  if (!domain) {
24
9
  throw new Error(`Unsupported domain: ${host}`);
25
10
  }
@@ -27,9 +12,10 @@ function getCurrentDomain() {
27
12
  }
28
13
  function environment() {
29
14
  try {
15
+ const host = getBusinessHost();
30
16
  const domain = getCurrentDomain();
31
17
  const strategy = EnvironmentStrategyFactory.getStrategy(domain);
32
- return strategy.getEnvironment(location.host);
18
+ return strategy.getEnvironment(host);
33
19
  } catch (error) {
34
20
  console.warn("Failed to determine environment:", error);
35
21
  return "unknown";
@@ -37,9 +23,10 @@ function environment() {
37
23
  }
38
24
  function region() {
39
25
  try {
26
+ const host = getBusinessHost();
40
27
  const domain = getCurrentDomain();
41
28
  const strategy = EnvironmentStrategyFactory.getStrategy(domain);
42
- return strategy.getRegion(location.host);
29
+ return strategy.getRegion(host);
43
30
  } catch (error) {
44
31
  console.warn("Failed to determine region:", error);
45
32
  return "unknown";
@@ -47,9 +34,10 @@ function region() {
47
34
  }
48
35
  function isAWSDomain() {
49
36
  try {
37
+ const host = getBusinessHost();
50
38
  const domain = getCurrentDomain();
51
39
  const strategy = EnvironmentStrategyFactory.getStrategy(domain);
52
- return strategy.isAWS(location.host);
40
+ return strategy.isAWS(host);
53
41
  } catch (error) {
54
42
  console.warn("Failed to determine AWS domain:", error);
55
43
  return false;
@@ -1,9 +1,13 @@
1
1
  // src/gateway/index.ts
2
- import { environment, isAWSDomain, region, SUPPORTED_DOMAINS } from "../environment/index";
2
+ import { getBusinessHost, SUPPORTED_DOMAINS } from "../business-host";
3
+ import { environment, isAWSDomain, region } from "../environment/index";
3
4
  import { URLStrategyFactory } from "./factory";
4
5
  function getCurrentDomain() {
5
- const host = location.host;
6
- const domain = SUPPORTED_DOMAINS.find((domain2) => host.endsWith(domain2));
6
+ const host = getBusinessHost();
7
+ const hostname = host.replace(/:\d+$/, "").toLowerCase();
8
+ const domain = SUPPORTED_DOMAINS.find(
9
+ (domain2) => hostname === domain2 || hostname.endsWith(`.${domain2}`)
10
+ );
7
11
  if (!domain) {
8
12
  throw new Error(`Unsupported domain: ${host}`);
9
13
  }
@@ -1,4 +1,5 @@
1
1
  export * from './arms';
2
+ export * from './business-host';
2
3
  export * from './cookie';
3
4
  export * from './environment/index';
4
5
  export * from './gateway/index';
package/dist/esm/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // src/index.ts
2
2
  export * from "./arms";
3
+ export * from "./business-host";
3
4
  export * from "./cookie";
4
5
  export * from "./environment/index";
5
6
  export * from "./gateway/index";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microbt/environment",
3
- "version": "1.2.12",
3
+ "version": "1.2.13",
4
4
  "description": "microbt app library for environment",
5
5
  "keywords": [],
6
6
  "license": "MIT",