@websolutespa/payload-plugin-bowl 1.7.3 → 1.7.5
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/CHANGELOG.md +12 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +69 -30
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { TreeItemIndex, TreeItem, TreeItemRenderContext, TreeInformation, TreeDa
|
|
|
13
13
|
import { Props as Props$4 } from 'payload/dist/admin/components/views/collections/List/types';
|
|
14
14
|
import { User } from 'payload/dist/auth';
|
|
15
15
|
import { PaginatedDocs } from 'payload/database';
|
|
16
|
+
import { Response, NextFunction } from 'express';
|
|
16
17
|
import { ContextType } from 'payload/dist/admin/components/utilities/DocumentInfo/types';
|
|
17
18
|
import { Props as Props$2 } from 'payload/components/views/Cell';
|
|
18
19
|
import { Props as Props$3 } from 'payload/components/fields/Text';
|
|
@@ -167,7 +168,7 @@ declare function getRouteByItemAndLocale(req: PayloadRequest<any>, item: ICatego
|
|
|
167
168
|
declare function getRouteByCategoryAndLocale(req: PayloadRequest<any>, item: ICategory, localeId: string, slug: string): Promise<IRoute[]>;
|
|
168
169
|
declare const routeGet: Endpoint;
|
|
169
170
|
declare const routePost: Endpoint;
|
|
170
|
-
declare function routePostHandler(request:
|
|
171
|
+
declare function routePostHandler(request: PayloadRequest, response: Response, next: NextFunction): Promise<Response<any, Record<string, any>>>;
|
|
171
172
|
declare function getEachMarketLocale(req: PayloadRequest<any>, callback: (market: IMarket, locale: ILocale, markets: IMarket[], locales: ILocale[]) => void): Promise<void>;
|
|
172
173
|
declare function getPages(req: PayloadRequest<any>): Promise<IMemoryStore<ICategorized>>;
|
|
173
174
|
|
package/dist/index.js
CHANGED
|
@@ -1479,10 +1479,41 @@ var routePost = {
|
|
|
1479
1479
|
method: "post",
|
|
1480
1480
|
handler: routePostHandler
|
|
1481
1481
|
};
|
|
1482
|
+
var trimTerminalSlash = /* @__PURE__ */ __name((path3) => {
|
|
1483
|
+
return path3.replace(/\/+$/, "");
|
|
1484
|
+
}, "trimTerminalSlash");
|
|
1485
|
+
var sanitizeHref = /* @__PURE__ */ __name((url, urlBeforeRedirect) => {
|
|
1486
|
+
if (urlBeforeRedirect) {
|
|
1487
|
+
const sanitizedUrl = new URL(urlBeforeRedirect);
|
|
1488
|
+
sanitizedUrl.protocol = url.protocol;
|
|
1489
|
+
return trimTerminalSlash(sanitizedUrl.href);
|
|
1490
|
+
} else {
|
|
1491
|
+
return trimTerminalSlash(url.href);
|
|
1492
|
+
}
|
|
1493
|
+
}, "sanitizeHref");
|
|
1494
|
+
var sanitizeRedirectFrom = /* @__PURE__ */ __name((path3, url, urlBeforeRedirect) => {
|
|
1495
|
+
path3 = trimTerminalSlash(path3);
|
|
1496
|
+
if (urlBeforeRedirect) {
|
|
1497
|
+
return path3.replace(/^(\^?)((https?:\/\/)+)/, `$1${url.protocol}//`);
|
|
1498
|
+
} else {
|
|
1499
|
+
return path3.replace(/^(\^?)((https?:\/\/)+(\w|\.|:)+)/, `$1${url.origin}`);
|
|
1500
|
+
}
|
|
1501
|
+
}, "sanitizeRedirectFrom");
|
|
1502
|
+
var sanitizeRedirectTo = /* @__PURE__ */ __name((path3) => {
|
|
1503
|
+
return path3 ? trimTerminalSlash(path3) : void 0;
|
|
1504
|
+
}, "sanitizeRedirectTo");
|
|
1505
|
+
var sanitizeRedirectUrl = /* @__PURE__ */ __name((path3, url) => {
|
|
1506
|
+
if (path3 != null) {
|
|
1507
|
+
path3 = trimTerminalSlash(path3);
|
|
1508
|
+
return path3.match(/^((https?:\/\/)+)/) ? path3 : `${url.origin}${path3}`;
|
|
1509
|
+
} else {
|
|
1510
|
+
return path3;
|
|
1511
|
+
}
|
|
1512
|
+
}, "sanitizeRedirectUrl");
|
|
1482
1513
|
async function routePostHandler(request, response, next) {
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1514
|
+
try {
|
|
1515
|
+
const { pathname, href, hrefBeforeRedirect } = request.body;
|
|
1516
|
+
if (pathname && href) {
|
|
1486
1517
|
const routes = await getRoutes(request);
|
|
1487
1518
|
const route = routes.find((x) => x.id === pathname);
|
|
1488
1519
|
if (route !== void 0) {
|
|
@@ -1500,17 +1531,9 @@ async function routePostHandler(request, response, next) {
|
|
|
1500
1531
|
if (splatRoute) {
|
|
1501
1532
|
return response.status(200).json(splatRoute);
|
|
1502
1533
|
}
|
|
1503
|
-
const
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
const redirectUrl = redirect.to;
|
|
1507
|
-
return response.status(status).send({
|
|
1508
|
-
redirectUrl
|
|
1509
|
-
});
|
|
1510
|
-
} else {
|
|
1511
|
-
return response.status(status).send("gone");
|
|
1512
|
-
}
|
|
1513
|
-
}, "exactMatchResolver");
|
|
1534
|
+
const url = new URL(href);
|
|
1535
|
+
const urlBeforeRedirect = hrefBeforeRedirect ? new URL(hrefBeforeRedirect) : null;
|
|
1536
|
+
const sanitizedHref = sanitizeHref(url, urlBeforeRedirect);
|
|
1514
1537
|
const { payload } = request;
|
|
1515
1538
|
const payloadResponse = await payload.find({
|
|
1516
1539
|
collection: options.slug.redirect,
|
|
@@ -1523,10 +1546,26 @@ async function routePostHandler(request, response, next) {
|
|
|
1523
1546
|
depth: 0,
|
|
1524
1547
|
limit: 1e4,
|
|
1525
1548
|
pagination: false,
|
|
1526
|
-
request
|
|
1549
|
+
req: request
|
|
1527
1550
|
});
|
|
1528
|
-
|
|
1529
|
-
|
|
1551
|
+
let redirects = payloadResponse.docs ? payloadResponse.docs : [];
|
|
1552
|
+
redirects = redirects.map((x) => ({
|
|
1553
|
+
...x,
|
|
1554
|
+
from: sanitizeRedirectFrom(x.from, url, urlBeforeRedirect),
|
|
1555
|
+
to: sanitizeRedirectTo(x.to)
|
|
1556
|
+
}));
|
|
1557
|
+
const exactMatchResolver = /* @__PURE__ */ __name((redirect) => {
|
|
1558
|
+
const status = parseInt(redirect.status) || 307;
|
|
1559
|
+
if (status < 400) {
|
|
1560
|
+
const redirectUrl = sanitizeRedirectUrl(redirect.to, url);
|
|
1561
|
+
return response.status(status).send({
|
|
1562
|
+
redirectUrl
|
|
1563
|
+
});
|
|
1564
|
+
} else {
|
|
1565
|
+
return response.status(status).send("gone");
|
|
1566
|
+
}
|
|
1567
|
+
}, "exactMatchResolver");
|
|
1568
|
+
const exactMatchRedirect = redirects.find((x) => x.from === sanitizedHref);
|
|
1530
1569
|
if (exactMatchRedirect !== void 0) {
|
|
1531
1570
|
return exactMatchResolver(exactMatchRedirect);
|
|
1532
1571
|
}
|
|
@@ -1538,7 +1577,7 @@ async function routePostHandler(request, response, next) {
|
|
|
1538
1577
|
let redirectUrl = redirect.to.replace(/\*/g, (...rest) => {
|
|
1539
1578
|
return `$${++i}`;
|
|
1540
1579
|
});
|
|
1541
|
-
redirectUrl =
|
|
1580
|
+
redirectUrl = sanitizedHref.replace(regexp, redirectUrl);
|
|
1542
1581
|
return response.status(status).send({
|
|
1543
1582
|
redirectUrl
|
|
1544
1583
|
});
|
|
@@ -1552,22 +1591,22 @@ async function routePostHandler(request, response, next) {
|
|
|
1552
1591
|
expression = `^${expression.replace(/(^\^)|(\$$)/g, "")}$`;
|
|
1553
1592
|
x.from = expression;
|
|
1554
1593
|
});
|
|
1555
|
-
const firstMatch = redirects.find((x) =>
|
|
1594
|
+
const firstMatch = redirects.find((x) => sanitizedHref.match(x.from));
|
|
1556
1595
|
if (firstMatch) {
|
|
1557
1596
|
return patternMatchResolver(firstMatch);
|
|
1558
1597
|
}
|
|
1559
1598
|
return response.status(404).send("not found");
|
|
1560
1599
|
}
|
|
1561
|
-
}
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1600
|
+
} else {
|
|
1601
|
+
return response.status(400).send("bad request");
|
|
1602
|
+
}
|
|
1603
|
+
} catch (error) {
|
|
1604
|
+
if (error.status === 404) {
|
|
1605
|
+
return response.status(404).send("not found");
|
|
1606
|
+
} else {
|
|
1607
|
+
console.error("storeHandler.error.500", error);
|
|
1608
|
+
throw error;
|
|
1568
1609
|
}
|
|
1569
|
-
} else {
|
|
1570
|
-
return response.status(400).send("bad request");
|
|
1571
1610
|
}
|
|
1572
1611
|
}
|
|
1573
1612
|
__name(routePostHandler, "routePostHandler");
|
|
@@ -4368,12 +4407,12 @@ var Label = /* @__PURE__ */ __name((options2) => ({
|
|
|
4368
4407
|
admin: {
|
|
4369
4408
|
group: options2.group.config,
|
|
4370
4409
|
useAsTitle: "id",
|
|
4371
|
-
defaultColumns: ["id", "
|
|
4410
|
+
defaultColumns: ["id", "text"]
|
|
4372
4411
|
},
|
|
4373
4412
|
fields: [
|
|
4374
4413
|
// inherited fields: id, createdAt, updatedAt
|
|
4375
4414
|
{ type: "withId", required: true },
|
|
4376
|
-
{ type: "
|
|
4415
|
+
{ type: "withText", required: true, localized: true }
|
|
4377
4416
|
]
|
|
4378
4417
|
}), "Label");
|
|
4379
4418
|
|