payload 3.2.3-canary.673b4b5 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/elements/DatePicker.d.ts +2 -2
- package/dist/admin/elements/DatePicker.d.ts.map +1 -1
- package/dist/admin/elements/DatePicker.js.map +1 -1
- package/dist/admin/types.js +3 -3
- package/dist/admin/types.js.map +1 -1
- package/dist/auth/cookies.js.map +1 -1
- package/dist/auth/crypto.js.map +1 -1
- package/dist/auth/extractJWT.js.map +1 -1
- package/dist/auth/getAuthFields.d.ts.map +1 -1
- package/dist/auth/getAuthFields.js +1 -1
- package/dist/auth/getAuthFields.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 +4 -12
- package/dist/auth/operations/login.js.map +1 -1
- package/dist/auth/operations/me.js.map +1 -1
- package/dist/auth/operations/registerFirstUser.d.ts.map +1 -1
- package/dist/auth/operations/registerFirstUser.js +3 -0
- 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 -3
- 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 +4 -0
- 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 +4 -1
- package/dist/auth/operations/verifyEmail.js.map +1 -1
- package/dist/auth/sendVerificationEmail.js.map +1 -1
- package/dist/auth/strategies/apiKey.js.map +1 -1
- package/dist/auth/types.d.ts +8 -1
- package/dist/auth/types.d.ts.map +1 -1
- package/dist/auth/types.js.map +1 -1
- package/dist/bin/generateImportMap/index.js.map +1 -1
- package/dist/bin/generateImportMap/parsePayloadComponent.js +1 -0
- package/dist/bin/generateImportMap/parsePayloadComponent.js.map +1 -1
- package/dist/bin/generateTypes.js.map +1 -1
- package/dist/bin/index.js.map +1 -1
- package/dist/bin/info.js.map +1 -1
- package/dist/bin/migrate.js.map +1 -1
- package/dist/collections/operations/findVersionByID.js +2 -0
- package/dist/collections/operations/findVersionByID.js.map +1 -1
- package/dist/collections/operations/findVersions.js +1 -0
- package/dist/collections/operations/findVersions.js.map +1 -1
- package/dist/config/client.js +2 -0
- package/dist/config/client.js.map +1 -1
- package/dist/config/defaults.js.map +1 -1
- package/dist/config/find.js.map +1 -1
- package/dist/config/sanitize.js.map +1 -1
- package/dist/database/getLocalizedPaths.js.map +1 -1
- package/dist/database/migrations/createMigration.js.map +1 -1
- package/dist/database/migrations/getPredefinedMigration.js.map +1 -1
- package/dist/database/migrations/migrate.js.map +1 -1
- package/dist/database/migrations/migrateDown.js.map +1 -1
- package/dist/database/migrations/migrateRefresh.js.map +1 -1
- package/dist/database/migrations/migrateReset.js.map +1 -1
- package/dist/database/migrations/readMigrationFiles.js.map +1 -1
- package/dist/database/migrations/writeMigrationIndex.js.map +1 -1
- package/dist/database/queryValidation/validateSearchParams.js.map +1 -1
- package/dist/email/sendEmail.js.map +1 -1
- package/dist/errors/AuthenticationError.js.map +1 -1
- package/dist/errors/FileRetrievalError.js.map +1 -1
- package/dist/errors/QueryError.js.map +1 -1
- package/dist/errors/ValidationError.js.map +1 -1
- package/dist/fields/config/client.js +1 -0
- package/dist/fields/config/client.js.map +1 -1
- package/dist/fields/config/sanitize.js.map +1 -1
- package/dist/fields/config/sanitizeJoinField.js.map +1 -1
- package/dist/fields/config/types.d.ts +14 -0
- package/dist/fields/config/types.d.ts.map +1 -1
- package/dist/fields/config/types.js.map +1 -1
- package/dist/fields/getFieldPaths.js.map +1 -1
- package/dist/fields/hooks/afterRead/relationshipPopulationPromise.js +1 -0
- package/dist/fields/hooks/afterRead/relationshipPopulationPromise.js.map +1 -1
- package/dist/fields/hooks/beforeDuplicate/promise.js +1 -0
- package/dist/fields/hooks/beforeDuplicate/promise.js.map +1 -1
- package/dist/fields/hooks/beforeValidate/promise.js +1 -0
- package/dist/fields/hooks/beforeValidate/promise.js.map +1 -1
- package/dist/fields/mergeBaseFields.js +1 -0
- package/dist/fields/mergeBaseFields.js.map +1 -1
- package/dist/fields/setDefaultBeforeDuplicate.js.map +1 -1
- package/dist/fields/validations.js.map +1 -1
- package/dist/globals/config/sanitize.js +1 -0
- package/dist/globals/config/sanitize.js.map +1 -1
- package/dist/globals/operations/findVersions.js +2 -0
- package/dist/globals/operations/findVersions.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/preferences/deleteUserPreferences.js.map +1 -1
- package/dist/queues/config/generateJobsJSONSchemas.js.map +1 -1
- package/dist/queues/config/types/taskTypes.d.ts +23 -4
- package/dist/queues/config/types/taskTypes.d.ts.map +1 -1
- package/dist/queues/config/types/taskTypes.js.map +1 -1
- package/dist/queues/config/types/workflowJSONTypes.d.ts +5 -0
- package/dist/queues/config/types/workflowJSONTypes.d.ts.map +1 -1
- package/dist/queues/config/types/workflowJSONTypes.js.map +1 -1
- package/dist/queues/config/types/workflowTypes.d.ts +9 -5
- package/dist/queues/config/types/workflowTypes.d.ts.map +1 -1
- package/dist/queues/config/types/workflowTypes.js.map +1 -1
- package/dist/queues/operations/runJobs/index.d.ts.map +1 -1
- package/dist/queues/operations/runJobs/index.js +2 -1
- package/dist/queues/operations/runJobs/index.js.map +1 -1
- package/dist/queues/operations/runJobs/runJob/getRunTaskFunction.d.ts.map +1 -1
- package/dist/queues/operations/runJobs/runJob/getRunTaskFunction.js +18 -5
- package/dist/queues/operations/runJobs/runJob/getRunTaskFunction.js.map +1 -1
- package/dist/queues/operations/runJobs/runJob/handleWorkflowError.d.ts.map +1 -1
- package/dist/queues/operations/runJobs/runJob/handleWorkflowError.js +16 -16
- package/dist/queues/operations/runJobs/runJob/handleWorkflowError.js.map +1 -1
- package/dist/queues/operations/runJobs/runJob/importHandlerPath.d.ts.map +1 -1
- package/dist/queues/operations/runJobs/runJob/importHandlerPath.js +8 -1
- package/dist/queues/operations/runJobs/runJob/importHandlerPath.js.map +1 -1
- package/dist/queues/operations/runJobs/runJob/index.d.ts.map +1 -1
- package/dist/queues/operations/runJobs/runJob/index.js +6 -1
- package/dist/queues/operations/runJobs/runJob/index.js.map +1 -1
- package/dist/queues/utilities/getJobTaskStatus.d.ts.map +1 -1
- package/dist/queues/utilities/getJobTaskStatus.js +5 -0
- package/dist/queues/utilities/getJobTaskStatus.js.map +1 -1
- package/dist/uploads/deleteAssociatedFiles.js.map +1 -1
- package/dist/uploads/formatFilesize.js.map +1 -1
- package/dist/uploads/generateFileData.js.map +1 -1
- package/dist/uploads/getBaseFields.js.map +1 -1
- package/dist/uploads/getExternalFile.js.map +1 -1
- package/dist/uploads/getSafeFilename.js.map +1 -1
- package/dist/uploads/imageResizer.js.map +1 -1
- package/dist/utilities/addSelectGenericsToGeneretedTypes.js.map +1 -1
- package/dist/utilities/configToJSONSchema.d.ts.map +1 -1
- package/dist/utilities/configToJSONSchema.js +2 -1
- package/dist/utilities/configToJSONSchema.js.map +1 -1
- package/dist/utilities/dependencies/dependencyChecker.js.map +1 -1
- package/dist/utilities/getDataByPath.js.map +1 -1
- package/dist/utilities/getSiblingData.js.map +1 -1
- package/dist/utilities/parseCookies.js.map +1 -1
- package/dist/utilities/sanitizePermissions.js +4 -0
- package/dist/utilities/sanitizePermissions.js.map +1 -1
- package/dist/utilities/telemetry/conf/envPaths.js.map +1 -1
- package/dist/utilities/telemetry/conf/index.js.map +1 -1
- package/dist/utilities/timestamp.js.map +1 -1
- package/dist/utilities/wordBoundariesRegex.js.map +1 -1
- package/dist/versions/drafts/appendVersionToQueryKey.js.map +1 -1
- package/dist/versions/drafts/getQueryDraftsSort.js.map +1 -1
- package/dist/versions/enforceMaxVersions.js.map +1 -1
- package/dist/versions/saveVersion.js +2 -0
- package/dist/versions/saveVersion.js.map +1 -1
- package/package.json +4 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { DatePickerProps } from 'react-datepicker';
|
|
2
2
|
export type SharedProps = {
|
|
3
3
|
displayFormat?: string;
|
|
4
|
-
overrides?:
|
|
4
|
+
overrides?: DatePickerProps;
|
|
5
5
|
pickerAppearance?: 'dayAndTime' | 'dayOnly' | 'default' | 'monthOnly' | 'timeOnly';
|
|
6
6
|
};
|
|
7
7
|
export type TimePickerProps = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatePicker.d.ts","sourceRoot":"","sources":["../../../src/admin/elements/DatePicker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"DatePicker.d.ts","sourceRoot":"","sources":["../../../src/admin/elements/DatePicker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAEvD,MAAM,MAAM,WAAW,GAAG;IACxB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,SAAS,CAAC,EAAE,eAAe,CAAA;IAC3B,gBAAgB,CAAC,EAAE,YAAY,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,UAAU,CAAA;CACnF,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,OAAO,CAAC,EAAE,IAAI,CAAA;IACd,OAAO,CAAC,EAAE,IAAI,CAAA;IACd,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB,CAAA;AAED,MAAM,MAAM,cAAc,GAAG;IAC3B,OAAO,CAAC,EAAE,IAAI,CAAA;IACd,OAAO,CAAC,EAAE,IAAI,CAAA;IACd,YAAY,CAAC,EAAE,CAAC,GAAG,CAAC,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,CAAC,EAAE,IAAI,CAAA;IACd,OAAO,CAAC,EAAE,IAAI,CAAA;CACf,CAAA;AAED,MAAM,MAAM,oBAAoB,GAC5B,CAAC;IACC,gBAAgB,EAAE,SAAS,CAAA;CAC5B,GAAG,cAAc,GAChB,WAAW,CAAC,GACd,CAAC;IACC,gBAAgB,EAAE,WAAW,CAAA;CAC9B,GAAG,gBAAgB,GAClB,WAAW,CAAC,GACd,CAAC;IACC,gBAAgB,EAAE,UAAU,CAAA;CAC7B,GAAG,WAAW,GACb,eAAe,CAAC,GAClB,CAAC;IACC,gBAAgB,CAAC,EAAE,YAAY,CAAA;CAChC,GAAG,cAAc,GAChB,WAAW,GACX,eAAe,CAAC,GAClB,CAAC;IACC,gBAAgB,CAAC,EAAE,SAAS,CAAA;CAC7B,GAAG,WAAW,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/admin/elements/DatePicker.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../../../src/admin/elements/DatePicker.ts"],"sourcesContent":["import type { DatePickerProps } from 'react-datepicker'\n\nexport type SharedProps = {\n displayFormat?: string\n overrides?: DatePickerProps\n pickerAppearance?: 'dayAndTime' | 'dayOnly' | 'default' | 'monthOnly' | 'timeOnly'\n}\n\nexport type TimePickerProps = {\n maxTime?: Date\n minTime?: Date\n timeFormat?: string\n timeIntervals?: number\n}\n\nexport type DayPickerProps = {\n maxDate?: Date\n minDate?: Date\n monthsToShow?: 1 | 2\n}\n\nexport type MonthPickerProps = {\n maxDate?: Date\n minDate?: Date\n}\n\nexport type ConditionalDateProps =\n | ({\n pickerAppearance: 'dayOnly'\n } & DayPickerProps &\n SharedProps)\n | ({\n pickerAppearance: 'monthOnly'\n } & MonthPickerProps &\n SharedProps)\n | ({\n pickerAppearance: 'timeOnly'\n } & SharedProps &\n TimePickerProps)\n | ({\n pickerAppearance?: 'dayAndTime'\n } & DayPickerProps &\n SharedProps &\n TimePickerProps)\n | ({\n pickerAppearance?: 'default'\n } & SharedProps)\n"],"names":[],"mappings":"AA0BA,WAoBoB"}
|
package/dist/admin/types.js
CHANGED
package/dist/admin/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/admin/types.ts"],"sourcesContent":["import type { AcceptedLanguages, I18nClient } from '@payloadcms/translations'\nimport type React from 'react'\n\nimport type { ImportMap } from '../bin/generateImportMap/index.js'\nimport type { SanitizedConfig } from '../config/types.js'\nimport type {\n Block,\n ClientBlock,\n ClientField,\n Field,\n FieldTypes,\n Tab,\n} from '../fields/config/types.js'\nimport type { JsonObject } from '../types/index.js'\nimport type { ClientTab } from './fields/Tabs.js'\nimport type {\n BuildFormStateArgs,\n Data,\n FieldState,\n FieldStateWithoutComponents,\n FilterOptionsResult,\n FormState,\n FormStateWithoutComponents,\n Row,\n} from './forms/Form.js'\n\nexport type { DefaultCellComponentProps, DefaultServerCellComponentProps } from './elements/Cell.js'\nexport type { ConditionalDateProps } from './elements/DatePicker.js'\nexport type { DayPickerProps, SharedProps, TimePickerProps } from './elements/DatePicker.js'\nexport type { NavGroupPreferences, NavPreferences } from './elements/Nav.js'\nexport type { CustomPreviewButton } from './elements/PreviewButton.js'\nexport type { CustomPublishButton } from './elements/PublishButton.js'\nexport type { CustomSaveButton } from './elements/SaveButton.js'\nexport type { CustomSaveDraftButton } from './elements/SaveDraftButton.js'\nexport type {\n DocumentTabComponent,\n DocumentTabCondition,\n DocumentTabConfig,\n DocumentTabProps,\n} from './elements/Tab.js'\n\nexport type { CustomUpload } from './elements/Upload.js'\n\nexport type {\n WithServerSidePropsComponent,\n WithServerSidePropsComponentProps,\n} from './elements/WithServerSideProps.js'\n\nexport type {\n ArrayFieldClientComponent,\n ArrayFieldClientProps,\n ArrayFieldDescriptionClientComponent,\n ArrayFieldDescriptionServerComponent,\n ArrayFieldErrorClientComponent,\n ArrayFieldErrorServerComponent,\n ArrayFieldLabelClientComponent,\n ArrayFieldLabelServerComponent,\n ArrayFieldServerComponent,\n ArrayFieldServerProps,\n} from './fields/Array.js'\n\nexport type {\n BlocksFieldClientComponent,\n BlocksFieldClientProps,\n BlocksFieldDescriptionClientComponent,\n BlocksFieldDescriptionServerComponent,\n BlocksFieldErrorClientComponent,\n BlocksFieldErrorServerComponent,\n BlocksFieldLabelClientComponent,\n BlocksFieldLabelServerComponent,\n BlocksFieldServerComponent,\n BlocksFieldServerProps,\n} from './fields/Blocks.js'\n\nexport type {\n CheckboxFieldClientComponent,\n CheckboxFieldClientProps,\n CheckboxFieldDescriptionClientComponent,\n CheckboxFieldDescriptionServerComponent,\n CheckboxFieldErrorClientComponent,\n CheckboxFieldErrorServerComponent,\n CheckboxFieldLabelClientComponent,\n CheckboxFieldLabelServerComponent,\n CheckboxFieldServerComponent,\n CheckboxFieldServerProps,\n} from './fields/Checkbox.js'\n\nexport type {\n CodeFieldClientComponent,\n CodeFieldClientProps,\n CodeFieldDescriptionClientComponent,\n CodeFieldDescriptionServerComponent,\n CodeFieldErrorClientComponent,\n CodeFieldErrorServerComponent,\n CodeFieldLabelClientComponent,\n CodeFieldLabelServerComponent,\n CodeFieldServerComponent,\n CodeFieldServerProps,\n} from './fields/Code.js'\n\nexport type {\n CollapsibleFieldClientComponent,\n CollapsibleFieldClientProps,\n CollapsibleFieldDescriptionClientComponent,\n CollapsibleFieldDescriptionServerComponent,\n CollapsibleFieldErrorClientComponent,\n CollapsibleFieldErrorServerComponent,\n CollapsibleFieldLabelClientComponent,\n CollapsibleFieldLabelServerComponent,\n CollapsibleFieldServerComponent,\n CollapsibleFieldServerProps,\n} from './fields/Collapsible.js'\n\nexport type {\n DateFieldClientComponent,\n DateFieldClientProps,\n DateFieldDescriptionClientComponent,\n DateFieldDescriptionServerComponent,\n DateFieldErrorClientComponent,\n DateFieldErrorServerComponent,\n DateFieldLabelClientComponent,\n DateFieldLabelServerComponent,\n DateFieldServerComponent,\n DateFieldServerProps,\n} from './fields/Date.js'\n\nexport type {\n EmailFieldClientComponent,\n EmailFieldClientProps,\n EmailFieldDescriptionClientComponent,\n EmailFieldDescriptionServerComponent,\n EmailFieldErrorClientComponent,\n EmailFieldErrorServerComponent,\n EmailFieldLabelClientComponent,\n EmailFieldLabelServerComponent,\n EmailFieldServerComponent,\n EmailFieldServerProps,\n} from './fields/Email.js'\n\nexport type {\n GroupFieldClientComponent,\n GroupFieldClientProps,\n GroupFieldDescriptionClientComponent,\n GroupFieldDescriptionServerComponent,\n GroupFieldErrorClientComponent,\n GroupFieldErrorServerComponent,\n GroupFieldLabelClientComponent,\n GroupFieldLabelServerComponent,\n GroupFieldServerComponent,\n GroupFieldServerProps,\n} from './fields/Group.js'\n\nexport type { HiddenFieldProps } from './fields/Hidden.js'\n\nexport type {\n JoinFieldClientComponent,\n JoinFieldClientProps,\n JoinFieldDescriptionClientComponent,\n JoinFieldDescriptionServerComponent,\n JoinFieldErrorClientComponent,\n JoinFieldErrorServerComponent,\n JoinFieldLabelClientComponent,\n JoinFieldLabelServerComponent,\n JoinFieldServerComponent,\n JoinFieldServerProps,\n} from './fields/Join.js'\n\nexport type {\n JSONFieldClientComponent,\n JSONFieldClientProps,\n JSONFieldDescriptionClientComponent,\n JSONFieldDescriptionServerComponent,\n JSONFieldErrorClientComponent,\n JSONFieldErrorServerComponent,\n JSONFieldLabelClientComponent,\n JSONFieldLabelServerComponent,\n JSONFieldServerComponent,\n JSONFieldServerProps,\n} from './fields/JSON.js'\n\nexport type {\n NumberFieldClientComponent,\n NumberFieldClientProps,\n NumberFieldDescriptionClientComponent,\n NumberFieldDescriptionServerComponent,\n NumberFieldErrorClientComponent,\n NumberFieldErrorServerComponent,\n NumberFieldLabelClientComponent,\n NumberFieldLabelServerComponent,\n NumberFieldServerComponent,\n NumberFieldServerProps,\n} from './fields/Number.js'\n\nexport type {\n PointFieldClientComponent,\n PointFieldClientProps,\n PointFieldDescriptionClientComponent,\n PointFieldDescriptionServerComponent,\n PointFieldErrorClientComponent,\n PointFieldErrorServerComponent,\n PointFieldLabelClientComponent,\n PointFieldLabelServerComponent,\n PointFieldServerComponent,\n PointFieldServerProps,\n} from './fields/Point.js'\n\nexport type {\n RadioFieldClientComponent,\n RadioFieldClientProps,\n RadioFieldDescriptionClientComponent,\n RadioFieldDescriptionServerComponent,\n RadioFieldErrorClientComponent,\n RadioFieldErrorServerComponent,\n RadioFieldLabelClientComponent,\n RadioFieldLabelServerComponent,\n RadioFieldServerComponent,\n RadioFieldServerProps,\n} from './fields/Radio.js'\n\nexport type {\n RelationshipFieldClientComponent,\n RelationshipFieldClientProps,\n RelationshipFieldDescriptionClientComponent,\n RelationshipFieldDescriptionServerComponent,\n RelationshipFieldErrorClientComponent,\n RelationshipFieldErrorServerComponent,\n RelationshipFieldLabelClientComponent,\n RelationshipFieldLabelServerComponent,\n RelationshipFieldServerComponent,\n RelationshipFieldServerProps,\n} from './fields/Relationship.js'\n\nexport type {\n RichTextFieldClientComponent,\n RichTextFieldClientProps,\n RichTextFieldDescriptionClientComponent,\n RichTextFieldDescriptionServerComponent,\n RichTextFieldErrorClientComponent,\n RichTextFieldErrorServerComponent,\n RichTextFieldLabelClientComponent,\n RichTextFieldLabelServerComponent,\n RichTextFieldServerComponent,\n RichTextFieldServerProps,\n} from './fields/RichText.js'\n\nexport type {\n RowFieldClientComponent,\n RowFieldClientProps,\n RowFieldDescriptionClientComponent,\n RowFieldDescriptionServerComponent,\n RowFieldErrorClientComponent,\n RowFieldErrorServerComponent,\n RowFieldLabelClientComponent,\n RowFieldLabelServerComponent,\n RowFieldServerComponent,\n RowFieldServerProps,\n} from './fields/Row.js'\n\nexport type {\n SelectFieldClientComponent,\n SelectFieldClientProps,\n SelectFieldDescriptionClientComponent,\n SelectFieldDescriptionServerComponent,\n SelectFieldErrorClientComponent,\n SelectFieldErrorServerComponent,\n SelectFieldLabelClientComponent,\n SelectFieldLabelServerComponent,\n SelectFieldServerComponent,\n SelectFieldServerProps,\n} from './fields/Select.js'\n\nexport type {\n ClientTab,\n TabsFieldClientComponent,\n TabsFieldClientProps,\n TabsFieldDescriptionClientComponent,\n TabsFieldDescriptionServerComponent,\n TabsFieldErrorClientComponent,\n TabsFieldErrorServerComponent,\n TabsFieldLabelClientComponent,\n TabsFieldLabelServerComponent,\n TabsFieldServerComponent,\n TabsFieldServerProps,\n} from './fields/Tabs.js'\n\nexport type {\n TextFieldClientComponent,\n TextFieldClientProps,\n TextFieldDescriptionClientComponent,\n TextFieldDescriptionServerComponent,\n TextFieldErrorClientComponent,\n TextFieldErrorServerComponent,\n TextFieldLabelClientComponent,\n TextFieldLabelServerComponent,\n TextFieldServerComponent,\n TextFieldServerProps,\n} from './fields/Text.js'\n\nexport type {\n TextareaFieldClientComponent,\n TextareaFieldClientProps,\n TextareaFieldDescriptionClientComponent,\n TextareaFieldDescriptionServerComponent,\n TextareaFieldErrorClientComponent,\n TextareaFieldErrorServerComponent,\n TextareaFieldLabelClientComponent,\n TextareaFieldLabelServerComponent,\n TextareaFieldServerComponent,\n TextareaFieldServerProps,\n} from './fields/Textarea.js'\n\nexport type {\n UIFieldClientComponent,\n UIFieldClientProps,\n UIFieldServerComponent,\n UIFieldServerProps,\n} from './fields/UI.js'\n\nexport type {\n UploadFieldClientComponent,\n UploadFieldClientProps,\n UploadFieldDescriptionClientComponent,\n UploadFieldDescriptionServerComponent,\n UploadFieldErrorClientComponent,\n UploadFieldErrorServerComponent,\n UploadFieldLabelClientComponent,\n UploadFieldLabelServerComponent,\n UploadFieldServerComponent,\n UploadFieldServerProps,\n} from './fields/Upload.js'\n\nexport type {\n Description,\n DescriptionFunction,\n FieldDescriptionClientComponent,\n FieldDescriptionClientProps,\n FieldDescriptionServerComponent,\n FieldDescriptionServerProps,\n GenericDescriptionProps,\n StaticDescription,\n} from './forms/Description.js'\n\nexport type {\n FieldErrorClientComponent,\n FieldErrorClientProps,\n FieldErrorServerComponent,\n FieldErrorServerProps,\n GenericErrorProps,\n} from './forms/Error.js'\n\nexport type {\n BuildFormStateArgs,\n Data,\n FieldState as FormField,\n FieldStateWithoutComponents as FormFieldWithoutComponents,\n FilterOptionsResult,\n FormState,\n FormStateWithoutComponents,\n Row,\n}\n\nexport type {\n ClientComponentProps,\n ClientFieldBase,\n ClientFieldWithOptionalType,\n FieldClientComponent,\n FieldPaths,\n FieldServerComponent,\n ServerComponentProps,\n ServerFieldBase,\n} from './forms/Field.js'\n\nexport type {\n FieldLabelClientComponent,\n FieldLabelClientProps,\n FieldLabelServerComponent,\n FieldLabelServerProps,\n GenericLabelProps,\n SanitizedLabelProps,\n} from './forms/Label.js'\n\nexport type { RowLabel, RowLabelComponent } from './forms/RowLabel.js'\n\nexport type {\n BuildTableStateArgs,\n DefaultServerFunctionArgs,\n ListQuery,\n ServerFunction,\n ServerFunctionArgs,\n ServerFunctionClient,\n ServerFunctionClientArgs,\n ServerFunctionConfig,\n ServerFunctionHandler,\n} from './functions/index.js'\n\nexport type MappedServerComponent<TComponentClientProps extends JsonObject = JsonObject> = {\n Component?: React.ComponentType<TComponentClientProps>\n props?: Partial<any>\n RenderedComponent: React.ReactNode\n type: 'server'\n}\n\nexport type MappedClientComponent<TComponentClientProps extends JsonObject = JsonObject> = {\n Component?: React.ComponentType<TComponentClientProps>\n props?: Partial<TComponentClientProps>\n RenderedComponent?: React.ReactNode\n type: 'client'\n}\n\nexport type MappedEmptyComponent = {\n type: 'empty'\n}\n\nexport enum Action {\n RenderConfig = 'render-config',\n}\n\nexport type RenderEntityConfigArgs = {\n collectionSlug?: string\n data?: Data\n globalSlug?: string\n}\n\nexport type RenderRootConfigArgs = {}\n\nexport type RenderFieldConfigArgs = {\n collectionSlug?: string\n formState?: FormState\n globalSlug?: string\n schemaPath: string\n}\n\nexport type RenderConfigArgs = {\n action: Action.RenderConfig\n config: Promise<SanitizedConfig> | SanitizedConfig\n i18n: I18nClient\n importMap: ImportMap\n languageCode: AcceptedLanguages\n serverProps?: any\n} & (RenderEntityConfigArgs | RenderFieldConfigArgs | RenderRootConfigArgs)\n\nexport type PayloadServerAction = (\n args:\n | {\n [key: string]: any\n action: Action\n i18n: I18nClient\n }\n | RenderConfigArgs,\n) => Promise<string>\n\nexport type RenderedField = {\n Field: React.ReactNode\n indexPath?: string\n initialSchemaPath?: string\n isSidebar: boolean\n path: string\n schemaPath: string\n type: FieldTypes\n}\n\nexport type FieldRow = {\n RowLabel?: React.ReactNode\n}\n\nexport type DocumentSlots = {\n Description?: React.ReactNode\n PreviewButton?: React.ReactNode\n PublishButton?: React.ReactNode\n SaveButton?: React.ReactNode\n SaveDraftButton?: React.ReactNode\n Upload?: React.ReactNode\n}\n\nexport type { LanguageOptions } from './LanguageOptions.js'\n\nexport type { RichTextAdapter, RichTextAdapterProvider, RichTextHooks } from './RichText.js'\n\nexport type {\n AdminViewComponent,\n AdminViewConfig,\n AdminViewProps,\n ClientSideEditViewProps,\n EditViewProps,\n InitPageResult,\n ServerSideEditViewProps,\n VisibleEntities,\n} from './views/types.js'\n\ntype SchemaPath = {} & string\nexport type FieldSchemaMap = Map<\n SchemaPath,\n | {\n fields: Field[]\n }\n | Block\n | Field\n | Tab\n>\n\nexport type ClientFieldSchemaMap = Map<\n SchemaPath,\n | {\n fields: ClientField[]\n }\n | ClientBlock\n | ClientField\n | ClientTab\n>\n"],"names":["Action"],"mappings":";UA6ZYA;;GAAAA,WAAAA"}
|
|
1
|
+
{"version":3,"sources":["../../src/admin/types.ts"],"sourcesContent":["import type { AcceptedLanguages, I18nClient } from '@payloadcms/translations'\nimport type React from 'react'\n\nimport type { ImportMap } from '../bin/generateImportMap/index.js'\nimport type { SanitizedConfig } from '../config/types.js'\nimport type {\n Block,\n ClientBlock,\n ClientField,\n Field,\n FieldTypes,\n Tab,\n} from '../fields/config/types.js'\nimport type { JsonObject } from '../types/index.js'\nimport type { ClientTab } from './fields/Tabs.js'\nimport type {\n BuildFormStateArgs,\n Data,\n FieldState,\n FieldStateWithoutComponents,\n FilterOptionsResult,\n FormState,\n FormStateWithoutComponents,\n Row,\n} from './forms/Form.js'\n\nexport type { DefaultCellComponentProps, DefaultServerCellComponentProps } from './elements/Cell.js'\nexport type { ConditionalDateProps } from './elements/DatePicker.js'\nexport type { DayPickerProps, SharedProps, TimePickerProps } from './elements/DatePicker.js'\nexport type { NavGroupPreferences, NavPreferences } from './elements/Nav.js'\nexport type { CustomPreviewButton } from './elements/PreviewButton.js'\nexport type { CustomPublishButton } from './elements/PublishButton.js'\nexport type { CustomSaveButton } from './elements/SaveButton.js'\nexport type { CustomSaveDraftButton } from './elements/SaveDraftButton.js'\nexport type {\n DocumentTabComponent,\n DocumentTabCondition,\n DocumentTabConfig,\n DocumentTabProps,\n} from './elements/Tab.js'\n\nexport type { CustomUpload } from './elements/Upload.js'\n\nexport type {\n WithServerSidePropsComponent,\n WithServerSidePropsComponentProps,\n} from './elements/WithServerSideProps.js'\n\nexport type {\n ArrayFieldClientComponent,\n ArrayFieldClientProps,\n ArrayFieldDescriptionClientComponent,\n ArrayFieldDescriptionServerComponent,\n ArrayFieldErrorClientComponent,\n ArrayFieldErrorServerComponent,\n ArrayFieldLabelClientComponent,\n ArrayFieldLabelServerComponent,\n ArrayFieldServerComponent,\n ArrayFieldServerProps,\n} from './fields/Array.js'\n\nexport type {\n BlocksFieldClientComponent,\n BlocksFieldClientProps,\n BlocksFieldDescriptionClientComponent,\n BlocksFieldDescriptionServerComponent,\n BlocksFieldErrorClientComponent,\n BlocksFieldErrorServerComponent,\n BlocksFieldLabelClientComponent,\n BlocksFieldLabelServerComponent,\n BlocksFieldServerComponent,\n BlocksFieldServerProps,\n} from './fields/Blocks.js'\n\nexport type {\n CheckboxFieldClientComponent,\n CheckboxFieldClientProps,\n CheckboxFieldDescriptionClientComponent,\n CheckboxFieldDescriptionServerComponent,\n CheckboxFieldErrorClientComponent,\n CheckboxFieldErrorServerComponent,\n CheckboxFieldLabelClientComponent,\n CheckboxFieldLabelServerComponent,\n CheckboxFieldServerComponent,\n CheckboxFieldServerProps,\n} from './fields/Checkbox.js'\n\nexport type {\n CodeFieldClientComponent,\n CodeFieldClientProps,\n CodeFieldDescriptionClientComponent,\n CodeFieldDescriptionServerComponent,\n CodeFieldErrorClientComponent,\n CodeFieldErrorServerComponent,\n CodeFieldLabelClientComponent,\n CodeFieldLabelServerComponent,\n CodeFieldServerComponent,\n CodeFieldServerProps,\n} from './fields/Code.js'\n\nexport type {\n CollapsibleFieldClientComponent,\n CollapsibleFieldClientProps,\n CollapsibleFieldDescriptionClientComponent,\n CollapsibleFieldDescriptionServerComponent,\n CollapsibleFieldErrorClientComponent,\n CollapsibleFieldErrorServerComponent,\n CollapsibleFieldLabelClientComponent,\n CollapsibleFieldLabelServerComponent,\n CollapsibleFieldServerComponent,\n CollapsibleFieldServerProps,\n} from './fields/Collapsible.js'\n\nexport type {\n DateFieldClientComponent,\n DateFieldClientProps,\n DateFieldDescriptionClientComponent,\n DateFieldDescriptionServerComponent,\n DateFieldErrorClientComponent,\n DateFieldErrorServerComponent,\n DateFieldLabelClientComponent,\n DateFieldLabelServerComponent,\n DateFieldServerComponent,\n DateFieldServerProps,\n} from './fields/Date.js'\n\nexport type {\n EmailFieldClientComponent,\n EmailFieldClientProps,\n EmailFieldDescriptionClientComponent,\n EmailFieldDescriptionServerComponent,\n EmailFieldErrorClientComponent,\n EmailFieldErrorServerComponent,\n EmailFieldLabelClientComponent,\n EmailFieldLabelServerComponent,\n EmailFieldServerComponent,\n EmailFieldServerProps,\n} from './fields/Email.js'\n\nexport type {\n GroupFieldClientComponent,\n GroupFieldClientProps,\n GroupFieldDescriptionClientComponent,\n GroupFieldDescriptionServerComponent,\n GroupFieldErrorClientComponent,\n GroupFieldErrorServerComponent,\n GroupFieldLabelClientComponent,\n GroupFieldLabelServerComponent,\n GroupFieldServerComponent,\n GroupFieldServerProps,\n} from './fields/Group.js'\n\nexport type { HiddenFieldProps } from './fields/Hidden.js'\n\nexport type {\n JoinFieldClientComponent,\n JoinFieldClientProps,\n JoinFieldDescriptionClientComponent,\n JoinFieldDescriptionServerComponent,\n JoinFieldErrorClientComponent,\n JoinFieldErrorServerComponent,\n JoinFieldLabelClientComponent,\n JoinFieldLabelServerComponent,\n JoinFieldServerComponent,\n JoinFieldServerProps,\n} from './fields/Join.js'\n\nexport type {\n JSONFieldClientComponent,\n JSONFieldClientProps,\n JSONFieldDescriptionClientComponent,\n JSONFieldDescriptionServerComponent,\n JSONFieldErrorClientComponent,\n JSONFieldErrorServerComponent,\n JSONFieldLabelClientComponent,\n JSONFieldLabelServerComponent,\n JSONFieldServerComponent,\n JSONFieldServerProps,\n} from './fields/JSON.js'\n\nexport type {\n NumberFieldClientComponent,\n NumberFieldClientProps,\n NumberFieldDescriptionClientComponent,\n NumberFieldDescriptionServerComponent,\n NumberFieldErrorClientComponent,\n NumberFieldErrorServerComponent,\n NumberFieldLabelClientComponent,\n NumberFieldLabelServerComponent,\n NumberFieldServerComponent,\n NumberFieldServerProps,\n} from './fields/Number.js'\n\nexport type {\n PointFieldClientComponent,\n PointFieldClientProps,\n PointFieldDescriptionClientComponent,\n PointFieldDescriptionServerComponent,\n PointFieldErrorClientComponent,\n PointFieldErrorServerComponent,\n PointFieldLabelClientComponent,\n PointFieldLabelServerComponent,\n PointFieldServerComponent,\n PointFieldServerProps,\n} from './fields/Point.js'\n\nexport type {\n RadioFieldClientComponent,\n RadioFieldClientProps,\n RadioFieldDescriptionClientComponent,\n RadioFieldDescriptionServerComponent,\n RadioFieldErrorClientComponent,\n RadioFieldErrorServerComponent,\n RadioFieldLabelClientComponent,\n RadioFieldLabelServerComponent,\n RadioFieldServerComponent,\n RadioFieldServerProps,\n} from './fields/Radio.js'\n\nexport type {\n RelationshipFieldClientComponent,\n RelationshipFieldClientProps,\n RelationshipFieldDescriptionClientComponent,\n RelationshipFieldDescriptionServerComponent,\n RelationshipFieldErrorClientComponent,\n RelationshipFieldErrorServerComponent,\n RelationshipFieldLabelClientComponent,\n RelationshipFieldLabelServerComponent,\n RelationshipFieldServerComponent,\n RelationshipFieldServerProps,\n} from './fields/Relationship.js'\n\nexport type {\n RichTextFieldClientComponent,\n RichTextFieldClientProps,\n RichTextFieldDescriptionClientComponent,\n RichTextFieldDescriptionServerComponent,\n RichTextFieldErrorClientComponent,\n RichTextFieldErrorServerComponent,\n RichTextFieldLabelClientComponent,\n RichTextFieldLabelServerComponent,\n RichTextFieldServerComponent,\n RichTextFieldServerProps,\n} from './fields/RichText.js'\n\nexport type {\n RowFieldClientComponent,\n RowFieldClientProps,\n RowFieldDescriptionClientComponent,\n RowFieldDescriptionServerComponent,\n RowFieldErrorClientComponent,\n RowFieldErrorServerComponent,\n RowFieldLabelClientComponent,\n RowFieldLabelServerComponent,\n RowFieldServerComponent,\n RowFieldServerProps,\n} from './fields/Row.js'\n\nexport type {\n SelectFieldClientComponent,\n SelectFieldClientProps,\n SelectFieldDescriptionClientComponent,\n SelectFieldDescriptionServerComponent,\n SelectFieldErrorClientComponent,\n SelectFieldErrorServerComponent,\n SelectFieldLabelClientComponent,\n SelectFieldLabelServerComponent,\n SelectFieldServerComponent,\n SelectFieldServerProps,\n} from './fields/Select.js'\n\nexport type {\n ClientTab,\n TabsFieldClientComponent,\n TabsFieldClientProps,\n TabsFieldDescriptionClientComponent,\n TabsFieldDescriptionServerComponent,\n TabsFieldErrorClientComponent,\n TabsFieldErrorServerComponent,\n TabsFieldLabelClientComponent,\n TabsFieldLabelServerComponent,\n TabsFieldServerComponent,\n TabsFieldServerProps,\n} from './fields/Tabs.js'\n\nexport type {\n TextFieldClientComponent,\n TextFieldClientProps,\n TextFieldDescriptionClientComponent,\n TextFieldDescriptionServerComponent,\n TextFieldErrorClientComponent,\n TextFieldErrorServerComponent,\n TextFieldLabelClientComponent,\n TextFieldLabelServerComponent,\n TextFieldServerComponent,\n TextFieldServerProps,\n} from './fields/Text.js'\n\nexport type {\n TextareaFieldClientComponent,\n TextareaFieldClientProps,\n TextareaFieldDescriptionClientComponent,\n TextareaFieldDescriptionServerComponent,\n TextareaFieldErrorClientComponent,\n TextareaFieldErrorServerComponent,\n TextareaFieldLabelClientComponent,\n TextareaFieldLabelServerComponent,\n TextareaFieldServerComponent,\n TextareaFieldServerProps,\n} from './fields/Textarea.js'\n\nexport type {\n UIFieldClientComponent,\n UIFieldClientProps,\n UIFieldServerComponent,\n UIFieldServerProps,\n} from './fields/UI.js'\n\nexport type {\n UploadFieldClientComponent,\n UploadFieldClientProps,\n UploadFieldDescriptionClientComponent,\n UploadFieldDescriptionServerComponent,\n UploadFieldErrorClientComponent,\n UploadFieldErrorServerComponent,\n UploadFieldLabelClientComponent,\n UploadFieldLabelServerComponent,\n UploadFieldServerComponent,\n UploadFieldServerProps,\n} from './fields/Upload.js'\n\nexport type {\n Description,\n DescriptionFunction,\n FieldDescriptionClientComponent,\n FieldDescriptionClientProps,\n FieldDescriptionServerComponent,\n FieldDescriptionServerProps,\n GenericDescriptionProps,\n StaticDescription,\n} from './forms/Description.js'\n\nexport type {\n FieldErrorClientComponent,\n FieldErrorClientProps,\n FieldErrorServerComponent,\n FieldErrorServerProps,\n GenericErrorProps,\n} from './forms/Error.js'\n\nexport type {\n BuildFormStateArgs,\n Data,\n FieldState as FormField,\n FieldStateWithoutComponents as FormFieldWithoutComponents,\n FilterOptionsResult,\n FormState,\n FormStateWithoutComponents,\n Row,\n}\n\nexport type {\n ClientComponentProps,\n ClientFieldBase,\n ClientFieldWithOptionalType,\n FieldClientComponent,\n FieldPaths,\n FieldServerComponent,\n ServerComponentProps,\n ServerFieldBase,\n} from './forms/Field.js'\n\nexport type {\n FieldLabelClientComponent,\n FieldLabelClientProps,\n FieldLabelServerComponent,\n FieldLabelServerProps,\n GenericLabelProps,\n SanitizedLabelProps,\n} from './forms/Label.js'\n\nexport type { RowLabel, RowLabelComponent } from './forms/RowLabel.js'\n\nexport type {\n BuildTableStateArgs,\n DefaultServerFunctionArgs,\n ListQuery,\n ServerFunction,\n ServerFunctionArgs,\n ServerFunctionClient,\n ServerFunctionClientArgs,\n ServerFunctionConfig,\n ServerFunctionHandler,\n} from './functions/index.js'\n\nexport type MappedServerComponent<TComponentClientProps extends JsonObject = JsonObject> = {\n Component?: React.ComponentType<TComponentClientProps>\n props?: Partial<any>\n RenderedComponent: React.ReactNode\n type: 'server'\n}\n\nexport type MappedClientComponent<TComponentClientProps extends JsonObject = JsonObject> = {\n Component?: React.ComponentType<TComponentClientProps>\n props?: Partial<TComponentClientProps>\n RenderedComponent?: React.ReactNode\n type: 'client'\n}\n\nexport type MappedEmptyComponent = {\n type: 'empty'\n}\n\nexport enum Action {\n RenderConfig = 'render-config',\n}\n\nexport type RenderEntityConfigArgs = {\n collectionSlug?: string\n data?: Data\n globalSlug?: string\n}\n\nexport type RenderRootConfigArgs = {}\n\nexport type RenderFieldConfigArgs = {\n collectionSlug?: string\n formState?: FormState\n globalSlug?: string\n schemaPath: string\n}\n\nexport type RenderConfigArgs = {\n action: Action.RenderConfig\n config: Promise<SanitizedConfig> | SanitizedConfig\n i18n: I18nClient\n importMap: ImportMap\n languageCode: AcceptedLanguages\n serverProps?: any\n} & (RenderEntityConfigArgs | RenderFieldConfigArgs | RenderRootConfigArgs)\n\nexport type PayloadServerAction = (\n args:\n | {\n [key: string]: any\n action: Action\n i18n: I18nClient\n }\n | RenderConfigArgs,\n) => Promise<string>\n\nexport type RenderedField = {\n Field: React.ReactNode\n indexPath?: string\n initialSchemaPath?: string\n isSidebar: boolean\n path: string\n schemaPath: string\n type: FieldTypes\n}\n\nexport type FieldRow = {\n RowLabel?: React.ReactNode\n}\n\nexport type DocumentSlots = {\n Description?: React.ReactNode\n PreviewButton?: React.ReactNode\n PublishButton?: React.ReactNode\n SaveButton?: React.ReactNode\n SaveDraftButton?: React.ReactNode\n Upload?: React.ReactNode\n}\n\nexport type { LanguageOptions } from './LanguageOptions.js'\n\nexport type { RichTextAdapter, RichTextAdapterProvider, RichTextHooks } from './RichText.js'\n\nexport type {\n AdminViewComponent,\n AdminViewConfig,\n AdminViewProps,\n ClientSideEditViewProps,\n EditViewProps,\n InitPageResult,\n ServerSideEditViewProps,\n VisibleEntities,\n} from './views/types.js'\n\ntype SchemaPath = {} & string\nexport type FieldSchemaMap = Map<\n SchemaPath,\n | {\n fields: Field[]\n }\n | Block\n | Field\n | Tab\n>\n\nexport type ClientFieldSchemaMap = Map<\n SchemaPath,\n | {\n fields: ClientField[]\n }\n | ClientBlock\n | ClientField\n | ClientTab\n>\n"],"names":["Action"],"mappings":"AA6ZA,OAAO,IAAA,AAAKA,gCAAAA;;WAAAA;MAEX"}
|
package/dist/auth/cookies.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/auth/cookies.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from './../collections/config/types.js'\n\ntype CookieOptions = {\n domain?: string\n expires?: Date\n httpOnly?: boolean\n maxAge?: number\n name: string\n path?: string\n returnCookieAsObject: boolean\n sameSite?: 'Lax' | 'None' | 'Strict'\n secure?: boolean\n value?: string\n}\n\ntype CookieObject = {\n domain?: string\n expires?: string\n httpOnly?: boolean\n maxAge?: number\n name: string\n path?: string\n sameSite?: 'Lax' | 'None' | 'Strict'\n secure?: boolean\n value: string | undefined\n}\n\nexport const generateCookie = <ReturnCookieAsObject = boolean>(\n args: CookieOptions,\n): ReturnCookieAsObject extends true ? CookieObject : string => {\n const {\n name,\n domain,\n expires,\n httpOnly,\n maxAge,\n path,\n returnCookieAsObject,\n sameSite,\n secure: secureArg,\n value,\n } = args\n\n let cookieString = `${name}=${value || ''}`\n const cookieObject: CookieObject = {\n name,\n value,\n }\n\n const secure = secureArg || sameSite === 'None'\n\n if (expires) {\n if (returnCookieAsObject) {\n cookieObject.expires = expires.toUTCString()\n } else {\n cookieString += `; Expires=${expires.toUTCString()}`\n }\n }\n\n if (maxAge) {\n if (returnCookieAsObject) {\n cookieObject.maxAge = maxAge\n } else {\n cookieString += `; Max-Age=${maxAge.toString()}`\n }\n }\n\n if (domain) {\n if (returnCookieAsObject) {\n cookieObject.domain = domain\n } else {\n cookieString += `; Domain=${domain}`\n }\n }\n\n if (path) {\n if (returnCookieAsObject) {\n cookieObject.path = path\n } else {\n cookieString += `; Path=${path}`\n }\n }\n\n if (secure) {\n if (returnCookieAsObject) {\n cookieObject.secure = secure\n } else {\n cookieString += `; Secure=${secure}`\n }\n }\n\n if (httpOnly) {\n if (returnCookieAsObject) {\n cookieObject.httpOnly = httpOnly\n } else {\n cookieString += `; HttpOnly=${httpOnly}`\n }\n }\n\n if (sameSite) {\n if (returnCookieAsObject) {\n cookieObject.sameSite = sameSite\n } else {\n cookieString += `; SameSite=${sameSite}`\n }\n }\n\n return (returnCookieAsObject ? cookieObject : cookieString) as ReturnCookieAsObject extends true\n ? CookieObject\n : string\n}\ntype GetCookieExpirationArgs = {\n /*\n The number of seconds until the cookie expires\n @default 7200 seconds (2 hours)\n */\n seconds: number\n}\nexport const getCookieExpiration = ({ seconds = 7200 }: GetCookieExpirationArgs) => {\n const currentTime = new Date()\n currentTime.setSeconds(currentTime.getSeconds() + seconds)\n return currentTime\n}\n\ntype GeneratePayloadCookieArgs = {\n /* The auth collection config */\n collectionAuthConfig: SanitizedCollectionConfig['auth']\n /* Prefix to scope the cookie */\n cookiePrefix: string\n /* The returnAs value */\n returnCookieAsObject?: boolean\n /* The token to be stored in the cookie */\n token: string\n}\nexport const generatePayloadCookie = <T extends GeneratePayloadCookieArgs>({\n collectionAuthConfig,\n cookiePrefix,\n returnCookieAsObject = false,\n token,\n}: T): T['returnCookieAsObject'] extends true ? CookieObject : string => {\n const sameSite =\n typeof collectionAuthConfig.cookies.sameSite === 'string'\n ? collectionAuthConfig.cookies.sameSite\n : collectionAuthConfig.cookies.sameSite\n ? 'Strict'\n : undefined\n\n return generateCookie<T['returnCookieAsObject']>({\n name: `${cookiePrefix}-token`,\n domain: collectionAuthConfig.cookies.domain ?? undefined,\n expires: getCookieExpiration({ seconds: collectionAuthConfig.tokenExpiration }),\n httpOnly: true,\n path: '/',\n returnCookieAsObject,\n sameSite,\n secure: collectionAuthConfig.cookies.secure,\n value: token,\n })\n}\n\nexport const generateExpiredPayloadCookie = <T extends Omit<GeneratePayloadCookieArgs, 'token'>>({\n collectionAuthConfig,\n cookiePrefix,\n returnCookieAsObject = false,\n}: T): T['returnCookieAsObject'] extends true ? CookieObject : string => {\n const sameSite =\n typeof collectionAuthConfig.cookies.sameSite === 'string'\n ? collectionAuthConfig.cookies.sameSite\n : collectionAuthConfig.cookies.sameSite\n ? 'Strict'\n : undefined\n\n const expires = new Date(Date.now() - 1000)\n\n return generateCookie<T['returnCookieAsObject']>({\n name: `${cookiePrefix}-token`,\n domain: collectionAuthConfig.cookies.domain ?? undefined,\n expires,\n httpOnly: true,\n path: '/',\n returnCookieAsObject,\n sameSite,\n secure: collectionAuthConfig.cookies.secure,\n })\n}\n\nexport const parseCookies = (headers: Request['headers']): Map<string, string> => {\n const cookieMap = new Map<string, string>()\n const cookie = headers.get('Cookie')\n\n if (cookie) {\n cookie.split(';').forEach((cookie) => {\n const parts = cookie.split('=')\n const key = parts.shift()?.trim()\n const encodedValue = parts.join('=')\n\n try {\n const decodedValue = decodeURI(encodedValue)\n cookieMap.set(key, decodedValue)\n } catch (ignore) {\n return null\n }\n })\n }\n\n return cookieMap\n}\n"],"names":["generateCookie","args","name","domain","expires","httpOnly","maxAge","path","returnCookieAsObject","sameSite","secure","secureArg","value","cookieString","cookieObject","toUTCString","toString","getCookieExpiration","seconds","currentTime","Date","setSeconds","getSeconds","generatePayloadCookie","collectionAuthConfig","cookiePrefix","token","cookies","undefined","tokenExpiration","generateExpiredPayloadCookie","now","parseCookies","headers","cookieMap","Map","cookie","get","split","forEach","parts","key","shift","trim","encodedValue","join","decodedValue","decodeURI","set","ignore"],"mappings":"AA2BA,OAAO,MAAMA,iBAAiB,CAC5BC;IAEA,MAAM,EACJC,IAAI,EACJC,MAAM,EACNC,OAAO,EACPC,QAAQ,EACRC,MAAM,EACNC,IAAI,EACJC,oBAAoB,EACpBC,QAAQ,EACRC,QAAQC,SAAS,EACjBC,KAAK,EACN,GAAGX;IAEJ,IAAIY,eAAe,
|
|
1
|
+
{"version":3,"sources":["../../src/auth/cookies.ts"],"sourcesContent":["import type { SanitizedCollectionConfig } from './../collections/config/types.js'\n\ntype CookieOptions = {\n domain?: string\n expires?: Date\n httpOnly?: boolean\n maxAge?: number\n name: string\n path?: string\n returnCookieAsObject: boolean\n sameSite?: 'Lax' | 'None' | 'Strict'\n secure?: boolean\n value?: string\n}\n\ntype CookieObject = {\n domain?: string\n expires?: string\n httpOnly?: boolean\n maxAge?: number\n name: string\n path?: string\n sameSite?: 'Lax' | 'None' | 'Strict'\n secure?: boolean\n value: string | undefined\n}\n\nexport const generateCookie = <ReturnCookieAsObject = boolean>(\n args: CookieOptions,\n): ReturnCookieAsObject extends true ? CookieObject : string => {\n const {\n name,\n domain,\n expires,\n httpOnly,\n maxAge,\n path,\n returnCookieAsObject,\n sameSite,\n secure: secureArg,\n value,\n } = args\n\n let cookieString = `${name}=${value || ''}`\n const cookieObject: CookieObject = {\n name,\n value,\n }\n\n const secure = secureArg || sameSite === 'None'\n\n if (expires) {\n if (returnCookieAsObject) {\n cookieObject.expires = expires.toUTCString()\n } else {\n cookieString += `; Expires=${expires.toUTCString()}`\n }\n }\n\n if (maxAge) {\n if (returnCookieAsObject) {\n cookieObject.maxAge = maxAge\n } else {\n cookieString += `; Max-Age=${maxAge.toString()}`\n }\n }\n\n if (domain) {\n if (returnCookieAsObject) {\n cookieObject.domain = domain\n } else {\n cookieString += `; Domain=${domain}`\n }\n }\n\n if (path) {\n if (returnCookieAsObject) {\n cookieObject.path = path\n } else {\n cookieString += `; Path=${path}`\n }\n }\n\n if (secure) {\n if (returnCookieAsObject) {\n cookieObject.secure = secure\n } else {\n cookieString += `; Secure=${secure}`\n }\n }\n\n if (httpOnly) {\n if (returnCookieAsObject) {\n cookieObject.httpOnly = httpOnly\n } else {\n cookieString += `; HttpOnly=${httpOnly}`\n }\n }\n\n if (sameSite) {\n if (returnCookieAsObject) {\n cookieObject.sameSite = sameSite\n } else {\n cookieString += `; SameSite=${sameSite}`\n }\n }\n\n return (returnCookieAsObject ? cookieObject : cookieString) as ReturnCookieAsObject extends true\n ? CookieObject\n : string\n}\ntype GetCookieExpirationArgs = {\n /*\n The number of seconds until the cookie expires\n @default 7200 seconds (2 hours)\n */\n seconds: number\n}\nexport const getCookieExpiration = ({ seconds = 7200 }: GetCookieExpirationArgs) => {\n const currentTime = new Date()\n currentTime.setSeconds(currentTime.getSeconds() + seconds)\n return currentTime\n}\n\ntype GeneratePayloadCookieArgs = {\n /* The auth collection config */\n collectionAuthConfig: SanitizedCollectionConfig['auth']\n /* Prefix to scope the cookie */\n cookiePrefix: string\n /* The returnAs value */\n returnCookieAsObject?: boolean\n /* The token to be stored in the cookie */\n token: string\n}\nexport const generatePayloadCookie = <T extends GeneratePayloadCookieArgs>({\n collectionAuthConfig,\n cookiePrefix,\n returnCookieAsObject = false,\n token,\n}: T): T['returnCookieAsObject'] extends true ? CookieObject : string => {\n const sameSite =\n typeof collectionAuthConfig.cookies.sameSite === 'string'\n ? collectionAuthConfig.cookies.sameSite\n : collectionAuthConfig.cookies.sameSite\n ? 'Strict'\n : undefined\n\n return generateCookie<T['returnCookieAsObject']>({\n name: `${cookiePrefix}-token`,\n domain: collectionAuthConfig.cookies.domain ?? undefined,\n expires: getCookieExpiration({ seconds: collectionAuthConfig.tokenExpiration }),\n httpOnly: true,\n path: '/',\n returnCookieAsObject,\n sameSite,\n secure: collectionAuthConfig.cookies.secure,\n value: token,\n })\n}\n\nexport const generateExpiredPayloadCookie = <T extends Omit<GeneratePayloadCookieArgs, 'token'>>({\n collectionAuthConfig,\n cookiePrefix,\n returnCookieAsObject = false,\n}: T): T['returnCookieAsObject'] extends true ? CookieObject : string => {\n const sameSite =\n typeof collectionAuthConfig.cookies.sameSite === 'string'\n ? collectionAuthConfig.cookies.sameSite\n : collectionAuthConfig.cookies.sameSite\n ? 'Strict'\n : undefined\n\n const expires = new Date(Date.now() - 1000)\n\n return generateCookie<T['returnCookieAsObject']>({\n name: `${cookiePrefix}-token`,\n domain: collectionAuthConfig.cookies.domain ?? undefined,\n expires,\n httpOnly: true,\n path: '/',\n returnCookieAsObject,\n sameSite,\n secure: collectionAuthConfig.cookies.secure,\n })\n}\n\nexport const parseCookies = (headers: Request['headers']): Map<string, string> => {\n const cookieMap = new Map<string, string>()\n const cookie = headers.get('Cookie')\n\n if (cookie) {\n cookie.split(';').forEach((cookie) => {\n const parts = cookie.split('=')\n const key = parts.shift()?.trim()\n const encodedValue = parts.join('=')\n\n try {\n const decodedValue = decodeURI(encodedValue)\n cookieMap.set(key, decodedValue)\n } catch (ignore) {\n return null\n }\n })\n }\n\n return cookieMap\n}\n"],"names":["generateCookie","args","name","domain","expires","httpOnly","maxAge","path","returnCookieAsObject","sameSite","secure","secureArg","value","cookieString","cookieObject","toUTCString","toString","getCookieExpiration","seconds","currentTime","Date","setSeconds","getSeconds","generatePayloadCookie","collectionAuthConfig","cookiePrefix","token","cookies","undefined","tokenExpiration","generateExpiredPayloadCookie","now","parseCookies","headers","cookieMap","Map","cookie","get","split","forEach","parts","key","shift","trim","encodedValue","join","decodedValue","decodeURI","set","ignore"],"mappings":"AA2BA,OAAO,MAAMA,iBAAiB,CAC5BC;IAEA,MAAM,EACJC,IAAI,EACJC,MAAM,EACNC,OAAO,EACPC,QAAQ,EACRC,MAAM,EACNC,IAAI,EACJC,oBAAoB,EACpBC,QAAQ,EACRC,QAAQC,SAAS,EACjBC,KAAK,EACN,GAAGX;IAEJ,IAAIY,eAAe,GAAGX,KAAK,CAAC,EAAEU,SAAS,IAAI;IAC3C,MAAME,eAA6B;QACjCZ;QACAU;IACF;IAEA,MAAMF,SAASC,aAAaF,aAAa;IAEzC,IAAIL,SAAS;QACX,IAAII,sBAAsB;YACxBM,aAAaV,OAAO,GAAGA,QAAQW,WAAW;QAC5C,OAAO;YACLF,gBAAgB,CAAC,UAAU,EAAET,QAAQW,WAAW,IAAI;QACtD;IACF;IAEA,IAAIT,QAAQ;QACV,IAAIE,sBAAsB;YACxBM,aAAaR,MAAM,GAAGA;QACxB,OAAO;YACLO,gBAAgB,CAAC,UAAU,EAAEP,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
|
|
1
|
-
{"version":3,"sources":["../../src/auth/crypto.ts"],"sourcesContent":["import crypto from 'crypto'\n\nconst algorithm = 'aes-256-ctr'\n\nexport function encrypt(text: string): string {\n const iv = crypto.randomBytes(16)\n const cipher = crypto.createCipheriv(algorithm, this.secret, iv)\n\n const encrypted = Buffer.concat([cipher.update(text), cipher.final()])\n\n const ivString = iv.toString('hex')\n const encryptedString = encrypted.toString('hex')\n\n return `${ivString}${encryptedString}`\n}\n\nexport function decrypt(hash: string): string {\n const iv = hash.slice(0, 32)\n const content = hash.slice(32)\n\n const decipher = crypto.createDecipheriv(algorithm, this.secret, Buffer.from(iv, 'hex'))\n\n const decrypted = Buffer.concat([decipher.update(Buffer.from(content, 'hex')), decipher.final()])\n\n return decrypted.toString()\n}\n"],"names":["crypto","algorithm","encrypt","text","iv","randomBytes","cipher","createCipheriv","secret","encrypted","Buffer","concat","update","final","ivString","toString","encryptedString","decrypt","hash","slice","content","decipher","createDecipheriv","from","decrypted"],"mappings":"AAAA,OAAOA,YAAY,SAAQ;AAE3B,MAAMC,YAAY;AAElB,OAAO,SAASC,QAAQC,IAAY;IAClC,MAAMC,KAAKJ,OAAOK,WAAW,CAAC;IAC9B,MAAMC,SAASN,OAAOO,cAAc,CAACN,WAAW,IAAI,CAACO,MAAM,EAAEJ;IAE7D,MAAMK,YAAYC,OAAOC,MAAM,CAAC;QAACL,OAAOM,MAAM,CAACT;QAAOG,OAAOO,KAAK;KAAG;IAErE,MAAMC,WAAWV,GAAGW,QAAQ,CAAC;IAC7B,MAAMC,kBAAkBP,UAAUM,QAAQ,CAAC;IAE3C,OAAO,
|
|
1
|
+
{"version":3,"sources":["../../src/auth/crypto.ts"],"sourcesContent":["import crypto from 'crypto'\n\nconst algorithm = 'aes-256-ctr'\n\nexport function encrypt(text: string): string {\n const iv = crypto.randomBytes(16)\n const cipher = crypto.createCipheriv(algorithm, this.secret, iv)\n\n const encrypted = Buffer.concat([cipher.update(text), cipher.final()])\n\n const ivString = iv.toString('hex')\n const encryptedString = encrypted.toString('hex')\n\n return `${ivString}${encryptedString}`\n}\n\nexport function decrypt(hash: string): string {\n const iv = hash.slice(0, 32)\n const content = hash.slice(32)\n\n const decipher = crypto.createDecipheriv(algorithm, this.secret, Buffer.from(iv, 'hex'))\n\n const decrypted = Buffer.concat([decipher.update(Buffer.from(content, 'hex')), decipher.final()])\n\n return decrypted.toString()\n}\n"],"names":["crypto","algorithm","encrypt","text","iv","randomBytes","cipher","createCipheriv","secret","encrypted","Buffer","concat","update","final","ivString","toString","encryptedString","decrypt","hash","slice","content","decipher","createDecipheriv","from","decrypted"],"mappings":"AAAA,OAAOA,YAAY,SAAQ;AAE3B,MAAMC,YAAY;AAElB,OAAO,SAASC,QAAQC,IAAY;IAClC,MAAMC,KAAKJ,OAAOK,WAAW,CAAC;IAC9B,MAAMC,SAASN,OAAOO,cAAc,CAACN,WAAW,IAAI,CAACO,MAAM,EAAEJ;IAE7D,MAAMK,YAAYC,OAAOC,MAAM,CAAC;QAACL,OAAOM,MAAM,CAACT;QAAOG,OAAOO,KAAK;KAAG;IAErE,MAAMC,WAAWV,GAAGW,QAAQ,CAAC;IAC7B,MAAMC,kBAAkBP,UAAUM,QAAQ,CAAC;IAE3C,OAAO,GAAGD,WAAWE,iBAAiB;AACxC;AAEA,OAAO,SAASC,QAAQC,IAAY;IAClC,MAAMd,KAAKc,KAAKC,KAAK,CAAC,GAAG;IACzB,MAAMC,UAAUF,KAAKC,KAAK,CAAC;IAE3B,MAAME,WAAWrB,OAAOsB,gBAAgB,CAACrB,WAAW,IAAI,CAACO,MAAM,EAAEE,OAAOa,IAAI,CAACnB,IAAI;IAEjF,MAAMoB,YAAYd,OAAOC,MAAM,CAAC;QAACU,SAAST,MAAM,CAACF,OAAOa,IAAI,CAACH,SAAS;QAASC,SAASR,KAAK;KAAG;IAEhG,OAAOW,UAAUT,QAAQ;AAC3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/auth/extractJWT.ts"],"sourcesContent":["import type { AuthStrategyFunctionArgs } from './index.js'\n\nimport { parseCookies } from '../utilities/parseCookies.js'\n\nexport const extractJWT = (args: AuthStrategyFunctionArgs): null | string => {\n const { headers, payload } = args\n\n const jwtFromHeader = headers.get('Authorization')\n const origin = headers.get('Origin')\n\n if (jwtFromHeader?.startsWith('JWT ')) {\n return jwtFromHeader.replace('JWT ', '')\n }\n // allow RFC6750 OAuth 2.0 compliant Bearer tokens\n // in addition to the payload default JWT format\n if (jwtFromHeader?.startsWith('Bearer ')) {\n return jwtFromHeader.replace('Bearer ', '')\n }\n\n const cookies = parseCookies(headers)\n const tokenCookieName = `${payload.config.cookiePrefix}-token`\n const cookieToken = cookies.get(tokenCookieName)\n\n if (!cookieToken) {\n return null\n }\n\n if (!origin || payload.config.csrf.length === 0 || payload.config.csrf.indexOf(origin) > -1) {\n return cookieToken\n }\n\n return null\n}\n"],"names":["parseCookies","extractJWT","args","headers","payload","jwtFromHeader","get","origin","startsWith","replace","cookies","tokenCookieName","config","cookiePrefix","cookieToken","csrf","length","indexOf"],"mappings":"AAEA,SAASA,YAAY,QAAQ,+BAA8B;AAE3D,OAAO,MAAMC,aAAa,CAACC;IACzB,MAAM,EAAEC,OAAO,EAAEC,OAAO,EAAE,GAAGF;IAE7B,MAAMG,gBAAgBF,QAAQG,GAAG,CAAC;IAClC,MAAMC,SAASJ,QAAQG,GAAG,CAAC;IAE3B,IAAID,eAAeG,WAAW,SAAS;QACrC,OAAOH,cAAcI,OAAO,CAAC,QAAQ;IACvC;IACA,kDAAkD;IAClD,gDAAgD;IAChD,IAAIJ,eAAeG,WAAW,YAAY;QACxC,OAAOH,cAAcI,OAAO,CAAC,WAAW;IAC1C;IAEA,MAAMC,UAAUV,aAAaG;IAC7B,MAAMQ,kBAAkB,
|
|
1
|
+
{"version":3,"sources":["../../src/auth/extractJWT.ts"],"sourcesContent":["import type { AuthStrategyFunctionArgs } from './index.js'\n\nimport { parseCookies } from '../utilities/parseCookies.js'\n\nexport const extractJWT = (args: AuthStrategyFunctionArgs): null | string => {\n const { headers, payload } = args\n\n const jwtFromHeader = headers.get('Authorization')\n const origin = headers.get('Origin')\n\n if (jwtFromHeader?.startsWith('JWT ')) {\n return jwtFromHeader.replace('JWT ', '')\n }\n // allow RFC6750 OAuth 2.0 compliant Bearer tokens\n // in addition to the payload default JWT format\n if (jwtFromHeader?.startsWith('Bearer ')) {\n return jwtFromHeader.replace('Bearer ', '')\n }\n\n const cookies = parseCookies(headers)\n const tokenCookieName = `${payload.config.cookiePrefix}-token`\n const cookieToken = cookies.get(tokenCookieName)\n\n if (!cookieToken) {\n return null\n }\n\n if (!origin || payload.config.csrf.length === 0 || payload.config.csrf.indexOf(origin) > -1) {\n return cookieToken\n }\n\n return null\n}\n"],"names":["parseCookies","extractJWT","args","headers","payload","jwtFromHeader","get","origin","startsWith","replace","cookies","tokenCookieName","config","cookiePrefix","cookieToken","csrf","length","indexOf"],"mappings":"AAEA,SAASA,YAAY,QAAQ,+BAA8B;AAE3D,OAAO,MAAMC,aAAa,CAACC;IACzB,MAAM,EAAEC,OAAO,EAAEC,OAAO,EAAE,GAAGF;IAE7B,MAAMG,gBAAgBF,QAAQG,GAAG,CAAC;IAClC,MAAMC,SAASJ,QAAQG,GAAG,CAAC;IAE3B,IAAID,eAAeG,WAAW,SAAS;QACrC,OAAOH,cAAcI,OAAO,CAAC,QAAQ;IACvC;IACA,kDAAkD;IAClD,gDAAgD;IAChD,IAAIJ,eAAeG,WAAW,YAAY;QACxC,OAAOH,cAAcI,OAAO,CAAC,WAAW;IAC1C;IAEA,MAAMC,UAAUV,aAAaG;IAC7B,MAAMQ,kBAAkB,GAAGP,QAAQQ,MAAM,CAACC,YAAY,CAAC,MAAM,CAAC;IAC9D,MAAMC,cAAcJ,QAAQJ,GAAG,CAACK;IAEhC,IAAI,CAACG,aAAa;QAChB,OAAO;IACT;IAEA,IAAI,CAACP,UAAUH,QAAQQ,MAAM,CAACG,IAAI,CAACC,MAAM,KAAK,KAAKZ,QAAQQ,MAAM,CAACG,IAAI,CAACE,OAAO,CAACV,UAAU,CAAC,GAAG;QAC3F,OAAOO;IACT;IAEA,OAAO;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getAuthFields.d.ts","sourceRoot":"","sources":["../../src/auth/getAuthFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAa,MAAM,2BAA2B,CAAA;AACjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AASlD,eAAO,MAAM,iBAAiB,eAAgB,gBAAgB,KAAG,KAAK,
|
|
1
|
+
{"version":3,"file":"getAuthFields.d.ts","sourceRoot":"","sources":["../../src/auth/getAuthFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAa,MAAM,2BAA2B,CAAA;AACjE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AASlD,eAAO,MAAM,iBAAiB,eAAgB,gBAAgB,KAAG,KAAK,EA+CrE,CAAA"}
|
|
@@ -9,7 +9,7 @@ export const getBaseAuthFields = (authConfig)=>{
|
|
|
9
9
|
if (authConfig.useAPIKey) {
|
|
10
10
|
authFields.push(...apiKeyFields);
|
|
11
11
|
}
|
|
12
|
-
if (!authConfig.disableLocalStrategy) {
|
|
12
|
+
if (!authConfig.disableLocalStrategy || typeof authConfig.disableLocalStrategy === 'object' && authConfig.disableLocalStrategy.enableFields) {
|
|
13
13
|
const emailField = {
|
|
14
14
|
...emailFieldConfig
|
|
15
15
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/auth/getAuthFields.ts"],"sourcesContent":["import type { Field, TextField } from '../fields/config/types.js'\nimport type { IncomingAuthType } from './types.js'\n\nimport { accountLockFields } from './baseFields/accountLock.js'\nimport { apiKeyFields } from './baseFields/apiKey.js'\nimport { baseAuthFields } from './baseFields/auth.js'\nimport { emailFieldConfig } from './baseFields/email.js'\nimport { usernameFieldConfig } from './baseFields/username.js'\nimport { verificationFields } from './baseFields/verification.js'\n\nexport const getBaseAuthFields = (authConfig: IncomingAuthType): Field[] => {\n const authFields: Field[] = []\n\n if (authConfig.useAPIKey) {\n authFields.push(...apiKeyFields)\n }\n\n if (!authConfig.disableLocalStrategy) {\n const emailField = { ...emailFieldConfig }\n let usernameField: TextField | undefined\n\n if (authConfig.loginWithUsername) {\n usernameField = { ...usernameFieldConfig }\n if (typeof authConfig.loginWithUsername === 'object') {\n if (authConfig.loginWithUsername.requireEmail === false) {\n emailField.required = false\n }\n if (authConfig.loginWithUsername.requireUsername === false) {\n usernameField.required = false\n }\n if (authConfig.loginWithUsername.allowEmailLogin === false) {\n emailField.unique = false\n }\n }\n }\n\n authFields.push(emailField)\n if (usernameField) {\n authFields.push(usernameField)\n }\n\n authFields.push(...baseAuthFields)\n\n if (authConfig.verify) {\n authFields.push(...verificationFields)\n }\n\n if (authConfig?.maxLoginAttempts && authConfig.maxLoginAttempts > 0) {\n authFields.push(...accountLockFields)\n }\n }\n\n return authFields\n}\n"],"names":["accountLockFields","apiKeyFields","baseAuthFields","emailFieldConfig","usernameFieldConfig","verificationFields","getBaseAuthFields","authConfig","authFields","useAPIKey","push","disableLocalStrategy","emailField","usernameField","loginWithUsername","requireEmail","required","requireUsername","allowEmailLogin","unique","verify","maxLoginAttempts"],"mappings":"AAGA,SAASA,iBAAiB,QAAQ,8BAA6B;AAC/D,SAASC,YAAY,QAAQ,yBAAwB;AACrD,SAASC,cAAc,QAAQ,uBAAsB;AACrD,SAASC,gBAAgB,QAAQ,wBAAuB;AACxD,SAASC,mBAAmB,QAAQ,2BAA0B;AAC9D,SAASC,kBAAkB,QAAQ,+BAA8B;AAEjE,OAAO,MAAMC,oBAAoB,CAACC;IAChC,MAAMC,aAAsB,EAAE;IAE9B,IAAID,WAAWE,SAAS,EAAE;QACxBD,WAAWE,IAAI,IAAIT;IACrB;IAEA,
|
|
1
|
+
{"version":3,"sources":["../../src/auth/getAuthFields.ts"],"sourcesContent":["import type { Field, TextField } from '../fields/config/types.js'\nimport type { IncomingAuthType } from './types.js'\n\nimport { accountLockFields } from './baseFields/accountLock.js'\nimport { apiKeyFields } from './baseFields/apiKey.js'\nimport { baseAuthFields } from './baseFields/auth.js'\nimport { emailFieldConfig } from './baseFields/email.js'\nimport { usernameFieldConfig } from './baseFields/username.js'\nimport { verificationFields } from './baseFields/verification.js'\n\nexport const getBaseAuthFields = (authConfig: IncomingAuthType): Field[] => {\n const authFields: Field[] = []\n\n if (authConfig.useAPIKey) {\n authFields.push(...apiKeyFields)\n }\n\n if (\n !authConfig.disableLocalStrategy ||\n (typeof authConfig.disableLocalStrategy === 'object' &&\n authConfig.disableLocalStrategy.enableFields)\n ) {\n const emailField = { ...emailFieldConfig }\n let usernameField: TextField | undefined\n\n if (authConfig.loginWithUsername) {\n usernameField = { ...usernameFieldConfig }\n if (typeof authConfig.loginWithUsername === 'object') {\n if (authConfig.loginWithUsername.requireEmail === false) {\n emailField.required = false\n }\n if (authConfig.loginWithUsername.requireUsername === false) {\n usernameField.required = false\n }\n if (authConfig.loginWithUsername.allowEmailLogin === false) {\n emailField.unique = false\n }\n }\n }\n\n authFields.push(emailField)\n if (usernameField) {\n authFields.push(usernameField)\n }\n\n authFields.push(...baseAuthFields)\n\n if (authConfig.verify) {\n authFields.push(...verificationFields)\n }\n\n if (authConfig?.maxLoginAttempts && authConfig.maxLoginAttempts > 0) {\n authFields.push(...accountLockFields)\n }\n }\n\n return authFields\n}\n"],"names":["accountLockFields","apiKeyFields","baseAuthFields","emailFieldConfig","usernameFieldConfig","verificationFields","getBaseAuthFields","authConfig","authFields","useAPIKey","push","disableLocalStrategy","enableFields","emailField","usernameField","loginWithUsername","requireEmail","required","requireUsername","allowEmailLogin","unique","verify","maxLoginAttempts"],"mappings":"AAGA,SAASA,iBAAiB,QAAQ,8BAA6B;AAC/D,SAASC,YAAY,QAAQ,yBAAwB;AACrD,SAASC,cAAc,QA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word.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,gCAAgC,EAChC,UAAU,EACX,MAAM,mCAAmC,CAAA;AAC1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EAAE,cAAc,EAAS,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"forgotPassword.d.ts","sourceRoot":"","sources":["../../../src/auth/operations/forgotPassword.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,gCAAgC,EAChC,UAAU,EACX,MAAM,mCAAmC,CAAA;AAC1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EAAE,cAAc,EAAS,MAAM,sBAAsB,CAAA;AAUjE,MAAM,MAAM,SAAS,CAAC,KAAK,SAAS,cAAc,IAAI;IACpD,UAAU,EAAE,UAAU,CAAA;IACtB,IAAI,EAAE;QACJ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KACvB,GAAG,gCAAgC,CAAC,KAAK,CAAC,CAAC,gBAAgB,CAAC,CAAA;IAC7D,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,MAAM,GAAG,MAAM,CAAA;AAE3B,eAAO,MAAM,uBAAuB,GAAU,KAAK,SAAS,cAAc,gBAC1D,SAAS,CAAC,KAAK,CAAC,KAC7B,OAAO,CAAC,IAAI,GAAG,MAAM,CAoLvB,CAAA"}
|
|
@@ -3,6 +3,7 @@ import httpStatus from 'http-status';
|
|
|
3
3
|
import { URL } from 'url';
|
|
4
4
|
import { buildAfterOperation } from '../../collections/operations/utils.js';
|
|
5
5
|
import { APIError } from '../../errors/index.js';
|
|
6
|
+
import { Forbidden } from '../../index.js';
|
|
6
7
|
import { commitTransaction } from '../../utilities/commitTransaction.js';
|
|
7
8
|
import { initTransaction } from '../../utilities/initTransaction.js';
|
|
8
9
|
import { killTransaction } from '../../utilities/killTransaction.js';
|
|
@@ -13,10 +14,13 @@ export const forgotPasswordOperation = async (incomingArgs)=>{
|
|
|
13
14
|
const { canLoginWithEmail, canLoginWithUsername } = getLoginOptions(loginWithUsername);
|
|
14
15
|
const sanitizedEmail = canLoginWithEmail && (incomingArgs.data.email || '').toLowerCase().trim() || null;
|
|
15
16
|
const sanitizedUsername = 'username' in data && typeof data?.username === 'string' ? data.username.toLowerCase().trim() : null;
|
|
17
|
+
let args = incomingArgs;
|
|
18
|
+
if (incomingArgs.collection.config.auth.disableLocalStrategy) {
|
|
19
|
+
throw new Forbidden(incomingArgs.req.t);
|
|
20
|
+
}
|
|
16
21
|
if (!sanitizedEmail && !sanitizedUsername) {
|
|
17
22
|
throw new APIError(`Missing ${loginWithUsername ? 'username' : 'email'}.`, httpStatus.BAD_REQUEST);
|
|
18
23
|
}
|
|
19
|
-
let args = incomingArgs;
|
|
20
24
|
try {
|
|
21
25
|
const shouldCommit = await initTransaction(args.req);
|
|
22
26
|
// /////////////////////////////////////
|
|
@@ -32,7 +36,7 @@ export const forgotPasswordOperation = async (incomingArgs)=>{
|
|
|
32
36
|
req: args.req
|
|
33
37
|
}) || args;
|
|
34
38
|
}, Promise.resolve());
|
|
35
|
-
const { collection: { config: collectionConfig },
|
|
39
|
+
const { collection: { config: collectionConfig }, disableEmail, expiration, req: { payload: { config, email }, payload }, req } = args;
|
|
36
40
|
// /////////////////////////////////////
|
|
37
41
|
// Forget password
|
|
38
42
|
// /////////////////////////////////////
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/auth/operations/forgotPassword.ts"],"sourcesContent":["import crypto from 'crypto'\nimport httpStatus from 'http-status'\nimport { URL } from 'url'\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 { buildAfterOperation } from '../../collections/operations/utils.js'\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 { getLoginOptions } from '../getLoginOptions.js'\n\nexport type Arguments<TSlug extends CollectionSlug> = {\n collection: Collection\n data: {\n [key: string]: unknown\n } & AuthOperationsFromCollectionSlug<TSlug>['forgotPassword']\n disableEmail?: boolean\n expiration?: number\n req: PayloadRequest\n}\n\nexport type Result = string\n\nexport const forgotPasswordOperation = async <TSlug extends CollectionSlug>(\n incomingArgs: Arguments<TSlug>,\n): Promise<null | string> => {\n const loginWithUsername = incomingArgs.collection.config.auth.loginWithUsername\n const { data } = incomingArgs\n\n const { canLoginWithEmail, canLoginWithUsername } = getLoginOptions(loginWithUsername)\n\n const sanitizedEmail =\n (canLoginWithEmail && (incomingArgs.data.email || '').toLowerCase().trim()) || null\n const sanitizedUsername =\n 'username' in data && typeof data?.username === 'string'\n ? data.username.toLowerCase().trim()\n : null\n\n if (!sanitizedEmail && !sanitizedUsername) {\n throw new APIError(\n `Missing ${loginWithUsername ? 'username' : 'email'}.`,\n httpStatus.BAD_REQUEST,\n )\n }\n\n let args = incomingArgs\n\n try {\n const shouldCommit = await initTransaction(args.req)\n\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n await args.collection.config.hooks.beforeOperation.reduce(async (priorHook, hook) => {\n await priorHook\n\n args =\n (await hook({\n args,\n collection: args.collection?.config,\n context: args.req.context,\n operation: 'forgotPassword',\n req: args.req,\n })) || args\n }, Promise.resolve())\n\n const {\n collection: { config: collectionConfig },\n data,\n disableEmail,\n expiration,\n req: {\n payload: { config, email },\n payload,\n },\n req,\n } = args\n\n // /////////////////////////////////////\n // Forget password\n // /////////////////////////////////////\n\n let token: string = crypto.randomBytes(20).toString('hex')\n type UserDoc = {\n email?: string\n id: number | string\n resetPasswordExpiration?: string\n resetPasswordToken?: string\n }\n\n if (!sanitizedEmail && !sanitizedUsername) {\n throw new APIError(\n `Missing ${loginWithUsername ? 'username' : 'email'}.`,\n httpStatus.BAD_REQUEST,\n )\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 let user = await payload.db.findOne<UserDoc>({\n collection: collectionConfig.slug,\n req,\n where: whereConstraint,\n })\n\n // We don't want to indicate specifically that an email was not found,\n // as doing so could lead to the exposure of registered emails.\n // Therefore, we prefer to fail silently.\n if (!user) {\n return null\n }\n\n user.resetPasswordToken = token\n user.resetPasswordExpiration = new Date(expiration || Date.now() + 3600000).toISOString() // 1 hour\n\n user = await payload.update({\n id: user.id,\n collection: collectionConfig.slug,\n data: user,\n req,\n })\n\n if (!disableEmail && user.email) {\n const protocol = new URL(req.url).protocol // includes the final :\n const serverURL =\n config.serverURL !== null && config.serverURL !== ''\n ? config.serverURL\n : `${protocol}//${req.headers.get('host')}`\n\n let html = `${req.t('authentication:youAreReceivingResetPassword')}\n <a href=\"${serverURL}${config.routes.admin}${config.admin.routes.reset}/${token}\">${serverURL}${config.routes.admin}${config.admin.routes.reset}/${token}</a>\n ${req.t('authentication:youDidNotRequestPassword')}`\n\n if (typeof collectionConfig.auth.forgotPassword?.generateEmailHTML === 'function') {\n html = await collectionConfig.auth.forgotPassword.generateEmailHTML({\n req,\n token,\n user,\n })\n }\n\n let subject = req.t('authentication:resetYourPassword')\n\n if (typeof collectionConfig.auth.forgotPassword?.generateEmailSubject === 'function') {\n subject = await collectionConfig.auth.forgotPassword.generateEmailSubject({\n req,\n token,\n user,\n })\n }\n\n await email.sendEmail({\n from: `\"${email.defaultFromName}\" <${email.defaultFromAddress}>`,\n html,\n subject,\n to: user.email,\n })\n }\n\n // /////////////////////////////////////\n // afterForgotPassword - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.afterForgotPassword.reduce(async (priorHook, hook) => {\n await priorHook\n await hook({ args, collection: args.collection?.config, context: req.context })\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n token = await buildAfterOperation({\n args,\n collection: args.collection?.config,\n operation: 'forgotPassword',\n result: token,\n })\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return token\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["crypto","httpStatus","URL","buildAfterOperation","APIError","commitTransaction","initTransaction","killTransaction","getLoginOptions","forgotPasswordOperation","incomingArgs","loginWithUsername","collection","config","auth","data","canLoginWithEmail","canLoginWithUsername","sanitizedEmail","email","toLowerCase","trim","sanitizedUsername","username","BAD_REQUEST","args","shouldCommit","req","hooks","beforeOperation","reduce","priorHook","hook","context","operation","Promise","resolve","collectionConfig","disableEmail","expiration","payload","token","randomBytes","toString","whereConstraint","equals","user","db","findOne","slug","where","resetPasswordToken","resetPasswordExpiration","Date","now","toISOString","update","id","protocol","url","serverURL","headers","get","html","t","routes","admin","reset","forgotPassword","generateEmailHTML","subject","generateEmailSubject","sendEmail","from","defaultFromName","defaultFromAddress","to","afterForgotPassword","result","error"],"mappings":"AAAA,OAAOA,YAAY,SAAQ;AAC3B,OAAOC,gBAAgB,cAAa;AACpC,SAASC,GAAG,QAAQ,MAAK;AASzB,SAASC,mBAAmB,QAAQ,wCAAuC;AAC3E,SAASC,QAAQ,QAAQ,wBAAuB;AAChD,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,wBAAuB;AAcvD,OAAO,MAAMC,0BAA0B,OACrCC;IAEA,MAAMC,oBAAoBD,aAAaE,UAAU,CAACC,MAAM,CAACC,IAAI,CAACH,iBAAiB;IAC/E,MAAM,EAA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YAAYa,KAAKb,UAAU,EAAEC;YAC7BqB,WAAW;YACX4C,QAAQrC;QACV;QAEA,IAAIf,cAAc;YAChB,MAAMrB,kBAAkBsB;QAC1B;QAEA,OAAOc;IACT,EAAE,OAAOsC,OAAgB;QACvB,MAAMxE,gBAAgBkB,KAAKE,GAAG;QAC9B,MAAMoD;IACR;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/auth/operations/forgotPassword.ts"],"sourcesContent":["import crypto from 'crypto'\nimport httpStatus from 'http-status'\nimport { URL } from 'url'\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 { buildAfterOperation } from '../../collections/operations/utils.js'\nimport { APIError } from '../../errors/index.js'\nimport { Forbidden } from '../../index.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { getLoginOptions } from '../getLoginOptions.js'\n\nexport type Arguments<TSlug extends CollectionSlug> = {\n collection: Collection\n data: {\n [key: string]: unknown\n } & AuthOperationsFromCollectionSlug<TSlug>['forgotPassword']\n disableEmail?: boolean\n expiration?: number\n req: PayloadRequest\n}\n\nexport type Result = string\n\nexport const forgotPasswordOperation = async <TSlug extends CollectionSlug>(\n incomingArgs: Arguments<TSlug>,\n): Promise<null | string> => {\n const loginWithUsername = incomingArgs.collection.config.auth.loginWithUsername\n const { data } = incomingArgs\n\n const { canLoginWithEmail, canLoginWithUsername } = getLoginOptions(loginWithUsername)\n\n const sanitizedEmail =\n (canLoginWithEmail && (incomingArgs.data.email || '').toLowerCase().trim()) || null\n const sanitizedUsername =\n 'username' in data && typeof data?.username === 'string'\n ? data.username.toLowerCase().trim()\n : null\n\n let args = incomingArgs\n\n if (incomingArgs.collection.config.auth.disableLocalStrategy) {\n throw new Forbidden(incomingArgs.req.t)\n }\n if (!sanitizedEmail && !sanitizedUsername) {\n throw new APIError(\n `Missing ${loginWithUsername ? 'username' : 'email'}.`,\n httpStatus.BAD_REQUEST,\n )\n }\n\n try {\n const shouldCommit = await initTransaction(args.req)\n\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n await args.collection.config.hooks.beforeOperation.reduce(async (priorHook, hook) => {\n await priorHook\n\n args =\n (await hook({\n args,\n collection: args.collection?.config,\n context: args.req.context,\n operation: 'forgotPassword',\n req: args.req,\n })) || args\n }, Promise.resolve())\n\n const {\n collection: { config: collectionConfig },\n disableEmail,\n expiration,\n req: {\n payload: { config, email },\n payload,\n },\n req,\n } = args\n\n // /////////////////////////////////////\n // Forget password\n // /////////////////////////////////////\n\n let token: string = crypto.randomBytes(20).toString('hex')\n type UserDoc = {\n email?: string\n id: number | string\n resetPasswordExpiration?: string\n resetPasswordToken?: string\n }\n\n if (!sanitizedEmail && !sanitizedUsername) {\n throw new APIError(\n `Missing ${loginWithUsername ? 'username' : 'email'}.`,\n httpStatus.BAD_REQUEST,\n )\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 let user = await payload.db.findOne<UserDoc>({\n collection: collectionConfig.slug,\n req,\n where: whereConstraint,\n })\n\n // We don't want to indicate specifically that an email was not found,\n // as doing so could lead to the exposure of registered emails.\n // Therefore, we prefer to fail silently.\n if (!user) {\n return null\n }\n\n user.resetPasswordToken = token\n user.resetPasswordExpiration = new Date(expiration || Date.now() + 3600000).toISOString() // 1 hour\n\n user = await payload.update({\n id: user.id,\n collection: collectionConfig.slug,\n data: user,\n req,\n })\n\n if (!disableEmail && user.email) {\n const protocol = new URL(req.url).protocol // includes the final :\n const serverURL =\n config.serverURL !== null && config.serverURL !== ''\n ? config.serverURL\n : `${protocol}//${req.headers.get('host')}`\n\n let html = `${req.t('authentication:youAreReceivingResetPassword')}\n <a href=\"${serverURL}${config.routes.admin}${config.admin.routes.reset}/${token}\">${serverURL}${config.routes.admin}${config.admin.routes.reset}/${token}</a>\n ${req.t('authentication:youDidNotRequestPassword')}`\n\n if (typeof collectionConfig.auth.forgotPassword?.generateEmailHTML === 'function') {\n html = await collectionConfig.auth.forgotPassword.generateEmailHTML({\n req,\n token,\n user,\n })\n }\n\n let subject = req.t('authentication:resetYourPassword')\n\n if (typeof collectionConfig.auth.forgotPassword?.generateEmailSubject === 'function') {\n subject = await collectionConfig.auth.forgotPassword.generateEmailSubject({\n req,\n token,\n user,\n })\n }\n\n await email.sendEmail({\n from: `\"${email.defaultFromName}\" <${email.defaultFromAddress}>`,\n html,\n subject,\n to: user.email,\n })\n }\n\n // /////////////////////////////////////\n // afterForgotPassword - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.afterForgotPassword.reduce(async (priorHook, hook) => {\n await priorHook\n await hook({ args, collection: args.collection?.config, context: req.context })\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n token = await buildAfterOperation({\n args,\n collection: args.collection?.config,\n operation: 'forgotPassword',\n result: token,\n })\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return token\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["crypto","httpStatus","URL","buildAfterOperation","APIError","Forbidden","commitTransaction","initTransaction","killTransaction","getLoginOptions","forgotPasswordOperation","incomingArgs","loginWithUsername","collection","config","auth","data","canLoginWithEmail","canLoginWithUsername","sanitizedEmail","email","toLowerCase","trim","sanitizedUsername","username","args","disableLocalStrategy","req","t","BAD_REQUEST","shouldCommit","hooks","beforeOperation","reduce","priorHook","hook","context","operation","Promise","resolve","collectionConfig","disableEmail","expiration","payload","token","randomBytes","toString","whereConstraint","equals","user","db","findOne","slug","where","resetPasswordToken","resetPasswordExpiration","Date","now","toISOString","update","id","protocol","url","serverURL","headers","get","html","routes","admin","reset","forgotPassword","generateEmailHTML","subject","generateEmailSubject","sendEmail","from","defaultFromName","defaultFromAddress","to","afterForgotPassword","result","error"],"mappings":"AAAA,OAAOA,YAAY,SAAQ;AAC3B,OAAOC,gBAAgB,cAAa;AACpC,SAASC,GAAG,QAAQ,MAAK;AASzB,SAASC,mBAAmB,QAAQ,wCAAuC;AAC3E,SAASC,QAAQ,QAAQ,wBAAuB;AAChD,SAASC,SAAS,QAAQ,iBAAgB;AAC1C,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,wBAAuB;AAcvD,OAAO,MAAMC,0BAA0B,OACrCC;IAEA,MAAMC,oBAAoBD,aAAaE,UAAU,CAACC,MAAM,CAACC,IAAI,CAACH,iBAAiB;IAC/E,MAAM,EAAEI,IAAI,EAAE,GAAGL;IAEjB,MAAM,EAAEM,iBAAiB,EAAEC,oBAAoB,EAAE,GAAGT,gBAAgBG;IAEpE,MAAMO,iBACJ,AAACF,qBAAqB,AAACN,CAAAA,aAAaK,IAAI,CAACI,KAAK,IAAI,EAAC,EAAGC,WAAW,GAAGC,IAAI,MAAO;IACjF,MAAMC,oBACJ,cAAcP,QAAQ,OAAOA,MAAMQ,aAAa,WAC5CR,KAAKQ,QAAQ,CAACH,WAAW,GAAGC,IAAI,KAChC;IAEN,IAAIG,OAAOd;IAEX,IAAIA,aAAaE,UAAU,CAACC,MAAM,CAACC,IAAI,CAACW,oBAAoB,EAAE;QAC5D,MAAM,IAAIrB,UAAUM,aAAagB,GAAG,CAACC,CAAC;IACxC;IACA,IAAI,CAACT,kBAAkB,CAACI,mBAAmB;QACzC,MAAM,IAAInB,SACR,CAAC,QAAQ,EAAEQ,oBAAoB,aAAa,QAAQ,CAAC,CAAC,EACtDX,WAAW4B,WAAW;IAE1B;IAEA,IAAI;QAC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,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../../src/auth/operations/login.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gCAAgC,EAChC,UAAU,EACV,sBAAsB,EACvB,MAAM,mCAAmC,CAAA;AAC1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EAAE,cAAc,EAAS,MAAM,sBAAsB,CAAA;AACjE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAgBvC,MAAM,MAAM,MAAM,GAAG;IACnB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,IAAI,CAAA;CACZ,CAAA;AAED,MAAM,MAAM,SAAS,CAAC,KAAK,SAAS,cAAc,IAAI;IACpD,UAAU,EAAE,UAAU,CAAA;IACtB,IAAI,EAAE,gCAAgC,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAA;IACtD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,GAAG,EAAE,cAAc,CAAA;IACnB,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B,CAAA;AAED,eAAO,MAAM,cAAc,GAAU,KAAK,SAAS,cAAc,gBACjD,SAAS,CAAC,KAAK,CAAC,KAC7B,OAAO,CAAC;IAAE,IAAI,EAAE,sBAAsB,CAAC,KAAK,CAAC,CAAA;CAAE,GAAG,MAAM,CA6R1D,CAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { buildAfterOperation } from '../../collections/operations/utils.js';
|
|
2
2
|
import { AuthenticationError, LockedAuth, ValidationError } from '../../errors/index.js';
|
|
3
3
|
import { afterRead } from '../../fields/hooks/afterRead/index.js';
|
|
4
|
+
import { Forbidden } from '../../index.js';
|
|
4
5
|
import { killTransaction } from '../../utilities/killTransaction.js';
|
|
5
6
|
import sanitizeInternalFields from '../../utilities/sanitizeInternalFields.js';
|
|
6
7
|
import { getFieldsToSign } from '../getFieldsToSign.js';
|
|
@@ -12,6 +13,9 @@ import { incrementLoginAttempts } from '../strategies/local/incrementLoginAttemp
|
|
|
12
13
|
import { resetLoginAttempts } from '../strategies/local/resetLoginAttempts.js';
|
|
13
14
|
export const loginOperation = async (incomingArgs)=>{
|
|
14
15
|
let args = incomingArgs;
|
|
16
|
+
if (args.collection.config.auth.disableLocalStrategy) {
|
|
17
|
+
throw new Forbidden(args.req.t);
|
|
18
|
+
}
|
|
15
19
|
try {
|
|
16
20
|
// /////////////////////////////////////
|
|
17
21
|
// beforeOperation - Collection
|
|
@@ -229,18 +233,6 @@ export const loginOperation = async (incomingArgs)=>{
|
|
|
229
233
|
req
|
|
230
234
|
}) || user;
|
|
231
235
|
}, Promise.resolve());
|
|
232
|
-
// /////////////////////////////////////
|
|
233
|
-
// afterRead - Collection
|
|
234
|
-
// /////////////////////////////////////
|
|
235
|
-
await collectionConfig.hooks.afterRead.reduce(async (priorHook, hook)=>{
|
|
236
|
-
await priorHook;
|
|
237
|
-
user = await hook({
|
|
238
|
-
collection: args.collection?.config,
|
|
239
|
-
context: req.context,
|
|
240
|
-
doc: user,
|
|
241
|
-
req
|
|
242
|
-
}) || user;
|
|
243
|
-
}, Promise.resolve());
|
|
244
236
|
let result = {
|
|
245
237
|
exp,
|
|
246
238
|
token,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/auth/operations/login.ts"],"sourcesContent":["import type {\n AuthOperationsFromCollectionSlug,\n Collection,\n DataFromCollectionSlug,\n} from '../../collections/config/types.js'\nimport type { CollectionSlug } from '../../index.js'\nimport type { PayloadRequest, Where } from '../../types/index.js'\nimport type { User } from '../types.js'\n\nimport { buildAfterOperation } from '../../collections/operations/utils.js'\nimport { AuthenticationError, LockedAuth, ValidationError } from '../../errors/index.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport sanitizeInternalFields from '../../utilities/sanitizeInternalFields.js'\nimport { getFieldsToSign } from '../getFieldsToSign.js'\nimport { getLoginOptions } from '../getLoginOptions.js'\nimport isLocked from '../isLocked.js'\nimport { jwtSign } from '../jwt.js'\nimport { authenticateLocalStrategy } from '../strategies/local/authenticate.js'\nimport { incrementLoginAttempts } from '../strategies/local/incrementLoginAttempts.js'\nimport { resetLoginAttempts } from '../strategies/local/resetLoginAttempts.js'\n\nexport type Result = {\n exp?: number\n token?: string\n user?: User\n}\n\nexport type Arguments<TSlug extends CollectionSlug> = {\n collection: Collection\n data: AuthOperationsFromCollectionSlug<TSlug>['login']\n depth?: number\n overrideAccess?: boolean\n req: PayloadRequest\n showHiddenFields?: boolean\n}\n\nexport const loginOperation = async <TSlug extends CollectionSlug>(\n incomingArgs: Arguments<TSlug>,\n): Promise<{ user: DataFromCollectionSlug<TSlug> } & Result> => {\n let args = incomingArgs\n\n try {\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n await args.collection.config.hooks.beforeOperation.reduce(async (priorHook, hook) => {\n await priorHook\n\n args =\n (await hook({\n args,\n collection: args.collection?.config,\n context: args.req.context,\n operation: 'login',\n req: args.req,\n })) || args\n }, Promise.resolve())\n\n const {\n collection: { config: collectionConfig },\n data,\n depth,\n overrideAccess,\n req,\n req: {\n fallbackLocale,\n locale,\n payload,\n payload: { secret },\n },\n showHiddenFields,\n } = args\n\n // /////////////////////////////////////\n // Login\n // /////////////////////////////////////\n\n let user\n const { email: unsanitizedEmail, password } = data\n const loginWithUsername = collectionConfig.auth.loginWithUsername\n\n const sanitizedEmail =\n typeof unsanitizedEmail === 'string' ? unsanitizedEmail.toLowerCase().trim() : null\n const sanitizedUsername =\n 'username' in data && typeof data?.username === 'string'\n ? data.username.toLowerCase().trim()\n : null\n\n const { canLoginWithEmail, canLoginWithUsername } = getLoginOptions(loginWithUsername)\n\n // cannot login with email, did not provide username\n if (!canLoginWithEmail && !sanitizedUsername) {\n throw new ValidationError({\n collection: collectionConfig.slug,\n errors: [{ message: req.i18n.t('validation:required'), path: 'username' }],\n })\n }\n\n // cannot login with username, did not provide email\n if (!canLoginWithUsername && !sanitizedEmail) {\n throw new ValidationError({\n collection: collectionConfig.slug,\n errors: [{ message: req.i18n.t('validation:required'), path: 'email' }],\n })\n }\n\n // can login with either email or username, did not provide either\n if (!sanitizedUsername && !sanitizedEmail) {\n throw new ValidationError({\n collection: collectionConfig.slug,\n errors: [\n { message: req.i18n.t('validation:required'), path: 'email' },\n { message: req.i18n.t('validation:required'), path: 'username' },\n ],\n })\n }\n\n // did not provide password for login\n if (typeof password !== 'string' || password.trim() === '') {\n throw new ValidationError({\n collection: collectionConfig.slug,\n errors: [{ message: req.i18n.t('validation:required'), path: 'password' }],\n })\n }\n\n let whereConstraint: Where = {}\n const emailConstraint: Where = {\n email: {\n equals: sanitizedEmail,\n },\n }\n const usernameConstraint: Where = {\n username: {\n equals: sanitizedUsername,\n },\n }\n\n if (canLoginWithEmail && canLoginWithUsername && (sanitizedUsername || sanitizedEmail)) {\n if (sanitizedUsername) {\n whereConstraint = {\n or: [\n usernameConstraint,\n {\n email: {\n equals: sanitizedUsername,\n },\n },\n ],\n }\n } else {\n whereConstraint = {\n or: [\n emailConstraint,\n {\n username: {\n equals: sanitizedEmail,\n },\n },\n ],\n }\n }\n } else if (canLoginWithEmail && sanitizedEmail) {\n whereConstraint = emailConstraint\n } else if (canLoginWithUsername && sanitizedUsername) {\n whereConstraint = usernameConstraint\n }\n\n user = await payload.db.findOne<any>({\n collection: collectionConfig.slug,\n req,\n where: whereConstraint,\n })\n\n if (!user || (args.collection.config.auth.verify && user._verified === false)) {\n throw new AuthenticationError(req.t, Boolean(canLoginWithUsername && sanitizedUsername))\n }\n\n user.collection = collectionConfig.slug\n\n if (isLocked(new Date(user.lockUntil).getTime())) {\n throw new LockedAuth(req.t)\n }\n\n const authResult = await authenticateLocalStrategy({ doc: user, password })\n\n user = sanitizeInternalFields(user)\n\n const maxLoginAttemptsEnabled = args.collection.config.auth.maxLoginAttempts > 0\n\n if (!authResult) {\n if (maxLoginAttemptsEnabled) {\n await incrementLoginAttempts({\n collection: collectionConfig,\n doc: user,\n payload: req.payload,\n req,\n })\n }\n\n throw new AuthenticationError(req.t)\n }\n\n if (maxLoginAttemptsEnabled) {\n await resetLoginAttempts({\n collection: collectionConfig,\n doc: user,\n payload: req.payload,\n req,\n })\n }\n\n const fieldsToSign = getFieldsToSign({\n collectionConfig,\n email: sanitizedEmail,\n user,\n })\n\n // /////////////////////////////////////\n // beforeLogin - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.beforeLogin.reduce(async (priorHook, hook) => {\n await priorHook\n\n user =\n (await hook({\n collection: args.collection?.config,\n context: args.req.context,\n req: args.req,\n user,\n })) || user\n }, Promise.resolve())\n\n const { exp, token } = await jwtSign({\n fieldsToSign,\n secret,\n tokenExpiration: collectionConfig.auth.tokenExpiration,\n })\n\n req.user = user\n\n // /////////////////////////////////////\n // afterLogin - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.afterLogin.reduce(async (priorHook, hook) => {\n await priorHook\n\n user =\n (await hook({\n collection: args.collection?.config,\n context: args.req.context,\n req: args.req,\n token,\n user,\n })) || user\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n user = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth,\n doc: user,\n draft: undefined,\n fallbackLocale,\n global: null,\n locale,\n overrideAccess,\n req,\n showHiddenFields,\n })\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.afterRead.reduce(async (priorHook, hook) => {\n await priorHook\n\n user =\n (await hook({\n collection: args.collection?.config,\n context: req.context,\n doc: user,\n req,\n })) || user\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.afterRead.reduce(async (priorHook, hook) => {\n await priorHook\n\n user =\n (await hook({\n collection: args.collection?.config,\n context: req.context,\n doc: user,\n req,\n })) || user\n }, Promise.resolve())\n\n let result: { user: DataFromCollectionSlug<TSlug> } & Result = {\n exp,\n token,\n user,\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: args.collection?.config,\n operation: 'login',\n result,\n })\n\n // /////////////////////////////////////\n // Return results\n // /////////////////////////////////////\n\n return result\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["buildAfterOperation","AuthenticationError","LockedAuth","ValidationError","afterRead","killTransaction","sanitizeInternalFields","getFieldsToSign","getLoginOptions","isLocked","jwtSign","authenticateLocalStrategy","incrementLoginAttempts","resetLoginAttempts","loginOperation","incomingArgs","args","collection","config","hooks","beforeOperation","reduce","priorHook","hook","context","req","operation","Promise","resolve","collectionConfig","data","depth","overrideAccess","fallbackLocale","locale","payload","secret","showHiddenFields","user","email","unsanitizedEmail","password","loginWithUsername","auth","sanitizedEmail","toLowerCase","trim","sanitizedUsername","username","canLoginWithEmail","canLoginWithUsername","slug","errors","message","i18n","t","path","whereConstraint","emailConstraint","equals","usernameConstraint","or","db","findOne","where","verify","_verified","Boolean","Date","lockUntil","getTime","authResult","doc","maxLoginAttemptsEnabled","maxLoginAttempts","fieldsToSign","beforeLogin","exp","token","tokenExpiration","afterLogin","draft","undefined","global","result","error"],"mappings":"AASA,SAASA,mBAAmB,QAAQ,wCAAuC;AAC3E,SAASC,mBAAmB,EAAEC,UAAU,EAAEC,eAAe,QAAQ,wBAAuB;AACxF,SAASC,SAAS,QAAQ,wCAAuC;AACjE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,OAAOC,4BAA4B,4CAA2C;AAC9E,SAASC,eAAe,QAAQ,wBAAuB;AACvD,SAASC,eAAe,QAAQ,wBAAuB;AACvD,OAAOC,cAAc,iBAAgB;AACrC,SAASC,OAA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,CAAC,OAAOC,WAAWC;YAC9D,MAAMD;YAENgB,OACE,AAAC,MAAMf,KAAK;gBACVN,YAAYD,KAAKC,UAAU,EAAEC;gBAC7BM,SAASC,IAAID,OAAO;gBACpBgD,KAAKlC;gBACLb;YACF,MAAOa;QACX,GAAGX,QAAQC,OAAO;QAElB,wCAAwC;QACxC,yBAAyB;QACzB,wCAAwC;QAExC,MAAMC,iBAAiBV,KAAK,CAACf,SAAS,CAACiB,MAAM,CAAC,OAAOC,WAAWC;YAC9D,MAAMD;YAENgB,OACE,AAAC,MAAMf,KAAK;gBACVN,YAAYD,KAAKC,UAAU,EAAEC;gBAC7BM,SAASC,IAAID,OAAO;gBACpBgD,KAAKlC;gBACLb;YACF,MAAOa;QACX,GAAGX,QAAQC,OAAO;QAElB,IAAIwD,SAA2D;YAC7DP;YACAC;YACAxC;QACF;QAEA,wCAAwC;QACxC,8BAA8B;QAC9B,wCAAwC;QAExC8C,SAAS,MAAMpF,oBAAoB;YACjCgB;YACAC,YAAYD,KAAKC,UAAU,EAAEC;YAC7BQ,WAAW;YACX0D;QACF;QAEA,wCAAwC;QACxC,iBAAiB;QACjB,wCAAwC;QAExC,OAAOA;IACT,EAAE,OAAOC,OAAgB;QACvB,MAAMhF,gBAAgBW,KAAKS,GAAG;QAC9B,MAAM4D;IACR;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/auth/operations/login.ts"],"sourcesContent":["import type {\n AuthOperationsFromCollectionSlug,\n Collection,\n DataFromCollectionSlug,\n} from '../../collections/config/types.js'\nimport type { CollectionSlug } from '../../index.js'\nimport type { PayloadRequest, Where } from '../../types/index.js'\nimport type { User } from '../types.js'\n\nimport { buildAfterOperation } from '../../collections/operations/utils.js'\nimport { AuthenticationError, LockedAuth, ValidationError } from '../../errors/index.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { Forbidden } from '../../index.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport sanitizeInternalFields from '../../utilities/sanitizeInternalFields.js'\nimport { getFieldsToSign } from '../getFieldsToSign.js'\nimport { getLoginOptions } from '../getLoginOptions.js'\nimport isLocked from '../isLocked.js'\nimport { jwtSign } from '../jwt.js'\nimport { authenticateLocalStrategy } from '../strategies/local/authenticate.js'\nimport { incrementLoginAttempts } from '../strategies/local/incrementLoginAttempts.js'\nimport { resetLoginAttempts } from '../strategies/local/resetLoginAttempts.js'\n\nexport type Result = {\n exp?: number\n token?: string\n user?: User\n}\n\nexport type Arguments<TSlug extends CollectionSlug> = {\n collection: Collection\n data: AuthOperationsFromCollectionSlug<TSlug>['login']\n depth?: number\n overrideAccess?: boolean\n req: PayloadRequest\n showHiddenFields?: boolean\n}\n\nexport const loginOperation = async <TSlug extends CollectionSlug>(\n incomingArgs: Arguments<TSlug>,\n): Promise<{ user: DataFromCollectionSlug<TSlug> } & Result> => {\n let args = incomingArgs\n\n if (args.collection.config.auth.disableLocalStrategy) {\n throw new Forbidden(args.req.t)\n }\n\n try {\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n await args.collection.config.hooks.beforeOperation.reduce(async (priorHook, hook) => {\n await priorHook\n\n args =\n (await hook({\n args,\n collection: args.collection?.config,\n context: args.req.context,\n operation: 'login',\n req: args.req,\n })) || args\n }, Promise.resolve())\n\n const {\n collection: { config: collectionConfig },\n data,\n depth,\n overrideAccess,\n req,\n req: {\n fallbackLocale,\n locale,\n payload,\n payload: { secret },\n },\n showHiddenFields,\n } = args\n\n // /////////////////////////////////////\n // Login\n // /////////////////////////////////////\n\n let user\n const { email: unsanitizedEmail, password } = data\n const loginWithUsername = collectionConfig.auth.loginWithUsername\n\n const sanitizedEmail =\n typeof unsanitizedEmail === 'string' ? unsanitizedEmail.toLowerCase().trim() : null\n const sanitizedUsername =\n 'username' in data && typeof data?.username === 'string'\n ? data.username.toLowerCase().trim()\n : null\n\n const { canLoginWithEmail, canLoginWithUsername } = getLoginOptions(loginWithUsername)\n\n // cannot login with email, did not provide username\n if (!canLoginWithEmail && !sanitizedUsername) {\n throw new ValidationError({\n collection: collectionConfig.slug,\n errors: [{ message: req.i18n.t('validation:required'), path: 'username' }],\n })\n }\n\n // cannot login with username, did not provide email\n if (!canLoginWithUsername && !sanitizedEmail) {\n throw new ValidationError({\n collection: collectionConfig.slug,\n errors: [{ message: req.i18n.t('validation:required'), path: 'email' }],\n })\n }\n\n // can login with either email or username, did not provide either\n if (!sanitizedUsername && !sanitizedEmail) {\n throw new ValidationError({\n collection: collectionConfig.slug,\n errors: [\n { message: req.i18n.t('validation:required'), path: 'email' },\n { message: req.i18n.t('validation:required'), path: 'username' },\n ],\n })\n }\n\n // did not provide password for login\n if (typeof password !== 'string' || password.trim() === '') {\n throw new ValidationError({\n collection: collectionConfig.slug,\n errors: [{ message: req.i18n.t('validation:required'), path: 'password' }],\n })\n }\n\n let whereConstraint: Where = {}\n const emailConstraint: Where = {\n email: {\n equals: sanitizedEmail,\n },\n }\n const usernameConstraint: Where = {\n username: {\n equals: sanitizedUsername,\n },\n }\n\n if (canLoginWithEmail && canLoginWithUsername && (sanitizedUsername || sanitizedEmail)) {\n if (sanitizedUsername) {\n whereConstraint = {\n or: [\n usernameConstraint,\n {\n email: {\n equals: sanitizedUsername,\n },\n },\n ],\n }\n } else {\n whereConstraint = {\n or: [\n emailConstraint,\n {\n username: {\n equals: sanitizedEmail,\n },\n },\n ],\n }\n }\n } else if (canLoginWithEmail && sanitizedEmail) {\n whereConstraint = emailConstraint\n } else if (canLoginWithUsername && sanitizedUsername) {\n whereConstraint = usernameConstraint\n }\n\n user = await payload.db.findOne<any>({\n collection: collectionConfig.slug,\n req,\n where: whereConstraint,\n })\n\n if (!user || (args.collection.config.auth.verify && user._verified === false)) {\n throw new AuthenticationError(req.t, Boolean(canLoginWithUsername && sanitizedUsername))\n }\n\n user.collection = collectionConfig.slug\n\n if (isLocked(new Date(user.lockUntil).getTime())) {\n throw new LockedAuth(req.t)\n }\n\n const authResult = await authenticateLocalStrategy({ doc: user, password })\n\n user = sanitizeInternalFields(user)\n\n const maxLoginAttemptsEnabled = args.collection.config.auth.maxLoginAttempts > 0\n\n if (!authResult) {\n if (maxLoginAttemptsEnabled) {\n await incrementLoginAttempts({\n collection: collectionConfig,\n doc: user,\n payload: req.payload,\n req,\n })\n }\n\n throw new AuthenticationError(req.t)\n }\n\n if (maxLoginAttemptsEnabled) {\n await resetLoginAttempts({\n collection: collectionConfig,\n doc: user,\n payload: req.payload,\n req,\n })\n }\n\n const fieldsToSign = getFieldsToSign({\n collectionConfig,\n email: sanitizedEmail,\n user,\n })\n\n // /////////////////////////////////////\n // beforeLogin - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.beforeLogin.reduce(async (priorHook, hook) => {\n await priorHook\n\n user =\n (await hook({\n collection: args.collection?.config,\n context: args.req.context,\n req: args.req,\n user,\n })) || user\n }, Promise.resolve())\n\n const { exp, token } = await jwtSign({\n fieldsToSign,\n secret,\n tokenExpiration: collectionConfig.auth.tokenExpiration,\n })\n\n req.user = user\n\n // /////////////////////////////////////\n // afterLogin - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.afterLogin.reduce(async (priorHook, hook) => {\n await priorHook\n\n user =\n (await hook({\n collection: args.collection?.config,\n context: args.req.context,\n req: args.req,\n token,\n user,\n })) || user\n }, Promise.resolve())\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n user = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth,\n doc: user,\n draft: undefined,\n fallbackLocale,\n global: null,\n locale,\n overrideAccess,\n req,\n showHiddenFields,\n })\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n await collectionConfig.hooks.afterRead.reduce(async (priorHook, hook) => {\n await priorHook\n\n user =\n (await hook({\n collection: args.collection?.config,\n context: req.context,\n doc: user,\n req,\n })) || user\n }, Promise.resolve())\n\n let result: { user: DataFromCollectionSlug<TSlug> } & Result = {\n exp,\n token,\n user,\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: args.collection?.config,\n operation: 'login',\n result,\n })\n\n // /////////////////////////////////////\n // Return results\n // /////////////////////////////////////\n\n return result\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["buildAfterOperation","AuthenticationError","LockedAuth","ValidationError","afterRead","Forbidden","killTransaction","sanitizeInternalFields","getFieldsToSign","getLoginOptions","isLocked","jwtSign","authenticateLocalStrategy","incrementLoginAttempts","resetLoginAttempts","loginOperation","incomingArgs","args","collection","config","auth","disableLocalStrategy","req","t","hooks","beforeOperation","reduce","priorHook","hook","context","operation","Promise","resolve","collectionConfig","data","depth","overrideAccess","fallbackLocale","locale","payload","secret","showHiddenFields","user","email","unsanitizedEmail","password","loginWithUsername","sanitizedEmail","toLowerCase","trim","sanitizedUsername","username","canLoginWithEmail","canLoginWithUsername","slug","errors","message","i18n","path","whereConstraint","emailConstraint","equals","usernameConstraint","or","db","findOne","where","verify","_verified","Boolean","Date","lockUntil","getTime","authResult","doc","maxLoginAttemptsEnabled","maxLoginAttempts","fieldsToSign","beforeLogin","exp","token","tokenExpiration","afterLogin","draft","undefined","global","result","error"],"mappings":"AASA,SAASA,mBAAmB,QAAQ,wCAAuC;AAC3E,SAASC,mBAAmB,EAAEC,UAAU,EAAEC,eAAe,QAAQ,wBAAuB;AACxF,SAASC,SAAS,QAAQ,wCAAuC;AACjE,SAASC,SAAS,QAAQ,iBAAgB;AAC1C,SAASC,eAAe,QAAQ,qCAAoC;AACpE,OAAOC,4BAA4B,4CAA2C;AAC9E,SAASC,eAAe,QAAQ,wBAAuB;AACvD,SAASC,eAAe,QAAQ,wBAAuB;AACvD,OAAOC,cAAc,iBAAgB;AACrC,SAASC,OAAO,QAAQ,YAAW;AACnC,SAASC,yBAAyB,QAAQ,sCAAqC;AAC/E,SAASC,sBAAsB,QAAQ,gDAA+C;AACtF,SAASC,kBAAkB,QAAQ,4CAA2C;AAiB9E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OAAOC,WAAWC;YAC9D,MAAMD;YAENe,OACE,AAAC,MAAMd,KAAK;gBACVV,YAAYD,KAAKC,UAAU,EAAEC;gBAC7BU,SAASP,IAAIO,OAAO;gBACpB6C,KAAKhC;gBACLpB;YACF,MAAOoB;QACX,GAAGX,QAAQC,OAAO;QAElB,IAAIsD,SAA2D;YAC7DP;YACAC;YACAtC;QACF;QAEA,wCAAwC;QACxC,8BAA8B;QAC9B,wCAAwC;QAExC4C,SAAS,MAAMtF,oBAAoB;YACjCiB;YACAC,YAAYD,KAAKC,UAAU,EAAEC;YAC7BW,WAAW;YACXwD;QACF;QAEA,wCAAwC;QACxC,iBAAiB;QACjB,wCAAwC;QAExC,OAAOA;IACT,EAAE,OAAOC,OAAgB;QACvB,MAAMjF,gBAAgBW,KAAKK,GAAG;QAC9B,MAAMiE;IACR;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/auth/operations/me.ts"],"sourcesContent":["import { decodeJwt } from 'jose'\n\nimport type { Collection } from '../../collections/config/types.js'\nimport type { PayloadRequest } from '../../types/index.js'\nimport type { ClientUser, User } from '../types.js'\n\nexport type MeOperationResult = {\n collection?: string\n exp?: number\n strategy?: string\n token?: string\n user?: ClientUser\n}\n\nexport type Arguments = {\n collection: Collection\n currentToken?: string\n req: PayloadRequest\n}\n\nexport const meOperation = async (args: Arguments): Promise<MeOperationResult> => {\n const { collection, currentToken, req } = args\n\n let result: MeOperationResult = {\n user: null,\n }\n\n if (req.user) {\n const { pathname } = req\n const isGraphQL = pathname === `/api${req.payload.config.routes.graphQL}`\n\n const user = (await req.payload.findByID({\n id: req.user.id,\n collection: collection.config.slug,\n depth: isGraphQL ? 0 : collection.config.auth.depth,\n overrideAccess: false,\n req,\n showHiddenFields: false,\n })) as User\n\n if (user) {\n user.collection = collection.config.slug\n }\n\n if (req.user.collection !== collection.config.slug) {\n return {\n user: null,\n }\n }\n\n // /////////////////////////////////////\n // me hook - Collection\n // /////////////////////////////////////\n\n for (const meHook of collection.config.hooks.me) {\n const hookResult = await meHook({ args, user })\n\n if (hookResult) {\n result.user = hookResult.user\n result.exp = hookResult.exp\n\n break\n }\n }\n\n result.collection = req.user.collection\n result.strategy = req.user._strategy\n\n if (!result.user) {\n result.user = user\n\n if (currentToken) {\n const decoded = decodeJwt(currentToken)\n if (decoded) {\n result.exp = decoded.exp\n }\n if (!collection.config.auth.removeTokenFromResponses) {\n result.token = currentToken\n }\n }\n }\n }\n\n // /////////////////////////////////////\n // After Me - Collection\n // /////////////////////////////////////\n\n await collection.config.hooks.afterMe.reduce(async (priorHook, hook) => {\n await priorHook\n\n result =\n (await hook({\n collection: collection?.config,\n context: req.context,\n req,\n response: result,\n })) || result\n }, Promise.resolve())\n\n return result\n}\n"],"names":["decodeJwt","meOperation","args","collection","currentToken","req","result","user","pathname","isGraphQL","payload","config","routes","graphQL","findByID","id","slug","depth","auth","overrideAccess","showHiddenFields","meHook","hooks","me","hookResult","exp","strategy","_strategy","decoded","removeTokenFromResponses","token","afterMe","reduce","priorHook","hook","context","response","Promise","resolve"],"mappings":"AAAA,SAASA,SAAS,QAAQ,OAAM;AAoBhC,OAAO,MAAMC,cAAc,OAAOC;IAChC,MAAM,EAAEC,UAAU,EAAEC,YAAY,EAAEC,GAAG,EAAE,GAAGH;IAE1C,IAAII,SAA4B;QAC9BC,MAAM;IACR;IAEA,IAAIF,IAAIE,IAAI,EAAE;QACZ,MAAM,EAAEC,QAAQ,EAAE,GAAGH;QACrB,MAAMI,YAAYD,aAAa,CAAC,IAAI,EAAEH,IAAIK,OAAO,CAACC,MAAM,CAACC,MAAM,CAACC,OAAO,
|
|
1
|
+
{"version":3,"sources":["../../../src/auth/operations/me.ts"],"sourcesContent":["import { decodeJwt } from 'jose'\n\nimport type { Collection } from '../../collections/config/types.js'\nimport type { PayloadRequest } from '../../types/index.js'\nimport type { ClientUser, User } from '../types.js'\n\nexport type MeOperationResult = {\n collection?: string\n exp?: number\n strategy?: string\n token?: string\n user?: ClientUser\n}\n\nexport type Arguments = {\n collection: Collection\n currentToken?: string\n req: PayloadRequest\n}\n\nexport const meOperation = async (args: Arguments): Promise<MeOperationResult> => {\n const { collection, currentToken, req } = args\n\n let result: MeOperationResult = {\n user: null,\n }\n\n if (req.user) {\n const { pathname } = req\n const isGraphQL = pathname === `/api${req.payload.config.routes.graphQL}`\n\n const user = (await req.payload.findByID({\n id: req.user.id,\n collection: collection.config.slug,\n depth: isGraphQL ? 0 : collection.config.auth.depth,\n overrideAccess: false,\n req,\n showHiddenFields: false,\n })) as User\n\n if (user) {\n user.collection = collection.config.slug\n }\n\n if (req.user.collection !== collection.config.slug) {\n return {\n user: null,\n }\n }\n\n // /////////////////////////////////////\n // me hook - Collection\n // /////////////////////////////////////\n\n for (const meHook of collection.config.hooks.me) {\n const hookResult = await meHook({ args, user })\n\n if (hookResult) {\n result.user = hookResult.user\n result.exp = hookResult.exp\n\n break\n }\n }\n\n result.collection = req.user.collection\n result.strategy = req.user._strategy\n\n if (!result.user) {\n result.user = user\n\n if (currentToken) {\n const decoded = decodeJwt(currentToken)\n if (decoded) {\n result.exp = decoded.exp\n }\n if (!collection.config.auth.removeTokenFromResponses) {\n result.token = currentToken\n }\n }\n }\n }\n\n // /////////////////////////////////////\n // After Me - Collection\n // /////////////////////////////////////\n\n await collection.config.hooks.afterMe.reduce(async (priorHook, hook) => {\n await priorHook\n\n result =\n (await hook({\n collection: collection?.config,\n context: req.context,\n req,\n response: result,\n })) || result\n }, Promise.resolve())\n\n return result\n}\n"],"names":["decodeJwt","meOperation","args","collection","currentToken","req","result","user","pathname","isGraphQL","payload","config","routes","graphQL","findByID","id","slug","depth","auth","overrideAccess","showHiddenFields","meHook","hooks","me","hookResult","exp","strategy","_strategy","decoded","removeTokenFromResponses","token","afterMe","reduce","priorHook","hook","context","response","Promise","resolve"],"mappings":"AAAA,SAASA,SAAS,QAAQ,OAAM;AAoBhC,OAAO,MAAMC,cAAc,OAAOC;IAChC,MAAM,EAAE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B,UAAUI;gBAC1B,IAAIwB,SAAS;oBACXtB,OAAOmB,GAAG,GAAGG,QAAQH,GAAG;gBAC1B;gBACA,IAAI,CAACtB,WAAWQ,MAAM,CAACO,IAAI,CAACW,wBAAwB,EAAE;oBACpDvB,OAAOwB,KAAK,GAAG1B;gBACjB;YACF;QACF;IACF;IAEA,wCAAwC;IACxC,wBAAwB;IACxB,wCAAwC;IAExC,MAAMD,WAAWQ,MAAM,CAACW,KAAK,CAACS,OAAO,CAACC,MAAM,CAAC,OAAOC,WAAWC;QAC7D,MAAMD;QAEN3B,SACE,AAAC,MAAM4B,KAAK;YACV/B,YAAYA,YAAYQ;YACxBwB,SAAS9B,IAAI8B,OAAO;YACpB9B;YACA+B,UAAU9B;QACZ,MAAOA;IACX,GAAG+B,QAAQC,OAAO;IAElB,OAAOhC;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerFirstUser.d.ts","sourceRoot":"","sources":["../../../src/auth/operations/registerFirstUser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gCAAgC,EAChC,UAAU,EACV,sBAAsB,EACtB,8BAA8B,EAC/B,MAAM,mCAAmC,CAAA;AAC1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,sBAAsB,CAAA;AAQtE,MAAM,MAAM,SAAS,CAAC,KAAK,SAAS,cAAc,IAAI;IACpD,UAAU,EAAE,UAAU,CAAA;IACtB,IAAI,EAAE,gCAAgC,CAAC,KAAK,CAAC,CAAC,mBAAmB,CAAC,GAChE,8BAA8B,CAAC,KAAK,CAAC,CAAA;IACvC,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,MAAM,CAAC,KAAK,IAAI;IAC1B,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,KAAK,CAAA;CACb,CAAA;AAED,eAAO,MAAM,0BAA0B,GAAU,KAAK,SAAS,cAAc,QACrE,SAAS,CAAC,KAAK,CAAC,KACrB,OAAO,CAAC,MAAM,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"registerFirstUser.d.ts","sourceRoot":"","sources":["../../../src/auth/operations/registerFirstUser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gCAAgC,EAChC,UAAU,EACV,sBAAsB,EACtB,8BAA8B,EAC/B,MAAM,mCAAmC,CAAA;AAC1C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,sBAAsB,CAAA;AAQtE,MAAM,MAAM,SAAS,CAAC,KAAK,SAAS,cAAc,IAAI;IACpD,UAAU,EAAE,UAAU,CAAA;IACtB,IAAI,EAAE,gCAAgC,CAAC,KAAK,CAAC,CAAC,mBAAmB,CAAC,GAChE,8BAA8B,CAAC,KAAK,CAAC,CAAA;IACvC,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,MAAM,CAAC,KAAK,IAAI;IAC1B,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,KAAK,CAAA;CACb,CAAA;AAED,eAAO,MAAM,0BAA0B,GAAU,KAAK,SAAS,cAAc,QACrE,SAAS,CAAC,KAAK,CAAC,KACrB,OAAO,CAAC,MAAM,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC,CAoF/C,CAAA"}
|
|
@@ -5,6 +5,9 @@ import { killTransaction } from '../../utilities/killTransaction.js';
|
|
|
5
5
|
import { ensureUsernameOrEmail } from '../ensureUsernameOrEmail.js';
|
|
6
6
|
export const registerFirstUserOperation = async (args)=>{
|
|
7
7
|
const { collection: { config, config: { slug, auth: { verify } } }, data, req, req: { payload } } = args;
|
|
8
|
+
if (config.auth.disableLocalStrategy) {
|
|
9
|
+
throw new Forbidden(req.t);
|
|
10
|
+
}
|
|
8
11
|
try {
|
|
9
12
|
const shouldCommit = await initTransaction(req);
|
|
10
13
|
ensureUsernameOrEmail({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/auth/operations/registerFirstUser.ts"],"sourcesContent":["import type {\n AuthOperationsFromCollectionSlug,\n Collection,\n DataFromCollectionSlug,\n RequiredDataFromCollectionSlug,\n} from '../../collections/config/types.js'\nimport type { CollectionSlug } from '../../index.js'\nimport type { PayloadRequest, SelectType } from '../../types/index.js'\n\nimport { Forbidden } from '../../errors/index.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { ensureUsernameOrEmail } from '../ensureUsernameOrEmail.js'\n\nexport type Arguments<TSlug extends CollectionSlug> = {\n collection: Collection\n data: AuthOperationsFromCollectionSlug<TSlug>['registerFirstUser'] &\n RequiredDataFromCollectionSlug<TSlug>\n req: PayloadRequest\n}\n\nexport type Result<TData> = {\n exp?: number\n token?: string\n user?: TData\n}\n\nexport const registerFirstUserOperation = async <TSlug extends CollectionSlug>(\n args: Arguments<TSlug>,\n): Promise<Result<DataFromCollectionSlug<TSlug>>> => {\n const {\n collection: {\n config,\n config: {\n slug,\n auth: { verify },\n },\n },\n data,\n req,\n req: { payload },\n } = args\n\n try {\n const shouldCommit = await initTransaction(req)\n\n ensureUsernameOrEmail<TSlug>({\n authOptions: config.auth,\n collectionSlug: slug,\n data,\n operation: 'create',\n req,\n })\n\n const doc = await payload.db.findOne({\n collection: config.slug,\n req,\n })\n\n if (doc) {\n throw new Forbidden(req.t)\n }\n\n // /////////////////////////////////////\n // Register first user\n // /////////////////////////////////////\n\n const result = await payload.create<TSlug, SelectType>({\n collection: slug as TSlug,\n data,\n overrideAccess: true,\n req,\n })\n\n // auto-verify (if applicable)\n if (verify) {\n await payload.update({\n id: result.id,\n collection: slug,\n data: {\n _verified: true,\n },\n req,\n })\n }\n\n // /////////////////////////////////////\n // Log in new user\n // /////////////////////////////////////\n\n const { exp, token } = await payload.login({\n ...args,\n collection: slug,\n req,\n })\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return {\n exp,\n token,\n user: result,\n }\n } catch (error: unknown) {\n await killTransaction(req)\n throw error\n }\n}\n"],"names":["Forbidden","commitTransaction","initTransaction","killTransaction","ensureUsernameOrEmail","registerFirstUserOperation","args","collection","config","slug","auth","verify","data","req","payload","shouldCommit","authOptions","collectionSlug","operation","doc","db","findOne","
|
|
1
|
+
{"version":3,"sources":["../../../src/auth/operations/registerFirstUser.ts"],"sourcesContent":["import type {\n AuthOperationsFromCollectionSlug,\n Collection,\n DataFromCollectionSlug,\n RequiredDataFromCollectionSlug,\n} from '../../collections/config/types.js'\nimport type { CollectionSlug } from '../../index.js'\nimport type { PayloadRequest, SelectType } from '../../types/index.js'\n\nimport { Forbidden } from '../../errors/index.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { ensureUsernameOrEmail } from '../ensureUsernameOrEmail.js'\n\nexport type Arguments<TSlug extends CollectionSlug> = {\n collection: Collection\n data: AuthOperationsFromCollectionSlug<TSlug>['registerFirstUser'] &\n RequiredDataFromCollectionSlug<TSlug>\n req: PayloadRequest\n}\n\nexport type Result<TData> = {\n exp?: number\n token?: string\n user?: TData\n}\n\nexport const registerFirstUserOperation = async <TSlug extends CollectionSlug>(\n args: Arguments<TSlug>,\n): Promise<Result<DataFromCollectionSlug<TSlug>>> => {\n const {\n collection: {\n config,\n config: {\n slug,\n auth: { verify },\n },\n },\n data,\n req,\n req: { payload },\n } = args\n\n if (config.auth.disableLocalStrategy) {\n throw new Forbidden(req.t)\n }\n\n try {\n const shouldCommit = await initTransaction(req)\n\n ensureUsernameOrEmail<TSlug>({\n authOptions: config.auth,\n collectionSlug: slug,\n data,\n operation: 'create',\n req,\n })\n\n const doc = await payload.db.findOne({\n collection: config.slug,\n req,\n })\n\n if (doc) {\n throw new Forbidden(req.t)\n }\n\n // /////////////////////////////////////\n // Register first user\n // /////////////////////////////////////\n\n const result = await payload.create<TSlug, SelectType>({\n collection: slug as TSlug,\n data,\n overrideAccess: true,\n req,\n })\n\n // auto-verify (if applicable)\n if (verify) {\n await payload.update({\n id: result.id,\n collection: slug,\n data: {\n _verified: true,\n },\n req,\n })\n }\n\n // /////////////////////////////////////\n // Log in new user\n // /////////////////////////////////////\n\n const { exp, token } = await payload.login({\n ...args,\n collection: slug,\n req,\n })\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return {\n exp,\n token,\n user: result,\n }\n } catch (error: unknown) {\n await killTransaction(req)\n throw error\n }\n}\n"],"names":["Forbidden","commitTransaction","initTransaction","killTransaction","ensureUsernameOrEmail","registerFirstUserOperation","args","collection","config","slug","auth","verify","data","req","payload","disableLocalStrategy","t","shouldCommit","authOptions","collectionSlug","operation","doc","db","findOne","result","create","overrideAccess","update","id","_verified","exp","token","login","user","error"],"mappings":"AASA,SAASA,SAAS,QAAQ,wBAAuB;AACjD,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,qBAAqB,QAAQ,8BAA6B;AAenE,OAAO,MAAMC,6BAA6B,OACxCC;IAEA,MAAM,EACJC,YAAY,EACVC,MAAM,EACNA,QAAQ,EACNC,IAAI,EACJC,MAAM,EAAEC,MAAM,EAAE,EACjB,EACF,EACDC,IAAI,EACJC,GAAG,EACHA,KAAK,EAAEC,OAAO,EAAE,EACjB,GAAGR;IAEJ,IAAIE,OAAOE,IAAI,CAACK,oBAAoB,EAAE;QACpC,MAAM,IAAIf,UAAUa,IAAIG,CAAC;IAC3B;IAEA,IAAI;QACF,MAAMC,eAAe,MAAMf,gBAAgBW;QAE3CT,sBAA6B;YAC3Bc,aAAaV,OAAOE,IAAI;YACxBS,gBAAgBV;YAChBG;YACAQ,WAAW;YACXP;QACF;QAEA,MAAMQ,MAAM,MAAMP,QAAQQ,EAAE,CAACC,OAAO,CAAC;YACnChB,YAAYC,OAAOC,IAAI;YACvBI;QACF;QAEA,IAAIQ,KAAK;YACP,MAAM,IAAIrB,UAAUa,IAAIG,CAAC;QAC3B;QAEA,wCAAwC;QACxC,sBAAsB;QACtB,wCAAwC;QAExC,MAAMQ,SAAS,MAAMV,QAAQW,MAAM,CAAoB;YACrDlB,YAAYE;YACZG;YACAc,gBAAgB;YAChBb;QACF;QAEA,8BAA8B;QAC9B,IAAIF,QAAQ;YACV,MAAMG,QAAQa,MAAM,CAAC;gBACnBC,IAAIJ,OAAOI,EAAE;gBACbrB,YAAYE;gBACZG,MAAM;oBACJiB,WAAW;gBACb;gBACAhB;YACF;QACF;QAEA,wCAAwC;QACxC,kBAAkB;QAClB,wCAAwC;QAExC,MAAM,EAAEiB,GAAG,EAAEC,KAAK,EAAE,GAAG,MAAMjB,QAAQkB,KAAK,CAAC;YACzC,GAAG1B,IAAI;YACPC,YAAYE;YACZI;QACF;QAEA,IAAII,cAAc;YAChB,MAAMhB,kBAAkBY;QAC1B;QAEA,OAAO;YACLiB;YACAC;YACAE,MAAMT;QACR;IACF,EAAE,OAAOU,OAAgB;QACvB,MAAM/B,gBAAgBU;QACtB,MAAMqB;IACR;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resetPassword.d.ts","sourceRoot":"","sources":["../../../src/auth/operations/resetPassword.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAA;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAW1D,MAAM,MAAM,MAAM,GAAG;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,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