@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
package/src/index.ts DELETED
@@ -1,2244 +0,0 @@
1
- import { html, render } from 'htm/preact';
2
- import { Provider } from 'unistore/preact';
3
-
4
- import { IntegryAPI } from '@/modules/api';
5
- import {
6
- InitConfig,
7
- ConfigWithObject,
8
- ConfigWithUrlParams,
9
- APIConfig,
10
- PreviewPayload,
11
- MarketplaceConfig,
12
- MultipurposeFieldType,
13
- FunctionFieldType,
14
- ConnectedAccount,
15
- MarketplaceApp,
16
- } from '@/interfaces';
17
-
18
- import { HMAC } from '@/extensions/HMAC';
19
-
20
- import { EventEmitter } from '@/modules/event-emitter';
21
- import AppContext from '@/contexts/AppContext';
22
-
23
- import {
24
- IntegrySDKEvents,
25
- MarketplaceRenderModes,
26
- TemplateFormRenderModes,
27
- TemplateListingRenderModes,
28
- ViewStyles,
29
- RenderModes,
30
- Layouts,
31
- SetupIntegrationOptions,
32
- RenderFlowStepOptions,
33
- RenderMappingMenuOptions,
34
- ShowFunctionOptions,
35
- } from '@/types';
36
-
37
- import { createSDKStore, initialState } from '@/store';
38
- import isBrowser from '@/utils/isBrowser';
39
- import { getUrlParam } from '@/utils/getUrlParam';
40
-
41
- import SDKContainer from '@/features/containers/SDKContainer';
42
- import SDKFailedContainer from '@/features/containers/SDKFailedContainer';
43
- import AuthSetupContainer from '@/features/containers/AuthSetupContainer';
44
- import FlowSetupContainer from '@/features/containers/FlowSetupContainer';
45
- import MarketplaceContainer from '@/features/containers/MarketplaceContainer';
46
- import AppFlowContainer from '@/features/containers/AppFlowContainer';
47
- import MarketplaceAppsContainer from '@/features/containers/MarketplaceAppsContainer';
48
- import ActionForm from '@/features/common/ActionForm';
49
- import { TagsMenu } from '@/components/TagsMenu';
50
-
51
- import FunctionForm from '@/features/common/FunctionForm';
52
- import { openPopupWindow } from '@/utils/popup';
53
- import { Modal } from '@/components/Modal';
54
- import {
55
- JSONToActivityOutputData,
56
- arrayToNestedJSONWithFirstValue,
57
- } from '@/utils/ActivityOutputUtils';
58
- import { ListBox } from '@/components/MultipurposeField/Dropdown';
59
- import { FunctionField } from '@/components/form';
60
- import { MultipurposeField } from './components/MultipurposeField';
61
- import SDKDebugContainer from './features/containers/SDKDebugContainer';
62
-
63
- const Helpers = { getAuthHash: HMAC };
64
-
65
- // eslint-disable-next-line no-underscore-dangle
66
- const __buildVersion__ = '';
67
-
68
- /**
69
- * Integry JS SDK
70
- */
71
- export class IntegryJS {
72
- static SDK_VERSION = __buildVersion__;
73
-
74
- private config: ConfigWithObject & ConfigWithUrlParams;
75
-
76
- private apiHandler: IntegryAPI;
77
-
78
- private initConfig: InitConfig;
79
-
80
- eventEmitter = new EventEmitter<IntegrySDKEvents>();
81
-
82
- // allow customers to use template tagging
83
- static html = html;
84
-
85
- static RenderModes: typeof RenderModes = RenderModes;
86
-
87
- static TemplateFormRenderModes: typeof TemplateFormRenderModes =
88
- TemplateFormRenderModes;
89
-
90
- static Layouts: typeof Layouts = Layouts;
91
-
92
- static ViewStyles: typeof ViewStyles = ViewStyles;
93
-
94
- static MarketplaceRenderModes: typeof MarketplaceRenderModes =
95
- MarketplaceRenderModes;
96
-
97
- static Helpers: {
98
- getAuthHash: (key: string, message: string) => Promise<string>;
99
- };
100
-
101
- private authModalId = '';
102
-
103
- private forceRerender = false;
104
-
105
- constructor(config: ConfigWithObject | ConfigWithUrlParams) {
106
- let integryAPIParams: APIConfig;
107
-
108
- const baseUrl = config.baseUrl || 'https://app.integry.io';
109
-
110
- const baseAPIUrl = 'https://api.integry.io';
111
-
112
- const configUpdated = config;
113
-
114
- // perform the overrides according to new configuration syntax
115
- if (configUpdated.user) {
116
- const { userId, apiKey, ...extras } = configUpdated.user;
117
- if (!('userId' in configUpdated)) {
118
- (configUpdated as any).userId = '';
119
- }
120
- if ('userId' in configUpdated) {
121
- configUpdated.userId = userId.toString();
122
- }
123
- if (!configUpdated.xIntegryConfig) {
124
- configUpdated.xIntegryConfig = {};
125
- }
126
-
127
- if (!configUpdated.xIntegryConfig.appAuth) {
128
- configUpdated.xIntegryConfig.appAuth = {};
129
- }
130
-
131
- if (!configUpdated.xIntegryConfig.appAuth.extras) {
132
- configUpdated.xIntegryConfig.appAuth.extras = {};
133
- }
134
-
135
- configUpdated.xIntegryConfig.appAuth.apiKey = (apiKey || '').toString();
136
- configUpdated.xIntegryConfig.appAuth.extras = extras as Record<
137
- string,
138
- string | number
139
- >;
140
- }
141
-
142
- const apiConfig = {
143
- oauthVerifyPath: 'auth/verify',
144
- endpointsUrl: 'https://integry-app.appspot.com',
145
- baseUrl,
146
- baseUrlv2: `${baseUrl}/v2`,
147
- baseAPIUrl: `${baseAPIUrl}`,
148
- apiKey: configUpdated.xIntegryConfig?.appAuth?.apiKey,
149
- authId: configUpdated.xIntegryConfig?.appAuth?.authId,
150
- extras: configUpdated.xIntegryConfig?.appAuth?.extras,
151
- };
152
-
153
- const userConfig = configUpdated.options || configUpdated.userConfig || {};
154
- if (configUpdated.options && configUpdated.payloads) {
155
- configUpdated.options.objects = config.payloads;
156
- }
157
-
158
- if ('appKey' in configUpdated) {
159
- integryAPIParams = {
160
- ...configUpdated,
161
- ...apiConfig,
162
- appKey: configUpdated.appKey,
163
- hash: configUpdated.hash,
164
- userId: configUpdated.userId,
165
- };
166
- this.config = {
167
- ...configUpdated,
168
- ...apiConfig,
169
- appKey: configUpdated.appKey,
170
- hash: configUpdated.hash,
171
- userId: configUpdated.userId,
172
- deploymentId: configUpdated.deploymentId,
173
- userConfig: configUpdated.deploymentId
174
- ? {
175
- ...userConfig,
176
- tags: userConfig?.tags
177
- ? [...userConfig?.tags, `${configUpdated.deploymentId}`]
178
- : [`${configUpdated.deploymentId}`],
179
- }
180
- : userConfig,
181
- };
182
- } else {
183
- const urlparams = this.getAuthParamsFromUrl() || {};
184
- integryAPIParams = {
185
- ...apiConfig,
186
- ...urlparams,
187
- };
188
- this.config = {
189
- ...apiConfig,
190
- ...urlparams,
191
- userConfig: configUpdated.userConfig,
192
- };
193
- }
194
- this.authModalId = this.getRandomFlowId(6);
195
- this.apiHandler = new IntegryAPI(integryAPIParams);
196
- this.verifyAuthConfig()
197
- .then((response) => {
198
- if (!response?.config_verified) {
199
- console.error(
200
- 'IntegrySDK: Auth config verification failed, are your auth parameters correct?',
201
- );
202
- } else {
203
- this.eventEmitter.emit('ready', {
204
- isReady: true,
205
- });
206
- }
207
- })
208
- .catch((err) => console.error(err));
209
- this.initConfig = {
210
- containerId: '',
211
- renderMode: TemplateFormRenderModes.INLINE,
212
- };
213
- }
214
-
215
- /**
216
- * Handler function when SDK has failed to load.
217
- */
218
- private SDKFailedHandler = (config: any, containerId: string) => {
219
- const userConfig = config.options || config.userConfig || {};
220
- const targetEl = document.getElementById(containerId);
221
- if (targetEl) {
222
- render(
223
- html`
224
- <${SDKFailedContainer}
225
- message="SDK failed to load"
226
- debug=${userConfig.debug}
227
- config=${userConfig.debug ? config : null}
228
- >
229
- <//>
230
- `,
231
- targetEl,
232
- );
233
- }
234
- throw new Error('IntegrySDK: SDK failed to load');
235
- };
236
-
237
- /**
238
- *
239
- * @param length Length of string to randomly generate
240
- * @returns {string} Returns a random string
241
- */
242
- private getRandomFlowId = (length: number): string => {
243
- const result = [];
244
- const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
245
- const charactersLength = characters.length;
246
- for (let i = 0; i < length; i += 1) {
247
- result.push(
248
- characters.charAt(Math.floor(Math.random() * charactersLength)),
249
- );
250
- }
251
- return `x-integry-modal-${result.join('')}`;
252
- };
253
-
254
- private getAuthParamsFromUrl = (): ConfigWithObject => {
255
- const urlParams =
256
- isBrowser() && new URLSearchParams(window.location.search);
257
- if (urlParams) {
258
- const userId = urlParams.get('user_id');
259
- const appKey = urlParams.get('app_key');
260
- const hash = urlParams.get('hash');
261
- const deploymentId = urlParams.get('deployment_id');
262
- if (!userId || !appKey || !hash || !deploymentId) {
263
- throw new Error(
264
- `The following auth variables are undefined: ${
265
- !userId ? 'userId' : ''
266
- } ${!appKey ? 'appKey' : ''} ${!hash ? 'hash' : ''} ${
267
- !deploymentId ? 'deploymentId' : ''
268
- }`,
269
- );
270
- }
271
- return {
272
- userId,
273
- appKey,
274
- hash,
275
- deploymentId,
276
- };
277
- }
278
- return {
279
- userId: '',
280
- appKey: '',
281
- hash: '',
282
- deploymentId: '',
283
- };
284
- };
285
-
286
- /**
287
- * Prints version number of this SDK version
288
- */
289
- public printVersion = (): void => {
290
- console.info(`@integry/sdk@${IntegryJS.SDK_VERSION}`);
291
- };
292
-
293
- /**
294
- *
295
- * @param renderMode
296
- * @param templateContainerId
297
- * @returns {HTMLElement | null}
298
- */
299
- private setupFlowFormDestination = (
300
- renderMode: TemplateFormRenderModes,
301
- templateContainerId?: string,
302
- ): HTMLElement | null => {
303
- let el: HTMLElement | null = null;
304
-
305
- if (templateContainerId) {
306
- if (
307
- renderMode === TemplateFormRenderModes.MODAL ||
308
- renderMode === TemplateFormRenderModes.INLINE
309
- ) {
310
- throw new Error(
311
- 'The `templateContainerId` property is unsupported when render mode is set to "MODAL" or "INLINE"',
312
- );
313
- }
314
- el = document.getElementById(templateContainerId);
315
- if (!el) {
316
- console.warn(
317
- `The template form render target with id ${templateContainerId} was not found`,
318
- );
319
- // throw new Error('The template form render target was not found');
320
- }
321
- }
322
-
323
- switch (renderMode) {
324
- case TemplateFormRenderModes.MODAL:
325
- el = document.createElement('div');
326
- el.id = this.getRandomFlowId(8);
327
- document.body.appendChild(el);
328
- return el;
329
- case TemplateFormRenderModes.INLINE:
330
- return null;
331
- case TemplateFormRenderModes.DETACHED:
332
- return el;
333
- case TemplateFormRenderModes.CUSTOM:
334
- return el;
335
- default:
336
- throw new Error(
337
- `Unsupported renderMode ${renderMode} configuration, please provide one of ${JSON.stringify(
338
- Object.keys(TemplateFormRenderModes),
339
- )}`,
340
- );
341
- }
342
- };
343
-
344
- /**
345
- * Render the template form we ship
346
- * @param data
347
- */
348
- public renderFlowSetupForm = (data: {
349
- flowId?: string;
350
- integrationId?: number;
351
- flowContainerId: string;
352
- versionId?: number;
353
- viewStyle?: string;
354
- }): void => {
355
- const { flowId, flowContainerId, versionId, viewStyle } = data;
356
- const targetEl = document.getElementById(flowContainerId);
357
- if (!targetEl) {
358
- console.warn(
359
- `Integry template form render target with id ${flowContainerId} was not found`,
360
- );
361
- return;
362
- }
363
- let parsedFlowId = Number(flowId);
364
- let parsedIntegrationId = this.config.integrationId || data.integrationId;
365
-
366
- if (!parsedIntegrationId) {
367
- parsedIntegrationId = Number(getUrlParam('integrationId'));
368
- }
369
-
370
- if (!parsedFlowId) {
371
- parsedFlowId = Number(getUrlParam('flowId'));
372
- }
373
-
374
- const store = createSDKStore();
375
-
376
- store.setState({
377
- integrationIdToEdit: parsedIntegrationId,
378
- userConfig: this.config.userConfig,
379
- genericData: {
380
- ...initialState.genericData,
381
- implicitAuthEnabled: !!this.config.xIntegryConfig?.appAuth?.apiKey,
382
- deploymentId: Number(this.config.deploymentId),
383
- isAnonymous: !!this.config.xIntegryConfig?.isAnonymous,
384
- viewStyle: viewStyle || ViewStyles.COMFORTABLE,
385
- testMultipurpose: true,
386
- customFlowSetupRender: true,
387
- },
388
- });
389
-
390
- render(
391
- html`
392
- <${AppContext.Provider}
393
- value=${{
394
- apiHandler: this.apiHandler,
395
- eventEmitter: this.eventEmitter,
396
- isPreviewMode: false,
397
- }}
398
- >
399
- <${Provider} store=${store} key=${this.getRandomFlowId(10)}>
400
- <${SDKContainer}
401
- deploymentId=${this.config.deploymentId}
402
- userConfig=${this.config.userConfig}
403
- layout=${TemplateListingRenderModes.LIST}
404
- renderMode=${this.initConfig.renderMode}
405
- renderFlowsMode=${this.initConfig.renderFlowsMode ||
406
- TemplateFormRenderModes.INLINE}
407
- flowId=${parsedFlowId}
408
- integrationId=${parsedIntegrationId}
409
- >
410
- <//>
411
- <//>
412
- <//>
413
- `,
414
- targetEl,
415
- );
416
- };
417
-
418
- public setupIntegration = (
419
- flowId: string,
420
- options: SetupIntegrationOptions = {
421
- containerId: 'integry-marketplace',
422
- renderMode: RenderModes.MODAL,
423
- layout: Layouts.WIDE,
424
- params: {},
425
- },
426
- ): void => {
427
- const targetEl = document.getElementById(options.containerId || '');
428
- if (!targetEl) {
429
- console.warn(
430
- `Integry template form render target with id ${options.containerId} was not found`,
431
- );
432
- return;
433
- }
434
- let parsedFlowId = Number(flowId);
435
- let parsedIntegrationId = options.integrationId || null;
436
-
437
- if (!parsedIntegrationId) {
438
- parsedIntegrationId = Number(getUrlParam('integrationId'));
439
- }
440
-
441
- if (!parsedFlowId) {
442
- parsedFlowId = Number(getUrlParam('flowId'));
443
- }
444
-
445
- const store = createSDKStore();
446
-
447
- store.setState({
448
- integrationIdToEdit: parsedIntegrationId,
449
- userConfig: this.config.userConfig,
450
- genericData: {
451
- ...initialState.genericData,
452
- implicitAuthEnabled: !!this.config.xIntegryConfig?.appAuth?.apiKey,
453
- deploymentId: Number(this.config.deploymentId),
454
- isAnonymous: !!this.config.xIntegryConfig?.isAnonymous,
455
- viewStyle: options.layout || ViewStyles.COMFORTABLE,
456
- testMultipurpose: true,
457
- customFlowSetupRender: true,
458
- },
459
- });
460
-
461
- render(
462
- html`
463
- <${AppContext.Provider}
464
- value=${{
465
- apiHandler: this.apiHandler,
466
- eventEmitter: this.eventEmitter,
467
- isPreviewMode: false,
468
- }}
469
- >
470
- <${Provider} store=${store} key=${this.getRandomFlowId(10)}>
471
- <${SDKContainer}
472
- deploymentId=${this.config.deploymentId}
473
- userConfig=${this.config.userConfig}
474
- layout=${TemplateListingRenderModes.LIST}
475
- renderMode=${options.renderMode}
476
- renderFlowsMode=${options.renderMode}
477
- flowId=${parsedFlowId}
478
- integrationId="${parsedIntegrationId}"
479
- params=${options.params}
480
- >
481
- <//>
482
- <//>
483
- <//>
484
- `,
485
- targetEl,
486
- );
487
- };
488
-
489
- public showFunctionUI = (
490
- functionName: string,
491
- functionArguments: {
492
- [key: string]: any;
493
- } = {},
494
- connectedAccountId?: string,
495
- ): Promise<Record<any, any>> => {
496
- const store = createSDKStore();
497
-
498
- return new Promise((resolve, reject) => {
499
- this.apiHandler
500
- .getFunctionDetails(functionName)
501
- .then((response: any) => {
502
- if (!response) {
503
- return reject(new Error('Function not found.'));
504
- }
505
- if (response.meta.app.connected_accounts.length === 0) {
506
- return reject(new Error('No connected account found.'));
507
- }
508
- if (
509
- connectedAccountId &&
510
- !response.meta.app.connected_accounts.find(
511
- (account: any) => account.id === connectedAccountId,
512
- )
513
- ) {
514
- return reject(new Error('Connected account not found.'));
515
- }
516
-
517
- let targetEl = document.getElementById(this.initConfig.containerId);
518
- if (!targetEl) {
519
- targetEl = document.createElement('div');
520
- targetEl.id = this.authModalId;
521
- document.body.appendChild(targetEl);
522
- }
523
-
524
- store.setState({
525
- userConfig: this.config.userConfig,
526
- genericData: {
527
- ...initialState.genericData,
528
- implicitAuthEnabled:
529
- !!this.config.xIntegryConfig?.appAuth?.apiKey,
530
- deploymentId: Number(this.config.deploymentId),
531
- isAnonymous: !!this.config.xIntegryConfig?.isAnonymous,
532
- },
533
- });
534
-
535
- render(
536
- html`
537
- <div id="functionFormWrap">
538
- <${Modal}
539
- isOpen=${true}
540
- onClose=${() => {
541
- const authIdElement = document.getElementById(
542
- this.authModalId,
543
- );
544
- if (authIdElement) {
545
- authIdElement.remove();
546
- this.eventEmitter.emit('modal-closed', {});
547
- }
548
- }}
549
- className="flowAppsModal"
550
- isCompact=${false}
551
- >
552
- ${html`<${AppContext.Provider}
553
- value=${{
554
- apiHandler: this.apiHandler,
555
- eventEmitter: this.eventEmitter,
556
- isPreviewMode: false,
557
- }}
558
- >
559
- <${Provider} store=${store}>
560
- <${FunctionForm}
561
- functionName=${functionName}
562
- connectedAccountId=${connectedAccountId}
563
- functionArguments=${functionArguments}
564
- apiHandler=${this.apiHandler}
565
- onClose=${(functionUIResponse: any) => {
566
- const authIdElement = document.getElementById(
567
- this.authModalId,
568
- );
569
- if (authIdElement) {
570
- authIdElement.remove();
571
- }
572
- resolve(functionUIResponse);
573
- }}
574
- >
575
- <//>
576
- </${AppContext.Provider}>`}
577
- <//>
578
- </div>
579
- `,
580
- targetEl,
581
- );
582
-
583
- // Ensure the function has a return value
584
- return null;
585
- })
586
- .catch((err) => {
587
- reject(err);
588
- });
589
- });
590
- };
591
-
592
- public showFunction = (
593
- functionName: string,
594
- options: ShowFunctionOptions = {
595
- params: {},
596
- payload: {},
597
- connectedAccountId: '',
598
- autoMapPayload: false,
599
- version: null,
600
- allow_workspace_connected_accounts: false,
601
- },
602
- ): Promise<Record<any, any>> => {
603
- const store = createSDKStore();
604
-
605
- return new Promise((resolve, reject) => {
606
- this.apiHandler
607
- .getFunctionDetails(
608
- functionName,
609
- options.autoMapPayload ? options.payload : {},
610
- options.version,
611
- options.allow_workspace_connected_accounts,
612
- )
613
- .then((response: any) => {
614
- if (!response) {
615
- return reject(new Error('Function not found.'));
616
- }
617
- if (response.meta.app.connected_accounts.length === 0) {
618
- return reject(new Error('No connected account found.'));
619
- }
620
- if (
621
- options.connectedAccountId &&
622
- !response.meta.app.connected_accounts.find(
623
- (account: any) =>
624
- Number(account.id) === Number(options.connectedAccountId),
625
- )
626
- ) {
627
- return reject(new Error('Connected account not found.'));
628
- }
629
-
630
- let targetEl = document.getElementById(this.initConfig.containerId);
631
- if (!targetEl) {
632
- targetEl = document.createElement('div');
633
- targetEl.id = this.authModalId;
634
- document.body.appendChild(targetEl);
635
- }
636
-
637
- store.setState({
638
- userConfig: this.config.userConfig,
639
- genericData: {
640
- ...initialState.genericData,
641
- implicitAuthEnabled:
642
- !!this.config.xIntegryConfig?.appAuth?.apiKey,
643
- deploymentId: Number(this.config.deploymentId),
644
- isAnonymous: !!this.config.xIntegryConfig?.isAnonymous,
645
- },
646
- });
647
-
648
- render(
649
- html`
650
- <div id="functionFormWrap">
651
- <${Modal}
652
- isOpen=${true}
653
- onClose=${() => {
654
- const authIdElement = document.getElementById(
655
- this.authModalId,
656
- );
657
- if (authIdElement) {
658
- authIdElement.remove();
659
- this.eventEmitter.emit('modal-closed', {});
660
- }
661
- }}
662
- className="flowAppsModal"
663
- isCompact=${false}
664
- >
665
- ${html`<${AppContext.Provider}
666
- value=${{
667
- apiHandler: this.apiHandler,
668
- eventEmitter: this.eventEmitter,
669
- isPreviewMode: false,
670
- }}
671
- >
672
- <${Provider} store=${store}>
673
- <${FunctionForm}
674
- functionName=${functionName}
675
- connectedAccountId=${options.connectedAccountId}
676
- functionArguments=${options.params}
677
- variables=${options.payload}
678
- autoMapVars=${options.autoMapPayload}
679
- version=${options.version}
680
- allowWorkspaceConnectedAccounts=${
681
- options.allow_workspace_connected_accounts
682
- }
683
- apiHandler=${this.apiHandler}
684
- onClose=${(functionUIResponse: any) => {
685
- const authIdElement = document.getElementById(
686
- this.authModalId,
687
- );
688
- if (authIdElement) {
689
- authIdElement.remove();
690
- }
691
- resolve(functionUIResponse);
692
- }}
693
- >
694
- <//>
695
- </${AppContext.Provider}>`}
696
- <//>
697
- </div>
698
- `,
699
- targetEl,
700
- );
701
-
702
- // Ensure the function has a return value
703
- return null;
704
- })
705
- .catch((err) => {
706
- reject(err);
707
- });
708
- });
709
- };
710
-
711
- public invokeFunction = (
712
- functionName: string,
713
- params: {
714
- [key: string]: any;
715
- },
716
- connectedAccountId: string,
717
- ): Promise<Record<any, any>> =>
718
- new Promise((resolve, reject) => {
719
- // Prepare the request body by encoding `args` to JSON
720
- const functionDetails = {
721
- method: this.getMethod(),
722
- url: `${this.getBaseAPIUrl()}/functions/${functionName}/call/`,
723
- headers: this.getHeaders(),
724
- args: params,
725
- };
726
- this.apiHandler
727
- .invokeFunction(functionDetails, connectedAccountId)
728
- .then((response: any) => {
729
- // Check if the response has an error or is not valid (you can customize this check based on the API response structure)
730
- resolve(response);
731
- })
732
- .catch((error: any) => {
733
- reject(
734
- new Error(
735
- `Failed to invoke function: ${error.message || 'Unknown error'}`,
736
- ),
737
- );
738
- });
739
- });
740
-
741
- public callFunction = (
742
- functionName: string,
743
- params: {
744
- [key: string]: any;
745
- },
746
- vars: {
747
- [key: string]: any;
748
- } = {},
749
- connectedAccountId: string,
750
- version: string | null = null,
751
- allow_workspace_connected_accounts = false,
752
- ): Promise<Record<any, any>> =>
753
- new Promise((resolve, reject) => {
754
- // Prepare the request body by encoding `args` to JSON
755
- const headers: Record<string, string> = {
756
- ...this.getHeaders(),
757
- };
758
- if (version) {
759
- headers.Version = version;
760
- }
761
- let url = `${this.getBaseAPIUrl()}/functions/${functionName}/call/`;
762
- if (allow_workspace_connected_accounts) {
763
- url += '?allow_workspace_connected_accounts=true';
764
- }
765
- const functionDetails = {
766
- method: this.getMethod(),
767
- url,
768
- headers,
769
- args: params,
770
- vars,
771
- };
772
- this.apiHandler
773
- .invokeFunction(functionDetails, connectedAccountId)
774
- .then((response: any) => {
775
- // Check if the response has an error or is not valid (you can customize this check based on the API response structure)
776
- resolve(response);
777
- })
778
- .catch((error: any) => {
779
- reject(
780
- new Error(
781
- `Failed to call function: ${error.message || 'Unknown error'}`,
782
- ),
783
- );
784
- });
785
- });
786
-
787
- public connectApp = (appName: string): Promise<string> =>
788
- new Promise((resolve, reject) => {
789
- // Open the child window
790
- this.apiHandler.getApp(appName).then((app) => {
791
- if (!app || !app.login_url || app.login_url === '') {
792
- reject(
793
- new Error(
794
- `App not found or doesn't require an authentication: ${appName}`,
795
- ),
796
- );
797
- return;
798
- }
799
- const authWindow = openPopupWindow(
800
- app.login_url,
801
- 'Auth Window',
802
- window,
803
- 800,
804
- 600,
805
- );
806
-
807
- // Function to handle the auth response from the child window
808
- const onAuthResponseReceived = (event: MessageEvent) => {
809
- // Verify the message origin (for security)
810
- if (event.origin !== 'https://app.integry.io') return;
811
-
812
- // Check if the message contains the connectedAccountId
813
- if (
814
- typeof event.data === 'object' &&
815
- event.data !== null &&
816
- 'authorization_id' in event.data
817
- ) {
818
- const { authorization_id } = event.data;
819
- // Resolve the Promise with the connectedAccountId
820
- resolve(`${authorization_id}`);
821
-
822
- // Clean up event listener
823
- window.removeEventListener('message', onAuthResponseReceived);
824
- // Close the auth window
825
- if (authWindow) authWindow.close();
826
- this.eventEmitter.emit('app-connected', app);
827
- } else {
828
- reject(new Error('No connected account ID received'));
829
- }
830
- };
831
-
832
- // Add the message event listener
833
- window.addEventListener('message', onAuthResponseReceived);
834
-
835
- // Handle cases where the user closes the auth window without completing auth
836
- const checkWindowClosed = setInterval(() => {
837
- if (authWindow && authWindow.closed) {
838
- clearInterval(checkWindowClosed);
839
- window.removeEventListener('message', onAuthResponseReceived);
840
- reject(new Error('Auth window closed by user'));
841
- }
842
- }, 500);
843
- });
844
- });
845
-
846
- public disconnectApp = (
847
- appName: string,
848
- connectedAccountId?: string,
849
- ): Promise<any> => {
850
- if (!connectedAccountId && !appName) {
851
- return Promise.reject(
852
- new Error(
853
- `'appName' or 'connectedAccountId' are required when calling 'disconnectApp'`,
854
- ),
855
- );
856
- }
857
-
858
- if (connectedAccountId) {
859
- return this.apiHandler
860
- .deleteAuth(Number(connectedAccountId))
861
- .then((response) => {
862
- this.getApp(appName).then((app) => {
863
- this.eventEmitter.emit('app-disconnected', app);
864
- });
865
- return response;
866
- })
867
- .catch((error) => Promise.reject(error));
868
- }
869
- return this.getApp(appName).then((app: any | null) => {
870
- // If no connected accounts were found
871
- if (
872
- !app ||
873
- !app.connected_accounts ||
874
- app.connected_accounts.length === 0
875
- ) {
876
- return Promise.reject(
877
- new Error(`No connected accounts found for app: ${appName}`),
878
- );
879
- }
880
-
881
- // If exactly one account is found
882
- if (app.connected_accounts.length === 1) {
883
- return this.apiHandler
884
- .deleteAuth(Number(app.connected_accounts[0].id))
885
- .then((response) => {
886
- const appUpdated = app;
887
- appUpdated.connected_accounts = [];
888
- this.eventEmitter.emit('app-disconnected', appUpdated);
889
- return response;
890
- })
891
- .catch((error) => Promise.reject(error));
892
- }
893
-
894
- // If more than one account is found
895
- return Promise.reject(
896
- new Error(`Multiple connected accounts found for app: ${appName}`),
897
- );
898
- });
899
- };
900
-
901
- public isAppConnected = (appName: string): Promise<any> => {
902
- if (!appName) {
903
- return Promise.reject(
904
- new Error(`'appName' is required when calling 'isConnected'`),
905
- );
906
- }
907
-
908
- return this.apiHandler
909
- .getConnectedAccounts(appName)
910
- .then((response) => {
911
- if (response && response.connected_accounts.length > 0) {
912
- return Promise.resolve(true);
913
- }
914
- return Promise.resolve(false);
915
- })
916
- .catch((error) => Promise.reject(error));
917
- };
918
-
919
- public getFunction = (functionName: string): Promise<any> => {
920
- if (!functionName) {
921
- return Promise.reject(
922
- new Error(
923
- `'functionName' is required when calling 'getFunctionSignature'`,
924
- ),
925
- );
926
- }
927
-
928
- return this.apiHandler.getFunctionSignature(functionName);
929
- };
930
-
931
- public getConnectedAccounts = (
932
- appName: string,
933
- ): Promise<ConnectedAccount[] | null> => {
934
- if (!appName) {
935
- return Promise.reject(
936
- new Error(`'appName' is required when calling 'getConnectedAccounts'`),
937
- );
938
- }
939
-
940
- return this.apiHandler.getConnectedAccounts(appName).then((response) => {
941
- // Check if response and connected_accounts are valid and not empty
942
- if (response && response.connected_accounts.length > 0) {
943
- // Return an array of strings containing only the ids
944
-
945
- return Promise.resolve(response.connected_accounts); // Resolve with the array of ids as strings
946
- }
947
- return Promise.resolve([]); // Return an empty array if no connected accounts
948
- });
949
- };
950
-
951
- private getApp = (appName: string): Promise<MarketplaceApp | null> => {
952
- if (!appName) {
953
- return Promise.reject(
954
- new Error(`'appName' is required when calling 'getApp'`),
955
- );
956
- }
957
-
958
- return this.apiHandler.getApp(appName).then((response) => response);
959
- };
960
-
961
- /**
962
- * Render the template form we ship
963
- * @param data
964
- */
965
- public renderAccountConnectionModal = (data?: {
966
- deploymentId?: string;
967
- appId?: number;
968
- authTypeId?: number;
969
- }): void => {
970
- const store = createSDKStore();
971
- if (data) {
972
- const { appId, authTypeId } = data;
973
- if (!appId && authTypeId) {
974
- throw new Error(
975
- `IntegrySDK: 'authTypeId' cannot be used without providing 'appId' when calling 'renderAccountConnectionModal'`,
976
- );
977
- }
978
- }
979
-
980
- let targetEl = document.getElementById(this.authModalId);
981
- if (!targetEl) {
982
- targetEl = document.createElement('div');
983
- targetEl.id = this.authModalId;
984
- document.body.appendChild(targetEl);
985
- } else {
986
- store.setState({
987
- genericData: {
988
- ...initialState.genericData,
989
- showAppAuthModal: true,
990
- },
991
- });
992
- }
993
- if (data && data.authTypeId) {
994
- this.forceRerender = !this.forceRerender;
995
- }
996
-
997
- store.setState({
998
- userConfig: this.config.userConfig,
999
- genericData: {
1000
- ...initialState.genericData,
1001
- deploymentId:
1002
- data && data.deploymentId ? Number(data.deploymentId) : null,
1003
- authConnection: {
1004
- appId: data && data.appId ? Number(data.appId) : null,
1005
- authTypeId: data && data.authTypeId ? Number(data.authTypeId) : null,
1006
- },
1007
- authModalId: this.authModalId,
1008
- showAppAuthModal: !data?.authTypeId,
1009
- isAnonymous: !!this.config.xIntegryConfig?.isAnonymous,
1010
- },
1011
- });
1012
-
1013
- render(
1014
- html`
1015
- <${AppContext.Provider}
1016
- value=${{
1017
- apiHandler: this.apiHandler,
1018
- eventEmitter: this.eventEmitter,
1019
- isPreviewMode: false,
1020
- }}
1021
- >
1022
- <${Provider} store=${store}>
1023
- <${AuthSetupContainer}
1024
- deploymentId=${data?.deploymentId}
1025
- appId=${data?.appId}
1026
- authTypeId=${data?.authTypeId}
1027
- forceRerender=${this.forceRerender}
1028
- onClose=${() => {
1029
- const authIdElement = document.getElementById(this.authModalId);
1030
- if (authIdElement) {
1031
- authIdElement.remove();
1032
- }
1033
- }}
1034
- >
1035
- <//>
1036
- <//>
1037
- <//>
1038
- `,
1039
- targetEl,
1040
- );
1041
- };
1042
-
1043
- public async removeAuthorization(data: { authorizationId: number }): Promise<{
1044
- data: string | null;
1045
- status: number;
1046
- } | null> {
1047
- /// throw error if authId is not provided
1048
- if (!data.authorizationId) {
1049
- throw new Error(
1050
- `'authorizationId' is required when calling 'removeAuthorization'`,
1051
- );
1052
- }
1053
- return this.apiHandler.deleteAuth(data.authorizationId).then((response) => {
1054
- this.eventEmitter.emit('did-remove-authorization', {
1055
- authorizationId: Number(data.authorizationId),
1056
- });
1057
- this.init({ ...this.initConfig, skipAccountConnectionOnLoad: true });
1058
- return response
1059
- ? {
1060
- status: response.status,
1061
- data: response.data,
1062
- }
1063
- : null;
1064
- });
1065
- }
1066
-
1067
- /**
1068
- * Render the template form we ship
1069
- * @param params
1070
- */
1071
- public renderPreview = (params: PreviewPayload): void => {
1072
- const { templateData, metadata, previewContainerId } = params;
1073
- const targetEl = document.getElementById(previewContainerId);
1074
- if (!targetEl) {
1075
- console.warn(
1076
- `Integry template form render target with id ${previewContainerId} was not found`,
1077
- );
1078
- return;
1079
- }
1080
- const store = createSDKStore();
1081
-
1082
- store.setState({
1083
- genericData: {
1084
- ...initialState.genericData,
1085
- implicitAuthEnabled: !!this.config.xIntegryConfig?.appAuth?.apiKey,
1086
- },
1087
- });
1088
-
1089
- render(
1090
- html`
1091
- <${AppContext.Provider}
1092
- value=${{
1093
- apiHandler: this.apiHandler,
1094
- eventEmitter: this.eventEmitter,
1095
- isPreviewMode: true,
1096
- }}
1097
- >
1098
- <${Provider} store=${store}>
1099
- <${FlowSetupContainer}
1100
- deploymentId=${this.config.deploymentId}
1101
- isPreviewMode=${true}
1102
- templatePreviewData=${templateData}
1103
- previewMetadata=${metadata}
1104
- >
1105
- <//>
1106
- <//>
1107
- <//>
1108
- `,
1109
- targetEl,
1110
- );
1111
- };
1112
-
1113
- /**
1114
- *
1115
- * @param initConfig
1116
- */
1117
- public init = (initConfig: InitConfig) => {
1118
- const { appId, showApps = false } = initConfig;
1119
- if (!this.config.appKey || !this.config.hash || !this.config.userId) {
1120
- this.SDKFailedHandler(this.config, initConfig.containerId);
1121
- }
1122
- this.initConfig = initConfig;
1123
- if (!appId) {
1124
- if (showApps) {
1125
- this.renderAppFlows(initConfig);
1126
- } else {
1127
- this.initializeMarketplace(initConfig);
1128
- }
1129
- } else {
1130
- this.renderAppFlows(initConfig);
1131
- }
1132
- };
1133
-
1134
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1135
- public updateSdkUserConfig = (config: any) => {
1136
- const store = createSDKStore();
1137
- const currentConfig = store.getState();
1138
- store.setState({
1139
- userConfig: { ...currentConfig.userConfig, ...config.userConfig },
1140
- });
1141
- };
1142
-
1143
- public initializeMarketplace = (initConfig: InitConfig) => {
1144
- const {
1145
- containerId,
1146
- templateContainerId,
1147
- renderMode,
1148
- renderFlowsMode,
1149
- skipAccountConnectionOnLoad = false,
1150
- testMultipurpose = true,
1151
- flowId = null,
1152
- integrationId = null,
1153
- viewStyle = testMultipurpose === false
1154
- ? ViewStyles.COMFORTABLE
1155
- : ViewStyles.COMFORTABLE,
1156
- } = initConfig;
1157
-
1158
- const target = document.getElementById(containerId);
1159
-
1160
- if (!renderMode) {
1161
- throw new Error('Template form render mode needs to be defined');
1162
- }
1163
-
1164
- this.setupFlowFormDestination(renderMode, templateContainerId);
1165
- if (target) {
1166
- const layout = TemplateListingRenderModes.LIST;
1167
- /** REMOVED THIS TO SUPPRESS x-integry-layout dom attribute to avoid grid */
1168
- // (target.getAttribute(
1169
- // 'x-integry-layout',
1170
- // ) as TemplateListingRenderModes) || TemplateListingRenderModes.LIST;
1171
- // this.renderMode = renderMode;
1172
- const store = createSDKStore();
1173
- store.setState({
1174
- userConfig: this.config.userConfig,
1175
- xIntegryConfig: this.config.xIntegryConfig || {},
1176
- integrationIdToEdit: integrationId,
1177
- showSetupModal: flowId
1178
- ? renderMode === TemplateFormRenderModes.MODAL
1179
- : false,
1180
- showSetupInline: flowId
1181
- ? renderMode === TemplateFormRenderModes.INLINE
1182
- : false,
1183
- genericData: {
1184
- ...initialState.genericData,
1185
- templateId: flowId,
1186
- implicitAuthEnabled: !!this.config.xIntegryConfig?.appAuth?.apiKey,
1187
- deploymentId: Number(this.config.deploymentId),
1188
- isAnonymous: !!this.config.xIntegryConfig?.isAnonymous,
1189
- skipAccountConnectionOnLoad,
1190
- deploymentIdFromConfig: this.config.deploymentId
1191
- ? Number(this.config.deploymentId)
1192
- : null,
1193
- testMultipurpose,
1194
- viewStyle,
1195
- },
1196
- customComponents: this.config.userConfig?.customComponents,
1197
- ...(renderFlowsMode === TemplateFormRenderModes.MODAL && {
1198
- showFlowsListModal: true,
1199
- }),
1200
- });
1201
-
1202
- this.verifyAuthConfig()
1203
- .then((response) => {
1204
- if (!response?.config_verified) {
1205
- console.error(
1206
- 'IntegrySDK: Auth config verification failed, are your auth parameters correct?',
1207
- );
1208
- } else {
1209
- const currentState = store.getState();
1210
- store.setState({
1211
- genericData: {
1212
- ...currentState.genericData,
1213
- customerAppName: response.meta.app.name,
1214
- },
1215
- });
1216
- this.eventEmitter.emit('ready', {
1217
- isReady: true,
1218
- });
1219
- this.getUserVariables().then((userVariables) => {
1220
- let userVariablesValidation = true;
1221
- userVariables.forEach((variable: any) => {
1222
- if (
1223
- (variable.key !== 'api_key' &&
1224
- (!this.config.xIntegryConfig?.appAuth?.extras ||
1225
- !this.config.xIntegryConfig?.appAuth?.extras[
1226
- variable.key
1227
- ])) ||
1228
- (variable.key === 'api_key' &&
1229
- !this.config.xIntegryConfig?.appAuth?.apiKey)
1230
- ) {
1231
- userVariablesValidation = false;
1232
- }
1233
- });
1234
- if (!userVariablesValidation) {
1235
- this.eventEmitter.emit('did-raise-sdk-embed-warning', {
1236
- type: 'missing-user-variable-values',
1237
- message:
1238
- 'One or more user variables or their values are missing.',
1239
- });
1240
- }
1241
- store.setState({
1242
- genericData: {
1243
- ...currentState.genericData,
1244
- userVariables,
1245
- userVariablesValidation,
1246
- storage: response.meta.storage,
1247
- },
1248
- });
1249
- });
1250
- }
1251
- })
1252
- .catch((err) => console.error(err));
1253
-
1254
- render(
1255
- html`
1256
- <${AppContext.Provider}
1257
- value=${{
1258
- apiHandler: this.apiHandler,
1259
- eventEmitter: this.eventEmitter,
1260
- isPreviewMode: false,
1261
- }}
1262
- >
1263
- <${Provider} store=${store} key=${this.getRandomFlowId(10)}>
1264
- <${SDKContainer}
1265
- deploymentId=${this.config.deploymentId}
1266
- userConfig=${this.config.userConfig}
1267
- layout=${layout}
1268
- renderMode=${renderMode}
1269
- renderFlowsMode=${renderFlowsMode ||
1270
- TemplateFormRenderModes.INLINE}
1271
- >
1272
- <//>
1273
- <//>
1274
- <//>
1275
- ${this.config.userConfig?.debug &&
1276
- html`<${SDKDebugContainer}
1277
- message=""
1278
- config=${this.config}
1279
- eventEmitter=${this.eventEmitter}
1280
- >
1281
- <//>`}
1282
- `,
1283
- target,
1284
- );
1285
- } else {
1286
- console.warn(
1287
- `Integry SDK render target with id ${containerId} was not found`,
1288
- );
1289
- // throw new Error('The render target was not found');
1290
- }
1291
- };
1292
-
1293
- public showFlows = (
1294
- renderMode: RenderModes = RenderModes.MODAL,
1295
- containerId = 'integry-marketplace',
1296
- layout = Layouts.WIDE,
1297
- ) => {
1298
- const target = document.getElementById(containerId);
1299
-
1300
- if (!renderMode) {
1301
- throw new Error('Template form render mode needs to be defined');
1302
- }
1303
-
1304
- if (target) {
1305
- const templateListLayout = TemplateListingRenderModes.LIST;
1306
-
1307
- const store = createSDKStore();
1308
- store.setState({
1309
- userConfig: this.config.userConfig,
1310
- xIntegryConfig: this.config.xIntegryConfig || {},
1311
- showSetupModal: false,
1312
- showSetupInline: false,
1313
- genericData: {
1314
- ...initialState.genericData,
1315
- templateId: null,
1316
- implicitAuthEnabled: !!this.config.xIntegryConfig?.appAuth?.apiKey,
1317
- deploymentId: Number(this.config.deploymentId),
1318
- isAnonymous: !!this.config.xIntegryConfig?.isAnonymous,
1319
- skipAccountConnectionOnLoad: false,
1320
- deploymentIdFromConfig: this.config.deploymentId
1321
- ? Number(this.config.deploymentId)
1322
- : null,
1323
- testMultipurpose: true,
1324
- showTemplates: true,
1325
- showApps: false,
1326
- viewStyle: layout,
1327
- },
1328
- customComponents: this.config.userConfig?.customComponents,
1329
- ...(renderMode === RenderModes.MODAL && {
1330
- showMarketplaceModal: true,
1331
- }),
1332
- });
1333
-
1334
- this.verifyAuthConfig()
1335
- .then((response) => {
1336
- if (!response?.config_verified) {
1337
- console.error(
1338
- 'IntegrySDK: Auth config verification failed, are your auth parameters correct?',
1339
- );
1340
- } else {
1341
- const currentState = store.getState();
1342
- store.setState({
1343
- genericData: {
1344
- ...currentState.genericData,
1345
- customerAppName: response.meta.app.name,
1346
- },
1347
- });
1348
- this.eventEmitter.emit('ready', {
1349
- isReady: true,
1350
- });
1351
- this.getUserVariables().then((userVariables) => {
1352
- let userVariablesValidation = true;
1353
- userVariables.forEach((variable: any) => {
1354
- if (
1355
- (variable.key !== 'api_key' &&
1356
- (!this.config.xIntegryConfig?.appAuth?.extras ||
1357
- !this.config.xIntegryConfig?.appAuth?.extras[
1358
- variable.key
1359
- ])) ||
1360
- (variable.key === 'api_key' &&
1361
- !this.config.xIntegryConfig?.appAuth?.apiKey)
1362
- ) {
1363
- userVariablesValidation = false;
1364
- }
1365
- });
1366
- if (!userVariablesValidation) {
1367
- this.eventEmitter.emit('did-raise-sdk-embed-warning', {
1368
- type: 'missing-user-variable-values',
1369
- message:
1370
- 'One or more user variables or their values are missing.',
1371
- });
1372
- }
1373
- store.setState({
1374
- genericData: {
1375
- ...currentState.genericData,
1376
- userVariables,
1377
- userVariablesValidation,
1378
- storage: response.meta.storage,
1379
- },
1380
- });
1381
- });
1382
- }
1383
- })
1384
- .catch((err) => console.error(err));
1385
-
1386
- render(
1387
- html`
1388
- <${AppContext.Provider}
1389
- value=${{
1390
- apiHandler: this.apiHandler,
1391
- eventEmitter: this.eventEmitter,
1392
- isPreviewMode: false,
1393
- }}
1394
- >
1395
- <${Provider} store=${store} key=${this.getRandomFlowId(10)}>
1396
- <${SDKContainer}
1397
- deploymentId=${this.config.deploymentId}
1398
- userConfig=${this.config.userConfig}
1399
- layout=${templateListLayout}
1400
- renderMode=${renderMode}
1401
- renderFlowsMode=${renderMode || TemplateFormRenderModes.INLINE}
1402
- >
1403
- <//>
1404
- <//>
1405
- <//>
1406
- ${this.config.userConfig?.debug &&
1407
- html`<${SDKDebugContainer}
1408
- message=""
1409
- config=${this.config}
1410
- eventEmitter=${this.eventEmitter}
1411
- >
1412
- <//>`}
1413
- `,
1414
- target,
1415
- );
1416
- } else {
1417
- console.warn(
1418
- `Integry SDK render target with id ${containerId} was not found`,
1419
- );
1420
- // throw new Error('The render target was not found');
1421
- }
1422
- };
1423
-
1424
- /**
1425
- *
1426
- * @param marketplaceConfig
1427
- */
1428
- public renderMarketplace = (marketplaceConfig: MarketplaceConfig) => {
1429
- const { containerId, renderMode } = marketplaceConfig;
1430
-
1431
- const target = document.getElementById(containerId);
1432
-
1433
- if (!renderMode) {
1434
- throw new Error('Marketplace render mode needs to be defined');
1435
- }
1436
-
1437
- if (target) {
1438
- const store = createSDKStore();
1439
- store.setState({
1440
- userConfig: this.config.userConfig,
1441
- genericData: {
1442
- ...initialState.genericData,
1443
- implicitAuthEnabled: !!this.config.xIntegryConfig?.appAuth?.apiKey,
1444
- deploymentId: Number(this.config.marketplaceId),
1445
- marketplaceId: Number(this.config.marketplaceId),
1446
- isAnonymous: !!this.config.xIntegryConfig?.isAnonymous,
1447
- },
1448
- customComponents: this.config.userConfig?.customComponents,
1449
- ...(renderMode === MarketplaceRenderModes.MODAL && {
1450
- showMarketplaceModal: true,
1451
- }),
1452
- });
1453
-
1454
- render(
1455
- html`
1456
- <${AppContext.Provider}
1457
- value=${{
1458
- apiHandler: this.apiHandler,
1459
- eventEmitter: this.eventEmitter,
1460
- isPreviewMode: false,
1461
- }}
1462
- >
1463
- <${Provider} store=${store} key=${this.getRandomFlowId(6)}>
1464
- <${MarketplaceContainer}
1465
- marketplaceId=${this.config.marketplaceId}
1466
- userConfig=${this.config.userConfig}
1467
- renderMode=${renderMode}
1468
- >
1469
- <//>
1470
- <//>
1471
- <//>
1472
- `,
1473
- target,
1474
- );
1475
- } else {
1476
- console.warn(
1477
- `Integry SDK render target with id ${containerId} was not found`,
1478
- );
1479
- }
1480
- };
1481
-
1482
- public renderAppFlows = (appFlowConfig: InitConfig) => {
1483
- const {
1484
- containerId,
1485
- renderMode,
1486
- appId,
1487
- renderAppPageMode,
1488
- renderFlowSetupMode,
1489
- showApps = false,
1490
- skipOnDemand = false,
1491
- skipAccountConnectionOnLoad = false,
1492
- testMultipurpose = true,
1493
- viewStyle = testMultipurpose === false
1494
- ? ViewStyles.COMFORTABLE
1495
- : ViewStyles.COMFORTABLE,
1496
- } = appFlowConfig;
1497
- /// const hostApiKey = this.config.xIntegryConfig?.appAuth?.apiKey;
1498
- const target = document.getElementById(containerId);
1499
- if (!renderMode) {
1500
- throw new Error('App Page render mode needs to be defined');
1501
- }
1502
- /* if (!hostApiKey && !showApps) {
1503
- throw new Error('API key for host app needs to be defined');
1504
- } */
1505
- if (target) {
1506
- const store = createSDKStore();
1507
- store.setState({
1508
- userConfig: {
1509
- ...this.config.userConfig,
1510
- hideWebhookUrlScreen: false,
1511
- hideExistingIntegrations:
1512
- this.config.userConfig &&
1513
- Object.prototype.hasOwnProperty.call(
1514
- this.config.userConfig,
1515
- 'hideExistingIntegrations',
1516
- )
1517
- ? this.config.userConfig.hideExistingIntegrations
1518
- : false,
1519
- },
1520
- xIntegryConfig: this.config.xIntegryConfig || {},
1521
- genericData: {
1522
- ...initialState.genericData,
1523
- app_id: appId,
1524
- deploymentId: Number(this.config.deploymentId),
1525
- showTemplates: !!appFlowConfig.showTemplates,
1526
- showApps,
1527
- skipOnDemand,
1528
- skipAccountConnectionOnLoad,
1529
- testMultipurpose,
1530
- viewStyle,
1531
- },
1532
- ...((renderMode === TemplateFormRenderModes.MODAL ||
1533
- renderAppPageMode === TemplateFormRenderModes.MODAL) && {
1534
- showMarketplaceModal: true,
1535
- }),
1536
- });
1537
-
1538
- this.verifyAuthConfig()
1539
- .then((response) => {
1540
- if (!response?.config_verified) {
1541
- console.error(
1542
- 'IntegrySDK: Auth config verification failed, are your auth parameters correct?',
1543
- );
1544
- } else {
1545
- const currentState = store.getState();
1546
- store.setState({
1547
- genericData: {
1548
- ...currentState.genericData,
1549
- customerAppName: response.meta.app.name,
1550
- },
1551
- });
1552
- this.eventEmitter.emit('ready', {
1553
- isReady: true,
1554
- });
1555
- this.getUserVariables().then((userVariables) => {
1556
- let userVariablesValidation = true;
1557
- userVariables.forEach((variable: any) => {
1558
- if (
1559
- (variable.is_required &&
1560
- variable.key !== 'api_key' &&
1561
- (!this.config.xIntegryConfig?.appAuth?.extras ||
1562
- !this.config.xIntegryConfig?.appAuth?.extras[
1563
- variable.key
1564
- ])) ||
1565
- (variable.key === 'api_key' &&
1566
- !this.config.xIntegryConfig?.appAuth?.apiKey)
1567
- ) {
1568
- userVariablesValidation = false;
1569
- }
1570
- });
1571
- if (!userVariablesValidation) {
1572
- this.eventEmitter.emit('did-raise-sdk-embed-warning', {
1573
- type: 'missing-user-variable-values',
1574
- message:
1575
- 'One or more user variables or their values are missing.',
1576
- });
1577
- }
1578
- store.setState({
1579
- genericData: {
1580
- ...currentState.genericData,
1581
- userVariables,
1582
- userVariablesValidation,
1583
- storage: response.meta.storage,
1584
- },
1585
- });
1586
- });
1587
- }
1588
- })
1589
- .catch((err) => console.error(err));
1590
-
1591
- render(
1592
- html`
1593
- <${AppContext.Provider}
1594
- value=${{
1595
- apiHandler: this.apiHandler,
1596
- eventEmitter: this.eventEmitter,
1597
- isPreviewMode: false,
1598
- }}
1599
- >
1600
- <${Provider} store=${store} key=${this.getRandomFlowId(6)}>
1601
- <${AppFlowContainer}
1602
- marketplaceId=${this.config.marketplaceId}
1603
- userConfig=${this.config.userConfig}
1604
- renderMode=${renderMode}
1605
- renderAppPageMode=${renderAppPageMode || renderMode}
1606
- renderFlowSetupMode=${renderFlowSetupMode ||
1607
- TemplateFormRenderModes.INLINE}
1608
- >
1609
- <//>
1610
- <//>
1611
- <//>
1612
- ${this.config.userConfig?.debug &&
1613
- html`<${SDKDebugContainer}
1614
- message=""
1615
- config=${this.config}
1616
- eventEmitter=${this.eventEmitter}
1617
- >
1618
- <//>`}
1619
- `,
1620
- target,
1621
- );
1622
- } else {
1623
- console.warn(
1624
- `Integry SDK render target with id ${containerId} was not found`,
1625
- );
1626
- }
1627
- };
1628
-
1629
- public showApp = (
1630
- appName: string,
1631
- renderMode: RenderModes = RenderModes.MODAL,
1632
- containerId = 'integry-marketplace',
1633
- layout: Layouts = Layouts.WIDE,
1634
- ) => {
1635
- /// const hostApiKey = this.config.xIntegryConfig?.appAuth?.apiKey;
1636
- let target = document.getElementById(containerId);
1637
- if (!appName) {
1638
- throw new Error('App name needs to be defined');
1639
- }
1640
- if (!target && renderMode !== RenderModes.MODAL) {
1641
- console.warn(
1642
- `Integry SDK render target with id ${containerId} was not found`,
1643
- );
1644
- return;
1645
- }
1646
-
1647
- if (!target && renderMode === RenderModes.MODAL) {
1648
- const targetEl = document.createElement('div');
1649
- targetEl.id = containerId;
1650
- document.body.appendChild(targetEl);
1651
- target = targetEl;
1652
- }
1653
- if (target) {
1654
- const store = createSDKStore();
1655
- store.setState({
1656
- userConfig: {
1657
- ...this.config.userConfig,
1658
- hideWebhookUrlScreen: false,
1659
- hideExistingIntegrations:
1660
- this.config.userConfig &&
1661
- Object.prototype.hasOwnProperty.call(
1662
- this.config.userConfig,
1663
- 'hideExistingIntegrations',
1664
- )
1665
- ? this.config.userConfig.hideExistingIntegrations
1666
- : false,
1667
- },
1668
- xIntegryConfig: this.config.xIntegryConfig || {},
1669
- genericData: {
1670
- ...initialState.genericData,
1671
- app_id: appName,
1672
- deploymentId: Number(this.config.deploymentId),
1673
- showTemplates: false,
1674
- showApps: false,
1675
- skipOnDemand: false,
1676
- skipAccountConnectionOnLoad: false,
1677
- testMultipurpose: true,
1678
- viewStyle: layout,
1679
- },
1680
- ...(renderMode === RenderModes.MODAL && {
1681
- showMarketplaceModal: true,
1682
- }),
1683
- });
1684
-
1685
- this.verifyAuthConfig()
1686
- .then((response) => {
1687
- if (!response?.config_verified) {
1688
- console.error(
1689
- 'IntegrySDK: Auth config verification failed, are your auth parameters correct?',
1690
- );
1691
- } else {
1692
- const currentState = store.getState();
1693
- store.setState({
1694
- genericData: {
1695
- ...currentState.genericData,
1696
- customerAppName: response.meta.app.name,
1697
- },
1698
- });
1699
- this.eventEmitter.emit('ready', {
1700
- isReady: true,
1701
- });
1702
- this.getUserVariables().then((userVariables) => {
1703
- let userVariablesValidation = true;
1704
- userVariables.forEach((variable: any) => {
1705
- if (
1706
- (variable.is_required &&
1707
- variable.key !== 'api_key' &&
1708
- (!this.config.xIntegryConfig?.appAuth?.extras ||
1709
- !this.config.xIntegryConfig?.appAuth?.extras[
1710
- variable.key
1711
- ])) ||
1712
- (variable.key === 'api_key' &&
1713
- !this.config.xIntegryConfig?.appAuth?.apiKey)
1714
- ) {
1715
- userVariablesValidation = false;
1716
- }
1717
- });
1718
- if (!userVariablesValidation) {
1719
- this.eventEmitter.emit('did-raise-sdk-embed-warning', {
1720
- type: 'missing-user-variable-values',
1721
- message:
1722
- 'One or more user variables or their values are missing.',
1723
- });
1724
- }
1725
- store.setState({
1726
- genericData: {
1727
- ...currentState.genericData,
1728
- userVariables,
1729
- userVariablesValidation,
1730
- storage: response.meta.storage,
1731
- },
1732
- });
1733
- });
1734
- }
1735
- })
1736
- .catch((err) => console.error(err));
1737
-
1738
- render(
1739
- html`
1740
- <${AppContext.Provider}
1741
- value=${{
1742
- apiHandler: this.apiHandler,
1743
- eventEmitter: this.eventEmitter,
1744
- isPreviewMode: false,
1745
- }}
1746
- >
1747
- <${Provider} store=${store} key=${this.getRandomFlowId(6)}>
1748
- <${AppFlowContainer}
1749
- marketplaceId=${this.config.marketplaceId}
1750
- userConfig=${this.config.userConfig}
1751
- renderMode=${renderMode}
1752
- renderAppPageMode=${renderMode}
1753
- renderFlowSetupMode=${renderMode}
1754
- >
1755
- <//>
1756
- <//>
1757
- <//>
1758
- ${this.config.userConfig?.debug &&
1759
- html`<${SDKDebugContainer}
1760
- message=""
1761
- config=${this.config}
1762
- eventEmitter=${this.eventEmitter}
1763
- >
1764
- <//>`}
1765
- `,
1766
- target,
1767
- );
1768
- } else {
1769
- console.warn(
1770
- `Integry SDK render target with id ${containerId} was not found`,
1771
- );
1772
- }
1773
- };
1774
-
1775
- public showApps = (
1776
- renderMode: RenderModes = RenderModes.MODAL,
1777
- containerId = 'integry-marketplace',
1778
- layout = Layouts.WIDE,
1779
- fetchAll = false,
1780
- useLoadMoreButton = false,
1781
- ) => {
1782
- let target = document.getElementById(containerId);
1783
- if (!target) {
1784
- const targetEl = document.createElement('div');
1785
- targetEl.id = containerId;
1786
- document.body.appendChild(targetEl);
1787
- target = targetEl;
1788
- }
1789
-
1790
- if (target) {
1791
- const store = createSDKStore();
1792
- store.setState({
1793
- userConfig: {
1794
- ...this.config.userConfig,
1795
- hideWebhookUrlScreen: false,
1796
- hideExistingIntegrations:
1797
- this.config.userConfig &&
1798
- Object.prototype.hasOwnProperty.call(
1799
- this.config.userConfig,
1800
- 'hideExistingIntegrations',
1801
- )
1802
- ? this.config.userConfig.hideExistingIntegrations
1803
- : false,
1804
- },
1805
- xIntegryConfig: this.config.xIntegryConfig || {},
1806
- genericData: {
1807
- ...initialState.genericData,
1808
- deploymentId: Number(this.config.deploymentId),
1809
- showTemplates: false,
1810
- showApps: true,
1811
- skipOnDemand: false,
1812
- skipAccountConnectionOnLoad: false,
1813
- testMultipurpose: true,
1814
- viewStyle: layout,
1815
- },
1816
- ...(renderMode === RenderModes.MODAL && {
1817
- showMarketplaceModal: true,
1818
- }),
1819
- });
1820
-
1821
- this.verifyAuthConfig()
1822
- .then((response) => {
1823
- if (!response?.config_verified) {
1824
- console.error(
1825
- 'IntegrySDK: Auth config verification failed, are your auth parameters correct?',
1826
- );
1827
- } else {
1828
- const currentState = store.getState();
1829
- store.setState({
1830
- genericData: {
1831
- ...currentState.genericData,
1832
- customerAppName: response.meta.app.name,
1833
- },
1834
- });
1835
- }
1836
- })
1837
- .catch((err) => console.error(err));
1838
-
1839
- render(
1840
- html`
1841
- <${AppContext.Provider}
1842
- value=${{
1843
- apiHandler: this.apiHandler,
1844
- eventEmitter: this.eventEmitter,
1845
- isPreviewMode: false,
1846
- }}
1847
- >
1848
- <${Provider} store=${store} key=${this.getRandomFlowId(6)}>
1849
- <${MarketplaceAppsContainer}
1850
- marketplaceId=${this.config.marketplaceId}
1851
- userConfig=${this.config.userConfig}
1852
- renderMode=${renderMode}
1853
- renderAppPageMode=${renderMode}
1854
- renderFlowSetupMode=${TemplateFormRenderModes.INLINE}
1855
- fetchAll=${fetchAll}
1856
- useLoadMoreButton=${useLoadMoreButton}
1857
- >
1858
- <//>
1859
- <//>
1860
- <//>
1861
- `,
1862
- target,
1863
- );
1864
- } else {
1865
- console.warn(
1866
- `Integry SDK render target with id ${containerId} was not found`,
1867
- );
1868
- }
1869
- };
1870
-
1871
- public showConnectedAccounts = (
1872
- appName: string,
1873
- renderMode: RenderModes = RenderModes.MODAL,
1874
- containerId = 'integry-marketplace',
1875
- layout = Layouts.WIDE,
1876
- ) => {
1877
- let target = document.getElementById(containerId);
1878
- if (!target) {
1879
- const targetEl = document.createElement('div');
1880
- targetEl.id = containerId;
1881
- document.body.appendChild(targetEl);
1882
- target = targetEl;
1883
- }
1884
-
1885
- if (target) {
1886
- const store = createSDKStore();
1887
- store.setState({
1888
- userConfig: {
1889
- ...this.config.userConfig,
1890
- hideWebhookUrlScreen: false,
1891
- hideExistingIntegrations:
1892
- this.config.userConfig &&
1893
- Object.prototype.hasOwnProperty.call(
1894
- this.config.userConfig,
1895
- 'hideExistingIntegrations',
1896
- )
1897
- ? this.config.userConfig.hideExistingIntegrations
1898
- : false,
1899
- },
1900
- xIntegryConfig: this.config.xIntegryConfig || {},
1901
- genericData: {
1902
- ...initialState.genericData,
1903
- deploymentId: Number(this.config.deploymentId),
1904
- showTemplates: false,
1905
- showApps: true,
1906
- skipOnDemand: false,
1907
- skipAccountConnectionOnLoad: false,
1908
- testMultipurpose: true,
1909
- viewStyle: layout,
1910
- },
1911
- ...(renderMode === RenderModes.MODAL && {
1912
- showMarketplaceModal: true,
1913
- }),
1914
- });
1915
-
1916
- this.verifyAuthConfig()
1917
- .then((response) => {
1918
- if (!response?.config_verified) {
1919
- console.error(
1920
- 'IntegrySDK: Auth config verification failed, are your auth parameters correct?',
1921
- );
1922
- } else {
1923
- const currentState = store.getState();
1924
- store.setState({
1925
- genericData: {
1926
- ...currentState.genericData,
1927
- customerAppName: response.meta.app.name,
1928
- },
1929
- });
1930
- }
1931
- })
1932
- .catch((err) => console.error(err));
1933
-
1934
- render(
1935
- html`
1936
- <${AppContext.Provider}
1937
- value=${{
1938
- apiHandler: this.apiHandler,
1939
- eventEmitter: this.eventEmitter,
1940
- isPreviewMode: false,
1941
- }}
1942
- >
1943
- <${Provider} store=${store} key=${this.getRandomFlowId(6)}>
1944
- <${MarketplaceAppsContainer}
1945
- marketplaceId=${this.config.marketplaceId}
1946
- userConfig=${this.config.userConfig}
1947
- renderMode=${renderMode}
1948
- renderAppPageMode=${renderMode}
1949
- renderFlowSetupMode=${TemplateFormRenderModes.INLINE}
1950
- appName=${appName}
1951
- >
1952
- <//>
1953
- <//>
1954
- <//>
1955
- `,
1956
- target,
1957
- );
1958
- } else {
1959
- console.warn(
1960
- `Integry SDK render target with id ${containerId} was not found`,
1961
- );
1962
- }
1963
- };
1964
-
1965
- public renderMultipurposeField = ({
1966
- containerId,
1967
- multipurposeFieldProps,
1968
- }: {
1969
- containerId: string;
1970
- multipurposeFieldProps: MultipurposeFieldType;
1971
- }) => {
1972
- const target = document.getElementById(containerId);
1973
-
1974
- if (target) {
1975
- render(
1976
- html`<div>
1977
- ${multipurposeFieldProps.type === 'CHECKBOX' ||
1978
- multipurposeFieldProps.type === 'RADIO' ||
1979
- multipurposeFieldProps.type === 'SELECT'
1980
- ? html`<${ListBox}
1981
- activityOutputData=${multipurposeFieldProps.activityOutputData}
1982
- title=${multipurposeFieldProps.title}
1983
- description=${multipurposeFieldProps.description}
1984
- placeholder=${multipurposeFieldProps.placeholder}
1985
- value=${multipurposeFieldProps.value}
1986
- type=${multipurposeFieldProps.type}
1987
- onChange=${multipurposeFieldProps.onChange}
1988
- endpointUrl=${multipurposeFieldProps.endpointUrl}
1989
- isSearchable=${multipurposeFieldProps.isSearchable}
1990
- allowTagsInText=${multipurposeFieldProps.allowTagsInText}
1991
- isMappable=${multipurposeFieldProps.isMappable}
1992
- isEditable=${multipurposeFieldProps.isEditable}
1993
- hideTabs=${multipurposeFieldProps.hideTabs}
1994
- />`
1995
- : html`<${MultipurposeField}
1996
- activityOutputData=${multipurposeFieldProps.activityOutputData}
1997
- title=${multipurposeFieldProps.title}
1998
- description=${multipurposeFieldProps.description}
1999
- placeholder=${multipurposeFieldProps.placeholder}
2000
- value=${multipurposeFieldProps.value}
2001
- type=${multipurposeFieldProps.type}
2002
- onChange=${multipurposeFieldProps.onChange}
2003
- isMappable=${multipurposeFieldProps.isMappable}
2004
- allowTagsInText=${multipurposeFieldProps.allowTagsInText}
2005
- isSearchable=${multipurposeFieldProps.isSearchable}
2006
- isEditable=${multipurposeFieldProps.isEditable}
2007
- fieldId=${multipurposeFieldProps.fieldId}
2008
- enableTagify=${multipurposeFieldProps.enableTagify}
2009
- />`}
2010
- </div>`,
2011
- target,
2012
- );
2013
- } else {
2014
- console.warn(
2015
- `Integry SDK render target with id ${containerId} was not found`,
2016
- );
2017
- }
2018
- };
2019
-
2020
- public renderFunctionField = (
2021
- containerId: string,
2022
- functionFieldProps: FunctionFieldType,
2023
- ) => {
2024
- const target = document.getElementById(containerId);
2025
-
2026
- if (target) {
2027
- const store = createSDKStore();
2028
- render(
2029
- html`<div>
2030
- <${AppContext.Provider}
2031
- value=${{
2032
- apiHandler: this.apiHandler,
2033
- eventEmitter: this.eventEmitter,
2034
- isPreviewMode: false,
2035
- }}
2036
- >
2037
- <${Provider} store=${store} key=${this.getRandomFlowId(10)}>
2038
- <${FunctionField}
2039
- field=${functionFieldProps.field}
2040
- name="${functionFieldProps.field.activity_field?.machine_name ||
2041
- 'function_field'}"
2042
- description=${functionFieldProps.field.description || ''}
2043
- label="${functionFieldProps.field.title}"
2044
- value=${functionFieldProps.field.default_value || []}
2045
- apiHandler=${this.apiHandler}
2046
- isArray=${!!(functionFieldProps.field.data_type === 'OBJECT[]')}
2047
- onChange=${(val: string) => {
2048
- if (functionFieldProps.onChange) {
2049
- functionFieldProps.onChange(val);
2050
- }
2051
- }}
2052
- tagsTree=${functionFieldProps.tagsTree
2053
- ? functionFieldProps.tagsTree
2054
- : null}
2055
- isReadOnly=${functionFieldProps.isReadOnly}
2056
- />
2057
- <//>
2058
- <//>
2059
- </div>`,
2060
- target,
2061
- );
2062
- } else {
2063
- console.warn(
2064
- `Integry SDK render target with id ${containerId} was not found`,
2065
- );
2066
- }
2067
- };
2068
-
2069
- public renderFlowStep = (
2070
- options: RenderFlowStepOptions = {
2071
- containerId: 'integry-marketplace',
2072
- step: {},
2073
- connectedAccountId: '',
2074
- tagsComponent: null,
2075
- tagsTree: {},
2076
- onFieldChangeCallback: () => {
2077
- // Placeholder function for future implementation
2078
- },
2079
- showMappingMenu: false,
2080
- isReadOnly: false,
2081
- showMenuOnLeft: false,
2082
- },
2083
- ) => {
2084
- const target = document.getElementById(options.containerId);
2085
-
2086
- if (target) {
2087
- const store = createSDKStore();
2088
- render(
2089
- html`<div>
2090
- <${AppContext.Provider}
2091
- value=${{
2092
- apiHandler: this.apiHandler,
2093
- eventEmitter: this.eventEmitter,
2094
- isPreviewMode: false,
2095
- }}
2096
- >
2097
- <${Provider} store=${store} key=${this.getRandomFlowId(10)}>
2098
- <${ActionForm}
2099
- step=${options.step}
2100
- stepType=${'CONFIGURE'}
2101
- showStepValidation=${false}
2102
- apiHandler=${this.apiHandler}
2103
- eventEmitter=${this.eventEmitter}
2104
- isReadOnly="${false}"
2105
- selectedAuthId="${options.connectedAccountId}"
2106
- accountConnected=${true}
2107
- tagsComponent=${options.tagsComponent}
2108
- onFieldChangeCallback=${options.onFieldChangeCallback}
2109
- tagsTree=${options.tagsTree}
2110
- showMappingMenu=${options.showMappingMenu}
2111
- isReadOnly=${options.isReadOnly}
2112
- showMenuOnLeft=${options.showMenuOnLeft}
2113
- tagsTreeActivityOutput=${JSONToActivityOutputData(
2114
- options.tagsTree || {},
2115
- )}
2116
- />
2117
- <//>
2118
- <//>
2119
- </div>`,
2120
- target,
2121
- );
2122
- } else {
2123
- console.warn(
2124
- `Integry SDK render target with id ${options.containerId} was not found`,
2125
- );
2126
- }
2127
- };
2128
-
2129
- public renderMappingMenu = (
2130
- options: RenderMappingMenuOptions = {
2131
- containerId: '',
2132
- tagsTree: {},
2133
- onTagSelect: () => {
2134
- // Placeholder function for future implementation
2135
- },
2136
- renderValuesTab: false,
2137
- options: [],
2138
- onOptionClick: () => {
2139
- // Placeholder function for future implementation
2140
- },
2141
- },
2142
- ) => {
2143
- const target = document.getElementById(options.containerId);
2144
-
2145
- if (target) {
2146
- const store = createSDKStore();
2147
- render(
2148
- html`<div>
2149
- <${AppContext.Provider}
2150
- value=${{
2151
- apiHandler: this.apiHandler,
2152
- eventEmitter: this.eventEmitter,
2153
- isPreviewMode: false,
2154
- }}
2155
- >
2156
- <${Provider} store=${store} key=${this.getRandomFlowId(10)}>
2157
- <${TagsMenu}
2158
- tagsTree=${options.tagsTree}
2159
- onSelect=${options.onTagSelect}
2160
- renderValuesTab=${options.renderValuesTab}
2161
- options=${options.options}
2162
- onOptionClick=${options.onOptionClick}
2163
- />
2164
- <//>
2165
- <//>
2166
- </div>`,
2167
- target,
2168
- );
2169
- } else {
2170
- console.warn(
2171
- `Integry SDK render target with id ${options.containerId} was not found`,
2172
- );
2173
- }
2174
- };
2175
-
2176
- public verifyAuthConfig = () =>
2177
- this.apiHandler.verifyAuthConfig({
2178
- deploymentId: this.config.deploymentId,
2179
- });
2180
-
2181
- private getUserVariables = async () => {
2182
- try {
2183
- const res = await this.apiHandler.getUserVariables();
2184
- return res ? res.results : [];
2185
- } catch (err) {
2186
- console.error(err);
2187
- return [];
2188
- }
2189
- };
2190
-
2191
- /**
2192
- * Destroy SDK instance and cleanup store
2193
- */
2194
- public destroy = () => {
2195
- try {
2196
- this.eventEmitter.offAll();
2197
- const authIdElement = document.getElementById(this.authModalId);
2198
- if (authIdElement) {
2199
- authIdElement.remove();
2200
- }
2201
- } catch (error) {
2202
- console.error('There was an error unsubscribing from all events');
2203
- }
2204
- };
2205
-
2206
- static setFieldValue = (fieldId: string, value: string) => {
2207
- const fieldElement = document
2208
- .getElementById(fieldId)
2209
- ?.querySelector('input') as HTMLInputElement | null;
2210
- if (fieldElement) {
2211
- if (fieldElement instanceof HTMLInputElement) {
2212
- fieldElement.value = value;
2213
- const keyupEvent = new KeyboardEvent('keyup', {
2214
- key: 'a', // Specify the key (optional)
2215
- bubbles: true, // Allow event to bubble up
2216
- cancelable: true, // Allow event to be cancelable
2217
- });
2218
- fieldElement.dispatchEvent(keyupEvent);
2219
- }
2220
- }
2221
- const tagifyFieldElement = document.getElementById(`tagify_${fieldId}`);
2222
- if (tagifyFieldElement) {
2223
- if (tagifyFieldElement instanceof HTMLInputElement) {
2224
- tagifyFieldElement.value = value;
2225
- const keyupEvent = new KeyboardEvent('keyup', {
2226
- key: 'a', // Specify the key (optional)
2227
- bubbles: true, // Allow event to bubble up
2228
- cancelable: true, // Allow event to be cancelable
2229
- });
2230
- tagifyFieldElement.dispatchEvent(keyupEvent);
2231
- }
2232
- }
2233
- };
2234
-
2235
- private getMethod = () => 'POST';
2236
-
2237
- private getBaseAPIUrl = () => 'https://api.integry.io';
2238
-
2239
- private getHeaders = () => ({
2240
- 'Content-Type': 'application/json',
2241
- });
2242
- }
2243
-
2244
- export { Helpers, html };