@lifeready/core 8.0.11 → 8.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 (32) hide show
  1. package/bundles/lifeready-core.umd.js +212 -45
  2. package/bundles/lifeready-core.umd.js.map +1 -1
  3. package/bundles/lifeready-core.umd.min.js +1 -1
  4. package/bundles/lifeready-core.umd.min.js.map +1 -1
  5. package/esm2015/lib/_common/exceptions.js +4 -1
  6. package/esm2015/lib/_common/index.js +3 -0
  7. package/esm2015/lib/_common/kc-lodash.js +11 -0
  8. package/esm2015/lib/api/lr-graphql/lr-graphql.service.js +2 -2
  9. package/esm2015/lib/api/lr-graphql/lr-merged-mutation.js +2 -2
  10. package/esm2015/lib/api/lr-graphql/lr-mutation.js +2 -2
  11. package/esm2015/lib/api/types/lr-graphql.types.js +1 -1
  12. package/esm2015/lib/auth/auth.service.js +12 -5
  13. package/esm2015/lib/key/key-graph.service.js +5 -5
  14. package/esm2015/lib/profile/profile-details.service.js +5 -5
  15. package/esm2015/lib/scenario/scenario.service.js +5 -1
  16. package/esm2015/lib/scenario/scenario.types.js +1 -1
  17. package/esm2015/lib/trusted-party/trusted-party.gql.private.js +25 -1
  18. package/esm2015/lib/trusted-party/trusted-party.service.js +95 -15
  19. package/esm2015/lib/trusted-party/trusted-party.types.js +1 -1
  20. package/fesm2015/lifeready-core.js +149 -28
  21. package/fesm2015/lifeready-core.js.map +1 -1
  22. package/lib/_common/exceptions.d.ts +1 -0
  23. package/lib/_common/index.d.ts +2 -0
  24. package/lib/_common/kc-lodash.d.ts +5 -0
  25. package/lib/api/types/lr-graphql.types.d.ts +1 -0
  26. package/lib/scenario/scenario.service.d.ts +59 -0
  27. package/lib/scenario/scenario.types.d.ts +2 -0
  28. package/lib/trusted-party/trusted-party.gql.private.d.ts +16 -0
  29. package/lib/trusted-party/trusted-party.service.d.ts +55 -11
  30. package/lib/trusted-party/trusted-party.types.d.ts +6 -2
  31. package/lifeready-core.metadata.json +1 -1
  32. package/package.json +1 -1
@@ -2,11 +2,14 @@ import { __awaiter, __decorate, __rest } from 'tslib';
2
2
  import { ɵɵdefineInjectable, ɵɵinject, Injectable, InjectionToken, isDevMode, INJECTOR, Injector, Inject, NgZone, APP_INITIALIZER, NgModule } from '@angular/core';
3
3
  import { Apollo, APOLLO_OPTIONS } from 'apollo-angular';
4
4
  import graphlib, { Graph } from '@dagrejs/graphlib';
5
- import _, { cloneDeep } from 'lodash';
6
5
  import { JWE, JWS, JWK } from 'node-jose';
7
6
  import { AuthClass } from '@aws-amplify/auth/lib-esm/Auth';
8
7
  import gql from 'graphql-tag';
9
8
  import * as moment_ from 'moment';
9
+ import lodash$1 from 'lodash/cloneDeep';
10
+ import lodash$2 from 'lodash/isEqual';
11
+ import 'lodash/keyBy';
12
+ import lodash from 'lodash/omit';
10
13
  import { ApolloLink, createHttpLink, from, InMemoryCache } from '@apollo/client/core';
11
14
  import { setContext } from '@apollo/client/link/context';
12
15
  import { RetryLink } from '@apollo/client/link/retry';
@@ -35,6 +38,8 @@ var PayloadType;
35
38
  PayloadType["UINT_8_ARRAY"] = "UINT_8_ARRAY";
36
39
  })(PayloadType || (PayloadType = {}));
37
40
 
41
+ // This file is in the "lr-lodash" directory so that we can use the barrel file
42
+
38
43
  function handleApolloError(errors) {
39
44
  if (!errors || !errors.length)
40
45
  return;
@@ -42,6 +47,7 @@ function handleApolloError(errors) {
42
47
  return new KcError({
43
48
  code: x.extensions && x.extensions.code,
44
49
  source: x.extensions && x.extensions.source,
50
+ data: x.extensions && lodash(x.extensions, ['code', 'source']),
45
51
  message: x.message,
46
52
  debug: {
47
53
  locations: x.locations,
@@ -69,6 +75,7 @@ class KcError {
69
75
  this._type = 'KcError';
70
76
  this.code = options.code;
71
77
  this.source = options.source;
78
+ this.data = options.data;
72
79
  this.message = options.message;
73
80
  this.debug = options.debug;
74
81
  }
@@ -1283,7 +1290,7 @@ class KeyGraphService {
1283
1290
  }
1284
1291
  const node = {
1285
1292
  type: KeyGraphNodeType.Key,
1286
- data: _.cloneDeep(key),
1293
+ data: lodash$1(key),
1287
1294
  };
1288
1295
  this.graph.setNode(key.id, node);
1289
1296
  }
@@ -1296,7 +1303,7 @@ class KeyGraphService {
1296
1303
  }
1297
1304
  const edge = {
1298
1305
  type: KeyGraphEdgeType.KeyLink,
1299
- data: _.cloneDeep(keyLink),
1306
+ data: lodash$1(keyLink),
1300
1307
  };
1301
1308
  // Edge goes from wrapping key to wrapped key.
1302
1309
  this.graph.setEdge(keyLink.wrappingKeyId, keyLink.keyId, edge);
@@ -1310,7 +1317,7 @@ class KeyGraphService {
1310
1317
  }
1311
1318
  const edge = {
1312
1319
  type: KeyGraphEdgeType.PassKeyLink,
1313
- data: _.cloneDeep(passKeyLink),
1320
+ data: lodash$1(passKeyLink),
1314
1321
  };
1315
1322
  // Edge goes from wrapping key to wrapped key.
1316
1323
  this.graph.setEdge(passKeyLink.passKeyId, passKeyLink.keyId, edge);
@@ -2313,7 +2320,7 @@ class LrMutation extends LrMutationBase {
2313
2320
  */
2314
2321
  select(fragments) {
2315
2322
  // Don't touch the original
2316
- const mutationDoc = cloneDeep(this.mutation);
2323
+ const mutationDoc = lodash$1(this.mutation);
2317
2324
  const mutationNode = getMutation(mutationDoc);
2318
2325
  const fragmentMap = {};
2319
2326
  getFragments(fragments).forEach((fragment) => {
@@ -2541,7 +2548,7 @@ class LrMergedMutation extends LrMutationBase {
2541
2548
  ...this.renameFragmentDefinitions(fragments, prefix),
2542
2549
  ];
2543
2550
  });
2544
- const mergedMutation = cloneDeep(lrMergedMutationDoc);
2551
+ const mergedMutation = lodash$1(lrMergedMutationDoc);
2545
2552
  const mutationNode = getMutation(mergedMutation);
2546
2553
  // Add in the mutation selections
2547
2554
  mutationNode.selectionSet.selections = selections;
@@ -2587,7 +2594,7 @@ let LrGraphQLService = class LrGraphQLService {
2587
2594
  query(options) {
2588
2595
  return __awaiter(this, void 0, void 0, function* () {
2589
2596
  // Make copies to avoid side effect.
2590
- options = cloneDeep(options);
2597
+ options = lodash$1(options);
2591
2598
  // Append the key graph query
2592
2599
  const includeKeyGraph = this.isIncludeKeyGraph(options.includeKeyGraph);
2593
2600
  if (includeKeyGraph) {
@@ -2637,7 +2644,7 @@ let LrGraphQLService = class LrGraphQLService {
2637
2644
  apolloMutate(options) {
2638
2645
  return __awaiter(this, void 0, void 0, function* () {
2639
2646
  // Make copies to avoid side effect.
2640
- options = Object.assign(Object.assign({}, options), { mutation: cloneDeep(options.mutation) });
2647
+ options = Object.assign(Object.assign({}, options), { mutation: lodash$1(options.mutation) });
2641
2648
  // Append the key graph query
2642
2649
  const includeKeyGraph = this.isIncludeKeyGraph(options.includeKeyGraph);
2643
2650
  if (includeKeyGraph) {
@@ -2667,7 +2674,7 @@ let LrGraphQLService = class LrGraphQLService {
2667
2674
  });
2668
2675
  }
2669
2676
  statsSnapshot() {
2670
- return cloneDeep(this.stats);
2677
+ return lodash$1(this.stats);
2671
2678
  }
2672
2679
  addKeys(response) {
2673
2680
  if (response.data.keyGraph) {
@@ -5525,10 +5532,17 @@ let AuthService = AuthService_1 = class AuthService extends LrService {
5525
5532
  // Debug utilities
5526
5533
  // ------------------------------------------------------
5527
5534
  debugLogin(username, password) {
5528
- // This will fail if debug is null. But when debug is null, this function
5529
- // should not be called.
5530
- this.kcConfig.debug.username = username;
5531
- return this.debugLoadUser(password);
5535
+ return __awaiter(this, void 0, void 0, function* () {
5536
+ // This will fail if debug is null. But when debug is null, this function
5537
+ // should not be called.
5538
+ this.kcConfig.debug.username = username;
5539
+ // This mechanism only works in a browser session because it needs to set cookies etc.
5540
+ // But it sets the last_login field for the users which we need in some tests.
5541
+ yield this.http
5542
+ .get(`${this.kcConfig.authUrl}debug_only/users/login/?username=${encodeURIComponent(username)}`)
5543
+ .toPromise();
5544
+ return this.debugLoadUser(password);
5545
+ });
5532
5546
  }
5533
5547
  debugLoadUser(password) {
5534
5548
  return __awaiter(this, void 0, void 0, function* () {
@@ -8117,7 +8131,7 @@ class ProfileDetailsService {
8117
8131
  oldValue: oldValue.value,
8118
8132
  });
8119
8133
  }
8120
- else if (!_.isEqual(newValue.value, oldValue.value)) {
8134
+ else if (!lodash$2(newValue.value, oldValue.value)) {
8121
8135
  changes.push({
8122
8136
  field,
8123
8137
  id: oldValue.id,
@@ -8158,7 +8172,7 @@ class ProfileDetailsService {
8158
8172
  break;
8159
8173
  default: {
8160
8174
  const value = details[change.field];
8161
- if (_.isEqual(value, change.oldValue)) {
8175
+ if (lodash$2(value, change.oldValue)) {
8162
8176
  hasChanged = true;
8163
8177
  details[change.field] = change.newValue;
8164
8178
  }
@@ -8175,7 +8189,7 @@ class ProfileDetailsService {
8175
8189
  property = property || { value: field, hasMultiple: false };
8176
8190
  property.values = property.values || [];
8177
8191
  if (property.values.length === 0 ||
8178
- property.values.every((x) => !_.isEqual(field, x.value))) {
8192
+ property.values.every((x) => !lodash$2(field, x.value))) {
8179
8193
  property.values.push({
8180
8194
  id: `${label}-${new Date().getTime()}`,
8181
8195
  label,
@@ -9031,6 +9045,7 @@ let ScenarioService = class ScenarioService extends LrService {
9031
9045
  const createClaimants = yield Promise.all(createClaimantsOptions.map((x) => this.prepareCreateClaimant(x)));
9032
9046
  return {
9033
9047
  enabled: options.enabled,
9048
+ inactiveSeconds: options.inactiveSeconds,
9034
9049
  createAssembly,
9035
9050
  createReceivers,
9036
9051
  createClaimants,
@@ -9084,6 +9099,7 @@ let ScenarioService = class ScenarioService extends LrService {
9084
9099
  return {
9085
9100
  scenarioId: options.scenarioId,
9086
9101
  enabled: options.enabled,
9102
+ inactiveSeconds: options.inactiveSeconds,
9087
9103
  updateAssembly,
9088
9104
  createReceivers,
9089
9105
  updateReceivers,
@@ -9102,6 +9118,7 @@ let ScenarioService = class ScenarioService extends LrService {
9102
9118
  if (accessRole == AccessRoleChoice.DENY) {
9103
9119
  const ret = {
9104
9120
  accessRole,
9121
+ itemKeyId: null,
9105
9122
  wrappedItemKey: null,
9106
9123
  sharedCipherData: null,
9107
9124
  };
@@ -9127,6 +9144,7 @@ let ScenarioService = class ScenarioService extends LrService {
9127
9144
  wrappedItemKey = yield this.keyGraph.encryptToString(assemblyKey, wrappedItemKey);
9128
9145
  const ret = {
9129
9146
  accessRole,
9147
+ itemKeyId: itemKey.id,
9130
9148
  wrappedItemKey,
9131
9149
  sharedCipherData,
9132
9150
  };
@@ -10262,6 +10280,30 @@ query TpCurrentUserSharedKeyQuery($id: LrRelayIdInput!) {
10262
10280
  }
10263
10281
  }
10264
10282
  `;
10283
+ const DirectoryShareQuery = gqlTyped `
10284
+ query DirectoryShareQuery($id: LrRelayIdInput!) {
10285
+ directoryShare(id: $id) {
10286
+ item {
10287
+ id
10288
+ }
10289
+ tp {
10290
+ id
10291
+ }
10292
+ }
10293
+ }
10294
+ `;
10295
+ const FileShareQuery = gqlTyped `
10296
+ query FileShareItemIdQuery($id: LrRelayIdInput!) {
10297
+ fileShare(id: $id) {
10298
+ item {
10299
+ id
10300
+ }
10301
+ tp {
10302
+ id
10303
+ }
10304
+ }
10305
+ }
10306
+ `;
10265
10307
 
10266
10308
  let TrustedPartyService = class TrustedPartyService extends LrService {
10267
10309
  constructor(ngZone, injector, keyGraph, itemService, keyService, keyFactory, encryptionService) {
@@ -10316,19 +10358,35 @@ let TrustedPartyService = class TrustedPartyService extends LrService {
10316
10358
  prepareCreateItemShareMutation(options) {
10317
10359
  return __awaiter(this, void 0, void 0, function* () {
10318
10360
  const { itemId, itemKeyId, tpId, tpSharedKeyId, accessRole, isDirectory, shareType, } = options;
10361
+ if (accessRole == AccessRoleChoice.DENY) {
10362
+ if (itemKeyId || tpSharedKeyId) {
10363
+ throw new KcBadArgumentException('If accessRole is AccessRoleChoice.DENY, must not specify any of itemId, itemKeyId, or tpSharedKeyId parameters');
10364
+ }
10365
+ return {
10366
+ input: {
10367
+ itemId,
10368
+ tpId,
10369
+ accessRole,
10370
+ itemKeyId: null,
10371
+ wrappingKeyId: null,
10372
+ wrappedItemKey: null,
10373
+ shareType,
10374
+ },
10375
+ };
10376
+ }
10319
10377
  const itemKey = yield this.keyGraph.getKey(itemKeyId, () => isDirectory
10320
10378
  ? this.itemService.getDirectoryKeyId(itemId)
10321
10379
  : this.itemService.getFileKeyId(itemId));
10322
10380
  const wrappingKey = yield this.keyGraph.getKey(tpSharedKeyId, () => this.getTpCurrentUserSharedKey(tpId).then((res) => res.sharedKey.id));
10323
- const wrappedKey = yield this.keyGraph.wrapKey(wrappingKey, itemKey.jwk);
10381
+ const wrappedItemKey = yield this.keyGraph.wrapKey(wrappingKey, itemKey.jwk);
10324
10382
  return {
10325
10383
  input: {
10326
- id: itemId,
10384
+ itemId,
10327
10385
  tpId,
10328
10386
  accessRole,
10329
- keyId: itemKey.id,
10387
+ itemKeyId: itemKey.id,
10330
10388
  wrappingKeyId: wrappingKey.id,
10331
- wrappedKey,
10389
+ wrappedItemKey,
10332
10390
  shareType,
10333
10391
  },
10334
10392
  };
@@ -10343,7 +10401,7 @@ let TrustedPartyService = class TrustedPartyService extends LrService {
10343
10401
  return __awaiter(this, void 0, void 0, function* () {
10344
10402
  return new LrMutation({
10345
10403
  mutation: UpdateDirectoryShareMutation,
10346
- variables: this.prepareUpdateItemShareMutation(options),
10404
+ variables: yield this.prepareUpdateItemShareMutation(Object.assign(Object.assign({}, options), { isDirectory: true })),
10347
10405
  });
10348
10406
  });
10349
10407
  }
@@ -10356,18 +10414,81 @@ let TrustedPartyService = class TrustedPartyService extends LrService {
10356
10414
  return __awaiter(this, void 0, void 0, function* () {
10357
10415
  return new LrMutation({
10358
10416
  mutation: UpdateFileShareMutation,
10359
- variables: this.prepareUpdateItemShareMutation(options),
10417
+ variables: yield this.prepareUpdateItemShareMutation(Object.assign(Object.assign({}, options), { isDirectory: false })),
10360
10418
  });
10361
10419
  });
10362
10420
  }
10363
- prepareUpdateItemShareMutation(options) {
10364
- const { itemShareId, accessRole } = options;
10365
- return {
10366
- input: {
10421
+ getDirectoryShare(itemShareId) {
10422
+ return this.lrGraphQL.query({
10423
+ query: DirectoryShareQuery,
10424
+ variables: {
10367
10425
  id: itemShareId,
10368
- accessRole,
10369
10426
  },
10370
- };
10427
+ });
10428
+ }
10429
+ getFileShare(itemShareId) {
10430
+ return this.lrGraphQL.query({
10431
+ query: FileShareQuery,
10432
+ variables: {
10433
+ id: itemShareId,
10434
+ },
10435
+ });
10436
+ }
10437
+ prepareUpdateItemShareMutation(options) {
10438
+ return __awaiter(this, void 0, void 0, function* () {
10439
+ const { itemShareId, accessRole, isDirectory, itemId, itemKeyId, tpId, tpSharedKeyId, } = options;
10440
+ if (accessRole == AccessRoleChoice.DENY) {
10441
+ if (itemId || itemKeyId || tpId || tpSharedKeyId) {
10442
+ throw new KcBadArgumentException('If accessRole is AccessRoleChoice.DENY, must not specify any of itemId, itemKeyId, tpId, or tpSharedKeyId parameters');
10443
+ }
10444
+ return {
10445
+ input: {
10446
+ id: itemShareId,
10447
+ accessRole,
10448
+ itemKeyId: null,
10449
+ wrappingKeyId: null,
10450
+ wrappedItemKey: null,
10451
+ },
10452
+ };
10453
+ }
10454
+ // Caching the result so we only need one call.
10455
+ let itemShare;
10456
+ const getItemShare = () => __awaiter(this, void 0, void 0, function* () {
10457
+ if (!itemShare) {
10458
+ if (isDirectory) {
10459
+ itemShare = (yield this.getDirectoryShare(itemShareId))
10460
+ .directoryShare;
10461
+ }
10462
+ else {
10463
+ itemShare = (yield this.getFileShare(itemShareId)).fileShare;
10464
+ }
10465
+ }
10466
+ return itemShare;
10467
+ });
10468
+ const itemKey = yield this.keyGraph.getKey(itemKeyId, () => __awaiter(this, void 0, void 0, function* () {
10469
+ const itemId_ = itemId || (yield getItemShare()).item.id;
10470
+ if (isDirectory) {
10471
+ return this.itemService.getDirectoryKeyId(itemId_);
10472
+ }
10473
+ else {
10474
+ return this.itemService.getFileKeyId(itemId_);
10475
+ }
10476
+ }));
10477
+ const wrappingKey = yield this.keyGraph.getKey(tpSharedKeyId, () => __awaiter(this, void 0, void 0, function* () {
10478
+ const tpId_ = tpId || (yield getItemShare()).tp.id;
10479
+ return (yield this.getTpCurrentUserSharedKey(tpId_)).sharedKey.id;
10480
+ }));
10481
+ const wrappedItemKey = yield this.keyGraph.wrapKey(wrappingKey, itemKey.jwk);
10482
+ return {
10483
+ input: {
10484
+ id: itemShareId,
10485
+ accessRole,
10486
+ itemKeyId: itemKey.id,
10487
+ wrappingKeyId: wrappingKey.id,
10488
+ wrappedItemKey,
10489
+ },
10490
+ };
10491
+ });
10371
10492
  }
10372
10493
  deleteDirectoryShare(id) {
10373
10494
  return __awaiter(this, void 0, void 0, function* () {