@eluvio/elv-client-js 3.1.77 → 3.1.81

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,16 @@ class AuthorizationClient {
84
84
  this.providers = {};
85
85
  }
86
86
 
87
+ CreateStaticToken({libraryId}) {
88
+ let token = { qspace_id: this.client.contentSpaceId };
89
+
90
+ if(libraryId) {
91
+ token.qlib_id = libraryId;
92
+ }
93
+
94
+ return Utils.B64(JSON.stringify(token));
95
+ }
96
+
87
97
  // Return authorization token in appropriate headers
88
98
  async AuthorizationHeader(params) {
89
99
  const authorizationToken = await this.AuthorizationToken(params);
@@ -150,6 +160,10 @@ class AuthorizationClient {
150
160
  oauthToken
151
161
  });
152
162
  } else {
163
+ if(noAuth) {
164
+ return this.CreateStaticToken({libraryId});
165
+ }
166
+
153
167
  authorizationToken = await this.GenerateAuthorizationToken({
154
168
  libraryId,
155
169
  objectId,
@@ -177,7 +191,7 @@ class AuthorizationClient {
177
191
  if(encryption && encryption !== "none" && objectId && await this.AccessType(objectId) === ACCESS_TYPES.OBJECT) {
178
192
  const owner = await this.Owner({id: objectId});
179
193
  const ownerCapKey = `eluv.caps.iusr${Utils.AddressToHash(this.client.signer.address)}`;
180
- const ownerCap = await client.ContentObjectMetadata({libraryId, objectId, metadataSubtree: ownerCapKey});
194
+ const ownerCap = await this.client.ContentObjectMetadata({libraryId, objectId, metadataSubtree: ownerCapKey});
181
195
 
182
196
  if(!Utils.EqualAddress(owner, this.client.signer.address) && !ownerCap) {
183
197
  const cap = await this.ReEncryptionConk({libraryId, objectId});
@@ -613,6 +627,10 @@ class AuthorizationClient {
613
627
  }
614
628
 
615
629
  async IsV3({id}) {
630
+ if(this.client.assumeV3) {
631
+ return true;
632
+ }
633
+
616
634
  const contractName = await this.client.ethClient.ContractName(Utils.HashToAddress(id), true);
617
635
 
618
636
  if(!this.accessVersions[contractName]) {
package/src/ElvClient.js CHANGED
@@ -148,7 +148,8 @@ class ElvClient {
148
148
  trustAuthorityId,
149
149
  staticToken,
150
150
  noCache=false,
151
- noAuth=false
151
+ noAuth=false,
152
+ assumeV3=false
152
153
  }) {
153
154
  this.utils = Utils;
154
155
 
@@ -171,6 +172,7 @@ class ElvClient {
171
172
 
172
173
  this.noCache = noCache;
173
174
  this.noAuth = noAuth;
175
+ this.assumeV3 = assumeV3;
174
176
 
175
177
  this.debug = false;
176
178
 
@@ -270,7 +272,8 @@ class ElvClient {
270
272
  staticToken,
271
273
  ethereumContractTimeout=10,
272
274
  noCache=false,
273
- noAuth=false
275
+ noAuth=false,
276
+ assumeV3
274
277
  }) {
275
278
  const configUrl = networks[networkName];
276
279
 
@@ -283,7 +286,8 @@ class ElvClient {
283
286
  staticToken,
284
287
  ethereumContractTimeout,
285
288
  noCache,
286
- noAuth
289
+ noAuth,
290
+ assumeV3
287
291
  });
288
292
  }
289
293
 
@@ -309,7 +313,8 @@ class ElvClient {
309
313
  staticToken,
310
314
  ethereumContractTimeout=10,
311
315
  noCache=false,
312
- noAuth=false
316
+ noAuth=false,
317
+ assumeV3=false
313
318
  }) {
314
319
  const {
315
320
  contentSpaceId,
@@ -336,7 +341,8 @@ class ElvClient {
336
341
  trustAuthorityId,
337
342
  staticToken,
338
343
  noCache,
339
- noAuth
344
+ noAuth,
345
+ assumeV3
340
346
  });
341
347
 
342
348
  client.configUrl = configUrl;
@@ -56,6 +56,8 @@ await client.userProfileClient.UserMetadata()
56
56
  this.client = client;
57
57
  this.debug = debug;
58
58
  this.userWalletAddresses = {};
59
+ this.walletAddress = undefined;
60
+ this.walletAddressRetrieved = false;
59
61
  }
60
62
 
61
63
  async CreateWallet() {
@@ -130,13 +132,17 @@ await client.userProfileClient.UserMetadata()
130
132
  * @return {Promise<string>} - The contract address of the current user's wallet contract
131
133
  */
132
134
  async WalletAddress(autoCreate=true) {
133
- if(this.walletAddress) { return this.walletAddress; }
135
+ if(this.walletAddress || this.walletAddressRetrieved) { return this.walletAddress; }
134
136
 
135
- const walletAddress = await this.client.CallContractMethod({
136
- contractAddress: Utils.HashToAddress(this.client.contentSpaceId),
137
- methodName: "userWallets",
138
- methodArgs: [this.client.signer.address]
139
- });
137
+ if(!this.walletAddressPromise) {
138
+ this.walletAddressPromise = this.client.CallContractMethod({
139
+ contractAddress: Utils.HashToAddress(this.client.contentSpaceId),
140
+ methodName: "userWallets",
141
+ methodArgs: [this.client.signer.address]
142
+ });
143
+ }
144
+
145
+ const walletAddress = await this.walletAddressPromise;
140
146
 
141
147
  if(!Utils.EqualAddress(walletAddress, Utils.nullAddress)) {
142
148
  this.walletAddress = walletAddress;
@@ -146,6 +152,8 @@ await client.userProfileClient.UserMetadata()
146
152
  await this.CreateWallet();
147
153
  }
148
154
 
155
+ this.walletAddressRetrieved = true;
156
+
149
157
  return this.walletAddress;
150
158
  }
151
159
 
@@ -703,7 +703,8 @@ exports.ProduceMetadataLinks = async function({
703
703
  versionHash,
704
704
  path="/",
705
705
  metadata,
706
- authorizationToken
706
+ authorizationToken,
707
+ noAuth
707
708
  }) {
708
709
  // Primitive
709
710
  if(!metadata || typeof metadata !== "object") { return metadata; }
@@ -719,7 +720,8 @@ exports.ProduceMetadataLinks = async function({
719
720
  versionHash,
720
721
  path: UrlJoin(path, i.toString()),
721
722
  metadata: entry,
722
- authorizationToken
723
+ authorizationToken,
724
+ noAuth
723
725
  })
724
726
  );
725
727
  }
@@ -747,7 +749,8 @@ exports.ProduceMetadataLinks = async function({
747
749
  versionHash,
748
750
  path: UrlJoin(path, key),
749
751
  metadata: metadata[key],
750
- authorizationToken
752
+ authorizationToken,
753
+ noAuth
751
754
  });
752
755
  }
753
756
  );
@@ -760,17 +763,22 @@ exports.MetadataAuth = async function({
760
763
  objectId,
761
764
  versionHash,
762
765
  path="/",
763
- channelAuth=false
766
+ channelAuth=false,
767
+ noAuth=false
764
768
  }) {
765
769
  ValidateParameters({libraryId, objectId, versionHash});
766
770
 
767
771
  if(versionHash) { objectId = this.utils.DecodeVersionHash(versionHash).objectId; }
768
772
 
769
- const visibility = await this.Visibility({id: objectId});
770
- const accessType = await this.AccessType({id: objectId});
771
- const isPublic = (path || "").replace(/^\/+/, "").startsWith("public");
772
-
773
- let noAuth = visibility >= 10 || (isPublic && visibility >= 1);
773
+ noAuth = this.noAuth || noAuth;
774
+ let isPublic = noAuth;
775
+ let accessType;
776
+ if(!noAuth) {
777
+ const visibility = await this.Visibility({id: objectId});
778
+ accessType = await this.AccessType({id: objectId});
779
+ isPublic = (path || "").replace(/^\/+/, "").startsWith("public");
780
+ noAuth = visibility >= 10 || (isPublic && visibility >= 1);
781
+ }
774
782
 
775
783
  if(this.oauthToken) {
776
784
  // Check that KMS is set on this object
@@ -823,6 +831,7 @@ exports.MetadataAuth = async function({
823
831
  * - Note: Selection is relative to "metadataSubtree". For example, metadataSubtree="public" and select=["name", "description"] would select "public/name" and "public/description"
824
832
  * @param {Array<string>=} remove - Exclude the specified items from the retrieved metadata
825
833
  * @param {string=} authorizationToken - Additional authorization token for this request
834
+ * @param {string=} noAuth=false - If specified, the normal authorization flow will be skipped. Useful if you know the metadata you're retrieving is publicly accessible
826
835
  * @param {boolean=} resolveLinks=false - If specified, links in the metadata will be resolved
827
836
  * @param {boolean=} resolveIncludeSource=false - If specified, resolved links will include the hash of the link at the root of the metadata
828
837
 
@@ -857,6 +866,7 @@ exports.ContentObjectMetadata = async function({
857
866
  select=[],
858
867
  remove=[],
859
868
  authorizationToken,
869
+ noAuth=false,
860
870
  resolveLinks=false,
861
871
  resolveIncludeSource=false,
862
872
  resolveIgnoreErrors=false,
@@ -877,7 +887,7 @@ exports.ContentObjectMetadata = async function({
877
887
  let path = UrlJoin("q", writeToken || versionHash || objectId, "meta", metadataSubtree);
878
888
 
879
889
  // Main authorization
880
- let defaultAuthToken = await this.MetadataAuth({libraryId, objectId, versionHash, path: metadataSubtree});
890
+ let defaultAuthToken = await this.MetadataAuth({libraryId, objectId, versionHash, path: metadataSubtree, noAuth});
881
891
 
882
892
  // All authorization
883
893
  const authTokens = [authorizationToken, queryParams.authorization, defaultAuthToken].flat().filter(token => token);
@@ -917,7 +927,8 @@ exports.ContentObjectMetadata = async function({
917
927
  versionHash,
918
928
  path: metadataSubtree,
919
929
  metadata,
920
- authorizationToken
930
+ authorizationToken,
931
+ noAuth
921
932
  });
922
933
  };
923
934
 
@@ -944,7 +955,7 @@ exports.ContentObjectMetadata = async function({
944
955
  * @param {boolean=} produceLinkUrls=false - If specified, file and rep links will automatically be populated with a
945
956
  * full URL
946
957
  */
947
- exports.AssetMetadata = async function({libraryId, objectId, versionHash, metadata, localization, produceLinkUrls=false}) {
958
+ exports.AssetMetadata = async function({libraryId, objectId, versionHash, metadata, localization, noAuth, produceLinkUrls=false}) {
948
959
  ValidateParameters({libraryId, objectId, versionHash});
949
960
 
950
961
  if(!objectId) {
@@ -960,7 +971,8 @@ exports.AssetMetadata = async function({libraryId, objectId, versionHash, metada
960
971
  resolveLinks: true,
961
972
  linkDepthLimit: 2,
962
973
  resolveIgnoreErrors: true,
963
- produceLinkUrls
974
+ produceLinkUrls,
975
+ noAuth
964
976
  })) || {};
965
977
  } else if(produceLinkUrls) {
966
978
  metadata = await this.ProduceMetadataLinks({
@@ -968,7 +980,8 @@ exports.AssetMetadata = async function({libraryId, objectId, versionHash, metada
968
980
  objectId,
969
981
  versionHash,
970
982
  path: UrlJoin("public", "asset_metadata"),
971
- metadata
983
+ metadata,
984
+ noAuth
972
985
  });
973
986
  }
974
987
 
@@ -2259,9 +2272,7 @@ exports.LinkUrl = async function({
2259
2272
  }
2260
2273
 
2261
2274
  let authorization = [ authorizationToken ];
2262
- if(!noAuth) {
2263
- authorization.push(await this.MetadataAuth({libraryId, objectId, versionHash, path: linkPath, channelAuth}));
2264
- }
2275
+ authorization.push(await this.MetadataAuth({libraryId, objectId, versionHash, path: linkPath, channelAuth, noAuth}));
2265
2276
 
2266
2277
  if(queryParams.authorization) {
2267
2278
  authorization.push(queryParams.authorization);
@@ -567,6 +567,17 @@ exports.CreateContentObject = async function({libraryId, objectId, options={}})
567
567
  }
568
568
 
569
569
  if(!objectId) {
570
+ const currentAccountAddress = await this.CurrentAccountAddress();
571
+ const canContribute = await this.CallContractMethod({
572
+ contractAddress: this.utils.HashToAddress(libraryId),
573
+ methodName: "canContribute",
574
+ methodArgs: [currentAccountAddress]
575
+ });
576
+
577
+ if(!canContribute) {
578
+ throw Error(`Current user does not have permission to create content in library ${libraryId}`);
579
+ }
580
+
570
581
  this.Log("Deploying contract...");
571
582
  const { contractAddress } = await this.authClient.CreateContentObject({libraryId, typeId});
572
583
 
@@ -270,7 +270,6 @@ const Create = async ({
270
270
  Report(createResponse);
271
271
 
272
272
  const objectId = createResponse.id;
273
- await client.SetVisibility({id: objectId, visibility: 0});
274
273
 
275
274
  console.log("Starting Mezzanine Job(s)");
276
275
 
@@ -0,0 +1,49 @@
1
+ /* eslint-disable no-console */
2
+
3
+ // Removes HLS playout options from an existing offering of a mezzanine
4
+
5
+ const ScriptOffering = require("./parentClasses/ScriptOffering");
6
+
7
+ class OfferingRemoveDash extends ScriptOffering {
8
+
9
+ async body() {
10
+ const client = await this.client();
11
+
12
+ const libraryId = this.args.libraryId;
13
+ const objectId = this.args.objectId;
14
+ const offeringKey = this.args.offeringKey;
15
+
16
+ let dashFound = false;
17
+
18
+ let metadata = await client.ContentObjectMetadata({
19
+ libraryId,
20
+ objectId
21
+ });
22
+
23
+ this.validateOffering(metadata, offeringKey);
24
+
25
+ // loop through playout formats, delete ones where protocol is Dash
26
+ const playoutFormatKeys = Object.keys(metadata.offerings[offeringKey].playout.playout_formats);
27
+ for(let i = 0; i < playoutFormatKeys.length; i++) {
28
+ const key = playoutFormatKeys[i];
29
+ if(metadata.offerings[offeringKey].playout.playout_formats[key].protocol.type === "ProtoDash") {
30
+ console.log("Found Dash playout format '" + key + "', removing...");
31
+ delete metadata.offerings[offeringKey].playout.playout_formats[key];
32
+ dashFound = true;
33
+ }
34
+ }
35
+
36
+ if(dashFound) {
37
+ await this.metadataWrite(metadata);
38
+ } else {
39
+ console.log("No playout formats found with Dash");
40
+ }
41
+ }
42
+
43
+ header() {
44
+ return "Removing playout formats with Dash from mezzanine offering '" + this.args.offeringKey + "'... ";
45
+ }
46
+ }
47
+
48
+ const script = new OfferingRemoveDash;
49
+ script.run();