bruce-models 3.2.5 → 3.2.7
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.
- package/dist/bruce-models.es5.js +148 -10
- package/dist/bruce-models.es5.js.map +1 -1
- package/dist/bruce-models.umd.js +148 -10
- package/dist/bruce-models.umd.js.map +1 -1
- package/dist/lib/api/api-getters.js +12 -3
- package/dist/lib/api/api-getters.js.map +1 -1
- package/dist/lib/api/bruce-api.js +19 -0
- package/dist/lib/api/bruce-api.js.map +1 -1
- package/dist/lib/bruce-models.js +1 -1
- package/dist/lib/client-file/client-file.js +14 -4
- package/dist/lib/client-file/client-file.js.map +1 -1
- package/dist/lib/entity/entity-attribute.js +63 -0
- package/dist/lib/entity/entity-attribute.js.map +1 -1
- package/dist/lib/entity/entity.js +21 -0
- package/dist/lib/entity/entity.js.map +1 -1
- package/dist/lib/server/hosting-location.js +18 -2
- package/dist/lib/server/hosting-location.js.map +1 -1
- package/dist/types/api/api-getters.d.ts +2 -0
- package/dist/types/api/bruce-api.d.ts +8 -0
- package/dist/types/bruce-models.d.ts +1 -1
- package/dist/types/client-file/client-file.d.ts +2 -0
- package/dist/types/entity/entity-attribute.d.ts +18 -0
- package/dist/types/entity/entity.d.ts +9 -0
- package/dist/types/server/hosting-location.d.ts +3 -0
- package/package.json +1 -1
package/dist/bruce-models.umd.js
CHANGED
|
@@ -1128,13 +1128,28 @@
|
|
|
1128
1128
|
*/
|
|
1129
1129
|
function GetKeyByAccountId(params) {
|
|
1130
1130
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1131
|
-
let { accountId, apiSettings, api, req } = params;
|
|
1131
|
+
let { accountId, apiSettings, api, account, req } = params;
|
|
1132
1132
|
if (!accountId && !apiSettings) {
|
|
1133
1133
|
throw ("Invalid accountId or apiSettings");
|
|
1134
1134
|
}
|
|
1135
1135
|
if (!api) {
|
|
1136
1136
|
api = exports.ENVIRONMENT.Api().GetGuardianApi();
|
|
1137
1137
|
}
|
|
1138
|
+
// We'll prioritize account record if provided.
|
|
1139
|
+
if (accountId && !account) {
|
|
1140
|
+
account = (yield exports.Account.Get({
|
|
1141
|
+
accountId,
|
|
1142
|
+
api,
|
|
1143
|
+
req
|
|
1144
|
+
})).account;
|
|
1145
|
+
}
|
|
1146
|
+
if (account === null || account === void 0 ? void 0 : account["HostingLocation.Key"]) {
|
|
1147
|
+
return {
|
|
1148
|
+
key: account["HostingLocation.Key"],
|
|
1149
|
+
isLegacy: false
|
|
1150
|
+
};
|
|
1151
|
+
}
|
|
1152
|
+
// Fallback to settings JSON for older records.
|
|
1138
1153
|
const settings = apiSettings ? apiSettings : (yield exports.Account.GetAppSettings({
|
|
1139
1154
|
api,
|
|
1140
1155
|
accountId,
|
|
@@ -1166,12 +1181,13 @@
|
|
|
1166
1181
|
*/
|
|
1167
1182
|
function GetByAccountId(params) {
|
|
1168
1183
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1169
|
-
let { accountId, apiSettings, api, req } = params;
|
|
1184
|
+
let { accountId, apiSettings, api, req, account } = params;
|
|
1170
1185
|
if (!api) {
|
|
1171
1186
|
api = exports.ENVIRONMENT.Api().GetGuardianApi();
|
|
1172
1187
|
}
|
|
1173
1188
|
const data = yield GetKeyByAccountId({
|
|
1174
1189
|
accountId,
|
|
1190
|
+
account,
|
|
1175
1191
|
apiSettings,
|
|
1176
1192
|
api,
|
|
1177
1193
|
req
|
|
@@ -1357,6 +1373,25 @@
|
|
|
1357
1373
|
GetCdnBaseUrl() {
|
|
1358
1374
|
return this.cdnBaseUrl;
|
|
1359
1375
|
}
|
|
1376
|
+
/**
|
|
1377
|
+
* Returns a url routed through the API's CDN.
|
|
1378
|
+
* If the CDN is not enabled for the account, this will return null.
|
|
1379
|
+
* @param url suffix to append to the base url.
|
|
1380
|
+
* @param urlParams
|
|
1381
|
+
* @returns
|
|
1382
|
+
*/
|
|
1383
|
+
ConstructCdnUrl(url, urlParams) {
|
|
1384
|
+
if (!this.cdnBaseUrl) {
|
|
1385
|
+
return null;
|
|
1386
|
+
}
|
|
1387
|
+
let cdnUrl = this.cdnBaseUrl + url;
|
|
1388
|
+
if (!urlParams) {
|
|
1389
|
+
urlParams = new URLSearchParams();
|
|
1390
|
+
}
|
|
1391
|
+
urlParams.set("accountId", this.accountId);
|
|
1392
|
+
cdnUrl += "?" + urlParams.toString();
|
|
1393
|
+
return cdnUrl;
|
|
1394
|
+
}
|
|
1360
1395
|
/**
|
|
1361
1396
|
* Warning: This will cancel the init process.
|
|
1362
1397
|
* The init process loads a region specific endpoint.
|
|
@@ -1664,7 +1699,7 @@
|
|
|
1664
1699
|
if (!params) {
|
|
1665
1700
|
params = {};
|
|
1666
1701
|
}
|
|
1667
|
-
let { accountId, env } = params;
|
|
1702
|
+
let { accountId, env, loadConfig, loadWebSocket } = params;
|
|
1668
1703
|
accountId = accountId ? accountId : this.accountId;
|
|
1669
1704
|
env = env ? env : this.env;
|
|
1670
1705
|
const key = `${accountId}-${env}`;
|
|
@@ -1672,7 +1707,11 @@
|
|
|
1672
1707
|
this.bruce[key] = new exports.BruceApi.Api({
|
|
1673
1708
|
accountId,
|
|
1674
1709
|
env,
|
|
1675
|
-
|
|
1710
|
+
loadConfig: loadConfig,
|
|
1711
|
+
loadWebSocket: loadWebSocket,
|
|
1712
|
+
guardian: this.GetGuardianApi({
|
|
1713
|
+
env
|
|
1714
|
+
}),
|
|
1676
1715
|
});
|
|
1677
1716
|
this.bruce[key].SetSessionId(this.sessionId);
|
|
1678
1717
|
}
|
|
@@ -1689,7 +1728,12 @@
|
|
|
1689
1728
|
accountId: this.accountId,
|
|
1690
1729
|
env: this.env,
|
|
1691
1730
|
getApi: (accountId, env) => {
|
|
1692
|
-
return this.GetBruceApi({
|
|
1731
|
+
return this.GetBruceApi({
|
|
1732
|
+
accountId,
|
|
1733
|
+
env,
|
|
1734
|
+
loadWebSocket: this.accountId == accountId,
|
|
1735
|
+
loadConfig: this.accountId == accountId
|
|
1736
|
+
});
|
|
1693
1737
|
}
|
|
1694
1738
|
};
|
|
1695
1739
|
}
|
|
@@ -2882,6 +2926,27 @@
|
|
|
2882
2926
|
return null;
|
|
2883
2927
|
}
|
|
2884
2928
|
Entity.GetValue = GetValue;
|
|
2929
|
+
/**
|
|
2930
|
+
* Removes a value from an entity.
|
|
2931
|
+
* This will mutate the entity record and run "delete" on the object property.
|
|
2932
|
+
* @param params
|
|
2933
|
+
*/
|
|
2934
|
+
function RemoveValue(params) {
|
|
2935
|
+
const { entity: data, path } = params;
|
|
2936
|
+
let curData = data;
|
|
2937
|
+
for (let i = 0; i < path.length; i++) {
|
|
2938
|
+
const step = path[i];
|
|
2939
|
+
if (!curData[step]) {
|
|
2940
|
+
return;
|
|
2941
|
+
}
|
|
2942
|
+
if (i >= path.length - 1) {
|
|
2943
|
+
delete curData[step];
|
|
2944
|
+
return;
|
|
2945
|
+
}
|
|
2946
|
+
curData = curData[step];
|
|
2947
|
+
}
|
|
2948
|
+
}
|
|
2949
|
+
Entity.RemoveValue = RemoveValue;
|
|
2885
2950
|
/**
|
|
2886
2951
|
* Calculates an entity's name based on attribute priority set in the type.
|
|
2887
2952
|
* @param params
|
|
@@ -6052,6 +6117,69 @@
|
|
|
6052
6117
|
return GetAttribute(item.Structure, path.slice(1));
|
|
6053
6118
|
}
|
|
6054
6119
|
EntityAttribute.GetAttribute = GetAttribute;
|
|
6120
|
+
/**
|
|
6121
|
+
* Removes an attribute from a provided hierarchy of attributes.
|
|
6122
|
+
* Eg: Use the path: ["Bruce", "ID"] to remove the "ID" attribute.
|
|
6123
|
+
* This will mutate the items array.
|
|
6124
|
+
* @param items
|
|
6125
|
+
* @param path
|
|
6126
|
+
*/
|
|
6127
|
+
function RemoveAttribute(items, path) {
|
|
6128
|
+
if (!items || !path || !path.length) {
|
|
6129
|
+
return;
|
|
6130
|
+
}
|
|
6131
|
+
const key = path[0];
|
|
6132
|
+
if (path.length === 1) {
|
|
6133
|
+
// If we're at the last key in the path, remove the item from the items array.
|
|
6134
|
+
const index = items.findIndex((i) => i.Key === key);
|
|
6135
|
+
if (index !== -1) {
|
|
6136
|
+
items.splice(index, 1);
|
|
6137
|
+
}
|
|
6138
|
+
return;
|
|
6139
|
+
}
|
|
6140
|
+
// If we're not at the end of the path, dig further.
|
|
6141
|
+
const item = items.find((i) => i.Key === key);
|
|
6142
|
+
if (item && item.Structure) {
|
|
6143
|
+
RemoveAttribute(item.Structure, path.slice(1));
|
|
6144
|
+
}
|
|
6145
|
+
}
|
|
6146
|
+
EntityAttribute.RemoveAttribute = RemoveAttribute;
|
|
6147
|
+
/**
|
|
6148
|
+
* Adds an attribute to a provided hierarchy of attributes.
|
|
6149
|
+
* Eg: Use the path: ["Bruce", "ID"] to add the "ID" attribute.
|
|
6150
|
+
* This will mutate the items array.
|
|
6151
|
+
* This requires the path to be valid and for a parent attribute to exist.
|
|
6152
|
+
* @param items
|
|
6153
|
+
* @param path
|
|
6154
|
+
* @param attribute
|
|
6155
|
+
*/
|
|
6156
|
+
function AddAttribute(items, path, attribute) {
|
|
6157
|
+
const key = path[0];
|
|
6158
|
+
if (path.length === 1) {
|
|
6159
|
+
// If we're at the last key in the path, add the attribute to the items array.
|
|
6160
|
+
const index = items.findIndex((i) => i.Key === key);
|
|
6161
|
+
if (index !== -1) {
|
|
6162
|
+
// Overwrite existing attribute if it already exists.
|
|
6163
|
+
items[index] = attribute;
|
|
6164
|
+
}
|
|
6165
|
+
else {
|
|
6166
|
+
// Add new attribute if it doesn't exist.
|
|
6167
|
+
items.push(attribute);
|
|
6168
|
+
}
|
|
6169
|
+
return;
|
|
6170
|
+
}
|
|
6171
|
+
// If we're not at the end of the path, dig further.
|
|
6172
|
+
let item = items.find((i) => i.Key === key);
|
|
6173
|
+
if (!item) {
|
|
6174
|
+
item = { Key: key, Structure: [] };
|
|
6175
|
+
items.push(item);
|
|
6176
|
+
}
|
|
6177
|
+
if (!item.Structure) {
|
|
6178
|
+
item.Structure = [];
|
|
6179
|
+
}
|
|
6180
|
+
AddAttribute(item.Structure, path.slice(1), attribute);
|
|
6181
|
+
}
|
|
6182
|
+
EntityAttribute.AddAttribute = AddAttribute;
|
|
6055
6183
|
})(exports.EntityAttribute || (exports.EntityAttribute = {}));
|
|
6056
6184
|
|
|
6057
6185
|
(function (Uploader) {
|
|
@@ -6151,11 +6279,16 @@
|
|
|
6151
6279
|
* @returns
|
|
6152
6280
|
*/
|
|
6153
6281
|
function GetUrl(params) {
|
|
6154
|
-
let { api, fileId } = params;
|
|
6282
|
+
let { api, fileId, viaCdn } = params;
|
|
6155
6283
|
if (!api) {
|
|
6156
6284
|
api = exports.ENVIRONMENT.Api().GetBruceApi();
|
|
6157
6285
|
}
|
|
6158
|
-
|
|
6286
|
+
const urlSuffix = `file/${fileId}`;
|
|
6287
|
+
const cdnUrl = viaCdn ? api.ConstructCdnUrl(urlSuffix) : null;
|
|
6288
|
+
if (cdnUrl) {
|
|
6289
|
+
return cdnUrl;
|
|
6290
|
+
}
|
|
6291
|
+
return `${api.GetBaseUrl()}${urlSuffix}`;
|
|
6159
6292
|
}
|
|
6160
6293
|
ClientFile.GetUrl = GetUrl;
|
|
6161
6294
|
/**
|
|
@@ -6164,11 +6297,16 @@
|
|
|
6164
6297
|
* @returns
|
|
6165
6298
|
*/
|
|
6166
6299
|
function GetUrlWithExt(params) {
|
|
6167
|
-
let { api, file } = params;
|
|
6300
|
+
let { api, file, viaCdn } = params;
|
|
6168
6301
|
if (!api) {
|
|
6169
6302
|
api = exports.ENVIRONMENT.Api().GetBruceApi();
|
|
6170
6303
|
}
|
|
6171
|
-
|
|
6304
|
+
const urlSuffix = file.FileExt ? `file/${file.ID}${file.FileExt}` : `file/${file.ID}`;
|
|
6305
|
+
const cdnUrl = viaCdn ? api.ConstructCdnUrl(urlSuffix) : null;
|
|
6306
|
+
if (cdnUrl) {
|
|
6307
|
+
return cdnUrl;
|
|
6308
|
+
}
|
|
6309
|
+
return `${api.GetBaseUrl()}${urlSuffix}`;
|
|
6172
6310
|
}
|
|
6173
6311
|
ClientFile.GetUrlWithExt = GetUrlWithExt;
|
|
6174
6312
|
/**
|
|
@@ -10229,7 +10367,7 @@
|
|
|
10229
10367
|
DataSource.GetList = GetList;
|
|
10230
10368
|
})(exports.DataSource || (exports.DataSource = {}));
|
|
10231
10369
|
|
|
10232
|
-
const VERSION = "3.2.
|
|
10370
|
+
const VERSION = "3.2.7";
|
|
10233
10371
|
|
|
10234
10372
|
exports.VERSION = VERSION;
|
|
10235
10373
|
exports.AbstractApi = AbstractApi;
|