Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ccms-sdk

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ccms-sdk - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

es5/ccms-sdk.js

48

interceptors/token-refresh-interceptor.js

@@ -6,3 +6,4 @@ 'use strict';

});
exports.REQUEST_TOKEN_STORAGE_KEY = undefined;
exports.getRequestCredential = getRequestCredential;
exports.setRequestCredential = setRequestCredential;
exports.setAuthFailedBehavior = setAuthFailedBehavior;

@@ -31,10 +32,26 @@ exports.setRefreshTokenUrl = setRefreshTokenUrl;

var needToRefreshToken = false;
var execAuthFailure = function execAuthFailure() {};
var REQUEST_TOKEN_STORAGE_KEY = exports.REQUEST_TOKEN_STORAGE_KEY = 'ccmsRequestCredential';
var REQUEST_TOKEN_STORAGE_KEY = 'ccmsRequestCredential';
var redirectToLogin = function redirectToLogin() {};
function setAuthFailedBehavior(fn) {
redirectToLogin = fn;
function getRequestCredential() {
return JSON.parse(localStorage.getItem(REQUEST_TOKEN_STORAGE_KEY));
}
function setRequestCredential(credential) {
localStorage.setItem(REQUEST_TOKEN_STORAGE_KEY, JSON.stringify(credential));
}
function setAuthFailedBehavior() {
var fn = arguments.length <= 0 || arguments[0] === undefined ? execAuthFailure : arguments[0];
execAuthFailure = function execAuthFailure() {
fn();
localStorage.removeItem(REQUEST_TOKEN_STORAGE_KEY);
var ex = new TypeError('credential was expired or had been removed, pls set it before the get action!');
console.error(ex);
return _injector2.default.get('$q').reject(ex);
};
}
var refreshTokenUrl = '';

@@ -49,11 +66,15 @@ function setRefreshTokenUrl(url) {

var ccmsRequestCredential = JSON.parse(localStorage.getItem(REQUEST_TOKEN_STORAGE_KEY));
var credential = getRequestCredential();
// storage 里的状态有可能已经失效
if (!credential) {
return execAuthFailure();
}
config.headers[REQUEST_TOKEN_HEADER] = ccmsRequestCredential.id;
config.headers[REQUEST_TOKEN_HEADER] = credential.id;
// 白名单之外的url做校验
// TODO 兼容处理,如果拿不到refreshToken说明系统还未升级,则不做刷新token逻辑
if (ccmsRequestCredential.refreshToken && REQUEST_WHITE_LIST.indexOf(config.url) === -1) {
if (credential.refreshToken && REQUEST_WHITE_LIST.indexOf(config.url) === -1) {
var expireTime = Date.parse(ccmsRequestCredential.expireTime);
var expireTime = Date.parse(credential.expireTime);
var now = Date.now();

@@ -67,3 +88,3 @@

// token失效
redirectToLogin();
return execAuthFailure();
}

@@ -76,3 +97,4 @@ }

var ccmsRequestCredential = JSON.parse(localStorage.getItem(REQUEST_TOKEN_STORAGE_KEY));
// 如果请求能正常响应,说明 storage 里的状态是存在的,所以这里不做判断
var credential = getRequestCredential();

@@ -85,6 +107,6 @@ var $http = _injector2.default.get('$http');

// refresh token
$http.put(refreshTokenUrl, ccmsRequestCredential.refreshToken).then(function (response) {
$http.put(refreshTokenUrl, credential.refreshToken).then(function (response) {
// 更新localStorage中token信息
localStorage.setItem(REQUEST_TOKEN_STORAGE_KEY, JSON.stringify(response.data));
}, redirectToLogin);
}, execAuthFailure);
}

@@ -91,0 +113,0 @@

{
"name": "ccms-sdk",
"version": "1.0.0",
"version": "1.1.0",
"description": "ccms fe sdk written by es2015+",
"main": "./index.js",
"scripts": {
"build": "rm -fr lib && NODE_ENV=production babel src --out-dir lib --ignore **/__tests__,index.js & webpack --config webpack-build.config.js && cp -R dist lib && cp package.json lib/package.json && cp README.md lib/README.md",
"build": "rm -fr lib && NODE_ENV=production babel src --out-dir lib --ignore **/__tests__,index.js & webpack --config webpack-build.config.js && cp -R es5 lib && cp package.json lib/package.json",
"codecheck": "NODE_EVN=test eslint src",

@@ -20,2 +20,3 @@ "prepush": "npm test",

"angular-es-utils": "^1.3.1",
"angular-mocks": "^1.5.3",
"babel-cli": "^6.7.7",

@@ -53,5 +54,4 @@ "babel-core": "^6.7.4",

"dependencies": {
"angular": "^1.5.3",
"angular-mocks": "^1.5.3"
"angular": "^1.5.3"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc