@cloudbase/oauth 2.5.44-beta.0 → 2.5.46-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudbase/oauth",
3
- "version": "2.5.44-beta.0",
3
+ "version": "2.5.46-beta.0",
4
4
  "description": "cloudbase javascript sdk auth componets",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -21,5 +21,5 @@
21
21
  "encryptlong": "^3.1.4"
22
22
  },
23
23
  "license": "Apache-2.0",
24
- "gitHead": "f3612f789fe731b7ac25f5fb0eaf6c5a07d011ba"
24
+ "gitHead": "b90d74de0cdcc63ba408acbafc7a7c386f582291"
25
25
  }
package/src/auth/apis.ts CHANGED
@@ -44,6 +44,11 @@ import {
44
44
  PublicKey,
45
45
  EncryptParams,
46
46
  ProviderSubType,
47
+ GetMiniProgramQrCodeRequest,
48
+ GetMiniProgramQrCodeStatusRequest,
49
+ GetMiniProgramQrCodeResponse,
50
+ GetMiniProgramQrCodeStatusResponse,
51
+ ModifyUserBasicInfoRequest,
47
52
  } from './models'
48
53
  import { SimpleStorage, RequestFunction } from '../oauth2client/interface'
49
54
  import { OAuth2Client, defaultStorage } from '../oauth2client/oauth2client'
@@ -308,6 +313,19 @@ export class Auth {
308
313
  return Promise.resolve(credentials)
309
314
  }
310
315
 
316
+ /**
317
+ * sign in with wechat idendify
318
+ * 需要结合 http overcallFunction 使用
319
+ */
320
+ public async signInWithWechat(params: any = {}): Promise<Credentials> {
321
+ const credentials: Credentials = await this.config.request<Credentials>(ApiUrls.AUTH_SIGN_IN_WITH_WECHAT_URL, {
322
+ method: 'POST',
323
+ body: params,
324
+ })
325
+ await this.config.credentialsClient.setCredentials(credentials)
326
+ return Promise.resolve(credentials)
327
+ }
328
+
311
329
  /**
312
330
  * Bind with provider
313
331
  * @param {BindWithProviderRequest} params A BindWithProviderRequest object.
@@ -570,6 +588,18 @@ export class Auth {
570
588
  })
571
589
  }
572
590
 
591
+ /**
592
+ * Update user basic info
593
+ * @return {Promise<void>}
594
+ */
595
+ public async updateUserBasicInfo(params: ModifyUserBasicInfoRequest): Promise<void> {
596
+ return this.config.request(ApiUrls.USER_BASIC_EDIT_URL, {
597
+ method: 'POST',
598
+ withCredentials: true,
599
+ body: params,
600
+ })
601
+ }
602
+
573
603
  /**
574
604
  * Patch the user profile.
575
605
  * @param {QueryUserProfileReq} appended_params A QueryUserProfileReq Object.
@@ -731,8 +761,8 @@ export class Auth {
731
761
  * get provider sub type
732
762
  * @returns
733
763
  */
734
- public async varifyCaptchaData({ token, key }: { token: string; key: string }) {
735
- return this.config.request<{ captcha_token: string; expires_in: number }>(ApiUrls.VARIFY_CAPTCHA_DATA_URL, {
764
+ public async verifyCaptchaData({ token, key }: { token: string; key: string }) {
765
+ return this.config.request<{ captcha_token: string; expires_in: number }>(ApiUrls.VERIFY_CAPTCHA_DATA_URL, {
736
766
  method: 'POST',
737
767
  body: { token, key },
738
768
  withCredentials: false,
@@ -746,4 +776,26 @@ export class Auth {
746
776
  withCredentials: false,
747
777
  })
748
778
  }
779
+
780
+ /**
781
+ * mini-program scan code
782
+ * @returns
783
+ */
784
+ public async getMiniProgramCode(params: GetMiniProgramQrCodeRequest): Promise<GetMiniProgramQrCodeResponse> {
785
+ return this.config.request<GetMiniProgramQrCodeResponse>(ApiUrls.GET_MINIPROGRAM_QRCODE, {
786
+ method: 'POST',
787
+ body: params,
788
+ })
789
+ }
790
+
791
+ /**
792
+ * mini-program scan code status
793
+ * @returns
794
+ */
795
+ public async checkMiniProgramCode(params: GetMiniProgramQrCodeStatusRequest,): Promise<GetMiniProgramQrCodeStatusResponse> {
796
+ return this.config.request<GetMiniProgramQrCodeStatusResponse>(ApiUrls.GET_MINIPROGRAM_QRCODE_STATUS, {
797
+ method: 'POST',
798
+ body: params,
799
+ })
800
+ }
749
801
  }
@@ -2,6 +2,7 @@ export enum ApiUrls {
2
2
  AUTH_SIGN_IN_URL = '/auth/v1/signin',
3
3
  AUTH_SIGN_IN_ANONYMOUSLY_URL = '/auth/v1/signin/anonymously',
4
4
  AUTH_SIGN_IN_WITH_PROVIDER_URL = '/auth/v1/signin/with/provider',
5
+ AUTH_SIGN_IN_WITH_WECHAT_URL = '/auth/v1/signin/wechat/noauth',
5
6
  AUTH_SIGN_UP_URL = '/auth/v1/signup',
6
7
  AUTH_TOKEN_URL = '/auth/v1/token',
7
8
  AUTH_REVOKE_URL = '/auth/v1/revoke',
@@ -12,11 +13,12 @@ export enum ApiUrls {
12
13
  WEDA_USER_URL = '/auth/v1/plugin/weda/userinfo',
13
14
  USER_QUERY_URL = '/auth/v1/user/query',
14
15
  USER_PRIFILE_URL = '/auth/v1/user/profile',
16
+ USER_BASIC_EDIT_URL = '/auth/v1/user/basic/edit',
15
17
  USER_TRANS_BY_PROVIDER_URL = '/auth/v1/user/trans/by/provider',
16
18
  VERIFICATION_URL = '/auth/v1/verification',
17
19
  VERIFY_URL = '/auth/v1/verification/verify',
18
20
  CAPTCHA_DATA_URL = '/auth/v1/captcha/data',
19
- VARIFY_CAPTCHA_DATA_URL = '/auth/v1/captcha/data/verify',
21
+ VERIFY_CAPTCHA_DATA_URL = '/auth/v1/captcha/data/verify',
20
22
  GET_CAPTCHA_URL = '/auth/v1/captcha/init',
21
23
 
22
24
  PROVIDER_LIST = '/auth/v1/user/provider',
@@ -30,6 +32,9 @@ export enum ApiUrls {
30
32
  CHECK_USERNAME = '/auth/v1/checkUsername',
31
33
  CHECK_IF_USER_EXIST = '/auth/v1/checkIfUserExist',
32
34
  GET_PROVIDER_TYPE = '/auth/v1/mgr/provider/providerSubType',
35
+
36
+ GET_MINIPROGRAM_QRCODE = '/auth/v1/qrcode/generate',
37
+ GET_MINIPROGRAM_QRCODE_STATUS = '/auth/v1/qrcode/get/status',
33
38
  }
34
39
 
35
40
  export enum ApiUrlsV2 {
@@ -469,3 +469,34 @@ export interface ProviderSubType {
469
469
  id: string;
470
470
  provider_sub_type: 'NO_AUTH_LOGIN' | ''; // NO_AUTH_LOGIN-免密登录
471
471
  }
472
+
473
+ export interface GetMiniProgramQrCodeRequest {
474
+ envId: string;
475
+ wxAppId: string;
476
+ }
477
+
478
+ export interface GetMiniProgramQrCodeResponse {
479
+ qr_code: string;
480
+ qr_code_id: string;
481
+ expires_in: number;
482
+ }
483
+
484
+ export interface GetMiniProgramQrCodeStatusRequest {
485
+ qrCodeId: string;
486
+ envId: string;
487
+ wxAppId: string;
488
+ }
489
+
490
+ export interface GetMiniProgramQrCodeStatusResponse {
491
+ status: string;
492
+ provider_token: string;
493
+ expires_in: number;
494
+ }
495
+
496
+ export interface ModifyUserBasicInfoRequest {
497
+ user_id: string;
498
+ nickname: string;
499
+ username: string;
500
+ description: string;
501
+ avatar_url: string;
502
+ }
package/src/utils/mp.ts CHANGED
@@ -37,17 +37,22 @@ export function isMp() {
37
37
  return true
38
38
  }
39
39
 
40
- let IS_IN_MP_WEBVIEW = !!navigator.userAgent.match(/miniprogram/i) || (window as any).__wxjs_environment === 'miniprogram'
40
+ let IS_IN_MP_WEBVIEW = false
41
41
  function ready() {
42
42
  IS_IN_MP_WEBVIEW = IS_IN_MP_WEBVIEW || (typeof window !== undefined && (window as any).__wxjs_environment === 'miniprogram')
43
43
  }
44
- if (!isMp()) {
45
- if ((window as any)?.WeixinJSBridge?.invoke) {
46
- ready()
47
- } else if (typeof document !== 'undefined') {
48
- document.addEventListener?.('WeixinJSBridgeReady', ready, false)
44
+ try {
45
+ if (!isMp()) {
46
+ IS_IN_MP_WEBVIEW = IS_IN_MP_WEBVIEW
47
+ || !!navigator.userAgent.match(/miniprogram/i)
48
+ || (window as any).__wxjs_environment === 'miniprogram'
49
+ if ((window as any) && (window as any).WeixinJSBridge && (window as any).WeixinJSBridge.invoke) {
50
+ ready()
51
+ } else if (typeof document !== 'undefined') {
52
+ document.addEventListener('WeixinJSBridgeReady', ready, false)
53
+ }
49
54
  }
50
- }
55
+ } catch (e) {}
51
56
  export function isInMpWebView() {
52
57
  return IS_IN_MP_WEBVIEW
53
58
  }