@bluemarble/bm-components 2.2.0 → 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 +44 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -9
- package/dist/index.d.ts +19 -9
- package/dist/index.js +32 -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 {};
|
|
@@ -4872,7 +4881,7 @@ function decodeSessionToken({
|
|
|
4872
4881
|
sessionTokenName,
|
|
4873
4882
|
validate
|
|
4874
4883
|
}) {
|
|
4875
|
-
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];
|
|
4876
4885
|
if (!token) {
|
|
4877
4886
|
res.status(401).json({ error: "Token inv\xE1lido", code: "token.invalid" });
|
|
4878
4887
|
return true;
|
|
@@ -5067,7 +5076,7 @@ var AuthHelper = class {
|
|
|
5067
5076
|
const data = await response.json();
|
|
5068
5077
|
const decodedToken = _jsonwebtoken2.default.decode(data.access_token);
|
|
5069
5078
|
const email = decodedToken.upn;
|
|
5070
|
-
const fullName = `${_optionalChain([decodedToken, 'optionalAccess',
|
|
5079
|
+
const fullName = `${_optionalChain([decodedToken, 'optionalAccess', _100 => _100.given_name])} ${_optionalChain([decodedToken, 'optionalAccess', _101 => _101.family_name])}`;
|
|
5071
5080
|
return { decodedToken, email, fullName };
|
|
5072
5081
|
}
|
|
5073
5082
|
createOauthCallbackGetServerSideProps({
|
|
@@ -5151,7 +5160,7 @@ function useFilter(props = { defaultFilters: [] }) {
|
|
|
5151
5160
|
return defaultFilters || [];
|
|
5152
5161
|
});
|
|
5153
5162
|
const filterBy = _react.useCallback.call(void 0, (newFilter) => {
|
|
5154
|
-
const propToCompare = _optionalChain([newFilter, 'optionalAccess',
|
|
5163
|
+
const propToCompare = _optionalChain([newFilter, 'optionalAccess', _102 => _102.id]) ? "id" : "prop";
|
|
5155
5164
|
function removeRepeatedFilters(filter) {
|
|
5156
5165
|
return filter[propToCompare] !== newFilter[propToCompare];
|
|
5157
5166
|
}
|
|
@@ -5504,7 +5513,7 @@ function useAsyncGrid({
|
|
|
5504
5513
|
const params = new URLSearchParams({
|
|
5505
5514
|
page: String(page),
|
|
5506
5515
|
rowsPerPage: String(rowsPerPage2),
|
|
5507
|
-
searchText: _optionalChain([search2, 'optionalAccess',
|
|
5516
|
+
searchText: _optionalChain([search2, 'optionalAccess', _103 => _103.value]) || "",
|
|
5508
5517
|
sort: sortedBy2.map(({ prop, direction }) => `${prop}:${direction}`).join(","),
|
|
5509
5518
|
filters: filters2.map(
|
|
5510
5519
|
(filter) => `${filter.prop}:${filter.compareType}:${filter.value}`
|
|
@@ -5640,7 +5649,7 @@ function CreateAuthProvider({
|
|
|
5640
5649
|
setStatus("autenticated");
|
|
5641
5650
|
return true;
|
|
5642
5651
|
} catch (error) {
|
|
5643
|
-
createAlert(_optionalChain([error, 'optionalAccess',
|
|
5652
|
+
createAlert(_optionalChain([error, 'optionalAccess', _104 => _104.response, 'optionalAccess', _105 => _105.data, 'optionalAccess', _106 => _106.error]), "error");
|
|
5644
5653
|
setStatus("unauthenticated");
|
|
5645
5654
|
throw error;
|
|
5646
5655
|
}
|