@coveo/push-api-client 1.7.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/README.md +2 -2
  2. package/dist/definitions/environment.d.ts +3 -3
  3. package/dist/definitions/errors/privilegeError.d.ts +6 -0
  4. package/dist/definitions/help/axiosUtils.d.ts +2 -0
  5. package/dist/definitions/help/fileConsumer.d.ts +26 -0
  6. package/dist/definitions/{source.spec.d.ts → help/fileConsumer.spec.d.ts} +0 -0
  7. package/dist/definitions/help/fileContainer.d.ts +9 -0
  8. package/dist/definitions/help/fileContainer.spec.d.ts +1 -0
  9. package/dist/definitions/help/urlUtils.d.ts +27 -0
  10. package/dist/definitions/index.d.ts +7 -2
  11. package/dist/definitions/interfaces.d.ts +39 -0
  12. package/dist/definitions/source/batchUploadDocumentsFromFile.d.ts +11 -0
  13. package/dist/definitions/source/catalog.d.ts +69 -0
  14. package/dist/definitions/source/catalog.spec.d.ts +1 -0
  15. package/dist/definitions/source/catalog.stream.spec.d.ts +1 -0
  16. package/dist/definitions/source/documentUploader.d.ts +5 -0
  17. package/dist/definitions/{source.d.ts → source/push.d.ts} +35 -77
  18. package/dist/definitions/source/push.spec.d.ts +1 -0
  19. package/dist/definitions/source/securityIdenty.d.ts +42 -0
  20. package/dist/definitions/source/source.d.ts +5 -0
  21. package/dist/definitions/uploadStrategy/fileContainerStrategy.d.ts +23 -0
  22. package/dist/definitions/uploadStrategy/index.d.ts +3 -0
  23. package/dist/definitions/uploadStrategy/strategy.d.ts +16 -0
  24. package/dist/definitions/uploadStrategy/streamChunkStrategy.d.ts +27 -0
  25. package/dist/definitions/validation/preconditions/apiKeyPrivilege.d.ts +3 -0
  26. package/dist/definitions/validation/preconditions/apiKeyPrivilege.spec.d.ts +1 -0
  27. package/dist/definitions/validation/preconditions/platformPrivilege.d.ts +7 -0
  28. package/dist/docs/assets/search.js +1 -1
  29. package/dist/docs/classes/AnySecurityIdentityBuilder.html +3 -3
  30. package/dist/docs/classes/CatalogSource.html +40 -0
  31. package/dist/docs/classes/DocumentBuilder.html +17 -17
  32. package/dist/docs/classes/FieldAnalyser.html +3 -3
  33. package/dist/docs/classes/GroupSecurityIdentityBuilder.html +3 -3
  34. package/dist/docs/classes/PushSource.html +43 -0
  35. package/dist/docs/classes/UserSecurityIdentityBuilder.html +3 -3
  36. package/dist/docs/classes/VirtualGroupSecurityIdentityBuilder.html +3 -3
  37. package/dist/docs/enums/PlatformEnvironment.html +1 -1
  38. package/dist/docs/enums/Region.html +1 -1
  39. package/dist/docs/enums/SourceVisibility.html +1 -1
  40. package/dist/docs/index.html +2 -2
  41. package/dist/docs/interfaces/BatchUpdateDocuments.html +1 -1
  42. package/dist/docs/interfaces/Document.html +14 -14
  43. package/dist/docs/interfaces/SecurityIdentity.html +4 -4
  44. package/dist/docs/interfaces/SecurityIdentityBuilder.html +1 -1
  45. package/dist/docs/interfaces/UploadBatchCallbackData.html +1 -1
  46. package/dist/docs/modules.html +3 -2
  47. package/dist/environment.js.map +1 -1
  48. package/dist/errors/privilegeError.js +13 -0
  49. package/dist/errors/privilegeError.js.map +1 -0
  50. package/dist/fieldAnalyser/fieldAnalyser.js +3 -0
  51. package/dist/fieldAnalyser/fieldAnalyser.js.map +1 -1
  52. package/dist/fieldAnalyser/fieldAnalyser.spec.js +13 -0
  53. package/dist/fieldAnalyser/fieldAnalyser.spec.js.map +1 -1
  54. package/dist/fieldAnalyser/fieldUtils.js +4 -0
  55. package/dist/fieldAnalyser/fieldUtils.js.map +1 -1
  56. package/dist/fieldAnalyser/fieldsUtils.spec.js +3 -0
  57. package/dist/fieldAnalyser/fieldsUtils.spec.js.map +1 -1
  58. package/dist/help/axiosUtils.js +12 -0
  59. package/dist/help/axiosUtils.js.map +1 -0
  60. package/dist/help/fileConsumer.js +100 -0
  61. package/dist/help/fileConsumer.js.map +1 -0
  62. package/dist/help/fileConsumer.spec.js +75 -0
  63. package/dist/help/fileConsumer.spec.js.map +1 -0
  64. package/dist/help/fileContainer.js +20 -0
  65. package/dist/help/fileContainer.js.map +1 -0
  66. package/dist/help/fileContainer.spec.js +34 -0
  67. package/dist/help/fileContainer.spec.js.map +1 -0
  68. package/dist/help/urlUtils.js +43 -0
  69. package/dist/help/urlUtils.js.map +1 -0
  70. package/dist/index.js +8 -3
  71. package/dist/index.js.map +1 -1
  72. package/dist/interfaces.js +3 -0
  73. package/dist/interfaces.js.map +1 -0
  74. package/dist/localtest.js +2 -2
  75. package/dist/localtest.js.map +1 -1
  76. package/dist/source/batchUploadDocumentsFromFile.js +50 -0
  77. package/dist/source/batchUploadDocumentsFromFile.js.map +1 -0
  78. package/dist/source/catalog.js +115 -0
  79. package/dist/source/catalog.js.map +1 -0
  80. package/dist/source/catalog.spec.js +239 -0
  81. package/dist/source/catalog.spec.js.map +1 -0
  82. package/dist/source/catalog.stream.spec.js +189 -0
  83. package/dist/source/catalog.stream.spec.js.map +1 -0
  84. package/dist/source/documentUploader.js +23 -0
  85. package/dist/source/documentUploader.js.map +1 -0
  86. package/dist/source/push.js +199 -0
  87. package/dist/source/push.js.map +1 -0
  88. package/dist/{source.spec.js → source/push.spec.js} +44 -27
  89. package/dist/source/push.spec.js.map +1 -0
  90. package/dist/source/securityIdenty.js +59 -0
  91. package/dist/source/securityIdenty.js.map +1 -0
  92. package/dist/source/source.js +9 -0
  93. package/dist/source/source.js.map +1 -0
  94. package/dist/uploadStrategy/fileContainerStrategy.js +34 -0
  95. package/dist/uploadStrategy/fileContainerStrategy.js.map +1 -0
  96. package/dist/uploadStrategy/index.js +7 -0
  97. package/dist/uploadStrategy/index.js.map +1 -0
  98. package/dist/uploadStrategy/strategy.js +3 -0
  99. package/dist/uploadStrategy/strategy.js.map +1 -0
  100. package/dist/uploadStrategy/streamChunkStrategy.js +51 -0
  101. package/dist/uploadStrategy/streamChunkStrategy.js.map +1 -0
  102. package/dist/validation/preconditions/apiKeyPrivilege.js +21 -0
  103. package/dist/validation/preconditions/apiKeyPrivilege.js.map +1 -0
  104. package/dist/validation/preconditions/apiKeyPrivilege.spec.js +70 -0
  105. package/dist/validation/preconditions/apiKeyPrivilege.spec.js.map +1 -0
  106. package/dist/validation/preconditions/platformPrivilege.js +35 -0
  107. package/dist/validation/preconditions/platformPrivilege.js.map +1 -0
  108. package/package.json +1 -1
  109. package/dist/docs/classes/Source.html +0 -45
  110. package/dist/docs/interfaces/BatchUpdateDocumentsFromFiles.html +0 -7
  111. package/dist/source.js +0 -322
  112. package/dist/source.js.map +0 -1
  113. package/dist/source.spec.js.map +0 -1
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SecurityIdentity = void 0;
4
+ require('isomorphic-fetch');
5
+ require('abortcontroller-polyfill');
6
+ class SecurityIdentity {
7
+ /**
8
+ *
9
+ * @param apikey An apiKey capable of pushing documents and managing sources in a Coveo organization. See [Manage API Keys](https://docs.coveo.com/en/1718).
10
+ * @param organizationid The Coveo Organization identifier.
11
+ */
12
+ constructor(platformClient) {
13
+ this.platformClient = platformClient;
14
+ }
15
+ /**
16
+ * Create or update a security identity. See [Adding a Single Security Identity](https://docs.coveo.com/en/167) and [Security Identity Models](https://docs.coveo.com/en/139).
17
+ * @param securityProviderId
18
+ * @param securityIdentity
19
+ * @returns
20
+ */
21
+ createSecurityIdentity(securityProviderId, securityIdentity) {
22
+ return this.platformClient.pushApi.createOrUpdateSecurityIdentity(securityProviderId, securityIdentity);
23
+ }
24
+ /**
25
+ * Create or update a security identity alias. See [Adding a Single Alias](https://docs.coveo.com/en/142) and [User Alias Definition Examples](https://docs.coveo.com/en/46).
26
+ * @param securityProviderId
27
+ * @param securityIdentityAlias
28
+ * @returns
29
+ */
30
+ createOrUpdateSecurityIdentityAlias(securityProviderId, securityIdentityAlias) {
31
+ return this.platformClient.pushApi.createOrUpdateSecurityIdentityAlias(securityProviderId, securityIdentityAlias);
32
+ }
33
+ /**
34
+ * Delete a security identity. See [Disabling a Single Security Identity](https://docs.coveo.com/en/84).
35
+ * @param securityProviderId
36
+ * @param securityIdentityToDelete
37
+ * @returns
38
+ */
39
+ deleteSecurityIdentity(securityProviderId, securityIdentityToDelete) {
40
+ return this.platformClient.pushApi.deleteSecurityIdentity(securityProviderId, securityIdentityToDelete);
41
+ }
42
+ /**
43
+ * Delete old security identities. See [Disabling Old Security Identities](https://docs.coveo.com/en/33).
44
+ * @param securityProviderId
45
+ * @param batchDelete
46
+ * @returns
47
+ */
48
+ deleteOldSecurityIdentities(securityProviderId, batchDelete) {
49
+ return this.platformClient.pushApi.deleteOldSecurityIdentities(securityProviderId, batchDelete);
50
+ }
51
+ /**
52
+ * Manage batches of security identities. See [Manage Batches of Security Identities](https://docs.coveo.com/en/55).
53
+ */
54
+ manageSecurityIdentities(securityProviderId, batchConfig) {
55
+ return this.platformClient.pushApi.manageSecurityIdentities(securityProviderId, batchConfig);
56
+ }
57
+ }
58
+ exports.SecurityIdentity = SecurityIdentity;
59
+ //# sourceMappingURL=securityIdenty.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"securityIdenty.js","sourceRoot":"","sources":["../../src/source/securityIdenty.ts"],"names":[],"mappings":";;;AAAA,OAAO,CAAC,kBAAkB,CAAC,CAAC;AAC5B,OAAO,CAAC,0BAA0B,CAAC,CAAC;AAWpC,MAAa,gBAAgB;IAC3B;;;;OAIG;IACH,YAAoB,cAA8B;QAA9B,mBAAc,GAAd,cAAc,CAAgB;IAAG,CAAC;IAEtD;;;;;OAKG;IACI,sBAAsB,CAC3B,kBAA0B,EAC1B,gBAAuC;QAEvC,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,8BAA8B,CAC/D,kBAAkB,EAClB,gBAAgB,CACjB,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACI,mCAAmC,CACxC,kBAA0B,EAC1B,qBAAiD;QAEjD,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,mCAAmC,CACpE,kBAAkB,EAClB,qBAAqB,CACtB,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACI,sBAAsB,CAC3B,kBAA0B,EAC1B,wBAAgD;QAEhD,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,sBAAsB,CACvD,kBAAkB,EAClB,wBAAwB,CACzB,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACI,2BAA2B,CAChC,kBAA0B,EAC1B,WAA0C;QAE1C,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,2BAA2B,CAC5D,kBAAkB,EAClB,WAAW,CACZ,CAAC;IACJ,CAAC;IAED;;OAEG;IACI,wBAAwB,CAC7B,kBAA0B,EAC1B,WAAwC;QAExC,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,wBAAwB,CACzD,kBAAkB,EAClB,WAAW,CACZ,CAAC;IACJ,CAAC;CACF;AApFD,4CAoFC"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Source = void 0;
4
+ const push_1 = require("./push");
5
+ /**
6
+ * @deprecated This class has been replaced by {@link PushSource}
7
+ */
8
+ exports.Source = push_1.PushSource;
9
+ //# sourceMappingURL=source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source.js","sourceRoot":"","sources":["../../src/source/source.ts"],"names":[],"mappings":";;;AAAA,iCAAkC;AAElC;;GAEG;AACU,QAAA,MAAM,GAAG,iBAAU,CAAC"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FileContainerStrategy = void 0;
4
+ const axios_1 = require("axios");
5
+ const fileContainer_1 = require("../help/fileContainer");
6
+ /**
7
+ * Upload documents using the [File container](https://docs.coveo.com/en/43/index-content/creating-a-file-container)
8
+ *
9
+ * @class FileContainerStrategy
10
+ * @implements {UploadStrategy}
11
+ */
12
+ class FileContainerStrategy {
13
+ constructor(urlBuilder, documentsAxiosConfig) {
14
+ this.urlBuilder = urlBuilder;
15
+ this.documentsAxiosConfig = documentsAxiosConfig;
16
+ }
17
+ async upload(batch) {
18
+ const fileContainer = await this.createFileContainer();
19
+ await (0, fileContainer_1.uploadContentToFileContainer)(fileContainer, batch);
20
+ return this.pushFileContainerContent(fileContainer);
21
+ }
22
+ async createFileContainer() {
23
+ const fileContainerURL = this.urlBuilder.fileContainerUrl.toString();
24
+ const res = await axios_1.default.post(fileContainerURL, {}, this.documentsAxiosConfig);
25
+ return res.data;
26
+ }
27
+ pushFileContainerContent(fileContainer) {
28
+ const pushURL = this.urlBuilder.baseAPIURLForUpdate;
29
+ pushURL.searchParams.append('fileId', fileContainer.fileId);
30
+ return axios_1.default.put(pushURL.toString(), {}, this.documentsAxiosConfig);
31
+ }
32
+ }
33
+ exports.FileContainerStrategy = FileContainerStrategy;
34
+ //# sourceMappingURL=fileContainerStrategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fileContainerStrategy.js","sourceRoot":"","sources":["../../src/uploadStrategy/fileContainerStrategy.ts"],"names":[],"mappings":";;;AAAA,iCAAgD;AAGhD,yDAAmE;AAQnE;;;;;GAKG;AACH,MAAa,qBAAqB;IAChC,YACU,UAAsB,EACtB,oBAAwC;QADxC,eAAU,GAAV,UAAU,CAAY;QACtB,yBAAoB,GAApB,oBAAoB,CAAoB;IAC/C,CAAC;IAEG,KAAK,CAAC,MAAM,CAAC,KAA2B;QAC7C,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACvD,MAAM,IAAA,4CAA4B,EAAC,aAAa,EAAE,KAAK,CAAC,CAAC;QACzD,OAAO,IAAI,CAAC,wBAAwB,CAAC,aAAa,CAAC,CAAC;IACtD,CAAC;IAEO,KAAK,CAAC,mBAAmB;QAC/B,MAAM,gBAAgB,GAAG,IAAI,CAAC,UAAU,CAAC,gBAAgB,CAAC,QAAQ,EAAE,CAAC;QACrE,MAAM,GAAG,GAAG,MAAM,eAAK,CAAC,IAAI,CAC1B,gBAAgB,EAChB,EAAE,EACF,IAAI,CAAC,oBAAoB,CAC1B,CAAC;QACF,OAAO,GAAG,CAAC,IAAI,CAAC;IAClB,CAAC;IAEO,wBAAwB,CAAC,aAAoC;QACnE,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,mBAAmB,CAAC;QACpD,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,QAAQ,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;QAC5D,OAAO,eAAK,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;IACtE,CAAC;CACF;AA3BD,sDA2BC"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./fileContainerStrategy"), exports);
5
+ tslib_1.__exportStar(require("./strategy"), exports);
6
+ tslib_1.__exportStar(require("./streamChunkStrategy"), exports);
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/uploadStrategy/index.ts"],"names":[],"mappings":";;;AAAA,kEAAwC;AACxC,qDAA2B;AAC3B,gEAAsC"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=strategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strategy.js","sourceRoot":"","sources":["../../src/uploadStrategy/strategy.ts"],"names":[],"mappings":""}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StreamChunkStrategy = void 0;
4
+ const axios_1 = require("axios");
5
+ const url_1 = require("url");
6
+ const fileContainer_1 = require("../help/fileContainer");
7
+ /**
8
+ * Upload documents using the [Stream API](https://docs.coveo.com/en/lb4a0344/coveo-for-commerce/how-to-stream-your-catalog-data-to-your-source)
9
+ *
10
+ * @class StreamChunkStrategy
11
+ * @implements {UploadStrategy}
12
+ */
13
+ class StreamChunkStrategy {
14
+ constructor(urlBuilder, documentsAxiosConfig) {
15
+ this.urlBuilder = urlBuilder;
16
+ this.documentsAxiosConfig = documentsAxiosConfig;
17
+ this._openedStream = null;
18
+ }
19
+ async upload(batch) {
20
+ const chunk = await this.requestStreamChunk();
21
+ return (0, fileContainer_1.uploadContentToFileContainer)(chunk, batch);
22
+ }
23
+ postUpload() {
24
+ return this.closeOpenedStream();
25
+ }
26
+ async openStreamIfNotAlreadyOpen() {
27
+ if (this._openedStream === null) {
28
+ const openStreamUrl = new url_1.URL(`${this.urlBuilder.baseStreamURL}/open`);
29
+ const res = await axios_1.default.post(openStreamUrl.toString(), {}, this.documentsAxiosConfig);
30
+ this._openedStream = res.data;
31
+ }
32
+ return this._openedStream;
33
+ }
34
+ async closeOpenedStream() {
35
+ if (this._openedStream === null) {
36
+ return;
37
+ }
38
+ const openStreamUrl = new url_1.URL(`${this.urlBuilder.baseStreamURL}/${this._openedStream.streamId}/close`);
39
+ const res = await axios_1.default.post(openStreamUrl.toString(), {}, this.documentsAxiosConfig);
40
+ this._openedStream = null;
41
+ return res.data;
42
+ }
43
+ async requestStreamChunk() {
44
+ const { streamId } = await this.openStreamIfNotAlreadyOpen();
45
+ const openStreamUrl = new url_1.URL(`${this.urlBuilder.baseStreamURL}/${streamId}/chunk`);
46
+ const res = await axios_1.default.post(openStreamUrl.toString(), {}, this.documentsAxiosConfig);
47
+ return res.data;
48
+ }
49
+ }
50
+ exports.StreamChunkStrategy = StreamChunkStrategy;
51
+ //# sourceMappingURL=streamChunkStrategy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streamChunkStrategy.js","sourceRoot":"","sources":["../../src/uploadStrategy/streamChunkStrategy.ts"],"names":[],"mappings":";;;AAAA,iCAAgD;AAChD,6BAAwB;AAGxB,yDAAmE;AAUnE;;;;;GAKG;AACH,MAAa,mBAAmB;IAE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AI,CAAC;IAClB,CAAC;IAEO,KAAK,CAAC,kBAAkB;QAC9B,MAAM,EAAC,QAAQ,EAAC,GAAG,MAAM,IAAI,CAAC,0BAA0B,EAAE,CAAC;QAC3D,MAAM,aAAa,GAAG,IAAI,SAAG,CAC3B,GAAG,IAAI,CAAC,UAAU,CAAC,aAAa,IAAI,QAAQ,QAAQ,CACrD,CAAC;QAEF,MAAM,GAAG,GAAG,MAAM,eAAK,CAAC,IAAI,CAC1B,aAAa,CAAC,QAAQ,EAAE,EACxB,EAAE,EACF,IAAI,CAAC,oBAAoB,CAC1B,CAAC;QACF,OAAO,GAAG,CAAC,IAAI,CAAC;IAClB,CAAC;CACF;AA5DD,kDA4DC"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensureNecessaryCoveoPrivileges = void 0;
4
+ const privilegeError_1 = require("../../errors/privilegeError");
5
+ // Code copy pasted from https://github.com/coveo/cli/blob/master/packages/cli/src/lib/decorators/preconditions/apiKeyPrivilege.ts#L15
6
+ async function ensureNecessaryCoveoPrivileges(client, ...privileges) {
7
+ const promises = privileges.flatMap((privilege) => privilege.models.map(async (model) => {
8
+ if (!(await hasPrivilege(client, model))) {
9
+ const message = privilege.unsatisfiedConditionMessage;
10
+ throw new privilegeError_1.PrivilegeError(message);
11
+ }
12
+ }));
13
+ await Promise.all(promises);
14
+ }
15
+ exports.ensureNecessaryCoveoPrivileges = ensureNecessaryCoveoPrivileges;
16
+ async function hasPrivilege(client, privilege) {
17
+ const model = Object.assign({ requestedPrivilege: privilege });
18
+ const validation = await client.privilegeEvaluator.evaluate(model);
19
+ return Boolean(validation.approved);
20
+ }
21
+ //# sourceMappingURL=apiKeyPrivilege.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apiKeyPrivilege.js","sourceRoot":"","sources":["../../../src/validation/preconditions/apiKeyPrivilege.ts"],"names":[],"mappings":";;;AAMA,gEAA2D;AAE3D,sIAAsI;AAC/H,KAAK,UAAU,8BAA8B,CAClD,MAAsB,EACtB,GAAG,UAA+B;IAElC,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE,CAChD,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QACnC,IAAI,CAAC,CAAC,MAAM,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,EAAE;YACxC,MAAM,OAAO,GAAG,SAAS,CAAC,2BAA2B,CAAC;YACtD,MAAM,IAAI,+BAAc,CAAC,OAAO,CAAC,CAAC;SACnC;IACH,CAAC,CAAC,CACH,CAAC;IAEF,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AAC9B,CAAC;AAdD,wEAcC;AAED,KAAK,UAAU,YAAY,CAAC,MAAsB,EAAE,SAAyB;IAC3E,MAAM,KAAK,iBACN,EAAC,kBAAkB,EAAE,SAAS,EAAC,CACnC,CAAC;IAEF,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACnE,OAAO,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;AACtC,CAAC"}
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ jest.mock('@coveord/platform-client');
4
+ const platform_client_1 = require("@coveord/platform-client");
5
+ const platformPrivilege_1 = require("./platformPrivilege");
6
+ const apiKeyPrivilege_1 = require("./apiKeyPrivilege");
7
+ const mockedPlatformClient = jest.mocked(platform_client_1.default);
8
+ const mockEvaluate = jest.fn();
9
+ const doMockPlatformClient = () => {
10
+ mockedPlatformClient.mockImplementation(() => ({
11
+ privilegeEvaluator: { evaluate: mockEvaluate },
12
+ }));
13
+ };
14
+ const dummyPlatformClient = () => {
15
+ return new platform_client_1.default({ accessToken: 'xxx' });
16
+ };
17
+ describe('ApiKeyPrivileges', () => {
18
+ let client;
19
+ beforeAll(() => {
20
+ doMockPlatformClient();
21
+ });
22
+ beforeEach(async () => {
23
+ client = dummyPlatformClient();
24
+ });
25
+ describe('when not missing privileges', () => {
26
+ beforeEach(async () => {
27
+ mockEvaluate.mockResolvedValue({ approved: true });
28
+ });
29
+ it('should call the privilege evaluator for each privilege to evaluate', async () => {
30
+ await (0, apiKeyPrivilege_1.ensureNecessaryCoveoPrivileges)(client, platformPrivilege_1.writeFieldsPrivilege);
31
+ expect(mockEvaluate).toHaveBeenCalledTimes(3);
32
+ });
33
+ it.each([
34
+ {
35
+ type: 'VIEW',
36
+ },
37
+ {
38
+ type: 'CREATE',
39
+ },
40
+ {
41
+ type: 'EDIT',
42
+ },
43
+ ])('should evaluate the "$type FIELD" privilege', async ({ type }) => {
44
+ process.stdout.write('*********************\n');
45
+ process.stdout.write(`${type}\n`);
46
+ process.stdout.write('*********************\n');
47
+ await (0, apiKeyPrivilege_1.ensureNecessaryCoveoPrivileges)(client, platformPrivilege_1.writeFieldsPrivilege);
48
+ expect(mockEvaluate).toHaveBeenCalledWith({
49
+ requestedPrivilege: {
50
+ type,
51
+ targetDomain: 'FIELD',
52
+ targetId: '*',
53
+ owner: 'PLATFORM',
54
+ },
55
+ });
56
+ });
57
+ it('should not throw a Privilege Error', async () => {
58
+ await expect((0, apiKeyPrivilege_1.ensureNecessaryCoveoPrivileges)(client, platformPrivilege_1.writeFieldsPrivilege)).resolves.not.toThrow();
59
+ });
60
+ });
61
+ describe('when missing privileges', () => {
62
+ beforeEach(async () => {
63
+ mockEvaluate.mockResolvedValue({ approved: false });
64
+ });
65
+ it('should throw a Privilege Error', async () => {
66
+ await expect((0, apiKeyPrivilege_1.ensureNecessaryCoveoPrivileges)(client, platformPrivilege_1.writeFieldsPrivilege)).rejects.toThrow(/Your API key doesn't have the privilege to create or update fields/);
67
+ });
68
+ });
69
+ });
70
+ //# sourceMappingURL=apiKeyPrivilege.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":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AAoB,CAAC,CAC7D,CAAC,OAAO,CAAC,OAAO,CACf,oEAAoE,CACrE,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.writeFieldsPrivilege = exports.readFieldsPrivilege = void 0;
4
+ exports.readFieldsPrivilege = {
5
+ models: [
6
+ {
7
+ type: 'VIEW',
8
+ targetDomain: 'FIELD',
9
+ targetId: '*',
10
+ owner: 'PLATFORM',
11
+ },
12
+ ],
13
+ unsatisfiedConditionMessage: `Your API key doesn't have the privilege to view fields and their configuration. Make sure to grant this privilege to your API key before running the command again.
14
+ See https://docs.coveo.com/en/1707#fields-domain`,
15
+ };
16
+ exports.writeFieldsPrivilege = {
17
+ models: [
18
+ ...exports.readFieldsPrivilege.models,
19
+ {
20
+ type: 'CREATE',
21
+ targetDomain: 'FIELD',
22
+ targetId: '*',
23
+ owner: 'PLATFORM',
24
+ },
25
+ {
26
+ type: 'EDIT',
27
+ targetDomain: 'FIELD',
28
+ targetId: '*',
29
+ owner: 'PLATFORM',
30
+ },
31
+ ],
32
+ unsatisfiedConditionMessage: `Your API key doesn't have the privilege to create or update fields. Make sure to grant this privilege to your API key before running the command again.
33
+ See https://docs.coveo.com/en/1707#fields-domain`,
34
+ };
35
+ //# sourceMappingURL=platformPrivilege.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platformPrivilege.js","sourceRoot":"","sources":["../../../src/validation/preconditions/platformPrivilege.ts"],"names":[],"mappings":";;;AAOa,QAAA,mBAAmB,GAAsB;IACpD,MAAM,EAAE;QACN;YACE,IAAI,EAAE,MAAM;YACZ,YAAY,EAAE,OAAO;YACrB,QAAQ,EAAE,GAAG;YACb,KAAK,EAAE,UAAU;SAClB;KACF;IACD,2BAA2B,EAAE;mDACoB;CAClD,CAAC;AAEW,QAAA,oBAAoB,GAAsB;IACrD,MAAM,EAAE;QACN,GAAG,2BAAmB,CAAC,MAAM;QAC7B;YACE,IAAI,EAAE,QAAQ;YACd,YAAY,EAAE,OAAO;YACrB,QAAQ,EAAE,GAAG;YACb,KAAK,EAAE,UAAU;SAClB;QACD;YACE,IAAI,EAAE,MAAM;YACZ,YAAY,EAAE,OAAO;YACrB,QAAQ,EAAE,GAAG;YACb,KAAK,EAAE,UAAU;SAClB;KACF;IACD,2BAA2B,EAAE;mDACoB;CAClD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coveo/push-api-client",
3
- "version": "1.7.0",
3
+ "version": "2.1.1",
4
4
  "description": "Push API client",
5
5
  "main": "./dist/index.js",
6
6
  "files": [