@lifeready/core 8.0.6 → 8.0.7
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 +168 -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/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 +121 -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_;
|
|
@@ -8583,6 +8595,9 @@ query ScenarioQuery(
|
|
|
8583
8595
|
id
|
|
8584
8596
|
}
|
|
8585
8597
|
accessRole
|
|
8598
|
+
|
|
8599
|
+
# The itemKey is the same as directory.keyId. It's here so we can detect
|
|
8600
|
+
# when the directory key has been rotated.
|
|
8586
8601
|
itemKey {
|
|
8587
8602
|
id
|
|
8588
8603
|
}
|
|
@@ -8602,9 +8617,16 @@ query ScenarioQuery(
|
|
|
8602
8617
|
id
|
|
8603
8618
|
}
|
|
8604
8619
|
accessRole
|
|
8620
|
+
|
|
8621
|
+
# The itemKey is the same as file.keyId. It's here so we can detect
|
|
8622
|
+
# when the file key has been rotated.
|
|
8605
8623
|
itemKey {
|
|
8606
8624
|
id
|
|
8607
8625
|
}
|
|
8626
|
+
file {
|
|
8627
|
+
id
|
|
8628
|
+
keyId
|
|
8629
|
+
}
|
|
8608
8630
|
}
|
|
8609
8631
|
}
|
|
8610
8632
|
}
|
|
@@ -8726,6 +8748,8 @@ let ScenarioService = class ScenarioService extends LrService {
|
|
|
8726
8748
|
this.encryptionService = encryptionService;
|
|
8727
8749
|
this.prepareAddReceiverDirectory = this.prepareReceiverDirectory;
|
|
8728
8750
|
this.prepareUpdateReceiverDirectory = this.prepareReceiverDirectory;
|
|
8751
|
+
this.prepareAddReceiverFile = this.prepareReceiverFile;
|
|
8752
|
+
this.prepareUpdateReceiverFile = this.prepareReceiverFile;
|
|
8729
8753
|
}
|
|
8730
8754
|
// Scenarios
|
|
8731
8755
|
createScenario(options) {
|
|
@@ -9018,38 +9042,86 @@ let ScenarioService = class ScenarioService extends LrService {
|
|
|
9018
9042
|
};
|
|
9019
9043
|
});
|
|
9020
9044
|
}
|
|
9021
|
-
|
|
9045
|
+
prepareReceiverItem(options) {
|
|
9022
9046
|
return __awaiter(this, void 0, void 0, function* () {
|
|
9023
|
-
|
|
9024
|
-
|
|
9025
|
-
|
|
9026
|
-
|
|
9027
|
-
|
|
9047
|
+
const { receiverItemOptions, receiverSharedKey, assemblyKey, directory, file, } = options;
|
|
9048
|
+
assert_xor({ directory, file });
|
|
9049
|
+
const { accessRole } = receiverItemOptions;
|
|
9050
|
+
if (accessRole == AccessRoleChoice.DENY) {
|
|
9051
|
+
const ret = {
|
|
9052
|
+
accessRole,
|
|
9028
9053
|
wrappedItemKey: null,
|
|
9029
9054
|
sharedCipherData: null,
|
|
9030
9055
|
};
|
|
9056
|
+
if (directory) {
|
|
9057
|
+
// Cryptographic access to item is not required.
|
|
9058
|
+
return Object.assign(Object.assign({}, ret), { directoryId: directory.id });
|
|
9059
|
+
}
|
|
9060
|
+
else {
|
|
9061
|
+
return Object.assign(Object.assign({}, ret), { fileId: file.id });
|
|
9062
|
+
}
|
|
9031
9063
|
}
|
|
9032
9064
|
else {
|
|
9033
9065
|
// TODO this should be batched
|
|
9034
|
-
|
|
9035
|
-
|
|
9036
|
-
|
|
9066
|
+
let itemKey;
|
|
9067
|
+
if (directory) {
|
|
9068
|
+
itemKey = yield this.itemService.getDirectoryKey(directory.id, directory.keyId);
|
|
9069
|
+
}
|
|
9070
|
+
else {
|
|
9071
|
+
itemKey = yield this.itemService.getFileKey(file.id, file.keyId);
|
|
9072
|
+
}
|
|
9073
|
+
let wrappedItemKey = yield this.keyGraph.encryptToString(receiverSharedKey, itemKey.jwk.toJSON(true));
|
|
9074
|
+
const sharedCipherData = yield this.keyGraph.encryptToString(receiverSharedKey, receiverItemOptions.sharedCipherDataClearJson || '');
|
|
9037
9075
|
wrappedItemKey = yield this.keyGraph.encryptToString(assemblyKey, wrappedItemKey);
|
|
9038
|
-
|
|
9039
|
-
|
|
9040
|
-
accessRole: options.accessRole,
|
|
9076
|
+
const ret = {
|
|
9077
|
+
accessRole,
|
|
9041
9078
|
wrappedItemKey,
|
|
9042
9079
|
sharedCipherData,
|
|
9043
9080
|
};
|
|
9081
|
+
if (directory) {
|
|
9082
|
+
return Object.assign(Object.assign({}, ret), { directoryId: directory.id });
|
|
9083
|
+
}
|
|
9084
|
+
else {
|
|
9085
|
+
return Object.assign(Object.assign({}, ret), { fileId: file.id });
|
|
9086
|
+
}
|
|
9044
9087
|
}
|
|
9045
9088
|
});
|
|
9046
9089
|
}
|
|
9090
|
+
prepareReceiverDirectory(options, receiverSharedKey, assemblyKey) {
|
|
9091
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
9092
|
+
return this.prepareReceiverItem({
|
|
9093
|
+
receiverItemOptions: options,
|
|
9094
|
+
receiverSharedKey,
|
|
9095
|
+
assemblyKey,
|
|
9096
|
+
directory: {
|
|
9097
|
+
id: options.directoryId,
|
|
9098
|
+
keyId: options.directoryKeyId,
|
|
9099
|
+
},
|
|
9100
|
+
});
|
|
9101
|
+
});
|
|
9102
|
+
}
|
|
9103
|
+
prepareReceiverFile(options, receiverSharedKey, assemblyKey) {
|
|
9104
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
9105
|
+
return this.prepareReceiverItem({
|
|
9106
|
+
receiverItemOptions: options,
|
|
9107
|
+
receiverSharedKey,
|
|
9108
|
+
assemblyKey,
|
|
9109
|
+
file: {
|
|
9110
|
+
id: options.fileId,
|
|
9111
|
+
keyId: options.fileKeyId,
|
|
9112
|
+
},
|
|
9113
|
+
});
|
|
9114
|
+
});
|
|
9115
|
+
}
|
|
9047
9116
|
prepareCreateReceiver(options, assemblyKey) {
|
|
9048
9117
|
return __awaiter(this, void 0, void 0, function* () {
|
|
9049
9118
|
const { sharedKey, mutationInput } = yield this.prepareCreateParticipant(options);
|
|
9050
9119
|
const addDirectories = options.addDirectories &&
|
|
9051
9120
|
(yield Promise.all(options.addDirectories.map((x) => this.prepareAddReceiverDirectory(x, sharedKey.key, assemblyKey))));
|
|
9052
|
-
|
|
9121
|
+
const addFiles = options.addFiles &&
|
|
9122
|
+
(yield Promise.all(options.addFiles.map((x) => this.prepareAddReceiverFile(x, sharedKey.key, assemblyKey))));
|
|
9123
|
+
return Object.assign(Object.assign({}, mutationInput), { addDirectories,
|
|
9124
|
+
addFiles });
|
|
9053
9125
|
});
|
|
9054
9126
|
}
|
|
9055
9127
|
prepareUpdateReceiver(options, assemblyKey, existingReceiver) {
|
|
@@ -9057,6 +9129,8 @@ let ScenarioService = class ScenarioService extends LrService {
|
|
|
9057
9129
|
const sharedKeyId = existingReceiver.sharedKey.id;
|
|
9058
9130
|
const deleteDirectoriesOptions = options.deleteDirectories || [];
|
|
9059
9131
|
const updateDirectoriesOptions = options.updateDirectories || [];
|
|
9132
|
+
const deleteFilesOptions = options.deleteFiles || [];
|
|
9133
|
+
const updateFilesOptions = options.updateFiles || [];
|
|
9060
9134
|
// Fill in any missing update directories
|
|
9061
9135
|
mapEdges(existingReceiver.receiverItems.receiverDirectories).forEach((existingDirectory) => {
|
|
9062
9136
|
if (deleteDirectoriesOptions.includes(existingDirectory.directory.id)) {
|
|
@@ -9068,30 +9142,58 @@ let ScenarioService = class ScenarioService extends LrService {
|
|
|
9068
9142
|
updateDirectoriesOptions.push({
|
|
9069
9143
|
accessRole: existingDirectory.accessRole,
|
|
9070
9144
|
directoryId: existingDirectory.directory.id,
|
|
9145
|
+
directoryKeyId: existingDirectory.directory.keyId,
|
|
9071
9146
|
sharedCipherDataClearJson: existingDirectory.sharedCipherDataClearJson,
|
|
9072
9147
|
});
|
|
9073
9148
|
});
|
|
9149
|
+
// Fill in any missing update directories
|
|
9150
|
+
mapEdges(existingReceiver.receiverItems.receiverFiles).forEach((existingFile) => {
|
|
9151
|
+
if (deleteFilesOptions.includes(existingFile.file.id)) {
|
|
9152
|
+
return;
|
|
9153
|
+
}
|
|
9154
|
+
if (updateFilesOptions.find((x) => x.fileId === existingFile.file.id)) {
|
|
9155
|
+
return;
|
|
9156
|
+
}
|
|
9157
|
+
updateFilesOptions.push({
|
|
9158
|
+
accessRole: existingFile.accessRole,
|
|
9159
|
+
fileId: existingFile.file.id,
|
|
9160
|
+
fileKeyId: existingFile.file.keyId,
|
|
9161
|
+
sharedCipherDataClearJson: existingFile.sharedCipherDataClearJson,
|
|
9162
|
+
});
|
|
9163
|
+
});
|
|
9074
9164
|
const { sharedKey, mutationInput } = yield this.prepareUpdateParticipant(options, sharedKeyId);
|
|
9075
9165
|
const addDirectories = options.addDirectories &&
|
|
9076
9166
|
(yield Promise.all(options.addDirectories.map((x) => this.prepareAddReceiverDirectory(x, sharedKey, assemblyKey))));
|
|
9167
|
+
const addFiles = options.addFiles &&
|
|
9168
|
+
(yield Promise.all(options.addFiles.map((x) => this.prepareAddReceiverFile(x, sharedKey, assemblyKey))));
|
|
9077
9169
|
const updateDirectories = yield Promise.all(updateDirectoriesOptions.map((x) => this.prepareUpdateReceiverDirectory(x, sharedKey, assemblyKey)));
|
|
9170
|
+
const updateFiles = yield Promise.all(updateFilesOptions.map((x) => this.prepareUpdateReceiverFile(x, sharedKey, assemblyKey)));
|
|
9078
9171
|
return Object.assign(Object.assign({}, mutationInput), { addDirectories,
|
|
9079
|
-
|
|
9172
|
+
addFiles,
|
|
9173
|
+
updateDirectories,
|
|
9174
|
+
updateFiles, deleteDirectories: options.deleteDirectories, deleteFiles: options.deleteFiles });
|
|
9080
9175
|
});
|
|
9081
9176
|
}
|
|
9082
9177
|
prepareExistingReceiver(existingReceiver, assemblyKey) {
|
|
9083
9178
|
return __awaiter(this, void 0, void 0, function* () {
|
|
9084
|
-
const updateDirectories = mapEdges(existingReceiver.receiverItems.receiverDirectories).map((
|
|
9085
|
-
|
|
9086
|
-
|
|
9087
|
-
|
|
9088
|
-
|
|
9179
|
+
const updateDirectories = mapEdges(existingReceiver.receiverItems.receiverDirectories).map(({ accessRole, sharedCipherDataClearJson, directory }) => ({
|
|
9180
|
+
accessRole,
|
|
9181
|
+
sharedCipherDataClearJson,
|
|
9182
|
+
directoryId: directory.id,
|
|
9183
|
+
directoryKeyId: directory.keyId,
|
|
9184
|
+
}));
|
|
9185
|
+
const updateFiles = mapEdges(existingReceiver.receiverItems.receiverFiles).map(({ accessRole, sharedCipherDataClearJson, file }) => ({
|
|
9186
|
+
accessRole,
|
|
9187
|
+
sharedCipherDataClearJson,
|
|
9188
|
+
fileId: file.id,
|
|
9189
|
+
fileKeyId: file.keyId,
|
|
9089
9190
|
}));
|
|
9090
9191
|
// Fill it in with existing receiver.
|
|
9091
9192
|
return this.prepareUpdateReceiver({
|
|
9092
9193
|
tpId: existingReceiver.tp.id,
|
|
9093
9194
|
sharedCipherDataClearJson: existingReceiver.sharedCipherDataClearJson,
|
|
9094
9195
|
updateDirectories,
|
|
9196
|
+
updateFiles,
|
|
9095
9197
|
}, assemblyKey, existingReceiver);
|
|
9096
9198
|
});
|
|
9097
9199
|
}
|