analytica.click 0.0.235 → 0.0.239
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/dist/index.d.ts +8 -0
- package/dist/index.js +88 -56
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
@@ -216,6 +216,14 @@ declare module 'analytica.click/ui-npm/src/components/UserProvider/refreshToken'
|
|
216
216
|
logout: () => void;
|
217
217
|
}): Promise<User | undefined>;
|
218
218
|
|
219
|
+
}
|
220
|
+
declare module 'analytica.click/ui-npm/src/components/UserProvider/useGranularHook' {
|
221
|
+
import { DependencyList, EffectCallback } from 'react';
|
222
|
+
type HookWithDependencies<C, R> = (callback: C, deps: DependencyList) => R;
|
223
|
+
export const useGranularHook: <T extends HookWithDependencies<C, ReturnType<T>>, C>(hook: T, callback: C, primaryDeps: DependencyList, secondaryDeps: DependencyList) => ReturnType<T>;
|
224
|
+
export const useGranularEffect: (effect: EffectCallback, primaryDeps: DependencyList, secondaryDeps: DependencyList) => void;
|
225
|
+
export {};
|
226
|
+
|
219
227
|
}
|
220
228
|
declare module 'analytica.click/ui-npm/src/components/index' {
|
221
229
|
export * from 'analytica.click/ui-npm/src/components/AnalyticaConfig/index';
|
package/dist/index.js
CHANGED
@@ -1310,13 +1310,45 @@ function getTokensFromCode(_0) {
|
|
1310
1310
|
});
|
1311
1311
|
}
|
1312
1312
|
|
1313
|
+
// src/components/UserProvider/useGranularHook.ts
|
1314
|
+
var import_react7 = require("react");
|
1315
|
+
var useGranularHook = (hook, callback, primaryDeps, secondaryDeps) => {
|
1316
|
+
const ref = (0, import_react7.useRef)();
|
1317
|
+
if (!ref.current || !primaryDeps.every((w, i) => {
|
1318
|
+
var _a;
|
1319
|
+
return Object.is(w, (_a = ref.current) == null ? void 0 : _a[i]);
|
1320
|
+
}))
|
1321
|
+
ref.current = [...primaryDeps, ...secondaryDeps];
|
1322
|
+
return hook(callback, ref.current);
|
1323
|
+
};
|
1324
|
+
var useGranularEffect = (effect, primaryDeps, secondaryDeps) => useGranularHook(import_react7.useEffect, effect, primaryDeps, secondaryDeps);
|
1325
|
+
|
1313
1326
|
// src/components/UserProvider/index.tsx
|
1314
1327
|
var import_log9 = require("ag-common/dist/common/helpers/log");
|
1315
|
-
var
|
1328
|
+
var import_react8 = __toESM(require("react"));
|
1316
1329
|
var import_useLocalStorage = require("ag-common/dist/ui/helpers/useLocalStorage");
|
1317
1330
|
var import_cookie = require("ag-common/dist/ui/helpers/cookie");
|
1318
1331
|
var import_dom3 = __toESM(require_dom());
|
1319
|
-
var CognitoAuthContext =
|
1332
|
+
var CognitoAuthContext = import_react8.default.createContext(void 0);
|
1333
|
+
var getStatefulUrl = ({
|
1334
|
+
redirectUrl,
|
1335
|
+
qs
|
1336
|
+
}) => {
|
1337
|
+
let url = redirectUrl || "/";
|
1338
|
+
if (qs == null ? void 0 : qs.state) {
|
1339
|
+
try {
|
1340
|
+
if (!url.includes("?")) {
|
1341
|
+
url += "?";
|
1342
|
+
} else {
|
1343
|
+
url += "&";
|
1344
|
+
}
|
1345
|
+
url += `state=${qs.state}`;
|
1346
|
+
} catch (e) {
|
1347
|
+
(0, import_log9.warn)("bad state passed in");
|
1348
|
+
}
|
1349
|
+
}
|
1350
|
+
return url;
|
1351
|
+
};
|
1320
1352
|
var CognitoAuthProvider = ({
|
1321
1353
|
config,
|
1322
1354
|
children,
|
@@ -1327,7 +1359,7 @@ var CognitoAuthProvider = ({
|
|
1327
1359
|
cookieDocument
|
1328
1360
|
}) => {
|
1329
1361
|
var _a, _b;
|
1330
|
-
const [error2, setError] = (0,
|
1362
|
+
const [error2, setError] = (0, import_react8.useState)();
|
1331
1363
|
const [idTokenRaw, setIdToken] = (0, import_cookie.useCookieString)({
|
1332
1364
|
name: "id_token",
|
1333
1365
|
cookieDocument: typeof window === "undefined" ? cookieDocument : void 0,
|
@@ -1344,8 +1376,12 @@ var CognitoAuthProvider = ({
|
|
1344
1376
|
if (idToken && !(0, import_useLocalStorage.getLocalStorageItem)("user", void 0)) {
|
1345
1377
|
defUser = getUserFromIdToken(idToken);
|
1346
1378
|
}
|
1347
|
-
const [user,
|
1348
|
-
const
|
1379
|
+
const [user, setUserRaw] = (0, import_useLocalStorage.UseLocalStorage)("user", defUser);
|
1380
|
+
const setUser = (value2) => {
|
1381
|
+
setUserRaw(value2);
|
1382
|
+
return;
|
1383
|
+
};
|
1384
|
+
const [loading, setLoading] = (0, import_react8.useState)(false);
|
1349
1385
|
const qs = (0, import_dom3.extractQs)({
|
1350
1386
|
search: typeof window === "undefined" ? "" : window.location.search,
|
1351
1387
|
sanatise: false
|
@@ -1360,8 +1396,7 @@ var CognitoAuthProvider = ({
|
|
1360
1396
|
yield goToPageUrl({ url: location.origin, login: false });
|
1361
1397
|
setLoading(false);
|
1362
1398
|
});
|
1363
|
-
|
1364
|
-
(0, import_react7.useEffect)(() => {
|
1399
|
+
(0, import_react8.useEffect)(() => {
|
1365
1400
|
var _a2;
|
1366
1401
|
const newT = (_a2 = user == null ? void 0 : user.jwt) == null ? void 0 : _a2.id_token;
|
1367
1402
|
if (!!newT && newT !== idToken) {
|
@@ -1387,29 +1422,33 @@ var CognitoAuthProvider = ({
|
|
1387
1422
|
login: true
|
1388
1423
|
});
|
1389
1424
|
});
|
1390
|
-
(
|
1425
|
+
useGranularEffect(() => {
|
1391
1426
|
function run() {
|
1392
1427
|
return __async(this, null, function* () {
|
1393
|
-
var _a2, _b2, _c;
|
1428
|
+
var _a2, _b2, _c, _d;
|
1394
1429
|
const hasQs = !!(qs == null ? void 0 : qs.code) || !!(qs == null ? void 0 : qs.error);
|
1395
1430
|
const expired = jwtExpired(user == null ? void 0 : user.jwt);
|
1396
1431
|
const onlyJwt = !(user == null ? void 0 : user.userId) && !!(user == null ? void 0 : user.jwt);
|
1397
|
-
if (
|
1432
|
+
if (loading || error2 || ((_a2 = user == null ? void 0 : user.idJwt) == null ? void 0 : _a2.email) && !hasQs && !expired) {
|
1398
1433
|
return;
|
1399
1434
|
}
|
1400
1435
|
try {
|
1401
1436
|
setLoading(true);
|
1402
|
-
if (
|
1403
|
-
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
1409
|
-
|
1410
|
-
|
1411
|
-
|
1412
|
-
|
1437
|
+
if (qs == null ? void 0 : qs.error) {
|
1438
|
+
const newerror = {
|
1439
|
+
message: (qs == null ? void 0 : qs.error_description) || "auth error"
|
1440
|
+
};
|
1441
|
+
if (JSON.stringify(newerror || {}) !== JSON.stringify(error2 || {})) {
|
1442
|
+
setError(newerror);
|
1443
|
+
}
|
1444
|
+
return;
|
1445
|
+
}
|
1446
|
+
if ((qs == null ? void 0 : qs.code) && !expired) {
|
1447
|
+
yield goToPageUrl({ url: redirectUrl, login: false });
|
1448
|
+
return;
|
1449
|
+
}
|
1450
|
+
if (qs == null ? void 0 : qs.code) {
|
1451
|
+
if (expired) {
|
1413
1452
|
yield getTokensFromCode({
|
1414
1453
|
code: qs.code,
|
1415
1454
|
redirectUrl,
|
@@ -1417,31 +1456,24 @@ var CognitoAuthProvider = ({
|
|
1417
1456
|
setUser
|
1418
1457
|
});
|
1419
1458
|
}
|
1420
|
-
|
1421
|
-
|
1422
|
-
|
1423
|
-
|
1424
|
-
|
1425
|
-
|
1426
|
-
|
1427
|
-
url += "&";
|
1428
|
-
}
|
1429
|
-
url += `state=${qs.state}`;
|
1430
|
-
} catch (e) {
|
1431
|
-
(0, import_log9.warn)("bad state passed in");
|
1432
|
-
}
|
1433
|
-
}
|
1434
|
-
yield goToPageUrl({ url, login: true });
|
1435
|
-
} else if (expired && ((_a2 = user == null ? void 0 : user.jwt) == null ? void 0 : _a2.refresh_token)) {
|
1459
|
+
yield goToPageUrl({
|
1460
|
+
url: getStatefulUrl({ redirectUrl, qs }),
|
1461
|
+
login: false
|
1462
|
+
});
|
1463
|
+
return;
|
1464
|
+
}
|
1465
|
+
if (expired && ((_b2 = user == null ? void 0 : user.jwt) == null ? void 0 : _b2.refresh_token)) {
|
1436
1466
|
yield refreshToken({
|
1437
1467
|
setUser,
|
1438
1468
|
setError,
|
1439
1469
|
user,
|
1440
1470
|
config,
|
1441
|
-
logout
|
1471
|
+
logout
|
1442
1472
|
});
|
1443
|
-
|
1444
|
-
|
1473
|
+
return;
|
1474
|
+
}
|
1475
|
+
if (onlyJwt) {
|
1476
|
+
const token = (_d = (_c = user == null ? void 0 : user.jwt) == null ? void 0 : _c.id_token) == null ? void 0 : _d.substr(user.jwt.id_token.indexOf(" ") + 1);
|
1445
1477
|
if (!user || !token) {
|
1446
1478
|
(0, import_log9.info)("logging out no token");
|
1447
1479
|
setUser(void 0);
|
@@ -1458,21 +1490,19 @@ var CognitoAuthProvider = ({
|
|
1458
1490
|
}
|
1459
1491
|
});
|
1460
1492
|
}
|
1461
|
-
|
1462
|
-
|
1463
|
-
}
|
1464
|
-
}, [
|
1493
|
+
void run();
|
1494
|
+
}, [user == null ? void 0 : user.jwt, qs], [
|
1465
1495
|
config,
|
1466
1496
|
error2,
|
1467
1497
|
goToPageUrl,
|
1468
|
-
|
1498
|
+
logout,
|
1469
1499
|
loading,
|
1470
1500
|
qs,
|
1471
1501
|
redirectUrl,
|
1472
1502
|
setUser,
|
1473
1503
|
user
|
1474
1504
|
]);
|
1475
|
-
(0,
|
1505
|
+
(0, import_react8.useEffect)(() => {
|
1476
1506
|
var _a2;
|
1477
1507
|
if (error2) {
|
1478
1508
|
(0, import_log9.error)(JSON.stringify(error2));
|
@@ -1497,7 +1527,7 @@ var CognitoAuthProvider = ({
|
|
1497
1527
|
error: error2,
|
1498
1528
|
user
|
1499
1529
|
};
|
1500
|
-
return /* @__PURE__ */
|
1530
|
+
return /* @__PURE__ */ import_react8.default.createElement(CognitoAuthContext.Provider, {
|
1501
1531
|
value
|
1502
1532
|
}, children);
|
1503
1533
|
};
|
@@ -1506,7 +1536,8 @@ var CognitoAuthProvider = ({
|
|
1506
1536
|
var import_log10 = require("ag-common/dist/common/helpers/log");
|
1507
1537
|
var import_string = require("ag-common/dist/common/helpers/string");
|
1508
1538
|
var import_Loader = require("ag-common/dist/ui/components/Loader");
|
1509
|
-
var
|
1539
|
+
var import_useQueryString = require("ag-common/dist/ui/helpers/useQueryString");
|
1540
|
+
var import_react9 = __toESM(require("react"));
|
1510
1541
|
var DashboardAuthValidation = ({
|
1511
1542
|
rc: { request, pushPath },
|
1512
1543
|
cac: {
|
@@ -1520,7 +1551,7 @@ var DashboardAuthValidation = ({
|
|
1520
1551
|
getUnauthedPage,
|
1521
1552
|
addToast
|
1522
1553
|
}) => {
|
1523
|
-
(
|
1554
|
+
useGranularEffect(() => {
|
1524
1555
|
if (authError) {
|
1525
1556
|
const emailOption = authError.message.includes("email") ? ` We require the use of your email for the functionality of this app.
|
1526
1557
|
You can update your settings at https://www.facebook.com/settings?tab=applications` : "";
|
@@ -1530,28 +1561,29 @@ var DashboardAuthValidation = ({
|
|
1530
1561
|
(0, import_log10.error)(`auth error:`, JSON.stringify(authError, null, 2));
|
1531
1562
|
void logout();
|
1532
1563
|
}
|
1533
|
-
}, [authError]);
|
1564
|
+
}, [authError], [authError, addToast, logout]);
|
1534
1565
|
const forceLogin = Object.keys(request.url.query || {}).includes("login");
|
1535
1566
|
if (forceLogin) {
|
1536
1567
|
if (!isAuthenticated) {
|
1537
1568
|
void loginWithRedirect(request.url.query.state);
|
1538
|
-
return { render: /* @__PURE__ */
|
1569
|
+
return { render: /* @__PURE__ */ import_react9.default.createElement(import_react9.default.Fragment, null), openApiDisabled: true };
|
1539
1570
|
}
|
1540
1571
|
if (isAuthenticated) {
|
1541
1572
|
void pushPath(getDashboardPath());
|
1542
|
-
return { render: /* @__PURE__ */
|
1573
|
+
return { render: /* @__PURE__ */ import_react9.default.createElement(import_react9.default.Fragment, null), openApiDisabled: true };
|
1543
1574
|
}
|
1544
1575
|
}
|
1545
1576
|
if (request.url.query.state && isAuthenticated) {
|
1546
1577
|
const decoded = JSON.parse((0, import_string.fromBase64)(request.url.query.state));
|
1547
1578
|
if (decoded.redirect) {
|
1548
1579
|
void pushPath(decoded.redirect);
|
1549
|
-
return { render: /* @__PURE__ */
|
1580
|
+
return { render: /* @__PURE__ */ import_react9.default.createElement(import_react9.default.Fragment, null), openApiDisabled: true };
|
1550
1581
|
}
|
1551
1582
|
}
|
1552
|
-
|
1583
|
+
const serverAuthLoading = import_useQueryString.isServer && !authError && !authLoading && !isAuthenticated && Object.keys(request.url.query || {}).includes("code");
|
1584
|
+
if (authLoading || serverAuthLoading) {
|
1553
1585
|
return {
|
1554
|
-
render: /* @__PURE__ */
|
1586
|
+
render: /* @__PURE__ */ import_react9.default.createElement(import_Loader.Loader, {
|
1555
1587
|
name: "authload"
|
1556
1588
|
}),
|
1557
1589
|
openApiDisabled: true
|
@@ -1559,7 +1591,7 @@ var DashboardAuthValidation = ({
|
|
1559
1591
|
}
|
1560
1592
|
if (!isAuthenticated && !authLoading && !authError && getUnauthedPage) {
|
1561
1593
|
void pushPath(getUnauthedPage());
|
1562
|
-
return { render: /* @__PURE__ */
|
1594
|
+
return { render: /* @__PURE__ */ import_react9.default.createElement(import_react9.default.Fragment, null), openApiDisabled: true };
|
1563
1595
|
}
|
1564
1596
|
const openApiDisabled = !isAuthenticated || authLoading || !!authError;
|
1565
1597
|
return { openApiDisabled };
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "analytica.click",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.239",
|
4
4
|
"description": "",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"typings": "dist/index.d.ts",
|
@@ -9,7 +9,7 @@
|
|
9
9
|
"scripts": {
|
10
10
|
"format": "npx eslint --ext .ts,.tsx ./src --fix",
|
11
11
|
"lint": "tsc && npx eslint --ext .ts,.tsx ./src",
|
12
|
-
"build-direct": "cross-env NODE_ENV=prod ts-node esbuild",
|
12
|
+
"build-direct": "rimraf .build && rimraf dist && cross-env NODE_ENV=prod ts-node esbuild",
|
13
13
|
"build": "yarn lint && yarn build-direct",
|
14
14
|
"start": "cross-env NODE_ENV=dev nodemon -e ts,tsx -w ./src --exec 'ts-node esbuild'"
|
15
15
|
},
|
@@ -30,6 +30,7 @@
|
|
30
30
|
"nodemon": "2.x",
|
31
31
|
"react": "18.x",
|
32
32
|
"react-dom": "18.x",
|
33
|
+
"rimraf": "3.x",
|
33
34
|
"styled-components": "5.x",
|
34
35
|
"ts-node": "10.x",
|
35
36
|
"typescript": "4.x"
|