@memberjunction/actions-bizapps-formbuilders 2.112.0-beta

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 (219) hide show
  1. package/IMPLEMENTATION_PLAN.md +311 -0
  2. package/README.md +498 -0
  3. package/dist/base/base-form-builder.action.d.ts +153 -0
  4. package/dist/base/base-form-builder.action.d.ts.map +1 -0
  5. package/dist/base/base-form-builder.action.js +301 -0
  6. package/dist/base/base-form-builder.action.js.map +1 -0
  7. package/dist/base/index.d.ts +2 -0
  8. package/dist/base/index.d.ts.map +1 -0
  9. package/dist/base/index.js +18 -0
  10. package/dist/base/index.js.map +1 -0
  11. package/dist/index.d.ts +8 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +31 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/providers/google-forms/actions/export-csv.action.d.ts +31 -0
  16. package/dist/providers/google-forms/actions/export-csv.action.d.ts.map +1 -0
  17. package/dist/providers/google-forms/actions/export-csv.action.js +165 -0
  18. package/dist/providers/google-forms/actions/export-csv.action.js.map +1 -0
  19. package/dist/providers/google-forms/actions/get-form.action.d.ts +28 -0
  20. package/dist/providers/google-forms/actions/get-form.action.d.ts.map +1 -0
  21. package/dist/providers/google-forms/actions/get-form.action.js +151 -0
  22. package/dist/providers/google-forms/actions/get-form.action.js.map +1 -0
  23. package/dist/providers/google-forms/actions/get-single-response.action.d.ts +31 -0
  24. package/dist/providers/google-forms/actions/get-single-response.action.d.ts.map +1 -0
  25. package/dist/providers/google-forms/actions/get-single-response.action.js +150 -0
  26. package/dist/providers/google-forms/actions/get-single-response.action.js.map +1 -0
  27. package/dist/providers/google-forms/actions/get-statistics.action.d.ts +36 -0
  28. package/dist/providers/google-forms/actions/get-statistics.action.d.ts.map +1 -0
  29. package/dist/providers/google-forms/actions/get-statistics.action.js +254 -0
  30. package/dist/providers/google-forms/actions/get-statistics.action.js.map +1 -0
  31. package/dist/providers/google-forms/actions/index.d.ts +5 -0
  32. package/dist/providers/google-forms/actions/index.d.ts.map +1 -0
  33. package/dist/providers/google-forms/actions/index.js +23 -0
  34. package/dist/providers/google-forms/actions/index.js.map +1 -0
  35. package/dist/providers/google-forms/googleforms-base.action.d.ts +197 -0
  36. package/dist/providers/google-forms/googleforms-base.action.d.ts.map +1 -0
  37. package/dist/providers/google-forms/googleforms-base.action.js +352 -0
  38. package/dist/providers/google-forms/googleforms-base.action.js.map +1 -0
  39. package/dist/providers/google-forms/index.d.ts +3 -0
  40. package/dist/providers/google-forms/index.d.ts.map +1 -0
  41. package/dist/providers/google-forms/index.js +21 -0
  42. package/dist/providers/google-forms/index.js.map +1 -0
  43. package/dist/providers/jotform/actions/create-form.action.d.ts +61 -0
  44. package/dist/providers/jotform/actions/create-form.action.d.ts.map +1 -0
  45. package/dist/providers/jotform/actions/create-form.action.js +259 -0
  46. package/dist/providers/jotform/actions/create-form.action.js.map +1 -0
  47. package/dist/providers/jotform/actions/export-csv.action.d.ts +31 -0
  48. package/dist/providers/jotform/actions/export-csv.action.d.ts.map +1 -0
  49. package/dist/providers/jotform/actions/export-csv.action.js +187 -0
  50. package/dist/providers/jotform/actions/export-csv.action.js.map +1 -0
  51. package/dist/providers/jotform/actions/get-form.action.d.ts +31 -0
  52. package/dist/providers/jotform/actions/get-form.action.d.ts.map +1 -0
  53. package/dist/providers/jotform/actions/get-form.action.js +188 -0
  54. package/dist/providers/jotform/actions/get-form.action.js.map +1 -0
  55. package/dist/providers/jotform/actions/get-single-submission.action.d.ts +31 -0
  56. package/dist/providers/jotform/actions/get-single-submission.action.d.ts.map +1 -0
  57. package/dist/providers/jotform/actions/get-single-submission.action.js +138 -0
  58. package/dist/providers/jotform/actions/get-single-submission.action.js.map +1 -0
  59. package/dist/providers/jotform/actions/get-statistics.action.d.ts +39 -0
  60. package/dist/providers/jotform/actions/get-statistics.action.d.ts.map +1 -0
  61. package/dist/providers/jotform/actions/get-statistics.action.js +290 -0
  62. package/dist/providers/jotform/actions/get-statistics.action.js.map +1 -0
  63. package/dist/providers/jotform/actions/get-submissions.action.d.ts +34 -0
  64. package/dist/providers/jotform/actions/get-submissions.action.d.ts.map +1 -0
  65. package/dist/providers/jotform/actions/get-submissions.action.js +218 -0
  66. package/dist/providers/jotform/actions/get-submissions.action.js.map +1 -0
  67. package/dist/providers/jotform/actions/index.d.ts +9 -0
  68. package/dist/providers/jotform/actions/index.d.ts.map +1 -0
  69. package/dist/providers/jotform/actions/index.js +27 -0
  70. package/dist/providers/jotform/actions/index.js.map +1 -0
  71. package/dist/providers/jotform/actions/update-form.action.d.ts +38 -0
  72. package/dist/providers/jotform/actions/update-form.action.d.ts.map +1 -0
  73. package/dist/providers/jotform/actions/update-form.action.js +232 -0
  74. package/dist/providers/jotform/actions/update-form.action.js.map +1 -0
  75. package/dist/providers/jotform/actions/watch-new-submissions.action.d.ts +32 -0
  76. package/dist/providers/jotform/actions/watch-new-submissions.action.d.ts.map +1 -0
  77. package/dist/providers/jotform/actions/watch-new-submissions.action.js +229 -0
  78. package/dist/providers/jotform/actions/watch-new-submissions.action.js.map +1 -0
  79. package/dist/providers/jotform/index.d.ts +3 -0
  80. package/dist/providers/jotform/index.d.ts.map +1 -0
  81. package/dist/providers/jotform/index.js +21 -0
  82. package/dist/providers/jotform/index.js.map +1 -0
  83. package/dist/providers/jotform/jotform-base.action.d.ts +96 -0
  84. package/dist/providers/jotform/jotform-base.action.d.ts.map +1 -0
  85. package/dist/providers/jotform/jotform-base.action.js +269 -0
  86. package/dist/providers/jotform/jotform-base.action.js.map +1 -0
  87. package/dist/providers/surveymonkey/actions/create-survey.action.d.ts +48 -0
  88. package/dist/providers/surveymonkey/actions/create-survey.action.d.ts.map +1 -0
  89. package/dist/providers/surveymonkey/actions/create-survey.action.js +192 -0
  90. package/dist/providers/surveymonkey/actions/create-survey.action.js.map +1 -0
  91. package/dist/providers/surveymonkey/actions/export-csv.action.d.ts +30 -0
  92. package/dist/providers/surveymonkey/actions/export-csv.action.d.ts.map +1 -0
  93. package/dist/providers/surveymonkey/actions/export-csv.action.js +173 -0
  94. package/dist/providers/surveymonkey/actions/export-csv.action.js.map +1 -0
  95. package/dist/providers/surveymonkey/actions/get-responses.action.d.ts +33 -0
  96. package/dist/providers/surveymonkey/actions/get-responses.action.d.ts.map +1 -0
  97. package/dist/providers/surveymonkey/actions/get-responses.action.js +243 -0
  98. package/dist/providers/surveymonkey/actions/get-responses.action.js.map +1 -0
  99. package/dist/providers/surveymonkey/actions/get-single-response.action.d.ts +30 -0
  100. package/dist/providers/surveymonkey/actions/get-single-response.action.d.ts.map +1 -0
  101. package/dist/providers/surveymonkey/actions/get-single-response.action.js +149 -0
  102. package/dist/providers/surveymonkey/actions/get-single-response.action.js.map +1 -0
  103. package/dist/providers/surveymonkey/actions/get-statistics.action.d.ts +38 -0
  104. package/dist/providers/surveymonkey/actions/get-statistics.action.d.ts.map +1 -0
  105. package/dist/providers/surveymonkey/actions/get-statistics.action.js +261 -0
  106. package/dist/providers/surveymonkey/actions/get-statistics.action.js.map +1 -0
  107. package/dist/providers/surveymonkey/actions/get-survey.action.d.ts +27 -0
  108. package/dist/providers/surveymonkey/actions/get-survey.action.d.ts.map +1 -0
  109. package/dist/providers/surveymonkey/actions/get-survey.action.js +180 -0
  110. package/dist/providers/surveymonkey/actions/get-survey.action.js.map +1 -0
  111. package/dist/providers/surveymonkey/actions/index.d.ts +9 -0
  112. package/dist/providers/surveymonkey/actions/index.d.ts.map +1 -0
  113. package/dist/providers/surveymonkey/actions/index.js +27 -0
  114. package/dist/providers/surveymonkey/actions/index.js.map +1 -0
  115. package/dist/providers/surveymonkey/actions/update-survey.action.d.ts +39 -0
  116. package/dist/providers/surveymonkey/actions/update-survey.action.d.ts.map +1 -0
  117. package/dist/providers/surveymonkey/actions/update-survey.action.js +217 -0
  118. package/dist/providers/surveymonkey/actions/update-survey.action.js.map +1 -0
  119. package/dist/providers/surveymonkey/actions/watch-new-responses.action.d.ts +31 -0
  120. package/dist/providers/surveymonkey/actions/watch-new-responses.action.d.ts.map +1 -0
  121. package/dist/providers/surveymonkey/actions/watch-new-responses.action.js +214 -0
  122. package/dist/providers/surveymonkey/actions/watch-new-responses.action.js.map +1 -0
  123. package/dist/providers/surveymonkey/index.d.ts +3 -0
  124. package/dist/providers/surveymonkey/index.d.ts.map +1 -0
  125. package/dist/providers/surveymonkey/index.js +21 -0
  126. package/dist/providers/surveymonkey/index.js.map +1 -0
  127. package/dist/providers/surveymonkey/surveymonkey-base.action.d.ts +193 -0
  128. package/dist/providers/surveymonkey/surveymonkey-base.action.d.ts.map +1 -0
  129. package/dist/providers/surveymonkey/surveymonkey-base.action.js +329 -0
  130. package/dist/providers/surveymonkey/surveymonkey-base.action.js.map +1 -0
  131. package/dist/providers/typeform/actions/create-form.action.d.ts +40 -0
  132. package/dist/providers/typeform/actions/create-form.action.d.ts.map +1 -0
  133. package/dist/providers/typeform/actions/create-form.action.js +205 -0
  134. package/dist/providers/typeform/actions/create-form.action.js.map +1 -0
  135. package/dist/providers/typeform/actions/export-csv.action.d.ts +31 -0
  136. package/dist/providers/typeform/actions/export-csv.action.d.ts.map +1 -0
  137. package/dist/providers/typeform/actions/export-csv.action.js +182 -0
  138. package/dist/providers/typeform/actions/export-csv.action.js.map +1 -0
  139. package/dist/providers/typeform/actions/get-form.action.d.ts +28 -0
  140. package/dist/providers/typeform/actions/get-form.action.d.ts.map +1 -0
  141. package/dist/providers/typeform/actions/get-form.action.js +172 -0
  142. package/dist/providers/typeform/actions/get-form.action.js.map +1 -0
  143. package/dist/providers/typeform/actions/get-responses.action.d.ts +34 -0
  144. package/dist/providers/typeform/actions/get-responses.action.d.ts.map +1 -0
  145. package/dist/providers/typeform/actions/get-responses.action.js +238 -0
  146. package/dist/providers/typeform/actions/get-responses.action.js.map +1 -0
  147. package/dist/providers/typeform/actions/get-single-response.action.d.ts +31 -0
  148. package/dist/providers/typeform/actions/get-single-response.action.d.ts.map +1 -0
  149. package/dist/providers/typeform/actions/get-single-response.action.js +161 -0
  150. package/dist/providers/typeform/actions/get-single-response.action.js.map +1 -0
  151. package/dist/providers/typeform/actions/get-statistics.action.d.ts +33 -0
  152. package/dist/providers/typeform/actions/get-statistics.action.d.ts.map +1 -0
  153. package/dist/providers/typeform/actions/get-statistics.action.js +257 -0
  154. package/dist/providers/typeform/actions/get-statistics.action.js.map +1 -0
  155. package/dist/providers/typeform/actions/index.d.ts +9 -0
  156. package/dist/providers/typeform/actions/index.d.ts.map +1 -0
  157. package/dist/providers/typeform/actions/index.js +27 -0
  158. package/dist/providers/typeform/actions/index.js.map +1 -0
  159. package/dist/providers/typeform/actions/update-form.action.d.ts +38 -0
  160. package/dist/providers/typeform/actions/update-form.action.d.ts.map +1 -0
  161. package/dist/providers/typeform/actions/update-form.action.js +228 -0
  162. package/dist/providers/typeform/actions/update-form.action.js.map +1 -0
  163. package/dist/providers/typeform/actions/watch-new-responses.action.d.ts +32 -0
  164. package/dist/providers/typeform/actions/watch-new-responses.action.d.ts.map +1 -0
  165. package/dist/providers/typeform/actions/watch-new-responses.action.js +215 -0
  166. package/dist/providers/typeform/actions/watch-new-responses.action.js.map +1 -0
  167. package/dist/providers/typeform/index.d.ts +3 -0
  168. package/dist/providers/typeform/index.d.ts.map +1 -0
  169. package/dist/providers/typeform/index.js +21 -0
  170. package/dist/providers/typeform/index.js.map +1 -0
  171. package/dist/providers/typeform/typeform-base.action.d.ts +121 -0
  172. package/dist/providers/typeform/typeform-base.action.d.ts.map +1 -0
  173. package/dist/providers/typeform/typeform-base.action.js +292 -0
  174. package/dist/providers/typeform/typeform-base.action.js.map +1 -0
  175. package/package.json +41 -0
  176. package/src/base/base-form-builder.action.ts +403 -0
  177. package/src/base/index.ts +1 -0
  178. package/src/index.ts +18 -0
  179. package/src/providers/google-forms/actions/export-csv.action.ts +167 -0
  180. package/src/providers/google-forms/actions/get-form.action.ts +151 -0
  181. package/src/providers/google-forms/actions/get-single-response.action.ts +150 -0
  182. package/src/providers/google-forms/actions/get-statistics.action.ts +273 -0
  183. package/src/providers/google-forms/actions/index.ts +7 -0
  184. package/src/providers/google-forms/googleforms-base.action.ts +517 -0
  185. package/src/providers/google-forms/index.ts +5 -0
  186. package/src/providers/jotform/actions/create-form.action.ts +281 -0
  187. package/src/providers/jotform/actions/export-csv.action.ts +189 -0
  188. package/src/providers/jotform/actions/get-form.action.ts +189 -0
  189. package/src/providers/jotform/actions/get-single-submission.action.ts +137 -0
  190. package/src/providers/jotform/actions/get-statistics.action.ts +308 -0
  191. package/src/providers/jotform/actions/get-submissions.action.ts +220 -0
  192. package/src/providers/jotform/actions/index.ts +11 -0
  193. package/src/providers/jotform/actions/update-form.action.ts +254 -0
  194. package/src/providers/jotform/actions/watch-new-submissions.action.ts +238 -0
  195. package/src/providers/jotform/index.ts +5 -0
  196. package/src/providers/jotform/jotform-base.action.ts +365 -0
  197. package/src/providers/surveymonkey/actions/create-survey.action.ts +196 -0
  198. package/src/providers/surveymonkey/actions/export-csv.action.ts +175 -0
  199. package/src/providers/surveymonkey/actions/get-responses.action.ts +245 -0
  200. package/src/providers/surveymonkey/actions/get-single-response.action.ts +148 -0
  201. package/src/providers/surveymonkey/actions/get-statistics.action.ts +280 -0
  202. package/src/providers/surveymonkey/actions/get-survey.action.ts +181 -0
  203. package/src/providers/surveymonkey/actions/index.ts +11 -0
  204. package/src/providers/surveymonkey/actions/update-survey.action.ts +234 -0
  205. package/src/providers/surveymonkey/actions/watch-new-responses.action.ts +221 -0
  206. package/src/providers/surveymonkey/index.ts +5 -0
  207. package/src/providers/surveymonkey/surveymonkey-base.action.ts +505 -0
  208. package/src/providers/typeform/actions/create-form.action.ts +211 -0
  209. package/src/providers/typeform/actions/export-csv.action.ts +184 -0
  210. package/src/providers/typeform/actions/get-form.action.ts +173 -0
  211. package/src/providers/typeform/actions/get-responses.action.ts +242 -0
  212. package/src/providers/typeform/actions/get-single-response.action.ts +160 -0
  213. package/src/providers/typeform/actions/get-statistics.action.ts +276 -0
  214. package/src/providers/typeform/actions/index.ts +11 -0
  215. package/src/providers/typeform/actions/update-form.action.ts +235 -0
  216. package/src/providers/typeform/actions/watch-new-responses.action.ts +222 -0
  217. package/src/providers/typeform/index.ts +5 -0
  218. package/src/providers/typeform/typeform-base.action.ts +387 -0
  219. package/tsconfig.json +18 -0
@@ -0,0 +1,160 @@
1
+ import { RegisterClass } from '@memberjunction/global';
2
+ import { TypeformBaseAction } from '../typeform-base.action';
3
+ import { ActionParam, ActionResultSimple, RunActionParams } from '@memberjunction/actions-base';
4
+ import { BaseAction } from '@memberjunction/actions';
5
+
6
+ /**
7
+ * Action to retrieve a specific response from Typeform by response token
8
+ *
9
+ * Security: API credentials are retrieved securely from Company Integrations table or environment variables.
10
+ * Never pass API tokens as action parameters.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * await runAction({
15
+ * ActionName: 'Get Single Typeform Response',
16
+ * Params: [{
17
+ * Name: 'CompanyID',
18
+ * Value: '12345'
19
+ * }, {
20
+ * Name: 'FormID',
21
+ * Value: 'abc123'
22
+ * }, {
23
+ * Name: 'ResponseToken',
24
+ * Value: 'xyz789'
25
+ * }]
26
+ * });
27
+ * ```
28
+ */
29
+ @RegisterClass(BaseAction, 'Get Single Typeform Response')
30
+ export class GetSingleTypeformResponseAction extends TypeformBaseAction {
31
+
32
+ public get Description(): string {
33
+ return 'Retrieves details of a specific Typeform response by its unique response token. Includes all answers, metadata, hidden fields, and calculated values.';
34
+ }
35
+
36
+ protected async InternalRunAction(params: RunActionParams): Promise<ActionResultSimple> {
37
+ try {
38
+ const contextUser = params.ContextUser;
39
+ if (!contextUser) {
40
+ return {
41
+ Success: false,
42
+ ResultCode: 'MISSING_CONTEXT_USER',
43
+ Message: 'Context user is required for Typeform API calls'
44
+ };
45
+ }
46
+
47
+ const companyId = this.getParamValue(params.Params, 'CompanyID');
48
+
49
+ const formId = this.getParamValue(params.Params, 'FormID');
50
+ if (!formId) {
51
+ return {
52
+ Success: false,
53
+ ResultCode: 'MISSING_FORM_ID',
54
+ Message: 'FormID parameter is required'
55
+ };
56
+ }
57
+
58
+ const responseToken = this.getParamValue(params.Params, 'ResponseToken');
59
+ if (!responseToken) {
60
+ return {
61
+ Success: false,
62
+ ResultCode: 'MISSING_RESPONSE_TOKEN',
63
+ Message: 'ResponseToken parameter is required'
64
+ };
65
+ }
66
+
67
+ // Securely retrieve API token using company integration
68
+ const apiToken = await this.getSecureAPIToken(companyId, contextUser);
69
+
70
+ const tfResponse = await this.getSingleTypeformResponse(formId, responseToken, apiToken);
71
+ const normalizedResponse = this.normalizeTypeformResponse(tfResponse);
72
+
73
+ const outputParams: ActionParam[] = [
74
+ {
75
+ Name: 'Response',
76
+ Type: 'Output',
77
+ Value: normalizedResponse
78
+ },
79
+ {
80
+ Name: 'ResponseID',
81
+ Type: 'Output',
82
+ Value: normalizedResponse.responseId
83
+ },
84
+ {
85
+ Name: 'SubmittedAt',
86
+ Type: 'Output',
87
+ Value: normalizedResponse.submittedAt
88
+ },
89
+ {
90
+ Name: 'Completed',
91
+ Type: 'Output',
92
+ Value: normalizedResponse.completed
93
+ },
94
+ {
95
+ Name: 'Answers',
96
+ Type: 'Output',
97
+ Value: normalizedResponse.answers
98
+ },
99
+ {
100
+ Name: 'Metadata',
101
+ Type: 'Output',
102
+ Value: normalizedResponse.metadata
103
+ },
104
+ {
105
+ Name: 'HiddenFields',
106
+ Type: 'Output',
107
+ Value: normalizedResponse.hiddenFields
108
+ },
109
+ {
110
+ Name: 'CalculatedFields',
111
+ Type: 'Output',
112
+ Value: normalizedResponse.calculatedFields
113
+ }
114
+ ];
115
+
116
+ for (const outputParam of outputParams) {
117
+ const existingParam = params.Params.find(p => p.Name === outputParam.Name);
118
+ if (existingParam) {
119
+ existingParam.Value = outputParam.Value;
120
+ } else {
121
+ params.Params.push(outputParam);
122
+ }
123
+ }
124
+
125
+ return {
126
+ Success: true,
127
+ ResultCode: 'SUCCESS',
128
+ Message: `Successfully retrieved response ${responseToken} from Typeform`
129
+ };
130
+
131
+ } catch (error) {
132
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
133
+ return {
134
+ Success: false,
135
+ ResultCode: 'ERROR',
136
+ Message: this.buildFormErrorMessage('Get Single Typeform Response', errorMessage, error)
137
+ };
138
+ }
139
+ }
140
+
141
+ public get Params(): ActionParam[] {
142
+ return [
143
+ {
144
+ Name: 'CompanyID',
145
+ Type: 'Input',
146
+ Value: null,
147
+ },
148
+ {
149
+ Name: 'FormID',
150
+ Type: 'Input',
151
+ Value: null,
152
+ },
153
+ {
154
+ Name: 'ResponseToken',
155
+ Type: 'Input',
156
+ Value: null,
157
+ }
158
+ ];
159
+ }
160
+ }
@@ -0,0 +1,276 @@
1
+ import { RegisterClass } from '@memberjunction/global';
2
+ import { TypeformBaseAction } from '../typeform-base.action';
3
+ import { ActionParam, ActionResultSimple, RunActionParams } from '@memberjunction/actions-base';
4
+ import { BaseAction } from '@memberjunction/actions';
5
+ import { FormStatistics } from '../../../base/base-form-builder.action';
6
+
7
+ /**
8
+ * Action to calculate aggregate statistics from Typeform responses
9
+ *
10
+ * Security: API credentials are retrieved securely from Company Integrations table or environment variables.
11
+ * Never pass API tokens as action parameters.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * await runAction({
16
+ * ActionName: 'Get Typeform Response Statistics',
17
+ * Params: [{
18
+ * Name: 'CompanyID',
19
+ * Value: '12345'
20
+ * }, {
21
+ * Name: 'FormID',
22
+ * Value: 'abc123'
23
+ * }, {
24
+ * Name: 'Since',
25
+ * Value: '2024-01-01T00:00:00Z'
26
+ * }]
27
+ * });
28
+ * ```
29
+ */
30
+ @RegisterClass(BaseAction, 'Get Typeform Response Statistics')
31
+ export class GetTypeformStatisticsAction extends TypeformBaseAction {
32
+
33
+ public get Description(): string {
34
+ return 'Calculates comprehensive statistics from Typeform responses including completion rates, response trends, popular answers, and time-based analytics. Useful for dashboards and reporting.';
35
+ }
36
+
37
+ protected async InternalRunAction(params: RunActionParams): Promise<ActionResultSimple> {
38
+ try {
39
+ const contextUser = params.ContextUser;
40
+ if (!contextUser) {
41
+ return {
42
+ Success: false,
43
+ ResultCode: 'MISSING_CONTEXT_USER',
44
+ Message: 'Context user is required for Typeform API calls'
45
+ };
46
+ }
47
+
48
+ const companyId = this.getParamValue(params.Params, 'CompanyID');
49
+
50
+ const formId = this.getParamValue(params.Params, 'FormID');
51
+ if (!formId) {
52
+ return {
53
+ Success: false,
54
+ ResultCode: 'MISSING_FORM_ID',
55
+ Message: 'FormID parameter is required'
56
+ };
57
+ }
58
+
59
+ // Securely retrieve API token using company integration
60
+ const apiToken = await this.getSecureAPIToken(companyId, contextUser);
61
+
62
+ const since = this.getParamValue(params.Params, 'Since');
63
+ const until = this.getParamValue(params.Params, 'Until');
64
+ const maxResponses = this.getParamValue(params.Params, 'MaxResponses') || 10000;
65
+ const includeTopAnswers = this.getParamValue(params.Params, 'IncludeTopAnswers') !== false;
66
+ const topAnswersLimit = this.getParamValue(params.Params, 'TopAnswersLimit') || 10;
67
+
68
+ const tfResponses = await this.getAllTypeformResponses(formId, apiToken, {
69
+ since,
70
+ until,
71
+ maxResponses
72
+ });
73
+
74
+ const responses = tfResponses.map(r => this.normalizeTypeformResponse(r));
75
+
76
+ const completedResponses = responses.filter(r => r.completed);
77
+ const partialResponses = responses.filter(r => !r.completed);
78
+ const completionRate = this.calculateCompletionRate(
79
+ completedResponses.length,
80
+ responses.length
81
+ );
82
+
83
+ const responsesByDate = this.groupResponsesByDate(responses);
84
+
85
+ const statistics: FormStatistics = {
86
+ totalResponses: responses.length,
87
+ completedResponses: completedResponses.length,
88
+ partialResponses: partialResponses.length,
89
+ completionRate,
90
+ averageCompletionTime: this.calculateAverageCompletionTime(responses),
91
+ responsesByDate
92
+ };
93
+
94
+ if (includeTopAnswers && responses.length > 0) {
95
+ const topAnswers: Record<string, Array<{ answer: string; count: number }>> = {};
96
+ const allFieldIds = new Set<string>();
97
+
98
+ for (const response of responses) {
99
+ for (const answer of response.answers) {
100
+ allFieldIds.add(answer.fieldId);
101
+ }
102
+ }
103
+
104
+ for (const fieldId of allFieldIds) {
105
+ const fieldTopAnswers = this.findTopAnswers(responses, fieldId, topAnswersLimit);
106
+ if (fieldTopAnswers.length > 0) {
107
+ topAnswers[fieldId] = fieldTopAnswers;
108
+ }
109
+ }
110
+
111
+ statistics.topAnswers = topAnswers;
112
+ }
113
+
114
+ const dailyBreakdown = this.calculateDailyBreakdown(responses);
115
+ const hourlyDistribution = this.calculateHourlyDistribution(responses);
116
+
117
+ const outputParams: ActionParam[] = [
118
+ {
119
+ Name: 'Statistics',
120
+ Type: 'Output',
121
+ Value: statistics
122
+ },
123
+ {
124
+ Name: 'TotalResponses',
125
+ Type: 'Output',
126
+ Value: statistics.totalResponses
127
+ },
128
+ {
129
+ Name: 'CompletedResponses',
130
+ Type: 'Output',
131
+ Value: statistics.completedResponses
132
+ },
133
+ {
134
+ Name: 'PartialResponses',
135
+ Type: 'Output',
136
+ Value: statistics.partialResponses
137
+ },
138
+ {
139
+ Name: 'CompletionRate',
140
+ Type: 'Output',
141
+ Value: statistics.completionRate
142
+ },
143
+ {
144
+ Name: 'AverageCompletionTime',
145
+ Type: 'Output',
146
+ Value: statistics.averageCompletionTime
147
+ },
148
+ {
149
+ Name: 'ResponsesByDate',
150
+ Type: 'Output',
151
+ Value: statistics.responsesByDate
152
+ },
153
+ {
154
+ Name: 'DailyBreakdown',
155
+ Type: 'Output',
156
+ Value: dailyBreakdown
157
+ },
158
+ {
159
+ Name: 'HourlyDistribution',
160
+ Type: 'Output',
161
+ Value: hourlyDistribution
162
+ }
163
+ ];
164
+
165
+ if (includeTopAnswers) {
166
+ outputParams.push({
167
+ Name: 'TopAnswers',
168
+ Type: 'Output',
169
+ Value: statistics.topAnswers
170
+ });
171
+ }
172
+
173
+ for (const outputParam of outputParams) {
174
+ const existingParam = params.Params.find(p => p.Name === outputParam.Name);
175
+ if (existingParam) {
176
+ existingParam.Value = outputParam.Value;
177
+ } else {
178
+ params.Params.push(outputParam);
179
+ }
180
+ }
181
+
182
+ return {
183
+ Success: true,
184
+ ResultCode: 'SUCCESS',
185
+ Message: `Successfully calculated statistics from ${responses.length} Typeform responses (${completionRate}% completion rate)`
186
+ };
187
+
188
+ } catch (error) {
189
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
190
+ return {
191
+ Success: false,
192
+ ResultCode: 'ERROR',
193
+ Message: this.buildFormErrorMessage('Get Typeform Statistics', errorMessage, error)
194
+ };
195
+ }
196
+ }
197
+
198
+ private calculateDailyBreakdown(responses: any[]): Array<{ date: string; count: number; completed: number; partial: number }> {
199
+ const daily: Record<string, { count: number; completed: number; partial: number }> = {};
200
+
201
+ for (const response of responses) {
202
+ const dateKey = response.submittedAt.toISOString().split('T')[0];
203
+ if (!daily[dateKey]) {
204
+ daily[dateKey] = { count: 0, completed: 0, partial: 0 };
205
+ }
206
+ daily[dateKey].count++;
207
+ if (response.completed) {
208
+ daily[dateKey].completed++;
209
+ } else {
210
+ daily[dateKey].partial++;
211
+ }
212
+ }
213
+
214
+ return Object.entries(daily)
215
+ .map(([date, stats]) => ({ date, ...stats }))
216
+ .sort((a, b) => a.date.localeCompare(b.date));
217
+ }
218
+
219
+ private calculateHourlyDistribution(responses: any[]): Array<{ hour: number; count: number }> {
220
+ const hourly: Record<number, number> = {};
221
+
222
+ for (let i = 0; i < 24; i++) {
223
+ hourly[i] = 0;
224
+ }
225
+
226
+ for (const response of responses) {
227
+ const hour = response.submittedAt.getHours();
228
+ hourly[hour]++;
229
+ }
230
+
231
+ return Object.entries(hourly).map(([hour, count]) => ({
232
+ hour: parseInt(hour),
233
+ count
234
+ }));
235
+ }
236
+
237
+ public get Params(): ActionParam[] {
238
+ return [
239
+ {
240
+ Name: 'CompanyID',
241
+ Type: 'Input',
242
+ Value: null,
243
+ },
244
+ {
245
+ Name: 'FormID',
246
+ Type: 'Input',
247
+ Value: null,
248
+ },
249
+ {
250
+ Name: 'Since',
251
+ Type: 'Input',
252
+ Value: null,
253
+ },
254
+ {
255
+ Name: 'Until',
256
+ Type: 'Input',
257
+ Value: null,
258
+ },
259
+ {
260
+ Name: 'MaxResponses',
261
+ Type: 'Input',
262
+ Value: 10000,
263
+ },
264
+ {
265
+ Name: 'IncludeTopAnswers',
266
+ Type: 'Input',
267
+ Value: true,
268
+ },
269
+ {
270
+ Name: 'TopAnswersLimit',
271
+ Type: 'Input',
272
+ Value: 10,
273
+ }
274
+ ];
275
+ }
276
+ }
@@ -0,0 +1,11 @@
1
+ // Typeform Response Actions
2
+ export * from './get-responses.action';
3
+ export * from './get-single-response.action';
4
+ export * from './get-statistics.action';
5
+ export * from './export-csv.action';
6
+ export * from './watch-new-responses.action';
7
+
8
+ // Typeform Form Management Actions
9
+ export * from './get-form.action';
10
+ export * from './create-form.action';
11
+ export * from './update-form.action';
@@ -0,0 +1,235 @@
1
+ import { RegisterClass } from '@memberjunction/global';
2
+ import { TypeformBaseAction } from '../typeform-base.action';
3
+ import { ActionParam, ActionResultSimple, RunActionParams } from '@memberjunction/actions-base';
4
+ import { BaseAction } from '@memberjunction/actions';
5
+
6
+ /**
7
+ * Action to update an existing Typeform
8
+ *
9
+ * IMPORTANT: This uses PUT which replaces the entire form. If you only provide some fields,
10
+ * the rest will be deleted. Use the MergeWithExisting parameter to automatically fetch
11
+ * the current form and merge your changes.
12
+ *
13
+ * Security: API credentials are retrieved securely from Company Integrations table or environment variables.
14
+ * Never pass API tokens as action parameters.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * await runAction({
19
+ * ActionName: 'Update Typeform',
20
+ * Params: [{
21
+ * Name: 'CompanyID',
22
+ * Value: '12345'
23
+ * }, {
24
+ * Name: 'FormID',
25
+ * Value: 'abc123'
26
+ * }, {
27
+ * Name: 'Title',
28
+ * Value: 'Updated Survey Title'
29
+ * }, {
30
+ * Name: 'MergeWithExisting',
31
+ * Value: true
32
+ * }]
33
+ * });
34
+ * ```
35
+ */
36
+ @RegisterClass(BaseAction, 'Update Typeform')
37
+ export class UpdateTypeformAction extends TypeformBaseAction {
38
+
39
+ public get Description(): string {
40
+ return 'Updates an existing Typeform. WARNING: Uses PUT which replaces all form data - fields not included will be deleted. Set MergeWithExisting=true to safely update only specified properties while preserving others.';
41
+ }
42
+
43
+ protected async InternalRunAction(params: RunActionParams): Promise<ActionResultSimple> {
44
+ try {
45
+ const contextUser = params.ContextUser;
46
+ if (!contextUser) {
47
+ return {
48
+ Success: false,
49
+ ResultCode: 'MISSING_CONTEXT_USER',
50
+ Message: 'Context user is required for Typeform API calls'
51
+ };
52
+ }
53
+
54
+ const companyId = this.getParamValue(params.Params, 'CompanyID');
55
+
56
+ const formId = this.getParamValue(params.Params, 'FormID');
57
+ if (!formId) {
58
+ return {
59
+ Success: false,
60
+ ResultCode: 'MISSING_FORM_ID',
61
+ Message: 'FormID parameter is required'
62
+ };
63
+ }
64
+
65
+ // Securely retrieve API token using company integration
66
+ const apiToken = await this.getSecureAPIToken(companyId, contextUser);
67
+
68
+ const mergeWithExisting = this.getParamValue(params.Params, 'MergeWithExisting') !== false;
69
+
70
+ let formData: any = {};
71
+
72
+ if (mergeWithExisting) {
73
+ const existingResponse = await this.getAxiosInstance(apiToken).get(`/forms/${formId}`);
74
+ formData = existingResponse.data;
75
+
76
+ delete formData.id;
77
+ delete formData._links;
78
+ delete formData.created_at;
79
+ delete formData.last_updated_at;
80
+ delete formData.self;
81
+ }
82
+
83
+ const title = this.getParamValue(params.Params, 'Title');
84
+ if (title) {
85
+ formData.title = title;
86
+ }
87
+
88
+ const fields = this.getParamValue(params.Params, 'Fields');
89
+ if (fields && Array.isArray(fields)) {
90
+ formData.fields = fields;
91
+ } else if (!mergeWithExisting) {
92
+ return {
93
+ Success: false,
94
+ ResultCode: 'MISSING_FIELDS',
95
+ Message: 'Fields parameter is required when MergeWithExisting is false'
96
+ };
97
+ }
98
+
99
+ const settings = this.getParamValue(params.Params, 'Settings');
100
+ if (settings) {
101
+ if (mergeWithExisting && formData.settings) {
102
+ formData.settings = { ...formData.settings, ...settings };
103
+ } else {
104
+ formData.settings = settings;
105
+ }
106
+ }
107
+
108
+ const logic = this.getParamValue(params.Params, 'Logic');
109
+ if (logic !== undefined) {
110
+ formData.logic = logic;
111
+ }
112
+
113
+ const hiddenFields = this.getParamValue(params.Params, 'HiddenFields');
114
+ if (hiddenFields !== undefined) {
115
+ formData.hidden = hiddenFields;
116
+ }
117
+
118
+ const themeId = this.getParamValue(params.Params, 'ThemeID');
119
+ if (themeId) {
120
+ formData.theme = { href: `https://api.typeform.com/themes/${themeId}` };
121
+ }
122
+
123
+ const response = await this.getAxiosInstance(apiToken).put(`/forms/${formId}`, formData);
124
+ const updatedForm = response.data;
125
+
126
+ const formUrl = updatedForm._links?.display || `https://form.typeform.com/to/${updatedForm.id}`;
127
+
128
+ const outputParams: ActionParam[] = [
129
+ {
130
+ Name: 'Form',
131
+ Type: 'Output',
132
+ Value: updatedForm
133
+ },
134
+ {
135
+ Name: 'FormID',
136
+ Type: 'Output',
137
+ Value: updatedForm.id
138
+ },
139
+ {
140
+ Name: 'FormURL',
141
+ Type: 'Output',
142
+ Value: formUrl
143
+ },
144
+ {
145
+ Name: 'Title',
146
+ Type: 'Output',
147
+ Value: updatedForm.title
148
+ },
149
+ {
150
+ Name: 'FieldCount',
151
+ Type: 'Output',
152
+ Value: updatedForm.fields?.length || 0
153
+ },
154
+ {
155
+ Name: 'LastUpdated',
156
+ Type: 'Output',
157
+ Value: updatedForm.last_updated_at ? new Date(updatedForm.last_updated_at) : new Date()
158
+ }
159
+ ];
160
+
161
+ for (const outputParam of outputParams) {
162
+ const existingParam = params.Params.find(p => p.Name === outputParam.Name);
163
+ if (existingParam) {
164
+ existingParam.Value = outputParam.Value;
165
+ } else {
166
+ params.Params.push(outputParam);
167
+ }
168
+ }
169
+
170
+ return {
171
+ Success: true,
172
+ ResultCode: 'SUCCESS',
173
+ Message: `Successfully updated form "${updatedForm.title}" (ID: ${updatedForm.id})`
174
+ };
175
+
176
+ } catch (error) {
177
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
178
+ return {
179
+ Success: false,
180
+ ResultCode: 'ERROR',
181
+ Message: this.buildFormErrorMessage('Update Typeform', errorMessage, error)
182
+ };
183
+ }
184
+ }
185
+
186
+ public get Params(): ActionParam[] {
187
+ return [
188
+ {
189
+ Name: 'CompanyID',
190
+ Type: 'Input',
191
+ Value: null,
192
+ },
193
+ {
194
+ Name: 'FormID',
195
+ Type: 'Input',
196
+ Value: null,
197
+ },
198
+ {
199
+ Name: 'MergeWithExisting',
200
+ Type: 'Input',
201
+ Value: true,
202
+ },
203
+ {
204
+ Name: 'Title',
205
+ Type: 'Input',
206
+ Value: null,
207
+ },
208
+ {
209
+ Name: 'Fields',
210
+ Type: 'Input',
211
+ Value: null,
212
+ },
213
+ {
214
+ Name: 'Settings',
215
+ Type: 'Input',
216
+ Value: null,
217
+ },
218
+ {
219
+ Name: 'Logic',
220
+ Type: 'Input',
221
+ Value: null,
222
+ },
223
+ {
224
+ Name: 'HiddenFields',
225
+ Type: 'Input',
226
+ Value: null,
227
+ },
228
+ {
229
+ Name: 'ThemeID',
230
+ Type: 'Input',
231
+ Value: null,
232
+ }
233
+ ];
234
+ }
235
+ }