bruce-models 1.9.7 → 1.9.8

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 (83) hide show
  1. package/dist/bruce-models.es5.js +9 -3
  2. package/dist/bruce-models.es5.js.map +1 -1
  3. package/dist/bruce-models.umd.js +9 -3
  4. package/dist/bruce-models.umd.js.map +1 -1
  5. package/dist/lib/account/account-settings.js +2 -2
  6. package/dist/lib/account/account.js +185 -185
  7. package/dist/lib/ann-document/ann-document.js +86 -86
  8. package/dist/lib/api/abstract-api.js +246 -246
  9. package/dist/lib/api/api-getters.js +134 -134
  10. package/dist/lib/api/api.js +93 -93
  11. package/dist/lib/api/bruce-api.js +216 -216
  12. package/dist/lib/api/cam-api.js +82 -82
  13. package/dist/lib/api/global-api.js +81 -81
  14. package/dist/lib/api/idm-api.js +82 -82
  15. package/dist/lib/bruce-models.js +86 -86
  16. package/dist/lib/calculator/calculator.js +341 -335
  17. package/dist/lib/calculator/calculator.js.map +1 -1
  18. package/dist/lib/client-file/client-file.js +245 -245
  19. package/dist/lib/common/bounds.js +61 -61
  20. package/dist/lib/common/bruce-event.js +46 -46
  21. package/dist/lib/common/bruce-variable.js +60 -60
  22. package/dist/lib/common/cache.js +165 -165
  23. package/dist/lib/common/camera.js +11 -11
  24. package/dist/lib/common/cartes.js +123 -123
  25. package/dist/lib/common/carto.js +60 -60
  26. package/dist/lib/common/color.js +86 -86
  27. package/dist/lib/common/delay-queue.js +56 -56
  28. package/dist/lib/common/dictionary.js +2 -2
  29. package/dist/lib/common/geometry.js +120 -120
  30. package/dist/lib/common/transform.js +2 -2
  31. package/dist/lib/common/utc.js +39 -39
  32. package/dist/lib/custom-form/custom-form-content.js +26 -26
  33. package/dist/lib/custom-form/custom-form.js +106 -106
  34. package/dist/lib/data-lab/data-lab.js +49 -49
  35. package/dist/lib/entity/entity-attachment-type.js +83 -83
  36. package/dist/lib/entity/entity-attachment.js +122 -122
  37. package/dist/lib/entity/entity-attribute.js +29 -29
  38. package/dist/lib/entity/entity-comment.js +82 -82
  39. package/dist/lib/entity/entity-coords.js +149 -149
  40. package/dist/lib/entity/entity-link.js +82 -82
  41. package/dist/lib/entity/entity-lod-category.js +100 -100
  42. package/dist/lib/entity/entity-lod.js +185 -185
  43. package/dist/lib/entity/entity-relation-type.js +109 -109
  44. package/dist/lib/entity/entity-relation.js +132 -132
  45. package/dist/lib/entity/entity-source.js +136 -136
  46. package/dist/lib/entity/entity-tag.js +149 -149
  47. package/dist/lib/entity/entity-type-visual-settings.js +13 -13
  48. package/dist/lib/entity/entity-type.js +113 -113
  49. package/dist/lib/entity/entity.js +319 -319
  50. package/dist/lib/entity/getters/batched-data-getter.js +84 -84
  51. package/dist/lib/entity/getters/entity-filter-getter.js +303 -303
  52. package/dist/lib/entity/getters/entity-globe.js +211 -211
  53. package/dist/lib/entity/getters/view-monitor.js +2 -2
  54. package/dist/lib/import/import-cad.js +53 -53
  55. package/dist/lib/import/import-csv.js +23 -23
  56. package/dist/lib/import/import-json.js +23 -23
  57. package/dist/lib/import/import-kml.js +23 -23
  58. package/dist/lib/import/imported-file.js +91 -91
  59. package/dist/lib/internal/uploader.js +76 -76
  60. package/dist/lib/markup/markup.js +185 -185
  61. package/dist/lib/plugin/plugin.js +83 -83
  62. package/dist/lib/program-key/program-key.js +111 -111
  63. package/dist/lib/project/menu-item.js +121 -121
  64. package/dist/lib/project/project-view-bookmark.js +147 -147
  65. package/dist/lib/project/project-view-legacy-tile.js +77 -77
  66. package/dist/lib/project/project-view-tile.js +125 -125
  67. package/dist/lib/project/project-view.js +133 -133
  68. package/dist/lib/project/zoom-control.js +17 -17
  69. package/dist/lib/server/message-broker.js +142 -142
  70. package/dist/lib/server/pending-action.js +71 -71
  71. package/dist/lib/server/task.js +63 -63
  72. package/dist/lib/style/style.js +117 -117
  73. package/dist/lib/tileset/tileset.js +415 -415
  74. package/dist/lib/user/permission.js +20 -20
  75. package/dist/lib/user/session.js +137 -137
  76. package/dist/lib/user/user-group.js +94 -94
  77. package/dist/lib/user/user.js +446 -446
  78. package/dist/lib/util/encrypt-utils.js +19 -19
  79. package/dist/lib/util/math-utils.js +40 -40
  80. package/dist/lib/util/object-utils.js +17 -17
  81. package/dist/lib/util/path-utils.js +61 -61
  82. package/dist/lib/util/url-utils.js +94 -94
  83. package/package.json +1 -1
@@ -1,447 +1,447 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.User = void 0;
13
- const api_1 = require("../api/api");
14
- /**
15
- * Describes the "User" concept within Bruce.
16
- * A user is either a login-user or an access-token.
17
- *
18
- * You cannot login using an access-token, but both concepts are-
19
- * treated the same way in terms of permissions and user groups.
20
- */
21
- var User;
22
- (function (User) {
23
- function GetCacheKey(userId, accountId) {
24
- if (!accountId) {
25
- accountId = "";
26
- }
27
- return api_1.Api.ECacheKey.User + api_1.Api.ECacheKey.Id + userId + api_1.Api.ECacheKey.Id + accountId;
28
- }
29
- User.GetCacheKey = GetCacheKey;
30
- function GetEmailCacheKey(email, accountId) {
31
- if (!accountId) {
32
- accountId = "";
33
- }
34
- return api_1.Api.ECacheKey.User + api_1.Api.ECacheKey.UserEmail + email + api_1.Api.ECacheKey.Id + accountId;
35
- }
36
- User.GetEmailCacheKey = GetEmailCacheKey;
37
- function GetSettingsCacheKey(userId, appId) {
38
- return api_1.Api.ECacheKey.User + api_1.Api.ECacheKey.UserSettings + userId + api_1.Api.ECacheKey.Id + appId;
39
- }
40
- User.GetSettingsCacheKey = GetSettingsCacheKey;
41
- let EType;
42
- (function (EType) {
43
- EType["User"] = "LOGIN_USER";
44
- EType["AccessToken"] = "ACCESS_TOKEN";
45
- })(EType = User.EType || (User.EType = {}));
46
- function Get(params) {
47
- return __awaiter(this, void 0, void 0, function* () {
48
- const { api, userId: id, accountId, req: reqParams } = params;
49
- if (!id) {
50
- throw ("ID is required.");
51
- }
52
- const cacheData = api.GetCacheItem(GetCacheKey(id, accountId), reqParams);
53
- if (cacheData) {
54
- return cacheData;
55
- }
56
- const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
57
- try {
58
- const data = yield api.GET(`user/${id}${accountId ? `?clientAccountID=${accountId}` : ""}`, reqParams);
59
- res({
60
- user: data
61
- });
62
- }
63
- catch (e) {
64
- rej(e);
65
- }
66
- }));
67
- api.Cache.Set(GetCacheKey(id, accountId), prom, api_1.Api.DEFAULT_CACHE_DURATION);
68
- return prom;
69
- });
70
- }
71
- User.Get = Get;
72
- function Update(params) {
73
- var _a;
74
- return __awaiter(this, void 0, void 0, function* () {
75
- const { api, user: data, req: reqParams } = params;
76
- if (!(data === null || data === void 0 ? void 0 : data.ID) || !(data === null || data === void 0 ? void 0 : data.Type)) {
77
- throw ("ID and Type are required.");
78
- }
79
- // When getting a user it is structured slightly different to when we update it.
80
- // We can make up the difference here.
81
- if ((_a = data.AccessPermissions) === null || _a === void 0 ? void 0 : _a.length) {
82
- for (let i = 0; i < data.AccessPermissions.length; i++) {
83
- const perm = data.AccessPermissions[i];
84
- if (!perm["UserGroup.ID"] && perm.UserGroups) {
85
- perm["UserGroup.ID"] = [];
86
- for (let j = 0; j < perm.UserGroups.length; j++) {
87
- perm["UserGroup.ID"].push(perm.UserGroups[j].ID);
88
- }
89
- }
90
- }
91
- }
92
- const res = yield api.POST(`user/${data.ID}`, data, reqParams);
93
- api.Cache.RemoveByContains(api_1.Api.ECacheKey.User + api_1.Api.ECacheKey.Id + data.ID);
94
- if (data.Type == EType.AccessToken) {
95
- api.Cache.RemoveByStartsWith(api_1.Api.ECacheKey.AccessToken + api_1.Api.ECacheKey.Account);
96
- }
97
- else if (data.Type == EType.User) {
98
- api.Cache.RemoveByStartsWith(api_1.Api.ECacheKey.User + api_1.Api.ECacheKey.Account);
99
- }
100
- return {
101
- user: res
102
- };
103
- });
104
- }
105
- User.Update = Update;
106
- /**
107
- * Loads settings for a given user + app.
108
- * The session's account id is used to separate settings between accounts.
109
- * @param params
110
- */
111
- function GetSettings(params) {
112
- return __awaiter(this, void 0, void 0, function* () {
113
- const { api, userId, appId, req } = params;
114
- if (!userId || !appId) {
115
- throw ("UserId and appId are required.");
116
- }
117
- const cacheData = api.GetCacheItem(GetSettingsCacheKey(userId, appId), req);
118
- if (cacheData) {
119
- return cacheData;
120
- }
121
- const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
122
- try {
123
- const data = yield api.GET(`user/${userId}/application/${appId}/settings`);
124
- const settings = (data === null || data === void 0 ? void 0 : data.Settings) ? data.Settings : {};
125
- res({
126
- settings: settings
127
- });
128
- }
129
- catch (e) {
130
- // It will complain if an app id hasn't been used yet.
131
- // We need to suppress that error.
132
- if (e && typeof e == "object") {
133
- if (e.ERROR && typeof e.ERROR == "object" && e.ERROR.Type == "NotFound") {
134
- res({
135
- settings: {}
136
- });
137
- return;
138
- }
139
- }
140
- rej(e);
141
- }
142
- }));
143
- api.Cache.Set(GetSettingsCacheKey(userId, appId), prom, api_1.Api.DEFAULT_CACHE_DURATION);
144
- return prom;
145
- });
146
- }
147
- User.GetSettings = GetSettings;
148
- /**
149
- * Updates settings for a given accId + user + app.
150
- * The settings update will replace the existing record, please ensure to merge with existing settings.
151
- * @param params
152
- */
153
- function UpdateSettings(params) {
154
- return __awaiter(this, void 0, void 0, function* () {
155
- const { api, accId, userId, appId, settings, req } = params;
156
- if (!accId || !userId || !appId) {
157
- throw ("accId, userId and appId are required.");
158
- }
159
- const postBody = {
160
- Settings: settings == null ? {} : settings,
161
- Application: appId,
162
- ClientAccountID: accId,
163
- UserID: userId
164
- };
165
- const prom = api.POST(`user/${userId}/application/${appId}/settings`, postBody, req);
166
- api.Cache.Remove(GetSettingsCacheKey(userId, appId));
167
- return prom;
168
- });
169
- }
170
- User.UpdateSettings = UpdateSettings;
171
- function GetUsernameAvailable(params) {
172
- return __awaiter(this, void 0, void 0, function* () {
173
- const { api, username, excludeUserId, req: reqParams } = params;
174
- if (!username) {
175
- throw ("Username is required.");
176
- }
177
- const req = api.GET(`user/loginavailable/${username}${excludeUserId ? "?excludeUserId=" + excludeUserId : ""}`, reqParams);
178
- const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
179
- try {
180
- const data = yield req;
181
- res({
182
- isAvailable: data.IsAvailable
183
- });
184
- }
185
- catch (e) {
186
- rej(e);
187
- }
188
- }));
189
- return prom;
190
- });
191
- }
192
- User.GetUsernameAvailable = GetUsernameAvailable;
193
- let LoginUser;
194
- (function (LoginUser) {
195
- function GetListCacheKey(accountId) {
196
- return api_1.Api.ECacheKey.User + api_1.Api.ECacheKey.Account + api_1.Api.ECacheKey.Id + accountId;
197
- }
198
- LoginUser.GetListCacheKey = GetListCacheKey;
199
- function GetByEmail(params) {
200
- return __awaiter(this, void 0, void 0, function* () {
201
- const { api, email, accountId, req: reqParams } = params;
202
- if (!email) {
203
- throw ("Email is required.");
204
- }
205
- const cacheData = api.GetCacheItem(GetEmailCacheKey(email, accountId), reqParams);
206
- if (cacheData) {
207
- return cacheData;
208
- }
209
- const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
210
- try {
211
- const data = yield api.GET(`userByEmail/${email}${accountId ? `?clientAccountID=${accountId}` : ""}`, reqParams);
212
- res({
213
- user: data
214
- });
215
- }
216
- catch (e) {
217
- rej(e);
218
- }
219
- }));
220
- api.Cache.Set(GetEmailCacheKey(email, accountId), prom, api_1.Api.DEFAULT_CACHE_DURATION);
221
- return prom;
222
- });
223
- }
224
- LoginUser.GetByEmail = GetByEmail;
225
- function GetList(params) {
226
- return __awaiter(this, void 0, void 0, function* () {
227
- let { api, accountId, exclusive, req: reqParams } = params;
228
- if (!accountId) {
229
- throw ("Client account ID is required.");
230
- }
231
- if (!exclusive) {
232
- exclusive = false;
233
- }
234
- const cacheData = exclusive ? null : api.GetCacheItem(GetListCacheKey(accountId), reqParams);
235
- if (cacheData) {
236
- return cacheData;
237
- }
238
- const req = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
239
- try {
240
- const data = yield api.GET(`users?clientAccountID=${accountId}${exclusive ? "&allExcludingClientAccount=true" : ""}`, reqParams);
241
- res({
242
- users: data.Items
243
- });
244
- }
245
- catch (e) {
246
- rej(e);
247
- }
248
- }));
249
- req.then((data) => {
250
- const users = data.users;
251
- for (let i = 0; i < users.length; i++) {
252
- api.Cache.Set(GetCacheKey(users[i].ID, accountId), {
253
- user: users[i]
254
- });
255
- }
256
- });
257
- if (!exclusive) {
258
- api.Cache.Set(GetListCacheKey(accountId), req, api_1.Api.DEFAULT_CACHE_DURATION);
259
- }
260
- return req;
261
- });
262
- }
263
- LoginUser.GetList = GetList;
264
- /**
265
- * Sends a signup email to the specified email address.
266
- * @param params
267
- * @returns
268
- */
269
- function Signup(params) {
270
- return __awaiter(this, void 0, void 0, function* () {
271
- const { api, email, req: reqParams } = params;
272
- if (!email) {
273
- throw ("Email is required.");
274
- }
275
- return api.POST("clientaccount/signup", {
276
- Email: email
277
- }, reqParams);
278
- });
279
- }
280
- LoginUser.Signup = Signup;
281
- /**
282
- * Sends a new signup email using a previous one's expired code.
283
- * @param params
284
- * @returns
285
- */
286
- function SignupResend(params) {
287
- return __awaiter(this, void 0, void 0, function* () {
288
- const { api, expiredCode, req: reqParams } = params;
289
- if (!expiredCode) {
290
- throw ("Expired activation code is required.");
291
- }
292
- return api.POST(`clientaccount/signup/resend?activationKey=${api_1.Api.Encode(expiredCode)}`, null, reqParams);
293
- });
294
- }
295
- LoginUser.SignupResend = SignupResend;
296
- /**
297
- * Completes signup using user data and a signup code.
298
- * @param params
299
- * @returns
300
- */
301
- function SignupComplete(params) {
302
- return __awaiter(this, void 0, void 0, function* () {
303
- let { api, code, user: data, accountId, req: reqParams } = params;
304
- if (!code || !(data === null || data === void 0 ? void 0 : data.Login) || !(data === null || data === void 0 ? void 0 : data.Password)) {
305
- throw ("Login, password, and activation code are required.");
306
- }
307
- data = JSON.parse(JSON.stringify(data));
308
- data.IsActivated = true;
309
- data.IsDisabled = false;
310
- data.key = code;
311
- const res = yield api.POST(`UserActivate/${accountId ? accountId : ""}`, data, reqParams);
312
- api.Cache.RemoveByContains(api_1.Api.ECacheKey.User + api_1.Api.ECacheKey.Id + res.ID);
313
- if (data.Email) {
314
- api.Cache.RemoveByContains(api_1.Api.ECacheKey.User + api_1.Api.ECacheKey.UserEmail + data.Email);
315
- }
316
- return {
317
- user: res
318
- };
319
- });
320
- }
321
- LoginUser.SignupComplete = SignupComplete;
322
- /**
323
- * Sends a password reset email to the specified email address.
324
- * @param params
325
- * @returns user id associated with provided email.
326
- */
327
- function ForgotPassword(params) {
328
- return __awaiter(this, void 0, void 0, function* () {
329
- const { api, accountId, email, req: reqParams } = params;
330
- if (!accountId || !email) {
331
- throw ("Account ID and email are required.");
332
- }
333
- const req = api.POST(`UserForgotPassword/${accountId}`, {
334
- Email: email
335
- }, reqParams);
336
- const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
337
- try {
338
- const data = yield req;
339
- res({
340
- userId: data.ID
341
- });
342
- }
343
- catch (e) {
344
- rej(e);
345
- }
346
- }));
347
- return prom;
348
- });
349
- }
350
- LoginUser.ForgotPassword = ForgotPassword;
351
- /**
352
- * Completes password reset using a password reset code and new password.
353
- * @param params
354
- * @returns
355
- */
356
- function ForgotPasswordComplete(params) {
357
- return __awaiter(this, void 0, void 0, function* () {
358
- const { api, code, userId, password, req: reqParams } = params;
359
- const { user } = yield Get({
360
- api: api,
361
- userId: userId,
362
- accountId: "",
363
- req: reqParams
364
- });
365
- const res = yield api.POST("UserSetNameAndPassword", {
366
- ID: userId,
367
- Email: user.Email,
368
- ActivationCode: code,
369
- Password: password,
370
- FullName: user.FullName
371
- }, reqParams);
372
- return {
373
- user: res
374
- };
375
- });
376
- }
377
- LoginUser.ForgotPasswordComplete = ForgotPasswordComplete;
378
- })(LoginUser = User.LoginUser || (User.LoginUser = {}));
379
- let AccessToken;
380
- (function (AccessToken) {
381
- function GetListCacheKey(accountId) {
382
- return api_1.Api.ECacheKey.AccessToken + api_1.Api.ECacheKey.Account + api_1.Api.ECacheKey.Id + accountId;
383
- }
384
- AccessToken.GetListCacheKey = GetListCacheKey;
385
- function GetList(params) {
386
- return __awaiter(this, void 0, void 0, function* () {
387
- const { api, accountId, req: reqParams } = params;
388
- const cacheData = api.GetCacheItem(GetListCacheKey(accountId), reqParams);
389
- if (cacheData) {
390
- return cacheData;
391
- }
392
- const req = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
393
- try {
394
- const data = yield api.GET("usersByClientAccount/accessTokens", reqParams);
395
- res({
396
- users: data.Items
397
- });
398
- }
399
- catch (e) {
400
- rej(e);
401
- }
402
- }));
403
- req.then((data) => {
404
- const users = data.tokens;
405
- for (let i = 0; i < users.length; i++) {
406
- api.Cache.Set(GetCacheKey(users[i].ID, accountId), {
407
- user: users[i]
408
- });
409
- }
410
- });
411
- api.Cache.Set(GetListCacheKey(accountId), req, api_1.Api.DEFAULT_CACHE_DURATION);
412
- return req;
413
- });
414
- }
415
- AccessToken.GetList = GetList;
416
- function Delete(params) {
417
- return __awaiter(this, void 0, void 0, function* () {
418
- const { api, tokenId: id, req: reqParams } = params;
419
- yield api.DELETE(`accessToken/${id}`, reqParams);
420
- api.Cache.RemoveByContains(api_1.Api.ECacheKey.User + api_1.Api.ECacheKey.Id + id);
421
- api.Cache.RemoveByStartsWith(api_1.Api.ECacheKey.AccessToken + api_1.Api.ECacheKey.Account);
422
- });
423
- }
424
- AccessToken.Delete = Delete;
425
- function Create(params) {
426
- return __awaiter(this, void 0, void 0, function* () {
427
- let { api, token: data, req: reqParams } = params;
428
- if (!data) {
429
- data = {};
430
- }
431
- if (data.Type == EType.User) {
432
- throw ("User type is not allowed.");
433
- }
434
- if (!data.Type) {
435
- data.Type = EType.AccessToken;
436
- }
437
- data = yield api.POST("accessToken", data, reqParams);
438
- api.Cache.RemoveByStartsWith(api_1.Api.ECacheKey.AccessToken + api_1.Api.ECacheKey.Account);
439
- return {
440
- user: data
441
- };
442
- });
443
- }
444
- AccessToken.Create = Create;
445
- })(AccessToken = User.AccessToken || (User.AccessToken = {}));
446
- })(User = exports.User || (exports.User = {}));
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.User = void 0;
13
+ const api_1 = require("../api/api");
14
+ /**
15
+ * Describes the "User" concept within Bruce.
16
+ * A user is either a login-user or an access-token.
17
+ *
18
+ * You cannot login using an access-token, but both concepts are-
19
+ * treated the same way in terms of permissions and user groups.
20
+ */
21
+ var User;
22
+ (function (User) {
23
+ function GetCacheKey(userId, accountId) {
24
+ if (!accountId) {
25
+ accountId = "";
26
+ }
27
+ return api_1.Api.ECacheKey.User + api_1.Api.ECacheKey.Id + userId + api_1.Api.ECacheKey.Id + accountId;
28
+ }
29
+ User.GetCacheKey = GetCacheKey;
30
+ function GetEmailCacheKey(email, accountId) {
31
+ if (!accountId) {
32
+ accountId = "";
33
+ }
34
+ return api_1.Api.ECacheKey.User + api_1.Api.ECacheKey.UserEmail + email + api_1.Api.ECacheKey.Id + accountId;
35
+ }
36
+ User.GetEmailCacheKey = GetEmailCacheKey;
37
+ function GetSettingsCacheKey(userId, appId) {
38
+ return api_1.Api.ECacheKey.User + api_1.Api.ECacheKey.UserSettings + userId + api_1.Api.ECacheKey.Id + appId;
39
+ }
40
+ User.GetSettingsCacheKey = GetSettingsCacheKey;
41
+ let EType;
42
+ (function (EType) {
43
+ EType["User"] = "LOGIN_USER";
44
+ EType["AccessToken"] = "ACCESS_TOKEN";
45
+ })(EType = User.EType || (User.EType = {}));
46
+ function Get(params) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ const { api, userId: id, accountId, req: reqParams } = params;
49
+ if (!id) {
50
+ throw ("ID is required.");
51
+ }
52
+ const cacheData = api.GetCacheItem(GetCacheKey(id, accountId), reqParams);
53
+ if (cacheData) {
54
+ return cacheData;
55
+ }
56
+ const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
57
+ try {
58
+ const data = yield api.GET(`user/${id}${accountId ? `?clientAccountID=${accountId}` : ""}`, reqParams);
59
+ res({
60
+ user: data
61
+ });
62
+ }
63
+ catch (e) {
64
+ rej(e);
65
+ }
66
+ }));
67
+ api.Cache.Set(GetCacheKey(id, accountId), prom, api_1.Api.DEFAULT_CACHE_DURATION);
68
+ return prom;
69
+ });
70
+ }
71
+ User.Get = Get;
72
+ function Update(params) {
73
+ var _a;
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ const { api, user: data, req: reqParams } = params;
76
+ if (!(data === null || data === void 0 ? void 0 : data.ID) || !(data === null || data === void 0 ? void 0 : data.Type)) {
77
+ throw ("ID and Type are required.");
78
+ }
79
+ // When getting a user it is structured slightly different to when we update it.
80
+ // We can make up the difference here.
81
+ if ((_a = data.AccessPermissions) === null || _a === void 0 ? void 0 : _a.length) {
82
+ for (let i = 0; i < data.AccessPermissions.length; i++) {
83
+ const perm = data.AccessPermissions[i];
84
+ if (!perm["UserGroup.ID"] && perm.UserGroups) {
85
+ perm["UserGroup.ID"] = [];
86
+ for (let j = 0; j < perm.UserGroups.length; j++) {
87
+ perm["UserGroup.ID"].push(perm.UserGroups[j].ID);
88
+ }
89
+ }
90
+ }
91
+ }
92
+ const res = yield api.POST(`user/${data.ID}`, data, reqParams);
93
+ api.Cache.RemoveByContains(api_1.Api.ECacheKey.User + api_1.Api.ECacheKey.Id + data.ID);
94
+ if (data.Type == EType.AccessToken) {
95
+ api.Cache.RemoveByStartsWith(api_1.Api.ECacheKey.AccessToken + api_1.Api.ECacheKey.Account);
96
+ }
97
+ else if (data.Type == EType.User) {
98
+ api.Cache.RemoveByStartsWith(api_1.Api.ECacheKey.User + api_1.Api.ECacheKey.Account);
99
+ }
100
+ return {
101
+ user: res
102
+ };
103
+ });
104
+ }
105
+ User.Update = Update;
106
+ /**
107
+ * Loads settings for a given user + app.
108
+ * The session's account id is used to separate settings between accounts.
109
+ * @param params
110
+ */
111
+ function GetSettings(params) {
112
+ return __awaiter(this, void 0, void 0, function* () {
113
+ const { api, userId, appId, req } = params;
114
+ if (!userId || !appId) {
115
+ throw ("UserId and appId are required.");
116
+ }
117
+ const cacheData = api.GetCacheItem(GetSettingsCacheKey(userId, appId), req);
118
+ if (cacheData) {
119
+ return cacheData;
120
+ }
121
+ const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
122
+ try {
123
+ const data = yield api.GET(`user/${userId}/application/${appId}/settings`);
124
+ const settings = (data === null || data === void 0 ? void 0 : data.Settings) ? data.Settings : {};
125
+ res({
126
+ settings: settings
127
+ });
128
+ }
129
+ catch (e) {
130
+ // It will complain if an app id hasn't been used yet.
131
+ // We need to suppress that error.
132
+ if (e && typeof e == "object") {
133
+ if (e.ERROR && typeof e.ERROR == "object" && e.ERROR.Type == "NotFound") {
134
+ res({
135
+ settings: {}
136
+ });
137
+ return;
138
+ }
139
+ }
140
+ rej(e);
141
+ }
142
+ }));
143
+ api.Cache.Set(GetSettingsCacheKey(userId, appId), prom, api_1.Api.DEFAULT_CACHE_DURATION);
144
+ return prom;
145
+ });
146
+ }
147
+ User.GetSettings = GetSettings;
148
+ /**
149
+ * Updates settings for a given accId + user + app.
150
+ * The settings update will replace the existing record, please ensure to merge with existing settings.
151
+ * @param params
152
+ */
153
+ function UpdateSettings(params) {
154
+ return __awaiter(this, void 0, void 0, function* () {
155
+ const { api, accId, userId, appId, settings, req } = params;
156
+ if (!accId || !userId || !appId) {
157
+ throw ("accId, userId and appId are required.");
158
+ }
159
+ const postBody = {
160
+ Settings: settings == null ? {} : settings,
161
+ Application: appId,
162
+ ClientAccountID: accId,
163
+ UserID: userId
164
+ };
165
+ const prom = api.POST(`user/${userId}/application/${appId}/settings`, postBody, req);
166
+ api.Cache.Remove(GetSettingsCacheKey(userId, appId));
167
+ return prom;
168
+ });
169
+ }
170
+ User.UpdateSettings = UpdateSettings;
171
+ function GetUsernameAvailable(params) {
172
+ return __awaiter(this, void 0, void 0, function* () {
173
+ const { api, username, excludeUserId, req: reqParams } = params;
174
+ if (!username) {
175
+ throw ("Username is required.");
176
+ }
177
+ const req = api.GET(`user/loginavailable/${username}${excludeUserId ? "?excludeUserId=" + excludeUserId : ""}`, reqParams);
178
+ const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
179
+ try {
180
+ const data = yield req;
181
+ res({
182
+ isAvailable: data.IsAvailable
183
+ });
184
+ }
185
+ catch (e) {
186
+ rej(e);
187
+ }
188
+ }));
189
+ return prom;
190
+ });
191
+ }
192
+ User.GetUsernameAvailable = GetUsernameAvailable;
193
+ let LoginUser;
194
+ (function (LoginUser) {
195
+ function GetListCacheKey(accountId) {
196
+ return api_1.Api.ECacheKey.User + api_1.Api.ECacheKey.Account + api_1.Api.ECacheKey.Id + accountId;
197
+ }
198
+ LoginUser.GetListCacheKey = GetListCacheKey;
199
+ function GetByEmail(params) {
200
+ return __awaiter(this, void 0, void 0, function* () {
201
+ const { api, email, accountId, req: reqParams } = params;
202
+ if (!email) {
203
+ throw ("Email is required.");
204
+ }
205
+ const cacheData = api.GetCacheItem(GetEmailCacheKey(email, accountId), reqParams);
206
+ if (cacheData) {
207
+ return cacheData;
208
+ }
209
+ const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
210
+ try {
211
+ const data = yield api.GET(`userByEmail/${email}${accountId ? `?clientAccountID=${accountId}` : ""}`, reqParams);
212
+ res({
213
+ user: data
214
+ });
215
+ }
216
+ catch (e) {
217
+ rej(e);
218
+ }
219
+ }));
220
+ api.Cache.Set(GetEmailCacheKey(email, accountId), prom, api_1.Api.DEFAULT_CACHE_DURATION);
221
+ return prom;
222
+ });
223
+ }
224
+ LoginUser.GetByEmail = GetByEmail;
225
+ function GetList(params) {
226
+ return __awaiter(this, void 0, void 0, function* () {
227
+ let { api, accountId, exclusive, req: reqParams } = params;
228
+ if (!accountId) {
229
+ throw ("Client account ID is required.");
230
+ }
231
+ if (!exclusive) {
232
+ exclusive = false;
233
+ }
234
+ const cacheData = exclusive ? null : api.GetCacheItem(GetListCacheKey(accountId), reqParams);
235
+ if (cacheData) {
236
+ return cacheData;
237
+ }
238
+ const req = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
239
+ try {
240
+ const data = yield api.GET(`users?clientAccountID=${accountId}${exclusive ? "&allExcludingClientAccount=true" : ""}`, reqParams);
241
+ res({
242
+ users: data.Items
243
+ });
244
+ }
245
+ catch (e) {
246
+ rej(e);
247
+ }
248
+ }));
249
+ req.then((data) => {
250
+ const users = data.users;
251
+ for (let i = 0; i < users.length; i++) {
252
+ api.Cache.Set(GetCacheKey(users[i].ID, accountId), {
253
+ user: users[i]
254
+ });
255
+ }
256
+ });
257
+ if (!exclusive) {
258
+ api.Cache.Set(GetListCacheKey(accountId), req, api_1.Api.DEFAULT_CACHE_DURATION);
259
+ }
260
+ return req;
261
+ });
262
+ }
263
+ LoginUser.GetList = GetList;
264
+ /**
265
+ * Sends a signup email to the specified email address.
266
+ * @param params
267
+ * @returns
268
+ */
269
+ function Signup(params) {
270
+ return __awaiter(this, void 0, void 0, function* () {
271
+ const { api, email, req: reqParams } = params;
272
+ if (!email) {
273
+ throw ("Email is required.");
274
+ }
275
+ return api.POST("clientaccount/signup", {
276
+ Email: email
277
+ }, reqParams);
278
+ });
279
+ }
280
+ LoginUser.Signup = Signup;
281
+ /**
282
+ * Sends a new signup email using a previous one's expired code.
283
+ * @param params
284
+ * @returns
285
+ */
286
+ function SignupResend(params) {
287
+ return __awaiter(this, void 0, void 0, function* () {
288
+ const { api, expiredCode, req: reqParams } = params;
289
+ if (!expiredCode) {
290
+ throw ("Expired activation code is required.");
291
+ }
292
+ return api.POST(`clientaccount/signup/resend?activationKey=${api_1.Api.Encode(expiredCode)}`, null, reqParams);
293
+ });
294
+ }
295
+ LoginUser.SignupResend = SignupResend;
296
+ /**
297
+ * Completes signup using user data and a signup code.
298
+ * @param params
299
+ * @returns
300
+ */
301
+ function SignupComplete(params) {
302
+ return __awaiter(this, void 0, void 0, function* () {
303
+ let { api, code, user: data, accountId, req: reqParams } = params;
304
+ if (!code || !(data === null || data === void 0 ? void 0 : data.Login) || !(data === null || data === void 0 ? void 0 : data.Password)) {
305
+ throw ("Login, password, and activation code are required.");
306
+ }
307
+ data = JSON.parse(JSON.stringify(data));
308
+ data.IsActivated = true;
309
+ data.IsDisabled = false;
310
+ data.key = code;
311
+ const res = yield api.POST(`UserActivate/${accountId ? accountId : ""}`, data, reqParams);
312
+ api.Cache.RemoveByContains(api_1.Api.ECacheKey.User + api_1.Api.ECacheKey.Id + res.ID);
313
+ if (data.Email) {
314
+ api.Cache.RemoveByContains(api_1.Api.ECacheKey.User + api_1.Api.ECacheKey.UserEmail + data.Email);
315
+ }
316
+ return {
317
+ user: res
318
+ };
319
+ });
320
+ }
321
+ LoginUser.SignupComplete = SignupComplete;
322
+ /**
323
+ * Sends a password reset email to the specified email address.
324
+ * @param params
325
+ * @returns user id associated with provided email.
326
+ */
327
+ function ForgotPassword(params) {
328
+ return __awaiter(this, void 0, void 0, function* () {
329
+ const { api, accountId, email, req: reqParams } = params;
330
+ if (!accountId || !email) {
331
+ throw ("Account ID and email are required.");
332
+ }
333
+ const req = api.POST(`UserForgotPassword/${accountId}`, {
334
+ Email: email
335
+ }, reqParams);
336
+ const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
337
+ try {
338
+ const data = yield req;
339
+ res({
340
+ userId: data.ID
341
+ });
342
+ }
343
+ catch (e) {
344
+ rej(e);
345
+ }
346
+ }));
347
+ return prom;
348
+ });
349
+ }
350
+ LoginUser.ForgotPassword = ForgotPassword;
351
+ /**
352
+ * Completes password reset using a password reset code and new password.
353
+ * @param params
354
+ * @returns
355
+ */
356
+ function ForgotPasswordComplete(params) {
357
+ return __awaiter(this, void 0, void 0, function* () {
358
+ const { api, code, userId, password, req: reqParams } = params;
359
+ const { user } = yield Get({
360
+ api: api,
361
+ userId: userId,
362
+ accountId: "",
363
+ req: reqParams
364
+ });
365
+ const res = yield api.POST("UserSetNameAndPassword", {
366
+ ID: userId,
367
+ Email: user.Email,
368
+ ActivationCode: code,
369
+ Password: password,
370
+ FullName: user.FullName
371
+ }, reqParams);
372
+ return {
373
+ user: res
374
+ };
375
+ });
376
+ }
377
+ LoginUser.ForgotPasswordComplete = ForgotPasswordComplete;
378
+ })(LoginUser = User.LoginUser || (User.LoginUser = {}));
379
+ let AccessToken;
380
+ (function (AccessToken) {
381
+ function GetListCacheKey(accountId) {
382
+ return api_1.Api.ECacheKey.AccessToken + api_1.Api.ECacheKey.Account + api_1.Api.ECacheKey.Id + accountId;
383
+ }
384
+ AccessToken.GetListCacheKey = GetListCacheKey;
385
+ function GetList(params) {
386
+ return __awaiter(this, void 0, void 0, function* () {
387
+ const { api, accountId, req: reqParams } = params;
388
+ const cacheData = api.GetCacheItem(GetListCacheKey(accountId), reqParams);
389
+ if (cacheData) {
390
+ return cacheData;
391
+ }
392
+ const req = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
393
+ try {
394
+ const data = yield api.GET("usersByClientAccount/accessTokens", reqParams);
395
+ res({
396
+ users: data.Items
397
+ });
398
+ }
399
+ catch (e) {
400
+ rej(e);
401
+ }
402
+ }));
403
+ req.then((data) => {
404
+ const users = data.tokens;
405
+ for (let i = 0; i < users.length; i++) {
406
+ api.Cache.Set(GetCacheKey(users[i].ID, accountId), {
407
+ user: users[i]
408
+ });
409
+ }
410
+ });
411
+ api.Cache.Set(GetListCacheKey(accountId), req, api_1.Api.DEFAULT_CACHE_DURATION);
412
+ return req;
413
+ });
414
+ }
415
+ AccessToken.GetList = GetList;
416
+ function Delete(params) {
417
+ return __awaiter(this, void 0, void 0, function* () {
418
+ const { api, tokenId: id, req: reqParams } = params;
419
+ yield api.DELETE(`accessToken/${id}`, reqParams);
420
+ api.Cache.RemoveByContains(api_1.Api.ECacheKey.User + api_1.Api.ECacheKey.Id + id);
421
+ api.Cache.RemoveByStartsWith(api_1.Api.ECacheKey.AccessToken + api_1.Api.ECacheKey.Account);
422
+ });
423
+ }
424
+ AccessToken.Delete = Delete;
425
+ function Create(params) {
426
+ return __awaiter(this, void 0, void 0, function* () {
427
+ let { api, token: data, req: reqParams } = params;
428
+ if (!data) {
429
+ data = {};
430
+ }
431
+ if (data.Type == EType.User) {
432
+ throw ("User type is not allowed.");
433
+ }
434
+ if (!data.Type) {
435
+ data.Type = EType.AccessToken;
436
+ }
437
+ data = yield api.POST("accessToken", data, reqParams);
438
+ api.Cache.RemoveByStartsWith(api_1.Api.ECacheKey.AccessToken + api_1.Api.ECacheKey.Account);
439
+ return {
440
+ user: data
441
+ };
442
+ });
443
+ }
444
+ AccessToken.Create = Create;
445
+ })(AccessToken = User.AccessToken || (User.AccessToken = {}));
446
+ })(User = exports.User || (exports.User = {}));
447
447
  //# sourceMappingURL=user.js.map