@clxmedia/clxforms-client 1.0.26 → 1.0.28

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,12 +6,14 @@ export type ProcessedCLXFormSection = {
6
6
  question_layouts: CLXFormQuestionLayout[];
7
7
  conditions?: CLXFormRuleSet;
8
8
  is_complete: boolean;
9
+ has_ai: boolean;
9
10
  };
10
11
  export type ProcessedCLXFormStep = {
11
12
  id: number;
12
13
  name: string;
13
14
  description: string;
14
15
  is_gate: boolean;
16
+ has_ai: boolean;
15
17
  sections: ProcessedCLXFormSection[];
16
18
  conditions?: CLXFormRuleSet;
17
19
  is_complete: boolean;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CLXFormLayoutProcessor = void 0;
4
4
  const rules_processor_1 = require("./rules-processor");
5
+ const AI_RESPONSE_EMAIL = 'automation@clxp.us';
5
6
  const CLXFormLayoutProcessor = ({ mode, responseData, formRights }) => {
6
7
  const responseCopy = JSON.parse(JSON.stringify(responseData));
7
8
  const isQuestionLayoutEnabled = (questionLayout, sectionResponses) => {
@@ -48,19 +49,20 @@ const CLXFormLayoutProcessor = ({ mode, responseData, formRights }) => {
48
49
  const sectionProcessor = (section) => {
49
50
  const sectionResponses = JSON.parse(JSON.stringify(responseCopy));
50
51
  if (section.conditions && !(0, rules_processor_1.CLXRulesetProcessor)({ responseData: sectionResponses }).processRuleSet(section.conditions)) {
51
- return Object.assign(Object.assign({}, section), { is_complete: true, question_layouts: [] });
52
+ return Object.assign(Object.assign({}, section), { is_complete: true, has_ai: false, question_layouts: [] });
52
53
  }
53
54
  const is_section_complete = isSectionComplete(section, sectionResponses);
54
- return Object.assign(Object.assign({}, section), { is_complete: is_section_complete, question_layouts: section.question_layouts.map(questionLayout => questionLayoutProcessor(questionLayout, sectionResponses)) });
55
+ const question_layouts = section.question_layouts.map(questionLayout => questionLayoutProcessor(questionLayout, sectionResponses));
56
+ return Object.assign(Object.assign({}, section), { is_complete: is_section_complete, has_ai: question_layouts.some(ql => { var _a; return ql.is_enabled && ((_a = sectionResponses[ql.form_question_slug]) === null || _a === void 0 ? void 0 : _a.last_answered_by) === AI_RESPONSE_EMAIL; }), question_layouts });
55
57
  };
56
58
  const stepProcessor = (step) => {
57
59
  if (step.conditions && !(0, rules_processor_1.CLXRulesetProcessor)({ responseData: responseCopy }).processRuleSet(step.conditions)) {
58
- return Object.assign(Object.assign({}, step), { is_complete: true, sections: [] });
60
+ return Object.assign(Object.assign({}, step), { is_complete: true, has_ai: false, sections: [] });
59
61
  }
60
62
  const sections = step.sections
61
63
  .map(section => sectionProcessor(section))
62
64
  .filter(section => section.question_layouts.some(ql => ql.is_enabled));
63
- return Object.assign(Object.assign({}, step), { is_complete: sections.every(section => section.is_complete), sections });
65
+ return Object.assign(Object.assign({}, step), { is_complete: sections.every(section => section.is_complete), has_ai: sections.some(section => section.has_ai), sections });
64
66
  };
65
67
  const gatherFormStats = (steps) => {
66
68
  const allEnabledQuestions = steps
@@ -102,6 +104,7 @@ const CLXFormLayoutProcessor = ({ mode, responseData, formRights }) => {
102
104
  }
103
105
  let isGated = false;
104
106
  const isCLXInternalUser = isResponseBooleanTrue('is_clxinternal_user');
107
+ let blockedByAi = false;
105
108
  const steps = formRights === 'none'
106
109
  ? []
107
110
  : layout.steps
@@ -111,6 +114,10 @@ const CLXFormLayoutProcessor = ({ mode, responseData, formRights }) => {
111
114
  if (isGated && !isCLXInternalUser) {
112
115
  return acc;
113
116
  }
117
+ if (step.has_ai && !isCLXInternalUser) {
118
+ blockedByAi = true;
119
+ return acc;
120
+ }
114
121
  if (step.is_gate && !isCLXInternalUser) {
115
122
  isGated = !step.is_complete;
116
123
  }
@@ -118,7 +125,7 @@ const CLXFormLayoutProcessor = ({ mode, responseData, formRights }) => {
118
125
  return acc;
119
126
  }, [])
120
127
  .filter(step => !step.is_gate || isCLXInternalUser);
121
- return { form: layout.form, steps, stats: gatherFormStats(steps) };
128
+ return { form: layout.form, steps: blockedByAi ? [] : steps, stats: gatherFormStats(steps) };
122
129
  };
123
130
  return {
124
131
  process,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clxmedia/clxforms-client",
3
- "version": "1.0.26",
3
+ "version": "1.0.28",
4
4
  "description": "CLXperience Forms Client",
5
5
  "author": "Brandon Thompson <brandont@clxmedia.com>",
6
6
  "license": "MIT",
@@ -44,12 +44,12 @@
44
44
  "bugs": "https://github.com/adsupnow/xperience-library/clxforms-client",
45
45
  "peerDependencies": {},
46
46
  "dependencies": {
47
- "@clxmedia/types": "1.0.182",
47
+ "@clxmedia/types": "1.0.188",
48
48
  "luxon": "3.4.4"
49
49
  },
50
50
  "devDependencies": {
51
51
  "typescript": "^5.2.2",
52
- "@types/node": "^20",
52
+ "@types/node": "^22",
53
53
  "@types/jsonwebtoken": "9.0.6",
54
54
  "jest": "29.7.0",
55
55
  "ts-jest": "29.1.2",