@klnap/payload-redirect 0.1.0 → 0.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.
Files changed (80) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +179 -158
  3. package/dist/core/redirects/auto/create-redirect.d.ts +8 -3
  4. package/dist/core/redirects/auto/create-redirect.js +20 -45
  5. package/dist/core/redirects/auto/match-existing-rule.js +1 -1
  6. package/dist/core/redirects/auto/persist-auto-rule.d.ts +3 -2
  7. package/dist/core/redirects/auto/persist-auto-rule.js +5 -4
  8. package/dist/core/redirects/auto/publication/get-publication-transition.d.ts +2 -2
  9. package/dist/core/redirects/auto/publication/get-publication-transition.js +20 -36
  10. package/dist/core/redirects/auto/publication/locales.d.ts +7 -5
  11. package/dist/core/redirects/auto/publication/locales.js +32 -28
  12. package/dist/core/redirects/auto/publication/publish-intent.d.ts +1 -3
  13. package/dist/core/redirects/auto/publication/publish-intent.js +2 -26
  14. package/dist/core/redirects/auto/publication/versions/document-locale.d.ts +4 -6
  15. package/dist/core/redirects/auto/publication/versions/document-locale.js +9 -18
  16. package/dist/core/redirects/auto/publication/versions/version-pages.d.ts +2 -10
  17. package/dist/core/redirects/auto/publication/versions/version-pages.js +4 -30
  18. package/dist/core/redirects/auto/publication/versions/version-rows.d.ts +1 -7
  19. package/dist/core/redirects/auto/publication/versions/version-rows.js +4 -28
  20. package/dist/core/redirects/auto/types.d.ts +27 -6
  21. package/dist/core/redirects/collection/access.d.ts +6 -11
  22. package/dist/core/redirects/collection/access.js +7 -24
  23. package/dist/core/redirects/collection/collection.d.ts +2 -10
  24. package/dist/core/redirects/collection/collection.js +20 -23
  25. package/dist/core/redirects/collection/duplicate-guard.d.ts +1 -1
  26. package/dist/core/redirects/collection/duplicate-guard.js +6 -9
  27. package/dist/core/redirects/collection/fields.d.ts +1 -0
  28. package/dist/core/redirects/collection/fields.js +77 -77
  29. package/dist/core/redirects/collection/origin-hook.js +7 -14
  30. package/dist/core/redirects/collection/types.d.ts +7 -0
  31. package/dist/core/redirects/collection/types.js +1 -0
  32. package/dist/core/redirects/model/errors.d.ts +0 -6
  33. package/dist/core/redirects/model/errors.js +0 -6
  34. package/dist/core/redirects/model/status-code.js +5 -8
  35. package/dist/core/redirects/queries.d.ts +4 -18
  36. package/dist/core/redirects/queries.js +6 -10
  37. package/dist/core/url/published-path.d.ts +5 -16
  38. package/dist/core/url/published-path.js +42 -95
  39. package/dist/core/url/route-params.d.ts +3 -11
  40. package/dist/core/url/route-params.js +31 -99
  41. package/dist/exports/index.d.ts +1 -7
  42. package/dist/exports/index.js +0 -4
  43. package/dist/plugin/payload-plugin.d.ts +3 -3
  44. package/dist/plugin/payload-plugin.js +142 -43
  45. package/dist/plugin/types.d.ts +17 -0
  46. package/dist/plugin/types.js +1 -0
  47. package/docs/FAILURE_SEMANTICS.md +50 -94
  48. package/package.json +11 -9
  49. package/dist/core/redirects/auto/publication/identifier-snapshot.d.ts +0 -2
  50. package/dist/core/redirects/auto/publication/identifier-snapshot.js +0 -27
  51. package/dist/core/redirects/auto/publication/identifier-transitions.d.ts +0 -18
  52. package/dist/core/redirects/auto/publication/identifier-transitions.js +0 -36
  53. package/dist/core/redirects/auto/publication/transition-for-locale.d.ts +0 -12
  54. package/dist/core/redirects/auto/publication/transition-for-locale.js +0 -163
  55. package/dist/core/redirects/auto/publication/transitions-to-pairs.d.ts +0 -7
  56. package/dist/core/redirects/auto/publication/transitions-to-pairs.js +0 -16
  57. package/dist/core/redirects/auto/published-link-config.d.ts +0 -6
  58. package/dist/core/redirects/auto/published-link-config.js +0 -49
  59. package/dist/core/redirects/auto/published-path.d.ts +0 -6
  60. package/dist/core/redirects/auto/published-path.js +0 -11
  61. package/dist/core/redirects/identifier-field-path.d.ts +0 -14
  62. package/dist/core/redirects/identifier-field-path.js +0 -94
  63. package/dist/core/redirects/resolution/resolve.d.ts +0 -7
  64. package/dist/core/redirects/resolution/resolve.js +0 -27
  65. package/dist/core/redirects/resolution/resolved.d.ts +0 -17
  66. package/dist/core/redirects/resolution/resolved.js +0 -18
  67. package/dist/core/redirects/runtime.d.ts +0 -9
  68. package/dist/core/redirects/runtime.js +0 -13
  69. package/dist/core/url/preview-path.d.ts +0 -1
  70. package/dist/core/url/preview-path.js +0 -9
  71. package/dist/core/url/preview-routes.d.ts +0 -3
  72. package/dist/core/url/preview-routes.js +0 -31
  73. package/dist/plugin/redirect-custom.d.ts +0 -9
  74. package/dist/plugin/redirect-custom.js +0 -18
  75. package/dist/plugin/resolve-config.d.ts +0 -17
  76. package/dist/plugin/resolve-config.js +0 -20
  77. package/dist/plugin/validate-config.d.ts +0 -3
  78. package/dist/plugin/validate-config.js +0 -40
  79. package/docs/RELEASING.md +0 -41
  80. package/docs/adr/0002-database-indexes.md +0 -45
@@ -1,20 +0,0 @@
1
- import { createRedirectsCollection } from '../core/redirects/collection/collection.js';
2
- import { RedirectConfigError } from '../core/redirects/model/errors.js';
3
- import { assertValidCollectionConfig } from './validate-config.js';
4
- export const resolveRedirectsPluginConfig = (config) => {
5
- if (!config?.collection) {
6
- throw new RedirectConfigError('redirects plugin requires `collection` — register a redirects CollectionConfig in config.collections and pass it to redirects({ collection })');
7
- }
8
- const collectionOptions = {
9
- trash: config.trash,
10
- access: config.access,
11
- };
12
- const collection = assertValidCollectionConfig(config.collection);
13
- return {
14
- localePrefix: config.localePrefix,
15
- collection: createRedirectsCollection({
16
- base: collection,
17
- ...collectionOptions,
18
- }),
19
- };
20
- };
@@ -1,3 +0,0 @@
1
- import type { CollectionConfig } from 'payload';
2
- export declare const validateRedirectsCollectionConfig: (collection: CollectionConfig) => void;
3
- export declare const assertValidCollectionConfig: (collection: unknown) => CollectionConfig;
@@ -1,40 +0,0 @@
1
- import { RedirectConfigError } from '../core/redirects/model/errors.js';
2
- const isFieldWithName = (field) => 'name' in field && typeof field.name === 'string';
3
- const findField = (fields, name) => fields.find((f) => isFieldWithName(f) && f.name === name);
4
- export const validateRedirectsCollectionConfig = (collection) => {
5
- if (!collection.slug || typeof collection.slug !== 'string') {
6
- throw new RedirectConfigError('redirects collection must have a valid slug');
7
- }
8
- const fields = collection.fields ?? [];
9
- const expectedTypes = {
10
- from: 'text',
11
- to: 'text',
12
- StatusCode: 'select',
13
- enabled: 'checkbox',
14
- origin: 'select',
15
- };
16
- for (const [name, type] of Object.entries(expectedTypes)) {
17
- const field = findField(fields, name);
18
- if (field && (!('type' in field) || field.type !== type)) {
19
- throw new RedirectConfigError(`redirects collection field "${name}" must be type ${type}, got "${field.type}"`);
20
- }
21
- }
22
- const fromField = findField(fields, 'from');
23
- if (fromField) {
24
- if (!('unique' in fromField) || fromField.unique !== true) {
25
- throw new RedirectConfigError('redirects collection field "from" must have unique: true');
26
- }
27
- }
28
- const enabledField = findField(fields, 'enabled');
29
- if (enabledField && (!('index' in enabledField) || enabledField.index !== true)) {
30
- throw new RedirectConfigError('redirects collection field "enabled" must have index: true');
31
- }
32
- };
33
- export const assertValidCollectionConfig = (collection) => {
34
- if (!collection || typeof collection !== 'object') {
35
- throw new RedirectConfigError('collection must be a CollectionConfig object');
36
- }
37
- const cfg = collection;
38
- validateRedirectsCollectionConfig(cfg);
39
- return cfg;
40
- };
package/docs/RELEASING.md DELETED
@@ -1,41 +0,0 @@
1
- # Releasing
2
-
3
- The first staged release uses package version `0.1.0`. npm creates the public
4
- `0.0.0-stage` placeholder when the first package is staged; the package contents
5
- stay private until a maintainer approves the staged release with 2FA.
6
-
7
- ## One-time setup
8
-
9
- 1. Create the public GitHub repository `klnap/payload-redirect` and push `main`.
10
- 2. From the package root, run `npm stage publish` while logged in to npm. This
11
- bootstraps the package entry and stages the `0.1.0` contents.
12
- 3. Configure the npm trusted publisher:
13
- - Provider: GitHub Actions
14
- - Organization/user: `klnap`
15
- - Repository: `payload-redirect`
16
- - Workflow filename: `release.yml`
17
- - Environment: `npm`
18
- - Allow `npm publish`; do not enable dist-tag changes.
19
- 4. Create the GitHub environment named `npm`.
20
-
21
- The release workflow needs no npm token. npm grants it short-lived OIDC
22
- publishing access and generates provenance. Stage approval remains a separate
23
- maintainer action and requires 2FA.
24
-
25
- ## Publish the initial release
26
-
27
- Review and approve the staged `0.1.0` package on npmjs.com or with
28
- `npm stage approve <stage-id>`. npm exposes a `0.0.0-stage` placeholder while
29
- the package is staged. After approval, push the matching release tag:
30
-
31
- ```sh
32
- git tag v0.1.0
33
- git push origin v0.1.0
34
- ```
35
-
36
- The workflow validates the tagged package and skips publishing if `0.1.0` is
37
- already on npm. Later versions are validated and published by the same OIDC
38
- workflow.
39
-
40
- For later releases, update `package.json`, validate the change, and push a matching
41
- `v<version>` tag from `main`.
@@ -1,45 +0,0 @@
1
- # ADR-0002: Redirects collection indexes and queries
2
-
3
- ## Status
4
-
5
- Accepted
6
-
7
- ## Context
8
-
9
- Hooks and `resolveRedirect` look up by normalized `from`. At most one row per `from` is a domain invariant.
10
-
11
- ## Schema (Payload field flags)
12
-
13
- | Field | Flags | Role |
14
- | :--- | :--- | :--- |
15
- | `from` | `unique: true` | Point lookups; duplicate guard (Postgres unique btree via Payload) |
16
- | `enabled` | `index: true` | Filters on active rules |
17
-
18
- Collection defaults: `versions: false`, `defaultSort: 'from'`, `timestamps: true`.
19
-
20
- Custom host collections must keep compatible `from` / `enabled` flags (`validateRedirectsCollectionConfig`).
21
-
22
- ## Postgres (host migration, optional but recommended)
23
-
24
- Partial index for active rules:
25
-
26
- ```sql
27
- CREATE INDEX IF NOT EXISTS "redirects_enabled_from_active_idx"
28
- ON "redirects" USING btree ("from")
29
- WHERE "enabled" = true AND "deleted_at" IS NULL;
30
- ```
31
-
32
- See host database performance docs when adding indexes for large redirect tables.
33
-
34
- ## Query patterns (package)
35
-
36
- | Path | DB round-trips | Notes |
37
- | :--- | :--- | :--- |
38
- | `resolveRedirect` | 1 | `find` by `from`, internal select (from/to/StatusCode/enabled), `depth: 0` |
39
- | `ensureAutoRedirect` | 1 or 2 | Single `find` by `from`; create if absent |
40
- | Duplicate guard | 1 per save | `beforeChange`; `id not_equals` on update |
41
-
42
- ## Non-goals
43
-
44
- - Redirect chains
45
- - Composite `(enabled, from)` btree without partial predicate — redundant with unique `from` for point lookups