@memberjunction/actions-bizapps-formbuilders 2.113.2 → 2.115.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.
Files changed (205) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +20 -0
  3. package/dist/base/base-form-builder.action.d.ts +15 -2
  4. package/dist/base/base-form-builder.action.d.ts.map +1 -1
  5. package/dist/base/base-form-builder.action.js +55 -13
  6. package/dist/base/base-form-builder.action.js.map +1 -1
  7. package/dist/index.d.ts +0 -2
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +0 -4
  10. package/dist/index.js.map +1 -1
  11. package/dist/providers/google-forms/actions/export-csv.action.d.ts +4 -0
  12. package/dist/providers/google-forms/actions/export-csv.action.d.ts.map +1 -1
  13. package/dist/providers/google-forms/actions/export-csv.action.js +9 -2
  14. package/dist/providers/google-forms/actions/export-csv.action.js.map +1 -1
  15. package/dist/providers/google-forms/actions/get-form.action.d.ts +4 -0
  16. package/dist/providers/google-forms/actions/get-form.action.d.ts.map +1 -1
  17. package/dist/providers/google-forms/actions/get-form.action.js +9 -2
  18. package/dist/providers/google-forms/actions/get-form.action.js.map +1 -1
  19. package/dist/providers/google-forms/actions/get-single-response.action.d.ts +4 -0
  20. package/dist/providers/google-forms/actions/get-single-response.action.d.ts.map +1 -1
  21. package/dist/providers/google-forms/actions/get-single-response.action.js +9 -2
  22. package/dist/providers/google-forms/actions/get-single-response.action.js.map +1 -1
  23. package/dist/providers/google-forms/actions/get-statistics.action.d.ts +4 -0
  24. package/dist/providers/google-forms/actions/get-statistics.action.d.ts.map +1 -1
  25. package/dist/providers/google-forms/actions/get-statistics.action.js +10 -3
  26. package/dist/providers/google-forms/actions/get-statistics.action.js.map +1 -1
  27. package/dist/providers/google-forms/actions/index.d.ts +5 -0
  28. package/dist/providers/google-forms/actions/index.d.ts.map +1 -1
  29. package/dist/providers/google-forms/actions/index.js +17 -0
  30. package/dist/providers/google-forms/actions/index.js.map +1 -1
  31. package/dist/providers/google-forms/googleforms-base.action.d.ts.map +1 -1
  32. package/dist/providers/google-forms/googleforms-base.action.js +2 -1
  33. package/dist/providers/google-forms/googleforms-base.action.js.map +1 -1
  34. package/dist/providers/jotform/actions/create-form.action.d.ts +4 -0
  35. package/dist/providers/jotform/actions/create-form.action.d.ts.map +1 -1
  36. package/dist/providers/jotform/actions/create-form.action.js +9 -2
  37. package/dist/providers/jotform/actions/create-form.action.js.map +1 -1
  38. package/dist/providers/jotform/actions/export-csv.action.d.ts +4 -0
  39. package/dist/providers/jotform/actions/export-csv.action.d.ts.map +1 -1
  40. package/dist/providers/jotform/actions/export-csv.action.js +9 -2
  41. package/dist/providers/jotform/actions/export-csv.action.js.map +1 -1
  42. package/dist/providers/jotform/actions/get-form.action.d.ts +4 -0
  43. package/dist/providers/jotform/actions/get-form.action.d.ts.map +1 -1
  44. package/dist/providers/jotform/actions/get-form.action.js +9 -2
  45. package/dist/providers/jotform/actions/get-form.action.js.map +1 -1
  46. package/dist/providers/jotform/actions/get-single-submission.action.d.ts +4 -0
  47. package/dist/providers/jotform/actions/get-single-submission.action.d.ts.map +1 -1
  48. package/dist/providers/jotform/actions/get-single-submission.action.js +9 -2
  49. package/dist/providers/jotform/actions/get-single-submission.action.js.map +1 -1
  50. package/dist/providers/jotform/actions/get-statistics.action.d.ts +4 -0
  51. package/dist/providers/jotform/actions/get-statistics.action.d.ts.map +1 -1
  52. package/dist/providers/jotform/actions/get-statistics.action.js +10 -3
  53. package/dist/providers/jotform/actions/get-statistics.action.js.map +1 -1
  54. package/dist/providers/jotform/actions/get-submissions.action.d.ts +4 -0
  55. package/dist/providers/jotform/actions/get-submissions.action.d.ts.map +1 -1
  56. package/dist/providers/jotform/actions/get-submissions.action.js +9 -2
  57. package/dist/providers/jotform/actions/get-submissions.action.js.map +1 -1
  58. package/dist/providers/jotform/actions/index.d.ts +5 -0
  59. package/dist/providers/jotform/actions/index.d.ts.map +1 -1
  60. package/dist/providers/jotform/actions/index.js +25 -0
  61. package/dist/providers/jotform/actions/index.js.map +1 -1
  62. package/dist/providers/jotform/actions/update-form.action.d.ts +4 -0
  63. package/dist/providers/jotform/actions/update-form.action.d.ts.map +1 -1
  64. package/dist/providers/jotform/actions/update-form.action.js +9 -2
  65. package/dist/providers/jotform/actions/update-form.action.js.map +1 -1
  66. package/dist/providers/jotform/actions/watch-new-submissions.action.d.ts +4 -0
  67. package/dist/providers/jotform/actions/watch-new-submissions.action.d.ts.map +1 -1
  68. package/dist/providers/jotform/actions/watch-new-submissions.action.js +11 -4
  69. package/dist/providers/jotform/actions/watch-new-submissions.action.js.map +1 -1
  70. package/dist/providers/jotform/jotform-base.action.d.ts.map +1 -1
  71. package/dist/providers/jotform/jotform-base.action.js +2 -1
  72. package/dist/providers/jotform/jotform-base.action.js.map +1 -1
  73. package/dist/providers/surveymonkey/actions/create-survey.action.d.ts +4 -0
  74. package/dist/providers/surveymonkey/actions/create-survey.action.d.ts.map +1 -1
  75. package/dist/providers/surveymonkey/actions/create-survey.action.js +9 -2
  76. package/dist/providers/surveymonkey/actions/create-survey.action.js.map +1 -1
  77. package/dist/providers/surveymonkey/actions/export-csv.action.d.ts +4 -0
  78. package/dist/providers/surveymonkey/actions/export-csv.action.d.ts.map +1 -1
  79. package/dist/providers/surveymonkey/actions/export-csv.action.js +9 -2
  80. package/dist/providers/surveymonkey/actions/export-csv.action.js.map +1 -1
  81. package/dist/providers/surveymonkey/actions/get-responses.action.d.ts +4 -0
  82. package/dist/providers/surveymonkey/actions/get-responses.action.d.ts.map +1 -1
  83. package/dist/providers/surveymonkey/actions/get-responses.action.js +9 -2
  84. package/dist/providers/surveymonkey/actions/get-responses.action.js.map +1 -1
  85. package/dist/providers/surveymonkey/actions/get-single-response.action.d.ts +4 -0
  86. package/dist/providers/surveymonkey/actions/get-single-response.action.d.ts.map +1 -1
  87. package/dist/providers/surveymonkey/actions/get-single-response.action.js +9 -2
  88. package/dist/providers/surveymonkey/actions/get-single-response.action.js.map +1 -1
  89. package/dist/providers/surveymonkey/actions/get-statistics.action.d.ts +4 -0
  90. package/dist/providers/surveymonkey/actions/get-statistics.action.d.ts.map +1 -1
  91. package/dist/providers/surveymonkey/actions/get-statistics.action.js +10 -3
  92. package/dist/providers/surveymonkey/actions/get-statistics.action.js.map +1 -1
  93. package/dist/providers/surveymonkey/actions/get-survey.action.d.ts +4 -0
  94. package/dist/providers/surveymonkey/actions/get-survey.action.d.ts.map +1 -1
  95. package/dist/providers/surveymonkey/actions/get-survey.action.js +9 -2
  96. package/dist/providers/surveymonkey/actions/get-survey.action.js.map +1 -1
  97. package/dist/providers/surveymonkey/actions/index.d.ts +5 -0
  98. package/dist/providers/surveymonkey/actions/index.d.ts.map +1 -1
  99. package/dist/providers/surveymonkey/actions/index.js +25 -0
  100. package/dist/providers/surveymonkey/actions/index.js.map +1 -1
  101. package/dist/providers/surveymonkey/actions/update-survey.action.d.ts +4 -0
  102. package/dist/providers/surveymonkey/actions/update-survey.action.d.ts.map +1 -1
  103. package/dist/providers/surveymonkey/actions/update-survey.action.js +9 -2
  104. package/dist/providers/surveymonkey/actions/update-survey.action.js.map +1 -1
  105. package/dist/providers/surveymonkey/actions/watch-new-responses.action.d.ts +4 -0
  106. package/dist/providers/surveymonkey/actions/watch-new-responses.action.d.ts.map +1 -1
  107. package/dist/providers/surveymonkey/actions/watch-new-responses.action.js +11 -4
  108. package/dist/providers/surveymonkey/actions/watch-new-responses.action.js.map +1 -1
  109. package/dist/providers/surveymonkey/surveymonkey-base.action.d.ts.map +1 -1
  110. package/dist/providers/surveymonkey/surveymonkey-base.action.js +2 -1
  111. package/dist/providers/surveymonkey/surveymonkey-base.action.js.map +1 -1
  112. package/dist/providers/typeform/actions/create-form.action.d.ts +4 -0
  113. package/dist/providers/typeform/actions/create-form.action.d.ts.map +1 -1
  114. package/dist/providers/typeform/actions/create-form.action.js +9 -2
  115. package/dist/providers/typeform/actions/create-form.action.js.map +1 -1
  116. package/dist/providers/typeform/actions/export-csv.action.d.ts +4 -0
  117. package/dist/providers/typeform/actions/export-csv.action.d.ts.map +1 -1
  118. package/dist/providers/typeform/actions/export-csv.action.js +9 -2
  119. package/dist/providers/typeform/actions/export-csv.action.js.map +1 -1
  120. package/dist/providers/typeform/actions/get-file-content.action.d.ts +46 -0
  121. package/dist/providers/typeform/actions/get-file-content.action.d.ts.map +1 -0
  122. package/dist/providers/typeform/actions/get-file-content.action.js +262 -0
  123. package/dist/providers/typeform/actions/get-file-content.action.js.map +1 -0
  124. package/dist/providers/typeform/actions/get-form.action.d.ts +4 -0
  125. package/dist/providers/typeform/actions/get-form.action.d.ts.map +1 -1
  126. package/dist/providers/typeform/actions/get-form.action.js +9 -2
  127. package/dist/providers/typeform/actions/get-form.action.js.map +1 -1
  128. package/dist/providers/typeform/actions/get-forms.action.d.ts +27 -0
  129. package/dist/providers/typeform/actions/get-forms.action.d.ts.map +1 -0
  130. package/dist/providers/typeform/actions/get-forms.action.js +152 -0
  131. package/dist/providers/typeform/actions/get-forms.action.js.map +1 -0
  132. package/dist/providers/typeform/actions/get-responses.action.d.ts +4 -0
  133. package/dist/providers/typeform/actions/get-responses.action.d.ts.map +1 -1
  134. package/dist/providers/typeform/actions/get-responses.action.js +32 -4
  135. package/dist/providers/typeform/actions/get-responses.action.js.map +1 -1
  136. package/dist/providers/typeform/actions/get-single-response.action.d.ts +4 -0
  137. package/dist/providers/typeform/actions/get-single-response.action.d.ts.map +1 -1
  138. package/dist/providers/typeform/actions/get-single-response.action.js +26 -3
  139. package/dist/providers/typeform/actions/get-single-response.action.js.map +1 -1
  140. package/dist/providers/typeform/actions/get-statistics.action.d.ts +4 -0
  141. package/dist/providers/typeform/actions/get-statistics.action.d.ts.map +1 -1
  142. package/dist/providers/typeform/actions/get-statistics.action.js +10 -3
  143. package/dist/providers/typeform/actions/get-statistics.action.js.map +1 -1
  144. package/dist/providers/typeform/actions/index.d.ts +7 -0
  145. package/dist/providers/typeform/actions/index.d.ts.map +1 -1
  146. package/dist/providers/typeform/actions/index.js +31 -0
  147. package/dist/providers/typeform/actions/index.js.map +1 -1
  148. package/dist/providers/typeform/actions/update-form.action.d.ts +4 -0
  149. package/dist/providers/typeform/actions/update-form.action.d.ts.map +1 -1
  150. package/dist/providers/typeform/actions/update-form.action.js +9 -2
  151. package/dist/providers/typeform/actions/update-form.action.js.map +1 -1
  152. package/dist/providers/typeform/actions/watch-new-responses.action.d.ts +4 -0
  153. package/dist/providers/typeform/actions/watch-new-responses.action.d.ts.map +1 -1
  154. package/dist/providers/typeform/actions/watch-new-responses.action.js +11 -4
  155. package/dist/providers/typeform/actions/watch-new-responses.action.js.map +1 -1
  156. package/dist/providers/typeform/typeform-base.action.d.ts +15 -1
  157. package/dist/providers/typeform/typeform-base.action.d.ts.map +1 -1
  158. package/dist/providers/typeform/typeform-base.action.js +67 -4
  159. package/dist/providers/typeform/typeform-base.action.js.map +1 -1
  160. package/dist/shared/file-content-processor.d.ts +77 -0
  161. package/dist/shared/file-content-processor.d.ts.map +1 -0
  162. package/dist/shared/file-content-processor.js +291 -0
  163. package/dist/shared/file-content-processor.js.map +1 -0
  164. package/package.json +6 -6
  165. package/src/base/base-form-builder.action.ts +64 -15
  166. package/src/index.ts +1 -5
  167. package/src/providers/google-forms/actions/export-csv.action.ts +8 -1
  168. package/src/providers/google-forms/actions/get-form.action.ts +8 -1
  169. package/src/providers/google-forms/actions/get-single-response.action.ts +8 -1
  170. package/src/providers/google-forms/actions/get-statistics.action.ts +9 -2
  171. package/src/providers/google-forms/actions/index.ts +17 -0
  172. package/src/providers/google-forms/googleforms-base.action.ts +2 -1
  173. package/src/providers/jotform/actions/create-form.action.ts +8 -1
  174. package/src/providers/jotform/actions/export-csv.action.ts +8 -1
  175. package/src/providers/jotform/actions/get-form.action.ts +8 -1
  176. package/src/providers/jotform/actions/get-single-submission.action.ts +8 -1
  177. package/src/providers/jotform/actions/get-statistics.action.ts +9 -2
  178. package/src/providers/jotform/actions/get-submissions.action.ts +8 -1
  179. package/src/providers/jotform/actions/index.ts +25 -0
  180. package/src/providers/jotform/actions/update-form.action.ts +8 -1
  181. package/src/providers/jotform/actions/watch-new-submissions.action.ts +10 -3
  182. package/src/providers/jotform/jotform-base.action.ts +2 -1
  183. package/src/providers/surveymonkey/actions/create-survey.action.ts +8 -1
  184. package/src/providers/surveymonkey/actions/export-csv.action.ts +8 -1
  185. package/src/providers/surveymonkey/actions/get-responses.action.ts +8 -1
  186. package/src/providers/surveymonkey/actions/get-single-response.action.ts +8 -1
  187. package/src/providers/surveymonkey/actions/get-statistics.action.ts +9 -2
  188. package/src/providers/surveymonkey/actions/get-survey.action.ts +8 -1
  189. package/src/providers/surveymonkey/actions/index.ts +25 -0
  190. package/src/providers/surveymonkey/actions/update-survey.action.ts +8 -1
  191. package/src/providers/surveymonkey/actions/watch-new-responses.action.ts +10 -3
  192. package/src/providers/surveymonkey/surveymonkey-base.action.ts +2 -1
  193. package/src/providers/typeform/actions/create-form.action.ts +8 -1
  194. package/src/providers/typeform/actions/export-csv.action.ts +8 -1
  195. package/src/providers/typeform/actions/get-file-content.action.ts +269 -0
  196. package/src/providers/typeform/actions/get-form.action.ts +8 -1
  197. package/src/providers/typeform/actions/get-forms.action.ts +152 -0
  198. package/src/providers/typeform/actions/get-responses.action.ts +31 -3
  199. package/src/providers/typeform/actions/get-single-response.action.ts +25 -2
  200. package/src/providers/typeform/actions/get-statistics.action.ts +9 -2
  201. package/src/providers/typeform/actions/index.ts +31 -0
  202. package/src/providers/typeform/actions/update-form.action.ts +8 -1
  203. package/src/providers/typeform/actions/watch-new-responses.action.ts +10 -3
  204. package/src/providers/typeform/typeform-base.action.ts +74 -4
  205. package/src/shared/file-content-processor.ts +322 -0
@@ -0,0 +1,77 @@
1
+ /// <reference types="node" />
2
+ /**
3
+ * File content processing options
4
+ */
5
+ export interface FileContentProcessorOptions {
6
+ /** Requested output format: 'auto' (smart detection), 'text', 'base64', 'raw' */
7
+ format?: 'auto' | 'text' | 'base64' | 'raw';
8
+ /** Maximum file size to process (in bytes) */
9
+ maxFileSize?: number;
10
+ /** Whether to include extraction warnings */
11
+ includeWarnings?: boolean;
12
+ }
13
+ /**
14
+ * Result of file content processing
15
+ */
16
+ export interface FileContentProcessorResult {
17
+ /** Processed content */
18
+ content: string;
19
+ /** Detected/processed format */
20
+ format: string;
21
+ /** Original content type */
22
+ contentType: string;
23
+ /** File size in bytes */
24
+ size: number;
25
+ /** Extraction method used */
26
+ extractionMethod: string;
27
+ /** Optional warning message */
28
+ warning?: string;
29
+ /** Processing success status */
30
+ success: boolean;
31
+ /** Error message if processing failed */
32
+ error?: string;
33
+ }
34
+ /**
35
+ * Reusable file content processor for Form Builders actions
36
+ * Handles intelligent content extraction from various file formats
37
+ */
38
+ export declare class FileContentProcessor {
39
+ private static readonly DEFAULT_MAX_FILE_SIZE;
40
+ /**
41
+ * Process file content based on content type and requested format
42
+ */
43
+ static processContent(buffer: Buffer, contentType: string, options?: FileContentProcessorOptions): Promise<FileContentProcessorResult>;
44
+ /**
45
+ * Intelligent content extraction based on file type
46
+ */
47
+ private static intelligentProcessing;
48
+ /**
49
+ * Check if content type is an image format
50
+ */
51
+ private static isImage;
52
+ /**
53
+ * Check if content type is a text-based format
54
+ */
55
+ private static isTextFormat;
56
+ /**
57
+ * Check if content type is PDF
58
+ */
59
+ private static isPDF;
60
+ /**
61
+ * Check if content type is Excel
62
+ */
63
+ private static isExcel;
64
+ /**
65
+ * Check if content type is Word
66
+ */
67
+ private static isWord;
68
+ /**
69
+ * Extract filename from URL or Content-Disposition header
70
+ */
71
+ static extractFilename(fileUrl: string, contentDisposition?: string): string;
72
+ /**
73
+ * Get content format description for easy processing
74
+ */
75
+ static getContentFormat(contentType: string): string;
76
+ }
77
+ //# sourceMappingURL=file-content-processor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-content-processor.d.ts","sourceRoot":"","sources":["../../src/shared/file-content-processor.ts"],"names":[],"mappings":";AAKA;;GAEG;AACH,MAAM,WAA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AM;IAuB5E;;OAEG;IACH,MAAM,CAAC,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM;CAiBvD"}
@@ -0,0 +1,291 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.FileContentProcessor = void 0;
30
+ const core_1 = require("@memberjunction/core");
31
+ const pdf_parse_1 = __importDefault(require("pdf-parse"));
32
+ const ExcelJS = __importStar(require("exceljs"));
33
+ const mammoth = __importStar(require("mammoth"));
34
+ /**
35
+ * Reusable file content processor for Form Builders actions
36
+ * Handles intelligent content extraction from various file formats
37
+ */
38
+ class FileContentProcessor {
39
+ static DEFAULT_MAX_FILE_SIZE = 50 * 1024 * 1024; // 50MB
40
+ /**
41
+ * Process file content based on content type and requested format
42
+ */
43
+ static async processContent(buffer, contentType, options = {}) {
44
+ try {
45
+ const { format = 'auto', maxFileSize = this.DEFAULT_MAX_FILE_SIZE, includeWarnings = true } = options;
46
+ // Check file size
47
+ if (buffer.length > maxFileSize) {
48
+ return {
49
+ content: '',
50
+ format: 'error',
51
+ contentType,
52
+ size: buffer.length,
53
+ extractionMethod: 'none',
54
+ warning: `File too large (${buffer.length} bytes). Maximum allowed: ${maxFileSize} bytes.`,
55
+ success: false,
56
+ error: 'File size exceeds limit'
57
+ };
58
+ }
59
+ // Process based on requested format
60
+ if (format === 'raw') {
61
+ return {
62
+ content: buffer.toString('base64'),
63
+ format: 'raw',
64
+ contentType,
65
+ size: buffer.length,
66
+ extractionMethod: 'none',
67
+ success: true
68
+ };
69
+ }
70
+ if (format === 'base64') {
71
+ return {
72
+ content: buffer.toString('base64'),
73
+ format: 'base64',
74
+ contentType,
75
+ size: buffer.length,
76
+ extractionMethod: 'none',
77
+ success: true
78
+ };
79
+ }
80
+ // Auto or text format - intelligent processing
81
+ return await this.intelligentProcessing(buffer, contentType, includeWarnings);
82
+ }
83
+ catch (error) {
84
+ const errorMessage = error instanceof Error ? error.message : String(error);
85
+ (0, core_1.LogStatus)(`File content processing failed: ${errorMessage}`);
86
+ return {
87
+ content: '',
88
+ format: 'error',
89
+ contentType,
90
+ size: buffer.length,
91
+ extractionMethod: 'none',
92
+ error: errorMessage,
93
+ success: false
94
+ };
95
+ }
96
+ }
97
+ /**
98
+ * Intelligent content extraction based on file type
99
+ */
100
+ static async intelligentProcessing(buffer, contentType, includeWarnings) {
101
+ let content;
102
+ let format;
103
+ let extractionMethod;
104
+ let warning;
105
+ const normalizedContentType = contentType.toLowerCase();
106
+ if (this.isImage(normalizedContentType)) {
107
+ // Images: Return base64 for LLM vision
108
+ format = 'image';
109
+ content = buffer.toString('base64');
110
+ extractionMethod = 'none';
111
+ }
112
+ else if (this.isTextFormat(normalizedContentType)) {
113
+ // Text formats: Return decoded text
114
+ format = 'text';
115
+ content = buffer.toString('utf8');
116
+ extractionMethod = 'none';
117
+ }
118
+ else if (this.isPDF(normalizedContentType)) {
119
+ // PDF: Extract text
120
+ try {
121
+ const pdfData = await (0, pdf_parse_1.default)(buffer);
122
+ format = 'text';
123
+ content = pdfData.text;
124
+ extractionMethod = 'pdf-parse';
125
+ }
126
+ catch (pdfError) {
127
+ format = 'base64';
128
+ content = buffer.toString('base64');
129
+ extractionMethod = 'none';
130
+ warning = 'PDF text extraction failed, returned as base64';
131
+ }
132
+ }
133
+ else if (this.isExcel(normalizedContentType)) {
134
+ // Excel: Parse to structured text
135
+ try {
136
+ const workbook = new ExcelJS.Workbook();
137
+ await workbook.xlsx.load(buffer);
138
+ const sheets = {};
139
+ workbook.eachSheet((worksheet) => {
140
+ const rows = [];
141
+ worksheet.eachRow((row) => {
142
+ const rowData = [];
143
+ row.eachCell((cell) => {
144
+ rowData.push(cell.value);
145
+ });
146
+ rows.push(rowData);
147
+ });
148
+ sheets[worksheet.name] = rows;
149
+ });
150
+ format = 'structured';
151
+ content = JSON.stringify(sheets, null, 2);
152
+ extractionMethod = 'excel-parse';
153
+ }
154
+ catch (excelError) {
155
+ format = 'base64';
156
+ content = buffer.toString('base64');
157
+ extractionMethod = 'none';
158
+ warning = 'Excel parsing failed, returned as base64';
159
+ }
160
+ }
161
+ else if (this.isWord(normalizedContentType)) {
162
+ // Word: Extract text
163
+ try {
164
+ const result = await mammoth.extractRawText({ buffer });
165
+ format = 'text';
166
+ content = result.value;
167
+ extractionMethod = 'word-extract';
168
+ if (result.messages.length > 0) {
169
+ warning = `Word processing warnings: ${result.messages.map(m => m.message).join(', ')}`;
170
+ }
171
+ }
172
+ catch (wordError) {
173
+ format = 'base64';
174
+ content = buffer.toString('base64');
175
+ extractionMethod = 'none';
176
+ warning = 'Word text extraction failed, returned as base64';
177
+ }
178
+ }
179
+ else {
180
+ // Unknown binary: Return base64 with warning
181
+ format = 'binary';
182
+ content = buffer.toString('base64');
183
+ extractionMethod = 'none';
184
+ if (includeWarnings) {
185
+ warning = `Unsupported format '${contentType}' - returned as base64. For LLM consumption, consider converting to text, image, or supported document format.`;
186
+ }
187
+ }
188
+ return {
189
+ content,
190
+ format,
191
+ contentType,
192
+ size: buffer.length,
193
+ extractionMethod,
194
+ warning: includeWarnings ? warning : undefined,
195
+ success: true
196
+ };
197
+ }
198
+ /**
199
+ * Check if content type is an image format
200
+ */
201
+ static isImage(contentType) {
202
+ return contentType.startsWith('image/');
203
+ }
204
+ /**
205
+ * Check if content type is a text-based format
206
+ */
207
+ static isTextFormat(contentType) {
208
+ const textTypes = [
209
+ 'text/',
210
+ 'application/json',
211
+ 'application/xml',
212
+ 'application/javascript',
213
+ 'application/typescript',
214
+ 'application/rtf',
215
+ 'text/csv',
216
+ 'text/markdown'
217
+ ];
218
+ return textTypes.some(type => contentType.startsWith(type));
219
+ }
220
+ /**
221
+ * Check if content type is PDF
222
+ */
223
+ static isPDF(contentType) {
224
+ return contentType === 'application/pdf';
225
+ }
226
+ /**
227
+ * Check if content type is Excel
228
+ */
229
+ static isExcel(contentType) {
230
+ return contentType === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' || // xlsx
231
+ contentType === 'application/vnd.ms-excel' || // xls
232
+ contentType === 'application/vnd.ms-excel.sheet.macroEnabled.12'; // xlsm
233
+ }
234
+ /**
235
+ * Check if content type is Word
236
+ */
237
+ static isWord(contentType) {
238
+ return contentType === 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' || // docx
239
+ contentType === 'application/msword' || // doc
240
+ contentType === 'application/vnd.ms-word.document.macroEnabled.12'; // docm
241
+ }
242
+ /**
243
+ * Extract filename from URL or Content-Disposition header
244
+ */
245
+ static extractFilename(fileUrl, contentDisposition) {
246
+ // Try to extract from Content-Disposition header first
247
+ if (contentDisposition) {
248
+ const filenameMatch = contentDisposition.match(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/);
249
+ if (filenameMatch && filenameMatch[1]) {
250
+ let filename = filenameMatch[1].replace(/['"]/g, '');
251
+ // Handle UTF-8 encoded filenames
252
+ if (filename.startsWith('UTF-8')) {
253
+ filename = filename.replace(/UTF-8''/, '');
254
+ }
255
+ return filename;
256
+ }
257
+ }
258
+ // Fall back to extracting from URL
259
+ const urlParts = fileUrl.split('/');
260
+ const filename = urlParts[urlParts.length - 1];
261
+ // Remove any query parameters and ensure we have a reasonable filename
262
+ const cleanFilename = filename.split('?')[0];
263
+ return cleanFilename || 'download';
264
+ }
265
+ /**
266
+ * Get content format description for easy processing
267
+ */
268
+ static getContentFormat(contentType) {
269
+ const normalizedContentType = contentType.toLowerCase();
270
+ if (this.isImage(normalizedContentType)) {
271
+ return 'image';
272
+ }
273
+ else if (this.isTextFormat(normalizedContentType)) {
274
+ return 'text';
275
+ }
276
+ else if (this.isPDF(normalizedContentType)) {
277
+ return 'pdf';
278
+ }
279
+ else if (this.isExcel(normalizedContentType)) {
280
+ return 'spreadsheet';
281
+ }
282
+ else if (this.isWord(normalizedContentType)) {
283
+ return 'document';
284
+ }
285
+ else {
286
+ return 'binary';
287
+ }
288
+ }
289
+ }
290
+ exports.FileContentProcessor = FileContentProcessor;
291
+ //# sourceMappingURL=file-content-processor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-content-processor.js","sourceRoot":"","sources":["../../src/shared/file-content-processor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAiD;AACjD,0DAAiC;AACjC,iDAAmC;AACnC,iDAAmC;AAoCnC;;;GAGG;AACH,MAAa,oBAAoB;IACrB,MAAM,CAAU,qBAAqB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,OAAO;IAEzE;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,cAAc,CACvB,MAAc,EACd,WAAmB,EACnB,UAAuC,EAAE;QAEzC,IAAI,CAAC;YACD,MAAM,EACF,MAAM,GAAG,MAAM,EACf,WAAW,GAAG,IAAI,CAAC,qBAAqB,EACxC,eAAe,GAAG,IAAI,EACzB,GAAG,OAAO,CAAC;YAEZ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AQ,CAAC;QACpB,CAAC;IACL,CAAC;;AArRL,oDAsRC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memberjunction/actions-bizapps-formbuilders",
3
- "version": "2.113.2",
3
+ "version": "2.115.0",
4
4
  "description": "Form builder and survey platform integration actions for MemberJunction",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -23,11 +23,11 @@
23
23
  "author": "MemberJunction",
24
24
  "license": "ISC",
25
25
  "dependencies": {
26
- "@memberjunction/core": "2.113.2",
27
- "@memberjunction/global": "2.113.2",
28
- "@memberjunction/actions-base": "2.113.2",
29
- "@memberjunction/actions": "2.113.2",
30
- "@memberjunction/core-entities": "2.113.2",
26
+ "@memberjunction/core": "2.115.0",
27
+ "@memberjunction/global": "2.115.0",
28
+ "@memberjunction/actions-base": "2.115.0",
29
+ "@memberjunction/actions": "2.115.0",
30
+ "@memberjunction/core-entities": "2.115.0",
31
31
  "axios": "^1.6.0"
32
32
  },
33
33
  "devDependencies": {
@@ -1,5 +1,5 @@
1
1
  import { ActionParam } from '@memberjunction/actions-base';
2
- import { BaseAction } from '@memberjunction/actions';
2
+ import { BaseAction, OAuth2Manager } from '@memberjunction/actions';
3
3
  import { RegisterClass } from '@memberjunction/global';
4
4
  import { UserInfo } from '@memberjunction/core';
5
5
  import { CompanyIntegrationEntity } from '@memberjunction/core-entities';
@@ -13,7 +13,8 @@ export interface FormResponse {
13
13
  formId: string;
14
14
  submittedAt: Date;
15
15
  completed: boolean;
16
- answers: FormAnswer[];
16
+ answerDetails: FormAnswer[]; // Renamed from answers - detailed array with field info
17
+ answers?: Record<string, any>; // Renamed from simpleAnswers - flat object with question titles as keys
17
18
  metadata?: {
18
19
  browser?: string;
19
20
  platform?: string;
@@ -120,10 +121,25 @@ export abstract class BaseFormBuilderAction extends BaseAction {
120
121
  * Gets credentials from environment variables
121
122
  * Format: BIZAPPS_{PROVIDER}_{COMPANY_ID}_{CREDENTIAL_TYPE}
122
123
  * Example: BIZAPPS_TYPEFORM_12345_API_TOKEN
124
+ *
125
+ * Falls back to: BIZAPPS_{PROVIDER}_{CREDENTIAL_TYPE} if no company-specific credential found
126
+ * Example fallback: BIZAPPS_TYPEFORM_API_TOKEN
123
127
  */
124
128
  protected getCredentialFromEnv(companyId: string, credentialType: string): string | undefined {
125
- const envKey = `BIZAPPS_${this.formPlatform.toUpperCase().replace(/\s+/g, '_')}_${companyId}_${credentialType.toUpperCase()}`;
126
- return process.env[envKey];
129
+ const platformKey = this.formPlatform.toUpperCase().replace(/\s+/g, '_');
130
+
131
+ // Try company-specific credential first
132
+ if (companyId) {
133
+ const companyEnvKey = `BIZAPPS_${platformKey}_${companyId}_${credentialType.toUpperCase()}`;
134
+ const companyCredential = process.env[companyEnvKey];
135
+ if (companyCredential) {
136
+ return companyCredential;
137
+ }
138
+ }
139
+
140
+ // Fall back to default credential (no company ID)
141
+ const defaultEnvKey = `BIZAPPS_${platformKey}_${credentialType.toUpperCase()}`;
142
+ return process.env[defaultEnvKey];
127
143
  }
128
144
 
129
145
  /**
@@ -165,22 +181,55 @@ export abstract class BaseFormBuilderAction extends BaseAction {
165
181
  * @throws Error if no credentials are found or company integration is not configured
166
182
  */
167
183
  protected async getSecureAPIToken(companyId: string | null | undefined, contextUser: UserInfo): Promise<string> {
168
- // CompanyID is required - if not provided, throw error
169
- if (!companyId) {
170
- throw new Error(`CompanyID parameter is required. Please provide a valid CompanyID to identify which company's ${this.integrationName} credentials should be used.`);
184
+ // Try environment variables first (faster, no database query needed)
185
+ const envToken = this.getCredentialFromEnv(companyId || '', 'API_TOKEN') ||
186
+ this.getCredentialFromEnv(companyId || '', 'ACCESS_TOKEN') ||
187
+ this.getCredentialFromEnv(companyId || '', 'API_KEY');
188
+
189
+ if (envToken) {
190
+ return envToken;
171
191
  }
172
192
 
173
- const effectiveCompanyId = companyId;
193
+ // Fall back to database lookup if companyId provided
194
+ if (companyId) {
195
+ const integration = await this.getCompanyIntegration(companyId, contextUser);
196
+ const credentials = await this.getAPICredentials(integration);
174
197
 
175
- const integration = await this.getCompanyIntegration(effectiveCompanyId, contextUser);
176
- const credentials = await this.getAPICredentials(integration);
198
+ const token = credentials.apiToken || credentials.accessToken || credentials.apiKey;
199
+ if (token) {
200
+ return token;
201
+ }
202
+ }
177
203
 
178
- const token = credentials.apiToken || credentials.accessToken || credentials.apiKey;
179
- if (!token) {
180
- throw new Error(`No API token found for ${this.integrationName} integration for company ${effectiveCompanyId}. Please configure credentials in Company Integrations or set environment variable BIZAPPS_${this.formPlatform.toUpperCase().replace(/\s+/g, '_')}_${effectiveCompanyId}_API_TOKEN`);
204
+ // No credentials found
205
+ const platformKey = this.formPlatform.toUpperCase().replace(/\s+/g, '_');
206
+ const envVarSuggestion = companyId
207
+ ? `BIZAPPS_${platformKey}_${companyId}_API_TOKEN or BIZAPPS_${platformKey}_API_TOKEN`
208
+ : `BIZAPPS_${platformKey}_API_TOKEN`;
209
+
210
+ throw new Error(`No API token found for ${this.integrationName} integration. Please set environment variable ${envVarSuggestion} or configure in Company Integrations table.`);
211
+ }
212
+
213
+ /**
214
+ * Creates an OAuth2Manager instance for the specified company.
215
+ * Override this method in provider-specific base classes to configure OAuth2 endpoints.
216
+ *
217
+ * @param companyId - The MemberJunction company ID
218
+ * @param contextUser - The user context
219
+ * @returns OAuth2Manager instance or null if OAuth2 is not configured
220
+ */
221
+ protected async createOAuth2Manager(companyId: string, contextUser: UserInfo): Promise<OAuth2Manager | null> {
222
+ // Check for OAuth2 credentials in environment variables
223
+ const platformKey = this.formPlatform.toUpperCase().replace(/\s+/g, '_');
224
+ const clientId = process.env[`BIZAPPS_${platformKey}_CLIENT_ID`];
225
+ const clientSecret = process.env[`BIZAPPS_${platformKey}_CLIENT_SECRET`];
226
+
227
+ if (!clientId || !clientSecret) {
228
+ return null; // OAuth2 not configured
181
229
  }
182
230
 
183
- return token;
231
+ // Subclasses should override this method to provide proper endpoints
232
+ throw new Error(`OAuth2 endpoints not configured for ${this.formPlatform}. Override createOAuth2Manager() in your provider base class.`);
184
233
  }
185
234
 
186
235
  /**
@@ -253,7 +302,7 @@ export abstract class BaseFormBuilderAction extends BaseAction {
253
302
  const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
254
303
 
255
304
  for (const response of responses) {
256
- for (const answer of response.answers) {
305
+ for (const answer of response.answerDetails) {
257
306
  if (answer.fieldType === 'email' ||
258
307
  (typeof answer.answer === 'string' && emailRegex.test(answer.answer))) {
259
308
  emails.push(answer.answer);
package/src/index.ts CHANGED
@@ -11,8 +11,4 @@ export * from './providers/jotform';
11
11
  export * from './providers/surveymonkey';
12
12
 
13
13
  // Google Forms Provider
14
- export * from './providers/google-forms';
15
-
16
- // Package metadata
17
- export const PACKAGE_NAME = '@memberjunction/actions-bizapps-formbuilders';
18
- export const PACKAGE_VERSION = '2.110.1';
14
+ export * from './providers/google-forms';
@@ -26,7 +26,7 @@ import { BaseAction } from '@memberjunction/actions';
26
26
  * });
27
27
  * ```
28
28
  */
29
- @RegisterClass(BaseAction, 'Export Google Forms Responses to CSV')
29
+ @RegisterClass(BaseAction, 'ExportGoogleFormsCSVAction')
30
30
  export class ExportGoogleFormsCSVAction extends GoogleFormsBaseAction {
31
31
 
32
32
  public get Description(): string {
@@ -165,3 +165,10 @@ export class ExportGoogleFormsCSVAction extends GoogleFormsBaseAction {
165
165
  ];
166
166
  }
167
167
  }
168
+
169
+ /**
170
+ * Load function to prevent tree shaking
171
+ */
172
+ export function LoadExportGoogleFormsCSVAction(): void {
173
+ // Empty function to create static code path and prevent tree shaking
174
+ }
@@ -23,7 +23,7 @@ import { BaseAction } from '@memberjunction/actions';
23
23
  * });
24
24
  * ```
25
25
  */
26
- @RegisterClass(BaseAction, 'Get Google Forms Details')
26
+ @RegisterClass(BaseAction, 'GetGoogleFormAction')
27
27
  export class GetGoogleFormAction extends GoogleFormsBaseAction {
28
28
 
29
29
  public get Description(): string {
@@ -149,3 +149,10 @@ export class GetGoogleFormAction extends GoogleFormsBaseAction {
149
149
  ];
150
150
  }
151
151
  }
152
+
153
+ /**
154
+ * Load function to prevent tree shaking
155
+ */
156
+ export function LoadGetGoogleFormAction(): void {
157
+ // Empty function to create static code path and prevent tree shaking
158
+ }
@@ -26,7 +26,7 @@ import { BaseAction } from '@memberjunction/actions';
26
26
  * });
27
27
  * ```
28
28
  */
29
- @RegisterClass(BaseAction, 'Get Single Google Forms Response')
29
+ @RegisterClass(BaseAction, 'GetSingleGoogleFormsResponseAction')
30
30
  export class GetSingleGoogleFormsResponseAction extends GoogleFormsBaseAction {
31
31
 
32
32
  public get Description(): string {
@@ -148,3 +148,10 @@ export class GetSingleGoogleFormsResponseAction extends GoogleFormsBaseAction {
148
148
  ];
149
149
  }
150
150
  }
151
+
152
+ /**
153
+ * Load function to prevent tree shaking
154
+ */
155
+ export function LoadGetSingleGoogleFormsResponseAction(): void {
156
+ // Empty function to create static code path and prevent tree shaking
157
+ }
@@ -24,7 +24,7 @@ import { FormStatistics } from '../../../base/base-form-builder.action';
24
24
  * });
25
25
  * ```
26
26
  */
27
- @RegisterClass(BaseAction, 'Get Google Forms Response Statistics')
27
+ @RegisterClass(BaseAction, 'GetGoogleFormsStatisticsAction')
28
28
  export class GetGoogleFormsStatisticsAction extends GoogleFormsBaseAction {
29
29
 
30
30
  public get Description(): string {
@@ -92,7 +92,7 @@ export class GetGoogleFormsStatisticsAction extends GoogleFormsBaseAction {
92
92
  const allFieldIds = new Set<string>();
93
93
 
94
94
  for (const response of responses) {
95
- for (const answer of response.answers) {
95
+ for (const answer of response.answerDetails) {
96
96
  allFieldIds.add(answer.fieldId);
97
97
  }
98
98
  }
@@ -271,3 +271,10 @@ export class GetGoogleFormsStatisticsAction extends GoogleFormsBaseAction {
271
271
  ];
272
272
  }
273
273
  }
274
+
275
+ /**
276
+ * Load function to prevent tree shaking
277
+ */
278
+ export function LoadGetGoogleFormsStatisticsAction(): void {
279
+ // Empty function to create static code path and prevent tree shaking
280
+ }
@@ -5,3 +5,20 @@ export * from './export-csv.action';
5
5
 
6
6
  // Google Forms Form Management Actions
7
7
  export * from './get-form.action';
8
+
9
+ // Import Load functions
10
+ import { LoadGetSingleGoogleFormsResponseAction } from './get-single-response.action';
11
+ import { LoadGetGoogleFormsStatisticsAction } from './get-statistics.action';
12
+ import { LoadExportGoogleFormsCSVAction } from './export-csv.action';
13
+ import { LoadGetGoogleFormAction } from './get-form.action';
14
+
15
+ /**
16
+ * Load all Google Forms actions to prevent tree shaking.
17
+ * Call this function from consuming packages to ensure all action classes are included in the bundle.
18
+ */
19
+ export function LoadAllGoogleFormsActions(): void {
20
+ LoadGetSingleGoogleFormsResponseAction();
21
+ LoadGetGoogleFormsStatisticsAction();
22
+ LoadExportGoogleFormsCSVAction();
23
+ LoadGetGoogleFormAction();
24
+ }
@@ -385,7 +385,8 @@ export abstract class GoogleFormsBaseAction extends BaseFormBuilderAction {
385
385
  formId: '', // Form ID is not included in response object, needs to be passed separately
386
386
  submittedAt,
387
387
  completed,
388
- answers,
388
+ answerDetails: answers, // For now, use answers as answerDetails since Google Forms doesn't have simpleAnswers
389
+ answers: {}, // Empty object for now - could be implemented later
389
390
  metadata: {
390
391
  userAgent: gfResponse.respondentEmail,
391
392
  platform: 'Google Forms'