@ampsec/platform-client 55.5.0 → 55.6.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.
@@ -6,6 +6,7 @@ import { PlatformJobExecutionStateDto, PlatformJobExecutionStateUpsertDto } from
6
6
  import { EnumService } from './rest/EnumService';
7
7
  import { AmpSdkSettingsService } from './settings.service';
8
8
  import { AmpSaaSEntityService, AmpSdkSaasAssetService, AmpSdkSaasComponentService, AmpSdkSaasUserService } from './saasEntity.service';
9
+ import { ContentfulService } from './contentful.service';
9
10
  export type AmpSdkOptions = AmpRestClientOptions;
10
11
  /**
11
12
  * AMP API
@@ -20,6 +21,7 @@ export declare class AmpSdkServices {
20
21
  readonly agents: AmpEntityService<PlatformAgentUpsertDto, PlatformAgentDto>;
21
22
  readonly asset: AmpSdkAssetService;
22
23
  readonly connectors: AmpEntityService<PlatformConnectorUpsertDto, PlatformConnectorDto>;
24
+ readonly contentful: ContentfulService;
23
25
  readonly enums: EnumService;
24
26
  readonly findings: AmpSaaSEntityService<PlatformFindingUpsertDto, PlatformFindingDto>;
25
27
  readonly jobExecutions: AmpEntityService<PlatformJobExecutionStateUpsertDto, PlatformJobExecutionStateDto>;
@@ -7,6 +7,7 @@ const constants_1 = require("./constants");
7
7
  const EnumService_1 = require("./rest/EnumService");
8
8
  const settings_service_1 = require("./settings.service");
9
9
  const saasEntity_service_1 = require("./saasEntity.service");
10
+ const contentful_service_1 = require("./contentful.service");
10
11
  /**
11
12
  * AMP API
12
13
  * This client is a wrapper around the AMP REST API meant to be used by
@@ -21,6 +22,7 @@ class AmpSdkServices {
21
22
  this.agents = new entity_service_1.AmpEntityServiceImpl(rest, constants_1.KIND.AGENTS, constants_1.TARGET_API_PLATFORM);
22
23
  this.asset = new entity_service_1.AmpSdkAssetService(rest, constants_1.TARGET_API_PLATFORM);
23
24
  this.connectors = new entity_service_1.AmpEntityServiceImpl(rest, constants_1.KIND.CONNECTORS, constants_1.TARGET_API_PLATFORM);
25
+ this.contentful = new contentful_service_1.ContentfulService();
24
26
  this.enums = new EnumService_1.DefaultEnumService(rest, constants_1.TARGET_API_PLATFORM);
25
27
  this.findings = new saasEntity_service_1.AmpSaaSEntityServiceImpl(rest, constants_1.KIND.FINDINGS, constants_1.TARGET_API_PLATFORM);
26
28
  this.jobExecutions = new entity_service_1.AmpEntityServiceImpl(rest, constants_1.KIND.JOB_EXECUTIONS, constants_1.TARGET_API_PLATFORM);
@@ -1 +1 @@
1
- {"version":3,"file":"AmpSdk.js","sourceRoot":"","sources":["../../../src/services/AmpSdk.ts"],"names":[],"mappings":";;;AAoBA,qDAAoI;AACpI,iCAA0E;AAC1E,2CAAsD;AAGtD,oDAAmE;AACnE,yDAAyD;AACzD,6DAA+J;AAI/J;;;;;;;;GAQG;AACH,MAAa,cAAc;IAoBzB,YAAY,IAAgB;QAC1B,IAAI,CAAC,MAAM,GAAG,IAAI,qCAAoB,CAA2C,IAAI,EAAE,gBAAI,CAAC,MAAM,EAAE,+BAAmB,CAAC,CAAC;QACzH,IAAI,CAAC,KAAK,GAAG,IAAI,mCAAkB,CAAC,IAAI,EAAE,+BAAmB,CAAC,CAAC;QAC/D,IAAI,CAAC,UAAU,GAAG,IAAI,qCAAoB,CAAmD,IAAI,EAAE,gBAAI,CAAC,UAAU,EAAE,+BAAmB,CAAC,CAAC;QACzI,IAAI,CAAC,KAAK,GAAG,IAAI,gCAAkB,CAAC,IAAI,EAAE,+BAAmB,CAAC,CAAC;QAC/D,IAAI,CAAC,QAAQ,GAAG,IAAI,6CAAwB,CAA+C,IAAI,EAAE,gBAAI,CAAC,QAAQ,EAAE,+BAAmB,CAAC,CAAC;QACrI,IAAI,CAAC,aAAa,GAAG,IAAI,qCAAoB,CAAmE,IAAI,EAAE,gBAAI,CAAC,cAAc,EAAE,+BAAmB,CAAC,CAAC;QAChK,IAAI,CAAC,IAAI,GAAG,IAAI,qCAAoB,CAA+C,IAAI,EAAE,gBAAI,CAAC,QAAQ,EAAE,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qCAAoB,CAAyC,IAAI,EAAE,gBAAI,CAAC,SAAS,EAAE,+BAAmB,CAAC,CAAC;QAC7H,IAAI,CAAC,aAAa,GAAG,IAAI,6CAAwB,CAAyD,IAAI,EAAE,gBAAI,CAAC,cAAc,EAAE,+BAAmB,CAAC,CAAC;QAC1J,IAAI,CAAC,gBAAgB,GAAG,IAAI,6CAAwB,CAA+D,IAAI,EAAE,gBAAI,CAAC,iBAAiB,EAAE,+BAAmB,CAAC,CAAC;QACtK,IAAI,CAAC,UAAU,GAAG,IAAI,2CAAsB,CAAC,IAAI,EAAE,+BAAmB,CAAC,CAAC;QACxE,IAAI,CAAC,cAAc,GAAG,IAAI,+CAA0B,CAAC,IAAI,EAAE,+BAAmB,CAAC,CAAC;QAChF,IAAI,CAAC,SAAS,GAAG,IAAI,0CAAqB,CAAC,IAAI,EAAE,+BAAmB,CAAC,CAAC;QACtE,IAAI,CAAC,QAAQ,GAAG,IAAI,wCAAqB,CAAC,IAAI,CAAC,CAAC;QAChD,IAAI,CAAC,OAAO,GAAG,IAAI,qCAAoB,CAA6B,IAAI,EAAE,gBAAI,CAAC,OAAO,EAAE,+BAAmB,CAAC,CAAC;QAC7G,IAAI,CAAC,KAAK,GAAG,IAAI,kCAAiB,CAAC,IAAI,EAAE,+BAAmB,CAAC,CAAC;QAC9D,IAAI,CAAC,iBAAiB,GAAG,IAAI,qCAAoB,CAAiE,IAAI,EAAE,gBAAI,CAAC,iBAAiB,EAAE,+BAAmB,CAAC,CAAC;IACvK,CAAC;IAED,MAAM,CAAC,QAAQ,CAAC,OAAsB;QACpC,MAAM,IAAI,GAAG,IAAA,uBAAgB,EAAC,OAAO,CAAC,CAAC;QACvC,OAAO,IAAI,cAAc,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;CACF;AA/CD,wCA+CC"}
@@ -0,0 +1,36 @@
1
+ import type { Entry, EntrySkeletonType, EntryFieldTypes, EntryCollection } from 'contentful/dist/types';
2
+ import * as contentful from 'contentful';
3
+ export type MessageTemplate = EntrySkeletonType & {
4
+ contentTypeId: 'messageTemplate';
5
+ fields: {
6
+ id: EntryFieldTypes.Text;
7
+ body: EntryFieldTypes.Text;
8
+ subject: EntryFieldTypes.Text;
9
+ callToActionsCsv: EntryFieldTypes.Text;
10
+ };
11
+ };
12
+ /**
13
+ * ContentfulService
14
+ *
15
+ * This client is a wrapper around the Contentful REST API meant to be used by
16
+ * service accounts, i.e. plugins and platform extensions. This class requires
17
+ * the following environment variables to be set:
18
+ * - CONTENTFUL_SPACE_ID
19
+ * - CONTENTFUL_ACCESS_TOKEN
20
+ * If these are not set, a warning will be logged.
21
+ **/
22
+ export declare class ContentfulService {
23
+ protected readonly contentfulClient: contentful.ContentfulClientApi<undefined>;
24
+ /**
25
+ * This contructs the ContentfulService. The following environment variables
26
+ * must be set:
27
+ * - CONTENTFUL_SPACE_ID
28
+ * - CONTENTFUL_ACCESS_TOKEN
29
+ *
30
+ * These can be found in Contentful under Settings > API Keys
31
+ */
32
+ constructor();
33
+ getMessageTemplates: () => Promise<EntryCollection<MessageTemplate>>;
34
+ getContentfulEntries: <T extends EntrySkeletonType>(contentType: string, include?: number) => Promise<EntryCollection<T>>;
35
+ getContentfulEntry: <T extends EntrySkeletonType>(entryId: string) => Promise<Entry<T>>;
36
+ }
@@ -0,0 +1,73 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.ContentfulService = void 0;
27
+ const contentful = __importStar(require("contentful"));
28
+ /**
29
+ * ContentfulService
30
+ *
31
+ * This client is a wrapper around the Contentful REST API meant to be used by
32
+ * service accounts, i.e. plugins and platform extensions. This class requires
33
+ * the following environment variables to be set:
34
+ * - CONTENTFUL_SPACE_ID
35
+ * - CONTENTFUL_ACCESS_TOKEN
36
+ * If these are not set, a warning will be logged.
37
+ **/
38
+ class ContentfulService {
39
+ /**
40
+ * This contructs the ContentfulService. The following environment variables
41
+ * must be set:
42
+ * - CONTENTFUL_SPACE_ID
43
+ * - CONTENTFUL_ACCESS_TOKEN
44
+ *
45
+ * These can be found in Contentful under Settings > API Keys
46
+ */
47
+ constructor() {
48
+ this.getMessageTemplates = async () => {
49
+ const messageTemplates = await this.getContentfulEntries('messageTemplate', 0);
50
+ return messageTemplates;
51
+ };
52
+ this.getContentfulEntries = async (contentType, include) => {
53
+ const entries = await this.contentfulClient.getEntries({
54
+ content_type: contentType,
55
+ ...(include ? { include } : {}),
56
+ });
57
+ return entries;
58
+ };
59
+ this.getContentfulEntry = async (entryId) => {
60
+ const entry = await this.contentfulClient.getEntry(entryId);
61
+ return entry;
62
+ };
63
+ if (!process.env.CONTENTFUL_SPACE_ID || !process.env.CONTENTFUL_ACCESS_TOKEN) {
64
+ console.warn('CONTENTFUL_SPACE_ID and CONTENTFUL_ACCESS_TOKEN must be set in the environment');
65
+ }
66
+ this.contentfulClient = contentful.createClient({
67
+ space: process.env.CONTENTFUL_SPACE_ID || '',
68
+ accessToken: process.env.CONTENTFUL_ACCESS_TOKEN || '',
69
+ });
70
+ }
71
+ }
72
+ exports.ContentfulService = ContentfulService;
73
+ //# sourceMappingURL=contentful.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contentful.service.js","sourceRoot":"","sources":["../../../src/services/contentful.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,uDAAyC;AAYzC;;;;;;;;;IASI;AACJ,MAAa,iBAAiB;IAE5B;;;;;;;OAOG;IACH;QAWA,wBAAmB,GAAG,KAAK,IAA+C,EAAE;YAC1E,MAAM,gBAAgB,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAAkB,iBAAiB,EAAE,CAAC,CAAC,CAAC;YAChG,OAAO,gBAAgB,CAAC;QAC1B,CAAC,CAAC;QAEF,yBAAoB,GAAG,KAAK,EAA+B,WAAmB,EAAE,OAAgB,EAA+B,EAAE;YAC/H,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,UAAU,CAAI;gBACxD,YAAY,EAAE,WAAW;gBACzB,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAC,OAAO,EAAC,CAAC,CAAC,CAAC,EAAE,CAAC;aAC9B,CAAC,CAAC;YACH,OAAO,OAAO,CAAC;QACjB,CAAC,CAAC;QAEF,uBAAkB,GAAG,KAAK,EAA+B,OAAe,EAAqB,EAAE;YAC7F,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAI,OAAO,CAAC,CAAC;YAC/D,OAAO,KAAK,CAAC;QACf,CAAC,CAAC;QA1BA,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,uBAAuB,EAAE;YAC5E,OAAO,CAAC,IAAI,CAAC,gFAAgF,CAAC,CAAC;SAChG;QAED,IAAI,CAAC,gBAAgB,GAAG,UAAU,CAAC,YAAY,CAAC;YAC9C,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,mBAAmB,IAAI,EAAE;YAC5C,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,uBAAuB,IAAI,EAAE;SACvD,CAAC,CAAC;IACL,CAAC;CAmBF;AAtCD,8CAsCC"}
@@ -13,3 +13,4 @@ export * from './utils';
13
13
  export * from './connectors.service';
14
14
  export * from './notification.service';
15
15
  export * from './reports.service';
16
+ export * from './contentful.service';
@@ -29,4 +29,5 @@ __exportStar(require("./utils"), exports);
29
29
  __exportStar(require("./connectors.service"), exports);
30
30
  __exportStar(require("./notification.service"), exports);
31
31
  __exportStar(require("./reports.service"), exports);
32
+ __exportStar(require("./contentful.service"), exports);
32
33
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,8CAA4B;AAC5B,2CAAyB;AACzB,8CAA4B;AAC5B,iDAA+B;AAC/B,mDAAiC;AACjC,qDAAmC;AACnC,mDAAiC;AACjC,yCAAuB;AACvB,uDAAqC;AACrC,qDAAmC;AACnC,0CAAwB;AACxB,uDAAqC;AACrC,yDAAuC;AACvC,oDAAkC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/services/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,8CAA4B;AAC5B,2CAAyB;AACzB,8CAA4B;AAC5B,iDAA+B;AAC/B,mDAAiC;AACjC,qDAAmC;AACnC,mDAAiC;AACjC,yCAAuB;AACvB,uDAAqC;AACrC,qDAAmC;AACnC,0CAAwB;AACxB,uDAAqC;AACrC,yDAAuC;AACvC,oDAAkC;AAClC,uDAAqC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ampsec/platform-client",
3
- "version": "55.5.0",
3
+ "version": "55.6.1",
4
4
  "description": "",
5
5
  "main": "build/src/index.js",
6
6
  "runkitExampleFilename": "example/main.js",
@@ -24,6 +24,7 @@
24
24
  "dependencies": {
25
25
  "axios": "^1.4.0",
26
26
  "blueimp-md5": "^2.19.0",
27
+ "contentful": "^10.6.9",
27
28
  "immutable": "^5.0.0-beta.4",
28
29
  "lodash": "^4.17.21",
29
30
  "lodash.omit": "^4.5.0",
@@ -26,6 +26,7 @@ import {PlatformJobExecutionStateDto, PlatformJobExecutionStateUpsertDto} from '
26
26
  import {DefaultEnumService, EnumService} from './rest/EnumService';
27
27
  import {AmpSdkSettingsService} from './settings.service';
28
28
  import {AmpSaaSEntityService, AmpSaaSEntityServiceImpl, AmpSdkSaasAssetService, AmpSdkSaasComponentService, AmpSdkSaasUserService} from './saasEntity.service';
29
+ import {ContentfulService} from './contentful.service';
29
30
 
30
31
  export type AmpSdkOptions = AmpRestClientOptions;
31
32
 
@@ -42,6 +43,7 @@ export class AmpSdkServices {
42
43
  readonly agents: AmpEntityService<PlatformAgentUpsertDto, PlatformAgentDto>;
43
44
  readonly asset: AmpSdkAssetService;
44
45
  readonly connectors: AmpEntityService<PlatformConnectorUpsertDto, PlatformConnectorDto>;
46
+ readonly contentful: ContentfulService;
45
47
  readonly enums: EnumService;
46
48
  readonly findings: AmpSaaSEntityService<PlatformFindingUpsertDto, PlatformFindingDto>;
47
49
  readonly jobExecutions: AmpEntityService<PlatformJobExecutionStateUpsertDto, PlatformJobExecutionStateDto>;
@@ -62,6 +64,7 @@ export class AmpSdkServices {
62
64
  this.agents = new AmpEntityServiceImpl<PlatformAgentUpsertDto, PlatformAgentDto>(rest, KIND.AGENTS, TARGET_API_PLATFORM);
63
65
  this.asset = new AmpSdkAssetService(rest, TARGET_API_PLATFORM);
64
66
  this.connectors = new AmpEntityServiceImpl<PlatformConnectorUpsertDto, PlatformConnectorDto>(rest, KIND.CONNECTORS, TARGET_API_PLATFORM);
67
+ this.contentful = new ContentfulService();
65
68
  this.enums = new DefaultEnumService(rest, TARGET_API_PLATFORM);
66
69
  this.findings = new AmpSaaSEntityServiceImpl<PlatformFindingUpsertDto, PlatformFindingDto>(rest, KIND.FINDINGS, TARGET_API_PLATFORM);
67
70
  this.jobExecutions = new AmpEntityServiceImpl<PlatformJobExecutionStateUpsertDto, PlatformJobExecutionStateDto>(rest, KIND.JOB_EXECUTIONS, TARGET_API_PLATFORM);
@@ -0,0 +1,62 @@
1
+ import type {Entry, EntrySkeletonType, EntryFieldTypes, EntryCollection} from 'contentful/dist/types';
2
+ import * as contentful from 'contentful';
3
+
4
+ export type MessageTemplate = EntrySkeletonType & {
5
+ contentTypeId: 'messageTemplate';
6
+ fields: {
7
+ id: EntryFieldTypes.Text;
8
+ body: EntryFieldTypes.Text;
9
+ subject: EntryFieldTypes.Text;
10
+ callToActionsCsv: EntryFieldTypes.Text;
11
+ };
12
+ };
13
+
14
+ /**
15
+ * ContentfulService
16
+ *
17
+ * This client is a wrapper around the Contentful REST API meant to be used by
18
+ * service accounts, i.e. plugins and platform extensions. This class requires
19
+ * the following environment variables to be set:
20
+ * - CONTENTFUL_SPACE_ID
21
+ * - CONTENTFUL_ACCESS_TOKEN
22
+ * If these are not set, a warning will be logged.
23
+ **/
24
+ export class ContentfulService {
25
+ protected readonly contentfulClient;
26
+ /**
27
+ * This contructs the ContentfulService. The following environment variables
28
+ * must be set:
29
+ * - CONTENTFUL_SPACE_ID
30
+ * - CONTENTFUL_ACCESS_TOKEN
31
+ *
32
+ * These can be found in Contentful under Settings > API Keys
33
+ */
34
+ constructor() {
35
+ if (!process.env.CONTENTFUL_SPACE_ID || !process.env.CONTENTFUL_ACCESS_TOKEN) {
36
+ console.warn('CONTENTFUL_SPACE_ID and CONTENTFUL_ACCESS_TOKEN must be set in the environment');
37
+ }
38
+
39
+ this.contentfulClient = contentful.createClient({
40
+ space: process.env.CONTENTFUL_SPACE_ID || '',
41
+ accessToken: process.env.CONTENTFUL_ACCESS_TOKEN || '',
42
+ });
43
+ }
44
+
45
+ getMessageTemplates = async (): Promise<EntryCollection<MessageTemplate>> => {
46
+ const messageTemplates = await this.getContentfulEntries<MessageTemplate>('messageTemplate', 0);
47
+ return messageTemplates;
48
+ };
49
+
50
+ getContentfulEntries = async <T extends EntrySkeletonType>(contentType: string, include?: number): Promise<EntryCollection<T>> => {
51
+ const entries = await this.contentfulClient.getEntries<T>({
52
+ content_type: contentType,
53
+ ...(include ? {include} : {}),
54
+ });
55
+ return entries;
56
+ };
57
+
58
+ getContentfulEntry = async <T extends EntrySkeletonType>(entryId: string): Promise<Entry<T>> => {
59
+ const entry = await this.contentfulClient.getEntry<T>(entryId);
60
+ return entry;
61
+ };
62
+ }
@@ -13,3 +13,4 @@ export * from './utils';
13
13
  export * from './connectors.service';
14
14
  export * from './notification.service';
15
15
  export * from './reports.service';
16
+ export * from './contentful.service';