@inweb/client 25.2.2 → 25.2.5

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.
Files changed (222) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +70 -70
  3. package/dist/client.js +12739 -12352
  4. package/dist/client.js.map +1 -1
  5. package/dist/client.min.js +1 -1
  6. package/dist/client.module.js +588 -157
  7. package/dist/client.module.js.map +1 -1
  8. package/lib/Api/Assembly.d.ts +338 -338
  9. package/lib/Api/ClashTest.d.ts +175 -175
  10. package/lib/Api/Client.d.ts +451 -451
  11. package/lib/Api/ClientEvents.d.ts +28 -28
  12. package/lib/Api/File.d.ts +567 -567
  13. package/lib/Api/HttpClient.d.ts +12 -12
  14. package/lib/Api/IAssembly.d.ts +13 -13
  15. package/lib/Api/IFile.d.ts +45 -45
  16. package/lib/Api/IHttpClient.d.ts +10 -10
  17. package/lib/Api/IUser.d.ts +10 -10
  18. package/lib/Api/Job.d.ts +141 -141
  19. package/lib/Api/Member.d.ts +84 -84
  20. package/lib/Api/Model.d.ts +146 -146
  21. package/lib/Api/Permission.d.ts +92 -92
  22. package/lib/Api/Project.d.ts +246 -246
  23. package/lib/Api/Role.d.ts +81 -81
  24. package/lib/Api/User.d.ts +196 -196
  25. package/lib/Api/impl/FetchError.d.ts +17 -17
  26. package/lib/Api/impl/Utils.d.ts +32 -32
  27. package/lib/Api/impl/http.d.ts +66 -66
  28. package/lib/ConvetMath.d.ts +28 -28
  29. package/lib/Viewer/CanvasEvents.d.ts +1 -1
  30. package/lib/Viewer/Commands/ApplyModelTransform.d.ts +1 -1
  31. package/lib/Viewer/Commands/ClearMarkup.d.ts +1 -1
  32. package/lib/Viewer/Commands/ClearSlices.d.ts +1 -1
  33. package/lib/Viewer/Commands/CreatePreview.d.ts +1 -1
  34. package/lib/Viewer/Commands/Explode.d.ts +1 -1
  35. package/lib/Viewer/Commands/GetDefaultViewPositions.d.ts +1 -1
  36. package/lib/Viewer/Commands/GetModels.d.ts +1 -1
  37. package/lib/Viewer/Commands/GetSelected.d.ts +1 -1
  38. package/lib/Viewer/Commands/HideSelected.d.ts +1 -1
  39. package/lib/Viewer/Commands/IsolateSelected.d.ts +1 -1
  40. package/lib/Viewer/Commands/RegenerateAll.d.ts +1 -1
  41. package/lib/Viewer/Commands/ResetView.d.ts +1 -1
  42. package/lib/Viewer/Commands/SelectModel.d.ts +1 -1
  43. package/lib/Viewer/Commands/SetActiveDragger.d.ts +1 -1
  44. package/lib/Viewer/Commands/SetDefaultViewPosition.d.ts +1 -1
  45. package/lib/Viewer/Commands/SetMarkupColor.d.ts +1 -1
  46. package/lib/Viewer/Commands/SetSelected.d.ts +1 -1
  47. package/lib/Viewer/Commands/ShowAll.d.ts +1 -1
  48. package/lib/Viewer/Commands/Unselect.d.ts +1 -1
  49. package/lib/Viewer/Commands/ZoomToExtents.d.ts +1 -1
  50. package/lib/Viewer/Commands/ZoomToObjects.d.ts +1 -1
  51. package/lib/Viewer/Commands/ZoomToSelected.d.ts +1 -1
  52. package/lib/Viewer/Commands.d.ts +2 -2
  53. package/lib/Viewer/Draggers/Actions/OrbitAction.d.ts +21 -21
  54. package/lib/Viewer/Draggers/Actions/PanAction.d.ts +17 -17
  55. package/lib/Viewer/Draggers/Actions/ZoomAction.d.ts +7 -7
  56. package/lib/Viewer/Draggers/Common/Geometry.d.ts +114 -114
  57. package/lib/Viewer/Draggers/Common/GestureManager.d.ts +40 -40
  58. package/lib/Viewer/Draggers/Common/OdBaseDragger.d.ts +53 -53
  59. package/lib/Viewer/Draggers/Common/OdaGeAction.d.ts +29 -29
  60. package/lib/Viewer/Draggers/MeasureLineDragger/MeasureLineItem.d.ts +30 -30
  61. package/lib/Viewer/Draggers/MeasureLineDragger/MeasureUtils.d.ts +19 -19
  62. package/lib/Viewer/Draggers/MeasureLineDragger/index.d.ts +23 -23
  63. package/lib/Viewer/Draggers/OdBaseCuttingPlaneDragger.d.ts +26 -26
  64. package/lib/Viewer/Draggers/OdCuttingPlaneXAxisDragger.d.ts +7 -7
  65. package/lib/Viewer/Draggers/OdCuttingPlaneYAxisDragger.d.ts +7 -7
  66. package/lib/Viewer/Draggers/OdCuttingPlaneZAxisDragger.d.ts +7 -7
  67. package/lib/Viewer/Draggers/OdOrbitDragger.d.ts +14 -14
  68. package/lib/Viewer/Draggers/OdPanDragger.d.ts +11 -11
  69. package/lib/Viewer/Draggers/OdZoomDragger.d.ts +11 -11
  70. package/lib/Viewer/Draggers/OdZoomWheelDragger.d.ts +10 -10
  71. package/lib/Viewer/Draggers/OdZoomWindowDragger/OdSelectionFrame.d.ts +18 -18
  72. package/lib/Viewer/Draggers/OdZoomWindowDragger/index.d.ts +13 -13
  73. package/lib/Viewer/Draggers/OdaLineDragger.d.ts +14 -14
  74. package/lib/Viewer/Draggers/OdaTextDragger.d.ts +15 -15
  75. package/lib/Viewer/Draggers/OdaWalkDragger.d.ts +29 -29
  76. package/lib/Viewer/Draggers/OrbitAroundBuildingDragger.d.ts +18 -18
  77. package/lib/Viewer/EventEmitter2.d.ts +53 -53
  78. package/lib/Viewer/ICommands.d.ts +24 -24
  79. package/lib/Viewer/IEventEmitter2.d.ts +12 -12
  80. package/lib/Viewer/IViewer.d.ts +26 -26
  81. package/lib/Viewer/Loaders/BaseLoader.d.ts +10 -10
  82. package/lib/Viewer/Loaders/LoaderFactory.d.ts +9 -9
  83. package/lib/Viewer/Loaders/TCSLoader.d.ts +4 -4
  84. package/lib/Viewer/Loaders/UpdaterController.d.ts +14 -14
  85. package/lib/Viewer/Loaders/VsfXLoader.d.ts +4 -4
  86. package/lib/Viewer/Loaders/VsfXPartialLoader.d.ts +4 -4
  87. package/lib/Viewer/Markup/Api/IMarkupArrow.d.ts +21 -11
  88. package/lib/Viewer/Markup/Api/IMarkupCloud.d.ts +15 -0
  89. package/lib/Viewer/Markup/Api/IMarkupColorable.d.ts +4 -4
  90. package/lib/Viewer/Markup/Api/IMarkupEllipse.d.ts +14 -14
  91. package/lib/Viewer/Markup/Api/IMarkupImage.d.ts +14 -14
  92. package/lib/Viewer/Markup/Api/IMarkupLine.d.ts +18 -10
  93. package/lib/Viewer/Markup/Api/IMarkupObject.d.ts +11 -11
  94. package/lib/Viewer/Markup/Api/IMarkupRectangle.d.ts +14 -14
  95. package/lib/Viewer/Markup/Api/IMarkupText.d.ts +12 -12
  96. package/lib/Viewer/Markup/Api/Impl/Konva/KonvaArrow.d.ts +46 -31
  97. package/lib/Viewer/Markup/Api/Impl/Konva/KonvaCloud.d.ts +36 -0
  98. package/lib/Viewer/Markup/Api/Impl/Konva/KonvaEllipse.d.ts +40 -39
  99. package/lib/Viewer/Markup/Api/Impl/Konva/KonvaImage.d.ts +36 -35
  100. package/lib/Viewer/Markup/Api/Impl/Konva/KonvaLine.d.ts +35 -31
  101. package/lib/Viewer/Markup/Api/Impl/Konva/KonvaRectangle.d.ts +38 -37
  102. package/lib/Viewer/Markup/Api/Impl/Konva/KonvaText.d.ts +37 -36
  103. package/lib/Viewer/Markup/IMarkup.d.ts +38 -37
  104. package/lib/Viewer/Markup/Impl/Konva/KonvaMarkup.d.ts +71 -62
  105. package/lib/Viewer/Markup/Impl/Konva/MarkupColor.d.ts +18 -18
  106. package/lib/Viewer/Markup/Impl/Visualize/VisualizeMarkup.d.ts +32 -32
  107. package/lib/Viewer/Markup/MarkupFactory.d.ts +6 -6
  108. package/lib/Viewer/Options.d.ts +227 -227
  109. package/lib/Viewer/OptionsEvents.d.ts +25 -25
  110. package/lib/Viewer/Viewer.d.ts +352 -352
  111. package/lib/Viewer/ViewerCommands.d.ts +22 -22
  112. package/lib/Viewer/ViewerEvents.d.ts +600 -600
  113. package/lib/Viewer/utils.d.ts +3 -3
  114. package/lib/index.d.ts +23 -23
  115. package/package.json +38 -32
  116. package/src/Api/Assembly.ts +678 -678
  117. package/src/Api/ClashTest.ts +290 -290
  118. package/src/Api/Client.ts +816 -816
  119. package/src/Api/ClientEvents.ts +31 -31
  120. package/src/Api/File.ts +962 -962
  121. package/src/Api/HttpClient.ts +73 -73
  122. package/src/Api/IAssembly.ts +37 -37
  123. package/src/Api/IFile.ts +74 -74
  124. package/src/Api/IHttpClient.ts +50 -50
  125. package/src/Api/IUser.ts +33 -33
  126. package/src/Api/Job.ts +253 -253
  127. package/src/Api/Member.ts +161 -161
  128. package/src/Api/Model.ts +259 -259
  129. package/src/Api/Permission.ts +173 -173
  130. package/src/Api/Project.ts +479 -479
  131. package/src/Api/Role.ts +158 -158
  132. package/src/Api/User.ts +357 -357
  133. package/src/Api/impl/FetchError.ts +48 -48
  134. package/src/Api/impl/Utils.ts +367 -367
  135. package/src/Api/impl/http.ts +92 -92
  136. package/src/ConvetMath.ts +372 -372
  137. package/src/Viewer/CanvasEvents.ts +41 -41
  138. package/src/Viewer/Commands/ApplyModelTransform.ts +70 -70
  139. package/src/Viewer/Commands/ClearMarkup.ts +28 -28
  140. package/src/Viewer/Commands/ClearSlices.ts +27 -27
  141. package/src/Viewer/Commands/CreatePreview.ts +33 -33
  142. package/src/Viewer/Commands/Explode.ts +38 -38
  143. package/src/Viewer/Commands/GetDefaultViewPositions.ts +36 -36
  144. package/src/Viewer/Commands/GetModels.ts +43 -43
  145. package/src/Viewer/Commands/GetSelected.ts +58 -58
  146. package/src/Viewer/Commands/HideSelected.ts +37 -37
  147. package/src/Viewer/Commands/IsolateSelected.ts +37 -37
  148. package/src/Viewer/Commands/RegenerateAll.ts +37 -37
  149. package/src/Viewer/Commands/ResetView.ts +43 -43
  150. package/src/Viewer/Commands/SelectModel.ts +52 -52
  151. package/src/Viewer/Commands/SetActiveDragger.ts +29 -29
  152. package/src/Viewer/Commands/SetDefaultViewPosition.ts +50 -50
  153. package/src/Viewer/Commands/SetMarkupColor.ts +29 -29
  154. package/src/Viewer/Commands/SetSelected.ts +47 -47
  155. package/src/Viewer/Commands/ShowAll.ts +37 -37
  156. package/src/Viewer/Commands/Unselect.ts +37 -37
  157. package/src/Viewer/Commands/ZoomToExtents.ts +43 -43
  158. package/src/Viewer/Commands/ZoomToObjects.ts +47 -47
  159. package/src/Viewer/Commands/ZoomToSelected.ts +39 -39
  160. package/src/Viewer/Commands.ts +81 -81
  161. package/src/Viewer/Draggers/Actions/OrbitAction.ts +250 -250
  162. package/src/Viewer/Draggers/Actions/PanAction.ts +102 -102
  163. package/src/Viewer/Draggers/Actions/ZoomAction.ts +45 -45
  164. package/src/Viewer/Draggers/Common/Geometry.ts +152 -152
  165. package/src/Viewer/Draggers/Common/GestureManager.ts +263 -263
  166. package/src/Viewer/Draggers/Common/OdBaseDragger.ts +270 -270
  167. package/src/Viewer/Draggers/Common/OdaGeAction.ts +146 -146
  168. package/src/Viewer/Draggers/MeasureLineDragger/MeasureLineItem.ts +248 -248
  169. package/src/Viewer/Draggers/MeasureLineDragger/MeasureUtils.ts +182 -182
  170. package/src/Viewer/Draggers/MeasureLineDragger/index.ts +166 -166
  171. package/src/Viewer/Draggers/OdBaseCuttingPlaneDragger.ts +182 -182
  172. package/src/Viewer/Draggers/OdCuttingPlaneXAxisDragger.ts +53 -53
  173. package/src/Viewer/Draggers/OdCuttingPlaneYAxisDragger.ts +53 -53
  174. package/src/Viewer/Draggers/OdCuttingPlaneZAxisDragger.ts +53 -53
  175. package/src/Viewer/Draggers/OdOrbitDragger.ts +70 -70
  176. package/src/Viewer/Draggers/OdPanDragger.ts +62 -62
  177. package/src/Viewer/Draggers/OdZoomDragger.ts +59 -59
  178. package/src/Viewer/Draggers/OdZoomWheelDragger.ts +103 -103
  179. package/src/Viewer/Draggers/OdZoomWindowDragger/OdSelectionFrame.ts +123 -123
  180. package/src/Viewer/Draggers/OdZoomWindowDragger/index.ts +75 -75
  181. package/src/Viewer/Draggers/OdaLineDragger.ts +80 -80
  182. package/src/Viewer/Draggers/OdaTextDragger.ts +118 -118
  183. package/src/Viewer/Draggers/OdaWalkDragger.ts +278 -278
  184. package/src/Viewer/Draggers/OrbitAroundBuildingDragger.ts +184 -184
  185. package/src/Viewer/EventEmitter2.ts +116 -116
  186. package/src/Viewer/ICommands.ts +53 -53
  187. package/src/Viewer/IEventEmitter2.ts +36 -36
  188. package/src/Viewer/IViewer.ts +55 -55
  189. package/src/Viewer/Loaders/BaseLoader.ts +40 -40
  190. package/src/Viewer/Loaders/LoaderFactory.ts +44 -44
  191. package/src/Viewer/Loaders/TCSLoader.ts +82 -82
  192. package/src/Viewer/Loaders/UpdaterController.ts +36 -36
  193. package/src/Viewer/Loaders/VsfXLoader.ts +87 -87
  194. package/src/Viewer/Loaders/VsfXPartialLoader.ts +208 -208
  195. package/src/Viewer/Markup/Api/IMarkupArrow.ts +12 -15
  196. package/src/Viewer/Markup/Api/IMarkupCloud.ts +15 -0
  197. package/src/Viewer/Markup/Api/IMarkupColorable.ts +4 -4
  198. package/src/Viewer/Markup/Api/IMarkupEllipse.ts +15 -15
  199. package/src/Viewer/Markup/Api/IMarkupImage.ts +15 -15
  200. package/src/Viewer/Markup/Api/IMarkupLine.ts +20 -10
  201. package/src/Viewer/Markup/Api/IMarkupObject.ts +15 -15
  202. package/src/Viewer/Markup/Api/IMarkupRectangle.ts +15 -15
  203. package/src/Viewer/Markup/Api/IMarkupText.ts +12 -12
  204. package/src/Viewer/Markup/Api/Impl/Konva/KonvaArrow.ts +117 -119
  205. package/src/Viewer/Markup/Api/Impl/Konva/KonvaCloud.ts +208 -0
  206. package/src/Viewer/Markup/Api/Impl/Konva/KonvaEllipse.ts +118 -113
  207. package/src/Viewer/Markup/Api/Impl/Konva/KonvaImage.ts +123 -121
  208. package/src/Viewer/Markup/Api/Impl/Konva/KonvaLine.ts +130 -99
  209. package/src/Viewer/Markup/Api/Impl/Konva/KonvaRectangle.ts +119 -113
  210. package/src/Viewer/Markup/Api/Impl/Konva/KonvaText.ts +110 -104
  211. package/src/Viewer/Markup/IMarkup.ts +40 -39
  212. package/src/Viewer/Markup/Impl/Konva/KonvaMarkup.ts +1208 -872
  213. package/src/Viewer/Markup/Impl/Konva/MarkupColor.ts +39 -39
  214. package/src/Viewer/Markup/Impl/Visualize/VisualizeMarkup.ts +273 -273
  215. package/src/Viewer/Markup/MarkupFactory.ts +32 -32
  216. package/src/Viewer/Options.ts +502 -502
  217. package/src/Viewer/OptionsEvents.ts +28 -28
  218. package/src/Viewer/Viewer.ts +1109 -1109
  219. package/src/Viewer/ViewerCommands.ts +45 -45
  220. package/src/Viewer/ViewerEvents.ts +700 -700
  221. package/src/Viewer/utils.ts +74 -74
  222. package/src/index.ts +48 -48
package/src/Api/User.ts CHANGED
@@ -1,357 +1,357 @@
1
- ///////////////////////////////////////////////////////////////////////////////
2
- // Copyright (C) 2002-2021, Open Design Alliance (the "Alliance").
3
- // All rights reserved.
4
- //
5
- // This software and its documentation and related materials are owned by
6
- // the Alliance. The software may only be incorporated into application
7
- // programs owned by members of the Alliance, subject to a signed
8
- // Membership Agreement and Supplemental Software License Agreement with the
9
- // Alliance. The structure and organization of this software are the valuable
10
- // trade secrets of the Alliance and its suppliers. The software is also
11
- // protected by copyright law and international treaty provisions. Application
12
- // programs incorporating this software must include the following statement
13
- // with their copyright notices:
14
- //
15
- // This application incorporates Open Design Alliance software pursuant to a
16
- // license agreement with Open Design Alliance.
17
- // Open Design Alliance Copyright (C) 2002-2021 by Open Design Alliance.
18
- // All rights reserved.
19
- //
20
- // By use of this software, its documentation or related materials, you
21
- // acknowledge and accept the above terms.
22
- ///////////////////////////////////////////////////////////////////////////////
23
-
24
- import { IHttpClient } from "./IHttpClient";
25
- import { json, userFullName, userInitials } from "./impl/Utils";
26
-
27
- export interface UserParams {
28
- /**
29
- * `true` if user is an administrator
30
- */
31
- isAdmin?: boolean;
32
-
33
- /**
34
- * User name
35
- */
36
- userName?: string;
37
-
38
- /**
39
- * First name
40
- */
41
- firstName?: string;
42
-
43
- /**
44
- * Last name
45
- */
46
- lastName?: string;
47
-
48
- /**
49
- * `true` if user is allowed to create a project
50
- */
51
- canCreateProject?: boolean;
52
-
53
- /**
54
- * The maximum number of projects that the user can create
55
- */
56
- projectsLimit?: number;
57
-
58
- /**
59
- * The size of the file storage available to the user
60
- */
61
- storageLimit?: number;
62
- }
63
-
64
- /**
65
- * The class representing a `user` entity.
66
- */
67
- export class User {
68
- private _data: any;
69
- protected httpClient: IHttpClient;
70
-
71
- /**
72
- * @param data - An object that implements user data storage.
73
- * @param httpClient - Http client.
74
- */
75
- constructor(data: any, httpClient: IHttpClient) {
76
- this.httpClient = httpClient;
77
- this.data = data;
78
- }
79
-
80
- /**
81
- * User avatar image URL. Use {@link User#setAvatar | setAvatar()} to change avatar image.
82
- *
83
- * @readonly
84
- */
85
- get avatarUrl(): string {
86
- return this._data.avatarUrl;
87
- }
88
-
89
- /**
90
- * `true` if user is allowed to create a project.
91
- *
92
- * @readonly
93
- */
94
- get canCreateProject(): boolean {
95
- return this.data.canCreateProject;
96
- }
97
-
98
- /**
99
- * User account registration time (UTC) in the format specified in <a
100
- * href="https://www.wikipedia.org/wiki/ISO_8601" target="_blank">ISO 8601</a>.
101
- *
102
- * @readonly
103
- */
104
- get createAt(): string {
105
- return this.data.createAt;
106
- }
107
-
108
- /**
109
- * User custom fields object, to store custom data.
110
- */
111
- get customFields(): any {
112
- return this.data.customFields;
113
- }
114
-
115
- set customFields(value: any) {
116
- this._data.customFields = value;
117
- }
118
-
119
- /**
120
- * Raw user data received from the server.
121
- *
122
- * @readonly
123
- */
124
-
125
- get data(): any {
126
- return this._data;
127
- }
128
-
129
- private set data(value: any) {
130
- this._data = value;
131
- this._data.avatarUrl = value.avatarImage ? `${this.httpClient.serverUrl}/users/${this._data.id}/avatar` : "";
132
- this._data.fullName = userFullName(this._data);
133
- this._data.initials = userInitials(this._data.fullName);
134
- }
135
-
136
- /**
137
- * User email.
138
- *
139
- * @readonly
140
- */
141
- get email(): string {
142
- return this.data.email;
143
- }
144
-
145
- /**
146
- * The user's email confirmation code, or an empty string if the email has already been confirmed.
147
- *
148
- * @readonly
149
- */
150
- get emailConfirmationId(): string {
151
- return this.data.emailConfirmationId;
152
- }
153
-
154
- /**
155
- * First name.
156
- */
157
- get firstName(): string {
158
- return this.data.firstName;
159
- }
160
-
161
- set firstName(value: string) {
162
- this._data.firstName = value;
163
- }
164
-
165
- /**
166
- * Full name. Returns the user's first and last name. If first name and last names are empty,
167
- * returns the user name.
168
- */
169
- get fullName(): string {
170
- return this.data.fullName;
171
- }
172
-
173
- /**
174
- * Unique user ID.
175
- *
176
- * @readonly
177
- */
178
- get id(): string {
179
- return this.data.id;
180
- }
181
-
182
- /**
183
- * User initials. Returns a first letters of the user's first and last names. If first name
184
- * and last names are empty, returns the first letter of the user name.
185
- */
186
- get initials(): string {
187
- return this.data.initials;
188
- }
189
-
190
- /**
191
- * `false` if the user has not yet confirmed his email address.
192
- *
193
- * @readonly
194
- */
195
- get isEmailConfirmed(): boolean {
196
- return this.data.isEmailConfirmed;
197
- }
198
-
199
- /**
200
- * User last update time (UTC) in the format specified in <a
201
- * href="https://www.wikipedia.org/wiki/ISO_8601" target="_blank">ISO 8601</a>.
202
- */
203
- get lastModified(): string {
204
- return this.data.lastModified;
205
- }
206
-
207
- /**
208
- * Last name.
209
- */
210
- get lastName(): string {
211
- return this.data.lastName;
212
- }
213
-
214
- set lastName(value: string) {
215
- this._data.lastName = value;
216
- }
217
-
218
- /**
219
- * User last sign in time (UTC) in the format specified in <a
220
- * href="https://www.wikipedia.org/wiki/ISO_8601" target="_blank">ISO 8601</a>.
221
- */
222
- get lastSignIn(): string {
223
- return this.data.lastSignIn;
224
- }
225
-
226
- /**
227
- * The maximum number of projects that a user can create.
228
- *
229
- * @readonly
230
- */
231
- get projectsLimit(): number {
232
- return this.data.projectsLimit;
233
- }
234
-
235
- /**
236
- * The user's API key.
237
- *
238
- * @readonly
239
- */
240
- get token(): string {
241
- return this.data.tokenInfo.token;
242
- }
243
-
244
- /**
245
- * User name.
246
- */
247
- get userName(): string {
248
- return this.data.userName;
249
- }
250
-
251
- set userName(value: string) {
252
- this._data.userName = value;
253
- }
254
-
255
- /**
256
- * Refresh user data. Only admins can checkout other users, if the current logged in user
257
- * does not have administrator rights, hi can only checkout himself, otherwise an exception
258
- * will be thrown.
259
- */
260
- async checkout(): Promise<User> {
261
- if (this.id === this.httpClient.signInUserId) {
262
- const data = await json(this.httpClient.get("/user"));
263
- this.data = { id: this.id, ...data };
264
- } else {
265
- const data = await json(this.httpClient.get(`/users/${this.id}`));
266
- this.data = { id: data.id, ...data.userBrief };
267
- }
268
- return this;
269
- }
270
-
271
- /**
272
- * Update user data on the server. Only admins can update other users, if the current logged
273
- * in user does not have administrator rights, hi can only update himself, otherwise an
274
- * exception will be thrown.
275
- *
276
- * @async
277
- * @param data - Raw user data.
278
- */
279
- async update(data: any) {
280
- if (this.id === this.httpClient.signInUserId) {
281
- const newData = await json(this.httpClient.put("/user", data));
282
- this.data = { id: this.id, ...newData };
283
- } else {
284
- const newData = await json(this.httpClient.put(`/users/${this.id}`, { userBrief: data }));
285
- this.data = { id: newData.id, ...newData.userBrief };
286
- }
287
- return this;
288
- }
289
-
290
- /**
291
- * Delete a user from the server. Only admins can delete users, if the current logged in user
292
- * does not have administrator rights, an exception will be thrown.
293
- *
294
- * Admins can delete themselves or other admins. An admin can only delete himself if he is
295
- * not the last administrator.
296
- *
297
- * You need to re-login to continue working after deleting the current logged in user.
298
- *
299
- * @async
300
- * @returns Returns the raw data of a deleted user.
301
- */
302
- delete(): Promise<any> {
303
- return json(this.httpClient.delete(`/users/${this.id}`)).then((data) => {
304
- if (this.id === this.httpClient.signInUserId) {
305
- this.httpClient.headers = {};
306
- this.httpClient.signInUserId = "";
307
- }
308
- return data;
309
- });
310
- }
311
-
312
- /**
313
- * Save user data changes to the server. Call this method to update user data on the server
314
- * after any changes.
315
- *
316
- * @async
317
- */
318
- save(): Promise<User> {
319
- return this.update(this.data);
320
- }
321
-
322
- /**
323
- * Set or remove the user avatar. Only admins can set the avatar of other users, if the
324
- * current logged in user does not have administrator rights, he can only set his own avatar,
325
- * otherwise an exception will be thrown.
326
- *
327
- * @async
328
- * @param image - Avatar image. Can be a <a
329
- * href="https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/Data_URIs"
330
- * target="_blank">Data URL</a> string, <a
331
- * href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer"
332
- * target="_blank">ArrayBuffer</a>, <a
333
- * href="https://developer.mozilla.org/docs/Web/API/Blob/Blob" target="_blank">Blob</a> or
334
- * Web API <a href="https://developer.mozilla.org/docs/Web/API/File"
335
- * target="_blank">File</a> object. Setting the `image` to `null` will remove the avatar.
336
- */
337
- async setAvatar(image?: ArrayBuffer | Blob | globalThis.File | FormData | string | null): Promise<User> {
338
- if (image) {
339
- if (this.id === this.httpClient.signInUserId) {
340
- const data = await json(this.httpClient.post("/user/avatar", image));
341
- this.data = { id: this.id, ...data };
342
- } else {
343
- const data = await json(this.httpClient.post(`/users/${this.id}/avatar`, image));
344
- this.data = { id: data.id, ...data.userBrief };
345
- }
346
- } else {
347
- if (this.id === this.httpClient.signInUserId) {
348
- const data = await json(this.httpClient.delete("/user/avatar"));
349
- this.data = { id: this.id, ...data };
350
- } else {
351
- const data = await json(this.httpClient.delete(`/users/${this.id}/avatar`));
352
- this.data = { id: data.id, ...data.userBrief };
353
- }
354
- }
355
- return this;
356
- }
357
- }
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2002-2021, Open Design Alliance (the "Alliance").
3
+ // All rights reserved.
4
+ //
5
+ // This software and its documentation and related materials are owned by
6
+ // the Alliance. The software may only be incorporated into application
7
+ // programs owned by members of the Alliance, subject to a signed
8
+ // Membership Agreement and Supplemental Software License Agreement with the
9
+ // Alliance. The structure and organization of this software are the valuable
10
+ // trade secrets of the Alliance and its suppliers. The software is also
11
+ // protected by copyright law and international treaty provisions. Application
12
+ // programs incorporating this software must include the following statement
13
+ // with their copyright notices:
14
+ //
15
+ // This application incorporates Open Design Alliance software pursuant to a
16
+ // license agreement with Open Design Alliance.
17
+ // Open Design Alliance Copyright (C) 2002-2021 by Open Design Alliance.
18
+ // All rights reserved.
19
+ //
20
+ // By use of this software, its documentation or related materials, you
21
+ // acknowledge and accept the above terms.
22
+ ///////////////////////////////////////////////////////////////////////////////
23
+
24
+ import { IHttpClient } from "./IHttpClient";
25
+ import { json, userFullName, userInitials } from "./impl/Utils";
26
+
27
+ export interface UserParams {
28
+ /**
29
+ * `true` if user is an administrator
30
+ */
31
+ isAdmin?: boolean;
32
+
33
+ /**
34
+ * User name
35
+ */
36
+ userName?: string;
37
+
38
+ /**
39
+ * First name
40
+ */
41
+ firstName?: string;
42
+
43
+ /**
44
+ * Last name
45
+ */
46
+ lastName?: string;
47
+
48
+ /**
49
+ * `true` if user is allowed to create a project
50
+ */
51
+ canCreateProject?: boolean;
52
+
53
+ /**
54
+ * The maximum number of projects that the user can create
55
+ */
56
+ projectsLimit?: number;
57
+
58
+ /**
59
+ * The size of the file storage available to the user
60
+ */
61
+ storageLimit?: number;
62
+ }
63
+
64
+ /**
65
+ * The class representing a `user` entity.
66
+ */
67
+ export class User {
68
+ private _data: any;
69
+ protected httpClient: IHttpClient;
70
+
71
+ /**
72
+ * @param data - An object that implements user data storage.
73
+ * @param httpClient - Http client.
74
+ */
75
+ constructor(data: any, httpClient: IHttpClient) {
76
+ this.httpClient = httpClient;
77
+ this.data = data;
78
+ }
79
+
80
+ /**
81
+ * User avatar image URL. Use {@link User#setAvatar | setAvatar()} to change avatar image.
82
+ *
83
+ * @readonly
84
+ */
85
+ get avatarUrl(): string {
86
+ return this._data.avatarUrl;
87
+ }
88
+
89
+ /**
90
+ * `true` if user is allowed to create a project.
91
+ *
92
+ * @readonly
93
+ */
94
+ get canCreateProject(): boolean {
95
+ return this.data.canCreateProject;
96
+ }
97
+
98
+ /**
99
+ * User account registration time (UTC) in the format specified in <a
100
+ * href="https://www.wikipedia.org/wiki/ISO_8601" target="_blank">ISO 8601</a>.
101
+ *
102
+ * @readonly
103
+ */
104
+ get createAt(): string {
105
+ return this.data.createAt;
106
+ }
107
+
108
+ /**
109
+ * User custom fields object, to store custom data.
110
+ */
111
+ get customFields(): any {
112
+ return this.data.customFields;
113
+ }
114
+
115
+ set customFields(value: any) {
116
+ this._data.customFields = value;
117
+ }
118
+
119
+ /**
120
+ * Raw user data received from the server.
121
+ *
122
+ * @readonly
123
+ */
124
+
125
+ get data(): any {
126
+ return this._data;
127
+ }
128
+
129
+ private set data(value: any) {
130
+ this._data = value;
131
+ this._data.avatarUrl = value.avatarImage ? `${this.httpClient.serverUrl}/users/${this._data.id}/avatar` : "";
132
+ this._data.fullName = userFullName(this._data);
133
+ this._data.initials = userInitials(this._data.fullName);
134
+ }
135
+
136
+ /**
137
+ * User email.
138
+ *
139
+ * @readonly
140
+ */
141
+ get email(): string {
142
+ return this.data.email;
143
+ }
144
+
145
+ /**
146
+ * The user's email confirmation code, or an empty string if the email has already been confirmed.
147
+ *
148
+ * @readonly
149
+ */
150
+ get emailConfirmationId(): string {
151
+ return this.data.emailConfirmationId;
152
+ }
153
+
154
+ /**
155
+ * First name.
156
+ */
157
+ get firstName(): string {
158
+ return this.data.firstName;
159
+ }
160
+
161
+ set firstName(value: string) {
162
+ this._data.firstName = value;
163
+ }
164
+
165
+ /**
166
+ * Full name. Returns the user's first and last name. If first name and last names are empty,
167
+ * returns the user name.
168
+ */
169
+ get fullName(): string {
170
+ return this.data.fullName;
171
+ }
172
+
173
+ /**
174
+ * Unique user ID.
175
+ *
176
+ * @readonly
177
+ */
178
+ get id(): string {
179
+ return this.data.id;
180
+ }
181
+
182
+ /**
183
+ * User initials. Returns a first letters of the user's first and last names. If first name
184
+ * and last names are empty, returns the first letter of the user name.
185
+ */
186
+ get initials(): string {
187
+ return this.data.initials;
188
+ }
189
+
190
+ /**
191
+ * `false` if the user has not yet confirmed his email address.
192
+ *
193
+ * @readonly
194
+ */
195
+ get isEmailConfirmed(): boolean {
196
+ return this.data.isEmailConfirmed;
197
+ }
198
+
199
+ /**
200
+ * User last update time (UTC) in the format specified in <a
201
+ * href="https://www.wikipedia.org/wiki/ISO_8601" target="_blank">ISO 8601</a>.
202
+ */
203
+ get lastModified(): string {
204
+ return this.data.lastModified;
205
+ }
206
+
207
+ /**
208
+ * Last name.
209
+ */
210
+ get lastName(): string {
211
+ return this.data.lastName;
212
+ }
213
+
214
+ set lastName(value: string) {
215
+ this._data.lastName = value;
216
+ }
217
+
218
+ /**
219
+ * User last sign in time (UTC) in the format specified in <a
220
+ * href="https://www.wikipedia.org/wiki/ISO_8601" target="_blank">ISO 8601</a>.
221
+ */
222
+ get lastSignIn(): string {
223
+ return this.data.lastSignIn;
224
+ }
225
+
226
+ /**
227
+ * The maximum number of projects that a user can create.
228
+ *
229
+ * @readonly
230
+ */
231
+ get projectsLimit(): number {
232
+ return this.data.projectsLimit;
233
+ }
234
+
235
+ /**
236
+ * The user's API key.
237
+ *
238
+ * @readonly
239
+ */
240
+ get token(): string {
241
+ return this.data.tokenInfo.token;
242
+ }
243
+
244
+ /**
245
+ * User name.
246
+ */
247
+ get userName(): string {
248
+ return this.data.userName;
249
+ }
250
+
251
+ set userName(value: string) {
252
+ this._data.userName = value;
253
+ }
254
+
255
+ /**
256
+ * Refresh user data. Only admins can checkout other users, if the current logged in user
257
+ * does not have administrator rights, hi can only checkout himself, otherwise an exception
258
+ * will be thrown.
259
+ */
260
+ async checkout(): Promise<User> {
261
+ if (this.id === this.httpClient.signInUserId) {
262
+ const data = await json(this.httpClient.get("/user"));
263
+ this.data = { id: this.id, ...data };
264
+ } else {
265
+ const data = await json(this.httpClient.get(`/users/${this.id}`));
266
+ this.data = { id: data.id, ...data.userBrief };
267
+ }
268
+ return this;
269
+ }
270
+
271
+ /**
272
+ * Update user data on the server. Only admins can update other users, if the current logged
273
+ * in user does not have administrator rights, hi can only update himself, otherwise an
274
+ * exception will be thrown.
275
+ *
276
+ * @async
277
+ * @param data - Raw user data.
278
+ */
279
+ async update(data: any) {
280
+ if (this.id === this.httpClient.signInUserId) {
281
+ const newData = await json(this.httpClient.put("/user", data));
282
+ this.data = { id: this.id, ...newData };
283
+ } else {
284
+ const newData = await json(this.httpClient.put(`/users/${this.id}`, { userBrief: data }));
285
+ this.data = { id: newData.id, ...newData.userBrief };
286
+ }
287
+ return this;
288
+ }
289
+
290
+ /**
291
+ * Delete a user from the server. Only admins can delete users, if the current logged in user
292
+ * does not have administrator rights, an exception will be thrown.
293
+ *
294
+ * Admins can delete themselves or other admins. An admin can only delete himself if he is
295
+ * not the last administrator.
296
+ *
297
+ * You need to re-login to continue working after deleting the current logged in user.
298
+ *
299
+ * @async
300
+ * @returns Returns the raw data of a deleted user.
301
+ */
302
+ delete(): Promise<any> {
303
+ return json(this.httpClient.delete(`/users/${this.id}`)).then((data) => {
304
+ if (this.id === this.httpClient.signInUserId) {
305
+ this.httpClient.headers = {};
306
+ this.httpClient.signInUserId = "";
307
+ }
308
+ return data;
309
+ });
310
+ }
311
+
312
+ /**
313
+ * Save user data changes to the server. Call this method to update user data on the server
314
+ * after any changes.
315
+ *
316
+ * @async
317
+ */
318
+ save(): Promise<User> {
319
+ return this.update(this.data);
320
+ }
321
+
322
+ /**
323
+ * Set or remove the user avatar. Only admins can set the avatar of other users, if the
324
+ * current logged in user does not have administrator rights, he can only set his own avatar,
325
+ * otherwise an exception will be thrown.
326
+ *
327
+ * @async
328
+ * @param image - Avatar image. Can be a <a
329
+ * href="https://developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/Data_URIs"
330
+ * target="_blank">Data URL</a> string, <a
331
+ * href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer"
332
+ * target="_blank">ArrayBuffer</a>, <a
333
+ * href="https://developer.mozilla.org/docs/Web/API/Blob/Blob" target="_blank">Blob</a> or
334
+ * Web API <a href="https://developer.mozilla.org/docs/Web/API/File"
335
+ * target="_blank">File</a> object. Setting the `image` to `null` will remove the avatar.
336
+ */
337
+ async setAvatar(image?: ArrayBuffer | Blob | globalThis.File | FormData | string | null): Promise<User> {
338
+ if (image) {
339
+ if (this.id === this.httpClient.signInUserId) {
340
+ const data = await json(this.httpClient.post("/user/avatar", image));
341
+ this.data = { id: this.id, ...data };
342
+ } else {
343
+ const data = await json(this.httpClient.post(`/users/${this.id}/avatar`, image));
344
+ this.data = { id: data.id, ...data.userBrief };
345
+ }
346
+ } else {
347
+ if (this.id === this.httpClient.signInUserId) {
348
+ const data = await json(this.httpClient.delete("/user/avatar"));
349
+ this.data = { id: this.id, ...data };
350
+ } else {
351
+ const data = await json(this.httpClient.delete(`/users/${this.id}/avatar`));
352
+ this.data = { id: data.id, ...data.userBrief };
353
+ }
354
+ }
355
+ return this;
356
+ }
357
+ }