@cloudbase/utilities 3.0.0 → 3.0.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.
- package/dist/cjs/adapters/index.d.ts +12 -2
- package/dist/cjs/adapters/index.js +2 -2
- package/dist/cjs/adapters/platforms/web.d.ts +3 -1
- package/dist/cjs/adapters/platforms/web.js +11 -7
- package/dist/cjs/constants/common.d.ts +1 -1
- package/dist/cjs/constants/common.js +2 -2
- package/dist/cjs/libs/abortController.js +1 -1
- package/dist/cjs/libs/util.d.ts +13 -0
- package/dist/cjs/libs/util.js +48 -7
- package/dist/esm/adapters/index.d.ts +12 -2
- package/dist/esm/adapters/index.js +2 -2
- package/dist/esm/adapters/platforms/web.d.ts +3 -1
- package/dist/esm/adapters/platforms/web.js +11 -7
- package/dist/esm/constants/common.d.ts +1 -1
- package/dist/esm/constants/common.js +2 -2
- package/dist/esm/libs/abortController.js +1 -1
- package/dist/esm/libs/util.d.ts +13 -0
- package/dist/esm/libs/util.js +46 -6
- package/dist/miniprogram/index.js +1 -1
- package/package.json +3 -3
- package/src/adapters/index.ts +2 -2
- package/src/adapters/platforms/web.ts +11 -5
- package/src/constants/common.ts +2 -2
- package/src/libs/abortController.ts +1 -0
- package/src/libs/util.ts +48 -16
- package/tsconfig.json +1 -1
package/src/libs/util.ts
CHANGED
|
@@ -28,7 +28,7 @@ export function genSeqId(): string {
|
|
|
28
28
|
}
|
|
29
29
|
export function generateRequestId() {
|
|
30
30
|
let d = new Date().getTime()
|
|
31
|
-
let d2 = (Date?.now &&
|
|
31
|
+
let d2 = (Date?.now && Date.now() * 1000) || 0
|
|
32
32
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
33
33
|
let r = Math.random() * 16
|
|
34
34
|
if (d > 0) {
|
|
@@ -38,7 +38,7 @@ export function generateRequestId() {
|
|
|
38
38
|
r = (d2 + r) % 16 | 0
|
|
39
39
|
d2 = Math.floor(d2 / 16)
|
|
40
40
|
}
|
|
41
|
-
return (c === 'x' ? r : (
|
|
41
|
+
return (c === 'x' ? r : (r & 0x7) | 0x8).toString(16)
|
|
42
42
|
})
|
|
43
43
|
}
|
|
44
44
|
export function formatUrl(PROTOCOL: string, url: string, query: KV<any> = {}): string {
|
|
@@ -72,10 +72,10 @@ export function getQuery(name: string, url?: string) {
|
|
|
72
72
|
return false
|
|
73
73
|
}
|
|
74
74
|
// 参数:变量名,url为空则表从当前页面的url中取
|
|
75
|
-
const u = url || window.location.search
|
|
75
|
+
const u = url || decodeURIComponent(window.location.search)
|
|
76
76
|
const reg = new RegExp(`(^|&)${name}=([^&]*)(&|$)`)
|
|
77
77
|
const r = u.substr(u.indexOf('?') + 1).match(reg)
|
|
78
|
-
return
|
|
78
|
+
return r !== null && r !== undefined ? r[2] : ''
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
export const getHash = function (name: string) {
|
|
@@ -106,14 +106,14 @@ export function removeParam(key: string, sourceURL: string) {
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
export function createPromiseCallback() {
|
|
109
|
-
let cb: any
|
|
109
|
+
let cb: any = {}
|
|
110
110
|
if (!Promise) {
|
|
111
|
-
cb = () => {
|
|
111
|
+
cb = () => {}
|
|
112
112
|
cb.promise = {}
|
|
113
113
|
|
|
114
114
|
const throwPromiseNotDefined = () => {
|
|
115
115
|
throw new Error('Your Node runtime does support ES6 Promises. '
|
|
116
|
-
|
|
116
|
+
+ 'Set "global.Promise" to your preferred implementation of promises.',)
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
Object.defineProperty(cb.promise, 'then', { get: throwPromiseNotDefined })
|
|
@@ -158,18 +158,18 @@ export function throwError(error: string, msg: string) {
|
|
|
158
158
|
throw new Error(JSON.stringify({
|
|
159
159
|
code: error,
|
|
160
160
|
msg: `[${getSdkName()}][${error}]:${msg}`,
|
|
161
|
-
}))
|
|
161
|
+
}),)
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
interface IPrintGroupLogOptions {
|
|
165
|
-
title: string
|
|
166
|
-
subtitle: string | object
|
|
165
|
+
title: string
|
|
166
|
+
subtitle: string | object
|
|
167
167
|
content: {
|
|
168
|
-
type: 'info' | 'warn' | 'error'
|
|
169
|
-
body: string | Error
|
|
170
|
-
}[]
|
|
171
|
-
printTrace?: boolean
|
|
172
|
-
collapsed?: boolean
|
|
168
|
+
type: 'info' | 'warn' | 'error'
|
|
169
|
+
body: string | Error
|
|
170
|
+
}[]
|
|
171
|
+
printTrace?: boolean
|
|
172
|
+
collapsed?: boolean
|
|
173
173
|
}
|
|
174
174
|
export function printGroupLog(options: IPrintGroupLogOptions) {
|
|
175
175
|
const { title, subtitle = '', content = [], printTrace = false, collapsed = false } = options
|
|
@@ -204,7 +204,6 @@ export function transformPhone(phoneNumber: string) {
|
|
|
204
204
|
return `+86${phoneNumber}`
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
-
|
|
208
207
|
export const parseQueryString = (queryString) => {
|
|
209
208
|
queryString = queryString.replace(/^\?/, '')
|
|
210
209
|
const params = {}
|
|
@@ -229,3 +228,36 @@ export const parseQueryString = (queryString) => {
|
|
|
229
228
|
|
|
230
229
|
return params
|
|
231
230
|
}
|
|
231
|
+
|
|
232
|
+
// 解析URL参数
|
|
233
|
+
export function parseCaptcha(url) {
|
|
234
|
+
let queryObj: any = {}
|
|
235
|
+
const matched = url.match(/^(data:.*?)(\?[^#\s]*)?$/)
|
|
236
|
+
if (matched) {
|
|
237
|
+
// eslint-disable-next-line prefer-destructuring
|
|
238
|
+
url = matched[1]
|
|
239
|
+
const search = matched[2]
|
|
240
|
+
if (search) {
|
|
241
|
+
queryObj = parseQueryString(search)
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
const { token, ...restQueryObj } = queryObj
|
|
245
|
+
if (/^data:/.test(url) && !token) {
|
|
246
|
+
return {
|
|
247
|
+
error: 'invalid_argument',
|
|
248
|
+
error_description: `invalid captcha data: ${url}`,
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
if (!token) {
|
|
252
|
+
return {
|
|
253
|
+
error: 'unimplemented',
|
|
254
|
+
error_description: 'need to impl captcha data',
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
// 解析url得到的参数
|
|
258
|
+
return {
|
|
259
|
+
state: restQueryObj.state,
|
|
260
|
+
token, // 验证码token
|
|
261
|
+
captchaData: url, // 验证码base64图片
|
|
262
|
+
}
|
|
263
|
+
}
|