@malevich-studio/strapi-sdk-typescript 1.2.20 → 1.2.22
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 +22 -8
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.mjs +22 -8
- package/dist/cli.mjs.map +1 -1
- package/dist/index.cjs +16 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +17 -11
- package/dist/index.mjs +16 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -21413,6 +21413,12 @@ class Strapi {
|
|
|
21413
21413
|
...params,
|
|
21414
21414
|
});
|
|
21415
21415
|
}
|
|
21416
|
+
async updateUser(endpoint, id, data, params = {}) {
|
|
21417
|
+
return await this.fetchData(`${endpoint}/${id}`, data, {
|
|
21418
|
+
method: 'PUT',
|
|
21419
|
+
...params,
|
|
21420
|
+
});
|
|
21421
|
+
}
|
|
21416
21422
|
async delete(endpoint, id, params = {}) {
|
|
21417
21423
|
return await this.fetch(`${endpoint}/${id}`, {}, {
|
|
21418
21424
|
method: 'DELETE',
|
|
@@ -21434,7 +21440,11 @@ class Strapi {
|
|
|
21434
21440
|
} : {}),
|
|
21435
21441
|
}, params);
|
|
21436
21442
|
const response = await fetch(`${this.url}/api/${endpoint}`, mergedParams);
|
|
21437
|
-
|
|
21443
|
+
let data = null;
|
|
21444
|
+
try {
|
|
21445
|
+
data = await response?.json() || null;
|
|
21446
|
+
}
|
|
21447
|
+
catch (error) { }
|
|
21438
21448
|
log(mergedParams);
|
|
21439
21449
|
log(response);
|
|
21440
21450
|
log(data);
|
|
@@ -21442,8 +21452,11 @@ class Strapi {
|
|
|
21442
21452
|
}
|
|
21443
21453
|
async can(uid, controller, action) {
|
|
21444
21454
|
if (!this.permissionsList) {
|
|
21445
|
-
const
|
|
21446
|
-
|
|
21455
|
+
const user = await this.baseMe({ populate: { role: { fields: ["id"] } } });
|
|
21456
|
+
if (user.error) {
|
|
21457
|
+
return false;
|
|
21458
|
+
}
|
|
21459
|
+
const response = await this.fetchData(`users-permissions/roles/${user.role.id}`);
|
|
21447
21460
|
this.permissionsList = response.role.permissions;
|
|
21448
21461
|
}
|
|
21449
21462
|
if (!this.permissionsList[uid]) {
|
|
@@ -21919,7 +21932,7 @@ function generateInputTypeCode(name, attributes) {
|
|
|
21919
21932
|
lines.push(`}`);
|
|
21920
21933
|
return lines.join('\n');
|
|
21921
21934
|
}
|
|
21922
|
-
function generateMethodsCode(contentType) {
|
|
21935
|
+
function generateMethodsCode(contentType, permissions) {
|
|
21923
21936
|
const methods = [];
|
|
21924
21937
|
const modelName = getContentTypeName(contentType.uid);
|
|
21925
21938
|
if (contentType.schema.kind === ContentTypeKind.CollectionType) {
|
|
@@ -21941,7 +21954,7 @@ function generateMethodsCode(contentType) {
|
|
|
21941
21954
|
].join('\n'));
|
|
21942
21955
|
methods.push([
|
|
21943
21956
|
` public async update${getContentTypeName(contentType.schema.singularName)}(id: string, data: ${modelName}Input, params?: RequestInit) {`,
|
|
21944
|
-
` return await this.update<${modelName}, ${modelName}Input>('${contentType.schema.pluralName}', id, data, params);`,
|
|
21957
|
+
` return await this.update${modelName === 'User' ? 'User' : ''}<${modelName}, ${modelName}Input>('${contentType.schema.pluralName}', id, data, params);`,
|
|
21945
21958
|
' }',
|
|
21946
21959
|
].join('\n'));
|
|
21947
21960
|
methods.push([
|
|
@@ -21949,10 +21962,10 @@ function generateMethodsCode(contentType) {
|
|
|
21949
21962
|
` return await this.delete<${modelName}>('${contentType.schema.pluralName}', id, params);`,
|
|
21950
21963
|
' }',
|
|
21951
21964
|
].join('\n'));
|
|
21952
|
-
console.log(contentType.uid);
|
|
21953
21965
|
if (contentType.uid.startsWith('api::')) {
|
|
21966
|
+
const actions = Object.keys(permissions[contentType.uid.split('.')[0]].controllers[contentType.schema.singularName]);
|
|
21954
21967
|
methods.push([
|
|
21955
|
-
` public async can${getContentTypeName(contentType.schema.singularName)}(action:
|
|
21968
|
+
` public async can${getContentTypeName(contentType.schema.singularName)}(action: '${actions.join('\' | \'')}') {`,
|
|
21956
21969
|
` return await this.can('${contentType.uid.split('.')[0]}', '${contentType.schema.singularName}', action);`,
|
|
21957
21970
|
' }',
|
|
21958
21971
|
].join('\n'));
|
|
@@ -21965,6 +21978,7 @@ function generateMethodsCode(contentType) {
|
|
|
21965
21978
|
async function generateStrapiTypes(strapi) {
|
|
21966
21979
|
const contentTypes = (await strapi.fetch('content-type-builder/content-types')).data || [];
|
|
21967
21980
|
const components = (await strapi.fetch('content-type-builder/components')).data || [];
|
|
21981
|
+
const permissions = (await strapi.fetchData('users-permissions/permissions')).permissions || {};
|
|
21968
21982
|
const allInterfaces = [];
|
|
21969
21983
|
const methods = [];
|
|
21970
21984
|
for (const component of components) {
|
|
@@ -21983,7 +21997,7 @@ async function generateStrapiTypes(strapi) {
|
|
|
21983
21997
|
if (!['api::', 'plugin::upload', 'plugin::users-permissions'].filter(prefix => contentType.uid.startsWith(prefix)).length) {
|
|
21984
21998
|
continue;
|
|
21985
21999
|
}
|
|
21986
|
-
methods.push(...generateMethodsCode(contentType));
|
|
22000
|
+
methods.push(...generateMethodsCode(contentType, permissions));
|
|
21987
22001
|
const modelName = getContentTypeName(contentType.uid);
|
|
21988
22002
|
const attributes = {
|
|
21989
22003
|
id: {
|