kwikid-forms 0.2.10 → 0.3.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.
- package/bundles/kwikid-forms.umd.js +275 -95
- package/bundles/kwikid-forms.umd.js.map +1 -1
- package/esm2015/lib/renderer/config-converter.helper.js +22 -2
- package/esm2015/lib/renderer/form-view/definitions/form-view.actions.definition.js +3 -1
- package/esm2015/lib/renderer/form-view/definitions/form-view.apis.definition.js +6 -1
- package/esm2015/lib/renderer/form-view/form-view.component.js +110 -59
- package/esm2015/lib/renderer/form-view/helpers/form-view.apis.helper.js +107 -51
- package/fesm2015/kwikid-forms.js +239 -106
- package/fesm2015/kwikid-forms.js.map +1 -1
- package/lib/renderer/form-view/definitions/form-view.actions.definition.d.ts +17 -2
- package/lib/renderer/form-view/definitions/form-view.apis.definition.d.ts +20 -2
- package/lib/renderer/form-view/form-view.component.d.ts +5 -2
- package/lib/renderer/form-view/helpers/form-view.apis.helper.d.ts +3 -2
- package/package.json +1 -1
package/fesm2015/kwikid-forms.js
CHANGED
|
@@ -5,7 +5,7 @@ import * as i0 from '@angular/core';
|
|
|
5
5
|
import { EventEmitter, Component, Input, Output, ViewEncapsulation, Pipe, Inject, HostListener, NgModule } from '@angular/core';
|
|
6
6
|
import * as i1 from '@angular/forms';
|
|
7
7
|
import { FormGroup, FormControl, FormArray, Validators, FormsModule, ReactiveFormsModule } from '@angular/forms';
|
|
8
|
-
import { logMethod, setMissingKeyValue, mergeObjects, getObjectFromLocalStorage, isNotEmptyValue, isEmptyValue, checkObjectKeyExists, setValueToObjectPath, Source, Rule, Condition, Action, PATTERNS, Validation, isUndefined, replaceString, getObjectValueFromPath, ESourceKey,
|
|
8
|
+
import { logMethod, setMissingKeyValue, mergeObjects, getObjectFromLocalStorage, isNotEmptyValue, isEmptyValue, checkObjectKeyExists, setValueToObjectPath, Source, Rule, Condition, Action, PATTERNS, Validation, isUndefined, isNull, replaceString, getObjectValueFromPath, ESourceKey, getObjectDeepCopy } from 'kwikid-toolkit';
|
|
9
9
|
import * as i2 from 'kwikui';
|
|
10
10
|
import { KwikUIButtonModule, KwikUIInputModule, KwikUIButtonIconModule, KwikUIModule } from 'kwikui';
|
|
11
11
|
import * as i3 from '@angular/common';
|
|
@@ -1818,6 +1818,26 @@ class Converter {
|
|
|
1818
1818
|
failed: "API Failed"
|
|
1819
1819
|
});
|
|
1820
1820
|
}
|
|
1821
|
+
if (!checkObjectKeyExists(field.api, "request") &&
|
|
1822
|
+
!checkObjectKeyExists(field.api, "entrypoint")) {
|
|
1823
|
+
// Set entrypoint as First endpoint.
|
|
1824
|
+
const entrypoint = {
|
|
1825
|
+
triggers: ["ON_API_CALL"],
|
|
1826
|
+
rules: [],
|
|
1827
|
+
actions: [
|
|
1828
|
+
{
|
|
1829
|
+
id: "1",
|
|
1830
|
+
key: "API_CALL",
|
|
1831
|
+
condition: "true",
|
|
1832
|
+
props: {
|
|
1833
|
+
fieldKey: field.key,
|
|
1834
|
+
apiKey: field.api.endpoints[0].apiKey
|
|
1835
|
+
}
|
|
1836
|
+
}
|
|
1837
|
+
]
|
|
1838
|
+
};
|
|
1839
|
+
field = setMissingKeyValue(field.api, "entrypoint", entrypoint);
|
|
1840
|
+
}
|
|
1821
1841
|
return field;
|
|
1822
1842
|
};
|
|
1823
1843
|
const formatFieldTypeOtp = (field) => {
|
|
@@ -2277,6 +2297,8 @@ var EActionKey;
|
|
|
2277
2297
|
EActionKey["FIELD_GROUP_ENABLE"] = "FIELD_GROUP_ENABLE";
|
|
2278
2298
|
EActionKey["FIELD_GROUP_DISABLE"] = "FIELD_GROUP_DISABLE";
|
|
2279
2299
|
EActionKey["SET_DROPDOWN_OPTIONS"] = "SET_DROPDOWN_OPTIONS";
|
|
2300
|
+
EActionKey["API_CALL"] = "API_CALL";
|
|
2301
|
+
EActionKey["API_CALL_END"] = "API_CALL_END";
|
|
2280
2302
|
})(EActionKey || (EActionKey = {}));
|
|
2281
2303
|
|
|
2282
2304
|
var EApiStatusType;
|
|
@@ -2286,6 +2308,11 @@ var EApiStatusType;
|
|
|
2286
2308
|
EApiStatusType["SUCCESS"] = "success";
|
|
2287
2309
|
EApiStatusType["FAILED"] = "failed";
|
|
2288
2310
|
})(EApiStatusType || (EApiStatusType = {}));
|
|
2311
|
+
var EApiRequestUrlType;
|
|
2312
|
+
(function (EApiRequestUrlType) {
|
|
2313
|
+
EApiRequestUrlType["MOCK"] = "MOCK";
|
|
2314
|
+
EApiRequestUrlType["CALCULATED"] = "CALCULATED";
|
|
2315
|
+
})(EApiRequestUrlType || (EApiRequestUrlType = {}));
|
|
2289
2316
|
|
|
2290
2317
|
var EMessageType;
|
|
2291
2318
|
(function (EMessageType) {
|
|
@@ -2520,10 +2547,8 @@ class Apis {
|
|
|
2520
2547
|
constructor(object, takeAction) {
|
|
2521
2548
|
this._object = object;
|
|
2522
2549
|
this._takeAction = takeAction;
|
|
2523
|
-
this.
|
|
2524
|
-
this.
|
|
2525
|
-
this._response = this._object.FIELD_CONFIG.api.response;
|
|
2526
|
-
this._status = this._object.FIELD_CONFIG.api.status;
|
|
2550
|
+
this._request = this._object.API_CONFIG.request;
|
|
2551
|
+
this._response = this._object.API_CONFIG.response;
|
|
2527
2552
|
}
|
|
2528
2553
|
get object() {
|
|
2529
2554
|
return this._object;
|
|
@@ -2531,55 +2556,89 @@ class Apis {
|
|
|
2531
2556
|
set object(value) {
|
|
2532
2557
|
this._object = value;
|
|
2533
2558
|
}
|
|
2559
|
+
setUrl() {
|
|
2560
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2561
|
+
if (this._request.url.hasOwnProperty("type") &&
|
|
2562
|
+
this._request.url.type === EApiRequestUrlType.CALCULATED) {
|
|
2563
|
+
const source = new Source(this._object);
|
|
2564
|
+
const url = yield source.getValueFromSource(this._request.url.props.value.source);
|
|
2565
|
+
this._request.url = setValueToObjectPath(this._request.url, "value", url);
|
|
2566
|
+
}
|
|
2567
|
+
else {
|
|
2568
|
+
this._request.url = setValueToObjectPath({}, "value", this._request.url);
|
|
2569
|
+
}
|
|
2570
|
+
return this._object.API_CONFIG;
|
|
2571
|
+
});
|
|
2572
|
+
}
|
|
2534
2573
|
setRequestBody() {
|
|
2535
2574
|
var _a, _b, _c, _d;
|
|
2536
2575
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2576
|
+
if (checkObjectKeyExists(this._request, "body")) {
|
|
2577
|
+
if (checkObjectKeyExists(this._request.headers, "params")) {
|
|
2578
|
+
let params = this._request.body.params;
|
|
2579
|
+
let paramIndex = 0;
|
|
2580
|
+
for (let param of params) {
|
|
2581
|
+
let sources = param.sources;
|
|
2582
|
+
let sourceIndex = 0;
|
|
2583
|
+
for (let source of sources) {
|
|
2584
|
+
const sources = new Source(this._object);
|
|
2585
|
+
const value = sources.getValueFromSource(source);
|
|
2586
|
+
// Set the Value of current source.
|
|
2587
|
+
this._object.API_CONFIG = setValueToObjectPath(this._object.API_CONFIG, `request.body.params[${paramIndex}].sources[${sourceIndex}].value`, value);
|
|
2588
|
+
const validation = source.validation;
|
|
2589
|
+
const triggers = (_a = validation === null || validation === void 0 ? void 0 : validation.triggers) !== null && _a !== void 0 ? _a : [];
|
|
2590
|
+
const rules = (_b = validation === null || validation === void 0 ? void 0 : validation.rules) !== null && _b !== void 0 ? _b : [];
|
|
2591
|
+
const actions = (_d = (_c = validation) === null || _c === void 0 ? void 0 : _c.actions) !== null && _d !== void 0 ? _d : [];
|
|
2592
|
+
const rulesMapping = new Rule(rules, this._object).mapping();
|
|
2593
|
+
for (let action of actions) {
|
|
2594
|
+
const conditionEvaluation = new Condition(action.condition, rulesMapping).evaluate();
|
|
2595
|
+
if (conditionEvaluation) {
|
|
2596
|
+
const actions = new Action(action, rulesMapping, this._object, this._takeAction);
|
|
2597
|
+
yield actions.execute();
|
|
2598
|
+
}
|
|
2599
|
+
}
|
|
2600
|
+
sourceIndex++;
|
|
2557
2601
|
}
|
|
2602
|
+
paramIndex++;
|
|
2558
2603
|
}
|
|
2559
|
-
|
|
2604
|
+
return this._object.API_CONFIG;
|
|
2605
|
+
}
|
|
2606
|
+
else {
|
|
2607
|
+
return this._object.API_CONFIG;
|
|
2560
2608
|
}
|
|
2561
|
-
paramIndex++;
|
|
2562
2609
|
}
|
|
2563
|
-
|
|
2610
|
+
else {
|
|
2611
|
+
return this._object.API_CONFIG;
|
|
2612
|
+
}
|
|
2564
2613
|
});
|
|
2565
2614
|
}
|
|
2566
2615
|
validateRequestBody() {
|
|
2567
2616
|
var _a;
|
|
2568
2617
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2618
|
+
if (checkObjectKeyExists(this._request, "body")) {
|
|
2619
|
+
if (checkObjectKeyExists(this._request.body, "validation")) {
|
|
2620
|
+
const body = this._request.body;
|
|
2621
|
+
const validation = body.validation;
|
|
2622
|
+
const triggers = validation.triggers;
|
|
2623
|
+
const rules = validation.rules;
|
|
2624
|
+
const actions = (_a = validation) === null || _a === void 0 ? void 0 : _a.actions;
|
|
2625
|
+
const rulesMapping = new Rule(rules, this._object).mapping();
|
|
2626
|
+
for (let action of actions) {
|
|
2627
|
+
const conditionSuccess = new Condition(action.condition, rulesMapping).evaluate();
|
|
2628
|
+
if (conditionSuccess) {
|
|
2629
|
+
const actions = new Action(action, rulesMapping, this._object, this._takeAction);
|
|
2630
|
+
yield actions.execute();
|
|
2631
|
+
}
|
|
2632
|
+
}
|
|
2633
|
+
return this._object.API_CONFIG;
|
|
2634
|
+
}
|
|
2635
|
+
else {
|
|
2636
|
+
return this._object.API_CONFIG;
|
|
2580
2637
|
}
|
|
2581
2638
|
}
|
|
2582
|
-
|
|
2639
|
+
else {
|
|
2640
|
+
return this._object.API_CONFIG;
|
|
2641
|
+
}
|
|
2583
2642
|
});
|
|
2584
2643
|
}
|
|
2585
2644
|
setRequestHeaders() {
|
|
@@ -2596,7 +2655,7 @@ class Apis {
|
|
|
2596
2655
|
const sources = new Source(this._object);
|
|
2597
2656
|
const value = sources.getValueFromSource(source);
|
|
2598
2657
|
// Set the Value of current source.
|
|
2599
|
-
this._object.
|
|
2658
|
+
this._object.API_CONFIG = setValueToObjectPath(this._object.API_CONFIG, `request.headers.params[${paramIndex}].sources[${sourceIndex}].value`, value);
|
|
2600
2659
|
const validation = source.validation;
|
|
2601
2660
|
const triggers = (_a = validation === null || validation === void 0 ? void 0 : validation.triggers) !== null && _a !== void 0 ? _a : [];
|
|
2602
2661
|
const rules = (_b = validation === null || validation === void 0 ? void 0 : validation.rules) !== null && _b !== void 0 ? _b : [];
|
|
@@ -2613,14 +2672,14 @@ class Apis {
|
|
|
2613
2672
|
}
|
|
2614
2673
|
paramIndex++;
|
|
2615
2674
|
}
|
|
2616
|
-
return this._object.
|
|
2675
|
+
return this._object.API_CONFIG;
|
|
2617
2676
|
}
|
|
2618
2677
|
else {
|
|
2619
|
-
return this._object.
|
|
2678
|
+
return this._object.API_CONFIG;
|
|
2620
2679
|
}
|
|
2621
2680
|
}
|
|
2622
2681
|
else {
|
|
2623
|
-
return this._object.
|
|
2682
|
+
return this._object.API_CONFIG;
|
|
2624
2683
|
}
|
|
2625
2684
|
});
|
|
2626
2685
|
}
|
|
@@ -2642,23 +2701,41 @@ class Apis {
|
|
|
2642
2701
|
yield actions.execute();
|
|
2643
2702
|
}
|
|
2644
2703
|
}
|
|
2645
|
-
return this._object.
|
|
2704
|
+
return this._object.API_CONFIG;
|
|
2646
2705
|
}
|
|
2647
2706
|
else {
|
|
2648
|
-
return this._object.
|
|
2707
|
+
return this._object.API_CONFIG;
|
|
2649
2708
|
}
|
|
2650
2709
|
}
|
|
2651
2710
|
else {
|
|
2652
|
-
return this._object.
|
|
2711
|
+
return this._object.API_CONFIG;
|
|
2653
2712
|
}
|
|
2654
2713
|
});
|
|
2655
2714
|
}
|
|
2656
2715
|
validateResponse() {
|
|
2657
2716
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2658
|
-
|
|
2659
|
-
|
|
2717
|
+
if (checkObjectKeyExists(this._response, "validation")) {
|
|
2718
|
+
const validation = this._response.validation;
|
|
2719
|
+
const triggers = validation.triggers;
|
|
2720
|
+
const rules = validation.rules;
|
|
2721
|
+
const actions = validation.actions;
|
|
2722
|
+
const rulesMapping = new Rule(rules, this._object).mapping();
|
|
2723
|
+
for (let action of actions) {
|
|
2724
|
+
const conditionSuccess = new Condition(action.condition, rulesMapping).evaluate();
|
|
2725
|
+
if (conditionSuccess) {
|
|
2726
|
+
const actions = new Action(action, rulesMapping, this._object, this._takeAction);
|
|
2727
|
+
yield actions.execute();
|
|
2728
|
+
}
|
|
2729
|
+
}
|
|
2730
|
+
}
|
|
2731
|
+
return this._object.API_CONFIG;
|
|
2732
|
+
});
|
|
2733
|
+
}
|
|
2734
|
+
callNextApi(validation) {
|
|
2735
|
+
var _a;
|
|
2736
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2660
2737
|
const rules = validation.rules;
|
|
2661
|
-
const actions = validation.actions;
|
|
2738
|
+
const actions = (_a = validation) === null || _a === void 0 ? void 0 : _a.actions;
|
|
2662
2739
|
const rulesMapping = new Rule(rules, this._object).mapping();
|
|
2663
2740
|
for (let action of actions) {
|
|
2664
2741
|
const conditionSuccess = new Condition(action.condition, rulesMapping).evaluate();
|
|
@@ -2667,10 +2744,12 @@ class Apis {
|
|
|
2667
2744
|
yield actions.execute();
|
|
2668
2745
|
}
|
|
2669
2746
|
}
|
|
2670
|
-
return this._object.FIELD_CONFIG;
|
|
2671
2747
|
});
|
|
2672
2748
|
}
|
|
2673
2749
|
}
|
|
2750
|
+
__decorate([
|
|
2751
|
+
logMethod
|
|
2752
|
+
], Apis.prototype, "setUrl", null);
|
|
2674
2753
|
__decorate([
|
|
2675
2754
|
logMethod
|
|
2676
2755
|
], Apis.prototype, "setRequestBody", null);
|
|
@@ -2686,6 +2765,9 @@ __decorate([
|
|
|
2686
2765
|
__decorate([
|
|
2687
2766
|
logMethod
|
|
2688
2767
|
], Apis.prototype, "validateResponse", null);
|
|
2768
|
+
__decorate([
|
|
2769
|
+
logMethod
|
|
2770
|
+
], Apis.prototype, "callNextApi", null);
|
|
2689
2771
|
|
|
2690
2772
|
/**
|
|
2691
2773
|
* Generated class for the SafeHtmlPipe pipe.
|
|
@@ -2770,8 +2852,8 @@ class KwikIDFormViewComponent {
|
|
|
2770
2852
|
this.formGroup = yield this.formViewService.createFormGroup(this.formFields, this.formData, this.previousFormData, this.allFormsData, this.takeAction.bind(this));
|
|
2771
2853
|
for (let field of this.formFields) {
|
|
2772
2854
|
if (field.isFormElement) {
|
|
2773
|
-
this.previousFormData = Object.assign(Object.assign({}, this.previousFormData), { [field.key]: this.formGroup.controls[field.key].value });
|
|
2774
|
-
this.formData = Object.assign(Object.assign({}, this.formData), { [field.key]: this.formGroup.controls[field.key].value });
|
|
2855
|
+
this.previousFormData = Object.assign(Object.assign({}, this.previousFormData), { [field.key]: convertFormFieldValueToStandardFormat(field, this.formGroup.controls[field.key].value) });
|
|
2856
|
+
this.formData = Object.assign(Object.assign({}, this.formData), { [field.key]: convertFormFieldValueToStandardFormat(field, this.formGroup.controls[field.key].value) });
|
|
2775
2857
|
this.formGroup.controls[field.key].valueChanges
|
|
2776
2858
|
.pipe(pairwise())
|
|
2777
2859
|
.subscribe(([previousValue, currentValue]) => {
|
|
@@ -2970,8 +3052,73 @@ class KwikIDFormViewComponent {
|
|
|
2970
3052
|
}
|
|
2971
3053
|
});
|
|
2972
3054
|
}
|
|
2973
|
-
|
|
3055
|
+
handleApiCall(field, api) {
|
|
2974
3056
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
3057
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
3058
|
+
const apis = new Apis({
|
|
3059
|
+
FIELD_CONFIG: field,
|
|
3060
|
+
API_CONFIG: api,
|
|
3061
|
+
FORM_FIELDS: this.formFields,
|
|
3062
|
+
FORM_DATA: this.formData,
|
|
3063
|
+
PREVIOUS_FORM_DATA: this.previousFormData,
|
|
3064
|
+
ALL_FORMS_DATA: this.allFormsData
|
|
3065
|
+
}, this.takeAction.bind(this));
|
|
3066
|
+
api = yield apis.setUrl();
|
|
3067
|
+
api = yield apis.setRequestHeaders();
|
|
3068
|
+
api = yield apis.validateRequestHeaders();
|
|
3069
|
+
api = yield apis.setRequestBody();
|
|
3070
|
+
api = yield apis.validateRequestBody();
|
|
3071
|
+
let apiCallResponse = undefined;
|
|
3072
|
+
if (api.request.body.validation.is_valid) {
|
|
3073
|
+
if (api.request.url.hasOwnProperty("type") &&
|
|
3074
|
+
api.request.url.type === EApiRequestUrlType.MOCK) {
|
|
3075
|
+
apiCallResponse = api.request.url.props.mockedData.data;
|
|
3076
|
+
}
|
|
3077
|
+
else {
|
|
3078
|
+
const url = api.request.url.value;
|
|
3079
|
+
const method = (_b = (_a = api.request) === null || _a === void 0 ? void 0 : _a.method) !== null && _b !== void 0 ? _b : "POST";
|
|
3080
|
+
const headers = Object.assign({ "Content-Type": "application/json" }, (((_d = (_c = api.request) === null || _c === void 0 ? void 0 : _c.headers) === null || _d === void 0 ? void 0 : _d.value) || {}));
|
|
3081
|
+
const body = (_g = (_f = (_e = api.request) === null || _e === void 0 ? void 0 : _e.body) === null || _f === void 0 ? void 0 : _f.value) !== null && _g !== void 0 ? _g : null;
|
|
3082
|
+
const response = yield fetch(url, {
|
|
3083
|
+
method: method,
|
|
3084
|
+
headers: Object.assign({}, headers),
|
|
3085
|
+
body: JSON.stringify(body)
|
|
3086
|
+
});
|
|
3087
|
+
apiCallResponse = yield response.json();
|
|
3088
|
+
}
|
|
3089
|
+
/**
|
|
3090
|
+
* This runs when API is in old format or new.
|
|
3091
|
+
* If Old Format then it directly patches api response to field data
|
|
3092
|
+
*/
|
|
3093
|
+
if (checkObjectKeyExists(field.api, "request")) {
|
|
3094
|
+
this.formData = Object.assign(Object.assign({}, this.formData), { [field.key]: apiCallResponse });
|
|
3095
|
+
this.formGroup.patchValue({
|
|
3096
|
+
[field.key]: apiCallResponse
|
|
3097
|
+
}, { emitEvent: false });
|
|
3098
|
+
}
|
|
3099
|
+
api.response = setMissingKeyValue(api.response, "value", apiCallResponse);
|
|
3100
|
+
const apis = new Apis({
|
|
3101
|
+
FIELD_CONFIG: field,
|
|
3102
|
+
API_CONFIG: api,
|
|
3103
|
+
FORM_FIELDS: this.formFields,
|
|
3104
|
+
FORM_DATA: this.formData,
|
|
3105
|
+
PREVIOUS_FORM_DATA: this.previousFormData,
|
|
3106
|
+
ALL_FORMS_DATA: this.allFormsData
|
|
3107
|
+
}, this.takeAction.bind(this));
|
|
3108
|
+
(() => __awaiter(this, void 0, void 0, function* () {
|
|
3109
|
+
api = yield apis.validateResponse();
|
|
3110
|
+
}))();
|
|
3111
|
+
}
|
|
3112
|
+
else {
|
|
3113
|
+
setTimeout(() => {
|
|
3114
|
+
field["api"]["status"]["value"] = EApiStatusType.FAILED;
|
|
3115
|
+
field["showLoader"] = false;
|
|
3116
|
+
}, 500);
|
|
3117
|
+
}
|
|
3118
|
+
return { field: field, api: api };
|
|
3119
|
+
});
|
|
3120
|
+
}
|
|
3121
|
+
handleOnClickApiCall(e) {
|
|
2975
3122
|
return __awaiter(this, void 0, void 0, function* () {
|
|
2976
3123
|
let field = getFormFieldByKey(this.formFields, e.key);
|
|
2977
3124
|
if (field.type === "api-call") {
|
|
@@ -2982,59 +3129,19 @@ class KwikIDFormViewComponent {
|
|
|
2982
3129
|
this.viewFormsButton["showLoader"] = true;
|
|
2983
3130
|
this.saveFormButton["disabled"] = true;
|
|
2984
3131
|
this.saveFormButton["showLoader"] = true;
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
PREVIOUS_FORM_DATA: this.previousFormData,
|
|
2990
|
-
ALL_FORMS_DATA: this.allFormsData
|
|
2991
|
-
}, this.takeAction.bind(this));
|
|
2992
|
-
field = yield apis.setRequestHeaders();
|
|
2993
|
-
field = yield apis.validateRequestHeaders();
|
|
2994
|
-
field = yield apis.setRequestBody();
|
|
2995
|
-
field = yield apis.validateRequestBody();
|
|
2996
|
-
if (field.api.request.body.validation.is_valid) {
|
|
2997
|
-
// Call API Here
|
|
2998
|
-
let apiCallResponse = undefined;
|
|
2999
|
-
if (field.api.request.url.hasOwnProperty("type") &&
|
|
3000
|
-
field.api.request.url.type === "MOCK") {
|
|
3001
|
-
apiCallResponse = field.api.request.url.data;
|
|
3002
|
-
}
|
|
3003
|
-
else {
|
|
3004
|
-
const url = field.api.request.url;
|
|
3005
|
-
const method = (_b = (_a = field.api.request) === null || _a === void 0 ? void 0 : _a.method) !== null && _b !== void 0 ? _b : "POST";
|
|
3006
|
-
const headers = Object.assign({ "Content-Type": "application/json" }, (((_d = (_c = field.api.request) === null || _c === void 0 ? void 0 : _c.headers) === null || _d === void 0 ? void 0 : _d.value) || {}));
|
|
3007
|
-
const body = (_g = (_f = (_e = field.api.request) === null || _e === void 0 ? void 0 : _e.body) === null || _f === void 0 ? void 0 : _f.value) !== null && _g !== void 0 ? _g : null;
|
|
3008
|
-
const response = yield fetch(url, {
|
|
3009
|
-
method: method,
|
|
3010
|
-
headers: Object.assign({}, headers),
|
|
3011
|
-
body: JSON.stringify(body)
|
|
3012
|
-
});
|
|
3013
|
-
apiCallResponse = yield response.json();
|
|
3014
|
-
}
|
|
3015
|
-
this.formData = Object.assign(Object.assign({}, this.formData), { [field.key]: apiCallResponse });
|
|
3016
|
-
this.formGroup.patchValue({
|
|
3017
|
-
[field.key]: apiCallResponse
|
|
3018
|
-
}, { emitEvent: false });
|
|
3132
|
+
if (checkObjectKeyExists(field.api, "request")) {
|
|
3133
|
+
yield this.handleApiCall(field, field.api);
|
|
3134
|
+
}
|
|
3135
|
+
else {
|
|
3019
3136
|
const apis = new Apis({
|
|
3020
3137
|
FIELD_CONFIG: field,
|
|
3138
|
+
API_CONFIG: {},
|
|
3021
3139
|
FORM_FIELDS: this.formFields,
|
|
3022
3140
|
FORM_DATA: this.formData,
|
|
3023
3141
|
PREVIOUS_FORM_DATA: this.previousFormData,
|
|
3024
3142
|
ALL_FORMS_DATA: this.allFormsData
|
|
3025
3143
|
}, this.takeAction.bind(this));
|
|
3026
|
-
|
|
3027
|
-
field = yield apis.validateResponse();
|
|
3028
|
-
}))();
|
|
3029
|
-
}
|
|
3030
|
-
else {
|
|
3031
|
-
// Request Body Validation Failed
|
|
3032
|
-
// Highlight Error in UI to User to Retry After Sometime.
|
|
3033
|
-
// Take Action based on Validation
|
|
3034
|
-
setTimeout(() => {
|
|
3035
|
-
field["api"]["status"]["value"] = EApiStatusType.FAILED;
|
|
3036
|
-
field["showLoader"] = false;
|
|
3037
|
-
}, 500);
|
|
3144
|
+
yield apis.callNextApi(field.api.entrypoint);
|
|
3038
3145
|
}
|
|
3039
3146
|
this.viewFormsButton["disabled"] = false;
|
|
3040
3147
|
this.viewFormsButton["showLoader"] = false;
|
|
@@ -3269,7 +3376,6 @@ class KwikIDFormViewComponent {
|
|
|
3269
3376
|
field = removeFormFieldMessage(field, message);
|
|
3270
3377
|
this.formFields[fieldIndex] = field;
|
|
3271
3378
|
}
|
|
3272
|
-
setObjectValue(field, path, value) { }
|
|
3273
3379
|
patchFieldControlValue(key, value) {
|
|
3274
3380
|
this.formGroup.patchValue({
|
|
3275
3381
|
[key]: value
|
|
@@ -3280,7 +3386,15 @@ class KwikIDFormViewComponent {
|
|
|
3280
3386
|
throw new Error(`formGroup or formData is 'undefined'.`);
|
|
3281
3387
|
}
|
|
3282
3388
|
else {
|
|
3283
|
-
|
|
3389
|
+
let formDataInKwikUIFormat = {};
|
|
3390
|
+
for (let fieldKey in formData) {
|
|
3391
|
+
const field = getFormFieldByKey(this.formFields, fieldKey);
|
|
3392
|
+
if (!isUndefined(field) && !isNull(field)) {
|
|
3393
|
+
formDataInKwikUIFormat[fieldKey] =
|
|
3394
|
+
convertFormFieldValueToKwikUIFormat(field, formData[fieldKey]);
|
|
3395
|
+
}
|
|
3396
|
+
}
|
|
3397
|
+
this.formGroup.patchValue(formDataInKwikUIFormat, { emitEvent: false });
|
|
3284
3398
|
}
|
|
3285
3399
|
}
|
|
3286
3400
|
isFieldValid(fieldKey) {
|
|
@@ -3411,6 +3525,25 @@ class KwikIDFormViewComponent {
|
|
|
3411
3525
|
break;
|
|
3412
3526
|
case EActionKey.CUSTOM:
|
|
3413
3527
|
break;
|
|
3528
|
+
case EActionKey.API_CALL:
|
|
3529
|
+
const entrypointKey = action.props.apiKey;
|
|
3530
|
+
let apiField = getFormFieldByKey(this.formFields, action.props.fieldKey);
|
|
3531
|
+
const endpoints = apiField.api.endpoints;
|
|
3532
|
+
const nextApiIndex = endpoints.findIndex((api) => api.apiKey == entrypointKey);
|
|
3533
|
+
const response = yield this.handleApiCall(apiField, endpoints[nextApiIndex]);
|
|
3534
|
+
apiField = response.field;
|
|
3535
|
+
apiField.api.endpoints[nextApiIndex] = response.api;
|
|
3536
|
+
break;
|
|
3537
|
+
case EActionKey.API_CALL_END:
|
|
3538
|
+
const field = getFormFieldByKey(this.formFields, action.props.fieldKey);
|
|
3539
|
+
let apiCallResponses = {};
|
|
3540
|
+
field.api.endpoints.map((api) => {
|
|
3541
|
+
if (checkObjectKeyExists(api.response, "value"))
|
|
3542
|
+
apiCallResponses = setMissingKeyValue(apiCallResponses, api.apiKey, api.response.value);
|
|
3543
|
+
});
|
|
3544
|
+
this.formData = Object.assign(Object.assign({}, this.formData), { [field.key]: apiCallResponses });
|
|
3545
|
+
this.patchFormGroup(this.formData);
|
|
3546
|
+
break;
|
|
3414
3547
|
default:
|
|
3415
3548
|
break;
|
|
3416
3549
|
}
|
|
@@ -3461,6 +3594,9 @@ __decorate([
|
|
|
3461
3594
|
__decorate([
|
|
3462
3595
|
logMethod
|
|
3463
3596
|
], KwikIDFormViewComponent.prototype, "handleOnClickResetFormFields", null);
|
|
3597
|
+
__decorate([
|
|
3598
|
+
logMethod
|
|
3599
|
+
], KwikIDFormViewComponent.prototype, "handleApiCall", null);
|
|
3464
3600
|
__decorate([
|
|
3465
3601
|
logMethod
|
|
3466
3602
|
], KwikIDFormViewComponent.prototype, "handleOnClickApiCall", null);
|
|
@@ -3512,9 +3648,6 @@ __decorate([
|
|
|
3512
3648
|
__decorate([
|
|
3513
3649
|
logMethod
|
|
3514
3650
|
], KwikIDFormViewComponent.prototype, "fieldMessageHide", null);
|
|
3515
|
-
__decorate([
|
|
3516
|
-
logMethod
|
|
3517
|
-
], KwikIDFormViewComponent.prototype, "setObjectValue", null);
|
|
3518
3651
|
__decorate([
|
|
3519
3652
|
logMethod
|
|
3520
3653
|
], KwikIDFormViewComponent.prototype, "patchFieldControlValue", null);
|
|
@@ -3564,7 +3697,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImpo
|
|
|
3564
3697
|
type: Output
|
|
3565
3698
|
}], onClickApiCall: [{
|
|
3566
3699
|
type: Output
|
|
3567
|
-
}], ngOnInit: [], ngAfterViewInit: [], ngOnChanges: [], initFormConfig: [], setFormFieldsFromFormConfig: [], setFormFieldGroupsFromFormConfig: [], setFormDataFromAllFormsData: [], handleConnectedElementFieldGroupActions: [], handleConnectedElementFieldGroup: [], handleConnectedElementFieldActions: [], handleConnectedElementFields: [], handleConnectedElements: [], handleGetKeyValue: [], handleOnClickResetFormFields: [], handleOnClickApiCall: [], handleOnClickViewForms: [], handleOnClickSaveForm: [], toggleErrorNotification: [], fieldHide: [], fieldGroupHide: [], fieldShow: [], fieldGroupShow: [], fieldDisable: [], fieldGroupDisable: [], fieldEnable: [], fieldGroupEnable: [], fieldReset: [], fieldErrorShow: [], fieldErrorHide: [], fieldMessageShow: [], fieldMessageHide: [],
|
|
3700
|
+
}], ngOnInit: [], ngAfterViewInit: [], ngOnChanges: [], initFormConfig: [], setFormFieldsFromFormConfig: [], setFormFieldGroupsFromFormConfig: [], setFormDataFromAllFormsData: [], handleConnectedElementFieldGroupActions: [], handleConnectedElementFieldGroup: [], handleConnectedElementFieldActions: [], handleConnectedElementFields: [], handleConnectedElements: [], handleGetKeyValue: [], handleOnClickResetFormFields: [], handleApiCall: [], handleOnClickApiCall: [], handleOnClickViewForms: [], handleOnClickSaveForm: [], toggleErrorNotification: [], fieldHide: [], fieldGroupHide: [], fieldShow: [], fieldGroupShow: [], fieldDisable: [], fieldGroupDisable: [], fieldEnable: [], fieldGroupEnable: [], fieldReset: [], fieldErrorShow: [], fieldErrorHide: [], fieldMessageShow: [], fieldMessageHide: [], patchFieldControlValue: [], patchFormGroup: [], isFieldValid: [], isFieldEnabled: [], getFormGroupRawValues: [], takeActionOnFieldGroup: [], takeAction: [] } });
|
|
3568
3701
|
|
|
3569
3702
|
/**
|
|
3570
3703
|
* Generated class for the SafeHtmlPipe pipe.
|