authscape 1.0.90 → 1.0.92
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/.babelrc +2 -2
- package/index.js +16 -37
- package/package.json +1 -3
- package/src/index.js +12 -12
- package/src/services/apiService.js +15 -15
- package/src/services/helper.js +0 -11
package/.babelrc
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
{
|
|
2
|
-
"presets": ["@babel/preset-react", "@babel/preset-env"]
|
|
1
|
+
{
|
|
2
|
+
"presets": ["@babel/preset-react", "@babel/preset-env"]
|
|
3
3
|
}
|
package/index.js
CHANGED
|
@@ -322,8 +322,6 @@ var _queryString = _interopRequireDefault(require("query-string"));
|
|
|
322
322
|
|
|
323
323
|
var _jsFileDownload = _interopRequireDefault(require("js-file-download"));
|
|
324
324
|
|
|
325
|
-
var _nextCookies = _interopRequireDefault(require("next-cookies"));
|
|
326
|
-
|
|
327
325
|
var _nookies = require("nookies");
|
|
328
326
|
|
|
329
327
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
@@ -340,7 +338,6 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
|
|
|
340
338
|
|
|
341
339
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
342
340
|
|
|
343
|
-
// import Helper from "./helper";
|
|
344
341
|
var setupDefaultOptions = /*#__PURE__*/function () {
|
|
345
342
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
346
343
|
var ctx,
|
|
@@ -351,11 +348,11 @@ var setupDefaultOptions = /*#__PURE__*/function () {
|
|
|
351
348
|
while (1) {
|
|
352
349
|
switch (_context.prev = _context.next) {
|
|
353
350
|
case 0:
|
|
354
|
-
ctx = _args.length > 0 && _args[0] !== undefined ? _args[0] :
|
|
351
|
+
ctx = _args.length > 0 && _args[0] !== undefined ? _args[0] : null;
|
|
355
352
|
defaultOptions = {};
|
|
356
353
|
|
|
357
|
-
if (
|
|
358
|
-
accessToken = (0,
|
|
354
|
+
if (ctx == null) {
|
|
355
|
+
accessToken = (0, _nookies.parseCookies)().access_token || '';
|
|
359
356
|
|
|
360
357
|
if (accessToken !== null && accessToken !== undefined && accessToken != "") {
|
|
361
358
|
defaultOptions = {
|
|
@@ -396,8 +393,8 @@ var RefreshToken = /*#__PURE__*/function () {
|
|
|
396
393
|
while (1) {
|
|
397
394
|
switch (_context2.prev = _context2.next) {
|
|
398
395
|
case 0:
|
|
399
|
-
accessToken = (0,
|
|
400
|
-
refreshToken = (0,
|
|
396
|
+
accessToken = (0, _nookies.parseCookies)().access_token || '';
|
|
397
|
+
refreshToken = (0, _nookies.parseCookies)().refresh_token || '';
|
|
401
398
|
_context2.next = 4;
|
|
402
399
|
return instance.post(process.env.AUTHORITYURI + "/connect/token", _queryString["default"].stringify({
|
|
403
400
|
grant_type: 'refresh_token',
|
|
@@ -460,7 +457,7 @@ var RefreshToken = /*#__PURE__*/function () {
|
|
|
460
457
|
}();
|
|
461
458
|
|
|
462
459
|
var apiService = function apiService() {
|
|
463
|
-
var ctx = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] :
|
|
460
|
+
var ctx = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
464
461
|
var env = process.env.STAGE;
|
|
465
462
|
|
|
466
463
|
if (env == "development") {
|
|
@@ -514,17 +511,17 @@ var apiService = function apiService() {
|
|
|
514
511
|
// Do something
|
|
515
512
|
if (error.response.config.url.includes("/connect/token")) // remove the access and refresh if invalid
|
|
516
513
|
{
|
|
517
|
-
(0, _nookies.destroyCookie)(
|
|
514
|
+
(0, _nookies.destroyCookie)(null, "access_token", {
|
|
518
515
|
maxAge: 2147483647,
|
|
519
516
|
path: '/',
|
|
520
517
|
domain: process.env.cookieDomain
|
|
521
518
|
});
|
|
522
|
-
(0, _nookies.destroyCookie)(
|
|
519
|
+
(0, _nookies.destroyCookie)(null, "refresh_token", {
|
|
523
520
|
maxAge: 2147483647,
|
|
524
521
|
path: '/',
|
|
525
522
|
domain: process.env.cookieDomain
|
|
526
523
|
});
|
|
527
|
-
(0, _nookies.destroyCookie)(
|
|
524
|
+
(0, _nookies.destroyCookie)(null, "expires_in", {
|
|
528
525
|
maxAge: 2147483647,
|
|
529
526
|
path: '/',
|
|
530
527
|
domain: process.env.cookieDomain
|
|
@@ -721,7 +718,7 @@ var apiService = function apiService() {
|
|
|
721
718
|
switch (_context8.prev = _context8.next) {
|
|
722
719
|
case 0:
|
|
723
720
|
_context8.prev = 0;
|
|
724
|
-
accessToken = (0,
|
|
721
|
+
accessToken = (0, _nookies.parseCookies)().access_token || null;
|
|
725
722
|
|
|
726
723
|
if (!accessToken) {
|
|
727
724
|
_context8.next = 11;
|
|
@@ -729,7 +726,7 @@ var apiService = function apiService() {
|
|
|
729
726
|
}
|
|
730
727
|
|
|
731
728
|
_context8.next = 5;
|
|
732
|
-
return setupDefaultOptions(
|
|
729
|
+
return setupDefaultOptions(null);
|
|
733
730
|
|
|
734
731
|
case 5:
|
|
735
732
|
defaultOptions = _context8.sent;
|
|
@@ -747,17 +744,19 @@ var apiService = function apiService() {
|
|
|
747
744
|
return _context8.abrupt("return", response.data);
|
|
748
745
|
|
|
749
746
|
case 11:
|
|
750
|
-
_context8.next =
|
|
747
|
+
_context8.next = 16;
|
|
751
748
|
break;
|
|
752
749
|
|
|
753
750
|
case 13:
|
|
754
751
|
_context8.prev = 13;
|
|
755
752
|
_context8.t0 = _context8["catch"](0);
|
|
753
|
+
//return -1;
|
|
754
|
+
console.log(_context8.t0.message);
|
|
756
755
|
|
|
757
|
-
case
|
|
756
|
+
case 16:
|
|
758
757
|
return _context8.abrupt("return", null);
|
|
759
758
|
|
|
760
|
-
case
|
|
759
|
+
case 17:
|
|
761
760
|
case "end":
|
|
762
761
|
return _context8.stop();
|
|
763
762
|
}
|
|
@@ -1108,26 +1107,6 @@ var authService = function authService() {
|
|
|
1108
1107
|
exports.authService = authService;
|
|
1109
1108
|
"use strict";
|
|
1110
1109
|
|
|
1111
|
-
Object.defineProperty(exports, "__esModule", {
|
|
1112
|
-
value: true
|
|
1113
|
-
});
|
|
1114
|
-
exports.Helper = void 0;
|
|
1115
|
-
|
|
1116
|
-
var _react = _interopRequireDefault(require("react"));
|
|
1117
|
-
|
|
1118
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
1119
|
-
|
|
1120
|
-
var Helper = function Helper() {
|
|
1121
|
-
return {
|
|
1122
|
-
isObjectEmpty: function isObjectEmpty(obj) {
|
|
1123
|
-
return Object.keys(obj).length == 0;
|
|
1124
|
-
}
|
|
1125
|
-
};
|
|
1126
|
-
};
|
|
1127
|
-
|
|
1128
|
-
exports.Helper = Helper;
|
|
1129
|
-
"use strict";
|
|
1130
|
-
|
|
1131
1110
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
1132
1111
|
|
|
1133
1112
|
Object.defineProperty(exports, "__esModule", {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "authscape",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.92",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
"axios": "^0.27.2",
|
|
14
14
|
"js-file-download": "^0.4.12",
|
|
15
15
|
"next": "^12.2.0",
|
|
16
|
-
"next-cookies": "^2.0.3",
|
|
17
16
|
"nookies": "^2.5.2",
|
|
18
17
|
"react": "^17.0.2",
|
|
19
18
|
"react-data-table-component": "^7.5.2",
|
|
@@ -31,7 +30,6 @@
|
|
|
31
30
|
"axios": "^0.27.2",
|
|
32
31
|
"js-file-download": "^0.4.12",
|
|
33
32
|
"next": "^12.2.0",
|
|
34
|
-
"next-cookies": "^2.0.3",
|
|
35
33
|
"nookies": "^2.5.2",
|
|
36
34
|
"query-string": "^7.1.1",
|
|
37
35
|
"react-data-table-component": "^7.5.2"
|
package/src/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import React, { Component } from 'react';
|
|
2
|
-
|
|
3
|
-
export default class DummyComponent extends Component {
|
|
4
|
-
|
|
5
|
-
render () {
|
|
6
|
-
|
|
7
|
-
return (
|
|
8
|
-
<div>I am a dummy react npm module</div>
|
|
9
|
-
)
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
1
|
+
import React, { Component } from 'react';
|
|
2
|
+
|
|
3
|
+
export default class DummyComponent extends Component {
|
|
4
|
+
|
|
5
|
+
render () {
|
|
6
|
+
|
|
7
|
+
return (
|
|
8
|
+
<div>I am a dummy react npm module</div>
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
}
|
|
12
|
+
|
|
13
13
|
}
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import axios from 'axios'
|
|
2
2
|
import querystring from 'query-string';
|
|
3
3
|
import fileDownload from 'js-file-download';
|
|
4
|
-
import
|
|
5
|
-
import { setCookie, destroyCookie } from 'nookies';
|
|
6
|
-
// import Helper from "./helper";
|
|
4
|
+
import { parseCookies, setCookie, destroyCookie } from 'nookies';
|
|
7
5
|
|
|
8
|
-
const setupDefaultOptions = async (ctx =
|
|
6
|
+
const setupDefaultOptions = async (ctx = null) => {
|
|
9
7
|
|
|
10
8
|
let defaultOptions = {};
|
|
11
|
-
if (
|
|
9
|
+
if (ctx == null)
|
|
12
10
|
{
|
|
13
|
-
let accessToken =
|
|
11
|
+
let accessToken = parseCookies().access_token || '';
|
|
14
12
|
|
|
15
13
|
if (accessToken !== null && accessToken !== undefined && accessToken != "") {
|
|
16
14
|
defaultOptions = {
|
|
@@ -39,8 +37,8 @@ const setupDefaultOptions = async (ctx = {}) => {
|
|
|
39
37
|
|
|
40
38
|
const RefreshToken = async (originalRequest, instance) => {
|
|
41
39
|
|
|
42
|
-
let accessToken =
|
|
43
|
-
let refreshToken =
|
|
40
|
+
let accessToken = parseCookies().access_token || '';
|
|
41
|
+
let refreshToken = parseCookies().refresh_token || '';
|
|
44
42
|
|
|
45
43
|
let response = await instance.post(process.env.AUTHORITYURI + "/connect/token",
|
|
46
44
|
querystring.stringify({
|
|
@@ -85,7 +83,7 @@ const RefreshToken = async (originalRequest, instance) => {
|
|
|
85
83
|
}
|
|
86
84
|
}
|
|
87
85
|
|
|
88
|
-
export const apiService = (ctx =
|
|
86
|
+
export const apiService = (ctx = null) => {
|
|
89
87
|
|
|
90
88
|
let env = process.env.STAGE;
|
|
91
89
|
if (env == "development")
|
|
@@ -112,7 +110,7 @@ export const apiService = (ctx = {}) => {
|
|
|
112
110
|
|
|
113
111
|
if (error.response.status === 401 && !originalConfig._retry) {
|
|
114
112
|
originalConfig._retry = true;
|
|
115
|
-
|
|
113
|
+
|
|
116
114
|
// Do something, call refreshToken() request for example;
|
|
117
115
|
await RefreshToken(originalConfig, instance);
|
|
118
116
|
|
|
@@ -125,19 +123,19 @@ export const apiService = (ctx = {}) => {
|
|
|
125
123
|
|
|
126
124
|
if (error.response.config.url.includes("/connect/token")) // remove the access and refresh if invalid
|
|
127
125
|
{
|
|
128
|
-
destroyCookie(
|
|
126
|
+
destroyCookie(null, "access_token", {
|
|
129
127
|
maxAge: 2147483647,
|
|
130
128
|
path: '/',
|
|
131
129
|
domain: process.env.cookieDomain
|
|
132
130
|
});
|
|
133
131
|
|
|
134
|
-
destroyCookie(
|
|
132
|
+
destroyCookie(null, "refresh_token", {
|
|
135
133
|
maxAge: 2147483647,
|
|
136
134
|
path: '/',
|
|
137
135
|
domain: process.env.cookieDomain
|
|
138
136
|
});
|
|
139
137
|
|
|
140
|
-
destroyCookie(
|
|
138
|
+
destroyCookie(null, "expires_in", {
|
|
141
139
|
maxAge: 2147483647,
|
|
142
140
|
path: '/',
|
|
143
141
|
domain: process.env.cookieDomain
|
|
@@ -206,10 +204,11 @@ export const apiService = (ctx = {}) => {
|
|
|
206
204
|
|
|
207
205
|
try
|
|
208
206
|
{
|
|
209
|
-
let accessToken =
|
|
207
|
+
let accessToken = parseCookies().access_token || null;
|
|
208
|
+
|
|
210
209
|
if (accessToken)
|
|
211
210
|
{
|
|
212
|
-
let defaultOptions = await setupDefaultOptions(
|
|
211
|
+
let defaultOptions = await setupDefaultOptions(null);
|
|
213
212
|
const response = await instance.get('/UserManagement', defaultOptions);
|
|
214
213
|
if (response != null && response.status == 200)
|
|
215
214
|
{
|
|
@@ -223,6 +222,7 @@ export const apiService = (ctx = {}) => {
|
|
|
223
222
|
|
|
224
223
|
} catch(exp) {
|
|
225
224
|
//return -1;
|
|
225
|
+
console.log(exp.message);
|
|
226
226
|
}
|
|
227
227
|
return null;
|
|
228
228
|
},
|