@coveo/push-api-client 3.0.122 → 3.0.124

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 (129) hide show
  1. package/dist/APICore.js +47 -47
  2. package/dist/definitions/APICore.d.ts +18 -18
  3. package/dist/definitions/document.d.ts +124 -124
  4. package/dist/definitions/documentBuilder.d.ts +168 -168
  5. package/dist/definitions/documentBuilder.spec.d.ts +1 -1
  6. package/dist/definitions/environment.d.ts +16 -16
  7. package/dist/definitions/errors/baseError.d.ts +4 -4
  8. package/dist/definitions/errors/fieldErrors.d.ts +18 -18
  9. package/dist/definitions/errors/index.d.ts +3 -3
  10. package/dist/definitions/errors/privilegeError.d.ts +6 -6
  11. package/dist/definitions/errors/validatorErrors.d.ts +20 -20
  12. package/dist/definitions/fieldAnalyser/fieldAnalyser.d.ts +36 -36
  13. package/dist/definitions/fieldAnalyser/fieldAnalyser.spec.d.ts +1 -1
  14. package/dist/definitions/fieldAnalyser/fieldStore.d.ts +5 -5
  15. package/dist/definitions/fieldAnalyser/fieldUtils.d.ts +6 -6
  16. package/dist/definitions/fieldAnalyser/fieldsUtils.spec.d.ts +1 -1
  17. package/dist/definitions/fieldAnalyser/inconsistencies.d.ts +5 -5
  18. package/dist/definitions/fieldAnalyser/inconsistencies.spec.d.ts +1 -1
  19. package/dist/definitions/fieldAnalyser/typeUtils.d.ts +3 -3
  20. package/dist/definitions/fieldAnalyser/typeUtils.spec.d.ts +1 -1
  21. package/dist/definitions/help/file.d.ts +3 -3
  22. package/dist/definitions/help/file.spec.d.ts +1 -1
  23. package/dist/definitions/help/fileConsumer.d.ts +31 -31
  24. package/dist/definitions/help/fileConsumer.spec.d.ts +1 -1
  25. package/dist/definitions/help/fileContainer.d.ts +8 -8
  26. package/dist/definitions/help/fileContainer.spec.d.ts +1 -1
  27. package/dist/definitions/help/function.d.ts +1 -1
  28. package/dist/definitions/help/generator.d.ts +11 -11
  29. package/dist/definitions/help/generator.spec.d.ts +1 -1
  30. package/dist/definitions/help/urlUtils.d.ts +27 -27
  31. package/dist/definitions/help/urlUtils.spec.d.ts +1 -1
  32. package/dist/definitions/index.d.ts +14 -14
  33. package/dist/definitions/interfaces.d.ts +70 -70
  34. package/dist/definitions/localtest.d.ts +1 -1
  35. package/dist/definitions/permissionSetBuilder.d.ts +34 -34
  36. package/dist/definitions/permissionSetBuilder.spec.d.ts +1 -1
  37. package/dist/definitions/securityIdentityBuilder.d.ts +105 -105
  38. package/dist/definitions/securityIdentityBuilder.spec.d.ts +1 -1
  39. package/dist/definitions/source/batchUploadDocumentsFromFile.d.ts +11 -11
  40. package/dist/definitions/source/batchUploadDocumentsFromFile.spec.d.ts +1 -1
  41. package/dist/definitions/source/catalog.d.ts +70 -70
  42. package/dist/definitions/source/catalog.spec.d.ts +1 -1
  43. package/dist/definitions/source/documentUploader.d.ts +11 -11
  44. package/dist/definitions/source/documentUploader.spec.d.ts +1 -1
  45. package/dist/definitions/source/push.d.ts +87 -87
  46. package/dist/definitions/source/push.spec.d.ts +1 -1
  47. package/dist/definitions/source/securityIdenty.d.ts +43 -43
  48. package/dist/definitions/uploadStrategy/fileContainerStrategy.d.ts +23 -23
  49. package/dist/definitions/uploadStrategy/fileContainerStrategy.spec.d.ts +1 -1
  50. package/dist/definitions/uploadStrategy/index.d.ts +3 -3
  51. package/dist/definitions/uploadStrategy/strategy.d.ts +23 -23
  52. package/dist/definitions/uploadStrategy/streamChunkStrategy.d.ts +28 -28
  53. package/dist/definitions/uploadStrategy/streamChunkStrategy.spec.d.ts +1 -1
  54. package/dist/definitions/validation/caseInsensitiveDocument.d.ts +13 -13
  55. package/dist/definitions/validation/knownKey.d.ts +10 -10
  56. package/dist/definitions/validation/parseFile.d.ts +4 -4
  57. package/dist/definitions/validation/parseFile.spec.d.ts +1 -1
  58. package/dist/definitions/validation/parsePermissions.d.ts +5 -5
  59. package/dist/definitions/validation/parsePermissions.spec.d.ts +1 -1
  60. package/dist/definitions/validation/preconditions/apiKeyPrivilege.d.ts +3 -3
  61. package/dist/definitions/validation/preconditions/apiKeyPrivilege.spec.d.ts +1 -1
  62. package/dist/definitions/validation/preconditions/platformPrivilege.d.ts +7 -7
  63. package/dist/definitions/validation/requiredKeyValidator.d.ts +17 -17
  64. package/dist/definitions/validation/transformers/transformer.d.ts +31 -31
  65. package/dist/definitions/validation/transformers/transformer.spec.d.ts +1 -1
  66. package/dist/document.js +2 -2
  67. package/dist/documentBuilder.js +292 -292
  68. package/dist/documentBuilder.spec.js +191 -191
  69. package/dist/environment.js +41 -41
  70. package/dist/errors/baseError.js +10 -10
  71. package/dist/errors/fieldErrors.js +42 -42
  72. package/dist/errors/index.js +19 -19
  73. package/dist/errors/privilegeError.js +12 -12
  74. package/dist/errors/validatorErrors.js +40 -40
  75. package/dist/fieldAnalyser/fieldAnalyser.js +95 -95
  76. package/dist/fieldAnalyser/fieldAnalyser.spec.js +230 -230
  77. package/dist/fieldAnalyser/fieldStore.js +21 -21
  78. package/dist/fieldAnalyser/fieldUtils.js +41 -41
  79. package/dist/fieldAnalyser/fieldsUtils.spec.js +116 -116
  80. package/dist/fieldAnalyser/inconsistencies.js +14 -14
  81. package/dist/fieldAnalyser/inconsistencies.spec.js +40 -40
  82. package/dist/fieldAnalyser/typeUtils.js +61 -61
  83. package/dist/fieldAnalyser/typeUtils.spec.js +142 -142
  84. package/dist/help/file.js +37 -37
  85. package/dist/help/file.spec.js +67 -67
  86. package/dist/help/fileConsumer.js +150 -150
  87. package/dist/help/fileConsumer.spec.js +153 -153
  88. package/dist/help/fileContainer.js +48 -48
  89. package/dist/help/fileContainer.spec.js +65 -65
  90. package/dist/help/function.js +5 -5
  91. package/dist/help/generator.js +32 -32
  92. package/dist/help/generator.spec.js +82 -82
  93. package/dist/help/urlUtils.js +42 -42
  94. package/dist/help/urlUtils.spec.js +41 -41
  95. package/dist/index.js +38 -38
  96. package/dist/interfaces.js +2 -2
  97. package/dist/localtest.js +55 -55
  98. package/dist/permissionSetBuilder.js +58 -58
  99. package/dist/permissionSetBuilder.spec.js +68 -68
  100. package/dist/securityIdentityBuilder.js +128 -128
  101. package/dist/securityIdentityBuilder.spec.js +50 -50
  102. package/dist/source/batchUploadDocumentsFromFile.js +46 -46
  103. package/dist/source/batchUploadDocumentsFromFile.spec.js +145 -145
  104. package/dist/source/catalog.js +111 -111
  105. package/dist/source/catalog.spec.js +64 -64
  106. package/dist/source/documentUploader.js +45 -45
  107. package/dist/source/documentUploader.spec.js +118 -118
  108. package/dist/source/push.js +140 -140
  109. package/dist/source/push.spec.js +152 -152
  110. package/dist/source/securityIdenty.js +57 -57
  111. package/dist/uploadStrategy/fileContainerStrategy.js +32 -32
  112. package/dist/uploadStrategy/fileContainerStrategy.spec.js +86 -86
  113. package/dist/uploadStrategy/index.js +19 -19
  114. package/dist/uploadStrategy/strategy.js +2 -2
  115. package/dist/uploadStrategy/streamChunkStrategy.js +52 -52
  116. package/dist/uploadStrategy/streamChunkStrategy.spec.js +77 -77
  117. package/dist/validation/caseInsensitiveDocument.js +31 -31
  118. package/dist/validation/knownKey.js +37 -37
  119. package/dist/validation/parseFile.js +120 -120
  120. package/dist/validation/parseFile.spec.js +96 -96
  121. package/dist/validation/parsePermissions.js +118 -118
  122. package/dist/validation/parsePermissions.spec.js +86 -86
  123. package/dist/validation/preconditions/apiKeyPrivilege.js +20 -20
  124. package/dist/validation/preconditions/apiKeyPrivilege.spec.js +66 -66
  125. package/dist/validation/preconditions/platformPrivilege.js +32 -32
  126. package/dist/validation/requiredKeyValidator.js +61 -61
  127. package/dist/validation/transformers/transformer.js +51 -51
  128. package/dist/validation/transformers/transformer.spec.js +21 -21
  129. package/package.json +4 -4
@@ -1,121 +1,121 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseAndGetDocumentBuilderFromJSONDocument = void 0;
4
- const bueno_1 = require("@coveo/bueno");
5
- const __1 = require("..");
6
- const fs_1 = require("fs");
7
- const caseInsensitiveDocument_1 = require("./caseInsensitiveDocument");
8
- const knownKey_1 = require("./knownKey");
9
- const validatorErrors_1 = require("../errors/validatorErrors");
10
- const requiredKeyValidator_1 = require("./requiredKeyValidator");
11
- const parsePermissions_1 = require("./parsePermissions");
12
- const parseAndGetDocumentBuilderFromJSONDocument = async (documentPath, options) => {
13
- ensureFileIntegrity(documentPath);
14
- const fileContent = safeJSONParse(documentPath);
15
- const executeCallback = async (docBuilder) => {
16
- if (options === null || options === void 0 ? void 0 : options.callback) {
17
- await (options === null || options === void 0 ? void 0 : options.callback(docBuilder, documentPath));
18
- }
19
- };
20
- if (Array.isArray(fileContent)) {
21
- const docBuilders = [];
22
- for (const doc of fileContent) {
23
- const docBuilder = processDocument(doc, documentPath, options);
24
- await executeCallback(docBuilder);
25
- docBuilders.push(docBuilder);
26
- }
27
- return docBuilders;
28
- }
29
- else {
30
- const docBuilder = processDocument(fileContent, documentPath, options);
31
- executeCallback(docBuilder);
32
- return [docBuilder];
33
- }
34
- };
35
- exports.parseAndGetDocumentBuilderFromJSONDocument = parseAndGetDocumentBuilderFromJSONDocument;
36
- const safeJSONParse = (documentPath) => {
37
- const fileContent = (0, fs_1.readFileSync)(documentPath).toString();
38
- try {
39
- return JSON.parse(fileContent);
40
- }
41
- catch (error) {
42
- throw new validatorErrors_1.NotAJsonFileError(documentPath);
43
- }
44
- };
45
- const processDocument = (fileContent, documentPath, options) => {
46
- const caseInsensitiveDoc = new caseInsensitiveDocument_1.CaseInsensitiveDocument(fileContent);
47
- const documentBuilder = validateRequiredKeysAndGetDocumentBuilder(caseInsensitiveDoc, documentPath);
48
- try {
49
- processKnownKeys(caseInsensitiveDoc, documentBuilder);
50
- (0, parsePermissions_1.processPermissionList)(caseInsensitiveDoc, documentBuilder, documentPath);
51
- processMetadata(caseInsensitiveDoc, documentBuilder, options);
52
- }
53
- catch (error) {
54
- if (typeof error === 'string') {
55
- throw new validatorErrors_1.InvalidDocument(documentPath, caseInsensitiveDoc.originalDocument, error);
56
- }
57
- throw error;
58
- }
59
- return documentBuilder;
60
- };
61
- const validateRequiredKeysAndGetDocumentBuilder = (caseInsensitiveDoc, documentPath) => {
62
- const requiredDocumentId = new requiredKeyValidator_1.RequiredKeyValidator(['documentid', 'uri'], caseInsensitiveDoc, new bueno_1.StringValue({ required: true, emptyAllowed: false }));
63
- if (!requiredDocumentId.isValid) {
64
- throw new validatorErrors_1.InvalidDocument(documentPath, caseInsensitiveDoc.originalDocument, requiredDocumentId.explanation);
65
- }
66
- const requiredDocumentTitle = new requiredKeyValidator_1.RequiredKeyValidator('title', caseInsensitiveDoc, new bueno_1.StringValue({ required: true, emptyAllowed: false }));
67
- if (!requiredDocumentTitle.isValid) {
68
- throw new validatorErrors_1.InvalidDocument(documentPath, caseInsensitiveDoc.originalDocument, requiredDocumentTitle.explanation);
69
- }
70
- caseInsensitiveDoc.remove('documentid', 'uri', 'title');
71
- return new __1.DocumentBuilder(requiredDocumentId.value, requiredDocumentTitle.value);
72
- };
73
- const processKnownKeys = (caseInsensitiveDoc, documentBuilder) => {
74
- new knownKey_1.KnownKeys('author', caseInsensitiveDoc).whenExists((author) => {
75
- documentBuilder.withAuthor(author);
76
- caseInsensitiveDoc.remove('author');
77
- });
78
- new knownKey_1.KnownKeys('clickableuri', caseInsensitiveDoc).whenExists((clickuri) => {
79
- documentBuilder.withClickableUri(clickuri);
80
- caseInsensitiveDoc.remove('clickableuri');
81
- });
82
- new knownKey_1.KnownKeys('data', caseInsensitiveDoc).whenExists((data) => {
83
- documentBuilder.withData(data);
84
- caseInsensitiveDoc.remove('data');
85
- });
86
- new knownKey_1.KnownKeys('date', caseInsensitiveDoc).whenExists((date) => {
87
- documentBuilder.withDate(date);
88
- caseInsensitiveDoc.remove('date');
89
- });
90
- new knownKey_1.KnownKeys('modifieddate', caseInsensitiveDoc).whenExists((modifiedDate) => {
91
- documentBuilder.withModifiedDate(modifiedDate);
92
- caseInsensitiveDoc.remove('modifieddate');
93
- });
94
- new knownKey_1.KnownKeys('fileextension', caseInsensitiveDoc).whenExists((fileExtension) => {
95
- documentBuilder.withFileExtension(fileExtension);
96
- caseInsensitiveDoc.remove('fileextension');
97
- });
98
- new knownKey_1.KnownKeys('permanentid', caseInsensitiveDoc).whenExists((permanentId) => {
99
- documentBuilder.withPermanentId(permanentId);
100
- caseInsensitiveDoc.remove('permanentid');
101
- });
102
- };
103
- const processMetadata = (caseInsensitiveDoc, documentBuilder, options) => {
104
- const metadata = {};
105
- Object.entries(caseInsensitiveDoc.remainingRecord).forEach(([k, v]) => {
106
- metadata[k] = v;
107
- });
108
- documentBuilder.withMetadata(metadata, options === null || options === void 0 ? void 0 : options.fieldNameTransformer);
109
- };
110
- const ensureFileIntegrity = (documentPath) => {
111
- if (!isFile(documentPath)) {
112
- throw new validatorErrors_1.NotAFileError(documentPath);
113
- }
114
- };
115
- const isFile = (p) => {
116
- if (!(0, fs_1.existsSync)(p)) {
117
- return false;
118
- }
119
- return (0, fs_1.lstatSync)(p).isFile();
120
- };
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseAndGetDocumentBuilderFromJSONDocument = void 0;
4
+ const bueno_1 = require("@coveo/bueno");
5
+ const __1 = require("..");
6
+ const fs_1 = require("fs");
7
+ const caseInsensitiveDocument_1 = require("./caseInsensitiveDocument");
8
+ const knownKey_1 = require("./knownKey");
9
+ const validatorErrors_1 = require("../errors/validatorErrors");
10
+ const requiredKeyValidator_1 = require("./requiredKeyValidator");
11
+ const parsePermissions_1 = require("./parsePermissions");
12
+ const parseAndGetDocumentBuilderFromJSONDocument = async (documentPath, options) => {
13
+ ensureFileIntegrity(documentPath);
14
+ const fileContent = safeJSONParse(documentPath);
15
+ const executeCallback = async (docBuilder) => {
16
+ if (options === null || options === void 0 ? void 0 : options.callback) {
17
+ await (options === null || options === void 0 ? void 0 : options.callback(docBuilder, documentPath));
18
+ }
19
+ };
20
+ if (Array.isArray(fileContent)) {
21
+ const docBuilders = [];
22
+ for (const doc of fileContent) {
23
+ const docBuilder = processDocument(doc, documentPath, options);
24
+ await executeCallback(docBuilder);
25
+ docBuilders.push(docBuilder);
26
+ }
27
+ return docBuilders;
28
+ }
29
+ else {
30
+ const docBuilder = processDocument(fileContent, documentPath, options);
31
+ executeCallback(docBuilder);
32
+ return [docBuilder];
33
+ }
34
+ };
35
+ exports.parseAndGetDocumentBuilderFromJSONDocument = parseAndGetDocumentBuilderFromJSONDocument;
36
+ const safeJSONParse = (documentPath) => {
37
+ const fileContent = (0, fs_1.readFileSync)(documentPath).toString();
38
+ try {
39
+ return JSON.parse(fileContent);
40
+ }
41
+ catch (error) {
42
+ throw new validatorErrors_1.NotAJsonFileError(documentPath);
43
+ }
44
+ };
45
+ const processDocument = (fileContent, documentPath, options) => {
46
+ const caseInsensitiveDoc = new caseInsensitiveDocument_1.CaseInsensitiveDocument(fileContent);
47
+ const documentBuilder = validateRequiredKeysAndGetDocumentBuilder(caseInsensitiveDoc, documentPath);
48
+ try {
49
+ processKnownKeys(caseInsensitiveDoc, documentBuilder);
50
+ (0, parsePermissions_1.processPermissionList)(caseInsensitiveDoc, documentBuilder, documentPath);
51
+ processMetadata(caseInsensitiveDoc, documentBuilder, options);
52
+ }
53
+ catch (error) {
54
+ if (typeof error === 'string') {
55
+ throw new validatorErrors_1.InvalidDocument(documentPath, caseInsensitiveDoc.originalDocument, error);
56
+ }
57
+ throw error;
58
+ }
59
+ return documentBuilder;
60
+ };
61
+ const validateRequiredKeysAndGetDocumentBuilder = (caseInsensitiveDoc, documentPath) => {
62
+ const requiredDocumentId = new requiredKeyValidator_1.RequiredKeyValidator(['documentid', 'uri'], caseInsensitiveDoc, new bueno_1.StringValue({ required: true, emptyAllowed: false }));
63
+ if (!requiredDocumentId.isValid) {
64
+ throw new validatorErrors_1.InvalidDocument(documentPath, caseInsensitiveDoc.originalDocument, requiredDocumentId.explanation);
65
+ }
66
+ const requiredDocumentTitle = new requiredKeyValidator_1.RequiredKeyValidator('title', caseInsensitiveDoc, new bueno_1.StringValue({ required: true, emptyAllowed: false }));
67
+ if (!requiredDocumentTitle.isValid) {
68
+ throw new validatorErrors_1.InvalidDocument(documentPath, caseInsensitiveDoc.originalDocument, requiredDocumentTitle.explanation);
69
+ }
70
+ caseInsensitiveDoc.remove('documentid', 'uri', 'title');
71
+ return new __1.DocumentBuilder(requiredDocumentId.value, requiredDocumentTitle.value);
72
+ };
73
+ const processKnownKeys = (caseInsensitiveDoc, documentBuilder) => {
74
+ new knownKey_1.KnownKeys('author', caseInsensitiveDoc).whenExists((author) => {
75
+ documentBuilder.withAuthor(author);
76
+ caseInsensitiveDoc.remove('author');
77
+ });
78
+ new knownKey_1.KnownKeys('clickableuri', caseInsensitiveDoc).whenExists((clickuri) => {
79
+ documentBuilder.withClickableUri(clickuri);
80
+ caseInsensitiveDoc.remove('clickableuri');
81
+ });
82
+ new knownKey_1.KnownKeys('data', caseInsensitiveDoc).whenExists((data) => {
83
+ documentBuilder.withData(data);
84
+ caseInsensitiveDoc.remove('data');
85
+ });
86
+ new knownKey_1.KnownKeys('date', caseInsensitiveDoc).whenExists((date) => {
87
+ documentBuilder.withDate(date);
88
+ caseInsensitiveDoc.remove('date');
89
+ });
90
+ new knownKey_1.KnownKeys('modifieddate', caseInsensitiveDoc).whenExists((modifiedDate) => {
91
+ documentBuilder.withModifiedDate(modifiedDate);
92
+ caseInsensitiveDoc.remove('modifieddate');
93
+ });
94
+ new knownKey_1.KnownKeys('fileextension', caseInsensitiveDoc).whenExists((fileExtension) => {
95
+ documentBuilder.withFileExtension(fileExtension);
96
+ caseInsensitiveDoc.remove('fileextension');
97
+ });
98
+ new knownKey_1.KnownKeys('permanentid', caseInsensitiveDoc).whenExists((permanentId) => {
99
+ documentBuilder.withPermanentId(permanentId);
100
+ caseInsensitiveDoc.remove('permanentid');
101
+ });
102
+ };
103
+ const processMetadata = (caseInsensitiveDoc, documentBuilder, options) => {
104
+ const metadata = {};
105
+ Object.entries(caseInsensitiveDoc.remainingRecord).forEach(([k, v]) => {
106
+ metadata[k] = v;
107
+ });
108
+ documentBuilder.withMetadata(metadata, options === null || options === void 0 ? void 0 : options.fieldNameTransformer);
109
+ };
110
+ const ensureFileIntegrity = (documentPath) => {
111
+ if (!isFile(documentPath)) {
112
+ throw new validatorErrors_1.NotAFileError(documentPath);
113
+ }
114
+ };
115
+ const isFile = (p) => {
116
+ if (!(0, fs_1.existsSync)(p)) {
117
+ return false;
118
+ }
119
+ return (0, fs_1.lstatSync)(p).isFile();
120
+ };
121
121
  //# sourceMappingURL=parseFile.js.map
@@ -1,97 +1,97 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const path_1 = require("path");
4
- const process_1 = require("process");
5
- const parseFile_1 = require("./parseFile");
6
- const validatorErrors_1 = require("../errors/validatorErrors");
7
- const fs_1 = require("fs");
8
- const stripFilePathFromSnapshot = () => {
9
- const fileJsonFileErrorRegex = new RegExp(/^.*?(\w+\.json)(?= is not a valid JSON)/m);
10
- expect.addSnapshotSerializer({
11
- test: (val) => Boolean(val.match(fileJsonFileErrorRegex)),
12
- print: (val) => `${val}`.replace(fileJsonFileErrorRegex, '$1'),
13
- });
14
- };
15
- describe('parseFile', () => {
16
- const pathToStub = (0, path_1.join)((0, process_1.cwd)(), 'src', '__stub__');
17
- const parse = (file) => () => (0, parseFile_1.parseAndGetDocumentBuilderFromJSONDocument)(file);
18
- it('should accept non-url documentIDs', async () => {
19
- const file = (0, path_1.join)(pathToStub, 'jsondocuments', 'notAnUrl.json');
20
- await expect((0, parseFile_1.parseAndGetDocumentBuilderFromJSONDocument)(file)).resolves.not.toThrow();
21
- });
22
- it.each([
23
- {
24
- title: 'should fail on missing title',
25
- fileName: 'noTitle.json',
26
- error: 'title: value is required.',
27
- },
28
- {
29
- title: 'should fail on missing documentID',
30
- fileName: 'noID.json',
31
- error: 'documentid: value is required.',
32
- },
33
- {
34
- title: 'should fail on missing identity',
35
- fileName: 'noIdentity.json',
36
- error: 'allowedpermissions: value does not contain identity',
37
- },
38
- {
39
- title: 'should fail on identity with an invalid string',
40
- fileName: 'identityNotAString.json',
41
- error: 'allowedpermissions: value is not a string.',
42
- },
43
- {
44
- title: 'should fail on allow anonymous with an invalid boolean',
45
- fileName: 'identityAllowAnonymousNotABoolean.json',
46
- error: 'allowanonymous: value is not a boolean.',
47
- },
48
- {
49
- title: 'should fail on identityType with an invalid value',
50
- fileName: 'identityTypeInvalidValue.json',
51
- error: 'allowedpermissions: value did not match provided regex /Unknown|User|Group|VirtualGroup/i',
52
- },
53
- {
54
- title: 'should fail on permission not being an array',
55
- fileName: 'notAPermissionArray.json',
56
- error: 'permissions: value is not an array',
57
- },
58
- {
59
- title: 'should fail on permission not being an array',
60
- fileName: 'notAPermissionArray.json',
61
- error: 'permissions: value is not an array',
62
- },
63
- {
64
- title: 'should fail on permission not being an array',
65
- fileName: 'notAPermissionArray.json',
66
- error: 'permissions: value is not an array',
67
- },
68
- {
69
- title: 'should fail on permission not being an array',
70
- fileName: 'notAPermissionArray.json',
71
- error: 'permissions: value is not an array',
72
- },
73
- ])('$title', async ({ fileName, error }) => {
74
- const file = (0, path_1.join)(pathToStub, 'jsondocuments', fileName);
75
- const fileContent = (0, fs_1.readFileSync)(file).toString();
76
- await expect(parse(file)).rejects.toThrow(new validatorErrors_1.InvalidDocument(file, JSON.parse(fileContent), `Document contains an invalid value for ${error}`));
77
- });
78
- it('should not throw if allowedPermissions or deniedPermissions are omitted', async () => {
79
- const file = (0, path_1.join)(pathToStub, 'jsondocuments', 'limitedPermissionSet.json');
80
- await expect((0, parseFile_1.parseAndGetDocumentBuilderFromJSONDocument)(file)).resolves.not.toThrow();
81
- });
82
- it('should fail on reserved keyword', async () => {
83
- const file = (0, path_1.join)(pathToStub, 'jsondocuments', 'reservedKeyword.json');
84
- const fileContent = (0, fs_1.readFileSync)(file).toString();
85
- await expect(parse(file)).rejects.toThrow(new validatorErrors_1.InvalidDocument(file, JSON.parse(fileContent), 'Cannot use parentid as a metadata key: It is a reserved key name. See https://docs.coveo.com/en/78/index-content/push-api-reference#json-document-reserved-key-names'));
86
- });
87
- it('should fail on reserved keyword', async () => {
88
- const file = (0, path_1.join)(pathToStub, 'jsondocuments', 'brokenBatch.json');
89
- stripFilePathFromSnapshot();
90
- await expect(parse(file)).rejects.toThrowErrorMatchingSnapshot();
91
- });
92
- it('should fail on unsupported metadata key', async () => {
93
- const file = (0, path_1.join)(pathToStub, 'jsondocuments', 'invalidFields.json');
94
- await expect(parse(file)).rejects.toThrowErrorMatchingSnapshot();
95
- });
96
- });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const path_1 = require("path");
4
+ const process_1 = require("process");
5
+ const parseFile_1 = require("./parseFile");
6
+ const validatorErrors_1 = require("../errors/validatorErrors");
7
+ const fs_1 = require("fs");
8
+ const stripFilePathFromSnapshot = () => {
9
+ const fileJsonFileErrorRegex = new RegExp(/^.*?(\w+\.json)(?= is not a valid JSON)/m);
10
+ expect.addSnapshotSerializer({
11
+ test: (val) => Boolean(val.match(fileJsonFileErrorRegex)),
12
+ print: (val) => `${val}`.replace(fileJsonFileErrorRegex, '$1'),
13
+ });
14
+ };
15
+ describe('parseFile', () => {
16
+ const pathToStub = (0, path_1.join)((0, process_1.cwd)(), 'src', '__stub__');
17
+ const parse = (file) => () => (0, parseFile_1.parseAndGetDocumentBuilderFromJSONDocument)(file);
18
+ it('should accept non-url documentIDs', async () => {
19
+ const file = (0, path_1.join)(pathToStub, 'jsondocuments', 'notAnUrl.json');
20
+ await expect((0, parseFile_1.parseAndGetDocumentBuilderFromJSONDocument)(file)).resolves.not.toThrow();
21
+ });
22
+ it.each([
23
+ {
24
+ title: 'should fail on missing title',
25
+ fileName: 'noTitle.json',
26
+ error: 'title: value is required.',
27
+ },
28
+ {
29
+ title: 'should fail on missing documentID',
30
+ fileName: 'noID.json',
31
+ error: 'documentid: value is required.',
32
+ },
33
+ {
34
+ title: 'should fail on missing identity',
35
+ fileName: 'noIdentity.json',
36
+ error: 'allowedpermissions: value does not contain identity',
37
+ },
38
+ {
39
+ title: 'should fail on identity with an invalid string',
40
+ fileName: 'identityNotAString.json',
41
+ error: 'allowedpermissions: value is not a string.',
42
+ },
43
+ {
44
+ title: 'should fail on allow anonymous with an invalid boolean',
45
+ fileName: 'identityAllowAnonymousNotABoolean.json',
46
+ error: 'allowanonymous: value is not a boolean.',
47
+ },
48
+ {
49
+ title: 'should fail on identityType with an invalid value',
50
+ fileName: 'identityTypeInvalidValue.json',
51
+ error: 'allowedpermissions: value did not match provided regex /Unknown|User|Group|VirtualGroup/i',
52
+ },
53
+ {
54
+ title: 'should fail on permission not being an array',
55
+ fileName: 'notAPermissionArray.json',
56
+ error: 'permissions: value is not an array',
57
+ },
58
+ {
59
+ title: 'should fail on permission not being an array',
60
+ fileName: 'notAPermissionArray.json',
61
+ error: 'permissions: value is not an array',
62
+ },
63
+ {
64
+ title: 'should fail on permission not being an array',
65
+ fileName: 'notAPermissionArray.json',
66
+ error: 'permissions: value is not an array',
67
+ },
68
+ {
69
+ title: 'should fail on permission not being an array',
70
+ fileName: 'notAPermissionArray.json',
71
+ error: 'permissions: value is not an array',
72
+ },
73
+ ])('$title', async ({ fileName, error }) => {
74
+ const file = (0, path_1.join)(pathToStub, 'jsondocuments', fileName);
75
+ const fileContent = (0, fs_1.readFileSync)(file).toString();
76
+ await expect(parse(file)).rejects.toThrow(new validatorErrors_1.InvalidDocument(file, JSON.parse(fileContent), `Document contains an invalid value for ${error}`));
77
+ });
78
+ it('should not throw if allowedPermissions or deniedPermissions are omitted', async () => {
79
+ const file = (0, path_1.join)(pathToStub, 'jsondocuments', 'limitedPermissionSet.json');
80
+ await expect((0, parseFile_1.parseAndGetDocumentBuilderFromJSONDocument)(file)).resolves.not.toThrow();
81
+ });
82
+ it('should fail on reserved keyword', async () => {
83
+ const file = (0, path_1.join)(pathToStub, 'jsondocuments', 'reservedKeyword.json');
84
+ const fileContent = (0, fs_1.readFileSync)(file).toString();
85
+ await expect(parse(file)).rejects.toThrow(new validatorErrors_1.InvalidDocument(file, JSON.parse(fileContent), 'Cannot use parentid as a metadata key: It is a reserved key name. See https://docs.coveo.com/en/78/index-content/push-api-reference#json-document-reserved-key-names'));
86
+ });
87
+ it('should fail on reserved keyword', async () => {
88
+ const file = (0, path_1.join)(pathToStub, 'jsondocuments', 'brokenBatch.json');
89
+ stripFilePathFromSnapshot();
90
+ await expect(parse(file)).rejects.toThrowErrorMatchingSnapshot();
91
+ });
92
+ it('should fail on unsupported metadata key', async () => {
93
+ const file = (0, path_1.join)(pathToStub, 'jsondocuments', 'invalidFields.json');
94
+ await expect(parse(file)).rejects.toThrowErrorMatchingSnapshot();
95
+ });
96
+ });
97
97
  //# sourceMappingURL=parseFile.spec.js.map