@inweb/client 25.6.2 → 25.6.4

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.
@@ -127,8 +127,8 @@ export declare class Client extends EventEmitter2<ClientEventMap> {
127
127
  /**
128
128
  * Change server settings.
129
129
  *
130
- * Only admins can change server settings, if the current logged in user does not have
131
- * administrator rights, an exception will be thrown.
130
+ * Only administrators can change server settings, if the current logged in user is not an
131
+ * administrator, an exception will be thrown.
132
132
  *
133
133
  * @async
134
134
  */
@@ -136,8 +136,8 @@ export declare class Client extends EventEmitter2<ClientEventMap> {
136
136
  /**
137
137
  * Returns a list of server users.
138
138
  *
139
- * Only admins can get a list of users, if the current logged in user does not have
140
- * administrator rights, an exception will be thrown.
139
+ * Only administrators can get a list of users, if the current logged in user is not an
140
+ * administrator, an exception will be thrown.
141
141
  *
142
142
  * @async
143
143
  */
@@ -145,8 +145,8 @@ export declare class Client extends EventEmitter2<ClientEventMap> {
145
145
  /**
146
146
  * Returns the user information.
147
147
  *
148
- * Only admins can get other users, if the current logged in user does not have administrator
149
- * rights, hi can only get himself, otherwise an exception will be thrown.
148
+ * Only administrators can get other users, if the currently logged in user is not an
149
+ * administrator, they can only get themselves, otherwise an exception will be thrown.
150
150
  *
151
151
  * @async
152
152
  * @param userId - User ID.
@@ -155,8 +155,8 @@ export declare class Client extends EventEmitter2<ClientEventMap> {
155
155
  /**
156
156
  * Create a new user.
157
157
  *
158
- * Only admins can create users, if the current logged in user does not have administrator
159
- * rights, an exception will be thrown.
158
+ * Only administrators can create users, if the current logged in user is not an
159
+ * administrator, an exception will be thrown.
160
160
  *
161
161
  * @async
162
162
  * @param email - User email. Cannot be empty.
@@ -184,11 +184,11 @@ export declare class Client extends EventEmitter2<ClientEventMap> {
184
184
  /**
185
185
  * Delete a user from the server.
186
186
  *
187
- * Only admins can delete users, if the current logged in user does not have administrator
188
- * rights, an exception will be thrown.
187
+ * Only administrators can delete users, if the current logged in user is not an
188
+ * administrator, an exception will be thrown.
189
189
  *
190
- * Admins can delete themselves or other admins. An admin can only delete himself if he is
191
- * not the last administrator.
190
+ * Administrators can delete themselves or other administrators. An administrator can only
191
+ * delete themself if they is not the last administrator.
192
192
  *
193
193
  * You need to re-login to continue working after deleting the current logged in user.
194
194
  *
package/lib/Api/File.d.ts CHANGED
@@ -99,7 +99,8 @@ export declare class File {
99
99
  */
100
100
  get owner(): IShortUserDescription;
101
101
  /**
102
- * File preview image URL. Use {@link File.setPreview | setPreview()} to change preview image.
102
+ * File preview image URL or empty string if the file does not have a preview. Use
103
+ * {@link File.setPreview | setPreview()} to change preview image.
103
104
  *
104
105
  * @readonly
105
106
  */
package/lib/Api/Job.d.ts CHANGED
@@ -106,8 +106,8 @@ export declare class Job {
106
106
  /**
107
107
  * Update job data on the server.
108
108
  *
109
- * Only admins can update job data, if the current logged in user does not have administrator
110
- * rights, an exception will be thrown.
109
+ * Only administrators can update job data, if the current logged in user is not an
110
+ * administrator, an exception will be thrown.
111
111
  *
112
112
  * @async
113
113
  * @param data - Raw job data.
@@ -93,7 +93,8 @@ export declare class Project {
93
93
  */
94
94
  get owner(): IShortUserDescription;
95
95
  /**
96
- * Project preview image URL. Use {@link Project.setPreview | setPreview()} to change preview image.
96
+ * Project preview image URL or empty string if the project does not have a preview. Use
97
+ * {@link Project.setPreview | setPreview()} to change preview image.
97
98
  *
98
99
  * @readonly
99
100
  */
package/lib/Api/User.d.ts CHANGED
@@ -11,7 +11,8 @@ export declare class User {
11
11
  */
12
12
  constructor(data: any, httpClient: IHttpClient);
13
13
  /**
14
- * User avatar image URL. Use {@link User.setAvatar | setAvatar()} to change avatar image.
14
+ * User avatar image URL or empty string if the user does not have an avatar. Use
15
+ * {@link User.setAvatar | setAvatar()} to change avatar image.
15
16
  *
16
17
  * @readonly
17
18
  */
@@ -75,7 +76,7 @@ export declare class User {
75
76
  */
76
77
  get initials(): string;
77
78
  /**
78
- * `true` if user is has an administrator rights.
79
+ * `true` if user is an administrator.
79
80
  */
80
81
  get isAdmin(): boolean;
81
82
  /**
@@ -123,15 +124,15 @@ export declare class User {
123
124
  /**
124
125
  * Refresh user data.
125
126
  *
126
- * Only admins can checkout other users, if the current logged in user does not have
127
- * administrator rights, hi can only checkout himself, otherwise an exception will be thrown.
127
+ * Only administrators can checkout other users, if the current logged in user is not an
128
+ * administrator, they can only checkout themselves, otherwise an exception will be thrown.
128
129
  */
129
130
  checkout(): Promise<this>;
130
131
  /**
131
132
  * Update user data on the server.
132
133
  *
133
- * Only admins can update other users, if the current logged in user does not have
134
- * administrator rights, hi can only update himself, otherwise an exception will be thrown.
134
+ * Only administrators can update other users, if the current logged in user is not an
135
+ * administrator, they can only update themself, otherwise an exception will be thrown.
135
136
  *
136
137
  * @async
137
138
  * @param data - Raw user data.
@@ -140,11 +141,11 @@ export declare class User {
140
141
  /**
141
142
  * Delete a user from the server.
142
143
  *
143
- * Only admins can delete users, if the current logged in user does not have administrator
144
- * rights, an exception will be thrown.
144
+ * Only administrators can delete users, if the current logged in user is not an
145
+ * administrator, an exception will be thrown.
145
146
  *
146
- * Admins can delete themselves or other admins. An admin can only delete himself if he is
147
- * not the last administrator.
147
+ * Administrators can delete themselves or other administrators. An administrator can only
148
+ * delete themself if they is not the last administrator.
148
149
  *
149
150
  * You need to re-login to continue working after deleting the current logged in user.
150
151
  *
@@ -162,8 +163,8 @@ export declare class User {
162
163
  /**
163
164
  * Set or remove the user avatar.
164
165
  *
165
- * Only admins can set the avatar of other users, if the current logged in user does not have
166
- * administrator rights, he can only set his own avatar, otherwise an exception will be thrown.
166
+ * Only administrators can set the avatar of other users, if the current logged in user is
167
+ * not an administrator, they can only set their avatar, otherwise an exception will be thrown.
167
168
  *
168
169
  * @async
169
170
  * @param image - Avatar image. Can be a
@@ -178,11 +179,25 @@ export declare class User {
178
179
  /**
179
180
  * Remove the user avatar.
180
181
  *
181
- * Only admins can remove the avatar of other users, if the current logged in user does not
182
- * have administrator rights, they can only remove their own avatar, otherwise an exception
183
- * will be thrown.
182
+ * Only administrators can remove the avatar of other users, if the current logged in user is
183
+ * not an administrator, they can only remove their avatar, otherwise an exception will be thrown.
184
184
  *
185
185
  * @async
186
186
  */
187
187
  deleteAvatar(): Promise<this>;
188
+ /**
189
+ * Change the user password.
190
+ *
191
+ * Only administrators can change the passwords of other users, if the current logged in user
192
+ * is not an administrator, they can only change their password, otherwise an exception will
193
+ * be thrown.
194
+ *
195
+ * To change their password, non-administrator users must provide their old password.
196
+ *
197
+ * @async
198
+ * @param newPassword - New user password.
199
+ * @param oldPassword - Old user password. Only required for non-administrator users to
200
+ * change their password.
201
+ */
202
+ changePassword(newPassword: string, oldPassword?: string): Promise<this>;
188
203
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inweb/client",
3
- "version": "25.6.2",
3
+ "version": "25.6.4",
4
4
  "description": "JavaScript REST API client for the Open Cloud Server",
5
5
  "homepage": "https://cloud.opendesign.com/docs/index.html",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -26,6 +26,6 @@
26
26
  "ts-docs": "typedoc"
27
27
  },
28
28
  "dependencies": {
29
- "@inweb/eventemitter2": "~25.6.2"
29
+ "@inweb/eventemitter2": "~25.6.4"
30
30
  }
31
31
  }
package/src/Api/Client.ts CHANGED
@@ -271,8 +271,8 @@ export class Client extends EventEmitter2<ClientEventMap> {
271
271
  /**
272
272
  * Change server settings.
273
273
  *
274
- * Only admins can change server settings, if the current logged in user does not have
275
- * administrator rights, an exception will be thrown.
274
+ * Only administrators can change server settings, if the current logged in user is not an
275
+ * administrator, an exception will be thrown.
276
276
  *
277
277
  * @async
278
278
  */
@@ -283,8 +283,8 @@ export class Client extends EventEmitter2<ClientEventMap> {
283
283
  /**
284
284
  * Returns a list of server users.
285
285
  *
286
- * Only admins can get a list of users, if the current logged in user does not have
287
- * administrator rights, an exception will be thrown.
286
+ * Only administrators can get a list of users, if the current logged in user is not an
287
+ * administrator, an exception will be thrown.
288
288
  *
289
289
  * @async
290
290
  */
@@ -299,8 +299,8 @@ export class Client extends EventEmitter2<ClientEventMap> {
299
299
  /**
300
300
  * Returns the user information.
301
301
  *
302
- * Only admins can get other users, if the current logged in user does not have administrator
303
- * rights, hi can only get himself, otherwise an exception will be thrown.
302
+ * Only administrators can get other users, if the currently logged in user is not an
303
+ * administrator, they can only get themselves, otherwise an exception will be thrown.
304
304
  *
305
305
  * @async
306
306
  * @param userId - User ID.
@@ -326,8 +326,8 @@ export class Client extends EventEmitter2<ClientEventMap> {
326
326
  /**
327
327
  * Create a new user.
328
328
  *
329
- * Only admins can create users, if the current logged in user does not have administrator
330
- * rights, an exception will be thrown.
329
+ * Only administrators can create users, if the current logged in user is not an
330
+ * administrator, an exception will be thrown.
331
331
  *
332
332
  * @async
333
333
  * @param email - User email. Cannot be empty.
@@ -375,11 +375,11 @@ export class Client extends EventEmitter2<ClientEventMap> {
375
375
  /**
376
376
  * Delete a user from the server.
377
377
  *
378
- * Only admins can delete users, if the current logged in user does not have administrator
379
- * rights, an exception will be thrown.
378
+ * Only administrators can delete users, if the current logged in user is not an
379
+ * administrator, an exception will be thrown.
380
380
  *
381
- * Admins can delete themselves or other admins. An admin can only delete himself if he is
382
- * not the last administrator.
381
+ * Administrators can delete themselves or other administrators. An administrator can only
382
+ * delete themself if they is not the last administrator.
383
383
  *
384
384
  * You need to re-login to continue working after deleting the current logged in user.
385
385
  *
package/src/Api/File.ts CHANGED
@@ -117,7 +117,9 @@ export class File {
117
117
 
118
118
  private set data(value: any) {
119
119
  this._data = value;
120
- this._data.previewUrl = value.preview ? `${this.httpClient.serverUrl}${this.path}/preview` : "";
120
+ this._data.previewUrl = value.preview
121
+ ? `${this.httpClient.serverUrl}${this.path}/preview?updated=${value.updatedAt}`
122
+ : "";
121
123
  // owner since 24.8
122
124
  if (typeof this._data.owner === "string") this._data.owner = { userId: this._data.owner };
123
125
  this._data.owner ??= {};
@@ -213,7 +215,8 @@ export class File {
213
215
  }
214
216
 
215
217
  /**
216
- * File preview image URL. Use {@link File.setPreview | setPreview()} to change preview image.
218
+ * File preview image URL or empty string if the file does not have a preview. Use
219
+ * {@link File.setPreview | setPreview()} to change preview image.
217
220
  *
218
221
  * @readonly
219
222
  */
package/src/Api/Job.ts CHANGED
@@ -192,8 +192,8 @@ export class Job {
192
192
  /**
193
193
  * Update job data on the server.
194
194
  *
195
- * Only admins can update job data, if the current logged in user does not have administrator
196
- * rights, an exception will be thrown.
195
+ * Only administrators can update job data, if the current logged in user is not an
196
+ * administrator, an exception will be thrown.
197
197
  *
198
198
  * @async
199
199
  * @param data - Raw job data.
@@ -102,7 +102,9 @@ export class Project {
102
102
 
103
103
  private set data(value: any) {
104
104
  this._data = value;
105
- this._data.previewUrl = value.avatarUrl ? `${this.httpClient.serverUrl}/projects/${this._data.id}/preview` : "";
105
+ this._data.previewUrl = value.avatarUrl
106
+ ? `${this.httpClient.serverUrl}/projects/${this._data.id}/preview?updated=${value.updatedAt}`
107
+ : "";
106
108
  this._data.owner.avatarUrl = `${this.httpClient.serverUrl}/users/${this._data.owner.userId}/avatar`;
107
109
  this._data.owner.fullName = userFullName(this._data.owner);
108
110
  this._data.owner.initials = userInitials(this._data.owner.fullName);
@@ -187,7 +189,8 @@ export class Project {
187
189
  }
188
190
 
189
191
  /**
190
- * Project preview image URL. Use {@link Project.setPreview | setPreview()} to change preview image.
192
+ * Project preview image URL or empty string if the project does not have a preview. Use
193
+ * {@link Project.setPreview | setPreview()} to change preview image.
191
194
  *
192
195
  * @readonly
193
196
  */
package/src/Api/User.ts CHANGED
@@ -42,7 +42,8 @@ export class User {
42
42
  }
43
43
 
44
44
  /**
45
- * User avatar image URL. Use {@link User.setAvatar | setAvatar()} to change avatar image.
45
+ * User avatar image URL or empty string if the user does not have an avatar. Use
46
+ * {@link User.setAvatar | setAvatar()} to change avatar image.
46
47
  *
47
48
  * @readonly
48
49
  */
@@ -92,7 +93,9 @@ export class User {
92
93
 
93
94
  private set data(value: any) {
94
95
  this._data = value;
95
- this._data.avatarUrl = value.avatarImage ? `${this.httpClient.serverUrl}/users/${this._data.id}/avatar` : "";
96
+ this._data.avatarUrl = value.avatarImage
97
+ ? `${this.httpClient.serverUrl}/users/${this._data.id}/avatar?updated=${value.lastModified}`
98
+ : "";
96
99
  this._data.fullName = userFullName(this._data);
97
100
  this._data.initials = userInitials(this._data.fullName);
98
101
  }
@@ -152,7 +155,7 @@ export class User {
152
155
  }
153
156
 
154
157
  /**
155
- * `true` if user is has an administrator rights.
158
+ * `true` if user is an administrator.
156
159
  */
157
160
  get isAdmin(): boolean {
158
161
  return this.data.isAdmin;
@@ -233,8 +236,8 @@ export class User {
233
236
  /**
234
237
  * Refresh user data.
235
238
  *
236
- * Only admins can checkout other users, if the current logged in user does not have
237
- * administrator rights, hi can only checkout himself, otherwise an exception will be thrown.
239
+ * Only administrators can checkout other users, if the current logged in user is not an
240
+ * administrator, they can only checkout themselves, otherwise an exception will be thrown.
238
241
  */
239
242
  async checkout(): Promise<this> {
240
243
  if (this.httpClient.signInUserIsAdmin) {
@@ -254,8 +257,8 @@ export class User {
254
257
  /**
255
258
  * Update user data on the server.
256
259
  *
257
- * Only admins can update other users, if the current logged in user does not have
258
- * administrator rights, hi can only update himself, otherwise an exception will be thrown.
260
+ * Only administrators can update other users, if the current logged in user is not an
261
+ * administrator, they can only update themself, otherwise an exception will be thrown.
259
262
  *
260
263
  * @async
261
264
  * @param data - Raw user data.
@@ -278,11 +281,11 @@ export class User {
278
281
  /**
279
282
  * Delete a user from the server.
280
283
  *
281
- * Only admins can delete users, if the current logged in user does not have administrator
282
- * rights, an exception will be thrown.
284
+ * Only administrators can delete users, if the current logged in user is not an
285
+ * administrator, an exception will be thrown.
283
286
  *
284
- * Admins can delete themselves or other admins. An admin can only delete himself if he is
285
- * not the last administrator.
287
+ * Administrators can delete themselves or other administrators. An administrator can only
288
+ * delete themself if they is not the last administrator.
286
289
  *
287
290
  * You need to re-login to continue working after deleting the current logged in user.
288
291
  *
@@ -320,8 +323,8 @@ export class User {
320
323
  /**
321
324
  * Set or remove the user avatar.
322
325
  *
323
- * Only admins can set the avatar of other users, if the current logged in user does not have
324
- * administrator rights, he can only set his own avatar, otherwise an exception will be thrown.
326
+ * Only administrators can set the avatar of other users, if the current logged in user is
327
+ * not an administrator, they can only set their avatar, otherwise an exception will be thrown.
325
328
  *
326
329
  * @async
327
330
  * @param image - Avatar image. Can be a
@@ -352,9 +355,8 @@ export class User {
352
355
  /**
353
356
  * Remove the user avatar.
354
357
  *
355
- * Only admins can remove the avatar of other users, if the current logged in user does not
356
- * have administrator rights, they can only remove their own avatar, otherwise an exception
357
- * will be thrown.
358
+ * Only administrators can remove the avatar of other users, if the current logged in user is
359
+ * not an administrator, they can only remove their avatar, otherwise an exception will be thrown.
358
360
  *
359
361
  * @async
360
362
  */
@@ -372,4 +374,33 @@ export class User {
372
374
  }
373
375
  return this;
374
376
  }
377
+
378
+ /**
379
+ * Change the user password.
380
+ *
381
+ * Only administrators can change the passwords of other users, if the current logged in user
382
+ * is not an administrator, they can only change their password, otherwise an exception will
383
+ * be thrown.
384
+ *
385
+ * To change their password, non-administrator users must provide their old password.
386
+ *
387
+ * @async
388
+ * @param newPassword - New user password.
389
+ * @param oldPassword - Old user password. Only required for non-administrator users to
390
+ * change their password.
391
+ */
392
+ async changePassword(newPassword: string, oldPassword?: string): Promise<this> {
393
+ if (this.httpClient.signInUserIsAdmin) {
394
+ const response = await this.httpClient.put(`/users/${this.id}/password`, { new: newPassword });
395
+ const data = await response.json();
396
+ this.data = { id: data.id, ...data.userBrief };
397
+ } else if (this.id === this.httpClient.signInUserId) {
398
+ const response = await this.httpClient.put("/user/password", { old: oldPassword, new: newPassword });
399
+ const data = await response.json();
400
+ this.data = { id: this.id, ...data };
401
+ } else {
402
+ return Promise.reject(new FetchError(403));
403
+ }
404
+ return this;
405
+ }
375
406
  }