@coveo/push-api-client 2.6.6 → 2.7.1
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 +43 -0
- package/dist/APICore.js.map +1 -0
- package/dist/definitions/APICore.d.ts +11 -0
- package/dist/definitions/source/catalog.d.ts +1 -0
- package/dist/definitions/source/documentUploader.d.ts +3 -2
- package/dist/definitions/source/push.d.ts +5 -5
- package/dist/definitions/uploadStrategy/fileContainerStrategy.d.ts +4 -4
- package/dist/definitions/uploadStrategy/streamChunkStrategy.d.ts +4 -4
- package/dist/docs/assets/search.js +1 -1
- package/dist/docs/classes/AnySecurityIdentityBuilder.html +4 -4
- package/dist/docs/classes/CatalogSource.html +24 -17
- package/dist/docs/classes/DocumentBuilder.html +28 -28
- package/dist/docs/classes/FieldAnalyser.html +12 -12
- package/dist/docs/classes/GroupSecurityIdentityBuilder.html +5 -5
- package/dist/docs/classes/PushSource.html +40 -43
- package/dist/docs/classes/UserSecurityIdentityBuilder.html +5 -5
- package/dist/docs/classes/VirtualGroupSecurityIdentityBuilder.html +5 -5
- package/dist/docs/classes/errors.FieldTypeInconsistencyError.html +3 -3
- package/dist/docs/classes/errors.InvalidDocument.html +3 -3
- package/dist/docs/classes/errors.InvalidPermanentId.html +3 -3
- package/dist/docs/classes/errors.NotAFileError.html +3 -3
- package/dist/docs/classes/errors.NotAJsonFileError.html +3 -3
- package/dist/docs/classes/errors.PrivilegeError.html +4 -4
- package/dist/docs/classes/errors.UnsupportedAttribute.html +3 -3
- package/dist/docs/classes/errors.UnsupportedFieldError.html +6 -6
- package/dist/docs/enums/PlatformEnvironment.html +5 -5
- package/dist/docs/functions/parseAndGetDocumentBuilderFromJSONDocument.html +1 -1
- package/dist/docs/interfaces/BatchUpdateDocuments.html +3 -3
- package/dist/docs/interfaces/Document.html +14 -14
- package/dist/docs/interfaces/SecurityIdentity.html +4 -4
- package/dist/docs/interfaces/SecurityIdentityBuilder.html +2 -2
- package/dist/docs/interfaces/UploadBatchCallbackData.html +5 -5
- package/dist/docs/modules/errors.html +1 -1
- package/dist/docs/types/BatchUpdateDocumentsFromFiles.html +1 -1
- package/dist/docs/types/CompressionType.html +1 -1
- package/dist/docs/types/FailedUploadCallback.html +1 -1
- package/dist/docs/types/Metadata.html +1 -1
- package/dist/docs/types/MetadataValue.html +1 -1
- package/dist/docs/types/PlatformUrlOptions.html +1 -1
- package/dist/docs/types/SecurityIdentityType.html +1 -1
- package/dist/docs/types/SuccessfulUploadCallback.html +1 -1
- package/dist/docs/types/Transformer.html +1 -1
- package/dist/docs/variables/BuiltInTransformers.html +1 -1
- package/dist/docs/variables/Source.html +1 -1
- package/dist/help/fileContainer.spec.js +8 -7
- package/dist/help/fileContainer.spec.js.map +1 -1
- package/dist/source/catalog.js +4 -5
- package/dist/source/catalog.js.map +1 -1
- package/dist/source/documentUploader.js +2 -3
- package/dist/source/documentUploader.js.map +1 -1
- package/dist/source/documentUploader.spec.js +6 -19
- package/dist/source/documentUploader.spec.js.map +1 -1
- package/dist/source/push.js +7 -11
- package/dist/source/push.js.map +1 -1
- package/dist/source/push.spec.js +22 -50
- package/dist/source/push.spec.js.map +1 -1
- package/dist/uploadStrategy/fileContainerStrategy.js +4 -5
- package/dist/uploadStrategy/fileContainerStrategy.js.map +1 -1
- package/dist/uploadStrategy/fileContainerStrategy.spec.js +12 -28
- package/dist/uploadStrategy/fileContainerStrategy.spec.js.map +1 -1
- package/dist/uploadStrategy/streamChunkStrategy.js +5 -6
- package/dist/uploadStrategy/streamChunkStrategy.js.map +1 -1
- package/dist/uploadStrategy/streamChunkStrategy.spec.js +10 -34
- package/dist/uploadStrategy/streamChunkStrategy.spec.js.map +1 -1
- package/package.json +4 -3
- package/dist/definitions/help/axiosUtils.d.ts +0 -2
- package/dist/help/axiosUtils.js +0 -12
- package/dist/help/axiosUtils.js.map +0 -1
package/dist/source/push.spec.js
CHANGED
@@ -4,18 +4,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
jest.mock('@coveo/platform-client');
|
5
5
|
jest.mock('./documentUploader');
|
6
6
|
jest.mock('../uploadStrategy');
|
7
|
-
jest.mock('
|
7
|
+
jest.mock('../APICore');
|
8
8
|
const platform_client_1 = require("@coveo/platform-client");
|
9
9
|
const push_1 = require("./push");
|
10
10
|
const documentBuilder_1 = require("../documentBuilder");
|
11
11
|
const path_1 = require("path");
|
12
12
|
const process_1 = require("process");
|
13
13
|
const __1 = require("..");
|
14
|
-
const
|
14
|
+
const APICore_1 = require("../APICore");
|
15
15
|
const documentUploader_1 = require("./documentUploader");
|
16
16
|
const uploadStrategy_1 = require("../uploadStrategy");
|
17
17
|
const urlUtils_1 = require("../help/urlUtils");
|
18
|
-
const
|
18
|
+
const mockedAPICore = jest.mocked(APICore_1.APICore);
|
19
19
|
const mockedDelete = jest.fn();
|
20
20
|
const mockedPost = jest.fn();
|
21
21
|
const mockedPlatformClient = jest.mocked(platform_client_1.default);
|
@@ -24,29 +24,25 @@ const mockedUploadDocument = jest.mocked(documentUploader_1.uploadDocument);
|
|
24
24
|
const mockedUploadBatch = jest.mocked(documentUploader_1.uploadBatch);
|
25
25
|
const mockedUploadBatchFromFile = jest.mocked(documentUploader_1.uploadBatchFromFile);
|
26
26
|
const pathToStub = (0, path_1.join)((0, process_1.cwd)(), 'src', '__stub__');
|
27
|
-
const requestHeader = {
|
28
|
-
headers: {
|
29
|
-
Accept: 'application/json',
|
30
|
-
Authorization: 'Bearer the_key',
|
31
|
-
'Content-Type': 'application/json',
|
32
|
-
},
|
33
|
-
};
|
34
27
|
const dummyClient = {
|
35
28
|
source: {
|
36
29
|
create: mockCreateSource,
|
37
30
|
},
|
38
31
|
};
|
32
|
+
const dummyAPICore = {
|
33
|
+
delete: mockedDelete,
|
34
|
+
post: mockedPost,
|
35
|
+
};
|
39
36
|
const doMockPlatformClient = () => {
|
40
37
|
mockedPlatformClient.mockImplementation(() => dummyClient);
|
41
38
|
};
|
42
|
-
const
|
43
|
-
|
44
|
-
mockedAxios.post = mockedPost;
|
39
|
+
const doMockAPICore = () => {
|
40
|
+
mockedAPICore.mockImplementation(() => dummyAPICore);
|
45
41
|
};
|
46
42
|
describe('PushSource', () => {
|
47
43
|
let defaultSource;
|
48
44
|
beforeAll(() => {
|
49
|
-
|
45
|
+
doMockAPICore();
|
50
46
|
doMockPlatformClient();
|
51
47
|
});
|
52
48
|
beforeEach(() => {
|
@@ -90,41 +86,23 @@ describe('PushSource', () => {
|
|
90
86
|
},
|
91
87
|
])('should call #uploadDocument with $title', async ({ options, expectedUrl }) => {
|
92
88
|
await new push_1.PushSource('the_key', 'the_org', options).addOrUpdateDocument('the_id', new documentBuilder_1.DocumentBuilder('the_uri', 'the_title'));
|
93
|
-
expect(mockedUploadDocument).toHaveBeenCalledWith(dummyClient, new documentBuilder_1.DocumentBuilder('the_uri', 'the_title'), new URL(expectedUrl),
|
89
|
+
expect(mockedUploadDocument).toHaveBeenCalledWith(dummyClient, new documentBuilder_1.DocumentBuilder('the_uri', 'the_title'), new URL(expectedUrl), dummyAPICore, undefined);
|
94
90
|
});
|
95
91
|
it('should call #uploadDocument with right BatchUpdateDocumentsOptions', async () => {
|
96
92
|
await defaultSource.addOrUpdateDocument('the_id', new documentBuilder_1.DocumentBuilder('the_uri', 'the_title'), { createFields: true });
|
97
|
-
expect(mockedUploadDocument).toHaveBeenCalledWith(dummyClient, new documentBuilder_1.DocumentBuilder('the_uri', 'the_title'), new URL('https://api.cloud.coveo.com/push/v1/organizations/the_org/sources/the_id/documents'),
|
93
|
+
expect(mockedUploadDocument).toHaveBeenCalledWith(dummyClient, new documentBuilder_1.DocumentBuilder('the_uri', 'the_title'), new URL('https://api.cloud.coveo.com/push/v1/organizations/the_org/sources/the_id/documents'), dummyAPICore, { createFields: true });
|
98
94
|
});
|
99
|
-
it('should
|
95
|
+
it('should call #APICore on delete', () => {
|
100
96
|
defaultSource.deleteDocument('the_id', 'the_uri', true);
|
101
|
-
expect(mockedDelete).toHaveBeenCalledWith('https://api.cloud.coveo.com/push/v1/organizations/the_org/sources/the_id/documents?documentId=the_uri&deleteChildren=true'
|
102
|
-
headers: {
|
103
|
-
Accept: 'application/json',
|
104
|
-
Authorization: 'Bearer the_key',
|
105
|
-
'Content-Type': 'application/json',
|
106
|
-
},
|
107
|
-
});
|
97
|
+
expect(mockedDelete).toHaveBeenCalledWith('https://api.cloud.coveo.com/push/v1/organizations/the_org/sources/the_id/documents?documentId=the_uri&deleteChildren=true');
|
108
98
|
});
|
109
|
-
it('should
|
99
|
+
it('should call #APICore on status update', () => {
|
110
100
|
defaultSource.setSourceStatus('the_id', 'INCREMENTAL');
|
111
|
-
expect(mockedPost).toHaveBeenCalledWith('https://api.cloud.coveo.com/push/v1/organizations/the_org/sources/the_id/status?statusType=INCREMENTAL'
|
112
|
-
headers: {
|
113
|
-
Accept: 'application/json',
|
114
|
-
Authorization: 'Bearer the_key',
|
115
|
-
'Content-Type': 'application/json',
|
116
|
-
},
|
117
|
-
});
|
101
|
+
expect(mockedPost).toHaveBeenCalledWith('https://api.cloud.coveo.com/push/v1/organizations/the_org/sources/the_id/status?statusType=INCREMENTAL');
|
118
102
|
});
|
119
|
-
describe('when delete olderthan', () => {
|
103
|
+
describe('calls #APICore when doing delete olderthan', () => {
|
120
104
|
const expectCorrectOrderingId = (id) => {
|
121
|
-
expect(mockedDelete).toHaveBeenCalledWith(`https://api.cloud.coveo.com/push/v1/organizations/the_org/sources/the_id/documents/olderthan?orderingId=${id}
|
122
|
-
headers: {
|
123
|
-
Accept: 'application/json',
|
124
|
-
Authorization: 'Bearer the_key',
|
125
|
-
'Content-Type': 'application/json',
|
126
|
-
},
|
127
|
-
});
|
105
|
+
expect(mockedDelete).toHaveBeenCalledWith(`https://api.cloud.coveo.com/push/v1/organizations/the_org/sources/the_id/documents/olderthan?orderingId=${id}`);
|
128
106
|
};
|
129
107
|
it('with a date', () => {
|
130
108
|
const now = new Date();
|
@@ -141,15 +119,9 @@ describe('PushSource', () => {
|
|
141
119
|
expectCorrectOrderingId(nowInTimestamp);
|
142
120
|
});
|
143
121
|
});
|
144
|
-
it('should
|
122
|
+
it('should call #APICore on delete', () => {
|
145
123
|
defaultSource.deleteDocument('the_id', 'the_uri', true);
|
146
|
-
expect(mockedDelete).toHaveBeenCalledWith('https://api.cloud.coveo.com/push/v1/organizations/the_org/sources/the_id/documents?documentId=the_uri&deleteChildren=true'
|
147
|
-
headers: {
|
148
|
-
Accept: 'application/json',
|
149
|
-
Authorization: 'Bearer the_key',
|
150
|
-
'Content-Type': 'application/json',
|
151
|
-
},
|
152
|
-
});
|
124
|
+
expect(mockedDelete).toHaveBeenCalledWith('https://api.cloud.coveo.com/push/v1/organizations/the_org/sources/the_id/documents?documentId=the_uri&deleteChildren=true');
|
153
125
|
});
|
154
126
|
describe('when doing batch update', () => {
|
155
127
|
const batch = {
|
@@ -167,13 +139,13 @@ describe('PushSource', () => {
|
|
167
139
|
});
|
168
140
|
it('should call #uploadBatch with the right strategy', async () => {
|
169
141
|
await defaultSource.batchUpdateDocuments('the_id', batch);
|
170
|
-
expect(uploadStrategy_1.FileContainerStrategy).toHaveBeenCalledWith(expect.any(urlUtils_1.PushUrlBuilder),
|
142
|
+
expect(uploadStrategy_1.FileContainerStrategy).toHaveBeenCalledWith(expect.any(urlUtils_1.PushUrlBuilder), dummyAPICore);
|
171
143
|
});
|
172
144
|
});
|
173
145
|
describe('when doing batch update from local files', () => {
|
174
146
|
it('should call #uploadBatchFromFile', async () => {
|
175
147
|
await defaultSource.batchUpdateDocumentsFromFiles('the_id', [(0, path_1.join)(pathToStub, 'mixdocuments')], { createFields: false });
|
176
|
-
expect(uploadStrategy_1.FileContainerStrategy).toHaveBeenCalledWith(expect.any(urlUtils_1.PushUrlBuilder),
|
148
|
+
expect(uploadStrategy_1.FileContainerStrategy).toHaveBeenCalledWith(expect.any(urlUtils_1.PushUrlBuilder), dummyAPICore);
|
177
149
|
expect(mockedUploadBatchFromFile).toHaveBeenCalledWith(dummyClient, expect.any(uploadStrategy_1.FileContainerStrategy), [(0, path_1.join)(pathToStub, 'mixdocuments')], { createFields: false });
|
178
150
|
});
|
179
151
|
});
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"push.spec.js","sourceRoot":"","sources":["../../src/source/push.spec.ts"],"names":[],"mappings":";;AAAA,+CAA+C;AAC/C,IAAI,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;AACpC,IAAI,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;AAChC,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;AAC/B,IAAI,CAAC,IAAI,CAAC,
|
1
|
+
{"version":3,"file":"push.spec.js","sourceRoot":"","sources":["../../src/source/push.spec.ts"],"names":[],"mappings":";;AAAA,+CAA+C;AAC/C,IAAI,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;AACpC,IAAI,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;AAChC,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;AAC/B,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;AACxB,4DAAwE;AACxE,iCAAkC;AAClC,wDAAmD;AACnD,+BAA0B;AAC1B,qCAA4B;AAC5B,0BAAqE;AACrE,wCAAmC;AACnC,yDAI4B;AAC5B,sDAAwD;AACxD,+CAAgD;AAEhD,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,iBAAO,CAAC,CAAC;AAC3C,MAAM,YAAY,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAC/B,MAAM,UAAU,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAC7B,MAAM,oBAAoB,GAAG,IAAI,CAAC,MAAM,CAAC,yBAAc,CAAC,CAAC;AACzD,MAAM,gBAAgB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAEnC,MAAM,oBAAoB,GAAG,IAAI,CAAC,MAAM,CAAC,iCAAc,CAAC,CAAC;AACzD,MAAM,iBAAiB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MAAM,CAAC,sCAAqB,CAAC,CAAC,oBAAoB,CAChD,MAAM,CAAC,GAAG,CAAC,yBAAc,CAAC,EAC1B,YAAY,CACb,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,0CAA0C,EAAE,GAAG,EAAE;QACxD,EAAE,CAAC,kCAAkC,EAAE,KAAK,IAAI,EAAE;YAChD,MAAM,aAAa,CAAC,6BAA6B,CAC/C,QAAQ,EACR,CAAC,IAAA,WAAI,EAAC,UAAU,EAAE,cAAc,CAAC,CAAC,EAClC,EAAC,YAAY,EAAE,KAAK,EAAC,CACtB,CAAC;YAEF,MAAM,CAAC,sCAAqB,CAAC,CAAC,oBAAoB,CAChD,MAAM,CAAC,GAAG,CAAC,yBAAc,CAAC,EAC1B,YAAY,CACb,CAAC;YAEF,MAAM,CAAC,yBAAyB,CAAC,CAAC,oBAAoB,CACpD,WAAW,EACX,MAAM,CAAC,GAAG,CAAC,sCAAqB,CAAC,EACjC,CAAC,IAAA,WAAI,EAAC,UAAU,EAAE,cAAc,CAAC,CAAC,EAClC,EAAC,YAAY,EAAE,KAAK,EAAC,CACtB,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
@@ -1,7 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.FileContainerStrategy = void 0;
|
4
|
-
const axios_1 = require("axios");
|
5
4
|
const fileContainer_1 = require("../help/fileContainer");
|
6
5
|
/**
|
7
6
|
* Upload documents using the [File container](https://docs.coveo.com/en/43/index-content/creating-a-file-container)
|
@@ -10,9 +9,9 @@ const fileContainer_1 = require("../help/fileContainer");
|
|
10
9
|
* @implements {UploadStrategy}
|
11
10
|
*/
|
12
11
|
class FileContainerStrategy {
|
13
|
-
constructor(urlBuilder,
|
12
|
+
constructor(urlBuilder, api) {
|
14
13
|
this.urlBuilder = urlBuilder;
|
15
|
-
this.
|
14
|
+
this.api = api;
|
16
15
|
}
|
17
16
|
async upload(batch) {
|
18
17
|
const fileContainer = await this.createFileContainer();
|
@@ -21,13 +20,13 @@ class FileContainerStrategy {
|
|
21
20
|
}
|
22
21
|
async createFileContainer() {
|
23
22
|
const fileContainerURL = this.urlBuilder.fileContainerUrl.toString();
|
24
|
-
const res = await
|
23
|
+
const res = await this.api.post(fileContainerURL);
|
25
24
|
return res.data;
|
26
25
|
}
|
27
26
|
pushFileContainerContent(fileContainer) {
|
28
27
|
const pushURL = this.urlBuilder.baseAPIURLForUpdate;
|
29
28
|
pushURL.searchParams.append('fileId', fileContainer.fileId);
|
30
|
-
return
|
29
|
+
return this.api.put(pushURL.toString());
|
31
30
|
}
|
32
31
|
}
|
33
32
|
exports.FileContainerStrategy = FileContainerStrategy;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"fileContainerStrategy.js","sourceRoot":"","sources":["../../src/uploadStrategy/fileContainerStrategy.ts"],"names":[],"mappings":";;;
|
1
|
+
{"version":3,"file":"fileContainerStrategy.js","sourceRoot":"","sources":["../../src/uploadStrategy/fileContainerStrategy.ts"],"names":[],"mappings":";;;AAEA,yDAAmE;AASnE;;;;;GAKG;AACH,MAAa,qBAAqB;IAChC,YAA2B,UAAsB,EAAU,GAAY;QAA5C,eAAU,GAAV,UAAU,CAAY;QAAU,QAAG,GAAH,GAAG,CAAS;IAAG,CAAC;IAEpE,KAAK,CAAC,MAAM,CAAC,KAA2B;QAC7C,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACvD,MAAM,IAAA,4CAA4B,EAAC,aAAa,EAAE,KAAK,CAAC,CAAC;QACzD,OAAO,IAAI,CAAC,wBAAwB,CAAC,aAAa,CAAC,CAAC;IACtD,CAAC;IAEO,KAAK,CAAC,mBAAmB;QAC/B,MAAM,gBAAgB,GAAG,IAAI,CAAC,UAAU,CAAC,gBAAgB,CAAC,QAAQ,EAAE,CAAC;QACrE,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,IAAI,CAAwB,gBAAgB,CAAC,CAAC;QACzE,OAAO,GAAG,CAAC,IAAI,CAAC;IAClB,CAAC;IAEO,wBAAwB,CAAC,aAAoC;QACnE,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC;QACpD,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,QAAQ,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;QAC5D,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC1C,CAAC;CACF;AApBD,sDAoBC"}
|
@@ -1,15 +1,15 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
jest.mock('
|
3
|
+
jest.mock('../APICore');
|
4
4
|
jest.mock('../help/fileContainer');
|
5
5
|
const platform_client_1 = require("@coveo/platform-client");
|
6
|
-
const axios_1 = require("axios");
|
7
6
|
const __1 = require("..");
|
7
|
+
const APICore_1 = require("../APICore");
|
8
8
|
const environment_1 = require("../environment");
|
9
9
|
const fileContainer_1 = require("../help/fileContainer");
|
10
10
|
const urlUtils_1 = require("../help/urlUtils");
|
11
11
|
const fileContainerStrategy_1 = require("./fileContainerStrategy");
|
12
|
-
const
|
12
|
+
const mockedAPICore = jest.mocked(APICore_1.APICore);
|
13
13
|
const mockedPut = jest.fn();
|
14
14
|
const mockedPost = jest.fn();
|
15
15
|
const platformOptions = {
|
@@ -28,16 +28,18 @@ const fileContainerResponse = {
|
|
28
28
|
fileId: 'file_id',
|
29
29
|
requiredHeaders: { foo: 'bar' },
|
30
30
|
};
|
31
|
-
const
|
32
|
-
|
33
|
-
|
31
|
+
const doMockAPICore = () => {
|
32
|
+
mockedAPICore.mockImplementation(() => ({
|
33
|
+
put: mockedPut,
|
34
|
+
post: mockedPost,
|
35
|
+
}));
|
34
36
|
};
|
35
37
|
const doMockFileContainerResponse = () => {
|
36
38
|
mockedPost.mockResolvedValue({ data: fileContainerResponse });
|
37
39
|
};
|
38
40
|
describe('FileContainerStrategy', () => {
|
39
41
|
beforeAll(() => {
|
40
|
-
|
42
|
+
doMockAPICore();
|
41
43
|
});
|
42
44
|
describe.each([
|
43
45
|
{
|
@@ -55,24 +57,12 @@ describe('FileContainerStrategy', () => {
|
|
55
57
|
});
|
56
58
|
beforeEach(async () => {
|
57
59
|
const builder = new builderClass('source-id', 'org-id', platformOptions);
|
58
|
-
strategy = new fileContainerStrategy_1.FileContainerStrategy(builder,
|
59
|
-
headers: {
|
60
|
-
Accept: 'application/json',
|
61
|
-
Authorization: 'Bearer the_key',
|
62
|
-
'Content-Type': 'application/json',
|
63
|
-
},
|
64
|
-
});
|
60
|
+
strategy = new fileContainerStrategy_1.FileContainerStrategy(builder, new APICore_1.APICore('access_token'));
|
65
61
|
await strategy.upload(documentBatch);
|
66
62
|
});
|
67
63
|
it('should create a file container', () => {
|
68
64
|
expect(mockedPost).toHaveBeenCalledTimes(1);
|
69
|
-
expect(mockedPost).toHaveBeenCalledWith('https://api.cloud.coveo.com/push/v1/organizations/org-id/files'
|
70
|
-
headers: {
|
71
|
-
Accept: 'application/json',
|
72
|
-
Authorization: 'Bearer the_key',
|
73
|
-
'Content-Type': 'application/json',
|
74
|
-
},
|
75
|
-
});
|
65
|
+
expect(mockedPost).toHaveBeenCalledWith('https://api.cloud.coveo.com/push/v1/organizations/org-id/files');
|
76
66
|
});
|
77
67
|
it('should call #uploadContentToFileContainer with file container and batch', () => {
|
78
68
|
expect(fileContainer_1.uploadContentToFileContainer).toHaveBeenCalledTimes(1);
|
@@ -90,13 +80,7 @@ describe('FileContainerStrategy', () => {
|
|
90
80
|
});
|
91
81
|
it('should push file container content', () => {
|
92
82
|
expect(mockedPut).toHaveBeenCalledTimes(1);
|
93
|
-
expect(mockedPut).toHaveBeenCalledWith(pushUrl
|
94
|
-
headers: {
|
95
|
-
Accept: 'application/json',
|
96
|
-
Authorization: 'Bearer the_key',
|
97
|
-
'Content-Type': 'application/json',
|
98
|
-
},
|
99
|
-
});
|
83
|
+
expect(mockedPut).toHaveBeenCalledWith(pushUrl);
|
100
84
|
});
|
101
85
|
});
|
102
86
|
});
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"fileContainerStrategy.spec.js","sourceRoot":"","sources":["../../src/uploadStrategy/fileContainerStrategy.spec.ts"],"names":[],"mappings":";;AAAA,IAAI,CAAC,IAAI,CAAC,
|
1
|
+
{"version":3,"file":"fileContainerStrategy.spec.js","sourceRoot":"","sources":["../../src/uploadStrategy/fileContainerStrategy.spec.ts"],"names":[],"mappings":";;AAAA,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;AACxB,IAAI,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;AAEnC,4DAA8C;AAC9C,0BAAmC;AACnC,wCAAmC;AACnC,gDAAmD;AACnD,yDAAmE;AACnE,+CAAkE;AAElE,mEAGiC;AAEjC,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,iBAAO,CAAC,CAAC;AAC3C,MAAM,SAAS,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAC5B,MAAM,UAAU,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAE7B,MAAM,eAAe,GAAG;IACtB,MAAM,EAAE,wBAAM,CAAC,EAAE;IACjB,WAAW,EAAE,iCAAmB,CAAC,IAAI;CACtC,CAAC;AAEF,MAAM,aAAa,GAAyB;IAC1C,WAAW,EAAE;QACX,IAAI,mBAAe,CAAC,iBAAiB,EAAE,KAAK,CAAC;QAC7C,IAAI,mBAAe,CAAC,iBAAiB,EAAE,KAAK,CAAC;KAC9C;IACD,MAAM,EAAE,CAAC,EAAC,UAAU,EAAE,SAAS,EAAE,cAAc,EAAE,KAAK,EAAC,CAAC;CACzD,CAAC;AAEF,MAAM,qBAAqB,GAA0B;IACnD,SAAS,EAAE,yBAA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,EAAE;YACxC,MAAM,CAAC,UAAU,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;YAC5C,MAAM,CAAC,UAAU,CAAC,CAAC,oBAAoB,CACrC,gEAAgE,CACjE,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,yEAAyE,EAAE,GAAG,EAAE;YACjF,MAAM,CAAC,4CAA4B,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;YAC9D,MAAM,CAAC,4CAA4B,CAAC,CAAC,oBAAoB,CACvD,qBAAqB,EACrB;gBACE,WAAW,EAAE,MAAM,CAAC,eAAe,CAAC;oBAClC,MAAM,CAAC,gBAAgB,CAAC;wBACtB,GAAG,EAAE,iBAAiB;qBACvB,CAAC;oBACF,MAAM,CAAC,gBAAgB,CAAC;wBACtB,GAAG,EAAE,iBAAiB;qBACvB,CAAC;iBACH,CAAC;gBACF,MAAM,EAAE,CAAC,EAAC,cAAc,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,EAAC,CAAC;aACzD,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,oCAAoC,EAAE,GAAG,EAAE;YAC5C,MAAM,CAAC,SAAS,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;YAC3C,MAAM,CAAC,SAAS,CAAC,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
@@ -1,7 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.StreamChunkStrategy = void 0;
|
4
|
-
const axios_1 = require("axios");
|
5
4
|
const url_1 = require("url");
|
6
5
|
const fileContainer_1 = require("../help/fileContainer");
|
7
6
|
/**
|
@@ -11,9 +10,9 @@ const fileContainer_1 = require("../help/fileContainer");
|
|
11
10
|
* @implements {UploadStrategy}
|
12
11
|
*/
|
13
12
|
class StreamChunkStrategy {
|
14
|
-
constructor(urlBuilder,
|
13
|
+
constructor(urlBuilder, api) {
|
15
14
|
this.urlBuilder = urlBuilder;
|
16
|
-
this.
|
15
|
+
this.api = api;
|
17
16
|
this._openedStream = null;
|
18
17
|
}
|
19
18
|
async upload(batch) {
|
@@ -28,7 +27,7 @@ class StreamChunkStrategy {
|
|
28
27
|
}
|
29
28
|
async openStream() {
|
30
29
|
const openStreamUrl = new url_1.URL(`${this.urlBuilder.baseStreamURL}/open`);
|
31
|
-
const res = await
|
30
|
+
const res = await this.api.post(openStreamUrl.toString());
|
32
31
|
this._openedStream = res.data;
|
33
32
|
}
|
34
33
|
async closeOpenedStream() {
|
@@ -36,7 +35,7 @@ class StreamChunkStrategy {
|
|
36
35
|
return;
|
37
36
|
}
|
38
37
|
const openStreamUrl = new url_1.URL(`${this.urlBuilder.baseStreamURL}/${this._openedStream.streamId}/close`);
|
39
|
-
const res = await
|
38
|
+
const res = await this.api.post(openStreamUrl.toString());
|
40
39
|
this._openedStream = null;
|
41
40
|
return res.data;
|
42
41
|
}
|
@@ -46,7 +45,7 @@ class StreamChunkStrategy {
|
|
46
45
|
}
|
47
46
|
const { streamId } = this._openedStream;
|
48
47
|
const openStreamUrl = new url_1.URL(`${this.urlBuilder.baseStreamURL}/${streamId}/chunk`);
|
49
|
-
const res = await
|
48
|
+
const res = await this.api.post(openStreamUrl.toString());
|
50
49
|
return res.data;
|
51
50
|
}
|
52
51
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"streamChunkStrategy.js","sourceRoot":"","sources":["../../src/uploadStrategy/streamChunkStrategy.ts"],"names":[],"mappings":";;;AAAA,
|
1
|
+
{"version":3,"file":"streamChunkStrategy.js","sourceRoot":"","sources":["../../src/uploadStrategy/streamChunkStrategy.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAGxB,yDAAmE;AAWnE;;;;;GAKG;AACH,MAAa,mBAAmB;IAE9B,YACU,UAA4B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a,KAAK,IAAI,EAAE;YAC/B,MAAM,sBAAsB,CAAC;SAC9B;QAED,MAAM,EAAC,QAAQ,EAAC,GAAG,IAAI,CAAC,aAAa,CAAC;QACtC,MAAM,aAAa,GAAG,IAAI,SAAG,CAC3B,GAAG,IAAI,CAAC,UAAU,CAAC,aAAa,IAAI,QAAQ,QAAQ,CACrD,CAAC;QAEF,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,IAAI,CAAiB,aAAa,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC1E,OAAO,GAAG,CAAC,IAAI,CAAC;IAClB,CAAC;CACF;AArDD,kDAqDC"}
|
@@ -1,15 +1,15 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
jest.mock('
|
3
|
+
jest.mock('../APICore');
|
4
4
|
jest.mock('../help/fileContainer');
|
5
5
|
const platform_client_1 = require("@coveo/platform-client");
|
6
6
|
const __1 = require("..");
|
7
|
-
const
|
7
|
+
const APICore_1 = require("../APICore");
|
8
8
|
const environment_1 = require("../environment");
|
9
9
|
const fileContainer_1 = require("../help/fileContainer");
|
10
10
|
const urlUtils_1 = require("../help/urlUtils");
|
11
11
|
const streamChunkStrategy_1 = require("./streamChunkStrategy");
|
12
|
-
const
|
12
|
+
const mockedAPICore = jest.mocked(APICore_1.APICore);
|
13
13
|
const mockedPost = jest.fn();
|
14
14
|
const platformOptions = {
|
15
15
|
region: platform_client_1.Region.US,
|
@@ -27,8 +27,8 @@ const fileContainerResponse = {
|
|
27
27
|
fileId: 'file_id',
|
28
28
|
requiredHeaders: { foo: 'bar' },
|
29
29
|
};
|
30
|
-
const
|
31
|
-
|
30
|
+
const doMockAPICore = () => {
|
31
|
+
mockedAPICore.prototype.post.mockImplementation(mockedPost);
|
32
32
|
};
|
33
33
|
const doAxiosMockFileContainerResponse = () => ({
|
34
34
|
data: fileContainerResponse,
|
@@ -52,18 +52,12 @@ const mockSuccessAxiosCalls = () => {
|
|
52
52
|
describe('StreamChunkStrategy', () => {
|
53
53
|
let strategy;
|
54
54
|
beforeAll(() => {
|
55
|
-
|
55
|
+
doMockAPICore();
|
56
56
|
mockSuccessAxiosCalls();
|
57
57
|
});
|
58
58
|
beforeEach(async () => {
|
59
59
|
const builder = new urlUtils_1.StreamUrlBuilder('source-id', 'org-id', platformOptions);
|
60
|
-
strategy = new streamChunkStrategy_1.StreamChunkStrategy(builder,
|
61
|
-
headers: {
|
62
|
-
Accept: 'application/json',
|
63
|
-
Authorization: 'Bearer the_key',
|
64
|
-
'Content-Type': 'application/json',
|
65
|
-
},
|
66
|
-
});
|
60
|
+
strategy = new streamChunkStrategy_1.StreamChunkStrategy(builder, new APICore_1.APICore('access_token'));
|
67
61
|
await strategy.preUpload();
|
68
62
|
await strategy.upload(documentBatch);
|
69
63
|
await strategy.postUpload();
|
@@ -72,31 +66,13 @@ describe('StreamChunkStrategy', () => {
|
|
72
66
|
expect(mockedPost).toBeCalledTimes(3);
|
73
67
|
});
|
74
68
|
it('should open a stream', () => {
|
75
|
-
expect(mockedPost).toHaveBeenNthCalledWith(1, 'https://api.cloud.coveo.com/push/v1/organizations/org-id/sources/source-id/stream/open'
|
76
|
-
headers: {
|
77
|
-
Accept: 'application/json',
|
78
|
-
Authorization: 'Bearer the_key',
|
79
|
-
'Content-Type': 'application/json',
|
80
|
-
},
|
81
|
-
});
|
69
|
+
expect(mockedPost).toHaveBeenNthCalledWith(1, 'https://api.cloud.coveo.com/push/v1/organizations/org-id/sources/source-id/stream/open');
|
82
70
|
});
|
83
71
|
it('should request a stream chunk', () => {
|
84
|
-
expect(mockedPost).toHaveBeenNthCalledWith(2, 'https://api.cloud.coveo.com/push/v1/organizations/org-id/sources/source-id/stream/the_stream_id/chunk'
|
85
|
-
headers: {
|
86
|
-
Accept: 'application/json',
|
87
|
-
Authorization: 'Bearer the_key',
|
88
|
-
'Content-Type': 'application/json',
|
89
|
-
},
|
90
|
-
});
|
72
|
+
expect(mockedPost).toHaveBeenNthCalledWith(2, 'https://api.cloud.coveo.com/push/v1/organizations/org-id/sources/source-id/stream/the_stream_id/chunk');
|
91
73
|
});
|
92
74
|
it('should close the opened stream', () => {
|
93
|
-
expect(mockedPost).toHaveBeenNthCalledWith(3, 'https://api.cloud.coveo.com/push/v1/organizations/org-id/sources/source-id/stream/the_stream_id/close'
|
94
|
-
headers: {
|
95
|
-
Accept: 'application/json',
|
96
|
-
Authorization: 'Bearer the_key',
|
97
|
-
'Content-Type': 'application/json',
|
98
|
-
},
|
99
|
-
});
|
75
|
+
expect(mockedPost).toHaveBeenNthCalledWith(3, 'https://api.cloud.coveo.com/push/v1/organizations/org-id/sources/source-id/stream/the_stream_id/close');
|
100
76
|
});
|
101
77
|
it('should call #uploadContentToFileContainer with file container and batch', () => {
|
102
78
|
expect(fileContainer_1.uploadContentToFileContainer).toHaveBeenCalledTimes(1);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"streamChunkStrategy.spec.js","sourceRoot":"","sources":["../../src/uploadStrategy/streamChunkStrategy.spec.ts"],"names":[],"mappings":";;AAAA,IAAI,CAAC,IAAI,CAAC,
|
1
|
+
{"version":3,"file":"streamChunkStrategy.spec.js","sourceRoot":"","sources":["../../src/uploadStrategy/streamChunkStrategy.spec.ts"],"names":[],"mappings":";;AAAA,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;AACxB,IAAI,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;AAEnC,4DAA8C;AAC9C,0BAAmC;AACnC,wCAAmC;AACnC,gDAAmD;AACnD,yDAAmE;AACnE,+CAAkD;AAGlD,+DAA0D;AAE1D,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,iBAAO,CAAC,CAAC;AAC3C,MAAM,UAAU,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAE7B,MAAM,eAAe,GAAG;IACtB,MAAM,EAAE,wBAAM,CAAC,EAAE;IACjB,WAAW,EAAE,iCAAmB,CAAC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d,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@coveo/push-api-client",
|
3
|
-
"version": "2.
|
3
|
+
"version": "2.7.1",
|
4
4
|
"description": "Push API client",
|
5
5
|
"main": "./dist/index.js",
|
6
6
|
"files": [
|
@@ -10,10 +10,11 @@
|
|
10
10
|
"types": "./dist/definitions/index.d.ts",
|
11
11
|
"dependencies": {
|
12
12
|
"@coveo/bueno": "^0.42.0",
|
13
|
-
"@coveo/platform-client": "
|
13
|
+
"@coveo/platform-client": "37.1.0",
|
14
14
|
"abortcontroller-polyfill": "^1.7.1",
|
15
|
-
"axios": "^0.
|
15
|
+
"axios": "^1.0.0",
|
16
16
|
"dayjs": "^1.10.4",
|
17
|
+
"exponential-backoff": "^3.1.0",
|
17
18
|
"isomorphic-fetch": "^3.0.0"
|
18
19
|
},
|
19
20
|
"devDependencies": {
|
package/dist/help/axiosUtils.js
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.axiosRequestHeaders = void 0;
|
4
|
-
const axiosRequestHeaders = (apikey) => {
|
5
|
-
const authorizationHeader = {
|
6
|
-
Authorization: `Bearer ${apikey}`,
|
7
|
-
};
|
8
|
-
const documentsRequestHeaders = Object.assign(Object.assign({}, authorizationHeader), { 'Content-Type': 'application/json', Accept: 'application/json' });
|
9
|
-
return { headers: documentsRequestHeaders };
|
10
|
-
};
|
11
|
-
exports.axiosRequestHeaders = axiosRequestHeaders;
|
12
|
-
//# sourceMappingURL=axiosUtils.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"axiosUtils.js","sourceRoot":"","sources":["../../src/help/axiosUtils.ts"],"names":[],"mappings":";;;AAEO,MAAM,mBAAmB,GAAG,CAAC,MAAc,EAAsB,EAAE;IACxE,MAAM,mBAAmB,GAAG;QAC1B,aAAa,EAAE,UAAU,MAAM,EAAE;KAClC,CAAC;IAEF,MAAM,uBAAuB,mCACxB,mBAAmB,KACtB,cAAc,EAAE,kBAAkB,EAClC,MAAM,EAAE,kBAAkB,GAC3B,CAAC;IAEF,OAAO,EAAC,OAAO,EAAE,uBAAuB,EAAC,CAAC;AAC5C,CAAC,CAAC;AAZW,QAAA,mBAAmB,uBAY9B"}
|