@spotify/backstage-plugin-pulse-common 0.8.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
@@ -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
  */
@@ -146,7 +142,7 @@ interface Question {
146
142
  /**
147
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
  */
@@ -167,7 +163,7 @@ interface Question {
167
163
  /**
168
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
  */
@@ -260,6 +256,61 @@ declare const validateTemplate: (template: SurveyTemplate) => void;
260
256
  * @public */
261
257
  declare const interpolateTemplate: (template: SurveyTemplate) => SurveyTemplate;
262
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
+
263
314
  /** Refers to a specific choice in a specific question/statement
264
315
  * If statementId is defined, questionId.statementId is the full path
265
316
  * to this choice
@@ -276,16 +327,71 @@ type MatrixStatementRef = {
276
327
  statementId: string;
277
328
  };
278
329
  /** @public */
279
- type LogicContextEvaluator = {
330
+ declare const getAnswerValue: (answer: Answer) => string | number;
331
+ /** @public */
332
+ type TemplateContextEvaluatorOptions = {
333
+ surveyId?: string;
334
+ templateId?: string;
280
335
  surveyResponseId?: string;
281
- isSelected: (choice: ChoiceRef) => boolean;
282
- isDisplayed: (choice: ChoiceRef) => boolean;
283
- countSelected: (questionId: string) => number;
284
- countChoiceSelections: (questionId: string, choice: number | string) => number;
285
- textEntry: (choiceRef: ChoiceRef) => string;
336
+ questions: Question[];
337
+ questionResponses: SurveyQuestionResponse[];
286
338
  };
287
- /** @public */
288
- declare function evaluateExpression(expression: string, contextEvaluator: LogicContextEvaluator): any;
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[];
289
395
 
290
396
  /** @public */
291
397
  declare const templateSchema: {
@@ -297,7 +403,6 @@ declare const templateSchema: {
297
403
  template: {
298
404
  type: string;
299
405
  description: string;
300
- /** @public */
301
406
  properties: {
302
407
  id: {
303
408
  type: string;
@@ -446,10 +551,6 @@ declare const templateSchema: {
446
551
  type: string;
447
552
  description: string;
448
553
  };
449
- text_html: {
450
- type: string;
451
- description: string;
452
- };
453
554
  type: {
454
555
  type: string;
455
556
  enum: string[];
@@ -577,15 +678,10 @@ declare const templateSchema: {
577
678
  };
578
679
  };
579
680
  additionalProperties: boolean;
580
- allOf: ({
581
- oneOf: {
582
- required: string[];
583
- }[];
584
- } | {
585
- oneOf: {
586
- $ref: string;
587
- }[];
588
- })[];
681
+ required: string[];
682
+ oneOf: {
683
+ $ref: string;
684
+ }[];
589
685
  };
590
686
  "question-mc-horizontal": {
591
687
  type: string;
@@ -740,7 +836,7 @@ declare const templateSchema: {
740
836
  type: string;
741
837
  description: string;
742
838
  };
743
- text: {
839
+ text_input: {
744
840
  type: string;
745
841
  enum: string[];
746
842
  description: string;
@@ -819,4 +915,4 @@ declare const permissions: {
819
915
  surveyAdministerPermission: _backstage_plugin_permission_common.BasicPermission;
820
916
  };
821
917
 
822
- export { Choice, ChoiceRef, DEFAULT_TEMPLATE_ID, LogicContextEvaluator, MatrixStatementRef, Page, Question, Randomization, Section, Statement, SurveyTemplate, evaluateExpression, interpolateTemplate, 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 };