@integration-app/react 2.0.0-beta.0 → 2.0.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/dist/index.umd.js DELETED
@@ -1,799 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@integration-app/sdk'), require('react/jsx-runtime'), require('react'), require('swr'), require('awesome-debounce-promise'), require('swr/infinite'), require('query-string')) :
3
- typeof define === 'function' && define.amd ? define(['exports', '@integration-app/sdk', 'react/jsx-runtime', 'react', 'swr', 'awesome-debounce-promise', 'swr/infinite', 'query-string'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.integrationAppReact = {}, global.sdk, global.jsxRuntime, global.react, global.useSWR, global.AwesomeDebouncePromiseImport, global.useSWRInfinite, global.qs));
5
- })(this, (function (exports, sdk, jsxRuntime, react, useSWR, AwesomeDebouncePromiseImport, useSWRInfinite, qs) { 'use strict';
6
-
7
- const IntegrationAppContext = react.createContext(null);
8
- IntegrationAppContext.displayName = 'IntegrationAppClientContext';
9
- const IntegrationAppProvider = ({ token, fetchToken, credentials, fetchCredentials, apiUri = null, uiUri = null, children, }) => {
10
- const client = react.useMemo(() => new sdk.IntegrationAppClient({
11
- token,
12
- fetchToken,
13
- credentials,
14
- fetchCredentials,
15
- apiUri,
16
- uiUri,
17
- }), [token, JSON.stringify(credentials), apiUri, uiUri]);
18
- return (jsxRuntime.jsx(IntegrationAppContext.Provider, { value: client, children: children }));
19
- };
20
- function useIntegrationApp() {
21
- return react.useContext(IntegrationAppContext);
22
- }
23
-
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);
31
- }
32
-
33
- var _a;
34
- const AwesomeDebouncePromise = (_a = AwesomeDebouncePromiseImport === null || AwesomeDebouncePromiseImport === void 0 ? void 0 : AwesomeDebouncePromiseImport.default) !== null && _a !== void 0 ? _a : AwesomeDebouncePromiseImport;
35
-
36
- const elementStateCache = new Map();
37
- function useElement(selector, accessorGenerator) {
38
- var _a;
39
- const integrationApp = useIntegrationApp();
40
- const elementKeyData = {
41
- token: integrationApp === null || integrationApp === void 0 ? void 0 : integrationApp.token,
42
- selector,
43
- };
44
- const elementKey = JSON.stringify(elementKeyData);
45
- const elementState = (_a = elementStateCache.get(elementKey)) !== null && _a !== void 0 ? _a : {
46
- updatedLocally: false,
47
- savingToServer: false,
48
- currentPutRequests: [],
49
- debouncedPut: AwesomeDebouncePromise(async (data) => {
50
- const requestId = Math.random();
51
- elementState.currentPutRequests.push(requestId);
52
- elementState.updatedLocally = false;
53
- elementState.savingToServer = true;
54
- try {
55
- const result = await (accessor === null || accessor === void 0 ? void 0 : accessor.put(data));
56
- elementState.currentPutRequests =
57
- elementState.currentPutRequests.filter((id) => id !== requestId);
58
- if (!elementState.updatedLocally &&
59
- elementState.currentPutRequests.length === 0) {
60
- elementState.savingToServer = false;
61
- await mutate(result, false);
62
- }
63
- }
64
- catch (e) {
65
- elementState.updatedLocally = true;
66
- throw e;
67
- }
68
- finally {
69
- elementState.savingToServer = false;
70
- }
71
- }, 500),
72
- };
73
- if (!elementStateCache.has(elementKey)) {
74
- elementStateCache.set(elementKey, elementState);
75
- }
76
- const accessor = integrationApp
77
- ? accessorGenerator(integrationApp)
78
- : undefined;
79
- const swrKey = accessor && selector ? `element:${elementKey}` : undefined;
80
- const { data: item, mutate, error, isLoading, isValidating, } = useSWR(swrKey, () => accessor === null || accessor === void 0 ? void 0 : accessor.get(), {
81
- isPaused: () => elementState.updatedLocally || elementState.savingToServer,
82
- });
83
- const loading = isLoading;
84
- const refreshing = isValidating;
85
- async function refresh() {
86
- return await mutate();
87
- }
88
- async function put(data) {
89
- if (!(accessor === null || accessor === void 0 ? void 0 : accessor.put)) {
90
- throw new Error(`"put method is not supported for accessor ${accessor.constructor.name}`);
91
- }
92
- elementState.updatedLocally = true;
93
- const newLocalData = {
94
- ...item,
95
- ...data,
96
- };
97
- await mutate(newLocalData, false);
98
- await elementState.debouncedPut(data);
99
- }
100
- async function patch(data) {
101
- const newData = {
102
- ...item,
103
- ...data,
104
- };
105
- return put(newData);
106
- }
107
- async function archive() {
108
- if (!(accessor === null || accessor === void 0 ? void 0 : accessor.archive)) {
109
- return;
110
- }
111
- await mutate({ ...item, archivedAt: new Date().toISOString() }, false);
112
- await (accessor === null || accessor === void 0 ? void 0 : accessor.archive());
113
- await mutate();
114
- }
115
- async function create(data) {
116
- if (!(accessor === null || accessor === void 0 ? void 0 : accessor.create)) {
117
- throw new Error(`"create method is not supported for accessor ${accessor === null || accessor === void 0 ? void 0 : accessor.constructor.name}`);
118
- }
119
- const result = await (accessor === null || accessor === void 0 ? void 0 : accessor.create(data));
120
- return await mutate(result);
121
- }
122
- return {
123
- accessor,
124
- item,
125
- loading,
126
- saving: elementState.updatedLocally || elementState.savingToServer,
127
- error,
128
- refresh,
129
- refreshing,
130
- create,
131
- patch,
132
- put,
133
- archive,
134
- };
135
- }
136
-
137
- function useConnection(id) {
138
- const { item: connection, ...rest } = useElement(id, (integrationApp) => (id ? integrationApp.connection(id) : undefined));
139
- return {
140
- connection,
141
- ...rest,
142
- };
143
- }
144
-
145
- function useElements(route, query = {}) {
146
- var _a;
147
- const integrationApp = useIntegrationApp();
148
- const limit = (_a = query.limit) !== null && _a !== void 0 ? _a : 25;
149
- const tokenHash = hashCode(integrationApp.token);
150
- function getKey(page, previousPageData) {
151
- var _a;
152
- if (page === 0)
153
- return `/${route}?${qs.stringify({
154
- ...query,
155
- limit,
156
- hash: tokenHash,
157
- })}`;
158
- if (((_a = previousPageData.items) === null || _a === void 0 ? void 0 : _a.length) < limit)
159
- return null;
160
- return `/${route}?${qs.stringify({
161
- ...query,
162
- limit,
163
- cursor: previousPageData.cursor,
164
- hash: tokenHash,
165
- })}`;
166
- }
167
- const [loadingMore, setIsLoadingMore] = react.useState(false);
168
- const { data, size, setSize, isLoading, error, mutate, isValidating } = useSWRInfinite(getKey, (url) => integrationApp.get(url));
169
- const items = data ? data.map((page) => page.items).flat() : [];
170
- const loading = isLoading;
171
- const refreshing = isValidating;
172
- async function loadMore() {
173
- var _a, _b;
174
- const hasMoreToLoad = ((_b = (_a = data[size - 1]) === null || _a === void 0 ? void 0 : _a.items) === null || _b === void 0 ? void 0 : _b.length) === limit;
175
- if (hasMoreToLoad) {
176
- setIsLoadingMore(true);
177
- await setSize(size + 1);
178
- setIsLoadingMore(false);
179
- }
180
- }
181
- async function refresh() {
182
- await mutate();
183
- }
184
- return {
185
- items,
186
- refresh,
187
- refreshing,
188
- loadMore,
189
- loadingMore,
190
- loading,
191
- error,
192
- };
193
- }
194
- function hashCode(s) {
195
- if (!s) {
196
- return 0;
197
- }
198
- const l = s.length;
199
- let h = 0, i = 0;
200
- if (l > 0)
201
- while (i < l)
202
- h = ((h << 5) - h + s.charCodeAt(i++)) | 0;
203
- return h;
204
- }
205
-
206
- function useConnections(query) {
207
- const { ...rest } = useElements('connections', query);
208
- return {
209
- connections: rest.items,
210
- ...rest,
211
- };
212
- }
213
-
214
- function useConnectorSpec(integrationIdOrKey) {
215
- const integrationApp = useIntegrationApp();
216
- const { data, isLoading, error } = useSWR(integrationIdOrKey
217
- ? `/integrations/${integrationIdOrKey}/connector-spec`
218
- : undefined, () => integrationApp.integration(integrationIdOrKey).getConnectorSpec());
219
- return { data, loading: isLoading, error };
220
- }
221
-
222
- function useIntegration(idOrKey) {
223
- const { item: integration, ...rest } = useElement(idOrKey, (integrationApp) => idOrKey ? integrationApp.integration(idOrKey) : undefined);
224
- return { integration, ...rest };
225
- }
226
-
227
- function useIntegrations(query) {
228
- const { ...rest } = useElements('integrations', query);
229
- return {
230
- integrations: rest.items,
231
- ...rest,
232
- };
233
- }
234
-
235
- function useFieldMapping(selector) {
236
- const { item: fieldMapping, accessor, refresh, ...rest } = useElement(selector, (integrationApp) => selector ? integrationApp.fieldMapping(selector) : undefined);
237
- async function apply(integrationKeys) {
238
- const result = await (accessor === null || accessor === void 0 ? void 0 : accessor.apply(integrationKeys));
239
- await refresh();
240
- return result !== null && result !== void 0 ? result : [];
241
- }
242
- async function reset() {
243
- await (accessor === null || accessor === void 0 ? void 0 : accessor.reset());
244
- await refresh();
245
- }
246
- return { fieldMapping, apply, reset, refresh, accessor, ...rest };
247
- }
248
-
249
- function useFieldMappingInstance(selector) {
250
- const { item: fieldMappingInstance, accessor, refresh, ...rest } = useElement(selector, (integrationApp) => selector ? integrationApp.fieldMappingInstance(selector) : undefined);
251
- async function setup() {
252
- await (accessor === null || accessor === void 0 ? void 0 : accessor.setup());
253
- await refresh();
254
- }
255
- async function reset() {
256
- await (accessor === null || accessor === void 0 ? void 0 : accessor.reset());
257
- await refresh();
258
- }
259
- async function openConfiguration(options) {
260
- return accessor === null || accessor === void 0 ? void 0 : accessor.openConfiguration(options);
261
- }
262
- return {
263
- fieldMappingInstance,
264
- accessor,
265
- refresh,
266
- setup,
267
- reset,
268
- openConfiguration,
269
- ...rest,
270
- };
271
- }
272
-
273
- function useFieldMappingInstances(query) {
274
- const { ...rest } = useElements('field-mapping-instances', query);
275
- return {
276
- fieldMappingInstances: rest.items,
277
- ...rest,
278
- };
279
- }
280
-
281
- function useFieldMappings(query) {
282
- const { ...rest } = useElements('field-mappings', query);
283
- return {
284
- fieldMappings: rest.items,
285
- ...rest,
286
- };
287
- }
288
-
289
- function useDataSource(selector) {
290
- const { item: dataSource, refresh, accessor, ...rest } = useElement(selector, (integrationApp) => selector ? integrationApp.dataSource(selector) : undefined);
291
- async function apply(integrationKeys) {
292
- const result = await (accessor === null || accessor === void 0 ? void 0 : accessor.apply(integrationKeys));
293
- await refresh();
294
- return result !== null && result !== void 0 ? result : [];
295
- }
296
- async function reset() {
297
- await (accessor === null || accessor === void 0 ? void 0 : accessor.reset());
298
- await refresh();
299
- }
300
- return { dataSource, apply, reset, refresh, accessor, ...rest };
301
- }
302
-
303
- function useDataSourceInstance(selector) {
304
- const { item: dataSourceInstance, accessor, refresh, ...rest } = useElement(selector, (integrationApp) => selector ? integrationApp.dataSourceInstance(selector) : undefined);
305
- async function setup() {
306
- await (accessor === null || accessor === void 0 ? void 0 : accessor.setup());
307
- await refresh();
308
- }
309
- async function reset() {
310
- await (accessor === null || accessor === void 0 ? void 0 : accessor.reset());
311
- await refresh();
312
- }
313
- async function openConfiguration(options) {
314
- return accessor === null || accessor === void 0 ? void 0 : accessor.openConfiguration(options);
315
- }
316
- async function listRecords(request) {
317
- return accessor === null || accessor === void 0 ? void 0 : accessor.listRecords(request);
318
- }
319
- async function findRecords(request) {
320
- return accessor === null || accessor === void 0 ? void 0 : accessor.findRecords(request);
321
- }
322
- async function findRecordById(id) {
323
- return accessor === null || accessor === void 0 ? void 0 : accessor.findRecordById(id);
324
- }
325
- async function createRecord(request) {
326
- return accessor === null || accessor === void 0 ? void 0 : accessor.createRecord(request);
327
- }
328
- async function updateRecord(request) {
329
- return accessor === null || accessor === void 0 ? void 0 : accessor.updateRecord(request);
330
- }
331
- async function deleteRecord(id) {
332
- return accessor === null || accessor === void 0 ? void 0 : accessor.deleteRecord(id);
333
- }
334
- async function unifiedFieldsToNative(unifiedFields) {
335
- return accessor === null || accessor === void 0 ? void 0 : accessor.unifiedFieldsToNative(unifiedFields);
336
- }
337
- async function getCollection() {
338
- return accessor === null || accessor === void 0 ? void 0 : accessor.getCollection();
339
- }
340
- return {
341
- dataSourceInstance,
342
- accessor,
343
- refresh,
344
- setup,
345
- reset,
346
- openConfiguration,
347
- listRecords,
348
- findRecords,
349
- findRecordById,
350
- createRecord,
351
- updateRecord,
352
- deleteRecord,
353
- unifiedFieldsToNative,
354
- getCollection,
355
- ...rest,
356
- };
357
- }
358
-
359
- function useDataSourceInstanceCollection(dataSourceInstance) {
360
- const integrationApp = useIntegrationApp();
361
- const { data, error, isLoading, mutate } = useSWR(dataSourceInstance ? `${dataSourceInstance.id}/collection` : null, () => integrationApp.dataSourceInstance(dataSourceInstance.id).getCollection());
362
- async function refresh() {
363
- return await mutate();
364
- }
365
- const collection = data;
366
- return {
367
- collection,
368
- refresh,
369
- error,
370
- loading: isLoading,
371
- };
372
- }
373
-
374
- function useDataSourceInstances(query) {
375
- const { ...rest } = useElements('data-source-instances', query);
376
- return {
377
- dataSourceInstances: rest.items,
378
- ...rest,
379
- };
380
- }
381
-
382
- function useDataSources(query) {
383
- const { ...rest } = useElements('data-sources', query);
384
- return {
385
- dataSources: rest.items,
386
- ...rest,
387
- };
388
- }
389
-
390
- function useAppEventSubscription(selector) {
391
- const { item: appEventSubscription, ...rest } = useElement(selector, (integrationApp) => selector ? integrationApp.appEventSubscription(selector) : undefined);
392
- return { appEventSubscription, ...rest };
393
- }
394
-
395
- function useAppEventSubscriptions(query) {
396
- const { ...rest } = useElements('app-event-subscriptions', query);
397
- return {
398
- appEventSubscriptions: rest.items,
399
- ...rest,
400
- };
401
- }
402
-
403
- function useAppEventType(selector) {
404
- const { item: appEventType, ...rest } = useElement(selector, (integrationApp) => selector ? integrationApp.appEventType(selector) : undefined);
405
- return { appEventType, ...rest };
406
- }
407
-
408
- function useAppEventTypes(query) {
409
- const { ...rest } = useElements('app-event-types', query);
410
- return {
411
- appEventTypes: rest.items,
412
- ...rest,
413
- };
414
- }
415
-
416
- function useAppEvents(query) {
417
- const { ...rest } = useElements('app-events', query);
418
- return {
419
- appEvents: rest.items,
420
- ...rest,
421
- };
422
- }
423
-
424
- function useAppDataSchema(selector) {
425
- const { item: appDataSchema, ...rest } = useElement(selector, (integrationApp) => selector ? integrationApp.appDataSchema(selector) : undefined);
426
- return { appDataSchema, ...rest };
427
- }
428
-
429
- function useAppDataSchemas(query) {
430
- const { ...rest } = useElements('app-data-schemas', query);
431
- return {
432
- appDataSchemas: rest.items,
433
- ...rest,
434
- };
435
- }
436
-
437
- function useAppDataSchemaInstance(selector) {
438
- const { item: appDataSchemaInstance, accessor, refresh, ...rest } = useElement(selector, (integrationApp) => selector ? integrationApp.appDataSchemaInstance(selector) : undefined);
439
- async function setup() {
440
- await (accessor === null || accessor === void 0 ? void 0 : accessor.setup());
441
- await refresh();
442
- }
443
- return {
444
- appDataSchemaInstance,
445
- accessor,
446
- refresh,
447
- setup,
448
- ...rest,
449
- };
450
- }
451
-
452
- function useAppDataSchemaInstances(query) {
453
- const { ...rest } = useElements('app-data-schema-instances', query);
454
- return {
455
- appDataSchemaInstances: rest.items,
456
- ...rest,
457
- };
458
- }
459
-
460
- function useFlow(selector) {
461
- const { item: flow, accessor, refresh, ...rest } = useElement(selector, (integrationApp) => (selector ? integrationApp.flow(selector) : undefined));
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 };
472
- }
473
-
474
- function useFlows(query) {
475
- const { ...rest } = useElements('flows', query);
476
- return {
477
- flows: rest.items,
478
- ...rest,
479
- };
480
- }
481
-
482
- function useFlowInstance(selector) {
483
- const { item: flowInstance, accessor, refresh, ...rest } = useElement(selector, (integrationApp) => selector ? integrationApp.flowInstance(selector) : undefined);
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(options) {
493
- await (accessor === null || accessor === void 0 ? void 0 : accessor.reset(options));
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
- };
522
- }
523
-
524
- function useFlowInstances(query) {
525
- const { ...rest } = useElements('flow-instances', query);
526
- return {
527
- flowInstances: rest.items,
528
- ...rest,
529
- };
530
- }
531
-
532
- function useFlowRun(id) {
533
- const { item: flowRun, archive, refresh, error, loading, } = useElement(id, (integrationApp) => id ? integrationApp.flowRun(id) : undefined);
534
- return {
535
- flowRun,
536
- error,
537
- loading,
538
- refresh,
539
- archive,
540
- };
541
- }
542
-
543
- function useFlowRuns(query) {
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) => selector ? integrationApp.dataLinkTable(selector) : undefined);
553
- return { dataLinkTable, ...rest };
554
- }
555
-
556
- function useDataLinkTableInstance(selector) {
557
- const { item: dataLinkTableInstance, accessor, refresh, ...rest } = useElement(selector, (integrationApp) => selector ? integrationApp.dataLinkTableInstance(selector) : undefined);
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) => selector ? integrationApp.action(selector) : undefined);
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) => selector ? integrationApp.actionInstance(selector) : undefined);
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 useCustomer(selector) {
649
- const { item: customer, ...rest } = useElement(selector, (c) => (selector ? c.customer(selector) : undefined));
650
- return { customer, ...rest };
651
- }
652
-
653
- function useCustomers(query) {
654
- const { ...rest } = useElements('customers', query);
655
- return {
656
- customers: rest.items,
657
- ...rest,
658
- };
659
- }
660
-
661
- function useScenario(selector) {
662
- const { item: scenario, ...rest } = useElement(selector, (integrationApp) => selector ? integrationApp.scenario(selector) : undefined);
663
- return { scenario, ...rest };
664
- }
665
-
666
- function useScenarios(query) {
667
- const { ...rest } = useElements('scenarios', query);
668
- return {
669
- scenarios: rest.items,
670
- ...rest,
671
- };
672
- }
673
-
674
- function useDataCollectionSpec({ path, key, integrationId, }) {
675
- var _a;
676
- const client = useIntegrationApp();
677
- const dataCollectionKey = key !== null && key !== void 0 ? key : (_a = sdk.parseDataLocationPath(path)) === null || _a === void 0 ? void 0 : _a.key;
678
- const { data: dataCollectionSpec } = useSWR(dataCollectionKey && integrationId
679
- ? `/integrations/${integrationId}/data/${dataCollectionKey}`
680
- : null, async () => {
681
- return client
682
- .integration(integrationId)
683
- .getDataCollection(dataCollectionKey);
684
- });
685
- return dataCollectionSpec;
686
- }
687
-
688
- function useExternalEventSubscriptions(query) {
689
- const { ...rest } = useElements('external-event-subscriptions', query);
690
- return {
691
- externalEventSubscriptions: rest.items,
692
- ...rest,
693
- };
694
- }
695
-
696
- function useExternalEventSubscription(id) {
697
- const { item: externalEventSubscription, accessor, refresh, ...rest } = useElement(id, (integrationApp) => id ? integrationApp.externalEventSubscription(id) : undefined);
698
- async function setup() {
699
- await (accessor === null || accessor === void 0 ? void 0 : accessor.setup());
700
- await refresh();
701
- }
702
- async function subscribe() {
703
- await (accessor === null || accessor === void 0 ? void 0 : accessor.subscribe());
704
- await refresh();
705
- }
706
- async function resubscribe() {
707
- await (accessor === null || accessor === void 0 ? void 0 : accessor.resubscribe());
708
- await refresh();
709
- }
710
- async function unsubscribe() {
711
- await (accessor === null || accessor === void 0 ? void 0 : accessor.unsubscribe());
712
- await refresh();
713
- }
714
- async function pullEvents() {
715
- await (accessor === null || accessor === void 0 ? void 0 : accessor.pullEvents());
716
- await refresh();
717
- }
718
- return {
719
- externalEventSubscription,
720
- accessor,
721
- refresh,
722
- setup,
723
- subscribe,
724
- resubscribe,
725
- unsubscribe,
726
- pullEvents,
727
- ...rest,
728
- };
729
- }
730
-
731
- function useIntegrationElement(accessor) {
732
- if (!accessor.getUniqueIdentifier) {
733
- throw new Error('This accessor can not be used for with `useIntegrationElement` hook. Method `getUniqueIdentifier` is missing.');
734
- }
735
- return useElement(accessor.getUniqueIdentifier(), () => accessor);
736
- }
737
-
738
- Object.defineProperty(exports, "DataForm", {
739
- enumerable: true,
740
- get: function () { return sdk.DataForm; }
741
- });
742
- exports.IntegrationAppProvider = IntegrationAppProvider;
743
- exports.useAction = useAction;
744
- exports.useActionInstance = useActionInstance;
745
- exports.useActionInstances = useActionInstances;
746
- exports.useActions = useActions;
747
- exports.useAppDataSchema = useAppDataSchema;
748
- exports.useAppDataSchemaInstance = useAppDataSchemaInstance;
749
- exports.useAppDataSchemaInstances = useAppDataSchemaInstances;
750
- exports.useAppDataSchemas = useAppDataSchemas;
751
- exports.useAppEventSubscription = useAppEventSubscription;
752
- exports.useAppEventSubscriptions = useAppEventSubscriptions;
753
- exports.useAppEventType = useAppEventType;
754
- exports.useAppEventTypes = useAppEventTypes;
755
- exports.useAppEvents = useAppEvents;
756
- exports.useConnection = useConnection;
757
- exports.useConnections = useConnections;
758
- exports.useConnectorSpec = useConnectorSpec;
759
- exports.useCustomer = useCustomer;
760
- exports.useCustomers = useCustomers;
761
- exports.useDataCollectionSpec = useDataCollectionSpec;
762
- exports.useDataLinkTable = useDataLinkTable;
763
- exports.useDataLinkTableInstance = useDataLinkTableInstance;
764
- exports.useDataLinkTableInstances = useDataLinkTableInstances;
765
- exports.useDataLinkTables = useDataLinkTables;
766
- exports.useDataSource = useDataSource;
767
- exports.useDataSourceInstance = useDataSourceInstance;
768
- exports.useDataSourceInstanceCollection = useDataSourceInstanceCollection;
769
- exports.useDataSourceInstances = useDataSourceInstances;
770
- exports.useDataSources = useDataSources;
771
- exports.useExternalEventSubscription = useExternalEventSubscription;
772
- exports.useExternalEventSubscriptions = useExternalEventSubscriptions;
773
- exports.useFieldMapping = useFieldMapping;
774
- exports.useFieldMappingInstance = useFieldMappingInstance;
775
- exports.useFieldMappingInstances = useFieldMappingInstances;
776
- exports.useFieldMappings = useFieldMappings;
777
- exports.useFlow = useFlow;
778
- exports.useFlowInstance = useFlowInstance;
779
- exports.useFlowInstances = useFlowInstances;
780
- exports.useFlowRun = useFlowRun;
781
- exports.useFlowRuns = useFlowRuns;
782
- exports.useFlows = useFlows;
783
- exports.useIntegration = useIntegration;
784
- exports.useIntegrationApp = useIntegrationApp;
785
- exports.useIntegrationAppSWR = useIntegrationAppSWR;
786
- exports.useIntegrationElement = useIntegrationElement;
787
- exports.useIntegrations = useIntegrations;
788
- exports.useScenario = useScenario;
789
- exports.useScenarios = useScenarios;
790
- exports.useScreen = useScreen;
791
- Object.keys(sdk).forEach(function (k) {
792
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
793
- enumerable: true,
794
- get: function () { return sdk[k]; }
795
- });
796
- });
797
-
798
- }));
799
- //# sourceMappingURL=index.umd.js.map