@integration-app/react 0.3.8 → 0.3.9
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.ts +34 -29
- package/dist/index.js +49 -42
- package/dist/index.js.map +1 -1
- package/dist/index.module.d.ts +34 -29
- package/dist/index.module.mjs +48 -42
- package/dist/index.module.mjs.map +1 -1
- package/dist/index.umd.d.ts +34 -29
- package/dist/index.umd.js +49 -42
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -2
- package/src/data-sources/useDataSource.ts +2 -2
- package/src/data-sources/useDataSourceInstance.ts +0 -35
- package/src/external-events/useExternalEventSubscription.ts +60 -0
- package/src/external-events/useExternalEventSubscriptions.ts +19 -0
- package/src/field-mappings/useFieldMapping.ts +1 -3
- package/src/hooks/useElement.tsx +1 -1
- package/src/index.tsx +3 -1
- package/src/integrations/useConnection.ts +2 -2
- package/src/data-sources/useDataSourceEvents.ts +0 -14
@@ -0,0 +1,60 @@
|
|
1
|
+
import {
|
2
|
+
ExternalEventSubscription,
|
3
|
+
ExternalEventSubscriptionAccessor,
|
4
|
+
} from '@integration-app/sdk'
|
5
|
+
import { useElement } from '../hooks/useElement'
|
6
|
+
|
7
|
+
export function useExternalEventSubscription(id: string | undefined) {
|
8
|
+
const {
|
9
|
+
item: externalEventSubscription,
|
10
|
+
accessor,
|
11
|
+
refresh,
|
12
|
+
...rest
|
13
|
+
} = useElement<
|
14
|
+
ExternalEventSubscription,
|
15
|
+
undefined,
|
16
|
+
undefined,
|
17
|
+
ExternalEventSubscriptionAccessor
|
18
|
+
>(id, (integrationApp) =>
|
19
|
+
id ? integrationApp.externalEventSubscription(id) : undefined,
|
20
|
+
)
|
21
|
+
|
22
|
+
async function setup() {
|
23
|
+
await accessor?.setup()
|
24
|
+
await refresh()
|
25
|
+
}
|
26
|
+
|
27
|
+
async function subscribe() {
|
28
|
+
await accessor?.subscribe()
|
29
|
+
await refresh()
|
30
|
+
}
|
31
|
+
|
32
|
+
async function resubscribe() {
|
33
|
+
await accessor?.resubscribe()
|
34
|
+
await refresh()
|
35
|
+
}
|
36
|
+
|
37
|
+
async function unsubscribe() {
|
38
|
+
await accessor?.unsubscribe()
|
39
|
+
await refresh()
|
40
|
+
}
|
41
|
+
|
42
|
+
async function pullEvents() {
|
43
|
+
await accessor?.pullEvents()
|
44
|
+
await refresh()
|
45
|
+
}
|
46
|
+
|
47
|
+
return {
|
48
|
+
externalEventSubscription,
|
49
|
+
accessor,
|
50
|
+
refresh,
|
51
|
+
|
52
|
+
setup,
|
53
|
+
subscribe,
|
54
|
+
resubscribe,
|
55
|
+
unsubscribe,
|
56
|
+
pullEvents,
|
57
|
+
|
58
|
+
...rest,
|
59
|
+
}
|
60
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import {
|
2
|
+
FindExternalEventSubscriptionsQuery,
|
3
|
+
DataSourceInstance,
|
4
|
+
} from '@integration-app/sdk'
|
5
|
+
import { useElements } from '../hooks/useElements'
|
6
|
+
|
7
|
+
export function useExternalEventSubscriptions(
|
8
|
+
query?: FindExternalEventSubscriptionsQuery,
|
9
|
+
) {
|
10
|
+
const { ...rest } = useElements<DataSourceInstance>(
|
11
|
+
'external-event-subscriptions',
|
12
|
+
query,
|
13
|
+
)
|
14
|
+
|
15
|
+
return {
|
16
|
+
externalEventSubscriptions: rest.items,
|
17
|
+
...rest,
|
18
|
+
}
|
19
|
+
}
|
@@ -27,9 +27,7 @@ export function useFieldMapping(
|
|
27
27
|
async function apply(integrationKeys: string[]): Promise<FieldMapping[]> {
|
28
28
|
const result = await accessor?.apply(integrationKeys)
|
29
29
|
await refresh()
|
30
|
-
|
31
|
-
// @ts-expect-error TS(2322): Type 'FieldMapping[] | undefined' is not assignabl... Remove this comment to see the full error message
|
32
|
-
return result
|
30
|
+
return result ?? []
|
33
31
|
}
|
34
32
|
|
35
33
|
async function reset() {
|
package/src/hooks/useElement.tsx
CHANGED
@@ -43,7 +43,7 @@ export function useElement<
|
|
43
43
|
// To make sure all instances of useElement with the same IntegrationAppClient and selector
|
44
44
|
// are synchronized, we cache them using selector and token as a key
|
45
45
|
const elementKeyData: any = {
|
46
|
-
token: integrationApp
|
46
|
+
token: integrationApp?.token,
|
47
47
|
selector,
|
48
48
|
}
|
49
49
|
const elementKey = JSON.stringify(elementKeyData)
|
package/src/index.tsx
CHANGED
@@ -14,7 +14,6 @@ export { useFieldMappingInstances } from './field-mappings/useFieldMappingInstan
|
|
14
14
|
export { useFieldMappings } from './field-mappings/useFieldMappings.js'
|
15
15
|
|
16
16
|
export { useDataSource } from './data-sources/useDataSource.js'
|
17
|
-
export { useDataSourceEvents } from './data-sources/useDataSourceEvents.js'
|
18
17
|
export { useDataSourceInstance } from './data-sources/useDataSourceInstance.js'
|
19
18
|
export { useDataSourceInstanceCollection } from './data-sources/useDataSourceInstanceCollection.js'
|
20
19
|
export { useDataSourceInstances } from './data-sources/useDataSourceInstances.js'
|
@@ -60,4 +59,7 @@ export { useScenarios } from './scenarios/useScenarios.js'
|
|
60
59
|
|
61
60
|
export { useDataCollectionSpec } from './data-collections/useDataCollectionSpec.js'
|
62
61
|
|
62
|
+
export { useExternalEventSubscriptions } from './external-events/useExternalEventSubscriptions.js'
|
63
|
+
export { useExternalEventSubscription } from './external-events/useExternalEventSubscription.js'
|
64
|
+
|
63
65
|
export { DataForm } from '@integration-app/sdk'
|
@@ -6,13 +6,13 @@ import {
|
|
6
6
|
} from '@integration-app/sdk'
|
7
7
|
import { useElement } from '../hooks/useElement'
|
8
8
|
|
9
|
-
export function useConnection(id
|
9
|
+
export function useConnection(id?: string | undefined) {
|
10
10
|
const { item: connection, ...rest } = useElement<
|
11
11
|
Connection,
|
12
12
|
UpdateConnectionRequest,
|
13
13
|
CreateConnectionRequest,
|
14
14
|
ConnectionAccessor
|
15
|
-
>(id, (integrationApp) => integrationApp.connection(id))
|
15
|
+
>(id, (integrationApp) => (id ? integrationApp.connection(id) : undefined))
|
16
16
|
|
17
17
|
return {
|
18
18
|
connection,
|
@@ -1,14 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
DataSourceEvent,
|
3
|
-
FindDataSourceEventsQuery,
|
4
|
-
} from '@integration-app/sdk'
|
5
|
-
import { useElements } from '../hooks/useElements'
|
6
|
-
|
7
|
-
export function useDataSourceEvents(query?: FindDataSourceEventsQuery) {
|
8
|
-
const { ...rest } = useElements<DataSourceEvent>('data-source-events', query)
|
9
|
-
|
10
|
-
return {
|
11
|
-
dataSourceEvents: rest,
|
12
|
-
...rest,
|
13
|
-
}
|
14
|
-
}
|