@integration-app/react 0.2.1 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. package/dist/index.d.ts +371 -165
  2. package/dist/index.js +510 -234
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.module.d.ts +371 -165
  5. package/dist/index.module.mjs +500 -235
  6. package/dist/index.module.mjs.map +1 -1
  7. package/dist/index.umd.d.ts +371 -165
  8. package/dist/index.umd.js +510 -238
  9. package/dist/index.umd.js.map +1 -1
  10. package/package.json +5 -2
  11. package/src/actions/useAction.ts +35 -0
  12. package/src/actions/useActionInstance.ts +56 -0
  13. package/src/actions/useActionInstances.ts +11 -0
  14. package/src/actions/useActions.ts +11 -0
  15. package/src/app-events/useAppEventSubscription.ts +6 -6
  16. package/src/app-events/useAppEventSubscriptions.ts +5 -4
  17. package/src/app-events/useAppEventType.ts +10 -7
  18. package/src/app-events/useAppEventTypes.ts +2 -4
  19. package/src/app-events/useAppEvents.ts +2 -4
  20. package/src/contexts/index.tsx +4 -0
  21. package/src/data-collections/useDataCollectionSpec.ts +26 -0
  22. package/src/data-links/useDataLinkTable.ts +18 -0
  23. package/src/data-links/useDataLinkTableInstance.ts +39 -0
  24. package/src/data-links/useDataLinkTableInstances.ts +19 -0
  25. package/src/data-links/useDataLinkTables.ts +11 -0
  26. package/src/data-sources/useDataSource.ts +29 -6
  27. package/src/data-sources/useDataSourceEvents.ts +2 -4
  28. package/src/data-sources/useDataSourceInstance.ts +120 -26
  29. package/src/data-sources/useDataSourceInstanceCollection.ts +14 -4
  30. package/src/data-sources/useDataSourceInstanceLocations.ts +17 -6
  31. package/src/data-sources/useDataSourceInstances.ts +5 -4
  32. package/src/data-sources/useDataSources.ts +2 -4
  33. package/src/field-mappings/useFieldMapping.ts +29 -8
  34. package/src/field-mappings/useFieldMappingInstance.ts +35 -12
  35. package/src/field-mappings/useFieldMappingInstances.ts +5 -4
  36. package/src/field-mappings/useFieldMappings.ts +2 -4
  37. package/src/flows/useFlow.ts +29 -8
  38. package/src/flows/useFlowInstance.ts +62 -5
  39. package/src/flows/useFlowInstances.ts +2 -4
  40. package/src/flows/useFlowRun.ts +18 -6
  41. package/src/flows/useFlowRuns.ts +5 -5
  42. package/src/flows/useFlows.ts +5 -5
  43. package/src/hooks/useElement.tsx +137 -149
  44. package/src/hooks/useElements.tsx +44 -73
  45. package/src/hooks/useIntegrationAppSWR.tsx +13 -0
  46. package/src/index.tsx +27 -14
  47. package/src/integrations/useConnection.ts +14 -5
  48. package/src/integrations/useConnections.ts +3 -4
  49. package/src/integrations/useConnectorSpec.ts +7 -18
  50. package/src/integrations/useIntegration.ts +11 -7
  51. package/src/integrations/useIntegrations.ts +3 -4
  52. package/src/screens/useScreen.ts +19 -0
  53. package/rollup.dts.config.mjs +0 -21
  54. package/src/flows/useFlowTemplate.ts +0 -0
  55. package/src/flows/useFlowTemplates.ts +0 -0
  56. package/src/hooks/useGetter.tsx +0 -38
package/dist/index.umd.js CHANGED
@@ -1,8 +1,8 @@
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';
@@ -21,373 +21,634 @@
21
21
  return react.useContext(IntegrationAppContext);
22
22
  }
23
23
 
24
- function useConnectorSpec(integrationKey) {
25
- const integrationApp = useIntegrationApp();
26
- const [data, setData] = react.useState(null);
27
- const [loading, setLoading] = react.useState(true);
28
- const [error, setError] = react.useState(null);
29
- react.useEffect(() => {
30
- if (!integrationApp) {
31
- return;
32
- }
33
- integrationApp
34
- .integration(integrationKey)
35
- .getConnectorSpec()
36
- .then(setData)
37
- .catch(setError)
38
- .finally(() => setLoading(false));
39
- }, [integrationApp, integrationKey]);
40
- 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);
41
31
  }
42
32
 
43
- function useElement(props, accessorGenerator) {
33
+ const elementStateCache = new Map();
34
+ function useElement(selector, accessorGenerator) {
44
35
  const integrationApp = useIntegrationApp();
45
- const [data, setData] = react.useState();
46
- const [loading, setLoading] = react.useState(true);
47
- const [error, setError] = react.useState(null);
48
- const [refreshCounter, setRefreshCounter] = react.useState(0);
49
- function updateDataWith(newData) {
50
- if (data !== undefined) {
51
- setData({
52
- ...data,
53
- ...newData,
54
- });
55
- }
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
+ });
56
64
  }
57
- function replaceDataWith(newData) {
58
- setData(newData);
59
- }
60
- const selector = (props === null || props === void 0 ? void 0 : props.id)
61
- ? props.id
62
- : props;
63
- const accessor = integrationApp
64
- ? accessorGenerator(integrationApp)(selector)
65
- : null;
66
- react.useEffect(() => {
67
- setLoading(true);
68
- setError(null);
69
- if (integrationApp && selector) {
70
- accessor
71
- .get()
72
- .then(setData)
73
- .catch(setError)
74
- .finally(() => setLoading(false));
75
- }
76
- else {
77
- setError(new Error('IntegrationApp not found. Was this component wrapped in <IntegrationAppProvider>?'));
78
- }
79
- }, [
80
- integrationApp,
81
- JSON.stringify(selector),
82
- JSON.stringify(props),
83
- refreshCounter,
84
- ]);
85
- async function create(createData) {
86
- const returnedData = await accessor.create(createData);
87
- replaceDataWith(returnedData);
88
- return returnedData;
89
- }
90
- function refresh() {
91
- setRefreshCounter(refreshCounter + 1);
92
- }
93
- async function patch(patch) {
94
- if (typeof patch === 'object') {
95
- updateDataWith(patch !== null && patch !== void 0 ? patch : {});
96
- return accessor.patch(patch);
97
- }
98
- else {
99
- return data;
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}`);
100
79
  }
80
+ elementState.updatedLocally = true;
81
+ const newLocalData = {
82
+ ...item,
83
+ ...data,
84
+ };
85
+ await mutate(newLocalData, false);
86
+ await elementState.debouncedPut(data);
101
87
  }
102
- async function put(putData) {
103
- updateDataWith(putData);
104
- return await accessor.put(putData);
88
+ async function patch(data) {
89
+ const newData = {
90
+ ...item,
91
+ ...data,
92
+ };
93
+ return put(newData);
105
94
  }
106
95
  async function archive() {
107
- setData(null);
108
- return accessor.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);
109
109
  }
110
110
  return {
111
- data,
111
+ accessor,
112
+ item,
113
+ loading,
114
+ saving: elementState.updatedLocally || elementState.savingToServer,
115
+ error,
116
+ refresh,
117
+ refreshing,
112
118
  create,
113
119
  patch,
114
120
  put,
115
121
  archive,
116
- refresh,
117
- loading,
118
- error,
119
- accessor,
120
122
  };
121
123
  }
122
124
 
123
- function useIntegration(idOrKey) {
124
- const { data: integration, ...rest } = useElement(idOrKey, (integrationApp) => integrationApp.integration.bind(integrationApp));
125
- 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
+ };
126
131
  }
127
132
 
128
- function useElements(initialQuery, accessorGenerator) {
133
+ const LIMIT = 25;
134
+ function useElements(route, query = {}) {
129
135
  const integrationApp = useIntegrationApp();
130
- const refreshId = react.useRef(0);
131
- const [items, setItems] = react.useState([]);
132
- const [nextCursor, setNextCursor] = react.useState(undefined);
133
- const [loading, setLoading] = react.useState(false);
134
- 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;
135
156
  async function loadMore() {
136
- const startingRefreshId = refreshId.current;
137
- const isFirstPage = !nextCursor;
138
- function setStateIfCurrentRefresh(stateSetter, valueGetter) {
139
- stateSetter((value) => startingRefreshId === refreshId.current ? valueGetter(value) : value);
140
- }
141
- setStateIfCurrentRefresh(setError, () => null);
142
- setStateIfCurrentRefresh(setLoading, () => true);
143
- const queryParams = {
144
- ...initialQuery,
145
- };
146
- if (nextCursor)
147
- queryParams.cursor = nextCursor;
148
- try {
149
- const data = await accessorGenerator(integrationApp).find(queryParams);
150
- setStateIfCurrentRefresh(setNextCursor, () => data.cursor);
151
- setStateIfCurrentRefresh(setItems, (items) => isFirstPage ? data.items : [...items, ...data.items]);
152
- }
153
- catch (e) {
154
- setStateIfCurrentRefresh(setError, () => e);
155
- }
156
- finally {
157
- 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);
158
163
  }
159
164
  }
160
- react.useEffect(() => {
161
- if (!integrationApp) {
162
- setError(new Error('IntegrationApp not found. Was this component wrapped in <IntegrationAppProvider>?'));
163
- return;
164
- }
165
- refresh();
166
- }, [integrationApp, JSON.stringify(initialQuery)]);
167
165
  async function refresh() {
168
- refreshId.current += 1;
169
- setNextCursor(undefined);
170
- await loadMore();
166
+ await mutate();
171
167
  }
172
168
  return {
173
169
  items,
174
170
  refresh,
171
+ refreshing,
175
172
  loadMore,
173
+ loadingMore,
176
174
  loading,
177
175
  error,
178
176
  };
179
177
  }
180
178
 
181
- function useIntegrations(query) {
182
- const { ...rest } = useElements(query, (integrationApp) => integrationApp.integrations);
179
+ function useConnections(query) {
180
+ const { ...rest } = useElements('connections', query);
183
181
  return {
182
+ connections: rest.items,
184
183
  ...rest,
185
184
  };
186
185
  }
187
186
 
188
- function useConnection(id) {
189
- const { data: connection, ...rest } = useElement(id, (integrationApp) => integrationApp.connection.bind(integrationApp));
190
- 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 };
191
191
  }
192
192
 
193
- function useConnections(query) {
194
- 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);
195
200
  return {
201
+ integrations: rest.items,
196
202
  ...rest,
197
203
  };
198
204
  }
199
205
 
200
- function useFieldMapping(idOrKey) {
201
- const { data: fieldMapping, ...rest } = useElement(idOrKey, (integrationApp) => integrationApp.fieldMapping.bind(integrationApp));
202
- 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 };
203
218
  }
204
219
 
205
- function useFieldMappings(query) {
206
- 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
+ }
207
233
  return {
234
+ fieldMappingInstance,
235
+ accessor,
236
+ refresh,
237
+ setup,
238
+ reset,
239
+ openConfiguration,
208
240
  ...rest,
209
241
  };
210
242
  }
211
243
 
212
- function useFieldMappingInstance(selector) {
213
- const { data: fieldMappingInstance, ...rest } = useElement(selector, (integrationApp) => integrationApp.fieldMappingInstance.bind(integrationApp));
214
- const accessor = rest.accessor;
244
+ function useFieldMappingInstances(query) {
245
+ const { ...rest } = useElements('field-mapping-instances', query);
215
246
  return {
216
- fieldMappingInstance,
217
- setup: () => accessor.setup(),
218
- reset: () => accessor.reset(),
219
- openConfiguration: (options) => accessor.openConfiguration(options),
247
+ fieldMappingInstances: rest.items,
220
248
  ...rest,
221
249
  };
222
250
  }
223
251
 
224
- function useFieldMappingInstances(query) {
225
- const { ...rest } = useElements(query, (integrationApp) => integrationApp.fieldMappingInstances);
252
+ function useFieldMappings(query) {
253
+ const { ...rest } = useElements('field-mappings', query);
226
254
  return {
255
+ fieldMappings: rest.items,
227
256
  ...rest,
228
257
  };
229
258
  }
230
259
 
231
- function useDataSource(idOrKey) {
232
- const { data: dataSource, ...rest } = useElement(idOrKey, (integrationApp) => integrationApp.dataSource.bind(integrationApp));
233
- 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 };
234
272
  }
235
273
 
236
- function useDataSources(query) {
237
- const { ...rest } = useElements(query, (integrationApp) => integrationApp.dataSources);
274
+ function useDataSourceEvents(query) {
275
+ const { ...rest } = useElements('data-source-events', query);
238
276
  return {
277
+ dataSourceEvents: rest,
239
278
  ...rest,
240
279
  };
241
280
  }
242
281
 
243
282
  function useDataSourceInstance(selector) {
244
- const { data: dataSourceInstance, ...rest } = useElement(selector, (integrationApp) => integrationApp.dataSourceInstance.bind(integrationApp));
245
- 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
+ }
246
345
  return {
247
346
  dataSourceInstance,
248
- setup: () => accessor.setup(),
249
- subscribe: (eventType) => accessor.subscribe(eventType),
250
- resubscribe: (eventType) => accessor.resubscribe(eventType),
251
- unsubscribe: (eventType) => accessor.unsubscribe(eventType),
252
- pullUpdates: () => accessor.pullUpdates(),
253
- fullSync: () => accessor.fullSync(),
254
- reset: () => accessor.reset(),
255
- openConfiguration: (options) => accessor.openConfiguration(options),
256
- findRecords: (request) => accessor.findRecords(request),
257
- findRecordById: (id) => accessor.findRecordById(id),
258
- createRecord: (request) => accessor.createRecord(request),
259
- updateRecord: (request) => accessor.updateRecord(request),
260
- deleteRecord: (id) => accessor.deleteRecord(id),
261
- unifiedFieldsToNative: (unifiedFields) => accessor.unifiedFieldsToNative(unifiedFields),
262
- ...rest,
263
- };
264
- }
265
-
266
- function useDataSourceInstances(query) {
267
- const { ...rest } = useElements(query, (integrationApp) => integrationApp.dataSourceInstances);
268
- return {
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,
269
367
  ...rest,
270
368
  };
271
369
  }
272
370
 
273
- function useGetter(key, getter) {
274
- const integrationApp = useIntegrationApp();
275
- const [data, setData] = react.useState();
276
- const [loading, setLoading] = react.useState(true);
277
- const [error, setError] = react.useState(null);
278
- const [refreshCounter, setRefreshCounter] = react.useState(0);
279
- function refresh() {
280
- setRefreshCounter(refreshCounter + 1);
281
- }
282
- react.useEffect(() => {
283
- if (key !== undefined) {
284
- setLoading(true);
285
- setError(null);
286
- if (integrationApp) {
287
- getter()
288
- .then(setData)
289
- .catch(setError)
290
- .finally(() => setLoading(false));
291
- }
292
- else {
293
- setError(new Error('IntegrationApp not found. Was this component wrapped in <IntegrationAppProvider>?'));
294
- }
295
- }
296
- }, [integrationApp, key, refreshCounter]);
297
- return { data, loading, error, refresh };
298
- }
299
-
300
371
  function useDataSourceInstanceCollection(dataSourceInstance) {
301
372
  const integrationApp = useIntegrationApp();
302
- 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;
303
378
  return {
304
379
  collection,
305
- ...rest,
380
+ refresh,
381
+ error,
382
+ loading: isLoading,
306
383
  };
307
384
  }
308
385
 
309
386
  function useDataSourceInstanceLocations(dataSourceInstance, args) {
310
387
  var _a;
311
388
  const integrationApp = useIntegrationApp();
312
- const { data, ...rest } = useGetter(dataSourceInstance
313
- ? `${dataSourceInstance.id}/${JSON.stringify(args)}`
314
- : undefined, () => integrationApp
389
+ const { data, error, isLoading, mutate } = useSWR(dataSourceInstance
390
+ ? `${dataSourceInstance.id}/locations?${qs.stringify(args)}`
391
+ : null, () => integrationApp
315
392
  .dataSourceInstance(dataSourceInstance.id)
316
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 : [];
317
398
  return {
318
- locations: (_a = data === null || data === void 0 ? void 0 : data.locations) !== null && _a !== void 0 ? _a : [],
399
+ locations,
400
+ refresh,
401
+ error,
402
+ loading: isLoading,
403
+ };
404
+ }
405
+
406
+ function useDataSourceInstances(query) {
407
+ const { ...rest } = useElements('data-source-instances', query);
408
+ return {
409
+ dataSourceInstances: rest.items,
319
410
  ...rest,
320
411
  };
321
412
  }
322
413
 
323
- function useDataSourceEvents(query) {
324
- const { ...rest } = useElements(query, (integrationApp) => integrationApp.dataSourceEvents);
414
+ function useDataSources(query) {
415
+ const { ...rest } = useElements('data-sources', query);
325
416
  return {
417
+ dataSources: rest.items,
326
418
  ...rest,
327
419
  };
328
420
  }
329
421
 
330
- function useAppEvents(query) {
331
- 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);
332
429
  return {
430
+ appEventSubscriptions: rest.items,
333
431
  ...rest,
334
432
  };
335
433
  }
336
434
 
337
- function useAppEventType(idOrKey) {
338
- 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));
339
437
  return { appEventType, ...rest };
340
438
  }
341
439
 
342
440
  function useAppEventTypes(query) {
343
- const { ...rest } = useElements(query, (integrationApp) => integrationApp.appEventTypes);
441
+ const { ...rest } = useElements('app-event-types', query);
344
442
  return {
443
+ appEventTypes: rest.items,
345
444
  ...rest,
346
445
  };
347
446
  }
348
447
 
349
- function useAppEventSubscription(selector) {
350
- const { data: appEventSubscription, ...rest } = useElement(selector, (integrationApp) => integrationApp.appEventSubscription.bind(integrationApp));
351
- return { appEventSubscription, ...rest };
352
- }
353
-
354
- function useAppEventSubscriptions(query) {
355
- const { ...rest } = useElements(query, (integrationApp) => integrationApp.appEventSubscriptions);
448
+ function useAppEvents(query) {
449
+ const { ...rest } = useElements('app-events', query);
356
450
  return {
451
+ appEvents: rest.items,
357
452
  ...rest,
358
453
  };
359
454
  }
360
455
 
361
- function useFlow(idOrSelector) {
362
- const { data: flow, ...rest } = useElement(idOrSelector, (integrationApp) => integrationApp.flow.bind(integrationApp));
363
- 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 };
364
468
  }
365
469
 
366
470
  function useFlows(query) {
367
- const { ...rest } = useElements(query, (integrationApp) => integrationApp.flows);
368
- return { ...rest };
471
+ const { ...rest } = useElements('flows', query);
472
+ return {
473
+ flows: rest.items,
474
+ ...rest,
475
+ };
369
476
  }
370
477
 
371
- function useFlowInstance(props) {
372
- const { data: flowInstance, ...rest } = useElement(props, (integrationApp) => integrationApp.flowInstance.bind(integrationApp));
373
- 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
+ };
374
518
  }
375
519
 
376
520
  function useFlowInstances(query) {
377
- const { ...rest } = useElements(query, (integrationApp) => integrationApp.flowInstances);
521
+ const { ...rest } = useElements('flow-instances', query);
378
522
  return {
523
+ flowInstances: rest.items,
379
524
  ...rest,
380
525
  };
381
526
  }
382
527
 
383
528
  function useFlowRun(id) {
384
- const { data: flowRun, ...rest } = useElement(id, (integrationApp) => integrationApp.flowRun.bind(integrationApp));
385
- 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
+ };
386
537
  }
387
538
 
388
539
  function useFlowRuns(query) {
389
- const { ...rest } = useElements(query, (integrationApp) => integrationApp.flowRuns);
390
- 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;
391
652
  }
392
653
 
393
654
  Object.defineProperty(exports, 'DataForm', {
@@ -395,6 +656,10 @@
395
656
  get: function () { return sdk.DataForm; }
396
657
  });
397
658
  exports.IntegrationAppProvider = IntegrationAppProvider;
659
+ exports.useAction = useAction;
660
+ exports.useActionInstance = useActionInstance;
661
+ exports.useActionInstances = useActionInstances;
662
+ exports.useActions = useActions;
398
663
  exports.useAppEventSubscription = useAppEventSubscription;
399
664
  exports.useAppEventSubscriptions = useAppEventSubscriptions;
400
665
  exports.useAppEventType = useAppEventType;
@@ -403,12 +668,17 @@
403
668
  exports.useConnection = useConnection;
404
669
  exports.useConnections = useConnections;
405
670
  exports.useConnectorSpec = useConnectorSpec;
671
+ exports.useDataCollectionSpec = useDataCollectionSpec;
672
+ exports.useDataLinkTable = useDataLinkTable;
673
+ exports.useDataLinkTableInstance = useDataLinkTableInstance;
674
+ exports.useDataLinkTableInstances = useDataLinkTableInstances;
675
+ exports.useDataLinkTables = useDataLinkTables;
406
676
  exports.useDataSource = useDataSource;
407
- exports.useDataSourceCollection = useDataSourceInstanceCollection;
408
677
  exports.useDataSourceEvents = useDataSourceEvents;
409
678
  exports.useDataSourceInstance = useDataSourceInstance;
679
+ exports.useDataSourceInstanceCollection = useDataSourceInstanceCollection;
680
+ exports.useDataSourceInstanceLocations = useDataSourceInstanceLocations;
410
681
  exports.useDataSourceInstances = useDataSourceInstances;
411
- exports.useDataSourceLocations = useDataSourceInstanceLocations;
412
682
  exports.useDataSources = useDataSources;
413
683
  exports.useFieldMapping = useFieldMapping;
414
684
  exports.useFieldMappingInstance = useFieldMappingInstance;
@@ -422,7 +692,9 @@
422
692
  exports.useFlows = useFlows;
423
693
  exports.useIntegration = useIntegration;
424
694
  exports.useIntegrationApp = useIntegrationApp;
695
+ exports.useIntegrationAppSWR = useIntegrationAppSWR;
425
696
  exports.useIntegrations = useIntegrations;
697
+ exports.useScreen = useScreen;
426
698
 
427
699
  }));
428
700
  //# sourceMappingURL=index.umd.js.map