@integry/sdk 4.5.2 → 4.5.4

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 (279) hide show
  1. package/.vscode/launch.json +2 -2
  2. package/THIRD_PARTY_LICENSES +0 -37
  3. package/dist/esm/index.csm.d.ts +12 -2
  4. package/dist/esm/index.csm.js +7262 -1
  5. package/dist/umd/index.umd.d.ts +9 -1
  6. package/dist/umd/index.umd.js +7262 -1
  7. package/jest.config.cjs +10 -0
  8. package/package.json +10 -4
  9. package/src/components/AddTagButton/index.ts +23 -0
  10. package/src/components/BasicSelect/index.ts +114 -0
  11. package/src/components/BasicSelect/styles.module.scss +44 -0
  12. package/src/components/Button/index.ts +94 -0
  13. package/src/components/Button/styles.module.scss +152 -0
  14. package/src/components/CheckboxGroup/Checkbox.ts +104 -0
  15. package/src/components/CheckboxGroup/index.ts +190 -0
  16. package/src/components/CheckboxGroup/styles.module.scss +63 -0
  17. package/src/components/CollapsedMenu/index.ts +101 -0
  18. package/src/components/CollapsedMenu/styles.module.scss +46 -0
  19. package/src/components/ConfigureFieldWrapper/index.ts +85 -0
  20. package/src/components/ConfigureFieldWrapper/styles.module.scss +57 -0
  21. package/src/components/EditableText/index.ts +121 -0
  22. package/src/components/EditableText/styles.module.scss +38 -0
  23. package/src/components/EditableTextArea/index.ts +143 -0
  24. package/src/components/EditableTextArea/styles.module.scss +91 -0
  25. package/src/components/ErrorMessage/index.ts +16 -0
  26. package/src/components/ErrorMessage/styles.module.scss +19 -0
  27. package/src/components/ErrorPage/index.ts +42 -0
  28. package/src/components/ErrorPage/styles.module.scss +26 -0
  29. package/src/components/Footer/index.ts +41 -0
  30. package/src/components/Footer/styles.module.scss +40 -0
  31. package/src/components/HTMLContent/index.tsx +275 -0
  32. package/src/components/HTMLContent/styles.module.scss +3 -0
  33. package/src/components/InfoBox/index.ts +48 -0
  34. package/src/components/InfoBox/styles.module.scss +21 -0
  35. package/src/components/Input/BaseInput/index.ts +170 -0
  36. package/src/components/Input/BaseInput/styles.module.scss +94 -0
  37. package/src/components/Input/DateInput/index.ts +103 -0
  38. package/src/components/Input/DateInput/styles.module.scss +50 -0
  39. package/src/components/Input/Input/index.ts +206 -0
  40. package/src/components/Input/Input/styles.module.scss +14 -0
  41. package/src/components/Input/PasswordInput/index.ts +164 -0
  42. package/src/components/Input/PasswordInput/styles.module.scss +37 -0
  43. package/src/components/Input/index.ts +7 -0
  44. package/src/components/Label/index.ts +61 -0
  45. package/src/components/Label/styles.module.scss +41 -0
  46. package/src/components/LargeLoader/index.ts +25 -0
  47. package/src/components/LargeLoader/styles.module.scss +16 -0
  48. package/src/components/Listbox/ListBoxItem.ts +57 -0
  49. package/src/components/Listbox/index.ts +479 -0
  50. package/src/components/Listbox/styles.module.scss +197 -0
  51. package/src/components/Loader/index.ts +25 -0
  52. package/src/components/Loader/styles.module.scss +16 -0
  53. package/src/components/MediaGallery/MediaGalleryModal.ts +82 -0
  54. package/src/components/MediaGallery/MediaSlider.ts +76 -0
  55. package/src/components/MediaGallery/index.ts +92 -0
  56. package/src/components/MediaGallery/styles.module.scss +156 -0
  57. package/src/components/MediaUpload/index.ts +233 -0
  58. package/src/components/MediaUpload/styles.module.scss +118 -0
  59. package/src/components/Modal/index.ts +87 -0
  60. package/src/components/Modal/styles.module.scss +441 -0
  61. package/src/components/MultipurposeField/Dropdown/ListBoxItem.tsx +58 -0
  62. package/src/components/MultipurposeField/Dropdown/index.tsx +981 -0
  63. package/src/components/MultipurposeField/Dropdown/styles.module.scss +208 -0
  64. package/src/components/MultipurposeField/TagMenu/index.ts +384 -0
  65. package/src/components/MultipurposeField/TagMenu/styles.module.scss +136 -0
  66. package/src/components/MultipurposeField/TagOptions/index.tsx +83 -0
  67. package/src/components/MultipurposeField/TagOptions/styles.module.scss +95 -0
  68. package/src/components/MultipurposeField/index.tsx +687 -0
  69. package/src/components/MultipurposeField/styles.module.scss +56 -0
  70. package/src/components/NewModal/index.ts +69 -0
  71. package/src/components/NewModal/styles.module.scss +70 -0
  72. package/src/components/OverflowTooltip/index.tsx +59 -0
  73. package/src/components/PopUp/ConfirmationPopUp/index.ts +58 -0
  74. package/src/components/PopUp/ConfirmationPopUp/styles.module.scss +49 -0
  75. package/src/components/PopUp/SuccessPopUp/index.ts +62 -0
  76. package/src/components/PopUp/SuccessPopUp/styles.module.scss +38 -0
  77. package/src/components/RadioGroup/Radio.ts +129 -0
  78. package/src/components/RadioGroup/index.ts +169 -0
  79. package/src/components/RadioGroup/styles.module.scss +81 -0
  80. package/src/components/Search/index.ts +69 -0
  81. package/src/components/Search/styles.module.scss +149 -0
  82. package/src/components/TabBar/Tab.ts +33 -0
  83. package/src/components/TabBar/index.ts +64 -0
  84. package/src/components/TabBar/styles.module.scss +43 -0
  85. package/src/components/Tag/index.ts +29 -0
  86. package/src/components/Tag/styles.module.scss +57 -0
  87. package/src/components/TextArea/index.ts +172 -0
  88. package/src/components/TextArea/styles.module.scss +70 -0
  89. package/src/components/TextContent/index.tsx +128 -0
  90. package/src/components/TextContent/styles.module.scss +6 -0
  91. package/src/components/ThreeDotLoader/index.ts +39 -0
  92. package/src/components/ThreeDotLoader/styles.module.scss +41 -0
  93. package/src/components/TimeInput/index.ts +129 -0
  94. package/src/components/TimeInput/styles.module.scss +16 -0
  95. package/src/components/Toggle/index.ts +34 -0
  96. package/src/components/Toggle/styles.module.scss +56 -0
  97. package/src/components/Toggle-v2/index.ts +40 -0
  98. package/src/components/Toggle-v2/styles.module.scss +86 -0
  99. package/src/components/Tooltip/index.ts +271 -0
  100. package/src/components/Tooltip/styles.module.scss +105 -0
  101. package/src/components/form/ObjectField/index.ts +364 -0
  102. package/src/components/form/ObjectField/styles.module.scss +103 -0
  103. package/src/components/form/index.ts +3 -0
  104. package/src/contexts/AppContext.ts +12 -0
  105. package/src/declaration.d.ts +7 -0
  106. package/src/extensions/HMAC.ts +25 -0
  107. package/src/extensions/IntegryAPIError.ts +19 -0
  108. package/src/features/common/AccountDropdown/index.ts +291 -0
  109. package/src/features/common/AccountDropdown/styles.module.scss +19 -0
  110. package/src/features/common/ActionForm/index.ts +1818 -0
  111. package/src/features/common/ActionForm/styles.module.scss +23 -0
  112. package/src/features/common/AppCard/index.ts +207 -0
  113. package/src/features/common/AppCard/styles.module.scss +117 -0
  114. package/src/features/common/AppCardCompact/index.ts +189 -0
  115. package/src/features/common/AppCardCompact/styles.module.scss +141 -0
  116. package/src/features/common/AuthSelector/index.ts +537 -0
  117. package/src/features/common/AuthSelector/styles.module.scss +161 -0
  118. package/src/features/common/AuthSelectorCompact/index.ts +706 -0
  119. package/src/features/common/AuthSelectorCompact/styles.module.scss +219 -0
  120. package/src/features/common/AuthSelectorDropdown/index.ts +704 -0
  121. package/src/features/common/AuthSelectorDropdown/styles.module.scss +361 -0
  122. package/src/features/common/DynamicField/index.ts +229 -0
  123. package/src/features/common/DynamicField/styles.module.scss +67 -0
  124. package/src/features/common/DynamicTypedField/index.ts +217 -0
  125. package/src/features/common/DynamicTypedField/styles.module.scss +67 -0
  126. package/src/features/common/FunctionForm/index.ts +862 -0
  127. package/src/features/common/FunctionForm/styles.module.scss +163 -0
  128. package/src/features/common/MappingUI/index.ts +649 -0
  129. package/src/features/common/MappingUI/styles.module.scss +121 -0
  130. package/src/features/common/MarketplaceAppCard/index.ts +279 -0
  131. package/src/features/common/MarketplaceAppCard/styles.module.scss +231 -0
  132. package/src/features/common/MarketplaceAppCardCompact/index.ts +283 -0
  133. package/src/features/common/MarketplaceAppCardCompact/styles.module.scss +255 -0
  134. package/src/features/common/NewMappingUI/index.ts +515 -0
  135. package/src/features/common/NewMappingUI/styles.module.scss +113 -0
  136. package/src/features/common/RequestAppWidget/RequestAppModal/index.ts +67 -0
  137. package/src/features/common/RequestAppWidget/RequestAppModal/styles.module.scss +23 -0
  138. package/src/features/common/RequestAppWidget/index.ts +48 -0
  139. package/src/features/common/RequestAppWidget/request-app-form.ts +89 -0
  140. package/src/features/common/RequestAppWidget/styles.module.scss +43 -0
  141. package/src/features/common/SectionField/index.ts +272 -0
  142. package/src/features/common/SectionField/styles.module.scss +67 -0
  143. package/src/features/common/Step/index.ts +827 -0
  144. package/src/features/common/Step/styles.module.scss +12 -0
  145. package/src/features/common/StepNavigation/CollapsedSteps.ts +125 -0
  146. package/src/features/common/StepNavigation/NavItem.ts +111 -0
  147. package/src/features/common/StepNavigation/index.ts +257 -0
  148. package/src/features/common/StepNavigation/styles.module.scss +117 -0
  149. package/src/features/common/Steps/index.ts +1139 -0
  150. package/src/features/common/Steps/styles.module.scss +314 -0
  151. package/src/features/containers/AppFlowContainer/AppFlowListing/compactStyles.module.scss +383 -0
  152. package/src/features/containers/AppFlowContainer/AppFlowListing/flow-instance.tsx +367 -0
  153. package/src/features/containers/AppFlowContainer/AppFlowListing/flowCard.tsx +194 -0
  154. package/src/features/containers/AppFlowContainer/AppFlowListing/flowCardCompact.tsx +389 -0
  155. package/src/features/containers/AppFlowContainer/AppFlowListing/flowInstanceCompact.tsx +577 -0
  156. package/src/features/containers/AppFlowContainer/AppFlowListing/index.tsx +83 -0
  157. package/src/features/containers/AppFlowContainer/AppFlowListing/styles.module.scss +212 -0
  158. package/src/features/containers/AppFlowContainer/AppFlowWrap/app-page-loader.tsx +45 -0
  159. package/src/features/containers/AppFlowContainer/AppFlowWrap/index.tsx +1081 -0
  160. package/src/features/containers/AppFlowContainer/AppFlowWrap/styles.module.scss +452 -0
  161. package/src/features/containers/AppFlowContainer/Authentication/index.ts +610 -0
  162. package/src/features/containers/AppFlowContainer/Authentication/styles.module.scss +468 -0
  163. package/src/features/containers/AppFlowContainer/index.ts +114 -0
  164. package/src/features/containers/AppPageContainer/AppPage/index.tsx +262 -0
  165. package/src/features/containers/AppPageContainer/AppPage/styles.module.scss +120 -0
  166. package/src/features/containers/AppPageContainer/IntegrationCard/index.ts +165 -0
  167. package/src/features/containers/AppPageContainer/IntegrationCard/styles.module.scss +81 -0
  168. package/src/features/containers/AppPageContainer/index.tsx +93 -0
  169. package/src/features/containers/AppPageContainer/styles.module.scss +0 -0
  170. package/src/features/containers/AppsForFlows/index.ts +161 -0
  171. package/src/features/containers/AppsForFlows/styles.module.scss +280 -0
  172. package/src/features/containers/AppsForFlowsCompact/index.ts +161 -0
  173. package/src/features/containers/AppsForFlowsCompact/styles.module.scss +279 -0
  174. package/src/features/containers/AuthSetupContainer/AppSelection.ts +73 -0
  175. package/src/features/containers/AuthSetupContainer/AuthTypeSelection.ts +67 -0
  176. package/src/features/containers/AuthSetupContainer/Footer.ts +32 -0
  177. package/src/features/containers/AuthSetupContainer/Header.ts +39 -0
  178. package/src/features/containers/AuthSetupContainer/PostAdditionPopup.ts +27 -0
  179. package/src/features/containers/AuthSetupContainer/index.ts +349 -0
  180. package/src/features/containers/AuthSetupContainer/styles.module.scss +229 -0
  181. package/src/features/containers/FlowSetupContainer/index.ts +390 -0
  182. package/src/features/containers/FlowSetupContainer/styles.module.scss +18 -0
  183. package/src/features/containers/MarkeplaceApps/index.ts +574 -0
  184. package/src/features/containers/MarkeplaceApps/styles.module.scss +559 -0
  185. package/src/features/containers/MarketplaceAppsCompact/index.ts +576 -0
  186. package/src/features/containers/MarketplaceAppsCompact/styles.module.scss +546 -0
  187. package/src/features/containers/MarketplaceAppsContainer/index.ts +83 -0
  188. package/src/features/containers/MarketplaceContainer/AppCard/index.ts +91 -0
  189. package/src/features/containers/MarketplaceContainer/AppCard/styles.module.scss +66 -0
  190. package/src/features/containers/MarketplaceContainer/AppListing/index.ts +34 -0
  191. package/src/features/containers/MarketplaceContainer/AppListing/styles.module.scss +10 -0
  192. package/src/features/containers/MarketplaceContainer/MarketplaceContentWrap/index.ts +132 -0
  193. package/src/features/containers/MarketplaceContainer/MarketplaceContentWrap/styles.module.scss +117 -0
  194. package/src/features/containers/MarketplaceContainer/index.ts +242 -0
  195. package/src/features/containers/MarketplaceContainer/styles.module.scss +84 -0
  196. package/src/features/containers/SDKContainer/index.ts +817 -0
  197. package/src/features/containers/SDKContainer/styles.module.scss +266 -0
  198. package/src/features/containers/SDKDebugContainer/index.ts +137 -0
  199. package/src/features/containers/SDKDebugContainer/styles.module.scss +37 -0
  200. package/src/features/containers/SDKFailedContainer/index.ts +117 -0
  201. package/src/features/containers/SDKFailedContainer/styles.module.scss +57 -0
  202. package/src/features/integrations/IntegrationRow/Icons.ts +77 -0
  203. package/src/features/integrations/IntegrationRow/index.ts +129 -0
  204. package/src/features/integrations/IntegrationRow/styles.module.scss +62 -0
  205. package/src/features/integrations/IntegrationsHeader/index.ts +34 -0
  206. package/src/features/integrations/IntegrationsHeader/styles.module.scss +47 -0
  207. package/src/features/integrations/IntegrationsList/index.ts +252 -0
  208. package/src/features/integrations/IntegrationsList/styles.module.scss +67 -0
  209. package/src/features/templates/Template/index.ts +295 -0
  210. package/src/features/templates/Template/styles.module.scss +226 -0
  211. package/src/features/templates/TemplatesView/index.ts +368 -0
  212. package/src/features/templates/TemplatesView/styles.module.scss +71 -0
  213. package/src/features/templates/TemplatesViewCompact/index.ts +364 -0
  214. package/src/features/templates/TemplatesViewCompact/styles.module.scss +141 -0
  215. package/src/hooks/useAutosizeTextArea.ts +22 -0
  216. package/src/hooks/useCustomRef.ts +13 -0
  217. package/src/hooks/useDebounce.ts +17 -0
  218. package/src/hooks/useElementResize.ts +40 -0
  219. package/src/hooks/useEventListener.ts +44 -0
  220. package/src/hooks/useHover.ts +40 -0
  221. package/src/hooks/useOnClickOutside.ts +32 -0
  222. package/src/index.ts +2051 -0
  223. package/src/index.umd.ts +13 -0
  224. package/src/interfaces/index.ts +924 -0
  225. package/src/modules/api/index.ts +1315 -0
  226. package/src/modules/api/responseHandler.ts +38 -0
  227. package/src/modules/event-emitter/index.ts +72 -0
  228. package/src/modules/event-emitter/runners/abstract.ts +21 -0
  229. package/src/modules/event-emitter/runners/default.ts +11 -0
  230. package/src/modules/event-emitter/runners/ntimes.ts +28 -0
  231. package/src/modules/event-emitter/types.ts +34 -0
  232. package/src/store/actionFunctions.ts +1573 -0
  233. package/src/store/index.ts +17 -0
  234. package/src/store/initialState.ts +58 -0
  235. package/src/stories/Button.stories.tsx +83 -0
  236. package/src/stories/Checkbox/Checkbox.stories.tsx +41 -0
  237. package/src/stories/Checkbox/CheckboxGroup.stories.tsx +46 -0
  238. package/src/stories/EditableText.stories.tsx +35 -0
  239. package/src/stories/Input/BaseInput.stories.tsx +48 -0
  240. package/src/stories/Input/DateInput.stories.tsx +28 -0
  241. package/src/stories/Input/Input.stories.tsx +24 -0
  242. package/src/stories/Input/PasswordInput.stories.tsx +26 -0
  243. package/src/stories/Introduction.stories.mdx +211 -0
  244. package/src/stories/Label.stories.tsx +27 -0
  245. package/src/stories/Listbox.stories.tsx +122 -0
  246. package/src/stories/Radio/Radio.stories.tsx +39 -0
  247. package/src/stories/Radio/RadioGroup.stories.tsx +46 -0
  248. package/src/stories/StepNavigation/NavItem.stories.tsx +31 -0
  249. package/src/stories/StepNavigation/StepNavigation.stories.tsx +50 -0
  250. package/src/stories/TabBar.stories.tsx +31 -0
  251. package/src/stories/TextArea.stories.tsx +23 -0
  252. package/src/stories/TimeInput.stories.tsx +37 -0
  253. package/src/stories/Toggle.stories.tsx +33 -0
  254. package/src/stories/assets/code-brackets.svg +1 -0
  255. package/src/stories/assets/colors.svg +1 -0
  256. package/src/stories/assets/comments.svg +1 -0
  257. package/src/stories/assets/direction.svg +1 -0
  258. package/src/stories/assets/flow.svg +1 -0
  259. package/src/stories/assets/plugin.svg +1 -0
  260. package/src/stories/assets/repo.svg +1 -0
  261. package/src/stories/assets/stackalt.svg +1 -0
  262. package/src/types/index.ts +293 -0
  263. package/src/types/store.ts +366 -0
  264. package/src/types/utils.ts +19 -0
  265. package/src/utils/ActivityOutputUtils.ts +163 -0
  266. package/src/utils/common.ts +20 -0
  267. package/src/utils/copyToClipboard.ts +24 -0
  268. package/src/utils/datetime.ts +101 -0
  269. package/src/utils/getUrlParam.ts +11 -0
  270. package/src/utils/isAuthMessage.ts +16 -0
  271. package/src/utils/isBrowser.ts +1 -0
  272. package/src/utils/jsonEncodeDecode.ts +15 -0
  273. package/src/utils/objectUtils.ts +116 -0
  274. package/src/utils/popup.ts +30 -0
  275. package/src/utils/searchJson.ts +51 -0
  276. package/src/utils/stepUtils.ts +45 -0
  277. package/src/utils/truncate.ts +6 -0
  278. package/test/setup.ts +1 -0
  279. package/vitest.config.ts +10 -0
@@ -0,0 +1,1315 @@
1
+ /**
2
+ * Simple API module
3
+ */
4
+
5
+ import fetch from 'unfetch';
6
+
7
+ // eslint-disable-next-line import/no-cycle
8
+ import {
9
+ APIConfig,
10
+ BundleResponse,
11
+ IntegrationSaveResponse,
12
+ SaveOrUpdateIntegrationBody,
13
+ TemplateResponse,
14
+ IntegrationResponse,
15
+ TemplateStep,
16
+ ActivityCustomField,
17
+ AppsForAuthConnectionResponse,
18
+ AppsForAuthConnection,
19
+ Integration,
20
+ MarketplaceAppBundle,
21
+ AppRequestFormData,
22
+ MarketplaceAppAuthorizationType,
23
+ UploadFileObj,
24
+ AppFlowsResponse,
25
+ BrandingApp,
26
+ ExecuteFlowResponse,
27
+ IncomingWebhookPayload,
28
+ NestedObject,
29
+ MarketplaceApp,
30
+ } from '@/interfaces';
31
+
32
+ import { ResponseHandler } from './responseHandler';
33
+
34
+ class IntegryAPI {
35
+ private config: APIConfig;
36
+
37
+ constructor(config: APIConfig) {
38
+ this.config = config;
39
+ }
40
+
41
+ static addUrlSearchParams = (
42
+ url: URL,
43
+ paramList: Record<string, string | number | boolean | null>,
44
+ ) =>
45
+ Object.keys(paramList).map(
46
+ (objKey) =>
47
+ paramList[objKey] !== undefined &&
48
+ paramList[objKey] !== null &&
49
+ url.searchParams.append(objKey, `${paramList[objKey]}`),
50
+ );
51
+
52
+ public getTemplate = async (
53
+ templateId: number,
54
+ self_auth_id?: number,
55
+ app_auth_id?: number,
56
+ ): Promise<TemplateResponse | null> => {
57
+ const url = new URL(`${this.config.baseUrlv2}/template/${templateId}/`);
58
+
59
+ IntegryAPI.addUrlSearchParams(url, {
60
+ app_key: this.config.appKey,
61
+ hash: this.config.hash,
62
+ user_id: this.config.userId,
63
+ self_api_key: this.config.apiKey || null,
64
+ self_auth_id: this.config.authId || self_auth_id || null,
65
+ self_auth_extras: this.config.extras
66
+ ? JSON.stringify(this.config.extras)
67
+ : null,
68
+ app_auth_id: app_auth_id || null,
69
+ });
70
+
71
+ try {
72
+ const response = await fetch(url.toString()).then((data) =>
73
+ ResponseHandler<TemplateResponse>(data),
74
+ );
75
+ return response.data;
76
+ } catch (error) {
77
+ console.error(error);
78
+ return null;
79
+ }
80
+ };
81
+
82
+ public getAuthUrl = (authorizationTypeId: number): string => {
83
+ const url = new URL(
84
+ `${this.config.baseUrl}/auth/login/${authorizationTypeId}/`,
85
+ );
86
+
87
+ IntegryAPI.addUrlSearchParams(url, {
88
+ app_key: this.config.appKey,
89
+ hash: this.config.hash,
90
+ user_id: this.config.userId,
91
+ });
92
+
93
+ return url.toString();
94
+ };
95
+
96
+ public getAuthUrlByApp = (appName: string): string => {
97
+ const url = new URL(`${this.config.baseUrl}/auth/app/login/${appName}/`);
98
+
99
+ IntegryAPI.addUrlSearchParams(url, {
100
+ app_key: this.config.appKey,
101
+ hash: this.config.hash,
102
+ user_id: this.config.userId,
103
+ });
104
+
105
+ return url.toString();
106
+ };
107
+
108
+ public getAppById = async (appId: string): Promise<BrandingApp | null> => {
109
+ const url = new URL(`${this.config.baseUrl}/api/apps/${appId}/`);
110
+
111
+ IntegryAPI.addUrlSearchParams(url, {
112
+ app_key: this.config.appKey,
113
+ hash: this.config.hash,
114
+ user_id: this.config.userId,
115
+ sdk_request: true,
116
+ });
117
+
118
+ try {
119
+ const response = await fetch(url.toString()).then((data) =>
120
+ ResponseHandler<BrandingApp>(data),
121
+ );
122
+
123
+ return response.data;
124
+ } catch (error) {
125
+ console.error(error);
126
+ return null;
127
+ }
128
+ };
129
+
130
+ public getTemplateStep = async (
131
+ stepId: number,
132
+ integrationId?: number,
133
+ versionId?: number,
134
+ self_auth_id?: number,
135
+ app_auth_id?: number,
136
+ ): Promise<TemplateStep | null> => {
137
+ const url = new URL(`${this.config.baseUrl}/template_step/${stepId}/`);
138
+
139
+ IntegryAPI.addUrlSearchParams(url, {
140
+ app_key: this.config.appKey,
141
+ hash: this.config.hash,
142
+ user_id: this.config.userId,
143
+ self_api_key: this.config.apiKey || null,
144
+ self_auth_id: this.config.authId || self_auth_id || null,
145
+ integration_id: integrationId ? `${integrationId}` : null,
146
+ version_id: versionId ? `${versionId}` : null,
147
+ self_auth_extras: this.config.extras
148
+ ? JSON.stringify(this.config.extras)
149
+ : null,
150
+ app_auth_id: app_auth_id || null,
151
+ v: '4.0',
152
+ });
153
+
154
+ try {
155
+ const response = await fetch(url.toString()).then((data) =>
156
+ ResponseHandler<TemplateStep>(data),
157
+ );
158
+
159
+ return response.data;
160
+ } catch (error) {
161
+ console.error(error);
162
+ return null;
163
+ }
164
+ };
165
+
166
+ public verifyOAuth = async (authId: number): Promise<boolean | null> => {
167
+ const url = new URL(
168
+ `${this.config.baseUrl}/${this.config.oauthVerifyPath}`,
169
+ );
170
+
171
+ IntegryAPI.addUrlSearchParams(url, {
172
+ authorization_id: `${authId}`,
173
+ app_key: this.config.appKey,
174
+ hash: this.config.hash,
175
+ user_id: this.config.userId,
176
+ });
177
+
178
+ try {
179
+ const response = await fetch(url.toString(), { method: 'POST' }).then(
180
+ ResponseHandler,
181
+ );
182
+ return !!response.data;
183
+ } catch (error) {
184
+ console.error(error);
185
+ return null;
186
+ }
187
+ };
188
+
189
+ public verifyOAuthWithError = async (
190
+ authId: number,
191
+ ): Promise<{
192
+ error_message: string;
193
+ status: number;
194
+ is_valid: boolean;
195
+ } | null> => {
196
+ const url = new URL(
197
+ `${this.config.baseUrl}/${this.config.oauthVerifyPath}?return_error=true`,
198
+ );
199
+
200
+ IntegryAPI.addUrlSearchParams(url, {
201
+ authorization_id: `${authId}`,
202
+ app_key: this.config.appKey,
203
+ hash: this.config.hash,
204
+ user_id: this.config.userId,
205
+ });
206
+
207
+ try {
208
+ const response = await fetch(url.toString(), {
209
+ method: 'POST',
210
+ }).then((data) =>
211
+ ResponseHandler<{
212
+ error_message: string;
213
+ status: number;
214
+ is_valid: boolean;
215
+ }>(data),
216
+ );
217
+ return response.data;
218
+ } catch (error) {
219
+ console.error(error);
220
+ return null;
221
+ }
222
+ };
223
+
224
+ public deleteAuth = async (
225
+ authId: number,
226
+ force?: boolean,
227
+ ): Promise<{
228
+ data: string | null;
229
+ status: number;
230
+ } | null> => {
231
+ const url = new URL(
232
+ `${this.config.baseUrl}/connected-accounts/${authId}?force=${
233
+ force ?? false
234
+ }`,
235
+ );
236
+
237
+ IntegryAPI.addUrlSearchParams(url, {
238
+ app_key: this.config.appKey,
239
+ hash: this.config.hash,
240
+ user_id: this.config.userId,
241
+ });
242
+
243
+ try {
244
+ const response = await fetch(url.toString(), {
245
+ method: 'DELETE',
246
+ }).then((data) => ResponseHandler<string>(data));
247
+
248
+ return {
249
+ status: response.status,
250
+ data: response.data,
251
+ };
252
+ } catch (error) {
253
+ console.error(error);
254
+ return null;
255
+ }
256
+ };
257
+
258
+ public callDynamicDataEndpoint = async <T>(
259
+ url: URL,
260
+ endpointData: Record<string, string> = {},
261
+ method = 'GET',
262
+ body?: Record<string, string>,
263
+ ): Promise<T | null> => {
264
+ IntegryAPI.addUrlSearchParams(url, {
265
+ app_key: this.config.appKey,
266
+ hash: this.config.hash,
267
+ user_id: this.config.userId,
268
+ ...endpointData,
269
+ });
270
+
271
+ try {
272
+ const response = await fetch(url.toString(), {
273
+ method,
274
+ headers: {
275
+ 'Content-Type': 'application/json',
276
+ },
277
+ body: JSON.stringify(body),
278
+ }).then((data) => ResponseHandler<T>(data));
279
+ return response.data;
280
+ } catch (error) {
281
+ console.error(error);
282
+ return null;
283
+ }
284
+ };
285
+
286
+ public getTemplateListing = async (
287
+ deploymentId: number,
288
+ tags?: string[],
289
+ ): Promise<BundleResponse | null> => {
290
+ const url = new URL(`${this.config.baseUrl}/bundle/${deploymentId}/`);
291
+
292
+ if ((tags || []).length > 0) {
293
+ IntegryAPI.addUrlSearchParams(url, {
294
+ app_key: this.config.appKey,
295
+ hash: this.config.hash,
296
+ user_id: this.config.userId,
297
+ tags: (tags || []).join(','),
298
+ });
299
+ } else {
300
+ IntegryAPI.addUrlSearchParams(url, {
301
+ app_key: this.config.appKey,
302
+ hash: this.config.hash,
303
+ user_id: this.config.userId,
304
+ });
305
+ }
306
+
307
+ try {
308
+ const response = await fetch(url.toString()).then((data) =>
309
+ ResponseHandler<BundleResponse>(data),
310
+ );
311
+ return response.data;
312
+ } catch (error) {
313
+ console.error(error);
314
+ return null;
315
+ }
316
+ };
317
+
318
+ public getTemplateListingV2 = async (
319
+ tags?: string[],
320
+ deploymentId?: number | null,
321
+ ): Promise<BundleResponse | null> => {
322
+ const url = new URL(
323
+ `${this.config.baseUrl}/api/v1/sdk/flows/?page_size=9999&show_draft=true${
324
+ deploymentId ? `&deployment_id=${deploymentId}` : ''
325
+ }`,
326
+ );
327
+
328
+ if ((tags || []).length > 0) {
329
+ IntegryAPI.addUrlSearchParams(url, {
330
+ app_key: this.config.appKey,
331
+ hash: this.config.hash,
332
+ user_id: this.config.userId,
333
+ tags: (tags || []).join(','),
334
+ });
335
+ } else {
336
+ IntegryAPI.addUrlSearchParams(url, {
337
+ app_key: this.config.appKey,
338
+ hash: this.config.hash,
339
+ user_id: this.config.userId,
340
+ });
341
+ }
342
+
343
+ try {
344
+ const response = await fetch(url.toString()).then((data) =>
345
+ ResponseHandler<BundleResponse>(data),
346
+ );
347
+ return response.data;
348
+ } catch (error) {
349
+ console.error(error);
350
+ return null;
351
+ }
352
+ };
353
+
354
+ public saveIntegration = async (
355
+ body: SaveOrUpdateIntegrationBody,
356
+ ): Promise<IntegrationSaveResponse | null> => {
357
+ const url = new URL(`${this.config.baseUrlv2}/integration/`);
358
+
359
+ IntegryAPI.addUrlSearchParams(url, {
360
+ async: false,
361
+ app_key: this.config.appKey,
362
+ hash: this.config.hash,
363
+ user_id: this.config.userId,
364
+ activate: this.config?.defaultIntegrationStatus ?? true,
365
+ });
366
+
367
+ try {
368
+ const response = await fetch(url.toString(), {
369
+ method: 'POST',
370
+ body: JSON.stringify(body),
371
+ headers: {
372
+ 'Content-Type': 'application/json',
373
+ },
374
+ }).then((data) => ResponseHandler<IntegrationSaveResponse>(data));
375
+ return response.data;
376
+ } catch (error) {
377
+ console.error(error);
378
+ return null;
379
+ }
380
+ };
381
+
382
+ public getAppsForAuthConnection = async (payload?: {
383
+ deploymentId?: string;
384
+ page?: number;
385
+ tags?: string;
386
+ }): Promise<any | null> => {
387
+ const url = new URL(`${this.config.baseUrl}/api/v1/sdk/flow-apps/`);
388
+
389
+ IntegryAPI.addUrlSearchParams(url, {
390
+ app_key: this.config.appKey,
391
+ hash: this.config.hash,
392
+ user_id: this.config.userId,
393
+ page: `${payload?.page ?? ''}`,
394
+ tags: payload?.tags ?? '',
395
+ page_size: 9999,
396
+ });
397
+
398
+ try {
399
+ const response = await fetch(url.toString(), {
400
+ method: 'GET',
401
+ }).then((data) => ResponseHandler<BrandingApp>(data));
402
+ return response.data;
403
+ } catch (error) {
404
+ console.error(error);
405
+ return null;
406
+ }
407
+ };
408
+
409
+ public updateIntegration = async (
410
+ integrationId: string,
411
+ shouldActivate: boolean,
412
+ body: SaveOrUpdateIntegrationBody,
413
+ ): Promise<boolean | null> => {
414
+ const url = new URL(
415
+ `${this.config.baseUrlv2}/integration/${integrationId}/`,
416
+ );
417
+
418
+ IntegryAPI.addUrlSearchParams(url, {
419
+ async: false,
420
+ app_key: this.config.appKey,
421
+ hash: this.config.hash,
422
+ user_id: this.config.userId,
423
+ activate: shouldActivate,
424
+ });
425
+
426
+ try {
427
+ const response = await fetch(url.toString(), {
428
+ method: 'PUT',
429
+ body: JSON.stringify(body),
430
+ headers: {
431
+ 'Content-Type': 'application/json',
432
+ },
433
+ }).then((data) => ResponseHandler<boolean>(data));
434
+ return response.data;
435
+ } catch (error) {
436
+ console.error(error);
437
+ return null;
438
+ }
439
+ };
440
+
441
+ public renameIntegration = async (
442
+ integrationId: string,
443
+ name: string,
444
+ ): Promise<Integration | null> => {
445
+ const url = new URL(
446
+ `${this.config.baseUrlv2}/integration/${integrationId}/rename/`,
447
+ );
448
+
449
+ IntegryAPI.addUrlSearchParams(url, {
450
+ app_key: this.config.appKey,
451
+ hash: this.config.hash,
452
+ user_id: this.config.userId,
453
+ });
454
+
455
+ try {
456
+ const response = await fetch(url.toString(), {
457
+ method: 'PUT',
458
+ body: JSON.stringify({ name }),
459
+ headers: {
460
+ 'Content-Type': 'application/json',
461
+ },
462
+ }).then((data) => ResponseHandler<Integration>(data));
463
+ return response.data;
464
+ } catch (error) {
465
+ console.error(error);
466
+ return null;
467
+ }
468
+ };
469
+
470
+ public deleteIntegration = async (
471
+ integrationId: number,
472
+ ): Promise<boolean | null> => {
473
+ const url = new URL(
474
+ `${this.config.baseUrl}/setup/template/${integrationId}/`,
475
+ );
476
+
477
+ IntegryAPI.addUrlSearchParams(url, {
478
+ app_key: this.config.appKey,
479
+ hash: this.config.hash,
480
+ user_id: this.config.userId,
481
+ });
482
+
483
+ try {
484
+ const response = await fetch(url.toString(), {
485
+ method: 'DELETE',
486
+ }).then((data) => ResponseHandler<boolean>(data));
487
+ return response.data;
488
+ } catch (error) {
489
+ console.error(error);
490
+ return null;
491
+ }
492
+ };
493
+
494
+ public toggleIntegration = async (
495
+ integrationId: number,
496
+ activate: boolean,
497
+ ): Promise<string | null> => {
498
+ const url = new URL(
499
+ `${this.config.baseUrlv2}/integration/${integrationId}/${
500
+ activate ? 'enable' : 'disable'
501
+ }/`,
502
+ );
503
+
504
+ IntegryAPI.addUrlSearchParams(url, {
505
+ app_key: this.config.appKey,
506
+ hash: this.config.hash,
507
+ user_id: this.config.userId,
508
+ });
509
+
510
+ try {
511
+ const response = await fetch(url.toString(), {
512
+ method: 'PUT',
513
+ }).then((data) => ResponseHandler<string>(data));
514
+ return response.data;
515
+ } catch (error) {
516
+ console.error(error);
517
+ return null;
518
+ }
519
+ };
520
+
521
+ public getIntegrationById = async (
522
+ integrationId: number,
523
+ isReadOnly?: boolean,
524
+ ): Promise<IntegrationResponse | null> => {
525
+ const url = new URL(
526
+ `${this.config.baseUrlv2}/integration/${integrationId}`,
527
+ );
528
+
529
+ IntegryAPI.addUrlSearchParams(url, {
530
+ app_key: this.config.appKey,
531
+ hash: this.config.hash,
532
+ user_id: this.config.userId,
533
+ is_read_only: !!isReadOnly,
534
+ });
535
+
536
+ try {
537
+ const response = await fetch(url.toString(), {
538
+ method: 'GET',
539
+ }).then((data) => ResponseHandler<IntegrationResponse>(data));
540
+ return response.data;
541
+ } catch (error) {
542
+ console.error(error);
543
+ return null;
544
+ }
545
+ };
546
+
547
+ public getCustomFields = async (params: {
548
+ activityFieldId: number;
549
+ stepName?: string;
550
+ authorizationId: number;
551
+ endpointData?: Record<string, string | number>;
552
+ }): Promise<ActivityCustomField[] | null> => {
553
+ const url = new URL(
554
+ `${this.config.baseUrl}/endpoints/get_custom_fields/${params.activityFieldId}/`,
555
+ );
556
+
557
+ IntegryAPI.addUrlSearchParams(url, {
558
+ app_key: this.config.appKey,
559
+ hash: this.config.hash,
560
+ user_id: this.config.userId,
561
+ step_name: params.stepName || '',
562
+ authorization_id: `${params.authorizationId}`,
563
+ ...(params.endpointData || {}),
564
+ });
565
+
566
+ try {
567
+ const response = await fetch(url.toString(), {
568
+ method: 'GET',
569
+ }).then((data) => ResponseHandler<ActivityCustomField[]>(data));
570
+ return response.data;
571
+ } catch (error) {
572
+ console.error(error);
573
+ return null;
574
+ }
575
+ };
576
+
577
+ public verifyAuthConfig = async (params: {
578
+ deploymentId?: string;
579
+ }): Promise<{ config_verified: boolean; meta: any } | null> => {
580
+ const url = new URL(`${this.config.baseUrl}/verify-sdk-config/`);
581
+
582
+ if (params.deploymentId) {
583
+ IntegryAPI.addUrlSearchParams(url, {
584
+ app_key: this.config.appKey,
585
+ hash: this.config.hash,
586
+ user_id: this.config.userId,
587
+ bundle_id: params.deploymentId || '',
588
+ });
589
+ } else {
590
+ IntegryAPI.addUrlSearchParams(url, {
591
+ app_key: this.config.appKey,
592
+ hash: this.config.hash,
593
+ user_id: this.config.userId,
594
+ });
595
+ }
596
+
597
+ try {
598
+ const response = await fetch(url.toString(), {
599
+ method: 'GET',
600
+ }).then((data) =>
601
+ ResponseHandler<{ config_verified: boolean; meta: any }>(data),
602
+ );
603
+ return response.data;
604
+ } catch (error) {
605
+ console.error(error);
606
+ return null;
607
+ }
608
+ };
609
+
610
+ public getMarketplaceApps = async (payload: {
611
+ marketplaceId: string;
612
+ }): Promise<MarketplaceAppBundle[] | null> => {
613
+ const url = new URL(`${this.config.baseUrl}/sdk/bundle_apps/`);
614
+
615
+ IntegryAPI.addUrlSearchParams(url, {
616
+ app_key: this.config.appKey,
617
+ hash: this.config.hash,
618
+ user_id: this.config.userId,
619
+ bundle: payload.marketplaceId,
620
+ });
621
+
622
+ try {
623
+ const response = await fetch(url.toString(), {
624
+ method: 'GET',
625
+ }).then((data) => ResponseHandler<MarketplaceAppBundle[]>(data));
626
+ return response.data;
627
+ } catch (error) {
628
+ console.error(error);
629
+ return null;
630
+ }
631
+ };
632
+
633
+ public getMarketplaceAppDetail = async (payload: {
634
+ marketplaceId: string;
635
+ marketplaceAppId: string;
636
+ app_auth_id?: number | undefined | null;
637
+ }): Promise<MarketplaceAppBundle | null> => {
638
+ const url = new URL(
639
+ `${this.config.baseUrl}/sdk/bundle_apps/${payload.marketplaceAppId}/`,
640
+ );
641
+
642
+ IntegryAPI.addUrlSearchParams(url, {
643
+ app_key: this.config.appKey,
644
+ hash: this.config.hash,
645
+ user_id: this.config.userId,
646
+ bundle: payload.marketplaceId,
647
+ app_auth_id: payload.app_auth_id || null,
648
+ });
649
+
650
+ try {
651
+ const response = await fetch(url.toString(), {
652
+ method: 'GET',
653
+ }).then((data) => ResponseHandler<MarketplaceAppBundle>(data));
654
+ return response.data;
655
+ } catch (error) {
656
+ console.error(error);
657
+ return null;
658
+ }
659
+ };
660
+
661
+ public sendRequestForNewApp = async (
662
+ marketplaceId: number,
663
+ formData: AppRequestFormData,
664
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
665
+ ): Promise<any | null> => {
666
+ const url = new URL(
667
+ `${this.config.baseUrl}/bundle/${marketplaceId}/app_requests/`,
668
+ );
669
+
670
+ IntegryAPI.addUrlSearchParams(url, {
671
+ app_key: this.config.appKey,
672
+ hash: this.config.hash,
673
+ user_id: this.config.userId,
674
+ });
675
+
676
+ try {
677
+ const response = await fetch(url.toString(), {
678
+ method: 'POST',
679
+ body: JSON.stringify(formData),
680
+ headers: {
681
+ 'Content-Type': 'application/json',
682
+ },
683
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
684
+ }).then((data) => ResponseHandler<any>(data));
685
+ return response.data;
686
+ } catch (error) {
687
+ console.error(error);
688
+ return null;
689
+ }
690
+ };
691
+
692
+ public getMarketplaceDetails = async (payload: {
693
+ marketplaceId: string;
694
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
695
+ }): Promise<any | null> => {
696
+ const url = new URL(
697
+ `${this.config.baseUrl}/bundle/${payload.marketplaceId}`,
698
+ );
699
+
700
+ IntegryAPI.addUrlSearchParams(url, {
701
+ app_key: this.config.appKey,
702
+ hash: this.config.hash,
703
+ user_id: this.config.userId,
704
+ });
705
+
706
+ try {
707
+ const response = await fetch(url.toString(), {
708
+ method: 'GET',
709
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
710
+ }).then((data) => ResponseHandler<any>(data));
711
+ return response.data;
712
+ } catch (error) {
713
+ console.error(error);
714
+ return null;
715
+ }
716
+ };
717
+
718
+ public setDefaultAuthorization = async (payload: {
719
+ authorizationId: number;
720
+ authorizationTypeId: number;
721
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
722
+ }): Promise<{ id: number; user_identity: string } | null> => {
723
+ const url = new URL(
724
+ `${this.config.baseUrl}/connected-accounts/${payload.authorizationId}/set_as_default/`,
725
+ );
726
+
727
+ IntegryAPI.addUrlSearchParams(url, {
728
+ app_key: this.config.appKey,
729
+ hash: this.config.hash,
730
+ user_id: this.config.userId,
731
+ authorization_type: `${payload.authorizationTypeId}`,
732
+ });
733
+
734
+ try {
735
+ const response = await fetch(url.toString(), {
736
+ method: 'POST',
737
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
738
+ }).then((data) =>
739
+ ResponseHandler<{ id: number; user_identity: string }>(data),
740
+ );
741
+ return response.data;
742
+ } catch (error) {
743
+ console.error(error);
744
+ return null;
745
+ }
746
+ };
747
+
748
+ public saveAppDescription = async (
749
+ bundleAppId: number,
750
+ payload: {
751
+ long_description: string;
752
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
753
+ },
754
+ ): Promise<any | null> => {
755
+ const url = new URL(`${this.config.baseUrl}/bundle_apps/${bundleAppId}/`);
756
+
757
+ IntegryAPI.addUrlSearchParams(url, {
758
+ app_key: this.config.appKey,
759
+ hash: this.config.hash,
760
+ user_id: this.config.userId,
761
+ });
762
+
763
+ try {
764
+ const response = await fetch(url.toString(), {
765
+ method: 'PATCH',
766
+ body: JSON.stringify(payload),
767
+ headers: {
768
+ 'Content-Type': 'application/json',
769
+ },
770
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
771
+ }).then((data) => ResponseHandler<any>(data));
772
+ return response.data;
773
+ } catch (error) {
774
+ console.error(error);
775
+ return null;
776
+ }
777
+ };
778
+
779
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
780
+ public getIUTestingAccounts = async (): Promise<MarketplaceAppAuthorizationType | null> => {
781
+ const url = new URL(
782
+ `${this.config.baseUrl}/connected-accounts/list_workspace_connected_accounts/`,
783
+ );
784
+
785
+ IntegryAPI.addUrlSearchParams(url, {
786
+ app_key: this.config.appKey,
787
+ hash: this.config.hash,
788
+ user_id: this.config.userId,
789
+ });
790
+
791
+ try {
792
+ const response = await fetch(url.toString(), {
793
+ method: 'GET',
794
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
795
+ }).then((data) => ResponseHandler<MarketplaceAppAuthorizationType>(data));
796
+ return response.data;
797
+ } catch (error) {
798
+ console.error(error);
799
+ return null;
800
+ }
801
+ };
802
+
803
+ public uploadFile = async (
804
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
805
+ formData: any,
806
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
807
+ ): Promise<any | null> => {
808
+ const url = new URL(`${this.config.baseUrl}/api/files/`);
809
+
810
+ IntegryAPI.addUrlSearchParams(url, {
811
+ app_key: this.config.appKey,
812
+ hash: this.config.hash,
813
+ user_id: this.config.userId,
814
+ });
815
+
816
+ try {
817
+ const response = await fetch(url.toString(), {
818
+ method: 'POST',
819
+ body: formData,
820
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
821
+ }).then((data) => ResponseHandler<any>(data));
822
+ return response.data;
823
+ } catch (error) {
824
+ console.error(error);
825
+ return null;
826
+ }
827
+ };
828
+
829
+ public saveAppMedia = async (
830
+ bundleAppId: number,
831
+ payload: {
832
+ media: UploadFileObj[];
833
+ },
834
+ ): Promise<MarketplaceAppBundle | null> => {
835
+ const url = new URL(
836
+ `${this.config.baseUrl}/bundle_apps/${bundleAppId}/save_media/`,
837
+ );
838
+
839
+ IntegryAPI.addUrlSearchParams(url, {
840
+ app_key: this.config.appKey,
841
+ hash: this.config.hash,
842
+ user_id: this.config.userId,
843
+ });
844
+
845
+ try {
846
+ const response = await fetch(url.toString(), {
847
+ method: 'POST',
848
+ body: JSON.stringify(payload.media),
849
+ headers: {
850
+ 'Content-Type': 'application/json',
851
+ },
852
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
853
+ }).then((data) => ResponseHandler<MarketplaceAppBundle>(data));
854
+ return response.data;
855
+ } catch (error) {
856
+ console.error(error);
857
+ return null;
858
+ }
859
+ };
860
+
861
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
862
+ public getAppInfo = async (
863
+ appId: number | string,
864
+ ): Promise<BrandingApp | null> => {
865
+ const url = new URL(`${this.config.baseUrl}/api/v1/sdk/apps/${appId}/`);
866
+
867
+ IntegryAPI.addUrlSearchParams(url, {
868
+ app_key: this.config.appKey,
869
+ hash: this.config.hash,
870
+ user_id: this.config.userId,
871
+ });
872
+
873
+ try {
874
+ const response = await fetch(url.toString(), {
875
+ method: 'GET',
876
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
877
+ }).then((data) => ResponseHandler<BrandingApp>(data));
878
+ return response.data;
879
+ } catch (error) {
880
+ console.error(error);
881
+ return null;
882
+ }
883
+ };
884
+
885
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
886
+ public getAppFlows = async (
887
+ appId: number | string,
888
+ tags?: string[],
889
+ authId?: any,
890
+ ): Promise<AppFlowsResponse | null> => {
891
+ const url = new URL(
892
+ `${this.config.baseUrl}/api/v1/sdk/apps/${appId}/flows/`,
893
+ );
894
+ if (authId) {
895
+ IntegryAPI.addUrlSearchParams(url, {
896
+ app_key: this.config.appKey,
897
+ hash: this.config.hash,
898
+ user_id: this.config.userId,
899
+ tags: (tags || []).join(','),
900
+ show_draft: true,
901
+ authorization_id: authId,
902
+ page_size: 9999,
903
+ });
904
+ } else {
905
+ IntegryAPI.addUrlSearchParams(url, {
906
+ app_key: this.config.appKey,
907
+ hash: this.config.hash,
908
+ user_id: this.config.userId,
909
+ tags: (tags || []).join(','),
910
+ show_draft: true,
911
+ page_size: 9999,
912
+ });
913
+ }
914
+
915
+ try {
916
+ const response = await fetch(url.toString(), {
917
+ method: 'GET',
918
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
919
+ }).then((data) => ResponseHandler<AppFlowsResponse>(data));
920
+ return response.data;
921
+ } catch (error) {
922
+ console.error(error);
923
+ return null;
924
+ }
925
+ };
926
+
927
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
928
+ public getAdminAppFlows = async ({
929
+ appId,
930
+ bundleId,
931
+ }: {
932
+ appId: number | string;
933
+ bundleId: number;
934
+ }): Promise<AppFlowsResponse | null> => {
935
+ const url = new URL(
936
+ `${this.config.baseUrl}/api/v1/sdk/bundle/${bundleId}/apps/${appId}/templates/`,
937
+ );
938
+
939
+ IntegryAPI.addUrlSearchParams(url, {
940
+ app_key: this.config.appKey,
941
+ hash: this.config.hash,
942
+ user_id: this.config.userId,
943
+ });
944
+
945
+ try {
946
+ const response = await fetch(url.toString(), {
947
+ method: 'GET',
948
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
949
+ }).then((data) => ResponseHandler<AppFlowsResponse>(data));
950
+ return response.data;
951
+ } catch (error) {
952
+ console.error(error);
953
+ return null;
954
+ }
955
+ };
956
+
957
+ public executeFlow = async (
958
+ triggerPath: string,
959
+ body: IncomingWebhookPayload,
960
+ ): Promise<ExecuteFlowResponse | null> => {
961
+ const url = new URL(triggerPath);
962
+ IntegryAPI.addUrlSearchParams(url, {
963
+ app_key: this.config.appKey,
964
+ hash: this.config.hash,
965
+ user_id: this.config.userId,
966
+ });
967
+ try {
968
+ const response = await fetch(url.toString(), {
969
+ method: 'POST',
970
+ body: JSON.stringify(body),
971
+ headers: {
972
+ 'Content-Type': 'application/json',
973
+ },
974
+ }).then((data) => ResponseHandler<ExecuteFlowResponse>(data));
975
+ return response.data;
976
+ } catch (error) {
977
+ console.error(error);
978
+ return null;
979
+ }
980
+ };
981
+
982
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
983
+ public getApps = async ({
984
+ tags = <string[] | []>[],
985
+ nextURL = <string | null>null,
986
+ }): Promise<any | null> => {
987
+ // const url = (tags || []).length > 0 ? new URL(`${this.config.baseUrl}/api/v1/sdk/flow-apps/?tags=${tags.join(',')}`) : new URL(`${this.config.baseUrl}/api/v1/sdk/flow-apps/`);
988
+ const url = new URL(`${this.config.baseUrl}/api/v1/sdk/flow-apps/`);
989
+
990
+ if ((tags || []).length > 0) {
991
+ IntegryAPI.addUrlSearchParams(url, {
992
+ app_key: this.config.appKey,
993
+ hash: this.config.hash,
994
+ user_id: this.config.userId,
995
+ tags: tags.join(','),
996
+ show_draft: true,
997
+ });
998
+ } else {
999
+ IntegryAPI.addUrlSearchParams(url, {
1000
+ app_key: this.config.appKey,
1001
+ hash: this.config.hash,
1002
+ user_id: this.config.userId,
1003
+ tags: tags.join(','),
1004
+ show_draft: true,
1005
+ });
1006
+ }
1007
+
1008
+ if (nextURL === null) {
1009
+ IntegryAPI.addUrlSearchParams(url, {
1010
+ page_size: 100,
1011
+ });
1012
+ }
1013
+
1014
+ try {
1015
+ const response = await fetch(nextURL || url.toString(), {
1016
+ method: 'GET',
1017
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1018
+ }).then((data) => ResponseHandler<BrandingApp>(data));
1019
+ return response.data;
1020
+ } catch (error) {
1021
+ console.error(error);
1022
+ return null;
1023
+ }
1024
+ };
1025
+
1026
+ public getMarketplaceAppsV2 = async ({
1027
+ cursor = <string | null>null,
1028
+ search = '',
1029
+ }): Promise<any | null> => {
1030
+ const url = new URL(`${this.config.baseAPIUrl}/apps/list/`);
1031
+
1032
+ IntegryAPI.addUrlSearchParams(url, {
1033
+ app_key: this.config.appKey,
1034
+ hash: this.config.hash,
1035
+ user_id: this.config.userId,
1036
+ page_size: 30,
1037
+ });
1038
+
1039
+ if (search !== '' && search !== null) {
1040
+ IntegryAPI.addUrlSearchParams(url, {
1041
+ search,
1042
+ });
1043
+ }
1044
+
1045
+ const body: Record<string, string> = {};
1046
+ if (cursor !== null) {
1047
+ body._cursor = cursor;
1048
+ }
1049
+
1050
+ try {
1051
+ const response = await fetch(url.toString(), {
1052
+ method: 'POST',
1053
+ body: JSON.stringify(body),
1054
+ headers: {
1055
+ 'Content-Type': 'application/json',
1056
+ },
1057
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1058
+ }).then((data) => ResponseHandler<MarketplaceApp>(data));
1059
+ return response.data;
1060
+ } catch (error) {
1061
+ console.error(error);
1062
+ return null;
1063
+ }
1064
+ };
1065
+
1066
+ public getAdminApps = async ({
1067
+ nextURL = <string | null>null,
1068
+ bundleId = <string | number | null>0,
1069
+ }): Promise<any | null> => {
1070
+ const url = new URL(
1071
+ `${this.config.baseUrl}/api/v1/sdk/bundle/${bundleId}/apps/`,
1072
+ );
1073
+
1074
+ IntegryAPI.addUrlSearchParams(url, {
1075
+ app_key: this.config.appKey,
1076
+ hash: this.config.hash,
1077
+ user_id: this.config.userId,
1078
+ });
1079
+
1080
+ try {
1081
+ const response = await fetch(nextURL || url.toString(), {
1082
+ method: 'GET',
1083
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1084
+ }).then((data) => ResponseHandler<BrandingApp>(data));
1085
+ return response.data;
1086
+ } catch (error) {
1087
+ console.error(error);
1088
+ return null;
1089
+ }
1090
+ };
1091
+
1092
+ public callDynamicDataEndpointWithTags = async <T>(
1093
+ url: URL,
1094
+ endpointData: Record<string, string> = {},
1095
+ body: string | number | NestedObject,
1096
+ ): Promise<T | null> => {
1097
+ IntegryAPI.addUrlSearchParams(url, {
1098
+ app_key: this.config.appKey,
1099
+ hash: this.config.hash,
1100
+ user_id: this.config.userId,
1101
+ ...endpointData,
1102
+ });
1103
+
1104
+ let mergedBody = { query_string_data: body };
1105
+ if (typeof body === 'object') {
1106
+ mergedBody = { ...body, query_string_data: body };
1107
+ }
1108
+
1109
+ try {
1110
+ const response = await fetch(url.toString(), {
1111
+ method: 'POST',
1112
+ body: JSON.stringify(mergedBody),
1113
+ headers: {
1114
+ 'Content-Type': 'application/json',
1115
+ },
1116
+ }).then((data) => ResponseHandler<T>(data));
1117
+ return response.data;
1118
+ } catch (error) {
1119
+ console.error(error);
1120
+ return null;
1121
+ }
1122
+ };
1123
+
1124
+ public callSourceFlowIntegrationInvocationUrl = async <T>(
1125
+ url: URL,
1126
+ endpointData: Record<string, string> = {},
1127
+ body: string | number | NestedObject = {},
1128
+ ): Promise<T | null> => {
1129
+ IntegryAPI.addUrlSearchParams(url, {
1130
+ app_key: this.config.appKey,
1131
+ hash: this.config.hash,
1132
+ user_id: this.config.userId,
1133
+ ...endpointData,
1134
+ });
1135
+
1136
+ try {
1137
+ const response = await fetch(url.toString(), {
1138
+ method: 'POST',
1139
+ body: JSON.stringify(body),
1140
+ headers: {
1141
+ 'Content-Type': 'application/json',
1142
+ },
1143
+ }).then((data) => ResponseHandler<T>(data));
1144
+ return response.data;
1145
+ } catch (error) {
1146
+ console.error(error);
1147
+ return null;
1148
+ }
1149
+ };
1150
+
1151
+ public getUserVariables = async (): Promise<any | null> => {
1152
+ const url = new URL(`${this.config.baseUrl}/api/v1/app-user-variables/`);
1153
+
1154
+ IntegryAPI.addUrlSearchParams(url, {
1155
+ app_key: this.config.appKey,
1156
+ hash: this.config.hash,
1157
+ user_id: this.config.userId,
1158
+ });
1159
+
1160
+ try {
1161
+ const response = await fetch(url.toString(), { method: 'GET' }).then(
1162
+ ResponseHandler,
1163
+ );
1164
+ return response.data;
1165
+ } catch (error) {
1166
+ console.error(error);
1167
+ return null;
1168
+ }
1169
+ };
1170
+
1171
+ public getFunctionDetails = async (
1172
+ functionName: string,
1173
+ variables: Record<string, unknown> = {},
1174
+ ): Promise<any | null> => {
1175
+ const url = new URL(
1176
+ `${this.config.baseAPIUrl}/functions/${functionName}/get/`,
1177
+ );
1178
+
1179
+ IntegryAPI.addUrlSearchParams(url, {
1180
+ app_key: this.config.appKey,
1181
+ hash: this.config.hash,
1182
+ user_id: this.config.userId,
1183
+ include: 'meta',
1184
+ });
1185
+
1186
+ try {
1187
+ const response = await fetch(url.toString(), {
1188
+ method: 'POST',
1189
+ body: JSON.stringify({
1190
+ _variables: variables,
1191
+ }),
1192
+ headers: {
1193
+ 'Content-Type': 'application/json',
1194
+ },
1195
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1196
+ }).then((data) => ResponseHandler<BrandingApp>(data));
1197
+ return response.data;
1198
+ } catch (error) {
1199
+ console.error(error);
1200
+ return null;
1201
+ }
1202
+ };
1203
+
1204
+ public getFunctionSignature = async (
1205
+ functionName: string,
1206
+ ): Promise<any | null> => {
1207
+ const url = new URL(
1208
+ `${this.config.baseAPIUrl}/functions/${functionName}/get/`,
1209
+ );
1210
+
1211
+ IntegryAPI.addUrlSearchParams(url, {
1212
+ app_key: this.config.appKey,
1213
+ hash: this.config.hash,
1214
+ user_id: this.config.userId,
1215
+ });
1216
+
1217
+ try {
1218
+ const response = await fetch(url.toString(), {
1219
+ method: 'GET',
1220
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1221
+ }).then((data) => ResponseHandler<BrandingApp>(data));
1222
+ return response.data;
1223
+ } catch (error) {
1224
+ console.error(error);
1225
+ return null;
1226
+ }
1227
+ };
1228
+
1229
+ public getConnectedAccounts = async (appName: string): Promise<any> => {
1230
+ const url = new URL(`${this.config.baseUrl}/apps/${appName}/get/`);
1231
+
1232
+ IntegryAPI.addUrlSearchParams(url, {
1233
+ app_key: this.config.appKey,
1234
+ hash: this.config.hash,
1235
+ user_id: this.config.userId,
1236
+ });
1237
+
1238
+ try {
1239
+ const response = await fetch(url.toString(), {
1240
+ method: 'POST',
1241
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1242
+ }).then((data) => ResponseHandler<string[]>(data));
1243
+ return response.data;
1244
+ } catch (error) {
1245
+ console.error(error);
1246
+ return null;
1247
+ }
1248
+ };
1249
+
1250
+ public getApp = async (appName: string): Promise<any> => {
1251
+ const url = new URL(`${this.config.baseUrl}/apps/${appName}/get/`);
1252
+
1253
+ IntegryAPI.addUrlSearchParams(url, {
1254
+ app_key: this.config.appKey,
1255
+ hash: this.config.hash,
1256
+ user_id: this.config.userId,
1257
+ });
1258
+
1259
+ try {
1260
+ const response = await fetch(url.toString(), {
1261
+ method: 'POST',
1262
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1263
+ }).then((data) => ResponseHandler<string[]>(data));
1264
+ return response.data;
1265
+ } catch (error) {
1266
+ console.error(error);
1267
+ return null;
1268
+ }
1269
+ };
1270
+
1271
+ public invokeFunction = async (
1272
+ functionDetails: any,
1273
+ connectedAccountId: string,
1274
+ ): Promise<any | null> => {
1275
+ const url = new URL(functionDetails.url);
1276
+ IntegryAPI.addUrlSearchParams(url, {
1277
+ app_key: this.config.appKey,
1278
+ hash: this.config.hash,
1279
+ user_id: this.config.userId,
1280
+ });
1281
+
1282
+ if (connectedAccountId) {
1283
+ IntegryAPI.addUrlSearchParams(url, {
1284
+ connected_account_id: connectedAccountId,
1285
+ });
1286
+ }
1287
+
1288
+ try {
1289
+ const response = await fetch(url.toString(), {
1290
+ method: functionDetails.method,
1291
+ headers: functionDetails.headers,
1292
+ body: JSON.stringify({
1293
+ ...functionDetails.args,
1294
+ ...(functionDetails.vars && { _variables: functionDetails.vars }),
1295
+ }),
1296
+ });
1297
+
1298
+ // Now directly await the response.json() to parse the JSON
1299
+ const results = await response.json(); // This will return the parsed JSON
1300
+ return results; // Return the results to the caller
1301
+ } catch (error) {
1302
+ return new Error('Error while invoking function');
1303
+ }
1304
+ };
1305
+
1306
+ public getAuthConfig = (): string | null => {
1307
+ let authConfig = '';
1308
+ authConfig = `app_key=${this.config.appKey}&hash=${
1309
+ this.config.hash
1310
+ }&user_id=${encodeURIComponent(this.config.userId)}`;
1311
+ return authConfig;
1312
+ };
1313
+ }
1314
+
1315
+ export { IntegryAPI };