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