@miaixz/sdk 0.5.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.
Files changed (244) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +7 -0
  3. package/README.md +412 -0
  4. package/dist/api/client.d.ts +223 -0
  5. package/dist/api/client.d.ts.map +1 -0
  6. package/dist/api/client.js +1069 -0
  7. package/dist/api/client.js.map +1 -0
  8. package/dist/api/endpoint.d.ts +10 -0
  9. package/dist/api/endpoint.d.ts.map +1 -0
  10. package/dist/api/endpoint.js +51 -0
  11. package/dist/api/endpoint.js.map +1 -0
  12. package/dist/api/errors.d.ts +180 -0
  13. package/dist/api/errors.d.ts.map +1 -0
  14. package/dist/api/errors.js +173 -0
  15. package/dist/api/errors.js.map +1 -0
  16. package/dist/api/index.d.ts +6 -0
  17. package/dist/api/index.d.ts.map +1 -0
  18. package/dist/api/index.js +5 -0
  19. package/dist/api/index.js.map +1 -0
  20. package/dist/api/request.d.ts +135 -0
  21. package/dist/api/request.d.ts.map +1 -0
  22. package/dist/api/request.js +2 -0
  23. package/dist/api/request.js.map +1 -0
  24. package/dist/api/response.d.ts +69 -0
  25. package/dist/api/response.d.ts.map +1 -0
  26. package/dist/api/response.js +43 -0
  27. package/dist/api/response.js.map +1 -0
  28. package/dist/api/telemetry.d.ts +139 -0
  29. package/dist/api/telemetry.d.ts.map +1 -0
  30. package/dist/api/telemetry.js +2 -0
  31. package/dist/api/telemetry.js.map +1 -0
  32. package/dist/appearance/appearance.d.ts +161 -0
  33. package/dist/appearance/appearance.d.ts.map +1 -0
  34. package/dist/appearance/appearance.js +614 -0
  35. package/dist/appearance/appearance.js.map +1 -0
  36. package/dist/appearance/index.d.ts +3 -0
  37. package/dist/appearance/index.d.ts.map +1 -0
  38. package/dist/appearance/index.js +3 -0
  39. package/dist/appearance/index.js.map +1 -0
  40. package/dist/auth/auth.d.ts +197 -0
  41. package/dist/auth/auth.d.ts.map +1 -0
  42. package/dist/auth/auth.js +314 -0
  43. package/dist/auth/auth.js.map +1 -0
  44. package/dist/auth/index.d.ts +2 -0
  45. package/dist/auth/index.d.ts.map +1 -0
  46. package/dist/auth/index.js +2 -0
  47. package/dist/auth/index.js.map +1 -0
  48. package/dist/config/config.d.ts +117 -0
  49. package/dist/config/config.d.ts.map +1 -0
  50. package/dist/config/config.js +241 -0
  51. package/dist/config/config.js.map +1 -0
  52. package/dist/config/index.d.ts +2 -0
  53. package/dist/config/index.d.ts.map +1 -0
  54. package/dist/config/index.js +2 -0
  55. package/dist/config/index.js.map +1 -0
  56. package/dist/consts/index.d.ts +35 -0
  57. package/dist/consts/index.d.ts.map +1 -0
  58. package/dist/consts/index.js +35 -0
  59. package/dist/consts/index.js.map +1 -0
  60. package/dist/context/context.d.ts +123 -0
  61. package/dist/context/context.d.ts.map +1 -0
  62. package/dist/context/context.js +252 -0
  63. package/dist/context/context.js.map +1 -0
  64. package/dist/context/index.d.ts +2 -0
  65. package/dist/context/index.d.ts.map +1 -0
  66. package/dist/context/index.js +2 -0
  67. package/dist/context/index.js.map +1 -0
  68. package/dist/contracts/host-context.d.ts +132 -0
  69. package/dist/contracts/host-context.d.ts.map +1 -0
  70. package/dist/contracts/host-context.js +2 -0
  71. package/dist/contracts/host-context.js.map +1 -0
  72. package/dist/contracts/index.d.ts +8 -0
  73. package/dist/contracts/index.d.ts.map +1 -0
  74. package/dist/contracts/index.js +2 -0
  75. package/dist/contracts/index.js.map +1 -0
  76. package/dist/contracts/lifecycle.d.ts +49 -0
  77. package/dist/contracts/lifecycle.d.ts.map +1 -0
  78. package/dist/contracts/lifecycle.js +2 -0
  79. package/dist/contracts/lifecycle.js.map +1 -0
  80. package/dist/contracts/module-manifest.d.ts +110 -0
  81. package/dist/contracts/module-manifest.d.ts.map +1 -0
  82. package/dist/contracts/module-manifest.js +317 -0
  83. package/dist/contracts/module-manifest.js.map +1 -0
  84. package/dist/contracts/navigation.d.ts +36 -0
  85. package/dist/contracts/navigation.d.ts.map +1 -0
  86. package/dist/contracts/navigation.js +11 -0
  87. package/dist/contracts/navigation.js.map +1 -0
  88. package/dist/contracts/permission.d.ts +8 -0
  89. package/dist/contracts/permission.d.ts.map +1 -0
  90. package/dist/contracts/permission.js +14 -0
  91. package/dist/contracts/permission.js.map +1 -0
  92. package/dist/contracts/post-message.d.ts +124 -0
  93. package/dist/contracts/post-message.d.ts.map +1 -0
  94. package/dist/contracts/post-message.js +2 -0
  95. package/dist/contracts/post-message.js.map +1 -0
  96. package/dist/contracts/route.d.ts +45 -0
  97. package/dist/contracts/route.d.ts.map +1 -0
  98. package/dist/contracts/route.js +35 -0
  99. package/dist/contracts/route.js.map +1 -0
  100. package/dist/events/events.d.ts +191 -0
  101. package/dist/events/events.d.ts.map +1 -0
  102. package/dist/events/events.js +486 -0
  103. package/dist/events/events.js.map +1 -0
  104. package/dist/events/index.d.ts +2 -0
  105. package/dist/events/index.d.ts.map +1 -0
  106. package/dist/events/index.js +2 -0
  107. package/dist/events/index.js.map +1 -0
  108. package/dist/files/files.d.ts +138 -0
  109. package/dist/files/files.d.ts.map +1 -0
  110. package/dist/files/files.js +144 -0
  111. package/dist/files/files.js.map +1 -0
  112. package/dist/files/index.d.ts +2 -0
  113. package/dist/files/index.d.ts.map +1 -0
  114. package/dist/files/index.js +2 -0
  115. package/dist/files/index.js.map +1 -0
  116. package/dist/formatters/index.d.ts +44 -0
  117. package/dist/formatters/index.d.ts.map +1 -0
  118. package/dist/formatters/index.js +50 -0
  119. package/dist/formatters/index.js.map +1 -0
  120. package/dist/i18n/default-translator.d.ts +17 -0
  121. package/dist/i18n/default-translator.d.ts.map +1 -0
  122. package/dist/i18n/default-translator.js +19 -0
  123. package/dist/i18n/default-translator.js.map +1 -0
  124. package/dist/i18n/i18n.d.ts +248 -0
  125. package/dist/i18n/i18n.d.ts.map +1 -0
  126. package/dist/i18n/i18n.js +617 -0
  127. package/dist/i18n/i18n.js.map +1 -0
  128. package/dist/i18n/index.d.ts +2 -0
  129. package/dist/i18n/index.d.ts.map +1 -0
  130. package/dist/i18n/index.js +2 -0
  131. package/dist/i18n/index.js.map +1 -0
  132. package/dist/index.d.ts +19 -0
  133. package/dist/index.d.ts.map +1 -0
  134. package/dist/index.js +19 -0
  135. package/dist/index.js.map +1 -0
  136. package/dist/models/index.d.ts +2 -0
  137. package/dist/models/index.d.ts.map +1 -0
  138. package/dist/models/index.js +2 -0
  139. package/dist/models/index.js.map +1 -0
  140. package/dist/permissions/index.d.ts +2 -0
  141. package/dist/permissions/index.d.ts.map +1 -0
  142. package/dist/permissions/index.js +2 -0
  143. package/dist/permissions/index.js.map +1 -0
  144. package/dist/permissions/permissions.d.ts +67 -0
  145. package/dist/permissions/permissions.d.ts.map +1 -0
  146. package/dist/permissions/permissions.js +123 -0
  147. package/dist/permissions/permissions.js.map +1 -0
  148. package/dist/runtime/direct-host-bridge.d.ts +11 -0
  149. package/dist/runtime/direct-host-bridge.d.ts.map +1 -0
  150. package/dist/runtime/direct-host-bridge.js +299 -0
  151. package/dist/runtime/direct-host-bridge.js.map +1 -0
  152. package/dist/runtime/index.d.ts +5 -0
  153. package/dist/runtime/index.d.ts.map +1 -0
  154. package/dist/runtime/index.js +3 -0
  155. package/dist/runtime/index.js.map +1 -0
  156. package/dist/runtime/post-message-bridge.d.ts +20 -0
  157. package/dist/runtime/post-message-bridge.d.ts.map +1 -0
  158. package/dist/runtime/post-message-bridge.js +1115 -0
  159. package/dist/runtime/post-message-bridge.js.map +1 -0
  160. package/dist/sdk.d.ts +177 -0
  161. package/dist/sdk.d.ts.map +1 -0
  162. package/dist/sdk.js +214 -0
  163. package/dist/sdk.js.map +1 -0
  164. package/dist/storage/index.d.ts +2 -0
  165. package/dist/storage/index.d.ts.map +1 -0
  166. package/dist/storage/index.js +2 -0
  167. package/dist/storage/index.js.map +1 -0
  168. package/dist/storage/storage.d.ts +246 -0
  169. package/dist/storage/storage.d.ts.map +1 -0
  170. package/dist/storage/storage.js +358 -0
  171. package/dist/storage/storage.js.map +1 -0
  172. package/dist/types/api.d.ts +82 -0
  173. package/dist/types/api.d.ts.map +1 -0
  174. package/dist/types/api.js +2 -0
  175. package/dist/types/api.js.map +1 -0
  176. package/dist/types/appearance.d.ts +85 -0
  177. package/dist/types/appearance.d.ts.map +1 -0
  178. package/dist/types/appearance.js +48 -0
  179. package/dist/types/appearance.js.map +1 -0
  180. package/dist/types/config.d.ts +49 -0
  181. package/dist/types/config.d.ts.map +1 -0
  182. package/dist/types/config.js +2 -0
  183. package/dist/types/config.js.map +1 -0
  184. package/dist/types/context.d.ts +41 -0
  185. package/dist/types/context.d.ts.map +1 -0
  186. package/dist/types/context.js +2 -0
  187. package/dist/types/context.js.map +1 -0
  188. package/dist/types/file.d.ts +48 -0
  189. package/dist/types/file.d.ts.map +1 -0
  190. package/dist/types/file.js +2 -0
  191. package/dist/types/file.js.map +1 -0
  192. package/dist/types/index.d.ts +12 -0
  193. package/dist/types/index.d.ts.map +1 -0
  194. package/dist/types/index.js +12 -0
  195. package/dist/types/index.js.map +1 -0
  196. package/dist/types/organization.d.ts +56 -0
  197. package/dist/types/organization.d.ts.map +1 -0
  198. package/dist/types/organization.js +2 -0
  199. package/dist/types/organization.js.map +1 -0
  200. package/dist/types/pagination.d.ts +55 -0
  201. package/dist/types/pagination.d.ts.map +1 -0
  202. package/dist/types/pagination.js +13 -0
  203. package/dist/types/pagination.js.map +1 -0
  204. package/dist/types/permissions.d.ts +26 -0
  205. package/dist/types/permissions.d.ts.map +1 -0
  206. package/dist/types/permissions.js +2 -0
  207. package/dist/types/permissions.js.map +1 -0
  208. package/dist/types/space.d.ts +43 -0
  209. package/dist/types/space.d.ts.map +1 -0
  210. package/dist/types/space.js +2 -0
  211. package/dist/types/space.js.map +1 -0
  212. package/dist/types/tenant.d.ts +31 -0
  213. package/dist/types/tenant.d.ts.map +1 -0
  214. package/dist/types/tenant.js +2 -0
  215. package/dist/types/tenant.js.map +1 -0
  216. package/dist/types/user.d.ts +48 -0
  217. package/dist/types/user.d.ts.map +1 -0
  218. package/dist/types/user.js +2 -0
  219. package/dist/types/user.js.map +1 -0
  220. package/dist/utils/date.d.ts +9 -0
  221. package/dist/utils/date.d.ts.map +1 -0
  222. package/dist/utils/date.js +11 -0
  223. package/dist/utils/date.js.map +1 -0
  224. package/dist/utils/index.d.ts +5 -0
  225. package/dist/utils/index.d.ts.map +1 -0
  226. package/dist/utils/index.js +5 -0
  227. package/dist/utils/index.js.map +1 -0
  228. package/dist/utils/number.d.ts +11 -0
  229. package/dist/utils/number.d.ts.map +1 -0
  230. package/dist/utils/number.js +13 -0
  231. package/dist/utils/number.js.map +1 -0
  232. package/dist/utils/object.d.ts +9 -0
  233. package/dist/utils/object.d.ts.map +1 -0
  234. package/dist/utils/object.js +11 -0
  235. package/dist/utils/object.js.map +1 -0
  236. package/dist/utils/string.d.ts +9 -0
  237. package/dist/utils/string.d.ts.map +1 -0
  238. package/dist/utils/string.js +11 -0
  239. package/dist/utils/string.js.map +1 -0
  240. package/dist/validators/index.d.ts +8 -0
  241. package/dist/validators/index.d.ts.map +1 -0
  242. package/dist/validators/index.js +8 -0
  243. package/dist/validators/index.js.map +1 -0
  244. package/package.json +156 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ https://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,7 @@
1
+ Miaixz SDK
2
+
3
+ Copyright (c) 2015-2026 miaixz.org and other contributors.
4
+
5
+ This product includes software developed by
6
+ The Miaixz Team (https://www.miaixz.org).
7
+
package/README.md ADDED
@@ -0,0 +1,412 @@
1
+ # @miaixz/sdk
2
+
3
+ `@miaixz/sdk` 是仅支持 ESM 的 npm 包,不提供 CommonJS `require` 入口。消费端必须使用标准 ESM `import`。
4
+
5
+ Miaixz 官方浏览器 SDK。用于不同部署位置的首页、空间、设置等前端服务,共享统一的 API 协议、认证、运行上下文、配置、权限、事件、文件、外观和国际化能力。
6
+
7
+ SDK 不包含运行时第三方依赖,可使用 npm 独立构建和发布。
8
+
9
+ 当前 `0.5.x` 建设阶段使用 Host Bridge 协议 `1.0.0`。完整的版本、浏览器与废弃策略见 [SUPPORT.md](./SUPPORT.md)。
10
+
11
+ ## 安装
12
+
13
+ ```bash
14
+ npm install @miaixz/sdk
15
+ ```
16
+
17
+ ## 一次性初始化
18
+
19
+ ```ts
20
+ import { createMiaixzSdk } from "@miaixz/sdk";
21
+
22
+ const sdk = createMiaixzSdk({
23
+ appId: "portal",
24
+ config: {
25
+ apiBaseUrl: "https://api.miaixz.example",
26
+ environment: "production",
27
+ services: { space: "https://space-api.miaixz.example" },
28
+ },
29
+ csrfTokenProvider: () =>
30
+ document.querySelector<HTMLMetaElement>('meta[name="csrf-token"]')?.content,
31
+ locale: "zh-CN",
32
+ });
33
+
34
+ await sdk.ready;
35
+ sdk.context.set({
36
+ tenantId: "tenant-1",
37
+ spaceId: "space-1",
38
+ locale: "zh-CN",
39
+ });
40
+ ```
41
+
42
+ 租户是数据与安全隔离边界,SDK 通过 `X-Miaixz-Tenant-Id` 请求头传递 `tenantId`。空间等运行上下文同样通过请求头传递,不要求使用 `/spaces/:spaceId` 一类路径参数。
43
+
44
+ `organizationId` 仅表示当前租户内部选中的组织实体,不得代替 `tenantId` 承担租户隔离。部门、岗位与职称等组织架构仍属于 organization 领域。
45
+
46
+ `context.set()` 会替换完整上下文,局部更新请使用 `context.patch()`。即使完整替换时未传入 `locale`,组合式 SDK 仍会把当前国际化语言写入请求头。
47
+
48
+ 认证默认使用 Cookie/BFF 模式:请求会传递 `credentials: "include"`,SDK 不读取 HttpOnly Cookie、不创建 Token Session,也不附加 `Authorization` Header。`POST`、`PUT`、`PATCH`、`DELETE` 还必须由 `csrfTokenProvider` 提供非空 Token;SDK 会忽略消费方和请求拦截器写入的同名值,只把 Provider 返回值写入 `X-CSRF-Token`。`GET`、`HEAD`、`OPTIONS` 不读取 Provider,也不会附加该 Header。
49
+
50
+ 需要 Bearer 模式时必须显式声明 `authMode: "bearer"`。认证会话默认只保存在当前 SDK 实例内存中,刷新页面后不会保留:
51
+
52
+ ```ts
53
+ const sdk = createMiaixzSdk({
54
+ appId: "portal",
55
+ authMode: "bearer",
56
+ config,
57
+ });
58
+
59
+ sdk.auth.setSession({
60
+ accessToken: "token",
61
+ tokenType: "DP-Token",
62
+ });
63
+ ```
64
+
65
+ 仅在明确接受 Web Storage 可能受脚本注入窃取的风险时,才可通过唯一工厂启用持久化。优先使用默认内存模式或 HttpOnly Cookie/BFF:
66
+
67
+ ```ts
68
+ import { createMiaixzPersistentAuthStorage, createMiaixzSdk } from "@miaixz/sdk";
69
+
70
+ const authPersistence = createMiaixzPersistentAuthStorage(window.sessionStorage, {
71
+ acknowledgeWebStorageRisk: true,
72
+ });
73
+
74
+ const sdk = createMiaixzSdk({
75
+ appId: "portal",
76
+ authMode: "bearer",
77
+ authPersistence,
78
+ config,
79
+ });
80
+ ```
81
+
82
+ ## API 返回协议
83
+
84
+ 所有 JSON API 默认必须返回统一结构:
85
+
86
+ ```json
87
+ {
88
+ "errcode": "0",
89
+ "errmsg": "success",
90
+ "data": {}
91
+ }
92
+ ```
93
+
94
+ - `String(errcode) === "0"`:请求成功,SDK 自动返回内部 `data`。
95
+ - `errcode !== "0"`:即使 HTTP 状态是 `200`,也会抛出 `MiaixzApiError`。
96
+ - JSON 响应缺少 `errcode`、`errmsg` 或 `data`:抛出代码为 `API_ENVELOPE_INVALID` 的错误。
97
+ - 文本、Blob、ArrayBuffer 和空响应不要求使用该结构。
98
+
99
+ ```ts
100
+ interface Space {
101
+ id: string;
102
+ name: string;
103
+ }
104
+
105
+ const response = await sdk.api.get<Space>("/space/current");
106
+
107
+ // 已经是 data,不需要 response.data.data
108
+ console.log(response.data.name);
109
+ ```
110
+
111
+ 特殊接口可显式设置 `envelope: "optional"`,兼容有无返回包的 JSON;设置 `envelope: "none"` 时保留原始 JSON。业务 API 应保持默认的 `required`。
112
+
113
+ ## 项目多语言文件
114
+
115
+ SDK 内只保留基础错误文案。各项目或微服务通过自己的语言文件扩展和覆盖文案,并可按语言懒加载。
116
+
117
+ ```ts
118
+ // src/locales/zh-CN.ts
119
+ import type { MiaixzMessages } from "@miaixz/sdk/i18n";
120
+
121
+ export default {
122
+ "space.error.notFound": "未找到空间",
123
+ "sdk.error.network": "当前网络不可用,请稍后重试",
124
+ } satisfies MiaixzMessages;
125
+ ```
126
+
127
+ ```ts
128
+ import { createMiaixzMessageLoader, createMiaixzSdk } from "@miaixz/sdk";
129
+
130
+ const loadMessages = createMiaixzMessageLoader({
131
+ space: {
132
+ "zh-CN": () => import("./locales/zh-CN.js"),
133
+ "en-US": () => import("./locales/en-US.js"),
134
+ },
135
+ });
136
+
137
+ const sdk = createMiaixzSdk({
138
+ appId: "portal",
139
+ config,
140
+ locale: "zh-CN",
141
+ fallbackLocale: "en-US",
142
+ loadMessages,
143
+ onI18nLoadError(error) {
144
+ // 交由项目自己的日志或错误界面处理
145
+ reportError(error);
146
+ },
147
+ });
148
+
149
+ await sdk.ready;
150
+ console.log(sdk.i18n.t("space.error.notFound"));
151
+
152
+ // 切换前自动加载并缓存对应项目语言文件
153
+ await sdk.i18n.changeLocale("en-US");
154
+ ```
155
+
156
+ 也可在初始化时通过 `messages` 直接传入已静态导入的语言目录。项目文案优先级高于 SDK 内置文案;当前语言缺失时回退到 `fallbackLocale`,仍缺失时返回消息键。
157
+
158
+ 后端业务错误可使用 `api.error.<errcode>` 作为项目语言键,例如 `api.error.SPACE_FORBIDDEN`。存在该键时 SDK 使用项目译文;不存在时回退到接口返回的 `errmsg`。
159
+
160
+ ## 外观、主题与密度
161
+
162
+ SDK 是跨服务外观状态的唯一权威来源,负责校验、按应用和租户隔离持久化并发布变化;DOM 写入由 `@miaixz/ui` 完成:
163
+
164
+ ```ts
165
+ import { createMiaixzSdk } from "@miaixz/sdk";
166
+ import { applyMiaixzAppearance } from "@miaixz/ui/appearance";
167
+
168
+ const sdk = createMiaixzSdk({ appId: "portal", config });
169
+
170
+ applyMiaixzAppearance(sdk.appearance.getSnapshot());
171
+ const stopAppearance = sdk.appearance.subscribe((appearance) => {
172
+ applyMiaixzAppearance(appearance);
173
+ });
174
+
175
+ sdk.appearance.patch({
176
+ colorMode: "dark",
177
+ density: "compact",
178
+ colors: { brand: "#55b52d" },
179
+ });
180
+
181
+ stopAppearance();
182
+ sdk.destroy();
183
+ ```
184
+
185
+ 支持 `light`、`dark`、`system` 三种颜色偏好和 `compact`、`standard`、`comfortable` 三档密度。所有自定义语义颜色会在提交前完成格式与对比度校验;无效设置不会部分写入。
186
+
187
+ ## 独立服务 API
188
+
189
+ ```ts
190
+ const spaceApi = sdk.createServiceClient("space");
191
+ const spaces = await spaceApi.get<readonly Space[]>("/spaces");
192
+ ```
193
+
194
+ 服务端点由配置统一下发,各前端服务无需硬编码部署地址。
195
+
196
+ 主端点和服务端点必须是绝对 URL。production、staging 只允许 HTTPS;development、test 仅额外允许 `localhost`、`127.0.0.1`、`[::1]` 的 HTTP 地址。端点不能包含用户信息、查询参数或片段。
197
+
198
+ 单次请求只接受相对路径或以 `/` 开头的同源路径,禁止传入绝对 URL 或 `//host`。跨服务调用必须先创建对应服务客户端;认证、Cookie、CSRF 或运行上下文请求固定使用 `redirect: "error"`,请求拦截器不能改写该安全策略或把请求转发到其他来源。
199
+
200
+ ```ts
201
+ import { createApiClient } from "@miaixz/sdk/api";
202
+
203
+ const publicApi = createApiClient({
204
+ baseUrl: "https://public-api.miaixz.example",
205
+ environment: "production",
206
+ });
207
+
208
+ await publicApi.get("/health", {
209
+ authenticate: false,
210
+ includeContext: false,
211
+ });
212
+ ```
213
+
214
+ 调用 `sdk.config.set(nextConfig)` 后,主 API 客户端与文件客户端会自动切换到新地址和超时配置;后续创建的服务客户端也会读取最新配置。
215
+
216
+ ## 错误处理
217
+
218
+ SDK 不抛出裸字符串。请求失败会保留稳定类型、机器码和安全诊断字段,消费项目应先处理可恢复分支,再把消息键交给国际化运行时:
219
+
220
+ ```ts
221
+ import {
222
+ isMiaixzApiError,
223
+ MiaixzAbortError,
224
+ MiaixzNetworkError,
225
+ MiaixzTimeoutError,
226
+ } from "@miaixz/sdk/errors";
227
+
228
+ try {
229
+ await sdk.api.get("/spaces");
230
+ } catch (error) {
231
+ if (error instanceof MiaixzAbortError) return;
232
+ if (error instanceof MiaixzTimeoutError || error instanceof MiaixzNetworkError) {
233
+ showRetryMessage(error.message);
234
+ return;
235
+ }
236
+ if (isMiaixzApiError(error)) {
237
+ showApiMessage({ code: error.code, message: error.message, retryable: error.retryable });
238
+ return;
239
+ }
240
+ throw error;
241
+ }
242
+ ```
243
+
244
+ 日志与遥测中禁止记录 Token、Cookie、授权头、CSRF、个人信息、请求正文或文件内容。前端错误只辅助交互,服务端仍须执行鉴权和输入校验。
245
+
246
+ ## 权限
247
+
248
+ ```ts
249
+ sdk.setPermissions({
250
+ allowed: ["space:*", "organization:read"],
251
+ denied: ["space:delete"],
252
+ roles: ["member"],
253
+ });
254
+
255
+ sdk.permissions.can("space:read");
256
+ sdk.permissions.canAll(["space:read", "organization:read"]);
257
+ ```
258
+
259
+ 前端权限只用于界面和交互控制,不能替代后端鉴权。
260
+
261
+ ## 本地与跨标签事件
262
+
263
+ SDK 事件默认只在当前实例内同步分发,不会创建 `BroadcastChannel`。需要同源跨标签同步时,由组合入口根据 `appId` 生成唯一的版本化频道名:
264
+
265
+ ```ts
266
+ const sdk = createMiaixzSdk({
267
+ appId: "portal",
268
+ config,
269
+ eventChannel: true,
270
+ });
271
+
272
+ const stop = sdk.events.on("locale:changed", ({ locale }) => {
273
+ console.log(locale);
274
+ });
275
+
276
+ stop();
277
+ ```
278
+
279
+ 内置的认证、上下文、外观、语言和配置事件均具有不可覆盖的运行时校验器。认证事件只传递 `authenticated` 或 `anonymous` 状态,禁止传递 Session、Token、Cookie 或授权头。
280
+
281
+ 应用自定义事件默认也可在本实例内使用;跨标签发送前必须提供对应运行时校验器。直接创建事件总线时,频道名必须采用 `miaixz:v1:<appId>:events`:
282
+
283
+ ```ts
284
+ import { createMiaixzEventBus } from "@miaixz/sdk/events";
285
+
286
+ interface PortalEvents {
287
+ "portal:ready": Readonly<{ ready: boolean }>;
288
+ }
289
+
290
+ const events = createMiaixzEventBus<PortalEvents>({
291
+ channelName: "miaixz:v1:portal:events",
292
+ validators: {
293
+ "portal:ready": (payload) =>
294
+ typeof payload === "object" &&
295
+ payload !== null &&
296
+ "ready" in payload &&
297
+ typeof payload.ready === "boolean",
298
+ },
299
+ });
300
+ ```
301
+
302
+ ## 稳定子路径
303
+
304
+ ```ts
305
+ import { createApiClient } from "@miaixz/sdk/api";
306
+ import { createMiaixzI18n } from "@miaixz/sdk/i18n";
307
+ import type { MiaixzSpace } from "@miaixz/sdk/types";
308
+ import { formatMiaixzBytes } from "@miaixz/sdk/formatters";
309
+ ```
310
+
311
+ 已发布子路径包括 `api`、`auth`、`context`、`config`、`contracts`、`permissions`、`events`、`storage`、`appearance`、`files`、`i18n`、`sdk`、`consts`、`errors`、`formatters`、`models`、`types`、`utils` 和 `validators`。
312
+
313
+ ## 微前端模块清单
314
+
315
+ 独立部署的模块只需依赖 `@miaixz/sdk`,即可声明和校验纯 JSON 清单:
316
+
317
+ ```ts
318
+ import {
319
+ MIAIXZ_MODULE_PROTOCOL_VERSION,
320
+ parseMiaixzModuleManifest,
321
+ type MiaixzIntegratedModule,
322
+ type MiaixzModuleManifest,
323
+ } from "@miaixz/sdk/contracts";
324
+
325
+ const manifest = {
326
+ protocolVersion: MIAIXZ_MODULE_PROTOCOL_VERSION,
327
+ id: "spaces-console",
328
+ version: "1.2.0",
329
+ hostVersion: "^1.0.0",
330
+ kind: "integrated",
331
+ basePath: "/spaces",
332
+ entry: "@miaixz/spaces",
333
+ routes: [
334
+ {
335
+ id: "spaces-home",
336
+ path: "/",
337
+ titleKey: "spaces.route.home",
338
+ requiredPermissions: ["spaces:workspace:read"],
339
+ },
340
+ ],
341
+ navigation: [
342
+ {
343
+ id: "spaces-navigation",
344
+ routeId: "spaces-home",
345
+ labelKey: "spaces.navigation.home",
346
+ order: 10,
347
+ },
348
+ ],
349
+ requiredPermissions: ["spaces:workspace:read"],
350
+ requiredCapabilities: ["context", "navigation", "permissions"],
351
+ } satisfies MiaixzModuleManifest;
352
+
353
+ const verifiedManifest = parseMiaixzModuleManifest(manifest, {
354
+ environment: "production",
355
+ hostVersion: "1.3.0",
356
+ });
357
+
358
+ export const module: MiaixzIntegratedModule = {
359
+ mount({ container }) {
360
+ container.textContent = verifiedManifest.id;
361
+ return {
362
+ unmount() {
363
+ container.replaceChildren();
364
+ },
365
+ };
366
+ },
367
+ };
368
+ ```
369
+
370
+ 同运行时模块使用 `createMiaixzDirectHostBridge()`。跨域 iframe 必须在两端使用精确 origin,并分别创建 Host 与 Child Bridge;禁止使用 `"*"`:
371
+
372
+ ```ts
373
+ import { createMiaixzDirectHostBridge } from "@miaixz/sdk/runtime";
374
+
375
+ const bridge = createMiaixzDirectHostBridge({
376
+ moduleId: "spaces-console",
377
+ adapter: {
378
+ getContext: async () => sdk.context.getSnapshot(),
379
+ hasPermissions: async (permissions) => sdk.permissions.canAll(permissions),
380
+ },
381
+ });
382
+
383
+ const context = await bridge.getContext();
384
+ bridge.dispose();
385
+ ```
386
+
387
+ 模块不得通过共享全局变量或直接读取宿主 DOM 获取上下文。完整可编译示例见 [仓库测试示例目录](https://github.com/818000/miaixz.js/tree/main/sdk/tests/examples)。
388
+
389
+ ## 本地开发
390
+
391
+ ```bash
392
+ npm install
393
+ npm run check
394
+ npm test
395
+ npm run test:consumer
396
+ npm run test:size
397
+ npm run api:check
398
+ npm run pack:check
399
+ ```
400
+
401
+ 发布由仓库的 `Release Vendor Package` 工作流统一执行。默认 `dry-run` 只生成可审计构件,不发布到 npm;`next` 和 `latest` 必须从对应受保护 Tag 启动,并通过 `npm-production` 环境人工批准。正式发布使用 npm Trusted Publishing/OIDC,不配置长期 npm Token。
402
+
403
+ ## 治理文档
404
+
405
+ - [CHANGELOG.md](./CHANGELOG.md):版本变化。
406
+ - [MIGRATION.md](./MIGRATION.md):迁移步骤。
407
+ - [SECURITY.md](./SECURITY.md):漏洞报告与安全边界。
408
+ - [SUPPORT.md](./SUPPORT.md):兼容、浏览器与废弃周期。
409
+
410
+ ## License
411
+
412
+ Apache-2.0