@oneblink/sdk 0.4.4-beta.1 → 0.4.4-beta.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.
Files changed (231) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +7 -19
  3. package/package.json +48 -40
  4. package/tenants/civicplus.d.ts +1 -0
  5. package/tenants/civicplus.js +26 -0
  6. package/tenants/civicplus.js.map +1 -0
  7. package/tenants/classes/Approvals.d.ts +95 -0
  8. package/tenants/classes/Approvals.js +95 -0
  9. package/tenants/classes/Approvals.js.map +1 -0
  10. package/tenants/classes/DataManager.d.ts +45 -0
  11. package/tenants/classes/DataManager.js +68 -0
  12. package/tenants/classes/DataManager.js.map +1 -0
  13. package/tenants/classes/EmailTemplates.d.ts +100 -0
  14. package/tenants/classes/EmailTemplates.js +128 -0
  15. package/tenants/classes/EmailTemplates.js.map +1 -0
  16. package/tenants/classes/Forms.d.ts +667 -0
  17. package/tenants/classes/Forms.js +859 -0
  18. package/tenants/classes/Forms.js.map +1 -0
  19. package/tenants/classes/FormsAppEnvironments.d.ts +103 -0
  20. package/tenants/classes/FormsAppEnvironments.js +131 -0
  21. package/tenants/classes/FormsAppEnvironments.js.map +1 -0
  22. package/tenants/classes/FormsApps.d.ts +207 -0
  23. package/tenants/classes/FormsApps.js +296 -0
  24. package/tenants/classes/FormsApps.js.map +1 -0
  25. package/tenants/classes/Jobs.d.ts +102 -0
  26. package/tenants/classes/Jobs.js +180 -0
  27. package/tenants/classes/Jobs.js.map +1 -0
  28. package/tenants/classes/Keys.d.ts +33 -0
  29. package/tenants/classes/Keys.js +46 -0
  30. package/tenants/classes/Keys.js.map +1 -0
  31. package/tenants/classes/Organisations.d.ts +50 -0
  32. package/tenants/classes/Organisations.js +73 -0
  33. package/tenants/classes/Organisations.js.map +1 -0
  34. package/tenants/classes/PDF.d.ts +108 -0
  35. package/tenants/classes/PDF.js +133 -0
  36. package/tenants/classes/PDF.js.map +1 -0
  37. package/tenants/classes/TeamMembers.d.ts +34 -0
  38. package/tenants/classes/TeamMembers.js +55 -0
  39. package/tenants/classes/TeamMembers.js.map +1 -0
  40. package/tenants/classes/index.d.ts +13 -0
  41. package/tenants/classes/index.js +33 -0
  42. package/tenants/classes/index.js.map +1 -0
  43. package/tenants/classes/sendEmail.d.ts +36 -0
  44. package/tenants/classes/sendEmail.js +53 -0
  45. package/tenants/classes/sendEmail.js.map +1 -0
  46. package/tenants/lib/forms-schema/common.d.ts +9 -0
  47. package/tenants/lib/forms-schema/common.js +67 -0
  48. package/tenants/lib/forms-schema/common.js.map +1 -0
  49. package/tenants/lib/forms-schema/element-schema.d.ts +3 -0
  50. package/tenants/lib/forms-schema/element-schema.js +230 -0
  51. package/tenants/lib/forms-schema/element-schema.js.map +1 -0
  52. package/tenants/lib/forms-schema/elements/AbnElement.d.ts +4 -0
  53. package/tenants/lib/forms-schema/elements/AbnElement.js +22 -0
  54. package/tenants/lib/forms-schema/elements/AbnElement.js.map +1 -0
  55. package/tenants/lib/forms-schema/elements/AutocompleteElement.d.ts +4 -0
  56. package/tenants/lib/forms-schema/elements/AutocompleteElement.js +30 -0
  57. package/tenants/lib/forms-schema/elements/AutocompleteElement.js.map +1 -0
  58. package/tenants/lib/forms-schema/elements/BarcodeElement.d.ts +4 -0
  59. package/tenants/lib/forms-schema/elements/BarcodeElement.js +30 -0
  60. package/tenants/lib/forms-schema/elements/BarcodeElement.js.map +1 -0
  61. package/tenants/lib/forms-schema/elements/BooleanElement.d.ts +4 -0
  62. package/tenants/lib/forms-schema/elements/BooleanElement.js +22 -0
  63. package/tenants/lib/forms-schema/elements/BooleanElement.js.map +1 -0
  64. package/tenants/lib/forms-schema/elements/BsbElement.d.ts +4 -0
  65. package/tenants/lib/forms-schema/elements/BsbElement.js +22 -0
  66. package/tenants/lib/forms-schema/elements/BsbElement.js.map +1 -0
  67. package/tenants/lib/forms-schema/elements/CalculationElement.d.ts +4 -0
  68. package/tenants/lib/forms-schema/elements/CalculationElement.js +32 -0
  69. package/tenants/lib/forms-schema/elements/CalculationElement.js.map +1 -0
  70. package/tenants/lib/forms-schema/elements/CameraElement.d.ts +4 -0
  71. package/tenants/lib/forms-schema/elements/CameraElement.js +24 -0
  72. package/tenants/lib/forms-schema/elements/CameraElement.js.map +1 -0
  73. package/tenants/lib/forms-schema/elements/CaptchaElement.d.ts +4 -0
  74. package/tenants/lib/forms-schema/elements/CaptchaElement.js +20 -0
  75. package/tenants/lib/forms-schema/elements/CaptchaElement.js.map +1 -0
  76. package/tenants/lib/forms-schema/elements/CheckboxElement.d.ts +4 -0
  77. package/tenants/lib/forms-schema/elements/CheckboxElement.js +25 -0
  78. package/tenants/lib/forms-schema/elements/CheckboxElement.js.map +1 -0
  79. package/tenants/lib/forms-schema/elements/CivicaNameRecordElement.d.ts +4 -0
  80. package/tenants/lib/forms-schema/elements/CivicaNameRecordElement.js +47 -0
  81. package/tenants/lib/forms-schema/elements/CivicaNameRecordElement.js.map +1 -0
  82. package/tenants/lib/forms-schema/elements/CivicaStreetNameElement.d.ts +4 -0
  83. package/tenants/lib/forms-schema/elements/CivicaStreetNameElement.js +22 -0
  84. package/tenants/lib/forms-schema/elements/CivicaStreetNameElement.js.map +1 -0
  85. package/tenants/lib/forms-schema/elements/ComplianceElement.d.ts +4 -0
  86. package/tenants/lib/forms-schema/elements/ComplianceElement.js +24 -0
  87. package/tenants/lib/forms-schema/elements/ComplianceElement.js.map +1 -0
  88. package/tenants/lib/forms-schema/elements/DateElement.d.ts +5 -0
  89. package/tenants/lib/forms-schema/elements/DateElement.js +70 -0
  90. package/tenants/lib/forms-schema/elements/DateElement.js.map +1 -0
  91. package/tenants/lib/forms-schema/elements/DrawElement.d.ts +4 -0
  92. package/tenants/lib/forms-schema/elements/DrawElement.js +23 -0
  93. package/tenants/lib/forms-schema/elements/DrawElement.js.map +1 -0
  94. package/tenants/lib/forms-schema/elements/EmailElement.d.ts +4 -0
  95. package/tenants/lib/forms-schema/elements/EmailElement.js +24 -0
  96. package/tenants/lib/forms-schema/elements/EmailElement.js.map +1 -0
  97. package/tenants/lib/forms-schema/elements/FilesElement.d.ts +4 -0
  98. package/tenants/lib/forms-schema/elements/FilesElement.js +36 -0
  99. package/tenants/lib/forms-schema/elements/FilesElement.js.map +1 -0
  100. package/tenants/lib/forms-schema/elements/FormElement.d.ts +4 -0
  101. package/tenants/lib/forms-schema/elements/FormElement.js +17 -0
  102. package/tenants/lib/forms-schema/elements/FormElement.js.map +1 -0
  103. package/tenants/lib/forms-schema/elements/FreshdeskDependentFieldElement.d.ts +4 -0
  104. package/tenants/lib/forms-schema/elements/FreshdeskDependentFieldElement.js +31 -0
  105. package/tenants/lib/forms-schema/elements/FreshdeskDependentFieldElement.js.map +1 -0
  106. package/tenants/lib/forms-schema/elements/GeoscapeElement.d.ts +4 -0
  107. package/tenants/lib/forms-schema/elements/GeoscapeElement.js +23 -0
  108. package/tenants/lib/forms-schema/elements/GeoscapeElement.js.map +1 -0
  109. package/tenants/lib/forms-schema/elements/HTMLElement.d.ts +4 -0
  110. package/tenants/lib/forms-schema/elements/HTMLElement.js +22 -0
  111. package/tenants/lib/forms-schema/elements/HTMLElement.js.map +1 -0
  112. package/tenants/lib/forms-schema/elements/HeadingElement.d.ts +4 -0
  113. package/tenants/lib/forms-schema/elements/HeadingElement.js +18 -0
  114. package/tenants/lib/forms-schema/elements/HeadingElement.js.map +1 -0
  115. package/tenants/lib/forms-schema/elements/ImageElement.d.ts +4 -0
  116. package/tenants/lib/forms-schema/elements/ImageElement.js +18 -0
  117. package/tenants/lib/forms-schema/elements/ImageElement.js.map +1 -0
  118. package/tenants/lib/forms-schema/elements/InfoPageElement.d.ts +4 -0
  119. package/tenants/lib/forms-schema/elements/InfoPageElement.js +17 -0
  120. package/tenants/lib/forms-schema/elements/InfoPageElement.js.map +1 -0
  121. package/tenants/lib/forms-schema/elements/LocationElement.d.ts +4 -0
  122. package/tenants/lib/forms-schema/elements/LocationElement.js +21 -0
  123. package/tenants/lib/forms-schema/elements/LocationElement.js.map +1 -0
  124. package/tenants/lib/forms-schema/elements/NumberElement.d.ts +4 -0
  125. package/tenants/lib/forms-schema/elements/NumberElement.js +95 -0
  126. package/tenants/lib/forms-schema/elements/NumberElement.js.map +1 -0
  127. package/tenants/lib/forms-schema/elements/PhoneElement.d.ts +4 -0
  128. package/tenants/lib/forms-schema/elements/PhoneElement.js +24 -0
  129. package/tenants/lib/forms-schema/elements/PhoneElement.js.map +1 -0
  130. package/tenants/lib/forms-schema/elements/PointElement.d.ts +4 -0
  131. package/tenants/lib/forms-schema/elements/PointElement.js +24 -0
  132. package/tenants/lib/forms-schema/elements/PointElement.js.map +1 -0
  133. package/tenants/lib/forms-schema/elements/RadioElement.d.ts +4 -0
  134. package/tenants/lib/forms-schema/elements/RadioElement.js +24 -0
  135. package/tenants/lib/forms-schema/elements/RadioElement.js.map +1 -0
  136. package/tenants/lib/forms-schema/elements/RepeatableSetElement.d.ts +4 -0
  137. package/tenants/lib/forms-schema/elements/RepeatableSetElement.js +44 -0
  138. package/tenants/lib/forms-schema/elements/RepeatableSetElement.js.map +1 -0
  139. package/tenants/lib/forms-schema/elements/SectionElement.d.ts +4 -0
  140. package/tenants/lib/forms-schema/elements/SectionElement.js +34 -0
  141. package/tenants/lib/forms-schema/elements/SectionElement.js.map +1 -0
  142. package/tenants/lib/forms-schema/elements/SelectElement.d.ts +4 -0
  143. package/tenants/lib/forms-schema/elements/SelectElement.js +34 -0
  144. package/tenants/lib/forms-schema/elements/SelectElement.js.map +1 -0
  145. package/tenants/lib/forms-schema/elements/SummaryElement.d.ts +4 -0
  146. package/tenants/lib/forms-schema/elements/SummaryElement.js +22 -0
  147. package/tenants/lib/forms-schema/elements/SummaryElement.js.map +1 -0
  148. package/tenants/lib/forms-schema/elements/TextElement.d.ts +5 -0
  149. package/tenants/lib/forms-schema/elements/TextElement.js +45 -0
  150. package/tenants/lib/forms-schema/elements/TextElement.js.map +1 -0
  151. package/tenants/lib/forms-schema/elements/TimeElement.d.ts +4 -0
  152. package/tenants/lib/forms-schema/elements/TimeElement.js +23 -0
  153. package/tenants/lib/forms-schema/elements/TimeElement.js.map +1 -0
  154. package/tenants/lib/forms-schema/index.d.ts +15 -0
  155. package/tenants/lib/forms-schema/index.js +441 -0
  156. package/tenants/lib/forms-schema/index.js.map +1 -0
  157. package/tenants/lib/forms-schema/property-schemas.d.ts +53 -0
  158. package/tenants/lib/forms-schema/property-schemas.js +239 -0
  159. package/tenants/lib/forms-schema/property-schemas.js.map +1 -0
  160. package/tenants/lib/forms-validation/common.d.ts +5 -0
  161. package/tenants/lib/forms-validation/common.js +50 -0
  162. package/tenants/lib/forms-validation/common.js.map +1 -0
  163. package/tenants/lib/forms-validation/index.d.ts +8 -0
  164. package/tenants/lib/forms-validation/index.js +165 -0
  165. package/tenants/lib/forms-validation/index.js.map +1 -0
  166. package/tenants/lib/forms-validation/validate-form-events.d.ts +16 -0
  167. package/tenants/lib/forms-validation/validate-form-events.js +164 -0
  168. package/tenants/lib/forms-validation/validate-form-events.js.map +1 -0
  169. package/tenants/lib/generate-form-element.d.ts +2 -0
  170. package/tenants/lib/generate-form-element.js +49 -0
  171. package/tenants/lib/generate-form-element.js.map +1 -0
  172. package/tenants/lib/generate-form-url.d.ts +9 -0
  173. package/tenants/lib/generate-form-url.js +32 -0
  174. package/tenants/lib/generate-form-url.js.map +1 -0
  175. package/tenants/lib/generate-jwt.d.ts +1 -0
  176. package/tenants/lib/generate-jwt.js +15 -0
  177. package/tenants/lib/generate-jwt.js.map +1 -0
  178. package/tenants/lib/generate-page-element.d.ts +2 -0
  179. package/tenants/lib/generate-page-element.js +32 -0
  180. package/tenants/lib/generate-page-element.js.map +1 -0
  181. package/tenants/lib/generate-tenant.d.ts +2 -0
  182. package/tenants/lib/generate-tenant.js +13 -0
  183. package/tenants/lib/generate-tenant.js.map +1 -0
  184. package/tenants/lib/one-blink-api.d.ts +37 -0
  185. package/tenants/lib/one-blink-api.js +122 -0
  186. package/tenants/lib/one-blink-api.js.map +1 -0
  187. package/tenants/lib/package.d.ts +2 -0
  188. package/tenants/lib/package.js +6 -0
  189. package/tenants/lib/package.js.map +1 -0
  190. package/tenants/lib/pre-fill-data.d.ts +2 -0
  191. package/tenants/lib/pre-fill-data.js +29 -0
  192. package/tenants/lib/pre-fill-data.js.map +1 -0
  193. package/tenants/lib/retrieve-submission-data.d.ts +2 -0
  194. package/tenants/lib/retrieve-submission-data.js +26 -0
  195. package/tenants/lib/retrieve-submission-data.js.map +1 -0
  196. package/tenants/lib/tenant-configuration.d.ts +3 -0
  197. package/tenants/lib/tenant-configuration.js +22 -0
  198. package/tenants/lib/tenant-configuration.js.map +1 -0
  199. package/tenants/lib/upload-asset.d.ts +4 -0
  200. package/tenants/lib/upload-asset.js +30 -0
  201. package/tenants/lib/upload-asset.js.map +1 -0
  202. package/tenants/lib/user-token-helpers.d.ts +9 -0
  203. package/tenants/lib/user-token-helpers.js +34 -0
  204. package/tenants/lib/user-token-helpers.js.map +1 -0
  205. package/tenants/oneblink.d.ts +1 -0
  206. package/tenants/oneblink.js +26 -0
  207. package/tenants/oneblink.js.map +1 -0
  208. package/tenants/types.d.ts +304 -0
  209. package/tenants/types.js +18 -0
  210. package/tenants/types.js.map +1 -0
  211. package/changelog.md +0 -201
  212. package/classes/Forms.js +0 -244
  213. package/classes/FormsApps.js +0 -98
  214. package/classes/Jobs.js +0 -133
  215. package/classes/Keys.js +0 -23
  216. package/classes/Organisations.js +0 -25
  217. package/classes/TeamMembers.js +0 -34
  218. package/flow-typed/npm/axios_v0.18.x.js +0 -165
  219. package/flow-typed/npm/jest_v24.x.x.js +0 -1186
  220. package/flow-typed/types.js +0 -301
  221. package/index.js +0 -18
  222. package/lib/forms-schema.js +0 -859
  223. package/lib/forms-validation.js +0 -33
  224. package/lib/generate-form-element.js +0 -75
  225. package/lib/generate-form-url.js +0 -29
  226. package/lib/generate-jwt.js +0 -18
  227. package/lib/one-blink-api-error-handler.js +0 -31
  228. package/lib/one-blink-api.js +0 -107
  229. package/lib/pre-fill-data.js +0 -33
  230. package/lib/retrieve-submission-data.js +0 -29
  231. package/lib/tenant.js +0 -23
@@ -1,859 +0,0 @@
1
- // @flow
2
- 'use strict'
3
-
4
- const Joi = require('joi')
5
-
6
- const base64DataRegex = /<[^>]*src="data:([a-zA-Z]*)\/([a-zA-Z]*);base64,([^"]*)".*>/m
7
-
8
- const elementTypes = [
9
- 'camera',
10
- 'checkboxes',
11
- 'date',
12
- 'datetime',
13
- 'heading',
14
- 'location',
15
- 'number',
16
- 'radio',
17
- 'select',
18
- 'draw',
19
- 'text',
20
- 'textarea',
21
- 'time',
22
- 'repeatableSet',
23
- 'barcodeScanner',
24
- 'html',
25
- 'captcha',
26
- 'email',
27
- 'image',
28
- 'file',
29
- 'calculation',
30
- 'telephone',
31
- 'autocomplete',
32
- 'form',
33
- 'infoPage',
34
- 'files'
35
- ]
36
-
37
- const CUSTOM_OPTION_TYPE = 'CUSTOM'
38
- const DYNAMIC_OPTION_TYPE = 'DYNAMIC'
39
- const SEARCH_OPTION_TYPE = 'SEARCH'
40
-
41
- const optionTypes = [CUSTOM_OPTION_TYPE, DYNAMIC_OPTION_TYPE]
42
-
43
- const userInputTypes = [
44
- 'checkboxes',
45
- 'date',
46
- 'datetime',
47
- 'location',
48
- 'number',
49
- 'radio',
50
- 'select',
51
- 'text',
52
- 'textarea',
53
- 'time',
54
- 'barcodeScanner',
55
- 'email',
56
- 'telephone',
57
- 'autocomplete'
58
- ]
59
-
60
- const ConditionallyShowPredicatesSchema = Joi.when('conditionallyShow', {
61
- is: true,
62
- then: Joi.array()
63
- .label('Form Element - Conditionally Show Predicates')
64
- .unique('elementId')
65
- .min(1)
66
- .items(
67
- Joi.object().keys({
68
- elementId: Joi.string()
69
- .guid()
70
- .required()
71
- .label('Form Element - Conditionally Show Predicate - Element Id'),
72
- type: Joi.string()
73
- .default('OPTIONS')
74
- .label('Form Element - Conditionally Show Predicate - Type')
75
- .valid(['OPTIONS', 'NUMERIC']),
76
- optionIds: Joi.label(
77
- 'Form Element - Conditionally Show Predicate - Option Ids'
78
- ).when('type', {
79
- is: Joi.only('OPTIONS'),
80
- then: Joi.array()
81
- .min(1)
82
- .items(Joi.string())
83
- .required(),
84
- else: Joi.allow(null)
85
- }),
86
- operator: Joi.label(
87
- 'Form Element - Conditionally Show Predicate - Operator'
88
- ).when('type', {
89
- is: Joi.only('NUMERIC'),
90
- then: Joi.string()
91
- .valid(['>', '>=', '===', '!==', '<=', '<'])
92
- .required(),
93
- else: Joi.allow(null)
94
- }),
95
- value: Joi.label(
96
- 'Form Element - Conditionally Show Predicate - Value'
97
- ).when('type', {
98
- is: Joi.only('NUMERIC'),
99
- then: Joi.number().required(),
100
- else: Joi.allow(null)
101
- })
102
- })
103
- )
104
- .required(),
105
- otherwise: Joi.any().strip()
106
- })
107
-
108
- const JoiRange = Joi.extend(joi => ({
109
- base: joi.number(),
110
- name: 'range',
111
- language: {
112
- within: 'Must not exceed range of values {{min}} and {{max}}: ({{v}})'
113
- },
114
- rules: [
115
- {
116
- name: 'within',
117
- params: {
118
- options: joi.object({
119
- min: joi.func().ref(),
120
- max: joi.func().ref()
121
- })
122
- },
123
- validate(params, value, state, options) {
124
- const max = params.options.max.key
125
- const min = params.options.min.key
126
- const parent = state.parent
127
- const range = parent[max] - parent[min]
128
- if (value > range) {
129
- return this.createError(
130
- 'range.within',
131
- { v: value, min: parent[min], max: parent[max] },
132
- state,
133
- options
134
- )
135
- }
136
- return value
137
- }
138
- }
139
- ]
140
- }))
141
-
142
- const BaseSchema = Joi.object().keys({
143
- // Generic
144
- id: Joi.string()
145
- .guid()
146
- .required()
147
- .label('Form Element - Id'),
148
- type: Joi.string()
149
- .required()
150
- .label('Form Element - Type')
151
- .valid(elementTypes),
152
- name: Joi.string()
153
- .label('Form Element - Name')
154
- .required(),
155
- label: Joi.when('type', {
156
- is: Joi.only(['form', 'infoPage']),
157
- then: Joi.any().strip(),
158
- otherwise: Joi.string()
159
- .label('Form Element - Label')
160
- .required()
161
- }),
162
- required: Joi.when('type', {
163
- is: Joi.only(['form', 'infoPage', 'files']),
164
- then: Joi.any().strip(),
165
- otherwise: Joi.bool()
166
- .default(false)
167
- .label('Form Element - Required')
168
- }),
169
- readOnly: Joi.when('type', {
170
- is: Joi.only(['form', 'infoPage']),
171
- then: Joi.any().strip(),
172
- otherwise: Joi.bool()
173
- .default(false)
174
- .label('Form Element - Read Only')
175
- }),
176
- conditionallyShow: Joi.bool()
177
- .default(false)
178
- .label('Form Element - Conditionally Show'),
179
- requiresAllConditionallyShowPredicates: Joi.when('conditionallyShow', {
180
- is: true,
181
- then: Joi.bool()
182
- .default(false)
183
- .label(
184
- 'Form Element - Requires All Conditionally Show Predicates are Met'
185
- ),
186
- otherwise: Joi.any().strip()
187
- }),
188
- conditionallyShowPredicates: ConditionallyShowPredicatesSchema,
189
- defaultValue: Joi.allow(null)
190
- .label('Form Element - Default Value')
191
- .when('type', {
192
- is: Joi.only(['text', 'textarea', 'barcodeScanner', 'telephone']),
193
- then: Joi.string()
194
- })
195
- .when('type', {
196
- is: Joi.only(['html', 'calculation']),
197
- then: Joi.string()
198
- .required()
199
- .regex(base64DataRegex, {
200
- name: 'No Binary Data',
201
- invert: true
202
- })
203
- })
204
- .when('type', {
205
- is: 'image',
206
- then: Joi.string()
207
- .required()
208
- .uri()
209
- })
210
- .when('type', {
211
- is: 'number',
212
- then: Joi.number()
213
- .label('Form Element - Default Value')
214
- .when('minNumber', {
215
- is: Joi.number().required(),
216
- then: Joi.number().min(Joi.ref('minNumber'))
217
- })
218
- .when('maxNumber', {
219
- is: Joi.number().required(),
220
- then: Joi.number().max(Joi.ref('maxNumber'))
221
- })
222
- })
223
- .when('type', {
224
- is: Joi.only(['date', 'datetime', 'time']),
225
- then: Joi.date()
226
- .iso()
227
- .label('Form Element - Default Date Value')
228
- .when('fromDate', {
229
- is: Joi.date()
230
- .iso()
231
- .required(),
232
- then: Joi.date()
233
- .iso()
234
- .min(Joi.ref('fromDate'))
235
- })
236
- .when('toDate', {
237
- is: Joi.date()
238
- .iso()
239
- .required(),
240
- then: Joi.date()
241
- .iso()
242
- .max(Joi.ref('toDate'))
243
- })
244
- })
245
- .when('type', {
246
- is: 'radio',
247
- then: Joi.when('optionsType', {
248
- is: Joi.invalid(DYNAMIC_OPTION_TYPE),
249
- then: Joi.string()
250
- .guid()
251
- .label('Form Element - Default Value'),
252
- otherwise: Joi.string().label('Form Element - Default Value')
253
- })
254
- })
255
- .when('type', {
256
- is: 'checkboxes',
257
- then: Joi.when('optionsType', {
258
- is: Joi.invalid(DYNAMIC_OPTION_TYPE),
259
- then: Joi.array()
260
- .items(Joi.string().guid())
261
- .label('Form Element - Default Value'),
262
- otherwise: Joi.array()
263
- .items(Joi.string())
264
- .label('Form Element - Default Value')
265
- })
266
- })
267
- .when('type', {
268
- is: 'autocompelete',
269
- then: Joi.when('optionsType', {
270
- is: Joi.invalid(DYNAMIC_OPTION_TYPE),
271
- then: Joi.string()
272
- .guid()
273
- .label('Form Element - Default Value'),
274
- otherwise: Joi.string().label('Form Element - Default Value')
275
- })
276
- })
277
- .when('type', {
278
- is: 'select',
279
- then: Joi.when('multi', {
280
- is: true,
281
- then: Joi.when('optionsType', {
282
- is: Joi.invalid(DYNAMIC_OPTION_TYPE),
283
- then: Joi.array()
284
- .items(Joi.string().guid())
285
- .label('Form Element - Default Value'),
286
- otherwise: Joi.array()
287
- .items(Joi.string())
288
- .label('Form Element - Default Value')
289
- }),
290
- otherwise: Joi.when('optionsType', {
291
- is: Joi.invalid(DYNAMIC_OPTION_TYPE),
292
- then: Joi.string()
293
- .guid()
294
- .label('Form Element - Default Value'),
295
- otherwise: Joi.string().label('Form Element - Default Value')
296
- })
297
- })
298
- })
299
- .when('type', {
300
- is: 'email',
301
- then: Joi.string()
302
- .email()
303
- .label('Form Element - Default Email Value')
304
- }),
305
- // Radio buttons
306
- buttons: Joi.when('type', {
307
- is: Joi.only(['radio', 'checkboxes']),
308
- then: Joi.boolean()
309
- .label('Form Element - Radio Buttons as Buttons')
310
- .default(false),
311
- otherwise: Joi.any().strip()
312
- }),
313
- // Select
314
- multi: Joi.when('type', {
315
- is: 'select',
316
- then: Joi.boolean()
317
- .label('Form Element - Multi Select')
318
- .default(false),
319
- otherwise: Joi.any().strip()
320
- }),
321
-
322
- // Number
323
- isSlider: Joi.when('type', {
324
- is: 'number',
325
- then: Joi.boolean()
326
- .label('Form Element - Display Number as Slider')
327
- .default(false),
328
- otherwise: Joi.any().strip()
329
- }),
330
- sliderIncrement: Joi.when('isSlider', {
331
- is: true,
332
- then: JoiRange.range()
333
- .within({ min: Joi.ref('minNumber'), max: Joi.ref('maxNumber') })
334
- .label('Form Element - Slider Increment'),
335
- else: Joi.any().strip()
336
- }),
337
- minNumber: Joi.number()
338
- .allow(null)
339
- .label('Form Element - Minimum Number')
340
- .when('type', {
341
- is: Joi.not('number'),
342
- then: Joi.any().strip()
343
- })
344
- .when('isSlider', {
345
- is: true,
346
- then: Joi.required()
347
- }),
348
- maxNumber: Joi.number()
349
- .label('Form Element - Maximum Number')
350
- .when('type', {
351
- is: Joi.not('number'),
352
- then: Joi.any().strip()
353
- })
354
- .when('minNumber', {
355
- is: Joi.number().required(),
356
- then: Joi.number().min(Joi.ref('minNumber'))
357
- })
358
- .when('isSlider', {
359
- is: true,
360
- then: Joi.required()
361
- }),
362
-
363
- // Heading
364
- headingType: Joi.when('type', {
365
- is: Joi.only('heading'),
366
- then: Joi.number()
367
- .required()
368
- .label('Form Element - Heading Size')
369
- .valid([1, 2, 3, 4, 5]),
370
- otherwise: Joi.any().strip()
371
- }),
372
-
373
- // Date and Date+Time
374
- fromDate: Joi.when('type', {
375
- is: Joi.only(['date', 'datetime']),
376
- then: Joi.date()
377
- .iso()
378
- .label('Form Element - From Date')
379
- .allow(null),
380
- otherwise: Joi.any().strip()
381
- }),
382
- toDate: Joi.when('type', {
383
- is: Joi.only(['date', 'datetime']),
384
- then: Joi.when('fromDate', {
385
- is: Joi.date()
386
- .iso()
387
- .required()
388
- .label('Form Element - To Date'),
389
- then: Joi.date()
390
- .iso()
391
- .min(Joi.ref('fromDate'))
392
- .label('Form Element - To Date')
393
- }).allow(null),
394
- otherwise: Joi.any().strip()
395
- }),
396
- // Checkboxes, selects, radio and autocomplete
397
- optionsType: Joi.when('type', {
398
- is: Joi.only(['checkboxes', 'radio', 'select', 'autocomplete']),
399
- then: Joi.string()
400
- .label('Form Element - Options type')
401
- .default(CUSTOM_OPTION_TYPE)
402
- .when('type', {
403
- is: 'autocomplete',
404
- then: Joi.valid([...optionTypes, SEARCH_OPTION_TYPE]),
405
- otherwise: Joi.valid(optionTypes)
406
- }),
407
- otherwise: Joi.any().strip()
408
- }),
409
- dynamicOptionSetId: Joi.when('optionsType', {
410
- is: DYNAMIC_OPTION_TYPE,
411
- then: Joi.number()
412
- .label('Form Element - Dynamic Option Set Id')
413
- .required(),
414
- otherwise: Joi.any().strip()
415
- }),
416
- options: Joi.when('optionsType', {
417
- is: CUSTOM_OPTION_TYPE,
418
- then: Joi.array()
419
- .label('Form Element - Options')
420
- .unique('id')
421
- .items(
422
- Joi.object().keys({
423
- id: Joi.string()
424
- .guid()
425
- .required()
426
- .label('Form Element - Option Id'),
427
- value: Joi.string()
428
- .required()
429
- .label('Form Element - Option Value'),
430
- label: Joi.string()
431
- .required()
432
- .label('Form Element - Option Label'),
433
- colour: Joi.string()
434
- .allow([null, ''])
435
- .regex(/^#[A-Fa-f0-9]{3}([A-Fa-f0-9]{3})?$/)
436
- .label('Form Element - Option Colour'),
437
- attributes: Joi.array().items(
438
- Joi.object().keys({
439
- optionIds: Joi.array()
440
- .required()
441
- .items(Joi.string())
442
- .label('Form Element - Attributes Mapping - Element Id'),
443
- elementId: Joi.string()
444
- .guid()
445
- .required()
446
- .label('Form Element - Option Value - Attribute Option Id')
447
- })
448
- )
449
- })
450
- )
451
- .required(),
452
- otherwise: Joi.any().strip()
453
- }),
454
- attributesMapping: Joi.when('optionsType', {
455
- is: DYNAMIC_OPTION_TYPE,
456
- then: Joi.array().items(
457
- Joi.object().keys({
458
- elementId: Joi.string()
459
- .guid()
460
- .required()
461
- .label('Form Element - Option Value - Attribute Element Id'),
462
- attribute: Joi.string()
463
- .required()
464
- .label('Form Element - Attributes Mapping - Attribute')
465
- })
466
- ),
467
- otherwise: Joi.any().strip()
468
- }),
469
- conditionallyShowOptions: Joi.when('type', {
470
- is: Joi.only(['checkboxes', 'radio', 'select', 'autocomplete']),
471
- then: Joi.boolean()
472
- .label('Form Element - conditionallyShowOptionsElementIds')
473
- .default(false),
474
- otherwise: Joi.any().strip()
475
- }),
476
- conditionallyShowOptionsElementIds: Joi.when('optionsType', {
477
- is: CUSTOM_OPTION_TYPE,
478
- then: Joi.array().items(
479
- Joi.string()
480
- .guid()
481
- .required()
482
- .label('Form Element - Attributes Mapping - Element Id')
483
- ),
484
- otherwise: Joi.any().strip()
485
- }),
486
-
487
- // repeatableSet
488
- minSetEntries: Joi.when('type', {
489
- is: Joi.only('repeatableSet'),
490
- then: Joi.number()
491
- .min(0)
492
- .label('Form Element - Minimum number of repeatable set entries'),
493
- otherwise: Joi.any().strip()
494
- }),
495
- maxSetEntries: Joi.when('type', {
496
- is: Joi.only('repeatableSet'),
497
- then: Joi.number()
498
- .label('Form Element - Maximum number of repeatable set entries')
499
- .when('minSetEntries', {
500
- is: Joi.number()
501
- .required()
502
- .min(0),
503
- then: Joi.number().min(Joi.ref('minSetEntries')),
504
- otherwise: Joi.number().min(0)
505
- }),
506
- otherwise: Joi.any().strip()
507
- }),
508
- addSetEntryLabel: Joi.string().when('type', {
509
- is: Joi.only('repeatableSet'),
510
- then: Joi.string().label('Form Element - Add repeatable set entry label'),
511
- otherwise: Joi.any().strip()
512
- }),
513
- removeSetEntryLabel: Joi.when('type', {
514
- is: Joi.only('repeatableSet'),
515
- then: Joi.string().label(
516
- 'Form Element - Remove repeatable set entry label'
517
- ),
518
- otherwise: Joi.any().strip()
519
- }),
520
- elements: Joi.when('type', {
521
- is: Joi.only('repeatableSet'),
522
- then: Joi.array()
523
- .items(Joi.lazy(() => BaseSchema))
524
- .required()
525
- .min(1)
526
- .unique('name', { ignoreUndefined: true })
527
- .unique('id')
528
- .label('Form Element - Repeatable Set - Elements'),
529
- otherwise: Joi.any().strip()
530
- }),
531
-
532
- // Barcode Scanner
533
- restrictBarcodeTypes: Joi.when('type', {
534
- is: Joi.only('barcodeScanner'),
535
- then: Joi.boolean()
536
- .default(false)
537
- .label('Form Element - Barcode Scanner - restrictBarcodeTypes'),
538
- otherwise: Joi.any().strip()
539
- }),
540
- restrictedBarcodeTypes: Joi.when('type', {
541
- is: Joi.only('barcodeScanner'),
542
- then: Joi.when('restrictBarcodeTypes', {
543
- is: true,
544
- then: Joi.array()
545
- .items(Joi.string())
546
- .label('Form Element - Barcode Scanner - restrictedBarcodeTypes')
547
- .required(),
548
- otherwise: Joi.any().strip()
549
- }),
550
- otherwise: Joi.any().strip()
551
- }),
552
-
553
- // calculation
554
- calculation: Joi.when('type', {
555
- is: Joi.only('calculation'),
556
- then: Joi.string()
557
- .label('Form Element - Calculation - calculation')
558
- .required(),
559
- otherwise: Joi.any().strip()
560
- }),
561
- preCalculationDisplay: Joi.when('type', {
562
- is: Joi.only('calculation'),
563
- then: Joi.string()
564
- .label('Form Element - Pre Calculation Display')
565
- .allow(null)
566
- .regex(base64DataRegex, {
567
- name: 'No Binary Data',
568
- invert: true
569
- }),
570
- otherwise: Joi.any().strip()
571
- }),
572
-
573
- // Data lookup configuration
574
- isDataLookup: Joi.when('type', {
575
- is: Joi.only(userInputTypes),
576
- then: Joi.boolean()
577
- .default(false)
578
- .label('Data Lookup enabled'),
579
- otherwise: Joi.any().strip()
580
- }),
581
- dataLookupId: Joi.when('type', {
582
- is: Joi.only(userInputTypes),
583
- then: Joi.when('isDataLookup', {
584
- is: true,
585
- then: Joi.number()
586
- .required()
587
- .label('Data Lookup Id'),
588
- otherwise: Joi.any().strip()
589
- }),
590
- otherwise: Joi.any().strip()
591
- }),
592
-
593
- // Element lookup configuration
594
- isElementLookup: Joi.when('type', {
595
- is: Joi.only(userInputTypes),
596
- then: Joi.boolean()
597
- .default(false)
598
- .label('Element Lookup enabled'),
599
- otherwise: Joi.any().strip()
600
- }),
601
- elementLookupId: Joi.when('type', {
602
- is: Joi.only(userInputTypes),
603
- then: Joi.when('isElementLookup', {
604
- is: true,
605
- then: Joi.number()
606
- .required()
607
- .label('Element Lookup Id'),
608
- otherwise: Joi.any().strip()
609
- }),
610
- otherwise: Joi.any().strip()
611
- }),
612
-
613
- // form and infoPage
614
- formId: Joi.when('type', {
615
- is: ['form', 'infoPage'],
616
- then: Joi.number()
617
- .label('Form Id')
618
- .required(),
619
- otherwise: Joi.any().strip()
620
- }),
621
-
622
- // autocomplete with SEARCH option type
623
- searchUrl: Joi.when('type', {
624
- is: 'autocomplete',
625
- then: Joi.when('optionsType', {
626
- is: SEARCH_OPTION_TYPE,
627
- then: Joi.string()
628
- .required()
629
- .label('Search URL'),
630
- otherwise: Joi.any().strip()
631
- }),
632
- otherwise: Joi.any().strip()
633
- }),
634
-
635
- // file and files
636
- restrictFileTypes: Joi.when('type', {
637
- is: Joi.only(['file', 'files']),
638
- then: Joi.boolean()
639
- .label('Restrict File Types')
640
- .default(false),
641
- otherwise: Joi.any().strip()
642
- }),
643
- restrictedFileTypes: Joi.when('type', {
644
- is: Joi.only(['file', 'files']),
645
- then: Joi.when('restrictFileTypes', {
646
- is: Joi.only(true),
647
- then: Joi.array()
648
- .items(Joi.string().label('restricted file type'))
649
- .required()
650
- .label('Restricted File Types'),
651
- otherwise: Joi.any().strip()
652
- }),
653
- otherwise: Joi.any().strip()
654
- }),
655
- minEntries: Joi.when('type', {
656
- is: Joi.only('files'),
657
- then: Joi.number()
658
- .min(0)
659
- .label('Form Element - Minimum number of files'),
660
- otherwise: Joi.any().strip()
661
- }),
662
- maxEntries: Joi.when('type', {
663
- is: Joi.only('files'),
664
- then: Joi.number()
665
- .label('Form Element - Maximum number of files')
666
- .when('minEntries', {
667
- is: Joi.number()
668
- .required()
669
- .min(0),
670
- then: Joi.number().min(Joi.ref('minEntries')),
671
- otherwise: Joi.number().min(0)
672
- }),
673
- otherwise: Joi.any().strip()
674
- })
675
- })
676
-
677
- const SubmissionEventsSchema = Joi.object().keys({
678
- isDraft: Joi.boolean().default(false),
679
- type: Joi.string()
680
- .required()
681
- .label('Form Submission Event - Type')
682
- .valid(['CALLBACK', 'PDF', 'SPOTTO', 'ONEBLINK_API', 'TRIM']),
683
- configuration: Joi.allow(null)
684
- .label('Form Submission Event - Configuration')
685
- .when('type', {
686
- is: 'CALLBACK',
687
- then: Joi.object().keys({
688
- url: Joi.string()
689
- .uri()
690
- .required()
691
- .label('Form Submission Event - Callback Url'),
692
- secret: Joi.string()
693
- .required()
694
- .label('Form Submission Event - Callback Secret')
695
- })
696
- })
697
- .when('type', {
698
- is: 'PDF',
699
- then: Joi.object().keys({
700
- email: Joi.alternatives([
701
- Joi.string()
702
- .email()
703
- .required()
704
- .label('Form Submission Event - Email Address'),
705
- Joi.string()
706
- .regex(/^{ELEMENT:\S+}$/)
707
- .required()
708
- .label('Form Submission Event - Email Address')
709
- ]),
710
- pdfFileName: Joi.string()
711
- .allow([null, ''])
712
- .label('Form Submission Event - PDF File Name'),
713
- emailSubjectLine: Joi.string()
714
- .allow([null, ''])
715
- .label('Form Submission Event - Email Subject Line')
716
- })
717
- })
718
- .when('type', {
719
- is: 'ONEBLINK_API',
720
- then: Joi.object().keys({
721
- apiId: Joi.string()
722
- .required()
723
- .label('Form Submission Event - API Instance'),
724
- apiEnvironment: Joi.string()
725
- .required()
726
- .label('Form Submission Event - API Environment'),
727
- apiEnvironmentRoute: Joi.string()
728
- .required()
729
- .label('Form Submission Event - API Environment Route'),
730
- secret: Joi.string()
731
- .required()
732
- .label('Form Submission Event - Callback Secret')
733
- })
734
- })
735
- .when('type', {
736
- is: 'TRIM',
737
- then: Joi.object().keys({
738
- url: Joi.string()
739
- .required()
740
- .uri(),
741
- recordTitle: Joi.string().allow([null, '']),
742
- container: Joi.object().keys({
743
- uri: Joi.number().required(),
744
- label: Joi.string().required()
745
- }),
746
- username: Joi.string().required(),
747
- password: Joi.string().required(),
748
- recordType: Joi.object().keys({
749
- uri: Joi.number().required(),
750
- label: Joi.string().required()
751
- }),
752
- actionDefinition: Joi.object().keys({
753
- uri: Joi.number().required(),
754
- label: Joi.string().required()
755
- }),
756
- location: Joi.object().keys({
757
- uri: Joi.number().required(),
758
- label: Joi.string().required()
759
- })
760
- })
761
- })
762
- })
763
-
764
- module.exports = {
765
- formSchema: Joi.object().keys({
766
- id: Joi.number(),
767
- formsAppEnvironmentId: Joi.number()
768
- .label('Environment')
769
- .required(),
770
- name: Joi.string()
771
- .label('Name')
772
- .required(),
773
- description: Joi.string()
774
- .label('Description')
775
- .allow('')
776
- .allow(null),
777
- organisationId: Joi.string()
778
- .label('Organisation')
779
- .required(),
780
- elements: Joi.array()
781
- .label('Form Elements')
782
- .when('isMultiPage', {
783
- is: false,
784
- then: Joi.array()
785
- .required()
786
- .items(BaseSchema)
787
- .unique('name', { ignoreUndefined: true })
788
- .unique('id'),
789
- otherwise: Joi.array().items(
790
- Joi.object().keys({
791
- id: Joi.string()
792
- .guid()
793
- .required()
794
- .label('Form Element - Id'),
795
- label: Joi.string()
796
- .required()
797
- .label('Form Element - Label'),
798
- type: Joi.only('page'),
799
- conditionallyShow: Joi.bool()
800
- .default(false)
801
- .label('Form Element - Conditionally Show'),
802
- conditionallyShowPredicates: ConditionallyShowPredicatesSchema,
803
- requiresAllConditionallyShowPredicates: Joi.bool()
804
- .default(false)
805
- .label(
806
- 'Form Element - Requires All Conditionally Show Predicates are Met'
807
- ),
808
- elements: Joi.array()
809
- .label('Form Element - Page - Elements')
810
- .required()
811
- .items(BaseSchema)
812
- .min(1)
813
- .unique('name', { ignoreUndefined: true })
814
- .unique('id')
815
- })
816
- )
817
- }),
818
- isMultiPage: Joi.bool()
819
- .default(false)
820
- .label('Form Is Multi Page'),
821
- isAuthenticated: Joi.bool()
822
- .default(false)
823
- .label('Form Authentication'),
824
- isPublished: Joi.bool()
825
- .default(false)
826
- .label('Form Publication'),
827
- submissionEvents: Joi.array()
828
- .allow(null)
829
- .label('Submission Events')
830
- .items(SubmissionEventsSchema),
831
- postSubmissionAction: Joi.string()
832
- .label('Post Submission Action')
833
- .required()
834
- .valid(['URL', 'CLOSE', 'FORMS_LIBRARY']),
835
- redirectUrl: Joi.when('postSubmissionAction', {
836
- is: 'URL',
837
- then: Joi.string()
838
- .required()
839
- .label('Post Submission Redirect URL'),
840
- otherwise: Joi.any().strip()
841
- }),
842
- isInfoPage: Joi.bool()
843
- .default(false)
844
- .label('Form Information Page'),
845
- formsAppIds: Joi.array()
846
- .items(Joi.number())
847
- .required()
848
- .label('Associated Forms Apps'),
849
- createdAt: Joi.string()
850
- .label('Date Created')
851
- .allow('')
852
- .allow(null),
853
- updatedAt: Joi.string()
854
- .label('Date Updated')
855
- .allow('')
856
- .allow(null)
857
- }),
858
- elementSchema: BaseSchema
859
- }