@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,146 +1,146 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- jest.mock('../help/file');
4
- jest.mock('../validation/parseFile');
5
- jest.mock('../fieldAnalyser/fieldAnalyser');
6
- jest.mock('../fieldAnalyser/fieldUtils');
7
- const platform_client_1 = require("@coveo/platform-client");
8
- const __1 = require("..");
9
- const fieldAnalyser_1 = require("../fieldAnalyser/fieldAnalyser");
10
- const fieldUtils_1 = require("../fieldAnalyser/fieldUtils");
11
- const file_1 = require("../help/file");
12
- const function_1 = require("../help/function");
13
- const parseFile_1 = require("../validation/parseFile");
14
- const transformer_1 = require("../validation/transformers/transformer");
15
- const batchUploadDocumentsFromFile_1 = require("./batchUploadDocumentsFromFile");
16
- const mockedParse = jest.mocked(parseFile_1.parseAndGetDocumentBuilderFromJSONDocument);
17
- const mockedGetAllFilesFromEntries = jest.mocked(file_1.getAllJsonFilesFromEntries);
18
- const mockedUpload = jest.fn();
19
- const mockedPreUpload = jest.fn();
20
- const mockedPostUpload = jest.fn();
21
- const mockedStrategy = {
22
- upload: mockedUpload,
23
- preUpload: mockedPreUpload,
24
- postUpload: mockedPostUpload,
25
- };
26
- const getDocBuilder = () => new __1.DocumentBuilder('http://uri.com', 'title').withPermanentId('random-id');
27
- const getBatchUpload = (options) => {
28
- const defaultBatchOptions = {
29
- createFields: true,
30
- };
31
- const defaultBatchFromFileOptions = Object.assign(Object.assign({}, defaultBatchOptions), { fieldNameTransformer: transformer_1.BuiltInTransformers.identity, maxConcurrent: 10, callback: function_1.noop });
32
- const client = new platform_client_1.default({ accessToken: 'xxx' });
33
- return new batchUploadDocumentsFromFile_1.BatchUploadDocumentsFromFilesReturn(client, mockedStrategy, ['some/folder'], Object.assign(Object.assign({}, defaultBatchFromFileOptions), options));
34
- };
35
- const doMockSuccessUpload = () => {
36
- mockedUpload.mockResolvedValue({ status: 202, statusText: 'ALL_GOOD' });
37
- };
38
- const doMockFailedUpload = () => {
39
- mockedUpload.mockRejectedValue({ status: 412, statusText: 'BAD_REQUEST' });
40
- };
41
- const doMockSuccessParse = () => {
42
- mockedParse.mockResolvedValue([getDocBuilder()]);
43
- };
44
- const doMockGetFilesFromEntries = () => {
45
- mockedGetAllFilesFromEntries.mockReturnValue([
46
- 'path/file_1.json',
47
- 'path/file_2.json',
48
- ]);
49
- };
50
- describe('BatchUploadDocumentsFromFilesReturn', () => {
51
- beforeEach(() => {
52
- doMockSuccessUpload();
53
- });
54
- beforeAll(() => {
55
- doMockGetFilesFromEntries();
56
- doMockSuccessParse();
57
- });
58
- describe('when createFields option is set to true', () => {
59
- beforeEach(async () => {
60
- await getBatchUpload({ createFields: true }).batch();
61
- });
62
- it('should always call the field analyser', () => {
63
- expect(fieldAnalyser_1.FieldAnalyser).toHaveBeenCalledTimes(1);
64
- });
65
- it('should call #createFieldsFromReport', () => {
66
- expect(fieldUtils_1.createFieldsFromReport).toHaveBeenCalledTimes(1);
67
- });
68
- });
69
- describe('when createFields option is set to false', () => {
70
- beforeEach(() => {
71
- getBatchUpload({ createFields: false }).batch();
72
- });
73
- it('should always call the field analyser', () => {
74
- expect(fieldAnalyser_1.FieldAnalyser).toHaveBeenCalledTimes(1);
75
- });
76
- it('should call #createFieldsFromReport', () => {
77
- expect(fieldUtils_1.createFieldsFromReport).not.toHaveBeenCalled();
78
- });
79
- });
80
- describe('when files are successfully consumed', () => {
81
- const mockedSuccessCallback = jest.fn();
82
- const mockedErrorCallback = jest.fn();
83
- beforeEach(async () => {
84
- await getBatchUpload()
85
- .onBatchUpload(mockedSuccessCallback)
86
- .onBatchError(mockedErrorCallback)
87
- .batch();
88
- });
89
- it('should call the success callback', async () => {
90
- expect(mockedSuccessCallback).toHaveBeenCalledWith({
91
- batch: [getDocBuilder(), getDocBuilder()],
92
- files: ['file_1.json', 'file_2.json'],
93
- progress: {
94
- remainingDocumentCount: 0,
95
- totalDocumentCount: 2,
96
- },
97
- res: {
98
- status: 202,
99
- statusText: 'ALL_GOOD',
100
- },
101
- });
102
- });
103
- it('should call the callback without error when uploading documents', async () => {
104
- expect(mockedErrorCallback).not.toHaveBeenCalled();
105
- });
106
- });
107
- describe('when API returns an error', () => {
108
- const mockedSuccessCallback = jest.fn();
109
- const mockedErrorCallback = jest.fn();
110
- beforeAll(() => {
111
- mockedUpload.mockReset();
112
- });
113
- beforeEach(async () => {
114
- doMockFailedUpload();
115
- await getBatchUpload()
116
- .onBatchUpload(mockedSuccessCallback)
117
- .onBatchError(mockedErrorCallback)
118
- .batch();
119
- });
120
- it('should call the errorCallback on a failure from the API', async () => {
121
- expect(mockedErrorCallback).toHaveBeenCalledWith({ status: 412, statusText: 'BAD_REQUEST' }, {
122
- batch: [getDocBuilder(), getDocBuilder()],
123
- files: ['file_1.json', 'file_2.json'],
124
- progress: {
125
- remainingDocumentCount: 0,
126
- totalDocumentCount: 2,
127
- },
128
- });
129
- });
130
- });
131
- it('should call #getAllJsonFilesFromEntries with the right files', async () => {
132
- await getBatchUpload().batch();
133
- expect(mockedGetAllFilesFromEntries).toHaveBeenCalledWith(['some/folder']);
134
- });
135
- it('should execute pre and post upload methods once', async () => {
136
- await getBatchUpload().batch();
137
- expect(mockedPreUpload).toHaveBeenCalledTimes(1);
138
- expect(mockedPostUpload).toHaveBeenCalledTimes(1);
139
- expect(mockedUpload).toHaveBeenCalledTimes(1);
140
- });
141
- it('should execute upload', async () => {
142
- await getBatchUpload().batch();
143
- expect(mockedUpload).toHaveBeenCalled();
144
- });
145
- });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ jest.mock('../help/file');
4
+ jest.mock('../validation/parseFile');
5
+ jest.mock('../fieldAnalyser/fieldAnalyser');
6
+ jest.mock('../fieldAnalyser/fieldUtils');
7
+ const platform_client_1 = require("@coveo/platform-client");
8
+ const __1 = require("..");
9
+ const fieldAnalyser_1 = require("../fieldAnalyser/fieldAnalyser");
10
+ const fieldUtils_1 = require("../fieldAnalyser/fieldUtils");
11
+ const file_1 = require("../help/file");
12
+ const function_1 = require("../help/function");
13
+ const parseFile_1 = require("../validation/parseFile");
14
+ const transformer_1 = require("../validation/transformers/transformer");
15
+ const batchUploadDocumentsFromFile_1 = require("./batchUploadDocumentsFromFile");
16
+ const mockedParse = jest.mocked(parseFile_1.parseAndGetDocumentBuilderFromJSONDocument);
17
+ const mockedGetAllFilesFromEntries = jest.mocked(file_1.getAllJsonFilesFromEntries);
18
+ const mockedUpload = jest.fn();
19
+ const mockedPreUpload = jest.fn();
20
+ const mockedPostUpload = jest.fn();
21
+ const mockedStrategy = {
22
+ upload: mockedUpload,
23
+ preUpload: mockedPreUpload,
24
+ postUpload: mockedPostUpload,
25
+ };
26
+ const getDocBuilder = () => new __1.DocumentBuilder('http://uri.com', 'title').withPermanentId('random-id');
27
+ const getBatchUpload = (options) => {
28
+ const defaultBatchOptions = {
29
+ createFields: true,
30
+ };
31
+ const defaultBatchFromFileOptions = Object.assign(Object.assign({}, defaultBatchOptions), { fieldNameTransformer: transformer_1.BuiltInTransformers.identity, maxConcurrent: 10, callback: function_1.noop });
32
+ const client = new platform_client_1.default({ accessToken: 'xxx' });
33
+ return new batchUploadDocumentsFromFile_1.BatchUploadDocumentsFromFilesReturn(client, mockedStrategy, ['some/folder'], Object.assign(Object.assign({}, defaultBatchFromFileOptions), options));
34
+ };
35
+ const doMockSuccessUpload = () => {
36
+ mockedUpload.mockResolvedValue({ status: 202, statusText: 'ALL_GOOD' });
37
+ };
38
+ const doMockFailedUpload = () => {
39
+ mockedUpload.mockRejectedValue({ status: 412, statusText: 'BAD_REQUEST' });
40
+ };
41
+ const doMockSuccessParse = () => {
42
+ mockedParse.mockResolvedValue([getDocBuilder()]);
43
+ };
44
+ const doMockGetFilesFromEntries = () => {
45
+ mockedGetAllFilesFromEntries.mockReturnValue([
46
+ 'path/file_1.json',
47
+ 'path/file_2.json',
48
+ ]);
49
+ };
50
+ describe('BatchUploadDocumentsFromFilesReturn', () => {
51
+ beforeEach(() => {
52
+ doMockSuccessUpload();
53
+ });
54
+ beforeAll(() => {
55
+ doMockGetFilesFromEntries();
56
+ doMockSuccessParse();
57
+ });
58
+ describe('when createFields option is set to true', () => {
59
+ beforeEach(async () => {
60
+ await getBatchUpload({ createFields: true }).batch();
61
+ });
62
+ it('should always call the field analyser', () => {
63
+ expect(fieldAnalyser_1.FieldAnalyser).toHaveBeenCalledTimes(1);
64
+ });
65
+ it('should call #createFieldsFromReport', () => {
66
+ expect(fieldUtils_1.createFieldsFromReport).toHaveBeenCalledTimes(1);
67
+ });
68
+ });
69
+ describe('when createFields option is set to false', () => {
70
+ beforeEach(() => {
71
+ getBatchUpload({ createFields: false }).batch();
72
+ });
73
+ it('should always call the field analyser', () => {
74
+ expect(fieldAnalyser_1.FieldAnalyser).toHaveBeenCalledTimes(1);
75
+ });
76
+ it('should call #createFieldsFromReport', () => {
77
+ expect(fieldUtils_1.createFieldsFromReport).not.toHaveBeenCalled();
78
+ });
79
+ });
80
+ describe('when files are successfully consumed', () => {
81
+ const mockedSuccessCallback = jest.fn();
82
+ const mockedErrorCallback = jest.fn();
83
+ beforeEach(async () => {
84
+ await getBatchUpload()
85
+ .onBatchUpload(mockedSuccessCallback)
86
+ .onBatchError(mockedErrorCallback)
87
+ .batch();
88
+ });
89
+ it('should call the success callback', async () => {
90
+ expect(mockedSuccessCallback).toHaveBeenCalledWith({
91
+ batch: [getDocBuilder(), getDocBuilder()],
92
+ files: ['file_1.json', 'file_2.json'],
93
+ progress: {
94
+ remainingDocumentCount: 0,
95
+ totalDocumentCount: 2,
96
+ },
97
+ res: {
98
+ status: 202,
99
+ statusText: 'ALL_GOOD',
100
+ },
101
+ });
102
+ });
103
+ it('should call the callback without error when uploading documents', async () => {
104
+ expect(mockedErrorCallback).not.toHaveBeenCalled();
105
+ });
106
+ });
107
+ describe('when API returns an error', () => {
108
+ const mockedSuccessCallback = jest.fn();
109
+ const mockedErrorCallback = jest.fn();
110
+ beforeAll(() => {
111
+ mockedUpload.mockReset();
112
+ });
113
+ beforeEach(async () => {
114
+ doMockFailedUpload();
115
+ await getBatchUpload()
116
+ .onBatchUpload(mockedSuccessCallback)
117
+ .onBatchError(mockedErrorCallback)
118
+ .batch();
119
+ });
120
+ it('should call the errorCallback on a failure from the API', async () => {
121
+ expect(mockedErrorCallback).toHaveBeenCalledWith({ status: 412, statusText: 'BAD_REQUEST' }, {
122
+ batch: [getDocBuilder(), getDocBuilder()],
123
+ files: ['file_1.json', 'file_2.json'],
124
+ progress: {
125
+ remainingDocumentCount: 0,
126
+ totalDocumentCount: 2,
127
+ },
128
+ });
129
+ });
130
+ });
131
+ it('should call #getAllJsonFilesFromEntries with the right files', async () => {
132
+ await getBatchUpload().batch();
133
+ expect(mockedGetAllFilesFromEntries).toHaveBeenCalledWith(['some/folder']);
134
+ });
135
+ it('should execute pre and post upload methods once', async () => {
136
+ await getBatchUpload().batch();
137
+ expect(mockedPreUpload).toHaveBeenCalledTimes(1);
138
+ expect(mockedPostUpload).toHaveBeenCalledTimes(1);
139
+ expect(mockedUpload).toHaveBeenCalledTimes(1);
140
+ });
141
+ it('should execute upload', async () => {
142
+ await getBatchUpload().batch();
143
+ expect(mockedUpload).toHaveBeenCalled();
144
+ });
145
+ });
146
146
  //# sourceMappingURL=batchUploadDocumentsFromFile.spec.js.map
@@ -1,112 +1,112 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CatalogSource = void 0;
4
- require("fetch-undici-polyfill");
5
- const platform_client_1 = require("@coveo/platform-client");
6
- const environment_1 = require("../environment");
7
- const securityIdenty_1 = require("./securityIdenty");
8
- const uploadStrategy_1 = require("../uploadStrategy");
9
- const documentUploader_1 = require("./documentUploader");
10
- const urlUtils_1 = require("../help/urlUtils");
11
- const APICore_1 = require("../APICore");
12
- /**
13
- * Manage a catalog source.
14
- *
15
- * Allows you to create a new catalog source, manage security identities and documents in a Coveo organization.
16
- */
17
- class CatalogSource {
18
- /**
19
- * Creates an instance of CatalogSource.
20
- * @param {string} apikey An apiKey capable of pushing documents and managing sources in a Coveo organization. See [Manage API Keys](https://docs.coveo.com/en/1718).
21
- * @param {string} organizationid The Coveo Organization identifier.
22
- * @param {PlatformUrlOptions} [opts=CatalogSource.defaultOptions]
23
- */
24
- constructor(apikey, organizationid, opts = CatalogSource.defaultOptions) {
25
- this.apikey = apikey;
26
- this.organizationid = organizationid;
27
- this.options = Object.assign(Object.assign({}, CatalogSource.defaultOptions), opts);
28
- this.api = new APICore_1.APICore(this.apikey);
29
- this.platformClient = new platform_client_1.PlatformClient({
30
- accessToken: apikey,
31
- environment: (0, environment_1.castEnvironmentToPlatformClient)(this.options.environment),
32
- organizationId: organizationid,
33
- region: this.options.region,
34
- });
35
- }
36
- /**
37
- * Create a new catalog source
38
- * @param name The name of the source to create.
39
- * @param sourceVisibility The security option that should be applied to the content of the source. See [Content Security](https://docs.coveo.com/en/1779).
40
- * @returns
41
- */
42
- create(name, sourceVisibility) {
43
- return this.platformClient.source.create({
44
- name,
45
- streamEnabled: true,
46
- sourceVisibility,
47
- sourceType: platform_client_1.SourceType.CATALOG,
48
- });
49
- }
50
- get identity() {
51
- return new securityIdenty_1.SecurityIdentity(this.platformClient);
52
- }
53
- /**
54
- * Manage batches of items in a catalog source.
55
- * See [Full Document Update](https://docs.coveo.com/en/l62e0540)
56
- * @param sourceId
57
- * @param batch
58
- * @param {BatchUpdateDocumentsOptions}
59
- * @returns
60
- */
61
- batchUpdateDocuments(sourceId, batch, options) {
62
- const strategy = this.fileContainerStrategy(sourceId);
63
- return (0, documentUploader_1.uploadBatch)(this.platformClient, strategy, batch, options);
64
- }
65
- /**
66
- * Send your catalog data to your catalog source.
67
- * See [How to Stream Your Catalog Data to Your Source](https://docs.coveo.com/en/lb4a0344)
68
- * @param {string} sourceId
69
- * @param {BatchUpdateDocuments} batch
70
- * @param {BatchUpdateDocumentsOptions}
71
- */
72
- async batchStreamDocuments(sourceId, batch, options) {
73
- const strategy = this.streamChunkStrategy(sourceId);
74
- await (0, documentUploader_1.uploadBatch)(this.platformClient, strategy, batch, options);
75
- }
76
- /**
77
- * Manage batches of items in a catalog source from a list of JSON files. See [Full Document Update Source](https://docs.coveo.com/en/l62e0540)
78
- * @param {string} sourceId The unique identifier of the target Push source
79
- * @param {string[]} filesOrDirectories A list of JSON files or directories (containing JSON files) from which to extract documents.
80
- * @param {BatchUpdateDocumentsFromFiles} options
81
- */
82
- batchUpdateDocumentsFromFiles(sourceId, filesOrDirectories, options) {
83
- return (0, documentUploader_1.uploadBatchFromFile)(this.platformClient, this.fileContainerStrategy(sourceId), filesOrDirectories, options);
84
- }
85
- /**
86
- * Send your catalog data to your catalog source from a list of JSON files.
87
- * See [How to Stream Your Catalog Data to Your Source](https://docs.coveo.com/en/lb4a0344)
88
- * @param {string} sourceId The unique identifier of the target Push source
89
- * @param {string[]} filesOrDirectories A list of JSON files or directories (containing JSON files) from which to extract documents.
90
- * @param {BatchUpdateDocumentsFromFiles} [options]
91
- */
92
- batchStreamDocumentsFromFiles(sourceId, filesOrDirectories, options) {
93
- return (0, documentUploader_1.uploadBatchFromFile)(this.platformClient, this.streamChunkStrategy(sourceId), filesOrDirectories, options);
94
- }
95
- urlBuilder(sourceId) {
96
- return new urlUtils_1.StreamUrlBuilder(sourceId, this.organizationid, this.options);
97
- }
98
- fileContainerStrategy(sourceId) {
99
- const urlBuilder = this.urlBuilder(sourceId);
100
- return new uploadStrategy_1.FileContainerStrategy(urlBuilder, this.api);
101
- }
102
- streamChunkStrategy(sourceId) {
103
- const urlBuilder = this.urlBuilder(sourceId);
104
- return new uploadStrategy_1.StreamChunkStrategy(urlBuilder, this.api);
105
- }
106
- }
107
- exports.CatalogSource = CatalogSource;
108
- CatalogSource.defaultOptions = {
109
- region: environment_1.DEFAULT_REGION,
110
- environment: environment_1.DEFAULT_ENVIRONMENT,
111
- };
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CatalogSource = void 0;
4
+ require("fetch-undici-polyfill");
5
+ const platform_client_1 = require("@coveo/platform-client");
6
+ const environment_1 = require("../environment");
7
+ const securityIdenty_1 = require("./securityIdenty");
8
+ const uploadStrategy_1 = require("../uploadStrategy");
9
+ const documentUploader_1 = require("./documentUploader");
10
+ const urlUtils_1 = require("../help/urlUtils");
11
+ const APICore_1 = require("../APICore");
12
+ /**
13
+ * Manage a catalog source.
14
+ *
15
+ * Allows you to create a new catalog source, manage security identities and documents in a Coveo organization.
16
+ */
17
+ class CatalogSource {
18
+ /**
19
+ * Creates an instance of CatalogSource.
20
+ * @param {string} apikey An apiKey capable of pushing documents and managing sources in a Coveo organization. See [Manage API Keys](https://docs.coveo.com/en/1718).
21
+ * @param {string} organizationid The Coveo Organization identifier.
22
+ * @param {PlatformUrlOptions} [opts=CatalogSource.defaultOptions]
23
+ */
24
+ constructor(apikey, organizationid, opts = CatalogSource.defaultOptions) {
25
+ this.apikey = apikey;
26
+ this.organizationid = organizationid;
27
+ this.options = Object.assign(Object.assign({}, CatalogSource.defaultOptions), opts);
28
+ this.api = new APICore_1.APICore(this.apikey);
29
+ this.platformClient = new platform_client_1.PlatformClient({
30
+ accessToken: apikey,
31
+ environment: (0, environment_1.castEnvironmentToPlatformClient)(this.options.environment),
32
+ organizationId: organizationid,
33
+ region: this.options.region,
34
+ });
35
+ }
36
+ /**
37
+ * Create a new catalog source
38
+ * @param name The name of the source to create.
39
+ * @param sourceVisibility The security option that should be applied to the content of the source. See [Content Security](https://docs.coveo.com/en/1779).
40
+ * @returns
41
+ */
42
+ create(name, sourceVisibility) {
43
+ return this.platformClient.source.create({
44
+ name,
45
+ streamEnabled: true,
46
+ sourceVisibility,
47
+ sourceType: platform_client_1.SourceType.CATALOG,
48
+ });
49
+ }
50
+ get identity() {
51
+ return new securityIdenty_1.SecurityIdentity(this.platformClient);
52
+ }
53
+ /**
54
+ * Manage batches of items in a catalog source.
55
+ * See [Full Document Update](https://docs.coveo.com/en/l62e0540)
56
+ * @param sourceId
57
+ * @param batch
58
+ * @param {BatchUpdateDocumentsOptions}
59
+ * @returns
60
+ */
61
+ batchUpdateDocuments(sourceId, batch, options) {
62
+ const strategy = this.fileContainerStrategy(sourceId);
63
+ return (0, documentUploader_1.uploadBatch)(this.platformClient, strategy, batch, options);
64
+ }
65
+ /**
66
+ * Send your catalog data to your catalog source.
67
+ * See [How to Stream Your Catalog Data to Your Source](https://docs.coveo.com/en/lb4a0344)
68
+ * @param {string} sourceId
69
+ * @param {BatchUpdateDocuments} batch
70
+ * @param {BatchUpdateDocumentsOptions}
71
+ */
72
+ async batchStreamDocuments(sourceId, batch, options) {
73
+ const strategy = this.streamChunkStrategy(sourceId);
74
+ await (0, documentUploader_1.uploadBatch)(this.platformClient, strategy, batch, options);
75
+ }
76
+ /**
77
+ * Manage batches of items in a catalog source from a list of JSON files. See [Full Document Update Source](https://docs.coveo.com/en/l62e0540)
78
+ * @param {string} sourceId The unique identifier of the target Push source
79
+ * @param {string[]} filesOrDirectories A list of JSON files or directories (containing JSON files) from which to extract documents.
80
+ * @param {BatchUpdateDocumentsFromFiles} options
81
+ */
82
+ batchUpdateDocumentsFromFiles(sourceId, filesOrDirectories, options) {
83
+ return (0, documentUploader_1.uploadBatchFromFile)(this.platformClient, this.fileContainerStrategy(sourceId), filesOrDirectories, options);
84
+ }
85
+ /**
86
+ * Send your catalog data to your catalog source from a list of JSON files.
87
+ * See [How to Stream Your Catalog Data to Your Source](https://docs.coveo.com/en/lb4a0344)
88
+ * @param {string} sourceId The unique identifier of the target Push source
89
+ * @param {string[]} filesOrDirectories A list of JSON files or directories (containing JSON files) from which to extract documents.
90
+ * @param {BatchUpdateDocumentsFromFiles} [options]
91
+ */
92
+ batchStreamDocumentsFromFiles(sourceId, filesOrDirectories, options) {
93
+ return (0, documentUploader_1.uploadBatchFromFile)(this.platformClient, this.streamChunkStrategy(sourceId), filesOrDirectories, options);
94
+ }
95
+ urlBuilder(sourceId) {
96
+ return new urlUtils_1.StreamUrlBuilder(sourceId, this.organizationid, this.options);
97
+ }
98
+ fileContainerStrategy(sourceId) {
99
+ const urlBuilder = this.urlBuilder(sourceId);
100
+ return new uploadStrategy_1.FileContainerStrategy(urlBuilder, this.api);
101
+ }
102
+ streamChunkStrategy(sourceId) {
103
+ const urlBuilder = this.urlBuilder(sourceId);
104
+ return new uploadStrategy_1.StreamChunkStrategy(urlBuilder, this.api);
105
+ }
106
+ }
107
+ exports.CatalogSource = CatalogSource;
108
+ CatalogSource.defaultOptions = {
109
+ region: environment_1.DEFAULT_REGION,
110
+ environment: environment_1.DEFAULT_ENVIRONMENT,
111
+ };
112
112
  //# sourceMappingURL=catalog.js.map
@@ -1,65 +1,65 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- jest.mock('@coveo/platform-client');
4
- jest.mock('./documentUploader');
5
- const platform_client_1 = require("@coveo/platform-client");
6
- const documentBuilder_1 = require("../documentBuilder");
7
- const path_1 = require("path");
8
- const process_1 = require("process");
9
- const catalog_1 = require("./catalog");
10
- const documentUploader_1 = require("./documentUploader");
11
- const uploadStrategy_1 = require("../uploadStrategy");
12
- const mockedUploadBatch = jest.mocked(documentUploader_1.uploadBatch);
13
- const mockedUploadBatchFromFile = jest.mocked(documentUploader_1.uploadBatchFromFile);
14
- const mockedPlatformClient = jest.mocked(platform_client_1.default);
15
- const mockCreateSource = jest.fn();
16
- const pathToStub = (0, path_1.join)((0, process_1.cwd)(), 'src', '__stub__');
17
- const dummyClient = {
18
- source: {
19
- create: mockCreateSource,
20
- },
21
- };
22
- const doMockPlatformClient = () => {
23
- mockedPlatformClient.mockImplementation(() => dummyClient);
24
- };
25
- describe('CatalogSource', () => {
26
- let source;
27
- let batch;
28
- beforeAll(() => {
29
- doMockPlatformClient();
30
- });
31
- beforeEach(() => {
32
- source = new catalog_1.CatalogSource('the_key', 'the_org');
33
- batch = {
34
- addOrUpdate: [
35
- new documentBuilder_1.DocumentBuilder('the_uri_1', 'the_title_1'),
36
- new documentBuilder_1.DocumentBuilder('the_uri_2', 'the_title_2'),
37
- ],
38
- delete: [{ documentId: 'the_uri_3', deleteChildren: true }],
39
- };
40
- });
41
- it('should call platform client on creation', () => {
42
- source.create('the_name', platform_client_1.SourceVisibility.SHARED);
43
- expect(mockCreateSource).toHaveBeenCalledWith({
44
- name: 'the_name',
45
- streamEnabled: true,
46
- sourceType: 'CATALOG',
47
- sourceVisibility: 'SHARED',
48
- });
49
- });
50
- it('should upload a batch', async () => {
51
- await source.batchUpdateDocuments('the_id', batch, {
52
- createFields: false,
53
- });
54
- expect(mockedUploadBatch).toHaveBeenCalledWith(dummyClient, expect.any(uploadStrategy_1.FileContainerStrategy), batch, { createFields: false });
55
- });
56
- it('should upload documents from local file', async () => {
57
- await source.batchUpdateDocumentsFromFiles('the_id', [(0, path_1.join)(pathToStub, 'mixdocuments')], { createFields: false });
58
- expect(mockedUploadBatchFromFile).toHaveBeenCalledWith(dummyClient, expect.any(uploadStrategy_1.FileContainerStrategy), [(0, path_1.join)(pathToStub, 'mixdocuments')], { createFields: false });
59
- });
60
- it('should stream documents from local file', async () => {
61
- await source.batchStreamDocumentsFromFiles('the_id', [(0, path_1.join)(pathToStub, 'mixdocuments')], { createFields: false });
62
- expect(mockedUploadBatchFromFile).toHaveBeenCalledWith(dummyClient, expect.any(uploadStrategy_1.StreamChunkStrategy), [(0, path_1.join)(pathToStub, 'mixdocuments')], { createFields: false });
63
- });
64
- });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ jest.mock('@coveo/platform-client');
4
+ jest.mock('./documentUploader');
5
+ const platform_client_1 = require("@coveo/platform-client");
6
+ const documentBuilder_1 = require("../documentBuilder");
7
+ const path_1 = require("path");
8
+ const process_1 = require("process");
9
+ const catalog_1 = require("./catalog");
10
+ const documentUploader_1 = require("./documentUploader");
11
+ const uploadStrategy_1 = require("../uploadStrategy");
12
+ const mockedUploadBatch = jest.mocked(documentUploader_1.uploadBatch);
13
+ const mockedUploadBatchFromFile = jest.mocked(documentUploader_1.uploadBatchFromFile);
14
+ const mockedPlatformClient = jest.mocked(platform_client_1.default);
15
+ const mockCreateSource = jest.fn();
16
+ const pathToStub = (0, path_1.join)((0, process_1.cwd)(), 'src', '__stub__');
17
+ const dummyClient = {
18
+ source: {
19
+ create: mockCreateSource,
20
+ },
21
+ };
22
+ const doMockPlatformClient = () => {
23
+ mockedPlatformClient.mockImplementation(() => dummyClient);
24
+ };
25
+ describe('CatalogSource', () => {
26
+ let source;
27
+ let batch;
28
+ beforeAll(() => {
29
+ doMockPlatformClient();
30
+ });
31
+ beforeEach(() => {
32
+ source = new catalog_1.CatalogSource('the_key', 'the_org');
33
+ batch = {
34
+ addOrUpdate: [
35
+ new documentBuilder_1.DocumentBuilder('the_uri_1', 'the_title_1'),
36
+ new documentBuilder_1.DocumentBuilder('the_uri_2', 'the_title_2'),
37
+ ],
38
+ delete: [{ documentId: 'the_uri_3', deleteChildren: true }],
39
+ };
40
+ });
41
+ it('should call platform client on creation', () => {
42
+ source.create('the_name', platform_client_1.SourceVisibility.SHARED);
43
+ expect(mockCreateSource).toHaveBeenCalledWith({
44
+ name: 'the_name',
45
+ streamEnabled: true,
46
+ sourceType: 'CATALOG',
47
+ sourceVisibility: 'SHARED',
48
+ });
49
+ });
50
+ it('should upload a batch', async () => {
51
+ await source.batchUpdateDocuments('the_id', batch, {
52
+ createFields: false,
53
+ });
54
+ expect(mockedUploadBatch).toHaveBeenCalledWith(dummyClient, expect.any(uploadStrategy_1.FileContainerStrategy), batch, { createFields: false });
55
+ });
56
+ it('should upload documents from local file', async () => {
57
+ await source.batchUpdateDocumentsFromFiles('the_id', [(0, path_1.join)(pathToStub, 'mixdocuments')], { createFields: false });
58
+ expect(mockedUploadBatchFromFile).toHaveBeenCalledWith(dummyClient, expect.any(uploadStrategy_1.FileContainerStrategy), [(0, path_1.join)(pathToStub, 'mixdocuments')], { createFields: false });
59
+ });
60
+ it('should stream documents from local file', async () => {
61
+ await source.batchStreamDocumentsFromFiles('the_id', [(0, path_1.join)(pathToStub, 'mixdocuments')], { createFields: false });
62
+ expect(mockedUploadBatchFromFile).toHaveBeenCalledWith(dummyClient, expect.any(uploadStrategy_1.StreamChunkStrategy), [(0, path_1.join)(pathToStub, 'mixdocuments')], { createFields: false });
63
+ });
64
+ });
65
65
  //# sourceMappingURL=catalog.spec.js.map