@eluvio/elv-client-js 4.0.5 → 4.0.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.
Files changed (43) hide show
  1. package/dist/ElvClient-min.js +12 -11
  2. package/dist/ElvClient-node-min.js +12 -11
  3. package/dist/ElvFrameClient-min.js +12 -11
  4. package/dist/ElvPermissionsClient-min.js +10 -9
  5. package/dist/ElvWalletClient-min.js +12 -11
  6. package/dist/ElvWalletClient-node-min.js +11 -10
  7. package/dist/src/AuthorizationClient.js +1556 -2077
  8. package/dist/src/ContentObjectVerification.js +134 -185
  9. package/dist/src/Crypto.js +225 -322
  10. package/dist/src/ElvClient.js +823 -1117
  11. package/dist/src/ElvWallet.js +64 -106
  12. package/dist/src/EthClient.js +719 -974
  13. package/dist/src/FrameClient.js +222 -318
  14. package/dist/src/HttpClient.js +112 -154
  15. package/dist/src/Id.js +1 -6
  16. package/dist/src/LogMessage.js +4 -8
  17. package/dist/src/PermissionsClient.js +973 -1271
  18. package/dist/src/RemoteSigner.js +161 -232
  19. package/dist/src/UserProfileClient.js +781 -1038
  20. package/dist/src/Utils.js +160 -302
  21. package/dist/src/Validation.js +2 -17
  22. package/dist/src/client/ABRPublishing.js +772 -942
  23. package/dist/src/client/AccessGroups.js +849 -1095
  24. package/dist/src/client/ContentAccess.js +3263 -4132
  25. package/dist/src/client/ContentManagement.js +1811 -2283
  26. package/dist/src/client/Contracts.js +468 -614
  27. package/dist/src/client/Files.js +1505 -1845
  28. package/dist/src/client/NFT.js +94 -116
  29. package/dist/src/client/NTP.js +326 -425
  30. package/dist/src/index.js +2 -5
  31. package/dist/src/walletClient/ClientMethods.js +1348 -1735
  32. package/dist/src/walletClient/Configuration.js +4 -2
  33. package/dist/src/walletClient/Notifications.js +98 -127
  34. package/dist/src/walletClient/Profile.js +184 -246
  35. package/dist/src/walletClient/Utils.js +76 -122
  36. package/dist/src/walletClient/index.js +1168 -1493
  37. package/package.json +2 -2
  38. package/src/Crypto.js +1 -1
  39. package/src/ElvClient.js +1 -3
  40. package/src/Utils.js +1 -1
  41. package/testScripts/Test.js +0 -1
  42. package/utilities/NFTIngest.js +527 -0
  43. package/utilities/lib/concerns/LocalFile.js +2 -1
@@ -1,27 +1,20 @@
1
1
  var _typeof = require("@babel/runtime/helpers/typeof");
2
-
3
2
  var _defineProperty = require("@babel/runtime/helpers/defineProperty");
4
-
5
3
  var _regeneratorRuntime = require("@babel/runtime/regenerator");
6
-
7
4
  var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
8
-
9
5
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
10
-
11
6
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
12
-
13
7
  /**
14
8
  * Methods for managing content types, libraries and objects
15
9
  *
16
10
  * @module ElvClient/ContentManagement
17
11
  */
18
- var UrlJoin = require("url-join");
19
12
 
13
+ var UrlJoin = require("url-join");
20
14
  var ImageType = require("image-type");
21
-
22
15
  var Ethers = require("ethers");
23
-
24
16
  var Pako = require("pako");
17
+
25
18
  /*
26
19
  const LibraryContract = require("../contracts/BaseLibrary");
27
20
  const ContentContract = require("../contracts/BaseContent");
@@ -29,70 +22,59 @@ const EditableContract = require("../contracts/Editable");
29
22
 
30
23
  */
31
24
 
32
-
33
25
  var _require = require("../Validation"),
34
- ValidateLibrary = _require.ValidateLibrary,
35
- ValidateObject = _require.ValidateObject,
36
- ValidateVersion = _require.ValidateVersion,
37
- ValidateWriteToken = _require.ValidateWriteToken,
38
- ValidateParameters = _require.ValidateParameters,
39
- ValidatePresence = _require.ValidatePresence;
40
-
26
+ ValidateLibrary = _require.ValidateLibrary,
27
+ ValidateObject = _require.ValidateObject,
28
+ ValidateVersion = _require.ValidateVersion,
29
+ ValidateWriteToken = _require.ValidateWriteToken,
30
+ ValidateParameters = _require.ValidateParameters,
31
+ ValidatePresence = _require.ValidatePresence;
41
32
  exports.SetVisibility = /*#__PURE__*/function () {
42
33
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
43
34
  var id, visibility, hasSetVisibility, event;
44
35
  return _regeneratorRuntime.wrap(function _callee$(_context) {
45
- while (1) {
46
- switch (_context.prev = _context.next) {
47
- case 0:
48
- id = _ref.id, visibility = _ref.visibility;
49
- this.Log("Setting visibility ".concat(visibility, " on ").concat(id));
50
- _context.next = 4;
51
- return this.authClient.ContractHasMethod({
52
- contractAddress: this.utils.HashToAddress(id),
53
- methodName: "setVisibility"
54
- });
55
-
56
- case 4:
57
- hasSetVisibility = _context.sent;
58
-
59
- if (hasSetVisibility) {
60
- _context.next = 7;
61
- break;
62
- }
63
-
64
- return _context.abrupt("return");
65
-
66
- case 7:
67
- _context.next = 9;
68
- return this.CallContractMethodAndWait({
69
- contractAddress: this.utils.HashToAddress(id),
70
- methodName: "setVisibility",
71
- methodArgs: [visibility]
72
- });
73
-
74
- case 9:
75
- event = _context.sent;
76
- _context.next = 12;
77
- return new Promise(function (resolve) {
78
- return setTimeout(resolve, 5000);
79
- });
80
-
81
- case 12:
82
- return _context.abrupt("return", event);
83
-
84
- case 13:
85
- case "end":
86
- return _context.stop();
87
- }
36
+ while (1) switch (_context.prev = _context.next) {
37
+ case 0:
38
+ id = _ref.id, visibility = _ref.visibility;
39
+ this.Log("Setting visibility ".concat(visibility, " on ").concat(id));
40
+ _context.next = 4;
41
+ return this.authClient.ContractHasMethod({
42
+ contractAddress: this.utils.HashToAddress(id),
43
+ methodName: "setVisibility"
44
+ });
45
+ case 4:
46
+ hasSetVisibility = _context.sent;
47
+ if (hasSetVisibility) {
48
+ _context.next = 7;
49
+ break;
50
+ }
51
+ return _context.abrupt("return");
52
+ case 7:
53
+ _context.next = 9;
54
+ return this.CallContractMethodAndWait({
55
+ contractAddress: this.utils.HashToAddress(id),
56
+ methodName: "setVisibility",
57
+ methodArgs: [visibility]
58
+ });
59
+ case 9:
60
+ event = _context.sent;
61
+ _context.next = 12;
62
+ return new Promise(function (resolve) {
63
+ return setTimeout(resolve, 5000);
64
+ });
65
+ case 12:
66
+ return _context.abrupt("return", event);
67
+ case 13:
68
+ case "end":
69
+ return _context.stop();
88
70
  }
89
71
  }, _callee, this);
90
72
  }));
91
-
92
73
  return function (_x) {
93
74
  return _ref2.apply(this, arguments);
94
75
  };
95
76
  }();
77
+
96
78
  /**
97
79
  * Set the current permission level for the specified object. See client.permissionLevels for all available permissions.
98
80
  *
@@ -103,222 +85,182 @@ exports.SetVisibility = /*#__PURE__*/function () {
103
85
  * @param {string} permission - The key for the permission to set - See client.permissionLevels for available permissions
104
86
  * @param {string} writeToken - Write token for the content object - If specified, info will be retrieved from the write draft instead of creating a new draft and finalizing
105
87
  */
106
-
107
-
108
88
  exports.SetPermission = /*#__PURE__*/function () {
109
89
  var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref3) {
110
90
  var _this = this;
111
-
112
91
  var objectId, permission, writeToken, permissionSettings, settings, libraryId, statusCode, kmsAddress, kmsConkKey, kmsConk, finalize;
113
92
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
114
- while (1) {
115
- switch (_context3.prev = _context3.next) {
116
- case 0:
117
- objectId = _ref3.objectId, permission = _ref3.permission, writeToken = _ref3.writeToken;
118
- ValidateObject(objectId);
119
- ValidatePresence("permission", permission);
120
- permissionSettings = this.permissionLevels[permission];
121
-
122
- if (permissionSettings) {
123
- _context3.next = 6;
124
- break;
125
- }
126
-
127
- throw Error("Unknown permission level: " + permission);
128
-
129
- case 6:
130
- _context3.next = 8;
131
- return this.AccessType({
132
- id: objectId
133
- });
134
-
135
- case 8:
136
- _context3.t0 = _context3.sent;
137
- _context3.t1 = this.authClient.ACCESS_TYPES.OBJECT;
138
-
139
- if (!(_context3.t0 !== _context3.t1)) {
140
- _context3.next = 12;
141
- break;
142
- }
143
-
144
- throw Error("Permission only valid for normal content objects: " + objectId);
145
-
146
- case 12:
147
- settings = permissionSettings.settings;
148
- _context3.next = 15;
149
- return this.ContentObjectLibraryId({
150
- objectId: objectId
151
- });
152
-
153
- case 15:
154
- libraryId = _context3.sent;
155
- _context3.next = 18;
156
- return this.SetVisibility({
157
- id: objectId,
158
- visibility: settings.visibility
159
- });
160
-
161
- case 18:
162
- _context3.next = 20;
163
- return this.CallContractMethod({
164
- contractAddress: this.utils.HashToAddress(objectId),
165
- methodName: "statusCode"
166
- });
167
-
168
- case 20:
169
- statusCode = _context3.sent;
170
-
171
- if (!(statusCode !== settings.statusCode)) {
172
- _context3.next = 29;
173
- break;
174
- }
175
-
176
- if (!(settings.statusCode < 0)) {
177
- _context3.next = 27;
178
- break;
179
- }
180
-
181
- _context3.next = 25;
182
- return this.CallContractMethod({
183
- contractAddress: this.utils.HashToAddress(objectId),
184
- methodName: "setStatusCode",
185
- methodArgs: [-1]
186
- });
187
-
188
- case 25:
189
- _context3.next = 29;
93
+ while (1) switch (_context3.prev = _context3.next) {
94
+ case 0:
95
+ objectId = _ref3.objectId, permission = _ref3.permission, writeToken = _ref3.writeToken;
96
+ ValidateObject(objectId);
97
+ ValidatePresence("permission", permission);
98
+ permissionSettings = this.permissionLevels[permission];
99
+ if (permissionSettings) {
100
+ _context3.next = 6;
190
101
  break;
191
-
192
- case 27:
102
+ }
103
+ throw Error("Unknown permission level: " + permission);
104
+ case 6:
105
+ _context3.next = 8;
106
+ return this.AccessType({
107
+ id: objectId
108
+ });
109
+ case 8:
110
+ _context3.t0 = _context3.sent;
111
+ _context3.t1 = this.authClient.ACCESS_TYPES.OBJECT;
112
+ if (!(_context3.t0 !== _context3.t1)) {
113
+ _context3.next = 12;
114
+ break;
115
+ }
116
+ throw Error("Permission only valid for normal content objects: " + objectId);
117
+ case 12:
118
+ settings = permissionSettings.settings;
119
+ _context3.next = 15;
120
+ return this.ContentObjectLibraryId({
121
+ objectId: objectId
122
+ });
123
+ case 15:
124
+ libraryId = _context3.sent;
125
+ _context3.next = 18;
126
+ return this.SetVisibility({
127
+ id: objectId,
128
+ visibility: settings.visibility
129
+ });
130
+ case 18:
131
+ _context3.next = 20;
132
+ return this.CallContractMethod({
133
+ contractAddress: this.utils.HashToAddress(objectId),
134
+ methodName: "statusCode"
135
+ });
136
+ case 20:
137
+ statusCode = _context3.sent;
138
+ if (!(statusCode !== settings.statusCode)) {
193
139
  _context3.next = 29;
194
- return this.CallContractMethod({
195
- contractAddress: this.utils.HashToAddress(objectId),
196
- methodName: "publish"
197
- });
198
-
199
- case 29:
200
- _context3.next = 31;
201
- return this.CallContractMethod({
202
- contractAddress: this.utils.HashToAddress(objectId),
203
- methodName: "addressKMS"
204
- });
205
-
206
- case 31:
207
- kmsAddress = _context3.sent;
208
- kmsConkKey = "eluv.caps.ikms".concat(this.utils.AddressToHash(kmsAddress));
209
- _context3.next = 35;
210
- return this.ContentObjectMetadata({
211
- libraryId: libraryId,
212
- objectId: objectId,
213
- metadataSubtree: kmsConkKey
214
- });
215
-
216
- case 35:
217
- kmsConk = _context3.sent;
218
-
219
- if (!(kmsConk && !settings.kmsConk)) {
220
- _context3.next = 41;
221
- break;
222
- }
223
-
224
- _context3.next = 39;
225
- return this.EditAndFinalizeContentObject({
226
- libraryId: libraryId,
227
- objectId: objectId,
228
- commitMessage: "Remove encryption conk",
229
- callback: function () {
230
- var _callback = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref5) {
231
- var writeToken;
232
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
233
- while (1) {
234
- switch (_context2.prev = _context2.next) {
235
- case 0:
236
- writeToken = _ref5.writeToken;
237
- _context2.next = 3;
238
- return _this.DeleteMetadata({
239
- libraryId: libraryId,
240
- objectId: objectId,
241
- writeToken: writeToken,
242
- metadataSubtree: kmsConkKey
243
- });
244
-
245
- case 3:
246
- case "end":
247
- return _context2.stop();
248
- }
249
- }
250
- }, _callee2);
251
- }));
252
-
253
- function callback(_x3) {
254
- return _callback.apply(this, arguments);
255
- }
256
-
257
- return callback;
258
- }()
259
- });
260
-
261
- case 39:
140
+ break;
141
+ }
142
+ if (!(settings.statusCode < 0)) {
143
+ _context3.next = 27;
144
+ break;
145
+ }
146
+ _context3.next = 25;
147
+ return this.CallContractMethod({
148
+ contractAddress: this.utils.HashToAddress(objectId),
149
+ methodName: "setStatusCode",
150
+ methodArgs: [-1]
151
+ });
152
+ case 25:
153
+ _context3.next = 29;
154
+ break;
155
+ case 27:
156
+ _context3.next = 29;
157
+ return this.CallContractMethod({
158
+ contractAddress: this.utils.HashToAddress(objectId),
159
+ methodName: "publish"
160
+ });
161
+ case 29:
162
+ _context3.next = 31;
163
+ return this.CallContractMethod({
164
+ contractAddress: this.utils.HashToAddress(objectId),
165
+ methodName: "addressKMS"
166
+ });
167
+ case 31:
168
+ kmsAddress = _context3.sent;
169
+ kmsConkKey = "eluv.caps.ikms".concat(this.utils.AddressToHash(kmsAddress));
170
+ _context3.next = 35;
171
+ return this.ContentObjectMetadata({
172
+ libraryId: libraryId,
173
+ objectId: objectId,
174
+ metadataSubtree: kmsConkKey
175
+ });
176
+ case 35:
177
+ kmsConk = _context3.sent;
178
+ if (!(kmsConk && !settings.kmsConk)) {
179
+ _context3.next = 41;
180
+ break;
181
+ }
182
+ _context3.next = 39;
183
+ return this.EditAndFinalizeContentObject({
184
+ libraryId: libraryId,
185
+ objectId: objectId,
186
+ commitMessage: "Remove encryption conk",
187
+ callback: function () {
188
+ var _callback = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref5) {
189
+ var writeToken;
190
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
191
+ while (1) switch (_context2.prev = _context2.next) {
192
+ case 0:
193
+ writeToken = _ref5.writeToken;
194
+ _context2.next = 3;
195
+ return _this.DeleteMetadata({
196
+ libraryId: libraryId,
197
+ objectId: objectId,
198
+ writeToken: writeToken,
199
+ metadataSubtree: kmsConkKey
200
+ });
201
+ case 3:
202
+ case "end":
203
+ return _context2.stop();
204
+ }
205
+ }, _callee2);
206
+ }));
207
+ function callback(_x3) {
208
+ return _callback.apply(this, arguments);
209
+ }
210
+ return callback;
211
+ }()
212
+ });
213
+ case 39:
214
+ _context3.next = 52;
215
+ break;
216
+ case 41:
217
+ if (!(!kmsConk && settings.kmsConk)) {
262
218
  _context3.next = 52;
263
219
  break;
264
-
265
- case 41:
266
- if (!(!kmsConk && settings.kmsConk)) {
267
- _context3.next = 52;
268
- break;
269
- }
270
-
271
- finalize = !writeToken;
272
-
273
- if (writeToken) {
274
- _context3.next = 47;
275
- break;
276
- }
277
-
278
- _context3.next = 46;
279
- return this.EditContentObject({
280
- libraryId: libraryId,
281
- objectId: objectId
282
- });
283
-
284
- case 46:
285
- writeToken = _context3.sent.writeToken;
286
-
287
- case 47:
288
- _context3.next = 49;
289
- return this.CreateEncryptionConk({
290
- libraryId: libraryId,
291
- objectId: objectId,
292
- writeToken: writeToken,
293
- createKMSConk: true
294
- });
295
-
296
- case 49:
297
- if (!finalize) {
298
- _context3.next = 52;
299
- break;
300
- }
301
-
220
+ }
221
+ finalize = !writeToken;
222
+ if (writeToken) {
223
+ _context3.next = 47;
224
+ break;
225
+ }
226
+ _context3.next = 46;
227
+ return this.EditContentObject({
228
+ libraryId: libraryId,
229
+ objectId: objectId
230
+ });
231
+ case 46:
232
+ writeToken = _context3.sent.writeToken;
233
+ case 47:
234
+ _context3.next = 49;
235
+ return this.CreateEncryptionConk({
236
+ libraryId: libraryId,
237
+ objectId: objectId,
238
+ writeToken: writeToken,
239
+ createKMSConk: true
240
+ });
241
+ case 49:
242
+ if (!finalize) {
302
243
  _context3.next = 52;
303
- return this.FinalizeContentObject({
304
- libraryId: libraryId,
305
- objectId: objectId,
306
- writeToken: writeToken,
307
- commitMessage: "Set permissions to ".concat(permission)
308
- });
309
-
310
- case 52:
311
- case "end":
312
- return _context3.stop();
313
- }
244
+ break;
245
+ }
246
+ _context3.next = 52;
247
+ return this.FinalizeContentObject({
248
+ libraryId: libraryId,
249
+ objectId: objectId,
250
+ writeToken: writeToken,
251
+ commitMessage: "Set permissions to ".concat(permission)
252
+ });
253
+ case 52:
254
+ case "end":
255
+ return _context3.stop();
314
256
  }
315
257
  }, _callee3, this);
316
258
  }));
317
-
318
259
  return function (_x2) {
319
260
  return _ref4.apply(this, arguments);
320
261
  };
321
262
  }();
263
+
322
264
  /* Content Type Creation */
323
265
 
324
266
  /**
@@ -339,123 +281,108 @@ exports.SetPermission = /*#__PURE__*/function () {
339
281
  *
340
282
  * @returns {Promise<string>} - Object ID of created content type
341
283
  */
342
-
343
-
344
284
  exports.CreateContentType = /*#__PURE__*/function () {
345
285
  var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref6) {
346
286
  var name, _ref6$metadata, metadata, bitcode, _yield$this$authClien, contractAddress, objectId, path, createResponse, uploadResponse;
347
-
348
287
  return _regeneratorRuntime.wrap(function _callee4$(_context4) {
349
- while (1) {
350
- switch (_context4.prev = _context4.next) {
351
- case 0:
352
- name = _ref6.name, _ref6$metadata = _ref6.metadata, metadata = _ref6$metadata === void 0 ? {} : _ref6$metadata, bitcode = _ref6.bitcode;
353
- this.Log("Creating content type: ".concat(name));
354
- metadata.name = name;
355
- metadata["public"] = _objectSpread({
356
- name: name
357
- }, metadata["public"] || {});
358
- _context4.next = 6;
359
- return this.authClient.CreateContentType();
360
-
361
- case 6:
362
- _yield$this$authClien = _context4.sent;
363
- contractAddress = _yield$this$authClien.contractAddress;
364
- objectId = this.utils.AddressToObjectId(contractAddress);
365
- _context4.next = 11;
366
- return this.SetVisibility({
367
- id: objectId,
368
- visibility: 1
369
- });
370
-
371
- case 11:
372
- path = UrlJoin("qlibs", this.contentSpaceLibraryId, "qid", objectId);
373
- this.Log("Created type: ".concat(contractAddress, " ").concat(objectId));
374
- /* Create object, upload bitcode and finalize */
375
-
376
- _context4.t0 = this.utils;
377
- _context4.t1 = this.HttpClient;
378
- _context4.next = 17;
379
- return this.authClient.AuthorizationHeader({
380
- libraryId: this.contentSpaceLibraryId,
381
- objectId: objectId,
382
- update: true
383
- });
384
-
385
- case 17:
386
- _context4.t2 = _context4.sent;
387
- _context4.t3 = path;
388
- _context4.t4 = {
389
- headers: _context4.t2,
390
- method: "POST",
391
- path: _context4.t3
392
- };
393
- _context4.t5 = _context4.t1.Request.call(_context4.t1, _context4.t4);
394
- _context4.next = 23;
395
- return _context4.t0.ResponseToJson.call(_context4.t0, _context4.t5);
396
-
397
- case 23:
398
- createResponse = _context4.sent;
399
- // Record the node used in creating this write token
400
- this.HttpClient.RecordWriteToken(createResponse.write_token);
401
- _context4.next = 27;
402
- return this.ReplaceMetadata({
403
- libraryId: this.contentSpaceLibraryId,
404
- objectId: objectId,
405
- writeToken: createResponse.write_token,
406
- metadata: metadata
407
- });
408
-
409
- case 27:
410
- if (!bitcode) {
411
- _context4.next = 33;
412
- break;
413
- }
414
-
415
- _context4.next = 30;
416
- return this.UploadPart({
417
- libraryId: this.contentSpaceLibraryId,
418
- objectId: objectId,
419
- writeToken: createResponse.write_token,
420
- data: bitcode,
421
- encrypted: false
422
- });
423
-
424
- case 30:
425
- uploadResponse = _context4.sent;
288
+ while (1) switch (_context4.prev = _context4.next) {
289
+ case 0:
290
+ name = _ref6.name, _ref6$metadata = _ref6.metadata, metadata = _ref6$metadata === void 0 ? {} : _ref6$metadata, bitcode = _ref6.bitcode;
291
+ this.Log("Creating content type: ".concat(name));
292
+ metadata.name = name;
293
+ metadata["public"] = _objectSpread({
294
+ name: name
295
+ }, metadata["public"] || {});
296
+ _context4.next = 6;
297
+ return this.authClient.CreateContentType();
298
+ case 6:
299
+ _yield$this$authClien = _context4.sent;
300
+ contractAddress = _yield$this$authClien.contractAddress;
301
+ objectId = this.utils.AddressToObjectId(contractAddress);
302
+ _context4.next = 11;
303
+ return this.SetVisibility({
304
+ id: objectId,
305
+ visibility: 1
306
+ });
307
+ case 11:
308
+ path = UrlJoin("qlibs", this.contentSpaceLibraryId, "qid", objectId);
309
+ this.Log("Created type: ".concat(contractAddress, " ").concat(objectId));
310
+
311
+ /* Create object, upload bitcode and finalize */
312
+ _context4.t0 = this.utils;
313
+ _context4.t1 = this.HttpClient;
314
+ _context4.next = 17;
315
+ return this.authClient.AuthorizationHeader({
316
+ libraryId: this.contentSpaceLibraryId,
317
+ objectId: objectId,
318
+ update: true
319
+ });
320
+ case 17:
321
+ _context4.t2 = _context4.sent;
322
+ _context4.t3 = path;
323
+ _context4.t4 = {
324
+ headers: _context4.t2,
325
+ method: "POST",
326
+ path: _context4.t3
327
+ };
328
+ _context4.t5 = _context4.t1.Request.call(_context4.t1, _context4.t4);
329
+ _context4.next = 23;
330
+ return _context4.t0.ResponseToJson.call(_context4.t0, _context4.t5);
331
+ case 23:
332
+ createResponse = _context4.sent;
333
+ // Record the node used in creating this write token
334
+ this.HttpClient.RecordWriteToken(createResponse.write_token);
335
+ _context4.next = 27;
336
+ return this.ReplaceMetadata({
337
+ libraryId: this.contentSpaceLibraryId,
338
+ objectId: objectId,
339
+ writeToken: createResponse.write_token,
340
+ metadata: metadata
341
+ });
342
+ case 27:
343
+ if (!bitcode) {
426
344
  _context4.next = 33;
427
- return this.ReplaceMetadata({
428
- libraryId: this.contentSpaceLibraryId,
429
- objectId: objectId,
430
- writeToken: createResponse.write_token,
431
- metadataSubtree: "bitcode_part",
432
- metadata: uploadResponse.part.hash
433
- });
434
-
435
- case 33:
436
- _context4.next = 35;
437
- return this.FinalizeContentObject({
438
- libraryId: this.contentSpaceLibraryId,
439
- objectId: objectId,
440
- writeToken: createResponse.write_token,
441
- commitMessage: "Create content type"
442
- });
443
-
444
- case 35:
445
- return _context4.abrupt("return", objectId);
446
-
447
- case 36:
448
- case "end":
449
- return _context4.stop();
450
- }
345
+ break;
346
+ }
347
+ _context4.next = 30;
348
+ return this.UploadPart({
349
+ libraryId: this.contentSpaceLibraryId,
350
+ objectId: objectId,
351
+ writeToken: createResponse.write_token,
352
+ data: bitcode,
353
+ encrypted: false
354
+ });
355
+ case 30:
356
+ uploadResponse = _context4.sent;
357
+ _context4.next = 33;
358
+ return this.ReplaceMetadata({
359
+ libraryId: this.contentSpaceLibraryId,
360
+ objectId: objectId,
361
+ writeToken: createResponse.write_token,
362
+ metadataSubtree: "bitcode_part",
363
+ metadata: uploadResponse.part.hash
364
+ });
365
+ case 33:
366
+ _context4.next = 35;
367
+ return this.FinalizeContentObject({
368
+ libraryId: this.contentSpaceLibraryId,
369
+ objectId: objectId,
370
+ writeToken: createResponse.write_token,
371
+ commitMessage: "Create content type"
372
+ });
373
+ case 35:
374
+ return _context4.abrupt("return", objectId);
375
+ case 36:
376
+ case "end":
377
+ return _context4.stop();
451
378
  }
452
379
  }, _callee4, this);
453
380
  }));
454
-
455
381
  return function (_x4) {
456
382
  return _ref7.apply(this, arguments);
457
383
  };
458
384
  }();
385
+
459
386
  /* Library creation and deletion */
460
387
 
461
388
  /**
@@ -479,145 +406,122 @@ exports.CreateContentType = /*#__PURE__*/function () {
479
406
  *
480
407
  * @returns {Promise<string>} - Library ID of created library
481
408
  */
482
-
483
-
484
409
  exports.CreateContentLibrary = /*#__PURE__*/function () {
485
410
  var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(_ref8) {
486
411
  var name, description, image, imageName, _ref8$metadata, metadata, kmsId, tenantId, _yield$this$authClien2, contractAddress, libraryId, objectId, editResponse;
487
-
488
412
  return _regeneratorRuntime.wrap(function _callee5$(_context5) {
489
- while (1) {
490
- switch (_context5.prev = _context5.next) {
491
- case 0:
492
- name = _ref8.name, description = _ref8.description, image = _ref8.image, imageName = _ref8.imageName, _ref8$metadata = _ref8.metadata, metadata = _ref8$metadata === void 0 ? {} : _ref8$metadata, kmsId = _ref8.kmsId, tenantId = _ref8.tenantId;
493
-
494
- if (kmsId) {
495
- _context5.next = 9;
496
- break;
497
- }
498
-
499
- _context5.t0 = "ikms";
500
- _context5.t1 = this.utils;
501
- _context5.next = 6;
502
- return this.DefaultKMSAddress();
503
-
504
- case 6:
505
- _context5.t2 = _context5.sent;
506
- _context5.t3 = _context5.t1.AddressToHash.call(_context5.t1, _context5.t2);
507
- kmsId = _context5.t0.concat.call(_context5.t0, _context5.t3);
508
-
509
- case 9:
510
- this.Log("Creating content library");
511
- this.Log("KMS ID: ".concat(kmsId));
512
- _context5.next = 13;
513
- return this.authClient.CreateContentLibrary({
514
- kmsId: kmsId
515
- });
516
-
517
- case 13:
518
- _yield$this$authClien2 = _context5.sent;
519
- contractAddress = _yield$this$authClien2.contractAddress;
520
-
521
- if (tenantId) {
522
- _context5.next = 19;
523
- break;
524
- }
525
-
526
- _context5.next = 18;
527
- return this.userProfileClient.TenantId();
528
-
529
- case 18:
530
- tenantId = _context5.sent;
531
-
532
- case 19:
533
- if (!tenantId) {
534
- _context5.next = 24;
535
- break;
536
- }
537
-
538
- if (this.utils.ValidHash(tenantId)) {
539
- _context5.next = 22;
540
- break;
541
- }
542
-
543
- throw Error("Invalid tenant ID: ".concat(tenantId));
544
-
545
- case 22:
413
+ while (1) switch (_context5.prev = _context5.next) {
414
+ case 0:
415
+ name = _ref8.name, description = _ref8.description, image = _ref8.image, imageName = _ref8.imageName, _ref8$metadata = _ref8.metadata, metadata = _ref8$metadata === void 0 ? {} : _ref8$metadata, kmsId = _ref8.kmsId, tenantId = _ref8.tenantId;
416
+ if (kmsId) {
417
+ _context5.next = 9;
418
+ break;
419
+ }
420
+ _context5.t0 = "ikms";
421
+ _context5.t1 = this.utils;
422
+ _context5.next = 6;
423
+ return this.DefaultKMSAddress();
424
+ case 6:
425
+ _context5.t2 = _context5.sent;
426
+ _context5.t3 = _context5.t1.AddressToHash.call(_context5.t1, _context5.t2);
427
+ kmsId = _context5.t0.concat.call(_context5.t0, _context5.t3);
428
+ case 9:
429
+ this.Log("Creating content library");
430
+ this.Log("KMS ID: ".concat(kmsId));
431
+ _context5.next = 13;
432
+ return this.authClient.CreateContentLibrary({
433
+ kmsId: kmsId
434
+ });
435
+ case 13:
436
+ _yield$this$authClien2 = _context5.sent;
437
+ contractAddress = _yield$this$authClien2.contractAddress;
438
+ if (tenantId) {
439
+ _context5.next = 19;
440
+ break;
441
+ }
442
+ _context5.next = 18;
443
+ return this.userProfileClient.TenantId();
444
+ case 18:
445
+ tenantId = _context5.sent;
446
+ case 19:
447
+ if (!tenantId) {
546
448
  _context5.next = 24;
547
- return this.CallContractMethod({
548
- contractAddress: contractAddress,
549
- methodName: "putMeta",
550
- methodArgs: ["_tenantId", tenantId]
551
- });
552
-
553
- case 24:
554
- metadata = _objectSpread(_objectSpread({}, metadata), {}, {
449
+ break;
450
+ }
451
+ if (this.utils.ValidHash(tenantId)) {
452
+ _context5.next = 22;
453
+ break;
454
+ }
455
+ throw Error("Invalid tenant ID: ".concat(tenantId));
456
+ case 22:
457
+ _context5.next = 24;
458
+ return this.CallContractMethod({
459
+ contractAddress: contractAddress,
460
+ methodName: "putMeta",
461
+ methodArgs: ["_tenantId", tenantId]
462
+ });
463
+ case 24:
464
+ metadata = _objectSpread(_objectSpread({}, metadata), {}, {
465
+ name: name,
466
+ description: description,
467
+ "public": {
555
468
  name: name,
556
- description: description,
557
- "public": {
558
- name: name,
559
- description: description
560
- }
561
- });
562
- libraryId = this.utils.AddressToLibraryId(contractAddress);
563
- this.Log("Library ID: ".concat(libraryId));
564
- this.Log("Contract address: ".concat(contractAddress)); // Set library content object type and metadata on automatically created library object
565
-
566
- objectId = libraryId.replace("ilib", "iq__");
567
- _context5.next = 31;
568
- return this.EditContentObject({
569
- libraryId: libraryId,
570
- objectId: objectId
571
- });
572
-
573
- case 31:
574
- editResponse = _context5.sent;
575
- _context5.next = 34;
576
- return this.ReplaceMetadata({
577
- libraryId: libraryId,
578
- objectId: objectId,
579
- metadata: metadata,
580
- writeToken: editResponse.write_token
581
- });
582
-
583
- case 34:
584
- _context5.next = 36;
585
- return this.FinalizeContentObject({
586
- libraryId: libraryId,
587
- objectId: objectId,
588
- writeToken: editResponse.write_token,
589
- commitMessage: "Create library"
590
- });
591
-
592
- case 36:
593
- if (!image) {
594
- _context5.next = 39;
595
- break;
469
+ description: description
596
470
  }
597
-
471
+ });
472
+ libraryId = this.utils.AddressToLibraryId(contractAddress);
473
+ this.Log("Library ID: ".concat(libraryId));
474
+ this.Log("Contract address: ".concat(contractAddress));
475
+
476
+ // Set library content object type and metadata on automatically created library object
477
+ objectId = libraryId.replace("ilib", "iq__");
478
+ _context5.next = 31;
479
+ return this.EditContentObject({
480
+ libraryId: libraryId,
481
+ objectId: objectId
482
+ });
483
+ case 31:
484
+ editResponse = _context5.sent;
485
+ _context5.next = 34;
486
+ return this.ReplaceMetadata({
487
+ libraryId: libraryId,
488
+ objectId: objectId,
489
+ metadata: metadata,
490
+ writeToken: editResponse.write_token
491
+ });
492
+ case 34:
493
+ _context5.next = 36;
494
+ return this.FinalizeContentObject({
495
+ libraryId: libraryId,
496
+ objectId: objectId,
497
+ writeToken: editResponse.write_token,
498
+ commitMessage: "Create library"
499
+ });
500
+ case 36:
501
+ if (!image) {
598
502
  _context5.next = 39;
599
- return this.SetContentLibraryImage({
600
- libraryId: libraryId,
601
- image: image,
602
- imageName: imageName
603
- });
604
-
605
- case 39:
606
- this.Log("Library ".concat(libraryId, " created"));
607
- return _context5.abrupt("return", libraryId);
608
-
609
- case 41:
610
- case "end":
611
- return _context5.stop();
612
- }
503
+ break;
504
+ }
505
+ _context5.next = 39;
506
+ return this.SetContentLibraryImage({
507
+ libraryId: libraryId,
508
+ image: image,
509
+ imageName: imageName
510
+ });
511
+ case 39:
512
+ this.Log("Library ".concat(libraryId, " created"));
513
+ return _context5.abrupt("return", libraryId);
514
+ case 41:
515
+ case "end":
516
+ return _context5.stop();
613
517
  }
614
518
  }, _callee5, this);
615
519
  }));
616
-
617
520
  return function (_x5) {
618
521
  return _ref9.apply(this, arguments);
619
522
  };
620
523
  }();
524
+
621
525
  /**
622
526
  * Set the image associated with this library
623
527
  *
@@ -628,38 +532,33 @@ exports.CreateContentLibrary = /*#__PURE__*/function () {
628
532
  * @param {Blob | ArrayBuffer | Buffer} image - Image to upload
629
533
  * @param {string=} imageName - Name of the image file
630
534
  */
631
-
632
-
633
535
  exports.SetContentLibraryImage = /*#__PURE__*/function () {
634
536
  var _ref11 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(_ref10) {
635
537
  var libraryId, writeToken, image, imageName, objectId;
636
538
  return _regeneratorRuntime.wrap(function _callee6$(_context6) {
637
- while (1) {
638
- switch (_context6.prev = _context6.next) {
639
- case 0:
640
- libraryId = _ref10.libraryId, writeToken = _ref10.writeToken, image = _ref10.image, imageName = _ref10.imageName;
641
- ValidateLibrary(libraryId);
642
- objectId = libraryId.replace("ilib", "iq__");
643
- return _context6.abrupt("return", this.SetContentObjectImage({
644
- libraryId: libraryId,
645
- objectId: objectId,
646
- writeToken: writeToken,
647
- image: image,
648
- imageName: imageName
649
- }));
650
-
651
- case 4:
652
- case "end":
653
- return _context6.stop();
654
- }
539
+ while (1) switch (_context6.prev = _context6.next) {
540
+ case 0:
541
+ libraryId = _ref10.libraryId, writeToken = _ref10.writeToken, image = _ref10.image, imageName = _ref10.imageName;
542
+ ValidateLibrary(libraryId);
543
+ objectId = libraryId.replace("ilib", "iq__");
544
+ return _context6.abrupt("return", this.SetContentObjectImage({
545
+ libraryId: libraryId,
546
+ objectId: objectId,
547
+ writeToken: writeToken,
548
+ image: image,
549
+ imageName: imageName
550
+ }));
551
+ case 4:
552
+ case "end":
553
+ return _context6.stop();
655
554
  }
656
555
  }, _callee6, this);
657
556
  }));
658
-
659
557
  return function (_x6) {
660
558
  return _ref11.apply(this, arguments);
661
559
  };
662
560
  }();
561
+
663
562
  /**
664
563
  * Set the image associated with this object
665
564
  *
@@ -672,78 +571,67 @@ exports.SetContentLibraryImage = /*#__PURE__*/function () {
672
571
  * @param {string=} imageName - Name of the image file
673
572
  * @param {string=} imagePath=public/display_image - Metadata path of the image link (default is recommended)
674
573
  */
675
-
676
-
677
574
  exports.SetContentObjectImage = /*#__PURE__*/function () {
678
575
  var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(_ref12) {
679
576
  var libraryId, objectId, writeToken, image, imageName, _ref12$imagePath, imagePath, type, mimeType;
680
-
681
577
  return _regeneratorRuntime.wrap(function _callee7$(_context7) {
682
- while (1) {
683
- switch (_context7.prev = _context7.next) {
684
- case 0:
685
- libraryId = _ref12.libraryId, objectId = _ref12.objectId, writeToken = _ref12.writeToken, image = _ref12.image, imageName = _ref12.imageName, _ref12$imagePath = _ref12.imagePath, imagePath = _ref12$imagePath === void 0 ? "public/display_image" : _ref12$imagePath;
686
- ValidateParameters({
687
- libraryId: libraryId,
688
- objectId: objectId
689
- });
690
- ValidateWriteToken(writeToken);
691
- ValidatePresence("image", image);
692
- imageName = imageName || "display_image";
693
-
694
- if (!(_typeof(image) === "object")) {
695
- _context7.next = 9;
696
- break;
578
+ while (1) switch (_context7.prev = _context7.next) {
579
+ case 0:
580
+ libraryId = _ref12.libraryId, objectId = _ref12.objectId, writeToken = _ref12.writeToken, image = _ref12.image, imageName = _ref12.imageName, _ref12$imagePath = _ref12.imagePath, imagePath = _ref12$imagePath === void 0 ? "public/display_image" : _ref12$imagePath;
581
+ ValidateParameters({
582
+ libraryId: libraryId,
583
+ objectId: objectId
584
+ });
585
+ ValidateWriteToken(writeToken);
586
+ ValidatePresence("image", image);
587
+ imageName = imageName || "display_image";
588
+ if (!(_typeof(image) === "object")) {
589
+ _context7.next = 9;
590
+ break;
591
+ }
592
+ _context7.next = 8;
593
+ return new Response(image).arrayBuffer();
594
+ case 8:
595
+ image = _context7.sent;
596
+ case 9:
597
+ // Determine image type
598
+ type = ImageType(image);
599
+ mimeType = ["jpg", "jpeg", "png", "gif", "webp"].includes(type.ext) ? type.mime : "image/*";
600
+ _context7.next = 13;
601
+ return this.UploadFiles({
602
+ libraryId: libraryId,
603
+ objectId: objectId,
604
+ writeToken: writeToken,
605
+ encrypted: false,
606
+ fileInfo: [{
607
+ path: imageName,
608
+ mime_type: mimeType,
609
+ size: image.size || image.length || image.byteLength,
610
+ data: image
611
+ }]
612
+ });
613
+ case 13:
614
+ _context7.next = 15;
615
+ return this.ReplaceMetadata({
616
+ libraryId: libraryId,
617
+ objectId: objectId,
618
+ writeToken: writeToken,
619
+ metadataSubtree: imagePath,
620
+ metadata: {
621
+ "/": "./files/".concat(imageName)
697
622
  }
698
-
699
- _context7.next = 8;
700
- return new Response(image).arrayBuffer();
701
-
702
- case 8:
703
- image = _context7.sent;
704
-
705
- case 9:
706
- // Determine image type
707
- type = ImageType(image);
708
- mimeType = ["jpg", "jpeg", "png", "gif", "webp"].includes(type.ext) ? type.mime : "image/*";
709
- _context7.next = 13;
710
- return this.UploadFiles({
711
- libraryId: libraryId,
712
- objectId: objectId,
713
- writeToken: writeToken,
714
- encrypted: false,
715
- fileInfo: [{
716
- path: imageName,
717
- mime_type: mimeType,
718
- size: image.size || image.length || image.byteLength,
719
- data: image
720
- }]
721
- });
722
-
723
- case 13:
724
- _context7.next = 15;
725
- return this.ReplaceMetadata({
726
- libraryId: libraryId,
727
- objectId: objectId,
728
- writeToken: writeToken,
729
- metadataSubtree: imagePath,
730
- metadata: {
731
- "/": "./files/".concat(imageName)
732
- }
733
- });
734
-
735
- case 15:
736
- case "end":
737
- return _context7.stop();
738
- }
623
+ });
624
+ case 15:
625
+ case "end":
626
+ return _context7.stop();
739
627
  }
740
628
  }, _callee7, this);
741
629
  }));
742
-
743
630
  return function (_x7) {
744
631
  return _ref13.apply(this, arguments);
745
632
  };
746
633
  }();
634
+
747
635
  /**
748
636
  * NOT YET SUPPORTED - Delete the specified content library
749
637
  *
@@ -752,47 +640,40 @@ exports.SetContentObjectImage = /*#__PURE__*/function () {
752
640
  * @namedParams
753
641
  * @param {string} libraryId - ID of the library to delete
754
642
  */
755
-
756
-
757
643
  exports.DeleteContentLibrary = /*#__PURE__*/function () {
758
644
  var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(_ref14) {
759
645
  var libraryId, path, authorizationHeader;
760
646
  return _regeneratorRuntime.wrap(function _callee8$(_context8) {
761
- while (1) {
762
- switch (_context8.prev = _context8.next) {
763
- case 0:
764
- libraryId = _ref14.libraryId;
765
- throw Error("Not supported");
766
-
767
- case 6:
768
- authorizationHeader = _context8.sent;
769
- _context8.next = 9;
770
- return this.CallContractMethodAndWait({
771
- contractAddress: this.utils.HashToAddress(libraryId),
772
- methodName: "kill",
773
- methodArgs: []
774
- });
775
-
776
- case 9:
777
- _context8.next = 11;
778
- return this.HttpClient.Request({
779
- headers: authorizationHeader,
780
- method: "DELETE",
781
- path: path
782
- });
783
-
784
- case 11:
785
- case "end":
786
- return _context8.stop();
787
- }
647
+ while (1) switch (_context8.prev = _context8.next) {
648
+ case 0:
649
+ libraryId = _ref14.libraryId;
650
+ throw Error("Not supported");
651
+ case 6:
652
+ authorizationHeader = _context8.sent;
653
+ _context8.next = 9;
654
+ return this.CallContractMethodAndWait({
655
+ contractAddress: this.utils.HashToAddress(libraryId),
656
+ methodName: "kill",
657
+ methodArgs: []
658
+ });
659
+ case 9:
660
+ _context8.next = 11;
661
+ return this.HttpClient.Request({
662
+ headers: authorizationHeader,
663
+ method: "DELETE",
664
+ path: path
665
+ });
666
+ case 11:
667
+ case "end":
668
+ return _context8.stop();
788
669
  }
789
670
  }, _callee8, this);
790
671
  }));
791
-
792
672
  return function (_x8) {
793
673
  return _ref15.apply(this, arguments);
794
674
  };
795
675
  }();
676
+
796
677
  /* Library Content Type Management */
797
678
 
798
679
  /**
@@ -809,64 +690,53 @@ exports.DeleteContentLibrary = /*#__PURE__*/function () {
809
690
  *
810
691
  * @returns {Promise<string>} - Hash of the addContentType transaction
811
692
  */
812
-
813
-
814
693
  exports.AddLibraryContentType = /*#__PURE__*/function () {
815
694
  var _ref17 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(_ref16) {
816
695
  var libraryId, typeId, typeName, typeHash, customContractAddress, type, typeAddress, event;
817
696
  return _regeneratorRuntime.wrap(function _callee9$(_context9) {
818
- while (1) {
819
- switch (_context9.prev = _context9.next) {
820
- case 0:
821
- libraryId = _ref16.libraryId, typeId = _ref16.typeId, typeName = _ref16.typeName, typeHash = _ref16.typeHash, customContractAddress = _ref16.customContractAddress;
822
- ValidateLibrary(libraryId);
823
- this.Log("Adding library content type to ".concat(libraryId, ": ").concat(typeId || typeHash || typeName));
824
-
825
- if (typeHash) {
826
- typeId = this.utils.DecodeVersionHash(typeHash).objectId;
827
- }
828
-
829
- if (typeId) {
830
- _context9.next = 9;
831
- break;
832
- }
833
-
834
- _context9.next = 7;
835
- return this.ContentType({
836
- name: typeName
837
- });
838
-
839
- case 7:
840
- type = _context9.sent;
841
- typeId = type.id;
842
-
843
- case 9:
844
- this.Log("Type ID: ".concat(typeId));
845
- typeAddress = this.utils.HashToAddress(typeId);
846
- customContractAddress = customContractAddress || this.utils.nullAddress;
847
- _context9.next = 14;
848
- return this.ethClient.CallContractMethodAndWait({
849
- contractAddress: this.utils.HashToAddress(libraryId),
850
- methodName: "addContentType",
851
- methodArgs: [typeAddress, customContractAddress]
852
- });
853
-
854
- case 14:
855
- event = _context9.sent;
856
- return _context9.abrupt("return", event.transactionHash);
857
-
858
- case 16:
859
- case "end":
860
- return _context9.stop();
861
- }
697
+ while (1) switch (_context9.prev = _context9.next) {
698
+ case 0:
699
+ libraryId = _ref16.libraryId, typeId = _ref16.typeId, typeName = _ref16.typeName, typeHash = _ref16.typeHash, customContractAddress = _ref16.customContractAddress;
700
+ ValidateLibrary(libraryId);
701
+ this.Log("Adding library content type to ".concat(libraryId, ": ").concat(typeId || typeHash || typeName));
702
+ if (typeHash) {
703
+ typeId = this.utils.DecodeVersionHash(typeHash).objectId;
704
+ }
705
+ if (typeId) {
706
+ _context9.next = 9;
707
+ break;
708
+ }
709
+ _context9.next = 7;
710
+ return this.ContentType({
711
+ name: typeName
712
+ });
713
+ case 7:
714
+ type = _context9.sent;
715
+ typeId = type.id;
716
+ case 9:
717
+ this.Log("Type ID: ".concat(typeId));
718
+ typeAddress = this.utils.HashToAddress(typeId);
719
+ customContractAddress = customContractAddress || this.utils.nullAddress;
720
+ _context9.next = 14;
721
+ return this.ethClient.CallContractMethodAndWait({
722
+ contractAddress: this.utils.HashToAddress(libraryId),
723
+ methodName: "addContentType",
724
+ methodArgs: [typeAddress, customContractAddress]
725
+ });
726
+ case 14:
727
+ event = _context9.sent;
728
+ return _context9.abrupt("return", event.transactionHash);
729
+ case 16:
730
+ case "end":
731
+ return _context9.stop();
862
732
  }
863
733
  }, _callee9, this);
864
734
  }));
865
-
866
735
  return function (_x9) {
867
736
  return _ref17.apply(this, arguments);
868
737
  };
869
738
  }();
739
+
870
740
  /**
871
741
  * Remove the specified content type from a library
872
742
  *
@@ -879,63 +749,52 @@ exports.AddLibraryContentType = /*#__PURE__*/function () {
879
749
  *
880
750
  * @returns {Promise<string>} - Hash of the removeContentType transaction
881
751
  */
882
-
883
-
884
752
  exports.RemoveLibraryContentType = /*#__PURE__*/function () {
885
753
  var _ref19 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(_ref18) {
886
754
  var libraryId, typeId, typeName, typeHash, type, typeAddress, event;
887
755
  return _regeneratorRuntime.wrap(function _callee10$(_context10) {
888
- while (1) {
889
- switch (_context10.prev = _context10.next) {
890
- case 0:
891
- libraryId = _ref18.libraryId, typeId = _ref18.typeId, typeName = _ref18.typeName, typeHash = _ref18.typeHash;
892
- ValidateLibrary(libraryId);
893
- this.Log("Removing library content type from ".concat(libraryId, ": ").concat(typeId || typeHash || typeName));
894
-
895
- if (typeHash) {
896
- typeId = this.utils.DecodeVersionHash(typeHash).objectId;
897
- }
898
-
899
- if (typeId) {
900
- _context10.next = 9;
901
- break;
902
- }
903
-
904
- _context10.next = 7;
905
- return this.ContentType({
906
- name: typeName
907
- });
908
-
909
- case 7:
910
- type = _context10.sent;
911
- typeId = type.id;
912
-
913
- case 9:
914
- this.Log("Type ID: ".concat(typeId));
915
- typeAddress = this.utils.HashToAddress(typeId);
916
- _context10.next = 13;
917
- return this.ethClient.CallContractMethodAndWait({
918
- contractAddress: this.utils.HashToAddress(libraryId),
919
- methodName: "removeContentType",
920
- methodArgs: [typeAddress]
921
- });
922
-
923
- case 13:
924
- event = _context10.sent;
925
- return _context10.abrupt("return", event.transactionHash);
926
-
927
- case 15:
928
- case "end":
929
- return _context10.stop();
930
- }
756
+ while (1) switch (_context10.prev = _context10.next) {
757
+ case 0:
758
+ libraryId = _ref18.libraryId, typeId = _ref18.typeId, typeName = _ref18.typeName, typeHash = _ref18.typeHash;
759
+ ValidateLibrary(libraryId);
760
+ this.Log("Removing library content type from ".concat(libraryId, ": ").concat(typeId || typeHash || typeName));
761
+ if (typeHash) {
762
+ typeId = this.utils.DecodeVersionHash(typeHash).objectId;
763
+ }
764
+ if (typeId) {
765
+ _context10.next = 9;
766
+ break;
767
+ }
768
+ _context10.next = 7;
769
+ return this.ContentType({
770
+ name: typeName
771
+ });
772
+ case 7:
773
+ type = _context10.sent;
774
+ typeId = type.id;
775
+ case 9:
776
+ this.Log("Type ID: ".concat(typeId));
777
+ typeAddress = this.utils.HashToAddress(typeId);
778
+ _context10.next = 13;
779
+ return this.ethClient.CallContractMethodAndWait({
780
+ contractAddress: this.utils.HashToAddress(libraryId),
781
+ methodName: "removeContentType",
782
+ methodArgs: [typeAddress]
783
+ });
784
+ case 13:
785
+ event = _context10.sent;
786
+ return _context10.abrupt("return", event.transactionHash);
787
+ case 15:
788
+ case "end":
789
+ return _context10.stop();
931
790
  }
932
791
  }, _callee10, this);
933
792
  }));
934
-
935
793
  return function (_x10) {
936
794
  return _ref19.apply(this, arguments);
937
795
  };
938
796
  }();
797
+
939
798
  /* Content object creation, modification, deletion */
940
799
 
941
800
  /**
@@ -956,201 +815,166 @@ exports.RemoveLibraryContentType = /*#__PURE__*/function () {
956
815
  *
957
816
  * @returns {Promise<Object>} - Response containing the object ID and write token of the draft
958
817
  */
959
-
960
-
961
818
  exports.CreateContentObject = /*#__PURE__*/function () {
962
819
  var _ref21 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(_ref20) {
963
820
  var libraryId, objectId, _ref20$options, options, typeId, type, currentAccountAddress, canContribute, _yield$this$authClien3, contractAddress, path, createResponse;
964
-
965
821
  return _regeneratorRuntime.wrap(function _callee11$(_context11) {
966
- while (1) {
967
- switch (_context11.prev = _context11.next) {
968
- case 0:
969
- libraryId = _ref20.libraryId, objectId = _ref20.objectId, _ref20$options = _ref20.options, options = _ref20$options === void 0 ? {} : _ref20$options;
970
- ValidateLibrary(libraryId);
971
-
972
- if (objectId) {
973
- ValidateObject(objectId);
974
- }
975
-
976
- this.Log("Creating content object: ".concat(libraryId, " ").concat(objectId || "")); // Look up content type, if specified
977
-
978
- if (!options.type) {
979
- _context11.next = 26;
980
- break;
981
- }
982
-
983
- this.Log("Type specified: ".concat(options.type));
984
- type = options.type;
985
-
986
- if (!type.startsWith("hq__")) {
987
- _context11.next = 13;
988
- break;
989
- }
990
-
991
- _context11.next = 10;
992
- return this.ContentType({
993
- versionHash: type
994
- });
822
+ while (1) switch (_context11.prev = _context11.next) {
823
+ case 0:
824
+ libraryId = _ref20.libraryId, objectId = _ref20.objectId, _ref20$options = _ref20.options, options = _ref20$options === void 0 ? {} : _ref20$options;
825
+ ValidateLibrary(libraryId);
826
+ if (objectId) {
827
+ ValidateObject(objectId);
828
+ }
829
+ this.Log("Creating content object: ".concat(libraryId, " ").concat(objectId || ""));
995
830
 
996
- case 10:
997
- type = _context11.sent;
998
- _context11.next = 22;
831
+ // Look up content type, if specified
832
+ if (!options.type) {
833
+ _context11.next = 26;
999
834
  break;
1000
-
1001
- case 13:
1002
- if (!type.startsWith("iq__")) {
1003
- _context11.next = 19;
1004
- break;
1005
- }
1006
-
1007
- _context11.next = 16;
1008
- return this.ContentType({
1009
- typeId: type
1010
- });
1011
-
1012
- case 16:
1013
- type = _context11.sent;
1014
- _context11.next = 22;
835
+ }
836
+ this.Log("Type specified: ".concat(options.type));
837
+ type = options.type;
838
+ if (!type.startsWith("hq__")) {
839
+ _context11.next = 13;
1015
840
  break;
1016
-
1017
- case 19:
1018
- _context11.next = 21;
1019
- return this.ContentType({
1020
- name: type
1021
- });
1022
-
1023
- case 21:
1024
- type = _context11.sent;
1025
-
1026
- case 22:
1027
- if (type) {
1028
- _context11.next = 24;
1029
- break;
1030
- }
1031
-
1032
- throw Error("Unable to find content type '".concat(options.type, "'"));
1033
-
1034
- case 24:
1035
- typeId = type.id;
1036
- options.type = type.hash;
1037
-
1038
- case 26:
1039
- if (objectId) {
1040
- _context11.next = 44;
1041
- break;
1042
- }
1043
-
1044
- _context11.next = 29;
1045
- return this.CurrentAccountAddress();
1046
-
1047
- case 29:
1048
- currentAccountAddress = _context11.sent;
1049
- _context11.next = 32;
1050
- return this.CallContractMethod({
1051
- contractAddress: this.utils.HashToAddress(libraryId),
1052
- methodName: "canContribute",
1053
- methodArgs: [currentAccountAddress]
1054
- });
1055
-
1056
- case 32:
1057
- canContribute = _context11.sent;
1058
-
1059
- if (canContribute) {
1060
- _context11.next = 35;
1061
- break;
1062
- }
1063
-
1064
- throw Error("Current user does not have permission to create content in library ".concat(libraryId));
1065
-
1066
- case 35:
1067
- this.Log("Deploying contract...");
1068
- _context11.next = 38;
1069
- return this.authClient.CreateContentObject({
1070
- libraryId: libraryId,
1071
- typeId: typeId
1072
- });
1073
-
1074
- case 38:
1075
- _yield$this$authClien3 = _context11.sent;
1076
- contractAddress = _yield$this$authClien3.contractAddress;
1077
- objectId = this.utils.AddressToObjectId(contractAddress);
1078
- this.Log("Contract deployed: ".concat(contractAddress, " ").concat(objectId));
1079
- _context11.next = 51;
841
+ }
842
+ _context11.next = 10;
843
+ return this.ContentType({
844
+ versionHash: type
845
+ });
846
+ case 10:
847
+ type = _context11.sent;
848
+ _context11.next = 22;
849
+ break;
850
+ case 13:
851
+ if (!type.startsWith("iq__")) {
852
+ _context11.next = 19;
1080
853
  break;
1081
-
1082
- case 44:
1083
- _context11.t0 = this;
1084
- _context11.t1 = "Contract already deployed for contract type: ";
1085
- _context11.next = 48;
1086
- return this.AccessType({
1087
- id: objectId
1088
- });
1089
-
1090
- case 48:
1091
- _context11.t2 = _context11.sent;
1092
- _context11.t3 = _context11.t1.concat.call(_context11.t1, _context11.t2);
1093
-
1094
- _context11.t0.Log.call(_context11.t0, _context11.t3);
1095
-
1096
- case 51:
1097
- if (!options.visibility) {
1098
- _context11.next = 55;
1099
- break;
1100
- }
1101
-
1102
- this.Log("Setting visibility to ".concat(options.visibility));
854
+ }
855
+ _context11.next = 16;
856
+ return this.ContentType({
857
+ typeId: type
858
+ });
859
+ case 16:
860
+ type = _context11.sent;
861
+ _context11.next = 22;
862
+ break;
863
+ case 19:
864
+ _context11.next = 21;
865
+ return this.ContentType({
866
+ name: type
867
+ });
868
+ case 21:
869
+ type = _context11.sent;
870
+ case 22:
871
+ if (type) {
872
+ _context11.next = 24;
873
+ break;
874
+ }
875
+ throw Error("Unable to find content type '".concat(options.type, "'"));
876
+ case 24:
877
+ typeId = type.id;
878
+ options.type = type.hash;
879
+ case 26:
880
+ if (objectId) {
881
+ _context11.next = 44;
882
+ break;
883
+ }
884
+ _context11.next = 29;
885
+ return this.CurrentAccountAddress();
886
+ case 29:
887
+ currentAccountAddress = _context11.sent;
888
+ _context11.next = 32;
889
+ return this.CallContractMethod({
890
+ contractAddress: this.utils.HashToAddress(libraryId),
891
+ methodName: "canContribute",
892
+ methodArgs: [currentAccountAddress]
893
+ });
894
+ case 32:
895
+ canContribute = _context11.sent;
896
+ if (canContribute) {
897
+ _context11.next = 35;
898
+ break;
899
+ }
900
+ throw Error("Current user does not have permission to create content in library ".concat(libraryId));
901
+ case 35:
902
+ this.Log("Deploying contract...");
903
+ _context11.next = 38;
904
+ return this.authClient.CreateContentObject({
905
+ libraryId: libraryId,
906
+ typeId: typeId
907
+ });
908
+ case 38:
909
+ _yield$this$authClien3 = _context11.sent;
910
+ contractAddress = _yield$this$authClien3.contractAddress;
911
+ objectId = this.utils.AddressToObjectId(contractAddress);
912
+ this.Log("Contract deployed: ".concat(contractAddress, " ").concat(objectId));
913
+ _context11.next = 51;
914
+ break;
915
+ case 44:
916
+ _context11.t0 = this;
917
+ _context11.t1 = "Contract already deployed for contract type: ";
918
+ _context11.next = 48;
919
+ return this.AccessType({
920
+ id: objectId
921
+ });
922
+ case 48:
923
+ _context11.t2 = _context11.sent;
924
+ _context11.t3 = _context11.t1.concat.call(_context11.t1, _context11.t2);
925
+ _context11.t0.Log.call(_context11.t0, _context11.t3);
926
+ case 51:
927
+ if (!options.visibility) {
1103
928
  _context11.next = 55;
1104
- return this.SetVisibility({
1105
- id: objectId,
1106
- visibility: options.visibility
1107
- });
1108
-
1109
- case 55:
1110
- path = UrlJoin("qid", objectId);
1111
- _context11.t4 = this.utils;
1112
- _context11.t5 = this.HttpClient;
1113
- _context11.next = 60;
1114
- return this.authClient.AuthorizationHeader({
1115
- libraryId: libraryId,
1116
- objectId: objectId,
1117
- update: true
1118
- });
1119
-
1120
- case 60:
1121
- _context11.t6 = _context11.sent;
1122
- _context11.t7 = path;
1123
- _context11.t8 = options;
1124
- _context11.t9 = {
1125
- headers: _context11.t6,
1126
- method: "POST",
1127
- path: _context11.t7,
1128
- body: _context11.t8
1129
- };
1130
- _context11.t10 = _context11.t5.Request.call(_context11.t5, _context11.t9);
1131
- _context11.next = 67;
1132
- return _context11.t4.ResponseToJson.call(_context11.t4, _context11.t10);
1133
-
1134
- case 67:
1135
- createResponse = _context11.sent;
1136
- // Record the node used in creating this write token
1137
- this.HttpClient.RecordWriteToken(createResponse.write_token);
1138
- createResponse.writeToken = createResponse.write_token;
1139
- createResponse.objectId = createResponse.id;
1140
- return _context11.abrupt("return", createResponse);
1141
-
1142
- case 72:
1143
- case "end":
1144
- return _context11.stop();
1145
- }
929
+ break;
930
+ }
931
+ this.Log("Setting visibility to ".concat(options.visibility));
932
+ _context11.next = 55;
933
+ return this.SetVisibility({
934
+ id: objectId,
935
+ visibility: options.visibility
936
+ });
937
+ case 55:
938
+ path = UrlJoin("qid", objectId);
939
+ _context11.t4 = this.utils;
940
+ _context11.t5 = this.HttpClient;
941
+ _context11.next = 60;
942
+ return this.authClient.AuthorizationHeader({
943
+ libraryId: libraryId,
944
+ objectId: objectId,
945
+ update: true
946
+ });
947
+ case 60:
948
+ _context11.t6 = _context11.sent;
949
+ _context11.t7 = path;
950
+ _context11.t8 = options;
951
+ _context11.t9 = {
952
+ headers: _context11.t6,
953
+ method: "POST",
954
+ path: _context11.t7,
955
+ body: _context11.t8
956
+ };
957
+ _context11.t10 = _context11.t5.Request.call(_context11.t5, _context11.t9);
958
+ _context11.next = 67;
959
+ return _context11.t4.ResponseToJson.call(_context11.t4, _context11.t10);
960
+ case 67:
961
+ createResponse = _context11.sent;
962
+ // Record the node used in creating this write token
963
+ this.HttpClient.RecordWriteToken(createResponse.write_token);
964
+ createResponse.writeToken = createResponse.write_token;
965
+ createResponse.objectId = createResponse.id;
966
+ return _context11.abrupt("return", createResponse);
967
+ case 72:
968
+ case "end":
969
+ return _context11.stop();
1146
970
  }
1147
971
  }, _callee11, this);
1148
972
  }));
1149
-
1150
973
  return function (_x11) {
1151
974
  return _ref21.apply(this, arguments);
1152
975
  };
1153
976
  }();
977
+
1154
978
  /**
1155
979
  * Create a new content object draft from an existing content object version.
1156
980
  *
@@ -1169,152 +993,128 @@ exports.CreateContentObject = /*#__PURE__*/function () {
1169
993
  *
1170
994
  * @returns {Promise<Object>} - Response containing the object ID and write token of the draft
1171
995
  */
1172
-
1173
-
1174
996
  exports.CopyContentObject = /*#__PURE__*/function () {
1175
997
  var _ref23 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(_ref22) {
1176
998
  var _this2 = this;
1177
-
1178
999
  var libraryId, originalVersionHash, _ref22$options, options, _yield$this$CreateCon, objectId, writeToken, originalObjectId, metadata, permission, userCapKey, userConkKey;
1179
-
1180
1000
  return _regeneratorRuntime.wrap(function _callee13$(_context13) {
1181
- while (1) {
1182
- switch (_context13.prev = _context13.next) {
1183
- case 0:
1184
- libraryId = _ref22.libraryId, originalVersionHash = _ref22.originalVersionHash, _ref22$options = _ref22.options, options = _ref22$options === void 0 ? {} : _ref22$options;
1185
- ValidateLibrary(libraryId);
1186
- ValidateVersion(originalVersionHash);
1187
- options.copy_from = originalVersionHash;
1188
- _context13.next = 6;
1189
- return this.CreateContentObject({
1190
- libraryId: libraryId,
1191
- options: options
1192
- });
1193
-
1194
- case 6:
1195
- _yield$this$CreateCon = _context13.sent;
1196
- objectId = _yield$this$CreateCon.objectId;
1197
- writeToken = _yield$this$CreateCon.writeToken;
1198
- originalObjectId = this.utils.DecodeVersionHash(originalVersionHash).objectId;
1199
- _context13.next = 12;
1200
- return this.ContentObjectMetadata({
1201
- versionHash: originalVersionHash
1202
- });
1203
-
1204
- case 12:
1205
- metadata = _context13.sent;
1206
- _context13.next = 15;
1207
- return this.Permission({
1208
- objectId: originalObjectId
1209
- });
1210
-
1211
- case 15:
1212
- permission = _context13.sent;
1213
- // User CAP
1214
- userCapKey = "eluv.caps.iusr".concat(this.utils.AddressToHash(this.signer.address));
1215
-
1216
- if (!metadata[userCapKey]) {
1217
- _context13.next = 33;
1218
- break;
1219
- }
1220
-
1221
- _context13.next = 20;
1222
- return this.Crypto.DecryptCap(metadata[userCapKey], this.signer._signingKey().privateKey);
1223
-
1224
- case 20:
1225
- userConkKey = _context13.sent;
1226
- userConkKey.qid = objectId;
1227
- _context13.t0 = this;
1228
- _context13.t1 = libraryId;
1229
- _context13.t2 = objectId;
1230
- _context13.t3 = writeToken;
1231
- _context13.t4 = userCapKey;
1232
- _context13.next = 29;
1233
- return this.Crypto.EncryptConk(userConkKey, this.signer._signingKey().publicKey);
1234
-
1235
- case 29:
1236
- _context13.t5 = _context13.sent;
1237
- _context13.t6 = {
1238
- libraryId: _context13.t1,
1239
- objectId: _context13.t2,
1240
- writeToken: _context13.t3,
1241
- metadataSubtree: _context13.t4,
1242
- metadata: _context13.t5
1243
- };
1001
+ while (1) switch (_context13.prev = _context13.next) {
1002
+ case 0:
1003
+ libraryId = _ref22.libraryId, originalVersionHash = _ref22.originalVersionHash, _ref22$options = _ref22.options, options = _ref22$options === void 0 ? {} : _ref22$options;
1004
+ ValidateLibrary(libraryId);
1005
+ ValidateVersion(originalVersionHash);
1006
+ options.copy_from = originalVersionHash;
1007
+ _context13.next = 6;
1008
+ return this.CreateContentObject({
1009
+ libraryId: libraryId,
1010
+ options: options
1011
+ });
1012
+ case 6:
1013
+ _yield$this$CreateCon = _context13.sent;
1014
+ objectId = _yield$this$CreateCon.objectId;
1015
+ writeToken = _yield$this$CreateCon.writeToken;
1016
+ originalObjectId = this.utils.DecodeVersionHash(originalVersionHash).objectId;
1017
+ _context13.next = 12;
1018
+ return this.ContentObjectMetadata({
1019
+ versionHash: originalVersionHash
1020
+ });
1021
+ case 12:
1022
+ metadata = _context13.sent;
1023
+ _context13.next = 15;
1024
+ return this.Permission({
1025
+ objectId: originalObjectId
1026
+ });
1027
+ case 15:
1028
+ permission = _context13.sent;
1029
+ // User CAP
1030
+ userCapKey = "eluv.caps.iusr".concat(this.utils.AddressToHash(this.signer.address));
1031
+ if (!metadata[userCapKey]) {
1244
1032
  _context13.next = 33;
1245
- return _context13.t0.ReplaceMetadata.call(_context13.t0, _context13.t6);
1246
-
1247
- case 33:
1248
- _context13.next = 35;
1249
- return Promise.all(Object.keys(metadata).filter(function (key) {
1250
- return key.startsWith("eluv.caps.ikms");
1251
- }).map( /*#__PURE__*/function () {
1252
- var _ref24 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(kmsCapKey) {
1253
- return _regeneratorRuntime.wrap(function _callee12$(_context12) {
1254
- while (1) {
1255
- switch (_context12.prev = _context12.next) {
1256
- case 0:
1257
- _context12.next = 2;
1258
- return _this2.DeleteMetadata({
1259
- libraryId: libraryId,
1260
- objectId: objectId,
1261
- writeToken: writeToken,
1262
- metadataSubtree: kmsCapKey
1263
- });
1264
-
1265
- case 2:
1266
- return _context12.abrupt("return", _context12.sent);
1267
-
1268
- case 3:
1269
- case "end":
1270
- return _context12.stop();
1271
- }
1272
- }
1273
- }, _callee12);
1274
- }));
1275
-
1276
- return function (_x13) {
1277
- return _ref24.apply(this, arguments);
1278
- };
1279
- }()));
1280
-
1281
- case 35:
1282
- if (!(permission !== "owner")) {
1283
- _context13.next = 38;
1284
- break;
1285
- }
1286
-
1033
+ break;
1034
+ }
1035
+ _context13.next = 20;
1036
+ return this.Crypto.DecryptCap(metadata[userCapKey], this.signer._signingKey().privateKey);
1037
+ case 20:
1038
+ userConkKey = _context13.sent;
1039
+ userConkKey.qid = objectId;
1040
+ _context13.t0 = this;
1041
+ _context13.t1 = libraryId;
1042
+ _context13.t2 = objectId;
1043
+ _context13.t3 = writeToken;
1044
+ _context13.t4 = userCapKey;
1045
+ _context13.next = 29;
1046
+ return this.Crypto.EncryptConk(userConkKey, this.signer._signingKey().publicKey);
1047
+ case 29:
1048
+ _context13.t5 = _context13.sent;
1049
+ _context13.t6 = {
1050
+ libraryId: _context13.t1,
1051
+ objectId: _context13.t2,
1052
+ writeToken: _context13.t3,
1053
+ metadataSubtree: _context13.t4,
1054
+ metadata: _context13.t5
1055
+ };
1056
+ _context13.next = 33;
1057
+ return _context13.t0.ReplaceMetadata.call(_context13.t0, _context13.t6);
1058
+ case 33:
1059
+ _context13.next = 35;
1060
+ return Promise.all(Object.keys(metadata).filter(function (key) {
1061
+ return key.startsWith("eluv.caps.ikms");
1062
+ }).map( /*#__PURE__*/function () {
1063
+ var _ref24 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(kmsCapKey) {
1064
+ return _regeneratorRuntime.wrap(function _callee12$(_context12) {
1065
+ while (1) switch (_context12.prev = _context12.next) {
1066
+ case 0:
1067
+ _context12.next = 2;
1068
+ return _this2.DeleteMetadata({
1069
+ libraryId: libraryId,
1070
+ objectId: objectId,
1071
+ writeToken: writeToken,
1072
+ metadataSubtree: kmsCapKey
1073
+ });
1074
+ case 2:
1075
+ return _context12.abrupt("return", _context12.sent);
1076
+ case 3:
1077
+ case "end":
1078
+ return _context12.stop();
1079
+ }
1080
+ }, _callee12);
1081
+ }));
1082
+ return function (_x13) {
1083
+ return _ref24.apply(this, arguments);
1084
+ };
1085
+ }()));
1086
+ case 35:
1087
+ if (!(permission !== "owner")) {
1287
1088
  _context13.next = 38;
1288
- return this.CreateEncryptionConk({
1289
- libraryId: libraryId,
1290
- objectId: objectId,
1291
- writeToken: writeToken,
1292
- createKMSConk: true
1293
- });
1294
-
1295
- case 38:
1296
- _context13.next = 40;
1297
- return this.FinalizeContentObject({
1298
- libraryId: libraryId,
1299
- objectId: objectId,
1300
- writeToken: writeToken
1301
- });
1302
-
1303
- case 40:
1304
- return _context13.abrupt("return", _context13.sent);
1305
-
1306
- case 41:
1307
- case "end":
1308
- return _context13.stop();
1309
- }
1089
+ break;
1090
+ }
1091
+ _context13.next = 38;
1092
+ return this.CreateEncryptionConk({
1093
+ libraryId: libraryId,
1094
+ objectId: objectId,
1095
+ writeToken: writeToken,
1096
+ createKMSConk: true
1097
+ });
1098
+ case 38:
1099
+ _context13.next = 40;
1100
+ return this.FinalizeContentObject({
1101
+ libraryId: libraryId,
1102
+ objectId: objectId,
1103
+ writeToken: writeToken
1104
+ });
1105
+ case 40:
1106
+ return _context13.abrupt("return", _context13.sent);
1107
+ case 41:
1108
+ case "end":
1109
+ return _context13.stop();
1310
1110
  }
1311
1111
  }, _callee13, this);
1312
1112
  }));
1313
-
1314
1113
  return function (_x12) {
1315
1114
  return _ref23.apply(this, arguments);
1316
1115
  };
1317
1116
  }();
1117
+
1318
1118
  /**
1319
1119
  * Create a non-owner cap key using the specified public key and address
1320
1120
  *
@@ -1327,97 +1127,80 @@ exports.CopyContentObject = /*#__PURE__*/function () {
1327
1127
  *
1328
1128
  * @returns {Promise<Object>}
1329
1129
  */
1330
-
1331
-
1332
1130
  exports.CreateNonOwnerCap = /*#__PURE__*/function () {
1333
1131
  var _ref26 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(_ref25) {
1334
1132
  var objectId, libraryId, publicKey, writeToken, userCapKey, userCapValue, userConk, publicAddress, targetUserCapKey, targetUserCapValue, finalize;
1335
1133
  return _regeneratorRuntime.wrap(function _callee14$(_context14) {
1336
- while (1) {
1337
- switch (_context14.prev = _context14.next) {
1338
- case 0:
1339
- objectId = _ref25.objectId, libraryId = _ref25.libraryId, publicKey = _ref25.publicKey, writeToken = _ref25.writeToken;
1340
- userCapKey = "eluv.caps.iusr".concat(this.utils.AddressToHash(this.signer.address));
1341
- _context14.next = 4;
1342
- return this.ContentObjectMetadata({
1343
- objectId: objectId,
1344
- libraryId: libraryId,
1345
- metadataSubtree: userCapKey
1346
- });
1347
-
1348
- case 4:
1349
- userCapValue = _context14.sent;
1350
-
1351
- if (userCapValue) {
1352
- _context14.next = 7;
1353
- break;
1354
- }
1355
-
1356
- throw Error("No user cap found for current user");
1357
-
1358
- case 7:
1359
- _context14.next = 9;
1360
- return this.Crypto.DecryptCap(userCapValue, this.signer._signingKey().privateKey);
1361
-
1362
- case 9:
1363
- userConk = _context14.sent;
1364
- publicAddress = this.utils.PublicKeyToAddress(publicKey);
1365
- targetUserCapKey = "eluv.caps.iusr".concat(this.utils.AddressToHash(publicAddress));
1366
- _context14.next = 14;
1367
- return this.Crypto.EncryptConk(userConk, publicKey);
1368
-
1369
- case 14:
1370
- targetUserCapValue = _context14.sent;
1371
- finalize = !writeToken;
1372
-
1373
- if (writeToken) {
1374
- _context14.next = 20;
1375
- break;
1376
- }
1377
-
1378
- _context14.next = 19;
1379
- return this.EditContentObject({
1380
- libraryId: libraryId,
1381
- objectId: objectId
1382
- }).writeToken;
1383
-
1384
- case 19:
1385
- writeToken = _context14.sent;
1386
-
1387
- case 20:
1388
- this.ReplaceMetadata({
1389
- libraryId: libraryId,
1390
- objectId: objectId,
1391
- writeToken: writeToken,
1392
- metadataSubtree: targetUserCapKey,
1393
- metadata: targetUserCapValue
1394
- });
1395
-
1396
- if (!finalize) {
1397
- _context14.next = 24;
1398
- break;
1399
- }
1400
-
1134
+ while (1) switch (_context14.prev = _context14.next) {
1135
+ case 0:
1136
+ objectId = _ref25.objectId, libraryId = _ref25.libraryId, publicKey = _ref25.publicKey, writeToken = _ref25.writeToken;
1137
+ userCapKey = "eluv.caps.iusr".concat(this.utils.AddressToHash(this.signer.address));
1138
+ _context14.next = 4;
1139
+ return this.ContentObjectMetadata({
1140
+ objectId: objectId,
1141
+ libraryId: libraryId,
1142
+ metadataSubtree: userCapKey
1143
+ });
1144
+ case 4:
1145
+ userCapValue = _context14.sent;
1146
+ if (userCapValue) {
1147
+ _context14.next = 7;
1148
+ break;
1149
+ }
1150
+ throw Error("No user cap found for current user");
1151
+ case 7:
1152
+ _context14.next = 9;
1153
+ return this.Crypto.DecryptCap(userCapValue, this.signer._signingKey().privateKey);
1154
+ case 9:
1155
+ userConk = _context14.sent;
1156
+ publicAddress = this.utils.PublicKeyToAddress(publicKey);
1157
+ targetUserCapKey = "eluv.caps.iusr".concat(this.utils.AddressToHash(publicAddress));
1158
+ _context14.next = 14;
1159
+ return this.Crypto.EncryptConk(userConk, publicKey);
1160
+ case 14:
1161
+ targetUserCapValue = _context14.sent;
1162
+ finalize = !writeToken;
1163
+ if (writeToken) {
1164
+ _context14.next = 20;
1165
+ break;
1166
+ }
1167
+ _context14.next = 19;
1168
+ return this.EditContentObject({
1169
+ libraryId: libraryId,
1170
+ objectId: objectId
1171
+ }).writeToken;
1172
+ case 19:
1173
+ writeToken = _context14.sent;
1174
+ case 20:
1175
+ this.ReplaceMetadata({
1176
+ libraryId: libraryId,
1177
+ objectId: objectId,
1178
+ writeToken: writeToken,
1179
+ metadataSubtree: targetUserCapKey,
1180
+ metadata: targetUserCapValue
1181
+ });
1182
+ if (!finalize) {
1401
1183
  _context14.next = 24;
1402
- return this.FinalizeContentObject({
1403
- libraryId: libraryId,
1404
- objectId: objectId,
1405
- writeToken: writeToken,
1406
- commitMessage: "Create non-owner cap"
1407
- });
1408
-
1409
- case 24:
1410
- case "end":
1411
- return _context14.stop();
1412
- }
1184
+ break;
1185
+ }
1186
+ _context14.next = 24;
1187
+ return this.FinalizeContentObject({
1188
+ libraryId: libraryId,
1189
+ objectId: objectId,
1190
+ writeToken: writeToken,
1191
+ commitMessage: "Create non-owner cap"
1192
+ });
1193
+ case 24:
1194
+ case "end":
1195
+ return _context14.stop();
1413
1196
  }
1414
1197
  }, _callee14, this);
1415
1198
  }));
1416
-
1417
1199
  return function (_x14) {
1418
1200
  return _ref26.apply(this, arguments);
1419
1201
  };
1420
1202
  }();
1203
+
1421
1204
  /**
1422
1205
  * Create a new content object draft from an existing object.
1423
1206
  *
@@ -1431,132 +1214,111 @@ exports.CreateNonOwnerCap = /*#__PURE__*/function () {
1431
1214
  *
1432
1215
  * @returns {Promise<object>} - Response containing the object ID and write token of the draft, as well as URL of node handling the draft
1433
1216
  */
1434
-
1435
-
1436
1217
  exports.EditContentObject = /*#__PURE__*/function () {
1437
1218
  var _ref28 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(_ref27) {
1438
1219
  var libraryId, objectId, _ref27$options, options, path, rawEditResponse, actualUrl, nodeUrl, editResponse;
1439
-
1440
1220
  return _regeneratorRuntime.wrap(function _callee15$(_context15) {
1441
- while (1) {
1442
- switch (_context15.prev = _context15.next) {
1443
- case 0:
1444
- libraryId = _ref27.libraryId, objectId = _ref27.objectId, _ref27$options = _ref27.options, options = _ref27$options === void 0 ? {} : _ref27$options;
1445
- ValidateParameters({
1446
- libraryId: libraryId,
1447
- objectId: objectId
1448
- });
1449
- this.Log("Opening content draft: ".concat(libraryId, " ").concat(objectId));
1450
-
1451
- if (!("type" in options && options.type)) {
1452
- _context15.next = 23;
1453
- break;
1454
- }
1455
-
1456
- if (!options.type.startsWith("hq__")) {
1457
- _context15.next = 10;
1458
- break;
1459
- }
1460
-
1461
- _context15.next = 7;
1462
- return this.ContentType({
1463
- versionHash: options.type
1464
- });
1465
-
1466
- case 7:
1467
- options.type = _context15.sent.hash;
1221
+ while (1) switch (_context15.prev = _context15.next) {
1222
+ case 0:
1223
+ libraryId = _ref27.libraryId, objectId = _ref27.objectId, _ref27$options = _ref27.options, options = _ref27$options === void 0 ? {} : _ref27$options;
1224
+ ValidateParameters({
1225
+ libraryId: libraryId,
1226
+ objectId: objectId
1227
+ });
1228
+ this.Log("Opening content draft: ".concat(libraryId, " ").concat(objectId));
1229
+ if (!("type" in options && options.type)) {
1468
1230
  _context15.next = 23;
1469
1231
  break;
1470
-
1471
- case 10:
1472
- if (!options.type.startsWith("iq__")) {
1473
- _context15.next = 16;
1474
- break;
1475
- }
1476
-
1477
- _context15.next = 13;
1478
- return this.ContentType({
1479
- typeId: options.type
1480
- });
1481
-
1482
- case 13:
1483
- options.type = _context15.sent.hash;
1484
- _context15.next = 23;
1232
+ }
1233
+ if (!options.type.startsWith("hq__")) {
1234
+ _context15.next = 10;
1485
1235
  break;
1486
-
1487
- case 16:
1488
- if (!options.type) {
1489
- _context15.next = 22;
1490
- break;
1491
- }
1492
-
1493
- _context15.next = 19;
1494
- return this.ContentType({
1495
- name: options.type
1496
- });
1497
-
1498
- case 19:
1499
- options.type = _context15.sent.hash;
1500
- _context15.next = 23;
1236
+ }
1237
+ _context15.next = 7;
1238
+ return this.ContentType({
1239
+ versionHash: options.type
1240
+ });
1241
+ case 7:
1242
+ options.type = _context15.sent.hash;
1243
+ _context15.next = 23;
1244
+ break;
1245
+ case 10:
1246
+ if (!options.type.startsWith("iq__")) {
1247
+ _context15.next = 16;
1501
1248
  break;
1502
-
1503
- case 22:
1504
- options.type = "";
1505
-
1506
- case 23:
1507
- path = UrlJoin("qid", objectId);
1508
- _context15.t0 = this.HttpClient;
1509
- _context15.next = 27;
1510
- return this.authClient.AuthorizationHeader({
1511
- libraryId: libraryId,
1512
- objectId: objectId,
1513
- update: true
1514
- });
1515
-
1516
- case 27:
1517
- _context15.t1 = _context15.sent;
1518
- _context15.t2 = path;
1519
- _context15.t3 = options;
1520
- _context15.t4 = {
1521
- headers: _context15.t1,
1522
- method: "POST",
1523
- path: _context15.t2,
1524
- body: _context15.t3
1525
- };
1526
- _context15.next = 33;
1527
- return _context15.t0.Request.call(_context15.t0, _context15.t4);
1528
-
1529
- case 33:
1530
- rawEditResponse = _context15.sent;
1531
- actualUrl = new URL(rawEditResponse.url);
1532
- actualUrl.pathname = "";
1533
- actualUrl.search = "";
1534
- actualUrl.hash = "";
1535
- nodeUrl = actualUrl.href;
1536
- _context15.next = 41;
1537
- return this.utils.ResponseToJson(rawEditResponse);
1538
-
1539
- case 41:
1540
- editResponse = _context15.sent;
1541
- // Record the node used in creating this write token
1542
- this.HttpClient.RecordWriteToken(editResponse.write_token, nodeUrl);
1543
- editResponse.writeToken = editResponse.write_token;
1544
- editResponse.objectId = editResponse.id;
1545
- editResponse.nodeUrl = nodeUrl;
1546
- return _context15.abrupt("return", editResponse);
1547
-
1548
- case 47:
1549
- case "end":
1550
- return _context15.stop();
1551
- }
1249
+ }
1250
+ _context15.next = 13;
1251
+ return this.ContentType({
1252
+ typeId: options.type
1253
+ });
1254
+ case 13:
1255
+ options.type = _context15.sent.hash;
1256
+ _context15.next = 23;
1257
+ break;
1258
+ case 16:
1259
+ if (!options.type) {
1260
+ _context15.next = 22;
1261
+ break;
1262
+ }
1263
+ _context15.next = 19;
1264
+ return this.ContentType({
1265
+ name: options.type
1266
+ });
1267
+ case 19:
1268
+ options.type = _context15.sent.hash;
1269
+ _context15.next = 23;
1270
+ break;
1271
+ case 22:
1272
+ options.type = "";
1273
+ case 23:
1274
+ path = UrlJoin("qid", objectId);
1275
+ _context15.t0 = this.HttpClient;
1276
+ _context15.next = 27;
1277
+ return this.authClient.AuthorizationHeader({
1278
+ libraryId: libraryId,
1279
+ objectId: objectId,
1280
+ update: true
1281
+ });
1282
+ case 27:
1283
+ _context15.t1 = _context15.sent;
1284
+ _context15.t2 = path;
1285
+ _context15.t3 = options;
1286
+ _context15.t4 = {
1287
+ headers: _context15.t1,
1288
+ method: "POST",
1289
+ path: _context15.t2,
1290
+ body: _context15.t3
1291
+ };
1292
+ _context15.next = 33;
1293
+ return _context15.t0.Request.call(_context15.t0, _context15.t4);
1294
+ case 33:
1295
+ rawEditResponse = _context15.sent;
1296
+ actualUrl = new URL(rawEditResponse.url);
1297
+ actualUrl.pathname = "";
1298
+ actualUrl.search = "";
1299
+ actualUrl.hash = "";
1300
+ nodeUrl = actualUrl.href;
1301
+ _context15.next = 41;
1302
+ return this.utils.ResponseToJson(rawEditResponse);
1303
+ case 41:
1304
+ editResponse = _context15.sent;
1305
+ // Record the node used in creating this write token
1306
+ this.HttpClient.RecordWriteToken(editResponse.write_token, nodeUrl);
1307
+ editResponse.writeToken = editResponse.write_token;
1308
+ editResponse.objectId = editResponse.id;
1309
+ editResponse.nodeUrl = nodeUrl;
1310
+ return _context15.abrupt("return", editResponse);
1311
+ case 47:
1312
+ case "end":
1313
+ return _context15.stop();
1552
1314
  }
1553
1315
  }, _callee15, this);
1554
1316
  }));
1555
-
1556
1317
  return function (_x15) {
1557
1318
  return _ref28.apply(this, arguments);
1558
1319
  };
1559
1320
  }();
1321
+
1560
1322
  /**
1561
1323
  * Create and finalize new content object draft from an existing object.
1562
1324
  *
@@ -1583,64 +1345,53 @@ exports.EditContentObject = /*#__PURE__*/function () {
1583
1345
  *
1584
1346
  * @returns {Promise<object>} - Response from FinalizeContentObject
1585
1347
  */
1586
-
1587
-
1588
1348
  exports.CreateAndFinalizeContentObject = /*#__PURE__*/function () {
1589
1349
  var _ref30 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16(_ref29) {
1590
1350
  var libraryId, callback, _ref29$options, options, _ref29$commitMessage, commitMessage, _ref29$publish, publish, _ref29$awaitCommitCon, awaitCommitConfirmation, args, id, writeToken;
1591
-
1592
1351
  return _regeneratorRuntime.wrap(function _callee16$(_context16) {
1593
- while (1) {
1594
- switch (_context16.prev = _context16.next) {
1595
- case 0:
1596
- libraryId = _ref29.libraryId, callback = _ref29.callback, _ref29$options = _ref29.options, options = _ref29$options === void 0 ? {} : _ref29$options, _ref29$commitMessage = _ref29.commitMessage, commitMessage = _ref29$commitMessage === void 0 ? "" : _ref29$commitMessage, _ref29$publish = _ref29.publish, publish = _ref29$publish === void 0 ? true : _ref29$publish, _ref29$awaitCommitCon = _ref29.awaitCommitConfirmation, awaitCommitConfirmation = _ref29$awaitCommitCon === void 0 ? true : _ref29$awaitCommitCon;
1597
- _context16.next = 3;
1598
- return this.CreateContentObject({
1599
- libraryId: libraryId,
1600
- options: options
1601
- });
1602
-
1603
- case 3:
1604
- args = _context16.sent;
1605
- id = args.id, writeToken = args.writeToken;
1606
-
1607
- if (!callback) {
1608
- _context16.next = 8;
1609
- break;
1610
- }
1611
-
1352
+ while (1) switch (_context16.prev = _context16.next) {
1353
+ case 0:
1354
+ libraryId = _ref29.libraryId, callback = _ref29.callback, _ref29$options = _ref29.options, options = _ref29$options === void 0 ? {} : _ref29$options, _ref29$commitMessage = _ref29.commitMessage, commitMessage = _ref29$commitMessage === void 0 ? "" : _ref29$commitMessage, _ref29$publish = _ref29.publish, publish = _ref29$publish === void 0 ? true : _ref29$publish, _ref29$awaitCommitCon = _ref29.awaitCommitConfirmation, awaitCommitConfirmation = _ref29$awaitCommitCon === void 0 ? true : _ref29$awaitCommitCon;
1355
+ _context16.next = 3;
1356
+ return this.CreateContentObject({
1357
+ libraryId: libraryId,
1358
+ options: options
1359
+ });
1360
+ case 3:
1361
+ args = _context16.sent;
1362
+ id = args.id, writeToken = args.writeToken;
1363
+ if (!callback) {
1612
1364
  _context16.next = 8;
1613
- return callback({
1614
- objectId: id,
1615
- writeToken: writeToken
1616
- });
1617
-
1618
- case 8:
1619
- _context16.next = 10;
1620
- return this.FinalizeContentObject({
1621
- libraryId: libraryId,
1622
- objectId: id,
1623
- writeToken: writeToken,
1624
- commitMessage: commitMessage,
1625
- publish: publish,
1626
- awaitCommitConfirmation: awaitCommitConfirmation
1627
- });
1628
-
1629
- case 10:
1630
- return _context16.abrupt("return", _context16.sent);
1631
-
1632
- case 11:
1633
- case "end":
1634
- return _context16.stop();
1635
- }
1365
+ break;
1366
+ }
1367
+ _context16.next = 8;
1368
+ return callback({
1369
+ objectId: id,
1370
+ writeToken: writeToken
1371
+ });
1372
+ case 8:
1373
+ _context16.next = 10;
1374
+ return this.FinalizeContentObject({
1375
+ libraryId: libraryId,
1376
+ objectId: id,
1377
+ writeToken: writeToken,
1378
+ commitMessage: commitMessage,
1379
+ publish: publish,
1380
+ awaitCommitConfirmation: awaitCommitConfirmation
1381
+ });
1382
+ case 10:
1383
+ return _context16.abrupt("return", _context16.sent);
1384
+ case 11:
1385
+ case "end":
1386
+ return _context16.stop();
1636
1387
  }
1637
1388
  }, _callee16, this);
1638
1389
  }));
1639
-
1640
1390
  return function (_x16) {
1641
1391
  return _ref30.apply(this, arguments);
1642
1392
  };
1643
1393
  }();
1394
+
1644
1395
  /**
1645
1396
  * Create and finalize new content object draft from an existing object.
1646
1397
  *
@@ -1668,189 +1419,151 @@ exports.CreateAndFinalizeContentObject = /*#__PURE__*/function () {
1668
1419
  *
1669
1420
  * @returns {Promise<object>} - Response from FinalizeContentObject
1670
1421
  */
1671
-
1672
-
1673
1422
  exports.EditAndFinalizeContentObject = /*#__PURE__*/function () {
1674
1423
  var _ref32 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee17(_ref31) {
1675
1424
  var libraryId, objectId, callback, _ref31$options, options, _ref31$commitMessage, commitMessage, _ref31$publish, publish, _ref31$awaitCommitCon, awaitCommitConfirmation, _yield$this$EditConte, writeToken;
1676
-
1677
1425
  return _regeneratorRuntime.wrap(function _callee17$(_context17) {
1678
- while (1) {
1679
- switch (_context17.prev = _context17.next) {
1680
- case 0:
1681
- libraryId = _ref31.libraryId, objectId = _ref31.objectId, callback = _ref31.callback, _ref31$options = _ref31.options, options = _ref31$options === void 0 ? {} : _ref31$options, _ref31$commitMessage = _ref31.commitMessage, commitMessage = _ref31$commitMessage === void 0 ? "" : _ref31$commitMessage, _ref31$publish = _ref31.publish, publish = _ref31$publish === void 0 ? true : _ref31$publish, _ref31$awaitCommitCon = _ref31.awaitCommitConfirmation, awaitCommitConfirmation = _ref31$awaitCommitCon === void 0 ? true : _ref31$awaitCommitCon;
1682
- _context17.next = 3;
1683
- return this.EditContentObject({
1684
- libraryId: libraryId,
1685
- objectId: objectId,
1686
- options: options
1687
- });
1688
-
1689
- case 3:
1690
- _yield$this$EditConte = _context17.sent;
1691
- writeToken = _yield$this$EditConte.writeToken;
1692
-
1693
- if (!callback) {
1694
- _context17.next = 8;
1695
- break;
1696
- }
1697
-
1426
+ while (1) switch (_context17.prev = _context17.next) {
1427
+ case 0:
1428
+ libraryId = _ref31.libraryId, objectId = _ref31.objectId, callback = _ref31.callback, _ref31$options = _ref31.options, options = _ref31$options === void 0 ? {} : _ref31$options, _ref31$commitMessage = _ref31.commitMessage, commitMessage = _ref31$commitMessage === void 0 ? "" : _ref31$commitMessage, _ref31$publish = _ref31.publish, publish = _ref31$publish === void 0 ? true : _ref31$publish, _ref31$awaitCommitCon = _ref31.awaitCommitConfirmation, awaitCommitConfirmation = _ref31$awaitCommitCon === void 0 ? true : _ref31$awaitCommitCon;
1429
+ _context17.next = 3;
1430
+ return this.EditContentObject({
1431
+ libraryId: libraryId,
1432
+ objectId: objectId,
1433
+ options: options
1434
+ });
1435
+ case 3:
1436
+ _yield$this$EditConte = _context17.sent;
1437
+ writeToken = _yield$this$EditConte.writeToken;
1438
+ if (!callback) {
1698
1439
  _context17.next = 8;
1699
- return callback({
1700
- writeToken: writeToken
1701
- });
1702
-
1703
- case 8:
1704
- _context17.next = 10;
1705
- return this.FinalizeContentObject({
1706
- libraryId: libraryId,
1707
- objectId: objectId,
1708
- writeToken: writeToken,
1709
- commitMessage: commitMessage,
1710
- publish: publish,
1711
- awaitCommitConfirmation: awaitCommitConfirmation
1712
- });
1713
-
1714
- case 10:
1715
- return _context17.abrupt("return", _context17.sent);
1716
-
1717
- case 11:
1718
- case "end":
1719
- return _context17.stop();
1720
- }
1440
+ break;
1441
+ }
1442
+ _context17.next = 8;
1443
+ return callback({
1444
+ writeToken: writeToken
1445
+ });
1446
+ case 8:
1447
+ _context17.next = 10;
1448
+ return this.FinalizeContentObject({
1449
+ libraryId: libraryId,
1450
+ objectId: objectId,
1451
+ writeToken: writeToken,
1452
+ commitMessage: commitMessage,
1453
+ publish: publish,
1454
+ awaitCommitConfirmation: awaitCommitConfirmation
1455
+ });
1456
+ case 10:
1457
+ return _context17.abrupt("return", _context17.sent);
1458
+ case 11:
1459
+ case "end":
1460
+ return _context17.stop();
1721
1461
  }
1722
1462
  }, _callee17, this);
1723
1463
  }));
1724
-
1725
1464
  return function (_x17) {
1726
1465
  return _ref32.apply(this, arguments);
1727
1466
  };
1728
1467
  }();
1729
-
1730
1468
  exports.AwaitPending = /*#__PURE__*/function () {
1731
1469
  var _ref33 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee19(objectId) {
1732
1470
  var _this3 = this;
1733
-
1734
1471
  var PendingHash, pending, isWallet, timeout, i;
1735
1472
  return _regeneratorRuntime.wrap(function _callee19$(_context19) {
1736
- while (1) {
1737
- switch (_context19.prev = _context19.next) {
1738
- case 0:
1739
- PendingHash = /*#__PURE__*/function () {
1740
- var _ref34 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee18() {
1741
- return _regeneratorRuntime.wrap(function _callee18$(_context18) {
1742
- while (1) {
1743
- switch (_context18.prev = _context18.next) {
1744
- case 0:
1745
- _context18.next = 2;
1746
- return _this3.CallContractMethod({
1747
- contractAddress: _this3.utils.HashToAddress(objectId),
1748
- methodName: "pendingHash"
1749
- });
1750
-
1751
- case 2:
1752
- return _context18.abrupt("return", _context18.sent);
1753
-
1754
- case 3:
1755
- case "end":
1756
- return _context18.stop();
1757
- }
1758
- }
1759
- }, _callee18);
1760
- }));
1761
-
1762
- return function PendingHash() {
1763
- return _ref34.apply(this, arguments);
1764
- };
1765
- }();
1766
-
1767
- this.Log("Checking for pending commit");
1768
- _context19.next = 4;
1769
- return PendingHash();
1770
-
1771
- case 4:
1772
- pending = _context19.sent;
1773
-
1774
- if (pending) {
1775
- _context19.next = 7;
1776
- break;
1777
- }
1778
-
1779
- return _context19.abrupt("return");
1780
-
1781
- case 7:
1782
- _context19.next = 9;
1783
- return this.authClient.AccessType(objectId);
1784
-
1785
- case 9:
1786
- _context19.t0 = _context19.sent;
1787
- _context19.t1 = this.authClient.ACCESS_TYPES.WALLET;
1788
- isWallet = _context19.t0 === _context19.t1;
1789
- timeout = isWallet ? 3 : 10;
1790
- this.Log("Waiting for pending commit to clear for ".concat(objectId));
1791
- i = 0;
1792
-
1793
- case 15:
1794
- if (!(i < timeout)) {
1795
- _context19.next = 25;
1796
- break;
1797
- }
1798
-
1799
- _context19.next = 18;
1800
- return new Promise(function (resolve) {
1801
- return setTimeout(resolve, 1000);
1802
- });
1803
-
1804
- case 18:
1805
- _context19.next = 20;
1806
- return PendingHash();
1807
-
1808
- case 20:
1809
- if (_context19.sent) {
1810
- _context19.next = 22;
1811
- break;
1812
- }
1813
-
1814
- return _context19.abrupt("return");
1815
-
1816
- case 22:
1817
- i++;
1818
- _context19.next = 15;
1473
+ while (1) switch (_context19.prev = _context19.next) {
1474
+ case 0:
1475
+ PendingHash = /*#__PURE__*/function () {
1476
+ var _ref34 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee18() {
1477
+ return _regeneratorRuntime.wrap(function _callee18$(_context18) {
1478
+ while (1) switch (_context18.prev = _context18.next) {
1479
+ case 0:
1480
+ _context18.next = 2;
1481
+ return _this3.CallContractMethod({
1482
+ contractAddress: _this3.utils.HashToAddress(objectId),
1483
+ methodName: "pendingHash"
1484
+ });
1485
+ case 2:
1486
+ return _context18.abrupt("return", _context18.sent);
1487
+ case 3:
1488
+ case "end":
1489
+ return _context18.stop();
1490
+ }
1491
+ }, _callee18);
1492
+ }));
1493
+ return function PendingHash() {
1494
+ return _ref34.apply(this, arguments);
1495
+ };
1496
+ }();
1497
+ this.Log("Checking for pending commit");
1498
+ _context19.next = 4;
1499
+ return PendingHash();
1500
+ case 4:
1501
+ pending = _context19.sent;
1502
+ if (pending) {
1503
+ _context19.next = 7;
1819
1504
  break;
1820
-
1821
- case 25:
1822
- if (!isWallet) {
1823
- _context19.next = 31;
1824
- break;
1825
- }
1826
-
1827
- this.Log("Clearing stuck wallet commit", true); // Clear pending commit, it's probably stuck
1828
-
1829
- _context19.next = 29;
1830
- return this.CallContractMethodAndWait({
1831
- contractAddress: this.utils.HashToAddress(objectId),
1832
- methodName: "clearPending"
1833
- });
1834
-
1835
- case 29:
1836
- _context19.next = 32;
1505
+ }
1506
+ return _context19.abrupt("return");
1507
+ case 7:
1508
+ _context19.next = 9;
1509
+ return this.authClient.AccessType(objectId);
1510
+ case 9:
1511
+ _context19.t0 = _context19.sent;
1512
+ _context19.t1 = this.authClient.ACCESS_TYPES.WALLET;
1513
+ isWallet = _context19.t0 === _context19.t1;
1514
+ timeout = isWallet ? 3 : 10;
1515
+ this.Log("Waiting for pending commit to clear for ".concat(objectId));
1516
+ i = 0;
1517
+ case 15:
1518
+ if (!(i < timeout)) {
1519
+ _context19.next = 25;
1837
1520
  break;
1838
-
1839
- case 31:
1840
- throw Error("Unable to finalize ".concat(objectId, " - Another commit is pending"));
1841
-
1842
- case 32:
1843
- case "end":
1844
- return _context19.stop();
1845
- }
1521
+ }
1522
+ _context19.next = 18;
1523
+ return new Promise(function (resolve) {
1524
+ return setTimeout(resolve, 1000);
1525
+ });
1526
+ case 18:
1527
+ _context19.next = 20;
1528
+ return PendingHash();
1529
+ case 20:
1530
+ if (_context19.sent) {
1531
+ _context19.next = 22;
1532
+ break;
1533
+ }
1534
+ return _context19.abrupt("return");
1535
+ case 22:
1536
+ i++;
1537
+ _context19.next = 15;
1538
+ break;
1539
+ case 25:
1540
+ if (!isWallet) {
1541
+ _context19.next = 31;
1542
+ break;
1543
+ }
1544
+ this.Log("Clearing stuck wallet commit", true);
1545
+ // Clear pending commit, it's probably stuck
1546
+ _context19.next = 29;
1547
+ return this.CallContractMethodAndWait({
1548
+ contractAddress: this.utils.HashToAddress(objectId),
1549
+ methodName: "clearPending"
1550
+ });
1551
+ case 29:
1552
+ _context19.next = 32;
1553
+ break;
1554
+ case 31:
1555
+ throw Error("Unable to finalize ".concat(objectId, " - Another commit is pending"));
1556
+ case 32:
1557
+ case "end":
1558
+ return _context19.stop();
1846
1559
  }
1847
1560
  }, _callee19, this);
1848
1561
  }));
1849
-
1850
1562
  return function (_x18) {
1851
1563
  return _ref33.apply(this, arguments);
1852
1564
  };
1853
1565
  }();
1566
+
1854
1567
  /**
1855
1568
  * Finalize content draft
1856
1569
  *
@@ -1864,124 +1577,107 @@ exports.AwaitPending = /*#__PURE__*/function () {
1864
1577
  * @param {boolean=} awaitCommitConfirmation=true - If specified, will wait for the publish commit to be confirmed.
1865
1578
  * Irrelevant if not publishing.
1866
1579
  */
1867
-
1868
-
1869
1580
  exports.FinalizeContentObject = /*#__PURE__*/function () {
1870
1581
  var _ref36 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee20(_ref35) {
1871
1582
  var libraryId, objectId, writeToken, _ref35$commitMessage, commitMessage, _ref35$publish, publish, _ref35$awaitCommitCon, awaitCommitConfirmation, path, finalizeResponse;
1872
-
1873
1583
  return _regeneratorRuntime.wrap(function _callee20$(_context20) {
1874
- while (1) {
1875
- switch (_context20.prev = _context20.next) {
1876
- case 0:
1877
- libraryId = _ref35.libraryId, objectId = _ref35.objectId, writeToken = _ref35.writeToken, _ref35$commitMessage = _ref35.commitMessage, commitMessage = _ref35$commitMessage === void 0 ? "" : _ref35$commitMessage, _ref35$publish = _ref35.publish, publish = _ref35$publish === void 0 ? true : _ref35$publish, _ref35$awaitCommitCon = _ref35.awaitCommitConfirmation, awaitCommitConfirmation = _ref35$awaitCommitCon === void 0 ? true : _ref35$awaitCommitCon;
1878
- ValidateParameters({
1879
- libraryId: libraryId,
1880
- objectId: objectId
1881
- });
1882
- ValidateWriteToken(writeToken);
1883
- _context20.t0 = this;
1884
- _context20.t1 = libraryId;
1885
- _context20.t2 = objectId;
1886
- _context20.t3 = writeToken;
1887
- _context20.t4 = commitMessage;
1888
- _context20.next = 10;
1889
- return this.userProfileClient.UserMetadata({
1890
- metadataSubtree: "public/name"
1891
- });
1892
-
1893
- case 10:
1894
- _context20.t5 = _context20.sent;
1895
-
1896
- if (_context20.t5) {
1897
- _context20.next = 13;
1898
- break;
1899
- }
1900
-
1901
- _context20.t5 = this.CurrentAccountAddress();
1902
-
1903
- case 13:
1904
- _context20.t6 = _context20.t5;
1905
- _context20.t7 = this.CurrentAccountAddress();
1906
- _context20.t8 = new Date().toISOString();
1907
- _context20.t9 = {
1908
- message: _context20.t4,
1909
- author: _context20.t6,
1910
- author_address: _context20.t7,
1911
- timestamp: _context20.t8
1912
- };
1913
- _context20.t10 = {
1914
- libraryId: _context20.t1,
1915
- objectId: _context20.t2,
1916
- writeToken: _context20.t3,
1917
- metadataSubtree: "commit",
1918
- metadata: _context20.t9
1919
- };
1920
- _context20.next = 20;
1921
- return _context20.t0.ReplaceMetadata.call(_context20.t0, _context20.t10);
1922
-
1923
- case 20:
1924
- this.Log("Finalizing content draft: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken));
1925
- _context20.next = 23;
1926
- return this.AwaitPending(objectId);
1927
-
1928
- case 23:
1929
- path = UrlJoin("q", writeToken);
1930
- _context20.t11 = this.utils;
1931
- _context20.t12 = this.HttpClient;
1932
- _context20.next = 28;
1933
- return this.authClient.AuthorizationHeader({
1934
- libraryId: libraryId,
1935
- objectId: objectId,
1936
- update: true
1937
- });
1938
-
1939
- case 28:
1940
- _context20.t13 = _context20.sent;
1941
- _context20.t14 = path;
1942
- _context20.t15 = {
1943
- headers: _context20.t13,
1944
- method: "POST",
1945
- path: _context20.t14,
1946
- failover: false
1947
- };
1948
- _context20.t16 = _context20.t12.Request.call(_context20.t12, _context20.t15);
1949
- _context20.next = 34;
1950
- return _context20.t11.ResponseToJson.call(_context20.t11, _context20.t16);
1951
-
1952
- case 34:
1953
- finalizeResponse = _context20.sent;
1954
- this.Log("Finalized: ".concat(finalizeResponse.hash));
1955
-
1956
- if (!publish) {
1957
- _context20.next = 39;
1958
- break;
1959
- }
1960
-
1584
+ while (1) switch (_context20.prev = _context20.next) {
1585
+ case 0:
1586
+ libraryId = _ref35.libraryId, objectId = _ref35.objectId, writeToken = _ref35.writeToken, _ref35$commitMessage = _ref35.commitMessage, commitMessage = _ref35$commitMessage === void 0 ? "" : _ref35$commitMessage, _ref35$publish = _ref35.publish, publish = _ref35$publish === void 0 ? true : _ref35$publish, _ref35$awaitCommitCon = _ref35.awaitCommitConfirmation, awaitCommitConfirmation = _ref35$awaitCommitCon === void 0 ? true : _ref35$awaitCommitCon;
1587
+ ValidateParameters({
1588
+ libraryId: libraryId,
1589
+ objectId: objectId
1590
+ });
1591
+ ValidateWriteToken(writeToken);
1592
+ _context20.t0 = this;
1593
+ _context20.t1 = libraryId;
1594
+ _context20.t2 = objectId;
1595
+ _context20.t3 = writeToken;
1596
+ _context20.t4 = commitMessage;
1597
+ _context20.next = 10;
1598
+ return this.userProfileClient.UserMetadata({
1599
+ metadataSubtree: "public/name"
1600
+ });
1601
+ case 10:
1602
+ _context20.t5 = _context20.sent;
1603
+ if (_context20.t5) {
1604
+ _context20.next = 13;
1605
+ break;
1606
+ }
1607
+ _context20.t5 = this.CurrentAccountAddress();
1608
+ case 13:
1609
+ _context20.t6 = _context20.t5;
1610
+ _context20.t7 = this.CurrentAccountAddress();
1611
+ _context20.t8 = new Date().toISOString();
1612
+ _context20.t9 = {
1613
+ message: _context20.t4,
1614
+ author: _context20.t6,
1615
+ author_address: _context20.t7,
1616
+ timestamp: _context20.t8
1617
+ };
1618
+ _context20.t10 = {
1619
+ libraryId: _context20.t1,
1620
+ objectId: _context20.t2,
1621
+ writeToken: _context20.t3,
1622
+ metadataSubtree: "commit",
1623
+ metadata: _context20.t9
1624
+ };
1625
+ _context20.next = 20;
1626
+ return _context20.t0.ReplaceMetadata.call(_context20.t0, _context20.t10);
1627
+ case 20:
1628
+ this.Log("Finalizing content draft: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken));
1629
+ _context20.next = 23;
1630
+ return this.AwaitPending(objectId);
1631
+ case 23:
1632
+ path = UrlJoin("q", writeToken);
1633
+ _context20.t11 = this.utils;
1634
+ _context20.t12 = this.HttpClient;
1635
+ _context20.next = 28;
1636
+ return this.authClient.AuthorizationHeader({
1637
+ libraryId: libraryId,
1638
+ objectId: objectId,
1639
+ update: true
1640
+ });
1641
+ case 28:
1642
+ _context20.t13 = _context20.sent;
1643
+ _context20.t14 = path;
1644
+ _context20.t15 = {
1645
+ headers: _context20.t13,
1646
+ method: "POST",
1647
+ path: _context20.t14,
1648
+ failover: false
1649
+ };
1650
+ _context20.t16 = _context20.t12.Request.call(_context20.t12, _context20.t15);
1651
+ _context20.next = 34;
1652
+ return _context20.t11.ResponseToJson.call(_context20.t11, _context20.t16);
1653
+ case 34:
1654
+ finalizeResponse = _context20.sent;
1655
+ this.Log("Finalized: ".concat(finalizeResponse.hash));
1656
+ if (!publish) {
1961
1657
  _context20.next = 39;
1962
- return this.PublishContentVersion({
1963
- objectId: objectId,
1964
- versionHash: finalizeResponse.hash,
1965
- awaitCommitConfirmation: awaitCommitConfirmation
1966
- });
1967
-
1968
- case 39:
1969
- // Invalidate cached content type, if this is one.
1970
- delete this.contentTypes[objectId];
1971
- return _context20.abrupt("return", finalizeResponse);
1972
-
1973
- case 41:
1974
- case "end":
1975
- return _context20.stop();
1976
- }
1658
+ break;
1659
+ }
1660
+ _context20.next = 39;
1661
+ return this.PublishContentVersion({
1662
+ objectId: objectId,
1663
+ versionHash: finalizeResponse.hash,
1664
+ awaitCommitConfirmation: awaitCommitConfirmation
1665
+ });
1666
+ case 39:
1667
+ // Invalidate cached content type, if this is one.
1668
+ delete this.contentTypes[objectId];
1669
+ return _context20.abrupt("return", finalizeResponse);
1670
+ case 41:
1671
+ case "end":
1672
+ return _context20.stop();
1977
1673
  }
1978
1674
  }, _callee20, this);
1979
1675
  }));
1980
-
1981
1676
  return function (_x19) {
1982
1677
  return _ref36.apply(this, arguments);
1983
1678
  };
1984
1679
  }();
1680
+
1985
1681
  /**
1986
1682
  * Publish a previously finalized content object version
1987
1683
  *
@@ -1992,147 +1688,106 @@ exports.FinalizeContentObject = /*#__PURE__*/function () {
1992
1688
  * @param {string} versionHash - The version hash of the content object to publish
1993
1689
  * @param {boolean=} awaitCommitConfirmation=true - If specified, will wait for the publish commit to be confirmed.
1994
1690
  */
1995
-
1996
-
1997
1691
  exports.PublishContentVersion = /*#__PURE__*/function () {
1998
- var _ref38 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee22(_ref37) {
1999
- var _this4 = this;
2000
-
2001
- var objectId, versionHash, _ref37$awaitCommitCon, awaitCommitConfirmation, commit, abi, fromBlock, objectHash, pendingHash;
2002
-
2003
- return _regeneratorRuntime.wrap(function _callee22$(_context22) {
2004
- while (1) {
2005
- switch (_context22.prev = _context22.next) {
2006
- case 0:
2007
- objectId = _ref37.objectId, versionHash = _ref37.versionHash, _ref37$awaitCommitCon = _ref37.awaitCommitConfirmation, awaitCommitConfirmation = _ref37$awaitCommitCon === void 0 ? true : _ref37$awaitCommitCon;
2008
- versionHash ? ValidateVersion(versionHash) : ValidateObject(objectId);
2009
- this.Log("Publishing: ".concat(objectId || versionHash));
2010
-
2011
- if (versionHash) {
2012
- objectId = this.utils.DecodeVersionHash(versionHash).objectId;
2013
- }
2014
-
2015
- _context22.next = 6;
2016
- return this.ethClient.CommitContent({
2017
- contentObjectAddress: this.utils.HashToAddress(objectId),
2018
- versionHash: versionHash,
2019
- signer: this.signer
2020
- });
2021
-
2022
- case 6:
2023
- commit = _context22.sent;
2024
- _context22.next = 9;
2025
- return this.ContractAbi({
2026
- id: objectId
2027
- });
2028
-
2029
- case 9:
2030
- abi = _context22.sent;
2031
- fromBlock = commit.blockNumber + 1;
2032
- _context22.next = 13;
2033
- return this.ExtractValueFromEvent({
2034
- abi: abi,
2035
- event: commit,
2036
- eventName: "CommitPending",
2037
- eventValue: "objectHash"
2038
- });
2039
-
2040
- case 13:
2041
- objectHash = _context22.sent;
2042
- _context22.next = 16;
2043
- return this.CallContractMethod({
2044
- contractAddress: this.utils.HashToAddress(objectId),
2045
- methodName: "pendingHash"
2046
- });
2047
-
2048
- case 16:
2049
- pendingHash = _context22.sent;
2050
-
2051
- if (!(pendingHash && pendingHash !== objectHash)) {
2052
- _context22.next = 19;
2053
- break;
2054
- }
2055
-
2056
- throw Error("Pending version hash mismatch on ".concat(objectId, ": expected ").concat(objectHash, ", currently ").concat(pendingHash));
2057
-
2058
- case 19:
2059
- if (!awaitCommitConfirmation) {
2060
- _context22.next = 21;
2061
- break;
2062
- }
2063
-
2064
- return _context22.delegateYield( /*#__PURE__*/_regeneratorRuntime.mark(function _callee21() {
2065
- var pollingInterval, events, confirmEvent;
2066
- return _regeneratorRuntime.wrap(function _callee21$(_context21) {
2067
- while (1) {
2068
- switch (_context21.prev = _context21.next) {
2069
- case 0:
2070
- _this4.Log("Awaiting commit confirmation for ".concat(objectHash));
2071
-
2072
- pollingInterval = _this4.ethClient.Provider().pollingInterval || 500; // eslint-disable-next-line no-constant-condition
2073
-
2074
- case 2:
2075
- if (!true) {
2076
- _context21.next = 14;
2077
- break;
2078
- }
2079
-
2080
- _context21.next = 5;
2081
- return new Promise(function (resolve) {
2082
- return setTimeout(resolve, pollingInterval);
2083
- });
2084
-
2085
- case 5:
2086
- _context21.next = 7;
2087
- return _this4.ContractEvents({
2088
- contractAddress: _this4.utils.HashToAddress(objectId),
2089
- abi: abi,
2090
- fromBlock: fromBlock,
2091
- count: 1000
2092
- });
2093
-
2094
- case 7:
2095
- events = _context21.sent;
2096
- confirmEvent = events.find(function (blockEvents) {
2097
- return blockEvents.find(function (event) {
2098
- return objectHash === (event && event.args && event.args.objectHash);
2099
- });
2100
- });
2101
-
2102
- if (!confirmEvent) {
2103
- _context21.next = 12;
2104
- break;
2105
- }
2106
-
2107
- // Found confirmation
2108
- _this4.Log("Commit confirmed: ".concat(objectHash));
2109
-
2110
- return _context21.abrupt("break", 14);
2111
-
2112
- case 12:
2113
- _context21.next = 2;
2114
- break;
2115
-
2116
- case 14:
2117
- case "end":
2118
- return _context21.stop();
2119
- }
2120
- }
2121
- }, _callee21);
2122
- })(), "t0", 21);
2123
-
2124
- case 21:
2125
- case "end":
2126
- return _context22.stop();
2127
- }
1692
+ var _ref38 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee21(_ref37) {
1693
+ var objectId, versionHash, _ref37$awaitCommitCon, awaitCommitConfirmation, commit, abi, fromBlock, objectHash, pendingHash, pollingInterval, events, confirmEvent;
1694
+ return _regeneratorRuntime.wrap(function _callee21$(_context21) {
1695
+ while (1) switch (_context21.prev = _context21.next) {
1696
+ case 0:
1697
+ objectId = _ref37.objectId, versionHash = _ref37.versionHash, _ref37$awaitCommitCon = _ref37.awaitCommitConfirmation, awaitCommitConfirmation = _ref37$awaitCommitCon === void 0 ? true : _ref37$awaitCommitCon;
1698
+ versionHash ? ValidateVersion(versionHash) : ValidateObject(objectId);
1699
+ this.Log("Publishing: ".concat(objectId || versionHash));
1700
+ if (versionHash) {
1701
+ objectId = this.utils.DecodeVersionHash(versionHash).objectId;
1702
+ }
1703
+ _context21.next = 6;
1704
+ return this.ethClient.CommitContent({
1705
+ contentObjectAddress: this.utils.HashToAddress(objectId),
1706
+ versionHash: versionHash,
1707
+ signer: this.signer
1708
+ });
1709
+ case 6:
1710
+ commit = _context21.sent;
1711
+ _context21.next = 9;
1712
+ return this.ContractAbi({
1713
+ id: objectId
1714
+ });
1715
+ case 9:
1716
+ abi = _context21.sent;
1717
+ fromBlock = commit.blockNumber + 1;
1718
+ _context21.next = 13;
1719
+ return this.ExtractValueFromEvent({
1720
+ abi: abi,
1721
+ event: commit,
1722
+ eventName: "CommitPending",
1723
+ eventValue: "objectHash"
1724
+ });
1725
+ case 13:
1726
+ objectHash = _context21.sent;
1727
+ _context21.next = 16;
1728
+ return this.CallContractMethod({
1729
+ contractAddress: this.utils.HashToAddress(objectId),
1730
+ methodName: "pendingHash"
1731
+ });
1732
+ case 16:
1733
+ pendingHash = _context21.sent;
1734
+ if (!(pendingHash && pendingHash !== objectHash)) {
1735
+ _context21.next = 19;
1736
+ break;
1737
+ }
1738
+ throw Error("Pending version hash mismatch on ".concat(objectId, ": expected ").concat(objectHash, ", currently ").concat(pendingHash));
1739
+ case 19:
1740
+ if (!awaitCommitConfirmation) {
1741
+ _context21.next = 34;
1742
+ break;
1743
+ }
1744
+ this.Log("Awaiting commit confirmation for ".concat(objectHash));
1745
+ pollingInterval = this.ethClient.Provider().pollingInterval || 500; // eslint-disable-next-line no-constant-condition
1746
+ case 22:
1747
+ if (!true) {
1748
+ _context21.next = 34;
1749
+ break;
1750
+ }
1751
+ _context21.next = 25;
1752
+ return new Promise(function (resolve) {
1753
+ return setTimeout(resolve, pollingInterval);
1754
+ });
1755
+ case 25:
1756
+ _context21.next = 27;
1757
+ return this.ContractEvents({
1758
+ contractAddress: this.utils.HashToAddress(objectId),
1759
+ abi: abi,
1760
+ fromBlock: fromBlock,
1761
+ count: 1000
1762
+ });
1763
+ case 27:
1764
+ events = _context21.sent;
1765
+ confirmEvent = events.find(function (blockEvents) {
1766
+ return blockEvents.find(function (event) {
1767
+ return objectHash === (event && event.args && event.args.objectHash);
1768
+ });
1769
+ });
1770
+ if (!confirmEvent) {
1771
+ _context21.next = 32;
1772
+ break;
1773
+ }
1774
+ // Found confirmation
1775
+ this.Log("Commit confirmed: ".concat(objectHash));
1776
+ return _context21.abrupt("break", 34);
1777
+ case 32:
1778
+ _context21.next = 22;
1779
+ break;
1780
+ case 34:
1781
+ case "end":
1782
+ return _context21.stop();
2128
1783
  }
2129
- }, _callee22, this);
1784
+ }, _callee21, this);
2130
1785
  }));
2131
-
2132
1786
  return function (_x20) {
2133
1787
  return _ref38.apply(this, arguments);
2134
1788
  };
2135
1789
  }();
1790
+
2136
1791
  /**
2137
1792
  * Delete specified version of the content object
2138
1793
  *
@@ -2140,39 +1795,33 @@ exports.PublishContentVersion = /*#__PURE__*/function () {
2140
1795
  * @namedParams
2141
1796
  * @param {string=} versionHash - Hash of the object version - if not specified, most recent version will be deleted
2142
1797
  */
2143
-
2144
-
2145
1798
  exports.DeleteContentVersion = /*#__PURE__*/function () {
2146
- var _ref40 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee23(_ref39) {
1799
+ var _ref40 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee22(_ref39) {
2147
1800
  var versionHash, _this$utils$DecodeVer, objectId;
2148
-
2149
- return _regeneratorRuntime.wrap(function _callee23$(_context23) {
2150
- while (1) {
2151
- switch (_context23.prev = _context23.next) {
2152
- case 0:
2153
- versionHash = _ref39.versionHash;
2154
- ValidateVersion(versionHash);
2155
- this.Log("Deleting content version: ".concat(versionHash));
2156
- _this$utils$DecodeVer = this.utils.DecodeVersionHash(versionHash), objectId = _this$utils$DecodeVer.objectId;
2157
- _context23.next = 6;
2158
- return this.CallContractMethodAndWait({
2159
- contractAddress: this.utils.HashToAddress(objectId),
2160
- methodName: "deleteVersion",
2161
- methodArgs: [versionHash]
2162
- });
2163
-
2164
- case 6:
2165
- case "end":
2166
- return _context23.stop();
2167
- }
1801
+ return _regeneratorRuntime.wrap(function _callee22$(_context22) {
1802
+ while (1) switch (_context22.prev = _context22.next) {
1803
+ case 0:
1804
+ versionHash = _ref39.versionHash;
1805
+ ValidateVersion(versionHash);
1806
+ this.Log("Deleting content version: ".concat(versionHash));
1807
+ _this$utils$DecodeVer = this.utils.DecodeVersionHash(versionHash), objectId = _this$utils$DecodeVer.objectId;
1808
+ _context22.next = 6;
1809
+ return this.CallContractMethodAndWait({
1810
+ contractAddress: this.utils.HashToAddress(objectId),
1811
+ methodName: "deleteVersion",
1812
+ methodArgs: [versionHash]
1813
+ });
1814
+ case 6:
1815
+ case "end":
1816
+ return _context22.stop();
2168
1817
  }
2169
- }, _callee23, this);
1818
+ }, _callee22, this);
2170
1819
  }));
2171
-
2172
1820
  return function (_x21) {
2173
1821
  return _ref40.apply(this, arguments);
2174
1822
  };
2175
1823
  }();
1824
+
2176
1825
  /**
2177
1826
  * Delete specified content object
2178
1827
  *
@@ -2181,40 +1830,35 @@ exports.DeleteContentVersion = /*#__PURE__*/function () {
2181
1830
  * @param {string} libraryId - ID of the library
2182
1831
  * @param {string} objectId - ID of the object
2183
1832
  */
2184
-
2185
-
2186
1833
  exports.DeleteContentObject = /*#__PURE__*/function () {
2187
- var _ref42 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee24(_ref41) {
1834
+ var _ref42 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee23(_ref41) {
2188
1835
  var libraryId, objectId;
2189
- return _regeneratorRuntime.wrap(function _callee24$(_context24) {
2190
- while (1) {
2191
- switch (_context24.prev = _context24.next) {
2192
- case 0:
2193
- libraryId = _ref41.libraryId, objectId = _ref41.objectId;
2194
- ValidateParameters({
2195
- libraryId: libraryId,
2196
- objectId: objectId
2197
- });
2198
- this.Log("Deleting content version: ".concat(libraryId, " ").concat(objectId));
2199
- _context24.next = 5;
2200
- return this.CallContractMethodAndWait({
2201
- contractAddress: this.utils.HashToAddress(libraryId),
2202
- methodName: "deleteContent",
2203
- methodArgs: [this.utils.HashToAddress(objectId)]
2204
- });
2205
-
2206
- case 5:
2207
- case "end":
2208
- return _context24.stop();
2209
- }
1836
+ return _regeneratorRuntime.wrap(function _callee23$(_context23) {
1837
+ while (1) switch (_context23.prev = _context23.next) {
1838
+ case 0:
1839
+ libraryId = _ref41.libraryId, objectId = _ref41.objectId;
1840
+ ValidateParameters({
1841
+ libraryId: libraryId,
1842
+ objectId: objectId
1843
+ });
1844
+ this.Log("Deleting content version: ".concat(libraryId, " ").concat(objectId));
1845
+ _context23.next = 5;
1846
+ return this.CallContractMethodAndWait({
1847
+ contractAddress: this.utils.HashToAddress(libraryId),
1848
+ methodName: "deleteContent",
1849
+ methodArgs: [this.utils.HashToAddress(objectId)]
1850
+ });
1851
+ case 5:
1852
+ case "end":
1853
+ return _context23.stop();
2210
1854
  }
2211
- }, _callee24, this);
1855
+ }, _callee23, this);
2212
1856
  }));
2213
-
2214
1857
  return function (_x22) {
2215
1858
  return _ref42.apply(this, arguments);
2216
1859
  };
2217
1860
  }();
1861
+
2218
1862
  /* Content object metadata */
2219
1863
 
2220
1864
  /**
@@ -2228,59 +1872,52 @@ exports.DeleteContentObject = /*#__PURE__*/function () {
2228
1872
  * @param {Object} metadata - New metadata to merge
2229
1873
  * @param {string=} metadataSubtree - Subtree of the object metadata to modify
2230
1874
  */
2231
-
2232
-
2233
1875
  exports.MergeMetadata = /*#__PURE__*/function () {
2234
- var _ref44 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee25(_ref43) {
1876
+ var _ref44 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee24(_ref43) {
2235
1877
  var libraryId, objectId, writeToken, _ref43$metadataSubtre, metadataSubtree, _ref43$metadata, metadata, path;
2236
-
2237
- return _regeneratorRuntime.wrap(function _callee25$(_context25) {
2238
- while (1) {
2239
- switch (_context25.prev = _context25.next) {
2240
- case 0:
2241
- libraryId = _ref43.libraryId, objectId = _ref43.objectId, writeToken = _ref43.writeToken, _ref43$metadataSubtre = _ref43.metadataSubtree, metadataSubtree = _ref43$metadataSubtre === void 0 ? "/" : _ref43$metadataSubtre, _ref43$metadata = _ref43.metadata, metadata = _ref43$metadata === void 0 ? {} : _ref43$metadata;
2242
- ValidateParameters({
2243
- libraryId: libraryId,
2244
- objectId: objectId
2245
- });
2246
- ValidateWriteToken(writeToken);
2247
- this.Log("Merging metadata: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken, "\n Subtree: ").concat(metadataSubtree));
2248
- this.Log(metadata);
2249
- path = UrlJoin("q", writeToken, "meta", metadataSubtree);
2250
- _context25.t0 = this.HttpClient;
2251
- _context25.next = 9;
2252
- return this.authClient.AuthorizationHeader({
2253
- libraryId: libraryId,
2254
- objectId: objectId,
2255
- update: true
2256
- });
2257
-
2258
- case 9:
2259
- _context25.t1 = _context25.sent;
2260
- _context25.t2 = path;
2261
- _context25.t3 = metadata;
2262
- _context25.t4 = {
2263
- headers: _context25.t1,
2264
- method: "POST",
2265
- path: _context25.t2,
2266
- body: _context25.t3,
2267
- failover: false
2268
- };
2269
- _context25.next = 15;
2270
- return _context25.t0.Request.call(_context25.t0, _context25.t4);
2271
-
2272
- case 15:
2273
- case "end":
2274
- return _context25.stop();
2275
- }
1878
+ return _regeneratorRuntime.wrap(function _callee24$(_context24) {
1879
+ while (1) switch (_context24.prev = _context24.next) {
1880
+ case 0:
1881
+ libraryId = _ref43.libraryId, objectId = _ref43.objectId, writeToken = _ref43.writeToken, _ref43$metadataSubtre = _ref43.metadataSubtree, metadataSubtree = _ref43$metadataSubtre === void 0 ? "/" : _ref43$metadataSubtre, _ref43$metadata = _ref43.metadata, metadata = _ref43$metadata === void 0 ? {} : _ref43$metadata;
1882
+ ValidateParameters({
1883
+ libraryId: libraryId,
1884
+ objectId: objectId
1885
+ });
1886
+ ValidateWriteToken(writeToken);
1887
+ this.Log("Merging metadata: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken, "\n Subtree: ").concat(metadataSubtree));
1888
+ this.Log(metadata);
1889
+ path = UrlJoin("q", writeToken, "meta", metadataSubtree);
1890
+ _context24.t0 = this.HttpClient;
1891
+ _context24.next = 9;
1892
+ return this.authClient.AuthorizationHeader({
1893
+ libraryId: libraryId,
1894
+ objectId: objectId,
1895
+ update: true
1896
+ });
1897
+ case 9:
1898
+ _context24.t1 = _context24.sent;
1899
+ _context24.t2 = path;
1900
+ _context24.t3 = metadata;
1901
+ _context24.t4 = {
1902
+ headers: _context24.t1,
1903
+ method: "POST",
1904
+ path: _context24.t2,
1905
+ body: _context24.t3,
1906
+ failover: false
1907
+ };
1908
+ _context24.next = 15;
1909
+ return _context24.t0.Request.call(_context24.t0, _context24.t4);
1910
+ case 15:
1911
+ case "end":
1912
+ return _context24.stop();
2276
1913
  }
2277
- }, _callee25, this);
1914
+ }, _callee24, this);
2278
1915
  }));
2279
-
2280
1916
  return function (_x23) {
2281
1917
  return _ref44.apply(this, arguments);
2282
1918
  };
2283
1919
  }();
1920
+
2284
1921
  /**
2285
1922
  * Replace content object metadata with specified metadata
2286
1923
  *
@@ -2292,59 +1929,52 @@ exports.MergeMetadata = /*#__PURE__*/function () {
2292
1929
  * @param {Object} metadata - New metadata to merge
2293
1930
  * @param {string=} metadataSubtree - Subtree of the object metadata to modify
2294
1931
  */
2295
-
2296
-
2297
1932
  exports.ReplaceMetadata = /*#__PURE__*/function () {
2298
- var _ref46 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee26(_ref45) {
1933
+ var _ref46 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee25(_ref45) {
2299
1934
  var libraryId, objectId, writeToken, _ref45$metadataSubtre, metadataSubtree, _ref45$metadata, metadata, path;
2300
-
2301
- return _regeneratorRuntime.wrap(function _callee26$(_context26) {
2302
- while (1) {
2303
- switch (_context26.prev = _context26.next) {
2304
- case 0:
2305
- libraryId = _ref45.libraryId, objectId = _ref45.objectId, writeToken = _ref45.writeToken, _ref45$metadataSubtre = _ref45.metadataSubtree, metadataSubtree = _ref45$metadataSubtre === void 0 ? "/" : _ref45$metadataSubtre, _ref45$metadata = _ref45.metadata, metadata = _ref45$metadata === void 0 ? {} : _ref45$metadata;
2306
- ValidateParameters({
2307
- libraryId: libraryId,
2308
- objectId: objectId
2309
- });
2310
- ValidateWriteToken(writeToken);
2311
- this.Log("Replacing metadata: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken, "\n Subtree: ").concat(metadataSubtree));
2312
- this.Log(metadata);
2313
- path = UrlJoin("q", writeToken, "meta", metadataSubtree);
2314
- _context26.t0 = this.HttpClient;
2315
- _context26.next = 9;
2316
- return this.authClient.AuthorizationHeader({
2317
- libraryId: libraryId,
2318
- objectId: objectId,
2319
- update: true
2320
- });
2321
-
2322
- case 9:
2323
- _context26.t1 = _context26.sent;
2324
- _context26.t2 = path;
2325
- _context26.t3 = metadata;
2326
- _context26.t4 = {
2327
- headers: _context26.t1,
2328
- method: "PUT",
2329
- path: _context26.t2,
2330
- body: _context26.t3,
2331
- failover: false
2332
- };
2333
- _context26.next = 15;
2334
- return _context26.t0.Request.call(_context26.t0, _context26.t4);
2335
-
2336
- case 15:
2337
- case "end":
2338
- return _context26.stop();
2339
- }
1935
+ return _regeneratorRuntime.wrap(function _callee25$(_context25) {
1936
+ while (1) switch (_context25.prev = _context25.next) {
1937
+ case 0:
1938
+ libraryId = _ref45.libraryId, objectId = _ref45.objectId, writeToken = _ref45.writeToken, _ref45$metadataSubtre = _ref45.metadataSubtree, metadataSubtree = _ref45$metadataSubtre === void 0 ? "/" : _ref45$metadataSubtre, _ref45$metadata = _ref45.metadata, metadata = _ref45$metadata === void 0 ? {} : _ref45$metadata;
1939
+ ValidateParameters({
1940
+ libraryId: libraryId,
1941
+ objectId: objectId
1942
+ });
1943
+ ValidateWriteToken(writeToken);
1944
+ this.Log("Replacing metadata: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken, "\n Subtree: ").concat(metadataSubtree));
1945
+ this.Log(metadata);
1946
+ path = UrlJoin("q", writeToken, "meta", metadataSubtree);
1947
+ _context25.t0 = this.HttpClient;
1948
+ _context25.next = 9;
1949
+ return this.authClient.AuthorizationHeader({
1950
+ libraryId: libraryId,
1951
+ objectId: objectId,
1952
+ update: true
1953
+ });
1954
+ case 9:
1955
+ _context25.t1 = _context25.sent;
1956
+ _context25.t2 = path;
1957
+ _context25.t3 = metadata;
1958
+ _context25.t4 = {
1959
+ headers: _context25.t1,
1960
+ method: "PUT",
1961
+ path: _context25.t2,
1962
+ body: _context25.t3,
1963
+ failover: false
1964
+ };
1965
+ _context25.next = 15;
1966
+ return _context25.t0.Request.call(_context25.t0, _context25.t4);
1967
+ case 15:
1968
+ case "end":
1969
+ return _context25.stop();
2340
1970
  }
2341
- }, _callee26, this);
1971
+ }, _callee25, this);
2342
1972
  }));
2343
-
2344
1973
  return function (_x24) {
2345
1974
  return _ref46.apply(this, arguments);
2346
1975
  };
2347
1976
  }();
1977
+
2348
1978
  /**
2349
1979
  * Delete content object metadata of specified subtree
2350
1980
  *
@@ -2356,57 +1986,50 @@ exports.ReplaceMetadata = /*#__PURE__*/function () {
2356
1986
  * @param {string=} metadataSubtree - Subtree of the object metadata to modify
2357
1987
  * - if not specified, all metadata will be deleted
2358
1988
  */
2359
-
2360
-
2361
1989
  exports.DeleteMetadata = /*#__PURE__*/function () {
2362
- var _ref48 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee27(_ref47) {
1990
+ var _ref48 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee26(_ref47) {
2363
1991
  var libraryId, objectId, writeToken, _ref47$metadataSubtre, metadataSubtree, path;
2364
-
2365
- return _regeneratorRuntime.wrap(function _callee27$(_context27) {
2366
- while (1) {
2367
- switch (_context27.prev = _context27.next) {
2368
- case 0:
2369
- libraryId = _ref47.libraryId, objectId = _ref47.objectId, writeToken = _ref47.writeToken, _ref47$metadataSubtre = _ref47.metadataSubtree, metadataSubtree = _ref47$metadataSubtre === void 0 ? "/" : _ref47$metadataSubtre;
2370
- ValidateParameters({
2371
- libraryId: libraryId,
2372
- objectId: objectId
2373
- });
2374
- ValidateWriteToken(writeToken);
2375
- this.Log("Deleting metadata: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken, "\n Subtree: ").concat(metadataSubtree));
2376
- this.Log("Subtree: ".concat(metadataSubtree));
2377
- path = UrlJoin("q", writeToken, "meta", metadataSubtree);
2378
- _context27.t0 = this.HttpClient;
2379
- _context27.next = 9;
2380
- return this.authClient.AuthorizationHeader({
2381
- libraryId: libraryId,
2382
- objectId: objectId,
2383
- update: true
2384
- });
2385
-
2386
- case 9:
2387
- _context27.t1 = _context27.sent;
2388
- _context27.t2 = path;
2389
- _context27.t3 = {
2390
- headers: _context27.t1,
2391
- method: "DELETE",
2392
- path: _context27.t2,
2393
- failover: false
2394
- };
2395
- _context27.next = 14;
2396
- return _context27.t0.Request.call(_context27.t0, _context27.t3);
2397
-
2398
- case 14:
2399
- case "end":
2400
- return _context27.stop();
2401
- }
1992
+ return _regeneratorRuntime.wrap(function _callee26$(_context26) {
1993
+ while (1) switch (_context26.prev = _context26.next) {
1994
+ case 0:
1995
+ libraryId = _ref47.libraryId, objectId = _ref47.objectId, writeToken = _ref47.writeToken, _ref47$metadataSubtre = _ref47.metadataSubtree, metadataSubtree = _ref47$metadataSubtre === void 0 ? "/" : _ref47$metadataSubtre;
1996
+ ValidateParameters({
1997
+ libraryId: libraryId,
1998
+ objectId: objectId
1999
+ });
2000
+ ValidateWriteToken(writeToken);
2001
+ this.Log("Deleting metadata: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken, "\n Subtree: ").concat(metadataSubtree));
2002
+ this.Log("Subtree: ".concat(metadataSubtree));
2003
+ path = UrlJoin("q", writeToken, "meta", metadataSubtree);
2004
+ _context26.t0 = this.HttpClient;
2005
+ _context26.next = 9;
2006
+ return this.authClient.AuthorizationHeader({
2007
+ libraryId: libraryId,
2008
+ objectId: objectId,
2009
+ update: true
2010
+ });
2011
+ case 9:
2012
+ _context26.t1 = _context26.sent;
2013
+ _context26.t2 = path;
2014
+ _context26.t3 = {
2015
+ headers: _context26.t1,
2016
+ method: "DELETE",
2017
+ path: _context26.t2,
2018
+ failover: false
2019
+ };
2020
+ _context26.next = 14;
2021
+ return _context26.t0.Request.call(_context26.t0, _context26.t3);
2022
+ case 14:
2023
+ case "end":
2024
+ return _context26.stop();
2402
2025
  }
2403
- }, _callee27, this);
2026
+ }, _callee26, this);
2404
2027
  }));
2405
-
2406
2028
  return function (_x25) {
2407
2029
  return _ref48.apply(this, arguments);
2408
2030
  };
2409
2031
  }();
2032
+
2410
2033
  /**
2411
2034
  * Set the access charge for the specified object
2412
2035
  *
@@ -2415,37 +2038,32 @@ exports.DeleteMetadata = /*#__PURE__*/function () {
2415
2038
  * @param {string} objectId - ID of the object
2416
2039
  * @param {number | string} accessCharge - The new access charge, in ether
2417
2040
  */
2418
-
2419
-
2420
2041
  exports.SetAccessCharge = /*#__PURE__*/function () {
2421
- var _ref50 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee28(_ref49) {
2042
+ var _ref50 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee27(_ref49) {
2422
2043
  var objectId, accessCharge;
2423
- return _regeneratorRuntime.wrap(function _callee28$(_context28) {
2424
- while (1) {
2425
- switch (_context28.prev = _context28.next) {
2426
- case 0:
2427
- objectId = _ref49.objectId, accessCharge = _ref49.accessCharge;
2428
- ValidateObject(objectId);
2429
- this.Log("Setting access charge: ".concat(objectId, " ").concat(accessCharge));
2430
- _context28.next = 5;
2431
- return this.ethClient.CallContractMethodAndWait({
2432
- contractAddress: this.utils.HashToAddress(objectId),
2433
- methodName: "setAccessCharge",
2434
- methodArgs: [this.utils.EtherToWei(accessCharge).toString()]
2435
- });
2436
-
2437
- case 5:
2438
- case "end":
2439
- return _context28.stop();
2440
- }
2044
+ return _regeneratorRuntime.wrap(function _callee27$(_context27) {
2045
+ while (1) switch (_context27.prev = _context27.next) {
2046
+ case 0:
2047
+ objectId = _ref49.objectId, accessCharge = _ref49.accessCharge;
2048
+ ValidateObject(objectId);
2049
+ this.Log("Setting access charge: ".concat(objectId, " ").concat(accessCharge));
2050
+ _context27.next = 5;
2051
+ return this.ethClient.CallContractMethodAndWait({
2052
+ contractAddress: this.utils.HashToAddress(objectId),
2053
+ methodName: "setAccessCharge",
2054
+ methodArgs: [this.utils.EtherToWei(accessCharge).toString()]
2055
+ });
2056
+ case 5:
2057
+ case "end":
2058
+ return _context27.stop();
2441
2059
  }
2442
- }, _callee28, this);
2060
+ }, _callee27, this);
2443
2061
  }));
2444
-
2445
2062
  return function (_x26) {
2446
2063
  return _ref50.apply(this, arguments);
2447
2064
  };
2448
2065
  }();
2066
+
2449
2067
  /**
2450
2068
  * Recursively update all auto_update links in the specified object.
2451
2069
  *
@@ -2459,192 +2077,153 @@ exports.SetAccessCharge = /*#__PURE__*/function () {
2459
2077
  * current progress as well as information about the last update (action)
2460
2078
  * - Format: {completed: number, total: number, action: string}
2461
2079
  */
2462
-
2463
-
2464
2080
  exports.UpdateContentObjectGraph = /*#__PURE__*/function () {
2465
- var _ref52 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee30(_ref51) {
2466
- var _this5 = this;
2467
-
2081
+ var _ref52 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee29(_ref51) {
2082
+ var _this4 = this;
2468
2083
  var libraryId, objectId, versionHash, callback, total, completed, _loop, _ret;
2469
-
2470
- return _regeneratorRuntime.wrap(function _callee30$(_context31) {
2471
- while (1) {
2472
- switch (_context31.prev = _context31.next) {
2473
- case 0:
2474
- libraryId = _ref51.libraryId, objectId = _ref51.objectId, versionHash = _ref51.versionHash, callback = _ref51.callback;
2475
- ValidateParameters({
2476
- libraryId: libraryId,
2477
- objectId: objectId,
2478
- versionHash: versionHash
2479
- });
2480
- this.Log("Updating content object graph: ".concat(libraryId || "", " ").concat(objectId || versionHash));
2481
-
2482
- if (versionHash) {
2483
- objectId = this.utils.DecodeVersionHash(versionHash).objectId;
2484
- }
2485
-
2486
- completed = 0; // eslint-disable-next-line no-constant-condition
2487
-
2488
- _loop = /*#__PURE__*/_regeneratorRuntime.mark(function _loop() {
2489
- var graph, currentHash, links, details, name, currentLibraryId, currentObjectId, _yield$_this5$EditCon, write_token, _yield$_this5$Finaliz, hash;
2490
-
2491
- return _regeneratorRuntime.wrap(function _loop$(_context30) {
2492
- while (1) {
2493
- switch (_context30.prev = _context30.next) {
2494
- case 0:
2495
- _context30.next = 2;
2496
- return _this5.ContentObjectGraph({
2497
- libraryId: libraryId,
2498
- objectId: objectId,
2499
- versionHash: versionHash,
2500
- autoUpdate: true,
2501
- select: ["name", "public/name", "public/asset_metadata/display_title"]
2502
- });
2503
-
2504
- case 2:
2505
- graph = _context30.sent;
2506
-
2507
- if (!(Object.keys(graph.auto_updates).length === 0)) {
2508
- _context30.next = 6;
2509
- break;
2510
- }
2511
-
2512
- _this5.Log("No more updates required");
2513
-
2514
- return _context30.abrupt("return", {
2515
- v: void 0
2516
- });
2517
-
2518
- case 6:
2519
- if (!total) {
2520
- total = graph.auto_updates.order.length;
2521
- }
2522
-
2523
- currentHash = graph.auto_updates.order[0];
2524
- links = graph.auto_updates.links[currentHash];
2525
- details = graph.details[currentHash].meta || {};
2526
- name = details["public"] && details["public"].asset_metadata && details["public"].asset_metadata.display_title || details["public"] && details["public"].name || details.name || versionHash || objectId;
2527
- _context30.next = 13;
2528
- return _this5.ContentObjectLibraryId({
2529
- versionHash: currentHash
2530
- });
2531
-
2532
- case 13:
2533
- currentLibraryId = _context30.sent;
2534
- currentObjectId = _this5.utils.DecodeVersionHash(currentHash).objectId;
2535
-
2536
- if (callback) {
2537
- callback({
2538
- completed: completed,
2539
- total: total,
2540
- action: "Updating ".concat(name, " (").concat(currentObjectId, ")...")
2541
- });
2542
- }
2543
-
2544
- _this5.Log("Updating links for ".concat(name, " (").concat(currentObjectId, " / ").concat(currentHash, ")"));
2545
-
2546
- _context30.next = 19;
2547
- return _this5.EditContentObject({
2548
- libraryId: currentLibraryId,
2549
- objectId: currentObjectId
2550
- });
2551
-
2552
- case 19:
2553
- _yield$_this5$EditCon = _context30.sent;
2554
- write_token = _yield$_this5$EditCon.write_token;
2555
- _context30.next = 23;
2556
- return Promise.all(links.map( /*#__PURE__*/function () {
2557
- var _ref54 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee29(_ref53) {
2558
- var path, updated;
2559
- return _regeneratorRuntime.wrap(function _callee29$(_context29) {
2560
- while (1) {
2561
- switch (_context29.prev = _context29.next) {
2562
- case 0:
2563
- path = _ref53.path, updated = _ref53.updated;
2564
- _context29.next = 3;
2565
- return _this5.ReplaceMetadata({
2566
- libraryId: currentLibraryId,
2567
- objectId: currentObjectId,
2568
- writeToken: write_token,
2569
- metadataSubtree: path,
2570
- metadata: updated
2571
- });
2572
-
2573
- case 3:
2574
- case "end":
2575
- return _context29.stop();
2576
- }
2577
- }
2578
- }, _callee29);
2579
- }));
2580
-
2581
- return function (_x28) {
2582
- return _ref54.apply(this, arguments);
2583
- };
2584
- }()));
2585
-
2586
- case 23:
2587
- _context30.next = 25;
2588
- return _this5.FinalizeContentObject({
2589
- libraryId: currentLibraryId,
2590
- objectId: currentObjectId,
2591
- writeToken: write_token,
2592
- commitMessage: "Update links"
2593
- });
2594
-
2595
- case 25:
2596
- _yield$_this5$Finaliz = _context30.sent;
2597
- hash = _yield$_this5$Finaliz.hash;
2598
-
2599
- // If root object was specified by hash and updated, update hash
2600
- if (currentHash === versionHash) {
2601
- versionHash = hash;
2602
- }
2603
-
2604
- completed += 1;
2605
-
2606
- case 29:
2607
- case "end":
2608
- return _context30.stop();
2084
+ return _regeneratorRuntime.wrap(function _callee29$(_context30) {
2085
+ while (1) switch (_context30.prev = _context30.next) {
2086
+ case 0:
2087
+ libraryId = _ref51.libraryId, objectId = _ref51.objectId, versionHash = _ref51.versionHash, callback = _ref51.callback;
2088
+ ValidateParameters({
2089
+ libraryId: libraryId,
2090
+ objectId: objectId,
2091
+ versionHash: versionHash
2092
+ });
2093
+ this.Log("Updating content object graph: ".concat(libraryId || "", " ").concat(objectId || versionHash));
2094
+ if (versionHash) {
2095
+ objectId = this.utils.DecodeVersionHash(versionHash).objectId;
2096
+ }
2097
+ completed = 0; // eslint-disable-next-line no-constant-condition
2098
+ _loop = /*#__PURE__*/_regeneratorRuntime.mark(function _loop() {
2099
+ var graph, currentHash, links, details, name, currentLibraryId, currentObjectId, _yield$_this4$EditCon, write_token, _yield$_this4$Finaliz, hash;
2100
+ return _regeneratorRuntime.wrap(function _loop$(_context29) {
2101
+ while (1) switch (_context29.prev = _context29.next) {
2102
+ case 0:
2103
+ _context29.next = 2;
2104
+ return _this4.ContentObjectGraph({
2105
+ libraryId: libraryId,
2106
+ objectId: objectId,
2107
+ versionHash: versionHash,
2108
+ autoUpdate: true,
2109
+ select: ["name", "public/name", "public/asset_metadata/display_title"]
2110
+ });
2111
+ case 2:
2112
+ graph = _context29.sent;
2113
+ if (!(Object.keys(graph.auto_updates).length === 0)) {
2114
+ _context29.next = 6;
2115
+ break;
2609
2116
  }
2610
- }
2611
- }, _loop);
2612
- });
2613
-
2614
- case 6:
2615
- if (!1) {
2616
- _context31.next = 13;
2617
- break;
2618
- }
2619
-
2620
- return _context31.delegateYield(_loop(), "t0", 8);
2621
-
2622
- case 8:
2623
- _ret = _context31.t0;
2624
-
2625
- if (!(_typeof(_ret) === "object")) {
2626
- _context31.next = 11;
2627
- break;
2628
- }
2629
-
2630
- return _context31.abrupt("return", _ret.v);
2631
-
2632
- case 11:
2633
- _context31.next = 6;
2117
+ _this4.Log("No more updates required");
2118
+ return _context29.abrupt("return", {
2119
+ v: void 0
2120
+ });
2121
+ case 6:
2122
+ if (!total) {
2123
+ total = graph.auto_updates.order.length;
2124
+ }
2125
+ currentHash = graph.auto_updates.order[0];
2126
+ links = graph.auto_updates.links[currentHash];
2127
+ details = graph.details[currentHash].meta || {};
2128
+ name = details["public"] && details["public"].asset_metadata && details["public"].asset_metadata.display_title || details["public"] && details["public"].name || details.name || versionHash || objectId;
2129
+ _context29.next = 13;
2130
+ return _this4.ContentObjectLibraryId({
2131
+ versionHash: currentHash
2132
+ });
2133
+ case 13:
2134
+ currentLibraryId = _context29.sent;
2135
+ currentObjectId = _this4.utils.DecodeVersionHash(currentHash).objectId;
2136
+ if (callback) {
2137
+ callback({
2138
+ completed: completed,
2139
+ total: total,
2140
+ action: "Updating ".concat(name, " (").concat(currentObjectId, ")...")
2141
+ });
2142
+ }
2143
+ _this4.Log("Updating links for ".concat(name, " (").concat(currentObjectId, " / ").concat(currentHash, ")"));
2144
+ _context29.next = 19;
2145
+ return _this4.EditContentObject({
2146
+ libraryId: currentLibraryId,
2147
+ objectId: currentObjectId
2148
+ });
2149
+ case 19:
2150
+ _yield$_this4$EditCon = _context29.sent;
2151
+ write_token = _yield$_this4$EditCon.write_token;
2152
+ _context29.next = 23;
2153
+ return Promise.all(links.map( /*#__PURE__*/function () {
2154
+ var _ref54 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee28(_ref53) {
2155
+ var path, updated;
2156
+ return _regeneratorRuntime.wrap(function _callee28$(_context28) {
2157
+ while (1) switch (_context28.prev = _context28.next) {
2158
+ case 0:
2159
+ path = _ref53.path, updated = _ref53.updated;
2160
+ _context28.next = 3;
2161
+ return _this4.ReplaceMetadata({
2162
+ libraryId: currentLibraryId,
2163
+ objectId: currentObjectId,
2164
+ writeToken: write_token,
2165
+ metadataSubtree: path,
2166
+ metadata: updated
2167
+ });
2168
+ case 3:
2169
+ case "end":
2170
+ return _context28.stop();
2171
+ }
2172
+ }, _callee28);
2173
+ }));
2174
+ return function (_x28) {
2175
+ return _ref54.apply(this, arguments);
2176
+ };
2177
+ }()));
2178
+ case 23:
2179
+ _context29.next = 25;
2180
+ return _this4.FinalizeContentObject({
2181
+ libraryId: currentLibraryId,
2182
+ objectId: currentObjectId,
2183
+ writeToken: write_token,
2184
+ commitMessage: "Update links"
2185
+ });
2186
+ case 25:
2187
+ _yield$_this4$Finaliz = _context29.sent;
2188
+ hash = _yield$_this4$Finaliz.hash;
2189
+ // If root object was specified by hash and updated, update hash
2190
+ if (currentHash === versionHash) {
2191
+ versionHash = hash;
2192
+ }
2193
+ completed += 1;
2194
+ case 29:
2195
+ case "end":
2196
+ return _context29.stop();
2197
+ }
2198
+ }, _loop);
2199
+ });
2200
+ case 6:
2201
+ if (!1) {
2202
+ _context30.next = 13;
2634
2203
  break;
2635
-
2636
- case 13:
2637
- case "end":
2638
- return _context31.stop();
2639
- }
2204
+ }
2205
+ return _context30.delegateYield(_loop(), "t0", 8);
2206
+ case 8:
2207
+ _ret = _context30.t0;
2208
+ if (!(_typeof(_ret) === "object")) {
2209
+ _context30.next = 11;
2210
+ break;
2211
+ }
2212
+ return _context30.abrupt("return", _ret.v);
2213
+ case 11:
2214
+ _context30.next = 6;
2215
+ break;
2216
+ case 13:
2217
+ case "end":
2218
+ return _context30.stop();
2640
2219
  }
2641
- }, _callee30, this);
2220
+ }, _callee29, this);
2642
2221
  }));
2643
-
2644
2222
  return function (_x27) {
2645
2223
  return _ref52.apply(this, arguments);
2646
2224
  };
2647
2225
  }();
2226
+
2648
2227
  /**
2649
2228
  * Generate a signed link token.
2650
2229
  *
@@ -2657,91 +2236,78 @@ exports.UpdateContentObjectGraph = /*#__PURE__*/function () {
2657
2236
  *
2658
2237
  * @return {Promise<string>} - The state channel token
2659
2238
  */
2660
-
2661
-
2662
2239
  exports.GenerateSignedLinkToken = /*#__PURE__*/function () {
2663
- var _ref56 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee31(_ref55) {
2240
+ var _ref56 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee30(_ref55) {
2664
2241
  var containerId, versionHash, link, duration, canEdit, _this$utils$DecodeVer2, objectId, signerAddress, token, compressedToken, signature;
2665
-
2666
- return _regeneratorRuntime.wrap(function _callee31$(_context32) {
2667
- while (1) {
2668
- switch (_context32.prev = _context32.next) {
2669
- case 0:
2670
- containerId = _ref55.containerId, versionHash = _ref55.versionHash, link = _ref55.link, duration = _ref55.duration;
2671
- ValidateObject(containerId);
2672
- _context32.next = 4;
2673
- return this.CallContractMethod({
2674
- contractAddress: this.utils.HashToAddress(containerId),
2675
- methodName: "canEdit"
2676
- });
2677
-
2678
- case 4:
2679
- canEdit = _context32.sent;
2680
- _this$utils$DecodeVer2 = this.utils.DecodeVersionHash(versionHash), objectId = _this$utils$DecodeVer2.objectId;
2681
-
2682
- if (canEdit) {
2683
- _context32.next = 8;
2684
- break;
2242
+ return _regeneratorRuntime.wrap(function _callee30$(_context31) {
2243
+ while (1) switch (_context31.prev = _context31.next) {
2244
+ case 0:
2245
+ containerId = _ref55.containerId, versionHash = _ref55.versionHash, link = _ref55.link, duration = _ref55.duration;
2246
+ ValidateObject(containerId);
2247
+ _context31.next = 4;
2248
+ return this.CallContractMethod({
2249
+ contractAddress: this.utils.HashToAddress(containerId),
2250
+ methodName: "canEdit"
2251
+ });
2252
+ case 4:
2253
+ canEdit = _context31.sent;
2254
+ _this$utils$DecodeVer2 = this.utils.DecodeVersionHash(versionHash), objectId = _this$utils$DecodeVer2.objectId;
2255
+ if (canEdit) {
2256
+ _context31.next = 8;
2257
+ break;
2258
+ }
2259
+ throw Error("Current user does not have permission to edit content object ".concat(objectId));
2260
+ case 8:
2261
+ signerAddress = this.CurrentAccountAddress();
2262
+ _context31.t0 = this.utils.B64(signerAddress.replace("0x", ""), "hex");
2263
+ _context31.next = 12;
2264
+ return this.ContentSpaceId();
2265
+ case 12:
2266
+ _context31.t1 = _context31.sent;
2267
+ _context31.next = 15;
2268
+ return this.ContentObjectLibraryId({
2269
+ objectId: objectId
2270
+ });
2271
+ case 15:
2272
+ _context31.t2 = _context31.sent;
2273
+ _context31.t3 = objectId;
2274
+ _context31.t4 = "iusr".concat(this.utils.AddressToHash(signerAddress));
2275
+ _context31.t5 = Date.now();
2276
+ _context31.t6 = duration ? Date.now() + duration : "";
2277
+ _context31.t7 = {
2278
+ elv: {
2279
+ lnk: link,
2280
+ src: containerId
2685
2281
  }
2686
-
2687
- throw Error("Current user does not have permission to edit content object ".concat(objectId));
2688
-
2689
- case 8:
2690
- signerAddress = this.CurrentAccountAddress();
2691
- _context32.t0 = this.utils.B64(signerAddress.replace("0x", ""), "hex");
2692
- _context32.next = 12;
2693
- return this.ContentSpaceId();
2694
-
2695
- case 12:
2696
- _context32.t1 = _context32.sent;
2697
- _context32.next = 15;
2698
- return this.ContentObjectLibraryId({
2699
- objectId: objectId
2700
- });
2701
-
2702
- case 15:
2703
- _context32.t2 = _context32.sent;
2704
- _context32.t3 = objectId;
2705
- _context32.t4 = "iusr".concat(this.utils.AddressToHash(signerAddress));
2706
- _context32.t5 = Date.now();
2707
- _context32.t6 = duration ? Date.now() + duration : "";
2708
- _context32.t7 = {
2709
- elv: {
2710
- lnk: link,
2711
- src: containerId
2712
- }
2713
- };
2714
- token = {
2715
- adr: _context32.t0,
2716
- spc: _context32.t1,
2717
- lib: _context32.t2,
2718
- qid: _context32.t3,
2719
- sub: _context32.t4,
2720
- gra: "read",
2721
- iat: _context32.t5,
2722
- exp: _context32.t6,
2723
- ctx: _context32.t7
2724
- };
2725
- compressedToken = Pako.deflateRaw(Buffer.from(JSON.stringify(token), "utf-8"));
2726
- _context32.next = 25;
2727
- return this.authClient.Sign(Ethers.utils.keccak256(compressedToken));
2728
-
2729
- case 25:
2730
- signature = _context32.sent;
2731
- return _context32.abrupt("return", "aslsjc".concat(this.utils.B58(Buffer.concat([Buffer.from(signature.replace(/^0x/, ""), "hex"), Buffer.from(compressedToken)]))));
2732
-
2733
- case 27:
2734
- case "end":
2735
- return _context32.stop();
2736
- }
2282
+ };
2283
+ token = {
2284
+ adr: _context31.t0,
2285
+ spc: _context31.t1,
2286
+ lib: _context31.t2,
2287
+ qid: _context31.t3,
2288
+ sub: _context31.t4,
2289
+ gra: "read",
2290
+ iat: _context31.t5,
2291
+ exp: _context31.t6,
2292
+ ctx: _context31.t7
2293
+ };
2294
+ compressedToken = Pako.deflateRaw(Buffer.from(JSON.stringify(token), "utf-8"));
2295
+ _context31.next = 25;
2296
+ return this.authClient.Sign(Ethers.utils.keccak256(compressedToken));
2297
+ case 25:
2298
+ signature = _context31.sent;
2299
+ return _context31.abrupt("return", "aslsjc".concat(this.utils.B58(Buffer.concat([Buffer.from(signature.replace(/^0x/, ""), "hex"), Buffer.from(compressedToken)]))));
2300
+ case 27:
2301
+ case "end":
2302
+ return _context31.stop();
2737
2303
  }
2738
- }, _callee31, this);
2304
+ }, _callee30, this);
2739
2305
  }));
2740
-
2741
2306
  return function (_x29) {
2742
2307
  return _ref56.apply(this, arguments);
2743
2308
  };
2744
2309
  }();
2310
+
2745
2311
  /**
2746
2312
  * Create links to files, metadata and/or representations of this or or other
2747
2313
  * content objects.
@@ -2767,131 +2333,107 @@ exports.GenerateSignedLinkToken = /*#__PURE__*/function () {
2767
2333
  * @param {string} writeToken - Write token of the draft
2768
2334
  * @param {Array<Object>} links - Link specifications
2769
2335
  */
2770
-
2771
-
2772
2336
  exports.CreateLinks = /*#__PURE__*/function () {
2773
- var _ref58 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee33(_ref57) {
2774
- var _this6 = this;
2775
-
2337
+ var _ref58 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee32(_ref57) {
2338
+ var _this5 = this;
2776
2339
  var libraryId, objectId, writeToken, _ref57$links, links;
2777
-
2778
- return _regeneratorRuntime.wrap(function _callee33$(_context34) {
2779
- while (1) {
2780
- switch (_context34.prev = _context34.next) {
2781
- case 0:
2782
- libraryId = _ref57.libraryId, objectId = _ref57.objectId, writeToken = _ref57.writeToken, _ref57$links = _ref57.links, links = _ref57$links === void 0 ? [] : _ref57$links;
2783
- ValidateParameters({
2784
- libraryId: libraryId,
2785
- objectId: objectId
2786
- });
2787
- ValidateWriteToken(writeToken);
2788
- _context34.next = 5;
2789
- return this.utils.LimitedMap(10, links, /*#__PURE__*/function () {
2790
- var _ref59 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee32(info) {
2791
- var path, type, target, authTarget, link, linkMetadata;
2792
- return _regeneratorRuntime.wrap(function _callee32$(_context33) {
2793
- while (1) {
2794
- switch (_context33.prev = _context33.next) {
2795
- case 0:
2796
- path = info.path.replace(/^(\/|\.)+/, "");
2797
- type = (info.type || "file") === "file" ? "files" : info.type;
2798
-
2799
- if (type === "metadata") {
2800
- type = "meta";
2801
- }
2802
-
2803
- target = authTarget = info.target.replace(/^(\/|\.)+/, "");
2804
-
2805
- if (info.targetHash) {
2806
- target = "/qfab/".concat(info.targetHash, "/").concat(type, "/").concat(target);
2807
- } else {
2808
- target = "./".concat(type, "/").concat(target);
2809
- }
2810
-
2811
- link = {
2812
- "/": target
2813
- };
2814
-
2815
- if (info.autoUpdate) {
2816
- link["."] = {
2817
- auto_update: {
2818
- tag: "latest"
2819
- }
2820
- };
2821
- } // Sign link
2822
-
2823
-
2824
- if (!info.authContainer) {
2825
- _context33.next = 17;
2826
- break;
2827
- }
2828
-
2829
- _context33.next = 10;
2830
- return _this6.ContentObjectMetadata({
2831
- libraryId: libraryId,
2832
- objectId: objectId,
2833
- metadataSubtree: path
2834
- });
2835
-
2836
- case 10:
2837
- linkMetadata = _context33.sent;
2838
-
2839
- if (linkMetadata) {
2840
- link = linkMetadata;
2841
- }
2842
-
2843
- if (!link["."]) link["."] = {};
2844
-
2845
- if (linkMetadata["."]["authorization"]) {
2846
- _context33.next = 17;
2847
- break;
2340
+ return _regeneratorRuntime.wrap(function _callee32$(_context33) {
2341
+ while (1) switch (_context33.prev = _context33.next) {
2342
+ case 0:
2343
+ libraryId = _ref57.libraryId, objectId = _ref57.objectId, writeToken = _ref57.writeToken, _ref57$links = _ref57.links, links = _ref57$links === void 0 ? [] : _ref57$links;
2344
+ ValidateParameters({
2345
+ libraryId: libraryId,
2346
+ objectId: objectId
2347
+ });
2348
+ ValidateWriteToken(writeToken);
2349
+ _context33.next = 5;
2350
+ return this.utils.LimitedMap(10, links, /*#__PURE__*/function () {
2351
+ var _ref59 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee31(info) {
2352
+ var path, type, target, authTarget, link, linkMetadata;
2353
+ return _regeneratorRuntime.wrap(function _callee31$(_context32) {
2354
+ while (1) switch (_context32.prev = _context32.next) {
2355
+ case 0:
2356
+ path = info.path.replace(/^(\/|\.)+/, "");
2357
+ type = (info.type || "file") === "file" ? "files" : info.type;
2358
+ if (type === "metadata") {
2359
+ type = "meta";
2360
+ }
2361
+ target = authTarget = info.target.replace(/^(\/|\.)+/, "");
2362
+ if (info.targetHash) {
2363
+ target = "/qfab/".concat(info.targetHash, "/").concat(type, "/").concat(target);
2364
+ } else {
2365
+ target = "./".concat(type, "/").concat(target);
2366
+ }
2367
+ link = {
2368
+ "/": target
2369
+ };
2370
+ if (info.autoUpdate) {
2371
+ link["."] = {
2372
+ auto_update: {
2373
+ tag: "latest"
2848
2374
  }
2849
-
2850
- _context33.next = 16;
2851
- return _this6.GenerateSignedLinkToken({
2852
- containerId: info.authContainer,
2853
- versionHash: info.targetHash,
2854
- link: "./".concat(type, "/").concat(authTarget)
2855
- });
2856
-
2857
- case 16:
2858
- link["."]["authorization"] = _context33.sent;
2859
-
2860
- case 17:
2861
- _context33.next = 19;
2862
- return _this6.ReplaceMetadata({
2863
- libraryId: libraryId,
2864
- objectId: objectId,
2865
- writeToken: writeToken,
2866
- metadataSubtree: path,
2867
- metadata: link
2868
- });
2869
-
2870
- case 19:
2871
- case "end":
2872
- return _context33.stop();
2375
+ };
2873
2376
  }
2874
- }
2875
- }, _callee32);
2876
- }));
2877
2377
 
2878
- return function (_x31) {
2879
- return _ref59.apply(this, arguments);
2880
- };
2881
- }());
2882
-
2883
- case 5:
2884
- case "end":
2885
- return _context34.stop();
2886
- }
2378
+ // Sign link
2379
+ if (!info.authContainer) {
2380
+ _context32.next = 17;
2381
+ break;
2382
+ }
2383
+ _context32.next = 10;
2384
+ return _this5.ContentObjectMetadata({
2385
+ libraryId: libraryId,
2386
+ objectId: objectId,
2387
+ metadataSubtree: path
2388
+ });
2389
+ case 10:
2390
+ linkMetadata = _context32.sent;
2391
+ if (linkMetadata) {
2392
+ link = linkMetadata;
2393
+ }
2394
+ if (!link["."]) link["."] = {};
2395
+ if (linkMetadata["."]["authorization"]) {
2396
+ _context32.next = 17;
2397
+ break;
2398
+ }
2399
+ _context32.next = 16;
2400
+ return _this5.GenerateSignedLinkToken({
2401
+ containerId: info.authContainer,
2402
+ versionHash: info.targetHash,
2403
+ link: "./".concat(type, "/").concat(authTarget)
2404
+ });
2405
+ case 16:
2406
+ link["."]["authorization"] = _context32.sent;
2407
+ case 17:
2408
+ _context32.next = 19;
2409
+ return _this5.ReplaceMetadata({
2410
+ libraryId: libraryId,
2411
+ objectId: objectId,
2412
+ writeToken: writeToken,
2413
+ metadataSubtree: path,
2414
+ metadata: link
2415
+ });
2416
+ case 19:
2417
+ case "end":
2418
+ return _context32.stop();
2419
+ }
2420
+ }, _callee31);
2421
+ }));
2422
+ return function (_x31) {
2423
+ return _ref59.apply(this, arguments);
2424
+ };
2425
+ }());
2426
+ case 5:
2427
+ case "end":
2428
+ return _context33.stop();
2887
2429
  }
2888
- }, _callee33, this);
2430
+ }, _callee32, this);
2889
2431
  }));
2890
-
2891
2432
  return function (_x30) {
2892
2433
  return _ref58.apply(this, arguments);
2893
2434
  };
2894
2435
  }();
2436
+
2895
2437
  /**
2896
2438
  * Initialize or replace the signed auth policy for the specified object
2897
2439
  *
@@ -2906,64 +2448,56 @@ exports.CreateLinks = /*#__PURE__*/function () {
2906
2448
  * @param {string=} description - A description for the policy
2907
2449
  * @param {string=} id - The ID of the policy
2908
2450
  */
2909
-
2910
-
2911
2451
  exports.InitializeAuthPolicy = /*#__PURE__*/function () {
2912
- var _ref61 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee34(_ref60) {
2452
+ var _ref61 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee33(_ref60) {
2913
2453
  var libraryId, objectId, writeToken, _ref60$target, target, body, version, description, id, authPolicy, string;
2914
-
2915
- return _regeneratorRuntime.wrap(function _callee34$(_context35) {
2916
- while (1) {
2917
- switch (_context35.prev = _context35.next) {
2918
- case 0:
2919
- libraryId = _ref60.libraryId, objectId = _ref60.objectId, writeToken = _ref60.writeToken, _ref60$target = _ref60.target, target = _ref60$target === void 0 ? "auth_policy_spec" : _ref60$target, body = _ref60.body, version = _ref60.version, description = _ref60.description, id = _ref60.id;
2920
- authPolicy = {
2921
- type: "epl-ast",
2922
- version: version,
2923
- body: body,
2924
- data: {
2925
- "/": UrlJoin(".", "meta", target)
2926
- },
2927
- signer: "iusr".concat(this.utils.AddressToHash(this.signer.address)),
2928
- description: description || "",
2929
- id: id || ""
2930
- };
2931
- string = "".concat(authPolicy.type, "|").concat(authPolicy.version, "|").concat(authPolicy.body, "|").concat(authPolicy.data["/"]);
2932
- _context35.t0 = this.utils;
2933
- _context35.next = 6;
2934
- return this.authClient.Sign(Ethers.utils.keccak256(Ethers.utils.toUtf8Bytes(string)));
2935
-
2936
- case 6:
2937
- _context35.t1 = _context35.sent;
2938
- authPolicy.signature = _context35.t0.FormatSignature.call(_context35.t0, _context35.t1);
2939
- _context35.next = 10;
2940
- return this.ReplaceMetadata({
2941
- libraryId: libraryId,
2942
- objectId: objectId,
2943
- writeToken: writeToken,
2944
- metadataSubtree: "auth_policy",
2945
- metadata: authPolicy
2946
- });
2947
-
2948
- case 10:
2949
- _context35.next = 12;
2950
- return this.SetAuthPolicy({
2951
- objectId: objectId,
2952
- policyId: objectId
2953
- });
2954
-
2955
- case 12:
2956
- case "end":
2957
- return _context35.stop();
2958
- }
2454
+ return _regeneratorRuntime.wrap(function _callee33$(_context34) {
2455
+ while (1) switch (_context34.prev = _context34.next) {
2456
+ case 0:
2457
+ libraryId = _ref60.libraryId, objectId = _ref60.objectId, writeToken = _ref60.writeToken, _ref60$target = _ref60.target, target = _ref60$target === void 0 ? "auth_policy_spec" : _ref60$target, body = _ref60.body, version = _ref60.version, description = _ref60.description, id = _ref60.id;
2458
+ authPolicy = {
2459
+ type: "epl-ast",
2460
+ version: version,
2461
+ body: body,
2462
+ data: {
2463
+ "/": UrlJoin(".", "meta", target)
2464
+ },
2465
+ signer: "iusr".concat(this.utils.AddressToHash(this.signer.address)),
2466
+ description: description || "",
2467
+ id: id || ""
2468
+ };
2469
+ string = "".concat(authPolicy.type, "|").concat(authPolicy.version, "|").concat(authPolicy.body, "|").concat(authPolicy.data["/"]);
2470
+ _context34.t0 = this.utils;
2471
+ _context34.next = 6;
2472
+ return this.authClient.Sign(Ethers.utils.keccak256(Ethers.utils.toUtf8Bytes(string)));
2473
+ case 6:
2474
+ _context34.t1 = _context34.sent;
2475
+ authPolicy.signature = _context34.t0.FormatSignature.call(_context34.t0, _context34.t1);
2476
+ _context34.next = 10;
2477
+ return this.ReplaceMetadata({
2478
+ libraryId: libraryId,
2479
+ objectId: objectId,
2480
+ writeToken: writeToken,
2481
+ metadataSubtree: "auth_policy",
2482
+ metadata: authPolicy
2483
+ });
2484
+ case 10:
2485
+ _context34.next = 12;
2486
+ return this.SetAuthPolicy({
2487
+ objectId: objectId,
2488
+ policyId: objectId
2489
+ });
2490
+ case 12:
2491
+ case "end":
2492
+ return _context34.stop();
2959
2493
  }
2960
- }, _callee34, this);
2494
+ }, _callee33, this);
2961
2495
  }));
2962
-
2963
2496
  return function (_x32) {
2964
2497
  return _ref61.apply(this, arguments);
2965
2498
  };
2966
2499
  }();
2500
+
2967
2501
  /**
2968
2502
  * Set the authorization policy for the specified object
2969
2503
  *
@@ -2972,33 +2506,27 @@ exports.InitializeAuthPolicy = /*#__PURE__*/function () {
2972
2506
  * @param {string} objectId - The ID of the object
2973
2507
  * @param {string} policyId - The ID of the policy
2974
2508
  */
2975
-
2976
-
2977
2509
  exports.SetAuthPolicy = /*#__PURE__*/function () {
2978
- var _ref63 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee35(_ref62) {
2510
+ var _ref63 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee34(_ref62) {
2979
2511
  var objectId, policyId;
2980
- return _regeneratorRuntime.wrap(function _callee35$(_context36) {
2981
- while (1) {
2982
- switch (_context36.prev = _context36.next) {
2983
- case 0:
2984
- objectId = _ref62.objectId, policyId = _ref62.policyId;
2985
- _context36.next = 3;
2986
- return this.MergeContractMetadata({
2987
- contractAddress: this.utils.HashToAddress(objectId),
2988
- metadataKey: "_AUTH_CONTEXT",
2989
- metadata: {
2990
- "elv:delegation-id": policyId
2991
- }
2992
- });
2993
-
2994
- case 3:
2995
- case "end":
2996
- return _context36.stop();
2997
- }
2512
+ return _regeneratorRuntime.wrap(function _callee34$(_context35) {
2513
+ while (1) switch (_context35.prev = _context35.next) {
2514
+ case 0:
2515
+ objectId = _ref62.objectId, policyId = _ref62.policyId;
2516
+ _context35.next = 3;
2517
+ return this.MergeContractMetadata({
2518
+ contractAddress: this.utils.HashToAddress(objectId),
2519
+ metadataKey: "_AUTH_CONTEXT",
2520
+ metadata: {
2521
+ "elv:delegation-id": policyId
2522
+ }
2523
+ });
2524
+ case 3:
2525
+ case "end":
2526
+ return _context35.stop();
2998
2527
  }
2999
- }, _callee35, this);
2528
+ }, _callee34, this);
3000
2529
  }));
3001
-
3002
2530
  return function (_x33) {
3003
2531
  return _ref63.apply(this, arguments);
3004
2532
  };