@eluvio/elv-client-js 4.0.11 → 4.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/dist/.keep +0 -0
  2. package/dist/ElvClient-min.js +11 -10
  3. package/dist/ElvClient-node-min.js +11 -10
  4. package/dist/ElvFrameClient-min.js +11 -10
  5. package/dist/ElvPermissionsClient-min.js +10 -9
  6. package/dist/ElvWalletClient-min.js +10 -9
  7. package/dist/ElvWalletClient-node-min.js +10 -9
  8. package/dist/src/AuthorizationClient.js +1555 -2076
  9. package/dist/src/ContentObjectVerification.js +134 -185
  10. package/dist/src/Crypto.js +224 -319
  11. package/dist/src/ElvClient.js +822 -1114
  12. package/dist/src/ElvWallet.js +64 -106
  13. package/dist/src/EthClient.js +719 -974
  14. package/dist/src/FrameClient.js +223 -319
  15. package/dist/src/HttpClient.js +117 -156
  16. package/dist/src/Id.js +1 -6
  17. package/dist/src/LogMessage.js +4 -8
  18. package/dist/src/PermissionsClient.js +973 -1271
  19. package/dist/src/RemoteSigner.js +161 -232
  20. package/dist/src/UserProfileClient.js +781 -1038
  21. package/dist/src/Utils.js +159 -299
  22. package/dist/src/Validation.js +2 -17
  23. package/dist/src/client/ABRPublishing.js +828 -958
  24. package/dist/src/client/AccessGroups.js +849 -1095
  25. package/dist/src/client/ContentAccess.js +3323 -4195
  26. package/dist/src/client/ContentManagement.js +1818 -2290
  27. package/dist/src/client/Contracts.js +468 -614
  28. package/dist/src/client/Files.js +1506 -1846
  29. package/dist/src/client/NFT.js +94 -116
  30. package/dist/src/client/NTP.js +326 -425
  31. package/dist/src/index.js +2 -5
  32. package/dist/src/walletClient/ClientMethods.js +1368 -1763
  33. package/dist/src/walletClient/Configuration.js +5 -3
  34. package/dist/src/walletClient/Notifications.js +98 -127
  35. package/dist/src/walletClient/Profile.js +184 -246
  36. package/dist/src/walletClient/Utils.js +76 -122
  37. package/dist/src/walletClient/index.js +1171 -1496
  38. package/package.json +4 -21
  39. package/src/FrameClient.js +1 -0
  40. package/src/HttpClient.js +4 -2
  41. package/src/client/ABRPublishing.js +126 -105
  42. package/src/client/ContentAccess.js +1 -0
  43. package/src/client/ContentManagement.js +4 -2
  44. package/src/walletClient/Configuration.js +3 -2
  45. package/dist/AccessClient-min.js +0 -54
  46. package/dist/AccessClient-node-min.js +0 -74
  47. package/dist/src/AccessClient.js +0 -798
  48. package/dist/src/LimitedMap.js +0 -120
  49. package/dist/src/client/Access.js +0 -1
  50. package/dist/src/client/Management.js +0 -1606
  51. package/dist/src/contracts/AccessIndexor.js +0 -831
  52. package/dist/src/contracts/Accessible.js +0 -31
  53. package/dist/src/contracts/AdmgrAdvertisement.js +0 -695
  54. package/dist/src/contracts/AdmgrCampaign.js +0 -648
  55. package/dist/src/contracts/AdmgrCampaignManager.js +0 -493
  56. package/dist/src/contracts/AdmgrCommercialOffering.js +0 -622
  57. package/dist/src/contracts/AdmgrCommercialOfferingManager.js +0 -413
  58. package/dist/src/contracts/AdmgrMarketPlace.js +0 -413
  59. package/dist/src/contracts/AvailsDelivery.js +0 -535
  60. package/dist/src/contracts/BaseAccessControlGroup.js +0 -1221
  61. package/dist/src/contracts/BaseAccessWallet.js +0 -1575
  62. package/dist/src/contracts/BaseAccessWalletFactory.js +0 -93
  63. package/dist/src/contracts/BaseContent.js +0 -1104
  64. package/dist/src/contracts/BaseContentFactory.js +0 -99
  65. package/dist/src/contracts/BaseContentFactoryExt.js +0 -219
  66. package/dist/src/contracts/BaseContentSpace.js +0 -1346
  67. package/dist/src/contracts/BaseContentType.js +0 -353
  68. package/dist/src/contracts/BaseFactory.js +0 -107
  69. package/dist/src/contracts/BaseGroupFactory.js +0 -93
  70. package/dist/src/contracts/BaseLibrary.js +0 -1035
  71. package/dist/src/contracts/BaseLibraryFactory.js +0 -96
  72. package/dist/src/contracts/Certifyer.js +0 -87
  73. package/dist/src/contracts/Container.js +0 -543
  74. package/dist/src/contracts/Content.js +0 -432
  75. package/dist/src/contracts/Editable.js +0 -295
  76. package/dist/src/contracts/FactorySpace.js +0 -57
  77. package/dist/src/contracts/KmsSpace.js +0 -52
  78. package/dist/src/contracts/LvProvider.js +0 -512
  79. package/dist/src/contracts/LvRecordableStream.js +0 -1026
  80. package/dist/src/contracts/LvRecording.js +0 -627
  81. package/dist/src/contracts/LvStreamRightsHolder.js +0 -551
  82. package/dist/src/contracts/MetaObject.js +0 -110
  83. package/dist/src/contracts/Node.js +0 -167
  84. package/dist/src/contracts/NodeSpace.js +0 -18
  85. package/dist/src/contracts/NodeSpaceImpl.js +0 -273
  86. package/dist/src/contracts/Ownable.js +0 -87
  87. package/dist/src/contracts/PaymentService.js +0 -616
  88. package/dist/src/contracts/Precompile.js +0 -15
  89. package/dist/src/contracts/SampleContentAdMarketplace.js +0 -564
  90. package/dist/src/contracts/SampleContentAdvertising.js +0 -444
  91. package/dist/src/contracts/SampleContentHelloWorld.js +0 -459
  92. package/dist/src/contracts/SampleContentLicensing.js +0 -618
  93. package/dist/src/contracts/SampleContentSigned.js +0 -447
  94. package/dist/src/contracts/SampleInstance.js +0 -438
  95. package/dist/src/contracts/SampleInstanceFactory.js +0 -451
  96. package/dist/src/contracts/Transactable.js +0 -82
  97. package/dist/src/contracts/UserSpace.js +0 -18
  98. package/dist/src/contracts/UserSpaceImpl.js +0 -43
  99. package/dist/src/contracts/Utils.js +0 -18
  100. package/dist/src/contracts/Verifier.js +0 -53
  101. package/dist/src/contracts/strings.js +0 -4
  102. package/dist/src/contracts/v2/BaseContentFactoryExt.js +0 -219
  103. package/dist/src/contracts/v2/FactorySpace.js +0 -57
  104. package/dist/src/contracts/v2/KmsSpace.js +0 -52
  105. package/dist/src/contracts/v2/NodeSpaceImpl.js +0 -273
  106. package/dist/src/contracts/v2/UserSpaceImpl.js +0 -43
  107. package/dist/src/marketplaceClient/ClientMethods.js +0 -1918
  108. package/dist/src/marketplaceClient/Configuration.js +0 -29
  109. package/dist/src/marketplaceClient/Utils.js +0 -304
  110. package/dist/src/marketplaceClient/index.js +0 -1553
  111. package/utilities/ListAccessGroups.js +0 -34
@@ -1,23 +1,14 @@
1
1
  var _regeneratorRuntime = require("@babel/runtime/regenerator");
2
-
3
2
  var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
4
-
5
3
  var _defineProperty = require("@babel/runtime/helpers/defineProperty");
6
-
7
4
  var _classCallCheck = require("@babel/runtime/helpers/classCallCheck");
8
-
9
5
  var _createClass = require("@babel/runtime/helpers/createClass");
10
-
11
6
  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; }
12
-
13
7
  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; }
14
-
15
8
  var UrlJoin = require("url-join");
16
-
17
9
  var _require = require("./Validation"),
18
- ValidatePresence = _require.ValidatePresence,
19
- ValidatePermission = _require.ValidatePermission;
20
-
10
+ ValidatePresence = _require.ValidatePresence,
11
+ ValidatePermission = _require.ValidatePermission;
21
12
  var PermissionsClient = /*#__PURE__*/function () {
22
13
  "use strict";
23
14
 
@@ -127,50 +118,40 @@ var PermissionsClient = /*#__PURE__*/function () {
127
118
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
128
119
  offline: false
129
120
  };
130
-
131
121
  _classCallCheck(this, PermissionsClient);
132
-
133
122
  this.client = client;
134
123
  this.subjectNames = {};
135
124
  this.drafts = {};
136
125
  this.offline = options.offline;
137
126
  }
138
-
139
127
  _createClass(PermissionsClient, [{
140
128
  key: "FormatDate",
141
129
  value: function FormatDate(date) {
142
130
  if (!date) {
143
131
  return;
144
132
  }
145
-
146
133
  if (isNaN(new Date(date))) {
147
134
  throw Error("Invalid start time: ".concat(date));
148
135
  }
149
-
150
136
  return new Date(date).toISOString();
151
137
  }
152
138
  }, {
153
139
  key: "FormatProfile",
154
140
  value: function FormatProfile(profile) {
155
141
  var _this = this;
156
-
157
142
  ValidatePermission(profile.default_permission);
158
143
  var profileSpec = {};
159
-
160
144
  if (profile.start) {
161
145
  profileSpec.start = this.FormatDate(profile.start);
162
146
  }
163
-
164
147
  if (profile.end) {
165
148
  profileSpec.end = this.FormatDate(profile.end);
166
149
  }
167
-
168
150
  ["assets", "offerings"].forEach(function (type) {
169
151
  var typeInfo = profile[type] || {};
170
152
  profileSpec[type] = {
171
153
  default_permission: typeInfo.default_permission || typeInfo.default_permissions || "no-access"
172
154
  };
173
-
174
155
  if (typeInfo.custom_permissions) {
175
156
  profileSpec[type].custom_permissions = {};
176
157
  Object.keys(typeInfo.custom_permissions).forEach(function (id) {
@@ -178,244 +159,197 @@ var PermissionsClient = /*#__PURE__*/function () {
178
159
  var spec = {
179
160
  permission: ValidatePermission(permission.permission)
180
161
  };
181
-
182
162
  if (permission.start) {
183
163
  spec.start = _this.FormatDate(permission.start);
184
164
  }
185
-
186
165
  if (permission.end) {
187
166
  spec.end = _this.FormatDate(permission.end);
188
167
  }
189
-
190
168
  profileSpec[type].custom_permissions[id] = _objectSpread(_objectSpread({}, permission), spec);
191
169
  });
192
170
  }
193
171
  });
194
172
  return profileSpec;
195
- } // Convert from fabric metadata spec to client spec
173
+ }
196
174
 
175
+ // Convert from fabric metadata spec to client spec
197
176
  }, {
198
177
  key: "FormatPermission",
199
178
  value: function () {
200
179
  var _FormatPermission = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
201
180
  var policyId, policyWriteToken, permission, subjectSource, subjectType, subjectId, subjectName, subjectNTPId, id, cachedName, contentSpaceLibraryId, permissionSpec;
202
181
  return _regeneratorRuntime.wrap(function _callee$(_context) {
203
- while (1) {
204
- switch (_context.prev = _context.next) {
205
- case 0:
206
- policyId = _ref.policyId, policyWriteToken = _ref.policyWriteToken, permission = _ref.permission;
207
- subjectSource = permission.subject.type.startsWith("oauth") ? "oauth" : "fabric";
208
- _context.t0 = permission.subject.type;
209
- _context.next = _context.t0 === "otp" ? 5 : _context.t0 === "otp_subject" ? 8 : _context.t0 === "group" ? 13 : _context.t0 === "oauth_group" ? 13 : _context.t0 === "user" ? 16 : _context.t0 === "oauth_user" ? 16 : 19;
210
- break;
211
-
212
- case 5:
213
- subjectType = "ntp";
214
- subjectId = permission.subject.id;
215
- return _context.abrupt("break", 20);
216
-
217
- case 8:
218
- subjectType = "ntp_subject";
219
- subjectId = permission.subject.id;
220
- subjectName = subjectId;
221
- subjectNTPId = permission.subject.otp_id;
222
- return _context.abrupt("break", 20);
223
-
224
- case 13:
225
- subjectType = "group";
226
- subjectId = subjectSource === "oauth" ? permission.subject.oauth_id : this.client.utils.HashToAddress(permission.subject.id);
227
- return _context.abrupt("break", 20);
228
-
229
- case 16:
230
- subjectType = "user";
231
- subjectId = subjectSource === "oauth" ? permission.subject.oauth_id : this.client.utils.HashToAddress(permission.subject.id);
232
- return _context.abrupt("break", 20);
233
-
234
- case 19:
235
- throw Error("Unknown subject type: " + permission.subject.type);
236
-
237
- case 20:
238
- id = permission.subject.oauth_id || permission.subject.id;
239
- cachedName = this.subjectNames[id];
240
- subjectName = subjectName || cachedName || permission.subject.id;
241
-
242
- if (!(!cachedName && subjectSource === "fabric")) {
243
- _context.next = 74;
244
- break;
245
- }
246
-
247
- if (!(subjectType === "group")) {
248
- _context.next = 36;
249
- break;
250
- }
251
-
252
- _context.next = 27;
253
- return this.client.ContentSpaceId();
254
-
255
- case 27:
256
- contentSpaceLibraryId = _context.sent.replace("ispc", "ilib");
257
- _context.next = 30;
258
- return this.client.ContentObjectMetadata({
259
- libraryId: contentSpaceLibraryId,
260
- objectId: this.client.utils.AddressToObjectId(subjectId),
261
- metadataSubtree: UrlJoin("public", "name")
262
- });
263
-
264
- case 30:
265
- _context.t1 = _context.sent;
266
-
267
- if (_context.t1) {
268
- _context.next = 33;
269
- break;
270
- }
271
-
272
- _context.t1 = subjectId;
273
-
274
- case 33:
275
- subjectName = _context.t1;
182
+ while (1) switch (_context.prev = _context.next) {
183
+ case 0:
184
+ policyId = _ref.policyId, policyWriteToken = _ref.policyWriteToken, permission = _ref.permission;
185
+ subjectSource = permission.subject.type.startsWith("oauth") ? "oauth" : "fabric";
186
+ _context.t0 = permission.subject.type;
187
+ _context.next = _context.t0 === "otp" ? 5 : _context.t0 === "otp_subject" ? 8 : _context.t0 === "group" ? 13 : _context.t0 === "oauth_group" ? 13 : _context.t0 === "user" ? 16 : _context.t0 === "oauth_user" ? 16 : 19;
188
+ break;
189
+ case 5:
190
+ subjectType = "ntp";
191
+ subjectId = permission.subject.id;
192
+ return _context.abrupt("break", 20);
193
+ case 8:
194
+ subjectType = "ntp_subject";
195
+ subjectId = permission.subject.id;
196
+ subjectName = subjectId;
197
+ subjectNTPId = permission.subject.otp_id;
198
+ return _context.abrupt("break", 20);
199
+ case 13:
200
+ subjectType = "group";
201
+ subjectId = subjectSource === "oauth" ? permission.subject.oauth_id : this.client.utils.HashToAddress(permission.subject.id);
202
+ return _context.abrupt("break", 20);
203
+ case 16:
204
+ subjectType = "user";
205
+ subjectId = subjectSource === "oauth" ? permission.subject.oauth_id : this.client.utils.HashToAddress(permission.subject.id);
206
+ return _context.abrupt("break", 20);
207
+ case 19:
208
+ throw Error("Unknown subject type: " + permission.subject.type);
209
+ case 20:
210
+ id = permission.subject.oauth_id || permission.subject.id;
211
+ cachedName = this.subjectNames[id];
212
+ subjectName = subjectName || cachedName || permission.subject.id;
213
+ if (!(!cachedName && subjectSource === "fabric")) {
276
214
  _context.next = 74;
277
215
  break;
278
-
279
- case 36:
280
- if (!(subjectType === "user")) {
281
- _context.next = 56;
282
- break;
283
- }
284
-
285
- _context.t4 = this.client;
286
- _context.next = 40;
287
- return this.client.ContentObjectLibraryId({
288
- objectId: policyId
289
- });
290
-
291
- case 40:
292
- _context.t5 = _context.sent;
293
- _context.t6 = policyId;
294
- _context.t7 = policyWriteToken;
295
- _context.t8 = UrlJoin("auth_policy_settings", "fabric_users", subjectId);
296
- _context.t9 = {
297
- libraryId: _context.t5,
298
- objectId: _context.t6,
299
- writeToken: _context.t7,
300
- metadataSubtree: _context.t8
301
- };
302
- _context.next = 47;
303
- return _context.t4.ContentObjectMetadata.call(_context.t4, _context.t9);
304
-
305
- case 47:
306
- _context.t3 = _context.sent;
307
-
308
- if (_context.t3) {
309
- _context.next = 50;
310
- break;
311
- }
312
-
313
- _context.t3 = {};
314
-
315
- case 50:
316
- _context.t2 = _context.t3.name;
317
-
318
- if (_context.t2) {
319
- _context.next = 53;
320
- break;
321
- }
322
-
323
- _context.t2 = subjectId;
324
-
325
- case 53:
326
- subjectName = _context.t2;
216
+ }
217
+ if (!(subjectType === "group")) {
218
+ _context.next = 36;
219
+ break;
220
+ }
221
+ _context.next = 27;
222
+ return this.client.ContentSpaceId();
223
+ case 27:
224
+ contentSpaceLibraryId = _context.sent.replace("ispc", "ilib");
225
+ _context.next = 30;
226
+ return this.client.ContentObjectMetadata({
227
+ libraryId: contentSpaceLibraryId,
228
+ objectId: this.client.utils.AddressToObjectId(subjectId),
229
+ metadataSubtree: UrlJoin("public", "name")
230
+ });
231
+ case 30:
232
+ _context.t1 = _context.sent;
233
+ if (_context.t1) {
234
+ _context.next = 33;
235
+ break;
236
+ }
237
+ _context.t1 = subjectId;
238
+ case 33:
239
+ subjectName = _context.t1;
240
+ _context.next = 74;
241
+ break;
242
+ case 36:
243
+ if (!(subjectType === "user")) {
244
+ _context.next = 56;
245
+ break;
246
+ }
247
+ _context.t4 = this.client;
248
+ _context.next = 40;
249
+ return this.client.ContentObjectLibraryId({
250
+ objectId: policyId
251
+ });
252
+ case 40:
253
+ _context.t5 = _context.sent;
254
+ _context.t6 = policyId;
255
+ _context.t7 = policyWriteToken;
256
+ _context.t8 = UrlJoin("auth_policy_settings", "fabric_users", subjectId);
257
+ _context.t9 = {
258
+ libraryId: _context.t5,
259
+ objectId: _context.t6,
260
+ writeToken: _context.t7,
261
+ metadataSubtree: _context.t8
262
+ };
263
+ _context.next = 47;
264
+ return _context.t4.ContentObjectMetadata.call(_context.t4, _context.t9);
265
+ case 47:
266
+ _context.t3 = _context.sent;
267
+ if (_context.t3) {
268
+ _context.next = 50;
269
+ break;
270
+ }
271
+ _context.t3 = {};
272
+ case 50:
273
+ _context.t2 = _context.t3.name;
274
+ if (_context.t2) {
275
+ _context.next = 53;
276
+ break;
277
+ }
278
+ _context.t2 = subjectId;
279
+ case 53:
280
+ subjectName = _context.t2;
281
+ _context.next = 74;
282
+ break;
283
+ case 56:
284
+ if (!(subjectType === "ntp")) {
327
285
  _context.next = 74;
328
286
  break;
329
-
330
- case 56:
331
- if (!(subjectType === "ntp")) {
332
- _context.next = 74;
333
- break;
334
- }
335
-
336
- _context.t12 = this.client;
337
- _context.next = 60;
338
- return this.client.ContentObjectLibraryId({
339
- objectId: policyId
340
- });
341
-
342
- case 60:
343
- _context.t13 = _context.sent;
344
- _context.t14 = policyId;
345
- _context.t15 = policyWriteToken;
346
- _context.t16 = UrlJoin("auth_policy_settings", "ntp_instances", subjectId);
347
- _context.t17 = {
348
- libraryId: _context.t13,
349
- objectId: _context.t14,
350
- writeToken: _context.t15,
351
- metadataSubtree: _context.t16
352
- };
353
- _context.next = 67;
354
- return _context.t12.ContentObjectMetadata.call(_context.t12, _context.t17);
355
-
356
- case 67:
357
- _context.t11 = _context.sent;
358
-
359
- if (_context.t11) {
360
- _context.next = 70;
361
- break;
362
- }
363
-
364
- _context.t11 = {};
365
-
366
- case 70:
367
- _context.t10 = _context.t11.name;
368
-
369
- if (_context.t10) {
370
- _context.next = 73;
371
- break;
372
- }
373
-
374
- _context.t10 = subjectId;
375
-
376
- case 73:
377
- subjectName = _context.t10;
378
-
379
- case 74:
380
- this.subjectNames[id] = subjectName;
381
- permissionSpec = {
382
- profileName: permission.profile,
383
- subjectSource: subjectSource,
384
- subjectType: subjectType,
385
- subjectId: subjectId,
386
- subjectName: subjectName
387
- };
388
-
389
- if (subjectNTPId) {
390
- permissionSpec.subjectNTPId = subjectNTPId;
391
- }
392
-
393
- if (permission.start) {
394
- permissionSpec.start = permission.start;
395
- }
396
-
397
- if (permission.end) {
398
- permissionSpec.end = permission.end;
399
- }
400
-
401
- return _context.abrupt("return", permissionSpec);
402
-
403
- case 80:
404
- case "end":
405
- return _context.stop();
406
- }
287
+ }
288
+ _context.t12 = this.client;
289
+ _context.next = 60;
290
+ return this.client.ContentObjectLibraryId({
291
+ objectId: policyId
292
+ });
293
+ case 60:
294
+ _context.t13 = _context.sent;
295
+ _context.t14 = policyId;
296
+ _context.t15 = policyWriteToken;
297
+ _context.t16 = UrlJoin("auth_policy_settings", "ntp_instances", subjectId);
298
+ _context.t17 = {
299
+ libraryId: _context.t13,
300
+ objectId: _context.t14,
301
+ writeToken: _context.t15,
302
+ metadataSubtree: _context.t16
303
+ };
304
+ _context.next = 67;
305
+ return _context.t12.ContentObjectMetadata.call(_context.t12, _context.t17);
306
+ case 67:
307
+ _context.t11 = _context.sent;
308
+ if (_context.t11) {
309
+ _context.next = 70;
310
+ break;
311
+ }
312
+ _context.t11 = {};
313
+ case 70:
314
+ _context.t10 = _context.t11.name;
315
+ if (_context.t10) {
316
+ _context.next = 73;
317
+ break;
318
+ }
319
+ _context.t10 = subjectId;
320
+ case 73:
321
+ subjectName = _context.t10;
322
+ case 74:
323
+ this.subjectNames[id] = subjectName;
324
+ permissionSpec = {
325
+ profileName: permission.profile,
326
+ subjectSource: subjectSource,
327
+ subjectType: subjectType,
328
+ subjectId: subjectId,
329
+ subjectName: subjectName
330
+ };
331
+ if (subjectNTPId) {
332
+ permissionSpec.subjectNTPId = subjectNTPId;
333
+ }
334
+ if (permission.start) {
335
+ permissionSpec.start = permission.start;
336
+ }
337
+ if (permission.end) {
338
+ permissionSpec.end = permission.end;
339
+ }
340
+ return _context.abrupt("return", permissionSpec);
341
+ case 80:
342
+ case "end":
343
+ return _context.stop();
407
344
  }
408
345
  }, _callee, this);
409
346
  }));
410
-
411
347
  function FormatPermission(_x) {
412
348
  return _FormatPermission.apply(this, arguments);
413
349
  }
414
-
415
350
  return FormatPermission;
416
351
  }()
417
352
  /* Offline draft */
418
-
419
353
  /**
420
354
  * Open an offline draft - copies object data locally and allows the functions processing this data to operate
421
355
  * on the local copy, much faster. Closing the draft will copy the data back to the object's write token.
@@ -426,59 +360,48 @@ var PermissionsClient = /*#__PURE__*/function () {
426
360
  * @param {string} policyLibraryId - Policy object library ID (optional)
427
361
  * @param {string=} policyWriteToken - Write token for the policy object
428
362
  */
429
-
430
363
  }, {
431
364
  key: "OpenOfflineDraft",
432
365
  value: function () {
433
366
  var _OpenOfflineDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref2) {
434
367
  var policyId, policyLibraryId, policyWriteToken, meta;
435
368
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
436
- while (1) {
437
- switch (_context2.prev = _context2.next) {
438
- case 0:
439
- policyId = _ref2.policyId, policyLibraryId = _ref2.policyLibraryId, policyWriteToken = _ref2.policyWriteToken;
440
-
441
- if (!(policyLibraryId == null)) {
442
- _context2.next = 5;
443
- break;
444
- }
445
-
446
- _context2.next = 4;
447
- return this.client.ContentObjectLibraryId({
448
- objectId: policyId
449
- });
450
-
451
- case 4:
452
- policyLibraryId = _context2.sent;
453
-
454
- case 5:
455
- _context2.next = 7;
456
- return this.client.ContentObjectMetadata({
457
- libraryId: policyLibraryId,
458
- objectId: policyId,
459
- writeToken: policyWriteToken
460
- });
461
-
462
- case 7:
463
- meta = _context2.sent;
464
- this.drafts[policyId] = {
465
- meta: meta,
466
- policyLibraryId: policyLibraryId,
467
- policyWriteToken: policyWriteToken
468
- };
469
-
470
- case 9:
471
- case "end":
472
- return _context2.stop();
473
- }
369
+ while (1) switch (_context2.prev = _context2.next) {
370
+ case 0:
371
+ policyId = _ref2.policyId, policyLibraryId = _ref2.policyLibraryId, policyWriteToken = _ref2.policyWriteToken;
372
+ if (!(policyLibraryId == null)) {
373
+ _context2.next = 5;
374
+ break;
375
+ }
376
+ _context2.next = 4;
377
+ return this.client.ContentObjectLibraryId({
378
+ objectId: policyId
379
+ });
380
+ case 4:
381
+ policyLibraryId = _context2.sent;
382
+ case 5:
383
+ _context2.next = 7;
384
+ return this.client.ContentObjectMetadata({
385
+ libraryId: policyLibraryId,
386
+ objectId: policyId,
387
+ writeToken: policyWriteToken
388
+ });
389
+ case 7:
390
+ meta = _context2.sent;
391
+ this.drafts[policyId] = {
392
+ meta: meta,
393
+ policyLibraryId: policyLibraryId,
394
+ policyWriteToken: policyWriteToken
395
+ };
396
+ case 9:
397
+ case "end":
398
+ return _context2.stop();
474
399
  }
475
400
  }, _callee2, this);
476
401
  }));
477
-
478
402
  function OpenOfflineDraft(_x2) {
479
403
  return _OpenOfflineDraft.apply(this, arguments);
480
404
  }
481
-
482
405
  return OpenOfflineDraft;
483
406
  }()
484
407
  /**
@@ -489,53 +412,42 @@ var PermissionsClient = /*#__PURE__*/function () {
489
412
  * @namedParams
490
413
  * @param {string} policyId - Object ID of the policy
491
414
  */
492
-
493
415
  }, {
494
416
  key: "CloseOfflineDraft",
495
417
  value: function () {
496
418
  var _CloseOfflineDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref3) {
497
419
  var policyId;
498
420
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
499
- while (1) {
500
- switch (_context3.prev = _context3.next) {
501
- case 0:
502
- policyId = _ref3.policyId;
503
-
504
- if (!(this.drafts[policyId] == null)) {
505
- _context3.next = 3;
506
- break;
507
- }
508
-
509
- throw Error("No draft open for policyId: " + policyId);
510
-
511
- case 3:
512
- _context3.next = 5;
513
- return this.client.ReplaceMetadata({
514
- libraryId: this.drafts[policyId].policyLibraryId,
515
- objectId: policyId,
516
- writeToken: this.drafts[policyId].policyWriteToken,
517
- metadata: this.drafts[policyId].meta
518
- });
519
-
520
- case 5:
521
- this.drafts[policyId] = null;
522
-
523
- case 6:
524
- case "end":
525
- return _context3.stop();
526
- }
421
+ while (1) switch (_context3.prev = _context3.next) {
422
+ case 0:
423
+ policyId = _ref3.policyId;
424
+ if (!(this.drafts[policyId] == null)) {
425
+ _context3.next = 3;
426
+ break;
427
+ }
428
+ throw Error("No draft open for policyId: " + policyId);
429
+ case 3:
430
+ _context3.next = 5;
431
+ return this.client.ReplaceMetadata({
432
+ libraryId: this.drafts[policyId].policyLibraryId,
433
+ objectId: policyId,
434
+ writeToken: this.drafts[policyId].policyWriteToken,
435
+ metadata: this.drafts[policyId].meta
436
+ });
437
+ case 5:
438
+ this.drafts[policyId] = null;
439
+ case 6:
440
+ case "end":
441
+ return _context3.stop();
527
442
  }
528
443
  }, _callee3, this);
529
444
  }));
530
-
531
445
  function CloseOfflineDraft(_x3) {
532
446
  return _CloseOfflineDraft.apply(this, arguments);
533
447
  }
534
-
535
448
  return CloseOfflineDraft;
536
449
  }()
537
450
  /* Add / remove overall item permission */
538
-
539
451
  /**
540
452
  * Retrieve a list of all items in the specified policy
541
453
  *
@@ -545,63 +457,52 @@ var PermissionsClient = /*#__PURE__*/function () {
545
457
  * @param {string=} policyWriteToken - Write token for the policy object - if specified, info will be retrieved from the write draft instead of the last finalized policy object
546
458
  * @return {Promise<Object>} - A mapping of item objectId to the display name of the item
547
459
  */
548
-
549
460
  }, {
550
461
  key: "PolicyItems",
551
462
  value: function () {
552
463
  var _PolicyItems = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref4) {
553
464
  var policyId, policyWriteToken;
554
465
  return _regeneratorRuntime.wrap(function _callee4$(_context4) {
555
- while (1) {
556
- switch (_context4.prev = _context4.next) {
557
- case 0:
558
- policyId = _ref4.policyId, policyWriteToken = _ref4.policyWriteToken;
559
- _context4.t1 = this.client;
560
- _context4.next = 4;
561
- return this.client.ContentObjectLibraryId({
562
- objectId: policyId
563
- });
564
-
565
- case 4:
566
- _context4.t2 = _context4.sent;
567
- _context4.t3 = policyId;
568
- _context4.t4 = policyWriteToken;
569
- _context4.t5 = ["*/display_title"];
570
- _context4.t6 = {
571
- libraryId: _context4.t2,
572
- objectId: _context4.t3,
573
- writeToken: _context4.t4,
574
- metadataSubtree: "auth_policy_spec",
575
- select: _context4.t5
576
- };
577
- _context4.next = 11;
578
- return _context4.t1.ContentObjectMetadata.call(_context4.t1, _context4.t6);
579
-
580
- case 11:
581
- _context4.t0 = _context4.sent;
582
-
583
- if (_context4.t0) {
584
- _context4.next = 14;
585
- break;
586
- }
587
-
588
- _context4.t0 = {};
589
-
590
- case 14:
591
- return _context4.abrupt("return", _context4.t0);
592
-
593
- case 15:
594
- case "end":
595
- return _context4.stop();
596
- }
466
+ while (1) switch (_context4.prev = _context4.next) {
467
+ case 0:
468
+ policyId = _ref4.policyId, policyWriteToken = _ref4.policyWriteToken;
469
+ _context4.t1 = this.client;
470
+ _context4.next = 4;
471
+ return this.client.ContentObjectLibraryId({
472
+ objectId: policyId
473
+ });
474
+ case 4:
475
+ _context4.t2 = _context4.sent;
476
+ _context4.t3 = policyId;
477
+ _context4.t4 = policyWriteToken;
478
+ _context4.t5 = ["*/display_title"];
479
+ _context4.t6 = {
480
+ libraryId: _context4.t2,
481
+ objectId: _context4.t3,
482
+ writeToken: _context4.t4,
483
+ metadataSubtree: "auth_policy_spec",
484
+ select: _context4.t5
485
+ };
486
+ _context4.next = 11;
487
+ return _context4.t1.ContentObjectMetadata.call(_context4.t1, _context4.t6);
488
+ case 11:
489
+ _context4.t0 = _context4.sent;
490
+ if (_context4.t0) {
491
+ _context4.next = 14;
492
+ break;
493
+ }
494
+ _context4.t0 = {};
495
+ case 14:
496
+ return _context4.abrupt("return", _context4.t0);
497
+ case 15:
498
+ case "end":
499
+ return _context4.stop();
597
500
  }
598
501
  }, _callee4, this);
599
502
  }));
600
-
601
503
  function PolicyItems(_x4) {
602
504
  return _PolicyItems.apply(this, arguments);
603
505
  }
604
-
605
506
  return PolicyItems;
606
507
  }()
607
508
  /**
@@ -614,61 +515,50 @@ var PermissionsClient = /*#__PURE__*/function () {
614
515
  * @param {string} itemId - Object ID of the item
615
516
  * @return {Promise<Object | undefined>} - The policy for the specified item. If none exists, returns undefined
616
517
  */
617
-
618
518
  }, {
619
519
  key: "ItemPolicy",
620
520
  value: function () {
621
521
  var _ItemPolicy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(_ref5) {
622
522
  var policyId, policyWriteToken, itemId, profiles, permissions;
623
523
  return _regeneratorRuntime.wrap(function _callee5$(_context5) {
624
- while (1) {
625
- switch (_context5.prev = _context5.next) {
626
- case 0:
627
- policyId = _ref5.policyId, policyWriteToken = _ref5.policyWriteToken, itemId = _ref5.itemId;
628
- _context5.next = 3;
629
- return this.ItemProfiles({
630
- policyId: policyId,
631
- policyWriteToken: policyWriteToken,
632
- itemId: itemId
633
- });
634
-
635
- case 3:
636
- profiles = _context5.sent;
637
- _context5.next = 6;
638
- return this.ItemPermissions({
639
- policyId: policyId,
640
- policyWriteToken: policyWriteToken,
641
- itemId: itemId
642
- });
643
-
644
- case 6:
645
- permissions = _context5.sent;
646
-
647
- if (!(!profiles || !permissions)) {
648
- _context5.next = 9;
649
- break;
650
- }
651
-
652
- return _context5.abrupt("return");
653
-
654
- case 9:
655
- return _context5.abrupt("return", {
656
- profiles: profiles,
657
- permissions: permissions
658
- });
659
-
660
- case 10:
661
- case "end":
662
- return _context5.stop();
663
- }
524
+ while (1) switch (_context5.prev = _context5.next) {
525
+ case 0:
526
+ policyId = _ref5.policyId, policyWriteToken = _ref5.policyWriteToken, itemId = _ref5.itemId;
527
+ _context5.next = 3;
528
+ return this.ItemProfiles({
529
+ policyId: policyId,
530
+ policyWriteToken: policyWriteToken,
531
+ itemId: itemId
532
+ });
533
+ case 3:
534
+ profiles = _context5.sent;
535
+ _context5.next = 6;
536
+ return this.ItemPermissions({
537
+ policyId: policyId,
538
+ policyWriteToken: policyWriteToken,
539
+ itemId: itemId
540
+ });
541
+ case 6:
542
+ permissions = _context5.sent;
543
+ if (!(!profiles || !permissions)) {
544
+ _context5.next = 9;
545
+ break;
546
+ }
547
+ return _context5.abrupt("return");
548
+ case 9:
549
+ return _context5.abrupt("return", {
550
+ profiles: profiles,
551
+ permissions: permissions
552
+ });
553
+ case 10:
554
+ case "end":
555
+ return _context5.stop();
664
556
  }
665
557
  }, _callee5, this);
666
558
  }));
667
-
668
559
  function ItemPolicy(_x5) {
669
560
  return _ItemPolicy.apply(this, arguments);
670
561
  }
671
-
672
562
  return ItemPolicy;
673
563
  }()
674
564
  /**
@@ -681,98 +571,84 @@ var PermissionsClient = /*#__PURE__*/function () {
681
571
  * @param {string} itemId - Object ID of the item
682
572
  * @param {object=} profiles={} - Profiles to create
683
573
  */
684
-
685
574
  }, {
686
575
  key: "CreateItemPolicy",
687
576
  value: function () {
688
577
  var _CreateItemPolicy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(_ref6) {
689
578
  var _this2 = this;
690
-
691
579
  var policyId, policyWriteToken, itemId, _ref6$profiles, profiles, metadata, assetMetadata, displayTitle, itemSpec;
692
-
693
580
  return _regeneratorRuntime.wrap(function _callee6$(_context6) {
694
- while (1) {
695
- switch (_context6.prev = _context6.next) {
696
- case 0:
697
- policyId = _ref6.policyId, policyWriteToken = _ref6.policyWriteToken, itemId = _ref6.itemId, _ref6$profiles = _ref6.profiles, profiles = _ref6$profiles === void 0 ? {} : _ref6$profiles;
698
- ValidatePresence("policyId", policyId);
699
- ValidatePresence("policyWriteToken", policyWriteToken);
700
- ValidatePresence("itemId", itemId);
701
- ValidatePresence("profiles", profiles);
702
- _context6.t1 = this.client;
703
- _context6.next = 8;
704
- return this.client.ContentObjectLibraryId({
705
- objectId: itemId
706
- });
707
-
708
- case 8:
709
- _context6.t2 = _context6.sent;
710
- _context6.t3 = itemId;
711
- _context6.t4 = ["public/name", "public/asset_metadata/title", "public/asset_metadata/display_title"];
712
- _context6.t5 = {
713
- libraryId: _context6.t2,
714
- objectId: _context6.t3,
715
- select: _context6.t4
716
- };
717
- _context6.next = 14;
718
- return _context6.t1.ContentObjectMetadata.call(_context6.t1, _context6.t5);
719
-
720
- case 14:
721
- _context6.t0 = _context6.sent;
722
-
723
- if (_context6.t0) {
724
- _context6.next = 17;
725
- break;
726
- }
727
-
728
- _context6.t0 = {};
729
-
730
- case 17:
731
- metadata = _context6.t0;
732
- assetMetadata = (metadata["public"] || {}).asset_metadata || {};
733
- displayTitle = assetMetadata.display_title || assetMetadata.title || (metadata["public"] || {}).name;
734
- itemSpec = {
735
- display_title: displayTitle,
736
- permissions: [],
737
- profiles: {}
738
- };
739
- Object.keys(profiles).forEach(function (profileName) {
740
- itemSpec.profiles[profileName] = _this2.FormatProfile(profiles[profileName]);
741
- });
742
- _context6.t6 = this.client;
743
- _context6.next = 25;
744
- return this.client.ContentObjectLibraryId({
745
- objectId: policyId
746
- });
747
-
748
- case 25:
749
- _context6.t7 = _context6.sent;
750
- _context6.t8 = policyId;
751
- _context6.t9 = policyWriteToken;
752
- _context6.t10 = UrlJoin("auth_policy_spec", itemId);
753
- _context6.t11 = itemSpec;
754
- _context6.t12 = {
755
- libraryId: _context6.t7,
756
- objectId: _context6.t8,
757
- writeToken: _context6.t9,
758
- metadataSubtree: _context6.t10,
759
- metadata: _context6.t11
760
- };
761
- _context6.next = 33;
762
- return _context6.t6.ReplaceMetadata.call(_context6.t6, _context6.t12);
763
-
764
- case 33:
765
- case "end":
766
- return _context6.stop();
767
- }
581
+ while (1) switch (_context6.prev = _context6.next) {
582
+ case 0:
583
+ policyId = _ref6.policyId, policyWriteToken = _ref6.policyWriteToken, itemId = _ref6.itemId, _ref6$profiles = _ref6.profiles, profiles = _ref6$profiles === void 0 ? {} : _ref6$profiles;
584
+ ValidatePresence("policyId", policyId);
585
+ ValidatePresence("policyWriteToken", policyWriteToken);
586
+ ValidatePresence("itemId", itemId);
587
+ ValidatePresence("profiles", profiles);
588
+ _context6.t1 = this.client;
589
+ _context6.next = 8;
590
+ return this.client.ContentObjectLibraryId({
591
+ objectId: itemId
592
+ });
593
+ case 8:
594
+ _context6.t2 = _context6.sent;
595
+ _context6.t3 = itemId;
596
+ _context6.t4 = ["public/name", "public/asset_metadata/title", "public/asset_metadata/display_title"];
597
+ _context6.t5 = {
598
+ libraryId: _context6.t2,
599
+ objectId: _context6.t3,
600
+ select: _context6.t4
601
+ };
602
+ _context6.next = 14;
603
+ return _context6.t1.ContentObjectMetadata.call(_context6.t1, _context6.t5);
604
+ case 14:
605
+ _context6.t0 = _context6.sent;
606
+ if (_context6.t0) {
607
+ _context6.next = 17;
608
+ break;
609
+ }
610
+ _context6.t0 = {};
611
+ case 17:
612
+ metadata = _context6.t0;
613
+ assetMetadata = (metadata["public"] || {}).asset_metadata || {};
614
+ displayTitle = assetMetadata.display_title || assetMetadata.title || (metadata["public"] || {}).name;
615
+ itemSpec = {
616
+ display_title: displayTitle,
617
+ permissions: [],
618
+ profiles: {}
619
+ };
620
+ Object.keys(profiles).forEach(function (profileName) {
621
+ itemSpec.profiles[profileName] = _this2.FormatProfile(profiles[profileName]);
622
+ });
623
+ _context6.t6 = this.client;
624
+ _context6.next = 25;
625
+ return this.client.ContentObjectLibraryId({
626
+ objectId: policyId
627
+ });
628
+ case 25:
629
+ _context6.t7 = _context6.sent;
630
+ _context6.t8 = policyId;
631
+ _context6.t9 = policyWriteToken;
632
+ _context6.t10 = UrlJoin("auth_policy_spec", itemId);
633
+ _context6.t11 = itemSpec;
634
+ _context6.t12 = {
635
+ libraryId: _context6.t7,
636
+ objectId: _context6.t8,
637
+ writeToken: _context6.t9,
638
+ metadataSubtree: _context6.t10,
639
+ metadata: _context6.t11
640
+ };
641
+ _context6.next = 33;
642
+ return _context6.t6.ReplaceMetadata.call(_context6.t6, _context6.t12);
643
+ case 33:
644
+ case "end":
645
+ return _context6.stop();
768
646
  }
769
647
  }, _callee6, this);
770
648
  }));
771
-
772
649
  function CreateItemPolicy(_x6) {
773
650
  return _CreateItemPolicy.apply(this, arguments);
774
651
  }
775
-
776
652
  return CreateItemPolicy;
777
653
  }()
778
654
  /**
@@ -784,56 +660,48 @@ var PermissionsClient = /*#__PURE__*/function () {
784
660
  * @param {string} policyWriteToken - Write token for the policy
785
661
  * @param {string} itemId - Object ID of the item
786
662
  */
787
-
788
663
  }, {
789
664
  key: "RemoveItemPolicy",
790
665
  value: function () {
791
666
  var _RemoveItemPolicy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(_ref7) {
792
667
  var policyId, policyWriteToken, itemId;
793
668
  return _regeneratorRuntime.wrap(function _callee7$(_context7) {
794
- while (1) {
795
- switch (_context7.prev = _context7.next) {
796
- case 0:
797
- policyId = _ref7.policyId, policyWriteToken = _ref7.policyWriteToken, itemId = _ref7.itemId;
798
- ValidatePresence("policyId", policyId);
799
- ValidatePresence("policyWriteToken", policyWriteToken);
800
- ValidatePresence("itemId", itemId);
801
- _context7.t0 = this.client;
802
- _context7.next = 7;
803
- return this.client.ContentObjectLibraryId({
804
- objectId: policyId
805
- });
806
-
807
- case 7:
808
- _context7.t1 = _context7.sent;
809
- _context7.t2 = policyId;
810
- _context7.t3 = policyWriteToken;
811
- _context7.t4 = UrlJoin("auth_policy_spec", itemId);
812
- _context7.t5 = {
813
- libraryId: _context7.t1,
814
- objectId: _context7.t2,
815
- writeToken: _context7.t3,
816
- metadataSubtree: _context7.t4
817
- };
818
- _context7.next = 14;
819
- return _context7.t0.DeleteMetadata.call(_context7.t0, _context7.t5);
820
-
821
- case 14:
822
- case "end":
823
- return _context7.stop();
824
- }
669
+ while (1) switch (_context7.prev = _context7.next) {
670
+ case 0:
671
+ policyId = _ref7.policyId, policyWriteToken = _ref7.policyWriteToken, itemId = _ref7.itemId;
672
+ ValidatePresence("policyId", policyId);
673
+ ValidatePresence("policyWriteToken", policyWriteToken);
674
+ ValidatePresence("itemId", itemId);
675
+ _context7.t0 = this.client;
676
+ _context7.next = 7;
677
+ return this.client.ContentObjectLibraryId({
678
+ objectId: policyId
679
+ });
680
+ case 7:
681
+ _context7.t1 = _context7.sent;
682
+ _context7.t2 = policyId;
683
+ _context7.t3 = policyWriteToken;
684
+ _context7.t4 = UrlJoin("auth_policy_spec", itemId);
685
+ _context7.t5 = {
686
+ libraryId: _context7.t1,
687
+ objectId: _context7.t2,
688
+ writeToken: _context7.t3,
689
+ metadataSubtree: _context7.t4
690
+ };
691
+ _context7.next = 14;
692
+ return _context7.t0.DeleteMetadata.call(_context7.t0, _context7.t5);
693
+ case 14:
694
+ case "end":
695
+ return _context7.stop();
825
696
  }
826
697
  }, _callee7, this);
827
698
  }));
828
-
829
699
  function RemoveItemPolicy(_x7) {
830
700
  return _RemoveItemPolicy.apply(this, arguments);
831
701
  }
832
-
833
702
  return RemoveItemPolicy;
834
703
  }()
835
704
  /* Get / set / remove profile permissions */
836
-
837
705
  /**
838
706
  * Retrieve profile information on the specified item policy
839
707
  *
@@ -844,52 +712,44 @@ var PermissionsClient = /*#__PURE__*/function () {
844
712
  * @param {string} itemId - Object ID of the item
845
713
  * @param {string=} profileName - The name of the profile. If not specified, all profiles will be returned
846
714
  */
847
-
848
715
  }, {
849
716
  key: "ItemProfiles",
850
717
  value: function () {
851
718
  var _ItemProfiles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(_ref8) {
852
719
  var policyId, policyWriteToken, itemId, profileName;
853
720
  return _regeneratorRuntime.wrap(function _callee8$(_context8) {
854
- while (1) {
855
- switch (_context8.prev = _context8.next) {
856
- case 0:
857
- policyId = _ref8.policyId, policyWriteToken = _ref8.policyWriteToken, itemId = _ref8.itemId, profileName = _ref8.profileName;
858
- _context8.t0 = this.client;
859
- _context8.next = 4;
860
- return this.client.ContentObjectLibraryId({
861
- objectId: policyId
862
- });
863
-
864
- case 4:
865
- _context8.t1 = _context8.sent;
866
- _context8.t2 = policyId;
867
- _context8.t3 = policyWriteToken;
868
- _context8.t4 = UrlJoin("auth_policy_spec", itemId, "profiles", profileName || "");
869
- _context8.t5 = {
870
- libraryId: _context8.t1,
871
- objectId: _context8.t2,
872
- writeToken: _context8.t3,
873
- metadataSubtree: _context8.t4
874
- };
875
- _context8.next = 11;
876
- return _context8.t0.ContentObjectMetadata.call(_context8.t0, _context8.t5);
877
-
878
- case 11:
879
- return _context8.abrupt("return", _context8.sent);
880
-
881
- case 12:
882
- case "end":
883
- return _context8.stop();
884
- }
721
+ while (1) switch (_context8.prev = _context8.next) {
722
+ case 0:
723
+ policyId = _ref8.policyId, policyWriteToken = _ref8.policyWriteToken, itemId = _ref8.itemId, profileName = _ref8.profileName;
724
+ _context8.t0 = this.client;
725
+ _context8.next = 4;
726
+ return this.client.ContentObjectLibraryId({
727
+ objectId: policyId
728
+ });
729
+ case 4:
730
+ _context8.t1 = _context8.sent;
731
+ _context8.t2 = policyId;
732
+ _context8.t3 = policyWriteToken;
733
+ _context8.t4 = UrlJoin("auth_policy_spec", itemId, "profiles", profileName || "");
734
+ _context8.t5 = {
735
+ libraryId: _context8.t1,
736
+ objectId: _context8.t2,
737
+ writeToken: _context8.t3,
738
+ metadataSubtree: _context8.t4
739
+ };
740
+ _context8.next = 11;
741
+ return _context8.t0.ContentObjectMetadata.call(_context8.t0, _context8.t5);
742
+ case 11:
743
+ return _context8.abrupt("return", _context8.sent);
744
+ case 12:
745
+ case "end":
746
+ return _context8.stop();
885
747
  }
886
748
  }, _callee8, this);
887
749
  }));
888
-
889
750
  function ItemProfiles(_x8) {
890
751
  return _ItemProfiles.apply(this, arguments);
891
752
  }
892
-
893
753
  return ItemProfiles;
894
754
  }()
895
755
  /**
@@ -904,56 +764,49 @@ var PermissionsClient = /*#__PURE__*/function () {
904
764
  * @param {object} profileSpec - Specification for the profile. If not provided, profile
905
765
  * will default to no access for both assets and offerings
906
766
  */
907
-
908
767
  }, {
909
768
  key: "SetProfile",
910
769
  value: function () {
911
770
  var _SetProfile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(_ref9) {
912
771
  var policyId, policyWriteToken, itemId, profileName, profileSpec;
913
772
  return _regeneratorRuntime.wrap(function _callee9$(_context9) {
914
- while (1) {
915
- switch (_context9.prev = _context9.next) {
916
- case 0:
917
- policyId = _ref9.policyId, policyWriteToken = _ref9.policyWriteToken, itemId = _ref9.itemId, profileName = _ref9.profileName, profileSpec = _ref9.profileSpec;
918
- ValidatePresence("policyId", policyId);
919
- ValidatePresence("policyWriteToken", policyWriteToken);
920
- ValidatePresence("itemId", itemId);
921
- ValidatePresence("profileName", profileName);
922
- ValidatePresence("profileSpec", profileSpec);
923
- _context9.t0 = this.client;
924
- _context9.next = 9;
925
- return this.client.ContentObjectLibraryId({
926
- objectId: policyId
927
- });
928
-
929
- case 9:
930
- _context9.t1 = _context9.sent;
931
- _context9.t2 = policyId;
932
- _context9.t3 = policyWriteToken;
933
- _context9.t4 = UrlJoin("auth_policy_spec", itemId, "profiles", profileName);
934
- _context9.t5 = this.FormatProfile(profileSpec);
935
- _context9.t6 = {
936
- libraryId: _context9.t1,
937
- objectId: _context9.t2,
938
- writeToken: _context9.t3,
939
- metadataSubtree: _context9.t4,
940
- metadata: _context9.t5
941
- };
942
- _context9.next = 17;
943
- return _context9.t0.ReplaceMetadata.call(_context9.t0, _context9.t6);
944
-
945
- case 17:
946
- case "end":
947
- return _context9.stop();
948
- }
773
+ while (1) switch (_context9.prev = _context9.next) {
774
+ case 0:
775
+ policyId = _ref9.policyId, policyWriteToken = _ref9.policyWriteToken, itemId = _ref9.itemId, profileName = _ref9.profileName, profileSpec = _ref9.profileSpec;
776
+ ValidatePresence("policyId", policyId);
777
+ ValidatePresence("policyWriteToken", policyWriteToken);
778
+ ValidatePresence("itemId", itemId);
779
+ ValidatePresence("profileName", profileName);
780
+ ValidatePresence("profileSpec", profileSpec);
781
+ _context9.t0 = this.client;
782
+ _context9.next = 9;
783
+ return this.client.ContentObjectLibraryId({
784
+ objectId: policyId
785
+ });
786
+ case 9:
787
+ _context9.t1 = _context9.sent;
788
+ _context9.t2 = policyId;
789
+ _context9.t3 = policyWriteToken;
790
+ _context9.t4 = UrlJoin("auth_policy_spec", itemId, "profiles", profileName);
791
+ _context9.t5 = this.FormatProfile(profileSpec);
792
+ _context9.t6 = {
793
+ libraryId: _context9.t1,
794
+ objectId: _context9.t2,
795
+ writeToken: _context9.t3,
796
+ metadataSubtree: _context9.t4,
797
+ metadata: _context9.t5
798
+ };
799
+ _context9.next = 17;
800
+ return _context9.t0.ReplaceMetadata.call(_context9.t0, _context9.t6);
801
+ case 17:
802
+ case "end":
803
+ return _context9.stop();
949
804
  }
950
805
  }, _callee9, this);
951
806
  }));
952
-
953
807
  function SetProfile(_x9) {
954
808
  return _SetProfile.apply(this, arguments);
955
809
  }
956
-
957
810
  return SetProfile;
958
811
  }()
959
812
  /**
@@ -968,57 +821,49 @@ var PermissionsClient = /*#__PURE__*/function () {
968
821
  * @param {object} profileSpec - Specification for the profile. If not provided, profile
969
822
  * will default to no access for both assets and offerings
970
823
  */
971
-
972
824
  }, {
973
825
  key: "RemoveProfile",
974
826
  value: function () {
975
827
  var _RemoveProfile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(_ref10) {
976
828
  var policyId, policyWriteToken, itemId, profileName;
977
829
  return _regeneratorRuntime.wrap(function _callee10$(_context10) {
978
- while (1) {
979
- switch (_context10.prev = _context10.next) {
980
- case 0:
981
- policyId = _ref10.policyId, policyWriteToken = _ref10.policyWriteToken, itemId = _ref10.itemId, profileName = _ref10.profileName;
982
- ValidatePresence("policyId", policyId);
983
- ValidatePresence("policyWriteToken", policyWriteToken);
984
- ValidatePresence("itemId", itemId);
985
- ValidatePresence("profileName", profileName);
986
- _context10.t0 = this.client;
987
- _context10.next = 8;
988
- return this.client.ContentObjectLibraryId({
989
- objectId: policyId
990
- });
991
-
992
- case 8:
993
- _context10.t1 = _context10.sent;
994
- _context10.t2 = policyId;
995
- _context10.t3 = policyWriteToken;
996
- _context10.t4 = UrlJoin("auth_policy_spec", itemId, "profiles", profileName);
997
- _context10.t5 = {
998
- libraryId: _context10.t1,
999
- objectId: _context10.t2,
1000
- writeToken: _context10.t3,
1001
- metadataSubtree: _context10.t4
1002
- };
1003
- _context10.next = 15;
1004
- return _context10.t0.DeleteMetadata.call(_context10.t0, _context10.t5);
1005
-
1006
- case 15:
1007
- case "end":
1008
- return _context10.stop();
1009
- }
830
+ while (1) switch (_context10.prev = _context10.next) {
831
+ case 0:
832
+ policyId = _ref10.policyId, policyWriteToken = _ref10.policyWriteToken, itemId = _ref10.itemId, profileName = _ref10.profileName;
833
+ ValidatePresence("policyId", policyId);
834
+ ValidatePresence("policyWriteToken", policyWriteToken);
835
+ ValidatePresence("itemId", itemId);
836
+ ValidatePresence("profileName", profileName);
837
+ _context10.t0 = this.client;
838
+ _context10.next = 8;
839
+ return this.client.ContentObjectLibraryId({
840
+ objectId: policyId
841
+ });
842
+ case 8:
843
+ _context10.t1 = _context10.sent;
844
+ _context10.t2 = policyId;
845
+ _context10.t3 = policyWriteToken;
846
+ _context10.t4 = UrlJoin("auth_policy_spec", itemId, "profiles", profileName);
847
+ _context10.t5 = {
848
+ libraryId: _context10.t1,
849
+ objectId: _context10.t2,
850
+ writeToken: _context10.t3,
851
+ metadataSubtree: _context10.t4
852
+ };
853
+ _context10.next = 15;
854
+ return _context10.t0.DeleteMetadata.call(_context10.t0, _context10.t5);
855
+ case 15:
856
+ case "end":
857
+ return _context10.stop();
1010
858
  }
1011
859
  }, _callee10, this);
1012
860
  }));
1013
-
1014
861
  function RemoveProfile(_x10) {
1015
862
  return _RemoveProfile.apply(this, arguments);
1016
863
  }
1017
-
1018
864
  return RemoveProfile;
1019
865
  }()
1020
866
  /* Get / set / remove subject permissions */
1021
-
1022
867
  /**
1023
868
  * Retrieve the permissions for the specified item policy
1024
869
  *
@@ -1030,91 +875,73 @@ var PermissionsClient = /*#__PURE__*/function () {
1030
875
  *
1031
876
  * @return {Promise<Array>} - The list of permissions for the specified item
1032
877
  */
1033
-
1034
878
  }, {
1035
879
  key: "ItemPermissions",
1036
880
  value: function () {
1037
881
  var _ItemPermissions = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(_ref11) {
1038
882
  var _this3 = this;
1039
-
1040
883
  var policyId, policyWriteToken, itemId, libraryId, permissions;
1041
884
  return _regeneratorRuntime.wrap(function _callee12$(_context12) {
1042
- while (1) {
1043
- switch (_context12.prev = _context12.next) {
1044
- case 0:
1045
- policyId = _ref11.policyId, policyWriteToken = _ref11.policyWriteToken, itemId = _ref11.itemId;
1046
- _context12.next = 3;
1047
- return this.client.ContentObjectLibraryId({
1048
- objectId: policyId
1049
- });
1050
-
1051
- case 3:
1052
- libraryId = _context12.sent;
1053
- _context12.next = 6;
1054
- return this.client.ContentObjectMetadata({
1055
- libraryId: libraryId,
1056
- objectId: policyId,
1057
- writeToken: policyWriteToken,
1058
- metadataSubtree: UrlJoin("auth_policy_spec", itemId, "permissions")
1059
- });
1060
-
1061
- case 6:
1062
- _context12.t0 = _context12.sent;
1063
-
1064
- if (_context12.t0) {
1065
- _context12.next = 9;
1066
- break;
1067
- }
1068
-
1069
- _context12.t0 = [];
1070
-
1071
- case 9:
1072
- permissions = _context12.t0;
1073
- _context12.next = 12;
1074
- return Promise.all(permissions.map( /*#__PURE__*/function () {
1075
- var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(permission) {
1076
- return _regeneratorRuntime.wrap(function _callee11$(_context11) {
1077
- while (1) {
1078
- switch (_context11.prev = _context11.next) {
1079
- case 0:
1080
- _context11.next = 2;
1081
- return _this3.FormatPermission({
1082
- policyId: policyId,
1083
- policyWriteToken: policyWriteToken,
1084
- permission: permission
1085
- });
1086
-
1087
- case 2:
1088
- return _context11.abrupt("return", _context11.sent);
1089
-
1090
- case 3:
1091
- case "end":
1092
- return _context11.stop();
1093
- }
1094
- }
1095
- }, _callee11);
1096
- }));
1097
-
1098
- return function (_x12) {
1099
- return _ref12.apply(this, arguments);
1100
- };
1101
- }()));
1102
-
1103
- case 12:
1104
- return _context12.abrupt("return", _context12.sent);
1105
-
1106
- case 13:
1107
- case "end":
1108
- return _context12.stop();
1109
- }
885
+ while (1) switch (_context12.prev = _context12.next) {
886
+ case 0:
887
+ policyId = _ref11.policyId, policyWriteToken = _ref11.policyWriteToken, itemId = _ref11.itemId;
888
+ _context12.next = 3;
889
+ return this.client.ContentObjectLibraryId({
890
+ objectId: policyId
891
+ });
892
+ case 3:
893
+ libraryId = _context12.sent;
894
+ _context12.next = 6;
895
+ return this.client.ContentObjectMetadata({
896
+ libraryId: libraryId,
897
+ objectId: policyId,
898
+ writeToken: policyWriteToken,
899
+ metadataSubtree: UrlJoin("auth_policy_spec", itemId, "permissions")
900
+ });
901
+ case 6:
902
+ _context12.t0 = _context12.sent;
903
+ if (_context12.t0) {
904
+ _context12.next = 9;
905
+ break;
906
+ }
907
+ _context12.t0 = [];
908
+ case 9:
909
+ permissions = _context12.t0;
910
+ _context12.next = 12;
911
+ return Promise.all(permissions.map( /*#__PURE__*/function () {
912
+ var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(permission) {
913
+ return _regeneratorRuntime.wrap(function _callee11$(_context11) {
914
+ while (1) switch (_context11.prev = _context11.next) {
915
+ case 0:
916
+ _context11.next = 2;
917
+ return _this3.FormatPermission({
918
+ policyId: policyId,
919
+ policyWriteToken: policyWriteToken,
920
+ permission: permission
921
+ });
922
+ case 2:
923
+ return _context11.abrupt("return", _context11.sent);
924
+ case 3:
925
+ case "end":
926
+ return _context11.stop();
927
+ }
928
+ }, _callee11);
929
+ }));
930
+ return function (_x12) {
931
+ return _ref12.apply(this, arguments);
932
+ };
933
+ }()));
934
+ case 12:
935
+ return _context12.abrupt("return", _context12.sent);
936
+ case 13:
937
+ case "end":
938
+ return _context12.stop();
1110
939
  }
1111
940
  }, _callee12, this);
1112
941
  }));
1113
-
1114
942
  function ItemPermissions(_x11) {
1115
943
  return _ItemPermissions.apply(this, arguments);
1116
944
  }
1117
-
1118
945
  return ItemPermissions;
1119
946
  }()
1120
947
  /**
@@ -1134,355 +961,293 @@ var PermissionsClient = /*#__PURE__*/function () {
1134
961
  * @param {string | number} start - The start time for the permission
1135
962
  * @param {string | number} end - The end time for the permission
1136
963
  */
1137
-
1138
964
  }, {
1139
965
  key: "SetPermission",
1140
966
  value: function () {
1141
967
  var _SetPermission = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(_ref13) {
1142
968
  var policyId, policyWriteToken, itemId, _ref13$subjectSource, subjectSource, _ref13$subjectType, subjectType, subjectName, subjectId, subjectNTPId, profileName, start, end, offlineDraft, policyLibraryId, existingPermissions, index, permissionSpec, subjectInfo, newMeta, userInfo, _newMeta, _userInfo;
1143
-
1144
969
  return _regeneratorRuntime.wrap(function _callee13$(_context13) {
1145
- while (1) {
1146
- switch (_context13.prev = _context13.next) {
1147
- case 0:
1148
- policyId = _ref13.policyId, policyWriteToken = _ref13.policyWriteToken, itemId = _ref13.itemId, _ref13$subjectSource = _ref13.subjectSource, subjectSource = _ref13$subjectSource === void 0 ? "fabric" : _ref13$subjectSource, _ref13$subjectType = _ref13.subjectType, subjectType = _ref13$subjectType === void 0 ? "group" : _ref13$subjectType, subjectName = _ref13.subjectName, subjectId = _ref13.subjectId, subjectNTPId = _ref13.subjectNTPId, profileName = _ref13.profileName, start = _ref13.start, end = _ref13.end;
1149
- ValidatePresence("policyId", policyId);
1150
- ValidatePresence("policyWriteToken", policyWriteToken);
1151
- ValidatePresence("itemId", itemId);
1152
- ValidatePresence("subjectType", subjectType);
1153
- ValidatePresence("subjectSource", subjectSource);
1154
- ValidatePresence("subjectId", subjectId);
1155
- ValidatePresence("profileName", profileName);
1156
- start = this.FormatDate(start);
1157
- end = this.FormatDate(end); // Check if we have an open offline draft for this policy
1158
-
1159
- offlineDraft = this.offline && this.drafts[policyId] != null;
1160
- policyLibraryId = null;
1161
-
1162
- if (offlineDraft) {
1163
- _context13.next = 16;
1164
- break;
1165
- }
1166
-
1167
- _context13.next = 15;
1168
- return this.client.ContentObjectLibraryId({
1169
- objectId: policyId
1170
- });
1171
-
1172
- case 15:
1173
- policyLibraryId = _context13.sent;
1174
-
1175
- case 16:
1176
- // Allow address to be passed in for fabric subjects, though spec requires iusr/igrp hash
1177
- if (subjectSource === "fabric") {
1178
- if (subjectType === "group") {
1179
- if (!subjectId.startsWith("igrp")) {
1180
- subjectId = "igrp".concat(this.client.utils.AddressToHash(subjectId));
1181
- }
1182
- } else if (subjectType === "user") {
1183
- if (!subjectId.startsWith("iusr")) {
1184
- subjectId = "iusr".concat(this.client.utils.AddressToHash(subjectId));
1185
- }
1186
- }
1187
- }
1188
-
1189
- if (!offlineDraft) {
1190
- _context13.next = 21;
1191
- break;
1192
- }
1193
-
1194
- existingPermissions = this.drafts[policyId].meta["auth_policy_spec"][itemId];
1195
- _context13.next = 24;
970
+ while (1) switch (_context13.prev = _context13.next) {
971
+ case 0:
972
+ policyId = _ref13.policyId, policyWriteToken = _ref13.policyWriteToken, itemId = _ref13.itemId, _ref13$subjectSource = _ref13.subjectSource, subjectSource = _ref13$subjectSource === void 0 ? "fabric" : _ref13$subjectSource, _ref13$subjectType = _ref13.subjectType, subjectType = _ref13$subjectType === void 0 ? "group" : _ref13$subjectType, subjectName = _ref13.subjectName, subjectId = _ref13.subjectId, subjectNTPId = _ref13.subjectNTPId, profileName = _ref13.profileName, start = _ref13.start, end = _ref13.end;
973
+ ValidatePresence("policyId", policyId);
974
+ ValidatePresence("policyWriteToken", policyWriteToken);
975
+ ValidatePresence("itemId", itemId);
976
+ ValidatePresence("subjectType", subjectType);
977
+ ValidatePresence("subjectSource", subjectSource);
978
+ ValidatePresence("subjectId", subjectId);
979
+ ValidatePresence("profileName", profileName);
980
+ start = this.FormatDate(start);
981
+ end = this.FormatDate(end);
982
+
983
+ // Check if we have an open offline draft for this policy
984
+ offlineDraft = this.offline && this.drafts[policyId] != null;
985
+ policyLibraryId = null;
986
+ if (offlineDraft) {
987
+ _context13.next = 16;
1196
988
  break;
1197
-
1198
- case 21:
1199
- _context13.next = 23;
1200
- return this.client.ContentObjectMetadata({
1201
- libraryId: policyLibraryId,
1202
- objectId: policyId,
1203
- writeToken: policyWriteToken,
1204
- metadataSubtree: UrlJoin("auth_policy_spec", itemId)
1205
- });
1206
-
1207
- case 23:
1208
- existingPermissions = _context13.sent;
1209
-
1210
- case 24:
1211
- if (existingPermissions) {
1212
- _context13.next = 26;
1213
- break;
1214
- }
1215
-
1216
- throw Error("Unable to add permissions to uninitialized item");
1217
-
1218
- case 26:
1219
- if (existingPermissions.profiles[profileName]) {
1220
- _context13.next = 28;
1221
- break;
1222
- }
1223
-
1224
- throw Error("Profile '".concat(profileName, "' does not exist"));
1225
-
1226
- case 28:
1227
- index = existingPermissions.permissions.findIndex(function (permission) {
1228
- if (subjectSource === "fabric") {
1229
- return permission.subject.id === subjectId;
1230
- } else {
1231
- return permission.subject.oauth_id === subjectId;
989
+ }
990
+ _context13.next = 15;
991
+ return this.client.ContentObjectLibraryId({
992
+ objectId: policyId
993
+ });
994
+ case 15:
995
+ policyLibraryId = _context13.sent;
996
+ case 16:
997
+ // Allow address to be passed in for fabric subjects, though spec requires iusr/igrp hash
998
+ if (subjectSource === "fabric") {
999
+ if (subjectType === "group") {
1000
+ if (!subjectId.startsWith("igrp")) {
1001
+ subjectId = "igrp".concat(this.client.utils.AddressToHash(subjectId));
1002
+ }
1003
+ } else if (subjectType === "user") {
1004
+ if (!subjectId.startsWith("iusr")) {
1005
+ subjectId = "iusr".concat(this.client.utils.AddressToHash(subjectId));
1232
1006
  }
1233
- });
1234
-
1235
- if (index < 0) {
1236
- index = existingPermissions.permissions.length;
1237
- }
1238
-
1239
- permissionSpec = {
1240
- profile: profileName
1241
- };
1242
-
1243
- if (start) {
1244
- permissionSpec.start = start;
1245
- }
1246
-
1247
- if (end) {
1248
- permissionSpec.end = end;
1249
- }
1250
-
1251
- if (!(subjectSource === "fabric")) {
1252
- _context13.next = 53;
1253
- break;
1254
- }
1255
-
1256
- if (!(subjectType === "group")) {
1257
- _context13.next = 38;
1258
- break;
1259
1007
  }
1260
-
1261
- subjectInfo = {
1262
- id: subjectId,
1263
- type: "group"
1264
- };
1265
- _context13.next = 51;
1008
+ }
1009
+ if (!offlineDraft) {
1010
+ _context13.next = 21;
1266
1011
  break;
1267
-
1268
- case 38:
1269
- if (!(subjectType === "user")) {
1270
- _context13.next = 42;
1271
- break;
1272
- }
1273
-
1274
- subjectInfo = {
1275
- id: subjectId,
1276
- type: "user"
1277
- };
1278
- _context13.next = 51;
1012
+ }
1013
+ existingPermissions = this.drafts[policyId].meta["auth_policy_spec"][itemId];
1014
+ _context13.next = 24;
1015
+ break;
1016
+ case 21:
1017
+ _context13.next = 23;
1018
+ return this.client.ContentObjectMetadata({
1019
+ libraryId: policyLibraryId,
1020
+ objectId: policyId,
1021
+ writeToken: policyWriteToken,
1022
+ metadataSubtree: UrlJoin("auth_policy_spec", itemId)
1023
+ });
1024
+ case 23:
1025
+ existingPermissions = _context13.sent;
1026
+ case 24:
1027
+ if (existingPermissions) {
1028
+ _context13.next = 26;
1279
1029
  break;
1280
-
1281
- case 42:
1282
- if (!(subjectType === "ntp")) {
1283
- _context13.next = 46;
1284
- break;
1285
- }
1286
-
1287
- subjectInfo = {
1288
- id: subjectId,
1289
- type: "otp"
1290
- };
1291
- _context13.next = 51;
1030
+ }
1031
+ throw Error("Unable to add permissions to uninitialized item");
1032
+ case 26:
1033
+ if (existingPermissions.profiles[profileName]) {
1034
+ _context13.next = 28;
1292
1035
  break;
1293
-
1294
- case 46:
1295
- if (!(subjectType === "ntp_subject")) {
1296
- _context13.next = 50;
1297
- break;
1036
+ }
1037
+ throw Error("Profile '".concat(profileName, "' does not exist"));
1038
+ case 28:
1039
+ index = existingPermissions.permissions.findIndex(function (permission) {
1040
+ if (subjectSource === "fabric") {
1041
+ return permission.subject.id === subjectId;
1042
+ } else {
1043
+ return permission.subject.oauth_id === subjectId;
1298
1044
  }
1299
-
1300
- subjectInfo = {
1301
- id: subjectId,
1302
- otp_id: subjectNTPId,
1303
- type: "otp_subject"
1304
- };
1305
- _context13.next = 51;
1045
+ });
1046
+ if (index < 0) {
1047
+ index = existingPermissions.permissions.length;
1048
+ }
1049
+ permissionSpec = {
1050
+ profile: profileName
1051
+ };
1052
+ if (start) {
1053
+ permissionSpec.start = start;
1054
+ }
1055
+ if (end) {
1056
+ permissionSpec.end = end;
1057
+ }
1058
+ if (!(subjectSource === "fabric")) {
1059
+ _context13.next = 53;
1306
1060
  break;
1307
-
1308
- case 50:
1309
- throw Error("Invalid subject type: ".concat(subjectType));
1310
-
1311
- case 51:
1312
- _context13.next = 66;
1061
+ }
1062
+ if (!(subjectType === "group")) {
1063
+ _context13.next = 38;
1313
1064
  break;
1314
-
1315
- case 53:
1316
- if (!(subjectSource === "oauth")) {
1317
- _context13.next = 65;
1318
- break;
1319
- }
1320
-
1321
- if (!(subjectType === "group")) {
1322
- _context13.next = 58;
1323
- break;
1324
- }
1325
-
1326
- subjectInfo = {
1327
- id: subjectName,
1328
- oauth_id: subjectId,
1329
- type: "oauth_group"
1330
- };
1331
- _context13.next = 63;
1065
+ }
1066
+ subjectInfo = {
1067
+ id: subjectId,
1068
+ type: "group"
1069
+ };
1070
+ _context13.next = 51;
1071
+ break;
1072
+ case 38:
1073
+ if (!(subjectType === "user")) {
1074
+ _context13.next = 42;
1332
1075
  break;
1333
-
1334
- case 58:
1335
- if (!(subjectType === "user")) {
1336
- _context13.next = 62;
1337
- break;
1338
- }
1339
-
1340
- subjectInfo = {
1341
- id: subjectName,
1342
- oauth_id: subjectId,
1343
- type: "oauth_user"
1344
- };
1345
- _context13.next = 63;
1076
+ }
1077
+ subjectInfo = {
1078
+ id: subjectId,
1079
+ type: "user"
1080
+ };
1081
+ _context13.next = 51;
1082
+ break;
1083
+ case 42:
1084
+ if (!(subjectType === "ntp")) {
1085
+ _context13.next = 46;
1346
1086
  break;
1347
-
1348
- case 62:
1349
- throw Error("Invalid subject type: ".concat(subjectType));
1350
-
1351
- case 63:
1352
- _context13.next = 66;
1087
+ }
1088
+ subjectInfo = {
1089
+ id: subjectId,
1090
+ type: "otp"
1091
+ };
1092
+ _context13.next = 51;
1093
+ break;
1094
+ case 46:
1095
+ if (!(subjectType === "ntp_subject")) {
1096
+ _context13.next = 50;
1353
1097
  break;
1354
-
1355
- case 65:
1356
- throw Error("Invalid subject source: ".concat(subjectSource));
1357
-
1358
- case 66:
1359
- permissionSpec.subject = subjectInfo;
1360
- existingPermissions.permissions[index] = permissionSpec;
1361
-
1362
- if (offlineDraft) {
1363
- _context13.next = 71;
1364
- break;
1365
- }
1366
-
1098
+ }
1099
+ subjectInfo = {
1100
+ id: subjectId,
1101
+ otp_id: subjectNTPId,
1102
+ type: "otp_subject"
1103
+ };
1104
+ _context13.next = 51;
1105
+ break;
1106
+ case 50:
1107
+ throw Error("Invalid subject type: ".concat(subjectType));
1108
+ case 51:
1109
+ _context13.next = 66;
1110
+ break;
1111
+ case 53:
1112
+ if (!(subjectSource === "oauth")) {
1113
+ _context13.next = 65;
1114
+ break;
1115
+ }
1116
+ if (!(subjectType === "group")) {
1117
+ _context13.next = 58;
1118
+ break;
1119
+ }
1120
+ subjectInfo = {
1121
+ id: subjectName,
1122
+ oauth_id: subjectId,
1123
+ type: "oauth_group"
1124
+ };
1125
+ _context13.next = 63;
1126
+ break;
1127
+ case 58:
1128
+ if (!(subjectType === "user")) {
1129
+ _context13.next = 62;
1130
+ break;
1131
+ }
1132
+ subjectInfo = {
1133
+ id: subjectName,
1134
+ oauth_id: subjectId,
1135
+ type: "oauth_user"
1136
+ };
1137
+ _context13.next = 63;
1138
+ break;
1139
+ case 62:
1140
+ throw Error("Invalid subject type: ".concat(subjectType));
1141
+ case 63:
1142
+ _context13.next = 66;
1143
+ break;
1144
+ case 65:
1145
+ throw Error("Invalid subject source: ".concat(subjectSource));
1146
+ case 66:
1147
+ permissionSpec.subject = subjectInfo;
1148
+ existingPermissions.permissions[index] = permissionSpec;
1149
+ if (offlineDraft) {
1367
1150
  _context13.next = 71;
1368
- return this.client.ReplaceMetadata({
1369
- libraryId: policyLibraryId,
1370
- objectId: policyId,
1371
- writeToken: policyWriteToken,
1372
- metadataSubtree: UrlJoin("auth_policy_spec", itemId, "permissions"),
1373
- metadata: existingPermissions.permissions
1374
- });
1375
-
1376
- case 71:
1377
- if (!(subjectSource === "fabric" && subjectType === "user")) {
1378
- _context13.next = 85;
1379
- break;
1380
- }
1381
-
1382
- newMeta = {
1383
- address: this.client.utils.HashToAddress(subjectId),
1384
- name: subjectName
1385
- };
1386
-
1387
- if (!offlineDraft) {
1388
- _context13.next = 77;
1389
- break;
1390
- }
1391
-
1392
- this.drafts[policyId].meta["auth_policy_settings"]["fabric_users"][this.client.utils.HashToAddress(subjectId)] = newMeta;
1393
- _context13.next = 83;
1394
1151
  break;
1395
-
1396
- case 77:
1397
- _context13.next = 79;
1398
- return this.client.ContentObjectMetadata({
1399
- libraryId: policyLibraryId,
1400
- objectId: policyId,
1401
- writeToken: policyWriteToken,
1402
- metadataSubtree: UrlJoin("auth_policy_settings", "fabric_users", this.client.utils.HashToAddress(subjectId))
1403
- });
1404
-
1405
- case 79:
1406
- userInfo = _context13.sent;
1407
-
1408
- if (userInfo) {
1409
- _context13.next = 83;
1410
- break;
1411
- }
1412
-
1152
+ }
1153
+ _context13.next = 71;
1154
+ return this.client.ReplaceMetadata({
1155
+ libraryId: policyLibraryId,
1156
+ objectId: policyId,
1157
+ writeToken: policyWriteToken,
1158
+ metadataSubtree: UrlJoin("auth_policy_spec", itemId, "permissions"),
1159
+ metadata: existingPermissions.permissions
1160
+ });
1161
+ case 71:
1162
+ if (!(subjectSource === "fabric" && subjectType === "user")) {
1163
+ _context13.next = 85;
1164
+ break;
1165
+ }
1166
+ newMeta = {
1167
+ address: this.client.utils.HashToAddress(subjectId),
1168
+ name: subjectName
1169
+ };
1170
+ if (!offlineDraft) {
1171
+ _context13.next = 77;
1172
+ break;
1173
+ }
1174
+ this.drafts[policyId].meta["auth_policy_settings"]["fabric_users"][this.client.utils.HashToAddress(subjectId)] = newMeta;
1175
+ _context13.next = 83;
1176
+ break;
1177
+ case 77:
1178
+ _context13.next = 79;
1179
+ return this.client.ContentObjectMetadata({
1180
+ libraryId: policyLibraryId,
1181
+ objectId: policyId,
1182
+ writeToken: policyWriteToken,
1183
+ metadataSubtree: UrlJoin("auth_policy_settings", "fabric_users", this.client.utils.HashToAddress(subjectId))
1184
+ });
1185
+ case 79:
1186
+ userInfo = _context13.sent;
1187
+ if (userInfo) {
1413
1188
  _context13.next = 83;
1414
- return this.client.ReplaceMetadata({
1415
- libraryId: policyLibraryId,
1416
- objectId: policyId,
1417
- writeToken: policyWriteToken,
1418
- metadataSubtree: UrlJoin("auth_policy_settings", "fabric_users", this.client.utils.HashToAddress(subjectId)),
1419
- metadata: newMeta
1420
- });
1421
-
1422
- case 83:
1423
- _context13.next = 97;
1424
1189
  break;
1425
-
1426
- case 85:
1427
- if (!(subjectSource === "fabric" && subjectType === "ntp")) {
1428
- _context13.next = 97;
1429
- break;
1430
- }
1431
-
1432
- _newMeta = {
1433
- address: subjectId,
1434
- ntpId: subjectId,
1435
- name: subjectName,
1436
- type: "ntpInstance"
1437
- };
1438
-
1439
- if (!offlineDraft) {
1440
- _context13.next = 91;
1441
- break;
1442
- }
1443
-
1444
- this.drafts[policyId].meta["auth_policy_settings"]["ntp_instances"][subjectId] = _newMeta;
1190
+ }
1191
+ _context13.next = 83;
1192
+ return this.client.ReplaceMetadata({
1193
+ libraryId: policyLibraryId,
1194
+ objectId: policyId,
1195
+ writeToken: policyWriteToken,
1196
+ metadataSubtree: UrlJoin("auth_policy_settings", "fabric_users", this.client.utils.HashToAddress(subjectId)),
1197
+ metadata: newMeta
1198
+ });
1199
+ case 83:
1200
+ _context13.next = 97;
1201
+ break;
1202
+ case 85:
1203
+ if (!(subjectSource === "fabric" && subjectType === "ntp")) {
1445
1204
  _context13.next = 97;
1446
1205
  break;
1447
-
1448
- case 91:
1449
- _context13.next = 93;
1450
- return this.client.ContentObjectMetadata({
1451
- libraryId: policyLibraryId,
1452
- objectId: policyId,
1453
- writeToken: policyWriteToken,
1454
- metadataSubtree: UrlJoin("auth_policy_settings", "ntp_instances", subjectId)
1455
- });
1456
-
1457
- case 93:
1458
- _userInfo = _context13.sent;
1459
-
1460
- if (_userInfo) {
1461
- _context13.next = 97;
1462
- break;
1463
- }
1464
-
1206
+ }
1207
+ _newMeta = {
1208
+ address: subjectId,
1209
+ ntpId: subjectId,
1210
+ name: subjectName,
1211
+ type: "ntpInstance"
1212
+ };
1213
+ if (!offlineDraft) {
1214
+ _context13.next = 91;
1215
+ break;
1216
+ }
1217
+ this.drafts[policyId].meta["auth_policy_settings"]["ntp_instances"][subjectId] = _newMeta;
1218
+ _context13.next = 97;
1219
+ break;
1220
+ case 91:
1221
+ _context13.next = 93;
1222
+ return this.client.ContentObjectMetadata({
1223
+ libraryId: policyLibraryId,
1224
+ objectId: policyId,
1225
+ writeToken: policyWriteToken,
1226
+ metadataSubtree: UrlJoin("auth_policy_settings", "ntp_instances", subjectId)
1227
+ });
1228
+ case 93:
1229
+ _userInfo = _context13.sent;
1230
+ if (_userInfo) {
1465
1231
  _context13.next = 97;
1466
- return this.client.ReplaceMetadata({
1467
- libraryId: policyLibraryId,
1468
- objectId: policyId,
1469
- writeToken: policyWriteToken,
1470
- metadataSubtree: UrlJoin("auth_policy_settings", "ntp_instances", subjectId),
1471
- metadata: _newMeta
1472
- });
1473
-
1474
- case 97:
1475
- case "end":
1476
- return _context13.stop();
1477
- }
1232
+ break;
1233
+ }
1234
+ _context13.next = 97;
1235
+ return this.client.ReplaceMetadata({
1236
+ libraryId: policyLibraryId,
1237
+ objectId: policyId,
1238
+ writeToken: policyWriteToken,
1239
+ metadataSubtree: UrlJoin("auth_policy_settings", "ntp_instances", subjectId),
1240
+ metadata: _newMeta
1241
+ });
1242
+ case 97:
1243
+ case "end":
1244
+ return _context13.stop();
1478
1245
  }
1479
1246
  }, _callee13, this);
1480
1247
  }));
1481
-
1482
1248
  function SetPermission(_x13) {
1483
1249
  return _SetPermission.apply(this, arguments);
1484
1250
  }
1485
-
1486
1251
  return SetPermission;
1487
1252
  }()
1488
1253
  /**
@@ -1495,121 +1260,98 @@ var PermissionsClient = /*#__PURE__*/function () {
1495
1260
  * @param {string} itemId - Object ID of the item
1496
1261
  * @param {string} subjectId - The ID of the subject
1497
1262
  */
1498
-
1499
1263
  }, {
1500
1264
  key: "RemovePermission",
1501
1265
  value: function () {
1502
1266
  var _RemovePermission = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(_ref14) {
1503
1267
  var _this4 = this;
1504
-
1505
1268
  var policyId, policyWriteToken, itemId, subjectId, policyLibraryId, permissions, id;
1506
1269
  return _regeneratorRuntime.wrap(function _callee15$(_context15) {
1507
- while (1) {
1508
- switch (_context15.prev = _context15.next) {
1509
- case 0:
1510
- policyId = _ref14.policyId, policyWriteToken = _ref14.policyWriteToken, itemId = _ref14.itemId, subjectId = _ref14.subjectId;
1511
- ValidatePresence("policyId", policyId);
1512
- ValidatePresence("policyWriteToken", policyWriteToken);
1513
- ValidatePresence("itemId", itemId);
1514
- ValidatePresence("subjectId", subjectId);
1515
- _context15.next = 7;
1516
- return this.client.ContentObjectLibraryId({
1517
- objectId: policyId
1518
- });
1519
-
1520
- case 7:
1521
- policyLibraryId = _context15.sent;
1522
- _context15.next = 10;
1523
- return this.client.ContentObjectMetadata({
1524
- libraryId: policyLibraryId,
1525
- objectId: policyId,
1526
- writeToken: policyWriteToken,
1527
- metadataSubtree: UrlJoin("auth_policy_spec", itemId, "permissions")
1528
- });
1529
-
1530
- case 10:
1531
- permissions = _context15.sent;
1532
-
1533
- if (permissions) {
1534
- _context15.next = 13;
1535
- break;
1536
- }
1537
-
1538
- return _context15.abrupt("return");
1539
-
1540
- case 13:
1541
- if (!subjectId.startsWith("0x")) {
1542
- _context15.next = 23;
1543
- break;
1544
- }
1545
-
1546
- id = this.client.utils.AddressToObjectId(subjectId);
1547
- _context15.next = 17;
1548
- return this.client.AccessType({
1549
- id: id
1550
- });
1551
-
1552
- case 17:
1553
- _context15.t0 = _context15.sent;
1554
-
1555
- if (!(_context15.t0 === "group")) {
1556
- _context15.next = 22;
1557
- break;
1558
- }
1559
-
1560
- subjectId = "igrp".concat(this.client.utils.AddressToHash(subjectId));
1270
+ while (1) switch (_context15.prev = _context15.next) {
1271
+ case 0:
1272
+ policyId = _ref14.policyId, policyWriteToken = _ref14.policyWriteToken, itemId = _ref14.itemId, subjectId = _ref14.subjectId;
1273
+ ValidatePresence("policyId", policyId);
1274
+ ValidatePresence("policyWriteToken", policyWriteToken);
1275
+ ValidatePresence("itemId", itemId);
1276
+ ValidatePresence("subjectId", subjectId);
1277
+ _context15.next = 7;
1278
+ return this.client.ContentObjectLibraryId({
1279
+ objectId: policyId
1280
+ });
1281
+ case 7:
1282
+ policyLibraryId = _context15.sent;
1283
+ _context15.next = 10;
1284
+ return this.client.ContentObjectMetadata({
1285
+ libraryId: policyLibraryId,
1286
+ objectId: policyId,
1287
+ writeToken: policyWriteToken,
1288
+ metadataSubtree: UrlJoin("auth_policy_spec", itemId, "permissions")
1289
+ });
1290
+ case 10:
1291
+ permissions = _context15.sent;
1292
+ if (permissions) {
1293
+ _context15.next = 13;
1294
+ break;
1295
+ }
1296
+ return _context15.abrupt("return");
1297
+ case 13:
1298
+ if (!subjectId.startsWith("0x")) {
1561
1299
  _context15.next = 23;
1562
1300
  break;
1563
-
1564
- case 22:
1565
- subjectId = "iusr".concat(this.client.utils.AddressToHash(subjectId));
1566
-
1567
- case 23:
1568
- _context15.next = 25;
1569
- return Promise.all(permissions.map( /*#__PURE__*/function () {
1570
- var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(permission, index) {
1571
- return _regeneratorRuntime.wrap(function _callee14$(_context14) {
1572
- while (1) {
1573
- switch (_context14.prev = _context14.next) {
1574
- case 0:
1575
- if (!(permission.subject.id === subjectId || permission.subject.oauth_id === subjectId)) {
1576
- _context14.next = 3;
1577
- break;
1578
- }
1579
-
1580
- _context14.next = 3;
1581
- return _this4.client.DeleteMetadata({
1582
- libraryId: policyLibraryId,
1583
- objectId: policyId,
1584
- writeToken: policyWriteToken,
1585
- metadataSubtree: UrlJoin("auth_policy_spec", itemId, "permissions", index.toString())
1586
- });
1587
-
1588
- case 3:
1589
- case "end":
1590
- return _context14.stop();
1301
+ }
1302
+ id = this.client.utils.AddressToObjectId(subjectId);
1303
+ _context15.next = 17;
1304
+ return this.client.AccessType({
1305
+ id: id
1306
+ });
1307
+ case 17:
1308
+ _context15.t0 = _context15.sent;
1309
+ if (!(_context15.t0 === "group")) {
1310
+ _context15.next = 22;
1311
+ break;
1312
+ }
1313
+ subjectId = "igrp".concat(this.client.utils.AddressToHash(subjectId));
1314
+ _context15.next = 23;
1315
+ break;
1316
+ case 22:
1317
+ subjectId = "iusr".concat(this.client.utils.AddressToHash(subjectId));
1318
+ case 23:
1319
+ _context15.next = 25;
1320
+ return Promise.all(permissions.map( /*#__PURE__*/function () {
1321
+ var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(permission, index) {
1322
+ return _regeneratorRuntime.wrap(function _callee14$(_context14) {
1323
+ while (1) switch (_context14.prev = _context14.next) {
1324
+ case 0:
1325
+ if (!(permission.subject.id === subjectId || permission.subject.oauth_id === subjectId)) {
1326
+ _context14.next = 3;
1327
+ break;
1591
1328
  }
1592
- }
1593
- }, _callee14);
1594
- }));
1595
-
1596
- return function (_x15, _x16) {
1597
- return _ref15.apply(this, arguments);
1598
- };
1599
- }()));
1600
-
1601
- case 25:
1602
- case "end":
1603
- return _context15.stop();
1604
- }
1329
+ _context14.next = 3;
1330
+ return _this4.client.DeleteMetadata({
1331
+ libraryId: policyLibraryId,
1332
+ objectId: policyId,
1333
+ writeToken: policyWriteToken,
1334
+ metadataSubtree: UrlJoin("auth_policy_spec", itemId, "permissions", index.toString())
1335
+ });
1336
+ case 3:
1337
+ case "end":
1338
+ return _context14.stop();
1339
+ }
1340
+ }, _callee14);
1341
+ }));
1342
+ return function (_x15, _x16) {
1343
+ return _ref15.apply(this, arguments);
1344
+ };
1345
+ }()));
1346
+ case 25:
1347
+ case "end":
1348
+ return _context15.stop();
1605
1349
  }
1606
1350
  }, _callee15, this);
1607
1351
  }));
1608
-
1609
1352
  function RemovePermission(_x14) {
1610
1353
  return _RemovePermission.apply(this, arguments);
1611
1354
  }
1612
-
1613
1355
  return RemovePermission;
1614
1356
  }()
1615
1357
  /**
@@ -1623,139 +1365,113 @@ var PermissionsClient = /*#__PURE__*/function () {
1623
1365
  *
1624
1366
  * @returns {Object} - All permissions pertaining to the given subject. Format of result for each item is identical to the format of `ItemPolicy`
1625
1367
  */
1626
-
1627
1368
  }, {
1628
1369
  key: "SubjectPermissions",
1629
1370
  value: function () {
1630
1371
  var _SubjectPermissions = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee17(_ref16) {
1631
1372
  var _this5 = this;
1632
-
1633
1373
  var policyId, policyWriteToken, subjectId, id, policyLibraryId, policy, allSubjectPermissions, _i, _Object$keys, itemId, itemPermissions, subjectPermissions;
1634
-
1635
1374
  return _regeneratorRuntime.wrap(function _callee17$(_context17) {
1636
- while (1) {
1637
- switch (_context17.prev = _context17.next) {
1638
- case 0:
1639
- policyId = _ref16.policyId, policyWriteToken = _ref16.policyWriteToken, subjectId = _ref16.subjectId;
1640
- ValidatePresence("policyId", policyId);
1641
- ValidatePresence("subjectId", subjectId); // Convert address to appropriate ID
1642
-
1643
- if (!subjectId.startsWith("0x")) {
1644
- _context17.next = 13;
1645
- break;
1646
- }
1647
-
1648
- id = this.client.utils.AddressToObjectId(subjectId);
1649
- _context17.next = 7;
1650
- return this.client.AccessType({
1651
- id: id
1652
- });
1653
-
1654
- case 7:
1655
- _context17.t0 = _context17.sent;
1656
-
1657
- if (!(_context17.t0 === "group")) {
1658
- _context17.next = 12;
1659
- break;
1660
- }
1661
-
1662
- subjectId = "igrp".concat(this.client.utils.AddressToHash(subjectId));
1375
+ while (1) switch (_context17.prev = _context17.next) {
1376
+ case 0:
1377
+ policyId = _ref16.policyId, policyWriteToken = _ref16.policyWriteToken, subjectId = _ref16.subjectId;
1378
+ ValidatePresence("policyId", policyId);
1379
+ ValidatePresence("subjectId", subjectId);
1380
+
1381
+ // Convert address to appropriate ID
1382
+ if (!subjectId.startsWith("0x")) {
1663
1383
  _context17.next = 13;
1664
1384
  break;
1665
-
1666
- case 12:
1667
- subjectId = "iusr".concat(this.client.utils.AddressToHash(subjectId));
1668
-
1669
- case 13:
1670
- _context17.next = 15;
1671
- return this.client.ContentObjectLibraryId({
1672
- objectId: policyId
1673
- });
1674
-
1675
- case 15:
1676
- policyLibraryId = _context17.sent;
1677
- _context17.next = 18;
1678
- return this.client.ContentObjectMetadata({
1679
- libraryId: policyLibraryId,
1680
- objectId: policyId,
1681
- writeToken: policyWriteToken,
1682
- metadataSubtree: UrlJoin("auth_policy_spec")
1683
- });
1684
-
1685
- case 18:
1686
- policy = _context17.sent;
1687
- allSubjectPermissions = {};
1688
- _i = 0, _Object$keys = Object.keys(policy);
1689
-
1690
- case 21:
1691
- if (!(_i < _Object$keys.length)) {
1692
- _context17.next = 31;
1693
- break;
1694
- }
1695
-
1696
- itemId = _Object$keys[_i];
1697
- itemPermissions = policy[itemId].permissions || [];
1698
- _context17.next = 26;
1699
- return Promise.all(itemPermissions.filter(function (permission) {
1700
- return (permission.subject || {}).oauth_id === subjectId || (permission.subject || {}).id === subjectId;
1701
- }).map( /*#__PURE__*/function () {
1702
- var _ref17 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16(permission) {
1703
- return _regeneratorRuntime.wrap(function _callee16$(_context16) {
1704
- while (1) {
1705
- switch (_context16.prev = _context16.next) {
1706
- case 0:
1707
- _context16.next = 2;
1708
- return _this5.FormatPermission({
1709
- policyId: policyId,
1710
- policyWriteToken: policyWriteToken,
1711
- permission: permission
1712
- });
1713
-
1714
- case 2:
1715
- return _context16.abrupt("return", _context16.sent);
1716
-
1717
- case 3:
1718
- case "end":
1719
- return _context16.stop();
1720
- }
1721
- }
1722
- }, _callee16);
1723
- }));
1724
-
1725
- return function (_x18) {
1726
- return _ref17.apply(this, arguments);
1727
- };
1728
- }()));
1729
-
1730
- case 26:
1731
- subjectPermissions = _context17.sent;
1732
-
1733
- if (subjectPermissions.length > 0) {
1734
- allSubjectPermissions[itemId] = _objectSpread(_objectSpread({}, policy[itemId]), {}, {
1735
- permissions: subjectPermissions
1736
- });
1737
- }
1738
-
1739
- case 28:
1740
- _i++;
1741
- _context17.next = 21;
1385
+ }
1386
+ id = this.client.utils.AddressToObjectId(subjectId);
1387
+ _context17.next = 7;
1388
+ return this.client.AccessType({
1389
+ id: id
1390
+ });
1391
+ case 7:
1392
+ _context17.t0 = _context17.sent;
1393
+ if (!(_context17.t0 === "group")) {
1394
+ _context17.next = 12;
1742
1395
  break;
1743
-
1744
- case 31:
1745
- return _context17.abrupt("return", allSubjectPermissions);
1746
-
1747
- case 32:
1748
- case "end":
1749
- return _context17.stop();
1750
- }
1396
+ }
1397
+ subjectId = "igrp".concat(this.client.utils.AddressToHash(subjectId));
1398
+ _context17.next = 13;
1399
+ break;
1400
+ case 12:
1401
+ subjectId = "iusr".concat(this.client.utils.AddressToHash(subjectId));
1402
+ case 13:
1403
+ _context17.next = 15;
1404
+ return this.client.ContentObjectLibraryId({
1405
+ objectId: policyId
1406
+ });
1407
+ case 15:
1408
+ policyLibraryId = _context17.sent;
1409
+ _context17.next = 18;
1410
+ return this.client.ContentObjectMetadata({
1411
+ libraryId: policyLibraryId,
1412
+ objectId: policyId,
1413
+ writeToken: policyWriteToken,
1414
+ metadataSubtree: UrlJoin("auth_policy_spec")
1415
+ });
1416
+ case 18:
1417
+ policy = _context17.sent;
1418
+ allSubjectPermissions = {};
1419
+ _i = 0, _Object$keys = Object.keys(policy);
1420
+ case 21:
1421
+ if (!(_i < _Object$keys.length)) {
1422
+ _context17.next = 31;
1423
+ break;
1424
+ }
1425
+ itemId = _Object$keys[_i];
1426
+ itemPermissions = policy[itemId].permissions || [];
1427
+ _context17.next = 26;
1428
+ return Promise.all(itemPermissions.filter(function (permission) {
1429
+ return (permission.subject || {}).oauth_id === subjectId || (permission.subject || {}).id === subjectId;
1430
+ }).map( /*#__PURE__*/function () {
1431
+ var _ref17 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16(permission) {
1432
+ return _regeneratorRuntime.wrap(function _callee16$(_context16) {
1433
+ while (1) switch (_context16.prev = _context16.next) {
1434
+ case 0:
1435
+ _context16.next = 2;
1436
+ return _this5.FormatPermission({
1437
+ policyId: policyId,
1438
+ policyWriteToken: policyWriteToken,
1439
+ permission: permission
1440
+ });
1441
+ case 2:
1442
+ return _context16.abrupt("return", _context16.sent);
1443
+ case 3:
1444
+ case "end":
1445
+ return _context16.stop();
1446
+ }
1447
+ }, _callee16);
1448
+ }));
1449
+ return function (_x18) {
1450
+ return _ref17.apply(this, arguments);
1451
+ };
1452
+ }()));
1453
+ case 26:
1454
+ subjectPermissions = _context17.sent;
1455
+ if (subjectPermissions.length > 0) {
1456
+ allSubjectPermissions[itemId] = _objectSpread(_objectSpread({}, policy[itemId]), {}, {
1457
+ permissions: subjectPermissions
1458
+ });
1459
+ }
1460
+ case 28:
1461
+ _i++;
1462
+ _context17.next = 21;
1463
+ break;
1464
+ case 31:
1465
+ return _context17.abrupt("return", allSubjectPermissions);
1466
+ case 32:
1467
+ case "end":
1468
+ return _context17.stop();
1751
1469
  }
1752
1470
  }, _callee17, this);
1753
1471
  }));
1754
-
1755
1472
  function SubjectPermissions(_x17) {
1756
1473
  return _SubjectPermissions.apply(this, arguments);
1757
1474
  }
1758
-
1759
1475
  return SubjectPermissions;
1760
1476
  }()
1761
1477
  /**
@@ -1767,76 +1483,62 @@ var PermissionsClient = /*#__PURE__*/function () {
1767
1483
  * @param {string} policyWriteToken - Write token for the policy
1768
1484
  * @param {string} subjectId - The ID of the subject
1769
1485
  */
1770
-
1771
1486
  }, {
1772
1487
  key: "RemoveSubjectPermissions",
1773
1488
  value: function () {
1774
1489
  var _RemoveSubjectPermissions = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee19(_ref18) {
1775
1490
  var _this6 = this;
1776
-
1777
1491
  var policyId, policyWriteToken, subjectId, subjectPermissions;
1778
1492
  return _regeneratorRuntime.wrap(function _callee19$(_context19) {
1779
- while (1) {
1780
- switch (_context19.prev = _context19.next) {
1781
- case 0:
1782
- policyId = _ref18.policyId, policyWriteToken = _ref18.policyWriteToken, subjectId = _ref18.subjectId;
1783
- ValidatePresence("policyId", policyId);
1784
- ValidatePresence("policyWriteToken", policyWriteToken);
1785
- ValidatePresence("subjectId", subjectId);
1786
- _context19.next = 6;
1787
- return this.SubjectPermissions({
1788
- policyId: policyId,
1789
- policyWriteToken: policyWriteToken,
1790
- subjectId: subjectId
1791
- });
1792
-
1793
- case 6:
1794
- subjectPermissions = _context19.sent;
1795
- _context19.next = 9;
1796
- return this.client.utils.LimitedMap(5, Object.keys(subjectPermissions), /*#__PURE__*/function () {
1797
- var _ref19 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee18(itemId) {
1798
- return _regeneratorRuntime.wrap(function _callee18$(_context18) {
1799
- while (1) {
1800
- switch (_context18.prev = _context18.next) {
1801
- case 0:
1802
- _context18.next = 2;
1803
- return _this6.RemovePermission({
1804
- policyId: policyId,
1805
- policyWriteToken: policyWriteToken,
1806
- subjectId: subjectId,
1807
- itemId: itemId
1808
- });
1809
-
1810
- case 2:
1811
- case "end":
1812
- return _context18.stop();
1813
- }
1814
- }
1815
- }, _callee18);
1816
- }));
1817
-
1818
- return function (_x20) {
1819
- return _ref19.apply(this, arguments);
1820
- };
1821
- }());
1822
-
1823
- case 9:
1824
- case "end":
1825
- return _context19.stop();
1826
- }
1493
+ while (1) switch (_context19.prev = _context19.next) {
1494
+ case 0:
1495
+ policyId = _ref18.policyId, policyWriteToken = _ref18.policyWriteToken, subjectId = _ref18.subjectId;
1496
+ ValidatePresence("policyId", policyId);
1497
+ ValidatePresence("policyWriteToken", policyWriteToken);
1498
+ ValidatePresence("subjectId", subjectId);
1499
+ _context19.next = 6;
1500
+ return this.SubjectPermissions({
1501
+ policyId: policyId,
1502
+ policyWriteToken: policyWriteToken,
1503
+ subjectId: subjectId
1504
+ });
1505
+ case 6:
1506
+ subjectPermissions = _context19.sent;
1507
+ _context19.next = 9;
1508
+ return this.client.utils.LimitedMap(5, Object.keys(subjectPermissions), /*#__PURE__*/function () {
1509
+ var _ref19 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee18(itemId) {
1510
+ return _regeneratorRuntime.wrap(function _callee18$(_context18) {
1511
+ while (1) switch (_context18.prev = _context18.next) {
1512
+ case 0:
1513
+ _context18.next = 2;
1514
+ return _this6.RemovePermission({
1515
+ policyId: policyId,
1516
+ policyWriteToken: policyWriteToken,
1517
+ subjectId: subjectId,
1518
+ itemId: itemId
1519
+ });
1520
+ case 2:
1521
+ case "end":
1522
+ return _context18.stop();
1523
+ }
1524
+ }, _callee18);
1525
+ }));
1526
+ return function (_x20) {
1527
+ return _ref19.apply(this, arguments);
1528
+ };
1529
+ }());
1530
+ case 9:
1531
+ case "end":
1532
+ return _context19.stop();
1827
1533
  }
1828
1534
  }, _callee19, this);
1829
1535
  }));
1830
-
1831
1536
  function RemoveSubjectPermissions(_x19) {
1832
1537
  return _RemoveSubjectPermissions.apply(this, arguments);
1833
1538
  }
1834
-
1835
1539
  return RemoveSubjectPermissions;
1836
1540
  }()
1837
1541
  }]);
1838
-
1839
1542
  return PermissionsClient;
1840
1543
  }();
1841
-
1842
1544
  module.exports = PermissionsClient;