@beabee/beabee-common 1.10.9 → 1.10.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/data/callouts.js +2 -0
- package/dist/cjs/data/index.js +15 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/search/callouts.js +0 -4
- package/dist/cjs/search/index.js +6 -6
- package/dist/cjs/utils/callouts.js +47 -0
- package/dist/cjs/utils/rules.js +9 -9
- package/dist/esm/data/callouts.js +1 -0
- package/dist/esm/data/index.js +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/search/callouts.js +0 -4
- package/dist/esm/search/index.js +6 -6
- package/dist/esm/utils/callouts.js +42 -0
- package/dist/esm/utils/rules.js +9 -9
- package/dist/types/data/callouts.d.ts +31 -0
- package/dist/types/data/index.d.ts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/search/callouts.d.ts +0 -4
- package/dist/types/search/index.d.ts +1 -46
- package/dist/types/utils/callouts.d.ts +4 -0
- package/package.json +1 -1
package/dist/cjs/data/index.js
CHANGED
|
@@ -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);
|
package/dist/cjs/search/index.js
CHANGED
|
@@ -70,12 +70,12 @@ exports.operatorsByType = {
|
|
|
70
70
|
array: arrayOperators,
|
|
71
71
|
enum: equalityOperators,
|
|
72
72
|
contact: equalityOperators,
|
|
73
|
-
custom: {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
},
|
|
73
|
+
// custom: {
|
|
74
|
+
// ...equalityOperators,
|
|
75
|
+
// ...arrayOperators,
|
|
76
|
+
// ...stringOperators,
|
|
77
|
+
// ...numericOperators,
|
|
78
|
+
// },
|
|
79
79
|
};
|
|
80
80
|
// More general type to allow mapping while maintaining full type above
|
|
81
81
|
exports.operatorsByTypeMap = exports.operatorsByType;
|
|
@@ -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;
|
package/dist/cjs/utils/rules.js
CHANGED
|
@@ -9,8 +9,7 @@ function isRuleGroup(ruleOrGroup) {
|
|
|
9
9
|
}
|
|
10
10
|
exports.isRuleGroup = isRuleGroup;
|
|
11
11
|
function validateRule(filters, rule) {
|
|
12
|
-
const
|
|
13
|
-
const filter = filters[fieldName];
|
|
12
|
+
const filter = filters[rule.field];
|
|
14
13
|
if (!filter) {
|
|
15
14
|
throw new error_1.InvalidRule(rule, `Invalid field: ${rule.field}`);
|
|
16
15
|
}
|
|
@@ -31,11 +30,12 @@ function validateRule(filters, rule) {
|
|
|
31
30
|
if (expectedArgs !== rule.value.length) {
|
|
32
31
|
throw new error_1.InvalidRule(rule, `Invalid operator argument count: ${rule.operator} needs ${expectedArgs}, ${rule.value.length} given`);
|
|
33
32
|
}
|
|
34
|
-
const expectedType =
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
33
|
+
const expectedType =
|
|
34
|
+
// filter.type === "custom"
|
|
35
|
+
// ? typeof rule.value[0] :
|
|
36
|
+
filter.type === "boolean" || filter.type === "number"
|
|
37
|
+
? filter.type
|
|
38
|
+
: "string";
|
|
39
39
|
if (rule.value.some((v) => typeof v !== expectedType)) {
|
|
40
40
|
throw new error_1.InvalidRule(rule, `Invalid operator argument type: ${rule.operator} needs ${expectedType}, ${rule.value.map((v) => typeof v)} given`);
|
|
41
41
|
}
|
|
@@ -48,8 +48,8 @@ function validateRule(filters, rule) {
|
|
|
48
48
|
throw new error_1.InvalidRule(rule, `Invalid operator argument: ${filter.type} type expected ${filter.options}, ${rule.value} given`);
|
|
49
49
|
}
|
|
50
50
|
return {
|
|
51
|
-
field:
|
|
52
|
-
param: fieldParam,
|
|
51
|
+
field: rule.field,
|
|
52
|
+
// param: fieldParam,
|
|
53
53
|
type: filter.type,
|
|
54
54
|
operator: rule.operator,
|
|
55
55
|
value: rule.value,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/esm/data/index.js
CHANGED
package/dist/esm/index.js
CHANGED
package/dist/esm/search/index.js
CHANGED
|
@@ -53,12 +53,12 @@ export const operatorsByType = {
|
|
|
53
53
|
array: arrayOperators,
|
|
54
54
|
enum: equalityOperators,
|
|
55
55
|
contact: equalityOperators,
|
|
56
|
-
custom: {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
},
|
|
56
|
+
// custom: {
|
|
57
|
+
// ...equalityOperators,
|
|
58
|
+
// ...arrayOperators,
|
|
59
|
+
// ...stringOperators,
|
|
60
|
+
// ...numericOperators,
|
|
61
|
+
// },
|
|
62
62
|
};
|
|
63
63
|
// More general type to allow mapping while maintaining full type above
|
|
64
64
|
export const operatorsByTypeMap = operatorsByType;
|
|
@@ -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
|
+
}
|
package/dist/esm/utils/rules.js
CHANGED
|
@@ -5,8 +5,7 @@ export function isRuleGroup(ruleOrGroup) {
|
|
|
5
5
|
return "condition" in ruleOrGroup;
|
|
6
6
|
}
|
|
7
7
|
export function validateRule(filters, rule) {
|
|
8
|
-
const
|
|
9
|
-
const filter = filters[fieldName];
|
|
8
|
+
const filter = filters[rule.field];
|
|
10
9
|
if (!filter) {
|
|
11
10
|
throw new InvalidRule(rule, `Invalid field: ${rule.field}`);
|
|
12
11
|
}
|
|
@@ -27,11 +26,12 @@ export function validateRule(filters, rule) {
|
|
|
27
26
|
if (expectedArgs !== rule.value.length) {
|
|
28
27
|
throw new InvalidRule(rule, `Invalid operator argument count: ${rule.operator} needs ${expectedArgs}, ${rule.value.length} given`);
|
|
29
28
|
}
|
|
30
|
-
const expectedType =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
const expectedType =
|
|
30
|
+
// filter.type === "custom"
|
|
31
|
+
// ? typeof rule.value[0] :
|
|
32
|
+
filter.type === "boolean" || filter.type === "number"
|
|
33
|
+
? filter.type
|
|
34
|
+
: "string";
|
|
35
35
|
if (rule.value.some((v) => typeof v !== expectedType)) {
|
|
36
36
|
throw new InvalidRule(rule, `Invalid operator argument type: ${rule.operator} needs ${expectedType}, ${rule.value.map((v) => typeof v)} given`);
|
|
37
37
|
}
|
|
@@ -44,8 +44,8 @@ export function validateRule(filters, rule) {
|
|
|
44
44
|
throw new InvalidRule(rule, `Invalid operator argument: ${filter.type} type expected ${filter.options}, ${rule.value} given`);
|
|
45
45
|
}
|
|
46
46
|
return {
|
|
47
|
-
field:
|
|
48
|
-
param: fieldParam,
|
|
47
|
+
field: rule.field,
|
|
48
|
+
// param: fieldParam,
|
|
49
49
|
type: filter.type,
|
|
50
50
|
operator: rule.operator,
|
|
51
51
|
value: rule.value,
|
|
@@ -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 {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -35,9 +35,5 @@ export declare const calloutResponseFilters: {
|
|
|
35
35
|
readonly updatedAt: {
|
|
36
36
|
readonly type: "date";
|
|
37
37
|
};
|
|
38
|
-
readonly answers: {
|
|
39
|
-
readonly type: "custom";
|
|
40
|
-
readonly nullable: true;
|
|
41
|
-
};
|
|
42
38
|
};
|
|
43
39
|
export type CalloutResponseFilterName = keyof typeof calloutResponseFilters;
|
|
@@ -14,7 +14,6 @@ export type ValidatedRuleValue<T extends FilterType> = T extends "number" ? numb
|
|
|
14
14
|
interface BaseValidatedRule<T extends FilterType, F extends string> {
|
|
15
15
|
type: T;
|
|
16
16
|
field: F;
|
|
17
|
-
param: string | undefined;
|
|
18
17
|
operator: keyof (typeof operatorsByType)[T];
|
|
19
18
|
value: ValidatedRuleValue<T>[];
|
|
20
19
|
}
|
|
@@ -26,7 +25,7 @@ export interface ValidatedRuleGroup<Field extends string> {
|
|
|
26
25
|
condition: "AND" | "OR";
|
|
27
26
|
rules: (ValidatedRuleGroup<Field> | ValidatedRule<Field>)[];
|
|
28
27
|
}
|
|
29
|
-
export type FilterType = "text" | "date" | "number" | "boolean" | "array" | "enum" | "contact"
|
|
28
|
+
export type FilterType = "text" | "date" | "number" | "boolean" | "array" | "enum" | "contact";
|
|
30
29
|
interface BaseFilterArgs {
|
|
31
30
|
type: FilterType;
|
|
32
31
|
nullable?: boolean;
|
|
@@ -164,50 +163,6 @@ export declare const operatorsByType: {
|
|
|
164
163
|
args: number;
|
|
165
164
|
};
|
|
166
165
|
};
|
|
167
|
-
readonly custom: {
|
|
168
|
-
readonly between: {
|
|
169
|
-
args: number;
|
|
170
|
-
};
|
|
171
|
-
readonly not_between: {
|
|
172
|
-
args: number;
|
|
173
|
-
};
|
|
174
|
-
readonly less: {
|
|
175
|
-
args: number;
|
|
176
|
-
};
|
|
177
|
-
readonly greater: {
|
|
178
|
-
args: number;
|
|
179
|
-
};
|
|
180
|
-
readonly less_or_equal: {
|
|
181
|
-
args: number;
|
|
182
|
-
};
|
|
183
|
-
readonly greater_or_equal: {
|
|
184
|
-
args: number;
|
|
185
|
-
};
|
|
186
|
-
readonly equal: {
|
|
187
|
-
args: number;
|
|
188
|
-
};
|
|
189
|
-
readonly not_equal: {
|
|
190
|
-
args: number;
|
|
191
|
-
};
|
|
192
|
-
readonly begins_with: {
|
|
193
|
-
args: number;
|
|
194
|
-
};
|
|
195
|
-
readonly ends_with: {
|
|
196
|
-
args: number;
|
|
197
|
-
};
|
|
198
|
-
readonly not_begins_with: {
|
|
199
|
-
args: number;
|
|
200
|
-
};
|
|
201
|
-
readonly not_ends_with: {
|
|
202
|
-
args: number;
|
|
203
|
-
};
|
|
204
|
-
readonly contains: {
|
|
205
|
-
args: number;
|
|
206
|
-
};
|
|
207
|
-
readonly not_contains: {
|
|
208
|
-
args: number;
|
|
209
|
-
};
|
|
210
|
-
};
|
|
211
166
|
};
|
|
212
167
|
export declare const operatorsByTypeMap: OperatorsByType;
|
|
213
168
|
export interface Paginated<T> {
|
|
@@ -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;
|