@malevich-studio/strapi-sdk-typescript 1.2.19 → 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 CHANGED
@@ -21462,8 +21462,11 @@ class Strapi {
21462
21462
  }
21463
21463
  async can(uid, controller, action) {
21464
21464
  if (!this.permissionsList) {
21465
- const { role } = await this.me();
21466
- const response = await this.fetchData(`users-permissions/role/${role?.documentId}`);
21465
+ const user = await this.baseMe({ populate: { role: { fields: ["id"] } } });
21466
+ if (user.error) {
21467
+ return false;
21468
+ }
21469
+ const response = await this.fetchData(`users-permissions/roles/${user.role.id}`);
21467
21470
  this.permissionsList = response.role.permissions;
21468
21471
  }
21469
21472
  if (!this.permissionsList[uid]) {
@@ -21939,7 +21942,7 @@ function generateInputTypeCode(name, attributes) {
21939
21942
  lines.push(`}`);
21940
21943
  return lines.join('\n');
21941
21944
  }
21942
- function generateMethodsCode(contentType) {
21945
+ function generateMethodsCode(contentType, permissions) {
21943
21946
  const methods = [];
21944
21947
  const modelName = getContentTypeName(contentType.uid);
21945
21948
  if (contentType.schema.kind === ContentTypeKind.CollectionType) {
@@ -21969,10 +21972,10 @@ function generateMethodsCode(contentType) {
21969
21972
  ` return await this.delete<${modelName}>('${contentType.schema.pluralName}', id, params);`,
21970
21973
  ' }',
21971
21974
  ].join('\n'));
21972
- console.log(contentType.uid);
21973
21975
  if (contentType.uid.startsWith('api::')) {
21976
+ const actions = Object.keys(permissions[contentType.uid.split('.')[0]].controllers[contentType.schema.singularName]);
21974
21977
  methods.push([
21975
- ` public async can${getContentTypeName(contentType.schema.singularName)}(action: PermissionAction) {`,
21978
+ ` public async can${getContentTypeName(contentType.schema.singularName)}(action: '${actions.join('\' | \'')}') {`,
21976
21979
  ` return await this.can('${contentType.uid.split('.')[0]}', '${contentType.schema.singularName}', action);`,
21977
21980
  ' }',
21978
21981
  ].join('\n'));
@@ -21985,6 +21988,7 @@ function generateMethodsCode(contentType) {
21985
21988
  async function generateStrapiTypes(strapi) {
21986
21989
  const contentTypes = (await strapi.fetch('content-type-builder/content-types')).data || [];
21987
21990
  const components = (await strapi.fetch('content-type-builder/components')).data || [];
21991
+ const permissions = (await strapi.fetchData('users-permissions/permissions')).permissions || {};
21988
21992
  const allInterfaces = [];
21989
21993
  const methods = [];
21990
21994
  for (const component of components) {
@@ -22003,7 +22007,7 @@ async function generateStrapiTypes(strapi) {
22003
22007
  if (!['api::', 'plugin::upload', 'plugin::users-permissions'].filter(prefix => contentType.uid.startsWith(prefix)).length) {
22004
22008
  continue;
22005
22009
  }
22006
- methods.push(...generateMethodsCode(contentType));
22010
+ methods.push(...generateMethodsCode(contentType, permissions));
22007
22011
  const modelName = getContentTypeName(contentType.uid);
22008
22012
  const attributes = {
22009
22013
  id: {