@integry/sdk 4.7.39 → 4.7.41

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.
Files changed (267) hide show
  1. package/dist/esm/index.csm.js +1 -1
  2. package/dist/umd/index.umd.js +1 -1
  3. package/package.json +6 -1
  4. package/.eslintignore +0 -1
  5. package/.vscode/launch.json +0 -17
  6. package/CHANGELOG_INTERNAL.md +0 -134
  7. package/README_INTERNAL.md +0 -176
  8. package/THIRD_PARTY_LICENSES +0 -525
  9. package/generateTests.js +0 -80
  10. package/jest.config.cjs +0 -10
  11. package/src/components/AddTagButton/index.ts +0 -23
  12. package/src/components/BasicSelect/index.ts +0 -123
  13. package/src/components/BasicSelect/styles.module.scss +0 -44
  14. package/src/components/Button/index.ts +0 -97
  15. package/src/components/Button/styles.module.scss +0 -152
  16. package/src/components/CheckboxGroup/Checkbox.ts +0 -104
  17. package/src/components/CheckboxGroup/index.ts +0 -190
  18. package/src/components/CheckboxGroup/styles.module.scss +0 -63
  19. package/src/components/CollapsedMenu/index.ts +0 -104
  20. package/src/components/CollapsedMenu/styles.module.scss +0 -46
  21. package/src/components/ConfigureFieldWrapper/index.ts +0 -85
  22. package/src/components/ConfigureFieldWrapper/styles.module.scss +0 -57
  23. package/src/components/EditableText/index.ts +0 -121
  24. package/src/components/EditableText/styles.module.scss +0 -38
  25. package/src/components/EditableTextArea/index.ts +0 -143
  26. package/src/components/EditableTextArea/styles.module.scss +0 -91
  27. package/src/components/ErrorMessage/index.ts +0 -16
  28. package/src/components/ErrorMessage/styles.module.scss +0 -19
  29. package/src/components/ErrorPage/index.ts +0 -42
  30. package/src/components/ErrorPage/styles.module.scss +0 -26
  31. package/src/components/Footer/index.ts +0 -41
  32. package/src/components/Footer/styles.module.scss +0 -40
  33. package/src/components/HTMLContent/index.tsx +0 -205
  34. package/src/components/HTMLContent/styles.module.scss +0 -3
  35. package/src/components/InfoBox/index.ts +0 -48
  36. package/src/components/InfoBox/styles.module.scss +0 -21
  37. package/src/components/Input/BaseInput/index.ts +0 -170
  38. package/src/components/Input/BaseInput/styles.module.scss +0 -95
  39. package/src/components/Input/DateInput/index.ts +0 -103
  40. package/src/components/Input/DateInput/styles.module.scss +0 -50
  41. package/src/components/Input/Input/index.ts +0 -225
  42. package/src/components/Input/Input/styles.module.scss +0 -16
  43. package/src/components/Input/PasswordInput/index.ts +0 -164
  44. package/src/components/Input/PasswordInput/styles.module.scss +0 -37
  45. package/src/components/Input/index.ts +0 -7
  46. package/src/components/Label/index.ts +0 -61
  47. package/src/components/Label/styles.module.scss +0 -41
  48. package/src/components/LargeLoader/index.ts +0 -25
  49. package/src/components/LargeLoader/styles.module.scss +0 -16
  50. package/src/components/Listbox/ListBoxItem.ts +0 -57
  51. package/src/components/Listbox/index.ts +0 -488
  52. package/src/components/Listbox/styles.module.scss +0 -197
  53. package/src/components/Loader/index.ts +0 -25
  54. package/src/components/Loader/styles.module.scss +0 -16
  55. package/src/components/MediaGallery/MediaGalleryModal.ts +0 -82
  56. package/src/components/MediaGallery/MediaSlider.ts +0 -76
  57. package/src/components/MediaGallery/index.ts +0 -92
  58. package/src/components/MediaGallery/styles.module.scss +0 -156
  59. package/src/components/MediaUpload/index.ts +0 -233
  60. package/src/components/MediaUpload/styles.module.scss +0 -118
  61. package/src/components/Modal/index.ts +0 -87
  62. package/src/components/Modal/styles.module.scss +0 -441
  63. package/src/components/MultipurposeField/Dropdown/ListBoxItem.tsx +0 -59
  64. package/src/components/MultipurposeField/Dropdown/index.tsx +0 -1202
  65. package/src/components/MultipurposeField/Dropdown/styles.module.scss +0 -215
  66. package/src/components/MultipurposeField/TagMenu/index.ts +0 -536
  67. package/src/components/MultipurposeField/TagMenu/styles.module.scss +0 -175
  68. package/src/components/MultipurposeField/TagOptions/index.tsx +0 -83
  69. package/src/components/MultipurposeField/TagOptions/styles.module.scss +0 -95
  70. package/src/components/MultipurposeField/index.tsx +0 -944
  71. package/src/components/MultipurposeField/styles.module.scss +0 -77
  72. package/src/components/NewModal/index.ts +0 -69
  73. package/src/components/NewModal/styles.module.scss +0 -70
  74. package/src/components/OverflowTooltip/index.tsx +0 -59
  75. package/src/components/PopUp/ConfirmationPopUp/index.ts +0 -58
  76. package/src/components/PopUp/ConfirmationPopUp/styles.module.scss +0 -49
  77. package/src/components/PopUp/SuccessPopUp/index.ts +0 -62
  78. package/src/components/PopUp/SuccessPopUp/styles.module.scss +0 -38
  79. package/src/components/RadioGroup/Radio.ts +0 -128
  80. package/src/components/RadioGroup/index.ts +0 -169
  81. package/src/components/RadioGroup/styles.module.scss +0 -81
  82. package/src/components/Search/index.ts +0 -69
  83. package/src/components/Search/styles.module.scss +0 -149
  84. package/src/components/TabBar/Tab.ts +0 -33
  85. package/src/components/TabBar/index.ts +0 -64
  86. package/src/components/TabBar/styles.module.scss +0 -43
  87. package/src/components/Tag/index.ts +0 -29
  88. package/src/components/Tag/styles.module.scss +0 -57
  89. package/src/components/TagsMenu/index.ts +0 -1697
  90. package/src/components/TagsMenu/styles.module.scss +0 -350
  91. package/src/components/TestComponent/index.ts +0 -71
  92. package/src/components/TestComponent/styles.module.scss +0 -152
  93. package/src/components/TextArea/index.ts +0 -172
  94. package/src/components/TextArea/styles.module.scss +0 -72
  95. package/src/components/TextContent/index.tsx +0 -128
  96. package/src/components/TextContent/styles.module.scss +0 -6
  97. package/src/components/ThreeDotLoader/index.ts +0 -39
  98. package/src/components/ThreeDotLoader/styles.module.scss +0 -41
  99. package/src/components/TimeInput/index.ts +0 -129
  100. package/src/components/TimeInput/styles.module.scss +0 -16
  101. package/src/components/Toggle/index.ts +0 -34
  102. package/src/components/Toggle/styles.module.scss +0 -56
  103. package/src/components/Toggle-v2/index.ts +0 -40
  104. package/src/components/Toggle-v2/styles.module.scss +0 -86
  105. package/src/components/Tooltip/index.ts +0 -271
  106. package/src/components/Tooltip/styles.module.scss +0 -105
  107. package/src/components/form/FunctionField/index.ts +0 -816
  108. package/src/components/form/FunctionField/styles.module.scss +0 -478
  109. package/src/components/form/ObjectField/__snapshots__/index.ts.test.tsx.snap +0 -3
  110. package/src/components/form/ObjectField/index.ts +0 -593
  111. package/src/components/form/ObjectField/index.ts.test.tsx +0 -213
  112. package/src/components/form/ObjectField/styles.module.scss +0 -103
  113. package/src/components/form/index.ts +0 -4
  114. package/src/contexts/AppContext.ts +0 -12
  115. package/src/declaration.d.ts +0 -7
  116. package/src/extensions/HMAC.ts +0 -25
  117. package/src/extensions/IntegryAPIError.ts +0 -19
  118. package/src/features/common/AccountDropdown/index.ts +0 -291
  119. package/src/features/common/AccountDropdown/styles.module.scss +0 -19
  120. package/src/features/common/ActionForm/index.ts +0 -2602
  121. package/src/features/common/ActionForm/styles.module.scss +0 -35
  122. package/src/features/common/AppCard/index.ts +0 -207
  123. package/src/features/common/AppCard/styles.module.scss +0 -117
  124. package/src/features/common/AppCardCompact/index.ts +0 -189
  125. package/src/features/common/AppCardCompact/styles.module.scss +0 -141
  126. package/src/features/common/AuthSelector/index.ts +0 -537
  127. package/src/features/common/AuthSelector/styles.module.scss +0 -161
  128. package/src/features/common/AuthSelectorCompact/index.ts +0 -706
  129. package/src/features/common/AuthSelectorCompact/styles.module.scss +0 -219
  130. package/src/features/common/AuthSelectorDropdown/index.ts +0 -704
  131. package/src/features/common/AuthSelectorDropdown/styles.module.scss +0 -361
  132. package/src/features/common/AuthSelectorV2/index.ts +0 -336
  133. package/src/features/common/AuthSelectorV2/styles.module.scss +0 -235
  134. package/src/features/common/DynamicField/index.ts +0 -402
  135. package/src/features/common/DynamicField/styles.module.scss +0 -266
  136. package/src/features/common/DynamicTypedField/index.ts +0 -504
  137. package/src/features/common/DynamicTypedField/styles.module.scss +0 -135
  138. package/src/features/common/FunctionForm/index.ts +0 -1095
  139. package/src/features/common/FunctionForm/styles.module.scss +0 -225
  140. package/src/features/common/MappingUI/index.ts +0 -649
  141. package/src/features/common/MappingUI/styles.module.scss +0 -121
  142. package/src/features/common/MarketplaceAppCard/index.ts +0 -279
  143. package/src/features/common/MarketplaceAppCard/styles.module.scss +0 -231
  144. package/src/features/common/MarketplaceAppCardCompact/index.ts +0 -283
  145. package/src/features/common/MarketplaceAppCardCompact/styles.module.scss +0 -255
  146. package/src/features/common/NewMappingUI/index.ts +0 -515
  147. package/src/features/common/NewMappingUI/styles.module.scss +0 -113
  148. package/src/features/common/RequestAppWidget/RequestAppModal/index.ts +0 -67
  149. package/src/features/common/RequestAppWidget/RequestAppModal/styles.module.scss +0 -23
  150. package/src/features/common/RequestAppWidget/index.ts +0 -48
  151. package/src/features/common/RequestAppWidget/request-app-form.ts +0 -89
  152. package/src/features/common/RequestAppWidget/styles.module.scss +0 -43
  153. package/src/features/common/SectionField/index.ts +0 -272
  154. package/src/features/common/SectionField/styles.module.scss +0 -67
  155. package/src/features/common/Step/index.ts +0 -827
  156. package/src/features/common/Step/styles.module.scss +0 -12
  157. package/src/features/common/StepNavigation/CollapsedSteps.ts +0 -131
  158. package/src/features/common/StepNavigation/NavItem.ts +0 -111
  159. package/src/features/common/StepNavigation/index.ts +0 -261
  160. package/src/features/common/StepNavigation/styles.module.scss +0 -117
  161. package/src/features/common/Steps/index.ts +0 -1140
  162. package/src/features/common/Steps/styles.module.scss +0 -314
  163. package/src/features/containers/AppFlowContainer/AppFlowListing/compactStyles.module.scss +0 -404
  164. package/src/features/containers/AppFlowContainer/AppFlowListing/flow-instance.tsx +0 -367
  165. package/src/features/containers/AppFlowContainer/AppFlowListing/flowCard.test.tsx +0 -58
  166. package/src/features/containers/AppFlowContainer/AppFlowListing/flowCard.tsx +0 -208
  167. package/src/features/containers/AppFlowContainer/AppFlowListing/flowCardCompact.test.tsx +0 -49
  168. package/src/features/containers/AppFlowContainer/AppFlowListing/flowCardCompact.tsx +0 -421
  169. package/src/features/containers/AppFlowContainer/AppFlowListing/flowInstanceCompact.tsx +0 -577
  170. package/src/features/containers/AppFlowContainer/AppFlowListing/index.tsx +0 -83
  171. package/src/features/containers/AppFlowContainer/AppFlowListing/styles.module.scss +0 -233
  172. package/src/features/containers/AppFlowContainer/AppFlowWrap/app-page-loader.tsx +0 -45
  173. package/src/features/containers/AppFlowContainer/AppFlowWrap/index.tsx +0 -1085
  174. package/src/features/containers/AppFlowContainer/AppFlowWrap/styles.module.scss +0 -465
  175. package/src/features/containers/AppFlowContainer/Authentication/index.ts +0 -610
  176. package/src/features/containers/AppFlowContainer/Authentication/styles.module.scss +0 -468
  177. package/src/features/containers/AppFlowContainer/index.ts +0 -114
  178. package/src/features/containers/AppPageContainer/AppPage/index.tsx +0 -262
  179. package/src/features/containers/AppPageContainer/AppPage/styles.module.scss +0 -120
  180. package/src/features/containers/AppPageContainer/IntegrationCard/index.ts +0 -165
  181. package/src/features/containers/AppPageContainer/IntegrationCard/styles.module.scss +0 -81
  182. package/src/features/containers/AppPageContainer/index.tsx +0 -93
  183. package/src/features/containers/AppPageContainer/styles.module.scss +0 -0
  184. package/src/features/containers/AppsForFlows/index.ts +0 -161
  185. package/src/features/containers/AppsForFlows/styles.module.scss +0 -280
  186. package/src/features/containers/AppsForFlowsCompact/index.ts +0 -161
  187. package/src/features/containers/AppsForFlowsCompact/styles.module.scss +0 -279
  188. package/src/features/containers/AuthSetupContainer/AppSelection.ts +0 -73
  189. package/src/features/containers/AuthSetupContainer/AuthTypeSelection.ts +0 -67
  190. package/src/features/containers/AuthSetupContainer/Footer.ts +0 -32
  191. package/src/features/containers/AuthSetupContainer/Header.ts +0 -39
  192. package/src/features/containers/AuthSetupContainer/PostAdditionPopup.ts +0 -27
  193. package/src/features/containers/AuthSetupContainer/index.ts +0 -349
  194. package/src/features/containers/AuthSetupContainer/styles.module.scss +0 -229
  195. package/src/features/containers/FlowSetupContainer/index.ts +0 -391
  196. package/src/features/containers/FlowSetupContainer/styles.module.scss +0 -18
  197. package/src/features/containers/MarkeplaceApps/index.ts +0 -583
  198. package/src/features/containers/MarkeplaceApps/styles.module.scss +0 -558
  199. package/src/features/containers/MarketplaceAppsCompact/index.ts +0 -585
  200. package/src/features/containers/MarketplaceAppsCompact/styles.module.scss +0 -563
  201. package/src/features/containers/MarketplaceAppsContainer/index.ts +0 -91
  202. package/src/features/containers/MarketplaceContainer/AppCard/index.ts +0 -91
  203. package/src/features/containers/MarketplaceContainer/AppCard/styles.module.scss +0 -66
  204. package/src/features/containers/MarketplaceContainer/AppListing/index.ts +0 -34
  205. package/src/features/containers/MarketplaceContainer/AppListing/styles.module.scss +0 -10
  206. package/src/features/containers/MarketplaceContainer/MarketplaceContentWrap/index.ts +0 -132
  207. package/src/features/containers/MarketplaceContainer/MarketplaceContentWrap/styles.module.scss +0 -117
  208. package/src/features/containers/MarketplaceContainer/index.ts +0 -242
  209. package/src/features/containers/MarketplaceContainer/styles.module.scss +0 -84
  210. package/src/features/containers/SDKContainer/index.ts +0 -817
  211. package/src/features/containers/SDKContainer/styles.module.scss +0 -266
  212. package/src/features/containers/SDKDebugContainer/index.ts +0 -137
  213. package/src/features/containers/SDKDebugContainer/styles.module.scss +0 -37
  214. package/src/features/containers/SDKFailedContainer/index.ts +0 -117
  215. package/src/features/containers/SDKFailedContainer/styles.module.scss +0 -57
  216. package/src/features/integrations/IntegrationRow/Icons.ts +0 -77
  217. package/src/features/integrations/IntegrationRow/index.ts +0 -129
  218. package/src/features/integrations/IntegrationRow/styles.module.scss +0 -62
  219. package/src/features/integrations/IntegrationsHeader/index.ts +0 -34
  220. package/src/features/integrations/IntegrationsHeader/styles.module.scss +0 -47
  221. package/src/features/integrations/IntegrationsList/index.ts +0 -252
  222. package/src/features/integrations/IntegrationsList/styles.module.scss +0 -67
  223. package/src/features/templates/Template/index.ts +0 -295
  224. package/src/features/templates/Template/styles.module.scss +0 -226
  225. package/src/features/templates/TemplatesView/index.ts +0 -368
  226. package/src/features/templates/TemplatesView/styles.module.scss +0 -71
  227. package/src/features/templates/TemplatesViewCompact/index.ts +0 -364
  228. package/src/features/templates/TemplatesViewCompact/styles.module.scss +0 -141
  229. package/src/hooks/useAutosizeTextArea.ts +0 -22
  230. package/src/hooks/useCustomRef.ts +0 -13
  231. package/src/hooks/useDebounce.ts +0 -17
  232. package/src/hooks/useElementResize.ts +0 -40
  233. package/src/hooks/useEventListener.ts +0 -42
  234. package/src/hooks/useHover.ts +0 -40
  235. package/src/hooks/useOnClickOutside.ts +0 -32
  236. package/src/index.ts +0 -2244
  237. package/src/index.umd.ts +0 -13
  238. package/src/interfaces/index.ts +0 -938
  239. package/src/modules/api/index.ts +0 -1325
  240. package/src/modules/api/responseHandler.ts +0 -38
  241. package/src/modules/event-emitter/index.ts +0 -72
  242. package/src/modules/event-emitter/runners/abstract.ts +0 -21
  243. package/src/modules/event-emitter/runners/default.ts +0 -11
  244. package/src/modules/event-emitter/runners/ntimes.ts +0 -28
  245. package/src/modules/event-emitter/types.ts +0 -34
  246. package/src/store/actionFunctions.ts +0 -1578
  247. package/src/store/index.ts +0 -17
  248. package/src/store/initialState.ts +0 -58
  249. package/src/types/index.ts +0 -320
  250. package/src/types/preact-compat.d.ts +0 -4
  251. package/src/types/store.ts +0 -366
  252. package/src/types/utils.ts +0 -19
  253. package/src/utils/ActivityOutputUtils.ts +0 -176
  254. package/src/utils/common.ts +0 -20
  255. package/src/utils/copyToClipboard.ts +0 -24
  256. package/src/utils/datetime.ts +0 -101
  257. package/src/utils/getUrlParam.ts +0 -11
  258. package/src/utils/isAuthMessage.ts +0 -16
  259. package/src/utils/isBrowser.ts +0 -1
  260. package/src/utils/jsonEncodeDecode.ts +0 -15
  261. package/src/utils/objectUtils.ts +0 -117
  262. package/src/utils/popup.ts +0 -30
  263. package/src/utils/searchJson.ts +0 -51
  264. package/src/utils/stepUtils.ts +0 -45
  265. package/src/utils/truncate.ts +0 -6
  266. package/test/setup.ts +0 -1
  267. package/vitest.config.ts +0 -16
@@ -1,1578 +0,0 @@
1
- /* eslint-disable import/no-cycle */
2
- import { Store } from 'unistore';
3
-
4
- import {
5
- BundleResponse,
6
- // IntegrationResponse,
7
- PreviewMetadata,
8
- TemplateField,
9
- TemplateStep,
10
- ConditionalFields,
11
- MarketplaceDetail,
12
- MarketplaceAppAuthorizationType,
13
- } from '@/interfaces';
14
- import { StepStateStep, State } from '@/types/store';
15
- import { Authorization } from '@/types';
16
- import { initialState } from '@/store/initialState';
17
- import { decodeJSON } from '@/utils/jsonEncodeDecode';
18
- import { areParentValuesValid } from '@/utils/stepUtils';
19
-
20
- export const actionFunctions = (storeSnapshot: Store<State>) => ({
21
- setStoreState(state: State, partialUpdate: Partial<State>): Partial<State> {
22
- return {
23
- ...state,
24
- ...partialUpdate,
25
- };
26
- },
27
- setBaseData(state: State, bundleResponse: BundleResponse): Partial<State> {
28
- return {
29
- ...state,
30
- integrations: bundleResponse.integrations.map((el) => ({
31
- ...el,
32
- loading: false,
33
- })),
34
- templates: bundleResponse.templates,
35
- fetchingIntegrations: false,
36
- fetchingTemplates: false,
37
- };
38
- },
39
-
40
- setSteps(state: State, templateSteps: TemplateStep[]): Partial<State> {
41
- const parsedSteps: StepStateStep[] = [];
42
- let itemIndex = -1;
43
- const appAuthIsAdded: number[] = [];
44
- templateSteps.forEach((element) => {
45
- const { authorization_type } = element;
46
- const { app } = authorization_type;
47
- const hideAuthorizaiton = element.hide_authorization;
48
-
49
- if (!hideAuthorizaiton && !appAuthIsAdded.includes(app.id)) {
50
- appAuthIsAdded.push(app.id);
51
- let stepTitle: string = element.activity.app.name;
52
- let stepIcon: string = element.activity.app.icon_url;
53
- if (element.activity.type === 'MAKE_HTTP_CALL') {
54
- stepTitle = element.authorization_type.app.name;
55
- stepIcon = element.authorization_type.app.icon_url;
56
- }
57
-
58
- itemIndex += 1;
59
- // step has auth required so split into two.
60
- parsedSteps.push({
61
- stepId: element.id,
62
- title: `${stepTitle} Account`,
63
- iconUrl: stepIcon,
64
- isCompleted: false,
65
- isCurrentlyOpen: false,
66
- type: 'AUTH',
67
- requiredFields: [element.id], // auth if required will always be named like this
68
- invalidFields: {
69
- [element.id]: '',
70
- },
71
- isValid: false,
72
- itemIndex,
73
- });
74
- } else {
75
- // auth is implicit so we will select the first available auth
76
- }
77
-
78
- // if (element.is_visible) {
79
- // // check if we need to show the config step at all
80
- // if (element.template_fields.length > 0) {
81
- // // step has template fields with at least one visible
82
- // const hasVisibleTemplateFields =
83
- // element.template_fields.filter((el) => el.is_visible).length > 0;
84
-
85
- // // check which of these are required
86
- // const requiredFields = element.template_fields
87
- // .filter((el) => el.is_required && el.is_visible)
88
- // .map((field) => field.id);
89
-
90
- // // check if no default value is provided
91
- // const invalidFields = element.template_fields
92
- // .filter(
93
- // (el) => el.is_required && !el.default_value && el.is_visible,
94
- // )
95
- // .reduce((prev, field) => ({ ...prev, [field.id]: '' }), {});
96
-
97
- // const isValidDefault = Object.keys(invalidFields).length < 1;
98
-
99
- // if (hasVisibleTemplateFields) {
100
- // itemIndex += 1;
101
- // parsedSteps.push({
102
- // stepId: element.id,
103
- // title: element.title,
104
- // iconUrl: element.activity.app.icon_url,
105
- // isCompleted: false,
106
- // isCurrentlyOpen: false,
107
- // type: 'CONFIGURATION',
108
- // requiredFields,
109
- // invalidFields,
110
- // isValid: isValidDefault,
111
- // itemIndex,
112
- // });
113
- // }
114
- // }
115
- // }
116
- });
117
- templateSteps.forEach((element) => {
118
- if (element.is_visible) {
119
- // check if we need to show the config step at all
120
- if (element.template_fields.length > 0) {
121
- // step has template fields with at least one visible
122
- const hasVisibleTemplateFields =
123
- element.template_fields.filter((el) => el.is_visible).length > 0;
124
-
125
- // check which of these are required
126
- const requiredFields = element.template_fields
127
- .filter((el) => el.is_required && el.is_visible)
128
- .map((field) => field.id);
129
-
130
- // check if no default value is provided
131
- const invalidFields = element.template_fields
132
- .filter(
133
- (el) => el.is_required && !el.default_value && el.is_visible,
134
- )
135
- .reduce((prev, field) => ({ ...prev, [field.id]: '' }), {});
136
-
137
- const isValidDefault = Object.keys(invalidFields).length < 1;
138
-
139
- if (hasVisibleTemplateFields) {
140
- itemIndex += 1;
141
- parsedSteps.push({
142
- stepId: element.id,
143
- title: element.title,
144
- description: element.description || '',
145
- iconUrl: element.activity.app.icon_url,
146
- isCompleted: false,
147
- isCurrentlyOpen: false,
148
- type: 'CONFIGURATION',
149
- requiredFields,
150
- invalidFields,
151
- isValid: isValidDefault,
152
- itemIndex,
153
- });
154
- }
155
- }
156
- }
157
- });
158
-
159
- return {
160
- ...state,
161
- stepState: {
162
- steps: parsedSteps,
163
- fieldsListData: null,
164
- currentStep: parsedSteps[0],
165
- stepIndex: 0,
166
- showValidation: false,
167
- allStepsCompleted: false,
168
- },
169
- };
170
- },
171
-
172
- setIntegrationLoadingState(
173
- state: State,
174
- data: {
175
- integrationId: number;
176
- isLoading: boolean;
177
- op: 'edit' | 'delete' | 'edit-name';
178
- nextVal?: boolean;
179
- updatedName?: string;
180
- },
181
- ): Partial<State> {
182
- const { integrationId, isLoading, op, nextVal } = data;
183
- const index = state.integrations.findIndex((el) => el.id === integrationId);
184
- if (op === 'delete') {
185
- return {
186
- ...state,
187
- integrations: state.integrations.filter(
188
- (el) => el.id !== integrationId,
189
- ),
190
- };
191
- }
192
- if (op === 'edit' && index > -1) {
193
- const int = {
194
- ...state.integrations[index],
195
- loading: isLoading,
196
- };
197
- if (nextVal !== null && nextVal !== undefined) {
198
- int.status = nextVal ? 'ACTIVE' : 'INACTIVE';
199
- }
200
- return {
201
- ...state,
202
- integrations: [
203
- ...state.integrations.slice(0, index),
204
- int,
205
- ...state.integrations.slice(index + 1),
206
- ],
207
- };
208
- }
209
- if (op === 'edit-name' && index > -1) {
210
- const int = {
211
- ...state.integrations[index],
212
- name: `${data.updatedName}`,
213
- loading: isLoading,
214
- };
215
- return {
216
- ...state,
217
- integrations: [
218
- ...state.integrations.slice(0, index),
219
- int,
220
- ...state.integrations.slice(index + 1),
221
- ],
222
- };
223
- }
224
- return {
225
- ...state,
226
- };
227
- },
228
-
229
- showStepValidationState(state: State): Partial<State> {
230
- const { stepState } = state;
231
- return {
232
- stepState: {
233
- ...stepState,
234
- showValidation: true,
235
- },
236
- };
237
- },
238
-
239
- hideStepValidationState(state: State): Partial<State> {
240
- const { stepState } = state;
241
- return {
242
- stepState: {
243
- ...stepState,
244
- showValidation: false,
245
- },
246
- };
247
- },
248
-
249
- gotoNextStep(state: State): Partial<State> {
250
- const { stepState } = state;
251
- if (stepState) {
252
- const newIndex = Number(stepState.stepIndex) + 1;
253
- const step = stepState.steps[Number(stepState.stepIndex) + 1];
254
- const updatedStep = {
255
- ...stepState.steps[state.stepState.stepIndex],
256
- isCompleted: true,
257
- };
258
- if (!step) {
259
- // last step reached
260
- return {
261
- stepState: {
262
- ...stepState,
263
- steps: [
264
- ...stepState.steps.slice(0, stepState.stepIndex),
265
- updatedStep,
266
- ...stepState.steps.slice(stepState.stepIndex + 1),
267
- ],
268
- currentStep: {
269
- type: 'CONFIRMATION',
270
- },
271
- stepIndex: newIndex,
272
- allStepsCompleted: true,
273
- showValidation: false,
274
- },
275
- };
276
- }
277
-
278
- return {
279
- stepState: {
280
- ...stepState,
281
- steps: [
282
- ...stepState.steps.slice(0, stepState.stepIndex),
283
- updatedStep,
284
- ...stepState.steps.slice(stepState.stepIndex + 1),
285
- ],
286
- currentStep: {
287
- ...step,
288
- },
289
- stepIndex: newIndex,
290
- showValidation: false,
291
- },
292
- };
293
- }
294
- return state;
295
- },
296
-
297
- gotoPreviousStep(state: State): Partial<State> {
298
- if (state.stepState) {
299
- const newIndex = Number(state.stepState.stepIndex) - 1;
300
- const step = state.stepState.steps[Number(state.stepState.stepIndex) - 1];
301
- let showStepValidation = !step.isValid;
302
- if (state.genericData.isReadOnly) {
303
- showStepValidation = false;
304
- }
305
- return {
306
- stepState: {
307
- ...state.stepState,
308
- currentStep: step,
309
- stepIndex: newIndex,
310
- showValidation: showStepValidation,
311
- },
312
- };
313
- }
314
- return state;
315
- },
316
-
317
- gotoStepInPreview: (
318
- state: State,
319
- previewMetadata: PreviewMetadata,
320
- ): Partial<State> => {
321
- const { stepState } = state;
322
- const { stepId, type } = previewMetadata;
323
-
324
- if (stepId && type !== 'CONFIRMATION') {
325
- // go to a particular step
326
- const stepIndexToNavigateTo = stepState.steps.findIndex(
327
- (el) => el.stepId === stepId && el.type === type,
328
- );
329
- if (stepIndexToNavigateTo > -1)
330
- return {
331
- stepState: {
332
- ...state.stepState,
333
- currentStep: stepState.steps[stepIndexToNavigateTo],
334
- stepIndex: stepIndexToNavigateTo,
335
- allStepsCompleted: false,
336
- },
337
- };
338
- }
339
-
340
- if (!stepId && type === 'CONFIRMATION') {
341
- return {
342
- stepState: {
343
- ...stepState,
344
- currentStep: {
345
- type: 'CONFIRMATION',
346
- },
347
- stepIndex: stepState.steps.length,
348
- allStepsCompleted: true,
349
- },
350
- };
351
- }
352
- return state;
353
- },
354
-
355
- gotoStep: (state: State, stepIndex: number): Partial<State> => {
356
- const { stepState } = state;
357
- const { stepIndex: oldStepIndex } = stepState;
358
- if (stepState) {
359
- const { currentStep } = stepState;
360
- const stepToNavigateTo = stepState.steps[stepIndex];
361
-
362
- if (state.genericData.isPreviewMode) {
363
- // we can go to any step in preview mode
364
- if (stepIndex === stepState.steps.length) {
365
- return {
366
- stepState: {
367
- ...stepState,
368
- currentStep: {
369
- type: 'CONFIRMATION',
370
- },
371
- stepIndex: stepState.steps.length,
372
- allStepsCompleted: true,
373
- },
374
- };
375
- }
376
- return {
377
- stepState: {
378
- ...state.stepState,
379
- currentStep: {
380
- ...stepToNavigateTo,
381
- },
382
- stepIndex,
383
- allStepsCompleted: false,
384
- },
385
- };
386
- }
387
-
388
- // go to any step in isReadOnly Mode
389
- if (state.genericData.isReadOnly) {
390
- return {
391
- stepState: {
392
- ...state.stepState,
393
- currentStep: {
394
- ...stepToNavigateTo,
395
- },
396
- stepIndex,
397
- // allStepsCompleted: false,
398
- },
399
- };
400
- }
401
-
402
- // navigate directly to confirmation page if all steps are completed
403
- if (
404
- stepState.allStepsCompleted &&
405
- stepIndex === stepState.steps.length &&
406
- stepState.currentStep?.type !== 'CONFIRMATION' &&
407
- stepState.currentStep?.isValid
408
- ) {
409
- return {
410
- stepState: {
411
- ...stepState,
412
- currentStep: {
413
- type: 'CONFIRMATION',
414
- },
415
- stepIndex: stepState.steps.length,
416
- allStepsCompleted: true,
417
- },
418
- };
419
- }
420
-
421
- // navigate to confirmation from final step
422
- if (
423
- currentStep &&
424
- currentStep.type !== 'CONFIRMATION' &&
425
- currentStep.isValid &&
426
- oldStepIndex === stepState.steps.length - 1 &&
427
- stepIndex === stepState.steps.length
428
- ) {
429
- const updatedStep = {
430
- ...stepState.steps[oldStepIndex],
431
- isCompleted: true,
432
- };
433
- return {
434
- stepState: {
435
- ...stepState,
436
- steps: [
437
- ...stepState.steps.slice(0, oldStepIndex),
438
- updatedStep,
439
- ...stepState.steps.slice(oldStepIndex + 1),
440
- ],
441
- currentStep: {
442
- type: 'CONFIRMATION',
443
- },
444
- stepIndex,
445
- allStepsCompleted: true,
446
- },
447
- };
448
- }
449
-
450
- // navigate to a step if it is completed
451
- if (
452
- (stepToNavigateTo && stepToNavigateTo.isCompleted) ||
453
- (stepToNavigateTo &&
454
- stepState.currentStep?.type !== 'CONFIRMATION' &&
455
- stepState.currentStep?.isCompleted &&
456
- stepToNavigateTo.type === 'CONFIRMATION')
457
- ) {
458
- return {
459
- stepState: {
460
- ...state.stepState,
461
- currentStep: {
462
- ...stepToNavigateTo,
463
- },
464
- stepIndex,
465
- showValidation: !stepToNavigateTo.isValid,
466
- },
467
- };
468
- }
469
- if (
470
- // clicking on next step with current completed
471
- stepState.currentStep?.type !== 'CONFIRMATION' &&
472
- stepState.currentStep?.isValid &&
473
- stepIndex === oldStepIndex + 1
474
- ) {
475
- const updatedStep = {
476
- ...stepState.steps[oldStepIndex],
477
- isCompleted: true,
478
- isValid: true,
479
- };
480
- return {
481
- stepState: {
482
- ...state.stepState,
483
- steps: [
484
- ...stepState.steps.slice(0, oldStepIndex),
485
- updatedStep,
486
- ...stepState.steps.slice(oldStepIndex + 1),
487
- ],
488
- currentStep: {
489
- ...stepToNavigateTo,
490
- },
491
- stepIndex,
492
- },
493
- };
494
- }
495
-
496
- // navigate to a step immediately following a completed step
497
- if (
498
- stepState.steps[stepIndex - 1] &&
499
- stepState.steps[stepIndex - 1].isCompleted &&
500
- stepState.steps[stepIndex].type !== 'CONFIRMATION'
501
- ) {
502
- return {
503
- stepState: {
504
- ...state.stepState,
505
- currentStep: {
506
- ...stepToNavigateTo,
507
- },
508
- stepIndex,
509
- },
510
- };
511
- }
512
- }
513
- return state;
514
- },
515
-
516
- verifyStepValidity(state: State, stepId: number) {
517
- const { stepDataMapping, conditionalFieldMapping } = state;
518
- const element = stepDataMapping[stepId];
519
-
520
- let fieldsData: any[] = [];
521
- if (element) {
522
- fieldsData = Object.keys(element).map((fieldId) => {
523
- const ele = element[Number(fieldId)];
524
- return ele;
525
- });
526
- } else {
527
- fieldsData = [];
528
- }
529
-
530
- const visibleFields = fieldsData.filter((el) => {
531
- // filter out hidden conditional fields
532
- const fieldConditions = conditionalFieldMapping[stepId][el.machineName];
533
- if (fieldConditions) {
534
- return areParentValuesValid(stepId, fieldConditions, stepDataMapping);
535
- }
536
- return true;
537
- });
538
-
539
- const invalid = visibleFields.filter((el) => {
540
- if (el.isRequired) {
541
- if (el.type === 'SECTION') {
542
- return false;
543
- }
544
- if (!el.value && !el.objectValue) {
545
- return true;
546
- }
547
- if (el.type === 'CHECKBOX' && el.value === '0') {
548
- return true;
549
- }
550
- }
551
- if (el.value && !el.passesRegexTest) {
552
- return true;
553
- }
554
- return false;
555
- });
556
-
557
- const isValid = !(invalid.length > 0);
558
-
559
- return {
560
- stepState: {
561
- ...state.stepState,
562
- currentStep: {
563
- ...state.stepState.currentStep,
564
- isValid,
565
- },
566
- },
567
- };
568
- },
569
-
570
- getStepState() {
571
- return storeSnapshot.getState().stepState;
572
- },
573
-
574
- setGenericData(
575
- state: State,
576
- genericData: Partial<{
577
- templateId: number;
578
- deploymentId: number;
579
- isPreviewMode: boolean;
580
- marketplaceId?: number;
581
- marketplaceDetail?: MarketplaceDetail;
582
- IUAccountsData?: MarketplaceAppAuthorizationType;
583
- testMultipurpose?: boolean;
584
- }>,
585
- ): Partial<State> {
586
- return {
587
- genericData: {
588
- ...state.genericData,
589
- ...genericData,
590
- },
591
- };
592
- },
593
-
594
- setStepMapping(
595
- state: State,
596
- steps: TemplateStep[],
597
- integrationId?: number,
598
- ): Partial<State> {
599
- const integrationIdToEdit = state.integrationIdToEdit || integrationId;
600
-
601
- // find first step that is of trigger/query type
602
- const stepWithActivityOutput =
603
- steps.find(
604
- (step) =>
605
- step.activity &&
606
- (step.activity.type === 'TRIGGER' ||
607
- step.activity.type === 'QUERY' ||
608
- step.activity.type === 'ADAPTER'),
609
- ) || null;
610
-
611
- let fieldListMappingData: {
612
- [machineName: string]: TemplateField & { stepId: number };
613
- } = {};
614
-
615
- let standardFieldsInsideMapping: {
616
- [k: string]: string | Record<string, string>;
617
- } = {};
618
-
619
- let stepIdWithFieldMapping = '';
620
-
621
- fieldListMappingData = steps
622
- .map((step) =>
623
- step.template_fields.reduce((prev, next) => {
624
- if (next.activity_field?.type === 'FIELD_LIST') {
625
- return {
626
- ...prev,
627
- [`{steps.${step.machine_name}.field_list}`]: {
628
- ...next,
629
- stepId: step.id,
630
- },
631
- };
632
- }
633
- return prev;
634
- }, {}),
635
- )
636
- .filter((el) => Object.keys(el).length > 0)
637
- .reduce((prev, next) => ({ ...prev, ...next }), {});
638
-
639
- const stepMapping: any = steps.reduce((prev, step) => {
640
- let selectedAuthId = 0;
641
- let shouldAutoVerifyAuth = false;
642
- if (
643
- state.genericData.isReadOnly &&
644
- integrationIdToEdit &&
645
- step.step_authorization
646
- ) {
647
- selectedAuthId = step.step_authorization; // set selected auth in read only mode
648
- } else if (
649
- step.hide_authorization ||
650
- state.genericData.isPreviewMode ||
651
- (step.is_workspace_app_step && step.activity.type === 'FORM')
652
- ) {
653
- shouldAutoVerifyAuth = true;
654
- selectedAuthId = step.step_authorization
655
- ? step.step_authorization
656
- : step.authorization_type.authorizations[0]?.id ?? null;
657
- } else if (state.stepMapping[step.id]) {
658
- selectedAuthId = state.stepMapping[step.id].selectedAuthId;
659
- } else if (integrationIdToEdit && step.step_authorization) {
660
- shouldAutoVerifyAuth = true;
661
- selectedAuthId = step.step_authorization; // set selected auth in edit mode
662
- }
663
- return {
664
- ...prev,
665
- [step.id]: {
666
- step,
667
- integrationStepId: step.step_instance,
668
- authorizations:
669
- step.authorization_type.authorizations?.map((el) => ({
670
- authorizationId: el.id,
671
- userIdentity: el.user_identity,
672
- authType: el.authorization_type,
673
- disableLink: el.disable_link,
674
- isErrored: false,
675
- isVerifying: false,
676
- isVerified: false,
677
- accessToken: el?.access_token || null,
678
- })) ?? [],
679
- isAuthVerified: shouldAutoVerifyAuth,
680
- isUserinfoRequired: step.authorization_type?.is_userinfo_required,
681
- selectedAuthId,
682
- invalidFields: {},
683
- isValid: !!integrationIdToEdit,
684
- isCompleted: !!integrationIdToEdit,
685
- },
686
- };
687
- }, {});
688
-
689
- const parsedStepsCopy = state.stepState.steps.map((el) => ({
690
- ...el,
691
- invalidFields: {},
692
- isValid: !!stepMapping[el.stepId].selectedAuthId,
693
- isCompleted: !!stepMapping[el.stepId].selectedAuthId,
694
- }));
695
-
696
- function processTemplateFields(templateFields: any, step: any) {
697
- return templateFields.reduce((acc: any, curr: any) => {
698
- let value = null;
699
- let objectValue = null;
700
- let changedDynamicFields = [];
701
- const isEditMode = !!integrationIdToEdit;
702
- const isFieldMapping = curr.activity_field?.type === 'FIELD_MAPPING';
703
- const isDynamicField = curr.activity_field?.type === 'DYNAMIC';
704
- const isStepVisible = !!step.is_visible;
705
- const isFieldVisible = !!curr.is_visible;
706
- const userData =
707
- (curr.app_user_data &&
708
- curr.app_user_data.length > 0 &&
709
- curr.app_user_data[0]) ||
710
- null;
711
-
712
- if (isEditMode && !isFieldMapping && userData && isFieldVisible) {
713
- if (isDynamicField) {
714
- try {
715
- objectValue = JSON.parse(`${userData.value || '{}'}`);
716
- changedDynamicFields = JSON.parse(
717
- `${userData.changed_dynamic_fields || '[]'}`,
718
- );
719
- } catch (err) {
720
- console.error(err);
721
- }
722
- } else {
723
- value = userData.value;
724
- }
725
- } else if (!isStepVisible || !isFieldVisible) {
726
- value = curr.default_value;
727
- if (userData && userData.value) value = userData.value;
728
- } else if (isFieldMapping && userData && userData.value) {
729
- const mappingData: Record<
730
- string,
731
- string | Record<string, string>
732
- > = JSON.parse(`${userData.value}`);
733
-
734
- stepIdWithFieldMapping = `${step.id}`;
735
-
736
- standardFieldsInsideMapping = Object.fromEntries(
737
- Object.entries(mappingData).filter(
738
- ([key]) => typeof mappingData[key] === 'string',
739
- ),
740
- );
741
-
742
- const mapping = Object.fromEntries(
743
- Object.entries(mappingData).filter(
744
- ([key]) => typeof mappingData[key] !== 'string',
745
- ),
746
- );
747
-
748
- objectValue = mapping[Object.keys(mapping)[0]];
749
- } else {
750
- value = '';
751
- }
752
-
753
- const newAcc = {
754
- ...acc,
755
- [curr.id]: {
756
- fieldId: curr.id,
757
- value,
758
- objectValue,
759
- machineName: curr.activity_field?.machine_name,
760
- isRequired: curr.activity_field?.is_required || curr.is_required,
761
- isVisible: curr.is_visible,
762
- isDynamic:
763
- curr.activity_field?.type === 'DYNAMIC' ||
764
- curr.activity_field?.type === 'FIELD_MAPPING',
765
- integrationFieldId:
766
- curr.app_user_data && curr.app_user_data.length > 0
767
- ? curr.app_user_data[0].id
768
- : null,
769
- isAddedInMapping: !!curr.added_in_mapping,
770
- type: curr.activity_field?.type || curr.type,
771
- regex: curr.activity_field?.regex,
772
- regexErrorMessage: curr.activity_field?.regex_error_message,
773
- passesRegexTest: true,
774
- isChanged: userData ? userData.is_changed : false,
775
- changedDynamicFields,
776
- },
777
- };
778
-
779
- if (curr?.type === 'SECTION' && curr?.template_fields) {
780
- return {
781
- ...newAcc,
782
- ...processTemplateFields(curr.template_fields, step),
783
- };
784
- }
785
-
786
- return newAcc;
787
- }, {});
788
- }
789
-
790
- const stepDataMapping: Record<number, any> = steps.reduce(
791
- (prev, step) => ({
792
- ...prev,
793
- [step.id]: {
794
- ...state.stepDataMapping[step.id],
795
- ...processTemplateFields(step.template_fields, step),
796
- },
797
- }),
798
- {},
799
- );
800
-
801
- // set standard field values from mapping data
802
- if (
803
- Object.keys(standardFieldsInsideMapping).length > 0 &&
804
- stepIdWithFieldMapping
805
- ) {
806
- Object.keys(stepDataMapping).forEach((stepId) => {
807
- const stepObj = stepDataMapping[Number(stepId)];
808
- Object.keys(stepObj).forEach((fieldId) => {
809
- const field = stepObj[Number(fieldId)];
810
- if (standardFieldsInsideMapping[field.machineName]) {
811
- field.value = standardFieldsInsideMapping[field.machineName];
812
- }
813
- });
814
- });
815
- }
816
-
817
- return {
818
- stepState: integrationIdToEdit
819
- ? {
820
- ...state.stepState,
821
- steps: parsedStepsCopy,
822
- currentStep: parsedStepsCopy[0],
823
- showValidation: !integrationIdToEdit,
824
- allStepsCompleted: !!integrationIdToEdit,
825
- }
826
- : state.stepState,
827
- stepMapping: {
828
- ...state.stepMapping,
829
- ...stepMapping,
830
- },
831
- stepDataMapping: {
832
- ...state.stepDataMapping,
833
- ...stepDataMapping,
834
- },
835
- fieldListMapping: fieldListMappingData,
836
- genericData: {
837
- ...state.genericData,
838
- stepWithActivityOutput,
839
- },
840
- };
841
- },
842
-
843
- setActivityOutputData(
844
- state: State,
845
- data: {
846
- activityOutputData: {
847
- value: string;
848
- text: string;
849
- }[];
850
- },
851
- ): Partial<State> {
852
- return {
853
- ...state,
854
- activityOutputData: data.activityOutputData,
855
- };
856
- },
857
-
858
- setAppsAuthData(
859
- state: State,
860
- data: {
861
- appsAuthData: {
862
- appId: number;
863
- isVerified: boolean;
864
- }[];
865
- },
866
- ): Partial<State> {
867
- return {
868
- ...state,
869
- appsAuthData: data.appsAuthData,
870
- };
871
- },
872
-
873
- setDynamicFieldData(
874
- state: State,
875
- data: {
876
- dynamicFieldData: {
877
- [fieldId: string]: (string | Record<string, string>)[];
878
- };
879
- },
880
- ): Partial<State> {
881
- return {
882
- ...state,
883
- dynamicFieldData: Object.keys(data.dynamicFieldData).reduce(
884
- (prev, next) => ({
885
- ...prev,
886
- [`{${next}}`]: data.dynamicFieldData[next],
887
- }),
888
- {},
889
- ),
890
- };
891
- },
892
-
893
- setIncomingWebhookPayload(
894
- state: State,
895
- data: {
896
- incomingWebhookPayload: {
897
- [fieldId: string]: string | Record<string, string>;
898
- };
899
- },
900
- ): Partial<State> {
901
- return {
902
- ...state,
903
- incomingWebhookPayload: data.incomingWebhookPayload,
904
- };
905
- },
906
-
907
- setParentChildMapping(state: State, steps: TemplateStep[]): Partial<State> {
908
- const parentChildMapping = steps.reduce(
909
- (prev, step) => ({
910
- ...prev,
911
- [step.id]: {
912
- ...state.parentChildMapping[step.id],
913
- ...step.template_fields.reduce((acc, curr) => {
914
- if (curr.activity_field)
915
- return {
916
- ...acc,
917
- [curr.activity_field?.machine_name]: {
918
- fieldId: curr.id,
919
- childFields: curr.activity_field?.child_fields
920
- ? JSON.parse(curr.activity_field?.child_fields ?? '[]')
921
- : null,
922
- parentFields: curr.activity_field?.parent_fields
923
- ? JSON.parse(curr.activity_field?.parent_fields ?? '[]')
924
- : null,
925
- },
926
- };
927
- return acc;
928
- }, {}),
929
- },
930
- }),
931
- {},
932
- );
933
-
934
- return {
935
- parentChildMapping: {
936
- ...state.parentChildMapping,
937
- ...parentChildMapping,
938
- },
939
- };
940
- },
941
-
942
- setConditionalFieldMapping(
943
- state: State,
944
- steps: TemplateStep[],
945
- ): Partial<State> {
946
- const conditionalFieldMapping = steps.reduce(
947
- (prev, step) => ({
948
- ...prev,
949
- [step.id]: {
950
- ...state.conditionalFieldMapping[step.id],
951
- ...step.template_fields.reduce((acc: { [key: string]: [] }, curr) => {
952
- if (
953
- curr.activity_field &&
954
- !!curr.activity_field.conditional_fields
955
- ) {
956
- const parentMachineName = curr.activity_field?.machine_name;
957
- const parentFieldId = curr.id;
958
- const conditions = (decodeJSON(
959
- curr?.activity_field?.conditional_fields,
960
- ) || []) as ConditionalFields[];
961
- return {
962
- ...acc, // conditions from previous fields
963
- ...conditions.reduce(
964
- (accCondition: { [key: string]: [] }, currCondition) => {
965
- const { value } = currCondition;
966
- const childFields = (decodeJSON(
967
- currCondition.field_array,
968
- ) || []) as string[];
969
- return {
970
- ...accCondition,
971
- ...childFields.reduce(
972
- (accChild, currChild) => ({
973
- ...accChild,
974
- [currChild]: [
975
- ...(acc[currChild] || []), // current child conditions from previous fields
976
- ...(accCondition[currChild] || []), // current child conditions from previous condition array
977
- { value, parentMachineName, parentFieldId },
978
- ],
979
- }),
980
- {},
981
- ),
982
- };
983
- },
984
- {},
985
- ),
986
- };
987
- }
988
- return acc;
989
- }, {}),
990
- },
991
- }),
992
- {},
993
- );
994
-
995
- return {
996
- conditionalFieldMapping: {
997
- ...state.conditionalFieldMapping,
998
- ...conditionalFieldMapping,
999
- },
1000
- };
1001
- },
1002
-
1003
- addAuthorization(
1004
- state: State,
1005
- params: {
1006
- stepId: number;
1007
- authData: Authorization;
1008
- },
1009
- ): Partial<State> {
1010
- const { stepId, authData } = params;
1011
- return {
1012
- stepMapping: {
1013
- ...state.stepMapping,
1014
- [stepId]: {
1015
- ...state.stepMapping[stepId],
1016
- authorizations: [
1017
- ...state.stepMapping[stepId].authorizations,
1018
- authData,
1019
- ],
1020
- },
1021
- },
1022
- };
1023
- },
1024
-
1025
- addAppAuthorization(
1026
- state: State,
1027
- params: {
1028
- appId: number;
1029
- authData: Authorization;
1030
- },
1031
- ): Partial<State> {
1032
- const { appId, authData } = params;
1033
- return {
1034
- authMapping: {
1035
- ...state.authMapping,
1036
- [appId]: {
1037
- ...state.authMapping[appId],
1038
- authorizations: [
1039
- ...state.authMapping[appId]?.authorizations,
1040
- authData,
1041
- ],
1042
- },
1043
- },
1044
- };
1045
- },
1046
-
1047
- setSelectedAuthByAppId(
1048
- state: State,
1049
- params: {
1050
- appId: number;
1051
- authId: number | null;
1052
- },
1053
- ): Partial<State> {
1054
- const { appId, authId } = params;
1055
- return {
1056
- selectedAuthByAppId: {
1057
- ...state.selectedAuthByAppId,
1058
- [appId]: authId,
1059
- },
1060
- };
1061
- },
1062
-
1063
- removeAuthorization(
1064
- state: State,
1065
- params: {
1066
- stepId: number;
1067
- authId: number;
1068
- },
1069
- ): Partial<State> {
1070
- const { stepId, authId } = params;
1071
-
1072
- const updatedArr = state.stepMapping[stepId].authorizations.filter(
1073
- (el) => el.authorizationId !== authId,
1074
- );
1075
-
1076
- const step = state.stepState.currentStep as StepStateStep;
1077
- return {
1078
- stepState: {
1079
- ...state.stepState,
1080
- currentStep: {
1081
- ...step,
1082
- isValid: updatedArr.length > 0 ? step.isValid : false,
1083
- isCompleted: updatedArr.length > 0 ? step.isCompleted : false,
1084
- },
1085
- },
1086
- stepMapping: {
1087
- ...state.stepMapping,
1088
- [stepId]: {
1089
- ...state.stepMapping[stepId],
1090
- authorizations: updatedArr,
1091
- },
1092
- },
1093
- };
1094
- },
1095
-
1096
- toggleVerifyAuthorizationFlag(
1097
- state: State,
1098
- params: {
1099
- stepId: number;
1100
- authId: number;
1101
- isVerifying: boolean;
1102
- },
1103
- ): Partial<State> {
1104
- const { stepId, authId, isVerifying } = params;
1105
- const authObjIndex = state.stepMapping[stepId]?.authorizations.findIndex(
1106
- (el) => el.authorizationId === authId,
1107
- );
1108
-
1109
- if (!(authObjIndex > -1)) return state;
1110
-
1111
- return {
1112
- stepMapping: {
1113
- ...state.stepMapping,
1114
- [stepId]: {
1115
- ...state.stepMapping[stepId],
1116
- authorizations: [
1117
- ...state.stepMapping[stepId].authorizations.slice(0, authObjIndex),
1118
- {
1119
- ...state.stepMapping[stepId].authorizations[authObjIndex],
1120
- isVerifying,
1121
- },
1122
- ...state.stepMapping[stepId].authorizations.slice(authObjIndex + 1),
1123
- ],
1124
- },
1125
- },
1126
- };
1127
- },
1128
-
1129
- toggleVerifyAppAuthorizationFlag(
1130
- state: State,
1131
- params: {
1132
- appId: number;
1133
- authId: number;
1134
- isVerifying: boolean;
1135
- },
1136
- ): Partial<State> {
1137
- const { appId, authId, isVerifying } = params;
1138
- const authObjIndex = state.authMapping[appId]?.authorizations.findIndex(
1139
- (el) => el.authorizationId === authId,
1140
- );
1141
-
1142
- if (!(authObjIndex > -1)) return state;
1143
-
1144
- return {
1145
- stepMapping: {
1146
- ...state.stepMapping,
1147
- [appId]: {
1148
- ...state.authMapping[appId],
1149
- authorizations: [
1150
- ...state.authMapping[appId].authorizations.slice(0, authObjIndex),
1151
- {
1152
- ...state.authMapping[appId].authorizations[authObjIndex],
1153
- isVerifying,
1154
- },
1155
- ...state.authMapping[appId].authorizations.slice(authObjIndex + 1),
1156
- ],
1157
- },
1158
- },
1159
- };
1160
- },
1161
-
1162
- toggleDeleteAuthorizationFlag(
1163
- state: State,
1164
- params: {
1165
- stepId: number;
1166
- authId: number;
1167
- isDeleting: boolean;
1168
- error: string;
1169
- },
1170
- ): Partial<State> {
1171
- const { stepId, authId, isDeleting, error } = params;
1172
- const authObjIndex = state.stepMapping[stepId].authorizations.findIndex(
1173
- (el) => el.authorizationId === authId,
1174
- );
1175
- return {
1176
- stepMapping: {
1177
- ...state.stepMapping,
1178
- [stepId]: {
1179
- ...state.stepMapping[stepId],
1180
- authorizations: [
1181
- ...state.stepMapping[stepId].authorizations.slice(0, authObjIndex),
1182
- {
1183
- ...state.stepMapping[stepId].authorizations[authObjIndex],
1184
- isDeleting,
1185
- error,
1186
- },
1187
- ...state.stepMapping[stepId].authorizations.slice(authObjIndex + 1),
1188
- ],
1189
- },
1190
- },
1191
- };
1192
- },
1193
-
1194
- toggleDeleteAppAuthorizationFlag(
1195
- state: State,
1196
- params: {
1197
- stepId: number;
1198
- authId: number;
1199
- isDeleting: boolean;
1200
- error: string;
1201
- },
1202
- ): Partial<State> {
1203
- const { stepId, authId, isDeleting, error } = params;
1204
- const authObjIndex = state.stepMapping[stepId].authorizations.findIndex(
1205
- (el) => el.authorizationId === authId,
1206
- );
1207
- return {
1208
- stepMapping: {
1209
- ...state.stepMapping,
1210
- [stepId]: {
1211
- ...state.stepMapping[stepId],
1212
- authorizations: [
1213
- ...state.stepMapping[stepId].authorizations.slice(0, authObjIndex),
1214
- {
1215
- ...state.stepMapping[stepId].authorizations[authObjIndex],
1216
- isDeleting,
1217
- error,
1218
- },
1219
- ...state.stepMapping[stepId].authorizations.slice(authObjIndex + 1),
1220
- ],
1221
- },
1222
- },
1223
- };
1224
- },
1225
-
1226
- setStepAuthId(
1227
- state: State,
1228
- params: { stepId: number; authId: number },
1229
- ): Partial<State> {
1230
- const { stepId, authId } = params;
1231
- return {
1232
- stepMapping: {
1233
- ...state.stepMapping,
1234
- [stepId]: {
1235
- ...state.stepMapping[stepId],
1236
- selectedAuthId: authId,
1237
- },
1238
- },
1239
- };
1240
- },
1241
-
1242
- setStepAuthorization(
1243
- state: State,
1244
- stepId: number,
1245
- selectedAuthId: number | null,
1246
- isVerified: boolean,
1247
- fieldsToReset: number[],
1248
- override: boolean,
1249
- ): Partial<State> {
1250
- const step = state.stepState.steps[state.stepState.stepIndex];
1251
- const stepFromMapping = state.stepMapping[stepId];
1252
- const latestStepState = storeSnapshot.getState().stepState;
1253
- if (
1254
- step &&
1255
- step.type !== 'CONFIRMATION' &&
1256
- latestStepState.currentStep?.type !== 'CONFIRMATION' &&
1257
- latestStepState.currentStep?.stepId === stepId
1258
- ) {
1259
- const { invalidFields } = step;
1260
- if (isVerified) delete invalidFields[stepId];
1261
- const updatedStep = {
1262
- ...state.stepState.steps[state.stepState.stepIndex],
1263
- invalidFields,
1264
- isValid: Object.keys(invalidFields).length < 1 && isVerified,
1265
- isCompleted: stepFromMapping.selectedAuthId !== null || isVerified,
1266
- };
1267
- const authObjIndex = state.stepMapping[stepId]?.authorizations.findIndex(
1268
- (el) => el.authorizationId === selectedAuthId,
1269
- );
1270
-
1271
- if (!(authObjIndex > -1)) {
1272
- /**
1273
- * Reset template step fields when the step does not have the selected auth ID
1274
- */
1275
- if (!(authObjIndex > -1)) {
1276
- return {
1277
- // reset all values for the dependent fields of auth
1278
- stepMapping: {
1279
- ...state.stepMapping,
1280
- [stepId]: {
1281
- ...state.stepMapping[stepId],
1282
- selectedAuthId: null,
1283
- },
1284
- },
1285
- stepDataMapping: override
1286
- ? state.stepDataMapping
1287
- : {
1288
- ...state.stepDataMapping,
1289
- [stepId]: {
1290
- ...state.stepDataMapping[stepId],
1291
- ...fieldsToReset.reduce(
1292
- (acc, curr) => ({
1293
- ...acc,
1294
- [curr]: {
1295
- ...state.stepDataMapping[stepId][curr],
1296
- value: '',
1297
- },
1298
- }),
1299
- {},
1300
- ),
1301
- },
1302
- },
1303
- };
1304
- }
1305
- }
1306
-
1307
- // get all steps, update selected auth ID for all steps where auth type matches
1308
- let stepMappingCopy = {};
1309
-
1310
- Object.keys(state.stepMapping).forEach((stepID) => {
1311
- const currentStep = state.stepMapping[stepID];
1312
- const authStep = state.stepMapping[stepId];
1313
- let defaultStepAuthorizations = currentStep.authorizations;
1314
- if (
1315
- currentStep.step.authorization_type.app.id ===
1316
- state.stepMapping[stepId].step.authorization_type.app.id &&
1317
- stepId !== Number(stepID)
1318
- ) {
1319
- /**
1320
- * this means that there is another step of same app that should also be populated with new auth added
1321
- */
1322
- if (defaultStepAuthorizations.length === 0) {
1323
- defaultStepAuthorizations =
1324
- state.stepMapping[stepId].authorizations;
1325
- } else {
1326
- defaultStepAuthorizations = [
1327
- ...currentStep.authorizations.slice(0, authObjIndex),
1328
- {
1329
- ...state.stepMapping[stepId].authorizations[authObjIndex],
1330
- isVerified,
1331
- isVerifying: false,
1332
- didFetchStatus: true,
1333
- error: '',
1334
- },
1335
- ...currentStep.authorizations.slice(authObjIndex + 1),
1336
- ];
1337
- }
1338
- }
1339
- stepMappingCopy = {
1340
- ...stepMappingCopy,
1341
- [stepID]: {
1342
- ...currentStep,
1343
- selectedAuthId:
1344
- (isVerified && stepId === Number(stepID)) ||
1345
- currentStep.step.authorization_type.id ===
1346
- authStep.step.authorization_type.id // if the step we are currently on has the same auth type, update the ID
1347
- ? selectedAuthId
1348
- : currentStep.selectedAuthId,
1349
- isAuthVerified: isVerified,
1350
- authorizations:
1351
- Number(stepID) === stepId
1352
- ? [
1353
- ...currentStep.authorizations.slice(0, authObjIndex),
1354
- {
1355
- ...currentStep.authorizations[authObjIndex],
1356
- isVerified,
1357
- isVerifying: false,
1358
- didFetchStatus: true,
1359
- error: '',
1360
- },
1361
- ...currentStep.authorizations.slice(authObjIndex + 1),
1362
- ]
1363
- : defaultStepAuthorizations,
1364
- },
1365
- };
1366
- });
1367
-
1368
- return {
1369
- stepState: {
1370
- ...state.stepState,
1371
- steps: [
1372
- ...state.stepState.steps.slice(0, state.stepState.stepIndex),
1373
- updatedStep,
1374
- ...state.stepState.steps.slice(state.stepState.stepIndex + 1),
1375
- ],
1376
- currentStep: updatedStep,
1377
- showValidation: !isVerified && !stepFromMapping.selectedAuthId,
1378
- },
1379
- stepMapping: stepMappingCopy,
1380
- // // reset all values for the dependent fields of auth
1381
- stepDataMapping: override
1382
- ? state.stepDataMapping
1383
- : {
1384
- ...state.stepDataMapping,
1385
- [stepId]: {
1386
- ...state.stepDataMapping[stepId],
1387
- ...fieldsToReset.reduce(
1388
- (acc, curr) => ({
1389
- ...acc,
1390
- [curr]: {
1391
- ...state.stepDataMapping[stepId][curr],
1392
- value: '',
1393
- },
1394
- }),
1395
- {},
1396
- ),
1397
- },
1398
- },
1399
- };
1400
- }
1401
- return state;
1402
- },
1403
-
1404
- resetCustomMappingData(state: State, stepId: number): Partial<State> {
1405
- const step = state.stepMapping[stepId];
1406
- const dynamicFieldId = step.step.template_fields.filter(
1407
- (el) => el.activity_field?.type === 'DYNAMIC',
1408
- )[0]?.id;
1409
-
1410
- if (dynamicFieldId) {
1411
- const stepData = state.stepDataMapping[stepId][dynamicFieldId];
1412
- if (stepData) stepData.objectValue = {};
1413
- return {
1414
- stepDataMapping: {
1415
- ...state.stepDataMapping,
1416
- [stepId]: {
1417
- ...state.stepDataMapping[stepId],
1418
- [dynamicFieldId]: stepData,
1419
- },
1420
- },
1421
- };
1422
- }
1423
- return state;
1424
- },
1425
-
1426
- setStepFieldData(
1427
- state: State,
1428
- data: {
1429
- stepId: number;
1430
- fieldId: number;
1431
- value: string;
1432
- isRequired: boolean;
1433
- passesRegexTest?: boolean;
1434
- },
1435
- ): Partial<State> {
1436
- const { stepId, fieldId, value, passesRegexTest = true } = data;
1437
- const step = state.stepState.steps[state.stepState.stepIndex];
1438
-
1439
- if (step.type !== 'CONFIRMATION') {
1440
- return {
1441
- stepState: {
1442
- ...state.stepState,
1443
- allStepsCompleted: false,
1444
- },
1445
- stepDataMapping: {
1446
- ...state.stepDataMapping,
1447
- [stepId]: {
1448
- ...state.stepDataMapping[stepId],
1449
- [fieldId]: {
1450
- ...state.stepDataMapping[stepId][fieldId],
1451
- value,
1452
- passesRegexTest,
1453
- },
1454
- },
1455
- },
1456
- };
1457
- }
1458
- return state;
1459
- },
1460
-
1461
- clearChildFields(
1462
- state: State,
1463
- data: {
1464
- stepId: number;
1465
- fieldId: number;
1466
- },
1467
- ): Partial<State> {
1468
- // clear all child fields of the field that was just updated
1469
- const { stepId, fieldId } = data;
1470
- const step = state.stepState.steps[state.stepState.stepIndex];
1471
- if (step && step.type !== 'CONFIRMATION') {
1472
- const stepData = state.parentChildMapping[stepId];
1473
-
1474
- if (!stepData) return state;
1475
-
1476
- const field = Object.keys(stepData).find(
1477
- (el) => stepData[el].fieldId === fieldId,
1478
- );
1479
-
1480
- if (!field) return state;
1481
-
1482
- const { childFields } = stepData[field];
1483
-
1484
- if (!childFields) return state;
1485
-
1486
- // empty all fields in step data mapping for this step ID
1487
- const stepDataMapping = state.stepDataMapping[stepId];
1488
-
1489
- // update fields inside step data mapping if machine name matches
1490
- const updatedStepDataMapping = Object.keys(stepDataMapping).reduce(
1491
- (acc, curr: string) => {
1492
- const stepField = stepDataMapping[Number(curr)];
1493
- if (childFields.includes(stepField.machineName)) {
1494
- return {
1495
- ...acc,
1496
- [curr]: {
1497
- ...stepField,
1498
- value: '',
1499
- },
1500
- };
1501
- }
1502
- return {
1503
- ...acc,
1504
- [curr]: stepField,
1505
- };
1506
- },
1507
- {},
1508
- );
1509
-
1510
- return {
1511
- ...state,
1512
- stepDataMapping: {
1513
- ...state.stepDataMapping,
1514
- [stepId]: updatedStepDataMapping,
1515
- },
1516
- };
1517
- }
1518
- return state;
1519
- },
1520
-
1521
- setStepMappingData(
1522
- state: State,
1523
- data: {
1524
- stepId: number;
1525
- fieldId: number;
1526
- id: string;
1527
- value: string | null;
1528
- },
1529
- ): Partial<State> {
1530
- const val = state.stepDataMapping[data.stepId][data.fieldId]?.objectValue;
1531
- let newVal;
1532
- if (data.value) {
1533
- newVal = {
1534
- ...(state.stepDataMapping[data.stepId][data.fieldId]?.objectValue ??
1535
- {}),
1536
- ...{ [data.id]: data.value },
1537
- };
1538
- } else if (val) {
1539
- delete val[data.id];
1540
- newVal = val;
1541
- if (Object.keys(newVal).length === 0) newVal = null;
1542
- }
1543
- if (newVal)
1544
- return {
1545
- stepDataMapping: {
1546
- ...state.stepDataMapping,
1547
- [data.stepId]: {
1548
- ...state.stepDataMapping[data.stepId],
1549
- [data.fieldId]: {
1550
- ...state.stepDataMapping[data.stepId][data.fieldId],
1551
- objectValue: newVal,
1552
- },
1553
- },
1554
- },
1555
- };
1556
- return state;
1557
- },
1558
- resetTemplateFields(state: State): State {
1559
- return {
1560
- ...state,
1561
- stepMapping: initialState.stepMapping,
1562
- stepDataMapping: initialState.stepDataMapping,
1563
- stepState: initialState.stepState,
1564
- showSetupModal: initialState.showSetupModal,
1565
- showSetupInline: initialState.showSetupInline,
1566
- parentChildMapping: initialState.parentChildMapping,
1567
- integrationIdToEdit: initialState.integrationIdToEdit,
1568
- genericData: {
1569
- ...state.genericData,
1570
- brandingApp: initialState.genericData.brandingApp,
1571
- templateId: initialState.genericData.templateId,
1572
- },
1573
- };
1574
- },
1575
- reset(): State {
1576
- return initialState;
1577
- },
1578
- });