@beabee/beabee-common 1.10.9 → 1.10.10

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.
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +1,18 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
17
  exports.RoleTypes = exports.PaymentStatus = exports.PaymentMethod = exports.NewsletterStatus = exports.MembershipStatus = exports.ItemStatus = exports.ContributionType = exports.ContributionPeriod = void 0;
4
18
  var ContributionPeriod;
@@ -50,3 +64,4 @@ var PaymentStatus;
50
64
  PaymentStatus["Cancelled"] = "cancelled";
51
65
  })(PaymentStatus = exports.PaymentStatus || (exports.PaymentStatus = {}));
52
66
  exports.RoleTypes = ["member", "admin", "superadmin"];
67
+ __exportStar(require("./callouts"), exports);
package/dist/cjs/index.js CHANGED
@@ -17,5 +17,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./search"), exports);
18
18
  __exportStar(require("./data"), exports);
19
19
  __exportStar(require("./error"), exports);
20
+ __exportStar(require("./utils/callouts"), exports);
20
21
  __exportStar(require("./utils/date"), exports);
21
22
  __exportStar(require("./utils/rules"), exports);
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertComponentsToFilters = exports.flattenComponents = void 0;
4
+ function flattenComponents(components) {
5
+ return components.flatMap((component) => [
6
+ component,
7
+ ...flattenComponents(component.components || []),
8
+ ]);
9
+ }
10
+ exports.flattenComponents = flattenComponents;
11
+ function convertValuesToOptions(values) {
12
+ return values.map(({ value, label }) => value);
13
+ }
14
+ function convertComponentToFilter(component) {
15
+ const baseItem = {
16
+ // label: component.label || component.key,
17
+ nullable: true,
18
+ };
19
+ switch (component.type) {
20
+ case "checkbox":
21
+ return { ...baseItem, type: "boolean", nullable: false };
22
+ case "number":
23
+ return { ...baseItem, type: "number" };
24
+ case "select":
25
+ return {
26
+ ...baseItem,
27
+ type: "enum",
28
+ options: convertValuesToOptions(component.data.values),
29
+ };
30
+ case "selectboxes":
31
+ case "radio":
32
+ return {
33
+ ...baseItem,
34
+ type: component.type === "radio" ? "enum" : "array",
35
+ options: convertValuesToOptions(component.values),
36
+ };
37
+ default:
38
+ return { ...baseItem, type: "text" };
39
+ }
40
+ }
41
+ function convertComponentsToFilters(components) {
42
+ const items = components.map((c) => {
43
+ return [`answers.${c.key}`, convertComponentToFilter(c)];
44
+ });
45
+ return Object.fromEntries(items);
46
+ }
47
+ exports.convertComponentsToFilters = convertComponentsToFilters;
@@ -0,0 +1 @@
1
+ export {};
@@ -47,3 +47,4 @@ export var PaymentStatus;
47
47
  PaymentStatus["Cancelled"] = "cancelled";
48
48
  })(PaymentStatus || (PaymentStatus = {}));
49
49
  export const RoleTypes = ["member", "admin", "superadmin"];
50
+ export * from "./callouts";
package/dist/esm/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from "./search";
2
2
  export * from "./data";
3
3
  export * from "./error";
4
+ export * from "./utils/callouts";
4
5
  export * from "./utils/date";
5
6
  export * from "./utils/rules";
@@ -0,0 +1,42 @@
1
+ export function flattenComponents(components) {
2
+ return components.flatMap((component) => [
3
+ component,
4
+ ...flattenComponents(component.components || []),
5
+ ]);
6
+ }
7
+ function convertValuesToOptions(values) {
8
+ return values.map(({ value, label }) => value);
9
+ }
10
+ function convertComponentToFilter(component) {
11
+ const baseItem = {
12
+ // label: component.label || component.key,
13
+ nullable: true,
14
+ };
15
+ switch (component.type) {
16
+ case "checkbox":
17
+ return { ...baseItem, type: "boolean", nullable: false };
18
+ case "number":
19
+ return { ...baseItem, type: "number" };
20
+ case "select":
21
+ return {
22
+ ...baseItem,
23
+ type: "enum",
24
+ options: convertValuesToOptions(component.data.values),
25
+ };
26
+ case "selectboxes":
27
+ case "radio":
28
+ return {
29
+ ...baseItem,
30
+ type: component.type === "radio" ? "enum" : "array",
31
+ options: convertValuesToOptions(component.values),
32
+ };
33
+ default:
34
+ return { ...baseItem, type: "text" };
35
+ }
36
+ }
37
+ export function convertComponentsToFilters(components) {
38
+ const items = components.map((c) => {
39
+ return [`answers.${c.key}`, convertComponentToFilter(c)];
40
+ });
41
+ return Object.fromEntries(items);
42
+ }
@@ -0,0 +1,31 @@
1
+ interface BaseCalloutComponentSchema {
2
+ key: string;
3
+ label?: string;
4
+ input?: boolean;
5
+ components?: CalloutComponentSchema[];
6
+ [key: string]: unknown;
7
+ }
8
+ interface OtherCalloutComponentSchema extends BaseCalloutComponentSchema {
9
+ type: "button" | "checkbox" | "number" | "password" | "textfield" | "textarea";
10
+ }
11
+ interface SelectCalloutComponentSchema extends BaseCalloutComponentSchema {
12
+ type: "select";
13
+ data: {
14
+ values: {
15
+ label: string;
16
+ value: string;
17
+ }[];
18
+ };
19
+ }
20
+ interface RadioCalloutComponentSchema extends BaseCalloutComponentSchema {
21
+ type: "radio" | "selectboxes";
22
+ values: {
23
+ label: string;
24
+ value: string;
25
+ }[];
26
+ }
27
+ export type CalloutComponentSchema = SelectCalloutComponentSchema | RadioCalloutComponentSchema | OtherCalloutComponentSchema;
28
+ export interface CalloutFormSchema {
29
+ components: CalloutComponentSchema[];
30
+ }
31
+ export {};
@@ -41,3 +41,4 @@ export declare enum PaymentStatus {
41
41
  }
42
42
  export declare const RoleTypes: readonly ["member", "admin", "superadmin"];
43
43
  export type RoleType = (typeof RoleTypes)[number];
44
+ export * from "./callouts";
@@ -1,5 +1,6 @@
1
1
  export * from "./search";
2
2
  export * from "./data";
3
3
  export * from "./error";
4
+ export * from "./utils/callouts";
4
5
  export * from "./utils/date";
5
6
  export * from "./utils/rules";
@@ -0,0 +1,4 @@
1
+ import { CalloutComponentSchema } from "../data/callouts";
2
+ import { Filters } from "../search";
3
+ export declare function flattenComponents(components: CalloutComponentSchema[]): CalloutComponentSchema[];
4
+ export declare function convertComponentsToFilters(components: CalloutComponentSchema[]): Filters;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beabee/beabee-common",
3
- "version": "1.10.9",
3
+ "version": "1.10.10",
4
4
  "description": "",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",