@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/index.d.ts
CHANGED
|
@@ -13,6 +13,18 @@ type RelationInput = {
|
|
|
13
13
|
set?: RelationData[];
|
|
14
14
|
} | RelationData[];
|
|
15
15
|
|
|
16
|
+
type Permissions = {
|
|
17
|
+
[key: string]: {
|
|
18
|
+
controllers: {
|
|
19
|
+
[key: string]: {
|
|
20
|
+
[key: string]: {
|
|
21
|
+
enabled: boolean;
|
|
22
|
+
policy: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
};
|
|
16
28
|
type PermissionAction = 'find' | 'findOne' | 'create' | 'update' | 'delete';
|
|
17
29
|
type SuccessResponse<T> = {
|
|
18
30
|
data: T;
|
|
@@ -148,12 +160,12 @@ type DynamiczonePopulate<T> = {
|
|
|
148
160
|
[K in keyof T]: T[K];
|
|
149
161
|
};
|
|
150
162
|
};
|
|
151
|
-
declare
|
|
163
|
+
declare class Strapi {
|
|
152
164
|
private readonly url;
|
|
153
165
|
private token?;
|
|
154
166
|
constructor(url: string, token?: string | undefined);
|
|
155
167
|
fetch<T>(endpoint: string, data?: object | FormData, params?: RequestInit): Promise<Response<T>>;
|
|
156
|
-
|
|
168
|
+
fetchData<T>(endpoint: string, data?: object | FormData, params?: RequestInit): Promise<T>;
|
|
157
169
|
setToken(token: string): void;
|
|
158
170
|
getToken(): string | undefined;
|
|
159
171
|
protected baseLogin<T>(identifier: string, password: string): Promise<AuthResponse<T>>;
|
|
@@ -175,18 +187,12 @@ declare abstract class Strapi {
|
|
|
175
187
|
getDocument<T, Q extends object>(endpoint: string, data?: Q, params?: RequestInit): Promise<Response<T>>;
|
|
176
188
|
create<T, Q extends object>(endpoint: string, data: Q, params?: RequestInit): Promise<Response<T>>;
|
|
177
189
|
update<T, Q extends object>(endpoint: string, id: string, data: Q, params?: RequestInit): Promise<Response<T>>;
|
|
190
|
+
updateUser<T, Q extends object>(endpoint: string, id: string, data: Q, params?: RequestInit): Promise<T>;
|
|
178
191
|
delete<T>(endpoint: string, id: string, params?: RequestInit): Promise<Response<T>>;
|
|
179
192
|
uploadForm(form: FormData): Promise<File[]>;
|
|
180
193
|
private baseFetch;
|
|
181
194
|
private permissionsList?;
|
|
182
|
-
|
|
183
|
-
role: Query<'id' | 'documentId', 'id' | 'documentId', {}, {}>;
|
|
184
|
-
}>): Promise<{
|
|
185
|
-
role?: {
|
|
186
|
-
id?: number;
|
|
187
|
-
};
|
|
188
|
-
}>;
|
|
189
|
-
can(uid: string, controller: string, action: PermissionAction): Promise<boolean>;
|
|
195
|
+
can(uid: string, controller: string, action: string): Promise<boolean>;
|
|
190
196
|
}
|
|
191
197
|
|
|
192
|
-
export { type AuthResponse, type DynamiczoneComponent, type DynamiczonePopulate, type ErrorResponse, type File, type FilterValue, type Filters, type Folder, type Locale, type PermissionAction, type Query, type RelationInput, type Response, Strapi, type SuccessResponse, type UserResponse };
|
|
198
|
+
export { type AuthResponse, type DynamiczoneComponent, type DynamiczonePopulate, type ErrorResponse, type File, type FilterValue, type Filters, type Folder, type Locale, type PermissionAction, type Permissions, type Query, type RelationInput, type Response, Strapi, type SuccessResponse, type UserResponse };
|
package/dist/index.mjs
CHANGED
|
@@ -21407,6 +21407,12 @@ class Strapi {
|
|
|
21407
21407
|
...params,
|
|
21408
21408
|
});
|
|
21409
21409
|
}
|
|
21410
|
+
async updateUser(endpoint, id, data, params = {}) {
|
|
21411
|
+
return await this.fetchData(`${endpoint}/${id}`, data, {
|
|
21412
|
+
method: 'PUT',
|
|
21413
|
+
...params,
|
|
21414
|
+
});
|
|
21415
|
+
}
|
|
21410
21416
|
async delete(endpoint, id, params = {}) {
|
|
21411
21417
|
return await this.fetch(`${endpoint}/${id}`, {}, {
|
|
21412
21418
|
method: 'DELETE',
|
|
@@ -21428,7 +21434,11 @@ class Strapi {
|
|
|
21428
21434
|
} : {}),
|
|
21429
21435
|
}, params);
|
|
21430
21436
|
const response = await fetch(`${this.url}/api/${endpoint}`, mergedParams);
|
|
21431
|
-
|
|
21437
|
+
let data = null;
|
|
21438
|
+
try {
|
|
21439
|
+
data = await response?.json() || null;
|
|
21440
|
+
}
|
|
21441
|
+
catch (error) { }
|
|
21432
21442
|
log(mergedParams);
|
|
21433
21443
|
log(response);
|
|
21434
21444
|
log(data);
|
|
@@ -21436,8 +21446,11 @@ class Strapi {
|
|
|
21436
21446
|
}
|
|
21437
21447
|
async can(uid, controller, action) {
|
|
21438
21448
|
if (!this.permissionsList) {
|
|
21439
|
-
const
|
|
21440
|
-
|
|
21449
|
+
const user = await this.baseMe({ populate: { role: { fields: ["id"] } } });
|
|
21450
|
+
if (user.error) {
|
|
21451
|
+
return false;
|
|
21452
|
+
}
|
|
21453
|
+
const response = await this.fetchData(`users-permissions/roles/${user.role.id}`);
|
|
21441
21454
|
this.permissionsList = response.role.permissions;
|
|
21442
21455
|
}
|
|
21443
21456
|
if (!this.permissionsList[uid]) {
|