@se-studio/contentful-rest-api 1.1.2 → 1.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 (51) hide show
  1. package/CHANGELOG.md +68 -0
  2. package/README.md +7 -1
  3. package/dist/api/context.d.ts.map +1 -1
  4. package/dist/api/context.js +2 -0
  5. package/dist/api/context.js.map +1 -1
  6. package/dist/api/index.d.ts +2 -0
  7. package/dist/api/index.d.ts.map +1 -1
  8. package/dist/api/index.js +2 -0
  9. package/dist/api/index.js.map +1 -1
  10. package/dist/api/redirects.d.ts +16 -0
  11. package/dist/api/redirects.d.ts.map +1 -0
  12. package/dist/api/redirects.js +106 -0
  13. package/dist/api/redirects.js.map +1 -0
  14. package/dist/api/related-articles.d.ts +6 -1
  15. package/dist/api/related-articles.d.ts.map +1 -1
  16. package/dist/api/related-articles.js +66 -19
  17. package/dist/api/related-articles.js.map +1 -1
  18. package/dist/api/types.d.ts +15 -3
  19. package/dist/api/types.d.ts.map +1 -1
  20. package/dist/baseTypes/baseRedirect.d.ts +126 -0
  21. package/dist/baseTypes/baseRedirect.d.ts.map +1 -0
  22. package/dist/baseTypes/baseRedirect.js +2 -0
  23. package/dist/baseTypes/baseRedirect.js.map +1 -0
  24. package/dist/converters/helpers.d.ts +1 -0
  25. package/dist/converters/helpers.d.ts.map +1 -1
  26. package/dist/converters/helpers.js.map +1 -1
  27. package/dist/converters/index.d.ts +1 -0
  28. package/dist/converters/index.d.ts.map +1 -1
  29. package/dist/converters/index.js +1 -0
  30. package/dist/converters/index.js.map +1 -1
  31. package/dist/converters/redirect.d.ts +20 -0
  32. package/dist/converters/redirect.d.ts.map +1 -0
  33. package/dist/converters/redirect.js +103 -0
  34. package/dist/converters/redirect.js.map +1 -0
  35. package/dist/index.d.ts +2 -1
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +2 -1
  38. package/dist/index.js.map +1 -1
  39. package/dist/revalidation/handlers.d.ts.map +1 -1
  40. package/dist/revalidation/handlers.js +6 -1
  41. package/dist/revalidation/handlers.js.map +1 -1
  42. package/dist/revalidation/tags.d.ts +6 -0
  43. package/dist/revalidation/tags.d.ts.map +1 -1
  44. package/dist/revalidation/tags.js +9 -0
  45. package/dist/revalidation/tags.js.map +1 -1
  46. package/dist/utils/redirectMap.d.ts +25 -0
  47. package/dist/utils/redirectMap.d.ts.map +1 -0
  48. package/dist/utils/redirectMap.js +39 -0
  49. package/dist/utils/redirectMap.js.map +1 -0
  50. package/docs/llms.md +9 -3
  51. package/package.json +2 -2
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Pure helper that turns a list of IRedirect (from Contentful) into the simple
3
+ * map used by middleware at runtime or baked into a static module at build.
4
+ *
5
+ * - Filters out inactive redirects.
6
+ * - Prefers explicit statusCode; defaults to 301.
7
+ * - Does light normalization (ensures leading /; the app's trailingSlash: true
8
+ * convention means callers should store rules with trailing slashes for
9
+ * internal paths).
10
+ *
11
+ * This is intentionally side-effect free and safe to run in a Next.js build
12
+ * script or edge middleware context.
13
+ */
14
+ export function buildRedirectMap(redirects) {
15
+ const map = {};
16
+ if (!redirects || redirects.length === 0) {
17
+ return map;
18
+ }
19
+ for (const r of redirects) {
20
+ if (r.active === false)
21
+ continue;
22
+ let from = r.fromPath || '';
23
+ if (!from)
24
+ continue;
25
+ if (!from.startsWith('/'))
26
+ from = `/${from}`;
27
+ // Basic self-loop guard (don't bake a rule that points to itself)
28
+ const to = r.to || '';
29
+ if (!to)
30
+ continue;
31
+ if (to === from)
32
+ continue;
33
+ const status = (r.statusCode ?? 301);
34
+ // Last one wins if duplicates (editors should avoid); keeps it simple.
35
+ map[from] = { to, status };
36
+ }
37
+ return map;
38
+ }
39
+ //# sourceMappingURL=redirectMap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"redirectMap.js","sourceRoot":"","sources":["../../src/utils/redirectMap.ts"],"names":[],"mappings":"AAaA;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,gBAAgB,CAAC,SAAyC;IACxE,MAAM,GAAG,GAAgB,EAAE,CAAC;IAE5B,IAAI,CAAC,SAAS,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzC,OAAO,GAAG,CAAC;IACb,CAAC;IAED,KAAK,MAAM,CAAC,IAAI,SAAS,EAAE,CAAC;QAC1B,IAAI,CAAC,CAAC,MAAM,KAAK,KAAK;YAAE,SAAS;QAEjC,IAAI,IAAI,GAAG,CAAC,CAAC,QAAQ,IAAI,EAAE,CAAC;QAC5B,IAAI,CAAC,IAAI;YAAE,SAAS;QACpB,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC;YAAE,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;QAE7C,kEAAkE;QAClE,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;QACtB,IAAI,CAAC,EAAE;YAAE,SAAS;QAClB,IAAI,EAAE,KAAK,IAAI;YAAE,SAAS;QAE1B,MAAM,MAAM,GAAG,CAAC,CAAC,CAAC,UAAU,IAAI,GAAG,CAA+B,CAAC;QAEnE,uEAAuE;QACvE,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC;IAC7B,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC"}
package/docs/llms.md CHANGED
@@ -70,13 +70,19 @@ import { filterRelatedArticles } from '@se-studio/contentful-rest-api';
70
70
 
71
71
  const related = filterRelatedArticles(allArticleLinks, {
72
72
  tagIds: ['tag-entry-id-1', 'tag-entry-id-2'], // OR filter — must match at least one
73
- articleTypeIds: ['article-type-id'],
73
+ tagSlugs: ['topic-a'], // slugs also supported (combined with OR)
74
+ articleTypeSlugs: ['resources/news'], // or articleTypeIds
75
+ authorSlugs: ['alice'], // or authorIds
76
+ strictAuthorMatch: true, // hard filter (exclude non-matches) instead of boost
77
+ tagTypeSlugs: ['condition'], // hard filter on any tag's tagType
74
78
  excludeArticleIds: [currentArticle.id],
75
- count: 3,
79
+ before: new Date('2025-01-01'),
80
+ count: 3, // undefined = all matches after sort
81
+ allowUnindexed: true,
76
82
  });
77
83
  ```
78
84
 
79
- When `tagIds` is set, articles with no matching tag are excluded. Articles with more matching tags rank higher (then by date).
85
+ When tag criteria are set, articles must match at least one (OR). More distinct matching tags higher rank (then newest date). `strictAuthorMatch` turns author criteria into an exclude filter (key for person-scoped full lists). Use via `getAllArticleLinks({ articleTypeSlugs, strictAuthorMatch, ... })` in core-ui helpers for News Grids / Publications Lists without duplicating filter logic. Direct import is server-only (main barrel of the package pulls server-only transitive deps via enrichers).
80
86
 
81
87
  ## Sitemap Helpers
82
88
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@se-studio/contentful-rest-api",
3
- "version": "1.1.2",
3
+ "version": "1.3.0",
4
4
  "description": "Type-safe Contentful REST API client with caching and rate limiting for Next.js applications",
5
5
  "repository": {
6
6
  "type": "git",
@@ -51,7 +51,7 @@
51
51
  "@contentful/rich-text-types": "^17.2.7",
52
52
  "contentful": "^11.12.3",
53
53
  "server-only": "0.0.1",
54
- "@se-studio/core-data-types": "1.1.2"
54
+ "@se-studio/core-data-types": "1.2.0"
55
55
  },
56
56
  "peerDependencies": {
57
57
  "next": ">=15.5.0"