@spotify/backstage-plugin-pulse-common 0.7.0 → 0.9.0

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/index.d.ts CHANGED
@@ -54,7 +54,7 @@ interface SurveyTemplate {
54
54
  default?: string | number | boolean;
55
55
  }[];
56
56
  /**
57
- * Expression shortcuts. Macros are referred to elsewhere in the survey using the $\{p:<name>\} construct (same as parameters) and will get lazily in-place replaced. Macros can be recursive and contain references to parameters or answers in the survey.
57
+ * Expression shortcuts. Macros are referred to elsewhere in the survey using the $\{m:<name>\} construct (similar to parameters) and will get lazily in-place replaced. Macros can be recursive and contain references to parameters or answers in the survey.
58
58
  */
59
59
  macros?: {
60
60
  [k: string]: string;
@@ -98,11 +98,7 @@ interface Question {
98
98
  /**
99
99
  * The question description, in markdown
100
100
  */
101
- text?: string;
102
- /**
103
- * The question description, in HTML
104
- */
105
- text_html?: string;
101
+ text: string;
106
102
  /**
107
103
  * The type of question
108
104
  */
@@ -144,9 +140,9 @@ interface Question {
144
140
  statement_groups?: {
145
141
  statements: Statement[];
146
142
  /**
147
- * The id of the group. Need only be set if referenced to in constrained randomization.
143
+ * The id of the group.
148
144
  */
149
- id?: string;
145
+ id: string;
150
146
  /**
151
147
  * The display name of the group
152
148
  */
@@ -165,9 +161,9 @@ interface Question {
165
161
  choice_groups?: {
166
162
  choices: Choice[];
167
163
  /**
168
- * The id of the group. Need only be set if referenced to in constrained randomization.
164
+ * The id of the group.
169
165
  */
170
- id?: string;
166
+ id: string;
171
167
  /**
172
168
  * The display name of the group
173
169
  */
@@ -233,7 +229,7 @@ interface Choice {
233
229
  /**
234
230
  * If a textbox should appear next to the choice, and if it should be mandatory to fill it in if the choice is selected
235
231
  */
236
- text?: 'no' | 'optional' | 'forced';
232
+ text_input?: 'no' | 'optional' | 'forced';
237
233
  /**
238
234
  * If true, this choice can't be combined with other choices in this question
239
235
  */
@@ -250,6 +246,153 @@ interface Page {
250
246
  /** @public */
251
247
  declare const validateTemplate: (template: SurveyTemplate) => void;
252
248
 
249
+ /**
250
+ * Mutates the template by replacing all references to $\{m:<macro>\} with
251
+ * the evaluation of the macro. This can and must be done once after
252
+ * loading the template and before evaluating any expression etc.
253
+ *
254
+ * The interpolation is idempotent.
255
+ *
256
+ * @public */
257
+ declare const interpolateTemplate: (template: SurveyTemplate) => SurveyTemplate;
258
+
259
+ /** @public */
260
+ declare enum LOCATOR_EXPRESSION {
261
+ ALL = "all",
262
+ ALL_ENTERED_TEXT = "all_entered_text",
263
+ SELECTED = "selected",
264
+ SELECTED_ENTERED_TEXT = "selected_entered_text",
265
+ NOT_SELECTED = "not_selected",
266
+ FOR_MATRIX_CHOICE = "for_matrix_choice",
267
+ UNSELECTED_FOR_MATRIX_CHOICE = "unselected_for_matrix_choice",
268
+ DISPLAYED = "displayed",
269
+ NOT_DISPLAYED = "not_displayed"
270
+ }
271
+ /** @public */
272
+ type Locator = {
273
+ questionId: string;
274
+ expression: LOCATOR_EXPRESSION;
275
+ identifier?: string | number;
276
+ };
277
+ /** @public */
278
+ declare const validateLocator: (locatorExpression: string) => boolean;
279
+ /** @public */
280
+ declare const parseLocator: (locatorExpression: string) => Locator;
281
+
282
+ /** @public */
283
+ type Answer = {
284
+ choiceId?: string | null;
285
+ choiceValue?: number | null;
286
+ text?: string | null;
287
+ };
288
+ /** @public */
289
+ type SurveyQuestionResponse = {
290
+ id: string;
291
+ surveyId: string;
292
+ questionId: string;
293
+ surveyResponseId: string;
294
+ /** The ID of the statement. Only set if question.type is MATRIX_SINGLE or MATRIX_MULTI. */
295
+ statementId?: string | null;
296
+ /** The selected choices for multiple answer questions (mc-multi, matrix-multi). */
297
+ multipleAnswers?: readonly Answer[] | null;
298
+ /** The selected choice for single answer questions (mc-single, matrix-single). */
299
+ singleAnswer?: Answer | null;
300
+ createdAt: Date;
301
+ updatedAt: Date;
302
+ };
303
+ /** @public */
304
+ type StatementWithGroupInfo = Statement & {
305
+ groupId?: string;
306
+ groupDisplay?: string;
307
+ };
308
+ /** @public */
309
+ type ChoiceWithGroupInfo = Choice & {
310
+ groupId?: string;
311
+ groupDisplay?: string;
312
+ };
313
+
314
+ /** Refers to a specific choice in a specific question/statement
315
+ * If statementId is defined, questionId.statementId is the full path
316
+ * to this choice
317
+ * @public */
318
+ type ChoiceRef = {
319
+ questionId: string;
320
+ statementId?: string;
321
+ choice: string | number;
322
+ };
323
+ /** Refers to a specific statement in a matrix
324
+ * @public */
325
+ type MatrixStatementRef = {
326
+ questionId: string;
327
+ statementId: string;
328
+ };
329
+ /** @public */
330
+ declare const getAnswerValue: (answer: Answer) => string | number;
331
+ /** @public */
332
+ type TemplateContextEvaluatorOptions = {
333
+ surveyId?: string;
334
+ templateId?: string;
335
+ surveyResponseId?: string;
336
+ questions: Question[];
337
+ questionResponses: SurveyQuestionResponse[];
338
+ };
339
+ /**
340
+ * Provides useful methods for making template schema evaluations given a particular response context
341
+ * @public */
342
+ declare class TemplateContextEvaluator {
343
+ #private;
344
+ surveyId?: string;
345
+ templateId?: string;
346
+ surveyResponseId?: string;
347
+ questions: Question[];
348
+ questionResponses: SurveyQuestionResponse[];
349
+ constructor(options: TemplateContextEvaluatorOptions);
350
+ /**
351
+ * Returns the relevant answers for a particular question. If a statement ID or choice
352
+ * identifier is provided, answers will be filtered to those matching the specified
353
+ * inputs.
354
+ */
355
+ getQuestionAnswers(questionId: string, statementId?: string | null, choiceIdOrValue?: string | number | null): Answer[];
356
+ /**
357
+ * Returns the list of choices or statements referenced by a locator taking into
358
+ * account the current response context.
359
+ */
360
+ evaluateDynamicExpression<T extends Choice | Statement>(locator: Locator, target: 'choices' | 'statements'): T[];
361
+ isStatementSelected(statement: MatrixStatementRef): boolean;
362
+ isSelected(choice: ChoiceRef): boolean;
363
+ isDisplayed(_: ChoiceRef): boolean;
364
+ countSelected(questionId: string): number;
365
+ countChoiceSelections(questionId: string, choice: number | string): number;
366
+ textEntry(choice: ChoiceRef): string;
367
+ }
368
+ /**
369
+ * Returns a context evaluator with no responses which effectively means most
370
+ * display logic expressions would evaluate to false. This evaluator is useful when
371
+ * there is no existing surver response such as when a user first begins taking a survey.
372
+ * @public */
373
+ declare const getBaseContextEvaluator: (questions?: Question[]) => TemplateContextEvaluator;
374
+ /**
375
+ * Evaluates a display logic expression using the given response context
376
+ * @public */
377
+ declare const evaluateDisplayLogic: (evaluator: TemplateContextEvaluator, expression?: string) => boolean;
378
+ /**
379
+ * Returns the question text with any dynamic expressions interpolated.
380
+ * @public
381
+ */
382
+ declare const getQuestionText: (question: Question, evaluator?: TemplateContextEvaluator | null) => string;
383
+ /**
384
+ * Returns all choices that are valid for a particular question given a specific
385
+ * response context. This takes into account choices that are in groups and
386
+ * dynamic choices that may come from other questions.
387
+ * @public */
388
+ declare const getQuestionChoices: (question: Question, evaluator?: TemplateContextEvaluator | null) => ChoiceWithGroupInfo[];
389
+ /**
390
+ * Returns all statements that are valid for a particular question given a specific
391
+ * response context. This takes into account statements that are in groups and
392
+ * dynamic statements that may come from other questions.
393
+ * @public */
394
+ declare const getQuestionStatements: (question: Question, evaluator?: TemplateContextEvaluator | null) => StatementWithGroupInfo[];
395
+
253
396
  /** @public */
254
397
  declare const templateSchema: {
255
398
  $id: string;
@@ -408,10 +551,6 @@ declare const templateSchema: {
408
551
  type: string;
409
552
  description: string;
410
553
  };
411
- text_html: {
412
- type: string;
413
- description: string;
414
- };
415
554
  type: {
416
555
  type: string;
417
556
  enum: string[];
@@ -539,15 +678,10 @@ declare const templateSchema: {
539
678
  };
540
679
  };
541
680
  additionalProperties: boolean;
542
- allOf: ({
543
- oneOf: {
544
- required: string[];
545
- }[];
546
- } | {
547
- oneOf: {
548
- $ref: string;
549
- }[];
550
- })[];
681
+ required: string[];
682
+ oneOf: {
683
+ $ref: string;
684
+ }[];
551
685
  };
552
686
  "question-mc-horizontal": {
553
687
  type: string;
@@ -702,7 +836,7 @@ declare const templateSchema: {
702
836
  type: string;
703
837
  description: string;
704
838
  };
705
- text: {
839
+ text_input: {
706
840
  type: string;
707
841
  enum: string[];
708
842
  description: string;
@@ -781,4 +915,4 @@ declare const permissions: {
781
915
  surveyAdministerPermission: _backstage_plugin_permission_common.BasicPermission;
782
916
  };
783
917
 
784
- export { Choice, DEFAULT_TEMPLATE_ID, Page, Question, Randomization, Section, Statement, SurveyTemplate, permissions, templateSchema, validateTemplate };
918
+ export { Answer, Choice, ChoiceRef, ChoiceWithGroupInfo, DEFAULT_TEMPLATE_ID, LOCATOR_EXPRESSION, Locator, MatrixStatementRef, Page, Question, Randomization, Section, Statement, StatementWithGroupInfo, SurveyQuestionResponse, SurveyTemplate, TemplateContextEvaluator, TemplateContextEvaluatorOptions, evaluateDisplayLogic, getAnswerValue, getBaseContextEvaluator, getQuestionChoices, getQuestionStatements, getQuestionText, interpolateTemplate, parseLocator, permissions, templateSchema, validateLocator, validateTemplate };