@microbt/environment 1.0.2 → 1.1.0
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.
- package/.cursorrules +91 -0
- package/README.md +127 -11
- package/dist/esm/arms.d.ts +39 -0
- package/dist/esm/cookie.d.ts +2 -0
- package/dist/esm/environment/factory.d.ts +5 -0
- package/dist/esm/environment/factory.js +31 -0
- package/dist/esm/environment/index.d.ts +4 -0
- package/dist/esm/environment/index.js +59 -0
- package/dist/esm/environment/strategies/cinmoore.d.ts +7 -0
- package/dist/esm/environment/strategies/cinmoore.js +42 -0
- package/dist/esm/environment/strategies/local.d.ts +7 -0
- package/dist/esm/environment/strategies/local.js +23 -0
- package/dist/esm/environment/strategies/safio365.d.ts +7 -0
- package/dist/esm/environment/strategies/safio365.js +42 -0
- package/dist/esm/environment/strategies/sensforge.d.ts +7 -0
- package/dist/esm/environment/strategies/sensforge.js +42 -0
- package/dist/esm/environment/strategies/superacme.d.ts +8 -0
- package/dist/esm/environment/strategies/superacme.js +45 -0
- package/dist/esm/gateway/factory.d.ts +4 -0
- package/dist/esm/gateway/factory.js +25 -0
- package/dist/esm/gateway/index.d.ts +33 -0
- package/dist/esm/gateway/index.js +44 -0
- package/dist/esm/gateway/strategies/index.d.ts +3 -0
- package/dist/esm/gateway/strategies/index.js +4 -0
- package/dist/esm/gateway/strategies/safio365.d.ts +4 -0
- package/dist/esm/gateway/strategies/safio365.js +19 -0
- package/dist/esm/gateway/strategies/sensforge.d.ts +4 -0
- package/dist/esm/gateway/strategies/sensforge.js +19 -0
- package/dist/esm/gateway/strategies/superacme.d.ts +4 -0
- package/dist/esm/gateway/strategies/superacme.js +27 -0
- package/dist/esm/global.d.ts +58 -0
- package/dist/esm/index.d.ts +4 -2
- package/dist/esm/index.js +8 -0
- package/package.json +6 -4
- package/dist/esm/environment.d.ts +0 -15
- package/dist/esm/gateway.d.ts +0 -1
- package/dist/umd/environment.min.js +0 -1
package/.cursorrules
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
You are an expert in Typescript, React, Immer, Zustand, UmiJS, Ant Design Mobile, and React Query, with experience in H5 in-app hybrid development, and have a deep understanding of cloud solutions including Alibaba Cloud and AWS.
|
|
2
|
+
|
|
3
|
+
# Response Structure
|
|
4
|
+
|
|
5
|
+
- First analyze requirements thoroughly
|
|
6
|
+
- Provide step-by-step planning before implementation
|
|
7
|
+
- Include file paths in code block metadata
|
|
8
|
+
- Format code blocks with appropriate language tags
|
|
9
|
+
- Break down complex changes into manageable steps
|
|
10
|
+
- Provide context for changes
|
|
11
|
+
- Explain trade-offs in solutions
|
|
12
|
+
- Include examples where helpful
|
|
13
|
+
- Reference relevant documentation
|
|
14
|
+
- Suggest testing strategies
|
|
15
|
+
|
|
16
|
+
# Communication Style
|
|
17
|
+
|
|
18
|
+
- No apologies
|
|
19
|
+
- No understanding feedback
|
|
20
|
+
- No whitespace suggestions
|
|
21
|
+
- No summaries
|
|
22
|
+
- No inventions beyond explicit requests
|
|
23
|
+
|
|
24
|
+
# Core Principles
|
|
25
|
+
|
|
26
|
+
- Code Quality Standards
|
|
27
|
+
- Write clean, maintainable code
|
|
28
|
+
- Follow language/framework best practices
|
|
29
|
+
- Use appropriate design patterns
|
|
30
|
+
- Implement proper error handling
|
|
31
|
+
- Design Philosophy
|
|
32
|
+
- Favor composition over inheritance
|
|
33
|
+
- Keep components small and focused
|
|
34
|
+
- Follow SOLID principles
|
|
35
|
+
- Maintain separation of concerns
|
|
36
|
+
- Architecture Patterns
|
|
37
|
+
- Define clear project structure
|
|
38
|
+
- Use appropriate architectural patterns
|
|
39
|
+
- Plan for scalability
|
|
40
|
+
- Consider modularity
|
|
41
|
+
- Best Practices
|
|
42
|
+
- Write tests for critical functionality
|
|
43
|
+
- Document complex logic
|
|
44
|
+
- Optimize performance where needed
|
|
45
|
+
- Follow security best practices
|
|
46
|
+
|
|
47
|
+
# Development Workflow
|
|
48
|
+
|
|
49
|
+
- Testing Requirements
|
|
50
|
+
- Define test coverage requirements
|
|
51
|
+
- Specify test frameworks
|
|
52
|
+
- Document test organization
|
|
53
|
+
- List required test types
|
|
54
|
+
- Error Handling
|
|
55
|
+
- Define error handling patterns
|
|
56
|
+
- Specify logging requirements
|
|
57
|
+
- Document error recovery
|
|
58
|
+
- List error categories
|
|
59
|
+
- Performance Optimization
|
|
60
|
+
- Define performance targets
|
|
61
|
+
- Specify optimization techniques
|
|
62
|
+
- Document monitoring requirements
|
|
63
|
+
- List performance metrics
|
|
64
|
+
- Security Practices
|
|
65
|
+
- Define security requirements
|
|
66
|
+
- Specify authentication methods
|
|
67
|
+
- Document data protection
|
|
68
|
+
- List security checks
|
|
69
|
+
|
|
70
|
+
# Error Prevention & Recovery
|
|
71
|
+
|
|
72
|
+
- Code Review Focus Points
|
|
73
|
+
- Check for common pitfalls
|
|
74
|
+
- Validate type safety
|
|
75
|
+
- Verify error handling
|
|
76
|
+
- Review security implications
|
|
77
|
+
- Refactoring Guidelines
|
|
78
|
+
- When to suggest refactoring
|
|
79
|
+
- How to approach large changes
|
|
80
|
+
- Breaking changes management
|
|
81
|
+
- Migration strategies
|
|
82
|
+
- Recovery Procedures
|
|
83
|
+
|
|
84
|
+
- How to handle failed changes
|
|
85
|
+
- Rollback strategies
|
|
86
|
+
- Alternative solutions
|
|
87
|
+
- Debugging approaches - Example: ``` try { await deployChanges(); } catch (error) { // 1. Log the error logger.error('Deployment failed', { error }); // 2. Attempt rollback await rollbackToLastStable(); // 3. Notify monitoring await alertDevOps('Deployment failed and rolled back'); // 4. Provide recovery guidance throw new DeploymentError('Deployment failed, see logs for details'); }
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
```
|
package/README.md
CHANGED
|
@@ -60,17 +60,28 @@ console.log(regionCode); // 输出: 'cn'
|
|
|
60
60
|
|
|
61
61
|
## 网关相关函数
|
|
62
62
|
|
|
63
|
-
### `baseUrl()`
|
|
63
|
+
### `baseUrl(params: { name: string; path?: string })`
|
|
64
64
|
|
|
65
|
-
|
|
65
|
+
根据当前域名生成对应的 API URL。
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
**参数**:
|
|
68
|
+
|
|
69
|
+
- `params.name`: `string` - **必填**,API 服务名称(如 'api'、'iot-api')
|
|
70
|
+
- `params.path`: `string` - **可选**,API 路径(如 '/saas')
|
|
71
|
+
|
|
72
|
+
**返回值**: `string` - 生成的 URL。如果生成失败则返回传入的 path 值
|
|
68
73
|
|
|
69
74
|
**示例**:
|
|
70
75
|
|
|
71
76
|
```typescript
|
|
72
|
-
|
|
73
|
-
|
|
77
|
+
// 中国区开发环境
|
|
78
|
+
// location.host: 'mall-cn-dev.superacme.com'
|
|
79
|
+
baseUrl({ name: 'api' }); // => '//api-cn-dev.superacme.com'
|
|
80
|
+
baseUrl({ name: 'iot-api', path: '/saas' }); // => '//iot-api-cn-dev.superacme.com/saas'
|
|
81
|
+
|
|
82
|
+
// 美区 AWS 生产环境
|
|
83
|
+
// location.host: 'mall-us-aws.superacme.com'
|
|
84
|
+
baseUrl({ name: 'api' }); // => '//api-us-aws.superacme.com'
|
|
74
85
|
```
|
|
75
86
|
|
|
76
87
|
## 混合应用相关函数
|
|
@@ -94,12 +105,12 @@ console.log(resp);
|
|
|
94
105
|
|
|
95
106
|
### `bridgeBootstrap()`
|
|
96
107
|
|
|
97
|
-
|
|
108
|
+
初始化桥接环境。
|
|
98
109
|
|
|
99
110
|
**示例**:
|
|
100
111
|
|
|
101
112
|
```typescript
|
|
102
|
-
bridgeBootstrap();
|
|
113
|
+
bridgeBootstrap();
|
|
103
114
|
```
|
|
104
115
|
|
|
105
116
|
### `inSuperAcme()`
|
|
@@ -117,15 +128,36 @@ console.log(isInApp); // 输出: true 或 false
|
|
|
117
128
|
|
|
118
129
|
### `superAcmeVersion()`
|
|
119
130
|
|
|
120
|
-
获取 SuperAcme
|
|
131
|
+
获取 SuperAcme 应用的版本信息。
|
|
132
|
+
|
|
133
|
+
**返回值**: 返回一个包含版本信息的对象:
|
|
134
|
+
|
|
135
|
+
- 如果在 SuperAcme 应用中且能够解析版本号:
|
|
121
136
|
|
|
122
|
-
|
|
137
|
+
```json
|
|
138
|
+
{
|
|
139
|
+
version: string; // 完整版本号,如 "1.2.3"
|
|
140
|
+
major: number; // 主版本号
|
|
141
|
+
minor: number; // 次版本号
|
|
142
|
+
patch: number; // 修订号
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
- 如果不在 SuperAcme 应用中或无法解析版本号:
|
|
147
|
+
|
|
148
|
+
```json
|
|
149
|
+
{
|
|
150
|
+
version: 'unknown';
|
|
151
|
+
}
|
|
152
|
+
```
|
|
123
153
|
|
|
124
154
|
**示例**:
|
|
125
155
|
|
|
126
156
|
```typescript
|
|
127
|
-
const
|
|
128
|
-
console.log(
|
|
157
|
+
const versionInfo = superAcmeVersion();
|
|
158
|
+
console.log(versionInfo);
|
|
159
|
+
// 在 SuperAcme 应用中可能输出:{ version: "1.2.3", major: 1, minor: 2, patch: 3 }
|
|
160
|
+
// 在非 SuperAcme 应用中输出:{ version: "unknown" }
|
|
129
161
|
```
|
|
130
162
|
|
|
131
163
|
## 平台相关函数
|
|
@@ -176,3 +208,87 @@ if (androidWebView) {
|
|
|
176
208
|
const locale = getLocale();
|
|
177
209
|
console.log(locale); // 输出: 'zh-CN' 或 'en-US'
|
|
178
210
|
```
|
|
211
|
+
|
|
212
|
+
## Cookie 相关函数
|
|
213
|
+
|
|
214
|
+
### `getCookie(name: string)`
|
|
215
|
+
|
|
216
|
+
获取指定名称的 Cookie 值。
|
|
217
|
+
|
|
218
|
+
**参数**:
|
|
219
|
+
|
|
220
|
+
- `name`: `string` - 要获取的 Cookie 名称
|
|
221
|
+
|
|
222
|
+
**返回值**: `string | null` - 返回指定名称的 Cookie 值,如果不存在或解析失败则返回 `null`
|
|
223
|
+
|
|
224
|
+
**功能描述**:
|
|
225
|
+
|
|
226
|
+
- 使用正则表达式匹配指定名称的 Cookie 值。
|
|
227
|
+
- 如果匹配成功,返回解码后的 Cookie 值。
|
|
228
|
+
- 如果匹配失败或解码过程中发生错误,返回 `null`。
|
|
229
|
+
|
|
230
|
+
**示例**:
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
const userToken = getCookie('token');
|
|
234
|
+
if (userToken) {
|
|
235
|
+
console.log(`User token: ${userToken}`);
|
|
236
|
+
} else {
|
|
237
|
+
console.log('Token not found or invalid');
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
**注意事项**:
|
|
242
|
+
|
|
243
|
+
- 函数会对 Cookie 值进行解码,如果解码失败会捕获错误并返回 `null`。
|
|
244
|
+
- 确保传入的 `name` 参数是合法的 Cookie 名称。
|
|
245
|
+
|
|
246
|
+
### `getRUID()`
|
|
247
|
+
|
|
248
|
+
获取当前域名下的 `RUID` 值。
|
|
249
|
+
|
|
250
|
+
**返回值**: `string | null` - 返回当前域名下的 `RUID` 值,如果不存在或解析失败则返回 `null`
|
|
251
|
+
|
|
252
|
+
**功能描述**:
|
|
253
|
+
|
|
254
|
+
- 基于当前域名(`location.hostname`)动态生成 `RUID` 的 Cookie 名称。
|
|
255
|
+
- 调用 `getCookie` 函数获取对应的 Cookie 值。
|
|
256
|
+
|
|
257
|
+
**示例**:
|
|
258
|
+
|
|
259
|
+
```typescript
|
|
260
|
+
const ruid = getRUID();
|
|
261
|
+
if (ruid) {
|
|
262
|
+
console.log(`RUID: ${ruid}`);
|
|
263
|
+
} else {
|
|
264
|
+
console.log('RUID not found or invalid');
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
**注意事项**:
|
|
269
|
+
|
|
270
|
+
- 确保 `RUID` 的 Cookie 名称格式为 `RUID_<当前域名>`。
|
|
271
|
+
- 函数依赖 `getCookie`,因此会继承其解码逻辑和错误处理机制。
|
|
272
|
+
|
|
273
|
+
## ARMS 模块
|
|
274
|
+
|
|
275
|
+
`arms` 模块封装了阿里云 ARMS(应用实时监控服务)的前端监控功能,提供了一系列 API 用于上报性能数据、错误信息、用户行为等。
|
|
276
|
+
|
|
277
|
+
### 可用 API
|
|
278
|
+
|
|
279
|
+
以下是 `arms` 模块中提供的 API 列表:
|
|
280
|
+
|
|
281
|
+
- **`api(params)`**: 上报 API 请求数据。
|
|
282
|
+
- **`error(e, pos)`**: 上报错误信息。
|
|
283
|
+
- **`sum(key, value)`**: 上报累加指标。
|
|
284
|
+
- **`avg(key, value)`**: 上报平均值指标。
|
|
285
|
+
- **`reportBehavior()`**: 上报用户行为数据。
|
|
286
|
+
- **`performance(params)`**: 上报性能数据。
|
|
287
|
+
- **`setConfig(params)`**: 设置 ARMS 配置。
|
|
288
|
+
- **`setPage(page, sendPv)`**: 设置当前页面信息,并可选择是否发送页面访问数据(PV)。
|
|
289
|
+
- **`setCommonInfo(params)`**: 设置通用信息。
|
|
290
|
+
- **`addBehavior(data, page)`**: 添加用户行为数据。
|
|
291
|
+
|
|
292
|
+
### 参考链接
|
|
293
|
+
|
|
294
|
+
- [阿里云 ARMS 文档 - API 参考](https://help.aliyun.com/zh/arms/browser-monitoring/developer-reference/api-reference)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
declare const api: (params: {
|
|
2
|
+
api: string;
|
|
3
|
+
success: boolean;
|
|
4
|
+
time: number;
|
|
5
|
+
code?: string | number;
|
|
6
|
+
msg?: string;
|
|
7
|
+
begin?: number;
|
|
8
|
+
traceId?: string;
|
|
9
|
+
sid?: string;
|
|
10
|
+
}) => void;
|
|
11
|
+
export declare const arms: {
|
|
12
|
+
api: (params: {
|
|
13
|
+
api: string;
|
|
14
|
+
success: boolean;
|
|
15
|
+
time: number;
|
|
16
|
+
code?: string | number;
|
|
17
|
+
msg?: string;
|
|
18
|
+
begin?: number;
|
|
19
|
+
traceId?: string;
|
|
20
|
+
sid?: string;
|
|
21
|
+
}) => void;
|
|
22
|
+
error: (e: Error, pos: {
|
|
23
|
+
filename: string;
|
|
24
|
+
lineno: number;
|
|
25
|
+
colno: number;
|
|
26
|
+
}) => void;
|
|
27
|
+
sum: (key: string, value: number) => void;
|
|
28
|
+
avg: (key: string, value: number) => void;
|
|
29
|
+
reportBehavior: () => void;
|
|
30
|
+
performance: (params: unknown) => void;
|
|
31
|
+
setConfig: (params: unknown) => void;
|
|
32
|
+
setPage: (page: string, sendPv: boolean) => void;
|
|
33
|
+
setCommonInfo: (params: unknown) => void;
|
|
34
|
+
addBehavior: (data: {
|
|
35
|
+
name: string;
|
|
36
|
+
message: string;
|
|
37
|
+
}, page: string) => void;
|
|
38
|
+
};
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// src/environment/factory.ts
|
|
2
|
+
import { CinmooreEnvironmentStrategy } from "./strategies/cinmoore";
|
|
3
|
+
import { LocalEnvironmentStrategy } from "./strategies/local";
|
|
4
|
+
import { Safio365EnvironmentStrategy } from "./strategies/safio365";
|
|
5
|
+
import { SensforgeEnvironmentStrategy } from "./strategies/sensforge";
|
|
6
|
+
import { SuperAcmeEnvironmentStrategy } from "./strategies/superacme";
|
|
7
|
+
var _EnvironmentStrategyFactory = class {
|
|
8
|
+
static getStrategy(domain) {
|
|
9
|
+
if (this.localStrategy.getEnvironment(domain) === "local") {
|
|
10
|
+
return this.localStrategy;
|
|
11
|
+
}
|
|
12
|
+
const strategy = this.strategies.get(domain);
|
|
13
|
+
if (!strategy) {
|
|
14
|
+
throw new Error(`Unsupported domain: ${domain}`);
|
|
15
|
+
}
|
|
16
|
+
return strategy;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
var EnvironmentStrategyFactory = _EnvironmentStrategyFactory;
|
|
20
|
+
EnvironmentStrategyFactory.strategies = /* @__PURE__ */ new Map();
|
|
21
|
+
EnvironmentStrategyFactory.localStrategy = new LocalEnvironmentStrategy();
|
|
22
|
+
(() => {
|
|
23
|
+
_EnvironmentStrategyFactory.strategies.set("superacme.com", new SuperAcmeEnvironmentStrategy());
|
|
24
|
+
_EnvironmentStrategyFactory.strategies.set("safio365.com", new Safio365EnvironmentStrategy());
|
|
25
|
+
_EnvironmentStrategyFactory.strategies.set("sensforge.com", new SensforgeEnvironmentStrategy());
|
|
26
|
+
_EnvironmentStrategyFactory.strategies.set("cinmoore.com", new CinmooreEnvironmentStrategy());
|
|
27
|
+
_EnvironmentStrategyFactory.strategies.set("cinmoore.cn", new CinmooreEnvironmentStrategy());
|
|
28
|
+
})();
|
|
29
|
+
export {
|
|
30
|
+
EnvironmentStrategyFactory
|
|
31
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// src/environment/index.ts
|
|
2
|
+
import { EnvironmentStrategyFactory } from "./factory";
|
|
3
|
+
var SUPPORTED_DOMAINS = [
|
|
4
|
+
"superacme.com",
|
|
5
|
+
"cinmoore.com",
|
|
6
|
+
"cinmoore.cn",
|
|
7
|
+
"safio365.com",
|
|
8
|
+
"sensforge.com",
|
|
9
|
+
"0.0.0.0",
|
|
10
|
+
"127.0.0.1",
|
|
11
|
+
"localhost"
|
|
12
|
+
];
|
|
13
|
+
function getCurrentDomain() {
|
|
14
|
+
if (typeof location === "undefined") {
|
|
15
|
+
throw new Error("location is not defined");
|
|
16
|
+
}
|
|
17
|
+
const host = location.host;
|
|
18
|
+
const domain = SUPPORTED_DOMAINS.find((d) => host.endsWith(d));
|
|
19
|
+
if (!domain) {
|
|
20
|
+
throw new Error(`Unsupported domain: ${host}`);
|
|
21
|
+
}
|
|
22
|
+
return domain;
|
|
23
|
+
}
|
|
24
|
+
function environment() {
|
|
25
|
+
try {
|
|
26
|
+
const domain = getCurrentDomain();
|
|
27
|
+
const strategy = EnvironmentStrategyFactory.getStrategy(domain);
|
|
28
|
+
return strategy.getEnvironment(location.host);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
console.warn("Failed to determine environment:", error);
|
|
31
|
+
return "unknown";
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function region() {
|
|
35
|
+
try {
|
|
36
|
+
const domain = getCurrentDomain();
|
|
37
|
+
const strategy = EnvironmentStrategyFactory.getStrategy(domain);
|
|
38
|
+
return strategy.getRegion(location.host);
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.warn("Failed to determine region:", error);
|
|
41
|
+
return "unknown";
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function isAWSDomain() {
|
|
45
|
+
try {
|
|
46
|
+
const domain = getCurrentDomain();
|
|
47
|
+
const strategy = EnvironmentStrategyFactory.getStrategy(domain);
|
|
48
|
+
return strategy.isAWS(location.host);
|
|
49
|
+
} catch (error) {
|
|
50
|
+
console.warn("Failed to determine AWS domain:", error);
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export {
|
|
55
|
+
SUPPORTED_DOMAINS,
|
|
56
|
+
environment,
|
|
57
|
+
isAWSDomain,
|
|
58
|
+
region
|
|
59
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// src/environment/strategies/cinmoore.ts
|
|
2
|
+
var CinmooreEnvironmentStrategy = class {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.features = {
|
|
5
|
+
supportEnv: true,
|
|
6
|
+
supportRegion: false,
|
|
7
|
+
supportAWS: false
|
|
8
|
+
};
|
|
9
|
+
this.ENV_PATTERNS = {
|
|
10
|
+
// 匹配 -dev、-dev1、-dev-1、-dev. 等
|
|
11
|
+
dev: /-dev(?:\d*)?(?:-|\.|\b|$)/,
|
|
12
|
+
// 匹配 -test、-test1、-test-1、-test. 等
|
|
13
|
+
test: /-test(?:\d*)?(?:-|\.|\b|$)/,
|
|
14
|
+
// 匹配 -pre、-pre1、-pre-1、-pre. 等
|
|
15
|
+
pre: /-pre(?:\d*)?(?:-|\.|\b|$)/,
|
|
16
|
+
// 匹配 -gray、-gray1、-gray-1、-gray. 等
|
|
17
|
+
gray: /-gray(?:\d*)?(?:-|\.|\b|$)/,
|
|
18
|
+
// 本地环境
|
|
19
|
+
local: /^(localhost|127\.0\.0\.1|0\.0\.0\.0)(?::\d+)?$/
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
getEnvironment(host) {
|
|
23
|
+
if (this.ENV_PATTERNS.local.test(host)) {
|
|
24
|
+
return "local";
|
|
25
|
+
}
|
|
26
|
+
for (const [env, pattern] of Object.entries(this.ENV_PATTERNS)) {
|
|
27
|
+
if (pattern.test(host)) {
|
|
28
|
+
return env;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return "prod";
|
|
32
|
+
}
|
|
33
|
+
getRegion() {
|
|
34
|
+
return "unknown";
|
|
35
|
+
}
|
|
36
|
+
isAWS() {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
export {
|
|
41
|
+
CinmooreEnvironmentStrategy
|
|
42
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// src/environment/strategies/local.ts
|
|
2
|
+
var LocalEnvironmentStrategy = class {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.features = {
|
|
5
|
+
supportEnv: true,
|
|
6
|
+
supportRegion: false,
|
|
7
|
+
supportAWS: false
|
|
8
|
+
};
|
|
9
|
+
this.LOCAL_PATTERN = /^(localhost|127\.0\.0\.1|0\.0\.0\.0)(?::\d+)?$/;
|
|
10
|
+
}
|
|
11
|
+
getEnvironment(host) {
|
|
12
|
+
return this.LOCAL_PATTERN.test(host) ? "local" : "unknown";
|
|
13
|
+
}
|
|
14
|
+
getRegion() {
|
|
15
|
+
return "unknown";
|
|
16
|
+
}
|
|
17
|
+
isAWS() {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
export {
|
|
22
|
+
LocalEnvironmentStrategy
|
|
23
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// src/environment/strategies/safio365.ts
|
|
2
|
+
var Safio365EnvironmentStrategy = class {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.features = {
|
|
5
|
+
supportEnv: true,
|
|
6
|
+
supportRegion: false,
|
|
7
|
+
supportAWS: false
|
|
8
|
+
};
|
|
9
|
+
this.ENV_PATTERNS = {
|
|
10
|
+
// 匹配 -dev、-dev1、-dev-1、-dev. 等
|
|
11
|
+
dev: /-dev(?:\d*)?(?:-|\.|\b|$)/,
|
|
12
|
+
// 匹配 -test、-test1、-test-1、-test. 等
|
|
13
|
+
test: /-test(?:\d*)?(?:-|\.|\b|$)/,
|
|
14
|
+
// 匹配 -pre、-pre1、-pre-1、-pre. 等
|
|
15
|
+
pre: /-pre(?:\d*)?(?:-|\.|\b|$)/,
|
|
16
|
+
// 匹配 -gray、-gray1、-gray-1、-gray. 等
|
|
17
|
+
gray: /-gray(?:\d*)?(?:-|\.|\b|$)/,
|
|
18
|
+
// 本地环境
|
|
19
|
+
local: /^(localhost|127\.0\.0\.1|0\.0\.0\.0)(?::\d+)?$/
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
getEnvironment(host) {
|
|
23
|
+
if (this.ENV_PATTERNS.local.test(host)) {
|
|
24
|
+
return "local";
|
|
25
|
+
}
|
|
26
|
+
for (const [env, pattern] of Object.entries(this.ENV_PATTERNS)) {
|
|
27
|
+
if (pattern.test(host)) {
|
|
28
|
+
return env;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return "prod";
|
|
32
|
+
}
|
|
33
|
+
getRegion() {
|
|
34
|
+
return "unknown";
|
|
35
|
+
}
|
|
36
|
+
isAWS() {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
export {
|
|
41
|
+
Safio365EnvironmentStrategy
|
|
42
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// src/environment/strategies/sensforge.ts
|
|
2
|
+
var SensforgeEnvironmentStrategy = class {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.features = {
|
|
5
|
+
supportEnv: true,
|
|
6
|
+
supportRegion: false,
|
|
7
|
+
supportAWS: false
|
|
8
|
+
};
|
|
9
|
+
this.ENV_PATTERNS = {
|
|
10
|
+
// 匹配 -dev、-dev1、-dev-1、-dev. 等
|
|
11
|
+
dev: /-dev(?:\d*)?(?:-|\.|\b|$)/,
|
|
12
|
+
// 匹配 -test、-test1、-test-1、-test. 等
|
|
13
|
+
test: /-test(?:\d*)?(?:-|\.|\b|$)/,
|
|
14
|
+
// 匹配 -pre、-pre1、-pre-1、-pre. 等
|
|
15
|
+
pre: /-pre(?:\d*)?(?:-|\.|\b|$)/,
|
|
16
|
+
// 匹配 -gray、-gray1、-gray-1、-gray. 等
|
|
17
|
+
gray: /-gray(?:\d*)?(?:-|\.|\b|$)/,
|
|
18
|
+
// 本地环境
|
|
19
|
+
local: /^(localhost|127\.0\.0\.1|0\.0\.0\.0)(?::\d+)?$/
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
getEnvironment(host) {
|
|
23
|
+
if (this.ENV_PATTERNS.local.test(host)) {
|
|
24
|
+
return "local";
|
|
25
|
+
}
|
|
26
|
+
for (const [env, pattern] of Object.entries(this.ENV_PATTERNS)) {
|
|
27
|
+
if (pattern.test(host)) {
|
|
28
|
+
return env;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return "prod";
|
|
32
|
+
}
|
|
33
|
+
getRegion() {
|
|
34
|
+
return "unknown";
|
|
35
|
+
}
|
|
36
|
+
isAWS() {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
export {
|
|
41
|
+
SensforgeEnvironmentStrategy
|
|
42
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare class SuperAcmeEnvironmentStrategy implements EnvironmentStrategy {
|
|
2
|
+
features: EnvironmentFeatures;
|
|
3
|
+
private readonly ENV_PATTERNS;
|
|
4
|
+
private readonly REGION_PATTERN;
|
|
5
|
+
getEnvironment(host: string): string;
|
|
6
|
+
getRegion(host: string): string;
|
|
7
|
+
isAWS(host: string): boolean;
|
|
8
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// src/environment/strategies/superacme.ts
|
|
2
|
+
var SuperAcmeEnvironmentStrategy = class {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.features = {
|
|
5
|
+
supportEnv: true,
|
|
6
|
+
supportRegion: true,
|
|
7
|
+
supportAWS: true
|
|
8
|
+
};
|
|
9
|
+
this.ENV_PATTERNS = {
|
|
10
|
+
// 匹配 -dev、-dev1、-dev-1、-dev.、-dev-aws 等
|
|
11
|
+
dev: /-dev(?:\d*)?(?:-|\.|\b|$)/,
|
|
12
|
+
// 匹配 -test、-test1、-test-1、-test.、-test-aws 等
|
|
13
|
+
test: /-test(?:\d*)?(?:-|\.|\b|$)/,
|
|
14
|
+
// 匹配 -pre、-pre1、-pre-1、-pre.、-pre-aws 等
|
|
15
|
+
pre: /-pre(?:\d*)?(?:-|\.|\b|$)/,
|
|
16
|
+
// 匹配 -gray、-gray1、-gray-1、-gray.、-gray-aws 等
|
|
17
|
+
gray: /-gray(?:\d*)?(?:-|\.|\b|$)/,
|
|
18
|
+
// 本地环境保持不变
|
|
19
|
+
local: /^(localhost|127\.0\.0\.1|0\.0\.0\.0)(?::\d+)?$/
|
|
20
|
+
};
|
|
21
|
+
this.REGION_PATTERN = new RegExp("-(?<region>cn|us|usa|jpn|deu|gbr|fra|can|sgp|aus|kor|ind|bra|rus|zaf|mex|idn|tur|sau|che|twn|hkg|mac)(?=-|\\.|\\d|$)");
|
|
22
|
+
}
|
|
23
|
+
getEnvironment(host) {
|
|
24
|
+
if (this.ENV_PATTERNS.local.test(host)) {
|
|
25
|
+
return "local";
|
|
26
|
+
}
|
|
27
|
+
for (const [env, pattern] of Object.entries(this.ENV_PATTERNS)) {
|
|
28
|
+
if (pattern.test(host)) {
|
|
29
|
+
return env;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return "prod";
|
|
33
|
+
}
|
|
34
|
+
getRegion(host) {
|
|
35
|
+
var _a;
|
|
36
|
+
const match = host.match(this.REGION_PATTERN);
|
|
37
|
+
return ((_a = match == null ? void 0 : match.groups) == null ? void 0 : _a.region) || "unknown";
|
|
38
|
+
}
|
|
39
|
+
isAWS(host) {
|
|
40
|
+
return host.includes("-aws");
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
export {
|
|
44
|
+
SuperAcmeEnvironmentStrategy
|
|
45
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// src/gateway/factory.ts
|
|
2
|
+
import {
|
|
3
|
+
Safio365URLStrategy,
|
|
4
|
+
SensforgeURLStrategy,
|
|
5
|
+
SuperAcmeURLStrategy
|
|
6
|
+
} from "./strategies/index";
|
|
7
|
+
var _URLStrategyFactory = class {
|
|
8
|
+
static getStrategy(domain) {
|
|
9
|
+
const strategy = this.strategies.get(domain);
|
|
10
|
+
if (!strategy) {
|
|
11
|
+
throw new Error(`Unsupported domain: ${domain}`);
|
|
12
|
+
}
|
|
13
|
+
return strategy;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
var URLStrategyFactory = _URLStrategyFactory;
|
|
17
|
+
URLStrategyFactory.strategies = /* @__PURE__ */ new Map();
|
|
18
|
+
(() => {
|
|
19
|
+
_URLStrategyFactory.strategies.set("superacme.com", new SuperAcmeURLStrategy());
|
|
20
|
+
_URLStrategyFactory.strategies.set("sensforge.com", new SensforgeURLStrategy());
|
|
21
|
+
_URLStrategyFactory.strategies.set("safio365.com", new Safio365URLStrategy());
|
|
22
|
+
})();
|
|
23
|
+
export {
|
|
24
|
+
URLStrategyFactory
|
|
25
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 根据当前域名生成基于 name 和 path 的 baseUrl
|
|
3
|
+
*
|
|
4
|
+
* @param params 配置参数
|
|
5
|
+
* @param params.name - 必填,API 服务名称(例如:'api', 'iot-api')
|
|
6
|
+
* @param params.path - 可选,API 路径(例如:'/saas')
|
|
7
|
+
* @returns 生成的 URL。如果生成失败则返回传入的 path 值
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* // SuperAcme 域名系列
|
|
11
|
+
* // 中国区开发环境
|
|
12
|
+
* baseUrl({ name: 'api' }) // => '//api-cn-dev.superacme.com'
|
|
13
|
+
* baseUrl({ name: 'iot-api', path: '/saas' }) // => '//iot-api-cn-dev.superacme.com/saas'
|
|
14
|
+
*
|
|
15
|
+
* // 美区 AWS 环境
|
|
16
|
+
* // location.host: 'mall-us-aws.superacme.com'
|
|
17
|
+
* baseUrl({ name: 'api' }) // => '//api-us-aws.superacme.com'
|
|
18
|
+
*
|
|
19
|
+
* // Safio365 域名系列
|
|
20
|
+
* // location.host: 'iot-dev.safio365.com'
|
|
21
|
+
* baseUrl({ name: 'iot-api', path: '/saas' }) // => '//iot-api-dev.safio365.com/saas'
|
|
22
|
+
*
|
|
23
|
+
* // Sensforge 域名系列
|
|
24
|
+
* // location.host: 'api-dev.sensforge.com'
|
|
25
|
+
* baseUrl({ name: 'iot-api' }) // => '//iot-api-dev.sensforge.com'
|
|
26
|
+
*
|
|
27
|
+
* @throws 如果 name 参数为空,将抛出错误并返回 path
|
|
28
|
+
* @throws 如果域名不在支持列表中,将返回 path
|
|
29
|
+
*/
|
|
30
|
+
export declare function baseUrl(params: {
|
|
31
|
+
name: string;
|
|
32
|
+
path?: string;
|
|
33
|
+
}): string | undefined;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// src/gateway/index.ts
|
|
2
|
+
import { environment, isAWSDomain, region, SUPPORTED_DOMAINS } from "../environment/index";
|
|
3
|
+
import { URLStrategyFactory } from "./factory";
|
|
4
|
+
function getCurrentDomain() {
|
|
5
|
+
const host = location.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;
|
|
11
|
+
}
|
|
12
|
+
function baseUrl(params) {
|
|
13
|
+
try {
|
|
14
|
+
if (!params.name) {
|
|
15
|
+
throw new Error("name parameter is required");
|
|
16
|
+
}
|
|
17
|
+
const domain = getCurrentDomain();
|
|
18
|
+
const strategy = URLStrategyFactory.getStrategy(domain);
|
|
19
|
+
const urlParams = {
|
|
20
|
+
name: params.name,
|
|
21
|
+
path: params.path || ""
|
|
22
|
+
};
|
|
23
|
+
if (strategy.features.supportEnv) {
|
|
24
|
+
const env = environment();
|
|
25
|
+
if (env === "unknown") {
|
|
26
|
+
return params.path;
|
|
27
|
+
}
|
|
28
|
+
urlParams.env = env;
|
|
29
|
+
}
|
|
30
|
+
if (strategy.features.supportRegion) {
|
|
31
|
+
urlParams.region = region();
|
|
32
|
+
}
|
|
33
|
+
if (strategy.features.supportAWS) {
|
|
34
|
+
urlParams.isAWS = isAWSDomain();
|
|
35
|
+
}
|
|
36
|
+
return strategy.generateURL(urlParams);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
console.warn("Failed to generate base URL:", error);
|
|
39
|
+
return params.path;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export {
|
|
43
|
+
baseUrl
|
|
44
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// src/gateway/strategies/safio365.ts
|
|
2
|
+
var Safio365URLStrategy = class {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.features = {
|
|
5
|
+
supportEnv: true,
|
|
6
|
+
supportRegion: false,
|
|
7
|
+
supportAWS: false
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
generateURL({ name, env = "prod", path = "" }) {
|
|
11
|
+
if (env === "prod" || !env) {
|
|
12
|
+
return `//${name}.safio365.com${path}`;
|
|
13
|
+
}
|
|
14
|
+
return `//${name}-${env}.safio365.com${path}`;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
export {
|
|
18
|
+
Safio365URLStrategy
|
|
19
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// src/gateway/strategies/sensforge.ts
|
|
2
|
+
var SensforgeURLStrategy = class {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.features = {
|
|
5
|
+
supportEnv: true,
|
|
6
|
+
supportRegion: false,
|
|
7
|
+
supportAWS: false
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
generateURL({ name, env = "prod", path = "" }) {
|
|
11
|
+
if (env === "prod" || !env) {
|
|
12
|
+
return `//${name}.sensforge.com${path}`;
|
|
13
|
+
}
|
|
14
|
+
return `//${name}-${env}.sensforge.com${path}`;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
export {
|
|
18
|
+
SensforgeURLStrategy
|
|
19
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// src/gateway/strategies/superacme.ts
|
|
2
|
+
var SuperAcmeURLStrategy = class {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.features = {
|
|
5
|
+
supportEnv: true,
|
|
6
|
+
supportRegion: true,
|
|
7
|
+
supportAWS: true
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
generateURL({
|
|
11
|
+
name,
|
|
12
|
+
env = "prod",
|
|
13
|
+
region = "",
|
|
14
|
+
isAWS = false,
|
|
15
|
+
path = ""
|
|
16
|
+
}) {
|
|
17
|
+
const regionPart = region ? `-${region}` : "";
|
|
18
|
+
const awsPart = isAWS ? "-aws" : "";
|
|
19
|
+
if (env === "prod" || !env) {
|
|
20
|
+
return `//${name}${regionPart}${awsPart}.superacme.com${path}`;
|
|
21
|
+
}
|
|
22
|
+
return `//${name}${regionPart}-${env}${awsPart}.superacme.com${path}`;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
export {
|
|
26
|
+
SuperAcmeURLStrategy
|
|
27
|
+
};
|
package/dist/esm/global.d.ts
CHANGED
|
@@ -17,6 +17,64 @@ declare global {
|
|
|
17
17
|
};
|
|
18
18
|
};
|
|
19
19
|
};
|
|
20
|
+
__bl?: {
|
|
21
|
+
api(params: {
|
|
22
|
+
api: string;
|
|
23
|
+
success: boolean;
|
|
24
|
+
time: number;
|
|
25
|
+
code?: string | number;
|
|
26
|
+
msg?: string;
|
|
27
|
+
begin?: number;
|
|
28
|
+
traceId?: string;
|
|
29
|
+
sid?: string;
|
|
30
|
+
}): void;
|
|
31
|
+
error(e: Error, pos: { filename: string; lineno: number; colno: number }): void;
|
|
32
|
+
sum(key: string, value: number): void;
|
|
33
|
+
avg(key: string, value: number): void;
|
|
34
|
+
reportBehavior(): void;
|
|
35
|
+
performance(params: unknown): void;
|
|
36
|
+
setConfig(params: unknown): void;
|
|
37
|
+
setPage(page: string, sendPv: boolean): void;
|
|
38
|
+
setCommonInfo(params: unknown): void;
|
|
39
|
+
addBehavior(data: { name: string; message: string }, page: string): void;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
type URLStrategyConfig = {
|
|
44
|
+
name: string;
|
|
45
|
+
env?: string;
|
|
46
|
+
region?: string;
|
|
47
|
+
isAWS?: boolean;
|
|
48
|
+
path?: string;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
interface DomainFeatures {
|
|
52
|
+
supportEnv: boolean;
|
|
53
|
+
supportRegion: boolean;
|
|
54
|
+
supportAWS: boolean;
|
|
55
|
+
}
|
|
56
|
+
interface URLStrategy {
|
|
57
|
+
features: DomainFeatures;
|
|
58
|
+
generateURL(params: URLStrategyConfig): string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
interface EnvironmentFeatures {
|
|
62
|
+
supportEnv: boolean; // 是否支持环境判断
|
|
63
|
+
supportRegion: boolean; // 是否支持区域判断
|
|
64
|
+
supportAWS: boolean; // 是否支持 AWS 判断
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
interface EnvironmentStrategy {
|
|
68
|
+
features: EnvironmentFeatures;
|
|
69
|
+
getEnvironment(host: string): string;
|
|
70
|
+
getRegion(host: string): string;
|
|
71
|
+
isAWS(host: string): boolean;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
interface EnvironmentConfig {
|
|
75
|
+
env?: string;
|
|
76
|
+
region?: string;
|
|
77
|
+
isAWS?: boolean;
|
|
20
78
|
}
|
|
21
79
|
}
|
|
22
80
|
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
1
|
+
export * from './arms';
|
|
2
|
+
export * from './cookie';
|
|
3
|
+
export * from './environment/index';
|
|
4
|
+
export * from './gateway/index';
|
|
3
5
|
export * from './hybrid';
|
|
4
6
|
export * from './local';
|
|
5
7
|
export * from './platform';
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@microbt/environment",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "microbt app library for environment",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"main": "dist/
|
|
7
|
+
"main": "dist/esm/index.js",
|
|
8
8
|
"types": "dist/esm/index.d.ts",
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "father build",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"format": "prettier --cache --write .",
|
|
14
14
|
"lint": "eslint . --fix ",
|
|
15
15
|
"prepare": "husky install",
|
|
16
|
-
"prepublishOnly": "father doctor && npm run
|
|
16
|
+
"prepublishOnly": "father doctor && npm run build",
|
|
17
17
|
"postpublish": "cnpm sync @microbt/environment",
|
|
18
18
|
"test": "jest"
|
|
19
19
|
},
|
|
@@ -30,7 +30,9 @@
|
|
|
30
30
|
"prettier --cache --parser=typescript --write"
|
|
31
31
|
]
|
|
32
32
|
},
|
|
33
|
-
"dependencies": {
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"alife-logger": "^1.8.30"
|
|
35
|
+
},
|
|
34
36
|
"devDependencies": {
|
|
35
37
|
"@commitlint/cli": "^17.4.4",
|
|
36
38
|
"@commitlint/config-conventional": "^17.4.4",
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 获取当前运行的环境
|
|
3
|
-
* @returns {string} 环境名称(local, dev, test, pre, gray, prod, unknown)
|
|
4
|
-
*/
|
|
5
|
-
export declare const environment: () => string;
|
|
6
|
-
/**
|
|
7
|
-
* 获取当前运行的区域
|
|
8
|
-
* @returns {string} 区域名称(如 cn, us 等)
|
|
9
|
-
*/
|
|
10
|
-
export declare const region: () => string;
|
|
11
|
-
/**
|
|
12
|
-
* 判断当前域名是否为 AWS 域名
|
|
13
|
-
* @returns {boolean} 是否为 AWS 域名
|
|
14
|
-
*/
|
|
15
|
-
export declare function isAWSDomain(): boolean;
|
package/dist/esm/gateway.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function baseUrl(): string | undefined;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var r=t();for(var o in r)("object"==typeof exports?exports:e)[o]=r[o]}}(self,(function(){return function(){var e={803:function(e){e.exports=function(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,o=new Array(t);r<t;r++)o[r]=e[r];return o},e.exports.__esModule=!0,e.exports.default=e.exports},473:function(e){e.exports=function(e){if(Array.isArray(e))return e},e.exports.__esModule=!0,e.exports.default=e.exports},502:function(e,t,r){var o=r(582);e.exports=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&o(e,t)},e.exports.__esModule=!0,e.exports.default=e.exports},941:function(e){e.exports=function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var o,n,u,i,a=[],c=!0,s=!1;try{if(u=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;c=!1}else for(;!(c=(o=u.call(r)).done)&&(a.push(o.value),a.length!==t);c=!0);}catch(e){s=!0,n=e}finally{try{if(!c&&null!=r.return&&(i=r.return(),Object(i)!==i))return}finally{if(s)throw n}}return a}},e.exports.__esModule=!0,e.exports.default=e.exports},551:function(e){e.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},e.exports.__esModule=!0,e.exports.default=e.exports},582:function(e){function t(r,o){return e.exports=t=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},e.exports.__esModule=!0,e.exports.default=e.exports,t(r,o)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports},216:function(e,t,r){var o=r(473),n=r(941),u=r(317),i=r(551);e.exports=function(e,t){return o(e)||n(e,t)||u(e,t)||i()},e.exports.__esModule=!0,e.exports.default=e.exports},71:function(e){function t(r){return e.exports=t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e.exports.__esModule=!0,e.exports.default=e.exports,t(r)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports},317:function(e,t,r){var o=r(803);e.exports=function(e,t){if(e){if("string"==typeof e)return o(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?o(e,t):void 0}},e.exports.__esModule=!0,e.exports.default=e.exports},583:function(e,t,r){var o=r(71).default,n=r(582),u=r(502);function i(){e.exports=i=function(e,t){return new a(e,void 0,t)},e.exports.__esModule=!0,e.exports.default=e.exports;var t=RegExp.prototype,r=new WeakMap;function a(e,t,o){var u=new RegExp(e,t);return r.set(u,o||r.get(e)),n(u,a.prototype)}function c(e,t){var o=r.get(t);return Object.keys(o).reduce((function(t,r){var n=o[r];if("number"==typeof n)t[r]=e[n];else{for(var u=0;void 0===e[n[u]]&&u+1<n.length;)u++;t[r]=e[n[u]]}return t}),Object.create(null))}return u(a,RegExp),a.prototype.exec=function(e){var r=t.exec.call(this,e);if(r){r.groups=c(r,this);var o=r.indices;o&&(o.groups=c(o,this))}return r},a.prototype[Symbol.replace]=function(e,n){if("string"==typeof n){var u=r.get(this);return t[Symbol.replace].call(this,e,n.replace(/\$<([^>]+)>/g,(function(e,t){var r=u[t];return"$"+(Array.isArray(r)?r.join("$"):r)})))}if("function"==typeof n){var i=this;return t[Symbol.replace].call(this,e,(function(){var e=arguments;return"object"!=o(e[e.length-1])&&(e=[].slice.call(e)).push(c(e,i)),n.apply(this,e)}))}return t[Symbol.replace].call(this,e,n)},i.apply(this,arguments)}e.exports=i,e.exports.__esModule=!0,e.exports.default=e.exports}},t={};function r(o){var n=t[o];if(void 0!==n)return n.exports;var u=t[o]={exports:{}};return e[o](u,u.exports,r),u.exports}r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return function(){"use strict";r.r(o),r.d(o,{androidWebView:function(){return x},baseUrl:function(){return f},bridgeBootstrap:function(){return g},bridgeCall:function(){return b},environment:function(){return s},getLocale:function(){return S},iOSWebview:function(){return y},inSuperAcme:function(){return h},isAWSDomain:function(){return l},region:function(){return p},superAcmeVersion:function(){return _}});var e=r(583),t=r.n(e)()(/(dev|test|pre|gray)/,{env:1}),n=["us","usa","cn","chn","jp","jpn","de","deu","uk","gbr","fr","fra","ca","can","sg","sgp","au","aus","kr","kor","in","ind","br","bra","ru","rus","za","zaf","mx","mex","id","idn","tr","tur","sa","sau","ch","che","tw","twn","hk","hkg","mo","mac"],u=new RegExp("-(?<region>".concat(n.join("|"),")(-|$|\\.)")),i=/-aws\./,a=/^(localhost|127\.0\.0\.1|0\.0\.0\.0)(:\d+)?$/,c=new RegExp("^(?:[a-z0-9-]+\\.)*(?:".concat(["superacme.com","cinmoore.com","cinmoore.cn","safio365.com","sensforge.com"].join("|"),")$")),s=function(){var e=location.host;if(a.test(e))return"local";if(!c.test(e))return"unknown";var r=e.match(t);return r&&r.groups&&r.groups.env?r.groups.env:"prod"},p=function(){var e=location.host;if(!c.test(e))return"unknown";var t=e.match(new RegExp("-(".concat(n.join("|"),")-(dev|test|pre|gray)(?=-|\\.|$)")));if(t)return t[1];var r=e.match(u);return r&&r.groups&&r.groups.region?r.groups.region:"unknown"};function l(){var e=location.host;return!!c.test(e)&&i.test(e)}function f(){var e=s(),t=p();return"dev"===e||"test"===e||"pre"===e?"//api-".concat(t,"-").concat(e).concat(l()?"-aws":"",".superacme.com").concat(""):"prod"===e?"//api-".concat(t).concat(l()?"-aws":"",".superacme.com").concat(""):void 0}var d,v=r(216),m=r.n(v),y=(d=window.navigator.userAgent.toLocaleLowerCase()).includes("ios")||d.includes("iphone")||d.includes("ipad"),x=window.navigator.userAgent.toLocaleLowerCase().includes("android"),w=[];function b(e,t,r){window.SuperAcme&&"function"==typeof window.SuperAcme.call?window.SuperAcme.call(e,t,r):w.push({method:e,params:t,callback:r})}function g(){y&&function(e){if(window.SuperAcme&&"function"==typeof window.SuperAcme.call)return e();if(window.WKWVJBCallbacks)return window.WKWVJBCallbacks.push(e);var t,r;window.WKWVJBCallbacks=[e],window.webkit&&(null===(t=window.webkit.messageHandlers)||void 0===t||null===(t=t.iOS_Native_InjectJavascript)||void 0===t||null===(r=t.postMessage)||void 0===r||r.call(t,null))}((function(){var e=new CustomEvent("WebViewJavascriptBridgeReady",{detail:{platform:"ios"}});document.dispatchEvent(e)}))}function h(){return navigator.userAgent.toLowerCase().includes("superacme")}function _(){var e=navigator.userAgent,t={version:"unknown"};if(!h())return t;var r=e.match(/AppVersion\s([\d.]+)/);if(r){var o=r[1],n=o.split(".").map(Number),u=m()(n,3);return{version:o,major:u[0],minor:u[1],patch:u[2]}}return t}function S(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"zh-CN",t=e,r=window.location.search,o=window.navigator.userAgent;if(o.toLocaleLowerCase().indexOf("en-us")>-1&&(t="en-US"),r){for(var n={},u=r.substring(1),i=u.split("&"),a=0;a<i.length;a++){var c=i[a].split("="),s=decodeURIComponent(c[0]),p=decodeURIComponent(c[1]||"");n[s]=p}n.locale&&(t=n.locale)}return t}document.addEventListener("WebViewJavascriptBridgeReady",(function(){w.forEach((function(e){var t=e.method,r=e.params,o=e.callback;window.SuperAcme&&"function"==typeof window.SuperAcme.call&&window.SuperAcme.call(t,r,o)})),w.length=0}))}(),o}()}));
|