@mearl/app-profiles 0.0.0-stage → 3.0.0-beta.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/LICENSE +201 -0
- package/README.md +14 -2
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/metadata.d.ts +2 -0
- package/dist/metadata.js +3 -0
- package/dist/profiles.d.ts +41 -0
- package/dist/profiles.js +358 -0
- package/dist/settings.d.ts +9 -0
- package/dist/settings.js +50 -0
- package/dist/updates.d.ts +16 -0
- package/dist/updates.js +102 -0
- package/package.json +40 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @mearl/app-profiles
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
内置飞猪、淘宝、微信、支付宝的基础 UA/版本档案。四份档案保留当前 UA 格式和版本替换,不内置桥对象、App 设置、scheme 路由、业务响应和完整容器实现。
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { resolveAppProfile } from '@mearl/app-profiles';
|
|
7
|
+
const profile = resolveAppProfile('taobao', { os: 'android', appVersion: '10.65.0' });
|
|
8
|
+
console.log(profile.ua);
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
宿主可以向 resolveAppProfile 或 resolveAppProfileDefinition 提供已校验的动态定义;编译器保留桥、设置及 pageRuntime 描述,不执行能力代码。定义与选项被复制并绑定 revision,插件升级不直接改写活动文档。
|
|
12
|
+
|
|
13
|
+
resolveAppProfileUpdate、rebuildAppProfileConfig 和 updateAppProfileSetting 保持显式选项、设备外观及方法覆盖的优先级。preset 默认值由宿主传入,用户已有选择继续优先;能力包安装成功不等于默认配置已经应用。
|
|
14
|
+
|
|
15
|
+
完整 App 行为由能力包声明并安装到受控页面;真实设备授权仍由相应宿主能力执行。本包与基础运行时的迁入没有切换当前产品的实现来源,完整产品验收进度见 [迁移说明](../../docs/migration.md)。
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/metadata.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type AppProfileCatalogEntry, type AppProfileDefinition, type AppProfileOptions, type BuiltinAppProfileName, type AppBridgeConfig, type AppProfileName, type BridgeActionMap, type BrowserDevicePresetName, type InjectedAppProfileConfig } from '@mearl/browser-core';
|
|
2
|
+
export type { AppProfileName };
|
|
3
|
+
export type AppProfileOs = 'ios' | 'android';
|
|
4
|
+
export type AppProfile = AppProfileDefinition;
|
|
5
|
+
/** 校验并复制用户提供的声明式桥配置。 */
|
|
6
|
+
export declare function validateAppBridgeConfig(value: unknown): AppBridgeConfig;
|
|
7
|
+
/** 后传配置按方法覆盖前传配置,供扩展本地配置与单次 Agent 参数组合。 */
|
|
8
|
+
export declare function mergeAppBridgeConfigs(...configs: Array<AppBridgeConfig | undefined>): AppBridgeConfig | undefined;
|
|
9
|
+
/** 将声明式方法覆盖编译进运行时动作表,不修改档案的静态数据。 */
|
|
10
|
+
export declare function applyAppBridgeConfig(actions: BridgeActionMap, config?: AppBridgeConfig): BridgeActionMap;
|
|
11
|
+
export declare const APP_PROFILES: Record<BuiltinAppProfileName, AppProfile>;
|
|
12
|
+
export interface ResolveAppProfileOptions extends AppProfileOptions {
|
|
13
|
+
os?: AppProfileOs;
|
|
14
|
+
appVersion?: string;
|
|
15
|
+
language?: string;
|
|
16
|
+
/** App 读取到的机型名;不影响所选设备的物理外观。 */
|
|
17
|
+
deviceModel?: string;
|
|
18
|
+
/** App 系统栏与安全区使用的设备 preset,默认跟随 os 的推荐设备。 */
|
|
19
|
+
devicePreset?: BrowserDevicePresetName;
|
|
20
|
+
orientation?: 'portrait' | 'landscape';
|
|
21
|
+
/** 按方法覆盖档案内置桥配置 */
|
|
22
|
+
bridgeConfig?: AppBridgeConfig;
|
|
23
|
+
}
|
|
24
|
+
/** resolve 结果:UA + 注入配置 + 推荐设备模拟 preset */
|
|
25
|
+
export interface ResolvedAppProfile {
|
|
26
|
+
profile: AppProfileName;
|
|
27
|
+
label: string;
|
|
28
|
+
ua: string;
|
|
29
|
+
injected: InjectedAppProfileConfig;
|
|
30
|
+
/** 推荐配合的视口 preset(browser-core DEVICE_PRESETS 键名) */
|
|
31
|
+
recommendedPreset: BrowserDevicePresetName;
|
|
32
|
+
}
|
|
33
|
+
/** 构造容器 UA。os 默认 ios;uaTokens 中的 {v} 替换为 appVersion */
|
|
34
|
+
export declare function buildAppProfileUa(profile: AppProfile, options?: ResolveAppProfileOptions): string;
|
|
35
|
+
/**
|
|
36
|
+
* 解析容器档案为可下发配置。
|
|
37
|
+
* @throws profile 名不存在时抛错,错误信息列出全部可用档案
|
|
38
|
+
*/
|
|
39
|
+
export declare function listBuiltinAppProfiles(): AppProfileCatalogEntry[];
|
|
40
|
+
export declare function resolveAppProfile(name: string, options?: ResolveAppProfileOptions, pinnedDefinition?: AppProfileDefinition): ResolvedAppProfile;
|
|
41
|
+
export declare function resolveAppProfileDefinition(definition: AppProfileDefinition, options?: ResolveAppProfileOptions): ResolvedAppProfile;
|
package/dist/profiles.js
ADDED
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import { DEVICE_PRESETS, APP_BRIDGE_BEHAVIORS, appProfileRevision, validateAppProfileDefinition, resolveEmulationConfig, } from '@mearl/browser-core';
|
|
2
|
+
import { BUILTIN_APP_PROFILE_LABELS } from './metadata.js';
|
|
3
|
+
function emptyActions() {
|
|
4
|
+
return {
|
|
5
|
+
open: [],
|
|
6
|
+
close: [],
|
|
7
|
+
title: [],
|
|
8
|
+
navigationBar: [],
|
|
9
|
+
statusBar: [],
|
|
10
|
+
systemInfo: [],
|
|
11
|
+
mtop: [],
|
|
12
|
+
kvGet: [],
|
|
13
|
+
kvSet: [],
|
|
14
|
+
kvDelete: [],
|
|
15
|
+
pageContext: [],
|
|
16
|
+
responses: {},
|
|
17
|
+
behaviors: {},
|
|
18
|
+
noop: [],
|
|
19
|
+
silent: [],
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function mergeActions(...maps) {
|
|
23
|
+
const out = emptyActions();
|
|
24
|
+
for (const m of maps) {
|
|
25
|
+
out.open.push(...m.open);
|
|
26
|
+
out.close.push(...m.close);
|
|
27
|
+
out.title.push(...m.title);
|
|
28
|
+
out.navigationBar.push(...(m.navigationBar ?? []));
|
|
29
|
+
out.statusBar.push(...(m.statusBar ?? []));
|
|
30
|
+
out.systemInfo.push(...m.systemInfo);
|
|
31
|
+
out.mtop.push(...m.mtop);
|
|
32
|
+
out.kvGet.push(...(m.kvGet ?? []));
|
|
33
|
+
out.kvSet.push(...(m.kvSet ?? []));
|
|
34
|
+
out.kvDelete.push(...(m.kvDelete ?? []));
|
|
35
|
+
out.pageContext.push(...(m.pageContext ?? []));
|
|
36
|
+
Object.assign(out.responses, m.responses ?? {});
|
|
37
|
+
Object.assign(out.behaviors, m.behaviors ?? {});
|
|
38
|
+
out.noop.push(...m.noop);
|
|
39
|
+
out.silent.push(...(m.silent ?? []));
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
const APP_BRIDGE_BEHAVIOR_SET = new Set(APP_BRIDGE_BEHAVIORS);
|
|
44
|
+
const BRIDGE_ACTION_ARRAY_KEYS = [
|
|
45
|
+
'open',
|
|
46
|
+
'close',
|
|
47
|
+
'title',
|
|
48
|
+
'navigationBar',
|
|
49
|
+
'statusBar',
|
|
50
|
+
'systemInfo',
|
|
51
|
+
'mtop',
|
|
52
|
+
'kvGet',
|
|
53
|
+
'kvSet',
|
|
54
|
+
'kvDelete',
|
|
55
|
+
'pageContext',
|
|
56
|
+
'noop',
|
|
57
|
+
];
|
|
58
|
+
function isJsonValue(value, seen = new Set()) {
|
|
59
|
+
if (value === null || typeof value === 'string' || typeof value === 'boolean')
|
|
60
|
+
return true;
|
|
61
|
+
if (typeof value === 'number')
|
|
62
|
+
return Number.isFinite(value);
|
|
63
|
+
if (typeof value !== 'object')
|
|
64
|
+
return false;
|
|
65
|
+
if (seen.has(value))
|
|
66
|
+
return false;
|
|
67
|
+
seen.add(value);
|
|
68
|
+
const valid = Array.isArray(value)
|
|
69
|
+
? value.every(item => isJsonValue(item, seen))
|
|
70
|
+
: Object.values(value).every(item => isJsonValue(item, seen));
|
|
71
|
+
seen.delete(value);
|
|
72
|
+
return valid;
|
|
73
|
+
}
|
|
74
|
+
/** 校验并复制用户提供的声明式桥配置。 */
|
|
75
|
+
export function validateAppBridgeConfig(value) {
|
|
76
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) {
|
|
77
|
+
throw new Error('bridgeConfig must be an object');
|
|
78
|
+
}
|
|
79
|
+
const root = value;
|
|
80
|
+
if (Object.keys(root).some(key => key !== 'methods')) {
|
|
81
|
+
throw new Error('bridgeConfig only supports the "methods" field');
|
|
82
|
+
}
|
|
83
|
+
if (!root.methods || typeof root.methods !== 'object' || Array.isArray(root.methods)) {
|
|
84
|
+
throw new Error('bridgeConfig.methods must be an object');
|
|
85
|
+
}
|
|
86
|
+
const entries = Object.entries(root.methods);
|
|
87
|
+
if (entries.length > 200)
|
|
88
|
+
throw new Error('bridgeConfig supports at most 200 methods');
|
|
89
|
+
const methods = {};
|
|
90
|
+
for (const [method, rawConfig] of entries) {
|
|
91
|
+
if (!method.trim() || method.length > 200) {
|
|
92
|
+
throw new Error('bridgeConfig method names must contain 1-200 characters');
|
|
93
|
+
}
|
|
94
|
+
if (method === '__proto__' || method === 'prototype' || method === 'constructor') {
|
|
95
|
+
throw new Error(`bridgeConfig method name "${method}" is reserved`);
|
|
96
|
+
}
|
|
97
|
+
if (!rawConfig || typeof rawConfig !== 'object' || Array.isArray(rawConfig)) {
|
|
98
|
+
throw new Error(`bridgeConfig.methods.${method} must be an object`);
|
|
99
|
+
}
|
|
100
|
+
const methodConfig = rawConfig;
|
|
101
|
+
const supportedKeys = new Set(['behavior', 'response', 'noop', 'silent']);
|
|
102
|
+
if (Object.keys(methodConfig).some(key => !supportedKeys.has(key))) {
|
|
103
|
+
throw new Error(`bridgeConfig.methods.${method} contains an unsupported field`);
|
|
104
|
+
}
|
|
105
|
+
if ('behavior' in methodConfig && typeof methodConfig.behavior !== 'string') {
|
|
106
|
+
throw new Error(`bridgeConfig.methods.${method}.behavior must be a string`);
|
|
107
|
+
}
|
|
108
|
+
const hasBehavior = typeof methodConfig.behavior === 'string';
|
|
109
|
+
const hasResponse = Object.prototype.hasOwnProperty.call(methodConfig, 'response');
|
|
110
|
+
const hasNoop = methodConfig.noop === true;
|
|
111
|
+
if (Number(hasBehavior) + Number(hasResponse) + Number(hasNoop) !== 1) {
|
|
112
|
+
throw new Error(`bridgeConfig.methods.${method} must define exactly one of behavior, response, or noop=true`);
|
|
113
|
+
}
|
|
114
|
+
if (hasBehavior && !APP_BRIDGE_BEHAVIOR_SET.has(methodConfig.behavior)) {
|
|
115
|
+
throw new Error(`bridgeConfig.methods.${method} has an unsupported behavior`);
|
|
116
|
+
}
|
|
117
|
+
if (hasResponse && !isJsonValue(methodConfig.response)) {
|
|
118
|
+
throw new Error(`bridgeConfig.methods.${method}.response must be valid JSON data`);
|
|
119
|
+
}
|
|
120
|
+
if ('noop' in methodConfig && methodConfig.noop !== true) {
|
|
121
|
+
throw new Error(`bridgeConfig.methods.${method}.noop must be true when provided`);
|
|
122
|
+
}
|
|
123
|
+
if ('silent' in methodConfig && typeof methodConfig.silent !== 'boolean') {
|
|
124
|
+
throw new Error(`bridgeConfig.methods.${method}.silent must be a boolean`);
|
|
125
|
+
}
|
|
126
|
+
methods[method] = {
|
|
127
|
+
...(hasBehavior && { behavior: methodConfig.behavior }),
|
|
128
|
+
...(hasResponse && { response: JSON.parse(JSON.stringify(methodConfig.response)) }),
|
|
129
|
+
...(hasNoop && { noop: true }),
|
|
130
|
+
...(methodConfig.silent === true && { silent: true }),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
const normalized = { methods };
|
|
134
|
+
if (JSON.stringify(normalized).length > 65_536) {
|
|
135
|
+
throw new Error('bridgeConfig must not exceed 64 KiB');
|
|
136
|
+
}
|
|
137
|
+
return normalized;
|
|
138
|
+
}
|
|
139
|
+
/** 后传配置按方法覆盖前传配置,供扩展本地配置与单次 Agent 参数组合。 */
|
|
140
|
+
export function mergeAppBridgeConfigs(...configs) {
|
|
141
|
+
const present = configs.filter((config) => config !== undefined);
|
|
142
|
+
if (present.length === 0)
|
|
143
|
+
return undefined;
|
|
144
|
+
const methods = {};
|
|
145
|
+
for (const config of present)
|
|
146
|
+
Object.assign(methods, validateAppBridgeConfig(config).methods);
|
|
147
|
+
return validateAppBridgeConfig({ methods });
|
|
148
|
+
}
|
|
149
|
+
/** 将声明式方法覆盖编译进运行时动作表,不修改档案的静态数据。 */
|
|
150
|
+
export function applyAppBridgeConfig(actions, config) {
|
|
151
|
+
const out = mergeActions(actions);
|
|
152
|
+
if (!config)
|
|
153
|
+
return out;
|
|
154
|
+
const { methods } = validateAppBridgeConfig(config);
|
|
155
|
+
for (const [method, methodConfig] of Object.entries(methods)) {
|
|
156
|
+
for (const key of BRIDGE_ACTION_ARRAY_KEYS) {
|
|
157
|
+
const values = out[key];
|
|
158
|
+
if (values)
|
|
159
|
+
out[key] = values.filter(value => value !== method);
|
|
160
|
+
}
|
|
161
|
+
out.silent = (out.silent ?? []).filter(value => value !== method);
|
|
162
|
+
delete out.responses?.[method];
|
|
163
|
+
delete out.behaviors?.[method];
|
|
164
|
+
if (methodConfig.behavior)
|
|
165
|
+
out.behaviors[method] = methodConfig.behavior;
|
|
166
|
+
else if (Object.prototype.hasOwnProperty.call(methodConfig, 'response')) {
|
|
167
|
+
out.responses[method] = methodConfig.response;
|
|
168
|
+
}
|
|
169
|
+
else if (methodConfig.noop)
|
|
170
|
+
out.noop.push(method);
|
|
171
|
+
if (methodConfig.silent)
|
|
172
|
+
out.silent.push(method);
|
|
173
|
+
}
|
|
174
|
+
return out;
|
|
175
|
+
}
|
|
176
|
+
/** Built-ins provide UA/version identity; full environments come from capability packages. */
|
|
177
|
+
function basicProfile(name, appName, defaultAppVersion, uaTokens, uaFamily) {
|
|
178
|
+
return { name, label: BUILTIN_APP_PROFILE_LABELS[name], appName, defaultAppVersion, uaTokens,
|
|
179
|
+
...(uaFamily && { uaFamily }), globals: {}, bridges: [], activeEvents: [], actions: emptyActions(), schemes: [] };
|
|
180
|
+
}
|
|
181
|
+
export const APP_PROFILES = {
|
|
182
|
+
fliggy: basicProfile('fliggy', 'LX', '10.0.9', ['AliTrip/{v}', 'WindVane/8.7.0']),
|
|
183
|
+
taobao: basicProfile('taobao', 'TB', '10.65.0', ['WindVane/8.7.0']),
|
|
184
|
+
wechat: basicProfile('wechat', 'WeChat', '8.0.58', [], 'wechatMiniProgram'),
|
|
185
|
+
alipay: { ...basicProfile('alipay', 'AP', '10.8.0', ['AlipayClient/{v}']), policies: { navigatorLanguage: true, defaultLanguage: 'zh-CN' } },
|
|
186
|
+
};
|
|
187
|
+
/** 构造容器 UA。os 默认 ios;uaTokens 中的 {v} 替换为 appVersion */
|
|
188
|
+
export function buildAppProfileUa(profile, options = {}) {
|
|
189
|
+
const os = options.os ??
|
|
190
|
+
(options.devicePreset ? DEVICE_PRESETS[options.devicePreset]?.appProfileOs : undefined) ??
|
|
191
|
+
'ios';
|
|
192
|
+
const version = options.appVersion ?? profile.defaultAppVersion;
|
|
193
|
+
const deviceModel = options.deviceModel ??
|
|
194
|
+
(options.devicePreset ? DEVICE_PRESETS[options.devicePreset]?.appProfileModel : undefined) ??
|
|
195
|
+
'Pixel 11';
|
|
196
|
+
if (profile.uaTemplate) {
|
|
197
|
+
return profile.uaTemplate[os]
|
|
198
|
+
.replaceAll('{v}', version)
|
|
199
|
+
.replaceAll('{deviceModel}', deviceModel)
|
|
200
|
+
.replaceAll('{language}', options.language ?? profile.policies?.defaultLanguage ?? 'zh-Hans');
|
|
201
|
+
}
|
|
202
|
+
if (profile.uaFamily === 'wechatMiniProgram') {
|
|
203
|
+
if (os === 'android') {
|
|
204
|
+
return `Mozilla/5.0 (Linux; Android 17; ${deviceModel}; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/152.0.0.0 Mobile MicroMessenger/${version} WeChat/arm64 NetType/WIFI Language/zh_CN miniProgram`;
|
|
205
|
+
}
|
|
206
|
+
return `Mozilla/5.0 (iPhone; CPU iPhone OS 18_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/${version} NetType/WIFI Language/zh_CN miniProgram`;
|
|
207
|
+
}
|
|
208
|
+
const tokens = profile.uaTokens.map(t => t.replaceAll('{v}', version)).filter(Boolean);
|
|
209
|
+
const tail = `${tokens.length > 0 ? ` ${tokens.join(' ')}` : ''}${profile.policies?.navigatorLanguage ? ` Language/${options.language ?? profile.policies.defaultLanguage ?? 'zh-CN'}` : ''}`;
|
|
210
|
+
if (os === 'android') {
|
|
211
|
+
return `Mozilla/5.0 (Linux; Android 17; ${deviceModel}) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/152.0.0.0 Mobile Safari/537.36 AliApp(${profile.appName}/${version})${tail}`;
|
|
212
|
+
}
|
|
213
|
+
return `Mozilla/5.0 (iPhone; CPU iPhone OS 18_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) AliApp(${profile.appName}/${version})${tail}`;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* 解析容器档案为可下发配置。
|
|
217
|
+
* @throws profile 名不存在时抛错,错误信息列出全部可用档案
|
|
218
|
+
*/
|
|
219
|
+
export function listBuiltinAppProfiles() {
|
|
220
|
+
return Object.values(APP_PROFILES).map(definition => ({
|
|
221
|
+
id: definition.name,
|
|
222
|
+
label: definition.label,
|
|
223
|
+
source: 'builtin',
|
|
224
|
+
revision: appProfileRevision(definition),
|
|
225
|
+
definition,
|
|
226
|
+
}));
|
|
227
|
+
}
|
|
228
|
+
export function resolveAppProfile(name, options = {}, pinnedDefinition) {
|
|
229
|
+
const definition = pinnedDefinition ?? APP_PROFILES[name];
|
|
230
|
+
if (!definition || definition.name !== name) {
|
|
231
|
+
throw new Error(`Unknown app profile "${name}". Available: ${Object.keys(APP_PROFILES).join(', ')}`);
|
|
232
|
+
}
|
|
233
|
+
return resolveAppProfileDefinition(definition, options);
|
|
234
|
+
}
|
|
235
|
+
export function resolveAppProfileDefinition(definition, options = {}) {
|
|
236
|
+
const profile = validateAppProfileDefinition(definition);
|
|
237
|
+
if (options.lockDefinition !== undefined && typeof options.lockDefinition !== 'boolean')
|
|
238
|
+
throw new Error('lockDefinition must be a boolean');
|
|
239
|
+
if (options.os !== undefined && options.os !== 'ios' && options.os !== 'android')
|
|
240
|
+
throw new Error('Invalid app profile OS');
|
|
241
|
+
if (options.orientation !== undefined &&
|
|
242
|
+
options.orientation !== 'portrait' &&
|
|
243
|
+
options.orientation !== 'landscape')
|
|
244
|
+
throw new Error('Invalid app profile orientation');
|
|
245
|
+
if (options.devicePreset !== undefined && !Object.hasOwn(DEVICE_PRESETS, options.devicePreset))
|
|
246
|
+
throw new Error('Invalid app profile device preset');
|
|
247
|
+
for (const [key, maximum] of [
|
|
248
|
+
['appVersion', 100],
|
|
249
|
+
['deviceModel', 200],
|
|
250
|
+
['language', 100],
|
|
251
|
+
]) {
|
|
252
|
+
const value = options[key];
|
|
253
|
+
if (value !== undefined &&
|
|
254
|
+
(typeof value !== 'string' || !value || value.length > maximum || /[\r\n]/.test(value)))
|
|
255
|
+
throw new Error(`Invalid app profile ${key}`);
|
|
256
|
+
}
|
|
257
|
+
if (options.language !== undefined &&
|
|
258
|
+
profile.policies?.languages &&
|
|
259
|
+
!profile.policies.languages.includes(options.language)) {
|
|
260
|
+
throw new Error(`Unsupported ${profile.settingsGroup === 'alipay' ? 'Alipay' : profile.label} language. Use ${profile.policies.languages.join(', ')}.`);
|
|
261
|
+
}
|
|
262
|
+
const os = options.os ??
|
|
263
|
+
(options.devicePreset ? DEVICE_PRESETS[options.devicePreset]?.appProfileOs : undefined) ??
|
|
264
|
+
'ios';
|
|
265
|
+
const version = options.appVersion ?? profile.defaultAppVersion;
|
|
266
|
+
const recommendedPreset = os === 'android' ? 'pixel-11' : 'iphone-17-pro';
|
|
267
|
+
const devicePreset = options.devicePreset ?? recommendedPreset;
|
|
268
|
+
const emulation = resolveEmulationConfig({
|
|
269
|
+
enabled: true,
|
|
270
|
+
preset: devicePreset,
|
|
271
|
+
orientation: options.orientation,
|
|
272
|
+
});
|
|
273
|
+
const deviceModel = options.deviceModel ?? DEVICE_PRESETS[devicePreset].appProfileModel;
|
|
274
|
+
const globals = profile.pageRuntime || profile.bridges.length > 0 || Object.keys(profile.globals).length > 0 ? {
|
|
275
|
+
...profile.globals,
|
|
276
|
+
__APP_NAME__: profile.appName,
|
|
277
|
+
__APP_VERSION__: version,
|
|
278
|
+
__FLI_DEVICE_MODEL__: deviceModel,
|
|
279
|
+
__DEVICE_MODEL__: deviceModel,
|
|
280
|
+
} : {};
|
|
281
|
+
const ua = buildAppProfileUa(profile, { ...options, os, deviceModel });
|
|
282
|
+
return {
|
|
283
|
+
profile: profile.name,
|
|
284
|
+
label: profile.label,
|
|
285
|
+
ua,
|
|
286
|
+
injected: {
|
|
287
|
+
...(profile.pageRuntime && { pageRuntime: profile.pageRuntime }),
|
|
288
|
+
binding: {
|
|
289
|
+
version: 1,
|
|
290
|
+
revision: appProfileRevision(profile),
|
|
291
|
+
definition: profile,
|
|
292
|
+
options: JSON.parse(JSON.stringify({ ...options, os, appVersion: version, deviceModel, devicePreset })),
|
|
293
|
+
explicitOptions: JSON.parse(JSON.stringify(Object.fromEntries(Object.entries(options).filter(([key]) => key !== 'bridgeConfig')))),
|
|
294
|
+
},
|
|
295
|
+
policies: profile.policies ?? {},
|
|
296
|
+
settings: profile.settings ?? [],
|
|
297
|
+
profile: profile.name,
|
|
298
|
+
label: profile.label,
|
|
299
|
+
globals,
|
|
300
|
+
bridges: profile.bridges,
|
|
301
|
+
activeEvents: profile.activeEvents,
|
|
302
|
+
maxTouchPoints: 5,
|
|
303
|
+
statusBarHeight: emulation.safeAreaInsets.top,
|
|
304
|
+
safeAreaInsets: emulation.safeAreaInsets,
|
|
305
|
+
deviceAppearance: {
|
|
306
|
+
preset: devicePreset,
|
|
307
|
+
orientation: emulation.orientation,
|
|
308
|
+
cutout: emulation.appearance.cutout,
|
|
309
|
+
},
|
|
310
|
+
language: options.language ?? profile.policies?.defaultLanguage ?? 'zh-Hans',
|
|
311
|
+
// UA 随注入配置一起下发,供 DNR、页内运行时和动态 WebView 导航前刷新使用
|
|
312
|
+
userAgent: ua,
|
|
313
|
+
navigatorPlatform: os === 'android' ? 'Linux armv8l' : 'iPhone',
|
|
314
|
+
// systemInfo 使用产品系统版本;Safari UA 中的系统 token 可能是兼容性固定值。
|
|
315
|
+
platform: os === 'android' ? 'Android' : 'iOS',
|
|
316
|
+
systemVersion: os === 'android' ? '17' : '26.0',
|
|
317
|
+
clientType: os === 'android' ? 'android' : 'iphone',
|
|
318
|
+
actions: applyAppBridgeConfig(profile.actions, options.bridgeConfig),
|
|
319
|
+
schemes: profile.schemes,
|
|
320
|
+
...(profile.miniProgram && { miniProgram: profile.miniProgram }),
|
|
321
|
+
...(profile.imagePicker && { imagePicker: profile.imagePicker }),
|
|
322
|
+
...(profile.geolocation && { geolocation: profile.geolocation }),
|
|
323
|
+
...(profile.overlay && { overlay: profile.overlay }),
|
|
324
|
+
...(profile.popBeforeOpenParam && { popBeforeOpenParam: profile.popBeforeOpenParam }),
|
|
325
|
+
...(profile.messageEvent && { messageEvent: profile.messageEvent }),
|
|
326
|
+
...(profile.nativeBack && { nativeBack: profile.nativeBack }),
|
|
327
|
+
...(profile.layerUrlProxy && { layerUrlProxy: profile.layerUrlProxy }),
|
|
328
|
+
...(profile.urlSyncHostSuffixes && { urlSyncHostSuffixes: profile.urlSyncHostSuffixes }),
|
|
329
|
+
...(profile.forceH5Mtop && { forceH5Mtop: true }),
|
|
330
|
+
simulateSystemBars: false,
|
|
331
|
+
externalDeviceChrome: false,
|
|
332
|
+
rootContainer: {
|
|
333
|
+
enabled: false,
|
|
334
|
+
...(profile.rootContainer?.statusBarHeightCookie && {
|
|
335
|
+
initialCookies: [
|
|
336
|
+
{
|
|
337
|
+
...profile.rootContainer.statusBarHeightCookie,
|
|
338
|
+
value: String(emulation.safeAreaInsets.top),
|
|
339
|
+
},
|
|
340
|
+
],
|
|
341
|
+
}),
|
|
342
|
+
},
|
|
343
|
+
titleBar: {
|
|
344
|
+
navigationBarHeight: os === 'android' ? 48 : 44,
|
|
345
|
+
backgroundColor: '#ffffff',
|
|
346
|
+
textColor: '#0f131a',
|
|
347
|
+
...(profile.titleBarHiddenPathnames && {
|
|
348
|
+
hiddenPathnames: profile.titleBarHiddenPathnames,
|
|
349
|
+
}),
|
|
350
|
+
...(profile.statusBarBackgroundColors && {
|
|
351
|
+
statusBarBackgroundColors: profile.statusBarBackgroundColors,
|
|
352
|
+
}),
|
|
353
|
+
...(profile.titleBarHostStyles && { hostStyles: profile.titleBarHostStyles }),
|
|
354
|
+
},
|
|
355
|
+
},
|
|
356
|
+
recommendedPreset,
|
|
357
|
+
};
|
|
358
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AppProfileOptions, AppProfileSetting, InjectedAppProfileConfig } from '@mearl/browser-core';
|
|
2
|
+
export declare function readAppProfileSetting(config: InjectedAppProfileConfig, setting: AppProfileSetting): unknown;
|
|
3
|
+
/** Settings write canonical options or method overrides; presentation state is derived. */
|
|
4
|
+
export declare function updateAppProfileSetting(config: InjectedAppProfileConfig, id: string, value: unknown): {
|
|
5
|
+
config: InjectedAppProfileConfig;
|
|
6
|
+
options: AppProfileOptions;
|
|
7
|
+
responses?: Record<string, unknown>;
|
|
8
|
+
reload: boolean;
|
|
9
|
+
};
|
package/dist/settings.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { rebuildAppProfileConfig } from './updates.js';
|
|
2
|
+
export function readAppProfileSetting(config, setting) {
|
|
3
|
+
if ('option' in setting.target)
|
|
4
|
+
return config.language;
|
|
5
|
+
const response = config.actions.responses?.[setting.target.method];
|
|
6
|
+
if (setting.target.field) {
|
|
7
|
+
return response && typeof response === 'object' && !Array.isArray(response)
|
|
8
|
+
? response[setting.target.field]
|
|
9
|
+
: undefined;
|
|
10
|
+
}
|
|
11
|
+
return response;
|
|
12
|
+
}
|
|
13
|
+
/** Settings write canonical options or method overrides; presentation state is derived. */
|
|
14
|
+
export function updateAppProfileSetting(config, id, value) {
|
|
15
|
+
const binding = config.binding;
|
|
16
|
+
const setting = binding?.definition.settings?.find(item => item.id === id);
|
|
17
|
+
if (!binding || !setting)
|
|
18
|
+
throw new Error('App profile setting is unavailable');
|
|
19
|
+
if ((setting.type === 'boolean' && typeof value !== 'boolean') ||
|
|
20
|
+
(setting.type === 'number' &&
|
|
21
|
+
(typeof value !== 'number' ||
|
|
22
|
+
!Number.isFinite(value) ||
|
|
23
|
+
(setting.minimum !== undefined && value < setting.minimum) ||
|
|
24
|
+
(setting.maximum !== undefined && value > setting.maximum))) ||
|
|
25
|
+
(['text', 'select'].includes(setting.type) && typeof value !== 'string') ||
|
|
26
|
+
(setting.type === 'select' && !setting.choices?.some(choice => choice.value === value))) {
|
|
27
|
+
throw new Error('Invalid app profile setting value');
|
|
28
|
+
}
|
|
29
|
+
if (JSON.stringify(value)?.length > 16_384 || value === undefined)
|
|
30
|
+
throw new Error('Invalid app profile setting value');
|
|
31
|
+
if ('option' in setting.target) {
|
|
32
|
+
const next = rebuildAppProfileConfig(config, { language: String(value) });
|
|
33
|
+
return { config: next, options: next.binding.options, reload: true };
|
|
34
|
+
}
|
|
35
|
+
const { method, field } = setting.target;
|
|
36
|
+
const old = config.actions.responses?.[method];
|
|
37
|
+
const response = field
|
|
38
|
+
? { ...(old && typeof old === 'object' && !Array.isArray(old) ? old : {}), [field]: value }
|
|
39
|
+
: value;
|
|
40
|
+
const patch = {
|
|
41
|
+
methods: { [method]: { response, silent: config.actions.silent?.includes(method) === true } },
|
|
42
|
+
};
|
|
43
|
+
const next = rebuildAppProfileConfig(config, { bridgeConfig: patch });
|
|
44
|
+
return {
|
|
45
|
+
config: next,
|
|
46
|
+
options: next.binding.options,
|
|
47
|
+
responses: { [method]: response },
|
|
48
|
+
reload: false,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AppProfileDefinition, AppProfileOptions, InjectedAppProfileConfig } from '@mearl/browser-core';
|
|
2
|
+
/** Definition lookup must not keep a navigation paused when the host or a plugin is unavailable. */
|
|
3
|
+
export declare function findAppProfileDefinitionUpdate(current: InjectedAppProfileConfig, load: () => Promise<AppProfileDefinition>, timeoutMs?: number): Promise<AppProfileDefinition | undefined>;
|
|
4
|
+
/** Host command envelopes never become part of a serialized profile binding. */
|
|
5
|
+
export declare function mergeAppProfileOptions(...sources: Array<AppProfileOptions | undefined>): AppProfileOptions;
|
|
6
|
+
export declare function getAppProfileExplicitOptions(config: InjectedAppProfileConfig): AppProfileOptions;
|
|
7
|
+
/** Both hosts use the same precedence for saved choices, active choices and command overrides. */
|
|
8
|
+
export declare function resolveAppProfileUpdate(name: string, { current, definition, defaults, options, deviceOptions, }?: {
|
|
9
|
+
current?: InjectedAppProfileConfig;
|
|
10
|
+
definition?: AppProfileDefinition;
|
|
11
|
+
defaults?: AppProfileOptions;
|
|
12
|
+
options?: AppProfileOptions;
|
|
13
|
+
deviceOptions?: AppProfileOptions;
|
|
14
|
+
}): import("./profiles.js").ResolvedAppProfile;
|
|
15
|
+
/** Recompile profile-owned fields while retaining the independently managed device layout. */
|
|
16
|
+
export declare function rebuildAppProfileConfig(current: InjectedAppProfileConfig, options?: AppProfileOptions, definition?: AppProfileDefinition | undefined): InjectedAppProfileConfig;
|
package/dist/updates.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { appProfileRevision } from '@mearl/browser-core';
|
|
2
|
+
import { mergeAppBridgeConfigs, resolveAppProfile } from './profiles.js';
|
|
3
|
+
const OPTION_KEYS = [
|
|
4
|
+
'os',
|
|
5
|
+
'appVersion',
|
|
6
|
+
'language',
|
|
7
|
+
'deviceModel',
|
|
8
|
+
'devicePreset',
|
|
9
|
+
'orientation',
|
|
10
|
+
'lockDefinition',
|
|
11
|
+
];
|
|
12
|
+
/** Definition lookup must not keep a navigation paused when the host or a plugin is unavailable. */
|
|
13
|
+
export async function findAppProfileDefinitionUpdate(current, load, timeoutMs = 1500) {
|
|
14
|
+
if (!current.binding || current.binding.options.lockDefinition)
|
|
15
|
+
return undefined;
|
|
16
|
+
let timer;
|
|
17
|
+
try {
|
|
18
|
+
const definition = await Promise.race([
|
|
19
|
+
load(),
|
|
20
|
+
new Promise(resolve => {
|
|
21
|
+
timer = setTimeout(() => resolve(undefined), timeoutMs);
|
|
22
|
+
}),
|
|
23
|
+
]);
|
|
24
|
+
// Removing a code provider does not replace a pinned full environment with a UA-only fallback.
|
|
25
|
+
if (current.binding.definition.pageRuntime && definition && !definition.pageRuntime)
|
|
26
|
+
return undefined;
|
|
27
|
+
return definition &&
|
|
28
|
+
definition.name === current.profile &&
|
|
29
|
+
appProfileRevision(definition) !== current.binding.revision
|
|
30
|
+
? definition
|
|
31
|
+
: undefined;
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
clearTimeout(timer);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** Host command envelopes never become part of a serialized profile binding. */
|
|
41
|
+
export function mergeAppProfileOptions(...sources) {
|
|
42
|
+
const result = {};
|
|
43
|
+
for (const source of sources) {
|
|
44
|
+
if (!source)
|
|
45
|
+
continue;
|
|
46
|
+
for (const key of OPTION_KEYS) {
|
|
47
|
+
if (source[key] !== undefined)
|
|
48
|
+
Object.assign(result, { [key]: source[key] });
|
|
49
|
+
}
|
|
50
|
+
if (source.bridgeConfig !== undefined)
|
|
51
|
+
result.bridgeConfig = mergeAppBridgeConfigs(result.bridgeConfig, source.bridgeConfig);
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
export function getAppProfileExplicitOptions(config) {
|
|
56
|
+
return mergeAppProfileOptions(config.binding?.explicitOptions, {
|
|
57
|
+
bridgeConfig: config.binding?.options.bridgeConfig,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/** Both hosts use the same precedence for saved choices, active choices and command overrides. */
|
|
61
|
+
export function resolveAppProfileUpdate(name, { current, definition, defaults, options, deviceOptions, } = {}) {
|
|
62
|
+
const active = current?.profile === name ? current : undefined;
|
|
63
|
+
const explicit = mergeAppProfileOptions(defaults, active ? getAppProfileExplicitOptions(active) : undefined, options);
|
|
64
|
+
const previousDevice = active?.binding?.options;
|
|
65
|
+
const effective = mergeAppProfileOptions(previousDevice && {
|
|
66
|
+
os: previousDevice.os,
|
|
67
|
+
deviceModel: previousDevice.deviceModel,
|
|
68
|
+
devicePreset: previousDevice.devicePreset,
|
|
69
|
+
orientation: previousDevice.orientation,
|
|
70
|
+
}, explicit, deviceOptions);
|
|
71
|
+
const resolved = resolveAppProfile(name, effective, definition ?? active?.binding?.definition);
|
|
72
|
+
resolved.injected.binding.explicitOptions = Object.fromEntries(Object.entries(explicit).filter(([key]) => key !== 'bridgeConfig'));
|
|
73
|
+
if (active?.hostCapabilities && (definition === undefined || definition === active.binding?.definition))
|
|
74
|
+
resolved.injected.hostCapabilities = structuredClone(active.hostCapabilities);
|
|
75
|
+
return resolved;
|
|
76
|
+
}
|
|
77
|
+
/** Recompile profile-owned fields while retaining the independently managed device layout. */
|
|
78
|
+
export function rebuildAppProfileConfig(current, options = {}, definition = current.binding?.definition) {
|
|
79
|
+
const next = resolveAppProfileUpdate(current.profile, { current, definition, options }).injected;
|
|
80
|
+
return {
|
|
81
|
+
...next,
|
|
82
|
+
animationMs: current.animationMs,
|
|
83
|
+
statusBarHeight: current.statusBarHeight,
|
|
84
|
+
safeAreaInsets: current.safeAreaInsets,
|
|
85
|
+
deviceAppearance: current.deviceAppearance,
|
|
86
|
+
simulateSystemBars: current.simulateSystemBars,
|
|
87
|
+
externalDeviceChrome: current.externalDeviceChrome,
|
|
88
|
+
rootContainer: {
|
|
89
|
+
...next.rootContainer,
|
|
90
|
+
...(next.rootContainer?.initialCookies && {
|
|
91
|
+
initialCookies: next.rootContainer.initialCookies.map(cookie => ({
|
|
92
|
+
...cookie,
|
|
93
|
+
value: String(current.statusBarHeight),
|
|
94
|
+
})),
|
|
95
|
+
}),
|
|
96
|
+
enabled: current.rootContainer?.enabled ?? false,
|
|
97
|
+
...(current.rootContainer?.splitScreen !== undefined && {
|
|
98
|
+
splitScreen: current.rootContainer.splitScreen,
|
|
99
|
+
}),
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mearl/app-profiles",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "3.0.0-beta.1",
|
|
4
|
+
"description": "Basic App user agents and declarative profile compilation",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./metadata": {
|
|
14
|
+
"types": "./dist/metadata.d.ts",
|
|
15
|
+
"import": "./dist/metadata.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"!dist/**/*.map"
|
|
21
|
+
],
|
|
22
|
+
"keywords": [
|
|
23
|
+
"mearl"
|
|
24
|
+
],
|
|
25
|
+
"license": "Apache-2.0",
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@mearl/browser-core": "3.0.0-beta.1"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"typescript": "^5.8.3"
|
|
31
|
+
},
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git+https://github.com/F-loat/mearl.git",
|
|
35
|
+
"directory": "packages/app-profiles"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "rm -rf dist/ && tsc",
|
|
39
|
+
"dev": "tsc --watch",
|
|
40
|
+
"typecheck": "tsc --noEmit",
|
|
41
|
+
"test": "vitest run"
|
|
42
|
+
}
|
|
6
43
|
}
|