@bluemarble/bm-components 2.1.2 → 2.1.4
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.cjs +137 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +127 -9
- package/dist/index.js.map +1 -1
- package/package.json +8 -7
package/dist/index.cjs
CHANGED
|
@@ -4305,7 +4305,7 @@ var DialogConfirm = (props) => {
|
|
|
4305
4305
|
onClick: model.onCancel,
|
|
4306
4306
|
color: "inherit"
|
|
4307
4307
|
},
|
|
4308
|
-
props.cancelButtonText || "
|
|
4308
|
+
props.cancelButtonText || "Cancelar"
|
|
4309
4309
|
))))));
|
|
4310
4310
|
};
|
|
4311
4311
|
|
|
@@ -4753,17 +4753,118 @@ function useFormHelper() {
|
|
|
4753
4753
|
}
|
|
4754
4754
|
|
|
4755
4755
|
// src/helpers/authHelper.ts
|
|
4756
|
-
var _cookie = require('cookie');
|
|
4757
|
-
var _nookies = require('nookies');
|
|
4756
|
+
var _cookie = require('cookie'); var cookie = _interopRequireWildcard(_cookie);
|
|
4758
4757
|
var _uuid = require('uuid');
|
|
4759
4758
|
var _jsonwebtoken = require('jsonwebtoken'); var _jsonwebtoken2 = _interopRequireDefault(_jsonwebtoken);
|
|
4759
|
+
|
|
4760
|
+
// packages/nookies/index.ts
|
|
4761
|
+
|
|
4762
|
+
var _setcookieparser = require('set-cookie-parser'); var setCookieParser = _interopRequireWildcard(_setcookieparser);
|
|
4763
|
+
|
|
4764
|
+
// packages/nookies/util.ts
|
|
4765
|
+
function isBrowser() {
|
|
4766
|
+
return typeof window !== "undefined";
|
|
4767
|
+
}
|
|
4768
|
+
function createCookie(name, value, options) {
|
|
4769
|
+
let sameSite = options.sameSite;
|
|
4770
|
+
if (sameSite === true) {
|
|
4771
|
+
sameSite = "strict";
|
|
4772
|
+
}
|
|
4773
|
+
if (sameSite === void 0 || sameSite === false) {
|
|
4774
|
+
sameSite = "lax";
|
|
4775
|
+
}
|
|
4776
|
+
const cookieToSet = { ...options, sameSite };
|
|
4777
|
+
delete cookieToSet.encode;
|
|
4778
|
+
return {
|
|
4779
|
+
name,
|
|
4780
|
+
value,
|
|
4781
|
+
...cookieToSet
|
|
4782
|
+
};
|
|
4783
|
+
}
|
|
4784
|
+
function hasSameProperties(a, b) {
|
|
4785
|
+
const aProps = Object.getOwnPropertyNames(a);
|
|
4786
|
+
const bProps = Object.getOwnPropertyNames(b);
|
|
4787
|
+
if (aProps.length !== bProps.length) {
|
|
4788
|
+
return false;
|
|
4789
|
+
}
|
|
4790
|
+
for (let i = 0; i < aProps.length; i++) {
|
|
4791
|
+
const propName = aProps[i];
|
|
4792
|
+
if (a[propName] !== b[propName]) {
|
|
4793
|
+
return false;
|
|
4794
|
+
}
|
|
4795
|
+
}
|
|
4796
|
+
return true;
|
|
4797
|
+
}
|
|
4798
|
+
function areCookiesEqual(a, b) {
|
|
4799
|
+
let sameSiteSame = a.sameSite === b.sameSite;
|
|
4800
|
+
if (typeof a.sameSite === "string" && typeof b.sameSite === "string") {
|
|
4801
|
+
sameSiteSame = a.sameSite.toLowerCase() === b.sameSite.toLowerCase();
|
|
4802
|
+
}
|
|
4803
|
+
return hasSameProperties(
|
|
4804
|
+
{ ...a, sameSite: void 0 },
|
|
4805
|
+
{ ...b, sameSite: void 0 }
|
|
4806
|
+
) && sameSiteSame;
|
|
4807
|
+
}
|
|
4808
|
+
|
|
4809
|
+
// packages/nookies/index.ts
|
|
4810
|
+
function parseCookies(ctx, options) {
|
|
4811
|
+
if (_optionalChain([ctx, 'optionalAccess', _87 => _87.req, 'optionalAccess', _88 => _88.headers, 'optionalAccess', _89 => _89.cookie])) {
|
|
4812
|
+
return cookie.parse(ctx.req.headers.cookie, options);
|
|
4813
|
+
}
|
|
4814
|
+
if (isBrowser()) {
|
|
4815
|
+
return cookie.parse(document.cookie, options);
|
|
4816
|
+
}
|
|
4817
|
+
return {};
|
|
4818
|
+
}
|
|
4819
|
+
function setCookie(ctx, name, value, options = {}) {
|
|
4820
|
+
if (_optionalChain([ctx, 'optionalAccess', _90 => _90.res, 'optionalAccess', _91 => _91.getHeader]) && ctx.res.setHeader) {
|
|
4821
|
+
if (_optionalChain([ctx, 'optionalAccess', _92 => _92.res, 'optionalAccess', _93 => _93.finished])) {
|
|
4822
|
+
console.warn(`Not setting "${name}" cookie. Response has finished.`);
|
|
4823
|
+
console.warn(`You should set cookie before res.send()`);
|
|
4824
|
+
return {};
|
|
4825
|
+
}
|
|
4826
|
+
let cookies = ctx.res.getHeader("Set-Cookie") || [];
|
|
4827
|
+
if (typeof cookies === "string") cookies = [cookies];
|
|
4828
|
+
if (typeof cookies === "number") cookies = [];
|
|
4829
|
+
const parsedCookies = setCookieParser.parse(cookies, {
|
|
4830
|
+
decodeValues: false
|
|
4831
|
+
});
|
|
4832
|
+
const newCookie = createCookie(name, value, options);
|
|
4833
|
+
let cookiesToSet = [];
|
|
4834
|
+
parsedCookies.forEach((parsedCookie) => {
|
|
4835
|
+
if (!areCookiesEqual(parsedCookie, newCookie)) {
|
|
4836
|
+
const serializedCookie = cookie.serialize(
|
|
4837
|
+
parsedCookie.name,
|
|
4838
|
+
parsedCookie.value,
|
|
4839
|
+
{
|
|
4840
|
+
// we prevent reencoding by default, but you might override it
|
|
4841
|
+
encode: (val) => val,
|
|
4842
|
+
...parsedCookie
|
|
4843
|
+
}
|
|
4844
|
+
);
|
|
4845
|
+
cookiesToSet.push(serializedCookie);
|
|
4846
|
+
}
|
|
4847
|
+
});
|
|
4848
|
+
cookiesToSet.push(cookie.serialize(name, value, options));
|
|
4849
|
+
ctx.res.setHeader("Set-Cookie", cookiesToSet);
|
|
4850
|
+
}
|
|
4851
|
+
if (isBrowser()) {
|
|
4852
|
+
if (options && options.httpOnly) {
|
|
4853
|
+
throw new Error("Can not set a httpOnly cookie in the browser.");
|
|
4854
|
+
}
|
|
4855
|
+
document.cookie = cookie.serialize(name, value, options);
|
|
4856
|
+
}
|
|
4857
|
+
return {};
|
|
4858
|
+
}
|
|
4859
|
+
|
|
4860
|
+
// src/helpers/authHelper.ts
|
|
4760
4861
|
function decodeSessionToken({
|
|
4761
4862
|
req,
|
|
4762
4863
|
res,
|
|
4763
4864
|
sessionTokenName,
|
|
4764
4865
|
validate
|
|
4765
4866
|
}) {
|
|
4766
|
-
const token = _optionalChain([req, 'access',
|
|
4867
|
+
const token = _optionalChain([req, 'access', _94 => _94.headers, 'access', _95 => _95.authorization, 'optionalAccess', _96 => _96.split, 'call', _97 => _97(" "), 'access', _98 => _98[1]]) || req.cookies[sessionTokenName];
|
|
4767
4868
|
if (!token) {
|
|
4768
4869
|
res.status(401).json({ error: "Token inv\xE1lido", code: "token.invalid" });
|
|
4769
4870
|
return true;
|
|
@@ -4836,14 +4937,14 @@ var AuthHelper = class {
|
|
|
4836
4937
|
loginResult.userId,
|
|
4837
4938
|
{}
|
|
4838
4939
|
);
|
|
4839
|
-
|
|
4940
|
+
setCookie({ res }, this.cookies.sessionToken, token, {
|
|
4840
4941
|
secure: true,
|
|
4841
4942
|
maxAge: 60 * 60 * 24 * 30,
|
|
4842
4943
|
// 30 days
|
|
4843
4944
|
path: "/",
|
|
4844
4945
|
sameSite: true
|
|
4845
4946
|
});
|
|
4846
|
-
|
|
4947
|
+
setCookie({ res }, this.cookies.refreshToken, refreshToken, {
|
|
4847
4948
|
secure: true,
|
|
4848
4949
|
maxAge: 60 * 60 * 24 * 30,
|
|
4849
4950
|
// 30 days
|
|
@@ -4867,7 +4968,7 @@ var AuthHelper = class {
|
|
|
4867
4968
|
});
|
|
4868
4969
|
if (error) return;
|
|
4869
4970
|
const userId = String(req.user);
|
|
4870
|
-
const refreshToken =
|
|
4971
|
+
const refreshToken = parseCookies({ req })[this.cookies.refreshToken];
|
|
4871
4972
|
if (!refreshToken) {
|
|
4872
4973
|
this.invalidateCookies(res);
|
|
4873
4974
|
return res.status(400).json({
|
|
@@ -4886,14 +4987,14 @@ var AuthHelper = class {
|
|
|
4886
4987
|
}
|
|
4887
4988
|
await this.onInvalidateRefreshToken(userId, refreshToken);
|
|
4888
4989
|
const { token, refreshToken: newRefreshToken } = await this.generateJwtAndRefreshToken(userId, {});
|
|
4889
|
-
|
|
4990
|
+
setCookie({ res }, this.cookies.sessionToken, token, {
|
|
4890
4991
|
secure: true,
|
|
4891
4992
|
maxAge: 60 * 60 * 24 * 30,
|
|
4892
4993
|
// 30 days
|
|
4893
4994
|
path: "/",
|
|
4894
4995
|
sameSite: true
|
|
4895
4996
|
});
|
|
4896
|
-
|
|
4997
|
+
setCookie({ res }, this.cookies.refreshToken, newRefreshToken, {
|
|
4897
4998
|
secure: true,
|
|
4898
4999
|
maxAge: 60 * 60 * 24 * 30,
|
|
4899
5000
|
// 30 days
|
|
@@ -4958,7 +5059,7 @@ var AuthHelper = class {
|
|
|
4958
5059
|
const data = await response.json();
|
|
4959
5060
|
const decodedToken = _jsonwebtoken2.default.decode(data.access_token);
|
|
4960
5061
|
const email = decodedToken.upn;
|
|
4961
|
-
const fullName = `${_optionalChain([decodedToken, 'optionalAccess',
|
|
5062
|
+
const fullName = `${_optionalChain([decodedToken, 'optionalAccess', _99 => _99.given_name])} ${_optionalChain([decodedToken, 'optionalAccess', _100 => _100.family_name])}`;
|
|
4962
5063
|
return { decodedToken, email, fullName };
|
|
4963
5064
|
}
|
|
4964
5065
|
createOauthCallbackGetServerSideProps({
|
|
@@ -4987,13 +5088,13 @@ var AuthHelper = class {
|
|
|
4987
5088
|
email,
|
|
4988
5089
|
{}
|
|
4989
5090
|
);
|
|
4990
|
-
|
|
5091
|
+
setCookie(ctx, this.cookies.sessionToken, token, {
|
|
4991
5092
|
secure: true,
|
|
4992
5093
|
maxAge: 60 * 60 * 24 * 30,
|
|
4993
5094
|
// 30 days
|
|
4994
5095
|
path: "/"
|
|
4995
5096
|
});
|
|
4996
|
-
|
|
5097
|
+
setCookie(ctx, this.cookies.refreshToken, refreshToken, {
|
|
4997
5098
|
secure: true,
|
|
4998
5099
|
maxAge: 60 * 60 * 24 * 30,
|
|
4999
5100
|
// 30 days
|
|
@@ -5042,7 +5143,7 @@ function useFilter(props = { defaultFilters: [] }) {
|
|
|
5042
5143
|
return defaultFilters || [];
|
|
5043
5144
|
});
|
|
5044
5145
|
const filterBy = _react.useCallback.call(void 0, (newFilter) => {
|
|
5045
|
-
const propToCompare = _optionalChain([newFilter, 'optionalAccess',
|
|
5146
|
+
const propToCompare = _optionalChain([newFilter, 'optionalAccess', _101 => _101.id]) ? "id" : "prop";
|
|
5046
5147
|
function removeRepeatedFilters(filter) {
|
|
5047
5148
|
return filter[propToCompare] !== newFilter[propToCompare];
|
|
5048
5149
|
}
|
|
@@ -5114,8 +5215,26 @@ function createFilter(filters) {
|
|
|
5114
5215
|
};
|
|
5115
5216
|
}
|
|
5116
5217
|
|
|
5218
|
+
// src/helpers/sortHelper.ts
|
|
5219
|
+
function SortHelper(...fields) {
|
|
5220
|
+
return (a, b) => {
|
|
5221
|
+
for (const field of fields) {
|
|
5222
|
+
let direction = 1;
|
|
5223
|
+
let key = field;
|
|
5224
|
+
if (field.startsWith("-")) {
|
|
5225
|
+
direction = -1;
|
|
5226
|
+
key = field.slice(1);
|
|
5227
|
+
}
|
|
5228
|
+
const aVal = a[key];
|
|
5229
|
+
const bVal = b[key];
|
|
5230
|
+
if (aVal > bVal) return direction;
|
|
5231
|
+
if (aVal < bVal) return -direction;
|
|
5232
|
+
}
|
|
5233
|
+
return 0;
|
|
5234
|
+
};
|
|
5235
|
+
}
|
|
5236
|
+
|
|
5117
5237
|
// src/hooks/useGrid.ts
|
|
5118
|
-
var _sortby = require('sort-by'); var _sortby2 = _interopRequireDefault(_sortby);
|
|
5119
5238
|
function useGrid({
|
|
5120
5239
|
columns,
|
|
5121
5240
|
filters,
|
|
@@ -5185,7 +5304,7 @@ function useGrid({
|
|
|
5185
5304
|
const formattedKeys = sortedBy.map(
|
|
5186
5305
|
({ prop, direction }) => `${symbolDir[direction]}${prop}`
|
|
5187
5306
|
);
|
|
5188
|
-
return data.sort(
|
|
5307
|
+
return data.sort(SortHelper(...formattedKeys));
|
|
5189
5308
|
} else return data;
|
|
5190
5309
|
},
|
|
5191
5310
|
[sortedBy]
|
|
@@ -5377,7 +5496,7 @@ function useAsyncGrid({
|
|
|
5377
5496
|
const params = new URLSearchParams({
|
|
5378
5497
|
page: String(page),
|
|
5379
5498
|
rowsPerPage: String(rowsPerPage2),
|
|
5380
|
-
searchText: _optionalChain([search2, 'optionalAccess',
|
|
5499
|
+
searchText: _optionalChain([search2, 'optionalAccess', _102 => _102.value]) || "",
|
|
5381
5500
|
sort: sortedBy2.map(({ prop, direction }) => `${prop}:${direction}`).join(","),
|
|
5382
5501
|
filters: filters2.map(
|
|
5383
5502
|
(filter) => `${filter.prop}:${filter.compareType}:${filter.value}`
|
|
@@ -5486,7 +5605,6 @@ function useEvent(event, handler, passive = false) {
|
|
|
5486
5605
|
|
|
5487
5606
|
|
|
5488
5607
|
|
|
5489
|
-
|
|
5490
5608
|
function createAuthContext() {
|
|
5491
5609
|
return _react.createContext.call(void 0, {});
|
|
5492
5610
|
}
|
|
@@ -5514,7 +5632,7 @@ function CreateAuthProvider({
|
|
|
5514
5632
|
setStatus("autenticated");
|
|
5515
5633
|
return true;
|
|
5516
5634
|
} catch (error) {
|
|
5517
|
-
createAlert(_optionalChain([error, 'optionalAccess',
|
|
5635
|
+
createAlert(_optionalChain([error, 'optionalAccess', _103 => _103.response, 'optionalAccess', _104 => _104.data, 'optionalAccess', _105 => _105.error]), "error");
|
|
5518
5636
|
setStatus("unauthenticated");
|
|
5519
5637
|
throw error;
|
|
5520
5638
|
}
|
|
@@ -5526,7 +5644,7 @@ function CreateAuthProvider({
|
|
|
5526
5644
|
setUser(void 0);
|
|
5527
5645
|
}, [api]);
|
|
5528
5646
|
_react.useEffect.call(void 0, () => {
|
|
5529
|
-
const token =
|
|
5647
|
+
const token = parseCookies()[sessionTokenName];
|
|
5530
5648
|
if (token) {
|
|
5531
5649
|
setStatus("loading");
|
|
5532
5650
|
api.get("/auth/me").then((response) => {
|