@beabee/beabee-common 1.19.7 → 1.19.9

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 (220) hide show
  1. package/dist/cjs/data/callouts.js +2 -0
  2. package/dist/cjs/data/index.js +67 -0
  3. package/dist/cjs/error/InvalidRule.js +11 -0
  4. package/dist/cjs/error/index.js +8 -0
  5. package/dist/cjs/index.js +23 -0
  6. package/dist/cjs/search/api-keys.js +11 -0
  7. package/dist/cjs/search/callouts.js +101 -0
  8. package/dist/cjs/search/contacts.js +78 -0
  9. package/dist/cjs/search/index.js +81 -0
  10. package/dist/cjs/search/notices.js +37 -0
  11. package/dist/cjs/search/payments.js +27 -0
  12. package/dist/cjs/utils/callouts.js +118 -0
  13. package/dist/cjs/utils/date.js +77 -0
  14. package/dist/cjs/utils/payments.js +31 -0
  15. package/dist/cjs/utils/rules.js +69 -0
  16. package/dist/esm/data/callouts.js +1 -0
  17. package/dist/esm/data/index.js +50 -57
  18. package/dist/esm/error/InvalidRule.js +7 -10
  19. package/dist/esm/error/index.js +2 -1
  20. package/dist/esm/index.js +7 -4
  21. package/dist/esm/search/api-keys.js +7 -10
  22. package/dist/esm/search/callouts.js +94 -100
  23. package/dist/esm/search/contacts.js +74 -83
  24. package/dist/esm/search/index.js +64 -6
  25. package/dist/esm/search/notices.js +33 -36
  26. package/dist/esm/search/payments.js +23 -26
  27. package/dist/esm/utils/callouts.js +93 -91
  28. package/dist/esm/utils/date.js +56 -56
  29. package/dist/esm/utils/payments.js +23 -25
  30. package/dist/esm/utils/rules.js +58 -75
  31. package/dist/types/data/callouts.d.ts +74 -0
  32. package/dist/types/data/index.d.ts +4 -0
  33. package/dist/types/error/InvalidRule.d.ts +2 -2
  34. package/dist/types/error/index.d.ts +2 -1
  35. package/dist/types/index.d.ts +7 -5
  36. package/dist/types/search/api-keys.d.ts +1 -0
  37. package/dist/types/search/callouts.d.ts +5 -1
  38. package/dist/types/search/contacts.d.ts +1 -2
  39. package/dist/types/search/index.d.ts +194 -6
  40. package/dist/types/search/notices.d.ts +2 -1
  41. package/dist/types/search/payments.d.ts +2 -1
  42. package/dist/types/utils/callouts.d.ts +3 -1
  43. package/dist/types/utils/date.d.ts +3 -3
  44. package/dist/types/utils/payments.d.ts +7 -1
  45. package/dist/types/utils/rules.d.ts +1 -1
  46. package/package.json +12 -31
  47. package/README.md +0 -41
  48. package/dist/cjs/data/index.cjs +0 -87
  49. package/dist/cjs/error/InvalidRule.cjs +0 -35
  50. package/dist/cjs/error/index.cjs +0 -22
  51. package/dist/cjs/index.cjs +0 -28
  52. package/dist/cjs/search/api-keys.cjs +0 -35
  53. package/dist/cjs/search/callouts.cjs +0 -131
  54. package/dist/cjs/search/contacts.cjs +0 -105
  55. package/dist/cjs/search/index.cjs +0 -32
  56. package/dist/cjs/search/notices.cjs +0 -61
  57. package/dist/cjs/search/operators.cjs +0 -89
  58. package/dist/cjs/search/payments.cjs +0 -51
  59. package/dist/cjs/types/api-key-filter-name.cjs +0 -16
  60. package/dist/cjs/types/array-filter-args.cjs +0 -16
  61. package/dist/cjs/types/base-callout-component-schema.cjs +0 -16
  62. package/dist/cjs/types/base-filter-args.cjs +0 -16
  63. package/dist/cjs/types/base-validated-rule.cjs +0 -16
  64. package/dist/cjs/types/callout-component-schema.cjs +0 -16
  65. package/dist/cjs/types/callout-filter-name.cjs +0 -16
  66. package/dist/cjs/types/callout-form-schema.cjs +0 -16
  67. package/dist/cjs/types/callout-navigation-schema.cjs +0 -16
  68. package/dist/cjs/types/callout-response-answer-address.cjs +0 -16
  69. package/dist/cjs/types/callout-response-answer-file-upload.cjs +0 -16
  70. package/dist/cjs/types/callout-response-answer.cjs +0 -16
  71. package/dist/cjs/types/callout-response-answers.cjs +0 -16
  72. package/dist/cjs/types/callout-response-comment-filter-name.cjs +0 -16
  73. package/dist/cjs/types/callout-response-filter-name.cjs +0 -16
  74. package/dist/cjs/types/callout-slide-schema.cjs +0 -16
  75. package/dist/cjs/types/callout-tag-filter-name.cjs +0 -16
  76. package/dist/cjs/types/content-callout-component-schema.cjs +0 -16
  77. package/dist/cjs/types/date-unit.cjs +0 -16
  78. package/dist/cjs/types/duration.cjs +0 -16
  79. package/dist/cjs/types/enum-filter-args.cjs +0 -16
  80. package/dist/cjs/types/feeable.cjs +0 -16
  81. package/dist/cjs/types/filter-args.cjs +0 -16
  82. package/dist/cjs/types/filter-type.cjs +0 -16
  83. package/dist/cjs/types/filters.cjs +0 -16
  84. package/dist/cjs/types/index.cjs +0 -120
  85. package/dist/cjs/types/input-callout-component-schema.cjs +0 -16
  86. package/dist/cjs/types/input-file-callout-component-schema.cjs +0 -16
  87. package/dist/cjs/types/nestable-callout-component-schema.cjs +0 -16
  88. package/dist/cjs/types/notice-filter-name.cjs +0 -16
  89. package/dist/cjs/types/operators-by-type.cjs +0 -16
  90. package/dist/cjs/types/other-filter-args.cjs +0 -16
  91. package/dist/cjs/types/paginated-query.cjs +0 -16
  92. package/dist/cjs/types/paginated.cjs +0 -16
  93. package/dist/cjs/types/payment-filter-name.cjs +0 -16
  94. package/dist/cjs/types/radio-callout-component-schema.cjs +0 -16
  95. package/dist/cjs/types/role-type.cjs +0 -16
  96. package/dist/cjs/types/rule-group.cjs +0 -16
  97. package/dist/cjs/types/rule-operator.cjs +0 -16
  98. package/dist/cjs/types/rule-opperator-params.cjs +0 -16
  99. package/dist/cjs/types/rule-value.cjs +0 -16
  100. package/dist/cjs/types/rule.cjs +0 -16
  101. package/dist/cjs/types/select-callout-component-schema.cjs +0 -16
  102. package/dist/cjs/types/stripe-fee-country.cjs +0 -16
  103. package/dist/cjs/types/unit-matches.cjs +0 -16
  104. package/dist/cjs/types/validated-boolean-rule.cjs +0 -16
  105. package/dist/cjs/types/validated-number-rule.cjs +0 -16
  106. package/dist/cjs/types/validated-rule-group.cjs +0 -16
  107. package/dist/cjs/types/validated-rule-value.cjs +0 -16
  108. package/dist/cjs/types/validated-rule.cjs +0 -16
  109. package/dist/cjs/types/validated-string-rule.cjs +0 -16
  110. package/dist/cjs/utils/callouts.cjs +0 -137
  111. package/dist/cjs/utils/date.cjs +0 -87
  112. package/dist/cjs/utils/index.cjs +0 -28
  113. package/dist/cjs/utils/payments.cjs +0 -53
  114. package/dist/cjs/utils/rules.cjs +0 -109
  115. package/dist/esm/search/operators.js +0 -62
  116. package/dist/esm/types/api-key-filter-name.js +0 -0
  117. package/dist/esm/types/array-filter-args.js +0 -0
  118. package/dist/esm/types/base-callout-component-schema.js +0 -0
  119. package/dist/esm/types/base-filter-args.js +0 -0
  120. package/dist/esm/types/base-validated-rule.js +0 -0
  121. package/dist/esm/types/callout-component-schema.js +0 -0
  122. package/dist/esm/types/callout-filter-name.js +0 -0
  123. package/dist/esm/types/callout-form-schema.js +0 -0
  124. package/dist/esm/types/callout-navigation-schema.js +0 -0
  125. package/dist/esm/types/callout-response-answer-address.js +0 -0
  126. package/dist/esm/types/callout-response-answer-file-upload.js +0 -0
  127. package/dist/esm/types/callout-response-answer.js +0 -0
  128. package/dist/esm/types/callout-response-answers.js +0 -0
  129. package/dist/esm/types/callout-response-comment-filter-name.js +0 -0
  130. package/dist/esm/types/callout-response-filter-name.js +0 -0
  131. package/dist/esm/types/callout-slide-schema.js +0 -0
  132. package/dist/esm/types/callout-tag-filter-name.js +0 -0
  133. package/dist/esm/types/content-callout-component-schema.js +0 -0
  134. package/dist/esm/types/date-unit.js +0 -0
  135. package/dist/esm/types/duration.js +0 -0
  136. package/dist/esm/types/enum-filter-args.js +0 -0
  137. package/dist/esm/types/feeable.js +0 -0
  138. package/dist/esm/types/filter-args.js +0 -0
  139. package/dist/esm/types/filter-type.js +0 -0
  140. package/dist/esm/types/filters.js +0 -0
  141. package/dist/esm/types/index.js +0 -50
  142. package/dist/esm/types/input-callout-component-schema.js +0 -0
  143. package/dist/esm/types/input-file-callout-component-schema.js +0 -0
  144. package/dist/esm/types/nestable-callout-component-schema.js +0 -0
  145. package/dist/esm/types/notice-filter-name.js +0 -0
  146. package/dist/esm/types/operators-by-type.js +0 -0
  147. package/dist/esm/types/other-filter-args.js +0 -0
  148. package/dist/esm/types/paginated-query.js +0 -0
  149. package/dist/esm/types/paginated.js +0 -0
  150. package/dist/esm/types/payment-filter-name.js +0 -0
  151. package/dist/esm/types/radio-callout-component-schema.js +0 -0
  152. package/dist/esm/types/role-type.js +0 -0
  153. package/dist/esm/types/rule-group.js +0 -0
  154. package/dist/esm/types/rule-operator.js +0 -0
  155. package/dist/esm/types/rule-opperator-params.js +0 -0
  156. package/dist/esm/types/rule-value.js +0 -0
  157. package/dist/esm/types/rule.js +0 -0
  158. package/dist/esm/types/select-callout-component-schema.js +0 -0
  159. package/dist/esm/types/stripe-fee-country.js +0 -0
  160. package/dist/esm/types/unit-matches.js +0 -0
  161. package/dist/esm/types/validated-boolean-rule.js +0 -0
  162. package/dist/esm/types/validated-number-rule.js +0 -0
  163. package/dist/esm/types/validated-rule-group.js +0 -0
  164. package/dist/esm/types/validated-rule-value.js +0 -0
  165. package/dist/esm/types/validated-rule.js +0 -0
  166. package/dist/esm/types/validated-string-rule.js +0 -0
  167. package/dist/esm/utils/index.js +0 -4
  168. package/dist/types/search/operators.d.ts +0 -128
  169. package/dist/types/types/api-key-filter-name.d.ts +0 -2
  170. package/dist/types/types/array-filter-args.d.ts +0 -5
  171. package/dist/types/types/base-callout-component-schema.d.ts +0 -9
  172. package/dist/types/types/base-filter-args.d.ts +0 -5
  173. package/dist/types/types/base-validated-rule.d.ts +0 -9
  174. package/dist/types/types/callout-component-schema.d.ts +0 -2
  175. package/dist/types/types/callout-filter-name.d.ts +0 -2
  176. package/dist/types/types/callout-form-schema.d.ts +0 -4
  177. package/dist/types/types/callout-navigation-schema.d.ts +0 -6
  178. package/dist/types/types/callout-response-answer-address.d.ts +0 -9
  179. package/dist/types/types/callout-response-answer-file-upload.d.ts +0 -3
  180. package/dist/types/types/callout-response-answer.d.ts +0 -2
  181. package/dist/types/types/callout-response-answers.d.ts +0 -5
  182. package/dist/types/types/callout-response-comment-filter-name.d.ts +0 -2
  183. package/dist/types/types/callout-response-filter-name.d.ts +0 -2
  184. package/dist/types/types/callout-slide-schema.d.ts +0 -7
  185. package/dist/types/types/callout-tag-filter-name.d.ts +0 -2
  186. package/dist/types/types/content-callout-component-schema.d.ts +0 -5
  187. package/dist/types/types/date-unit.d.ts +0 -2
  188. package/dist/types/types/duration.d.ts +0 -1
  189. package/dist/types/types/enum-filter-args.d.ts +0 -5
  190. package/dist/types/types/feeable.d.ts +0 -6
  191. package/dist/types/types/filter-args.d.ts +0 -2
  192. package/dist/types/types/filter-type.d.ts +0 -1
  193. package/dist/types/types/filters.d.ts +0 -2
  194. package/dist/types/types/index.d.ts +0 -50
  195. package/dist/types/types/input-callout-component-schema.d.ts +0 -6
  196. package/dist/types/types/input-file-callout-component-schema.d.ts +0 -5
  197. package/dist/types/types/nestable-callout-component-schema.d.ts +0 -6
  198. package/dist/types/types/notice-filter-name.d.ts +0 -2
  199. package/dist/types/types/operators-by-type.d.ts +0 -2
  200. package/dist/types/types/other-filter-args.d.ts +0 -4
  201. package/dist/types/types/paginated-query.d.ts +0 -8
  202. package/dist/types/types/paginated.d.ts +0 -6
  203. package/dist/types/types/payment-filter-name.d.ts +0 -2
  204. package/dist/types/types/radio-callout-component-schema.d.ts +0 -10
  205. package/dist/types/types/role-type.d.ts +0 -2
  206. package/dist/types/types/rule-group.d.ts +0 -5
  207. package/dist/types/types/rule-operator.d.ts +0 -2
  208. package/dist/types/types/rule-opperator-params.d.ts +0 -3
  209. package/dist/types/types/rule-value.d.ts +0 -1
  210. package/dist/types/types/rule.d.ts +0 -6
  211. package/dist/types/types/select-callout-component-schema.d.ts +0 -11
  212. package/dist/types/types/stripe-fee-country.d.ts +0 -1
  213. package/dist/types/types/unit-matches.d.ts +0 -2
  214. package/dist/types/types/validated-boolean-rule.d.ts +0 -2
  215. package/dist/types/types/validated-number-rule.d.ts +0 -2
  216. package/dist/types/types/validated-rule-group.d.ts +0 -5
  217. package/dist/types/types/validated-rule-value.d.ts +0 -2
  218. package/dist/types/types/validated-rule.d.ts +0 -2
  219. package/dist/types/types/validated-string-rule.d.ts +0 -2
  220. package/dist/types/utils/index.d.ts +0 -4
@@ -1,37 +1,34 @@
1
- import { ItemStatus } from "../data/index.js";
2
- const noticeFilters = {
3
- id: {
4
- type: "text"
5
- },
6
- createdAt: {
7
- type: "date"
8
- },
9
- updatedAt: {
10
- type: "date"
11
- },
12
- name: {
13
- type: "text"
14
- },
15
- expires: {
16
- type: "date",
17
- nullable: true
18
- },
19
- enabled: {
20
- type: "boolean"
21
- },
22
- text: {
23
- type: "text"
24
- },
25
- status: {
26
- type: "enum",
27
- options: [
28
- ItemStatus.Draft,
29
- ItemStatus.Scheduled,
30
- ItemStatus.Open,
31
- ItemStatus.Ended
32
- ]
33
- }
34
- };
35
- export {
36
- noticeFilters
1
+ import { ItemStatus } from "../data";
2
+ export const noticeFilters = {
3
+ id: {
4
+ type: "text",
5
+ },
6
+ createdAt: {
7
+ type: "date",
8
+ },
9
+ updatedAt: {
10
+ type: "date",
11
+ },
12
+ name: {
13
+ type: "text",
14
+ },
15
+ expires: {
16
+ type: "date",
17
+ nullable: true,
18
+ },
19
+ enabled: {
20
+ type: "boolean",
21
+ },
22
+ text: {
23
+ type: "text",
24
+ },
25
+ status: {
26
+ type: "enum",
27
+ options: [
28
+ ItemStatus.Draft,
29
+ ItemStatus.Scheduled,
30
+ ItemStatus.Open,
31
+ ItemStatus.Ended,
32
+ ],
33
+ },
37
34
  };
@@ -1,27 +1,24 @@
1
- import { PaymentStatus } from "../data/index.js";
2
- const paymentFilters = {
3
- id: {
4
- type: "text"
5
- },
6
- contact: {
7
- type: "contact"
8
- },
9
- chargeDate: {
10
- type: "date"
11
- },
12
- amount: {
13
- type: "number"
14
- },
15
- status: {
16
- type: "enum",
17
- options: [
18
- PaymentStatus.Successful,
19
- PaymentStatus.Pending,
20
- PaymentStatus.Failed,
21
- PaymentStatus.Cancelled
22
- ]
23
- }
24
- };
25
- export {
26
- paymentFilters
1
+ import { PaymentStatus } from "../data";
2
+ export const paymentFilters = {
3
+ id: {
4
+ type: "text",
5
+ },
6
+ contact: {
7
+ type: "contact",
8
+ },
9
+ chargeDate: {
10
+ type: "date",
11
+ },
12
+ amount: {
13
+ type: "number",
14
+ },
15
+ status: {
16
+ type: "enum",
17
+ options: [
18
+ PaymentStatus.Successful,
19
+ PaymentStatus.Pending,
20
+ PaymentStatus.Failed,
21
+ PaymentStatus.Cancelled,
22
+ ],
23
+ },
27
24
  };
@@ -1,106 +1,108 @@
1
1
  function isNestableComponent(component) {
2
- return "components" in component && component.type !== "address";
2
+ // Addresses have embedded components we don't want to include
3
+ return "components" in component && component.type !== "address";
3
4
  }
4
5
  function convertValuesToOptions(values) {
5
- return values.map(({ value }) => value);
6
+ return values.map(({ value, label }) => value);
6
7
  }
7
8
  function convertComponentToFilter(component) {
8
- const baseItem = {
9
- label: component.label || component.fullKey,
10
- nullable: true
11
- };
12
- switch (component.type) {
13
- case "checkbox":
14
- return { ...baseItem, type: "boolean", nullable: false };
15
- case "number":
16
- return { ...baseItem, type: "number" };
17
- case "select":
18
- return {
19
- ...baseItem,
20
- type: "enum",
21
- options: convertValuesToOptions(component.data.values)
22
- };
23
- case "selectboxes":
24
- case "radio":
25
- return {
26
- ...baseItem,
27
- type: component.type === "radio" ? "enum" : "array",
28
- options: convertValuesToOptions(component.values)
29
- };
30
- case "textarea":
31
- return { ...baseItem, type: "blob" };
32
- default:
33
- return { ...baseItem, type: "text" };
34
- }
9
+ const baseItem = {
10
+ label: component.label || component.fullKey,
11
+ nullable: true,
12
+ };
13
+ switch (component.type) {
14
+ case "checkbox":
15
+ return { ...baseItem, type: "boolean", nullable: false };
16
+ case "number":
17
+ return { ...baseItem, type: "number" };
18
+ case "select":
19
+ return {
20
+ ...baseItem,
21
+ type: "enum",
22
+ options: convertValuesToOptions(component.data.values),
23
+ };
24
+ case "selectboxes":
25
+ case "radio":
26
+ return {
27
+ ...baseItem,
28
+ type: component.type === "radio" ? "enum" : "array",
29
+ options: convertValuesToOptions(component.values),
30
+ };
31
+ case "textarea":
32
+ return { ...baseItem, type: "blob" };
33
+ default:
34
+ return { ...baseItem, type: "text" };
35
+ }
35
36
  }
36
37
  function getNiceAnswer(component, value) {
37
- switch (component.type) {
38
- case "radio":
39
- case "selectboxes":
40
- return component.values.find((v) => v.value === value)?.label || value;
41
- case "select":
42
- return component.data.values.find((v) => v.value === value)?.label || value;
43
- default:
44
- return value;
45
- }
38
+ switch (component.type) {
39
+ case "radio":
40
+ case "selectboxes":
41
+ return component.values.find((v) => v.value === value)?.label || value;
42
+ case "select":
43
+ return (component.data.values.find((v) => v.value === value)?.label || value);
44
+ default:
45
+ return value;
46
+ }
46
47
  }
47
- function flattenComponents(components) {
48
- return components.flatMap(
49
- (component) => isNestableComponent(component) ? [component, ...flattenComponents(component.components)] : [component]
50
- );
48
+ export function flattenComponents(components) {
49
+ return components.flatMap((component) => isNestableComponent(component)
50
+ ? [component, ...flattenComponents(component.components)]
51
+ : [component]);
51
52
  }
52
- function filterComponents(components, filterFn) {
53
- return components.filter(filterFn).map((component) => {
54
- return {
55
- ...component,
56
- ...isNestableComponent(component) && {
57
- components: filterComponents(component.components, filterFn)
58
- }
59
- };
60
- });
53
+ export function filterComponents(components, filterFn) {
54
+ return components.filter(filterFn).map((component) => {
55
+ return {
56
+ ...component,
57
+ ...(isNestableComponent(component) && {
58
+ components: filterComponents(component.components, filterFn),
59
+ }),
60
+ };
61
+ });
61
62
  }
62
- function getCalloutComponents(formSchema) {
63
- return formSchema.slides.flatMap(
64
- (slide) => flattenComponents(slide.components).map((component) => ({
65
- ...component,
66
- slideId: slide.id,
67
- fullKey: `${slide.id}.${component.key}`
68
- }))
69
- );
63
+ export function getCalloutComponents(formSchema) {
64
+ return formSchema.slides.flatMap((slide) => flattenComponents(slide.components).map((component) => ({
65
+ ...component,
66
+ slideId: slide.id,
67
+ fullKey: `${slide.id}.${component.key}`,
68
+ })));
70
69
  }
71
- function getCalloutFilters(formSchema) {
72
- const items = getCalloutComponents(formSchema).filter((c) => c.input).map((c) => [`answers.${c.fullKey}`, convertComponentToFilter(c)]);
73
- return Object.fromEntries(items);
70
+ export function getCalloutFilters(formSchema) {
71
+ const items = getCalloutComponents(formSchema)
72
+ .filter((c) => c.input)
73
+ .map((c) => [`answers.${c.fullKey}`, convertComponentToFilter(c)]);
74
+ return Object.fromEntries(items);
74
75
  }
75
- function isAddressAnswer(answer) {
76
- return !!answer && typeof answer === "object" && "geometry" in answer;
76
+ export function isAddressAnswer(answer) {
77
+ return !!answer && typeof answer === "object" && "geometry" in answer;
77
78
  }
78
- function isFileUploadAnswer(answer) {
79
- return !!answer && typeof answer === "object" && "url" in answer;
79
+ export function isFileUploadAnswer(answer) {
80
+ return !!answer && typeof answer === "object" && "url" in answer;
80
81
  }
81
- function stringifyAnswer(component, answer) {
82
- if (Array.isArray(answer)) {
83
- return answer.map((a) => stringifyAnswer(component, a)).join(", ");
84
- } else if (!answer) {
85
- return "";
86
- } else if (isAddressAnswer(answer)) {
87
- return answer.geometry.location.lat + ", " + answer.geometry.location.lng;
88
- } else if (isFileUploadAnswer(answer)) {
89
- return answer.url;
90
- } else if (typeof answer === "object") {
91
- return Object.entries(answer).filter(([, selected]) => selected).map(([value]) => getNiceAnswer(component, value)).join(", ");
92
- } else if (typeof answer === "string") {
93
- return getNiceAnswer(component, answer);
94
- } else {
95
- return answer.toString();
96
- }
82
+ export function stringifyAnswer(component, answer) {
83
+ if (Array.isArray(answer)) {
84
+ return answer.map((a) => stringifyAnswer(component, a)).join(", ");
85
+ }
86
+ else if (!answer) {
87
+ return "";
88
+ }
89
+ else if (isAddressAnswer(answer)) {
90
+ return answer.geometry.location.lat + ", " + answer.geometry.location.lng;
91
+ }
92
+ else if (isFileUploadAnswer(answer)) {
93
+ return answer.url;
94
+ }
95
+ else if (typeof answer === "object") {
96
+ // Checkboxes
97
+ return Object.entries(answer)
98
+ .filter(([, selected]) => selected)
99
+ .map(([value]) => getNiceAnswer(component, value))
100
+ .join(", ");
101
+ }
102
+ else if (typeof answer === "string") {
103
+ return getNiceAnswer(component, answer);
104
+ }
105
+ else {
106
+ return answer.toString();
107
+ }
97
108
  }
98
- export {
99
- filterComponents,
100
- flattenComponents,
101
- getCalloutComponents,
102
- getCalloutFilters,
103
- isAddressAnswer,
104
- isFileUploadAnswer,
105
- stringifyAnswer
106
- };
@@ -1,68 +1,68 @@
1
- import {
2
- add,
3
- isValid,
4
- parseISO,
5
- startOfDay,
6
- startOfHour,
7
- startOfMinute,
8
- startOfMonth,
9
- startOfSecond,
10
- startOfYear
11
- } from "date-fns";
1
+ import add from "date-fns/add";
2
+ import isValid from "date-fns/isValid";
3
+ import parseISO from "date-fns/parseISO";
4
+ import startOfDay from "date-fns/startOfDay";
5
+ import startOfHour from "date-fns/startOfHour";
6
+ import startOfMinute from "date-fns/startOfMinute";
7
+ import startOfMonth from "date-fns/startOfMonth";
8
+ import startOfSecond from "date-fns/startOfSecond";
9
+ import startOfYear from "date-fns/startOfYear";
10
+ // Must be ordered from highest resolution to lowest (seconds to years)
12
11
  const dateUnits = ["s", "m", "h", "d", "M", "y"];
13
12
  const dateUnitMap = {
14
- y: "years",
15
- M: "months",
16
- d: "days",
17
- h: "hours",
18
- m: "minutes",
19
- s: "seconds"
13
+ y: "years",
14
+ M: "months",
15
+ d: "days",
16
+ h: "hours",
17
+ m: "minutes",
18
+ s: "seconds",
20
19
  };
21
20
  const startOf = {
22
- y: startOfYear,
23
- M: startOfMonth,
24
- d: startOfDay,
25
- h: startOfHour,
26
- m: startOfMinute,
27
- s: startOfSecond
21
+ y: startOfYear,
22
+ M: startOfMonth,
23
+ d: startOfDay,
24
+ h: startOfHour,
25
+ m: startOfMinute,
26
+ s: startOfSecond,
28
27
  };
29
28
  const relativeDate = /^\$now(?<units>\(((y|M|d|h|m|s):(-?\d+),?)+\))?$/;
30
29
  const relativeUnit = /(y|M|d|h|m|s):(-?\d+)/g;
30
+ // Matches the different parts of an ISO 8601 date. Note we don't validate the
31
+ // pattern properly as that is handled by parseISO, we just want to know which
32
+ // parts of the date were specified
31
33
  const absoluteDate = /^(?<y>\d{4,})(-(?<M>\d\d)(-(?<d>\d\d)([T ](?<h>\d\d)(:(?<m>\d\d)(:(?<s>\d\d))?)?)?)?)?/;
32
- function parseDate(value, now) {
33
- let date;
34
- let units;
35
- const relativeMatch = relativeDate.exec(value);
36
- if (relativeMatch) {
37
- date = now || /* @__PURE__ */ new Date();
38
- const unitsGroup = relativeMatch.groups?.units;
39
- if (unitsGroup) {
40
- const unitMatches = unitsGroup.matchAll(relativeUnit);
41
- units = [];
42
- for (const [_, unit, delta] of unitMatches) {
43
- date = add(date, { [dateUnitMap[unit]]: Number(delta) });
44
- units.push(unit);
45
- }
46
- } else {
47
- units = ["d"];
34
+ // Convert relative dates and returns the minimum date unit specified
35
+ export function parseDate(value, now) {
36
+ let date;
37
+ let units;
38
+ const relativeMatch = relativeDate.exec(value);
39
+ if (relativeMatch) {
40
+ date = now || new Date();
41
+ const unitsGroup = relativeMatch.groups?.units;
42
+ if (unitsGroup) {
43
+ const unitMatches = unitsGroup.matchAll(relativeUnit);
44
+ units = [];
45
+ for (const [_, unit, delta] of unitMatches) {
46
+ date = add(date, { [dateUnitMap[unit]]: Number(delta) });
47
+ units.push(unit);
48
+ }
49
+ }
50
+ else {
51
+ units = ["d"];
52
+ }
48
53
  }
49
- } else {
50
- date = parseISO(value);
51
- units = Object.entries(absoluteDate.exec(value)?.groups || {}).filter(([_, n]) => !!n).map(([unit]) => unit);
52
- }
53
- const minUnit = getMinDateUnit(units) || "s";
54
- return [startOf[minUnit](date), minUnit];
54
+ else {
55
+ date = parseISO(value);
56
+ units = Object.entries(absoluteDate.exec(value)?.groups || {})
57
+ .filter(([_, n]) => !!n)
58
+ .map(([unit]) => unit);
59
+ }
60
+ const minUnit = getMinDateUnit(units) || "s";
61
+ return [startOf[minUnit](date), minUnit];
55
62
  }
56
- function getMinDateUnit(units) {
57
- return dateUnits.find((unit) => units.includes(unit));
63
+ export function getMinDateUnit(units) {
64
+ return dateUnits.find((unit) => units.includes(unit));
58
65
  }
59
- function isValidDate(s) {
60
- return relativeDate.test(s) || isValid(parseISO(s));
66
+ export function isValidDate(s) {
67
+ return relativeDate.test(s) || isValid(parseISO(s));
61
68
  }
62
- export {
63
- dateUnitMap,
64
- dateUnits,
65
- getMinDateUnit,
66
- isValidDate,
67
- parseDate
68
- };
@@ -1,29 +1,27 @@
1
- import { ContributionPeriod, PaymentMethod } from "../data/index.js";
1
+ import { ContributionPeriod, PaymentMethod } from "../data";
2
2
  const stripeFees = {
3
- gb: {
4
- [PaymentMethod.StripeCard]: (amount) => 0.2 + 0.015 * amount,
5
- [PaymentMethod.StripeSEPA]: () => 0.3,
6
- [PaymentMethod.StripeBACS]: (amount) => Math.min(2, Math.max(0.2, 0.01 * amount))
7
- },
8
- eu: {
9
- [PaymentMethod.StripeCard]: (amount) => 0.25 + 0.015 * amount,
10
- [PaymentMethod.StripeSEPA]: () => 0.35,
11
- [PaymentMethod.StripeBACS]: () => 0
12
- // Not available
13
- },
14
- ca: {
15
- [PaymentMethod.StripeCard]: (amount) => 0.3 + 0.029 * amount,
16
- [PaymentMethod.StripeSEPA]: () => 0,
17
- // Not available
18
- [PaymentMethod.StripeBACS]: () => 0
19
- // Not available
20
- }
3
+ gb: {
4
+ [PaymentMethod.StripeCard]: (amount) => 0.2 + 0.015 * amount,
5
+ [PaymentMethod.StripeSEPA]: () => 0.3,
6
+ [PaymentMethod.StripeBACS]: (amount) => Math.min(2, Math.max(0.2, 0.01 * amount)),
7
+ },
8
+ eu: {
9
+ [PaymentMethod.StripeCard]: (amount) => 0.25 + 0.015 * amount,
10
+ [PaymentMethod.StripeSEPA]: () => 0.35,
11
+ [PaymentMethod.StripeBACS]: () => 0, // Not available
12
+ },
13
+ ca: {
14
+ [PaymentMethod.StripeCard]: (amount) => 0.3 + 0.029 * amount,
15
+ [PaymentMethod.StripeSEPA]: () => 0,
16
+ [PaymentMethod.StripeBACS]: () => 0, // Not available
17
+ },
21
18
  };
22
19
  const gcFee = (amount) => 0.2 + amount * 0.01;
23
- function calcPaymentFee(feeable, country) {
24
- const feeFn = feeable.paymentMethod === PaymentMethod.GoCardlessDirectDebit ? gcFee : stripeFees[country][feeable.paymentMethod];
25
- return feeable.period === ContributionPeriod.Annually ? 0 : feeFn(feeable.amount);
20
+ export function calcPaymentFee(feeable, country) {
21
+ const feeFn = feeable.paymentMethod === PaymentMethod.GoCardlessDirectDebit
22
+ ? gcFee
23
+ : stripeFees[country][feeable.paymentMethod];
24
+ return feeable.period === ContributionPeriod.Annually
25
+ ? 0
26
+ : feeFn(feeable.amount);
26
27
  }
27
- export {
28
- calcPaymentFee
29
- };
@@ -1,80 +1,63 @@
1
- import { InvalidRule } from "../error/index.js";
2
- import { nullableOperators, operatorsByTypeMap } from "../search/index.js";
3
- import { isValidDate } from "./date.js";
4
- function isRuleGroup(ruleOrGroup) {
5
- return "condition" in ruleOrGroup;
1
+ import { InvalidRule } from "../error";
2
+ import { nullableOperators, operatorsByTypeMap, } from "../search";
3
+ import { isValidDate } from "./date";
4
+ export function isRuleGroup(ruleOrGroup) {
5
+ return "condition" in ruleOrGroup;
6
6
  }
7
- function validateRule(filters, rule) {
8
- const filter = filters[rule.field];
9
- if (!filter) {
10
- throw new InvalidRule(rule, `Invalid field: ${rule.field}`);
11
- }
12
- let expectedArgs = 0;
13
- if (rule.operator in nullableOperators) {
14
- if (!filter.nullable && filter.type !== "text") {
15
- throw new InvalidRule(
16
- rule,
17
- `Invalid nullable operator: field is not nullable`
18
- );
7
+ export function validateRule(filters, rule) {
8
+ const filter = filters[rule.field];
9
+ if (!filter) {
10
+ throw new InvalidRule(rule, `Invalid field: ${rule.field}`);
19
11
  }
20
- } else {
21
- const operator = operatorsByTypeMap[filter.type][rule.operator];
22
- if (!operator) {
23
- throw new InvalidRule(
24
- rule,
25
- `Invalid operator for type: ${filter.type} type doesn't define ${rule.operator}`
26
- );
12
+ let expectedArgs = 0;
13
+ if (rule.operator in nullableOperators) {
14
+ // Field cannot be empty (except text which can always be empty)
15
+ if (!filter.nullable && filter.type !== "text") {
16
+ throw new InvalidRule(rule, `Invalid nullable operator: field is not nullable`);
17
+ }
27
18
  }
28
- expectedArgs = operator.args;
29
- }
30
- if (expectedArgs !== rule.value.length) {
31
- throw new InvalidRule(
32
- rule,
33
- `Invalid operator argument count: ${rule.operator} needs ${expectedArgs}, ${rule.value.length} given`
34
- );
35
- }
36
- const expectedType = filter.type === "boolean" || filter.type === "number" ? filter.type : "string";
37
- if (rule.value.some((v) => typeof v !== expectedType)) {
38
- throw new InvalidRule(
39
- rule,
40
- `Invalid operator argument type: ${rule.operator} needs ${expectedType}, ${rule.value.map(
41
- (v) => typeof v
42
- )} given`
43
- );
44
- }
45
- if (filter.type === "date" && rule.value.some((v) => !isValidDate(v))) {
46
- throw new InvalidRule(
47
- rule,
48
- `Invalid operator argument: date type needs valid absolute or relative date, ${rule.value} given`
49
- );
50
- }
51
- if ((filter.type === "enum" || filter.type === "array") && rule.value.some((v) => filter.options?.indexOf(v) === -1)) {
52
- throw new InvalidRule(
53
- rule,
54
- `Invalid operator argument: ${filter.type} type expected ${filter.options}, ${rule.value} given`
55
- );
56
- }
57
- return {
58
- field: rule.field,
59
- type: filter.type,
60
- nullable: !!filter.nullable,
61
- operator: rule.operator,
62
- value: rule.value
63
- };
19
+ else {
20
+ const operator = operatorsByTypeMap[filter.type][rule.operator];
21
+ if (!operator) {
22
+ throw new InvalidRule(rule, `Invalid operator for type: ${filter.type} type doesn't define ${rule.operator}`);
23
+ }
24
+ expectedArgs = operator.args;
25
+ }
26
+ if (expectedArgs !== rule.value.length) {
27
+ throw new InvalidRule(rule, `Invalid operator argument count: ${rule.operator} needs ${expectedArgs}, ${rule.value.length} given`);
28
+ }
29
+ const expectedType = filter.type === "boolean" || filter.type === "number"
30
+ ? filter.type
31
+ : "string";
32
+ if (rule.value.some((v) => typeof v !== expectedType)) {
33
+ throw new InvalidRule(rule, `Invalid operator argument type: ${rule.operator} needs ${expectedType}, ${rule.value.map((v) => typeof v)} given`);
34
+ }
35
+ if (filter.type === "date" &&
36
+ rule.value.some((v) => !isValidDate(v))) {
37
+ throw new InvalidRule(rule, `Invalid operator argument: date type needs valid absolute or relative date, ${rule.value} given`);
38
+ }
39
+ if ((filter.type === "enum" || filter.type === "array") &&
40
+ rule.value.some((v) => filter.options?.indexOf(v) === -1)) {
41
+ throw new InvalidRule(rule, `Invalid operator argument: ${filter.type} type expected ${filter.options}, ${rule.value} given`);
42
+ }
43
+ return {
44
+ field: rule.field,
45
+ type: filter.type,
46
+ nullable: !!filter.nullable,
47
+ operator: rule.operator,
48
+ value: rule.value,
49
+ };
64
50
  }
65
- function validateRuleGroup(filters, ruleGroup) {
66
- const validatedRuleGroup = {
67
- condition: ruleGroup.condition,
68
- rules: []
69
- };
70
- for (const rule of ruleGroup.rules) {
71
- const valid = isRuleGroup(rule) ? validateRuleGroup(filters, rule) : validateRule(filters, rule);
72
- validatedRuleGroup.rules.push(valid);
73
- }
74
- return validatedRuleGroup;
51
+ export function validateRuleGroup(filters, ruleGroup) {
52
+ const validatedRuleGroup = {
53
+ condition: ruleGroup.condition,
54
+ rules: [],
55
+ };
56
+ for (const rule of ruleGroup.rules) {
57
+ const valid = isRuleGroup(rule)
58
+ ? validateRuleGroup(filters, rule)
59
+ : validateRule(filters, rule);
60
+ validatedRuleGroup.rules.push(valid);
61
+ }
62
+ return validatedRuleGroup;
75
63
  }
76
- export {
77
- isRuleGroup,
78
- validateRule,
79
- validateRuleGroup
80
- };