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