@eluvio/elv-client-js 4.0.147 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/ElvClient-min.js +2 -67
  2. package/dist/ElvClient-min.js.LICENSE.txt +72 -0
  3. package/dist/ElvClient-node-min.js +2 -66
  4. package/dist/ElvClient-node-min.js.LICENSE.txt +72 -0
  5. package/dist/ElvFrameClient-min.js +2 -60
  6. package/dist/ElvFrameClient-min.js.LICENSE.txt +72 -0
  7. package/dist/ElvPermissionsClient-min.js +2 -60
  8. package/dist/ElvPermissionsClient-min.js.LICENSE.txt +72 -0
  9. package/dist/ElvWalletClient-min.js +2 -67
  10. package/dist/ElvWalletClient-min.js.LICENSE.txt +72 -0
  11. package/dist/ElvWalletClient-node-min.js +2 -66
  12. package/dist/ElvWalletClient-node-min.js.LICENSE.txt +72 -0
  13. package/dist/src/AuthorizationClient.js +713 -715
  14. package/dist/src/ContentObjectAudit.js +59 -59
  15. package/dist/src/Crypto.js +85 -86
  16. package/dist/src/ElvClient.js +532 -501
  17. package/dist/src/ElvWallet.js +30 -28
  18. package/dist/src/EthClient.js +316 -316
  19. package/dist/src/FrameClient.js +70 -71
  20. package/dist/src/HttpClient.js +60 -60
  21. package/dist/src/Id.js +1 -2
  22. package/dist/src/PermissionsClient.js +501 -489
  23. package/dist/src/RemoteSigner.js +83 -84
  24. package/dist/src/UserProfileClient.js +392 -374
  25. package/dist/src/Utils.js +67 -67
  26. package/dist/src/Validation.js +20 -12
  27. package/dist/src/client/ABRPublishing.js +412 -356
  28. package/dist/src/client/AccessGroups.js +479 -476
  29. package/dist/src/client/ContentAccess.js +1750 -1804
  30. package/dist/src/client/ContentManagement.js +874 -874
  31. package/dist/src/client/Contracts.js +586 -590
  32. package/dist/src/client/Files.js +702 -686
  33. package/dist/src/client/LiveConf.js +3 -5
  34. package/dist/src/client/LiveStream.js +659 -652
  35. package/dist/src/client/NFT.js +16 -16
  36. package/dist/src/client/NTP.js +84 -84
  37. package/dist/src/client/Shares.js +51 -51
  38. package/dist/src/walletClient/ClientMethods.js +979 -953
  39. package/dist/src/walletClient/Notifications.js +14 -14
  40. package/dist/src/walletClient/Profile.js +68 -68
  41. package/dist/src/walletClient/Utils.js +17 -17
  42. package/dist/src/walletClient/index.js +574 -564
  43. package/package.json +17 -16
  44. package/src/client/AccessGroups.js +1 -1
  45. package/testScripts/Test.js +5 -1
  46. package/webpack.config.js +10 -13
  47. package/dist/src/ContentObjectVerification.js +0 -281
@@ -2,8 +2,8 @@ var _toConsumableArray = require("@babel/runtime/helpers/toConsumableArray");
2
2
  var _regeneratorRuntime = require("@babel/runtime/regenerator");
3
3
  var _defineProperty = require("@babel/runtime/helpers/defineProperty");
4
4
  var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
5
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
6
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
5
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
6
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
7
7
  /**
8
8
  * Methods for ABR video creation and management
9
9
  *
@@ -18,7 +18,8 @@ var _require = require("../Validation"),
18
18
  ValidateLibrary = _require.ValidateLibrary,
19
19
  ValidateVersion = _require.ValidateVersion,
20
20
  ValidateParameters = _require.ValidateParameters,
21
- ValidateWriteToken = _require.ValidateWriteToken;
21
+ ValidateWriteToken = _require.ValidateWriteToken,
22
+ ValidateObject = _require.ValidateObject;
22
23
 
23
24
  // When `/abr_mezzanine/offerings` contains more than one entry, only 1 is the 'real' offering, the others are
24
25
  // additional copies to be modified upon finalization due to addlOfferingSpecs having been specified in call to
@@ -89,88 +90,89 @@ var MezJobMainOfferingKey = function MezJobMainOfferingKey(abrMezOfferings) {
89
90
  * @return {Object} - The finalize response for the object, as well as logs, warnings and errors from the master initialization
90
91
  */
91
92
  exports.CreateProductionMaster = /*#__PURE__*/function () {
92
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
93
- var libraryId, type, writeToken, name, description, _ref$metadata, metadata, fileInfo, _ref$encrypt, encrypt, _ref$access, access, _ref$copy, copy, callback, _ref$respLogLevel, respLogLevel, _ref$structLogLevel, structLogLevel, id, finalize, _yield$this$CreateCon, s3prefixRegex, i, oneFileInfo, matched, j, credentialSet, credentialSetBucket, matchers, k, matcher, fileSourcePath, s3prefixMatch, bucketName, _i, _credentialSet, region, bucket, accessKey, secret, _yield$this$CallBitco, logs, errors, warnings, finalizeResponse;
94
- return _regeneratorRuntime.wrap(function _callee$(_context) {
93
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
94
+ var libraryId, type, writeToken, name, description, _ref$metadata, metadata, fileInfo, _ref$encrypt, encrypt, _ref$access, access, _ref$copy, copy, callback, _ref$respLogLevel, respLogLevel, _ref$structLogLevel, structLogLevel, objectId, finalize, _yield$this$CreateCon, s3prefixRegex, i, oneFileInfo, matched, j, credentialSet, credentialSetBucket, matchers, k, matcher, fileSourcePath, s3prefixMatch, bucketName, _i, _credentialSet, region, bucket, accessKey, secret, _yield$this$CallBitco, logs, errors, warnings, additionalReturnVals;
95
+ return _regeneratorRuntime.wrap(function (_context) {
95
96
  while (1) switch (_context.prev = _context.next) {
96
97
  case 0:
97
98
  libraryId = _ref.libraryId, type = _ref.type, writeToken = _ref.writeToken, name = _ref.name, description = _ref.description, _ref$metadata = _ref.metadata, metadata = _ref$metadata === void 0 ? {} : _ref$metadata, fileInfo = _ref.fileInfo, _ref$encrypt = _ref.encrypt, encrypt = _ref$encrypt === void 0 ? true : _ref$encrypt, _ref$access = _ref.access, access = _ref$access === void 0 ? [] : _ref$access, _ref$copy = _ref.copy, copy = _ref$copy === void 0 ? false : _ref$copy, callback = _ref.callback, _ref$respLogLevel = _ref.respLogLevel, respLogLevel = _ref$respLogLevel === void 0 ? "warn" : _ref$respLogLevel, _ref$structLogLevel = _ref.structLogLevel, structLogLevel = _ref$structLogLevel === void 0 ? "none" : _ref$structLogLevel;
98
99
  ValidateLibrary(libraryId);
99
100
  finalize = !writeToken;
100
101
  if (!writeToken) {
101
- _context.next = 7;
102
+ _context.next = 1;
102
103
  break;
103
104
  }
104
- id = this.utils.DecodeWriteToken(writeToken).objectId;
105
- _context.next = 12;
105
+ // if write token passed in, don't create a new object
106
+ objectId = this.utils.DecodeWriteToken(writeToken).objectId;
107
+ _context.next = 3;
106
108
  break;
107
- case 7:
108
- _context.next = 9;
109
+ case 1:
110
+ _context.next = 2;
109
111
  return this.CreateContentObject({
110
112
  libraryId: libraryId,
111
113
  options: type ? {
112
114
  type: type
113
115
  } : {}
114
116
  });
115
- case 9:
117
+ case 2:
116
118
  _yield$this$CreateCon = _context.sent;
117
- id = _yield$this$CreateCon.id;
119
+ objectId = _yield$this$CreateCon.objectId;
118
120
  writeToken = _yield$this$CreateCon.writeToken;
119
- case 12:
121
+ case 3:
120
122
  if (!fileInfo) {
121
- _context.next = 64;
123
+ _context.next = 17;
122
124
  break;
123
125
  }
124
126
  if (!(access.length > 0)) {
125
- _context.next = 62;
127
+ _context.next = 16;
126
128
  break;
127
129
  }
128
130
  // S3 Upload
129
131
  s3prefixRegex = /^s3:\/\/([^/]+)\//i; // for matching and extracting bucket name when full s3:// path is specified
130
132
  // batch the cloud storage files by matching credential set, check each file's source path against credential set path_matchers
131
133
  i = 0;
132
- case 16:
134
+ case 4:
133
135
  if (!(i < fileInfo.length)) {
134
- _context.next = 47;
136
+ _context.next = 12;
135
137
  break;
136
138
  }
137
139
  oneFileInfo = fileInfo[i];
138
140
  matched = false;
139
141
  j = 0;
140
- case 20:
142
+ case 5:
141
143
  if (!(!matched && j < access.length)) {
142
- _context.next = 42;
144
+ _context.next = 10;
143
145
  break;
144
146
  }
145
147
  credentialSet = access[j]; // strip trailing slash to get bucket name for credential set
146
148
  credentialSetBucket = credentialSet.remote_access.path.replace(/\/$/, "");
147
149
  matchers = credentialSet.path_matchers;
148
150
  k = 0;
149
- case 25:
151
+ case 6:
150
152
  if (!(!matched && k < matchers.length)) {
151
- _context.next = 39;
153
+ _context.next = 9;
152
154
  break;
153
155
  }
154
156
  matcher = new RegExp(matchers[k]);
155
157
  fileSourcePath = oneFileInfo.source;
156
158
  if (!matcher.test(fileSourcePath)) {
157
- _context.next = 36;
159
+ _context.next = 8;
158
160
  break;
159
161
  }
160
162
  matched = true;
161
163
  // if full s3 path supplied, check bucket name
162
164
  s3prefixMatch = s3prefixRegex.exec(fileSourcePath);
163
165
  if (!s3prefixMatch) {
164
- _context.next = 35;
166
+ _context.next = 7;
165
167
  break;
166
168
  }
167
169
  bucketName = s3prefixMatch[1];
168
170
  if (!(bucketName !== credentialSetBucket)) {
169
- _context.next = 35;
171
+ _context.next = 7;
170
172
  break;
171
173
  }
172
174
  throw Error("Full S3 file path \"" + fileSourcePath + "\" matched to credential set with different bucket name '" + credentialSetBucket + "'");
173
- case 35:
175
+ case 7:
174
176
  if (credentialSet.hasOwnProperty("matched")) {
175
177
  credentialSet.matched.push(oneFileInfo);
176
178
  } else {
@@ -178,44 +180,44 @@ exports.CreateProductionMaster = /*#__PURE__*/function () {
178
180
  // initialize new 'matched' property to 1-element array
179
181
  credentialSet.matched = [oneFileInfo];
180
182
  }
181
- case 36:
183
+ case 8:
182
184
  k++;
183
- _context.next = 25;
185
+ _context.next = 6;
184
186
  break;
185
- case 39:
187
+ case 9:
186
188
  j++;
187
- _context.next = 20;
189
+ _context.next = 5;
188
190
  break;
189
- case 42:
191
+ case 10:
190
192
  if (matched) {
191
- _context.next = 44;
193
+ _context.next = 11;
192
194
  break;
193
195
  }
194
196
  throw Error("no credential set found for file path: \"" + filePath + "\"");
195
- case 44:
197
+ case 11:
196
198
  i++;
197
- _context.next = 16;
199
+ _context.next = 4;
198
200
  break;
199
- case 47:
201
+ case 12:
200
202
  _i = 0;
201
- case 48:
203
+ case 13:
202
204
  if (!(_i < access.length)) {
203
- _context.next = 60;
205
+ _context.next = 15;
204
206
  break;
205
207
  }
206
208
  _credentialSet = access[_i];
207
209
  if (!(_credentialSet.hasOwnProperty("matched") && _credentialSet.matched.length > 0)) {
208
- _context.next = 57;
210
+ _context.next = 14;
209
211
  break;
210
212
  }
211
213
  region = _credentialSet.remote_access.storage_endpoint.region;
212
214
  bucket = _credentialSet.remote_access.path.replace(/\/$/, "");
213
215
  accessKey = _credentialSet.remote_access.cloud_credentials.access_key_id;
214
216
  secret = _credentialSet.remote_access.cloud_credentials.secret_access_key;
215
- _context.next = 57;
217
+ _context.next = 14;
216
218
  return this.UploadFilesFromS3({
217
219
  libraryId: libraryId,
218
- objectId: id,
220
+ objectId: objectId,
219
221
  writeToken: writeToken,
220
222
  fileInfo: _credentialSet.matched,
221
223
  region: region,
@@ -226,36 +228,36 @@ exports.CreateProductionMaster = /*#__PURE__*/function () {
226
228
  callback: callback,
227
229
  encryption: encrypt ? "cgck" : "none"
228
230
  });
229
- case 57:
231
+ case 14:
230
232
  _i++;
231
- _context.next = 48;
233
+ _context.next = 13;
232
234
  break;
233
- case 60:
234
- _context.next = 64;
235
+ case 15:
236
+ _context.next = 17;
235
237
  break;
236
- case 62:
237
- _context.next = 64;
238
+ case 16:
239
+ _context.next = 17;
238
240
  return this.UploadFiles({
239
241
  libraryId: libraryId,
240
- objectId: id,
242
+ objectId: objectId,
241
243
  writeToken: writeToken,
242
244
  fileInfo: fileInfo,
243
245
  callback: callback,
244
246
  encryption: encrypt ? "cgck" : "none"
245
247
  });
246
- case 64:
247
- _context.next = 66;
248
+ case 17:
249
+ _context.next = 18;
248
250
  return this.CreateEncryptionConk({
249
251
  libraryId: libraryId,
250
- objectId: id,
252
+ objectId: objectId,
251
253
  writeToken: writeToken,
252
254
  createKMSConk: true
253
255
  });
254
- case 66:
255
- _context.next = 68;
256
+ case 18:
257
+ _context.next = 19;
256
258
  return this.CallBitcodeMethod({
257
259
  libraryId: libraryId,
258
- objectId: id,
260
+ objectId: objectId,
259
261
  writeToken: writeToken,
260
262
  method: UrlJoin("media", "production_master", "init"),
261
263
  queryParams: {
@@ -267,15 +269,15 @@ exports.CreateProductionMaster = /*#__PURE__*/function () {
267
269
  },
268
270
  constant: false
269
271
  });
270
- case 68:
272
+ case 19:
271
273
  _yield$this$CallBitco = _context.sent;
272
274
  logs = _yield$this$CallBitco.logs;
273
275
  errors = _yield$this$CallBitco.errors;
274
276
  warnings = _yield$this$CallBitco.warnings;
275
- _context.next = 74;
277
+ _context.next = 20;
276
278
  return this.MergeMetadata({
277
279
  libraryId: libraryId,
278
- objectId: id,
280
+ objectId: objectId,
279
281
  writeToken: writeToken,
280
282
  metadata: _objectSpread(_objectSpread({}, metadata || {}), {}, {
281
283
  name: name,
@@ -288,37 +290,37 @@ exports.CreateProductionMaster = /*#__PURE__*/function () {
288
290
  elv_created_at: new Date().getTime()
289
291
  })
290
292
  });
291
- case 74:
293
+ case 20:
292
294
  if (!finalize) {
293
- _context.next = 80;
295
+ _context.next = 22;
294
296
  break;
295
297
  }
296
- _context.next = 77;
298
+ _context.next = 21;
297
299
  return this.FinalizeContentObject({
298
300
  libraryId: libraryId,
299
- objectId: id,
301
+ objectId: objectId,
300
302
  writeToken: writeToken,
301
303
  commitMessage: "Create master",
302
304
  awaitCommitConfirmation: false
303
305
  });
304
- case 77:
305
- finalizeResponse = _context.sent;
306
- _context.next = 81;
306
+ case 21:
307
+ additionalReturnVals = _context.sent;
308
+ _context.next = 23;
307
309
  break;
308
- case 80:
309
- finalizeResponse = {
310
+ case 22:
311
+ additionalReturnVals = {
310
312
  write_token: writeToken,
311
313
  type: type,
312
314
  qlib_id: libraryId,
313
- id: id
315
+ id: objectId
314
316
  };
315
- case 81:
317
+ case 23:
316
318
  return _context.abrupt("return", _objectSpread({
317
319
  errors: errors || [],
318
320
  logs: logs || [],
319
321
  warnings: warnings || []
320
- }, finalizeResponse));
321
- case 82:
322
+ }, additionalReturnVals));
323
+ case 24:
322
324
  case "end":
323
325
  return _context.stop();
324
326
  }
@@ -340,8 +342,8 @@ exports.CreateProductionMaster = /*#__PURE__*/function () {
340
342
  * @param {boolean=} keepOtherStreams=false - If objectId is specified, whether to preserve existing streams with keys other than the ones specified in production master
341
343
  * @param {string} libraryId - ID of the mezzanine library
342
344
  * @param {string} masterVersionHash - The version hash of the production master content object
343
- * @param {string=} masterWriteToken - The write token of the production master content object draft. If provided, the object will not be finalized
344
- * @param {string=} writeToken - The write token of the mezzanine object draft. If specified, the object will not be finalized
345
+ * @param {string=} masterWriteToken - The write token of the production master content object draft.
346
+ * @param {string=} writeToken - The write token of the mezzanine object draft. If specified, the object will not be finalized, and no extra version of the object will be created to hold "bread crumb" metadata entry /lro_draft
345
347
  * @param {Object=} metadata - Additional metadata for mezzanine content object
346
348
  * @param {string} name - Name for mezzanine content object
347
349
  * @param {string=} objectId - ID of existing object (if not specified, new object will be created)
@@ -355,138 +357,159 @@ exports.CreateProductionMaster = /*#__PURE__*/function () {
355
357
  * @return {Object} - The finalize response for the object, as well as logs, warnings and errors from the mezzanine initialization
356
358
  */
357
359
  exports.CreateABRMezzanine = /*#__PURE__*/function () {
358
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref3) {
359
- var libraryId, objectId, type, name, description, metadata, masterVersionHash, masterWriteToken, writeToken, abrProfile, addlOfferingSpecs, _ref3$variant, variant, _ref3$offeringKey, offeringKey, _ref3$keepOtherStream, keepOtherStreams, _ref3$respLogLevel, respLogLevel, _ref3$structLogLevel, structLogLevel, streamKeys, masterObjectId, existingMez, options, id, finalize, _yield$this$EditConte, createResponse, nameMetaPayload, masterName, authorizationTokens, headers, body, storeClear, _yield$this$CallBitco2, logs, errors, warnings, masterId, existingMetadata, finalizeResponse;
360
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
360
+ var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref3) {
361
+ var libraryId, objectId, type, name, description, metadata, masterVersionHash, masterWriteToken, writeToken, abrProfile, addlOfferingSpecs, _ref3$variant, variant, _ref3$offeringKey, offeringKey, _ref3$keepOtherStream, keepOtherStreams, _ref3$respLogLevel, respLogLevel, _ref3$structLogLevel, structLogLevel, streamKeys, masterObjectId, masterLibId, useExistingMez, options, finalize, _yield$this$EditConte, _yield$this$CreateCon2, masterMetaSource, masterName, authorizationTokens, headers, body, storeClear, _yield$this$CallBitco2, logs, errors, warnings, masterId, existingMetadata, additionalReturnVals, _t, _t2, _t3, _t4, _t5, _t6;
362
+ return _regeneratorRuntime.wrap(function (_context2) {
361
363
  while (1) switch (_context2.prev = _context2.next) {
362
364
  case 0:
363
365
  libraryId = _ref3.libraryId, objectId = _ref3.objectId, type = _ref3.type, name = _ref3.name, description = _ref3.description, metadata = _ref3.metadata, masterVersionHash = _ref3.masterVersionHash, masterWriteToken = _ref3.masterWriteToken, writeToken = _ref3.writeToken, abrProfile = _ref3.abrProfile, addlOfferingSpecs = _ref3.addlOfferingSpecs, _ref3$variant = _ref3.variant, variant = _ref3$variant === void 0 ? "default" : _ref3$variant, _ref3$offeringKey = _ref3.offeringKey, offeringKey = _ref3$offeringKey === void 0 ? "default" : _ref3$offeringKey, _ref3$keepOtherStream = _ref3.keepOtherStreams, keepOtherStreams = _ref3$keepOtherStream === void 0 ? false : _ref3$keepOtherStream, _ref3$respLogLevel = _ref3.respLogLevel, respLogLevel = _ref3$respLogLevel === void 0 ? "warn" : _ref3$respLogLevel, _ref3$structLogLevel = _ref3.structLogLevel, structLogLevel = _ref3$structLogLevel === void 0 ? "none" : _ref3$structLogLevel, streamKeys = _ref3.streamKeys;
364
- ValidateLibrary(libraryId);
365
- if (masterVersionHash) {
366
- ValidateVersion(masterVersionHash);
367
- } else if (masterWriteToken) {
368
- ValidateWriteToken(masterWriteToken);
369
- masterObjectId = this.utils.DecodeWriteToken(masterWriteToken).objectId;
366
+ if (!(!masterVersionHash && !masterWriteToken)) {
367
+ _context2.next = 1;
368
+ break;
370
369
  }
371
- if (writeToken) {
372
- ValidateWriteToken(writeToken);
373
- if (!objectId) {
374
- objectId = this.utils.DecodeWriteToken(writeToken).objectId;
375
- }
370
+ throw Error("Neither master version hash nor master write token specified. One must be provided");
371
+ case 1:
372
+ if (!(masterVersionHash && masterWriteToken)) {
373
+ _context2.next = 2;
374
+ break;
376
375
  }
377
- if (!(!masterVersionHash && !masterWriteToken)) {
378
- _context2.next = 6;
376
+ throw Error("Both master version hash and master write token specified. Only one can be provided");
377
+ case 2:
378
+ // double-check library id for mez
379
+ ValidateLibrary(libraryId);
380
+
381
+ // The following 2 vars are used only if masterWriteToken is passed in (to retrieve master name)
382
+ if (!masterVersionHash) {
383
+ _context2.next = 3;
379
384
  break;
380
385
  }
381
- throw Error("Master version hash and master write token not specified. One must be provided");
382
- case 6:
386
+ // NOTE: masterObjectId is left undefined if masterWriteToken not passed in
387
+ ValidateVersion(masterVersionHash);
388
+ _context2.next = 5;
389
+ break;
390
+ case 3:
391
+ if (!masterWriteToken) {
392
+ _context2.next = 5;
393
+ break;
394
+ }
395
+ // determine master object id if a master write token was passed in
396
+ ValidateWriteToken(masterWriteToken);
397
+ masterObjectId = this.utils.DecodeWriteToken(masterWriteToken).objectId;
398
+ _context2.next = 4;
399
+ return client.ContentObjectLibraryId({
400
+ masterObjectId: masterObjectId
401
+ });
402
+ case 4:
403
+ masterLibId = _context2.sent;
404
+ case 5:
405
+ // if pre-existing mez object id passed in, validate
406
+ if (objectId) ValidateObject(objectId);
407
+
408
+ // if mez write token supplied, validate it
409
+ if (writeToken) {
410
+ ValidateWriteToken(writeToken, objectId);
411
+
412
+ // if pre-existing mez object id not passed in, decode it from write token
413
+ objectId = objectId || this.utils.DecodeWriteToken(writeToken).objectId;
414
+ }
415
+ // After above, if objectId is undefined then no mez writeToken was passed in, no mez objectId was passed in,
416
+ // meaning we must create a new object
417
+ useExistingMez = !!objectId; // type coerce string or undefined to boolean: "" -> false, undefined -> false, all else -> true
383
418
  if (!(!objectId && keepOtherStreams)) {
384
- _context2.next = 8;
419
+ _context2.next = 6;
385
420
  break;
386
421
  }
387
422
  throw Error("Existing mezzanine object ID required in order to use 'keepOtherStreams'");
388
- case 8:
423
+ case 6:
389
424
  if (!(addlOfferingSpecs && !abrProfile)) {
390
- _context2.next = 10;
425
+ _context2.next = 7;
391
426
  break;
392
427
  }
393
428
  throw Error("abrProfile required when using addlOfferingSpecs");
394
- case 10:
395
- existingMez = !!objectId;
429
+ case 7:
396
430
  options = type ? {
397
431
  type: type
398
432
  } : {};
399
- finalize = !writeToken;
400
- if (!existingMez) {
401
- _context2.next = 25;
433
+ finalize = !writeToken; // are we ingesting to an existing mez (and did NOT supply a write token?)
434
+ if (!(useExistingMez && !writeToken)) {
435
+ _context2.next = 9;
402
436
  break;
403
437
  }
404
- if (!writeToken) {
405
- _context2.next = 18;
406
- break;
407
- }
408
- id = objectId;
409
- _context2.next = 23;
410
- break;
411
- case 18:
412
- _context2.next = 20;
438
+ _context2.next = 8;
413
439
  return this.EditContentObject({
414
440
  libraryId: libraryId,
415
441
  objectId: objectId,
416
442
  options: options
417
443
  });
418
- case 20:
444
+ case 8:
419
445
  _yield$this$EditConte = _context2.sent;
420
446
  writeToken = _yield$this$EditConte.writeToken;
421
- id = _yield$this$EditConte.id;
422
- case 23:
423
- _context2.next = 30;
424
- break;
425
- case 25:
426
- _context2.next = 27;
447
+ case 9:
448
+ if (useExistingMez) {
449
+ _context2.next = 11;
450
+ break;
451
+ }
452
+ _context2.next = 10;
427
453
  return this.CreateContentObject({
428
454
  libraryId: libraryId,
429
455
  options: options
430
456
  });
431
- case 27:
432
- createResponse = _context2.sent;
433
- id = createResponse.id;
434
- writeToken = createResponse.write_token;
435
- case 30:
436
- _context2.next = 32;
457
+ case 10:
458
+ _yield$this$CreateCon2 = _context2.sent;
459
+ objectId = _yield$this$CreateCon2.objectId;
460
+ writeToken = _yield$this$CreateCon2.writeToken;
461
+ case 11:
462
+ _context2.next = 12;
437
463
  return this.CreateEncryptionConk({
438
464
  libraryId: libraryId,
439
- objectId: id,
465
+ objectId: objectId,
440
466
  writeToken: writeToken,
441
467
  createKMSConk: true
442
468
  });
443
- case 32:
444
- if (masterWriteToken) {
445
- nameMetaPayload = {
446
- libraryId: libraryId,
447
- objectId: masterObjectId,
448
- writeToken: masterWriteToken
449
- };
450
- } else if (masterVersionHash) {
451
- nameMetaPayload = {
452
- versionHash: masterVersionHash
453
- };
454
- }
455
- _context2.next = 35;
456
- return this.ContentObjectMetadata(_objectSpread(_objectSpread({}, nameMetaPayload), {}, {
469
+ case 12:
470
+ // figure out where to read master metadata from
471
+ masterMetaSource = masterWriteToken ? {
472
+ libraryId: masterLibId,
473
+ objectId: masterObjectId,
474
+ writeToken: masterWriteToken
475
+ } : {
476
+ versionHash: masterVersionHash
477
+ };
478
+ _context2.next = 13;
479
+ return this.ContentObjectMetadata(_objectSpread(_objectSpread({}, masterMetaSource), {}, {
457
480
  metadataSubtree: "public/name"
458
481
  }));
459
- case 35:
482
+ case 13:
460
483
  masterName = _context2.sent;
461
484
  // Include authorization for library, master, and mezzanine
462
485
  authorizationTokens = [];
463
- _context2.t0 = authorizationTokens;
464
- _context2.next = 40;
486
+ _t = authorizationTokens;
487
+ _context2.next = 14;
465
488
  return this.authClient.AuthorizationToken({
466
489
  libraryId: libraryId,
467
- objectId: id,
490
+ objectId: objectId,
468
491
  update: true
469
492
  });
470
- case 40:
471
- _context2.t1 = _context2.sent;
472
- _context2.t0.push.call(_context2.t0, _context2.t1);
473
- _context2.t2 = authorizationTokens;
474
- _context2.next = 45;
493
+ case 14:
494
+ _t2 = _context2.sent;
495
+ _t.push.call(_t, _t2);
496
+ _t3 = authorizationTokens;
497
+ _context2.next = 15;
475
498
  return this.authClient.AuthorizationToken({
476
499
  libraryId: libraryId
477
500
  });
478
- case 45:
479
- _context2.t3 = _context2.sent;
480
- _context2.t2.push.call(_context2.t2, _context2.t3);
481
- _context2.t4 = authorizationTokens;
482
- _context2.next = 50;
501
+ case 15:
502
+ _t4 = _context2.sent;
503
+ _t3.push.call(_t3, _t4);
504
+ _t5 = authorizationTokens;
505
+ _context2.next = 16;
483
506
  return this.authClient.AuthorizationToken({
484
507
  versionHash: masterVersionHash,
485
508
  objectId: masterObjectId
486
509
  });
487
- case 50:
488
- _context2.t5 = _context2.sent;
489
- _context2.t4.push.call(_context2.t4, _context2.t5);
510
+ case 16:
511
+ _t6 = _context2.sent;
512
+ _t5.push.call(_t5, _t6);
490
513
  headers = {
491
514
  Authorization: authorizationTokens.map(function (token) {
492
515
  return "Bearer ".concat(token);
@@ -500,40 +523,39 @@ exports.CreateABRMezzanine = /*#__PURE__*/function () {
500
523
  stream_keys: streamKeys,
501
524
  variant_key: variant
502
525
  };
503
- storeClear = false;
504
526
  if (!abrProfile) {
505
- _context2.next = 60;
527
+ _context2.next = 17;
506
528
  break;
507
529
  }
508
530
  body.abr_profile = abrProfile;
509
531
  storeClear = abrProfile.store_clear;
510
- _context2.next = 63;
532
+ _context2.next = 19;
511
533
  break;
512
- case 60:
513
- _context2.next = 62;
534
+ case 17:
535
+ _context2.next = 18;
514
536
  return this.ContentObjectMetadata({
515
537
  libraryId: libraryId,
516
538
  objectId: this.utils.AddressToObjectId(this.utils.HashToAddress(libraryId)),
517
539
  metadataSubtree: "abr_profile/store_clear"
518
540
  });
519
- case 62:
541
+ case 18:
520
542
  storeClear = _context2.sent;
521
- case 63:
543
+ case 19:
522
544
  if (storeClear) {
523
- _context2.next = 66;
545
+ _context2.next = 20;
524
546
  break;
525
547
  }
526
- _context2.next = 66;
548
+ _context2.next = 20;
527
549
  return this.EncryptionConk({
528
550
  libraryId: libraryId,
529
- objectId: id,
551
+ objectId: objectId,
530
552
  writeToken: writeToken
531
553
  });
532
- case 66:
533
- _context2.next = 68;
554
+ case 20:
555
+ _context2.next = 21;
534
556
  return this.CallBitcodeMethod({
535
557
  libraryId: libraryId,
536
- objectId: id,
558
+ objectId: objectId,
537
559
  writeToken: writeToken,
538
560
  method: UrlJoin("media", "abr_mezzanine", "init"),
539
561
  queryParams: {
@@ -544,7 +566,7 @@ exports.CreateABRMezzanine = /*#__PURE__*/function () {
544
566
  body: body,
545
567
  constant: false
546
568
  });
547
- case 68:
569
+ case 21:
548
570
  _yield$this$CallBitco2 = _context2.sent;
549
571
  logs = _yield$this$CallBitco2.logs;
550
572
  errors = _yield$this$CallBitco2.errors;
@@ -575,70 +597,70 @@ exports.CreateABRMezzanine = /*#__PURE__*/function () {
575
597
  "/": "./rep/playout/".concat(offeringKey, "/options.json")
576
598
  })
577
599
  }, metadata["public"].asset_metadata);
578
- if (name || !existingMez) {
600
+ if (name || !useExistingMez) {
579
601
  metadata.name = name || "".concat(masterName, " Mezzanine");
580
602
  metadata["public"].name = name || "".concat(masterName, " Mezzanine");
581
603
  }
582
- if (description || !existingMez) {
604
+ if (description || !useExistingMez) {
583
605
  metadata.description = description || "";
584
606
  metadata["public"].description = description || "";
585
607
  }
586
608
 
587
609
  // retrieve existing metadata to merge with updated metadata
588
- _context2.next = 83;
610
+ _context2.next = 22;
589
611
  return this.ContentObjectMetadata({
590
612
  libraryId: libraryId,
591
- objectId: id,
613
+ objectId: objectId,
592
614
  writeToken: writeToken
593
615
  });
594
- case 83:
616
+ case 22:
595
617
  existingMetadata = _context2.sent;
596
618
  // newer metadata values replace existing metadata, unless both new and old values are objects,
597
619
  // in which case their keys are merged recursively
598
620
  metadata = R.mergeDeepRight(existingMetadata, metadata);
599
- if (!existingMez) {
621
+ if (!useExistingMez) {
600
622
  // set creation date
601
623
  metadata.elv_created_at = new Date().getTime();
602
624
  }
603
625
 
604
626
  // write metadata to mezzanine object
605
- _context2.next = 88;
627
+ _context2.next = 23;
606
628
  return this.ReplaceMetadata({
607
629
  libraryId: libraryId,
608
- objectId: id,
630
+ objectId: objectId,
609
631
  writeToken: writeToken,
610
632
  metadata: metadata
611
633
  });
612
- case 88:
634
+ case 23:
613
635
  if (!finalize) {
614
- _context2.next = 94;
636
+ _context2.next = 25;
615
637
  break;
616
638
  }
617
- _context2.next = 91;
639
+ _context2.next = 24;
618
640
  return this.FinalizeContentObject({
619
641
  libraryId: libraryId,
620
- objectId: id,
642
+ objectId: objectId,
621
643
  writeToken: writeToken,
622
644
  commitMessage: "Create ABR mezzanine"
623
645
  });
624
- case 91:
625
- finalizeResponse = _context2.sent;
626
- _context2.next = 95;
646
+ case 24:
647
+ additionalReturnVals = _context2.sent;
648
+ _context2.next = 26;
627
649
  break;
628
- case 94:
629
- finalizeResponse = {
650
+ case 25:
651
+ additionalReturnVals = {
630
652
  write_token: writeToken,
631
653
  type: type,
632
654
  qlib_id: libraryId,
633
- id: id
655
+ id: objectId
634
656
  };
635
- case 95:
657
+ case 26:
636
658
  return _context2.abrupt("return", _objectSpread({
637
659
  logs: logs || [],
638
660
  warnings: warnings || [],
639
661
  errors: errors || []
640
- }, finalizeResponse));
641
- case 96:
662
+ }, additionalReturnVals));
663
+ case 27:
642
664
  case "end":
643
665
  return _context2.stop();
644
666
  }
@@ -656,7 +678,7 @@ exports.CreateABRMezzanine = /*#__PURE__*/function () {
656
678
  * @namedParams
657
679
  * @param {string} libraryId - ID of the mezzanine library
658
680
  * @param {string} objectId - ID of the mezzanine object
659
- * @param {string=} writeToken - Write token of the mezzanine object draft. If provided, the object will not be finalized
681
+ * @param {string=} writeToken - Write token of the mezzanine object draft. If provided, no "bread crumb" metadata /lro_draft will be created, nor saved as an extra finalized version
660
682
  * @param {Array<Object>=} access - Array of S3 credentials, along with path matching regexes - Required if any files in the masters are S3 references (See CreateProductionMaster method)
661
683
  * - Format: {region, bucket, accessKey, secret}
662
684
  * @param {number[]} jobIndexes - Array of LRO job indexes to start. LROs are listed in a map under metadata key /abr_mezzanine/offerings/(offeringKey)/mez_prep_specs/, and job indexes start with 0, corresponding to map keys in alphabetical order
@@ -664,10 +686,10 @@ exports.CreateABRMezzanine = /*#__PURE__*/function () {
664
686
  * @return {Promise<Object>} - A write token for the mezzanine object, as well as any logs, warnings and errors from the job initialization
665
687
  */
666
688
  exports.StartABRMezzanineJobs = /*#__PURE__*/function () {
667
- var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref5) {
689
+ var _ref6 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref5) {
668
690
  var _this = this;
669
- var libraryId, objectId, writeToken, _ref5$access, access, _ref5$jobIndexes, jobIndexes, lastJobOfferingsInfo, offeringKey, prepSpecs, masterVersionHashes, authorizationTokens, headers, processingDraft, nodeUrl, lroInfo, finalizeResponse, statusDraft, _yield$this$CallBitco3, data, errors, warnings, logs;
670
- return _regeneratorRuntime.wrap(function _callee4$(_context4) {
691
+ var libraryId, objectId, writeToken, _ref5$access, access, _ref5$jobIndexes, jobIndexes, writeTokenSupplied, lastJobOfferingsInfo, offeringKey, prepSpecs, masterVersionHashes, authorizationTokens, headers, breadCrumb, breadCrumbHash, lroWorkingDraft, breadCrumbDraft, finalizeResponse, nodeUrl, _yield$this$CallBitco3, data, errors, warnings, logs, _t7;
692
+ return _regeneratorRuntime.wrap(function (_context4) {
671
693
  while (1) switch (_context4.prev = _context4.next) {
672
694
  case 0:
673
695
  libraryId = _ref5.libraryId, objectId = _ref5.objectId, writeToken = _ref5.writeToken, _ref5$access = _ref5.access, access = _ref5$access === void 0 ? [] : _ref5$access, _ref5$jobIndexes = _ref5.jobIndexes, jobIndexes = _ref5$jobIndexes === void 0 ? null : _ref5$jobIndexes;
@@ -675,29 +697,28 @@ exports.StartABRMezzanineJobs = /*#__PURE__*/function () {
675
697
  libraryId: libraryId,
676
698
  objectId: objectId
677
699
  });
678
- if (writeToken) {
679
- ValidateWriteToken(writeToken);
680
- if (!objectId) {
681
- objectId = this.utils.DecodeWriteToken(writeToken).objectId;
682
- }
700
+ writeTokenSupplied = !!writeToken;
701
+ if (writeTokenSupplied) {
702
+ ValidateWriteToken(writeToken, objectId);
703
+ objectId = objectId || this.utils.DecodeWriteToken(writeToken).objectId;
683
704
  }
684
- _context4.next = 5;
705
+ _context4.next = 1;
685
706
  return this.ContentObjectMetadata({
686
707
  libraryId: libraryId,
687
708
  objectId: objectId,
688
709
  writeToken: writeToken,
689
710
  metadataSubtree: UrlJoin("abr_mezzanine", "offerings")
690
711
  });
691
- case 5:
712
+ case 1:
692
713
  lastJobOfferingsInfo = _context4.sent;
693
714
  offeringKey = MezJobMainOfferingKey(lastJobOfferingsInfo);
694
715
  prepSpecs = lastJobOfferingsInfo[offeringKey].mez_prep_specs;
695
716
  if (prepSpecs) {
696
- _context4.next = 10;
717
+ _context4.next = 2;
697
718
  break;
698
719
  }
699
720
  throw Error("No stream preparation specs found");
700
- case 10:
721
+ case 2:
701
722
  // Retrieve all masters associated with this offering
702
723
  masterVersionHashes = Object.keys(prepSpecs).map(function (spec) {
703
724
  return (prepSpecs[spec].source_streams || []).map(function (stream) {
@@ -711,11 +732,11 @@ exports.StartABRMezzanineJobs = /*#__PURE__*/function () {
711
732
  });
712
733
 
713
734
  // Retrieve authorization tokens for all masters and the mezzanine
714
- _context4.next = 14;
715
- return Promise.all(masterVersionHashes.map( /*#__PURE__*/function () {
716
- var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(versionHash) {
735
+ _context4.next = 3;
736
+ return Promise.all(masterVersionHashes.map(/*#__PURE__*/function () {
737
+ var _ref7 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee3(versionHash) {
717
738
  var payload;
718
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
739
+ return _regeneratorRuntime.wrap(function (_context3) {
719
740
  while (1) switch (_context3.prev = _context3.next) {
720
741
  case 0:
721
742
  payload = {}; // Hash may be a write token since media/abr_mezzanine/init doesn't support write token, only prod_master_hash
@@ -724,11 +745,11 @@ exports.StartABRMezzanineJobs = /*#__PURE__*/function () {
724
745
  } else {
725
746
  payload["versionHash"] = versionHash;
726
747
  }
727
- _context3.next = 4;
748
+ _context3.next = 1;
728
749
  return _this.authClient.AuthorizationToken(_objectSpread({}, payload));
729
- case 4:
750
+ case 1:
730
751
  return _context3.abrupt("return", _context3.sent);
731
- case 5:
752
+ case 2:
732
753
  case "end":
733
754
  return _context3.stop();
734
755
  }
@@ -738,99 +759,87 @@ exports.StartABRMezzanineJobs = /*#__PURE__*/function () {
738
759
  return _ref7.apply(this, arguments);
739
760
  };
740
761
  }()));
741
- case 14:
762
+ case 3:
742
763
  authorizationTokens = _context4.sent;
743
- _context4.next = 17;
764
+ _context4.next = 4;
744
765
  return this.authClient.AuthorizationToken({
745
766
  libraryId: libraryId,
746
767
  objectId: objectId,
747
768
  update: true
748
769
  });
749
- case 17:
750
- _context4.t0 = _context4.sent;
751
- authorizationTokens = [_context4.t0].concat(_toConsumableArray(authorizationTokens));
770
+ case 4:
771
+ _t7 = _context4.sent;
772
+ authorizationTokens = [_t7].concat(_toConsumableArray(authorizationTokens));
752
773
  headers = {
753
774
  Authorization: authorizationTokens.map(function (token) {
754
775
  return "Bearer ".concat(token);
755
776
  }).join(",")
756
777
  };
757
- if (!writeToken) {
758
- _context4.next = 27;
778
+ if (writeTokenSupplied) {
779
+ _context4.next = 9;
759
780
  break;
760
781
  }
761
- _context4.next = 23;
762
- return this.WriteTokenNodeUrlNetwork({
763
- writeToken: writeToken
764
- });
765
- case 23:
766
- nodeUrl = _context4.sent;
767
- processingDraft = {
768
- write_token: writeToken,
769
- nodeUrl: nodeUrl
770
- };
771
- _context4.next = 30;
772
- break;
773
- case 27:
774
- _context4.next = 29;
782
+ _context4.next = 5;
775
783
  return this.EditContentObject({
776
784
  libraryId: libraryId,
777
785
  objectId: objectId
778
786
  });
779
- case 29:
780
- processingDraft = _context4.sent;
781
- case 30:
782
- lroInfo = {
783
- write_token: processingDraft.write_token,
784
- node: processingDraft.nodeUrl,
785
- offering: offeringKey
786
- }; // Update metadata with LRO version write token
787
- if (!writeToken) {
788
- _context4.next = 36;
789
- break;
790
- }
791
- _context4.next = 34;
792
- return this.ReplaceMetadata({
793
- libraryId: libraryId,
794
- objectId: objectId,
795
- writeToken: writeToken,
796
- metadataSubtree: "lro_draft",
797
- metadata: lroInfo
798
- });
799
- case 34:
800
- _context4.next = 44;
801
- break;
802
- case 36:
803
- _context4.next = 38;
787
+ case 5:
788
+ lroWorkingDraft = _context4.sent;
789
+ writeToken = lroWorkingDraft.writeToken;
790
+
791
+ // Save this write token (and node url, and offering key) to ANOTHER, NEW write token in order to
792
+ // record "bread crumb" metadata at /lro_draft, and save (finalize) this second write token
793
+ _context4.next = 6;
804
794
  return this.EditContentObject({
805
795
  libraryId: libraryId,
806
796
  objectId: objectId
807
797
  });
808
- case 38:
809
- statusDraft = _context4.sent;
810
- _context4.next = 41;
798
+ case 6:
799
+ breadCrumbDraft = _context4.sent;
800
+ breadCrumb = {
801
+ write_token: lroWorkingDraft.writeToken,
802
+ node: lroWorkingDraft.nodeUrl,
803
+ offering: offeringKey
804
+ };
805
+ _context4.next = 7;
811
806
  return this.ReplaceMetadata({
812
807
  libraryId: libraryId,
813
808
  objectId: objectId,
814
- writeToken: statusDraft.write_token,
809
+ writeToken: breadCrumbDraft.writeToken,
815
810
  metadataSubtree: "lro_draft",
816
- metadata: lroInfo
811
+ metadata: breadCrumb
817
812
  });
818
- case 41:
819
- _context4.next = 43;
813
+ case 7:
814
+ _context4.next = 8;
820
815
  return this.FinalizeContentObject({
821
816
  libraryId: libraryId,
822
817
  objectId: objectId,
823
- writeToken: statusDraft.write_token,
824
- commitMessage: "Mezzanine LRO status"
818
+ writeToken: breadCrumbDraft.write_token,
819
+ commitMessage: "Save mez LRO write token to /lro_draft"
825
820
  });
826
- case 43:
821
+ case 8:
827
822
  finalizeResponse = _context4.sent;
828
- case 44:
829
- _context4.next = 46;
823
+ breadCrumbHash = finalizeResponse.hash;
824
+ case 9:
825
+ _context4.next = 10;
826
+ return this.WriteTokenNodeUrlNetwork({
827
+ writeToken: writeToken
828
+ });
829
+ case 10:
830
+ nodeUrl = _context4.sent;
831
+ // tell http client what node to contact for this write token
832
+ this.RecordWriteToken({
833
+ writeToken: writeToken,
834
+ fabricNodeUrl: nodeUrl
835
+ });
836
+
837
+ // Make the API call that actually starts the LROs
838
+ _context4.next = 11;
830
839
  return this.CallBitcodeMethod({
831
840
  libraryId: libraryId,
832
841
  objectId: objectId,
833
- writeToken: processingDraft.write_token,
842
+ writeToken: writeToken,
834
843
  headers: headers,
835
844
  method: UrlJoin("media", "abr_mezzanine", "prep_start"),
836
845
  constant: false,
@@ -840,23 +849,23 @@ exports.StartABRMezzanineJobs = /*#__PURE__*/function () {
840
849
  job_indexes: jobIndexes
841
850
  }
842
851
  });
843
- case 46:
852
+ case 11:
844
853
  _yield$this$CallBitco3 = _context4.sent;
845
854
  data = _yield$this$CallBitco3.data;
846
855
  errors = _yield$this$CallBitco3.errors;
847
856
  warnings = _yield$this$CallBitco3.warnings;
848
857
  logs = _yield$this$CallBitco3.logs;
849
858
  return _context4.abrupt("return", {
850
- hash: finalizeResponse ? finalizeResponse.hash : "",
851
- lro_draft: lroInfo,
852
- writeToken: processingDraft.write_token,
853
- nodeUrl: processingDraft.nodeUrl,
859
+ hash: breadCrumbHash,
860
+ lro_draft: breadCrumb,
861
+ writeToken: writeToken,
862
+ nodeUrl: nodeUrl,
854
863
  data: data,
855
864
  logs: logs || [],
856
865
  warnings: warnings || [],
857
866
  errors: errors || []
858
867
  });
859
- case 52:
868
+ case 12:
860
869
  case "end":
861
870
  return _context4.stop();
862
871
  }
@@ -871,6 +880,10 @@ exports.StartABRMezzanineJobs = /*#__PURE__*/function () {
871
880
  * Retrieve node and write token for a mezzanine's current offering preparation job (if any).
872
881
  * Also returns the offering key.
873
882
  *
883
+ * This information is contained in metadata at /lro_draft, in an extra version of the object
884
+ * that gets created and finalized as part of creating a mezzanine. This serves as a "bread crumb trail" to
885
+ * allow users to find the active draft/write token that the ingest LROs are writing to.
886
+ *
874
887
  * @methodGroup ABR Publishing
875
888
  * @namedParams
876
889
  * @param {string} libraryId - ID of the library
@@ -879,74 +892,73 @@ exports.StartABRMezzanineJobs = /*#__PURE__*/function () {
879
892
  * @return {Promise<Object>} - LRO status
880
893
  */
881
894
  exports.LRODraftInfo = /*#__PURE__*/function () {
882
- var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(_ref8) {
883
- var libraryId, objectId, writeToken, standardPathContents, lastJobOfferingsInfo, mainOfferingKey, ready, oldPathContents;
884
- return _regeneratorRuntime.wrap(function _callee5$(_context5) {
895
+ var _ref9 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee5(_ref8) {
896
+ var libraryId, objectId, standardPathContents, lastJobOfferingsInfo, mainOfferingKey, ready, oldPathContents;
897
+ return _regeneratorRuntime.wrap(function (_context5) {
885
898
  while (1) switch (_context5.prev = _context5.next) {
886
899
  case 0:
887
- libraryId = _ref8.libraryId, objectId = _ref8.objectId, writeToken = _ref8.writeToken;
888
- _context5.next = 3;
900
+ libraryId = _ref8.libraryId, objectId = _ref8.objectId;
901
+ _context5.next = 1;
889
902
  return this.ContentObjectMetadata({
890
903
  libraryId: libraryId,
891
904
  objectId: objectId,
892
- writeToken: writeToken,
893
905
  metadataSubtree: "lro_draft"
894
906
  });
895
- case 3:
907
+ case 1:
896
908
  standardPathContents = _context5.sent;
897
909
  if (!standardPathContents) {
898
- _context5.next = 6;
910
+ _context5.next = 2;
899
911
  break;
900
912
  }
901
913
  return _context5.abrupt("return", standardPathContents);
902
- case 6:
903
- _context5.next = 8;
914
+ case 2:
915
+ _context5.next = 3;
904
916
  return this.ContentObjectMetadata({
905
917
  libraryId: libraryId,
906
918
  objectId: objectId,
907
919
  writeToken: writeToken,
908
920
  metadataSubtree: UrlJoin("abr_mezzanine", "offerings")
909
921
  });
910
- case 8:
922
+ case 3:
911
923
  lastJobOfferingsInfo = _context5.sent;
912
924
  if (lastJobOfferingsInfo) {
913
- _context5.next = 11;
925
+ _context5.next = 4;
914
926
  break;
915
927
  }
916
928
  throw Error("No metadata for mezzanine preparation job found at /abr_mezzanine");
917
- case 11:
929
+ case 4:
918
930
  mainOfferingKey = MezJobMainOfferingKey(lastJobOfferingsInfo);
919
931
  if (mainOfferingKey) {
920
- _context5.next = 14;
932
+ _context5.next = 5;
921
933
  break;
922
934
  }
923
935
  throw Error("Could not determine offering key for last submitted job");
924
- case 14:
936
+ case 5:
925
937
  // see if offering from last job was finalized
926
938
  ready = lastJobOfferingsInfo[mainOfferingKey].ready; // old location for LRO draft info
927
- _context5.next = 17;
939
+ _context5.next = 6;
928
940
  return this.ContentObjectMetadata({
929
941
  libraryId: libraryId,
930
942
  objectId: objectId,
931
943
  writeToken: writeToken,
932
944
  metadataSubtree: "lro_draft_".concat(mainOfferingKey)
933
945
  });
934
- case 17:
946
+ case 6:
935
947
  oldPathContents = _context5.sent;
936
948
  if (!oldPathContents) {
937
- _context5.next = 22;
949
+ _context5.next = 7;
938
950
  break;
939
951
  }
940
952
  return _context5.abrupt("return", oldPathContents);
941
- case 22:
953
+ case 7:
942
954
  if (!ready) {
943
- _context5.next = 26;
955
+ _context5.next = 8;
944
956
  break;
945
957
  }
946
958
  throw Error("No LRO draft found for this mezzanine - looks like last mez prep job was already finalized.");
947
- case 26:
959
+ case 8:
948
960
  throw Error("No LRO draft found for this mezzanine - looks like last mez prep job was either cancelled or discarded.");
949
- case 27:
961
+ case 9:
950
962
  case "end":
951
963
  return _context5.stop();
952
964
  }
@@ -959,133 +971,173 @@ exports.LRODraftInfo = /*#__PURE__*/function () {
959
971
 
960
972
  /**
961
973
  * Retrieve status information for mezzanine transcoding jobs, aka long running operations (LROs) on the given object.
974
+ * If a write token is passed in, its draft will be checked directly by lookiing at /lro_status.
975
+ * If a write token is not passed in, then the latest version of objectId will be checked for "bread crumb" entry
976
+ * at /lro_draft, to determine the write token that current ingest LRO(s) are writing to.
962
977
  *
963
978
  * @methodGroup ABR Publishing
964
979
  * @namedParams
965
980
  * @param {string} libraryId - ID of the library
966
981
  * @param {string} objectId - ID of the object
982
+ * @param {string=} writeToken - Write token of the active draft (that the transcode LROs are writing to)
967
983
  *
968
984
  * @return {Promise<Object>} - LRO status
969
985
  */
970
986
  exports.LROStatus = /*#__PURE__*/function () {
971
- var _ref11 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(_ref10) {
972
- var libraryId, objectId, writeToken, lroDraft;
973
- return _regeneratorRuntime.wrap(function _callee6$(_context6) {
987
+ var _ref1 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee6(_ref0) {
988
+ var libraryId, objectId, _ref0$writeToken, writeToken, activeWriteToken, lroDraft, fabricNodeUrl;
989
+ return _regeneratorRuntime.wrap(function (_context6) {
974
990
  while (1) switch (_context6.prev = _context6.next) {
975
991
  case 0:
976
- libraryId = _ref10.libraryId, objectId = _ref10.objectId, writeToken = _ref10.writeToken;
992
+ libraryId = _ref0.libraryId, objectId = _ref0.objectId, _ref0$writeToken = _ref0.writeToken, writeToken = _ref0$writeToken === void 0 ? "" : _ref0$writeToken;
977
993
  ValidateParameters({
978
994
  libraryId: libraryId,
979
995
  objectId: objectId
980
996
  });
997
+ if (!writeToken) {
998
+ _context6.next = 1;
999
+ break;
1000
+ }
1001
+ ValidateWriteToken(writeToken, objectId);
1002
+ activeWriteToken = writeToken;
981
1003
  _context6.next = 4;
1004
+ break;
1005
+ case 1:
1006
+ _context6.next = 2;
982
1007
  return this.LRODraftInfo({
983
1008
  libraryId: libraryId,
984
- objectId: objectId,
985
- writeToken: writeToken
1009
+ objectId: objectId
986
1010
  });
987
- case 4:
1011
+ case 2:
988
1012
  lroDraft = _context6.sent;
1013
+ activeWriteToken = lroDraft.write_token;
1014
+ _context6.next = 3;
1015
+ return this.WriteTokenNodeUrlNetwork({
1016
+ writeToken: activeWriteToken
1017
+ });
1018
+ case 3:
1019
+ fabricNodeUrl = _context6.sent;
989
1020
  this.RecordWriteToken({
990
1021
  writeToken: lroDraft.write_token,
991
- fabricNodeUrl: lroDraft.node
1022
+ fabricNodeUrl: fabricNodeUrl
992
1023
  });
993
- _context6.next = 8;
1024
+ case 4:
1025
+ _context6.next = 5;
994
1026
  return this.ContentObjectMetadata({
995
1027
  libraryId: libraryId,
996
1028
  objectId: objectId,
997
- writeToken: writeToken,
1029
+ writeToken: activeWriteToken,
998
1030
  metadataSubtree: "lro_status"
999
1031
  });
1000
- case 8:
1032
+ case 5:
1001
1033
  return _context6.abrupt("return", _context6.sent);
1002
- case 9:
1034
+ case 6:
1003
1035
  case "end":
1004
1036
  return _context6.stop();
1005
1037
  }
1006
1038
  }, _callee6, this);
1007
1039
  }));
1008
1040
  return function (_x6) {
1009
- return _ref11.apply(this, arguments);
1041
+ return _ref1.apply(this, arguments);
1010
1042
  };
1011
1043
  }();
1012
1044
 
1013
1045
  /**
1014
- * Finalize a mezzanine object after all jobs have finished
1046
+ * Process completed mezzanine transcoding LRO(s), creating the final offering(s) from the transcode(s)
1047
+ * Unless a writeToken is passed in, finalize the mez object working draft as well.
1048
+ *
1049
+ * If a writeToken is not passed in, then it will be retrieved from /lro_draft of most recent version of object.
1050
+ * This is a "bread crumb" entry that gets created by StartABRMezzanineJobs() - unless a writeToken was passed in to StartABRMezzanineJobs() also.
1015
1051
  *
1016
1052
  * @methodGroup ABR Publishing
1017
1053
  * @namedParams
1018
1054
  * @param {string} libraryId - ID of the mezzanine library
1019
1055
  * @param {string} objectId - ID of the mezzanine object
1020
- * @param {string} writeToken - Write token for the mezzanine object. If specified, the object will not be finalized.
1056
+ * @param {string=} writeToken - Write token for the mezzanine object. If specified, the object will not be finalized.
1021
1057
  * @param {function=} preFinalizeFn - A function to call before finalizing changes, to allow further modifications to offering. The function will be invoked with {elvClient, nodeUrl, writeToken} to allow access to the draft and MUST NOT finalize the draft.
1022
1058
  * @param {boolean=} preFinalizeThrow - If set to `true` then any error thrown by preFinalizeFn will not be caught. Otherwise, any exception will be appended to the `warnings` array returned after finalization.
1023
1059
  *
1024
1060
  * @return {Promise<Object>} - The finalize response for the mezzanine object, as well as any logs, warnings and errors from the finalization
1025
1061
  */
1026
1062
  exports.FinalizeABRMezzanine = /*#__PURE__*/function () {
1027
- var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(_ref12) {
1028
- var libraryId, objectId, preFinalizeFn, preFinalizeThrow, writeToken, nodeUrl, lastJobOfferingsInfo, offeringKey, masterHash, authPayload, authorizationTokens, headers, _yield$this$CallBitco4, data, errors, warnings, logs, preFinalizeWarnings, params, finalizeResponse;
1029
- return _regeneratorRuntime.wrap(function _callee7$(_context7) {
1063
+ var _ref11 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee7(_ref10) {
1064
+ var libraryId, objectId, preFinalizeFn, preFinalizeThrow, _ref10$writeToken, writeToken, writeTokenSupplied, lroDraft, fabricNodeUrl, lastJobOfferingsInfo, offeringKey, masterHash, masterIdentifier, authorizationTokens, headers, _yield$this$CallBitco4, data, errors, warnings, logs, preFinalizeWarnings, params, finalizeResponse, _t8, _t9, _t0, _t1;
1065
+ return _regeneratorRuntime.wrap(function (_context7) {
1030
1066
  while (1) switch (_context7.prev = _context7.next) {
1031
1067
  case 0:
1032
- libraryId = _ref12.libraryId, objectId = _ref12.objectId, preFinalizeFn = _ref12.preFinalizeFn, preFinalizeThrow = _ref12.preFinalizeThrow, writeToken = _ref12.writeToken;
1068
+ libraryId = _ref10.libraryId, objectId = _ref10.objectId, preFinalizeFn = _ref10.preFinalizeFn, preFinalizeThrow = _ref10.preFinalizeThrow, _ref10$writeToken = _ref10.writeToken, writeToken = _ref10$writeToken === void 0 ? "" : _ref10$writeToken;
1033
1069
  ValidateParameters({
1034
1070
  libraryId: libraryId,
1035
1071
  objectId: objectId
1036
1072
  });
1037
- if (writeToken) {
1038
- ValidateWriteToken(writeToken);
1073
+ writeTokenSupplied = !!writeToken;
1074
+ if (!writeTokenSupplied) {
1075
+ _context7.next = 1;
1076
+ break;
1039
1077
  }
1040
- _context7.next = 5;
1078
+ ValidateWriteToken(writeToken, objectId);
1079
+ objectId = objectId || this.utils.DecodeWriteToken(writeToken).objectId;
1080
+ _context7.next = 3;
1081
+ break;
1082
+ case 1:
1083
+ _context7.next = 2;
1084
+ return this.LRODraftInfo({
1085
+ libraryId: libraryId,
1086
+ objectId: objectId
1087
+ });
1088
+ case 2:
1089
+ lroDraft = _context7.sent;
1090
+ writeToken = lroDraft.write_token;
1091
+ case 3:
1092
+ _context7.next = 4;
1041
1093
  return this.WriteTokenNodeUrlNetwork({
1042
1094
  writeToken: writeToken
1043
1095
  });
1044
- case 5:
1045
- nodeUrl = _context7.sent;
1096
+ case 4:
1097
+ fabricNodeUrl = _context7.sent;
1046
1098
  // tell http client what node to contact for this write token
1047
1099
  this.RecordWriteToken({
1048
1100
  writeToken: writeToken,
1049
- fabricNodeUrl: nodeUrl
1101
+ fabricNodeUrl: fabricNodeUrl
1050
1102
  });
1051
- _context7.next = 9;
1103
+ _context7.next = 5;
1052
1104
  return this.ContentObjectMetadata({
1053
1105
  libraryId: libraryId,
1054
1106
  objectId: objectId,
1055
1107
  writeToken: writeToken,
1056
1108
  metadataSubtree: UrlJoin("abr_mezzanine", "offerings")
1057
1109
  });
1058
- case 9:
1110
+ case 5:
1059
1111
  lastJobOfferingsInfo = _context7.sent;
1060
1112
  offeringKey = MezJobMainOfferingKey(lastJobOfferingsInfo);
1061
1113
  masterHash = lastJobOfferingsInfo[offeringKey].prod_master_hash;
1062
- authPayload = {};
1114
+ masterIdentifier = {};
1063
1115
  if (masterHash.startsWith("tqw__")) {
1064
- authPayload["objectId"] = this.utils.DecodeWriteToken(masterHash).objectId;
1116
+ masterIdentifier["objectId"] = this.utils.DecodeWriteToken(masterHash).objectId;
1065
1117
  } else {
1066
- authPayload["versionHash"] = masterHash;
1118
+ masterIdentifier["versionHash"] = masterHash;
1067
1119
  }
1068
1120
 
1069
1121
  // Authorization token for mezzanine and master
1070
- _context7.next = 16;
1122
+ _context7.next = 6;
1071
1123
  return this.authClient.AuthorizationToken({
1072
1124
  libraryId: libraryId,
1073
1125
  objectId: objectId,
1074
1126
  update: true
1075
1127
  });
1076
- case 16:
1077
- _context7.t0 = _context7.sent;
1078
- _context7.next = 19;
1079
- return this.authClient.AuthorizationToken(_objectSpread({}, authPayload));
1080
- case 19:
1081
- _context7.t1 = _context7.sent;
1082
- authorizationTokens = [_context7.t0, _context7.t1];
1128
+ case 6:
1129
+ _t8 = _context7.sent;
1130
+ _context7.next = 7;
1131
+ return this.authClient.AuthorizationToken(_objectSpread({}, masterIdentifier));
1132
+ case 7:
1133
+ _t9 = _context7.sent;
1134
+ authorizationTokens = [_t8, _t9];
1083
1135
  headers = {
1084
1136
  Authorization: authorizationTokens.map(function (token) {
1085
1137
  return "Bearer ".concat(token);
1086
1138
  }).join(",")
1087
1139
  };
1088
- _context7.next = 24;
1140
+ _context7.next = 8;
1089
1141
  return this.CallBitcodeMethod({
1090
1142
  objectId: objectId,
1091
1143
  libraryId: libraryId,
@@ -1094,7 +1146,7 @@ exports.FinalizeABRMezzanine = /*#__PURE__*/function () {
1094
1146
  headers: headers,
1095
1147
  constant: false
1096
1148
  });
1097
- case 24:
1149
+ case 8:
1098
1150
  _yield$this$CallBitco4 = _context7.sent;
1099
1151
  data = _yield$this$CallBitco4.data;
1100
1152
  errors = _yield$this$CallBitco4.errors;
@@ -1102,7 +1154,7 @@ exports.FinalizeABRMezzanine = /*#__PURE__*/function () {
1102
1154
  logs = _yield$this$CallBitco4.logs;
1103
1155
  preFinalizeWarnings = [];
1104
1156
  if (!preFinalizeFn) {
1105
- _context7.next = 44;
1157
+ _context7.next = 13;
1106
1158
  break;
1107
1159
  }
1108
1160
  params = {
@@ -1110,31 +1162,34 @@ exports.FinalizeABRMezzanine = /*#__PURE__*/function () {
1110
1162
  offeringKey: offeringKey,
1111
1163
  writeToken: writeToken
1112
1164
  };
1113
- _context7.prev = 32;
1114
- _context7.next = 35;
1165
+ _context7.prev = 9;
1166
+ _context7.next = 10;
1115
1167
  return preFinalizeFn(params);
1116
- case 35:
1117
- _context7.next = 44;
1168
+ case 10:
1169
+ _context7.next = 13;
1118
1170
  break;
1119
- case 37:
1120
- _context7.prev = 37;
1121
- _context7.t2 = _context7["catch"](32);
1171
+ case 11:
1172
+ _context7.prev = 11;
1173
+ _t0 = _context7["catch"](9);
1122
1174
  if (!preFinalizeThrow) {
1123
- _context7.next = 43;
1175
+ _context7.next = 12;
1124
1176
  break;
1125
1177
  }
1126
1178
  throw new Error("Error running preFinalize function", {
1127
- cause: _context7.t2
1179
+ cause: _t0
1128
1180
  });
1129
- case 43:
1130
- preFinalizeWarnings = "Error running preFinalize function: ".concat(_context7.t2);
1131
- case 44:
1132
- finalizeResponse = {};
1133
- if (writeToken) {
1134
- _context7.next = 49;
1181
+ case 12:
1182
+ preFinalizeWarnings = "Error running preFinalize function: ".concat(_t0);
1183
+ case 13:
1184
+ if (!writeTokenSupplied) {
1185
+ _context7.next = 14;
1135
1186
  break;
1136
1187
  }
1137
- _context7.next = 48;
1188
+ _t1 = {};
1189
+ _context7.next = 16;
1190
+ break;
1191
+ case 14:
1192
+ _context7.next = 15;
1138
1193
  return this.FinalizeContentObject({
1139
1194
  libraryId: libraryId,
1140
1195
  objectId: objectId,
@@ -1142,22 +1197,23 @@ exports.FinalizeABRMezzanine = /*#__PURE__*/function () {
1142
1197
  commitMessage: "Finalize ABR mezzanine",
1143
1198
  awaitCommitConfirmation: false
1144
1199
  });
1145
- case 48:
1146
- finalizeResponse = _context7.sent;
1147
- case 49:
1200
+ case 15:
1201
+ _t1 = _context7.sent;
1202
+ case 16:
1203
+ finalizeResponse = _t1;
1148
1204
  return _context7.abrupt("return", _objectSpread({
1149
1205
  data: data,
1150
1206
  logs: logs || [],
1151
1207
  warnings: (warnings || []).concat(preFinalizeWarnings),
1152
1208
  errors: errors || []
1153
1209
  }, finalizeResponse));
1154
- case 50:
1210
+ case 17:
1155
1211
  case "end":
1156
1212
  return _context7.stop();
1157
1213
  }
1158
- }, _callee7, this, [[32, 37]]);
1214
+ }, _callee7, this, [[9, 11]]);
1159
1215
  }));
1160
1216
  return function (_x7) {
1161
- return _ref13.apply(this, arguments);
1217
+ return _ref11.apply(this, arguments);
1162
1218
  };
1163
1219
  }();