@coveo/push-api-client 3.0.122 → 3.0.124
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/APICore.js +47 -47
- package/dist/definitions/APICore.d.ts +18 -18
- package/dist/definitions/document.d.ts +124 -124
- package/dist/definitions/documentBuilder.d.ts +168 -168
- package/dist/definitions/documentBuilder.spec.d.ts +1 -1
- package/dist/definitions/environment.d.ts +16 -16
- package/dist/definitions/errors/baseError.d.ts +4 -4
- package/dist/definitions/errors/fieldErrors.d.ts +18 -18
- package/dist/definitions/errors/index.d.ts +3 -3
- package/dist/definitions/errors/privilegeError.d.ts +6 -6
- package/dist/definitions/errors/validatorErrors.d.ts +20 -20
- package/dist/definitions/fieldAnalyser/fieldAnalyser.d.ts +36 -36
- package/dist/definitions/fieldAnalyser/fieldAnalyser.spec.d.ts +1 -1
- package/dist/definitions/fieldAnalyser/fieldStore.d.ts +5 -5
- package/dist/definitions/fieldAnalyser/fieldUtils.d.ts +6 -6
- package/dist/definitions/fieldAnalyser/fieldsUtils.spec.d.ts +1 -1
- package/dist/definitions/fieldAnalyser/inconsistencies.d.ts +5 -5
- package/dist/definitions/fieldAnalyser/inconsistencies.spec.d.ts +1 -1
- package/dist/definitions/fieldAnalyser/typeUtils.d.ts +3 -3
- package/dist/definitions/fieldAnalyser/typeUtils.spec.d.ts +1 -1
- package/dist/definitions/help/file.d.ts +3 -3
- package/dist/definitions/help/file.spec.d.ts +1 -1
- package/dist/definitions/help/fileConsumer.d.ts +31 -31
- package/dist/definitions/help/fileConsumer.spec.d.ts +1 -1
- package/dist/definitions/help/fileContainer.d.ts +8 -8
- package/dist/definitions/help/fileContainer.spec.d.ts +1 -1
- package/dist/definitions/help/function.d.ts +1 -1
- package/dist/definitions/help/generator.d.ts +11 -11
- package/dist/definitions/help/generator.spec.d.ts +1 -1
- package/dist/definitions/help/urlUtils.d.ts +27 -27
- package/dist/definitions/help/urlUtils.spec.d.ts +1 -1
- package/dist/definitions/index.d.ts +14 -14
- package/dist/definitions/interfaces.d.ts +70 -70
- package/dist/definitions/localtest.d.ts +1 -1
- package/dist/definitions/permissionSetBuilder.d.ts +34 -34
- package/dist/definitions/permissionSetBuilder.spec.d.ts +1 -1
- package/dist/definitions/securityIdentityBuilder.d.ts +105 -105
- package/dist/definitions/securityIdentityBuilder.spec.d.ts +1 -1
- package/dist/definitions/source/batchUploadDocumentsFromFile.d.ts +11 -11
- package/dist/definitions/source/batchUploadDocumentsFromFile.spec.d.ts +1 -1
- package/dist/definitions/source/catalog.d.ts +70 -70
- package/dist/definitions/source/catalog.spec.d.ts +1 -1
- package/dist/definitions/source/documentUploader.d.ts +11 -11
- package/dist/definitions/source/documentUploader.spec.d.ts +1 -1
- package/dist/definitions/source/push.d.ts +87 -87
- package/dist/definitions/source/push.spec.d.ts +1 -1
- package/dist/definitions/source/securityIdenty.d.ts +43 -43
- package/dist/definitions/uploadStrategy/fileContainerStrategy.d.ts +23 -23
- package/dist/definitions/uploadStrategy/fileContainerStrategy.spec.d.ts +1 -1
- package/dist/definitions/uploadStrategy/index.d.ts +3 -3
- package/dist/definitions/uploadStrategy/strategy.d.ts +23 -23
- package/dist/definitions/uploadStrategy/streamChunkStrategy.d.ts +28 -28
- package/dist/definitions/uploadStrategy/streamChunkStrategy.spec.d.ts +1 -1
- package/dist/definitions/validation/caseInsensitiveDocument.d.ts +13 -13
- package/dist/definitions/validation/knownKey.d.ts +10 -10
- package/dist/definitions/validation/parseFile.d.ts +4 -4
- package/dist/definitions/validation/parseFile.spec.d.ts +1 -1
- package/dist/definitions/validation/parsePermissions.d.ts +5 -5
- package/dist/definitions/validation/parsePermissions.spec.d.ts +1 -1
- package/dist/definitions/validation/preconditions/apiKeyPrivilege.d.ts +3 -3
- package/dist/definitions/validation/preconditions/apiKeyPrivilege.spec.d.ts +1 -1
- package/dist/definitions/validation/preconditions/platformPrivilege.d.ts +7 -7
- package/dist/definitions/validation/requiredKeyValidator.d.ts +17 -17
- package/dist/definitions/validation/transformers/transformer.d.ts +31 -31
- package/dist/definitions/validation/transformers/transformer.spec.d.ts +1 -1
- package/dist/document.js +2 -2
- package/dist/documentBuilder.js +292 -292
- package/dist/documentBuilder.spec.js +191 -191
- package/dist/environment.js +41 -41
- package/dist/errors/baseError.js +10 -10
- package/dist/errors/fieldErrors.js +42 -42
- package/dist/errors/index.js +19 -19
- package/dist/errors/privilegeError.js +12 -12
- package/dist/errors/validatorErrors.js +40 -40
- package/dist/fieldAnalyser/fieldAnalyser.js +95 -95
- package/dist/fieldAnalyser/fieldAnalyser.spec.js +230 -230
- package/dist/fieldAnalyser/fieldStore.js +21 -21
- package/dist/fieldAnalyser/fieldUtils.js +41 -41
- package/dist/fieldAnalyser/fieldsUtils.spec.js +116 -116
- package/dist/fieldAnalyser/inconsistencies.js +14 -14
- package/dist/fieldAnalyser/inconsistencies.spec.js +40 -40
- package/dist/fieldAnalyser/typeUtils.js +61 -61
- package/dist/fieldAnalyser/typeUtils.spec.js +142 -142
- package/dist/help/file.js +37 -37
- package/dist/help/file.spec.js +67 -67
- package/dist/help/fileConsumer.js +150 -150
- package/dist/help/fileConsumer.spec.js +153 -153
- package/dist/help/fileContainer.js +48 -48
- package/dist/help/fileContainer.spec.js +65 -65
- package/dist/help/function.js +5 -5
- package/dist/help/generator.js +32 -32
- package/dist/help/generator.spec.js +82 -82
- package/dist/help/urlUtils.js +42 -42
- package/dist/help/urlUtils.spec.js +41 -41
- package/dist/index.js +38 -38
- package/dist/interfaces.js +2 -2
- package/dist/localtest.js +55 -55
- package/dist/permissionSetBuilder.js +58 -58
- package/dist/permissionSetBuilder.spec.js +68 -68
- package/dist/securityIdentityBuilder.js +128 -128
- package/dist/securityIdentityBuilder.spec.js +50 -50
- package/dist/source/batchUploadDocumentsFromFile.js +46 -46
- package/dist/source/batchUploadDocumentsFromFile.spec.js +145 -145
- package/dist/source/catalog.js +111 -111
- package/dist/source/catalog.spec.js +64 -64
- package/dist/source/documentUploader.js +45 -45
- package/dist/source/documentUploader.spec.js +118 -118
- package/dist/source/push.js +140 -140
- package/dist/source/push.spec.js +152 -152
- package/dist/source/securityIdenty.js +57 -57
- package/dist/uploadStrategy/fileContainerStrategy.js +32 -32
- package/dist/uploadStrategy/fileContainerStrategy.spec.js +86 -86
- package/dist/uploadStrategy/index.js +19 -19
- package/dist/uploadStrategy/strategy.js +2 -2
- package/dist/uploadStrategy/streamChunkStrategy.js +52 -52
- package/dist/uploadStrategy/streamChunkStrategy.spec.js +77 -77
- package/dist/validation/caseInsensitiveDocument.js +31 -31
- package/dist/validation/knownKey.js +37 -37
- package/dist/validation/parseFile.js +120 -120
- package/dist/validation/parseFile.spec.js +96 -96
- package/dist/validation/parsePermissions.js +118 -118
- package/dist/validation/parsePermissions.spec.js +86 -86
- package/dist/validation/preconditions/apiKeyPrivilege.js +20 -20
- package/dist/validation/preconditions/apiKeyPrivilege.spec.js +66 -66
- package/dist/validation/preconditions/platformPrivilege.js +32 -32
- package/dist/validation/requiredKeyValidator.js +61 -61
- package/dist/validation/transformers/transformer.js +51 -51
- package/dist/validation/transformers/transformer.spec.js +21 -21
- package/package.json +4 -4
@@ -1,231 +1,231 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
jest.mock('@coveo/platform-client');
|
4
|
-
const platform_client_1 = require("@coveo/platform-client");
|
5
|
-
const __1 = require("..");
|
6
|
-
const fieldErrors_1 = require("../errors/fieldErrors");
|
7
|
-
const fieldAnalyser_1 = require("./fieldAnalyser");
|
8
|
-
const buildDocument = (metadata) => {
|
9
|
-
const doc = new __1.DocumentBuilder('https://my.document.uri', 'some title');
|
10
|
-
if (metadata) {
|
11
|
-
doc.withMetadata(metadata);
|
12
|
-
}
|
13
|
-
return doc;
|
14
|
-
};
|
15
|
-
const docWithNewFields = buildDocument({
|
16
|
-
some_integer: 100,
|
17
|
-
promo_price: 23.99,
|
18
|
-
description: 'Plumbus can generate and store vast amounts of heat, allowing it to be used for cooking, ironing or just heating the room.',
|
19
|
-
additional_info: 'Plumbus can secrete various agents from itself and has adaptive rubbing surfaces, making it useful for cleaning.',
|
20
|
-
price: 'six-and-a-half Brapples',
|
21
|
-
category: 'Various',
|
22
|
-
available: true,
|
23
|
-
});
|
24
|
-
const docWithExistingFields = buildDocument({
|
25
|
-
type: 'Teleportation Device',
|
26
|
-
category: 'Electronics',
|
27
|
-
})
|
28
|
-
.withAuthor('Rick')
|
29
|
-
.withFileExtension('.pewpew');
|
30
|
-
const dummyPlatformClient = () => {
|
31
|
-
return new platform_client_1.default({ accessToken: 'xxx' });
|
32
|
-
};
|
33
|
-
describe('FieldAnalyser', () => {
|
34
|
-
let analyser;
|
35
|
-
const mockedPlatformClient = jest.mocked(platform_client_1.default);
|
36
|
-
const mockedListFields = jest.fn();
|
37
|
-
const mockEvaluate = jest.fn();
|
38
|
-
const mockListFieldsWithValidPermanentId = () => {
|
39
|
-
mockedListFields
|
40
|
-
.mockResolvedValueOnce({
|
41
|
-
items: [
|
42
|
-
{ name: 'brand', type: platform_client_1.FieldTypes.STRING },
|
43
|
-
{ name: 'category', type: platform_client_1.FieldTypes.STRING },
|
44
|
-
{ name: 'permanentid', type: platform_client_1.FieldTypes.STRING },
|
45
|
-
],
|
46
|
-
totalPages: 2,
|
47
|
-
})
|
48
|
-
.mockResolvedValueOnce({
|
49
|
-
items: [{ name: 'type' }],
|
50
|
-
totalPages: 2,
|
51
|
-
});
|
52
|
-
};
|
53
|
-
const mockListFieldsWithInvalidPermanentId = () => {
|
54
|
-
mockedListFields.mockResolvedValueOnce({
|
55
|
-
items: [{ name: 'permanentid', type: platform_client_1.FieldTypes.DATE }],
|
56
|
-
totalPages: 1,
|
57
|
-
});
|
58
|
-
};
|
59
|
-
const mockListFieldsWithNoPermanentId = () => {
|
60
|
-
mockedListFields.mockResolvedValueOnce({
|
61
|
-
items: [],
|
62
|
-
totalPages: 1,
|
63
|
-
});
|
64
|
-
};
|
65
|
-
const doMockPlatformClient = () => {
|
66
|
-
mockedPlatformClient.mockImplementation(() => ({
|
67
|
-
privilegeEvaluator: { evaluate: mockEvaluate },
|
68
|
-
field: { list: mockedListFields },
|
69
|
-
}));
|
70
|
-
};
|
71
|
-
beforeAll(() => {
|
72
|
-
doMockPlatformClient();
|
73
|
-
});
|
74
|
-
beforeEach(() => {
|
75
|
-
mockEvaluate.mockResolvedValue({ approved: true });
|
76
|
-
mockedListFields.mockReset();
|
77
|
-
analyser = new fieldAnalyser_1.FieldAnalyser(dummyPlatformClient());
|
78
|
-
});
|
79
|
-
describe('when client is not allowed to create fields', () => {
|
80
|
-
beforeEach(async () => {
|
81
|
-
mockEvaluate.mockReset();
|
82
|
-
mockListFieldsWithValidPermanentId();
|
83
|
-
});
|
84
|
-
it('should throw an error', async () => {
|
85
|
-
mockEvaluate.mockResolvedValue({ approved: false });
|
86
|
-
await expect(analyser.add([docWithExistingFields])).rejects.toThrow();
|
87
|
-
});
|
88
|
-
});
|
89
|
-
describe('when fields from the batch already exist in the org', () => {
|
90
|
-
let report;
|
91
|
-
beforeEach(async () => {
|
92
|
-
mockListFieldsWithValidPermanentId();
|
93
|
-
report = (await analyser.add([docWithExistingFields])).report();
|
94
|
-
});
|
95
|
-
afterEach(() => { });
|
96
|
-
it('should not return fields to create', async () => {
|
97
|
-
expect(report.fields).toStrictEqual([]);
|
98
|
-
});
|
99
|
-
it('should not detect inconsistencies', async () => {
|
100
|
-
expect(report.inconsistencies.size).toStrictEqual(0);
|
101
|
-
});
|
102
|
-
});
|
103
|
-
describe('when batch contain new fields', () => {
|
104
|
-
beforeEach(() => {
|
105
|
-
mockListFieldsWithValidPermanentId();
|
106
|
-
});
|
107
|
-
it('should return fields to create', async () => {
|
108
|
-
const docBuilders = [docWithNewFields, docWithExistingFields];
|
109
|
-
const { fields } = (await analyser.add(docBuilders)).report();
|
110
|
-
expect(fields).toStrictEqual([
|
111
|
-
{
|
112
|
-
name: 'some_integer',
|
113
|
-
type: 'LONG',
|
114
|
-
},
|
115
|
-
{
|
116
|
-
name: 'promo_price',
|
117
|
-
type: 'DOUBLE',
|
118
|
-
},
|
119
|
-
{
|
120
|
-
name: 'description',
|
121
|
-
type: 'STRING',
|
122
|
-
},
|
123
|
-
{
|
124
|
-
name: 'additional_info',
|
125
|
-
type: 'STRING',
|
126
|
-
},
|
127
|
-
{
|
128
|
-
name: 'price',
|
129
|
-
type: 'STRING',
|
130
|
-
},
|
131
|
-
{
|
132
|
-
name: 'available',
|
133
|
-
type: 'STRING',
|
134
|
-
},
|
135
|
-
]);
|
136
|
-
});
|
137
|
-
it('should always take the most englobing numeric type regardless of the transition direction', async () => {
|
138
|
-
const docBuilders = [
|
139
|
-
buildDocument({
|
140
|
-
from_long_to_double: 10,
|
141
|
-
from_double_to_long: 20.1,
|
142
|
-
}),
|
143
|
-
buildDocument({
|
144
|
-
from_long_to_double: 10.1,
|
145
|
-
from_double_to_long: 20,
|
146
|
-
}),
|
147
|
-
];
|
148
|
-
const { fields } = (await analyser.add(docBuilders)).report();
|
149
|
-
expect(fields).toStrictEqual([
|
150
|
-
{
|
151
|
-
name: 'from_long_to_double',
|
152
|
-
type: 'DOUBLE',
|
153
|
-
},
|
154
|
-
{
|
155
|
-
name: 'from_double_to_long',
|
156
|
-
type: 'DOUBLE',
|
157
|
-
},
|
158
|
-
]);
|
159
|
-
});
|
160
|
-
});
|
161
|
-
describe('when the batch contains inconsistent metadata', () => {
|
162
|
-
let report;
|
163
|
-
const docBuilders = [
|
164
|
-
docWithNewFields,
|
165
|
-
docWithExistingFields,
|
166
|
-
buildDocument({ price: 6.5, available: 0 }),
|
167
|
-
buildDocument({ available: 1 }),
|
168
|
-
];
|
169
|
-
beforeEach(async () => {
|
170
|
-
mockListFieldsWithValidPermanentId();
|
171
|
-
report = (await analyser.add(docBuilders)).report();
|
172
|
-
});
|
173
|
-
it('should detect 2 inconsistencies', () => {
|
174
|
-
expect(report.inconsistencies.size).toBe(2);
|
175
|
-
});
|
176
|
-
it('should detect type inconsistencies', () => {
|
177
|
-
const inconsistenciesSet = report.inconsistencies;
|
178
|
-
expect(inconsistenciesSet.get('price')).toStrictEqual(new Set(['DOUBLE', 'STRING']));
|
179
|
-
expect(inconsistenciesSet.get('available')).toStrictEqual(new Set(['LONG', 'STRING']));
|
180
|
-
});
|
181
|
-
it('should still provide fields to create', () => {
|
182
|
-
expect(report.fields).toStrictEqual([
|
183
|
-
{
|
184
|
-
name: 'some_integer',
|
185
|
-
type: 'LONG',
|
186
|
-
},
|
187
|
-
{
|
188
|
-
name: 'promo_price',
|
189
|
-
type: 'DOUBLE',
|
190
|
-
},
|
191
|
-
{
|
192
|
-
name: 'description',
|
193
|
-
type: 'STRING',
|
194
|
-
},
|
195
|
-
{
|
196
|
-
name: 'additional_info',
|
197
|
-
type: 'STRING',
|
198
|
-
},
|
199
|
-
]);
|
200
|
-
});
|
201
|
-
it('should not return fields with inconsistencies', () => {
|
202
|
-
report.fields.forEach((field) => {
|
203
|
-
expect(field.name).not.toEqual('available');
|
204
|
-
expect(field.name).not.toEqual('price');
|
205
|
-
});
|
206
|
-
});
|
207
|
-
});
|
208
|
-
describe('when permanentId is not correctly configured', () => {
|
209
|
-
beforeEach(() => {
|
210
|
-
mockListFieldsWithInvalidPermanentId();
|
211
|
-
});
|
212
|
-
it('should throw an error', async () => {
|
213
|
-
await analyser.add([docWithExistingFields]);
|
214
|
-
expect(() => analyser.report()).toThrow(fieldErrors_1.InvalidPermanentId);
|
215
|
-
});
|
216
|
-
});
|
217
|
-
describe('when permanentId is missing from the organization', () => {
|
218
|
-
beforeEach(() => {
|
219
|
-
mockListFieldsWithNoPermanentId();
|
220
|
-
});
|
221
|
-
it('should include permanentid field in the analysis report', async () => {
|
222
|
-
await analyser.add([docWithExistingFields]);
|
223
|
-
const report = analyser.report();
|
224
|
-
expect(report.fields).toContainEqual({
|
225
|
-
name: 'permanentid',
|
226
|
-
type: 'STRING',
|
227
|
-
});
|
228
|
-
});
|
229
|
-
});
|
230
|
-
});
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
jest.mock('@coveo/platform-client');
|
4
|
+
const platform_client_1 = require("@coveo/platform-client");
|
5
|
+
const __1 = require("..");
|
6
|
+
const fieldErrors_1 = require("../errors/fieldErrors");
|
7
|
+
const fieldAnalyser_1 = require("./fieldAnalyser");
|
8
|
+
const buildDocument = (metadata) => {
|
9
|
+
const doc = new __1.DocumentBuilder('https://my.document.uri', 'some title');
|
10
|
+
if (metadata) {
|
11
|
+
doc.withMetadata(metadata);
|
12
|
+
}
|
13
|
+
return doc;
|
14
|
+
};
|
15
|
+
const docWithNewFields = buildDocument({
|
16
|
+
some_integer: 100,
|
17
|
+
promo_price: 23.99,
|
18
|
+
description: 'Plumbus can generate and store vast amounts of heat, allowing it to be used for cooking, ironing or just heating the room.',
|
19
|
+
additional_info: 'Plumbus can secrete various agents from itself and has adaptive rubbing surfaces, making it useful for cleaning.',
|
20
|
+
price: 'six-and-a-half Brapples',
|
21
|
+
category: 'Various',
|
22
|
+
available: true,
|
23
|
+
});
|
24
|
+
const docWithExistingFields = buildDocument({
|
25
|
+
type: 'Teleportation Device',
|
26
|
+
category: 'Electronics',
|
27
|
+
})
|
28
|
+
.withAuthor('Rick')
|
29
|
+
.withFileExtension('.pewpew');
|
30
|
+
const dummyPlatformClient = () => {
|
31
|
+
return new platform_client_1.default({ accessToken: 'xxx' });
|
32
|
+
};
|
33
|
+
describe('FieldAnalyser', () => {
|
34
|
+
let analyser;
|
35
|
+
const mockedPlatformClient = jest.mocked(platform_client_1.default);
|
36
|
+
const mockedListFields = jest.fn();
|
37
|
+
const mockEvaluate = jest.fn();
|
38
|
+
const mockListFieldsWithValidPermanentId = () => {
|
39
|
+
mockedListFields
|
40
|
+
.mockResolvedValueOnce({
|
41
|
+
items: [
|
42
|
+
{ name: 'brand', type: platform_client_1.FieldTypes.STRING },
|
43
|
+
{ name: 'category', type: platform_client_1.FieldTypes.STRING },
|
44
|
+
{ name: 'permanentid', type: platform_client_1.FieldTypes.STRING },
|
45
|
+
],
|
46
|
+
totalPages: 2,
|
47
|
+
})
|
48
|
+
.mockResolvedValueOnce({
|
49
|
+
items: [{ name: 'type' }],
|
50
|
+
totalPages: 2,
|
51
|
+
});
|
52
|
+
};
|
53
|
+
const mockListFieldsWithInvalidPermanentId = () => {
|
54
|
+
mockedListFields.mockResolvedValueOnce({
|
55
|
+
items: [{ name: 'permanentid', type: platform_client_1.FieldTypes.DATE }],
|
56
|
+
totalPages: 1,
|
57
|
+
});
|
58
|
+
};
|
59
|
+
const mockListFieldsWithNoPermanentId = () => {
|
60
|
+
mockedListFields.mockResolvedValueOnce({
|
61
|
+
items: [],
|
62
|
+
totalPages: 1,
|
63
|
+
});
|
64
|
+
};
|
65
|
+
const doMockPlatformClient = () => {
|
66
|
+
mockedPlatformClient.mockImplementation(() => ({
|
67
|
+
privilegeEvaluator: { evaluate: mockEvaluate },
|
68
|
+
field: { list: mockedListFields },
|
69
|
+
}));
|
70
|
+
};
|
71
|
+
beforeAll(() => {
|
72
|
+
doMockPlatformClient();
|
73
|
+
});
|
74
|
+
beforeEach(() => {
|
75
|
+
mockEvaluate.mockResolvedValue({ approved: true });
|
76
|
+
mockedListFields.mockReset();
|
77
|
+
analyser = new fieldAnalyser_1.FieldAnalyser(dummyPlatformClient());
|
78
|
+
});
|
79
|
+
describe('when client is not allowed to create fields', () => {
|
80
|
+
beforeEach(async () => {
|
81
|
+
mockEvaluate.mockReset();
|
82
|
+
mockListFieldsWithValidPermanentId();
|
83
|
+
});
|
84
|
+
it('should throw an error', async () => {
|
85
|
+
mockEvaluate.mockResolvedValue({ approved: false });
|
86
|
+
await expect(analyser.add([docWithExistingFields])).rejects.toThrow();
|
87
|
+
});
|
88
|
+
});
|
89
|
+
describe('when fields from the batch already exist in the org', () => {
|
90
|
+
let report;
|
91
|
+
beforeEach(async () => {
|
92
|
+
mockListFieldsWithValidPermanentId();
|
93
|
+
report = (await analyser.add([docWithExistingFields])).report();
|
94
|
+
});
|
95
|
+
afterEach(() => { });
|
96
|
+
it('should not return fields to create', async () => {
|
97
|
+
expect(report.fields).toStrictEqual([]);
|
98
|
+
});
|
99
|
+
it('should not detect inconsistencies', async () => {
|
100
|
+
expect(report.inconsistencies.size).toStrictEqual(0);
|
101
|
+
});
|
102
|
+
});
|
103
|
+
describe('when batch contain new fields', () => {
|
104
|
+
beforeEach(() => {
|
105
|
+
mockListFieldsWithValidPermanentId();
|
106
|
+
});
|
107
|
+
it('should return fields to create', async () => {
|
108
|
+
const docBuilders = [docWithNewFields, docWithExistingFields];
|
109
|
+
const { fields } = (await analyser.add(docBuilders)).report();
|
110
|
+
expect(fields).toStrictEqual([
|
111
|
+
{
|
112
|
+
name: 'some_integer',
|
113
|
+
type: 'LONG',
|
114
|
+
},
|
115
|
+
{
|
116
|
+
name: 'promo_price',
|
117
|
+
type: 'DOUBLE',
|
118
|
+
},
|
119
|
+
{
|
120
|
+
name: 'description',
|
121
|
+
type: 'STRING',
|
122
|
+
},
|
123
|
+
{
|
124
|
+
name: 'additional_info',
|
125
|
+
type: 'STRING',
|
126
|
+
},
|
127
|
+
{
|
128
|
+
name: 'price',
|
129
|
+
type: 'STRING',
|
130
|
+
},
|
131
|
+
{
|
132
|
+
name: 'available',
|
133
|
+
type: 'STRING',
|
134
|
+
},
|
135
|
+
]);
|
136
|
+
});
|
137
|
+
it('should always take the most englobing numeric type regardless of the transition direction', async () => {
|
138
|
+
const docBuilders = [
|
139
|
+
buildDocument({
|
140
|
+
from_long_to_double: 10,
|
141
|
+
from_double_to_long: 20.1,
|
142
|
+
}),
|
143
|
+
buildDocument({
|
144
|
+
from_long_to_double: 10.1,
|
145
|
+
from_double_to_long: 20,
|
146
|
+
}),
|
147
|
+
];
|
148
|
+
const { fields } = (await analyser.add(docBuilders)).report();
|
149
|
+
expect(fields).toStrictEqual([
|
150
|
+
{
|
151
|
+
name: 'from_long_to_double',
|
152
|
+
type: 'DOUBLE',
|
153
|
+
},
|
154
|
+
{
|
155
|
+
name: 'from_double_to_long',
|
156
|
+
type: 'DOUBLE',
|
157
|
+
},
|
158
|
+
]);
|
159
|
+
});
|
160
|
+
});
|
161
|
+
describe('when the batch contains inconsistent metadata', () => {
|
162
|
+
let report;
|
163
|
+
const docBuilders = [
|
164
|
+
docWithNewFields,
|
165
|
+
docWithExistingFields,
|
166
|
+
buildDocument({ price: 6.5, available: 0 }),
|
167
|
+
buildDocument({ available: 1 }),
|
168
|
+
];
|
169
|
+
beforeEach(async () => {
|
170
|
+
mockListFieldsWithValidPermanentId();
|
171
|
+
report = (await analyser.add(docBuilders)).report();
|
172
|
+
});
|
173
|
+
it('should detect 2 inconsistencies', () => {
|
174
|
+
expect(report.inconsistencies.size).toBe(2);
|
175
|
+
});
|
176
|
+
it('should detect type inconsistencies', () => {
|
177
|
+
const inconsistenciesSet = report.inconsistencies;
|
178
|
+
expect(inconsistenciesSet.get('price')).toStrictEqual(new Set(['DOUBLE', 'STRING']));
|
179
|
+
expect(inconsistenciesSet.get('available')).toStrictEqual(new Set(['LONG', 'STRING']));
|
180
|
+
});
|
181
|
+
it('should still provide fields to create', () => {
|
182
|
+
expect(report.fields).toStrictEqual([
|
183
|
+
{
|
184
|
+
name: 'some_integer',
|
185
|
+
type: 'LONG',
|
186
|
+
},
|
187
|
+
{
|
188
|
+
name: 'promo_price',
|
189
|
+
type: 'DOUBLE',
|
190
|
+
},
|
191
|
+
{
|
192
|
+
name: 'description',
|
193
|
+
type: 'STRING',
|
194
|
+
},
|
195
|
+
{
|
196
|
+
name: 'additional_info',
|
197
|
+
type: 'STRING',
|
198
|
+
},
|
199
|
+
]);
|
200
|
+
});
|
201
|
+
it('should not return fields with inconsistencies', () => {
|
202
|
+
report.fields.forEach((field) => {
|
203
|
+
expect(field.name).not.toEqual('available');
|
204
|
+
expect(field.name).not.toEqual('price');
|
205
|
+
});
|
206
|
+
});
|
207
|
+
});
|
208
|
+
describe('when permanentId is not correctly configured', () => {
|
209
|
+
beforeEach(() => {
|
210
|
+
mockListFieldsWithInvalidPermanentId();
|
211
|
+
});
|
212
|
+
it('should throw an error', async () => {
|
213
|
+
await analyser.add([docWithExistingFields]);
|
214
|
+
expect(() => analyser.report()).toThrow(fieldErrors_1.InvalidPermanentId);
|
215
|
+
});
|
216
|
+
});
|
217
|
+
describe('when permanentId is missing from the organization', () => {
|
218
|
+
beforeEach(() => {
|
219
|
+
mockListFieldsWithNoPermanentId();
|
220
|
+
});
|
221
|
+
it('should include permanentid field in the analysis report', async () => {
|
222
|
+
await analyser.add([docWithExistingFields]);
|
223
|
+
const report = analyser.report();
|
224
|
+
expect(report.fields).toContainEqual({
|
225
|
+
name: 'permanentid',
|
226
|
+
type: 'STRING',
|
227
|
+
});
|
228
|
+
});
|
229
|
+
});
|
230
|
+
});
|
231
231
|
//# sourceMappingURL=fieldAnalyser.spec.js.map
|
@@ -1,22 +1,22 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.FieldStore = void 0;
|
4
|
-
class FieldStore extends Map {
|
5
|
-
concat(fieldBuilder) {
|
6
|
-
fieldBuilder.forEach((type, name) => {
|
7
|
-
this.set(name, type);
|
8
|
-
});
|
9
|
-
}
|
10
|
-
marshal() {
|
11
|
-
const fieldModels = [];
|
12
|
-
this.forEach((fieldType, fieldName) => {
|
13
|
-
fieldModels.push({
|
14
|
-
name: fieldName,
|
15
|
-
type: fieldType,
|
16
|
-
});
|
17
|
-
});
|
18
|
-
return fieldModels;
|
19
|
-
}
|
20
|
-
}
|
21
|
-
exports.FieldStore = FieldStore;
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.FieldStore = void 0;
|
4
|
+
class FieldStore extends Map {
|
5
|
+
concat(fieldBuilder) {
|
6
|
+
fieldBuilder.forEach((type, name) => {
|
7
|
+
this.set(name, type);
|
8
|
+
});
|
9
|
+
}
|
10
|
+
marshal() {
|
11
|
+
const fieldModels = [];
|
12
|
+
this.forEach((fieldType, fieldName) => {
|
13
|
+
fieldModels.push({
|
14
|
+
name: fieldName,
|
15
|
+
type: fieldType,
|
16
|
+
});
|
17
|
+
});
|
18
|
+
return fieldModels;
|
19
|
+
}
|
20
|
+
}
|
21
|
+
exports.FieldStore = FieldStore;
|
22
22
|
//# sourceMappingURL=fieldStore.js.map
|
@@ -1,42 +1,42 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.isFieldNameValid = exports.createFieldsFromReport = exports.createFields = exports.listAllFieldsFromOrg = void 0;
|
4
|
-
const fieldErrors_1 = require("../errors/fieldErrors");
|
5
|
-
const apiKeyPrivilege_1 = require("../validation/preconditions/apiKeyPrivilege");
|
6
|
-
const platformPrivilege_1 = require("../validation/preconditions/platformPrivilege");
|
7
|
-
const allowedCharRegExp = new RegExp('^[a-z]+[a-z0-9_]*$');
|
8
|
-
const listAllFieldsFromOrg = async (client, page = 0, fields = []) => {
|
9
|
-
await (0, apiKeyPrivilege_1.ensureNecessaryCoveoPrivileges)(client, platformPrivilege_1.readFieldsPrivilege);
|
10
|
-
const list = await client.field.list({
|
11
|
-
page,
|
12
|
-
perPage: 1000,
|
13
|
-
});
|
14
|
-
fields.push(...list.items);
|
15
|
-
if (page < list.totalPages - 1) {
|
16
|
-
return (0, exports.listAllFieldsFromOrg)(client, page + 1, fields);
|
17
|
-
}
|
18
|
-
return fields;
|
19
|
-
};
|
20
|
-
exports.listAllFieldsFromOrg = listAllFieldsFromOrg;
|
21
|
-
const createFields = async (client, fields, fieldBatch = 500) => {
|
22
|
-
await (0, apiKeyPrivilege_1.ensureNecessaryCoveoPrivileges)(client, platformPrivilege_1.writeFieldsPrivilege);
|
23
|
-
for (let i = 0; i < fields.length; i += fieldBatch) {
|
24
|
-
const batch = fields.slice(i, fieldBatch + i);
|
25
|
-
await client.field.createFields(batch);
|
26
|
-
}
|
27
|
-
};
|
28
|
-
exports.createFields = createFields;
|
29
|
-
const createFieldsFromReport = async (client, report) => {
|
30
|
-
{
|
31
|
-
if (report.inconsistencies.size > 0) {
|
32
|
-
throw new fieldErrors_1.FieldTypeInconsistencyError(report.inconsistencies);
|
33
|
-
}
|
34
|
-
await (0, exports.createFields)(client, report.fields);
|
35
|
-
}
|
36
|
-
};
|
37
|
-
exports.createFieldsFromReport = createFieldsFromReport;
|
38
|
-
const isFieldNameValid = (fieldName) => {
|
39
|
-
return allowedCharRegExp.test(fieldName.toLowerCase());
|
40
|
-
};
|
41
|
-
exports.isFieldNameValid = isFieldNameValid;
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.isFieldNameValid = exports.createFieldsFromReport = exports.createFields = exports.listAllFieldsFromOrg = void 0;
|
4
|
+
const fieldErrors_1 = require("../errors/fieldErrors");
|
5
|
+
const apiKeyPrivilege_1 = require("../validation/preconditions/apiKeyPrivilege");
|
6
|
+
const platformPrivilege_1 = require("../validation/preconditions/platformPrivilege");
|
7
|
+
const allowedCharRegExp = new RegExp('^[a-z]+[a-z0-9_]*$');
|
8
|
+
const listAllFieldsFromOrg = async (client, page = 0, fields = []) => {
|
9
|
+
await (0, apiKeyPrivilege_1.ensureNecessaryCoveoPrivileges)(client, platformPrivilege_1.readFieldsPrivilege);
|
10
|
+
const list = await client.field.list({
|
11
|
+
page,
|
12
|
+
perPage: 1000,
|
13
|
+
});
|
14
|
+
fields.push(...list.items);
|
15
|
+
if (page < list.totalPages - 1) {
|
16
|
+
return (0, exports.listAllFieldsFromOrg)(client, page + 1, fields);
|
17
|
+
}
|
18
|
+
return fields;
|
19
|
+
};
|
20
|
+
exports.listAllFieldsFromOrg = listAllFieldsFromOrg;
|
21
|
+
const createFields = async (client, fields, fieldBatch = 500) => {
|
22
|
+
await (0, apiKeyPrivilege_1.ensureNecessaryCoveoPrivileges)(client, platformPrivilege_1.writeFieldsPrivilege);
|
23
|
+
for (let i = 0; i < fields.length; i += fieldBatch) {
|
24
|
+
const batch = fields.slice(i, fieldBatch + i);
|
25
|
+
await client.field.createFields(batch);
|
26
|
+
}
|
27
|
+
};
|
28
|
+
exports.createFields = createFields;
|
29
|
+
const createFieldsFromReport = async (client, report) => {
|
30
|
+
{
|
31
|
+
if (report.inconsistencies.size > 0) {
|
32
|
+
throw new fieldErrors_1.FieldTypeInconsistencyError(report.inconsistencies);
|
33
|
+
}
|
34
|
+
await (0, exports.createFields)(client, report.fields);
|
35
|
+
}
|
36
|
+
};
|
37
|
+
exports.createFieldsFromReport = createFieldsFromReport;
|
38
|
+
const isFieldNameValid = (fieldName) => {
|
39
|
+
return allowedCharRegExp.test(fieldName.toLowerCase());
|
40
|
+
};
|
41
|
+
exports.isFieldNameValid = isFieldNameValid;
|
42
42
|
//# sourceMappingURL=fieldUtils.js.map
|