@cloudbase/oauth 2.5.49-beta.0 → 2.5.49-beta.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 (39) hide show
  1. package/dist/cjs/auth/apis.d.ts +13 -6
  2. package/dist/cjs/auth/apis.js +94 -18
  3. package/dist/cjs/auth/consts.d.ts +5 -0
  4. package/dist/cjs/auth/consts.js +6 -1
  5. package/dist/cjs/auth/models.d.ts +60 -2
  6. package/dist/cjs/auth/models.js +1 -1
  7. package/dist/cjs/index.d.ts +2 -1
  8. package/dist/cjs/index.js +1 -1
  9. package/dist/cjs/oauth2client/models.d.ts +1 -0
  10. package/dist/cjs/oauth2client/models.js +1 -1
  11. package/dist/cjs/oauth2client/oauth2client.d.ts +5 -0
  12. package/dist/cjs/oauth2client/oauth2client.js +23 -14
  13. package/dist/cjs/utils/base64.d.ts +4 -0
  14. package/dist/cjs/utils/base64.js +99 -0
  15. package/dist/cjs/utils/encryptlong/index.js +4 -3
  16. package/dist/esm/auth/apis.d.ts +13 -6
  17. package/dist/esm/auth/apis.js +94 -18
  18. package/dist/esm/auth/consts.d.ts +5 -0
  19. package/dist/esm/auth/consts.js +6 -1
  20. package/dist/esm/auth/models.d.ts +60 -2
  21. package/dist/esm/auth/models.js +1 -1
  22. package/dist/esm/index.d.ts +2 -1
  23. package/dist/esm/index.js +1 -1
  24. package/dist/esm/oauth2client/models.d.ts +1 -0
  25. package/dist/esm/oauth2client/models.js +1 -1
  26. package/dist/esm/oauth2client/oauth2client.d.ts +5 -0
  27. package/dist/esm/oauth2client/oauth2client.js +23 -14
  28. package/dist/esm/utils/base64.d.ts +4 -0
  29. package/dist/esm/utils/base64.js +92 -0
  30. package/dist/esm/utils/encryptlong/index.js +4 -3
  31. package/package.json +2 -2
  32. package/src/auth/apis.ts +102 -30
  33. package/src/auth/consts.ts +5 -0
  34. package/src/auth/models.ts +103 -38
  35. package/src/index.ts +3 -9
  36. package/src/oauth2client/models.ts +1 -0
  37. package/src/oauth2client/oauth2client.ts +27 -16
  38. package/src/utils/base64.ts +100 -0
  39. package/src/utils/encryptlong/index.js +3 -2
@@ -0,0 +1,100 @@
1
+ /* eslint-disable */
2
+ // weapp jwt-decode
3
+ const b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
4
+ const b64re = /^(?:[A-Za-z\d+/]{4})*?(?:[A-Za-z\d+/]{2}(?:==)?|[A-Za-z\d+/]{3}=?)?$/
5
+
6
+ // btoa
7
+ export function weBtoa(string: string) {
8
+ string = String(string)
9
+ let bitmap
10
+ let a
11
+ let b
12
+ let c
13
+ let result = ''
14
+ let i = 0
15
+ const rest = string.length % 3
16
+
17
+ for (; i < string.length;) {
18
+ if ((a = string.charCodeAt(i++)) > 255 || (b = string.charCodeAt(i++)) > 255 || (c = string.charCodeAt(i++)) > 255) throw new TypeError('Failed to execute \'btoa\' on \'Window\': The string to be encoded contains characters outside of the Latin1 range.',)
19
+
20
+ bitmap = (a << 16) | (b << 8) | c
21
+ result
22
+ += b64.charAt((bitmap >> 18) & 63)
23
+ + b64.charAt((bitmap >> 12) & 63)
24
+ + b64.charAt((bitmap >> 6) & 63)
25
+ + b64.charAt(bitmap & 63)
26
+ }
27
+
28
+ return rest ? result.slice(0, rest - 3) + '==='.substring(rest) : result
29
+ }
30
+ // atob
31
+ export const weAtob = function (string: string) {
32
+ string = String(string).replace(/[\t\n\f\r ]+/g, '')
33
+ if (!b64re.test(string)) throw new TypeError('Failed to execute \'atob\' on \'Window\': The string to be decoded is not correctly encoded.')
34
+ string += '=='.slice(2 - (string.length & 3))
35
+ let bitmap
36
+ let result = ''
37
+ let r1
38
+ let r2
39
+ let i = 0
40
+ for (; i < string.length;) {
41
+ bitmap = (b64.indexOf(string.charAt(i++)) << 18)
42
+ | (b64.indexOf(string.charAt(i++)) << 12)
43
+ | ((r1 = b64.indexOf(string.charAt(i++))) << 6)
44
+ | (r2 = b64.indexOf(string.charAt(i++)))
45
+
46
+ result
47
+ += r1 === 64
48
+ ? String.fromCharCode((bitmap >> 16) & 255)
49
+ : r2 === 64
50
+ ? String.fromCharCode((bitmap >> 16) & 255, (bitmap >> 8) & 255)
51
+ : String.fromCharCode((bitmap >> 16) & 255, (bitmap >> 8) & 255, bitmap & 255)
52
+ }
53
+ return result
54
+ }
55
+
56
+ function b64DecodeUnicode(str: string) {
57
+ return decodeURIComponent(weAtob(str).replace(/(.)/g, (p) => {
58
+ let code = p.charCodeAt(0).toString(16)
59
+ .toUpperCase()
60
+ if (code.length < 2) {
61
+ code = `0${code}`
62
+ }
63
+ return `%${code}`
64
+ }),)
65
+ }
66
+
67
+ export function base64_url_decode(str: string) {
68
+ let output = str.replace(/-/g, '+').replace(/_/g, '/')
69
+ switch (output.length % 4) {
70
+ case 0:
71
+ break
72
+ case 2:
73
+ output += '=='
74
+ break
75
+ case 3:
76
+ output += '='
77
+ break
78
+ default:
79
+ throw new Error('Illegal base64url string!')
80
+ }
81
+
82
+ try {
83
+ return b64DecodeUnicode(output)
84
+ } catch (err) {
85
+ return weAtob(output)
86
+ }
87
+ }
88
+
89
+ export function weappJwtDecode(token: string, options?: any) {
90
+ if (typeof token !== 'string') {
91
+ throw new Error('Invalid token specified')
92
+ }
93
+ options = options || {}
94
+ const pos = options.header === true ? 0 : 1
95
+ try {
96
+ return JSON.parse(base64_url_decode(token.split('.')[pos]))
97
+ } catch (e) {
98
+ throw new Error(`Invalid token specified: ${e}` ? (e as any).message : '')
99
+ }
100
+ }
@@ -1,5 +1,6 @@
1
1
  /* eslint-disable */
2
2
  /* tslint:disable */
3
+ const navigator = typeof globalThis !== 'undefined' ? globalThis.navigator : window.globalThis;
3
4
  var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz";
4
5
  function int2char(n) {
5
6
  return BI_RM.charAt(n);
@@ -2606,7 +2607,7 @@ function am3(i, x, w, j, c, n) {
2606
2607
  }
2607
2608
  return c;
2608
2609
  }
2609
- if (j_lm && (navigator?.appName == "Microsoft Internet Explorer")) {
2610
+ if (j_lm && (typeof navigator !== 'undefined' && navigator?.appName == "Microsoft Internet Explorer")) {
2610
2611
  BigInteger.prototype.am = am2;
2611
2612
  dbits = 30;
2612
2613
  }
@@ -3296,7 +3297,7 @@ YAHOO.lang = {
3296
3297
  var _IEEnumFix = function () { },
3297
3298
  ADD = ["toString", "valueOf"];
3298
3299
  try {
3299
- if (/MSIE/.test(navigator.userAgent)) {
3300
+ if (typeof navigator !== 'undefined' && /MSIE/.test(navigator.userAgent)) {
3300
3301
  _IEEnumFix = function (r, s) {
3301
3302
  for (i = 0; i < ADD.length; i = i + 1) {
3302
3303
  var fname = ADD[i], f = s[fname];