kwikid-forms 0.5.1 → 0.5.3

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.
@@ -1,7 +1,7 @@
1
1
  import { __decorate, __awaiter } from 'tslib';
2
2
  import * as i0 from '@angular/core';
3
3
  import { EventEmitter, Component, Input, Output, ChangeDetectionStrategy, Inject, ViewChild, HostListener, NgModule } from '@angular/core';
4
- import { checkObjectKeyExists, setValueToObjectPath, isEmptyValue, getObjectDeepCopy, logMethod, isNotEmptyValue, mergeObjects, checkObjectPathExists, setMissingKeyValue, getObjectValueFromPath, getObjectFromLocalStorage, Source, Rule, Condition, Action, PATTERNS, Validation, ESourceKey, replaceString, isUndefined, isNull } from 'kwikid-toolkit';
4
+ import { checkObjectKeyExists, setValueToObjectPath, isEmptyValue, getObjectDeepCopy, logMethod, isNotEmptyValue, mergeObjects, checkObjectPathExists, setMissingKeyValue, getObjectValueFromPath, getObjectFromLocalStorage, Source, Rule, Condition, Action, PATTERNS, Validation, ESourceKey, replaceString, isUndefined, isNull, isEmptyString } from 'kwikid-toolkit';
5
5
  import * as i3$1 from '@angular/forms';
6
6
  import { FormGroup, FormControl, Validators, FormArray, FormsModule, ReactiveFormsModule } from '@angular/forms';
7
7
  import * as i2 from 'kwikui';
@@ -1105,6 +1105,7 @@ const OPTIONS = {
1105
1105
  "select",
1106
1106
  "slider",
1107
1107
  "otp",
1108
+ "api",
1108
1109
  "api-call",
1109
1110
  "aadhaar-number",
1110
1111
  "input-aadhaar",
@@ -1231,6 +1232,7 @@ const FIELD_PROPERTIES_CONFIG = {
1231
1232
  select: Object.assign({}, FIELD_PROPERTIES_COMMON_CONFIG),
1232
1233
  slider: Object.assign(Object.assign({}, FIELD_PROPERTIES_COMMON_CONFIG), { min: -Infinity, max: Infinity, quantum: 0, size: "m", steps: 1 }),
1233
1234
  otp: Object.assign(Object.assign({}, FIELD_PROPERTIES_COMMON_CONFIG), { mask: "", size: "m", mode: "multiple", otpLength: 6 }),
1235
+ api: Object.assign({}, FIELD_PROPERTIES_COMMON_CONFIG),
1234
1236
  "api-call": Object.assign({}, FIELD_PROPERTIES_COMMON_CONFIG),
1235
1237
  "aadhaar-number": Object.assign({}, FIELD_PROPERTIES_COMMON_CONFIG),
1236
1238
  "input-aadhaar": Object.assign({}, FIELD_PROPERTIES_COMMON_CONFIG),
@@ -1258,6 +1260,7 @@ const FIELD_CONFIG = {
1258
1260
  select: Object.assign(Object.assign({}, FIELD_COMMON_CONFIG), { type: "select", properties: Object.assign({}, FIELD_PROPERTIES_CONFIG["select"]), options: [] }),
1259
1261
  slider: Object.assign(Object.assign({}, FIELD_COMMON_CONFIG), { type: "slider", properties: Object.assign({}, FIELD_PROPERTIES_CONFIG.slider) }),
1260
1262
  otp: Object.assign(Object.assign({}, FIELD_COMMON_CONFIG), { type: "otp", properties: Object.assign({}, FIELD_PROPERTIES_CONFIG.otp) }),
1263
+ api: Object.assign(Object.assign({}, FIELD_COMMON_CONFIG), { type: "api", properties: Object.assign({}, FIELD_PROPERTIES_CONFIG["api"]) }),
1261
1264
  "api-call": Object.assign(Object.assign({}, FIELD_COMMON_CONFIG), { type: "api-call", properties: Object.assign({}, FIELD_PROPERTIES_CONFIG["api-call"]) }),
1262
1265
  "aadhaar-number": Object.assign(Object.assign({}, FIELD_COMMON_CONFIG), { type: "aadhaar-number", properties: Object.assign({}, FIELD_PROPERTIES_CONFIG["aadhaar-number"]) }),
1263
1266
  "input-aadhaar": Object.assign(Object.assign({}, FIELD_COMMON_CONFIG), { type: "input-aadhaar", properties: Object.assign({}, FIELD_PROPERTIES_CONFIG["input-aadhaar"]) }),
@@ -1881,6 +1884,7 @@ var EActionKey;
1881
1884
  EActionKey["DIALOG_HIDE"] = "DIALOG_HIDE";
1882
1885
  EActionKey["RESUME_TASK_EXECUTION"] = "RESUME_TASK_EXECUTION";
1883
1886
  EActionKey["STOP_TASK_EXECUTION"] = "STOP_TASK_EXECUTION";
1887
+ EActionKey["REDIRECT_TO_URL"] = "REDIRECT_TO_URL";
1884
1888
  })(EActionKey || (EActionKey = {}));
1885
1889
 
1886
1890
  var EApiStatusType;
@@ -2920,7 +2924,7 @@ class KwikIDFormViewComponent {
2920
2924
  PREVIOUS_FORM_DATA: this.previousFormData,
2921
2925
  ALL_FORMS_DATA: this.allFormsData
2922
2926
  });
2923
- if (this.validateHeadersAndBody(api)) {
2927
+ if (this.isValidRequestHeadersAndBody(api)) {
2924
2928
  if (checkObjectKeyExists(field.api, "request")) {
2925
2929
  this.formData = Object.assign(Object.assign({}, this.formData), { [field.key]: api.response.value });
2926
2930
  this.formGroup.patchValue({
@@ -2930,6 +2934,7 @@ class KwikIDFormViewComponent {
2930
2934
  const apis = new Apis({
2931
2935
  FIELD_CONFIG: field,
2932
2936
  API_CONFIG: api,
2937
+ API_RESPONSE: api.response,
2933
2938
  FORM_FIELDS: this.formFields,
2934
2939
  FORM_DATA: this.formData,
2935
2940
  TASK_DATA: this.taskData,
@@ -2967,7 +2972,7 @@ class KwikIDFormViewComponent {
2967
2972
  PREVIOUS_FORM_DATA: this.previousFormData,
2968
2973
  ALL_FORMS_DATA: this.allFormsData
2969
2974
  }, this.takeAction.bind(this));
2970
- if (this.validateHeadersAndBody(api)) {
2975
+ if (this.isValidRequestHeadersAndBody(api)) {
2971
2976
  api = yield apis.validateResponse();
2972
2977
  }
2973
2978
  return { api: api };
@@ -2983,7 +2988,8 @@ class KwikIDFormViewComponent {
2983
2988
  api = yield apis.setRequestBody();
2984
2989
  api = yield apis.validateRequestBody();
2985
2990
  let apiCallResponse = {};
2986
- if (this.validateHeadersAndBody(api)) {
2991
+ let apiCallResponseStatusCode;
2992
+ if (this.isValidRequestHeadersAndBody(api)) {
2987
2993
  if (api.request.url.hasOwnProperty("type") &&
2988
2994
  api.request.url.type === EApiRequestUrlType.MOCK) {
2989
2995
  apiCallResponse = yield new Promise((resolve) => {
@@ -3004,6 +3010,7 @@ class KwikIDFormViewComponent {
3004
3010
  headers: Object.assign({}, headers)
3005
3011
  });
3006
3012
  apiCallResponse = yield response.json();
3013
+ apiCallResponseStatusCode = response.status;
3007
3014
  }
3008
3015
  catch (err) {
3009
3016
  apiCallResponse = {};
@@ -3017,6 +3024,7 @@ class KwikIDFormViewComponent {
3017
3024
  body: JSON.stringify(body)
3018
3025
  });
3019
3026
  apiCallResponse = yield response.json();
3027
+ apiCallResponseStatusCode = response.status;
3020
3028
  }
3021
3029
  catch (err) {
3022
3030
  apiCallResponse = {};
@@ -3024,15 +3032,14 @@ class KwikIDFormViewComponent {
3024
3032
  }
3025
3033
  }
3026
3034
  api.response = setValueToObjectPath(api.response, "value", apiCallResponse);
3035
+ api.response = setValueToObjectPath(api.response, "status", apiCallResponseStatusCode);
3027
3036
  }
3028
3037
  return api;
3029
3038
  });
3030
3039
  }
3031
- validateHeadersAndBody(api) {
3032
- return __awaiter(this, void 0, void 0, function* () {
3033
- return (api.request.body.validation.is_valid &&
3034
- api.request.headers.validation.is_valid);
3035
- });
3040
+ isValidRequestHeadersAndBody(api) {
3041
+ return (api.request.body.validation.is_valid &&
3042
+ api.request.headers.validation.is_valid);
3036
3043
  }
3037
3044
  showApiLoader() {
3038
3045
  this.apiLoading = true;
@@ -3051,7 +3058,7 @@ class KwikIDFormViewComponent {
3051
3058
  handleOnClickApiCall(e) {
3052
3059
  return __awaiter(this, void 0, void 0, function* () {
3053
3060
  let field = getFormFieldByKey(this.formFields, e.key);
3054
- if (field.type === "api-call") {
3061
+ if (field.type === EFieldType.API) {
3055
3062
  // set button status to loading
3056
3063
  field["api"]["status"]["value"] = EApiStatusType.LOADING;
3057
3064
  field["showLoader"] = true;
@@ -3327,7 +3334,7 @@ class KwikIDFormViewComponent {
3327
3334
  });
3328
3335
  // Reset the value of the field in the formFields array
3329
3336
  switch (field.type) {
3330
- case "api-call":
3337
+ case EFieldType.API:
3331
3338
  const fieldApiCall = field;
3332
3339
  fieldApiCall.api.status.value = EApiStatusType.DEFAULT;
3333
3340
  this.formFields[fieldIndex] = fieldApiCall;
@@ -3552,6 +3559,20 @@ class KwikIDFormViewComponent {
3552
3559
  this.dialogRef.complete();
3553
3560
  }
3554
3561
  }
3562
+ redirectToUrl(action) {
3563
+ if (checkObjectKeyExists(action.props, "url")) {
3564
+ if (checkObjectKeyExists(action.props.url, "url")) {
3565
+ let timeout = 2000;
3566
+ if (checkObjectKeyExists(action.props.url, "timeout") &&
3567
+ typeof action.props.url.timeout == "number") {
3568
+ timeout = action.props.url.timeout;
3569
+ }
3570
+ setTimeout(() => {
3571
+ window.location.replace(action.props.url.url);
3572
+ }, timeout);
3573
+ }
3574
+ }
3575
+ }
3555
3576
  patchFieldControlValue(key, value) {
3556
3577
  this.formGroup.controls[key].patchValue(value, { emitEvent: false });
3557
3578
  }
@@ -3775,21 +3796,31 @@ class KwikIDFormViewComponent {
3775
3796
  case EActionKey.TASK_API_CALL_MULTIPLE_END:
3776
3797
  yield this.taskMultipleApiCallsEnd(action, object);
3777
3798
  break;
3799
+ case EActionKey.REDIRECT_TO_URL:
3800
+ if (checkObjectKeyExists(action.props.url, "source")) {
3801
+ const redirectToUrl_Source = new Source(object);
3802
+ let redirectToUrlSourceValue = yield redirectToUrl_Source.getValueFromSource(action.props.url.source);
3803
+ if (isEmptyString(redirectToUrlSourceValue)) {
3804
+ redirectToUrlSourceValue = "";
3805
+ }
3806
+ action = setValueToObjectPath(action, "props.url.url", redirectToUrlSourceValue);
3807
+ }
3808
+ this.redirectToUrl(action);
3778
3809
  case EActionKey.PREVIEW_DIALOG_SHOW:
3779
3810
  this.showPreview(action.props);
3780
3811
  break;
3781
3812
  case EActionKey.PREVIEW_ERROR_SHOW:
3782
3813
  if (checkObjectKeyExists(action.props.message, "source")) {
3783
- const fieldErrorShow_Source = new Source(object);
3784
- let fieldErrorShowSourceValue = yield fieldErrorShow_Source.getValueFromSource(action.props.message.source);
3785
- if (typeof fieldErrorShowSourceValue == "string" ||
3786
- typeof fieldErrorShowSourceValue == "number") {
3787
- fieldErrorShowSourceValue = String(fieldErrorShowSourceValue);
3814
+ const previewErrorShow_Source = new Source(object);
3815
+ let previewErrorShowSourceValue = yield previewErrorShow_Source.getValueFromSource(action.props.message.source);
3816
+ if (typeof previewErrorShowSourceValue == "string" ||
3817
+ typeof previewErrorShowSourceValue == "number") {
3818
+ previewErrorShowSourceValue = String(previewErrorShowSourceValue);
3788
3819
  }
3789
3820
  else {
3790
- fieldErrorShowSourceValue = "";
3821
+ previewErrorShowSourceValue = "";
3791
3822
  }
3792
- action = setValueToObjectPath(action, "props.message.message", fieldErrorShowSourceValue);
3823
+ action = setValueToObjectPath(action, "props.message.message", previewErrorShowSourceValue);
3793
3824
  }
3794
3825
  this.showErrorPreview(action.props);
3795
3826
  break;
@@ -3895,7 +3926,7 @@ __decorate([
3895
3926
  ], KwikIDFormViewComponent.prototype, "executeApiCall", null);
3896
3927
  __decorate([
3897
3928
  logMethod
3898
- ], KwikIDFormViewComponent.prototype, "validateHeadersAndBody", null);
3929
+ ], KwikIDFormViewComponent.prototype, "isValidRequestHeadersAndBody", null);
3899
3930
  __decorate([
3900
3931
  logMethod
3901
3932
  ], KwikIDFormViewComponent.prototype, "handleOnClickApiCall", null);
@@ -3986,6 +4017,9 @@ __decorate([
3986
4017
  __decorate([
3987
4018
  logMethod
3988
4019
  ], KwikIDFormViewComponent.prototype, "dialogHide", null);
4020
+ __decorate([
4021
+ logMethod
4022
+ ], KwikIDFormViewComponent.prototype, "redirectToUrl", null);
3989
4023
  __decorate([
3990
4024
  logMethod
3991
4025
  ], KwikIDFormViewComponent.prototype, "patchFieldControlValue", null);
@@ -4069,7 +4103,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImpo
4069
4103
  type: Output
4070
4104
  }], onActionShowPopupForm: [{
4071
4105
  type: Output
4072
- }], ngOnInit: [], ngAfterViewInit: [], ngOnChanges: [], initFormConfig: [], setFormFieldsFromFormConfig: [], setFormFieldGroupsFromFormConfig: [], setFormDataFromAllFormsData: [], handleConnectedElementFieldGroupActions: [], handleConnectedElementFieldGroup: [], handleConnectedElementFieldActions: [], handleConnectedElementFields: [], handleConnectedElements: [], handleRemovedFile: [], handleGetKeyValueFile: [], updateFiles: [], uploadFile: [], handleGetKeyValue: [], handleOnClickResetFormFields: [], handleFieldApiCall: [], handleApiCall: [], executeApiCall: [], validateHeadersAndBody: [], handleOnClickApiCall: [], handleOnClickGoBack: [], handleOnClickViewForms: [], handleOnClickSaveForm: [], toggleErrorNotification: [], fieldHide: [], fieldGroupHide: [], fieldShow: [], fieldGroupShow: [], fieldDisable: [], fieldGroupDisable: [], fieldEnable: [], fieldGroupEnable: [], fieldReset: [], fieldErrorShow: [], fieldErrorHide: [], fieldMessageShow: [], fieldMessageHide: [], setValue: [], setFieldDefaultValue: [], setDropdownOptions: [], apiCall: [], fieldApiCall: [], fieldMultipleApiCalls: [], fieldMultipleApiCallsEnd: [], taskApiCall: [], taskMultipleApiCalls: [], taskMultipleApiCallsEnd: [], dialogShow: [], dialogHide: [], patchFieldControlValue: [], setFieldControlValue: [], patchFormGroup: [], isFieldValid: [], isFieldEnabled: [], getFormGroupRawValues: [], showPreview: [], showErrorPreview: [], showPopupForm: [], takeActionOnFieldGroup: [], takeAction: [] } });
4106
+ }], ngOnInit: [], ngAfterViewInit: [], ngOnChanges: [], initFormConfig: [], setFormFieldsFromFormConfig: [], setFormFieldGroupsFromFormConfig: [], setFormDataFromAllFormsData: [], handleConnectedElementFieldGroupActions: [], handleConnectedElementFieldGroup: [], handleConnectedElementFieldActions: [], handleConnectedElementFields: [], handleConnectedElements: [], handleRemovedFile: [], handleGetKeyValueFile: [], updateFiles: [], uploadFile: [], handleGetKeyValue: [], handleOnClickResetFormFields: [], handleFieldApiCall: [], handleApiCall: [], executeApiCall: [], isValidRequestHeadersAndBody: [], handleOnClickApiCall: [], handleOnClickGoBack: [], handleOnClickViewForms: [], handleOnClickSaveForm: [], toggleErrorNotification: [], fieldHide: [], fieldGroupHide: [], fieldShow: [], fieldGroupShow: [], fieldDisable: [], fieldGroupDisable: [], fieldEnable: [], fieldGroupEnable: [], fieldReset: [], fieldErrorShow: [], fieldErrorHide: [], fieldMessageShow: [], fieldMessageHide: [], setValue: [], setFieldDefaultValue: [], setDropdownOptions: [], apiCall: [], fieldApiCall: [], fieldMultipleApiCalls: [], fieldMultipleApiCallsEnd: [], taskApiCall: [], taskMultipleApiCalls: [], taskMultipleApiCallsEnd: [], dialogShow: [], dialogHide: [], redirectToUrl: [], patchFieldControlValue: [], setFieldControlValue: [], patchFormGroup: [], isFieldValid: [], isFieldEnabled: [], getFormGroupRawValues: [], showPreview: [], showErrorPreview: [], showPopupForm: [], takeActionOnFieldGroup: [], takeAction: [] } });
4073
4107
 
4074
4108
  var EFormType;
4075
4109
  (function (EFormType) {