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