@cloudbase/oauth 0.1.1-alpha → 0.1.1-alpha.2

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 (332) hide show
  1. package/Dockerfile +15 -0
  2. package/README.md +1 -1
  3. package/_exmaple/assets/scripts/function/function.ts +99 -0
  4. package/_exmaple/assets/scripts/index.ts +99 -0
  5. package/_exmaple/assets/scripts/request.ts +11 -0
  6. package/_exmaple/index.html +15 -0
  7. package/_exmaple/package.json +33 -0
  8. package/_exmaple/tsconfig.json +71 -0
  9. package/_exmaple/typings.d.ts +0 -0
  10. package/_exmaple/webpack.config.js +42 -0
  11. package/cdnjs/1.0.0/cloudbase.auth.js +1 -0
  12. package/cdnjs/1.0.0/cloudbase.database.js +8 -0
  13. package/cdnjs/1.0.0/cloudbase.full.js +8 -0
  14. package/cdnjs/1.0.0/cloudbase.functions.js +1 -0
  15. package/cdnjs/1.0.0/cloudbase.js +1 -0
  16. package/cdnjs/1.0.0/cloudbase.storage.js +1 -0
  17. package/cdnjs/1.0.1/cloudbase.auth.js +1 -0
  18. package/cdnjs/1.0.1/cloudbase.database.js +8 -0
  19. package/cdnjs/1.0.1/cloudbase.full.js +8 -0
  20. package/cdnjs/1.0.1/cloudbase.functions.js +1 -0
  21. package/cdnjs/1.0.1/cloudbase.js +1 -0
  22. package/cdnjs/1.0.1/cloudbase.storage.js +1 -0
  23. package/cdnjs/1.0.2/cloudbase.auth.js +1 -0
  24. package/cdnjs/1.0.2/cloudbase.database.js +8 -0
  25. package/cdnjs/1.0.2/cloudbase.full.js +8 -0
  26. package/cdnjs/1.0.2/cloudbase.functions.js +1 -0
  27. package/cdnjs/1.0.2/cloudbase.js +1 -0
  28. package/cdnjs/1.0.2/cloudbase.storage.js +1 -0
  29. package/cdnjs/1.0.3/cloudbase.auth.js +1 -0
  30. package/cdnjs/1.0.3/cloudbase.database.js +8 -0
  31. package/cdnjs/1.0.3/cloudbase.full.js +8 -0
  32. package/cdnjs/1.0.3/cloudbase.functions.js +1 -0
  33. package/cdnjs/1.0.3/cloudbase.js +1 -0
  34. package/cdnjs/1.0.3/cloudbase.storage.js +1 -0
  35. package/cdnjs/1.0.4/cloudbase.auth.js +1 -0
  36. package/cdnjs/1.0.4/cloudbase.database.js +8 -0
  37. package/cdnjs/1.0.4/cloudbase.full.js +8 -0
  38. package/cdnjs/1.0.4/cloudbase.functions.js +1 -0
  39. package/cdnjs/1.0.4/cloudbase.js +1 -0
  40. package/cdnjs/1.0.4/cloudbase.storage.js +1 -0
  41. package/cdnjs/1.1.0/cloudbase.auth.js +1 -0
  42. package/cdnjs/1.1.0/cloudbase.database.js +8 -0
  43. package/cdnjs/1.1.0/cloudbase.full.js +8 -0
  44. package/cdnjs/1.1.0/cloudbase.functions.js +1 -0
  45. package/cdnjs/1.1.0/cloudbase.js +1 -0
  46. package/cdnjs/1.1.0/cloudbase.storage.js +1 -0
  47. package/cdnjs/1.1.1/cloudbase.auth.js +1 -0
  48. package/cdnjs/1.1.1/cloudbase.database.js +8 -0
  49. package/cdnjs/1.1.1/cloudbase.full.js +8 -0
  50. package/cdnjs/1.1.1/cloudbase.functions.js +1 -0
  51. package/cdnjs/1.1.1/cloudbase.js +1 -0
  52. package/cdnjs/1.1.1/cloudbase.storage.js +1 -0
  53. package/cdnjs/1.1.2/cloudbase.auth.js +1 -0
  54. package/cdnjs/1.1.2/cloudbase.database.js +8 -0
  55. package/cdnjs/1.1.2/cloudbase.full.js +8 -0
  56. package/cdnjs/1.1.2/cloudbase.functions.js +1 -0
  57. package/cdnjs/1.1.2/cloudbase.js +1 -0
  58. package/cdnjs/1.1.2/cloudbase.storage.js +1 -0
  59. package/cdnjs/1.1.3/cloudbase.auth.js +1 -0
  60. package/cdnjs/1.1.3/cloudbase.database.js +8 -0
  61. package/cdnjs/1.1.3/cloudbase.full.js +8 -0
  62. package/cdnjs/1.1.3/cloudbase.functions.js +1 -0
  63. package/cdnjs/1.1.3/cloudbase.js +1 -0
  64. package/cdnjs/1.1.3/cloudbase.storage.js +1 -0
  65. package/cdnjs/1.1.4/cloudbase.auth.js +1 -0
  66. package/cdnjs/1.1.4/cloudbase.database.js +8 -0
  67. package/cdnjs/1.1.4/cloudbase.full.js +8 -0
  68. package/cdnjs/1.1.4/cloudbase.functions.js +1 -0
  69. package/cdnjs/1.1.4/cloudbase.js +1 -0
  70. package/cdnjs/1.1.4/cloudbase.storage.js +1 -0
  71. package/cdnjs/1.2.1/cloudbase.auth.js +1 -0
  72. package/cdnjs/1.2.1/cloudbase.database.js +8 -0
  73. package/cdnjs/1.2.1/cloudbase.full.js +8 -0
  74. package/cdnjs/1.2.1/cloudbase.functions.js +1 -0
  75. package/cdnjs/1.2.1/cloudbase.js +1 -0
  76. package/cdnjs/1.2.1/cloudbase.storage.js +1 -0
  77. package/cdnjs/1.2.2/cloudbase.auth.js +1 -0
  78. package/cdnjs/1.2.2/cloudbase.database.js +8 -0
  79. package/cdnjs/1.2.2/cloudbase.full.js +8 -0
  80. package/cdnjs/1.2.2/cloudbase.functions.js +1 -0
  81. package/cdnjs/1.2.2/cloudbase.js +1 -0
  82. package/cdnjs/1.2.2/cloudbase.storage.js +1 -0
  83. package/cdnjs/1.2.3/cloudbase.auth.js +1 -0
  84. package/cdnjs/1.2.3/cloudbase.database.js +8 -0
  85. package/cdnjs/1.2.3/cloudbase.full.js +8 -0
  86. package/cdnjs/1.2.3/cloudbase.functions.js +1 -0
  87. package/cdnjs/1.2.3/cloudbase.js +1 -0
  88. package/cdnjs/1.2.3/cloudbase.storage.js +1 -0
  89. package/cdnjs/1.3.0/cloudbase.auth.js +1 -0
  90. package/cdnjs/1.3.0/cloudbase.database.js +8 -0
  91. package/cdnjs/1.3.0/cloudbase.full.js +8 -0
  92. package/cdnjs/1.3.0/cloudbase.functions.js +1 -0
  93. package/cdnjs/1.3.0/cloudbase.js +1 -0
  94. package/cdnjs/1.3.0/cloudbase.realtime.js +1 -0
  95. package/cdnjs/1.3.0/cloudbase.storage.js +1 -0
  96. package/cdnjs/1.3.1/cloudbase.auth.js +1 -0
  97. package/cdnjs/1.3.1/cloudbase.database.js +8 -0
  98. package/cdnjs/1.3.1/cloudbase.full.js +8 -0
  99. package/cdnjs/1.3.1/cloudbase.functions.js +1 -0
  100. package/cdnjs/1.3.1/cloudbase.js +1 -0
  101. package/cdnjs/1.3.1/cloudbase.realtime.js +1 -0
  102. package/cdnjs/1.3.1/cloudbase.storage.js +1 -0
  103. package/cdnjs/1.3.2/cloudbase.auth.js +1 -0
  104. package/cdnjs/1.3.2/cloudbase.database.js +8 -0
  105. package/cdnjs/1.3.2/cloudbase.full.js +8 -0
  106. package/cdnjs/1.3.2/cloudbase.functions.js +1 -0
  107. package/cdnjs/1.3.2/cloudbase.js +1 -0
  108. package/cdnjs/1.3.2/cloudbase.realtime.js +1 -0
  109. package/cdnjs/1.3.2/cloudbase.storage.js +1 -0
  110. package/cdnjs/1.3.3/cloudbase.auth.js +1 -0
  111. package/cdnjs/1.3.3/cloudbase.database.js +8 -0
  112. package/cdnjs/1.3.3/cloudbase.full.js +8 -0
  113. package/cdnjs/1.3.3/cloudbase.functions.js +1 -0
  114. package/cdnjs/1.3.3/cloudbase.js +1 -0
  115. package/cdnjs/1.3.3/cloudbase.realtime.js +1 -0
  116. package/cdnjs/1.3.3/cloudbase.storage.js +1 -0
  117. package/cdnjs/1.3.4-alpha.0/cloudbase.auth.js +1 -0
  118. package/cdnjs/1.3.4-alpha.0/cloudbase.database.js +8 -0
  119. package/cdnjs/1.3.4-alpha.0/cloudbase.full.js +8 -0
  120. package/cdnjs/1.3.4-alpha.0/cloudbase.functions.js +1 -0
  121. package/cdnjs/1.3.4-alpha.0/cloudbase.js +1 -0
  122. package/cdnjs/1.3.4-alpha.0/cloudbase.realtime.js +1 -0
  123. package/cdnjs/1.3.4-alpha.0/cloudbase.storage.js +1 -0
  124. package/cdnjs/1.3.5/cloudbase.analytics.js +1 -0
  125. package/cdnjs/1.3.5/cloudbase.auth.js +1 -0
  126. package/cdnjs/1.3.5/cloudbase.database.js +10 -0
  127. package/cdnjs/1.3.5/cloudbase.full.js +10 -0
  128. package/cdnjs/1.3.5/cloudbase.functions.js +1 -0
  129. package/cdnjs/1.3.5/cloudbase.js +1 -0
  130. package/cdnjs/1.3.5/cloudbase.realtime.js +1 -0
  131. package/cdnjs/1.3.5/cloudbase.storage.js +1 -0
  132. package/cdnjs/1.3.5-alpha.0/cloudbase.auth.js +1 -0
  133. package/cdnjs/1.3.5-alpha.0/cloudbase.database.js +10 -0
  134. package/cdnjs/1.3.5-alpha.0/cloudbase.full.js +10 -0
  135. package/cdnjs/1.3.5-alpha.0/cloudbase.functions.js +1 -0
  136. package/cdnjs/1.3.5-alpha.0/cloudbase.js +1 -0
  137. package/cdnjs/1.3.5-alpha.0/cloudbase.realtime.js +1 -0
  138. package/cdnjs/1.3.5-alpha.0/cloudbase.storage.js +1 -0
  139. package/cdnjs/1.4.0/cloudbase.analytics.js +1 -0
  140. package/cdnjs/1.4.0/cloudbase.auth.js +1 -0
  141. package/cdnjs/1.4.0/cloudbase.database.js +10 -0
  142. package/cdnjs/1.4.0/cloudbase.full.js +10 -0
  143. package/cdnjs/1.4.0/cloudbase.functions.js +1 -0
  144. package/cdnjs/1.4.0/cloudbase.js +1 -0
  145. package/cdnjs/1.4.0/cloudbase.realtime.js +1 -0
  146. package/cdnjs/1.4.0/cloudbase.storage.js +1 -0
  147. package/cdnjs/1.4.1/cloudbase.analytics.js +1 -0
  148. package/cdnjs/1.4.1/cloudbase.auth.js +1 -0
  149. package/cdnjs/1.4.1/cloudbase.database.js +10 -0
  150. package/cdnjs/1.4.1/cloudbase.full.js +10 -0
  151. package/cdnjs/1.4.1/cloudbase.functions.js +1 -0
  152. package/cdnjs/1.4.1/cloudbase.js +1 -0
  153. package/cdnjs/1.4.1/cloudbase.realtime.js +1 -0
  154. package/cdnjs/1.4.1/cloudbase.storage.js +1 -0
  155. package/cdnjs/1.4.1-alpha.0/cloudbase.analytics.js +1 -0
  156. package/cdnjs/1.4.1-alpha.0/cloudbase.auth.js +1 -0
  157. package/cdnjs/1.4.1-alpha.0/cloudbase.database.js +10 -0
  158. package/cdnjs/1.4.1-alpha.0/cloudbase.full.js +10 -0
  159. package/cdnjs/1.4.1-alpha.0/cloudbase.functions.js +1 -0
  160. package/cdnjs/1.4.1-alpha.0/cloudbase.js +1 -0
  161. package/cdnjs/1.4.1-alpha.0/cloudbase.realtime.js +1 -0
  162. package/cdnjs/1.4.1-alpha.0/cloudbase.storage.js +1 -0
  163. package/cdnjs/1.4.2-alpha.0/cloudbase.analytics.js +1 -0
  164. package/cdnjs/1.4.2-alpha.0/cloudbase.auth.js +1 -0
  165. package/cdnjs/1.4.2-alpha.0/cloudbase.database.js +10 -0
  166. package/cdnjs/1.4.2-alpha.0/cloudbase.full.js +10 -0
  167. package/cdnjs/1.4.2-alpha.0/cloudbase.functions.js +1 -0
  168. package/cdnjs/1.4.2-alpha.0/cloudbase.js +1 -0
  169. package/cdnjs/1.4.2-alpha.0/cloudbase.realtime.js +1 -0
  170. package/cdnjs/1.4.2-alpha.0/cloudbase.storage.js +1 -0
  171. package/cdnjs/1.5.0/cloudbase.analytics.js +1 -0
  172. package/cdnjs/1.5.0/cloudbase.auth.js +1 -0
  173. package/cdnjs/1.5.0/cloudbase.database.js +10 -0
  174. package/cdnjs/1.5.0/cloudbase.full.js +10 -0
  175. package/cdnjs/1.5.0/cloudbase.functions.js +1 -0
  176. package/cdnjs/1.5.0/cloudbase.js +1 -0
  177. package/cdnjs/1.5.0/cloudbase.realtime.js +1 -0
  178. package/cdnjs/1.5.0/cloudbase.storage.js +1 -0
  179. package/cdnjs/1.5.1/cloudbase.analytics.js +1 -0
  180. package/cdnjs/1.5.1/cloudbase.auth.js +1 -0
  181. package/cdnjs/1.5.1/cloudbase.database.js +26 -0
  182. package/cdnjs/1.5.1/cloudbase.full.js +26 -0
  183. package/cdnjs/1.5.1/cloudbase.functions.js +1 -0
  184. package/cdnjs/1.5.1/cloudbase.js +1 -0
  185. package/cdnjs/1.5.1/cloudbase.realtime.js +1 -0
  186. package/cdnjs/1.5.1/cloudbase.storage.js +1 -0
  187. package/cdnjs/1.5.1-alpha.0/cloudbase.analytics.js +1 -0
  188. package/cdnjs/1.5.1-alpha.0/cloudbase.auth.js +1 -0
  189. package/cdnjs/1.5.1-alpha.0/cloudbase.database.js +10 -0
  190. package/cdnjs/1.5.1-alpha.0/cloudbase.full.js +10 -0
  191. package/cdnjs/1.5.1-alpha.0/cloudbase.functions.js +1 -0
  192. package/cdnjs/1.5.1-alpha.0/cloudbase.js +1 -0
  193. package/cdnjs/1.5.1-alpha.0/cloudbase.realtime.js +1 -0
  194. package/cdnjs/1.5.1-alpha.0/cloudbase.storage.js +1 -0
  195. package/cdnjs/1.5.3-alpha.0/cloudbase.analytics.js +1 -0
  196. package/cdnjs/1.5.3-alpha.0/cloudbase.auth.js +1 -0
  197. package/cdnjs/1.5.3-alpha.0/cloudbase.database.js +26 -0
  198. package/cdnjs/1.5.3-alpha.0/cloudbase.full.js +26 -0
  199. package/cdnjs/1.5.3-alpha.0/cloudbase.functions.js +1 -0
  200. package/cdnjs/1.5.3-alpha.0/cloudbase.js +1 -0
  201. package/cdnjs/1.5.3-alpha.0/cloudbase.realtime.js +1 -0
  202. package/cdnjs/1.5.3-alpha.0/cloudbase.storage.js +1 -0
  203. package/cdnjs/1.6.0/cloudbase.analytics.js +1 -0
  204. package/cdnjs/1.6.0/cloudbase.auth.js +1 -0
  205. package/cdnjs/1.6.0/cloudbase.database.js +26 -0
  206. package/cdnjs/1.6.0/cloudbase.full.js +26 -0
  207. package/cdnjs/1.6.0/cloudbase.functions.js +1 -0
  208. package/cdnjs/1.6.0/cloudbase.js +1 -0
  209. package/cdnjs/1.6.0/cloudbase.realtime.js +1 -0
  210. package/cdnjs/1.6.0/cloudbase.storage.js +1 -0
  211. package/{CHANGELOG.md → changelog.md} +0 -0
  212. package/dist/README.md +153 -0
  213. package/{app → dist/app}/index.d.ts +1 -0
  214. package/{app → dist/app}/index.js +0 -0
  215. package/dist/app/index.js.map +1 -0
  216. package/{app → dist/app}/internal.d.ts +0 -0
  217. package/{app → dist/app}/internal.js +0 -0
  218. package/{app → dist/app}/internal.js.map +0 -0
  219. package/{app → dist/app}/openuri.d.ts +0 -0
  220. package/{app → dist/app}/openuri.js +2 -1
  221. package/{app → dist/app}/openuri.js.map +1 -1
  222. package/{app → dist/app}/request.d.ts +4 -3
  223. package/{app → dist/app}/request.js +20 -12
  224. package/dist/app/request.js.map +1 -0
  225. package/{app → dist/app}/storage.d.ts +0 -0
  226. package/{app → dist/app}/storage.js +0 -0
  227. package/{app → dist/app}/storage.js.map +0 -0
  228. package/{auth → dist/auth}/consts.d.ts +21 -4
  229. package/{auth → dist/auth}/consts.js +27 -5
  230. package/dist/auth/consts.js.map +1 -0
  231. package/{auth → dist/auth}/index.d.ts +83 -34
  232. package/{auth → dist/auth}/index.js +239 -92
  233. package/dist/auth/index.js.map +1 -0
  234. package/dist/auth/models.d.ts +284 -0
  235. package/{oauthclient → dist/auth}/models.js +1 -0
  236. package/dist/auth/models.js.map +1 -0
  237. package/{captcha → dist/captcha}/index.d.ts +0 -0
  238. package/{captcha → dist/captcha}/index.js +4 -2
  239. package/dist/captcha/index.js.map +1 -0
  240. package/dist/changelog.md +30 -0
  241. package/dist/function/index.d.ts +38 -0
  242. package/dist/function/index.js +80 -0
  243. package/dist/function/index.js.map +1 -0
  244. package/dist/index.d.ts +14 -0
  245. package/dist/index.js +24 -0
  246. package/dist/index.js.map +1 -0
  247. package/{oauthclient → dist/oauthclient}/consts.d.ts +0 -0
  248. package/{oauthclient → dist/oauthclient}/consts.js +0 -0
  249. package/{oauthclient → dist/oauthclient}/consts.js.map +0 -0
  250. package/{oauthclient → dist/oauthclient}/index.d.ts +0 -0
  251. package/{oauthclient → dist/oauthclient}/index.js +2 -2
  252. package/dist/oauthclient/index.js.map +1 -0
  253. package/{oauthclient → dist/oauthclient}/interface.d.ts +4 -0
  254. package/{oauthclient → dist/oauthclient}/interface.js +0 -0
  255. package/{oauthclient → dist/oauthclient}/interface.js.map +1 -1
  256. package/{oauthclient → dist/oauthclient}/models.d.ts +12 -11
  257. package/{auth → dist/oauthclient}/models.js +0 -0
  258. package/{oauthclient → dist/oauthclient}/models.js.map +0 -0
  259. package/{oauthclient → dist/oauthclient}/oauthclient.d.ts +11 -7
  260. package/{oauthclient → dist/oauthclient}/oauthclient.js +27 -12
  261. package/dist/oauthclient/oauthclient.js.map +1 -0
  262. package/dist/package.json +32 -0
  263. package/{utils/single-promise.d.ts → dist/utils/promise.d.ts} +3 -3
  264. package/{utils/single-promise.js → dist/utils/promise.js} +6 -6
  265. package/dist/utils/promise.js.map +1 -0
  266. package/{utils → dist/utils}/uuid.d.ts +0 -0
  267. package/{utils → dist/utils}/uuid.js +0 -0
  268. package/{utils → dist/utils}/uuid.js.map +0 -0
  269. package/docs/dev.md +71 -0
  270. package/docs/errlog.md +79 -0
  271. package/package.json +3 -2
  272. package/publish.sh +2 -0
  273. package/src/app/index.ts +83 -0
  274. package/src/app/internal.ts +26 -0
  275. package/src/app/openuri.ts +111 -0
  276. package/src/app/request.ts +66 -0
  277. package/src/app/storage.ts +58 -0
  278. package/src/auth/consts.ts +74 -0
  279. package/src/auth/index.ts +718 -0
  280. package/src/auth/models.ts +352 -0
  281. package/src/captcha/index.ts +170 -0
  282. package/src/function/index.ts +103 -0
  283. package/src/index.ts +32 -0
  284. package/src/oauthclient/consts.ts +48 -0
  285. package/src/oauthclient/index.ts +33 -0
  286. package/src/oauthclient/interface.ts +34 -0
  287. package/src/oauthclient/models.ts +50 -0
  288. package/src/oauthclient/oauthclient.ts +487 -0
  289. package/src/utils/promise.ts +41 -0
  290. package/src/utils/uuid.ts +11 -0
  291. package/test/e2e/cases/custom-login.test.js +122 -0
  292. package/test/e2e/cases/index.test.js +61 -0
  293. package/test/e2e/cases/login-state.test.js +89 -0
  294. package/test/e2e/environment.js +39 -0
  295. package/test/e2e/global_setup.js +33 -0
  296. package/test/e2e/global_teardown.js +15 -0
  297. package/test/e2e/setup.js +37 -0
  298. package/test/unit/index.test.js +89 -0
  299. package/test/web/cases/auth/index.js +256 -0
  300. package/test/web/cases/database/collection.js +173 -0
  301. package/test/web/cases/database/command.js +754 -0
  302. package/test/web/cases/database/date.js +122 -0
  303. package/test/web/cases/database/db.js +20 -0
  304. package/test/web/cases/database/document.js +160 -0
  305. package/test/web/cases/database/geo-advanced.js +327 -0
  306. package/test/web/cases/database/geo.js +105 -0
  307. package/test/web/cases/database/index.js +315 -0
  308. package/test/web/cases/database/order.js +83 -0
  309. package/test/web/cases/database/realtime.js +102 -0
  310. package/test/web/cases/database/regex.js +140 -0
  311. package/test/web/cases/ext/index.js +88 -0
  312. package/test/web/cases/function/index.js +77 -0
  313. package/test/web/cases/storage/cos.jpeg +0 -0
  314. package/test/web/cases/storage/index.js +207 -0
  315. package/test/web/index.html +63 -0
  316. package/test/web/index.js +109 -0
  317. package/test/web/util.js +80 -0
  318. package/tsconfig.json +35 -0
  319. package/wiki/README.md +75 -0
  320. package/app/index.js.map +0 -1
  321. package/app/request.js.map +0 -1
  322. package/auth/consts.js.map +0 -1
  323. package/auth/index.js.map +0 -1
  324. package/auth/models.d.ts +0 -158
  325. package/auth/models.js.map +0 -1
  326. package/captcha/index.js.map +0 -1
  327. package/index.d.ts +0 -8
  328. package/index.js +0 -17
  329. package/index.js.map +0 -1
  330. package/oauthclient/index.js.map +0 -1
  331. package/oauthclient/oauthclient.js.map +0 -1
  332. package/utils/single-promise.js.map +0 -1
package/Dockerfile ADDED
@@ -0,0 +1,15 @@
1
+ # FROM base_npm:latest
2
+
3
+ # # ARG NPM_TOKEN
4
+ # RUN mkdir -p /usr/src/app
5
+ # WORKDIR /usr/src/app/
6
+
7
+ # COPY package.json .
8
+ # ADD . /usr/src/app
9
+ # RUN npm set registry https://npm.xbase.xyz
10
+ # RUN npm install
11
+ # RUN npm run build
12
+
13
+ # # @todo use semantic-release with gitlab ci to auto release with branch
14
+ # # RUN npm view @xbase/sdk version
15
+ # RUN npm publish
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # xbase-sdk
1
+ # CloudBase TS sdk
2
2
 
3
3
  提供 oauth2 的登录相关功能。
4
4
 
@@ -0,0 +1,99 @@
1
+ import {App} from "@xbasesdk/xbase/app";
2
+ import {getOAuthClient, AuthClient, ErrorType} from "@xbasesdk/xbase/oauthclient";
3
+ import {uuidv4} from "@xbasesdk/xbase/utils/uuid";
4
+
5
+ export interface FunctionOptions {
6
+ credentialsClient: AuthClient;
7
+ env: string
8
+ }
9
+
10
+ /**
11
+ * Returns the existing `Auth` instance that is associated with the app
12
+ */
13
+ export function getFunction(app: App): Function {
14
+ const credentialsClient = getOAuthClient(app)
15
+ return new Function({
16
+ credentialsClient: credentialsClient,
17
+ env: app.options.clientId
18
+ })
19
+ }
20
+
21
+
22
+ export class Function {
23
+
24
+ private _config: FunctionOptions;
25
+
26
+ /**
27
+ * constructor
28
+ * @param {AuthOptions} opts
29
+ */
30
+ constructor(opts: FunctionOptions) {
31
+ this._config = {
32
+ credentialsClient: opts.credentialsClient,
33
+ env: opts.env,
34
+ }
35
+ }
36
+ /**
37
+ * callFunction call function
38
+ * @param {SignInRequest} params A SignInRequest Object.
39
+ * @return {Promise<Credentials>} A Promise<Credentials> object.
40
+ */
41
+ public async callFunction(params: FunctionRequest): Promise<FunctionResponse> {
42
+ let accessToken: string
43
+ try {
44
+ accessToken = await this._config.credentialsClient.getAccessToken()
45
+ } catch (e) {
46
+ if (e.error === ErrorType.UNAUTHENTICATED) {
47
+ accessToken = ""
48
+ } else {
49
+ return Promise.reject(e)
50
+ }
51
+ }
52
+ const requestId = uuidv4()
53
+ var reqBody = {
54
+ "action": "functions.invokeFunction",
55
+ "dataVersion": "2020-01-10",
56
+ "env": this._config.env,
57
+ "function_name": params.name,
58
+ "request_data": JSON.stringify(params.data),
59
+ "seqId": requestId,
60
+ "access_token": accessToken
61
+ }
62
+ const url = "/web?env=" + this._config.env
63
+ const resp = await this._config.credentialsClient.request<functionHTTPResponse>(url, {
64
+ method: 'POST',
65
+ body: reqBody,
66
+ headers: {
67
+ 'content-type': 'application/json'
68
+ }
69
+ })
70
+ if (resp.code) {
71
+ return Promise.reject({
72
+ error: resp.code,
73
+ error_description: resp.message
74
+ })
75
+ }
76
+ return {
77
+ requestId: resp.requestId,
78
+ result: resp.data.response_data,
79
+ }
80
+ }
81
+ }
82
+
83
+
84
+ export interface FunctionRequest {
85
+ name: string;
86
+ data: any;
87
+ }
88
+
89
+ export interface FunctionResponse {
90
+ requestId: string;
91
+ result: any;
92
+ }
93
+
94
+ export interface functionHTTPResponse {
95
+ requestId: string;
96
+ data: any
97
+ code: string
98
+ message: string
99
+ }
@@ -0,0 +1,99 @@
1
+ import {client, fn} from "./request";
2
+
3
+ async function init() {
4
+ try {
5
+ signInWithUserNameAndPassword()
6
+ } catch (error) {
7
+ // 获取用户信息失败
8
+ console.log('test error: ', error);
9
+ }
10
+
11
+ // try {
12
+ // console.log("rest password")
13
+ // const verificationToken = await client.auth.getVerification({
14
+ // phone_number: "+86 16622002084",
15
+ // })
16
+ // console.log(verificationToken.verification_id, verificationToken.is_user)
17
+ // } catch (error) {
18
+ // // 获取用户信息失败
19
+ // console.log('发送失败 error: ', error);
20
+ // }
21
+ try {
22
+ signInWithProviderToken()
23
+ } catch (error) {
24
+ // 获取用户信息失败
25
+ console.log('grant error error: ', error);
26
+ }
27
+
28
+ const resp = await fn.callFunction({name:"test", data: {
29
+ name: "ok"
30
+ }})
31
+ console.log(resp.result)
32
+ }
33
+
34
+ init();
35
+
36
+
37
+
38
+ async function signInWithUserNameAndPassword(): Promise<void> {
39
+ // 判断是否已经登录过了
40
+ const loginState = await client.auth.hasLoginState()
41
+ if (!loginState) {
42
+ // 用户名密码登录
43
+ await client.auth.signIn({
44
+ username: "leenanxi",
45
+ password: "qw0000"
46
+ })
47
+ }
48
+ // 获取用户信息,相当于 auth.signInWithUsernameAndPassword
49
+ const userInfoA = await client.auth.getUserProfile()
50
+ console.log(userInfoA)
51
+
52
+ // 修改密码
53
+
54
+ }
55
+
56
+
57
+ async function signInWithProviderToken(): Promise<void> {
58
+ // 判断是否已经登录过了
59
+ const loginState = await client.auth.hasLoginState()
60
+
61
+ console.log("test", loginState)
62
+
63
+ return
64
+
65
+ // if (!loginState) {
66
+ // const crd = await client.auth.signInAnonymously()
67
+ // console.log(crd)
68
+ // }
69
+
70
+ const userInfoA = await client.auth.getUserProfile()
71
+ console.log(userInfoA)
72
+ //
73
+ // // 获取provider token
74
+ // const providerToken = await client.auth.grantProviderToken({
75
+ // provider_id: "weda",
76
+ // provider_access_token: "ya29.a0ARrdaM8nNGa2g3eNWok38QWChn5hcOMZIXIbV48LxcEIt7lSfOt2ERLVRMQh9-iOxMy9anVtVV20ONWWyIHKxeA68D8FlpSZIazLfscLDOY8X1IjzF7kfhLiQwVbPYVeVsj7prOacREaICaaYO632za8bLSp2RU",
77
+ // });
78
+ // // 用provider token 登录
79
+ // client.auth.signInWithProvider({
80
+ // provider_token: providerToken.provider_token,
81
+ // })
82
+
83
+ // 调用云函数
84
+
85
+
86
+
87
+ // 登录成功后,获取用户信息
88
+ const userInfo = await client.auth.getUserProfile()
89
+ console.log(userInfo)
90
+ // 获取 accessToken
91
+ const accessToken = await client.auth.credentialsClient.getAccessToken();
92
+ console.log(accessToken)
93
+ // 用 OIDC 请求信息
94
+ // export interface ExampleData {
95
+ // result?: string;
96
+ // }
97
+ // const data = await client.oAuth2Client.request<ExampleData>("https://example.com", {withCredentials:true})
98
+ // console.log(data.result)
99
+ }
@@ -0,0 +1,11 @@
1
+ import {initializeClient} from '@cloudbase/cloudbase';
2
+ import {getFunction} from './function/function';
3
+
4
+ export const config = {
5
+ apiOrigin: "https://xbase-4gh5dh6nf62145a9.ap-shanghai.tcb-api.tencentcloudapi.com",
6
+ clientId: "xbase-4gh5dh6nf62145a9",
7
+ };
8
+ const client = initializeClient(config);
9
+ const fn = getFunction(client.app);
10
+
11
+ export {client, fn}
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <meta http-equiv="Pragma" content="no-cache">
7
+ <meta http-equiv="Cache-Control" content="no-cache">
8
+ <meta http-equiv="Expires" content="0">
9
+ <title>Demo</title>
10
+ </head>
11
+ <body>
12
+ <div>loading...</div>
13
+ <div>test</div>
14
+ </body>
15
+ </html>
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "device",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1",
8
+ "build": "cross-env NODE_ENV=production webpack",
9
+ "start": "cross-env NODE_ENV=development webpack-dev-server"
10
+ },
11
+ "author": "",
12
+ "license": "ISC",
13
+ "dependencies": {
14
+ "@types/qs": "^6.9.1",
15
+ "@xbasesdk/xbase": "file://Users/nx/Documents/go/xbase/src/gitlab.xunlei.cn/xbase/sdk/xbasesdk/dist",
16
+ "cross-env": "^7.0.2",
17
+ "firebase": "^9.0.2",
18
+ "qs": "^6.9.3",
19
+ "webpack": "^4.39.3",
20
+ "webpack-cli": "^4.8.0"
21
+ },
22
+ "devDependencies": {
23
+ "@babel/cli": "^7.14.8",
24
+ "@babel/core": "^7.15.0",
25
+ "clean-webpack-plugin": "^4.0.0-alpha.0",
26
+ "copy-webpack-plugin": "^9.0.1",
27
+ "html-webpack-plugin": "^3.2.0",
28
+ "ts-loader": "^6.1.0",
29
+ "typescript": "^3.8.3",
30
+ "webpack-cli": "^4.8.0",
31
+ "webpack-dev-server": "^4.1.0"
32
+ }
33
+ }
@@ -0,0 +1,71 @@
1
+ {
2
+ "compilerOptions": {
3
+ /* Basic Options */
4
+ // "incremental": true, /* Enable incremental compilation */
5
+ "target": "es2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
6
+ "module": "es2020", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
7
+ // "lib": [], /* Specify library files to be included in the compilation. */
8
+ "allowJs": true, /* Allow javascript files to be compiled. */
9
+ // "checkJs": true, /* Report errors in .js files. */
10
+ // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
11
+ // "declaration": true, /* Generates corresponding '.d.ts' file. */
12
+ // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
13
+ // "sourceMap": true, /* Generates corresponding '.map' file. */
14
+ // "outFile": "./", /* Concatenate and emit output to single file. */
15
+ "outDir": "./dist/", /* Redirect output structure to the directory. */
16
+ // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
17
+ // "composite": true, /* Enable project compilation */
18
+ // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
19
+ // "removeComments": true, /* Do not emit comments to output. */
20
+ // "noEmit": true, /* Do not emit outputs. */
21
+ // "importHelpers": true, /* Import emit helpers from 'tslib'. */
22
+ // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
23
+ // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
24
+
25
+ /* Strict Type-Checking Options */
26
+ "strict": true, /* Enable all strict type-checking options. */
27
+ "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
28
+ // "strictNullChecks": true, /* Enable strict null checks. */
29
+ // "strictFunctionTypes": true, /* Enable strict checking of function types. */
30
+ // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
31
+ // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
32
+ // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
33
+ // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
34
+
35
+ /* Additional Checks */
36
+ // "noUnusedLocals": true, /* Report errors on unused locals. */
37
+ // "noUnusedParameters": true, /* Report errors on unused parameters. */
38
+ // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
39
+ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
40
+
41
+ /* Module Resolution Options */
42
+ "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
43
+ // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
44
+ // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
45
+ // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
46
+ // "typeRoots": [], /* List of folders to include type definitions from. */
47
+ // "types": [], /* Type declaration files to be included in compilation. */
48
+ // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
49
+ "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
50
+ // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
51
+ // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
52
+
53
+ /* Source Map Options */
54
+ // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
55
+ // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
56
+ // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
57
+ // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
58
+
59
+ /* Experimental Options */
60
+ // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
61
+ // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
62
+
63
+
64
+
65
+ "strictPropertyInitialization": false,
66
+ "experimentalDecorators": true,
67
+ "strictNullChecks": false,
68
+ "noUnusedLocals": true,
69
+ "declaration": true
70
+ }
71
+ }
File without changes
@@ -0,0 +1,42 @@
1
+ const path = require('path');
2
+ const { CleanWebpackPlugin } = require('clean-webpack-plugin');
3
+ const CopyPlugin = require('copy-webpack-plugin');
4
+ const HtmlWebpackPlugin = require('html-webpack-plugin');
5
+
6
+ const mode = process.env.NODE_ENV;
7
+
8
+ console.log('环境:', mode);
9
+
10
+ module.exports = {
11
+ entry: {
12
+ main: './assets/scripts/index.ts',
13
+ },
14
+ mode,
15
+ devServer: {
16
+ contentBase: path.join(__dirname, 'dist'),
17
+ port: 4000,
18
+ hot: true,
19
+ },
20
+ module: {
21
+ rules: [
22
+ {
23
+ test: /\.tsx?$/,
24
+ use: 'ts-loader',
25
+ exclude: /node_modules/
26
+ }
27
+ ]
28
+ },
29
+ resolve: {
30
+ extensions: [ '.ts', '.tsx', '.js' ]
31
+ },
32
+ output: {
33
+ filename: '[name].[hash:5].js',
34
+ path: path.resolve(__dirname, 'dist')
35
+ },
36
+ plugins: [
37
+ new CleanWebpackPlugin(),
38
+ new HtmlWebpackPlugin({
39
+ template: "./index.html"
40
+ })
41
+ ],
42
+ };
@@ -0,0 +1 @@
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(function(){try{return require("null")}catch(e){}}()):"function"==typeof define&&define.amd?define("cloudbase_auth",["null"],t):"object"==typeof exports?exports.cloudbase_auth=t(function(){try{return require("null")}catch(e){}}()):e.cloudbase_auth=t(e.null)}("undefined"!=typeof window?window:this,(function(e){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=6)}([function(e,t,n){"use strict";var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.hasOwnProperty.call(e,n)&&r(t,e,n);return o(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.utils=t.events=t.cache=t.adapters=t.constants=void 0;var s=i(n(3));t.constants=s;var c=i(n(8));t.adapters=c;var a=i(n(17));t.cache=a;var u=i(n(19));t.events=u;var h=i(n(1));t.utils=h},function(e,t,n){"use strict";var r=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.throwError=t.printInfo=t.printError=t.printWarn=t.execCallback=t.createPromiseCallback=t.removeParam=t.getHash=t.getQuery=t.toQueryString=t.createSign=t.formatUrl=t.genSeqId=t.isFormData=t.isInstanceOf=t.isNull=t.isPalinObject=t.isUndefined=t.isString=t.isArray=void 0;var o=r(n(10)),i=r(n(15)),s=r(n(16)),c=n(3);function a(e){var t=i.default.stringify(e);return t=(t=(t=t.replace(/=+$/,"")).replace(/\+/g,"-")).replace(/\//g,"_")}t.isArray=function(e){return"[object Array]"===Object.prototype.toString.call(e)},t.isString=function(e){return"string"==typeof e},t.isUndefined=function(e){return void 0===e},t.isPalinObject=function(e){return"[object Object]"===Object.prototype.toString.call(e)},t.isNull=function(e){return"[object Null]"===Object.prototype.toString.call(e)},t.isInstanceOf=function(e,t){return e instanceof t},t.isFormData=function(e){return"[object FormData]"===Object.prototype.toString.call(e)},t.genSeqId=function(){return Math.random().toString(16).slice(2)},t.formatUrl=function(e,t,n){void 0===n&&(n={});var r=/\?/.test(t),o="";for(var i in n)""===o?!r&&(t+="?"):o+="&",o+=i+"="+encodeURIComponent(n[i]);return/^http(s)?\:\/\//.test(t+=o)?t:""+e+t},t.createSign=function(e,t){var n=a(s.default.parse(JSON.stringify({alg:"HS256",typ:"JWT"})))+"."+a(s.default.parse(JSON.stringify(e)));return n+"."+a(o.default(n,t))},t.toQueryString=function(e){void 0===e&&(e={});var t=[];for(var n in e)t.push(n+"="+encodeURIComponent(e[n]));return t.join("&")},t.getQuery=function(e,t){if("undefined"==typeof window)return!1;var n=t||window.location.search,r=new RegExp("(^|&)"+e+"=([^&]*)(&|$)"),o=n.substr(n.indexOf("?")+1).match(r);return null!=o?o[2]:""},t.getHash=function(e){if("undefined"==typeof window)return"";var t=window.location.hash.match(new RegExp("[#?&/]"+e+"=([^&#]*)"));return t?t[1]:""},t.removeParam=function(e,t){var n=t.split("?")[0],r=[],o=-1!==t.indexOf("?")?t.split("?")[1]:"";if(""!==o){for(var i=(r=o.split("&")).length-1;i>=0;i-=1)r[i].split("=")[0]===e&&r.splice(i,1);n=n+"?"+r.join("&")}return n},t.createPromiseCallback=function(){var e;if(!Promise){(e=function(){}).promise={};var t=function(){throw new Error('Your Node runtime does support ES6 Promises. Set "global.Promise" to your preferred implementation of promises.')};return Object.defineProperty(e.promise,"then",{get:t}),Object.defineProperty(e.promise,"catch",{get:t}),e}var n=new Promise((function(t,n){e=function(e,r){return e?n(e):t(r)}}));return e.promise=n,e},t.execCallback=function(e,t,n){if(void 0===n&&(n=null),e&&"function"==typeof e)return e(t,n);if(t)throw t;return n},t.printWarn=function(e,t){console.warn("["+c.SDK_NAME+"]["+e+"]:"+t)},t.printError=function(e,t){console.error({code:e,msg:"["+c.SDK_NAME+"]["+e+"]:"+t})},t.printInfo=function(e,t){console.log("["+c.SDK_NAME+"]["+e+"]:"+t)},t.throwError=function(e,t){throw new Error(JSON.stringify({code:e,msg:"["+c.SDK_NAME+"]["+e+"]:"+t}))}},function(e,t,n){(function(t){var r;e.exports=(r=r||function(e,r){var o;if("undefined"!=typeof window&&window.crypto&&(o=window.crypto),!o&&"undefined"!=typeof window&&window.msCrypto&&(o=window.msCrypto),!o&&void 0!==t&&t.crypto&&(o=t.crypto),!o)try{o=n(12)}catch(e){}var i=function(){if(o){if("function"==typeof o.getRandomValues)try{return o.getRandomValues(new Uint32Array(1))[0]}catch(e){}if("function"==typeof o.randomBytes)try{return o.randomBytes(4).readInt32LE()}catch(e){}}throw new Error("Native crypto module could not be used to get secure random number.")},s=Object.create||function(){function e(){}return function(t){var n;return e.prototype=t,n=new e,e.prototype=null,n}}(),c={},a=c.lib={},u=a.Base={extend:function(e){var t=s(this);return e&&t.mixIn(e),t.hasOwnProperty("init")&&this.init!==t.init||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},h=a.WordArray=u.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||l).stringify(this)},concat:function(e){var t=this.words,n=e.words,r=this.sigBytes,o=e.sigBytes;if(this.clamp(),r%4)for(var i=0;i<o;i++){var s=n[i>>>2]>>>24-i%4*8&255;t[r+i>>>2]|=s<<24-(r+i)%4*8}else for(i=0;i<o;i+=4)t[r+i>>>2]=n[i>>>2];return this.sigBytes+=o,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=u.clone.call(this);return e.words=this.words.slice(0),e},random:function(e){for(var t=[],n=0;n<e;n+=4)t.push(i());return new h.init(t,e)}}),f=c.enc={},l=f.Hex={stringify:function(e){for(var t=e.words,n=e.sigBytes,r=[],o=0;o<n;o++){var i=t[o>>>2]>>>24-o%4*8&255;r.push((i>>>4).toString(16)),r.push((15&i).toString(16))}return r.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r<t;r+=2)n[r>>>3]|=parseInt(e.substr(r,2),16)<<24-r%8*4;return new h.init(n,t/2)}},p=f.Latin1={stringify:function(e){for(var t=e.words,n=e.sigBytes,r=[],o=0;o<n;o++){var i=t[o>>>2]>>>24-o%4*8&255;r.push(String.fromCharCode(i))}return r.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r<t;r++)n[r>>>2]|=(255&e.charCodeAt(r))<<24-r%4*8;return new h.init(n,t)}},d=f.Utf8={stringify:function(e){try{return decodeURIComponent(escape(p.stringify(e)))}catch(e){throw new Error("Malformed UTF-8 data")}},parse:function(e){return p.parse(unescape(encodeURIComponent(e)))}},y=a.BufferedBlockAlgorithm=u.extend({reset:function(){this._data=new h.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=d.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n,r=this._data,o=r.words,i=r.sigBytes,s=this.blockSize,c=i/(4*s),a=(c=t?e.ceil(c):e.max((0|c)-this._minBufferSize,0))*s,u=e.min(4*a,i);if(a){for(var f=0;f<a;f+=s)this._doProcessBlock(o,f);n=o.splice(0,a),r.sigBytes-=u}return new h.init(n,u)},clone:function(){var e=u.clone.call(this);return e._data=this._data.clone(),e},_minBufferSize:0}),_=(a.Hasher=y.extend({cfg:u.extend(),init:function(e){this.cfg=this.cfg.extend(e),this.reset()},reset:function(){y.reset.call(this),this._doReset()},update:function(e){return this._append(e),this._process(),this},finalize:function(e){return e&&this._append(e),this._doFinalize()},blockSize:16,_createHelper:function(e){return function(t,n){return new e.init(n).finalize(t)}},_createHmacHelper:function(e){return function(t,n){return new _.HMAC.init(e,n).finalize(t)}}}),c.algo={});return c}(Math),r)}).call(this,n(11))},function(e,t,n){"use strict";var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||t.hasOwnProperty(n)||r(t,e,n)};Object.defineProperty(t,"__esModule",{value:!0}),o(n(4),t),o(n(7),t)},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.PROTOCOL=t.SDK_NAME=void 0,t.SDK_NAME="@cloudbase/js-sdk",t.PROTOCOL="https:"},function(e,t,n){"use strict";var r;n.r(t),n.d(t,"StorageType",(function(){return r})),n.d(t,"AbstractSDKRequest",(function(){return o})),n.d(t,"AbstractStorage",(function(){return i})),n.d(t,"formatUrl",(function(){return s})),function(e){e.local="local",e.none="none",e.session="session"}(r||(r={}));var o=function(){},i=function(){};function s(e,t,n){void 0===n&&(n={});var r=/\?/.test(t),o="";for(var i in n)""===o?!r&&(t+="?"):o+="&",o+=i+"="+encodeURIComponent(n[i]);return/^http(s)?\:\/\//.test(t+=o)?t:""+e+t}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.registerAuth=void 0;var r=n(20);Object.defineProperty(t,"registerAuth",{enumerable:!0,get:function(){return r.registerAuth}})},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.ERRORS=void 0,t.ERRORS={INVALID_PARAMS:"INVALID_PARAMS",INVALID_SYNTAX:"INVALID_SYNTAX",INVALID_OPERATION:"INVALID_OPERATION",OPERATION_FAIL:"OPERATION_FAIL",NETWORK_ERROR:"NETWORK_ERROR",UNKOWN_ERROR:"UNKOWN_ERROR"}},function(e,t,n){"use strict";var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){void 0===r&&(r=n),e[r]=t[n]}),o=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)"default"!==n&&Object.hasOwnProperty.call(e,n)&&r(t,e,n);return o(t,e),t};Object.defineProperty(t,"__esModule",{value:!0}),t.useDefaultAdapter=t.useAdapters=t.RUNTIME=void 0;var s,c=i(n(9)),a=n(1);!function(e){e.WEB="web",e.WX_MP="wx_mp"}(s=t.RUNTIME||(t.RUNTIME={})),t.useAdapters=function(e){for(var t=0,n=a.isArray(e)?e:[e];t<n.length;t++){var r=n[t],o=r.isMatch,i=r.genAdapter,s=r.runtime;if(o())return{adapter:i(),runtime:s}}},t.useDefaultAdapter=function(){return{adapter:c.genAdapter(),runtime:s.WEB}}},function(e,t,n){"use strict";var r,o=this&&this.__extends||(r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__assign||function(){return(i=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},s=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{a(r.next(e))}catch(e){i(e)}}function c(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,c)}a((r=r.apply(e,t||[])).next())}))},c=this&&this.__generator||function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.WebRequest=t.genAdapter=void 0;var a=n(5),u=n(1),h=n(4),f=function(e){function t(t){var n=e.call(this)||this,r=t.timeout,o=t.timeoutMsg,i=t.restrictedMethods;return n._timeout=r||0,n._timeoutMsg=o||"请求超时",n._restrictedMethods=i||["get","post","upload","download"],n}return o(t,e),t.prototype.get=function(e){return this._request(i(i({},e),{method:"get"}),this._restrictedMethods.includes("get"))},t.prototype.post=function(e){return this._request(i(i({},e),{method:"post"}),this._restrictedMethods.includes("post"))},t.prototype.put=function(e){return this._request(i(i({},e),{method:"put"}))},t.prototype.upload=function(e){var t=e.data,n=e.file,r=e.name,o=new FormData;for(var s in t)o.append(s,t[s]);return o.append("key",r),o.append("file",n),this._request(i(i({},e),{data:o,method:"post"}),this._restrictedMethods.includes("upload"))},t.prototype.download=function(e){return s(this,void 0,void 0,(function(){var t,n;return c(this,(function(r){return t=decodeURIComponent(new URL(e.url).pathname.split("/").pop()||""),(n=document.createElement("a")).href=e.url,n.setAttribute("download",t),n.setAttribute("target","_blank"),document.body.appendChild(n),n.click(),[2,new Promise((function(t){t({statusCode:200,tempFilePath:e.url})}))]}))}))},t.prototype._request=function(e,t){var n=this;void 0===t&&(t=!1);var r=String(e.method).toLowerCase()||"get";return new Promise((function(o){var i,s,c=e.url,a=e.headers,f=void 0===a?{}:a,l=e.data,p=e.responseType,d=e.withCredentials,y=e.body,_=e.onUploadProgress,v=u.formatUrl(h.PROTOCOL,c,"get"===r?l:{}),g=new XMLHttpRequest;for(var b in g.open(r,v),p&&(g.responseType=p),f)g.setRequestHeader(b,f[b]);_&&g.addEventListener("progress",_),g.onreadystatechange=function(){var e={};if(4===g.readyState){var t=g.getAllResponseHeaders().trim().split(/[\r\n]+/),n={};t.forEach((function(e){var t=e.split(": "),r=t.shift().toLowerCase(),o=t.join(": ");n[r]=o})),e.header=n,e.statusCode=g.status;try{e.data=JSON.parse(g.responseText)}catch(t){e.data=g.responseText}clearTimeout(i),o(e)}},t&&n._timeout&&(i=setTimeout((function(){console.warn(n._timeoutMsg),g.abort()}),n._timeout)),s=u.isFormData(l)?l:"application/x-www-form-urlencoded"===f["content-type"]?u.toQueryString(l):y||(l?JSON.stringify(l):void 0),d&&(g.withCredentials=!0),g.send(s)}))},t}(a.AbstractSDKRequest);t.WebRequest=f,t.genAdapter=function(){return{root:window,reqClass:f,wsClass:WebSocket,localStorage:localStorage,sessionStorage:sessionStorage}}},function(e,t,n){var r;e.exports=(r=n(2),n(13),n(14),r.HmacSHA256)},function(e,t){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(t,n){if(void 0===e){var r=new Error("Cannot find module 'null'");throw r.code="MODULE_NOT_FOUND",r}t.exports=e},function(e,t,n){var r;e.exports=(r=n(2),function(e){var t=r,n=t.lib,o=n.WordArray,i=n.Hasher,s=t.algo,c=[],a=[];!function(){function t(t){for(var n=e.sqrt(t),r=2;r<=n;r++)if(!(t%r))return!1;return!0}function n(e){return 4294967296*(e-(0|e))|0}for(var r=2,o=0;o<64;)t(r)&&(o<8&&(c[o]=n(e.pow(r,.5))),a[o]=n(e.pow(r,1/3)),o++),r++}();var u=[],h=s.SHA256=i.extend({_doReset:function(){this._hash=new o.init(c.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,r=n[0],o=n[1],i=n[2],s=n[3],c=n[4],h=n[5],f=n[6],l=n[7],p=0;p<64;p++){if(p<16)u[p]=0|e[t+p];else{var d=u[p-15],y=(d<<25|d>>>7)^(d<<14|d>>>18)^d>>>3,_=u[p-2],v=(_<<15|_>>>17)^(_<<13|_>>>19)^_>>>10;u[p]=y+u[p-7]+v+u[p-16]}var g=r&o^r&i^o&i,b=(r<<30|r>>>2)^(r<<19|r>>>13)^(r<<10|r>>>22),w=l+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&h^~c&f)+a[p]+u[p];l=f,f=h,h=c,c=s+w|0,s=i,i=o,o=r,r=w+(b+g)|0}n[0]=n[0]+r|0,n[1]=n[1]+o|0,n[2]=n[2]+i|0,n[3]=n[3]+s|0,n[4]=n[4]+c|0,n[5]=n[5]+h|0,n[6]=n[6]+f|0,n[7]=n[7]+l|0},_doFinalize:function(){var t=this._data,n=t.words,r=8*this._nDataBytes,o=8*t.sigBytes;return n[o>>>5]|=128<<24-o%32,n[14+(o+64>>>9<<4)]=e.floor(r/4294967296),n[15+(o+64>>>9<<4)]=r,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=i.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=i._createHelper(h),t.HmacSHA256=i._createHmacHelper(h)}(Math),r.SHA256)},function(e,t,n){var r,o,i,s;e.exports=(r=n(2),i=(o=r).lib.Base,s=o.enc.Utf8,void(o.algo.HMAC=i.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=s.parse(t));var n=e.blockSize,r=4*n;t.sigBytes>r&&(t=e.finalize(t)),t.clamp();for(var o=this._oKey=t.clone(),i=this._iKey=t.clone(),c=o.words,a=i.words,u=0;u<n;u++)c[u]^=1549556828,a[u]^=909522486;o.sigBytes=i.sigBytes=r,this.reset()},reset:function(){var e=this._hasher;e.reset(),e.update(this._iKey)},update:function(e){return this._hasher.update(e),this},finalize:function(e){var t=this._hasher,n=t.finalize(e);return t.reset(),t.finalize(this._oKey.clone().concat(n))}})))},function(e,t,n){var r,o,i;e.exports=(i=n(2),o=(r=i).lib.WordArray,r.enc.Base64={stringify:function(e){var t=e.words,n=e.sigBytes,r=this._map;e.clamp();for(var o=[],i=0;i<n;i+=3)for(var s=(t[i>>>2]>>>24-i%4*8&255)<<16|(t[i+1>>>2]>>>24-(i+1)%4*8&255)<<8|t[i+2>>>2]>>>24-(i+2)%4*8&255,c=0;c<4&&i+.75*c<n;c++)o.push(r.charAt(s>>>6*(3-c)&63));var a=r.charAt(64);if(a)for(;o.length%4;)o.push(a);return o.join("")},parse:function(e){var t=e.length,n=this._map,r=this._reverseMap;if(!r){r=this._reverseMap=[];for(var i=0;i<n.length;i++)r[n.charCodeAt(i)]=i}var s=n.charAt(64);if(s){var c=e.indexOf(s);-1!==c&&(t=c)}return function(e,t,n){for(var r=[],i=0,s=0;s<t;s++)if(s%4){var c=n[e.charCodeAt(s-1)]<<s%4*2,a=n[e.charCodeAt(s)]>>>6-s%4*2,u=c|a;r[i>>>2]|=u<<24-i%4*8,i++}return o.create(r,i)}(e,t,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},i.enc.Base64)},function(e,t,n){var r;e.exports=(r=n(2),r.enc.Utf8)},function(e,t,n){"use strict";(function(e){var r,o=this&&this.__extends||(r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__awaiter||function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{a(r.next(e))}catch(e){i(e)}}function c(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,c)}a((r=r.apply(e,t||[])).next())}))},s=this&&this.__generator||function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}};Object.defineProperty(t,"__esModule",{value:!0}),t.CloudbaseCache=void 0;var c=n(5),a=n(1),u=n(3),h=function(e){function t(t){var n=e.call(this)||this;return n._root=t,t.tcbCacheObject||(t.tcbCacheObject={}),n}return o(t,e),t.prototype.setItem=function(e,t){this._root.tcbCacheObject[e]=t},t.prototype.getItem=function(e){return this._root.tcbCacheObject[e]},t.prototype.removeItem=function(e){delete this._root.tcbCacheObject[e]},t.prototype.clear=function(){delete this._root.tcbCacheObject},t}(c.AbstractStorage);function f(e,t){switch(e){case"local":return t.localStorage?t.localStorage:(a.printWarn(u.ERRORS.INVALID_PARAMS,"localStorage is not supported on current platform"),new h(t.root));case"none":return new h(t.root);default:return t.sessionStorage?t.sessionStorage:(a.printWarn(u.ERRORS.INVALID_PARAMS,"sessionStorage is not supported on current platform"),new h(t.root))}}var l=function(){function t(e){this.keys={};var t=e.persistence,n=e.platformInfo,r=void 0===n?{}:n,o=e.keys,i=void 0===o?{}:o,s=e.alwaysLocalKeys,c=void 0===s?[]:s;this._platformInfo=r,this._alwaysLocalKeys=c,this._storage||(this._persistence=r.adapter.primaryStorage||t,this._storage=f(this._persistence,r.adapter),this.keys=i)}return Object.defineProperty(t.prototype,"mode",{get:function(){return this._storage.mode||"sync"},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"persistence",{get:function(){return this._persistence},enumerable:!1,configurable:!0}),t.prototype.updatePersistence=function(e){if("async"!==this.mode){if(e!==this._persistence){var t="local"===this._persistence;this._persistence=e;var n=f(e,this._platformInfo.adapter);for(var r in this.keys){var o=this.keys[r];if(!t||!this._alwaysLocalKeys.includes(r)){var i=this._storage.getItem(o);a.isUndefined(i)||a.isNull(i)||(n.setItem(o,i),this._storage.removeItem(o))}}this._storage=n}}else a.printWarn(u.ERRORS.INVALID_OPERATION,"current platform's storage is asynchronous, please use updatePersistenceAsync insteed")},t.prototype.updatePersistenceAsync=function(e){return i(this,void 0,void 0,(function(){var t,n,r,o,i,c,u,h;return s(this,(function(s){switch(s.label){case 0:if(e===this._persistence)return[2];for(o in t="local"===this._persistence,this._persistence=e,n=f(e,this._platformInfo.adapter),r=[],this.keys)r.push(o);i=0,s.label=1;case 1:return i<r.length?(c=r[i],u=this.keys[c],t&&this._alwaysLocalKeys.includes(c)?[3,4]:[4,this._storage.getItem(u)]):[3,5];case 2:return h=s.sent(),a.isUndefined(h)||a.isNull(h)?[3,4]:(n.setItem(u,h),[4,this._storage.removeItem(u)]);case 3:s.sent(),s.label=4;case 4:return i++,[3,1];case 5:return this._storage=n,[2]}}))}))},t.prototype.setStore=function(e,t,n){if("async"!==this.mode){if(this._storage)try{var r={version:n||"localCachev1",content:t};this._storage.setItem(e,JSON.stringify(r))}catch(e){return}}else a.printWarn(u.ERRORS.INVALID_OPERATION,"current platform's storage is asynchronous, please use setStoreAsync insteed")},t.prototype.setStoreAsync=function(e,t,n){return i(this,void 0,void 0,(function(){var r;return s(this,(function(o){switch(o.label){case 0:if(!this._storage)return[2];o.label=1;case 1:return o.trys.push([1,3,,4]),r={version:n||"localCachev1",content:t},[4,this._storage.setItem(e,JSON.stringify(r))];case 2:return o.sent(),[3,4];case 3:return o.sent(),[2];case 4:return[2]}}))}))},t.prototype.getStore=function(t,n){var r;if("async"!==this.mode){try{if(void 0!==e&&(null===(r=e.env)||void 0===r?void 0:r.tcb_token))return e.env.tcb_token;if(!this._storage)return""}catch(e){return""}n=n||"localCachev1";var o=this._storage.getItem(t);return o&&o.indexOf(n)>=0?JSON.parse(o).content:""}a.printWarn(u.ERRORS.INVALID_OPERATION,"current platform's storage is asynchronous, please use getStoreAsync insteed")},t.prototype.getStoreAsync=function(t,n){var r;return i(this,void 0,void 0,(function(){var o;return s(this,(function(i){switch(i.label){case 0:try{if(void 0!==e&&(null===(r=e.env)||void 0===r?void 0:r.tcb_token))return[2,e.env.tcb_token];if(!this._storage)return[2,""]}catch(e){return[2,""]}return n=n||"localCachev1",[4,this._storage.getItem(t)];case 1:return(o=i.sent())&&o.indexOf(n)>=0?[2,JSON.parse(o).content]:[2,""]}}))}))},t.prototype.removeStore=function(e){"async"!==this.mode?this._storage.removeItem(e):a.printWarn(u.ERRORS.INVALID_OPERATION,"current platform's storage is asynchronous, please use removeStoreAsync insteed")},t.prototype.removeStoreAsync=function(e){return i(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return[4,this._storage.removeItem(e)];case 1:return t.sent(),[2]}}))}))},t}();t.CloudbaseCache=l}).call(this,n(18))},function(e,t){var n,r,o=e.exports={};function i(){throw new Error("setTimeout has not been defined")}function s(){throw new Error("clearTimeout has not been defined")}function c(e){if(n===setTimeout)return setTimeout(e,0);if((n===i||!n)&&setTimeout)return n=setTimeout,setTimeout(e,0);try{return n(e,0)}catch(t){try{return n.call(null,e,0)}catch(t){return n.call(this,e,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:i}catch(e){n=i}try{r="function"==typeof clearTimeout?clearTimeout:s}catch(e){r=s}}();var a,u=[],h=!1,f=-1;function l(){h&&a&&(h=!1,a.length?u=a.concat(u):f=-1,u.length&&p())}function p(){if(!h){var e=c(l);h=!0;for(var t=u.length;t;){for(a=u,u=[];++f<t;)a&&a[f].run();f=-1,t=u.length}a=null,h=!1,function(e){if(r===clearTimeout)return clearTimeout(e);if((r===s||!r)&&clearTimeout)return r=clearTimeout,clearTimeout(e);try{r(e)}catch(t){try{return r.call(null,e)}catch(t){return r.call(this,e)}}}(e)}}function d(e,t){this.fun=e,this.array=t}function y(){}o.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];u.push(new d(e,t)),1!==u.length||h||c(p)},d.prototype.run=function(){this.fun.apply(null,this.array)},o.title="browser",o.browser=!0,o.env={},o.argv=[],o.version="",o.versions={},o.on=y,o.addListener=y,o.once=y,o.off=y,o.removeListener=y,o.removeAllListeners=y,o.emit=y,o.prependListener=y,o.prependOnceListener=y,o.listeners=function(e){return[]},o.binding=function(e){throw new Error("process.binding is not supported")},o.cwd=function(){return"/"},o.chdir=function(e){throw new Error("process.chdir is not supported")},o.umask=function(){return 0}},function(e,t,n){"use strict";var r,o=this&&this.__extends||(r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),i=this&&this.__spreadArrays||function(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;var r=Array(e),o=0;for(t=0;t<n;t++)for(var i=arguments[t],s=0,c=i.length;s<c;s++,o++)r[o]=i[s];return r};Object.defineProperty(t,"__esModule",{value:!0}),t.removeEventListener=t.activateEvent=t.addEventListener=t.CloudbaseEventEmitter=t.IErrorEvent=t.CloudbaseEvent=void 0;var s=n(1);var c=function(e,t){this.data=t||null,this.name=e};t.CloudbaseEvent=c;var a=function(e){function t(t,n){var r=e.call(this,"error",{error:t,data:n})||this;return r.error=t,r}return o(t,e),t}(c);t.IErrorEvent=a;var u=function(){function e(){this._listeners={}}return e.prototype.on=function(e,t){return function(e,t,n){n[e]=n[e]||[],n[e].push(t)}(e,t,this._listeners),this},e.prototype.off=function(e,t){return function(e,t,n){if(null==n?void 0:n[e]){var r=n[e].indexOf(t);-1!==r&&n[e].splice(r,1)}}(e,t,this._listeners),this},e.prototype.fire=function(e,t){if(s.isInstanceOf(e,a))return console.error(e.error),this;var n=s.isString(e)?new c(e,t||{}):e,r=n.name;if(this._listens(r)){n.target=this;for(var o=0,u=this._listeners[r]?i(this._listeners[r]):[];o<u.length;o++){u[o].call(this,n)}}return this},e.prototype._listens=function(e){return this._listeners[e]&&this._listeners[e].length>0},e}();t.CloudbaseEventEmitter=u;var h=new u;t.addEventListener=function(e,t){h.on(e,t)},t.activateEvent=function(e,t){void 0===t&&(t={}),h.fire(e,t)},t.removeEventListener=function(e,t){h.off(e,t)}},function(e,t,n){"use strict";n.r(t),n.d(t,"LoginState",(function(){return ie})),n.d(t,"Auth",(function(){return se})),n.d(t,"AuthProvider",(function(){return c})),n.d(t,"EVENTS",(function(){return ce})),n.d(t,"eventBus",(function(){return re})),n.d(t,"registerAuth",(function(){return ue})),n.d(t,"registerProvider",(function(){return he}));var r,o=n(0),i=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{a(r.next(e))}catch(e){i(e)}}function c(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,c)}a((r=r.apply(e,t||[])).next())}))},s=function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}},c=function(){function e(e){this._config=e,this._cache=e.cache,this._request=e.request}return e.prototype.checkLocalLoginState=function(){return i(this,void 0,void 0,(function(){var e,t,n,r,o,i;return s(this,(function(s){switch(s.label){case 0:return e=this._cache.keys,t=e.accessTokenKey,n=e.accessTokenExpireKey,[4,this._cache.getStoreAsync(t)];case 1:return r=s.sent(),[4,this._cache.getStoreAsync(n)];case 2:return o=s.sent(),r?o&&o>Date.now()?[4,(i=new ie({envId:this._config.env,cache:this._cache,request:this._request})).checkLocalStateAsync()]:[3,4]:[3,7];case 3:return s.sent(),[2,i];case 4:return[4,this._cache.removeStoreAsync(t)];case 5:return s.sent(),[4,this._cache.removeStoreAsync(n)];case 6:s.sent(),s.label=7;case 7:return[2]}}))}))},e.prototype.setRefreshToken=function(e){return i(this,void 0,void 0,(function(){var t,n,r,o;return s(this,(function(i){switch(i.label){case 0:return t=this._cache.keys,n=t.accessTokenKey,r=t.accessTokenExpireKey,o=t.refreshTokenKey,[4,this._cache.removeStoreAsync(n)];case 1:return i.sent(),[4,this._cache.removeStoreAsync(r)];case 2:return i.sent(),[4,this._cache.setStoreAsync(o,e)];case 3:return i.sent(),[2]}}))}))},e.prototype.setAccessToken=function(e,t){return i(this,void 0,void 0,(function(){var n,r,o;return s(this,(function(i){switch(i.label){case 0:return n=this._cache.keys,r=n.accessTokenKey,o=n.accessTokenExpireKey,[4,this._cache.setStoreAsync(r,e)];case 1:return i.sent(),[4,this._cache.setStoreAsync(o,t)];case 2:return i.sent(),[2]}}))}))},e.prototype.refreshUserInfo=function(){return i(this,void 0,void 0,(function(){var e;return s(this,(function(t){switch(t.label){case 0:return"auth.getUserInfo",[4,this._request.send("auth.getUserInfo",{})];case 1:return e=t.sent().data,[4,this.setLocalUserInfo(e)];case 2:return t.sent(),[2,e]}}))}))},e.prototype.setLocalUserInfo=function(e){return i(this,void 0,void 0,(function(){var t;return s(this,(function(n){switch(n.label){case 0:return t=this._cache.keys.userInfoKey,[4,this._cache.setStoreAsync(t,e)];case 1:return n.sent(),[2]}}))}))},e}();!function(e){e.ANONYMOUS="ANONYMOUS",e.WECHAT="WECHAT",e.WECHAT_PUBLIC="WECHAT-PUBLIC",e.WECHAT_OPEN="WECHAT-OPEN",e.CUSTOM="CUSTOM",e.EMAIL="EMAIL",e.USERNAME="USERNAME",e.NULL="NULL"}(r||(r={}));var a,u=(a=function(e,t){return(a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}a(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),h=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{a(r.next(e))}catch(e){i(e)}}function c(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,c)}a((r=r.apply(e,t||[])).next())}))},f=function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}},l=o.constants.SDK_NAME,p=o.constants.ERRORS,d=o.adapters.RUNTIME,y=o.utils.getQuery,_=o.utils.getHash,v=o.utils.removeParam,g=o.utils.printWarn,b=function(e){function t(t,n,r,o){var i=e.call(this,t)||this;return i._runtime=t.runtime,i._appid=n,i._scope=r,i._state=o||"weixin",i}return u(t,e),t.prototype.signIn=function(){return h(this,void 0,void 0,(function(){return f(this,(function(e){return[2,g(p.OPERATION_FAIL,"API signIn has been deprecated, please use signInWithRedirect insteed")]}))}))},t.prototype.signInWithRedirect=function(){return h(this,void 0,void 0,(function(){return f(this,(function(e){return[2,this._redirect()]}))}))},t.prototype.getRedirectResult=function(e){return h(this,void 0,void 0,(function(){var t;return f(this,(function(n){return(t=w())?[2,this._signInWithCode(t,e)]:[2,null]}))}))},t.prototype.getLinkRedirectResult=function(e){return void 0===e&&(e={}),h(this,void 0,void 0,(function(){var t,n,r,o,i,s;return f(this,(function(c){return t=e.withUnionId,n=void 0!==t&&t,(r=w())?(o=this._appid,i=function(e){switch(e){case"snsapi_login":return"WECHAT-OPEN";default:return"WECHAT-PUBLIC"}}(this._scope),s=this._runtime===d.WX_MP?"1":"0",[2,this._request.send("auth.linkWithWeixinCode",{payload:{appid:o,loginType:i,code:r,hybridMiniapp:s,withUnionId:n}})]):[2,null]}))}))},t.prototype._redirect=function(){var e=v("code",location.href);e=v("state",e),e=encodeURIComponent(e);var t="//open.weixin.qq.com/connect/oauth2/authorize";"snsapi_login"===this._scope&&(t="//open.weixin.qq.com/connect/qrconnect");try{location.href=t+"?appid="+this._appid+"&redirect_uri="+e+"&response_type=code&scope="+this._scope+"&state="+this._state+"#wechat_redirect"}catch(e){throw new Error("["+l+"]["+p.UNKOWN_ERROR+"]"+e)}},t.prototype._signInWithCode=function(e,t){return h(this,void 0,void 0,(function(){var n,o,i,s,c,a,u,h;return f(this,(function(f){switch(f.label){case 0:return n=this._cache.keys,o=n.accessTokenKey,i=n.accessTokenExpireKey,s=n.refreshTokenKey,c=function(e){switch(e){case"snsapi_login":return"WECHAT-OPEN";default:return"WECHAT-PUBLIC"}}(this._scope),[4,this._getRefreshTokenByWXCode(this._appid,c,e,t)];case 1:return a=f.sent(),u=a.refreshToken,[4,this._cache.setStoreAsync(s,u)];case 2:return f.sent(),a.accessToken?[4,this._cache.setStoreAsync(o,a.accessToken)]:[3,4];case 3:f.sent(),f.label=4;case 4:return a.accessTokenExpire?[4,this._cache.setStoreAsync(i,String(a.accessTokenExpire+Date.now()))]:[3,6];case 5:f.sent(),f.label=6;case 6:return re.fire(ce.LOGIN_STATE_CHANGED),re.fire(ce.LOGIN_TYPE_CHANGED,{env:this._config.env,loginType:r.WECHAT,persistence:this._config.persistence}),[4,this.refreshUserInfo()];case 7:return f.sent(),[4,(h=new ie({envId:this._config.env,cache:this._cache,request:this._request})).checkLocalStateAsync()];case 8:return f.sent(),[2,h]}}))}))},t.prototype._getRefreshTokenByWXCode=function(e,t,n,r){return void 0===r&&(r={}),h(this,void 0,void 0,(function(){var o,i,s,c,a,u;return f(this,(function(h){return o=r.withUnionId,i=void 0!==o&&o,s=r.createUser,c=void 0===s||s,a="snsapi_base"!==this._scope&&(r.syncUserInfo||!1),"auth.getJwt",u=this._runtime===d.WX_MP?"1":"0",[2,this._request.send("auth.getJwt",{appid:e,loginType:t,hybridMiniapp:u,syncUserInfo:a,loginCredential:n,withUnionId:i,createUser:c}).then((function(e){if(e.code)throw new Error("["+l+"]["+p.OPERATION_FAIL+"] failed login via wechat: "+e.code);if(e.refresh_token)return{refreshToken:e.refresh_token,accessToken:e.access_token,accessTokenExpire:e.access_token_expire};throw new Error("["+l+"]["+p.OPERATION_FAIL+"] action:getJwt not return refreshToken")}))]}))}))},t}(c);function w(){return y("code")||_("code")}var A=function(){var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(t,n)};return function(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),m=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{a(r.next(e))}catch(e){i(e)}}function c(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,c)}a((r=r.apply(e,t||[])).next())}))},I=function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}},O=o.constants.ERRORS,S=o.utils.throwError,T=o.utils.isString,E=function(e){function t(t){var n=e.call(this,t)||this;return n._onConverted=n._onConverted.bind(n),addEventListener(ce.ANONYMOUS_CONVERTED,n._onConverted),n}return A(t,e),t.prototype.signIn=function(){return m(this,void 0,void 0,(function(){var e,t,n,o,i,s,c;return I(this,(function(a){switch(a.label){case 0:return[4,this._cache.updatePersistenceAsync("local")];case 1:return a.sent(),e=this._cache.keys,t=e.anonymousUuidKey,n=e.refreshTokenKey,[4,this._cache.getStoreAsync(t)];case 2:return o=a.sent(),[4,this._cache.getStoreAsync(n)];case 3:return i=a.sent(),[4,this._request.send("auth.signInAnonymously",{anonymous_uuid:o,refresh_token:i})];case 4:return(s=a.sent()).uuid&&s.refresh_token?[4,this._setAnonymousUUID(s.uuid)]:[3,10];case 5:return a.sent(),[4,this.setRefreshToken(s.refresh_token)];case 6:return a.sent(),[4,this._request.refreshAccessToken()];case 7:return a.sent(),re.fire(ce.LOGIN_TYPE_CHANGED,{env:this._config.env,loginType:r.ANONYMOUS,persistence:"local"}),re.fire(ce.LOGIN_STATE_CHANGED),[4,(c=new ie({envId:this._config.env,cache:this._cache,request:this._request})).checkLocalStateAsync()];case 8:return a.sent(),[4,c.user.refresh()];case 9:return a.sent(),[2,c];case 10:S(O.OPERATION_FAIL,JSON.stringify(s)||"anonymous signIn failed"),a.label=11;case 11:return[2]}}))}))},t.prototype.linkAndRetrieveDataWithTicket=function(e){return m(this,void 0,void 0,(function(){var t,n,o,i,s,c,a;return I(this,(function(u){switch(u.label){case 0:return T(e)||S(O.INVALID_PARAMS,"ticket must be a string"),t=this._cache.keys,n=t.anonymousUuidKey,o=t.refreshTokenKey,[4,this._cache.getStoreAsync(n)];case 1:return i=u.sent(),[4,this._cache.getStoreAsync(o)];case 2:return s=u.sent(),[4,this._request.send("auth.linkAndRetrieveDataWithTicket",{anonymous_uuid:i,refresh_token:s,ticket:e})];case 3:return(c=u.sent()).refresh_token?[4,this._clearAnonymousUUID()]:[3,8];case 4:return u.sent(),[4,this.setRefreshToken(c.refresh_token)];case 5:return u.sent(),[4,this._request.refreshAccessToken()];case 6:return u.sent(),re.fire(ce.ANONYMOUS_CONVERTED,{env:this._config.env}),re.fire(ce.LOGIN_TYPE_CHANGED,{loginType:r.CUSTOM,persistence:"local"}),[4,(a=new ie({envId:this._config.env,cache:this._cache,request:this._request})).checkLocalStateAsync()];case 7:return u.sent(),[2,a];case 8:S(O.OPERATION_FAIL,JSON.stringify(c)||"linkAndRetrieveDataWithTicket failed"),u.label=9;case 9:return[2]}}))}))},t.prototype._setAnonymousUUID=function(e){return m(this,void 0,void 0,(function(){var t,n,o;return I(this,(function(i){switch(i.label){case 0:return t=this._cache.keys,n=t.anonymousUuidKey,o=t.loginTypeKey,[4,this._cache.removeStoreAsync(n)];case 1:return i.sent(),[4,this._cache.setStoreAsync(n,e)];case 2:return i.sent(),[4,this._cache.setStoreAsync(o,r.ANONYMOUS)];case 3:return i.sent(),[2]}}))}))},t.prototype._clearAnonymousUUID=function(){return m(this,void 0,void 0,(function(){return I(this,(function(e){switch(e.label){case 0:return[4,this._cache.removeStoreAsync(this._cache.keys.anonymousUuidKey)];case 1:return e.sent(),[2]}}))}))},t.prototype._onConverted=function(e){return m(this,void 0,void 0,(function(){return I(this,(function(t){switch(t.label){case 0:return e.data.env!==this._config.env?[2]:[4,this._cache.updatePersistenceAsync(this._config.persistence)];case 1:return t.sent(),[2]}}))}))},t}(c),k=function(){var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(t,n)};return function(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),P=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{a(r.next(e))}catch(e){i(e)}}function c(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,c)}a((r=r.apply(e,t||[])).next())}))},N=function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}},L=o.constants.ERRORS,R=o.utils.throwError,U=o.utils.isString,x=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return k(t,e),t.prototype.signIn=function(e){return P(this,void 0,void 0,(function(){var t,n,o,i,s,c,a;return N(this,(function(u){switch(u.label){case 0:return U(e)||R(L.INVALID_PARAMS,"ticket must be a string"),t=this._cache.keys.refreshTokenKey,i=(o=this._request).send,s=["auth.signInWithTicket"],c={ticket:e},[4,this._cache.getStoreAsync(t)];case 1:return[4,i.apply(o,s.concat([(c.refresh_token=u.sent()||"",c)]))];case 2:return(n=u.sent()).refresh_token?[4,this.setRefreshToken(n.refresh_token)]:[3,7];case 3:return u.sent(),[4,this._request.refreshAccessToken()];case 4:return u.sent(),re.fire(ce.LOGIN_TYPE_CHANGED,{env:this._config.env,loginType:r.CUSTOM,persistence:this._config.persistence}),re.fire(ce.LOGIN_STATE_CHANGED),[4,this.refreshUserInfo()];case 5:return u.sent(),[4,(a=new ie({envId:this._config.env,cache:this._cache,request:this._request})).checkLocalStateAsync()];case 6:return u.sent(),[2,a];case 7:R(L.OPERATION_FAIL,"custom signIn failed"),u.label=8;case 8:return[2]}}))}))},t}(c),C=function(){var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(t,n)};return function(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),q=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{a(r.next(e))}catch(e){i(e)}}function c(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,c)}a((r=r.apply(e,t||[])).next())}))},M=function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}},j=o.utils.throwError,D=o.utils.isString,K=o.constants.ERRORS,H=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return C(t,e),t.prototype.signIn=function(e,t){return q(this,void 0,void 0,(function(){var n,o,i,s,c;return M(this,(function(a){switch(a.label){case 0:return D(e)||j(K.INVALID_PARAMS,"email must be a string"),n=this._cache.keys.refreshTokenKey,[4,this._request.send("auth.signIn",{loginType:"EMAIL",email:e,password:t,refresh_token:this._cache.getStore(n)||""})];case 1:return o=a.sent(),i=o.refresh_token,s=o.access_token,c=o.access_token_expire,i?[4,this.setRefreshToken(i)]:[3,8];case 2:return a.sent(),s&&c?[4,this.setAccessToken(s,c)]:[3,4];case 3:return a.sent(),[3,6];case 4:return[4,this._request.refreshAccessToken()];case 5:a.sent(),a.label=6;case 6:return[4,this.refreshUserInfo()];case 7:return a.sent(),re.fire(ce.LOGIN_STATE_CHANGED),re.fire(ce.LOGIN_TYPE_CHANGED,{env:this._config.env,loginType:r.EMAIL,persistence:this._config.persistence}),[2,new ie({envId:this._config.env,cache:this._cache,request:this._request})];case 8:o.code?j(K.OPERATION_FAIL,"Email login fail["+o.code+"] "+o.message):j(K.OPERATION_FAIL,"Email login fail"),a.label=9;case 9:return[2]}}))}))},t.prototype.signUp=function(e,t){return q(this,void 0,void 0,(function(){return M(this,(function(n){return[2,this._request.send("auth.signUpWithEmailAndPassword",{email:e,password:t})]}))}))},t.prototype.resetPassword=function(e){return q(this,void 0,void 0,(function(){return M(this,(function(t){return[2,this._request.send("auth.sendPasswordResetEmail",{email:e})]}))}))},t.prototype.resetPasswordWithToken=function(e,t){return q(this,void 0,void 0,(function(){return M(this,(function(n){return[2,this._request.send("auth.resetPasswordWithToken",{token:e,newPassword:t})]}))}))},t.prototype.activate=function(e){return q(this,void 0,void 0,(function(){return M(this,(function(t){return[2,this._request.send("auth.activateEndUserMail",{token:e})]}))}))},t}(c),W=function(){var e=function(t,n){return(e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(t,n)};return function(t,n){function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),G=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{a(r.next(e))}catch(e){i(e)}}function c(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,c)}a((r=r.apply(e,t||[])).next())}))},B=function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}},V=o.utils.throwError,F=o.utils.printWarn,Y=o.constants.ERRORS,z=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return W(t,e),t.prototype.signIn=function(e,t){return G(this,void 0,void 0,(function(){var n,o,i,s,c,a,u,h,f;return B(this,(function(l){switch(l.label){case 0:return"string"!=typeof e&&V(Y.INVALID_PARAMS,"username must be a string"),"string"!=typeof t&&(t="",F(Y.INVALID_PARAMS,"password is empty")),n=this._cache.keys.refreshTokenKey,s=(i=this._request).send,c=["auth.signIn"],a={loginType:r.USERNAME,username:e,password:t},[4,this._cache.getStoreAsync(n)];case 1:return[4,s.apply(i,c.concat([(a.refresh_token=l.sent()||"",a)]))];case 2:return o=l.sent(),u=o.refresh_token,h=o.access_token_expire,f=o.access_token,u?[4,this.setRefreshToken(u)]:[3,9];case 3:return l.sent(),f&&h?[4,this.setAccessToken(f,h)]:[3,5];case 4:return l.sent(),[3,7];case 5:return[4,this._request.refreshAccessToken()];case 6:l.sent(),l.label=7;case 7:return[4,this.refreshUserInfo()];case 8:return l.sent(),re.fire(ce.LOGIN_STATE_CHANGED),re.fire(ce.LOGIN_TYPE_CHANGED,{env:this._config.env,loginType:r.USERNAME,persistence:this._config.persistence}),[2,new ie({envId:this._config.env,cache:this._cache,request:this._request})];case 9:o.code?V(Y.OPERATION_FAIL,"login failed:["+o.code+"] "+o.message):V(Y.OPERATION_FAIL,"login failed"),l.label=10;case 10:return[2]}}))}))},t}(c),J=function(){return(J=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)},X=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function s(e){try{a(r.next(e))}catch(e){i(e)}}function c(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,c)}a((r=r.apply(e,t||[])).next())}))},Q=function(e,t){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=t.call(e,s)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}},$=o.events.CloudbaseEventEmitter,Z=o.adapters.RUNTIME,ee=o.utils.printWarn,te=o.utils.throwError,ne=o.constants.ERRORS,re=new $,oe=function(){function e(e){var t=e.cache,n=e.request;this._cache=t,this._request=n,this._setUserInfo()}return e.prototype.checkLocalInfo=function(){return X(this,void 0,void 0,(function(){return Q(this,(function(e){return this.uid=this._getLocalUserInfo("uid"),this.loginType=this._getLocalUserInfo("loginType"),this.openid=this._getLocalUserInfo("wxOpenId"),this.wxOpenId=this._getLocalUserInfo("wxOpenId"),this.wxPublicId=this._getLocalUserInfo("wxPublicId"),this.unionId=this._getLocalUserInfo("wxUnionId"),this.qqMiniOpenId=this._getLocalUserInfo("qqMiniOpenId"),this.customUserId=this._getLocalUserInfo("customUserId"),this.nickName=this._getLocalUserInfo("nickName"),this.gender=this._getLocalUserInfo("gender"),this.avatarUrl=this._getLocalUserInfo("avatarUrl"),this.email=this._getLocalUserInfo("email"),this.hasPassword=Boolean(this._getLocalUserInfo("hasPassword")),this.location={country:this._getLocalUserInfo("country"),province:this._getLocalUserInfo("province"),city:this._getLocalUserInfo("city")},[2]}))}))},e.prototype.checkLocalInfoAsync=function(){return X(this,void 0,void 0,(function(){var e,t,n,r,o,i,s,c,a,u,h,f,l,p,d,y;return Q(this,(function(_){switch(_.label){case 0:return e=this,[4,this._getLocalUserInfoAsync("uid")];case 1:return e.uid=_.sent(),t=this,[4,this._getLocalUserInfoAsync("loginType")];case 2:return t.loginType=_.sent(),n=this,[4,this._getLocalUserInfoAsync("wxOpenId")];case 3:return n.openid=_.sent(),r=this,[4,this._getLocalUserInfoAsync("wxOpenId")];case 4:return r.wxOpenId=_.sent(),o=this,[4,this._getLocalUserInfoAsync("wxPublicId")];case 5:return o.wxPublicId=_.sent(),i=this,[4,this._getLocalUserInfoAsync("wxUnionId")];case 6:return i.unionId=_.sent(),s=this,[4,this._getLocalUserInfoAsync("qqMiniOpenId")];case 7:return s.qqMiniOpenId=_.sent(),c=this,[4,this._getLocalUserInfoAsync("customUserId")];case 8:return c.customUserId=_.sent(),a=this,[4,this._getLocalUserInfoAsync("nickName")];case 9:return a.nickName=_.sent(),u=this,[4,this._getLocalUserInfoAsync("gender")];case 10:return u.gender=_.sent(),h=this,[4,this._getLocalUserInfoAsync("avatarUrl")];case 11:return h.avatarUrl=_.sent(),f=this,[4,this._getLocalUserInfoAsync("email")];case 12:return f.email=_.sent(),l=this,p=Boolean,[4,this._getLocalUserInfoAsync("hasPassword")];case 13:return l.hasPassword=p.apply(void 0,[_.sent()]),d=this,y={},[4,this._getLocalUserInfoAsync("country")];case 14:return y.country=_.sent(),[4,this._getLocalUserInfoAsync("province")];case 15:return y.province=_.sent(),[4,this._getLocalUserInfoAsync("city")];case 16:return d.location=(y.city=_.sent(),y),[2]}}))}))},e.prototype.linkWithTicket=function(e){if("string"!=typeof e)throw new Error("ticket must be string");return this._request.send("auth.linkWithTicket",{ticket:e})},e.prototype.linkWithRedirect=function(e){e.signInWithRedirect()},e.prototype.getLinkedUidList=function(){return X(this,void 0,void 0,(function(){var e,t,n,r,o,i;return Q(this,(function(s){switch(s.label){case 0:return[4,this._request.send("auth.getLinkedUidList",{})];case 1:for(e=s.sent().data,t=!1,n=e.users,r=0,o=n;r<o.length;r++)if((i=o[r]).wxOpenId&&i.wxPublicId){t=!0;break}return[2,{users:n,hasPrimaryUid:t}]}}))}))},e.prototype.setPrimaryUid=function(e){return this._request.send("auth.setPrimaryUid",{uid:e})},e.prototype.unlink=function(e){return this._request.send("auth.unlink",{platform:e})},e.prototype.update=function(e){return X(this,void 0,void 0,(function(){var t,n,r,o,i,s,c;return Q(this,(function(a){switch(a.label){case 0:return t=e.nickName,n=e.gender,r=e.avatarUrl,o=e.province,i=e.country,s=e.city,[4,this._request.send("auth.updateUserInfo",{nickName:t,gender:n,avatarUrl:r,province:o,country:i,city:s})];case 1:return c=a.sent().data,this._setLocalUserInfo(c),[2]}}))}))},e.prototype.updatePassword=function(e,t){return this._request.send("auth.updatePassword",{oldPassword:t,newPassword:e})},e.prototype.updateEmail=function(e){return this._request.send("auth.updateEmail",{newEmail:e})},e.prototype.updateUsername=function(e){return"string"!=typeof e&&te(ne.INVALID_PARAMS,"username must be a string"),this._request.send("auth.updateUsername",{username:e})},e.prototype.refresh=function(){return X(this,void 0,void 0,(function(){var e;return Q(this,(function(t){switch(t.label){case 0:return"auth.getUserInfo",[4,this._request.send("auth.getUserInfo",{})];case 1:return e=t.sent().data,this._setLocalUserInfo(e),[2,e]}}))}))},e.prototype._getLocalUserInfo=function(e){var t=this._cache.keys.userInfoKey;return this._cache.getStore(t)[e]},e.prototype._getLocalUserInfoAsync=function(e){return X(this,void 0,void 0,(function(){var t;return Q(this,(function(n){switch(n.label){case 0:return t=this._cache.keys.userInfoKey,[4,this._cache.getStoreAsync(t)];case 1:return[2,n.sent()[e]]}}))}))},e.prototype._setUserInfo=function(){var e=this,t=this._cache.keys.userInfoKey,n=this._cache.getStore(t);["uid","loginType","openid","wxOpenId","wxPublicId","unionId","qqMiniOpenId","email","hasPassword","customUserId","nickName","gender","avatarUrl"].forEach((function(t){e[t]=n[t]})),this.location={country:n.country,province:n.province,city:n.city}},e.prototype._setLocalUserInfo=function(e){var t=this._cache.keys.userInfoKey;this._cache.setStore(t,e),this._setUserInfo()},e}(),ie=function(){function e(e){var t=e.envId,n=e.cache,r=e.request;t||te(ne.INVALID_PARAMS,"envId is not defined"),this._cache=n,this.user=new oe({cache:n,request:r})}return e.prototype.checkLocalState=function(){return X(this,void 0,void 0,(function(){var e,t,n,r,o,i,s;return Q(this,(function(c){return e=this._cache.keys,t=e.refreshTokenKey,n=e.accessTokenKey,r=e.accessTokenExpireKey,o=this._cache.getStore(t),i=this._cache.getStore(n),s=this._cache.getStore(r),this.credential={refreshToken:o,accessToken:i,accessTokenExpire:s},this._loginType=this._cache.getStore(this._cache.keys.loginTypeKey),this.user.checkLocalInfo(),[2]}))}))},e.prototype.checkLocalStateAsync=function(){return X(this,void 0,void 0,(function(){var e,t,n,r,o,i,s,c;return Q(this,(function(a){switch(a.label){case 0:return e=this._cache.keys,t=e.refreshTokenKey,n=e.accessTokenKey,r=e.accessTokenExpireKey,[4,this._cache.getStoreAsync(t)];case 1:return o=a.sent(),[4,this._cache.getStoreAsync(n)];case 2:return i=a.sent(),[4,this._cache.getStoreAsync(r)];case 3:return s=a.sent(),this.credential={refreshToken:o,accessToken:i,accessTokenExpire:s},c=this,[4,this._cache.getStoreAsync(this._cache.keys.loginTypeKey)];case 4:return c._loginType=a.sent(),[4,this.user.checkLocalInfoAsync()];case 5:return a.sent(),[2]}}))}))},Object.defineProperty(e.prototype,"isAnonymousAuth",{get:function(){return this.loginType===r.ANONYMOUS},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isCustomAuth",{get:function(){return this.loginType===r.CUSTOM},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isWeixinAuth",{get:function(){return this.loginType===r.WECHAT||this.loginType===r.WECHAT_OPEN||this.loginType===r.WECHAT_PUBLIC},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isUsernameAuth",{get:function(){return this.loginType===r.USERNAME},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"loginType",{get:function(){return this._loginType},enumerable:!1,configurable:!0}),e}(),se=function(){function e(e){this._config=e,this._cache=e.cache,this._request=e.request,this._runtime=e.runtime||Z.WEB,re.on(ce.LOGIN_TYPE_CHANGED,this._onLoginTypeChanged.bind(this))}return Object.defineProperty(e.prototype,"currentUser",{get:function(){if("async"!==this._cache.mode){var e=this.hasLoginState();return e&&e.user||null}ee(ne.INVALID_OPERATION,"current platform's storage is asynchronous, please use getCurrenUser insteed")},enumerable:!1,configurable:!0}),e.prototype.getCurrenUser=function(){return X(this,void 0,void 0,(function(){var e;return Q(this,(function(t){switch(t.label){case 0:return[4,this.getLoginState()];case 1:return(e=t.sent())?[4,e.user.checkLocalInfoAsync()]:[3,3];case 2:return t.sent(),[2,e.user||null];case 3:return[2,null]}}))}))},Object.defineProperty(e.prototype,"loginType",{get:function(){return this._cache.getStore(this._cache.keys.loginTypeKey)},enumerable:!1,configurable:!0}),e.prototype.getLoginType=function(){return X(this,void 0,void 0,(function(){return Q(this,(function(e){switch(e.label){case 0:return[4,this._cache.getStoreAsync(this._cache.keys.loginTypeKey)];case 1:return[2,e.sent()]}}))}))},e.prototype.getAccessToken=function(){return X(this,void 0,void 0,(function(){var e;return Q(this,(function(t){switch(t.label){case 0:return e={},[4,this._request.getAccessToken()];case 1:return[2,(e.accessToken=t.sent().accessToken,e.env=this._config.env,e)]}}))}))},e.prototype.weixinAuthProvider=function(e){var t=e.appid,n=e.scope,r=e.state;return this._weixinAuthProvider||(this._weixinAuthProvider=new b(J(J({},this._config),{cache:this._cache,request:this._request,runtime:this._runtime}),t,n,r)),this._weixinAuthProvider},e.prototype.anonymousAuthProvider=function(){return this._anonymousAuthProvider||(this._anonymousAuthProvider=new E(J(J({},this._config),{cache:this._cache,request:this._request}))),this._anonymousAuthProvider},e.prototype.customAuthProvider=function(){return this._customAuthProvider||(this._customAuthProvider=new x(J(J({},this._config),{cache:this._cache,request:this._request}))),this._customAuthProvider},e.prototype.emailAuthProvider=function(){return this._emailAuthProvider||(this._emailAuthProvider=new H(J(J({},this._config),{cache:this._cache,request:this._request}))),this._emailAuthProvider},e.prototype.usernameAuthProvider=function(){return this._usernameAuthProvider||(this._usernameAuthProvider=new z(J(J({},this._config),{cache:this._cache,request:this._request}))),this._usernameAuthProvider},e.prototype.signInWithUsernameAndPassword=function(e,t){return X(this,void 0,void 0,(function(){return Q(this,(function(n){return[2,this._usernameAuthProvider.signIn(e,t)]}))}))},e.prototype.isUsernameRegistered=function(e){return X(this,void 0,void 0,(function(){var t;return Q(this,(function(n){switch(n.label){case 0:return"string"!=typeof e&&te(ne.INVALID_PARAMS,"username must be a string"),[4,this._request.send("auth.isUsernameRegistered",{username:e})];case 1:return[2,null==(t=n.sent().data)?void 0:t.isRegistered]}}))}))},e.prototype.signInWithEmailAndPassword=function(e,t){return X(this,void 0,void 0,(function(){return Q(this,(function(n){return[2,this.emailAuthProvider().signIn(e,t)]}))}))},e.prototype.signUpWithEmailAndPassword=function(e,t){return X(this,void 0,void 0,(function(){return Q(this,(function(n){return[2,this.emailAuthProvider().signUp(e,t)]}))}))},e.prototype.sendPasswordResetEmail=function(e){return X(this,void 0,void 0,(function(){return Q(this,(function(t){return[2,this.emailAuthProvider().resetPassword(e)]}))}))},e.prototype.signOut=function(){return X(this,void 0,void 0,(function(){var e,t,n,o,i,s,c;return Q(this,(function(a){switch(a.label){case 0:return[4,this.getLoginType()];case 1:return a.sent()===r.ANONYMOUS&&te(ne.INVALID_OPERATION,"anonymous user doesn't support signOut action"),e=this._cache.keys,t=e.refreshTokenKey,n=e.accessTokenKey,o=e.accessTokenExpireKey,i="auth.logout",[4,this._cache.getStoreAsync(t)];case 2:return(s=a.sent())?[4,this._request.send(i,{refresh_token:s})]:[2];case 3:return c=a.sent(),this._cache.removeStoreAsync(t),this._cache.removeStoreAsync(n),this._cache.removeStoreAsync(o),re.fire(ce.LOGIN_STATE_CHANGED),re.fire(ce.LOGIN_TYPE_CHANGED,{env:this._config.env,loginType:r.NULL,persistence:this._config.persistence}),[2,c]}}))}))},e.prototype.onLoginStateChanged=function(e){return X(this,void 0,void 0,(function(){var t,n=this;return Q(this,(function(r){switch(r.label){case 0:return re.on(ce.LOGIN_STATE_CHANGED,(function(){return X(n,void 0,void 0,(function(){var t;return Q(this,(function(n){switch(n.label){case 0:return[4,this.getLoginState()];case 1:return t=n.sent(),e.call(this,t),[2]}}))}))})),[4,this.getLoginState()];case 1:return t=r.sent(),e.call(this,t),[2]}}))}))},e.prototype.onLoginStateExpired=function(e){re.on(ce.LOGIN_STATE_EXPIRED,e.bind(this))},e.prototype.onAccessTokenRefreshed=function(e){re.on(ce.ACCESS_TOKEN_REFRESHD,e.bind(this))},e.prototype.onAnonymousConverted=function(e){re.on(ce.ANONYMOUS_CONVERTED,e.bind(this))},e.prototype.onLoginTypeChanged=function(e){var t=this;re.on(ce.LOGIN_TYPE_CHANGED,(function(){return X(t,void 0,void 0,(function(){var t;return Q(this,(function(n){switch(n.label){case 0:return[4,this.getLoginState()];case 1:return t=n.sent(),e.call(this,t),[2]}}))}))}))},e.prototype.hasLoginState=function(){if("async"!==this._cache.mode){var e=this._cache.keys.refreshTokenKey;if(this._cache.getStore(e)){var t=new ie({envId:this._config.env,cache:this._cache,request:this._request});return t.checkLocalState(),t}return null}ee(ne.INVALID_OPERATION,"current platform's storage is asynchronous, please use getLoginState insteed")},e.prototype.getLoginState=function(){return X(this,void 0,void 0,(function(){var e,t;return Q(this,(function(n){switch(n.label){case 0:return e=this._cache.keys.refreshTokenKey,[4,this._cache.getStoreAsync(e)];case 1:return n.sent()?[4,(t=new ie({envId:this._config.env,cache:this._cache,request:this._request})).checkLocalStateAsync()]:[3,3];case 2:return n.sent(),[2,t];case 3:return[2,null]}}))}))},e.prototype.shouldRefreshAccessToken=function(e){this._request._shouldRefreshAccessTokenHook=e.bind(this)},e.prototype.getUserInfo=function(){return X(this,void 0,void 0,(function(){var e;return Q(this,(function(t){switch(t.label){case 0:return"auth.getUserInfo",[4,this._request.send("auth.getUserInfo",{})];case 1:return(e=t.sent()).code?[2,e]:[2,J(J({},e.data),{requestId:e.seqId})]}}))}))},e.prototype.getAuthHeader=function(){if("async"!==this._cache.mode){var e=this._cache.keys,t=e.refreshTokenKey,n=e.accessTokenKey,r=this._cache.getStore(t);return{"x-cloudbase-credentials":this._cache.getStore(n)+"/@@/"+r}}ee(ne.INVALID_OPERATION,"current platform's storage is asynchronous, please use getAuthHeaderAsync insteed")},e.prototype.getAuthHeaderAsync=function(){return X(this,void 0,void 0,(function(){var e,t,n,r;return Q(this,(function(o){switch(o.label){case 0:return e=this._cache.keys,t=e.refreshTokenKey,n=e.accessTokenKey,[4,this._cache.getStoreAsync(t)];case 1:return r=o.sent(),[4,this._cache.getStoreAsync(n)];case 2:return[2,{"x-cloudbase-credentials":o.sent()+"/@@/"+r}]}}))}))},e.prototype._onLoginTypeChanged=function(e){return X(this,void 0,void 0,(function(){var t,n,r;return Q(this,(function(o){switch(o.label){case 0:return t=e.data,n=t.loginType,r=t.persistence,t.env!==this._config.env?[2]:[4,this._cache.updatePersistenceAsync(r)];case 1:return o.sent(),[4,this._cache.setStoreAsync(this._cache.keys.loginTypeKey,n)];case 2:return o.sent(),[2]}}))}))},e}(),ce={LOGIN_STATE_CHANGED:"loginStateChanged",LOGIN_STATE_EXPIRED:"loginStateExpire",LOGIN_TYPE_CHANGED:"loginTypeChanged",ANONYMOUS_CONVERTED:"anonymousConverted",ACCESS_TOKEN_REFRESHD:"refreshAccessToken"},ae={name:"auth",namespace:"auth",injectEvents:{bus:re,events:[ce.LOGIN_TYPE_CHANGED,ce.LOGIN_STATE_EXPIRED,ce.LOGIN_STATE_CHANGED,ce.ACCESS_TOKEN_REFRESHD,ce.ANONYMOUS_CONVERTED]},entity:function(e){if(void 0===e&&(e={persistence:"session"}),this.authInstance)return ee(ne.INVALID_OPERATION,"every cloudbase instance should has only one auth object"),this.authInstance;var t=this.platform,n=t.adapter,r=t.runtime,o=e.persistence||n.primaryStorage;o&&o!==this.config.persistence&&this.updateConfig({persistence:o});var i=this.config,s=i.env,c=i.persistence,a=i.debug;return this.authInstance=new se({env:s,persistence:c,debug:a,cache:this.cache,request:this.request,runtime:r}),this.authInstance}};try{cloudbase.registerComponent(ae)}catch(e){}function ue(e){e.registerComponent(ae)}function he(e,t){se.prototype[e]=function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];var o="_"+e;return this[o]||(this[o]=new t(J(J({},n),{cache:this._cache,request:this._request,runtime:this._runtime}))),this[o]}}}])}));