@beinformed/ui 1.27.0 → 1.27.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.
- package/CHANGELOG.md +12 -0
- package/esm/models/attributes/AttributeDataHelper.js +2 -2
- package/esm/models/attributes/AttributeDataHelper.js.map +1 -1
- package/esm/models/attributes/CaptchaAttributeModel.js +19 -0
- package/esm/models/attributes/CaptchaAttributeModel.js.map +1 -1
- package/esm/models/attributes/_createAttribute.js +2 -2
- package/esm/models/attributes/_createAttribute.js.map +1 -1
- package/esm/models/base/BaseCollection.js +3 -9
- package/esm/models/base/BaseCollection.js.map +1 -1
- package/esm/models/base/BaseModel.js +2 -8
- package/esm/models/base/BaseModel.js.map +1 -1
- package/esm/modularui/CaptchaRequest.js +25 -8
- package/esm/modularui/CaptchaRequest.js.map +1 -1
- package/esm/redux/actions/FormValidations.js +1 -1
- package/esm/redux/actions/FormValidations.js.map +1 -1
- package/lib/models/attributes/AttributeDataHelper.js +2 -2
- package/lib/models/attributes/AttributeDataHelper.js.flow +2 -2
- package/lib/models/attributes/AttributeDataHelper.js.map +1 -1
- package/lib/models/attributes/CaptchaAttributeModel.js +19 -0
- package/lib/models/attributes/CaptchaAttributeModel.js.flow +16 -0
- package/lib/models/attributes/CaptchaAttributeModel.js.map +1 -1
- package/lib/models/attributes/__tests__/ChoiceAttributeModel.spec.js.flow +3 -0
- package/lib/models/attributes/__tests__/CompositeAttributeModel.spec.js.flow +3 -0
- package/lib/models/attributes/_createAttribute.js +2 -2
- package/lib/models/attributes/_createAttribute.js.flow +2 -2
- package/lib/models/attributes/_createAttribute.js.map +1 -1
- package/lib/models/base/BaseCollection.js +3 -9
- package/lib/models/base/BaseCollection.js.flow +4 -10
- package/lib/models/base/BaseCollection.js.map +1 -1
- package/lib/models/base/BaseModel.js +2 -8
- package/lib/models/base/BaseModel.js.flow +3 -9
- package/lib/models/base/BaseModel.js.map +1 -1
- package/lib/models/base/__tests__/BaseModel.spec.js.flow +3 -7
- package/lib/modularui/CaptchaRequest.js +25 -8
- package/lib/modularui/CaptchaRequest.js.flow +51 -10
- package/lib/modularui/CaptchaRequest.js.map +1 -1
- package/lib/redux/actions/FormValidations.js +1 -1
- package/lib/redux/actions/FormValidations.js.flow +1 -1
- package/lib/redux/actions/FormValidations.js.map +1 -1
- package/package.json +13 -12
- package/src/models/attributes/AttributeDataHelper.js +2 -2
- package/src/models/attributes/CaptchaAttributeModel.js +16 -0
- package/src/models/attributes/__tests__/ChoiceAttributeModel.spec.js +3 -0
- package/src/models/attributes/__tests__/CompositeAttributeModel.spec.js +3 -0
- package/src/models/attributes/_createAttribute.js +2 -2
- package/src/models/base/BaseCollection.js +4 -10
- package/src/models/base/BaseModel.js +3 -9
- package/src/models/base/__tests__/BaseModel.spec.js +3 -7
- package/src/modularui/CaptchaRequest.js +51 -10
- package/src/redux/actions/FormValidations.js +1 -1
- package/types/models/attributes/CaptchaAttributeModel.d.ts +9 -0
- package/types/models/base/BaseCollection.d.ts +2 -2
- package/types/models/base/BaseModel.d.ts +1 -1
- package/types/modularui/CaptchaRequest.d.ts +29 -1
|
@@ -5,6 +5,8 @@ import AttributeModel from "./AttributeModel";
|
|
|
5
5
|
* Password attribute
|
|
6
6
|
*/
|
|
7
7
|
export default class CaptchaAttributeModel extends AttributeModel {
|
|
8
|
+
_answer: string = "";
|
|
9
|
+
|
|
8
10
|
/**
|
|
9
11
|
*/
|
|
10
12
|
static isApplicableModel(contributions: Object): boolean {
|
|
@@ -27,6 +29,20 @@ export default class CaptchaAttributeModel extends AttributeModel {
|
|
|
27
29
|
return this;
|
|
28
30
|
}
|
|
29
31
|
|
|
32
|
+
/**
|
|
33
|
+
*/
|
|
34
|
+
setAnswer(answer: string) {
|
|
35
|
+
this._answer = answer;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Retrieve the given answer for the captcha
|
|
40
|
+
* The value of this attribute is the token id of the captcha
|
|
41
|
+
*/
|
|
42
|
+
getAnswer(): string {
|
|
43
|
+
return this._answer;
|
|
44
|
+
}
|
|
45
|
+
|
|
30
46
|
/**
|
|
31
47
|
*/
|
|
32
48
|
get hasDynamicValidationData(): boolean {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CaptchaAttributeModel.js","names":["CaptchaAttributeModel","AttributeModel","isApplicableModel","contributions","type","update","value","updateLastModification","inputvalue","hasDynamicValidationData"],"sources":["../../../src/models/attributes/CaptchaAttributeModel.js"],"sourcesContent":["// @flow\nimport AttributeModel from \"./AttributeModel\";\n\n/**\n * Password attribute\n */\nexport default class CaptchaAttributeModel extends AttributeModel {\n /**\n */\n static isApplicableModel(contributions: Object): boolean {\n return contributions.type === \"captcha\";\n }\n\n /**\n */\n get type(): string {\n return \"captcha\";\n }\n\n /**\n * Update the attribute by name and value\n */\n update(value: string): this {\n this.updateLastModification();\n this.inputvalue = value;\n\n return this;\n }\n\n /**\n */\n get hasDynamicValidationData(): boolean {\n return false;\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"CaptchaAttributeModel.js","names":["CaptchaAttributeModel","AttributeModel","isApplicableModel","contributions","type","update","value","updateLastModification","inputvalue","setAnswer","answer","_answer","getAnswer","hasDynamicValidationData"],"sources":["../../../src/models/attributes/CaptchaAttributeModel.js"],"sourcesContent":["// @flow\nimport AttributeModel from \"./AttributeModel\";\n\n/**\n * Password attribute\n */\nexport default class CaptchaAttributeModel extends AttributeModel {\n _answer: string = \"\";\n\n /**\n */\n static isApplicableModel(contributions: Object): boolean {\n return contributions.type === \"captcha\";\n }\n\n /**\n */\n get type(): string {\n return \"captcha\";\n }\n\n /**\n * Update the attribute by name and value\n */\n update(value: string): this {\n this.updateLastModification();\n this.inputvalue = value;\n\n return this;\n }\n\n /**\n */\n setAnswer(answer: string) {\n this._answer = answer;\n }\n\n /**\n * Retrieve the given answer for the captcha\n * The value of this attribute is the token id of the captcha\n */\n getAnswer(): string {\n return this._answer;\n }\n\n /**\n */\n get hasDynamicValidationData(): boolean {\n return false;\n }\n}\n"],"mappings":";;;;;;;;AACA;AAEA;AACA;AACA;AACe,MAAMA,qBAAqB,SAASC,uBAAc,CAAC;EAAA;IAAA;IAAA,+CAC9C,EAAE;EAAA;EAEpB;AACF;EACE,OAAOC,iBAAiB,CAACC,aAAqB,EAAW;IACvD,OAAOA,aAAa,CAACC,IAAI,KAAK,SAAS;EACzC;;EAEA;AACF;EACE,IAAIA,IAAI,GAAW;IACjB,OAAO,SAAS;EAClB;;EAEA;AACF;AACA;EACEC,MAAM,CAACC,KAAa,EAAQ;IAC1B,IAAI,CAACC,sBAAsB,EAAE;IAC7B,IAAI,CAACC,UAAU,GAAGF,KAAK;IAEvB,OAAO,IAAI;EACb;;EAEA;AACF;EACEG,SAAS,CAACC,MAAc,EAAE;IACxB,IAAI,CAACC,OAAO,GAAGD,MAAM;EACvB;;EAEA;AACF;AACA;AACA;EACEE,SAAS,GAAW;IAClB,OAAO,IAAI,CAACD,OAAO;EACrB;;EAEA;AACF;EACE,IAAIE,wBAAwB,GAAY;IACtC,OAAO,KAAK;EACd;AACF;AAAC"}
|
|
@@ -130,6 +130,9 @@ describe("choiceAttributeModel", () => {
|
|
|
130
130
|
expect(attribute.format).toBeNull();
|
|
131
131
|
|
|
132
132
|
expect(attribute.options).toHaveLength(4);
|
|
133
|
+
|
|
134
|
+
const clonedAttribute = attribute.clone();
|
|
135
|
+
expect(clonedAttribute).toStrictEqual(attribute);
|
|
133
136
|
});
|
|
134
137
|
|
|
135
138
|
it("handles sort-options hint", () => {
|
|
@@ -202,6 +202,9 @@ describe("compositeAttributeModel", () => {
|
|
|
202
202
|
PrintingHouse: "Printers united",
|
|
203
203
|
Title: "Matilda",
|
|
204
204
|
});
|
|
205
|
+
|
|
206
|
+
const clonedAttribute = attribute.clone();
|
|
207
|
+
expect(clonedAttribute).toStrictEqual(attribute);
|
|
205
208
|
});
|
|
206
209
|
|
|
207
210
|
it("creates a composite attribute for a choice attribute with a table codemap on a list, multiple choice", () => {
|
|
@@ -8,7 +8,7 @@ exports.default = void 0;
|
|
|
8
8
|
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
|
|
9
9
|
var _keys = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/keys"));
|
|
10
10
|
var _find = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/find"));
|
|
11
|
-
var
|
|
11
|
+
var _full = require("klona/full");
|
|
12
12
|
var _objects = require("../../utils/helpers/objects");
|
|
13
13
|
var _LayoutHintRuleCollection = _interopRequireDefault(require("./layouthint-rules/LayoutHintRuleCollection"));
|
|
14
14
|
var _CaptchaAttributeModel = _interopRequireDefault(require("./CaptchaAttributeModel"));
|
|
@@ -67,7 +67,7 @@ const updateContributions = (key, data, contributions) => {
|
|
|
67
67
|
* @private
|
|
68
68
|
*/
|
|
69
69
|
const updateData = (key, data, contributions) => {
|
|
70
|
-
const newData = (0,
|
|
70
|
+
const newData = (0, _full.klona)(data);
|
|
71
71
|
if (contributions.dynamicschemaId) {
|
|
72
72
|
newData.dynamicschemaId = contributions.dynamicschemaId;
|
|
73
73
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import
|
|
2
|
+
import { klona } from "klona/full";
|
|
3
3
|
|
|
4
4
|
import { has, isPlainObject } from "../../utils/helpers/objects";
|
|
5
5
|
|
|
@@ -105,7 +105,7 @@ const updateData = (
|
|
|
105
105
|
data: Object,
|
|
106
106
|
contributions: Object
|
|
107
107
|
): Object => {
|
|
108
|
-
const newData =
|
|
108
|
+
const newData = klona(data);
|
|
109
109
|
|
|
110
110
|
if (contributions.dynamicschemaId) {
|
|
111
111
|
newData.dynamicschemaId = contributions.dynamicschemaId;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_createAttribute.js","names":["getChildrenKeys","children","child","childKey","isComposite","type","key","dynamicschemaId","undefined","getAttributeModel","contributions","ATTRIBUTE_MODELS","ChoiceAttributeModel","BooleanAttributeModel","HelptextAttributeModel","LabelAttributeModel","XMLAttributeModel","MemoAttributeModel","StringAttributeModel","DatetimeAttributeModel","MoneyAttributeModel","NumberAttributeModel","PasswordAttributeModel","UploadAttributeModel","CompositeAttributeModel","CaptchaAttributeModel","model","isApplicableModel","updateContributions","data","has","isPlainObject","Array","isArray","updateData","newData","
|
|
1
|
+
{"version":3,"file":"_createAttribute.js","names":["getChildrenKeys","children","child","childKey","isComposite","type","key","dynamicschemaId","undefined","getAttributeModel","contributions","ATTRIBUTE_MODELS","ChoiceAttributeModel","BooleanAttributeModel","HelptextAttributeModel","LabelAttributeModel","XMLAttributeModel","MemoAttributeModel","StringAttributeModel","DatetimeAttributeModel","MoneyAttributeModel","NumberAttributeModel","PasswordAttributeModel","UploadAttributeModel","CompositeAttributeModel","CaptchaAttributeModel","model","isApplicableModel","updateContributions","data","has","isPlainObject","Array","isArray","updateData","newData","klona","createAttribute","updatedContributions","updatedData","Model","Error","childrenKeys","dataHelper","AttributeDataHelper","getData","attribute","LayoutHintRuleCollection","setLayoutHintRules"],"sources":["../../../src/models/attributes/_createAttribute.js"],"sourcesContent":["// @flow\nimport { klona } from \"klona/full\";\n\nimport { has, isPlainObject } from \"../../utils/helpers/objects\";\n\nimport LayoutHintRuleCollection from \"./layouthint-rules/LayoutHintRuleCollection\";\n\nimport CaptchaAttributeModel from \"./CaptchaAttributeModel\";\nimport ChoiceAttributeModel from \"./ChoiceAttributeModel\";\nimport DatetimeAttributeModel from \"./DatetimeAttributeModel\";\nimport HelptextAttributeModel from \"./HelptextAttributeModel\";\nimport LabelAttributeModel from \"./LabelAttributeModel\";\nimport MemoAttributeModel from \"./MemoAttributeModel\";\nimport MoneyAttributeModel from \"./MoneyAttributeModel\";\nimport NumberAttributeModel from \"./NumberAttributeModel\";\nimport PasswordAttributeModel from \"./PasswordAttributeModel\";\nimport CompositeAttributeModel from \"./CompositeAttributeModel\";\nimport StringAttributeModel from \"./StringAttributeModel\";\nimport UploadAttributeModel from \"./UploadAttributeModel\";\nimport XMLAttributeModel from \"./XMLAttributeModel\";\nimport BooleanAttributeModel from \"./BooleanAttributeModel\";\n\nimport AttributeDataHelper from \"./AttributeDataHelper\";\n\nimport type { AttributeType } from \"../types\";\n\n/**\n * @private\n */\nconst getChildrenKeys = (children: Array<Object>): Array<Object> => {\n if (children) {\n return children.map((child) => {\n const [childKey] = Object.keys(child);\n const isComposite =\n child[childKey].type === \"range\" ||\n child[childKey].type === \"composite\";\n\n return {\n key: childKey,\n dynamicschemaId: child[childKey]?.dynamicschemaId || undefined,\n children: isComposite ? getChildrenKeys(child[childKey]?.children) : [],\n };\n });\n }\n\n return [];\n};\n\n/**\n * @private\n */\nconst getAttributeModel = (contributions: Object): ?Class<AttributeType> => {\n const ATTRIBUTE_MODELS = [\n ChoiceAttributeModel,\n BooleanAttributeModel,\n\n HelptextAttributeModel,\n LabelAttributeModel,\n\n XMLAttributeModel,\n MemoAttributeModel,\n StringAttributeModel,\n\n DatetimeAttributeModel,\n\n MoneyAttributeModel,\n NumberAttributeModel,\n PasswordAttributeModel,\n\n UploadAttributeModel,\n CompositeAttributeModel,\n CaptchaAttributeModel,\n ];\n\n return ATTRIBUTE_MODELS.find((model) =>\n model.isApplicableModel(contributions)\n );\n};\n\n/**\n * @private\n */\nconst updateContributions = (\n key: string,\n data: Object,\n contributions: Object\n): Object => {\n const isComposite =\n contributions.type === \"array\" &&\n has(contributions, \"children\") &&\n isPlainObject(data) &&\n Array.isArray(data[key]);\n\n return {\n ...contributions,\n type: isComposite ? \"composite\" : contributions.type,\n };\n};\n\n/**\n * @private\n */\nconst updateData = (\n key: string,\n data: Object,\n contributions: Object\n): Object => {\n const newData = klona(data);\n\n if (contributions.dynamicschemaId) {\n newData.dynamicschemaId = contributions.dynamicschemaId;\n }\n\n return newData;\n};\n\n/**\n * Create an attribute based on data and contributions\n */\nconst createAttribute = (\n key: string,\n data: Object | Array<Object>,\n contributions: Object\n): AttributeType => {\n const updatedContributions = updateContributions(key, data, contributions);\n const updatedData = updateData(key, data, contributions);\n\n const Model = getAttributeModel(updatedContributions);\n\n if (!Model) {\n throw new Error(\"Could not find model\");\n }\n\n const childrenKeys = getChildrenKeys(updatedContributions.children ?? []);\n const dataHelper = new AttributeDataHelper(\n updatedData,\n key,\n childrenKeys\n ).getData();\n\n const attribute = new Model(dataHelper, updatedContributions);\n\n return LayoutHintRuleCollection.setLayoutHintRules(attribute);\n};\n\nexport default createAttribute;\n"],"mappings":";;;;;;;;;;AACA;AAEA;AAEA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AAIA;AACA;AACA;AACA,MAAMA,eAAe,GAAIC,QAAuB,IAAoB;EAClE,IAAIA,QAAQ,EAAE;IACZ,OAAO,kBAAAA,QAAQ,OAARA,QAAQ,EAAMC,KAAK,IAAK;MAC7B,MAAM,CAACC,QAAQ,CAAC,GAAG,mBAAYD,KAAK,CAAC;MACrC,MAAME,WAAW,GACfF,KAAK,CAACC,QAAQ,CAAC,CAACE,IAAI,KAAK,OAAO,IAChCH,KAAK,CAACC,QAAQ,CAAC,CAACE,IAAI,KAAK,WAAW;MAEtC,OAAO;QACLC,GAAG,EAAEH,QAAQ;QACbI,eAAe,EAAEL,KAAK,CAACC,QAAQ,CAAC,EAAEI,eAAe,IAAIC,SAAS;QAC9DP,QAAQ,EAAEG,WAAW,GAAGJ,eAAe,CAACE,KAAK,CAACC,QAAQ,CAAC,EAAEF,QAAQ,CAAC,GAAG;MACvE,CAAC;IACH,CAAC,CAAC;EACJ;EAEA,OAAO,EAAE;AACX,CAAC;;AAED;AACA;AACA;AACA,MAAMQ,iBAAiB,GAAIC,aAAqB,IAA4B;EAC1E,MAAMC,gBAAgB,GAAG,CACvBC,6BAAoB,EACpBC,8BAAqB,EAErBC,+BAAsB,EACtBC,4BAAmB,EAEnBC,0BAAiB,EACjBC,2BAAkB,EAClBC,6BAAoB,EAEpBC,+BAAsB,E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EAErD,IAAI,CAACE,KAAK,EAAE;IACV,MAAM,IAAIC,KAAK,CAAC,sBAAsB,CAAC;EACzC;EAEA,MAAMC,YAAY,GAAG1C,eAAe,CAACsC,oBAAoB,CAACrC,QAAQ,IAAI,EAAE,CAAC;EACzE,MAAM0C,UAAU,GAAG,IAAIC,4BAAmB,CACxCL,WAAW,EACXjC,GAAG,EACHoC,YAAY,CACb,CAACG,OAAO,EAAE;EAEX,MAAMC,SAAS,GAAG,IAAIN,KAAK,CAACG,UAAU,EAAEL,oBAAoB,CAAC;EAE7D,OAAOS,iCAAwB,CAACC,kBAAkB,CAACF,SAAS,CAAC;AAC/D,CAAC;AAAC,eAEaT,eAAe;AAAA"}
|
|
@@ -11,8 +11,7 @@ var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-sta
|
|
|
11
11
|
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
|
|
12
12
|
var _sort = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/sort"));
|
|
13
13
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
|
14
|
-
var
|
|
15
|
-
var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
|
|
14
|
+
var _full = require("klona/full");
|
|
16
15
|
/**
|
|
17
16
|
* Base class for collections of models
|
|
18
17
|
*/
|
|
@@ -177,15 +176,10 @@ class BaseCollection {
|
|
|
177
176
|
}
|
|
178
177
|
|
|
179
178
|
/**
|
|
180
|
-
* Returns a clone of the model
|
|
179
|
+
* Returns a clone of the model
|
|
181
180
|
*/
|
|
182
181
|
clone() {
|
|
183
|
-
|
|
184
|
-
// deepcopy can be expensive, use with care!
|
|
185
|
-
if (deepcopy) {
|
|
186
|
-
return (0, _cloneDeep.default)(this);
|
|
187
|
-
}
|
|
188
|
-
return (0, _clone.default)(this);
|
|
182
|
+
return (0, _full.klona)(this);
|
|
189
183
|
}
|
|
190
184
|
}
|
|
191
185
|
var _default = BaseCollection;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import
|
|
3
|
-
import cloneDeep from "lodash/cloneDeep";
|
|
2
|
+
import { klona } from "klona/full";
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
5
|
* Base class for collections of models
|
|
@@ -182,15 +181,10 @@ class BaseCollection<T> {
|
|
|
182
181
|
}
|
|
183
182
|
|
|
184
183
|
/**
|
|
185
|
-
* Returns a clone of the model
|
|
184
|
+
* Returns a clone of the model
|
|
186
185
|
*/
|
|
187
|
-
clone(
|
|
188
|
-
|
|
189
|
-
if (deepcopy) {
|
|
190
|
-
return cloneDeep(this);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
return clone(this);
|
|
186
|
+
clone(): this {
|
|
187
|
+
return klona(this);
|
|
194
188
|
}
|
|
195
189
|
}
|
|
196
190
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseCollection.js","names":["BaseCollection","constructor","initCollection","collection","_collection","add","items","all","Array","isArray","removeByIndex","itemIndex","hasItems","length","isEmpty","size","first","last","get","index","find","callbackfn","thisArg","filter","some","every","map","forEach","sort","compareFn","sorted","clone","
|
|
1
|
+
{"version":3,"file":"BaseCollection.js","names":["BaseCollection","constructor","initCollection","collection","_collection","add","items","all","Array","isArray","removeByIndex","itemIndex","hasItems","length","isEmpty","size","first","last","get","index","find","callbackfn","thisArg","filter","some","every","map","forEach","sort","compareFn","sorted","clone","klona"],"sources":["../../../src/models/base/BaseCollection.js"],"sourcesContent":["// @flow\nimport { klona } from \"klona/full\";\n\n/**\n * Base class for collections of models\n */\nclass BaseCollection<T> {\n _collection: Array<T>;\n\n /**\n * Construct base collection\n */\n constructor(initCollection: Array<T> = []) {\n this.collection = initCollection;\n }\n\n /**\n * Retrieve current collection\n */\n get collection(): Array<T> {\n return this._collection;\n }\n\n /**\n * Replace current collection with a new collection\n */\n set collection(collection: Array<T>) {\n this._collection = collection;\n }\n\n /**\n * Add an other collection, array of items or single item to this collection;\n */\n add(items: BaseCollection<T> | Array<T> | T): BaseCollection<T> {\n if (items instanceof BaseCollection) {\n this.collection = [...this.collection, ...items.all];\n } else if (Array.isArray(items)) {\n // $FlowExpectedError[incompatible-type]\n this.collection = [...this.collection, ...items];\n } else {\n this.collection = [...this.collection, items];\n }\n\n return this;\n }\n\n /**\n * Remove an item from the collection by it's index.\n */\n removeByIndex(itemIndex: number) {\n if (itemIndex > -1) {\n this.collection = [\n ...this.collection.slice(0, itemIndex),\n ...this.collection.slice(itemIndex + 1),\n ];\n }\n }\n\n /**\n * Indicates if the collection has items\n */\n get hasItems(): boolean {\n return this.length > 0;\n }\n\n /**\n * Indicates if collection is empty\n */\n get isEmpty(): boolean {\n return !this.hasItems;\n }\n\n /**\n * Retrieve all items in collection\n */\n get all(): Array<T> {\n return this.collection;\n }\n\n /**\n * Get the size of this collection\n */\n get size(): number {\n return this.length;\n }\n\n /**\n * Get the size of this collection\n */\n get length(): number {\n return this.collection.length;\n }\n\n /**\n * Return first link in collection\n */\n get first(): T | null {\n return this.collection[0] ?? null;\n }\n\n /**\n */\n get last(): T | null {\n return this.collection[this.collection.length - 1] ?? null;\n }\n\n /**\n */\n get(index: number): T | null {\n return this.collection[index] ?? null;\n }\n\n /**\n * Find item\n */\n find(\n callbackfn: (value: T, index: number, array: Array<T>) => any,\n thisArg?: any\n ): T | null {\n return this.collection.find(callbackfn, thisArg) ?? null;\n }\n\n /**\n * Filter items\n */\n filter(\n callbackfn: (value: T, index: number, array: Array<T>) => any,\n thisArg?: any\n ): Array<T> {\n return this.collection.filter(callbackfn, thisArg);\n }\n\n /**\n * Check if at least one item occurs\n */\n some(\n callbackfn: (value: T, index: number, array: Array<T>) => any,\n thisArg?: any\n ): boolean {\n return this.collection.some(callbackfn, thisArg);\n }\n\n /**\n */\n every(\n callbackfn: (value: T, index: number, array: Array<T>) => any,\n thisArg?: any\n ): boolean {\n return this.collection.every(callbackfn, thisArg);\n }\n\n /**\n */\n map<U>(\n callbackfn: (value: T, index: number, array: Array<T>) => U,\n thisArg?: T\n ): Array<U> {\n return this.collection.map<U, ?T>(callbackfn, thisArg);\n }\n\n /**\n */\n forEach(\n callbackfn: (value: T, index: number, array: Array<T>) => any,\n thisArg?: any\n ) {\n this.collection.forEach(callbackfn, thisArg);\n }\n\n /**\n */\n sort(compareFn?: (a: T, b: T) => number): Array<T> {\n return this.collection.sort(compareFn);\n }\n\n /**\n * Retrieve an alphabetically sorted array of items\n */\n get sorted(): Array<T> {\n return this.collection.sort();\n }\n\n /**\n * Returns a clone of the model\n */\n clone(): this {\n return klona(this);\n }\n}\n\nexport default BaseCollection;\n"],"mappings":";;;;;;;;;;;;;AACA;AAEA;AACA;AACA;AACA,MAAMA,cAAc,CAAI;EAGtB;AACF;AACA;EACEC,WAAW,GAAgC;IAAA,IAA/BC,cAAwB,uEAAG,EAAE;IAAA;IACvC,IAAI,CAACC,UAAU,GAAGD,cAAc;EAClC;;EAEA;AACF;AACA;EACE,IAAIC,UAAU,GAAa;IACzB,OAAO,IAAI,CAACC,WAAW;EACzB;;EAEA;AACF;AACA;EACE,IAAID,UAAU,CAACA,UAAoB,EAAE;IACnC,IAAI,CAACC,WAAW,GAAGD,UAAU;EAC/B;;EAEA;AACF;AACA;EACEE,GAAG,CAACC,KAAuC,EAAqB;IAC9D,IAAIA,KAAK,YAAYN,cAAc,EAAE;MACnC,IAAI,CAACG,UAAU,GAAG,CAAC,GAAG,IAAI,CAACA,UAAU,EAAE,GAAGG,KAAK,CAACC,GAAG,CAAC;IACtD,CAAC,MAAM,IAAIC,KAAK,CAACC,OAAO,CAACH,KAAK,CAAC,EAAE;MAC/B;MACA,IAAI,CAACH,UAAU,GAAG,CAAC,GAAG,IAAI,CAACA,UAAU,EAAE,GAAGG,KAAK,CAAC;IAClD,CAAC,MAAM;MACL,IAAI,CAACH,UAAU,GAAG,CAAC,GAAG,IAAI,CAACA,UAAU,EAAEG,KAAK,CAAC;IAC/C;IAEA,OAA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ACA;EACEC,MAAM,CACJF,UAA6D,EAC7DC,OAAa,EACH;IAAA;IACV,OAAO,qCAAI,CAACnB,UAAU,kBAAQkB,UAAU,EAAEC,OAAO,CAAC;EACpD;;EAEA;AACF;AACA;EACEE,IAAI,CACFH,UAA6D,EAC7DC,OAAa,EACJ;IACT,OAAO,IAAI,CAACnB,UAAU,CAACqB,IAAI,CAACH,UAAU,EAAEC,OAAO,CAAC;EAClD;;EAEA;AACF;EACEG,KAAK,CACHJ,UAA6D,EAC7DC,OAAa,EACJ;IACT,OAAO,IAAI,CAACnB,UAAU,CAACsB,KAAK,CAACJ,UAAU,EAAEC,OAAO,CAAC;EACnD;;EAEA;AACF;EACEI,GAAG,CACDL,UAA2D,EAC3DC,OAAW,EACD;IAAA;IACV,OAAO,kCAAI,CAACnB,UAAU,kBAAYkB,UAAU,EAAEC,OAAO,CAAC;EACxD;;EAEA;AACF;EACEK,OAAO,CACLN,UAA6D,EAC7DC,OAAa,EACb;IACA,IAAI,CAACnB,UAAU,CAACwB,OAAO,CAACN,UAAU,EAAEC,OAAO,CAAC;EAC9C;;EAEA;AACF;EACEM,IAAI,CAACC,SAAkC,EAAY;IAAA;IACjD,OAAO,mCAAI,CAAC1B,UAAU,kBAAM0B,SAAS,CAAC;EACxC;;EAEA;AACF;AACA;EACE,IAAIC,MAAM,GAAa;IAAA;IACrB,OAAO,mCAAI,CAAC3B,UAAU,iBAAO;EAC/B;;EAEA;AACF;AACA;EACE4B,KAAK,GAAS;IACZ,OAAO,IAAAC,WAAK,EAAC,IAAI,CAAC;EACpB;AACF;AAAC,eAEchC,cAAc;AAAA"}
|
|
@@ -7,8 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
var _keys = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/keys"));
|
|
9
9
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
|
10
|
-
var
|
|
11
|
-
var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
|
|
10
|
+
var _full = require("klona/full");
|
|
12
11
|
var _LayoutHintCollection = _interopRequireDefault(require("../layouthint/LayoutHintCollection"));
|
|
13
12
|
/**
|
|
14
13
|
* Base model, this is the foundation of a model,
|
|
@@ -117,12 +116,7 @@ class BaseModel {
|
|
|
117
116
|
* Returns a clone of the model
|
|
118
117
|
*/
|
|
119
118
|
clone() {
|
|
120
|
-
|
|
121
|
-
// deepcopy can be expensive, use with care!
|
|
122
|
-
if (deepcopy) {
|
|
123
|
-
return (0, _cloneDeep.default)(this);
|
|
124
|
-
}
|
|
125
|
-
return (0, _clone.default)(this);
|
|
119
|
+
return (0, _full.klona)(this);
|
|
126
120
|
}
|
|
127
121
|
}
|
|
128
122
|
var _default = BaseModel;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// @flow
|
|
2
|
-
import
|
|
3
|
-
import cloneDeep from "lodash/cloneDeep";
|
|
2
|
+
import { klona } from "klona/full";
|
|
4
3
|
|
|
5
4
|
import LayoutHintCollection from "../layouthint/LayoutHintCollection";
|
|
6
5
|
|
|
@@ -118,13 +117,8 @@ class BaseModel {
|
|
|
118
117
|
/**
|
|
119
118
|
* Returns a clone of the model
|
|
120
119
|
*/
|
|
121
|
-
clone(
|
|
122
|
-
|
|
123
|
-
if (deepcopy) {
|
|
124
|
-
return cloneDeep(this);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return clone(this);
|
|
120
|
+
clone(): any {
|
|
121
|
+
return klona(this);
|
|
128
122
|
}
|
|
129
123
|
}
|
|
130
124
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseModel.js","names":["BaseModel","constructor","data","contributions","_data","_contributions","_layouthint","LayoutHintCollection","getContribution","getData","propName","defaultValue","layouthint","hasData","length","connectKey","key","_connectKey","dehydrate","rehydrate","clone","
|
|
1
|
+
{"version":3,"file":"BaseModel.js","names":["BaseModel","constructor","data","contributions","_data","_contributions","_layouthint","LayoutHintCollection","getContribution","getData","propName","defaultValue","layouthint","hasData","length","connectKey","key","_connectKey","dehydrate","rehydrate","clone","klona"],"sources":["../../../src/models/base/BaseModel.js"],"sourcesContent":["// @flow\nimport { klona } from \"klona/full\";\n\nimport LayoutHintCollection from \"../layouthint/LayoutHintCollection\";\n\nexport type BaseDehydrateData = {\n +data: Object,\n +contributions: Object,\n connectKey: string,\n ...\n};\n\n/**\n * Base model, this is the foundation of a model,\n * it contains data that is needed for all models like, data, contributions and layout hint\n *\n * Extend this for non modular ui resources, for modular ui resource start with the resourceModel\n */\nclass BaseModel {\n _data: Object;\n _contributions: Object;\n _layouthint: LayoutHintCollection;\n _connectKey: string;\n\n /**\n * constructor\n */\n constructor(data: Object, contributions: Object) {\n this._data = data;\n this._contributions = contributions;\n this._layouthint = new LayoutHintCollection(\n this.getContribution(\"layouthint\", [])\n );\n }\n\n /**\n * Retrieve data\n */\n get data(): Object {\n return this._data || {};\n }\n\n /**\n * Retrieve property from the data object of the model, mostly used internal\n */\n getData(propName: string, defaultValue: any = null): any {\n return this.data[propName] ?? defaultValue;\n }\n\n /**\n * Retrieve contributions\n */\n get contributions(): Object {\n return this._contributions || {};\n }\n\n /**\n * Retrieve property from the contributions of the model, mostly used internal\n */\n getContribution(propName: string, defaultValue: any = null): any {\n return this.contributions[propName] ?? defaultValue;\n }\n\n /**\n * Getting the layouthint\n */\n get layouthint(): LayoutHintCollection {\n return this._layouthint;\n }\n\n /**\n * Set the layouthint\n */\n set layouthint(layouthint: Array<string>) {\n this._layouthint = new LayoutHintCollection(layouthint);\n }\n\n /**\n * Indicates if the model has data\n */\n get hasData(): boolean {\n return Object.keys(this.data).length > 0;\n }\n\n /**\n * Set the unique key for this model\n */\n set connectKey(key: string) {\n this._connectKey = key;\n }\n\n /**\n * Get the unique key of this model\n */\n get connectKey(): string {\n return this._connectKey;\n }\n\n /**\n * Dehydrate internal data, returns the information that is needed to recreate the model\n */\n dehydrate(): BaseDehydrateData {\n return {\n data: this._data,\n contributions: this._contributions,\n connectKey: this._connectKey,\n };\n }\n\n /**\n * Recreate the model with the given data\n */\n rehydrate(data: BaseDehydrateData) {\n this._connectKey = data.connectKey;\n }\n\n /**\n * Returns a clone of the model\n */\n clone(): any {\n return klona(this);\n }\n}\n\nexport default BaseModel;\n"],"mappings":";;;;;;;;;AACA;AAEA;AASA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,SAAS,CAAC;EAMd;AACF;AACA;EACEC,WAAW,CAACC,IAAY,EAAEC,aAAqB,EAAE;IAAA;IAAA;IAAA;IAAA;IAC/C,IAAI,CAACC,KAAK,GAAGF,IAAI;IACjB,IAAI,CAACG,cAAc,GAAGF,aAAa;IACnC,IAAI,CAACG,WAAW,GAAG,IAAIC,6BAAoB,CACzC,IAAI,CAACC,eAAe,CAAC,YAAY,EAAE,EAAE,CAAC,CACvC;EACH;;EAEA;AACF;AACA;EACE,IAAIN,IAAI,GAAW;IACjB,OAAO,IAAI,CAACE,KAAK,IAAI,CAAC,CAAC;EACzB;;EAEA;AACF;AACA;EACEK,OAAO,CAACC,QAAgB,EAAiC;IAAA,IAA/BC,YAAiB,uEAAG,IAAI;IAChD,OAAO,IAAI,CAACT,IAAI,CAACQ,QAAQ,CAAC,IAAIC,YAAY;EAC5C;;EAEA;AACF;AACA;EACE,IAAIR,aAAa,GAAW;IAC1B,OAAO,IAAI,CAACE,cAAc,IAAI,CAAC,CAAC;EAClC;;EAEA;AACF;AACA;EACEG,eAAe,CAACE,QAAgB,EAAiC;IAAA,IAA/BC,YAAiB,uEAAG,IAAI;IACxD,OAAO,IAAI,CAACR,aAAa,CAACO,QAAQ,CAAC,IAAIC,YAAY;EACrD;;EAEA;AACF;AACA;EACE,IAAIC,UAAU,GAAyB;IACrC,OAAO,IAAI,CAACN,WAAW;EACzB;;EAEA;AACF;AACA;EACE,IAAIM,UAAU,CAACA,UAAyB,EAAE;IACxC,IAAI,CAACN,WAAW,GAAG,IAAIC,6BAAoB,CAACK,UAAU,CAAC;EACzD;;EAEA;AACF;AACA;EACE,IAAIC,OAAO,GAAY;IACrB,OAAO,mBAAY,IAAI,CAACX,IAAI,CAAC,CAACY,MAAM,GAAG,CAAC;EAC1C;;EAEA;AACF;AACA;EACE,IAAIC,UAAU,CAACC,GAAW,EAAE;IAC1B,IAAI,CAACC,WAAW,GAAGD,GAAG;EACxB;;EAEA;AACF;AACA;EACE,IAAID,UAAU,GAAW;IACvB,OAAO,IAAI,CAACE,WAAW;EACzB;;EAEA;AACF;AACA;EACEC,SAAS,GAAsB;IAC7B,OAAO;MACLhB,IAAI,EAAE,IAAI,CAACE,KAAK;MAChBD,aAAa,EAAE,IAAI,CAACE,cAAc;MAClCU,UAAU,EAAE,IAAI,CAACE;IACnB,CAAC;EACH;;EAEA;AACF;AACA;EACEE,SAAS,CAACjB,IAAuB,EAAE;IACjC,IAAI,CAACe,WAAW,GAAGf,IAAI,CAACa,UAAU;EACpC;;EAEA;AACF;AACA;EACEK,KAAK,GAAQ;IACX,OAAO,IAAAC,WAAK,EAAC,IAAI,CAAC;EACpB;AACF;AAAC,eAEcrB,SAAS;AAAA"}
|
|
@@ -11,7 +11,8 @@ describe("baseModel", () => {
|
|
|
11
11
|
expect(model.contributions).toStrictEqual({});
|
|
12
12
|
expect(model.hasData).toBeFalsy();
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
const clonedModel = model.clone();
|
|
15
|
+
expect(clonedModel).toStrictEqual(model);
|
|
15
16
|
});
|
|
16
17
|
|
|
17
18
|
it("should handle data without contributions", () => {
|
|
@@ -72,12 +73,7 @@ describe("baseModel", () => {
|
|
|
72
73
|
},
|
|
73
74
|
});
|
|
74
75
|
|
|
75
|
-
const
|
|
76
|
-
expect(model).not.toBe(shallowClone);
|
|
77
|
-
expect(model.data.prop).toBe(shallowClone.data.prop);
|
|
78
|
-
expect(model.data.prop.child).toBe(shallowClone.data.prop.child);
|
|
79
|
-
|
|
80
|
-
const deepClone = model.clone(true);
|
|
76
|
+
const deepClone = model.clone();
|
|
81
77
|
expect(model).not.toBe(deepClone);
|
|
82
78
|
expect(model.data.prop === deepClone.data.prop).toBeFalsy();
|
|
83
79
|
expect(model.data.prop.child).toBe(deepClone.data.prop.child);
|
|
@@ -13,19 +13,32 @@ var _constants = require("../constants");
|
|
|
13
13
|
class CaptchaRequest {
|
|
14
14
|
constructor() {
|
|
15
15
|
(0, _defineProperty2.default)(this, "_tokenId", void 0);
|
|
16
|
+
(0, _defineProperty2.default)(this, "_image", void 0);
|
|
16
17
|
}
|
|
17
18
|
/**
|
|
18
19
|
*/
|
|
20
|
+
captchaResponse(response) {
|
|
21
|
+
this._tokenId = response.tokenId ?? this._tokenId;
|
|
22
|
+
this._image = response.image ?? this._image;
|
|
23
|
+
return {
|
|
24
|
+
tokenId: this._tokenId,
|
|
25
|
+
image: this._image,
|
|
26
|
+
valid: response.valid ?? false,
|
|
27
|
+
error: response.error ?? null
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Initiate the captcha request
|
|
33
|
+
*/
|
|
19
34
|
init() {
|
|
20
35
|
return (0, _xhr.default)({
|
|
21
36
|
url: (0, _constants.getCaptchaPath)()
|
|
22
|
-
}).then(response =>
|
|
23
|
-
this._tokenId = response.tokenId;
|
|
24
|
-
return response;
|
|
25
|
-
});
|
|
37
|
+
}).then(response => this.captchaResponse(response));
|
|
26
38
|
}
|
|
27
39
|
|
|
28
40
|
/**
|
|
41
|
+
* Answer the captcha
|
|
29
42
|
*/
|
|
30
43
|
send(answer) {
|
|
31
44
|
return (0, _xhr.default)({
|
|
@@ -35,10 +48,14 @@ class CaptchaRequest {
|
|
|
35
48
|
tokenId: this._tokenId ?? "",
|
|
36
49
|
answer: answer ?? ""
|
|
37
50
|
}
|
|
38
|
-
}).catch(error =>
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
51
|
+
}).then(response => this.captchaResponse(response)).catch(error => this.captchaResponse(error.response));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Reset the captcha and receive a new token and image
|
|
56
|
+
*/
|
|
57
|
+
refresh() {
|
|
58
|
+
return this.init();
|
|
42
59
|
}
|
|
43
60
|
}
|
|
44
61
|
var _default = CaptchaRequest;
|
|
@@ -2,30 +2,65 @@
|
|
|
2
2
|
import xhr from "../utils/fetch/xhr";
|
|
3
3
|
import { getCaptchaPath, HTTP_METHODS } from "../constants";
|
|
4
4
|
|
|
5
|
+
type CaptchaInitialResponse = {
|
|
6
|
+
tokenId: string,
|
|
7
|
+
image: string,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
type CaptchaValidResponse = {
|
|
11
|
+
valid: boolean,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
type CaptchaInvalidResponse = {
|
|
15
|
+
tokenId: string,
|
|
16
|
+
image: string,
|
|
17
|
+
valid: boolean,
|
|
18
|
+
error: { id: string },
|
|
19
|
+
};
|
|
20
|
+
|
|
5
21
|
type CaptchaResponse = {
|
|
6
22
|
tokenId: string,
|
|
7
|
-
image:
|
|
23
|
+
image: string,
|
|
8
24
|
valid: boolean,
|
|
25
|
+
error: { id: string } | null,
|
|
9
26
|
};
|
|
10
27
|
|
|
11
28
|
/**
|
|
12
29
|
*/
|
|
13
30
|
class CaptchaRequest {
|
|
14
31
|
_tokenId: string;
|
|
32
|
+
_image: string;
|
|
15
33
|
|
|
16
34
|
/**
|
|
17
35
|
*/
|
|
36
|
+
captchaResponse(
|
|
37
|
+
response:
|
|
38
|
+
| CaptchaInitialResponse
|
|
39
|
+
| CaptchaValidResponse
|
|
40
|
+
| CaptchaInvalidResponse
|
|
41
|
+
): CaptchaResponse {
|
|
42
|
+
this._tokenId = response.tokenId ?? this._tokenId;
|
|
43
|
+
this._image = response.image ?? this._image;
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
tokenId: this._tokenId,
|
|
47
|
+
image: this._image,
|
|
48
|
+
valid: response.valid ?? false,
|
|
49
|
+
error: response.error ?? null,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Initiate the captcha request
|
|
55
|
+
*/
|
|
18
56
|
init(): Promise<CaptchaResponse> {
|
|
19
57
|
return xhr({
|
|
20
58
|
url: getCaptchaPath(),
|
|
21
|
-
}).then((response) =>
|
|
22
|
-
this._tokenId = response.tokenId;
|
|
23
|
-
|
|
24
|
-
return response;
|
|
25
|
-
});
|
|
59
|
+
}).then((response) => this.captchaResponse(response));
|
|
26
60
|
}
|
|
27
61
|
|
|
28
62
|
/**
|
|
63
|
+
* Answer the captcha
|
|
29
64
|
*/
|
|
30
65
|
send(answer?: string): Promise<CaptchaResponse> {
|
|
31
66
|
return xhr({
|
|
@@ -35,10 +70,16 @@ class CaptchaRequest {
|
|
|
35
70
|
tokenId: this._tokenId ?? "",
|
|
36
71
|
answer: answer ?? "",
|
|
37
72
|
},
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
73
|
+
})
|
|
74
|
+
.then((response) => this.captchaResponse(response))
|
|
75
|
+
.catch((error) => this.captchaResponse(error.response));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Reset the captcha and receive a new token and image
|
|
80
|
+
*/
|
|
81
|
+
refresh(): Promise<CaptchaResponse> {
|
|
82
|
+
return this.init();
|
|
42
83
|
}
|
|
43
84
|
}
|
|
44
85
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CaptchaRequest.js","names":["CaptchaRequest","
|
|
1
|
+
{"version":3,"file":"CaptchaRequest.js","names":["CaptchaRequest","captchaResponse","response","_tokenId","tokenId","_image","image","valid","error","init","xhr","url","getCaptchaPath","then","send","answer","method","HTTP_METHODS","POST","data","catch","refresh"],"sources":["../../src/modularui/CaptchaRequest.js"],"sourcesContent":["// @flow\nimport xhr from \"../utils/fetch/xhr\";\nimport { getCaptchaPath, HTTP_METHODS } from \"../constants\";\n\ntype CaptchaInitialResponse = {\n tokenId: string,\n image: string,\n};\n\ntype CaptchaValidResponse = {\n valid: boolean,\n};\n\ntype CaptchaInvalidResponse = {\n tokenId: string,\n image: string,\n valid: boolean,\n error: { id: string },\n};\n\ntype CaptchaResponse = {\n tokenId: string,\n image: string,\n valid: boolean,\n error: { id: string } | null,\n};\n\n/**\n */\nclass CaptchaRequest {\n _tokenId: string;\n _image: string;\n\n /**\n */\n captchaResponse(\n response:\n | CaptchaInitialResponse\n | CaptchaValidResponse\n | CaptchaInvalidResponse\n ): CaptchaResponse {\n this._tokenId = response.tokenId ?? this._tokenId;\n this._image = response.image ?? this._image;\n\n return {\n tokenId: this._tokenId,\n image: this._image,\n valid: response.valid ?? false,\n error: response.error ?? null,\n };\n }\n\n /**\n * Initiate the captcha request\n */\n init(): Promise<CaptchaResponse> {\n return xhr({\n url: getCaptchaPath(),\n }).then((response) => this.captchaResponse(response));\n }\n\n /**\n * Answer the captcha\n */\n send(answer?: string): Promise<CaptchaResponse> {\n return xhr({\n url: getCaptchaPath(),\n method: HTTP_METHODS.POST,\n data: {\n tokenId: this._tokenId ?? \"\",\n answer: answer ?? \"\",\n },\n })\n .then((response) => this.captchaResponse(response))\n .catch((error) => this.captchaResponse(error.response));\n }\n\n /**\n * Reset the captcha and receive a new token and image\n */\n refresh(): Promise<CaptchaResponse> {\n return this.init();\n }\n}\n\nexport default CaptchaRequest;\n"],"mappings":";;;;;;;;AACA;AACA;AAyBA;AACA;AACA,MAAMA,cAAc,CAAC;EAAA;IAAA;IAAA;EAAA;EAInB;AACF;EACEC,eAAe,CACbC,QAG0B,EACT;IACjB,IAAI,CAACC,QAAQ,GAAGD,QAAQ,CAACE,OAAO,IAAI,IAAI,CAACD,QAAQ;IACjD,IAAI,CAACE,MAAM,GAAGH,QAAQ,CAACI,KAAK,IAAI,IAAI,CAACD,MAAM;IAE3C,OAAO;MACLD,OAAO,EAAE,IAAI,CAACD,QAAQ;MACtBG,KAAK,EAAE,IAAI,CAACD,MAAM;MAClBE,KAAK,EAAEL,QAAQ,CAACK,KAAK,IAAI,KAAK;MAC9BC,KAAK,EAAEN,QAAQ,CAACM,KAAK,IAAI;IAC3B,CAAC;EACH;;EAEA;AACF;AACA;EACEC,IAAI,GAA6B;IAC/B,OAAO,IAAAC,YAAG,EAAC;MACTC,GAAG,EAAE,IAAAC,yBAAc;IACrB,CAAC,CAAC,CAACC,IAAI,CAAEX,QAAQ,IAAK,IAAI,CAACD,eAAe,CAACC,QAAQ,CAAC,CAAC;EACvD;;EAEA;AACF;AACA;EACEY,IAAI,CAACC,MAAe,EAA4B;IAC9C,OAAO,IAAAL,YAAG,EAAC;MACTC,GAAG,EAAE,IAAAC,yBAAc,GAAE;MACrBI,MAAM,EAAEC,uBAAY,CAACC,IAAI;MACzBC,IAAI,EAAE;QACJf,OAAO,EAAE,IAAI,CAACD,QAAQ,IAAI,EAAE;QAC5BY,MAAM,EAAEA,MAAM,IAAI;MACpB;IACF,CAAC,CAAC,CACCF,IAAI,CAAEX,QAAQ,IAAK,IAAI,CAACD,eAAe,CAACC,QAAQ,CAAC,CAAC,CAClDkB,KAAK,CAAEZ,KAAK,IAAK,IAAI,CAACP,eAAe,CAACO,KAAK,CAACN,QAAQ,CAAC,CAAC;EAC3D;;EAEA;AACF;AACA;EACEmB,OAAO,GAA6B;IAClC,OAAO,IAAI,CAACZ,IAAI,EAAE;EACpB;AACF;AAAC,eAEcT,cAAc;AAAA"}
|
|
@@ -17,7 +17,7 @@ var _FormModel = _interopRequireDefault(require("../../models/form/FormModel"));
|
|
|
17
17
|
const updateValidations = (form, formWithValidations) => (dispatch, getState) => {
|
|
18
18
|
const currentForm = getState().modularui[form.connectKey];
|
|
19
19
|
if (currentForm) {
|
|
20
|
-
const validatedForm = currentForm.model.clone(
|
|
20
|
+
const validatedForm = currentForm.model.clone();
|
|
21
21
|
if (validatedForm instanceof _FormModel.default) {
|
|
22
22
|
validatedForm.updateValidations(formWithValidations.data);
|
|
23
23
|
}
|
|
@@ -25,7 +25,7 @@ const updateValidations =
|
|
|
25
25
|
const currentForm = getState().modularui[form.connectKey];
|
|
26
26
|
|
|
27
27
|
if (currentForm) {
|
|
28
|
-
const validatedForm = currentForm.model.clone(
|
|
28
|
+
const validatedForm = currentForm.model.clone();
|
|
29
29
|
if (validatedForm instanceof FormModel) {
|
|
30
30
|
validatedForm.updateValidations(formWithValidations.data);
|
|
31
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormValidations.js","names":["updateValidations","form","formWithValidations","dispatch","getState","currentForm","modularui","connectKey","validatedForm","model","clone","FormModel","data","updateModel","debouncedValidateFormObject","debounce","ModularUIRequest","selfhref","setParameter","method","HTTP_METHODS","POST","validationData","childmodels","isValidationRequest","locale","fetch","then","VALIDATE_DEBOUNCE_TIMEOUT","leading","trailing","validateFormObject"],"sources":["../../../src/redux/actions/FormValidations.js"],"sourcesContent":["// @flow\nimport debounce from \"lodash/debounce\";\n\nimport { updateModel } from \"../_modularui/ModularUIActions\";\n\nimport ModularUIRequest from \"../../modularui/ModularUIRequest\";\n\nimport {\n HTTP_METHODS,\n VALIDATE_DEBOUNCE_TIMEOUT,\n} from \"../../constants/Constants\";\n\nimport FormModel from \"../../models/form/FormModel\";\n\nimport type { Dispatch, GetState, ThunkAction } from \"../types\";\nimport type { ModularUIModel } from \"../../models\";\n\n/**\n * Update validations of the form currently in the reducer\n * because of the debounce timeout there might have been an update on the form during validation\n */\nconst updateValidations =\n (form: FormModel, formWithValidations: ModularUIModel) =>\n (dispatch: Dispatch, getState: GetState) => {\n const currentForm = getState().modularui[form.connectKey];\n\n if (currentForm) {\n const validatedForm = currentForm.model.clone(
|
|
1
|
+
{"version":3,"file":"FormValidations.js","names":["updateValidations","form","formWithValidations","dispatch","getState","currentForm","modularui","connectKey","validatedForm","model","clone","FormModel","data","updateModel","debouncedValidateFormObject","debounce","ModularUIRequest","selfhref","setParameter","method","HTTP_METHODS","POST","validationData","childmodels","isValidationRequest","locale","fetch","then","VALIDATE_DEBOUNCE_TIMEOUT","leading","trailing","validateFormObject"],"sources":["../../../src/redux/actions/FormValidations.js"],"sourcesContent":["// @flow\nimport debounce from \"lodash/debounce\";\n\nimport { updateModel } from \"../_modularui/ModularUIActions\";\n\nimport ModularUIRequest from \"../../modularui/ModularUIRequest\";\n\nimport {\n HTTP_METHODS,\n VALIDATE_DEBOUNCE_TIMEOUT,\n} from \"../../constants/Constants\";\n\nimport FormModel from \"../../models/form/FormModel\";\n\nimport type { Dispatch, GetState, ThunkAction } from \"../types\";\nimport type { ModularUIModel } from \"../../models\";\n\n/**\n * Update validations of the form currently in the reducer\n * because of the debounce timeout there might have been an update on the form during validation\n */\nconst updateValidations =\n (form: FormModel, formWithValidations: ModularUIModel) =>\n (dispatch: Dispatch, getState: GetState) => {\n const currentForm = getState().modularui[form.connectKey];\n\n if (currentForm) {\n const validatedForm = currentForm.model.clone();\n if (validatedForm instanceof FormModel) {\n validatedForm.updateValidations(formWithValidations.data);\n }\n\n dispatch(updateModel(validatedForm));\n }\n };\n\n/**\n * Validates form objects debounced to prevent overloading the (form) service\n * When a form with new errors (or complete) arrives, we send the validations\n * to the current form model where the errors are processed\n * A new form with the new constraints is send to the store\n */\nconst debouncedValidateFormObject = debounce<\n (dispatch: Dispatch, form: FormModel) => void\n>(\n (dispatch, form: FormModel) => {\n new ModularUIRequest(form.selfhref.setParameter(\"commit\", \"false\"), {\n method: HTTP_METHODS.POST,\n data: form.validationData,\n childmodels: false,\n isValidationRequest: true,\n locale: form.locale,\n })\n .fetch()\n .then((formWithValidations) =>\n dispatch(updateValidations(form, formWithValidations))\n );\n },\n VALIDATE_DEBOUNCE_TIMEOUT,\n {\n leading: true,\n trailing: true,\n }\n);\n\n/**\n */\nexport const validateFormObject =\n (form: FormModel): ThunkAction =>\n (dispatch) =>\n debouncedValidateFormObject(dispatch, form);\n"],"mappings":";;;;;;;AACA;AAEA;AAEA;AAEA;AAKA;AAKA;AACA;AACA;AACA;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|
2
2
|
"name": "@beinformed/ui",
|
|
3
|
-
"version": "1.27.
|
|
3
|
+
"version": "1.27.2",
|
|
4
4
|
"description": "Toolbox for be informed javascript layouts",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
6
|
"bugs": "http://support.beinformed.com",
|
|
@@ -82,10 +82,10 @@
|
|
|
82
82
|
"styled-components": "^5.0.0"
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {
|
|
85
|
-
"@babel/runtime-corejs3": "^7.20.
|
|
85
|
+
"@babel/runtime-corejs3": "^7.20.13",
|
|
86
86
|
"big.js": "^6.2.1",
|
|
87
87
|
"date-fns": "^2.29.3",
|
|
88
|
-
"deepmerge": "^4.
|
|
88
|
+
"deepmerge": "^4.3.0",
|
|
89
89
|
"dequal": "^2.0.3",
|
|
90
90
|
"element-closest": "^3.0.2",
|
|
91
91
|
"file-size": "^1.0.0",
|
|
@@ -94,6 +94,7 @@
|
|
|
94
94
|
"he": "^1.2.0",
|
|
95
95
|
"iban": "^0.0.14",
|
|
96
96
|
"js-cookie": "^3.0.1",
|
|
97
|
+
"klona": "^2.0.6",
|
|
97
98
|
"lodash": "^4.17.21",
|
|
98
99
|
"reselect": "^4.1.7",
|
|
99
100
|
"setimmediate": "^1.0.5"
|
|
@@ -113,29 +114,29 @@
|
|
|
113
114
|
"@commitlint/config-conventional": "^17.4.2",
|
|
114
115
|
"@testing-library/react": "^13.4.0",
|
|
115
116
|
"auditjs": "^4.0.39",
|
|
116
|
-
"babel-jest": "^29.
|
|
117
|
+
"babel-jest": "^29.4.1",
|
|
117
118
|
"babel-plugin-styled-components": "^2.0.7",
|
|
118
119
|
"cherry-pick": "^0.5.0",
|
|
119
120
|
"cross-env": "^7.0.3",
|
|
120
121
|
"documentation": "^14.0.1",
|
|
121
|
-
"eslint": "^8.
|
|
122
|
+
"eslint": "^8.33.0",
|
|
122
123
|
"eslint-config-prettier": "^8.6.0",
|
|
123
124
|
"eslint-plugin-babel": "^5.3.1",
|
|
124
125
|
"eslint-plugin-ft-flow": "^2.0.3",
|
|
125
126
|
"eslint-plugin-import": "^2.27.5",
|
|
126
127
|
"eslint-plugin-jest": "^27.2.1",
|
|
127
|
-
"eslint-plugin-jsdoc": "^39.
|
|
128
|
-
"eslint-plugin-react": "^7.32.
|
|
128
|
+
"eslint-plugin-jsdoc": "^39.7.4",
|
|
129
|
+
"eslint-plugin-react": "^7.32.2",
|
|
129
130
|
"eslint-plugin-react-hooks": "^4.5.0",
|
|
130
131
|
"eslint-plugin-you-dont-need-lodash-underscore": "^6.12.0",
|
|
131
|
-
"flow-bin": "^0.
|
|
132
|
+
"flow-bin": "^0.198.2",
|
|
132
133
|
"flow-copy-source": "^2.0.9",
|
|
133
134
|
"flow-typed": "^3.8.0",
|
|
134
135
|
"glob": "^8.1.0",
|
|
135
136
|
"history": "^4.0.0",
|
|
136
137
|
"husky": "^8.0.3",
|
|
137
|
-
"jest": "^29.
|
|
138
|
-
"jest-environment-jsdom": "^29.
|
|
138
|
+
"jest": "^29.4.1",
|
|
139
|
+
"jest-environment-jsdom": "^29.4.1",
|
|
139
140
|
"jest-junit": "^15.0.0",
|
|
140
141
|
"jest-sonar-reporter": "^2.0.0",
|
|
141
142
|
"jscodeshift": "^0.14.0",
|
|
@@ -148,10 +149,10 @@
|
|
|
148
149
|
"react-redux": "^8.0.5",
|
|
149
150
|
"react-router": "^5.0.0",
|
|
150
151
|
"react-test-renderer": "^18.1.0",
|
|
151
|
-
"redux": "^4.
|
|
152
|
+
"redux": "^4.2.1",
|
|
152
153
|
"redux-mock-store": "^1.5.4",
|
|
153
154
|
"redux-thunk": "^2.4.2",
|
|
154
|
-
"rimraf": "^4.1.
|
|
155
|
+
"rimraf": "^4.1.2",
|
|
155
156
|
"standard-version": "^9.5.0",
|
|
156
157
|
"styled-components": "^5.3.6",
|
|
157
158
|
"xhr-mock": "^2.5.1"
|