@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.
- package/IMPLEMENTATION_PLAN.md +311 -0
- package/README.md +498 -0
- package/dist/base/base-form-builder.action.d.ts +153 -0
- package/dist/base/base-form-builder.action.d.ts.map +1 -0
- package/dist/base/base-form-builder.action.js +301 -0
- package/dist/base/base-form-builder.action.js.map +1 -0
- package/dist/base/index.d.ts +2 -0
- package/dist/base/index.d.ts.map +1 -0
- package/dist/base/index.js +18 -0
- package/dist/base/index.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/providers/google-forms/actions/export-csv.action.d.ts +31 -0
- package/dist/providers/google-forms/actions/export-csv.action.d.ts.map +1 -0
- package/dist/providers/google-forms/actions/export-csv.action.js +165 -0
- package/dist/providers/google-forms/actions/export-csv.action.js.map +1 -0
- package/dist/providers/google-forms/actions/get-form.action.d.ts +28 -0
- package/dist/providers/google-forms/actions/get-form.action.d.ts.map +1 -0
- package/dist/providers/google-forms/actions/get-form.action.js +151 -0
- package/dist/providers/google-forms/actions/get-form.action.js.map +1 -0
- package/dist/providers/google-forms/actions/get-single-response.action.d.ts +31 -0
- package/dist/providers/google-forms/actions/get-single-response.action.d.ts.map +1 -0
- package/dist/providers/google-forms/actions/get-single-response.action.js +150 -0
- package/dist/providers/google-forms/actions/get-single-response.action.js.map +1 -0
- package/dist/providers/google-forms/actions/get-statistics.action.d.ts +36 -0
- package/dist/providers/google-forms/actions/get-statistics.action.d.ts.map +1 -0
- package/dist/providers/google-forms/actions/get-statistics.action.js +254 -0
- package/dist/providers/google-forms/actions/get-statistics.action.js.map +1 -0
- package/dist/providers/google-forms/actions/index.d.ts +5 -0
- package/dist/providers/google-forms/actions/index.d.ts.map +1 -0
- package/dist/providers/google-forms/actions/index.js +23 -0
- package/dist/providers/google-forms/actions/index.js.map +1 -0
- package/dist/providers/google-forms/googleforms-base.action.d.ts +197 -0
- package/dist/providers/google-forms/googleforms-base.action.d.ts.map +1 -0
- package/dist/providers/google-forms/googleforms-base.action.js +352 -0
- package/dist/providers/google-forms/googleforms-base.action.js.map +1 -0
- package/dist/providers/google-forms/index.d.ts +3 -0
- package/dist/providers/google-forms/index.d.ts.map +1 -0
- package/dist/providers/google-forms/index.js +21 -0
- package/dist/providers/google-forms/index.js.map +1 -0
- package/dist/providers/jotform/actions/create-form.action.d.ts +61 -0
- package/dist/providers/jotform/actions/create-form.action.d.ts.map +1 -0
- package/dist/providers/jotform/actions/create-form.action.js +259 -0
- package/dist/providers/jotform/actions/create-form.action.js.map +1 -0
- package/dist/providers/jotform/actions/export-csv.action.d.ts +31 -0
- package/dist/providers/jotform/actions/export-csv.action.d.ts.map +1 -0
- package/dist/providers/jotform/actions/export-csv.action.js +187 -0
- package/dist/providers/jotform/actions/export-csv.action.js.map +1 -0
- package/dist/providers/jotform/actions/get-form.action.d.ts +31 -0
- package/dist/providers/jotform/actions/get-form.action.d.ts.map +1 -0
- package/dist/providers/jotform/actions/get-form.action.js +188 -0
- package/dist/providers/jotform/actions/get-form.action.js.map +1 -0
- package/dist/providers/jotform/actions/get-single-submission.action.d.ts +31 -0
- package/dist/providers/jotform/actions/get-single-submission.action.d.ts.map +1 -0
- package/dist/providers/jotform/actions/get-single-submission.action.js +138 -0
- package/dist/providers/jotform/actions/get-single-submission.action.js.map +1 -0
- package/dist/providers/jotform/actions/get-statistics.action.d.ts +39 -0
- package/dist/providers/jotform/actions/get-statistics.action.d.ts.map +1 -0
- package/dist/providers/jotform/actions/get-statistics.action.js +290 -0
- package/dist/providers/jotform/actions/get-statistics.action.js.map +1 -0
- package/dist/providers/jotform/actions/get-submissions.action.d.ts +34 -0
- package/dist/providers/jotform/actions/get-submissions.action.d.ts.map +1 -0
- package/dist/providers/jotform/actions/get-submissions.action.js +218 -0
- package/dist/providers/jotform/actions/get-submissions.action.js.map +1 -0
- package/dist/providers/jotform/actions/index.d.ts +9 -0
- package/dist/providers/jotform/actions/index.d.ts.map +1 -0
- package/dist/providers/jotform/actions/index.js +27 -0
- package/dist/providers/jotform/actions/index.js.map +1 -0
- package/dist/providers/jotform/actions/update-form.action.d.ts +38 -0
- package/dist/providers/jotform/actions/update-form.action.d.ts.map +1 -0
- package/dist/providers/jotform/actions/update-form.action.js +232 -0
- package/dist/providers/jotform/actions/update-form.action.js.map +1 -0
- package/dist/providers/jotform/actions/watch-new-submissions.action.d.ts +32 -0
- package/dist/providers/jotform/actions/watch-new-submissions.action.d.ts.map +1 -0
- package/dist/providers/jotform/actions/watch-new-submissions.action.js +229 -0
- package/dist/providers/jotform/actions/watch-new-submissions.action.js.map +1 -0
- package/dist/providers/jotform/index.d.ts +3 -0
- package/dist/providers/jotform/index.d.ts.map +1 -0
- package/dist/providers/jotform/index.js +21 -0
- package/dist/providers/jotform/index.js.map +1 -0
- package/dist/providers/jotform/jotform-base.action.d.ts +96 -0
- package/dist/providers/jotform/jotform-base.action.d.ts.map +1 -0
- package/dist/providers/jotform/jotform-base.action.js +269 -0
- package/dist/providers/jotform/jotform-base.action.js.map +1 -0
- package/dist/providers/surveymonkey/actions/create-survey.action.d.ts +48 -0
- package/dist/providers/surveymonkey/actions/create-survey.action.d.ts.map +1 -0
- package/dist/providers/surveymonkey/actions/create-survey.action.js +192 -0
- package/dist/providers/surveymonkey/actions/create-survey.action.js.map +1 -0
- package/dist/providers/surveymonkey/actions/export-csv.action.d.ts +30 -0
- package/dist/providers/surveymonkey/actions/export-csv.action.d.ts.map +1 -0
- package/dist/providers/surveymonkey/actions/export-csv.action.js +173 -0
- package/dist/providers/surveymonkey/actions/export-csv.action.js.map +1 -0
- package/dist/providers/surveymonkey/actions/get-responses.action.d.ts +33 -0
- package/dist/providers/surveymonkey/actions/get-responses.action.d.ts.map +1 -0
- package/dist/providers/surveymonkey/actions/get-responses.action.js +243 -0
- package/dist/providers/surveymonkey/actions/get-responses.action.js.map +1 -0
- package/dist/providers/surveymonkey/actions/get-single-response.action.d.ts +30 -0
- package/dist/providers/surveymonkey/actions/get-single-response.action.d.ts.map +1 -0
- package/dist/providers/surveymonkey/actions/get-single-response.action.js +149 -0
- package/dist/providers/surveymonkey/actions/get-single-response.action.js.map +1 -0
- package/dist/providers/surveymonkey/actions/get-statistics.action.d.ts +38 -0
- package/dist/providers/surveymonkey/actions/get-statistics.action.d.ts.map +1 -0
- package/dist/providers/surveymonkey/actions/get-statistics.action.js +261 -0
- package/dist/providers/surveymonkey/actions/get-statistics.action.js.map +1 -0
- package/dist/providers/surveymonkey/actions/get-survey.action.d.ts +27 -0
- package/dist/providers/surveymonkey/actions/get-survey.action.d.ts.map +1 -0
- package/dist/providers/surveymonkey/actions/get-survey.action.js +180 -0
- package/dist/providers/surveymonkey/actions/get-survey.action.js.map +1 -0
- package/dist/providers/surveymonkey/actions/index.d.ts +9 -0
- package/dist/providers/surveymonkey/actions/index.d.ts.map +1 -0
- package/dist/providers/surveymonkey/actions/index.js +27 -0
- package/dist/providers/surveymonkey/actions/index.js.map +1 -0
- package/dist/providers/surveymonkey/actions/update-survey.action.d.ts +39 -0
- package/dist/providers/surveymonkey/actions/update-survey.action.d.ts.map +1 -0
- package/dist/providers/surveymonkey/actions/update-survey.action.js +217 -0
- package/dist/providers/surveymonkey/actions/update-survey.action.js.map +1 -0
- package/dist/providers/surveymonkey/actions/watch-new-responses.action.d.ts +31 -0
- package/dist/providers/surveymonkey/actions/watch-new-responses.action.d.ts.map +1 -0
- package/dist/providers/surveymonkey/actions/watch-new-responses.action.js +214 -0
- package/dist/providers/surveymonkey/actions/watch-new-responses.action.js.map +1 -0
- package/dist/providers/surveymonkey/index.d.ts +3 -0
- package/dist/providers/surveymonkey/index.d.ts.map +1 -0
- package/dist/providers/surveymonkey/index.js +21 -0
- package/dist/providers/surveymonkey/index.js.map +1 -0
- package/dist/providers/surveymonkey/surveymonkey-base.action.d.ts +193 -0
- package/dist/providers/surveymonkey/surveymonkey-base.action.d.ts.map +1 -0
- package/dist/providers/surveymonkey/surveymonkey-base.action.js +329 -0
- package/dist/providers/surveymonkey/surveymonkey-base.action.js.map +1 -0
- package/dist/providers/typeform/actions/create-form.action.d.ts +40 -0
- package/dist/providers/typeform/actions/create-form.action.d.ts.map +1 -0
- package/dist/providers/typeform/actions/create-form.action.js +205 -0
- package/dist/providers/typeform/actions/create-form.action.js.map +1 -0
- package/dist/providers/typeform/actions/export-csv.action.d.ts +31 -0
- package/dist/providers/typeform/actions/export-csv.action.d.ts.map +1 -0
- package/dist/providers/typeform/actions/export-csv.action.js +182 -0
- package/dist/providers/typeform/actions/export-csv.action.js.map +1 -0
- package/dist/providers/typeform/actions/get-form.action.d.ts +28 -0
- package/dist/providers/typeform/actions/get-form.action.d.ts.map +1 -0
- package/dist/providers/typeform/actions/get-form.action.js +172 -0
- package/dist/providers/typeform/actions/get-form.action.js.map +1 -0
- package/dist/providers/typeform/actions/get-responses.action.d.ts +34 -0
- package/dist/providers/typeform/actions/get-responses.action.d.ts.map +1 -0
- package/dist/providers/typeform/actions/get-responses.action.js +238 -0
- package/dist/providers/typeform/actions/get-responses.action.js.map +1 -0
- package/dist/providers/typeform/actions/get-single-response.action.d.ts +31 -0
- package/dist/providers/typeform/actions/get-single-response.action.d.ts.map +1 -0
- package/dist/providers/typeform/actions/get-single-response.action.js +161 -0
- package/dist/providers/typeform/actions/get-single-response.action.js.map +1 -0
- package/dist/providers/typeform/actions/get-statistics.action.d.ts +33 -0
- package/dist/providers/typeform/actions/get-statistics.action.d.ts.map +1 -0
- package/dist/providers/typeform/actions/get-statistics.action.js +257 -0
- package/dist/providers/typeform/actions/get-statistics.action.js.map +1 -0
- package/dist/providers/typeform/actions/index.d.ts +9 -0
- package/dist/providers/typeform/actions/index.d.ts.map +1 -0
- package/dist/providers/typeform/actions/index.js +27 -0
- package/dist/providers/typeform/actions/index.js.map +1 -0
- package/dist/providers/typeform/actions/update-form.action.d.ts +38 -0
- package/dist/providers/typeform/actions/update-form.action.d.ts.map +1 -0
- package/dist/providers/typeform/actions/update-form.action.js +228 -0
- package/dist/providers/typeform/actions/update-form.action.js.map +1 -0
- package/dist/providers/typeform/actions/watch-new-responses.action.d.ts +32 -0
- package/dist/providers/typeform/actions/watch-new-responses.action.d.ts.map +1 -0
- package/dist/providers/typeform/actions/watch-new-responses.action.js +215 -0
- package/dist/providers/typeform/actions/watch-new-responses.action.js.map +1 -0
- package/dist/providers/typeform/index.d.ts +3 -0
- package/dist/providers/typeform/index.d.ts.map +1 -0
- package/dist/providers/typeform/index.js +21 -0
- package/dist/providers/typeform/index.js.map +1 -0
- package/dist/providers/typeform/typeform-base.action.d.ts +121 -0
- package/dist/providers/typeform/typeform-base.action.d.ts.map +1 -0
- package/dist/providers/typeform/typeform-base.action.js +292 -0
- package/dist/providers/typeform/typeform-base.action.js.map +1 -0
- package/package.json +41 -0
- package/src/base/base-form-builder.action.ts +403 -0
- package/src/base/index.ts +1 -0
- package/src/index.ts +18 -0
- package/src/providers/google-forms/actions/export-csv.action.ts +167 -0
- package/src/providers/google-forms/actions/get-form.action.ts +151 -0
- package/src/providers/google-forms/actions/get-single-response.action.ts +150 -0
- package/src/providers/google-forms/actions/get-statistics.action.ts +273 -0
- package/src/providers/google-forms/actions/index.ts +7 -0
- package/src/providers/google-forms/googleforms-base.action.ts +517 -0
- package/src/providers/google-forms/index.ts +5 -0
- package/src/providers/jotform/actions/create-form.action.ts +281 -0
- package/src/providers/jotform/actions/export-csv.action.ts +189 -0
- package/src/providers/jotform/actions/get-form.action.ts +189 -0
- package/src/providers/jotform/actions/get-single-submission.action.ts +137 -0
- package/src/providers/jotform/actions/get-statistics.action.ts +308 -0
- package/src/providers/jotform/actions/get-submissions.action.ts +220 -0
- package/src/providers/jotform/actions/index.ts +11 -0
- package/src/providers/jotform/actions/update-form.action.ts +254 -0
- package/src/providers/jotform/actions/watch-new-submissions.action.ts +238 -0
- package/src/providers/jotform/index.ts +5 -0
- package/src/providers/jotform/jotform-base.action.ts +365 -0
- package/src/providers/surveymonkey/actions/create-survey.action.ts +196 -0
- package/src/providers/surveymonkey/actions/export-csv.action.ts +175 -0
- package/src/providers/surveymonkey/actions/get-responses.action.ts +245 -0
- package/src/providers/surveymonkey/actions/get-single-response.action.ts +148 -0
- package/src/providers/surveymonkey/actions/get-statistics.action.ts +280 -0
- package/src/providers/surveymonkey/actions/get-survey.action.ts +181 -0
- package/src/providers/surveymonkey/actions/index.ts +11 -0
- package/src/providers/surveymonkey/actions/update-survey.action.ts +234 -0
- package/src/providers/surveymonkey/actions/watch-new-responses.action.ts +221 -0
- package/src/providers/surveymonkey/index.ts +5 -0
- package/src/providers/surveymonkey/surveymonkey-base.action.ts +505 -0
- package/src/providers/typeform/actions/create-form.action.ts +211 -0
- package/src/providers/typeform/actions/export-csv.action.ts +184 -0
- package/src/providers/typeform/actions/get-form.action.ts +173 -0
- package/src/providers/typeform/actions/get-responses.action.ts +242 -0
- package/src/providers/typeform/actions/get-single-response.action.ts +160 -0
- package/src/providers/typeform/actions/get-statistics.action.ts +276 -0
- package/src/providers/typeform/actions/index.ts +11 -0
- package/src/providers/typeform/actions/update-form.action.ts +235 -0
- package/src/providers/typeform/actions/watch-new-responses.action.ts +222 -0
- package/src/providers/typeform/index.ts +5 -0
- package/src/providers/typeform/typeform-base.action.ts +387 -0
- package/tsconfig.json +18 -0
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
import { RegisterClass } from '@memberjunction/global';
|
|
2
|
+
import { BaseFormBuilderAction, FormResponse, FormAnswer } from '../../base/base-form-builder.action';
|
|
3
|
+
import { UserInfo, LogError, LogStatus } from '@memberjunction/core';
|
|
4
|
+
import axios, { AxiosInstance, AxiosError } from 'axios';
|
|
5
|
+
import { BaseAction } from '@memberjunction/actions';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* JotForm API response structures
|
|
9
|
+
*/
|
|
10
|
+
export interface JotFormSubmission {
|
|
11
|
+
id: string;
|
|
12
|
+
form_id: string;
|
|
13
|
+
ip: string;
|
|
14
|
+
created_at: string;
|
|
15
|
+
status: string;
|
|
16
|
+
new: string;
|
|
17
|
+
flag: string;
|
|
18
|
+
answers: Record<string, {
|
|
19
|
+
name: string;
|
|
20
|
+
order: string;
|
|
21
|
+
text: string;
|
|
22
|
+
type: string;
|
|
23
|
+
answer?: string | string[];
|
|
24
|
+
prettyFormat?: string;
|
|
25
|
+
}>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface JotFormSubmissionsResult {
|
|
29
|
+
responseCode: number;
|
|
30
|
+
message: string;
|
|
31
|
+
content: JotFormSubmission[];
|
|
32
|
+
limit: number;
|
|
33
|
+
offset: number;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Base class for all JotForm actions.
|
|
38
|
+
* Handles JotForm-specific authentication and API interaction patterns.
|
|
39
|
+
*/
|
|
40
|
+
@RegisterClass(BaseAction, 'JotFormBaseAction')
|
|
41
|
+
export abstract class JotFormBaseAction extends BaseFormBuilderAction {
|
|
42
|
+
protected get formPlatform(): string {
|
|
43
|
+
return 'JotForm';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
protected get integrationName(): string {
|
|
47
|
+
return 'JotForm';
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
protected get apiBaseUrl(): string {
|
|
51
|
+
return 'https://api.jotform.com';
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
private axiosInstance: AxiosInstance | null = null;
|
|
55
|
+
private currentAPIKey: string | null = null;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Get axios instance with JotForm authentication
|
|
59
|
+
*/
|
|
60
|
+
protected getAxiosInstance(apiKey: string, region?: 'us' | 'eu' | 'hipaa'): AxiosInstance {
|
|
61
|
+
const baseURL = this.getRegionalBaseUrl(region);
|
|
62
|
+
|
|
63
|
+
if (!this.axiosInstance || this.currentAPIKey !== apiKey) {
|
|
64
|
+
this.currentAPIKey = apiKey;
|
|
65
|
+
this.axiosInstance = axios.create({
|
|
66
|
+
baseURL,
|
|
67
|
+
timeout: 60000,
|
|
68
|
+
headers: {
|
|
69
|
+
'Accept': 'application/json',
|
|
70
|
+
'Content-Type': 'application/json'
|
|
71
|
+
},
|
|
72
|
+
params: {
|
|
73
|
+
apiKey // JotForm uses API key in query params
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
this.axiosInstance.interceptors.response.use(
|
|
78
|
+
(response) => {
|
|
79
|
+
return response;
|
|
80
|
+
},
|
|
81
|
+
async (error: AxiosError) => {
|
|
82
|
+
if (error.response?.status === 429) {
|
|
83
|
+
LogStatus('JotForm rate limit hit. Waiting 60 seconds...');
|
|
84
|
+
await this.sleep(60000);
|
|
85
|
+
return this.axiosInstance!.request(error.config!);
|
|
86
|
+
}
|
|
87
|
+
return Promise.reject(error);
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
return this.axiosInstance;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Get regional base URL
|
|
96
|
+
*/
|
|
97
|
+
protected getRegionalBaseUrl(region?: 'us' | 'eu' | 'hipaa'): string {
|
|
98
|
+
switch (region) {
|
|
99
|
+
case 'eu':
|
|
100
|
+
return 'https://eu-api.jotform.com';
|
|
101
|
+
case 'hipaa':
|
|
102
|
+
return 'https://hipaa-api.jotform.com';
|
|
103
|
+
default:
|
|
104
|
+
return 'https://api.jotform.com';
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Get submissions from a JotForm
|
|
110
|
+
*/
|
|
111
|
+
protected async getJotFormSubmissions(
|
|
112
|
+
formId: string,
|
|
113
|
+
apiKey: string,
|
|
114
|
+
options?: {
|
|
115
|
+
limit?: number;
|
|
116
|
+
offset?: number;
|
|
117
|
+
filter?: Record<string, string>;
|
|
118
|
+
orderby?: string;
|
|
119
|
+
region?: 'us' | 'eu' | 'hipaa';
|
|
120
|
+
}
|
|
121
|
+
): Promise<JotFormSubmissionsResult> {
|
|
122
|
+
try {
|
|
123
|
+
const params: Record<string, any> = {
|
|
124
|
+
apiKey,
|
|
125
|
+
limit: options?.limit || 100,
|
|
126
|
+
offset: options?.offset || 0
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
if (options?.filter) {
|
|
130
|
+
params.filter = JSON.stringify(options.filter);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (options?.orderby) {
|
|
134
|
+
params.orderby = options.orderby;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const response = await this.getAxiosInstance(apiKey, options?.region).get(
|
|
138
|
+
`/form/${formId}/submissions`,
|
|
139
|
+
{ params }
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
return response.data;
|
|
143
|
+
} catch (error) {
|
|
144
|
+
LogError('Failed to get JotForm submissions:', error);
|
|
145
|
+
throw this.handleJotFormError(error);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Get all submissions with automatic pagination
|
|
151
|
+
*/
|
|
152
|
+
protected async getAllJotFormSubmissions(
|
|
153
|
+
formId: string,
|
|
154
|
+
apiKey: string,
|
|
155
|
+
options?: {
|
|
156
|
+
filter?: Record<string, string>;
|
|
157
|
+
orderby?: string;
|
|
158
|
+
maxSubmissions?: number;
|
|
159
|
+
region?: 'us' | 'eu' | 'hipaa';
|
|
160
|
+
}
|
|
161
|
+
): Promise<JotFormSubmission[]> {
|
|
162
|
+
const allSubmissions: JotFormSubmission[] = [];
|
|
163
|
+
let offset = 0;
|
|
164
|
+
const limit = 1000;
|
|
165
|
+
const maxSubmissions = options?.maxSubmissions || 10000;
|
|
166
|
+
|
|
167
|
+
try {
|
|
168
|
+
while (true) {
|
|
169
|
+
const result = await this.getJotFormSubmissions(formId, apiKey, {
|
|
170
|
+
limit: Math.min(limit, maxSubmissions - allSubmissions.length),
|
|
171
|
+
offset,
|
|
172
|
+
filter: options?.filter,
|
|
173
|
+
orderby: options?.orderby,
|
|
174
|
+
region: options?.region
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
if (result.content && result.content.length > 0) {
|
|
178
|
+
allSubmissions.push(...result.content);
|
|
179
|
+
|
|
180
|
+
if (allSubmissions.length >= maxSubmissions) {
|
|
181
|
+
LogStatus(`Reached max submissions limit of ${maxSubmissions}`);
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (result.content.length < limit) {
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
offset += limit;
|
|
190
|
+
await this.sleep(100);
|
|
191
|
+
} else {
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
LogStatus(`Retrieved ${allSubmissions.length} submissions from JotForm`);
|
|
197
|
+
return allSubmissions;
|
|
198
|
+
} catch (error) {
|
|
199
|
+
LogError('Failed to get all JotForm submissions:', error);
|
|
200
|
+
throw error;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Get a single submission by ID
|
|
206
|
+
*/
|
|
207
|
+
protected async getSingleJotFormSubmission(
|
|
208
|
+
submissionId: string,
|
|
209
|
+
apiKey: string,
|
|
210
|
+
region?: 'us' | 'eu' | 'hipaa'
|
|
211
|
+
): Promise<JotFormSubmission> {
|
|
212
|
+
try {
|
|
213
|
+
const response = await this.getAxiosInstance(apiKey, region).get(
|
|
214
|
+
`/submission/${submissionId}`,
|
|
215
|
+
{ params: { apiKey } }
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
return response.data.content;
|
|
219
|
+
} catch (error) {
|
|
220
|
+
LogError('Failed to get single JotForm submission:', error);
|
|
221
|
+
throw this.handleJotFormError(error);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Get form details
|
|
227
|
+
*/
|
|
228
|
+
protected async getJotFormDetails(
|
|
229
|
+
formId: string,
|
|
230
|
+
apiKey: string,
|
|
231
|
+
region?: 'us' | 'eu' | 'hipaa'
|
|
232
|
+
): Promise<any> {
|
|
233
|
+
try {
|
|
234
|
+
const response = await this.getAxiosInstance(apiKey, region).get(
|
|
235
|
+
`/form/${formId}`,
|
|
236
|
+
{ params: { apiKey } }
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
return response.data.content;
|
|
240
|
+
} catch (error) {
|
|
241
|
+
LogError('Failed to get JotForm details:', error);
|
|
242
|
+
throw this.handleJotFormError(error);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Get form questions/fields
|
|
248
|
+
*/
|
|
249
|
+
protected async getJotFormQuestions(
|
|
250
|
+
formId: string,
|
|
251
|
+
apiKey: string,
|
|
252
|
+
region?: 'us' | 'eu' | 'hipaa'
|
|
253
|
+
): Promise<any> {
|
|
254
|
+
try {
|
|
255
|
+
const response = await this.getAxiosInstance(apiKey, region).get(
|
|
256
|
+
`/form/${formId}/questions`,
|
|
257
|
+
{ params: { apiKey } }
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
return response.data.content;
|
|
261
|
+
} catch (error) {
|
|
262
|
+
LogError('Failed to get JotForm questions:', error);
|
|
263
|
+
throw this.handleJotFormError(error);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Create a new submission
|
|
269
|
+
*/
|
|
270
|
+
protected async createJotFormSubmission(
|
|
271
|
+
formId: string,
|
|
272
|
+
apiKey: string,
|
|
273
|
+
submissionData: Record<string, any>,
|
|
274
|
+
region?: 'us' | 'eu' | 'hipaa'
|
|
275
|
+
): Promise<any> {
|
|
276
|
+
try {
|
|
277
|
+
const params: Record<string, any> = { apiKey };
|
|
278
|
+
|
|
279
|
+
// Add submission data to params
|
|
280
|
+
Object.entries(submissionData).forEach(([fieldId, value]) => {
|
|
281
|
+
params[`submission[${fieldId}]`] = value;
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
const response = await this.getAxiosInstance(apiKey, region).post(
|
|
285
|
+
`/form/${formId}/submissions`,
|
|
286
|
+
null,
|
|
287
|
+
{ params }
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
return response.data;
|
|
291
|
+
} catch (error) {
|
|
292
|
+
LogError('Failed to create JotForm submission:', error);
|
|
293
|
+
throw this.handleJotFormError(error);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Normalize JotForm submission to common format
|
|
299
|
+
*/
|
|
300
|
+
protected normalizeJotFormSubmission(jfSubmission: JotFormSubmission): FormResponse {
|
|
301
|
+
const answers: FormAnswer[] = Object.entries(jfSubmission.answers || {}).map(([fieldId, answerData]) => {
|
|
302
|
+
let answerValue: any = answerData.answer;
|
|
303
|
+
|
|
304
|
+
// Handle array answers
|
|
305
|
+
if (Array.isArray(answerValue)) {
|
|
306
|
+
answerValue = answerValue.filter(v => v !== '');
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
return {
|
|
310
|
+
fieldId,
|
|
311
|
+
fieldType: answerData.type,
|
|
312
|
+
question: answerData.text || answerData.name,
|
|
313
|
+
answer: answerValue || answerData.prettyFormat,
|
|
314
|
+
choices: Array.isArray(answerValue) ? answerValue : undefined
|
|
315
|
+
};
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
const submittedAt = new Date(jfSubmission.created_at);
|
|
319
|
+
const completed = jfSubmission.status === 'ACTIVE';
|
|
320
|
+
|
|
321
|
+
return {
|
|
322
|
+
responseId: jfSubmission.id,
|
|
323
|
+
formId: jfSubmission.form_id,
|
|
324
|
+
submittedAt,
|
|
325
|
+
completed,
|
|
326
|
+
answers,
|
|
327
|
+
metadata: {
|
|
328
|
+
userAgent: jfSubmission.ip,
|
|
329
|
+
platform: 'JotForm'
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Handle JotForm-specific errors
|
|
336
|
+
*/
|
|
337
|
+
protected handleJotFormError(error: any): Error {
|
|
338
|
+
if (axios.isAxiosError(error)) {
|
|
339
|
+
const axiosError = error as AxiosError;
|
|
340
|
+
const status = axiosError.response?.status;
|
|
341
|
+
const data = axiosError.response?.data as any;
|
|
342
|
+
|
|
343
|
+
if (status === 401) {
|
|
344
|
+
return new Error('Invalid JotForm API key. Please check your authentication.');
|
|
345
|
+
} else if (status === 403) {
|
|
346
|
+
return new Error('Insufficient permissions to access this JotForm resource.');
|
|
347
|
+
} else if (status === 404) {
|
|
348
|
+
return new Error('JotForm form or submission not found.');
|
|
349
|
+
} else if (status === 429) {
|
|
350
|
+
return new Error('JotForm API rate limit exceeded. Please try again later.');
|
|
351
|
+
} else if (data?.message) {
|
|
352
|
+
return new Error(`JotForm API error: ${data.message}`);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Sleep helper for rate limiting
|
|
361
|
+
*/
|
|
362
|
+
protected sleep(ms: number): Promise<void> {
|
|
363
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
364
|
+
}
|
|
365
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { RegisterClass } from '@memberjunction/global';
|
|
2
|
+
import { SurveyMonkeyBaseAction } from '../surveymonkey-base.action';
|
|
3
|
+
import { ActionParam, ActionResultSimple, RunActionParams } from '@memberjunction/actions-base';
|
|
4
|
+
import { BaseAction } from '@memberjunction/actions';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Action to create a new SurveyMonkey survey programmatically
|
|
8
|
+
*
|
|
9
|
+
* Security: Uses secure credential lookup via CompanyID instead of accepting tokens directly.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* await runAction({
|
|
14
|
+
* ActionName: 'Create SurveyMonkey',
|
|
15
|
+
* Params: [{
|
|
16
|
+
* Name: 'CompanyID',
|
|
17
|
+
* Value: 'your-company-id'
|
|
18
|
+
* }, {
|
|
19
|
+
* Name: 'Title',
|
|
20
|
+
* Value: 'Customer Satisfaction Survey'
|
|
21
|
+
* }, {
|
|
22
|
+
* Name: 'Pages',
|
|
23
|
+
* Value: [{
|
|
24
|
+
* title: 'Page 1',
|
|
25
|
+
* questions: [{
|
|
26
|
+
* family: 'single_choice',
|
|
27
|
+
* subtype: 'vertical',
|
|
28
|
+
* heading: 'How satisfied are you with our service?',
|
|
29
|
+
* answers: {
|
|
30
|
+
* choices: [
|
|
31
|
+
* { text: 'Very Satisfied' },
|
|
32
|
+
* { text: 'Satisfied' },
|
|
33
|
+
* { text: 'Neutral' },
|
|
34
|
+
* { text: 'Dissatisfied' }
|
|
35
|
+
* ]
|
|
36
|
+
* }
|
|
37
|
+
* }]
|
|
38
|
+
* }]
|
|
39
|
+
* }, {
|
|
40
|
+
* Name: 'Language',
|
|
41
|
+
* Value: 'en'
|
|
42
|
+
* }]
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
@RegisterClass(BaseAction, 'Create SurveyMonkey')
|
|
47
|
+
export class CreateSurveyMonkeyAction extends SurveyMonkeyBaseAction {
|
|
48
|
+
|
|
49
|
+
public get Description(): string {
|
|
50
|
+
return 'Creates a new SurveyMonkey survey with specified title, pages, and questions. Supports all question families including single_choice, multiple_choice, matrix, open_ended, demographic, datetime, and presentation. Returns the new survey ID, URLs, and page count.';
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
protected async InternalRunAction(params: RunActionParams): Promise<ActionResultSimple> {
|
|
54
|
+
try {
|
|
55
|
+
const contextUser = params.ContextUser;
|
|
56
|
+
if (!contextUser) {
|
|
57
|
+
return {
|
|
58
|
+
Success: false,
|
|
59
|
+
ResultCode: 'MISSING_CONTEXT_USER',
|
|
60
|
+
Message: 'Context user is required for SurveyMonkey API calls'
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const companyId = this.getParamValue(params.Params, 'CompanyID');
|
|
65
|
+
|
|
66
|
+
const accessToken = await this.getSecureAPIToken(companyId, contextUser);
|
|
67
|
+
|
|
68
|
+
const title = this.getParamValue(params.Params, 'Title');
|
|
69
|
+
if (!title) {
|
|
70
|
+
return {
|
|
71
|
+
Success: false,
|
|
72
|
+
ResultCode: 'MISSING_TITLE',
|
|
73
|
+
Message: 'Title parameter is required'
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const pages = this.getParamValue(params.Params, 'Pages');
|
|
78
|
+
if (!pages || !Array.isArray(pages) || pages.length === 0) {
|
|
79
|
+
return {
|
|
80
|
+
Success: false,
|
|
81
|
+
ResultCode: 'MISSING_PAGES',
|
|
82
|
+
Message: 'Pages parameter is required and must be a non-empty array'
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const surveyData: Record<string, any> = {
|
|
87
|
+
title,
|
|
88
|
+
pages
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const language = this.getParamValue(params.Params, 'Language');
|
|
92
|
+
if (language) {
|
|
93
|
+
surveyData.language = language;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const buttonsText = this.getParamValue(params.Params, 'ButtonsText');
|
|
97
|
+
if (buttonsText && typeof buttonsText === 'object') {
|
|
98
|
+
surveyData.buttons_text = buttonsText;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const response = await this.getAxiosInstance(accessToken).post('/surveys', surveyData);
|
|
102
|
+
const createdSurvey = response.data;
|
|
103
|
+
|
|
104
|
+
const surveyDetails = await this.getSurveyMonkeyDetails(createdSurvey.id, accessToken);
|
|
105
|
+
|
|
106
|
+
const surveyUrl = surveyDetails.collect_url || `https://www.surveymonkey.com/r/${createdSurvey.id}`;
|
|
107
|
+
const editUrl = surveyDetails.edit_url || `https://www.surveymonkey.com/create/?sm=${createdSurvey.id}`;
|
|
108
|
+
|
|
109
|
+
const outputParams: ActionParam[] = [
|
|
110
|
+
{
|
|
111
|
+
Name: 'Survey',
|
|
112
|
+
Type: 'Output',
|
|
113
|
+
Value: surveyDetails
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
Name: 'SurveyID',
|
|
117
|
+
Type: 'Output',
|
|
118
|
+
Value: createdSurvey.id
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
Name: 'Title',
|
|
122
|
+
Type: 'Output',
|
|
123
|
+
Value: surveyDetails.title
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
Name: 'SurveyURL',
|
|
127
|
+
Type: 'Output',
|
|
128
|
+
Value: surveyUrl
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
Name: 'EditURL',
|
|
132
|
+
Type: 'Output',
|
|
133
|
+
Value: editUrl
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
Name: 'PageCount',
|
|
137
|
+
Type: 'Output',
|
|
138
|
+
Value: surveyDetails.page_count
|
|
139
|
+
}
|
|
140
|
+
];
|
|
141
|
+
|
|
142
|
+
for (const outputParam of outputParams) {
|
|
143
|
+
const existingParam = params.Params.find(p => p.Name === outputParam.Name);
|
|
144
|
+
if (existingParam) {
|
|
145
|
+
existingParam.Value = outputParam.Value;
|
|
146
|
+
} else {
|
|
147
|
+
params.Params.push(outputParam);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
Success: true,
|
|
153
|
+
ResultCode: 'SUCCESS',
|
|
154
|
+
Message: `Successfully created survey "${surveyDetails.title}" (ID: ${createdSurvey.id}). View at: ${surveyUrl}`
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
} catch (error) {
|
|
158
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
|
159
|
+
return {
|
|
160
|
+
Success: false,
|
|
161
|
+
ResultCode: 'ERROR',
|
|
162
|
+
Message: this.buildFormErrorMessage('Create SurveyMonkey Survey', errorMessage, error)
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
public get Params(): ActionParam[] {
|
|
168
|
+
return [
|
|
169
|
+
{
|
|
170
|
+
Name: 'CompanyID',
|
|
171
|
+
Type: 'Input',
|
|
172
|
+
Value: null
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
Name: 'Title',
|
|
176
|
+
Type: 'Input',
|
|
177
|
+
Value: null
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
Name: 'Pages',
|
|
181
|
+
Type: 'Input',
|
|
182
|
+
Value: null
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
Name: 'Language',
|
|
186
|
+
Type: 'Input',
|
|
187
|
+
Value: null
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
Name: 'ButtonsText',
|
|
191
|
+
Type: 'Input',
|
|
192
|
+
Value: null
|
|
193
|
+
}
|
|
194
|
+
];
|
|
195
|
+
}
|
|
196
|
+
}
|