unreach-util
Advanced tools
Comparing version 0.5.1 to 0.5.2
@@ -1,2 +0,3 @@ | ||
const env = process.env.REACT_APP_ENV || process.env.NODE_ENV || 'development'; | ||
export default env; | ||
export default function() { | ||
return process.env.REACT_APP_ENV || process.env.NODE_ENV || 'development'; | ||
} |
@@ -5,4 +5,4 @@ import env from './env'; | ||
it('test', () => { | ||
expect(env).toBe('test'); | ||
expect(env()).toBe('test'); | ||
}); | ||
}); |
{ | ||
"name": "unreach-util", | ||
"version": "0.5.1", | ||
"version": "0.5.2", | ||
"description": "前端工具基础库", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
import axios from 'axios'; | ||
import env from './env'; | ||
const serverHost = (/(\.[-\w]+\.[-\w]+)$/).exec(window.location.hostname)[1]; | ||
const serverHost = /(\.[-\w]+\.[-\w]+)$/.exec(window.location.hostname)[1]; | ||
async function request({ method = 'get', scope, url, params, data }) { | ||
url = `${getHost(scope)}/api/${url}`; | ||
if (!url.startsWith('http')) { | ||
url = `${getHost(scope)}/api/${url}`; | ||
} | ||
if (method === 'get') { | ||
@@ -40,7 +41,7 @@ params = { ...params, ...data, _: Date.now() }; | ||
function getHost(scope) { | ||
return env === 'development' ? | ||
`https://${scope}.dev${serverHost}` : | ||
`https://${scope}${serverHost}`; | ||
return env() === 'development' | ||
? `https://${scope}.dev${serverHost}` | ||
: `https://${scope}${serverHost}`; | ||
} | ||
export default { request, get, post, postSync }; |
21
track.js
@@ -7,9 +7,10 @@ import qs from 'querystring'; | ||
const getLoginUserId = cached(async() => { | ||
const data = await request.get('member', 'account/query'); | ||
return data && data.id; | ||
const getLoginUserId = cached(async () => { | ||
const data = await request.get( | ||
'member', | ||
'https://member.unreach.io/api/account/query' | ||
); | ||
return data && data.user && data.user.id; | ||
}); | ||
export default async function track({ type, id, data }) { | ||
@@ -22,3 +23,2 @@ debug('track: [%s] %s', type, id); | ||
export async function trackSync({ type, id, data }) { | ||
@@ -33,3 +33,2 @@ debug('track sync: [%s] %s', type, id); | ||
async function getTrackUrl({ type, id, data, ext = '' }) { | ||
@@ -42,5 +41,5 @@ type = type || 'click'; | ||
const url = window.location.href.replace(/#.*$/, ''); // remove hash | ||
const url = window.location.href.replace(/#.*$/, ''); // remove hash | ||
const query = { | ||
APIVersion: '0.6.0', // 保留字段,必选 | ||
APIVersion: '0.6.0', // 保留字段,必选 | ||
url, | ||
@@ -55,7 +54,7 @@ __topic__: userId || '', | ||
const trackUrl = 'https://learninqgt.cn-hangzhou.log.aliyuncs.com/logstores/document/track'; | ||
const trackUrl = | ||
'https://learninqgt.cn-hangzhou.log.aliyuncs.com/logstores/document/track'; | ||
return `${trackUrl}${ext}?${qs.stringify(query)}`; | ||
} | ||
function cached(fn) { | ||
@@ -62,0 +61,0 @@ let called = false; |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
6176
186
1