axios-annotations 1.3.4 → 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.
Files changed (98) hide show
  1. package/README.md +248 -105
  2. package/index.d.ts +1 -0
  3. package/index.js +121 -0
  4. package/lib/core/cancel.d.ts +30 -0
  5. package/lib/core/cancel.js +56 -0
  6. package/lib/core/common.d.ts +6 -0
  7. package/lib/core/common.js +166 -1
  8. package/lib/core/config.d.ts +60 -29
  9. package/lib/core/config.js +332 -1
  10. package/lib/core/parser.d.ts +19 -15
  11. package/lib/core/parser.js +79 -1
  12. package/lib/core/provider.d.ts +6 -0
  13. package/lib/core/provider.js +172 -0
  14. package/lib/core/service.d.ts +153 -33
  15. package/lib/core/service.js +562 -1
  16. package/lib/decorator/abort-source.d.ts +3 -9
  17. package/lib/decorator/abort-source.js +25 -1
  18. package/lib/decorator/delete-mapping.d.ts +1 -3
  19. package/lib/decorator/delete-mapping.js +13 -1
  20. package/lib/decorator/get-mapping.d.ts +1 -3
  21. package/lib/decorator/get-mapping.js +13 -1
  22. package/lib/decorator/ignore-residual-params.d.ts +1 -3
  23. package/lib/decorator/ignore-residual-params.js +24 -1
  24. package/lib/decorator/patch-mapping.d.ts +1 -3
  25. package/lib/decorator/patch-mapping.js +13 -1
  26. package/lib/decorator/post-mapping.d.ts +1 -3
  27. package/lib/decorator/post-mapping.js +13 -1
  28. package/lib/decorator/put-mapping.d.ts +1 -3
  29. package/lib/decorator/put-mapping.js +13 -1
  30. package/lib/decorator/request-body.d.ts +1 -3
  31. package/lib/decorator/request-body.js +28 -1
  32. package/lib/decorator/request-config.d.ts +5 -7
  33. package/lib/decorator/request-config.js +23 -1
  34. package/lib/decorator/request-header.d.ts +2 -5
  35. package/lib/decorator/request-header.js +21 -1
  36. package/lib/decorator/request-mapping.d.ts +3 -6
  37. package/lib/decorator/request-mapping.js +58 -1
  38. package/lib/decorator/request-param.d.ts +1 -3
  39. package/lib/decorator/request-param.js +27 -1
  40. package/lib/decorator/request-with.d.ts +1 -3
  41. package/lib/decorator/request-with.js +20 -1
  42. package/lib/index.d.ts +19 -0
  43. package/lib/index.js +139 -0
  44. package/lib/plugins/auth/authorizer.d.ts +23 -49
  45. package/lib/plugins/auth/authorizer.js +271 -1
  46. package/lib/plugins/auth/history.d.ts +14 -15
  47. package/lib/plugins/auth/history.js +96 -1
  48. package/lib/plugins/auth/index.d.ts +9 -4
  49. package/lib/plugins/auth/index.js +368 -1
  50. package/lib/plugins/auth/queue.d.ts +28 -16
  51. package/lib/plugins/auth/queue.js +270 -1
  52. package/lib/plugins/auth/storage.d.ts +6 -7
  53. package/lib/plugins/auth/storage.js +207 -1
  54. package/package.json +16 -16
  55. package/plugins/auth/index.d.ts +4 -4
  56. package/plugins/auth/index.js +26 -1
  57. package/core/config.d.ts +0 -29
  58. package/core/config.js +0 -1
  59. package/core/parser.d.ts +0 -15
  60. package/core/parser.js +0 -1
  61. package/core/service.d.ts +0 -33
  62. package/core/service.js +0 -1
  63. package/decorator/abort-source.d.ts +0 -9
  64. package/decorator/abort-source.js +0 -1
  65. package/decorator/delete-mapping.d.ts +0 -1
  66. package/decorator/delete-mapping.js +0 -1
  67. package/decorator/get-mapping.d.ts +0 -1
  68. package/decorator/get-mapping.js +0 -1
  69. package/decorator/ignore-residual-params.d.ts +0 -1
  70. package/decorator/ignore-residual-params.js +0 -1
  71. package/decorator/patch-mapping.d.ts +0 -1
  72. package/decorator/patch-mapping.js +0 -1
  73. package/decorator/post-mapping.d.ts +0 -1
  74. package/decorator/post-mapping.js +0 -1
  75. package/decorator/put-mapping.d.ts +0 -3
  76. package/decorator/put-mapping.js +0 -1
  77. package/decorator/request-body.d.ts +0 -3
  78. package/decorator/request-body.js +0 -1
  79. package/decorator/request-config.d.ts +0 -29
  80. package/decorator/request-config.js +0 -1
  81. package/decorator/request-header.d.ts +0 -1
  82. package/decorator/request-header.js +0 -1
  83. package/decorator/request-mapping.d.ts +0 -1
  84. package/decorator/request-mapping.js +0 -1
  85. package/decorator/request-param.d.ts +0 -1
  86. package/decorator/request-param.js +0 -1
  87. package/decorator/request-with.d.ts +0 -1
  88. package/decorator/request-with.js +0 -1
  89. package/lib/plugins/cache/index.js +0 -1
  90. package/plugins/auth/authorizer.d.ts +0 -49
  91. package/plugins/auth/authorizer.js +0 -1
  92. package/plugins/auth/history.d.ts +0 -15
  93. package/plugins/auth/history.js +0 -1
  94. package/plugins/auth/queue.d.ts +0 -16
  95. package/plugins/auth/queue.js +0 -1
  96. package/plugins/auth/storage.d.ts +0 -7
  97. package/plugins/auth/storage.js +0 -1
  98. package/plugins/cache/index.js +0 -1
@@ -1 +1,368 @@
1
- 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)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=AuthorizationPlugin;var _queue=_interopRequireDefault(require("./queue"));function _interopRequireDefault(t){return t&&t.__esModule?t:{default:t}}function _regeneratorRuntime(){_regeneratorRuntime=function(){return a};var u,a={},t=Object.prototype,s=t.hasOwnProperty,f=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(u){i=function(t,e,r){return t[e]=r}}function c(t,e,r,n){var o,i,a,c,e=e&&e.prototype instanceof g?e:g,e=Object.create(e.prototype),n=new S(n||[]);return f(e,"_invoke",{value:(o=t,i=r,a=n,c=l,function(t,e){if(c===y)throw Error("Generator is already running");if(c===v){if("throw"===t)throw e;return{value:u,done:!0}}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(o===u)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=u,t(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),d;n=h(o,e.iterator,r.arg);if("throw"===n.type)return r.method="throw",r.arg=n.arg,r.delegate=null,d;o=n.arg;return o?o.done?(r[e.resultName]=o.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=u),r.delegate=null,d):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,d)}(r,a);if(r){if(r===d)continue;return r}}if("next"===a.method)a.sent=a._sent=a.arg;else if("throw"===a.method){if(c===l)throw c=v,a.arg;a.dispatchException(a.arg)}else"return"===a.method&&a.abrupt("return",a.arg);c=y;r=h(o,i,a);if("normal"===r.type){if(c=a.done?v:p,r.arg===d)continue;return{value:r.arg,done:a.done}}"throw"===r.type&&(c=v,a.method="throw",a.arg=r.arg)}})}),e}function h(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}a.wrap=c;var l="suspendedStart",p="suspendedYield",y="executing",v="completed",d={};function g(){}function m(){}function w(){}var e={},x=(i(e,n,function(){return this}),Object.getPrototypeOf),x=x&&x(x(O([]))),b=(x&&x!==t&&s.call(x,n)&&(e=x),w.prototype=g.prototype=Object.create(e));function _(t){["next","throw","return"].forEach(function(e){i(t,e,function(t){return this._invoke(e,t)})})}function L(a,c){var e;f(this,"_invoke",{value:function(r,n){function t(){return new c(function(t,e){!function e(t,r,n,o){var i,t=h(a[t],a,r);if("throw"!==t.type)return(r=(i=t.arg).value)&&"object"==_typeof(r)&&s.call(r,"__await")?c.resolve(r.__await).then(function(t){e("next",t,n,o)},function(t){e("throw",t,n,o)}):c.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 E(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 k(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function S(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(E,this),this.reset(!0)}function O(e){if(e||""===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(s.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=u,t.done=!0,t}).next=t}throw new TypeError(_typeof(e)+" is not iterable")}return f(b,"constructor",{value:m.prototype=w,configurable:!0}),f(w,"constructor",{value:m,configurable:!0}),m.displayName=i(w,o,"GeneratorFunction"),a.isGeneratorFunction=function(t){t="function"==typeof t&&t.constructor;return!!t&&(t===m||"GeneratorFunction"===(t.displayName||t.name))},a.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,w):(t.__proto__=w,i(t,o,"GeneratorFunction")),t.prototype=Object.create(b),t},a.awrap=function(t){return{__await:t}},_(L.prototype),i(L.prototype,r,function(){return this}),a.AsyncIterator=L,a.async=function(t,e,r,n,o){void 0===o&&(o=Promise);var i=new L(c(t,e,r,n),o);return a.isGeneratorFunction(e)?i:i.next().then(function(t){return t.done?t.value:i.next()})},_(b),i(b,o,"Generator"),i(b,n,function(){return this}),i(b,"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=O,S.prototype={constructor:S,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=u,this.done=!1,this.delegate=null,this.method="next",this.arg=u,this.tryEntries.forEach(k),!t)for(var e in this)"t"===e.charAt(0)&&s.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=u)},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=u),!!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=s.call(o,"catchLoc"),c=s.call(o,"finallyLoc");if(a&&c){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(!c)throw 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&&s.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,d):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),d},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),k(r),d}},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,k(o)),n}throw Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:O(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=u),d}},a}function asyncGeneratorStep(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function _asyncToGenerator(c){return function(){var t=this,a=arguments;return new Promise(function(e,r){var n=c.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 AuthorizationPlugin(c){return function(t){var e,r,o=!1,i=null,a=new _queue.default(c);t.axios.interceptors.response.use(function(t){return i&&(c.sessionHistory.add(i),i=null),t},(e=_asyncToGenerator(_regeneratorRuntime().mark(function t(e){var r,n;return _regeneratorRuntime().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(r=e.response,c.checkResponse(r)){t.next=66;break}if(o){t.next=61;break}return o=!0,t.next=6,c.getSession();case 6:if(n=t.sent,c.sessionHistory.isDeprecated(n))return t.prev=8,t.next=11,c.onAuthorizedDenied(e);t.next=21;break;case 11:c.sessionHistory.clean(),t.next=17;break;case 14:throw t.prev=14,t.t0=t.catch(8),e;case 17:return t.prev=17,o=!1,a.clear(),t.finish(17);case 21:if(i=n,c.checkSession(e.config,n)){t.next=48;break}return t.prev=23,t.t1=c,t.next=27,c.refreshSession(n);case 27:return t.t2=t.sent,t.next=30,t.t1.storageSession.call(t.t1,t.t2);case 30:t.next=48;break;case 32:return t.prev=32,t.t3=t.catch(23),c.sessionHistory.deprecate(n),t.prev=35,t.next=38,c.onAuthorizedDenied(t.t3);case 38:c.sessionHistory.clean(),t.next=44;break;case 41:throw t.prev=41,t.t4=t.catch(35),e;case 44:return t.prev=44,o=!1,a.clear(),t.finish(44);case 48:for(o=!1;a.size;)a.pop();return t.prev=50,t.next=53,a.resend(e);case 53:return t.abrupt("return",t.sent);case 56:throw t.prev=56,t.t5=t.catch(50),t.t5;case 59:t.next=64;break;case 61:return t.next=63,a.push(e);case 63:return t.abrupt("return",t.sent);case 64:t.next=67;break;case 66:throw e;case 67:case"end":return t.stop()}},t,null,[[8,14,17,21],[23,32],[35,41,44,48],[50,56]])})),function(t){return e.apply(this,arguments)})),t.axios.interceptors.request.use((r=_asyncToGenerator(_regeneratorRuntime().mark(function t(e){var r;return _regeneratorRuntime().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,c.getSession();case 2:return r=t.sent,c.withAuthentication(e,r),t.abrupt("return",e);case 5:case"end":return t.stop()}},t)})),function(t){return r.apply(this,arguments)}))}}
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
+ exports.SessionStorage = exports.Authorizer = void 0;
124
+ exports["default"] = AuthorizationPlugin;
125
+ var queue_1 = require("./queue");
126
+ var authorizer_1 = require("./authorizer");
127
+ Object.defineProperty(exports, "Authorizer", {
128
+ enumerable: true,
129
+ get: function get() {
130
+ return authorizer_1["default"];
131
+ }
132
+ });
133
+ var storage_1 = require("./storage");
134
+ Object.defineProperty(exports, "SessionStorage", {
135
+ enumerable: true,
136
+ get: function get() {
137
+ return storage_1["default"];
138
+ }
139
+ });
140
+ function AuthorizationPlugin(authorizer, options) {
141
+ return function(axios, config) {
142
+ var unauthorized = false;
143
+ var expiredSession = null;
144
+ var queue = new queue_1["default"](authorizer, config, (options === null || options === void 0 ? void 0 : options.minTryRetryInterval) || 3000, (options === null || options === void 0 ? void 0 : options.maxTryRetryInterval) || 5000, (options === null || options === void 0 ? void 0 : options.retryTimes) || 3);
145
+ new queue_1["default"](authorizer, config, (options === null || options === void 0 ? void 0 : options.minTryRetryInterval) || 3000, (options === null || options === void 0 ? void 0 : options.maxTryRetryInterval) || 5000, (options === null || options === void 0 ? void 0 : options.retryTimes) || 3);
146
+ axios.interceptors.response.use(function(i) {
147
+ if (expiredSession) {
148
+ // Previously requests sent have been rejected, record and release it (will be resending)
149
+ authorizer.sessionHistory.add(expiredSession);
150
+ expiredSession = null;
151
+ }
152
+ return i;
153
+ }, function(e) {
154
+ return __awaiter(this, void 0, void 0, function() {
155
+ var response, session, e5_1, _a, _b, e2_1, e3_1, e4_1;
156
+ return __generator(this, function(_c) {
157
+ switch(_c.label){
158
+ case 0:
159
+ response = e.response;
160
+ if (!!authorizer.checkResponse(response)) return [
161
+ 3 /*break*/ ,
162
+ 24
163
+ ];
164
+ if (!!unauthorized) return [
165
+ 3 /*break*/ ,
166
+ 21
167
+ ];
168
+ unauthorized = true;
169
+ return [
170
+ 4 /*yield*/ ,
171
+ authorizer.getSession()
172
+ ];
173
+ case 1:
174
+ session = _c.sent();
175
+ if (!authorizer.sessionHistory.isDeprecated(session)) return [
176
+ 3 /*break*/ ,
177
+ 6
178
+ ];
179
+ _c.label = 2;
180
+ case 2:
181
+ _c.trys.push([
182
+ 2,
183
+ 4,
184
+ 5,
185
+ 6
186
+ ]);
187
+ // You may override this method for home page redirecting.
188
+ return [
189
+ 4 /*yield*/ ,
190
+ authorizer.onAuthorizedDenied(e)
191
+ ];
192
+ case 3:
193
+ // You may override this method for home page redirecting.
194
+ _c.sent();
195
+ authorizer.sessionHistory.clean();
196
+ return [
197
+ 3 /*break*/ ,
198
+ 6
199
+ ];
200
+ case 4:
201
+ e5_1 = _c.sent();
202
+ throw e;
203
+ case 5:
204
+ unauthorized = false;
205
+ queue.clear();
206
+ return [
207
+ 7 /*endfinally*/
208
+ ];
209
+ case 6:
210
+ expiredSession = session;
211
+ if (!!authorizer.checkSession(e.config, session)) return [
212
+ 3 /*break*/ ,
213
+ 16
214
+ ];
215
+ _c.label = 7;
216
+ case 7:
217
+ _c.trys.push([
218
+ 7,
219
+ 10,
220
+ ,
221
+ 16
222
+ ]);
223
+ _b = (_a = authorizer).storageSession;
224
+ return [
225
+ 4 /*yield*/ ,
226
+ authorizer.refreshSession(session)
227
+ ];
228
+ case 8:
229
+ // waiting for next accessToken refresh, on the server side, updates are synchronized.
230
+ // Note:
231
+ // even if the refreshing request send few times, the server side will only return the same token.
232
+ return [
233
+ 4 /*yield*/ ,
234
+ _b.apply(_a, [
235
+ _c.sent()
236
+ ])
237
+ ];
238
+ case 9:
239
+ // waiting for next accessToken refresh, on the server side, updates are synchronized.
240
+ // Note:
241
+ // even if the refreshing request send few times, the server side will only return the same token.
242
+ _c.sent();
243
+ return [
244
+ 3 /*break*/ ,
245
+ 16
246
+ ];
247
+ case 10:
248
+ e2_1 = _c.sent();
249
+ // invalid refresh_token
250
+ authorizer.sessionHistory.deprecate(session);
251
+ _c.label = 11;
252
+ case 11:
253
+ _c.trys.push([
254
+ 11,
255
+ 13,
256
+ 14,
257
+ 15
258
+ ]);
259
+ return [
260
+ 4 /*yield*/ ,
261
+ authorizer.onAuthorizedDenied(e2_1)
262
+ ];
263
+ case 12:
264
+ _c.sent();
265
+ authorizer.sessionHistory.clean();
266
+ return [
267
+ 3 /*break*/ ,
268
+ 15
269
+ ];
270
+ case 13:
271
+ e3_1 = _c.sent();
272
+ throw e;
273
+ case 14:
274
+ unauthorized = false;
275
+ // cancel all requests resending.
276
+ queue.clear();
277
+ return [
278
+ 7 /*endfinally*/
279
+ ];
280
+ case 15:
281
+ return [
282
+ 3 /*break*/ ,
283
+ 16
284
+ ];
285
+ case 16:
286
+ unauthorized = false;
287
+ // the accessToken refreshed, send the request itself and startup resending queue cleaning.
288
+ (function() {
289
+ while(queue.size){
290
+ queue.pop();
291
+ }
292
+ })();
293
+ _c.label = 17;
294
+ case 17:
295
+ _c.trys.push([
296
+ 17,
297
+ 19,
298
+ ,
299
+ 20
300
+ ]);
301
+ return [
302
+ 4 /*yield*/ ,
303
+ queue.resend(e)
304
+ ];
305
+ case 18:
306
+ return [
307
+ 2 /*return*/ ,
308
+ _c.sent()
309
+ ];
310
+ case 19:
311
+ e4_1 = _c.sent();
312
+ // 500 502 503 ...
313
+ throw e4_1;
314
+ case 20:
315
+ return [
316
+ 3 /*break*/ ,
317
+ 23
318
+ ];
319
+ case 21:
320
+ return [
321
+ 4 /*yield*/ ,
322
+ queue.push(e)
323
+ ];
324
+ case 22:
325
+ // No, 401 request occurred, put in to resending queue itself and waiting.
326
+ return [
327
+ 2 /*return*/ ,
328
+ _c.sent()
329
+ ];
330
+ case 23:
331
+ return [
332
+ 3 /*break*/ ,
333
+ 25
334
+ ];
335
+ case 24:
336
+ // HTTP Code = 500 503 502 ... just throw it
337
+ throw e;
338
+ case 25:
339
+ return [
340
+ 2 /*return*/
341
+ ];
342
+ }
343
+ });
344
+ });
345
+ });
346
+ axios.interceptors.request.use(function(request) {
347
+ return __awaiter(this, void 0, void 0, function() {
348
+ var session;
349
+ return __generator(this, function(_a) {
350
+ switch(_a.label){
351
+ case 0:
352
+ return [
353
+ 4 /*yield*/ ,
354
+ authorizer.getSession()
355
+ ];
356
+ case 1:
357
+ session = _a.sent();
358
+ authorizer.withAuthentication(request, session);
359
+ return [
360
+ 2 /*return*/ ,
361
+ request
362
+ ];
363
+ }
364
+ });
365
+ });
366
+ });
367
+ };
368
+ }
@@ -1,16 +1,28 @@
1
- import {AxiosError, AxiosPromise} from "axios";
2
- import Authorizer from "./authorizer";
3
-
4
- export default class PendingQueue {
5
- constructor(authorizer: Authorizer);
6
-
7
- resend(error: AxiosError, retries?: number): AxiosPromise<any>;
8
-
9
- push(error: AxiosError): AxiosPromise<any>;
10
-
11
- pop(): void;
12
-
13
- clear(): void;
14
-
15
- size: number;
16
- }
1
+ import type { AxiosError } from "axios";
2
+ import Authorizer from "./authorizer";
3
+ import { Config } from "../../index";
4
+ export default class PendingQueue {
5
+ _queue: {
6
+ error: AxiosError;
7
+ resolve: (arg: any) => void;
8
+ reject: (arg: any) => void;
9
+ }[];
10
+ _authorizer: Authorizer;
11
+ _config: Config;
12
+ _minTryRetryInterval: number;
13
+ _maxTryRetryInterval: number;
14
+ _retryTimes: number;
15
+ /**
16
+ * @param {Authorizer} authorizer
17
+ * @param {Config} config
18
+ * @param {number} minTryRetryInterval
19
+ * @param {number} maxTryRetryInterval
20
+ * @param retryTimes
21
+ */
22
+ constructor(authorizer: Authorizer, config: Config, minTryRetryInterval?: number, maxTryRetryInterval?: number, retryTimes?: number);
23
+ resend(error: AxiosError, retries?: number): Promise<any>;
24
+ push(error: AxiosError): Promise<any>;
25
+ pop(): void;
26
+ clear(): void;
27
+ get size(): number;
28
+ }