@bluemarble/bm-components 2.1.4 → 2.3.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/dist/index.cjs +57 -36
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +65 -10
- package/dist/index.d.ts +65 -10
- package/dist/index.js +44 -23
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -4501,55 +4501,62 @@ var VALID_METHODS = [
|
|
|
4501
4501
|
"PATCH"
|
|
4502
4502
|
];
|
|
4503
4503
|
var _ApiHelper = class _ApiHelper {
|
|
4504
|
-
async onFinally(
|
|
4504
|
+
async onFinally(_req, _res) {
|
|
4505
4505
|
}
|
|
4506
|
-
async onError(
|
|
4506
|
+
async onError(_req, _res, _error) {
|
|
4507
4507
|
}
|
|
4508
4508
|
constructor(props) {
|
|
4509
|
-
this.
|
|
4510
|
-
this.
|
|
4509
|
+
this.public = _nullishCoalesce(_optionalChain([props, 'optionalAccess', _83 => _83.public]), () => ( false));
|
|
4510
|
+
this.middlewares = (_optionalChain([props, 'optionalAccess', _84 => _84.middlewares]) || []).reverse();
|
|
4511
|
+
this.onFinally = _optionalChain([props, 'optionalAccess', _85 => _85.onFinally]) || (async () => {
|
|
4511
4512
|
});
|
|
4512
|
-
this.onError = _optionalChain([props, 'optionalAccess',
|
|
4513
|
+
this.onError = _optionalChain([props, 'optionalAccess', _86 => _86.onError]) || (async () => {
|
|
4513
4514
|
});
|
|
4514
4515
|
}
|
|
4515
|
-
setMiddlewares(middlewares) {
|
|
4516
|
-
this.middlewares = middlewares.reverse();
|
|
4517
|
-
return this;
|
|
4518
|
-
}
|
|
4519
4516
|
createMethods(methods) {
|
|
4520
4517
|
return async (req, res) => {
|
|
4521
4518
|
const currentMethod = methods[req.method] || methods.ALL;
|
|
4519
|
+
const options = { public: this.public };
|
|
4522
4520
|
if (req.method === "OPTIONS") return res.status(200).end();
|
|
4523
4521
|
try {
|
|
4524
4522
|
if (!VALID_METHODS.includes(req.method))
|
|
4525
4523
|
throw new HttpError(405, "M\xE9todo inv\xE1lido");
|
|
4526
4524
|
if (!currentMethod) throw new HttpError(500, "M\xE9todo n\xE3o encontrado");
|
|
4527
4525
|
const methodWithMiddlewares = this.middlewares.reduce(
|
|
4528
|
-
(acc, fn) => fn(acc),
|
|
4526
|
+
(acc, fn) => fn(acc, options),
|
|
4529
4527
|
currentMethod
|
|
4530
4528
|
);
|
|
4531
|
-
await methodWithMiddlewares(req, res);
|
|
4529
|
+
return await methodWithMiddlewares(req, res, options);
|
|
4532
4530
|
} catch (error) {
|
|
4533
|
-
if (error instanceof DomainError)
|
|
4534
|
-
|
|
4535
|
-
if (error instanceof HttpError)
|
|
4536
|
-
return res.status(error.status).json(error.message);
|
|
4537
|
-
if (process.env.NODE_ENV === "production") {
|
|
4538
|
-
res.status(500).json({
|
|
4539
|
-
code: "internal.error",
|
|
4540
|
-
error: "Erro interno do servidor",
|
|
4541
|
-
details: error
|
|
4542
|
-
});
|
|
4543
|
-
return this.onError(req, res, error);
|
|
4544
|
-
}
|
|
4531
|
+
if (error instanceof DomainError) return res.status(400).json(error.message);
|
|
4532
|
+
if (error instanceof HttpError) return res.status(error.status).json(error.message);
|
|
4545
4533
|
this.onError(req, res, error);
|
|
4546
|
-
throw
|
|
4534
|
+
throw error;
|
|
4547
4535
|
} finally {
|
|
4548
4536
|
await this.onFinally(req, res);
|
|
4549
4537
|
}
|
|
4550
4538
|
};
|
|
4551
4539
|
}
|
|
4552
|
-
|
|
4540
|
+
buildFactory(factory) {
|
|
4541
|
+
const options = {
|
|
4542
|
+
public: this.public
|
|
4543
|
+
};
|
|
4544
|
+
return async (req, res) => {
|
|
4545
|
+
const methods = factory(req, res);
|
|
4546
|
+
const handler = methods[req.method];
|
|
4547
|
+
const methodWithMiddlewares = this.middlewares.reduce((acc, fn) => {
|
|
4548
|
+
return fn(acc, options);
|
|
4549
|
+
}, handler);
|
|
4550
|
+
return await methodWithMiddlewares(req, res, options);
|
|
4551
|
+
};
|
|
4552
|
+
}
|
|
4553
|
+
static build(factory, options) {
|
|
4554
|
+
const helper = new _ApiHelper({
|
|
4555
|
+
...options
|
|
4556
|
+
}).buildFactory(factory);
|
|
4557
|
+
return helper;
|
|
4558
|
+
}
|
|
4559
|
+
static parser(body, parser) {
|
|
4553
4560
|
try {
|
|
4554
4561
|
const object = parser.parse(body);
|
|
4555
4562
|
return object;
|
|
@@ -4561,13 +4568,15 @@ var _ApiHelper = class _ApiHelper {
|
|
|
4561
4568
|
});
|
|
4562
4569
|
}
|
|
4563
4570
|
}
|
|
4571
|
+
/** @deprecated Use {@Link ApiHelper.build} instead. */
|
|
4564
4572
|
static create({ onFinally }) {
|
|
4565
4573
|
return new _ApiHelper({
|
|
4566
4574
|
onFinally
|
|
4567
4575
|
});
|
|
4568
4576
|
}
|
|
4569
4577
|
};
|
|
4570
|
-
|
|
4578
|
+
/** @deprecated Use {@link ApiHelper.parser} instead. */
|
|
4579
|
+
_ApiHelper.parserErrorWrapper = _ApiHelper.parser;
|
|
4571
4580
|
var ApiHelper = _ApiHelper;
|
|
4572
4581
|
|
|
4573
4582
|
// src/hooks/useFormHelper.ts
|
|
@@ -4723,7 +4732,7 @@ function useFormHelper() {
|
|
|
4723
4732
|
);
|
|
4724
4733
|
const errorHandler = _react.useCallback.call(void 0,
|
|
4725
4734
|
(error, callback) => {
|
|
4726
|
-
if (_optionalChain([error, 'optionalAccess',
|
|
4735
|
+
if (_optionalChain([error, 'optionalAccess', _87 => _87.message]) === "cancel.navigation") return;
|
|
4727
4736
|
if (callback) {
|
|
4728
4737
|
if (error.response.data.code === "invalid.body") {
|
|
4729
4738
|
const errors = error.response.data.details.issues;
|
|
@@ -4808,7 +4817,7 @@ function areCookiesEqual(a, b) {
|
|
|
4808
4817
|
|
|
4809
4818
|
// packages/nookies/index.ts
|
|
4810
4819
|
function parseCookies(ctx, options) {
|
|
4811
|
-
if (_optionalChain([ctx, 'optionalAccess',
|
|
4820
|
+
if (_optionalChain([ctx, 'optionalAccess', _88 => _88.req, 'optionalAccess', _89 => _89.headers, 'optionalAccess', _90 => _90.cookie])) {
|
|
4812
4821
|
return cookie.parse(ctx.req.headers.cookie, options);
|
|
4813
4822
|
}
|
|
4814
4823
|
if (isBrowser()) {
|
|
@@ -4817,8 +4826,8 @@ function parseCookies(ctx, options) {
|
|
|
4817
4826
|
return {};
|
|
4818
4827
|
}
|
|
4819
4828
|
function setCookie(ctx, name, value, options = {}) {
|
|
4820
|
-
if (_optionalChain([ctx, 'optionalAccess',
|
|
4821
|
-
if (_optionalChain([ctx, 'optionalAccess',
|
|
4829
|
+
if (_optionalChain([ctx, 'optionalAccess', _91 => _91.res, 'optionalAccess', _92 => _92.getHeader]) && ctx.res.setHeader) {
|
|
4830
|
+
if (_optionalChain([ctx, 'optionalAccess', _93 => _93.res, 'optionalAccess', _94 => _94.finished])) {
|
|
4822
4831
|
console.warn(`Not setting "${name}" cookie. Response has finished.`);
|
|
4823
4832
|
console.warn(`You should set cookie before res.send()`);
|
|
4824
4833
|
return {};
|
|
@@ -4856,6 +4865,14 @@ function setCookie(ctx, name, value, options = {}) {
|
|
|
4856
4865
|
}
|
|
4857
4866
|
return {};
|
|
4858
4867
|
}
|
|
4868
|
+
function destroyCookie(ctx, name, options) {
|
|
4869
|
+
return setCookie(ctx, name, "", { ...options || {}, maxAge: -1 });
|
|
4870
|
+
}
|
|
4871
|
+
var nookies = {
|
|
4872
|
+
set: setCookie,
|
|
4873
|
+
get: parseCookies,
|
|
4874
|
+
destroy: destroyCookie
|
|
4875
|
+
};
|
|
4859
4876
|
|
|
4860
4877
|
// src/helpers/authHelper.ts
|
|
4861
4878
|
function decodeSessionToken({
|
|
@@ -4864,7 +4881,7 @@ function decodeSessionToken({
|
|
|
4864
4881
|
sessionTokenName,
|
|
4865
4882
|
validate
|
|
4866
4883
|
}) {
|
|
4867
|
-
const token = _optionalChain([req, 'access',
|
|
4884
|
+
const token = _optionalChain([req, 'access', _95 => _95.headers, 'access', _96 => _96.authorization, 'optionalAccess', _97 => _97.split, 'call', _98 => _98(" "), 'access', _99 => _99[1]]) || req.cookies[sessionTokenName];
|
|
4868
4885
|
if (!token) {
|
|
4869
4886
|
res.status(401).json({ error: "Token inv\xE1lido", code: "token.invalid" });
|
|
4870
4887
|
return true;
|
|
@@ -5059,7 +5076,7 @@ var AuthHelper = class {
|
|
|
5059
5076
|
const data = await response.json();
|
|
5060
5077
|
const decodedToken = _jsonwebtoken2.default.decode(data.access_token);
|
|
5061
5078
|
const email = decodedToken.upn;
|
|
5062
|
-
const fullName = `${_optionalChain([decodedToken, 'optionalAccess',
|
|
5079
|
+
const fullName = `${_optionalChain([decodedToken, 'optionalAccess', _100 => _100.given_name])} ${_optionalChain([decodedToken, 'optionalAccess', _101 => _101.family_name])}`;
|
|
5063
5080
|
return { decodedToken, email, fullName };
|
|
5064
5081
|
}
|
|
5065
5082
|
createOauthCallbackGetServerSideProps({
|
|
@@ -5143,7 +5160,7 @@ function useFilter(props = { defaultFilters: [] }) {
|
|
|
5143
5160
|
return defaultFilters || [];
|
|
5144
5161
|
});
|
|
5145
5162
|
const filterBy = _react.useCallback.call(void 0, (newFilter) => {
|
|
5146
|
-
const propToCompare = _optionalChain([newFilter, 'optionalAccess',
|
|
5163
|
+
const propToCompare = _optionalChain([newFilter, 'optionalAccess', _102 => _102.id]) ? "id" : "prop";
|
|
5147
5164
|
function removeRepeatedFilters(filter) {
|
|
5148
5165
|
return filter[propToCompare] !== newFilter[propToCompare];
|
|
5149
5166
|
}
|
|
@@ -5496,7 +5513,7 @@ function useAsyncGrid({
|
|
|
5496
5513
|
const params = new URLSearchParams({
|
|
5497
5514
|
page: String(page),
|
|
5498
5515
|
rowsPerPage: String(rowsPerPage2),
|
|
5499
|
-
searchText: _optionalChain([search2, 'optionalAccess',
|
|
5516
|
+
searchText: _optionalChain([search2, 'optionalAccess', _103 => _103.value]) || "",
|
|
5500
5517
|
sort: sortedBy2.map(({ prop, direction }) => `${prop}:${direction}`).join(","),
|
|
5501
5518
|
filters: filters2.map(
|
|
5502
5519
|
(filter) => `${filter.prop}:${filter.compareType}:${filter.value}`
|
|
@@ -5632,7 +5649,7 @@ function CreateAuthProvider({
|
|
|
5632
5649
|
setStatus("autenticated");
|
|
5633
5650
|
return true;
|
|
5634
5651
|
} catch (error) {
|
|
5635
|
-
createAlert(_optionalChain([error, 'optionalAccess',
|
|
5652
|
+
createAlert(_optionalChain([error, 'optionalAccess', _104 => _104.response, 'optionalAccess', _105 => _105.data, 'optionalAccess', _106 => _106.error]), "error");
|
|
5636
5653
|
setStatus("unauthenticated");
|
|
5637
5654
|
throw error;
|
|
5638
5655
|
}
|
|
@@ -5716,7 +5733,11 @@ function CreateAuthProvider({
|
|
|
5716
5733
|
|
|
5717
5734
|
|
|
5718
5735
|
|
|
5719
|
-
|
|
5736
|
+
|
|
5737
|
+
|
|
5738
|
+
|
|
5739
|
+
|
|
5740
|
+
exports.AlertContext = AlertContext; exports.AlertProvider = AlertProvider; exports.ApiHelper = ApiHelper; exports.AuthHelper = AuthHelper; exports.Autocomplete = Autocomplete2; exports.BaseDialog = BaseDialog; exports.BaseDialogBody = BaseDialogBody; exports.BaseDialogContainer = BaseDialogContainer; exports.BaseDialogCreate = BaseDialogCreate; exports.BaseDialogTrigger = BaseDialogTrigger; exports.BaseGrid = BaseGrid; exports.BaseGridAutoRows = BaseGridAutoRows; exports.Checkbox = Checkbox; exports.CreateAuthProvider = CreateAuthProvider; exports.Dialog = Dialog; exports.DialogConfirm = DialogConfirm; exports.DomainError = DomainError; exports.EditableTableCell = EditableTableCell; exports.FormHelperContext = FormHelperContext; exports.FormHelperProvider = FormHelperProvider; exports.GetInputLabel = GetInputLabel; exports.Grid = Grid_default; exports.HttpError = HttpError; exports.Input = Input; exports.InputMask = InputMask2; exports.LargeButton = LargeButton; exports.Modal = Modal; exports.Radio = Radio; exports.Select = Select; exports.Switch = Switch; exports.TabPanel = TabPanel; exports.Td = Td; exports.Tr = Tr; exports.UseDialogConfirm = UseDialogConfirm; exports.createAuthContext = createAuthContext; exports.createFilter = createFilter; exports.destroyCookie = destroyCookie; exports.filterData = filterData; exports.getTabProps = getTabProps; exports.nookies = nookies; exports.parseCookies = parseCookies; exports.setCookie = setCookie; exports.useAlert = useAlert; exports.useAsyncGrid = useAsyncGrid; exports.useBaseDialog = useBaseDialog; exports.useBaseDialogInstance = useBaseDialogInstance; exports.useEvent = useEvent; exports.useFilter = useFilter; exports.useFormHelper = useFormHelper; exports.useGrid = useGrid; exports.useLoading = useLoading;
|
|
5720
5741
|
/*! Bundled license information:
|
|
5721
5742
|
|
|
5722
5743
|
react-is/cjs/react-is.production.min.js:
|