@ampsec/platform-client 79.4.1 → 79.5.0

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.
@@ -1,4 +1,5 @@
1
1
  export declare enum EngagementChannelKind {
2
2
  SLACK = "SLACK",
3
- CHROME_EXTENSION = "CHROME_EXTENSION"
3
+ CHROME_EXTENSION = "CHROME_EXTENSION",
4
+ TEAMS = "TEAMS"
4
5
  }
@@ -5,5 +5,6 @@ var EngagementChannelKind;
5
5
  (function (EngagementChannelKind) {
6
6
  EngagementChannelKind["SLACK"] = "SLACK";
7
7
  EngagementChannelKind["CHROME_EXTENSION"] = "CHROME_EXTENSION";
8
+ EngagementChannelKind["TEAMS"] = "TEAMS";
8
9
  })(EngagementChannelKind || (exports.EngagementChannelKind = EngagementChannelKind = {}));
9
10
  //# sourceMappingURL=engagementChannelKind.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"engagementChannelKind.js","sourceRoot":"","sources":["../../../../src/dto/enums/engagementChannelKind.ts"],"names":[],"mappings":";;;AAAA,IAAY,qBAGX;AAHD,WAAY,qBAAqB;IAC/B,wCAAe,CAAA;IACf,8DAAqC,CAAA;AACvC,CAAC,EAHW,qBAAqB,qCAArB,qBAAqB,QAGhC"}
1
+ {"version":3,"file":"engagementChannelKind.js","sourceRoot":"","sources":["../../../../src/dto/enums/engagementChannelKind.ts"],"names":[],"mappings":";;;AAAA,IAAY,qBAIX;AAJD,WAAY,qBAAqB;IAC/B,wCAAe,CAAA;IACf,8DAAqC,CAAA;IACrC,wCAAe,CAAA;AACjB,CAAC,EAJW,qBAAqB,qCAArB,qBAAqB,QAIhC"}
@@ -1 +1,8 @@
1
1
  export declare const fillJsonPathTemplate: (raw: string, meta: unknown) => string;
2
+ /**
3
+ * @param rawTemplateString Template string with placeholders in the format of {{path.to.value}}
4
+ * @param meta object containing the values to replace the placeholders
5
+ * @returns string with placeholders replaced with values from the meta object
6
+ * @note Ensure that meta object does not contain any information that should not be exposed to end users
7
+ */
8
+ export declare const fillDynamicPropertyTemplate: (rawTemplateString: string, meta: unknown) => string;
@@ -3,9 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.fillJsonPathTemplate = void 0;
6
+ exports.fillDynamicPropertyTemplate = exports.fillJsonPathTemplate = void 0;
7
7
  const lodash_1 = __importDefault(require("lodash"));
8
8
  const JSON_PATH_PATTERN = /(\$\.(?:(?:[a-zA-Z0-9_]+)(?:\.[a-zA-Z0-9_]+)*)?)/g;
9
+ const DYNAMIC_PROPERTY_PATTERN = /\{\{([^}]+)\}\}/g;
10
+ // @deprecated : consider using fillDynamicPropertyTemplate
9
11
  const fillJsonPathTemplate = (raw, meta) => {
10
12
  const jsonPathMatches = raw.match(JSON_PATH_PATTERN);
11
13
  let result = raw;
@@ -22,4 +24,34 @@ const fillJsonPathTemplate = (raw, meta) => {
22
24
  return result;
23
25
  };
24
26
  exports.fillJsonPathTemplate = fillJsonPathTemplate;
27
+ /**
28
+ * @param rawTemplateString Template string with placeholders in the format of {{path.to.value}}
29
+ * @param meta object containing the values to replace the placeholders
30
+ * @returns string with placeholders replaced with values from the meta object
31
+ * @note Ensure that meta object does not contain any information that should not be exposed to end users
32
+ */
33
+ const fillDynamicPropertyTemplate = (rawTemplateString, meta) => {
34
+ let result = rawTemplateString;
35
+ const matches = rawTemplateString.match(DYNAMIC_PROPERTY_PATTERN);
36
+ if (matches) {
37
+ matches.forEach(placeholder => {
38
+ const path = placeholder.slice(2, -2).trim();
39
+ const value = lodash_1.default.get(meta, path, undefined);
40
+ if (lodash_1.default.isString(value) || lodash_1.default.isNumber(value) || lodash_1.default.isBoolean(value)) {
41
+ // primitive value type is replaced as is
42
+ result = result.replace(placeholder, value);
43
+ }
44
+ else if (lodash_1.default.isObject(value) || lodash_1.default.isArray(value)) {
45
+ // object and array values are stringified
46
+ result = result.replace(placeholder, JSON.stringify(value, null, 2));
47
+ }
48
+ else {
49
+ // unknown value type is replaced with a placeholder
50
+ result = result.replace(placeholder, 'UNKNOWN_TEMPLATE_VALUE');
51
+ }
52
+ });
53
+ }
54
+ return result;
55
+ };
56
+ exports.fillDynamicPropertyTemplate = fillDynamicPropertyTemplate;
25
57
  //# sourceMappingURL=ContentTemplateService.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ContentTemplateService.js","sourceRoot":"","sources":["../../../src/services/ContentTemplateService.ts"],"names":[],"mappings":";;;;;;AAAA,oDAAuB;AACvB,MAAM,iBAAiB,GAAG,mDAAmD,CAAC;AAEvE,MAAM,oBAAoB,GAAG,CAAC,GAAW,EAAE,IAAa,EAAE,EAAE;IACjE,MAAM,eAAe,GAAG,GAAG,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrD,IAAI,MAAM,GAAG,GAAG,CAAC;IACjB,IAAI,eAAe,EAAE,CAAC;QACpB,eAAe,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;YACjC,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YACxC,IAAI,KAAK,GAAG,gBAAC,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;YACnC,IAAI,CAAC,gBAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;gBACvB,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;YAChC,CAAC;YACD,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAdW,QAAA,oBAAoB,wBAc/B"}
1
+ {"version":3,"file":"ContentTemplateService.js","sourceRoot":"","sources":["../../../src/services/ContentTemplateService.ts"],"names":[],"mappings":";;;;;;AAAA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KAAK,GAAG,gBAAC,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;YAC3C,IAAI,gBAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,gBAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,gBAAC,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;gBACjE,yCAAyC;gBACzC,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;YAC9C,CAAC;iBAAM,IAAI,gBAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,gBAAC,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;gBACjD,0CAA0C;gBAC1C,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YACvE,CAAC;iBAAM,CAAC;gBACN,oDAAoD;gBACpD,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,wBAAwB,CAAC,CAAC;YACjE,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AApBW,QAAA,2BAA2B,+BAoBtC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ampsec/platform-client",
3
- "version": "79.4.1",
3
+ "version": "79.5.0",
4
4
  "description": "",
5
5
  "main": "build/src/index.js",
6
6
  "runkitExampleFilename": "example/main.js",
@@ -1,4 +1,5 @@
1
1
  export enum EngagementChannelKind {
2
2
  SLACK = 'SLACK',
3
3
  CHROME_EXTENSION = 'CHROME_EXTENSION',
4
+ TEAMS = 'TEAMS',
4
5
  }
@@ -1,6 +1,8 @@
1
1
  import _ from 'lodash';
2
2
  const JSON_PATH_PATTERN = /(\$\.(?:(?:[a-zA-Z0-9_]+)(?:\.[a-zA-Z0-9_]+)*)?)/g;
3
+ const DYNAMIC_PROPERTY_PATTERN = /\{\{([^}]+)\}\}/g;
3
4
 
5
+ // @deprecated : consider using fillDynamicPropertyTemplate
4
6
  export const fillJsonPathTemplate = (raw: string, meta: unknown) => {
5
7
  const jsonPathMatches = raw.match(JSON_PATH_PATTERN);
6
8
  let result = raw;
@@ -16,3 +18,31 @@ export const fillJsonPathTemplate = (raw: string, meta: unknown) => {
16
18
  }
17
19
  return result;
18
20
  };
21
+
22
+ /**
23
+ * @param rawTemplateString Template string with placeholders in the format of {{path.to.value}}
24
+ * @param meta object containing the values to replace the placeholders
25
+ * @returns string with placeholders replaced with values from the meta object
26
+ * @note Ensure that meta object does not contain any information that should not be exposed to end users
27
+ */
28
+ export const fillDynamicPropertyTemplate = (rawTemplateString: string, meta: unknown) => {
29
+ let result = rawTemplateString;
30
+ const matches = rawTemplateString.match(DYNAMIC_PROPERTY_PATTERN);
31
+ if (matches) {
32
+ matches.forEach(placeholder => {
33
+ const path = placeholder.slice(2, -2).trim();
34
+ const value = _.get(meta, path, undefined);
35
+ if (_.isString(value) || _.isNumber(value) || _.isBoolean(value)) {
36
+ // primitive value type is replaced as is
37
+ result = result.replace(placeholder, value);
38
+ } else if (_.isObject(value) || _.isArray(value)) {
39
+ // object and array values are stringified
40
+ result = result.replace(placeholder, JSON.stringify(value, null, 2));
41
+ } else {
42
+ // unknown value type is replaced with a placeholder
43
+ result = result.replace(placeholder, 'UNKNOWN_TEMPLATE_VALUE');
44
+ }
45
+ });
46
+ }
47
+ return result;
48
+ };