@beabee/beabee-common 0.20.1 → 0.20.2-alpha.1

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 (78) hide show
  1. package/dist/cjs/data/payment-method.cjs +1 -0
  2. package/dist/cjs/index.cjs +0 -1
  3. package/dist/cjs/search/callouts.cjs +5 -2
  4. package/dist/cjs/types/{callout-navigation-schema.cjs → callout-response-answers.cjs} +2 -2
  5. package/dist/cjs/types/{callout-form-schema.cjs → get-callout-form-schema.cjs} +2 -2
  6. package/dist/cjs/types/{callout-response-answers-nestable.cjs → get-callout-navigation-schema.cjs} +2 -2
  7. package/dist/cjs/types/get-callout-slide-schema.cjs +16 -0
  8. package/dist/cjs/types/index.cjs +14 -8
  9. package/dist/cjs/types/{callout-slide-schema.cjs → set-callout-form-schema.cjs} +2 -2
  10. package/dist/cjs/types/set-callout-navigation-schema.cjs +16 -0
  11. package/dist/cjs/types/set-callout-slide-schema.cjs +16 -0
  12. package/dist/cjs/utils/payments.cjs +7 -3
  13. package/dist/cjs/validators/callout-component-input-address.validator.cjs +1 -5
  14. package/dist/cjs/validators/callout-component-input-checkbox.validator.cjs +1 -5
  15. package/dist/cjs/validators/callout-component-input-currency.validator.cjs +1 -5
  16. package/dist/cjs/validators/callout-component-input-date-time.validator.cjs +0 -4
  17. package/dist/cjs/validators/callout-component-input-email.validator.cjs +1 -9
  18. package/dist/cjs/validators/callout-component-input-file.validator.cjs +5 -5
  19. package/dist/cjs/validators/callout-component-input-number.validator.cjs +0 -4
  20. package/dist/cjs/validators/callout-component-input-phone-number.validator.cjs +1 -5
  21. package/dist/cjs/validators/callout-component-input-select.validator.cjs +0 -9
  22. package/dist/cjs/validators/callout-component-input-selectable.validator.cjs +0 -12
  23. package/dist/cjs/validators/callout-component-input-text.validator.cjs +4 -5
  24. package/dist/cjs/validators/callout-component-input-time.validator.cjs +1 -5
  25. package/dist/cjs/validators/callout-component-input-url.validator.cjs +1 -9
  26. package/dist/cjs/validators/callout-component.validator.cjs +46 -32
  27. package/dist/esm/data/payment-method.js +1 -0
  28. package/dist/esm/search/callouts.js +5 -2
  29. package/dist/esm/types/index.js +7 -4
  30. package/dist/esm/types/set-callout-form-schema.js +0 -0
  31. package/dist/esm/types/set-callout-navigation-schema.js +0 -0
  32. package/dist/esm/types/set-callout-slide-schema.js +0 -0
  33. package/dist/esm/utils/payments.js +7 -3
  34. package/dist/esm/validators/callout-component-input-address.validator.js +1 -4
  35. package/dist/esm/validators/callout-component-input-checkbox.validator.js +1 -4
  36. package/dist/esm/validators/callout-component-input-currency.validator.js +1 -4
  37. package/dist/esm/validators/callout-component-input-date-time.validator.js +0 -3
  38. package/dist/esm/validators/callout-component-input-email.validator.js +2 -9
  39. package/dist/esm/validators/callout-component-input-file.validator.js +5 -4
  40. package/dist/esm/validators/callout-component-input-number.validator.js +0 -3
  41. package/dist/esm/validators/callout-component-input-phone-number.validator.js +1 -4
  42. package/dist/esm/validators/callout-component-input-select.validator.js +0 -8
  43. package/dist/esm/validators/callout-component-input-selectable.validator.js +0 -11
  44. package/dist/esm/validators/callout-component-input-text.validator.js +4 -4
  45. package/dist/esm/validators/callout-component-input-time.validator.js +1 -4
  46. package/dist/esm/validators/callout-component-input-url.validator.js +2 -9
  47. package/dist/esm/validators/callout-component.validator.js +48 -33
  48. package/dist/types/data/payment-method.d.ts +1 -0
  49. package/dist/types/search/callouts.d.ts +5 -2
  50. package/dist/types/types/callout-component-base-input-schema.d.ts +2 -0
  51. package/dist/types/types/callout-component-base-schema.d.ts +1 -1
  52. package/dist/types/types/callout-component-content-schema.d.ts +7 -0
  53. package/dist/types/types/callout-component-input-address-schema.d.ts +2 -0
  54. package/dist/types/types/callout-component-input-phone-number-schema.d.ts +2 -0
  55. package/dist/types/types/callout-component-input-select-schema.d.ts +2 -0
  56. package/dist/types/types/callout-response-answer.d.ts +1 -1
  57. package/dist/types/types/callout-response-answers-slide.d.ts +2 -2
  58. package/dist/types/types/callout-response-answers.d.ts +5 -0
  59. package/dist/types/types/get-callout-form-schema.d.ts +5 -0
  60. package/dist/types/types/get-callout-navigation-schema.d.ts +6 -0
  61. package/dist/types/types/get-callout-slide-schema.d.ts +4 -0
  62. package/dist/types/types/index.d.ts +7 -4
  63. package/dist/types/types/set-callout-form-schema.d.ts +4 -0
  64. package/dist/types/types/set-callout-navigation-schema.d.ts +3 -0
  65. package/dist/types/types/set-callout-slide-schema.d.ts +7 -0
  66. package/dist/types/types/validator-callout-component.d.ts +2 -2
  67. package/dist/types/utils/callouts.d.ts +5 -5
  68. package/dist/types/validators/callout-component-content.validator.d.ts +1 -1
  69. package/dist/types/validators/callout-component.validator.d.ts +5 -3
  70. package/package.json +12 -4
  71. package/dist/types/types/callout-form-schema.d.ts +0 -4
  72. package/dist/types/types/callout-navigation-schema.d.ts +0 -6
  73. package/dist/types/types/callout-response-answers-nestable.d.ts +0 -5
  74. package/dist/types/types/callout-slide-schema.d.ts +0 -7
  75. /package/dist/esm/types/{callout-form-schema.js → callout-response-answers.js} +0 -0
  76. /package/dist/esm/types/{callout-navigation-schema.js → get-callout-form-schema.js} +0 -0
  77. /package/dist/esm/types/{callout-response-answers-nestable.js → get-callout-navigation-schema.js} +0 -0
  78. /package/dist/esm/types/{callout-slide-schema.js → get-callout-slide-schema.js} +0 -0
@@ -3,19 +3,23 @@ const stripeFees = {
3
3
  gb: {
4
4
  [PaymentMethod.StripeCard]: (amount) => 0.2 + 0.015 * amount,
5
5
  [PaymentMethod.StripeSEPA]: () => 0.3,
6
- [PaymentMethod.StripeBACS]: (amount) => Math.min(2, Math.max(0.2, 0.01 * amount))
6
+ [PaymentMethod.StripeBACS]: (amount) => Math.min(2, Math.max(0.2, 0.01 * amount)),
7
+ [PaymentMethod.StripePayPal]: (amount) => 0.1 + 0.02 * amount
7
8
  },
8
9
  eu: {
9
10
  [PaymentMethod.StripeCard]: (amount) => 0.25 + 0.015 * amount,
10
11
  [PaymentMethod.StripeSEPA]: () => 0.35,
11
- [PaymentMethod.StripeBACS]: () => 0
12
+ [PaymentMethod.StripeBACS]: () => 0,
12
13
  // Not available
14
+ [PaymentMethod.StripePayPal]: (amount) => 0.1 + 0.02 * amount
13
15
  },
14
16
  ca: {
15
17
  [PaymentMethod.StripeCard]: (amount) => 0.3 + 0.029 * amount,
16
18
  [PaymentMethod.StripeSEPA]: () => 0,
17
19
  // Not available
18
- [PaymentMethod.StripeBACS]: () => 0
20
+ [PaymentMethod.StripeBACS]: () => 0,
21
+ // Not available
22
+ [PaymentMethod.StripePayPal]: () => 0
19
23
  // Not available
20
24
  }
21
25
  };
@@ -1,7 +1,4 @@
1
- const calloutComponentInputAddressValidator = (schema, answer) => {
2
- if (!schema.validate?.required && answer === void 0) {
3
- return true;
4
- }
1
+ const calloutComponentInputAddressValidator = (_schema, _answer) => {
5
2
  throw new Error(
6
3
  `[calloutComponentInputAddressValidator] Not implemented yet`
7
4
  );
@@ -1,7 +1,4 @@
1
- const calloutComponentInputCheckboxValidator = (schema, answer) => {
2
- if (schema.validate?.required && !answer) {
3
- return true;
4
- }
1
+ const calloutComponentInputCheckboxValidator = (_schema, answer) => {
5
2
  return typeof answer === "boolean";
6
3
  };
7
4
  export {
@@ -1,8 +1,5 @@
1
1
  import { isAmountOfMoney } from "../utils/index.js";
2
- const calloutComponentInputCurrencyValidator = (schema, answer) => {
3
- if (schema.validate?.required && answer === void 0) {
4
- return true;
5
- }
2
+ const calloutComponentInputCurrencyValidator = (_schema, answer) => {
6
3
  return isAmountOfMoney(answer);
7
4
  };
8
5
  export {
@@ -1,8 +1,5 @@
1
1
  import { isDateBetween } from "../utils/index.js";
2
2
  const calloutComponentInputDateTimeValidator = (schema, answer) => {
3
- if (!schema.validate?.required && !answer) {
4
- return true;
5
- }
6
3
  if (typeof answer !== "string") {
7
4
  return false;
8
5
  }
@@ -1,12 +1,5 @@
1
- import { isCalloutComponentOfType, isEmail } from "../utils/index.js";
2
- import { CalloutComponentType } from "../data/index.js";
3
- const calloutComponentInputEmailValidator = (schema, answer) => {
4
- if (!isCalloutComponentOfType(schema, CalloutComponentType.INPUT_EMAIL)) {
5
- throw new Error("Schema is not a email component");
6
- }
7
- if (!schema.validate?.required && answer === void 0) {
8
- return true;
9
- }
1
+ import { isEmail } from "../utils/index.js";
2
+ const calloutComponentInputEmailValidator = (_schema, answer) => {
10
3
  return isEmail(answer);
11
4
  };
12
5
  export {
@@ -1,9 +1,10 @@
1
1
  import { isURL } from "../utils/index.js";
2
- const calloutComponentInputFileValidator = (schema, answer) => {
3
- if (!schema.validate?.required && answer === void 0) {
4
- return true;
2
+ import { isFileUploadAnswer } from "../utils/callouts.js";
3
+ const calloutComponentInputFileValidator = (_schema, answer) => {
4
+ if (isFileUploadAnswer(answer)) {
5
+ return isURL(answer.url);
5
6
  }
6
- return isURL(answer);
7
+ return false;
7
8
  };
8
9
  export {
9
10
  calloutComponentInputFileValidator
@@ -1,8 +1,5 @@
1
1
  import { isNumber, isNumberInRange } from "../utils/index.js";
2
2
  const calloutComponentInputNumberValidator = (schema, answer) => {
3
- if (!schema.validate?.required && answer === void 0) {
4
- return true;
5
- }
6
3
  if (schema.validate && !isNumberInRange(answer, schema.validate.min, schema.validate.max)) {
7
4
  return false;
8
5
  }
@@ -1,8 +1,5 @@
1
1
  import { isPhoneNumber } from "../utils/index.js";
2
- const calloutComponentInputPhoneNumberValidator = (schema, answer) => {
3
- if (!schema.validate?.required && answer === void 0) {
4
- return true;
5
- }
2
+ const calloutComponentInputPhoneNumberValidator = (_schema, answer) => {
6
3
  return isPhoneNumber(answer);
7
4
  };
8
5
  export {
@@ -1,12 +1,4 @@
1
- import { isCalloutComponentOfType } from "../utils/index.js";
2
- import { CalloutComponentType } from "../data/index.js";
3
1
  const calloutComponentInputSelectValidator = (schema, answer) => {
4
- if (!isCalloutComponentOfType(schema, CalloutComponentType.INPUT_SELECT)) {
5
- throw new Error("Schema is not a select component");
6
- }
7
- if (!schema.validate?.required && !answer) {
8
- return true;
9
- }
10
2
  const optionValue = schema.data.values.find((v) => v.value === answer);
11
3
  return !!optionValue;
12
4
  };
@@ -1,15 +1,4 @@
1
- import { isCalloutComponentOfBaseType } from "../utils/index.js";
2
- import { CalloutComponentBaseType } from "../data/index.js";
3
1
  const calloutComponentInputSelectableValidator = (schema, answer) => {
4
- if (!isCalloutComponentOfBaseType(
5
- schema,
6
- CalloutComponentBaseType.INPUT_SELECTABLE
7
- )) {
8
- throw new Error("Schema is not a selectable component");
9
- }
10
- if (!schema.validate?.required && !answer) {
11
- return true;
12
- }
13
2
  const optionValue = schema.values.find((v) => v.value === answer);
14
3
  return !!optionValue;
15
4
  };
@@ -3,7 +3,10 @@ const validateRules = (rules, answer) => {
3
3
  if (!rules) {
4
4
  return true;
5
5
  }
6
- if (typeof rules.pattern === "string" && rules.pattern.length && !new RegExp(rules.pattern).test(answer)) {
6
+ if (!answer && rules.required) {
7
+ return false;
8
+ }
9
+ if (typeof rules.pattern === "string" && rules.pattern.length && !new RegExp(rules.pattern).test(answer || "")) {
7
10
  return false;
8
11
  }
9
12
  if (!isTextInWordRange(answer, rules.minWords, rules.maxWords)) {
@@ -15,9 +18,6 @@ const validateRules = (rules, answer) => {
15
18
  return true;
16
19
  };
17
20
  const calloutComponentInputTextValidator = (schema, answer) => {
18
- if (!schema.validate?.required && !answer) {
19
- return true;
20
- }
21
21
  if (typeof answer !== "string") {
22
22
  return false;
23
23
  }
@@ -1,7 +1,4 @@
1
- const calloutComponentInputTimeValidator = (schema, answer) => {
2
- if (!schema.validate?.required && answer === void 0) {
3
- return true;
4
- }
1
+ const calloutComponentInputTimeValidator = (_schema, _answer) => {
5
2
  throw new Error(
6
3
  `[calloutComponentInputTimeValidator] Not implemented yet`
7
4
  );
@@ -1,12 +1,5 @@
1
- import { isCalloutComponentOfType, isURL } from "../utils/index.js";
2
- import { CalloutComponentType } from "../data/index.js";
3
- const calloutComponentInputUrlValidator = (schema, answer) => {
4
- if (!isCalloutComponentOfType(schema, CalloutComponentType.INPUT_URL)) {
5
- throw new Error("Schema is not a url component");
6
- }
7
- if (!schema.validate?.required && answer === void 0) {
8
- return true;
9
- }
1
+ import { isURL } from "../utils/index.js";
2
+ const calloutComponentInputUrlValidator = (_schema, answer) => {
10
3
  return isURL(answer);
11
4
  };
12
5
  export {
@@ -13,31 +13,24 @@ import { calloutComponentInputSignatureValidator } from "./callout-component-inp
13
13
  import { calloutComponentInputTextValidator } from "./callout-component-input-text.validator.js";
14
14
  import { calloutComponentInputTimeValidator } from "./callout-component-input-time.validator.js";
15
15
  import { calloutComponentInputUrlValidator } from "./callout-component-input-url.validator.js";
16
- import { CalloutComponentType } from "../data/index.js";
17
- const calloutComponentNestableValidator = (schema, answerMap) => {
18
- let valid = true;
16
+ import {
17
+ CalloutComponentBaseType,
18
+ CalloutComponentType
19
+ } from "../data/index.js";
20
+ import { isCalloutComponentOfBaseType } from "../utils/callouts.js";
21
+ const calloutComponentNestableValidator = (schema, answers) => {
19
22
  for (const component of schema.components) {
20
- const answer = answerMap[component.key];
21
- const answers = Array.isArray(answer) ? answer : [answer];
22
- if (!answer) {
23
- throw new Error(
24
- `[calloutComponentNestableValidator] no answer`
25
- );
26
- }
27
- for (const _answersLevel2 of answers) {
28
- const answersLevel2 = Array.isArray(_answersLevel2) ? _answersLevel2 : [_answersLevel2];
29
- for (const answer2 of answersLevel2) {
30
- valid = calloutComponentValidator(component, answer2) && valid;
31
- if (!valid) {
32
- return false;
33
- }
34
- }
23
+ const valid = calloutComponentValidator(
24
+ component,
25
+ answers[component.key]
26
+ );
27
+ if (!valid) {
28
+ return false;
35
29
  }
36
30
  }
37
- return valid;
31
+ return true;
38
32
  };
39
- const calloutValidatorsMap = {
40
- [CalloutComponentType.CONTENT]: calloutComponentContentValidator,
33
+ const calloutInputValidatorsMap = {
41
34
  // Input
42
35
  [CalloutComponentType.INPUT_EMAIL]: calloutComponentInputEmailValidator,
43
36
  [CalloutComponentType.INPUT_ADDRESS]: calloutComponentInputAddressValidator,
@@ -56,24 +49,46 @@ const calloutValidatorsMap = {
56
49
  [CalloutComponentType.INPUT_TEXT_AREA]: calloutComponentInputTextValidator,
57
50
  // Selectable
58
51
  [CalloutComponentType.INPUT_SELECTABLE_RADIO]: calloutComponentInputSelectableValidator,
59
- [CalloutComponentType.INPUT_SELECTABLE_SELECTBOXES]: calloutComponentInputSelectableValidator,
60
- // NESTABLE
61
- [CalloutComponentType.NESTABLE_PANEL]: calloutComponentNestableValidator,
62
- [CalloutComponentType.NESTABLE_WELL]: calloutComponentNestableValidator,
63
- [CalloutComponentType.NESTABLE_TABS]: calloutComponentNestableValidator
52
+ [CalloutComponentType.INPUT_SELECTABLE_SELECTBOXES]: calloutComponentInputSelectableValidator
64
53
  };
65
- const calloutComponentValidator = (schema, answer) => {
66
- const validator = calloutValidatorsMap[schema.type];
54
+ function calloutComponentInputValidator(schema, answer) {
55
+ const validator = calloutInputValidatorsMap[schema.type];
67
56
  if (!validator) {
68
57
  console.error(`No validator found for ${schema.type}`);
69
58
  return false;
70
59
  }
71
- return validator(
72
- schema,
73
- answer
74
- );
75
- };
60
+ if (answer === void 0) {
61
+ return schema.validate?.required ? false : true;
62
+ }
63
+ const values = Array.isArray(answer) ? answer : [answer];
64
+ for (const value of values) {
65
+ const valid = validator(schema, value);
66
+ if (!valid) {
67
+ return false;
68
+ }
69
+ }
70
+ return true;
71
+ }
72
+ function calloutComponentValidator(schema, answer) {
73
+ if (isCalloutComponentOfBaseType(schema, CalloutComponentBaseType.NESTABLE)) {
74
+ return calloutComponentNestableValidator(
75
+ schema,
76
+ answer
77
+ );
78
+ }
79
+ if (isCalloutComponentOfBaseType(schema, CalloutComponentBaseType.INPUT)) {
80
+ return calloutComponentInputValidator(
81
+ schema,
82
+ answer
83
+ );
84
+ }
85
+ if (isCalloutComponentOfBaseType(schema, CalloutComponentBaseType.CONTENT)) {
86
+ return calloutComponentContentValidator(schema, answer);
87
+ }
88
+ throw new Error("Invalid schema type");
89
+ }
76
90
  export {
91
+ calloutComponentInputValidator,
77
92
  calloutComponentNestableValidator,
78
93
  calloutComponentValidator
79
94
  };
@@ -2,5 +2,6 @@ export declare enum PaymentMethod {
2
2
  StripeCard = "s_card",
3
3
  StripeSEPA = "s_sepa",
4
4
  StripeBACS = "s_bacs",
5
+ StripePayPal = "s_paypal",
5
6
  GoCardlessDirectDebit = "gc_direct-debit"
6
7
  }
@@ -1,5 +1,8 @@
1
1
  import { ItemStatus } from "../data/index.ts";
2
2
  export declare const calloutFilters: {
3
+ readonly id: {
4
+ readonly type: "text";
5
+ };
3
6
  readonly slug: {
4
7
  readonly type: "text";
5
8
  };
@@ -33,7 +36,7 @@ export declare const calloutResponseFilters: {
33
36
  readonly type: "contact";
34
37
  readonly nullable: true;
35
38
  };
36
- readonly callout: {
39
+ readonly calloutId: {
37
40
  readonly type: "text";
38
41
  };
39
42
  readonly createdAt: {
@@ -87,7 +90,7 @@ export declare const calloutTagFilters: {
87
90
  readonly description: {
88
91
  readonly type: "text";
89
92
  };
90
- readonly calloutSlug: {
93
+ readonly calloutId: {
91
94
  readonly type: "text";
92
95
  };
93
96
  };
@@ -6,4 +6,6 @@ export interface CalloutComponentBaseInputSchema extends CalloutComponentBaseSch
6
6
  input: true;
7
7
  /** The validation rules for input forms */
8
8
  validate?: CalloutComponentBaseRules;
9
+ /** The description for the component */
10
+ description?: string;
9
11
  }
@@ -14,7 +14,7 @@ export interface CalloutComponentBaseSchema {
14
14
  /** True if multiple responses / answers allowed */
15
15
  multiple?: boolean;
16
16
  /** If defined then this is the default value */
17
- defaultValue?: CalloutResponseAnswer | CalloutResponseAnswer[];
17
+ defaultValue?: CalloutResponseAnswer | CalloutResponseAnswer[] | null;
18
18
  /** `true` if this component should be hidden */
19
19
  hidden?: boolean;
20
20
  /** Unused property */
@@ -1,5 +1,12 @@
1
1
  import type { CalloutComponentType } from "../data/index.ts";
2
2
  import type { CalloutComponentBaseSchema } from "./index.ts";
3
+ /** A Callout content component only providing html content and accepts no answers. */
3
4
  export interface CalloutComponentContentSchema extends CalloutComponentBaseSchema {
4
5
  type: CalloutComponentType.CONTENT;
6
+ /** The html content of the callout component. */
7
+ html: string;
8
+ /** The label for this field that will appear next to it. */
9
+ label: string;
10
+ /** This is always false for content components. */
11
+ input: false;
5
12
  }
@@ -4,4 +4,6 @@ export interface CalloutComponentInputAddressSchema extends CalloutComponentBase
4
4
  type: CalloutComponentType.INPUT_ADDRESS;
5
5
  /** The validation rules for the form */
6
6
  validate?: CalloutComponentInputAddressRules;
7
+ /** Placeholder for the form */
8
+ placeholder?: string;
7
9
  }
@@ -4,4 +4,6 @@ export interface CalloutComponentInputPhoneNumberSchema extends CalloutComponent
4
4
  type: CalloutComponentType.INPUT_PHONE_NUMBER;
5
5
  /** The validation rules for the form */
6
6
  validate?: CalloutComponentInputPhoneNumberRules;
7
+ /** The placeholder for the component */
8
+ placeholder?: string;
7
9
  }
@@ -12,4 +12,6 @@ export interface CalloutComponentInputSelectSchema extends CalloutComponentBaseI
12
12
  [key: string]: unknown;
13
13
  };
14
14
  validate?: CalloutComponentInputSelectRules;
15
+ /** The placeholder for the component */
16
+ placeholder?: string;
15
17
  }
@@ -1,2 +1,2 @@
1
1
  import type { CalloutResponseAnswerAddress, CalloutResponseAnswerFileUpload } from "./index.ts";
2
- export type CalloutResponseAnswer = string | boolean | number | null | undefined | Record<string, boolean> | CalloutResponseAnswerAddress | CalloutResponseAnswerFileUpload;
2
+ export type CalloutResponseAnswer = string | boolean | number | Record<string, boolean> | CalloutResponseAnswerAddress | CalloutResponseAnswerFileUpload;
@@ -1,5 +1,5 @@
1
- import type { CalloutResponseAnswersNestable } from "./index.ts";
1
+ import type { CalloutResponseAnswers } from "./index.ts";
2
2
  /**
3
3
  * Answers are grouped by slide key: `{[slideId]: {[componentKey]: answer | answer[]}}`
4
4
  */
5
- export type CalloutResponseAnswersSlide = Record<string, CalloutResponseAnswersNestable | undefined>;
5
+ export type CalloutResponseAnswersSlide = Record<string, CalloutResponseAnswers | undefined>;
@@ -0,0 +1,5 @@
1
+ import type { CalloutResponseAnswer } from "./index.ts";
2
+ /**
3
+ * Answers are grouped by component key: `{[componentKey]: answer | answer[]}`
4
+ */
5
+ export type CalloutResponseAnswers = Record<string, CalloutResponseAnswer | CalloutResponseAnswer[] | undefined>;
@@ -0,0 +1,5 @@
1
+ import type { GetCalloutSlideSchema, SetCalloutFormSchema } from "./index.ts";
2
+ export interface GetCalloutFormSchema extends SetCalloutFormSchema {
3
+ slides: GetCalloutSlideSchema[];
4
+ componentText: Record<string, string>;
5
+ }
@@ -0,0 +1,6 @@
1
+ import { SetCalloutNavigationSchema } from "../index.ts";
2
+ export interface GetCalloutNavigationSchema extends SetCalloutNavigationSchema {
3
+ prevText: string;
4
+ nextText: string;
5
+ submitText: string;
6
+ }
@@ -0,0 +1,4 @@
1
+ import { GetCalloutNavigationSchema, SetCalloutSlideSchema } from "../index.ts";
2
+ export interface GetCalloutSlideSchema extends SetCalloutSlideSchema {
3
+ navigation: GetCalloutNavigationSchema;
4
+ }
@@ -51,16 +51,13 @@ export * from "./callout-component-nestable-tabs-schema.ts";
51
51
  export * from "./callout-component-nestable-well-schema.ts";
52
52
  export * from "./callout-component-schema.ts";
53
53
  export * from "./callout-filter-name.ts";
54
- export * from "./callout-form-schema.ts";
55
- export * from "./callout-navigation-schema.ts";
56
54
  export * from "./callout-response-answer-address.ts";
57
55
  export * from "./callout-response-answer-file-upload.ts";
58
56
  export * from "./callout-response-answer.ts";
59
- export * from "./callout-response-answers-nestable.ts";
60
57
  export * from "./callout-response-answers-slide.ts";
58
+ export * from "./callout-response-answers.ts";
61
59
  export * from "./callout-response-comment-filter-name.ts";
62
60
  export * from "./callout-response-filter-name.ts";
63
- export * from "./callout-slide-schema.ts";
64
61
  export * from "./callout-tag-filter-name.ts";
65
62
  export * from "./date-unit.ts";
66
63
  export * from "./duration.ts";
@@ -69,6 +66,9 @@ export * from "./feeable.ts";
69
66
  export * from "./filter-args.ts";
70
67
  export * from "./filter-type.ts";
71
68
  export * from "./filters.ts";
69
+ export * from "./get-callout-form-schema.ts";
70
+ export * from "./get-callout-navigation-schema.ts";
71
+ export * from "./get-callout-slide-schema.ts";
72
72
  export * from "./notice-filter-name.ts";
73
73
  export * from "./operators-by-type.ts";
74
74
  export * from "./other-filter-args.ts";
@@ -82,6 +82,9 @@ export * from "./rule-opperator-params.ts";
82
82
  export * from "./rule-value.ts";
83
83
  export * from "./rule.ts";
84
84
  export * from "./segment-filter-name.ts";
85
+ export * from "./set-callout-form-schema.ts";
86
+ export * from "./set-callout-navigation-schema.ts";
87
+ export * from "./set-callout-slide-schema.ts";
85
88
  export * from "./stripe-fee-country.ts";
86
89
  export * from "./text-case.ts";
87
90
  export * from "./unit-matches.ts";
@@ -0,0 +1,4 @@
1
+ import { SetCalloutSlideSchema } from "../index.ts";
2
+ export interface SetCalloutFormSchema {
3
+ slides: SetCalloutSlideSchema[];
4
+ }
@@ -0,0 +1,3 @@
1
+ export interface SetCalloutNavigationSchema {
2
+ nextSlideId: string;
3
+ }
@@ -0,0 +1,7 @@
1
+ import { CalloutComponentSchema, SetCalloutNavigationSchema } from "./index.ts";
2
+ export interface SetCalloutSlideSchema {
3
+ id: string;
4
+ title: string;
5
+ components: CalloutComponentSchema[];
6
+ navigation: SetCalloutNavigationSchema;
7
+ }
@@ -1,2 +1,2 @@
1
- import type { CalloutComponentBaseSchema } from "./index.ts";
2
- export type ValidatorCalloutComponent<S extends CalloutComponentBaseSchema> = (schema: S, answer: any) => boolean;
1
+ import type { CalloutComponentBaseSchema, CalloutResponseAnswer } from "./index.ts";
2
+ export type ValidatorCalloutComponent<S extends CalloutComponentBaseSchema, A = CalloutResponseAnswer> = (schema: S, answer: A) => boolean;
@@ -1,5 +1,5 @@
1
1
  import { CalloutComponentBaseType, CalloutComponentType } from "../data/index.ts";
2
- import type { CalloutComponentBaseMap, CalloutComponentBaseSchema, CalloutComponentMap, CalloutComponentSchema, CalloutFormSchema, CalloutResponseAnswer, CalloutResponseAnswerAddress, CalloutResponseAnswerFileUpload, FilterArgs } from "../types/index.ts";
2
+ import type { CalloutComponentBaseMap, CalloutComponentBaseSchema, CalloutComponentMap, CalloutComponentSchema, CalloutResponseAnswer, CalloutResponseAnswerAddress, CalloutResponseAnswerFileUpload, FilterArgs, SetCalloutFormSchema } from "../types/index.ts";
3
3
  /**
4
4
  * Check if a component is a specific component type
5
5
  *
@@ -18,13 +18,13 @@ export declare function isCalloutComponentOfType<T extends CalloutComponentType>
18
18
  export declare function isCalloutComponentOfBaseType<T extends CalloutComponentBaseType>(component: CalloutComponentBaseSchema, type: T): component is CalloutComponentBaseMap[T];
19
19
  export declare function flattenComponents(components: CalloutComponentSchema[]): CalloutComponentSchema[];
20
20
  export declare function filterComponents(components: CalloutComponentSchema[], filterFn: (component: CalloutComponentSchema) => boolean): CalloutComponentSchema[];
21
- export declare function getCalloutComponents(formSchema: CalloutFormSchema): (CalloutComponentSchema & {
21
+ export declare function getCalloutComponents(formSchema: SetCalloutFormSchema): (CalloutComponentSchema & {
22
22
  slideId: string;
23
23
  fullKey: string;
24
24
  })[];
25
- export declare function getCalloutFilters(formSchema: CalloutFormSchema): Record<string, FilterArgs & {
25
+ export declare function getCalloutFilters(formSchema: SetCalloutFormSchema): Record<string, FilterArgs & {
26
26
  label: string;
27
27
  }>;
28
28
  export declare function isAddressAnswer(answer: CalloutResponseAnswer): answer is CalloutResponseAnswerAddress;
29
- export declare function isFileUploadAnswer(answer: CalloutResponseAnswer): answer is CalloutResponseAnswerFileUpload;
30
- export declare function stringifyAnswer(component: CalloutComponentSchema, answer: CalloutResponseAnswer | CalloutResponseAnswer[]): string;
29
+ export declare function isFileUploadAnswer(answer: CalloutResponseAnswer | undefined): answer is CalloutResponseAnswerFileUpload;
30
+ export declare function stringifyAnswer(component: CalloutComponentSchema, answer: CalloutResponseAnswer | CalloutResponseAnswer[] | undefined): string;
@@ -1,2 +1,2 @@
1
1
  import type { CalloutComponentContentSchema, ValidatorCalloutComponent } from "../types/index.ts";
2
- export declare const calloutComponentContentValidator: ValidatorCalloutComponent<CalloutComponentContentSchema>;
2
+ export declare const calloutComponentContentValidator: ValidatorCalloutComponent<CalloutComponentContentSchema, unknown>;
@@ -1,3 +1,5 @@
1
- import type { CalloutComponentNestableSchema, CalloutComponentSchema, CalloutResponseAnswer, CalloutResponseAnswersNestable, ValidatorCalloutComponent } from "../types/index.ts";
2
- export declare const calloutComponentNestableValidator: ValidatorCalloutComponent<CalloutComponentNestableSchema>;
3
- export declare const calloutComponentValidator: (schema: CalloutComponentSchema, answer: CalloutResponseAnswer | CalloutResponseAnswersNestable) => boolean;
1
+ import type { CalloutComponentInputSchema, CalloutComponentNestableSchema, CalloutComponentSchema, CalloutResponseAnswer, CalloutResponseAnswers } from "../types/index.ts";
2
+ export declare const calloutComponentNestableValidator: (schema: CalloutComponentNestableSchema, answers: CalloutResponseAnswers) => boolean;
3
+ export declare function calloutComponentInputValidator(schema: CalloutComponentInputSchema, answer: CalloutResponseAnswer | CalloutResponseAnswer[] | undefined): boolean;
4
+ export declare function calloutComponentValidator(schema: CalloutComponentSchema, answer: CalloutResponseAnswer | CalloutResponseAnswer[] | undefined): boolean;
5
+ export declare function calloutComponentValidator(schema: CalloutComponentNestableSchema, answer: CalloutResponseAnswers): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beabee/beabee-common",
3
- "version": "0.20.1",
3
+ "version": "0.20.2-alpha.1",
4
4
  "description": "Shared code between Beabee projects for Node.js, Deno and the browser",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.cjs",
@@ -29,7 +29,9 @@
29
29
  "test": "deno task test",
30
30
  "test:deno": "deno task test:deno",
31
31
  "test:node": "deno task test:node",
32
- "test:types": "tsc --noEmit --emitDeclarationOnly false",
32
+ "test:types": "deno task test:types",
33
+ "test:deno:types": "deno task test:deno:types",
34
+ "test:node:types": "tsc --noEmit --emitDeclarationOnly false",
33
35
  "test:node:esm": "node test/node/import.mjs",
34
36
  "test:node:cjs": "node test/node/require.cjs",
35
37
  "build": "deno task build",
@@ -39,7 +41,13 @@
39
41
  "build:types": "tsc && echo 'export * from \"./index.ts\";' > dist/types/index.d.cts",
40
42
  "generate:index": "deno task generate:index",
41
43
  "sync": "deno task sync",
42
- "prepublishOnly": "npm run build"
44
+ "prepublishOnly": "npm run build",
45
+ "cache": "deno task cache",
46
+ "cache:deno": "deno task cache:deno",
47
+ "cache:node": "deno task cache:node",
48
+ "check": "deno task check",
49
+ "check:format": "deno task check:format",
50
+ "check:types": "deno task check:types"
43
51
  },
44
52
  "repository": {
45
53
  "type": "git",
@@ -56,6 +64,6 @@
56
64
  "typescript": "^5.3.3"
57
65
  },
58
66
  "dependencies": {
59
- "date-fns": "^3.2.0"
67
+ "date-fns": "^3.3.1"
60
68
  }
61
69
  }
@@ -1,4 +0,0 @@
1
- import type { CalloutSlideSchema } from "./index.ts";
2
- export interface CalloutFormSchema {
3
- slides: CalloutSlideSchema[];
4
- }
@@ -1,6 +0,0 @@
1
- export interface CalloutNavigationSchema {
2
- prevText: string;
3
- nextText: string;
4
- nextSlideId: string;
5
- submitText: string;
6
- }
@@ -1,5 +0,0 @@
1
- import type { CalloutResponseAnswer } from "./index.ts";
2
- /**
3
- * Answers are grouped by nestable component key: `{[slideId]: {[componentKey]: answer | answer[]}}`
4
- */
5
- export type CalloutResponseAnswersNestable = Record<string, CalloutResponseAnswer | CalloutResponseAnswer[]>;
@@ -1,7 +0,0 @@
1
- import type { CalloutComponentSchema, CalloutNavigationSchema } from "./index.ts";
2
- export interface CalloutSlideSchema {
3
- id: string;
4
- title: string;
5
- components: CalloutComponentSchema[];
6
- navigation: CalloutNavigationSchema;
7
- }