@lifeready/core 8.0.6 → 8.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundles/lifeready-core.umd.js +186 -47
- package/bundles/lifeready-core.umd.js.map +1 -1
- package/bundles/lifeready-core.umd.min.js +1 -1
- package/bundles/lifeready-core.umd.min.js.map +1 -1
- package/esm2015/lib/_common/utils.js +14 -1
- package/esm2015/lib/api/query-processor/query-processor.service.js +13 -1
- package/esm2015/lib/api/types/lr-graphql.types.js +1 -1
- package/esm2015/lib/scenario/scenario.private.gql.js +11 -1
- package/esm2015/lib/scenario/scenario.service.js +101 -20
- package/esm2015/lib/scenario/scenario.types.js +1 -1
- package/fesm2015/lifeready-core.js +133 -19
- package/fesm2015/lifeready-core.js.map +1 -1
- package/lib/_common/utils.d.ts +1 -0
- package/lib/api/types/lr-graphql.types.d.ts +2 -2
- package/lib/scenario/scenario.service.d.ts +223 -0
- package/lib/scenario/scenario.types.d.ts +15 -3
- package/lifeready-core.metadata.json +1 -1
- package/package.json +1 -1
|
@@ -279,6 +279,18 @@ function getAccessJwtToken(auth) {
|
|
|
279
279
|
}
|
|
280
280
|
});
|
|
281
281
|
}
|
|
282
|
+
function assert_xor(options) {
|
|
283
|
+
const keys = Object.keys(options);
|
|
284
|
+
if (keys.length != 2) {
|
|
285
|
+
throw new KcBadLogicException('You must provide exactly 2 fields in the argument.');
|
|
286
|
+
}
|
|
287
|
+
if (options[keys[0]] != null && options[keys[1]] != null) {
|
|
288
|
+
throw new KcBadLogicException(`You can not specify both ${keys[0]} and ${keys[1]}`);
|
|
289
|
+
}
|
|
290
|
+
if (options[keys[0]] == null && options[keys[1]] == null) {
|
|
291
|
+
throw new KcBadLogicException(`You must specify either ${keys[0]} and ${keys[1]}`);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
282
294
|
|
|
283
295
|
// Ref: https://stackoverflow.com/questions/59735280/angular-8-moment-error-cannot-call-a-namespace-moment
|
|
284
296
|
const moment = moment_;
|
|
@@ -1984,6 +1996,18 @@ let QueryProcessorService = class QueryProcessorService {
|
|
|
1984
1996
|
getKeyId: ({ field }) => field.sharedKey.id,
|
|
1985
1997
|
}),
|
|
1986
1998
|
]));
|
|
1999
|
+
this.registerProcessor('ScenarioReceiverFileNode', common.series([
|
|
2000
|
+
common.makeDecryptionProcessor({
|
|
2001
|
+
cipherFieldName: 'sharedCipherData',
|
|
2002
|
+
getKeyId: ({ field }) => field.sharedKey.id,
|
|
2003
|
+
}),
|
|
2004
|
+
]));
|
|
2005
|
+
this.registerProcessor('SharedScenarioReceiverNode', common.series([
|
|
2006
|
+
common.makeDecryptionProcessor({
|
|
2007
|
+
cipherFieldName: 'sharedCipherData',
|
|
2008
|
+
getKeyId: ({ field }) => field.sharedKey.id,
|
|
2009
|
+
}),
|
|
2010
|
+
]));
|
|
1987
2011
|
this.registerProcessor('ScenarioApproverAssemblyNode', common.series([
|
|
1988
2012
|
common.makeDecryptionProcessor({
|
|
1989
2013
|
cipherFieldName: 'assemblyCipherData',
|
|
@@ -8583,6 +8607,9 @@ query ScenarioQuery(
|
|
|
8583
8607
|
id
|
|
8584
8608
|
}
|
|
8585
8609
|
accessRole
|
|
8610
|
+
|
|
8611
|
+
# The itemKey is the same as directory.keyId. It's here so we can detect
|
|
8612
|
+
# when the directory key has been rotated.
|
|
8586
8613
|
itemKey {
|
|
8587
8614
|
id
|
|
8588
8615
|
}
|
|
@@ -8602,9 +8629,16 @@ query ScenarioQuery(
|
|
|
8602
8629
|
id
|
|
8603
8630
|
}
|
|
8604
8631
|
accessRole
|
|
8632
|
+
|
|
8633
|
+
# The itemKey is the same as file.keyId. It's here so we can detect
|
|
8634
|
+
# when the file key has been rotated.
|
|
8605
8635
|
itemKey {
|
|
8606
8636
|
id
|
|
8607
8637
|
}
|
|
8638
|
+
file {
|
|
8639
|
+
id
|
|
8640
|
+
keyId
|
|
8641
|
+
}
|
|
8608
8642
|
}
|
|
8609
8643
|
}
|
|
8610
8644
|
}
|
|
@@ -8726,6 +8760,8 @@ let ScenarioService = class ScenarioService extends LrService {
|
|
|
8726
8760
|
this.encryptionService = encryptionService;
|
|
8727
8761
|
this.prepareAddReceiverDirectory = this.prepareReceiverDirectory;
|
|
8728
8762
|
this.prepareUpdateReceiverDirectory = this.prepareReceiverDirectory;
|
|
8763
|
+
this.prepareAddReceiverFile = this.prepareReceiverFile;
|
|
8764
|
+
this.prepareUpdateReceiverFile = this.prepareReceiverFile;
|
|
8729
8765
|
}
|
|
8730
8766
|
// Scenarios
|
|
8731
8767
|
createScenario(options) {
|
|
@@ -9018,38 +9054,86 @@ let ScenarioService = class ScenarioService extends LrService {
|
|
|
9018
9054
|
};
|
|
9019
9055
|
});
|
|
9020
9056
|
}
|
|
9021
|
-
|
|
9057
|
+
prepareReceiverItem(options) {
|
|
9022
9058
|
return __awaiter(this, void 0, void 0, function* () {
|
|
9023
|
-
|
|
9024
|
-
|
|
9025
|
-
|
|
9026
|
-
|
|
9027
|
-
|
|
9059
|
+
const { receiverItemOptions, receiverSharedKey, assemblyKey, directory, file, } = options;
|
|
9060
|
+
assert_xor({ directory, file });
|
|
9061
|
+
const { accessRole } = receiverItemOptions;
|
|
9062
|
+
if (accessRole == AccessRoleChoice.DENY) {
|
|
9063
|
+
const ret = {
|
|
9064
|
+
accessRole,
|
|
9028
9065
|
wrappedItemKey: null,
|
|
9029
9066
|
sharedCipherData: null,
|
|
9030
9067
|
};
|
|
9068
|
+
if (directory) {
|
|
9069
|
+
// Cryptographic access to item is not required.
|
|
9070
|
+
return Object.assign(Object.assign({}, ret), { directoryId: directory.id });
|
|
9071
|
+
}
|
|
9072
|
+
else {
|
|
9073
|
+
return Object.assign(Object.assign({}, ret), { fileId: file.id });
|
|
9074
|
+
}
|
|
9031
9075
|
}
|
|
9032
9076
|
else {
|
|
9033
9077
|
// TODO this should be batched
|
|
9034
|
-
|
|
9035
|
-
|
|
9036
|
-
|
|
9078
|
+
let itemKey;
|
|
9079
|
+
if (directory) {
|
|
9080
|
+
itemKey = yield this.itemService.getDirectoryKey(directory.id, directory.keyId);
|
|
9081
|
+
}
|
|
9082
|
+
else {
|
|
9083
|
+
itemKey = yield this.itemService.getFileKey(file.id, file.keyId);
|
|
9084
|
+
}
|
|
9085
|
+
let wrappedItemKey = yield this.keyGraph.encryptToString(receiverSharedKey, itemKey.jwk.toJSON(true));
|
|
9086
|
+
const sharedCipherData = yield this.keyGraph.encryptToString(receiverSharedKey, receiverItemOptions.sharedCipherDataClearJson || '');
|
|
9037
9087
|
wrappedItemKey = yield this.keyGraph.encryptToString(assemblyKey, wrappedItemKey);
|
|
9038
|
-
|
|
9039
|
-
|
|
9040
|
-
accessRole: options.accessRole,
|
|
9088
|
+
const ret = {
|
|
9089
|
+
accessRole,
|
|
9041
9090
|
wrappedItemKey,
|
|
9042
9091
|
sharedCipherData,
|
|
9043
9092
|
};
|
|
9093
|
+
if (directory) {
|
|
9094
|
+
return Object.assign(Object.assign({}, ret), { directoryId: directory.id });
|
|
9095
|
+
}
|
|
9096
|
+
else {
|
|
9097
|
+
return Object.assign(Object.assign({}, ret), { fileId: file.id });
|
|
9098
|
+
}
|
|
9044
9099
|
}
|
|
9045
9100
|
});
|
|
9046
9101
|
}
|
|
9102
|
+
prepareReceiverDirectory(options, receiverSharedKey, assemblyKey) {
|
|
9103
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
9104
|
+
return this.prepareReceiverItem({
|
|
9105
|
+
receiverItemOptions: options,
|
|
9106
|
+
receiverSharedKey,
|
|
9107
|
+
assemblyKey,
|
|
9108
|
+
directory: {
|
|
9109
|
+
id: options.directoryId,
|
|
9110
|
+
keyId: options.directoryKeyId,
|
|
9111
|
+
},
|
|
9112
|
+
});
|
|
9113
|
+
});
|
|
9114
|
+
}
|
|
9115
|
+
prepareReceiverFile(options, receiverSharedKey, assemblyKey) {
|
|
9116
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
9117
|
+
return this.prepareReceiverItem({
|
|
9118
|
+
receiverItemOptions: options,
|
|
9119
|
+
receiverSharedKey,
|
|
9120
|
+
assemblyKey,
|
|
9121
|
+
file: {
|
|
9122
|
+
id: options.fileId,
|
|
9123
|
+
keyId: options.fileKeyId,
|
|
9124
|
+
},
|
|
9125
|
+
});
|
|
9126
|
+
});
|
|
9127
|
+
}
|
|
9047
9128
|
prepareCreateReceiver(options, assemblyKey) {
|
|
9048
9129
|
return __awaiter(this, void 0, void 0, function* () {
|
|
9049
9130
|
const { sharedKey, mutationInput } = yield this.prepareCreateParticipant(options);
|
|
9050
9131
|
const addDirectories = options.addDirectories &&
|
|
9051
9132
|
(yield Promise.all(options.addDirectories.map((x) => this.prepareAddReceiverDirectory(x, sharedKey.key, assemblyKey))));
|
|
9052
|
-
|
|
9133
|
+
const addFiles = options.addFiles &&
|
|
9134
|
+
(yield Promise.all(options.addFiles.map((x) => this.prepareAddReceiverFile(x, sharedKey.key, assemblyKey))));
|
|
9135
|
+
return Object.assign(Object.assign({}, mutationInput), { addDirectories,
|
|
9136
|
+
addFiles });
|
|
9053
9137
|
});
|
|
9054
9138
|
}
|
|
9055
9139
|
prepareUpdateReceiver(options, assemblyKey, existingReceiver) {
|
|
@@ -9057,6 +9141,8 @@ let ScenarioService = class ScenarioService extends LrService {
|
|
|
9057
9141
|
const sharedKeyId = existingReceiver.sharedKey.id;
|
|
9058
9142
|
const deleteDirectoriesOptions = options.deleteDirectories || [];
|
|
9059
9143
|
const updateDirectoriesOptions = options.updateDirectories || [];
|
|
9144
|
+
const deleteFilesOptions = options.deleteFiles || [];
|
|
9145
|
+
const updateFilesOptions = options.updateFiles || [];
|
|
9060
9146
|
// Fill in any missing update directories
|
|
9061
9147
|
mapEdges(existingReceiver.receiverItems.receiverDirectories).forEach((existingDirectory) => {
|
|
9062
9148
|
if (deleteDirectoriesOptions.includes(existingDirectory.directory.id)) {
|
|
@@ -9068,30 +9154,58 @@ let ScenarioService = class ScenarioService extends LrService {
|
|
|
9068
9154
|
updateDirectoriesOptions.push({
|
|
9069
9155
|
accessRole: existingDirectory.accessRole,
|
|
9070
9156
|
directoryId: existingDirectory.directory.id,
|
|
9157
|
+
directoryKeyId: existingDirectory.directory.keyId,
|
|
9071
9158
|
sharedCipherDataClearJson: existingDirectory.sharedCipherDataClearJson,
|
|
9072
9159
|
});
|
|
9073
9160
|
});
|
|
9161
|
+
// Fill in any missing update directories
|
|
9162
|
+
mapEdges(existingReceiver.receiverItems.receiverFiles).forEach((existingFile) => {
|
|
9163
|
+
if (deleteFilesOptions.includes(existingFile.file.id)) {
|
|
9164
|
+
return;
|
|
9165
|
+
}
|
|
9166
|
+
if (updateFilesOptions.find((x) => x.fileId === existingFile.file.id)) {
|
|
9167
|
+
return;
|
|
9168
|
+
}
|
|
9169
|
+
updateFilesOptions.push({
|
|
9170
|
+
accessRole: existingFile.accessRole,
|
|
9171
|
+
fileId: existingFile.file.id,
|
|
9172
|
+
fileKeyId: existingFile.file.keyId,
|
|
9173
|
+
sharedCipherDataClearJson: existingFile.sharedCipherDataClearJson,
|
|
9174
|
+
});
|
|
9175
|
+
});
|
|
9074
9176
|
const { sharedKey, mutationInput } = yield this.prepareUpdateParticipant(options, sharedKeyId);
|
|
9075
9177
|
const addDirectories = options.addDirectories &&
|
|
9076
9178
|
(yield Promise.all(options.addDirectories.map((x) => this.prepareAddReceiverDirectory(x, sharedKey, assemblyKey))));
|
|
9179
|
+
const addFiles = options.addFiles &&
|
|
9180
|
+
(yield Promise.all(options.addFiles.map((x) => this.prepareAddReceiverFile(x, sharedKey, assemblyKey))));
|
|
9077
9181
|
const updateDirectories = yield Promise.all(updateDirectoriesOptions.map((x) => this.prepareUpdateReceiverDirectory(x, sharedKey, assemblyKey)));
|
|
9182
|
+
const updateFiles = yield Promise.all(updateFilesOptions.map((x) => this.prepareUpdateReceiverFile(x, sharedKey, assemblyKey)));
|
|
9078
9183
|
return Object.assign(Object.assign({}, mutationInput), { addDirectories,
|
|
9079
|
-
|
|
9184
|
+
addFiles,
|
|
9185
|
+
updateDirectories,
|
|
9186
|
+
updateFiles, deleteDirectories: options.deleteDirectories, deleteFiles: options.deleteFiles });
|
|
9080
9187
|
});
|
|
9081
9188
|
}
|
|
9082
9189
|
prepareExistingReceiver(existingReceiver, assemblyKey) {
|
|
9083
9190
|
return __awaiter(this, void 0, void 0, function* () {
|
|
9084
|
-
const updateDirectories = mapEdges(existingReceiver.receiverItems.receiverDirectories).map((
|
|
9085
|
-
|
|
9086
|
-
|
|
9087
|
-
|
|
9088
|
-
|
|
9191
|
+
const updateDirectories = mapEdges(existingReceiver.receiverItems.receiverDirectories).map(({ accessRole, sharedCipherDataClearJson, directory }) => ({
|
|
9192
|
+
accessRole,
|
|
9193
|
+
sharedCipherDataClearJson,
|
|
9194
|
+
directoryId: directory.id,
|
|
9195
|
+
directoryKeyId: directory.keyId,
|
|
9196
|
+
}));
|
|
9197
|
+
const updateFiles = mapEdges(existingReceiver.receiverItems.receiverFiles).map(({ accessRole, sharedCipherDataClearJson, file }) => ({
|
|
9198
|
+
accessRole,
|
|
9199
|
+
sharedCipherDataClearJson,
|
|
9200
|
+
fileId: file.id,
|
|
9201
|
+
fileKeyId: file.keyId,
|
|
9089
9202
|
}));
|
|
9090
9203
|
// Fill it in with existing receiver.
|
|
9091
9204
|
return this.prepareUpdateReceiver({
|
|
9092
9205
|
tpId: existingReceiver.tp.id,
|
|
9093
9206
|
sharedCipherDataClearJson: existingReceiver.sharedCipherDataClearJson,
|
|
9094
9207
|
updateDirectories,
|
|
9208
|
+
updateFiles,
|
|
9095
9209
|
}, assemblyKey, existingReceiver);
|
|
9096
9210
|
});
|
|
9097
9211
|
}
|