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