axios-annotations 1.3.3 → 2.0.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/README.md +248 -105
- package/index.d.ts +1 -0
- package/index.js +121 -0
- package/lib/core/cancel.d.ts +30 -0
- package/lib/core/cancel.js +56 -0
- package/lib/core/common.d.ts +6 -0
- package/lib/core/common.js +166 -1
- package/lib/core/config.d.ts +60 -29
- package/lib/core/config.js +332 -1
- package/lib/core/parser.d.ts +19 -15
- package/lib/core/parser.js +79 -1
- package/lib/core/provider.d.ts +6 -0
- package/lib/core/provider.js +172 -0
- package/lib/core/service.d.ts +153 -33
- package/lib/core/service.js +562 -1
- package/lib/decorator/abort-source.d.ts +3 -9
- package/lib/decorator/abort-source.js +25 -1
- package/lib/decorator/delete-mapping.d.ts +1 -3
- package/lib/decorator/delete-mapping.js +13 -1
- package/lib/decorator/get-mapping.d.ts +1 -3
- package/lib/decorator/get-mapping.js +13 -1
- package/lib/decorator/ignore-residual-params.d.ts +1 -3
- package/lib/decorator/ignore-residual-params.js +24 -1
- package/lib/decorator/patch-mapping.d.ts +1 -3
- package/lib/decorator/patch-mapping.js +13 -1
- package/lib/decorator/post-mapping.d.ts +1 -3
- package/lib/decorator/post-mapping.js +13 -1
- package/lib/decorator/put-mapping.d.ts +1 -3
- package/lib/decorator/put-mapping.js +13 -1
- package/lib/decorator/request-body.d.ts +1 -3
- package/lib/decorator/request-body.js +28 -1
- package/lib/decorator/request-config.d.ts +5 -7
- package/lib/decorator/request-config.js +23 -1
- package/lib/decorator/request-header.d.ts +2 -5
- package/lib/decorator/request-header.js +21 -1
- package/lib/decorator/request-mapping.d.ts +3 -6
- package/lib/decorator/request-mapping.js +58 -1
- package/lib/decorator/request-param.d.ts +1 -3
- package/lib/decorator/request-param.js +27 -1
- package/lib/decorator/request-with.d.ts +1 -3
- package/lib/decorator/request-with.js +20 -1
- package/lib/index.d.ts +19 -0
- package/lib/index.js +139 -0
- package/lib/plugins/auth/authorizer.d.ts +23 -49
- package/lib/plugins/auth/authorizer.js +271 -1
- package/lib/plugins/auth/history.d.ts +14 -15
- package/lib/plugins/auth/history.js +96 -1
- package/lib/plugins/auth/index.d.ts +9 -4
- package/lib/plugins/auth/index.js +368 -1
- package/lib/plugins/auth/queue.d.ts +28 -16
- package/lib/plugins/auth/queue.js +270 -1
- package/lib/plugins/auth/storage.d.ts +6 -7
- package/lib/plugins/auth/storage.js +207 -1
- package/package.json +16 -16
- package/plugins/auth/index.d.ts +4 -4
- package/plugins/auth/index.js +26 -1
- package/core/config.d.ts +0 -29
- package/core/config.js +0 -1
- package/core/parser.d.ts +0 -15
- package/core/parser.js +0 -1
- package/core/service.d.ts +0 -33
- package/core/service.js +0 -1
- package/decorator/abort-source.d.ts +0 -9
- package/decorator/abort-source.js +0 -1
- package/decorator/delete-mapping.d.ts +0 -1
- package/decorator/delete-mapping.js +0 -1
- package/decorator/get-mapping.d.ts +0 -1
- package/decorator/get-mapping.js +0 -1
- package/decorator/ignore-residual-params.d.ts +0 -1
- package/decorator/ignore-residual-params.js +0 -1
- package/decorator/patch-mapping.d.ts +0 -1
- package/decorator/patch-mapping.js +0 -1
- package/decorator/post-mapping.d.ts +0 -1
- package/decorator/post-mapping.js +0 -1
- package/decorator/put-mapping.d.ts +0 -3
- package/decorator/put-mapping.js +0 -1
- package/decorator/request-body.d.ts +0 -3
- package/decorator/request-body.js +0 -1
- package/decorator/request-config.d.ts +0 -29
- package/decorator/request-config.js +0 -1
- package/decorator/request-header.d.ts +0 -1
- package/decorator/request-header.js +0 -1
- package/decorator/request-mapping.d.ts +0 -1
- package/decorator/request-mapping.js +0 -1
- package/decorator/request-param.d.ts +0 -1
- package/decorator/request-param.js +0 -1
- package/decorator/request-with.d.ts +0 -1
- package/decorator/request-with.js +0 -1
- package/lib/plugins/cache/index.js +0 -1
- package/plugins/auth/authorizer.d.ts +0 -49
- package/plugins/auth/authorizer.js +0 -1
- package/plugins/auth/history.d.ts +0 -15
- package/plugins/auth/history.js +0 -1
- package/plugins/auth/queue.d.ts +0 -16
- package/plugins/auth/queue.js +0 -1
- package/plugins/auth/storage.d.ts +0 -7
- package/plugins/auth/storage.js +0 -1
- package/plugins/cache/index.js +0 -1
|
@@ -1 +1,271 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _storage=_interopRequireDefault(require("./storage")),_history=_interopRequireDefault(require("./history"));function _interopRequireDefault(t){return t&&t.__esModule?t:{default:t}}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _regeneratorRuntime(){_regeneratorRuntime=function(){return a};var a={},t=Object.prototype,u=t.hasOwnProperty,c=Object.defineProperty||function(t,e,r){t[e]=r.value},e="function"==typeof Symbol?Symbol:{},n=e.iterator||"@@iterator",r=e.asyncIterator||"@@asyncIterator",o=e.toStringTag||"@@toStringTag";function i(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{i({},"")}catch(t){i=function(t,e,r){return t[e]=r}}function s(t,e,r,n){var o,i,a,s,e=e&&e.prototype instanceof h?e:h,e=Object.create(e.prototype),n=new b(n||[]);return c(e,"_invoke",{value:(o=t,i=r,a=n,s="suspendedStart",function(t,e){if("executing"===s)throw new Error("Generator is already running");if("completed"===s){if("throw"===t)throw e;return k()}for(a.method=t,a.arg=e;;){var r=a.delegate;if(r){r=function t(e,r){var n=r.method,o=e.iterator[n];if(void 0===o)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=void 0,t(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),l;n=f(o,e.iterator,r.arg);if("throw"===n.type)return r.method="throw",r.arg=n.arg,r.delegate=null,l;o=n.arg;return o?o.done?(r[e.resultName]=o.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=void 0),r.delegate=null,l):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,l)}(r,a);if(r){if(r===l)continue;return r}}if("next"===a.method)a.sent=a._sent=a.arg;else if("throw"===a.method){if("suspendedStart"===s)throw s="completed",a.arg;a.dispatchException(a.arg)}else"return"===a.method&&a.abrupt("return",a.arg);s="executing";r=f(o,i,a);if("normal"===r.type){if(s=a.done?"completed":"suspendedYield",r.arg===l)continue;return{value:r.arg,done:a.done}}"throw"===r.type&&(s="completed",a.method="throw",a.arg=r.arg)}})}),e}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}a.wrap=s;var l={};function h(){}function y(){}function p(){}var e={},v=(i(e,n,function(){return this}),Object.getPrototypeOf),v=v&&v(v(x([]))),d=(v&&v!==t&&u.call(v,n)&&(e=v),p.prototype=h.prototype=Object.create(e));function g(t){["next","throw","return"].forEach(function(e){i(t,e,function(t){return this._invoke(e,t)})})}function m(a,s){var e;c(this,"_invoke",{value:function(r,n){function t(){return new s(function(t,e){!function e(t,r,n,o){var i,t=f(a[t],a,r);if("throw"!==t.type)return(r=(i=t.arg).value)&&"object"==_typeof(r)&&u.call(r,"__await")?s.resolve(r.__await).then(function(t){e("next",t,n,o)},function(t){e("throw",t,n,o)}):s.resolve(r).then(function(t){i.value=t,n(i)},function(t){return e("throw",t,n,o)});o(t.arg)}(r,n,t,e)})}return e=e?e.then(t,t):t()}})}function _(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function w(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function b(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(_,this),this.reset(!0)}function x(e){if(e){var r,t=e[n];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length))return r=-1,(t=function t(){for(;++r<e.length;)if(u.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t}).next=t}return{next:k}}function k(){return{value:void 0,done:!0}}return c(d,"constructor",{value:y.prototype=p,configurable:!0}),c(p,"constructor",{value:y,configurable:!0}),y.displayName=i(p,o,"GeneratorFunction"),a.isGeneratorFunction=function(t){t="function"==typeof t&&t.constructor;return!!t&&(t===y||"GeneratorFunction"===(t.displayName||t.name))},a.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,p):(t.__proto__=p,i(t,o,"GeneratorFunction")),t.prototype=Object.create(d),t},a.awrap=function(t){return{__await:t}},g(m.prototype),i(m.prototype,r,function(){return this}),a.AsyncIterator=m,a.async=function(t,e,r,n,o){void 0===o&&(o=Promise);var i=new m(s(t,e,r,n),o);return a.isGeneratorFunction(e)?i:i.next().then(function(t){return t.done?t.value:i.next()})},g(d),i(d,o,"Generator"),i(d,n,function(){return this}),i(d,"toString",function(){return"[object Generator]"}),a.keys=function(t){var e,r=Object(t),n=[];for(e in r)n.push(e);return n.reverse(),function t(){for(;n.length;){var e=n.pop();if(e in r)return t.value=e,t.done=!1,t}return t.done=!0,t}},a.values=x,b.prototype={constructor:b,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(w),!t)for(var e in this)"t"===e.charAt(0)&&u.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var n=this;function t(t,e){return i.type="throw",i.arg=r,n.next=t,e&&(n.method="next",n.arg=void 0),!!e}for(var e=this.tryEntries.length-1;0<=e;--e){var o=this.tryEntries[e],i=o.completion;if("root"===o.tryLoc)return t("end");if(o.tryLoc<=this.prev){var a=u.call(o,"catchLoc"),s=u.call(o,"finallyLoc");if(a&&s){if(this.prev<o.catchLoc)return t(o.catchLoc,!0);if(this.prev<o.finallyLoc)return t(o.finallyLoc)}else if(a){if(this.prev<o.catchLoc)return t(o.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return t(o.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;0<=r;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&u.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}var i=(o=o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc?null:o)?o.completion:{};return i.type=t,i.arg=e,o?(this.method="next",this.next=o.finallyLoc,l):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),l},finish:function(t){for(var e=this.tryEntries.length-1;0<=e;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),w(r),l}},catch:function(t){for(var e=this.tryEntries.length-1;0<=e;--e){var r,n,o=this.tryEntries[e];if(o.tryLoc===t)return"throw"===(r=o.completion).type&&(n=r.arg,w(o)),n}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:x(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),l}},a}function asyncGeneratorStep(t,e,r,n,o,i,a){try{var s=t[i](a),u=s.value}catch(t){return void r(t)}s.done?e(u):Promise.resolve(u).then(n,o)}function _asyncToGenerator(s){return function(){var t=this,a=arguments;return new Promise(function(e,r){var n=s.apply(t,a);function o(t){asyncGeneratorStep(n,e,r,o,i,"next",t)}function i(t){asyncGeneratorStep(n,e,r,o,i,"throw",t)}o(void 0)})}}function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _defineProperties(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,_toPropertyKey(n.key),n)}}function _createClass(t,e,r){return e&&_defineProperties(t.prototype,e),r&&_defineProperties(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function _defineProperty(t,e,r){return(e=_toPropertyKey(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function _toPropertyKey(t){t=_toPrimitive(t,"string");return"symbol"===_typeof(t)?t:String(t)}function _toPrimitive(t,e){if("object"!==_typeof(t)||null===t)return t;var r=t[Symbol.toPrimitive];if(void 0===r)return("string"===e?String:Number)(t);r=r.call(t,e||"default");if("object"!==_typeof(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}var Authorizer=function(){function t(){_classCallCheck(this,t),_defineProperty(this,"_sessionKey","$_SESSION"),_defineProperty(this,"_sessionStorage",new _storage.default),_defineProperty(this,"_sessionHistory",new _history.default)}var e,r,n,o,i;return _createClass(t,[{key:"sessionKey",get:function(){return this._sessionKey},set:function(t){this._sessionKey=t}},{key:"sessionStorage",get:function(){return this._sessionStorage},set:function(t){this._sessionStorage=t}},{key:"sessionHistory",get:function(){return this._sessionHistory},set:function(t){this._sessionHistory=t}},{key:"getSession",value:(i=_asyncToGenerator(_regeneratorRuntime().mark(function t(){return _regeneratorRuntime().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.sessionStorage.get(this.sessionKey);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},t,this)})),function(){return i.apply(this,arguments)})},{key:"storageSession",value:(o=_asyncToGenerator(_regeneratorRuntime().mark(function t(e){return _regeneratorRuntime().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.sessionStorage.set(this.sessionKey,e);case 2:case"end":return t.stop()}},t,this)})),function(t){return o.apply(this,arguments)})},{key:"refreshSession",value:(n=_asyncToGenerator(_regeneratorRuntime().mark(function t(e){return _regeneratorRuntime().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",null);case 1:case"end":return t.stop()}},t)})),function(t){return n.apply(this,arguments)})},{key:"withAuthentication",value:function(t,e){var r,n;e&&(r=e.access_token,n=e.accessToken,e=e.token,r||n||e)&&(t.headers.Authorization="Bearer "+(r||n||e))}},{key:"checkSession",value:function(t,e){t=t.headers.Authorization||t.headers.authorization,t=t&&t.split(" ")[1]||"";return!((e.access_token||e.accessToken||e.token)===t||this.sessionHistory.size&&this.sessionHistory.check(t))}},{key:"checkResponse",value:function(t){return 401!==(t||{status:0}).status}},{key:"onAuthorizedDenied",value:(r=_asyncToGenerator(_regeneratorRuntime().mark(function t(e){return _regeneratorRuntime().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:throw e;case 1:case"end":return t.stop()}},t)})),function(t){return r.apply(this,arguments)})},{key:"onSessionInvalidated",value:function(){}},{key:"invalidateSession",value:(e=_asyncToGenerator(_regeneratorRuntime().mark(function t(){return _regeneratorRuntime().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.sessionStorage.remove(this.sessionKey);case 2:this.onSessionInvalidated();case 3:case"end":return t.stop()}},t,this)})),function(){return e.apply(this,arguments)})}]),t}();exports.default=Authorizer;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = this && this.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) {
|
|
4
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
5
|
+
resolve(value);
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
9
|
+
function fulfilled(value) {
|
|
10
|
+
try {
|
|
11
|
+
step(generator.next(value));
|
|
12
|
+
} catch (e) {
|
|
13
|
+
reject(e);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function rejected(value) {
|
|
17
|
+
try {
|
|
18
|
+
step(generator["throw"](value));
|
|
19
|
+
} catch (e) {
|
|
20
|
+
reject(e);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function step(result) {
|
|
24
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
25
|
+
}
|
|
26
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
var __generator = this && this.__generator || function(thisArg, body) {
|
|
30
|
+
var _ = {
|
|
31
|
+
label: 0,
|
|
32
|
+
sent: function sent() {
|
|
33
|
+
if (t[0] & 1) throw t[1];
|
|
34
|
+
return t[1];
|
|
35
|
+
},
|
|
36
|
+
trys: [],
|
|
37
|
+
ops: []
|
|
38
|
+
}, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
39
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
40
|
+
return this;
|
|
41
|
+
}), g;
|
|
42
|
+
function verb(n) {
|
|
43
|
+
return function(v) {
|
|
44
|
+
return step([
|
|
45
|
+
n,
|
|
46
|
+
v
|
|
47
|
+
]);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function step(op) {
|
|
51
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
52
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
53
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
54
|
+
if (y = 0, t) op = [
|
|
55
|
+
op[0] & 2,
|
|
56
|
+
t.value
|
|
57
|
+
];
|
|
58
|
+
switch(op[0]){
|
|
59
|
+
case 0:
|
|
60
|
+
case 1:
|
|
61
|
+
t = op;
|
|
62
|
+
break;
|
|
63
|
+
case 4:
|
|
64
|
+
_.label++;
|
|
65
|
+
return {
|
|
66
|
+
value: op[1],
|
|
67
|
+
done: false
|
|
68
|
+
};
|
|
69
|
+
case 5:
|
|
70
|
+
_.label++;
|
|
71
|
+
y = op[1];
|
|
72
|
+
op = [
|
|
73
|
+
0
|
|
74
|
+
];
|
|
75
|
+
continue;
|
|
76
|
+
case 7:
|
|
77
|
+
op = _.ops.pop();
|
|
78
|
+
_.trys.pop();
|
|
79
|
+
continue;
|
|
80
|
+
default:
|
|
81
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
82
|
+
_ = 0;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
86
|
+
_.label = op[1];
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
90
|
+
_.label = t[1];
|
|
91
|
+
t = op;
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
if (t && _.label < t[2]) {
|
|
95
|
+
_.label = t[2];
|
|
96
|
+
_.ops.push(op);
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
if (t[2]) _.ops.pop();
|
|
100
|
+
_.trys.pop();
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
op = body.call(thisArg, _);
|
|
104
|
+
} catch (e) {
|
|
105
|
+
op = [
|
|
106
|
+
6,
|
|
107
|
+
e
|
|
108
|
+
];
|
|
109
|
+
y = 0;
|
|
110
|
+
} finally{
|
|
111
|
+
f = t = 0;
|
|
112
|
+
}
|
|
113
|
+
if (op[0] & 5) throw op[1];
|
|
114
|
+
return {
|
|
115
|
+
value: op[0] ? op[1] : void 0,
|
|
116
|
+
done: true
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
Object.defineProperty(exports, "__esModule", {
|
|
121
|
+
value: true
|
|
122
|
+
});
|
|
123
|
+
var storage_1 = require("./storage");
|
|
124
|
+
var history_1 = require("./history");
|
|
125
|
+
var Authorizer = /** @class */ function() {
|
|
126
|
+
function Authorizer() {
|
|
127
|
+
this._sessionKey = "$_SESSION";
|
|
128
|
+
this._sessionStorage = new storage_1["default"]();
|
|
129
|
+
this._sessionHistory = new history_1["default"]();
|
|
130
|
+
}
|
|
131
|
+
Object.defineProperty(Authorizer.prototype, "sessionKey", {
|
|
132
|
+
get: function get() {
|
|
133
|
+
return this._sessionKey;
|
|
134
|
+
},
|
|
135
|
+
set: function set(value) {
|
|
136
|
+
this._sessionKey = value;
|
|
137
|
+
},
|
|
138
|
+
enumerable: false,
|
|
139
|
+
configurable: true
|
|
140
|
+
});
|
|
141
|
+
Object.defineProperty(Authorizer.prototype, "sessionStorage", {
|
|
142
|
+
get: function get() {
|
|
143
|
+
return this._sessionStorage;
|
|
144
|
+
},
|
|
145
|
+
set: function set(value) {
|
|
146
|
+
this._sessionStorage = value;
|
|
147
|
+
},
|
|
148
|
+
enumerable: false,
|
|
149
|
+
configurable: true
|
|
150
|
+
});
|
|
151
|
+
Object.defineProperty(Authorizer.prototype, "sessionHistory", {
|
|
152
|
+
get: function get() {
|
|
153
|
+
return this._sessionHistory;
|
|
154
|
+
},
|
|
155
|
+
set: function set(value) {
|
|
156
|
+
this._sessionHistory = value;
|
|
157
|
+
},
|
|
158
|
+
enumerable: false,
|
|
159
|
+
configurable: true
|
|
160
|
+
});
|
|
161
|
+
Authorizer.prototype.getSession = function() {
|
|
162
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
163
|
+
return __generator(this, function(_a) {
|
|
164
|
+
switch(_a.label){
|
|
165
|
+
case 0:
|
|
166
|
+
return [
|
|
167
|
+
4 /*yield*/ ,
|
|
168
|
+
this.sessionStorage.get(this.sessionKey)
|
|
169
|
+
];
|
|
170
|
+
case 1:
|
|
171
|
+
return [
|
|
172
|
+
2 /*return*/ ,
|
|
173
|
+
_a.sent()
|
|
174
|
+
];
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
Authorizer.prototype.storageSession = function(session) {
|
|
180
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
181
|
+
return __generator(this, function(_a) {
|
|
182
|
+
switch(_a.label){
|
|
183
|
+
case 0:
|
|
184
|
+
return [
|
|
185
|
+
4 /*yield*/ ,
|
|
186
|
+
this.sessionStorage.set(this.sessionKey, session)
|
|
187
|
+
];
|
|
188
|
+
case 1:
|
|
189
|
+
_a.sent();
|
|
190
|
+
return [
|
|
191
|
+
2 /*return*/
|
|
192
|
+
];
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
};
|
|
197
|
+
Authorizer.prototype.refreshSession = function(_session) {
|
|
198
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
199
|
+
return __generator(this, function(_a) {
|
|
200
|
+
return [
|
|
201
|
+
2 /*return*/ ,
|
|
202
|
+
null
|
|
203
|
+
];
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
};
|
|
207
|
+
// append auth headers
|
|
208
|
+
Authorizer.prototype.withAuthentication = function(request, session) {
|
|
209
|
+
if (session) {
|
|
210
|
+
var access_token = session.access_token, accessToken = session.accessToken, token = session.token;
|
|
211
|
+
if (access_token || accessToken || token) {
|
|
212
|
+
if (request.headers) {
|
|
213
|
+
request.headers['Authorization'] = "Bearer " + (access_token || accessToken || token);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
Authorizer.prototype.checkSession = function(request, session) {
|
|
219
|
+
var header = (request.headers || {})["Authorization"] || (request.headers || {})["authorization"];
|
|
220
|
+
var jwt = typeof header === "string" ? header.split(" ")[1] || "" : "";
|
|
221
|
+
var token = session.access_token || session.accessToken || session.token;
|
|
222
|
+
if (token === jwt) {
|
|
223
|
+
// request header token equal to invalid session token
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
// request time is too long , token may be refreshed few times
|
|
227
|
+
if (this.sessionHistory.size) {
|
|
228
|
+
if (this.sessionHistory.check(jwt)) {
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return true;
|
|
233
|
+
};
|
|
234
|
+
Authorizer.prototype.checkResponse = function(response) {
|
|
235
|
+
var status = (response || {
|
|
236
|
+
status: 0
|
|
237
|
+
}).status;
|
|
238
|
+
return status !== 401;
|
|
239
|
+
};
|
|
240
|
+
Authorizer.prototype.onAuthorizedDenied = function(error) {
|
|
241
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
242
|
+
return __generator(this, function(_a) {
|
|
243
|
+
throw error;
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
};
|
|
247
|
+
Authorizer.prototype.onSessionInvalidated = function() {
|
|
248
|
+
return;
|
|
249
|
+
};
|
|
250
|
+
Authorizer.prototype.invalidateSession = function() {
|
|
251
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
252
|
+
return __generator(this, function(_a) {
|
|
253
|
+
switch(_a.label){
|
|
254
|
+
case 0:
|
|
255
|
+
return [
|
|
256
|
+
4 /*yield*/ ,
|
|
257
|
+
this.sessionStorage.remove(this.sessionKey)
|
|
258
|
+
];
|
|
259
|
+
case 1:
|
|
260
|
+
_a.sent();
|
|
261
|
+
this.onSessionInvalidated();
|
|
262
|
+
return [
|
|
263
|
+
2 /*return*/
|
|
264
|
+
];
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
};
|
|
269
|
+
return Authorizer;
|
|
270
|
+
}();
|
|
271
|
+
exports["default"] = Authorizer;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 缓存过期会话,判断请求是否过期
|
|
3
|
+
*/
|
|
4
|
+
export default class SessionHistory {
|
|
5
|
+
_history: (Record<string, any> | null)[];
|
|
6
|
+
_position: number;
|
|
7
|
+
_size: number;
|
|
8
|
+
get size(): number;
|
|
9
|
+
add(session: Record<string, any>): void;
|
|
10
|
+
check(jwt: string): boolean;
|
|
11
|
+
deprecate(session: Record<string, any>): void;
|
|
12
|
+
clean(): void;
|
|
13
|
+
isDeprecated(session: Record<string, any>): boolean;
|
|
14
|
+
}
|
|
@@ -1 +1,96 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
var common_1 = require("../../core/common");
|
|
6
|
+
/**
|
|
7
|
+
* 缓存过期会话,判断请求是否过期
|
|
8
|
+
*/ var SessionHistory = /** @class */ function() {
|
|
9
|
+
function SessionHistory() {
|
|
10
|
+
// store up to 10 sessions, include expired or not
|
|
11
|
+
this._history = new Array(10);
|
|
12
|
+
// next session storage location
|
|
13
|
+
this._position = 0;
|
|
14
|
+
this._size = 0;
|
|
15
|
+
}
|
|
16
|
+
Object.defineProperty(SessionHistory.prototype, "size", {
|
|
17
|
+
get: function get() {
|
|
18
|
+
return this._size;
|
|
19
|
+
},
|
|
20
|
+
enumerable: false,
|
|
21
|
+
configurable: true
|
|
22
|
+
});
|
|
23
|
+
// store primary keys for session
|
|
24
|
+
SessionHistory.prototype.add = function(session) {
|
|
25
|
+
if (Object.keys(session).every(function(i) {
|
|
26
|
+
return (0, common_1.isNullOrEmpty)(session[i]);
|
|
27
|
+
})) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
var access_token = session.access_token, accessToken = session.accessToken, token = session.token, refresh_token = session.refresh_token, refreshToken = session.refreshToken;
|
|
31
|
+
this._history[this._position] = Object.assign({}, session, {
|
|
32
|
+
access_token: access_token || accessToken || token,
|
|
33
|
+
refresh_token: refresh_token || refreshToken,
|
|
34
|
+
invalid: false
|
|
35
|
+
});
|
|
36
|
+
this._position++;
|
|
37
|
+
this._position %= this._history.length;
|
|
38
|
+
this._size = this._history.reduce(function(s, i) {
|
|
39
|
+
return i ? s + 1 : s;
|
|
40
|
+
}, 0);
|
|
41
|
+
};
|
|
42
|
+
// session exist or not
|
|
43
|
+
SessionHistory.prototype.check = function(jwt) {
|
|
44
|
+
return this._history.some(function(session) {
|
|
45
|
+
if (session) {
|
|
46
|
+
var access_token = session.access_token, accessToken = session.accessToken, token = session.token;
|
|
47
|
+
return (access_token || accessToken || token) === jwt;
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
// mark the session expired
|
|
53
|
+
SessionHistory.prototype.deprecate = function(session) {
|
|
54
|
+
var position = 0;
|
|
55
|
+
var refresh_token = session.refresh_token, refreshToken = session.refreshToken;
|
|
56
|
+
var matching = this._history.find(function(s, i) {
|
|
57
|
+
position = i;
|
|
58
|
+
if (s) {
|
|
59
|
+
return (s.refresh_token || s.refreshToken) === (refresh_token || refreshToken);
|
|
60
|
+
}
|
|
61
|
+
return false;
|
|
62
|
+
});
|
|
63
|
+
if (matching) {
|
|
64
|
+
matching.invalid = true;
|
|
65
|
+
var first = this._history[0];
|
|
66
|
+
this._history[0] = this._history[position];
|
|
67
|
+
this._history[position] = first;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
// remove expired sessions
|
|
71
|
+
SessionHistory.prototype.clean = function() {
|
|
72
|
+
for(var i = 0; i < this._history.length; ++i){
|
|
73
|
+
var s = this._history[i];
|
|
74
|
+
if (s && s.invalid) {
|
|
75
|
+
this._history[i] = null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
this._size = this._history.reduce(function(s, i) {
|
|
79
|
+
return i ? s + 1 : s;
|
|
80
|
+
}, 0);
|
|
81
|
+
};
|
|
82
|
+
// is the session expired
|
|
83
|
+
SessionHistory.prototype.isDeprecated = function(session) {
|
|
84
|
+
return this._history.some(function(s) {
|
|
85
|
+
if (s) {
|
|
86
|
+
var refresh_token = session.refresh_token, refreshToken = session.refreshToken;
|
|
87
|
+
if (refresh_token || refreshToken) {
|
|
88
|
+
return (s.refresh_token || s.refreshToken) === (refresh_token || refreshToken) && s.invalid;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return false;
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
return SessionHistory;
|
|
95
|
+
}();
|
|
96
|
+
exports["default"] = SessionHistory;
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import Authorizer from "./authorizer";
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
export default
|
|
1
|
+
import Authorizer from "./authorizer";
|
|
2
|
+
import type { ConfigPlugin } from "../../core/config";
|
|
3
|
+
export { default as Authorizer } from "./authorizer";
|
|
4
|
+
export { default as SessionStorage } from "./storage";
|
|
5
|
+
export default function AuthorizationPlugin(authorizer: Authorizer, options?: {
|
|
6
|
+
minTryRetryInterval: number;
|
|
7
|
+
maxTryRetryInterval: number;
|
|
8
|
+
retryTimes: number;
|
|
9
|
+
}): ConfigPlugin;
|