@spotify/backstage-plugin-pulse-common 0.5.1 → 0.6.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/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @spotify/backstage-plugin-pulse-common
2
2
 
3
+ ## 0.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Changed how survey questions are loaded to allow customization in the future.
8
+
9
+ ### Patch Changes
10
+
11
+ - Upgraded Backstage to `v1.13.0`.
12
+ - Added utilities for handling survey templates.
13
+
3
14
  ## 0.5.1
4
15
 
5
16
  ### Patch Changes
package/dist/index.cjs.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var s=require("@backstage/plugin-permission-common");const i="survey-instance",e=s.createPermission({name:"survey.instance.administer",attributes:{action:"create"}}),r=[e],n={allPermissions:r,SURVEY_RESOURCE_TYPE:i,surveyAdministerPermission:e};exports.permissions=n;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var o=require("@backstage/plugin-permission-common"),n=require("ajv"),a=require("ajv-formats");function t(e){return e&&typeof e=="object"&&"default"in e?e:{default:e}}var d=t(n),p=t(a);const c="survey-instance",i=o.createPermission({name:"survey.instance.administer",attributes:{action:"create"}}),u=[i];var l="http://json-schema.org/draft-07/schema",m="Survey Template",y="object",h={template:{type:"object",description:"Meta data about the survey template",properties:{id:{type:"string",description:"An id of the survey template. If there are multiple templates with the same id, they must have different versions.",format:"regex",pattern:"^[a-zA-Z][a-zA-Z0-9_-]*[a-zA-Z0-9]$",minLength:1},version:{type:"string",format:"regex",pattern:"^[0-9]+(\\.[0-9]+)?$",description:"A version of template"},name:{type:"string",description:"The display name of the survey template",minLength:1},description:{type:"string",description:"A longer description of the survey template"},owner:{type:"string",description:"The owner of the survey template",minLength:1}},required:["id","version","name","owner"],additionalProperties:!1},parameters:{type:"array",description:"Template parameters that can or must be set when creating a survey from this template. Parameters are referred to elsewhere in the survey using the ${p:<id>} construct and will get lazily in-place replaced.",items:{type:"object",properties:{id:{type:"string",description:"The id of the parameter",format:"regex",pattern:"^[a-zA-Z][a-zA-Z0-9_]*$"},description:{type:"string",description:"The description of the parameter"},format:{type:"string",enum:["string","number","boolean"],description:"The format of the parameter. Should only be set if a default value is not provided."},default:{type:["string","number","boolean"],description:"An optional default value of this parameter. If this is omitted, the parameter must be provided when creating a survey from the template."}},required:["id","description"],oneOf:[{required:["format"]},{required:["default"]}],additionalProperties:!1}},macros:{type:"object",description:"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.",additionalProperties:{type:"string"}},sections:{type:"array",description:"The survey sections, in the order they will appear in the survey",items:{type:"object",description:"A survey section.",properties:{id:{type:"string",description:"The id of this section",format:"regex",pattern:"^[a-zA-Z][a-zA-Z0-9_-]*[a-zA-Z0-9]$"},name:{type:"string",description:"The name of this section"},display_logic:{type:"string",description:"An optional boolean expression that decides if the surveyee should see the questions in this section."},questions:{type:"array",description:"The questions in the section (all in one page)",items:{$ref:"#/$defs/question"}},pages:{type:"array",description:"The questions in the section, split into pages",items:{type:"object",properties:{questions:{type:"array",description:"The questions on the page",items:{$ref:"#/$defs/question"}}},required:["questions"],additionalProperties:!1}}},additionalProperties:!1,required:["id","name"],oneOf:[{required:["questions"]},{required:["pages"]}]}}},f=!1,g=["template","parameters","sections"],q={question:{type:"object",properties:{id:{type:"string",description:"The unique ID of the question",pattern:"^[a-zA-Z][a-zA-Z0-9_]*$"},text:{type:"string",description:"The question description, in markdown"},text_html:{type:"string",description:"The question description, in HTML"},type:{type:"string",enum:["mc-single","mc-multi","matrix-single","matrix-multi","text-single","text-multi","description"],description:"The type of question"},layout:{type:"string",enum:["vertical","horizontal"],description:"Determines the visual layout of the options in multiple choice questions"},display_logic:{type:"string",description:"A boolean expression with logic if this question should be displayed or not"},display_logic_in_page:{type:"string",description:"Similar to display_logic, but enables the question to appear on the same page as the depending question"},required:{type:"string",enum:["required","optional","request"],description:"If the question is required to answer; request means you will get a warning if you skip it but you can."},validation:{type:"object",description:"Validation constraints on the question. Only applied if the user has answered the question, so typically used in combination with required",properties:{min_choices:{type:"integer",description:"The minimum number of choices to user can pick (multiple choice questions only)"},max_choices:{type:"integer",description:"The maximum number of choices to user can pick (multiple choice questions only)"}},additionalProperties:!1},statements:{type:"array",items:{$ref:"#/$defs/statement"}},dynamic_statements:{type:"string",description:"Carry forward statements from a previous question",pattern:"^[a-zA-Z][a-zA-Z0-9_]*/(all|selected|all_entered_text|selected_entered_text|not_selected|displayed|not_displayed|for_matrix_choice\\([\\-a-zA-Z0-9_]+\\)|unselected_for_matrix_choice\\([\\-a-zA-Z0-9_]+\\))$"},statement_groups:{type:"array",items:{type:"object",properties:{statements:{type:"array",items:{$ref:"#/$defs/statement"}},id:{type:"string",description:"The id of the group. Need only be set if referenced to in constrained randomization."},display:{type:"string",description:"The display name of the group"},display_logic:{type:"string",description:"A boolean expression determining if the group should be displayed"},randomization:{$ref:"#/$defs/randomization"}},required:["statements","display"],additionalProperties:!1}},choices:{type:"array",items:{$ref:"#/$defs/choice"}},dynamic_choices:{type:"string",description:"Carry forward choices from a previous question",pattern:"^[a-zA-Z][a-zA-Z0-9_]*/(all|selected|all_entered_text|selected_entered_text|not_selected|displayed|not_displayed|for_matrix_choice\\([\\-a-zA-Z0-9_]+\\)|unselected_for_matrix_choice\\([\\-a-zA-Z0-9_]+\\))$"},choice_groups:{type:"array",items:{type:"object",properties:{choices:{type:"array",items:{$ref:"#/$defs/choice"}},id:{type:"string",description:"The id of the group. Need only be set if referenced to in constrained randomization."},display:{type:"string",description:"The display name of the group"},display_logic:{type:"string",description:"A boolean expression determining if the group should be displayed"},randomization:{$ref:"#/$defs/randomization"}},required:["choices","display"],additionalProperties:!1}},randomization:{$ref:"#/$defs/randomization"}},additionalProperties:!1,allOf:[{oneOf:[{required:["text"]},{required:["text_html"]}]},{oneOf:[{$ref:"#/$defs/question-mc-horizontal"},{$ref:"#/$defs/question-mc-vertical"},{$ref:"#/$defs/question-matrix"},{$ref:"#/$defs/question-text"},{$ref:"#/$defs/question-description"}]}]},"question-mc-horizontal":{type:"object",properties:{type:{enum:["mc-single","mc-multi"]},position:{const:"horizontal"}},required:["id","type","position","choices"],not:{anyOf:[{required:["choice_groups"]},{required:["dynamic_choices"]},{required:["statements"]},{required:["dynamic_statements"]},{required:["statement_groups"]}]}},"question-mc-vertical":{type:"object",properties:{type:{enum:["mc-single","mc-multi"]},position:{const:"vertical"}},required:["id","type"],not:{anyOf:[{required:["statements"]},{required:["dynamic_statements"]},{required:["statement_groups"]}]},oneOf:[{anyOf:[{required:["choices"]},{required:["dynamic_choices"]}],not:{required:["choice_groups"]}},{required:["choice_groups"],not:{anyOf:[{required:["choices"]},{required:["dynamic_choices"]}]}}]},"question-matrix":{type:"object",properties:{type:{enum:["matrix-single","matrix-multi"]}},required:["id","type","choices"],not:{anyOf:[{required:["dynamic_choices"]},{required:["choice_groups"]}]},oneOf:[{anyOf:[{required:["statements"]},{required:["dynamic_statements"]}],not:{required:["statement_groups"]}},{required:["statement_groups"],not:{anyOf:[{required:["statements"]},{required:["dynamic_statements"]}]}}]},"question-text":{type:"object",properties:{type:{enum:["text-single","text-multi"]}},required:["id","type"],not:{anyOf:[{required:["choices"]},{required:["choice_groups"]},{required:["dynamic_choices"]},{required:["statements"]},{required:["statement_groups"]},{required:["dynamic_statements"]},{required:["randomization"]}]}},"question-description":{type:"object",properties:{type:{const:"description"}},not:{anyOf:[{required:["choices"]},{required:["choice_groups"]},{required:["dynamic_choices"]},{required:["statements"]},{required:["statement_groups"]},{required:["dynamic_statements"]},{required:["randomization"]}]}},statement:{type:"object",properties:{id:{type:"string",pattern:"^[a-zA-Z][a-zA-Z0-9_]*$",description:"The id of the statement"},display:{type:"string",description:"The statement name, as shown to the surveyee"},display_logic:{type:"string",description:"A boolean expression determining if the statement should be displayed"}},required:["id","display"],additionalProperties:!1},choice:{type:"object",properties:{display:{type:"string",description:"The choice name, as shown to the surveyee"},id:{type:"string",pattern:"^[a-zA-Z][a-zA-Z0-9_]*$",description:"The id of the choice"},value:{type:"integer",description:"The value the choice"},display_logic:{type:"string",description:"A boolean expression determining if the choice should be displayed"},text:{type:"string",enum:["no","optional","forced"],description:"If a textbox should appear next to the choice, and if it should be mandatory to fill it in if the choice is selected"},exclusive_answer:{type:"boolean",description:"If true, this choice can't be combined with other choices in this question"}},required:["display"],anyOf:[{required:["value"]},{required:["id"]}],additionalProperties:!1},randomization:{type:"object",description:"Configuration of the display order randomization of choices, statements or groups.",properties:{type:{type:"string",description:"The type of randomization: randomize all items, a subset of them, or using constrained randomization",enum:["all","subset","constrained"]},total:{type:"integer",description:"Maximum number of items to show"},order:{type:"string",description:"A space separated string containing the order of the items; each 'word' is either an id of some item or the wildcard $ representing the remaining items"}},required:["type"],oneOf:[{properties:{type:{const:"all"}},not:{required:["total","order"]}},{properties:{type:{const:"subset"}},required:["total"],not:{required:["order"]}},{properties:{type:{const:"constrained"}},required:["order"]}],additionalProperties:!1}},_={$schema:l,title:m,type:y,properties:h,additionalProperties:f,required:g,$defs:q};const r=new d.default({allowUnionTypes:!0});p.default(r);const s=r.compile(_),v=e=>{if(!s(e))throw new Error(`Invalid template: ${e.template.id}. Reason: ${s.errors}`)},b="pulse_default_alpha",$={allPermissions:u,SURVEY_RESOURCE_TYPE:c,surveyAdministerPermission:i};exports.DEFAULT_TEMPLATE_ID=b,exports.permissions=$,exports.validateTemplate=v;
2
2
  //# sourceMappingURL=index.cjs.js.map
package/dist/index.d.ts CHANGED
@@ -1,5 +1,253 @@
1
1
  import * as _backstage_plugin_permission_common from '@backstage/plugin-permission-common';
2
2
 
3
+ /**
4
+ * Types automatically generated by `yarn json2ts`.
5
+ * To resolve api-report warnings you will need to manually add @public tags
6
+ * and escape chars for macro braces ("${p:<id>}").
7
+ */
8
+ /** @public */
9
+ interface SurveyTemplate {
10
+ /**
11
+ * Meta data about the survey template
12
+ */
13
+ template: {
14
+ /**
15
+ * An id of the survey template. If there are multiple templates with the same id, they must have different versions.
16
+ */
17
+ id: string;
18
+ /**
19
+ * A version of template
20
+ */
21
+ version: string;
22
+ /**
23
+ * The display name of the survey template
24
+ */
25
+ name: string;
26
+ /**
27
+ * A longer description of the survey template
28
+ */
29
+ description?: string;
30
+ /**
31
+ * The owner of the survey template
32
+ */
33
+ owner: string;
34
+ };
35
+ /**
36
+ * Template parameters that can or must be set when creating a survey from this template. Parameters are referred to elsewhere in the survey using the $\{p:<id>\} construct and will get lazily in-place replaced.
37
+ */
38
+ parameters: {
39
+ /**
40
+ * The id of the parameter
41
+ */
42
+ id: string;
43
+ /**
44
+ * The description of the parameter
45
+ */
46
+ description: string;
47
+ /**
48
+ * The format of the parameter. Should only be set if a default value is not provided.
49
+ */
50
+ format?: 'string' | 'number' | 'boolean';
51
+ /**
52
+ * An optional default value of this parameter. If this is omitted, the parameter must be provided when creating a survey from the template.
53
+ */
54
+ default?: string | number | boolean;
55
+ }[];
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.
58
+ */
59
+ macros?: {
60
+ [k: string]: string;
61
+ };
62
+ /**
63
+ * The survey sections, in the order they will appear in the survey
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
+ }[];
92
+ }
93
+ /** @public */
94
+ interface Question {
95
+ /**
96
+ * The unique ID of the question
97
+ */
98
+ id?: string;
99
+ /**
100
+ * The question description, in markdown
101
+ */
102
+ text?: string;
103
+ /**
104
+ * The question description, in HTML
105
+ */
106
+ text_html?: string;
107
+ /**
108
+ * The type of question
109
+ */
110
+ type?: 'mc-single' | 'mc-multi' | 'matrix-single' | 'matrix-multi' | 'text-single' | 'text-multi' | 'description';
111
+ /**
112
+ * Determines the visual layout of the options in multiple choice questions
113
+ */
114
+ layout?: 'vertical' | 'horizontal';
115
+ /**
116
+ * A boolean expression with logic if this question should be displayed or not
117
+ */
118
+ display_logic?: string;
119
+ /**
120
+ * Similar to display_logic, but enables the question to appear on the same page as the depending question
121
+ */
122
+ display_logic_in_page?: string;
123
+ /**
124
+ * If the question is required to answer; request means you will get a warning if you skip it but you can.
125
+ */
126
+ required?: 'required' | 'optional' | 'request';
127
+ /**
128
+ * Validation constraints on the question. Only applied if the user has answered the question, so typically used in combination with required
129
+ */
130
+ validation?: {
131
+ /**
132
+ * The minimum number of choices to user can pick (multiple choice questions only)
133
+ */
134
+ min_choices?: number;
135
+ /**
136
+ * The maximum number of choices to user can pick (multiple choice questions only)
137
+ */
138
+ max_choices?: number;
139
+ };
140
+ statements?: Statement[];
141
+ /**
142
+ * Carry forward statements from a previous question
143
+ */
144
+ dynamic_statements?: string;
145
+ statement_groups?: {
146
+ statements: Statement[];
147
+ /**
148
+ * The id of the group. Need only be set if referenced to in constrained randomization.
149
+ */
150
+ id?: string;
151
+ /**
152
+ * The display name of the group
153
+ */
154
+ display: string;
155
+ /**
156
+ * A boolean expression determining if the group should be displayed
157
+ */
158
+ display_logic?: string;
159
+ randomization?: Randomization;
160
+ }[];
161
+ choices?: Choice[];
162
+ /**
163
+ * Carry forward choices from a previous question
164
+ */
165
+ dynamic_choices?: string;
166
+ choice_groups?: {
167
+ choices: Choice[];
168
+ /**
169
+ * The id of the group. Need only be set if referenced to in constrained randomization.
170
+ */
171
+ id?: string;
172
+ /**
173
+ * The display name of the group
174
+ */
175
+ display: string;
176
+ /**
177
+ * A boolean expression determining if the group should be displayed
178
+ */
179
+ display_logic?: string;
180
+ randomization?: Randomization;
181
+ }[];
182
+ randomization?: Randomization;
183
+ }
184
+ /** @public */
185
+ interface Statement {
186
+ /**
187
+ * The id of the statement
188
+ */
189
+ id: string;
190
+ /**
191
+ * The statement name, as shown to the surveyee
192
+ */
193
+ display: string;
194
+ /**
195
+ * A boolean expression determining if the statement should be displayed
196
+ */
197
+ display_logic?: string;
198
+ }
199
+ /**
200
+ * Configuration of the display order randomization of choices, statements or groups.
201
+ */
202
+ /** @public */
203
+ interface Randomization {
204
+ /**
205
+ * The type of randomization: randomize all items, a subset of them, or using constrained randomization
206
+ */
207
+ type: 'all' | 'subset' | 'constrained';
208
+ /**
209
+ * Maximum number of items to show
210
+ */
211
+ total?: number;
212
+ /**
213
+ * A space separated string containing the order of the items; each 'word' is either an id of some item or the wildcard $ representing the remaining items
214
+ */
215
+ order?: string;
216
+ }
217
+ /** @public */
218
+ interface Choice {
219
+ /**
220
+ * The choice name, as shown to the surveyee
221
+ */
222
+ display: string;
223
+ /**
224
+ * The id of the choice
225
+ */
226
+ id?: string;
227
+ /**
228
+ * The value the choice
229
+ */
230
+ value?: number;
231
+ /**
232
+ * A boolean expression determining if the choice should be displayed
233
+ */
234
+ display_logic?: string;
235
+ /**
236
+ * If a textbox should appear next to the choice, and if it should be mandatory to fill it in if the choice is selected
237
+ */
238
+ text?: 'no' | 'optional' | 'forced';
239
+ /**
240
+ * If true, this choice can't be combined with other choices in this question
241
+ */
242
+ exclusive_answer?: boolean;
243
+ }
244
+
245
+ /** @public */
246
+ declare const validateTemplate: (template: SurveyTemplate) => void;
247
+
248
+ /** @public */
249
+ declare const DEFAULT_TEMPLATE_ID = "pulse_default_alpha";
250
+
3
251
  /** @public */
4
252
  declare const permissions: {
5
253
  allPermissions: _backstage_plugin_permission_common.BasicPermission[];
@@ -7,4 +255,4 @@ declare const permissions: {
7
255
  surveyAdministerPermission: _backstage_plugin_permission_common.BasicPermission;
8
256
  };
9
257
 
10
- export { permissions };
258
+ export { Choice, DEFAULT_TEMPLATE_ID, Question, Randomization, Statement, SurveyTemplate, permissions, validateTemplate };
package/dist/index.esm.js CHANGED
@@ -1,2 +1,2 @@
1
- import{createPermission as i}from"@backstage/plugin-permission-common";const e="survey-instance",s=i({name:"survey.instance.administer",attributes:{action:"create"}}),r=[s],n={allPermissions:r,SURVEY_RESOURCE_TYPE:e,surveyAdministerPermission:s};export{n as permissions};
1
+ import{createPermission as s}from"@backstage/plugin-permission-common";import o from"ajv";import n from"ajv-formats";const a="survey-instance",t=s({name:"survey.instance.administer",attributes:{action:"create"}}),p=[t];var d="http://json-schema.org/draft-07/schema",c="Survey Template",u="object",m={template:{type:"object",description:"Meta data about the survey template",properties:{id:{type:"string",description:"An id of the survey template. If there are multiple templates with the same id, they must have different versions.",format:"regex",pattern:"^[a-zA-Z][a-zA-Z0-9_-]*[a-zA-Z0-9]$",minLength:1},version:{type:"string",format:"regex",pattern:"^[0-9]+(\\.[0-9]+)?$",description:"A version of template"},name:{type:"string",description:"The display name of the survey template",minLength:1},description:{type:"string",description:"A longer description of the survey template"},owner:{type:"string",description:"The owner of the survey template",minLength:1}},required:["id","version","name","owner"],additionalProperties:!1},parameters:{type:"array",description:"Template parameters that can or must be set when creating a survey from this template. Parameters are referred to elsewhere in the survey using the ${p:<id>} construct and will get lazily in-place replaced.",items:{type:"object",properties:{id:{type:"string",description:"The id of the parameter",format:"regex",pattern:"^[a-zA-Z][a-zA-Z0-9_]*$"},description:{type:"string",description:"The description of the parameter"},format:{type:"string",enum:["string","number","boolean"],description:"The format of the parameter. Should only be set if a default value is not provided."},default:{type:["string","number","boolean"],description:"An optional default value of this parameter. If this is omitted, the parameter must be provided when creating a survey from the template."}},required:["id","description"],oneOf:[{required:["format"]},{required:["default"]}],additionalProperties:!1}},macros:{type:"object",description:"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.",additionalProperties:{type:"string"}},sections:{type:"array",description:"The survey sections, in the order they will appear in the survey",items:{type:"object",description:"A survey section.",properties:{id:{type:"string",description:"The id of this section",format:"regex",pattern:"^[a-zA-Z][a-zA-Z0-9_-]*[a-zA-Z0-9]$"},name:{type:"string",description:"The name of this section"},display_logic:{type:"string",description:"An optional boolean expression that decides if the surveyee should see the questions in this section."},questions:{type:"array",description:"The questions in the section (all in one page)",items:{$ref:"#/$defs/question"}},pages:{type:"array",description:"The questions in the section, split into pages",items:{type:"object",properties:{questions:{type:"array",description:"The questions on the page",items:{$ref:"#/$defs/question"}}},required:["questions"],additionalProperties:!1}}},additionalProperties:!1,required:["id","name"],oneOf:[{required:["questions"]},{required:["pages"]}]}}},l=!1,y=["template","parameters","sections"],h={question:{type:"object",properties:{id:{type:"string",description:"The unique ID of the question",pattern:"^[a-zA-Z][a-zA-Z0-9_]*$"},text:{type:"string",description:"The question description, in markdown"},text_html:{type:"string",description:"The question description, in HTML"},type:{type:"string",enum:["mc-single","mc-multi","matrix-single","matrix-multi","text-single","text-multi","description"],description:"The type of question"},layout:{type:"string",enum:["vertical","horizontal"],description:"Determines the visual layout of the options in multiple choice questions"},display_logic:{type:"string",description:"A boolean expression with logic if this question should be displayed or not"},display_logic_in_page:{type:"string",description:"Similar to display_logic, but enables the question to appear on the same page as the depending question"},required:{type:"string",enum:["required","optional","request"],description:"If the question is required to answer; request means you will get a warning if you skip it but you can."},validation:{type:"object",description:"Validation constraints on the question. Only applied if the user has answered the question, so typically used in combination with required",properties:{min_choices:{type:"integer",description:"The minimum number of choices to user can pick (multiple choice questions only)"},max_choices:{type:"integer",description:"The maximum number of choices to user can pick (multiple choice questions only)"}},additionalProperties:!1},statements:{type:"array",items:{$ref:"#/$defs/statement"}},dynamic_statements:{type:"string",description:"Carry forward statements from a previous question",pattern:"^[a-zA-Z][a-zA-Z0-9_]*/(all|selected|all_entered_text|selected_entered_text|not_selected|displayed|not_displayed|for_matrix_choice\\([\\-a-zA-Z0-9_]+\\)|unselected_for_matrix_choice\\([\\-a-zA-Z0-9_]+\\))$"},statement_groups:{type:"array",items:{type:"object",properties:{statements:{type:"array",items:{$ref:"#/$defs/statement"}},id:{type:"string",description:"The id of the group. Need only be set if referenced to in constrained randomization."},display:{type:"string",description:"The display name of the group"},display_logic:{type:"string",description:"A boolean expression determining if the group should be displayed"},randomization:{$ref:"#/$defs/randomization"}},required:["statements","display"],additionalProperties:!1}},choices:{type:"array",items:{$ref:"#/$defs/choice"}},dynamic_choices:{type:"string",description:"Carry forward choices from a previous question",pattern:"^[a-zA-Z][a-zA-Z0-9_]*/(all|selected|all_entered_text|selected_entered_text|not_selected|displayed|not_displayed|for_matrix_choice\\([\\-a-zA-Z0-9_]+\\)|unselected_for_matrix_choice\\([\\-a-zA-Z0-9_]+\\))$"},choice_groups:{type:"array",items:{type:"object",properties:{choices:{type:"array",items:{$ref:"#/$defs/choice"}},id:{type:"string",description:"The id of the group. Need only be set if referenced to in constrained randomization."},display:{type:"string",description:"The display name of the group"},display_logic:{type:"string",description:"A boolean expression determining if the group should be displayed"},randomization:{$ref:"#/$defs/randomization"}},required:["choices","display"],additionalProperties:!1}},randomization:{$ref:"#/$defs/randomization"}},additionalProperties:!1,allOf:[{oneOf:[{required:["text"]},{required:["text_html"]}]},{oneOf:[{$ref:"#/$defs/question-mc-horizontal"},{$ref:"#/$defs/question-mc-vertical"},{$ref:"#/$defs/question-matrix"},{$ref:"#/$defs/question-text"},{$ref:"#/$defs/question-description"}]}]},"question-mc-horizontal":{type:"object",properties:{type:{enum:["mc-single","mc-multi"]},position:{const:"horizontal"}},required:["id","type","position","choices"],not:{anyOf:[{required:["choice_groups"]},{required:["dynamic_choices"]},{required:["statements"]},{required:["dynamic_statements"]},{required:["statement_groups"]}]}},"question-mc-vertical":{type:"object",properties:{type:{enum:["mc-single","mc-multi"]},position:{const:"vertical"}},required:["id","type"],not:{anyOf:[{required:["statements"]},{required:["dynamic_statements"]},{required:["statement_groups"]}]},oneOf:[{anyOf:[{required:["choices"]},{required:["dynamic_choices"]}],not:{required:["choice_groups"]}},{required:["choice_groups"],not:{anyOf:[{required:["choices"]},{required:["dynamic_choices"]}]}}]},"question-matrix":{type:"object",properties:{type:{enum:["matrix-single","matrix-multi"]}},required:["id","type","choices"],not:{anyOf:[{required:["dynamic_choices"]},{required:["choice_groups"]}]},oneOf:[{anyOf:[{required:["statements"]},{required:["dynamic_statements"]}],not:{required:["statement_groups"]}},{required:["statement_groups"],not:{anyOf:[{required:["statements"]},{required:["dynamic_statements"]}]}}]},"question-text":{type:"object",properties:{type:{enum:["text-single","text-multi"]}},required:["id","type"],not:{anyOf:[{required:["choices"]},{required:["choice_groups"]},{required:["dynamic_choices"]},{required:["statements"]},{required:["statement_groups"]},{required:["dynamic_statements"]},{required:["randomization"]}]}},"question-description":{type:"object",properties:{type:{const:"description"}},not:{anyOf:[{required:["choices"]},{required:["choice_groups"]},{required:["dynamic_choices"]},{required:["statements"]},{required:["statement_groups"]},{required:["dynamic_statements"]},{required:["randomization"]}]}},statement:{type:"object",properties:{id:{type:"string",pattern:"^[a-zA-Z][a-zA-Z0-9_]*$",description:"The id of the statement"},display:{type:"string",description:"The statement name, as shown to the surveyee"},display_logic:{type:"string",description:"A boolean expression determining if the statement should be displayed"}},required:["id","display"],additionalProperties:!1},choice:{type:"object",properties:{display:{type:"string",description:"The choice name, as shown to the surveyee"},id:{type:"string",pattern:"^[a-zA-Z][a-zA-Z0-9_]*$",description:"The id of the choice"},value:{type:"integer",description:"The value the choice"},display_logic:{type:"string",description:"A boolean expression determining if the choice should be displayed"},text:{type:"string",enum:["no","optional","forced"],description:"If a textbox should appear next to the choice, and if it should be mandatory to fill it in if the choice is selected"},exclusive_answer:{type:"boolean",description:"If true, this choice can't be combined with other choices in this question"}},required:["display"],anyOf:[{required:["value"]},{required:["id"]}],additionalProperties:!1},randomization:{type:"object",description:"Configuration of the display order randomization of choices, statements or groups.",properties:{type:{type:"string",description:"The type of randomization: randomize all items, a subset of them, or using constrained randomization",enum:["all","subset","constrained"]},total:{type:"integer",description:"Maximum number of items to show"},order:{type:"string",description:"A space separated string containing the order of the items; each 'word' is either an id of some item or the wildcard $ representing the remaining items"}},required:["type"],oneOf:[{properties:{type:{const:"all"}},not:{required:["total","order"]}},{properties:{type:{const:"subset"}},required:["total"],not:{required:["order"]}},{properties:{type:{const:"constrained"}},required:["order"]}],additionalProperties:!1}},f={$schema:d,title:c,type:u,properties:m,additionalProperties:l,required:y,$defs:h};const i=new o({allowUnionTypes:!0});n(i);const r=i.compile(f),g=e=>{if(!r(e))throw new Error(`Invalid template: ${e.template.id}. Reason: ${r.errors}`)},q="pulse_default_alpha",_={allPermissions:p,SURVEY_RESOURCE_TYPE:a,surveyAdministerPermission:t};export{q as DEFAULT_TEMPLATE_ID,_ as permissions,g as validateTemplate};
2
2
  //# sourceMappingURL=index.esm.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spotify/backstage-plugin-pulse-common",
3
- "version": "0.5.1",
3
+ "version": "0.6.0",
4
4
  "license": "SEE LICENSE IN LICENSE.md",
5
5
  "homepage": "https://backstage.spotify.com/",
6
6
  "main": "dist/index.cjs.js",
@@ -19,20 +19,25 @@
19
19
  "test": "backstage-cli package test",
20
20
  "clean": "backstage-cli package clean",
21
21
  "prepack": "backstage-cli package prepack",
22
- "postpack": "backstage-cli package postpack"
22
+ "postpack": "backstage-cli package postpack",
23
+ "json2ts": "./src/templates/schema/generateSchemaTypes.sh"
23
24
  },
24
25
  "dependencies": {
25
- "@backstage/plugin-permission-common": "^0.7.4",
26
- "js-yaml": "^4.1.0"
26
+ "@backstage/plugin-permission-common": "^0.7.5",
27
+ "ajv": "^8.11.2",
28
+ "ajv-formats": "^2.1.1",
29
+ "graphql": "^16.0.0"
27
30
  },
28
31
  "devDependencies": {
29
- "@backstage/cli": "^0.22.4",
30
- "ajv": "^8.11.2",
31
- "ajv-formats": "^2.1.1"
32
+ "@backstage/cli": "^0.22.6",
33
+ "js-yaml": "^4.1.0",
34
+ "json-schema-to-typescript": "12.0.0",
35
+ "process": "^0.11.10"
32
36
  },
33
37
  "files": [
34
38
  "dist",
35
- "!dist/**/*.map"
39
+ "!dist/**/*.map",
40
+ "src/templates/surveys"
36
41
  ],
37
42
  "module": "dist/index.esm.js"
38
43
  }