@prenta/plugin-redirects 0.1.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/CHANGELOG.md +248 -0
- package/LICENSE +21 -0
- package/README.md +28 -0
- package/dist/__tests__/collections.test.d.ts +2 -0
- package/dist/__tests__/collections.test.d.ts.map +1 -0
- package/dist/__tests__/collections.test.js +43 -0
- package/dist/__tests__/collections.test.js.map +1 -0
- package/dist/__tests__/import.test.d.ts +2 -0
- package/dist/__tests__/import.test.d.ts.map +1 -0
- package/dist/__tests__/import.test.js +99 -0
- package/dist/__tests__/import.test.js.map +1 -0
- package/dist/__tests__/index.test.d.ts +2 -0
- package/dist/__tests__/index.test.d.ts.map +1 -0
- package/dist/__tests__/index.test.js +36 -0
- package/dist/__tests__/index.test.js.map +1 -0
- package/dist/__tests__/middleware.test.d.ts +2 -0
- package/dist/__tests__/middleware.test.d.ts.map +1 -0
- package/dist/__tests__/middleware.test.js +137 -0
- package/dist/__tests__/middleware.test.js.map +1 -0
- package/dist/admin/RedirectList.d.ts +19 -0
- package/dist/admin/RedirectList.d.ts.map +1 -0
- package/dist/admin/RedirectList.js +92 -0
- package/dist/admin/RedirectList.js.map +1 -0
- package/dist/collections.d.ts +3 -0
- package/dist/collections.d.ts.map +1 -0
- package/dist/collections.js +63 -0
- package/dist/collections.js.map +1 -0
- package/dist/fields.d.ts +3 -0
- package/dist/fields.d.ts.map +1 -0
- package/dist/fields.js +2 -0
- package/dist/fields.js.map +1 -0
- package/dist/hooks.d.ts +3 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +12 -0
- package/dist/hooks.js.map +1 -0
- package/dist/import.d.ts +22 -0
- package/dist/import.d.ts.map +1 -0
- package/dist/import.js +81 -0
- package/dist/import.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/middleware.d.ts +27 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js +69 -0
- package/dist/middleware.js.map +1 -0
- package/package.json +47 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
+
import { createRedirectMiddleware } from '../middleware.js';
|
|
3
|
+
function mw(rules, options = {}) {
|
|
4
|
+
return createRedirectMiddleware({ getRedirects: async () => rules, ...options });
|
|
5
|
+
}
|
|
6
|
+
const rule = (over = {}) => ({
|
|
7
|
+
id: '1',
|
|
8
|
+
fromUrl: '/old-page',
|
|
9
|
+
toUrl: '/new-page',
|
|
10
|
+
type: '301',
|
|
11
|
+
isActive: true,
|
|
12
|
+
...over,
|
|
13
|
+
});
|
|
14
|
+
describe('createRedirectMiddleware', () => {
|
|
15
|
+
it('matches a bare path', async () => {
|
|
16
|
+
const run = mw([rule()]);
|
|
17
|
+
const res = await run({ url: '/old-page', method: 'GET' });
|
|
18
|
+
expect(res).toMatchObject({ statusCode: 301, location: '/new-page' });
|
|
19
|
+
});
|
|
20
|
+
it('matches even when the request carries a query string (UTM/tracking params)', async () => {
|
|
21
|
+
// Regression: the query used to be re-appended to the compared path, so
|
|
22
|
+
// /old-page?utm_source=x never equalled the '/old-page' rule and silently
|
|
23
|
+
// failed for the most common inbound traffic.
|
|
24
|
+
const run = mw([rule()]);
|
|
25
|
+
const res = await run({ url: '/old-page?utm_source=news&gclid=123', method: 'GET' });
|
|
26
|
+
expect(res).toMatchObject({ statusCode: 301, location: '/new-page' });
|
|
27
|
+
});
|
|
28
|
+
it('preserveQuery re-appends the incoming query to the destination', async () => {
|
|
29
|
+
const run = mw([rule({ preserveQuery: true })]);
|
|
30
|
+
const res = await run({ url: '/old-page?utm_source=news', method: 'GET' });
|
|
31
|
+
expect(res?.location).toBe('/new-page?utm_source=news');
|
|
32
|
+
});
|
|
33
|
+
it('preserveQuery merges into a destination that already has a query', async () => {
|
|
34
|
+
const run = mw([rule({ toUrl: '/new-page?ref=1', preserveQuery: true })]);
|
|
35
|
+
const res = await run({ url: '/old-page?utm_source=news', method: 'GET' });
|
|
36
|
+
expect(res?.location).toBe('/new-page?ref=1&utm_source=news');
|
|
37
|
+
});
|
|
38
|
+
it('ignores the query when preserveQuery is not set', async () => {
|
|
39
|
+
const run = mw([rule()]);
|
|
40
|
+
const res = await run({ url: '/old-page?utm_source=news', method: 'GET' });
|
|
41
|
+
expect(res?.location).toBe('/new-page');
|
|
42
|
+
});
|
|
43
|
+
it('normalizes trailing slash by default (/old/ matches an /old rule)', async () => {
|
|
44
|
+
const run = mw([rule({ fromUrl: '/old-page' })]);
|
|
45
|
+
const res = await run({ url: '/old-page/', method: 'GET' });
|
|
46
|
+
expect(res).toMatchObject({ statusCode: 301, location: '/new-page' });
|
|
47
|
+
});
|
|
48
|
+
it('preserves 307 and 308 status codes (no downgrade to 301/302)', async () => {
|
|
49
|
+
const run307 = mw([rule({ type: '307' })]);
|
|
50
|
+
expect(await run307({ url: '/old-page', method: 'GET' })).toMatchObject({ statusCode: 307 });
|
|
51
|
+
const run308 = mw([rule({ type: '308' })]);
|
|
52
|
+
expect(await run308({ url: '/old-page', method: 'GET' })).toMatchObject({ statusCode: 308 });
|
|
53
|
+
});
|
|
54
|
+
it('emits a 410 Gone with no location', async () => {
|
|
55
|
+
const run = mw([rule({ type: '410' })]);
|
|
56
|
+
const res = await run({ url: '/old-page', method: 'GET' });
|
|
57
|
+
expect(res).toMatchObject({ statusCode: 410, location: '' });
|
|
58
|
+
});
|
|
59
|
+
it('skips inactive rules and non-GET/HEAD methods', async () => {
|
|
60
|
+
expect(await mw([rule({ isActive: false })])({ url: '/old-page', method: 'GET' })).toBeNull();
|
|
61
|
+
expect(await mw([rule()])({ url: '/old-page', method: 'POST' })).toBeNull();
|
|
62
|
+
});
|
|
63
|
+
it('is case-insensitive by default', async () => {
|
|
64
|
+
const run = mw([rule({ fromUrl: '/Old-Page' })]);
|
|
65
|
+
const res = await run({ url: '/old-page', method: 'GET' });
|
|
66
|
+
expect(res).toMatchObject({ location: '/new-page' });
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
describe('createRedirectMiddleware — options, caching, and matching edges', () => {
|
|
70
|
+
it('caseSensitive: true enforces exact-case matching (option changes behavior)', async () => {
|
|
71
|
+
// Inverse of the case-insensitive default: /Old-Page must NOT swallow
|
|
72
|
+
// /old-page when the caller opts into strict casing.
|
|
73
|
+
const run = mw([rule({ fromUrl: '/Old-Page' })], { caseSensitive: true });
|
|
74
|
+
expect(await run({ url: '/old-page', method: 'GET' })).toBeNull();
|
|
75
|
+
// ...but the exact-case request still matches.
|
|
76
|
+
expect(await run({ url: '/Old-Page', method: 'GET' })).toMatchObject({
|
|
77
|
+
statusCode: 301,
|
|
78
|
+
location: '/new-page',
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
it("trailingSlash: 'add' appends a slash to both sides so /old-page matches an /old-page/ rule", async () => {
|
|
82
|
+
const run = mw([rule({ fromUrl: '/old-page/' })], { trailingSlash: 'add' });
|
|
83
|
+
const res = await run({ url: '/old-page', method: 'GET' });
|
|
84
|
+
expect(res).toMatchObject({ statusCode: 301, location: '/new-page' });
|
|
85
|
+
});
|
|
86
|
+
it("trailingSlash: 'ignore' leaves paths untouched (/old-page/ does not match an /old-page rule)", async () => {
|
|
87
|
+
const run = mw([rule({ fromUrl: '/old-page' })], { trailingSlash: 'ignore' });
|
|
88
|
+
// No normalization: the request's trailing slash makes it a different path.
|
|
89
|
+
expect(await run({ url: '/old-page/', method: 'GET' })).toBeNull();
|
|
90
|
+
// The un-slashed request still matches exactly.
|
|
91
|
+
expect(await run({ url: '/old-page', method: 'GET' })).toMatchObject({ location: '/new-page' });
|
|
92
|
+
});
|
|
93
|
+
it('caches getRedirects for the 60s TTL, then refetches (new rules take effect)', async () => {
|
|
94
|
+
vi.useFakeTimers();
|
|
95
|
+
try {
|
|
96
|
+
vi.setSystemTime(0);
|
|
97
|
+
let current = [rule({ toUrl: '/first' })];
|
|
98
|
+
const getRedirects = vi.fn(async () => current);
|
|
99
|
+
const run = createRedirectMiddleware({ getRedirects });
|
|
100
|
+
// First request populates the cache; a back-to-back second request within
|
|
101
|
+
// the window reuses it without a refetch.
|
|
102
|
+
expect(await run({ url: '/old-page', method: 'GET' })).toMatchObject({ location: '/first' });
|
|
103
|
+
current = [rule({ toUrl: '/second' })];
|
|
104
|
+
const cached = await run({ url: '/old-page', method: 'GET' });
|
|
105
|
+
expect(getRedirects).toHaveBeenCalledTimes(1);
|
|
106
|
+
expect(cached).toMatchObject({ location: '/first' });
|
|
107
|
+
// Past the 60_000ms TTL the matcher refetches and serves the new rules.
|
|
108
|
+
vi.setSystemTime(60_001);
|
|
109
|
+
const refreshed = await run({ url: '/old-page', method: 'GET' });
|
|
110
|
+
expect(getRedirects).toHaveBeenCalledTimes(2);
|
|
111
|
+
expect(refreshed).toMatchObject({ location: '/second' });
|
|
112
|
+
}
|
|
113
|
+
finally {
|
|
114
|
+
vi.useRealTimers();
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
it('matches HEAD requests just like GET (both sides of the method guard)', async () => {
|
|
118
|
+
const run = mw([rule()]);
|
|
119
|
+
const res = await run({ url: '/old-page', method: 'HEAD' });
|
|
120
|
+
expect(res).toMatchObject({ statusCode: 301, location: '/new-page' });
|
|
121
|
+
});
|
|
122
|
+
it('falls back to 301 for an unrecognized/out-of-range status type', async () => {
|
|
123
|
+
// 418 is not in the allowed status set — toStatus must return the safe 301
|
|
124
|
+
// default rather than passing an invalid code through.
|
|
125
|
+
const run = mw([rule({ type: '418' })]);
|
|
126
|
+
const res = await run({ url: '/old-page', method: 'GET' });
|
|
127
|
+
expect(res).toMatchObject({ statusCode: 301, location: '/new-page' });
|
|
128
|
+
});
|
|
129
|
+
it("keeps the site root '/' intact under the default 'remove' (root redirects still match)", async () => {
|
|
130
|
+
// path.length > 1 guard: a lone '/' must not be stripped to '' or the root
|
|
131
|
+
// redirect silently stops matching.
|
|
132
|
+
const run = mw([rule({ fromUrl: '/', toUrl: '/home' })]);
|
|
133
|
+
const res = await run({ url: '/', method: 'GET' });
|
|
134
|
+
expect(res).toMatchObject({ statusCode: 301, location: '/home' });
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
//# sourceMappingURL=middleware.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.test.js","sourceRoot":"","sources":["../../src/__tests__/middleware.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AACjD,OAAO,EAAE,wBAAwB,EAAqB,MAAM,kBAAkB,CAAA;AAE9E,SAAS,EAAE,CACT,KAAqB,EACrB,UAAmE,EAAE;IAErE,OAAO,wBAAwB,CAAC,EAAE,YAAY,EAAE,KAAK,IAAI,EAAE,CAAC,KAAK,EAAE,GAAG,OAAO,EAAE,CAAC,CAAA;AAClF,CAAC;AAED,MAAM,IAAI,GAAG,CAAC,OAA8B,EAAE,EAAgB,EAAE,CAAC,CAAC;IAChE,EAAE,EAAE,GAAG;IACP,OAAO,EAAE,WAAW;IACpB,KAAK,EAAE,WAAW;IAClB,IAAI,EAAE,KAAK;IACX,QAAQ,EAAE,IAAI;IACd,GAAG,IAAI;CACR,CAAC,CAAA;AAEF,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;IACxC,EAAE,CAAC,qBAAqB,EAAE,KAAK,IAAI,EAAE;QACnC,MAAM,GAAG,GAAG,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAA;QACxB,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAA;QAC1D,MAAM,CAAC,GAAG,CAAC,CAAC,aAAa,CAAC,EAAE,UAAU,EAAE,GAAG,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC,CAAA;IACvE,CAAC,CAAC,CAAA;I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C,CAAA;QAC/D,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAA;QAC1D,MAAM,CAAC,GAAG,CAAC,CAAC,aAAa,CAAC,EAAE,UAAU,EAAE,GAAG,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC,CAAA;IACvE,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,wFAAwF,EAAE,KAAK,IAAI,EAAE;QACtG,2EAA2E;QAC3E,oCAAoC;QACpC,MAAM,GAAG,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,CAAA;QACxD,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAA;QAClD,MAAM,CAAC,GAAG,CAAC,CAAC,aAAa,CAAC,EAAE,UAAU,EAAE,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAA;IACnE,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface RedirectItem {
|
|
2
|
+
id: string;
|
|
3
|
+
fromUrl: string;
|
|
4
|
+
toUrl: string;
|
|
5
|
+
type: '301' | '302';
|
|
6
|
+
hitCount: number;
|
|
7
|
+
isActive: boolean;
|
|
8
|
+
notes?: string;
|
|
9
|
+
}
|
|
10
|
+
interface RedirectListProps {
|
|
11
|
+
redirects: RedirectItem[];
|
|
12
|
+
onEdit: (item: RedirectItem) => void;
|
|
13
|
+
onDelete: (item: RedirectItem) => void;
|
|
14
|
+
onImport: () => void;
|
|
15
|
+
}
|
|
16
|
+
/** Renders a sortable table of redirect rules with inline active toggle. */
|
|
17
|
+
export declare function RedirectList({ redirects, onEdit, onDelete, onImport }: RedirectListProps): import("react/jsx-runtime").JSX.Element;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=RedirectList.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RedirectList.d.ts","sourceRoot":"","sources":["../../src/admin/RedirectList.tsx"],"names":[],"mappings":"AAIA,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAA;IACV,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,KAAK,GAAG,KAAK,CAAA;IACnB,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,OAAO,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED,UAAU,iBAAiB;IACzB,SAAS,EAAE,YAAY,EAAE,CAAA;IACzB,MAAM,EAAE,CAAC,IAAI,EAAE,YAAY,KAAK,IAAI,CAAA;IACpC,QAAQ,EAAE,CAAC,IAAI,EAAE,YAAY,KAAK,IAAI,CAAA;IACtC,QAAQ,EAAE,MAAM,IAAI,CAAA;CACrB;AAED,4EAA4E;AAC5E,wBAAgB,YAAY,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,iBAAiB,2CA0LxF"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
/** Renders a sortable table of redirect rules with inline active toggle. */
|
|
5
|
+
export function RedirectList({ redirects, onEdit, onDelete, onImport }) {
|
|
6
|
+
const [sortField, setSortField] = useState('fromUrl');
|
|
7
|
+
const [sortDir, setSortDir] = useState('asc');
|
|
8
|
+
const [filter, setFilter] = useState('');
|
|
9
|
+
const handleSort = (field) => {
|
|
10
|
+
if (sortField === field) {
|
|
11
|
+
setSortDir(sortDir === 'asc' ? 'desc' : 'asc');
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
setSortField(field);
|
|
15
|
+
setSortDir('asc');
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const sorted = [...redirects]
|
|
19
|
+
.filter((r) => !filter ||
|
|
20
|
+
r.fromUrl.toLowerCase().includes(filter.toLowerCase()) ||
|
|
21
|
+
r.toUrl.toLowerCase().includes(filter.toLowerCase()))
|
|
22
|
+
.sort((a, b) => {
|
|
23
|
+
const av = a[sortField] ?? '';
|
|
24
|
+
const bv = b[sortField] ?? '';
|
|
25
|
+
const cmp = av < bv ? -1 : av > bv ? 1 : 0;
|
|
26
|
+
return sortDir === 'asc' ? cmp : -cmp;
|
|
27
|
+
});
|
|
28
|
+
const sortIndicator = (field) => sortField === field ? (sortDir === 'asc' ? ' \u25B2' : ' \u25BC') : '';
|
|
29
|
+
const thStyle = {
|
|
30
|
+
textAlign: 'left',
|
|
31
|
+
padding: '10px 12px',
|
|
32
|
+
fontWeight: 600,
|
|
33
|
+
fontSize: 13,
|
|
34
|
+
color: '#374151',
|
|
35
|
+
cursor: 'pointer',
|
|
36
|
+
userSelect: 'none',
|
|
37
|
+
borderBottom: '2px solid #e5e7eb',
|
|
38
|
+
};
|
|
39
|
+
const tdStyle = {
|
|
40
|
+
padding: '10px 12px',
|
|
41
|
+
fontSize: 14,
|
|
42
|
+
borderBottom: '1px solid #f3f4f6',
|
|
43
|
+
};
|
|
44
|
+
return (_jsxs("div", { className: "prenta-redirect-list", children: [_jsxs("div", { style: {
|
|
45
|
+
display: 'flex',
|
|
46
|
+
justifyContent: 'space-between',
|
|
47
|
+
alignItems: 'center',
|
|
48
|
+
marginBottom: 16,
|
|
49
|
+
}, children: [_jsx("input", { type: "text", placeholder: "Filter redirects...", value: filter, onChange: (e) => setFilter(e.target.value), style: {
|
|
50
|
+
padding: '6px 12px',
|
|
51
|
+
border: '1px solid #d1d5db',
|
|
52
|
+
borderRadius: 6,
|
|
53
|
+
fontSize: 14,
|
|
54
|
+
width: 280,
|
|
55
|
+
} }), _jsx("button", { onClick: onImport, style: {
|
|
56
|
+
padding: '6px 16px',
|
|
57
|
+
background: '#f3f4f6',
|
|
58
|
+
border: '1px solid #d1d5db',
|
|
59
|
+
borderRadius: 6,
|
|
60
|
+
cursor: 'pointer',
|
|
61
|
+
fontSize: 14,
|
|
62
|
+
}, children: "Import CSV" })] }), _jsxs("table", { style: { width: '100%', borderCollapse: 'collapse' }, children: [_jsx("thead", { children: _jsxs("tr", { children: [_jsxs("th", { style: thStyle, onClick: () => handleSort('fromUrl'), children: ["From", sortIndicator('fromUrl')] }), _jsxs("th", { style: thStyle, onClick: () => handleSort('toUrl'), children: ["To", sortIndicator('toUrl')] }), _jsxs("th", { style: thStyle, onClick: () => handleSort('type'), children: ["Type", sortIndicator('type')] }), _jsxs("th", { style: thStyle, onClick: () => handleSort('hitCount'), children: ["Hits", sortIndicator('hitCount')] }), _jsxs("th", { style: thStyle, onClick: () => handleSort('isActive'), children: ["Active", sortIndicator('isActive')] }), _jsx("th", { style: { ...thStyle, cursor: 'default' }, children: "Actions" })] }) }), _jsxs("tbody", { children: [sorted.map((item) => (_jsxs("tr", { style: { background: item.isActive ? 'transparent' : '#fafafa' }, children: [_jsx("td", { style: { ...tdStyle, fontFamily: 'monospace', fontSize: 13 }, children: item.fromUrl }), _jsx("td", { style: { ...tdStyle, fontFamily: 'monospace', fontSize: 13 }, children: item.toUrl }), _jsx("td", { style: tdStyle, children: _jsx("span", { style: {
|
|
63
|
+
display: 'inline-block',
|
|
64
|
+
padding: '2px 8px',
|
|
65
|
+
borderRadius: 9999,
|
|
66
|
+
fontSize: 12,
|
|
67
|
+
fontWeight: 500,
|
|
68
|
+
background: item.type === '301' ? '#dbeafe' : '#fef3c7',
|
|
69
|
+
color: item.type === '301' ? '#1d4ed8' : '#92400e',
|
|
70
|
+
}, children: item.type }) }), _jsx("td", { style: { ...tdStyle, fontVariantNumeric: 'tabular-nums' }, children: item.hitCount.toLocaleString() }), _jsxs("td", { style: tdStyle, children: [_jsx("span", { style: {
|
|
71
|
+
display: 'inline-block',
|
|
72
|
+
width: 8,
|
|
73
|
+
height: 8,
|
|
74
|
+
borderRadius: '50%',
|
|
75
|
+
background: item.isActive ? '#22c55e' : '#d1d5db',
|
|
76
|
+
marginRight: 6,
|
|
77
|
+
} }), item.isActive ? 'Yes' : 'No'] }), _jsxs("td", { style: { ...tdStyle, whiteSpace: 'nowrap' }, children: [_jsx("button", { onClick: () => onEdit(item), style: {
|
|
78
|
+
marginRight: 8,
|
|
79
|
+
background: 'none',
|
|
80
|
+
border: 'none',
|
|
81
|
+
color: '#3b82f6',
|
|
82
|
+
cursor: 'pointer',
|
|
83
|
+
fontSize: 13,
|
|
84
|
+
}, children: "Edit" }), _jsx("button", { onClick: () => onDelete(item), style: {
|
|
85
|
+
background: 'none',
|
|
86
|
+
border: 'none',
|
|
87
|
+
color: '#dc2626',
|
|
88
|
+
cursor: 'pointer',
|
|
89
|
+
fontSize: 13,
|
|
90
|
+
}, children: "Delete" })] })] }, item.id))), sorted.length === 0 && (_jsx("tr", { children: _jsx("td", { colSpan: 6, style: { ...tdStyle, textAlign: 'center', color: '#9ca3af', padding: 32 }, children: filter ? 'No redirects match your filter' : 'No redirects configured' }) }))] })] })] }));
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=RedirectList.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RedirectList.js","sourceRoot":"","sources":["../../src/admin/RedirectList.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAc,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAmBvC,4EAA4E;AAC5E,MAAM,UAAU,YAAY,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAqB;IACvF,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAqB,SAAS,CAAC,CAAA;IACzE,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ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E,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,EAC7B,KAAK,EAAE;oDACL,UAAU,EAAE,MAAM;oDAClB,MAAM,EAAE,MAAM;oDACd,KAAK,EAAE,SAAS;oDAChB,MAAM,EAAE,SAAS;oDACjB,QAAQ,EAAE,EAAE;iDACb,uBAGM,IACN,KA5DE,IAAI,CAAC,EAAE,CA6DX,CACN,CAAC,EACD,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,CACtB,uBACE,aACE,OAAO,EAAE,CAAC,EACV,KAAK,EAAE,EAAE,GAAG,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE,EAAE,YAExE,MAAM,CAAC,CAAC,CAAC,gCAAgC,CAAC,CAAC,CAAC,yBAAyB,GACnE,GACF,CACN,IACK,IACF,IACJ,CACP,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collections.d.ts","sourceRoot":"","sources":["../src/collections.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAExD,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE,oBAAoB,CA6DrE,CAAA"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export const redirectsCollections = {
|
|
2
|
+
redirects: {
|
|
3
|
+
slug: 'redirects',
|
|
4
|
+
labels: { singular: 'Redirect', plural: 'Redirects' },
|
|
5
|
+
timestamps: true,
|
|
6
|
+
fields: {
|
|
7
|
+
fromUrl: {
|
|
8
|
+
type: 'text',
|
|
9
|
+
label: 'From URL',
|
|
10
|
+
required: true,
|
|
11
|
+
admin: {
|
|
12
|
+
placeholder: '/old-page',
|
|
13
|
+
description: 'The URL path to redirect from',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
toUrl: {
|
|
17
|
+
type: 'text',
|
|
18
|
+
label: 'To URL',
|
|
19
|
+
required: true,
|
|
20
|
+
admin: {
|
|
21
|
+
placeholder: '/new-page',
|
|
22
|
+
description: 'The destination URL to redirect to',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
type: {
|
|
26
|
+
type: 'select',
|
|
27
|
+
label: 'Redirect Type',
|
|
28
|
+
options: [
|
|
29
|
+
{ label: 'Permanent (301)', value: '301' },
|
|
30
|
+
{ label: 'Temporary (302)', value: '302' },
|
|
31
|
+
],
|
|
32
|
+
defaultValue: '301',
|
|
33
|
+
},
|
|
34
|
+
hitCount: {
|
|
35
|
+
type: 'number',
|
|
36
|
+
label: 'Hit Count',
|
|
37
|
+
defaultValue: 0,
|
|
38
|
+
admin: { readOnly: true },
|
|
39
|
+
},
|
|
40
|
+
isActive: {
|
|
41
|
+
type: 'boolean',
|
|
42
|
+
label: 'Active',
|
|
43
|
+
defaultValue: true,
|
|
44
|
+
},
|
|
45
|
+
notes: {
|
|
46
|
+
type: 'text',
|
|
47
|
+
label: 'Notes',
|
|
48
|
+
admin: {
|
|
49
|
+
placeholder: 'Optional notes about this redirect',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
admin: {
|
|
54
|
+
useAsTitle: 'fromUrl',
|
|
55
|
+
defaultColumns: ['fromUrl', 'toUrl', 'type', 'hitCount', 'isActive'],
|
|
56
|
+
// Hidden from the sidebar: redirects are managed in the SEO Operations
|
|
57
|
+
// Center (SEO → Redirects tab), not as a raw collection. A `group` here
|
|
58
|
+
// surfaced a "/redirects" nav entry that the admin doesn't route (404).
|
|
59
|
+
hidden: true,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=collections.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collections.js","sourceRoot":"","sources":["../src/collections.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,oBAAoB,GAAyC;IACxE,SAAS,EAAE;QACT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AC;YACpE,uEAAuE;YACvE,wEAAwE;YACxE,wEAAwE;YACxE,MAAM,EAAE,IAAI;SACb;KACF;CACF,CAAA"}
|
package/dist/fields.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../src/fields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAEnD,eAAO,MAAM,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAM,CAAA"}
|
package/dist/fields.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fields.js","sourceRoot":"","sources":["../src/fields.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,eAAe,GAAoC,EAAE,CAAA"}
|
package/dist/hooks.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAY9C,eAAO,MAAM,cAAc,EAAE,UAAU,EAAO,CAAA"}
|
package/dist/hooks.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// This plugin previously registered an 'onRedirectMatch' hook that incremented
|
|
2
|
+
// a redirect's hit count whenever it matched an incoming request. cms-core's
|
|
3
|
+
// plugin hook bus only dispatches document-lifecycle events
|
|
4
|
+
// ('afterCreate' | 'afterUpdate' | 'afterDelete', plus their
|
|
5
|
+
// `${event}:${collection}` variants) and 'afterUpload'. It does NOT dispatch
|
|
6
|
+
// request-time events such as 'onRedirectMatch' — matching a request against
|
|
7
|
+
// redirect rules and tracking hit counts is a concern of the redirect
|
|
8
|
+
// matcher/middleware (see createRedirectMiddleware), not the lifecycle hook
|
|
9
|
+
// bus. That hook has therefore been removed. This plugin exposes no
|
|
10
|
+
// document/upload lifecycle hooks, so the array is intentionally empty.
|
|
11
|
+
export const redirectsHooks = [];
|
|
12
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAEA,+EAA+E;AAC/E,6EAA6E;AAC7E,4DAA4D;AAC5D,6DAA6D;AAC7D,6EAA6E;AAC7E,6EAA6E;AAC7E,sEAAsE;AACtE,4EAA4E;AAC5E,oEAAoE;AACpE,wEAAwE;AACxE,MAAM,CAAC,MAAM,cAAc,GAAiB,EAAE,CAAA"}
|
package/dist/import.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface ParsedRedirect {
|
|
2
|
+
fromUrl: string;
|
|
3
|
+
toUrl: string;
|
|
4
|
+
type: '301' | '302';
|
|
5
|
+
lineNumber: number;
|
|
6
|
+
}
|
|
7
|
+
export interface ValidationResult {
|
|
8
|
+
valid: boolean;
|
|
9
|
+
errors: Array<{
|
|
10
|
+
lineNumber: number;
|
|
11
|
+
message: string;
|
|
12
|
+
}>;
|
|
13
|
+
warnings: Array<{
|
|
14
|
+
lineNumber: number;
|
|
15
|
+
message: string;
|
|
16
|
+
}>;
|
|
17
|
+
}
|
|
18
|
+
/** Parses a CSV string with columns: from,to,type into redirect entries. */
|
|
19
|
+
export declare function parseRedirectCSV(csvContent: string): ParsedRedirect[];
|
|
20
|
+
/** Validates parsed redirects for circular references, duplicates, and missing fields. */
|
|
21
|
+
export declare function validateRedirects(redirects: ParsedRedirect[]): ValidationResult;
|
|
22
|
+
//# sourceMappingURL=import.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import.d.ts","sourceRoot":"","sources":["../src/import.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,KAAK,GAAG,KAAK,CAAA;IACnB,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,OAAO,CAAA;IACd,MAAM,EAAE,KAAK,CAAC;QACZ,UAAU,EAAE,MAAM,CAAA;QAClB,OAAO,EAAE,MAAM,CAAA;KAChB,CAAC,CAAA;IACF,QAAQ,EAAE,KAAK,CAAC;QACd,UAAU,EAAE,MAAM,CAAA;QAClB,OAAO,EAAE,MAAM,CAAA;KAChB,CAAC,CAAA;CACH;AAED,4EAA4E;AAC5E,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,cAAc,EAAE,CA0BrE;AAED,0FAA0F;AAC1F,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,cAAc,EAAE,GAAG,gBAAgB,CA8D/E"}
|
package/dist/import.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/** Parses a CSV string with columns: from,to,type into redirect entries. */
|
|
2
|
+
export function parseRedirectCSV(csvContent) {
|
|
3
|
+
const lines = csvContent.split('\n').map((line) => line.trim());
|
|
4
|
+
const results = [];
|
|
5
|
+
for (let i = 0; i < lines.length; i++) {
|
|
6
|
+
const line = lines[i];
|
|
7
|
+
if (!line || (i === 0 && line.toLowerCase().startsWith('from'))) {
|
|
8
|
+
continue;
|
|
9
|
+
}
|
|
10
|
+
const parts = line.split(',').map((p) => p.trim().replace(/^["']|["']$/g, ''));
|
|
11
|
+
if (parts.length < 2)
|
|
12
|
+
continue;
|
|
13
|
+
const [fromUrl, toUrl, rawType] = parts;
|
|
14
|
+
const type = rawType === '302' ? '302' : '301';
|
|
15
|
+
results.push({
|
|
16
|
+
fromUrl: fromUrl,
|
|
17
|
+
toUrl: toUrl,
|
|
18
|
+
type,
|
|
19
|
+
lineNumber: i + 1,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return results;
|
|
23
|
+
}
|
|
24
|
+
/** Validates parsed redirects for circular references, duplicates, and missing fields. */
|
|
25
|
+
export function validateRedirects(redirects) {
|
|
26
|
+
const errors = [];
|
|
27
|
+
const warnings = [];
|
|
28
|
+
const fromUrls = new Map();
|
|
29
|
+
for (const redirect of redirects) {
|
|
30
|
+
if (!redirect.fromUrl) {
|
|
31
|
+
errors.push({
|
|
32
|
+
lineNumber: redirect.lineNumber,
|
|
33
|
+
message: "Missing 'from' URL",
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
if (!redirect.toUrl) {
|
|
37
|
+
errors.push({
|
|
38
|
+
lineNumber: redirect.lineNumber,
|
|
39
|
+
message: "Missing 'to' URL",
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
if (redirect.fromUrl === redirect.toUrl) {
|
|
43
|
+
errors.push({
|
|
44
|
+
lineNumber: redirect.lineNumber,
|
|
45
|
+
message: `Circular redirect: "${redirect.fromUrl}" redirects to itself`,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
const existing = fromUrls.get(redirect.fromUrl);
|
|
49
|
+
if (existing !== undefined) {
|
|
50
|
+
warnings.push({
|
|
51
|
+
lineNumber: redirect.lineNumber,
|
|
52
|
+
message: `Duplicate 'from' URL "${redirect.fromUrl}" (first seen on line ${existing})`,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
fromUrls.set(redirect.fromUrl, redirect.lineNumber);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const toUrlMap = new Map(redirects.map((r) => [r.fromUrl, r.toUrl]));
|
|
60
|
+
for (const redirect of redirects) {
|
|
61
|
+
const chain = [redirect.fromUrl];
|
|
62
|
+
let current = redirect.toUrl;
|
|
63
|
+
while (current && toUrlMap.has(current)) {
|
|
64
|
+
if (chain.includes(current)) {
|
|
65
|
+
errors.push({
|
|
66
|
+
lineNumber: redirect.lineNumber,
|
|
67
|
+
message: `Redirect chain forms a cycle: ${[...chain, current].join(' → ')}`,
|
|
68
|
+
});
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
chain.push(current);
|
|
72
|
+
current = toUrlMap.get(current);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
valid: errors.length === 0,
|
|
77
|
+
errors,
|
|
78
|
+
warnings,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=import.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import.js","sourceRoot":"","sources":["../src/import.ts"],"names":[],"mappings":"AAmBA,4EAA4E;AAC5E,MAAM,UAAU,gBAAgB,CAAC,UAAkB;IACjD,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAA;IAC/D,MAAM,OAAO,GAAqB,EAAE,CAAA;IAEpC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;QACrB,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;YAChE,SAAQ;QACV,CAAC;QAED,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC,CAAA;QAE9E,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;YAAE,SAAQ;QAE9B,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC,GAAG,KAAK,CAAA;QACvC,MAAM,IAAI,GAAG,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAA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ig {
|
|
3
|
+
autoDetect404s?: boolean;
|
|
4
|
+
}
|
|
5
|
+
/** Creates a redirects plugin that manages URL redirect rules. */
|
|
6
|
+
export declare function redirectsPlugin(config?: RedirectsPluginConfig): PluginDefinition;
|
|
7
|
+
export { redirectsFields } from './fields.js';
|
|
8
|
+
export { redirectsCollections } from './collections.js';
|
|
9
|
+
export { redirectsHooks } from './hooks.js';
|
|
10
|
+
export { createRedirectMiddleware } from './middleware.js';
|
|
11
|
+
export type { RedirectMiddlewareOptions, RedirectRule, RedirectResponse } from './middleware.js';
|
|
12
|
+
export { parseRedirectCSV, validateRedirects } from './import.js';
|
|
13
|
+
export type { ParsedRedirect } from './import.js';
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAMzE,MAAM,WAAW,qBAAqB;IACpC,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB;AAED,kEAAkE;AAClE,wBAAgB,eAAe,CAAC,MAAM,GAAE,qBAA0B,GAAG,gBAAgB,CAsBpF;AAED,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAA;AAC1D,YAAY,EAAE,yBAAyB,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAChG,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AACjE,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { definePlugin } from '@prenta/core/config';
|
|
2
|
+
import { redirectsFields } from './fields.js';
|
|
3
|
+
import { redirectsCollections } from './collections.js';
|
|
4
|
+
import { redirectsHooks } from './hooks.js';
|
|
5
|
+
/** Creates a redirects plugin that manages URL redirect rules. */
|
|
6
|
+
export function redirectsPlugin(config = {}) {
|
|
7
|
+
// `autoDetect404s` is a request-time concern: logging unmatched 404s to
|
|
8
|
+
// suggest new redirects requires the actual request/response, which only the
|
|
9
|
+
// redirect matcher/middleware sees. cms-core's plugin hook bus dispatches
|
|
10
|
+
// only document and upload lifecycle events — there is no 'onRequest'
|
|
11
|
+
// dispatch — so there is no lifecycle hook to register for it here. The
|
|
12
|
+
// option is retained on the config for the request-time middleware to
|
|
13
|
+
// consume; enabling it does not add any plugin hooks.
|
|
14
|
+
void config.autoDetect404s;
|
|
15
|
+
const hooks = [...redirectsHooks];
|
|
16
|
+
// No sidebar item: the redirects UI lives in the SEO Operations Center
|
|
17
|
+
// (SEO → Redirects tab). The old 'Redirects' item pointed at /redirects, a
|
|
18
|
+
// route the admin doesn't have (it 404'd) — the standalone Redirects view is
|
|
19
|
+
// deprecated in favor of that tab.
|
|
20
|
+
return definePlugin({
|
|
21
|
+
name: 'redirects',
|
|
22
|
+
fields: redirectsFields,
|
|
23
|
+
collections: redirectsCollections,
|
|
24
|
+
hooks,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
export { redirectsFields } from './fields.js';
|
|
28
|
+
export { redirectsCollections } from './collections.js';
|
|
29
|
+
export { redirectsHooks } from './hooks.js';
|
|
30
|
+
export { createRedirectMiddleware } from './middleware.js';
|
|
31
|
+
export { parseRedirectCSV, validateRedirects } from './import.js';
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAyB,MAAM,qBAAqB,CAAA;AAEzE,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAM3C,kEAAkE;AAClE,MAAM,UAAU,eAAe,CAAC,SAAgC,EAAE;IAChE,wEAAwE;IACxE,6EAA6E;IAC7E,0EAA0E;IAC1E,sEAAsE;IACtE,wEAAwE;IACxE,sEAAsE;IACtE,sDAAsD;IACtD,KAAK,MAAM,CAAC,cAAc,CAAA;IAE1B,MAAM,KAAK,GAAiB,CAAC,GAAG,cAAc,CAAC,CAAA;IAE/C,uEAAuE;IACvE,2EAA2E;IAC3E,6EAA6E;IAC7E,mCAAmC;IACnC,OAAO,YAAY,CAAC;QAClB,IAAI,EAAE,WAAW;QACjB,MAAM,EAAE,eAAe;QACvB,WAAW,EAAE,oBAAoB;QACjC,KAAK;KACN,CAAC,CAAA;AACJ,CAAC;AAED,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAA;AAE1D,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface RedirectRule {
|
|
2
|
+
id: string;
|
|
3
|
+
fromUrl: string;
|
|
4
|
+
toUrl: string;
|
|
5
|
+
/** 301/302 redirects, 307/308 method-preserving redirects, or 410 Gone. */
|
|
6
|
+
type: '301' | '302' | '307' | '308' | '410';
|
|
7
|
+
isActive: boolean;
|
|
8
|
+
/** Re-append the incoming request's query string to the destination. */
|
|
9
|
+
preserveQuery?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface RedirectResponse {
|
|
12
|
+
statusCode: 301 | 302 | 307 | 308 | 410;
|
|
13
|
+
/** Destination URL. Empty for a 410 Gone (no redirect target). */
|
|
14
|
+
location: string;
|
|
15
|
+
matchedRule: RedirectRule;
|
|
16
|
+
}
|
|
17
|
+
export interface RedirectMiddlewareOptions {
|
|
18
|
+
getRedirects: () => Promise<RedirectRule[]>;
|
|
19
|
+
caseSensitive?: boolean;
|
|
20
|
+
trailingSlash?: 'add' | 'remove' | 'ignore';
|
|
21
|
+
}
|
|
22
|
+
/** Creates a middleware function that matches incoming requests against redirect rules. */
|
|
23
|
+
export declare function createRedirectMiddleware(options: RedirectMiddlewareOptions): (request: {
|
|
24
|
+
url: string;
|
|
25
|
+
method: string;
|
|
26
|
+
}) => Promise<RedirectResponse | null>;
|
|
27
|
+
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAA;IACV,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,2EAA2E;IAC3E,IAAI,EAAE,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAA;IAC3C,QAAQ,EAAE,OAAO,CAAA;IACjB,wEAAwE;IACxE,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB;AAED,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAA;IACvC,kEAAkE;IAClE,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,EAAE,YAAY,CAAA;CAC1B;AAED,MAAM,WAAW,yBAAyB;IACxC,YAAY,EAAE,MAAM,OAAO,CAAC,YAAY,EAAE,CAAC,CAAA;IAC3C,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,aAAa,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,QAAQ,CAAA;CAC5C;AAwCD,2FAA2F;AAC3F,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,IAS3D,SAAS;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,KAAG,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAqC1F"}
|