bruce-models 0.1.7 → 0.1.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.
@@ -5056,6 +5056,39 @@ var User;
5056
5056
  });
5057
5057
  }
5058
5058
  User.Update = Update;
5059
+ function GetUsernameAvailable(api, username) {
5060
+ return __awaiter(this, void 0, void 0, function () {
5061
+ var req, prom;
5062
+ var _this = this;
5063
+ return __generator(this, function (_a) {
5064
+ if (!username) {
5065
+ throw ("Username is required.");
5066
+ }
5067
+ req = api.GET("user/loginavailable/" + username);
5068
+ prom = new Promise(function (rej, res) { return __awaiter(_this, void 0, void 0, function () {
5069
+ var data, e_1;
5070
+ return __generator(this, function (_a) {
5071
+ switch (_a.label) {
5072
+ case 0:
5073
+ _a.trys.push([0, 2, , 3]);
5074
+ return [4 /*yield*/, req];
5075
+ case 1:
5076
+ data = _a.sent();
5077
+ res(data.IsAvailable);
5078
+ return [3 /*break*/, 3];
5079
+ case 2:
5080
+ e_1 = _a.sent();
5081
+ rej(e_1);
5082
+ return [3 /*break*/, 3];
5083
+ case 3: return [2 /*return*/];
5084
+ }
5085
+ });
5086
+ }); });
5087
+ return [2 /*return*/, prom];
5088
+ });
5089
+ });
5090
+ }
5091
+ User.GetUsernameAvailable = GetUsernameAvailable;
5059
5092
  var LoginUser;
5060
5093
  (function (LoginUser) {
5061
5094
  function GetListCacheKey(accountId) {
@@ -5078,7 +5111,7 @@ var User;
5078
5111
  return [2 /*return*/, cacheData];
5079
5112
  }
5080
5113
  req = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
5081
- var data, e_1;
5114
+ var data, e_2;
5082
5115
  return __generator(this, function (_a) {
5083
5116
  switch (_a.label) {
5084
5117
  case 0:
@@ -5089,8 +5122,8 @@ var User;
5089
5122
  res(data.Items);
5090
5123
  return [3 /*break*/, 3];
5091
5124
  case 2:
5092
- e_1 = _a.sent();
5093
- rej(e_1);
5125
+ e_2 = _a.sent();
5126
+ rej(e_2);
5094
5127
  return [3 /*break*/, 3];
5095
5128
  case 3: return [2 /*return*/];
5096
5129
  }
@@ -5109,6 +5142,146 @@ var User;
5109
5142
  });
5110
5143
  }
5111
5144
  LoginUser.GetList = GetList;
5145
+ /**
5146
+ * Sends a signup email to the specified email address.
5147
+ * @param api
5148
+ * @param email
5149
+ * @returns
5150
+ */
5151
+ function Signup(api, email) {
5152
+ return __awaiter(this, void 0, void 0, function () {
5153
+ return __generator(this, function (_a) {
5154
+ if (!email) {
5155
+ throw ("Email is required.");
5156
+ }
5157
+ return [2 /*return*/, api.POST("clientaccount/signup", {
5158
+ Email: email
5159
+ })];
5160
+ });
5161
+ });
5162
+ }
5163
+ LoginUser.Signup = Signup;
5164
+ /**
5165
+ * Sends a new signup email using a previous one's expired code.
5166
+ * @param api
5167
+ * @param expiredCode
5168
+ * @returns
5169
+ */
5170
+ function SignupResend(api, expiredCode) {
5171
+ return __awaiter(this, void 0, void 0, function () {
5172
+ return __generator(this, function (_a) {
5173
+ if (!expiredCode) {
5174
+ throw ("Expired activation code is required.");
5175
+ }
5176
+ return [2 /*return*/, api.POST("clientaccount/signup/resend?activationKey=" + Api.Encode(expiredCode), null)];
5177
+ });
5178
+ });
5179
+ }
5180
+ LoginUser.SignupResend = SignupResend;
5181
+ /**
5182
+ * Completes signup using user data and a signup code.
5183
+ * @param api
5184
+ * @param accountId
5185
+ * @param code
5186
+ * @param data
5187
+ * @returns
5188
+ */
5189
+ function SignupComplete(api, accountId, code, data) {
5190
+ return __awaiter(this, void 0, void 0, function () {
5191
+ var res;
5192
+ return __generator(this, function (_a) {
5193
+ switch (_a.label) {
5194
+ case 0:
5195
+ if (!code || !accountId) {
5196
+ throw ("Activation code and account ID are required.");
5197
+ }
5198
+ if (!(data === null || data === void 0 ? void 0 : data.Login) || !(data === null || data === void 0 ? void 0 : data.Password)) {
5199
+ throw ("Login and password are required.");
5200
+ }
5201
+ data = JSON.parse(JSON.stringify(data));
5202
+ data.IsActivated = true;
5203
+ data.IsDisabled = false;
5204
+ data.key = code;
5205
+ return [4 /*yield*/, api.POST("UserActivate/" + accountId, data)];
5206
+ case 1:
5207
+ res = _a.sent();
5208
+ api.Cache.RemoveByContains(Api.ECacheKey.User + Api.ECacheKey.Id + res.ID);
5209
+ return [2 /*return*/, res];
5210
+ }
5211
+ });
5212
+ });
5213
+ }
5214
+ LoginUser.SignupComplete = SignupComplete;
5215
+ /**
5216
+ * Sends a password reset email to the specified email address.
5217
+ * @param api
5218
+ * @param accountId
5219
+ * @param email
5220
+ * @returns user id associated with provided email.
5221
+ */
5222
+ function ForgotPassword(api, accountId, email) {
5223
+ return __awaiter(this, void 0, void 0, function () {
5224
+ var req, prom;
5225
+ var _this = this;
5226
+ return __generator(this, function (_a) {
5227
+ if (!accountId || !email) {
5228
+ throw ("Account ID and email are required.");
5229
+ }
5230
+ req = api.POST("UserForgotPassword/" + accountId, {
5231
+ Email: email
5232
+ });
5233
+ prom = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
5234
+ var data, e_3;
5235
+ return __generator(this, function (_a) {
5236
+ switch (_a.label) {
5237
+ case 0:
5238
+ _a.trys.push([0, 2, , 3]);
5239
+ return [4 /*yield*/, req];
5240
+ case 1:
5241
+ data = _a.sent();
5242
+ res(data.ID);
5243
+ return [3 /*break*/, 3];
5244
+ case 2:
5245
+ e_3 = _a.sent();
5246
+ rej(e_3);
5247
+ return [3 /*break*/, 3];
5248
+ case 3: return [2 /*return*/];
5249
+ }
5250
+ });
5251
+ }); });
5252
+ return [2 /*return*/, prom];
5253
+ });
5254
+ });
5255
+ }
5256
+ LoginUser.ForgotPassword = ForgotPassword;
5257
+ /**
5258
+ * Completes password reset using a password reset code and new password.
5259
+ * @param api
5260
+ * @param code
5261
+ * @param userId
5262
+ * @param password
5263
+ * @returns
5264
+ */
5265
+ function ForgotPasswordComplete(api, code, userId, password) {
5266
+ return __awaiter(this, void 0, void 0, function () {
5267
+ var user;
5268
+ return __generator(this, function (_a) {
5269
+ switch (_a.label) {
5270
+ case 0: return [4 /*yield*/, Get(api, userId, "")];
5271
+ case 1:
5272
+ user = _a.sent();
5273
+ return [2 /*return*/, api.POST("UserSetNameAndPassword", {
5274
+ ID: userId,
5275
+ Email: user.Email,
5276
+ ActivationCode: code,
5277
+ Password: password,
5278
+ FullName: user.FullName
5279
+ })];
5280
+ }
5281
+ });
5282
+ });
5283
+ }
5284
+ LoginUser.ForgotPasswordComplete = ForgotPasswordComplete;
5112
5285
  })(LoginUser = User.LoginUser || (User.LoginUser = {}));
5113
5286
  var AccessToken;
5114
5287
  (function (AccessToken) {
@@ -5126,7 +5299,7 @@ var User;
5126
5299
  return [2 /*return*/, cacheData];
5127
5300
  }
5128
5301
  req = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
5129
- var data, e_2;
5302
+ var data, e_4;
5130
5303
  return __generator(this, function (_a) {
5131
5304
  switch (_a.label) {
5132
5305
  case 0:
@@ -5137,8 +5310,8 @@ var User;
5137
5310
  res(data.Items);
5138
5311
  return [3 /*break*/, 3];
5139
5312
  case 2:
5140
- e_2 = _a.sent();
5141
- rej(e_2);
5313
+ e_4 = _a.sent();
5314
+ rej(e_4);
5142
5315
  return [3 /*break*/, 3];
5143
5316
  case 3: return [2 /*return*/];
5144
5317
  }
@@ -5359,5 +5532,178 @@ var UrlUtils;
5359
5532
  UrlUtils.Handler = Handler;
5360
5533
  })(UrlUtils || (UrlUtils = {}));
5361
5534
 
5362
- export { AnnDocument, CustomForm, AbstractApi, Api, BruceApi, CamApi, IdmApi, Calculator, BruceEvent, CacheControl, Camera, Cartes, Carto, Color, DelayQueue, Geometry, UTC, EntityAttachmentType, EntityAttachment, EntityComment, EntityLink, EntityLod, EntityRelationType, EntityRelation, EntitySource, EntityTag, EntityType, Entity, EntityGlobe, EntityFilterGetter, BatchedDataGetter, ClientFile, ProgramKey, ZoomControl, MenuItem, ProjectViewBookmark, ProjectView, PendingAction, Style, TilesetEntitiesMapTiles, TilesetExtMapTiles, Tileset, Ucs, Permission, Session, UserGroup, User, EncryptUtils, MathUtils, ObjectUtils, PathUtils, UrlUtils };
5535
+ var ACCOUNT_EXCLUSIONS = ["hyperportal", "hypeportal", "bviewer"];
5536
+ /**
5537
+ * Describes the "Client Account" concept within Bruce.
5538
+ * A client account is a database instance that holds one or many users.
5539
+ */
5540
+ var Account;
5541
+ (function (Account$$1) {
5542
+ function GetCacheKey(accountId, appSettingsId) {
5543
+ if (appSettingsId) {
5544
+ return Api.ECacheKey.Account + Api.ECacheKey.Id + accountId + Api.ECacheKey + appSettingsId;
5545
+ }
5546
+ return Api.ECacheKey.Account + Api.ECacheKey.Id + accountId;
5547
+ }
5548
+ Account$$1.GetCacheKey = GetCacheKey;
5549
+ function GetListCacheKey(ssid) {
5550
+ return Api.ECacheKey.Account + Api.ECacheKey.Session + Api.ECacheKey.Id + ssid;
5551
+ }
5552
+ Account$$1.GetListCacheKey = GetListCacheKey;
5553
+ var EDbRegion;
5554
+ (function (EDbRegion) {
5555
+ EDbRegion["USA"] = "US";
5556
+ EDbRegion["Paris"] = "EU";
5557
+ EDbRegion["Singapore"] = "SE";
5558
+ EDbRegion["Australia"] = "AU";
5559
+ })(EDbRegion || (EDbRegion = {}));
5560
+ function Get(api, id) {
5561
+ return __awaiter(this, void 0, void 0, function () {
5562
+ var cacheData, req;
5563
+ return __generator(this, function (_a) {
5564
+ switch (_a.label) {
5565
+ case 0:
5566
+ cacheData = api.Cache.Get(GetCacheKey(id));
5567
+ if (cacheData) {
5568
+ return [2 /*return*/, cacheData];
5569
+ }
5570
+ return [4 /*yield*/, api.GET("account/" + id)];
5571
+ case 1:
5572
+ req = _a.sent();
5573
+ api.Cache.Set(GetCacheKey(id), req, Api.DEFAULT_CACHE_DURATION);
5574
+ return [2 /*return*/, req];
5575
+ }
5576
+ });
5577
+ });
5578
+ }
5579
+ Account$$1.Get = Get;
5580
+ function GetRelatedList(api) {
5581
+ return __awaiter(this, void 0, void 0, function () {
5582
+ var cacheData, req, prom;
5583
+ var _this = this;
5584
+ return __generator(this, function (_a) {
5585
+ cacheData = api.Cache.Get(GetListCacheKey(api.GetSessionId()));
5586
+ if (cacheData) {
5587
+ return [2 /*return*/, cacheData];
5588
+ }
5589
+ req = api.GET("user/relatedClientAccounts");
5590
+ prom = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
5591
+ var data, items, e_1;
5592
+ return __generator(this, function (_a) {
5593
+ switch (_a.label) {
5594
+ case 0:
5595
+ _a.trys.push([0, 2, , 3]);
5596
+ return [4 /*yield*/, req];
5597
+ case 1:
5598
+ data = _a.sent();
5599
+ items = data.Items.filter(function (x) { return !ACCOUNT_EXCLUSIONS.includes(x.ID); });
5600
+ res(items);
5601
+ return [3 /*break*/, 3];
5602
+ case 2:
5603
+ e_1 = _a.sent();
5604
+ rej(e_1);
5605
+ return [3 /*break*/, 3];
5606
+ case 3: return [2 /*return*/];
5607
+ }
5608
+ });
5609
+ }); });
5610
+ api.Cache.Set(GetListCacheKey(api.GetSessionId()), prom, Api.DEFAULT_CACHE_DURATION);
5611
+ return [2 /*return*/, prom];
5612
+ });
5613
+ });
5614
+ }
5615
+ Account$$1.GetRelatedList = GetRelatedList;
5616
+ function GetAppSettings(api, id, appId) {
5617
+ return __awaiter(this, void 0, void 0, function () {
5618
+ var cacheData, req, prom;
5619
+ var _this = this;
5620
+ return __generator(this, function (_a) {
5621
+ switch (_a.label) {
5622
+ case 0:
5623
+ cacheData = api.Cache.Get(GetCacheKey(id, appId));
5624
+ if (cacheData) {
5625
+ return [2 /*return*/, cacheData];
5626
+ }
5627
+ return [4 /*yield*/, api.GET("account/" + id + "?ApplicationID=" + appId)];
5628
+ case 1:
5629
+ req = _a.sent();
5630
+ prom = new Promise(function (res, rej) { return __awaiter(_this, void 0, void 0, function () {
5631
+ var data, settings, e_2;
5632
+ var _a;
5633
+ return __generator(this, function (_b) {
5634
+ switch (_b.label) {
5635
+ case 0:
5636
+ _b.trys.push([0, 2, , 3]);
5637
+ return [4 /*yield*/, req];
5638
+ case 1:
5639
+ data = _b.sent();
5640
+ settings = (_a = data === null || data === void 0 ? void 0 : data["Application.Settings"]) !== null && _a !== void 0 ? _a : {};
5641
+ res(settings);
5642
+ return [3 /*break*/, 3];
5643
+ case 2:
5644
+ e_2 = _b.sent();
5645
+ rej(e_2);
5646
+ return [3 /*break*/, 3];
5647
+ case 3: return [2 /*return*/];
5648
+ }
5649
+ });
5650
+ }); });
5651
+ api.Cache.Set(GetCacheKey(id, appId), prom, Api.DEFAULT_CACHE_DURATION);
5652
+ return [2 /*return*/, prom];
5653
+ }
5654
+ });
5655
+ });
5656
+ }
5657
+ Account$$1.GetAppSettings = GetAppSettings;
5658
+ /**
5659
+ * WARNING: Do not update API settings without knowing what you're doing.
5660
+ * @param api
5661
+ * @param id
5662
+ * @param appId
5663
+ * @param data
5664
+ * @returns
5665
+ */
5666
+ function UpdateAppSettings(api, id, appId, data) {
5667
+ return __awaiter(this, void 0, void 0, function () {
5668
+ return __generator(this, function (_a) {
5669
+ switch (_a.label) {
5670
+ case 0: return [4 /*yield*/, api.POST("account/" + id + "/applicationSettings/" + appId, data)];
5671
+ case 1:
5672
+ data = _a.sent();
5673
+ api.Cache.RemoveByStartsWith(Api.ECacheKey.Account + Api.ECacheKey.Id + id);
5674
+ return [2 /*return*/, data];
5675
+ }
5676
+ });
5677
+ });
5678
+ }
5679
+ Account$$1.UpdateAppSettings = UpdateAppSettings;
5680
+ /**
5681
+ * Creates a new Bruce account using given details.
5682
+ * @param api
5683
+ * @param id
5684
+ * @param name
5685
+ * @param region
5686
+ * @returns
5687
+ */
5688
+ function Create(api, id, name, region) {
5689
+ return __awaiter(this, void 0, void 0, function () {
5690
+ var reqData, res;
5691
+ return __generator(this, function (_a) {
5692
+ if (!id || !name || !region) {
5693
+ throw new Error("Id, Name and Region are required.");
5694
+ }
5695
+ reqData = {
5696
+ "Name": name,
5697
+ "DBLocation": region
5698
+ };
5699
+ res = api.POST("clientAccount/" + id, reqData);
5700
+ api.Cache.Remove(GetListCacheKey(api.GetSessionId()));
5701
+ return [2 /*return*/, res];
5702
+ });
5703
+ });
5704
+ }
5705
+ Account$$1.Create = Create;
5706
+ })(Account || (Account = {}));
5707
+
5708
+ export { AnnDocument, CustomForm, AbstractApi, Api, BruceApi, CamApi, IdmApi, Calculator, BruceEvent, CacheControl, Camera, Cartes, Carto, Color, DelayQueue, Geometry, UTC, EntityAttachmentType, EntityAttachment, EntityComment, EntityLink, EntityLod, EntityRelationType, EntityRelation, EntitySource, EntityTag, EntityType, Entity, EntityGlobe, EntityFilterGetter, BatchedDataGetter, ClientFile, ProgramKey, ZoomControl, MenuItem, ProjectViewBookmark, ProjectView, PendingAction, Style, TilesetEntitiesMapTiles, TilesetExtMapTiles, Tileset, Ucs, Permission, Session, UserGroup, User, Account, EncryptUtils, MathUtils, ObjectUtils, PathUtils, UrlUtils };
5363
5709
  //# sourceMappingURL=bruce-models.es5.js.map