@microbt/environment 1.1.0 → 1.1.1
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/dist/esm/arms.js +66 -0
- package/dist/esm/cookie.js +20 -0
- package/dist/esm/hybrid.js +89 -0
- package/dist/esm/local.js +27 -0
- package/dist/esm/platform.js +14 -0
- package/package.json +1 -1
- package/.cursorrules +0 -91
package/dist/esm/arms.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// src/arms.ts
|
|
2
|
+
var api = (params) => {
|
|
3
|
+
if (window.__bl) {
|
|
4
|
+
window.__bl.api(params);
|
|
5
|
+
}
|
|
6
|
+
};
|
|
7
|
+
var error = (e, pos) => {
|
|
8
|
+
if (window.__bl) {
|
|
9
|
+
window.__bl.error(e, pos);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
var sum = (key, value) => {
|
|
13
|
+
if (window.__bl) {
|
|
14
|
+
window.__bl.sum(key, value);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var avg = (key, value) => {
|
|
18
|
+
if (window.__bl) {
|
|
19
|
+
window.__bl.avg(key, value);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
var reportBehavior = () => {
|
|
23
|
+
if (window.__bl) {
|
|
24
|
+
window.__bl.reportBehavior();
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var performance = (params) => {
|
|
28
|
+
if (window.__bl) {
|
|
29
|
+
window.__bl.performance(params);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
var setConfig = (params) => {
|
|
33
|
+
if (window.__bl) {
|
|
34
|
+
window.__bl.setConfig(params);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var setPage = (page, sendPv) => {
|
|
38
|
+
if (window.__bl) {
|
|
39
|
+
window.__bl.setPage(page, sendPv);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var setCommonInfo = (params) => {
|
|
43
|
+
if (window.__bl) {
|
|
44
|
+
window.__bl.setCommonInfo(params);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var addBehavior = (data, page) => {
|
|
48
|
+
if (window.__bl) {
|
|
49
|
+
window.__bl.addBehavior(data, page);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var arms = {
|
|
53
|
+
api,
|
|
54
|
+
error,
|
|
55
|
+
sum,
|
|
56
|
+
avg,
|
|
57
|
+
reportBehavior,
|
|
58
|
+
performance,
|
|
59
|
+
setConfig,
|
|
60
|
+
setPage,
|
|
61
|
+
setCommonInfo,
|
|
62
|
+
addBehavior
|
|
63
|
+
};
|
|
64
|
+
export {
|
|
65
|
+
arms
|
|
66
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// src/cookie.ts
|
|
2
|
+
var COOKIE_REGEX = (name) => new RegExp("(^| )" + name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + "=([^;]+)");
|
|
3
|
+
function getCookie(name) {
|
|
4
|
+
try {
|
|
5
|
+
const match = document.cookie.match(COOKIE_REGEX(name));
|
|
6
|
+
if (!match)
|
|
7
|
+
return null;
|
|
8
|
+
return decodeURIComponent(match[2]);
|
|
9
|
+
} catch (e) {
|
|
10
|
+
console.warn(`Error decoding cookie "${name}":`, e);
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function getRUID() {
|
|
15
|
+
return getCookie(`RUID_${location.hostname}`);
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
getCookie,
|
|
19
|
+
getRUID
|
|
20
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// src/hybrid.ts
|
|
2
|
+
import { iOSWebview } from "./platform";
|
|
3
|
+
var queue = [];
|
|
4
|
+
document.addEventListener("WebViewJavascriptBridgeReady", () => {
|
|
5
|
+
queue.forEach(({ method, params, callback }) => {
|
|
6
|
+
if (window.SuperAcme && typeof window.SuperAcme.call === "function") {
|
|
7
|
+
window.SuperAcme.call(method, params, callback);
|
|
8
|
+
}
|
|
9
|
+
});
|
|
10
|
+
queue.length = 0;
|
|
11
|
+
});
|
|
12
|
+
function bridgeCall(method, params, callback) {
|
|
13
|
+
var _a;
|
|
14
|
+
try {
|
|
15
|
+
if (((_a = window.SuperAcme) == null ? void 0 : _a.call) && typeof window.SuperAcme.call === "function") {
|
|
16
|
+
window.SuperAcme.call(method, params, callback);
|
|
17
|
+
} else {
|
|
18
|
+
queue.push({ method, params, callback });
|
|
19
|
+
}
|
|
20
|
+
} catch (error) {
|
|
21
|
+
console.error("Bridge call failed:", error);
|
|
22
|
+
const errorResponse = {
|
|
23
|
+
success: false,
|
|
24
|
+
error: {
|
|
25
|
+
code: "BRIDGE_CALL_ERROR",
|
|
26
|
+
message: error instanceof Error ? error.message : String(error),
|
|
27
|
+
method,
|
|
28
|
+
params,
|
|
29
|
+
stack: error instanceof Error ? error.stack : void 0,
|
|
30
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
callback(JSON.stringify(errorResponse));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function bridgeBootstrap() {
|
|
37
|
+
function bootstrap(callback) {
|
|
38
|
+
var _a, _b, _c;
|
|
39
|
+
if (window.SuperAcme && typeof window.SuperAcme.call === "function") {
|
|
40
|
+
return callback();
|
|
41
|
+
}
|
|
42
|
+
if (window.WKWVJBCallbacks) {
|
|
43
|
+
return window.WKWVJBCallbacks.push(callback);
|
|
44
|
+
}
|
|
45
|
+
window.WKWVJBCallbacks = [callback];
|
|
46
|
+
if (window.webkit) {
|
|
47
|
+
(_c = (_b = (_a = window.webkit.messageHandlers) == null ? void 0 : _a.iOS_Native_InjectJavascript) == null ? void 0 : _b.postMessage) == null ? void 0 : _c.call(_b, null);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (iOSWebview) {
|
|
51
|
+
bootstrap(() => {
|
|
52
|
+
const ready = new CustomEvent("WebViewJavascriptBridgeReady", {
|
|
53
|
+
detail: { platform: "ios" }
|
|
54
|
+
});
|
|
55
|
+
document.dispatchEvent(ready);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function inSuperAcme() {
|
|
60
|
+
return navigator.userAgent.toLowerCase().includes("superacme");
|
|
61
|
+
}
|
|
62
|
+
var VERSION_REGEX = /AppVersion\s([\d.]+)/;
|
|
63
|
+
function superAcmeVersion() {
|
|
64
|
+
const ua = navigator.userAgent;
|
|
65
|
+
const UNKNOWN = {
|
|
66
|
+
version: "unknown"
|
|
67
|
+
};
|
|
68
|
+
if (!inSuperAcme()) {
|
|
69
|
+
return UNKNOWN;
|
|
70
|
+
}
|
|
71
|
+
const versionMatch = ua.match(VERSION_REGEX);
|
|
72
|
+
if (versionMatch) {
|
|
73
|
+
const version = versionMatch[1];
|
|
74
|
+
const [major, minor, patch] = version.split(".").map(Number);
|
|
75
|
+
return {
|
|
76
|
+
version,
|
|
77
|
+
major,
|
|
78
|
+
minor,
|
|
79
|
+
patch
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return UNKNOWN;
|
|
83
|
+
}
|
|
84
|
+
export {
|
|
85
|
+
bridgeBootstrap,
|
|
86
|
+
bridgeCall,
|
|
87
|
+
inSuperAcme,
|
|
88
|
+
superAcmeVersion
|
|
89
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// src/local.ts
|
|
2
|
+
function getLocale(defaultLocal = "zh-CN") {
|
|
3
|
+
let lang = defaultLocal;
|
|
4
|
+
const { search } = window.location;
|
|
5
|
+
const { userAgent } = window.navigator;
|
|
6
|
+
if (userAgent.toLocaleLowerCase().indexOf("en-us") > -1) {
|
|
7
|
+
lang = "en-US";
|
|
8
|
+
}
|
|
9
|
+
if (search) {
|
|
10
|
+
const queryParams = {};
|
|
11
|
+
const searchString = search.substring(1);
|
|
12
|
+
const pairs = searchString.split("&");
|
|
13
|
+
for (let i = 0; i < pairs.length; i++) {
|
|
14
|
+
const pair = pairs[i].split("=");
|
|
15
|
+
const key = decodeURIComponent(pair[0]);
|
|
16
|
+
const value = decodeURIComponent(pair[1] || "");
|
|
17
|
+
queryParams[key] = value;
|
|
18
|
+
}
|
|
19
|
+
if (queryParams.locale) {
|
|
20
|
+
lang = queryParams.locale;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return lang;
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
getLocale
|
|
27
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/platform.ts
|
|
2
|
+
var getUserAgent = () => window.navigator.userAgent.toLowerCase();
|
|
3
|
+
var iOSWebview = (() => {
|
|
4
|
+
const ua = getUserAgent();
|
|
5
|
+
return ua.includes("ios") || ua.includes("iphone") || ua.includes("ipad") || ua.includes("ipod") || ua.includes("mac") && navigator.maxTouchPoints > 0;
|
|
6
|
+
})();
|
|
7
|
+
var androidWebView = (() => {
|
|
8
|
+
const ua = getUserAgent();
|
|
9
|
+
return ua.includes("android");
|
|
10
|
+
})();
|
|
11
|
+
export {
|
|
12
|
+
androidWebView,
|
|
13
|
+
iOSWebview
|
|
14
|
+
};
|
package/package.json
CHANGED
package/.cursorrules
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
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
|
-
```
|