payload 3.55.0-internal.ce8fe55 → 3.55.0-internal.df60e35
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/fields/Row.d.ts +4 -2
- package/dist/admin/fields/Row.d.ts.map +1 -1
- package/dist/admin/fields/Row.js.map +1 -1
- package/dist/admin/forms/Field.d.ts +0 -7
- package/dist/admin/forms/Field.d.ts.map +1 -1
- package/dist/admin/forms/Field.js.map +1 -1
- package/dist/admin/functions/index.d.ts +0 -25
- package/dist/admin/functions/index.d.ts.map +1 -1
- package/dist/admin/functions/index.js.map +1 -1
- package/dist/auth/operations/resetPassword.d.ts.map +1 -1
- package/dist/auth/operations/resetPassword.js +12 -1
- package/dist/auth/operations/resetPassword.js.map +1 -1
- package/dist/collections/endpoints/findByID.d.ts.map +1 -1
- package/dist/collections/endpoints/findByID.js +5 -4
- package/dist/collections/endpoints/findByID.js.map +1 -1
- package/dist/collections/operations/create.d.ts.map +1 -1
- package/dist/collections/operations/create.js +1 -0
- package/dist/collections/operations/create.js.map +1 -1
- package/dist/collections/operations/findByID.d.ts +5 -0
- package/dist/collections/operations/findByID.d.ts.map +1 -1
- package/dist/collections/operations/findByID.js +1 -1
- package/dist/collections/operations/findByID.js.map +1 -1
- package/dist/collections/operations/local/findByID.d.ts +5 -0
- package/dist/collections/operations/local/findByID.d.ts.map +1 -1
- package/dist/collections/operations/local/findByID.js +2 -1
- package/dist/collections/operations/local/findByID.js.map +1 -1
- package/dist/collections/operations/utilities/update.d.ts.map +1 -1
- package/dist/collections/operations/utilities/update.js +1 -0
- package/dist/collections/operations/utilities/update.js.map +1 -1
- package/dist/config/client.d.ts.map +1 -1
- package/dist/config/client.js +8 -0
- package/dist/config/client.js.map +1 -1
- package/dist/config/defaults.d.ts.map +1 -1
- package/dist/config/defaults.js +2 -0
- package/dist/config/defaults.js.map +1 -1
- package/dist/config/types.d.ts +14 -0
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js.map +1 -1
- package/dist/database/types.d.ts +2 -0
- package/dist/database/types.d.ts.map +1 -1
- package/dist/database/types.js.map +1 -1
- package/dist/exports/shared.d.ts +0 -1
- package/dist/exports/shared.d.ts.map +1 -1
- package/dist/exports/shared.js +0 -1
- package/dist/exports/shared.js.map +1 -1
- package/dist/folders/types.d.ts +2 -2
- package/dist/folders/types.d.ts.map +1 -1
- package/dist/folders/types.js.map +1 -1
- package/dist/globals/operations/update.d.ts.map +1 -1
- package/dist/globals/operations/update.js +1 -0
- package/dist/globals/operations/update.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/utilities/handleEndpoints.d.ts.map +1 -1
- package/dist/utilities/handleEndpoints.js +30 -10
- package/dist/utilities/handleEndpoints.js.map +1 -1
- package/dist/versions/baseFields.d.ts +2 -0
- package/dist/versions/baseFields.d.ts.map +1 -1
- package/dist/versions/baseFields.js +23 -0
- package/dist/versions/baseFields.js.map +1 -1
- package/dist/versions/buildCollectionFields.d.ts.map +1 -1
- package/dist/versions/buildCollectionFields.js +16 -1
- package/dist/versions/buildCollectionFields.js.map +1 -1
- package/dist/versions/buildGlobalFields.d.ts.map +1 -1
- package/dist/versions/buildGlobalFields.js +16 -1
- package/dist/versions/buildGlobalFields.js.map +1 -1
- package/dist/versions/drafts/replaceWithDraftIfAvailable.d.ts.map +1 -1
- package/dist/versions/drafts/replaceWithDraftIfAvailable.js +6 -0
- package/dist/versions/drafts/replaceWithDraftIfAvailable.js.map +1 -1
- package/dist/versions/saveVersion.d.ts +2 -1
- package/dist/versions/saveVersion.d.ts.map +1 -1
- package/dist/versions/saveVersion.js +64 -31
- package/dist/versions/saveVersion.js.map +1 -1
- package/dist/versions/types.d.ts +1 -0
- package/dist/versions/types.d.ts.map +1 -1
- package/dist/versions/types.js.map +1 -1
- package/package.json +2 -2
- package/dist/utilities/fieldSchemaToJSON.d.ts +0 -14
- package/dist/utilities/fieldSchemaToJSON.d.ts.map +0 -1
- package/dist/utilities/fieldSchemaToJSON.js +0 -91
- package/dist/utilities/fieldSchemaToJSON.js.map +0 -1
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { MarkOptional } from 'ts-essentials';
|
|
2
2
|
import type { RowField, RowFieldClient } from '../../fields/config/types.js';
|
|
3
|
-
import type {
|
|
3
|
+
import type { ClientFieldBase, FieldClientComponent, FieldPaths, FieldServerComponent, ServerFieldBase } from '../forms/Field.js';
|
|
4
4
|
import type { FieldDescriptionClientComponent, FieldDescriptionServerComponent, FieldDiffClientComponent, FieldDiffServerComponent, FieldErrorClientComponent, FieldErrorServerComponent, FieldLabelClientComponent, FieldLabelServerComponent } from '../types.js';
|
|
5
5
|
type RowFieldClientWithoutType = MarkOptional<RowFieldClient, 'type'>;
|
|
6
|
-
type RowFieldBaseClientProps =
|
|
6
|
+
type RowFieldBaseClientProps = {
|
|
7
|
+
readonly forceRender?: boolean;
|
|
8
|
+
} & Omit<FieldPaths, 'path'>;
|
|
7
9
|
export type RowFieldClientProps = Omit<ClientFieldBase<RowFieldClientWithoutType>, 'path'> & RowFieldBaseClientProps;
|
|
8
10
|
export type RowFieldServerProps = ServerFieldBase<RowField, RowFieldClientWithoutType>;
|
|
9
11
|
export type RowFieldServerComponent = FieldServerComponent<RowField, RowFieldClientWithoutType>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Row.d.ts","sourceRoot":"","sources":["../../../src/admin/fields/Row.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAEjD,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAC5E,OAAO,KAAK,EACV,
|
|
1
|
+
{"version":3,"file":"Row.d.ts","sourceRoot":"","sources":["../../../src/admin/fields/Row.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AA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CAClE,QAAQ,EACR,yBAAyB,CAC1B,CAAA;AAED,MAAM,MAAM,4BAA4B,GAAG,yBAAyB,CAAC,yBAAyB,CAAC,CAAA;AAE/F,MAAM,MAAM,2BAA2B,GAAG,wBAAwB,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAA;AAE5F,MAAM,MAAM,2BAA2B,GAAG,wBAAwB,CAAC,cAAc,CAAC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/admin/fields/Row.ts"],"sourcesContent":["import type { MarkOptional } from 'ts-essentials'\n\nimport type { RowField, RowFieldClient } from '../../fields/config/types.js'\nimport type {\n
|
|
1
|
+
{"version":3,"sources":["../../../src/admin/fields/Row.ts"],"sourcesContent":["import type { MarkOptional } from 'ts-essentials'\n\nimport type { RowField, RowFieldClient } from '../../fields/config/types.js'\nimport type {\n ClientFieldBase,\n FieldClientComponent,\n FieldPaths,\n FieldServerComponent,\n ServerFieldBase,\n} from '../forms/Field.js'\nimport type {\n FieldDescriptionClientComponent,\n FieldDescriptionServerComponent,\n FieldDiffClientComponent,\n FieldDiffServerComponent,\n FieldErrorClientComponent,\n FieldErrorServerComponent,\n FieldLabelClientComponent,\n FieldLabelServerComponent,\n} from '../types.js'\n\ntype RowFieldClientWithoutType = MarkOptional<RowFieldClient, 'type'>\n\ntype RowFieldBaseClientProps = {\n readonly forceRender?: boolean\n} & Omit<FieldPaths, 'path'>\n\nexport type RowFieldClientProps = Omit<ClientFieldBase<RowFieldClientWithoutType>, 'path'> &\n RowFieldBaseClientProps\n\nexport type RowFieldServerProps = ServerFieldBase<RowField, RowFieldClientWithoutType>\n\nexport type RowFieldServerComponent = FieldServerComponent<RowField, RowFieldClientWithoutType>\n\nexport type RowFieldClientComponent = FieldClientComponent<\n RowFieldClientWithoutType,\n RowFieldBaseClientProps\n>\n\nexport type RowFieldLabelServerComponent = FieldLabelServerComponent<\n RowField,\n RowFieldClientWithoutType\n>\n\nexport type RowFieldLabelClientComponent = FieldLabelClientComponent<RowFieldClientWithoutType>\n\nexport type RowFieldDescriptionServerComponent = FieldDescriptionServerComponent<\n RowField,\n RowFieldClientWithoutType\n>\n\nexport type RowFieldDescriptionClientComponent =\n FieldDescriptionClientComponent<RowFieldClientWithoutType>\n\nexport type RowFieldErrorServerComponent = FieldErrorServerComponent<\n RowField,\n RowFieldClientWithoutType\n>\n\nexport type RowFieldErrorClientComponent = FieldErrorClientComponent<RowFieldClientWithoutType>\n\nexport type RowFieldDiffServerComponent = FieldDiffServerComponent<RowField, RowFieldClient>\n\nexport type RowFieldDiffClientComponent = FieldDiffClientComponent<RowFieldClient>\n"],"names":[],"mappings":"AA+DA,WAAkF"}
|
|
@@ -10,13 +10,6 @@ export type ClientFieldWithOptionalType = MarkOptional<ClientField, 'type'>;
|
|
|
10
10
|
export type ClientComponentProps = {
|
|
11
11
|
customComponents?: FormField['customComponents'];
|
|
12
12
|
field: ClientBlock | ClientField | ClientTab;
|
|
13
|
-
/**
|
|
14
|
-
* Controls the rendering behavior of the fields, i.e. defers rendering until they intersect with the viewport using the Intersection Observer API.
|
|
15
|
-
*
|
|
16
|
-
* If true, the fields will be rendered immediately, rather than waiting for them to intersect with the viewport.
|
|
17
|
-
*
|
|
18
|
-
* If a number is provided, will immediately render fields _up to that index_.
|
|
19
|
-
*/
|
|
20
13
|
forceRender?: boolean;
|
|
21
14
|
permissions?: SanitizedFieldPermissions;
|
|
22
15
|
readOnly?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Field.d.ts","sourceRoot":"","sources":["../../../src/admin/forms/Field.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAEjD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAA;AACpE,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,KAAK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{ MarkOptional } from 'ts-essentials'\n\nimport type { SanitizedFieldPermissions } from '../../auth/types.js'\nimport type { ClientBlock, ClientField, Field } from '../../fields/config/types.js'\nimport type { TypedUser } from '../../index.js'\nimport type { DocumentPreferences } from '../../preferences/types.js'\nimport type { Operation, Payload, PayloadRequest } from '../../types/index.js'\nimport type {\n ClientFieldSchemaMap,\n ClientTab,\n Data,\n FieldSchemaMap,\n FormField,\n FormState,\n RenderedField,\n} from '../types.js'\n\nexport type ClientFieldWithOptionalType = MarkOptional<ClientField, 'type'>\n\nexport type ClientComponentProps = {\n customComponents?: FormField['customComponents']\n field: ClientBlock | ClientField | ClientTab\n
|
|
1
|
+
{"version":3,"sources":["../../../src/admin/forms/Field.ts"],"sourcesContent":["import type { I18nClient } from '@payloadcms/translations'\nimport type { MarkOptional } from 'ts-essentials'\n\nimport type { SanitizedFieldPermissions } from '../../auth/types.js'\nimport type { ClientBlock, ClientField, Field } from '../../fields/config/types.js'\nimport type { TypedUser } from '../../index.js'\nimport type { DocumentPreferences } from '../../preferences/types.js'\nimport type { Operation, Payload, PayloadRequest } from '../../types/index.js'\nimport type {\n ClientFieldSchemaMap,\n ClientTab,\n Data,\n FieldSchemaMap,\n FormField,\n FormState,\n RenderedField,\n} from '../types.js'\n\nexport type ClientFieldWithOptionalType = MarkOptional<ClientField, 'type'>\n\nexport type ClientComponentProps = {\n customComponents?: FormField['customComponents']\n field: ClientBlock | ClientField | ClientTab\n forceRender?: boolean\n permissions?: SanitizedFieldPermissions\n readOnly?: boolean\n renderedBlocks?: RenderedField[]\n /**\n * Used to extract field configs from a schemaMap.\n * Does not include indexes.\n *\n * @default field.name\n **/\n schemaPath?: string\n}\n\n// TODO: maybe we can come up with a better name?\nexport type FieldPaths = {\n /**\n * @default ''\n */\n indexPath?: string\n /**\n * @default ''\n */\n parentPath?: string\n /**\n * The path built up to the point of the field\n * excluding the field name.\n *\n * @default ''\n */\n parentSchemaPath?: string\n /**\n * A built up path to access FieldState in the form state.\n * Nested fields will have a path that includes the parent field names\n * if they are nested within a group, array, block or named tab.\n *\n * Collapsibles and unnamed tabs will have arbitrary paths\n * that look like _index-0, _index-1, etc.\n *\n * Row fields will not have a path.\n *\n * @example 'parentGroupField.childTextField'\n *\n * @default field.name\n */\n path: string\n}\n\n/**\n * TODO: This should be renamed to `FieldComponentServerProps` or similar\n */\nexport type ServerComponentProps = {\n clientField: ClientFieldWithOptionalType\n clientFieldSchemaMap: ClientFieldSchemaMap\n collectionSlug: string\n data: Data\n field: Field\n /**\n * The fieldSchemaMap that is created before form state is built is made available here.\n */\n fieldSchemaMap: FieldSchemaMap\n /**\n * Server Components will also have available to the entire form state.\n * We cannot add it to ClientComponentProps as that would blow up the size of the props sent to the client.\n */\n formState: FormState\n i18n: I18nClient\n id?: number | string\n operation: Operation\n payload: Payload\n permissions: SanitizedFieldPermissions\n preferences: DocumentPreferences\n req: PayloadRequest\n siblingData: Data\n user: TypedUser\n value?: unknown\n}\n\nexport type ClientFieldBase<\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = {\n readonly field: TFieldClient\n} & Omit<ClientComponentProps, 'customComponents' | 'field'>\n\nexport type ServerFieldBase<\n TFieldServer extends Field = Field,\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n> = {\n readonly clientField: TFieldClient\n readonly field: TFieldServer\n} & Omit<ClientComponentProps, 'field'> &\n Omit<ServerComponentProps, 'clientField' | 'field'>\n\nexport type FieldClientComponent<\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n AdditionalProps extends Record<string, unknown> = Record<string, unknown>,\n> = React.ComponentType<AdditionalProps & ClientFieldBase<TFieldClient>>\n\nexport type FieldServerComponent<\n TFieldServer extends Field = Field,\n TFieldClient extends ClientFieldWithOptionalType = ClientFieldWithOptionalType,\n AdditionalProps extends Record<string, unknown> = Record<string, unknown>,\n> = React.ComponentType<AdditionalProps & ServerFieldBase<TFieldServer, TFieldClient>>\n"],"names":[],"mappings":"AAwHA,WAIsF"}
|
|
@@ -25,31 +25,6 @@ export type ServerFunctionConfig = {
|
|
|
25
25
|
export type ServerFunctionHandler = (args: {
|
|
26
26
|
config: Promise<SanitizedConfig> | SanitizedConfig;
|
|
27
27
|
importMap: ImportMap;
|
|
28
|
-
/**
|
|
29
|
-
* A map of server function names to their implementations. These are
|
|
30
|
-
* registered alongside the base server functions and can be called
|
|
31
|
-
* using the useServerFunctions() hook.
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* const { serverFunction } = useServerFunctions()
|
|
35
|
-
*
|
|
36
|
-
* const callServerFunction = useCallback(() => {
|
|
37
|
-
*
|
|
38
|
-
* async function call() {
|
|
39
|
-
* const result = (await serverFunction({
|
|
40
|
-
* name: 'record-key',
|
|
41
|
-
* args: {
|
|
42
|
-
* // Your args
|
|
43
|
-
* },
|
|
44
|
-
* }))
|
|
45
|
-
*
|
|
46
|
-
* // Do someting with the result
|
|
47
|
-
* }
|
|
48
|
-
*
|
|
49
|
-
* void call()
|
|
50
|
-
* }, [serverFunction])
|
|
51
|
-
*/
|
|
52
|
-
serverFunctions?: Record<string, ServerFunction<any, any>>;
|
|
53
28
|
} & ServerFunctionClientArgs) => Promise<unknown>;
|
|
54
29
|
export type ListQuery = {
|
|
55
30
|
columns?: ColumnsFromURL;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/admin/functions/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAA;AACrE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACtF,OAAO,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,KAAK,EAA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ACvB;;;;;;OAMG;IACH,oBAAoB,EAAE,cAAc,EAAE,CAAA;IACtC;;OAEG;IACH,SAAS,EAAE,MAAM,GAAG,MAAM,CAAA;IAC1B;;;;OAIG;IACH,yBAAyB,EAAE,cAAc,EAAE,CAAA;IAC3C;;OAEG;IACH,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IACrC,GAAG,EAAE,cAAc,CAAA;IACnB;;OAEG;IACH,IAAI,EAAE,cAAc,CAAA;CACrB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/admin/functions/index.ts"],"sourcesContent":["import type { ImportMap } from '../../bin/generateImportMap/index.js'\nimport type { SanitizedConfig } from '../../config/types.js'\nimport type { PaginatedDocs } from '../../database/types.js'\nimport type { CollectionSlug, ColumnPreference, FolderSortKeys } from '../../index.js'\nimport type { PayloadRequest, Sort, Where } from '../../types/index.js'\nimport type { ColumnsFromURL } from '../../utilities/transformColumnPreferences.js'\n\nexport type DefaultServerFunctionArgs = {\n importMap: ImportMap\n req: PayloadRequest\n}\n\nexport type ServerFunctionArgs = {\n args: Record<string, unknown>\n name: string\n}\n\nexport type ServerFunctionClientArgs = {\n args: Record<string, unknown>\n name: string\n}\n\nexport type ServerFunctionClient = (args: ServerFunctionClientArgs) => Promise<unknown> | unknown\n\nexport type ServerFunction<\n TArgs extends object = Record<string, unknown>,\n TReturnType = Promise<unknown> | unknown,\n> = (args: DefaultServerFunctionArgs & TArgs) => TReturnType\n\nexport type ServerFunctionConfig = {\n fn: ServerFunction\n name: string\n}\n\nexport type ServerFunctionHandler = (\n args: {\n config: Promise<SanitizedConfig> | SanitizedConfig\n importMap: ImportMap\n
|
|
1
|
+
{"version":3,"sources":["../../../src/admin/functions/index.ts"],"sourcesContent":["import type { ImportMap } from '../../bin/generateImportMap/index.js'\nimport type { SanitizedConfig } from '../../config/types.js'\nimport type { PaginatedDocs } from '../../database/types.js'\nimport type { CollectionSlug, ColumnPreference, FolderSortKeys } from '../../index.js'\nimport type { PayloadRequest, Sort, Where } from '../../types/index.js'\nimport type { ColumnsFromURL } from '../../utilities/transformColumnPreferences.js'\n\nexport type DefaultServerFunctionArgs = {\n importMap: ImportMap\n req: PayloadRequest\n}\n\nexport type ServerFunctionArgs = {\n args: Record<string, unknown>\n name: string\n}\n\nexport type ServerFunctionClientArgs = {\n args: Record<string, unknown>\n name: string\n}\n\nexport type ServerFunctionClient = (args: ServerFunctionClientArgs) => Promise<unknown> | unknown\n\nexport type ServerFunction<\n TArgs extends object = Record<string, unknown>,\n TReturnType = Promise<unknown> | unknown,\n> = (args: DefaultServerFunctionArgs & TArgs) => TReturnType\n\nexport type ServerFunctionConfig = {\n fn: ServerFunction\n name: string\n}\n\nexport type ServerFunctionHandler = (\n args: {\n config: Promise<SanitizedConfig> | SanitizedConfig\n importMap: ImportMap\n } & ServerFunctionClientArgs,\n) => Promise<unknown>\n\nexport type ListQuery = {\n /*\n * This is an of strings, i.e. `['title', '-slug']`\n * Use `transformColumnsToPreferences` and `transformColumnsToSearchParams` to convert it back and forth\n */\n columns?: ColumnsFromURL\n /*\n * A string representing the field to group by, e.g. `category`\n * A leading hyphen represents descending order, e.g. `-category`\n */\n groupBy?: string\n limit?: number\n page?: number\n preset?: number | string\n queryByGroup?: Record<string, ListQuery>\n /*\n When provided, is automatically injected into the `where` object\n */\n search?: string\n sort?: Sort\n where?: Where\n} & Record<string, unknown>\n\nexport type BuildTableStateArgs = {\n collectionSlug: string | string[]\n columns?: ColumnPreference[]\n data?: PaginatedDocs\n /**\n * @deprecated Use `data` instead\n */\n docs?: PaginatedDocs['docs']\n enableRowSelections?: boolean\n orderableFieldName: string\n parent?: {\n collectionSlug: CollectionSlug\n id: number | string\n joinPath: string\n }\n query?: ListQuery\n renderRowTypes?: boolean\n req: PayloadRequest\n tableAppearance?: 'condensed' | 'default'\n}\n\nexport type BuildCollectionFolderViewResult = {\n View: React.ReactNode\n}\n\nexport type GetFolderResultsComponentAndDataArgs = {\n /**\n * If true and no folderID is provided, only folders will be returned.\n * If false, the results will include documents from the active collections.\n */\n browseByFolder: boolean\n /**\n * Used to filter document types to include in the results/display.\n *\n * i.e. ['folders', 'posts'] will only include folders and posts in the results.\n *\n * collectionsToQuery?\n */\n collectionsToDisplay: CollectionSlug[]\n /**\n * Used to determine how the results should be displayed.\n */\n displayAs: 'grid' | 'list'\n /**\n * Used to filter folders by the collections they are assigned to.\n *\n * i.e. ['posts'] will only include folders that are assigned to the posts collections.\n */\n folderAssignedCollections: CollectionSlug[]\n /**\n * The ID of the folder to filter results by.\n */\n folderID: number | string | undefined\n req: PayloadRequest\n /**\n * The sort order for the results.\n */\n sort: FolderSortKeys\n}\n"],"names":[],"mappings":"AAyFA,WAiCC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resetPassword.d.ts","sourceRoot":"","sources":["../../../src/auth/operations/resetPassword.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAA0B,MAAM,mCAAmC,CAAA;AAC3F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;
|
|
1
|
+
{"version":3,"file":"resetPassword.d.ts","sourceRoot":"","sources":["../../../src/auth/operations/resetPassword.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAA0B,MAAM,mCAAmC,CAAA;AAC3F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAc1D,MAAM,MAAM,MAAM,GAAG;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC9B,CAAA;AAED,MAAM,MAAM,SAAS,GAAG;IACtB,UAAU,EAAE,UAAU,CAAA;IACtB,IAAI,EAAE;QACJ,QAAQ,EAAE,MAAM,CAAA;QAChB,KAAK,EAAE,MAAM,CAAA;KACd,CAAA;IACD,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,GAAG,EAAE,cAAc,CAAA;CACpB,CAAA;AAED,eAAO,MAAM,sBAAsB,GAAU,KAAK,SAAS,cAAc,QACjE,SAAS,KACd,OAAO,CAAC,MAAM,CA8KhB,CAAA"}
|
|
@@ -7,6 +7,7 @@ import { initTransaction } from '../../utilities/initTransaction.js';
|
|
|
7
7
|
import { killTransaction } from '../../utilities/killTransaction.js';
|
|
8
8
|
import { getFieldsToSign } from '../getFieldsToSign.js';
|
|
9
9
|
import { jwtSign } from '../jwt.js';
|
|
10
|
+
import { addSessionToUser } from '../sessions.js';
|
|
10
11
|
import { authenticateLocalStrategy } from '../strategies/local/authenticate.js';
|
|
11
12
|
import { generatePasswordSaltHash } from '../strategies/local/generatePasswordSaltHash.js';
|
|
12
13
|
export const resetPasswordOperation = async (args)=>{
|
|
@@ -94,11 +95,21 @@ export const resetPasswordOperation = async (args)=>{
|
|
|
94
95
|
doc,
|
|
95
96
|
password: data.password
|
|
96
97
|
});
|
|
97
|
-
const
|
|
98
|
+
const fieldsToSignArgs = {
|
|
98
99
|
collectionConfig,
|
|
99
100
|
email: user.email,
|
|
100
101
|
user
|
|
102
|
+
};
|
|
103
|
+
const { sid } = await addSessionToUser({
|
|
104
|
+
collectionConfig,
|
|
105
|
+
payload,
|
|
106
|
+
req,
|
|
107
|
+
user
|
|
101
108
|
});
|
|
109
|
+
if (sid) {
|
|
110
|
+
fieldsToSignArgs.sid = sid;
|
|
111
|
+
}
|
|
112
|
+
const fieldsToSign = getFieldsToSign(fieldsToSignArgs);
|
|
102
113
|
const { token } = await jwtSign({
|
|
103
114
|
fieldsToSign,
|
|
104
115
|
secret,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/auth/operations/resetPassword.ts"],"sourcesContent":["import { status as httpStatus } from 'http-status'\n\nimport type { Collection, DataFromCollectionSlug } from '../../collections/config/types.js'\nimport type { CollectionSlug } from '../../index.js'\nimport type { PayloadRequest } from '../../types/index.js'\n\nimport { buildAfterOperation } from '../../collections/operations/utils.js'\nimport { APIError, Forbidden } from '../../errors/index.js'\nimport { appendNonTrashedFilter } from '../../utilities/appendNonTrashedFilter.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { getFieldsToSign } from '../getFieldsToSign.js'\nimport { jwtSign } from '../jwt.js'\nimport { authenticateLocalStrategy } from '../strategies/local/authenticate.js'\nimport { generatePasswordSaltHash } from '../strategies/local/generatePasswordSaltHash.js'\n\nexport type Result = {\n token?: string\n user: Record<string, unknown>\n}\n\nexport type Arguments = {\n collection: Collection\n data: {\n password: string\n token: string\n }\n depth?: number\n overrideAccess?: boolean\n req: PayloadRequest\n}\n\nexport const resetPasswordOperation = async <TSlug extends CollectionSlug>(\n args: Arguments,\n): Promise<Result> => {\n const {\n collection: { config: collectionConfig },\n data,\n depth,\n overrideAccess,\n req: {\n payload: { secret },\n payload,\n },\n req,\n } = args\n\n if (\n !Object.prototype.hasOwnProperty.call(data, 'token') ||\n !Object.prototype.hasOwnProperty.call(data, 'password')\n ) {\n throw new APIError('Missing required data.', httpStatus.BAD_REQUEST)\n }\n\n if (collectionConfig.auth.disableLocalStrategy) {\n throw new Forbidden(req.t)\n }\n\n try {\n const shouldCommit = await initTransaction(req)\n\n if (args.collection.config.hooks?.beforeOperation?.length) {\n for (const hook of args.collection.config.hooks.beforeOperation) {\n args =\n (await hook({\n args,\n collection: args.collection?.config,\n context: args.req.context,\n operation: 'resetPassword',\n req: args.req,\n })) || args\n }\n }\n\n // /////////////////////////////////////\n // Reset Password\n // /////////////////////////////////////\n\n const where = appendNonTrashedFilter({\n enableTrash: Boolean(collectionConfig.trash),\n trash: false,\n where: {\n resetPasswordExpiration: { greater_than: new Date().toISOString() },\n resetPasswordToken: { equals: data.token },\n },\n })\n\n const user = await payload.db.findOne<any>({\n collection: collectionConfig.slug,\n req,\n where,\n })\n\n if (!user) {\n throw new APIError('Token is either invalid or has expired.', httpStatus.FORBIDDEN)\n }\n\n // TODO: replace this method\n const { hash, salt } = await generatePasswordSaltHash({\n collection: collectionConfig,\n password: data.password,\n req,\n })\n\n user.salt = salt\n user.hash = hash\n\n user.resetPasswordExpiration = new Date().toISOString()\n\n if (collectionConfig.auth.verify) {\n user._verified = Boolean(user._verified)\n }\n // /////////////////////////////////////\n // beforeValidate - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.beforeValidate?.length) {\n for (const hook of collectionConfig.hooks.beforeValidate) {\n await hook({\n collection: args.collection?.config,\n context: req.context,\n data: user,\n operation: 'update',\n req,\n })\n }\n }\n\n // /////////////////////////////////////\n // Update new password\n // /////////////////////////////////////\n\n // Ensure updatedAt date is always updated\n user.updatedAt = new Date().toISOString()\n\n const doc = await payload.db.updateOne({\n id: user.id,\n collection: collectionConfig.slug,\n data: user,\n req,\n })\n\n await authenticateLocalStrategy({ doc, password: data.password })\n\n const fieldsToSign = getFieldsToSign({\n collectionConfig,\n email: user.email,\n user,\n })\n\n const { token } = await jwtSign({\n fieldsToSign,\n secret,\n tokenExpiration: collectionConfig.auth.tokenExpiration,\n })\n\n const fullUser = await payload.findByID({\n id: user.id,\n collection: collectionConfig.slug,\n depth,\n overrideAccess,\n req,\n trash: false,\n })\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n if (fullUser) {\n fullUser.collection = collectionConfig.slug\n fullUser._strategy = 'local-jwt'\n }\n\n let result: { user: DataFromCollectionSlug<TSlug> } & Result = {\n token,\n user: fullUser,\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: args.collection?.config,\n operation: 'resetPassword',\n result,\n })\n\n return result\n } catch (error: unknown) {\n await killTransaction(req)\n throw error\n }\n}\n"],"names":["status","httpStatus","buildAfterOperation","APIError","Forbidden","appendNonTrashedFilter","commitTransaction","initTransaction","killTransaction","getFieldsToSign","jwtSign","authenticateLocalStrategy","generatePasswordSaltHash","resetPasswordOperation","args","collection","config","collectionConfig","data","depth","overrideAccess","req","payload","secret","Object","prototype","hasOwnProperty","call","BAD_REQUEST","auth","disableLocalStrategy","t","shouldCommit","hooks","beforeOperation","length","hook","context","operation","where","enableTrash","Boolean","trash","resetPasswordExpiration","greater_than","Date","toISOString","resetPasswordToken","equals","token","user","db","findOne","slug","FORBIDDEN","hash","salt","password","verify","_verified","beforeValidate","updatedAt","doc","updateOne","id","fieldsToSign","email","tokenExpiration","fullUser","findByID","_strategy","result","error"],"mappings":"AAAA,SAASA,UAAUC,UAAU,QAAQ,cAAa;AAMlD,SAASC,mBAAmB,QAAQ,wCAAuC;AAC3E,SAASC,QAAQ,EAAEC,SAAS,QAAQ,wBAAuB;AAC3D,SAASC,sBAAsB,QAAQ,4CAA2C;AAClF,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,wBAAuB;AACvD,SAASC,OAAO,QAAQ,YAAW;AACnC,SAASC,yBAAyB,QAAQ,sCAAqC;AAC/E,SAASC,wBAAwB,QAAQ,kDAAiD;AAkB1F,OAAO,MAAMC,yBAAyB,OACpCC;IAEA,MAAM,EACJC,YAAY,EAAEC,QAAQC,gBAAgB,EAAE,EACxCC,IAAI,EACJC,KAAK,EACLC,cAAc,EACdC,KAAK,EACHC,SAAS,EAAEC,MAAM,EAAE,EACnBD,OAAO,EACR,EACDD,GAAG,EACJ,GAAGP;IAEJ,IACE,CAACU,OAAOC,SAAS,CAACC,cAAc,CAACC,IAAI,CAACT,MAAM,YAC5C,CAACM,OAAOC,SAAS,CAACC,cAAc,CAACC,IAAI,CAACT,MAAM,aAC5C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IAAI;YAC3Ce,SAASE,SAAS,GAAG;QACvB;QAEA,IAAIC,SAA2D;YAC7DtB;YACAC,MAAMkB;QACR;QAEA,wCAAwC;QACxC,8BAA8B;QAC9B,wCAAwC;QAExCG,SAAS,MAAMrE,oBAAoB;YACjCY;YACAC,YAAYD,KAAKC,UAAU,EAAEC;YAC7BsB,WAAW;YACXiC;QACF;QAEA,OAAOA;IACT,EAAE,OAAOC,OAAgB;QACvB,MAAMhE,gBAAgBa;QACtB,MAAMmD;IACR;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/auth/operations/resetPassword.ts"],"sourcesContent":["import { status as httpStatus } from 'http-status'\n\nimport type { Collection, DataFromCollectionSlug } from '../../collections/config/types.js'\nimport type { CollectionSlug } from '../../index.js'\nimport type { PayloadRequest } from '../../types/index.js'\n\nimport { buildAfterOperation } from '../../collections/operations/utils.js'\nimport { APIError, Forbidden } from '../../errors/index.js'\nimport { appendNonTrashedFilter } from '../../utilities/appendNonTrashedFilter.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { getFieldsToSign } from '../getFieldsToSign.js'\nimport { jwtSign } from '../jwt.js'\nimport { addSessionToUser } from '../sessions.js'\nimport { authenticateLocalStrategy } from '../strategies/local/authenticate.js'\nimport { generatePasswordSaltHash } from '../strategies/local/generatePasswordSaltHash.js'\n\nexport type Result = {\n token?: string\n user: Record<string, unknown>\n}\n\nexport type Arguments = {\n collection: Collection\n data: {\n password: string\n token: string\n }\n depth?: number\n overrideAccess?: boolean\n req: PayloadRequest\n}\n\nexport const resetPasswordOperation = async <TSlug extends CollectionSlug>(\n args: Arguments,\n): Promise<Result> => {\n const {\n collection: { config: collectionConfig },\n data,\n depth,\n overrideAccess,\n req: {\n payload: { secret },\n payload,\n },\n req,\n } = args\n\n if (\n !Object.prototype.hasOwnProperty.call(data, 'token') ||\n !Object.prototype.hasOwnProperty.call(data, 'password')\n ) {\n throw new APIError('Missing required data.', httpStatus.BAD_REQUEST)\n }\n\n if (collectionConfig.auth.disableLocalStrategy) {\n throw new Forbidden(req.t)\n }\n\n try {\n const shouldCommit = await initTransaction(req)\n\n if (args.collection.config.hooks?.beforeOperation?.length) {\n for (const hook of args.collection.config.hooks.beforeOperation) {\n args =\n (await hook({\n args,\n collection: args.collection?.config,\n context: args.req.context,\n operation: 'resetPassword',\n req: args.req,\n })) || args\n }\n }\n\n // /////////////////////////////////////\n // Reset Password\n // /////////////////////////////////////\n\n const where = appendNonTrashedFilter({\n enableTrash: Boolean(collectionConfig.trash),\n trash: false,\n where: {\n resetPasswordExpiration: { greater_than: new Date().toISOString() },\n resetPasswordToken: { equals: data.token },\n },\n })\n\n const user = await payload.db.findOne<any>({\n collection: collectionConfig.slug,\n req,\n where,\n })\n\n if (!user) {\n throw new APIError('Token is either invalid or has expired.', httpStatus.FORBIDDEN)\n }\n\n // TODO: replace this method\n const { hash, salt } = await generatePasswordSaltHash({\n collection: collectionConfig,\n password: data.password,\n req,\n })\n\n user.salt = salt\n user.hash = hash\n\n user.resetPasswordExpiration = new Date().toISOString()\n\n if (collectionConfig.auth.verify) {\n user._verified = Boolean(user._verified)\n }\n // /////////////////////////////////////\n // beforeValidate - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.beforeValidate?.length) {\n for (const hook of collectionConfig.hooks.beforeValidate) {\n await hook({\n collection: args.collection?.config,\n context: req.context,\n data: user,\n operation: 'update',\n req,\n })\n }\n }\n\n // /////////////////////////////////////\n // Update new password\n // /////////////////////////////////////\n\n // Ensure updatedAt date is always updated\n user.updatedAt = new Date().toISOString()\n\n const doc = await payload.db.updateOne({\n id: user.id,\n collection: collectionConfig.slug,\n data: user,\n req,\n })\n\n await authenticateLocalStrategy({ doc, password: data.password })\n\n const fieldsToSignArgs: Parameters<typeof getFieldsToSign>[0] = {\n collectionConfig,\n email: user.email,\n user,\n }\n\n const { sid } = await addSessionToUser({\n collectionConfig,\n payload,\n req,\n user,\n })\n\n if (sid) {\n fieldsToSignArgs.sid = sid\n }\n\n const fieldsToSign = getFieldsToSign(fieldsToSignArgs)\n\n const { token } = await jwtSign({\n fieldsToSign,\n secret,\n tokenExpiration: collectionConfig.auth.tokenExpiration,\n })\n\n const fullUser = await payload.findByID({\n id: user.id,\n collection: collectionConfig.slug,\n depth,\n overrideAccess,\n req,\n trash: false,\n })\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n if (fullUser) {\n fullUser.collection = collectionConfig.slug\n fullUser._strategy = 'local-jwt'\n }\n\n let result: { user: DataFromCollectionSlug<TSlug> } & Result = {\n token,\n user: fullUser,\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation({\n args,\n collection: args.collection?.config,\n operation: 'resetPassword',\n result,\n })\n\n return result\n } catch (error: unknown) {\n await killTransaction(req)\n throw error\n }\n}\n"],"names":["status","httpStatus","buildAfterOperation","APIError","Forbidden","appendNonTrashedFilter","commitTransaction","initTransaction","killTransaction","getFieldsToSign","jwtSign","addSessionToUser","authenticateLocalStrategy","generatePasswordSaltHash","resetPasswordOperation","args","collection","config","collectionConfig","data","depth","overrideAccess","req","payload","secret","Object","prototype","hasOwnProperty","call","BAD_REQUEST","auth","disableLocalStrategy","t","shouldCommit","hooks","beforeOperation","length","hook","context","operation","where","enableTrash","Boolean","trash","resetPasswordExpiration","greater_than","Date","toISOString","resetPasswordToken","equals","token","user","db","findOne","slug","FORBIDDEN","hash","salt","password","verify","_verified","beforeValidate","updatedAt","doc","updateOne","id","fieldsToSignArgs","email","sid","fieldsToSign","tokenExpiration","fullUser","findByID","_strategy","result","error"],"mappings":"AAAA,SAASA,UAAUC,UAAU,QAAQ,cAAa;AAMlD,SAASC,mBAAmB,QAAQ,wCAAuC;AAC3E,SAASC,QAAQ,EAAEC,SAAS,QAAQ,wBAAuB;AAC3D,SAASC,sBAAsB,QAAQ,4CAA2C;AAClF,S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AS,CAAC;YACrCC,IAAId,KAAKc,EAAE;YACXjD,YAAYE,iBAAiBoC,IAAI;YACjCnC,MAAMgC;YACN7B;QACF;QAEA,MAAMV,0BAA0B;YAAEmD;YAAKL,UAAUvC,KAAKuC,QAAQ;QAAC;QAE/D,MAAMQ,mBAA0D;YAC9DhD;YACAiD,OAAOhB,KAAKgB,KAAK;YACjBhB;QACF;QAEA,MAAM,EAAEiB,GAAG,EAAE,GAAG,MAAMzD,iBAAiB;YACrCO;YACAK;YACAD;YACA6B;QACF;QAEA,IAAIiB,KAAK;YACPF,iBAAiBE,GAAG,GAAGA;QACzB;QAEA,MAAMC,eAAe5D,gBAAgByD;QAErC,MAAM,EAAEhB,KAAK,EAAE,GAAG,MAAMxC,QAAQ;YAC9B2D;YACA7C;YACA8C,iBAAiBpD,iBAAiBY,IAAI,CAACwC,eAAe;QACxD;QAEA,MAAMC,WAAW,MAAMhD,QAAQiD,QAAQ,CAAC;YACtCP,IAAId,KAAKc,EAAE;YACXjD,YAAYE,iBAAiBoC,IAAI;YACjClC;YACAC;YACAC;YACAqB,OAAO;QACT;QAEA,IAAIV,cAAc;YAChB,MAAM3B,kBAAkBgB;QAC1B;QAEA,IAAIiD,UAAU;YACZA,SAASvD,UAAU,GAAGE,iBAAiBoC,IAAI;YAC3CiB,SAASE,SAAS,GAAG;QACvB;QAEA,IAAIC,SAA2D;YAC7DxB;YACAC,MAAMoB;QACR;QAEA,wCAAwC;QACxC,8BAA8B;QAC9B,wCAAwC;QAExCG,SAAS,MAAMxE,oBAAoB;YACjCa;YACAC,YAAYD,KAAKC,UAAU,EAAEC;YAC7BsB,WAAW;YACXmC;QACF;QAEA,OAAOA;IACT,EAAE,OAAOC,OAAgB;QACvB,MAAMnE,gBAAgBc;QACtB,MAAMqD;IACR;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findByID.d.ts","sourceRoot":"","sources":["../../../src/collections/endpoints/findByID.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAU3D,eAAO,MAAM,eAAe,EAAE,
|
|
1
|
+
{"version":3,"file":"findByID.d.ts","sourceRoot":"","sources":["../../../src/collections/endpoints/findByID.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAU3D,eAAO,MAAM,eAAe,EAAE,cA8B7B,CAAA"}
|
|
@@ -7,15 +7,16 @@ import { sanitizePopulateParam } from '../../utilities/sanitizePopulateParam.js'
|
|
|
7
7
|
import { sanitizeSelectParam } from '../../utilities/sanitizeSelectParam.js';
|
|
8
8
|
import { findByIDOperation } from '../operations/findByID.js';
|
|
9
9
|
export const findByIDHandler = async (req)=>{
|
|
10
|
-
const { searchParams } = req;
|
|
10
|
+
const { data, searchParams } = req;
|
|
11
11
|
const { id, collection } = getRequestCollectionWithID(req);
|
|
12
|
-
const depth = searchParams.get('depth');
|
|
13
|
-
const trash = searchParams.get('trash') === 'true';
|
|
12
|
+
const depth = data ? data.depth : searchParams.get('depth');
|
|
13
|
+
const trash = data ? data.trash : searchParams.get('trash') === 'true';
|
|
14
14
|
const result = await findByIDOperation({
|
|
15
15
|
id,
|
|
16
16
|
collection,
|
|
17
|
+
data: data ? data?.data : searchParams.get('data') ? JSON.parse(searchParams.get('data')) : undefined,
|
|
17
18
|
depth: isNumber(depth) ? Number(depth) : undefined,
|
|
18
|
-
draft: searchParams.get('draft') === 'true',
|
|
19
|
+
draft: data ? data.draft : searchParams.get('draft') === 'true',
|
|
19
20
|
joins: sanitizeJoinParams(req.query.joins),
|
|
20
21
|
populate: sanitizePopulateParam(req.query.populate),
|
|
21
22
|
req,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/collections/endpoints/findByID.ts"],"sourcesContent":["import { status as httpStatus } from 'http-status'\n\nimport type { PayloadHandler } from '../../config/types.js'\n\nimport { getRequestCollectionWithID } from '../../utilities/getRequestEntity.js'\nimport { headersWithCors } from '../../utilities/headersWithCors.js'\nimport { isNumber } from '../../utilities/isNumber.js'\nimport { type JoinParams, sanitizeJoinParams } from '../../utilities/sanitizeJoinParams.js'\nimport { sanitizePopulateParam } from '../../utilities/sanitizePopulateParam.js'\nimport { sanitizeSelectParam } from '../../utilities/sanitizeSelectParam.js'\nimport { findByIDOperation } from '../operations/findByID.js'\n\nexport const findByIDHandler: PayloadHandler = async (req) => {\n const { searchParams } = req\n const { id, collection } = getRequestCollectionWithID(req)\n const depth = searchParams.get('depth')\n const trash = searchParams.get('trash') === 'true'\n\n const result = await findByIDOperation({\n id,\n collection,\n depth: isNumber(depth) ? Number(depth) : undefined,\n draft: searchParams.get('draft') === 'true',\n joins: sanitizeJoinParams(req.query.joins as JoinParams),\n populate: sanitizePopulateParam(req.query.populate),\n req,\n select: sanitizeSelectParam(req.query.select),\n trash,\n })\n\n return Response.json(result, {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n status: httpStatus.OK,\n })\n}\n"],"names":["status","httpStatus","getRequestCollectionWithID","headersWithCors","isNumber","sanitizeJoinParams","sanitizePopulateParam","sanitizeSelectParam","findByIDOperation","findByIDHandler","req","searchParams","id","collection","depth","get","trash","result","
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/endpoints/findByID.ts"],"sourcesContent":["import { status as httpStatus } from 'http-status'\n\nimport type { PayloadHandler } from '../../config/types.js'\n\nimport { getRequestCollectionWithID } from '../../utilities/getRequestEntity.js'\nimport { headersWithCors } from '../../utilities/headersWithCors.js'\nimport { isNumber } from '../../utilities/isNumber.js'\nimport { type JoinParams, sanitizeJoinParams } from '../../utilities/sanitizeJoinParams.js'\nimport { sanitizePopulateParam } from '../../utilities/sanitizePopulateParam.js'\nimport { sanitizeSelectParam } from '../../utilities/sanitizeSelectParam.js'\nimport { findByIDOperation } from '../operations/findByID.js'\n\nexport const findByIDHandler: PayloadHandler = async (req) => {\n const { data, searchParams } = req\n const { id, collection } = getRequestCollectionWithID(req)\n const depth = data ? data.depth : searchParams.get('depth')\n const trash = data ? data.trash : searchParams.get('trash') === 'true'\n\n const result = await findByIDOperation({\n id,\n collection,\n data: data\n ? data?.data\n : searchParams.get('data')\n ? JSON.parse(searchParams.get('data') as string)\n : undefined,\n depth: isNumber(depth) ? Number(depth) : undefined,\n draft: data ? data.draft : searchParams.get('draft') === 'true',\n joins: sanitizeJoinParams(req.query.joins as JoinParams),\n populate: sanitizePopulateParam(req.query.populate),\n req,\n select: sanitizeSelectParam(req.query.select),\n trash,\n })\n\n return Response.json(result, {\n headers: headersWithCors({\n headers: new Headers(),\n req,\n }),\n status: httpStatus.OK,\n })\n}\n"],"names":["status","httpStatus","getRequestCollectionWithID","headersWithCors","isNumber","sanitizeJoinParams","sanitizePopulateParam","sanitizeSelectParam","findByIDOperation","findByIDHandler","req","data","searchParams","id","collection","depth","get","trash","result","JSON","parse","undefined","Number","draft","joins","query","populate","select","Response","json","headers","Headers","OK"],"mappings":"AAAA,SAASA,UAAUC,UAAU,QAAQ,cAAa;AAIlD,SAASC,0BAA0B,QAAQ,sCAAqC;AAChF,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,QAAQ,QAAQ,8BAA6B;AACtD,SAA0BC,kBAAkB,QAAQ,wCAAuC;AAC3F,SAASC,qBAAqB,QAAQ,2CAA0C;AAChF,SAASC,mBAAmB,QAAQ,yCAAwC;AAC5E,SAASC,iBAAiB,QAAQ,4BAA2B;AAE7D,OAAO,MAAMC,kBAAkC,OAAOC;IACpD,MAAM,EAAEC,IAAI,EAAEC,YAAY,EAAE,GAAGF;IAC/B,MAAM,EAAEG,EAAE,EAAEC,UAAU,EAAE,GAAGZ,2BAA2BQ;IACtD,MAAMK,QAAQJ,OAAOA,KAAKI,KAAK,GAAGH,aAAaI,GAAG,CAAC;IACnD,MAAMC,QAAQN,OAAOA,KAAKM,KAAK,GAAGL,aAAaI,GAAG,CAAC,aAAa;IAEhE,MAAME,SAAS,MAAMV,kBAAkB;QACrCK;QACAC;QACAH,MAAMA,OACFA,MAAMA,OACNC,aAAaI,GAAG,CAAC,UACfG,KAAKC,KAAK,CAACR,aAAaI,GAAG,CAAC,WAC5BK;QACNN,OAAOX,SAASW,SAASO,OAAOP,SAASM;QACzCE,OAAOZ,OAAOA,KAAKY,KAAK,GAAGX,aAAaI,GAAG,CAAC,aAAa;QACzDQ,OAAOnB,mBAAmBK,IAAIe,KAAK,CAACD,KAAK;QACzCE,UAAUpB,sBAAsBI,IAAIe,KAAK,CAACC,QAAQ;QAClDhB;QACAiB,QAAQpB,oBAAoBG,IAAIe,KAAK,CAACE,MAAM;QAC5CV;IACF;IAEA,OAAOW,SAASC,IAAI,CAACX,QAAQ;QAC3BY,SAAS3B,gBAAgB;YACvB2B,SAAS,IAAIC;YACbrB;QACF;QACAV,QAAQC,WAAW+B,EAAE;IACvB;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../src/collections/operations/create.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,cAAc,EACd,YAAY,EACZ,UAAU,EACV,6BAA6B,EAC9B,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EACV,UAAU,EACV,sBAAsB,EACtB,8BAA8B,EAC9B,wBAAwB,EACzB,MAAM,oBAAoB,CAAA;AAW3B,OAAO,EAAE,KAAK,cAAc,EAAmB,MAAM,gBAAgB,CAAA;AAYrE,MAAM,MAAM,SAAS,CAAC,KAAK,SAAS,cAAc,IAAI;IACpD,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,UAAU,EAAE,UAAU,CAAA;IACtB,IAAI,EAAE,8BAA8B,CAAC,KAAK,CAAC,CAAA;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,kBAAkB,CAAC,EAAE,OAAO,CAAA;IAC5B,wBAAwB,CAAC,EAAE,OAAO,CAAA;IAClC,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,eAAe,C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AI,CAAC,CAAA;IACrD,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAChC,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,qBAAqB,CAAC,EAAE,MAAM,CAAA;IAC9B,GAAG,EAAE,cAAc,CAAA;IACnB,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B,CAAA;AAED,eAAO,MAAM,eAAe,GAC1B,KAAK,SAAS,cAAc,EAC5B,OAAO,SAAS,wBAAwB,CAAC,KAAK,CAAC,gBAEjC,SAAS,CAAC,KAAK,CAAC,KAC7B,OAAO,CAAC,6BAA6B,CAAC,KAAK,EAAE,OAAO,CAAC,CAiWvD,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/collections/operations/create.ts"],"sourcesContent":["import crypto from 'crypto'\n\nimport type {\n Document,\n PayloadRequest,\n PopulateType,\n SelectType,\n TransformCollectionWithSelect,\n} from '../../types/index.js'\nimport type {\n Collection,\n DataFromCollectionSlug,\n RequiredDataFromCollectionSlug,\n SelectFromCollectionSlug,\n} from '../config/types.js'\n\nimport { ensureUsernameOrEmail } from '../../auth/ensureUsernameOrEmail.js'\nimport { executeAccess } from '../../auth/executeAccess.js'\nimport { sendVerificationEmail } from '../../auth/sendVerificationEmail.js'\nimport { registerLocalStrategy } from '../../auth/strategies/local/register.js'\nimport { getDuplicateDocumentData } from '../../duplicateDocument/index.js'\nimport { afterChange } from '../../fields/hooks/afterChange/index.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { beforeChange } from '../../fields/hooks/beforeChange/index.js'\nimport { beforeValidate } from '../../fields/hooks/beforeValidate/index.js'\nimport { type CollectionSlug, type JsonObject } from '../../index.js'\nimport { generateFileData } from '../../uploads/generateFileData.js'\nimport { unlinkTempFiles } from '../../uploads/unlinkTempFiles.js'\nimport { uploadFiles } from '../../uploads/uploadFiles.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { sanitizeInternalFields } from '../../utilities/sanitizeInternalFields.js'\nimport { sanitizeSelect } from '../../utilities/sanitizeSelect.js'\nimport { saveVersion } from '../../versions/saveVersion.js'\nimport { buildAfterOperation } from './utils.js'\n\nexport type Arguments<TSlug extends CollectionSlug> = {\n autosave?: boolean\n collection: Collection\n data: RequiredDataFromCollectionSlug<TSlug>\n depth?: number\n disableTransaction?: boolean\n disableVerificationEmail?: boolean\n draft?: boolean\n duplicateFromID?: DataFromCollectionSlug<TSlug>['id']\n overrideAccess?: boolean\n overwriteExistingFiles?: boolean\n populate?: PopulateType\n publishSpecificLocale?: string\n req: PayloadRequest\n select?: SelectType\n showHiddenFields?: boolean\n}\n\nexport const createOperation = async <\n TSlug extends CollectionSlug,\n TSelect extends SelectFromCollectionSlug<TSlug>,\n>(\n incomingArgs: Arguments<TSlug>,\n): Promise<TransformCollectionWithSelect<TSlug, TSelect>> => {\n let args = incomingArgs\n\n try {\n const shouldCommit = !args.disableTransaction && (await initTransaction(args.req))\n\n ensureUsernameOrEmail<TSlug>({\n authOptions: args.collection.config.auth,\n collectionSlug: args.collection.config.slug,\n data: args.data,\n operation: 'create',\n req: args.req,\n })\n\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n if (args.collection.config.hooks.beforeOperation?.length) {\n for (const hook of args.collection.config.hooks.beforeOperation) {\n args =\n (await hook({\n args,\n collection: args.collection.config,\n context: args.req.context,\n operation: 'create',\n req: args.req,\n })) || args\n }\n }\n\n if (args.publishSpecificLocale) {\n args.req.locale = args.publishSpecificLocale\n }\n\n const {\n autosave = false,\n collection: { config: collectionConfig },\n collection,\n depth,\n disableVerificationEmail,\n draft = false,\n duplicateFromID,\n overrideAccess,\n overwriteExistingFiles = false,\n populate,\n publishSpecificLocale,\n req: {\n fallbackLocale,\n locale,\n payload,\n payload: { config },\n },\n req,\n select: incomingSelect,\n showHiddenFields,\n } = args\n\n let { data } = args\n\n const shouldSaveDraft = Boolean(draft && collectionConfig.versions.drafts)\n\n let duplicatedFromDocWithLocales: JsonObject = {}\n let duplicatedFromDoc: JsonObject = {}\n\n if (duplicateFromID) {\n const duplicateResult = await getDuplicateDocumentData({\n id: duplicateFromID,\n collectionConfig,\n draftArg: shouldSaveDraft,\n overrideAccess,\n req,\n shouldSaveDraft,\n })\n\n duplicatedFromDoc = duplicateResult.duplicatedFromDoc\n duplicatedFromDocWithLocales = duplicateResult.duplicatedFromDocWithLocales\n }\n\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n if (!overrideAccess) {\n await executeAccess({ data, req }, collectionConfig.access.create)\n }\n\n // /////////////////////////////////////\n // Generate data for all files and sizes\n // /////////////////////////////////////\n\n const { data: newFileData, files: filesToUpload } = await generateFileData({\n collection,\n config,\n data,\n isDuplicating: Boolean(duplicateFromID),\n operation: 'create',\n originalDoc: duplicatedFromDoc,\n overwriteExistingFiles,\n req,\n throwOnMissingFile:\n !shouldSaveDraft && collection.config.upload.filesRequiredOnCreate !== false,\n })\n\n data = newFileData\n\n // /////////////////////////////////////\n // beforeValidate - Fields\n // /////////////////////////////////////\n\n data = await beforeValidate({\n collection: collectionConfig,\n context: req.context,\n data,\n doc: duplicatedFromDoc,\n global: null,\n operation: 'create',\n overrideAccess: overrideAccess!,\n req,\n })\n\n // /////////////////////////////////////\n // beforeValidate - Collections\n // /////////////////////////////////////\n\n if (collectionConfig.hooks.beforeValidate?.length) {\n for (const hook of collectionConfig.hooks.beforeValidate) {\n data =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n operation: 'create',\n originalDoc: duplicatedFromDoc,\n req,\n })) || data\n }\n }\n\n // /////////////////////////////////////\n // beforeChange - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.beforeChange?.length) {\n for (const hook of collectionConfig.hooks.beforeChange) {\n data =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n operation: 'create',\n originalDoc: duplicatedFromDoc,\n req,\n })) || data\n }\n }\n\n // /////////////////////////////////////\n // beforeChange - Fields\n // /////////////////////////////////////\n\n const resultWithLocales = await beforeChange<JsonObject>({\n collection: collectionConfig,\n context: req.context,\n data,\n doc: duplicatedFromDoc,\n docWithLocales: duplicatedFromDocWithLocales,\n global: null,\n operation: 'create',\n overrideAccess,\n req,\n skipValidation:\n shouldSaveDraft &&\n collectionConfig.versions.drafts &&\n !collectionConfig.versions.drafts.validate,\n })\n\n // /////////////////////////////////////\n // Write files to local storage\n // /////////////////////////////////////\n\n if (!collectionConfig.upload.disableLocalStorage) {\n await uploadFiles(payload, filesToUpload, req)\n }\n\n // /////////////////////////////////////\n // Create\n // /////////////////////////////////////\n\n let doc\n\n const select = sanitizeSelect({\n fields: collectionConfig.flattenedFields,\n forceSelect: collectionConfig.forceSelect,\n select: incomingSelect,\n })\n\n if (collectionConfig.auth && !collectionConfig.auth.disableLocalStrategy) {\n if (collectionConfig.auth.verify) {\n resultWithLocales._verified = Boolean(resultWithLocales._verified) || false\n resultWithLocales._verificationToken = crypto.randomBytes(20).toString('hex')\n }\n\n doc = await registerLocalStrategy({\n collection: collectionConfig,\n doc: resultWithLocales,\n password: data.password as string,\n payload: req.payload,\n req,\n select,\n })\n } else {\n doc = await payload.db.create({\n collection: collectionConfig.slug,\n data: resultWithLocales,\n req,\n select,\n })\n }\n\n const verificationToken = doc._verificationToken\n let result: Document = sanitizeInternalFields(doc)\n\n // /////////////////////////////////////\n // Create version\n // /////////////////////////////////////\n\n if (collectionConfig.versions) {\n await saveVersion({\n id: result.id,\n autosave,\n collection: collectionConfig,\n docWithLocales: result,\n operation: 'create',\n payload,\n publishSpecificLocale,\n req,\n })\n }\n\n // /////////////////////////////////////\n // Send verification email if applicable\n // /////////////////////////////////////\n\n if (collectionConfig.auth && collectionConfig.auth.verify && result.email) {\n await sendVerificationEmail({\n collection: { config: collectionConfig },\n config: payload.config,\n disableEmail: disableVerificationEmail!,\n email: payload.email,\n req,\n token: verificationToken,\n user: result,\n })\n }\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth: depth!,\n doc: result,\n draft,\n fallbackLocale: fallbackLocale!,\n global: null,\n locale: locale!,\n overrideAccess: overrideAccess!,\n populate,\n req,\n select,\n showHiddenFields: showHiddenFields!,\n })\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterRead?.length) {\n for (const hook of collectionConfig.hooks.afterRead) {\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result,\n req,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // afterChange - Fields\n // /////////////////////////////////////\n\n result = await afterChange({\n collection: collectionConfig,\n context: req.context,\n data,\n doc: result,\n global: null,\n operation: 'create',\n previousDoc: {},\n req,\n })\n\n // /////////////////////////////////////\n // afterChange - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterChange?.length) {\n for (const hook of collectionConfig.hooks.afterChange) {\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n doc: result,\n operation: 'create',\n previousDoc: {},\n req: args.req,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation<TSlug>({\n args,\n collection: collectionConfig,\n operation: 'create',\n result,\n })\n\n await unlinkTempFiles({ collectionConfig, config, req })\n\n // /////////////////////////////////////\n // Return results\n // /////////////////////////////////////\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return result\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["crypto","ensureUsernameOrEmail","executeAccess","sendVerificationEmail","registerLocalStrategy","getDuplicateDocumentData","afterChange","afterRead","beforeChange","beforeValidate","generateFileData","unlinkTempFiles","uploadFiles","commitTransaction","initTransaction","killTransaction","sanitizeInternalFields","sanitizeSelect","saveVersion","buildAfterOperation","createOperation","incomingArgs","args","shouldCommit","disableTransaction","req","authOptions","collection","config","auth","collectionSlug","slug","data","operation","hooks","beforeOperation","length","hook","context","publishSpecificLocale","locale","autosave","collectionConfig","depth","disableVerificationEmail","draft","duplicateFromID","overrideAccess","overwriteExistingFiles","populate","fallbackLocale","payload","select","incomingSelect","showHiddenFields","shouldSaveDraft","Boolean","versions","drafts","duplicatedFromDocWithLocales","duplicatedFromDoc","duplicateResult","id","draftArg","access","create","newFileData","files","filesToUpload","isDuplicating","originalDoc","throwOnMissingFile","upload","filesRequiredOnCreate","doc","global","resultWithLocales","docWithLocales","skipValidation","validate","disableLocalStorage","fields","flattenedFields","forceSelect","disableLocalStrategy","verify","_verified","_verificationToken","randomBytes","toString","password","db","verificationToken","result","email","disableEmail","token","user","previousDoc","error"],"mappings":"AAAA,OAAOA,YAAY,SAAQ;AAgB3B,SAASC,qBAAqB,QAAQ,sCAAqC;AAC3E,SAASC,aAAa,QAAQ,8BAA6B;AAC3D,SAASC,qBAAqB,QAAQ,sCAAqC;AAC3E,SAASC,qBAAqB,QAAQ,0CAAyC;AAC/E,SAASC,wBAAwB,QAAQ,mCAAkC;AAC3E,SAASC,WAAW,QAAQ,0CAAyC;AACrE,SAASC,SAAS,QAAQ,wCAAuC;AACjE,SAASC,YAAY,QAAQ,2CAA0C;AACvE,SAASC,cAAc,QAAQ,6CAA4C;AAE3E,SAASC,gBAAgB,QAAQ,oCAAmC;AACpE,SAASC,eAAe,QAAQ,mCAAkC;AAClE,SAASC,WAAW,QAAQ,+BAA8B;AAC1D,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,sBAAsB,QAAQ,4CAA2C;AAClF,SAASC,cAAc,QAAQ,oCAAmC;AAClE,SAASC,WAAW,QAAQ,gCAA+B;AAC3D,SAASC,mBAAmB,Q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"}
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/operations/create.ts"],"sourcesContent":["import crypto from 'crypto'\n\nimport type {\n Document,\n PayloadRequest,\n PopulateType,\n SelectType,\n TransformCollectionWithSelect,\n} from '../../types/index.js'\nimport type {\n Collection,\n DataFromCollectionSlug,\n RequiredDataFromCollectionSlug,\n SelectFromCollectionSlug,\n} from '../config/types.js'\n\nimport { ensureUsernameOrEmail } from '../../auth/ensureUsernameOrEmail.js'\nimport { executeAccess } from '../../auth/executeAccess.js'\nimport { sendVerificationEmail } from '../../auth/sendVerificationEmail.js'\nimport { registerLocalStrategy } from '../../auth/strategies/local/register.js'\nimport { getDuplicateDocumentData } from '../../duplicateDocument/index.js'\nimport { afterChange } from '../../fields/hooks/afterChange/index.js'\nimport { afterRead } from '../../fields/hooks/afterRead/index.js'\nimport { beforeChange } from '../../fields/hooks/beforeChange/index.js'\nimport { beforeValidate } from '../../fields/hooks/beforeValidate/index.js'\nimport { type CollectionSlug, type JsonObject } from '../../index.js'\nimport { generateFileData } from '../../uploads/generateFileData.js'\nimport { unlinkTempFiles } from '../../uploads/unlinkTempFiles.js'\nimport { uploadFiles } from '../../uploads/uploadFiles.js'\nimport { commitTransaction } from '../../utilities/commitTransaction.js'\nimport { initTransaction } from '../../utilities/initTransaction.js'\nimport { killTransaction } from '../../utilities/killTransaction.js'\nimport { sanitizeInternalFields } from '../../utilities/sanitizeInternalFields.js'\nimport { sanitizeSelect } from '../../utilities/sanitizeSelect.js'\nimport { saveVersion } from '../../versions/saveVersion.js'\nimport { buildAfterOperation } from './utils.js'\n\nexport type Arguments<TSlug extends CollectionSlug> = {\n autosave?: boolean\n collection: Collection\n data: RequiredDataFromCollectionSlug<TSlug>\n depth?: number\n disableTransaction?: boolean\n disableVerificationEmail?: boolean\n draft?: boolean\n duplicateFromID?: DataFromCollectionSlug<TSlug>['id']\n overrideAccess?: boolean\n overwriteExistingFiles?: boolean\n populate?: PopulateType\n publishSpecificLocale?: string\n req: PayloadRequest\n select?: SelectType\n showHiddenFields?: boolean\n}\n\nexport const createOperation = async <\n TSlug extends CollectionSlug,\n TSelect extends SelectFromCollectionSlug<TSlug>,\n>(\n incomingArgs: Arguments<TSlug>,\n): Promise<TransformCollectionWithSelect<TSlug, TSelect>> => {\n let args = incomingArgs\n\n try {\n const shouldCommit = !args.disableTransaction && (await initTransaction(args.req))\n\n ensureUsernameOrEmail<TSlug>({\n authOptions: args.collection.config.auth,\n collectionSlug: args.collection.config.slug,\n data: args.data,\n operation: 'create',\n req: args.req,\n })\n\n // /////////////////////////////////////\n // beforeOperation - Collection\n // /////////////////////////////////////\n\n if (args.collection.config.hooks.beforeOperation?.length) {\n for (const hook of args.collection.config.hooks.beforeOperation) {\n args =\n (await hook({\n args,\n collection: args.collection.config,\n context: args.req.context,\n operation: 'create',\n req: args.req,\n })) || args\n }\n }\n\n if (args.publishSpecificLocale) {\n args.req.locale = args.publishSpecificLocale\n }\n\n const {\n autosave = false,\n collection: { config: collectionConfig },\n collection,\n depth,\n disableVerificationEmail,\n draft = false,\n duplicateFromID,\n overrideAccess,\n overwriteExistingFiles = false,\n populate,\n publishSpecificLocale,\n req: {\n fallbackLocale,\n locale,\n payload,\n payload: { config },\n },\n req,\n select: incomingSelect,\n showHiddenFields,\n } = args\n\n let { data } = args\n\n const shouldSaveDraft = Boolean(draft && collectionConfig.versions.drafts)\n\n let duplicatedFromDocWithLocales: JsonObject = {}\n let duplicatedFromDoc: JsonObject = {}\n\n if (duplicateFromID) {\n const duplicateResult = await getDuplicateDocumentData({\n id: duplicateFromID,\n collectionConfig,\n draftArg: shouldSaveDraft,\n overrideAccess,\n req,\n shouldSaveDraft,\n })\n\n duplicatedFromDoc = duplicateResult.duplicatedFromDoc\n duplicatedFromDocWithLocales = duplicateResult.duplicatedFromDocWithLocales\n }\n\n // /////////////////////////////////////\n // Access\n // /////////////////////////////////////\n\n if (!overrideAccess) {\n await executeAccess({ data, req }, collectionConfig.access.create)\n }\n\n // /////////////////////////////////////\n // Generate data for all files and sizes\n // /////////////////////////////////////\n\n const { data: newFileData, files: filesToUpload } = await generateFileData({\n collection,\n config,\n data,\n isDuplicating: Boolean(duplicateFromID),\n operation: 'create',\n originalDoc: duplicatedFromDoc,\n overwriteExistingFiles,\n req,\n throwOnMissingFile:\n !shouldSaveDraft && collection.config.upload.filesRequiredOnCreate !== false,\n })\n\n data = newFileData\n\n // /////////////////////////////////////\n // beforeValidate - Fields\n // /////////////////////////////////////\n\n data = await beforeValidate({\n collection: collectionConfig,\n context: req.context,\n data,\n doc: duplicatedFromDoc,\n global: null,\n operation: 'create',\n overrideAccess: overrideAccess!,\n req,\n })\n\n // /////////////////////////////////////\n // beforeValidate - Collections\n // /////////////////////////////////////\n\n if (collectionConfig.hooks.beforeValidate?.length) {\n for (const hook of collectionConfig.hooks.beforeValidate) {\n data =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n operation: 'create',\n originalDoc: duplicatedFromDoc,\n req,\n })) || data\n }\n }\n\n // /////////////////////////////////////\n // beforeChange - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.beforeChange?.length) {\n for (const hook of collectionConfig.hooks.beforeChange) {\n data =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n operation: 'create',\n originalDoc: duplicatedFromDoc,\n req,\n })) || data\n }\n }\n\n // /////////////////////////////////////\n // beforeChange - Fields\n // /////////////////////////////////////\n\n const resultWithLocales = await beforeChange<JsonObject>({\n collection: collectionConfig,\n context: req.context,\n data,\n doc: duplicatedFromDoc,\n docWithLocales: duplicatedFromDocWithLocales,\n global: null,\n operation: 'create',\n overrideAccess,\n req,\n skipValidation:\n shouldSaveDraft &&\n collectionConfig.versions.drafts &&\n !collectionConfig.versions.drafts.validate,\n })\n\n // /////////////////////////////////////\n // Write files to local storage\n // /////////////////////////////////////\n\n if (!collectionConfig.upload.disableLocalStorage) {\n await uploadFiles(payload, filesToUpload, req)\n }\n\n // /////////////////////////////////////\n // Create\n // /////////////////////////////////////\n\n let doc\n\n const select = sanitizeSelect({\n fields: collectionConfig.flattenedFields,\n forceSelect: collectionConfig.forceSelect,\n select: incomingSelect,\n })\n\n if (collectionConfig.auth && !collectionConfig.auth.disableLocalStrategy) {\n if (collectionConfig.auth.verify) {\n resultWithLocales._verified = Boolean(resultWithLocales._verified) || false\n resultWithLocales._verificationToken = crypto.randomBytes(20).toString('hex')\n }\n\n doc = await registerLocalStrategy({\n collection: collectionConfig,\n doc: resultWithLocales,\n password: data.password as string,\n payload: req.payload,\n req,\n select,\n })\n } else {\n doc = await payload.db.create({\n collection: collectionConfig.slug,\n data: resultWithLocales,\n req,\n select,\n })\n }\n\n const verificationToken = doc._verificationToken\n let result: Document = sanitizeInternalFields(doc)\n\n // /////////////////////////////////////\n // Create version\n // /////////////////////////////////////\n\n if (collectionConfig.versions) {\n await saveVersion({\n id: result.id,\n autosave,\n collection: collectionConfig,\n docWithLocales: result,\n locale,\n operation: 'create',\n payload,\n publishSpecificLocale,\n req,\n })\n }\n\n // /////////////////////////////////////\n // Send verification email if applicable\n // /////////////////////////////////////\n\n if (collectionConfig.auth && collectionConfig.auth.verify && result.email) {\n await sendVerificationEmail({\n collection: { config: collectionConfig },\n config: payload.config,\n disableEmail: disableVerificationEmail!,\n email: payload.email,\n req,\n token: verificationToken,\n user: result,\n })\n }\n\n // /////////////////////////////////////\n // afterRead - Fields\n // /////////////////////////////////////\n\n result = await afterRead({\n collection: collectionConfig,\n context: req.context,\n depth: depth!,\n doc: result,\n draft,\n fallbackLocale: fallbackLocale!,\n global: null,\n locale: locale!,\n overrideAccess: overrideAccess!,\n populate,\n req,\n select,\n showHiddenFields: showHiddenFields!,\n })\n\n // /////////////////////////////////////\n // afterRead - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterRead?.length) {\n for (const hook of collectionConfig.hooks.afterRead) {\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n doc: result,\n req,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // afterChange - Fields\n // /////////////////////////////////////\n\n result = await afterChange({\n collection: collectionConfig,\n context: req.context,\n data,\n doc: result,\n global: null,\n operation: 'create',\n previousDoc: {},\n req,\n })\n\n // /////////////////////////////////////\n // afterChange - Collection\n // /////////////////////////////////////\n\n if (collectionConfig.hooks?.afterChange?.length) {\n for (const hook of collectionConfig.hooks.afterChange) {\n result =\n (await hook({\n collection: collectionConfig,\n context: req.context,\n data,\n doc: result,\n operation: 'create',\n previousDoc: {},\n req: args.req,\n })) || result\n }\n }\n\n // /////////////////////////////////////\n // afterOperation - Collection\n // /////////////////////////////////////\n\n result = await buildAfterOperation<TSlug>({\n args,\n collection: collectionConfig,\n operation: 'create',\n result,\n })\n\n await unlinkTempFiles({ collectionConfig, config, req })\n\n // /////////////////////////////////////\n // Return results\n // /////////////////////////////////////\n\n if (shouldCommit) {\n await commitTransaction(req)\n }\n\n return result\n } catch (error: unknown) {\n await killTransaction(args.req)\n throw error\n }\n}\n"],"names":["crypto","ensureUsernameOrEmail","executeAccess","sendVerificationEmail","registerLocalStrategy","getDuplicateDocumentData","afterChange","afterRead","beforeChange","beforeValidate","generateFileData","unlinkTempFiles","uploadFiles","commitTransaction","initTransaction","killTransaction","sanitizeInternalFields","sanitizeSelect","saveVersion","buildAfterOperation","createOperation","incomingArgs","args","shouldCommit","disableTransaction","req","authOptions","collection","config","auth","collectionSlug","slug","data","operation","hooks","beforeOperation","length","hook","context","publishSpecificLocale","locale","autosave","collectionConfig","depth","disableVerificationEmail","draft","duplicateFromID","overrideAccess","overwriteExistingFiles","populate","fallbackLocale","payload","select","incomingSelect","showHiddenFields","shouldSaveDraft","Boolean","versions","drafts","duplicatedFromDocWithLocales","duplicatedFromDoc","duplicateResult","id","draftArg","access","create","newFileData","files","filesToUpload","isDuplicating","originalDoc","throwOnMissingFile","upload","filesRequiredOnCreate","doc","global","resultWithLocales","docWithLocales","skipValidation","validate","disableLocalStorage","fields","flattenedFields","forceSelect","disableLocalStrategy","verify","_verified","_verificationToken","randomBytes","toString","password","db","verificationToken","result","email","disableEmail","token","user","previousDoc","error"],"mappings":"AAAA,OAAOA,YAAY,SAAQ;AAgB3B,SAASC,qBAAqB,QAAQ,sCAAqC;AAC3E,SAASC,aAAa,QAAQ,8BAA6B;AAC3D,SAASC,qBAAqB,QAAQ,sCAAqC;AAC3E,SAASC,qBAAqB,QAAQ,0CAAyC;AAC/E,SAASC,wBAAwB,QAAQ,mCAAkC;AAC3E,SAASC,WAAW,QAAQ,0CAAyC;AACrE,SAASC,SAAS,QAAQ,wCAAuC;AACjE,SAASC,YAAY,QAAQ,2CAA0C;AACvE,SAASC,cAAc,QAAQ,6CAA4C;AAE3E,SAASC,gBAAgB,QAAQ,oCAAmC;AACpE,SAASC,eAAe,QAAQ,mCAAkC;AAClE,SAASC,WAAW,QAAQ,+BAA8B;AAC1D,SAASC,iBAAiB,QAAQ,uCAAsC;AACxE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,eAAe,QAAQ,qCAAoC;AACpE,SAASC,sBAAsB,QAAQ,4CAA2C;AAClF,SAASC,cAAc,QAAQ,oCAAmC;AAClE,SAASC,WAAW,QAAQ,gCAA+B;AAC3D,SAASC,mBAAmB,QAAQ,aAAY;AAoBhD,OAAO,MAAMC,kBAAkB,OAI7BC;IAEA,IAAIC,OAAOD;IAEX,IAAI;QACF,MAAME,eAAe,CAACD,KAAKE,kBAAkB,IAAK,MAAMV,gBAAgBQ,KAAKG,GAAG;QAEhFxB,sBAA6B;YAC3ByB,aAAaJ,KAAKK,UAAU,CAACC,MAAM,CAACC,IAAI;YACxCC,gBAAgBR,KAAKK,UAAU,CAACC,MAAM,CAACG,IAAI;YAC3CC,MAAMV,KAAKU,IAAI;YACfC,WAAW;YACXR,KAAKH,KAAKG,GAAG;QACf;QAEA,wCAAwC;QACxC,+BAA+B;QAC/B,wCAAwC;QAExC,IAAIH,KAAKK,UAAU,CAACC,MAAM,CAACM,KAAK,CAACC,eAAe,EAAEC,QAAQ;YACxD,KAAK,MAAMC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AC;YACdzE;QACF;QAEA,wCAAwC;QACxC,2BAA2B;QAC3B,wCAAwC;QAExC,IAAIiB,iBAAiBR,KAAK,EAAE5B,aAAa8B,QAAQ;YAC/C,KAAK,MAAMC,QAAQK,iBAAiBR,KAAK,CAAC5B,WAAW,CAAE;gBACrDuF,SACE,AAAC,MAAMxD,KAAK;oBACVV,YAAYe;oBACZJ,SAASb,IAAIa,OAAO;oBACpBN;oBACA0C,KAAKmB;oBACL5D,WAAW;oBACXiE,aAAa,CAAC;oBACdzE,KAAKH,KAAKG,GAAG;gBACf,MAAOoE;YACX;QACF;QAEA,wCAAwC;QACxC,8BAA8B;QAC9B,wCAAwC;QAExCA,SAAS,MAAM1E,oBAA2B;YACxCG;YACAK,YAAYe;YACZT,WAAW;YACX4D;QACF;QAEA,MAAMlF,gBAAgB;YAAE+B;YAAkBd;YAAQH;QAAI;QAEtD,wCAAwC;QACxC,iBAAiB;QACjB,wCAAwC;QAExC,IAAIF,cAAc;YAChB,MAAMV,kBAAkBY;QAC1B;QAEA,OAAOoE;IACT,EAAE,OAAOM,OAAgB;QACvB,MAAMpF,gBAAgBO,KAAKG,GAAG;QAC9B,MAAM0E;IACR;AACF,EAAC"}
|
|
@@ -4,6 +4,11 @@ import type { Collection, SelectFromCollectionSlug } from '../config/types.js';
|
|
|
4
4
|
export type Arguments = {
|
|
5
5
|
collection: Collection;
|
|
6
6
|
currentDepth?: number;
|
|
7
|
+
/**
|
|
8
|
+
* You may pass the document data directly which will skip the `db.findOne` database query.
|
|
9
|
+
* This is useful if you want to use this endpoint solely for running hooks and populating data.
|
|
10
|
+
*/
|
|
11
|
+
data?: Record<string, unknown>;
|
|
7
12
|
depth?: number;
|
|
8
13
|
disableErrors?: boolean;
|
|
9
14
|
draft?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findByID.d.ts","sourceRoot":"","sources":["../../../src/collections/operations/findByID.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,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C9B,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EACV,UAAU,EAEV,wBAAwB,EAEzB,MAAM,oBAAoB,CAAA;AAgB3B,MAAM,MAAM,SAAS,GAAG;IACtB,UAAU,EAAE,UAAU,CAAA;IACtB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,KAAK,CAAC,EAAE,SAAS,CAAA;IACjB,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,QAAQ,CAAC,EAAE,YAAY,CAAA;IACvB,GAAG,EAAE,cAAc,CAAA;IACnB,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAED,eAAO,MAAM,iBAAiB,GAC5B,KAAK,SAAS,cAAc,EAC5B,cAAc,SAAS,OAAO,EAC9B,OAAO,SAAS,wBAAwB,CAAC,KAAK,CAAC,gBAEjC,SAAS,KACtB,OAAO,CAAC,kBAAkB,CAAC,6BAA6B,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,cAAc,CAAC,CA+Q3F,CAAA"}
|
|
@@ -95,7 +95,7 @@ export const findByIDOperation = async (incomingArgs)=>{
|
|
|
95
95
|
if (!findOneArgs.where?.and?.[0]?.id) {
|
|
96
96
|
throw new NotFound(t);
|
|
97
97
|
}
|
|
98
|
-
let result = await req.payload.db.findOne(findOneArgs);
|
|
98
|
+
let result = args.data ?? await req.payload.db.findOne(findOneArgs);
|
|
99
99
|
if (!result) {
|
|
100
100
|
if (!disableErrors) {
|
|
101
101
|
throw new NotFound(req.t);
|