@eluvio/elv-client-js 4.0.111 → 4.0.113

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