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