@payloadcms/ui 4.0.0-canary.35 → 4.0.0-canary.37

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 (237) hide show
  1. package/dist/css/app.css +1 -0
  2. package/dist/css/preflight.css +1 -0
  3. package/dist/css/spacing.css +3 -0
  4. package/dist/elements/AppHeader/index.css +3 -0
  5. package/dist/elements/Banner/index.css +4 -0
  6. package/dist/elements/Banner/index.d.ts.map +1 -1
  7. package/dist/elements/Banner/index.js +1 -0
  8. package/dist/elements/Banner/index.js.map +1 -1
  9. package/dist/elements/BulkUpload/ActionsBar/index.css +1 -0
  10. package/dist/elements/BulkUpload/AddingFilesView/index.css +2 -4
  11. package/dist/elements/BulkUpload/FileSidebar/index.css +1 -0
  12. package/dist/elements/BulkUpload/FormsManager/index.d.ts.map +1 -1
  13. package/dist/elements/BulkUpload/FormsManager/index.js +12 -7
  14. package/dist/elements/BulkUpload/FormsManager/index.js.map +1 -1
  15. package/dist/elements/BulkUpload/index.css +2 -0
  16. package/dist/elements/Collapsible/index.css +1 -0
  17. package/dist/elements/DatePicker/index.css +2 -0
  18. package/dist/elements/Dialog/index.css +1 -0
  19. package/dist/elements/DocumentControls/index.css +1 -0
  20. package/dist/elements/DocumentFields/index.css +2 -0
  21. package/dist/elements/DocumentHeader/Tabs/index.css +1 -0
  22. package/dist/elements/DocumentHeader/index.css +1 -0
  23. package/dist/elements/EditUpload/index.css +1 -1
  24. package/dist/elements/FieldDiffContainer/index.css +1 -0
  25. package/dist/elements/FieldDiffLabel/index.css +1 -0
  26. package/dist/elements/FileDetails/StaticFileDetails/index.css +2 -0
  27. package/dist/elements/HTMLDiff/index.css +1 -0
  28. package/dist/elements/ItemsDrawer/index.css +3 -0
  29. package/dist/elements/ListControls/index.css +1 -0
  30. package/dist/elements/ListControls/index.d.ts.map +1 -1
  31. package/dist/elements/ListControls/index.js +7 -1
  32. package/dist/elements/ListControls/index.js.map +1 -1
  33. package/dist/elements/ListControls/types.d.ts +3 -1
  34. package/dist/elements/ListControls/types.d.ts.map +1 -1
  35. package/dist/elements/ListControls/types.js.map +1 -1
  36. package/dist/elements/ListControlsBar/index.css +1 -0
  37. package/dist/elements/ListHeader/TitleActions/ListEmptyTrashButton.js +1 -1
  38. package/dist/elements/ListHeader/TitleActions/ListEmptyTrashButton.js.map +1 -1
  39. package/dist/elements/LivePreview/Window/index.css +1 -0
  40. package/dist/elements/Nav/getNavPrefs.d.ts.map +1 -1
  41. package/dist/elements/Nav/getNavPrefs.js +2 -0
  42. package/dist/elements/Nav/getNavPrefs.js.map +1 -1
  43. package/dist/elements/Nav/index.css +2 -0
  44. package/dist/elements/PageControls/index.css +1 -0
  45. package/dist/elements/PillSelector/index.css +1 -0
  46. package/dist/elements/PreviewSizes/index.css +2 -0
  47. package/dist/elements/PublishButton/index.css +1 -0
  48. package/dist/elements/PublishButton/index.d.ts.map +1 -1
  49. package/dist/elements/PublishButton/index.js +11 -25
  50. package/dist/elements/PublishButton/index.js.map +1 -1
  51. package/dist/elements/QueryPresets/fields/Heading/index.css +1 -0
  52. package/dist/elements/RenderTitle/index.css +1 -0
  53. package/dist/elements/Table/index.css +1 -0
  54. package/dist/elements/TableSection/index.css +1 -0
  55. package/dist/elements/Tabs/index.css +1 -0
  56. package/dist/elements/Thumbnail/index.css +1 -0
  57. package/dist/elements/TimezonePicker/index.css +1 -0
  58. package/dist/elements/Tooltip/index.css +7 -0
  59. package/dist/elements/WhereBuilder/Condition/index.css +1 -0
  60. package/dist/elements/WhereBuilder/index.css +2 -0
  61. package/dist/fields/Array/index.css +1 -0
  62. package/dist/fields/Blocks/index.css +1 -0
  63. package/dist/fields/Group/index.css +1 -0
  64. package/dist/fields/Row/index.css +2 -0
  65. package/dist/fields/Tabs/index.css +1 -0
  66. package/dist/forms/RenderFields/index.css +1 -0
  67. package/dist/hooks/useControllableState.js +3 -3
  68. package/dist/hooks/useControllableState.js.map +1 -1
  69. package/dist/layouts/Root/index.d.ts +3 -6
  70. package/dist/layouts/Root/index.d.ts.map +1 -1
  71. package/dist/layouts/Root/index.js +2 -4
  72. package/dist/layouts/Root/index.js.map +1 -1
  73. package/dist/providers/DocumentInfo/index.d.ts.map +1 -1
  74. package/dist/providers/DocumentInfo/index.js +30 -19
  75. package/dist/providers/DocumentInfo/index.js.map +1 -1
  76. package/dist/providers/Locale/index.d.ts.map +1 -1
  77. package/dist/providers/Locale/index.js +6 -7
  78. package/dist/providers/Locale/index.js.map +1 -1
  79. package/dist/styles.css +5 -1
  80. package/dist/templates/Default/Wrapper/index.css +2 -0
  81. package/dist/templates/Default/index.css +1 -0
  82. package/dist/utilities/getDocPreferences.d.ts.map +1 -1
  83. package/dist/utilities/getDocPreferences.js +1 -0
  84. package/dist/utilities/getDocPreferences.js.map +1 -1
  85. package/dist/utilities/getPreferences.d.ts.map +1 -1
  86. package/dist/utilities/getPreferences.js +1 -0
  87. package/dist/utilities/getPreferences.js.map +1 -1
  88. package/dist/utilities/getVersions.d.ts.map +1 -1
  89. package/dist/utilities/getVersions.js +8 -0
  90. package/dist/utilities/getVersions.js.map +1 -1
  91. package/dist/utilities/handleAuthRedirect.d.ts.map +1 -1
  92. package/dist/utilities/handleAuthRedirect.js +4 -1
  93. package/dist/utilities/handleAuthRedirect.js.map +1 -1
  94. package/dist/utilities/isPathMatchingRoute.d.ts.map +1 -1
  95. package/dist/utilities/isPathMatchingRoute.js +7 -5
  96. package/dist/utilities/isPathMatchingRoute.js.map +1 -1
  97. package/dist/utilities/schedulePublishHandler.d.ts.map +1 -1
  98. package/dist/utilities/schedulePublishHandler.js +2 -0
  99. package/dist/utilities/schedulePublishHandler.js.map +1 -1
  100. package/dist/utilities/upsertPreferences.d.ts.map +1 -1
  101. package/dist/utilities/upsertPreferences.js +3 -0
  102. package/dist/utilities/upsertPreferences.js.map +1 -1
  103. package/dist/views/API/index.css +1 -0
  104. package/dist/views/Dashboard/Default/ModularDashboard/index.css +2 -0
  105. package/dist/views/Document/handleServerFunction.d.ts.map +1 -1
  106. package/dist/views/Document/handleServerFunction.js +1 -0
  107. package/dist/views/Document/handleServerFunction.js.map +1 -1
  108. package/dist/views/Edit/index.css +1 -0
  109. package/dist/views/HierarchyList/HierarchyTable/SlotTable.css +1 -0
  110. package/dist/views/HierarchyList/index.css +1 -0
  111. package/dist/views/List/ListHeader/index.css +1 -0
  112. package/dist/views/List/ListHeader/index.d.ts +0 -1
  113. package/dist/views/List/ListHeader/index.d.ts.map +1 -1
  114. package/dist/views/List/ListHeader/index.js +2 -6
  115. package/dist/views/List/ListHeader/index.js.map +1 -1
  116. package/dist/views/List/enrichDocsWithVersionStatus.d.ts.map +1 -1
  117. package/dist/views/List/enrichDocsWithVersionStatus.js +1 -0
  118. package/dist/views/List/enrichDocsWithVersionStatus.js.map +1 -1
  119. package/dist/views/List/handleServerFunction.d.ts.map +1 -1
  120. package/dist/views/List/handleServerFunction.js +1 -0
  121. package/dist/views/List/handleServerFunction.js.map +1 -1
  122. package/dist/views/List/index.client.d.ts.map +1 -1
  123. package/dist/views/List/index.client.js +3 -2
  124. package/dist/views/List/index.client.js.map +1 -1
  125. package/dist/views/List/index.css +2 -0
  126. package/dist/views/NotFound/client.d.ts +2 -0
  127. package/dist/views/NotFound/client.d.ts.map +1 -0
  128. package/dist/views/NotFound/client.js +4 -0
  129. package/dist/views/NotFound/client.js.map +1 -0
  130. package/dist/views/Root/index.d.ts.map +1 -1
  131. package/dist/views/Root/index.js +26 -19
  132. package/dist/views/Root/index.js.map +1 -1
  133. package/dist/views/Version/Default/index.css +2 -0
  134. package/dist/views/Version/RenderFieldsToDiff/fields/Date/index.css +8 -0
  135. package/dist/views/Version/RenderFieldsToDiff/fields/Relationship/generateLabelFromValue.d.ts.map +1 -1
  136. package/dist/views/Version/RenderFieldsToDiff/fields/Relationship/generateLabelFromValue.js +1 -0
  137. package/dist/views/Version/RenderFieldsToDiff/fields/Relationship/generateLabelFromValue.js.map +1 -1
  138. package/dist/views/Version/RenderFieldsToDiff/fields/Relationship/index.css +1 -0
  139. package/dist/views/Version/RenderFieldsToDiff/fields/Upload/index.css +1 -0
  140. package/dist/views/Version/RenderFieldsToDiff/index.css +2 -0
  141. package/dist/views/Version/Restore/index.d.ts.map +1 -1
  142. package/dist/views/Version/Restore/index.js +9 -6
  143. package/dist/views/Version/Restore/index.js.map +1 -1
  144. package/dist/views/Versions/VersionPillLabel/index.css +1 -0
  145. package/dist/views/Versions/index.css +1 -0
  146. package/dist/widgets/CollectionCards/index.css +4 -0
  147. package/package.json +11 -6
  148. package/dist/elements/ClipboardAction/clipboardUtilities.spec.js +0 -120
  149. package/dist/elements/ClipboardAction/clipboardUtilities.spec.js.map +0 -1
  150. package/dist/elements/ClipboardAction/isClipboardDataValid.spec.js +0 -144
  151. package/dist/elements/ClipboardAction/isClipboardDataValid.spec.js.map +0 -1
  152. package/dist/elements/ClipboardAction/mergeFormStateFromClipboard.spec.js +0 -885
  153. package/dist/elements/ClipboardAction/mergeFormStateFromClipboard.spec.js.map +0 -1
  154. package/dist/elements/ColumnSelection/matchesColumnSearch.spec.js +0 -87
  155. package/dist/elements/ColumnSelection/matchesColumnSearch.spec.js.map +0 -1
  156. package/dist/elements/CommandPalette/buildActions.spec.js +0 -158
  157. package/dist/elements/CommandPalette/buildActions.spec.js.map +0 -1
  158. package/dist/elements/CommandPalette/highlightLabel.spec.js +0 -78
  159. package/dist/elements/CommandPalette/highlightLabel.spec.js.map +0 -1
  160. package/dist/elements/FieldSelect/reduceFieldOptions.spec.js +0 -143
  161. package/dist/elements/FieldSelect/reduceFieldOptions.spec.js.map +0 -1
  162. package/dist/elements/Toasts/fieldErrors.spec.js +0 -46
  163. package/dist/elements/Toasts/fieldErrors.spec.js.map +0 -1
  164. package/dist/elements/WhereBuilder/Condition/Relationship/optionsReducer.spec.js +0 -152
  165. package/dist/elements/WhereBuilder/Condition/Relationship/optionsReducer.spec.js.map +0 -1
  166. package/dist/elements/WhereBuilder/conditionValue.spec.js +0 -65
  167. package/dist/elements/WhereBuilder/conditionValue.spec.js.map +0 -1
  168. package/dist/fields/Upload/Input.spec.js +0 -242
  169. package/dist/fields/Upload/Input.spec.js.map +0 -1
  170. package/dist/forms/fieldSchemasToFormState/fieldSchemasToFormState.spec.d.ts +0 -2
  171. package/dist/forms/fieldSchemasToFormState/fieldSchemasToFormState.spec.d.ts.map +0 -1
  172. package/dist/forms/fieldSchemasToFormState/fieldSchemasToFormState.spec.js +0 -67
  173. package/dist/forms/fieldSchemasToFormState/fieldSchemasToFormState.spec.js.map +0 -1
  174. package/dist/forms/fieldSchemasToFormState/serverFunctions/renderFieldServerFn.spec.js +0 -150
  175. package/dist/forms/fieldSchemasToFormState/serverFunctions/renderFieldServerFn.spec.js.map +0 -1
  176. package/dist/layouts/Root/index.spec.js +0 -20
  177. package/dist/layouts/Root/index.spec.js.map +0 -1
  178. package/dist/providers/Auth/authSessionRequests.spec.js +0 -121
  179. package/dist/providers/Auth/authSessionRequests.spec.js.map +0 -1
  180. package/dist/providers/Auth/sessionActivity.spec.js +0 -44
  181. package/dist/providers/Auth/sessionActivity.spec.js.map +0 -1
  182. package/dist/providers/Auth/tabSessionSync/index.spec.js +0 -463
  183. package/dist/providers/Auth/tabSessionSync/index.spec.js.map +0 -1
  184. package/dist/providers/Auth/useAuthSessionTimers.spec.js +0 -311
  185. package/dist/providers/Auth/useAuthSessionTimers.spec.js.map +0 -1
  186. package/dist/providers/RouteTransition/ProgressBar/index.spec.js +0 -44
  187. package/dist/providers/RouteTransition/ProgressBar/index.spec.js.map +0 -1
  188. package/dist/providers/TableColumns/buildColumnState/index.spec.js +0 -40
  189. package/dist/providers/TableColumns/buildColumnState/index.spec.js.map +0 -1
  190. package/dist/utilities/appendCacheTag.spec.js +0 -34
  191. package/dist/utilities/appendCacheTag.spec.js.map +0 -1
  192. package/dist/utilities/formatAbsoluteURL.spec.js +0 -27
  193. package/dist/utilities/formatAbsoluteURL.spec.js.map +0 -1
  194. package/dist/utilities/formatMetadata.spec.js +0 -83
  195. package/dist/utilities/formatMetadata.spec.js.map +0 -1
  196. package/dist/utilities/fuzzyMatch.spec.js +0 -38
  197. package/dist/utilities/fuzzyMatch.spec.js.map +0 -1
  198. package/dist/utilities/getRequestLocale.d.ts +0 -7
  199. package/dist/utilities/getRequestLocale.d.ts.map +0 -1
  200. package/dist/utilities/getRequestLocale.js +0 -20
  201. package/dist/utilities/getRequestLocale.js.map +0 -1
  202. package/dist/utilities/initReq.d.ts +0 -16
  203. package/dist/utilities/initReq.d.ts.map +0 -1
  204. package/dist/utilities/initReq.js +0 -146
  205. package/dist/utilities/initReq.js.map +0 -1
  206. package/dist/utilities/initReq.spec.js +0 -226
  207. package/dist/utilities/initReq.spec.js.map +0 -1
  208. package/dist/utilities/isAbsoluteURL.spec.js +0 -11
  209. package/dist/utilities/isAbsoluteURL.spec.js.map +0 -1
  210. package/dist/utilities/isCustomAdminView.spec.js +0 -90
  211. package/dist/utilities/isCustomAdminView.spec.js.map +0 -1
  212. package/dist/utilities/isHttpURL.spec.js +0 -25
  213. package/dist/utilities/isHttpURL.spec.js.map +0 -1
  214. package/dist/utilities/isPathMatchingRoute.spec.js +0 -178
  215. package/dist/utilities/isPathMatchingRoute.spec.js.map +0 -1
  216. package/dist/utilities/isPublicAdminRoute.spec.js +0 -34
  217. package/dist/utilities/isPublicAdminRoute.spec.js.map +0 -1
  218. package/dist/utilities/normalizeRelationshipValue.spec.js +0 -373
  219. package/dist/utilities/normalizeRelationshipValue.spec.js.map +0 -1
  220. package/dist/utilities/recentlyViewed.spec.js +0 -92
  221. package/dist/utilities/recentlyViewed.spec.js.map +0 -1
  222. package/dist/utilities/selectiveCache.d.ts +0 -12
  223. package/dist/utilities/selectiveCache.d.ts.map +0 -1
  224. package/dist/utilities/selectiveCache.js +0 -37
  225. package/dist/utilities/selectiveCache.js.map +0 -1
  226. package/dist/views/Root/getCustomCollectionViewByRoute.spec.js +0 -168
  227. package/dist/views/Root/getCustomCollectionViewByRoute.spec.js.map +0 -1
  228. package/dist/views/Version/RenderFieldsToDiff/buildVersionFields.spec.js +0 -258
  229. package/dist/views/Version/RenderFieldsToDiff/buildVersionFields.spec.js.map +0 -1
  230. package/dist/views/Version/RenderFieldsToDiff/utilities/countChangedFields.spec.js +0 -915
  231. package/dist/views/Version/RenderFieldsToDiff/utilities/countChangedFields.spec.js.map +0 -1
  232. package/dist/views/Version/RenderFieldsToDiff/utilities/fieldHasChanges.spec.js +0 -47
  233. package/dist/views/Version/RenderFieldsToDiff/utilities/fieldHasChanges.spec.js.map +0 -1
  234. package/dist/views/Version/RenderFieldsToDiff/utilities/getFieldsForRowComparison.spec.js +0 -125
  235. package/dist/views/Version/RenderFieldsToDiff/utilities/getFieldsForRowComparison.spec.js.map +0 -1
  236. package/dist/widgets/CollectionQuery/getCollectionFieldPaths.spec.js +0 -100
  237. package/dist/widgets/CollectionQuery/getCollectionFieldPaths.spec.js.map +0 -1
@@ -1,38 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { fuzzyMatch } from './fuzzyMatch.js';
3
- describe('fuzzyMatch', () => {
4
- it('should match a subsequence case-insensitively', () => {
5
- const result = fuzzyMatch('pst', 'Posts');
6
- expect(result).not.toBeNull();
7
- expect(result?.indices).toEqual([0, 2, 3]);
8
- });
9
- it('should match regardless of query case', () => {
10
- expect(fuzzyMatch('POS', 'Posts')).not.toBeNull();
11
- });
12
- it('should return null when not all query chars are present in order', () => {
13
- expect(fuzzyMatch('xyz', 'Posts')).toBeNull();
14
- expect(fuzzyMatch('sp', 'Posts')).toBeNull(); // wrong order
15
- });
16
- it('should return a zero-score empty match for an empty query', () => {
17
- expect(fuzzyMatch('', 'Posts')).toEqual({
18
- indices: [],
19
- score: 0
20
- });
21
- });
22
- it('should score a leading consecutive match higher than a mid-word match', () => {
23
- const leading = fuzzyMatch('pa', 'Pages');
24
- const midWord = fuzzyMatch('pa', 'Media Packs');
25
- expect(leading.score).toBeGreaterThan(midWord.score);
26
- });
27
- it('should score consecutive matches higher than gapped matches', () => {
28
- const consecutive = fuzzyMatch('po', 'Posts');
29
- const gapped = fuzzyMatch('ps', 'Posts');
30
- expect(consecutive.score).toBeGreaterThan(gapped.score);
31
- });
32
- it('returns a non-null match with a negative score for a very sparse match', () => {
33
- const result = fuzzyMatch('az', 'abcdefghijklmnopqrstuvwxyz');
34
- expect(result).not.toBeNull();
35
- expect(result.score).toBeLessThan(0);
36
- });
37
- });
38
- //# sourceMappingURL=fuzzyMatch.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fuzzyMatch.spec.js","names":["describe","expect","it","fuzzyMatch","result","not","toBeNull","indices","toEqual","score","leading","midWord","toBeGreaterThan","consecutive","gapped","toBeLessThan"],"sources":["../../src/utilities/fuzzyMatch.spec.ts"],"sourcesContent":["import { describe, expect, it } from 'vitest'\n\nimport { fuzzyMatch } from './fuzzyMatch.js'\n\ndescribe('fuzzyMatch', () => {\n it('should match a subsequence case-insensitively', () => {\n const result = fuzzyMatch('pst', 'Posts')\n expect(result).not.toBeNull()\n expect(result?.indices).toEqual([0, 2, 3])\n })\n\n it('should match regardless of query case', () => {\n expect(fuzzyMatch('POS', 'Posts')).not.toBeNull()\n })\n\n it('should return null when not all query chars are present in order', () => {\n expect(fuzzyMatch('xyz', 'Posts')).toBeNull()\n expect(fuzzyMatch('sp', 'Posts')).toBeNull() // wrong order\n })\n\n it('should return a zero-score empty match for an empty query', () => {\n expect(fuzzyMatch('', 'Posts')).toEqual({ indices: [], score: 0 })\n })\n\n it('should score a leading consecutive match higher than a mid-word match', () => {\n const leading = fuzzyMatch('pa', 'Pages')\n const midWord = fuzzyMatch('pa', 'Media Packs')\n expect(leading!.score).toBeGreaterThan(midWord!.score)\n })\n\n it('should score consecutive matches higher than gapped matches', () => {\n const consecutive = fuzzyMatch('po', 'Posts')\n const gapped = fuzzyMatch('ps', 'Posts')\n expect(consecutive!.score).toBeGreaterThan(gapped!.score)\n })\n\n it('returns a non-null match with a negative score for a very sparse match', () => {\n const result = fuzzyMatch('az', 'abcd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AME,MAAA,GAASD,UAAA,CAAW,MAAM;IAChCF,MAAA,CAAOG,MAAA,EAAQC,GAAG,CAACC,QAAQ;IAC3BL,MAAA,CAAOG,MAAA,CAAQK,KAAK,EAAEM,YAAY,CAAC;EACrC;AACF","ignoreList":[]}
@@ -1,7 +0,0 @@
1
- import type { Locale, PayloadRequest } from 'payload';
2
- type GetRequestLocalesArgs = {
3
- req: PayloadRequest;
4
- };
5
- export declare function getRequestLocale({ req }: GetRequestLocalesArgs): Promise<Locale>;
6
- export {};
7
- //# sourceMappingURL=getRequestLocale.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getRequestLocale.d.ts","sourceRoot":"","sources":["../../src/utilities/getRequestLocale.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAMrD,KAAK,qBAAqB,GAAG;IAC3B,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED,wBAAsB,gBAAgB,CAAC,EAAE,GAAG,EAAE,EAAE,qBAAqB,GAAG,OAAO,CAAC,MAAM,CAAC,CA8BtF"}
@@ -1,20 +0,0 @@
1
- import { findLocaleFromCode } from './findLocaleFromCode.js';
2
- import { getPreferences } from './getPreferences.js';
3
- import { upsertPreferences } from './upsertPreferences.js';
4
- export async function getRequestLocale({
5
- req
6
- }) {
7
- if (req.payload.config.localization) {
8
- const localeFromParams = req.query.locale;
9
- if (req.user && localeFromParams) {
10
- await upsertPreferences({
11
- key: 'locale',
12
- req,
13
- value: localeFromParams
14
- });
15
- }
16
- return req.user && findLocaleFromCode(req.payload.config.localization, localeFromParams || (await getPreferences('locale', req.payload, req.user.id, req.user.collection))?.value) || findLocaleFromCode(req.payload.config.localization, req.payload.config.localization.defaultLocale || 'en');
17
- }
18
- return undefined;
19
- }
20
- //# sourceMappingURL=getRequestLocale.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getRequestLocale.js","names":["findLocaleFromCode","getPreferences","upsertPreferences","getRequestLocale","req","payload","config","localization","localeFromParams","query","locale","user","key","value","id","collection","defaultLocale","undefined"],"sources":["../../src/utilities/getRequestLocale.ts"],"sourcesContent":["import type { Locale, PayloadRequest } from 'payload'\n\nimport { findLocaleFromCode } from './findLocaleFromCode.js'\nimport { getPreferences } from './getPreferences.js'\nimport { upsertPreferences } from './upsertPreferences.js'\n\ntype GetRequestLocalesArgs = {\n req: PayloadRequest\n}\n\nexport async function getRequestLocale({ req }: GetRequestLocalesArgs): Promise<Locale> {\n if (req.payload.config.localization) {\n const localeFromParams = req.query.locale as string | undefined\n\n if (req.user && localeFromParams) {\n await upsertPreferences<Locale['code']>({ key: 'locale', req, value: localeFromParams })\n }\n\n return (\n (req.user &&\n findLocaleFromCode(\n req.payload.config.localization,\n localeFromParams ||\n (\n await getPreferences<Locale['code']>(\n 'locale',\n req.payload,\n req.user.id,\n req.user.collection,\n )\n )?.value,\n )) ||\n findLocaleFromCode(\n req.payload.config.localization,\n req.payload.config.localization.defaultLocale || 'en',\n )\n )\n }\n\n return undefined\n}\n"],"mappings":"AAEA,SAASA,kBAAkB,QAAQ;AACnC,SAASC,cAAc,QAAQ;AAC/B,SAASC,iBAAiB,QAAQ;AAMlC,OAAO,eAAeC,iBAAiB;EAAEC;AAAG,CAAyB;EACnE,IAAIA,GAAA,CAAIC,OAAO,CAACC,MAAM,CAACC,YAAY,EAAE;IACnC,MAAMC,gBAAA,GAAmBJ,GAAA,CAAIK,KAAK,CAACC,MAAM;IAEzC,IAAIN,GAAA,CAAIO,IAAI,IAAIH,gBAAA,EAAkB;MAChC,MAAMN,iBAAA,CAAkC;QAAEU,GAAA,EAAK;QAAUR,GAAA;QAAKS,KAAA,EAAOL;MAAiB;IACxF;IAEA,OACEJ,GAAC,CAAIO,IAAI,IACPX,kBAAA,CACEI,GAAA,CAAIC,OAAO,CAACC,MAAM,CAACC,YAAY,EAC/BC,gBAAA,IAEI,OAAMP,cAAA,CACJ,UACAG,GAAA,CAAIC,OAAO,EACXD,GAAA,CAAIO,IAAI,CAACG,EAAE,EACXV,GAAA,CAAIO,IAAI,CAACI,UAAU,CACrB,GACCF,KAAA,KAETb,kBAAA,CACEI,GAAA,CAAIC,OAAO,CAACC,MAAM,CAACC,YAAY,EAC/BH,GAAA,CAAIC,OAAO,CAACC,MAAM,CAACC,YAAY,CAACS,aAAa,IAAI;EAGvD;EAEA,OAAOC,SAAA;AACT","ignoreList":[]}
@@ -1,16 +0,0 @@
1
- import type { ImportMap, InitReqResult, SanitizedConfig, ServerAdapter } from 'payload';
2
- import { createLocalReq } from 'payload';
3
- /**
4
- * Initializes a full request object, including the `req` object and access control.
5
- * Reads headers/cookies through the supplied `serverAdapter` so the function is
6
- * framework-agnostic; the consuming framework wires its own adapter.
7
- */
8
- export declare const initReq: ({ canSetHeaders, configPromise, importMap, key, overrides, serverAdapter, }: {
9
- canSetHeaders?: boolean;
10
- configPromise: Promise<SanitizedConfig> | SanitizedConfig;
11
- importMap: ImportMap;
12
- key: string;
13
- overrides?: Parameters<typeof createLocalReq>[0];
14
- serverAdapter: ServerAdapter;
15
- }) => Promise<InitReqResult>;
16
- //# sourceMappingURL=initReq.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"initReq.d.ts","sourceRoot":"","sources":["../../src/utilities/initReq.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,SAAS,EACT,aAAa,EAEb,eAAe,EACf,aAAa,EACd,MAAM,SAAS,CAAA;AAGhB,OAAO,EACL,cAAc,EAMf,MAAM,SAAS,CAAA;AAchB;;;;GAIG;AACH,eAAO,MAAM,OAAO,gFAOjB;IACD,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,aAAa,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,CAAA;IACzD,SAAS,EAAE,SAAS,CAAA;IACpB,GAAG,EAAE,MAAM,CAAA;IACX,SAAS,CAAC,EAAE,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC,CAAC,CAAC,CAAA;IAChD,aAAa,EAAE,aAAa,CAAA;CAC7B,KAAG,OAAO,CAAC,aAAa,CA2HxB,CAAA"}
@@ -1,146 +0,0 @@
1
- import { initI18n } from '@payloadcms/translations';
2
- import { createLocalReq, executeAuthStrategies, getAccessResults, getPayload, getRequestLanguage, parseCookies } from 'payload';
3
- import { applyUserReadAccess } from 'payload/internal';
4
- import { getRequestLocale } from './getRequestLocale.js';
5
- import { selectiveCache } from './selectiveCache.js';
6
- const partialReqCache = selectiveCache('partialReq');
7
- const reqCache = selectiveCache('req');
8
- /**
9
- * Initializes a full request object, including the `req` object and access control.
10
- * Reads headers/cookies through the supplied `serverAdapter` so the function is
11
- * framework-agnostic; the consuming framework wires its own adapter.
12
- */
13
- export const initReq = async function ({
14
- canSetHeaders,
15
- configPromise,
16
- importMap,
17
- key,
18
- overrides,
19
- serverAdapter
20
- }) {
21
- const headers = await serverAdapter.getHeaders();
22
- const cookies = parseCookies(headers);
23
- const getPartialResult = async () => {
24
- const config = await configPromise;
25
- const payload = await getPayload({
26
- config,
27
- cron: true,
28
- importMap
29
- });
30
- const languageCode = getRequestLanguage({
31
- config,
32
- cookies,
33
- headers
34
- });
35
- const i18n = await initI18n({
36
- config: config.i18n,
37
- context: 'client',
38
- language: languageCode
39
- });
40
- const {
41
- responseHeaders,
42
- user
43
- } = await executeAuthStrategies({
44
- canSetHeaders,
45
- headers,
46
- payload
47
- });
48
- return {
49
- i18n,
50
- languageCode,
51
- payload,
52
- responseHeaders,
53
- user
54
- };
55
- };
56
- const partialResult = await partialReqCache.get(getPartialResult, 'global');
57
- const getResult = async () => {
58
- const {
59
- i18n,
60
- languageCode,
61
- payload,
62
- responseHeaders,
63
- user
64
- } = partialResult;
65
- const {
66
- req: reqOverrides,
67
- ...optionsOverrides
68
- } = overrides || {};
69
- const hasOptionsUserOverride = Object.hasOwn(optionsOverrides, 'user');
70
- const hasReqUserOverride = Object.hasOwn(reqOverrides ?? {}, 'user');
71
- const hasUserOverride = hasOptionsUserOverride || hasReqUserOverride;
72
- const userOverride = hasOptionsUserOverride ? optionsOverrides.user : reqOverrides?.user;
73
- const req = await createLocalReq({
74
- req: {
75
- headers,
76
- host: headers.get('host'),
77
- i18n: i18n,
78
- responseHeaders,
79
- server: serverAdapter,
80
- user,
81
- ...(reqOverrides || {})
82
- },
83
- ...(optionsOverrides || {})
84
- }, payload);
85
- if (hasUserOverride && userOverride == null) {
86
- req.user = null;
87
- }
88
- let userWithReadAccess = req.user;
89
- const locale = await getRequestLocale({
90
- req
91
- });
92
- req.locale = locale?.code;
93
- if (!hasUserOverride && req.user) {
94
- try {
95
- const collectionSlug = req.user.collection ?? payload.config.admin.user;
96
- const collection = payload.collections[collectionSlug]?.config;
97
- if (!collection?.auth) {
98
- throw new Error('Authenticated user collection not found');
99
- }
100
- userWithReadAccess = await applyUserReadAccess({
101
- collection,
102
- depth: collection.auth.depth,
103
- overrideAccess: false,
104
- req,
105
- showHiddenFields: false,
106
- user: req.user
107
- });
108
- } catch (error) {
109
- payload.logger.error({
110
- err: error
111
- });
112
- req.user = null;
113
- userWithReadAccess = null;
114
- }
115
- }
116
- const permissions = await getAccessResults({
117
- req
118
- });
119
- return {
120
- cookies,
121
- headers,
122
- languageCode,
123
- locale,
124
- permissions,
125
- req,
126
- user: userWithReadAccess
127
- };
128
- };
129
- return reqCache.get(getResult, key, overrides).then(result => {
130
- // Shallow-copy req before returning to prevent
131
- // mutations from propagating to the cached req object.
132
- // This ensures parallel operations using the same cache key don't affect each other.
133
- return {
134
- ...result,
135
- req: {
136
- ...result.req,
137
- ...(result.req?.context ? {
138
- context: {
139
- ...result.req.context
140
- }
141
- } : {})
142
- }
143
- };
144
- });
145
- };
146
- //# sourceMappingURL=initReq.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"initReq.js","names":["initI18n","createLocalReq","executeAuthStrategies","getAccessResults","getPayload","getRequestLanguage","parseCookies","applyUserReadAccess","getRequestLocale","selectiveCache","partialReqCache","reqCache","initReq","canSetHeaders","configPromise","importMap","key","overrides","serverAdapter","headers","getHeaders","cookies","getPartialResult","config","payload","cron","languageCode","i18n","context","language","responseHeaders","user","partialResult","get","getResult","req","reqOverrides","optionsOverrides","hasOptionsUserOverride","Object","hasOwn","hasReqUserOverride","hasUserOverride","userOverride","host","server","userWithReadAccess","locale","code","collectionSlug","collection","admin","collections","auth","Error","depth","overrideAccess","showHiddenFields","error","logger","err","permissions","then","result"],"sources":["../../src/utilities/initReq.ts"],"sourcesContent":["import type { I18n, I18nClient } from '@payloadcms/translations'\nimport type {\n ImportMap,\n InitReqResult,\n PayloadRequest,\n SanitizedConfig,\n ServerAdapter,\n} from 'payload'\n\nimport { initI18n } from '@payloadcms/translations'\nimport {\n createLocalReq,\n executeAuthStrategies,\n getAccessResults,\n getPayload,\n getRequestLanguage,\n parseCookies,\n} from 'payload'\nimport { applyUserReadAccess } from 'payload/internal'\n\nimport { getRequestLocale } from './getRequestLocale.js'\nimport { selectiveCache } from './selectiveCache.js'\n\ntype PartialResult = {\n i18n: I18nClient\n} & Pick<InitReqResult, 'languageCode'> &\n Pick<PayloadRequest, 'payload' | 'responseHeaders' | 'user'>\n\nconst partialReqCache = selectiveCache<PartialResult>('partialReq')\nconst reqCache = selectiveCache<InitReqResult>('req')\n\n/**\n * Initializes a full request object, including the `req` object and access control.\n * Reads headers/cookies through the supplied `serverAdapter` so the function is\n * framework-agnostic; the consuming framework wires its own adapter.\n */\nexport const initReq = async function ({\n canSetHeaders,\n configPromise,\n importMap,\n key,\n overrides,\n serverAdapter,\n}: {\n canSetHeaders?: boolean\n configPromise: Promise<SanitizedConfig> | SanitizedConfig\n importMap: ImportMap\n key: string\n overrides?: Parameters<typeof createLocalReq>[0]\n serverAdapter: ServerAdapter\n}): Promise<InitReqResult> {\n const headers = await serverAdapter.getHeaders()\n const cookies = parseCookies(headers)\n\n const getPartialResult = async () => {\n const config = await configPromise\n const payload = await getPayload({ config, cron: true, importMap })\n const languageCode = getRequestLanguage({\n config,\n cookies,\n headers,\n })\n\n const i18n: I18nClient = await initI18n({\n config: config.i18n,\n context: 'client',\n language: languageCode,\n })\n\n const { responseHeaders, user } = await executeAuthStrategies({\n canSetHeaders,\n headers,\n payload,\n })\n\n return {\n i18n,\n languageCode,\n payload,\n responseHeaders,\n user,\n }\n }\n\n const partialResult = await partialReqCache.get(getPartialResult, 'global')\n\n const getResult = async () => {\n const { i18n, languageCode, payload, responseHeaders, user } = partialResult\n\n const { req: reqOverrides, ...optionsOverrides } = overrides || {}\n const hasOptionsUserOverride = Object.hasOwn(optionsOverrides, 'user')\n const hasReqUserOverride = Object.hasOwn(reqOverrides ?? {}, 'user')\n const hasUserOverride = hasOptionsUserOverride || hasReqUserOverride\n const userOverride = hasOptionsUserOverride ? optionsOverrides.user : reqOverrides?.user\n\n const req = await createLocalReq(\n {\n req: {\n headers,\n host: headers.get('host'),\n i18n: i18n as I18n,\n responseHeaders,\n server: serverAdapter,\n user,\n ...(reqOverrides || {}),\n },\n ...(optionsOverrides || {}),\n },\n payload,\n )\n\n if (hasUserOverride && userOverride == null) {\n req.user = null\n }\n\n let userWithReadAccess = req.user\n\n const locale = await getRequestLocale({ req })\n req.locale = locale?.code\n\n if (!hasUserOverride && req.user) {\n try {\n const collectionSlug = req.user.collection ?? payload.config.admin.user\n const collection = payload.collections[collectionSlug]?.config\n\n if (!collection?.auth) {\n throw new Error('Authenticated user collection not found')\n }\n\n userWithReadAccess = await applyUserReadAccess({\n collection,\n depth: collection.auth.depth,\n overrideAccess: false,\n req,\n showHiddenFields: false,\n user: req.user,\n })\n } catch (error) {\n payload.logger.error({ err: error })\n req.user = null\n userWithReadAccess = null\n }\n }\n\n const permissions = await getAccessResults({ req })\n\n return {\n cookies,\n headers,\n languageCode,\n locale,\n permissions,\n req,\n user: userWithReadAccess,\n }\n }\n\n return reqCache.get(getResult, key, overrides).then((result) => {\n // Shallow-copy req before returning to prevent\n // mutations from propagating to the cached req object.\n // This ensures parallel operations using the same cache key don't affect each other.\n return {\n ...result,\n req: {\n ...result.req,\n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AAQD,MAAM,CAAC4B,KAAK,CAACpB,IAAI;QACvE,MAAMmB,UAAA,GAAa1B,OAAA,CAAQ4B,WAAW,CAACH,cAAA,CAAe,EAAE1B,MAAA;QAExD,IAAI,CAAC2B,UAAA,EAAYG,IAAA,EAAM;UACrB,MAAM,IAAIC,KAAA,CAAM;QAClB;QAEAR,kBAAA,GAAqB,MAAMvC,mBAAA,CAAoB;UAC7C2C,UAAA;UACAK,KAAA,EAAOL,UAAA,CAAWG,IAAI,CAACE,KAAK;UAC5BC,cAAA,EAAgB;UAChBrB,GAAA;UACAsB,gBAAA,EAAkB;UAClB1B,IAAA,EAAMI,GAAA,CAAIJ;QACZ;MACF,EAAE,OAAO2B,KAAA,EAAO;QACdlC,OAAA,CAAQmC,MAAM,CAACD,KAAK,CAAC;UAAEE,GAAA,EAAKF;QAAM;QAClCvB,GAAA,CAAIJ,IAAI,GAAG;QACXe,kBAAA,GAAqB;MACvB;IACF;IAEA,MAAMe,WAAA,GAAc,MAAM1D,gBAAA,CAAiB;MAAEgC;IAAI;IAEjD,OAAO;MACLd,OAAA;MACAF,OAAA;MACAO,YAAA;MACAqB,MAAA;MACAc,WAAA;MACA1B,GAAA;MACAJ,IAAA,EAAMe;IACR;EACF;EAEA,OAAOnC,QAAA,CAASsB,GAAG,CAACC,SAAA,EAAWlB,GAAA,EAAKC,SAAA,EAAW6C,IAAI,CAAEC,MAAA;IACnD;IACA;IACA;IACA,OAAO;MACL,GAAGA,MAAM;MACT5B,GAAA,EAAK;QACH,GAAG4B,MAAA,CAAO5B,GAAG;QACb,IAAI4B,MAAA,CAAO5B,GAAG,EAAEP,OAAA,GACZ;UACEA,OAAA,EAAS;YAAE,GAAGmC,MAAA,CAAO5B,GAAG,CAACP;UAAQ;QACnC,IACA,CAAC,CAAC;MACR;IACF;EACF;AACF","ignoreList":[]}
@@ -1,226 +0,0 @@
1
- import { beforeEach, describe, expect, it, vi } from 'vitest';
2
- const mocks = vi.hoisted(() => ({
3
- accessContexts: [],
4
- accessUser: null,
5
- applyUserReadAccess: vi.fn(),
6
- cacheStores: new Map(),
7
- executeAuthStrategies: vi.fn(),
8
- user: {
9
- collection: 'users',
10
- id: 'user-id',
11
- role: 'admin'
12
- }
13
- }));
14
- vi.mock('@payloadcms/translations', () => ({
15
- initI18n: vi.fn(async () => ({
16
- fallbackLanguage: 'en',
17
- language: 'en',
18
- t: key => key,
19
- translations: {}
20
- }))
21
- }));
22
- vi.mock('payload', () => ({
23
- createLocalReq: vi.fn(async (options, payload) => {
24
- const request = options.req ?? {};
25
- const user = options.user ?? request.user ?? null;
26
- return {
27
- ...request,
28
- context: options.context ?? request.context ?? {},
29
- headers: request.headers ?? new Headers(),
30
- locale: options.locale ?? request.locale ?? 'en',
31
- pathname: options.urlSuffix,
32
- payload,
33
- query: request.query ?? {},
34
- responseHeaders: request.responseHeaders ?? new Headers(),
35
- user: user && !user.collection ? {
36
- ...user,
37
- collection: payload.config.admin.user
38
- } : user
39
- };
40
- }),
41
- executeAuthStrategies: mocks.executeAuthStrategies,
42
- getAccessResults: vi.fn(async ({
43
- req
44
- }) => {
45
- mocks.accessContexts.push(req.context.name);
46
- mocks.accessUser = req.user;
47
- return {};
48
- }),
49
- getPayload: vi.fn(async () => ({
50
- collections: {
51
- users: {
52
- config: {
53
- auth: {
54
- depth: 1
55
- },
56
- slug: 'users'
57
- }
58
- }
59
- },
60
- config: {
61
- admin: {
62
- user: 'users'
63
- },
64
- i18n: {
65
- fallbackLanguage: 'en',
66
- supportedLanguages: {
67
- en: {}
68
- },
69
- translations: {}
70
- }
71
- },
72
- logger: {
73
- error: vi.fn()
74
- }
75
- })),
76
- getRequestLanguage: vi.fn(() => 'en'),
77
- parseCookies: vi.fn(() => new Map())
78
- }));
79
- vi.mock('payload/internal', () => ({
80
- applyUserReadAccess: mocks.applyUserReadAccess
81
- }));
82
- vi.mock('./getRequestLocale.js', () => ({
83
- getRequestLocale: vi.fn(async ({
84
- req
85
- }) => ({
86
- code: req.locale
87
- }))
88
- }));
89
- vi.mock('./selectiveCache.js', () => ({
90
- selectiveCache: namespace => ({
91
- get: async (factory, ...args) => {
92
- let entries = mocks.cacheStores.get(namespace);
93
- if (!entries) {
94
- entries = [];
95
- mocks.cacheStores.set(namespace, entries);
96
- }
97
- const cached = entries.find(entry => entry.args.length === args.length && entry.args.every((arg, i) => arg === args[i]));
98
- if (cached) {
99
- return cached.value;
100
- }
101
- const value = await factory();
102
- entries.push({
103
- args,
104
- value
105
- });
106
- return value;
107
- }
108
- })
109
- }));
110
- import { initReq } from './initReq.js';
111
- describe('initReq', () => {
112
- beforeEach(() => {
113
- mocks.accessContexts = [];
114
- mocks.accessUser = null;
115
- mocks.applyUserReadAccess.mockReset();
116
- mocks.applyUserReadAccess.mockImplementation(async ({
117
- req,
118
- user
119
- }) => ({
120
- collection: user.collection,
121
- id: user.id,
122
- name: req.context.name
123
- }));
124
- mocks.cacheStores.clear();
125
- mocks.executeAuthStrategies.mockReset();
126
- mocks.executeAuthStrategies.mockResolvedValue({
127
- user: mocks.user
128
- });
129
- });
130
- it('should keep the complete req.user and filter the user for each response', async () => {
131
- const first = await initReq({
132
- configPromise: {},
133
- importMap: {},
134
- key: 'response',
135
- overrides: {
136
- context: {
137
- name: 'First'
138
- }
139
- },
140
- serverAdapter: {
141
- getHeaders: async () => new Headers()
142
- }
143
- });
144
- const second = await initReq({
145
- configPromise: {},
146
- importMap: {},
147
- key: 'response',
148
- overrides: {
149
- context: {
150
- name: 'Second'
151
- }
152
- },
153
- serverAdapter: {
154
- getHeaders: async () => new Headers()
155
- }
156
- });
157
- expect(mocks.executeAuthStrategies).toHaveBeenCalledOnce();
158
- expect(mocks.applyUserReadAccess).toHaveBeenCalledTimes(2);
159
- expect(first.req.user).toHaveProperty('role', 'admin');
160
- expect(second.req.user).toHaveProperty('role', 'admin');
161
- expect(first.user).toMatchObject({
162
- name: 'First'
163
- });
164
- expect(second.user).toMatchObject({
165
- name: 'Second'
166
- });
167
- expect(first.user).not.toHaveProperty('role');
168
- expect(mocks.accessUser).toHaveProperty('role', 'admin');
169
- expect(mocks.accessContexts).toEqual(['First', 'Second']);
170
- });
171
- it('should use anonymous access when user read access fails', async () => {
172
- mocks.applyUserReadAccess.mockRejectedValue(new Error('read access failed'));
173
- const result = await initReq({
174
- configPromise: {},
175
- importMap: {},
176
- key: 'failure',
177
- serverAdapter: {
178
- getHeaders: async () => new Headers()
179
- }
180
- });
181
- expect(result.req.user).toBeNull();
182
- expect(result.user).toBeNull();
183
- expect(mocks.accessUser).toBeNull();
184
- });
185
- it('should preserve an explicit req.user override', async () => {
186
- const user = {
187
- id: 'override-user'
188
- };
189
- const result = await initReq({
190
- configPromise: {},
191
- importMap: {},
192
- key: 'override',
193
- overrides: {
194
- req: {
195
- user
196
- }
197
- },
198
- serverAdapter: {
199
- getHeaders: async () => new Headers()
200
- }
201
- });
202
- expect(result.req.user).toMatchObject({
203
- collection: 'users',
204
- id: 'override-user'
205
- });
206
- expect(result.user).toBe(result.req.user);
207
- expect(mocks.applyUserReadAccess).not.toHaveBeenCalled();
208
- });
209
- it('should preserve an explicit null user override', async () => {
210
- const result = await initReq({
211
- configPromise: {},
212
- importMap: {},
213
- key: 'anonymous',
214
- overrides: {
215
- user: null
216
- },
217
- serverAdapter: {
218
- getHeaders: async () => new Headers()
219
- }
220
- });
221
- expect(result.req.user).toBeNull();
222
- expect(result.user).toBeNull();
223
- expect(mocks.applyUserReadAccess).not.toHaveBeenCalled();
224
- });
225
- });
226
- //# sourceMappingURL=initReq.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"initReq.spec.js","names":["beforeEach","describe","expect","it","vi","mocks","hoisted","accessContexts","accessUser","applyUserReadAccess","fn","cacheStores","Map","executeAuthStrategies","user","collection","id","role","mock","initI18n","fallbackLanguage","language","t","key","translations","createLocalReq","options","payload","request","req","context","headers","Headers","locale","pathname","urlSuffix","query","responseHeaders","config","admin","getAccessResults","push","name","getPayload","collections","users","auth","depth","slug","i18n","supportedLanguages","en","logger","error","getRequestLanguage","parseCookies","getRequestLocale","code","selectiveCache","namespace","get","factory","args","entries","set","cached","find","entry","length","every","arg","i","value","initReq","mockReset","mockImplementation","clear","mockResolvedValue","first","configPromise","importMap","overrides","serverAdapter","getHeaders","second","toHaveBeenCalledOnce","toHaveBeenCalledTimes","toHaveProperty","toMatchObject","not","toEqual","mockRejectedValue","Error","result","toBeNull","toBe","toHaveBeenCalled"],"sources":["../../src/utilities/initReq.spec.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\n\nimport { beforeEach, describe, expect, it, vi } from 'vitest'\n\nconst mocks = vi.hoisted(() => ({\n accessContexts: [] as unknown[],\n accessUser: null as PayloadRequest['user'],\n applyUserReadAccess: vi.fn(),\n cacheStores: new Map<string, Array<{ args: unknown[]; value: object }>>(),\n executeAuthStrategies: vi.fn(),\n user: {\n collection: 'users',\n id: 'user-id',\n role: 'admin',\n } as PayloadRequest['user'],\n}))\n\nvi.mock('@payloadcms/translations', () => ({\n initI18n: vi.fn(async () => ({\n fallbackLanguage: 'en',\n language: 'en',\n t: (key: string) => key,\n translations: {},\n })),\n}))\n\nvi.mock('payload', () => ({\n createLocalReq: vi.fn(async (options, payload) => {\n const request = options.req ?? {}\n const user = options.user ?? request.user ?? null\n\n return {\n ...request,\n context: options.context ?? request.context ?? {},\n headers: request.headers ?? new Headers(),\n locale: options.locale ?? request.locale ?? 'en',\n pathname: options.urlSuffix,\n payload,\n query: request.query ?? {},\n responseHeaders: request.responseHeaders ?? new Headers(),\n user: user && !user.collection ? { ...user, collection: payload.config.admin.user } : user,\n }\n }),\n executeAuthStrategies: mocks.executeAuthStrategies,\n getAccessResults: vi.fn(async ({ req }: { req: PayloadRequest }) => {\n mocks.accessContexts.push(req.context.name)\n mocks.accessUser = req.user\n return {}\n }),\n getPayload: vi.fn(async () => ({\n collections: {\n users: {\n config: {\n auth: { depth: 1 },\n slug: 'users',\n },\n },\n },\n config: {\n admin: { user: 'users' },\n i18n: {\n fallbackLanguage: 'en',\n supportedLanguages: { en: {} },\n translations: {},\n },\n },\n logger: { error: vi.fn() },\n })),\n getRequestLanguage: vi.fn(() => 'en'),\n parseCookies: vi.fn(() => new Map()),\n}))\n\nvi.mock('payload/internal', () => ({\n applyUserReadAccess: mocks.applyUserReadAccess,\n}))\n\nvi.mock('./getRequestLocale.js', () => ({\n getRequestLocale: vi.fn(async ({ req }: { req: PayloadRequest }) => ({\n code: req.locale,\n })),\n}))\n\nvi.mock('./selectiveCache.js', () => ({\n selectiveCache: (namespace: string) => ({\n get: async (factory: () => Promise<object>, ...args: unknown[]) => {\n let entries = mocks.cacheStores.get(namespace)\n\n if (!entries) {\n entries = []\n mocks.cacheStores.set(namespace, entries)\n }\n\n const cached = entries.find(\n (entry) =>\n entry.args.length === args.length && entry.args.every((arg, i) => arg === args[i]),\n )\n\n if (cached) {\n return cached.value\n }\n\n const value = await factory()\n entries.push({ args, value })\n\n return value\n },\n }),\n}))\n\nimport { initReq } from './initReq.js'\n\ndescribe('initReq', () => {\n beforeEach(() => {\n mocks.accessContexts = []\n mocks.accessUser = null\n mocks.applyUserReadAccess.mockReset()\n mocks.applyUserReadAccess.mockImplementation(async ({ req, user }) => ({\n collection: user.collection,\n id: user.id,\n name: req.context.name,\n }))\n mocks.cacheStores.clear()\n mocks.executeAuthStrategies.mockReset()\n mocks.executeAuthStrategies.mockResolvedValue({ user: mocks.user })\n })\n\n it('should keep the complete req.user and filter the user for each response', async () => {\n const first = await initReq({\n configPromise: {} as never,\n importMap: {},\n key: 'response',\n overrides: { context: { name: 'First' } },\n serverAdapter: { getHeaders: async () => new Headers() } as never,\n })\n const second = await initReq({\n configPromise: {} as never,\n importMap: {},\n key: 'response',\n overrides: { context: { name: 'Second' } },\n serverAdapter: { getHeaders: async () => new Headers() } as never,\n })\n\n expect(mocks.executeAuthStrategies).toHaveBeenCalledOnce()\n expect(mocks.applyUserReadAccess).toHaveBeenCalledTimes(2)\n expect(first.req.user).toHaveProperty('role', 'admin')\n expect(second.req.user).toHaveProperty('role', 'admin')\n expect(first.user).toMatchObject({ name: 'First' })\n expect(second.user).toMatchObject({ name: 'Second' })\n expect(first.user).not.toHaveProperty('role')\n expect(mocks.accessUser).toHaveProperty('role', 'admin')\n expect(mocks.accessContexts).toEqual(['First', 'Second'])\n })\n\n it('should use anonymous access when user read access fails', async () => {\n mocks.applyUserReadAccess.mockRejectedValue(new Error('read access failed'))\n\n const result = await initReq({\n configPromise: {} as never,\n importMap: {},\n key: 'failure',\n serverAdapter: { getHeaders: async () => new Headers() } as never,\n })\n\n expect(result.req.user).toBeNull()\n expect(result.user).toBeNull()\n expect(mocks.accessUser).toBeNull()\n })\n\n it('should preserve an explicit req.user override', async () => {\n const user = { id: 'override-user' }\n\n const result = await initReq({\n configPromise: {} as never,\n importMap: {},\n key: 'override',\n overrides: { req: { user } as never },\n serverAdapter: { getHeaders: async () => new Headers() } as never,\n })\n\n expect(result.req.user).toMatchObject({ collection: 'users', id: 'override-user' })\n expect(result.user).toBe(result.req.user)\n expect(mocks.applyUserReadAccess).not.toHaveBeenCalled()\n })\n\n it('should preserve an explicit null user override', async () => {\n const result = await initReq({\n configPromise: {} as never,\n importMap: {},\n key: 'anonymous',\n overrides: { user: null } as never,\n serverAdapter: { getHeaders: async () => new Headers() } as never,\n })\n\n expect(result.req.user).toBeNull()\n expect(result.user).toBeNull()\n expect(mocks.applyUserReadAccess).not.toHaveBeenCalled()\n })\n})\n"],"mappings":"AAEA,SAASA,UAAU,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ;AAErD,MAAMC,KAAA,GAAQD,EAAA,CAAGE,OAAO,CAAC,OAAO;EAC9BC,cAAA,EAAgB,EAAE;EAClBC,UAAA,EAAY;EACZC,mBAAA,EAAqBL,EAAA,CAAGM,EAAE;EAC1BC,WAAA,EAAa,IAAIC,GAAA;EACjBC,qBAAA,EAAuBT,EAAA,CAAGM,EAAE;EAC5BI,IAAA,EAAM;IACJC,UAAA,EAAY;IACZC,EA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,EAAK;MACL0D,SAAA,EAAW;QAAEnE,IAAA,EAAM;MAAK;MACxBoE,aAAA,EAAe;QAAEC,UAAA,EAAY,MAAAA,CAAA,KAAY,IAAInD,OAAA;MAAU;IACzD;IAEA9B,MAAA,CAAO2F,MAAA,CAAOhE,GAAG,CAACf,IAAI,EAAEgF,QAAQ;IAChC5F,MAAA,CAAO2F,MAAA,CAAO/E,IAAI,EAAEgF,QAAQ;IAC5B5F,MAAA,CAAOG,KAAA,CAAMI,mBAAmB,EAAEgF,GAAG,CAACO,gBAAgB;EACxD;AACF","ignoreList":[]}
@@ -1,11 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { isAbsoluteURL } from './isAbsoluteURL.js';
3
- describe('isAbsoluteURL', () => {
4
- it.each(['http://example.com', 'https://example.com/preview', 'mailto:editor@example.com', 'file:///preview.html', new URL('https://example.com/preview')])('should accept absolute URL %s', input => {
5
- expect(isAbsoluteURL(input)).toBe(true);
6
- });
7
- it.each([undefined, '', '/preview', '../preview', 'preview?draft=true', '?draft=true', '#preview', '//example.com/preview', 'https://', 'https://[invalid'])('should reject relative, absent, or invalid URL %s', input => {
8
- expect(isAbsoluteURL(input)).toBe(false);
9
- });
10
- });
11
- //# sourceMappingURL=isAbsoluteURL.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"isAbsoluteURL.spec.js","names":["describe","expect","it","isAbsoluteURL","each","URL","input","toBe","undefined"],"sources":["../../src/utilities/isAbsoluteURL.spec.ts"],"sourcesContent":["import { describe, expect, it } from 'vitest'\n\nimport { isAbsoluteURL } from './isAbsoluteURL.js'\n\ndescribe('isAbsoluteURL', () => {\n it.each([\n 'http://example.com',\n 'https://example.com/preview',\n 'mailto:editor@example.com',\n 'file:///preview.html',\n new URL('https://example.com/preview'),\n ])('should accept absolute URL %s', (input) => {\n expect(isAbsoluteURL(input)).toBe(true)\n })\n\n it.each([\n undefined,\n '',\n '/preview',\n '../preview',\n 'preview?draft=true',\n '?draft=true',\n '#preview',\n '//example.com/preview',\n 'https://',\n 'https://[invalid',\n ])('should reject relative, absent, or invalid URL %s', (input) => {\n expect(isAbsoluteURL(input)).toBe(false)\n })\n})\n"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ;AAErC,SAASC,aAAa,QAAQ;AAE9BH,QAAA,CAAS,iBAAiB;EACxBE,EAAA,CAAGE,IAAI,CAAC,CACN,sBACA,+BACA,6BACA,wBACA,IAAIC,GAAA,CAAI,+BACT,EAAE,iCAAkCC,KAAA;IACnCL,MAAA,CAAOE,aAAA,CAAcG,KAAA,GAAQC,IAAI,CAAC;EACpC;EAEAL,EAAA,CAAGE,IAAI,CAAC,CACNI,SAAA,EACA,IACA,YACA,cACA,sBACA,eACA,YACA,yBACA,YACA,mBACD,EAAE,qDAAsDF,KAAA;IACvDL,MAAA,CAAOE,aAAA,CAAcG,KAAA,GAAQC,IAAI,CAAC;EACpC;AACF","ignoreList":[]}
@@ -1,90 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { isCustomAdminView } from './isCustomAdminView.js';
3
- describe('isCustomAdminView', () => {
4
- const adminRoute = '/admin';
5
- const configWithCustomDashboard = {
6
- admin: {
7
- components: {
8
- views: {
9
- dashboard: {
10
- path: '/'
11
- }
12
- }
13
- }
14
- }
15
- };
16
- it('should not bypass admin access for the root admin route even with a custom dashboard view', () => {
17
- // The root path '/' maps to the dashboard — it is not a public custom view.
18
- // canAccessAdmin must still be enforced for the admin root.
19
- const result = isCustomAdminView({
20
- adminRoute,
21
- config: configWithCustomDashboard,
22
- route: '/admin'
23
- });
24
- expect(result).toBe(false);
25
- });
26
- it('should not match collection routes as custom dashboard views when dashboard path is "/"', () => {
27
- const result = isCustomAdminView({
28
- adminRoute,
29
- config: configWithCustomDashboard,
30
- route: '/admin/collections/tickets'
31
- });
32
- expect(result).toBe(false);
33
- });
34
- it('should not match document routes as custom dashboard views when dashboard path is "/"', () => {
35
- const result = isCustomAdminView({
36
- adminRoute,
37
- config: configWithCustomDashboard,
38
- route: '/admin/collections/tickets/123'
39
- });
40
- expect(result).toBe(false);
41
- });
42
- it('should return false when no custom views are configured', () => {
43
- const config = {};
44
- const result = isCustomAdminView({
45
- adminRoute,
46
- config,
47
- route: '/admin/collections/tickets'
48
- });
49
- expect(result).toBe(false);
50
- });
51
- it('should return true for a custom view with a non-root path', () => {
52
- const config = {
53
- admin: {
54
- components: {
55
- views: {
56
- myCustomView: {
57
- path: '/my-custom-view'
58
- }
59
- }
60
- }
61
- }
62
- };
63
- const result = isCustomAdminView({
64
- adminRoute,
65
- config,
66
- route: '/admin/my-custom-view'
67
- });
68
- expect(result).toBe(true);
69
- });
70
- it('should not match collection routes when a non-root custom view path is set', () => {
71
- const config = {
72
- admin: {
73
- components: {
74
- views: {
75
- myCustomView: {
76
- path: '/my-custom-view'
77
- }
78
- }
79
- }
80
- }
81
- };
82
- const result = isCustomAdminView({
83
- adminRoute,
84
- config,
85
- route: '/admin/collections/tickets'
86
- });
87
- expect(result).toBe(false);
88
- });
89
- });
90
- //# sourceMappingURL=isCustomAdminView.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"isCustomAdminView.spec.js","names":["describe","expect","it","isCustomAdminView","adminRoute","configWithCustomDashboard","admin","components","views","dashboard","path","result","config","route","toBe","myCustomView"],"sources":["../../src/utilities/isCustomAdminView.spec.ts"],"sourcesContent":["import type { SanitizedConfig } from 'payload'\n\nimport { describe, expect, it } from 'vitest'\n\nimport { isCustomAdminView } from './isCustomAdminView.js'\n\ndescribe('isCustomAdminView', () => {\n const adminRoute = '/admin'\n\n const configWithCustomDashboard = {\n admin: {\n components: {\n views: {\n dashboard: {\n path: '/',\n },\n },\n },\n },\n } as unknown as SanitizedConfig\n\n it('should not bypass admin access for the root admin route even with a custom dashboard view', () => {\n // The root path '/' maps to the dashboard — it is not a public custom view.\n // canAccessAdmin must still be enforced for the admin root.\n const result = isCustomAdminView({\n adminRoute,\n config: configWithCustomDashboard,\n route: '/admin',\n })\n\n expect(result).toBe(false)\n })\n\n it('should not match collection routes as custom dashboard views when dashboard path is \"/\"', () => {\n const result = isCustomAdminView({\n adminRoute,\n config: configWithCustomDashboard,\n route: '/admin/collections/tickets',\n })\n\n expect(result).toBe(false)\n })\n\n it('should not match document routes as custom dashboard views when dashboard path is \"/\"', () => {\n const result = isCustomAdminView({\n adminRoute,\n config: configWithCustomDashboard,\n route: '/admin/collections/tickets/123',\n })\n\n expect(result).toBe(false)\n })\n\n it('should return false when no custom views are configured', () => {\n const config = {} as SanitizedConfig\n\n const result = isCustomAdminView({\n adminRoute,\n config,\n route: '/admin/collections/tickets',\n })\n\n expect(result).toBe(false)\n })\n\n it('should return true for a custom view with a non-root path', () => {\n const config = {\n admin: {\n components: {\n views: {\n myCustomView: {\n path: '/my-custom-view',\n },\n },\n },\n },\n } as unknown as SanitizedConfig\n\n const result = isCustomAdminView({\n adminRoute,\n config,\n route: '/admin/my-custom-view',\n })\n\n expect(result).toBe(true)\n })\n\n it('should not match collection routes when a non-root custom view path is set', () => {\n const config = {\n admin: {\n components: {\n views: {\n myCustomView: {\n path: '/my-custom-view',\n },\n },\n },\n },\n } as unknown as SanitizedConfig\n\n const result = isCustomAdminView({\n adminRoute,\n config,\n route: '/admin/collections/tickets',\n })\n\n expect(result).toBe(false)\n })\n})\n"],"mappings":"AAEA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ;AAErC,SAASC,iBAAiB,QAAQ;AAElCH,QAAA,CAAS,qBAAqB;EAC5B,MAAMI,UAAA,GAAa;EAEnB,MAAMC,yBAAA,GAA4B;IAChCC,KAAA,EAAO;MACLC,UAAA,EAAY;QACVC,KAAA,EAAO;UACLC,SAAA,EAAW;YACTC,IAAA,EAAM;UACR;QACF;MACF;IACF;EACF;EAEAR,EAAA,CAAG,6FAA6F;IAC9F;IACA;IACA,MAAMS,MAAA,GAASR,iBAAA,CAAkB;MAC/BC,UAAA;MACAQ,MAAA,EAAQP,yBAAA;MACRQ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