payload 4.0.0-internal.cd69eef → 4.0.0-internal.d1cc1d3
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/dist/admin/RichText.d.ts +1 -1
- package/dist/admin/RichText.d.ts.map +1 -1
- package/dist/admin/RichText.js.map +1 -1
- package/dist/admin/functions/index.d.ts +10 -8
- package/dist/admin/functions/index.d.ts.map +1 -1
- package/dist/admin/functions/index.js.map +1 -1
- package/dist/admin/types.d.ts +2 -2
- package/dist/admin/types.d.ts.map +1 -1
- package/dist/admin/types.js.map +1 -1
- package/dist/auth/endpoints/login.d.ts.map +1 -1
- package/dist/auth/endpoints/login.js +2 -11
- package/dist/auth/endpoints/login.js.map +1 -1
- package/dist/auth/loginWithCookie.d.ts +33 -0
- package/dist/auth/loginWithCookie.d.ts.map +1 -0
- package/dist/auth/loginWithCookie.js +34 -0
- package/dist/auth/loginWithCookie.js.map +1 -0
- package/dist/auth/serverFunctions/cookies.d.ts +47 -0
- package/dist/auth/serverFunctions/cookies.d.ts.map +1 -0
- package/dist/auth/serverFunctions/cookies.js +52 -0
- package/dist/auth/serverFunctions/cookies.js.map +1 -0
- package/dist/auth/serverFunctions/login.d.ts +29 -0
- package/dist/auth/serverFunctions/login.d.ts.map +1 -0
- package/dist/auth/serverFunctions/login.js +63 -0
- package/dist/auth/serverFunctions/login.js.map +1 -0
- package/dist/auth/serverFunctions/logout.d.ts +17 -0
- package/dist/auth/serverFunctions/logout.d.ts.map +1 -0
- package/dist/auth/serverFunctions/logout.js +58 -0
- package/dist/auth/serverFunctions/logout.js.map +1 -0
- package/dist/auth/serverFunctions/refresh.d.ts +17 -0
- package/dist/auth/serverFunctions/refresh.d.ts.map +1 -0
- package/dist/auth/serverFunctions/refresh.js +61 -0
- package/dist/auth/serverFunctions/refresh.js.map +1 -0
- package/dist/collections/config/client.d.ts +2 -3
- package/dist/collections/config/client.d.ts.map +1 -1
- package/dist/collections/config/client.js +5 -7
- package/dist/collections/config/client.js.map +1 -1
- package/dist/collections/config/defaults.d.ts.map +1 -1
- package/dist/collections/config/defaults.js +1 -0
- package/dist/collections/config/defaults.js.map +1 -1
- package/dist/collections/config/sanitize.d.ts +3 -8
- package/dist/collections/config/sanitize.d.ts.map +1 -1
- package/dist/collections/config/sanitize.js +2 -6
- package/dist/collections/config/sanitize.js.map +1 -1
- package/dist/collections/config/types.d.ts +1 -1
- package/dist/collections/config/types.d.ts.map +1 -1
- package/dist/collections/config/types.js.map +1 -1
- package/dist/collections/config/useAsTitle.spec.js +27 -27
- package/dist/collections/config/useAsTitle.spec.js.map +1 -1
- package/dist/collections/operations/create.d.ts.map +1 -1
- package/dist/collections/operations/create.js +10 -0
- package/dist/collections/operations/create.js.map +1 -1
- package/dist/collections/operations/restoreVersion.d.ts.map +1 -1
- package/dist/collections/operations/restoreVersion.js +7 -4
- package/dist/collections/operations/restoreVersion.js.map +1 -1
- package/dist/collections/operations/updateByID.js +1 -0
- package/dist/collections/operations/updateByID.js.map +1 -1
- package/dist/config/build.js +1 -1
- package/dist/config/build.js.map +1 -1
- package/dist/config/defaults.d.ts.map +1 -1
- package/dist/config/defaults.js +5 -2
- package/dist/config/defaults.js.map +1 -1
- package/dist/config/orderable/index.d.ts +1 -1
- package/dist/config/orderable/index.d.ts.map +1 -1
- package/dist/config/orderable/index.js +2 -2
- package/dist/config/orderable/index.js.map +1 -1
- package/dist/config/sanitize.d.ts +1 -1
- package/dist/config/sanitize.d.ts.map +1 -1
- package/dist/config/sanitize.js +33 -40
- package/dist/config/sanitize.js.map +1 -1
- package/dist/config/types.d.ts +1 -1
- package/dist/config/types.js.map +1 -1
- package/dist/database/createDatabaseAdapter.d.ts +1 -1
- package/dist/database/createDatabaseAdapter.d.ts.map +1 -1
- package/dist/database/createDatabaseAdapter.js +0 -2
- package/dist/database/createDatabaseAdapter.js.map +1 -1
- package/dist/database/types.d.ts +6 -0
- package/dist/database/types.d.ts.map +1 -1
- package/dist/database/types.js.map +1 -1
- package/dist/exports/auth.d.ts +5 -0
- package/dist/exports/auth.d.ts.map +1 -0
- package/dist/exports/auth.js +6 -0
- package/dist/exports/auth.js.map +1 -0
- package/dist/exports/internal.d.ts +2 -0
- package/dist/exports/internal.d.ts.map +1 -1
- package/dist/exports/internal.js +3 -1
- package/dist/exports/internal.js.map +1 -1
- package/dist/fields/baseFields/slug/duplicateContext.d.ts +11 -0
- package/dist/fields/baseFields/slug/duplicateContext.d.ts.map +1 -0
- package/dist/fields/baseFields/slug/duplicateContext.js +21 -0
- package/dist/fields/baseFields/slug/duplicateContext.js.map +1 -0
- package/dist/fields/baseFields/slug/fillEmptyLocalizedSlugs.d.ts +22 -0
- package/dist/fields/baseFields/slug/fillEmptyLocalizedSlugs.d.ts.map +1 -0
- package/dist/fields/baseFields/slug/fillEmptyLocalizedSlugs.js +63 -0
- package/dist/fields/baseFields/slug/fillEmptyLocalizedSlugs.js.map +1 -0
- package/dist/fields/baseFields/slug/generateSlug.d.ts +13 -8
- package/dist/fields/baseFields/slug/generateSlug.d.ts.map +1 -1
- package/dist/fields/baseFields/slug/generateSlug.js +98 -45
- package/dist/fields/baseFields/slug/generateSlug.js.map +1 -1
- package/dist/fields/baseFields/slug/generateSlugBeforeDuplicate.d.ts +18 -0
- package/dist/fields/baseFields/slug/generateSlugBeforeDuplicate.d.ts.map +1 -0
- package/dist/fields/baseFields/slug/generateSlugBeforeDuplicate.js +20 -0
- package/dist/fields/baseFields/slug/generateSlugBeforeDuplicate.js.map +1 -0
- package/dist/fields/baseFields/slug/getSlugFallbackValue.d.ts +22 -0
- package/dist/fields/baseFields/slug/getSlugFallbackValue.d.ts.map +1 -0
- package/dist/fields/baseFields/slug/getSlugFallbackValue.js +23 -0
- package/dist/fields/baseFields/slug/getSlugFallbackValue.js.map +1 -0
- package/dist/fields/baseFields/slug/hasValue.d.ts +3 -0
- package/dist/fields/baseFields/slug/hasValue.d.ts.map +1 -0
- package/dist/fields/baseFields/slug/hasValue.js +3 -0
- package/dist/fields/baseFields/slug/hasValue.js.map +1 -0
- package/dist/fields/config/reservedFieldNames.spec.js +18 -18
- package/dist/fields/config/reservedFieldNames.spec.js.map +1 -1
- package/dist/fields/config/sanitize.d.ts +3 -9
- package/dist/fields/config/sanitize.d.ts.map +1 -1
- package/dist/fields/config/sanitize.js +33 -34
- package/dist/fields/config/sanitize.js.map +1 -1
- package/dist/fields/config/sanitize.spec.js +128 -105
- package/dist/fields/config/sanitize.spec.js.map +1 -1
- package/dist/fields/config/types.d.ts +4 -3
- package/dist/fields/config/types.d.ts.map +1 -1
- package/dist/fields/config/types.js.map +1 -1
- package/dist/fields/hooks/beforeValidate/promise.d.ts.map +1 -1
- package/dist/fields/hooks/beforeValidate/promise.js +5 -3
- package/dist/fields/hooks/beforeValidate/promise.js.map +1 -1
- package/dist/fields/hooks/beforeValidate/stripNullRows.d.ts +10 -0
- package/dist/fields/hooks/beforeValidate/stripNullRows.d.ts.map +1 -0
- package/dist/fields/hooks/beforeValidate/stripNullRows.js +18 -0
- package/dist/fields/hooks/beforeValidate/stripNullRows.js.map +1 -0
- package/dist/fields/validations.d.ts.map +1 -1
- package/dist/fields/validations.js +7 -8
- package/dist/fields/validations.js.map +1 -1
- package/dist/fields/validations.spec.js +61 -37
- package/dist/fields/validations.spec.js.map +1 -1
- package/dist/globals/config/sanitize.d.ts +2 -7
- package/dist/globals/config/sanitize.d.ts.map +1 -1
- package/dist/globals/config/sanitize.js +2 -6
- package/dist/globals/config/sanitize.js.map +1 -1
- package/dist/globals/config/sanitize.spec.js +6 -6
- package/dist/globals/config/sanitize.spec.js.map +1 -1
- package/dist/globals/operations/countGlobalVersions.d.ts.map +1 -1
- package/dist/globals/operations/countGlobalVersions.js +1 -0
- package/dist/globals/operations/countGlobalVersions.js.map +1 -1
- package/dist/index.bundled.d.ts +247 -178
- package/dist/index.d.ts +49 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/query-presets/constraints.js +1 -1
- package/dist/query-presets/constraints.js.map +1 -1
- package/dist/queues/config/collection.d.ts.map +1 -1
- package/dist/queues/config/collection.js +37 -43
- package/dist/queues/config/collection.js.map +1 -1
- package/dist/queues/config/global.d.ts +5 -6
- package/dist/queues/config/global.d.ts.map +1 -1
- package/dist/queues/config/global.js +1 -1
- package/dist/queues/config/global.js.map +1 -1
- package/dist/queues/config/types/index.d.ts +29 -24
- package/dist/queues/config/types/index.d.ts.map +1 -1
- package/dist/queues/config/types/index.js.map +1 -1
- package/dist/queues/config/types/taskTypes.d.ts +4 -7
- package/dist/queues/config/types/taskTypes.d.ts.map +1 -1
- package/dist/queues/config/types/taskTypes.js.map +1 -1
- package/dist/queues/config/types/workflowJSONTypes.d.ts +10 -9
- package/dist/queues/config/types/workflowJSONTypes.d.ts.map +1 -1
- package/dist/queues/config/types/workflowJSONTypes.js.map +1 -1
- package/dist/queues/config/types/workflowTypes.d.ts +11 -58
- package/dist/queues/config/types/workflowTypes.d.ts.map +1 -1
- package/dist/queues/config/types/workflowTypes.js.map +1 -1
- package/dist/queues/endpoints/handleSchedules.js +1 -1
- package/dist/queues/endpoints/handleSchedules.js.map +1 -1
- package/dist/queues/errors/handleTaskError.js +4 -4
- package/dist/queues/errors/handleTaskError.js.map +1 -1
- package/dist/queues/errors/handleWorkflowError.js +1 -1
- package/dist/queues/errors/handleWorkflowError.js.map +1 -1
- package/dist/queues/errors/index.d.ts +6 -0
- package/dist/queues/errors/index.d.ts.map +1 -1
- package/dist/queues/errors/index.js +5 -0
- package/dist/queues/errors/index.js.map +1 -1
- package/dist/queues/localAPI.d.ts +4 -4
- package/dist/queues/localAPI.d.ts.map +1 -1
- package/dist/queues/localAPI.js +63 -66
- package/dist/queues/localAPI.js.map +1 -1
- package/dist/queues/operations/handleSchedules/countRunnableOrActiveJobsForQueue.d.ts +4 -4
- package/dist/queues/operations/handleSchedules/countRunnableOrActiveJobsForQueue.d.ts.map +1 -1
- package/dist/queues/operations/handleSchedules/countRunnableOrActiveJobsForQueue.js.map +1 -1
- package/dist/queues/operations/handleSchedules/index.d.ts +1 -1
- package/dist/queues/operations/handleSchedules/index.d.ts.map +1 -1
- package/dist/queues/operations/handleSchedules/index.js +1 -1
- package/dist/queues/operations/handleSchedules/index.js.map +1 -1
- package/dist/queues/operations/runJobs/heartbeat.d.ts +13 -0
- package/dist/queues/operations/runJobs/heartbeat.d.ts.map +1 -0
- package/dist/queues/operations/runJobs/heartbeat.js +66 -0
- package/dist/queues/operations/runJobs/heartbeat.js.map +1 -0
- package/dist/queues/operations/runJobs/index.d.ts.map +1 -1
- package/dist/queues/operations/runJobs/index.js +133 -84
- package/dist/queues/operations/runJobs/index.js.map +1 -1
- package/dist/queues/operations/runJobs/runJSONJob/index.d.ts.map +1 -1
- package/dist/queues/operations/runJobs/runJSONJob/index.js +6 -3
- package/dist/queues/operations/runJobs/runJSONJob/index.js.map +1 -1
- package/dist/queues/operations/runJobs/runJob/getRunTaskFunction.js +5 -5
- package/dist/queues/operations/runJobs/runJob/getRunTaskFunction.js.map +1 -1
- package/dist/queues/operations/runJobs/runJob/getUpdateJobFunction.d.ts +2 -1
- package/dist/queues/operations/runJobs/runJob/getUpdateJobFunction.d.ts.map +1 -1
- package/dist/queues/operations/runJobs/runJob/getUpdateJobFunction.js +39 -8
- package/dist/queues/operations/runJobs/runJob/getUpdateJobFunction.js.map +1 -1
- package/dist/queues/operations/runJobs/runJob/importHandlerPath.js.map +1 -1
- package/dist/queues/operations/runJobs/runJob/index.d.ts.map +1 -1
- package/dist/queues/operations/runJobs/runJob/index.js +4 -4
- package/dist/queues/operations/runJobs/runJob/index.js.map +1 -1
- package/dist/queues/utilities/updateJob.d.ts.map +1 -1
- package/dist/queues/utilities/updateJob.js +3 -0
- package/dist/queues/utilities/updateJob.js.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/uploads/checkFileRestrictions.d.ts +1 -1
- package/dist/uploads/checkFileRestrictions.d.ts.map +1 -1
- package/dist/uploads/checkFileRestrictions.js +15 -1
- package/dist/uploads/checkFileRestrictions.js.map +1 -1
- package/dist/uploads/endpoints/uploadInstructions.d.ts +12 -0
- package/dist/uploads/endpoints/uploadInstructions.d.ts.map +1 -1
- package/dist/uploads/endpoints/uploadInstructions.js +66 -20
- package/dist/uploads/endpoints/uploadInstructions.js.map +1 -1
- package/dist/uploads/generateFileData.js +4 -1
- package/dist/uploads/generateFileData.js.map +1 -1
- package/dist/uploads/getFileFromUploadInstructions.d.ts +8 -0
- package/dist/uploads/getFileFromUploadInstructions.d.ts.map +1 -0
- package/dist/uploads/getFileFromUploadInstructions.js +62 -0
- package/dist/uploads/getFileFromUploadInstructions.js.map +1 -0
- package/dist/uploads/getImageSize.d.ts +12 -1
- package/dist/uploads/getImageSize.d.ts.map +1 -1
- package/dist/uploads/getImageSize.js +20 -18
- package/dist/uploads/getImageSize.js.map +1 -1
- package/dist/uploads/getImageSize.spec.js +298 -0
- package/dist/uploads/getImageSize.spec.js.map +1 -0
- package/dist/uploads/probeImageSize.d.ts +39 -0
- package/dist/uploads/probeImageSize.d.ts.map +1 -0
- package/dist/uploads/probeImageSize.js +374 -0
- package/dist/uploads/probeImageSize.js.map +1 -0
- package/dist/uploads/probeImageSize.spec.js +366 -0
- package/dist/uploads/probeImageSize.spec.js.map +1 -0
- package/dist/uploads/stagedUpload.d.ts +27 -0
- package/dist/uploads/stagedUpload.d.ts.map +1 -0
- package/dist/uploads/stagedUpload.js +197 -0
- package/dist/uploads/stagedUpload.js.map +1 -0
- package/dist/uploads/types.d.ts +41 -13
- package/dist/uploads/types.d.ts.map +1 -1
- package/dist/uploads/types.js.map +1 -1
- package/dist/utilities/addDataAndFileToRequest.d.ts.map +1 -1
- package/dist/utilities/addDataAndFileToRequest.js +12 -46
- package/dist/utilities/addDataAndFileToRequest.js.map +1 -1
- package/dist/utilities/configToJSONSchema.spec.js +33 -33
- package/dist/utilities/configToJSONSchema.spec.js.map +1 -1
- package/dist/utilities/fieldValueExists.d.ts +29 -0
- package/dist/utilities/fieldValueExists.d.ts.map +1 -0
- package/dist/utilities/fieldValueExists.js +27 -0
- package/dist/utilities/fieldValueExists.js.map +1 -0
- package/dist/utilities/getUniqueFieldValue.d.ts +27 -0
- package/dist/utilities/getUniqueFieldValue.d.ts.map +1 -0
- package/dist/utilities/getUniqueFieldValue.js +26 -0
- package/dist/utilities/getUniqueFieldValue.js.map +1 -0
- package/dist/versions/deleteScheduledPublishJobs.js +2 -2
- package/dist/versions/deleteScheduledPublishJobs.js.map +1 -1
- package/dist/versions/payloadPackageList.d.ts.map +1 -1
- package/dist/versions/payloadPackageList.js +0 -1
- package/dist/versions/payloadPackageList.js.map +1 -1
- package/package.json +8 -3
- package/dist/database/defaultUpdateJobs.d.ts +0 -3
- package/dist/database/defaultUpdateJobs.d.ts.map +0 -1
- package/dist/database/defaultUpdateJobs.js +0 -41
- package/dist/database/defaultUpdateJobs.js.map +0 -1
- package/dist/fields/baseFields/slug/countVersions.d.ts +0 -13
- package/dist/fields/baseFields/slug/countVersions.d.ts.map +0 -1
- package/dist/fields/baseFields/slug/countVersions.js +0 -27
- package/dist/fields/baseFields/slug/countVersions.js.map +0 -1
- package/dist/uploads/tempFile.d.ts +0 -7
- package/dist/uploads/tempFile.d.ts.map +0 -1
- package/dist/uploads/tempFile.js +0 -39
- package/dist/uploads/tempFile.js.map +0 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { generateExpiredPayloadCookie, generatePayloadCookie } from '../cookies.js';
|
|
2
|
+
// `generateCookie` emits capitalized `SameSite` values (as they appear in the
|
|
3
|
+
// header); `CookieOptions` takes the lowercase form.
|
|
4
|
+
const toCookieOptions = (cookie)=>({
|
|
5
|
+
domain: cookie.domain,
|
|
6
|
+
expires: cookie.expires ? new Date(cookie.expires) : undefined,
|
|
7
|
+
httpOnly: cookie.httpOnly,
|
|
8
|
+
maxAge: cookie.maxAge,
|
|
9
|
+
path: cookie.path,
|
|
10
|
+
sameSite: cookie.sameSite?.toLowerCase(),
|
|
11
|
+
secure: cookie.secure
|
|
12
|
+
});
|
|
13
|
+
/** Writes an already-generated cookie through the framework's cookie API. */ export async function applyAuthCookie({ cookie, serverAdapter }) {
|
|
14
|
+
if (!cookie.value) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
await serverAdapter.setCookie(cookie.name, cookie.value, toCookieOptions(cookie));
|
|
18
|
+
}
|
|
19
|
+
/** Writes the Payload auth cookie for `token` through the framework's cookie API. */ export async function setAuthCookie({ authConfig, cookiePrefix, serverAdapter, token }) {
|
|
20
|
+
const cookie = generatePayloadCookie({
|
|
21
|
+
collectionAuthConfig: authConfig,
|
|
22
|
+
cookiePrefix,
|
|
23
|
+
returnCookieAsObject: true,
|
|
24
|
+
token
|
|
25
|
+
});
|
|
26
|
+
await applyAuthCookie({
|
|
27
|
+
cookie,
|
|
28
|
+
serverAdapter
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Expires the Payload auth cookie. Written with the same `domain`/`path`/`secure`
|
|
33
|
+
* attributes it was set with — a mismatched `domain` leaves the original cookie
|
|
34
|
+
* in place.
|
|
35
|
+
*/ export async function clearAuthCookie({ authConfig, cookiePrefix, serverAdapter }) {
|
|
36
|
+
const cookie = generateExpiredPayloadCookie({
|
|
37
|
+
collectionAuthConfig: authConfig,
|
|
38
|
+
cookiePrefix,
|
|
39
|
+
returnCookieAsObject: true
|
|
40
|
+
});
|
|
41
|
+
await serverAdapter.setCookie(cookie.name, '', toCookieOptions(cookie));
|
|
42
|
+
}
|
|
43
|
+
/** Reads the request's existing Payload auth cookie, if any. */ export async function getExistingAuthToken({ cookiePrefix, serverAdapter }) {
|
|
44
|
+
const store = await serverAdapter.getCookies();
|
|
45
|
+
const allCookies = store.getAll?.();
|
|
46
|
+
if (allCookies) {
|
|
47
|
+
return allCookies.find((cookie)=>cookie.name.startsWith(cookiePrefix));
|
|
48
|
+
}
|
|
49
|
+
return store.get(`${cookiePrefix}-token`) ?? undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=cookies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/auth/serverFunctions/cookies.ts"],"sourcesContent":["import type { CookieOptions } from '../../admin/adapters/cookies.js'\nimport type { ServerAdapter } from '../../admin/adapters/server.js'\nimport type { Auth } from '../types.js'\n\nimport { generateExpiredPayloadCookie, generatePayloadCookie } from '../cookies.js'\n\n/**\n * Object form returned by `generatePayloadCookie`/`generateExpiredPayloadCookie`\n * when `returnCookieAsObject` is `true`.\n */\nexport type GeneratedCookie = {\n domain?: string\n expires?: string\n httpOnly?: boolean\n maxAge?: number\n name: string\n path?: string\n sameSite?: 'Lax' | 'None' | 'Strict'\n secure?: boolean\n value: string | undefined\n}\n\n// `generateCookie` emits capitalized `SameSite` values (as they appear in the\n// header); `CookieOptions` takes the lowercase form.\nconst toCookieOptions = (cookie: GeneratedCookie): CookieOptions => ({\n domain: cookie.domain,\n expires: cookie.expires ? new Date(cookie.expires) : undefined,\n httpOnly: cookie.httpOnly,\n maxAge: cookie.maxAge,\n path: cookie.path,\n sameSite: cookie.sameSite?.toLowerCase() as CookieOptions['sameSite'],\n secure: cookie.secure,\n})\n\ntype AuthCookieArgs = {\n authConfig: Auth\n cookiePrefix: string\n serverAdapter: ServerAdapter\n}\n\n/** Writes an already-generated cookie through the framework's cookie API. */\nexport async function applyAuthCookie({\n cookie,\n serverAdapter,\n}: {\n cookie: GeneratedCookie\n serverAdapter: ServerAdapter\n}): Promise<void> {\n if (!cookie.value) {\n return\n }\n\n await serverAdapter.setCookie(cookie.name, cookie.value, toCookieOptions(cookie))\n}\n\n/** Writes the Payload auth cookie for `token` through the framework's cookie API. */\nexport async function setAuthCookie({\n authConfig,\n cookiePrefix,\n serverAdapter,\n token,\n}: { token: string } & AuthCookieArgs): Promise<void> {\n const cookie = generatePayloadCookie({\n collectionAuthConfig: authConfig,\n cookiePrefix,\n returnCookieAsObject: true,\n token,\n }) as GeneratedCookie\n\n await applyAuthCookie({ cookie, serverAdapter })\n}\n\n/**\n * Expires the Payload auth cookie. Written with the same `domain`/`path`/`secure`\n * attributes it was set with — a mismatched `domain` leaves the original cookie\n * in place.\n */\nexport async function clearAuthCookie({\n authConfig,\n cookiePrefix,\n serverAdapter,\n}: AuthCookieArgs): Promise<void> {\n const cookie = generateExpiredPayloadCookie({\n collectionAuthConfig: authConfig,\n cookiePrefix,\n returnCookieAsObject: true,\n }) as GeneratedCookie\n\n await serverAdapter.setCookie(cookie.name, '', toCookieOptions(cookie))\n}\n\n/** Reads the request's existing Payload auth cookie, if any. */\nexport async function getExistingAuthToken({\n cookiePrefix,\n serverAdapter,\n}: {\n cookiePrefix: string\n serverAdapter: ServerAdapter\n}): Promise<{ name: string; value: string } | undefined> {\n const store = await serverAdapter.getCookies()\n const allCookies = store.getAll?.()\n\n if (allCookies) {\n return allCookies.find((cookie) => cookie.name.startsWith(cookiePrefix))\n }\n\n return store.get(`${cookiePrefix}-token`) ?? undefined\n}\n"],"names":["generateExpiredPayloadCookie","generatePayloadCookie","toCookieOptions","cookie","domain","expires","Date","undefined","httpOnly","maxAge","path","sameSite","toLowerCase","secure","applyAuthCookie","serverAdapter","value","setCookie","name","setAuthCookie","authConfig","cookiePrefix","token","collectionAuthConfig","returnCookieAsObject","clearAuthCookie","getExistingAuthToken","store","getCookies","allCookies","getAll","find","startsWith","get"],"mappings":"AAIA,SAASA,4BAA4B,EAAEC,qBAAqB,QAAQ,gBAAe;AAkBnF,8EAA8E;AAC9E,qDAAqD;AACrD,MAAMC,kBAAkB,CAACC,SAA4C,CAAA;QACnEC,QAAQD,OAAOC,MAAM;QACrBC,SAASF,OAAOE,OAAO,GAAG,IAAIC,KAAKH,OAAOE,OAAO,IAAIE;QACrDC,UAAUL,OAAOK,QAAQ;QACzBC,QAAQN,OAAOM,MAAM;QACrBC,MAAMP,OAAOO,IAAI;QACjBC,UAAUR,OAAOQ,QAAQ,EAAEC;QAC3BC,QAAQV,OAAOU,MAAM;IACvB,CAAA;AAQA,2EAA2E,GAC3E,OAAO,eAAeC,gBAAgB,EACpCX,MAAM,EACNY,aAAa,EAId;IACC,IAAI,CAACZ,OAAOa,KAAK,EAAE;QACjB;IACF;IAEA,MAAMD,cAAcE,SAAS,CAACd,OAAOe,IAAI,EAAEf,OAAOa,KAAK,EAAEd,gBAAgBC;AAC3E;AAEA,mFAAmF,GACnF,OAAO,eAAegB,cAAc,EAClCC,UAAU,EACVC,YAAY,EACZN,aAAa,EACbO,KAAK,EAC8B;IACnC,MAAMnB,SAASF,sBAAsB;QACnCsB,sBAAsBH;QACtBC;QACAG,sBAAsB;QACtBF;IACF;IAEA,MAAMR,gBAAgB;QAAEX;QAAQY;IAAc;AAChD;AAEA;;;;CAIC,GACD,OAAO,eAAeU,gBAAgB,EACpCL,UAAU,EACVC,YAAY,EACZN,aAAa,EACE;IACf,MAAMZ,SAASH,6BAA6B;QAC1CuB,sBAAsBH;QACtBC;QACAG,sBAAsB;IACxB;IAEA,MAAMT,cAAcE,SAAS,CAACd,OAAOe,IAAI,EAAE,IAAIhB,gBAAgBC;AACjE;AAEA,8DAA8D,GAC9D,OAAO,eAAeuB,qBAAqB,EACzCL,YAAY,EACZN,aAAa,EAId;IACC,MAAMY,QAAQ,MAAMZ,cAAca,UAAU;IAC5C,MAAMC,aAAaF,MAAMG,MAAM;IAE/B,IAAID,YAAY;QACd,OAAOA,WAAWE,IAAI,CAAC,CAAC5B,SAAWA,OAAOe,IAAI,CAACc,UAAU,CAACX;IAC5D;IAEA,OAAOM,MAAMM,GAAG,CAAC,GAAGZ,aAAa,MAAM,CAAC,KAAKd;AAC/C"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ServerAdapter } from '../../admin/adapters/server.js';
|
|
2
|
+
import type { SanitizedConfig } from '../../config/types.js';
|
|
3
|
+
import type { AuthCollectionSlug } from '../../index.js';
|
|
4
|
+
import type { MaybePromise } from '../../types/index.js';
|
|
5
|
+
import type { LoginResult } from '../operations/login.js';
|
|
6
|
+
export type LoginArgs<TSlug extends AuthCollectionSlug> = {
|
|
7
|
+
collection: TSlug;
|
|
8
|
+
config: MaybePromise<SanitizedConfig>;
|
|
9
|
+
password: string;
|
|
10
|
+
serverAdapter: ServerAdapter;
|
|
11
|
+
} & ({
|
|
12
|
+
email: string;
|
|
13
|
+
username?: never;
|
|
14
|
+
} | {
|
|
15
|
+
email?: never;
|
|
16
|
+
username: string;
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* `LoginArgs` as the adapters expose it — they bind `serverAdapter` themselves.
|
|
20
|
+
* Distributes over the email/username union so the either-or survives; a plain
|
|
21
|
+
* `Omit` collapses the union and accepts both keys at once.
|
|
22
|
+
*/
|
|
23
|
+
export type LoginArgsWithoutServerAdapter<TSlug extends AuthCollectionSlug> = LoginArgs<TSlug> extends infer TArgs ? TArgs extends unknown ? Omit<TArgs, 'serverAdapter'> : never : never;
|
|
24
|
+
/**
|
|
25
|
+
* Logs a user in and writes the auth cookie through the supplied `serverAdapter`,
|
|
26
|
+
* so the function is framework-agnostic; each adapter binds its own.
|
|
27
|
+
*/
|
|
28
|
+
export declare function login<TSlug extends AuthCollectionSlug>({ collection, config, email, password, serverAdapter, username, }: LoginArgs<TSlug>): Promise<LoginResult<TSlug>>;
|
|
29
|
+
//# sourceMappingURL=login.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../../src/auth/serverFunctions/login.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAA;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAC5D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAOzD,MAAM,MAAM,SAAS,CAAC,KAAK,SAAS,kBAAkB,IAAI;IACxD,UAAU,EAAE,KAAK,CAAA;IACjB,MAAM,EAAE,YAAY,CAAC,eAAe,CAAC,CAAA;IACrC,QAAQ,EAAE,MAAM,CAAA;IAChB,aAAa,EAAE,aAAa,CAAA;CAC7B,GAAG,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,KAAK,CAAA;CAAE,GAAG;IAAE,KAAK,CAAC,EAAE,KAAK,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAAA;AAE/E;;;;GAIG;AACH,MAAM,MAAM,6BAA6B,CAAC,KAAK,SAAS,kBAAkB,IACxE,SAAS,CAAC,KAAK,CAAC,SAAS,MAAM,KAAK,GAChC,KAAK,SAAS,OAAO,GACnB,IAAI,CAAC,KAAK,EAAE,eAAe,CAAC,GAC5B,KAAK,GACP,KAAK,CAAA;AAEX;;;GAGG;AACH,wBAAsB,KAAK,CAAC,KAAK,SAAS,kBAAkB,EAAE,EAC5D,UAAU,EACV,MAAM,EACN,KAAK,EACL,QAAQ,EACR,aAAa,EACb,QAAQ,GACT,EAAE,SAAS,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAgDhD"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { getPayload } from '../../index.js';
|
|
2
|
+
import { createLocalReq } from '../../utilities/createLocalReq.js';
|
|
3
|
+
import { loginWithCookie } from '../loginWithCookie.js';
|
|
4
|
+
import { applyAuthCookie } from './cookies.js';
|
|
5
|
+
/**
|
|
6
|
+
* Logs a user in and writes the auth cookie through the supplied `serverAdapter`,
|
|
7
|
+
* so the function is framework-agnostic; each adapter binds its own.
|
|
8
|
+
*/ export async function login({ collection, config, email, password, serverAdapter, username }) {
|
|
9
|
+
const payload = await getPayload({
|
|
10
|
+
config,
|
|
11
|
+
cron: true
|
|
12
|
+
});
|
|
13
|
+
const authConfig = payload.collections[collection]?.config.auth;
|
|
14
|
+
if (!authConfig) {
|
|
15
|
+
throw new Error(`No auth config found for collection: ${collection}`);
|
|
16
|
+
}
|
|
17
|
+
const loginWithUsername = authConfig.loginWithUsername ?? false;
|
|
18
|
+
if (loginWithUsername) {
|
|
19
|
+
if (loginWithUsername.allowEmailLogin) {
|
|
20
|
+
if (!email && !username) {
|
|
21
|
+
throw new Error('Email or username is required.');
|
|
22
|
+
}
|
|
23
|
+
} else {
|
|
24
|
+
if (!username) {
|
|
25
|
+
throw new Error('Username is required.');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
} else {
|
|
29
|
+
if (!email) {
|
|
30
|
+
throw new Error('Email is required.');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
let loginData;
|
|
34
|
+
if (loginWithUsername) {
|
|
35
|
+
loginData = username ? {
|
|
36
|
+
password,
|
|
37
|
+
username
|
|
38
|
+
} : {
|
|
39
|
+
email,
|
|
40
|
+
password
|
|
41
|
+
};
|
|
42
|
+
} else {
|
|
43
|
+
loginData = {
|
|
44
|
+
email,
|
|
45
|
+
password
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const collectionConfig = payload.collections[collection];
|
|
49
|
+
const { cookie, result } = await loginWithCookie({
|
|
50
|
+
collection: collectionConfig,
|
|
51
|
+
data: loginData,
|
|
52
|
+
overrideAccess: true,
|
|
53
|
+
req: await createLocalReq({}, payload),
|
|
54
|
+
returnCookieAsObject: true
|
|
55
|
+
});
|
|
56
|
+
await applyAuthCookie({
|
|
57
|
+
cookie,
|
|
58
|
+
serverAdapter
|
|
59
|
+
});
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
//# sourceMappingURL=login.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/auth/serverFunctions/login.ts"],"sourcesContent":["import type { ServerAdapter } from '../../admin/adapters/server.js'\nimport type { SanitizedConfig } from '../../config/types.js'\nimport type { AuthCollectionSlug } from '../../index.js'\nimport type { MaybePromise } from '../../types/index.js'\nimport type { LoginResult } from '../operations/login.js'\n\nimport { getPayload } from '../../index.js'\nimport { createLocalReq } from '../../utilities/createLocalReq.js'\nimport { loginWithCookie } from '../loginWithCookie.js'\nimport { applyAuthCookie } from './cookies.js'\n\nexport type LoginArgs<TSlug extends AuthCollectionSlug> = {\n collection: TSlug\n config: MaybePromise<SanitizedConfig>\n password: string\n serverAdapter: ServerAdapter\n} & ({ email: string; username?: never } | { email?: never; username: string })\n\n/**\n * `LoginArgs` as the adapters expose it — they bind `serverAdapter` themselves.\n * Distributes over the email/username union so the either-or survives; a plain\n * `Omit` collapses the union and accepts both keys at once.\n */\nexport type LoginArgsWithoutServerAdapter<TSlug extends AuthCollectionSlug> =\n LoginArgs<TSlug> extends infer TArgs\n ? TArgs extends unknown\n ? Omit<TArgs, 'serverAdapter'>\n : never\n : never\n\n/**\n * Logs a user in and writes the auth cookie through the supplied `serverAdapter`,\n * so the function is framework-agnostic; each adapter binds its own.\n */\nexport async function login<TSlug extends AuthCollectionSlug>({\n collection,\n config,\n email,\n password,\n serverAdapter,\n username,\n}: LoginArgs<TSlug>): Promise<LoginResult<TSlug>> {\n const payload = await getPayload({ config, cron: true })\n\n const authConfig = payload.collections[collection]?.config.auth\n\n if (!authConfig) {\n throw new Error(`No auth config found for collection: ${collection}`)\n }\n\n const loginWithUsername = authConfig.loginWithUsername ?? false\n\n if (loginWithUsername) {\n if (loginWithUsername.allowEmailLogin) {\n if (!email && !username) {\n throw new Error('Email or username is required.')\n }\n } else {\n if (!username) {\n throw new Error('Username is required.')\n }\n }\n } else {\n if (!email) {\n throw new Error('Email is required.')\n }\n }\n\n let loginData\n\n if (loginWithUsername) {\n loginData = username ? { password, username } : { email, password }\n } else {\n loginData = { email, password }\n }\n\n const collectionConfig = payload.collections[collection]!\n\n const { cookie, result } = await loginWithCookie({\n collection: collectionConfig,\n data: loginData as Parameters<typeof loginWithCookie>[0]['data'],\n overrideAccess: true,\n req: await createLocalReq({}, payload),\n returnCookieAsObject: true,\n })\n\n await applyAuthCookie({ cookie, serverAdapter })\n\n return result as LoginResult<TSlug>\n}\n"],"names":["getPayload","createLocalReq","loginWithCookie","applyAuthCookie","login","collection","config","email","password","serverAdapter","username","payload","cron","authConfig","collections","auth","Error","loginWithUsername","allowEmailLogin","loginData","collectionConfig","cookie","result","data","overrideAccess","req","returnCookieAsObject"],"mappings":"AAMA,SAASA,UAAU,QAAQ,iBAAgB;AAC3C,SAASC,cAAc,QAAQ,oCAAmC;AAClE,SAASC,eAAe,QAAQ,wBAAuB;AACvD,SAASC,eAAe,QAAQ,eAAc;AAqB9C;;;CAGC,GACD,OAAO,eAAeC,MAAwC,EAC5DC,UAAU,EACVC,MAAM,EACNC,KAAK,EACLC,QAAQ,EACRC,aAAa,EACbC,QAAQ,EACS;IACjB,MAAMC,UAAU,MAAMX,WAAW;QAAEM;QAAQM,MAAM;IAAK;IAEtD,MAAMC,aAAaF,QAAQG,WAAW,CAACT,WAAW,EAAEC,OAAOS;IAE3D,IAAI,CAACF,YAAY;QACf,MAAM,IAAIG,MAAM,CAAC,qCAAqC,EAAEX,YAAY;IACtE;IAEA,MAAMY,oBAAoBJ,WAAWI,iBAAiB,IAAI;IAE1D,IAAIA,mBAAmB;QACrB,IAAIA,kBAAkBC,eAAe,EAAE;YACrC,IAAI,CAACX,SAAS,CAACG,UAAU;gBACvB,MAAM,IAAIM,MAAM;YAClB;QACF,OAAO;YACL,IAAI,CAACN,UAAU;gBACb,MAAM,IAAIM,MAAM;YAClB;QACF;IACF,OAAO;QACL,IAAI,CAACT,OAAO;YACV,MAAM,IAAIS,MAAM;QAClB;IACF;IAEA,IAAIG;IAEJ,IAAIF,mBAAmB;QACrBE,YAAYT,WAAW;YAAEF;YAAUE;QAAS,IAAI;YAAEH;YAAOC;QAAS;IACpE,OAAO;QACLW,YAAY;YAAEZ;YAAOC;QAAS;IAChC;IAEA,MAAMY,mBAAmBT,QAAQG,WAAW,CAACT,WAAW;IAExD,MAAM,EAAEgB,MAAM,EAAEC,MAAM,EAAE,GAAG,MAAMpB,gBAAgB;QAC/CG,YAAYe;QACZG,MAAMJ;QACNK,gBAAgB;QAChBC,KAAK,MAAMxB,eAAe,CAAC,GAAGU;QAC9Be,sBAAsB;IACxB;IAEA,MAAMvB,gBAAgB;QAAEkB;QAAQZ;IAAc;IAE9C,OAAOa;AACT"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ServerAdapter } from '../../admin/adapters/server.js';
|
|
2
|
+
import type { SanitizedConfig } from '../../config/types.js';
|
|
3
|
+
import type { MaybePromise } from '../../types/index.js';
|
|
4
|
+
export type LogoutArgs = {
|
|
5
|
+
allSessions?: boolean;
|
|
6
|
+
config: MaybePromise<SanitizedConfig>;
|
|
7
|
+
serverAdapter: ServerAdapter;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Logs the current user out and expires the auth cookie through the supplied
|
|
11
|
+
* `serverAdapter`, so the function is framework-agnostic; each adapter binds its own.
|
|
12
|
+
*/
|
|
13
|
+
export declare function logout({ allSessions, config, serverAdapter, }: LogoutArgs): Promise<{
|
|
14
|
+
message: string;
|
|
15
|
+
success: boolean;
|
|
16
|
+
}>;
|
|
17
|
+
//# sourceMappingURL=logout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logout.d.ts","sourceRoot":"","sources":["../../../src/auth/serverFunctions/logout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAA;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAOxD,MAAM,MAAM,UAAU,GAAG;IACvB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,MAAM,EAAE,YAAY,CAAC,eAAe,CAAC,CAAA;IACrC,aAAa,EAAE,aAAa,CAAA;CAC7B,CAAA;AAED;;;GAGG;AACH,wBAAsB,MAAM,CAAC,EAC3B,WAAmB,EACnB,MAAM,EACN,aAAa,GACd,EAAE,UAAU,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CAoC7D"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { getPayload } from '../../index.js';
|
|
2
|
+
import { createLocalReq } from '../../utilities/createLocalReq.js';
|
|
3
|
+
import { logoutOperation } from '../operations/logout.js';
|
|
4
|
+
import { clearAuthCookie } from './cookies.js';
|
|
5
|
+
/**
|
|
6
|
+
* Logs the current user out and expires the auth cookie through the supplied
|
|
7
|
+
* `serverAdapter`, so the function is framework-agnostic; each adapter binds its own.
|
|
8
|
+
*/ export async function logout({ allSessions = false, config, serverAdapter }) {
|
|
9
|
+
const payload = await getPayload({
|
|
10
|
+
config,
|
|
11
|
+
cron: true
|
|
12
|
+
});
|
|
13
|
+
const headers = await serverAdapter.getHeaders();
|
|
14
|
+
const authResult = await payload.auth({
|
|
15
|
+
headers
|
|
16
|
+
});
|
|
17
|
+
if (!authResult.user) {
|
|
18
|
+
return {
|
|
19
|
+
message: 'User already logged out',
|
|
20
|
+
success: true
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
const { user } = authResult;
|
|
24
|
+
const req = await createLocalReq({
|
|
25
|
+
user
|
|
26
|
+
}, payload);
|
|
27
|
+
const collection = payload.collections[user.collection];
|
|
28
|
+
if (!collection) {
|
|
29
|
+
return {
|
|
30
|
+
message: 'Collection not found',
|
|
31
|
+
success: false
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const logoutResult = await logoutOperation({
|
|
35
|
+
allSessions,
|
|
36
|
+
collection,
|
|
37
|
+
req
|
|
38
|
+
});
|
|
39
|
+
if (!logoutResult) {
|
|
40
|
+
return {
|
|
41
|
+
message: 'Logout failed',
|
|
42
|
+
success: false
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
if (collection.config.auth) {
|
|
46
|
+
await clearAuthCookie({
|
|
47
|
+
authConfig: collection.config.auth,
|
|
48
|
+
cookiePrefix: payload.config.cookiePrefix,
|
|
49
|
+
serverAdapter
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
message: 'User logged out successfully',
|
|
54
|
+
success: true
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
//# sourceMappingURL=logout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/auth/serverFunctions/logout.ts"],"sourcesContent":["import type { ServerAdapter } from '../../admin/adapters/server.js'\nimport type { SanitizedConfig } from '../../config/types.js'\nimport type { MaybePromise } from '../../types/index.js'\n\nimport { getPayload } from '../../index.js'\nimport { createLocalReq } from '../../utilities/createLocalReq.js'\nimport { logoutOperation } from '../operations/logout.js'\nimport { clearAuthCookie } from './cookies.js'\n\nexport type LogoutArgs = {\n allSessions?: boolean\n config: MaybePromise<SanitizedConfig>\n serverAdapter: ServerAdapter\n}\n\n/**\n * Logs the current user out and expires the auth cookie through the supplied\n * `serverAdapter`, so the function is framework-agnostic; each adapter binds its own.\n */\nexport async function logout({\n allSessions = false,\n config,\n serverAdapter,\n}: LogoutArgs): Promise<{ message: string; success: boolean }> {\n const payload = await getPayload({ config, cron: true })\n const headers = await serverAdapter.getHeaders()\n const authResult = await payload.auth({ headers })\n\n if (!authResult.user) {\n return { message: 'User already logged out', success: true }\n }\n\n const { user } = authResult\n const req = await createLocalReq({ user }, payload)\n const collection = payload.collections[user.collection]\n\n if (!collection) {\n return { message: 'Collection not found', success: false }\n }\n\n const logoutResult = await logoutOperation({\n allSessions,\n collection,\n req,\n })\n\n if (!logoutResult) {\n return { message: 'Logout failed', success: false }\n }\n\n if (collection.config.auth) {\n await clearAuthCookie({\n authConfig: collection.config.auth,\n cookiePrefix: payload.config.cookiePrefix,\n serverAdapter,\n })\n }\n\n return { message: 'User logged out successfully', success: true }\n}\n"],"names":["getPayload","createLocalReq","logoutOperation","clearAuthCookie","logout","allSessions","config","serverAdapter","payload","cron","headers","getHeaders","authResult","auth","user","message","success","req","collection","collections","logoutResult","authConfig","cookiePrefix"],"mappings":"AAIA,SAASA,UAAU,QAAQ,iBAAgB;AAC3C,SAASC,cAAc,QAAQ,oCAAmC;AAClE,SAASC,eAAe,QAAQ,0BAAyB;AACzD,SAASC,eAAe,QAAQ,eAAc;AAQ9C;;;CAGC,GACD,OAAO,eAAeC,OAAO,EAC3BC,cAAc,KAAK,EACnBC,MAAM,EACNC,aAAa,EACF;IACX,MAAMC,UAAU,MAAMR,WAAW;QAAEM;QAAQG,MAAM;IAAK;IACtD,MAAMC,UAAU,MAAMH,cAAcI,UAAU;IAC9C,MAAMC,aAAa,MAAMJ,QAAQK,IAAI,CAAC;QAAEH;IAAQ;IAEhD,IAAI,CAACE,WAAWE,IAAI,EAAE;QACpB,OAAO;YAAEC,SAAS;YAA2BC,SAAS;QAAK;IAC7D;IAEA,MAAM,EAAEF,IAAI,EAAE,GAAGF;IACjB,MAAMK,MAAM,MAAMhB,eAAe;QAAEa;IAAK,GAAGN;IAC3C,MAAMU,aAAaV,QAAQW,WAAW,CAACL,KAAKI,UAAU,CAAC;IAEvD,IAAI,CAACA,YAAY;QACf,OAAO;YAAEH,SAAS;YAAwBC,SAAS;QAAM;IAC3D;IAEA,MAAMI,eAAe,MAAMlB,gBAAgB;QACzCG;QACAa;QACAD;IACF;IAEA,IAAI,CAACG,cAAc;QACjB,OAAO;YAAEL,SAAS;YAAiBC,SAAS;QAAM;IACpD;IAEA,IAAIE,WAAWZ,MAAM,CAACO,IAAI,EAAE;QAC1B,MAAMV,gBAAgB;YACpBkB,YAAYH,WAAWZ,MAAM,CAACO,IAAI;YAClCS,cAAcd,QAAQF,MAAM,CAACgB,YAAY;YACzCf;QACF;IACF;IAEA,OAAO;QAAEQ,SAAS;QAAgCC,SAAS;IAAK;AAClE"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ServerAdapter } from '../../admin/adapters/server.js';
|
|
2
|
+
import type { SanitizedConfig } from '../../config/types.js';
|
|
3
|
+
import type { MaybePromise } from '../../types/index.js';
|
|
4
|
+
export type RefreshArgs = {
|
|
5
|
+
config: MaybePromise<SanitizedConfig>;
|
|
6
|
+
serverAdapter: ServerAdapter;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Refreshes the current user's auth token and rewrites the cookie through the
|
|
10
|
+
* supplied `serverAdapter`, so the function is framework-agnostic; each adapter
|
|
11
|
+
* binds its own.
|
|
12
|
+
*/
|
|
13
|
+
export declare function refresh({ config, serverAdapter, }: RefreshArgs): Promise<{
|
|
14
|
+
message: string;
|
|
15
|
+
success: boolean;
|
|
16
|
+
}>;
|
|
17
|
+
//# sourceMappingURL=refresh.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"refresh.d.ts","sourceRoot":"","sources":["../../../src/auth/serverFunctions/refresh.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAA;AACnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAE5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAOxD,MAAM,MAAM,WAAW,GAAG;IACxB,MAAM,EAAE,YAAY,CAAC,eAAe,CAAC,CAAA;IACrC,aAAa,EAAE,aAAa,CAAA;CAC7B,CAAA;AAED;;;;GAIG;AACH,wBAAsB,OAAO,CAAC,EAC5B,MAAM,EACN,aAAa,GACd,EAAE,WAAW,GAAG,OAAO,CAAC;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CA4C9D"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { getPayload } from '../../index.js';
|
|
2
|
+
import { createLocalReq } from '../../utilities/createLocalReq.js';
|
|
3
|
+
import { refreshOperation } from '../operations/refresh.js';
|
|
4
|
+
import { getExistingAuthToken, setAuthCookie } from './cookies.js';
|
|
5
|
+
/**
|
|
6
|
+
* Refreshes the current user's auth token and rewrites the cookie through the
|
|
7
|
+
* supplied `serverAdapter`, so the function is framework-agnostic; each adapter
|
|
8
|
+
* binds its own.
|
|
9
|
+
*/ export async function refresh({ config, serverAdapter }) {
|
|
10
|
+
const payload = await getPayload({
|
|
11
|
+
config,
|
|
12
|
+
cron: true
|
|
13
|
+
});
|
|
14
|
+
const headers = await serverAdapter.getHeaders();
|
|
15
|
+
const result = await payload.auth({
|
|
16
|
+
headers
|
|
17
|
+
});
|
|
18
|
+
if (!result.user) {
|
|
19
|
+
throw new Error('Cannot refresh token: user not authenticated');
|
|
20
|
+
}
|
|
21
|
+
const existingCookie = await getExistingAuthToken({
|
|
22
|
+
cookiePrefix: payload.config.cookiePrefix,
|
|
23
|
+
serverAdapter
|
|
24
|
+
});
|
|
25
|
+
if (!existingCookie) {
|
|
26
|
+
return {
|
|
27
|
+
message: 'No valid token found to refresh',
|
|
28
|
+
success: false
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const collection = result.user.collection;
|
|
32
|
+
const collectionConfig = payload.collections[collection];
|
|
33
|
+
if (!collectionConfig?.config.auth) {
|
|
34
|
+
throw new Error(`No auth config found for collection: ${collection}`);
|
|
35
|
+
}
|
|
36
|
+
const req = await createLocalReq({
|
|
37
|
+
user: result.user
|
|
38
|
+
}, payload);
|
|
39
|
+
const refreshResult = await refreshOperation({
|
|
40
|
+
collection: collectionConfig,
|
|
41
|
+
req
|
|
42
|
+
});
|
|
43
|
+
if (!refreshResult) {
|
|
44
|
+
return {
|
|
45
|
+
message: 'Token refresh failed',
|
|
46
|
+
success: false
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
await setAuthCookie({
|
|
50
|
+
authConfig: collectionConfig.config.auth,
|
|
51
|
+
cookiePrefix: payload.config.cookiePrefix,
|
|
52
|
+
serverAdapter,
|
|
53
|
+
token: refreshResult.refreshedToken
|
|
54
|
+
});
|
|
55
|
+
return {
|
|
56
|
+
message: 'Token refreshed successfully',
|
|
57
|
+
success: true
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=refresh.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/auth/serverFunctions/refresh.ts"],"sourcesContent":["import type { ServerAdapter } from '../../admin/adapters/server.js'\nimport type { SanitizedConfig } from '../../config/types.js'\nimport type { CollectionSlug } from '../../index.js'\nimport type { MaybePromise } from '../../types/index.js'\n\nimport { getPayload } from '../../index.js'\nimport { createLocalReq } from '../../utilities/createLocalReq.js'\nimport { refreshOperation } from '../operations/refresh.js'\nimport { getExistingAuthToken, setAuthCookie } from './cookies.js'\n\nexport type RefreshArgs = {\n config: MaybePromise<SanitizedConfig>\n serverAdapter: ServerAdapter\n}\n\n/**\n * Refreshes the current user's auth token and rewrites the cookie through the\n * supplied `serverAdapter`, so the function is framework-agnostic; each adapter\n * binds its own.\n */\nexport async function refresh({\n config,\n serverAdapter,\n}: RefreshArgs): Promise<{ message: string; success: boolean }> {\n const payload = await getPayload({ config, cron: true })\n const headers = await serverAdapter.getHeaders()\n const result = await payload.auth({ headers })\n\n if (!result.user) {\n throw new Error('Cannot refresh token: user not authenticated')\n }\n\n const existingCookie = await getExistingAuthToken({\n cookiePrefix: payload.config.cookiePrefix,\n serverAdapter,\n })\n\n if (!existingCookie) {\n return { message: 'No valid token found to refresh', success: false }\n }\n\n const collection: CollectionSlug | undefined = result.user.collection\n const collectionConfig = payload.collections[collection]\n\n if (!collectionConfig?.config.auth) {\n throw new Error(`No auth config found for collection: ${collection}`)\n }\n\n const req = await createLocalReq({ user: result.user }, payload)\n\n const refreshResult = await refreshOperation({\n collection: collectionConfig,\n req,\n })\n\n if (!refreshResult) {\n return { message: 'Token refresh failed', success: false }\n }\n\n await setAuthCookie({\n authConfig: collectionConfig.config.auth,\n cookiePrefix: payload.config.cookiePrefix,\n serverAdapter,\n token: refreshResult.refreshedToken,\n })\n\n return { message: 'Token refreshed successfully', success: true }\n}\n"],"names":["getPayload","createLocalReq","refreshOperation","getExistingAuthToken","setAuthCookie","refresh","config","serverAdapter","payload","cron","headers","getHeaders","result","auth","user","Error","existingCookie","cookiePrefix","message","success","collection","collectionConfig","collections","req","refreshResult","authConfig","token","refreshedToken"],"mappings":"AAKA,SAASA,UAAU,QAAQ,iBAAgB;AAC3C,SAASC,cAAc,QAAQ,oCAAmC;AAClE,SAASC,gBAAgB,QAAQ,2BAA0B;AAC3D,SAASC,oBAAoB,EAAEC,aAAa,QAAQ,eAAc;AAOlE;;;;CAIC,GACD,OAAO,eAAeC,QAAQ,EAC5BC,MAAM,EACNC,aAAa,EACD;IACZ,MAAMC,UAAU,MAAMR,WAAW;QAAEM;QAAQG,MAAM;IAAK;IACtD,MAAMC,UAAU,MAAMH,cAAcI,UAAU;IAC9C,MAAMC,SAAS,MAAMJ,QAAQK,IAAI,CAAC;QAAEH;IAAQ;IAE5C,IAAI,CAACE,OAAOE,IAAI,EAAE;QAChB,MAAM,IAAIC,MAAM;IAClB;IAEA,MAAMC,iBAAiB,MAAMb,qBAAqB;QAChDc,cAAcT,QAAQF,MAAM,CAACW,YAAY;QACzCV;IACF;IAEA,IAAI,CAACS,gBAAgB;QACnB,OAAO;YAAEE,SAAS;YAAmCC,SAAS;QAAM;IACtE;IAEA,MAAMC,aAAyCR,OAAOE,IAAI,CAACM,UAAU;IACrE,MAAMC,mBAAmBb,QAAQc,WAAW,CAACF,WAAW;IAExD,IAAI,CAACC,kBAAkBf,OAAOO,MAAM;QAClC,MAAM,IAAIE,MAAM,CAAC,qCAAqC,EAAEK,YAAY;IACtE;IAEA,MAAMG,MAAM,MAAMtB,eAAe;QAAEa,MAAMF,OAAOE,IAAI;IAAC,GAAGN;IAExD,MAAMgB,gBAAgB,MAAMtB,iBAAiB;QAC3CkB,YAAYC;QACZE;IACF;IAEA,IAAI,CAACC,eAAe;QAClB,OAAO;YAAEN,SAAS;YAAwBC,SAAS;QAAM;IAC3D;IAEA,MAAMf,cAAc;QAClBqB,YAAYJ,iBAAiBf,MAAM,CAACO,IAAI;QACxCI,cAAcT,QAAQF,MAAM,CAACW,YAAY;QACzCV;QACAmB,OAAOF,cAAcG,cAAc;IACrC;IAEA,OAAO;QAAET,SAAS;QAAgCC,SAAS;IAAK;AAClE"}
|
|
@@ -5,14 +5,13 @@ import type { LivePreviewConfig, ServerOnlyLivePreviewProperties, StaticLabel }
|
|
|
5
5
|
import type { ClientField } from '../../fields/config/client.js';
|
|
6
6
|
import type { ClientHierarchyConfig } from '../../hierarchy/types.js';
|
|
7
7
|
import type { Payload } from '../../types/index.js';
|
|
8
|
-
import type { SanitizedUploadConfig } from '../../uploads/types.js';
|
|
8
|
+
import type { SanitizedUploadConfig, UploadInstructionsCapability } from '../../uploads/types.js';
|
|
9
9
|
import type { SanitizedCollectionConfig } from './types.js';
|
|
10
10
|
export type ServerOnlyCollectionProperties = keyof Pick<SanitizedCollectionConfig, 'access' | 'custom' | 'endpoints' | 'flattenedFields' | 'hooks' | 'indexes' | 'joins' | 'polymorphicJoins' | 'sanitizedIndexes' | 'select'>;
|
|
11
11
|
export type ServerOnlyCollectionAdminProperties = keyof Pick<SanitizedCollectionConfig['admin'], 'baseFilter' | 'baseListFilter' | 'components' | 'formatDocURL' | 'hidden'>;
|
|
12
12
|
export type ServerOnlyUploadProperties = keyof Pick<SanitizedCollectionConfig['upload'], 'admin' | 'adminThumbnail' | 'externalFileHeaderFilter' | 'handlers' | 'modifyResponseHeaders' | 'uploadInstructions' | 'withMetadata'>;
|
|
13
13
|
type ClientUploadConfig = {
|
|
14
|
-
|
|
15
|
-
uploadInstructions?: true;
|
|
14
|
+
uploadInstructions: Pick<UploadInstructionsCapability, 'useInAdmin'>;
|
|
16
15
|
} & Omit<SanitizedUploadConfig, 'uploadInstructions'>;
|
|
17
16
|
export type ClientCollectionConfig = {
|
|
18
17
|
admin: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/collections/config/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAa,MAAM,0BAA0B,CAAA;AAErE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAA;AACrE,OAAO,KAAK,EACV,iBAAiB,EACjB,+BAA+B,EAC/B,WAAW,EACZ,MAAM,uBAAuB,CAAA;AAC9B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAA;AAChE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAA;AACrE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AACnD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/collections/config/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAa,MAAM,0BAA0B,CAAA;AAErE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAA;AACrE,OAAO,KAAK,EACV,iBAAiB,EACjB,+BAA+B,EAC/B,WAAW,EACZ,MAAM,uBAAuB,CAAA;AAC9B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAA;AAChE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAA;AACrE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBA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AI,CAC7B,yBAAyB,CAAC,MAAM,CAAC,EACjC,gBAAgB,GAAG,YAAY,GAAG,QAAQ,CAC3C,CAAA;IACD,MAAM,EAAE,WAAW,EAAE,CAAA;IACrB,SAAS,CAAC,EAAE,qBAAqB,GAAG,KAAK,CAAA;IACzC,MAAM,EAAE;QACN,MAAM,EAAE,WAAW,CAAA;QACnB,QAAQ,EAAE,WAAW,CAAA;KACtB,CAAA;IACD,MAAM,EAAE,kBAAkB,CAAA;CAC3B,GAAG,IAAI,CACN,yBAAyB,EACzB,OAAO,GAAG,MAAM,GAAG,QAAQ,GAAG,WAAW,GAAG,QAAQ,GAAG,QAAQ,GAAG,8BAA8B,CACjG,CAAA;AAsCD,eAAO,MAAM,4BAA4B,oDAKtC;IACD,UAAU,EAAE,yBAAyB,CAAA;IACrC,aAAa,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,eAAe,CAAC,CAAA;IACvD,IAAI,EAAE,UAAU,CAAA;IAChB,SAAS,EAAE,SAAS,CAAA;CACrB,KAAG,sBA8LH,CAAA;AAED,eAAO,MAAM,6BAA6B,qDAKvC;IACD,WAAW,EAAE,yBAAyB,EAAE,CAAA;IACxC,aAAa,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,eAAe,CAAC,CAAA;IACvD,IAAI,EAAE,UAAU,CAAA;IAChB,SAAS,EAAE,SAAS,CAAA;CACrB,KAAG,sBAAsB,EAezB,CAAA"}
|
|
@@ -149,14 +149,12 @@ export const createClientCollectionConfig = ({ collection, defaultIDType, i18n,
|
|
|
149
149
|
if (!collection.upload) {
|
|
150
150
|
break;
|
|
151
151
|
}
|
|
152
|
-
clientCollection.upload = {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
if (collection.upload.uploadInstructions) {
|
|
156
|
-
clientCollection.upload.uploadInstructions = true;
|
|
157
|
-
}
|
|
158
|
-
continue;
|
|
152
|
+
clientCollection.upload = {
|
|
153
|
+
uploadInstructions: {
|
|
154
|
+
useInAdmin: collection.upload.uploadInstructions?.useInAdmin ?? false
|
|
159
155
|
}
|
|
156
|
+
};
|
|
157
|
+
for(const uploadKey in collection.upload){
|
|
160
158
|
if (serverOnlyUploadProperties.includes(uploadKey)) {
|
|
161
159
|
continue;
|
|
162
160
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/collections/config/client.ts"],"sourcesContent":["import type { I18nClient, TFunction } from '@payloadcms/translations'\n\nimport type { StaticDescription } from '../../admin/types.js'\nimport type { ImportMap } from '../../bin/generateImportMap/index.js'\nimport type {\n LivePreviewConfig,\n ServerOnlyLivePreviewProperties,\n StaticLabel,\n} from '../../config/types.js'\nimport type { ClientField } from '../../fields/config/client.js'\nimport type { ClientHierarchyConfig } from '../../hierarchy/types.js'\nimport type { Payload } from '../../types/index.js'\nimport type { SanitizedUploadConfig } from '../../uploads/types.js'\nimport type { SanitizedCollectionConfig } from './types.js'\n\nimport { createClientFields } from '../../fields/config/client.js'\n\nexport type ServerOnlyCollectionProperties = keyof Pick<\n SanitizedCollectionConfig,\n | 'access'\n | 'custom'\n | 'endpoints'\n | 'flattenedFields'\n | 'hooks'\n | 'indexes'\n | 'joins'\n | 'polymorphicJoins'\n | 'sanitizedIndexes'\n | 'select'\n>\n\nexport type ServerOnlyCollectionAdminProperties = keyof Pick<\n SanitizedCollectionConfig['admin'],\n 'baseFilter' | 'baseListFilter' | 'components' | 'formatDocURL' | 'hidden'\n>\n\nexport type ServerOnlyUploadProperties = keyof Pick<\n SanitizedCollectionConfig['upload'],\n | 'admin'\n | 'adminThumbnail'\n | 'externalFileHeaderFilter'\n | 'handlers'\n | 'modifyResponseHeaders'\n | 'uploadInstructions'\n | 'withMetadata'\n>\n\ntype ClientUploadConfig = {\n /** Whether this collection provides separate upload instructions. */\n uploadInstructions?: true\n} & Omit<SanitizedUploadConfig, 'uploadInstructions'>\n\nexport type ClientCollectionConfig = {\n admin: {\n description?: StaticDescription\n livePreview?: Omit<LivePreviewConfig, ServerOnlyLivePreviewProperties>\n preview?: boolean\n } & Omit<\n SanitizedCollectionConfig['admin'],\n | 'components'\n | 'description'\n | 'formatDocURL'\n | 'joins'\n | 'livePreview'\n | 'preview'\n | ServerOnlyCollectionAdminProperties\n >\n auth?: { verify?: true } & Omit<\n SanitizedCollectionConfig['auth'],\n 'forgotPassword' | 'strategies' | 'verify'\n >\n fields: ClientField[]\n hierarchy?: ClientHierarchyConfig | false\n labels: {\n plural: StaticLabel\n singular: StaticLabel\n }\n upload: ClientUploadConfig\n} & Omit<\n SanitizedCollectionConfig,\n 'admin' | 'auth' | 'fields' | 'hierarchy' | 'labels' | 'upload' | ServerOnlyCollectionProperties\n>\n\nconst serverOnlyCollectionProperties: Partial<ServerOnlyCollectionProperties>[] = [\n 'hooks',\n 'access',\n 'endpoints',\n 'custom',\n 'joins',\n 'polymorphicJoins',\n 'flattenedFields',\n 'indexes',\n 'sanitizedIndexes',\n 'select',\n // `upload`\n // `admin`\n // are all handled separately\n]\n\nconst serverOnlyUploadProperties: Partial<ServerOnlyUploadProperties>[] = [\n 'admin',\n 'adminThumbnail',\n 'externalFileHeaderFilter',\n 'handlers',\n 'modifyResponseHeaders',\n 'uploadInstructions',\n 'withMetadata',\n]\n\nconst serverOnlyCollectionAdminProperties: Partial<ServerOnlyCollectionAdminProperties>[] = [\n 'hidden',\n 'baseFilter',\n 'baseListFilter',\n 'components',\n 'formatDocURL',\n // 'preview' is handled separately\n // `livePreview` is handled separately\n]\n\nexport const createClientCollectionConfig = ({\n collection,\n defaultIDType,\n i18n,\n importMap,\n}: {\n collection: SanitizedCollectionConfig\n defaultIDType: Payload['config']['db']['defaultIDType']\n i18n: I18nClient\n importMap: ImportMap\n}): ClientCollectionConfig => {\n const clientCollection = {} as Partial<ClientCollectionConfig>\n\n for (const key in collection) {\n if (serverOnlyCollectionProperties.includes(key as any)) {\n continue\n }\n switch (key) {\n case 'admin':\n if (!collection.admin) {\n break\n }\n\n clientCollection.admin = {} as ClientCollectionConfig['admin']\n\n for (const adminKey in collection.admin) {\n if (serverOnlyCollectionAdminProperties.includes(adminKey as any)) {\n continue\n }\n\n switch (adminKey) {\n case 'description':\n if (\n typeof collection.admin.description === 'string' ||\n typeof collection.admin.description === 'object'\n ) {\n if (collection.admin.description) {\n clientCollection.admin.description = collection.admin.description\n }\n } else if (typeof collection.admin.description === 'function') {\n const description = collection.admin.description({ t: i18n.t as TFunction })\n\n if (description) {\n clientCollection.admin.description = description\n }\n }\n break\n\n case 'livePreview':\n clientCollection.admin.livePreview = {}\n\n if (collection.admin.livePreview?.breakpoints) {\n clientCollection.admin.livePreview.breakpoints =\n collection.admin.livePreview.breakpoints\n }\n\n break\n\n case 'preview':\n if (collection.admin.preview) {\n clientCollection.admin.preview = true\n }\n\n break\n\n default:\n ;(clientCollection as any).admin[adminKey] =\n collection.admin[adminKey as keyof SanitizedCollectionConfig['admin']]\n }\n }\n\n break\n\n case 'auth':\n if (!collection.auth) {\n break\n }\n\n clientCollection.auth = {} as { verify?: true } & SanitizedCollectionConfig['auth']\n\n if (collection.auth.cookies) {\n clientCollection.auth.cookies = collection.auth.cookies\n }\n\n if (collection.auth.depth !== undefined) {\n // Check for undefined as it can be a number (0)\n clientCollection.auth.depth = collection.auth.depth\n }\n\n if (collection.auth.disableLocalStrategy) {\n clientCollection.auth.disableLocalStrategy = collection.auth.disableLocalStrategy\n }\n\n if (collection.auth.lockTime !== undefined) {\n // Check for undefined as it can be a number (0)\n clientCollection.auth.lockTime = collection.auth.lockTime\n }\n\n if (collection.auth.loginWithUsername) {\n clientCollection.auth.loginWithUsername = collection.auth.loginWithUsername\n }\n\n if (collection.auth.maxLoginAttempts !== undefined) {\n // Check for undefined as it can be a number (0)\n clientCollection.auth.maxLoginAttempts = collection.auth.maxLoginAttempts\n }\n\n if (collection.auth.removeTokenFromResponses) {\n clientCollection.auth.removeTokenFromResponses = collection.auth.removeTokenFromResponses\n }\n\n if (collection.auth.useAPIKey) {\n clientCollection.auth.useAPIKey = collection.auth.useAPIKey\n }\n\n if (collection.auth.tokenExpiration) {\n clientCollection.auth.tokenExpiration = collection.auth.tokenExpiration\n }\n\n if (collection.auth.verify) {\n clientCollection.auth.verify = true\n }\n\n break\n\n case 'fields':\n clientCollection.fields = createClientFields({\n defaultIDType,\n fields: collection.fields,\n i18n,\n importMap,\n })\n\n break\n\n case 'hierarchy': {\n if (!collection.hierarchy || typeof collection.hierarchy !== 'object') {\n clientCollection.hierarchy = false\n break\n }\n\n // Strip slugify function as it can't cross server-client boundary\n const { slugify: _slugify, ...clientHierarchy } = collection.hierarchy\n clientCollection.hierarchy = clientHierarchy as ClientHierarchyConfig\n\n break\n }\n\n case 'labels':\n clientCollection.labels = {\n plural:\n typeof collection.labels.plural === 'function'\n ? collection.labels.plural({ i18n, t: i18n.t as TFunction })\n : collection.labels.plural,\n singular:\n typeof collection.labels.singular === 'function'\n ? collection.labels.singular({ i18n, t: i18n.t as TFunction })\n : collection.labels.singular,\n }\n\n break\n\n case 'upload':\n if (!collection.upload) {\n break\n }\n\n clientCollection.upload = {} as ClientUploadConfig\n\n for (const uploadKey in collection.upload) {\n if (uploadKey === 'uploadInstructions') {\n if (collection.upload.uploadInstructions) {\n clientCollection.upload.uploadInstructions = true\n }\n continue\n }\n\n if (serverOnlyUploadProperties.includes(uploadKey as any)) {\n continue\n }\n\n if (uploadKey === 'imageSizes') {\n clientCollection.upload.imageSizes = collection.upload.imageSizes?.map((size) => {\n const sanitizedSize = { ...size }\n if ('generateImageName' in sanitizedSize) {\n delete sanitizedSize.generateImageName\n }\n return sanitizedSize\n })\n } else {\n ;(clientCollection.upload as any)[uploadKey] =\n collection.upload[uploadKey as keyof SanitizedUploadConfig]\n }\n }\n\n break\n\n default:\n ;(clientCollection as any)[key] = collection[key as keyof SanitizedCollectionConfig]\n }\n }\n\n return clientCollection as ClientCollectionConfig\n}\n\nexport const createClientCollectionConfigs = ({\n collections,\n defaultIDType,\n i18n,\n importMap,\n}: {\n collections: SanitizedCollectionConfig[]\n defaultIDType: Payload['config']['db']['defaultIDType']\n i18n: I18nClient\n importMap: ImportMap\n}): ClientCollectionConfig[] => {\n const clientCollections = new Array(collections.length)\n\n for (let i = 0; i < collections.length; i++) {\n const collection = collections[i]!\n\n clientCollections[i] = createClientCollectionConfig({\n collection,\n defaultIDType,\n i18n,\n importMap,\n })\n }\n\n return clientCollections\n}\n"],"names":["createClientFields","serverOnlyCollectionProperties","serverOnlyUploadProperties","serverOnlyCollectionAdminProperties","createClientCollectionConfig","collection","defaultIDType","i18n","importMap","clientCollection","key","includes","admin","adminKey","description","t","livePreview","breakpoints","preview","auth","cookies","depth","undefined","disableLocalStrategy","lockTime","loginWithUsername","maxLoginAttempts","removeTokenFromResponses","useAPIKey","tokenExpiration","verify","fields","hierarchy","slugify","_slugify","clientHierarchy","labels","plural","singular","upload","uploadKey","uploadInstructions","imageSizes","map","size","sanitizedSize","generateImageName","createClientCollectionConfigs","collections","clientCollections","Array","length","i"],"mappings":"AAeA,SAASA,kBAAkB,QAAQ,gCAA+B;AAoElE,MAAMC,iCAA4E;IAChF;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CAID;AAED,MAAMC,6BAAoE;IACxE;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED,MAAMC,sCAAsF;IAC1F;IACA;IACA;IACA;IACA;CAGD;AAED,OAAO,MAAMC,+BAA+B,CAAC,EAC3CC,UAAU,EACVC,aAAa,EACbC,IAAI,EACJC,SAAS,EAMV;IACC,MAAMC,mBAAmB,CAAC;IAE1B,IAAK,MAAMC,OAAOL,WAAY;QAC5B,IAAIJ,+BAA+BU,QAAQ,CAACD,MAAa;YACvD;QACF;QACA,OAAQA;YACN,KAAK;gBACH,IAAI,CAACL,WAAWO,KAAK,EAAE;oBACrB;gBACF;gBAEAH,iBAAiBG,KAAK,GAAG,CAAC;gBAE1B,IAAK,MAAMC,YAAYR,WAAWO,KAAK,CAAE;oBACvC,IAAIT,oCAAoCQ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C;4BACtE,MAAMC,gBAAgB;gCAAE,GAAGD,IAAI;4BAAC;4BAChC,IAAI,uBAAuBC,eAAe;gCACxC,OAAOA,cAAcC,iBAAiB;4BACxC;4BACA,OAAOD;wBACT;oBACF,OAAO;;wBACHpC,iBAAiB8B,MAAM,AAAQ,CAACC,UAAU,GAC1CnC,WAAWkC,MAAM,CAACC,UAAyC;oBAC/D;gBACF;gBAEA;YAEF;;gBACI/B,gBAAwB,CAACC,IAAI,GAAGL,UAAU,CAACK,IAAuC;QACxF;IACF;IAEA,OAAOD;AACT,EAAC;AAED,OAAO,MAAMsC,gCAAgC,CAAC,EAC5CC,WAAW,EACX1C,aAAa,EACbC,IAAI,EACJC,SAAS,EAMV;IACC,MAAMyC,oBAAoB,IAAIC,MAAMF,YAAYG,MAAM;IAEtD,IAAK,IAAIC,IAAI,GAAGA,IAAIJ,YAAYG,MAAM,EAAEC,IAAK;QAC3C,MAAM/C,aAAa2C,WAAW,CAACI,EAAE;QAEjCH,iBAAiB,CAACG,EAAE,GAAGhD,6BAA6B;YAClDC;YACAC;YACAC;YACAC;QACF;IACF;IAEA,OAAOyC;AACT,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/config/client.ts"],"sourcesContent":["import type { I18nClient, TFunction } from '@payloadcms/translations'\n\nimport type { StaticDescription } from '../../admin/types.js'\nimport type { ImportMap } from '../../bin/generateImportMap/index.js'\nimport type {\n LivePreviewConfig,\n ServerOnlyLivePreviewProperties,\n StaticLabel,\n} from '../../config/types.js'\nimport type { ClientField } from '../../fields/config/client.js'\nimport type { ClientHierarchyConfig } from '../../hierarchy/types.js'\nimport type { Payload } from '../../types/index.js'\nimport type { SanitizedUploadConfig, UploadInstructionsCapability } from '../../uploads/types.js'\nimport type { SanitizedCollectionConfig } from './types.js'\n\nimport { createClientFields } from '../../fields/config/client.js'\n\nexport type ServerOnlyCollectionProperties = keyof Pick<\n SanitizedCollectionConfig,\n | 'access'\n | 'custom'\n | 'endpoints'\n | 'flattenedFields'\n | 'hooks'\n | 'indexes'\n | 'joins'\n | 'polymorphicJoins'\n | 'sanitizedIndexes'\n | 'select'\n>\n\nexport type ServerOnlyCollectionAdminProperties = keyof Pick<\n SanitizedCollectionConfig['admin'],\n 'baseFilter' | 'baseListFilter' | 'components' | 'formatDocURL' | 'hidden'\n>\n\nexport type ServerOnlyUploadProperties = keyof Pick<\n SanitizedCollectionConfig['upload'],\n | 'admin'\n | 'adminThumbnail'\n | 'externalFileHeaderFilter'\n | 'handlers'\n | 'modifyResponseHeaders'\n | 'uploadInstructions'\n | 'withMetadata'\n>\n\ntype ClientUploadConfig = {\n uploadInstructions: Pick<UploadInstructionsCapability, 'useInAdmin'>\n} & Omit<SanitizedUploadConfig, 'uploadInstructions'>\n\nexport type ClientCollectionConfig = {\n admin: {\n description?: StaticDescription\n livePreview?: Omit<LivePreviewConfig, ServerOnlyLivePreviewProperties>\n preview?: boolean\n } & Omit<\n SanitizedCollectionConfig['admin'],\n | 'components'\n | 'description'\n | 'formatDocURL'\n | 'joins'\n | 'livePreview'\n | 'preview'\n | ServerOnlyCollectionAdminProperties\n >\n auth?: { verify?: true } & Omit<\n SanitizedCollectionConfig['auth'],\n 'forgotPassword' | 'strategies' | 'verify'\n >\n fields: ClientField[]\n hierarchy?: ClientHierarchyConfig | false\n labels: {\n plural: StaticLabel\n singular: StaticLabel\n }\n upload: ClientUploadConfig\n} & Omit<\n SanitizedCollectionConfig,\n 'admin' | 'auth' | 'fields' | 'hierarchy' | 'labels' | 'upload' | ServerOnlyCollectionProperties\n>\n\nconst serverOnlyCollectionProperties: Partial<ServerOnlyCollectionProperties>[] = [\n 'hooks',\n 'access',\n 'endpoints',\n 'custom',\n 'joins',\n 'polymorphicJoins',\n 'flattenedFields',\n 'indexes',\n 'sanitizedIndexes',\n 'select',\n // `upload`\n // `admin`\n // are all handled separately\n]\n\nconst serverOnlyUploadProperties: Partial<ServerOnlyUploadProperties>[] = [\n 'admin',\n 'adminThumbnail',\n 'externalFileHeaderFilter',\n 'handlers',\n 'modifyResponseHeaders',\n 'uploadInstructions',\n 'withMetadata',\n]\n\nconst serverOnlyCollectionAdminProperties: Partial<ServerOnlyCollectionAdminProperties>[] = [\n 'hidden',\n 'baseFilter',\n 'baseListFilter',\n 'components',\n 'formatDocURL',\n // 'preview' is handled separately\n // `livePreview` is handled separately\n]\n\nexport const createClientCollectionConfig = ({\n collection,\n defaultIDType,\n i18n,\n importMap,\n}: {\n collection: SanitizedCollectionConfig\n defaultIDType: Payload['config']['db']['defaultIDType']\n i18n: I18nClient\n importMap: ImportMap\n}): ClientCollectionConfig => {\n const clientCollection = {} as Partial<ClientCollectionConfig>\n\n for (const key in collection) {\n if (serverOnlyCollectionProperties.includes(key as any)) {\n continue\n }\n switch (key) {\n case 'admin':\n if (!collection.admin) {\n break\n }\n\n clientCollection.admin = {} as ClientCollectionConfig['admin']\n\n for (const adminKey in collection.admin) {\n if (serverOnlyCollectionAdminProperties.includes(adminKey as any)) {\n continue\n }\n\n switch (adminKey) {\n case 'description':\n if (\n typeof collection.admin.description === 'string' ||\n typeof collection.admin.description === 'object'\n ) {\n if (collection.admin.description) {\n clientCollection.admin.description = collection.admin.description\n }\n } else if (typeof collection.admin.description === 'function') {\n const description = collection.admin.description({ t: i18n.t as TFunction })\n\n if (description) {\n clientCollection.admin.description = description\n }\n }\n break\n\n case 'livePreview':\n clientCollection.admin.livePreview = {}\n\n if (collection.admin.livePreview?.breakpoints) {\n clientCollection.admin.livePreview.breakpoints =\n collection.admin.livePreview.breakpoints\n }\n\n break\n\n case 'preview':\n if (collection.admin.preview) {\n clientCollection.admin.preview = true\n }\n\n break\n\n default:\n ;(clientCollection as any).admin[adminKey] =\n collection.admin[adminKey as keyof SanitizedCollectionConfig['admin']]\n }\n }\n\n break\n\n case 'auth':\n if (!collection.auth) {\n break\n }\n\n clientCollection.auth = {} as { verify?: true } & SanitizedCollectionConfig['auth']\n\n if (collection.auth.cookies) {\n clientCollection.auth.cookies = collection.auth.cookies\n }\n\n if (collection.auth.depth !== undefined) {\n // Check for undefined as it can be a number (0)\n clientCollection.auth.depth = collection.auth.depth\n }\n\n if (collection.auth.disableLocalStrategy) {\n clientCollection.auth.disableLocalStrategy = collection.auth.disableLocalStrategy\n }\n\n if (collection.auth.lockTime !== undefined) {\n // Check for undefined as it can be a number (0)\n clientCollection.auth.lockTime = collection.auth.lockTime\n }\n\n if (collection.auth.loginWithUsername) {\n clientCollection.auth.loginWithUsername = collection.auth.loginWithUsername\n }\n\n if (collection.auth.maxLoginAttempts !== undefined) {\n // Check for undefined as it can be a number (0)\n clientCollection.auth.maxLoginAttempts = collection.auth.maxLoginAttempts\n }\n\n if (collection.auth.removeTokenFromResponses) {\n clientCollection.auth.removeTokenFromResponses = collection.auth.removeTokenFromResponses\n }\n\n if (collection.auth.useAPIKey) {\n clientCollection.auth.useAPIKey = collection.auth.useAPIKey\n }\n\n if (collection.auth.tokenExpiration) {\n clientCollection.auth.tokenExpiration = collection.auth.tokenExpiration\n }\n\n if (collection.auth.verify) {\n clientCollection.auth.verify = true\n }\n\n break\n\n case 'fields':\n clientCollection.fields = createClientFields({\n defaultIDType,\n fields: collection.fields,\n i18n,\n importMap,\n })\n\n break\n\n case 'hierarchy': {\n if (!collection.hierarchy || typeof collection.hierarchy !== 'object') {\n clientCollection.hierarchy = false\n break\n }\n\n // Strip slugify function as it can't cross server-client boundary\n const { slugify: _slugify, ...clientHierarchy } = collection.hierarchy\n clientCollection.hierarchy = clientHierarchy as ClientHierarchyConfig\n\n break\n }\n\n case 'labels':\n clientCollection.labels = {\n plural:\n typeof collection.labels.plural === 'function'\n ? collection.labels.plural({ i18n, t: i18n.t as TFunction })\n : collection.labels.plural,\n singular:\n typeof collection.labels.singular === 'function'\n ? collection.labels.singular({ i18n, t: i18n.t as TFunction })\n : collection.labels.singular,\n }\n\n break\n\n case 'upload':\n if (!collection.upload) {\n break\n }\n\n clientCollection.upload = {\n uploadInstructions: {\n useInAdmin: collection.upload.uploadInstructions?.useInAdmin ?? false,\n },\n } as ClientUploadConfig\n\n for (const uploadKey in collection.upload) {\n if (serverOnlyUploadProperties.includes(uploadKey as any)) {\n continue\n }\n\n if (uploadKey === 'imageSizes') {\n clientCollection.upload.imageSizes = collection.upload.imageSizes?.map((size) => {\n const sanitizedSize = { ...size }\n if ('generateImageName' in sanitizedSize) {\n delete sanitizedSize.generateImageName\n }\n return sanitizedSize\n })\n } else {\n ;(clientCollection.upload as any)[uploadKey] =\n collection.upload[uploadKey as keyof SanitizedUploadConfig]\n }\n }\n\n break\n\n default:\n ;(clientCollection as any)[key] = collection[key as keyof SanitizedCollectionConfig]\n }\n }\n\n return clientCollection as ClientCollectionConfig\n}\n\nexport const createClientCollectionConfigs = ({\n collections,\n defaultIDType,\n i18n,\n importMap,\n}: {\n collections: SanitizedCollectionConfig[]\n defaultIDType: Payload['config']['db']['defaultIDType']\n i18n: I18nClient\n importMap: ImportMap\n}): ClientCollectionConfig[] => {\n const clientCollections = new Array(collections.length)\n\n for (let i = 0; i < collections.length; i++) {\n const collection = collections[i]!\n\n clientCollections[i] = createClientCollectionConfig({\n collection,\n defaultIDType,\n i18n,\n importMap,\n })\n }\n\n return clientCollections\n}\n"],"names":["createClientFields","serverOnlyCollectionProperties","serverOnlyUploadProperties","serverOnlyCollectionAdminProperties","createClientCollectionConfig","collection","defaultIDType","i18n","importMap","clientCollection","key","includes","admin","adminKey","description","t","livePreview","breakpoints","preview","auth","cookies","depth","undefined","disableLocalStrategy","lockTime","loginWithUsername","maxLoginAttempts","removeTokenFromResponses","useAPIKey","tokenExpiration","verify","fields","hierarchy","slugify","_slugify","clientHierarchy","labels","plural","singular","upload","uploadInstructions","useInAdmin","uploadKey","imageSizes","map","size","sanitizedSize","generateImageName","createClientCollectionConfigs","collections","clientCollections","Array","length","i"],"mappings":"AAeA,SAASA,kBAAkB,QAAQ,gCAA+B;AAmElE,MAAMC,iCAA4E;IAChF;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CAID;AAED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Q;gBAClC;gBAEA;YAEF,KAAK;gBACH,IAAI,CAACjC,WAAWkC,MAAM,EAAE;oBACtB;gBACF;gBAEA9B,iBAAiB8B,MAAM,GAAG;oBACxBC,oBAAoB;wBAClBC,YAAYpC,WAAWkC,MAAM,CAACC,kBAAkB,EAAEC,cAAc;oBAClE;gBACF;gBAEA,IAAK,MAAMC,aAAarC,WAAWkC,MAAM,CAAE;oBACzC,IAAIrC,2BAA2BS,QAAQ,CAAC+B,YAAmB;wBACzD;oBACF;oBAEA,IAAIA,cAAc,cAAc;wBAC9BjC,iBAAiB8B,MAAM,CAACI,UAAU,GAAGtC,WAAWkC,MAAM,CAACI,UAAU,EAAEC,IAAI,CAACC;4BACtE,MAAMC,gBAAgB;gCAAE,GAAGD,IAAI;4BAAC;4BAChC,IAAI,uBAAuBC,eAAe;gCACxC,OAAOA,cAAcC,iBAAiB;4BACxC;4BACA,OAAOD;wBACT;oBACF,OAAO;;wBACHrC,iBAAiB8B,MAAM,AAAQ,CAACG,UAAU,GAC1CrC,WAAWkC,MAAM,CAACG,UAAyC;oBAC/D;gBACF;gBAEA;YAEF;;gBACIjC,gBAAwB,CAACC,IAAI,GAAGL,UAAU,CAACK,IAAuC;QACxF;IACF;IAEA,OAAOD;AACT,EAAC;AAED,OAAO,MAAMuC,gCAAgC,CAAC,EAC5CC,WAAW,EACX3C,aAAa,EACbC,IAAI,EACJC,SAAS,EAMV;IACC,MAAM0C,oBAAoB,IAAIC,MAAMF,YAAYG,MAAM;IAEtD,IAAK,IAAIC,IAAI,GAAGA,IAAIJ,YAAYG,MAAM,EAAEC,IAAK;QAC3C,MAAMhD,aAAa4C,WAAW,CAACI,EAAE;QAEjCH,iBAAiB,CAACG,EAAE,GAAGjD,6BAA6B;YAClDC;YACAC;YACAC;YACAC;QACF;IACF;IAEA,OAAO0C;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../../src/collections/config/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AACrF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAIlD;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,OAAO,CAAC,gBAAgB,CA8C9C,CAAA;AAED,eAAO,MAAM,6BAA6B,eAAgB,gBAAgB,KAAG,gBA0D5E,CAAA;AAED,eAAO,MAAM,uBAAuB,SAAU,gBAAgB,KAAG,
|
|
1
|
+
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../../src/collections/config/defaults.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AACrF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAIlD;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,OAAO,CAAC,gBAAgB,CA8C9C,CAAA;AAED,eAAO,MAAM,6BAA6B,eAAgB,gBAAgB,KAAG,gBA0D5E,CAAA;AAED,eAAO,MAAM,uBAAuB,SAAU,gBAAgB,KAAG,gBAsBhE,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,yBAAyB,EAAE,wBAIvC,CAAA;AAED,eAAO,MAAM,oCAAoC,sBAC5B,wBAAwB,KAC1C,wBAM6B,CAAA"}
|
|
@@ -119,6 +119,7 @@ export const addDefaultsToAuthConfig = (auth)=>{
|
|
|
119
119
|
secure: false,
|
|
120
120
|
...auth.cookies || {}
|
|
121
121
|
};
|
|
122
|
+
auth.depth = auth.depth ?? 0;
|
|
122
123
|
auth.forgotPassword = auth.forgotPassword ?? {};
|
|
123
124
|
auth.lockTime = auth.lockTime ?? 600000; // 10 minutes
|
|
124
125
|
auth.loginWithUsername = auth.loginWithUsername ?? false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/collections/config/defaults.ts"],"sourcesContent":["import type { IncomingAuthType, LoginWithUsernameOptions } from '../../auth/types.js'\nimport type { CollectionConfig } from './types.js'\n\nimport { defaultAccess } from '../../auth/defaultAccess.js'\n\n/**\n * @deprecated - remove in 4.0. This is error-prone, as mutating this object will affect any objects that use the defaults as a base.\n */\nexport const defaults: Partial<CollectionConfig> = {\n access: {\n create: defaultAccess,\n delete: defaultAccess,\n read: defaultAccess,\n unlock: defaultAccess,\n update: defaultAccess,\n },\n admin: {\n components: {},\n custom: {},\n enableRichTextLink: true,\n enableRichTextRelationship: true,\n pagination: {\n defaultLimit: 10,\n limits: [5, 10, 25, 50, 100],\n },\n useAsTitle: 'id',\n },\n auth: false,\n custom: {},\n endpoints: [],\n fields: [],\n hooks: {\n afterChange: [],\n afterDelete: [],\n afterForgotPassword: [],\n afterLogin: [],\n afterLogout: [],\n afterMe: [],\n afterOperation: [],\n afterRead: [],\n afterRefresh: [],\n beforeChange: [],\n beforeDelete: [],\n beforeLogin: [],\n beforeOperation: [],\n beforeRead: [],\n beforeValidate: [],\n me: [],\n refresh: [],\n },\n indexes: [],\n timestamps: true,\n upload: false,\n versions: true,\n}\n\nexport const addDefaultsToCollectionConfig = (collection: CollectionConfig): CollectionConfig => {\n collection.access = {\n create: defaultAccess,\n delete: defaultAccess,\n read: defaultAccess,\n unlock: defaultAccess,\n update: defaultAccess,\n ...(collection.access || {}),\n }\n\n collection.admin = {\n components: {},\n custom: {},\n enableRichTextLink: true,\n enableRichTextRelationship: true,\n useAsTitle: 'id',\n ...(collection.admin || {}),\n pagination: {\n defaultLimit: 10,\n limits: [5, 10, 25, 50, 100],\n ...(collection.admin?.pagination || {}),\n },\n }\n\n collection.auth = collection.auth ?? false\n collection.custom = collection.custom ?? {}\n collection.endpoints = collection.endpoints ?? []\n collection.fields = collection.fields ?? []\n collection.hierarchy = collection.hierarchy ?? false\n\n collection.hooks = {\n afterChange: [],\n afterDelete: [],\n afterForgotPassword: [],\n afterLogin: [],\n afterLogout: [],\n afterMe: [],\n afterOperation: [],\n afterRead: [],\n afterRefresh: [],\n beforeChange: [],\n beforeDelete: [],\n beforeLogin: [],\n beforeOperation: [],\n beforeRead: [],\n beforeValidate: [],\n me: [],\n refresh: [],\n ...(collection.hooks || {}),\n }\n\n collection.timestamps = collection.timestamps ?? true\n collection.upload = collection.upload ?? false\n collection.versions = collection.versions ?? true\n\n collection.indexes = collection.indexes ?? []\n\n return collection\n}\n\nexport const addDefaultsToAuthConfig = (auth: IncomingAuthType): IncomingAuthType => {\n auth.cookies = {\n sameSite: 'Lax',\n secure: false,\n ...(auth.cookies || {}),\n }\n\n auth.forgotPassword = auth.forgotPassword ?? {}\n auth.lockTime = auth.lockTime ?? 600000 // 10 minutes\n auth.loginWithUsername = auth.loginWithUsername ?? false\n auth.maxLoginAttempts = auth.maxLoginAttempts ?? 5\n auth.tokenExpiration = auth.tokenExpiration ?? 7200\n auth.useSessions = auth.useSessions ?? true\n auth.verify = auth.verify ?? false\n auth.strategies = auth.strategies ?? []\n\n if (!auth.disableLocalStrategy && auth.verify === true) {\n auth.verify = {}\n }\n\n return auth\n}\n\n/**\n * @deprecated - remove in 4.0. This is error-prone, as mutating this object will affect any objects that use the defaults as a base.\n */\nexport const loginWithUsernameDefaults: LoginWithUsernameOptions = {\n allowEmailLogin: false,\n requireEmail: false,\n requireUsername: true,\n}\n\nexport const addDefaultsToLoginWithUsernameConfig = (\n loginWithUsername: LoginWithUsernameOptions,\n): LoginWithUsernameOptions =>\n ({\n allowEmailLogin: false,\n requireEmail: false,\n requireUsername: true,\n ...(loginWithUsername || {}),\n }) as LoginWithUsernameOptions\n"],"names":["defaultAccess","defaults","access","create","delete","read","unlock","update","admin","components","custom","enableRichTextLink","enableRichTextRelationship","pagination","defaultLimit","limits","useAsTitle","auth","endpoints","fields","hooks","afterChange","afterDelete","afterForgotPassword","afterLogin","afterLogout","afterMe","afterOperation","afterRead","afterRefresh","beforeChange","beforeDelete","beforeLogin","beforeOperation","beforeRead","beforeValidate","me","refresh","indexes","timestamps","upload","versions","addDefaultsToCollectionConfig","collection","hierarchy","addDefaultsToAuthConfig","cookies","sameSite","secure","forgotPassword","lockTime","loginWithUsername","maxLoginAttempts","tokenExpiration","useSessions","verify","strategies","disableLocalStrategy","loginWithUsernameDefaults","allowEmailLogin","requireEmail","requireUsername","addDefaultsToLoginWithUsernameConfig"],"mappings":"AAGA,SAASA,aAAa,QAAQ,8BAA6B;AAE3D;;CAEC,GACD,OAAO,MAAMC,WAAsC;IACjDC,QAAQ;QACNC,QAAQH;QACRI,QAAQJ;QACRK,MAAML;QACNM,QAAQN;QACRO,QAAQP;IACV;IACAQ,OAAO;QACLC,YAAY,CAAC;QACbC,QAAQ,CAAC;QACTC,oBAAoB;QACpBC,4BAA4B;QAC5BC,YAAY;YACVC,cAAc;YACdC,QAAQ;gBAAC;gBAAG;gBAAI;gBAAI;gBAAI;aAAI;QAC9B;QACAC,YAAY;IACd;IACAC,MAAM;IACNP,QAAQ,CAAC;IACTQ,WAAW,EAAE;IACbC,QAAQ,EAAE;IACVC,OAAO;QACLC,aAAa,EAAE;QACfC,aAAa,EAAE;QACfC,qBAAqB,EAAE;QACvBC,YAAY,EAAE;QACdC,aAAa,EAAE;QACfC,SAAS,EAAE;QACXC,gBAAgB,EAAE;QAClBC,WAAW,EAAE;QACbC,cAAc,EAAE;QAChBC,cAAc,EAAE;QAChBC,cAAc,EAAE;QAChBC,aAAa,EAAE;QACfC,iBAAiB,EAAE;QACnBC,YAAY,EAAE;QACdC,gBAAgB,EAAE;QAClBC,IAAI,EAAE;QACNC,SAAS,EAAE;IACb;IACAC,SAAS,EAAE;IACXC,YAAY;IACZC,QAAQ;IACRC,UAAU;AACZ,EAAC;AAED,OAAO,MAAMC,gCAAgC,CAACC;IAC5CA,WAAWzC,MAAM,GAAG;QAClBC,QAAQH;QACRI,QAAQJ;QACRK,MAAML;QACNM,QAAQN;QACRO,QAAQP;QACR,GAAI2C,WAAWzC,MAAM,IAAI,CAAC,CAAC;IAC7B;IA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AA0B,CAAC5B;IACtCA,KAAK6B,OAAO,GAAG;QACbC,UAAU;QACVC,QAAQ;QACR,GAAI/B,KAAK6B,OAAO,IAAI,CAAC,CAAC;IACxB;IAEA7B,KAAKgC,
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/config/defaults.ts"],"sourcesContent":["import type { IncomingAuthType, LoginWithUsernameOptions } from '../../auth/types.js'\nimport type { CollectionConfig } from './types.js'\n\nimport { defaultAccess } from '../../auth/defaultAccess.js'\n\n/**\n * @deprecated - remove in 4.0. This is error-prone, as mutating this object will affect any objects that use the defaults as a base.\n */\nexport const defaults: Partial<CollectionConfig> = {\n access: {\n create: defaultAccess,\n delete: defaultAccess,\n read: defaultAccess,\n unlock: defaultAccess,\n update: defaultAccess,\n },\n admin: {\n components: {},\n custom: {},\n enableRichTextLink: true,\n enableRichTextRelationship: true,\n pagination: {\n defaultLimit: 10,\n limits: [5, 10, 25, 50, 100],\n },\n useAsTitle: 'id',\n },\n auth: false,\n custom: {},\n endpoints: [],\n fields: [],\n hooks: {\n afterChange: [],\n afterDelete: [],\n afterForgotPassword: [],\n afterLogin: [],\n afterLogout: [],\n afterMe: [],\n afterOperation: [],\n afterRead: [],\n afterRefresh: [],\n beforeChange: [],\n beforeDelete: [],\n beforeLogin: [],\n beforeOperation: [],\n beforeRead: [],\n beforeValidate: [],\n me: [],\n refresh: [],\n },\n indexes: [],\n timestamps: true,\n upload: false,\n versions: true,\n}\n\nexport const addDefaultsToCollectionConfig = (collection: CollectionConfig): CollectionConfig => {\n collection.access = {\n create: defaultAccess,\n delete: defaultAccess,\n read: defaultAccess,\n unlock: defaultAccess,\n update: defaultAccess,\n ...(collection.access || {}),\n }\n\n collection.admin = {\n components: {},\n custom: {},\n enableRichTextLink: true,\n enableRichTextRelationship: true,\n useAsTitle: 'id',\n ...(collection.admin || {}),\n pagination: {\n defaultLimit: 10,\n limits: [5, 10, 25, 50, 100],\n ...(collection.admin?.pagination || {}),\n },\n }\n\n collection.auth = collection.auth ?? false\n collection.custom = collection.custom ?? {}\n collection.endpoints = collection.endpoints ?? []\n collection.fields = collection.fields ?? []\n collection.hierarchy = collection.hierarchy ?? false\n\n collection.hooks = {\n afterChange: [],\n afterDelete: [],\n afterForgotPassword: [],\n afterLogin: [],\n afterLogout: [],\n afterMe: [],\n afterOperation: [],\n afterRead: [],\n afterRefresh: [],\n beforeChange: [],\n beforeDelete: [],\n beforeLogin: [],\n beforeOperation: [],\n beforeRead: [],\n beforeValidate: [],\n me: [],\n refresh: [],\n ...(collection.hooks || {}),\n }\n\n collection.timestamps = collection.timestamps ?? true\n collection.upload = collection.upload ?? false\n collection.versions = collection.versions ?? true\n\n collection.indexes = collection.indexes ?? []\n\n return collection\n}\n\nexport const addDefaultsToAuthConfig = (auth: IncomingAuthType): IncomingAuthType => {\n auth.cookies = {\n sameSite: 'Lax',\n secure: false,\n ...(auth.cookies || {}),\n }\n\n auth.depth = auth.depth ?? 0\n auth.forgotPassword = auth.forgotPassword ?? {}\n auth.lockTime = auth.lockTime ?? 600000 // 10 minutes\n auth.loginWithUsername = auth.loginWithUsername ?? false\n auth.maxLoginAttempts = auth.maxLoginAttempts ?? 5\n auth.tokenExpiration = auth.tokenExpiration ?? 7200\n auth.useSessions = auth.useSessions ?? true\n auth.verify = auth.verify ?? false\n auth.strategies = auth.strategies ?? []\n\n if (!auth.disableLocalStrategy && auth.verify === true) {\n auth.verify = {}\n }\n\n return auth\n}\n\n/**\n * @deprecated - remove in 4.0. This is error-prone, as mutating this object will affect any objects that use the defaults as a base.\n */\nexport const loginWithUsernameDefaults: LoginWithUsernameOptions = {\n allowEmailLogin: false,\n requireEmail: false,\n requireUsername: true,\n}\n\nexport const addDefaultsToLoginWithUsernameConfig = (\n loginWithUsername: LoginWithUsernameOptions,\n): LoginWithUsernameOptions =>\n ({\n allowEmailLogin: false,\n requireEmail: false,\n requireUsername: true,\n ...(loginWithUsername || {}),\n }) as LoginWithUsernameOptions\n"],"names":["defaultAccess","defaults","access","create","delete","read","unlock","update","admin","components","custom","enableRichTextLink","enableRichTextRelationship","pagination","defaultLimit","limits","useAsTitle","auth","endpoints","fields","hooks","afterChange","afterDelete","afterForgotPassword","afterLogin","afterLogout","afterMe","afterOperation","afterRead","afterRefresh","beforeChange","beforeDelete","beforeLogin","beforeOperation","beforeRead","beforeValidate","me","refresh","indexes","timestamps","upload","versions","addDefaultsToCollectionConfig","collection","hierarchy","addDefaultsToAuthConfig","cookies","sameSite","secure","depth","forgotPassword","lockTime","loginWithUsername","maxLoginAttempts","tokenExpiration","useSessions","verify","strategies","disableLocalStrategy","loginWithUsernameDefaults","allowEmailLogin","requireEmail","requireUsername","addDefaultsToLoginWithUsernameConfig"],"mappings":"AAGA,SAASA,aAAa,QAAQ,8BAA6B;AAE3D;;CAEC,GACD,OAAO,MAAMC,WAAsC;IACjDC,QAAQ;QACNC,QAAQH;QACRI,QAAQJ;QACRK,MAAML;QACNM,QAAQN;QACRO,QAAQP;IACV;IACAQ,OAAO;QACLC,YAAY,CAAC;QACbC,QAAQ,CAAC;QACTC,oBAAoB;QACpBC,4BAA4B;QAC5BC,YAAY;YACVC,cAAc;YACdC,QAAQ;gBAAC;gBAAG;gBAAI;gBAAI;gBAAI;aAAI;QAC9B;QACAC,YAAY;IACd;IACAC,MAAM;IACNP,QAAQ,CAAC;IACTQ,WAAW,EAAE;IACbC,QAAQ,EAAE;IACVC,OAAO;QACLC,aAAa,EAAE;QACfC,aAAa,EAAE;QACfC,qBAAqB,EAAE;QACvBC,YAAY,EAAE;QACdC,aAAa,EAAE;QACfC,SAAS,EAAE;QACXC,gBAAgB,EAAE;QAClBC,WAAW,EAAE;QACbC,cAAc,EAAE;QAChBC,cAAc,EAAE;QAChBC,cAAc,EAAE;QAChBC,aAAa,EAAE;QACfC,iBAAiB,EAAE;QACnBC,YAAY,EAAE;QACdC,gBAAgB,EAAE;QAClBC,IAAI,EAAE;QACNC,SAAS,EAAE;IACb;IACAC,SAAS,EAAE;IACXC,YAAY;IACZC,QAAQ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,4 @@
|
|
|
1
|
-
import type { Config
|
|
1
|
+
import type { Config } from '../../config/types.js';
|
|
2
2
|
import type { OrderableJoinInfo } from '../../fields/config/sanitizeJoinField.js';
|
|
3
3
|
import type { CollectionConfig, SanitizedCollectionConfig } from './types.js';
|
|
4
4
|
/**
|
|
@@ -6,14 +6,9 @@ import type { CollectionConfig, SanitizedCollectionConfig } from './types.js';
|
|
|
6
6
|
* Views without `path` will never be matched by the router and are silently ignored.
|
|
7
7
|
*/
|
|
8
8
|
export declare const warnOnInvalidCustomViews: (collection: CollectionConfig) => void;
|
|
9
|
-
export declare const sanitizeCollection: (config: Config, collection: CollectionConfig,
|
|
10
|
-
/**
|
|
11
|
-
* If this property is set, RichText fields won't be sanitized immediately. Instead, they will be added to this array as promises
|
|
12
|
-
* so that you can sanitize them together, after the config has been sanitized.
|
|
13
|
-
*/
|
|
14
|
-
richTextSanitizationPromises?: Array<(config: SanitizedConfig) => Promise<void>>, _validRelationships?: string[],
|
|
9
|
+
export declare const sanitizeCollection: (config: Config, collection: CollectionConfig, _validRelationships?: string[],
|
|
15
10
|
/**
|
|
16
11
|
* Tracker for orderable join fields - populated during sanitization
|
|
17
12
|
*/
|
|
18
|
-
orderableJoins?: OrderableJoinInfo[]) =>
|
|
13
|
+
orderableJoins?: OrderableJoinInfo[]) => SanitizedCollectionConfig;
|
|
19
14
|
//# sourceMappingURL=sanitize.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../../src/collections/config/sanitize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../../src/collections/config/sanitize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAA;AAEjF,OAAO,KAAK,EACV,gBAAgB,EAChB,yBAAyB,EAG1B,MAAM,YAAY,CAAA;AA0BnB;;;GAGG;AACH,eAAO,MAAM,wBAAwB,eAAgB,gBAAgB,KAAG,IAuBvE,CAAA;AAED,eAAO,MAAM,kBAAkB,WACrB,MAAM,cACF,gBAAgB,wBACN,MAAM,EAAE;AAC9B;;GAEG;iBACc,iBAAiB,EAAE,KACnC,yBA8SF,CAAA"}
|
|
@@ -37,10 +37,7 @@ import { validateUseAsTitle } from './useAsTitle.js';
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
|
-
export const sanitizeCollection =
|
|
41
|
-
* If this property is set, RichText fields won't be sanitized immediately. Instead, they will be added to this array as promises
|
|
42
|
-
* so that you can sanitize them together, after the config has been sanitized.
|
|
43
|
-
*/ richTextSanitizationPromises, _validRelationships, /**
|
|
40
|
+
export const sanitizeCollection = (config, collection, _validRelationships, /**
|
|
44
41
|
* Tracker for orderable join fields - populated during sanitization
|
|
45
42
|
*/ orderableJoins)=>{
|
|
46
43
|
if (collection._sanitized) {
|
|
@@ -96,7 +93,7 @@ export const sanitizeCollection = async (config, collection, /**
|
|
|
96
93
|
const validRelationships = _validRelationships ?? config.collections.map((c)=>c.slug) ?? [];
|
|
97
94
|
const joins = {};
|
|
98
95
|
const polymorphicJoins = [];
|
|
99
|
-
sanitized.fields =
|
|
96
|
+
sanitized.fields = sanitizeFields({
|
|
100
97
|
collectionConfig: sanitized,
|
|
101
98
|
config,
|
|
102
99
|
fields: sanitized.fields,
|
|
@@ -105,7 +102,6 @@ export const sanitizeCollection = async (config, collection, /**
|
|
|
105
102
|
orderableJoins,
|
|
106
103
|
parentIsLocalized: false,
|
|
107
104
|
polymorphicJoins,
|
|
108
|
-
richTextSanitizationPromises,
|
|
109
105
|
validRelationships
|
|
110
106
|
});
|
|
111
107
|
if (sanitized.endpoints !== false) {
|