@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,192 +1,192 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const documentBuilder_1 = require("./documentBuilder");
4
- const permissionSetBuilder_1 = require("./permissionSetBuilder");
5
- const securityIdentityBuilder_1 = require("./securityIdentityBuilder");
6
- const transformer_1 = require("./validation/transformers/transformer");
7
- describe('DocumentBuilder', () => {
8
- let docBuilder;
9
- beforeEach(() => {
10
- docBuilder = new documentBuilder_1.DocumentBuilder('uri', 'title');
11
- });
12
- it('should marshal title', () => {
13
- expect(docBuilder.marshal().title).toBe('title');
14
- });
15
- it('should uri marshal to documentID (path->uri)', () => {
16
- expect(docBuilder.marshal().documentId).toMatch(/file:\/\/.*\/uri/);
17
- });
18
- it('should uri marshal to documentID (uri->uri)', () => {
19
- expect(new documentBuilder_1.DocumentBuilder('foo://bar.biz', 'aaa').marshal().documentId).toBe('foo://bar.biz');
20
- });
21
- it('should marshal data', () => {
22
- expect(docBuilder.withData('foo').marshal().data).toBe('foo');
23
- });
24
- it('should marshal date', () => {
25
- const d = new Date();
26
- expect(docBuilder.withDate(d).marshal().date).toMatch(d.toISOString());
27
- });
28
- it('should marshal author', () => {
29
- expect(docBuilder.withAuthor('bob').marshal().author).toBe('bob');
30
- });
31
- it('should marshal clickableUri', () => {
32
- expect(docBuilder.withClickableUri('click').marshal().clickableUri).toBe('click');
33
- });
34
- it('should marshal fileExtension', () => {
35
- expect(docBuilder.withFileExtension('.html').marshal().fileExtension).toBe('.html');
36
- });
37
- it('should marshal metadata', () => {
38
- expect(docBuilder
39
- .withMetadata({
40
- foo: 'bar',
41
- buzz: ['bazz', 'bozz'],
42
- baz: { '': 'defaultValue', key1: 'value1' },
43
- })
44
- .marshal()).toMatchObject({
45
- foo: 'bar',
46
- buzz: ['bazz', 'bozz'],
47
- baz: { '': 'defaultValue', key1: 'value1' },
48
- });
49
- });
50
- it('should throw error for invalid single metadata value', () => {
51
- expect(() => {
52
- docBuilder.withMetadataValue('f-o=o', 'bar').marshal();
53
- }).toThrowError('f-o=o');
54
- });
55
- it('should throw error for invalid metadata values', () => {
56
- expect(() => {
57
- docBuilder
58
- .withMetadata({ 'f-o=o': 'bar', '<buzz>': ['bazz', 'bozz'] })
59
- .marshal();
60
- }).toThrowErrorMatchingSnapshot();
61
- });
62
- it('should throw error for invalid metadata values even after transformation', () => {
63
- const poorTransformer = (text) => text.replace(/[\W_]+/g, '*');
64
- expect(() => {
65
- docBuilder
66
- .withMetadata({ 'f-o=o': 'bar', '<buzz>': ['bazz', 'bozz'] }, poorTransformer)
67
- .marshal();
68
- }).toThrowErrorMatchingSnapshot();
69
- });
70
- describe.each([
71
- {
72
- title: 'default',
73
- transformer: transformer_1.BuiltInTransformers.toLowerCase,
74
- expectedKey: 'foo',
75
- },
76
- {
77
- title: 'underscore',
78
- transformer: transformer_1.BuiltInTransformers.toSnakeCase,
79
- expectedKey: 'f_o_o',
80
- },
81
- ])('when using the $title transformer', ({ transformer, expectedKey }) => {
82
- it(`should format to ${expectedKey}`, () => {
83
- expect(new documentBuilder_1.DocumentBuilder('uri', 'title')
84
- .withMetadataValue('f-o=o', 'bar', transformer)
85
- .marshal()).toMatchObject({
86
- [expectedKey]: 'bar',
87
- });
88
- });
89
- });
90
- it('should marshal single metadata value', () => {
91
- expect(docBuilder.withMetadataValue('foo', 'bar').marshal()).toMatchObject({
92
- foo: 'bar',
93
- });
94
- });
95
- it('should not marshal metadata key', () => {
96
- expect(docBuilder
97
- .withMetadata({ foo: 'bar', buzz: ['bazz', 'bozz'] })
98
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
99
- .marshal().metadata).toBeUndefined();
100
- });
101
- it('should marshal modifiedDate', () => {
102
- const d = new Date();
103
- expect(docBuilder.withModifiedDate(d).marshal().modifiedDate).toMatch(d.toISOString());
104
- });
105
- it('should marshal parentId', () => {
106
- expect(docBuilder.withParentID('id').marshal().parentId).toBe('id');
107
- });
108
- it('should marshal permanentId', () => {
109
- expect(docBuilder.withPermanentId('id').marshal().permanentid).toBe('id');
110
- });
111
- it('should generate permanentid', () => {
112
- docBuilder = new documentBuilder_1.DocumentBuilder('https://foo.com', 'bar');
113
- expect(docBuilder.marshal().permanentid).toBe('aa2e0510b66edff7f05e2b30d4f1b3a4b5481c06b69f41751c54675c5afb');
114
- });
115
- it('throws when adding a reserved key name metadata', () => {
116
- const theseShouldThrow = [
117
- 'compressedBinaryData',
118
- 'compressedBinaryDataFileId',
119
- 'parentId',
120
- 'fileExtension',
121
- 'data',
122
- 'permissions',
123
- 'documentId',
124
- 'orderingId',
125
- ];
126
- for (const shouldThrow of theseShouldThrow) {
127
- expect(() => docBuilder.withMetadataValue(shouldThrow, 'foo')).toThrow();
128
- }
129
- });
130
- it('should validate file extension', () => {
131
- expect(() => docBuilder.withFileExtension('nope')).toThrow();
132
- });
133
- it('should build every permission set added to the document', () => {
134
- const userIdentity = new securityIdentityBuilder_1.UserSecurityIdentityBuilder([
135
- 'bob@foo.com',
136
- 'sue@foo.com',
137
- ]);
138
- const groupIdentity = new securityIdentityBuilder_1.GroupSecurityIdentityBuilder('my_group');
139
- const bobSpy = jest.spyOn(userIdentity, 'build');
140
- const groupSpy = jest.spyOn(userIdentity, 'build');
141
- const permissionSet = new permissionSetBuilder_1.PermissionSetBuilder(false)
142
- .withDeniedPermissions(userIdentity)
143
- .withDeniedPermissions(groupIdentity);
144
- docBuilder.withPermissionSet(permissionSet);
145
- expect(bobSpy).toHaveBeenCalledTimes(1);
146
- expect(groupSpy).toHaveBeenCalledTimes(1);
147
- });
148
- it('should not marshal an empty array when permissions are not defined', () => {
149
- expect(docBuilder.marshal()).not.toContain('permissions');
150
- });
151
- it('should marshal permission set', () => {
152
- const userIdentity = new securityIdentityBuilder_1.UserSecurityIdentityBuilder([
153
- 'bob@foo.com',
154
- 'sue@foo.com',
155
- ]);
156
- const permissionSet = new permissionSetBuilder_1.PermissionSetBuilder(false)
157
- .withDeniedPermissions(userIdentity)
158
- .withDeniedPermissions(new securityIdentityBuilder_1.GroupSecurityIdentityBuilder('my_group'))
159
- .withDeniedPermissions(new securityIdentityBuilder_1.VirtualGroupSecurityIdentityBuilder('virtual_group'));
160
- const { permissions } = docBuilder.withPermissionSet(permissionSet).marshal();
161
- expect(permissions).toHaveLength(1);
162
- });
163
- describe('when combining multiple permission sets', () => {
164
- // Example taken from https://docs.coveo.com/en/107
165
- const openedPermissionSet = new permissionSetBuilder_1.PermissionSetBuilder(true).withDeniedPermissions(new securityIdentityBuilder_1.UserSecurityIdentityBuilder('asmith@example.com'));
166
- const restrictedPermissionSet = new permissionSetBuilder_1.PermissionSetBuilder(false)
167
- .withAllowedPermissions(new securityIdentityBuilder_1.GroupSecurityIdentityBuilder('SampleTeam1'))
168
- .withAllowedPermissions(new securityIdentityBuilder_1.UserSecurityIdentityBuilder('emitchell@example.com'));
169
- const misteryPermissionSet = new permissionSetBuilder_1.PermissionSetBuilder(false)
170
- .withDeniedPermissions(new securityIdentityBuilder_1.VirtualGroupSecurityIdentityBuilder('SampleGroup'))
171
- .withAllowedPermissions(new securityIdentityBuilder_1.UserSecurityIdentityBuilder('MysteryUserX'));
172
- it('should marshal multiple permission sets', () => {
173
- const { permissions } = docBuilder
174
- .withPermissionSet(openedPermissionSet)
175
- .withPermissionSet(restrictedPermissionSet)
176
- .withPermissionSet(misteryPermissionSet)
177
- .marshal();
178
- expect(permissions).toHaveLength(3);
179
- });
180
- it('should marshal permission level', () => {
181
- const { permissions } = docBuilder
182
- .withPermissionLevel('level1', [
183
- openedPermissionSet,
184
- restrictedPermissionSet,
185
- ])
186
- .withPermissionLevel('level2', [misteryPermissionSet])
187
- .marshal();
188
- expect(permissions).toMatchSnapshot();
189
- });
190
- });
191
- });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const documentBuilder_1 = require("./documentBuilder");
4
+ const permissionSetBuilder_1 = require("./permissionSetBuilder");
5
+ const securityIdentityBuilder_1 = require("./securityIdentityBuilder");
6
+ const transformer_1 = require("./validation/transformers/transformer");
7
+ describe('DocumentBuilder', () => {
8
+ let docBuilder;
9
+ beforeEach(() => {
10
+ docBuilder = new documentBuilder_1.DocumentBuilder('uri', 'title');
11
+ });
12
+ it('should marshal title', () => {
13
+ expect(docBuilder.marshal().title).toBe('title');
14
+ });
15
+ it('should uri marshal to documentID (path->uri)', () => {
16
+ expect(docBuilder.marshal().documentId).toMatch(/file:\/\/.*\/uri/);
17
+ });
18
+ it('should uri marshal to documentID (uri->uri)', () => {
19
+ expect(new documentBuilder_1.DocumentBuilder('foo://bar.biz', 'aaa').marshal().documentId).toBe('foo://bar.biz');
20
+ });
21
+ it('should marshal data', () => {
22
+ expect(docBuilder.withData('foo').marshal().data).toBe('foo');
23
+ });
24
+ it('should marshal date', () => {
25
+ const d = new Date();
26
+ expect(docBuilder.withDate(d).marshal().date).toMatch(d.toISOString());
27
+ });
28
+ it('should marshal author', () => {
29
+ expect(docBuilder.withAuthor('bob').marshal().author).toBe('bob');
30
+ });
31
+ it('should marshal clickableUri', () => {
32
+ expect(docBuilder.withClickableUri('click').marshal().clickableUri).toBe('click');
33
+ });
34
+ it('should marshal fileExtension', () => {
35
+ expect(docBuilder.withFileExtension('.html').marshal().fileExtension).toBe('.html');
36
+ });
37
+ it('should marshal metadata', () => {
38
+ expect(docBuilder
39
+ .withMetadata({
40
+ foo: 'bar',
41
+ buzz: ['bazz', 'bozz'],
42
+ baz: { '': 'defaultValue', key1: 'value1' },
43
+ })
44
+ .marshal()).toMatchObject({
45
+ foo: 'bar',
46
+ buzz: ['bazz', 'bozz'],
47
+ baz: { '': 'defaultValue', key1: 'value1' },
48
+ });
49
+ });
50
+ it('should throw error for invalid single metadata value', () => {
51
+ expect(() => {
52
+ docBuilder.withMetadataValue('f-o=o', 'bar').marshal();
53
+ }).toThrowError('f-o=o');
54
+ });
55
+ it('should throw error for invalid metadata values', () => {
56
+ expect(() => {
57
+ docBuilder
58
+ .withMetadata({ 'f-o=o': 'bar', '<buzz>': ['bazz', 'bozz'] })
59
+ .marshal();
60
+ }).toThrowErrorMatchingSnapshot();
61
+ });
62
+ it('should throw error for invalid metadata values even after transformation', () => {
63
+ const poorTransformer = (text) => text.replace(/[\W_]+/g, '*');
64
+ expect(() => {
65
+ docBuilder
66
+ .withMetadata({ 'f-o=o': 'bar', '<buzz>': ['bazz', 'bozz'] }, poorTransformer)
67
+ .marshal();
68
+ }).toThrowErrorMatchingSnapshot();
69
+ });
70
+ describe.each([
71
+ {
72
+ title: 'default',
73
+ transformer: transformer_1.BuiltInTransformers.toLowerCase,
74
+ expectedKey: 'foo',
75
+ },
76
+ {
77
+ title: 'underscore',
78
+ transformer: transformer_1.BuiltInTransformers.toSnakeCase,
79
+ expectedKey: 'f_o_o',
80
+ },
81
+ ])('when using the $title transformer', ({ transformer, expectedKey }) => {
82
+ it(`should format to ${expectedKey}`, () => {
83
+ expect(new documentBuilder_1.DocumentBuilder('uri', 'title')
84
+ .withMetadataValue('f-o=o', 'bar', transformer)
85
+ .marshal()).toMatchObject({
86
+ [expectedKey]: 'bar',
87
+ });
88
+ });
89
+ });
90
+ it('should marshal single metadata value', () => {
91
+ expect(docBuilder.withMetadataValue('foo', 'bar').marshal()).toMatchObject({
92
+ foo: 'bar',
93
+ });
94
+ });
95
+ it('should not marshal metadata key', () => {
96
+ expect(docBuilder
97
+ .withMetadata({ foo: 'bar', buzz: ['bazz', 'bozz'] })
98
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
99
+ .marshal().metadata).toBeUndefined();
100
+ });
101
+ it('should marshal modifiedDate', () => {
102
+ const d = new Date();
103
+ expect(docBuilder.withModifiedDate(d).marshal().modifiedDate).toMatch(d.toISOString());
104
+ });
105
+ it('should marshal parentId', () => {
106
+ expect(docBuilder.withParentID('id').marshal().parentId).toBe('id');
107
+ });
108
+ it('should marshal permanentId', () => {
109
+ expect(docBuilder.withPermanentId('id').marshal().permanentid).toBe('id');
110
+ });
111
+ it('should generate permanentid', () => {
112
+ docBuilder = new documentBuilder_1.DocumentBuilder('https://foo.com', 'bar');
113
+ expect(docBuilder.marshal().permanentid).toBe('aa2e0510b66edff7f05e2b30d4f1b3a4b5481c06b69f41751c54675c5afb');
114
+ });
115
+ it('throws when adding a reserved key name metadata', () => {
116
+ const theseShouldThrow = [
117
+ 'compressedBinaryData',
118
+ 'compressedBinaryDataFileId',
119
+ 'parentId',
120
+ 'fileExtension',
121
+ 'data',
122
+ 'permissions',
123
+ 'documentId',
124
+ 'orderingId',
125
+ ];
126
+ for (const shouldThrow of theseShouldThrow) {
127
+ expect(() => docBuilder.withMetadataValue(shouldThrow, 'foo')).toThrow();
128
+ }
129
+ });
130
+ it('should validate file extension', () => {
131
+ expect(() => docBuilder.withFileExtension('nope')).toThrow();
132
+ });
133
+ it('should build every permission set added to the document', () => {
134
+ const userIdentity = new securityIdentityBuilder_1.UserSecurityIdentityBuilder([
135
+ 'bob@foo.com',
136
+ 'sue@foo.com',
137
+ ]);
138
+ const groupIdentity = new securityIdentityBuilder_1.GroupSecurityIdentityBuilder('my_group');
139
+ const bobSpy = jest.spyOn(userIdentity, 'build');
140
+ const groupSpy = jest.spyOn(userIdentity, 'build');
141
+ const permissionSet = new permissionSetBuilder_1.PermissionSetBuilder(false)
142
+ .withDeniedPermissions(userIdentity)
143
+ .withDeniedPermissions(groupIdentity);
144
+ docBuilder.withPermissionSet(permissionSet);
145
+ expect(bobSpy).toHaveBeenCalledTimes(1);
146
+ expect(groupSpy).toHaveBeenCalledTimes(1);
147
+ });
148
+ it('should not marshal an empty array when permissions are not defined', () => {
149
+ expect(docBuilder.marshal()).not.toContain('permissions');
150
+ });
151
+ it('should marshal permission set', () => {
152
+ const userIdentity = new securityIdentityBuilder_1.UserSecurityIdentityBuilder([
153
+ 'bob@foo.com',
154
+ 'sue@foo.com',
155
+ ]);
156
+ const permissionSet = new permissionSetBuilder_1.PermissionSetBuilder(false)
157
+ .withDeniedPermissions(userIdentity)
158
+ .withDeniedPermissions(new securityIdentityBuilder_1.GroupSecurityIdentityBuilder('my_group'))
159
+ .withDeniedPermissions(new securityIdentityBuilder_1.VirtualGroupSecurityIdentityBuilder('virtual_group'));
160
+ const { permissions } = docBuilder.withPermissionSet(permissionSet).marshal();
161
+ expect(permissions).toHaveLength(1);
162
+ });
163
+ describe('when combining multiple permission sets', () => {
164
+ // Example taken from https://docs.coveo.com/en/107
165
+ const openedPermissionSet = new permissionSetBuilder_1.PermissionSetBuilder(true).withDeniedPermissions(new securityIdentityBuilder_1.UserSecurityIdentityBuilder('asmith@example.com'));
166
+ const restrictedPermissionSet = new permissionSetBuilder_1.PermissionSetBuilder(false)
167
+ .withAllowedPermissions(new securityIdentityBuilder_1.GroupSecurityIdentityBuilder('SampleTeam1'))
168
+ .withAllowedPermissions(new securityIdentityBuilder_1.UserSecurityIdentityBuilder('emitchell@example.com'));
169
+ const misteryPermissionSet = new permissionSetBuilder_1.PermissionSetBuilder(false)
170
+ .withDeniedPermissions(new securityIdentityBuilder_1.VirtualGroupSecurityIdentityBuilder('SampleGroup'))
171
+ .withAllowedPermissions(new securityIdentityBuilder_1.UserSecurityIdentityBuilder('MysteryUserX'));
172
+ it('should marshal multiple permission sets', () => {
173
+ const { permissions } = docBuilder
174
+ .withPermissionSet(openedPermissionSet)
175
+ .withPermissionSet(restrictedPermissionSet)
176
+ .withPermissionSet(misteryPermissionSet)
177
+ .marshal();
178
+ expect(permissions).toHaveLength(3);
179
+ });
180
+ it('should marshal permission level', () => {
181
+ const { permissions } = docBuilder
182
+ .withPermissionLevel('level1', [
183
+ openedPermissionSet,
184
+ restrictedPermissionSet,
185
+ ])
186
+ .withPermissionLevel('level2', [misteryPermissionSet])
187
+ .marshal();
188
+ expect(permissions).toMatchSnapshot();
189
+ });
190
+ });
191
+ });
192
192
  //# sourceMappingURL=documentBuilder.spec.js.map
@@ -1,42 +1,42 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.castEnvironmentToPlatformClient = exports.platformUrl = exports.DEFAULT_REGION = exports.DEFAULT_ENVIRONMENT = exports.PlatformEnvironment = exports.Region = void 0;
4
- const platform_client_1 = require("@coveo/platform-client");
5
- var platform_client_2 = require("@coveo/platform-client");
6
- Object.defineProperty(exports, "Region", { enumerable: true, get: function () { return platform_client_2.Region; } });
7
- var PlatformEnvironment;
8
- (function (PlatformEnvironment) {
9
- PlatformEnvironment["Dev"] = "dev";
10
- PlatformEnvironment["Stg"] = "stg";
11
- PlatformEnvironment["Hipaa"] = "hipaa";
12
- PlatformEnvironment["Prod"] = "prod";
13
- })(PlatformEnvironment = exports.PlatformEnvironment || (exports.PlatformEnvironment = {}));
14
- exports.DEFAULT_ENVIRONMENT = PlatformEnvironment.Prod;
15
- exports.DEFAULT_REGION = platform_client_1.Region.US;
16
- const defaultOptions = {
17
- environment: exports.DEFAULT_ENVIRONMENT,
18
- region: exports.DEFAULT_REGION,
19
- };
20
- function platformUrl(options) {
21
- options = Object.assign(Object.assign({}, defaultOptions), options);
22
- const urlEnv = options.environment === exports.DEFAULT_ENVIRONMENT ? '' : options.environment;
23
- const urlRegion = options.region === exports.DEFAULT_REGION ? '' : `-${options.region}`;
24
- return `https://api${urlEnv}${urlRegion}.cloud.coveo.com/push/v1/organizations`;
25
- }
26
- exports.platformUrl = platformUrl;
27
- function castEnvironmentToPlatformClient(e) {
28
- switch (e) {
29
- case 'dev':
30
- return platform_client_1.Environment.dev;
31
- case 'stg':
32
- return platform_client_1.Environment.stg;
33
- case 'prod':
34
- return platform_client_1.Environment.prod;
35
- case 'hipaa':
36
- return platform_client_1.Environment.hipaa;
37
- default:
38
- return platform_client_1.Environment.prod;
39
- }
40
- }
41
- exports.castEnvironmentToPlatformClient = castEnvironmentToPlatformClient;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.castEnvironmentToPlatformClient = exports.platformUrl = exports.DEFAULT_REGION = exports.DEFAULT_ENVIRONMENT = exports.PlatformEnvironment = exports.Region = void 0;
4
+ const platform_client_1 = require("@coveo/platform-client");
5
+ var platform_client_2 = require("@coveo/platform-client");
6
+ Object.defineProperty(exports, "Region", { enumerable: true, get: function () { return platform_client_2.Region; } });
7
+ var PlatformEnvironment;
8
+ (function (PlatformEnvironment) {
9
+ PlatformEnvironment["Dev"] = "dev";
10
+ PlatformEnvironment["Stg"] = "stg";
11
+ PlatformEnvironment["Hipaa"] = "hipaa";
12
+ PlatformEnvironment["Prod"] = "prod";
13
+ })(PlatformEnvironment = exports.PlatformEnvironment || (exports.PlatformEnvironment = {}));
14
+ exports.DEFAULT_ENVIRONMENT = PlatformEnvironment.Prod;
15
+ exports.DEFAULT_REGION = platform_client_1.Region.US;
16
+ const defaultOptions = {
17
+ environment: exports.DEFAULT_ENVIRONMENT,
18
+ region: exports.DEFAULT_REGION,
19
+ };
20
+ function platformUrl(options) {
21
+ options = Object.assign(Object.assign({}, defaultOptions), options);
22
+ const urlEnv = options.environment === exports.DEFAULT_ENVIRONMENT ? '' : options.environment;
23
+ const urlRegion = options.region === exports.DEFAULT_REGION ? '' : `-${options.region}`;
24
+ return `https://api${urlEnv}${urlRegion}.cloud.coveo.com/push/v1/organizations`;
25
+ }
26
+ exports.platformUrl = platformUrl;
27
+ function castEnvironmentToPlatformClient(e) {
28
+ switch (e) {
29
+ case 'dev':
30
+ return platform_client_1.Environment.dev;
31
+ case 'stg':
32
+ return platform_client_1.Environment.stg;
33
+ case 'prod':
34
+ return platform_client_1.Environment.prod;
35
+ case 'hipaa':
36
+ return platform_client_1.Environment.hipaa;
37
+ default:
38
+ return platform_client_1.Environment.prod;
39
+ }
40
+ }
41
+ exports.castEnvironmentToPlatformClient = castEnvironmentToPlatformClient;
42
42
  //# sourceMappingURL=environment.js.map
@@ -1,11 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PushApiClientBaseError = void 0;
4
- class PushApiClientBaseError extends Error {
5
- constructor(message) {
6
- super(message);
7
- this.name = 'Push API Client Error';
8
- }
9
- }
10
- exports.PushApiClientBaseError = PushApiClientBaseError;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PushApiClientBaseError = void 0;
4
+ class PushApiClientBaseError extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ this.name = 'Push API Client Error';
8
+ }
9
+ }
10
+ exports.PushApiClientBaseError = PushApiClientBaseError;
11
11
  //# sourceMappingURL=baseError.js.map
@@ -1,28 +1,28 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UnsupportedFieldError = exports.InvalidPermanentId = exports.FieldTypeInconsistencyError = void 0;
4
- const baseError_1 = require("./baseError");
5
- class FieldTypeInconsistencyError extends baseError_1.PushApiClientBaseError {
6
- constructor(inconsitencies) {
7
- super();
8
- this.name = 'Field Type Inconsistency Error';
9
- this.message = `Inconsistent types detected in the following field${inconsitencies.size > 1 ? 's' : ''}:`;
10
- inconsitencies.forEach((typeSet, field) => {
11
- const inconsistentTypes = [];
12
- for (const type of typeSet) {
13
- inconsistentTypes.push(type);
14
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UnsupportedFieldError = exports.InvalidPermanentId = exports.FieldTypeInconsistencyError = void 0;
4
+ const baseError_1 = require("./baseError");
5
+ class FieldTypeInconsistencyError extends baseError_1.PushApiClientBaseError {
6
+ constructor(inconsitencies) {
7
+ super();
8
+ this.name = 'Field Type Inconsistency Error';
9
+ this.message = `Inconsistent types detected in the following field${inconsitencies.size > 1 ? 's' : ''}:`;
10
+ inconsitencies.forEach((typeSet, field) => {
11
+ const inconsistentTypes = [];
12
+ for (const type of typeSet) {
13
+ inconsistentTypes.push(type);
14
+ }
15
15
  this.message += `
16
- ${field}: ${inconsistentTypes.sort().join(', ')}`;
17
- });
18
- // TODO: CDX-844: display document with type inconsistencies
16
+ ${field}: ${inconsistentTypes.sort().join(', ')}`;
17
+ });
18
+ // TODO: CDX-844: display document with type inconsistencies
19
19
  this.message += `
20
- Make sure to review and fix your document metadata before pushing`;
21
- }
22
- }
23
- exports.FieldTypeInconsistencyError = FieldTypeInconsistencyError;
24
- class InvalidPermanentId extends baseError_1.PushApiClientBaseError {
25
- constructor(field) {
20
+ Make sure to review and fix your document metadata before pushing`;
21
+ }
22
+ }
23
+ exports.FieldTypeInconsistencyError = FieldTypeInconsistencyError;
24
+ class InvalidPermanentId extends baseError_1.PushApiClientBaseError {
25
+ constructor(field) {
26
26
  super(`
27
27
  The permanentid field detected in the index is not correctly configured.
28
28
  Expected field type: STRING
@@ -30,27 +30,27 @@ class InvalidPermanentId extends baseError_1.PushApiClientBaseError {
30
30
 
31
31
  You can delete and recreate the permanentid field as a STRING field.
32
32
  See docs.coveo.com/en/1913 fore more info.
33
- `);
34
- this.name = 'Invalid permanentId field Error';
35
- }
36
- }
37
- exports.InvalidPermanentId = InvalidPermanentId;
38
- class UnsupportedFieldError extends baseError_1.PushApiClientBaseError {
39
- constructor(...unsupportedFields) {
40
- super();
41
- this.name = 'Unsupported field Error';
42
- this.unsupportedFields = unsupportedFields;
33
+ `);
34
+ this.name = 'Invalid permanentId field Error';
35
+ }
36
+ }
37
+ exports.InvalidPermanentId = InvalidPermanentId;
38
+ class UnsupportedFieldError extends baseError_1.PushApiClientBaseError {
39
+ constructor(...unsupportedFields) {
40
+ super();
41
+ this.name = 'Unsupported field Error';
42
+ this.unsupportedFields = unsupportedFields;
43
43
  this.message = `
44
44
  The following field names are still invalid after transformation:
45
45
  ${this.formattedFieldList}
46
46
  Field names can only contain lowercase letters (a-z), numbers (0-9), and underscores. Field names must be at least one character long and must start with a lowercase letter.
47
- `;
48
- }
49
- get formattedFieldList() {
50
- const replacer = UnsupportedFieldError.emptyFieldNameReplacer;
51
- return this.unsupportedFields.reduce((prev, curr) => (prev += ` • ${curr[0] || replacer} --> ${curr[1] || replacer}\n`), '');
52
- }
53
- }
54
- exports.UnsupportedFieldError = UnsupportedFieldError;
55
- UnsupportedFieldError.emptyFieldNameReplacer = '<empty field name>';
47
+ `;
48
+ }
49
+ get formattedFieldList() {
50
+ const replacer = UnsupportedFieldError.emptyFieldNameReplacer;
51
+ return this.unsupportedFields.reduce((prev, curr) => (prev += ` • ${curr[0] || replacer} --> ${curr[1] || replacer}\n`), '');
52
+ }
53
+ }
54
+ exports.UnsupportedFieldError = UnsupportedFieldError;
55
+ UnsupportedFieldError.emptyFieldNameReplacer = '<empty field name>';
56
56
  //# sourceMappingURL=fieldErrors.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("./fieldErrors"), exports);
18
- __exportStar(require("./privilegeError"), exports);
19
- __exportStar(require("./validatorErrors"), 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("./fieldErrors"), exports);
18
+ __exportStar(require("./privilegeError"), exports);
19
+ __exportStar(require("./validatorErrors"), exports);
20
20
  //# sourceMappingURL=index.js.map