@spotify/backstage-plugin-pulse-common 0.6.3 → 0.8.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;
@@ -62,33 +62,32 @@ interface SurveyTemplate {
62
62
  /**
63
63
  * The survey sections, in the order they will appear in the survey
64
64
  */
65
- sections: {
66
- /**
67
- * The id of this section
68
- */
69
- id: string;
70
- /**
71
- * The name of this section
72
- */
73
- name: string;
74
- /**
75
- * An optional boolean expression that decides if the surveyee should see the questions in this section.
76
- */
77
- display_logic?: string;
78
- /**
79
- * The questions in the section (all in one page)
80
- */
81
- questions?: Question[];
82
- /**
83
- * The questions in the section, split into pages
84
- */
85
- pages?: {
86
- /**
87
- * The questions on the page
88
- */
89
- questions: Question[];
90
- }[];
91
- }[];
65
+ sections: Section[];
66
+ }
67
+ /**
68
+ * A survey section.
69
+ * @public */
70
+ interface Section {
71
+ /**
72
+ * The id of this section
73
+ */
74
+ id: string;
75
+ /**
76
+ * The name of this section
77
+ */
78
+ name: string;
79
+ /**
80
+ * An optional boolean expression that decides if the surveyee should see the questions in this section.
81
+ */
82
+ display_logic?: string;
83
+ /**
84
+ * The questions in the section (all in one page)
85
+ */
86
+ questions?: Question[];
87
+ /**
88
+ * The questions in the section, split into pages
89
+ */
90
+ pages?: Page[];
92
91
  }
93
92
  /** @public */
94
93
  interface Question {
@@ -145,7 +144,7 @@ interface Question {
145
144
  statement_groups?: {
146
145
  statements: Statement[];
147
146
  /**
148
- * The id of the group. Need only be set if referenced to in constrained randomization.
147
+ * The id of the group.
149
148
  */
150
149
  id?: string;
151
150
  /**
@@ -166,7 +165,7 @@ interface Question {
166
165
  choice_groups?: {
167
166
  choices: Choice[];
168
167
  /**
169
- * The id of the group. Need only be set if referenced to in constrained randomization.
168
+ * The id of the group.
170
169
  */
171
170
  id?: string;
172
171
  /**
@@ -198,8 +197,7 @@ interface Statement {
198
197
  }
199
198
  /**
200
199
  * Configuration of the display order randomization of choices, statements or groups.
201
- */
202
- /** @public */
200
+ * @public */
203
201
  interface Randomization {
204
202
  /**
205
203
  * The type of randomization: randomize all items, a subset of them, or using constrained randomization
@@ -241,10 +239,54 @@ interface Choice {
241
239
  */
242
240
  exclusive_answer?: boolean;
243
241
  }
242
+ /** @public */
243
+ interface Page {
244
+ /**
245
+ * The questions on the page
246
+ */
247
+ questions: Question[];
248
+ }
244
249
 
245
250
  /** @public */
246
251
  declare const validateTemplate: (template: SurveyTemplate) => void;
247
252
 
253
+ /**
254
+ * Mutates the template by replacing all references to $\{m:<macro>\} with
255
+ * the evaluation of the macro. This can and must be done once after
256
+ * loading the template and before evaluating any expression etc.
257
+ *
258
+ * The interpolation is idempotent.
259
+ *
260
+ * @public */
261
+ declare const interpolateTemplate: (template: SurveyTemplate) => SurveyTemplate;
262
+
263
+ /** Refers to a specific choice in a specific question/statement
264
+ * If statementId is defined, questionId.statementId is the full path
265
+ * to this choice
266
+ * @public */
267
+ type ChoiceRef = {
268
+ questionId: string;
269
+ statementId?: string;
270
+ choice: string | number;
271
+ };
272
+ /** Refers to a specific statement in a matrix
273
+ * @public */
274
+ type MatrixStatementRef = {
275
+ questionId: string;
276
+ statementId: string;
277
+ };
278
+ /** @public */
279
+ type LogicContextEvaluator = {
280
+ 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;
286
+ };
287
+ /** @public */
288
+ declare function evaluateExpression(expression: string, contextEvaluator: LogicContextEvaluator): any;
289
+
248
290
  /** @public */
249
291
  declare const templateSchema: {
250
292
  $id: string;
@@ -255,6 +297,7 @@ declare const templateSchema: {
255
297
  template: {
256
298
  type: string;
257
299
  description: string;
300
+ /** @public */
258
301
  properties: {
259
302
  id: {
260
303
  type: string;
@@ -331,60 +374,66 @@ declare const templateSchema: {
331
374
  type: string;
332
375
  description: string;
333
376
  items: {
334
- type: string;
335
- description: string;
336
- properties: {
337
- id: {
338
- type: string;
339
- description: string;
340
- format: string;
341
- pattern: string;
342
- };
343
- name: {
344
- type: string;
345
- description: string;
346
- };
347
- display_logic: {
348
- type: string;
349
- description: string;
350
- };
351
- questions: {
352
- type: string;
353
- description: string;
354
- items: {
355
- $ref: string;
356
- };
357
- };
358
- pages: {
359
- type: string;
360
- description: string;
361
- items: {
362
- type: string;
363
- properties: {
364
- questions: {
365
- type: string;
366
- description: string;
367
- items: {
368
- $ref: string;
369
- };
370
- };
371
- };
372
- required: string[];
373
- additionalProperties: boolean;
374
- };
375
- };
376
- };
377
- additionalProperties: boolean;
378
- required: string[];
379
- oneOf: {
380
- required: string[];
381
- }[];
377
+ $ref: string;
382
378
  };
383
379
  };
384
380
  };
385
381
  additionalProperties: boolean;
386
382
  required: string[];
387
383
  $defs: {
384
+ section: {
385
+ type: string;
386
+ description: string;
387
+ properties: {
388
+ id: {
389
+ type: string;
390
+ description: string;
391
+ format: string;
392
+ pattern: string;
393
+ };
394
+ name: {
395
+ type: string;
396
+ description: string;
397
+ };
398
+ display_logic: {
399
+ type: string;
400
+ description: string;
401
+ };
402
+ questions: {
403
+ type: string;
404
+ description: string;
405
+ items: {
406
+ $ref: string;
407
+ };
408
+ };
409
+ pages: {
410
+ type: string;
411
+ description: string;
412
+ items: {
413
+ $ref: string;
414
+ };
415
+ };
416
+ };
417
+ additionalProperties: boolean;
418
+ required: string[];
419
+ oneOf: {
420
+ required: string[];
421
+ }[];
422
+ };
423
+ page: {
424
+ type: string;
425
+ properties: {
426
+ questions: {
427
+ type: string;
428
+ description: string;
429
+ items: {
430
+ $ref: string;
431
+ };
432
+ };
433
+ };
434
+ required: string[];
435
+ additionalProperties: boolean;
436
+ };
388
437
  question: {
389
438
  type: string;
390
439
  properties: {
@@ -770,4 +819,4 @@ declare const permissions: {
770
819
  surveyAdministerPermission: _backstage_plugin_permission_common.BasicPermission;
771
820
  };
772
821
 
773
- export { Choice, DEFAULT_TEMPLATE_ID, Question, Randomization, Statement, SurveyTemplate, permissions, templateSchema, validateTemplate };
822
+ export { Choice, ChoiceRef, DEFAULT_TEMPLATE_ID, LogicContextEvaluator, MatrixStatementRef, Page, Question, Randomization, Section, Statement, SurveyTemplate, evaluateExpression, interpolateTemplate, permissions, templateSchema, validateTemplate };