@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.
- package/dist/APICore.js +47 -47
- 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 +4 -4
@@ -1,46 +1,46 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.uploadBatchFromFile = exports.uploadBatch = exports.uploadDocument = void 0;
|
4
|
-
const __1 = require("..");
|
5
|
-
const fieldUtils_1 = require("../fieldAnalyser/fieldUtils");
|
6
|
-
const function_1 = require("../help/function");
|
7
|
-
const transformer_1 = require("../validation/transformers/transformer");
|
8
|
-
const batchUploadDocumentsFromFile_1 = require("./batchUploadDocumentsFromFile");
|
9
|
-
const defaultBatchOptions = {
|
10
|
-
createFields: true,
|
11
|
-
};
|
12
|
-
const defaultBatchFromFileOptions = Object.assign(Object.assign({}, defaultBatchOptions), { fieldNameTransformer: transformer_1.BuiltInTransformers.identity, maxConcurrent: 10, callback: function_1.noop });
|
13
|
-
async function uploadDocument(platformClient, docBuilder, addURL, api, options) {
|
14
|
-
const { createFields } = Object.assign(Object.assign({}, defaultBatchFromFileOptions), options);
|
15
|
-
if (createFields) {
|
16
|
-
const analyser = new __1.FieldAnalyser(platformClient);
|
17
|
-
await analyser.add([docBuilder]);
|
18
|
-
const report = analyser.report();
|
19
|
-
await (0, fieldUtils_1.createFieldsFromReport)(platformClient, report);
|
20
|
-
}
|
21
|
-
const doc = docBuilder.build();
|
22
|
-
addURL.searchParams.append('documentId', doc.uri);
|
23
|
-
return api.put(addURL.toString(), docBuilder.marshal(), false);
|
24
|
-
}
|
25
|
-
exports.uploadDocument = uploadDocument;
|
26
|
-
async function uploadBatch(platformClient, strategy, batch, options) {
|
27
|
-
var _a, _b;
|
28
|
-
const { createFields } = Object.assign(Object.assign({}, defaultBatchOptions), options);
|
29
|
-
if (createFields) {
|
30
|
-
const analyser = new __1.FieldAnalyser(platformClient);
|
31
|
-
await analyser.add(batch.addOrUpdate);
|
32
|
-
const report = analyser.report();
|
33
|
-
await (0, fieldUtils_1.createFieldsFromReport)(platformClient, report);
|
34
|
-
}
|
35
|
-
await ((_a = strategy.preUpload) === null || _a === void 0 ? void 0 : _a.call(strategy));
|
36
|
-
const res = await strategy.upload(batch);
|
37
|
-
await ((_b = strategy.postUpload) === null || _b === void 0 ? void 0 : _b.call(strategy));
|
38
|
-
return res;
|
39
|
-
}
|
40
|
-
exports.uploadBatch = uploadBatch;
|
41
|
-
function uploadBatchFromFile(platformClient, strategy, filesOrDirectories, options) {
|
42
|
-
const opts = Object.assign(Object.assign({}, defaultBatchFromFileOptions), options);
|
43
|
-
return new batchUploadDocumentsFromFile_1.BatchUploadDocumentsFromFilesReturn(platformClient, strategy, filesOrDirectories, opts);
|
44
|
-
}
|
45
|
-
exports.uploadBatchFromFile = uploadBatchFromFile;
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.uploadBatchFromFile = exports.uploadBatch = exports.uploadDocument = void 0;
|
4
|
+
const __1 = require("..");
|
5
|
+
const fieldUtils_1 = require("../fieldAnalyser/fieldUtils");
|
6
|
+
const function_1 = require("../help/function");
|
7
|
+
const transformer_1 = require("../validation/transformers/transformer");
|
8
|
+
const batchUploadDocumentsFromFile_1 = require("./batchUploadDocumentsFromFile");
|
9
|
+
const defaultBatchOptions = {
|
10
|
+
createFields: true,
|
11
|
+
};
|
12
|
+
const defaultBatchFromFileOptions = Object.assign(Object.assign({}, defaultBatchOptions), { fieldNameTransformer: transformer_1.BuiltInTransformers.identity, maxConcurrent: 10, callback: function_1.noop });
|
13
|
+
async function uploadDocument(platformClient, docBuilder, addURL, api, options) {
|
14
|
+
const { createFields } = Object.assign(Object.assign({}, defaultBatchFromFileOptions), options);
|
15
|
+
if (createFields) {
|
16
|
+
const analyser = new __1.FieldAnalyser(platformClient);
|
17
|
+
await analyser.add([docBuilder]);
|
18
|
+
const report = analyser.report();
|
19
|
+
await (0, fieldUtils_1.createFieldsFromReport)(platformClient, report);
|
20
|
+
}
|
21
|
+
const doc = docBuilder.build();
|
22
|
+
addURL.searchParams.append('documentId', doc.uri);
|
23
|
+
return api.put(addURL.toString(), docBuilder.marshal(), false);
|
24
|
+
}
|
25
|
+
exports.uploadDocument = uploadDocument;
|
26
|
+
async function uploadBatch(platformClient, strategy, batch, options) {
|
27
|
+
var _a, _b;
|
28
|
+
const { createFields } = Object.assign(Object.assign({}, defaultBatchOptions), options);
|
29
|
+
if (createFields) {
|
30
|
+
const analyser = new __1.FieldAnalyser(platformClient);
|
31
|
+
await analyser.add(batch.addOrUpdate);
|
32
|
+
const report = analyser.report();
|
33
|
+
await (0, fieldUtils_1.createFieldsFromReport)(platformClient, report);
|
34
|
+
}
|
35
|
+
await ((_a = strategy.preUpload) === null || _a === void 0 ? void 0 : _a.call(strategy));
|
36
|
+
const res = await strategy.upload(batch);
|
37
|
+
await ((_b = strategy.postUpload) === null || _b === void 0 ? void 0 : _b.call(strategy));
|
38
|
+
return res;
|
39
|
+
}
|
40
|
+
exports.uploadBatch = uploadBatch;
|
41
|
+
function uploadBatchFromFile(platformClient, strategy, filesOrDirectories, options) {
|
42
|
+
const opts = Object.assign(Object.assign({}, defaultBatchFromFileOptions), options);
|
43
|
+
return new batchUploadDocumentsFromFile_1.BatchUploadDocumentsFromFilesReturn(platformClient, strategy, filesOrDirectories, opts);
|
44
|
+
}
|
45
|
+
exports.uploadBatchFromFile = uploadBatchFromFile;
|
46
46
|
//# sourceMappingURL=documentUploader.js.map
|
@@ -1,119 +1,119 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
jest.mock('../fieldAnalyser/fieldAnalyser');
|
4
|
-
jest.mock('../fieldAnalyser/fieldUtils');
|
5
|
-
jest.mock('../APICore');
|
6
|
-
jest.mock('./batchUploadDocumentsFromFile');
|
7
|
-
const platform_client_1 = require("@coveo/platform-client");
|
8
|
-
const __1 = require("..");
|
9
|
-
const APICore_1 = require("../APICore");
|
10
|
-
const fieldAnalyser_1 = require("../fieldAnalyser/fieldAnalyser");
|
11
|
-
const fieldUtils_1 = require("../fieldAnalyser/fieldUtils");
|
12
|
-
const function_1 = require("../help/function");
|
13
|
-
const batchUploadDocumentsFromFile_1 = require("./batchUploadDocumentsFromFile");
|
14
|
-
const transformer_1 = require("../validation/transformers/transformer");
|
15
|
-
const documentUploader_1 = require("./documentUploader");
|
16
|
-
const dummyClient = new platform_client_1.default({ accessToken: 'my_token' });
|
17
|
-
const dummyAPI = new APICore_1.APICore('my_token');
|
18
|
-
const dummyStrategy = {
|
19
|
-
upload: jest.fn(),
|
20
|
-
preUpload: jest.fn(),
|
21
|
-
postUpload: jest.fn(),
|
22
|
-
};
|
23
|
-
describe('documentUploader', () => {
|
24
|
-
describe('#uploadDocument', () => {
|
25
|
-
const upload = (options) => (0, documentUploader_1.uploadDocument)(dummyClient, new __1.DocumentBuilder('http://some.url', 'Some document'), new URL('https://fake.upload.url'), dummyAPI, options);
|
26
|
-
it('should get field report from FieldAnalyser', async () => {
|
27
|
-
await upload({ createFields: true });
|
28
|
-
expect(fieldAnalyser_1.FieldAnalyser.prototype.report).toHaveBeenCalled();
|
29
|
-
});
|
30
|
-
it('should create missing fields from report', async () => {
|
31
|
-
await upload({ createFields: true });
|
32
|
-
expect(fieldUtils_1.createFieldsFromReport).toHaveBeenCalled();
|
33
|
-
});
|
34
|
-
it('should not create missing fields', async () => {
|
35
|
-
await upload({ createFields: false });
|
36
|
-
expect(fieldUtils_1.createFieldsFromReport).not.toHaveBeenCalled();
|
37
|
-
});
|
38
|
-
it('should upload document', async () => {
|
39
|
-
await upload();
|
40
|
-
expect(APICore_1.APICore.prototype.put).toBeCalledWith('https://fake.upload.url/?documentId=http%3A%2F%2Fsome.url', expect.objectContaining({
|
41
|
-
documentId: 'http://some.url',
|
42
|
-
title: 'Some document',
|
43
|
-
}), false);
|
44
|
-
});
|
45
|
-
});
|
46
|
-
describe('#uploadBatch', () => {
|
47
|
-
const batch = {
|
48
|
-
addOrUpdate: [new __1.DocumentBuilder('http://some.url', 'Some document')],
|
49
|
-
delete: [{ documentId: 'foo_bar', deleteChildren: true }],
|
50
|
-
};
|
51
|
-
const upload = (options) => (0, documentUploader_1.uploadBatch)(dummyClient, dummyStrategy, batch, options);
|
52
|
-
it('should get field report from FieldAnalyser', async () => {
|
53
|
-
await upload({ createFields: true });
|
54
|
-
expect(fieldAnalyser_1.FieldAnalyser.prototype.report).toHaveBeenCalled();
|
55
|
-
});
|
56
|
-
it('should create missing fields from report', async () => {
|
57
|
-
await upload({ createFields: true });
|
58
|
-
expect(fieldUtils_1.createFieldsFromReport).toHaveBeenCalled();
|
59
|
-
});
|
60
|
-
it('should not create missing fields', async () => {
|
61
|
-
await upload({ createFields: false });
|
62
|
-
expect(fieldUtils_1.createFieldsFromReport).not.toHaveBeenCalled();
|
63
|
-
});
|
64
|
-
it('should execute the pre-upload strategy logic', async () => {
|
65
|
-
await upload();
|
66
|
-
expect(dummyStrategy.preUpload).toHaveBeenCalled();
|
67
|
-
});
|
68
|
-
it('should execute the upload strategy logic', async () => {
|
69
|
-
await upload();
|
70
|
-
expect(dummyStrategy.upload).toHaveBeenCalledWith({
|
71
|
-
addOrUpdate: [
|
72
|
-
expect.objectContaining({
|
73
|
-
uri: 'http://some.url',
|
74
|
-
}),
|
75
|
-
],
|
76
|
-
delete: [
|
77
|
-
{
|
78
|
-
deleteChildren: true,
|
79
|
-
documentId: 'foo_bar',
|
80
|
-
},
|
81
|
-
],
|
82
|
-
});
|
83
|
-
});
|
84
|
-
it('should execute the post-upload strategy logic', async () => {
|
85
|
-
await upload();
|
86
|
-
expect(dummyStrategy.postUpload).toHaveBeenCalled();
|
87
|
-
});
|
88
|
-
});
|
89
|
-
describe('#uploadBatchFromFile', () => {
|
90
|
-
const dummyCallback = jest.fn();
|
91
|
-
it('should call BatchUploadDocumentsFromFilesReturn with default options', () => {
|
92
|
-
(0, documentUploader_1.uploadBatchFromFile)(dummyClient, dummyStrategy, [
|
93
|
-
'path/to/file',
|
94
|
-
'other/path',
|
95
|
-
]);
|
96
|
-
expect(batchUploadDocumentsFromFile_1.BatchUploadDocumentsFromFilesReturn).toHaveBeenCalledWith(dummyClient, dummyStrategy, ['path/to/file', 'other/path'], {
|
97
|
-
callback: function_1.noop,
|
98
|
-
createFields: true,
|
99
|
-
fieldNameTransformer: transformer_1.BuiltInTransformers.identity,
|
100
|
-
maxConcurrent: 10,
|
101
|
-
});
|
102
|
-
});
|
103
|
-
it('should call BatchUploadDocumentsFromFilesReturn with custom options', () => {
|
104
|
-
(0, documentUploader_1.uploadBatchFromFile)(dummyClient, dummyStrategy, ['path/to/file', 'other/path'], {
|
105
|
-
createFields: false,
|
106
|
-
maxConcurrent: 3,
|
107
|
-
fieldNameTransformer: transformer_1.BuiltInTransformers.toLowerCase,
|
108
|
-
callback: dummyCallback,
|
109
|
-
});
|
110
|
-
expect(batchUploadDocumentsFromFile_1.BatchUploadDocumentsFromFilesReturn).toHaveBeenCalledWith(dummyClient, dummyStrategy, ['path/to/file', 'other/path'], {
|
111
|
-
callback: dummyCallback,
|
112
|
-
createFields: false,
|
113
|
-
fieldNameTransformer: transformer_1.BuiltInTransformers.toLowerCase,
|
114
|
-
maxConcurrent: 3,
|
115
|
-
});
|
116
|
-
});
|
117
|
-
});
|
118
|
-
});
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
jest.mock('../fieldAnalyser/fieldAnalyser');
|
4
|
+
jest.mock('../fieldAnalyser/fieldUtils');
|
5
|
+
jest.mock('../APICore');
|
6
|
+
jest.mock('./batchUploadDocumentsFromFile');
|
7
|
+
const platform_client_1 = require("@coveo/platform-client");
|
8
|
+
const __1 = require("..");
|
9
|
+
const APICore_1 = require("../APICore");
|
10
|
+
const fieldAnalyser_1 = require("../fieldAnalyser/fieldAnalyser");
|
11
|
+
const fieldUtils_1 = require("../fieldAnalyser/fieldUtils");
|
12
|
+
const function_1 = require("../help/function");
|
13
|
+
const batchUploadDocumentsFromFile_1 = require("./batchUploadDocumentsFromFile");
|
14
|
+
const transformer_1 = require("../validation/transformers/transformer");
|
15
|
+
const documentUploader_1 = require("./documentUploader");
|
16
|
+
const dummyClient = new platform_client_1.default({ accessToken: 'my_token' });
|
17
|
+
const dummyAPI = new APICore_1.APICore('my_token');
|
18
|
+
const dummyStrategy = {
|
19
|
+
upload: jest.fn(),
|
20
|
+
preUpload: jest.fn(),
|
21
|
+
postUpload: jest.fn(),
|
22
|
+
};
|
23
|
+
describe('documentUploader', () => {
|
24
|
+
describe('#uploadDocument', () => {
|
25
|
+
const upload = (options) => (0, documentUploader_1.uploadDocument)(dummyClient, new __1.DocumentBuilder('http://some.url', 'Some document'), new URL('https://fake.upload.url'), dummyAPI, options);
|
26
|
+
it('should get field report from FieldAnalyser', async () => {
|
27
|
+
await upload({ createFields: true });
|
28
|
+
expect(fieldAnalyser_1.FieldAnalyser.prototype.report).toHaveBeenCalled();
|
29
|
+
});
|
30
|
+
it('should create missing fields from report', async () => {
|
31
|
+
await upload({ createFields: true });
|
32
|
+
expect(fieldUtils_1.createFieldsFromReport).toHaveBeenCalled();
|
33
|
+
});
|
34
|
+
it('should not create missing fields', async () => {
|
35
|
+
await upload({ createFields: false });
|
36
|
+
expect(fieldUtils_1.createFieldsFromReport).not.toHaveBeenCalled();
|
37
|
+
});
|
38
|
+
it('should upload document', async () => {
|
39
|
+
await upload();
|
40
|
+
expect(APICore_1.APICore.prototype.put).toBeCalledWith('https://fake.upload.url/?documentId=http%3A%2F%2Fsome.url', expect.objectContaining({
|
41
|
+
documentId: 'http://some.url',
|
42
|
+
title: 'Some document',
|
43
|
+
}), false);
|
44
|
+
});
|
45
|
+
});
|
46
|
+
describe('#uploadBatch', () => {
|
47
|
+
const batch = {
|
48
|
+
addOrUpdate: [new __1.DocumentBuilder('http://some.url', 'Some document')],
|
49
|
+
delete: [{ documentId: 'foo_bar', deleteChildren: true }],
|
50
|
+
};
|
51
|
+
const upload = (options) => (0, documentUploader_1.uploadBatch)(dummyClient, dummyStrategy, batch, options);
|
52
|
+
it('should get field report from FieldAnalyser', async () => {
|
53
|
+
await upload({ createFields: true });
|
54
|
+
expect(fieldAnalyser_1.FieldAnalyser.prototype.report).toHaveBeenCalled();
|
55
|
+
});
|
56
|
+
it('should create missing fields from report', async () => {
|
57
|
+
await upload({ createFields: true });
|
58
|
+
expect(fieldUtils_1.createFieldsFromReport).toHaveBeenCalled();
|
59
|
+
});
|
60
|
+
it('should not create missing fields', async () => {
|
61
|
+
await upload({ createFields: false });
|
62
|
+
expect(fieldUtils_1.createFieldsFromReport).not.toHaveBeenCalled();
|
63
|
+
});
|
64
|
+
it('should execute the pre-upload strategy logic', async () => {
|
65
|
+
await upload();
|
66
|
+
expect(dummyStrategy.preUpload).toHaveBeenCalled();
|
67
|
+
});
|
68
|
+
it('should execute the upload strategy logic', async () => {
|
69
|
+
await upload();
|
70
|
+
expect(dummyStrategy.upload).toHaveBeenCalledWith({
|
71
|
+
addOrUpdate: [
|
72
|
+
expect.objectContaining({
|
73
|
+
uri: 'http://some.url',
|
74
|
+
}),
|
75
|
+
],
|
76
|
+
delete: [
|
77
|
+
{
|
78
|
+
deleteChildren: true,
|
79
|
+
documentId: 'foo_bar',
|
80
|
+
},
|
81
|
+
],
|
82
|
+
});
|
83
|
+
});
|
84
|
+
it('should execute the post-upload strategy logic', async () => {
|
85
|
+
await upload();
|
86
|
+
expect(dummyStrategy.postUpload).toHaveBeenCalled();
|
87
|
+
});
|
88
|
+
});
|
89
|
+
describe('#uploadBatchFromFile', () => {
|
90
|
+
const dummyCallback = jest.fn();
|
91
|
+
it('should call BatchUploadDocumentsFromFilesReturn with default options', () => {
|
92
|
+
(0, documentUploader_1.uploadBatchFromFile)(dummyClient, dummyStrategy, [
|
93
|
+
'path/to/file',
|
94
|
+
'other/path',
|
95
|
+
]);
|
96
|
+
expect(batchUploadDocumentsFromFile_1.BatchUploadDocumentsFromFilesReturn).toHaveBeenCalledWith(dummyClient, dummyStrategy, ['path/to/file', 'other/path'], {
|
97
|
+
callback: function_1.noop,
|
98
|
+
createFields: true,
|
99
|
+
fieldNameTransformer: transformer_1.BuiltInTransformers.identity,
|
100
|
+
maxConcurrent: 10,
|
101
|
+
});
|
102
|
+
});
|
103
|
+
it('should call BatchUploadDocumentsFromFilesReturn with custom options', () => {
|
104
|
+
(0, documentUploader_1.uploadBatchFromFile)(dummyClient, dummyStrategy, ['path/to/file', 'other/path'], {
|
105
|
+
createFields: false,
|
106
|
+
maxConcurrent: 3,
|
107
|
+
fieldNameTransformer: transformer_1.BuiltInTransformers.toLowerCase,
|
108
|
+
callback: dummyCallback,
|
109
|
+
});
|
110
|
+
expect(batchUploadDocumentsFromFile_1.BatchUploadDocumentsFromFilesReturn).toHaveBeenCalledWith(dummyClient, dummyStrategy, ['path/to/file', 'other/path'], {
|
111
|
+
callback: dummyCallback,
|
112
|
+
createFields: false,
|
113
|
+
fieldNameTransformer: transformer_1.BuiltInTransformers.toLowerCase,
|
114
|
+
maxConcurrent: 3,
|
115
|
+
});
|
116
|
+
});
|
117
|
+
});
|
118
|
+
});
|
119
119
|
//# sourceMappingURL=documentUploader.spec.js.map
|
package/dist/source/push.js
CHANGED
@@ -1,141 +1,141 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.PushSource = exports.SourceVisibility = void 0;
|
4
|
-
require("fetch-undici-polyfill");
|
5
|
-
const platform_client_1 = require("@coveo/platform-client");
|
6
|
-
var platform_client_2 = require("@coveo/platform-client");
|
7
|
-
Object.defineProperty(exports, "SourceVisibility", { enumerable: true, get: function () { return platform_client_2.SourceVisibility; } });
|
8
|
-
const dayjs = require("dayjs");
|
9
|
-
const url_1 = require("url");
|
10
|
-
const environment_1 = require("../environment");
|
11
|
-
const securityIdenty_1 = require("./securityIdenty");
|
12
|
-
const documentUploader_1 = require("./documentUploader");
|
13
|
-
const urlUtils_1 = require("../help/urlUtils");
|
14
|
-
const uploadStrategy_1 = require("../uploadStrategy");
|
15
|
-
const fieldUtils_1 = require("../fieldAnalyser/fieldUtils");
|
16
|
-
const APICore_1 = require("../APICore");
|
17
|
-
/**
|
18
|
-
* Manage a push source.
|
19
|
-
*
|
20
|
-
* Allows you to create a new push source, manage security identities and documents in a Coveo organization.
|
21
|
-
*/
|
22
|
-
class PushSource {
|
23
|
-
/**
|
24
|
-
*
|
25
|
-
* @param apikey An apiKey capable of pushing documents and managing sources in a Coveo organization. See [Manage API Keys](https://docs.coveo.com/en/1718).
|
26
|
-
* @param organizationid The Coveo Organization identifier.
|
27
|
-
*/
|
28
|
-
constructor(apikey, organizationid, options) {
|
29
|
-
this.apikey = apikey;
|
30
|
-
this.organizationid = organizationid;
|
31
|
-
this.api = new APICore_1.APICore(this.apikey);
|
32
|
-
this.options = Object.assign(Object.assign({}, PushSource.defaultOptions), options);
|
33
|
-
this.platformClient = new platform_client_1.PlatformClient({
|
34
|
-
accessToken: this.apikey,
|
35
|
-
environment: (0, environment_1.castEnvironmentToPlatformClient)(this.options.environment),
|
36
|
-
organizationId: this.organizationid,
|
37
|
-
region: this.options.region,
|
38
|
-
});
|
39
|
-
}
|
40
|
-
/**
|
41
|
-
* Create a new push source
|
42
|
-
* @param name The name of the source to create.
|
43
|
-
* @param sourceVisibility The security option that should be applied to the content of the source. See [Content Security](https://docs.coveo.com/en/1779).
|
44
|
-
* @returns
|
45
|
-
*/
|
46
|
-
create(name, sourceVisibility) {
|
47
|
-
return this.platformClient.source.create({
|
48
|
-
sourceType: platform_client_1.SourceType.PUSH,
|
49
|
-
pushEnabled: true,
|
50
|
-
name,
|
51
|
-
sourceVisibility,
|
52
|
-
});
|
53
|
-
}
|
54
|
-
get identity() {
|
55
|
-
return new securityIdenty_1.SecurityIdentity(this.platformClient);
|
56
|
-
}
|
57
|
-
/**
|
58
|
-
* Adds or updates an individual item in a push source. See [Adding a Single Item in a Push Source](https://docs.coveo.com/en/133).
|
59
|
-
* @param sourceID
|
60
|
-
* @param docBuilder
|
61
|
-
* @param {BatchUpdateDocumentsOptions}
|
62
|
-
* @returns
|
63
|
-
*/
|
64
|
-
addOrUpdateDocument(sourceID, docBuilder, options) {
|
65
|
-
const addURL = new url_1.URL(`${this.urlBuilder(sourceID).baseURL}/documents`);
|
66
|
-
return (0, documentUploader_1.uploadDocument)(this.platformClient, docBuilder, addURL, this.api, options);
|
67
|
-
}
|
68
|
-
/**
|
69
|
-
* Manage batches of items in a push source. See [Manage Batches of Items in a Push Source](https://docs.coveo.com/en/90)
|
70
|
-
* @param sourceID
|
71
|
-
* @param batch
|
72
|
-
* @returns
|
73
|
-
*/
|
74
|
-
batchUpdateDocuments(sourceID, batch, options) {
|
75
|
-
return (0, documentUploader_1.uploadBatch)(this.platformClient, this.fileContainerStrategy(sourceID), batch, options);
|
76
|
-
}
|
77
|
-
/**
|
78
|
-
*
|
79
|
-
* Manage batches of items in a push source from a list of JSON files. See [Manage Batches of Items in a Push Source](https://docs.coveo.com/en/90)
|
80
|
-
* @param {string} sourceID The unique identifier of the target Push source
|
81
|
-
* @param {string[]} filesOrDirectories A list of JSON files or directories (containing JSON files) from which to extract documents.
|
82
|
-
* @param {UploadBatchCallback} callback Callback executed when a batch of documents is either successfully uploaded or when an error occurs during the upload
|
83
|
-
* @param {BatchUpdateDocumentsFromFiles} options
|
84
|
-
*/
|
85
|
-
batchUpdateDocumentsFromFiles(sourceID, filesOrDirectories, options) {
|
86
|
-
return (0, documentUploader_1.uploadBatchFromFile)(this.platformClient, this.fileContainerStrategy(sourceID), filesOrDirectories, options);
|
87
|
-
}
|
88
|
-
/**
|
89
|
-
* Deletes a specific item from a Push source. Optionally, the child items of that item can also be deleted. See [Deleting an Item in a Push Source](https://docs.coveo.com/en/171).
|
90
|
-
* @param sourceID
|
91
|
-
* @param documentId
|
92
|
-
* @param deleteChildren
|
93
|
-
* @returns
|
94
|
-
*/
|
95
|
-
deleteDocument(sourceID, documentId, deleteChildren = false) {
|
96
|
-
const deleteURL = new url_1.URL(`${this.urlBuilder(sourceID).baseURL}/documents`);
|
97
|
-
deleteURL.searchParams.append('documentId', documentId);
|
98
|
-
deleteURL.searchParams.append('deleteChildren', `${deleteChildren}`);
|
99
|
-
return this.api.delete(deleteURL.toString(), false);
|
100
|
-
}
|
101
|
-
/**
|
102
|
-
* Deletes all items whose last update was made by a Push API operation whose orderingId is strictly lower than a specified value. See [Deleting Old Items in a Push Source](https://docs.coveo.com/en/131).
|
103
|
-
* @param sourceID
|
104
|
-
* @param olderThan
|
105
|
-
* @returns
|
106
|
-
*/
|
107
|
-
deleteDocumentsOlderThan(sourceID, olderThan) {
|
108
|
-
const date = dayjs(olderThan);
|
109
|
-
const deleteURL = new url_1.URL(`${this.urlBuilder(sourceID).baseURL}/documents/olderthan`);
|
110
|
-
deleteURL.searchParams.append('orderingId', `${date.valueOf()}`);
|
111
|
-
return this.api.delete(deleteURL.toString(), false);
|
112
|
-
}
|
113
|
-
/**
|
114
|
-
* Set the status of a push source. See [Updating the Status of a Push Source](https://docs.coveo.com/en/35/)
|
115
|
-
* @param sourceID
|
116
|
-
* @param status
|
117
|
-
* @returns {Promise<void>}
|
118
|
-
*/
|
119
|
-
async setSourceStatus(sourceID, status) {
|
120
|
-
const urlStatus = new url_1.URL(`${this.urlBuilder(sourceID).baseURL}/status`);
|
121
|
-
urlStatus.searchParams.append('statusType', status);
|
122
|
-
await this.api.post(urlStatus.toString());
|
123
|
-
}
|
124
|
-
async createFields(analyser) {
|
125
|
-
const report = analyser.report();
|
126
|
-
await (0, fieldUtils_1.createFieldsFromReport)(this.platformClient, report);
|
127
|
-
}
|
128
|
-
urlBuilder(sourceId) {
|
129
|
-
return new urlUtils_1.PushUrlBuilder(sourceId, this.organizationid, this.options);
|
130
|
-
}
|
131
|
-
fileContainerStrategy(sourceId) {
|
132
|
-
const urlBuilder = this.urlBuilder(sourceId);
|
133
|
-
return new uploadStrategy_1.FileContainerStrategy(urlBuilder, this.api);
|
134
|
-
}
|
135
|
-
}
|
136
|
-
exports.PushSource = PushSource;
|
137
|
-
PushSource.defaultOptions = {
|
138
|
-
region: environment_1.DEFAULT_REGION,
|
139
|
-
environment: environment_1.DEFAULT_ENVIRONMENT,
|
140
|
-
};
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.PushSource = exports.SourceVisibility = void 0;
|
4
|
+
require("fetch-undici-polyfill");
|
5
|
+
const platform_client_1 = require("@coveo/platform-client");
|
6
|
+
var platform_client_2 = require("@coveo/platform-client");
|
7
|
+
Object.defineProperty(exports, "SourceVisibility", { enumerable: true, get: function () { return platform_client_2.SourceVisibility; } });
|
8
|
+
const dayjs = require("dayjs");
|
9
|
+
const url_1 = require("url");
|
10
|
+
const environment_1 = require("../environment");
|
11
|
+
const securityIdenty_1 = require("./securityIdenty");
|
12
|
+
const documentUploader_1 = require("./documentUploader");
|
13
|
+
const urlUtils_1 = require("../help/urlUtils");
|
14
|
+
const uploadStrategy_1 = require("../uploadStrategy");
|
15
|
+
const fieldUtils_1 = require("../fieldAnalyser/fieldUtils");
|
16
|
+
const APICore_1 = require("../APICore");
|
17
|
+
/**
|
18
|
+
* Manage a push source.
|
19
|
+
*
|
20
|
+
* Allows you to create a new push source, manage security identities and documents in a Coveo organization.
|
21
|
+
*/
|
22
|
+
class PushSource {
|
23
|
+
/**
|
24
|
+
*
|
25
|
+
* @param apikey An apiKey capable of pushing documents and managing sources in a Coveo organization. See [Manage API Keys](https://docs.coveo.com/en/1718).
|
26
|
+
* @param organizationid The Coveo Organization identifier.
|
27
|
+
*/
|
28
|
+
constructor(apikey, organizationid, options) {
|
29
|
+
this.apikey = apikey;
|
30
|
+
this.organizationid = organizationid;
|
31
|
+
this.api = new APICore_1.APICore(this.apikey);
|
32
|
+
this.options = Object.assign(Object.assign({}, PushSource.defaultOptions), options);
|
33
|
+
this.platformClient = new platform_client_1.PlatformClient({
|
34
|
+
accessToken: this.apikey,
|
35
|
+
environment: (0, environment_1.castEnvironmentToPlatformClient)(this.options.environment),
|
36
|
+
organizationId: this.organizationid,
|
37
|
+
region: this.options.region,
|
38
|
+
});
|
39
|
+
}
|
40
|
+
/**
|
41
|
+
* Create a new push source
|
42
|
+
* @param name The name of the source to create.
|
43
|
+
* @param sourceVisibility The security option that should be applied to the content of the source. See [Content Security](https://docs.coveo.com/en/1779).
|
44
|
+
* @returns
|
45
|
+
*/
|
46
|
+
create(name, sourceVisibility) {
|
47
|
+
return this.platformClient.source.create({
|
48
|
+
sourceType: platform_client_1.SourceType.PUSH,
|
49
|
+
pushEnabled: true,
|
50
|
+
name,
|
51
|
+
sourceVisibility,
|
52
|
+
});
|
53
|
+
}
|
54
|
+
get identity() {
|
55
|
+
return new securityIdenty_1.SecurityIdentity(this.platformClient);
|
56
|
+
}
|
57
|
+
/**
|
58
|
+
* Adds or updates an individual item in a push source. See [Adding a Single Item in a Push Source](https://docs.coveo.com/en/133).
|
59
|
+
* @param sourceID
|
60
|
+
* @param docBuilder
|
61
|
+
* @param {BatchUpdateDocumentsOptions}
|
62
|
+
* @returns
|
63
|
+
*/
|
64
|
+
addOrUpdateDocument(sourceID, docBuilder, options) {
|
65
|
+
const addURL = new url_1.URL(`${this.urlBuilder(sourceID).baseURL}/documents`);
|
66
|
+
return (0, documentUploader_1.uploadDocument)(this.platformClient, docBuilder, addURL, this.api, options);
|
67
|
+
}
|
68
|
+
/**
|
69
|
+
* Manage batches of items in a push source. See [Manage Batches of Items in a Push Source](https://docs.coveo.com/en/90)
|
70
|
+
* @param sourceID
|
71
|
+
* @param batch
|
72
|
+
* @returns
|
73
|
+
*/
|
74
|
+
batchUpdateDocuments(sourceID, batch, options) {
|
75
|
+
return (0, documentUploader_1.uploadBatch)(this.platformClient, this.fileContainerStrategy(sourceID), batch, options);
|
76
|
+
}
|
77
|
+
/**
|
78
|
+
*
|
79
|
+
* Manage batches of items in a push source from a list of JSON files. See [Manage Batches of Items in a Push Source](https://docs.coveo.com/en/90)
|
80
|
+
* @param {string} sourceID The unique identifier of the target Push source
|
81
|
+
* @param {string[]} filesOrDirectories A list of JSON files or directories (containing JSON files) from which to extract documents.
|
82
|
+
* @param {UploadBatchCallback} callback Callback executed when a batch of documents is either successfully uploaded or when an error occurs during the upload
|
83
|
+
* @param {BatchUpdateDocumentsFromFiles} options
|
84
|
+
*/
|
85
|
+
batchUpdateDocumentsFromFiles(sourceID, filesOrDirectories, options) {
|
86
|
+
return (0, documentUploader_1.uploadBatchFromFile)(this.platformClient, this.fileContainerStrategy(sourceID), filesOrDirectories, options);
|
87
|
+
}
|
88
|
+
/**
|
89
|
+
* Deletes a specific item from a Push source. Optionally, the child items of that item can also be deleted. See [Deleting an Item in a Push Source](https://docs.coveo.com/en/171).
|
90
|
+
* @param sourceID
|
91
|
+
* @param documentId
|
92
|
+
* @param deleteChildren
|
93
|
+
* @returns
|
94
|
+
*/
|
95
|
+
deleteDocument(sourceID, documentId, deleteChildren = false) {
|
96
|
+
const deleteURL = new url_1.URL(`${this.urlBuilder(sourceID).baseURL}/documents`);
|
97
|
+
deleteURL.searchParams.append('documentId', documentId);
|
98
|
+
deleteURL.searchParams.append('deleteChildren', `${deleteChildren}`);
|
99
|
+
return this.api.delete(deleteURL.toString(), false);
|
100
|
+
}
|
101
|
+
/**
|
102
|
+
* Deletes all items whose last update was made by a Push API operation whose orderingId is strictly lower than a specified value. See [Deleting Old Items in a Push Source](https://docs.coveo.com/en/131).
|
103
|
+
* @param sourceID
|
104
|
+
* @param olderThan
|
105
|
+
* @returns
|
106
|
+
*/
|
107
|
+
deleteDocumentsOlderThan(sourceID, olderThan) {
|
108
|
+
const date = dayjs(olderThan);
|
109
|
+
const deleteURL = new url_1.URL(`${this.urlBuilder(sourceID).baseURL}/documents/olderthan`);
|
110
|
+
deleteURL.searchParams.append('orderingId', `${date.valueOf()}`);
|
111
|
+
return this.api.delete(deleteURL.toString(), false);
|
112
|
+
}
|
113
|
+
/**
|
114
|
+
* Set the status of a push source. See [Updating the Status of a Push Source](https://docs.coveo.com/en/35/)
|
115
|
+
* @param sourceID
|
116
|
+
* @param status
|
117
|
+
* @returns {Promise<void>}
|
118
|
+
*/
|
119
|
+
async setSourceStatus(sourceID, status) {
|
120
|
+
const urlStatus = new url_1.URL(`${this.urlBuilder(sourceID).baseURL}/status`);
|
121
|
+
urlStatus.searchParams.append('statusType', status);
|
122
|
+
await this.api.post(urlStatus.toString());
|
123
|
+
}
|
124
|
+
async createFields(analyser) {
|
125
|
+
const report = analyser.report();
|
126
|
+
await (0, fieldUtils_1.createFieldsFromReport)(this.platformClient, report);
|
127
|
+
}
|
128
|
+
urlBuilder(sourceId) {
|
129
|
+
return new urlUtils_1.PushUrlBuilder(sourceId, this.organizationid, this.options);
|
130
|
+
}
|
131
|
+
fileContainerStrategy(sourceId) {
|
132
|
+
const urlBuilder = this.urlBuilder(sourceId);
|
133
|
+
return new uploadStrategy_1.FileContainerStrategy(urlBuilder, this.api);
|
134
|
+
}
|
135
|
+
}
|
136
|
+
exports.PushSource = PushSource;
|
137
|
+
PushSource.defaultOptions = {
|
138
|
+
region: environment_1.DEFAULT_REGION,
|
139
|
+
environment: environment_1.DEFAULT_ENVIRONMENT,
|
140
|
+
};
|
141
141
|
//# sourceMappingURL=push.js.map
|