@rnaga/wp-node 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/application.d.ts +76 -0
- package/application.d.ts.map +1 -0
- package/application.js +132 -0
- package/common/async-constructor.d.ts +2 -0
- package/common/async-constructor.d.ts.map +1 -0
- package/common/async-constructor.js +7 -0
- package/common/config/define-post-status.config.d.ts +4 -0
- package/common/config/define-post-status.config.d.ts.map +1 -0
- package/common/config/define-post-status.config.js +26 -0
- package/common/config/define-post-type.config.d.ts +4 -0
- package/common/config/define-post-type.config.d.ts.map +1 -0
- package/common/config/define-post-type.config.js +39 -0
- package/common/config/define-taxonomies.config.d.ts +4 -0
- package/common/config/define-taxonomies.config.d.ts.map +1 -0
- package/common/config/define-taxonomies.config.js +26 -0
- package/common/config/define-wp.config..d.ts +12 -0
- package/common/config/define-wp.config..d.ts.map +1 -0
- package/common/config/define-wp.config..js +110 -0
- package/common/config/index.d.ts +5 -0
- package/common/config/index.d.ts.map +1 -0
- package/common/config/index.js +20 -0
- package/common/date.d.ts +19 -0
- package/common/date.d.ts.map +1 -0
- package/common/date.js +116 -0
- package/common/define-hooks.d.ts +4 -0
- package/common/define-hooks.d.ts.map +1 -0
- package/common/define-hooks.js +16 -0
- package/common/diff.d.ts +3 -0
- package/common/diff.d.ts.map +1 -0
- package/common/diff.js +23 -0
- package/common/files.d.ts +14 -0
- package/common/files.d.ts.map +1 -0
- package/common/files.js +160 -0
- package/common/formatting.d.ts +47 -0
- package/common/formatting.d.ts.map +1 -0
- package/common/formatting.js +218 -0
- package/common/hierarchy.d.ts +21 -0
- package/common/hierarchy.d.ts.map +1 -0
- package/common/hierarchy.js +78 -0
- package/common/hooks-command.d.ts +7 -0
- package/common/hooks-command.d.ts.map +1 -0
- package/common/hooks-command.js +21 -0
- package/common/index.d.ts +11 -0
- package/common/index.d.ts.map +1 -0
- package/common/index.js +49 -0
- package/common/password.d.ts +4 -0
- package/common/password.d.ts.map +1 -0
- package/common/password.js +224 -0
- package/common/php-serialize.d.ts +3 -0
- package/common/php-serialize.d.ts.map +1 -0
- package/common/php-serialize.js +17 -0
- package/common/validating.d.ts +10 -0
- package/common/validating.d.ts.map +1 -0
- package/common/validating.js +65 -0
- package/config.d.ts +99 -0
- package/config.d.ts.map +1 -0
- package/config.js +76 -0
- package/constants/async-init.d.ts +2 -0
- package/constants/async-init.d.ts.map +1 -0
- package/constants/async-init.js +4 -0
- package/constants/component.d.ts +3 -0
- package/constants/component.d.ts.map +1 -0
- package/constants/component.js +5 -0
- package/constants/database.d.ts +2 -0
- package/constants/database.d.ts.map +1 -0
- package/constants/database.js +9 -0
- package/constants/default-database-tables.d.ts +7 -0
- package/constants/default-database-tables.d.ts.map +1 -0
- package/constants/default-database-tables.js +26 -0
- package/constants/index.d.ts +9 -0
- package/constants/index.d.ts.map +1 -0
- package/constants/index.js +24 -0
- package/constants/role-capabilities.d.ts +3 -0
- package/constants/role-capabilities.d.ts.map +1 -0
- package/constants/role-capabilities.js +67 -0
- package/constants/role-capability-actions.d.ts +2 -0
- package/constants/role-capability-actions.d.ts.map +1 -0
- package/constants/role-capability-actions.js +90 -0
- package/constants/role-names.d.ts +2 -0
- package/constants/role-names.d.ts.map +1 -0
- package/constants/role-names.js +12 -0
- package/constants/scope.d.ts +6 -0
- package/constants/scope.d.ts.map +1 -0
- package/constants/scope.js +9 -0
- package/core/async-init-reflect.d.ts +5 -0
- package/core/async-init-reflect.d.ts.map +1 -0
- package/core/async-init-reflect.js +18 -0
- package/core/blog.d.ts +20 -0
- package/core/blog.d.ts.map +1 -0
- package/core/blog.js +123 -0
- package/core/capabilities.d.ts +12 -0
- package/core/capabilities.d.ts.map +1 -0
- package/core/capabilities.js +625 -0
- package/core/comment.d.ts +111 -0
- package/core/comment.d.ts.map +1 -0
- package/core/comment.js +173 -0
- package/core/components.d.ts +13 -0
- package/core/components.d.ts.map +1 -0
- package/core/components.js +129 -0
- package/core/context.d.ts +38 -0
- package/core/context.d.ts.map +1 -0
- package/core/context.js +77 -0
- package/core/current.d.ts +33 -0
- package/core/current.d.ts.map +1 -0
- package/core/current.js +229 -0
- package/core/date-time.d.ts +18 -0
- package/core/date-time.d.ts.map +1 -0
- package/core/date-time.js +71 -0
- package/core/hooks/action.d.ts +16 -0
- package/core/hooks/action.d.ts.map +1 -0
- package/core/hooks/action.js +44 -0
- package/core/hooks/actions/init.d.ts +5 -0
- package/core/hooks/actions/init.d.ts.map +1 -0
- package/core/hooks/actions/init.js +28 -0
- package/core/hooks/default-hooks.d.ts +7 -0
- package/core/hooks/default-hooks.d.ts.map +1 -0
- package/core/hooks/default-hooks.js +19 -0
- package/core/hooks/filter.d.ts +12 -0
- package/core/hooks/filter.d.ts.map +1 -0
- package/core/hooks/filter.js +76 -0
- package/core/hooks/filters/capabilities.d.ts +16 -0
- package/core/hooks/filters/capabilities.d.ts.map +1 -0
- package/core/hooks/filters/capabilities.js +395 -0
- package/core/hooks/hooks-command.d.ts +9 -0
- package/core/hooks/hooks-command.d.ts.map +1 -0
- package/core/hooks/hooks-command.js +28 -0
- package/core/hooks/hooks-reflect.d.ts +42 -0
- package/core/hooks/hooks-reflect.d.ts.map +1 -0
- package/core/hooks/hooks-reflect.js +73 -0
- package/core/hooks/hooks.d.ts +61 -0
- package/core/hooks/hooks.d.ts.map +1 -0
- package/core/hooks/hooks.js +82 -0
- package/core/hooks/index.d.ts +4 -0
- package/core/hooks/index.d.ts.map +1 -0
- package/core/hooks/index.js +19 -0
- package/core/installer.d.ts +56 -0
- package/core/installer.d.ts.map +1 -0
- package/core/installer.js +395 -0
- package/core/logger.d.ts +22 -0
- package/core/logger.d.ts.map +1 -0
- package/core/logger.js +65 -0
- package/core/meta.d.ts +20 -0
- package/core/meta.d.ts.map +1 -0
- package/core/meta.js +123 -0
- package/core/options.d.ts +20 -0
- package/core/options.d.ts.map +1 -0
- package/core/options.js +148 -0
- package/core/post.d.ts +39 -0
- package/core/post.d.ts.map +1 -0
- package/core/post.js +164 -0
- package/core/query.d.ts +14 -0
- package/core/query.d.ts.map +1 -0
- package/core/query.js +39 -0
- package/core/role.d.ts +21 -0
- package/core/role.d.ts.map +1 -0
- package/core/role.js +71 -0
- package/core/roles.d.ts +16 -0
- package/core/roles.d.ts.map +1 -0
- package/core/roles.js +84 -0
- package/core/schema.d.ts +13 -0
- package/core/schema.d.ts.map +1 -0
- package/core/schema.js +83 -0
- package/core/site.d.ts +28 -0
- package/core/site.d.ts.map +1 -0
- package/core/site.js +105 -0
- package/core/tables.d.ts +18 -0
- package/core/tables.d.ts.map +1 -0
- package/core/tables.js +64 -0
- package/core/taxonomy.d.ts +23 -0
- package/core/taxonomy.d.ts.map +1 -0
- package/core/taxonomy.js +83 -0
- package/core/term.d.ts +104 -0
- package/core/term.d.ts.map +1 -0
- package/core/term.js +136 -0
- package/core/user.d.ts +32 -0
- package/core/user.d.ts.map +1 -0
- package/core/user.js +273 -0
- package/core/utils/blog.util.d.ts +14 -0
- package/core/utils/blog.util.d.ts.map +1 -0
- package/core/utils/blog.util.js +97 -0
- package/core/utils/comment.util.d.ts +23 -0
- package/core/utils/comment.util.d.ts.map +1 -0
- package/core/utils/comment.util.js +312 -0
- package/core/utils/crud.util.d.ts +40 -0
- package/core/utils/crud.util.d.ts.map +1 -0
- package/core/utils/crud.util.js +97 -0
- package/core/utils/date-time.util.d.ts +9 -0
- package/core/utils/date-time.util.d.ts.map +1 -0
- package/core/utils/date-time.util.js +29 -0
- package/core/utils/link.util.d.ts +23 -0
- package/core/utils/link.util.d.ts.map +1 -0
- package/core/utils/link.util.js +148 -0
- package/core/utils/meta.util.d.ts +13 -0
- package/core/utils/meta.util.d.ts.map +1 -0
- package/core/utils/meta.util.js +73 -0
- package/core/utils/post.util.d.ts +34 -0
- package/core/utils/post.util.d.ts.map +1 -0
- package/core/utils/post.util.js +272 -0
- package/core/utils/query.util.d.ts +36 -0
- package/core/utils/query.util.d.ts.map +1 -0
- package/core/utils/query.util.js +168 -0
- package/core/utils/revision.util.d.ts +67 -0
- package/core/utils/revision.util.d.ts.map +1 -0
- package/core/utils/revision.util.js +105 -0
- package/core/utils/roles.util.d.ts +30 -0
- package/core/utils/roles.util.d.ts.map +1 -0
- package/core/utils/roles.util.js +189 -0
- package/core/utils/signup.util.d.ts +33 -0
- package/core/utils/signup.util.d.ts.map +1 -0
- package/core/utils/signup.util.js +227 -0
- package/core/utils/site.util.d.ts +22 -0
- package/core/utils/site.util.d.ts.map +1 -0
- package/core/utils/site.util.js +122 -0
- package/core/utils/taxonomy.util.d.ts +19 -0
- package/core/utils/taxonomy.util.d.ts.map +1 -0
- package/core/utils/taxonomy.util.js +52 -0
- package/core/utils/term.util.d.ts +13 -0
- package/core/utils/term.util.d.ts.map +1 -0
- package/core/utils/term.util.js +113 -0
- package/core/utils/trx.util.d.ts +24 -0
- package/core/utils/trx.util.d.ts.map +1 -0
- package/core/utils/trx.util.js +86 -0
- package/core/utils/user-self-registration.util.d.ts +46 -0
- package/core/utils/user-self-registration.util.d.ts.map +1 -0
- package/core/utils/user-self-registration.util.js +171 -0
- package/core/utils/user.util.d.ts +153 -0
- package/core/utils/user.util.d.ts.map +1 -0
- package/core/utils/user.util.js +550 -0
- package/core/utils/utils.d.ts +36 -0
- package/core/utils/utils.d.ts.map +1 -0
- package/core/utils/utils.js +85 -0
- package/core/validator.d.ts +11 -0
- package/core/validator.d.ts.map +1 -0
- package/core/validator.js +40 -0
- package/core/vars.d.ts +19 -0
- package/core/vars.d.ts.map +1 -0
- package/core/vars.js +54 -0
- package/crud/blog.crud.d.ts +56 -0
- package/crud/blog.crud.d.ts.map +1 -0
- package/crud/blog.crud.js +301 -0
- package/crud/comment.crud.d.ts +104 -0
- package/crud/comment.crud.d.ts.map +1 -0
- package/crud/comment.crud.js +431 -0
- package/crud/crud.d.ts +63 -0
- package/crud/crud.d.ts.map +1 -0
- package/crud/crud.js +278 -0
- package/crud/error.d.ts +23 -0
- package/crud/error.d.ts.map +1 -0
- package/crud/error.js +51 -0
- package/crud/meta.crud.d.ts +69 -0
- package/crud/meta.crud.d.ts.map +1 -0
- package/crud/meta.crud.js +244 -0
- package/crud/options.crud.d.ts +37 -0
- package/crud/options.crud.d.ts.map +1 -0
- package/crud/options.crud.js +178 -0
- package/crud/post.crud.d.ts +225 -0
- package/crud/post.crud.d.ts.map +1 -0
- package/crud/post.crud.js +589 -0
- package/crud/revision.crud.d.ts +76 -0
- package/crud/revision.crud.d.ts.map +1 -0
- package/crud/revision.crud.js +155 -0
- package/crud/roles.crud.d.ts +50 -0
- package/crud/roles.crud.d.ts.map +1 -0
- package/crud/roles.crud.js +198 -0
- package/crud/settings.crud.d.ts +50 -0
- package/crud/settings.crud.d.ts.map +1 -0
- package/crud/settings.crud.js +153 -0
- package/crud/site.crud.d.ts +62 -0
- package/crud/site.crud.d.ts.map +1 -0
- package/crud/site.crud.js +241 -0
- package/crud/sitemeta.crud.d.ts +55 -0
- package/crud/sitemeta.crud.d.ts.map +1 -0
- package/crud/sitemeta.crud.js +97 -0
- package/crud/term.crud.d.ts +85 -0
- package/crud/term.crud.d.ts.map +1 -0
- package/crud/term.crud.js +285 -0
- package/crud/user-self-registration.crud.d.ts +57 -0
- package/crud/user-self-registration.crud.d.ts.map +1 -0
- package/crud/user-self-registration.crud.js +173 -0
- package/crud/user.crud.d.ts +147 -0
- package/crud/user.crud.d.ts.map +1 -0
- package/crud/user.crud.js +626 -0
- package/database.d.ts +18 -0
- package/database.d.ts.map +1 -0
- package/database.js +80 -0
- package/decorators/async-init.d.ts +2 -0
- package/decorators/async-init.d.ts.map +1 -0
- package/decorators/async-init.js +7 -0
- package/decorators/component.d.ts +12 -0
- package/decorators/component.d.ts.map +1 -0
- package/decorators/component.js +47 -0
- package/decorators/hooks.d.ts +5 -0
- package/decorators/hooks.d.ts.map +1 -0
- package/decorators/hooks.js +30 -0
- package/defaults/extensions.d.ts +4 -0
- package/defaults/extensions.d.ts.map +1 -0
- package/defaults/extensions.js +34 -0
- package/defaults/index.d.ts +11 -0
- package/defaults/index.d.ts.map +1 -0
- package/defaults/index.js +49 -0
- package/defaults/options.d.ts +6 -0
- package/defaults/options.d.ts.map +1 -0
- package/defaults/options.js +267 -0
- package/defaults/post-status.d.ts +10 -0
- package/defaults/post-status.d.ts.map +1 -0
- package/defaults/post-status.js +83 -0
- package/defaults/post-types.d.ts +4 -0
- package/defaults/post-types.d.ts.map +1 -0
- package/defaults/post-types.js +72 -0
- package/defaults/roles.d.ts +31 -0
- package/defaults/roles.d.ts.map +1 -0
- package/defaults/roles.js +213 -0
- package/defaults/seeder.d.ts +34 -0
- package/defaults/seeder.d.ts.map +1 -0
- package/defaults/seeder.js +201 -0
- package/defaults/sitemeta.d.ts +2 -0
- package/defaults/sitemeta.d.ts.map +1 -0
- package/defaults/sitemeta.js +38 -0
- package/defaults/subdirectory-reserved-names.d.ts +2 -0
- package/defaults/subdirectory-reserved-names.d.ts.map +1 -0
- package/defaults/subdirectory-reserved-names.js +16 -0
- package/defaults/taxonomies.d.ts +5 -0
- package/defaults/taxonomies.d.ts.map +1 -0
- package/defaults/taxonomies.js +57 -0
- package/defaults/timezone.d.ts +2 -0
- package/defaults/timezone.d.ts.map +1 -0
- package/defaults/timezone.js +353 -0
- package/package.json +51 -0
- package/query-builder/alias.d.ts +24 -0
- package/query-builder/alias.d.ts.map +1 -0
- package/query-builder/alias.js +64 -0
- package/query-builder/blogs.query.d.ts +22 -0
- package/query-builder/blogs.query.d.ts.map +1 -0
- package/query-builder/blogs.query.js +85 -0
- package/query-builder/comments.query.d.ts +35 -0
- package/query-builder/comments.query.d.ts.map +1 -0
- package/query-builder/comments.query.js +211 -0
- package/query-builder/common.query.d.ts +18 -0
- package/query-builder/common.query.d.ts.map +1 -0
- package/query-builder/common.query.js +58 -0
- package/query-builder/index.d.ts +12 -0
- package/query-builder/index.d.ts.map +1 -0
- package/query-builder/index.js +27 -0
- package/query-builder/meta.query.d.ts +45 -0
- package/query-builder/meta.query.d.ts.map +1 -0
- package/query-builder/meta.query.js +188 -0
- package/query-builder/options.query.d.ts +19 -0
- package/query-builder/options.query.d.ts.map +1 -0
- package/query-builder/options.query.js +57 -0
- package/query-builder/posts.query.d.ts +30 -0
- package/query-builder/posts.query.d.ts.map +1 -0
- package/query-builder/posts.query.js +208 -0
- package/query-builder/query-builder.d.ts +21 -0
- package/query-builder/query-builder.d.ts.map +1 -0
- package/query-builder/query-builder.js +70 -0
- package/query-builder/query-builders.d.ts +18 -0
- package/query-builder/query-builders.d.ts.map +1 -0
- package/query-builder/query-builders.js +64 -0
- package/query-builder/site.query.d.ts +22 -0
- package/query-builder/site.query.d.ts.map +1 -0
- package/query-builder/site.query.js +85 -0
- package/query-builder/terms.query.d.ts +47 -0
- package/query-builder/terms.query.d.ts.map +1 -0
- package/query-builder/terms.query.js +233 -0
- package/query-builder/users.query.d.ts +37 -0
- package/query-builder/users.query.d.ts.map +1 -0
- package/query-builder/users.query.js +188 -0
- package/schema-builder/proxy.d.ts +10 -0
- package/schema-builder/proxy.d.ts.map +1 -0
- package/schema-builder/proxy.js +19 -0
- package/schema-builder/schema-builder.d.ts +21 -0
- package/schema-builder/schema-builder.d.ts.map +1 -0
- package/schema-builder/schema-builder.js +207 -0
- package/schema-builder/schema.d.ts +20 -0
- package/schema-builder/schema.d.ts.map +1 -0
- package/schema-builder/schema.js +527 -0
- package/transactions/blog.trx.d.ts +37 -0
- package/transactions/blog.trx.d.ts.map +1 -0
- package/transactions/blog.trx.js +296 -0
- package/transactions/comment.trx.d.ts +22 -0
- package/transactions/comment.trx.d.ts.map +1 -0
- package/transactions/comment.trx.js +311 -0
- package/transactions/index.d.ts +15 -0
- package/transactions/index.d.ts.map +1 -0
- package/transactions/index.js +30 -0
- package/transactions/link.trx.d.ts +22 -0
- package/transactions/link.trx.d.ts.map +1 -0
- package/transactions/link.trx.js +208 -0
- package/transactions/meta.trx.d.ts +30 -0
- package/transactions/meta.trx.d.ts.map +1 -0
- package/transactions/meta.trx.js +197 -0
- package/transactions/options.trx.d.ts +31 -0
- package/transactions/options.trx.d.ts.map +1 -0
- package/transactions/options.trx.js +192 -0
- package/transactions/post.trx.d.ts +48 -0
- package/transactions/post.trx.d.ts.map +1 -0
- package/transactions/post.trx.js +906 -0
- package/transactions/registration-log.trx.d.ts +14 -0
- package/transactions/registration-log.trx.d.ts.map +1 -0
- package/transactions/registration-log.trx.js +103 -0
- package/transactions/revision.trx.d.ts +32 -0
- package/transactions/revision.trx.d.ts.map +1 -0
- package/transactions/revision.trx.js +278 -0
- package/transactions/roles.trx.d.ts +20 -0
- package/transactions/roles.trx.d.ts.map +1 -0
- package/transactions/roles.trx.js +144 -0
- package/transactions/seeder.trx.d.ts +43 -0
- package/transactions/seeder.trx.d.ts.map +1 -0
- package/transactions/seeder.trx.js +530 -0
- package/transactions/signup.trx.d.ts +53 -0
- package/transactions/signup.trx.d.ts.map +1 -0
- package/transactions/signup.trx.js +305 -0
- package/transactions/site.trx.d.ts +21 -0
- package/transactions/site.trx.d.ts.map +1 -0
- package/transactions/site.trx.js +167 -0
- package/transactions/term.trx.d.ts +51 -0
- package/transactions/term.trx.d.ts.map +1 -0
- package/transactions/term.trx.js +838 -0
- package/transactions/trx.d.ts +9 -0
- package/transactions/trx.d.ts.map +1 -0
- package/transactions/trx.js +20 -0
- package/transactions/user.trx.d.ts +45 -0
- package/transactions/user.trx.d.ts.map +1 -0
- package/transactions/user.trx.js +535 -0
- package/types/capabilities.d.ts +71 -0
- package/types/common.d.ts +16 -0
- package/types/component.d.ts +3 -0
- package/types/config.d.ts +33 -0
- package/types/crud.d.ts +230 -0
- package/types/database.d.ts +50 -0
- package/types/hooks/actions.d.ts +67 -0
- package/types/hooks/command.d.ts +17 -0
- package/types/hooks/filters.d.ts +86 -0
- package/types/hooks/index.d.ts +11 -0
- package/types/index.d.ts +18 -0
- package/types/logging.d.ts +1 -0
- package/types/meta.d.ts +9 -0
- package/types/options.d.ts +3 -0
- package/types/post.d.ts +54 -0
- package/types/query-builder.d.ts +11 -0
- package/types/role.d.ts +34 -0
- package/types/schema.d.ts +11 -0
- package/types/schema.d.ts.map +1 -0
- package/types/schema.js +2 -0
- package/types/taxonomy.d.ts +29 -0
- package/types/timezone.d.ts +3 -0
- package/types/transactions.d.ts +32 -0
- package/types/user.d.ts +12 -0
- package/types/validating.d.ts +9 -0
- package/types/validating.d.ts.map +1 -0
- package/types/validating.js +2 -0
- package/validators/config.d.ts +948 -0
- package/validators/config.d.ts.map +1 -0
- package/validators/config.js +149 -0
- package/validators/crud.d.ts +571 -0
- package/validators/crud.d.ts.map +1 -0
- package/validators/crud.js +281 -0
- package/validators/database.d.ts +958 -0
- package/validators/database.d.ts.map +1 -0
- package/validators/database.js +245 -0
- package/validators/date.d.ts +4 -0
- package/validators/date.d.ts.map +1 -0
- package/validators/date.js +15 -0
- package/validators/helpers.d.ts +16 -0
- package/validators/helpers.d.ts.map +1 -0
- package/validators/helpers.js +86 -0
- package/validators/index.d.ts +10 -0
- package/validators/index.d.ts.map +1 -0
- package/validators/index.js +48 -0
- package/validators/options.d.ts +303 -0
- package/validators/options.d.ts.map +1 -0
- package/validators/options.js +106 -0
- package/validators/post-status.d.ts +42 -0
- package/validators/post-status.d.ts.map +1 -0
- package/validators/post-status.js +18 -0
- package/validators/query.d.ts +534 -0
- package/validators/query.d.ts.map +1 -0
- package/validators/query.js +110 -0
- package/validators/roles.d.ts +22 -0
- package/validators/roles.d.ts.map +1 -0
- package/validators/roles.js +9 -0
- package/validators/sitemeta.d.ts +105 -0
- package/validators/sitemeta.d.ts.map +1 -0
- package/validators/sitemeta.js +39 -0
- package/validators/transactions/blog.d.ts +225 -0
- package/validators/transactions/blog.d.ts.map +1 -0
- package/validators/transactions/blog.js +63 -0
- package/validators/transactions/comment.d.ts +155 -0
- package/validators/transactions/comment.d.ts.map +1 -0
- package/validators/transactions/comment.js +68 -0
- package/validators/transactions/index.d.ts +11 -0
- package/validators/transactions/index.d.ts.map +1 -0
- package/validators/transactions/index.js +26 -0
- package/validators/transactions/link.d.ts +128 -0
- package/validators/transactions/link.d.ts.map +1 -0
- package/validators/transactions/link.js +60 -0
- package/validators/transactions/meta.d.ts +23 -0
- package/validators/transactions/meta.d.ts.map +1 -0
- package/validators/transactions/meta.js +18 -0
- package/validators/transactions/post.d.ts +234 -0
- package/validators/transactions/post.d.ts.map +1 -0
- package/validators/transactions/post.js +100 -0
- package/validators/transactions/roles.d.ts +18 -0
- package/validators/transactions/roles.d.ts.map +1 -0
- package/validators/transactions/roles.js +13 -0
- package/validators/transactions/signup.d.ts +35 -0
- package/validators/transactions/signup.d.ts.map +1 -0
- package/validators/transactions/signup.js +51 -0
- package/validators/transactions/site.d.ts +36 -0
- package/validators/transactions/site.d.ts.map +1 -0
- package/validators/transactions/site.js +49 -0
- package/validators/transactions/term.d.ts +57 -0
- package/validators/transactions/term.d.ts.map +1 -0
- package/validators/transactions/term.js +44 -0
- package/validators/transactions/user.d.ts +182 -0
- package/validators/transactions/user.d.ts.map +1 -0
- package/validators/transactions/user.js +104 -0
|
@@ -0,0 +1,626 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
21
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
22
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
23
|
+
};
|
|
24
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
+
var ownKeys = function(o) {
|
|
26
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
+
var ar = [];
|
|
28
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
+
return ar;
|
|
30
|
+
};
|
|
31
|
+
return ownKeys(o);
|
|
32
|
+
};
|
|
33
|
+
return function (mod) {
|
|
34
|
+
if (mod && mod.__esModule) return mod;
|
|
35
|
+
var result = {};
|
|
36
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
+
__setModuleDefault(result, mod);
|
|
38
|
+
return result;
|
|
39
|
+
};
|
|
40
|
+
})();
|
|
41
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
42
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.UserCrud = void 0;
|
|
46
|
+
const zod_1 = require("zod");
|
|
47
|
+
const common_1 = require("../common");
|
|
48
|
+
const diff_1 = require("../common/diff");
|
|
49
|
+
const config_1 = require("../config");
|
|
50
|
+
const components_1 = require("../core/components");
|
|
51
|
+
const current_1 = require("../core/current");
|
|
52
|
+
const roles_1 = require("../core/roles");
|
|
53
|
+
const query_util_1 = require("../core/utils/query.util");
|
|
54
|
+
const roles_util_1 = require("../core/utils/roles.util");
|
|
55
|
+
const user_util_1 = require("../core/utils/user.util");
|
|
56
|
+
const component_1 = require("../decorators/component");
|
|
57
|
+
const transactions_1 = require("../transactions");
|
|
58
|
+
const val = __importStar(require("../validators"));
|
|
59
|
+
const crud_1 = require("./crud");
|
|
60
|
+
const error_1 = require("./error");
|
|
61
|
+
let UserCrud = class UserCrud extends crud_1.Crud {
|
|
62
|
+
config;
|
|
63
|
+
constructor(components, config) {
|
|
64
|
+
super(components);
|
|
65
|
+
this.config = config;
|
|
66
|
+
}
|
|
67
|
+
async getAsUpsert(userId) {
|
|
68
|
+
const user = await this.get(userId, { context: "edit" });
|
|
69
|
+
const userUpsertMeta = val.trx.userUpsertMeta.parse(user.data.metas);
|
|
70
|
+
const userUpsert = val.trx.userUpsert
|
|
71
|
+
.merge(zod_1.z.object({
|
|
72
|
+
user_login: val.database.wpUsers.shape.user_login,
|
|
73
|
+
user_pass: zod_1.z.string().transform(() => ""),
|
|
74
|
+
}))
|
|
75
|
+
.parse({
|
|
76
|
+
...user.data,
|
|
77
|
+
role: user.data.roles,
|
|
78
|
+
meta_input: user.data.metas,
|
|
79
|
+
});
|
|
80
|
+
return this.returnValue({
|
|
81
|
+
...userUpsert,
|
|
82
|
+
...userUpsertMeta,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
// check_role_update
|
|
86
|
+
async checkRoleUpdatePermission(userId, role) {
|
|
87
|
+
const { user: currentUser } = await this.getUser();
|
|
88
|
+
if (!currentUser.props?.ID) {
|
|
89
|
+
throw new error_1.CrudError(error_1.StatusMessage.UNAUTHORIZED, "Invalid User");
|
|
90
|
+
}
|
|
91
|
+
const currentUserId = currentUser.props.ID;
|
|
92
|
+
const currentRole = await currentUser.role();
|
|
93
|
+
// Changing role
|
|
94
|
+
if (role.length > 0 &&
|
|
95
|
+
(0, diff_1.diffStringArray)(Array.from(currentRole.names), role).length > 0 &&
|
|
96
|
+
!(await currentUser.can("promote_user", userId))) {
|
|
97
|
+
throw new error_1.CrudError(error_1.StatusMessage.UNAUTHORIZED, "Sorry, you are not allowed to edit roles of this user");
|
|
98
|
+
}
|
|
99
|
+
// Removing role
|
|
100
|
+
if (0 >= role.length && !(await currentUser.can("remove_users"))) {
|
|
101
|
+
throw new error_1.CrudError(error_1.StatusMessage.UNAUTHORIZED, "Sorry, you are not allowed to edit roles of this user");
|
|
102
|
+
}
|
|
103
|
+
/*
|
|
104
|
+
* Don't let anyone with 'edit_users' (admins) edit their own role to something without it.
|
|
105
|
+
* Multisite super admins can freely edit their blog roles -- they possess all caps.
|
|
106
|
+
*/
|
|
107
|
+
if ((!this.config.isMultiSite() ||
|
|
108
|
+
!(await currentUser.can("manage_sites"))) &&
|
|
109
|
+
currentUserId === userId &&
|
|
110
|
+
!(await currentUser.can("edit_users"))) {
|
|
111
|
+
throw new error_1.CrudError(error_1.StatusMessage.UNAUTHORIZED, "Sorry, you are not allowed to give users that role");
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
async get(userId = 0, options) {
|
|
115
|
+
const userUtil = this.components.get(user_util_1.UserUtil);
|
|
116
|
+
const { user: currentUser } = await this.getUser();
|
|
117
|
+
let targetUser = currentUser;
|
|
118
|
+
if (userId > 0 && currentUser.props?.ID !== userId) {
|
|
119
|
+
if (!(await currentUser.can("list_users"))) {
|
|
120
|
+
throw new error_1.CrudError(error_1.StatusMessage.UNAUTHORIZED, "Sorry, you are not allowed to list users");
|
|
121
|
+
}
|
|
122
|
+
targetUser = await userUtil.get(userId);
|
|
123
|
+
}
|
|
124
|
+
if (!targetUser.props) {
|
|
125
|
+
throw new error_1.CrudError(error_1.StatusMessage.NOT_FOUND, "User not found");
|
|
126
|
+
}
|
|
127
|
+
let data = {};
|
|
128
|
+
const targetRole = await targetUser.role();
|
|
129
|
+
if (options?.context == "edit" &&
|
|
130
|
+
(currentUser.props?.ID === userId ||
|
|
131
|
+
(await currentUser.can("edit_users")))) {
|
|
132
|
+
data = {
|
|
133
|
+
...targetUser.props,
|
|
134
|
+
metas: await targetUser.meta.props(),
|
|
135
|
+
role: Array.from(targetRole.names),
|
|
136
|
+
capabilities: targetRole.capabilities,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
data = {
|
|
141
|
+
ID: targetUser.props.ID,
|
|
142
|
+
display_name: targetUser.props.display_name,
|
|
143
|
+
user_nicename: targetUser.props.user_nicename,
|
|
144
|
+
user_url: targetUser.props.user_url,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
return this.returnValue(data);
|
|
148
|
+
}
|
|
149
|
+
async getBlogs(userId) {
|
|
150
|
+
const { user: currentUser, userProps: currentUserProps } = await this.getUser();
|
|
151
|
+
if (!currentUserProps || !(await currentUser.can("manage_network_users"))) {
|
|
152
|
+
throw new error_1.CrudError(error_1.StatusMessage.UNAUTHORIZED, "Not permitted");
|
|
153
|
+
}
|
|
154
|
+
const userUtil = this.components.get(user_util_1.UserUtil);
|
|
155
|
+
const blogs = await userUtil.getBlogs(userId);
|
|
156
|
+
if (0 >= blogs.length) {
|
|
157
|
+
return this.returnValue([]);
|
|
158
|
+
}
|
|
159
|
+
const blogIds = blogs.map((blog) => blog.blog_id);
|
|
160
|
+
if (!(await currentUser.can("list_blog_users", blogIds))) {
|
|
161
|
+
throw new error_1.CrudError(error_1.StatusMessage.UNAUTHORIZED, "Not permitted");
|
|
162
|
+
}
|
|
163
|
+
return this.returnValue(blogs.map((blog) => ({
|
|
164
|
+
site_id: blog.site_id,
|
|
165
|
+
blog_id: blog.blog_id,
|
|
166
|
+
blogname: blog.blogname,
|
|
167
|
+
rolenames: blog.rolenames,
|
|
168
|
+
})));
|
|
169
|
+
}
|
|
170
|
+
async getAvailableSites() {
|
|
171
|
+
const { user: currentUser, userProps: currentUserProps } = await this.getUser();
|
|
172
|
+
if (!currentUserProps) {
|
|
173
|
+
throw new error_1.CrudError(error_1.StatusMessage.UNAUTHORIZED, "Not permitted");
|
|
174
|
+
}
|
|
175
|
+
const userUtil = this.components.get(user_util_1.UserUtil);
|
|
176
|
+
const currentUserId = currentUserProps.ID;
|
|
177
|
+
const currentSites = await userUtil.getSites(currentUserId);
|
|
178
|
+
if (!currentSites.primary_blog) {
|
|
179
|
+
throw new error_1.CrudError(error_1.StatusMessage.UNAUTHORIZED, "Not permitted (no primary blog)");
|
|
180
|
+
}
|
|
181
|
+
const getCapabilities = async (user, blogId, siteId, capabilities) => {
|
|
182
|
+
const set = new Set(capabilities);
|
|
183
|
+
if (await user.can("edit_user_roles", [blogId])) {
|
|
184
|
+
set.add("edit_user_roles");
|
|
185
|
+
}
|
|
186
|
+
if (await user.can("manage_roles", blogId)) {
|
|
187
|
+
set.add("manage_roles");
|
|
188
|
+
}
|
|
189
|
+
if (await user.can("list_blog_users", [blogId])) {
|
|
190
|
+
set.add("list_blog_users");
|
|
191
|
+
}
|
|
192
|
+
if (!(await user.can("manage_blog_users", [blogId]))) {
|
|
193
|
+
set.delete("edit_users");
|
|
194
|
+
}
|
|
195
|
+
(await user.can("create_users", [siteId]))
|
|
196
|
+
? set.add("create_users")
|
|
197
|
+
: set.delete("create_users");
|
|
198
|
+
return Array.from(set);
|
|
199
|
+
};
|
|
200
|
+
const getBlog = async (blog) => {
|
|
201
|
+
const capabilities = await getCapabilities(currentUser, blog.blog_id, blog.site_id, blog.capabilities);
|
|
202
|
+
const returnValue = {
|
|
203
|
+
site_id: blog.site_id,
|
|
204
|
+
blog_id: blog.blog_id,
|
|
205
|
+
blogname: blog.blogname,
|
|
206
|
+
rolenames: blog.rolenames,
|
|
207
|
+
blog_roles: undefined,
|
|
208
|
+
capabilities,
|
|
209
|
+
};
|
|
210
|
+
if (await currentUser.can("manage_blog_users", [blog.blog_id])) {
|
|
211
|
+
return {
|
|
212
|
+
...returnValue,
|
|
213
|
+
blog_roles: blog.blog_roles,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
return returnValue;
|
|
217
|
+
};
|
|
218
|
+
const sites = [];
|
|
219
|
+
for (const site of currentSites.sites ?? []) {
|
|
220
|
+
const blogs = [];
|
|
221
|
+
for (const blog of site.blogs) {
|
|
222
|
+
blogs.push(await getBlog(blog));
|
|
223
|
+
}
|
|
224
|
+
if (blogs.length > 0) {
|
|
225
|
+
sites.push({
|
|
226
|
+
site_id: site.site_id,
|
|
227
|
+
sitename: site.sitename,
|
|
228
|
+
siteurl: site.siteurl,
|
|
229
|
+
is_superadmin: site.is_superadmin,
|
|
230
|
+
blogs,
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return this.returnValue({
|
|
235
|
+
user: currentSites.user,
|
|
236
|
+
primary_blog: await getBlog(currentSites.primary_blog),
|
|
237
|
+
is_multisite: this.config.isMultiSite(),
|
|
238
|
+
sites: 0 >= sites.length ? undefined : sites,
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
async create(input) {
|
|
242
|
+
const { user: currentUser } = await this.getUser();
|
|
243
|
+
if (!(await currentUser.can("create_users"))) {
|
|
244
|
+
throw new error_1.CrudError(error_1.StatusMessage.UNAUTHORIZED, "Sorry, you are not allowed to create new users");
|
|
245
|
+
}
|
|
246
|
+
const data = val.trx.userUpsert.parse(input);
|
|
247
|
+
// For not to attach default role (subscriber)
|
|
248
|
+
data.role = !input.role ? undefined : data.role;
|
|
249
|
+
if (data.role) {
|
|
250
|
+
const roleNames = Array.isArray(data.role)
|
|
251
|
+
? data.role
|
|
252
|
+
.map((roleName) => roleName.trim())
|
|
253
|
+
.filter((roleName) => roleName.length > 0)
|
|
254
|
+
: [data.role];
|
|
255
|
+
if (0 >= roleNames.length) {
|
|
256
|
+
data.role = undefined;
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
const roles = this.components.get(roles_1.Roles);
|
|
260
|
+
for (const roleName of roleNames) {
|
|
261
|
+
if (!roles.get(roleName)) {
|
|
262
|
+
throw new error_1.CrudError(error_1.StatusMessage.BAD_REQUEST, `The role does not exist. - ${data.role}`);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
data.ID = undefined;
|
|
268
|
+
const userTrx = this.components.get(transactions_1.UserTrx);
|
|
269
|
+
const newUserId = await userTrx.upsert(data, {
|
|
270
|
+
attachRole: data.role ? true : false,
|
|
271
|
+
});
|
|
272
|
+
const userUtil = this.components.get(user_util_1.UserUtil);
|
|
273
|
+
const newUser = await userUtil.get(newUserId);
|
|
274
|
+
if (!newUser.props) {
|
|
275
|
+
throw new error_1.CrudError(error_1.StatusMessage.NOT_FOUND, "User not found");
|
|
276
|
+
}
|
|
277
|
+
const newUserLogin = newUser.props.user_login;
|
|
278
|
+
if (this.config.isMultiSite()) {
|
|
279
|
+
const signupTrx = this.components.get(transactions_1.SignupTrx);
|
|
280
|
+
await signupTrx.remove(newUserLogin);
|
|
281
|
+
if (data.role) {
|
|
282
|
+
const blogTrx = this.components.get(transactions_1.BlogTrx);
|
|
283
|
+
const current = this.components.get(current_1.Current);
|
|
284
|
+
await blogTrx.addUser(current.blogId, newUserId, data.role);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return this.returnValue(newUser.props);
|
|
288
|
+
}
|
|
289
|
+
async updateSuperAdmin(userId, options) {
|
|
290
|
+
if (!this.config.isMultiSite()) {
|
|
291
|
+
throw new error_1.CrudError(error_1.StatusMessage.BAD_REQUEST, "Not supported");
|
|
292
|
+
}
|
|
293
|
+
try {
|
|
294
|
+
const { blogId, siteId, remove = false } = options ?? {};
|
|
295
|
+
await this.switchBlog({
|
|
296
|
+
siteId,
|
|
297
|
+
blogId,
|
|
298
|
+
});
|
|
299
|
+
const userUtil = this.components.get(user_util_1.UserUtil);
|
|
300
|
+
const user = await userUtil.get(userId);
|
|
301
|
+
if (!user.props?.user_login) {
|
|
302
|
+
throw new error_1.CrudError(error_1.StatusMessage.NOT_FOUND, "User not found");
|
|
303
|
+
}
|
|
304
|
+
const { user: currentUser } = await this.getUser();
|
|
305
|
+
// Not allowing to remove own.
|
|
306
|
+
if ((userId === currentUser.props?.ID && remove) ||
|
|
307
|
+
!(await currentUser.can("manage_network_users"))) {
|
|
308
|
+
throw new error_1.CrudError(error_1.StatusMessage.UNAUTHORIZED, "Not permitted");
|
|
309
|
+
}
|
|
310
|
+
const userTrx = this.components.get(transactions_1.UserTrx);
|
|
311
|
+
await userTrx.syncSuperAdmin(userId, {
|
|
312
|
+
siteId,
|
|
313
|
+
blogId,
|
|
314
|
+
remove,
|
|
315
|
+
});
|
|
316
|
+
return this.returnValue(true);
|
|
317
|
+
}
|
|
318
|
+
finally {
|
|
319
|
+
await this.restoreBlog();
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
async updateRole(userId, role, options) {
|
|
323
|
+
try {
|
|
324
|
+
const { blogId, siteId } = options ?? {};
|
|
325
|
+
await this.switchBlog({
|
|
326
|
+
siteId,
|
|
327
|
+
blogId,
|
|
328
|
+
});
|
|
329
|
+
const parsedRole = zod_1.z.array(zod_1.z.string()).parse(role);
|
|
330
|
+
await this.checkRoleUpdatePermission(userId, parsedRole);
|
|
331
|
+
const userUtil = this.components.get(user_util_1.UserUtil);
|
|
332
|
+
const user = await userUtil.get(userId);
|
|
333
|
+
if (!user.props?.user_login) {
|
|
334
|
+
throw new error_1.CrudError(error_1.StatusMessage.NOT_FOUND, "User not found");
|
|
335
|
+
}
|
|
336
|
+
const userTrx = this.components.get(transactions_1.UserTrx);
|
|
337
|
+
if (parsedRole.length > 0) {
|
|
338
|
+
await userTrx.upsertRole(userId, parsedRole);
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
await userTrx.removeRole(userId, {
|
|
342
|
+
removeSuperAdmin: false,
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
return this.returnValue(true);
|
|
346
|
+
}
|
|
347
|
+
finally {
|
|
348
|
+
await this.restoreBlog();
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
async update(userId, data, options) {
|
|
352
|
+
try {
|
|
353
|
+
const { blogId, siteId, attachRole = false, removeRole = false, } = options ?? {};
|
|
354
|
+
await this.switchBlog({
|
|
355
|
+
siteId,
|
|
356
|
+
blogId,
|
|
357
|
+
});
|
|
358
|
+
data.ID = userId;
|
|
359
|
+
const { user: currentUser } = await this.getUser();
|
|
360
|
+
const queryUtil = this.components.get(query_util_1.QueryUtil);
|
|
361
|
+
const currentUserData = (await this.getAsUpsert(userId)).data;
|
|
362
|
+
const diffData = (0, diff_1.diffObject)(data, currentUserData);
|
|
363
|
+
if (!(await currentUser.can("edit_user", userId))) {
|
|
364
|
+
throw new error_1.CrudError(error_1.StatusMessage.UNAUTHORIZED, "Sorry, you are not allowed to edit this user");
|
|
365
|
+
}
|
|
366
|
+
if (diffData.user_login ||
|
|
367
|
+
currentUserData.user_login !== data.user_login) {
|
|
368
|
+
throw new error_1.CrudError(error_1.StatusMessage.UNAUTHORIZED, "User Login is not editable");
|
|
369
|
+
}
|
|
370
|
+
if (typeof data.user_nicename == "string" &&
|
|
371
|
+
data.user_nicename.length > 0 &&
|
|
372
|
+
data.user_nicename !== currentUserData.user_nicename &&
|
|
373
|
+
(await queryUtil.users((query) => {
|
|
374
|
+
query.where("user_nicename", data.user_nicename);
|
|
375
|
+
}))) {
|
|
376
|
+
throw new error_1.CrudError(error_1.StatusMessage.BAD_REQUEST, "Invalid slug");
|
|
377
|
+
}
|
|
378
|
+
const userTrx = this.components.get(transactions_1.UserTrx);
|
|
379
|
+
if (data.role) {
|
|
380
|
+
const roleNames = Array.isArray(data.role)
|
|
381
|
+
? data.role
|
|
382
|
+
.map((roleName) => roleName.trim())
|
|
383
|
+
.filter((roleName) => roleName.length > 0)
|
|
384
|
+
: [data.role];
|
|
385
|
+
await this.checkRoleUpdatePermission(userId, roleNames);
|
|
386
|
+
if (0 >= roleNames.length) {
|
|
387
|
+
data.role = undefined;
|
|
388
|
+
}
|
|
389
|
+
else {
|
|
390
|
+
const roles = this.components.get(roles_1.Roles);
|
|
391
|
+
for (const roleName of roleNames) {
|
|
392
|
+
if (!roles.get(roleName)) {
|
|
393
|
+
throw new error_1.CrudError(error_1.StatusMessage.BAD_REQUEST, `The role does not exist - ${data.role}`);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
return this.returnValue(await userTrx.upsert(data, {
|
|
399
|
+
attachRole,
|
|
400
|
+
removeRole,
|
|
401
|
+
}));
|
|
402
|
+
}
|
|
403
|
+
finally {
|
|
404
|
+
await this.restoreBlog();
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
async updatePassword(userId, newPassword) {
|
|
408
|
+
const userUtil = this.components.get(user_util_1.UserUtil);
|
|
409
|
+
const user = await userUtil.get(userId);
|
|
410
|
+
if (!user.props || !user.props.user_login) {
|
|
411
|
+
throw new error_1.CrudError(error_1.StatusMessage.BAD_REQUEST, "User not found");
|
|
412
|
+
}
|
|
413
|
+
const userLogin = user.props.user_login;
|
|
414
|
+
const hashedPassword = (0, common_1.hashPassword)(newPassword);
|
|
415
|
+
return await this.update(userId, {
|
|
416
|
+
user_login: userLogin,
|
|
417
|
+
user_pass: hashedPassword,
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
async delete(userId, options) {
|
|
421
|
+
const { reassignList = undefined } = options ?? {};
|
|
422
|
+
let { reassign = undefined } = options ?? {};
|
|
423
|
+
const { user: currentUser } = await this.getUser();
|
|
424
|
+
const userTrx = this.components.get(transactions_1.UserTrx);
|
|
425
|
+
if (!(await currentUser.can("delete_user", userId))) {
|
|
426
|
+
throw new error_1.CrudError(error_1.StatusMessage.UNAUTHORIZED, "Sorry, you are not allowed to delete this user");
|
|
427
|
+
}
|
|
428
|
+
if (!this.config.isMultiSite()) {
|
|
429
|
+
if (reassignList) {
|
|
430
|
+
reassign = Object.values(reassignList)[0];
|
|
431
|
+
}
|
|
432
|
+
return this.returnValue(await userTrx.remove(userId, reassign));
|
|
433
|
+
}
|
|
434
|
+
return this.returnValue(await userTrx.removeFromAllBlogs(userId, reassignList));
|
|
435
|
+
}
|
|
436
|
+
async list(args, options) {
|
|
437
|
+
try {
|
|
438
|
+
const { context = "view" } = options ?? {};
|
|
439
|
+
const queryUtil = this.components.get(query_util_1.QueryUtil);
|
|
440
|
+
const userUtil = this.components.get(user_util_1.UserUtil);
|
|
441
|
+
const rolesUtil = this.components.get(roles_util_1.RolesUtil);
|
|
442
|
+
const parsedArgs = val.crud.userListParams.parse(args ?? {});
|
|
443
|
+
await this.switchBlog({
|
|
444
|
+
siteId: parsedArgs.site_id,
|
|
445
|
+
blogId: parsedArgs.blog_id,
|
|
446
|
+
});
|
|
447
|
+
const { user: currentUser } = await this.getUser();
|
|
448
|
+
const currentRole = await currentUser.role();
|
|
449
|
+
if ((parsedArgs.roles ||
|
|
450
|
+
parsedArgs.superadmins ||
|
|
451
|
+
parsedArgs.include_unregistered_users ||
|
|
452
|
+
context == "edit" ||
|
|
453
|
+
parsedArgs.orderby == "user_email" ||
|
|
454
|
+
parsedArgs.orderby == "user_registered") &&
|
|
455
|
+
(!currentUser.props?.ID || !(await currentUser.can("list_users")))) {
|
|
456
|
+
throw new error_1.CrudError(error_1.StatusMessage.UNAUTHORIZED, "Sorry, you are not allowed to filter users by role");
|
|
457
|
+
}
|
|
458
|
+
let blogIds = [];
|
|
459
|
+
let superAdmins = [];
|
|
460
|
+
if (this.config.isMultiSite()) {
|
|
461
|
+
const current = this.components.get(current_1.Current);
|
|
462
|
+
superAdmins =
|
|
463
|
+
(await rolesUtil.getSuperAdmins({
|
|
464
|
+
siteId: current.siteId,
|
|
465
|
+
})) ?? [];
|
|
466
|
+
if (parsedArgs.site_id) {
|
|
467
|
+
const siteId = parsedArgs.site_id;
|
|
468
|
+
const blogs = (await queryUtil.blogs((query) => {
|
|
469
|
+
query.where("site_id", siteId);
|
|
470
|
+
})) ?? [];
|
|
471
|
+
// List all users in site
|
|
472
|
+
blogs.map((blog) => blogIds?.push(blog.blog_id));
|
|
473
|
+
}
|
|
474
|
+
else {
|
|
475
|
+
const current = this.components.get(current_1.Current);
|
|
476
|
+
blogIds = [parsedArgs.blog_id ?? current.blogId];
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
const includeAnonymous = Array.isArray(parsedArgs.roles) &&
|
|
480
|
+
parsedArgs.roles.filter((role) => role === "anonymous").length > 0;
|
|
481
|
+
const roleNames = !Array.isArray(parsedArgs.roles)
|
|
482
|
+
? []
|
|
483
|
+
: parsedArgs.roles.filter((role) => role !== "anonymous");
|
|
484
|
+
const buildSearchQuery = (query) => {
|
|
485
|
+
query.andWhere((query) => {
|
|
486
|
+
const searchColumns = [
|
|
487
|
+
"user_login",
|
|
488
|
+
"user_nicename",
|
|
489
|
+
"display_name",
|
|
490
|
+
"user_email",
|
|
491
|
+
];
|
|
492
|
+
for (const searchColumn of searchColumns) {
|
|
493
|
+
parsedArgs.search &&
|
|
494
|
+
query.or.whereLike(searchColumn, parsedArgs.search);
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
};
|
|
498
|
+
const buildQuery = (query) => {
|
|
499
|
+
const { column } = query.alias;
|
|
500
|
+
const offset = parsedArgs.offset ?? (parsedArgs.page - 1) * parsedArgs.per_page;
|
|
501
|
+
const limit = parsedArgs.per_page;
|
|
502
|
+
if (includeAnonymous && !parsedArgs.exclude_anonymous) {
|
|
503
|
+
query.hasNoRole();
|
|
504
|
+
}
|
|
505
|
+
else if (blogIds.length > 0) {
|
|
506
|
+
query.andWhere((query) => {
|
|
507
|
+
query.withBlogIds(blogIds);
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
else if (!this.config.isMultiSite()) {
|
|
511
|
+
// For single site
|
|
512
|
+
query.hasRole();
|
|
513
|
+
}
|
|
514
|
+
query.builder
|
|
515
|
+
.offset(offset)
|
|
516
|
+
.limit(limit)
|
|
517
|
+
.groupBy(column("users", "ID"));
|
|
518
|
+
if (parsedArgs.orderby) {
|
|
519
|
+
query.builder.orderBy(column("users", parsedArgs.orderby), parsedArgs.order);
|
|
520
|
+
}
|
|
521
|
+
if (Array.isArray(parsedArgs.include)) {
|
|
522
|
+
query.whereIn("ID", parsedArgs.include);
|
|
523
|
+
}
|
|
524
|
+
if (Array.isArray(parsedArgs.exclude)) {
|
|
525
|
+
query.andWhereNot((query) => query.whereIn("ID", parsedArgs.exclude));
|
|
526
|
+
}
|
|
527
|
+
if (parsedArgs.search) {
|
|
528
|
+
buildSearchQuery(query);
|
|
529
|
+
}
|
|
530
|
+
if (Array.isArray(parsedArgs.slug) && parsedArgs.slug.length > 0) {
|
|
531
|
+
query.where("user_nicename", parsedArgs.slug);
|
|
532
|
+
}
|
|
533
|
+
if (roleNames.length > 0) {
|
|
534
|
+
query.withRoles(roleNames);
|
|
535
|
+
}
|
|
536
|
+
// SuperAdmins
|
|
537
|
+
if (superAdmins.length > 0) {
|
|
538
|
+
if (parsedArgs.site_id && currentRole.isSuperAdmin()) {
|
|
539
|
+
query[parsedArgs.superadmins ? "andWhere" : "orWhere"]((query) => {
|
|
540
|
+
query.whereIn("user_login", superAdmins);
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
// Include anonymous users if no role is specified
|
|
545
|
+
if (!includeAnonymous &&
|
|
546
|
+
!parsedArgs.exclude_anonymous &&
|
|
547
|
+
0 >= roleNames.length &&
|
|
548
|
+
!parsedArgs.superadmins) {
|
|
549
|
+
query.orWhere((query) => {
|
|
550
|
+
query.hasNoRole();
|
|
551
|
+
if (parsedArgs.search) {
|
|
552
|
+
buildSearchQuery(query);
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
if (parsedArgs.has_published_posts) {
|
|
557
|
+
query.withPublishedPosts();
|
|
558
|
+
}
|
|
559
|
+
};
|
|
560
|
+
const users = (await queryUtil.users((query) => {
|
|
561
|
+
buildQuery(query);
|
|
562
|
+
})) ?? [];
|
|
563
|
+
const counts = await queryUtil.users((query) => {
|
|
564
|
+
buildQuery(query);
|
|
565
|
+
query.count("users", "ID");
|
|
566
|
+
}, val.query.resultCount);
|
|
567
|
+
const countPosts = context !== "edit"
|
|
568
|
+
? []
|
|
569
|
+
: await userUtil.countPosts(users.map((user) => user.ID));
|
|
570
|
+
const data = [];
|
|
571
|
+
for (const user of await userUtil.toUsers(users)) {
|
|
572
|
+
if (!user.props)
|
|
573
|
+
continue;
|
|
574
|
+
// const props = Object.entries(user.props)
|
|
575
|
+
// .filter(([k]) => k !== "user_pass")
|
|
576
|
+
// .reduce((a, b) => ({ ...a, [b[0]]: b[1] }), {}) as Exclude<
|
|
577
|
+
// types.WpUsers,
|
|
578
|
+
// "user_pass"
|
|
579
|
+
// >;
|
|
580
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
581
|
+
const { user_pass, ...props } = user.props;
|
|
582
|
+
const role = await user.role();
|
|
583
|
+
const posts = countPosts?.filter((v) => v.post_author == props.ID)[0]?.count ?? 0;
|
|
584
|
+
if (this.config.isMultiSite() && !currentRole.isSuperAdmin()) {
|
|
585
|
+
role.names.delete("superadmin");
|
|
586
|
+
}
|
|
587
|
+
if (context === "edit") {
|
|
588
|
+
data.push({
|
|
589
|
+
...props,
|
|
590
|
+
metas: await user.meta.props(),
|
|
591
|
+
roles: Array.from(role.names),
|
|
592
|
+
capabilities: role.capabilities,
|
|
593
|
+
posts,
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
else {
|
|
597
|
+
data.push({
|
|
598
|
+
ID: props.ID,
|
|
599
|
+
display_name: props.display_name,
|
|
600
|
+
user_url: props.user_url,
|
|
601
|
+
user_nicename: props.user_nicename,
|
|
602
|
+
user_login: props.user_login,
|
|
603
|
+
posts,
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
const pagination = this.pagination({
|
|
608
|
+
page: parsedArgs.page,
|
|
609
|
+
limit: parsedArgs.per_page,
|
|
610
|
+
count: counts?.count ?? 0,
|
|
611
|
+
});
|
|
612
|
+
return this.returnValue(data, {
|
|
613
|
+
pagination,
|
|
614
|
+
context,
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
finally {
|
|
618
|
+
await this.restoreBlog();
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
};
|
|
622
|
+
exports.UserCrud = UserCrud;
|
|
623
|
+
exports.UserCrud = UserCrud = __decorate([
|
|
624
|
+
(0, component_1.component)(),
|
|
625
|
+
__metadata("design:paramtypes", [components_1.Components, config_1.Config])
|
|
626
|
+
], UserCrud);
|
package/database.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Knex } from "knex";
|
|
2
|
+
import { Config } from "./config";
|
|
3
|
+
export type DbConnection = Knex | undefined;
|
|
4
|
+
export default class Database {
|
|
5
|
+
#private;
|
|
6
|
+
private config;
|
|
7
|
+
static connections: Knex[];
|
|
8
|
+
static perSiteTables: (keyof import("./types").Tables)[];
|
|
9
|
+
constructor(config: Config);
|
|
10
|
+
get prefix(): string;
|
|
11
|
+
hasTable(tableName: string): Promise<boolean>;
|
|
12
|
+
get connection(): Knex<any, any[]>;
|
|
13
|
+
get transaction(): Promise<Knex.Transaction<any, any[]>>;
|
|
14
|
+
get schema(): Knex.SchemaBuilder;
|
|
15
|
+
closeConnection(): void;
|
|
16
|
+
static closeAll(): void;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=database.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../src/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAKlC,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,SAAS,CAAC;AAG5C,MAAM,CAAC,OAAO,OAAO,QAAQ;;IAKf,OAAO,CAAC,MAAM;IAJ1B,MAAM,CAAC,WAAW,EAAE,IAAI,EAAE,CAAM;IAChC,MAAM,CAAC,aAAa,qCAAgC;gBAGhC,MAAM,EAAE,MAAM;IAmBlC,IAAI,MAAM,WAET;IAEK,QAAQ,CAAC,SAAS,EAAE,MAAM;IAIhC,IAAI,UAAU,qBAEb;IAED,IAAI,WAAW,0CAEd;IAED,IAAI,MAAM,uBAET;IAED,eAAe;IAUf,MAAM,CAAC,QAAQ;CAOhB"}
|