@malevich-studio/strapi-sdk-typescript 1.2.16 → 1.2.17

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
@@ -21460,17 +21460,22 @@ class Strapi {
21460
21460
  log(data);
21461
21461
  return data;
21462
21462
  }
21463
- }
21464
-
21465
- /**
21466
- * Returns the TypeScript interface name from a component UID
21467
- * e.g. "default.test-component" => "DefaultTestComponent"
21468
- */
21469
- function getComponentName(uid) {
21470
- return uid
21471
- .split(/[\.\-]/)
21472
- .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
21473
- .join('');
21463
+ async can(uid, controller, action) {
21464
+ if (!this.permissions) {
21465
+ const response = await this.fetchData('users-permissions/permissions');
21466
+ this.permissions = response.permissions;
21467
+ }
21468
+ if (!this.permissions[uid]) {
21469
+ throw new Error(`Permissions for ${uid} not found!`);
21470
+ }
21471
+ if (!this.permissions[uid].controllers[controller]) {
21472
+ throw new Error(`Permissions for ${uid}.${controller} not found!`);
21473
+ }
21474
+ if (!this.permissions[uid].controllers[controller][action]) {
21475
+ throw new Error(`Permission for ${uid}.${controller}.${action} not found!`);
21476
+ }
21477
+ return this.permissions[uid].controllers[controller][action].enabled;
21478
+ }
21474
21479
  }
21475
21480
 
21476
21481
  var AttributeMode;
@@ -21543,32 +21548,6 @@ class BaseRelation extends Base {
21543
21548
  }
21544
21549
  }
21545
21550
 
21546
- class Media extends BaseRelation {
21547
- constructor(name, attribute) {
21548
- super(name, attribute);
21549
- this.name = name;
21550
- this.attribute = attribute;
21551
- }
21552
- getType() {
21553
- return this.attribute.multiple ? 'File[]' : 'File';
21554
- }
21555
- getInputType() {
21556
- return 'number[]';
21557
- }
21558
- getPopulates() {
21559
- return [{
21560
- name: this.name,
21561
- type: 'FileQuery',
21562
- }];
21563
- }
21564
- getFilters() {
21565
- return [{
21566
- name: this.name,
21567
- type: 'FileFilters',
21568
- }];
21569
- }
21570
- }
21571
-
21572
21551
  /**
21573
21552
  * Returns the TypeScript interface name from a content type UID
21574
21553
  * e.g. "api::article.article" => "Article"
@@ -21643,6 +21622,43 @@ class Relation extends BaseRelation {
21643
21622
  }
21644
21623
  }
21645
21624
 
21625
+ /**
21626
+ * Returns the TypeScript interface name from a component UID
21627
+ * e.g. "default.test-component" => "DefaultTestComponent"
21628
+ */
21629
+ function getComponentName(uid) {
21630
+ return uid
21631
+ .split(/[\.\-]/)
21632
+ .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
21633
+ .join('');
21634
+ }
21635
+
21636
+ class Media extends BaseRelation {
21637
+ constructor(name, attribute) {
21638
+ super(name, attribute);
21639
+ this.name = name;
21640
+ this.attribute = attribute;
21641
+ }
21642
+ getType() {
21643
+ return this.attribute.multiple ? 'File[]' : 'File';
21644
+ }
21645
+ getInputType() {
21646
+ return 'number[]';
21647
+ }
21648
+ getPopulates() {
21649
+ return [{
21650
+ name: this.name,
21651
+ type: 'FileQuery',
21652
+ }];
21653
+ }
21654
+ getFilters() {
21655
+ return [{
21656
+ name: this.name,
21657
+ type: 'FileFilters',
21658
+ }];
21659
+ }
21660
+ }
21661
+
21646
21662
  class Enumeration extends Base {
21647
21663
  constructor(name, attribute) {
21648
21664
  super(name, attribute);
@@ -21952,6 +21968,14 @@ function generateMethodsCode(contentType) {
21952
21968
  ` return await this.delete<${modelName}>('${contentType.schema.pluralName}', id, params);`,
21953
21969
  ' }',
21954
21970
  ].join('\n'));
21971
+ console.log(contentType.uid);
21972
+ if (contentType.uid.startsWith('api::')) {
21973
+ methods.push([
21974
+ ` public async can${getContentTypeName(contentType.schema.singularName)}(action: PermissionAction) {`,
21975
+ ` return await this.can('${contentType.uid}', '${contentType.schema.singularName.replace(/^api::/, '')}', action);`,
21976
+ ' }',
21977
+ ].join('\n'));
21978
+ }
21955
21979
  return methods;
21956
21980
  }
21957
21981
  /**
@@ -22005,7 +22029,7 @@ async function generateStrapiTypes(strapi) {
22005
22029
  localizations: {
22006
22030
  type: 'relation',
22007
22031
  target: contentType.uid,
22008
- relation: 'oneToMany',
22032
+ relation: AttributeRelation.OneToMany,
22009
22033
  required: true,
22010
22034
  },
22011
22035
  } : {}),
@@ -22016,7 +22040,7 @@ async function generateStrapiTypes(strapi) {
22016
22040
  allInterfaces.push(generateInputTypeCode(modelName, attributes));
22017
22041
  }
22018
22042
  const output = [
22019
- 'import {Strapi as StrapiBase, Query, Filters, FilterValue, RelationInput, DynamiczonePopulate, DynamiczoneComponent} from "@malevich-studio/strapi-sdk-typescript";',
22043
+ 'import {Strapi as StrapiBase, Query, Filters, FilterValue, RelationInput, DynamiczonePopulate, DynamiczoneComponent, PermissionAction} from "@malevich-studio/strapi-sdk-typescript";',
22020
22044
  'import {BlocksContent} from "@strapi/blocks-react-renderer";',
22021
22045
  '',
22022
22046
  'export default class Strapi extends StrapiBase {',