@studyportals/campaign-management-api-interface 16.4.3-5 → 17.0.2-2

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 (49) hide show
  1. package/index.d.ts +3 -5
  2. package/index.js +3 -6
  3. package/index.js.map +1 -1
  4. package/package.json +4 -7
  5. package/src/auditor-campaign-management-api.client.d.ts +0 -5
  6. package/src/auditor-campaign-management-api.client.js +8 -28
  7. package/src/auditor-campaign-management-api.client.js.map +1 -1
  8. package/src/campaign-management-api.client.d.ts +12 -25
  9. package/src/campaign-management-api.client.js +65 -220
  10. package/src/campaign-management-api.client.js.map +1 -1
  11. package/src/domain/campaign/index.d.ts +1 -3
  12. package/src/domain/campaign/index.js +1 -3
  13. package/src/domain/campaign/index.js.map +1 -1
  14. package/src/errors/http-error.d.ts +12 -0
  15. package/src/errors/http-error.js +12 -0
  16. package/src/errors/http-error.js.map +1 -0
  17. package/src/links-campaign-management-api.client.js +2 -5
  18. package/src/links-campaign-management-api.client.js.map +1 -1
  19. package/src/organisations-campaign-management-api.client.d.ts +1 -0
  20. package/src/organisations-campaign-management-api.client.js +8 -17
  21. package/src/organisations-campaign-management-api.client.js.map +1 -1
  22. package/src/private-campaign-management-api.client.d.ts +1 -43
  23. package/src/private-campaign-management-api.client.js +23 -97
  24. package/src/private-campaign-management-api.client.js.map +1 -1
  25. package/src/products-campaign-management-api.client.js +2 -5
  26. package/src/products-campaign-management-api.client.js.map +1 -1
  27. package/src/study-campaign-management-api.client.js +2 -5
  28. package/src/study-campaign-management-api.client.js.map +1 -1
  29. package/src/user-campaign-management-api.client.d.ts +1 -0
  30. package/src/user-campaign-management-api.client.js +8 -16
  31. package/src/user-campaign-management-api.client.js.map +1 -1
  32. package/src/utils/http-request.d.ts +33 -0
  33. package/src/utils/http-request.js +57 -0
  34. package/src/utils/http-request.js.map +1 -0
  35. package/src/campaign-saving/index.d.ts +0 -3
  36. package/src/campaign-saving/index.js +0 -6
  37. package/src/campaign-saving/index.js.map +0 -1
  38. package/src/campaign-saving/websocket-data-type.d.ts +0 -19
  39. package/src/campaign-saving/websocket-data-type.js +0 -3
  40. package/src/campaign-saving/websocket-data-type.js.map +0 -1
  41. package/src/campaign-saving/websocket-lambda-topics.enum.d.ts +0 -3
  42. package/src/campaign-saving/websocket-lambda-topics.enum.js +0 -8
  43. package/src/campaign-saving/websocket-lambda-topics.enum.js.map +0 -1
  44. package/src/domain/campaign/entity-geotargeting.dto.d.ts +0 -5
  45. package/src/domain/campaign/entity-geotargeting.dto.js +0 -3
  46. package/src/domain/campaign/entity-geotargeting.dto.js.map +0 -1
  47. package/src/domain/campaign/targeted-countries.dto.d.ts +0 -8
  48. package/src/domain/campaign/targeted-countries.dto.js +0 -10
  49. package/src/domain/campaign/targeted-countries.dto.js.map +0 -1
package/index.d.ts CHANGED
@@ -1,17 +1,16 @@
1
1
  import { AuditorCampaignManagementAPIClient } from "./src/auditor-campaign-management-api.client";
2
+ import { HttpError } from "./src/errors/http-error";
2
3
  import { OrganisationsCampaignManagementAPIClient } from "./src/organisations-campaign-management-api.client";
3
- import { CampaignManagementAPIClient } from "./src/campaign-management-api.client";
4
+ import { CampaignManagementAPIClient, CampaignManagementAPIClientConfig } from "./src/campaign-management-api.client";
4
5
  import { AuditorEntityType } from "./src/domain/auditor/enums/auditor-entity-type.enum";
5
6
  import { AuditorOperation } from "./src/domain/auditor/enums/auditor-operation.enum";
6
7
  import { GetAuditorDto } from "./src/domain/auditor/get-auditor.dto";
7
- import { CampaignsEntitiesConfigDto } from "./src/domain/campaign/campaign-entities-config.dto";
8
8
  import { NumberMap, Pricing, ICampaignAuditorData } from "./src/domain/auditor/campaigns/geotargeting.entities";
9
9
  import { PrivateCampaignManagementAPIClient } from "./src/private-campaign-management-api.client";
10
10
  import { UserCampaignManagementAPIClient } from "./src/user-campaign-management-api.client";
11
11
  import { StudyCampaignManagementAPIClient } from "./src/study-campaign-management-api.client";
12
12
  import { MinimalOrganisationDto } from "./src/domain/organisations/minimal-organisations.dto";
13
13
  import { LinkType } from "./src/domain/studies/enums/link-type.enum";
14
- import { PersistGoogleLinkerResultDto } from "./src/domain/campaign/persist-google-linker-result.dto";
15
14
  import { LinkEntityType } from "./src/domain/links/link-entity-type.enum";
16
15
  import { LinksCampaignManagementAPIClient } from './src/links-campaign-management-api.client';
17
16
  import { SwappingEnabledLinkTypes } from "./src/domain/links/swapping-enabled-link-types.enum";
@@ -34,5 +33,4 @@ export * from "./src/validation";
34
33
  export * from "./src/domain/organisations";
35
34
  export * from "./src/domain/products";
36
35
  export * from "./src/domain/degrees";
37
- export * from "./src/campaign-saving";
38
- export { AuditorCampaignManagementAPIClient, OrganisationsCampaignManagementAPIClient, CampaignManagementAPIClient, PrivateCampaignManagementAPIClient, PrivateUserCampaignManagementAPIClient, UserCampaignManagementAPIClient, StudyCampaignManagementAPIClient, LinksCampaignManagementAPIClient, ProductsCampaignManagementAPIClient, PublicStatusClient, GeotarginatorFrontCMAClient, UniversitySchedulerCMAClient, AuditorEntityType, AuditorOperation, LinkType, LinkEntityType, SwappingEnabledLinkTypes, GetAuditorDto, PersistGoogleLinkerResultDto, IdDto, CampaignsEntitiesConfigDto, CreateLinkDto, UpdateLinkDto, MinimalOrganisationDto, CampaignEditorFrontendStatusDto, StatusHealthy, StatusBlocked, SaveCampaignGeotargetingRequest, GeotargetingEntity, TargetedCountries, EntityConfigsGroup, FlatEntityConfig, groupEntityConfigs, flattenEntityConfigs, CampaignStartPayload, SchedulerGeoEntity, SchedulerPricingEntity, NumberMap, Pricing, ICampaignAuditorData, SuperAgentResponseCover };
36
+ export { AuditorCampaignManagementAPIClient, OrganisationsCampaignManagementAPIClient, CampaignManagementAPIClient, CampaignManagementAPIClientConfig, PrivateCampaignManagementAPIClient, PrivateUserCampaignManagementAPIClient, UserCampaignManagementAPIClient, StudyCampaignManagementAPIClient, LinksCampaignManagementAPIClient, ProductsCampaignManagementAPIClient, PublicStatusClient, GeotarginatorFrontCMAClient, UniversitySchedulerCMAClient, AuditorEntityType, AuditorOperation, LinkType, LinkEntityType, SwappingEnabledLinkTypes, GetAuditorDto, IdDto, CreateLinkDto, UpdateLinkDto, MinimalOrganisationDto, CampaignEditorFrontendStatusDto, StatusHealthy, StatusBlocked, SaveCampaignGeotargetingRequest, GeotargetingEntity, TargetedCountries, EntityConfigsGroup, FlatEntityConfig, groupEntityConfigs, flattenEntityConfigs, CampaignStartPayload, SchedulerGeoEntity, SchedulerPricingEntity, NumberMap, Pricing, ICampaignAuditorData, SuperAgentResponseCover, HttpError };
package/index.js CHANGED
@@ -14,9 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.Pricing = exports.flattenEntityConfigs = exports.groupEntityConfigs = exports.MinimalOrganisationDto = exports.CampaignsEntitiesConfigDto = exports.IdDto = exports.PersistGoogleLinkerResultDto = exports.GetAuditorDto = exports.SwappingEnabledLinkTypes = exports.LinkEntityType = exports.LinkType = exports.AuditorOperation = exports.AuditorEntityType = exports.UniversitySchedulerCMAClient = exports.GeotarginatorFrontCMAClient = exports.PublicStatusClient = exports.ProductsCampaignManagementAPIClient = exports.LinksCampaignManagementAPIClient = exports.StudyCampaignManagementAPIClient = exports.UserCampaignManagementAPIClient = exports.PrivateUserCampaignManagementAPIClient = exports.PrivateCampaignManagementAPIClient = exports.CampaignManagementAPIClient = exports.OrganisationsCampaignManagementAPIClient = exports.AuditorCampaignManagementAPIClient = void 0;
17
+ exports.HttpError = exports.Pricing = exports.flattenEntityConfigs = exports.groupEntityConfigs = exports.MinimalOrganisationDto = exports.IdDto = exports.GetAuditorDto = exports.SwappingEnabledLinkTypes = exports.LinkEntityType = exports.LinkType = exports.AuditorOperation = exports.AuditorEntityType = exports.UniversitySchedulerCMAClient = exports.GeotarginatorFrontCMAClient = exports.PublicStatusClient = exports.ProductsCampaignManagementAPIClient = exports.LinksCampaignManagementAPIClient = exports.StudyCampaignManagementAPIClient = exports.UserCampaignManagementAPIClient = exports.PrivateUserCampaignManagementAPIClient = exports.PrivateCampaignManagementAPIClient = exports.CampaignManagementAPIClient = exports.OrganisationsCampaignManagementAPIClient = exports.AuditorCampaignManagementAPIClient = void 0;
18
18
  const auditor_campaign_management_api_client_1 = require("./src/auditor-campaign-management-api.client");
19
19
  Object.defineProperty(exports, "AuditorCampaignManagementAPIClient", { enumerable: true, get: function () { return auditor_campaign_management_api_client_1.AuditorCampaignManagementAPIClient; } });
20
+ const http_error_1 = require("./src/errors/http-error");
21
+ Object.defineProperty(exports, "HttpError", { enumerable: true, get: function () { return http_error_1.HttpError; } });
20
22
  const organisations_campaign_management_api_client_1 = require("./src/organisations-campaign-management-api.client");
21
23
  Object.defineProperty(exports, "OrganisationsCampaignManagementAPIClient", { enumerable: true, get: function () { return organisations_campaign_management_api_client_1.OrganisationsCampaignManagementAPIClient; } });
22
24
  const campaign_management_api_client_1 = require("./src/campaign-management-api.client");
@@ -27,8 +29,6 @@ const auditor_operation_enum_1 = require("./src/domain/auditor/enums/auditor-ope
27
29
  Object.defineProperty(exports, "AuditorOperation", { enumerable: true, get: function () { return auditor_operation_enum_1.AuditorOperation; } });
28
30
  const get_auditor_dto_1 = require("./src/domain/auditor/get-auditor.dto");
29
31
  Object.defineProperty(exports, "GetAuditorDto", { enumerable: true, get: function () { return get_auditor_dto_1.GetAuditorDto; } });
30
- const campaign_entities_config_dto_1 = require("./src/domain/campaign/campaign-entities-config.dto");
31
- Object.defineProperty(exports, "CampaignsEntitiesConfigDto", { enumerable: true, get: function () { return campaign_entities_config_dto_1.CampaignsEntitiesConfigDto; } });
32
32
  const geotargeting_entities_1 = require("./src/domain/auditor/campaigns/geotargeting.entities");
33
33
  Object.defineProperty(exports, "Pricing", { enumerable: true, get: function () { return geotargeting_entities_1.Pricing; } });
34
34
  const private_campaign_management_api_client_1 = require("./src/private-campaign-management-api.client");
@@ -41,8 +41,6 @@ const minimal_organisations_dto_1 = require("./src/domain/organisations/minimal-
41
41
  Object.defineProperty(exports, "MinimalOrganisationDto", { enumerable: true, get: function () { return minimal_organisations_dto_1.MinimalOrganisationDto; } });
42
42
  const link_type_enum_1 = require("./src/domain/studies/enums/link-type.enum");
43
43
  Object.defineProperty(exports, "LinkType", { enumerable: true, get: function () { return link_type_enum_1.LinkType; } });
44
- const persist_google_linker_result_dto_1 = require("./src/domain/campaign/persist-google-linker-result.dto");
45
- Object.defineProperty(exports, "PersistGoogleLinkerResultDto", { enumerable: true, get: function () { return persist_google_linker_result_dto_1.PersistGoogleLinkerResultDto; } });
46
44
  const link_entity_type_enum_1 = require("./src/domain/links/link-entity-type.enum");
47
45
  Object.defineProperty(exports, "LinkEntityType", { enumerable: true, get: function () { return link_entity_type_enum_1.LinkEntityType; } });
48
46
  const links_campaign_management_api_client_1 = require("./src/links-campaign-management-api.client");
@@ -70,5 +68,4 @@ __exportStar(require("./src/validation"), exports);
70
68
  __exportStar(require("./src/domain/organisations"), exports);
71
69
  __exportStar(require("./src/domain/products"), exports);
72
70
  __exportStar(require("./src/domain/degrees"), exports);
73
- __exportStar(require("./src/campaign-saving"), exports);
74
71
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,yGAAkG;AAmDjG,mHAnDQ,2EAAkC,OAmDR;AAlDnC,qHAA8G;AAmD7G,yHAnDQ,uFAAwC,OAmDR;AAlDzC,yFAAmF;AAmDlF,4GAnDQ,4DAA2B,OAmDR;AAlD5B,kGAAwF;AA8DvF,kGA9DQ,4CAAiB,OA8DR;AA7DlB,8FAAqF;AA8DpF,iGA9DQ,yCAAgB,OA8DR;AA7DjB,0EAAqE;AAmEpE,8FAnEQ,+BAAa,OAmER;AAlEd,qGAAgG;AAuE/F,2GAvEQ,yDA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fR bin && npx tsc",
6
6
  "test-u": "jest -c jest.config.unit.json --maxWorkers=1",
7
7
  "test-i": "nyc mocha src tests-i",
8
8
  "prepare-deployment": "npm run test-u && npm run compile && cp package.json bin/package.json && rm -fR bin/tests-u",
9
9
  "predeploy": "npm run prepare-deployment",
10
- "deploy": "npm publish ./bin --access=public",
10
+ "deploy": "npm publish ./bin --access=public --otp=123",
11
11
  "deploy-patch": "npm version patch && npm run deploy",
12
12
  "deploy-minor": "npm version minor && npm run deploy",
13
13
  "deploy-major": "npm version major && npm run deploy",
@@ -22,12 +22,10 @@
22
22
  "@types/chai": "^4.3.20",
23
23
  "@types/jest": "^29.5.14",
24
24
  "@types/node": "^22.19.7",
25
- "@types/superagent": "^8.1.9",
26
25
  "chai": "^4.5.0",
27
26
  "eslint": "^8.57.1",
28
27
  "jest": "^29.7.0",
29
28
  "jest-mock-extended": "^3.0.7",
30
- "superagent-mocker": "^0.5.2",
31
29
  "ts-jest": "^29.4.6",
32
30
  "ts-node": "^10.9.2",
33
31
  "typescript": "^5.9.3"
@@ -37,13 +35,12 @@
37
35
  "@aws-sdk/credential-provider-node": "^3.972.2",
38
36
  "@smithy/signature-v4": "^5.3.8",
39
37
  "@studyportals/mb-platform-date-time": "^1.3.1",
40
- "@studyportals/mb-platform-http-requests": "^2.8.0",
41
38
  "@studyportals/university-scheduler-interface": "^0.7.0",
39
+ "@studyportals/ws-client": "^0.3.1",
42
40
  "class-transformer": "^0.5.1",
43
41
  "class-validator": "^0.14.3",
44
42
  "inversify": "^6.2.2",
45
- "reflect-metadata": "^0.2.2",
46
- "superagent": "^8.1.2"
43
+ "reflect-metadata": "^0.2.2"
47
44
  },
48
45
  "engines": {
49
46
  "node": ">=18.x <=22.x",
@@ -6,11 +6,6 @@ export declare class AuditorCampaignManagementAPIClient {
6
6
  constructor(baseUrl: string);
7
7
  getCampaignAuditorData(campaignID: number, jwt?: string): Promise<GetAuditorDto[]>;
8
8
  getStudyAuditorData(studyID: number, jwt?: string): Promise<GetAuditorDto[]>;
9
- /**
10
- * @deprecated Auditing is now handled internally by CMA as part of write operations.
11
- * Use GeotarginatorFrontCMAClient.saveCampaignGeotargeting() instead—auditing is automatic.
12
- */
13
- storeCampaignAuditorData(operation: AuditorOperation, campaignID: number, username: string, isUserAction: boolean, data: any, jwt?: string): Promise<GetAuditorDto>;
14
9
  storeStudyAuditorData(operation: AuditorOperation, studyID: number, username: string, isUserAction: boolean, messageType: string, message: any, jwt?: string): Promise<GetAuditorDto>;
15
10
  storeStudiesAuditorData(operation: AuditorOperation, studyIDs: number[], username: string, isUserAction: boolean, messageType: string, message: any, jwt?: string): Promise<GetAuditorDto[]>;
16
11
  private getRequest;
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.AuditorCampaignManagementAPIClient = void 0;
13
13
  require("reflect-metadata");
14
14
  const inversify_1 = require("inversify");
15
- const superagent = require("superagent");
15
+ const http_request_1 = require("./utils/http-request");
16
16
  let AuditorCampaignManagementAPIClient = class AuditorCampaignManagementAPIClient {
17
17
  constructor(baseUrl) {
18
18
  this.baseUrl = baseUrl;
@@ -27,47 +27,27 @@ let AuditorCampaignManagementAPIClient = class AuditorCampaignManagementAPIClien
27
27
  const getAuditorDtos = result.body;
28
28
  return getAuditorDtos;
29
29
  }
30
- /**
31
- * @deprecated Auditing is now handled internally by CMA as part of write operations.
32
- * Use GeotarginatorFrontCMAClient.saveCampaignGeotargeting() instead—auditing is automatic.
33
- */
34
- async storeCampaignAuditorData(operation, campaignID, username, isUserAction, data, jwt = "") {
35
- const sendData = {
36
- "operation": operation,
37
- "entityID": campaignID,
38
- "username": username,
39
- "isUserAction": isUserAction,
40
- "data": data
41
- };
42
- const result = await this.postRequest(`auditor/campaigns`, sendData, jwt);
43
- return result.body;
44
- }
45
30
  async storeStudyAuditorData(operation, studyID, username, isUserAction, messageType, message, jwt = "") {
46
31
  const body = await this.storeStudiesAuditorData(operation, [studyID], username, isUserAction, messageType, message, jwt);
47
32
  return body[0];
48
33
  }
49
34
  async storeStudiesAuditorData(operation, studyIDs, username, isUserAction, messageType, message, jwt = "") {
50
35
  const sendData = {
51
- "operation": operation,
36
+ operation,
52
37
  "entityIDs": studyIDs,
53
- "username": username,
54
- "isUserAction": isUserAction,
55
- "messageType": messageType,
56
- "message": message
38
+ username,
39
+ isUserAction,
40
+ messageType,
41
+ message
57
42
  };
58
43
  const result = await this.postRequest(`auditor/studies`, sendData, jwt);
59
44
  return result.body;
60
45
  }
61
46
  async getRequest(relative = "", jwt = "") {
62
- return await superagent.get(this.buildBaseUrl(relative))
63
- .set("Content-Type", "application/json")
64
- .set("Authorization", jwt);
47
+ return (0, http_request_1.fetchJson)('GET', this.buildBaseUrl(relative), jwt);
65
48
  }
66
49
  async postRequest(relative = "", data, jwt = "") {
67
- return await superagent.post(this.buildBaseUrl(relative))
68
- .set("Content-Type", "application/json")
69
- .set("Authorization", jwt)
70
- .send(data);
50
+ return (0, http_request_1.fetchJson)('POST', this.buildBaseUrl(relative), jwt, data);
71
51
  }
72
52
  buildBaseUrl(relative) {
73
53
  return `${this.baseUrl}/${relative}`;
@@ -1 +1 @@
1
- {"version":3,"file":"auditor-campaign-management-api.client.js","sourceRoot":"","sources":["../../src/auditor-campaign-management-api.client.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4BAA0B;AAK1B,yCAAuC;AAEvC,yCAAyC;AAGlC,IAAM,kCAAkC,GAAxC,MAAM,kCAAkC;IAC3C,YACqB,OAAe;QAAf,YAAO,GAAP,OAAO,CAAQ;IAChC,CAAC;IAEE,KAAK,CAAC,sBAAsB,CAAC,UAAkB,EAAE,GAAG,GAAG,EAAE;QAC5D,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,qBAAqB,UAAU,EAAE,EAAE,GAAG,CAAC,CAAC;QAC7E,MAAM,cAAc,GAAG,MAAM,CAAC,IAAuB,CAAC;QAEtD,OAAO,cAAc,CAAC;IAC1B,CAAC;IAEM,KAAK,CAAC,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AQ;YACpB,cAAc,EAAE,YAAY;YAC5B,aAAa,EAAE,WAAW;YAC1B,SAAS,EAAE,OAAO;SACrB,CAAC;QAEF,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,iBAAiB,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC;QAExE,OAAO,MAAM,CAAC,IAAuB,CAAC;IAC1C,CAAC;IAGO,KAAK,CAAC,UAAU,CAAC,WAAmB,EAAE,EAAE,GAAG,GAAG,EAAE;QACpD,OAAO,MAAM,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;aACnD,GAAG,CAAC,cAAc,EAAE,kBAAkB,CAAC;aACvC,GAAG,CAAC,eAAe,EAAE,GAAG,CAAC,CAAC;IACnC,CAAC;IAEO,KAAK,CAAC,WAAW,CAAC,WAAmB,EAAE,EAAE,IAAS,EAAE,GAAG,GAAG,EAAE;QAChE,OAAO,MAAM,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;aACpD,GAAG,CAAC,cAAc,EAAE,kBAAkB,CAAC;aACvC,GAAG,CAAC,eAAe,EAAE,GAAG,CAAC;aACzB,IAAI,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC;IAEO,YAAY,CAAC,QAAgB;QACjC,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,QAAQ,EAAE,CAAC;IACzC,CAAC;CACJ,CAAA;AA1EY,gFAAkC;6CAAlC,kCAAkC;IAD9C,IAAA,sBAAU,GAAE;;GACA,kCAAkC,CA0E9C"}
1
+ {"version":3,"file":"auditor-campaign-management-api.client.js","sourceRoot":"","sources":["../../src/auditor-campaign-management-api.client.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4BAA0B;AAI1B,yCAAuC;AACvC,uDAAiD;AAG1C,IAAM,kCAAkC,GAAxC,MAAM,kCAAkC;IAC9C,YACwB,OAAe;QAAf,YAAO,GAAP,OAAO,CA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AuB,CAAC;IACvC,CAAC;IAGO,KAAK,CAAC,UAAU,CAAC,WAAmB,EAAE,EAAE,GAAG,GAAG,EAAE;QACvD,OAAO,IAAA,wBAAS,EAAC,KAAK,EAAE,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,EAAE,GAAG,CAAC,CAAC;IAC3D,CAAC;IAEO,KAAK,CAAC,WAAW,CAAC,WAAmB,EAAE,EAAE,IAAS,EAAE,GAAG,GAAG,EAAE;QACnE,OAAO,IAAA,wBAAS,EAAC,MAAM,EAAE,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;IAClE,CAAC;IAEO,YAAY,CAAC,QAAgB;QACpC,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,QAAQ,EAAE,CAAC;IACtC,CAAC;CACD,CAAA;AAnDY,gFAAkC;6CAAlC,kCAAkC;IAD9C,IAAA,sBAAU,GAAE;;GACA,kCAAkC,CAmD9C"}
@@ -1,5 +1,4 @@
1
1
  import "reflect-metadata";
2
- import { CampaignsEntitiesConfigDto } from "./domain/campaign/campaign-entities-config.dto";
3
2
  import { CampaignsDuplicatesDto } from "./domain/campaign/campaign-duplicates.dto";
4
3
  import { DuplicateCampaignDto } from "./domain/campaign/duplicate-campaign.dto";
5
4
  import { CampaignEditorGetResultDto } from "./domain/campaign/campaign-editor-get-result.dto";
@@ -9,35 +8,23 @@ import { CustomProductDto } from "./domain/campaign/custom-product.dto";
9
8
  import { ValidationStateResponse } from "./domain/campaign/validation-state.response";
10
9
  import { SearchUserDto } from "./domain/users";
11
10
  import { EnrichedCampaignGeotargetingDto } from "./domain/campaign/enriched-campaign-geotargeting.dto";
11
+ import type { EventBus } from "@studyportals/ws-client";
12
+ export type CampaignManagementAPIClientConfig = {
13
+ /** Max ms to wait for lambda 'start' acknowledgement before giving up. Default: 10 000. */
14
+ startAckTimeoutMs?: number;
15
+ /** Max ms to wait for 'success'/'failed' after 'start' was received. Default: 900 000. */
16
+ operationTimeoutMs?: number;
17
+ };
12
18
  export declare class CampaignManagementAPIClient {
13
19
  private readonly baseUrl;
14
- private connectionId;
15
- private ws;
16
- private pingInterval;
17
- private reconnectTimeout;
20
+ private readonly bus;
21
+ private readonly config;
18
22
  private pendingSaveOperations;
19
- private readonly PING_INTERVAL_MS;
20
- private readonly TEST_TIMEOUT_MS;
21
- private readonly LAMBDA_MAX_TIMEOUT_MS;
22
- constructor(baseUrl: string);
23
- private static readonly CMA_SUBDOMAIN_PREFIX;
24
- private initializeWebSocket;
25
- startWSConnection(wsUrl: string): void;
26
- private sendWhoAmI;
27
- private setupPingInterval;
28
- private clearPingInterval;
29
- private handleSavingEndMessage;
30
- /** Checks if API Gateway timed out, based on the status code */
31
- private is502BadGatewayError;
32
- getConnectionId(): string | undefined;
23
+ constructor(baseUrl: string, bus: EventBus, config?: CampaignManagementAPIClientConfig);
24
+ private readonly handleCampaignSavingPayload;
25
+ private readonly handleWsDisconnected;
33
26
  disconnect(): void;
34
27
  getCampaignDuplicates(campaigsnDuplicates: CampaignsDuplicatesDto, jwt?: string): Promise<DuplicateCampaignDto>;
35
- addCampaignsEntitiesConfigs(campaignID: number, campaignsEntitiesConfigs: CampaignsEntitiesConfigDto[], jwt?: string): Promise<void>;
36
- removeCampaignsEntitiesConfigsByID(campaignID: number, campaignsEntitiesConfigsIDs: number[], jwt?: string): Promise<void>;
37
- clearCampaignsEntitiesConfigsByCampaignID(campaignID: number, jwt?: string): Promise<void>;
38
- setEntitiesBasic(campaignID: number, organisationIDs: number[], studyIDs: number[], jwt?: string): Promise<void>;
39
- setEntitiesPremium(campaignID: number, organisationIDs: number[], studyIDs: number[], jwt?: string): Promise<void>;
40
- setEntitiesPersistGoogleLinkerProperty(organisationIds: number[], studyIds: number[], persistGoogleLinkerValue: boolean, jwt: string): Promise<void>;
41
28
  getCampaignForCampaignEditor(campaignID: number, jwt?: string): Promise<CampaignEditorGetResultDto>;
42
29
  getClientServicesUsers(jwt?: string): Promise<MinimalUserDto[]>;
43
30
  getAccountManagers(jwt?: string): Promise<MinimalUserDto[]>;
@@ -8,210 +8,78 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
- var CampaignManagementAPIClient_1;
12
11
  Object.defineProperty(exports, "__esModule", { value: true });
13
12
  exports.CampaignManagementAPIClient = void 0;
14
13
  require("reflect-metadata");
15
14
  const inversify_1 = require("inversify");
16
- const superagent = require("superagent");
17
15
  const mb_platform_date_time_1 = require("@studyportals/mb-platform-date-time");
18
16
  const ws_retrieved_error_1 = require("./errors/ws-retrieved-error");
19
- const campaign_saving_1 = require("./campaign-saving");
20
- let CampaignManagementAPIClient = CampaignManagementAPIClient_1 = class CampaignManagementAPIClient {
21
- constructor(baseUrl) {
17
+ const http_request_1 = require("./utils/http-request");
18
+ const DEFAULT_CONFIG = {
19
+ startAckTimeoutMs: 10000,
20
+ operationTimeoutMs: 900000,
21
+ };
22
+ let CampaignManagementAPIClient = class CampaignManagementAPIClient {
23
+ constructor(baseUrl, bus, config = {}) {
22
24
  this.baseUrl = baseUrl;
23
25
  this.pendingSaveOperations = new Map();
24
- this.PING_INTERVAL_MS = 8 * 60 * 1000; // 8 minutes
25
- this.TEST_TIMEOUT_MS = 5000; // 5 seconds for test environment
26
- this.LAMBDA_MAX_TIMEOUT_MS = 900000; // 900 seconds (15 minutes) for production
27
- this.initializeWebSocket();
28
- }
29
- initializeWebSocket() {
30
- // Convert HTTP(S) URL to WebSocket URL and add "ws." prefix.
31
- // If the base URL starts with the CMA subdomain, use "ws." prefix (e.g., "wss://ws.cma.tst.studyportals.eu").
32
- // Otherwise, use "ws" directly before the rest of the URL (e.g., "wss://ws515.cma.tst.studyportals.eu").
33
- const wsUrl = this.baseUrl.replace(/^https?:\/\//, '');
34
- const fullWsUrl = `wss://${wsUrl.startsWith(CampaignManagementAPIClient_1.CMA_SUBDOMAIN_PREFIX) ? `ws.${wsUrl}` : `ws${wsUrl}`}`;
35
- this.startWSConnection(fullWsUrl);
36
- }
37
- startWSConnection(wsUrl) {
38
- this.ws = new WebSocket(wsUrl);
39
- this.ws.addEventListener("open", () => {
40
- console.log("WebSocket connection opened");
41
- this.sendWhoAmI();
42
- this.setupPingInterval();
43
- });
44
- this.ws.addEventListener("message", (event) => {
45
- try {
46
- if (typeof event.data === 'string') {
47
- const response = JSON.parse(event.data);
48
- // Handle connectionId response
49
- if ("connectionId" in response) {
50
- this.connectionId = response.connectionId;
51
- console.log("Connection ID received:", this.connectionId);
26
+ this.handleCampaignSavingPayload = (payload) => {
27
+ const operationKey = 'campaign:saving';
28
+ const operation = this.pendingSaveOperations.get(operationKey);
29
+ if (!operation)
30
+ return;
31
+ if (payload.status === 'start') {
32
+ // Lambda acknowledged swap start-ack timeout for full operation timeout
33
+ clearTimeout(operation.timeoutHandle);
34
+ operation.timeoutHandle = setTimeout(() => {
35
+ if (this.pendingSaveOperations.has(operationKey)) {
36
+ this.pendingSaveOperations.delete(operationKey);
37
+ operation.reject(new Error('Campaign save operation timed out'));
52
38
  }
53
- // Handle topic responses
54
- else {
55
- this.handleSavingEndMessage(response);
56
- }
57
- }
58
- }
59
- catch (error) {
60
- console.error("Error parsing WebSocket message:", error);
61
- throw error;
39
+ }, this.config.operationTimeoutMs);
62
40
  }
63
- });
64
- this.ws.addEventListener("close", (event) => {
65
- console.log("WebSocket connection closed", event);
66
- this.clearPingInterval();
67
- // Reject all pending save operations
68
- const pendingOperations = Array.from(this.pendingSaveOperations.values());
69
- this.pendingSaveOperations.clear();
70
- const disconnectError = new Error('WebSocket connection was closed');
71
- pendingOperations.forEach(operation => operation.reject(disconnectError));
72
- // Attempt to reconnect after 5 seconds (only in non-test environment)
73
- if (process.env.NODE_ENV !== 'test') {
74
- this.reconnectTimeout = setTimeout(() => {
75
- this.initializeWebSocket();
76
- }, 5000);
77
- }
78
- });
79
- this.ws.addEventListener("error", (error) => {
80
- console.error("WebSocket error:", error);
81
- });
82
- }
83
- sendWhoAmI() {
84
- if (this.ws && this.ws.readyState === WebSocket.OPEN) {
85
- const message = { action: "who-am-I" };
86
- this.ws.send(JSON.stringify(message));
87
- }
88
- }
89
- setupPingInterval() {
90
- this.clearPingInterval();
91
- // Ping every 8 minutes (480,000 milliseconds) in production, but not in tests
92
- if (process.env.NODE_ENV !== 'test') {
93
- this.pingInterval = setInterval(() => {
94
- this.sendWhoAmI();
95
- }, this.PING_INTERVAL_MS);
96
- }
97
- }
98
- clearPingInterval() {
99
- if (this.pingInterval) {
100
- clearInterval(this.pingInterval);
101
- this.pingInterval = undefined;
102
- }
103
- }
104
- handleSavingEndMessage(response) {
105
- const operationTopic = response.topic;
106
- const operation = this.pendingSaveOperations.get(operationTopic);
107
- // Only process if HTTP hasn't already resolved this operation
108
- if (operation) {
109
- if (response.message.status === "success") {
110
- this.pendingSaveOperations.delete(operationTopic);
41
+ else if (payload.status === 'success') {
42
+ clearTimeout(operation.timeoutHandle);
43
+ this.pendingSaveOperations.delete(operationKey);
111
44
  operation.resolve();
112
45
  }
113
- else if (response.message.status === "failed") {
114
- const error = new ws_retrieved_error_1.WSRetrievedError(response.message.error);
115
- this.pendingSaveOperations.delete(operationTopic);
46
+ else if (payload.status === 'failed') {
47
+ clearTimeout(operation.timeoutHandle);
48
+ const error = new ws_retrieved_error_1.WSRetrievedError(payload.error);
49
+ this.pendingSaveOperations.delete(operationKey);
116
50
  operation.reject(error);
117
51
  }
118
- }
119
- }
120
- /** Checks if API Gateway timed out, based on the status code */
121
- is502BadGatewayError(error) {
122
- if (!error)
123
- return false;
124
- try {
125
- // Check direct status property
126
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
127
- if ('status' in error && error.status === 502)
128
- return true;
129
- // Check response.status property (common in HTTP libraries)
130
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
131
- if ('response' in error && error.response && 'status' in error.response && error.response.status === 502)
132
- return true;
133
- // Check message for 502 text
134
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
135
- if ('message' in error && typeof error.message === 'string' && error.message.includes('502'))
136
- return true;
137
- }
138
- catch (_a) {
139
- // If any error occurs during checking, return false
140
- return false;
141
- }
142
- return false;
143
- }
144
- getConnectionId() {
145
- return this.connectionId;
52
+ };
53
+ this.handleWsDisconnected = () => {
54
+ const pendingOperations = Array.from(this.pendingSaveOperations.values());
55
+ this.pendingSaveOperations.clear();
56
+ const disconnectError = new Error('WebSocket connection was closed');
57
+ pendingOperations.forEach(operation => {
58
+ clearTimeout(operation.timeoutHandle);
59
+ operation.reject(disconnectError);
60
+ });
61
+ };
62
+ this.config = Object.assign(Object.assign({}, DEFAULT_CONFIG), config);
63
+ this.bus = bus;
64
+ this.bus.on('campaign:saving', this.handleCampaignSavingPayload);
65
+ this.bus.on('ws:disconnected', this.handleWsDisconnected);
146
66
  }
147
67
  disconnect() {
148
- this.clearPingInterval();
149
- // Clear reconnect timeout
150
- if (this.reconnectTimeout) {
151
- clearTimeout(this.reconnectTimeout);
152
- this.reconnectTimeout = undefined;
153
- }
154
- // Reject all pending save operations
68
+ this.bus.off('campaign:saving', this.handleCampaignSavingPayload);
69
+ this.bus.off('ws:disconnected', this.handleWsDisconnected);
155
70
  const pendingOperations = Array.from(this.pendingSaveOperations.values());
156
71
  this.pendingSaveOperations.clear();
157
72
  const disconnectError = new Error('WebSocket connection was closed');
158
- pendingOperations.forEach(operation => operation.reject(disconnectError));
159
- if (this.ws) {
160
- this.ws.close();
161
- this.ws = undefined;
162
- }
163
- this.connectionId = undefined;
73
+ pendingOperations.forEach(operation => {
74
+ clearTimeout(operation.timeoutHandle);
75
+ operation.reject(disconnectError);
76
+ });
164
77
  }
165
78
  async getCampaignDuplicates(campaigsnDuplicates, jwt = '') {
166
79
  const path = `campaigns/get-duplicates`;
167
80
  const result = await this.postRequest(path, campaigsnDuplicates, jwt);
168
81
  return result.body;
169
82
  }
170
- async addCampaignsEntitiesConfigs(campaignID, campaignsEntitiesConfigs, jwt = '') {
171
- const path = `campaigns/add-campaigns-entities-configs`;
172
- const data = {
173
- campaignsEntitiesConfigs,
174
- campaignID
175
- };
176
- await this.postRequest(path, data, jwt);
177
- }
178
- async removeCampaignsEntitiesConfigsByID(campaignID, campaignsEntitiesConfigsIDs, jwt = '') {
179
- const path = `campaigns/remove-campaigns-entities-configs`;
180
- const data = { campaignsEntitiesConfigsIDs, campaignID };
181
- await this.postRequest(path, data, jwt);
182
- }
183
- async clearCampaignsEntitiesConfigsByCampaignID(campaignID, jwt = '') {
184
- const path = `campaigns/clear-campaigns-entities-configs`;
185
- const data = { campaignID };
186
- await this.postRequest(path, data, jwt);
187
- }
188
- async setEntitiesBasic(campaignID, organisationIDs, studyIDs, jwt = '') {
189
- const path = `campaigns/set-entities-basic`;
190
- const data = {
191
- organisationIDs,
192
- studyIDs,
193
- campaignID
194
- };
195
- await this.postRequest(path, data, jwt);
196
- }
197
- async setEntitiesPremium(campaignID, organisationIDs, studyIDs, jwt = '') {
198
- const path = `campaigns/set-entities-premium`;
199
- const data = {
200
- organisationIDs,
201
- studyIDs,
202
- campaignID
203
- };
204
- await this.postRequest(path, data, jwt);
205
- }
206
- async setEntitiesPersistGoogleLinkerProperty(organisationIds, studyIds, persistGoogleLinkerValue, jwt) {
207
- const path = `campaigns/set-entities-persist-google-linker`;
208
- const data = {
209
- organisationIds,
210
- studyIds,
211
- persistGoogleLinkerValue
212
- };
213
- await this.postRequest(path, data, jwt);
214
- }
215
83
  async getCampaignForCampaignEditor(campaignID, jwt = '') {
216
84
  const path = `campaigns/campaign-editor/${campaignID}`;
217
85
  const result = await this.getRequest(path, jwt);
@@ -235,38 +103,22 @@ let CampaignManagementAPIClient = CampaignManagementAPIClient_1 = class Campaign
235
103
  return parseInt(result.text);
236
104
  }
237
105
  async saveCampaign(campaignId, changes, jwt) {
238
- const path = `campaigns/${campaignId}/process-changes?connectionId=${this.connectionId}`;
239
- // Create a promise that resolves either from HTTP response or WebSocket message
240
- const savePromise = new Promise((resolve, reject) => {
241
- const operationTopic = campaign_saving_1.WebsocketLambdaTopics.CAMPAIGN_SAVING;
242
- // Store the operation for potential WebSocket response
243
- this.pendingSaveOperations.set(operationTopic, { resolve, reject });
244
- // Make the async POST request
245
- this.postRequest(path, changes, jwt)
246
- .catch((error) => {
247
- // Check if this is a 502 Bad Gateway (timeout scenario)
248
- const is502BadGateway = this.is502BadGatewayError(error);
249
- if (is502BadGateway) {
250
- // 502 Bad Gateway means the request timed out server-side
251
- // Continue waiting for WebSocket response, don't treat as error
252
- return;
253
- }
254
- // For other HTTP errors, fail immediately (takes priority over WebSocket)
255
- if (this.pendingSaveOperations.has(operationTopic)) {
256
- this.pendingSaveOperations.delete(operationTopic);
257
- reject(error instanceof Error ? error : new Error(String(error)));
258
- }
259
- });
260
- // Set a timeout for the entire operation (900 seconds (15 minutes) for HTTP + WebSocket)
261
- const timeout = process.env.NODE_ENV === 'test' ? this.TEST_TIMEOUT_MS : this.LAMBDA_MAX_TIMEOUT_MS;
262
- setTimeout(() => {
263
- if (this.pendingSaveOperations.has(operationTopic)) {
264
- this.pendingSaveOperations.delete(operationTopic);
265
- reject(new Error('Campaign save operation timed out'));
106
+ const path = `campaigns/${campaignId}/process-changes`;
107
+ const operationKey = 'campaign:saving';
108
+ if (this.pendingSaveOperations.has(operationKey)) {
109
+ throw new Error('A campaign save operation is already in progress');
110
+ }
111
+ await new Promise((resolve, reject) => {
112
+ const timeoutHandle = setTimeout(() => {
113
+ if (this.pendingSaveOperations.has(operationKey)) {
114
+ this.pendingSaveOperations.delete(operationKey);
115
+ reject(new Error('Campaign save operation timed out: lambda did not acknowledge'));
266
116
  }
267
- }, timeout);
117
+ }, this.config.startAckTimeoutMs);
118
+ this.pendingSaveOperations.set(operationKey, { resolve, reject, timeoutHandle });
119
+ // Fire-and-forget — resolution driven entirely by WebSocket message
120
+ void this.postRequest(path, changes, jwt).catch(() => { });
268
121
  });
269
- await savePromise;
270
122
  }
271
123
  async getCustomProducts(campaignID, jwt = '') {
272
124
  const path = `campaigns/campaign-editor/custom-products/${campaignID}`;
@@ -298,25 +150,18 @@ let CampaignManagementAPIClient = CampaignManagementAPIClient_1 = class Campaign
298
150
  return result.body;
299
151
  }
300
152
  async postRequest(relative = "", data, jwt = "") {
301
- const request = superagent.post(this.buildBaseUrl(relative))
302
- .set("Content-Type", "application/json")
303
- .set("Authorization", jwt);
304
- return await request.send(data);
153
+ return (0, http_request_1.fetchJson)('POST', this.buildBaseUrl(relative), jwt, data);
305
154
  }
306
155
  async getRequest(relative = "", jwt = "") {
307
- const request = superagent.get(this.buildBaseUrl(relative))
308
- .set("Content-Type", "application/json")
309
- .set("Authorization", jwt);
310
- return await request;
156
+ return (0, http_request_1.fetchJson)('GET', this.buildBaseUrl(relative), jwt);
311
157
  }
312
158
  buildBaseUrl(relative) {
313
159
  return `${this.baseUrl}/${relative}`;
314
160
  }
315
161
  };
316
162
  exports.CampaignManagementAPIClient = CampaignManagementAPIClient;
317
- CampaignManagementAPIClient.CMA_SUBDOMAIN_PREFIX = 'cma.';
318
- exports.CampaignManagementAPIClient = CampaignManagementAPIClient = CampaignManagementAPIClient_1 = __decorate([
163
+ exports.CampaignManagementAPIClient = CampaignManagementAPIClient = __decorate([
319
164
  (0, inversify_1.injectable)(),
320
- __metadata("design:paramtypes", [String])
165
+ __metadata("design:paramtypes", [String, Object, Object])
321
166
  ], CampaignManagementAPIClient);
322
167
  //# sourceMappingURL=campaign-management-api.client.js.map