@eluvio/elv-client-js 4.2.18 → 4.2.19
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/package.json +1 -1
- package/src/client/ContentAccess.js +62 -53
package/package.json
CHANGED
|
@@ -20,8 +20,6 @@ const {
|
|
|
20
20
|
} = require("../Validation");
|
|
21
21
|
|
|
22
22
|
const MergeWith = require("lodash/mergeWith");
|
|
23
|
-
const LodashSet = require("lodash/set");
|
|
24
|
-
const LodashGet = require("lodash/get");
|
|
25
23
|
|
|
26
24
|
// Note: Keep these ordered by most-restrictive to least-restrictive
|
|
27
25
|
exports.permissionLevels = {
|
|
@@ -585,7 +583,7 @@ exports.ContentObjects = async function({libraryId, filterOptions={}}) {
|
|
|
585
583
|
*
|
|
586
584
|
* @returns {Promise<Object>} - Description of content object
|
|
587
585
|
*/
|
|
588
|
-
exports.ContentObject = async function({objectId, versionHash, writeToken, noCache
|
|
586
|
+
exports.ContentObject = async function({objectId, versionHash, writeToken, noCache}) {
|
|
589
587
|
this.Log(`Retrieving content object: ${writeToken || versionHash || objectId}`);
|
|
590
588
|
|
|
591
589
|
if(writeToken) {
|
|
@@ -600,9 +598,7 @@ exports.ContentObject = async function({objectId, versionHash, writeToken, noCac
|
|
|
600
598
|
if(noCache || !this.objectInfo[id] || Date.now() - this.objectInfo[id].retrievedAt > 30000) {
|
|
601
599
|
let path = UrlJoin("q", id);
|
|
602
600
|
const info = await this.HttpClient.RequestJsonBody({
|
|
603
|
-
headers: {
|
|
604
|
-
Authorization: `Bearer ${authorizationToken || await this.authClient.AuthorizationToken({objectId, versionHash})}`,
|
|
605
|
-
},
|
|
601
|
+
headers: await this.authClient.AuthorizationHeader({objectId, versionHash}),
|
|
606
602
|
method: "GET",
|
|
607
603
|
path: path,
|
|
608
604
|
queryParams: {
|
|
@@ -630,7 +626,7 @@ exports.ContentObject = async function({objectId, versionHash, writeToken, noCac
|
|
|
630
626
|
*
|
|
631
627
|
* @returns {Promise<string>} - The account address of the owner
|
|
632
628
|
*/
|
|
633
|
-
exports.ContentObjectOwner = async function({objectId, versionHash
|
|
629
|
+
exports.ContentObjectOwner = async function({objectId, versionHash}) {
|
|
634
630
|
versionHash ? ValidateVersion(versionHash) : ValidateObject(objectId);
|
|
635
631
|
|
|
636
632
|
if(versionHash) {
|
|
@@ -639,7 +635,7 @@ exports.ContentObjectOwner = async function({objectId, versionHash, authorizatio
|
|
|
639
635
|
|
|
640
636
|
this.Log(`Retrieving content object owner: ${objectId}`);
|
|
641
637
|
|
|
642
|
-
return this.utils.HashToAddress((await this.ContentObject({objectId, versionHash
|
|
638
|
+
return this.utils.HashToAddress((await this.ContentObject({objectId, versionHash})).content_profile.owner);
|
|
643
639
|
};
|
|
644
640
|
|
|
645
641
|
/**
|
|
@@ -653,7 +649,7 @@ exports.ContentObjectOwner = async function({objectId, versionHash, authorizatio
|
|
|
653
649
|
*
|
|
654
650
|
* @returns {Promise<string>} - Tenant ID of the object
|
|
655
651
|
*/
|
|
656
|
-
exports.ContentObjectTenantId = async function({objectId, versionHash
|
|
652
|
+
exports.ContentObjectTenantId = async function({objectId, versionHash}) {
|
|
657
653
|
versionHash ? ValidateVersion(versionHash) : ValidateObject(objectId);
|
|
658
654
|
|
|
659
655
|
if(versionHash) {
|
|
@@ -663,7 +659,7 @@ exports.ContentObjectTenantId = async function({objectId, versionHash, authoriza
|
|
|
663
659
|
// Cache results because they will never change
|
|
664
660
|
if(!this.objectTenantIds[objectId]) {
|
|
665
661
|
try {
|
|
666
|
-
this.objectTenantIds[objectId] = (await this.ContentObject({objectId, versionHash
|
|
662
|
+
this.objectTenantIds[objectId] = (await this.ContentObject({objectId, versionHash})).content_profile.tenant_id;
|
|
667
663
|
} catch(error) {
|
|
668
664
|
error.message = `Unable to determine tenant ID for ${versionHash || objectId}`;
|
|
669
665
|
throw error;
|
|
@@ -684,7 +680,7 @@ exports.ContentObjectTenantId = async function({objectId, versionHash, authoriza
|
|
|
684
680
|
*
|
|
685
681
|
* @returns {Promise<string>} - Library ID of the object
|
|
686
682
|
*/
|
|
687
|
-
exports.ContentObjectLibraryId = async function({objectId, versionHash
|
|
683
|
+
exports.ContentObjectLibraryId = async function({objectId, versionHash}) {
|
|
688
684
|
versionHash ? ValidateVersion(versionHash) : ValidateObject(objectId);
|
|
689
685
|
|
|
690
686
|
if(versionHash) {
|
|
@@ -694,7 +690,7 @@ exports.ContentObjectLibraryId = async function({objectId, versionHash, authoriz
|
|
|
694
690
|
// Cache results because they will never change
|
|
695
691
|
if(!this.objectLibraryIds[objectId]) {
|
|
696
692
|
try {
|
|
697
|
-
this.objectLibraryIds[objectId] = (await this.ContentObject({objectId, versionHash
|
|
693
|
+
this.objectLibraryIds[objectId] = (await this.ContentObject({objectId, versionHash})).qlib_id;
|
|
698
694
|
} catch(error) {
|
|
699
695
|
error.message = `Unable to determine library ID for ${versionHash || objectId}`;
|
|
700
696
|
throw error;
|
|
@@ -713,43 +709,56 @@ exports.ProduceMetadataLinks = async function({
|
|
|
713
709
|
authorizationToken,
|
|
714
710
|
noAuth
|
|
715
711
|
}) {
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
const Traverse = async (currentPath="") => {
|
|
719
|
-
const currentMetadata = !currentPath ? metadata : LodashGet(metadata, currentPath.split("/"));
|
|
720
|
-
|
|
721
|
-
// Primitive
|
|
722
|
-
if(!currentMetadata || typeof currentMetadata !== "object") {
|
|
723
|
-
return;
|
|
724
|
-
}
|
|
712
|
+
// Primitive
|
|
713
|
+
if(!metadata || typeof metadata !== "object") { return metadata; }
|
|
725
714
|
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
715
|
+
// Array
|
|
716
|
+
if(Array.isArray(metadata)) {
|
|
717
|
+
return await this.utils.LimitedMap(
|
|
718
|
+
5,
|
|
719
|
+
metadata,
|
|
720
|
+
async (entry, i) => await this.ProduceMetadataLinks({
|
|
721
|
+
libraryId,
|
|
722
|
+
objectId,
|
|
723
|
+
versionHash,
|
|
724
|
+
path: UrlJoin(path, i.toString()),
|
|
725
|
+
metadata: entry,
|
|
726
|
+
authorizationToken,
|
|
727
|
+
noAuth
|
|
728
|
+
})
|
|
729
|
+
);
|
|
730
|
+
}
|
|
732
731
|
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
} else {
|
|
744
|
-
for(let key of Object.keys(currentMetadata)) {
|
|
745
|
-
await Traverse(UrlJoin(currentPath, key))
|
|
746
|
-
}
|
|
747
|
-
}
|
|
732
|
+
// Object
|
|
733
|
+
if(metadata["/"] &&
|
|
734
|
+
(metadata["/"].match(/\.\/(rep|files)\/.+/) ||
|
|
735
|
+
metadata["/"].match(/^\/?qfab\/([\w]+)\/?(rep|files)\/.+/)))
|
|
736
|
+
{
|
|
737
|
+
// Is file or rep link - produce a url
|
|
738
|
+
return {
|
|
739
|
+
...metadata,
|
|
740
|
+
url: await this.LinkUrl({libraryId, objectId, versionHash, linkPath: path, authorizationToken, noAuth})
|
|
741
|
+
};
|
|
748
742
|
}
|
|
749
743
|
|
|
750
|
-
|
|
744
|
+
let result = {};
|
|
745
|
+
await this.utils.LimitedMap(
|
|
746
|
+
5,
|
|
747
|
+
Object.keys(metadata),
|
|
748
|
+
async key => {
|
|
749
|
+
result[key] = await this.ProduceMetadataLinks({
|
|
750
|
+
libraryId,
|
|
751
|
+
objectId,
|
|
752
|
+
versionHash,
|
|
753
|
+
path: UrlJoin(path, key),
|
|
754
|
+
metadata: metadata[key],
|
|
755
|
+
authorizationToken,
|
|
756
|
+
noAuth
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
);
|
|
751
760
|
|
|
752
|
-
return
|
|
761
|
+
return result;
|
|
753
762
|
};
|
|
754
763
|
|
|
755
764
|
exports.MetadataAuth = async function({
|
|
@@ -1047,7 +1056,7 @@ exports.ContentObjectVersions = async function({libraryId, objectId}) {
|
|
|
1047
1056
|
return this.HttpClient.RequestJsonBody({
|
|
1048
1057
|
headers: await this.authClient.AuthorizationHeader({libraryId, objectId}),
|
|
1049
1058
|
method: "GET",
|
|
1050
|
-
path
|
|
1059
|
+
path: path
|
|
1051
1060
|
});
|
|
1052
1061
|
};
|
|
1053
1062
|
|
|
@@ -1061,13 +1070,13 @@ exports.ContentObjectVersions = async function({libraryId, objectId}) {
|
|
|
1061
1070
|
*
|
|
1062
1071
|
* @returns {Promise<string>} - The latest version hash of the object
|
|
1063
1072
|
*/
|
|
1064
|
-
exports.LatestVersionHash = async function({objectId, versionHash
|
|
1073
|
+
exports.LatestVersionHash = async function({objectId, versionHash}) {
|
|
1065
1074
|
if(versionHash) {
|
|
1066
1075
|
objectId = this.utils.DecodeVersionHash(versionHash).objectId;
|
|
1067
1076
|
}
|
|
1068
1077
|
|
|
1069
1078
|
try {
|
|
1070
|
-
return (await this.ContentObject({objectId, noCache: true
|
|
1079
|
+
return (await this.ContentObject({objectId, noCache: true})).hash;
|
|
1071
1080
|
} catch(error) {
|
|
1072
1081
|
error.message = `Unable to determine latest version hash for ${versionHash || objectId}`;
|
|
1073
1082
|
throw error;
|
|
@@ -1166,11 +1175,11 @@ exports.PlayoutPathResolution = async function({
|
|
|
1166
1175
|
authorizationToken
|
|
1167
1176
|
}) {
|
|
1168
1177
|
if(!libraryId) {
|
|
1169
|
-
libraryId = await this.ContentObjectLibraryId({objectId
|
|
1178
|
+
libraryId = await this.ContentObjectLibraryId({objectId});
|
|
1170
1179
|
}
|
|
1171
1180
|
|
|
1172
1181
|
if(!versionHash) {
|
|
1173
|
-
versionHash = await this.LatestVersionHash({objectId
|
|
1182
|
+
versionHash = await this.LatestVersionHash({objectId});
|
|
1174
1183
|
}
|
|
1175
1184
|
|
|
1176
1185
|
let path = UrlJoin("qlibs", libraryId, "q", writeToken || versionHash, "rep", handler, offering, "options.json");
|
|
@@ -1206,7 +1215,7 @@ exports.PlayoutPathResolution = async function({
|
|
|
1206
1215
|
authorizationToken
|
|
1207
1216
|
});
|
|
1208
1217
|
linkTargetId = this.utils.DecodeVersionHash(linkTargetHash).objectId;
|
|
1209
|
-
linkTargetLibraryId = await this.ContentObjectLibraryId({objectId: linkTargetId
|
|
1218
|
+
linkTargetLibraryId = await this.ContentObjectLibraryId({objectId: linkTargetId});
|
|
1210
1219
|
|
|
1211
1220
|
if(!multiOfferingLink && !offering) {
|
|
1212
1221
|
// If the offering is not specified, the intent is to get available offerings. For a single offering link, must
|
|
@@ -1263,7 +1272,7 @@ exports.AvailableOfferings = async function({
|
|
|
1263
1272
|
|
|
1264
1273
|
if(directLink) {
|
|
1265
1274
|
return await this.ContentObjectMetadata({
|
|
1266
|
-
libraryId: await this.ContentObjectLibraryId({objectId
|
|
1275
|
+
libraryId: await this.ContentObjectLibraryId({objectId}),
|
|
1267
1276
|
objectId,
|
|
1268
1277
|
versionHash,
|
|
1269
1278
|
metadataSubtree: linkPath,
|
|
@@ -1374,10 +1383,10 @@ exports.PlayoutOptions = async function({
|
|
|
1374
1383
|
if(!objectId) {
|
|
1375
1384
|
objectId = this.utils.DecodeVersionHash(versionHash).objectId;
|
|
1376
1385
|
} else if(!versionHash) {
|
|
1377
|
-
versionHash = await this.LatestVersionHash({objectId
|
|
1386
|
+
versionHash = await this.LatestVersionHash({objectId});
|
|
1378
1387
|
}
|
|
1379
1388
|
|
|
1380
|
-
const libraryId = await this.ContentObjectLibraryId({objectId
|
|
1389
|
+
const libraryId = await this.ContentObjectLibraryId({objectId});
|
|
1381
1390
|
|
|
1382
1391
|
try {
|
|
1383
1392
|
// If public/asset_metadata/sources/<offering> exists, use that instead of directly calling on object
|