@coveo/push-api-client 3.0.122 → 3.0.123

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 +1 -1
@@ -1,87 +1,87 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- jest.mock('../APICore');
4
- jest.mock('../help/fileContainer');
5
- const platform_client_1 = require("@coveo/platform-client");
6
- const __1 = require("..");
7
- const APICore_1 = require("../APICore");
8
- const environment_1 = require("../environment");
9
- const fileContainer_1 = require("../help/fileContainer");
10
- const urlUtils_1 = require("../help/urlUtils");
11
- const fileContainerStrategy_1 = require("./fileContainerStrategy");
12
- const mockedAPICore = jest.mocked(APICore_1.APICore);
13
- const mockedPut = jest.fn();
14
- const mockedPost = jest.fn();
15
- const platformOptions = {
16
- region: platform_client_1.Region.US,
17
- environment: environment_1.PlatformEnvironment.Prod,
18
- };
19
- const documentBatch = {
20
- addOrUpdate: [
21
- new __1.DocumentBuilder('https://foo.com', 'Foo'),
22
- new __1.DocumentBuilder('https://bar.com', 'Bar'),
23
- ],
24
- delete: [{ documentId: 'some_id', deleteChildren: false }],
25
- };
26
- const fileContainerResponse = {
27
- uploadUri: 'https://fake.upload.url',
28
- fileId: 'file_id',
29
- requiredHeaders: { foo: 'bar' },
30
- };
31
- const doMockAPICore = () => {
32
- mockedAPICore.mockImplementation(() => ({
33
- put: mockedPut,
34
- post: mockedPost,
35
- }));
36
- };
37
- const doMockFileContainerResponse = () => {
38
- mockedPost.mockResolvedValue(fileContainerResponse);
39
- };
40
- describe('FileContainerStrategy', () => {
41
- beforeAll(() => {
42
- doMockAPICore();
43
- });
44
- describe.each([
45
- {
46
- builderClass: urlUtils_1.PushUrlBuilder,
47
- pushUrl: 'https://api.cloud.coveo.com/push/v1/organizations/org-id/sources/source-id/documents/batch?fileId=file_id', // note the last part of the url
48
- },
49
- {
50
- builderClass: urlUtils_1.StreamUrlBuilder,
51
- pushUrl: 'https://api.cloud.coveo.com/push/v1/organizations/org-id/sources/source-id/stream/update?fileId=file_id', // note the last part of the url
52
- },
53
- ])('when using a $builder', ({ builderClass, pushUrl }) => {
54
- let strategy;
55
- beforeAll(() => {
56
- doMockFileContainerResponse();
57
- });
58
- beforeEach(async () => {
59
- const builder = new builderClass('source-id', 'org-id', platformOptions);
60
- strategy = new fileContainerStrategy_1.FileContainerStrategy(builder, new APICore_1.APICore('access_token'));
61
- await strategy.upload(documentBatch);
62
- });
63
- it('should create a file container', () => {
64
- expect(mockedPost).toHaveBeenCalledTimes(1);
65
- expect(mockedPost).toHaveBeenCalledWith('https://api.cloud.coveo.com/push/v1/organizations/org-id/files');
66
- });
67
- it('should call #uploadContentToFileContainer with file container and batch', () => {
68
- expect(fileContainer_1.uploadContentToFileContainer).toHaveBeenCalledTimes(1);
69
- expect(fileContainer_1.uploadContentToFileContainer).toHaveBeenCalledWith(fileContainerResponse, {
70
- addOrUpdate: expect.arrayContaining([
71
- expect.objectContaining({
72
- uri: 'https://foo.com',
73
- }),
74
- expect.objectContaining({
75
- uri: 'https://bar.com',
76
- }),
77
- ]),
78
- delete: [{ deleteChildren: false, documentId: 'some_id' }],
79
- });
80
- });
81
- it('should push file container content', () => {
82
- expect(mockedPut).toHaveBeenCalledTimes(1);
83
- expect(mockedPut).toHaveBeenCalledWith(pushUrl, undefined, false);
84
- });
85
- });
86
- });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ jest.mock('../APICore');
4
+ jest.mock('../help/fileContainer');
5
+ const platform_client_1 = require("@coveo/platform-client");
6
+ const __1 = require("..");
7
+ const APICore_1 = require("../APICore");
8
+ const environment_1 = require("../environment");
9
+ const fileContainer_1 = require("../help/fileContainer");
10
+ const urlUtils_1 = require("../help/urlUtils");
11
+ const fileContainerStrategy_1 = require("./fileContainerStrategy");
12
+ const mockedAPICore = jest.mocked(APICore_1.APICore);
13
+ const mockedPut = jest.fn();
14
+ const mockedPost = jest.fn();
15
+ const platformOptions = {
16
+ region: platform_client_1.Region.US,
17
+ environment: environment_1.PlatformEnvironment.Prod,
18
+ };
19
+ const documentBatch = {
20
+ addOrUpdate: [
21
+ new __1.DocumentBuilder('https://foo.com', 'Foo'),
22
+ new __1.DocumentBuilder('https://bar.com', 'Bar'),
23
+ ],
24
+ delete: [{ documentId: 'some_id', deleteChildren: false }],
25
+ };
26
+ const fileContainerResponse = {
27
+ uploadUri: 'https://fake.upload.url',
28
+ fileId: 'file_id',
29
+ requiredHeaders: { foo: 'bar' },
30
+ };
31
+ const doMockAPICore = () => {
32
+ mockedAPICore.mockImplementation(() => ({
33
+ put: mockedPut,
34
+ post: mockedPost,
35
+ }));
36
+ };
37
+ const doMockFileContainerResponse = () => {
38
+ mockedPost.mockResolvedValue(fileContainerResponse);
39
+ };
40
+ describe('FileContainerStrategy', () => {
41
+ beforeAll(() => {
42
+ doMockAPICore();
43
+ });
44
+ describe.each([
45
+ {
46
+ builderClass: urlUtils_1.PushUrlBuilder,
47
+ pushUrl: 'https://api.cloud.coveo.com/push/v1/organizations/org-id/sources/source-id/documents/batch?fileId=file_id', // note the last part of the url
48
+ },
49
+ {
50
+ builderClass: urlUtils_1.StreamUrlBuilder,
51
+ pushUrl: 'https://api.cloud.coveo.com/push/v1/organizations/org-id/sources/source-id/stream/update?fileId=file_id', // note the last part of the url
52
+ },
53
+ ])('when using a $builder', ({ builderClass, pushUrl }) => {
54
+ let strategy;
55
+ beforeAll(() => {
56
+ doMockFileContainerResponse();
57
+ });
58
+ beforeEach(async () => {
59
+ const builder = new builderClass('source-id', 'org-id', platformOptions);
60
+ strategy = new fileContainerStrategy_1.FileContainerStrategy(builder, new APICore_1.APICore('access_token'));
61
+ await strategy.upload(documentBatch);
62
+ });
63
+ it('should create a file container', () => {
64
+ expect(mockedPost).toHaveBeenCalledTimes(1);
65
+ expect(mockedPost).toHaveBeenCalledWith('https://api.cloud.coveo.com/push/v1/organizations/org-id/files');
66
+ });
67
+ it('should call #uploadContentToFileContainer with file container and batch', () => {
68
+ expect(fileContainer_1.uploadContentToFileContainer).toHaveBeenCalledTimes(1);
69
+ expect(fileContainer_1.uploadContentToFileContainer).toHaveBeenCalledWith(fileContainerResponse, {
70
+ addOrUpdate: expect.arrayContaining([
71
+ expect.objectContaining({
72
+ uri: 'https://foo.com',
73
+ }),
74
+ expect.objectContaining({
75
+ uri: 'https://bar.com',
76
+ }),
77
+ ]),
78
+ delete: [{ deleteChildren: false, documentId: 'some_id' }],
79
+ });
80
+ });
81
+ it('should push file container content', () => {
82
+ expect(mockedPut).toHaveBeenCalledTimes(1);
83
+ expect(mockedPut).toHaveBeenCalledWith(pushUrl, undefined, false);
84
+ });
85
+ });
86
+ });
87
87
  //# sourceMappingURL=fileContainerStrategy.spec.js.map
@@ -1,20 +1,20 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./fileContainerStrategy"), exports);
18
- __exportStar(require("./strategy"), exports);
19
- __exportStar(require("./streamChunkStrategy"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./fileContainerStrategy"), exports);
18
+ __exportStar(require("./strategy"), exports);
19
+ __exportStar(require("./streamChunkStrategy"), exports);
20
20
  //# sourceMappingURL=index.js.map
@@ -1,3 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  //# sourceMappingURL=strategy.js.map
@@ -1,53 +1,53 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StreamChunkStrategy = void 0;
4
- const url_1 = require("url");
5
- const fileContainer_1 = require("../help/fileContainer");
6
- /**
7
- * Upload documents using the [Stream API](https://docs.coveo.com/en/lb4a0344/coveo-for-commerce/how-to-stream-your-catalog-data-to-your-source)
8
- *
9
- * @class StreamChunkStrategy
10
- * @implements {UploadStrategy}
11
- */
12
- class StreamChunkStrategy {
13
- constructor(urlBuilder, api) {
14
- this.urlBuilder = urlBuilder;
15
- this.api = api;
16
- this._openedStream = null;
17
- }
18
- async upload(batch) {
19
- const chunk = await this.requestStreamChunk();
20
- return (0, fileContainer_1.uploadContentToFileContainer)(chunk, batch);
21
- }
22
- async preUpload() {
23
- await this.openStream();
24
- }
25
- async postUpload() {
26
- await this.closeOpenedStream();
27
- }
28
- async openStream() {
29
- const openStreamUrl = new url_1.URL(`${this.urlBuilder.baseStreamURL}/open`);
30
- const res = await this.api.post(openStreamUrl.toString());
31
- this._openedStream = res;
32
- }
33
- async closeOpenedStream() {
34
- if (this._openedStream === null) {
35
- return;
36
- }
37
- const openStreamUrl = new url_1.URL(`${this.urlBuilder.baseStreamURL}/${this._openedStream.streamId}/close`);
38
- const res = await this.api.post(openStreamUrl.toString());
39
- this._openedStream = null;
40
- return res;
41
- }
42
- async requestStreamChunk() {
43
- if (this._openedStream === null) {
44
- throw new Error('No open stream found');
45
- }
46
- const { streamId } = this._openedStream;
47
- const openStreamUrl = new url_1.URL(`${this.urlBuilder.baseStreamURL}/${streamId}/chunk`);
48
- const res = await this.api.post(openStreamUrl.toString());
49
- return res;
50
- }
51
- }
52
- exports.StreamChunkStrategy = StreamChunkStrategy;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StreamChunkStrategy = void 0;
4
+ const url_1 = require("url");
5
+ const fileContainer_1 = require("../help/fileContainer");
6
+ /**
7
+ * Upload documents using the [Stream API](https://docs.coveo.com/en/lb4a0344/coveo-for-commerce/how-to-stream-your-catalog-data-to-your-source)
8
+ *
9
+ * @class StreamChunkStrategy
10
+ * @implements {UploadStrategy}
11
+ */
12
+ class StreamChunkStrategy {
13
+ constructor(urlBuilder, api) {
14
+ this.urlBuilder = urlBuilder;
15
+ this.api = api;
16
+ this._openedStream = null;
17
+ }
18
+ async upload(batch) {
19
+ const chunk = await this.requestStreamChunk();
20
+ return (0, fileContainer_1.uploadContentToFileContainer)(chunk, batch);
21
+ }
22
+ async preUpload() {
23
+ await this.openStream();
24
+ }
25
+ async postUpload() {
26
+ await this.closeOpenedStream();
27
+ }
28
+ async openStream() {
29
+ const openStreamUrl = new url_1.URL(`${this.urlBuilder.baseStreamURL}/open`);
30
+ const res = await this.api.post(openStreamUrl.toString());
31
+ this._openedStream = res;
32
+ }
33
+ async closeOpenedStream() {
34
+ if (this._openedStream === null) {
35
+ return;
36
+ }
37
+ const openStreamUrl = new url_1.URL(`${this.urlBuilder.baseStreamURL}/${this._openedStream.streamId}/close`);
38
+ const res = await this.api.post(openStreamUrl.toString());
39
+ this._openedStream = null;
40
+ return res;
41
+ }
42
+ async requestStreamChunk() {
43
+ if (this._openedStream === null) {
44
+ throw new Error('No open stream found');
45
+ }
46
+ const { streamId } = this._openedStream;
47
+ const openStreamUrl = new url_1.URL(`${this.urlBuilder.baseStreamURL}/${streamId}/chunk`);
48
+ const res = await this.api.post(openStreamUrl.toString());
49
+ return res;
50
+ }
51
+ }
52
+ exports.StreamChunkStrategy = StreamChunkStrategy;
53
53
  //# sourceMappingURL=streamChunkStrategy.js.map
@@ -1,78 +1,78 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- jest.mock('../APICore');
4
- jest.mock('../help/fileContainer');
5
- const platform_client_1 = require("@coveo/platform-client");
6
- const __1 = require("..");
7
- const APICore_1 = require("../APICore");
8
- const environment_1 = require("../environment");
9
- const fileContainer_1 = require("../help/fileContainer");
10
- const urlUtils_1 = require("../help/urlUtils");
11
- const streamChunkStrategy_1 = require("./streamChunkStrategy");
12
- const mockedAPICore = jest.mocked(APICore_1.APICore);
13
- const mockedPost = jest.fn();
14
- const platformOptions = {
15
- region: platform_client_1.Region.US,
16
- environment: environment_1.PlatformEnvironment.Prod,
17
- };
18
- const documentBatch = {
19
- addOrUpdate: [
20
- new __1.DocumentBuilder('https://foo.com', 'Foo'),
21
- new __1.DocumentBuilder('https://bar.com', 'Bar'),
22
- ],
23
- delete: [{ documentId: 'some_id', deleteChildren: false }],
24
- };
25
- const fileContainerResponse = {
26
- uploadUri: 'https://fake.upload.url',
27
- fileId: 'file_id',
28
- requiredHeaders: { foo: 'bar' },
29
- };
30
- const doMockAPICore = () => {
31
- mockedAPICore.prototype.post.mockImplementation(mockedPost);
32
- };
33
- const doFetchMockFileContainerResponse = () => fileContainerResponse;
34
- const doFetchMockOpenStream = () => ({
35
- streamId: 'the_stream_id',
36
- });
37
- const mockSuccessFetchCalls = () => {
38
- mockedPost.mockImplementation((url) => {
39
- if (url.match(/chunk/)) {
40
- return doFetchMockFileContainerResponse();
41
- }
42
- if (url.match(/stream\/open/)) {
43
- return doFetchMockOpenStream();
44
- }
45
- return {};
46
- });
47
- };
48
- describe('StreamChunkStrategy', () => {
49
- let strategy;
50
- beforeAll(() => {
51
- doMockAPICore();
52
- mockSuccessFetchCalls();
53
- });
54
- beforeEach(async () => {
55
- const builder = new urlUtils_1.StreamUrlBuilder('source-id', 'org-id', platformOptions);
56
- strategy = new streamChunkStrategy_1.StreamChunkStrategy(builder, new APICore_1.APICore('access_token'));
57
- await strategy.preUpload();
58
- await strategy.upload(documentBatch);
59
- await strategy.postUpload();
60
- });
61
- it('should make 3 post calls', () => {
62
- expect(mockedPost).toBeCalledTimes(3);
63
- });
64
- it('should open a stream', () => {
65
- expect(mockedPost).toHaveBeenNthCalledWith(1, 'https://api.cloud.coveo.com/push/v1/organizations/org-id/sources/source-id/stream/open');
66
- });
67
- it('should request a stream chunk', () => {
68
- expect(mockedPost).toHaveBeenNthCalledWith(2, 'https://api.cloud.coveo.com/push/v1/organizations/org-id/sources/source-id/stream/the_stream_id/chunk');
69
- });
70
- it('should close the opened stream', () => {
71
- expect(mockedPost).toHaveBeenNthCalledWith(3, 'https://api.cloud.coveo.com/push/v1/organizations/org-id/sources/source-id/stream/the_stream_id/close');
72
- });
73
- it('should call #uploadContentToFileContainer with file container and batch', () => {
74
- expect(fileContainer_1.uploadContentToFileContainer).toHaveBeenCalledTimes(1);
75
- expect(fileContainer_1.uploadContentToFileContainer).toHaveBeenCalledWith(fileContainerResponse, documentBatch);
76
- });
77
- });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ jest.mock('../APICore');
4
+ jest.mock('../help/fileContainer');
5
+ const platform_client_1 = require("@coveo/platform-client");
6
+ const __1 = require("..");
7
+ const APICore_1 = require("../APICore");
8
+ const environment_1 = require("../environment");
9
+ const fileContainer_1 = require("../help/fileContainer");
10
+ const urlUtils_1 = require("../help/urlUtils");
11
+ const streamChunkStrategy_1 = require("./streamChunkStrategy");
12
+ const mockedAPICore = jest.mocked(APICore_1.APICore);
13
+ const mockedPost = jest.fn();
14
+ const platformOptions = {
15
+ region: platform_client_1.Region.US,
16
+ environment: environment_1.PlatformEnvironment.Prod,
17
+ };
18
+ const documentBatch = {
19
+ addOrUpdate: [
20
+ new __1.DocumentBuilder('https://foo.com', 'Foo'),
21
+ new __1.DocumentBuilder('https://bar.com', 'Bar'),
22
+ ],
23
+ delete: [{ documentId: 'some_id', deleteChildren: false }],
24
+ };
25
+ const fileContainerResponse = {
26
+ uploadUri: 'https://fake.upload.url',
27
+ fileId: 'file_id',
28
+ requiredHeaders: { foo: 'bar' },
29
+ };
30
+ const doMockAPICore = () => {
31
+ mockedAPICore.prototype.post.mockImplementation(mockedPost);
32
+ };
33
+ const doFetchMockFileContainerResponse = () => fileContainerResponse;
34
+ const doFetchMockOpenStream = () => ({
35
+ streamId: 'the_stream_id',
36
+ });
37
+ const mockSuccessFetchCalls = () => {
38
+ mockedPost.mockImplementation((url) => {
39
+ if (url.match(/chunk/)) {
40
+ return doFetchMockFileContainerResponse();
41
+ }
42
+ if (url.match(/stream\/open/)) {
43
+ return doFetchMockOpenStream();
44
+ }
45
+ return {};
46
+ });
47
+ };
48
+ describe('StreamChunkStrategy', () => {
49
+ let strategy;
50
+ beforeAll(() => {
51
+ doMockAPICore();
52
+ mockSuccessFetchCalls();
53
+ });
54
+ beforeEach(async () => {
55
+ const builder = new urlUtils_1.StreamUrlBuilder('source-id', 'org-id', platformOptions);
56
+ strategy = new streamChunkStrategy_1.StreamChunkStrategy(builder, new APICore_1.APICore('access_token'));
57
+ await strategy.preUpload();
58
+ await strategy.upload(documentBatch);
59
+ await strategy.postUpload();
60
+ });
61
+ it('should make 3 post calls', () => {
62
+ expect(mockedPost).toBeCalledTimes(3);
63
+ });
64
+ it('should open a stream', () => {
65
+ expect(mockedPost).toHaveBeenNthCalledWith(1, 'https://api.cloud.coveo.com/push/v1/organizations/org-id/sources/source-id/stream/open');
66
+ });
67
+ it('should request a stream chunk', () => {
68
+ expect(mockedPost).toHaveBeenNthCalledWith(2, 'https://api.cloud.coveo.com/push/v1/organizations/org-id/sources/source-id/stream/the_stream_id/chunk');
69
+ });
70
+ it('should close the opened stream', () => {
71
+ expect(mockedPost).toHaveBeenNthCalledWith(3, 'https://api.cloud.coveo.com/push/v1/organizations/org-id/sources/source-id/stream/the_stream_id/close');
72
+ });
73
+ it('should call #uploadContentToFileContainer with file container and batch', () => {
74
+ expect(fileContainer_1.uploadContentToFileContainer).toHaveBeenCalledTimes(1);
75
+ expect(fileContainer_1.uploadContentToFileContainer).toHaveBeenCalledWith(fileContainerResponse, documentBatch);
76
+ });
77
+ });
78
78
  //# sourceMappingURL=streamChunkStrategy.spec.js.map
@@ -1,32 +1,32 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CaseInsensitiveDocument = void 0;
4
- class CaseInsensitiveDocument {
5
- constructor(doc) {
6
- this._originalDocument = {};
7
- this._remainingRecord = {};
8
- this._originalDocument = this.shallowCopy(doc);
9
- Object.entries(doc).forEach(([k, v]) => {
10
- this._remainingRecord[k.toLowerCase()] = v;
11
- });
12
- }
13
- remove(...keys) {
14
- keys.forEach((key) => {
15
- delete this._remainingRecord[key.toLowerCase()];
16
- });
17
- }
18
- getRecordValue(key) {
19
- return this._remainingRecord[key.toLowerCase()];
20
- }
21
- get remainingRecord() {
22
- return this._remainingRecord;
23
- }
24
- get originalDocument() {
25
- return this._originalDocument;
26
- }
27
- shallowCopy(sourceRecord) {
28
- return Object.assign({}, sourceRecord);
29
- }
30
- }
31
- exports.CaseInsensitiveDocument = CaseInsensitiveDocument;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CaseInsensitiveDocument = void 0;
4
+ class CaseInsensitiveDocument {
5
+ constructor(doc) {
6
+ this._originalDocument = {};
7
+ this._remainingRecord = {};
8
+ this._originalDocument = this.shallowCopy(doc);
9
+ Object.entries(doc).forEach(([k, v]) => {
10
+ this._remainingRecord[k.toLowerCase()] = v;
11
+ });
12
+ }
13
+ remove(...keys) {
14
+ keys.forEach((key) => {
15
+ delete this._remainingRecord[key.toLowerCase()];
16
+ });
17
+ }
18
+ getRecordValue(key) {
19
+ return this._remainingRecord[key.toLowerCase()];
20
+ }
21
+ get remainingRecord() {
22
+ return this._remainingRecord;
23
+ }
24
+ get originalDocument() {
25
+ return this._originalDocument;
26
+ }
27
+ shallowCopy(sourceRecord) {
28
+ return Object.assign({}, sourceRecord);
29
+ }
30
+ }
31
+ exports.CaseInsensitiveDocument = CaseInsensitiveDocument;
32
32
  //# sourceMappingURL=caseInsensitiveDocument.js.map
@@ -1,38 +1,38 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.KnownKeys = void 0;
4
- const bueno_1 = require("@coveo/bueno");
5
- class KnownKeys {
6
- constructor(k, doc) {
7
- this.doc = doc;
8
- if (Array.isArray(k)) {
9
- this.keys = k;
10
- }
11
- else {
12
- this.keys = [k];
13
- }
14
- }
15
- get value() {
16
- const found = this.keys.find((k) => !(0, bueno_1.isNullOrUndefined)(this.doc.getRecordValue(k)));
17
- if (found) {
18
- return this.doc.getRecordValue(found);
19
- }
20
- return null;
21
- }
22
- whenExists(cb) {
23
- const value = this.value;
24
- if (!(0, bueno_1.isNullOrUndefined)(value)) {
25
- cb(value);
26
- }
27
- return this;
28
- }
29
- whenDoesNotExist(cb) {
30
- const value = this.value;
31
- if ((0, bueno_1.isNullOrUndefined)(value)) {
32
- cb(this.doc.remainingRecord);
33
- }
34
- return this;
35
- }
36
- }
37
- exports.KnownKeys = KnownKeys;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KnownKeys = void 0;
4
+ const bueno_1 = require("@coveo/bueno");
5
+ class KnownKeys {
6
+ constructor(k, doc) {
7
+ this.doc = doc;
8
+ if (Array.isArray(k)) {
9
+ this.keys = k;
10
+ }
11
+ else {
12
+ this.keys = [k];
13
+ }
14
+ }
15
+ get value() {
16
+ const found = this.keys.find((k) => !(0, bueno_1.isNullOrUndefined)(this.doc.getRecordValue(k)));
17
+ if (found) {
18
+ return this.doc.getRecordValue(found);
19
+ }
20
+ return null;
21
+ }
22
+ whenExists(cb) {
23
+ const value = this.value;
24
+ if (!(0, bueno_1.isNullOrUndefined)(value)) {
25
+ cb(value);
26
+ }
27
+ return this;
28
+ }
29
+ whenDoesNotExist(cb) {
30
+ const value = this.value;
31
+ if ((0, bueno_1.isNullOrUndefined)(value)) {
32
+ cb(this.doc.remainingRecord);
33
+ }
34
+ return this;
35
+ }
36
+ }
37
+ exports.KnownKeys = KnownKeys;
38
38
  //# sourceMappingURL=knownKey.js.map