@posthog/browser-common 0.9.10 → 0.9.12
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/config.js +1 -1
- package/dist/config.mjs +1 -1
- package/dist/surveys/survey-branching.d.ts +1 -1
- package/dist/surveys/survey-branching.js +2 -0
- package/dist/surveys/survey-branching.mjs +2 -0
- package/dist/surveys/survey-url-prefill.js +2 -1
- package/dist/surveys/survey-url-prefill.mjs +2 -1
- package/dist/surveys-renderer.js +4 -1
- package/dist/surveys-renderer.mjs +4 -1
- package/dist/utils/uuidv7.js +1 -7
- package/dist/utils/uuidv7.mjs +1 -7
- package/package.json +4 -6
package/dist/config.js
CHANGED
package/dist/config.mjs
CHANGED
|
@@ -9,4 +9,4 @@ export declare function getRatingBucketForResponseValue(responseValue: number, s
|
|
|
9
9
|
* Determine the next survey step based on branching configuration.
|
|
10
10
|
* Returns the next question index, or SurveyQuestionBranchingType.End if the survey should end.
|
|
11
11
|
*/
|
|
12
|
-
export declare function getNextSurveyStep(survey: Survey, currentQuestionIndex: number, response: string | string[] | number | null): number | typeof SurveyQuestionBranchingType.End;
|
|
12
|
+
export declare function getNextSurveyStep(survey: Survey, currentQuestionIndex: number, response: string | string[] | number | null | undefined): number | typeof SurveyQuestionBranchingType.End;
|
|
@@ -33,6 +33,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
33
33
|
});
|
|
34
34
|
const external_survey_constants_js_namespaceObject = require("../survey-constants.js");
|
|
35
35
|
const logger_js_namespaceObject = require("../utils/logger.js");
|
|
36
|
+
const core_namespaceObject = require("@posthog/core");
|
|
36
37
|
const logger = (0, logger_js_namespaceObject.createLogger)('[Surveys]');
|
|
37
38
|
function getRatingBucketForResponseValue(responseValue, scale) {
|
|
38
39
|
if (2 === scale) {
|
|
@@ -77,6 +78,7 @@ function getNextSurveyStep(survey, currentQuestionIndex, response) {
|
|
|
77
78
|
if (nextStep === external_survey_constants_js_namespaceObject.SurveyQuestionBranchingType.End) return external_survey_constants_js_namespaceObject.SurveyQuestionBranchingType.End;
|
|
78
79
|
}
|
|
79
80
|
} else if (question.type === external_survey_constants_js_namespaceObject.SurveyQuestionType.Rating) {
|
|
81
|
+
if (question.optional && (0, core_namespaceObject.isNullish)(response)) return nextQuestionIndex === survey.questions.length ? external_survey_constants_js_namespaceObject.SurveyQuestionBranchingType.End : nextQuestionIndex;
|
|
80
82
|
if ('number' != typeof response || !Number.isInteger(response)) throw new Error('The response type must be an integer');
|
|
81
83
|
const ratingBucket = getRatingBucketForResponseValue(response, question.scale);
|
|
82
84
|
if (question.branching?.responseValues?.hasOwnProperty(ratingBucket)) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SurveyQuestionBranchingType, SurveyQuestionType } from "../survey-constants.mjs";
|
|
2
2
|
import { createLogger } from "../utils/logger.mjs";
|
|
3
|
+
import { isNullish } from "@posthog/core";
|
|
3
4
|
const logger = createLogger('[Surveys]');
|
|
4
5
|
function getRatingBucketForResponseValue(responseValue, scale) {
|
|
5
6
|
if (2 === scale) {
|
|
@@ -44,6 +45,7 @@ function getNextSurveyStep(survey, currentQuestionIndex, response) {
|
|
|
44
45
|
if (nextStep === SurveyQuestionBranchingType.End) return SurveyQuestionBranchingType.End;
|
|
45
46
|
}
|
|
46
47
|
} else if (question.type === SurveyQuestionType.Rating) {
|
|
48
|
+
if (question.optional && isNullish(response)) return nextQuestionIndex === survey.questions.length ? SurveyQuestionBranchingType.End : nextQuestionIndex;
|
|
47
49
|
if ('number' != typeof response || !Number.isInteger(response)) throw new Error('The response type must be an integer');
|
|
48
50
|
const ratingBucket = getRatingBucketForResponseValue(response, question.scale);
|
|
49
51
|
if (question.branching?.responseValues?.hasOwnProperty(ratingBucket)) {
|
|
@@ -105,7 +105,8 @@ function convertPrefillToResponses(survey, prefillParams) {
|
|
|
105
105
|
{
|
|
106
106
|
const rating = parseInt(values[0], 10);
|
|
107
107
|
const scale = question.scale || 10;
|
|
108
|
-
|
|
108
|
+
const min = 10 === scale ? 0 : 1;
|
|
109
|
+
if (isNaN(rating) || rating < min || rating > scale) return void logger_js_namespaceObject.logger.warn(`[Survey Prefill] Invalid rating for q${index}: ${values[0]} (scale: ${min}-${scale})`);
|
|
109
110
|
responses[responseKey] = rating;
|
|
110
111
|
break;
|
|
111
112
|
}
|
|
@@ -71,7 +71,8 @@ function convertPrefillToResponses(survey, prefillParams) {
|
|
|
71
71
|
{
|
|
72
72
|
const rating = parseInt(values[0], 10);
|
|
73
73
|
const scale = question.scale || 10;
|
|
74
|
-
|
|
74
|
+
const min = 10 === scale ? 0 : 1;
|
|
75
|
+
if (isNaN(rating) || rating < min || rating > scale) return void logger.warn(`[Survey Prefill] Invalid rating for q${index}: ${values[0]} (scale: ${min}-${scale})`);
|
|
75
76
|
responses[responseKey] = rating;
|
|
76
77
|
break;
|
|
77
78
|
}
|
package/dist/surveys-renderer.js
CHANGED
|
@@ -498,7 +498,10 @@ class SurveyManager {
|
|
|
498
498
|
return null;
|
|
499
499
|
}
|
|
500
500
|
const submissionId = (0, uuidv7_js_namespaceObject.uuidv7)();
|
|
501
|
-
const prefilledIndices = Object.keys(prefillParams).map((k)=>parseInt(k, 10))
|
|
501
|
+
const prefilledIndices = Object.keys(prefillParams).map((k)=>parseInt(k, 10)).filter((index)=>{
|
|
502
|
+
const question = survey.questions[index];
|
|
503
|
+
return question?.id && !(0, core_namespaceObject.isUndefined)(responses[(0, surveys_extension_utils_js_namespaceObject.getSurveyResponseKey)(question.id)]);
|
|
504
|
+
});
|
|
502
505
|
const { startQuestionIndex, skippedResponses, skippedIndices } = (0, survey_url_prefill_js_namespaceObject.calculatePrefillStartIndex)(survey, prefilledIndices, responses);
|
|
503
506
|
const isSurveyCompleted = startQuestionIndex >= survey.questions.length;
|
|
504
507
|
(0, surveys_extension_utils_js_namespaceObject.setInProgressSurveyState)(survey, {
|
|
@@ -456,7 +456,10 @@ class SurveyManager {
|
|
|
456
456
|
return null;
|
|
457
457
|
}
|
|
458
458
|
const submissionId = uuidv7();
|
|
459
|
-
const prefilledIndices = Object.keys(prefillParams).map((k)=>parseInt(k, 10))
|
|
459
|
+
const prefilledIndices = Object.keys(prefillParams).map((k)=>parseInt(k, 10)).filter((index)=>{
|
|
460
|
+
const question = survey.questions[index];
|
|
461
|
+
return question?.id && !isUndefined(responses[getSurveyResponseKey(question.id)]);
|
|
462
|
+
});
|
|
460
463
|
const { startQuestionIndex, skippedResponses, skippedIndices } = calculatePrefillStartIndex(survey, prefilledIndices, responses);
|
|
461
464
|
const isSurveyCompleted = startQuestionIndex >= survey.questions.length;
|
|
462
465
|
setInProgressSurveyState(survey, {
|
package/dist/utils/uuidv7.js
CHANGED
|
@@ -42,13 +42,7 @@ const core_namespaceObject = require("@posthog/core");
|
|
|
42
42
|
* @packageDocumentation
|
|
43
43
|
*
|
|
44
44
|
* from https://github.com/LiosK/uuidv7/blob/e501462ea3d23241de13192ceae726956f9b3b7d/src/index.ts
|
|
45
|
-
*/
|
|
46
|
-
return v < 0 ? Math.ceil(v) : Math.floor(v);
|
|
47
|
-
};
|
|
48
|
-
if (!Number.isInteger) Number.isInteger = function(value) {
|
|
49
|
-
return (0, core_namespaceObject.isNumber)(value) && isFinite(value) && Math.floor(value) === value;
|
|
50
|
-
};
|
|
51
|
-
class UUID {
|
|
45
|
+
*/ class UUID {
|
|
52
46
|
constructor(bytes){
|
|
53
47
|
this.bytes = bytes;
|
|
54
48
|
if (16 !== bytes.length) throw new TypeError('not 128-bit length');
|
package/dist/utils/uuidv7.mjs
CHANGED
|
@@ -8,13 +8,7 @@ import { isNumber, isUndefined } from "@posthog/core";
|
|
|
8
8
|
* @packageDocumentation
|
|
9
9
|
*
|
|
10
10
|
* from https://github.com/LiosK/uuidv7/blob/e501462ea3d23241de13192ceae726956f9b3b7d/src/index.ts
|
|
11
|
-
*/
|
|
12
|
-
return v < 0 ? Math.ceil(v) : Math.floor(v);
|
|
13
|
-
};
|
|
14
|
-
if (!Number.isInteger) Number.isInteger = function(value) {
|
|
15
|
-
return isNumber(value) && isFinite(value) && Math.floor(value) === value;
|
|
16
|
-
};
|
|
17
|
-
class UUID {
|
|
11
|
+
*/ class UUID {
|
|
18
12
|
constructor(bytes){
|
|
19
13
|
this.bytes = bytes;
|
|
20
14
|
if (16 !== bytes.length) throw new TypeError('not 128-bit length');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posthog/browser-common",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.12",
|
|
4
4
|
"description": "Internal shared browser utilities and extension primitives for PostHog Browser SDKs",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -10,9 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"sideEffects": [
|
|
12
12
|
"./dist/utils/*-polyfill.js",
|
|
13
|
-
"./dist/utils/*-polyfill.mjs"
|
|
14
|
-
"./dist/utils/uuidv7.js",
|
|
15
|
-
"./dist/utils/uuidv7.mjs"
|
|
13
|
+
"./dist/utils/*-polyfill.mjs"
|
|
16
14
|
],
|
|
17
15
|
"files": [
|
|
18
16
|
"dist",
|
|
@@ -242,8 +240,8 @@
|
|
|
242
240
|
},
|
|
243
241
|
"dependencies": {
|
|
244
242
|
"preact": "^10.29.3",
|
|
245
|
-
"@posthog/core": "^1.60.
|
|
246
|
-
"@posthog/types": "^1.416.
|
|
243
|
+
"@posthog/core": "^1.60.1",
|
|
244
|
+
"@posthog/types": "^1.416.1"
|
|
247
245
|
},
|
|
248
246
|
"devDependencies": {
|
|
249
247
|
"@rsbuild/plugin-react": "^2.1.0",
|