diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 4fa312f3ad..4fb5d5bf6e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -121,7 +121,7 @@ jobs: - uses: nrwl/nx-set-shas@v3 - name: Monorepo install uses: ./.github/actions/yarn-nm-install - - name: Run build for admin-test-utils + - name: Run build:ts for admin-test-utils & helper-plugin run: yarn build --projects=@strapi/admin-test-utils,@strapi/helper-plugin --skip-nx-cache - name: Run test run: yarn nx affected --target=test:front --nx-ignore-cycles diff --git a/packages/core/helper-plugin/declarations/@strapi/permissions.d.ts b/packages/core/helper-plugin/declarations/@strapi/permissions.d.ts deleted file mode 100644 index 7e8e60edac..0000000000 --- a/packages/core/helper-plugin/declarations/@strapi/permissions.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -export interface Permission { - action: string; - subject?: string | object | null; - properties?: object; - conditions?: string[]; -} diff --git a/packages/core/helper-plugin/src/components/CheckPagePermissions.tsx b/packages/core/helper-plugin/src/components/CheckPagePermissions.tsx index 80b7ca711a..6802ecfc73 100644 --- a/packages/core/helper-plugin/src/components/CheckPagePermissions.tsx +++ b/packages/core/helper-plugin/src/components/CheckPagePermissions.tsx @@ -8,7 +8,9 @@ import { hasPermissions } from '../utils/hasPermissions'; import { LoadingIndicatorPage } from './LoadingIndicatorPage'; -import type { Permission } from '@strapi/permissions'; +import type { domain } from '@strapi/permissions'; + +type Permission = domain.permission.Permission; export interface CheckPagePermissions { children: React.ReactNode; diff --git a/packages/core/helper-plugin/src/components/CheckPermissions.tsx b/packages/core/helper-plugin/src/components/CheckPermissions.tsx index 00d5feafec..8fb9bf1cde 100644 --- a/packages/core/helper-plugin/src/components/CheckPermissions.tsx +++ b/packages/core/helper-plugin/src/components/CheckPermissions.tsx @@ -4,7 +4,9 @@ import { useNotification } from '../features/Notifications'; import { useRBACProvider } from '../features/RBAC'; import { hasPermissions } from '../utils/hasPermissions'; -import type { Permission } from '@strapi/permissions'; +import type { domain } from '@strapi/permissions'; + +type Permission = domain.permission.Permission; // NOTE: this component is very similar to the CheckPagePermissions // except that it does not handle redirections nor loading state diff --git a/packages/core/helper-plugin/src/features/RBAC.tsx b/packages/core/helper-plugin/src/features/RBAC.tsx index 17191277c2..46b8cb6b8b 100644 --- a/packages/core/helper-plugin/src/features/RBAC.tsx +++ b/packages/core/helper-plugin/src/features/RBAC.tsx @@ -1,8 +1,10 @@ import * as React from 'react'; -import type { Permission } from '@strapi/permissions'; +import type { domain } from '@strapi/permissions'; import type { QueryObserverBaseResult } from 'react-query'; +type Permission = domain.permission.Permission; + /* ------------------------------------------------------------------------------------------------- * Context * -----------------------------------------------------------------------------------------------*/ diff --git a/packages/core/helper-plugin/src/features/StrapiApp.tsx b/packages/core/helper-plugin/src/features/StrapiApp.tsx index fb49e6dac7..c3e72c2de5 100644 --- a/packages/core/helper-plugin/src/features/StrapiApp.tsx +++ b/packages/core/helper-plugin/src/features/StrapiApp.tsx @@ -2,7 +2,9 @@ import * as React from 'react'; import { TranslationMessage } from '../types'; -import type { Permission } from '@strapi/permissions'; +import type { domain } from '@strapi/permissions'; + +type Permission = domain.permission.Permission; interface MenuItem { to: string; diff --git a/packages/core/helper-plugin/src/hooks/useQueryParams.ts b/packages/core/helper-plugin/src/hooks/useQueryParams.ts index 0ef0d707fc..1340f58725 100644 --- a/packages/core/helper-plugin/src/hooks/useQueryParams.ts +++ b/packages/core/helper-plugin/src/hooks/useQueryParams.ts @@ -1,6 +1,6 @@ import { useCallback, useMemo } from 'react'; -import { parse, ParsedQs, stringify } from 'qs'; +import { parse, stringify } from 'qs'; import { useHistory, useLocation } from 'react-router-dom'; const useQueryParams = >(initialParams?: TQuery) => { diff --git a/packages/core/helper-plugin/src/hooks/useRBAC.ts b/packages/core/helper-plugin/src/hooks/useRBAC.ts index ec949da4d4..e29dd1150d 100644 --- a/packages/core/helper-plugin/src/hooks/useRBAC.ts +++ b/packages/core/helper-plugin/src/hooks/useRBAC.ts @@ -6,9 +6,11 @@ import { useRBACProvider } from '../features/RBAC'; import { useFetchClient } from './useFetchClient'; -import type { Permission } from '@strapi/permissions'; +import type { domain } from '@strapi/permissions'; import type { AxiosResponse } from 'axios'; +type Permission = domain.permission.Permission; + type AllowedActions = Record; export const useRBAC = ( diff --git a/packages/core/helper-plugin/src/utils/hasPermissions.ts b/packages/core/helper-plugin/src/utils/hasPermissions.ts index 7d21c47cbf..ffd0f0300d 100644 --- a/packages/core/helper-plugin/src/utils/hasPermissions.ts +++ b/packages/core/helper-plugin/src/utils/hasPermissions.ts @@ -1,8 +1,10 @@ import { getFetchClient } from './getFetchClient'; -import type { Permission } from '@strapi/permissions'; +import type { domain } from '@strapi/permissions'; import type { GenericAbortSignal } from 'axios'; +type Permission = domain.permission.Permission; + const findMatchingPermissions = (userPermissions: Permission[], permissions: Permission[]) => userPermissions.reduce((acc, curr) => { const associatedPermission = permissions.find( diff --git a/packages/core/helper-plugin/src/utils/tests/hasPermissions.test.ts b/packages/core/helper-plugin/src/utils/tests/hasPermissions.test.ts index bc05664690..8c0a37c922 100644 --- a/packages/core/helper-plugin/src/utils/tests/hasPermissions.test.ts +++ b/packages/core/helper-plugin/src/utils/tests/hasPermissions.test.ts @@ -1,5 +1,3 @@ -import { Permission } from '@strapi/permissions'; - import { hasPermissions, findMatchingPermissions, @@ -7,6 +5,10 @@ import { shouldCheckPermissions, } from '../hasPermissions'; +import type { domain } from '@strapi/permissions'; + +type Permission = domain.permission.Permission; + const hasPermissionsTestData: Record> = { userPermissions: { user1: [ diff --git a/packages/core/permissions/package.json b/packages/core/permissions/package.json index b6a6e6ed22..fdac24fc05 100644 --- a/packages/core/permissions/package.json +++ b/packages/core/permissions/package.json @@ -19,20 +19,22 @@ "url": "https://strapi.io" } ], + "main": "./dist/index.js", + "module": "./dist/index.mjs", + "source": "./src/index.ts", + "types": "./dist/index.d.ts", "files": [ "./dist" ], - "main": "./dist/index.js", - "types": "./dist/index.d.ts", "scripts": { - "build": "run -T tsc", - "build:ts": "run build", - "watch": "run -T tsc -w --preserveWatchOutput", + "build": "pack-up build", "clean": "run -T rimraf ./dist", + "lint": "run -T eslint .", "prepublishOnly": "yarn clean && yarn build", + "test:ts": "run -T tsc --noEmit", "test:unit": "run -T jest", "test:unit:watch": "run -T jest --watch", - "lint": "run -T eslint ." + "watch": "pack-up watch" }, "dependencies": { "@casl/ability": "6.5.0", @@ -42,6 +44,7 @@ "sift": "16.0.1" }, "devDependencies": { + "@strapi/pack-up": "workspace:*", "eslint-config-custom": "4.14.3", "tsconfig": "4.14.3" }, diff --git a/packages/core/permissions/packup.config.ts b/packages/core/permissions/packup.config.ts new file mode 100644 index 0000000000..95e06b2131 --- /dev/null +++ b/packages/core/permissions/packup.config.ts @@ -0,0 +1,6 @@ +// eslint-disable-next-line import/no-extraneous-dependencies +import { defineConfig } from '@strapi/pack-up'; + +export default defineConfig({ + runtime: 'node', +}); diff --git a/packages/core/permissions/src/__tests__/permissions.engine.test.ts b/packages/core/permissions/src/__tests__/permissions.engine.test.ts index 0ae4525d9b..ac2363a8bc 100644 --- a/packages/core/permissions/src/__tests__/permissions.engine.test.ts +++ b/packages/core/permissions/src/__tests__/permissions.engine.test.ts @@ -1,7 +1,7 @@ import _ from 'lodash'; import { subject } from '@casl/ability'; import { providerFactory } from '@strapi/utils'; -import permissions from '..'; +import * as permissions from '../index'; import type { HookName } from '../engine/hooks'; import type { Permission } from '../domain/permission'; diff --git a/packages/core/permissions/src/index.ts b/packages/core/permissions/src/index.ts index 8d6c12e778..55611014da 100644 --- a/packages/core/permissions/src/index.ts +++ b/packages/core/permissions/src/index.ts @@ -1,7 +1,4 @@ import * as domain from './domain'; import * as engine from './engine'; -export = { - domain, - engine, -}; +export { domain, engine }; diff --git a/packages/core/permissions/tsconfig.build.json b/packages/core/permissions/tsconfig.build.json new file mode 100644 index 0000000000..e54ade8009 --- /dev/null +++ b/packages/core/permissions/tsconfig.build.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "rootDir": "./src", + "outDir": "./dist" + }, + "include": ["src"], + "exclude": ["**/__tests__/**"] +} diff --git a/packages/core/permissions/tsconfig.eslint.json b/packages/core/permissions/tsconfig.eslint.json index b531808514..d0192f9ff6 100644 --- a/packages/core/permissions/tsconfig.eslint.json +++ b/packages/core/permissions/tsconfig.eslint.json @@ -3,6 +3,6 @@ "compilerOptions": { "noEmit": true }, - "include": ["src"], + "include": ["src", "packup.config.ts"], "exclude": ["node_modules"] } diff --git a/packages/core/utils/package.json b/packages/core/utils/package.json index 81be25bf0c..a48eec18de 100644 --- a/packages/core/utils/package.json +++ b/packages/core/utils/package.json @@ -39,6 +39,7 @@ "clean": "run -T rimraf ./dist", "lint": "run -T eslint .", "prepublishOnly": "yarn clean && yarn build", + "test:ts": "run -T tsc --noEmit", "test:unit": "run -T jest", "test:unit:watch": "run -T jest --watch", "watch": "run -T pack-up watch" diff --git a/yarn.lock b/yarn.lock index fafb6a5c23..c90900e02b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7817,6 +7817,7 @@ __metadata: resolution: "@strapi/permissions@workspace:packages/core/permissions" dependencies: "@casl/ability": 6.5.0 + "@strapi/pack-up": "workspace:*" "@strapi/utils": 4.14.3 eslint-config-custom: 4.14.3 lodash: 4.17.21