@malevich-studio/strapi-sdk-typescript 1.2.20 → 1.2.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +10 -6
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.mjs +10 -6
- package/dist/cli.mjs.map +1 -1
- package/dist/index.cjs +5 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +16 -11
- package/dist/index.mjs +5 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -21442,8 +21442,11 @@ class Strapi {
|
|
|
21442
21442
|
}
|
|
21443
21443
|
async can(uid, controller, action) {
|
|
21444
21444
|
if (!this.permissionsList) {
|
|
21445
|
-
const
|
|
21446
|
-
|
|
21445
|
+
const user = await this.baseMe({ populate: { role: { fields: ["id"] } } });
|
|
21446
|
+
if (user.error) {
|
|
21447
|
+
return false;
|
|
21448
|
+
}
|
|
21449
|
+
const response = await this.fetchData(`users-permissions/roles/${user.role.id}`);
|
|
21447
21450
|
this.permissionsList = response.role.permissions;
|
|
21448
21451
|
}
|
|
21449
21452
|
if (!this.permissionsList[uid]) {
|
|
@@ -21919,7 +21922,7 @@ function generateInputTypeCode(name, attributes) {
|
|
|
21919
21922
|
lines.push(`}`);
|
|
21920
21923
|
return lines.join('\n');
|
|
21921
21924
|
}
|
|
21922
|
-
function generateMethodsCode(contentType) {
|
|
21925
|
+
function generateMethodsCode(contentType, permissions) {
|
|
21923
21926
|
const methods = [];
|
|
21924
21927
|
const modelName = getContentTypeName(contentType.uid);
|
|
21925
21928
|
if (contentType.schema.kind === ContentTypeKind.CollectionType) {
|
|
@@ -21949,10 +21952,10 @@ function generateMethodsCode(contentType) {
|
|
|
21949
21952
|
` return await this.delete<${modelName}>('${contentType.schema.pluralName}', id, params);`,
|
|
21950
21953
|
' }',
|
|
21951
21954
|
].join('\n'));
|
|
21952
|
-
console.log(contentType.uid);
|
|
21953
21955
|
if (contentType.uid.startsWith('api::')) {
|
|
21956
|
+
const actions = Object.keys(permissions[contentType.uid.split('.')[0]].controllers[contentType.schema.singularName]);
|
|
21954
21957
|
methods.push([
|
|
21955
|
-
` public async can${getContentTypeName(contentType.schema.singularName)}(action:
|
|
21958
|
+
` public async can${getContentTypeName(contentType.schema.singularName)}(action: '${actions.join('\' | \'')}') {`,
|
|
21956
21959
|
` return await this.can('${contentType.uid.split('.')[0]}', '${contentType.schema.singularName}', action);`,
|
|
21957
21960
|
' }',
|
|
21958
21961
|
].join('\n'));
|
|
@@ -21965,6 +21968,7 @@ function generateMethodsCode(contentType) {
|
|
|
21965
21968
|
async function generateStrapiTypes(strapi) {
|
|
21966
21969
|
const contentTypes = (await strapi.fetch('content-type-builder/content-types')).data || [];
|
|
21967
21970
|
const components = (await strapi.fetch('content-type-builder/components')).data || [];
|
|
21971
|
+
const permissions = (await strapi.fetchData('users-permissions/permissions')).permissions || {};
|
|
21968
21972
|
const allInterfaces = [];
|
|
21969
21973
|
const methods = [];
|
|
21970
21974
|
for (const component of components) {
|
|
@@ -21983,7 +21987,7 @@ async function generateStrapiTypes(strapi) {
|
|
|
21983
21987
|
if (!['api::', 'plugin::upload', 'plugin::users-permissions'].filter(prefix => contentType.uid.startsWith(prefix)).length) {
|
|
21984
21988
|
continue;
|
|
21985
21989
|
}
|
|
21986
|
-
methods.push(...generateMethodsCode(contentType));
|
|
21990
|
+
methods.push(...generateMethodsCode(contentType, permissions));
|
|
21987
21991
|
const modelName = getContentTypeName(contentType.uid);
|
|
21988
21992
|
const attributes = {
|
|
21989
21993
|
id: {
|