@amp-labs/react 1.0.0

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 (205) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +138 -0
  3. package/build/generated-sources/api/src/apis/DefaultApi.d.ts +858 -0
  4. package/build/generated-sources/api/src/apis/DefaultApi.js +942 -0
  5. package/build/generated-sources/api/src/apis/index.d.ts +1 -0
  6. package/build/generated-sources/api/src/apis/index.js +19 -0
  7. package/build/generated-sources/api/src/index.d.ts +3 -0
  8. package/build/generated-sources/api/src/index.js +21 -0
  9. package/build/generated-sources/api/src/models/BaseConfigContent.d.ts +38 -0
  10. package/build/generated-sources/api/src/models/BaseConfigContent.js +53 -0
  11. package/build/generated-sources/api/src/models/BaseReadConfig.d.ts +34 -0
  12. package/build/generated-sources/api/src/models/BaseReadConfig.js +51 -0
  13. package/build/generated-sources/api/src/models/BaseReadConfigStandardObject.d.ts +59 -0
  14. package/build/generated-sources/api/src/models/BaseReadConfigStandardObject.js +58 -0
  15. package/build/generated-sources/api/src/models/BatchUpsertIntegrationsRequest.d.ts +31 -0
  16. package/build/generated-sources/api/src/models/BatchUpsertIntegrationsRequest.js +50 -0
  17. package/build/generated-sources/api/src/models/Config.d.ts +56 -0
  18. package/build/generated-sources/api/src/models/Config.js +63 -0
  19. package/build/generated-sources/api/src/models/ConfigContent.d.ts +37 -0
  20. package/build/generated-sources/api/src/models/ConfigContent.js +53 -0
  21. package/build/generated-sources/api/src/models/ConfigContentAllOf.d.ts +31 -0
  22. package/build/generated-sources/api/src/models/ConfigContentAllOf.js +50 -0
  23. package/build/generated-sources/api/src/models/Connection.d.ts +82 -0
  24. package/build/generated-sources/api/src/models/Connection.js +76 -0
  25. package/build/generated-sources/api/src/models/Consumer.d.ts +55 -0
  26. package/build/generated-sources/api/src/models/Consumer.js +62 -0
  27. package/build/generated-sources/api/src/models/CreateConsumerRequest.d.ts +37 -0
  28. package/build/generated-sources/api/src/models/CreateConsumerRequest.js +53 -0
  29. package/build/generated-sources/api/src/models/CreateDestinationRequest.d.ts +44 -0
  30. package/build/generated-sources/api/src/models/CreateDestinationRequest.js +57 -0
  31. package/build/generated-sources/api/src/models/CreateDestinationRequestMetadata.d.ts +39 -0
  32. package/build/generated-sources/api/src/models/CreateDestinationRequestMetadata.js +52 -0
  33. package/build/generated-sources/api/src/models/CreateGroupRequest.d.ts +37 -0
  34. package/build/generated-sources/api/src/models/CreateGroupRequest.js +53 -0
  35. package/build/generated-sources/api/src/models/CreateInstallationRequest.d.ts +44 -0
  36. package/build/generated-sources/api/src/models/CreateInstallationRequest.js +57 -0
  37. package/build/generated-sources/api/src/models/CreateInstallationRequestConfig.d.ts +44 -0
  38. package/build/generated-sources/api/src/models/CreateInstallationRequestConfig.js +57 -0
  39. package/build/generated-sources/api/src/models/CreateIntegrationRequest.d.ts +44 -0
  40. package/build/generated-sources/api/src/models/CreateIntegrationRequest.js +57 -0
  41. package/build/generated-sources/api/src/models/CreateIntegrationRequestLatestRevision.d.ts +31 -0
  42. package/build/generated-sources/api/src/models/CreateIntegrationRequestLatestRevision.js +50 -0
  43. package/build/generated-sources/api/src/models/CreateProjectRequest.d.ts +37 -0
  44. package/build/generated-sources/api/src/models/CreateProjectRequest.js +53 -0
  45. package/build/generated-sources/api/src/models/CreateProviderAppRequest.d.ts +49 -0
  46. package/build/generated-sources/api/src/models/CreateProviderAppRequest.js +59 -0
  47. package/build/generated-sources/api/src/models/Group.d.ts +55 -0
  48. package/build/generated-sources/api/src/models/Group.js +62 -0
  49. package/build/generated-sources/api/src/models/HydratedIntegration.d.ts +50 -0
  50. package/build/generated-sources/api/src/models/HydratedIntegration.js +59 -0
  51. package/build/generated-sources/api/src/models/HydratedIntegrationField.d.ts +22 -0
  52. package/build/generated-sources/api/src/models/HydratedIntegrationField.js +45 -0
  53. package/build/generated-sources/api/src/models/HydratedIntegrationFieldExistent.d.ts +37 -0
  54. package/build/generated-sources/api/src/models/HydratedIntegrationFieldExistent.js +53 -0
  55. package/build/generated-sources/api/src/models/HydratedIntegrationObject.d.ts +75 -0
  56. package/build/generated-sources/api/src/models/HydratedIntegrationObject.js +70 -0
  57. package/build/generated-sources/api/src/models/HydratedIntegrationRead.d.ts +32 -0
  58. package/build/generated-sources/api/src/models/HydratedIntegrationRead.js +51 -0
  59. package/build/generated-sources/api/src/models/HydratedRevision.d.ts +50 -0
  60. package/build/generated-sources/api/src/models/HydratedRevision.js +60 -0
  61. package/build/generated-sources/api/src/models/ImportConnectionRequest.d.ts +85 -0
  62. package/build/generated-sources/api/src/models/ImportConnectionRequest.js +75 -0
  63. package/build/generated-sources/api/src/models/ImportInstallationRequest.d.ts +39 -0
  64. package/build/generated-sources/api/src/models/ImportInstallationRequest.js +55 -0
  65. package/build/generated-sources/api/src/models/ImportInstallationRequestConfig.d.ts +38 -0
  66. package/build/generated-sources/api/src/models/ImportInstallationRequestConfig.js +54 -0
  67. package/build/generated-sources/api/src/models/Installation.d.ts +88 -0
  68. package/build/generated-sources/api/src/models/Installation.js +79 -0
  69. package/build/generated-sources/api/src/models/Integration.d.ts +68 -0
  70. package/build/generated-sources/api/src/models/Integration.js +69 -0
  71. package/build/generated-sources/api/src/models/Integration1.d.ts +50 -0
  72. package/build/generated-sources/api/src/models/Integration1.js +59 -0
  73. package/build/generated-sources/api/src/models/IntegrationField.d.ts +22 -0
  74. package/build/generated-sources/api/src/models/IntegrationField.js +45 -0
  75. package/build/generated-sources/api/src/models/IntegrationFieldExistent.d.ts +31 -0
  76. package/build/generated-sources/api/src/models/IntegrationFieldExistent.js +50 -0
  77. package/build/generated-sources/api/src/models/IntegrationFieldMapping.d.ts +49 -0
  78. package/build/generated-sources/api/src/models/IntegrationFieldMapping.js +57 -0
  79. package/build/generated-sources/api/src/models/IntegrationObject.d.ts +63 -0
  80. package/build/generated-sources/api/src/models/IntegrationObject.js +65 -0
  81. package/build/generated-sources/api/src/models/IntegrationRead.d.ts +32 -0
  82. package/build/generated-sources/api/src/models/IntegrationRead.js +51 -0
  83. package/build/generated-sources/api/src/models/OauthConnectRequest.d.ts +73 -0
  84. package/build/generated-sources/api/src/models/OauthConnectRequest.js +70 -0
  85. package/build/generated-sources/api/src/models/Operation.d.ts +80 -0
  86. package/build/generated-sources/api/src/models/Operation.js +73 -0
  87. package/build/generated-sources/api/src/models/OperationError.d.ts +49 -0
  88. package/build/generated-sources/api/src/models/OperationError.js +56 -0
  89. package/build/generated-sources/api/src/models/OptionalFieldsAutoOption.d.ts +22 -0
  90. package/build/generated-sources/api/src/models/OptionalFieldsAutoOption.js +35 -0
  91. package/build/generated-sources/api/src/models/Project.d.ts +55 -0
  92. package/build/generated-sources/api/src/models/Project.js +62 -0
  93. package/build/generated-sources/api/src/models/ProjectMembership.d.ts +56 -0
  94. package/build/generated-sources/api/src/models/ProjectMembership.js +63 -0
  95. package/build/generated-sources/api/src/models/ProviderApp.d.ts +67 -0
  96. package/build/generated-sources/api/src/models/ProviderApp.js +67 -0
  97. package/build/generated-sources/api/src/models/Revision.d.ts +50 -0
  98. package/build/generated-sources/api/src/models/Revision.js +60 -0
  99. package/build/generated-sources/api/src/models/UpdateInstallationConfigContent.d.ts +38 -0
  100. package/build/generated-sources/api/src/models/UpdateInstallationConfigContent.js +53 -0
  101. package/build/generated-sources/api/src/models/UpdateInstallationRequest.d.ts +38 -0
  102. package/build/generated-sources/api/src/models/UpdateInstallationRequest.js +54 -0
  103. package/build/generated-sources/api/src/models/UpdateInstallationRequestInstallation.d.ts +38 -0
  104. package/build/generated-sources/api/src/models/UpdateInstallationRequestInstallation.js +53 -0
  105. package/build/generated-sources/api/src/models/UpdateInstallationRequestInstallationConfig.d.ts +44 -0
  106. package/build/generated-sources/api/src/models/UpdateInstallationRequestInstallationConfig.js +55 -0
  107. package/build/generated-sources/api/src/models/UpdateProjectRequest.d.ts +38 -0
  108. package/build/generated-sources/api/src/models/UpdateProjectRequest.js +54 -0
  109. package/build/generated-sources/api/src/models/UpdateProjectRequestProject.d.ts +37 -0
  110. package/build/generated-sources/api/src/models/UpdateProjectRequestProject.js +52 -0
  111. package/build/generated-sources/api/src/models/UpdateProviderAppRequest.d.ts +38 -0
  112. package/build/generated-sources/api/src/models/UpdateProviderAppRequest.js +54 -0
  113. package/build/generated-sources/api/src/models/UpdateProviderAppRequestProviderApp.d.ts +49 -0
  114. package/build/generated-sources/api/src/models/UpdateProviderAppRequestProviderApp.js +56 -0
  115. package/build/generated-sources/api/src/models/UpsertProjectMembershipRequest.d.ts +37 -0
  116. package/build/generated-sources/api/src/models/UpsertProjectMembershipRequest.js +53 -0
  117. package/build/generated-sources/api/src/models/index.d.ts +54 -0
  118. package/build/generated-sources/api/src/models/index.js +72 -0
  119. package/build/generated-sources/api/src/runtime.d.ts +182 -0
  120. package/build/generated-sources/api/src/runtime.js +317 -0
  121. package/build/src/assets/LoadingIcon.d.ts +5 -0
  122. package/build/src/assets/LoadingIcon.js +9 -0
  123. package/build/src/assets/NavIcon.d.ts +1 -0
  124. package/build/src/assets/NavIcon.js +23 -0
  125. package/build/src/components/AmpersandProvider/AmpersandProvider.d.ts +19 -0
  126. package/build/src/components/AmpersandProvider/AmpersandProvider.js +31 -0
  127. package/build/src/components/AmpersandProvider/index.d.ts +1 -0
  128. package/build/src/components/AmpersandProvider/index.js +17 -0
  129. package/build/src/components/CenteredTextBox/CenteredTextBox.d.ts +5 -0
  130. package/build/src/components/CenteredTextBox/CenteredTextBox.js +8 -0
  131. package/build/src/components/Configure/ConfigureInstallationBase.d.ts +8 -0
  132. package/build/src/components/Configure/ConfigureInstallationBase.js +17 -0
  133. package/build/src/components/Configure/CreateInstallation.d.ts +1 -0
  134. package/build/src/components/Configure/CreateInstallation.js +73 -0
  135. package/build/src/components/Configure/ErrorTextBox.d.ts +5 -0
  136. package/build/src/components/Configure/ErrorTextBox.js +9 -0
  137. package/build/src/components/Configure/InstallIntegration.d.ts +9 -0
  138. package/build/src/components/Configure/InstallIntegration.js +40 -0
  139. package/build/src/components/Configure/ObjectManagementNav/NavObjectItem.d.ts +8 -0
  140. package/build/src/components/Configure/ObjectManagementNav/NavObjectItem.js +14 -0
  141. package/build/src/components/Configure/ObjectManagementNav/index.d.ts +9 -0
  142. package/build/src/components/Configure/ObjectManagementNav/index.js +45 -0
  143. package/build/src/components/Configure/ProtectedConnectionLayout.d.ts +6 -0
  144. package/build/src/components/Configure/ProtectedConnectionLayout.js +28 -0
  145. package/build/src/components/Configure/UpdateInstallation.d.ts +7 -0
  146. package/build/src/components/Configure/UpdateInstallation.js +87 -0
  147. package/build/src/components/Configure/actions/onSaveCreate.d.ts +3 -0
  148. package/build/src/components/Configure/actions/onSaveCreate.js +90 -0
  149. package/build/src/components/Configure/actions/onSaveUpdate.d.ts +3 -0
  150. package/build/src/components/Configure/actions/onSaveUpdate.js +74 -0
  151. package/build/src/components/Configure/fields/FieldHeader.d.ts +5 -0
  152. package/build/src/components/Configure/fields/FieldHeader.js +9 -0
  153. package/build/src/components/Configure/fields/FieldMapping.d.ts +10 -0
  154. package/build/src/components/Configure/fields/FieldMapping.js +28 -0
  155. package/build/src/components/Configure/fields/OptionalFields.d.ts +1 -0
  156. package/build/src/components/Configure/fields/OptionalFields.js +45 -0
  157. package/build/src/components/Configure/fields/RequiredFieldMappings.d.ts +1 -0
  158. package/build/src/components/Configure/fields/RequiredFieldMappings.js +40 -0
  159. package/build/src/components/Configure/fields/RequiredFields.d.ts +1 -0
  160. package/build/src/components/Configure/fields/RequiredFields.js +27 -0
  161. package/build/src/components/Configure/index.d.ts +1 -0
  162. package/build/src/components/Configure/index.js +5 -0
  163. package/build/src/components/Configure/state/ConfigurationStateProvider.d.ts +13 -0
  164. package/build/src/components/Configure/state/ConfigurationStateProvider.js +54 -0
  165. package/build/src/components/Configure/state/HydratedRevisionContext.d.ts +14 -0
  166. package/build/src/components/Configure/state/HydratedRevisionContext.js +82 -0
  167. package/build/src/components/Configure/state/utils.d.ts +34 -0
  168. package/build/src/components/Configure/state/utils.js +146 -0
  169. package/build/src/components/Configure/types.d.ts +31 -0
  170. package/build/src/components/Configure/types.js +2 -0
  171. package/build/src/components/Configure/utils.d.ts +24 -0
  172. package/build/src/components/Configure/utils.js +82 -0
  173. package/build/src/components/OAuthPopup/OAuthPopup.d.ts +14 -0
  174. package/build/src/components/OAuthPopup/OAuthPopup.js +85 -0
  175. package/build/src/components/Salesforce/SalesforceOauthFlow.d.ts +16 -0
  176. package/build/src/components/Salesforce/SalesforceOauthFlow.js +78 -0
  177. package/build/src/components/ThemeProvider/index.d.ts +6 -0
  178. package/build/src/components/ThemeProvider/index.js +37 -0
  179. package/build/src/components/index.d.ts +2 -0
  180. package/build/src/components/index.js +18 -0
  181. package/build/src/constants.d.ts +1 -0
  182. package/build/src/constants.js +4 -0
  183. package/build/src/context/ApiKeyContext.d.ts +3 -0
  184. package/build/src/context/ApiKeyContext.js +6 -0
  185. package/build/src/context/ConnectionsContext.d.ts +16 -0
  186. package/build/src/context/ConnectionsContext.js +57 -0
  187. package/build/src/context/ErrorContextProvider.d.ts +37 -0
  188. package/build/src/context/ErrorContextProvider.js +72 -0
  189. package/build/src/context/InstallIntegrationContext.d.ts +24 -0
  190. package/build/src/context/InstallIntegrationContext.js +90 -0
  191. package/build/src/context/IntegrationListContext.d.ts +13 -0
  192. package/build/src/context/IntegrationListContext.js +48 -0
  193. package/build/src/context/ProjectContext.d.ts +15 -0
  194. package/build/src/context/ProjectContext.js +50 -0
  195. package/build/src/hooks/index.d.ts +1 -0
  196. package/build/src/hooks/index.js +17 -0
  197. package/build/src/hooks/useIsIntegrationInstalled.d.ts +6 -0
  198. package/build/src/hooks/useIsIntegrationInstalled.js +48 -0
  199. package/build/src/index.d.ts +2 -0
  200. package/build/src/index.js +18 -0
  201. package/build/src/services/api.d.ts +9 -0
  202. package/build/src/services/api.js +64 -0
  203. package/build/src/utils/index.d.ts +10 -0
  204. package/build/src/utils/index.js +21 -0
  205. package/package.json +80 -0
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const jsx_runtime_1 = require("react/jsx-runtime");
4
+ /**
5
+ * OAuthPopup.tsx
6
+ *
7
+ * Takes a URL and creates a popup showing that page.
8
+ */
9
+ const react_1 = require("react");
10
+ const ApiKeyContext_1 = require("../../context/ApiKeyContext");
11
+ const ConnectionsContext_1 = require("../../context/ConnectionsContext");
12
+ const ProjectContext_1 = require("../../context/ProjectContext");
13
+ const api_1 = require("../../services/api");
14
+ const DEFAULT_WIDTH = 600; // px
15
+ const DEFAULT_HEIGHT = 600; // px
16
+ const DEFAULT_INTERVAL = 500; // ms
17
+ const SUCCESS_EVENT = 'AUTHORIZATION_SUCCEEDED';
18
+ const FAILURE_EVENT = 'AUTHORIZATION_FAILED';
19
+ const createPopup = ({ url, title, }) => {
20
+ const left = window.screenX + (window.outerWidth - DEFAULT_WIDTH) / 2;
21
+ const top = window.screenY + (window.outerHeight - DEFAULT_HEIGHT) / 2.5; // a lil shorter
22
+ const popup = window.open(url, title, `width=${DEFAULT_WIDTH},height=${DEFAULT_HEIGHT},left=${left},top=${top}`);
23
+ return popup;
24
+ };
25
+ function OAuthPopup({ title = '', url, children, onClose, }) {
26
+ const [externalWindow, setExternalWindow] = (0, react_1.useState)();
27
+ const intervalRef = (0, react_1.useRef)();
28
+ const clearTimer = () => window.clearInterval(intervalRef.current);
29
+ const { setSelectedConnection } = (0, ConnectionsContext_1.useConnections)();
30
+ const { projectId } = (0, ProjectContext_1.useProject)();
31
+ const apiKey = (0, react_1.useContext)(ApiKeyContext_1.ApiKeyContext);
32
+ (0, react_1.useEffect)(() => {
33
+ if (url)
34
+ setExternalWindow(createPopup({ url, title }));
35
+ }, [url, title]);
36
+ const refreshConnections = (0, react_1.useCallback)(async (connectionId) => {
37
+ const connection = await (0, api_1.api)().getConnection({ projectId, connectionId }, {
38
+ headers: {
39
+ 'X-Api-Key': apiKey !== null && apiKey !== void 0 ? apiKey : '',
40
+ },
41
+ });
42
+ setSelectedConnection(connection);
43
+ }, [projectId, apiKey, setSelectedConnection]);
44
+ (0, react_1.useEffect)(() => {
45
+ window.addEventListener('message', (event) => {
46
+ var _a, _b, _c, _d, _e;
47
+ if (event.origin === api_1.AMP_SERVER) {
48
+ // this event come from our own server
49
+ if (((_a = event.data) === null || _a === void 0 ? void 0 : _a.eventType) === SUCCESS_EVENT) {
50
+ clearTimer();
51
+ const connectionId = (_b = event.data.data) === null || _b === void 0 ? void 0 : _b.connection;
52
+ if (!connectionId) {
53
+ console.error('Ampersand server returned a successful authorization event, but did not return a connection ID.');
54
+ onClose('There is an unexpected server issue.');
55
+ }
56
+ else {
57
+ refreshConnections(connectionId);
58
+ onClose(null);
59
+ }
60
+ if (externalWindow)
61
+ externalWindow.close();
62
+ }
63
+ else if (((_c = event.data) === null || _c === void 0 ? void 0 : _c.eventType) === FAILURE_EVENT) {
64
+ clearTimer();
65
+ onClose((_e = (_d = event.data.data) === null || _d === void 0 ? void 0 : _d.message) !== null && _e !== void 0 ? _e : 'There was an error logging into your Salesforce subdomain. Please try again.');
66
+ if (externalWindow)
67
+ externalWindow.close();
68
+ }
69
+ }
70
+ });
71
+ }, [externalWindow, onClose, refreshConnections]);
72
+ (0, react_1.useEffect)(() => {
73
+ if (externalWindow && !intervalRef.current) {
74
+ intervalRef.current = window.setInterval(() => {
75
+ // Check if window was closed prematurely.
76
+ if (!externalWindow || externalWindow.closed) {
77
+ clearTimer();
78
+ onClose('The popup was closed too quickly. Please try again.');
79
+ }
80
+ }, DEFAULT_INTERVAL);
81
+ }
82
+ }, [externalWindow, onClose]);
83
+ return ((0, jsx_runtime_1.jsx)("div", { children: children }));
84
+ }
85
+ exports.default = OAuthPopup;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Prompts customer to input their Salesforce subdomain, then creates an OAuth connection to
3
+ * that Salesforce instance.
4
+ */
5
+ interface SalesforceOauthFlowProps {
6
+ consumerRef: string;
7
+ consumerName?: string;
8
+ groupRef: string;
9
+ groupName?: string;
10
+ }
11
+ /**
12
+ * SalesforceOauthFlow first prompts user for their workspace ("subdomain" in Salesforce lingo),
13
+ * then launches a popup with the OAuth flow.
14
+ */
15
+ declare function SalesforceOauthFlow({ consumerRef, consumerName, groupRef, groupName, }: SalesforceOauthFlowProps): import("react/jsx-runtime").JSX.Element;
16
+ export default SalesforceOauthFlow;
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const jsx_runtime_1 = require("react/jsx-runtime");
7
+ /**
8
+ * Prompts customer to input their Salesforce subdomain, then creates an OAuth connection to
9
+ * that Salesforce instance.
10
+ */
11
+ const react_1 = require("react");
12
+ const icons_1 = require("@chakra-ui/icons");
13
+ const react_2 = require("@chakra-ui/react");
14
+ const constants_1 = require("../../constants");
15
+ const ApiKeyContext_1 = require("../../context/ApiKeyContext");
16
+ const ProjectContext_1 = require("../../context/ProjectContext");
17
+ const api_1 = require("../../services/api");
18
+ const OAuthPopup_1 = __importDefault(require("../OAuthPopup/OAuthPopup"));
19
+ function OAuthErrorAlert({ error }) {
20
+ if (error) {
21
+ return ((0, jsx_runtime_1.jsxs)(react_2.Alert, { status: "error", marginTop: "2em", children: [(0, jsx_runtime_1.jsx)(react_2.AlertIcon, {}), (0, jsx_runtime_1.jsx)(react_2.AlertDescription, { children: error })] }));
22
+ }
23
+ return null;
24
+ }
25
+ /**
26
+ * SalesforceOauthFlow first prompts user for their workspace ("subdomain" in Salesforce lingo),
27
+ * then launches a popup with the OAuth flow.
28
+ */
29
+ function SalesforceOauthFlow({ consumerRef, consumerName, groupRef, groupName, }) {
30
+ const [workspace, setWorkspace] = (0, react_1.useState)('');
31
+ const [oAuthCallbackURL, setOAuthCallbackURL] = (0, react_1.useState)(null);
32
+ const [error, setError] = (0, react_1.useState)(null);
33
+ const { projectId } = (0, ProjectContext_1.useProject)();
34
+ const apiKey = (0, react_1.useContext)(ApiKeyContext_1.ApiKeyContext);
35
+ const handleSubmit = async () => {
36
+ var _a;
37
+ setError(null);
38
+ if (workspace) {
39
+ try {
40
+ const providerApps = await (0, api_1.api)().listProviderApps({
41
+ projectId,
42
+ }, {
43
+ headers: {
44
+ 'X-Api-Key': apiKey !== null && apiKey !== void 0 ? apiKey : '',
45
+ },
46
+ });
47
+ const app = providerApps.find((a) => a.provider === constants_1.PROVIDER_SALESFORCE);
48
+ if (!app) {
49
+ throw new Error('You must first set up a Salesforce Connected App using the Ampersand Console.');
50
+ }
51
+ const url = await (0, api_1.api)().oauthConnect({
52
+ connectOAuthParams: {
53
+ providerWorkspaceRef: workspace,
54
+ projectId,
55
+ groupRef,
56
+ groupName,
57
+ consumerRef,
58
+ consumerName,
59
+ providerAppId: app.id,
60
+ provider: constants_1.PROVIDER_SALESFORCE,
61
+ },
62
+ });
63
+ setOAuthCallbackURL(url);
64
+ }
65
+ catch (err) {
66
+ console.error(err);
67
+ setError((_a = err.message) !== null && _a !== void 0 ? _a : 'Unexpected error');
68
+ }
69
+ }
70
+ };
71
+ const onClose = (0, react_1.useCallback)((err) => {
72
+ setError(err);
73
+ setOAuthCallbackURL(null);
74
+ }, []);
75
+ const SubdomainEntry = ((0, jsx_runtime_1.jsx)(react_2.Container, { children: (0, jsx_runtime_1.jsx)(react_2.Box, { p: 8, maxWidth: "600px", borderWidth: 1, borderRadius: 8, boxShadow: "lg", textAlign: ['left'], margin: "auto", marginTop: "40px", bgColor: "white", children: (0, jsx_runtime_1.jsxs)(react_2.FormControl, { children: [(0, jsx_runtime_1.jsx)(react_2.FormLabel, { marginTop: "3em", marginBottom: "0", children: (0, jsx_runtime_1.jsx)(react_2.Heading, { as: "h4", size: "lg", children: "Enter your Salesforce subdomain" }) }), (0, jsx_runtime_1.jsxs)(react_2.Link, { href: "https://help.salesforce.com/s/articleView?id=sf.faq_domain_name_what.htm&type=5", color: "blackAlpha.600", isExternal: true, children: ["What is my Salesforce subdomain?", (0, jsx_runtime_1.jsx)(icons_1.ExternalLinkIcon, { mx: "2px" })] }), (0, jsx_runtime_1.jsx)(OAuthErrorAlert, { error: error }), (0, jsx_runtime_1.jsxs)(react_2.Flex, { marginTop: "1em", children: [(0, jsx_runtime_1.jsx)(react_2.Input, { placeholder: "MyDomain", onChange: (event) => setWorkspace(event.currentTarget.value) }), (0, jsx_runtime_1.jsx)(react_2.Text, { lineHeight: "2.2em", marginLeft: "0.4em", children: ".my.salesforce.com" })] }), (0, jsx_runtime_1.jsx)("br", {}), (0, jsx_runtime_1.jsx)(react_2.Button, { type: "submit", onClick: handleSubmit, children: "Submit" })] }) }) }));
76
+ return ((0, jsx_runtime_1.jsx)(OAuthPopup_1.default, { title: "Connect to Salesforce", url: oAuthCallbackURL, onClose: onClose, children: SubdomainEntry }));
77
+ }
78
+ exports.default = SalesforceOauthFlow;
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ type ThemeProviderProps = {
3
+ children: React.ReactNode;
4
+ };
5
+ export declare function ThemeProvider({ children }: ThemeProviderProps): import("react/jsx-runtime").JSX.Element;
6
+ export {};
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ThemeProvider = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("@chakra-ui/react");
6
+ const customTheme = (0, react_1.extendTheme)({
7
+ components: {
8
+ Tabs: {
9
+ baseStyle: {
10
+ tab: {
11
+ width: '100%',
12
+ borderRadius: '4px',
13
+ _hover: {
14
+ bg: 'gray.300',
15
+ },
16
+ _selected: {
17
+ color: 'black',
18
+ fontWeight: '500',
19
+ bg: 'gray.200',
20
+ border: 'none',
21
+ _hover: {
22
+ bg: 'gray.300',
23
+ },
24
+ },
25
+ },
26
+ },
27
+ },
28
+ },
29
+ });
30
+ const theme = (0, react_1.extendTheme)((0, react_1.withDefaultColorScheme)({
31
+ colorScheme: 'facebook',
32
+ components: ['Button'],
33
+ }), customTheme);
34
+ function ThemeProvider({ children }) {
35
+ return ((0, jsx_runtime_1.jsx)(react_1.ChakraProvider, { theme: theme, children: children }));
36
+ }
37
+ exports.ThemeProvider = ThemeProvider;
@@ -0,0 +1,2 @@
1
+ export * from './AmpersandProvider';
2
+ export * from './Configure';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./AmpersandProvider"), exports);
18
+ __exportStar(require("./Configure"), exports);
@@ -0,0 +1 @@
1
+ export declare const PROVIDER_SALESFORCE = "salesforce";
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PROVIDER_SALESFORCE = void 0;
4
+ exports.PROVIDER_SALESFORCE = 'salesforce';
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ export declare const ApiKeyContext: import("react").Context<string | null>;
3
+ export declare const ApiKeyProvider: import("react").Provider<string | null>;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiKeyProvider = exports.ApiKeyContext = void 0;
4
+ const react_1 = require("react");
5
+ exports.ApiKeyContext = (0, react_1.createContext)(null);
6
+ exports.ApiKeyProvider = exports.ApiKeyContext.Provider;
@@ -0,0 +1,16 @@
1
+ import React from 'react';
2
+ import { Connection } from '../services/api';
3
+ interface ConnectionsContextValue {
4
+ connections: Connection[] | null;
5
+ selectedConnection: Connection | null;
6
+ setConnections: React.Dispatch<React.SetStateAction<Connection[] | null>>;
7
+ setSelectedConnection: React.Dispatch<React.SetStateAction<Connection | null>>;
8
+ }
9
+ export declare const ConnectionsContext: React.Context<ConnectionsContextValue>;
10
+ export declare const useConnections: () => ConnectionsContextValue;
11
+ type ConnectionsProviderProps = {
12
+ projectId: string;
13
+ children?: React.ReactNode;
14
+ };
15
+ export declare function ConnectionsProvider({ projectId, children, }: ConnectionsProviderProps): import("react/jsx-runtime").JSX.Element;
16
+ export {};
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConnectionsProvider = exports.useConnections = exports.ConnectionsContext = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const LoadingIcon_1 = require("../assets/LoadingIcon");
7
+ const ErrorTextBox_1 = require("../components/Configure/ErrorTextBox");
8
+ const api_1 = require("../services/api");
9
+ const ApiKeyContext_1 = require("./ApiKeyContext");
10
+ const ErrorContextProvider_1 = require("./ErrorContextProvider");
11
+ const InstallIntegrationContext_1 = require("./InstallIntegrationContext");
12
+ exports.ConnectionsContext = (0, react_1.createContext)({
13
+ connections: null,
14
+ selectedConnection: null,
15
+ setConnections: () => { },
16
+ setSelectedConnection: () => { },
17
+ });
18
+ const useConnections = () => {
19
+ const context = (0, react_1.useContext)(exports.ConnectionsContext);
20
+ if (!context) {
21
+ throw new Error('useConnections must be used within a ConnectionsListProvider');
22
+ }
23
+ return context;
24
+ };
25
+ exports.useConnections = useConnections;
26
+ function ConnectionsProvider({ projectId, children, }) {
27
+ const { groupRef, provider } = (0, InstallIntegrationContext_1.useInstallIntegrationProps)();
28
+ const [connections, setConnections] = (0, react_1.useState)(null);
29
+ const [selectedConnection, setSelectedConnection] = (0, react_1.useState)(null);
30
+ const apiKey = (0, react_1.useContext)(ApiKeyContext_1.ApiKeyContext);
31
+ const [isLoading, setLoadingState] = (0, react_1.useState)(true);
32
+ const { setError, isError } = (0, ErrorContextProvider_1.useErrorState)();
33
+ (0, react_1.useEffect)(() => {
34
+ (0, api_1.api)().listConnections({ projectId, groupRef, provider }, {
35
+ headers: {
36
+ 'X-Api-Key': apiKey !== null && apiKey !== void 0 ? apiKey : '',
37
+ },
38
+ }).then((_connections) => {
39
+ setLoadingState(false);
40
+ setConnections(_connections);
41
+ }).catch((err) => {
42
+ setLoadingState(false);
43
+ setError(ErrorContextProvider_1.ErrorBoundary.CONNECTION_LIST, projectId);
44
+ console.error(`Error retrieving existing OAuth connections for group ID ${groupRef}:`, err);
45
+ });
46
+ }, [projectId, apiKey, groupRef, provider, setError]);
47
+ const contextValue = (0, react_1.useMemo)(() => ({
48
+ connections,
49
+ selectedConnection,
50
+ setConnections,
51
+ setSelectedConnection,
52
+ }), [connections, selectedConnection, setConnections, setSelectedConnection]);
53
+ return (isError(ErrorContextProvider_1.ErrorBoundary.CONNECTION_LIST, projectId)
54
+ ? (0, jsx_runtime_1.jsx)(ErrorTextBox_1.ErrorTextBox, { message: "Error retrieving existing connections" })
55
+ : ((0, jsx_runtime_1.jsx)(exports.ConnectionsContext.Provider, { value: contextValue, children: isLoading ? (0, jsx_runtime_1.jsx)(LoadingIcon_1.LoadingIcon, {}) : children })));
56
+ }
57
+ exports.ConnectionsProvider = ConnectionsProvider;
@@ -0,0 +1,37 @@
1
+ import React from 'react';
2
+ export declare enum ErrorBoundary {
3
+ MAPPING = "mappingError",
4
+ INTEGRATION_LIST = "integrationListError",
5
+ PROJECT = "projectError",
6
+ CONNECTION_LIST = "connectionListError",
7
+ HYDRATED_REVISION = "hydratedRevisionError",
8
+ INSTALLATION_LIST = "installationListError"
9
+ }
10
+ export type ErrorState = {
11
+ [boundary in ErrorBoundary]: {
12
+ [key: string]: boolean;
13
+ };
14
+ };
15
+ export declare const ErrorContext: React.Context<{
16
+ errorState: ErrorState;
17
+ setErrorState: React.Dispatch<React.SetStateAction<ErrorState>>;
18
+ resetBoundary: (boundary: ErrorBoundary) => void;
19
+ setError: (boundary: ErrorBoundary, key: string) => void;
20
+ isError: (boundary: ErrorBoundary, key: string) => boolean;
21
+ removeError: (boundary: ErrorBoundary, key: string) => void;
22
+ setErrors: (boundary: ErrorBoundary, keys: string[]) => void;
23
+ } | undefined>;
24
+ export declare function useErrorState(): {
25
+ errorState: ErrorState;
26
+ setErrorState: React.Dispatch<React.SetStateAction<ErrorState>>;
27
+ resetBoundary: (boundary: ErrorBoundary) => void;
28
+ setError: (boundary: ErrorBoundary, key: string) => void;
29
+ isError: (boundary: ErrorBoundary, key: string) => boolean;
30
+ removeError: (boundary: ErrorBoundary, key: string) => void;
31
+ setErrors: (boundary: ErrorBoundary, keys: string[]) => void;
32
+ };
33
+ type ErrorProviderProps = {
34
+ children: React.ReactNode;
35
+ };
36
+ export declare function ErrorStateProvider({ children }: ErrorProviderProps): import("react/jsx-runtime").JSX.Element;
37
+ export {};
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ErrorStateProvider = exports.useErrorState = exports.ErrorContext = exports.ErrorBoundary = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ var ErrorBoundary;
7
+ (function (ErrorBoundary) {
8
+ ErrorBoundary["MAPPING"] = "mappingError";
9
+ ErrorBoundary["INTEGRATION_LIST"] = "integrationListError";
10
+ ErrorBoundary["PROJECT"] = "projectError";
11
+ ErrorBoundary["CONNECTION_LIST"] = "connectionListError";
12
+ ErrorBoundary["HYDRATED_REVISION"] = "hydratedRevisionError";
13
+ ErrorBoundary["INSTALLATION_LIST"] = "installationListError";
14
+ })(ErrorBoundary || (exports.ErrorBoundary = ErrorBoundary = {}));
15
+ exports.ErrorContext = (0, react_1.createContext)(undefined);
16
+ function useErrorState() {
17
+ const context = (0, react_1.useContext)(exports.ErrorContext);
18
+ if (!context) {
19
+ throw new Error('useErrorState must be used within a ErrorProvider');
20
+ }
21
+ return context;
22
+ }
23
+ exports.useErrorState = useErrorState;
24
+ const initialState = (() => {
25
+ const obj = {};
26
+ Object.values(ErrorBoundary).forEach((key) => {
27
+ obj[key] = {};
28
+ });
29
+ return obj;
30
+ })();
31
+ function ErrorStateProvider({ children }) {
32
+ const [errorState, setErrorState] = (0, react_1.useState)(initialState);
33
+ const setError = (0, react_1.useCallback)((boundary, key) => {
34
+ setErrorState((prevState) => {
35
+ const newErrorState = Object.assign({}, prevState);
36
+ newErrorState[boundary] = newErrorState[boundary] || {};
37
+ newErrorState[boundary][key] = true;
38
+ return newErrorState;
39
+ });
40
+ }, [setErrorState]);
41
+ const isError = (0, react_1.useCallback)((boundary, key) => { var _a; return !!((_a = errorState[boundary]) === null || _a === void 0 ? void 0 : _a[key]); }, [errorState]);
42
+ const removeError = (0, react_1.useCallback)((boundary, key) => {
43
+ setErrorState((prevState) => {
44
+ var _a;
45
+ const newErrorState = Object.assign({}, prevState);
46
+ (_a = newErrorState[boundary]) === null || _a === void 0 ? true : delete _a[key];
47
+ return newErrorState;
48
+ });
49
+ }, [setErrorState]);
50
+ const resetBoundary = (0, react_1.useCallback)((boundary) => {
51
+ setErrorState((prevState) => {
52
+ const newErrorState = Object.assign({}, prevState);
53
+ newErrorState[boundary] = {};
54
+ return newErrorState;
55
+ });
56
+ }, [setErrorState]);
57
+ const setErrors = (0, react_1.useCallback)((boundary, keys) => {
58
+ setErrorState((prevState) => {
59
+ const newErrorState = Object.assign({}, prevState);
60
+ newErrorState[boundary] = newErrorState[boundary] || {};
61
+ keys.forEach((key) => {
62
+ newErrorState[boundary][key] = true;
63
+ });
64
+ return newErrorState;
65
+ });
66
+ }, [setErrorState]);
67
+ const contextValue = (0, react_1.useMemo)(() => ({
68
+ errorState, setErrorState, setError, isError, removeError, resetBoundary, setErrors,
69
+ }), [errorState, setErrorState, setError, isError, removeError, resetBoundary, setErrors]);
70
+ return ((0, jsx_runtime_1.jsx)(exports.ErrorContext.Provider, { value: contextValue, children: children }));
71
+ }
72
+ exports.ErrorStateProvider = ErrorStateProvider;
@@ -0,0 +1,24 @@
1
+ /// <reference types="react" />
2
+ import { Installation, Integration } from '../services/api';
3
+ interface InstallIntegrationContextValue {
4
+ integrationId: string;
5
+ provider: string;
6
+ integrationObj?: Integration | null;
7
+ consumerRef: string;
8
+ consumerName?: string;
9
+ groupRef: string;
10
+ groupName?: string;
11
+ installation?: Installation;
12
+ setInstallation: (installationObj: Installation) => void;
13
+ }
14
+ export declare function useInstallIntegrationProps(): InstallIntegrationContextValue;
15
+ interface InstallIntegrationProviderProps {
16
+ integration: string;
17
+ consumerRef: string;
18
+ consumerName?: string;
19
+ groupRef: string;
20
+ groupName?: string;
21
+ children: React.ReactNode;
22
+ }
23
+ export declare function InstallIntegrationProvider({ children, integration, consumerRef, consumerName, groupRef, groupName, }: InstallIntegrationProviderProps): import("react/jsx-runtime").JSX.Element;
24
+ export {};
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InstallIntegrationProvider = exports.useInstallIntegrationProps = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const LoadingIcon_1 = require("../assets/LoadingIcon");
7
+ const ErrorTextBox_1 = require("../components/Configure/ErrorTextBox");
8
+ const api_1 = require("../services/api");
9
+ const utils_1 = require("../utils");
10
+ const ApiKeyContext_1 = require("./ApiKeyContext");
11
+ const ErrorContextProvider_1 = require("./ErrorContextProvider");
12
+ const IntegrationListContext_1 = require("./IntegrationListContext");
13
+ const ProjectContext_1 = require("./ProjectContext");
14
+ // Create a context to pass down the props
15
+ const InstallIntegrationContext = (0, react_1.createContext)({
16
+ integrationId: '',
17
+ provider: '',
18
+ integrationObj: undefined,
19
+ consumerRef: '',
20
+ consumerName: '',
21
+ groupRef: '',
22
+ groupName: '',
23
+ installation: undefined,
24
+ setInstallation: () => { },
25
+ });
26
+ // Create a custom hook to access the props
27
+ function useInstallIntegrationProps() {
28
+ const context = (0, react_1.useContext)(InstallIntegrationContext);
29
+ if (!context) {
30
+ throw new Error('useInstallIntegrationProps must be used within an InstallIntegrationProvider');
31
+ }
32
+ return context;
33
+ }
34
+ exports.useInstallIntegrationProps = useInstallIntegrationProps;
35
+ // Wrap your parent component with the context provider
36
+ function InstallIntegrationProvider({ children, integration, consumerRef, consumerName, groupRef, groupName, }) {
37
+ const { projectId } = (0, ProjectContext_1.useProject)();
38
+ const [installations, setInstallations] = (0, react_1.useState)([]);
39
+ const installation = (installations === null || installations === void 0 ? void 0 : installations[0]) || null; // there should only be one installation for mvp
40
+ const apiKey = (0, react_1.useContext)(ApiKeyContext_1.ApiKeyContext);
41
+ const { integrations } = (0, IntegrationListContext_1.useIntegrationList)();
42
+ const integrationObj = (0, react_1.useMemo)(() => (0, utils_1.findIntegrationFromList)(integration, integrations || []), [integration, integrations]);
43
+ const [isLoading, setLoadingState] = (0, react_1.useState)(true);
44
+ const { setError, isError } = (0, ErrorContextProvider_1.useErrorState)();
45
+ (0, react_1.useEffect)(() => {
46
+ if (integrationObj === null && (integrations === null || integrations === void 0 ? void 0 : integrations.length)) {
47
+ console.error(`Integration "${integration}" not found in integration list`);
48
+ }
49
+ }, [integration, integrationObj, integrations]);
50
+ // default set the installations array with a single installation object
51
+ // may need to find and update the installation object in the future
52
+ const setInstallation = (0, react_1.useCallback)((installationObj) => {
53
+ setInstallations([installationObj]);
54
+ }, [setInstallations]);
55
+ const integrationErrorKey = (integrationObj === null || integrationObj === void 0 ? void 0 : integrationObj.id) || '';
56
+ // check if integration has been installed in AmpersandProvider
57
+ (0, react_1.useEffect)(() => {
58
+ if (integrationObj === null || integrationObj === void 0 ? void 0 : integrationObj.id) {
59
+ // check if installation exists on selected integration
60
+ (0, api_1.api)().listInstallations({ projectId, integrationId: integrationObj.id, groupRef }, {
61
+ headers: {
62
+ 'X-Api-Key': apiKey !== null && apiKey !== void 0 ? apiKey : '',
63
+ },
64
+ })
65
+ .then((_installations) => {
66
+ setLoadingState(false);
67
+ setInstallations(_installations || []);
68
+ })
69
+ .catch((err) => {
70
+ setError(ErrorContextProvider_1.ErrorBoundary.INSTALLATION_LIST, integrationObj.id);
71
+ setLoadingState(false);
72
+ console.error('Error retrieving installation information: ', err);
73
+ });
74
+ }
75
+ }, [projectId, integrationObj === null || integrationObj === void 0 ? void 0 : integrationObj.id, apiKey, groupRef, setError]);
76
+ const props = (0, react_1.useMemo)(() => ({
77
+ integrationId: (integrationObj === null || integrationObj === void 0 ? void 0 : integrationObj.id) || '',
78
+ provider: (integrationObj === null || integrationObj === void 0 ? void 0 : integrationObj.provider) || '',
79
+ integrationObj,
80
+ consumerRef,
81
+ consumerName,
82
+ groupRef,
83
+ groupName,
84
+ installation,
85
+ setInstallation,
86
+ }), [integrationObj, consumerRef, consumerName, groupRef,
87
+ groupName, installation, setInstallation]);
88
+ return (isError(ErrorContextProvider_1.ErrorBoundary.INSTALLATION_LIST, integrationErrorKey)) ? (0, jsx_runtime_1.jsx)(ErrorTextBox_1.ErrorTextBox, { message: `Error retrieving installation information for integration "${(integrationObj === null || integrationObj === void 0 ? void 0 : integrationObj.name) || 'unknown'}"` }) : ((0, jsx_runtime_1.jsx)(InstallIntegrationContext.Provider, { value: props, children: isLoading ? (0, jsx_runtime_1.jsx)(LoadingIcon_1.LoadingIcon, {}) : children }));
89
+ }
90
+ exports.InstallIntegrationProvider = InstallIntegrationProvider;
@@ -0,0 +1,13 @@
1
+ /// <reference types="react" />
2
+ import { Integration } from '../services/api';
3
+ interface IntegrationListContextValue {
4
+ integrations: Integration[] | null;
5
+ }
6
+ export declare const IntegrationListContext: import("react").Context<IntegrationListContextValue>;
7
+ export declare const useIntegrationList: () => IntegrationListContextValue;
8
+ type IntegrationListContextProviderProps = {
9
+ projectId: string;
10
+ children?: React.ReactNode;
11
+ };
12
+ export declare function IntegrationListProvider({ projectId, children }: IntegrationListContextProviderProps): import("react/jsx-runtime").JSX.Element;
13
+ export {};
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IntegrationListProvider = exports.useIntegrationList = exports.IntegrationListContext = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const LoadingIcon_1 = require("../assets/LoadingIcon");
7
+ const ErrorTextBox_1 = require("../components/Configure/ErrorTextBox");
8
+ const api_1 = require("../services/api");
9
+ const ApiKeyContext_1 = require("./ApiKeyContext");
10
+ const ErrorContextProvider_1 = require("./ErrorContextProvider");
11
+ exports.IntegrationListContext = (0, react_1.createContext)({
12
+ integrations: null,
13
+ });
14
+ const useIntegrationList = () => {
15
+ const context = (0, react_1.useContext)(exports.IntegrationListContext);
16
+ if (!context) {
17
+ throw new Error('useIntegrationList must be used within a IntegrationListProvider');
18
+ }
19
+ return context;
20
+ };
21
+ exports.useIntegrationList = useIntegrationList;
22
+ function IntegrationListProvider({ projectId, children }) {
23
+ const [integrations, setIntegrations] = (0, react_1.useState)(null);
24
+ const apiKey = (0, react_1.useContext)(ApiKeyContext_1.ApiKeyContext);
25
+ const { setError, isError } = (0, ErrorContextProvider_1.useErrorState)();
26
+ const [isLoading, setLoadingState] = (0, react_1.useState)(true);
27
+ (0, react_1.useEffect)(() => {
28
+ (0, api_1.api)().listIntegrations({ projectId }, {
29
+ headers: {
30
+ 'X-Api-Key': apiKey !== null && apiKey !== void 0 ? apiKey : '',
31
+ },
32
+ }).then((_integrations) => {
33
+ setLoadingState(false);
34
+ setIntegrations(_integrations || []);
35
+ }).catch((err) => {
36
+ setLoadingState(false);
37
+ setError(ErrorContextProvider_1.ErrorBoundary.INTEGRATION_LIST, projectId);
38
+ console.error('Error retrieving integration information for : ', err);
39
+ });
40
+ }, [projectId, apiKey, setError]);
41
+ const contextValue = (0, react_1.useMemo)(() => ({
42
+ integrations,
43
+ }), [integrations]);
44
+ return (isError(ErrorContextProvider_1.ErrorBoundary.INTEGRATION_LIST, projectId)
45
+ ? (0, jsx_runtime_1.jsx)(ErrorTextBox_1.ErrorTextBox, { message: "Error retrieving integrations for the project, double check the API key" })
46
+ : ((0, jsx_runtime_1.jsx)(exports.IntegrationListContext.Provider, { value: contextValue, children: isLoading ? (0, jsx_runtime_1.jsx)(LoadingIcon_1.LoadingIcon, {}) : children })));
47
+ }
48
+ exports.IntegrationListProvider = IntegrationListProvider;
@@ -0,0 +1,15 @@
1
+ /// <reference types="react" />
2
+ import { Project } from '../services/api';
3
+ interface ProjectContextValue {
4
+ project: Project | null;
5
+ appName: string;
6
+ projectId: string;
7
+ }
8
+ export declare const ProjectContext: import("react").Context<ProjectContextValue>;
9
+ export declare const useProject: () => ProjectContextValue;
10
+ type ProjectProviderProps = {
11
+ projectId: string;
12
+ children?: React.ReactNode;
13
+ };
14
+ export declare function ProjectProvider({ projectId, children }: ProjectProviderProps): import("react/jsx-runtime").JSX.Element;
15
+ export {};