@webiny/app-admin 6.6.0-alpha.12 → 6.6.0-alpha.14
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/base/Base/FieldRenderers/ObjectRenderer/KeyValueTagsRenderer.js.map +1 -1
- package/base/Base/FieldRenderers/ObjectRenderer/MultiValueDynamicZone/MultiValueDynamicZone.js.map +1 -1
- package/base/Base/FieldRenderers/ObjectRenderer/ObjectAccordionMultipleRenderer.js.map +1 -1
- package/base/Base/FieldRenderers/ObjectRenderer/ObjectFieldComponents.js.map +1 -1
- package/base/Base/LexicalPreset.js +1 -1
- package/base/Base/LexicalPreset.js.map +1 -1
- package/base/Base/Menus.js.map +1 -1
- package/base/Base/RoutesConfig.js.map +1 -1
- package/base/Base/Tenant.js.map +1 -1
- package/base/Base/UserMenu/SwitchTenant.d.ts +20 -0
- package/base/Base/UserMenu/SwitchTenant.js +45 -0
- package/base/Base/UserMenu/SwitchTenant.js.map +1 -0
- package/base/Base/UserMenu.js +4 -0
- package/base/Base/UserMenu.js.map +1 -1
- package/base/Base.js.map +1 -1
- package/base/ui/AssumedPermissionsSelector.js.map +1 -1
- package/base/ui/Brand.js.map +1 -1
- package/base/ui/Dashboard.js.map +1 -1
- package/base/ui/FileManager.js.map +1 -1
- package/base/ui/LoginScreen.js.map +1 -1
- package/base/ui/Logo.js.map +1 -1
- package/base/ui/Navigation.js.map +1 -1
- package/base/ui/NotFound.js.map +1 -1
- package/base/ui/Tags.js.map +1 -1
- package/base/ui/TenantSelector.js.map +1 -1
- package/base/ui/UserMenu/UserMenu.js.map +1 -1
- package/base/ui/UserMenu/UserMenuHandle.js.map +1 -1
- package/base/ui/UserMenu.js.map +1 -1
- package/components/Buttons/useButtons.js.map +1 -1
- package/components/Dialogs/DialogParamsContext.js.map +1 -1
- package/components/Dialogs/DialogsContext.js.map +1 -1
- package/components/Drawers/DrawerParamsContext.js.map +1 -1
- package/components/Drawers/DrawersContext.js.map +1 -1
- package/components/Filters/FiltersToggle.js.map +1 -1
- package/components/IconPicker/IconPickerPresenterProvider.js.map +1 -1
- package/components/IconPicker/IconPickerTab.js.map +1 -1
- package/components/IconPicker/IconRenderer.js.map +1 -1
- package/components/IconPicker/config/IconType.js.map +1 -1
- package/components/IconPicker/config/index.js.map +1 -1
- package/components/IconPicker/plugins/customPlugin.js.map +1 -1
- package/components/IconPicker/plugins/emojisPlugin.js.map +1 -1
- package/components/IconPicker/plugins/iconsPlugin.js.map +1 -1
- package/components/IconPicker/types.js.map +1 -1
- package/components/LexicalEditor/DefaultLexicalEditorConfig.js +1 -1
- package/components/LexicalEditor/DefaultLexicalEditorConfig.js.map +1 -1
- package/components/LexicalEditor/LexicalEditor.d.ts +3 -1
- package/components/LexicalEditor/LexicalEditor.js +3 -2
- package/components/LexicalEditor/LexicalEditor.js.map +1 -1
- package/components/LexicalEditor/LexicalLinkForm.js.map +1 -1
- package/components/ListView/ListViewBottomBar.js.map +1 -1
- package/components/ListView/ListViewHeader.js.map +1 -1
- package/components/OptionsMenu/useOptionsMenuItem.js.map +1 -1
- package/components/Table/useTableRow.js.map +1 -1
- package/config/AdminConfig/LexicalTheme/Typography.js +4 -4
- package/config/AdminConfig/LexicalTheme/Typography.js.map +1 -1
- package/config/AdminConfig/Menu.js.map +1 -1
- package/config/AdminConfig/Theme.js +1 -1
- package/config/AdminConfig/Theme.js.map +1 -1
- package/config/AdminConfig.js +2 -2
- package/config/AdminConfig.js.map +1 -1
- package/config/createAdminConfig.js.map +1 -1
- package/domain/Identity.d.ts +8 -0
- package/domain/Identity.js +6 -0
- package/domain/Identity.js.map +1 -1
- package/exports/admin/security.d.ts +4 -1
- package/exports/admin/security.js +4 -1
- package/exports/admin.d.ts +2 -0
- package/exports/admin.js +2 -0
- package/features/accessManagement/constants.js.map +1 -1
- package/features/adminUsers/capabilities/abstractions.d.ts +18 -0
- package/features/adminUsers/capabilities/abstractions.js +5 -0
- package/features/adminUsers/capabilities/abstractions.js.map +1 -0
- package/features/adminUsers/capabilities/feature.d.ts +4 -0
- package/features/adminUsers/capabilities/feature.js +19 -0
- package/features/adminUsers/capabilities/feature.js.map +1 -0
- package/features/adminUsers/capabilities/index.d.ts +3 -0
- package/features/adminUsers/capabilities/index.js +2 -0
- package/features/adminUsers/users/checkEmail/CheckEmailGateway.d.ts +11 -0
- package/features/adminUsers/users/checkEmail/CheckEmailGateway.js +44 -0
- package/features/adminUsers/users/checkEmail/CheckEmailGateway.js.map +1 -0
- package/features/adminUsers/users/checkEmail/CheckEmailUseCase.d.ts +10 -0
- package/features/adminUsers/users/checkEmail/CheckEmailUseCase.js +18 -0
- package/features/adminUsers/users/checkEmail/CheckEmailUseCase.js.map +1 -0
- package/features/adminUsers/users/checkEmail/abstractions/CheckEmailGateway.d.ts +14 -0
- package/features/adminUsers/users/checkEmail/abstractions/CheckEmailGateway.js +5 -0
- package/features/adminUsers/users/checkEmail/abstractions/CheckEmailGateway.js.map +1 -0
- package/features/adminUsers/users/checkEmail/abstractions/CheckEmailUseCase.d.ts +9 -0
- package/features/adminUsers/users/checkEmail/abstractions/CheckEmailUseCase.js +5 -0
- package/features/adminUsers/users/checkEmail/abstractions/CheckEmailUseCase.js.map +1 -0
- package/features/adminUsers/users/checkEmail/abstractions/index.d.ts +2 -0
- package/features/adminUsers/users/checkEmail/abstractions/index.js +2 -0
- package/features/adminUsers/users/checkEmail/feature.d.ts +3 -0
- package/features/adminUsers/users/checkEmail/feature.js +19 -0
- package/features/adminUsers/users/checkEmail/feature.js.map +1 -0
- package/features/adminUsers/users/checkEmail/index.d.ts +2 -0
- package/features/adminUsers/users/checkEmail/index.js +2 -0
- package/features/adminUsers/users/createUser/CreateUserGateway.js +2 -1
- package/features/adminUsers/users/createUser/CreateUserGateway.js.map +1 -1
- package/features/adminUsers/users/createUser/CreateUserUseCase.test.d.ts +1 -0
- package/features/adminUsers/users/createUser/CreateUserUseCase.test.js +65 -0
- package/features/adminUsers/users/createUser/CreateUserUseCase.test.js.map +1 -0
- package/features/adminUsers/users/linkUser/LinkUserGateway.d.ts +11 -0
- package/features/adminUsers/users/linkUser/LinkUserGateway.js +50 -0
- package/features/adminUsers/users/linkUser/LinkUserGateway.js.map +1 -0
- package/features/adminUsers/users/linkUser/LinkUserUseCase.d.ts +10 -0
- package/features/adminUsers/users/linkUser/LinkUserUseCase.js +18 -0
- package/features/adminUsers/users/linkUser/LinkUserUseCase.js.map +1 -0
- package/features/adminUsers/users/linkUser/abstractions/LinkUserGateway.d.ts +18 -0
- package/features/adminUsers/users/linkUser/abstractions/LinkUserGateway.js +5 -0
- package/features/adminUsers/users/linkUser/abstractions/LinkUserGateway.js.map +1 -0
- package/features/adminUsers/users/linkUser/abstractions/LinkUserUseCase.d.ts +15 -0
- package/features/adminUsers/users/linkUser/abstractions/LinkUserUseCase.js +5 -0
- package/features/adminUsers/users/linkUser/abstractions/LinkUserUseCase.js.map +1 -0
- package/features/adminUsers/users/linkUser/abstractions/index.d.ts +2 -0
- package/features/adminUsers/users/linkUser/abstractions/index.js +2 -0
- package/features/adminUsers/users/linkUser/feature.d.ts +3 -0
- package/features/adminUsers/users/linkUser/feature.js +19 -0
- package/features/adminUsers/users/linkUser/feature.js.map +1 -0
- package/features/adminUsers/users/linkUser/index.d.ts +2 -0
- package/features/adminUsers/users/linkUser/index.js +2 -0
- package/features/adminUsers/users/resetUserMfa/ResetUserMfaGateway.d.ts +11 -0
- package/features/adminUsers/users/resetUserMfa/ResetUserMfaGateway.js +42 -0
- package/features/adminUsers/users/resetUserMfa/ResetUserMfaGateway.js.map +1 -0
- package/features/adminUsers/users/resetUserMfa/ResetUserMfaUseCase.d.ts +10 -0
- package/features/adminUsers/users/resetUserMfa/ResetUserMfaUseCase.js +18 -0
- package/features/adminUsers/users/resetUserMfa/ResetUserMfaUseCase.js.map +1 -0
- package/features/adminUsers/users/resetUserMfa/abstractions/ResetUserMfaGateway.d.ts +11 -0
- package/features/adminUsers/users/resetUserMfa/abstractions/ResetUserMfaGateway.js +5 -0
- package/features/adminUsers/users/resetUserMfa/abstractions/ResetUserMfaGateway.js.map +1 -0
- package/features/adminUsers/users/resetUserMfa/abstractions/ResetUserMfaUseCase.d.ts +12 -0
- package/features/adminUsers/users/resetUserMfa/abstractions/ResetUserMfaUseCase.js +5 -0
- package/features/adminUsers/users/resetUserMfa/abstractions/ResetUserMfaUseCase.js.map +1 -0
- package/features/adminUsers/users/resetUserMfa/abstractions/index.d.ts +2 -0
- package/features/adminUsers/users/resetUserMfa/abstractions/index.js +2 -0
- package/features/adminUsers/users/resetUserMfa/feature.d.ts +3 -0
- package/features/adminUsers/users/resetUserMfa/feature.js +19 -0
- package/features/adminUsers/users/resetUserMfa/feature.js.map +1 -0
- package/features/adminUsers/users/resetUserMfa/index.d.ts +2 -0
- package/features/adminUsers/users/resetUserMfa/index.js +2 -0
- package/features/adminUsers/users/shared/AdminUsersError.d.ts +13 -0
- package/features/adminUsers/users/shared/AdminUsersError.js +11 -0
- package/features/adminUsers/users/shared/AdminUsersError.js.map +1 -0
- package/features/assumePermissions/AssumePermissionsUseCase.js +2 -2
- package/features/assumePermissions/AssumePermissionsUseCase.js.map +1 -1
- package/features/assumePermissions/LogInUseCaseDecorator.d.ts +1 -1
- package/features/assumePermissions/LogInUseCaseDecorator.js +8 -6
- package/features/assumePermissions/LogInUseCaseDecorator.js.map +1 -1
- package/features/formModel/FormView.js.map +1 -1
- package/features/formModel/createFieldRenderer.js.map +1 -1
- package/features/formModel/demo/FormModelDemo.js.map +1 -1
- package/features/formModel/fieldTypes/dateLimits.js.map +1 -1
- package/features/security/LogIn/LogInError.d.ts +15 -0
- package/features/security/LogIn/LogInError.js +25 -0
- package/features/security/LogIn/LogInError.js.map +1 -0
- package/features/security/LogIn/LogInGateway.d.ts +2 -2
- package/features/security/LogIn/LogInGateway.js +22 -5
- package/features/security/LogIn/LogInGateway.js.map +1 -1
- package/features/security/LogIn/LogInRepository.d.ts +1 -2
- package/features/security/LogIn/LogInRepository.js +6 -2
- package/features/security/LogIn/LogInRepository.js.map +1 -1
- package/features/security/LogIn/LogInUseCase.d.ts +7 -2
- package/features/security/LogIn/LogInUseCase.js +53 -3
- package/features/security/LogIn/LogInUseCase.js.map +1 -1
- package/features/security/LogIn/LogInUseCase.test.d.ts +1 -0
- package/features/security/LogIn/LogInUseCase.test.js +321 -0
- package/features/security/LogIn/LogInUseCase.test.js.map +1 -0
- package/features/security/LogIn/abstractions.d.ts +48 -3
- package/features/security/LogIn/abstractions.js.map +1 -1
- package/features/security/LogIn/createLoginMutation.js +40 -27
- package/features/security/LogIn/createLoginMutation.js.map +1 -1
- package/features/security/LogIn/feature.js +2 -0
- package/features/security/LogIn/feature.js.map +1 -1
- package/features/security/LogIn/index.d.ts +1 -0
- package/features/security/LogIn/index.js +1 -0
- package/features/security/LoginTenantResolver/LoginTenantResolver.d.ts +14 -0
- package/features/security/LoginTenantResolver/LoginTenantResolver.js +52 -0
- package/features/security/LoginTenantResolver/LoginTenantResolver.js.map +1 -0
- package/features/security/LoginTenantResolver/abstractions.d.ts +38 -0
- package/features/security/LoginTenantResolver/abstractions.js +5 -0
- package/features/security/LoginTenantResolver/abstractions.js.map +1 -0
- package/features/security/LoginTenantResolver/feature.d.ts +3 -0
- package/features/security/LoginTenantResolver/feature.js +17 -0
- package/features/security/LoginTenantResolver/feature.js.map +1 -0
- package/features/security/LoginTenantResolver/index.d.ts +2 -0
- package/features/security/LoginTenantResolver/index.js +2 -0
- package/features/webinySdk/WebinySdk.d.ts +2 -1
- package/features/webinySdk/WebinySdk.js +14 -2
- package/features/webinySdk/WebinySdk.js.map +1 -1
- package/features/webinySdk/__tests__/WebinySdk.test.d.ts +1 -0
- package/features/webinySdk/__tests__/WebinySdk.test.js +89 -0
- package/features/webinySdk/__tests__/WebinySdk.test.js.map +1 -0
- package/modules/AccessManagementExtension.js +1 -1
- package/modules/AccessManagementExtension.js.map +1 -1
- package/modules/DebuggerExtension.js +1 -1
- package/modules/DebuggerExtension.js.map +1 -1
- package/package.json +30 -30
- package/permissions/PermissionRenderer.js.map +1 -1
- package/permissions/PermissionValueContext.js.map +1 -1
- package/presentation/accessManagement/SecurityPermissions.js +1 -1
- package/presentation/accessManagement/SecurityPermissions.js.map +1 -1
- package/presentation/accessManagement/apiKeys/components/ApiKeysView.js.map +1 -1
- package/presentation/adminUsers/AdminUsers.d.ts +8 -1
- package/presentation/adminUsers/AdminUsers.js +22 -2
- package/presentation/adminUsers/AdminUsers.js.map +1 -1
- package/presentation/adminUsers/SecurityPermission.js +1 -1
- package/presentation/adminUsers/SecurityPermission.js.map +1 -1
- package/presentation/adminUsers/resetMfa/ResetMfaPresenter.d.ts +27 -0
- package/presentation/adminUsers/resetMfa/ResetMfaPresenter.js +67 -0
- package/presentation/adminUsers/resetMfa/ResetMfaPresenter.js.map +1 -0
- package/presentation/adminUsers/resetMfa/ResetMfaPresenter.test.d.ts +1 -0
- package/presentation/adminUsers/resetMfa/ResetMfaPresenter.test.js +150 -0
- package/presentation/adminUsers/resetMfa/ResetMfaPresenter.test.js.map +1 -0
- package/presentation/adminUsers/resetMfa/abstractions.d.ts +38 -0
- package/presentation/adminUsers/resetMfa/abstractions.js +5 -0
- package/presentation/adminUsers/resetMfa/abstractions.js.map +1 -0
- package/presentation/adminUsers/resetMfa/feature.d.ts +6 -0
- package/presentation/adminUsers/resetMfa/feature.js +17 -0
- package/presentation/adminUsers/resetMfa/feature.js.map +1 -0
- package/presentation/adminUsers/userForm/UserFormPresenter.d.ts +32 -0
- package/presentation/adminUsers/userForm/UserFormPresenter.js +124 -0
- package/presentation/adminUsers/userForm/UserFormPresenter.js.map +1 -0
- package/presentation/adminUsers/userForm/UserFormPresenter.test.d.ts +1 -0
- package/presentation/adminUsers/userForm/UserFormPresenter.test.js +264 -0
- package/presentation/adminUsers/userForm/UserFormPresenter.test.js.map +1 -0
- package/presentation/adminUsers/userForm/abstractions.d.ts +52 -0
- package/presentation/adminUsers/userForm/abstractions.js +5 -0
- package/presentation/adminUsers/userForm/abstractions.js.map +1 -0
- package/presentation/adminUsers/userForm/feature.d.ts +7 -0
- package/presentation/adminUsers/userForm/feature.js +17 -0
- package/presentation/adminUsers/userForm/feature.js.map +1 -0
- package/presentation/adminUsers/userMenu/AccountDetails.js +1 -1
- package/presentation/adminUsers/userMenu/AccountDetails.js.map +1 -1
- package/presentation/adminUsers/views/Users/UsersForm.d.ts +3 -1
- package/presentation/adminUsers/views/Users/UsersForm.js +51 -20
- package/presentation/adminUsers/views/Users/UsersForm.js.map +1 -1
- package/presentation/adminUsers/views/Users/components/LinkAccountAlert.d.ts +10 -0
- package/presentation/adminUsers/views/Users/components/LinkAccountAlert.js +17 -0
- package/presentation/adminUsers/views/Users/components/LinkAccountAlert.js.map +1 -0
- package/presentation/adminUsers/views/Users/components/ResetMfa.d.ts +12 -0
- package/presentation/adminUsers/views/Users/components/ResetMfa.js +63 -0
- package/presentation/adminUsers/views/Users/components/ResetMfa.js.map +1 -0
- package/presentation/adminUsers/views/Users/hooks/useUserForm.d.ts +1 -0
- package/presentation/adminUsers/views/Users/hooks/useUserForm.js +31 -18
- package/presentation/adminUsers/views/Users/hooks/useUserForm.js.map +1 -1
- package/presentation/adminUsers/views/Users/hooks/useUserForm.test.js +9 -0
- package/presentation/adminUsers/views/Users/hooks/useUserForm.test.js.map +1 -1
- package/presentation/assumePermissions/components/AssumedPermissionsSelector.js.map +1 -1
- package/presentation/debugger/components/DebuggerIndicator.js.map +1 -1
- package/presentation/installation/components/SystemInstaller/steps/AdminUserStep.js.map +1 -1
- package/presentation/installation/components/SystemInstaller/steps/BasicInfoStep.js.map +1 -1
- package/presentation/listPresenter/ListPresenter.js +1 -1
- package/presentation/listPresenter/ListPresenter.js.map +1 -1
- package/presentation/listPresenter/ListPresenter.test.js +28 -0
- package/presentation/listPresenter/ListPresenter.test.js.map +1 -1
- package/presentation/security/components/LoginNoTenantAccess.d.ts +27 -0
- package/presentation/security/components/LoginNoTenantAccess.js +22 -0
- package/presentation/security/components/LoginNoTenantAccess.js.map +1 -0
- package/presentation/security/components/LoginTenantPicker.d.ts +30 -0
- package/presentation/security/components/LoginTenantPicker.js +32 -0
- package/presentation/security/components/LoginTenantPicker.js.map +1 -0
- package/presentation/security/hooks/useAuthentication.d.ts +2 -2
- package/presentation/security/hooks/useAuthentication.js.map +1 -1
- package/presentation/security/hooks/useSecurity.js +2 -2
- package/presentation/security/hooks/useSecurity.js.map +1 -1
- package/presentation/sortable/SortablePresenter.js +3 -2
- package/presentation/sortable/SortablePresenter.js.map +1 -1
- package/presentation/trashBin/components/BulkActions/DeleteItems.test.js +1 -1
- package/presentation/trashBin/components/BulkActions/DeleteItems.test.js.map +1 -1
- package/presentation/trashBin/components/TrashBinConfigs.js +1 -1
- package/presentation/trashBin/components/TrashBinConfigs.js.map +1 -1
- package/presentation/trashBin/components/TrashBinOverlay.js.map +1 -1
- package/presentation/trashBin/configs/Browser/BulkAction.js +1 -1
- package/presentation/trashBin/configs/Browser/BulkAction.js.map +1 -1
- package/presentation/trashBin/hooks/useTrashBinItem.js +1 -1
- package/presentation/trashBin/hooks/useTrashBinItem.js.map +1 -1
- package/presentation/trashBin/hooks/useTrashBinPresenter.js +1 -1
- package/presentation/trashBin/hooks/useTrashBinPresenter.js.map +1 -1
|
@@ -9,19 +9,21 @@ class LogInUseCaseDecoratorImpl {
|
|
|
9
9
|
}
|
|
10
10
|
async execute(params) {
|
|
11
11
|
const active = this.assumePermissionsContext.get();
|
|
12
|
-
if (!active) return
|
|
12
|
+
if (!active) return this.decoratee.execute(params);
|
|
13
|
+
let result;
|
|
13
14
|
try {
|
|
14
|
-
await this.decoratee.execute(params);
|
|
15
|
+
result = await this.decoratee.execute(params);
|
|
15
16
|
} catch {
|
|
16
|
-
|
|
17
|
-
return;
|
|
17
|
+
return this.loginWithoutAssumedPermissions(params);
|
|
18
18
|
}
|
|
19
|
+
if ("loggedIn" !== result.type) return result;
|
|
19
20
|
const identity = this.identityContext.getIdentity();
|
|
20
|
-
if (identity.id !== active.startedBy)
|
|
21
|
+
if (identity.id !== active.startedBy) return this.loginWithoutAssumedPermissions(params);
|
|
22
|
+
return result;
|
|
21
23
|
}
|
|
22
24
|
async loginWithoutAssumedPermissions(params) {
|
|
23
25
|
this.assumePermissionsContext.set(null);
|
|
24
|
-
|
|
26
|
+
return this.decoratee.execute(params);
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
29
|
const LogInUseCaseDecorator = LogInUseCase.createDecorator({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/assumePermissions/LogInUseCaseDecorator.js","sources":["../../../src/features/assumePermissions/LogInUseCaseDecorator.ts"],"sourcesContent":["import { LogInUseCase } from \"~/features/security/LogIn/abstractions.js\";\nimport { IdentityContext } from \"~/features/security/IdentityContext/index.js\";\nimport { AssumePermissionsContext } from \"./abstractions.js\";\n\n/**\n * Drops a stored preview that doesn't belong to this login, and logs in again as the user.\n *\n * The login request has to carry the preview header, since that request is what returns the\n * previewed permissions, and it goes out before anyone knows who is signing in. So a preview left\n * behind is caught here, after the fact, in the two ways it can go wrong:\n *\n * - The login fails. A preview that no longer resolves (the role was deleted, or it belongs to\n * another tenant) grants nothing, and a login with no permissions throws. Without this the user\n * would be stuck on that error screen, because the selection survives a reload.\n * - It was started by someone else. A session can end without going through log out, so the next\n * person on the browser would otherwise inherit whatever the last one was previewing.\n *\n * Any login failure drops the preview, not only the one a bad preview causes. The login path throws\n * plain errors, so there is nothing to tell \"no permissions\" from a network error by. That errs on\n * the safe side: a transient failure costs the preview and one retry, and the user is back on\n * their own permissions. Narrowing it needs a typed error from LogInUseCase.\n */\nclass LogInUseCaseDecoratorImpl implements LogInUseCase.Interface {\n constructor(\n private assumePermissionsContext: AssumePermissionsContext.Interface,\n private identityContext: IdentityContext.Interface,\n private decoratee: LogInUseCase.Interface\n ) {}\n\n async execute(params: LogInUseCase.Params): Promise<
|
|
1
|
+
{"version":3,"file":"features/assumePermissions/LogInUseCaseDecorator.js","sources":["../../../src/features/assumePermissions/LogInUseCaseDecorator.ts"],"sourcesContent":["import { LogInUseCase } from \"~/features/security/LogIn/abstractions.js\";\nimport { IdentityContext } from \"~/features/security/IdentityContext/index.js\";\nimport { AssumePermissionsContext } from \"./abstractions.js\";\n\n/**\n * Drops a stored preview that doesn't belong to this login, and logs in again as the user.\n *\n * The login request has to carry the preview header, since that request is what returns the\n * previewed permissions, and it goes out before anyone knows who is signing in. So a preview left\n * behind is caught here, after the fact, in the two ways it can go wrong:\n *\n * - The login fails. A preview that no longer resolves (the role was deleted, or it belongs to\n * another tenant) grants nothing, and a login with no permissions throws. Without this the user\n * would be stuck on that error screen, because the selection survives a reload.\n * - It was started by someone else. A session can end without going through log out, so the next\n * person on the browser would otherwise inherit whatever the last one was previewing.\n *\n * Any login failure drops the preview, not only the one a bad preview causes. The login path throws\n * plain errors, so there is nothing to tell \"no permissions\" from a network error by. That errs on\n * the safe side: a transient failure costs the preview and one retry, and the user is back on\n * their own permissions. Narrowing it needs a typed error from LogInUseCase.\n */\nclass LogInUseCaseDecoratorImpl implements LogInUseCase.Interface {\n constructor(\n private assumePermissionsContext: AssumePermissionsContext.Interface,\n private identityContext: IdentityContext.Interface,\n private decoratee: LogInUseCase.Interface\n ) {}\n\n async execute(params: LogInUseCase.Params): Promise<LogInUseCase.Result> {\n const active = this.assumePermissionsContext.get();\n\n if (!active) {\n return this.decoratee.execute(params);\n }\n\n let result: LogInUseCase.Result;\n try {\n result = await this.decoratee.execute(params);\n } catch {\n return this.loginWithoutAssumedPermissions(params);\n }\n\n // Not logged in yet (the user is moving to, or picking, another tenant): no identity to check.\n if (result.type !== \"loggedIn\") {\n return result;\n }\n\n const identity = this.identityContext.getIdentity();\n if (identity.id !== active.startedBy) {\n return this.loginWithoutAssumedPermissions(params);\n }\n\n return result;\n }\n\n private async loginWithoutAssumedPermissions(\n params: LogInUseCase.Params\n ): Promise<LogInUseCase.Result> {\n this.assumePermissionsContext.set(null);\n return this.decoratee.execute(params);\n }\n}\n\nexport const LogInUseCaseDecorator = LogInUseCase.createDecorator({\n decorator: LogInUseCaseDecoratorImpl,\n dependencies: [AssumePermissionsContext, IdentityContext]\n});\n"],"names":["LogInUseCaseDecoratorImpl","assumePermissionsContext","identityContext","decoratee","params","active","result","identity","LogInUseCaseDecorator","LogInUseCase","AssumePermissionsContext","IdentityContext"],"mappings":";;;AAsBA,MAAMA;IACF,YACYC,wBAA4D,EAC5DC,eAA0C,EAC1CC,SAAiC,CAC3C;aAHUF,wBAAwB,GAAxBA;aACAC,eAAe,GAAfA;aACAC,SAAS,GAATA;IACT;IAEH,MAAM,QAAQC,MAA2B,EAAgC;QACrE,MAAMC,SAAS,IAAI,CAAC,wBAAwB,CAAC,GAAG;QAEhD,IAAI,CAACA,QACD,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAACD;QAGlC,IAAIE;QACJ,IAAI;YACAA,SAAS,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAACF;QAC1C,EAAE,OAAM;YACJ,OAAO,IAAI,CAAC,8BAA8B,CAACA;QAC/C;QAGA,IAAIE,AAAgB,eAAhBA,OAAO,IAAI,EACX,OAAOA;QAGX,MAAMC,WAAW,IAAI,CAAC,eAAe,CAAC,WAAW;QACjD,IAAIA,SAAS,EAAE,KAAKF,OAAO,SAAS,EAChC,OAAO,IAAI,CAAC,8BAA8B,CAACD;QAG/C,OAAOE;IACX;IAEA,MAAc,+BACVF,MAA2B,EACC;QAC5B,IAAI,CAAC,wBAAwB,CAAC,GAAG,CAAC;QAClC,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAACA;IAClC;AACJ;AAEO,MAAMI,wBAAwBC,aAAa,eAAe,CAAC;IAC9D,WAAWT;IACX,cAAc;QAACU;QAA0BC;KAAgB;AAC7D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/formModel/FormView.js","sources":["../../../src/features/formModel/FormView.tsx"],"sourcesContent":["import React, { createContext, useContext, useMemo } from \"react\";\nimport { observer } from \"mobx-react-lite\";\nimport {\n Alert,\n Grid,\n IconButton,\n Separator,\n Tabs,\n Text,\n Tooltip,\n useToast\n} from \"@webiny/admin-ui\";\nimport { ReactComponent as CopyIcon } from \"@webiny/icons/content_copy.svg\";\nimport { ReactComponent as PasteIcon } from \"@webiny/icons/content_paste.svg\";\nimport { DevToolsSection } from \"@webiny/react-properties\";\nimport type {\n IFormVM,\n LayoutNodeVM,\n IRowNodeVM,\n IFieldVM,\n ITabsNodeVM,\n ISeparatorNodeVM,\n IAlertNodeVM,\n IElementNodeVM\n} from \"./abstractions.js\";\nimport type { Icon } from \"~/components/IconPicker/types.js\";\nimport type { IconProp } from \"@fortawesome/fontawesome-svg-core\";\nimport { FontAwesomeIcon } from \"@fortawesome/react-fontawesome\";\nimport { DeveloperMode } from \"~/components/DeveloperMode/DeveloperMode.js\";\nimport { useFieldRenderers } from \"~/features/formModel/useFieldRenderers.js\";\nimport { useLayoutRenderers } from \"~/features/formModel/useLayoutRenderers.js\";\n\nexport function renderTabIcon(icon: Icon | undefined): React.ReactElement | undefined {\n if (!icon || typeof icon.name !== \"string\") {\n return undefined;\n }\n return <FontAwesomeIcon icon={icon.name.split(\"/\") as IconProp} />;\n}\n\n/**\n * A field renderer component receives a FieldVM and renders the appropriate UI.\n */\nexport type FieldRendererComponent = React.ComponentType<{ field: IFieldVM }>;\n\n/**\n * Map of renderer keys to React components for fields.\n * Lookup order: `{type}:{renderer}` → `{type}`.\n */\nexport type FieldRenderers = Record<string, FieldRendererComponent>;\n\n/**\n * Map of renderer keys to React components for layout nodes.\n */\nexport type LayoutRenderers = Record<string, React.ComponentType<any>>;\n\ninterface FormViewRenderers {\n fieldRenderers: FieldRenderers;\n layoutRenderers: LayoutRenderers;\n}\n\nconst FormViewRenderersContext = createContext<FormViewRenderers | null>(null);\n\nconst useFormViewRenderers = (): FormViewRenderers => {\n const ctx = useContext(FormViewRenderersContext);\n if (!ctx) {\n throw new Error(\"useFormViewRenderers must be used within a FormView.\");\n }\n return ctx;\n};\n\nexport { useFormViewRenderers };\n\ninterface FormViewProps {\n name: string;\n form: IFormVM;\n renderers?: FieldRenderers;\n layoutRenderers?: LayoutRenderers;\n}\n\n/**\n * Generic form view that walks layout nodes and renders fields.\n * This component is stateless — it reads from the FormVM and delegates to renderers.\n */\nexport const FormView = observer(({ name, form, renderers, layoutRenderers }: FormViewProps) => {\n const defaultFieldRenderers = useFieldRenderers();\n const defaultLayoutRenderers = useLayoutRenderers();\n\n const value = useMemo(\n () => ({\n fieldRenderers: renderers ?? defaultFieldRenderers,\n layoutRenderers: layoutRenderers ?? defaultLayoutRenderers\n }),\n [renderers, defaultFieldRenderers, layoutRenderers, defaultLayoutRenderers]\n );\n\n return (\n <FormViewRenderersContext.Provider value={value}>\n <DevToolsSection name={name} group=\"Forms\" data={form.getData()} views={\"raw\"} />\n <div className=\"w-full relative flex flex-col gap-4\">\n <DevModeTools form={form} />\n {form.layout.map((node, index) => (\n <LayoutNodeRenderer key={index} node={node} />\n ))}\n </div>\n </FormViewRenderersContext.Provider>\n );\n});\n\nexport const LayoutNodeRenderer = observer(({ node }: { node: LayoutNodeVM }) => {\n switch (node.type) {\n case \"row\":\n return <RowNodeRenderer node={node} />;\n case \"separator\":\n return <SeparatorNodeRenderer node={node} />;\n case \"alert\":\n return <AlertNodeRenderer node={node} />;\n case \"tabs\":\n return <TabsNodeRenderer node={node} />;\n case \"element\":\n return <ElementNodeRenderer node={node} />;\n default:\n return null;\n }\n});\n\nconst RowNodeRenderer = observer(({ node }: { node: IRowNodeVM }) => {\n const { fieldRenderers } = useFormViewRenderers();\n\n return (\n <Grid>\n {node.fields.map(field => {\n const span = Math.floor(12 / node.fields.length) as React.ComponentProps<\n typeof Grid.Column\n >[\"span\"];\n\n return (\n <Grid.Column key={field.name} span={span}>\n <FieldRenderer field={field} renderers={fieldRenderers} />\n </Grid.Column>\n );\n })}\n </Grid>\n );\n});\n\ninterface FieldRendererProps {\n field: IFieldVM;\n renderers: FieldRenderers;\n}\n\nconst FieldRenderer = observer(({ field, renderers }: FieldRendererProps) => {\n const Renderer = field.renderer ? renderers[field.renderer] : undefined;\n\n if (!Renderer) {\n if (process.env.NODE_ENV === \"development\") {\n console.warn(\n `[FormView] No renderer found for field \"${field.name}\" (renderer: \"${field.renderer || \"none\"}\").`\n );\n }\n return null;\n }\n\n return <Renderer field={field} />;\n});\n\nconst SeparatorNodeRenderer = observer(function SeparatorNodeRenderer({\n node\n}: {\n node: ISeparatorNodeVM;\n}) {\n if (node.title) {\n return (\n <div>\n <Separator variant={\"accent\"} labelPosition={\"start\"}>\n {node.title}\n </Separator>\n {node.description ? (\n <Text size={\"sm\"} className={\"mt-xs\"}>\n {node.description}\n </Text>\n ) : null}\n </div>\n );\n }\n return <Separator variant={\"dimmed\"} />;\n});\n\nconst AlertNodeRenderer = observer(function AlertNodeRenderer({ node }: { node: IAlertNodeVM }) {\n if (!node.message) {\n return null;\n }\n return <Alert type={node.alertType}>{node.message}</Alert>;\n});\n\nexport interface TabsNodeRendererProps {\n node: ITabsNodeVM;\n}\n\nconst TabsNodeRenderer = observer(({ node }: TabsNodeRendererProps) => {\n const { layoutRenderers } = useFormViewRenderers();\n\n if (node.renderer) {\n const CustomRenderer = layoutRenderers[node.renderer];\n if (CustomRenderer) {\n return <CustomRenderer node={node} />;\n }\n }\n\n return (\n <Tabs\n value={node.activeTabId}\n onValueChange={id => node.setActiveTab(id)}\n tabs={node.tabs.map(tab => (\n <Tabs.Tab\n key={tab.id}\n value={tab.id}\n icon={renderTabIcon(tab.icon)}\n trigger={\n <>\n {tab.label}\n {tab.hasErrors && (\n <span className=\"ml-1 text-destructive-default text-xs\">*</span>\n )}\n </>\n }\n disabled={tab.disabled}\n content={\n <div className={\"flex flex-col gap-4 mt-md\"}>\n {tab.layout.map((childNode, index) => (\n <LayoutNodeRenderer key={index} node={childNode} />\n ))}\n </div>\n }\n />\n ))}\n />\n );\n});\n\nconst ElementNodeRenderer = observer(({ node }: { node: IElementNodeVM }) => {\n const { fieldRenderers } = useFormViewRenderers();\n const Renderer = fieldRenderers[`element:${node.renderer}`];\n\n if (!Renderer) {\n if (process.env.NODE_ENV === \"development\") {\n console.warn(`[FormView] No renderer found for element \"${node.renderer}\".`);\n }\n return null;\n }\n\n return <Renderer field={{ ...node.props } as any} />;\n});\n\ninterface DevModelToolsProps {\n form: IFormVM;\n}\n\nconst DevModeTools = ({ form }: DevModelToolsProps) => {\n const toast = useToast();\n\n const handleCopy = () => {\n const data = form.getData();\n navigator.clipboard.writeText(JSON.stringify(data, null, 2));\n toast.showSuccessToast({ title: \"Form data copied to clipboard.\" });\n };\n\n const handlePaste = async () => {\n try {\n const text = await navigator.clipboard.readText();\n const data = JSON.parse(text);\n form.setData(data);\n toast.showSuccessToast({ title: \"Form data imported from clipboard.\" });\n } catch {\n toast.showWarningToast({\n title: \"Failed to import. Make sure clipboard contains valid JSON.\"\n });\n }\n };\n return (\n <DeveloperMode>\n <div className=\"absolute top-0 right-0 w-[200px] h-[80px] z-10 group/devtools\">\n <div className=\"absolute top-0 right-0 flex gap-xs opacity-0 group-hover/devtools:opacity-100 transition-opacity\">\n <Tooltip\n content=\"Copy form data to clipboard\"\n trigger={\n <IconButton\n variant={\"secondary\"}\n icon={<CopyIcon />}\n onClick={handleCopy}\n size=\"sm\"\n />\n }\n />\n <Tooltip\n content=\"Paste form data from clipboard\"\n trigger={\n <IconButton\n variant={\"secondary\"}\n icon={<PasteIcon />}\n onClick={handlePaste}\n size=\"sm\"\n />\n }\n />\n </div>\n </div>\n </DeveloperMode>\n );\n};\n"],"names":["renderTabIcon","icon","FontAwesomeIcon","FormViewRenderersContext","createContext","useFormViewRenderers","ctx","useContext","Error","FormView","observer","name","form","renderers","layoutRenderers","defaultFieldRenderers","useFieldRenderers","defaultLayoutRenderers","useLayoutRenderers","value","useMemo","DevToolsSection","DevModeTools","node","index","LayoutNodeRenderer","RowNodeRenderer","SeparatorNodeRenderer","AlertNodeRenderer","TabsNodeRenderer","ElementNodeRenderer","fieldRenderers","Grid","field","span","Math","FieldRenderer","Renderer","undefined","process","console","Separator","Text","Alert","CustomRenderer","Tabs","id","tab","childNode","toast","useToast","handleCopy","data","navigator","JSON","handlePaste","text","DeveloperMode","Tooltip","IconButton","CopyIcon","PasteIcon"],"mappings":";;;;;;;;;;AAgCO,SAASA,cAAcC,IAAsB;IAChD,IAAI,CAACA,QAAQ,AAAqB,YAArB,OAAOA,KAAK,IAAI,EACzB;IAEJ,OAAO,WAAP,GAAO,oBAACC,iBAAeA;QAAC,MAAMD,KAAK,IAAI,CAAC,KAAK,CAAC;;AAClD;AAuBA,MAAME,2BAA2B,WAAHA,GAAGC,cAAwC;AAEzE,MAAMC,uBAAuB;IACzB,MAAMC,MAAMC,WAAWJ;IACvB,IAAI,CAACG,KACD,MAAM,IAAIE,MAAM;IAEpB,OAAOF;AACX;AAeO,MAAMG,WAAWC,SAAS,CAAC,EAAEC,IAAI,EAAEC,IAAI,EAAEC,SAAS,EAAEC,eAAe,EAAiB;IACvF,MAAMC,wBAAwBC;IAC9B,MAAMC,yBAAyBC;IAE/B,MAAMC,QAAQC,QACV,IAAO;YACH,gBAAgBP,aAAaE;YAC7B,iBAAiBD,mBAAmBG;QACxC,IACA;QAACJ;QAAWE;QAAuBD;QAAiBG;KAAuB;IAG/E,OAAO,WAAP,GACI,oBAACd,yBAAyB,QAAQ;QAAC,OAAOgB;qBACtC,oBAACE,iBAAeA;QAAC,MAAMV;QAAM,OAAM;QAAQ,MAAMC,KAAK,OAAO;QAAI,OAAO;sBACxE,oBAAC;QAAI,WAAU;qBACX,oBAACU,cAAYA;QAAC,MAAMV;QACnBA,KAAK,MAAM,CAAC,GAAG,CAAC,CAACW,MAAMC,QAAAA,WAAAA,GACpB,oBAACC,oBAAkBA;YAAC,KAAKD;YAAO,MAAMD;;AAK1D;AAEO,MAAME,qBAAqBf,SAAS,CAAC,EAAEa,IAAI,EAA0B;IACxE,OAAQA,KAAK,IAAI;QACb,KAAK;YACD,OAAO,WAAP,GAAO,oBAACG,iBAAeA;gBAAC,MAAMH;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AAOA;QACJ,SAAQ;QACR,uBACI,oBAACC,YAAUA;YACP,SAAS;YACT,oBAAM,oBAACE,kCAASA;YAChB,SAASN;YACT,MAAK;;;AAQrC"}
|
|
1
|
+
{"version":3,"file":"features/formModel/FormView.js","sources":["../../../src/features/formModel/FormView.tsx"],"sourcesContent":["import React, { createContext, useContext, useMemo } from \"react\";\nimport { observer } from \"mobx-react-lite\";\nimport {\n Alert,\n Grid,\n IconButton,\n Separator,\n Tabs,\n Text,\n Tooltip,\n useToast\n} from \"@webiny/admin-ui\";\nimport { ReactComponent as CopyIcon } from \"@webiny/icons/content_copy.svg\";\nimport { ReactComponent as PasteIcon } from \"@webiny/icons/content_paste.svg\";\nimport { DevToolsSection } from \"@webiny/react-properties\";\nimport type {\n IFormVM,\n LayoutNodeVM,\n IRowNodeVM,\n IFieldVM,\n ITabsNodeVM,\n ISeparatorNodeVM,\n IAlertNodeVM,\n IElementNodeVM\n} from \"./abstractions.js\";\nimport type { Icon } from \"~/components/IconPicker/types.js\";\nimport type { IconProp } from \"@fortawesome/fontawesome-svg-core\";\nimport { FontAwesomeIcon } from \"@fortawesome/react-fontawesome\";\nimport { DeveloperMode } from \"~/components/DeveloperMode/DeveloperMode.js\";\nimport { useFieldRenderers } from \"~/features/formModel/useFieldRenderers.js\";\nimport { useLayoutRenderers } from \"~/features/formModel/useLayoutRenderers.js\";\n\nexport function renderTabIcon(icon: Icon | undefined): React.ReactElement | undefined {\n if (!icon || typeof icon.name !== \"string\") {\n return undefined;\n }\n return <FontAwesomeIcon icon={icon.name.split(\"/\") as IconProp} />;\n}\n\n/**\n * A field renderer component receives a FieldVM and renders the appropriate UI.\n */\nexport type FieldRendererComponent = React.ComponentType<{ field: IFieldVM }>;\n\n/**\n * Map of renderer keys to React components for fields.\n * Lookup order: `{type}:{renderer}` → `{type}`.\n */\nexport type FieldRenderers = Record<string, FieldRendererComponent>;\n\n/**\n * Map of renderer keys to React components for layout nodes.\n */\nexport type LayoutRenderers = Record<string, React.ComponentType<any>>;\n\ninterface FormViewRenderers {\n fieldRenderers: FieldRenderers;\n layoutRenderers: LayoutRenderers;\n}\n\nconst FormViewRenderersContext = createContext<FormViewRenderers | null>(null);\n\nconst useFormViewRenderers = (): FormViewRenderers => {\n const ctx = useContext(FormViewRenderersContext);\n if (!ctx) {\n throw new Error(\"useFormViewRenderers must be used within a FormView.\");\n }\n return ctx;\n};\n\nexport { useFormViewRenderers };\n\ninterface FormViewProps {\n name: string;\n form: IFormVM;\n renderers?: FieldRenderers;\n layoutRenderers?: LayoutRenderers;\n}\n\n/**\n * Generic form view that walks layout nodes and renders fields.\n * This component is stateless — it reads from the FormVM and delegates to renderers.\n */\nexport const FormView = observer(({ name, form, renderers, layoutRenderers }: FormViewProps) => {\n const defaultFieldRenderers = useFieldRenderers();\n const defaultLayoutRenderers = useLayoutRenderers();\n\n const value = useMemo(\n () => ({\n fieldRenderers: renderers ?? defaultFieldRenderers,\n layoutRenderers: layoutRenderers ?? defaultLayoutRenderers\n }),\n [renderers, defaultFieldRenderers, layoutRenderers, defaultLayoutRenderers]\n );\n\n return (\n <FormViewRenderersContext.Provider value={value}>\n <DevToolsSection name={name} group=\"Forms\" data={form.getData()} views={\"raw\"} />\n <div className=\"w-full relative flex flex-col gap-4\">\n <DevModeTools form={form} />\n {form.layout.map((node, index) => (\n <LayoutNodeRenderer key={index} node={node} />\n ))}\n </div>\n </FormViewRenderersContext.Provider>\n );\n});\n\nexport const LayoutNodeRenderer = observer(({ node }: { node: LayoutNodeVM }) => {\n switch (node.type) {\n case \"row\":\n return <RowNodeRenderer node={node} />;\n case \"separator\":\n return <SeparatorNodeRenderer node={node} />;\n case \"alert\":\n return <AlertNodeRenderer node={node} />;\n case \"tabs\":\n return <TabsNodeRenderer node={node} />;\n case \"element\":\n return <ElementNodeRenderer node={node} />;\n default:\n return null;\n }\n});\n\nconst RowNodeRenderer = observer(({ node }: { node: IRowNodeVM }) => {\n const { fieldRenderers } = useFormViewRenderers();\n\n return (\n <Grid>\n {node.fields.map(field => {\n const span = Math.floor(12 / node.fields.length) as React.ComponentProps<\n typeof Grid.Column\n >[\"span\"];\n\n return (\n <Grid.Column key={field.name} span={span}>\n <FieldRenderer field={field} renderers={fieldRenderers} />\n </Grid.Column>\n );\n })}\n </Grid>\n );\n});\n\ninterface FieldRendererProps {\n field: IFieldVM;\n renderers: FieldRenderers;\n}\n\nconst FieldRenderer = observer(({ field, renderers }: FieldRendererProps) => {\n const Renderer = field.renderer ? renderers[field.renderer] : undefined;\n\n if (!Renderer) {\n if (process.env.NODE_ENV === \"development\") {\n console.warn(\n `[FormView] No renderer found for field \"${field.name}\" (renderer: \"${field.renderer || \"none\"}\").`\n );\n }\n return null;\n }\n\n return <Renderer field={field} />;\n});\n\nconst SeparatorNodeRenderer = observer(function SeparatorNodeRenderer({\n node\n}: {\n node: ISeparatorNodeVM;\n}) {\n if (node.title) {\n return (\n <div>\n <Separator variant={\"accent\"} labelPosition={\"start\"}>\n {node.title}\n </Separator>\n {node.description ? (\n <Text size={\"sm\"} className={\"mt-xs\"}>\n {node.description}\n </Text>\n ) : null}\n </div>\n );\n }\n return <Separator variant={\"dimmed\"} />;\n});\n\nconst AlertNodeRenderer = observer(function AlertNodeRenderer({ node }: { node: IAlertNodeVM }) {\n if (!node.message) {\n return null;\n }\n return <Alert type={node.alertType}>{node.message}</Alert>;\n});\n\nexport interface TabsNodeRendererProps {\n node: ITabsNodeVM;\n}\n\nconst TabsNodeRenderer = observer(({ node }: TabsNodeRendererProps) => {\n const { layoutRenderers } = useFormViewRenderers();\n\n if (node.renderer) {\n const CustomRenderer = layoutRenderers[node.renderer];\n if (CustomRenderer) {\n return <CustomRenderer node={node} />;\n }\n }\n\n return (\n <Tabs\n value={node.activeTabId}\n onValueChange={id => node.setActiveTab(id)}\n tabs={node.tabs.map(tab => (\n <Tabs.Tab\n key={tab.id}\n value={tab.id}\n icon={renderTabIcon(tab.icon)}\n trigger={\n <>\n {tab.label}\n {tab.hasErrors && (\n <span className=\"ml-1 text-destructive-default text-xs\">*</span>\n )}\n </>\n }\n disabled={tab.disabled}\n content={\n <div className={\"flex flex-col gap-4 mt-md\"}>\n {tab.layout.map((childNode, index) => (\n <LayoutNodeRenderer key={index} node={childNode} />\n ))}\n </div>\n }\n />\n ))}\n />\n );\n});\n\nconst ElementNodeRenderer = observer(({ node }: { node: IElementNodeVM }) => {\n const { fieldRenderers } = useFormViewRenderers();\n const Renderer = fieldRenderers[`element:${node.renderer}`];\n\n if (!Renderer) {\n if (process.env.NODE_ENV === \"development\") {\n console.warn(`[FormView] No renderer found for element \"${node.renderer}\".`);\n }\n return null;\n }\n\n return <Renderer field={{ ...node.props } as any} />;\n});\n\ninterface DevModelToolsProps {\n form: IFormVM;\n}\n\nconst DevModeTools = ({ form }: DevModelToolsProps) => {\n const toast = useToast();\n\n const handleCopy = () => {\n const data = form.getData();\n navigator.clipboard.writeText(JSON.stringify(data, null, 2));\n toast.showSuccessToast({ title: \"Form data copied to clipboard.\" });\n };\n\n const handlePaste = async () => {\n try {\n const text = await navigator.clipboard.readText();\n const data = JSON.parse(text);\n form.setData(data);\n toast.showSuccessToast({ title: \"Form data imported from clipboard.\" });\n } catch {\n toast.showWarningToast({\n title: \"Failed to import. Make sure clipboard contains valid JSON.\"\n });\n }\n };\n return (\n <DeveloperMode>\n <div className=\"absolute top-0 right-0 w-[200px] h-[80px] z-10 group/devtools\">\n <div className=\"absolute top-0 right-0 flex gap-xs opacity-0 group-hover/devtools:opacity-100 transition-opacity\">\n <Tooltip\n content=\"Copy form data to clipboard\"\n trigger={\n <IconButton\n variant={\"secondary\"}\n icon={<CopyIcon />}\n onClick={handleCopy}\n size=\"sm\"\n />\n }\n />\n <Tooltip\n content=\"Paste form data from clipboard\"\n trigger={\n <IconButton\n variant={\"secondary\"}\n icon={<PasteIcon />}\n onClick={handlePaste}\n size=\"sm\"\n />\n }\n />\n </div>\n </div>\n </DeveloperMode>\n );\n};\n"],"names":["renderTabIcon","icon","FontAwesomeIcon","FormViewRenderersContext","createContext","useFormViewRenderers","ctx","useContext","Error","FormView","observer","name","form","renderers","layoutRenderers","defaultFieldRenderers","useFieldRenderers","defaultLayoutRenderers","useLayoutRenderers","value","useMemo","DevToolsSection","DevModeTools","node","index","LayoutNodeRenderer","RowNodeRenderer","SeparatorNodeRenderer","AlertNodeRenderer","TabsNodeRenderer","ElementNodeRenderer","fieldRenderers","Grid","field","span","Math","FieldRenderer","Renderer","undefined","process","console","Separator","Text","Alert","CustomRenderer","Tabs","id","tab","childNode","toast","useToast","handleCopy","data","navigator","JSON","handlePaste","text","DeveloperMode","Tooltip","IconButton","CopyIcon","PasteIcon"],"mappings":";;;;;;;;;;AAgCO,SAASA,cAAcC,IAAsB;IAChD,IAAI,CAACA,QAAQ,AAAqB,YAArB,OAAOA,KAAK,IAAI,EACzB;IAEJ,OAAO,WAAP,GAAO,oBAACC,iBAAeA;QAAC,MAAMD,KAAK,IAAI,CAAC,KAAK,CAAC;;AAClD;AAuBA,MAAME,2BAA2B,WAA3BA,GAA2BC,cAAwC;AAEzE,MAAMC,uBAAuB;IACzB,MAAMC,MAAMC,WAAWJ;IACvB,IAAI,CAACG,KACD,MAAM,IAAIE,MAAM;IAEpB,OAAOF;AACX;AAeO,MAAMG,WAAWC,SAAS,CAAC,EAAEC,IAAI,EAAEC,IAAI,EAAEC,SAAS,EAAEC,eAAe,EAAiB;IACvF,MAAMC,wBAAwBC;IAC9B,MAAMC,yBAAyBC;IAE/B,MAAMC,QAAQC,QACV,IAAO;YACH,gBAAgBP,aAAaE;YAC7B,iBAAiBD,mBAAmBG;QACxC,IACA;QAACJ;QAAWE;QAAuBD;QAAiBG;KAAuB;IAG/E,OAAO,WAAP,GACI,oBAACd,yBAAyB,QAAQ;QAAC,OAAOgB;qBACtC,oBAACE,iBAAeA;QAAC,MAAMV;QAAM,OAAM;QAAQ,MAAMC,KAAK,OAAO;QAAI,OAAO;sBACxE,oBAAC;QAAI,WAAU;qBACX,oBAACU,cAAAA;QAAa,MAAMV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gBACnB,OAAO;YACX;QACJ;IACJ;IACA,OAAO,WAAP,GACI,oBAACQ,eAAaA,MAAAA,WAAAA,GACV,oBAAC;QAAI,WAAU;qBACX,oBAAC;QAAI,WAAU;qBACX,oBAACC,SAAOA;QACJ,SAAQ;QACR,uBACI,oBAACC,YAAUA;YACP,SAAS;YACT,oBAAM,oBAACC,gBAAQA;YACf,SAAST;YACT,MAAK;;sBAIjB,oBAACO,SAAOA;QACJ,SAAQ;QACR,uBACI,oBAACC,YAAUA;YACP,SAAS;YACT,oBAAM,oBAACE,kCAASA;YAChB,SAASN;YACT,MAAK;;;AAQrC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/formModel/createFieldRenderer.js","sources":["../../../src/features/formModel/createFieldRenderer.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from \"react\";\nimport { observer } from \"mobx-react-lite\";\nimport { makeDecoratable } from \"@webiny/react-composition\";\nimport type { IFieldVM, IObjectFieldVM, FieldRendererSettings } from \"./abstractions.js\";\n\n/**\n * Decoratable wrapper rendered around every leaf field's content. Features can decorate it to\n * inject per-field UI (e.g. a comment marker) keyed on `field.qualifiedName`, without forking\n * the form. By default it renders the field content unchanged.\n */\nexport const FormFieldWrapper = makeDecoratable(\n \"FormFieldWrapper\",\n ({ children }: { field: IFieldVM; children?: React.ReactNode }) => {\n return <>{children}</>;\n }\n);\n\ntype RendererField<TName extends string> = IFieldVM & {\n rendererSettings: FieldRendererSettings<TName>;\n};\n\ntype ObjectRendererField<TName extends string> = IObjectFieldVM & {\n rendererSettings: FieldRendererSettings<TName>;\n};\n\ntype FieldRendererFn<TName extends string> = (props: {\n field: RendererField<TName>;\n}) => React.ReactNode;\n\n// How long the field stays visually highlighted after focus lands, so the user's eye is drawn\n// to where \"jump to field\" (a comment locator, a form error) scrolled to.\nconst FOCUS_HIGHLIGHT_MS = 1800;\n\n// A 6px tint around the field, then a 2px ring outside it.\nconst FOCUS_HIGHLIGHT_SHADOW = \"0 0 0 6px var(--color-primary-100), 0 0 0 8px var(--color-primary)\";\n\nconst ScrollOnFocus = observer(\n ({ field, children }: { field: IFieldVM; children: React.ReactNode }) => {\n const ref = useRef<HTMLDivElement>(null);\n const [highlighted, setHighlighted] = useState(false);\n const highlightTimer = useRef<number | null>(null);\n\n useEffect(() => {\n if (field.focusRequested && ref.current) {\n setTimeout(() => {\n ref.current?.scrollIntoView({ behavior: \"smooth\", block: \"center\" });\n }, 150);\n // Flash a highlight ring so it's obvious where focus landed. The timer is kept in a\n // ref (not tied to the effect cleanup) so clearing the focus request below — which\n // re-runs this effect — doesn't cut the highlight short.\n setHighlighted(true);\n if (highlightTimer.current) {\n window.clearTimeout(highlightTimer.current);\n }\n highlightTimer.current = window.setTimeout(\n () => setHighlighted(false),\n FOCUS_HIGHLIGHT_MS\n );\n }\n field.clearFocusRequest();\n }, [field.focusRequested]);\n\n useEffect(() => {\n return () => {\n if (highlightTimer.current) {\n window.clearTimeout(highlightTimer.current);\n }\n };\n }, []);\n\n return (\n <div\n ref={ref}\n data-field-path={field.qualifiedName}\n style={{\n /*\n * The highlight is drawn with shadows, which paint around the field without\n * taking up room. Padding with a matching negative margin looked the same, but\n * the padded box still stuck out of the field, so a scroll area around a form\n * always had 6px to scroll.\n */\n borderRadius: 2,\n transition: \"box-shadow .35s ease, background-color .35s ease\",\n boxShadow: highlighted ? FOCUS_HIGHLIGHT_SHADOW : undefined,\n backgroundColor: highlighted ? \"var(--color-primary-100)\" : undefined\n }}\n >\n <FormFieldWrapper field={field}>{children}</FormFieldWrapper>\n </div>\n );\n }\n);\n\nexport function createFieldRenderer<TName extends string = string>(\n render: FieldRendererFn<TName>\n): React.ComponentType<{ field: IFieldVM }> {\n const Inner = observer(render as FieldRendererFn<string>) as unknown as React.ComponentType<{\n field: IFieldVM;\n }>;\n\n const Wrapper = observer(({ field }: { field: IFieldVM }) => (\n <ScrollOnFocus field={field}>\n <Inner field={field} />\n </ScrollOnFocus>\n ));\n\n return Wrapper as unknown as React.ComponentType<{ field: IFieldVM }>;\n}\n\nexport function createObjectFieldRenderer<TName extends string = string>(\n render: (props: { field: ObjectRendererField<TName> }) => React.ReactNode\n): React.ComponentType<{ field: IFieldVM }> {\n const Wrapped = (props: { field: IFieldVM }) => {\n if (props.field.type !== \"object\") {\n return null;\n }\n return (render as (p: { field: IFieldVM }) => React.ReactNode)(props);\n };\n return observer(Wrapped) as unknown as React.ComponentType<{ field: IFieldVM }>;\n}\n"],"names":["FormFieldWrapper","makeDecoratable","children","FOCUS_HIGHLIGHT_MS","FOCUS_HIGHLIGHT_SHADOW","ScrollOnFocus","observer","field","ref","useRef","highlighted","setHighlighted","useState","highlightTimer","useEffect","setTimeout","window","undefined","createFieldRenderer","render","Inner","Wrapper","createObjectFieldRenderer","Wrapped","props"],"mappings":";;;AAUO,MAAMA,mBAAmBC,gBAC5B,oBACA,CAAC,EAAEC,QAAQ,EAAmD,GACnD,WAAP,GAAO,0CAAGA;AAkBlB,MAAMC,qBAAqB;AAG3B,MAAMC,yBAAyB;AAE/B,MAAMC,gBAAgBC,SAClB,CAAC,EAAEC,KAAK,EAAEL,QAAQ,EAAkD;IAChE,MAAMM,MAAMC,OAAuB;IACnC,MAAM,CAACC,aAAaC,eAAe,GAAGC,SAAS;IAC/C,MAAMC,iBAAiBJ,OAAsB;IAE7CK,UAAU;QACN,IAAIP,MAAM,cAAc,IAAIC,IAAI,OAAO,EAAE;YACrCO,WAAW;gBACPP,IAAI,OAAO,EAAE,eAAe;oBAAE,UAAU;oBAAU,OAAO;gBAAS;YACtE,GAAG;YAIHG,eAAe;YACf,IAAIE,eAAe,OAAO,EACtBG,OAAO,YAAY,CAACH,eAAe,OAAO;YAE9CA,eAAe,OAAO,GAAGG,OAAO,UAAU,CACtC,IAAML,eAAe,QACrBR;QAER;QACAI,MAAM,iBAAiB;IAC3B,GAAG;QAACA,MAAM,cAAc;KAAC;IAEzBO,UAAU,IACC;YACH,IAAID,eAAe,OAAO,EACtBG,OAAO,YAAY,CAACH,eAAe,OAAO;QAElD,GACD,EAAE;IAEL,OAAO,WAAP,GACI,oBAAC;QACG,KAAKL;QACL,mBAAiBD,MAAM,aAAa;QACpC,OAAO;YAOH,cAAc;YACd,YAAY;YACZ,WAAWG,cAAcN,yBAAyBa;YAClD,iBAAiBP,cAAc,6BAA6BO;QAChE;qBAEA,oBAACjB,
|
|
1
|
+
{"version":3,"file":"features/formModel/createFieldRenderer.js","sources":["../../../src/features/formModel/createFieldRenderer.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from \"react\";\nimport { observer } from \"mobx-react-lite\";\nimport { makeDecoratable } from \"@webiny/react-composition\";\nimport type { IFieldVM, IObjectFieldVM, FieldRendererSettings } from \"./abstractions.js\";\n\n/**\n * Decoratable wrapper rendered around every leaf field's content. Features can decorate it to\n * inject per-field UI (e.g. a comment marker) keyed on `field.qualifiedName`, without forking\n * the form. By default it renders the field content unchanged.\n */\nexport const FormFieldWrapper = makeDecoratable(\n \"FormFieldWrapper\",\n ({ children }: { field: IFieldVM; children?: React.ReactNode }) => {\n return <>{children}</>;\n }\n);\n\ntype RendererField<TName extends string> = IFieldVM & {\n rendererSettings: FieldRendererSettings<TName>;\n};\n\ntype ObjectRendererField<TName extends string> = IObjectFieldVM & {\n rendererSettings: FieldRendererSettings<TName>;\n};\n\ntype FieldRendererFn<TName extends string> = (props: {\n field: RendererField<TName>;\n}) => React.ReactNode;\n\n// How long the field stays visually highlighted after focus lands, so the user's eye is drawn\n// to where \"jump to field\" (a comment locator, a form error) scrolled to.\nconst FOCUS_HIGHLIGHT_MS = 1800;\n\n// A 6px tint around the field, then a 2px ring outside it.\nconst FOCUS_HIGHLIGHT_SHADOW = \"0 0 0 6px var(--color-primary-100), 0 0 0 8px var(--color-primary)\";\n\nconst ScrollOnFocus = observer(\n ({ field, children }: { field: IFieldVM; children: React.ReactNode }) => {\n const ref = useRef<HTMLDivElement>(null);\n const [highlighted, setHighlighted] = useState(false);\n const highlightTimer = useRef<number | null>(null);\n\n useEffect(() => {\n if (field.focusRequested && ref.current) {\n setTimeout(() => {\n ref.current?.scrollIntoView({ behavior: \"smooth\", block: \"center\" });\n }, 150);\n // Flash a highlight ring so it's obvious where focus landed. The timer is kept in a\n // ref (not tied to the effect cleanup) so clearing the focus request below — which\n // re-runs this effect — doesn't cut the highlight short.\n setHighlighted(true);\n if (highlightTimer.current) {\n window.clearTimeout(highlightTimer.current);\n }\n highlightTimer.current = window.setTimeout(\n () => setHighlighted(false),\n FOCUS_HIGHLIGHT_MS\n );\n }\n field.clearFocusRequest();\n }, [field.focusRequested]);\n\n useEffect(() => {\n return () => {\n if (highlightTimer.current) {\n window.clearTimeout(highlightTimer.current);\n }\n };\n }, []);\n\n return (\n <div\n ref={ref}\n data-field-path={field.qualifiedName}\n style={{\n /*\n * The highlight is drawn with shadows, which paint around the field without\n * taking up room. Padding with a matching negative margin looked the same, but\n * the padded box still stuck out of the field, so a scroll area around a form\n * always had 6px to scroll.\n */\n borderRadius: 2,\n transition: \"box-shadow .35s ease, background-color .35s ease\",\n boxShadow: highlighted ? FOCUS_HIGHLIGHT_SHADOW : undefined,\n backgroundColor: highlighted ? \"var(--color-primary-100)\" : undefined\n }}\n >\n <FormFieldWrapper field={field}>{children}</FormFieldWrapper>\n </div>\n );\n }\n);\n\nexport function createFieldRenderer<TName extends string = string>(\n render: FieldRendererFn<TName>\n): React.ComponentType<{ field: IFieldVM }> {\n const Inner = observer(render as FieldRendererFn<string>) as unknown as React.ComponentType<{\n field: IFieldVM;\n }>;\n\n const Wrapper = observer(({ field }: { field: IFieldVM }) => (\n <ScrollOnFocus field={field}>\n <Inner field={field} />\n </ScrollOnFocus>\n ));\n\n return Wrapper as unknown as React.ComponentType<{ field: IFieldVM }>;\n}\n\nexport function createObjectFieldRenderer<TName extends string = string>(\n render: (props: { field: ObjectRendererField<TName> }) => React.ReactNode\n): React.ComponentType<{ field: IFieldVM }> {\n const Wrapped = (props: { field: IFieldVM }) => {\n if (props.field.type !== \"object\") {\n return null;\n }\n return (render as (p: { field: IFieldVM }) => React.ReactNode)(props);\n };\n return observer(Wrapped) as unknown as React.ComponentType<{ field: IFieldVM }>;\n}\n"],"names":["FormFieldWrapper","makeDecoratable","children","FOCUS_HIGHLIGHT_MS","FOCUS_HIGHLIGHT_SHADOW","ScrollOnFocus","observer","field","ref","useRef","highlighted","setHighlighted","useState","highlightTimer","useEffect","setTimeout","window","undefined","createFieldRenderer","render","Inner","Wrapper","createObjectFieldRenderer","Wrapped","props"],"mappings":";;;AAUO,MAAMA,mBAAmBC,gBAC5B,oBACA,CAAC,EAAEC,QAAQ,EAAmD,GACnD,WAAP,GAAO,0CAAGA;AAkBlB,MAAMC,qBAAqB;AAG3B,MAAMC,yBAAyB;AAE/B,MAAMC,gBAAgBC,SAClB,CAAC,EAAEC,KAAK,EAAEL,QAAQ,EAAkD;IAChE,MAAMM,MAAMC,OAAuB;IACnC,MAAM,CAACC,aAAaC,eAAe,GAAGC,SAAS;IAC/C,MAAMC,iBAAiBJ,OAAsB;IAE7CK,UAAU;QACN,IAAIP,MAAM,cAAc,IAAIC,IAAI,OAAO,EAAE;YACrCO,WAAW;gBACPP,IAAI,OAAO,EAAE,eAAe;oBAAE,UAAU;oBAAU,OAAO;gBAAS;YACtE,GAAG;YAIHG,eAAe;YACf,IAAIE,eAAe,OAAO,EACtBG,OAAO,YAAY,CAACH,eAAe,OAAO;YAE9CA,eAAe,OAAO,GAAGG,OAAO,UAAU,CACtC,IAAML,eAAe,QACrBR;QAER;QACAI,MAAM,iBAAiB;IAC3B,GAAG;QAACA,MAAM,cAAc;KAAC;IAEzBO,UAAU,IACC;YACH,IAAID,eAAe,OAAO,EACtBG,OAAO,YAAY,CAACH,eAAe,OAAO;QAElD,GACD,EAAE;IAEL,OAAO,WAAP,GACI,oBAAC;QACG,KAAKL;QACL,mBAAiBD,MAAM,aAAa;QACpC,OAAO;YAOH,cAAc;YACd,YAAY;YACZ,WAAWG,cAAcN,yBAAyBa;YAClD,iBAAiBP,cAAc,6BAA6BO;QAChE;qBAEA,oBAACjB,kBAAAA;QAAiB,OAAOO;OAAQL;AAG7C;AAGG,SAASgB,oBACZC,MAA8B;IAE9B,MAAMC,QAAQd,SAASa;IAIvB,MAAME,UAAUf,SAAS,CAAC,EAAEC,KAAK,EAAuB,iBACpD,oBAACF,eAAAA;YAAc,OAAOE;yBAClB,oBAACa,OAAAA;YAAM,OAAOb;;IAItB,OAAOc;AACX;AAEO,SAASC,0BACZH,MAAyE;IAEzE,MAAMI,UAAU,CAACC;QACb,IAAIA,AAAqB,aAArBA,MAAM,KAAK,CAAC,IAAI,EAChB,OAAO;QAEX,OAAQL,OAAuDK;IACnE;IACA,OAAOlB,SAASiB;AACpB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/formModel/demo/FormModelDemo.js","sources":["../../../../src/features/formModel/demo/FormModelDemo.tsx"],"sourcesContent":["import React, { useMemo } from \"react\";\nimport { observer } from \"mobx-react-lite\";\nimport { useFeature } from \"@webiny/app\";\nimport { Button } from \"@webiny/admin-ui\";\nimport { FormView } from \"../FormView.js\";\nimport { FormModelFeature } from \"../feature.js\";\nimport { FieldRenderersDemoPresenter } from \"./FieldRenderersDemoPresenter.js\";\nimport { FormModelDemoPresenter } from \"./FormModelDemoPresenter.js\";\nimport { FormModelPhase8c1Presenter } from \"./FormModelPhase8c1Presenter.js\";\nimport { FormModelPhase11Presenter } from \"./FormModelPhase11Presenter.js\";\n\nexport const FormModelDemo = observer(() => {\n const { formModelFactory } = useFeature(FormModelFeature);\n const presenter = useMemo(\n () => new FormModelDemoPresenter(formModelFactory),\n [formModelFactory]\n );\n\n const { form, data, lastSubmitted, isSubmitting, runtimeTemplateAdded, textTemplateRemoved } =\n presenter.vm;\n\n return (\n <div className={\"p-lg flex flex-col gap-2xl max-w-4xl mx-auto\"}>\n <FieldRenderersSection />\n\n <div className={\"flex flex-col gap-lg\"}>\n <div className={\"flex flex-col gap-sm\"}>\n <h2 className={\"text-xl font-semibold\"}>FormModel Demo — Phase 8</h2>\n <p className={\"text-sm text-neutral-strong\"}>\n Exercises the full Phase 8 surface: single-object templates ("Content\n Block"), templated lists ("Page Sections"), per-template\n layouts (Hero spans two rows; Rich Text uses a single row; templates without\n a layout entry fall back to default), and runtime template management via{\" \"}\n <code>field.templates.add/remove</code>. Change Plan to{\" \"}\n <code>enterprise</code> to reveal the "Premium Widget" template in\n the Content Block picker.\n </p>\n </div>\n\n <FormView name=\"Demo\" form={form} />\n\n <div className={\"flex flex-wrap gap-sm\"}>\n <Button\n text={isSubmitting ? \"Submitting…\" : \"Submit\"}\n variant={\"primary\"}\n onClick={() => presenter.submit()}\n disabled={isSubmitting}\n />\n <Button\n text={\"Reset\"}\n variant={\"secondary\"}\n onClick={() => presenter.reset()}\n disabled={isSubmitting}\n />\n <Button\n text={\n runtimeTemplateAdded\n ? 'Remove \"Runtime Banner\" from sections'\n : 'Add \"Runtime Banner\" to sections'\n }\n variant={\"tertiary\"}\n onClick={() => presenter.toggleRuntimeTemplate()}\n />\n <Button\n text={\n textTemplateRemoved\n ? 'Restore \"Rich Text\" on content'\n : 'Remove \"Rich Text\" from content'\n }\n variant={\"tertiary\"}\n onClick={() => presenter.toggleTextTemplate()}\n />\n </div>\n\n <div className={\"grid grid-cols-2 gap-md\"}>\n <DataPanel title={\"Current getData()\"} data={data} />\n <DataPanel title={\"Last submitted\"} data={lastSubmitted} />\n </div>\n </div>\n\n <Phase8c1Section />\n\n <Phase11Section />\n </div>\n );\n});\n\nconst FieldRenderersSection = observer(() => {\n const { formModelFactory } = useFeature(FormModelFeature);\n const presenter = useMemo(\n () => new FieldRenderersDemoPresenter(formModelFactory),\n [formModelFactory]\n );\n\n const { form, data, lastSubmitted, isSubmitting, formErrors } = presenter.vm;\n\n return (\n <div className={\"flex flex-col gap-lg\"}>\n <div className={\"flex flex-col gap-sm\"}>\n <h2 className={\"text-xl font-semibold\"}>Field Renderers Showcase</h2>\n <p className={\"text-sm text-neutral-strong\"}>\n All field renderer variants: text, number, boolean, select\n (dropdown/radio/checkboxes), date/time (4 variants), tags, textarea, multi-value\n lists, hidden, and dynamic zones. Renderers not yet implemented show nothing\n (console warning).\n </p>\n </div>\n\n <FormView name=\"Demo\" form={form} />\n\n {formErrors.length > 0 && (\n <div className={\"flex flex-col gap-xs\"}>\n <div className={\"text-sm font-medium\"}>Form errors</div>\n <ul className={\"text-xs text-error-strong list-disc pl-md\"}>\n {formErrors.map((e, i) => (\n <li key={i}>\n {e.path ? (\n <button\n type={\"button\"}\n className={\n \"underline cursor-pointer hover:text-error-default\"\n }\n onClick={() => presenter.focusField(e.path)}\n >\n <code>{e.path}</code>\n </button>\n ) : null}{\" \"}\n {e.message}\n </li>\n ))}\n </ul>\n </div>\n )}\n\n <div className={\"flex flex-wrap gap-sm\"}>\n <Button\n text={isSubmitting ? \"Submitting…\" : \"Submit\"}\n variant={\"primary\"}\n onClick={() => presenter.submit()}\n disabled={isSubmitting}\n />\n <Button\n text={\"Reset\"}\n variant={\"secondary\"}\n onClick={() => presenter.reset()}\n disabled={isSubmitting}\n />\n </div>\n\n <div className={\"grid grid-cols-2 gap-md\"}>\n <DataPanel title={\"Current getData()\"} data={data} />\n <DataPanel title={\"Last submitted\"} data={lastSubmitted} />\n </div>\n </div>\n );\n});\n\nconst Phase8c1Section = observer(() => {\n const { formModelFactory } = useFeature(FormModelFeature);\n const presenter = useMemo(\n () => new FormModelPhase8c1Presenter(formModelFactory),\n [formModelFactory]\n );\n\n const { form, data, lastSubmitted, isSubmitting } = presenter.vm;\n\n return (\n <div className={\"flex flex-col gap-lg border-t border-neutral-dimmed pt-lg\"}>\n <div className={\"flex flex-col gap-sm\"}>\n <h2 className={\"text-xl font-semibold\"}>FormModel Demo — Phase 8c.1</h2>\n <p className={\"text-sm text-neutral-strong\"}>\n Nested object layouts. A top-level <code>page</code> object whose inner layout\n is split across tabs (General / SEO). The SEO tab contains a nested{\" \"}\n <code>layout.object("seo", ...)</code> with its own row layout, and\n the SEO object itself contains another nested{\" \"}\n <code>layout.object("og", ...)</code> for the Open Graph fields. Phase\n 8c.1 walks the inner layout (including across tabs) and forwards each nested{\" \"}\n <code>layout.object()</code> to the matching child at build time.\n </p>\n </div>\n\n <FormView name=\"Demo\" form={form} />\n\n <div className={\"flex flex-wrap gap-sm\"}>\n <Button\n text={isSubmitting ? \"Submitting…\" : \"Submit\"}\n variant={\"primary\"}\n onClick={() => presenter.submit()}\n disabled={isSubmitting}\n />\n <Button\n text={\"Reset\"}\n variant={\"secondary\"}\n onClick={() => presenter.reset()}\n disabled={isSubmitting}\n />\n </div>\n\n <div className={\"grid grid-cols-2 gap-md\"}>\n <DataPanel title={\"Current getData()\"} data={data} />\n <DataPanel title={\"Last submitted\"} data={lastSubmitted} />\n </div>\n </div>\n );\n});\n\nconst Phase11Section = observer(() => {\n const { formModelFactory } = useFeature(FormModelFeature);\n const presenter = useMemo(\n () => new FormModelPhase11Presenter(formModelFactory),\n [formModelFactory]\n );\n\n const { form, data, lastSubmitted, isSubmitting, formErrors } = presenter.vm;\n\n return (\n <div className={\"flex flex-col gap-lg border-t border-neutral-dimmed pt-lg\"}>\n <div className={\"flex flex-col gap-sm\"}>\n <h2 className={\"text-xl font-semibold\"}>FormModel Demo — Phase 11</h2>\n <p className={\"text-sm text-neutral-strong\"}>\n Conditional required (<code>requiredWhen</code> on Seats — chained builder +\n modifier rules), derived fields (<code>computed</code> Full Name and{\" \"}\n <code>computedUntilDirty</code> Slug), modifier-style child addition via{\" \"}\n <code>field.as("object").fields()</code> adding Company/Bio to\n Profile, form-level rules (<code>addRule</code> with a Zod refinement for\n password match plus an imperative slug-length rule), and a layout assembled via{\" \"}\n <code>setLayout</code>.\n </p>\n </div>\n\n <FormView name=\"Demo\" form={form} />\n\n {formErrors.length > 0 && (\n <div className={\"flex flex-col gap-xs\"}>\n <div className={\"text-sm font-medium\"}>Form errors</div>\n <ul className={\"text-xs text-error-strong list-disc pl-md\"}>\n {formErrors.map((e, i) => (\n <li key={i}>\n {e.path ? <code>{e.path}</code> : null} {e.message}\n </li>\n ))}\n </ul>\n </div>\n )}\n\n <div className={\"flex flex-wrap gap-sm\"}>\n <Button\n text={isSubmitting ? \"Submitting…\" : \"Submit\"}\n variant={\"primary\"}\n onClick={() => presenter.submit()}\n disabled={isSubmitting}\n />\n <Button\n text={\"Reset\"}\n variant={\"secondary\"}\n onClick={() => presenter.reset()}\n disabled={isSubmitting}\n />\n </div>\n\n <div className={\"grid grid-cols-2 gap-md\"}>\n <DataPanel title={\"Current getData()\"} data={data} />\n <DataPanel title={\"Last submitted\"} data={lastSubmitted} />\n </div>\n </div>\n );\n});\n\nconst DataPanel = ({ title, data }: { title: string; data: unknown }) => {\n return (\n <div className={\"flex flex-col gap-xs\"}>\n <div className={\"text-sm font-medium\"}>{title}</div>\n <pre\n className={\n \"text-xs bg-neutral-subtle p-sm rounded border border-neutral-dimmed overflow-auto\"\n }\n >\n {data === null ? \"null\" : JSON.stringify(data, null, 2)}\n </pre>\n </div>\n );\n};\n"],"names":["FormModelDemo","observer","formModelFactory","useFeature","FormModelFeature","presenter","useMemo","FormModelDemoPresenter","form","data","lastSubmitted","isSubmitting","runtimeTemplateAdded","textTemplateRemoved","FieldRenderersSection","FormView","Button","DataPanel","Phase8c1Section","Phase11Section","FieldRenderersDemoPresenter","formErrors","e","i","FormModelPhase8c1Presenter","FormModelPhase11Presenter","title","JSON"],"mappings":";;;;;;;;;;AAWO,MAAMA,gBAAgBC,SAAS;IAClC,MAAM,EAAEC,gBAAgB,EAAE,GAAGC,WAAWC;IACxC,MAAMC,YAAYC,QACd,IAAM,IAAIC,uBAAuBL,mBACjC;QAACA;KAAiB;IAGtB,MAAM,EAAEM,IAAI,EAAEC,IAAI,EAAEC,aAAa,EAAEC,YAAY,EAAEC,oBAAoB,EAAEC,mBAAmB,EAAE,GACxFR,UAAU,EAAE;IAEhB,OAAO,WAAP,GACI,oBAAC;QAAI,WAAW;qBACZ,oBAACS,uBAAqBA,OAAAA,WAAAA,GAEtB,oB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ACC,GAAGC,IAAAA,WAAAA,GAChB,oBAAC;YAAG,KAAKA;WACJD,EAAE,IAAI,GAAG,WAAH,GAAG,oBAAC,cAAMA,EAAE,IAAI,IAAW,MAAK,KAAEA,EAAE,OAAO,oBAOtE,oBAAC;QAAI,WAAW;qBACZ,oBAACN,QAAMA;QACH,MAAML,eAAe,gBAAgB;QACrC,SAAS;QACT,SAAS,IAAMN,UAAU,MAAM;QAC/B,UAAUM;sBAEd,oBAACK,QAAMA;QACH,MAAM;QACN,SAAS;QACT,SAAS,IAAMX,UAAU,KAAK;QAC9B,UAAUM;uBAIlB,oBAAC;QAAI,WAAW;qBACZ,oBAACM,WAASA;QAAC,OAAO;QAAqB,MAAMR;sBAC7C,oBAACQ,WAASA;QAAC,OAAO;QAAkB,MAAMP;;AAI1D;AAEA,MAAMO,YAAY,CAAC,EAAES,KAAK,EAAEjB,IAAI,EAAoC,GACzD,WAAP,GACI,oBAAC;QAAI,WAAW;qBACZ,oBAAC;QAAI,WAAW;OAAwBiB,QAAAA,WAAAA,GACxC,oBAAC;QACG,WACI;OAGHjB,AAAS,SAATA,OAAgB,SAASkB,KAAK,SAAS,CAAClB,MAAM,MAAM"}
|
|
1
|
+
{"version":3,"file":"features/formModel/demo/FormModelDemo.js","sources":["../../../../src/features/formModel/demo/FormModelDemo.tsx"],"sourcesContent":["import React, { useMemo } from \"react\";\nimport { observer } from \"mobx-react-lite\";\nimport { useFeature } from \"@webiny/app\";\nimport { Button } from \"@webiny/admin-ui\";\nimport { FormView } from \"../FormView.js\";\nimport { FormModelFeature } from \"../feature.js\";\nimport { FieldRenderersDemoPresenter } from \"./FieldRenderersDemoPresenter.js\";\nimport { FormModelDemoPresenter } from \"./FormModelDemoPresenter.js\";\nimport { FormModelPhase8c1Presenter } from \"./FormModelPhase8c1Presenter.js\";\nimport { FormModelPhase11Presenter } from \"./FormModelPhase11Presenter.js\";\n\nexport const FormModelDemo = observer(() => {\n const { formModelFactory } = useFeature(FormModelFeature);\n const presenter = useMemo(\n () => new FormModelDemoPresenter(formModelFactory),\n [formModelFactory]\n );\n\n const { form, data, lastSubmitted, isSubmitting, runtimeTemplateAdded, textTemplateRemoved } =\n presenter.vm;\n\n return (\n <div className={\"p-lg flex flex-col gap-2xl max-w-4xl mx-auto\"}>\n <FieldRenderersSection />\n\n <div className={\"flex flex-col gap-lg\"}>\n <div className={\"flex flex-col gap-sm\"}>\n <h2 className={\"text-xl font-semibold\"}>FormModel Demo — Phase 8</h2>\n <p className={\"text-sm text-neutral-strong\"}>\n Exercises the full Phase 8 surface: single-object templates ("Content\n Block"), templated lists ("Page Sections"), per-template\n layouts (Hero spans two rows; Rich Text uses a single row; templates without\n a layout entry fall back to default), and runtime template management via{\" \"}\n <code>field.templates.add/remove</code>. Change Plan to{\" \"}\n <code>enterprise</code> to reveal the "Premium Widget" template in\n the Content Block picker.\n </p>\n </div>\n\n <FormView name=\"Demo\" form={form} />\n\n <div className={\"flex flex-wrap gap-sm\"}>\n <Button\n text={isSubmitting ? \"Submitting…\" : \"Submit\"}\n variant={\"primary\"}\n onClick={() => presenter.submit()}\n disabled={isSubmitting}\n />\n <Button\n text={\"Reset\"}\n variant={\"secondary\"}\n onClick={() => presenter.reset()}\n disabled={isSubmitting}\n />\n <Button\n text={\n runtimeTemplateAdded\n ? 'Remove \"Runtime Banner\" from sections'\n : 'Add \"Runtime Banner\" to sections'\n }\n variant={\"tertiary\"}\n onClick={() => presenter.toggleRuntimeTemplate()}\n />\n <Button\n text={\n textTemplateRemoved\n ? 'Restore \"Rich Text\" on content'\n : 'Remove \"Rich Text\" from content'\n }\n variant={\"tertiary\"}\n onClick={() => presenter.toggleTextTemplate()}\n />\n </div>\n\n <div className={\"grid grid-cols-2 gap-md\"}>\n <DataPanel title={\"Current getData()\"} data={data} />\n <DataPanel title={\"Last submitted\"} data={lastSubmitted} />\n </div>\n </div>\n\n <Phase8c1Section />\n\n <Phase11Section />\n </div>\n );\n});\n\nconst FieldRenderersSection = observer(() => {\n const { formModelFactory } = useFeature(FormModelFeature);\n const presenter = useMemo(\n () => new FieldRenderersDemoPresenter(formModelFactory),\n [formModelFactory]\n );\n\n const { form, data, lastSubmitted, isSubmitting, formErrors } = presenter.vm;\n\n return (\n <div className={\"flex flex-col gap-lg\"}>\n <div className={\"flex flex-col gap-sm\"}>\n <h2 className={\"text-xl font-semibold\"}>Field Renderers Showcase</h2>\n <p className={\"text-sm text-neutral-strong\"}>\n All field renderer variants: text, number, boolean, select\n (dropdown/radio/checkboxes), date/time (4 variants), tags, textarea, multi-value\n lists, hidden, and dynamic zones. Renderers not yet implemented show nothing\n (console warning).\n </p>\n </div>\n\n <FormView name=\"Demo\" form={form} />\n\n {formErrors.length > 0 && (\n <div className={\"flex flex-col gap-xs\"}>\n <div className={\"text-sm font-medium\"}>Form errors</div>\n <ul className={\"text-xs text-error-strong list-disc pl-md\"}>\n {formErrors.map((e, i) => (\n <li key={i}>\n {e.path ? (\n <button\n type={\"button\"}\n className={\n \"underline cursor-pointer hover:text-error-default\"\n }\n onClick={() => presenter.focusField(e.path)}\n >\n <code>{e.path}</code>\n </button>\n ) : null}{\" \"}\n {e.message}\n </li>\n ))}\n </ul>\n </div>\n )}\n\n <div className={\"flex flex-wrap gap-sm\"}>\n <Button\n text={isSubmitting ? \"Submitting…\" : \"Submit\"}\n variant={\"primary\"}\n onClick={() => presenter.submit()}\n disabled={isSubmitting}\n />\n <Button\n text={\"Reset\"}\n variant={\"secondary\"}\n onClick={() => presenter.reset()}\n disabled={isSubmitting}\n />\n </div>\n\n <div className={\"grid grid-cols-2 gap-md\"}>\n <DataPanel title={\"Current getData()\"} data={data} />\n <DataPanel title={\"Last submitted\"} data={lastSubmitted} />\n </div>\n </div>\n );\n});\n\nconst Phase8c1Section = observer(() => {\n const { formModelFactory } = useFeature(FormModelFeature);\n const presenter = useMemo(\n () => new FormModelPhase8c1Presenter(formModelFactory),\n [formModelFactory]\n );\n\n const { form, data, lastSubmitted, isSubmitting } = presenter.vm;\n\n return (\n <div className={\"flex flex-col gap-lg border-t border-neutral-dimmed pt-lg\"}>\n <div className={\"flex flex-col gap-sm\"}>\n <h2 className={\"text-xl font-semibold\"}>FormModel Demo — Phase 8c.1</h2>\n <p className={\"text-sm text-neutral-strong\"}>\n Nested object layouts. A top-level <code>page</code> object whose inner layout\n is split across tabs (General / SEO). The SEO tab contains a nested{\" \"}\n <code>layout.object("seo", ...)</code> with its own row layout, and\n the SEO object itself contains another nested{\" \"}\n <code>layout.object("og", ...)</code> for the Open Graph fields. Phase\n 8c.1 walks the inner layout (including across tabs) and forwards each nested{\" \"}\n <code>layout.object()</code> to the matching child at build time.\n </p>\n </div>\n\n <FormView name=\"Demo\" form={form} />\n\n <div className={\"flex flex-wrap gap-sm\"}>\n <Button\n text={isSubmitting ? \"Submitting…\" : \"Submit\"}\n variant={\"primary\"}\n onClick={() => presenter.submit()}\n disabled={isSubmitting}\n />\n <Button\n text={\"Reset\"}\n variant={\"secondary\"}\n onClick={() => presenter.reset()}\n disabled={isSubmitting}\n />\n </div>\n\n <div className={\"grid grid-cols-2 gap-md\"}>\n <DataPanel title={\"Current getData()\"} data={data} />\n <DataPanel title={\"Last submitted\"} data={lastSubmitted} />\n </div>\n </div>\n );\n});\n\nconst Phase11Section = observer(() => {\n const { formModelFactory } = useFeature(FormModelFeature);\n const presenter = useMemo(\n () => new FormModelPhase11Presenter(formModelFactory),\n [formModelFactory]\n );\n\n const { form, data, lastSubmitted, isSubmitting, formErrors } = presenter.vm;\n\n return (\n <div className={\"flex flex-col gap-lg border-t border-neutral-dimmed pt-lg\"}>\n <div className={\"flex flex-col gap-sm\"}>\n <h2 className={\"text-xl font-semibold\"}>FormModel Demo — Phase 11</h2>\n <p className={\"text-sm text-neutral-strong\"}>\n Conditional required (<code>requiredWhen</code> on Seats — chained builder +\n modifier rules), derived fields (<code>computed</code> Full Name and{\" \"}\n <code>computedUntilDirty</code> Slug), modifier-style child addition via{\" \"}\n <code>field.as("object").fields()</code> adding Company/Bio to\n Profile, form-level rules (<code>addRule</code> with a Zod refinement for\n password match plus an imperative slug-length rule), and a layout assembled via{\" \"}\n <code>setLayout</code>.\n </p>\n </div>\n\n <FormView name=\"Demo\" form={form} />\n\n {formErrors.length > 0 && (\n <div className={\"flex flex-col gap-xs\"}>\n <div className={\"text-sm font-medium\"}>Form errors</div>\n <ul className={\"text-xs text-error-strong list-disc pl-md\"}>\n {formErrors.map((e, i) => (\n <li key={i}>\n {e.path ? <code>{e.path}</code> : null} {e.message}\n </li>\n ))}\n </ul>\n </div>\n )}\n\n <div className={\"flex flex-wrap gap-sm\"}>\n <Button\n text={isSubmitting ? \"Submitting…\" : \"Submit\"}\n variant={\"primary\"}\n onClick={() => presenter.submit()}\n disabled={isSubmitting}\n />\n <Button\n text={\"Reset\"}\n variant={\"secondary\"}\n onClick={() => presenter.reset()}\n disabled={isSubmitting}\n />\n </div>\n\n <div className={\"grid grid-cols-2 gap-md\"}>\n <DataPanel title={\"Current getData()\"} data={data} />\n <DataPanel title={\"Last submitted\"} data={lastSubmitted} />\n </div>\n </div>\n );\n});\n\nconst DataPanel = ({ title, data }: { title: string; data: unknown }) => {\n return (\n <div className={\"flex flex-col gap-xs\"}>\n <div className={\"text-sm font-medium\"}>{title}</div>\n <pre\n className={\n \"text-xs bg-neutral-subtle p-sm rounded border border-neutral-dimmed overflow-auto\"\n }\n >\n {data === null ? \"null\" : JSON.stringify(data, null, 2)}\n </pre>\n </div>\n );\n};\n"],"names":["FormModelDemo","observer","formModelFactory","useFeature","FormModelFeature","presenter","useMemo","FormModelDemoPresenter","form","data","lastSubmitted","isSubmitting","runtimeTemplateAdded","textTemplateRemoved","FieldRenderersSection","FormView","Button","DataPanel","Phase8c1Section","Phase11Section","FieldRenderersDemoPresenter","formErrors","e","i","FormModelPhase8c1Presenter","FormModelPhase11Presenter","title","JSON"],"mappings":";;;;;;;;;;AAWO,MAAMA,gBAAgBC,SAAS;IAClC,MAAM,EAAEC,gBAAgB,EAAE,GAAGC,WAAWC;IACxC,MAA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AK,gCAA4C,oEACvB,oBAAC,cAAK,YAAc,8GACiC,mBAChF,oBAAC,cAAK,cAAgB,qBAI9B,oBAACU,UAAQA;QAAC,MAAK;QAAO,MAAMP;QAE3Ba,WAAW,MAAM,GAAG,KAAK,WAAL,GACjB,oBAAC;QAAI,WAAW;qBACZ,oBAAC;QAAI,WAAW;OAAuB,8BACvC,oBAAC;QAAG,WAAW;OACVA,WAAW,GAAG,CAAC,CAACC,GAAGC,IAAAA,WAAAA,GAChB,oBAAC;YAAG,KAAKA;WACJD,EAAE,IAAI,GAAG,WAAH,GAAG,oBAAC,cAAMA,EAAE,IAAI,IAAW,MAAK,KAAEA,EAAE,OAAO,oBAOtE,oBAAC;QAAI,WAAW;qBACZ,oBAACN,QAAMA;QACH,MAAML,eAAe,gBAAgB;QACrC,SAAS;QACT,SAAS,IAAMN,UAAU,MAAM;QAC/B,UAAUM;sBAEd,oBAACK,QAAMA;QACH,MAAM;QACN,SAAS;QACT,SAAS,IAAMX,UAAU,KAAK;QAC9B,UAAUM;uBAIlB,oBAAC;QAAI,WAAW;qBACZ,oBAACM,WAAAA;QAAU,OAAO;QAAqB,MAAMR;sBAC7C,oBAACQ,WAAAA;QAAU,OAAO;QAAkB,MAAMP;;AAI1D;AAEA,MAAMO,YAAY,CAAC,EAAES,KAAK,EAAEjB,IAAI,EAAoC,GACzD,WAAP,GACI,oBAAC;QAAI,WAAW;qBACZ,oBAAC;QAAI,WAAW;OAAwBiB,QAAAA,WAAAA,GACxC,oBAAC;QACG,WACI;OAGHjB,AAAS,SAATA,OAAgB,SAASkB,KAAK,SAAS,CAAClB,MAAM,MAAM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/formModel/fieldTypes/dateLimits.js","sources":["../../../../src/features/formModel/fieldTypes/dateLimits.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { getLocalToday, resolveDateBound, type DateBound } from \"@webiny/utils\";\n\nexport type { DateBound };\n\nexport interface IDateLimit {\n bound: DateBound;\n message?: string;\n}\n\n/** A field's date limits, as `datetime()` hands them to its renderer in `rendererSettings`. */\nexport interface IDateLimits {\n gte: DateBound[];\n lte: DateBound[];\n}\n\n/** The resolved limits: the latest lower limit and the earliest upper one. */\nexport interface IResolvedDateLimits {\n min?: string;\n max?: string;\n}\n\nconst describeBound = (bound: DateBound) =>\n typeof bound === \"string\" ? bound : `\"${bound.expression}\"`;\n\n/**\n * A field's limits as dates, with expressions worked out against `today` (the editor's local\n * date by default). An expression that can't be read is left out.\n */\nexport function resolveDateLimits(\n limits: IDateLimits | undefined,\n today: string = getLocalToday()\n): IResolvedDateLimits {\n const resolve = (bounds: DateBound[] = []) =>\n bounds.flatMap(bound => {\n try {\n return [resolveDateBound(bound, today)];\n } catch {\n return [];\n }\n });\n const gte = resolve(limits?.gte);\n const lte = resolve(limits?.lte);\n return {\n min: gte.length ? gte.reduce((a, b) => (a > b ? a : b)) : undefined,\n max: lte.length ? lte.reduce((a, b) => (a < b ? a : b)) : undefined\n };\n}\n\n/** Reads the limits `datetime()` put into a field's renderer settings. */\nexport function getDateLimits(rendererSettings: unknown): IDateLimits | undefined {\n if (!rendererSettings || typeof rendererSettings !== \"object\") {\n return undefined;\n }\n return (rendererSettings as { dateLimits?: IDateLimits }).dateLimits;\n}\n\n/** Shows a worked-out limit in a message; by default as it is stored (`2008-10-19`). */\nexport type DateLimitFormatter = (date: string) => string;\n\n/** The message when a limit has none of its own. */\nexport const DEFAULT_DATE_GTE_MESSAGE = \"Must be on or after {date}.\";\nexport const DEFAULT_DATE_LTE_MESSAGE = \"Must be on or before {date}.\";\n\n/** Puts the worked-out limit into a message's `{date}`. */\nexport function formatDateLimitMessage(message: string, date: string): string {\n return message.replace(/\\{date}/g, date);\n}\n\n/**\n * A schema that checks a value, or each value of a list, against the limits. Expressions are\n * worked out against the editor's local date at the moment of the check, so a form left open\n * overnight checks against the new day. A message's `{date}` is the worked-out limit.\n */\nexport function createDateLimitsSchema(\n gte: IDateLimit[],\n lte: IDateLimit[],\n formatDate: DateLimitFormatter = date => date\n): z.ZodTypeAny {\n return z.any().superRefine((value, ctx) => {\n const values = (Array.isArray(value) ? value : [value]).filter(\n v => v !== null && v !== undefined && v !== \"\"\n );\n if (values.length === 0) {\n return;\n }\n const today = getLocalToday();\n const check = (limit: IDateLimit, kind: \"gte\" | \"lte\") => {\n let date: string;\n try {\n date = resolveDateBound(limit.bound, today);\n } catch {\n ctx.addIssue({\n code: \"custom\",\n message: `Invalid date limit ${describeBound(limit.bound)}.`\n });\n return false;\n }\n const ok = values.every(v => (kind === \"gte\" ? String(v) >= date : String(v) <= date));\n if (!ok) {\n const message =\n limit.message ||\n (kind === \"gte\" ? DEFAULT_DATE_GTE_MESSAGE : DEFAULT_DATE_LTE_MESSAGE);\n ctx.addIssue({\n code: \"custom\",\n message: formatDateLimitMessage(message, formatDate(date))\n });\n }\n return ok;\n };\n for (const limit of gte) {\n if (!check(limit, \"gte\")) {\n return;\n }\n }\n for (const limit of lte) {\n if (!check(limit, \"lte\")) {\n return;\n }\n }\n });\n}\n"],"names":["describeBound","bound","resolveDateLimits","limits","today","getLocalToday","resolve","bounds","resolveDateBound","gte","lte","a","b","undefined","getDateLimits","rendererSettings","DEFAULT_DATE_GTE_MESSAGE","DEFAULT_DATE_LTE_MESSAGE","formatDateLimitMessage","message","date","createDateLimitsSchema","formatDate","z","value","ctx","values","Array","v","check","limit","kind","ok","String"],"mappings":";;AAsBA,MAAMA,gBAAgB,CAACC,QACnB,AAAiB,YAAjB,OAAOA,QAAqBA,QAAQ,CAAC,CAAC,EAAEA,MAAM,UAAU,CAAC,CAAC,CAAC;AAMxD,SAASC,kBACZC,MAA+B,EAC/BC,QAAgBC,eAAe;IAE/B,MAAMC,UAAU,CAACC,SAAsB,EAAE,GACrCA,OAAO,OAAO,CAACN,CAAAA;YACX,IAAI;gBACA,OAAO;oBAACO,iBAAiBP,OAAOG;iBAAO;YAC3C,EAAE,OAAM;gBACJ,OAAO,EAAE;YACb;QACJ;IACJ,MAAMK,MAAMH,QAAQH,QAAQ;IAC5B,MAAMO,MAAMJ,QAAQH,QAAQ;IAC5B,OAAO;QACH,KAAKM,IAAI,MAAM,GAAGA,IAAI,MAAM,CAAC,CAACE,GAAGC,IAAOD,IAAIC,IAAID,IAAIC,KAAMC;QAC1D,KAAKH,IAAI,MAAM,GAAGA,IAAI,MAAM,CAAC,CAACC,GAAGC,IAAOD,IAAIC,IAAID,IAAIC,KAAMC;IAC9D;AACJ;AAGO,SAASC,cAAcC,gBAAyB;IACnD,IAAI,CAACA,oBAAoB,AAA4B,YAA5B,OAAOA,kBAC5B;IAEJ,OAAQA,iBAAkD,UAAU;AACxE;AAMO,MAAMC,2BAA2B;AACjC,MAAMC,2BAA2B;AAGjC,SAASC,uBAAuBC,OAAe,EAAEC,IAAY;IAChE,OAAOD,QAAQ,OAAO,CAAC,YAAYC;AACvC;AAOO,SAASC,uBACZZ,GAAiB,EACjBC,GAAiB,EACjBY,aAAiCF,CAAAA,OAAQA,IAAI;IAE7C,OAAOG,EAAE,GAAG,GAAG,WAAW,CAAC,CAACC,OAAOC;QAC/B,MAAMC,SAAUC,AAAAA,CAAAA,MAAM,OAAO,CAACH,SAASA,QAAQ;YAACA;SAAK,
|
|
1
|
+
{"version":3,"file":"features/formModel/fieldTypes/dateLimits.js","sources":["../../../../src/features/formModel/fieldTypes/dateLimits.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { getLocalToday, resolveDateBound, type DateBound } from \"@webiny/utils\";\n\nexport type { DateBound };\n\nexport interface IDateLimit {\n bound: DateBound;\n message?: string;\n}\n\n/** A field's date limits, as `datetime()` hands them to its renderer in `rendererSettings`. */\nexport interface IDateLimits {\n gte: DateBound[];\n lte: DateBound[];\n}\n\n/** The resolved limits: the latest lower limit and the earliest upper one. */\nexport interface IResolvedDateLimits {\n min?: string;\n max?: string;\n}\n\nconst describeBound = (bound: DateBound) =>\n typeof bound === \"string\" ? bound : `\"${bound.expression}\"`;\n\n/**\n * A field's limits as dates, with expressions worked out against `today` (the editor's local\n * date by default). An expression that can't be read is left out.\n */\nexport function resolveDateLimits(\n limits: IDateLimits | undefined,\n today: string = getLocalToday()\n): IResolvedDateLimits {\n const resolve = (bounds: DateBound[] = []) =>\n bounds.flatMap(bound => {\n try {\n return [resolveDateBound(bound, today)];\n } catch {\n return [];\n }\n });\n const gte = resolve(limits?.gte);\n const lte = resolve(limits?.lte);\n return {\n min: gte.length ? gte.reduce((a, b) => (a > b ? a : b)) : undefined,\n max: lte.length ? lte.reduce((a, b) => (a < b ? a : b)) : undefined\n };\n}\n\n/** Reads the limits `datetime()` put into a field's renderer settings. */\nexport function getDateLimits(rendererSettings: unknown): IDateLimits | undefined {\n if (!rendererSettings || typeof rendererSettings !== \"object\") {\n return undefined;\n }\n return (rendererSettings as { dateLimits?: IDateLimits }).dateLimits;\n}\n\n/** Shows a worked-out limit in a message; by default as it is stored (`2008-10-19`). */\nexport type DateLimitFormatter = (date: string) => string;\n\n/** The message when a limit has none of its own. */\nexport const DEFAULT_DATE_GTE_MESSAGE = \"Must be on or after {date}.\";\nexport const DEFAULT_DATE_LTE_MESSAGE = \"Must be on or before {date}.\";\n\n/** Puts the worked-out limit into a message's `{date}`. */\nexport function formatDateLimitMessage(message: string, date: string): string {\n return message.replace(/\\{date}/g, date);\n}\n\n/**\n * A schema that checks a value, or each value of a list, against the limits. Expressions are\n * worked out against the editor's local date at the moment of the check, so a form left open\n * overnight checks against the new day. A message's `{date}` is the worked-out limit.\n */\nexport function createDateLimitsSchema(\n gte: IDateLimit[],\n lte: IDateLimit[],\n formatDate: DateLimitFormatter = date => date\n): z.ZodTypeAny {\n return z.any().superRefine((value, ctx) => {\n const values = (Array.isArray(value) ? value : [value]).filter(\n v => v !== null && v !== undefined && v !== \"\"\n );\n if (values.length === 0) {\n return;\n }\n const today = getLocalToday();\n const check = (limit: IDateLimit, kind: \"gte\" | \"lte\") => {\n let date: string;\n try {\n date = resolveDateBound(limit.bound, today);\n } catch {\n ctx.addIssue({\n code: \"custom\",\n message: `Invalid date limit ${describeBound(limit.bound)}.`\n });\n return false;\n }\n const ok = values.every(v => (kind === \"gte\" ? String(v) >= date : String(v) <= date));\n if (!ok) {\n const message =\n limit.message ||\n (kind === \"gte\" ? DEFAULT_DATE_GTE_MESSAGE : DEFAULT_DATE_LTE_MESSAGE);\n ctx.addIssue({\n code: \"custom\",\n message: formatDateLimitMessage(message, formatDate(date))\n });\n }\n return ok;\n };\n for (const limit of gte) {\n if (!check(limit, \"gte\")) {\n return;\n }\n }\n for (const limit of lte) {\n if (!check(limit, \"lte\")) {\n return;\n }\n }\n });\n}\n"],"names":["describeBound","bound","resolveDateLimits","limits","today","getLocalToday","resolve","bounds","resolveDateBound","gte","lte","a","b","undefined","getDateLimits","rendererSettings","DEFAULT_DATE_GTE_MESSAGE","DEFAULT_DATE_LTE_MESSAGE","formatDateLimitMessage","message","date","createDateLimitsSchema","formatDate","z","value","ctx","values","Array","v","check","limit","kind","ok","String"],"mappings":";;AAsBA,MAAMA,gBAAgB,CAACC,QACnB,AAAiB,YAAjB,OAAOA,QAAqBA,QAAQ,CAAC,CAAC,EAAEA,MAAM,UAAU,CAAC,CAAC,CAAC;AAMxD,SAASC,kBACZC,MAA+B,EAC/BC,QAAgBC,eAAe;IAE/B,MAAMC,UAAU,CAACC,SAAsB,EAAE,GACrCA,OAAO,OAAO,CAACN,CAAAA;YACX,IAAI;gBACA,OAAO;oBAACO,iBAAiBP,OAAOG;iBAAO;YAC3C,EAAE,OAAM;gBACJ,OAAO,EAAE;YACb;QACJ;IACJ,MAAMK,MAAMH,QAAQH,QAAQ;IAC5B,MAAMO,MAAMJ,QAAQH,QAAQ;IAC5B,OAAO;QACH,KAAKM,IAAI,MAAM,GAAGA,IAAI,MAAM,CAAC,CAACE,GAAGC,IAAOD,IAAIC,IAAID,IAAIC,KAAMC;QAC1D,KAAKH,IAAI,MAAM,GAAGA,IAAI,MAAM,CAAC,CAACC,GAAGC,IAAOD,IAAIC,IAAID,IAAIC,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,IAAI,CAACoB,MAAMC,OAAO,QACd;QAGR,KAAK,MAAMA,SAASpB,IAChB,IAAI,CAACmB,MAAMC,OAAO,QACd;IAGZ;AACJ"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface LogInErrorParams {
|
|
2
|
+
code?: string | null;
|
|
3
|
+
message: string;
|
|
4
|
+
data?: Record<string, any> | null;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* A failed `security.login`: either the error the API returned, or the request's own failure
|
|
8
|
+
* (for example, the tenant in the `x-tenant` header couldn't be loaded).
|
|
9
|
+
*/
|
|
10
|
+
export declare class LogInError extends Error {
|
|
11
|
+
readonly code: string;
|
|
12
|
+
readonly data: Record<string, any>;
|
|
13
|
+
constructor(params: LogInErrorParams);
|
|
14
|
+
static from(error: unknown): LogInError;
|
|
15
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
class LogInError extends Error {
|
|
2
|
+
constructor(params){
|
|
3
|
+
super(params.message);
|
|
4
|
+
this.name = "LogInError";
|
|
5
|
+
this.code = params.code ?? "";
|
|
6
|
+
this.data = params.data ?? {};
|
|
7
|
+
}
|
|
8
|
+
static from(error) {
|
|
9
|
+
if (error instanceof LogInError) return error;
|
|
10
|
+
if (error && "object" == typeof error) {
|
|
11
|
+
const { code, message, data } = error;
|
|
12
|
+
return new LogInError({
|
|
13
|
+
code,
|
|
14
|
+
message: message || "Login failed.",
|
|
15
|
+
data
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return new LogInError({
|
|
19
|
+
message: String(error)
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export { LogInError };
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=LogInError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"features/security/LogIn/LogInError.js","sources":["../../../../src/features/security/LogIn/LogInError.ts"],"sourcesContent":["export interface LogInErrorParams {\n code?: string | null;\n message: string;\n data?: Record<string, any> | null;\n}\n\n/**\n * A failed `security.login`: either the error the API returned, or the request's own failure\n * (for example, the tenant in the `x-tenant` header couldn't be loaded).\n */\nexport class LogInError extends Error {\n public readonly code: string;\n public readonly data: Record<string, any>;\n\n constructor(params: LogInErrorParams) {\n super(params.message);\n this.name = \"LogInError\";\n this.code = params.code ?? \"\";\n this.data = params.data ?? {};\n }\n\n static from(error: unknown): LogInError {\n if (error instanceof LogInError) {\n return error;\n }\n\n if (error && typeof error === \"object\") {\n const { code, message, data } = error as Partial<LogInErrorParams>;\n return new LogInError({\n code,\n message: message || \"Login failed.\",\n data\n });\n }\n\n return new LogInError({ message: String(error) });\n }\n}\n"],"names":["LogInError","Error","params","error","code","message","data","String"],"mappings":"AAUO,MAAMA,mBAAmBC;IAI5B,YAAYC,MAAwB,CAAE;QAClC,KAAK,CAACA,OAAO,OAAO;QACpB,IAAI,CAAC,IAAI,GAAG;QACZ,IAAI,CAAC,IAAI,GAAGA,OAAO,IAAI,IAAI;QAC3B,IAAI,CAAC,IAAI,GAAGA,OAAO,IAAI,IAAI,CAAC;IAChC;IAEA,OAAO,KAAKC,KAAc,EAAc;QACpC,IAAIA,iBAAiBH,YACjB,OAAOG;QAGX,IAAIA,SAAS,AAAiB,YAAjB,OAAOA,OAAoB;YACpC,MAAM,EAAEC,IAAI,EAAEC,OAAO,EAAEC,IAAI,EAAE,GAAGH;YAChC,OAAO,IAAIH,WAAW;gBAClBI;gBACA,SAASC,WAAW;gBACpBC;YACJ;QACJ;QAEA,OAAO,IAAIN,WAAW;YAAE,SAASO,OAAOJ;QAAO;IACnD;AACJ"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { MainGraphQLClient } from "@webiny/app/features/mainGraphQLClient/index.js";
|
|
2
|
-
import { LogInGateway as Abstraction
|
|
2
|
+
import { LogInGateway as Abstraction } from "./abstractions.js";
|
|
3
3
|
declare class LogInGatewayImpl implements Abstraction.Interface {
|
|
4
4
|
private graphqlClient;
|
|
5
5
|
constructor(graphqlClient: MainGraphQLClient.Interface);
|
|
6
|
-
execute(): Promise<
|
|
6
|
+
execute(): Promise<Abstraction.Result>;
|
|
7
7
|
}
|
|
8
8
|
export declare const LogInGateway: typeof LogInGatewayImpl & {
|
|
9
9
|
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").ILogInGateway>;
|
|
@@ -1,17 +1,34 @@
|
|
|
1
1
|
import { MainGraphQLClient } from "@webiny/app/features/mainGraphQLClient/index.js";
|
|
2
2
|
import { LogInGateway } from "./abstractions.js";
|
|
3
3
|
import { createLoginMutation } from "./createLoginMutation.js";
|
|
4
|
+
import { LogInError } from "./LogInError.js";
|
|
4
5
|
class LogInGatewayImpl {
|
|
5
6
|
constructor(graphqlClient){
|
|
6
7
|
this.graphqlClient = graphqlClient;
|
|
7
8
|
}
|
|
8
9
|
async execute() {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
let response;
|
|
11
|
+
try {
|
|
12
|
+
response = await this.graphqlClient.execute({
|
|
13
|
+
query: createLoginMutation()
|
|
14
|
+
});
|
|
15
|
+
} catch (error) {
|
|
16
|
+
throw LogInError.from(error);
|
|
17
|
+
}
|
|
12
18
|
const { data, error } = response.security.login;
|
|
13
|
-
if (error) throw new
|
|
14
|
-
|
|
19
|
+
if (error) throw new LogInError(error);
|
|
20
|
+
if (!data) throw new LogInError({
|
|
21
|
+
message: "Login returned no identity."
|
|
22
|
+
});
|
|
23
|
+
if ("SecurityLoginTenantSelection" === data.__typename) return {
|
|
24
|
+
step: "selectTenant",
|
|
25
|
+
tenants: data.tenants
|
|
26
|
+
};
|
|
27
|
+
const { __typename, ...identity } = data;
|
|
28
|
+
return {
|
|
29
|
+
step: "done",
|
|
30
|
+
identity
|
|
31
|
+
};
|
|
15
32
|
}
|
|
16
33
|
}
|
|
17
34
|
const LogInGateway_LogInGateway = LogInGateway.createImplementation({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/security/LogIn/LogInGateway.js","sources":["../../../../src/features/security/LogIn/LogInGateway.ts"],"sourcesContent":["import { MainGraphQLClient } from \"@webiny/app/features/mainGraphQLClient/index.js\";\nimport { LogInGateway as Abstraction, LogInRepository } from \"./abstractions.js\";\nimport { createLoginMutation } from \"./createLoginMutation.js\";\n\ninterface LoginMutationResponse {\n security: {\n login: {\n data:
|
|
1
|
+
{"version":3,"file":"features/security/LogIn/LogInGateway.js","sources":["../../../../src/features/security/LogIn/LogInGateway.ts"],"sourcesContent":["import { MainGraphQLClient } from \"@webiny/app/features/mainGraphQLClient/index.js\";\nimport type { Tenant } from \"~/features/tenancy/abstractions.js\";\nimport { LogInGateway as Abstraction, LogInRepository } from \"./abstractions.js\";\nimport { createLoginMutation } from \"./createLoginMutation.js\";\nimport { LogInError } from \"./LogInError.js\";\n\ntype LoginResultDTO =\n | ({ __typename: \"SecurityIdentity\" } & LogInRepository.IdentityDTO)\n | { __typename: \"SecurityLoginTenantSelection\"; tenants: Tenant[] };\n\ninterface LoginMutationResponse {\n security: {\n login: {\n data: LoginResultDTO | null;\n error: {\n code: string;\n message: string;\n data: Record<string, any> | null;\n };\n };\n };\n}\n\nclass LogInGatewayImpl implements Abstraction.Interface {\n constructor(private graphqlClient: MainGraphQLClient.Interface) {}\n\n async execute(): Promise<Abstraction.Result> {\n let response: LoginMutationResponse;\n try {\n response = await this.graphqlClient.execute<LoginMutationResponse>({\n query: createLoginMutation()\n });\n } catch (error) {\n throw LogInError.from(error);\n }\n\n const { data, error } = response.security.login;\n\n if (error) {\n throw new LogInError(error);\n }\n\n if (!data) {\n throw new LogInError({ message: \"Login returned no identity.\" });\n }\n\n if (data.__typename === \"SecurityLoginTenantSelection\") {\n return { step: \"selectTenant\", tenants: data.tenants };\n }\n\n const { __typename, ...identity } = data;\n return { step: \"done\", identity };\n }\n}\n\nexport const LogInGateway = Abstraction.createImplementation({\n implementation: LogInGatewayImpl,\n dependencies: [MainGraphQLClient]\n});\n"],"names":["LogInGatewayImpl","graphqlClient","response","createLoginMutation","error","LogInError","data","__typename","identity","LogInGateway","Abstraction","MainGraphQLClient"],"mappings":";;;;AAuBA,MAAMA;IACF,YAAoBC,aAA0C,CAAE;aAA5CA,aAAa,GAAbA;IAA6C;IAEjE,MAAM,UAAuC;QACzC,IAAIC;QACJ,IAAI;YACAA,WAAW,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAAwB;gBAC/D,OAAOC;YACX;QACJ,EAAE,OAAOC,OAAO;YACZ,MAAMC,WAAW,IAAI,CAACD;QAC1B;QAEA,MAAM,EAAEE,IAAI,EAAEF,KAAK,EAAE,GAAGF,SAAS,QAAQ,CAAC,KAAK;QAE/C,IAAIE,OACA,MAAM,IAAIC,WAAWD;QAGzB,IAAI,CAACE,MACD,MAAM,IAAID,WAAW;YAAE,SAAS;QAA8B;QAGlE,IAAIC,AAAoB,mCAApBA,KAAK,UAAU,EACf,OAAO;YAAE,MAAM;YAAgB,SAASA,KAAK,OAAO;QAAC;QAGzD,MAAM,EAAEC,UAAU,EAAE,GAAGC,UAAU,GAAGF;QACpC,OAAO;YAAE,MAAM;YAAQE;QAAS;IACpC;AACJ;AAEO,MAAMC,4BAAeC,aAAAA,oBAAgC,CAAC;IACzD,gBAAgBV;IAChB,cAAc;QAACW;KAAkB;AACrC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { Identity } from "../../../domain/Identity.js";
|
|
2
1
|
import { LogInRepository as Abstraction } from "./abstractions.js";
|
|
3
2
|
import { LogInGateway } from "./abstractions.js";
|
|
4
3
|
import { IdentityMapper } from "./abstractions.js";
|
|
@@ -6,7 +5,7 @@ declare class LogInRepositoryImpl implements Abstraction.Interface {
|
|
|
6
5
|
private gateway;
|
|
7
6
|
private mapper;
|
|
8
7
|
constructor(gateway: LogInGateway.Interface, mapper: IdentityMapper.Interface);
|
|
9
|
-
login(): Promise<
|
|
8
|
+
login(): Promise<Abstraction.Result>;
|
|
10
9
|
}
|
|
11
10
|
export declare const LogInRepository: typeof LogInRepositoryImpl & {
|
|
12
11
|
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").ILogInRepository>;
|
|
@@ -5,8 +5,12 @@ class LogInRepositoryImpl {
|
|
|
5
5
|
this.mapper = mapper;
|
|
6
6
|
}
|
|
7
7
|
async login() {
|
|
8
|
-
const
|
|
9
|
-
|
|
8
|
+
const result = await this.gateway.execute();
|
|
9
|
+
if ("selectTenant" === result.step) return result;
|
|
10
|
+
return {
|
|
11
|
+
step: "done",
|
|
12
|
+
identity: this.mapper.toIdentity(result.identity)
|
|
13
|
+
};
|
|
10
14
|
}
|
|
11
15
|
}
|
|
12
16
|
const LogInRepository_LogInRepository = LogInRepository.createImplementation({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/security/LogIn/LogInRepository.js","sources":["../../../../src/features/security/LogIn/LogInRepository.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"features/security/LogIn/LogInRepository.js","sources":["../../../../src/features/security/LogIn/LogInRepository.ts"],"sourcesContent":["import { LogInRepository as Abstraction } from \"./abstractions.js\";\nimport { LogInGateway } from \"./abstractions.js\";\nimport { IdentityMapper } from \"./abstractions.js\";\n\nclass LogInRepositoryImpl implements Abstraction.Interface {\n constructor(\n private gateway: LogInGateway.Interface,\n private mapper: IdentityMapper.Interface\n ) {}\n\n async login(): Promise<Abstraction.Result> {\n const result = await this.gateway.execute();\n if (result.step === \"selectTenant\") {\n return result;\n }\n\n return { step: \"done\", identity: this.mapper.toIdentity(result.identity) };\n }\n}\n\nexport const LogInRepository = Abstraction.createImplementation({\n implementation: LogInRepositoryImpl,\n dependencies: [LogInGateway, IdentityMapper]\n});\n"],"names":["LogInRepositoryImpl","gateway","mapper","result","LogInRepository","Abstraction","LogInGateway","IdentityMapper"],"mappings":";AAIA,MAAMA;IACF,YACYC,OAA+B,EAC/BC,MAAgC,CAC1C;aAFUD,OAAO,GAAPA;aACAC,MAAM,GAANA;IACT;IAEH,MAAM,QAAqC;QACvC,MAAMC,SAAS,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO;QACzC,IAAIA,AAAgB,mBAAhBA,OAAO,IAAI,EACX,OAAOA;QAGX,OAAO;YAAE,MAAM;YAAQ,UAAU,IAAI,CAAC,MAAM,CAAC,UAAU,CAACA,OAAO,QAAQ;QAAE;IAC7E;AACJ;AAEO,MAAMC,kCAAkBC,gBAAAA,oBAAgC,CAAC;IAC5D,gBAAgBL;IAChB,cAAc;QAACM;QAAcC;KAAe;AAChD"}
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { LogInRepository, LogInUseCase as UseCase } from "./abstractions.js";
|
|
2
2
|
import { AuthenticationContext } from "../../../features/security/AuthenticationContext/index.js";
|
|
3
3
|
import { IdentityContext } from "../../../features/security/IdentityContext/index.js";
|
|
4
|
+
import { LoginTenantResolver } from "../../../features/security/LoginTenantResolver/index.js";
|
|
5
|
+
import { TenantContext } from "../../../features/tenancy/abstractions.js";
|
|
4
6
|
declare class LoginUseCaseImpl implements UseCase.Interface {
|
|
5
7
|
private authContext;
|
|
6
8
|
private identityContext;
|
|
7
9
|
private logInRepository;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
private tenantResolver;
|
|
11
|
+
private tenantContext;
|
|
12
|
+
constructor(authContext: AuthenticationContext.Interface, identityContext: IdentityContext.Interface, logInRepository: LogInRepository.Interface, tenantResolver: LoginTenantResolver.Interface, tenantContext: TenantContext.Interface);
|
|
13
|
+
execute(params: UseCase.Params): Promise<UseCase.Result>;
|
|
14
|
+
private applyResolution;
|
|
10
15
|
}
|
|
11
16
|
export declare const LogInUseCase: typeof LoginUseCaseImpl & {
|
|
12
17
|
__abstraction: import("@webiny/di").Abstraction<import("./abstractions.js").ILogInUseCase>;
|
|
@@ -1,19 +1,67 @@
|
|
|
1
1
|
import { LogInRepository, LogInUseCase } from "./abstractions.js";
|
|
2
2
|
import { AuthenticationContext } from "../AuthenticationContext/index.js";
|
|
3
3
|
import { IdentityContext } from "../IdentityContext/index.js";
|
|
4
|
+
import { LoginTenantResolver } from "../LoginTenantResolver/index.js";
|
|
5
|
+
import { TenantContext } from "../../tenancy/abstractions.js";
|
|
6
|
+
import { LogInError } from "./LogInError.js";
|
|
4
7
|
import { hasAppPermissions } from "./hasAppPermissions.js";
|
|
5
8
|
class LoginUseCaseImpl {
|
|
6
|
-
constructor(authContext, identityContext, logInRepository){
|
|
9
|
+
constructor(authContext, identityContext, logInRepository, tenantResolver, tenantContext){
|
|
7
10
|
this.authContext = authContext;
|
|
8
11
|
this.identityContext = identityContext;
|
|
9
12
|
this.logInRepository = logInRepository;
|
|
13
|
+
this.tenantResolver = tenantResolver;
|
|
14
|
+
this.tenantContext = tenantContext;
|
|
10
15
|
}
|
|
11
16
|
async execute(params) {
|
|
12
17
|
this.authContext.setIdTokenProvider(params.idTokenProvider);
|
|
13
18
|
if (params.logoutCallback) this.authContext.setLogoutCallback(params.logoutCallback);
|
|
14
|
-
|
|
19
|
+
let result;
|
|
20
|
+
try {
|
|
21
|
+
result = await this.logInRepository.login();
|
|
22
|
+
} catch (error) {
|
|
23
|
+
const logInError = LogInError.from(error);
|
|
24
|
+
return this.applyResolution(await this.tenantResolver.resolveError(logInError), ()=>{
|
|
25
|
+
throw logInError;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
if ("selectTenant" === result.step) {
|
|
29
|
+
const resolution = await this.tenantResolver.resolveTenants(result.tenants);
|
|
30
|
+
return this.applyResolution(resolution, ()=>{
|
|
31
|
+
throw new LogInError({
|
|
32
|
+
code: "Security/Identity/TenantSelectionFailed",
|
|
33
|
+
message: "Unable to find a tenant to log into."
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
const { identity } = result;
|
|
15
38
|
if (!hasAppPermissions(identity)) throw new Error("You have no permissions on this tenant!");
|
|
16
39
|
this.identityContext.setIdentity(identity);
|
|
40
|
+
return {
|
|
41
|
+
type: "loggedIn"
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
applyResolution(resolution, unresolved) {
|
|
45
|
+
switch(resolution.type){
|
|
46
|
+
case "switchTenant":
|
|
47
|
+
if (resolution.tenantId === this.tenantContext.getCurrentTenant()) return unresolved();
|
|
48
|
+
this.tenantContext.setTenant(resolution.tenantId);
|
|
49
|
+
return {
|
|
50
|
+
type: "switchingTenant",
|
|
51
|
+
tenantId: resolution.tenantId
|
|
52
|
+
};
|
|
53
|
+
case "selectTenant":
|
|
54
|
+
return {
|
|
55
|
+
type: "selectTenant",
|
|
56
|
+
tenants: resolution.tenants
|
|
57
|
+
};
|
|
58
|
+
case "noTenantAccess":
|
|
59
|
+
return {
|
|
60
|
+
type: "noTenantAccess"
|
|
61
|
+
};
|
|
62
|
+
default:
|
|
63
|
+
return unresolved();
|
|
64
|
+
}
|
|
17
65
|
}
|
|
18
66
|
}
|
|
19
67
|
const LogInUseCase_LogInUseCase = LogInUseCase.createImplementation({
|
|
@@ -21,7 +69,9 @@ const LogInUseCase_LogInUseCase = LogInUseCase.createImplementation({
|
|
|
21
69
|
dependencies: [
|
|
22
70
|
AuthenticationContext,
|
|
23
71
|
IdentityContext,
|
|
24
|
-
LogInRepository
|
|
72
|
+
LogInRepository,
|
|
73
|
+
LoginTenantResolver,
|
|
74
|
+
TenantContext
|
|
25
75
|
]
|
|
26
76
|
});
|
|
27
77
|
export { LogInUseCase_LogInUseCase as LogInUseCase };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features/security/LogIn/LogInUseCase.js","sources":["../../../../src/features/security/LogIn/LogInUseCase.ts"],"sourcesContent":["import { LogInRepository, LogInUseCase as UseCase } from \"./abstractions.js\";\nimport { AuthenticationContext } from \"~/features/security/AuthenticationContext/index.js\";\nimport { IdentityContext } from \"~/features/security/IdentityContext/index.js\";\nimport { hasAppPermissions } from \"./hasAppPermissions.js\";\n\nclass LoginUseCaseImpl implements UseCase.Interface {\n constructor(\n private authContext: AuthenticationContext.Interface,\n private identityContext: IdentityContext.Interface,\n private logInRepository: LogInRepository.Interface\n ) {}\n\n async execute(params: UseCase.Params): Promise<
|
|
1
|
+
{"version":3,"file":"features/security/LogIn/LogInUseCase.js","sources":["../../../../src/features/security/LogIn/LogInUseCase.ts"],"sourcesContent":["import { LogInRepository, LogInUseCase as UseCase } from \"./abstractions.js\";\nimport { AuthenticationContext } from \"~/features/security/AuthenticationContext/index.js\";\nimport { IdentityContext } from \"~/features/security/IdentityContext/index.js\";\nimport { LoginTenantResolver } from \"~/features/security/LoginTenantResolver/index.js\";\nimport { TenantContext } from \"~/features/tenancy/abstractions.js\";\nimport { LogInError } from \"./LogInError.js\";\nimport { hasAppPermissions } from \"./hasAppPermissions.js\";\n\nclass LoginUseCaseImpl implements UseCase.Interface {\n constructor(\n private authContext: AuthenticationContext.Interface,\n private identityContext: IdentityContext.Interface,\n private logInRepository: LogInRepository.Interface,\n private tenantResolver: LoginTenantResolver.Interface,\n private tenantContext: TenantContext.Interface\n ) {}\n\n async execute(params: UseCase.Params): Promise<UseCase.Result> {\n // 1. Set authentication providers\n this.authContext.setIdTokenProvider(params.idTokenProvider);\n if (params.logoutCallback) {\n this.authContext.setLogoutCallback(params.logoutCallback);\n }\n\n // 2. Log in on the current tenant. If the user can't, find the tenant they can log into.\n let result: LogInRepository.Result;\n try {\n result = await this.logInRepository.login();\n } catch (error) {\n const logInError = LogInError.from(error);\n return this.applyResolution(await this.tenantResolver.resolveError(logInError), () => {\n throw logInError;\n });\n }\n\n if (result.step === \"selectTenant\") {\n const resolution = await this.tenantResolver.resolveTenants(result.tenants);\n return this.applyResolution(resolution, () => {\n throw new LogInError({\n code: \"Security/Identity/TenantSelectionFailed\",\n message: \"Unable to find a tenant to log into.\"\n });\n });\n }\n\n const { identity } = result;\n\n // 3. Ensure identity has some permissions\n if (!hasAppPermissions(identity)) {\n throw new Error(\"You have no permissions on this tenant!\");\n }\n\n // 4. Set identity (user is now \"logged in\")\n this.identityContext.setIdentity(identity);\n\n return { type: \"loggedIn\" };\n }\n\n private applyResolution(\n resolution: LoginTenantResolver.Resolution,\n unresolved: () => never\n ): UseCase.Result {\n switch (resolution.type) {\n case \"switchTenant\":\n // Setting the current tenant again changes nothing and would leave the login pending.\n if (resolution.tenantId === this.tenantContext.getCurrentTenant()) {\n return unresolved();\n }\n // Changing the tenant reloads the app, which logs in again on the new tenant.\n this.tenantContext.setTenant(resolution.tenantId);\n return { type: \"switchingTenant\", tenantId: resolution.tenantId };\n case \"selectTenant\":\n return { type: \"selectTenant\", tenants: resolution.tenants };\n case \"noTenantAccess\":\n return { type: \"noTenantAccess\" };\n default:\n return unresolved();\n }\n }\n}\n\nexport const LogInUseCase = UseCase.createImplementation({\n implementation: LoginUseCaseImpl,\n dependencies: [\n AuthenticationContext,\n IdentityContext,\n LogInRepository,\n LoginTenantResolver,\n TenantContext\n ]\n});\n"],"names":["LoginUseCaseImpl","authContext","identityContext","logInRepository","tenantResolver","tenantContext","params","result","error","logInError","LogInError","resolution","identity","hasAppPermissions","Error","unresolved","LogInUseCase","UseCase","AuthenticationContext","IdentityContext","LogInRepository","LoginTenantResolver","TenantContext"],"mappings":";;;;;;;AAQA,MAAMA;IACF,YACYC,WAA4C,EAC5CC,eAA0C,EAC1CC,eAA0C,EAC1CC,cAA6C,EAC7CC,aAAsC,CAChD;aALUJ,WAAW,GAAXA;aACAC,eAAe,GAAfA;aACAC,eAAe,GAAfA;aACAC,cAAc,GAAdA;aACAC,aAAa,GAAbA;IACT;IAEH,MAAM,QAAQC,MAAsB,EAA2B;QAE3D,IAAI,CAAC,WAAW,CAAC,kBAAkB,CAACA,OAAO,eAAe;QAC1D,IAAIA,OAAO,cAAc,EACrB,IAAI,CAAC,WAAW,CAAC,iBAAiB,CAACA,OAAO,cAAc;QAI5D,IAAIC;QACJ,IAAI;YACAA,SAAS,MAAM,IAAI,CAAC,eAAe,CAAC,KAAK;QAC7C,EAAE,OAAOC,OAAO;YACZ,MAAMC,aAAaC,WAAW,IAAI,CAACF;YACnC,OAAO,IAAI,CAAC,eAAe,C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