@explorer02/cfm-survey-sdk 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/const.d.ts +24 -0
- package/dist/cli/const.d.ts.map +1 -0
- package/dist/cli/const.js +31 -0
- package/dist/cli/const.js.map +1 -0
- package/dist/cli/constants.d.ts +9 -0
- package/dist/cli/constants.js +12 -0
- package/dist/cli/deploy.d.ts.map +1 -1
- package/dist/cli/deploy.js +10 -189
- package/dist/cli/deploy.js.map +1 -1
- package/dist/cli/index.js +19 -10
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/init.d.ts +2 -0
- package/dist/cli/init.d.ts.map +1 -0
- package/dist/cli/init.js +405 -0
- package/dist/cli/init.js.map +1 -0
- package/dist/cli/utils/exec.d.ts +4 -0
- package/dist/cli/utils/exec.d.ts.map +1 -0
- package/dist/cli/utils/exec.js +41 -0
- package/dist/cli/utils/exec.js.map +1 -0
- package/dist/cli/utils/nodeCheck.d.ts +2 -0
- package/dist/cli/utils/nodeCheck.d.ts.map +1 -0
- package/dist/cli/utils/nodeCheck.js +64 -0
- package/dist/cli/utils/nodeCheck.js.map +1 -0
- package/dist/cli/utils/prompts.d.ts +2 -0
- package/dist/cli/utils/prompts.d.ts.map +1 -0
- package/dist/cli/utils/prompts.js +29 -0
- package/dist/cli/utils/prompts.js.map +1 -0
- package/dist/cli/utils/vercelCliCheck.d.ts +6 -0
- package/dist/cli/utils/vercelCliCheck.d.ts.map +1 -0
- package/dist/cli/utils/vercelCliCheck.js +38 -0
- package/dist/cli/utils/vercelCliCheck.js.map +1 -0
- package/dist/cli/utils/vercelDeploy.d.ts +2 -0
- package/dist/cli/utils/vercelDeploy.d.ts.map +1 -0
- package/dist/cli/utils/vercelDeploy.js +21 -0
- package/dist/cli/utils/vercelDeploy.js.map +1 -0
- package/dist/cli/utils/vercelLoginCheck.d.ts +2 -0
- package/dist/cli/utils/vercelLoginCheck.d.ts.map +1 -0
- package/dist/cli/utils/vercelLoginCheck.js +42 -0
- package/dist/cli/utils/vercelLoginCheck.js.map +1 -0
- package/package.json +8 -2
- package/postinstall.js +45 -0
- package/templates/AGENT.md +1281 -0
- package/src/analytics/analyticsTracker.ts +0 -48
- package/src/analytics/types.ts +0 -80
- package/src/cli/deploy.ts +0 -205
- package/src/cli/index.ts +0 -33
- package/src/fetchSurvey/internalTypes.ts +0 -80
- package/src/fetchSurvey/logger/fetchLogger.ts +0 -34
- package/src/fetchSurvey/logger/mapperLogger.ts +0 -13
- package/src/fetchSurvey/telemetry/fetchTelemetry.ts +0 -26
- package/src/fetchSurvey/types.ts +0 -82
- package/src/fetchSurvey/useFetchSurvey.ts +0 -126
- package/src/fetchSurvey/utils/constants.ts +0 -11
- package/src/fetchSurvey/utils/extractSurveyLanguages.ts +0 -63
- package/src/fetchSurvey/utils/index.ts +0 -7
- package/src/fetchSurvey/utils/mapSurveyPages.ts +0 -35
- package/src/fetchSurvey/utils/mappers/index.ts +0 -2
- package/src/fetchSurvey/utils/mappers/questionMapper.ts +0 -213
- package/src/fetchSurvey/utils/mappers/surveyMapper.ts +0 -69
- package/src/fetchSurvey/utils/url.ts +0 -21
- package/src/index.ts +0 -6
- package/src/logger/logger.ts +0 -71
- package/src/queryClient.ts +0 -67
- package/src/submitSurvey/logger/resolutionLogger.ts +0 -13
- package/src/submitSurvey/logger/submitLogger.ts +0 -51
- package/src/submitSurvey/telemetry/submitTelemetry.ts +0 -33
- package/src/submitSurvey/types.ts +0 -51
- package/src/submitSurvey/useSubmitResponse.ts +0 -111
- package/src/submitSurvey/utils/constants.ts +0 -4
- package/src/submitSurvey/utils/formatters.ts +0 -33
- package/src/submitSurvey/utils/index.ts +0 -4
- package/src/submitSurvey/utils/url.ts +0 -17
- package/src/submitSurvey/utils/validation.ts +0 -48
- package/src/surveyPagination/actions/index.ts +0 -4
- package/src/surveyPagination/actions/useOnBack.ts +0 -37
- package/src/surveyPagination/actions/useOnChange.ts +0 -16
- package/src/surveyPagination/actions/useOnNext.ts +0 -99
- package/src/surveyPagination/actions/useOnSubmit.ts +0 -137
- package/src/surveyPagination/dispatchers/index.ts +0 -3
- package/src/surveyPagination/dispatchers/useCheckBacktrackChanges.ts +0 -35
- package/src/surveyPagination/dispatchers/useTrackOptionalSkips.ts +0 -21
- package/src/surveyPagination/dispatchers/useTrackPageTime.ts +0 -13
- package/src/surveyPagination/effects/index.ts +0 -2
- package/src/surveyPagination/effects/useResetPageStartTime.ts +0 -10
- package/src/surveyPagination/effects/useTrackMaxVisitedPage.ts +0 -12
- package/src/surveyPagination/logger/navigationLogger.ts +0 -25
- package/src/surveyPagination/logger/validationLogger.ts +0 -17
- package/src/surveyPagination/telemetry/pageTelemetry.ts +0 -22
- package/src/surveyPagination/telemetry/sessionTelemetry.ts +0 -55
- package/src/surveyPagination/types.ts +0 -42
- package/src/surveyPagination/useSurveyPagination.ts +0 -109
- package/src/surveyPagination/utils/index.ts +0 -2
- package/src/surveyPagination/utils/scroll.ts +0 -62
- package/src/surveyPagination/utils/validation.ts +0 -62
- package/src/surveyProgress/useSurveyProgress.ts +0 -42
- package/src/surveyProgress/utils/index.ts +0 -1
- package/src/surveyProgress/utils/progress.ts +0 -61
- package/src/surveySDK/constants.ts +0 -9
- package/src/surveySDK/types.ts +0 -22
- package/src/surveySDK/useSurveySDK.ts +0 -109
- package/tsconfig.json +0 -13
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect, useMemo } from 'react';
|
|
2
|
-
import type { Survey } from '../fetchSurvey/types';
|
|
3
|
-
import type { SubmitAnswers } from '../submitSurvey/types';
|
|
4
|
-
import { countTotalQuestions, countAnsweredQuestions, calculateProgressPercentage } from './utils';
|
|
5
|
-
|
|
6
|
-
export interface UseSurveyProgressProps {
|
|
7
|
-
survey?: Survey | null;
|
|
8
|
-
values?: SubmitAnswers | null;
|
|
9
|
-
currentPageIndex?: number;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* A custom React hook that tracks progress within a survey.
|
|
14
|
-
* Computes completed question counts, total questions, and percentage completion.
|
|
15
|
-
*
|
|
16
|
-
* @param props Configurations holding active survey definition and answer values.
|
|
17
|
-
* @returns Real-time calculated progress tracking indices.
|
|
18
|
-
*/
|
|
19
|
-
export function useSurveyProgress({ survey, values, currentPageIndex = 0 }: UseSurveyProgressProps) {
|
|
20
|
-
const [maxVisitedPageIndex, setMaxVisitedPageIndex] = useState(0);
|
|
21
|
-
|
|
22
|
-
// Track the highest page index reached so far
|
|
23
|
-
useEffect(() => {
|
|
24
|
-
if (currentPageIndex > maxVisitedPageIndex) {
|
|
25
|
-
setMaxVisitedPageIndex(currentPageIndex);
|
|
26
|
-
}
|
|
27
|
-
}, [currentPageIndex, maxVisitedPageIndex]);
|
|
28
|
-
|
|
29
|
-
return useMemo(() => {
|
|
30
|
-
const totalQuestionsCount = countTotalQuestions(survey);
|
|
31
|
-
const answeredQuestionsCount = countAnsweredQuestions(survey, values, maxVisitedPageIndex);
|
|
32
|
-
const progressPercentage = calculateProgressPercentage(answeredQuestionsCount, totalQuestionsCount);
|
|
33
|
-
const isComplete = totalQuestionsCount > 0 && answeredQuestionsCount === totalQuestionsCount;
|
|
34
|
-
|
|
35
|
-
return {
|
|
36
|
-
totalQuestionsCount,
|
|
37
|
-
answeredQuestionsCount,
|
|
38
|
-
progressPercentage,
|
|
39
|
-
isComplete,
|
|
40
|
-
};
|
|
41
|
-
}, [survey, values, maxVisitedPageIndex]);
|
|
42
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './progress';
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import type { Survey } from '../../fetchSurvey/types';
|
|
2
|
-
import type { SubmitAnswers } from '../../submitSurvey/types';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Counts the total number of questions present across all pages of the survey.
|
|
6
|
-
*
|
|
7
|
-
* @param survey Fully mapped survey data structure.
|
|
8
|
-
* @returns Total number of questions.
|
|
9
|
-
*/
|
|
10
|
-
export function countTotalQuestions(survey?: Survey | null): number {
|
|
11
|
-
if (!survey || !Array.isArray(survey.pages)) return 0;
|
|
12
|
-
return survey.pages.reduce((acc, page) => acc + (page.questions?.length ?? 0), 0);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Counts the number of questions that have been answered by the user.
|
|
17
|
-
* Only questions that exist in the active survey configuration are counted.
|
|
18
|
-
*
|
|
19
|
-
* @param survey Fully mapped survey data structure.
|
|
20
|
-
* @param values Values map containing active user answers.
|
|
21
|
-
* @returns Count of completed questions.
|
|
22
|
-
*/
|
|
23
|
-
export function countAnsweredQuestions(
|
|
24
|
-
survey?: Survey | null,
|
|
25
|
-
values?: SubmitAnswers | null,
|
|
26
|
-
maxVisitedPageIndex: number = 0
|
|
27
|
-
): number {
|
|
28
|
-
if (!survey || !values || !Array.isArray(survey.pages)) return 0;
|
|
29
|
-
|
|
30
|
-
let answeredCount = 0;
|
|
31
|
-
survey.pages.forEach((page, index) => {
|
|
32
|
-
if (Array.isArray(page.questions)) {
|
|
33
|
-
if (index < maxVisitedPageIndex) {
|
|
34
|
-
// All questions on past pages count as completed (required or optional)
|
|
35
|
-
answeredCount += page.questions.length;
|
|
36
|
-
} else {
|
|
37
|
-
// Questions on current or future pages only count if they have been explicitly answered
|
|
38
|
-
page.questions.forEach(question => {
|
|
39
|
-
const value = values[question.id];
|
|
40
|
-
if (value !== undefined && value !== null && value !== '') {
|
|
41
|
-
answeredCount++;
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
return answeredCount;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Computes progress percentage as an integer between 0 and 100.
|
|
53
|
-
*
|
|
54
|
-
* @param answered Count of answered questions.
|
|
55
|
-
* @param total Count of total questions.
|
|
56
|
-
* @returns Progress percentage rounded to the nearest integer.
|
|
57
|
-
*/
|
|
58
|
-
export function calculateProgressPercentage(answered: number, total: number): number {
|
|
59
|
-
if (total <= 0) return 0;
|
|
60
|
-
return Math.min(100, Math.max(0, Math.round((answered / total) * 100)));
|
|
61
|
-
}
|
package/src/surveySDK/types.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { ACTIONS } from './constants';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Union type representing all dispatch actions for the survey SDK.
|
|
5
|
-
*/
|
|
6
|
-
export type SurveyAction =
|
|
7
|
-
| { type: ACTIONS.NEXT | 'NEXT' }
|
|
8
|
-
| { type: ACTIONS.PREVIOUS | 'PREVIOUS' }
|
|
9
|
-
| { type: ACTIONS.SUBMIT | 'SUBMIT' }
|
|
10
|
-
| { type: ACTIONS.CHANGE | 'CHANGE'; payload: { questionId: string; value: string | number } };
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Configuration settings for useSurveySDK hook behavior and layout parameters.
|
|
14
|
-
*/
|
|
15
|
-
export type UseSurveySDKProps = {
|
|
16
|
-
options?: {
|
|
17
|
-
language?: string;
|
|
18
|
-
placeholders?: Record<string, string>;
|
|
19
|
-
debug?: boolean;
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { useCallback, useMemo } from 'react';
|
|
2
|
-
import { useFetchSurvey } from '../fetchSurvey/useFetchSurvey';
|
|
3
|
-
import { useSurveyPagination } from '../surveyPagination/useSurveyPagination';
|
|
4
|
-
// remove unused imports eventhough they are used in the code
|
|
5
|
-
import type { Survey, SurveySession } from '../fetchSurvey/useFetchSurvey';
|
|
6
|
-
import type { SubmitAnswers, SubmitResult } from '../submitSurvey/types';
|
|
7
|
-
import { sdkLogger } from '../logger/logger';
|
|
8
|
-
import { ACTIONS } from './constants';
|
|
9
|
-
import type { SurveyAction, UseSurveySDKProps } from './types';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* The main entry-point custom React hook for the survey SDK.
|
|
13
|
-
* Handles fetching survey configurations, active session state, validation,
|
|
14
|
-
* page pagination, response submission, and user progress tracking.
|
|
15
|
-
*
|
|
16
|
-
* @param props Configuration settings for hook behavior and layout parameters.
|
|
17
|
-
* @returns Unified state structures, submission indicators, and action triggers.
|
|
18
|
-
*/
|
|
19
|
-
export function useSurveySDK({ options }: UseSurveySDKProps = {}) {
|
|
20
|
-
// Synchronize debug setting
|
|
21
|
-
sdkLogger.setEnabled(options?.debug ?? false);
|
|
22
|
-
|
|
23
|
-
// 1. Fetch survey layout
|
|
24
|
-
const { survey, session, fetching, fetchError } = useFetchSurvey({
|
|
25
|
-
language: options?.language,
|
|
26
|
-
placeholders: options?.placeholders,
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
// 2. Control navigation, validation, and submission
|
|
30
|
-
const {
|
|
31
|
-
currentPageIndex,
|
|
32
|
-
values,
|
|
33
|
-
validationErrors,
|
|
34
|
-
currentQuestions,
|
|
35
|
-
onBack,
|
|
36
|
-
onNext,
|
|
37
|
-
onSubmit,
|
|
38
|
-
onChange,
|
|
39
|
-
progressPercentage,
|
|
40
|
-
submitting,
|
|
41
|
-
submitError,
|
|
42
|
-
submitData,
|
|
43
|
-
} = useSurveyPagination({ survey, session });
|
|
44
|
-
|
|
45
|
-
// 3. Define the dispatcher
|
|
46
|
-
const onAction = useCallback(
|
|
47
|
-
(action: SurveyAction) => {
|
|
48
|
-
if (action.type === ACTIONS.NEXT && survey && currentPageIndex === survey.pages.length - 1) {
|
|
49
|
-
action = { type: ACTIONS.SUBMIT };
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
sdkLogger.info(`Action dispatched: ${action.type}`, action);
|
|
53
|
-
try {
|
|
54
|
-
switch (action.type) {
|
|
55
|
-
// constants and types
|
|
56
|
-
case ACTIONS.NEXT:
|
|
57
|
-
onNext();
|
|
58
|
-
break;
|
|
59
|
-
case ACTIONS.PREVIOUS:
|
|
60
|
-
onBack();
|
|
61
|
-
break;
|
|
62
|
-
case ACTIONS.SUBMIT:
|
|
63
|
-
onSubmit();
|
|
64
|
-
break;
|
|
65
|
-
case ACTIONS.CHANGE:
|
|
66
|
-
onChange(action.payload.questionId, action.payload.value);
|
|
67
|
-
break;
|
|
68
|
-
default:
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
} catch (err) {
|
|
72
|
-
sdkLogger.error(`Error executing action: ${action.type}`, err);
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
[onNext, onBack, onSubmit, onChange, survey, currentPageIndex]
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
// surveyQueryResults
|
|
79
|
-
// submitSurveyResults
|
|
80
|
-
// state
|
|
81
|
-
// onAction
|
|
82
|
-
return {
|
|
83
|
-
// 1. Survey Query Namespace
|
|
84
|
-
surveyQueryResults: {
|
|
85
|
-
data: survey,
|
|
86
|
-
error: fetchError,
|
|
87
|
-
isLoading: fetching,
|
|
88
|
-
},
|
|
89
|
-
|
|
90
|
-
// 2. Response Submission Namespace
|
|
91
|
-
submitSurveyResults: {
|
|
92
|
-
data: submitData,
|
|
93
|
-
error: submitError,
|
|
94
|
-
isLoading: submitting,
|
|
95
|
-
},
|
|
96
|
-
|
|
97
|
-
// 3. Client-Interactive State Namespace
|
|
98
|
-
state: {
|
|
99
|
-
currentPageIndex,
|
|
100
|
-
currentQuestions,
|
|
101
|
-
values,
|
|
102
|
-
validationErrors,
|
|
103
|
-
progressPercentage,
|
|
104
|
-
},
|
|
105
|
-
|
|
106
|
-
// 4. Action Dispatcher
|
|
107
|
-
onAction,
|
|
108
|
-
};
|
|
109
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "dist",
|
|
5
|
-
"rootDir": "src",
|
|
6
|
-
"module": "CommonJS",
|
|
7
|
-
"moduleResolution": "Node",
|
|
8
|
-
"jsx": "react-jsx",
|
|
9
|
-
"lib": ["ES2022", "DOM"]
|
|
10
|
-
},
|
|
11
|
-
"include": ["src/**/*"],
|
|
12
|
-
"exclude": ["node_modules", "dist"]
|
|
13
|
-
}
|