@clxmedia/clxforms-client 1.0.27 → 1.0.29

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.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- export { CLXFormLayoutProcessor, ProcessedCLXFormSection, ProcessedCLXFormStep, ProcessedCLXFormLayout } from './layout-processor';
2
- export { CLXFormLayoutFilter, FilteredCLXFormLayout, } from './layout-filter';
3
- export { CLXFormHelpers } from './form-helpers';
4
- export { CLXRulesetProcessor } from './rules-processor';
5
- export { CLXRulesEngine } from './rules-engine';
6
- export { CLXFormConstants } from './constants';
1
+ export { CLXFormLayoutProcessor, ProcessedCLXFormSection, ProcessedCLXFormStep, ProcessedCLXFormLayout, } from "./layout-processor";
2
+ export { CLXFormLayoutFilter, FilteredCLXFormLayout, } from "./layout-filter";
3
+ export { CLXFormLayoutConvert } from "./layout-convert";
4
+ export { CLXFormHelpers } from "./form-helpers";
5
+ export { CLXRulesetProcessor } from "./rules-processor";
6
+ export { CLXRulesEngine } from "./rules-engine";
7
+ export { CLXFormConstants } from "./constants";
package/dist/index.js CHANGED
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CLXFormConstants = exports.CLXRulesEngine = exports.CLXRulesetProcessor = exports.CLXFormHelpers = exports.CLXFormLayoutFilter = exports.CLXFormLayoutProcessor = void 0;
3
+ exports.CLXFormConstants = exports.CLXRulesEngine = exports.CLXRulesetProcessor = exports.CLXFormHelpers = exports.CLXFormLayoutConvert = exports.CLXFormLayoutFilter = exports.CLXFormLayoutProcessor = void 0;
4
4
  var layout_processor_1 = require("./layout-processor");
5
5
  Object.defineProperty(exports, "CLXFormLayoutProcessor", { enumerable: true, get: function () { return layout_processor_1.CLXFormLayoutProcessor; } });
6
6
  var layout_filter_1 = require("./layout-filter");
7
7
  Object.defineProperty(exports, "CLXFormLayoutFilter", { enumerable: true, get: function () { return layout_filter_1.CLXFormLayoutFilter; } });
8
+ var layout_convert_1 = require("./layout-convert");
9
+ Object.defineProperty(exports, "CLXFormLayoutConvert", { enumerable: true, get: function () { return layout_convert_1.CLXFormLayoutConvert; } });
8
10
  var form_helpers_1 = require("./form-helpers");
9
11
  Object.defineProperty(exports, "CLXFormHelpers", { enumerable: true, get: function () { return form_helpers_1.CLXFormHelpers; } });
10
12
  var rules_processor_1 = require("./rules-processor");
@@ -0,0 +1,5 @@
1
+ import type { CLXFormQuestions, CLXFormResponses } from "@clxmedia/types/core/clxforms";
2
+ import type { ProcessedCLXFormLayout } from "./layout-processor";
3
+ export declare const CLXFormLayoutConvert: {
4
+ markdown: (layout: ProcessedCLXFormLayout, questionData: CLXFormQuestions, responseData: CLXFormResponses) => string;
5
+ };
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CLXFormLayoutConvert = void 0;
4
+ const formatResponseValue = (response, question) => {
5
+ var _a, _b;
6
+ if (!(response === null || response === void 0 ? void 0 : response.value) ||
7
+ response.value === null ||
8
+ response.value === undefined) {
9
+ return "🔹 *Not provided*";
10
+ }
11
+ const value = response.value;
12
+ const minutesToTime = (minutes) => {
13
+ let actualMinutes;
14
+ if (minutes < 0) {
15
+ const absMinutes = Math.abs(minutes);
16
+ if (absMinutes === 1620) {
17
+ actualMinutes = 22 * 60;
18
+ }
19
+ else if (absMinutes === 1080) {
20
+ actualMinutes = 6 * 60;
21
+ }
22
+ else {
23
+ actualMinutes = absMinutes;
24
+ }
25
+ }
26
+ else {
27
+ actualMinutes = minutes;
28
+ }
29
+ const hours24 = Math.floor(actualMinutes / 60);
30
+ const mins = actualMinutes % 60;
31
+ const hours12 = hours24 % 12 || 12;
32
+ const ampm = hours24 >= 12 ? "PM" : "AM";
33
+ return `${hours12}:${mins.toString().padStart(2, "0")} ${ampm}`;
34
+ };
35
+ switch (response.type) {
36
+ case "STRING_ARRAY":
37
+ if (Array.isArray(value) && value.length > 0) {
38
+ return `📝 ${value.join(", ")}`;
39
+ }
40
+ return "🔹 *Not provided*";
41
+ case "CONTACT_ARRAY":
42
+ if (Array.isArray(value) && value.length > 0) {
43
+ return value
44
+ .map((contact) => {
45
+ const parts = [];
46
+ if (contact.name)
47
+ parts.push(`👤 **${contact.name}**`);
48
+ if (contact.email)
49
+ parts.push(`📧 ${contact.email}`);
50
+ if (contact.phone)
51
+ parts.push(`📞 ${contact.phone}`);
52
+ return ` - ${parts.join(" • ")}`;
53
+ })
54
+ .join("\n");
55
+ }
56
+ return "🔹 *Not provided*";
57
+ case "CONTACT":
58
+ if (value && typeof value === "object") {
59
+ const contact = value;
60
+ const parts = [];
61
+ if (contact.name)
62
+ parts.push(`👤 **${contact.name}**`);
63
+ if (contact.email)
64
+ parts.push(`📧 ${contact.email}`);
65
+ if (contact.phone)
66
+ parts.push(`📞 ${contact.phone}`);
67
+ return ` - ${parts.join(" • ")}`;
68
+ }
69
+ return "🔹 *Not provided*";
70
+ case "BOOLEAN":
71
+ return value ? "✅ Yes" : "❌ No";
72
+ case "STRING":
73
+ if (typeof value === "string") {
74
+ let cleanValue = value
75
+ .replace(/<[^>]*>/g, "")
76
+ .replace(/&nbsp;/g, " ")
77
+ .trim();
78
+ if (((_b = (_a = question === null || question === void 0 ? void 0 : question.response_options) === null || _a === void 0 ? void 0 : _a.field) === null || _b === void 0 ? void 0 : _b.type) === "select" &&
79
+ "options" in question.response_options.field &&
80
+ Array.isArray(question.response_options.field.options)) {
81
+ const option = question.response_options.field.options.find((opt) => opt.value === cleanValue);
82
+ if (option) {
83
+ cleanValue = option.label;
84
+ }
85
+ }
86
+ return cleanValue ? `📋 ${cleanValue}` : "🔹 *Not provided*";
87
+ }
88
+ return "🔹 *Not provided*";
89
+ case "NUMBER":
90
+ return `🔢 ${String(value)}`;
91
+ case "SCHEDULE":
92
+ if (value && typeof value === "object") {
93
+ const schedule = value;
94
+ const days = [];
95
+ const dayNames = [
96
+ "monday",
97
+ "tuesday",
98
+ "wednesday",
99
+ "thursday",
100
+ "friday",
101
+ "saturday",
102
+ "sunday",
103
+ ];
104
+ for (const dayName of dayNames) {
105
+ const dayData = schedule[dayName];
106
+ if (dayData === false) {
107
+ days.push(`${dayName.charAt(0).toUpperCase() + dayName.slice(1, 3)}: Closed`);
108
+ }
109
+ else if (typeof dayData === "object" &&
110
+ dayData.start !== undefined &&
111
+ dayData.end !== undefined) {
112
+ const startTime = minutesToTime(dayData.start);
113
+ const endTime = minutesToTime(dayData.end);
114
+ const isOvernightSchedule = dayData.start < 0 && dayData.end < 0;
115
+ if (isOvernightSchedule) {
116
+ days.push(`${dayName.charAt(0).toUpperCase() + dayName.slice(1, 3)}: ${startTime} - ${endTime}`);
117
+ }
118
+ else {
119
+ days.push(`${dayName.charAt(0).toUpperCase() + dayName.slice(1, 3)}: ${startTime} - ${endTime}`);
120
+ }
121
+ }
122
+ }
123
+ if (days.length > 0) {
124
+ return days
125
+ .map((day) => ` - ${day.includes("Closed") ? "❌" : "🕒"} ${day}`)
126
+ .join("\n");
127
+ }
128
+ }
129
+ return "🔹 *Schedule not available*";
130
+ case "ANY":
131
+ default:
132
+ return `📄 ${String(value)}`;
133
+ }
134
+ };
135
+ exports.CLXFormLayoutConvert = {
136
+ markdown: (layout, questionData, responseData) => {
137
+ let markdown = "";
138
+ if (!layout.steps.length) {
139
+ markdown += `⚠️ No steps found.\n\n`;
140
+ return markdown;
141
+ }
142
+ layout.steps.forEach((step, stepIndex) => {
143
+ markdown += `# ${stepIndex + 1}. ${step.name}\n\n`;
144
+ if (step.description) {
145
+ markdown += `*${step.description}*\n\n`;
146
+ }
147
+ step.sections.forEach((section) => {
148
+ if (section.name) {
149
+ markdown += `## 📂 ${section.name}\n\n`;
150
+ }
151
+ section.question_layouts.forEach((ql) => {
152
+ const question = questionData[ql.form_question_slug];
153
+ if (!question) {
154
+ return;
155
+ }
156
+ const response = responseData[ql.form_question_slug];
157
+ if (!ql.is_enabled ||
158
+ !response ||
159
+ response.value === null ||
160
+ response.value === undefined) {
161
+ return;
162
+ }
163
+ const formattedValue = formatResponseValue(response, question);
164
+ markdown += `**${question.question_text.trim()}**\n\n`;
165
+ markdown += `${formattedValue}\n\n`;
166
+ });
167
+ });
168
+ });
169
+ markdown += `\n*📅 Generated on ${new Date().toLocaleDateString()}*`;
170
+ return markdown;
171
+ },
172
+ };
@@ -52,8 +52,8 @@ const CLXFormLayoutProcessor = ({ mode, responseData, formRights }) => {
52
52
  return Object.assign(Object.assign({}, section), { is_complete: true, has_ai: false, question_layouts: [] });
53
53
  }
54
54
  const is_section_complete = isSectionComplete(section, sectionResponses);
55
- const has_ai = section.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; });
56
- return Object.assign(Object.assign({}, section), { is_complete: is_section_complete, has_ai, 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 });
57
57
  };
58
58
  const stepProcessor = (step) => {
59
59
  if (step.conditions && !(0, rules_processor_1.CLXRulesetProcessor)({ responseData: responseCopy }).processRuleSet(step.conditions)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clxmedia/clxforms-client",
3
- "version": "1.0.27",
3
+ "version": "1.0.29",
4
4
  "description": "CLXperience Forms Client",
5
5
  "author": "Brandon Thompson <brandont@clxmedia.com>",
6
6
  "license": "MIT",