@dev-fastn-ai/react-core 1.0.5 → 1.0.6
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/core/src/services/apis.d.ts +35 -0
- package/dist/core/src/utils/misc.d.ts +4 -0
- package/dist/index.cjs.js +661 -17168
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +248 -0
- package/dist/index.esm.js +634 -17141
- package/dist/index.esm.js.map +1 -1
- package/package.json +18 -6
- package/dist/core/src/services/api-hooks.d.ts +0 -35
- package/dist/core/src/services/apollo.d.ts +0 -4
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
3
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
4
|
+
import { GetConfigurationsInput, GetConfigurationFormInput, ConnectorField as ConnectorField$1, SelectOption as SelectOption$1 } from '@dev-fastn-ai/core';
|
|
5
|
+
export * from '@dev-fastn-ai/core';
|
|
6
|
+
|
|
7
|
+
type FastnEnvironment = 'LIVE' | 'DRAFT' | string;
|
|
8
|
+
interface FastnConfig {
|
|
9
|
+
baseUrl?: string;
|
|
10
|
+
environment?: FastnEnvironment;
|
|
11
|
+
authToken: string;
|
|
12
|
+
tenantId: string;
|
|
13
|
+
spaceId: string;
|
|
14
|
+
customAuth?: boolean | undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Supported field types for connector forms.
|
|
19
|
+
*/
|
|
20
|
+
declare enum ConnectorFieldType {
|
|
21
|
+
TEXT = "text",
|
|
22
|
+
NUMBER = "number",
|
|
23
|
+
CHECKBOX = "checkbox",
|
|
24
|
+
DATE = "date",
|
|
25
|
+
DATETIME = "datetime",
|
|
26
|
+
TIME = "time",
|
|
27
|
+
DATETIME_LOCAL = "datetime-local",
|
|
28
|
+
MULTI_SELECT = "multi-select",
|
|
29
|
+
SELECT = "select",
|
|
30
|
+
GOOGLE_FILES_PICKER_SELECT = "google-files-picker-select",
|
|
31
|
+
GOOGLE_FILES_PICKER_MULTI_SELECT = "google-files-picker-multi-select"
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Represents a form for configuring a connector or integration.
|
|
35
|
+
*/
|
|
36
|
+
interface ConfigurationForm {
|
|
37
|
+
readonly name: string;
|
|
38
|
+
readonly description: string;
|
|
39
|
+
readonly imageUri: string;
|
|
40
|
+
readonly fields: readonly ConnectorField[];
|
|
41
|
+
readonly submitButtonLabel?: string;
|
|
42
|
+
readonly loading?: boolean;
|
|
43
|
+
readonly error?: string;
|
|
44
|
+
readonly submitHandler?: (args: {
|
|
45
|
+
formData: FormData;
|
|
46
|
+
}) => Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Supported action types for connectors and configurations.
|
|
50
|
+
*/
|
|
51
|
+
declare enum ConnectorActionType {
|
|
52
|
+
ACTIVATION = "ACTIVATION",
|
|
53
|
+
DEACTIVATION = "DEACTIVATION",
|
|
54
|
+
NONE = "NONE",
|
|
55
|
+
ENABLE = "ENABLE",
|
|
56
|
+
DISABLE = "DISABLE",
|
|
57
|
+
DELETE = "DELETE"
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Status of a connector.
|
|
61
|
+
*/
|
|
62
|
+
declare enum ConnectorStatus {
|
|
63
|
+
ACTIVE = "ACTIVE",
|
|
64
|
+
INACTIVE = "INACTIVE",
|
|
65
|
+
ALL = "ALL"
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Supported action types for configuration actions.
|
|
69
|
+
*/
|
|
70
|
+
type ConfigurationActionType = ConnectorActionType.ENABLE | ConnectorActionType.DISABLE | ConnectorActionType.DELETE;
|
|
71
|
+
/**
|
|
72
|
+
* Represents a configuration instance for a connector.
|
|
73
|
+
*/
|
|
74
|
+
interface Configuration {
|
|
75
|
+
readonly id: string;
|
|
76
|
+
readonly connectorId: string;
|
|
77
|
+
readonly configurationId: string;
|
|
78
|
+
readonly name: string;
|
|
79
|
+
readonly flowId: string;
|
|
80
|
+
readonly description: string;
|
|
81
|
+
readonly imageUri: string;
|
|
82
|
+
readonly status: string;
|
|
83
|
+
readonly actions: readonly ConfigurationAction[];
|
|
84
|
+
readonly metadata?: unknown;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Represents an action available on a configuration.
|
|
88
|
+
*/
|
|
89
|
+
interface ConfigurationAction {
|
|
90
|
+
readonly name: string;
|
|
91
|
+
readonly actionType: ConfigurationActionType;
|
|
92
|
+
readonly onClick?: () => Promise<void>;
|
|
93
|
+
readonly form?: ConnectorForm | null;
|
|
94
|
+
readonly onSubmit?: (formData: unknown) => Promise<void>;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Represents a selectable option in a dropdown or select field.
|
|
98
|
+
*/
|
|
99
|
+
interface SelectOption {
|
|
100
|
+
readonly label: string;
|
|
101
|
+
readonly value: string;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Pagination information for select options.
|
|
105
|
+
*/
|
|
106
|
+
interface SelectOptionsResultPagination {
|
|
107
|
+
readonly sourceId: string;
|
|
108
|
+
readonly sourceProject: string;
|
|
109
|
+
readonly limit?: number;
|
|
110
|
+
readonly offset?: number;
|
|
111
|
+
readonly cursor?: string;
|
|
112
|
+
readonly type: "OFFSET" | "CURSOR";
|
|
113
|
+
readonly hasNextPage?: boolean;
|
|
114
|
+
readonly total?: number;
|
|
115
|
+
readonly loaded?: number;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Primitive types allowed in form data.
|
|
119
|
+
*/
|
|
120
|
+
type Primitive = string | number | boolean | null | undefined;
|
|
121
|
+
/**
|
|
122
|
+
* Represents form data as a record of values.
|
|
123
|
+
*/
|
|
124
|
+
type FormData = Record<string, Primitive | Primitive[] | Record<string, Primitive> | Record<string, Primitive>[]>;
|
|
125
|
+
/**
|
|
126
|
+
* Result of loading options for a select field.
|
|
127
|
+
*/
|
|
128
|
+
interface OptionsResult {
|
|
129
|
+
readonly options: readonly SelectOption[];
|
|
130
|
+
readonly pagination: SelectOptionsResultPagination;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Source for select options, supporting static and dynamic loading.
|
|
134
|
+
*/
|
|
135
|
+
interface SelectOptionSource {
|
|
136
|
+
readonly type: "STATIC" | "DYNAMIC" | "GOOGLE_FILES_PICKER";
|
|
137
|
+
readonly openGoogleFilesPicker?: (args: OpenGoogleFilesPickerArgs) => Promise<void>;
|
|
138
|
+
readonly staticOptions?: readonly SelectOption[];
|
|
139
|
+
readonly pagination?: SelectOptionsResultPagination;
|
|
140
|
+
readonly searchOptions?: (query: string, pagination: SelectOptionsResultPagination, context?: FormData) => Promise<OptionsResult>;
|
|
141
|
+
readonly getOptions?: (pagination: SelectOptionsResultPagination, context?: FormData) => Promise<OptionsResult>;
|
|
142
|
+
readonly loadMore?: (pagination: SelectOptionsResultPagination, context?: FormData) => Promise<OptionsResult>;
|
|
143
|
+
readonly refresh?: (pagination: SelectOptionsResultPagination, context?: FormData) => Promise<OptionsResult>;
|
|
144
|
+
}
|
|
145
|
+
type OpenGoogleFilesPickerArgs = {
|
|
146
|
+
onComplete: (files: readonly SelectOption[]) => Promise<void>;
|
|
147
|
+
onError: (error: Error) => Promise<void>;
|
|
148
|
+
apiKey?: string;
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* Represents a field in a connector form.
|
|
152
|
+
*/
|
|
153
|
+
interface ConnectorField {
|
|
154
|
+
readonly name: string;
|
|
155
|
+
readonly key: string;
|
|
156
|
+
readonly label: string;
|
|
157
|
+
readonly type: ConnectorFieldType | string;
|
|
158
|
+
readonly required: boolean;
|
|
159
|
+
readonly placeholder: string;
|
|
160
|
+
readonly description: string;
|
|
161
|
+
readonly hidden?: boolean;
|
|
162
|
+
readonly disabled?: boolean;
|
|
163
|
+
readonly initialValue?: string;
|
|
164
|
+
readonly optionsSource?: SelectOptionSource;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Represents a form for a connector action.
|
|
168
|
+
*/
|
|
169
|
+
interface ConnectorForm {
|
|
170
|
+
readonly description: string;
|
|
171
|
+
readonly fields: readonly ConnectorField[];
|
|
172
|
+
readonly submitButtonLabel?: string;
|
|
173
|
+
}
|
|
174
|
+
interface ConnectorActionResult {
|
|
175
|
+
readonly data: unknown;
|
|
176
|
+
readonly status: "SUCCESS" | "ERROR";
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Represents an action available on a connector.
|
|
180
|
+
*/
|
|
181
|
+
interface ConnectorAction {
|
|
182
|
+
readonly name: string;
|
|
183
|
+
readonly actionType: ConnectorActionType | string;
|
|
184
|
+
readonly form?: ConnectorForm | null;
|
|
185
|
+
readonly onClick?: (data?: unknown) => Promise<ConnectorActionResult>;
|
|
186
|
+
readonly onSubmit?: (formData: Record<string, unknown>) => Promise<ConnectorActionResult>;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Represents a connector (integration) instance.
|
|
190
|
+
*/
|
|
191
|
+
interface Connector {
|
|
192
|
+
readonly id: string;
|
|
193
|
+
readonly name: string;
|
|
194
|
+
readonly description: string;
|
|
195
|
+
readonly imageUri: string;
|
|
196
|
+
readonly status: ConnectorStatus;
|
|
197
|
+
readonly actions: readonly ConnectorAction[];
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
declare const FastnProvider: ({ children, config, queryClient, }: {
|
|
201
|
+
children: React.ReactNode;
|
|
202
|
+
config: FastnConfig;
|
|
203
|
+
queryClient?: QueryClient;
|
|
204
|
+
}) => react_jsx_runtime.JSX.Element;
|
|
205
|
+
|
|
206
|
+
declare const useConfigurations: (input: GetConfigurationsInput) => _tanstack_react_query.UseQueryResult<Configuration[], Error>;
|
|
207
|
+
|
|
208
|
+
declare const useConfigurationForm: (input: GetConfigurationFormInput) => _tanstack_react_query.UseQueryResult<ConfigurationForm, Error>;
|
|
209
|
+
|
|
210
|
+
declare const useConnectors: () => _tanstack_react_query.UseQueryResult<Connector[], Error>;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Custom hook to manage async select field options with search, pagination, and error handling using React Query.
|
|
214
|
+
*
|
|
215
|
+
* Benefits of React Query caching:
|
|
216
|
+
* - Automatic caching with configurable stale time (5 minutes)
|
|
217
|
+
* - Background refetching when data becomes stale
|
|
218
|
+
* - Deduplication of requests
|
|
219
|
+
* - Optimistic updates
|
|
220
|
+
* - Automatic retry on failure
|
|
221
|
+
* - Cache invalidation and garbage collection
|
|
222
|
+
*
|
|
223
|
+
* @param field ConnectorField - The field definition containing optionsSource
|
|
224
|
+
* @returns { options, loading, loadingMore, hasNext, query, refresh, search, loadMore, error }
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```tsx
|
|
228
|
+
* const { options, loading, loadingMore, hasNext, search, loadMore } = useFieldOptions(field);
|
|
229
|
+
*
|
|
230
|
+
* // Options are automatically cached and shared across components
|
|
231
|
+
* // Loading states are handled automatically
|
|
232
|
+
* // Pagination is managed with infinite query
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
declare function useFieldOptions(field: ConnectorField$1): {
|
|
236
|
+
options: SelectOption$1[];
|
|
237
|
+
loading: boolean;
|
|
238
|
+
loadingMore: boolean;
|
|
239
|
+
hasNext: boolean;
|
|
240
|
+
query: string;
|
|
241
|
+
refresh: () => Promise<void>;
|
|
242
|
+
search: (query: string) => void;
|
|
243
|
+
loadMore: () => Promise<void>;
|
|
244
|
+
totalLoadedOptions: number;
|
|
245
|
+
error: string | null;
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
export { FastnProvider, useConfigurationForm, useConfigurations, useConnectors, useFieldOptions };
|