@coveo/push-api-client 3.0.116 → 3.0.122
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/dist/APICore.js +47 -47
- package/dist/APICore.js.map +1 -1
- package/dist/definitions/APICore.d.ts +18 -18
- package/dist/definitions/document.d.ts +124 -124
- package/dist/definitions/documentBuilder.d.ts +168 -168
- package/dist/definitions/documentBuilder.spec.d.ts +1 -1
- package/dist/definitions/environment.d.ts +16 -16
- package/dist/definitions/errors/baseError.d.ts +4 -4
- package/dist/definitions/errors/fieldErrors.d.ts +18 -18
- package/dist/definitions/errors/index.d.ts +3 -3
- package/dist/definitions/errors/privilegeError.d.ts +6 -6
- package/dist/definitions/errors/validatorErrors.d.ts +20 -20
- package/dist/definitions/fieldAnalyser/fieldAnalyser.d.ts +36 -36
- package/dist/definitions/fieldAnalyser/fieldAnalyser.spec.d.ts +1 -1
- package/dist/definitions/fieldAnalyser/fieldStore.d.ts +5 -5
- package/dist/definitions/fieldAnalyser/fieldUtils.d.ts +6 -6
- package/dist/definitions/fieldAnalyser/fieldsUtils.spec.d.ts +1 -1
- package/dist/definitions/fieldAnalyser/inconsistencies.d.ts +5 -5
- package/dist/definitions/fieldAnalyser/inconsistencies.spec.d.ts +1 -1
- package/dist/definitions/fieldAnalyser/typeUtils.d.ts +3 -3
- package/dist/definitions/fieldAnalyser/typeUtils.spec.d.ts +1 -1
- package/dist/definitions/help/file.d.ts +3 -3
- package/dist/definitions/help/file.spec.d.ts +1 -1
- package/dist/definitions/help/fileConsumer.d.ts +31 -31
- package/dist/definitions/help/fileConsumer.spec.d.ts +1 -1
- package/dist/definitions/help/fileContainer.d.ts +8 -8
- package/dist/definitions/help/fileContainer.spec.d.ts +1 -1
- package/dist/definitions/help/function.d.ts +1 -1
- package/dist/definitions/help/generator.d.ts +11 -11
- package/dist/definitions/help/generator.spec.d.ts +1 -1
- package/dist/definitions/help/urlUtils.d.ts +27 -27
- package/dist/definitions/help/urlUtils.spec.d.ts +1 -1
- package/dist/definitions/index.d.ts +14 -14
- package/dist/definitions/interfaces.d.ts +70 -70
- package/dist/definitions/localtest.d.ts +1 -1
- package/dist/definitions/permissionSetBuilder.d.ts +34 -34
- package/dist/definitions/permissionSetBuilder.spec.d.ts +1 -1
- package/dist/definitions/securityIdentityBuilder.d.ts +105 -105
- package/dist/definitions/securityIdentityBuilder.spec.d.ts +1 -1
- package/dist/definitions/source/batchUploadDocumentsFromFile.d.ts +11 -11
- package/dist/definitions/source/batchUploadDocumentsFromFile.spec.d.ts +1 -1
- package/dist/definitions/source/catalog.d.ts +70 -70
- package/dist/definitions/source/catalog.spec.d.ts +1 -1
- package/dist/definitions/source/documentUploader.d.ts +11 -11
- package/dist/definitions/source/documentUploader.spec.d.ts +1 -1
- package/dist/definitions/source/push.d.ts +87 -87
- package/dist/definitions/source/push.spec.d.ts +1 -1
- package/dist/definitions/source/securityIdenty.d.ts +43 -43
- package/dist/definitions/uploadStrategy/fileContainerStrategy.d.ts +23 -23
- package/dist/definitions/uploadStrategy/fileContainerStrategy.spec.d.ts +1 -1
- package/dist/definitions/uploadStrategy/index.d.ts +3 -3
- package/dist/definitions/uploadStrategy/strategy.d.ts +23 -23
- package/dist/definitions/uploadStrategy/streamChunkStrategy.d.ts +28 -28
- package/dist/definitions/uploadStrategy/streamChunkStrategy.spec.d.ts +1 -1
- package/dist/definitions/validation/caseInsensitiveDocument.d.ts +13 -13
- package/dist/definitions/validation/knownKey.d.ts +10 -10
- package/dist/definitions/validation/parseFile.d.ts +4 -4
- package/dist/definitions/validation/parseFile.spec.d.ts +1 -1
- package/dist/definitions/validation/parsePermissions.d.ts +5 -5
- package/dist/definitions/validation/parsePermissions.spec.d.ts +1 -1
- package/dist/definitions/validation/preconditions/apiKeyPrivilege.d.ts +3 -3
- package/dist/definitions/validation/preconditions/apiKeyPrivilege.spec.d.ts +1 -1
- package/dist/definitions/validation/preconditions/platformPrivilege.d.ts +7 -7
- package/dist/definitions/validation/requiredKeyValidator.d.ts +17 -17
- package/dist/definitions/validation/transformers/transformer.d.ts +31 -31
- package/dist/definitions/validation/transformers/transformer.spec.d.ts +1 -1
- package/dist/document.js +2 -2
- package/dist/documentBuilder.js +292 -292
- package/dist/documentBuilder.spec.js +191 -191
- package/dist/environment.js +41 -41
- package/dist/errors/baseError.js +10 -10
- package/dist/errors/fieldErrors.js +42 -42
- package/dist/errors/index.js +19 -19
- package/dist/errors/privilegeError.js +12 -12
- package/dist/errors/validatorErrors.js +40 -40
- package/dist/fieldAnalyser/fieldAnalyser.js +95 -95
- package/dist/fieldAnalyser/fieldAnalyser.spec.js +230 -230
- package/dist/fieldAnalyser/fieldStore.js +21 -21
- package/dist/fieldAnalyser/fieldUtils.js +41 -41
- package/dist/fieldAnalyser/fieldsUtils.spec.js +116 -116
- package/dist/fieldAnalyser/inconsistencies.js +14 -14
- package/dist/fieldAnalyser/inconsistencies.spec.js +40 -40
- package/dist/fieldAnalyser/typeUtils.js +61 -61
- package/dist/fieldAnalyser/typeUtils.spec.js +142 -142
- package/dist/help/file.js +37 -37
- package/dist/help/file.spec.js +67 -67
- package/dist/help/fileConsumer.js +150 -150
- package/dist/help/fileConsumer.spec.js +153 -153
- package/dist/help/fileContainer.js +48 -48
- package/dist/help/fileContainer.spec.js +65 -65
- package/dist/help/function.js +5 -5
- package/dist/help/generator.js +32 -32
- package/dist/help/generator.spec.js +82 -82
- package/dist/help/urlUtils.js +42 -42
- package/dist/help/urlUtils.spec.js +41 -41
- package/dist/index.js +38 -38
- package/dist/interfaces.js +2 -2
- package/dist/localtest.js +55 -55
- package/dist/permissionSetBuilder.js +58 -58
- package/dist/permissionSetBuilder.spec.js +68 -68
- package/dist/securityIdentityBuilder.js +128 -128
- package/dist/securityIdentityBuilder.spec.js +50 -50
- package/dist/source/batchUploadDocumentsFromFile.js +46 -46
- package/dist/source/batchUploadDocumentsFromFile.spec.js +145 -145
- package/dist/source/catalog.js +111 -111
- package/dist/source/catalog.spec.js +64 -64
- package/dist/source/documentUploader.js +45 -45
- package/dist/source/documentUploader.spec.js +118 -118
- package/dist/source/push.js +140 -140
- package/dist/source/push.spec.js +152 -152
- package/dist/source/securityIdenty.js +57 -57
- package/dist/uploadStrategy/fileContainerStrategy.js +32 -32
- package/dist/uploadStrategy/fileContainerStrategy.spec.js +86 -86
- package/dist/uploadStrategy/index.js +19 -19
- package/dist/uploadStrategy/strategy.js +2 -2
- package/dist/uploadStrategy/streamChunkStrategy.js +52 -52
- package/dist/uploadStrategy/streamChunkStrategy.spec.js +77 -77
- package/dist/validation/caseInsensitiveDocument.js +31 -31
- package/dist/validation/knownKey.js +37 -37
- package/dist/validation/parseFile.js +120 -120
- package/dist/validation/parseFile.spec.js +96 -96
- package/dist/validation/parsePermissions.js +118 -118
- package/dist/validation/parsePermissions.spec.js +86 -86
- package/dist/validation/preconditions/apiKeyPrivilege.js +20 -20
- package/dist/validation/preconditions/apiKeyPrivilege.spec.js +66 -66
- package/dist/validation/preconditions/platformPrivilege.js +32 -32
- package/dist/validation/requiredKeyValidator.js +61 -61
- package/dist/validation/transformers/transformer.js +51 -51
- package/dist/validation/transformers/transformer.spec.js +21 -21
- package/package.json +11 -11
@@ -1,119 +1,119 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.processPermissionList = void 0;
|
4
|
-
const bueno_1 = require("@coveo/bueno");
|
5
|
-
const securityIdentityBuilder_1 = require("../securityIdentityBuilder");
|
6
|
-
const caseInsensitiveDocument_1 = require("./caseInsensitiveDocument");
|
7
|
-
const errors_1 = require("../errors");
|
8
|
-
const knownKey_1 = require("./knownKey");
|
9
|
-
const permissionSetBuilder_1 = require("../permissionSetBuilder");
|
10
|
-
const requiredKeyValidator_1 = require("./requiredKeyValidator");
|
11
|
-
const platform_client_1 = require("@coveo/platform-client");
|
12
|
-
class PermissionParser {
|
13
|
-
constructor(caseInsensitiveDoc, documentBuilder, documentPath) {
|
14
|
-
this.caseInsensitiveDoc = caseInsensitiveDoc;
|
15
|
-
this.documentBuilder = documentBuilder;
|
16
|
-
this.documentPath = documentPath;
|
17
|
-
this.processPermissionSet = (permissionSet) => {
|
18
|
-
const permissionSetBuilder = this.validateRequiredPermissionSetKeysAndGetPermissionSetBuilder(permissionSet);
|
19
|
-
this.documentBuilder.withPermissionSet(permissionSetBuilder);
|
20
|
-
};
|
21
|
-
}
|
22
|
-
processPermissionList() {
|
23
|
-
this.ensurePermissionArray();
|
24
|
-
new knownKey_1.KnownKeys('permissions', this.caseInsensitiveDoc).whenExists((permissions) => {
|
25
|
-
permissions.forEach((permission) => {
|
26
|
-
const caseInsensitivePermission = new caseInsensitiveDocument_1.CaseInsensitiveDocument(permission);
|
27
|
-
new knownKey_1.KnownKeys('permissionsets', caseInsensitivePermission)
|
28
|
-
.whenExists((permissionLevel) => this.processPermissionLevel(permissionLevel))
|
29
|
-
.whenDoesNotExist((permissionSet) => this.processPermissionSet(permissionSet));
|
30
|
-
});
|
31
|
-
this.caseInsensitiveDoc.remove('permissions');
|
32
|
-
});
|
33
|
-
}
|
34
|
-
processPermissionLevel(permission) {
|
35
|
-
// TODO: require at least some permissions
|
36
|
-
const permissionSetBuilders = permission.permissionSets.map((permissionSet) => {
|
37
|
-
const caseInsensitivePermissions = new caseInsensitiveDocument_1.CaseInsensitiveDocument(permission);
|
38
|
-
const { isValid, explanation } = new requiredKeyValidator_1.RequiredKeyValidator('name', caseInsensitivePermissions, new bueno_1.StringValue({ required: true, emptyAllowed: false }));
|
39
|
-
if (!isValid) {
|
40
|
-
this.throwInvalidDocumentError(explanation);
|
41
|
-
}
|
42
|
-
return this.validateRequiredPermissionSetKeysAndGetPermissionSetBuilder(permissionSet);
|
43
|
-
});
|
44
|
-
// TODO: prevent empty permission set
|
45
|
-
this.documentBuilder.withPermissionLevel(permission.name, permissionSetBuilders);
|
46
|
-
}
|
47
|
-
validateAllowAnonymous(caseInsensitivePermissions) {
|
48
|
-
const { isValid, explanation, value } = new requiredKeyValidator_1.RequiredKeyValidator('allowanonymous', caseInsensitivePermissions, new bueno_1.BooleanValue({ required: true }));
|
49
|
-
if (!isValid) {
|
50
|
-
this.throwInvalidDocumentError(explanation);
|
51
|
-
}
|
52
|
-
return value;
|
53
|
-
}
|
54
|
-
validatePermission(permissionLogic, caseInsensitivePermissions) {
|
55
|
-
const { isValid, explanation, value } = new requiredKeyValidator_1.RequiredKeyValidator(permissionLogic, caseInsensitivePermissions, this.getSecurityIdentitySchemaValidation());
|
56
|
-
if (!isValid) {
|
57
|
-
this.throwInvalidDocumentError(explanation);
|
58
|
-
}
|
59
|
-
return value;
|
60
|
-
}
|
61
|
-
validateRequiredPermissionSetKeysAndGetPermissionSetBuilder(permission) {
|
62
|
-
const caseInsensitivePermissions = new caseInsensitiveDocument_1.CaseInsensitiveDocument(permission);
|
63
|
-
const allowAnonymous = this.validateAllowAnonymous(caseInsensitivePermissions);
|
64
|
-
const allowedPermissions = this.validatePermission('allowedpermissions', caseInsensitivePermissions);
|
65
|
-
const deniedPermissions = this.validatePermission('deniedpermissions', caseInsensitivePermissions);
|
66
|
-
const permissionSetBuilder = new permissionSetBuilder_1.PermissionSetBuilder(allowAnonymous);
|
67
|
-
allowedPermissions === null || allowedPermissions === void 0 ? void 0 : allowedPermissions.forEach(({ identity, identityType, securityProvider }) => {
|
68
|
-
permissionSetBuilder.withAllowedPermissions(new securityIdentityBuilder_1.AnySecurityIdentityBuilder(identityType, identity, securityProvider));
|
69
|
-
});
|
70
|
-
deniedPermissions === null || deniedPermissions === void 0 ? void 0 : deniedPermissions.forEach(({ identity, identityType, securityProvider }) => {
|
71
|
-
permissionSetBuilder.withDeniedPermissions(new securityIdentityBuilder_1.AnySecurityIdentityBuilder(identityType, identity, securityProvider));
|
72
|
-
});
|
73
|
-
return permissionSetBuilder;
|
74
|
-
}
|
75
|
-
get identityTypeRegex() {
|
76
|
-
const identityTypesValues = Object.values(platform_client_1.PermissionIdentityType);
|
77
|
-
return new RegExp(identityTypesValues.join('|'), 'i');
|
78
|
-
}
|
79
|
-
getSecurityIdentitySchemaValidation() {
|
80
|
-
return new bueno_1.ArrayValue({
|
81
|
-
required: false,
|
82
|
-
each: new bueno_1.RecordValue({
|
83
|
-
values: {
|
84
|
-
identity: new bueno_1.StringValue({ required: true, emptyAllowed: false }),
|
85
|
-
identityType: new bueno_1.StringValue({
|
86
|
-
regex: this.identityTypeRegex,
|
87
|
-
required: true,
|
88
|
-
emptyAllowed: false,
|
89
|
-
}),
|
90
|
-
securityProvider: new bueno_1.StringValue({
|
91
|
-
emptyAllowed: true,
|
92
|
-
required: false,
|
93
|
-
}),
|
94
|
-
},
|
95
|
-
}),
|
96
|
-
});
|
97
|
-
}
|
98
|
-
ensurePermissionArray() {
|
99
|
-
const validator = (schema) => new requiredKeyValidator_1.RequiredKeyValidator('permissions', this.caseInsensitiveDoc, schema);
|
100
|
-
const { isValid, explanation } = validator(new bueno_1.ArrayValue({ required: false }));
|
101
|
-
const requiredAtLeastOnePermission = validator(new bueno_1.ArrayValue({ min: 1 }));
|
102
|
-
if (!isValid) {
|
103
|
-
this.throwInvalidDocumentError(explanation);
|
104
|
-
}
|
105
|
-
if (!requiredAtLeastOnePermission.isValid) {
|
106
|
-
// simply discard empty array permission instead of throwing
|
107
|
-
this.caseInsensitiveDoc.remove('permissions');
|
108
|
-
}
|
109
|
-
}
|
110
|
-
throwInvalidDocumentError(explanation) {
|
111
|
-
throw new errors_1.InvalidDocument(this.documentPath, this.caseInsensitiveDoc.originalDocument, explanation);
|
112
|
-
}
|
113
|
-
}
|
114
|
-
const processPermissionList = (caseInsensitiveDoc, documentBuilder, documentPath) => {
|
115
|
-
const parser = new PermissionParser(caseInsensitiveDoc, documentBuilder, documentPath);
|
116
|
-
return parser.processPermissionList();
|
117
|
-
};
|
118
|
-
exports.processPermissionList = processPermissionList;
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.processPermissionList = void 0;
|
4
|
+
const bueno_1 = require("@coveo/bueno");
|
5
|
+
const securityIdentityBuilder_1 = require("../securityIdentityBuilder");
|
6
|
+
const caseInsensitiveDocument_1 = require("./caseInsensitiveDocument");
|
7
|
+
const errors_1 = require("../errors");
|
8
|
+
const knownKey_1 = require("./knownKey");
|
9
|
+
const permissionSetBuilder_1 = require("../permissionSetBuilder");
|
10
|
+
const requiredKeyValidator_1 = require("./requiredKeyValidator");
|
11
|
+
const platform_client_1 = require("@coveo/platform-client");
|
12
|
+
class PermissionParser {
|
13
|
+
constructor(caseInsensitiveDoc, documentBuilder, documentPath) {
|
14
|
+
this.caseInsensitiveDoc = caseInsensitiveDoc;
|
15
|
+
this.documentBuilder = documentBuilder;
|
16
|
+
this.documentPath = documentPath;
|
17
|
+
this.processPermissionSet = (permissionSet) => {
|
18
|
+
const permissionSetBuilder = this.validateRequiredPermissionSetKeysAndGetPermissionSetBuilder(permissionSet);
|
19
|
+
this.documentBuilder.withPermissionSet(permissionSetBuilder);
|
20
|
+
};
|
21
|
+
}
|
22
|
+
processPermissionList() {
|
23
|
+
this.ensurePermissionArray();
|
24
|
+
new knownKey_1.KnownKeys('permissions', this.caseInsensitiveDoc).whenExists((permissions) => {
|
25
|
+
permissions.forEach((permission) => {
|
26
|
+
const caseInsensitivePermission = new caseInsensitiveDocument_1.CaseInsensitiveDocument(permission);
|
27
|
+
new knownKey_1.KnownKeys('permissionsets', caseInsensitivePermission)
|
28
|
+
.whenExists((permissionLevel) => this.processPermissionLevel(permissionLevel))
|
29
|
+
.whenDoesNotExist((permissionSet) => this.processPermissionSet(permissionSet));
|
30
|
+
});
|
31
|
+
this.caseInsensitiveDoc.remove('permissions');
|
32
|
+
});
|
33
|
+
}
|
34
|
+
processPermissionLevel(permission) {
|
35
|
+
// TODO: require at least some permissions
|
36
|
+
const permissionSetBuilders = permission.permissionSets.map((permissionSet) => {
|
37
|
+
const caseInsensitivePermissions = new caseInsensitiveDocument_1.CaseInsensitiveDocument(permission);
|
38
|
+
const { isValid, explanation } = new requiredKeyValidator_1.RequiredKeyValidator('name', caseInsensitivePermissions, new bueno_1.StringValue({ required: true, emptyAllowed: false }));
|
39
|
+
if (!isValid) {
|
40
|
+
this.throwInvalidDocumentError(explanation);
|
41
|
+
}
|
42
|
+
return this.validateRequiredPermissionSetKeysAndGetPermissionSetBuilder(permissionSet);
|
43
|
+
});
|
44
|
+
// TODO: prevent empty permission set
|
45
|
+
this.documentBuilder.withPermissionLevel(permission.name, permissionSetBuilders);
|
46
|
+
}
|
47
|
+
validateAllowAnonymous(caseInsensitivePermissions) {
|
48
|
+
const { isValid, explanation, value } = new requiredKeyValidator_1.RequiredKeyValidator('allowanonymous', caseInsensitivePermissions, new bueno_1.BooleanValue({ required: true }));
|
49
|
+
if (!isValid) {
|
50
|
+
this.throwInvalidDocumentError(explanation);
|
51
|
+
}
|
52
|
+
return value;
|
53
|
+
}
|
54
|
+
validatePermission(permissionLogic, caseInsensitivePermissions) {
|
55
|
+
const { isValid, explanation, value } = new requiredKeyValidator_1.RequiredKeyValidator(permissionLogic, caseInsensitivePermissions, this.getSecurityIdentitySchemaValidation());
|
56
|
+
if (!isValid) {
|
57
|
+
this.throwInvalidDocumentError(explanation);
|
58
|
+
}
|
59
|
+
return value;
|
60
|
+
}
|
61
|
+
validateRequiredPermissionSetKeysAndGetPermissionSetBuilder(permission) {
|
62
|
+
const caseInsensitivePermissions = new caseInsensitiveDocument_1.CaseInsensitiveDocument(permission);
|
63
|
+
const allowAnonymous = this.validateAllowAnonymous(caseInsensitivePermissions);
|
64
|
+
const allowedPermissions = this.validatePermission('allowedpermissions', caseInsensitivePermissions);
|
65
|
+
const deniedPermissions = this.validatePermission('deniedpermissions', caseInsensitivePermissions);
|
66
|
+
const permissionSetBuilder = new permissionSetBuilder_1.PermissionSetBuilder(allowAnonymous);
|
67
|
+
allowedPermissions === null || allowedPermissions === void 0 ? void 0 : allowedPermissions.forEach(({ identity, identityType, securityProvider }) => {
|
68
|
+
permissionSetBuilder.withAllowedPermissions(new securityIdentityBuilder_1.AnySecurityIdentityBuilder(identityType, identity, securityProvider));
|
69
|
+
});
|
70
|
+
deniedPermissions === null || deniedPermissions === void 0 ? void 0 : deniedPermissions.forEach(({ identity, identityType, securityProvider }) => {
|
71
|
+
permissionSetBuilder.withDeniedPermissions(new securityIdentityBuilder_1.AnySecurityIdentityBuilder(identityType, identity, securityProvider));
|
72
|
+
});
|
73
|
+
return permissionSetBuilder;
|
74
|
+
}
|
75
|
+
get identityTypeRegex() {
|
76
|
+
const identityTypesValues = Object.values(platform_client_1.PermissionIdentityType);
|
77
|
+
return new RegExp(identityTypesValues.join('|'), 'i');
|
78
|
+
}
|
79
|
+
getSecurityIdentitySchemaValidation() {
|
80
|
+
return new bueno_1.ArrayValue({
|
81
|
+
required: false,
|
82
|
+
each: new bueno_1.RecordValue({
|
83
|
+
values: {
|
84
|
+
identity: new bueno_1.StringValue({ required: true, emptyAllowed: false }),
|
85
|
+
identityType: new bueno_1.StringValue({
|
86
|
+
regex: this.identityTypeRegex,
|
87
|
+
required: true,
|
88
|
+
emptyAllowed: false,
|
89
|
+
}),
|
90
|
+
securityProvider: new bueno_1.StringValue({
|
91
|
+
emptyAllowed: true,
|
92
|
+
required: false,
|
93
|
+
}),
|
94
|
+
},
|
95
|
+
}),
|
96
|
+
});
|
97
|
+
}
|
98
|
+
ensurePermissionArray() {
|
99
|
+
const validator = (schema) => new requiredKeyValidator_1.RequiredKeyValidator('permissions', this.caseInsensitiveDoc, schema);
|
100
|
+
const { isValid, explanation } = validator(new bueno_1.ArrayValue({ required: false }));
|
101
|
+
const requiredAtLeastOnePermission = validator(new bueno_1.ArrayValue({ min: 1 }));
|
102
|
+
if (!isValid) {
|
103
|
+
this.throwInvalidDocumentError(explanation);
|
104
|
+
}
|
105
|
+
if (!requiredAtLeastOnePermission.isValid) {
|
106
|
+
// simply discard empty array permission instead of throwing
|
107
|
+
this.caseInsensitiveDoc.remove('permissions');
|
108
|
+
}
|
109
|
+
}
|
110
|
+
throwInvalidDocumentError(explanation) {
|
111
|
+
throw new errors_1.InvalidDocument(this.documentPath, this.caseInsensitiveDoc.originalDocument, explanation);
|
112
|
+
}
|
113
|
+
}
|
114
|
+
const processPermissionList = (caseInsensitiveDoc, documentBuilder, documentPath) => {
|
115
|
+
const parser = new PermissionParser(caseInsensitiveDoc, documentBuilder, documentPath);
|
116
|
+
return parser.processPermissionList();
|
117
|
+
};
|
118
|
+
exports.processPermissionList = processPermissionList;
|
119
119
|
//# sourceMappingURL=parsePermissions.js.map
|
@@ -1,87 +1,87 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
const path_1 = require("path");
|
4
|
-
const __1 = require("..");
|
5
|
-
const caseInsensitiveDocument_1 = require("./caseInsensitiveDocument");
|
6
|
-
const parsePermissions_1 = require("./parsePermissions");
|
7
|
-
describe('parsePermissions', () => {
|
8
|
-
let documentBuilder;
|
9
|
-
const dummyPath = (0, path_1.join)('dummy', 'path');
|
10
|
-
const publicPermissionsSet = {
|
11
|
-
allowAnonymous: true,
|
12
|
-
deniedpermissions: [
|
13
|
-
{
|
14
|
-
identity: 'foo@example.com',
|
15
|
-
identityType: 'USER',
|
16
|
-
},
|
17
|
-
],
|
18
|
-
};
|
19
|
-
const restrictedPermissionSet = {
|
20
|
-
allowAnonymous: false,
|
21
|
-
ALLOWEDPERMISSIONS: [
|
22
|
-
{
|
23
|
-
identity: 'asmith@example.com',
|
24
|
-
identityType: 'User',
|
25
|
-
},
|
26
|
-
{
|
27
|
-
identity: 'bjones@example.com',
|
28
|
-
identityType: 'USER',
|
29
|
-
},
|
30
|
-
],
|
31
|
-
};
|
32
|
-
const complexPermissionSet = {
|
33
|
-
aLLowAnonyMOUS: false,
|
34
|
-
deniedpermissions: [
|
35
|
-
{
|
36
|
-
identity: 'foo',
|
37
|
-
identityType: 'VirtualGroup',
|
38
|
-
},
|
39
|
-
],
|
40
|
-
allowedPERMISSIONS: [
|
41
|
-
{
|
42
|
-
identity: 'Sample_group',
|
43
|
-
identityType: 'Group',
|
44
|
-
},
|
45
|
-
{
|
46
|
-
identity: 'bjones@example.com',
|
47
|
-
identityType: 'user',
|
48
|
-
},
|
49
|
-
],
|
50
|
-
};
|
51
|
-
beforeEach(() => {
|
52
|
-
documentBuilder = new __1.DocumentBuilder('https://foo.com', 'Some Document');
|
53
|
-
});
|
54
|
-
it('should not marhsal empty permssion when is empty array', () => {
|
55
|
-
const caseInsensitiveDoc = new caseInsensitiveDocument_1.CaseInsensitiveDocument({
|
56
|
-
permissions: [],
|
57
|
-
});
|
58
|
-
(0, parsePermissions_1.processPermissionList)(caseInsensitiveDoc, documentBuilder, dummyPath);
|
59
|
-
expect(documentBuilder.marshal()).not.toHaveProperty('permissions');
|
60
|
-
});
|
61
|
-
it('should marhsal denied permssion set', () => {
|
62
|
-
const caseInsensitiveDoc = new caseInsensitiveDocument_1.CaseInsensitiveDocument({
|
63
|
-
permissions: [publicPermissionsSet],
|
64
|
-
});
|
65
|
-
(0, parsePermissions_1.processPermissionList)(caseInsensitiveDoc, documentBuilder, dummyPath);
|
66
|
-
expect(documentBuilder.marshal().permissions).toMatchSnapshot();
|
67
|
-
});
|
68
|
-
it('should marhsal allowed permssion set', () => {
|
69
|
-
const caseInsensitiveDoc = new caseInsensitiveDocument_1.CaseInsensitiveDocument({
|
70
|
-
permissions: [restrictedPermissionSet],
|
71
|
-
});
|
72
|
-
(0, parsePermissions_1.processPermissionList)(caseInsensitiveDoc, documentBuilder, dummyPath);
|
73
|
-
expect(documentBuilder.marshal().permissions).toMatchSnapshot();
|
74
|
-
});
|
75
|
-
it('should marhsal combined permssion sets', () => {
|
76
|
-
const caseInsensitiveDoc = new caseInsensitiveDocument_1.CaseInsensitiveDocument({
|
77
|
-
permissions: [
|
78
|
-
publicPermissionsSet,
|
79
|
-
restrictedPermissionSet,
|
80
|
-
complexPermissionSet,
|
81
|
-
],
|
82
|
-
});
|
83
|
-
(0, parsePermissions_1.processPermissionList)(caseInsensitiveDoc, documentBuilder, dummyPath);
|
84
|
-
expect(documentBuilder.marshal().permissions).toMatchSnapshot();
|
85
|
-
});
|
86
|
-
});
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const path_1 = require("path");
|
4
|
+
const __1 = require("..");
|
5
|
+
const caseInsensitiveDocument_1 = require("./caseInsensitiveDocument");
|
6
|
+
const parsePermissions_1 = require("./parsePermissions");
|
7
|
+
describe('parsePermissions', () => {
|
8
|
+
let documentBuilder;
|
9
|
+
const dummyPath = (0, path_1.join)('dummy', 'path');
|
10
|
+
const publicPermissionsSet = {
|
11
|
+
allowAnonymous: true,
|
12
|
+
deniedpermissions: [
|
13
|
+
{
|
14
|
+
identity: 'foo@example.com',
|
15
|
+
identityType: 'USER',
|
16
|
+
},
|
17
|
+
],
|
18
|
+
};
|
19
|
+
const restrictedPermissionSet = {
|
20
|
+
allowAnonymous: false,
|
21
|
+
ALLOWEDPERMISSIONS: [
|
22
|
+
{
|
23
|
+
identity: 'asmith@example.com',
|
24
|
+
identityType: 'User',
|
25
|
+
},
|
26
|
+
{
|
27
|
+
identity: 'bjones@example.com',
|
28
|
+
identityType: 'USER',
|
29
|
+
},
|
30
|
+
],
|
31
|
+
};
|
32
|
+
const complexPermissionSet = {
|
33
|
+
aLLowAnonyMOUS: false,
|
34
|
+
deniedpermissions: [
|
35
|
+
{
|
36
|
+
identity: 'foo',
|
37
|
+
identityType: 'VirtualGroup',
|
38
|
+
},
|
39
|
+
],
|
40
|
+
allowedPERMISSIONS: [
|
41
|
+
{
|
42
|
+
identity: 'Sample_group',
|
43
|
+
identityType: 'Group',
|
44
|
+
},
|
45
|
+
{
|
46
|
+
identity: 'bjones@example.com',
|
47
|
+
identityType: 'user',
|
48
|
+
},
|
49
|
+
],
|
50
|
+
};
|
51
|
+
beforeEach(() => {
|
52
|
+
documentBuilder = new __1.DocumentBuilder('https://foo.com', 'Some Document');
|
53
|
+
});
|
54
|
+
it('should not marhsal empty permssion when is empty array', () => {
|
55
|
+
const caseInsensitiveDoc = new caseInsensitiveDocument_1.CaseInsensitiveDocument({
|
56
|
+
permissions: [],
|
57
|
+
});
|
58
|
+
(0, parsePermissions_1.processPermissionList)(caseInsensitiveDoc, documentBuilder, dummyPath);
|
59
|
+
expect(documentBuilder.marshal()).not.toHaveProperty('permissions');
|
60
|
+
});
|
61
|
+
it('should marhsal denied permssion set', () => {
|
62
|
+
const caseInsensitiveDoc = new caseInsensitiveDocument_1.CaseInsensitiveDocument({
|
63
|
+
permissions: [publicPermissionsSet],
|
64
|
+
});
|
65
|
+
(0, parsePermissions_1.processPermissionList)(caseInsensitiveDoc, documentBuilder, dummyPath);
|
66
|
+
expect(documentBuilder.marshal().permissions).toMatchSnapshot();
|
67
|
+
});
|
68
|
+
it('should marhsal allowed permssion set', () => {
|
69
|
+
const caseInsensitiveDoc = new caseInsensitiveDocument_1.CaseInsensitiveDocument({
|
70
|
+
permissions: [restrictedPermissionSet],
|
71
|
+
});
|
72
|
+
(0, parsePermissions_1.processPermissionList)(caseInsensitiveDoc, documentBuilder, dummyPath);
|
73
|
+
expect(documentBuilder.marshal().permissions).toMatchSnapshot();
|
74
|
+
});
|
75
|
+
it('should marhsal combined permssion sets', () => {
|
76
|
+
const caseInsensitiveDoc = new caseInsensitiveDocument_1.CaseInsensitiveDocument({
|
77
|
+
permissions: [
|
78
|
+
publicPermissionsSet,
|
79
|
+
restrictedPermissionSet,
|
80
|
+
complexPermissionSet,
|
81
|
+
],
|
82
|
+
});
|
83
|
+
(0, parsePermissions_1.processPermissionList)(caseInsensitiveDoc, documentBuilder, dummyPath);
|
84
|
+
expect(documentBuilder.marshal().permissions).toMatchSnapshot();
|
85
|
+
});
|
86
|
+
});
|
87
87
|
//# sourceMappingURL=parsePermissions.spec.js.map
|
@@ -1,21 +1,21 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.ensureNecessaryCoveoPrivileges = void 0;
|
4
|
-
const privilegeError_1 = require("../../errors/privilegeError");
|
5
|
-
// Code copy pasted from https://github.com/coveo/cli/blob/master/packages/cli/src/lib/decorators/preconditions/apiKeyPrivilege.ts#L15
|
6
|
-
async function ensureNecessaryCoveoPrivileges(client, ...privileges) {
|
7
|
-
const promises = privileges.flatMap((privilege) => privilege.models.map(async (model) => {
|
8
|
-
if (!(await hasPrivilege(client, model))) {
|
9
|
-
const message = privilege.unsatisfiedConditionMessage;
|
10
|
-
throw new privilegeError_1.PrivilegeError(message);
|
11
|
-
}
|
12
|
-
}));
|
13
|
-
await Promise.all(promises);
|
14
|
-
}
|
15
|
-
exports.ensureNecessaryCoveoPrivileges = ensureNecessaryCoveoPrivileges;
|
16
|
-
async function hasPrivilege(client, privilege) {
|
17
|
-
const model = Object.assign({ requestedPrivilege: privilege });
|
18
|
-
const validation = await client.privilegeEvaluator.evaluate(model);
|
19
|
-
return Boolean(validation.approved);
|
20
|
-
}
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.ensureNecessaryCoveoPrivileges = void 0;
|
4
|
+
const privilegeError_1 = require("../../errors/privilegeError");
|
5
|
+
// Code copy pasted from https://github.com/coveo/cli/blob/master/packages/cli/src/lib/decorators/preconditions/apiKeyPrivilege.ts#L15
|
6
|
+
async function ensureNecessaryCoveoPrivileges(client, ...privileges) {
|
7
|
+
const promises = privileges.flatMap((privilege) => privilege.models.map(async (model) => {
|
8
|
+
if (!(await hasPrivilege(client, model))) {
|
9
|
+
const message = privilege.unsatisfiedConditionMessage;
|
10
|
+
throw new privilegeError_1.PrivilegeError(message);
|
11
|
+
}
|
12
|
+
}));
|
13
|
+
await Promise.all(promises);
|
14
|
+
}
|
15
|
+
exports.ensureNecessaryCoveoPrivileges = ensureNecessaryCoveoPrivileges;
|
16
|
+
async function hasPrivilege(client, privilege) {
|
17
|
+
const model = Object.assign({ requestedPrivilege: privilege });
|
18
|
+
const validation = await client.privilegeEvaluator.evaluate(model);
|
19
|
+
return Boolean(validation.approved);
|
20
|
+
}
|
21
21
|
//# sourceMappingURL=apiKeyPrivilege.js.map
|
@@ -1,67 +1,67 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
jest.mock('@coveo/platform-client');
|
4
|
-
const platform_client_1 = require("@coveo/platform-client");
|
5
|
-
const platformPrivilege_1 = require("./platformPrivilege");
|
6
|
-
const apiKeyPrivilege_1 = require("./apiKeyPrivilege");
|
7
|
-
const mockedPlatformClient = jest.mocked(platform_client_1.default);
|
8
|
-
const mockEvaluate = jest.fn();
|
9
|
-
const doMockPlatformClient = () => {
|
10
|
-
mockedPlatformClient.mockImplementation(() => ({
|
11
|
-
privilegeEvaluator: { evaluate: mockEvaluate },
|
12
|
-
}));
|
13
|
-
};
|
14
|
-
const dummyPlatformClient = () => {
|
15
|
-
return new platform_client_1.default({ accessToken: 'xxx' });
|
16
|
-
};
|
17
|
-
describe('ApiKeyPrivileges', () => {
|
18
|
-
let client;
|
19
|
-
beforeAll(() => {
|
20
|
-
doMockPlatformClient();
|
21
|
-
});
|
22
|
-
beforeEach(async () => {
|
23
|
-
client = dummyPlatformClient();
|
24
|
-
});
|
25
|
-
describe('when not missing privileges', () => {
|
26
|
-
beforeEach(async () => {
|
27
|
-
mockEvaluate.mockResolvedValue({ approved: true });
|
28
|
-
});
|
29
|
-
it('should call the privilege evaluator for each privilege to evaluate', async () => {
|
30
|
-
await (0, apiKeyPrivilege_1.ensureNecessaryCoveoPrivileges)(client, platformPrivilege_1.writeFieldsPrivilege);
|
31
|
-
expect(mockEvaluate).toHaveBeenCalledTimes(3);
|
32
|
-
});
|
33
|
-
it.each([
|
34
|
-
{
|
35
|
-
type: 'VIEW',
|
36
|
-
},
|
37
|
-
{
|
38
|
-
type: 'CREATE',
|
39
|
-
},
|
40
|
-
{
|
41
|
-
type: 'EDIT',
|
42
|
-
},
|
43
|
-
])('should evaluate the "$type FIELD" privilege', async ({ type }) => {
|
44
|
-
await (0, apiKeyPrivilege_1.ensureNecessaryCoveoPrivileges)(client, platformPrivilege_1.writeFieldsPrivilege);
|
45
|
-
expect(mockEvaluate).toHaveBeenCalledWith({
|
46
|
-
requestedPrivilege: {
|
47
|
-
type,
|
48
|
-
targetDomain: 'FIELD',
|
49
|
-
targetId: '*',
|
50
|
-
owner: 'PLATFORM',
|
51
|
-
},
|
52
|
-
});
|
53
|
-
});
|
54
|
-
it('should not throw a Privilege Error', async () => {
|
55
|
-
await expect((0, apiKeyPrivilege_1.ensureNecessaryCoveoPrivileges)(client, platformPrivilege_1.writeFieldsPrivilege)).resolves.not.toThrow();
|
56
|
-
});
|
57
|
-
});
|
58
|
-
describe('when missing privileges', () => {
|
59
|
-
beforeEach(async () => {
|
60
|
-
mockEvaluate.mockResolvedValue({ approved: false });
|
61
|
-
});
|
62
|
-
it('should throw a Privilege Error', async () => {
|
63
|
-
await expect((0, apiKeyPrivilege_1.ensureNecessaryCoveoPrivileges)(client, platformPrivilege_1.writeFieldsPrivilege)).rejects.toThrow(/Your API key doesn't have the privilege to create or update fields/);
|
64
|
-
});
|
65
|
-
});
|
66
|
-
});
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
jest.mock('@coveo/platform-client');
|
4
|
+
const platform_client_1 = require("@coveo/platform-client");
|
5
|
+
const platformPrivilege_1 = require("./platformPrivilege");
|
6
|
+
const apiKeyPrivilege_1 = require("./apiKeyPrivilege");
|
7
|
+
const mockedPlatformClient = jest.mocked(platform_client_1.default);
|
8
|
+
const mockEvaluate = jest.fn();
|
9
|
+
const doMockPlatformClient = () => {
|
10
|
+
mockedPlatformClient.mockImplementation(() => ({
|
11
|
+
privilegeEvaluator: { evaluate: mockEvaluate },
|
12
|
+
}));
|
13
|
+
};
|
14
|
+
const dummyPlatformClient = () => {
|
15
|
+
return new platform_client_1.default({ accessToken: 'xxx' });
|
16
|
+
};
|
17
|
+
describe('ApiKeyPrivileges', () => {
|
18
|
+
let client;
|
19
|
+
beforeAll(() => {
|
20
|
+
doMockPlatformClient();
|
21
|
+
});
|
22
|
+
beforeEach(async () => {
|
23
|
+
client = dummyPlatformClient();
|
24
|
+
});
|
25
|
+
describe('when not missing privileges', () => {
|
26
|
+
beforeEach(async () => {
|
27
|
+
mockEvaluate.mockResolvedValue({ approved: true });
|
28
|
+
});
|
29
|
+
it('should call the privilege evaluator for each privilege to evaluate', async () => {
|
30
|
+
await (0, apiKeyPrivilege_1.ensureNecessaryCoveoPrivileges)(client, platformPrivilege_1.writeFieldsPrivilege);
|
31
|
+
expect(mockEvaluate).toHaveBeenCalledTimes(3);
|
32
|
+
});
|
33
|
+
it.each([
|
34
|
+
{
|
35
|
+
type: 'VIEW',
|
36
|
+
},
|
37
|
+
{
|
38
|
+
type: 'CREATE',
|
39
|
+
},
|
40
|
+
{
|
41
|
+
type: 'EDIT',
|
42
|
+
},
|
43
|
+
])('should evaluate the "$type FIELD" privilege', async ({ type }) => {
|
44
|
+
await (0, apiKeyPrivilege_1.ensureNecessaryCoveoPrivileges)(client, platformPrivilege_1.writeFieldsPrivilege);
|
45
|
+
expect(mockEvaluate).toHaveBeenCalledWith({
|
46
|
+
requestedPrivilege: {
|
47
|
+
type,
|
48
|
+
targetDomain: 'FIELD',
|
49
|
+
targetId: '*',
|
50
|
+
owner: 'PLATFORM',
|
51
|
+
},
|
52
|
+
});
|
53
|
+
});
|
54
|
+
it('should not throw a Privilege Error', async () => {
|
55
|
+
await expect((0, apiKeyPrivilege_1.ensureNecessaryCoveoPrivileges)(client, platformPrivilege_1.writeFieldsPrivilege)).resolves.not.toThrow();
|
56
|
+
});
|
57
|
+
});
|
58
|
+
describe('when missing privileges', () => {
|
59
|
+
beforeEach(async () => {
|
60
|
+
mockEvaluate.mockResolvedValue({ approved: false });
|
61
|
+
});
|
62
|
+
it('should throw a Privilege Error', async () => {
|
63
|
+
await expect((0, apiKeyPrivilege_1.ensureNecessaryCoveoPrivileges)(client, platformPrivilege_1.writeFieldsPrivilege)).rejects.toThrow(/Your API key doesn't have the privilege to create or update fields/);
|
64
|
+
});
|
65
|
+
});
|
66
|
+
});
|
67
67
|
//# sourceMappingURL=apiKeyPrivilege.spec.js.map
|