@websolutespa/payload-plugin-bowl 2.0.1 → 3.0.1
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/CHANGELOG.md +23 -4
- package/README.md +1 -1
- package/dist/blocks/MenuItem.js +219 -0
- package/dist/blocks/MenuItem.js.map +1 -0
- package/dist/blocks/index.js +4 -0
- package/dist/blocks/index.js.map +1 -0
- package/dist/blocks/withComponentBlock.js +31 -0
- package/dist/blocks/withComponentBlock.js.map +1 -0
- package/dist/bowl.js +331 -0
- package/dist/bowl.js.map +1 -0
- package/dist/collections/Address.js +7 -0
- package/dist/collections/Address.js.map +1 -0
- package/dist/collections/Category.js +94 -0
- package/dist/collections/Category.js.map +1 -0
- package/dist/collections/ConsentPreference.js +34 -0
- package/dist/collections/ConsentPreference.js.map +1 -0
- package/dist/collections/Continent.js +24 -0
- package/dist/collections/Continent.js.map +1 -0
- package/dist/collections/Country.js +66 -0
- package/dist/collections/Country.js.map +1 -0
- package/dist/collections/CountryZone.js +24 -0
- package/dist/collections/CountryZone.js.map +1 -0
- package/dist/collections/EmailConfig.js +84 -0
- package/dist/collections/EmailConfig.js.map +1 -0
- package/dist/collections/EndUsers.js +24 -0
- package/dist/collections/EndUsers.js.map +1 -0
- package/dist/collections/Label.js +26 -0
- package/dist/collections/Label.js.map +1 -0
- package/dist/collections/Language.js +35 -0
- package/dist/collections/Language.js.map +1 -0
- package/dist/collections/LegalNotice.js +29 -0
- package/dist/collections/LegalNotice.js.map +1 -0
- package/dist/collections/Market.js +106 -0
- package/dist/collections/Market.js.map +1 -0
- package/dist/collections/Media.js +40 -0
- package/dist/collections/Media.js.map +1 -0
- package/dist/collections/Menu.js +49 -0
- package/dist/collections/Menu.js.map +1 -0
- package/dist/collections/Municipality.js +68 -0
- package/dist/collections/Municipality.js.map +1 -0
- package/dist/collections/Province.js +59 -0
- package/dist/collections/Province.js.map +1 -0
- package/dist/collections/Redirect.js +90 -0
- package/dist/collections/Redirect.js.map +1 -0
- package/dist/collections/Region.js +45 -0
- package/dist/collections/Region.js.map +1 -0
- package/dist/collections/SubContinent.js +36 -0
- package/dist/collections/SubContinent.js.map +1 -0
- package/dist/collections/Template.js +79 -0
- package/dist/collections/Template.js.map +1 -0
- package/dist/collections/Users.js +11 -0
- package/dist/collections/Users.js.map +1 -0
- package/dist/components/Category/CategoryMenu.js +47 -0
- package/dist/components/Category/CategoryMenu.js.map +1 -0
- package/dist/components/Category/CategoryTree.js +430 -0
- package/dist/components/Category/CategoryTree.js.map +1 -0
- package/dist/components/Category/CategoryTree.scss +330 -0
- package/dist/components/Category/CategoryTreeRoute.js +51 -0
- package/dist/components/Category/CategoryTreeRoute.js.map +1 -0
- package/dist/components/Category/category.service.js +32 -0
- package/dist/components/Category/category.service.js.map +1 -0
- package/dist/components/DataTree/DataTree.js +281 -0
- package/dist/components/DataTree/DataTree.js.map +1 -0
- package/dist/components/DataTree/DataTree.scss +363 -0
- package/dist/components/DataTree/DataTreeProvider.js +67 -0
- package/dist/components/DataTree/DataTreeProvider.js.map +1 -0
- package/dist/components/DataTree/EventEmitter.js +38 -0
- package/dist/components/DataTree/EventEmitter.js.map +1 -0
- package/dist/components/DataTree/useDataTree.js +52 -0
- package/dist/components/DataTree/useDataTree.js.map +1 -0
- package/dist/components/DecoratedList/DecoratedList.js +17 -0
- package/dist/components/DecoratedList/DecoratedList.js.map +1 -0
- package/dist/components/IconServer/IconServer.js +15 -0
- package/dist/components/IconServer/IconServer.js.map +1 -0
- package/dist/components/IconServer/IconServer.scss +14 -0
- package/dist/components/ImportExport/ImportExportList.js +91 -0
- package/dist/components/ImportExport/ImportExportList.js.map +1 -0
- package/dist/components/ImportExport/ImportExportList.scss +70 -0
- package/dist/components/ImportExport/ImportExportRedirect.js +142 -0
- package/dist/components/ImportExport/ImportExportRedirect.js.map +1 -0
- package/dist/components/ImportExport/ImportModal.js +458 -0
- package/dist/components/ImportExport/ImportModal.js.map +1 -0
- package/dist/components/ImportExport/ImportModal.scss +99 -0
- package/dist/components/ImportExport/types.js +3 -0
- package/dist/components/ImportExport/types.js.map +1 -0
- package/dist/components/LeaveWithoutSaving/LeaveWithoutSaving.js +83 -0
- package/dist/components/LeaveWithoutSaving/LeaveWithoutSaving.js.map +1 -0
- package/dist/components/LeaveWithoutSaving/LeaveWithoutSaving.scss +46 -0
- package/dist/components/LeaveWithoutSaving/usePreventLeave.js +119 -0
- package/dist/components/LeaveWithoutSaving/usePreventLeave.js.map +1 -0
- package/dist/components/LocalizedDescription/LocalizedDescriptionClient.js +15 -0
- package/dist/components/LocalizedDescription/LocalizedDescriptionClient.js.map +1 -0
- package/dist/components/LocalizedDescription/LocalizedDescriptionServer.js +13 -0
- package/dist/components/LocalizedDescription/LocalizedDescriptionServer.js.map +1 -0
- package/dist/components/LogoServer/LogoServer.js +20 -0
- package/dist/components/LogoServer/LogoServer.js.map +1 -0
- package/dist/components/LogoServer/LogoServer.scss +21 -0
- package/dist/core/access/access.js +181 -0
- package/dist/core/access/access.js.map +1 -0
- package/dist/core/access/access.test.js +454 -0
- package/dist/core/access/access.test.js.map +1 -0
- package/dist/core/access/index.js +3 -0
- package/dist/core/access/index.js.map +1 -0
- package/dist/core/api/action.service.js +441 -0
- package/dist/core/api/action.service.js.map +1 -0
- package/dist/core/api/action.service.test.js +218 -0
- package/dist/core/api/action.service.test.js.map +1 -0
- package/dist/core/api/cache.service.js +33 -0
- package/dist/core/api/cache.service.js.map +1 -0
- package/dist/core/api/cache.service.test.js +33 -0
- package/dist/core/api/cache.service.test.js.map +1 -0
- package/dist/core/api/category.service.js +53 -0
- package/dist/core/api/category.service.js.map +1 -0
- package/dist/core/api/collection.service.js +457 -0
- package/dist/core/api/collection.service.js.map +1 -0
- package/dist/core/api/collection.service.test.js +318 -0
- package/dist/core/api/collection.service.test.js.map +1 -0
- package/dist/core/api/email.service.js +84 -0
- package/dist/core/api/email.service.js.map +1 -0
- package/dist/core/api/global.service.js +18 -0
- package/dist/core/api/global.service.js.map +1 -0
- package/dist/core/api/health.service.js +12 -0
- package/dist/core/api/health.service.js.map +1 -0
- package/dist/core/api/index.js +16 -0
- package/dist/core/api/index.js.map +1 -0
- package/dist/core/api/locale.service.js +58 -0
- package/dist/core/api/locale.service.js.map +1 -0
- package/dist/core/api/locale.service.test.js +46 -0
- package/dist/core/api/locale.service.test.js.map +1 -0
- package/dist/core/api/menu.service.js +81 -0
- package/dist/core/api/menu.service.js.map +1 -0
- package/dist/core/api/menu.service.test.js +300 -0
- package/dist/core/api/menu.service.test.js.map +1 -0
- package/dist/core/api/page.service.js +171 -0
- package/dist/core/api/page.service.js.map +1 -0
- package/dist/core/api/page.service.test.js +68 -0
- package/dist/core/api/page.service.test.js.map +1 -0
- package/dist/core/api/pagination.service.js +29 -0
- package/dist/core/api/pagination.service.js.map +1 -0
- package/dist/core/api/pagination.service.test.js +175 -0
- package/dist/core/api/pagination.service.test.js.map +1 -0
- package/dist/core/api/redirect.service.js +106 -0
- package/dist/core/api/redirect.service.js.map +1 -0
- package/dist/core/api/redirect.service.test.js +106 -0
- package/dist/core/api/redirect.service.test.js.map +1 -0
- package/dist/core/api/route.service.js +451 -0
- package/dist/core/api/route.service.js.map +1 -0
- package/dist/core/api/route.service.test.js +214 -0
- package/dist/core/api/route.service.test.js.map +1 -0
- package/dist/core/api/static.service.js +249 -0
- package/dist/core/api/static.service.js.map +1 -0
- package/dist/core/api/static.service.test.js +240 -0
- package/dist/core/api/static.service.test.js.map +1 -0
- package/dist/core/api/store.service.js +336 -0
- package/dist/core/api/store.service.js.map +1 -0
- package/dist/core/api/store.service.test.js +105 -0
- package/dist/core/api/store.service.test.js.map +1 -0
- package/dist/core/api/types.js +21 -0
- package/dist/core/api/types.js.map +1 -0
- package/dist/core/api/utils.js +83 -0
- package/dist/core/api/utils.js.map +1 -0
- package/dist/core/api/where.service.js +231 -0
- package/dist/core/api/where.service.js.map +1 -0
- package/dist/core/collections/index.js +12 -0
- package/dist/core/collections/index.js.map +1 -0
- package/dist/core/collections/withAction.js +91 -0
- package/dist/core/collections/withAction.js.map +1 -0
- package/dist/core/collections/withAction.test.js +68 -0
- package/dist/core/collections/withAction.test.js.map +1 -0
- package/dist/core/collections/withAddress.js +122 -0
- package/dist/core/collections/withAddress.js.map +1 -0
- package/dist/core/collections/withBlock.js +17 -0
- package/dist/core/collections/withBlock.js.map +1 -0
- package/dist/core/collections/withBlock.test.js +68 -0
- package/dist/core/collections/withBlock.test.js.map +1 -0
- package/dist/core/collections/withCollection.js +61 -0
- package/dist/core/collections/withCollection.js.map +1 -0
- package/dist/core/collections/withCollection.test.js +64 -0
- package/dist/core/collections/withCollection.test.js.map +1 -0
- package/dist/core/collections/withEndUser.js +301 -0
- package/dist/core/collections/withEndUser.js.map +1 -0
- package/dist/core/collections/withGlobal.js +27 -0
- package/dist/core/collections/withGlobal.js.map +1 -0
- package/dist/core/collections/withGlobal.test.js +57 -0
- package/dist/core/collections/withGlobal.test.js.map +1 -0
- package/dist/core/collections/withMenu.js +19 -0
- package/dist/core/collections/withMenu.js.map +1 -0
- package/dist/core/collections/withMenu.test.js +63 -0
- package/dist/core/collections/withMenu.test.js.map +1 -0
- package/dist/core/collections/withPage.js +126 -0
- package/dist/core/collections/withPage.js.map +1 -0
- package/dist/core/collections/withPage.test.js +103 -0
- package/dist/core/collections/withPage.test.js.map +1 -0
- package/dist/core/collections/withStaticCollection.js +60 -0
- package/dist/core/collections/withStaticCollection.js.map +1 -0
- package/dist/core/collections/withStaticCollection.test.js +84 -0
- package/dist/core/collections/withStaticCollection.test.js.map +1 -0
- package/dist/core/collections/withUser.js +56 -0
- package/dist/core/collections/withUser.js.map +1 -0
- package/dist/core/decorators/category.js +28 -0
- package/dist/core/decorators/category.js.map +1 -0
- package/dist/core/decorators/components.js +9 -0
- package/dist/core/decorators/components.js.map +1 -0
- package/dist/core/decorators/href.js +25 -0
- package/dist/core/decorators/href.js.map +1 -0
- package/dist/core/decorators/index.js +11 -0
- package/dist/core/decorators/index.js.map +1 -0
- package/dist/core/decorators/localize.js +27 -0
- package/dist/core/decorators/localize.js.map +1 -0
- package/dist/core/decorators/menu.js +246 -0
- package/dist/core/decorators/menu.js.map +1 -0
- package/dist/core/decorators/nav.js +42 -0
- package/dist/core/decorators/nav.js.map +1 -0
- package/dist/core/decorators/rich-text.js +39 -0
- package/dist/core/decorators/rich-text.js.map +1 -0
- package/dist/core/decorators/schema.js +16 -0
- package/dist/core/decorators/schema.js.map +1 -0
- package/dist/core/decorators/upload.js +44 -0
- package/dist/core/decorators/upload.js.map +1 -0
- package/dist/core/encryption/encryption.js +66 -0
- package/dist/core/encryption/encryption.js.map +1 -0
- package/dist/core/encryption/index.js +3 -0
- package/dist/core/encryption/index.js.map +1 -0
- package/dist/core/fields/index.js +28 -0
- package/dist/core/fields/index.js.map +1 -0
- package/dist/core/fields/withAbstract.js +15 -0
- package/dist/core/fields/withAbstract.js.map +1 -0
- package/dist/core/fields/withAbstract.test.js +72 -0
- package/dist/core/fields/withAbstract.test.js.map +1 -0
- package/dist/core/fields/withAnchor.js +56 -0
- package/dist/core/fields/withAnchor.js.map +1 -0
- package/dist/core/fields/withCategory.js +21 -0
- package/dist/core/fields/withCategory.js.map +1 -0
- package/dist/core/fields/withCategory.test.js +63 -0
- package/dist/core/fields/withCategory.test.js.map +1 -0
- package/dist/core/fields/withCheckbox.js +19 -0
- package/dist/core/fields/withCheckbox.js.map +1 -0
- package/dist/core/fields/withCheckbox.test.js +59 -0
- package/dist/core/fields/withCheckbox.test.js.map +1 -0
- package/dist/core/fields/withComponents.js +17 -0
- package/dist/core/fields/withComponents.js.map +1 -0
- package/dist/core/fields/withComponents.test.js +62 -0
- package/dist/core/fields/withComponents.test.js.map +1 -0
- package/dist/core/fields/withDate.js +18 -0
- package/dist/core/fields/withDate.js.map +1 -0
- package/dist/core/fields/withDate.test.js +56 -0
- package/dist/core/fields/withDate.test.js.map +1 -0
- package/dist/core/fields/withDescription.js +15 -0
- package/dist/core/fields/withDescription.js.map +1 -0
- package/dist/core/fields/withDescription.test.js +72 -0
- package/dist/core/fields/withDescription.test.js.map +1 -0
- package/dist/core/fields/withId.js +19 -0
- package/dist/core/fields/withId.js.map +1 -0
- package/dist/core/fields/withId.test.js +61 -0
- package/dist/core/fields/withId.test.js.map +1 -0
- package/dist/core/fields/withIsActive.js +15 -0
- package/dist/core/fields/withIsActive.js.map +1 -0
- package/dist/core/fields/withIsActive.test.js +59 -0
- package/dist/core/fields/withIsActive.test.js.map +1 -0
- package/dist/core/fields/withIsDefault.js +15 -0
- package/dist/core/fields/withIsDefault.js.map +1 -0
- package/dist/core/fields/withIsDefault.test.js +59 -0
- package/dist/core/fields/withIsDefault.test.js.map +1 -0
- package/dist/core/fields/withLink.js +116 -0
- package/dist/core/fields/withLink.js.map +1 -0
- package/dist/core/fields/withLink.test.js +144 -0
- package/dist/core/fields/withLink.test.js.map +1 -0
- package/dist/core/fields/withMarkets.js +21 -0
- package/dist/core/fields/withMarkets.js.map +1 -0
- package/dist/core/fields/withMarkets.test.js +65 -0
- package/dist/core/fields/withMarkets.test.js.map +1 -0
- package/dist/core/fields/withMedia.js +20 -0
- package/dist/core/fields/withMedia.js.map +1 -0
- package/dist/core/fields/withMedia.test.js +41 -0
- package/dist/core/fields/withMedia.test.js.map +1 -0
- package/dist/core/fields/withMedias.js +25 -0
- package/dist/core/fields/withMedias.js.map +1 -0
- package/dist/core/fields/withMedias.test.js +46 -0
- package/dist/core/fields/withMedias.test.js.map +1 -0
- package/dist/core/fields/withName.js +17 -0
- package/dist/core/fields/withName.js.map +1 -0
- package/dist/core/fields/withName.test.js +59 -0
- package/dist/core/fields/withName.test.js.map +1 -0
- package/dist/core/fields/withNav.js +28 -0
- package/dist/core/fields/withNav.js.map +1 -0
- package/dist/core/fields/withNavs.js +53 -0
- package/dist/core/fields/withNavs.js.map +1 -0
- package/dist/core/fields/withOrder.js +80 -0
- package/dist/core/fields/withOrder.js.map +1 -0
- package/dist/core/fields/withOrder.test.js +56 -0
- package/dist/core/fields/withOrder.test.js.map +1 -0
- package/dist/core/fields/withRelated.js +18 -0
- package/dist/core/fields/withRelated.js.map +1 -0
- package/dist/core/fields/withRelated.test.js +62 -0
- package/dist/core/fields/withRelated.test.js.map +1 -0
- package/dist/core/fields/withRichText.js +68 -0
- package/dist/core/fields/withRichText.js.map +1 -0
- package/dist/core/fields/withRichText.test.js +72 -0
- package/dist/core/fields/withRichText.test.js.map +1 -0
- package/dist/core/fields/withRoles.js +27 -0
- package/dist/core/fields/withRoles.js.map +1 -0
- package/dist/core/fields/withRoles.test.js +49 -0
- package/dist/core/fields/withRoles.test.js.map +1 -0
- package/dist/core/fields/withSelect.js +23 -0
- package/dist/core/fields/withSelect.js.map +1 -0
- package/dist/core/fields/withSelect.test.js +59 -0
- package/dist/core/fields/withSelect.test.js.map +1 -0
- package/dist/core/fields/withSeoWeight.js +19 -0
- package/dist/core/fields/withSeoWeight.js.map +1 -0
- package/dist/core/fields/withSlug.js +33 -0
- package/dist/core/fields/withSlug.js.map +1 -0
- package/dist/core/fields/withSlug.test.js +71 -0
- package/dist/core/fields/withSlug.test.js.map +1 -0
- package/dist/core/fields/withTemplate.js +49 -0
- package/dist/core/fields/withTemplate.js.map +1 -0
- package/dist/core/fields/withTemplate.test.js +93 -0
- package/dist/core/fields/withTemplate.test.js.map +1 -0
- package/dist/core/fields/withTenants.js +21 -0
- package/dist/core/fields/withTenants.js.map +1 -0
- package/dist/core/fields/withTenants.test.js +42 -0
- package/dist/core/fields/withTenants.test.js.map +1 -0
- package/dist/core/fields/withText.js +18 -0
- package/dist/core/fields/withText.js.map +1 -0
- package/dist/core/fields/withText.test.js +56 -0
- package/dist/core/fields/withText.test.js.map +1 -0
- package/dist/core/fields/withTitle.js +17 -0
- package/dist/core/fields/withTitle.js.map +1 -0
- package/dist/core/fields/withTitle.test.js +58 -0
- package/dist/core/fields/withTitle.test.js.map +1 -0
- package/dist/core/index.js +11 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/logger/index.js +3 -0
- package/dist/core/logger/index.js.map +1 -0
- package/dist/core/logger/logger.js +9 -0
- package/dist/core/logger/logger.js.map +1 -0
- package/dist/core/translations/index.js +3 -0
- package/dist/core/translations/index.js.map +1 -0
- package/dist/core/translations/translations.js +137 -0
- package/dist/core/translations/translations.js.map +1 -0
- package/dist/core/translations/translations.test.js +72 -0
- package/dist/core/translations/translations.test.js.map +1 -0
- package/dist/core/utils/findByIDHandler.js +28 -0
- package/dist/core/utils/findByIDHandler.js.map +1 -0
- package/dist/core/utils/findHandler.js +31 -0
- package/dist/core/utils/findHandler.js.map +1 -0
- package/dist/core/utils/getPreviewURL.js +45 -0
- package/dist/core/utils/getPreviewURL.js.map +1 -0
- package/dist/core/utils/getRequestCollection.js +49 -0
- package/dist/core/utils/getRequestCollection.js.map +1 -0
- package/dist/core/utils/index.js +7 -0
- package/dist/core/utils/index.js.map +1 -0
- package/dist/core/utils/mergeCollections.js +18 -0
- package/dist/core/utils/mergeCollections.js.map +1 -0
- package/dist/core/utils/mergeFields.js +20 -0
- package/dist/core/utils/mergeFields.js.map +1 -0
- package/dist/core/utils/mergeGlobals.js +17 -0
- package/dist/core/utils/mergeGlobals.js.map +1 -0
- package/dist/core/utils/richText.js +29 -0
- package/dist/core/utils/richText.js.map +1 -0
- package/dist/core/utils/sortByGroup.js +36 -0
- package/dist/core/utils/sortByGroup.js.map +1 -0
- package/dist/debug.js +25 -0
- package/dist/debug.js.map +1 -0
- package/dist/declaration.d.js +3 -0
- package/dist/declaration.d.js.map +1 -0
- package/dist/exports/client.d.ts +36 -0
- package/dist/exports/client.d.ts.map +1 -0
- package/dist/exports/client.js +8 -0
- package/dist/exports/client.js.map +1 -0
- package/dist/exports/rsc.d.ts +18 -0
- package/dist/exports/rsc.d.ts.map +1 -0
- package/dist/exports/rsc.js +5 -0
- package/dist/exports/rsc.js.map +1 -0
- package/dist/fields/color-picker/ColorCell.js +19 -0
- package/dist/fields/color-picker/ColorCell.js.map +1 -0
- package/dist/fields/color-picker/ColorField.js +131 -0
- package/dist/fields/color-picker/ColorField.js.map +1 -0
- package/dist/fields/color-picker/index.js +26 -0
- package/dist/fields/color-picker/index.js.map +1 -0
- package/dist/fields/color-picker/styles.scss +113 -0
- package/dist/fields/color-picker/utils.js +6 -0
- package/dist/fields/color-picker/utils.js.map +1 -0
- package/dist/fields/index.js +3 -0
- package/dist/fields/index.js.map +1 -0
- package/dist/globals/App.js +97 -0
- package/dist/globals/App.js.map +1 -0
- package/dist/globals/Locale.js +82 -0
- package/dist/globals/Locale.js.map +1 -0
- package/dist/globals/LocaleRowLabel.js +16 -0
- package/dist/globals/LocaleRowLabel.js.map +1 -0
- package/dist/index.d.ts +891 -844
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -9263
- package/dist/index.js.map +1 -0
- package/dist/mapper.js +199 -0
- package/dist/mapper.js.map +1 -0
- package/dist/options.js +76 -0
- package/dist/options.js.map +1 -0
- package/dist/test/blocks/blocks.js +13 -0
- package/dist/test/blocks/blocks.js.map +1 -0
- package/dist/test/collections/ActionCollection.js +12 -0
- package/dist/test/collections/ActionCollection.js.map +1 -0
- package/dist/test/collections/AdminCollection.js +18 -0
- package/dist/test/collections/AdminCollection.js.map +1 -0
- package/dist/test/collections/BlockCollection.js +16 -0
- package/dist/test/collections/BlockCollection.js.map +1 -0
- package/dist/test/collections/Collection.js +12 -0
- package/dist/test/collections/Collection.js.map +1 -0
- package/dist/test/collections/FieldCollection.js +84 -0
- package/dist/test/collections/FieldCollection.js.map +1 -0
- package/dist/test/collections/GlobalCollection.js +12 -0
- package/dist/test/collections/GlobalCollection.js.map +1 -0
- package/dist/test/collections/LinkCollection.js +12 -0
- package/dist/test/collections/LinkCollection.js.map +1 -0
- package/dist/test/collections/MenuCollection.js +12 -0
- package/dist/test/collections/MenuCollection.js.map +1 -0
- package/dist/test/collections/PageCollection.js +12 -0
- package/dist/test/collections/PageCollection.js.map +1 -0
- package/dist/test/collections/RoleCollection.js +19 -0
- package/dist/test/collections/RoleCollection.js.map +1 -0
- package/dist/test/collections/RoleFieldCollection.js +40 -0
- package/dist/test/collections/RoleFieldCollection.js.map +1 -0
- package/dist/test/collections/StaticCollection.js +56 -0
- package/dist/test/collections/StaticCollection.js.map +1 -0
- package/dist/test/collections/StorePageCollection.js +12 -0
- package/dist/test/collections/StorePageCollection.js.map +1 -0
- package/dist/test/collections/TenantCollection.js +22 -0
- package/dist/test/collections/TenantCollection.js.map +1 -0
- package/dist/test/collections/TranslationCollection.js +16 -0
- package/dist/test/collections/TranslationCollection.js.map +1 -0
- package/dist/test/collections/TypeACollection.js +18 -0
- package/dist/test/collections/TypeACollection.js.map +1 -0
- package/dist/test/collections/TypeBCollection.js +18 -0
- package/dist/test/collections/TypeBCollection.js.map +1 -0
- package/dist/test/collections/actions/NewsletterAction.js +29 -0
- package/dist/test/collections/actions/NewsletterAction.js.map +1 -0
- package/dist/test/collections/actions/RegisterAction.js +44 -0
- package/dist/test/collections/actions/RegisterAction.js.map +1 -0
- package/dist/test/collections/users/EndUsers.js +40 -0
- package/dist/test/collections/users/EndUsers.js.map +1 -0
- package/dist/test/collections/users/Users.js +20 -0
- package/dist/test/collections/users/Users.js.map +1 -0
- package/dist/test/index.js +32 -0
- package/dist/test/index.js.map +1 -0
- package/dist/test/payload.config.js +106 -0
- package/dist/test/payload.config.js.map +1 -0
- package/dist/test/utils.js +52 -0
- package/dist/test/utils.js.map +1 -0
- package/dist/translations.js +467 -0
- package/dist/translations.js.map +1 -0
- package/dist/types.js +31 -0
- package/dist/types.js.map +1 -0
- package/package.json +119 -37
- package/scss/styles.scss +0 -1
- package/dist/index.css +0 -796
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { deepMerge, eachDataField, HttpStatus, withCollectionHook } from '@websolutespa/payload-utils';
|
|
2
|
+
import { ResponseError, ResponseSuccess } from '@websolutespa/payload-utils/server';
|
|
3
|
+
import { addDataAndFileToRequest, AuthenticationError } from 'payload';
|
|
4
|
+
import { toField } from '../../mapper';
|
|
5
|
+
import { options } from '../../options';
|
|
6
|
+
import { hasRole, isAdmin, isAdminOrSelf } from '../access';
|
|
7
|
+
import { sendEmail } from '../api/email.service';
|
|
8
|
+
import { decrypt, encrypt } from '../encryption';
|
|
9
|
+
import { translateCollection } from '../translations';
|
|
10
|
+
import { mergeFields } from '../utils';
|
|
11
|
+
export const EndUserDefault = {
|
|
12
|
+
access: {
|
|
13
|
+
create: ()=>false,
|
|
14
|
+
read: isAdminOrSelf,
|
|
15
|
+
update: isAdminOrSelf,
|
|
16
|
+
delete: ()=>false,
|
|
17
|
+
unlock: isAdmin
|
|
18
|
+
},
|
|
19
|
+
admin: {
|
|
20
|
+
useAsTitle: 'email',
|
|
21
|
+
group: options.group.users,
|
|
22
|
+
defaultColumns: [
|
|
23
|
+
'email'
|
|
24
|
+
]
|
|
25
|
+
},
|
|
26
|
+
auth: {
|
|
27
|
+
useAPIKey: false,
|
|
28
|
+
lockTime: 10 * 60 * 1000,
|
|
29
|
+
maxLoginAttempts: 5,
|
|
30
|
+
tokenExpiration: 2 * 60 * 60,
|
|
31
|
+
verify: false
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* End User before login hook.
|
|
36
|
+
*
|
|
37
|
+
* @param req - Full express request.
|
|
38
|
+
* @param user - User being logged in.
|
|
39
|
+
* @returns The logged in user.
|
|
40
|
+
* @throws {AuthenticationError} If the endUser does not have the role 'user' associated (this ensure endUser cannot authenticate before optin).
|
|
41
|
+
*/ const beforeLoginHook = async ({ req, user })=>{
|
|
42
|
+
if (!hasRole(user, options.roles.User)) {
|
|
43
|
+
throw new AuthenticationError();
|
|
44
|
+
}
|
|
45
|
+
return user;
|
|
46
|
+
};
|
|
47
|
+
export const endUserForgotPost = (slug)=>({
|
|
48
|
+
path: '/forgot',
|
|
49
|
+
method: 'post',
|
|
50
|
+
handler: async (req)=>{
|
|
51
|
+
try {
|
|
52
|
+
const { payload, user } = req;
|
|
53
|
+
if (!hasRole(user, options.roles.Guest)) {
|
|
54
|
+
throw new AuthenticationError();
|
|
55
|
+
}
|
|
56
|
+
await addDataAndFileToRequest(req);
|
|
57
|
+
const { email } = req.data;
|
|
58
|
+
if (!email) {
|
|
59
|
+
throw {
|
|
60
|
+
status: 400,
|
|
61
|
+
message: 'Bad Request: email is missing'
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const token = await payload.forgotPassword({
|
|
65
|
+
collection: slug,
|
|
66
|
+
data: {
|
|
67
|
+
email
|
|
68
|
+
},
|
|
69
|
+
disableEmail: true
|
|
70
|
+
});
|
|
71
|
+
// console.log('token', token);
|
|
72
|
+
if (!token) {
|
|
73
|
+
// !!! failing silently, we don't want to let know if email exhist.
|
|
74
|
+
return ResponseSuccess({
|
|
75
|
+
code: 'SENT'
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
const actionId = encrypt(token);
|
|
79
|
+
const actionSlug = slug;
|
|
80
|
+
await sendEmail(req, 'forgot', (options)=>{
|
|
81
|
+
const html = typeof options.html === 'string' ? options.html : '';
|
|
82
|
+
options.html = html.replace(/(\{(actionId|actionSlug)\})/gm, (m, g1, g2)=>g2 === 'actionId' ? actionId : actionSlug);
|
|
83
|
+
return options;
|
|
84
|
+
});
|
|
85
|
+
return ResponseSuccess({
|
|
86
|
+
code: 'SENT',
|
|
87
|
+
actionId
|
|
88
|
+
});
|
|
89
|
+
} catch (error) {
|
|
90
|
+
console.error('withEndUser.endUserForgotPost.error', error);
|
|
91
|
+
return ResponseError(error);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
export const endUserResetPost = (slug)=>({
|
|
96
|
+
path: '/reset',
|
|
97
|
+
method: 'post',
|
|
98
|
+
handler: async (req)=>{
|
|
99
|
+
try {
|
|
100
|
+
const { payload, user } = req;
|
|
101
|
+
if (!hasRole(user, options.roles.Guest)) {
|
|
102
|
+
throw new AuthenticationError();
|
|
103
|
+
}
|
|
104
|
+
await addDataAndFileToRequest(req);
|
|
105
|
+
const { actionId } = req.data;
|
|
106
|
+
if (!actionId) {
|
|
107
|
+
throw {
|
|
108
|
+
status: 400,
|
|
109
|
+
message: 'Bad Request: actionId is missing'
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
const { password } = req.data;
|
|
113
|
+
if (!password) {
|
|
114
|
+
throw {
|
|
115
|
+
status: 400,
|
|
116
|
+
message: 'Bad Request: password is missing'
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
const token = decrypt(actionId);
|
|
120
|
+
const result = await payload.resetPassword({
|
|
121
|
+
collection: slug,
|
|
122
|
+
data: {
|
|
123
|
+
password,
|
|
124
|
+
token
|
|
125
|
+
},
|
|
126
|
+
overrideAccess: true
|
|
127
|
+
});
|
|
128
|
+
return ResponseSuccess(result);
|
|
129
|
+
} catch (error) {
|
|
130
|
+
console.error('withEndUser.endUserResetPost.error', error);
|
|
131
|
+
return ResponseError(error);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
export const endUserPasswordPost = (slug)=>({
|
|
136
|
+
path: '/password',
|
|
137
|
+
method: 'post',
|
|
138
|
+
handler: async (req)=>{
|
|
139
|
+
try {
|
|
140
|
+
const { payload, user } = req;
|
|
141
|
+
if (!hasRole(user, options.roles.User)) {
|
|
142
|
+
throw new AuthenticationError();
|
|
143
|
+
}
|
|
144
|
+
await addDataAndFileToRequest(req);
|
|
145
|
+
const { oldPassword } = req.data;
|
|
146
|
+
if (!oldPassword) {
|
|
147
|
+
throw {
|
|
148
|
+
status: 400,
|
|
149
|
+
message: 'Bad Request: oldPassword is missing'
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
const { newPassword } = req.data;
|
|
153
|
+
if (!newPassword) {
|
|
154
|
+
throw {
|
|
155
|
+
status: 400,
|
|
156
|
+
message: 'Bad Request: newPassword is missing'
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
if (!user.email) {
|
|
160
|
+
throw {
|
|
161
|
+
status: HttpStatus.UNPROCESSABLE_ENTITY,
|
|
162
|
+
message: 'Unprocessable Entity: email is missing'
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
const oldPasswordResult = await payload.login({
|
|
166
|
+
collection: slug,
|
|
167
|
+
data: {
|
|
168
|
+
email: user.email,
|
|
169
|
+
password: oldPassword
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
if (!oldPasswordResult.user || !oldPasswordResult.token) {
|
|
173
|
+
throw {
|
|
174
|
+
status: 401,
|
|
175
|
+
message: 'Unauthorized'
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
const token = await payload.forgotPassword({
|
|
179
|
+
collection: slug,
|
|
180
|
+
data: {
|
|
181
|
+
email: oldPasswordResult.user.email
|
|
182
|
+
},
|
|
183
|
+
disableEmail: true
|
|
184
|
+
});
|
|
185
|
+
if (!token) {
|
|
186
|
+
throw {
|
|
187
|
+
status: 500,
|
|
188
|
+
message: 'Cannot create reset token'
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
const result = await payload.resetPassword({
|
|
192
|
+
collection: slug,
|
|
193
|
+
data: {
|
|
194
|
+
password: newPassword,
|
|
195
|
+
token
|
|
196
|
+
},
|
|
197
|
+
overrideAccess: true
|
|
198
|
+
});
|
|
199
|
+
return ResponseSuccess(result);
|
|
200
|
+
} catch (error) {
|
|
201
|
+
console.error('withEndUser.endUserForgotPost.error', error);
|
|
202
|
+
return ResponseError(error);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
export const endUserExistPost = (slug)=>({
|
|
207
|
+
path: '/exist',
|
|
208
|
+
method: 'post',
|
|
209
|
+
handler: async (req)=>{
|
|
210
|
+
try {
|
|
211
|
+
const { payload } = req;
|
|
212
|
+
await addDataAndFileToRequest(req);
|
|
213
|
+
const { email } = req.data;
|
|
214
|
+
if (!email) {
|
|
215
|
+
throw {
|
|
216
|
+
status: 400,
|
|
217
|
+
message: 'Bad Request: email is missing'
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
const existingEndUsers = await payload.find({
|
|
221
|
+
collection: slug,
|
|
222
|
+
where: {
|
|
223
|
+
email: {
|
|
224
|
+
equals: email.toLowerCase()
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
overrideAccess: true
|
|
228
|
+
});
|
|
229
|
+
const existingEndUser = existingEndUsers.totalDocs > 0 ? existingEndUsers.docs[0] : undefined;
|
|
230
|
+
const exist = existingEndUser && hasRole(existingEndUser, options.roles.User);
|
|
231
|
+
return ResponseSuccess({
|
|
232
|
+
exist
|
|
233
|
+
});
|
|
234
|
+
} catch (error) {
|
|
235
|
+
console.error('withEndUser.endUserExistPost.error', error);
|
|
236
|
+
return ResponseError(error);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
export const withEndUser = (config)=>{
|
|
241
|
+
const endUserConfig = deepMerge(EndUserDefault, config);
|
|
242
|
+
const endUserFields = endUserConfig.fields;
|
|
243
|
+
/**
|
|
244
|
+
* ATTENTION !
|
|
245
|
+
* Automatically setting defaultValue for DataField
|
|
246
|
+
*/ eachDataField(endUserFields, (field)=>{
|
|
247
|
+
if (field.type !== 'group' && field.required) {
|
|
248
|
+
switch(field.type){
|
|
249
|
+
case 'number':
|
|
250
|
+
field.defaultValue = 0;
|
|
251
|
+
break;
|
|
252
|
+
default:
|
|
253
|
+
field.defaultValue = '-';
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
const defaultFields = [
|
|
258
|
+
toField({
|
|
259
|
+
type: 'withRoles',
|
|
260
|
+
roles: options.rolesEndUser,
|
|
261
|
+
defaultValue: options.roles.Guest
|
|
262
|
+
}),
|
|
263
|
+
{
|
|
264
|
+
name: 'consentPreferences',
|
|
265
|
+
type: 'array',
|
|
266
|
+
label: 'Consent Preferences',
|
|
267
|
+
fields: [
|
|
268
|
+
{
|
|
269
|
+
name: 'consentPreference',
|
|
270
|
+
label: 'Consent Preference',
|
|
271
|
+
type: 'relationship',
|
|
272
|
+
relationTo: options.slug.consentPreference
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
name: 'date',
|
|
276
|
+
type: 'date',
|
|
277
|
+
label: 'Date'
|
|
278
|
+
}
|
|
279
|
+
]
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
type: 'checkbox',
|
|
283
|
+
name: 'emailVerified'
|
|
284
|
+
}
|
|
285
|
+
];
|
|
286
|
+
endUserConfig.fields = mergeFields(defaultFields, endUserConfig.fields, true);
|
|
287
|
+
// !!! todo check if
|
|
288
|
+
if (!endUserConfig.endpoints) {
|
|
289
|
+
endUserConfig.endpoints = [
|
|
290
|
+
endUserForgotPost(endUserConfig.slug),
|
|
291
|
+
endUserResetPost(endUserConfig.slug),
|
|
292
|
+
endUserPasswordPost(endUserConfig.slug),
|
|
293
|
+
endUserExistPost(endUserConfig.slug)
|
|
294
|
+
];
|
|
295
|
+
}
|
|
296
|
+
withCollectionHook(endUserConfig, 'beforeLogin', beforeLoginHook);
|
|
297
|
+
translateCollection(endUserConfig);
|
|
298
|
+
return endUserConfig;
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
//# sourceMappingURL=withEndUser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/core/collections/withEndUser.ts"],"sourcesContent":["import { IEndUser } from '@websolutespa/bom-core';\r\nimport { deepMerge, eachDataField, HttpStatus, withCollectionHook } from '@websolutespa/payload-utils';\r\nimport { ResponseError, ResponseSuccess } from '@websolutespa/payload-utils/server';\r\nimport { addDataAndFileToRequest, AdminViewConfig, AuthenticationError, CollectionBeforeLoginHook, CollectionConfig, CollectionSlug, Endpoint, Field, PaginatedDocs, PayloadRequest } from 'payload';\r\nimport { toField } from '../../mapper';\r\nimport { options } from '../../options';\r\nimport { BowlField } from '../../types';\r\nimport { hasRole, isAdmin, isAdminOrSelf } from '../access';\r\nimport { sendEmail } from '../api/email.service';\r\nimport { decrypt, encrypt } from '../encryption';\r\nimport { translateCollection } from '../translations';\r\nimport { mergeFields } from '../utils';\r\n\r\nexport type WithEndUserProps = (Omit<CollectionConfig, 'fields'> & {\r\n fields?: BowlField[];\r\n views?: Record<string, AdminViewConfig>;\r\n});\r\nexport type WithEndUser = WithEndUserProps & { type: 'withEndUser' };\r\n\r\nexport const EndUserDefault: Partial<CollectionConfig> = {\r\n access: {\r\n create: (): boolean => false,\r\n read: isAdminOrSelf,\r\n update: isAdminOrSelf,\r\n delete: (): boolean => false,\r\n unlock: isAdmin,\r\n },\r\n admin: {\r\n useAsTitle: 'email',\r\n group: options.group.users,\r\n defaultColumns: [\r\n 'email',\r\n ],\r\n },\r\n auth: {\r\n useAPIKey: false, // Payload Authentication provides for API keys to be set on each user within the Authentication-enabled Collection.\r\n lockTime: 10 * 60 * 1000, // (10min) Time period to allow the max login attempts\r\n maxLoginAttempts: 5, // Automatically lock a user out after X amount of failed logins\r\n tokenExpiration: 2 * 60 * 60, // (2hrs) How many seconds to keep the user logged in\r\n verify: false, // Require email verification before being allowed to authenticate\r\n // More options are available\r\n },\r\n};\r\n\r\n/**\r\n * End User before login hook.\r\n *\r\n * @param req - Full express request.\r\n * @param user - User being logged in.\r\n * @returns The logged in user.\r\n * @throws {AuthenticationError} If the endUser does not have the role 'user' associated (this ensure endUser cannot authenticate before optin).\r\n */\r\nconst beforeLoginHook: CollectionBeforeLoginHook = async ({\r\n req, // full express request\r\n user, // user being logged in\r\n}) => {\r\n if (!hasRole(user, options.roles.User)) {\r\n throw new AuthenticationError();\r\n }\r\n return user;\r\n};\r\n\r\nexport const endUserForgotPost: ((slug: string) => Endpoint) = (slug: string) => ({\r\n path: '/forgot',\r\n method: 'post',\r\n handler: async (req: PayloadRequest) => {\r\n try {\r\n const { payload, user } = req;\r\n if (!hasRole(user, options.roles.Guest)) {\r\n throw new AuthenticationError();\r\n }\r\n await addDataAndFileToRequest(req);\r\n const { email } = req.data as { email: string };\r\n if (!email) {\r\n throw { status: 400, message: 'Bad Request: email is missing' };\r\n }\r\n const token = await payload.forgotPassword({\r\n collection: slug,\r\n data: {\r\n email,\r\n },\r\n disableEmail: true,\r\n });\r\n // console.log('token', token);\r\n if (!token) {\r\n // !!! failing silently, we don't want to let know if email exhist.\r\n return ResponseSuccess({ code: 'SENT' });\r\n }\r\n const actionId = encrypt(token as string);\r\n const actionSlug = slug;\r\n await sendEmail(req, 'forgot', (options) => {\r\n const html = typeof options.html === 'string' ? options.html : '';\r\n options.html = html.replace(/(\\{(actionId|actionSlug)\\})/gm, (m, g1, g2) => g2 === 'actionId' ? actionId : actionSlug);\r\n return options;\r\n });\r\n return ResponseSuccess({ code: 'SENT', actionId });\r\n } catch (error: any) {\r\n console.error('withEndUser.endUserForgotPost.error', error);\r\n return ResponseError(error);\r\n }\r\n },\r\n});\r\n\r\nexport const endUserResetPost: ((slug: string) => Endpoint) = (slug: string) => ({\r\n path: '/reset',\r\n method: 'post',\r\n handler: async (req: PayloadRequest) => {\r\n try {\r\n const { payload, user } = req;\r\n if (!hasRole(user, options.roles.Guest)) {\r\n throw new AuthenticationError();\r\n }\r\n await addDataAndFileToRequest(req);\r\n const { actionId } = req.data as { actionId: string };\r\n if (!actionId) {\r\n throw { status: 400, message: 'Bad Request: actionId is missing' };\r\n }\r\n const { password } = req.data as { password: string };\r\n if (!password) {\r\n throw { status: 400, message: 'Bad Request: password is missing' };\r\n }\r\n const token = decrypt(actionId);\r\n const result = await payload.resetPassword({\r\n collection: slug,\r\n data: {\r\n password,\r\n token,\r\n },\r\n overrideAccess: true,\r\n });\r\n return ResponseSuccess(result);\r\n } catch (error: any) {\r\n console.error('withEndUser.endUserResetPost.error', error);\r\n return ResponseError(error);\r\n }\r\n },\r\n});\r\n\r\nexport const endUserPasswordPost: ((slug: string) => Endpoint) = (slug: string) => ({\r\n path: '/password',\r\n method: 'post',\r\n handler: async (req: PayloadRequest) => {\r\n try {\r\n const { payload, user } = req;\r\n if (!hasRole(user, options.roles.User)) {\r\n throw new AuthenticationError();\r\n }\r\n await addDataAndFileToRequest(req);\r\n const { oldPassword } = req.data as { oldPassword: string };\r\n if (!oldPassword) {\r\n throw { status: 400, message: 'Bad Request: oldPassword is missing' };\r\n }\r\n const { newPassword } = req.data as { newPassword: string };\r\n if (!newPassword) {\r\n throw { status: 400, message: 'Bad Request: newPassword is missing' };\r\n }\r\n if (!user.email) {\r\n throw { status: HttpStatus.UNPROCESSABLE_ENTITY, message: 'Unprocessable Entity: email is missing' };\r\n }\r\n const oldPasswordResult = await payload.login({\r\n collection: slug,\r\n data: {\r\n email: user.email,\r\n password: oldPassword,\r\n },\r\n });\r\n if (!oldPasswordResult.user || !oldPasswordResult.token) {\r\n throw { status: 401, message: 'Unauthorized' };\r\n }\r\n const token = await payload.forgotPassword({\r\n collection: slug,\r\n data: {\r\n email: oldPasswordResult.user.email!,\r\n },\r\n disableEmail: true,\r\n });\r\n if (!token) {\r\n throw { status: 500, message: 'Cannot create reset token' };\r\n }\r\n const result = await payload.resetPassword({\r\n collection: slug,\r\n data: {\r\n password: newPassword,\r\n token,\r\n },\r\n overrideAccess: true,\r\n });\r\n return ResponseSuccess(result);\r\n\r\n } catch (error: any) {\r\n console.error('withEndUser.endUserForgotPost.error', error);\r\n return ResponseError(error);\r\n }\r\n },\r\n});\r\n\r\nexport const endUserExistPost: ((slug: CollectionSlug) => Endpoint) = (slug: CollectionSlug) => ({\r\n path: '/exist',\r\n method: 'post',\r\n handler: async (req: PayloadRequest) => {\r\n try {\r\n const { payload } = req;\r\n await addDataAndFileToRequest(req);\r\n const { email } = req.data as { email: string };\r\n if (!email) {\r\n throw { status: 400, message: 'Bad Request: email is missing' };\r\n }\r\n const existingEndUsers = await payload.find({\r\n collection: slug,\r\n where: {\r\n email: {\r\n equals: email.toLowerCase(),\r\n },\r\n },\r\n overrideAccess: true,\r\n }) as PaginatedDocs<IEndUser>;\r\n const existingEndUser = existingEndUsers.totalDocs > 0 ? existingEndUsers.docs[0] : undefined;\r\n const exist = (existingEndUser && hasRole(existingEndUser, options.roles.User));\r\n return ResponseSuccess({ exist });\r\n } catch (error: any) {\r\n console.error('withEndUser.endUserExistPost.error', error);\r\n return ResponseError(error);\r\n }\r\n },\r\n});\r\n\r\nexport const withEndUser = (config: WithEndUserProps): CollectionConfig => {\r\n const endUserConfig = deepMerge(EndUserDefault, config);\r\n const endUserFields = endUserConfig.fields;\r\n /**\r\n * ATTENTION !\r\n * Automatically setting defaultValue for DataField\r\n */\r\n eachDataField(endUserFields, (field) => {\r\n if (field.type !== 'group' && field.required) {\r\n switch (field.type) {\r\n case 'number':\r\n field.defaultValue = 0;\r\n break;\r\n default:\r\n field.defaultValue = '-';\r\n }\r\n }\r\n });\r\n const defaultFields: Field[] = [\r\n toField({\r\n type: 'withRoles',\r\n roles: options.rolesEndUser,\r\n defaultValue: options.roles.Guest,\r\n }),\r\n {\r\n name: 'consentPreferences',\r\n type: 'array',\r\n label: 'Consent Preferences',\r\n fields: [\r\n {\r\n name: 'consentPreference',\r\n label: 'Consent Preference',\r\n type: 'relationship',\r\n relationTo: options.slug.consentPreference,\r\n },\r\n {\r\n name: 'date',\r\n type: 'date',\r\n label: 'Date',\r\n },\r\n ],\r\n },\r\n { type: 'checkbox', name: 'emailVerified' },\r\n ];\r\n endUserConfig.fields = mergeFields(defaultFields, endUserConfig.fields, true);\r\n // !!! todo check if\r\n if (!endUserConfig.endpoints) {\r\n endUserConfig.endpoints = [\r\n endUserForgotPost(endUserConfig.slug),\r\n endUserResetPost(endUserConfig.slug),\r\n endUserPasswordPost(endUserConfig.slug),\r\n endUserExistPost(endUserConfig.slug),\r\n ];\r\n }\r\n withCollectionHook(endUserConfig, 'beforeLogin', beforeLoginHook);\r\n translateCollection(endUserConfig);\r\n return endUserConfig;\r\n};\r\n"],"names":["deepMerge","eachDataField","HttpStatus","withCollectionHook","ResponseError","ResponseSuccess","addDataAndFileToRequest","AuthenticationError","toField","options","hasRole","isAdmin","isAdminOrSelf","sendEmail","decrypt","encrypt","translateCollection","mergeFields","EndUserDefault","access","create","read","update","delete","unlock","admin","useAsTitle","group","users","defaultColumns","auth","useAPIKey","lockTime","maxLoginAttempts","tokenExpiration","verify","beforeLoginHook","req","user","roles","User","endUserForgotPost","slug","path","method","handler","payload","Guest","email","data","status","message","token","forgotPassword","collection","disableEmail","code","actionId","actionSlug","html","replace","m","g1","g2","error","console","endUserResetPost","password","result","resetPassword","overrideAccess","endUserPasswordPost","oldPassword","newPassword","UNPROCESSABLE_ENTITY","oldPasswordResult","login","endUserExistPost","existingEndUsers","find","where","equals","toLowerCase","existingEndUser","totalDocs","docs","undefined","exist","withEndUser","config","endUserConfig","endUserFields","fields","field","type","required","defaultValue","defaultFields","rolesEndUser","name","label","relationTo","consentPreference","endpoints"],"mappings":"AACA,SAASA,SAAS,EAAEC,aAAa,EAAEC,UAAU,EAAEC,kBAAkB,QAAQ,8BAA8B;AACvG,SAASC,aAAa,EAAEC,eAAe,QAAQ,qCAAqC;AACpF,SAASC,uBAAuB,EAAmBC,mBAAmB,QAAqH,UAAU;AACrM,SAASC,OAAO,QAAQ,eAAe;AACvC,SAASC,OAAO,QAAQ,gBAAgB;AAExC,SAASC,OAAO,EAAEC,OAAO,EAAEC,aAAa,QAAQ,YAAY;AAC5D,SAASC,SAAS,QAAQ,uBAAuB;AACjD,SAASC,OAAO,EAAEC,OAAO,QAAQ,gBAAgB;AACjD,SAASC,mBAAmB,QAAQ,kBAAkB;AACtD,SAASC,WAAW,QAAQ,WAAW;AAQvC,OAAO,MAAMC,iBAA4C;IACvDC,QAAQ;QACNC,QAAQ,IAAe;QACvBC,MAAMT;QACNU,QAAQV;QACRW,QAAQ,IAAe;QACvBC,QAAQb;IACV;IACAc,OAAO;QACLC,YAAY;QACZC,OAAOlB,QAAQkB,KAAK,CAACC,KAAK;QAC1BC,gBAAgB;YACd;SACD;IACH;IACAC,MAAM;QACJC,WAAW;QACXC,UAAU,KAAK,KAAK;QACpBC,kBAAkB;QAClBC,iBAAiB,IAAI,KAAK;QAC1BC,QAAQ;I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ACEoD,MAAM;YACNL,MAAM;YACNM,OAAO;YACPR,QAAQ;gBACN;oBACEO,MAAM;oBACNC,OAAO;oBACPN,MAAM;oBACNO,YAAY5F,QAAQiC,IAAI,CAAC4D,iBAAiB;gBAC5C;gBACA;oBACEH,MAAM;oBACNL,MAAM;oBACNM,OAAO;gBACT;aACD;QACH;QACA;YAAEN,MAAM;YAAYK,MAAM;QAAgB;KAC3C;IACDT,cAAcE,MAAM,GAAG3E,YAAYgF,eAAeP,cAAcE,MAAM,EAAE;IACxE,oBAAoB;IACpB,IAAI,CAACF,cAAca,SAAS,EAAE;QAC5Bb,cAAca,SAAS,GAAG;YACxB9D,kBAAkBiD,cAAchD,IAAI;YACpCwB,iBAAiBwB,cAAchD,IAAI;YACnC6B,oBAAoBmB,cAAchD,IAAI;YACtCmC,iBAAiBa,cAAchD,IAAI;SACpC;IACH;IACAvC,mBAAmBuF,eAAe,eAAetD;IACjDpB,oBAAoB0E;IACpB,OAAOA;AACT,EAAE"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { deepMerge, withGlobalHook } from '@websolutespa/payload-utils';
|
|
2
|
+
import { options } from '../../options';
|
|
3
|
+
import { roles } from '../../types';
|
|
4
|
+
import { isRole } from '../access';
|
|
5
|
+
import { afterGlobalReadHook } from '../api/global.service';
|
|
6
|
+
import { translateGlobal } from '../translations';
|
|
7
|
+
export const GlobalDefault = {
|
|
8
|
+
admin: {
|
|
9
|
+
group: options.group.config
|
|
10
|
+
},
|
|
11
|
+
access: {
|
|
12
|
+
read: isRole(roles.Admin, roles.Contributor, roles.Editor, roles.Guest, roles.User),
|
|
13
|
+
update: isRole(roles.Admin, roles.Contributor, roles.Editor)
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
* @param {GlobalConfig} config
|
|
19
|
+
* @returns {GlobalConfig} Return a `GlobalConfig` with inherited fields: `id`, `createdAt`, `updatedAt`.
|
|
20
|
+
*/ export const withGlobal = (config)=>{
|
|
21
|
+
const globalConfig = deepMerge(GlobalDefault, config);
|
|
22
|
+
withGlobalHook(globalConfig, 'afterRead', afterGlobalReadHook(globalConfig));
|
|
23
|
+
translateGlobal(globalConfig);
|
|
24
|
+
return globalConfig;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=withGlobal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/core/collections/withGlobal.ts"],"sourcesContent":["import { deepMerge, withGlobalHook } from '@websolutespa/payload-utils';\r\nimport { AdminViewConfig, GlobalConfig } from 'payload';\r\nimport { options } from '../../options';\r\nimport { BowlField, roles } from '../../types';\r\nimport { isRole } from '../access';\r\nimport { afterGlobalReadHook } from '../api/global.service';\r\nimport { translateGlobal } from '../translations';\r\n\r\nexport type WithGlobalProps = (Omit<GlobalConfig, 'fields'> & {\r\n fields: BowlField[];\r\n views?: Record<string, AdminViewConfig>;\r\n});\r\nexport type WithGlobal = WithGlobalProps & { type: 'withGlobal' };\r\n\r\nexport const GlobalDefault: Partial<GlobalConfig> = {\r\n admin: {\r\n group: options.group.config,\r\n },\r\n access: {\r\n read: isRole(roles.Admin, roles.Contributor, roles.Editor, roles.Guest, roles.User),\r\n update: isRole(roles.Admin, roles.Contributor, roles.Editor),\r\n },\r\n};\r\n\r\n/**\r\n *\r\n * @param {GlobalConfig} config\r\n * @returns {GlobalConfig} Return a `GlobalConfig` with inherited fields: `id`, `createdAt`, `updatedAt`.\r\n */\r\nexport const withGlobal = (config: WithGlobalProps): GlobalConfig => {\r\n const globalConfig = deepMerge(GlobalDefault, config);\r\n withGlobalHook(globalConfig, 'afterRead', afterGlobalReadHook(globalConfig));\r\n translateGlobal(globalConfig);\r\n return globalConfig;\r\n};\r\n"],"names":["deepMerge","withGlobalHook","options","roles","isRole","afterGlobalReadHook","translateGlobal","GlobalDefault","admin","group","config","access","read","Admin","Contributor","Editor","Guest","User","update","withGlobal","globalConfig"],"mappings":"AAAA,SAASA,SAAS,EAAEC,cAAc,QAAQ,8BAA8B;AAExE,SAASC,OAAO,QAAQ,gBAAgB;AACxC,SAAoBC,KAAK,QAAQ,cAAc;AAC/C,SAASC,MAAM,QAAQ,YAAY;AACnC,SAASC,mBAAmB,QAAQ,wBAAwB;AAC5D,SAASC,eAAe,QAAQ,kBAAkB;AAQlD,OAAO,MAAMC,gBAAuC;IAClDC,OAAO;QACLC,OAAOP,QAAQO,KAAK,CAACC,MAAM;IAC7B;IACAC,QAAQ;QACNC,MAAMR,OAAOD,MAAMU,KAAK,EAAEV,MAAMW,WAAW,EAAEX,MAAMY,MAAM,EAAEZ,MAAMa,KAAK,EAAEb,MAAMc,IAAI;QAClFC,QAAQd,OAAOD,MAAMU,KAAK,EAAEV,MAAMW,WAAW,EAAEX,MAAMY,MAAM;IAC7D;AACF,EAAE;AAEF;;;;CAIC,GACD,OAAO,MAAMI,aAAa,CAACT;IACzB,MAAMU,eAAepB,UAAUO,eAAeG;IAC9CT,eAAemB,cAAc,aAAaf,oBAAoBe;IAC9Dd,gBAAgBc;IAChB,OAAOA;AACT,EAAE"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { config, GlobalCollection } from '@/test';
|
|
2
|
+
import { clearContext, endUsers, getContext, users } from '@websolutespa/test/payload';
|
|
3
|
+
import { v4 as uuid } from 'uuid';
|
|
4
|
+
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
|
5
|
+
describe('withGlobal global', ()=>{
|
|
6
|
+
let payload;
|
|
7
|
+
let client;
|
|
8
|
+
let userToken;
|
|
9
|
+
let endUserToken;
|
|
10
|
+
let apiKey;
|
|
11
|
+
beforeAll(async ()=>{
|
|
12
|
+
const context = await getContext(config);
|
|
13
|
+
payload = context.payload;
|
|
14
|
+
client = context.client;
|
|
15
|
+
userToken = await client.getToken('users', users.admin);
|
|
16
|
+
endUserToken = await client.getToken('end_users', endUsers.user);
|
|
17
|
+
apiKey = users.api.apiKey;
|
|
18
|
+
});
|
|
19
|
+
afterAll(async ()=>{
|
|
20
|
+
await clearContext();
|
|
21
|
+
});
|
|
22
|
+
describe('Global config', ()=>{
|
|
23
|
+
let withGlobalConfig;
|
|
24
|
+
beforeAll(async ()=>{
|
|
25
|
+
withGlobalConfig = payload.config.globals.find((global)=>global.slug === GlobalCollection.slug);
|
|
26
|
+
});
|
|
27
|
+
describe('translation', ()=>{
|
|
28
|
+
it('should have a label property', ()=>{
|
|
29
|
+
expect(withGlobalConfig).toHaveProperty('label');
|
|
30
|
+
});
|
|
31
|
+
it('fields should have a label property', ()=>{
|
|
32
|
+
const [field] = withGlobalConfig.fields;
|
|
33
|
+
expect(field).toHaveProperty('label');
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
describe('Global update', ()=>{
|
|
38
|
+
let doc;
|
|
39
|
+
let postData;
|
|
40
|
+
it('should update the global', async ()=>{
|
|
41
|
+
postData = {
|
|
42
|
+
customField: uuid()
|
|
43
|
+
};
|
|
44
|
+
({ result: doc } = await client.post(`/globals/${GlobalCollection.slug}`, postData, {
|
|
45
|
+
headers: {
|
|
46
|
+
Authorization: `JWT ${userToken}`
|
|
47
|
+
}
|
|
48
|
+
}));
|
|
49
|
+
expect(doc).toBeDefined();
|
|
50
|
+
});
|
|
51
|
+
it('global should have a valid custom field', async ()=>{
|
|
52
|
+
expect(doc.customField).toEqual(postData.customField);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=withGlobal.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/core/collections/withGlobal.test.ts"],"sourcesContent":["import { config, GlobalCollection } from '@/test';\r\nimport { clearContext, endUsers, getContext, RestClient, users } from '@websolutespa/test/payload';\r\nimport { Payload, SanitizedGlobalConfig } from 'payload';\r\nimport { v4 as uuid } from 'uuid';\r\nimport { afterAll, beforeAll, describe, expect, it } from 'vitest';\r\n\r\ndescribe('withGlobal global', () => {\r\n\r\n let payload: Payload;\r\n let client: RestClient;\r\n let userToken: string;\r\n let endUserToken: string;\r\n let apiKey: string;\r\n\r\n beforeAll(async () => {\r\n const context = await getContext(config);\r\n payload = context.payload;\r\n client = context.client;\r\n userToken = await client.getToken('users', users.admin);\r\n endUserToken = await client.getToken('end_users', endUsers.user);\r\n apiKey = users.api.apiKey;\r\n });\r\n\r\n afterAll(async () => {\r\n await clearContext();\r\n });\r\n\r\n describe('Global config', () => {\r\n let withGlobalConfig: SanitizedGlobalConfig;\r\n\r\n beforeAll(async () => {\r\n withGlobalConfig = payload.config.globals.find(global => global.slug === GlobalCollection.slug)!;\r\n });\r\n\r\n describe('translation', () => {\r\n it('should have a label property', () => {\r\n expect(withGlobalConfig).toHaveProperty('label');\r\n });\r\n\r\n it('fields should have a label property', () => {\r\n const [field] = withGlobalConfig.fields;\r\n expect(field).toHaveProperty('label');\r\n });\r\n });\r\n });\r\n\r\n describe('Global update', () => {\r\n let doc: any;\r\n let postData: any;\r\n\r\n it('should update the global', async () => {\r\n postData = {\r\n customField: uuid(),\r\n };\r\n ({ result: doc } = await client.post(`/globals/${GlobalCollection.slug}`, postData, {\r\n headers: {\r\n Authorization: `JWT ${userToken}`,\r\n },\r\n }));\r\n\r\n expect(doc).toBeDefined();\r\n });\r\n\r\n it('global should have a valid custom field', async () => {\r\n expect(doc.customField).toEqual(postData.customField);\r\n });\r\n });\r\n});\r\n"],"names":["config","GlobalCollection","clearContext","endUsers","getContext","users","v4","uuid","afterAll","beforeAll","describe","expect","it","payload","client","userToken","endUserToken","apiKey","context","getToken","admin","user","api","withGlobalConfig","globals","find","global","slug","toHaveProperty","field","fields","doc","postData","customField","result","post","headers","Authorization","toBeDefined","toEqual"],"mappings":"AAAA,SAASA,MAAM,EAAEC,gBAAgB,QAAQ,SAAS;AAClD,SAASC,YAAY,EAAEC,QAAQ,EAAEC,UAAU,EAAcC,KAAK,QAAQ,6BAA6B;AAEnG,SAASC,MAAMC,I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W;QACzB;QAEA1B,GAAG,2CAA2C;YAC5CD,OAAOoB,IAAIE,WAAW,EAAEM,OAAO,CAACP,SAASC,WAAW;QACtD;IACF;AACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { deepMerge, withCollectionHook } from '@websolutespa/payload-utils';
|
|
2
|
+
import { options } from '../../options';
|
|
3
|
+
import { beforeOperationHook } from '../api/collection.service';
|
|
4
|
+
import { afterMenuReadHook, menuDetailGet, menuIndexGet } from '../api/menu.service';
|
|
5
|
+
import { translateCollection } from '../translations';
|
|
6
|
+
import { CollectionDefault } from './withCollection';
|
|
7
|
+
export const withMenu = (config)=>{
|
|
8
|
+
const menuConfig = deepMerge(CollectionDefault, config);
|
|
9
|
+
menuConfig.endpoints = [
|
|
10
|
+
menuIndexGet(options),
|
|
11
|
+
menuDetailGet(options)
|
|
12
|
+
];
|
|
13
|
+
withCollectionHook(menuConfig, 'beforeOperation', beforeOperationHook);
|
|
14
|
+
withCollectionHook(menuConfig, 'afterRead', afterMenuReadHook(menuConfig));
|
|
15
|
+
translateCollection(menuConfig);
|
|
16
|
+
return menuConfig;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=withMenu.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/core/collections/withMenu.ts"],"sourcesContent":["import { deepMerge, withCollectionHook } from '@websolutespa/payload-utils';\r\nimport { AdminViewConfig, CollectionConfig } from 'payload';\r\nimport { options } from '../../options';\r\nimport { BowlField } from '../../types';\r\nimport { beforeOperationHook } from '../api/collection.service';\r\nimport { afterMenuReadHook, menuDetailGet, menuIndexGet } from '../api/menu.service';\r\nimport { translateCollection } from '../translations';\r\nimport { CollectionDefault } from './withCollection';\r\n\r\nexport type WithMenuProps = (Omit<CollectionConfig, 'fields'> & {\r\n fields: BowlField[];\r\n views?: Record<string, AdminViewConfig>;\r\n});\r\nexport type WithMenu = WithMenuProps & { type: 'withMenu' };\r\n\r\nexport const withMenu = (config: WithMenuProps): CollectionConfig => {\r\n const menuConfig = deepMerge(CollectionDefault, config);\r\n menuConfig.endpoints = [\r\n menuIndexGet(options),\r\n menuDetailGet(options),\r\n ];\r\n withCollectionHook(menuConfig, 'beforeOperation', beforeOperationHook);\r\n withCollectionHook(menuConfig, 'afterRead', afterMenuReadHook(menuConfig));\r\n translateCollection(menuConfig);\r\n return menuConfig;\r\n};\r\n"],"names":["deepMerge","withCollectionHook","options","beforeOperationHook","afterMenuReadHook","menuDetailGet","menuIndexGet","translateCollection","CollectionDefault","withMenu","config","menuConfig","endpoints"],"mappings":"AAAA,SAASA,SAAS,EAAEC,kBAAkB,QAAQ,8BAA8B;AAE5E,SAASC,OAAO,QAAQ,gBAAgB;AAExC,SAASC,mBAAmB,QAAQ,4BAA4B;AAChE,SAASC,iBAAiB,EAAEC,aAAa,EAAEC,YAAY,QAAQ,sBAAsB;AACrF,SAASC,mBAAmB,QAAQ,kBAAkB;AACtD,SAASC,iBAAiB,QAAQ,mBAAmB;AAQrD,OAAO,MAAMC,WAAW,CAACC;IACvB,MAAMC,aAAaX,UAAUQ,mBAAmBE;IAChDC,WAAWC,SAAS,GAAG;QACrBN,aAAaJ;QACbG,cAAcH;KACf;IACDD,mBAAmBU,YAAY,mBAAmBR;IAClDF,mBAAmBU,YAAY,aAAaP,kBAAkBO;IAC9DJ,oBAAoBI;IACpB,OAAOA;AACT,EAAE"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { config, MenuCollection } from '@/test';
|
|
2
|
+
import { clearContext, endUsers, getContext, users } from '@websolutespa/test/payload';
|
|
3
|
+
import { v4 as uuid } from 'uuid';
|
|
4
|
+
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
|
5
|
+
describe('withMenu collection', ()=>{
|
|
6
|
+
let payload;
|
|
7
|
+
let client;
|
|
8
|
+
let userToken;
|
|
9
|
+
let endUserToken;
|
|
10
|
+
let apiKey;
|
|
11
|
+
beforeAll(async ()=>{
|
|
12
|
+
const context = await getContext(config);
|
|
13
|
+
payload = context.payload;
|
|
14
|
+
client = context.client;
|
|
15
|
+
userToken = await client.getToken('users', users.admin);
|
|
16
|
+
endUserToken = await client.getToken('end_users', endUsers.user);
|
|
17
|
+
apiKey = users.api.apiKey;
|
|
18
|
+
});
|
|
19
|
+
afterAll(async ()=>{
|
|
20
|
+
await clearContext();
|
|
21
|
+
});
|
|
22
|
+
describe('Collection config', ()=>{
|
|
23
|
+
let withMenuCollection;
|
|
24
|
+
beforeAll(async ()=>{
|
|
25
|
+
withMenuCollection = payload.config.collections.find((collection)=>collection.slug === MenuCollection.slug);
|
|
26
|
+
});
|
|
27
|
+
it('should have a endpoint with "/" path', ()=>{
|
|
28
|
+
expect(withMenuCollection.endpoints && withMenuCollection.endpoints.find((endpoint)=>endpoint.path === '/')).toBeDefined();
|
|
29
|
+
});
|
|
30
|
+
it('should have a endpoint with "/:id/" path', ()=>{
|
|
31
|
+
expect(withMenuCollection.endpoints && withMenuCollection.endpoints.find((endpoint)=>endpoint.path === '/:id')).toBeDefined();
|
|
32
|
+
});
|
|
33
|
+
describe('translation', ()=>{
|
|
34
|
+
it('should have a labels property', ()=>{
|
|
35
|
+
expect(withMenuCollection).toHaveProperty('labels');
|
|
36
|
+
});
|
|
37
|
+
it('fields should have a label property', ()=>{
|
|
38
|
+
const [field] = withMenuCollection.fields;
|
|
39
|
+
expect(field).toHaveProperty('label');
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
describe('Create doc', ()=>{
|
|
44
|
+
let withMenuDoc;
|
|
45
|
+
let postData;
|
|
46
|
+
it('should create a MenuCollection document', async ()=>{
|
|
47
|
+
postData = {
|
|
48
|
+
customField: uuid()
|
|
49
|
+
};
|
|
50
|
+
({ doc: withMenuDoc } = await client.post(MenuCollection.slug, postData, {
|
|
51
|
+
headers: {
|
|
52
|
+
Authorization: `JWT ${userToken}`
|
|
53
|
+
}
|
|
54
|
+
}));
|
|
55
|
+
expect(withMenuDoc).toBeDefined();
|
|
56
|
+
});
|
|
57
|
+
it('should have a valid custom field', async ()=>{
|
|
58
|
+
expect(withMenuDoc.customField).toEqual(postData.customField);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
//# sourceMappingURL=withMenu.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/core/collections/withMenu.test.ts"],"sourcesContent":["import { config, MenuCollection } from '@/test';\r\nimport { clearContext, endUsers, getContext, RestClient, users } from '@websolutespa/test/payload';\r\nimport { Payload, SanitizedCollectionConfig } from 'payload';\r\nimport { v4 as uuid } from 'uuid';\r\nimport { afterAll, beforeAll, describe, expect, it } from 'vitest';\r\n\r\ndescribe('withMenu collection', () => {\r\n\r\n let payload: Payload;\r\n let client: RestClient;\r\n let userToken: string;\r\n let endUserToken: string;\r\n let apiKey: string;\r\n\r\n beforeAll(async () => {\r\n const context = await getContext(config);\r\n payload = context.payload;\r\n client = context.client;\r\n userToken = await client.getToken('users', users.admin);\r\n endUserToken = await client.getToken('end_users', endUsers.user);\r\n apiKey = users.api.apiKey;\r\n });\r\n\r\n afterAll(async () => {\r\n await clearContext();\r\n });\r\n\r\n describe('Collection config', () => {\r\n let withMenuCollection: SanitizedCollectionConfig;\r\n\r\n beforeAll(async () => {\r\n withMenuCollection = payload.config.collections.find(collection => collection.slug === MenuCollection.slug)!;\r\n });\r\n\r\n it('should have a endpoint with \"/\" path', () => {\r\n expect(withMenuCollection.endpoints && withMenuCollection.endpoints.find(endpoint => endpoint.path === '/')).toBeDefined();\r\n });\r\n\r\n it('should have a endpoint with \"/:id/\" path', () => {\r\n expect(withMenuCollection.endpoints && withMenuCollection.endpoints.find(endpoint => endpoint.path === '/:id')).toBeDefined();\r\n });\r\n\r\n describe('translation', () => {\r\n it('should have a labels property', () => {\r\n expect(withMenuCollection).toHaveProperty('labels');\r\n });\r\n\r\n it('fields should have a label property', () => {\r\n const [field] = withMenuCollection.fields;\r\n expect(field).toHaveProperty('label');\r\n });\r\n });\r\n });\r\n\r\n describe('Create doc', () => {\r\n let withMenuDoc: any;\r\n let postData: any;\r\n\r\n it('should create a MenuCollection document', async () => {\r\n postData = {\r\n customField: uuid(),\r\n };\r\n ({ doc: withMenuDoc } = await client.post(MenuCollection.slug, postData, {\r\n headers: {\r\n Authorization: `JWT ${userToken}`,\r\n },\r\n }));\r\n\r\n expect(withMenuDoc).toBeDefined();\r\n });\r\n\r\n it('should have a valid custom field', async () => {\r\n expect(withMenuDoc.customField).toEqual(postData.customField);\r\n });\r\n });\r\n});\r\n"],"names":["config","MenuCollection","clearContext","endUsers","getContext","users","v4","uuid","afterAll","beforeAll","describe","expect","it","payload","client","userToken","endUserToken","apiKey","context","getToken","admin","user","api","withMenuCollection","collections","find","collection","slug","endpoints","endpoint","path","toBeDefined","toHaveProperty","field","fields","withMenuDoc","postData","customField","doc","post","headers","Authorization","toEqual"],"mappings":"AAAA,SAASA,MAAM,EAAEC,cAAc,QAAQ,SAAS;AAChD,SAASC,YAAY,EAAEC,QAAQ,EAAEC,UAAU,EAAcC,KAAK,QAAQ,6BAA6B;AAEnG,SAASC,MAAMC,IAAI,QAAQ,OAAO;AAClC,SAASC,QAAQ,EAAEC,SAAS,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAS;AAEnEF,SAAS,uBAAuB;IAE9B,IAAIG;IACJ,IAAIC;IACJ,IAAIC;IACJ,IAAIC;IACJ,IAAIC;IAEJR,UAAU;QACR,MAAMS,UAAU,MAAMd,WAAWJ;QACjCa,UAAUK,QAAQL,OAAO;QACzBC,SAASI,QAAQJ,MAAM;QACvBC,YAAY,MAAMD,OAAOK,QAAQ,CAAC,SAASd,MAAMe,KAAK;QACtDJ,eAAe,MAAMF,OAAOK,QAAQ,CAAC,aAAahB,SAASkB,IAAI;QAC/DJ,SAASZ,MAAMiB,GAAG,CAACL,MAAM;IAC3B;IAEAT,SAAS;QACP,MAA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