@eluvio/elv-client-js 4.0.112 → 4.0.113

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 (124) hide show
  1. package/package.json +1 -1
  2. package/dist/ElvClient-min.js +0 -67
  3. package/dist/ElvClient-node-min.js +0 -66
  4. package/dist/ElvFrameClient-min.js +0 -60
  5. package/dist/ElvPermissionsClient-min.js +0 -60
  6. package/dist/ElvWalletClient-min.js +0 -67
  7. package/dist/ElvWalletClient-node-min.js +0 -66
  8. package/dist/src/AuthorizationClient.js +0 -2157
  9. package/dist/src/ContentObjectAudit.js +0 -175
  10. package/dist/src/ContentObjectVerification.js +0 -281
  11. package/dist/src/Crypto.js +0 -412
  12. package/dist/src/ElvClient.js +0 -2022
  13. package/dist/src/ElvWallet.js +0 -245
  14. package/dist/src/EthClient.js +0 -1154
  15. package/dist/src/FrameClient.js +0 -485
  16. package/dist/src/HttpClient.js +0 -315
  17. package/dist/src/Id.js +0 -21
  18. package/dist/src/LogMessage.js +0 -25
  19. package/dist/src/PermissionsClient.js +0 -1544
  20. package/dist/src/RemoteSigner.js +0 -385
  21. package/dist/src/UserProfileClient.js +0 -1450
  22. package/dist/src/Utils.js +0 -894
  23. package/dist/src/Validation.js +0 -121
  24. package/dist/src/abr_profiles/abr_profile_live_drm.js +0 -1661
  25. package/dist/src/abr_profiles/abr_profile_live_to_vod.js +0 -1606
  26. package/dist/src/client/ABRPublishing.js +0 -1018
  27. package/dist/src/client/AccessGroups.js +0 -1503
  28. package/dist/src/client/ContentAccess.js +0 -5173
  29. package/dist/src/client/ContentManagement.js +0 -2680
  30. package/dist/src/client/Contracts.js +0 -1520
  31. package/dist/src/client/Files.js +0 -2181
  32. package/dist/src/client/LiveConf.js +0 -567
  33. package/dist/src/client/LiveStream.js +0 -2638
  34. package/dist/src/client/NFT.js +0 -162
  35. package/dist/src/client/NTP.js +0 -581
  36. package/dist/src/contracts/v2/AccessIndexor.js +0 -831
  37. package/dist/src/contracts/v2/Accessible.js +0 -31
  38. package/dist/src/contracts/v2/BaseAccessControlGroup.js +0 -1263
  39. package/dist/src/contracts/v2/BaseAccessWallet.js +0 -1609
  40. package/dist/src/contracts/v2/BaseAccessWalletFactory.js +0 -93
  41. package/dist/src/contracts/v2/BaseContent.js +0 -1076
  42. package/dist/src/contracts/v2/BaseContentFactory.js +0 -219
  43. package/dist/src/contracts/v2/BaseContentSpace.js +0 -1352
  44. package/dist/src/contracts/v2/BaseContentType.js +0 -364
  45. package/dist/src/contracts/v2/BaseFactory.js +0 -107
  46. package/dist/src/contracts/v2/BaseGroupFactory.js +0 -93
  47. package/dist/src/contracts/v2/BaseLibrary.js +0 -1041
  48. package/dist/src/contracts/v2/BaseLibraryFactory.js +0 -96
  49. package/dist/src/contracts/v2/Certifyer.js +0 -86
  50. package/dist/src/contracts/v2/Container.js +0 -540
  51. package/dist/src/contracts/v2/Content.js +0 -443
  52. package/dist/src/contracts/v2/Editable.js +0 -306
  53. package/dist/src/contracts/v2/ExternalUserWallet.js +0 -379
  54. package/dist/src/contracts/v2/IFactorySpace.js +0 -57
  55. package/dist/src/contracts/v2/IKmsSpace.js +0 -52
  56. package/dist/src/contracts/v2/INodeSpace.js +0 -18
  57. package/dist/src/contracts/v2/IUserSpace.js +0 -18
  58. package/dist/src/contracts/v2/LvRecordableStream.js +0 -1037
  59. package/dist/src/contracts/v2/LvRecording.js +0 -627
  60. package/dist/src/contracts/v2/LvStreamRightsHolder.js +0 -562
  61. package/dist/src/contracts/v2/MetaObject.js +0 -119
  62. package/dist/src/contracts/v2/Node.js +0 -167
  63. package/dist/src/contracts/v2/NodeSpace.js +0 -273
  64. package/dist/src/contracts/v2/Ownable.js +0 -87
  65. package/dist/src/contracts/v2/PaymentService.js +0 -627
  66. package/dist/src/contracts/v2/Precompile.js +0 -15
  67. package/dist/src/contracts/v2/Transactable.js +0 -82
  68. package/dist/src/contracts/v2/UserSpace.js +0 -29
  69. package/dist/src/contracts/v2/Utils.js +0 -18
  70. package/dist/src/contracts/v2/Verifier.js +0 -53
  71. package/dist/src/contracts/v2/strings.js +0 -4
  72. package/dist/src/contracts/v3/AccessIndexor.js +0 -774
  73. package/dist/src/contracts/v3/Accessible.js +0 -232
  74. package/dist/src/contracts/v3/Adminable.js +0 -107
  75. package/dist/src/contracts/v3/AvailsDelivery.js +0 -586
  76. package/dist/src/contracts/v3/BaseAccessControlGroup.js +0 -1603
  77. package/dist/src/contracts/v3/BaseAccessWallet.js +0 -1628
  78. package/dist/src/contracts/v3/BaseAccessWalletFactory.js +0 -112
  79. package/dist/src/contracts/v3/BaseContent.js +0 -1312
  80. package/dist/src/contracts/v3/BaseContentFactory.js +0 -183
  81. package/dist/src/contracts/v3/BaseContentFactoryExt.js +0 -175
  82. package/dist/src/contracts/v3/BaseContentSpace.js +0 -1515
  83. package/dist/src/contracts/v3/BaseContentType.js +0 -527
  84. package/dist/src/contracts/v3/BaseFactory.js +0 -126
  85. package/dist/src/contracts/v3/BaseGroupFactory.js +0 -112
  86. package/dist/src/contracts/v3/BaseLibrary.js +0 -1204
  87. package/dist/src/contracts/v3/BaseLibraryFactory.js +0 -115
  88. package/dist/src/contracts/v3/BaseTenantSpace.js +0 -1587
  89. package/dist/src/contracts/v3/Certifyer.js +0 -86
  90. package/dist/src/contracts/v3/Container.js +0 -739
  91. package/dist/src/contracts/v3/Content.js +0 -438
  92. package/dist/src/contracts/v3/CounterObject.js +0 -243
  93. package/dist/src/contracts/v3/Editable.js +0 -519
  94. package/dist/src/contracts/v3/EncToken.js +0 -4
  95. package/dist/src/contracts/v3/ExternalUserWallet.js +0 -587
  96. package/dist/src/contracts/v3/IAdmin.js +0 -18
  97. package/dist/src/contracts/v3/IFactorySpace.js +0 -57
  98. package/dist/src/contracts/v3/IKmsSpace.js +0 -52
  99. package/dist/src/contracts/v3/INodeSpace.js +0 -18
  100. package/dist/src/contracts/v3/IUserSpace.js +0 -32
  101. package/dist/src/contracts/v3/LvRecordableStream.js +0 -1032
  102. package/dist/src/contracts/v3/LvRecording.js +0 -650
  103. package/dist/src/contracts/v3/LvStreamRightsHolder.js +0 -557
  104. package/dist/src/contracts/v3/MetaObject.js +0 -144
  105. package/dist/src/contracts/v3/Node.js +0 -178
  106. package/dist/src/contracts/v3/NodeSpace.js +0 -284
  107. package/dist/src/contracts/v3/Ownable.js +0 -98
  108. package/dist/src/contracts/v3/PaymentService.js +0 -622
  109. package/dist/src/contracts/v3/Precompile.js +0 -26
  110. package/dist/src/contracts/v3/TenantFuncsBase.js +0 -351
  111. package/dist/src/contracts/v3/Transactable.js +0 -82
  112. package/dist/src/contracts/v3/UserSpace.js +0 -43
  113. package/dist/src/contracts/v3/Utils.js +0 -18
  114. package/dist/src/contracts/v3/Verifier.js +0 -53
  115. package/dist/src/contracts/v3/strings.js +0 -4
  116. package/dist/src/contracts/v3b/BaseAccessControlGroup.js +0 -1704
  117. package/dist/src/events/Topics.js +0 -1793
  118. package/dist/src/index.js +0 -8
  119. package/dist/src/walletClient/ClientMethods.js +0 -3102
  120. package/dist/src/walletClient/Configuration.js +0 -38
  121. package/dist/src/walletClient/Notifications.js +0 -168
  122. package/dist/src/walletClient/Profile.js +0 -332
  123. package/dist/src/walletClient/Utils.js +0 -281
  124. package/dist/src/walletClient/index.js +0 -2106
@@ -1,1544 +0,0 @@
1
- var _regeneratorRuntime = require("@babel/runtime/regenerator");
2
- var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
3
- var _defineProperty = require("@babel/runtime/helpers/defineProperty");
4
- var _classCallCheck = require("@babel/runtime/helpers/classCallCheck");
5
- var _createClass = require("@babel/runtime/helpers/createClass");
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; }
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; }
8
- var UrlJoin = require("url-join");
9
- var _require = require("./Validation"),
10
- ValidatePresence = _require.ValidatePresence,
11
- ValidatePermission = _require.ValidatePermission;
12
- var PermissionsClient = /*#__PURE__*/function () {
13
- "use strict";
14
-
15
- /**
16
- * The PermissionsClient is intended to make it easy to setup and maintain permission policies in the fabric.
17
- *
18
- * <br/><b>Item Policies</b>:
19
- * - An item policy is the full specification of the policy for an object. It consists of a set of available profiles and a list of permissions.
20
- * - The item policy must be initialized using `CreateItemPolicy` before the other modification methods in this client can be used.
21
- * - The item policy can be retrieved using the `ItemPolicy` method to check if the policy for a particular item has been initialized.
22
- *
23
- *
24
- * <br/><b>Dates</b>:
25
- *
26
- * - `start` and `end` can be specified in several places in the policy. These can be provided in any format supported by JavaScript's `new Date(date)` constructor, such as Unix epoch timestamps or ISO timestamps.
27
- *
28
- * - Permissions, profiles and custom profile permissions may have start and end times. The effective allowed access is the *most restrictive* combination of applicable start and end times.
29
- *
30
- *
31
- * <br/><b>Subjects</b>:
32
- *
33
- * - A subject is a recipient of a permission - namely Fabric and oauth users and groups.
34
- *
35
- * - When specifying a subject, both the name and ID must be provided. For Fabric users, the ID is either the user or group address, or the igrp/iusr hash format of the address.
36
- *
37
- *
38
- * <br/><b>Items</b>:
39
- *
40
- * - An 'item' in this API is a content object to which permissions are granted. All profiles and permissions are on a per-item basis.
41
- *
42
- *
43
- * <br/><b>Profiles</b>:
44
- *
45
- * - Profiles represent a set of permissions that can be applied to a subject (via a 'permission', see below)
46
- *
47
- * - A profile may have `start` and `end` times
48
- *
49
- * - A profile includes permission specifications for both the assets and the offerings of an item. Both must be specified when creating or modifying a profile.
50
- *
51
- * - For both assets and offerings, there is a `default_permission` entry, which can be either `full-access` or `no-access`. This represents the access allowed to the assets and offerings when a permission for the profile is granted, excepting any custom permissions that override it.
52
- *
53
- * - For both assets and offerings, a profile may have a `custom_permissions` section, which specifies permissions for specific assets or offerings. These permissions must have a `permission` entry which is either `full-access` or `no-access`, and may have `start` and `end` times.
54
- *
55
- *
56
- * Example Profile Specification:
57
- "pre-release": {
58
- "start": "2020-12-10T08:00:00.000Z",
59
- "end": "2020-12-31T08:00:00.000Z",
60
- "assets": {
61
- "custom_permissions": {
62
- "2wLgQXV5VYvRPZlOEPN0.tif": {
63
- "start": "2020-09-10T07:00:00.000Z",
64
- "end": "2020-12-31T08:00:00.000Z",
65
- "permission": "full-access"
66
- },
67
- "781rsItfv8UxrkYgSNhb.tif": {
68
- "start": "2020-09-10T07:00:00.000Z",
69
- "end": "2020-12-31T08:00:00.000Z",
70
- "permission": "full-access"
71
- },
72
- "QCVtsOAcUKbA8svZeFRI.tif": {
73
- "permission": "full-access"
74
- },
75
- "QXWQVA7FfUwLlEPlBI1G.tif": {
76
- "permission": "full-access",
77
- "start": "2020-09-30T07:00:00.000Z"
78
- }
79
- },
80
- "default_permission": "no-access"
81
- },
82
- "offerings": {
83
- "default_permission": "no-access"
84
- }
85
- }
86
- *
87
- *
88
- * <br/><b>Permissions</b>:
89
- *
90
- * - A permission represents a grant of an item profile's permissions to a subject.
91
- *
92
- * - A permission must have a profile that is present in the item's policy
93
- *
94
- * - A permission may have `start` and `end` times. As mentioned above, the effective start and end times of a permission are the *most restrictive* of all applicable start and end times.
95
- *
96
- * - A permission must have a subject, which can be either a user or group, either from the Fabric or from an OAuth provider, or an NTP instance or an NTP Subject
97
- *
98
- * - A subject must have an ID and a name. In the case of certain OAuth providers, the name may be used as an ID in most cases, but the immutable ID for that subject must be used as the ID. For example, in Okta, a group may be specified by its name "Content Admins", but have the Okta ID "00g102tklfAorixGi4x7". The former should be used as the subjectName, and the latter as the subjectId
99
- *
100
- *
101
- * Example Permission:
102
- {
103
- "start": "2021-01-01T08:00:00.000Z",
104
- "end": "2021-03-31T07:00:00.000Z",
105
- "profileName": "servicing",
106
- "subjectSource": "oauth",
107
- "subjectType": "group",
108
- "subjectName": "Partner1",
109
- "subjectId: "00g102uednmwrTihN4x7"
110
- }
111
- *
112
- * @param client - An instance of ElvClient
113
- * @param {object=} options={offline: false} - Options for the PermissionsClient
114
- * - offline - If specified, metadata reads and updates will be done with a local copy.
115
- * Use OpenOfflineDraft and CloseOfflineDraft
116
- */
117
- function PermissionsClient(client) {
118
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
119
- offline: false
120
- };
121
- _classCallCheck(this, PermissionsClient);
122
- this.client = client;
123
- this.subjectNames = {};
124
- this.drafts = {};
125
- this.offline = options.offline;
126
- }
127
- _createClass(PermissionsClient, [{
128
- key: "FormatDate",
129
- value: function FormatDate(date) {
130
- if (!date) {
131
- return;
132
- }
133
- if (isNaN(new Date(date))) {
134
- throw Error("Invalid start time: ".concat(date));
135
- }
136
- return new Date(date).toISOString();
137
- }
138
- }, {
139
- key: "FormatProfile",
140
- value: function FormatProfile(profile) {
141
- var _this = this;
142
- ValidatePermission(profile.default_permission);
143
- var profileSpec = {};
144
- if (profile.start) {
145
- profileSpec.start = this.FormatDate(profile.start);
146
- }
147
- if (profile.end) {
148
- profileSpec.end = this.FormatDate(profile.end);
149
- }
150
- ["assets", "offerings"].forEach(function (type) {
151
- var typeInfo = profile[type] || {};
152
- profileSpec[type] = {
153
- default_permission: typeInfo.default_permission || typeInfo.default_permissions || "no-access"
154
- };
155
- if (typeInfo.custom_permissions) {
156
- profileSpec[type].custom_permissions = {};
157
- Object.keys(typeInfo.custom_permissions).forEach(function (id) {
158
- var permission = typeInfo.custom_permissions[id];
159
- var spec = {
160
- permission: ValidatePermission(permission.permission)
161
- };
162
- if (permission.start) {
163
- spec.start = _this.FormatDate(permission.start);
164
- }
165
- if (permission.end) {
166
- spec.end = _this.FormatDate(permission.end);
167
- }
168
- profileSpec[type].custom_permissions[id] = _objectSpread(_objectSpread({}, permission), spec);
169
- });
170
- }
171
- });
172
- return profileSpec;
173
- }
174
-
175
- // Convert from fabric metadata spec to client spec
176
- }, {
177
- key: "FormatPermission",
178
- value: function () {
179
- var _FormatPermission = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
180
- var policyId, policyWriteToken, permission, subjectSource, subjectType, subjectId, subjectName, subjectNTPId, id, cachedName, contentSpaceLibraryId, permissionSpec;
181
- return _regeneratorRuntime.wrap(function _callee$(_context) {
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")) {
214
- _context.next = 74;
215
- break;
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")) {
285
- _context.next = 74;
286
- break;
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();
344
- }
345
- }, _callee, this);
346
- }));
347
- function FormatPermission(_x) {
348
- return _FormatPermission.apply(this, arguments);
349
- }
350
- return FormatPermission;
351
- }()
352
- /* Offline draft */
353
- /**
354
- * Open an offline draft - copies object data locally and allows the functions processing this data to operate
355
- * on the local copy, much faster. Closing the draft will copy the data back to the object's write token.
356
- *
357
- * @methodGroup OfflineDraft
358
- * @namedParams
359
- * @param {string} policyId - Object ID of the policy
360
- * @param {string} policyLibraryId - Policy object library ID (optional)
361
- * @param {string=} policyWriteToken - Write token for the policy object
362
- */
363
- }, {
364
- key: "OpenOfflineDraft",
365
- value: function () {
366
- var _OpenOfflineDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref2) {
367
- var policyId, policyLibraryId, policyWriteToken, meta;
368
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
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();
399
- }
400
- }, _callee2, this);
401
- }));
402
- function OpenOfflineDraft(_x2) {
403
- return _OpenOfflineDraft.apply(this, arguments);
404
- }
405
- return OpenOfflineDraft;
406
- }()
407
- /**
408
- * Close an offline draft - copies the metadata stored locally back to the write token's metadata.
409
- * Does not finalize the write token.
410
- *
411
- * @methodGroup OfflineDraft
412
- * @namedParams
413
- * @param {string} policyId - Object ID of the policy
414
- */
415
- }, {
416
- key: "CloseOfflineDraft",
417
- value: function () {
418
- var _CloseOfflineDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(_ref3) {
419
- var policyId;
420
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
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();
442
- }
443
- }, _callee3, this);
444
- }));
445
- function CloseOfflineDraft(_x3) {
446
- return _CloseOfflineDraft.apply(this, arguments);
447
- }
448
- return CloseOfflineDraft;
449
- }()
450
- /* Add / remove overall item permission */
451
- /**
452
- * Retrieve a list of all items in the specified policy
453
- *
454
- * @methodGroup Policies
455
- * @namedParams
456
- * @param {string} policyId - Object ID of the policy
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
458
- * @return {Promise<Object>} - A mapping of item objectId to the display name of the item
459
- */
460
- }, {
461
- key: "PolicyItems",
462
- value: function () {
463
- var _PolicyItems = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref4) {
464
- var policyId, policyWriteToken;
465
- return _regeneratorRuntime.wrap(function _callee4$(_context4) {
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();
500
- }
501
- }, _callee4, this);
502
- }));
503
- function PolicyItems(_x4) {
504
- return _PolicyItems.apply(this, arguments);
505
- }
506
- return PolicyItems;
507
- }()
508
- /**
509
- * Retrieve the full item policy for the given item.
510
- *
511
- * @methodGroup Policies
512
- * @namedParams
513
- * @param {string} policyId - Object ID of the policy
514
- * @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
515
- * @param {string} itemId - Object ID of the item
516
- * @return {Promise<Object | undefined>} - The policy for the specified item. If none exists, returns undefined
517
- */
518
- }, {
519
- key: "ItemPolicy",
520
- value: function () {
521
- var _ItemPolicy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(_ref5) {
522
- var policyId, policyWriteToken, itemId, profiles, permissions;
523
- return _regeneratorRuntime.wrap(function _callee5$(_context5) {
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();
556
- }
557
- }, _callee5, this);
558
- }));
559
- function ItemPolicy(_x5) {
560
- return _ItemPolicy.apply(this, arguments);
561
- }
562
- return ItemPolicy;
563
- }()
564
- /**
565
- * Initialize policy for the specified item
566
- *
567
- * @methodGroup Policies
568
- * @namedParams
569
- * @param {string} policyId - Object ID of the policy
570
- * @param {string} policyWriteToken - Write token for the policy
571
- * @param {string} itemId - Object ID of the item
572
- * @param {object=} profiles={} - Profiles to create
573
- */
574
- }, {
575
- key: "CreateItemPolicy",
576
- value: function () {
577
- var _CreateItemPolicy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(_ref6) {
578
- var _this2 = this;
579
- var policyId, policyWriteToken, itemId, _ref6$profiles, profiles, metadata, assetMetadata, displayTitle, itemSpec;
580
- return _regeneratorRuntime.wrap(function _callee6$(_context6) {
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();
646
- }
647
- }, _callee6, this);
648
- }));
649
- function CreateItemPolicy(_x6) {
650
- return _CreateItemPolicy.apply(this, arguments);
651
- }
652
- return CreateItemPolicy;
653
- }()
654
- /**
655
- * Remove the specified item policy
656
- *
657
- * @methodGroup Policies
658
- * @namedParams
659
- * @param {string} policyId - Object ID of the policy
660
- * @param {string} policyWriteToken - Write token for the policy
661
- * @param {string} itemId - Object ID of the item
662
- */
663
- }, {
664
- key: "RemoveItemPolicy",
665
- value: function () {
666
- var _RemoveItemPolicy = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(_ref7) {
667
- var policyId, policyWriteToken, itemId;
668
- return _regeneratorRuntime.wrap(function _callee7$(_context7) {
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();
696
- }
697
- }, _callee7, this);
698
- }));
699
- function RemoveItemPolicy(_x7) {
700
- return _RemoveItemPolicy.apply(this, arguments);
701
- }
702
- return RemoveItemPolicy;
703
- }()
704
- /* Get / set / remove profile permissions */
705
- /**
706
- * Retrieve profile information on the specified item policy
707
- *
708
- * @methodGroup Profiles
709
- * @namedParams
710
- * @param {string} policyId - Object ID of the policy
711
- * @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
712
- * @param {string} itemId - Object ID of the item
713
- * @param {string=} profileName - The name of the profile. If not specified, all profiles will be returned
714
- */
715
- }, {
716
- key: "ItemProfiles",
717
- value: function () {
718
- var _ItemProfiles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(_ref8) {
719
- var policyId, policyWriteToken, itemId, profileName;
720
- return _regeneratorRuntime.wrap(function _callee8$(_context8) {
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();
747
- }
748
- }, _callee8, this);
749
- }));
750
- function ItemProfiles(_x8) {
751
- return _ItemProfiles.apply(this, arguments);
752
- }
753
- return ItemProfiles;
754
- }()
755
- /**
756
- * Create or modify a profile for the specified item policy
757
- *
758
- * @methodGroup Profiles
759
- * @namedParams
760
- * @param {string} policyId - Object ID of the policy
761
- * @param {string} policyWriteToken - Write token for the policy
762
- * @param {string} itemId - Object ID of the item
763
- * @param {string} profileName - The name of the profile
764
- * @param {object} profileSpec - Specification for the profile. If not provided, profile
765
- * will default to no access for both assets and offerings
766
- */
767
- }, {
768
- key: "SetProfile",
769
- value: function () {
770
- var _SetProfile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(_ref9) {
771
- var policyId, policyWriteToken, itemId, profileName, profileSpec;
772
- return _regeneratorRuntime.wrap(function _callee9$(_context9) {
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();
804
- }
805
- }, _callee9, this);
806
- }));
807
- function SetProfile(_x9) {
808
- return _SetProfile.apply(this, arguments);
809
- }
810
- return SetProfile;
811
- }()
812
- /**
813
- * Remove a profile from the specified item policy
814
- *
815
- * @methodGroup Profiles
816
- * @namedParams
817
- * @param {string} policyId - Object ID of the policy
818
- * @param {string} policyWriteToken - Write token for the policy
819
- * @param {string} itemId - Object ID of the item
820
- * @param {string} profileName - The name of the profile
821
- * @param {object} profileSpec - Specification for the profile. If not provided, profile
822
- * will default to no access for both assets and offerings
823
- */
824
- }, {
825
- key: "RemoveProfile",
826
- value: function () {
827
- var _RemoveProfile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(_ref10) {
828
- var policyId, policyWriteToken, itemId, profileName;
829
- return _regeneratorRuntime.wrap(function _callee10$(_context10) {
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();
858
- }
859
- }, _callee10, this);
860
- }));
861
- function RemoveProfile(_x10) {
862
- return _RemoveProfile.apply(this, arguments);
863
- }
864
- return RemoveProfile;
865
- }()
866
- /* Get / set / remove subject permissions */
867
- /**
868
- * Retrieve the permissions for the specified item policy
869
- *
870
- * @methodGroup Permissions
871
- * @namedParams
872
- * @param {string} policyId - Object ID of the policy
873
- * @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
874
- * @param {string} itemId - Object ID of the item
875
- *
876
- * @return {Promise<Array>} - The list of permissions for the specified item
877
- */
878
- }, {
879
- key: "ItemPermissions",
880
- value: function () {
881
- var _ItemPermissions = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(_ref11) {
882
- var _this3 = this;
883
- var policyId, policyWriteToken, itemId, libraryId, permissions;
884
- return _regeneratorRuntime.wrap(function _callee12$(_context12) {
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();
939
- }
940
- }, _callee12, this);
941
- }));
942
- function ItemPermissions(_x11) {
943
- return _ItemPermissions.apply(this, arguments);
944
- }
945
- return ItemPermissions;
946
- }()
947
- /**
948
- * Add or modify permission for the specified subject to the specified item policy
949
- *
950
- * @methodGroup Permissions
951
- * @namedParams
952
- * @param {string} policyId - Object ID of the policy
953
- * @param {string} policyWriteToken - Write token for the policy
954
- * @param {string} itemId - Object ID of the item
955
- * @param {string} subjectSource="fabric" - ("fabric" | "oauth") - The source of the subject
956
- * @param {string} subjectType="group - ("user" | "group" | "ntp" | "ntp_subject") - The type of the subject
957
- * @param {string=} subjectName - The name of the subject
958
- * @param {string} subjectId - The ID of the subject
959
- * @param {string=} subjectNTPId - (For subjectType "ntp_subject") The NTP ID associated with the subject
960
- * @param {string} profileName - The profile to apply for the permission
961
- * @param {string | number} start - The start time for the permission
962
- * @param {string | number} end - The end time for the permission
963
- */
964
- }, {
965
- key: "SetPermission",
966
- value: function () {
967
- var _SetPermission = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(_ref13) {
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;
969
- return _regeneratorRuntime.wrap(function _callee13$(_context13) {
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;
988
- break;
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));
1006
- }
1007
- }
1008
- }
1009
- if (!offlineDraft) {
1010
- _context13.next = 21;
1011
- break;
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;
1029
- break;
1030
- }
1031
- throw Error("Unable to add permissions to uninitialized item");
1032
- case 26:
1033
- if (existingPermissions.profiles[profileName]) {
1034
- _context13.next = 28;
1035
- 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;
1044
- }
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;
1060
- break;
1061
- }
1062
- if (!(subjectType === "group")) {
1063
- _context13.next = 38;
1064
- break;
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;
1075
- break;
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;
1086
- break;
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;
1097
- break;
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) {
1150
- _context13.next = 71;
1151
- break;
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) {
1188
- _context13.next = 83;
1189
- break;
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")) {
1204
- _context13.next = 97;
1205
- break;
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) {
1231
- _context13.next = 97;
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();
1245
- }
1246
- }, _callee13, this);
1247
- }));
1248
- function SetPermission(_x13) {
1249
- return _SetPermission.apply(this, arguments);
1250
- }
1251
- return SetPermission;
1252
- }()
1253
- /**
1254
- * Remove permission for the specified subject from the specified item policy
1255
- *
1256
- * @methodGroup Permissions
1257
- * @namedParams
1258
- * @param {string} policyId - Object ID of the policy
1259
- * @param {string} policyWriteToken - Write token for the policy
1260
- * @param {string} itemId - Object ID of the item
1261
- * @param {string} subjectId - The ID of the subject
1262
- */
1263
- }, {
1264
- key: "RemovePermission",
1265
- value: function () {
1266
- var _RemovePermission = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(_ref14) {
1267
- var _this4 = this;
1268
- var policyId, policyWriteToken, itemId, subjectId, policyLibraryId, permissions, id;
1269
- return _regeneratorRuntime.wrap(function _callee15$(_context15) {
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")) {
1299
- _context15.next = 23;
1300
- break;
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;
1328
- }
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();
1349
- }
1350
- }, _callee15, this);
1351
- }));
1352
- function RemovePermission(_x14) {
1353
- return _RemovePermission.apply(this, arguments);
1354
- }
1355
- return RemovePermission;
1356
- }()
1357
- /**
1358
- * Retrieve all permissions for the specified subject.
1359
- *
1360
- * @methodGroup Permissions
1361
- * @namedParams
1362
- * @param {string} policyId - Object ID of the policy
1363
- * @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
1364
- * @param {string} subjectId - The ID of the subject
1365
- *
1366
- * @returns {Object} - All permissions pertaining to the given subject. Format of result for each item is identical to the format of `ItemPolicy`
1367
- */
1368
- }, {
1369
- key: "SubjectPermissions",
1370
- value: function () {
1371
- var _SubjectPermissions = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee17(_ref16) {
1372
- var _this5 = this;
1373
- var policyId, policyWriteToken, subjectId, id, policyLibraryId, policy, allSubjectPermissions, _i, _Object$keys, itemId, itemPermissions, subjectPermissions;
1374
- return _regeneratorRuntime.wrap(function _callee17$(_context17) {
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")) {
1383
- _context17.next = 13;
1384
- break;
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;
1395
- break;
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();
1469
- }
1470
- }, _callee17, this);
1471
- }));
1472
- function SubjectPermissions(_x17) {
1473
- return _SubjectPermissions.apply(this, arguments);
1474
- }
1475
- return SubjectPermissions;
1476
- }()
1477
- /**
1478
- * Remove all permissions for the specified subject.
1479
- *
1480
- * @methodGroup Permissions
1481
- * @namedParams
1482
- * @param {string} policyId - Object ID of the policy
1483
- * @param {string} policyWriteToken - Write token for the policy
1484
- * @param {string} subjectId - The ID of the subject
1485
- */
1486
- }, {
1487
- key: "RemoveSubjectPermissions",
1488
- value: function () {
1489
- var _RemoveSubjectPermissions = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee19(_ref18) {
1490
- var _this6 = this;
1491
- var policyId, policyWriteToken, subjectId, subjectPermissions;
1492
- return _regeneratorRuntime.wrap(function _callee19$(_context19) {
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();
1533
- }
1534
- }, _callee19, this);
1535
- }));
1536
- function RemoveSubjectPermissions(_x19) {
1537
- return _RemoveSubjectPermissions.apply(this, arguments);
1538
- }
1539
- return RemoveSubjectPermissions;
1540
- }()
1541
- }]);
1542
- return PermissionsClient;
1543
- }();
1544
- module.exports = PermissionsClient;