@integration-app/react 0.2.0 → 0.3.1

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 (57) hide show
  1. package/README.md +49 -34
  2. package/dist/index.d.ts +377 -160
  3. package/dist/index.js +517 -226
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.module.d.ts +377 -160
  6. package/dist/index.module.mjs +506 -227
  7. package/dist/index.module.mjs.map +1 -1
  8. package/dist/index.umd.d.ts +377 -160
  9. package/dist/index.umd.js +517 -230
  10. package/dist/index.umd.js.map +1 -1
  11. package/package.json +16 -9
  12. package/src/actions/useAction.ts +35 -0
  13. package/src/actions/useActionInstance.ts +56 -0
  14. package/src/actions/useActionInstances.ts +11 -0
  15. package/src/actions/useActions.ts +11 -0
  16. package/src/app-events/useAppEventSubscription.ts +6 -6
  17. package/src/app-events/useAppEventSubscriptions.ts +5 -4
  18. package/src/app-events/useAppEventType.ts +10 -7
  19. package/src/app-events/useAppEventTypes.ts +2 -4
  20. package/src/app-events/useAppEvents.ts +2 -4
  21. package/src/contexts/index.tsx +4 -0
  22. package/src/contexts/integration-app-context.tsx +11 -2
  23. package/src/data-collections/useDataCollectionSpec.ts +26 -0
  24. package/src/data-links/useDataLinkTable.ts +18 -0
  25. package/src/data-links/useDataLinkTableInstance.ts +39 -0
  26. package/src/data-links/useDataLinkTableInstances.ts +19 -0
  27. package/src/data-links/useDataLinkTables.ts +11 -0
  28. package/src/data-sources/useDataSource.ts +29 -6
  29. package/src/data-sources/useDataSourceEvents.ts +2 -4
  30. package/src/data-sources/useDataSourceInstance.ts +120 -26
  31. package/src/data-sources/useDataSourceInstanceCollection.ts +14 -4
  32. package/src/data-sources/useDataSourceInstanceLocations.ts +17 -6
  33. package/src/data-sources/useDataSourceInstances.ts +17 -0
  34. package/src/data-sources/useDataSources.ts +2 -4
  35. package/src/field-mappings/useFieldMapping.ts +29 -8
  36. package/src/field-mappings/useFieldMappingInstance.ts +37 -14
  37. package/src/field-mappings/useFieldMappingInstances.ts +6 -5
  38. package/src/field-mappings/useFieldMappings.ts +2 -4
  39. package/src/flows/useFlow.ts +28 -6
  40. package/src/flows/useFlowInstance.ts +62 -5
  41. package/src/flows/useFlowInstances.ts +2 -4
  42. package/src/flows/useFlowRun.ts +18 -6
  43. package/src/flows/useFlowRuns.ts +5 -5
  44. package/src/flows/useFlows.ts +5 -5
  45. package/src/hooks/useElement.tsx +142 -136
  46. package/src/hooks/useElements.tsx +44 -73
  47. package/src/hooks/useIntegrationAppSWR.tsx +13 -0
  48. package/src/index.tsx +29 -16
  49. package/src/integrations/useConnection.ts +14 -5
  50. package/src/integrations/useConnections.ts +3 -4
  51. package/src/integrations/useConnectorSpec.ts +14 -0
  52. package/src/integrations/useIntegration.ts +11 -7
  53. package/src/integrations/useIntegrations.ts +3 -4
  54. package/src/screens/useScreen.ts +19 -0
  55. package/rollup.config.mjs +0 -64
  56. package/src/hooks/useGetter.tsx +0 -38
  57. package/src/integrations/useConnectionSpec.ts +0 -25
package/dist/index.umd.js CHANGED
@@ -1,379 +1,654 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react/jsx-runtime'), require('@integration-app/sdk'), require('react')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'react/jsx-runtime', '@integration-app/sdk', 'react'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.integrationAppReact = {}, global.jsxRuntime, global.sdk, global.react));
5
- })(this, (function (exports, jsxRuntime, sdk, react) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react/jsx-runtime'), require('@integration-app/sdk'), require('react'), require('swr'), require('awesome-debounce-promise'), require('swr/infinite'), require('query-string')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'react/jsx-runtime', '@integration-app/sdk', 'react', 'swr', 'awesome-debounce-promise', 'swr/infinite', 'query-string'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.integrationAppReact = {}, global.jsxRuntime, global.sdk, global.react, global.useSWR, global.AwesomeDebouncePromise, global.useSWRInfinite, global.qs));
5
+ })(this, (function (exports, jsxRuntime, sdk, react, useSWR, AwesomeDebouncePromise, useSWRInfinite, qs) { 'use strict';
6
6
 
7
7
  const IntegrationAppContext = react.createContext(null);
8
8
  IntegrationAppContext.displayName = 'IntegrationAppClientContext';
9
- const IntegrationAppProvider = ({ token, apiUri = null, uiUri = null, children, }) => {
9
+ const IntegrationAppProvider = ({ token, fetchToken, credentials, fetchCredentials, apiUri = null, uiUri = null, children, }) => {
10
10
  const client = react.useMemo(() => new sdk.IntegrationAppClient({
11
11
  token,
12
+ fetchToken,
13
+ credentials,
14
+ fetchCredentials,
12
15
  apiUri,
13
16
  uiUri,
14
- }), [token, apiUri, uiUri]);
17
+ }), [token, JSON.stringify(credentials), apiUri, uiUri]);
15
18
  return (jsxRuntime.jsx(IntegrationAppContext.Provider, { value: client, children: children }));
16
19
  };
17
20
  function useIntegrationApp() {
18
21
  return react.useContext(IntegrationAppContext);
19
22
  }
20
23
 
21
- function useConnectorSpec(integrationKey) {
22
- const integrationApp = useIntegrationApp();
23
- const [data, setData] = react.useState(null);
24
- const [loading, setLoading] = react.useState(true);
25
- const [error, setError] = react.useState(null);
26
- react.useEffect(() => {
27
- if (!integrationApp) {
28
- return;
29
- }
30
- integrationApp
31
- .integration(integrationKey)
32
- .getConnectorSpec()
33
- .then(setData)
34
- .catch(setError)
35
- .finally(() => setLoading(false));
36
- }, [integrationApp, integrationKey]);
37
- return { data, loading, error };
24
+ function useIntegrationAppSWR(path, options) {
25
+ const client = useIntegrationApp();
26
+ const fetcher = async () => {
27
+ const response = await client.get(path, options);
28
+ return response;
29
+ };
30
+ return useSWR(client ? path : undefined, fetcher, options);
38
31
  }
39
32
 
40
- function useElement(props, accessorGenerator) {
33
+ const elementStateCache = new Map();
34
+ function useElement(selector, accessorGenerator) {
41
35
  const integrationApp = useIntegrationApp();
42
- const [data, setData] = react.useState();
43
- const [loading, setLoading] = react.useState(true);
44
- const [error, setError] = react.useState(null);
45
- const [refreshCounter, setRefreshCounter] = react.useState(0);
46
- const selector = (props === null || props === void 0 ? void 0 : props.id)
47
- ? props.id
48
- : props;
49
- const accessor = integrationApp
50
- ? accessorGenerator(integrationApp)(selector)
51
- : null;
52
- react.useEffect(() => {
53
- setLoading(true);
54
- setError(null);
55
- if (integrationApp) {
56
- accessor
57
- .get()
58
- .then(setData)
59
- .catch(setError)
60
- .finally(() => setLoading(false));
61
- }
62
- else {
63
- setError(new Error('IntegrationApp not found. Was this component wrapped in <IntegrationAppProvider>?'));
64
- }
65
- }, [integrationApp, JSON.stringify(props), refreshCounter]);
66
- async function create(createData) {
67
- if (data !== undefined) {
68
- setData({
69
- ...data,
70
- ...createData,
71
- });
72
- }
73
- return accessorGenerator(integrationApp)(selector).create(createData);
74
- }
75
- function refresh() {
76
- setRefreshCounter(refreshCounter + 1);
77
- }
78
- async function patch(patch) {
79
- if (typeof patch === 'object') {
80
- setData({
81
- ...data,
82
- ...(patch !== null && patch !== void 0 ? patch : {}),
83
- });
84
- return accessorGenerator(integrationApp)(selector).patch(patch);
85
- }
86
- else {
87
- return data;
88
- }
36
+ const elementKeyData = {
37
+ token: integrationApp.token,
38
+ selector,
39
+ };
40
+ const elementKey = JSON.stringify(elementKeyData);
41
+ if (!elementStateCache.has(elementKey)) {
42
+ elementStateCache.set(elementKey, {
43
+ updatedLocally: false,
44
+ savingToServer: false,
45
+ debouncedPut: AwesomeDebouncePromise(async (data) => {
46
+ elementState.updatedLocally = false;
47
+ elementState.savingToServer = true;
48
+ try {
49
+ const result = await (accessor === null || accessor === void 0 ? void 0 : accessor.put(data));
50
+ if (!elementState.updatedLocally) {
51
+ elementState.savingToServer = false;
52
+ await mutate(result, false);
53
+ }
54
+ }
55
+ catch (e) {
56
+ elementState.updatedLocally = true;
57
+ throw e;
58
+ }
59
+ finally {
60
+ elementState.savingToServer = false;
61
+ }
62
+ }, 500),
63
+ });
89
64
  }
90
- async function put(putData) {
91
- if (data !== undefined) {
92
- setData({
93
- ...data,
94
- ...putData,
95
- });
65
+ const elementState = elementStateCache.get(elementKey);
66
+ const accessor = integrationApp ? accessorGenerator(integrationApp) : null;
67
+ const swrKey = accessor && selector ? `element:${elementKey}` : null;
68
+ const { data: item, mutate, error, isLoading, isValidating, } = useSWR(swrKey, () => accessor === null || accessor === void 0 ? void 0 : accessor.get(), {
69
+ isPaused: () => elementState.updatedLocally || elementState.savingToServer,
70
+ });
71
+ const loading = isLoading;
72
+ const refreshing = isValidating;
73
+ async function refresh() {
74
+ return await mutate();
75
+ }
76
+ async function put(data) {
77
+ if (!(accessor === null || accessor === void 0 ? void 0 : accessor.put)) {
78
+ throw new Error(`"put method is not supported for accessor ${accessor.constructor.name}`);
96
79
  }
97
- return accessorGenerator(integrationApp)(selector).put(putData);
80
+ elementState.updatedLocally = true;
81
+ const newLocalData = {
82
+ ...item,
83
+ ...data,
84
+ };
85
+ await mutate(newLocalData, false);
86
+ await elementState.debouncedPut(data);
87
+ }
88
+ async function patch(data) {
89
+ const newData = {
90
+ ...item,
91
+ ...data,
92
+ };
93
+ return put(newData);
98
94
  }
99
95
  async function archive() {
100
- setData(null);
101
- return accessorGenerator(integrationApp)(selector).archive();
96
+ if (!(accessor === null || accessor === void 0 ? void 0 : accessor.archive)) {
97
+ return;
98
+ }
99
+ await mutate({ ...item, archivedAt: new Date().toISOString() }, false);
100
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.archive());
101
+ await mutate();
102
+ }
103
+ async function create(data) {
104
+ if (!(accessor === null || accessor === void 0 ? void 0 : accessor.create)) {
105
+ throw new Error(`"create method is not supported for accessor ${accessor.constructor.name}`);
106
+ }
107
+ const result = await (accessor === null || accessor === void 0 ? void 0 : accessor.create(data));
108
+ return await mutate(result);
102
109
  }
103
110
  return {
104
- data,
111
+ accessor,
112
+ item,
113
+ loading,
114
+ saving: elementState.updatedLocally || elementState.savingToServer,
115
+ error,
116
+ refresh,
117
+ refreshing,
105
118
  create,
106
119
  patch,
107
120
  put,
108
121
  archive,
109
- refresh,
110
- loading,
111
- error,
112
- accessor,
113
122
  };
114
123
  }
115
124
 
116
- function useIntegration(idOrKey) {
117
- const { data: integration, ...rest } = useElement(idOrKey, (integrationApp) => integrationApp.integration.bind(integrationApp));
118
- return { integration, ...rest };
125
+ function useConnection(id) {
126
+ const { item: connection, ...rest } = useElement(id, (integrationApp) => integrationApp.connection(id));
127
+ return {
128
+ connection,
129
+ ...rest,
130
+ };
119
131
  }
120
132
 
121
- function useElements(initialQuery, accessorGenerator) {
133
+ const LIMIT = 25;
134
+ function useElements(route, query = {}) {
122
135
  const integrationApp = useIntegrationApp();
123
- const refreshId = react.useRef(0);
124
- const [items, setItems] = react.useState([]);
125
- const [nextCursor, setNextCursor] = react.useState(undefined);
126
- const [loading, setLoading] = react.useState(false);
127
- const [error, setError] = react.useState(null);
136
+ function getKey(page, previousPageData) {
137
+ var _a;
138
+ if (page === 0)
139
+ return `/${route}?${qs.stringify({
140
+ ...query,
141
+ limit: LIMIT,
142
+ })}`;
143
+ if (((_a = previousPageData.items) === null || _a === void 0 ? void 0 : _a.length) < LIMIT)
144
+ return null;
145
+ return `/${route}?${qs.stringify({
146
+ ...query,
147
+ limit: LIMIT,
148
+ cursor: previousPageData.cursor,
149
+ })}`;
150
+ }
151
+ const [loadingMore, setIsLoadingMore] = react.useState(false);
152
+ const { data, size, setSize, isLoading, error, mutate, isValidating } = useSWRInfinite(getKey, (url) => integrationApp.get(url));
153
+ const items = data ? data.map((page) => page.items).flat() : [];
154
+ const loading = isLoading;
155
+ const refreshing = isValidating;
128
156
  async function loadMore() {
129
- const startingRefreshId = refreshId.current;
130
- const isFirstPage = !nextCursor;
131
- function setStateIfCurrentRefresh(stateSetter, valueGetter) {
132
- stateSetter((value) => startingRefreshId === refreshId.current ? valueGetter(value) : value);
133
- }
134
- setStateIfCurrentRefresh(setError, () => null);
135
- setStateIfCurrentRefresh(setLoading, () => true);
136
- const queryParams = {
137
- ...initialQuery,
138
- };
139
- if (nextCursor)
140
- queryParams.cursor = nextCursor;
141
- try {
142
- const data = await accessorGenerator(integrationApp).find(queryParams);
143
- setStateIfCurrentRefresh(setNextCursor, () => data.cursor);
144
- setStateIfCurrentRefresh(setItems, (items) => isFirstPage ? data.items : [...items, ...data.items]);
145
- }
146
- catch (e) {
147
- setStateIfCurrentRefresh(setError, () => e);
148
- }
149
- finally {
150
- setStateIfCurrentRefresh(setLoading, () => false);
157
+ var _a, _b;
158
+ const hasMoreToLoad = ((_b = (_a = data[size - 1]) === null || _a === void 0 ? void 0 : _a.items) === null || _b === void 0 ? void 0 : _b.length) === LIMIT;
159
+ if (hasMoreToLoad) {
160
+ setIsLoadingMore(true);
161
+ await setSize(size + 1);
162
+ setIsLoadingMore(false);
151
163
  }
152
164
  }
153
- react.useEffect(() => {
154
- if (!integrationApp) {
155
- setError(new Error('IntegrationApp not found. Was this component wrapped in <IntegrationAppProvider>?'));
156
- return;
157
- }
158
- refresh();
159
- }, [integrationApp, JSON.stringify(initialQuery)]);
160
165
  async function refresh() {
161
- refreshId.current += 1;
162
- setNextCursor(undefined);
163
- await loadMore();
166
+ await mutate();
164
167
  }
165
168
  return {
166
169
  items,
167
170
  refresh,
171
+ refreshing,
168
172
  loadMore,
173
+ loadingMore,
169
174
  loading,
170
175
  error,
171
176
  };
172
177
  }
173
178
 
174
- function useIntegrations(query) {
175
- const { ...rest } = useElements(query, (integrationApp) => integrationApp.integrations);
179
+ function useConnections(query) {
180
+ const { ...rest } = useElements('connections', query);
176
181
  return {
182
+ connections: rest.items,
177
183
  ...rest,
178
184
  };
179
185
  }
180
186
 
181
- function useConnection(id) {
182
- const { data: connection, ...rest } = useElement(id, (integrationApp) => integrationApp.connection.bind(integrationApp));
183
- return { connection, ...rest };
187
+ function useConnectorSpec(integrationIdOrKey) {
188
+ const integrationApp = useIntegrationApp();
189
+ const { data, isLoading, error } = useSWR(`/integrations/${integrationIdOrKey}/connector-spec`, () => integrationApp.integration(integrationIdOrKey).getConnectorSpec());
190
+ return { data, loading: isLoading, error };
184
191
  }
185
192
 
186
- function useConnections(query) {
187
- const { ...rest } = useElements(query, (integrationApp) => integrationApp.connections);
193
+ function useIntegration(id) {
194
+ const { item: integration, ...rest } = useElement(id, (integrationApp) => integrationApp.integration(id));
195
+ return { integration, ...rest };
196
+ }
197
+
198
+ function useIntegrations(query) {
199
+ const { ...rest } = useElements('integrations', query);
188
200
  return {
201
+ integrations: rest.items,
189
202
  ...rest,
190
203
  };
191
204
  }
192
205
 
193
- function useFieldMapping(idOrKey) {
194
- const { data: fieldMapping, ...rest } = useElement(idOrKey, (integrationApp) => integrationApp.fieldMapping.bind(integrationApp));
195
- return { fieldMapping, ...rest };
206
+ function useFieldMapping(selector) {
207
+ const { item: fieldMapping, accessor, refresh, ...rest } = useElement(selector, (integrationApp) => integrationApp.fieldMapping(selector));
208
+ async function apply(integrationKeys) {
209
+ const result = await (accessor === null || accessor === void 0 ? void 0 : accessor.apply(integrationKeys));
210
+ await refresh();
211
+ return result;
212
+ }
213
+ async function reset() {
214
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.reset());
215
+ await refresh();
216
+ }
217
+ return { fieldMapping, apply, reset, refresh, accessor, ...rest };
196
218
  }
197
219
 
198
- function useFieldMappings(query) {
199
- const { ...rest } = useElements(query, (integrationApp) => integrationApp.fieldMappings);
220
+ function useFieldMappingInstance(selector) {
221
+ const { item: fieldMappingInstance, accessor, refresh, ...rest } = useElement(selector, (integrationApp) => integrationApp.fieldMappingInstance(selector));
222
+ async function setup() {
223
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.setup());
224
+ await refresh();
225
+ }
226
+ async function reset() {
227
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.reset());
228
+ await refresh();
229
+ }
230
+ async function openConfiguration(options) {
231
+ return accessor === null || accessor === void 0 ? void 0 : accessor.openConfiguration(options);
232
+ }
200
233
  return {
234
+ fieldMappingInstance,
235
+ accessor,
236
+ refresh,
237
+ setup,
238
+ reset,
239
+ openConfiguration,
201
240
  ...rest,
202
241
  };
203
242
  }
204
243
 
205
- function useFieldMappingInstance(selector) {
206
- const { data: fieldMappingInstance, ...rest } = useElement(selector, (integrationApp) => integrationApp.fieldMappingInstance.bind(integrationApp));
207
- const accessor = rest.accessor;
244
+ function useFieldMappingInstances(query) {
245
+ const { ...rest } = useElements('field-mapping-instances', query);
208
246
  return {
209
- fieldMappingInstance,
210
- setup: () => accessor.setup(),
211
- reset: () => accessor.reset(),
212
- openConfiguration: (options) => accessor.openConfiguration(options),
247
+ fieldMappingInstances: rest.items,
213
248
  ...rest,
214
249
  };
215
250
  }
216
251
 
217
- function useFieldMappingInstances(query) {
218
- const { ...rest } = useElements(query, (integrationApp) => integrationApp.fieldMappingInstances);
252
+ function useFieldMappings(query) {
253
+ const { ...rest } = useElements('field-mappings', query);
219
254
  return {
255
+ fieldMappings: rest.items,
220
256
  ...rest,
221
257
  };
222
258
  }
223
259
 
224
- function useDataSource(idOrKey) {
225
- const { data: dataSource, ...rest } = useElement(idOrKey, (integrationApp) => integrationApp.dataSource.bind(integrationApp));
226
- return { dataSource, ...rest };
260
+ function useDataSource(selector) {
261
+ const { item: dataSource, refresh, accessor, ...rest } = useElement(selector, (integrationApp) => integrationApp.dataSource(selector));
262
+ async function apply(integrationKeys) {
263
+ const result = await (accessor === null || accessor === void 0 ? void 0 : accessor.apply(integrationKeys));
264
+ await refresh();
265
+ return result;
266
+ }
267
+ async function reset() {
268
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.reset());
269
+ await refresh();
270
+ }
271
+ return { dataSource, apply, reset, refresh, accessor, ...rest };
227
272
  }
228
273
 
229
- function useDataSources(query) {
230
- const { ...rest } = useElements(query, (integrationApp) => integrationApp.dataSources);
274
+ function useDataSourceEvents(query) {
275
+ const { ...rest } = useElements('data-source-events', query);
231
276
  return {
277
+ dataSourceEvents: rest,
232
278
  ...rest,
233
279
  };
234
280
  }
235
281
 
236
282
  function useDataSourceInstance(selector) {
237
- const { data: dataSourceInstance, ...rest } = useElement(selector, (integrationApp) => integrationApp.dataSourceInstance.bind(integrationApp));
238
- const accessor = rest.accessor;
283
+ const { item: dataSourceInstance, accessor, refresh, ...rest } = useElement(selector, (integrationApp) => integrationApp.dataSourceInstance(selector));
284
+ async function setup() {
285
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.setup());
286
+ await refresh();
287
+ }
288
+ async function reset() {
289
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.reset());
290
+ await refresh();
291
+ }
292
+ async function subscribe(eventType) {
293
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.subscribe(eventType));
294
+ await refresh();
295
+ }
296
+ async function resubscribe(eventType) {
297
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.resubscribe(eventType));
298
+ await refresh();
299
+ }
300
+ async function unsubscribe(eventType) {
301
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.unsubscribe(eventType));
302
+ await refresh();
303
+ }
304
+ async function pullUpdates() {
305
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.pullUpdates());
306
+ await refresh();
307
+ }
308
+ async function fullSync() {
309
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.fullSync());
310
+ await refresh();
311
+ }
312
+ async function getSyncsList() {
313
+ return await (accessor === null || accessor === void 0 ? void 0 : accessor.getSyncsList());
314
+ }
315
+ async function openConfiguration(options) {
316
+ return accessor === null || accessor === void 0 ? void 0 : accessor.openConfiguration(options);
317
+ }
318
+ async function listRecords(request) {
319
+ return accessor === null || accessor === void 0 ? void 0 : accessor.listRecords(request);
320
+ }
321
+ async function findRecords(request) {
322
+ return accessor === null || accessor === void 0 ? void 0 : accessor.findRecords(request);
323
+ }
324
+ async function findRecordById(id) {
325
+ return accessor === null || accessor === void 0 ? void 0 : accessor.findRecordById(id);
326
+ }
327
+ async function createRecord(request) {
328
+ return accessor === null || accessor === void 0 ? void 0 : accessor.createRecord(request);
329
+ }
330
+ async function updateRecord(request) {
331
+ return accessor === null || accessor === void 0 ? void 0 : accessor.updateRecord(request);
332
+ }
333
+ async function deleteRecord(id) {
334
+ return accessor === null || accessor === void 0 ? void 0 : accessor.deleteRecord(id);
335
+ }
336
+ async function unifiedFieldsToNative(unifiedFields) {
337
+ return accessor === null || accessor === void 0 ? void 0 : accessor.unifiedFieldsToNative(unifiedFields);
338
+ }
339
+ async function getCollection() {
340
+ return accessor === null || accessor === void 0 ? void 0 : accessor.getCollection();
341
+ }
342
+ async function getLocations(request) {
343
+ return accessor === null || accessor === void 0 ? void 0 : accessor.getLocations(request);
344
+ }
239
345
  return {
240
346
  dataSourceInstance,
241
- setup: () => accessor.setup(),
242
- subscribe: (eventType) => accessor.subscribe(eventType),
243
- resubscribe: (eventType) => accessor.resubscribe(eventType),
244
- unsubscribe: (eventType) => accessor.unsubscribe(eventType),
245
- pullUpdates: () => accessor.pullUpdates(),
246
- fullSync: () => accessor.fullSync(),
247
- reset: () => accessor.reset(),
248
- openConfiguration: (options) => accessor.openConfiguration(options),
249
- findRecords: (request) => accessor.findRecords(request),
250
- findRecordById: (id) => accessor.findRecordById(id),
251
- createRecord: (request) => accessor.createRecord(request),
252
- updateRecord: (request) => accessor.updateRecord(request),
253
- deleteRecord: (id) => accessor.deleteRecord(id),
254
- unifiedFieldsToNative: (unifiedFields) => accessor.unifiedFieldsToNative(unifiedFields),
347
+ accessor,
348
+ refresh,
349
+ setup,
350
+ reset,
351
+ subscribe,
352
+ resubscribe,
353
+ unsubscribe,
354
+ pullUpdates,
355
+ fullSync,
356
+ getSyncsList,
357
+ openConfiguration,
358
+ listRecords,
359
+ findRecords,
360
+ findRecordById,
361
+ createRecord,
362
+ updateRecord,
363
+ deleteRecord,
364
+ unifiedFieldsToNative,
365
+ getLocations,
366
+ getCollection,
255
367
  ...rest,
256
368
  };
257
369
  }
258
370
 
259
- function useGetter(key, getter) {
260
- const integrationApp = useIntegrationApp();
261
- const [data, setData] = react.useState();
262
- const [loading, setLoading] = react.useState(true);
263
- const [error, setError] = react.useState(null);
264
- const [refreshCounter, setRefreshCounter] = react.useState(0);
265
- function refresh() {
266
- setRefreshCounter(refreshCounter + 1);
267
- }
268
- react.useEffect(() => {
269
- if (key !== undefined) {
270
- setLoading(true);
271
- setError(null);
272
- if (integrationApp) {
273
- getter()
274
- .then(setData)
275
- .catch(setError)
276
- .finally(() => setLoading(false));
277
- }
278
- else {
279
- setError(new Error('IntegrationApp not found. Was this component wrapped in <IntegrationAppProvider>?'));
280
- }
281
- }
282
- }, [integrationApp, key, refreshCounter]);
283
- return { data, loading, error, refresh };
284
- }
285
-
286
371
  function useDataSourceInstanceCollection(dataSourceInstance) {
287
372
  const integrationApp = useIntegrationApp();
288
- const { data: collection, ...rest } = useGetter(dataSourceInstance === null || dataSourceInstance === void 0 ? void 0 : dataSourceInstance.id, () => integrationApp.dataSourceInstance(dataSourceInstance.id).getCollection());
373
+ const { data, error, isLoading, mutate } = useSWR(dataSourceInstance ? `${dataSourceInstance.id}/collection` : null, () => integrationApp.dataSourceInstance(dataSourceInstance.id).getCollection());
374
+ async function refresh() {
375
+ return await mutate();
376
+ }
377
+ const collection = data;
289
378
  return {
290
379
  collection,
291
- ...rest,
380
+ refresh,
381
+ error,
382
+ loading: isLoading,
292
383
  };
293
384
  }
294
385
 
295
386
  function useDataSourceInstanceLocations(dataSourceInstance, args) {
296
387
  var _a;
297
388
  const integrationApp = useIntegrationApp();
298
- const { data, ...rest } = useGetter(dataSourceInstance
299
- ? `${dataSourceInstance.id}/${JSON.stringify(args)}`
300
- : undefined, () => integrationApp
389
+ const { data, error, isLoading, mutate } = useSWR(dataSourceInstance
390
+ ? `${dataSourceInstance.id}/locations?${qs.stringify(args)}`
391
+ : null, () => integrationApp
301
392
  .dataSourceInstance(dataSourceInstance.id)
302
393
  .getLocations(args));
394
+ async function refresh() {
395
+ return await mutate();
396
+ }
397
+ const locations = (_a = data === null || data === void 0 ? void 0 : data.locations) !== null && _a !== void 0 ? _a : [];
398
+ return {
399
+ locations,
400
+ refresh,
401
+ error,
402
+ loading: isLoading,
403
+ };
404
+ }
405
+
406
+ function useDataSourceInstances(query) {
407
+ const { ...rest } = useElements('data-source-instances', query);
303
408
  return {
304
- locations: (_a = data === null || data === void 0 ? void 0 : data.locations) !== null && _a !== void 0 ? _a : [],
409
+ dataSourceInstances: rest.items,
305
410
  ...rest,
306
411
  };
307
412
  }
308
413
 
309
- function useDataSourceEvents(query) {
310
- const { ...rest } = useElements(query, (integrationApp) => integrationApp.dataSourceEvents);
414
+ function useDataSources(query) {
415
+ const { ...rest } = useElements('data-sources', query);
311
416
  return {
417
+ dataSources: rest.items,
312
418
  ...rest,
313
419
  };
314
420
  }
315
421
 
316
- function useAppEvents(query) {
317
- const { ...rest } = useElements(query, (integrationApp) => integrationApp.appEvents);
422
+ function useAppEventSubscription(selector) {
423
+ const { item: appEventSubscription, ...rest } = useElement(selector, (integrationApp) => integrationApp.appEventSubscription(selector));
424
+ return { appEventSubscription, ...rest };
425
+ }
426
+
427
+ function useAppEventSubscriptions(query) {
428
+ const { ...rest } = useElements('app-event-subscriptions', query);
318
429
  return {
430
+ appEventSubscriptions: rest.items,
319
431
  ...rest,
320
432
  };
321
433
  }
322
434
 
323
- function useAppEventType(idOrKey) {
324
- const { data: appEventType, ...rest } = useElement(idOrKey, (integrationApp) => integrationApp.appEventType.bind(integrationApp));
435
+ function useAppEventType(id) {
436
+ const { item: appEventType, ...rest } = useElement(id, (integrationApp) => integrationApp.appEventType(id));
325
437
  return { appEventType, ...rest };
326
438
  }
327
439
 
328
440
  function useAppEventTypes(query) {
329
- const { ...rest } = useElements(query, (integrationApp) => integrationApp.appEventTypes);
441
+ const { ...rest } = useElements('app-event-types', query);
330
442
  return {
443
+ appEventTypes: rest.items,
331
444
  ...rest,
332
445
  };
333
446
  }
334
447
 
335
- function useAppEventSubscription(selector) {
336
- const { data: appEventSubscription, ...rest } = useElement(selector, (integrationApp) => integrationApp.appEventSubscription.bind(integrationApp));
337
- return { appEventSubscription, ...rest };
338
- }
339
-
340
- function useAppEventSubscriptions(query) {
341
- const { ...rest } = useElements(query, (integrationApp) => integrationApp.appEventSubscriptions);
448
+ function useAppEvents(query) {
449
+ const { ...rest } = useElements('app-events', query);
342
450
  return {
451
+ appEvents: rest.items,
343
452
  ...rest,
344
453
  };
345
454
  }
346
455
 
347
- function useFlow(idOrKey) {
348
- const { data: flow, ...rest } = useElement(idOrKey, (integrationApp) => integrationApp.flow.bind(integrationApp));
349
- return { flow, ...rest };
456
+ function useFlow(selector) {
457
+ const { item: flow, accessor, refresh, ...rest } = useElement(selector, (integrationApp) => integrationApp.flow(selector));
458
+ async function apply(integrationKeys) {
459
+ const result = await (accessor === null || accessor === void 0 ? void 0 : accessor.apply(integrationKeys));
460
+ await refresh();
461
+ return result;
462
+ }
463
+ async function reset() {
464
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.reset());
465
+ return await refresh();
466
+ }
467
+ return { flow, apply, reset, refresh, accessor, ...rest };
350
468
  }
351
469
 
352
470
  function useFlows(query) {
353
- const { ...rest } = useElements(query, (integrationApp) => integrationApp.flows);
354
- return { ...rest };
471
+ const { ...rest } = useElements('flows', query);
472
+ return {
473
+ flows: rest.items,
474
+ ...rest,
475
+ };
355
476
  }
356
477
 
357
- function useFlowInstance(props) {
358
- const { data: flowInstance, ...rest } = useElement(props, (integrationApp) => integrationApp.flowInstance.bind(integrationApp));
359
- return { flowInstance, ...rest };
478
+ function useFlowInstance(selector) {
479
+ const { item: flowInstance, accessor, refresh, ...rest } = useElement(selector, (integrationApp) => integrationApp.flowInstance(selector));
480
+ async function enable() {
481
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.enable());
482
+ await refresh();
483
+ }
484
+ async function disable() {
485
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.disable());
486
+ await refresh();
487
+ }
488
+ async function reset() {
489
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.reset());
490
+ await refresh();
491
+ }
492
+ async function setup() {
493
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.setup());
494
+ await refresh();
495
+ }
496
+ async function openConfiguration(options) {
497
+ return accessor === null || accessor === void 0 ? void 0 : accessor.openConfiguration(options);
498
+ }
499
+ async function run(options = {}) {
500
+ return accessor === null || accessor === void 0 ? void 0 : accessor.run(options);
501
+ }
502
+ async function startRun(options = {}) {
503
+ return accessor === null || accessor === void 0 ? void 0 : accessor.startRun(options);
504
+ }
505
+ return {
506
+ flowInstance,
507
+ accessor,
508
+ refresh,
509
+ enable,
510
+ disable,
511
+ reset,
512
+ setup,
513
+ openConfiguration,
514
+ run,
515
+ startRun,
516
+ ...rest,
517
+ };
360
518
  }
361
519
 
362
520
  function useFlowInstances(query) {
363
- const { ...rest } = useElements(query, (integrationApp) => integrationApp.flowInstances);
521
+ const { ...rest } = useElements('flow-instances', query);
364
522
  return {
523
+ flowInstances: rest.items,
365
524
  ...rest,
366
525
  };
367
526
  }
368
527
 
369
528
  function useFlowRun(id) {
370
- const { data: flowRun, ...rest } = useElement(id, (integrationApp) => integrationApp.flowRun.bind(integrationApp));
371
- return { flowRun, ...rest };
529
+ const { item: flowRun, archive, refresh, error, loading, } = useElement(id, (integrationApp) => integrationApp.flowRun(id));
530
+ return {
531
+ flowRun,
532
+ error,
533
+ loading,
534
+ refresh,
535
+ archive,
536
+ };
372
537
  }
373
538
 
374
539
  function useFlowRuns(query) {
375
- const { ...rest } = useElements(query, (integrationApp) => integrationApp.flowRuns);
376
- return { ...rest };
540
+ const { ...rest } = useElements('flow-runs', query);
541
+ return {
542
+ flowRuns: rest.items,
543
+ ...rest,
544
+ };
545
+ }
546
+
547
+ function useDataLinkTable(selector) {
548
+ const { item: dataLinkTable, ...rest } = useElement(selector, (integrationApp) => integrationApp.dataLinkTable(selector));
549
+ return { dataLinkTable, ...rest };
550
+ }
551
+
552
+ function useDataLinkTableInstance(selector) {
553
+ const { item: dataLinkTableInstance, accessor, refresh, ...rest } = useElement(selector, (integrationApp) => integrationApp.dataLinkTableInstance(selector));
554
+ return {
555
+ dataLinkTableInstance,
556
+ accessor,
557
+ refresh,
558
+ findLinks: accessor === null || accessor === void 0 ? void 0 : accessor.findLinks,
559
+ createLink: accessor === null || accessor === void 0 ? void 0 : accessor.createLink,
560
+ deleteLink: accessor === null || accessor === void 0 ? void 0 : accessor.deleteLink,
561
+ ...rest,
562
+ };
563
+ }
564
+
565
+ function useDataLinkTableInstances(query) {
566
+ const { ...rest } = useElements('data-link-table-instances', query);
567
+ return {
568
+ dataLinkTableInstances: rest.items,
569
+ ...rest,
570
+ };
571
+ }
572
+
573
+ function useDataLinkTables(query) {
574
+ const { ...rest } = useElements('data-link-tables', query);
575
+ return {
576
+ dataLinkTables: rest.items,
577
+ ...rest,
578
+ };
579
+ }
580
+
581
+ function useAction(selector) {
582
+ const { item: action, accessor, refresh, ...rest } = useElement(selector, (integrationApp) => integrationApp.action(selector));
583
+ async function apply(integrationKeys) {
584
+ const result = await (accessor === null || accessor === void 0 ? void 0 : accessor.apply(integrationKeys));
585
+ await refresh();
586
+ return result;
587
+ }
588
+ async function reset() {
589
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.reset());
590
+ await refresh();
591
+ }
592
+ return { action, apply, reset, refresh, accessor, ...rest };
593
+ }
594
+
595
+ function useActionInstance(selector) {
596
+ const { item: actionInstance, accessor, refresh, ...rest } = useElement(selector, (integrationApp) => integrationApp.actionInstance(selector));
597
+ async function run(input) {
598
+ return accessor === null || accessor === void 0 ? void 0 : accessor.run(input);
599
+ }
600
+ async function setup() {
601
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.setup());
602
+ await refresh();
603
+ }
604
+ async function reset() {
605
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.reset());
606
+ await refresh();
607
+ }
608
+ async function openConfiguration(options) {
609
+ return accessor === null || accessor === void 0 ? void 0 : accessor.open(options);
610
+ }
611
+ return {
612
+ actionInstance,
613
+ accessor,
614
+ refresh,
615
+ setup,
616
+ reset,
617
+ openConfiguration,
618
+ run,
619
+ ...rest,
620
+ };
621
+ }
622
+
623
+ function useActionInstances(query) {
624
+ const { ...rest } = useElements('action-instances', query);
625
+ return {
626
+ actionInstances: rest.items,
627
+ ...rest,
628
+ };
629
+ }
630
+
631
+ function useActions(query) {
632
+ const { ...rest } = useElements('actions', query);
633
+ return {
634
+ actions: rest.items,
635
+ ...rest,
636
+ };
637
+ }
638
+
639
+ function useScreen(selector) {
640
+ const { item: screen, ...rest } = useElement(selector, (integrationApp) => integrationApp.screen(selector));
641
+ return { screen, ...rest };
642
+ }
643
+
644
+ function useDataCollectionSpec({ path, key, integrationId, }) {
645
+ var _a;
646
+ const client = useIntegrationApp();
647
+ const dataCollectionKey = key !== null && key !== void 0 ? key : (_a = sdk.parseDataLocationPath(path)) === null || _a === void 0 ? void 0 : _a.key;
648
+ const { data: dataCollectionSpec } = useSWR(dataCollectionKey && integrationId
649
+ ? `/integrations/${integrationId}/data/${dataCollectionKey}`
650
+ : null, () => client.integration(integrationId).getDataLocation(dataCollectionKey));
651
+ return dataCollectionSpec;
377
652
  }
378
653
 
379
654
  Object.defineProperty(exports, 'DataForm', {
@@ -381,6 +656,10 @@
381
656
  get: function () { return sdk.DataForm; }
382
657
  });
383
658
  exports.IntegrationAppProvider = IntegrationAppProvider;
659
+ exports.useAction = useAction;
660
+ exports.useActionInstance = useActionInstance;
661
+ exports.useActionInstances = useActionInstances;
662
+ exports.useActions = useActions;
384
663
  exports.useAppEventSubscription = useAppEventSubscription;
385
664
  exports.useAppEventSubscriptions = useAppEventSubscriptions;
386
665
  exports.useAppEventType = useAppEventType;
@@ -389,11 +668,17 @@
389
668
  exports.useConnection = useConnection;
390
669
  exports.useConnections = useConnections;
391
670
  exports.useConnectorSpec = useConnectorSpec;
671
+ exports.useDataCollectionSpec = useDataCollectionSpec;
672
+ exports.useDataLinkTable = useDataLinkTable;
673
+ exports.useDataLinkTableInstance = useDataLinkTableInstance;
674
+ exports.useDataLinkTableInstances = useDataLinkTableInstances;
675
+ exports.useDataLinkTables = useDataLinkTables;
392
676
  exports.useDataSource = useDataSource;
393
- exports.useDataSourceCollection = useDataSourceInstanceCollection;
394
677
  exports.useDataSourceEvents = useDataSourceEvents;
395
678
  exports.useDataSourceInstance = useDataSourceInstance;
396
- exports.useDataSourceLocations = useDataSourceInstanceLocations;
679
+ exports.useDataSourceInstanceCollection = useDataSourceInstanceCollection;
680
+ exports.useDataSourceInstanceLocations = useDataSourceInstanceLocations;
681
+ exports.useDataSourceInstances = useDataSourceInstances;
397
682
  exports.useDataSources = useDataSources;
398
683
  exports.useFieldMapping = useFieldMapping;
399
684
  exports.useFieldMappingInstance = useFieldMappingInstance;
@@ -407,7 +692,9 @@
407
692
  exports.useFlows = useFlows;
408
693
  exports.useIntegration = useIntegration;
409
694
  exports.useIntegrationApp = useIntegrationApp;
695
+ exports.useIntegrationAppSWR = useIntegrationAppSWR;
410
696
  exports.useIntegrations = useIntegrations;
697
+ exports.useScreen = useScreen;
411
698
 
412
699
  }));
413
700
  //# sourceMappingURL=index.umd.js.map