@posthog/core 1.49.1 → 1.49.2

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.
@@ -4,7 +4,7 @@ export declare const SURVEY_LANGUAGE_PROPERTY = "$survey_language";
4
4
  export declare function getSurveyResponseKey(questionId: string): string;
5
5
  export declare function getSurveyOldResponseKey(originalQuestionIndex: number): string;
6
6
  export declare function getSurveyResponseValue(responses: SurveyResponses, questionId?: string): SurveyResponseValue | undefined;
7
- export declare function buildSurveyResponseProperties(responses: SurveyResponses | undefined, survey: SurveyForResponses): Record<string, unknown>;
7
+ export declare function buildSurveyResponseProperties(responses: SurveyResponses | undefined, survey: SurveyForResponses, questionSnapshots?: Record<string, string>): Record<string, unknown>;
8
8
  export declare function surveyHasResponses(responses?: SurveyResponses): boolean;
9
9
  export declare function getSurveyInteractionProperty(survey: SurveyWithIteration, action: string): string;
10
10
  type SurveyQuestionForResponses = {
@@ -1 +1 @@
1
- {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/surveys/events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAA;AAC5C,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAG/D,eAAO,MAAM,wBAAwB,qBAAqB,CAAA;AAE1D,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAE/D;AAED,wBAAgB,uBAAuB,CAAC,qBAAqB,EAAE,MAAM,GAAG,MAAM,CAE7E;AAED,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,eAAe,EAC1B,UAAU,CAAC,EAAE,MAAM,GAClB,mBAAmB,GAAG,SAAS,CASjC;AAED,wBAAgB,6BAA6B,CAC3C,SAAS,EAAE,eAAe,YAAK,EAC/B,MAAM,EAAE,kBAAkB,GACzB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAsBzB;AAED,wBAAgB,kBAAkB,CAA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M,CAAA;IACX,QAAQ,EAAE,MAAM,CAAA;IAChB,qBAAqB,CAAC,EAAE,MAAM,CAAA;CAC/B,CAAA;AAED,KAAK,kBAAkB,GAAG;IACxB,SAAS,EAAE,0BAA0B,EAAE,CAAA;CACxC,CAAA"}
@@ -48,7 +48,7 @@ function getSurveyResponseValue(responses, questionId) {
48
48
  ];
49
49
  return response;
50
50
  }
51
- function buildSurveyResponseProperties(responses = {}, survey) {
51
+ function buildSurveyResponseProperties(responses = {}, survey, questionSnapshots) {
52
52
  const oldFormatResponses = {};
53
53
  survey.questions.forEach((question)=>{
54
54
  if ((0, index_js_namespaceObject.isUndefined)(question.originalQuestionIndex)) return;
@@ -59,7 +59,7 @@ function buildSurveyResponseProperties(responses = {}, survey) {
59
59
  return {
60
60
  $survey_questions: survey.questions.map((question)=>({
61
61
  id: question.id,
62
- question: question.question,
62
+ question: questionSnapshots?.[question.id ?? ''] ?? question.question,
63
63
  response: getSurveyResponseValue(responses, question.id)
64
64
  })),
65
65
  ...responses,
@@ -14,7 +14,7 @@ function getSurveyResponseValue(responses, questionId) {
14
14
  ];
15
15
  return response;
16
16
  }
17
- function buildSurveyResponseProperties(responses = {}, survey) {
17
+ function buildSurveyResponseProperties(responses = {}, survey, questionSnapshots) {
18
18
  const oldFormatResponses = {};
19
19
  survey.questions.forEach((question)=>{
20
20
  if (isUndefined(question.originalQuestionIndex)) return;
@@ -25,7 +25,7 @@ function buildSurveyResponseProperties(responses = {}, survey) {
25
25
  return {
26
26
  $survey_questions: survey.questions.map((question)=>({
27
27
  id: question.id,
28
- question: question.question,
28
+ question: questionSnapshots?.[question.id ?? ''] ?? question.question,
29
29
  response: getSurveyResponseValue(responses, question.id)
30
30
  })),
31
31
  ...responses,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posthog/core",
3
- "version": "1.49.1",
3
+ "version": "1.49.2",
4
4
  "bugs": {
5
5
  "url": "https://github.com/PostHog/posthog-js/issues"
6
6
  },
@@ -70,7 +70,7 @@
70
70
  }
71
71
  },
72
72
  "dependencies": {
73
- "@posthog/types": "^1.407.0"
73
+ "@posthog/types": "^1.407.1"
74
74
  },
75
75
  "devDependencies": {
76
76
  "@rslib/core": "0.10.6",
@@ -35,6 +35,47 @@ describe('survey event helpers', () => {
35
35
  })
36
36
  })
37
37
 
38
+ it('prefers question snapshots over the current question text', () => {
39
+ const responses = { [getSurveyResponseKey('q1')]: 5 }
40
+ const questionSnapshots = { q1: 'Rate us (French)' }
41
+
42
+ expect(buildSurveyResponseProperties(responses, survey, questionSnapshots)).toEqual(
43
+ expect.objectContaining({
44
+ $survey_questions: [
45
+ { id: 'q1', question: 'Rate us (French)', response: 5 },
46
+ { id: 'q2', question: 'Anything else?', response: undefined },
47
+ ],
48
+ })
49
+ )
50
+ })
51
+
52
+ it('falls back to the current question text for a question with no snapshot', () => {
53
+ const questionSnapshots = { q1: 'Rate us (French)' }
54
+
55
+ expect(buildSurveyResponseProperties({}, survey, questionSnapshots)).toEqual(
56
+ expect.objectContaining({
57
+ $survey_questions: expect.arrayContaining([{ id: 'q2', question: 'Anything else?', response: undefined }]),
58
+ })
59
+ )
60
+ })
61
+
62
+ it('falls back to the current question text when the question id is an empty string', () => {
63
+ const surveyWithEmptyId = {
64
+ ...survey,
65
+ questions: [{ id: '', question: 'Untitled', originalQuestionIndex: 0 }],
66
+ }
67
+ // A snapshot recorded under the empty-string key must not be picked up for a
68
+ // question whose id is also '' — only an explicit questionSnapshots[''] set by
69
+ // the caller should ever surface here, and there is none in this case.
70
+ const questionSnapshots = {}
71
+
72
+ expect(buildSurveyResponseProperties({}, surveyWithEmptyId, questionSnapshots)).toEqual(
73
+ expect.objectContaining({
74
+ $survey_questions: [{ id: '', question: 'Untitled', response: null }],
75
+ })
76
+ )
77
+ })
78
+
38
79
  it('copies array response values before returning them', () => {
39
80
  const responses = { [getSurveyResponseKey('q1')]: ['a'] }
40
81
 
@@ -28,7 +28,8 @@ export function getSurveyResponseValue(
28
28
 
29
29
  export function buildSurveyResponseProperties(
30
30
  responses: SurveyResponses = {},
31
- survey: SurveyForResponses
31
+ survey: SurveyForResponses,
32
+ questionSnapshots?: Record<string, string>
32
33
  ): Record<string, unknown> {
33
34
  const oldFormatResponses: SurveyResponses = {}
34
35
  survey.questions.forEach((question: SurveyQuestionForResponses) => {
@@ -45,7 +46,7 @@ export function buildSurveyResponseProperties(
45
46
  return {
46
47
  $survey_questions: survey.questions.map((question: SurveyQuestionForResponses) => ({
47
48
  id: question.id,
48
- question: question.question,
49
+ question: questionSnapshots?.[question.id ?? ''] ?? question.question,
49
50
  response: getSurveyResponseValue(responses, question.id),
50
51
  })),
51
52
  ...responses,