@microbt/environment 1.2.9 → 1.2.11

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.
@@ -6,6 +6,7 @@
6
6
  "Bash(node:*)"
7
7
  ],
8
8
  "deny": [],
9
- "ask": []
9
+ "ask": [],
10
+ "defaultMode": "acceptEdits"
10
11
  }
11
12
  }
@@ -1,11 +1,4 @@
1
1
  export declare const SUPPORTED_DOMAINS: string[];
2
- /**
3
- * 验证域名是否在支持列表中
4
- * @param domain 要验证的域名
5
- * @returns 有效的域名
6
- * @throws 如果域名不在支持列表中
7
- */
8
- export declare function validateDomain(domain: string): string;
9
2
  export declare function environment(): string;
10
3
  export declare function region(): string;
11
4
  export declare function isAWSDomain(): boolean;
@@ -13,19 +13,16 @@ var SUPPORTED_DOMAINS = [
13
13
  "127.0.0.1",
14
14
  "localhost"
15
15
  ];
16
- function validateDomain(domain) {
17
- const validDomain = SUPPORTED_DOMAINS.find((d) => domain.endsWith(d));
18
- if (!validDomain) {
19
- throw new Error(`Unsupported domain: ${domain}`);
20
- }
21
- return validDomain;
22
- }
23
16
  function getCurrentDomain() {
24
17
  if (typeof location === "undefined") {
25
18
  throw new Error("location is not defined");
26
19
  }
27
20
  const host = location.host;
28
- return validateDomain(host);
21
+ const domain = SUPPORTED_DOMAINS.find((d) => host.endsWith(d));
22
+ if (!domain) {
23
+ throw new Error(`Unsupported domain: ${host}`);
24
+ }
25
+ return domain;
29
26
  }
30
27
  function environment() {
31
28
  try {
@@ -61,6 +58,5 @@ export {
61
58
  SUPPORTED_DOMAINS,
62
59
  environment,
63
60
  isAWSDomain,
64
- region,
65
- validateDomain
61
+ region
66
62
  };
@@ -1,10 +1,9 @@
1
1
  /**
2
- * 根据域名生成基于 name 和 path 的 baseUrl
2
+ * 根据当前域名生成基于 name 和 path 的 baseUrl
3
3
  *
4
4
  * @param params 配置参数
5
5
  * @param params.name - 必填,API 服务名称(例如:'api', 'iot-api')
6
6
  * @param params.path - 可选,API 路径(例如:'/saas')
7
- * @param params.domain - 可选,指定域名(必须符合SUPPORTED_DOMAINS约束)
8
7
  * @returns 生成的 URL。如果生成失败则返回传入的 path 值
9
8
  *
10
9
  * @example
@@ -12,7 +11,6 @@
12
11
  * // 中国区开发环境
13
12
  * baseUrl({ name: 'api' }) // => '//api-cn-dev.superacme.com'
14
13
  * baseUrl({ name: 'iot-api', path: '/saas' }) // => '//iot-api-cn-dev.superacme.com/saas'
15
- * baseUrl({ name: 'api', domain: 'superacme.com' }) // => '//api-cn-dev.superacme.com'
16
14
  *
17
15
  * // 美区 AWS 环境
18
16
  * // location.host: 'mall-us-aws.superacme.com'
@@ -21,7 +19,6 @@
21
19
  * // Safio365 域名系列
22
20
  * // location.host: 'iot-dev.safio365.com'
23
21
  * baseUrl({ name: 'iot-api', path: '/saas' }) // => '//iot-api-dev.safio365.com/saas'
24
- * baseUrl({ name: 'iot-api', domain: 'safio365.com' }) // => '//iot-api-dev.safio365.com/saas'
25
22
  *
26
23
  * // Sensforge 域名系列
27
24
  * // location.host: 'api-dev.sensforge.com'
@@ -33,5 +30,4 @@
33
30
  export declare function baseUrl(params: {
34
31
  name: string;
35
32
  path?: string;
36
- domain?: string;
37
33
  }): string | undefined;
@@ -1,16 +1,20 @@
1
1
  // src/gateway/index.ts
2
- import { environment, isAWSDomain, region, validateDomain } from "../environment/index";
2
+ import { environment, isAWSDomain, region, SUPPORTED_DOMAINS } from "../environment/index";
3
3
  import { URLStrategyFactory } from "./factory";
4
4
  function getCurrentDomain() {
5
5
  const host = location.host;
6
- return validateDomain(host);
6
+ const domain = SUPPORTED_DOMAINS.find((domain2) => host.endsWith(domain2));
7
+ if (!domain) {
8
+ throw new Error(`Unsupported domain: ${host}`);
9
+ }
10
+ return domain;
7
11
  }
8
12
  function baseUrl(params) {
9
13
  try {
10
14
  if (!params.name) {
11
15
  throw new Error("name parameter is required");
12
16
  }
13
- const domain = params.domain ? validateDomain(params.domain) : getCurrentDomain();
17
+ const domain = getCurrentDomain();
14
18
  const strategy = URLStrategyFactory.getStrategy(domain);
15
19
  const urlParams = {
16
20
  name: params.name,
@@ -46,7 +46,6 @@ declare global {
46
46
  region?: string;
47
47
  isAWS?: boolean;
48
48
  path?: string;
49
- domain?: string;
50
49
  };
51
50
 
52
51
  interface DomainFeatures {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microbt/environment",
3
- "version": "1.2.9",
3
+ "version": "1.2.11",
4
4
  "description": "microbt app library for environment",
5
5
  "keywords": [],
6
6
  "license": "MIT",