@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,517 @@
|
|
|
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
|
+
* Google Forms API response structures
|
|
9
|
+
*/
|
|
10
|
+
export interface GoogleFormsAnswer {
|
|
11
|
+
questionId: string;
|
|
12
|
+
textAnswers?: {
|
|
13
|
+
answers: Array<{
|
|
14
|
+
value: string;
|
|
15
|
+
}>;
|
|
16
|
+
};
|
|
17
|
+
fileUploadAnswers?: {
|
|
18
|
+
answers: Array<{
|
|
19
|
+
fileId: string;
|
|
20
|
+
fileName: string;
|
|
21
|
+
mimeType: string;
|
|
22
|
+
}>;
|
|
23
|
+
};
|
|
24
|
+
grade?: {
|
|
25
|
+
score: number;
|
|
26
|
+
correct: boolean;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface GoogleFormsResponseItem {
|
|
31
|
+
responseId: string;
|
|
32
|
+
createTime: string;
|
|
33
|
+
lastSubmittedTime: string;
|
|
34
|
+
respondentEmail?: string;
|
|
35
|
+
answers: Record<string, GoogleFormsAnswer>;
|
|
36
|
+
totalScore?: number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface GoogleFormsResponsesResult {
|
|
40
|
+
responses: GoogleFormsResponseItem[];
|
|
41
|
+
nextPageToken?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface GoogleFormItem {
|
|
45
|
+
questionItem?: {
|
|
46
|
+
question: {
|
|
47
|
+
questionId: string;
|
|
48
|
+
required?: boolean;
|
|
49
|
+
textQuestion?: {
|
|
50
|
+
paragraph?: boolean;
|
|
51
|
+
};
|
|
52
|
+
choiceQuestion?: {
|
|
53
|
+
type?: string;
|
|
54
|
+
options?: Array<{
|
|
55
|
+
value: string;
|
|
56
|
+
}>;
|
|
57
|
+
shuffle?: boolean;
|
|
58
|
+
};
|
|
59
|
+
scaleQuestion?: {
|
|
60
|
+
low: number;
|
|
61
|
+
high: number;
|
|
62
|
+
lowLabel?: string;
|
|
63
|
+
highLabel?: string;
|
|
64
|
+
};
|
|
65
|
+
dateQuestion?: {
|
|
66
|
+
includeTime?: boolean;
|
|
67
|
+
includeYear?: boolean;
|
|
68
|
+
};
|
|
69
|
+
timeQuestion?: {
|
|
70
|
+
duration?: boolean;
|
|
71
|
+
};
|
|
72
|
+
fileUploadQuestion?: {
|
|
73
|
+
folderId: string;
|
|
74
|
+
types?: string[];
|
|
75
|
+
maxFiles?: number;
|
|
76
|
+
maxFileSize?: string;
|
|
77
|
+
};
|
|
78
|
+
rowQuestion?: {
|
|
79
|
+
title: string;
|
|
80
|
+
};
|
|
81
|
+
grading?: {
|
|
82
|
+
pointValue: number;
|
|
83
|
+
correctAnswers?: {
|
|
84
|
+
answers: Array<{
|
|
85
|
+
value: string;
|
|
86
|
+
}>;
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
questionGroupItem?: {
|
|
92
|
+
questions: any[];
|
|
93
|
+
grid?: {
|
|
94
|
+
columns: {
|
|
95
|
+
type: string;
|
|
96
|
+
options: Array<{
|
|
97
|
+
value: string;
|
|
98
|
+
}>;
|
|
99
|
+
};
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
title?: string;
|
|
103
|
+
description?: string;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface GoogleFormsDetails {
|
|
107
|
+
formId: string;
|
|
108
|
+
info: {
|
|
109
|
+
title: string;
|
|
110
|
+
documentTitle?: string;
|
|
111
|
+
description?: string;
|
|
112
|
+
};
|
|
113
|
+
settings?: {
|
|
114
|
+
quizSettings?: {
|
|
115
|
+
isQuiz?: boolean;
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
items?: GoogleFormItem[];
|
|
119
|
+
revisionId?: string;
|
|
120
|
+
responderUri?: string;
|
|
121
|
+
linkedSheetId?: string;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Base class for all Google Forms actions.
|
|
126
|
+
* Handles Google Forms-specific authentication and API interaction patterns.
|
|
127
|
+
*
|
|
128
|
+
* Note: Google Forms API is read-only - there are no endpoints for creating or updating forms.
|
|
129
|
+
*/
|
|
130
|
+
@RegisterClass(BaseAction, 'GoogleFormsBaseAction')
|
|
131
|
+
export abstract class GoogleFormsBaseAction extends BaseFormBuilderAction {
|
|
132
|
+
protected get formPlatform(): string {
|
|
133
|
+
return 'Google Forms';
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
protected get integrationName(): string {
|
|
137
|
+
return 'Google Forms';
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
protected get apiBaseUrl(): string {
|
|
141
|
+
return 'https://forms.googleapis.com/v1';
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private axiosInstance: AxiosInstance | null = null;
|
|
145
|
+
private currentAccessToken: string | null = null;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Get axios instance with Google Forms authentication (OAuth 2.0)
|
|
149
|
+
*/
|
|
150
|
+
protected getAxiosInstance(accessToken: string): AxiosInstance {
|
|
151
|
+
if (!this.axiosInstance || this.currentAccessToken !== accessToken) {
|
|
152
|
+
this.currentAccessToken = accessToken;
|
|
153
|
+
this.axiosInstance = axios.create({
|
|
154
|
+
baseURL: this.apiBaseUrl,
|
|
155
|
+
timeout: 60000,
|
|
156
|
+
headers: {
|
|
157
|
+
'Accept': 'application/json',
|
|
158
|
+
'Content-Type': 'application/json',
|
|
159
|
+
'Authorization': `Bearer ${accessToken}`
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// Add response interceptor for rate limiting
|
|
164
|
+
this.axiosInstance.interceptors.response.use(
|
|
165
|
+
(response) => {
|
|
166
|
+
return response;
|
|
167
|
+
},
|
|
168
|
+
async (error: AxiosError) => {
|
|
169
|
+
if (error.response?.status === 429) {
|
|
170
|
+
const retryAfter = error.response.headers['retry-after'];
|
|
171
|
+
const waitTime = retryAfter ? parseInt(retryAfter) * 1000 : 60000;
|
|
172
|
+
LogStatus(`Google Forms rate limit hit. Waiting ${waitTime}ms before retry...`);
|
|
173
|
+
await this.sleep(waitTime);
|
|
174
|
+
return this.axiosInstance!.request(error.config!);
|
|
175
|
+
}
|
|
176
|
+
return Promise.reject(error);
|
|
177
|
+
}
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
return this.axiosInstance;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Get responses from a Google Form
|
|
185
|
+
*/
|
|
186
|
+
protected async getGoogleFormsResponses(
|
|
187
|
+
formId: string,
|
|
188
|
+
accessToken: string,
|
|
189
|
+
options?: {
|
|
190
|
+
pageSize?: number;
|
|
191
|
+
pageToken?: string;
|
|
192
|
+
filter?: string;
|
|
193
|
+
}
|
|
194
|
+
): Promise<GoogleFormsResponsesResult> {
|
|
195
|
+
try {
|
|
196
|
+
const params: Record<string, any> = {};
|
|
197
|
+
|
|
198
|
+
if (options?.pageSize) {
|
|
199
|
+
// Google Forms API max pageSize is 5000
|
|
200
|
+
params.pageSize = Math.min(options.pageSize, 5000);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (options?.pageToken) {
|
|
204
|
+
params.pageToken = options.pageToken;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (options?.filter) {
|
|
208
|
+
params.filter = options.filter;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const response = await this.getAxiosInstance(accessToken).get(
|
|
212
|
+
`/forms/${formId}/responses`,
|
|
213
|
+
{ params }
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
return response.data;
|
|
217
|
+
} catch (error) {
|
|
218
|
+
LogError('Failed to get Google Forms responses:', error);
|
|
219
|
+
throw this.handleGoogleFormsError(error);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Get all responses with automatic pagination using pageToken
|
|
225
|
+
*/
|
|
226
|
+
protected async getAllGoogleFormsResponses(
|
|
227
|
+
formId: string,
|
|
228
|
+
accessToken: string,
|
|
229
|
+
options?: {
|
|
230
|
+
filter?: string;
|
|
231
|
+
maxResponses?: number;
|
|
232
|
+
}
|
|
233
|
+
): Promise<GoogleFormsResponseItem[]> {
|
|
234
|
+
const allResponses: GoogleFormsResponseItem[] = [];
|
|
235
|
+
let pageToken: string | undefined = undefined;
|
|
236
|
+
const maxResponses = options?.maxResponses || 10000;
|
|
237
|
+
|
|
238
|
+
try {
|
|
239
|
+
while (true) {
|
|
240
|
+
const result = await this.getGoogleFormsResponses(formId, accessToken, {
|
|
241
|
+
pageSize: Math.min(5000, maxResponses - allResponses.length),
|
|
242
|
+
pageToken,
|
|
243
|
+
filter: options?.filter
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
if (result.responses && result.responses.length > 0) {
|
|
247
|
+
allResponses.push(...result.responses);
|
|
248
|
+
|
|
249
|
+
if (allResponses.length >= maxResponses) {
|
|
250
|
+
LogStatus(`Reached max responses limit of ${maxResponses}`);
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// Check if there are more pages
|
|
256
|
+
if (!result.nextPageToken || !result.responses || result.responses.length === 0) {
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
pageToken = result.nextPageToken;
|
|
261
|
+
await this.sleep(100);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
LogStatus(`Retrieved ${allResponses.length} responses from Google Forms`);
|
|
265
|
+
return allResponses;
|
|
266
|
+
} catch (error) {
|
|
267
|
+
LogError('Failed to get all Google Forms responses:', error);
|
|
268
|
+
throw error;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Get a single response by ID
|
|
274
|
+
*/
|
|
275
|
+
protected async getSingleGoogleFormsResponse(
|
|
276
|
+
formId: string,
|
|
277
|
+
responseId: string,
|
|
278
|
+
accessToken: string
|
|
279
|
+
): Promise<GoogleFormsResponseItem> {
|
|
280
|
+
try {
|
|
281
|
+
const response = await this.getAxiosInstance(accessToken).get(
|
|
282
|
+
`/forms/${formId}/responses/${responseId}`
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
return response.data;
|
|
286
|
+
} catch (error) {
|
|
287
|
+
LogError('Failed to get single Google Forms response:', error);
|
|
288
|
+
throw this.handleGoogleFormsError(error);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Get form details including questions and settings
|
|
294
|
+
*/
|
|
295
|
+
protected async getGoogleFormsDetails(
|
|
296
|
+
formId: string,
|
|
297
|
+
accessToken: string
|
|
298
|
+
): Promise<GoogleFormsDetails> {
|
|
299
|
+
try {
|
|
300
|
+
const response = await this.getAxiosInstance(accessToken).get(
|
|
301
|
+
`/forms/${formId}`
|
|
302
|
+
);
|
|
303
|
+
|
|
304
|
+
return response.data;
|
|
305
|
+
} catch (error) {
|
|
306
|
+
LogError('Failed to get Google Forms details:', error);
|
|
307
|
+
throw this.handleGoogleFormsError(error);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Normalize Google Forms response to common format
|
|
313
|
+
*/
|
|
314
|
+
protected normalizeGoogleFormsResponse(gfResponse: GoogleFormsResponseItem, formDetails?: GoogleFormsDetails): FormResponse {
|
|
315
|
+
const answers: FormAnswer[] = [];
|
|
316
|
+
|
|
317
|
+
// Build a map of question IDs to question details for better normalization
|
|
318
|
+
const questionMap = new Map<string, { title: string; type: string }>();
|
|
319
|
+
|
|
320
|
+
if (formDetails?.items) {
|
|
321
|
+
for (const item of formDetails.items) {
|
|
322
|
+
if (item.questionItem?.question) {
|
|
323
|
+
const question = item.questionItem.question;
|
|
324
|
+
let questionType = 'unknown';
|
|
325
|
+
|
|
326
|
+
if (question.textQuestion) {
|
|
327
|
+
questionType = question.textQuestion.paragraph ? 'paragraph_text' : 'short_text';
|
|
328
|
+
} else if (question.choiceQuestion) {
|
|
329
|
+
questionType = question.choiceQuestion.type?.toLowerCase() || 'choice';
|
|
330
|
+
} else if (question.scaleQuestion) {
|
|
331
|
+
questionType = 'scale';
|
|
332
|
+
} else if (question.dateQuestion) {
|
|
333
|
+
questionType = 'date';
|
|
334
|
+
} else if (question.timeQuestion) {
|
|
335
|
+
questionType = 'time';
|
|
336
|
+
} else if (question.fileUploadQuestion) {
|
|
337
|
+
questionType = 'file_upload';
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
questionMap.set(question.questionId, {
|
|
341
|
+
title: item.title || question.questionId,
|
|
342
|
+
type: questionType
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// Process answers
|
|
349
|
+
for (const [questionId, answerData] of Object.entries(gfResponse.answers || {})) {
|
|
350
|
+
const questionInfo = questionMap.get(questionId);
|
|
351
|
+
let answerValue: any;
|
|
352
|
+
let fieldType = questionInfo?.type || 'unknown';
|
|
353
|
+
let question = questionInfo?.title || questionId;
|
|
354
|
+
|
|
355
|
+
// Extract answer value based on answer type
|
|
356
|
+
if (answerData.textAnswers?.answers) {
|
|
357
|
+
if (answerData.textAnswers.answers.length === 1) {
|
|
358
|
+
answerValue = answerData.textAnswers.answers[0].value;
|
|
359
|
+
} else {
|
|
360
|
+
answerValue = answerData.textAnswers.answers.map(a => a.value);
|
|
361
|
+
}
|
|
362
|
+
} else if (answerData.fileUploadAnswers?.answers) {
|
|
363
|
+
answerValue = answerData.fileUploadAnswers.answers.map(file => ({
|
|
364
|
+
fileId: file.fileId,
|
|
365
|
+
fileName: file.fileName,
|
|
366
|
+
mimeType: file.mimeType
|
|
367
|
+
}));
|
|
368
|
+
fieldType = 'file_upload';
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
answers.push({
|
|
372
|
+
fieldId: questionId,
|
|
373
|
+
fieldType,
|
|
374
|
+
question,
|
|
375
|
+
answer: answerValue,
|
|
376
|
+
choices: Array.isArray(answerValue) ? answerValue : undefined
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
const submittedAt = new Date(gfResponse.lastSubmittedTime || gfResponse.createTime);
|
|
381
|
+
const completed = !!gfResponse.lastSubmittedTime;
|
|
382
|
+
|
|
383
|
+
return {
|
|
384
|
+
responseId: gfResponse.responseId,
|
|
385
|
+
formId: '', // Form ID is not included in response object, needs to be passed separately
|
|
386
|
+
submittedAt,
|
|
387
|
+
completed,
|
|
388
|
+
answers,
|
|
389
|
+
metadata: {
|
|
390
|
+
userAgent: gfResponse.respondentEmail,
|
|
391
|
+
platform: 'Google Forms'
|
|
392
|
+
},
|
|
393
|
+
calculatedFields: gfResponse.totalScore !== undefined ? {
|
|
394
|
+
totalScore: gfResponse.totalScore
|
|
395
|
+
} : undefined
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Handle Google Forms-specific errors
|
|
401
|
+
*/
|
|
402
|
+
protected handleGoogleFormsError(error: any): Error {
|
|
403
|
+
if (axios.isAxiosError(error)) {
|
|
404
|
+
const axiosError = error as AxiosError;
|
|
405
|
+
const status = axiosError.response?.status;
|
|
406
|
+
const data = axiosError.response?.data as any;
|
|
407
|
+
|
|
408
|
+
if (status === 401) {
|
|
409
|
+
return new Error('Invalid Google Forms access token. Please check your authentication or refresh your OAuth token.');
|
|
410
|
+
} else if (status === 403) {
|
|
411
|
+
return new Error('Insufficient permissions to access this Google Forms resource. Ensure the OAuth token has the required scopes (forms.responses.readonly or forms.readonly).');
|
|
412
|
+
} else if (status === 404) {
|
|
413
|
+
return new Error('Google Form or response not found. Verify the form ID and that the form exists.');
|
|
414
|
+
} else if (status === 429) {
|
|
415
|
+
return new Error('Google Forms API rate limit exceeded. Please try again later.');
|
|
416
|
+
} else if (status === 400) {
|
|
417
|
+
const errorMessage = data?.error?.message || 'Bad request';
|
|
418
|
+
return new Error(`Google Forms API error: ${errorMessage}`);
|
|
419
|
+
} else if (data?.error?.message) {
|
|
420
|
+
return new Error(`Google Forms API error: ${data.error.message}`);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
return error instanceof Error ? error : new Error(String(error));
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Sleep helper for rate limiting and pagination delays
|
|
429
|
+
*/
|
|
430
|
+
protected sleep(ms: number): Promise<void> {
|
|
431
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Format date for Google Forms API (RFC3339 format)
|
|
436
|
+
*/
|
|
437
|
+
protected formatGoogleFormsDate(date: Date): string {
|
|
438
|
+
return date.toISOString();
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Parse Google Forms date string (RFC3339 format)
|
|
443
|
+
*/
|
|
444
|
+
protected parseGoogleFormsDate(dateValue: string): Date {
|
|
445
|
+
return new Date(dateValue);
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* Extract question information from form details
|
|
450
|
+
* Useful for building comprehensive reports with question titles
|
|
451
|
+
*/
|
|
452
|
+
protected extractQuestions(formDetails: GoogleFormsDetails): Array<{ id: string; title: string; type: string; required: boolean }> {
|
|
453
|
+
const questions: Array<{ id: string; title: string; type: string; required: boolean }> = [];
|
|
454
|
+
|
|
455
|
+
if (!formDetails.items) {
|
|
456
|
+
return questions;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
for (const item of formDetails.items) {
|
|
460
|
+
if (item.questionItem?.question) {
|
|
461
|
+
const question = item.questionItem.question;
|
|
462
|
+
let questionType = 'unknown';
|
|
463
|
+
|
|
464
|
+
if (question.textQuestion) {
|
|
465
|
+
questionType = question.textQuestion.paragraph ? 'paragraph_text' : 'short_text';
|
|
466
|
+
} else if (question.choiceQuestion) {
|
|
467
|
+
questionType = question.choiceQuestion.type?.toLowerCase() || 'choice';
|
|
468
|
+
} else if (question.scaleQuestion) {
|
|
469
|
+
questionType = 'scale';
|
|
470
|
+
} else if (question.dateQuestion) {
|
|
471
|
+
questionType = 'date';
|
|
472
|
+
} else if (question.timeQuestion) {
|
|
473
|
+
questionType = 'time';
|
|
474
|
+
} else if (question.fileUploadQuestion) {
|
|
475
|
+
questionType = 'file_upload';
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
questions.push({
|
|
479
|
+
id: question.questionId,
|
|
480
|
+
title: item.title || question.questionId,
|
|
481
|
+
type: questionType,
|
|
482
|
+
required: question.required || false
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
return questions;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Check if a form is a quiz
|
|
492
|
+
*/
|
|
493
|
+
protected isQuiz(formDetails: GoogleFormsDetails): boolean {
|
|
494
|
+
return formDetails.settings?.quizSettings?.isQuiz || false;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* Build filter string for Google Forms API
|
|
499
|
+
* Filters use a SQL-like syntax: timestamp > "2024-01-01T00:00:00Z"
|
|
500
|
+
*/
|
|
501
|
+
protected buildFilter(conditions: {
|
|
502
|
+
timestampAfter?: Date;
|
|
503
|
+
timestampBefore?: Date;
|
|
504
|
+
}): string | undefined {
|
|
505
|
+
const filters: string[] = [];
|
|
506
|
+
|
|
507
|
+
if (conditions.timestampAfter) {
|
|
508
|
+
filters.push(`timestamp > "${this.formatGoogleFormsDate(conditions.timestampAfter)}"`);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
if (conditions.timestampBefore) {
|
|
512
|
+
filters.push(`timestamp < "${this.formatGoogleFormsDate(conditions.timestampBefore)}"`);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
return filters.length > 0 ? filters.join(' AND ') : undefined;
|
|
516
|
+
}
|
|
517
|
+
}
|