payload 3.0.0-beta.95 → 3.0.0-beta.97
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 +4 -3
- package/dist/admin/RichText.d.ts.map +1 -1
- package/dist/admin/RichText.js.map +1 -1
- package/dist/admin/elements/Tab.d.ts +1 -1
- package/dist/admin/elements/Tab.d.ts.map +1 -1
- package/dist/admin/elements/Tab.js.map +1 -1
- package/dist/admin/forms/Description.d.ts +1 -1
- package/dist/admin/forms/Description.d.ts.map +1 -1
- package/dist/admin/forms/Description.js.map +1 -1
- package/dist/admin/forms/Error.d.ts +1 -1
- package/dist/admin/forms/Error.d.ts.map +1 -1
- package/dist/admin/forms/Error.js.map +1 -1
- package/dist/admin/forms/Form.d.ts +1 -1
- package/dist/admin/forms/Form.d.ts.map +1 -1
- package/dist/admin/forms/Form.js.map +1 -1
- package/dist/admin/forms/Label.d.ts +1 -1
- package/dist/admin/forms/Label.d.ts.map +1 -1
- package/dist/admin/forms/Label.js.map +1 -1
- package/dist/admin/types.d.ts +5 -5
- package/dist/admin/types.d.ts.map +1 -1
- package/dist/admin/types.js.map +1 -1
- package/dist/admin/views/types.d.ts +1 -1
- package/dist/admin/views/types.d.ts.map +1 -1
- package/dist/admin/views/types.js.map +1 -1
- package/dist/auth/executeAccess.d.ts.map +1 -1
- package/dist/auth/executeAccess.js +6 -2
- package/dist/auth/executeAccess.js.map +1 -1
- package/dist/auth/getAuthFields.d.ts.map +1 -1
- package/dist/auth/getAuthFields.js +3 -1
- package/dist/auth/getAuthFields.js.map +1 -1
- package/dist/auth/isLocked.d.ts.map +1 -1
- package/dist/auth/isLocked.js +3 -1
- package/dist/auth/isLocked.js.map +1 -1
- package/dist/auth/operations/auth.d.ts +1 -1
- package/dist/auth/operations/auth.d.ts.map +1 -1
- package/dist/auth/operations/auth.js +3 -1
- package/dist/auth/operations/auth.js.map +1 -1
- package/dist/auth/operations/forgotPassword.d.ts.map +1 -1
- package/dist/auth/operations/forgotPassword.js +6 -2
- package/dist/auth/operations/forgotPassword.js.map +1 -1
- package/dist/auth/operations/login.d.ts.map +1 -1
- package/dist/auth/operations/login.js +6 -2
- package/dist/auth/operations/login.js.map +1 -1
- package/dist/auth/operations/logout.d.ts.map +1 -1
- package/dist/auth/operations/logout.js +6 -2
- package/dist/auth/operations/logout.js.map +1 -1
- package/dist/auth/operations/me.d.ts.map +1 -1
- package/dist/auth/operations/me.js +6 -2
- package/dist/auth/operations/me.js.map +1 -1
- package/dist/auth/operations/refresh.d.ts.map +1 -1
- package/dist/auth/operations/refresh.js +6 -2
- package/dist/auth/operations/refresh.js.map +1 -1
- package/dist/auth/operations/registerFirstUser.d.ts.map +1 -1
- package/dist/auth/operations/registerFirstUser.js +6 -2
- package/dist/auth/operations/registerFirstUser.js.map +1 -1
- package/dist/auth/operations/resetPassword.d.ts.map +1 -1
- package/dist/auth/operations/resetPassword.js +6 -2
- package/dist/auth/operations/resetPassword.js.map +1 -1
- package/dist/auth/operations/unlock.d.ts.map +1 -1
- package/dist/auth/operations/unlock.js +3 -1
- package/dist/auth/operations/unlock.js.map +1 -1
- package/dist/auth/operations/verifyEmail.d.ts.map +1 -1
- package/dist/auth/operations/verifyEmail.js +9 -3
- package/dist/auth/operations/verifyEmail.js.map +1 -1
- package/dist/auth/strategies/jwt.js.map +1 -1
- package/dist/auth/strategies/local/authenticate.d.ts.map +1 -1
- package/dist/auth/strategies/local/authenticate.js +3 -1
- package/dist/auth/strategies/local/authenticate.js.map +1 -1
- package/dist/auth/strategies/local/register.d.ts.map +1 -1
- package/dist/auth/strategies/local/register.js +3 -1
- package/dist/auth/strategies/local/register.js.map +1 -1
- package/dist/auth/strategies/local/resetLoginAttempts.d.ts.map +1 -1
- package/dist/auth/strategies/local/resetLoginAttempts.js +3 -1
- package/dist/auth/strategies/local/resetLoginAttempts.js.map +1 -1
- package/dist/auth/types.d.ts +5 -5
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/auth/types.js.map +1 -1
- package/dist/bin/generateImportMap/iterateFields.js.map +1 -1
- package/dist/bin/generateTypes.d.ts.map +1 -1
- package/dist/bin/generateTypes.js +7 -3
- package/dist/bin/generateTypes.js.map +1 -1
- package/dist/bin/index.d.ts.map +1 -1
- package/dist/bin/index.js +3 -1
- package/dist/bin/index.js.map +1 -1
- package/dist/collections/config/client.d.ts +2 -2
- package/dist/collections/config/client.d.ts.map +1 -1
- package/dist/collections/config/client.js.map +1 -1
- package/dist/collections/config/reservedFieldNames.spec.js +4 -4
- package/dist/collections/config/reservedFieldNames.spec.js.map +1 -1
- package/dist/collections/config/sanitize.d.ts.map +1 -1
- package/dist/collections/config/sanitize.js +15 -6
- package/dist/collections/config/sanitize.js.map +1 -1
- package/dist/collections/config/types.d.ts +9 -9
- package/dist/collections/config/types.d.ts.map +1 -1
- package/dist/collections/config/types.js.map +1 -1
- package/dist/collections/dataloader.d.ts +1 -1
- package/dist/collections/dataloader.d.ts.map +1 -1
- package/dist/collections/dataloader.js +3 -1
- package/dist/collections/dataloader.js.map +1 -1
- package/dist/collections/operations/create.d.ts.map +1 -1
- package/dist/collections/operations/create.js +3 -1
- package/dist/collections/operations/create.js.map +1 -1
- package/dist/collections/operations/delete.d.ts.map +1 -1
- package/dist/collections/operations/delete.js +3 -1
- package/dist/collections/operations/delete.js.map +1 -1
- package/dist/collections/operations/deleteByID.d.ts.map +1 -1
- package/dist/collections/operations/deleteByID.js +9 -3
- package/dist/collections/operations/deleteByID.js.map +1 -1
- package/dist/collections/operations/duplicate.d.ts.map +1 -1
- package/dist/collections/operations/duplicate.js +9 -3
- package/dist/collections/operations/duplicate.js.map +1 -1
- package/dist/collections/operations/findByID.d.ts.map +1 -1
- package/dist/collections/operations/findByID.js +6 -2
- package/dist/collections/operations/findByID.js.map +1 -1
- package/dist/collections/operations/findVersionByID.d.ts.map +1 -1
- package/dist/collections/operations/findVersionByID.js +9 -3
- package/dist/collections/operations/findVersionByID.js.map +1 -1
- package/dist/collections/operations/restoreVersion.d.ts.map +1 -1
- package/dist/collections/operations/restoreVersion.js +6 -2
- package/dist/collections/operations/restoreVersion.js.map +1 -1
- package/dist/collections/operations/update.d.ts.map +1 -1
- package/dist/collections/operations/update.js +3 -1
- package/dist/collections/operations/update.js.map +1 -1
- package/dist/collections/operations/updateByID.d.ts.map +1 -1
- package/dist/collections/operations/updateByID.js +9 -3
- package/dist/collections/operations/updateByID.js.map +1 -1
- package/dist/collections/operations/utils.d.ts +1 -1
- package/dist/collections/operations/utils.d.ts.map +1 -1
- package/dist/collections/operations/utils.js.map +1 -1
- package/dist/config/client.d.ts +2 -2
- package/dist/config/client.d.ts.map +1 -1
- package/dist/config/client.js.map +1 -1
- package/dist/config/find.d.ts.map +1 -1
- package/dist/config/find.js +9 -3
- package/dist/config/find.js.map +1 -1
- package/dist/config/sanitize.d.ts.map +1 -1
- package/dist/config/sanitize.js +10 -5
- package/dist/config/sanitize.js.map +1 -1
- package/dist/config/types.d.ts +164 -35
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js.map +1 -1
- package/dist/database/combineQueries.d.ts +1 -1
- package/dist/database/combineQueries.d.ts.map +1 -1
- package/dist/database/combineQueries.js +9 -3
- package/dist/database/combineQueries.js.map +1 -1
- package/dist/database/getLocalizedPaths.d.ts.map +1 -1
- package/dist/database/getLocalizedPaths.js +3 -1
- package/dist/database/getLocalizedPaths.js.map +1 -1
- package/dist/database/migrations/readMigrationFiles.d.ts.map +1 -1
- package/dist/database/migrations/readMigrationFiles.js +3 -1
- package/dist/database/migrations/readMigrationFiles.js.map +1 -1
- package/dist/database/types.d.ts +3 -3
- package/dist/database/types.d.ts.map +1 -1
- package/dist/database/types.js.map +1 -1
- package/dist/fields/config/sanitize.d.ts +2 -1
- package/dist/fields/config/sanitize.d.ts.map +1 -1
- package/dist/fields/config/sanitize.js +28 -8
- package/dist/fields/config/sanitize.js.map +1 -1
- package/dist/fields/config/types.d.ts +56 -56
- package/dist/fields/config/types.d.ts.map +1 -1
- package/dist/fields/config/types.js.map +1 -1
- package/dist/fields/hooks/afterChange/index.d.ts +2 -2
- package/dist/fields/hooks/afterChange/index.d.ts.map +1 -1
- package/dist/fields/hooks/afterChange/index.js.map +1 -1
- package/dist/fields/hooks/afterChange/promise.d.ts +2 -2
- package/dist/fields/hooks/afterChange/promise.d.ts.map +1 -1
- package/dist/fields/hooks/afterChange/promise.js.map +1 -1
- package/dist/fields/hooks/afterChange/traverseFields.d.ts +2 -2
- package/dist/fields/hooks/afterChange/traverseFields.d.ts.map +1 -1
- package/dist/fields/hooks/afterChange/traverseFields.js.map +1 -1
- package/dist/fields/hooks/afterRead/index.d.ts +2 -2
- package/dist/fields/hooks/afterRead/index.d.ts.map +1 -1
- package/dist/fields/hooks/afterRead/index.js +3 -1
- package/dist/fields/hooks/afterRead/index.js.map +1 -1
- package/dist/fields/hooks/afterRead/promise.d.ts +2 -2
- package/dist/fields/hooks/afterRead/promise.d.ts.map +1 -1
- package/dist/fields/hooks/afterRead/promise.js +6 -2
- package/dist/fields/hooks/afterRead/promise.js.map +1 -1
- package/dist/fields/hooks/afterRead/traverseFields.d.ts +2 -2
- package/dist/fields/hooks/afterRead/traverseFields.d.ts.map +1 -1
- package/dist/fields/hooks/afterRead/traverseFields.js.map +1 -1
- package/dist/fields/hooks/beforeChange/getExistingRowDoc.d.ts.map +1 -1
- package/dist/fields/hooks/beforeChange/getExistingRowDoc.js +6 -2
- package/dist/fields/hooks/beforeChange/getExistingRowDoc.js.map +1 -1
- package/dist/fields/hooks/beforeChange/index.d.ts +2 -2
- package/dist/fields/hooks/beforeChange/index.d.ts.map +1 -1
- package/dist/fields/hooks/beforeChange/index.js.map +1 -1
- package/dist/fields/hooks/beforeChange/promise.d.ts +2 -2
- package/dist/fields/hooks/beforeChange/promise.d.ts.map +1 -1
- package/dist/fields/hooks/beforeChange/promise.js +18 -6
- package/dist/fields/hooks/beforeChange/promise.js.map +1 -1
- package/dist/fields/hooks/beforeChange/traverseFields.d.ts +2 -2
- package/dist/fields/hooks/beforeChange/traverseFields.d.ts.map +1 -1
- package/dist/fields/hooks/beforeChange/traverseFields.js.map +1 -1
- package/dist/fields/hooks/beforeValidate/index.d.ts +2 -2
- package/dist/fields/hooks/beforeValidate/index.d.ts.map +1 -1
- package/dist/fields/hooks/beforeValidate/index.js.map +1 -1
- package/dist/fields/hooks/beforeValidate/promise.d.ts +2 -2
- package/dist/fields/hooks/beforeValidate/promise.d.ts.map +1 -1
- package/dist/fields/hooks/beforeValidate/promise.js +21 -7
- package/dist/fields/hooks/beforeValidate/promise.js.map +1 -1
- package/dist/fields/hooks/beforeValidate/traverseFields.d.ts +2 -2
- package/dist/fields/hooks/beforeValidate/traverseFields.d.ts.map +1 -1
- package/dist/fields/hooks/beforeValidate/traverseFields.js.map +1 -1
- package/dist/fields/validations.d.ts +1 -1
- package/dist/fields/validations.d.ts.map +1 -1
- package/dist/fields/validations.js +57 -19
- package/dist/fields/validations.js.map +1 -1
- package/dist/globals/config/sanitize.d.ts.map +1 -1
- package/dist/globals/config/sanitize.js +45 -16
- package/dist/globals/config/sanitize.js.map +1 -1
- package/dist/globals/config/types.d.ts +2 -2
- package/dist/globals/config/types.d.ts.map +1 -1
- package/dist/globals/config/types.js.map +1 -1
- package/dist/globals/operations/docAccess.d.ts.map +1 -1
- package/dist/globals/operations/docAccess.js +3 -1
- package/dist/globals/operations/docAccess.js.map +1 -1
- package/dist/globals/operations/findVersionByID.d.ts.map +1 -1
- package/dist/globals/operations/findVersionByID.js +12 -4
- package/dist/globals/operations/findVersionByID.js.map +1 -1
- package/dist/globals/operations/restoreVersion.d.ts.map +1 -1
- package/dist/globals/operations/restoreVersion.js +3 -1
- package/dist/globals/operations/restoreVersion.js.map +1 -1
- package/dist/globals/operations/update.d.ts.map +1 -1
- package/dist/globals/operations/update.js +3 -1
- package/dist/globals/operations/update.js.map +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -7
- package/dist/index.js.map +1 -1
- package/dist/preferences/operations/findOne.d.ts.map +1 -1
- package/dist/preferences/operations/findOne.js +3 -1
- package/dist/preferences/operations/findOne.js.map +1 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/uploads/cropImage.d.ts.map +1 -1
- package/dist/uploads/cropImage.js +3 -1
- package/dist/uploads/cropImage.js.map +1 -1
- package/dist/uploads/deleteAssociatedFiles.d.ts.map +1 -1
- package/dist/uploads/deleteAssociatedFiles.js +3 -1
- package/dist/uploads/deleteAssociatedFiles.js.map +1 -1
- package/dist/uploads/docWithFilenameExists.d.ts.map +1 -1
- package/dist/uploads/docWithFilenameExists.js +3 -1
- package/dist/uploads/docWithFilenameExists.js.map +1 -1
- package/dist/uploads/formatFilesize.d.ts.map +1 -1
- package/dist/uploads/formatFilesize.js +3 -1
- package/dist/uploads/formatFilesize.js.map +1 -1
- package/dist/uploads/generateFileData.d.ts.map +1 -1
- package/dist/uploads/generateFileData.js +12 -4
- package/dist/uploads/generateFileData.js.map +1 -1
- package/dist/uploads/getBaseFields.d.ts.map +1 -1
- package/dist/uploads/getBaseFields.js +6 -2
- package/dist/uploads/getBaseFields.js.map +1 -1
- package/dist/uploads/getExternalFile.d.ts.map +1 -1
- package/dist/uploads/getExternalFile.js +3 -1
- package/dist/uploads/getExternalFile.js.map +1 -1
- package/dist/uploads/imageResizer.d.ts.map +1 -1
- package/dist/uploads/imageResizer.js +35 -13
- package/dist/uploads/imageResizer.js.map +1 -1
- package/dist/uploads/optionallyAppendMetadata.d.ts.map +1 -1
- package/dist/uploads/optionallyAppendMetadata.js +3 -1
- package/dist/uploads/optionallyAppendMetadata.js.map +1 -1
- package/dist/utilities/configToJSONSchema.d.ts.map +1 -1
- package/dist/utilities/configToJSONSchema.js +12 -4
- package/dist/utilities/configToJSONSchema.js.map +1 -1
- package/dist/utilities/createArrayFromCommaDelineated.d.ts.map +1 -1
- package/dist/utilities/createArrayFromCommaDelineated.js +3 -1
- package/dist/utilities/createArrayFromCommaDelineated.js.map +1 -1
- package/dist/utilities/createLocalReq.d.ts.map +1 -1
- package/dist/utilities/createLocalReq.js +28 -12
- package/dist/utilities/createLocalReq.js.map +1 -1
- package/dist/utilities/deepCopyObject.d.ts.map +1 -1
- package/dist/utilities/deepCopyObject.js +15 -5
- package/dist/utilities/deepCopyObject.js.map +1 -1
- package/dist/utilities/dependencies/versionUtils.d.ts.map +1 -1
- package/dist/utilities/dependencies/versionUtils.js +24 -8
- package/dist/utilities/dependencies/versionUtils.js.map +1 -1
- package/dist/utilities/getEntityPolicies.d.ts.map +1 -1
- package/dist/utilities/getEntityPolicies.js +9 -3
- package/dist/utilities/getEntityPolicies.js.map +1 -1
- package/dist/utilities/getObjectDotNotation.d.ts.map +1 -1
- package/dist/utilities/getObjectDotNotation.js +3 -1
- package/dist/utilities/getObjectDotNotation.js.map +1 -1
- package/dist/utilities/getSiblingData.d.ts.map +1 -1
- package/dist/utilities/getSiblingData.js +3 -1
- package/dist/utilities/getSiblingData.js.map +1 -1
- package/dist/utilities/isReactComponent.d.ts +3 -3
- package/dist/utilities/isReactComponent.d.ts.map +1 -1
- package/dist/utilities/isReactComponent.js.map +1 -1
- package/dist/utilities/isValidID.d.ts +1 -1
- package/dist/utilities/isValidID.d.ts.map +1 -1
- package/dist/utilities/isValidID.js +3 -1
- package/dist/utilities/isValidID.js.map +1 -1
- package/dist/utilities/logger.d.ts +8 -3
- package/dist/utilities/logger.d.ts.map +1 -1
- package/dist/utilities/logger.js +22 -14
- package/dist/utilities/logger.js.map +1 -1
- package/dist/utilities/reduceFieldsToValues.d.ts.map +1 -1
- package/dist/utilities/reduceFieldsToValues.js +3 -1
- package/dist/utilities/reduceFieldsToValues.js.map +1 -1
- package/dist/utilities/telemetry/conf/index.d.ts +1 -1
- package/dist/utilities/telemetry/conf/index.d.ts.map +1 -1
- package/dist/utilities/telemetry/conf/index.js +8 -8
- package/dist/utilities/telemetry/conf/index.js.map +1 -1
- package/dist/utilities/timestamp.d.ts.map +1 -1
- package/dist/utilities/timestamp.js +3 -1
- package/dist/utilities/timestamp.js.map +1 -1
- package/dist/versions/drafts/appendVersionToQueryKey.js +1 -1
- package/dist/versions/drafts/appendVersionToQueryKey.js.map +1 -1
- package/dist/versions/drafts/getQueryDraftsSort.d.ts.map +1 -1
- package/dist/versions/drafts/getQueryDraftsSort.js +3 -1
- package/dist/versions/drafts/getQueryDraftsSort.js.map +1 -1
- package/dist/versions/saveVersion.d.ts.map +1 -1
- package/dist/versions/saveVersion.js +18 -6
- package/dist/versions/saveVersion.js.map +1 -1
- package/dist/versions/types.d.ts +4 -4
- package/dist/versions/types.d.ts.map +1 -1
- package/dist/versions/types.js.map +1 -1
- package/package.json +7 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/auth/operations/unlock.ts"],"sourcesContent":["import httpStatus from 'http-status'\n\nimport type {\n AuthOperationsFromCollectionSlug,\n Collection,\n} from '../../collections/config/types.js'\nimport type { CollectionSlug } from '../../index.js'\nimport type { PayloadRequest, Where } from '../../types/index.js'\n\nimport { APIError } from '../../errors/index.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport executeAccess from '../executeAccess.js'\nimport { resetLoginAttempts } from '../strategies/local/resetLoginAttempts.js'\n\nexport type Arguments<TSlug extends CollectionSlug> = {\n collection: Collection\n data: AuthOperationsFromCollectionSlug<TSlug>['unlock']\n overrideAccess?: boolean\n req: PayloadRequest\n}\n\nexport const unlockOperation = async <TSlug extends CollectionSlug>(\n args: Arguments<TSlug>,\n): Promise<boolean> => {\n const {\n collection: { config: collectionConfig },\n overrideAccess,\n req: { locale },\n req,\n } = args\n\n const loginWithUsername = collectionConfig.auth.loginWithUsername\n const canLoginWithUsername = Boolean(loginWithUsername)\n const canLoginWithEmail = !loginWithUsername || loginWithUsername.allowEmailLogin\n\n const sanitizedEmail = canLoginWithEmail && (args.data?.email || '').toLowerCase().trim()\n const sanitizedUsername =\n (canLoginWithUsername &&\n 'username' in args.data &&\n typeof args.data.username === 'string' &&\n args.data.username.toLowerCase().trim()) ||\n null\n\n if (!sanitizedEmail && !sanitizedUsername) {\n throw new APIError(\n `Missing ${collectionConfig.auth.loginWithUsername ? 'username' : 'email'}.`,\n httpStatus.BAD_REQUEST,\n )\n }\n\n try {\n const shouldCommit = await initTransaction(req)\n\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n if (!overrideAccess) {\n await executeAccess({ req }, collectionConfig.access.unlock)\n }\n\n // /////////////////////////////////////\n // Unlock\n // /////////////////////////////////////\n\n let whereConstraint: Where = {}\n\n if (canLoginWithEmail && sanitizedEmail) {\n whereConstraint = {\n email: {\n equals: sanitizedEmail,\n },\n }\n } else if (canLoginWithUsername && sanitizedUsername) {\n whereConstraint = {\n username: {\n equals: sanitizedUsername,\n },\n }\n }\n\n const user = await req.payload.db.findOne({\n collection: collectionConfig.slug,\n locale,\n req,\n where: whereConstraint,\n })\n\n let result\n\n if (user) {\n await resetLoginAttempts({\n collection: collectionConfig,\n doc: user,\n payload: req.payload,\n req,\n })\n result = true\n } else {\n result = null\n }\n\n if (shouldCommit) await commitTransaction(req)\n\n return result\n } catch (error: unknown) {\n await killTransaction(req)\n throw error\n }\n}\n"],"names":["httpStatus","APIError","commitTransaction","initTransaction","killTransaction","executeAccess","resetLoginAttempts","unlockOperation","args","collection","config","collectionConfig","overrideAccess","req","locale","loginWithUsername","auth","canLoginWithUsername","Boolean","canLoginWithEmail","allowEmailLogin","sanitizedEmail","data","email","toLowerCase","trim","sanitizedUsername","username","BAD_REQUEST","shouldCommit","access","unlock","whereConstraint","equals","user","payload","db","findOne","slug","where","result","doc","error"],"mappings":"AAAA,OAAOA,gBAAgB,cAAa;AASpC,SAASC,QAAQ,QAAQ,wBAAuB;AAChD,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC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O,IAAIJ,wBAAwBS,mBAAmB;YACpDM,kBAAkB;gBAChBL,UAAU;oBACRM,QAAQP;gBACV;YACF;QACF;QAEA,MAAMQ,OAAO,MAAMrB,IAAIsB,OAAO,CAACC,EAAE,CAACC,OAAO,CAAC;YACxC5B,YAAYE,iBAAiB2B,IAAI;YACjCxB;YACAD;YACA0B,OAAOP;QACT;QAEA,IAAIQ;QAEJ,IAAIN,MAAM;YACR,MAAM5B,mBAAmB;gBACvBG,YAAYE;gBACZ8B,KAAKP;gBACLC,SAAStB,IAAIsB,OAAO;gBACpBtB;YACF;YACA2B,SAAS;QACX,OAAO;YACLA,SAAS;QACX;QAEA,IAAIX,cAAc,MAAM3B,kBAAkBW;
|
|
1
|
+
{"version":3,"sources":["../../../src/auth/operations/unlock.ts"],"sourcesContent":["import httpStatus from 'http-status'\n\nimport type {\n AuthOperationsFromCollectionSlug,\n Collection,\n} from '../../collections/config/types.js'\nimport type { CollectionSlug } from '../../index.js'\nimport type { PayloadRequest, Where } from '../../types/index.js'\n\nimport { APIError } from '../../errors/index.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport executeAccess from '../executeAccess.js'\nimport { resetLoginAttempts } from '../strategies/local/resetLoginAttempts.js'\n\nexport type Arguments<TSlug extends CollectionSlug> = {\n collection: Collection\n data: AuthOperationsFromCollectionSlug<TSlug>['unlock']\n overrideAccess?: boolean\n req: PayloadRequest\n}\n\nexport const unlockOperation = async <TSlug extends CollectionSlug>(\n args: Arguments<TSlug>,\n): Promise<boolean> => {\n const {\n collection: { config: collectionConfig },\n overrideAccess,\n req: { locale },\n req,\n } = args\n\n const loginWithUsername = collectionConfig.auth.loginWithUsername\n const canLoginWithUsername = Boolean(loginWithUsername)\n const canLoginWithEmail = !loginWithUsername || loginWithUsername.allowEmailLogin\n\n const sanitizedEmail = canLoginWithEmail && (args.data?.email || '').toLowerCase().trim()\n const sanitizedUsername =\n (canLoginWithUsername &&\n 'username' in args.data &&\n typeof args.data.username === 'string' &&\n args.data.username.toLowerCase().trim()) ||\n null\n\n if (!sanitizedEmail && !sanitizedUsername) {\n throw new APIError(\n `Missing ${collectionConfig.auth.loginWithUsername ? 'username' : 'email'}.`,\n httpStatus.BAD_REQUEST,\n )\n }\n\n try {\n const shouldCommit = await initTransaction(req)\n\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n if (!overrideAccess) {\n await executeAccess({ req }, collectionConfig.access.unlock)\n }\n\n // /////////////////////////////////////\n // Unlock\n // /////////////////////////////////////\n\n let whereConstraint: Where = {}\n\n if (canLoginWithEmail && sanitizedEmail) {\n whereConstraint = {\n email: {\n equals: sanitizedEmail,\n },\n }\n } else if (canLoginWithUsername && sanitizedUsername) {\n whereConstraint = {\n username: {\n equals: sanitizedUsername,\n },\n }\n }\n\n const user = await req.payload.db.findOne({\n collection: collectionConfig.slug,\n locale,\n req,\n where: whereConstraint,\n })\n\n let result\n\n if (user) {\n await resetLoginAttempts({\n collection: collectionConfig,\n doc: user,\n payload: req.payload,\n req,\n })\n result = true\n } else {\n result = null\n }\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return result\n } catch (error: unknown) {\n await killTransaction(req)\n throw error\n }\n}\n"],"names":["httpStatus","APIError","commitTransaction","initTransaction","killTransaction","executeAccess","resetLoginAttempts","unlockOperation","args","collection","config","collectionConfig","overrideAccess","req","locale","loginWithUsername","auth","canLoginWithUsername","Boolean","canLoginWithEmail","allowEmailLogin","sanitizedEmail","data","email","toLowerCase","trim","sanitizedUsername","username","BAD_REQUEST","shouldCommit","access","unlock","whereConstraint","equals","user","payload","db","findOne","slug","where","result","doc","error"],"mappings":"AAAA,OAAOA,gBAAgB,cAAa;AASpC,SAASC,QAAQ,QAAQ,wBAAuB;AAChD,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ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AChBL,UAAU;oBACRM,QAAQP;gBACV;YACF;QACF;QAEA,MAAMQ,OAAO,MAAMrB,IAAIsB,OAAO,CAACC,EAAE,CAACC,OAAO,CAAC;YACxC5B,YAAYE,iBAAiB2B,IAAI;YACjCxB;YACAD;YACA0B,OAAOP;QACT;QAEA,IAAIQ;QAEJ,IAAIN,MAAM;YACR,MAAM5B,mBAAmB;gBACvBG,YAAYE;gBACZ8B,KAAKP;gBACLC,SAAStB,IAAIsB,OAAO;gBACpBtB;YACF;YACA2B,SAAS;QACX,OAAO;YACLA,SAAS;QACX;QAEA,IAAIX,cAAc;YAChB,MAAM3B,kBAAkBW;QAC1B;QAEA,OAAO2B;IACT,EAAE,OAAOE,OAAgB;QACvB,MAAMtC,gBAAgBS;QACtB,MAAM6B;IACR;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verifyEmail.d.ts","sourceRoot":"","sources":["../../../src/auth/operations/verifyEmail.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAO1D,MAAM,MAAM,IAAI,GAAG;IACjB,UAAU,EAAE,UAAU,CAAA;IACtB,GAAG,EAAE,cAAc,CAAA;IACnB,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,eAAO,MAAM,oBAAoB,SAAgB,IAAI,KAAG,OAAO,CAAC,OAAO,
|
|
1
|
+
{"version":3,"file":"verifyEmail.d.ts","sourceRoot":"","sources":["../../../src/auth/operations/verifyEmail.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAO1D,MAAM,MAAM,IAAI,GAAG;IACjB,UAAU,EAAE,UAAU,CAAA;IACtB,GAAG,EAAE,cAAc,CAAA;IACnB,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,eAAO,MAAM,oBAAoB,SAAgB,IAAI,KAAG,OAAO,CAAC,OAAO,CA4CtE,CAAA;AAED,eAAe,oBAAoB,CAAA"}
|
|
@@ -19,8 +19,12 @@ export const verifyEmailOperation = async (args)=>{
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
|
-
if (!user)
|
|
23
|
-
|
|
22
|
+
if (!user) {
|
|
23
|
+
throw new APIError('Verification token is invalid.', httpStatus.FORBIDDEN);
|
|
24
|
+
}
|
|
25
|
+
if (user && user._verified === true) {
|
|
26
|
+
throw new APIError('This account has already been activated.', httpStatus.ACCEPTED);
|
|
27
|
+
}
|
|
24
28
|
await req.payload.db.updateOne({
|
|
25
29
|
id: user.id,
|
|
26
30
|
collection: collection.config.slug,
|
|
@@ -31,7 +35,9 @@ export const verifyEmailOperation = async (args)=>{
|
|
|
31
35
|
},
|
|
32
36
|
req
|
|
33
37
|
});
|
|
34
|
-
if (shouldCommit)
|
|
38
|
+
if (shouldCommit) {
|
|
39
|
+
await commitTransaction(req);
|
|
40
|
+
}
|
|
35
41
|
return true;
|
|
36
42
|
} catch (error) {
|
|
37
43
|
await killTransaction(req);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/auth/operations/verifyEmail.ts"],"sourcesContent":["import httpStatus from 'http-status'\n\nimport type { Collection } from '../../collections/config/types.js'\nimport type { PayloadRequest } from '../../types/index.js'\n\nimport { APIError } from '../../errors/index.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\n\nexport type Args = {\n collection: Collection\n req: PayloadRequest\n token: string\n}\n\nexport const verifyEmailOperation = async (args: Args): Promise<boolean> => {\n const { collection, req, token } = args\n if (!Object.prototype.hasOwnProperty.call(args, 'token')) {\n throw new APIError('Missing required data.', httpStatus.BAD_REQUEST)\n }\n\n try {\n const shouldCommit = await initTransaction(req)\n\n const user = await req.payload.db.findOne<any>({\n collection: collection.config.slug,\n req,\n where: {\n _verificationToken: { equals: token },\n },\n })\n\n if (!user) throw new APIError('Verification token is invalid.', httpStatus.FORBIDDEN)\n if (user && user._verified === true)\n throw new APIError('This account has already been activated.', httpStatus.ACCEPTED)\n\n await req.payload.db.updateOne({\n id: user.id,\n collection: collection.config.slug,\n data: {\n ...user,\n _verificationToken: null,\n _verified: true,\n },\n req,\n })\n\n if (shouldCommit) await commitTransaction(req)\n\n return true\n } catch (error: unknown) {\n await killTransaction(req)\n throw error\n }\n}\n\nexport default verifyEmailOperation\n"],"names":["httpStatus","APIError","commitTransaction","initTransaction","killTransaction","verifyEmailOperation","args","collection","req","token","Object","prototype","hasOwnProperty","call","BAD_REQUEST","shouldCommit","user","payload","db","findOne","config","slug","where","_verificationToken","equals","FORBIDDEN","_verified","ACCEPTED","updateOne","id","data","error"],"mappings":"AAAA,OAAOA,gBAAgB,cAAa;AAKpC,SAASC,QAAQ,QAAQ,wBAAuB;AAChD,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AAQpE,OAAO,MAAMC,uBAAuB,OAAOC;IACzC,MAAM,EAAEC,UAAU,EAAEC,GAAG,EAAEC,KAAK,EAAE,GAAGH;IACnC,IAAI,CAACI,OAAOC,SAAS,CAACC,cAAc,CAACC,IAAI,CAACP,MAAM,UAAU;QACxD,MAAM,IAAIL,SAAS,0BAA0BD,WAAWc,WAAW;IACrE;IAEA,IAAI;QACF,MAAMC,eAAe,MAAMZ,gBAAgBK;QAE3C,MAAMQ,OAAO,MAAMR,IAAIS,OAAO,CAACC,EAAE,CAACC,OAAO,CAAM;YAC7CZ,YAAYA,WAAWa,MAAM,CAACC,IAAI;YAClCb;YACAc,OAAO;gBACLC,oBAAoB;oBAAEC,QAAQf;gBAAM;YACtC;QACF;QAEA,IAAI,CAACO,MAAM,MAAM,IAAIf,SAAS,kCAAkCD,WAAWyB,SAAS;
|
|
1
|
+
{"version":3,"sources":["../../../src/auth/operations/verifyEmail.ts"],"sourcesContent":["import httpStatus from 'http-status'\n\nimport type { Collection } from '../../collections/config/types.js'\nimport type { PayloadRequest } from '../../types/index.js'\n\nimport { APIError } from '../../errors/index.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\n\nexport type Args = {\n collection: Collection\n req: PayloadRequest\n token: string\n}\n\nexport const verifyEmailOperation = async (args: Args): Promise<boolean> => {\n const { collection, req, token } = args\n if (!Object.prototype.hasOwnProperty.call(args, 'token')) {\n throw new APIError('Missing required data.', httpStatus.BAD_REQUEST)\n }\n\n try {\n const shouldCommit = await initTransaction(req)\n\n const user = await req.payload.db.findOne<any>({\n collection: collection.config.slug,\n req,\n where: {\n _verificationToken: { equals: token },\n },\n })\n\n if (!user) {\n throw new APIError('Verification token is invalid.', httpStatus.FORBIDDEN)\n }\n if (user && user._verified === true) {\n throw new APIError('This account has already been activated.', httpStatus.ACCEPTED)\n }\n\n await req.payload.db.updateOne({\n id: user.id,\n collection: collection.config.slug,\n data: {\n ...user,\n _verificationToken: null,\n _verified: true,\n },\n req,\n })\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return true\n } catch (error: unknown) {\n await killTransaction(req)\n throw error\n }\n}\n\nexport default verifyEmailOperation\n"],"names":["httpStatus","APIError","commitTransaction","initTransaction","killTransaction","verifyEmailOperation","args","collection","req","token","Object","prototype","hasOwnProperty","call","BAD_REQUEST","shouldCommit","user","payload","db","findOne","config","slug","where","_verificationToken","equals","FORBIDDEN","_verified","ACCEPTED","updateOne","id","data","error"],"mappings":"AAAA,OAAOA,gBAAgB,cAAa;AAKpC,SAASC,QAAQ,QAAQ,wBAAuB;AAChD,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AAQpE,OAAO,MAAMC,uBAAuB,OAAOC;IACzC,MAAM,EAAEC,UAAU,EAAEC,GAAG,EAAEC,KAAK,EAAE,GAAGH;IACnC,IAAI,CAACI,OAAOC,SAAS,CAACC,cAAc,CAACC,IAAI,CAACP,MAAM,UAAU;QACxD,MAAM,IAAIL,SAAS,0BAA0BD,WAAWc,WAAW;IACrE;IAEA,IAAI;QACF,MAAMC,eAAe,MAAMZ,gBAAgBK;QAE3C,MAAMQ,OAAO,MAAMR,IAAIS,OAAO,CAACC,EAAE,CAACC,OAAO,CAAM;YAC7CZ,YAAYA,WAAWa,MAAM,CAACC,IAAI;YAClCb;YACAc,OAAO;gBACLC,oBAAoB;oBAAEC,QAAQf;gBAAM;YACtC;QACF;QAEA,IAAI,CAACO,MAAM;YACT,MAAM,IAAIf,SAAS,kCAAkCD,WAAWyB,SAAS;QAC3E;QACA,IAAIT,QAAQA,KAAKU,SAAS,KAAK,MAAM;YACnC,MAAM,IAAIzB,SAAS,4CAA4CD,WAAW2B,QAAQ;QACpF;QAEA,MAAMnB,IAAIS,OAAO,CAACC,EAAE,CAACU,SAAS,CAAC;YAC7BC,IAAIb,KAAKa,EAAE;YACXtB,YAAYA,WAAWa,MAAM,CAACC,IAAI;YAClCS,MAAM;gBACJ,GAAGd,IAAI;gBACPO,oBAAoB;gBACpBG,WAAW;YACb;YACAlB;QACF;QAEA,IAAIO,cAAc;YAChB,MAAMb,kBAAkBM;QAC1B;QAEA,OAAO;IACT,EAAE,OAAOuB,OAAgB;QACvB,MAAM3B,gBAAgBI;QACtB,MAAMuB;IACR;AACF,EAAC;AAED,eAAe1B,qBAAoB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/auth/strategies/jwt.ts"],"sourcesContent":["import jwt from 'jsonwebtoken'\n\nimport type { Payload, Where } from '../../types/index.js'\nimport type { AuthStrategyFunction, User } from '../index.js'\n\nimport { extractJWT } from '../extractJWT.js'\n\ntype JWTToken = {\n collection: string\n id: string\n}\n\nasync function autoLogin({\n isGraphQL,\n payload,\n}: {\n isGraphQL: boolean\n payload: Payload\n}): Promise<{\n user:
|
|
1
|
+
{"version":3,"sources":["../../../src/auth/strategies/jwt.ts"],"sourcesContent":["import jwt from 'jsonwebtoken'\n\nimport type { Payload, Where } from '../../types/index.js'\nimport type { AuthStrategyFunction, User } from '../index.js'\n\nimport { extractJWT } from '../extractJWT.js'\n\ntype JWTToken = {\n collection: string\n id: string\n}\n\nasync function autoLogin({\n isGraphQL,\n payload,\n}: {\n isGraphQL: boolean\n payload: Payload\n}): Promise<{\n user: null | User\n}> {\n if (\n typeof payload?.config?.admin?.autoLogin !== 'object' ||\n payload.config.admin?.autoLogin.prefillOnly ||\n !payload?.config?.admin?.autoLogin ||\n (!payload.config.admin?.autoLogin.email && !payload.config.admin?.autoLogin.username)\n ) {\n return { user: null }\n }\n\n const collection = payload.collections[payload.config.admin.user]\n\n const where: Where = {\n or: [],\n }\n if (payload.config.admin?.autoLogin.email) {\n where.or.push({\n email: {\n equals: payload.config.admin?.autoLogin.email,\n },\n })\n } else if (payload.config.admin?.autoLogin.username) {\n where.or.push({\n username: {\n equals: payload.config.admin?.autoLogin.username,\n },\n })\n }\n\n const user = (\n await payload.find({\n collection: collection.config.slug,\n depth: isGraphQL ? 0 : collection.config.auth.depth,\n where,\n })\n ).docs[0]\n\n if (!user) {\n return { user: null }\n }\n user.collection = collection.config.slug\n user._strategy = 'local-jwt'\n\n return {\n user: user as User,\n }\n}\n\nexport const JWTAuthentication: AuthStrategyFunction = async ({\n headers,\n isGraphQL = false,\n payload,\n}) => {\n try {\n const token = extractJWT({ headers, payload })\n\n if (!token) {\n if (headers.get('DisableAutologin') !== 'true') {\n return await autoLogin({ isGraphQL, payload })\n }\n return { user: null }\n }\n\n const decodedPayload = jwt.verify(token, payload.secret) as jwt.JwtPayload & JWTToken\n\n const collection = payload.collections[decodedPayload.collection]\n\n const user = await payload.findByID({\n id: decodedPayload.id,\n collection: decodedPayload.collection,\n depth: isGraphQL ? 0 : collection.config.auth.depth,\n })\n\n if (user && (!collection.config.auth.verify || user._verified)) {\n user.collection = collection.config.slug\n user._strategy = 'local-jwt'\n return {\n user: user as User,\n }\n } else {\n if (headers.get('DisableAutologin') !== 'true') {\n return await autoLogin({ isGraphQL, payload })\n }\n return { user: null }\n }\n } catch (error) {\n if (headers.get('DisableAutologin') !== 'true') {\n return await autoLogin({ isGraphQL, payload })\n }\n return { user: null }\n }\n}\n"],"names":["jwt","extractJWT","autoLogin","isGraphQL","payload","config","admin","prefillOnly","email","username","user","collection","collections","where","or","push","equals","find","slug","depth","auth","docs","_strategy","JWTAuthentication","headers","token","get","decodedPayload","verify","secret","findByID","id","_verified","error"],"mappings":"AAAA,OAAOA,SAAS,eAAc;AAK9B,SAASC,UAAU,QAAQ,mBAAkB;AAO7C,eAAeC,UAAU,EACvBC,SAAS,EACTC,OAAO,EAIR;IAGC,IACE,OAAOA,SAASC,QAAQC,OAAOJ,cAAc,YAC7CE,QAAQC,MAAM,CAACC,KAAK,EAAEJ,UAAUK,eAChC,CAACH,SAASC,QAAQC,OAAOJ,aACxB,CAACE,QAAQC,MAAM,CAACC,KAAK,EAAEJ,UAAUM,SAAS,CAACJ,QAAQC,MAAM,CAACC,KAAK,EAAEJ,UAAUO,UAC5E;QACA,OAAO;YAAEC,MAAM;QAAK;IACtB;IAEA,MAAMC,aAAaP,QAAQQ,WAAW,CAACR,QAAQC,MAAM,CAACC,KAAK,CAACI,IAAI,CAAC;IAEjE,MAAMG,QAAe;QACnBC,IAAI,EAAE;IACR;IACA,IAAIV,QAAQC,MAAM,CAACC,KAAK,EAAEJ,UAAUM,OAAO;QACzCK,MAAMC,EAAE,CAACC,IAAI,CAAC;YACZP,OAAO;gBACLQ,QAAQZ,QAAQC,MAAM,CAACC,KAAK,EAAEJ,UAAUM;YAC1C;QACF;IACF,OAAO,IAAIJ,QAAQC,MAAM,CAACC,K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M,IAAIlB,KAAKsB,SAAS,AAAD,GAAI;YAC9DtB,KAAKC,UAAU,GAAGA,WAAWN,MAAM,CAACa,IAAI;YACxCR,KAAKY,SAAS,GAAG;YACjB,OAAO;gBACLZ,MAAMA;YACR;QACF,OAAO;YACL,IAAIc,QAAQE,GAAG,CAAC,wBAAwB,QAAQ;gBAC9C,OAAO,MAAMxB,UAAU;oBAAEC;oBAAWC;gBAAQ;YAC9C;YACA,OAAO;gBAAEM,MAAM;YAAK;QACtB;IACF,EAAE,OAAOuB,OAAO;QACd,IAAIT,QAAQE,GAAG,CAAC,wBAAwB,QAAQ;YAC9C,OAAO,MAAMxB,UAAU;gBAAEC;gBAAWC;YAAQ;QAC9C;QACA,OAAO;YAAEM,MAAM;QAAK;IACtB;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authenticate.d.ts","sourceRoot":"","sources":["../../../../src/auth/strategies/local/authenticate.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAA;AAEtE,KAAK,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,CAAA;AAE/C,KAAK,IAAI,GAAG;IACV,GAAG,EAAE,GAAG,CAAA;IACR,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,eAAO,MAAM,yBAAyB,sBAA6B,IAAI,KAAG,OAAO,CAAC,GAAG,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"authenticate.d.ts","sourceRoot":"","sources":["../../../../src/auth/strategies/local/authenticate.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAA;AAEtE,KAAK,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,CAAA;AAE/C,KAAK,IAAI,GAAG;IACV,GAAG,EAAE,GAAG,CAAA;IACR,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,eAAO,MAAM,yBAAyB,sBAA6B,IAAI,KAAG,OAAO,CAAC,GAAG,GAAG,IAAI,CA0B3F,CAAA"}
|
|
@@ -6,7 +6,9 @@ export const authenticateLocalStrategy = async ({ doc, password })=>{
|
|
|
6
6
|
if (typeof salt === 'string' && typeof hash === 'string') {
|
|
7
7
|
const res = await new Promise((resolve, reject)=>{
|
|
8
8
|
crypto.pbkdf2(password, salt, 25000, 512, 'sha256', (e, hashBuffer)=>{
|
|
9
|
-
if (e)
|
|
9
|
+
if (e) {
|
|
10
|
+
reject(null);
|
|
11
|
+
}
|
|
10
12
|
if (scmp(hashBuffer, Buffer.from(hash, 'hex'))) {
|
|
11
13
|
resolve(doc);
|
|
12
14
|
} else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/auth/strategies/local/authenticate.ts"],"sourcesContent":["import crypto from 'crypto'\nimport scmp from 'scmp'\n\nimport type { TypeWithID } from '../../../collections/config/types.js'\n\ntype Doc = Record<string, unknown> & TypeWithID\n\ntype Args = {\n doc: Doc\n password: string\n}\n\nexport const authenticateLocalStrategy = async ({ doc, password }: Args): Promise<Doc | null> => {\n try {\n const { hash, salt } = doc\n\n if (typeof salt === 'string' && typeof hash === 'string') {\n const res = await new Promise<Doc | null>((resolve, reject) => {\n crypto.pbkdf2(password, salt, 25000, 512, 'sha256', (e, hashBuffer) => {\n if (e) reject(null)\n\n if (scmp(hashBuffer, Buffer.from(hash, 'hex'))) {\n resolve(doc)\n } else {\n reject(null)\n }\n })\n })\n\n return res\n }\n\n return null\n } catch (err) {\n return null\n }\n}\n"],"names":["crypto","scmp","authenticateLocalStrategy","doc","password","hash","salt","res","Promise","resolve","reject","pbkdf2","e","hashBuffer","Buffer","from","err"],"mappings":"AAAA,OAAOA,YAAY,SAAQ;AAC3B,OAAOC,UAAU,OAAM;AAWvB,OAAO,MAAMC,4BAA4B,OAAO,EAAEC,GAAG,EAAEC,QAAQ,EAAQ;IACrE,IAAI;QACF,MAAM,EAAEC,IAAI,EAAEC,IAAI,EAAE,GAAGH;QAEvB,IAAI,OAAOG,SAAS,YAAY,OAAOD,SAAS,UAAU;YACxD,MAAME,MAAM,MAAM,IAAIC,QAAoB,CAACC,SAASC;gBAClDV,OAAOW,MAAM,CAACP,UAAUE,MAAM,OAAO,KAAK,UAAU,CAACM,GAAGC;oBACtD,IAAID,
|
|
1
|
+
{"version":3,"sources":["../../../../src/auth/strategies/local/authenticate.ts"],"sourcesContent":["import crypto from 'crypto'\nimport scmp from 'scmp'\n\nimport type { TypeWithID } from '../../../collections/config/types.js'\n\ntype Doc = Record<string, unknown> & TypeWithID\n\ntype Args = {\n doc: Doc\n password: string\n}\n\nexport const authenticateLocalStrategy = async ({ doc, password }: Args): Promise<Doc | null> => {\n try {\n const { hash, salt } = doc\n\n if (typeof salt === 'string' && typeof hash === 'string') {\n const res = await new Promise<Doc | null>((resolve, reject) => {\n crypto.pbkdf2(password, salt, 25000, 512, 'sha256', (e, hashBuffer) => {\n if (e) {\n reject(null)\n }\n\n if (scmp(hashBuffer, Buffer.from(hash, 'hex'))) {\n resolve(doc)\n } else {\n reject(null)\n }\n })\n })\n\n return res\n }\n\n return null\n } catch (err) {\n return null\n }\n}\n"],"names":["crypto","scmp","authenticateLocalStrategy","doc","password","hash","salt","res","Promise","resolve","reject","pbkdf2","e","hashBuffer","Buffer","from","err"],"mappings":"AAAA,OAAOA,YAAY,SAAQ;AAC3B,OAAOC,UAAU,OAAM;AAWvB,OAAO,MAAMC,4BAA4B,OAAO,EAAEC,GAAG,EAAEC,QAAQ,EAAQ;IACrE,IAAI;QACF,MAAM,EAAEC,IAAI,EAAEC,IAAI,EAAE,GAAGH;QAEvB,IAAI,OAAOG,SAAS,YAAY,OAAOD,SAAS,UAAU;YACxD,MAAME,MAAM,MAAM,IAAIC,QAAoB,CAACC,SAASC;gBAClDV,OAAOW,MAAM,CAACP,UAAUE,MAAM,OAAO,KAAK,UAAU,CAACM,GAAGC;oBACtD,IAAID,GAAG;wBACLF,OAAO;oBACT;oBAEA,IAAIT,KAAKY,YAAYC,OAAOC,IAAI,CAACV,MAAM,SAAS;wBAC9CI,QAAQN;oBACV,OAAO;wBACLO,OAAO;oBACT;gBACF;YACF;YAEA,OAAOH;QACT;QAEA,OAAO;IACT,EAAE,OAAOS,KAAK;QACZ,OAAO;IACT;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../../../src/auth/strategies/local/register.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAA;AACrF,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAS,MAAM,yBAAyB,CAAA;AAKpE,KAAK,IAAI,GAAG;IACV,UAAU,EAAE,yBAAyB,CAAA;IACrC,GAAG,EAAE,UAAU,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,qBAAqB,iDAM/B,IAAI,KAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../../../src/auth/strategies/local/register.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAA;AACrF,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAS,MAAM,yBAAyB,CAAA;AAKpE,KAAK,IAAI,GAAG;IACV,UAAU,EAAE,yBAAyB,CAAA;IACrC,GAAG,EAAE,UAAU,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,qBAAqB,iDAM/B,IAAI,KAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAwExC,CAAA"}
|
|
@@ -58,7 +58,9 @@ export const registerLocalStrategy = async ({ collection, doc, password, payload
|
|
|
58
58
|
const sanitizedDoc = {
|
|
59
59
|
...doc
|
|
60
60
|
};
|
|
61
|
-
if (sanitizedDoc.password)
|
|
61
|
+
if (sanitizedDoc.password) {
|
|
62
|
+
delete sanitizedDoc.password;
|
|
63
|
+
}
|
|
62
64
|
return payload.db.create({
|
|
63
65
|
collection: collection.slug,
|
|
64
66
|
data: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/auth/strategies/local/register.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { JsonObject, Payload } from '../../../index.js'\nimport type { PayloadRequest, Where } from '../../../types/index.js'\n\nimport { ValidationError } from '../../../errors/index.js'\nimport { generatePasswordSaltHash } from './generatePasswordSaltHash.js'\n\ntype Args = {\n collection: SanitizedCollectionConfig\n doc: JsonObject\n password: string\n payload: Payload\n req: PayloadRequest\n}\n\nexport const registerLocalStrategy = async ({\n collection,\n doc,\n password,\n payload,\n req,\n}: Args): Promise<Record<string, unknown>> => {\n const loginWithUsername = collection?.auth?.loginWithUsername\n\n let whereConstraint: Where\n\n if (!loginWithUsername) {\n whereConstraint = {\n email: {\n equals: doc.email,\n },\n }\n } else {\n whereConstraint = {\n or: [],\n }\n\n if (doc.email) {\n whereConstraint.or.push({\n email: {\n equals: doc.email,\n },\n })\n }\n\n if (doc.username) {\n whereConstraint.or.push({\n username: {\n equals: doc.username,\n },\n })\n }\n }\n\n const existingUser = await payload.find({\n collection: collection.slug,\n depth: 0,\n limit: 1,\n pagination: false,\n req,\n where: whereConstraint,\n })\n\n if (existingUser.docs.length > 0) {\n throw new ValidationError({\n collection: collection.slug,\n errors: [\n loginWithUsername\n ? {\n field: 'username',\n message: req.t('error:usernameAlreadyRegistered'),\n }\n : { field: 'email', message: req.t('error:userEmailAlreadyRegistered') },\n ],\n })\n }\n\n const { hash, salt } = await generatePasswordSaltHash({ collection, password, req })\n\n const sanitizedDoc = { ...doc }\n if (sanitizedDoc.password) delete sanitizedDoc.password\n\n return payload.db.create({\n collection: collection.slug,\n data: {\n ...sanitizedDoc,\n hash,\n salt,\n },\n req,\n })\n}\n"],"names":["ValidationError","generatePasswordSaltHash","registerLocalStrategy","collection","doc","password","payload","req","loginWithUsername","auth","whereConstraint","email","equals","or","push","username","existingUser","find","slug","depth","limit","pagination","where","docs","length","errors","field","message","t","hash","salt","sanitizedDoc","db","create","data"],"mappings":"AAIA,SAASA,eAAe,QAAQ,2BAA0B;AAC1D,SAASC,wBAAwB,QAAQ,gCAA+B;AAUxE,OAAO,MAAMC,wBAAwB,OAAO,EAC1CC,UAAU,EACVC,GAAG,EACHC,QAAQ,EACRC,OAAO,EACPC,GAAG,EACE;IACL,MAAMC,oBAAoBL,YAAYM,MAAMD;IAE5C,IAAIE;IAEJ,IAAI,CAACF,mBAAmB;QACtBE,kBAAkB;YAChBC,OAAO;gBACLC,QAAQR,IAAIO,KAAK;YACnB;QACF;IACF,OAAO;QACLD,kBAAkB;YAChBG,IAAI,EAAE;QACR;QAEA,IAAIT,IAAIO,KAAK,EAAE;YACbD,gBAAgBG,EAAE,CAACC,IAAI,CAAC;gBACtBH,OAAO;oBACLC,QAAQR,IAAIO,KAAK;gBACnB;YACF;QACF;QAEA,IAAIP,IAAIW,QAAQ,EAAE;YAChBL,gBAAgBG,EAAE,CAACC,IAAI,CAAC;gBACtBC,UAAU;oBACRH,QAAQR,IAAIW,QAAQ;gBACtB;YACF;QACF;IACF;IAEA,MAAMC,eAAe,MAAMV,QAAQW,IAAI,CAAC;QACtCd,YAAYA,WAAWe,IAAI;QAC3BC,OAAO;QACPC,OAAO;QACPC,YAAY;QACZd;QACAe,OAAOZ;IACT;IAEA,IAAIM,aAAaO,IAAI,CAACC,MAAM,GAAG,GAAG;QAChC,MAAM,IAAIxB,gBAAgB;YACxBG,YAAYA,WAAWe,IAAI;YAC3BO,QAAQ;gBACNjB,oBACI;oBACEkB,OAAO;oBACPC,SAASpB,IAAIqB,CAAC,CAAC;gBACjB,IACA;oBAAEF,OAAO;oBAASC,SAASpB,IAAIqB,CAAC,CAAC;gBAAoC;aAC1E;QACH;IACF;IAEA,MAAM,EAAEC,IAAI,EAAEC,IAAI,EAAE,GAAG,MAAM7B,yBAAyB;QAAEE;QAAYE;QAAUE;IAAI;IAElF,MAAMwB,eAAe;QAAE,GAAG3B,GAAG;IAAC;IAC9B,IAAI2B,aAAa1B,QAAQ,EAAE,OAAO0B,aAAa1B,QAAQ;
|
|
1
|
+
{"version":3,"sources":["../../../../src/auth/strategies/local/register.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from '../../../collections/config/types.js'\nimport type { JsonObject, Payload } from '../../../index.js'\nimport type { PayloadRequest, Where } from '../../../types/index.js'\n\nimport { ValidationError } from '../../../errors/index.js'\nimport { generatePasswordSaltHash } from './generatePasswordSaltHash.js'\n\ntype Args = {\n collection: SanitizedCollectionConfig\n doc: JsonObject\n password: string\n payload: Payload\n req: PayloadRequest\n}\n\nexport const registerLocalStrategy = async ({\n collection,\n doc,\n password,\n payload,\n req,\n}: Args): Promise<Record<string, unknown>> => {\n const loginWithUsername = collection?.auth?.loginWithUsername\n\n let whereConstraint: Where\n\n if (!loginWithUsername) {\n whereConstraint = {\n email: {\n equals: doc.email,\n },\n }\n } else {\n whereConstraint = {\n or: [],\n }\n\n if (doc.email) {\n whereConstraint.or.push({\n email: {\n equals: doc.email,\n },\n })\n }\n\n if (doc.username) {\n whereConstraint.or.push({\n username: {\n equals: doc.username,\n },\n })\n }\n }\n\n const existingUser = await payload.find({\n collection: collection.slug,\n depth: 0,\n limit: 1,\n pagination: false,\n req,\n where: whereConstraint,\n })\n\n if (existingUser.docs.length > 0) {\n throw new ValidationError({\n collection: collection.slug,\n errors: [\n loginWithUsername\n ? {\n field: 'username',\n message: req.t('error:usernameAlreadyRegistered'),\n }\n : { field: 'email', message: req.t('error:userEmailAlreadyRegistered') },\n ],\n })\n }\n\n const { hash, salt } = await generatePasswordSaltHash({ collection, password, req })\n\n const sanitizedDoc = { ...doc }\n if (sanitizedDoc.password) {\n delete sanitizedDoc.password\n }\n\n return payload.db.create({\n collection: collection.slug,\n data: {\n ...sanitizedDoc,\n hash,\n salt,\n },\n req,\n })\n}\n"],"names":["ValidationError","generatePasswordSaltHash","registerLocalStrategy","collection","doc","password","payload","req","loginWithUsername","auth","whereConstraint","email","equals","or","push","username","existingUser","find","slug","depth","limit","pagination","where","docs","length","errors","field","message","t","hash","salt","sanitizedDoc","db","create","data"],"mappings":"AAIA,SAASA,eAAe,QAAQ,2BAA0B;AAC1D,SAASC,wBAAwB,QAAQ,gCAA+B;AAUxE,OAAO,MAAMC,wBAAwB,OAAO,EAC1CC,UAAU,EACVC,GAAG,EACHC,QAAQ,EACRC,OAAO,EACPC,GAAG,EACE;IACL,MAAMC,oBAAoBL,YAAYM,MAAMD;IAE5C,IAAIE;IAEJ,IAAI,CAACF,mBAAmB;QACtBE,kBAAkB;YAChBC,OAAO;gBACLC,QAAQR,IAAIO,KAAK;YACnB;QACF;IACF,OAAO;QACLD,kBAAkB;YAChBG,IAAI,EAAE;QACR;QAEA,IAAIT,IAAIO,KAAK,EAAE;YACbD,gBAAgBG,EAAE,CAACC,IAAI,CAAC;gBACtBH,OAAO;oBACLC,QAAQR,IAAIO,KAAK;gBACnB;YACF;QACF;QAEA,IAAIP,IAAIW,QAAQ,EAAE;YAChBL,gBAAgBG,EAAE,CAACC,IAAI,CAAC;gBACtBC,UAAU;oBACRH,QAAQR,IAAIW,QAAQ;gBACtB;YACF;QACF;IACF;IAEA,MAAMC,eAAe,MAAMV,QAAQW,IAAI,CAAC;QACtCd,YAAYA,WAAWe,IAAI;QAC3BC,OAAO;QACPC,OAAO;QACPC,YAAY;QACZd;QACAe,OAAOZ;IACT;IAEA,IAAIM,aAAaO,IAAI,CAACC,MAAM,GAAG,GAAG;QAChC,MAAM,IAAIxB,gBAAgB;YACxBG,YAAYA,WAAWe,IAAI;YAC3BO,QAAQ;gBACNjB,oBACI;oBACEkB,OAAO;oBACPC,SAASpB,IAAIqB,CAAC,CAAC;gBACjB,IACA;oBAAEF,OAAO;oBAASC,SAASpB,IAAIqB,CAAC,CAAC;gBAAoC;aAC1E;QACH;IACF;IAEA,MAAM,EAAEC,IAAI,EAAEC,IAAI,EAAE,GAAG,MAAM7B,yBAAyB;QAAEE;QAAYE;QAAUE;IAAI;IAElF,MAAMwB,eAAe;QAAE,GAAG3B,GAAG;IAAC;IAC9B,IAAI2B,aAAa1B,QAAQ,EAAE;QACzB,OAAO0B,aAAa1B,QAAQ;IAC9B;IAEA,OAAOC,QAAQ0B,EAAE,CAACC,MAAM,CAAC;QACvB9B,YAAYA,WAAWe,IAAI;QAC3BgB,MAAM;YACJ,GAAGH,YAAY;YACfF;YACAC;QACF;QACAvB;IACF;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resetLoginAttempts.d.ts","sourceRoot":"","sources":["../../../../src/auth/strategies/local/resetLoginAttempts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAA;AACjG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAE7D,KAAK,IAAI,GAAG;IACV,UAAU,EAAE,yBAAyB,CAAA;IACrC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,CAAA;IACzC,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,kBAAkB,uCAK5B,IAAI,KAAG,OAAO,CAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"resetLoginAttempts.d.ts","sourceRoot":"","sources":["../../../../src/auth/strategies/local/resetLoginAttempts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAA;AACjG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAE7D,KAAK,IAAI,GAAG;IACV,UAAU,EAAE,yBAAyB,CAAA;IACrC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,UAAU,CAAA;IACzC,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,kBAAkB,uCAK5B,IAAI,KAAG,OAAO,CAAC,IAAI,CAerB,CAAA"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export const resetLoginAttempts = async ({ collection, doc, payload, req })=>{
|
|
2
|
-
if (!('lockUntil' in doc && typeof doc.lockUntil === 'string') || doc.loginAttempts === 0)
|
|
2
|
+
if (!('lockUntil' in doc && typeof doc.lockUntil === 'string') || doc.loginAttempts === 0) {
|
|
3
|
+
return;
|
|
4
|
+
}
|
|
3
5
|
await payload.update({
|
|
4
6
|
id: doc.id,
|
|
5
7
|
collection: collection.slug,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/auth/strategies/local/resetLoginAttempts.ts"],"sourcesContent":["import type { SanitizedCollectionConfig, TypeWithID } from '../../../collections/config/types.js'\nimport type { Payload } from '../../../index.js'\nimport type { PayloadRequest } from '../../../types/index.js'\n\ntype Args = {\n collection: SanitizedCollectionConfig\n doc: Record<string, unknown> & TypeWithID\n payload: Payload\n req: PayloadRequest\n}\n\nexport const resetLoginAttempts = async ({\n collection,\n doc,\n payload,\n req,\n}: Args): Promise<void> => {\n if (!('lockUntil' in doc && typeof doc.lockUntil === 'string') || doc.loginAttempts === 0) return\n await payload.update({\n id: doc.id,\n collection: collection.slug,\n data: {\n lockUntil: null,\n loginAttempts: 0,\n },\n depth: 0,\n overrideAccess: true,\n req,\n })\n}\n"],"names":["resetLoginAttempts","collection","doc","payload","req","lockUntil","loginAttempts","update","id","slug","data","depth","overrideAccess"],"mappings":"AAWA,OAAO,MAAMA,qBAAqB,OAAO,EACvCC,UAAU,EACVC,GAAG,EACHC,OAAO,EACPC,GAAG,EACE;IACL,IAAI,CAAE,CAAA,eAAeF,OAAO,OAAOA,IAAIG,SAAS,KAAK,QAAO,KAAMH,IAAII,aAAa,KAAK,GAAG;
|
|
1
|
+
{"version":3,"sources":["../../../../src/auth/strategies/local/resetLoginAttempts.ts"],"sourcesContent":["import type { SanitizedCollectionConfig, TypeWithID } from '../../../collections/config/types.js'\nimport type { Payload } from '../../../index.js'\nimport type { PayloadRequest } from '../../../types/index.js'\n\ntype Args = {\n collection: SanitizedCollectionConfig\n doc: Record<string, unknown> & TypeWithID\n payload: Payload\n req: PayloadRequest\n}\n\nexport const resetLoginAttempts = async ({\n collection,\n doc,\n payload,\n req,\n}: Args): Promise<void> => {\n if (!('lockUntil' in doc && typeof doc.lockUntil === 'string') || doc.loginAttempts === 0) {\n return\n }\n await payload.update({\n id: doc.id,\n collection: collection.slug,\n data: {\n lockUntil: null,\n loginAttempts: 0,\n },\n depth: 0,\n overrideAccess: true,\n req,\n })\n}\n"],"names":["resetLoginAttempts","collection","doc","payload","req","lockUntil","loginAttempts","update","id","slug","data","depth","overrideAccess"],"mappings":"AAWA,OAAO,MAAMA,qBAAqB,OAAO,EACvCC,UAAU,EACVC,GAAG,EACHC,OAAO,EACPC,GAAG,EACE;IACL,IAAI,CAAE,CAAA,eAAeF,OAAO,OAAOA,IAAIG,SAAS,KAAK,QAAO,KAAMH,IAAII,aAAa,KAAK,GAAG;QACzF;IACF;IACA,MAAMH,QAAQI,MAAM,CAAC;QACnBC,IAAIN,IAAIM,EAAE;QACVP,YAAYA,WAAWQ,IAAI;QAC3BC,MAAM;YACJL,WAAW;YACXC,eAAe;QACjB;QACAK,OAAO;QACPC,gBAAgB;QAChBR;IACF;AACF,EAAC"}
|
package/dist/auth/types.d.ts
CHANGED
|
@@ -93,7 +93,7 @@ export type AuthStrategyFunctionArgs = {
|
|
|
93
93
|
};
|
|
94
94
|
export type AuthStrategyResult = {
|
|
95
95
|
responseHeaders?: Headers;
|
|
96
|
-
user:
|
|
96
|
+
user: null | User;
|
|
97
97
|
};
|
|
98
98
|
export type AuthStrategyFunction = (args: AuthStrategyFunctionArgs) => AuthStrategyResult | Promise<AuthStrategyResult>;
|
|
99
99
|
export type AuthStrategy = {
|
|
@@ -122,7 +122,7 @@ export interface IncomingAuthType {
|
|
|
122
122
|
generateEmailSubject?: GenerateForgotPasswordEmailSubject;
|
|
123
123
|
};
|
|
124
124
|
lockTime?: number;
|
|
125
|
-
loginWithUsername?:
|
|
125
|
+
loginWithUsername?: boolean | LoginWithUsernameOptions;
|
|
126
126
|
maxLoginAttempts?: number;
|
|
127
127
|
removeTokenFromResponses?: true;
|
|
128
128
|
strategies?: AuthStrategy[];
|
|
@@ -142,9 +142,9 @@ export interface Auth extends Omit<DeepRequired<IncomingAuthType>, 'forgotPasswo
|
|
|
142
142
|
generateEmailHTML?: GenerateForgotPasswordEmailHTML;
|
|
143
143
|
generateEmailSubject?: GenerateForgotPasswordEmailSubject;
|
|
144
144
|
};
|
|
145
|
-
loginWithUsername:
|
|
146
|
-
verify?:
|
|
145
|
+
loginWithUsername: false | LoginWithUsernameOptions;
|
|
146
|
+
verify?: boolean | VerifyConfig;
|
|
147
147
|
}
|
|
148
|
-
export declare function hasWhereAccessResult(result:
|
|
148
|
+
export declare function hasWhereAccessResult(result: boolean | Where): result is Where;
|
|
149
149
|
export {};
|
|
150
150
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/auth/types.d.ts.map
CHANGED
|
@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,EAAE,uBAAuB,CAAA;IAC3C,oBAAoB,CAAC,EAAE,0BAA0B,CAAA;CAClD,CAAA;AAED,MAAM,WAAW,IACf,SAAQ,IAAI,CAAC,YAAY,CAAC,gBAAgB,CAAC,EAAE,gBAAgB,GAAG,mBAAmB,GAAG,QAAQ,CAAC;IAC/F,cAAc,CAAC,EAAE;QACf,iBAAiB,CAAC,EAAE,+BAA+B,CAAA;QACnD,oBAAoB,CAAC,EAAE,kCAAkC,CAAA;KAC1D,CAAA;IACD,iBAAiB,EAAE,KAAK,GAAG,wBAAwB,CAAA;IACnD,MAAM,CAAC,EAAE,OAAO,GAAG,YAAY,CAAA;CAChC;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,GAAG,KAAK,GAAG,MAAM,IAAI,KAAK,CAE7E"}
|
package/dist/auth/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/auth/types.ts"],"sourcesContent":["import type { DeepRequired } from 'ts-essentials'\n\nimport type { Payload } from '../index.js'\nimport type { PayloadRequest, Where } from '../types/index.js'\n\nexport type Permission = {\n permission: boolean\n where?: Record<string, unknown>\n}\n\nexport type FieldPermissions = {\n blocks?: {\n [blockSlug: string]: {\n fields: {\n [fieldName: string]: FieldPermissions\n }\n }\n }\n create: {\n permission: boolean\n }\n fields?: {\n [fieldName: string]: FieldPermissions\n }\n read: {\n permission: boolean\n }\n update: {\n permission: boolean\n }\n}\n\nexport type CollectionPermission = {\n create: Permission\n delete: Permission\n fields: {\n [fieldName: string]: FieldPermissions\n }\n read: Permission\n readVersions?: Permission\n update: Permission\n}\n\nexport type GlobalPermission = {\n fields: {\n [fieldName: string]: FieldPermissions\n }\n read: Permission\n readVersions?: Permission\n update: Permission\n}\n\nexport type DocumentPermissions = CollectionPermission | GlobalPermission\nexport type Permissions = {\n canAccessAdmin: boolean\n collections: {\n [collectionSlug: string]: CollectionPermission\n }\n globals?: {\n [globalSlug: string]: GlobalPermission\n }\n}\n\nexport type User = {\n [key: string]: any // This NEEDS to be an any, otherwise it breaks the Omit for ClientUser below\n collection: string\n email?: string\n id: number | string\n username?: string\n}\n\n/**\n * `collection` is not available one the client. It's only available on the server (req.user)\n * On the client, you can access the collection via config.admin.user. Config can be accessed using the useConfig() hook\n */\nexport type ClientUser = Omit<User, 'collection'>\n\ntype GenerateVerifyEmailHTML<TUser = any> = (args: {\n req: PayloadRequest\n token: string\n user: TUser\n}) => Promise<string> | string\n\ntype GenerateVerifyEmailSubject<TUser = any> = (args: {\n req: PayloadRequest\n token: string\n user: TUser\n}) => Promise<string> | string\n\ntype GenerateForgotPasswordEmailHTML<TUser = any> = (args?: {\n req?: PayloadRequest\n token?: string\n user?: TUser\n}) => Promise<string> | string\n\ntype GenerateForgotPasswordEmailSubject<TUser = any> = (args?: {\n req?: PayloadRequest\n token?: string\n user?: TUser\n}) => Promise<string> | string\n\nexport type AuthStrategyFunctionArgs = {\n headers: Request['headers']\n isGraphQL?: boolean\n payload: Payload\n}\n\nexport type AuthStrategyResult = {\n responseHeaders?: Headers\n user:
|
|
1
|
+
{"version":3,"sources":["../../src/auth/types.ts"],"sourcesContent":["import type { DeepRequired } from 'ts-essentials'\n\nimport type { Payload } from '../index.js'\nimport type { PayloadRequest, Where } from '../types/index.js'\n\nexport type Permission = {\n permission: boolean\n where?: Record<string, unknown>\n}\n\nexport type FieldPermissions = {\n blocks?: {\n [blockSlug: string]: {\n fields: {\n [fieldName: string]: FieldPermissions\n }\n }\n }\n create: {\n permission: boolean\n }\n fields?: {\n [fieldName: string]: FieldPermissions\n }\n read: {\n permission: boolean\n }\n update: {\n permission: boolean\n }\n}\n\nexport type CollectionPermission = {\n create: Permission\n delete: Permission\n fields: {\n [fieldName: string]: FieldPermissions\n }\n read: Permission\n readVersions?: Permission\n update: Permission\n}\n\nexport type GlobalPermission = {\n fields: {\n [fieldName: string]: FieldPermissions\n }\n read: Permission\n readVersions?: Permission\n update: Permission\n}\n\nexport type DocumentPermissions = CollectionPermission | GlobalPermission\nexport type Permissions = {\n canAccessAdmin: boolean\n collections: {\n [collectionSlug: string]: CollectionPermission\n }\n globals?: {\n [globalSlug: string]: GlobalPermission\n }\n}\n\nexport type User = {\n [key: string]: any // This NEEDS to be an any, otherwise it breaks the Omit for ClientUser below\n collection: string\n email?: string\n id: number | string\n username?: string\n}\n\n/**\n * `collection` is not available one the client. It's only available on the server (req.user)\n * On the client, you can access the collection via config.admin.user. Config can be accessed using the useConfig() hook\n */\nexport type ClientUser = Omit<User, 'collection'>\n\ntype GenerateVerifyEmailHTML<TUser = any> = (args: {\n req: PayloadRequest\n token: string\n user: TUser\n}) => Promise<string> | string\n\ntype GenerateVerifyEmailSubject<TUser = any> = (args: {\n req: PayloadRequest\n token: string\n user: TUser\n}) => Promise<string> | string\n\ntype GenerateForgotPasswordEmailHTML<TUser = any> = (args?: {\n req?: PayloadRequest\n token?: string\n user?: TUser\n}) => Promise<string> | string\n\ntype GenerateForgotPasswordEmailSubject<TUser = any> = (args?: {\n req?: PayloadRequest\n token?: string\n user?: TUser\n}) => Promise<string> | string\n\nexport type AuthStrategyFunctionArgs = {\n headers: Request['headers']\n isGraphQL?: boolean\n payload: Payload\n}\n\nexport type AuthStrategyResult = {\n responseHeaders?: Headers\n user: null | User\n}\n\nexport type AuthStrategyFunction = (\n args: AuthStrategyFunctionArgs,\n) => AuthStrategyResult | Promise<AuthStrategyResult>\nexport type AuthStrategy = {\n authenticate: AuthStrategyFunction\n name: string\n}\n\nexport type LoginWithUsernameOptions =\n | {\n allowEmailLogin?: false\n requireEmail?: boolean\n // If `allowEmailLogin` is false, `requireUsername` must be true (default: true)\n requireUsername?: true\n }\n | {\n allowEmailLogin?: true\n requireEmail?: boolean\n requireUsername?: boolean\n }\n\nexport interface IncomingAuthType {\n cookies?: {\n domain?: string\n sameSite?: 'Lax' | 'None' | 'Strict' | boolean\n secure?: boolean\n }\n depth?: number\n disableLocalStrategy?: true\n forgotPassword?: {\n generateEmailHTML?: GenerateForgotPasswordEmailHTML\n generateEmailSubject?: GenerateForgotPasswordEmailSubject\n }\n lockTime?: number\n loginWithUsername?: boolean | LoginWithUsernameOptions\n maxLoginAttempts?: number\n removeTokenFromResponses?: true\n strategies?: AuthStrategy[]\n tokenExpiration?: number\n useAPIKey?: boolean\n verify?:\n | {\n generateEmailHTML?: GenerateVerifyEmailHTML\n generateEmailSubject?: GenerateVerifyEmailSubject\n }\n | boolean\n}\n\nexport type VerifyConfig = {\n generateEmailHTML?: GenerateVerifyEmailHTML\n generateEmailSubject?: GenerateVerifyEmailSubject\n}\n\nexport interface Auth\n extends Omit<DeepRequired<IncomingAuthType>, 'forgotPassword' | 'loginWithUsername' | 'verify'> {\n forgotPassword?: {\n generateEmailHTML?: GenerateForgotPasswordEmailHTML\n generateEmailSubject?: GenerateForgotPasswordEmailSubject\n }\n loginWithUsername: false | LoginWithUsernameOptions\n verify?: boolean | VerifyConfig\n}\n\nexport function hasWhereAccessResult(result: boolean | Where): result is Where {\n return result && typeof result === 'object'\n}\n"],"names":["hasWhereAccessResult","result"],"mappings":"AA+KA,OAAO,SAASA,qBAAqBC,MAAuB;IAC1D,OAAOA,UAAU,OAAOA,WAAW;AACrC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/bin/generateImportMap/iterateFields.ts"],"sourcesContent":["import type { PayloadComponent, SanitizedConfig } from '../../config/types.js'\nimport type { Block, Field, Tab } from '../../fields/config/types.js'\nimport type { AddToImportMap, Imports, InternalImportMap } from './index.js'\n\nfunction hasKey<T, K extends string>(\n obj:
|
|
1
|
+
{"version":3,"sources":["../../../src/bin/generateImportMap/iterateFields.ts"],"sourcesContent":["import type { PayloadComponent, SanitizedConfig } from '../../config/types.js'\nimport type { Block, Field, Tab } from '../../fields/config/types.js'\nimport type { AddToImportMap, Imports, InternalImportMap } from './index.js'\n\nfunction hasKey<T, K extends string>(\n obj: null | T | undefined,\n key: K,\n): obj is { [P in K]: PayloadComponent | PayloadComponent[] } & T {\n return obj != null && Object.prototype.hasOwnProperty.call(obj, key)\n}\n\nexport function genImportMapIterateFields({\n addToImportMap,\n baseDir,\n config,\n fields,\n importMap,\n imports,\n}: {\n addToImportMap: AddToImportMap\n baseDir: string\n config: SanitizedConfig\n fields: Block[] | Field[] | Tab[]\n importMap: InternalImportMap\n imports: Imports\n}) {\n for (const field of fields) {\n if ('fields' in field) {\n genImportMapIterateFields({\n addToImportMap,\n baseDir,\n config,\n fields: field.fields,\n importMap,\n imports,\n })\n } else if (field.type === 'blocks') {\n genImportMapIterateFields({\n addToImportMap,\n baseDir,\n config,\n fields: field.blocks,\n importMap,\n imports,\n })\n } else if (field.type === 'tabs') {\n genImportMapIterateFields({\n addToImportMap,\n baseDir,\n config,\n fields: field.tabs,\n importMap,\n imports,\n })\n } else if (field.type === 'richText') {\n if (\n field?.editor &&\n typeof field.editor === 'object' &&\n field.editor.generateImportMap &&\n typeof field.editor.generateImportMap === 'function'\n ) {\n field.editor.generateImportMap({\n addToImportMap,\n baseDir,\n config,\n importMap,\n imports,\n })\n }\n }\n\n hasKey(field?.admin?.components, 'Label') && addToImportMap(field.admin.components.Label)\n\n hasKey(field?.admin?.components, 'Cell') && addToImportMap(field?.admin?.components?.Cell)\n\n hasKey(field?.admin?.components, 'Description') &&\n addToImportMap(field?.admin?.components?.Description)\n\n hasKey(field?.admin?.components, 'Field') && addToImportMap(field?.admin?.components?.Field)\n hasKey(field?.admin?.components, 'Filter') && addToImportMap(field?.admin?.components?.Filter)\n\n hasKey(field?.admin?.components, 'Error') && addToImportMap(field?.admin?.components?.Error)\n\n hasKey(field?.admin?.components, 'afterInput') &&\n addToImportMap(field?.admin?.components?.afterInput)\n\n hasKey(field?.admin?.components, 'beforeInput') &&\n addToImportMap(field?.admin?.components?.beforeInput)\n\n hasKey(field?.admin?.components, 'RowLabel') &&\n addToImportMap(field?.admin?.components?.RowLabel)\n }\n}\n"],"names":["hasKey","obj","key","Object","prototype","hasOwnProperty","call","genImportMapIterateFields","addToImportMap","baseDir","config","fields","importMap","imports","field","type","blocks","tabs","editor","generateImportMap","admin","components","Label","Cell","Description","Field","Filter","Error","afterInput","beforeInput","RowLabel"],"mappings":"AAIA,SAASA,OACPC,GAAyB,EACzBC,GAAM;IAEN,OAAOD,OAAO,QAAQE,OAAOC,SAAS,CAACC,cAAc,CAACC,IAAI,CAACL,KAAKC;AAClE;AAEA,OAAO,SAASK,0BAA0B,EACxCC,cAAc,EACdC,OAAO,EACPC,MAAM,EACNC,MAAM,EACNC,SAAS,EACTC,OAAO,EAQR;IACC,KAAK,MAAMC,SAASH,OAAQ;QAC1B,IAAI,YAAYG,OAAO;YACrBP,0BAA0B;gBACxBC;gBACAC;gBACAC;gBACAC,QAAQG,MAAMH,MAAM;gBACpBC;gBACAC;YACF;QACF,OAAO,IAAIC,MAAMC,IAAI,KAAK,UAAU;YAClCR,0BAA0B;gBACxBC;gBACAC;gBACAC;gBACAC,QAAQG,MAAME,MAAM;gBACpBJ;gBACAC;YACF;QACF,OAAO,IAAIC,MAAMC,IAAI,KAAK,QAAQ;YAChCR,0BAA0B;gBACxBC;gBACAC;gBACAC;gBACAC,QAAQG,MAAMG,IAAI;gBAClBL;gBACAC;YACF;QACF,OAAO,IAAIC,MAAMC,IAAI,KAAK,YAAY;YACpC,IACED,OAAOI,UACP,OAAOJ,MAAMI,MAAM,KAAK,YACxBJ,MAAMI,MAAM,CAACC,iBAAiB,IAC9B,OAAOL,MAAMI,MAAM,CAACC,iBAAiB,KAAK,YAC1C;gBACAL,MAAMI,MAAM,CAACC,iBAAiB,CAAC;oBAC7BX;oBACAC;oBACAC;oBACAE;oBACAC;gBACF;YACF;QACF;QAEAb,OAAOc,OAAOM,OAAOC,YAAY,YAAYb,eAAeM,MAAMM,KAAK,CAACC,UAAU,CAACC,KAAK;QAExFtB,OAAOc,OAAOM,OAAOC,YAAY,WAAWb,eAAeM,OAAOM,OAAOC,YAAYE;QAErFvB,OAAOc,OAAOM,OAAOC,YAAY,kBAC/Bb,eAAeM,OAAOM,OAAOC,YAAYG;QAE3CxB,OAAOc,OAAOM,OAAOC,YAAY,YAAYb,eAAeM,OAAOM,OAAOC,YAAYI;QACtFzB,OAAOc,OAAOM,OAAOC,YAAY,aAAab,eAAeM,OAAOM,OAAOC,YAAYK;QAEvF1B,OAAOc,OAAOM,OAAOC,YAAY,YAAYb,eAAeM,OAAOM,OAAOC,YAAYM;QAEtF3B,OAAOc,OAAOM,OAAOC,YAAY,iBAC/Bb,eAAeM,OAAOM,OAAOC,YAAYO;QAE3C5B,OAAOc,OAAOM,OAAOC,YAAY,kBAC/Bb,eAAeM,OAAOM,OAAOC,YAAYQ;QAE3C7B,OAAOc,OAAOM,OAAOC,YAAY,eAC/Bb,eAAeM,OAAOM,OAAOC,YAAYS;IAC7C;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateTypes.d.ts","sourceRoot":"","sources":["../../src/bin/generateTypes.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAKzD,wBAAsB,aAAa,CACjC,MAAM,EAAE,eAAe,EACvB,OAAO,CAAC,EAAE;IAAE,GAAG,EAAE,OAAO,CAAA;CAAE,GACzB,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"generateTypes.d.ts","sourceRoot":"","sources":["../../src/bin/generateTypes.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AAKzD,wBAAsB,aAAa,CACjC,MAAM,EAAE,eAAe,EACvB,OAAO,CAAC,EAAE;IAAE,GAAG,EAAE,OAAO,CAAA;CAAE,GACzB,OAAO,CAAC,IAAI,CAAC,CAkDf"}
|
|
@@ -3,10 +3,12 @@ import { compile } from 'json-schema-to-typescript';
|
|
|
3
3
|
import { configToJSONSchema } from '../utilities/configToJSONSchema.js';
|
|
4
4
|
import { getLogger } from '../utilities/logger.js';
|
|
5
5
|
export async function generateTypes(config, options) {
|
|
6
|
-
const logger = getLogger();
|
|
6
|
+
const logger = getLogger('payload', 'sync');
|
|
7
7
|
const outputFile = process.env.PAYLOAD_TS_OUTPUT_PATH || config.typescript.outputFile;
|
|
8
8
|
const shouldLog = options?.log ?? true;
|
|
9
|
-
if (shouldLog)
|
|
9
|
+
if (shouldLog) {
|
|
10
|
+
logger.info('Compiling TS types for Collections and Globals...');
|
|
11
|
+
}
|
|
10
12
|
const jsonSchema = configToJSONSchema(config, config.db.defaultIDType);
|
|
11
13
|
const declare = `declare module 'payload' {\n export interface GeneratedTypes extends Config {}\n}`;
|
|
12
14
|
const declareWithTSIgnoreError = `declare module 'payload' {\n // @ts-ignore \n export interface GeneratedTypes extends Config {}\n}`;
|
|
@@ -37,7 +39,9 @@ export async function generateTypes(config, options) {
|
|
|
37
39
|
// swallow err
|
|
38
40
|
}
|
|
39
41
|
fs.writeFileSync(outputFile, compiled);
|
|
40
|
-
if (shouldLog)
|
|
42
|
+
if (shouldLog) {
|
|
43
|
+
logger.info(`Types written to ${outputFile}`);
|
|
44
|
+
}
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
//# sourceMappingURL=generateTypes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/bin/generateTypes.ts"],"sourcesContent":["import fs from 'fs'\nimport { compile } from 'json-schema-to-typescript'\n\nimport type { SanitizedConfig } from '../config/types.js'\n\nimport { configToJSONSchema } from '../utilities/configToJSONSchema.js'\nimport { getLogger } from '../utilities/logger.js'\n\nexport async function generateTypes(\n config: SanitizedConfig,\n options?: { log: boolean },\n): Promise<void> {\n const logger = getLogger()\n const outputFile = process.env.PAYLOAD_TS_OUTPUT_PATH || config.typescript.outputFile\n\n const shouldLog = options?.log ?? true\n\n if (shouldLog) logger.info('Compiling TS types for Collections and Globals...')\n\n const jsonSchema = configToJSONSchema(config, config.db.defaultIDType)\n\n const declare = `declare module 'payload' {\\n export interface GeneratedTypes extends Config {}\\n}`\n const declareWithTSIgnoreError = `declare module 'payload' {\\n // @ts-ignore \\n export interface GeneratedTypes extends Config {}\\n}`\n\n let compiled = await compile(jsonSchema, 'Config', {\n bannerComment:\n '/* tslint:disable */\\n/* eslint-disable */\\n/**\\n* This file was automatically generated by Payload.\\n* DO NOT MODIFY IT BY HAND. Instead, modify your source Payload config,\\n* and re-run `payload generate:types` to regenerate this file.\\n*/',\n style: {\n singleQuote: true,\n },\n // Generates code for $defs that aren't referenced by the schema. Reason:\n // If a field defines an interfaceName, it should be included in the generated types\n // even if it's not used by another type. Reason: the user might want to use it in their own code.\n unreachableDefinitions: true,\n })\n\n if (config.typescript.declare !== false) {\n if (config.typescript.declare?.ignoreTSError) {\n compiled += `\\n\\n${declareWithTSIgnoreError}`\n } else {\n compiled += `\\n\\n${declare}`\n }\n }\n\n // Diff the compiled types against the existing types file\n try {\n const existingTypes = fs.readFileSync(outputFile, 'utf-8')\n\n if (compiled === existingTypes) {\n return\n }\n } catch (_) {\n // swallow err\n }\n\n fs.writeFileSync(outputFile, compiled)\n if (shouldLog) logger.info(`Types written to ${outputFile}`)\n}\n"],"names":["fs","compile","configToJSONSchema","getLogger","generateTypes","config","options","logger","outputFile","process","env","PAYLOAD_TS_OUTPUT_PATH","typescript","shouldLog","log","info","jsonSchema","db","defaultIDType","declare","declareWithTSIgnoreError","compiled","bannerComment","style","singleQuote","unreachableDefinitions","ignoreTSError","existingTypes","readFileSync","_","writeFileSync"],"mappings":"AAAA,OAAOA,QAAQ,KAAI;AACnB,SAASC,OAAO,QAAQ,4BAA2B;AAInD,SAASC,kBAAkB,QAAQ,qCAAoC;AACvE,SAASC,SAAS,QAAQ,yBAAwB;AAElD,OAAO,eAAeC,cACpBC,MAAuB,EACvBC,OAA0B;IAE1B,MAAMC,SAASJ;
|
|
1
|
+
{"version":3,"sources":["../../src/bin/generateTypes.ts"],"sourcesContent":["import fs from 'fs'\nimport { compile } from 'json-schema-to-typescript'\n\nimport type { SanitizedConfig } from '../config/types.js'\n\nimport { configToJSONSchema } from '../utilities/configToJSONSchema.js'\nimport { getLogger } from '../utilities/logger.js'\n\nexport async function generateTypes(\n config: SanitizedConfig,\n options?: { log: boolean },\n): Promise<void> {\n const logger = getLogger('payload', 'sync')\n const outputFile = process.env.PAYLOAD_TS_OUTPUT_PATH || config.typescript.outputFile\n\n const shouldLog = options?.log ?? true\n\n if (shouldLog) {\n logger.info('Compiling TS types for Collections and Globals...')\n }\n\n const jsonSchema = configToJSONSchema(config, config.db.defaultIDType)\n\n const declare = `declare module 'payload' {\\n export interface GeneratedTypes extends Config {}\\n}`\n const declareWithTSIgnoreError = `declare module 'payload' {\\n // @ts-ignore \\n export interface GeneratedTypes extends Config {}\\n}`\n\n let compiled = await compile(jsonSchema, 'Config', {\n bannerComment:\n '/* tslint:disable */\\n/* eslint-disable */\\n/**\\n* This file was automatically generated by Payload.\\n* DO NOT MODIFY IT BY HAND. Instead, modify your source Payload config,\\n* and re-run `payload generate:types` to regenerate this file.\\n*/',\n style: {\n singleQuote: true,\n },\n // Generates code for $defs that aren't referenced by the schema. Reason:\n // If a field defines an interfaceName, it should be included in the generated types\n // even if it's not used by another type. Reason: the user might want to use it in their own code.\n unreachableDefinitions: true,\n })\n\n if (config.typescript.declare !== false) {\n if (config.typescript.declare?.ignoreTSError) {\n compiled += `\\n\\n${declareWithTSIgnoreError}`\n } else {\n compiled += `\\n\\n${declare}`\n }\n }\n\n // Diff the compiled types against the existing types file\n try {\n const existingTypes = fs.readFileSync(outputFile, 'utf-8')\n\n if (compiled === existingTypes) {\n return\n }\n } catch (_) {\n // swallow err\n }\n\n fs.writeFileSync(outputFile, compiled)\n if (shouldLog) {\n logger.info(`Types written to ${outputFile}`)\n }\n}\n"],"names":["fs","compile","configToJSONSchema","getLogger","generateTypes","config","options","logger","outputFile","process","env","PAYLOAD_TS_OUTPUT_PATH","typescript","shouldLog","log","info","jsonSchema","db","defaultIDType","declare","declareWithTSIgnoreError","compiled","bannerComment","style","singleQuote","unreachableDefinitions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/dist/bin/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bin/index.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,GAAG,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bin/index.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,GAAG,qBA0Ef,CAAA"}
|
package/dist/bin/index.js
CHANGED
|
@@ -44,7 +44,9 @@ export const bin = async ()=>{
|
|
|
44
44
|
const configPath = findConfig();
|
|
45
45
|
const configPromise = await import(pathToFileURL(configPath).toString());
|
|
46
46
|
let config = await configPromise;
|
|
47
|
-
if (config.default)
|
|
47
|
+
if (config.default) {
|
|
48
|
+
config = await config.default;
|
|
49
|
+
}
|
|
48
50
|
const userBinScript = Array.isArray(config.bin) ? config.bin.find(({ key })=>key === script) : false;
|
|
49
51
|
if (userBinScript) {
|
|
50
52
|
try {
|
package/dist/bin/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/bin/index.ts"],"sourcesContent":["import minimist from 'minimist'\nimport { pathToFileURL } from 'node:url'\nimport path from 'path'\n\nimport type { BinScript } from '../config/types.js'\n\nimport { findConfig } from '../config/find.js'\nimport { generateImportMap } from './generateImportMap/index.js'\nimport { generateTypes } from './generateTypes.js'\nimport { info } from './info.js'\nimport { loadEnv } from './loadEnv.js'\nimport { migrate } from './migrate.js'\n\nexport const bin = async () => {\n loadEnv()\n\n const args = minimist(process.argv.slice(2))\n const script = (typeof args._[0] === 'string' ? args._[0] : '').toLowerCase()\n\n if (script === 'info') {\n await info()\n return\n }\n\n if (script === 'run') {\n const scriptPath = args._[1]\n if (!scriptPath) {\n console.error('Please provide a script path to run.')\n process.exit(1)\n }\n\n const absoluteScriptPath = path.resolve(process.cwd(), scriptPath)\n\n // Modify process.argv to remove 'run' and the script path\n const originalArgv = process.argv\n process.argv = [process.argv[0], process.argv[1], ...args._.slice(2)]\n\n try {\n await import(pathToFileURL(absoluteScriptPath).toString())\n } catch (error) {\n console.error(`Error running script: ${absoluteScriptPath}`)\n console.error(error)\n process.exit(1)\n } finally {\n // Restore original process.argv\n process.argv = originalArgv\n }\n return\n }\n\n const configPath = findConfig()\n const configPromise = await import(pathToFileURL(configPath).toString())\n let config = await configPromise\n if (config.default) config = await config.default\n\n const userBinScript = Array.isArray(config.bin)\n ? config.bin.find(({ key }) => key === script)\n : false\n\n if (userBinScript) {\n try {\n const script: BinScript = await import(pathToFileURL(userBinScript.scriptPath).toString())\n await script(config)\n } catch (err) {\n console.log(`Could not find associated bin script for the ${userBinScript.key} command`)\n console.error(err)\n }\n\n return\n }\n\n if (script.startsWith('migrate')) {\n return migrate({ config, parsedArgs: args }).then(() => process.exit(0))\n }\n\n if (script === 'generate:types') {\n return generateTypes(config)\n }\n\n if (script === 'generate:importmap') {\n return generateImportMap(config)\n }\n\n console.error(`Unknown script: \"${script}\".`)\n process.exit(1)\n}\n"],"names":["minimist","pathToFileURL","path","findConfig","generateImportMap","generateTypes","info","loadEnv","migrate","bin","args","process","argv","slice","script","_","toLowerCase","scriptPath","console","error","exit","absoluteScriptPath","resolve","cwd","originalArgv","toString","configPath","configPromise","config","default","userBinScript","Array","isArray","find","key","err","log","startsWith","parsedArgs","then"],"mappings":"AAAA,OAAOA,cAAc,WAAU;AAC/B,SAASC,aAAa,QAAQ,WAAU;AACxC,OAAOC,UAAU,OAAM;AAIvB,SAASC,UAAU,QAAQ,oBAAmB;AAC9C,SAASC,iBAAiB,QAAQ,+BAA8B;AAChE,SAASC,aAAa,QAAQ,qBAAoB;AAClD,SAASC,IAAI,QAAQ,YAAW;AAChC,SAASC,OAAO,QAAQ,eAAc;AACtC,SAASC,OAAO,QAAQ,eAAc;AAEtC,OAAO,MAAMC,MAAM;IACjBF;IAEA,MAAMG,OAAOV,SAASW,QAAQC,IAAI,CAACC,KAAK,CAAC;IACzC,MAAMC,SAAS,AAAC,CAAA,OAAOJ,KAAKK,CAAC,CAAC,EAAE,KAAK,WAAWL,KAAKK,CAAC,CAAC,EAAE,GAAG,EAAC,EAAGC,WAAW;IAE3E,IAAIF,WAAW,QAAQ;QACrB,MAAMR;QACN;IACF;IAEA,IAAIQ,WAAW,OAAO;QACpB,MAAMG,aAAaP,KAAKK,CAAC,CAAC,EAAE;QAC5B,IAAI,CAACE,YAAY;YACfC,QAAQC,KAAK,CAAC;YACdR,QAAQS,IAAI,CAAC;QACf;QAEA,MAAMC,qBAAqBnB,KAAKoB,OAAO,CAACX,QAAQY,GAAG,IAAIN;QAEvD,0DAA0D;QAC1D,MAAMO,eAAeb,QAAQC,IAAI;QACjCD,QAAQC,IAAI,GAAG;YAACD,QAAQC,IAAI,CAAC,EAAE;YAAED,QAAQC,IAAI,CAAC,EAAE;eAAKF,KAAKK,CAAC,CAACF,KAAK,CAAC;SAAG;QAErE,IAAI;YACF,MAAM,MAAM,CAACZ,cAAcoB,oBAAoBI,QAAQ;QACzD,EAAE,OAAON,OAAO;YACdD,QAAQC,KAAK,CAAC,CAAC,sBAAsB,EAAEE,mBAAmB,CAAC;YAC3DH,QAAQC,KAAK,CAACA;YACdR,QAAQS,IAAI,CAAC;QACf,SAAU;YACR,gCAAgC;YAChCT,QAAQC,IAAI,GAAGY;QACjB;QACA;IACF;IAEA,MAAME,aAAavB;IACnB,MAAMwB,gBAAgB,MAAM,MAAM,CAAC1B,cAAcyB,YAAYD,QAAQ;IACrE,IAAIG,SAAS,MAAMD;IACnB,IAAIC,OAAOC,OAAO,
|
|
1
|
+
{"version":3,"sources":["../../src/bin/index.ts"],"sourcesContent":["import minimist from 'minimist'\nimport { pathToFileURL } from 'node:url'\nimport path from 'path'\n\nimport type { BinScript } from '../config/types.js'\n\nimport { findConfig } from '../config/find.js'\nimport { generateImportMap } from './generateImportMap/index.js'\nimport { generateTypes } from './generateTypes.js'\nimport { info } from './info.js'\nimport { loadEnv } from './loadEnv.js'\nimport { migrate } from './migrate.js'\n\nexport const bin = async () => {\n loadEnv()\n\n const args = minimist(process.argv.slice(2))\n const script = (typeof args._[0] === 'string' ? args._[0] : '').toLowerCase()\n\n if (script === 'info') {\n await info()\n return\n }\n\n if (script === 'run') {\n const scriptPath = args._[1]\n if (!scriptPath) {\n console.error('Please provide a script path to run.')\n process.exit(1)\n }\n\n const absoluteScriptPath = path.resolve(process.cwd(), scriptPath)\n\n // Modify process.argv to remove 'run' and the script path\n const originalArgv = process.argv\n process.argv = [process.argv[0], process.argv[1], ...args._.slice(2)]\n\n try {\n await import(pathToFileURL(absoluteScriptPath).toString())\n } catch (error) {\n console.error(`Error running script: ${absoluteScriptPath}`)\n console.error(error)\n process.exit(1)\n } finally {\n // Restore original process.argv\n process.argv = originalArgv\n }\n return\n }\n\n const configPath = findConfig()\n const configPromise = await import(pathToFileURL(configPath).toString())\n let config = await configPromise\n if (config.default) {\n config = await config.default\n }\n\n const userBinScript = Array.isArray(config.bin)\n ? config.bin.find(({ key }) => key === script)\n : false\n\n if (userBinScript) {\n try {\n const script: BinScript = await import(pathToFileURL(userBinScript.scriptPath).toString())\n await script(config)\n } catch (err) {\n console.log(`Could not find associated bin script for the ${userBinScript.key} command`)\n console.error(err)\n }\n\n return\n }\n\n if (script.startsWith('migrate')) {\n return migrate({ config, parsedArgs: args }).then(() => process.exit(0))\n }\n\n if (script === 'generate:types') {\n return generateTypes(config)\n }\n\n if (script === 'generate:importmap') {\n return generateImportMap(config)\n }\n\n console.error(`Unknown script: \"${script}\".`)\n process.exit(1)\n}\n"],"names":["minimist","pathToFileURL","path","findConfig","generateImportMap","generateTypes","info","loadEnv","migrate","bin","args","process","argv","slice","script","_","toLowerCase","scriptPath","console","error","exit","absoluteScriptPath","resolve","cwd","originalArgv","toString","configPath","configPromise","config","default","userBinScript","Array","isArray","find","key","err","log","startsWith","parsedArgs","then"],"mappings":"AAAA,OAAOA,cAAc,WAAU;AAC/B,SAASC,aAAa,QAAQ,WAAU;AACxC,OAAOC,UAAU,OAAM;AAI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G,SAAS,MAAMD;IACnB,IAAIC,OAAOC,OAAO,EAAE;QAClBD,SAAS,MAAMA,OAAOC,OAAO;IAC/B;IAEA,MAAMC,gBAAgBC,MAAMC,OAAO,CAACJ,OAAOnB,GAAG,IAC1CmB,OAAOnB,GAAG,CAACwB,IAAI,CAAC,CAAC,EAAEC,GAAG,EAAE,GAAKA,QAAQpB,UACrC;IAEJ,IAAIgB,eAAe;QACjB,IAAI;YACF,MAAMhB,SAAoB,MAAM,MAAM,CAACb,cAAc6B,cAAcb,UAAU,EAAEQ,QAAQ;YACvF,MAAMX,OAAOc;QACf,EAAE,OAAOO,KAAK;YACZjB,QAAQkB,GAAG,CAAC,CAAC,6CAA6C,EAAEN,cAAcI,GAAG,CAAC,QAAQ,CAAC;YACvFhB,QAAQC,KAAK,CAACgB;QAChB;QAEA;IACF;IAEA,IAAIrB,OAAOuB,UAAU,CAAC,YAAY;QAChC,OAAO7B,QAAQ;YAAEoB;YAAQU,YAAY5B;QAAK,GAAG6B,IAAI,CAAC,IAAM5B,QAAQS,IAAI,CAAC;IACvE;IAEA,IAAIN,WAAW,kBAAkB;QAC/B,OAAOT,cAAcuB;IACvB;IAEA,IAAId,WAAW,sBAAsB;QACnC,OAAOV,kBAAkBwB;IAC3B;IAEAV,QAAQC,KAAK,CAAC,CAAC,iBAAiB,EAAEL,OAAO,EAAE,CAAC;IAC5CH,QAAQS,IAAI,CAAC;AACf,EAAC"}
|
|
@@ -10,11 +10,11 @@ export type ClientCollectionConfig = {
|
|
|
10
10
|
_isPreviewEnabled?: true;
|
|
11
11
|
admin: {
|
|
12
12
|
components: {
|
|
13
|
-
Description: MappedComponent;
|
|
14
13
|
afterList: MappedComponent[];
|
|
15
14
|
afterListTable: MappedComponent[];
|
|
16
15
|
beforeList: MappedComponent[];
|
|
17
16
|
beforeListTable: MappedComponent[];
|
|
17
|
+
Description: MappedComponent;
|
|
18
18
|
edit: {
|
|
19
19
|
PreviewButton: MappedComponent;
|
|
20
20
|
PublishButton: MappedComponent;
|
|
@@ -32,8 +32,8 @@ export type ClientCollectionConfig = {
|
|
|
32
32
|
versions: MappedView;
|
|
33
33
|
};
|
|
34
34
|
list: {
|
|
35
|
-
Component: MappedComponent;
|
|
36
35
|
actions: MappedComponent[];
|
|
36
|
+
Component: MappedComponent;
|
|
37
37
|
};
|
|
38
38
|
};
|
|
39
39
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/collections/config/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAC9E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,+BAA+B,EAAE,MAAM,uBAAuB,CAAA;AAC/F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAA;AAChE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAA;AAE3D,MAAM,MAAM,8BAA8B,GAAG,MAAM,IAAI,CACrD,yBAAyB,EACzB,QAAQ,GAAG,QAAQ,GAAG,WAAW,GAAG,OAAO,CAC5C,CAAA;AAED,MAAM,MAAM,mCAAmC,GAAG,MAAM,IAAI,CAC1D,yBAAyB,CAAC,OAAO,CAAC,EAClC,QAAQ,GAAG,SAAS,CACrB,CAAA;AAED,MAAM,MAAM,0BAA0B,GAAG,MAAM,IAAI,CACjD,yBAAyB,CAAC,QAAQ,CAAC,EACjC,gBAAgB,GAChB,0BAA0B,GAC1B,UAAU,GACV,uBAAuB,GACvB,cAAc,CACjB,CAAA;AAED,MAAM,MAAM,sBAAsB,GAAG;IACnC,iBAAiB,CAAC,EAAE,IAAI,CAAA;IACxB,KAAK,EAAE;QACL,UAAU,EAAE;YACV,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/collections/config/client.ts"],"names":[],"mappings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C,GAAG,EAAE,MAAM,GAAG,UAAU,CAAA;oBACzB,GAAG,EAAE,UAAU,CAAA;oBACf,OAAO,EAAE,UAAU,CAAA;oBACnB,WAAW,EAAE,UAAU,CAAA;oBACvB,OAAO,EAAE,UAAU,CAAA;oBACnB,QAAQ,EAAE,UAAU,CAAA;iBACrB,CAAA;gBACD,IAAI,EAAE;oBACJ,OAAO,EAAE,eAAe,EAAE,CAAA;oBAC1B,SAAS,EAAE,eAAe,CAAA;iBAC3B,CAAA;aACF,CAAA;SACF,CAAA;QACD,WAAW,CAAC,EAAE,iBAAiB,CAAA;QAC/B,WAAW,CAAC,EAAE,IAAI,CAAC,iBAAiB,EAAE,+BAA+B,CAAC,CAAA;KACvE,GAAG,IAAI,CACN,yBAAyB,CAAC,OAAO,CAAC,EAClC,YAAY,GAAG,aAAa,GAAG,aAAa,GAAG,mCAAmC,CACnF,CAAA;IACD,MAAM,EAAE,WAAW,EAAE,CAAA;CACtB,GAAG,IAAI,CAAC,yBAAyB,EAAE,OAAO,GAAG,QAAQ,GAAG,8BAA8B,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/collections/config/client.ts"],"sourcesContent":["import type { MappedComponent, StaticDescription } from '../../admin/types.js'\nimport type { MappedView } from '../../admin/views/types.js'\nimport type { LivePreviewConfig, ServerOnlyLivePreviewProperties } from '../../config/types.js'\nimport type { ClientField } from '../../fields/config/client.js'\nimport type { SanitizedCollectionConfig } from './types.js'\n\nexport type ServerOnlyCollectionProperties = keyof Pick<\n SanitizedCollectionConfig,\n 'access' | 'custom' | 'endpoints' | 'hooks'\n>\n\nexport type ServerOnlyCollectionAdminProperties = keyof Pick<\n SanitizedCollectionConfig['admin'],\n 'hidden' | 'preview'\n>\n\nexport type ServerOnlyUploadProperties = keyof Pick<\n SanitizedCollectionConfig['upload'],\n | 'adminThumbnail'\n | 'externalFileHeaderFilter'\n | 'handlers'\n | 'modifyResponseHeaders'\n | 'withMetadata'\n>\n\nexport type ClientCollectionConfig = {\n _isPreviewEnabled?: true\n admin: {\n components: {\n
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/config/client.ts"],"sourcesContent":["import type { MappedComponent, StaticDescription } from '../../admin/types.js'\nimport type { MappedView } from '../../admin/views/types.js'\nimport type { LivePreviewConfig, ServerOnlyLivePreviewProperties } from '../../config/types.js'\nimport type { ClientField } from '../../fields/config/client.js'\nimport type { SanitizedCollectionConfig } from './types.js'\n\nexport type ServerOnlyCollectionProperties = keyof Pick<\n SanitizedCollectionConfig,\n 'access' | 'custom' | 'endpoints' | 'hooks'\n>\n\nexport type ServerOnlyCollectionAdminProperties = keyof Pick<\n SanitizedCollectionConfig['admin'],\n 'hidden' | 'preview'\n>\n\nexport type ServerOnlyUploadProperties = keyof Pick<\n SanitizedCollectionConfig['upload'],\n | 'adminThumbnail'\n | 'externalFileHeaderFilter'\n | 'handlers'\n | 'modifyResponseHeaders'\n | 'withMetadata'\n>\n\nexport type ClientCollectionConfig = {\n _isPreviewEnabled?: true\n admin: {\n components: {\n afterList: MappedComponent[]\n afterListTable: MappedComponent[]\n beforeList: MappedComponent[]\n beforeListTable: MappedComponent[]\n Description: MappedComponent\n edit: {\n PreviewButton: MappedComponent\n PublishButton: MappedComponent\n SaveButton: MappedComponent\n SaveDraftButton: MappedComponent\n Upload: MappedComponent\n }\n views: {\n edit: {\n [key: string]: MappedView\n api: MappedView\n default: MappedView\n livePreview: MappedView\n version: MappedView\n versions: MappedView\n }\n list: {\n actions: MappedComponent[]\n Component: MappedComponent\n }\n }\n }\n description?: StaticDescription\n livePreview?: Omit<LivePreviewConfig, ServerOnlyLivePreviewProperties>\n } & Omit<\n SanitizedCollectionConfig['admin'],\n 'components' | 'description' | 'livePreview' | ServerOnlyCollectionAdminProperties\n >\n fields: ClientField[]\n} & Omit<SanitizedCollectionConfig, 'admin' | 'fields' | ServerOnlyCollectionProperties>\n"],"names":[],"mappings":"AAyBA,WAsCwF"}
|
|
@@ -63,12 +63,12 @@ describe('reservedFieldNames - collections -', ()=>{
|
|
|
63
63
|
describe('auth -', ()=>{
|
|
64
64
|
const collectionWithAuth = {
|
|
65
65
|
slug: 'collection-with-auth',
|
|
66
|
-
fields: [],
|
|
67
66
|
auth: {
|
|
68
|
-
|
|
67
|
+
loginWithUsername: true,
|
|
69
68
|
useAPIKey: true,
|
|
70
|
-
|
|
71
|
-
}
|
|
69
|
+
verify: true
|
|
70
|
+
},
|
|
71
|
+
fields: []
|
|
72
72
|
};
|
|
73
73
|
it('should throw on hash', async ()=>{
|
|
74
74
|
const fields = [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/collections/config/reservedFieldNames.spec.ts"],"sourcesContent":["import type { Config } from '../../config/types.js'\nimport type { CollectionConfig, Field } from '../../index.js'\n\nimport { ReservedFieldName } from '../../errors/index.js'\nimport { sanitizeCollection } from './sanitize.js'\n\ndescribe('reservedFieldNames - collections -', () => {\n const config = {\n collections: [],\n globals: [],\n } as Partial<Config>\n\n describe('uploads -', () => {\n const collectionWithUploads: CollectionConfig = {\n slug: 'collection-with-uploads',\n fields: [],\n upload: true,\n }\n\n it('should throw on file', async () => {\n const fields: Field[] = [\n {\n name: 'file',\n type: 'text',\n label: 'some-collection',\n },\n ]\n await expect(async () => {\n await sanitizeCollection(\n // @ts-expect-error\n {\n ...config,\n collections: [\n {\n ...collectionWithUploads,\n fields,\n },\n ],\n },\n {\n ...collectionWithUploads,\n fields,\n },\n )\n }).rejects.toThrow(ReservedFieldName)\n })\n\n it('should not throw on a custom field', async () => {\n const fields: Field[] = [\n {\n name: 'customField',\n type: 'text',\n label: 'some-collection',\n },\n ]\n await expect(async () => {\n await sanitizeCollection(\n // @ts-expect-error\n {\n ...config,\n collections: [\n {\n ...collectionWithUploads,\n fields,\n },\n ],\n },\n {\n ...collectionWithUploads,\n fields,\n },\n )\n }).not.toThrow()\n })\n })\n\n describe('auth -', () => {\n const collectionWithAuth: CollectionConfig = {\n slug: 'collection-with-auth',\n
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/config/reservedFieldNames.spec.ts"],"sourcesContent":["import type { Config } from '../../config/types.js'\nimport type { CollectionConfig, Field } from '../../index.js'\n\nimport { ReservedFieldName } from '../../errors/index.js'\nimport { sanitizeCollection } from './sanitize.js'\n\ndescribe('reservedFieldNames - collections -', () => {\n const config = {\n collections: [],\n globals: [],\n } as Partial<Config>\n\n describe('uploads -', () => {\n const collectionWithUploads: CollectionConfig = {\n slug: 'collection-with-uploads',\n fields: [],\n upload: true,\n }\n\n it('should throw on file', async () => {\n const fields: Field[] = [\n {\n name: 'file',\n type: 'text',\n label: 'some-collection',\n },\n ]\n await expect(async () => {\n await sanitizeCollection(\n // @ts-expect-error\n {\n ...config,\n collections: [\n {\n ...collectionWithUploads,\n fields,\n },\n ],\n },\n {\n ...collectionWithUploads,\n fields,\n },\n )\n }).rejects.toThrow(ReservedFieldName)\n })\n\n it('should not throw on a custom field', async () => {\n const fields: Field[] = [\n {\n name: 'customField',\n type: 'text',\n label: 'some-collection',\n },\n ]\n await expect(async () => {\n await sanitizeCollection(\n // @ts-expect-error\n {\n ...config,\n collections: [\n {\n ...collectionWithUploads,\n fields,\n },\n ],\n },\n {\n ...collectionWithUploads,\n fields,\n },\n )\n }).not.toThrow()\n })\n })\n\n describe('auth -', () => {\n const collectionWithAuth: CollectionConfig = {\n slug: 'collection-with-auth',\n auth: {\n loginWithUsername: true,\n useAPIKey: true,\n verify: true,\n },\n fields: [],\n }\n\n it('should throw on hash', async () => {\n const fields: Field[] = [\n {\n name: 'hash',\n type: 'text',\n label: 'some-collection',\n },\n ]\n await expect(async () => {\n await sanitizeCollection(\n // @ts-expect-error\n {\n ...config,\n collections: [\n {\n ...collectionWithAuth,\n fields,\n },\n ],\n },\n {\n ...collectionWithAuth,\n fields,\n },\n )\n }).rejects.toThrow(ReservedFieldName)\n })\n\n it('should throw on salt', async () => {\n const fields: Field[] = [\n {\n name: 'salt',\n type: 'text',\n label: 'some-collection',\n },\n ]\n await expect(async () => {\n await sanitizeCollection(\n // @ts-expect-error\n {\n ...config,\n collections: [\n {\n ...collectionWithAuth,\n fields,\n },\n ],\n },\n {\n ...collectionWithAuth,\n fields,\n },\n )\n }).rejects.toThrow(ReservedFieldName)\n })\n\n it('should not throw on a custom field', async () => {\n const fields: Field[] = [\n {\n name: 'customField',\n type: 'text',\n label: 'some-collection',\n },\n ]\n await expect(async () => {\n await sanitizeCollection(\n // @ts-expect-error\n {\n ...config,\n collections: [\n {\n ...collectionWithAuth,\n fields,\n },\n ],\n },\n {\n ...collectionWithAuth,\n fields,\n },\n )\n }).not.toThrow()\n })\n })\n})\n"],"names":["ReservedFieldName","sanitizeCollection","describe","config","collections","globals","collectionWithUploads","slug","fields","upload","it","name","type","label","expect","rejects","toThrow","not","collectionWithAuth","auth","loginWithUsername","useAPIKey","verify"],"mappings":"AAGA,SAASA,iBAAiB,QAAQ,wBAAuB;AACzD,SAASC,kBAAkB,QAAQ,gBAAe;AAElDC,SAAS,sCAAsC;IAC7C,MAAMC,SAAS;QACbC,aAAa,EAAE;QACfC,SAAS,EAAE;IACb;IAEAH,SAAS,aAAa;QACpB,MAAMI,wBAA0C;YAC9CC,MAAM;YACNC,QAAQ,EAAE;YACVC,QAAQ;QACV;QAEAC,GAAG,wBAAwB;YACzB,MAAMF,SAAkB;gBACtB;oBACEG,MAAM;oBACNC,MAAM;oBACNC,OAAO;gBACT;aACD;YACD,MAAMC,OAAO;gBACX,MAAMb,mBACJ,mBAAmB;gBACnB;oBACE,GAAGE,MAAM;oBACTC,aAAa;wBACX;4BACE,GAAGE,qBAAqB;4BACxBE;wBACF;qBACD;gBACH,GACA;oBACE,GAAGF,qBAAqB;oBACxBE;gBACF;YAEJ,GAAGO,OAAO,CAACC,OAAO,CAAChB;QACrB;QAEAU,GAAG,sCAAsC;YACvC,MAAMF,SAAkB;gBACtB;oBACEG,MAAM;oBACNC,MAAM;oBACNC,OAAO;gBACT;aACD;YACD,MAAMC,OAA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ACF;qBACD;gBACH,GACA;oBACE,GAAGU,kBAAkB;oBACrBV;gBACF;YAEJ,GAAGS,GAAG,CAACD,OAAO;QAChB;IACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../../src/collections/config/sanitize.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,KAAK,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAA;AAe7E,eAAO,MAAM,kBAAkB,WACrB,MAAM,cACF,gBAAgB,iCAKG,KAAK,CAAC,CAAC,MAAM,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,KAC/E,OAAO,CAAC,yBAAyB,
|
|
1
|
+
{"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../../src/collections/config/sanitize.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,KAAK,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAA;AAe7E,eAAO,MAAM,kBAAkB,WACrB,MAAM,cACF,gBAAgB,iCAKG,KAAK,CAAC,CAAC,MAAM,EAAE,eAAe,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,KAC/E,OAAO,CAAC,yBAAyB,CAoKnC,CAAA"}
|
|
@@ -26,6 +26,7 @@ export const sanitizeCollection = async (config, collection, /**
|
|
|
26
26
|
collectionConfig: sanitized,
|
|
27
27
|
config,
|
|
28
28
|
fields: sanitized.fields,
|
|
29
|
+
parentIsLocalized: false,
|
|
29
30
|
richTextSanitizationPromises,
|
|
30
31
|
validRelationships
|
|
31
32
|
});
|
|
@@ -35,8 +36,12 @@ export const sanitizeCollection = async (config, collection, /**
|
|
|
35
36
|
let hasCreatedAt = null;
|
|
36
37
|
sanitized.fields.some((field)=>{
|
|
37
38
|
if (fieldAffectsData(field)) {
|
|
38
|
-
if (field.name === 'updatedAt')
|
|
39
|
-
|
|
39
|
+
if (field.name === 'updatedAt') {
|
|
40
|
+
hasUpdatedAt = true;
|
|
41
|
+
}
|
|
42
|
+
if (field.name === 'createdAt') {
|
|
43
|
+
hasCreatedAt = true;
|
|
44
|
+
}
|
|
40
45
|
}
|
|
41
46
|
return hasCreatedAt && hasUpdatedAt;
|
|
42
47
|
});
|
|
@@ -67,9 +72,11 @@ export const sanitizeCollection = async (config, collection, /**
|
|
|
67
72
|
}
|
|
68
73
|
sanitized.labels = sanitized.labels || formatLabels(sanitized.slug);
|
|
69
74
|
if (sanitized.versions) {
|
|
70
|
-
if (sanitized.versions === true)
|
|
71
|
-
|
|
72
|
-
|
|
75
|
+
if (sanitized.versions === true) {
|
|
76
|
+
sanitized.versions = {
|
|
77
|
+
drafts: false
|
|
78
|
+
};
|
|
79
|
+
}
|
|
73
80
|
if (sanitized.timestamps === false) {
|
|
74
81
|
throw new TimestampsRequired(collection);
|
|
75
82
|
}
|
|
@@ -92,7 +99,9 @@ export const sanitizeCollection = async (config, collection, /**
|
|
|
92
99
|
}
|
|
93
100
|
}
|
|
94
101
|
if (sanitized.upload) {
|
|
95
|
-
if (sanitized.upload === true)
|
|
102
|
+
if (sanitized.upload === true) {
|
|
103
|
+
sanitized.upload = {};
|
|
104
|
+
}
|
|
96
105
|
// sanitize fields for reserved names
|
|
97
106
|
sanitizeUploadFields(sanitized.fields, sanitized);
|
|
98
107
|
// disable duplicate for uploads by default
|