axios-annotations 2.3.0 → 3.1.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 +774 -741
- package/es/core/builder.d.ts +33 -0
- package/es/core/builder.js +515 -0
- package/es/core/common.d.ts +36 -0
- package/es/core/common.js +148 -0
- package/es/core/config.d.ts +60 -0
- package/es/core/config.js +357 -0
- package/es/core/core-expect.js +3 -0
- package/es/core/expect.d.ts +2 -0
- package/es/core/expect.js +2 -0
- package/es/core/provider.d.ts +6 -0
- package/es/core/provider.js +172 -0
- package/es/core/service.d.ts +5 -0
- package/es/core/service.js +57 -0
- package/es/decorator/path-variables.d.ts +7 -0
- package/es/decorator/path-variables.js +32 -0
- package/es/decorator/request-body.d.ts +7 -0
- package/es/decorator/request-body.js +31 -0
- package/es/decorator/request-config.d.ts +7 -0
- package/es/decorator/request-config.js +25 -0
- package/es/decorator/request-header.d.ts +4 -0
- package/es/decorator/request-header.js +14 -0
- package/es/decorator/request-mapping.d.ts +6 -0
- package/es/decorator/request-mapping.js +56 -0
- package/es/decorator/request-param.d.ts +4 -0
- package/es/decorator/request-param.js +15 -0
- package/es/decorator/request-with.d.ts +3 -0
- package/es/decorator/request-with.js +8 -0
- package/es/index.d.ts +13 -0
- package/es/index.js +14 -0
- package/es/plugins/auth/authorizer.d.ts +24 -0
- package/es/plugins/auth/authorizer.js +268 -0
- package/es/plugins/auth/history.d.ts +15 -0
- package/es/plugins/auth/history.js +94 -0
- package/es/plugins/auth/index.d.ts +16 -0
- package/es/plugins/auth/index.js +358 -0
- package/es/plugins/auth/queue.d.ts +29 -0
- package/es/plugins/auth/queue.js +281 -0
- package/es/plugins/auth/storage.d.ts +6 -0
- package/es/plugins/auth/storage.js +203 -0
- package/lib/core/builder.d.ts +33 -0
- package/lib/core/builder.js +520 -0
- package/lib/core/common.d.ts +34 -4
- package/lib/core/common.js +139 -147
- package/lib/core/config.d.ts +15 -15
- package/lib/core/config.js +44 -14
- package/lib/core/core-expect.js +8 -0
- package/lib/core/expect.d.ts +2 -4
- package/lib/core/expect.js +6 -15
- package/lib/core/provider.d.ts +5 -5
- package/lib/core/provider.js +2 -2
- package/lib/core/service.d.ts +3 -151
- package/lib/core/service.js +43 -544
- package/lib/decorator/path-variables.d.ts +7 -0
- package/lib/decorator/path-variables.js +37 -0
- package/lib/decorator/request-body.d.ts +7 -1
- package/lib/decorator/request-body.js +28 -20
- package/lib/decorator/request-config.d.ts +6 -4
- package/lib/decorator/request-config.js +23 -16
- package/lib/decorator/request-header.d.ts +4 -2
- package/lib/decorator/request-header.js +11 -13
- package/lib/decorator/request-mapping.d.ts +6 -3
- package/lib/decorator/request-mapping.js +46 -43
- package/lib/decorator/request-param.d.ts +4 -1
- package/lib/decorator/request-param.js +12 -19
- package/lib/decorator/request-with.d.ts +3 -1
- package/lib/decorator/request-with.js +6 -13
- package/lib/index.d.ts +4 -11
- package/lib/index.js +19 -68
- package/lib/plugins/auth/authorizer.d.ts +6 -5
- package/lib/plugins/auth/authorizer.js +3 -2
- package/lib/plugins/auth/history.d.ts +5 -4
- package/lib/plugins/auth/history.js +2 -0
- package/lib/plugins/auth/index.d.ts +7 -0
- package/lib/plugins/auth/index.js +11 -3
- package/lib/plugins/auth/queue.d.ts +3 -2
- package/lib/plugins/auth/queue.js +31 -24
- package/lib/plugins/auth/storage.js +2 -2
- package/package.json +42 -7
- package/wechat-mp/core/builder.d.ts +33 -0
- package/wechat-mp/core/builder.js +520 -0
- package/wechat-mp/core/common.d.ts +36 -0
- package/wechat-mp/core/common.js +158 -0
- package/wechat-mp/core/config.d.ts +60 -0
- package/wechat-mp/core/config.js +362 -0
- package/wechat-mp/core/core-expect.js +8 -0
- package/wechat-mp/core/expect.d.ts +2 -0
- package/wechat-mp/core/expect.js +6 -0
- package/wechat-mp/core/provider.d.ts +6 -0
- package/wechat-mp/core/provider.js +178 -0
- package/wechat-mp/core/service.d.ts +5 -0
- package/wechat-mp/core/service.js +61 -0
- package/wechat-mp/decorator/path-variables.d.ts +7 -0
- package/wechat-mp/decorator/path-variables.js +37 -0
- package/wechat-mp/decorator/request-body.d.ts +7 -0
- package/wechat-mp/decorator/request-body.js +36 -0
- package/wechat-mp/decorator/request-config.d.ts +7 -0
- package/wechat-mp/decorator/request-config.js +30 -0
- package/wechat-mp/decorator/request-header.d.ts +4 -0
- package/wechat-mp/decorator/request-header.js +19 -0
- package/wechat-mp/decorator/request-mapping.d.ts +6 -0
- package/wechat-mp/decorator/request-mapping.js +61 -0
- package/wechat-mp/decorator/request-param.d.ts +4 -0
- package/wechat-mp/decorator/request-param.js +20 -0
- package/wechat-mp/decorator/request-with.d.ts +3 -0
- package/wechat-mp/decorator/request-with.js +13 -0
- package/wechat-mp/index.d.ts +13 -0
- package/wechat-mp/index.js +97 -0
- package/wechat-mp/plugins/auth/authorizer.d.ts +24 -0
- package/wechat-mp/plugins/auth/authorizer.js +272 -0
- package/wechat-mp/plugins/auth/history.d.ts +15 -0
- package/wechat-mp/plugins/auth/history.js +98 -0
- package/wechat-mp/plugins/auth/index.d.ts +16 -0
- package/wechat-mp/plugins/auth/index.js +376 -0
- package/wechat-mp/plugins/auth/queue.d.ts +29 -0
- package/wechat-mp/plugins/auth/queue.js +285 -0
- package/wechat-mp/plugins/auth/storage.d.ts +6 -0
- package/wechat-mp/plugins/auth/storage.js +207 -0
- package/index.d.ts +0 -1
- package/index.js +0 -127
- package/lib/core/cancel.d.ts +0 -30
- package/lib/core/cancel.js +0 -56
- package/lib/core/parser.d.ts +0 -19
- package/lib/core/parser.js +0 -79
- package/lib/decorator/abort-source.d.ts +0 -3
- package/lib/decorator/abort-source.js +0 -25
- package/lib/decorator/delete-mapping.d.ts +0 -1
- package/lib/decorator/delete-mapping.js +0 -13
- package/lib/decorator/get-mapping.d.ts +0 -1
- package/lib/decorator/get-mapping.js +0 -13
- package/lib/decorator/ignore-residual-params.d.ts +0 -1
- package/lib/decorator/ignore-residual-params.js +0 -24
- package/lib/decorator/patch-mapping.d.ts +0 -1
- package/lib/decorator/patch-mapping.js +0 -13
- package/lib/decorator/post-mapping.d.ts +0 -1
- package/lib/decorator/post-mapping.js +0 -13
- package/lib/decorator/put-mapping.d.ts +0 -1
- package/lib/decorator/put-mapping.js +0 -13
- package/plugins/auth/index.d.ts +0 -4
- package/plugins/auth/index.js +0 -26
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (void 0) && (void 0).__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 = (void 0) && (void 0).__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
|
+
// 匹配队列中的请求头token跟会话token是否一致
|
|
219
|
+
Authorizer.prototype.checkSession = function(request, session) {
|
|
220
|
+
var header = (request.headers || {})["Authorization"] || (request.headers || {})["authorization"];
|
|
221
|
+
var jwt = typeof header === "string" ? header.split(" ")[1] || "" : "";
|
|
222
|
+
var token = session.access_token || session.accessToken || session.token;
|
|
223
|
+
if (token === jwt) {
|
|
224
|
+
// request header token equal to invalid session token
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
227
|
+
// request time is too long , token may be refreshed few times
|
|
228
|
+
if (this.sessionHistory.size) {
|
|
229
|
+
if (this.sessionHistory.check(jwt)) {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return true;
|
|
234
|
+
};
|
|
235
|
+
Authorizer.prototype.checkResponse = function(response) {
|
|
236
|
+
var status = (response || {
|
|
237
|
+
status: 0
|
|
238
|
+
}).status;
|
|
239
|
+
return status !== 401;
|
|
240
|
+
};
|
|
241
|
+
Authorizer.prototype.onAuthorizedDenied = function(error) {
|
|
242
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
243
|
+
return __generator(this, function(_a) {
|
|
244
|
+
throw error;
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
};
|
|
248
|
+
Authorizer.prototype.onSessionInvalidated = function() {
|
|
249
|
+
return;
|
|
250
|
+
};
|
|
251
|
+
Authorizer.prototype.invalidateSession = function() {
|
|
252
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
253
|
+
return __generator(this, function(_a) {
|
|
254
|
+
switch(_a.label){
|
|
255
|
+
case 0:
|
|
256
|
+
return [
|
|
257
|
+
4 /*yield*/ ,
|
|
258
|
+
this.sessionStorage.remove(this.sessionKey)
|
|
259
|
+
];
|
|
260
|
+
case 1:
|
|
261
|
+
_a.sent();
|
|
262
|
+
this.onSessionInvalidated();
|
|
263
|
+
return [
|
|
264
|
+
2 /*return*/
|
|
265
|
+
];
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
};
|
|
270
|
+
return Authorizer;
|
|
271
|
+
}();
|
|
272
|
+
exports["default"] = Authorizer;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BasicSession } from "./index";
|
|
2
|
+
/**
|
|
3
|
+
* 缓存过期会话,判断请求是否过期
|
|
4
|
+
*/
|
|
5
|
+
export default class SessionHistory {
|
|
6
|
+
_history: (BasicSession | null)[];
|
|
7
|
+
_position: number;
|
|
8
|
+
_size: number;
|
|
9
|
+
get size(): number;
|
|
10
|
+
add(session: BasicSession): void;
|
|
11
|
+
check(jwt: string): boolean;
|
|
12
|
+
deprecate(session: BasicSession): void;
|
|
13
|
+
clean(): void;
|
|
14
|
+
isDeprecated(session: BasicSession): boolean;
|
|
15
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
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
|
+
// 缓存 session 历史,这里只是添加并未作废,防止同时存在多个有效 session,这里允许存放有效 session
|
|
25
|
+
// 使用 invalid 作为标记
|
|
26
|
+
SessionHistory.prototype.add = function(session) {
|
|
27
|
+
if (Object.keys(session).every(function(i) {
|
|
28
|
+
return (0, common_1.isNullOrEmpty)(session[i]);
|
|
29
|
+
})) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
var access_token = session.access_token, accessToken = session.accessToken, token = session.token, refresh_token = session.refresh_token, refreshToken = session.refreshToken;
|
|
33
|
+
this._history[this._position] = Object.assign({}, session, {
|
|
34
|
+
access_token: access_token || accessToken || token,
|
|
35
|
+
refresh_token: refresh_token || refreshToken,
|
|
36
|
+
invalid: false
|
|
37
|
+
});
|
|
38
|
+
this._position++;
|
|
39
|
+
this._position %= this._history.length;
|
|
40
|
+
this._size = this._history.reduce(function(s, i) {
|
|
41
|
+
return i ? s + 1 : s;
|
|
42
|
+
}, 0);
|
|
43
|
+
};
|
|
44
|
+
// session exist or not
|
|
45
|
+
SessionHistory.prototype.check = function(jwt) {
|
|
46
|
+
return this._history.some(function(session) {
|
|
47
|
+
if (session) {
|
|
48
|
+
var access_token = session.access_token, accessToken = session.accessToken, token = session.token;
|
|
49
|
+
return (access_token || accessToken || token) === jwt;
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
// mark the session expired
|
|
55
|
+
SessionHistory.prototype.deprecate = function(session) {
|
|
56
|
+
var position = 0;
|
|
57
|
+
var refresh_token = session.refresh_token, refreshToken = session.refreshToken;
|
|
58
|
+
var matching = this._history.find(function(s, i) {
|
|
59
|
+
position = i;
|
|
60
|
+
if (s) {
|
|
61
|
+
return (s.refresh_token || s.refreshToken) === (refresh_token || refreshToken);
|
|
62
|
+
}
|
|
63
|
+
return false;
|
|
64
|
+
});
|
|
65
|
+
if (matching) {
|
|
66
|
+
matching.invalid = true;
|
|
67
|
+
var first = this._history[0];
|
|
68
|
+
this._history[0] = this._history[position];
|
|
69
|
+
this._history[position] = first;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
// remove expired sessions
|
|
73
|
+
SessionHistory.prototype.clean = function() {
|
|
74
|
+
for(var i = 0; i < this._history.length; ++i){
|
|
75
|
+
var s = this._history[i];
|
|
76
|
+
if (s && s.invalid) {
|
|
77
|
+
this._history[i] = null;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
this._size = this._history.reduce(function(s, i) {
|
|
81
|
+
return i ? s + 1 : s;
|
|
82
|
+
}, 0);
|
|
83
|
+
};
|
|
84
|
+
// is the session expired
|
|
85
|
+
SessionHistory.prototype.isDeprecated = function(session) {
|
|
86
|
+
return this._history.some(function(s) {
|
|
87
|
+
if (s) {
|
|
88
|
+
var refresh_token = session.refresh_token, refreshToken = session.refreshToken;
|
|
89
|
+
if (refresh_token || refreshToken) {
|
|
90
|
+
return (s.refresh_token || s.refreshToken) === (refresh_token || refreshToken) && s.invalid;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return false;
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
return SessionHistory;
|
|
97
|
+
}();
|
|
98
|
+
exports["default"] = SessionHistory;
|
|
@@ -0,0 +1,16 @@
|
|
|
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 type BasicSession = {
|
|
6
|
+
access_token?: string;
|
|
7
|
+
accessToken?: string;
|
|
8
|
+
token?: string;
|
|
9
|
+
refreshToken?: string;
|
|
10
|
+
refresh_token?: string;
|
|
11
|
+
} & Record<string, any>;
|
|
12
|
+
export default function AuthorizationPlugin(authorizer: Authorizer, options?: {
|
|
13
|
+
minTryRetryInterval: number;
|
|
14
|
+
maxTryRetryInterval: number;
|
|
15
|
+
retryTimes: number;
|
|
16
|
+
}): ConfigPlugin;
|