@integration-app/react 0.2.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. package/dist/index.d.ts +396 -165
  2. package/dist/index.js +527 -234
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.module.d.ts +396 -165
  5. package/dist/index.module.mjs +515 -235
  6. package/dist/index.module.mjs.map +1 -1
  7. package/dist/index.umd.d.ts +396 -165
  8. package/dist/index.umd.js +527 -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/customers/useCustomer.ts +19 -0
  22. package/src/customers/useCustomers.ts +11 -0
  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 +5 -4
  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 +35 -12
  37. package/src/field-mappings/useFieldMappingInstances.ts +5 -4
  38. package/src/field-mappings/useFieldMappings.ts +2 -4
  39. package/src/flows/useFlow.ts +29 -8
  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 +137 -149
  46. package/src/hooks/useElements.tsx +44 -73
  47. package/src/hooks/useIntegrationAppSWR.tsx +13 -0
  48. package/src/index.tsx +30 -14
  49. package/src/integrations/useConnection.ts +14 -5
  50. package/src/integrations/useConnections.ts +3 -4
  51. package/src/integrations/useConnectorSpec.ts +9 -18
  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/src/flows/useFlowTemplate.ts +0 -0
  56. package/src/flows/useFlowTemplates.ts +0 -0
  57. 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,649 @@
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(integrationIdOrKey
190
+ ? `/integrations/${integrationIdOrKey}/connector-spec`
191
+ : undefined, () => integrationApp.integration(integrationIdOrKey).getConnectorSpec());
192
+ return { data, loading: isLoading, error };
191
193
  }
192
194
 
193
- function useConnections(query) {
194
- const { ...rest } = useElements(query, (integrationApp) => integrationApp.connections);
195
+ function useIntegration(id) {
196
+ const { item: integration, ...rest } = useElement(id, (integrationApp) => integrationApp.integration(id));
197
+ return { integration, ...rest };
198
+ }
199
+
200
+ function useIntegrations(query) {
201
+ const { ...rest } = useElements('integrations', query);
195
202
  return {
203
+ integrations: rest.items,
196
204
  ...rest,
197
205
  };
198
206
  }
199
207
 
200
- function useFieldMapping(idOrKey) {
201
- const { data: fieldMapping, ...rest } = useElement(idOrKey, (integrationApp) => integrationApp.fieldMapping.bind(integrationApp));
202
- return { fieldMapping, ...rest };
208
+ function useFieldMapping(selector) {
209
+ const { item: fieldMapping, accessor, refresh, ...rest } = useElement(selector, (integrationApp) => integrationApp.fieldMapping(selector));
210
+ async function apply(integrationKeys) {
211
+ const result = await (accessor === null || accessor === void 0 ? void 0 : accessor.apply(integrationKeys));
212
+ await refresh();
213
+ return result;
214
+ }
215
+ async function reset() {
216
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.reset());
217
+ await refresh();
218
+ }
219
+ return { fieldMapping, apply, reset, refresh, accessor, ...rest };
203
220
  }
204
221
 
205
- function useFieldMappings(query) {
206
- const { ...rest } = useElements(query, (integrationApp) => integrationApp.fieldMappings);
222
+ function useFieldMappingInstance(selector) {
223
+ const { item: fieldMappingInstance, accessor, refresh, ...rest } = useElement(selector, (integrationApp) => integrationApp.fieldMappingInstance(selector));
224
+ async function setup() {
225
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.setup());
226
+ await refresh();
227
+ }
228
+ async function reset() {
229
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.reset());
230
+ await refresh();
231
+ }
232
+ async function openConfiguration(options) {
233
+ return accessor === null || accessor === void 0 ? void 0 : accessor.openConfiguration(options);
234
+ }
207
235
  return {
236
+ fieldMappingInstance,
237
+ accessor,
238
+ refresh,
239
+ setup,
240
+ reset,
241
+ openConfiguration,
208
242
  ...rest,
209
243
  };
210
244
  }
211
245
 
212
- function useFieldMappingInstance(selector) {
213
- const { data: fieldMappingInstance, ...rest } = useElement(selector, (integrationApp) => integrationApp.fieldMappingInstance.bind(integrationApp));
214
- const accessor = rest.accessor;
246
+ function useFieldMappingInstances(query) {
247
+ const { ...rest } = useElements('field-mapping-instances', query);
215
248
  return {
216
- fieldMappingInstance,
217
- setup: () => accessor.setup(),
218
- reset: () => accessor.reset(),
219
- openConfiguration: (options) => accessor.openConfiguration(options),
249
+ fieldMappingInstances: rest.items,
220
250
  ...rest,
221
251
  };
222
252
  }
223
253
 
224
- function useFieldMappingInstances(query) {
225
- const { ...rest } = useElements(query, (integrationApp) => integrationApp.fieldMappingInstances);
254
+ function useFieldMappings(query) {
255
+ const { ...rest } = useElements('field-mappings', query);
226
256
  return {
257
+ fieldMappings: rest.items,
227
258
  ...rest,
228
259
  };
229
260
  }
230
261
 
231
- function useDataSource(idOrKey) {
232
- const { data: dataSource, ...rest } = useElement(idOrKey, (integrationApp) => integrationApp.dataSource.bind(integrationApp));
233
- return { dataSource, ...rest };
262
+ function useDataSource(selector) {
263
+ const { item: dataSource, refresh, accessor, ...rest } = useElement(selector, (integrationApp) => integrationApp.dataSource(selector));
264
+ async function apply(integrationKeys) {
265
+ const result = await (accessor === null || accessor === void 0 ? void 0 : accessor.apply(integrationKeys));
266
+ await refresh();
267
+ return result;
268
+ }
269
+ async function reset() {
270
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.reset());
271
+ await refresh();
272
+ }
273
+ return { dataSource, apply, reset, refresh, accessor, ...rest };
234
274
  }
235
275
 
236
- function useDataSources(query) {
237
- const { ...rest } = useElements(query, (integrationApp) => integrationApp.dataSources);
276
+ function useDataSourceEvents(query) {
277
+ const { ...rest } = useElements('data-source-events', query);
238
278
  return {
279
+ dataSourceEvents: rest,
239
280
  ...rest,
240
281
  };
241
282
  }
242
283
 
243
284
  function useDataSourceInstance(selector) {
244
- const { data: dataSourceInstance, ...rest } = useElement(selector, (integrationApp) => integrationApp.dataSourceInstance.bind(integrationApp));
245
- const accessor = rest.accessor;
285
+ const { item: dataSourceInstance, accessor, refresh, ...rest } = useElement(selector, (integrationApp) => integrationApp.dataSourceInstance(selector));
286
+ async function setup() {
287
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.setup());
288
+ await refresh();
289
+ }
290
+ async function reset() {
291
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.reset());
292
+ await refresh();
293
+ }
294
+ async function subscribe(eventType) {
295
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.subscribe(eventType));
296
+ await refresh();
297
+ }
298
+ async function resubscribe(eventType) {
299
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.resubscribe(eventType));
300
+ await refresh();
301
+ }
302
+ async function unsubscribe(eventType) {
303
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.unsubscribe(eventType));
304
+ await refresh();
305
+ }
306
+ async function pullUpdates() {
307
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.pullUpdates());
308
+ await refresh();
309
+ }
310
+ async function fullSync() {
311
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.fullSync());
312
+ await refresh();
313
+ }
314
+ async function getSyncsList() {
315
+ return await (accessor === null || accessor === void 0 ? void 0 : accessor.getSyncsList());
316
+ }
317
+ async function openConfiguration(options) {
318
+ return accessor === null || accessor === void 0 ? void 0 : accessor.openConfiguration(options);
319
+ }
320
+ async function listRecords(request) {
321
+ return accessor === null || accessor === void 0 ? void 0 : accessor.listRecords(request);
322
+ }
323
+ async function findRecords(request) {
324
+ return accessor === null || accessor === void 0 ? void 0 : accessor.findRecords(request);
325
+ }
326
+ async function findRecordById(id) {
327
+ return accessor === null || accessor === void 0 ? void 0 : accessor.findRecordById(id);
328
+ }
329
+ async function createRecord(request) {
330
+ return accessor === null || accessor === void 0 ? void 0 : accessor.createRecord(request);
331
+ }
332
+ async function updateRecord(request) {
333
+ return accessor === null || accessor === void 0 ? void 0 : accessor.updateRecord(request);
334
+ }
335
+ async function deleteRecord(id) {
336
+ return accessor === null || accessor === void 0 ? void 0 : accessor.deleteRecord(id);
337
+ }
338
+ async function unifiedFieldsToNative(unifiedFields) {
339
+ return accessor === null || accessor === void 0 ? void 0 : accessor.unifiedFieldsToNative(unifiedFields);
340
+ }
341
+ async function getCollection() {
342
+ return accessor === null || accessor === void 0 ? void 0 : accessor.getCollection();
343
+ }
344
+ async function getLocations(request) {
345
+ return accessor === null || accessor === void 0 ? void 0 : accessor.getLocations(request);
346
+ }
246
347
  return {
247
348
  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 {
349
+ accessor,
350
+ refresh,
351
+ setup,
352
+ reset,
353
+ subscribe,
354
+ resubscribe,
355
+ unsubscribe,
356
+ pullUpdates,
357
+ fullSync,
358
+ getSyncsList,
359
+ openConfiguration,
360
+ listRecords,
361
+ findRecords,
362
+ findRecordById,
363
+ createRecord,
364
+ updateRecord,
365
+ deleteRecord,
366
+ unifiedFieldsToNative,
367
+ getLocations,
368
+ getCollection,
269
369
  ...rest,
270
370
  };
271
371
  }
272
372
 
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
373
  function useDataSourceInstanceCollection(dataSourceInstance) {
301
374
  const integrationApp = useIntegrationApp();
302
- const { data: collection, ...rest } = useGetter(dataSourceInstance === null || dataSourceInstance === void 0 ? void 0 : dataSourceInstance.id, () => integrationApp.dataSourceInstance(dataSourceInstance.id).getCollection());
375
+ const { data, error, isLoading, mutate } = useSWR(dataSourceInstance ? `${dataSourceInstance.id}/collection` : null, () => integrationApp.dataSourceInstance(dataSourceInstance.id).getCollection());
376
+ async function refresh() {
377
+ return await mutate();
378
+ }
379
+ const collection = data;
303
380
  return {
304
381
  collection,
305
- ...rest,
382
+ refresh,
383
+ error,
384
+ loading: isLoading,
306
385
  };
307
386
  }
308
387
 
309
388
  function useDataSourceInstanceLocations(dataSourceInstance, args) {
310
389
  var _a;
311
390
  const integrationApp = useIntegrationApp();
312
- const { data, ...rest } = useGetter(dataSourceInstance
313
- ? `${dataSourceInstance.id}/${JSON.stringify(args)}`
314
- : undefined, () => integrationApp
391
+ const { data, error, isLoading, mutate } = useSWR(dataSourceInstance
392
+ ? `${dataSourceInstance.id}/locations?${qs.stringify(args)}`
393
+ : null, () => integrationApp
315
394
  .dataSourceInstance(dataSourceInstance.id)
316
395
  .getLocations(args));
396
+ async function refresh() {
397
+ return await mutate();
398
+ }
399
+ const locations = (_a = data === null || data === void 0 ? void 0 : data.locations) !== null && _a !== void 0 ? _a : [];
317
400
  return {
318
- locations: (_a = data === null || data === void 0 ? void 0 : data.locations) !== null && _a !== void 0 ? _a : [],
401
+ locations,
402
+ refresh,
403
+ error,
404
+ loading: isLoading,
405
+ };
406
+ }
407
+
408
+ function useDataSourceInstances(query) {
409
+ const { ...rest } = useElements('data-source-instances', query);
410
+ return {
411
+ dataSourceInstances: rest.items,
319
412
  ...rest,
320
413
  };
321
414
  }
322
415
 
323
- function useDataSourceEvents(query) {
324
- const { ...rest } = useElements(query, (integrationApp) => integrationApp.dataSourceEvents);
416
+ function useDataSources(query) {
417
+ const { ...rest } = useElements('data-sources', query);
325
418
  return {
419
+ dataSources: rest.items,
326
420
  ...rest,
327
421
  };
328
422
  }
329
423
 
330
- function useAppEvents(query) {
331
- const { ...rest } = useElements(query, (integrationApp) => integrationApp.appEvents);
424
+ function useAppEventSubscription(selector) {
425
+ const { item: appEventSubscription, ...rest } = useElement(selector, (integrationApp) => integrationApp.appEventSubscription(selector));
426
+ return { appEventSubscription, ...rest };
427
+ }
428
+
429
+ function useAppEventSubscriptions(query) {
430
+ const { ...rest } = useElements('app-event-subscriptions', query);
332
431
  return {
432
+ appEventSubscriptions: rest.items,
333
433
  ...rest,
334
434
  };
335
435
  }
336
436
 
337
- function useAppEventType(idOrKey) {
338
- const { data: appEventType, ...rest } = useElement(idOrKey, (integrationApp) => integrationApp.appEventType.bind(integrationApp));
437
+ function useAppEventType(id) {
438
+ const { item: appEventType, ...rest } = useElement(id, (integrationApp) => integrationApp.appEventType(id));
339
439
  return { appEventType, ...rest };
340
440
  }
341
441
 
342
442
  function useAppEventTypes(query) {
343
- const { ...rest } = useElements(query, (integrationApp) => integrationApp.appEventTypes);
443
+ const { ...rest } = useElements('app-event-types', query);
344
444
  return {
445
+ appEventTypes: rest.items,
345
446
  ...rest,
346
447
  };
347
448
  }
348
449
 
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);
450
+ function useAppEvents(query) {
451
+ const { ...rest } = useElements('app-events', query);
356
452
  return {
453
+ appEvents: rest.items,
357
454
  ...rest,
358
455
  };
359
456
  }
360
457
 
361
- function useFlow(idOrSelector) {
362
- const { data: flow, ...rest } = useElement(idOrSelector, (integrationApp) => integrationApp.flow.bind(integrationApp));
363
- return { flow, ...rest };
458
+ function useFlow(selector) {
459
+ const { item: flow, accessor, refresh, ...rest } = useElement(selector, (integrationApp) => integrationApp.flow(selector));
460
+ async function apply(integrationKeys) {
461
+ const result = await (accessor === null || accessor === void 0 ? void 0 : accessor.apply(integrationKeys));
462
+ await refresh();
463
+ return result;
464
+ }
465
+ async function reset() {
466
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.reset());
467
+ return await refresh();
468
+ }
469
+ return { flow, apply, reset, refresh, accessor, ...rest };
364
470
  }
365
471
 
366
472
  function useFlows(query) {
367
- const { ...rest } = useElements(query, (integrationApp) => integrationApp.flows);
368
- return { ...rest };
473
+ const { ...rest } = useElements('flows', query);
474
+ return {
475
+ flows: rest.items,
476
+ ...rest,
477
+ };
369
478
  }
370
479
 
371
- function useFlowInstance(props) {
372
- const { data: flowInstance, ...rest } = useElement(props, (integrationApp) => integrationApp.flowInstance.bind(integrationApp));
373
- return { flowInstance, ...rest };
480
+ function useFlowInstance(selector) {
481
+ const { item: flowInstance, accessor, refresh, ...rest } = useElement(selector, (integrationApp) => integrationApp.flowInstance(selector));
482
+ async function enable() {
483
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.enable());
484
+ await refresh();
485
+ }
486
+ async function disable() {
487
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.disable());
488
+ await refresh();
489
+ }
490
+ async function reset() {
491
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.reset());
492
+ await refresh();
493
+ }
494
+ async function setup() {
495
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.setup());
496
+ await refresh();
497
+ }
498
+ async function openConfiguration(options) {
499
+ return accessor === null || accessor === void 0 ? void 0 : accessor.openConfiguration(options);
500
+ }
501
+ async function run(options = {}) {
502
+ return accessor === null || accessor === void 0 ? void 0 : accessor.run(options);
503
+ }
504
+ async function startRun(options = {}) {
505
+ return accessor === null || accessor === void 0 ? void 0 : accessor.startRun(options);
506
+ }
507
+ return {
508
+ flowInstance,
509
+ accessor,
510
+ refresh,
511
+ enable,
512
+ disable,
513
+ reset,
514
+ setup,
515
+ openConfiguration,
516
+ run,
517
+ startRun,
518
+ ...rest,
519
+ };
374
520
  }
375
521
 
376
522
  function useFlowInstances(query) {
377
- const { ...rest } = useElements(query, (integrationApp) => integrationApp.flowInstances);
523
+ const { ...rest } = useElements('flow-instances', query);
378
524
  return {
525
+ flowInstances: rest.items,
379
526
  ...rest,
380
527
  };
381
528
  }
382
529
 
383
530
  function useFlowRun(id) {
384
- const { data: flowRun, ...rest } = useElement(id, (integrationApp) => integrationApp.flowRun.bind(integrationApp));
385
- return { flowRun, ...rest };
531
+ const { item: flowRun, archive, refresh, error, loading, } = useElement(id, (integrationApp) => integrationApp.flowRun(id));
532
+ return {
533
+ flowRun,
534
+ error,
535
+ loading,
536
+ refresh,
537
+ archive,
538
+ };
386
539
  }
387
540
 
388
541
  function useFlowRuns(query) {
389
- const { ...rest } = useElements(query, (integrationApp) => integrationApp.flowRuns);
390
- return { ...rest };
542
+ const { ...rest } = useElements('flow-runs', query);
543
+ return {
544
+ flowRuns: rest.items,
545
+ ...rest,
546
+ };
547
+ }
548
+
549
+ function useDataLinkTable(selector) {
550
+ const { item: dataLinkTable, ...rest } = useElement(selector, (integrationApp) => integrationApp.dataLinkTable(selector));
551
+ return { dataLinkTable, ...rest };
552
+ }
553
+
554
+ function useDataLinkTableInstance(selector) {
555
+ const { item: dataLinkTableInstance, accessor, refresh, ...rest } = useElement(selector, (integrationApp) => integrationApp.dataLinkTableInstance(selector));
556
+ return {
557
+ dataLinkTableInstance,
558
+ accessor,
559
+ refresh,
560
+ findLinks: accessor === null || accessor === void 0 ? void 0 : accessor.findLinks,
561
+ createLink: accessor === null || accessor === void 0 ? void 0 : accessor.createLink,
562
+ deleteLink: accessor === null || accessor === void 0 ? void 0 : accessor.deleteLink,
563
+ ...rest,
564
+ };
565
+ }
566
+
567
+ function useDataLinkTableInstances(query) {
568
+ const { ...rest } = useElements('data-link-table-instances', query);
569
+ return {
570
+ dataLinkTableInstances: rest.items,
571
+ ...rest,
572
+ };
573
+ }
574
+
575
+ function useDataLinkTables(query) {
576
+ const { ...rest } = useElements('data-link-tables', query);
577
+ return {
578
+ dataLinkTables: rest.items,
579
+ ...rest,
580
+ };
581
+ }
582
+
583
+ function useAction(selector) {
584
+ const { item: action, accessor, refresh, ...rest } = useElement(selector, (integrationApp) => integrationApp.action(selector));
585
+ async function apply(integrationKeys) {
586
+ const result = await (accessor === null || accessor === void 0 ? void 0 : accessor.apply(integrationKeys));
587
+ await refresh();
588
+ return result;
589
+ }
590
+ async function reset() {
591
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.reset());
592
+ await refresh();
593
+ }
594
+ return { action, apply, reset, refresh, accessor, ...rest };
595
+ }
596
+
597
+ function useActionInstance(selector) {
598
+ const { item: actionInstance, accessor, refresh, ...rest } = useElement(selector, (integrationApp) => integrationApp.actionInstance(selector));
599
+ async function run(input) {
600
+ return accessor === null || accessor === void 0 ? void 0 : accessor.run(input);
601
+ }
602
+ async function setup() {
603
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.setup());
604
+ await refresh();
605
+ }
606
+ async function reset() {
607
+ await (accessor === null || accessor === void 0 ? void 0 : accessor.reset());
608
+ await refresh();
609
+ }
610
+ async function openConfiguration(options) {
611
+ return accessor === null || accessor === void 0 ? void 0 : accessor.open(options);
612
+ }
613
+ return {
614
+ actionInstance,
615
+ accessor,
616
+ refresh,
617
+ setup,
618
+ reset,
619
+ openConfiguration,
620
+ run,
621
+ ...rest,
622
+ };
623
+ }
624
+
625
+ function useActionInstances(query) {
626
+ const { ...rest } = useElements('action-instances', query);
627
+ return {
628
+ actionInstances: rest.items,
629
+ ...rest,
630
+ };
631
+ }
632
+
633
+ function useActions(query) {
634
+ const { ...rest } = useElements('actions', query);
635
+ return {
636
+ actions: rest.items,
637
+ ...rest,
638
+ };
639
+ }
640
+
641
+ function useScreen(selector) {
642
+ const { item: screen, ...rest } = useElement(selector, (integrationApp) => integrationApp.screen(selector));
643
+ return { screen, ...rest };
644
+ }
645
+
646
+ function useCustomer(selector) {
647
+ const { item: customer, ...rest } = useElement(selector, (c) => c.customer(selector));
648
+ return { customer, ...rest };
649
+ }
650
+
651
+ function useCustomers(query) {
652
+ const { ...rest } = useElements('users', query);
653
+ return {
654
+ customers: rest.items,
655
+ ...rest,
656
+ };
657
+ }
658
+
659
+ function useDataCollectionSpec({ path, key, integrationId, }) {
660
+ var _a;
661
+ const client = useIntegrationApp();
662
+ const dataCollectionKey = key !== null && key !== void 0 ? key : (_a = sdk.parseDataLocationPath(path)) === null || _a === void 0 ? void 0 : _a.key;
663
+ const { data: dataCollectionSpec } = useSWR(dataCollectionKey && integrationId
664
+ ? `/integrations/${integrationId}/data/${dataCollectionKey}`
665
+ : null, () => client.integration(integrationId).getDataLocation(dataCollectionKey));
666
+ return dataCollectionSpec;
391
667
  }
392
668
 
393
669
  Object.defineProperty(exports, 'DataForm', {
@@ -395,6 +671,10 @@
395
671
  get: function () { return sdk.DataForm; }
396
672
  });
397
673
  exports.IntegrationAppProvider = IntegrationAppProvider;
674
+ exports.useAction = useAction;
675
+ exports.useActionInstance = useActionInstance;
676
+ exports.useActionInstances = useActionInstances;
677
+ exports.useActions = useActions;
398
678
  exports.useAppEventSubscription = useAppEventSubscription;
399
679
  exports.useAppEventSubscriptions = useAppEventSubscriptions;
400
680
  exports.useAppEventType = useAppEventType;
@@ -403,12 +683,19 @@
403
683
  exports.useConnection = useConnection;
404
684
  exports.useConnections = useConnections;
405
685
  exports.useConnectorSpec = useConnectorSpec;
686
+ exports.useCustomer = useCustomer;
687
+ exports.useCustomers = useCustomers;
688
+ exports.useDataCollectionSpec = useDataCollectionSpec;
689
+ exports.useDataLinkTable = useDataLinkTable;
690
+ exports.useDataLinkTableInstance = useDataLinkTableInstance;
691
+ exports.useDataLinkTableInstances = useDataLinkTableInstances;
692
+ exports.useDataLinkTables = useDataLinkTables;
406
693
  exports.useDataSource = useDataSource;
407
- exports.useDataSourceCollection = useDataSourceInstanceCollection;
408
694
  exports.useDataSourceEvents = useDataSourceEvents;
409
695
  exports.useDataSourceInstance = useDataSourceInstance;
696
+ exports.useDataSourceInstanceCollection = useDataSourceInstanceCollection;
697
+ exports.useDataSourceInstanceLocations = useDataSourceInstanceLocations;
410
698
  exports.useDataSourceInstances = useDataSourceInstances;
411
- exports.useDataSourceLocations = useDataSourceInstanceLocations;
412
699
  exports.useDataSources = useDataSources;
413
700
  exports.useFieldMapping = useFieldMapping;
414
701
  exports.useFieldMappingInstance = useFieldMappingInstance;
@@ -422,7 +709,9 @@
422
709
  exports.useFlows = useFlows;
423
710
  exports.useIntegration = useIntegration;
424
711
  exports.useIntegrationApp = useIntegrationApp;
712
+ exports.useIntegrationAppSWR = useIntegrationAppSWR;
425
713
  exports.useIntegrations = useIntegrations;
714
+ exports.useScreen = useScreen;
426
715
 
427
716
  }));
428
717
  //# sourceMappingURL=index.umd.js.map