bruce-models 4.1.5 → 4.1.6

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.
@@ -84,6 +84,7 @@
84
84
  ECacheKey["EntityHistoricData"] = "entityhistoricdata";
85
85
  ECacheKey["EntityHistoricDataRec"] = "entityhistoricdatarec";
86
86
  ECacheKey["EntityHistoricDataStats"] = "entityhistoricdatastats";
87
+ ECacheKey["AccountLimits"] = "accountlimits";
87
88
  })(ECacheKey = Api.ECacheKey || (Api.ECacheKey = {}));
88
89
  // 1 minute.
89
90
  Api.DEFAULT_CACHE_DURATION = 60 * 1000;
@@ -1994,9 +1995,6 @@
1994
1995
  if (ENVIRONMENT.IS_SELF_MANAGED) {
1995
1996
  throw ("Self managed mode ON. You are getting this error because you didn't pass an Api instance to a function.");
1996
1997
  }
1997
- if (!ENVIRONMENT.PARAMS.accountId) {
1998
- console.warn("No accountId set. This is required for the getters to work properly.");
1999
- }
2000
1998
  if (!_getters) {
2001
1999
  _getters = new ApiGetters({
2002
2000
  accountId: ENVIRONMENT.PARAMS.accountId,
@@ -2941,7 +2939,7 @@
2941
2939
  * @returns
2942
2940
  */
2943
2941
  function Parse(str) {
2944
- if (!str) {
2942
+ if (!(str === null || str === void 0 ? void 0 : str.length)) {
2945
2943
  return [];
2946
2944
  }
2947
2945
  const broken = str.split("\"/\"");
@@ -2971,6 +2969,9 @@
2971
2969
  * @returns
2972
2970
  */
2973
2971
  function Wrap(path) {
2972
+ if (!(path === null || path === void 0 ? void 0 : path.length)) {
2973
+ return "";
2974
+ }
2974
2975
  let tmp = "\"";
2975
2976
  for (let i = 0; i < path.length; i++) {
2976
2977
  let section = path[i];
@@ -2989,6 +2990,9 @@
2989
2990
  * @returns
2990
2991
  */
2991
2992
  function ParseLegacy(str) {
2993
+ if (!(str === null || str === void 0 ? void 0 : str.length)) {
2994
+ return [];
2995
+ }
2992
2996
  const broken = str.split(".");
2993
2997
  for (let i = 0; i < broken.length; i++) {
2994
2998
  let piece = broken[0];
@@ -4860,22 +4864,123 @@
4860
4864
  EMonth[EMonth["November"] = 11] = "November";
4861
4865
  EMonth[EMonth["December"] = 12] = "December";
4862
4866
  })(EMonth = UTC.EMonth || (UTC.EMonth = {}));
4867
+ /**
4868
+ * Returns an ISO 8601 string representation of the provided date.
4869
+ * @param utc
4870
+ */
4871
+ function ToString(utc) {
4872
+ return ToDate(utc).toISOString();
4873
+ }
4874
+ UTC.ToString = ToString;
4863
4875
  function ToDate(utc) {
4864
- return new Date(utc.y, utc.m - 1, utc.d, utc.hh, utc.mm, utc.ss, 0);
4876
+ return new Date(Date.UTC(utc.y, utc.m - 1, utc.d, utc.hh, utc.mm, utc.ss, 0));
4865
4877
  }
4866
4878
  UTC.ToDate = ToDate;
4867
- function FromDate(date) {
4879
+ function FromDate(utc) {
4868
4880
  return {
4869
- y: date.getUTCFullYear(),
4870
- m: date.getUTCMonth() + 1,
4871
- d: date.getUTCDate(),
4872
- hh: date.getUTCHours(),
4873
- mm: date.getUTCMinutes(),
4874
- ss: date.getUTCSeconds()
4881
+ y: utc.getUTCFullYear(),
4882
+ m: utc.getUTCMonth() + 1,
4883
+ d: utc.getUTCDate(),
4884
+ hh: utc.getUTCHours(),
4885
+ mm: utc.getUTCMinutes(),
4886
+ ss: utc.getUTCSeconds()
4875
4887
  };
4876
4888
  }
4877
4889
  UTC.FromDate = FromDate;
4890
+ /**
4891
+ * Returns how many seconds have passed between two dates.
4892
+ * If the second date is not provided, it will be the current date.
4893
+ * @param from
4894
+ * @param to
4895
+ * @returns
4896
+ */
4897
+ function GetPassedSeconds(from, to) {
4898
+ if (!to) {
4899
+ to = FromDate(new Date());
4900
+ }
4901
+ const fromTime = ToDate(from).getTime();
4902
+ const toTime = ToDate(to).getTime();
4903
+ return Math.floor((toTime - fromTime) / 1000);
4904
+ }
4905
+ UTC.GetPassedSeconds = GetPassedSeconds;
4906
+ /**
4907
+ * Returns a human-readable string that describes how much time has passed since the provided date.
4908
+ * @param utc
4909
+ */
4910
+ function GetPassedTime(utc) {
4911
+ const passedSeconds = GetPassedSeconds(utc);
4912
+ if (passedSeconds < 60) {
4913
+ return `${passedSeconds} second${passedSeconds > 1 ? "s" : ""} ago`;
4914
+ }
4915
+ const passedMinutes = Math.floor(passedSeconds / 60);
4916
+ if (passedMinutes < 60) {
4917
+ return `${passedMinutes} minute${passedMinutes > 1 ? "s" : ""} ago`;
4918
+ }
4919
+ const passedHours = Math.floor(passedMinutes / 60);
4920
+ if (passedHours < 24) {
4921
+ return `${passedHours} hour${passedHours > 1 ? "s" : ""} ago`;
4922
+ }
4923
+ const passedDays = Math.floor(passedHours / 24);
4924
+ if (passedDays < 30) {
4925
+ return `${passedDays} day${passedDays > 1 ? "s" : ""} ago`;
4926
+ }
4927
+ const passedMonths = Math.floor(passedDays / 30);
4928
+ if (passedMonths < 12) {
4929
+ return `${passedMonths} month${passedMonths > 1 ? "s" : ""} ago`;
4930
+ }
4931
+ const passedYears = Math.floor(passedMonths / 12);
4932
+ return `${passedYears} year${passedYears > 1 ? "s" : ""} ago`;
4933
+ }
4934
+ UTC.GetPassedTime = GetPassedTime;
4935
+ /**
4936
+ * Returns a human-readable string that describes the provided date.
4937
+ * If a timezone is not provided then it will use the locale timezone.
4938
+ * @param utc
4939
+ * @param timezone
4940
+ */
4941
+ function GetDateTime(utc, timezone) {
4942
+ const date = ToDate(utc);
4943
+ // Possibly could just pass the timezone and it might get ignored if missing.
4944
+ if (timezone) {
4945
+ return date.toLocaleString("en-US", {
4946
+ timeZone: timezone,
4947
+ hour12: true,
4948
+ hour: "numeric",
4949
+ minute: "numeric",
4950
+ year: "2-digit",
4951
+ month: "2-digit",
4952
+ day: "2-digit"
4953
+ }) + " " + getTimezoneName(timezone);
4954
+ }
4955
+ return date.toLocaleString(undefined, {
4956
+ hour12: true,
4957
+ hour: "numeric",
4958
+ minute: "numeric",
4959
+ year: "2-digit",
4960
+ month: "2-digit",
4961
+ day: "2-digit"
4962
+ });
4963
+ }
4964
+ UTC.GetDateTime = GetDateTime;
4878
4965
  })(exports.UTC || (exports.UTC = {}));
4966
+ // Found here https://stackoverflow.com/questions/9772955/how-can-i-get-the-timezone-name-in-javascript
4967
+ // Formats a given timezone into a human readable format.
4968
+ function getTimezoneName(timezone) {
4969
+ const today = new Date();
4970
+ const short = today.toLocaleDateString(undefined, { timeZone: timezone });
4971
+ const full = today.toLocaleDateString(undefined, { timeZoneName: "long", timeZone: timezone });
4972
+ // Trying to remove date from the string in a locale-agnostic way
4973
+ const shortIndex = full.indexOf(short);
4974
+ if (shortIndex >= 0) {
4975
+ const trimmed = full.substring(0, shortIndex) + full.substring(shortIndex + short.length);
4976
+ // by this time `trimmed` should be the timezone's name with some punctuation -
4977
+ // trim it from both sides
4978
+ return trimmed.replace(/^[\s,.\-:;]+|[\s,.\-:;]+$/g, "");
4979
+ }
4980
+ // in some magic case when short representation of date is not present in the long one,
4981
+ // just return the long one as a fallback, since it should contain the timezone's name
4982
+ return full;
4983
+ }
4879
4984
 
4880
4985
  /**
4881
4986
  * A simple LRU cache implementation.
@@ -6894,7 +6999,7 @@
6894
6999
  * @param path
6895
7000
  */
6896
7001
  function RemoveAttribute(items, path) {
6897
- if (!items || !path || !path.length) {
7002
+ if (!items || !(path === null || path === void 0 ? void 0 : path.length)) {
6898
7003
  return;
6899
7004
  }
6900
7005
  const key = path[0];
@@ -6923,6 +7028,9 @@
6923
7028
  * @param attribute
6924
7029
  */
6925
7030
  function AddAttribute(items, path, attribute) {
7031
+ if (!items || !(path === null || path === void 0 ? void 0 : path.length)) {
7032
+ return;
7033
+ }
6926
7034
  const key = path[0];
6927
7035
  if (path.length === 1) {
6928
7036
  // If we're at the last key in the path, add the attribute to the items array.
@@ -6951,150 +7059,87 @@
6951
7059
  EntityAttribute.AddAttribute = AddAttribute;
6952
7060
  })(exports.EntityAttribute || (exports.EntityAttribute = {}));
6953
7061
 
6954
- (function (Uploader) {
6955
- Uploader.MIN_LARGE_FILE_SIZE = 100000000; // 100MB.
7062
+ (function (Style) {
6956
7063
  /**
6957
- * Uploads a file to the server.
7064
+ * Types of styles available.
7065
+ * The type will dictate what settings are available.
7066
+ */
7067
+ let EType;
7068
+ (function (EType) {
7069
+ EType["Entity"] = "ENTITY";
7070
+ EType["EntityRelationship"] = "ENTITY_RELATIONSHIP";
7071
+ })(EType = Style.EType || (Style.EType = {}));
7072
+ /**
7073
+ * Available types of points.
7074
+ * Default is POINT.
7075
+ */
7076
+ let EPointType;
7077
+ (function (EPointType) {
7078
+ // Render a sphere with a fixed pixel size.
7079
+ EPointType["Point"] = "POINT";
7080
+ // Render an icon.
7081
+ EPointType["Icon"] = "ICON";
7082
+ // Render a cylinder with a fixed meter size.
7083
+ EPointType["Cylinder"] = "CYLINDER";
7084
+ })(EPointType = Style.EPointType || (Style.EPointType = {}));
7085
+ /**
7086
+ * Returns a list of styles.
6958
7087
  * @param params
6959
7088
  * @returns
6960
7089
  */
6961
- function DoMultiPartUpload(params) {
7090
+ function GetList(params) {
6962
7091
  return __awaiter(this, void 0, void 0, function* () {
6963
- let { file, api, urlSuffix: url, req, onProgress } = params;
7092
+ let { api, req: reqParams } = params;
6964
7093
  if (!api) {
6965
7094
  api = exports.ENVIRONMENT.Api().GetBruceApi();
6966
7095
  }
6967
- const FILE_PORTION_SIZE = 100000000; // 100MB.
6968
- let fileSize = file.size;
6969
- let fileOffset = 0;
6970
- let filePartsCount = fileSize / FILE_PORTION_SIZE;
6971
- let t = Math.trunc(filePartsCount);
6972
- filePartsCount = filePartsCount > t ? t + 1 : t;
6973
- let filePartIndex = 1;
6974
- let uploadToken = exports.ObjectUtils.UId();
6975
- let data;
6976
- while (fileOffset < fileSize) {
6977
- let partSize = Math.min(FILE_PORTION_SIZE, fileSize - fileOffset);
6978
- let retryCount = 5;
6979
- let retryWait = 1000;
6980
- while (retryCount > 0) {
6981
- try {
6982
- const blob = file.slice(fileOffset, fileOffset + partSize);
6983
- const partialFile = new File([blob], file.name, { type: file.type });
6984
- const formData = new FormData();
6985
- formData.append("originalFileName", file.name);
6986
- formData.append("token", uploadToken);
6987
- formData.append("count", "" + filePartsCount);
6988
- formData.append("part", "" + filePartIndex);
6989
- formData.append("file", partialFile);
6990
- const reqParams = exports.Api.PrepReqParams(req);
6991
- reqParams.formData = formData;
6992
- reqParams.onProgress = (progress) => {
6993
- const sofar = fileOffset + progress.loaded;
6994
- const percent = Math.round((sofar / file.size) * 100);
6995
- onProgress === null || onProgress === void 0 ? void 0 : onProgress({
6996
- percent: percent,
6997
- uploaded: false
6998
- });
6999
- };
7000
- data = yield api.UPLOAD(url, partialFile, reqParams);
7001
- retryCount = 0;
7002
- }
7003
- catch (up) {
7004
- retryCount -= 1;
7005
- if (retryCount <= 0) {
7006
- throw up;
7007
- }
7008
- yield new Promise((res) => setTimeout(res, retryWait));
7009
- retryWait = retryWait * 2;
7010
- }
7011
- }
7012
- fileOffset += partSize;
7013
- filePartIndex++;
7096
+ const cache = yield api.GetCacheItem(GetListCacheKey(), reqParams);
7097
+ if (cache === null || cache === void 0 ? void 0 : cache.found) {
7098
+ return cache.data;
7014
7099
  }
7015
- onProgress === null || onProgress === void 0 ? void 0 : onProgress({
7016
- percent: 100,
7017
- uploaded: true
7100
+ const res = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
7101
+ try {
7102
+ const data = yield api.GET("ui.entityDisplaySettings", exports.Api.PrepReqParams(reqParams));
7103
+ res({
7104
+ styles: data.Items
7105
+ });
7106
+ }
7107
+ catch (e) {
7108
+ rej(e);
7109
+ }
7110
+ }));
7111
+ yield api.SetCacheItem({
7112
+ key: GetListCacheKey(),
7113
+ value: res,
7114
+ req: reqParams
7018
7115
  });
7019
- return data;
7116
+ return res;
7020
7117
  });
7021
7118
  }
7022
- Uploader.DoMultiPartUpload = DoMultiPartUpload;
7023
- })(exports.Uploader || (exports.Uploader = {}));
7024
-
7025
- (function (ClientFile) {
7026
- let EPurpose;
7027
- (function (EPurpose) {
7028
- // Use this purpose for uploading bookmark thumbnail images.
7029
- // This will allow lower level privileges to upload (small) bookmark thumbnails.
7030
- EPurpose["BookmarkThumbnail"] = "Bookmark Thumbnail";
7031
- })(EPurpose = ClientFile.EPurpose || (ClientFile.EPurpose = {}));
7032
- /**
7033
- * Returns the URL for a client file.
7034
- * @param params
7035
- * @returns
7036
- */
7037
- function GetUrl(params) {
7038
- let { api, fileId, viaCdn } = params;
7039
- if (!api) {
7040
- api = exports.ENVIRONMENT.Api().GetBruceApi();
7041
- }
7042
- const urlSuffix = `file/${fileId}`;
7043
- const cdnUrl = viaCdn ? api.ConstructCdnUrl(urlSuffix) : null;
7044
- if (cdnUrl) {
7045
- return cdnUrl;
7046
- }
7047
- let url = `${api.GetBaseUrl()}${urlSuffix}`;
7048
- // Invalidating cache manually because we have a wave of invalid headers now cached across devices.
7049
- url = exports.UrlUtils.AddQueryParam(url, "cc", "1");
7050
- return url;
7051
- }
7052
- ClientFile.GetUrl = GetUrl;
7053
- /**
7054
- * Returns the URL for a client file with the extension.
7055
- * @param params
7056
- * @returns
7057
- */
7058
- function GetUrlWithExt(params) {
7059
- let { api, file, viaCdn } = params;
7060
- if (!api) {
7061
- api = exports.ENVIRONMENT.Api().GetBruceApi();
7062
- }
7063
- const urlSuffix = file.FileExt ? `file/${file.ID}${file.FileExt}` : `file/${file.ID}`;
7064
- const cdnUrl = viaCdn ? api.ConstructCdnUrl(urlSuffix) : null;
7065
- if (cdnUrl) {
7066
- return cdnUrl;
7067
- }
7068
- let url = `${api.GetBaseUrl()}${urlSuffix}`;
7069
- // Invalidating cache manually because we have a wave of invalid headers now cached across devices.
7070
- url = exports.UrlUtils.AddQueryParam(url, "cc", "1");
7071
- return url;
7072
- }
7073
- ClientFile.GetUrlWithExt = GetUrlWithExt;
7119
+ Style.GetList = GetList;
7074
7120
  /**
7075
- * Returns a client file record by ID.
7121
+ * Returns a style.
7076
7122
  * @param params
7077
7123
  * @returns
7078
7124
  */
7079
7125
  function Get(params) {
7080
7126
  return __awaiter(this, void 0, void 0, function* () {
7081
- let { api, fileId, req: reqParams } = params;
7127
+ let { api, styleId: id, req: reqParams } = params;
7128
+ if (!id) {
7129
+ throw ("Style ID is required.");
7130
+ }
7082
7131
  if (!api) {
7083
7132
  api = exports.ENVIRONMENT.Api().GetBruceApi();
7084
7133
  }
7085
- if (!fileId) {
7086
- throw ("File ID is required.");
7087
- }
7088
- const key = GetCacheKey(fileId);
7089
- const cache = yield api.GetCacheItem(key, reqParams);
7134
+ const cache = yield api.GetCacheItem(GetCacheKey(id), reqParams);
7090
7135
  if (cache === null || cache === void 0 ? void 0 : cache.found) {
7091
7136
  return cache.data;
7092
7137
  }
7093
7138
  const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
7094
7139
  try {
7095
- const data = yield api.GET(`file/${fileId}/details`, exports.Api.PrepReqParams(reqParams));
7140
+ const data = yield api.GET(`ui.entityDisplaySetting/${id}`, exports.Api.PrepReqParams(reqParams));
7096
7141
  res({
7097
- clientFile: data
7142
+ style: data
7098
7143
  });
7099
7144
  }
7100
7145
  catch (e) {
@@ -7102,64 +7147,750 @@
7102
7147
  }
7103
7148
  }));
7104
7149
  yield api.SetCacheItem({
7105
- key,
7150
+ key: GetCacheKey(id),
7106
7151
  value: prom,
7107
7152
  req: reqParams
7108
7153
  });
7109
7154
  return prom;
7110
7155
  });
7111
7156
  }
7112
- ClientFile.Get = Get;
7157
+ Style.Get = Get;
7113
7158
  /**
7114
- * Deletes one or many client file records by IDs.
7159
+ * Creates or updates a style.
7115
7160
  * @param params
7161
+ * @returns
7116
7162
  */
7117
- function Delete(params) {
7163
+ function Update(params) {
7118
7164
  return __awaiter(this, void 0, void 0, function* () {
7119
- let { api, fileIds, req: reqParams } = params;
7120
- if (!fileIds.length) {
7121
- return Promise.resolve();
7165
+ let { api, style: data, req: reqParams } = params;
7166
+ if (!(data === null || data === void 0 ? void 0 : data.Name)) {
7167
+ throw ("Style name is required.");
7122
7168
  }
7123
7169
  if (!api) {
7124
7170
  api = exports.ENVIRONMENT.Api().GetBruceApi();
7125
7171
  }
7126
- const data = {
7127
- Items: fileIds
7128
- };
7129
- yield api.POST("deleteFiles", data, exports.Api.PrepReqParams(reqParams));
7130
- for (let i = 0; i < fileIds.length; i++) {
7131
- const key = GetCacheKey(fileIds[i]);
7132
- api.Cache.Remove(key);
7172
+ if (!data.ID) {
7173
+ data.ID = 0;
7133
7174
  }
7175
+ const res = yield api.POST(`ui.entityDisplaySetting/${data.ID}`, data, exports.Api.PrepReqParams(reqParams));
7176
+ api.Cache.Remove(GetCacheKey(data.ID));
7177
+ api.Cache.Remove(GetListCacheKey());
7178
+ return {
7179
+ style: res
7180
+ };
7134
7181
  });
7135
7182
  }
7136
- ClientFile.Delete = Delete;
7183
+ Style.Update = Update;
7137
7184
  /**
7138
- * Uploads a file and creates a new client file record.
7185
+ * Deletes a style.
7139
7186
  * @param params
7140
- * @returns
7141
7187
  */
7142
- function Upload(params) {
7188
+ function Delete(params) {
7143
7189
  return __awaiter(this, void 0, void 0, function* () {
7144
- let { api, file, purpose, req, onProgress } = params;
7190
+ let { api, styleId: id, req: reqParams } = params;
7145
7191
  if (!api) {
7146
7192
  api = exports.ENVIRONMENT.Api().GetBruceApi();
7147
7193
  }
7148
- if (!file) {
7149
- throw ("File is required.");
7150
- }
7151
- const size = file === null || file === void 0 ? void 0 : file.size;
7152
- if (!size) {
7153
- throw ("You cannot upload a 0byte sized file.");
7194
+ if (!id) {
7195
+ throw ("Style ID is required.");
7154
7196
  }
7155
- req = exports.Api.PrepReqParams(req);
7156
- let clientFile;
7157
- if (size > exports.Uploader.MIN_LARGE_FILE_SIZE) {
7158
- clientFile = yield exports.Uploader.DoMultiPartUpload({
7159
- api,
7160
- file,
7161
- urlSuffix: "fileUpload",
7162
- req,
7197
+ yield api.DELETE(`ui.entityDisplaySetting/${id}`, exports.Api.PrepReqParams(reqParams));
7198
+ api.Cache.Remove(GetCacheKey(id));
7199
+ api.Cache.Remove(GetListCacheKey());
7200
+ });
7201
+ }
7202
+ Style.Delete = Delete;
7203
+ /**
7204
+ * Returns cache identifier for a style.
7205
+ * Example: {
7206
+ * const api: BruceApi.Api = ...;
7207
+ * const key = GetCacheKey(1);
7208
+ * api.Cache.Remove(key);
7209
+ * }
7210
+ * @param id
7211
+ * @returns
7212
+ */
7213
+ function GetCacheKey(id) {
7214
+ return exports.Api.ECacheKey.Style + exports.Api.ECacheKey.Id + id;
7215
+ }
7216
+ Style.GetCacheKey = GetCacheKey;
7217
+ /**
7218
+ * Returns cache identifier for a list of styles.
7219
+ * Example: {
7220
+ * const api: BruceApi.Api = ...;
7221
+ * const key = GetListCacheKey();
7222
+ * api.Cache.Remove(key);
7223
+ * }
7224
+ * @returns
7225
+ */
7226
+ function GetListCacheKey() {
7227
+ return exports.Api.ECacheKey.Style;
7228
+ }
7229
+ Style.GetListCacheKey = GetListCacheKey;
7230
+ })(exports.Style || (exports.Style = {}));
7231
+
7232
+ (function (Comment) {
7233
+ // Entity Type used for storing comment records.
7234
+ Comment.ENTITY_TYPE_ID = "COMMENTS";
7235
+ // Relationship Type ID for linking relies to comments.
7236
+ Comment.REPLY_RELATIONSHIP_TYPE_ID = "COMMENTS_REPLY";
7237
+ // Possible kinds of comments.
7238
+ let EType;
7239
+ (function (EType) {
7240
+ EType["Comment"] = "COMMENT";
7241
+ EType["Reply"] = "REPLY";
7242
+ })(EType = Comment.EType || (Comment.EType = {}));
7243
+ /**
7244
+ * Returns a list of comments based on the provided filter.
7245
+ * @param params
7246
+ * @returns
7247
+ */
7248
+ function GetList(params) {
7249
+ return __awaiter(this, void 0, void 0, function* () {
7250
+ let { api, req, filter } = params;
7251
+ if (!api) {
7252
+ api = exports.ENVIRONMENT.Api().GetBruceApi();
7253
+ }
7254
+ req = exports.Api.PrepReqParams(req);
7255
+ if (!(yield getEntityTypeExists(api, req))) {
7256
+ return {
7257
+ comments: []
7258
+ };
7259
+ }
7260
+ const reqFilter = {};
7261
+ if (filter.viewId) {
7262
+ reqFilter["viewId"] = {
7263
+ "equals": filter.viewId
7264
+ };
7265
+ }
7266
+ if (filter.userId) {
7267
+ reqFilter["CreatedBy.User.ID"] = {
7268
+ "equals": filter.userId
7269
+ };
7270
+ }
7271
+ if (filter.text) {
7272
+ reqFilter["text"] = {
7273
+ "contains": filter.text
7274
+ };
7275
+ }
7276
+ if (filter.entityId) {
7277
+ reqFilter["entityId"] = {
7278
+ "equals": filter.entityId
7279
+ };
7280
+ }
7281
+ const records = (yield exports.Entity.GetList({
7282
+ api,
7283
+ req,
7284
+ filter: {
7285
+ entityTypeId: Comment.ENTITY_TYPE_ID,
7286
+ pageSize: filter.amount == null ? 20 : filter.amount,
7287
+ pageIndex: filter.index == null ? 0 : filter.index,
7288
+ entityTypeConditions: reqFilter,
7289
+ orderBy: "lastUpdateTime"
7290
+ }
7291
+ })).entities;
7292
+ return {
7293
+ comments: records
7294
+ };
7295
+ });
7296
+ }
7297
+ Comment.GetList = GetList;
7298
+ /**
7299
+ * Ensure the Entity Type exists.
7300
+ * If it does not exist, it will be created.
7301
+ * @param params
7302
+ */
7303
+ function AssertEntityType(params) {
7304
+ return __awaiter(this, void 0, void 0, function* () {
7305
+ let { api, req } = params;
7306
+ if (!api) {
7307
+ api = exports.ENVIRONMENT.Api().GetBruceApi();
7308
+ }
7309
+ req = exports.Api.PrepReqParams(req);
7310
+ // If the Entity Type does not exist, create it.
7311
+ if (!(yield getEntityTypeExists(api, req))) {
7312
+ // Create Style and set it to the Entity Type.
7313
+ const styleId = yield ensureStyleExists(api);
7314
+ const template = JSON.parse(JSON.stringify(ENTITY_TYPE_TEMPLATE));
7315
+ template["DisplaySetting.ID"] = styleId;
7316
+ yield exports.EntityType.Update({
7317
+ api,
7318
+ entityType: template
7319
+ });
7320
+ }
7321
+ });
7322
+ }
7323
+ Comment.AssertEntityType = AssertEntityType;
7324
+ /**
7325
+ * Ensure the Relation Type exists.
7326
+ * If it does not exist, it will be created.
7327
+ * @param params
7328
+ */
7329
+ function AssertRelationType(params) {
7330
+ return __awaiter(this, void 0, void 0, function* () {
7331
+ let { api, req } = params;
7332
+ if (!api) {
7333
+ api = exports.ENVIRONMENT.Api().GetBruceApi();
7334
+ }
7335
+ req = exports.Api.PrepReqParams(req);
7336
+ yield ensureRelationExists(api, req);
7337
+ });
7338
+ }
7339
+ Comment.AssertRelationType = AssertRelationType;
7340
+ })(exports.Comment || (exports.Comment = {}));
7341
+ function getEntityTypeExists(api, req) {
7342
+ return __awaiter(this, void 0, void 0, function* () {
7343
+ try {
7344
+ const { entityType: data } = yield exports.EntityType.Get({
7345
+ api,
7346
+ req: req,
7347
+ entityTypeId: exports.Comment.ENTITY_TYPE_ID
7348
+ });
7349
+ return !!data;
7350
+ }
7351
+ catch (e) {
7352
+ // TODO: suppress if the error is related to not being found.
7353
+ console.error(e);
7354
+ }
7355
+ return false;
7356
+ });
7357
+ }
7358
+ function ensureStyleExists(api, req) {
7359
+ return __awaiter(this, void 0, void 0, function* () {
7360
+ try {
7361
+ const template = JSON.parse(JSON.stringify(STYLE_SETTINGS_TEMPLATE));
7362
+ const { style } = yield exports.Style.Update({
7363
+ api,
7364
+ req: req,
7365
+ style: {
7366
+ Name: "Comment Style",
7367
+ Settings: template,
7368
+ Type: exports.Style.EType.Entity,
7369
+ ID: 0
7370
+ }
7371
+ });
7372
+ return style.ID;
7373
+ }
7374
+ catch (e) {
7375
+ console.error(e);
7376
+ }
7377
+ return 0;
7378
+ });
7379
+ }
7380
+ function ensureRelationExists(api, req) {
7381
+ return __awaiter(this, void 0, void 0, function* () {
7382
+ try {
7383
+ const { relationType: data } = yield exports.EntityRelationType.Get({
7384
+ api,
7385
+ req: req,
7386
+ relationTypeId: exports.Comment.REPLY_RELATIONSHIP_TYPE_ID
7387
+ });
7388
+ if (!data) {
7389
+ throw ("Relation Type not found");
7390
+ }
7391
+ }
7392
+ catch (e) {
7393
+ yield exports.EntityRelationType.Update({
7394
+ api,
7395
+ req: req,
7396
+ relationType: {
7397
+ ID: exports.Comment.REPLY_RELATIONSHIP_TYPE_ID,
7398
+ ForwardName: "Parent of",
7399
+ ReverseName: "Reply to",
7400
+ Name: "Comment Reply"
7401
+ }
7402
+ });
7403
+ }
7404
+ });
7405
+ }
7406
+ const STYLE_SETTINGS_TEMPLATE = {
7407
+ pointStyle: {
7408
+ "color": [
7409
+ {
7410
+ "type": 0,
7411
+ "value": "rgba(33,150,243,0.8)"
7412
+ }
7413
+ ],
7414
+ "CylinderBorderEnabled": false,
7415
+ "CylinderBorderWidth": [
7416
+ {
7417
+ "type": 1,
7418
+ "value": "15"
7419
+ }
7420
+ ],
7421
+ "CylinderFillExtrusion": [
7422
+ {
7423
+ "type": 1,
7424
+ "value": "40"
7425
+ }
7426
+ ],
7427
+ "Type": exports.Style.EPointType.Icon,
7428
+ "iconId": null,
7429
+ "altitudeOption": {
7430
+ "name": "Absolute position",
7431
+ "id": 1
7432
+ },
7433
+ "size": [
7434
+ {
7435
+ "type": 1,
7436
+ "value": "20"
7437
+ }
7438
+ ],
7439
+ "CylinderFillColor": [
7440
+ {
7441
+ "type": 1,
7442
+ "value": "rgba(33,150,243,0.8)"
7443
+ }
7444
+ ],
7445
+ "CylinderBorderExtrusion": [
7446
+ {
7447
+ "type": 1,
7448
+ "value": "35"
7449
+ }
7450
+ ],
7451
+ "CylinderRadius": [
7452
+ {
7453
+ "type": 1,
7454
+ "value": "20"
7455
+ }
7456
+ ],
7457
+ "iconUrl": [
7458
+ {
7459
+ "type": 1,
7460
+ "value": "https://template.api.nextspace-uat.net/file/faf2194d-3a95-40cc-a6b3-6a7aa223f766.png"
7461
+ }
7462
+ ],
7463
+ "ClusterNearbyEntities": false,
7464
+ "CylinderBorderColor": [
7465
+ {
7466
+ "type": 1,
7467
+ "value": "rgba(33,150,243,0.8)"
7468
+ }
7469
+ ],
7470
+ "iconScale": [
7471
+ {
7472
+ "type": 1,
7473
+ "value": 1
7474
+ }
7475
+ ],
7476
+ "MinimumEntitiesCountForClustering": [
7477
+ {
7478
+ "type": 1,
7479
+ "value": "2"
7480
+ }
7481
+ ]
7482
+ }
7483
+ };
7484
+ const ENTITY_TYPE_TEMPLATE = {
7485
+ ID: exports.Comment.ENTITY_TYPE_ID,
7486
+ Name: "Comments",
7487
+ DataSchema: {
7488
+ "Key": "root",
7489
+ "Name": "Root",
7490
+ "Type": exports.EntityAttribute.EType.Structure,
7491
+ Structure: [
7492
+ {
7493
+ "IsIndexed": true,
7494
+ "IsImportant": false,
7495
+ "Type": exports.EntityAttribute.EType.String,
7496
+ "IsArray": false,
7497
+ "Size": 40,
7498
+ "Key": "ID",
7499
+ "Name": "Identity",
7500
+ "IsFamilyAttribute": false,
7501
+ "IsFamilyAttributeDefault": false
7502
+ },
7503
+ {
7504
+ "IsIndexed": false,
7505
+ "IsImportant": false,
7506
+ "Type": exports.EntityAttribute.EType.Geometry,
7507
+ "IsArray": false,
7508
+ "Size": 0,
7509
+ "Key": "geometry",
7510
+ "Name": "Geometry",
7511
+ "IsFamilyAttribute": false,
7512
+ "IsFamilyAttributeDefault": false
7513
+ },
7514
+ {
7515
+ "IsImportant": false,
7516
+ "Type": exports.EntityAttribute.EType.Structure,
7517
+ "IsArray": false,
7518
+ "Structure": [
7519
+ {
7520
+ "IsIndexed": true,
7521
+ "IsImportant": false,
7522
+ "Type": exports.EntityAttribute.EType.Double,
7523
+ "IsArray": false,
7524
+ "Key": "minLongitude",
7525
+ "Name": "Min Longitude",
7526
+ "IsFamilyAttribute": false,
7527
+ "IsFamilyAttributeDefault": false
7528
+ },
7529
+ {
7530
+ "IsIndexed": true,
7531
+ "IsImportant": false,
7532
+ "Type": exports.EntityAttribute.EType.Double,
7533
+ "IsArray": false,
7534
+ "Key": "minLatitude",
7535
+ "Name": "Min Latitude",
7536
+ "IsFamilyAttribute": false,
7537
+ "IsFamilyAttributeDefault": false
7538
+ },
7539
+ {
7540
+ "IsIndexed": true,
7541
+ "IsImportant": false,
7542
+ "Type": exports.EntityAttribute.EType.Double,
7543
+ "IsArray": false,
7544
+ "Size": 0,
7545
+ "Key": "minAltitude",
7546
+ "Name": "Min Altitude",
7547
+ "IsFamilyAttribute": false,
7548
+ "IsFamilyAttributeDefault": false
7549
+ },
7550
+ {
7551
+ "IsIndexed": true,
7552
+ "IsImportant": false,
7553
+ "Type": exports.EntityAttribute.EType.Double,
7554
+ "IsArray": false,
7555
+ "Key": "maxLongitude",
7556
+ "Name": "Max Longitude",
7557
+ "IsFamilyAttribute": false,
7558
+ "IsFamilyAttributeDefault": false
7559
+ },
7560
+ {
7561
+ "IsIndexed": true,
7562
+ "IsImportant": false,
7563
+ "Type": exports.EntityAttribute.EType.Double,
7564
+ "IsArray": false,
7565
+ "Key": "maxLatitude",
7566
+ "Name": "Max Latitude",
7567
+ "IsFamilyAttribute": false,
7568
+ "IsFamilyAttributeDefault": false
7569
+ },
7570
+ {
7571
+ "IsIndexed": true,
7572
+ "IsImportant": false,
7573
+ "Type": exports.EntityAttribute.EType.Double,
7574
+ "IsArray": false,
7575
+ "Size": 0,
7576
+ "Key": "maxAltitude",
7577
+ "Name": "Max Altitude",
7578
+ "IsFamilyAttribute": false,
7579
+ "IsFamilyAttributeDefault": false
7580
+ }
7581
+ ],
7582
+ "Key": "boundaries",
7583
+ "Name": "Boundaries",
7584
+ "IsFamilyAttribute": false,
7585
+ "IsFamilyAttributeDefault": false
7586
+ },
7587
+ {
7588
+ "IsImportant": false,
7589
+ "Type": exports.EntityAttribute.EType.Structure,
7590
+ "IsArray": false,
7591
+ "Structure": [
7592
+ {
7593
+ "IsIndexed": true,
7594
+ "IsImportant": false,
7595
+ "Type": exports.EntityAttribute.EType.Double,
7596
+ "IsArray": false,
7597
+ "Key": "latitude",
7598
+ "Name": "Latitude",
7599
+ "IsFamilyAttribute": false,
7600
+ "IsFamilyAttributeDefault": false
7601
+ },
7602
+ {
7603
+ "IsIndexed": true,
7604
+ "IsImportant": false,
7605
+ "Type": exports.EntityAttribute.EType.Double,
7606
+ "IsArray": false,
7607
+ "Key": "longitude",
7608
+ "Name": "Longitude",
7609
+ "IsFamilyAttribute": false,
7610
+ "IsFamilyAttributeDefault": false
7611
+ },
7612
+ {
7613
+ "IsIndexed": true,
7614
+ "IsImportant": false,
7615
+ "Type": exports.EntityAttribute.EType.Double,
7616
+ "IsArray": false,
7617
+ "Key": "altitude",
7618
+ "Name": "Altitude",
7619
+ "IsFamilyAttribute": false,
7620
+ "IsFamilyAttributeDefault": false
7621
+ }
7622
+ ],
7623
+ "Key": "location",
7624
+ "Name": "Location",
7625
+ "IsFamilyAttribute": false,
7626
+ "IsFamilyAttributeDefault": false
7627
+ },
7628
+ {
7629
+ "IsIndexed": true,
7630
+ "IsImportant": true,
7631
+ "Type": exports.EntityAttribute.EType.String,
7632
+ "IsArray": false,
7633
+ "Size": 60,
7634
+ "Key": "viewId",
7635
+ "Name": "View Id",
7636
+ "IsFamilyAttribute": false,
7637
+ "IsFamilyAttributeDefault": false
7638
+ },
7639
+ {
7640
+ "IsIndexed": true,
7641
+ "IsImportant": true,
7642
+ "Type": exports.EntityAttribute.EType.String,
7643
+ "IsArray": false,
7644
+ "Size": 60,
7645
+ "Key": "bookmarkId",
7646
+ "Name": "Bookmark Id",
7647
+ "IsFamilyAttribute": false,
7648
+ "IsFamilyAttributeDefault": false
7649
+ },
7650
+ {
7651
+ "IsIndexed": true,
7652
+ "IsImportant": true,
7653
+ "Type": exports.EntityAttribute.EType.String,
7654
+ "IsArray": false,
7655
+ "Key": "text",
7656
+ "Name": "Comment",
7657
+ "IsFamilyAttribute": false,
7658
+ "IsFamilyAttributeDefault": false
7659
+ },
7660
+ {
7661
+ "IsIndexed": true,
7662
+ "IsImportant": true,
7663
+ "Type": exports.EntityAttribute.EType.Datetime,
7664
+ "IsArray": false,
7665
+ "Key": "lastUpdateTime",
7666
+ "Name": "Last Update Time",
7667
+ "IsFamilyAttribute": false,
7668
+ "IsFamilyAttributeDefault": false
7669
+ },
7670
+ {
7671
+ "IsIndexed": true,
7672
+ "IsImportant": true,
7673
+ "Type": exports.EntityAttribute.EType.String,
7674
+ "IsArray": false,
7675
+ "Key": "entityId",
7676
+ "Name": "Related Entity ID",
7677
+ "IsFamilyAttribute": false,
7678
+ "IsFamilyAttributeDefault": false
7679
+ }
7680
+ ]
7681
+ },
7682
+ "DisplaySetting.ID": 0
7683
+ };
7684
+
7685
+ (function (Uploader) {
7686
+ Uploader.MIN_LARGE_FILE_SIZE = 100000000; // 100MB.
7687
+ /**
7688
+ * Uploads a file to the server.
7689
+ * @param params
7690
+ * @returns
7691
+ */
7692
+ function DoMultiPartUpload(params) {
7693
+ return __awaiter(this, void 0, void 0, function* () {
7694
+ let { file, api, urlSuffix: url, req, onProgress } = params;
7695
+ if (!api) {
7696
+ api = exports.ENVIRONMENT.Api().GetBruceApi();
7697
+ }
7698
+ const FILE_PORTION_SIZE = 100000000; // 100MB.
7699
+ let fileSize = file.size;
7700
+ let fileOffset = 0;
7701
+ let filePartsCount = fileSize / FILE_PORTION_SIZE;
7702
+ let t = Math.trunc(filePartsCount);
7703
+ filePartsCount = filePartsCount > t ? t + 1 : t;
7704
+ let filePartIndex = 1;
7705
+ let uploadToken = exports.ObjectUtils.UId();
7706
+ let data;
7707
+ while (fileOffset < fileSize) {
7708
+ let partSize = Math.min(FILE_PORTION_SIZE, fileSize - fileOffset);
7709
+ let retryCount = 5;
7710
+ let retryWait = 1000;
7711
+ while (retryCount > 0) {
7712
+ try {
7713
+ const blob = file.slice(fileOffset, fileOffset + partSize);
7714
+ const partialFile = new File([blob], file.name, { type: file.type });
7715
+ const formData = new FormData();
7716
+ formData.append("originalFileName", file.name);
7717
+ formData.append("token", uploadToken);
7718
+ formData.append("count", "" + filePartsCount);
7719
+ formData.append("part", "" + filePartIndex);
7720
+ formData.append("file", partialFile);
7721
+ const reqParams = exports.Api.PrepReqParams(req);
7722
+ reqParams.formData = formData;
7723
+ reqParams.onProgress = (progress) => {
7724
+ const sofar = fileOffset + progress.loaded;
7725
+ const percent = Math.round((sofar / file.size) * 100);
7726
+ onProgress === null || onProgress === void 0 ? void 0 : onProgress({
7727
+ percent: percent,
7728
+ uploaded: false
7729
+ });
7730
+ };
7731
+ data = yield api.UPLOAD(url, partialFile, reqParams);
7732
+ retryCount = 0;
7733
+ }
7734
+ catch (up) {
7735
+ retryCount -= 1;
7736
+ if (retryCount <= 0) {
7737
+ throw up;
7738
+ }
7739
+ yield new Promise((res) => setTimeout(res, retryWait));
7740
+ retryWait = retryWait * 2;
7741
+ }
7742
+ }
7743
+ fileOffset += partSize;
7744
+ filePartIndex++;
7745
+ }
7746
+ onProgress === null || onProgress === void 0 ? void 0 : onProgress({
7747
+ percent: 100,
7748
+ uploaded: true
7749
+ });
7750
+ return data;
7751
+ });
7752
+ }
7753
+ Uploader.DoMultiPartUpload = DoMultiPartUpload;
7754
+ })(exports.Uploader || (exports.Uploader = {}));
7755
+
7756
+ (function (ClientFile) {
7757
+ let EPurpose;
7758
+ (function (EPurpose) {
7759
+ // Use this purpose for uploading bookmark thumbnail images.
7760
+ // This will allow lower level privileges to upload (small) bookmark thumbnails.
7761
+ EPurpose["BookmarkThumbnail"] = "Bookmark Thumbnail";
7762
+ })(EPurpose = ClientFile.EPurpose || (ClientFile.EPurpose = {}));
7763
+ /**
7764
+ * Returns the URL for a client file.
7765
+ * @param params
7766
+ * @returns
7767
+ */
7768
+ function GetUrl(params) {
7769
+ let { api, fileId, viaCdn } = params;
7770
+ if (!api) {
7771
+ api = exports.ENVIRONMENT.Api().GetBruceApi();
7772
+ }
7773
+ const urlSuffix = `file/${fileId}`;
7774
+ const cdnUrl = viaCdn ? api.ConstructCdnUrl(urlSuffix) : null;
7775
+ if (cdnUrl) {
7776
+ return cdnUrl;
7777
+ }
7778
+ let url = `${api.GetBaseUrl()}${urlSuffix}`;
7779
+ // Invalidating cache manually because we have a wave of invalid headers now cached across devices.
7780
+ url = exports.UrlUtils.AddQueryParam(url, "cc", "1");
7781
+ return url;
7782
+ }
7783
+ ClientFile.GetUrl = GetUrl;
7784
+ /**
7785
+ * Returns the URL for a client file with the extension.
7786
+ * @param params
7787
+ * @returns
7788
+ */
7789
+ function GetUrlWithExt(params) {
7790
+ let { api, file, viaCdn } = params;
7791
+ if (!api) {
7792
+ api = exports.ENVIRONMENT.Api().GetBruceApi();
7793
+ }
7794
+ const urlSuffix = file.FileExt ? `file/${file.ID}${file.FileExt}` : `file/${file.ID}`;
7795
+ const cdnUrl = viaCdn ? api.ConstructCdnUrl(urlSuffix) : null;
7796
+ if (cdnUrl) {
7797
+ return cdnUrl;
7798
+ }
7799
+ let url = `${api.GetBaseUrl()}${urlSuffix}`;
7800
+ // Invalidating cache manually because we have a wave of invalid headers now cached across devices.
7801
+ url = exports.UrlUtils.AddQueryParam(url, "cc", "1");
7802
+ return url;
7803
+ }
7804
+ ClientFile.GetUrlWithExt = GetUrlWithExt;
7805
+ /**
7806
+ * Returns a client file record by ID.
7807
+ * @param params
7808
+ * @returns
7809
+ */
7810
+ function Get(params) {
7811
+ return __awaiter(this, void 0, void 0, function* () {
7812
+ let { api, fileId, req: reqParams } = params;
7813
+ if (!api) {
7814
+ api = exports.ENVIRONMENT.Api().GetBruceApi();
7815
+ }
7816
+ if (!fileId) {
7817
+ throw ("File ID is required.");
7818
+ }
7819
+ const key = GetCacheKey(fileId);
7820
+ const cache = yield api.GetCacheItem(key, reqParams);
7821
+ if (cache === null || cache === void 0 ? void 0 : cache.found) {
7822
+ return cache.data;
7823
+ }
7824
+ const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
7825
+ try {
7826
+ const data = yield api.GET(`file/${fileId}/details`, exports.Api.PrepReqParams(reqParams));
7827
+ res({
7828
+ clientFile: data
7829
+ });
7830
+ }
7831
+ catch (e) {
7832
+ rej(e);
7833
+ }
7834
+ }));
7835
+ yield api.SetCacheItem({
7836
+ key,
7837
+ value: prom,
7838
+ req: reqParams
7839
+ });
7840
+ return prom;
7841
+ });
7842
+ }
7843
+ ClientFile.Get = Get;
7844
+ /**
7845
+ * Deletes one or many client file records by IDs.
7846
+ * @param params
7847
+ */
7848
+ function Delete(params) {
7849
+ return __awaiter(this, void 0, void 0, function* () {
7850
+ let { api, fileIds, req: reqParams } = params;
7851
+ if (!fileIds.length) {
7852
+ return Promise.resolve();
7853
+ }
7854
+ if (!api) {
7855
+ api = exports.ENVIRONMENT.Api().GetBruceApi();
7856
+ }
7857
+ const data = {
7858
+ Items: fileIds
7859
+ };
7860
+ yield api.POST("deleteFiles", data, exports.Api.PrepReqParams(reqParams));
7861
+ for (let i = 0; i < fileIds.length; i++) {
7862
+ const key = GetCacheKey(fileIds[i]);
7863
+ api.Cache.Remove(key);
7864
+ }
7865
+ });
7866
+ }
7867
+ ClientFile.Delete = Delete;
7868
+ /**
7869
+ * Uploads a file and creates a new client file record.
7870
+ * @param params
7871
+ * @returns
7872
+ */
7873
+ function Upload(params) {
7874
+ return __awaiter(this, void 0, void 0, function* () {
7875
+ let { api, file, purpose, req, onProgress } = params;
7876
+ if (!api) {
7877
+ api = exports.ENVIRONMENT.Api().GetBruceApi();
7878
+ }
7879
+ if (!file) {
7880
+ throw ("File is required.");
7881
+ }
7882
+ const size = file === null || file === void 0 ? void 0 : file.size;
7883
+ if (!size) {
7884
+ throw ("You cannot upload a 0byte sized file.");
7885
+ }
7886
+ req = exports.Api.PrepReqParams(req);
7887
+ let clientFile;
7888
+ if (size > exports.Uploader.MIN_LARGE_FILE_SIZE) {
7889
+ clientFile = yield exports.Uploader.DoMultiPartUpload({
7890
+ api,
7891
+ file,
7892
+ urlSuffix: "fileUpload",
7893
+ req,
7163
7894
  onProgress
7164
7895
  });
7165
7896
  // TODO: Check if we can add it to the request like the small file upload.
@@ -9328,186 +10059,16 @@
9328
10059
  return __awaiter(this, void 0, void 0, function* () {
9329
10060
  let { api, actionId, req: reqParams } = params;
9330
10061
  if (!actionId) {
9331
- throw ("Action ID is required.");
9332
- }
9333
- if (!api) {
9334
- api = exports.ENVIRONMENT.Api().GetBruceApi();
9335
- }
9336
- yield api.DELETE(`pendingAction/${actionId}`, exports.Api.PrepReqParams(reqParams));
9337
- });
9338
- }
9339
- PendingAction.Cancel = Cancel;
9340
- })(exports.PendingAction || (exports.PendingAction = {}));
9341
-
9342
- (function (Style) {
9343
- /**
9344
- * Types of styles available.
9345
- * The type will dictate what settings are available.
9346
- */
9347
- let EType;
9348
- (function (EType) {
9349
- EType["Entity"] = "ENTITY";
9350
- EType["EntityRelationship"] = "ENTITY_RELATIONSHIP";
9351
- })(EType = Style.EType || (Style.EType = {}));
9352
- /**
9353
- * Available types of points.
9354
- * Default is POINT.
9355
- */
9356
- let EPointType;
9357
- (function (EPointType) {
9358
- // Render a sphere with a fixed pixel size.
9359
- EPointType["Point"] = "POINT";
9360
- // Render an icon.
9361
- EPointType["Icon"] = "ICON";
9362
- // Render a cylinder with a fixed meter size.
9363
- EPointType["Cylinder"] = "CYLINDER";
9364
- })(EPointType = Style.EPointType || (Style.EPointType = {}));
9365
- /**
9366
- * Returns a list of styles.
9367
- * @param params
9368
- * @returns
9369
- */
9370
- function GetList(params) {
9371
- return __awaiter(this, void 0, void 0, function* () {
9372
- let { api, req: reqParams } = params;
9373
- if (!api) {
9374
- api = exports.ENVIRONMENT.Api().GetBruceApi();
9375
- }
9376
- const cache = yield api.GetCacheItem(GetListCacheKey(), reqParams);
9377
- if (cache === null || cache === void 0 ? void 0 : cache.found) {
9378
- return cache.data;
9379
- }
9380
- const res = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
9381
- try {
9382
- const data = yield api.GET("ui.entityDisplaySettings", exports.Api.PrepReqParams(reqParams));
9383
- res({
9384
- styles: data.Items
9385
- });
9386
- }
9387
- catch (e) {
9388
- rej(e);
9389
- }
9390
- }));
9391
- yield api.SetCacheItem({
9392
- key: GetListCacheKey(),
9393
- value: res,
9394
- req: reqParams
9395
- });
9396
- return res;
9397
- });
9398
- }
9399
- Style.GetList = GetList;
9400
- /**
9401
- * Returns a style.
9402
- * @param params
9403
- * @returns
9404
- */
9405
- function Get(params) {
9406
- return __awaiter(this, void 0, void 0, function* () {
9407
- let { api, styleId: id, req: reqParams } = params;
9408
- if (!id) {
9409
- throw ("Style ID is required.");
9410
- }
9411
- if (!api) {
9412
- api = exports.ENVIRONMENT.Api().GetBruceApi();
9413
- }
9414
- const cache = yield api.GetCacheItem(GetCacheKey(id), reqParams);
9415
- if (cache === null || cache === void 0 ? void 0 : cache.found) {
9416
- return cache.data;
9417
- }
9418
- const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
9419
- try {
9420
- const data = yield api.GET(`ui.entityDisplaySetting/${id}`, exports.Api.PrepReqParams(reqParams));
9421
- res({
9422
- style: data
9423
- });
9424
- }
9425
- catch (e) {
9426
- rej(e);
9427
- }
9428
- }));
9429
- yield api.SetCacheItem({
9430
- key: GetCacheKey(id),
9431
- value: prom,
9432
- req: reqParams
9433
- });
9434
- return prom;
9435
- });
9436
- }
9437
- Style.Get = Get;
9438
- /**
9439
- * Creates or updates a style.
9440
- * @param params
9441
- * @returns
9442
- */
9443
- function Update(params) {
9444
- return __awaiter(this, void 0, void 0, function* () {
9445
- let { api, style: data, req: reqParams } = params;
9446
- if (!(data === null || data === void 0 ? void 0 : data.Name)) {
9447
- throw ("Style name is required.");
9448
- }
9449
- if (!api) {
9450
- api = exports.ENVIRONMENT.Api().GetBruceApi();
9451
- }
9452
- if (!data.ID) {
9453
- data.ID = 0;
9454
- }
9455
- const res = yield api.POST(`ui.entityDisplaySetting/${data.ID}`, data, exports.Api.PrepReqParams(reqParams));
9456
- api.Cache.Remove(GetCacheKey(data.ID));
9457
- api.Cache.Remove(GetListCacheKey());
9458
- return {
9459
- style: res
9460
- };
9461
- });
9462
- }
9463
- Style.Update = Update;
9464
- /**
9465
- * Deletes a style.
9466
- * @param params
9467
- */
9468
- function Delete(params) {
9469
- return __awaiter(this, void 0, void 0, function* () {
9470
- let { api, styleId: id, req: reqParams } = params;
9471
- if (!api) {
9472
- api = exports.ENVIRONMENT.Api().GetBruceApi();
9473
- }
9474
- if (!id) {
9475
- throw ("Style ID is required.");
9476
- }
9477
- yield api.DELETE(`ui.entityDisplaySetting/${id}`, exports.Api.PrepReqParams(reqParams));
9478
- api.Cache.Remove(GetCacheKey(id));
9479
- api.Cache.Remove(GetListCacheKey());
9480
- });
9481
- }
9482
- Style.Delete = Delete;
9483
- /**
9484
- * Returns cache identifier for a style.
9485
- * Example: {
9486
- * const api: BruceApi.Api = ...;
9487
- * const key = GetCacheKey(1);
9488
- * api.Cache.Remove(key);
9489
- * }
9490
- * @param id
9491
- * @returns
9492
- */
9493
- function GetCacheKey(id) {
9494
- return exports.Api.ECacheKey.Style + exports.Api.ECacheKey.Id + id;
9495
- }
9496
- Style.GetCacheKey = GetCacheKey;
9497
- /**
9498
- * Returns cache identifier for a list of styles.
9499
- * Example: {
9500
- * const api: BruceApi.Api = ...;
9501
- * const key = GetListCacheKey();
9502
- * api.Cache.Remove(key);
9503
- * }
9504
- * @returns
9505
- */
9506
- function GetListCacheKey() {
9507
- return exports.Api.ECacheKey.Style;
10062
+ throw ("Action ID is required.");
10063
+ }
10064
+ if (!api) {
10065
+ api = exports.ENVIRONMENT.Api().GetBruceApi();
10066
+ }
10067
+ yield api.DELETE(`pendingAction/${actionId}`, exports.Api.PrepReqParams(reqParams));
10068
+ });
9508
10069
  }
9509
- Style.GetListCacheKey = GetListCacheKey;
9510
- })(exports.Style || (exports.Style = {}));
10070
+ PendingAction.Cancel = Cancel;
10071
+ })(exports.PendingAction || (exports.PendingAction = {}));
9511
10072
 
9512
10073
  /**
9513
10074
  * Permissions in Nextspace are arbitrary strings with meaning in specific contexts.
@@ -10672,6 +11233,609 @@
10672
11233
  AccountFeatures.GetCacheKey = GetCacheKey;
10673
11234
  })(exports.AccountFeatures || (exports.AccountFeatures = {}));
10674
11235
 
11236
+ (function (AccountLimits) {
11237
+ let ELimit;
11238
+ (function (ELimit) {
11239
+ ELimit["MaxProjectViewCount"] = "MaxProjectViewCount";
11240
+ ELimit["MaxStorageUseGigabytes"] = "MaxStorageUseGigabytes";
11241
+ ELimit["MaxEntitiesCount"] = "MaxEntitiesCount";
11242
+ ELimit["MaxFileImportSizeGigabytes"] = "MaxFileImportSizeGigabytes";
11243
+ ELimit["OperatorAccessAllowed"] = "OperatorAccessAllowed";
11244
+ ELimit["DenyPublicAccess"] = "DenyPublicAccess";
11245
+ ELimit["EnableSSOLogin"] = "EnableSSOLogin";
11246
+ ELimit["EnableSSOLoginAutoRedirect"] = "EnableSSOLoginAutoRedirect";
11247
+ })(ELimit = AccountLimits.ELimit || (AccountLimits.ELimit = {}));
11248
+ /**
11249
+ * Returns a dictionary of limits for the given account.
11250
+ * @param params
11251
+ * @returns
11252
+ */
11253
+ function GetLimits(params) {
11254
+ return __awaiter(this, void 0, void 0, function* () {
11255
+ let { accountId, api, req } = params;
11256
+ if (!api) {
11257
+ api = exports.ENVIRONMENT.Api().GetGuardianApi();
11258
+ }
11259
+ req = exports.Api.PrepReqParams(req);
11260
+ const cacheData = api.GetCacheItem(GetLimitsCacheKey(accountId));
11261
+ if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.found) {
11262
+ return cacheData.data;
11263
+ }
11264
+ const prom = new Promise((res, rej) => __awaiter(this, void 0, void 0, function* () {
11265
+ try {
11266
+ const data = yield api.GET(`account/${accountId}?WithLimits=true`);
11267
+ const limits = data.Limits ? data.Limits : {};
11268
+ res({
11269
+ limits: limits
11270
+ });
11271
+ }
11272
+ catch (e) {
11273
+ rej(e);
11274
+ }
11275
+ }));
11276
+ api.SetCacheItem({
11277
+ key: GetLimitsCacheKey(accountId),
11278
+ value: prom,
11279
+ req: req
11280
+ });
11281
+ return prom;
11282
+ });
11283
+ }
11284
+ AccountLimits.GetLimits = GetLimits;
11285
+ /**
11286
+ * Returns a numeric limit for the given account.
11287
+ * @param params
11288
+ */
11289
+ function GetNumericLimit(params) {
11290
+ return __awaiter(this, void 0, void 0, function* () {
11291
+ const { key, api, req, onErrorValue, onEmptyValue, accountId } = params;
11292
+ try {
11293
+ const { limits } = yield GetLimits({
11294
+ accountId: accountId,
11295
+ api: api,
11296
+ req: req
11297
+ });
11298
+ const limit = limits[key];
11299
+ if (limit == null || limit.Numeric == null) {
11300
+ return onEmptyValue;
11301
+ }
11302
+ return Number(limit.Numeric);
11303
+ }
11304
+ catch (e) {
11305
+ return onErrorValue;
11306
+ }
11307
+ });
11308
+ }
11309
+ AccountLimits.GetNumericLimit = GetNumericLimit;
11310
+ /**
11311
+ * Returns a boolean limit for the given account.
11312
+ * @param params
11313
+ */
11314
+ function GetBooleanLimit(params) {
11315
+ return __awaiter(this, void 0, void 0, function* () {
11316
+ const { key, api, req, onErrorValue, onEmptyValue, accountId } = params;
11317
+ try {
11318
+ const { limits } = yield GetLimits({
11319
+ accountId: accountId,
11320
+ api: api,
11321
+ req: req
11322
+ });
11323
+ const limit = limits[key];
11324
+ if (limit == null || limit.Boolean == null) {
11325
+ return onEmptyValue;
11326
+ }
11327
+ return Boolean(limit.Boolean);
11328
+ }
11329
+ catch (e) {
11330
+ return onErrorValue;
11331
+ }
11332
+ });
11333
+ }
11334
+ AccountLimits.GetBooleanLimit = GetBooleanLimit;
11335
+ /**
11336
+ * Returns a string limit for the given account.
11337
+ * @param params
11338
+ */
11339
+ function GetStringLimit(params) {
11340
+ return __awaiter(this, void 0, void 0, function* () {
11341
+ const { key, api, req, onErrorValue, onEmptyValue, accountId } = params;
11342
+ try {
11343
+ const { limits } = yield GetLimits({
11344
+ accountId: accountId,
11345
+ api: api,
11346
+ req: req
11347
+ });
11348
+ const limit = limits[key];
11349
+ if (limit == null || limit.String == null) {
11350
+ return onEmptyValue;
11351
+ }
11352
+ return limit.String;
11353
+ }
11354
+ catch (e) {
11355
+ return onErrorValue;
11356
+ }
11357
+ });
11358
+ }
11359
+ AccountLimits.GetStringLimit = GetStringLimit;
11360
+ /**
11361
+ * Functions for validating if a user can do things sit here.
11362
+ */
11363
+ let Assert;
11364
+ (function (Assert) {
11365
+ /**
11366
+ * Returns if project view creation is allowed for the account.
11367
+ */
11368
+ function GetCanCreateProjectView(params) {
11369
+ return __awaiter(this, void 0, void 0, function* () {
11370
+ if (!params.getters) {
11371
+ params.getters = exports.ENVIRONMENT.Api();
11372
+ }
11373
+ if (!params.accountId) {
11374
+ params.accountId = params.getters.GetAccountId();
11375
+ }
11376
+ let current = -1;
11377
+ let max = yield GetNumericLimit({
11378
+ accountId: params.accountId,
11379
+ key: ELimit.MaxProjectViewCount,
11380
+ onEmptyValue: 0,
11381
+ onErrorValue: null,
11382
+ api: params.getters.GetGuardianApi()
11383
+ });
11384
+ if (max != null) {
11385
+ // Should use proper statistic API as this will exclude project views the user cannot access.
11386
+ try {
11387
+ const { views } = yield exports.ProjectView.GetList({
11388
+ api: params.getters.GetBruceApi({
11389
+ accountId: params.accountId
11390
+ })
11391
+ });
11392
+ current = views.length;
11393
+ }
11394
+ catch (e) {
11395
+ console.error(e);
11396
+ max = null;
11397
+ }
11398
+ }
11399
+ if (max == null) {
11400
+ return {
11401
+ allowed: false,
11402
+ errorText: "We apologize but Project View creation is currently unavailable."
11403
+ };
11404
+ }
11405
+ else if (max == -1) {
11406
+ return {
11407
+ allowed: true
11408
+ };
11409
+ }
11410
+ else if (current == -1) {
11411
+ return {
11412
+ allowed: false,
11413
+ errorText: "We apologize but Project View creation is currently unavailable."
11414
+ };
11415
+ }
11416
+ else if (current >= max) {
11417
+ return {
11418
+ allowed: false,
11419
+ errorText: `You have reached the maximum number of Project Views allowed for your account. Your limit is ${max} Project ${max == 1 ? "View" : "Views"} and you have ${current}.`
11420
+ };
11421
+ }
11422
+ return {
11423
+ allowed: true
11424
+ };
11425
+ });
11426
+ }
11427
+ Assert.GetCanCreateProjectView = GetCanCreateProjectView;
11428
+ /**
11429
+ * Returns the project view limit for an account.
11430
+ * If -1 is returned then it is unlimited.
11431
+ * @param params
11432
+ * @returns
11433
+ */
11434
+ function GetProjectViewLimit(params) {
11435
+ return __awaiter(this, void 0, void 0, function* () {
11436
+ if (!params.api) {
11437
+ params.api = exports.ENVIRONMENT.Api().GetGuardianApi();
11438
+ }
11439
+ if (!params.accountId) {
11440
+ params.accountId = exports.ENVIRONMENT.Api().GetAccountId();
11441
+ }
11442
+ const max = yield GetNumericLimit({
11443
+ accountId: params.accountId,
11444
+ key: ELimit.MaxProjectViewCount,
11445
+ onEmptyValue: 0,
11446
+ onErrorValue: null,
11447
+ api: params.api
11448
+ });
11449
+ // Our error so we'll just allow unlimited for the time being.
11450
+ if (max == null) {
11451
+ return -1;
11452
+ }
11453
+ return max;
11454
+ });
11455
+ }
11456
+ Assert.GetProjectViewLimit = GetProjectViewLimit;
11457
+ /**
11458
+ * Returns if file uploads are allowed for the account.
11459
+ */
11460
+ function GetCanUploadFile(params) {
11461
+ return __awaiter(this, void 0, void 0, function* () {
11462
+ if (!params.getters) {
11463
+ params.getters = exports.ENVIRONMENT.Api();
11464
+ }
11465
+ if (!params.accountId) {
11466
+ params.accountId = params.getters.GetAccountId();
11467
+ }
11468
+ let current = -1;
11469
+ let max = yield GetNumericLimit({
11470
+ accountId: params.accountId,
11471
+ key: ELimit.MaxStorageUseGigabytes,
11472
+ onEmptyValue: 0,
11473
+ onErrorValue: null,
11474
+ api: params.getters.GetGuardianApi()
11475
+ });
11476
+ if (max != null && max > 0) {
11477
+ try {
11478
+ const api = params.getters.GetBruceApi({
11479
+ accountId: params.accountId
11480
+ });
11481
+ const stats = yield api.GET("account/summary-stats");
11482
+ if (stats === null || stats === void 0 ? void 0 : stats.ID) {
11483
+ const result = stats === null || stats === void 0 ? void 0 : stats.Result;
11484
+ try {
11485
+ const resJson = JSON.parse(result);
11486
+ const fileBytes = resJson.TotalStorageUseBytes;
11487
+ const fileGB = fileBytes != null && !isNaN(fileBytes) && fileBytes != -1 ? exports.MathUtils.Round(fileBytes / 1024 / 1024 / 1024, 2) : null;
11488
+ // Still counting so we'll give unlimited for the time being.
11489
+ // This count can take ages so we won't make the user wait.
11490
+ if (fileGB == null || isNaN(fileGB)) {
11491
+ max = -1;
11492
+ }
11493
+ else {
11494
+ current = fileGB;
11495
+ }
11496
+ }
11497
+ // We won't count this as a fatal error because who knows how stable this is.
11498
+ catch (e) {
11499
+ console.error(e);
11500
+ }
11501
+ }
11502
+ // Unknown so we'll just give unlimited for the time being.
11503
+ else {
11504
+ max = -1;
11505
+ }
11506
+ }
11507
+ catch (e) {
11508
+ console.error(e);
11509
+ max = null;
11510
+ }
11511
+ }
11512
+ // Optional param for a file size to add to the current storage amount.
11513
+ // Eg: user is uploading a 3gb file, is that allowed right now?
11514
+ if (current != -1 && !isNaN(params.fileSize) && params.fileSize) {
11515
+ current += exports.MathUtils.Round(params.fileSize / 1024 / 1024 / 1024, 3);
11516
+ }
11517
+ if (max == null) {
11518
+ return {
11519
+ allowed: false,
11520
+ errorText: "We apologize but file uploads are currently unavailable."
11521
+ };
11522
+ }
11523
+ else if (max == -1) {
11524
+ return {
11525
+ allowed: true
11526
+ };
11527
+ }
11528
+ else if (current == -1) {
11529
+ return {
11530
+ allowed: false,
11531
+ errorText: "We apologize but file uploads are currently unavailable."
11532
+ };
11533
+ }
11534
+ else if (current >= max) {
11535
+ return {
11536
+ allowed: false,
11537
+ errorText: `You have reached the maximum amount of storage allowed for your account. You are limited to ${max.toLocaleString()} ${max == 1 ? "GB" : "GBs"} of storage.`
11538
+ };
11539
+ }
11540
+ return {
11541
+ allowed: true
11542
+ };
11543
+ });
11544
+ }
11545
+ Assert.GetCanUploadFile = GetCanUploadFile;
11546
+ /**
11547
+ * Returns the file limit for an account.
11548
+ * If -1 is returned then it is unlimited.
11549
+ * @param params
11550
+ * @returns
11551
+ */
11552
+ function GetFileGBLimit(params) {
11553
+ return __awaiter(this, void 0, void 0, function* () {
11554
+ if (!params.api) {
11555
+ params.api = exports.ENVIRONMENT.Api().GetGuardianApi();
11556
+ }
11557
+ if (!params.accountId) {
11558
+ params.accountId = exports.ENVIRONMENT.Api().GetAccountId();
11559
+ }
11560
+ const max = yield GetNumericLimit({
11561
+ accountId: params.accountId,
11562
+ key: ELimit.MaxStorageUseGigabytes,
11563
+ onEmptyValue: 0,
11564
+ onErrorValue: null,
11565
+ api: params.api
11566
+ });
11567
+ // Our error so we'll just allow unlimited for the time being.
11568
+ if (max == null) {
11569
+ return -1;
11570
+ }
11571
+ return max;
11572
+ });
11573
+ }
11574
+ Assert.GetFileGBLimit = GetFileGBLimit;
11575
+ /**
11576
+ * Returns the maximum file import size for an account.
11577
+ * If -1 is returned then it is unlimited.
11578
+ * @param params
11579
+ * @returns
11580
+ */
11581
+ function GetMaxImportSizeGB(params) {
11582
+ return __awaiter(this, void 0, void 0, function* () {
11583
+ if (!params.api) {
11584
+ params.api = exports.ENVIRONMENT.Api().GetGuardianApi();
11585
+ }
11586
+ if (!params.accountId) {
11587
+ params.accountId = exports.ENVIRONMENT.Api().GetAccountId();
11588
+ }
11589
+ const max = yield GetNumericLimit({
11590
+ accountId: params.accountId,
11591
+ key: ELimit.MaxFileImportSizeGigabytes,
11592
+ onEmptyValue: 0,
11593
+ onErrorValue: null,
11594
+ api: params.api
11595
+ });
11596
+ // Our error so we'll just allow unlimited for the time being.
11597
+ if (max == null) {
11598
+ return -1;
11599
+ }
11600
+ return max;
11601
+ });
11602
+ }
11603
+ Assert.GetMaxImportSizeGB = GetMaxImportSizeGB;
11604
+ /**
11605
+ * Returns if entity creation is allowed for the account.
11606
+ */
11607
+ function GetCanCreateEntity(params) {
11608
+ return __awaiter(this, void 0, void 0, function* () {
11609
+ if (!params.getters) {
11610
+ params.getters = exports.ENVIRONMENT.Api();
11611
+ }
11612
+ if (!params.accountId) {
11613
+ params.accountId = params.getters.GetAccountId();
11614
+ }
11615
+ let current = -1;
11616
+ let max = yield GetNumericLimit({
11617
+ accountId: params.accountId,
11618
+ key: ELimit.MaxEntitiesCount,
11619
+ onEmptyValue: 0,
11620
+ onErrorValue: null,
11621
+ api: params.getters.GetGuardianApi()
11622
+ });
11623
+ if (max != null && max > 0) {
11624
+ try {
11625
+ const api = params.getters.GetBruceApi({
11626
+ accountId: params.accountId
11627
+ });
11628
+ const stats = yield api.GET("account/summary-stats");
11629
+ if (stats === null || stats === void 0 ? void 0 : stats.ID) {
11630
+ const result = stats === null || stats === void 0 ? void 0 : stats.Result;
11631
+ try {
11632
+ const resJson = JSON.parse(result);
11633
+ const eCount = resJson.EntitiesCount;
11634
+ // Still counting so we'll give unlimited for the time being.
11635
+ // This count can take ages so we won't make the user wait.
11636
+ if (eCount == null || isNaN(eCount)) {
11637
+ max = -1;
11638
+ }
11639
+ else {
11640
+ current = eCount;
11641
+ }
11642
+ }
11643
+ // We won't count this as a fatal error because who knows how stable this is.
11644
+ catch (e) {
11645
+ console.error(e);
11646
+ }
11647
+ }
11648
+ // Unknown so we'll just give unlimited for the time being.
11649
+ else {
11650
+ max = -1;
11651
+ }
11652
+ }
11653
+ catch (e) {
11654
+ console.error(e);
11655
+ max = null;
11656
+ }
11657
+ }
11658
+ // Optional param for an entity count to add to the current entity amount.
11659
+ // Eg: user is creating 3 entities, is that allowed right now?
11660
+ if (current != -1 && !isNaN(params.count) && params.count) {
11661
+ current += params.count;
11662
+ // Remove one since we do an inclusive check later in the code.
11663
+ current -= 1;
11664
+ }
11665
+ if (max == null) {
11666
+ return {
11667
+ allowed: false,
11668
+ errorText: "We apologize but Entity creation is currently unavailable."
11669
+ };
11670
+ }
11671
+ else if (max == -1) {
11672
+ return {
11673
+ allowed: true
11674
+ };
11675
+ }
11676
+ else if (current == -1) {
11677
+ return {
11678
+ allowed: false,
11679
+ errorText: "We apologize but Entity creation is currently unavailable."
11680
+ };
11681
+ }
11682
+ else if (current >= max) {
11683
+ return {
11684
+ allowed: false,
11685
+ errorText: `You have reached the maximum number of Entities allowed for your account. You are limited to ${max.toLocaleString()} ${max == 1 ? "Entity" : "Entities"}.`
11686
+ };
11687
+ }
11688
+ return {
11689
+ allowed: true
11690
+ };
11691
+ });
11692
+ }
11693
+ Assert.GetCanCreateEntity = GetCanCreateEntity;
11694
+ /**
11695
+ * Returns the entity limit for an account.
11696
+ * If -1 is returned then it is unlimited.
11697
+ */
11698
+ function GetEntityLimit(params) {
11699
+ return __awaiter(this, void 0, void 0, function* () {
11700
+ if (!params.api) {
11701
+ params.api = exports.ENVIRONMENT.Api().GetGuardianApi();
11702
+ }
11703
+ if (!params.accountId) {
11704
+ params.accountId = exports.ENVIRONMENT.Api().GetAccountId();
11705
+ }
11706
+ const max = yield GetNumericLimit({
11707
+ accountId: params.accountId,
11708
+ key: ELimit.MaxEntitiesCount,
11709
+ onEmptyValue: 0,
11710
+ onErrorValue: null,
11711
+ api: params.api
11712
+ });
11713
+ // Our error so we'll just allow unlimited for the time being.
11714
+ if (max == null) {
11715
+ return -1;
11716
+ }
11717
+ return max;
11718
+ });
11719
+ }
11720
+ Assert.GetEntityLimit = GetEntityLimit;
11721
+ /**
11722
+ * Returns if Operator access is allowed for the account.
11723
+ * @param params
11724
+ * @returns
11725
+ */
11726
+ function GetCanOpenOperator(params) {
11727
+ return __awaiter(this, void 0, void 0, function* () {
11728
+ if (!params.api) {
11729
+ params.api = exports.ENVIRONMENT.Api().GetGuardianApi();
11730
+ }
11731
+ if (!params.accountId) {
11732
+ params.accountId = exports.ENVIRONMENT.Api().GetAccountId();
11733
+ }
11734
+ const allowed = yield GetBooleanLimit({
11735
+ accountId: params.accountId,
11736
+ key: ELimit.OperatorAccessAllowed,
11737
+ onEmptyValue: false,
11738
+ onErrorValue: null,
11739
+ api: params.api
11740
+ });
11741
+ if (allowed == null) {
11742
+ return {
11743
+ allowed: false,
11744
+ errorText: "We apologize but Operator access is currently unavailable."
11745
+ };
11746
+ }
11747
+ else if (allowed) {
11748
+ return {
11749
+ allowed: true
11750
+ };
11751
+ }
11752
+ else {
11753
+ return {
11754
+ allowed: false,
11755
+ errorText: "You do not have access to Operator."
11756
+ };
11757
+ }
11758
+ });
11759
+ }
11760
+ Assert.GetCanOpenOperator = GetCanOpenOperator;
11761
+ /**
11762
+ * Returns SSO login settings for the account.
11763
+ * @param params
11764
+ * @returns
11765
+ */
11766
+ function GetSSOLoginSettings(params) {
11767
+ return __awaiter(this, void 0, void 0, function* () {
11768
+ if (!params.api) {
11769
+ params.api = exports.ENVIRONMENT.Api().GetGuardianApi();
11770
+ }
11771
+ if (!params.accountId) {
11772
+ params.accountId = exports.ENVIRONMENT.Api().GetAccountId();
11773
+ }
11774
+ const enabled = yield GetBooleanLimit({
11775
+ accountId: params.accountId,
11776
+ key: ELimit.EnableSSOLogin,
11777
+ onEmptyValue: false,
11778
+ onErrorValue: null,
11779
+ api: params.api
11780
+ });
11781
+ const autoRedirect = yield GetBooleanLimit({
11782
+ accountId: params.accountId,
11783
+ key: ELimit.EnableSSOLoginAutoRedirect,
11784
+ onEmptyValue: false,
11785
+ onErrorValue: null,
11786
+ api: params.api
11787
+ });
11788
+ if (enabled == null || autoRedirect == null) {
11789
+ return {
11790
+ enabled: false,
11791
+ autoRedirect: false,
11792
+ errorText: "We apologize but SSO login is currently unavailable."
11793
+ };
11794
+ }
11795
+ return {
11796
+ enabled: enabled,
11797
+ autoRedirect: autoRedirect
11798
+ };
11799
+ });
11800
+ }
11801
+ Assert.GetSSOLoginSettings = GetSSOLoginSettings;
11802
+ /**
11803
+ * Returns if public access is denied to this account.
11804
+ * @param params
11805
+ * @returns
11806
+ */
11807
+ function GetDenyPublicAccess(params) {
11808
+ return __awaiter(this, void 0, void 0, function* () {
11809
+ if (!params.api) {
11810
+ params.api = exports.ENVIRONMENT.Api().GetGuardianApi();
11811
+ }
11812
+ if (!params.accountId) {
11813
+ params.accountId = exports.ENVIRONMENT.Api().GetAccountId();
11814
+ }
11815
+ const enabled = yield GetBooleanLimit({
11816
+ accountId: params.accountId,
11817
+ key: ELimit.DenyPublicAccess,
11818
+ // If empty then we'll assume we are not denying public access.
11819
+ onEmptyValue: false,
11820
+ // If we crash we are denying public access.
11821
+ onErrorValue: true,
11822
+ api: params.api
11823
+ });
11824
+ return enabled;
11825
+ });
11826
+ }
11827
+ Assert.GetDenyPublicAccess = GetDenyPublicAccess;
11828
+ })(Assert = AccountLimits.Assert || (AccountLimits.Assert = {}));
11829
+ /**
11830
+ * Cache key for requesting account limits for a specific account.
11831
+ * @param accountId
11832
+ */
11833
+ function GetLimitsCacheKey(accountId) {
11834
+ return exports.Api.ECacheKey.AccountLimits + exports.Api.ECacheKey.Id + accountId;
11835
+ }
11836
+ AccountLimits.GetLimitsCacheKey = GetLimitsCacheKey;
11837
+ })(exports.AccountLimits || (exports.AccountLimits = {}));
11838
+
10675
11839
  (function (EncryptUtils) {
10676
11840
  // https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript
10677
11841
  function Cyrb53Hash(str, seed = 0) {
@@ -11684,7 +12848,7 @@
11684
12848
  })(exports.DataSource || (exports.DataSource = {}));
11685
12849
 
11686
12850
  // This is updated with the package.json version on build.
11687
- const VERSION = "4.1.5";
12851
+ const VERSION = "4.1.6";
11688
12852
 
11689
12853
  exports.VERSION = VERSION;
11690
12854
  exports.AbstractApi = AbstractApi;