@unifiedsoftware/react-plugin-remote 1.0.0
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 +90 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +587 -0
- package/dist/index.d.ts +587 -0
- package/dist/index.js +1 -0
- package/package.json +28 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,587 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { HttpAdapter, HttpRequest, HttpResponse } from '@unifiedsoftware/http-client';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Plugin System SDK Core - Types
|
|
6
|
+
*
|
|
7
|
+
* Generic interfaces for plugin system.
|
|
8
|
+
* These types are project-agnostic and can be reused in any project.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Host Context - Generic interface
|
|
13
|
+
* @template TContext - Project-specific context (e.g., MailingContext, etc.)
|
|
14
|
+
*/
|
|
15
|
+
interface HostContext<TContext = any> {
|
|
16
|
+
readonly version: string;
|
|
17
|
+
readonly environment: 'development' | 'production';
|
|
18
|
+
readonly capabilities: HostCapabilities;
|
|
19
|
+
readonly context: TContext;
|
|
20
|
+
}
|
|
21
|
+
interface HostCapabilities {
|
|
22
|
+
readonly navigation: NavigationAPI;
|
|
23
|
+
readonly modal: ModalAPI;
|
|
24
|
+
readonly notification: NotificationAPI;
|
|
25
|
+
readonly storage: StorageAPI;
|
|
26
|
+
readonly api: ApiAPI;
|
|
27
|
+
readonly events: EventAPI;
|
|
28
|
+
}
|
|
29
|
+
interface NavigationAPI {
|
|
30
|
+
navigate(path: string, options?: NavigateOptions): void;
|
|
31
|
+
back(): void;
|
|
32
|
+
forward?(): void;
|
|
33
|
+
replace?(path: string): void;
|
|
34
|
+
openExternal(url: string): void;
|
|
35
|
+
}
|
|
36
|
+
interface NavigateOptions {
|
|
37
|
+
readonly replace?: boolean;
|
|
38
|
+
readonly state?: any;
|
|
39
|
+
}
|
|
40
|
+
interface ModalAPI {
|
|
41
|
+
open<T = any>(config: ModalConfig): Promise<T>;
|
|
42
|
+
close(id?: string, result?: any): void;
|
|
43
|
+
confirm(message: string, options?: ConfirmOptions): Promise<boolean>;
|
|
44
|
+
alert(message: string, options?: AlertOptions): Promise<void>;
|
|
45
|
+
}
|
|
46
|
+
interface ModalConfig {
|
|
47
|
+
readonly id?: string;
|
|
48
|
+
readonly title: string;
|
|
49
|
+
readonly content: React.ReactNode | string;
|
|
50
|
+
readonly width?: number | string;
|
|
51
|
+
readonly height?: number | string;
|
|
52
|
+
readonly actions?: readonly ModalAction[];
|
|
53
|
+
readonly closable?: boolean;
|
|
54
|
+
readonly onClose?: () => void;
|
|
55
|
+
}
|
|
56
|
+
interface ModalAction {
|
|
57
|
+
readonly label: string;
|
|
58
|
+
readonly onClick: () => any | Promise<any>;
|
|
59
|
+
readonly primary?: boolean;
|
|
60
|
+
readonly disabled?: boolean;
|
|
61
|
+
}
|
|
62
|
+
interface ConfirmOptions {
|
|
63
|
+
readonly title?: string;
|
|
64
|
+
readonly okText?: string;
|
|
65
|
+
readonly cancelText?: string;
|
|
66
|
+
}
|
|
67
|
+
interface AlertOptions {
|
|
68
|
+
readonly title?: string;
|
|
69
|
+
readonly okText?: string;
|
|
70
|
+
}
|
|
71
|
+
interface NotificationAPI {
|
|
72
|
+
success(message: string, options?: NotificationOptions): void;
|
|
73
|
+
error(message: string, options?: NotificationOptions): void;
|
|
74
|
+
warning(message: string, options?: NotificationOptions): void;
|
|
75
|
+
info(message: string, options?: NotificationOptions): void;
|
|
76
|
+
}
|
|
77
|
+
interface NotificationOptions {
|
|
78
|
+
readonly duration?: number;
|
|
79
|
+
readonly title?: string;
|
|
80
|
+
readonly closable?: boolean;
|
|
81
|
+
readonly onClose?: () => void;
|
|
82
|
+
}
|
|
83
|
+
interface StorageAPI {
|
|
84
|
+
get<T = any>(key: string): Promise<T | null>;
|
|
85
|
+
set<T = any>(key: string, value: T): Promise<void>;
|
|
86
|
+
remove(key: string): Promise<void>;
|
|
87
|
+
clear(): Promise<void>;
|
|
88
|
+
keys?(): Promise<string[]>;
|
|
89
|
+
}
|
|
90
|
+
interface ApiAPI {
|
|
91
|
+
request<T = any>(config: ApiRequestConfig): Promise<T>;
|
|
92
|
+
graphql<T = any>(config: GraphQLRequestConfig): Promise<GraphQLResponse<T>>;
|
|
93
|
+
getAuthToken(): Promise<string>;
|
|
94
|
+
}
|
|
95
|
+
interface ApiRequestConfig {
|
|
96
|
+
readonly pluginId: string;
|
|
97
|
+
readonly apiName?: string;
|
|
98
|
+
readonly endpoint: string;
|
|
99
|
+
readonly method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
|
|
100
|
+
readonly params?: Record<string, any>;
|
|
101
|
+
readonly data?: any;
|
|
102
|
+
readonly headers?: Record<string, string>;
|
|
103
|
+
}
|
|
104
|
+
interface GraphQLRequestConfig {
|
|
105
|
+
readonly pluginId: string;
|
|
106
|
+
readonly apiName?: string;
|
|
107
|
+
readonly query: string;
|
|
108
|
+
readonly variables?: Record<string, any>;
|
|
109
|
+
readonly operationName?: string;
|
|
110
|
+
readonly headers?: Record<string, string>;
|
|
111
|
+
}
|
|
112
|
+
interface GraphQLResponse<T = any> {
|
|
113
|
+
readonly data?: T;
|
|
114
|
+
readonly errors?: readonly GraphQLError[];
|
|
115
|
+
readonly extensions?: Record<string, any>;
|
|
116
|
+
}
|
|
117
|
+
interface GraphQLError {
|
|
118
|
+
readonly message: string;
|
|
119
|
+
readonly locations?: readonly {
|
|
120
|
+
line: number;
|
|
121
|
+
column: number;
|
|
122
|
+
}[];
|
|
123
|
+
readonly path?: readonly (string | number)[];
|
|
124
|
+
readonly extensions?: Record<string, any>;
|
|
125
|
+
}
|
|
126
|
+
interface EventAPI {
|
|
127
|
+
on(event: string, handler: EventHandler): () => void;
|
|
128
|
+
once?(event: string, handler: EventHandler): () => void;
|
|
129
|
+
emit(event: string, data?: any): void;
|
|
130
|
+
off?(event: string, handler?: EventHandler): void;
|
|
131
|
+
}
|
|
132
|
+
type EventHandler = (data?: any) => void;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Plugin Manifest Types
|
|
136
|
+
*
|
|
137
|
+
* Generic manifest structure for plugins
|
|
138
|
+
*/
|
|
139
|
+
|
|
140
|
+
declare enum PluginType {
|
|
141
|
+
INTERNAL = "internal",
|
|
142
|
+
MICROFRONTEND = "microfrontend",
|
|
143
|
+
IFRAME = "iframe"
|
|
144
|
+
}
|
|
145
|
+
declare enum ExtensionPoint {
|
|
146
|
+
}
|
|
147
|
+
interface PluginManifest {
|
|
148
|
+
readonly id: string;
|
|
149
|
+
readonly name: string;
|
|
150
|
+
readonly version: string;
|
|
151
|
+
readonly description?: string;
|
|
152
|
+
readonly author?: string;
|
|
153
|
+
readonly homepage?: string;
|
|
154
|
+
readonly icon?: string;
|
|
155
|
+
readonly type: PluginType | 'internal' | 'microfrontend' | 'iframe';
|
|
156
|
+
readonly remote?: {
|
|
157
|
+
readonly url: string;
|
|
158
|
+
readonly scope: string;
|
|
159
|
+
readonly module: string;
|
|
160
|
+
};
|
|
161
|
+
readonly capabilities: readonly string[];
|
|
162
|
+
readonly extensionPoints: readonly string[];
|
|
163
|
+
readonly dependencies?: {
|
|
164
|
+
readonly host?: string;
|
|
165
|
+
readonly plugins?: Record<string, string>;
|
|
166
|
+
};
|
|
167
|
+
readonly config?: Record<string, any>;
|
|
168
|
+
readonly api?: PluginApiConfig;
|
|
169
|
+
readonly apis?: Record<string, PluginApiConfig>;
|
|
170
|
+
}
|
|
171
|
+
interface PluginApiConfig {
|
|
172
|
+
readonly strategy?: 'proxy' | 'direct' | 'bff';
|
|
173
|
+
readonly baseUrl?: string;
|
|
174
|
+
readonly auth?: 'inherit' | 'custom' | 'none';
|
|
175
|
+
readonly allowedEndpoints?: Record<string, EndpointConfig>;
|
|
176
|
+
readonly endpoints?: Record<string, EndpointConfig>;
|
|
177
|
+
readonly corsOrigins?: readonly string[];
|
|
178
|
+
readonly bffUrl?: string;
|
|
179
|
+
readonly graphql?: GraphQLApiConfig;
|
|
180
|
+
}
|
|
181
|
+
interface EndpointConfig {
|
|
182
|
+
readonly path: string;
|
|
183
|
+
readonly method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
184
|
+
readonly methods?: readonly ('GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH')[];
|
|
185
|
+
readonly rateLimit?: number;
|
|
186
|
+
readonly cache?: {
|
|
187
|
+
readonly ttl: number;
|
|
188
|
+
readonly key?: string;
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
interface GraphQLApiConfig {
|
|
192
|
+
readonly url: string;
|
|
193
|
+
readonly auth?: 'inherit' | 'custom' | 'none';
|
|
194
|
+
readonly schema?: string;
|
|
195
|
+
readonly operations?: Record<string, GraphQLOperation>;
|
|
196
|
+
readonly subscriptions?: {
|
|
197
|
+
readonly url?: string;
|
|
198
|
+
readonly protocol?: 'ws' | 'graphql-ws';
|
|
199
|
+
};
|
|
200
|
+
readonly headers?: Record<string, string>;
|
|
201
|
+
readonly rateLimit?: number;
|
|
202
|
+
readonly cache?: {
|
|
203
|
+
readonly ttl: number;
|
|
204
|
+
readonly enabled: boolean;
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
interface GraphQLOperation {
|
|
208
|
+
readonly query: string;
|
|
209
|
+
readonly type: 'query' | 'mutation' | 'subscription';
|
|
210
|
+
readonly variables?: Record<string, any>;
|
|
211
|
+
readonly cache?: boolean;
|
|
212
|
+
}
|
|
213
|
+
interface Plugin<TContext = any> {
|
|
214
|
+
readonly manifest: PluginManifest;
|
|
215
|
+
initialize?(context: HostContext<TContext>): Promise<void>;
|
|
216
|
+
activate?(context: HostContext<TContext>): Promise<void>;
|
|
217
|
+
deactivate?(): Promise<void>;
|
|
218
|
+
dispose?(): Promise<void>;
|
|
219
|
+
components?: Partial<Record<string, React.ComponentType<any>>>;
|
|
220
|
+
}
|
|
221
|
+
interface PluginDefinition<TContext = any> {
|
|
222
|
+
readonly manifest: PluginManifest;
|
|
223
|
+
initialize?(context: HostContext<TContext>): Promise<void>;
|
|
224
|
+
activate?(context: HostContext<TContext>): Promise<void>;
|
|
225
|
+
deactivate?(): Promise<void>;
|
|
226
|
+
dispose?(): Promise<void>;
|
|
227
|
+
components?: Partial<Record<string, React.ComponentType<any>>>;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Plugin SDK Helpers
|
|
232
|
+
*
|
|
233
|
+
* Utility functions for defining plugins and manifests
|
|
234
|
+
*/
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Define a plugin with type safety
|
|
238
|
+
*/
|
|
239
|
+
declare function definePlugin<TContext = any>(definition: PluginDefinition<TContext>): () => Plugin<TContext>;
|
|
240
|
+
/**
|
|
241
|
+
* Define a manifest with type safety
|
|
242
|
+
*/
|
|
243
|
+
declare function defineManifest(manifest: PluginManifest): PluginManifest;
|
|
244
|
+
/**
|
|
245
|
+
* Define API endpoints with type safety
|
|
246
|
+
*/
|
|
247
|
+
declare function defineEndpoints<T extends Record<string, EndpointConfig>>(endpoints: T): T;
|
|
248
|
+
/**
|
|
249
|
+
* Define API configuration with type safety
|
|
250
|
+
*/
|
|
251
|
+
declare function defineApiConfig<T extends Record<string, PluginApiConfig>>(apis: T): T;
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Plugin API Client Generator
|
|
255
|
+
*
|
|
256
|
+
* Creates a type-safe API client based on plugin manifest
|
|
257
|
+
* Similar to Redux Toolkit Query but for plugin APIs
|
|
258
|
+
*/
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Infer parameter types from path template
|
|
262
|
+
* Example: "/api/contacts/{id}" -> { id: string }
|
|
263
|
+
*/
|
|
264
|
+
type ExtractPathParams<T extends string> = T extends `${infer _Start}/{${infer Param}}/${infer Rest}` ? {
|
|
265
|
+
[K in Param | keyof ExtractPathParams<`/${Rest}`>]: string;
|
|
266
|
+
} : T extends `${infer _Start}/{${infer Param}}` ? {
|
|
267
|
+
[K in Param]: string;
|
|
268
|
+
} : {};
|
|
269
|
+
/**
|
|
270
|
+
* Infer request config from endpoint
|
|
271
|
+
*/
|
|
272
|
+
type EndpointRequestConfig<TEndpoint extends EndpointConfig> = {
|
|
273
|
+
params?: ExtractPathParams<TEndpoint['path']> extends Record<string, never> ? Record<string, any> : ExtractPathParams<TEndpoint['path']>;
|
|
274
|
+
data?: TEndpoint['method'] extends 'POST' | 'PUT' | 'PATCH' ? any : never;
|
|
275
|
+
headers?: Record<string, string>;
|
|
276
|
+
};
|
|
277
|
+
/**
|
|
278
|
+
* Create endpoint function type
|
|
279
|
+
*/
|
|
280
|
+
type EndpointFunction<TEndpoint extends EndpointConfig> = <TResponse = any>(config?: EndpointRequestConfig<TEndpoint>) => Promise<TResponse>;
|
|
281
|
+
/**
|
|
282
|
+
* Create API client type from endpoints definition
|
|
283
|
+
*/
|
|
284
|
+
type ApiClientFromEndpoints<TEndpoints extends Record<string, EndpointConfig>> = {
|
|
285
|
+
[K in keyof TEndpoints]: EndpointFunction<TEndpoints[K]>;
|
|
286
|
+
};
|
|
287
|
+
/**
|
|
288
|
+
* Create multi-API client type from manifest apis definition
|
|
289
|
+
*/
|
|
290
|
+
type PluginApiClient<TManifest extends PluginManifest> = TManifest['apis'] extends Record<string, PluginApiConfig> ? {
|
|
291
|
+
[ApiName in keyof TManifest['apis']]: TManifest['apis'][ApiName]['endpoints'] extends Record<string, EndpointConfig> ? ApiClientFromEndpoints<TManifest['apis'][ApiName]['endpoints']> : Record<string, never>;
|
|
292
|
+
} : {};
|
|
293
|
+
/**
|
|
294
|
+
* Create a type-safe API client from plugin manifest
|
|
295
|
+
*
|
|
296
|
+
* @example
|
|
297
|
+
* ```ts
|
|
298
|
+
* const api = createPluginApi(manifest, hostContext.capabilities.api);
|
|
299
|
+
*
|
|
300
|
+
* // Type-safe API calls
|
|
301
|
+
* const contact = await api.crm.getContact({ params: { id: '123' } });
|
|
302
|
+
* const lead = await api.crm.createLead({ data: { name: 'John' } });
|
|
303
|
+
* ```
|
|
304
|
+
*/
|
|
305
|
+
declare function createPluginApi<TManifest extends PluginManifest>(manifest: TManifest, apiCapability: ApiAPI): PluginApiClient<TManifest>;
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* React Hooks for Plugin API
|
|
309
|
+
*
|
|
310
|
+
* Provides reactive data fetching hooks similar to React Query / RTK Query
|
|
311
|
+
*/
|
|
312
|
+
|
|
313
|
+
interface UseApiQueryOptions {
|
|
314
|
+
/** Auto-fetch on mount (default: true) */
|
|
315
|
+
enabled?: boolean;
|
|
316
|
+
/** Refetch interval in ms */
|
|
317
|
+
refetchInterval?: number;
|
|
318
|
+
/** Cache time in ms */
|
|
319
|
+
cacheTime?: number;
|
|
320
|
+
/** Callback on success */
|
|
321
|
+
onSuccess?: (data: any) => void;
|
|
322
|
+
/** Callback on error */
|
|
323
|
+
onError?: (error: Error) => void;
|
|
324
|
+
}
|
|
325
|
+
interface UseApiQueryResult<TData = any> {
|
|
326
|
+
data: TData | null;
|
|
327
|
+
loading: boolean;
|
|
328
|
+
error: Error | null;
|
|
329
|
+
refetch: () => Promise<void>;
|
|
330
|
+
isSuccess: boolean;
|
|
331
|
+
isError: boolean;
|
|
332
|
+
}
|
|
333
|
+
interface UseApiMutationResult<TData = any, TVariables = any> {
|
|
334
|
+
data: TData | null;
|
|
335
|
+
loading: boolean;
|
|
336
|
+
error: Error | null;
|
|
337
|
+
mutate: (variables: TVariables) => Promise<TData>;
|
|
338
|
+
reset: () => void;
|
|
339
|
+
isSuccess: boolean;
|
|
340
|
+
isError: boolean;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Hook for data fetching with automatic state management
|
|
344
|
+
*
|
|
345
|
+
* @example
|
|
346
|
+
* ```tsx
|
|
347
|
+
* const { data, loading, error, refetch } = useApiQuery(
|
|
348
|
+
* context,
|
|
349
|
+
* 'crm-integration',
|
|
350
|
+
* 'crm',
|
|
351
|
+
* 'getContact',
|
|
352
|
+
* { params: { id: contactId } }
|
|
353
|
+
* );
|
|
354
|
+
*
|
|
355
|
+
* if (loading) return <div>Loading...</div>;
|
|
356
|
+
* if (error) return <div>Error: {error.message}</div>;
|
|
357
|
+
* return <div>{data.name}</div>;
|
|
358
|
+
* ```
|
|
359
|
+
*/
|
|
360
|
+
declare function useApiQuery<TData = any>(context: HostContext, pluginId: string, apiName: string, endpoint: string, config?: {
|
|
361
|
+
params?: Record<string, any>;
|
|
362
|
+
data?: any;
|
|
363
|
+
headers?: Record<string, string>;
|
|
364
|
+
}, options?: UseApiQueryOptions): UseApiQueryResult<TData>;
|
|
365
|
+
/**
|
|
366
|
+
* Hook for mutations (POST, PUT, DELETE) with automatic state management
|
|
367
|
+
*
|
|
368
|
+
* @example
|
|
369
|
+
* ```tsx
|
|
370
|
+
* const { mutate, loading, error } = useApiMutation(
|
|
371
|
+
* context,
|
|
372
|
+
* 'crm-integration',
|
|
373
|
+
* 'crm',
|
|
374
|
+
* 'createLead',
|
|
375
|
+
* 'POST'
|
|
376
|
+
* );
|
|
377
|
+
*
|
|
378
|
+
* const handleSubmit = async () => {
|
|
379
|
+
* try {
|
|
380
|
+
* const result = await mutate({
|
|
381
|
+
* data: { name: 'John Doe', email: 'john@example.com' }
|
|
382
|
+
* });
|
|
383
|
+
* console.log('Lead created:', result);
|
|
384
|
+
* } catch (err) {
|
|
385
|
+
* console.error('Failed:', err);
|
|
386
|
+
* }
|
|
387
|
+
* };
|
|
388
|
+
* ```
|
|
389
|
+
*/
|
|
390
|
+
declare function useApiMutation<TData = any, TVariables = any>(context: HostContext, pluginId: string, apiName: string, endpoint: string, method?: 'POST' | 'PUT' | 'DELETE' | 'PATCH', options?: {
|
|
391
|
+
onSuccess?: (data: TData, variables: TVariables) => void;
|
|
392
|
+
onError?: (error: Error, variables: TVariables) => void;
|
|
393
|
+
}): UseApiMutationResult<TData, TVariables>;
|
|
394
|
+
/**
|
|
395
|
+
* Infer hook types from endpoint config
|
|
396
|
+
*/
|
|
397
|
+
type HookFromEndpoint<TEndpoint> = TEndpoint extends {
|
|
398
|
+
readonly method: 'GET';
|
|
399
|
+
} ? (config?: any, options?: UseApiQueryOptions) => UseApiQueryResult : TEndpoint extends {
|
|
400
|
+
readonly method: 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
401
|
+
} ? (options?: any) => UseApiMutationResult : (config?: any, options?: UseApiQueryOptions) => UseApiQueryResult;
|
|
402
|
+
/**
|
|
403
|
+
* Create hook name from endpoint name
|
|
404
|
+
*/
|
|
405
|
+
type HookName<T extends string> = `use${Capitalize<T>}`;
|
|
406
|
+
/**
|
|
407
|
+
* Create hooks object from endpoints
|
|
408
|
+
*/
|
|
409
|
+
type HooksFromEndpoints<TEndpoints> = {
|
|
410
|
+
[K in keyof TEndpoints as HookName<K & string>]: HookFromEndpoint<TEndpoints[K]>;
|
|
411
|
+
};
|
|
412
|
+
/**
|
|
413
|
+
* Create hooks type from manifest
|
|
414
|
+
*/
|
|
415
|
+
type PluginApiHooks<TManifest extends PluginManifest> = TManifest['apis'] extends Record<string, any> ? {
|
|
416
|
+
[ApiName in keyof TManifest['apis']]: TManifest['apis'][ApiName] extends {
|
|
417
|
+
readonly endpoints: infer TEndpoints;
|
|
418
|
+
} ? HooksFromEndpoints<TEndpoints> : Record<string, never>;
|
|
419
|
+
} : Record<string, never>;
|
|
420
|
+
/**
|
|
421
|
+
* Create typed hooks from manifest
|
|
422
|
+
*
|
|
423
|
+
* @example
|
|
424
|
+
* ```tsx
|
|
425
|
+
* // In plugin setup:
|
|
426
|
+
* const api = createPluginApi(manifest, capabilities.api);
|
|
427
|
+
* const hooks = createPluginApiHooks(context, manifest.id, manifest);
|
|
428
|
+
*
|
|
429
|
+
* // In components:
|
|
430
|
+
* const { data, loading } = hooks.crm.useGetContact({ params: { id: '123' } });
|
|
431
|
+
* const { mutate } = hooks.crm.useCreateLead();
|
|
432
|
+
* ```
|
|
433
|
+
*/
|
|
434
|
+
declare function createPluginApiHooks<TManifest extends PluginManifest>(context: HostContext, pluginId: string, manifest: TManifest): PluginApiHooks<TManifest>;
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* GraphQL Client Generator
|
|
438
|
+
*
|
|
439
|
+
* Creates a type-safe GraphQL client based on plugin manifest
|
|
440
|
+
* Provides simple query/mutation/subscription methods
|
|
441
|
+
*/
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Extract operation types from GraphQL API config
|
|
445
|
+
*/
|
|
446
|
+
type GraphQLOperations<TConfig extends GraphQLApiConfig> = TConfig['operations'] extends Record<string, any> ? TConfig['operations'] : Record<string, never>;
|
|
447
|
+
/**
|
|
448
|
+
* Create GraphQL client type from operations
|
|
449
|
+
*/
|
|
450
|
+
type GraphQLClientFromOperations<TOperations extends Record<string, any>> = {
|
|
451
|
+
query<TData = any>(operation: keyof TOperations, variables?: Record<string, any>): Promise<TData>;
|
|
452
|
+
mutate<TData = any>(operation: keyof TOperations, variables?: Record<string, any>): Promise<TData>;
|
|
453
|
+
subscribe?<TData = any>(operation: keyof TOperations, variables?: Record<string, any>, callback?: (data: TData) => void): () => void;
|
|
454
|
+
};
|
|
455
|
+
/**
|
|
456
|
+
* Create multi-API GraphQL client type from manifest
|
|
457
|
+
*/
|
|
458
|
+
type PluginGraphQLClient<TManifest extends PluginManifest> = TManifest['apis'] extends Record<string, any> ? {
|
|
459
|
+
[ApiName in keyof TManifest['apis']]: TManifest['apis'][ApiName]['graphql'] extends GraphQLApiConfig ? GraphQLClientFromOperations<GraphQLOperations<TManifest['apis'][ApiName]['graphql']>> : never;
|
|
460
|
+
} : {};
|
|
461
|
+
/**
|
|
462
|
+
* Create a type-safe GraphQL client from plugin manifest
|
|
463
|
+
*
|
|
464
|
+
* @example
|
|
465
|
+
* ```ts
|
|
466
|
+
* const graphql = createGraphQLClient(manifest, hostContext.capabilities.api);
|
|
467
|
+
*
|
|
468
|
+
* // Type-safe GraphQL calls
|
|
469
|
+
* const user = await graphql.githubApi.query('getUser', { login: 'octocat' });
|
|
470
|
+
* const created = await graphql.githubApi.mutate('createIssue', { title: 'Bug' });
|
|
471
|
+
* ```
|
|
472
|
+
*/
|
|
473
|
+
declare function createGraphQLClient<TManifest extends PluginManifest>(manifest: TManifest, apiCapability: ApiAPI): PluginGraphQLClient<TManifest>;
|
|
474
|
+
/**
|
|
475
|
+
* Helper to create a raw GraphQL request (without predefined operations)
|
|
476
|
+
* Useful for dynamic queries or when operations are not defined in manifest
|
|
477
|
+
*/
|
|
478
|
+
declare function createRawGraphQLClient(pluginId: string, apiName: string, apiCapability: ApiAPI): {
|
|
479
|
+
query<TData = any>(query: string, variables?: Record<string, any>, operationName?: string): Promise<TData>;
|
|
480
|
+
mutate<TData = any>(mutation: string, variables?: Record<string, any>, operationName?: string): Promise<TData>;
|
|
481
|
+
};
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* GraphQL React Hooks
|
|
485
|
+
*
|
|
486
|
+
* Provides React hooks for GraphQL queries, mutations, and subscriptions
|
|
487
|
+
* Similar to Apollo Client or React Query but integrated with our plugin system
|
|
488
|
+
*/
|
|
489
|
+
|
|
490
|
+
interface UseQueryOptions<TData = any> {
|
|
491
|
+
enabled?: boolean;
|
|
492
|
+
refetchOnMount?: boolean;
|
|
493
|
+
refetchInterval?: number;
|
|
494
|
+
onSuccess?: (data: TData) => void;
|
|
495
|
+
onError?: (error: Error) => void;
|
|
496
|
+
cacheTime?: number;
|
|
497
|
+
}
|
|
498
|
+
interface UseQueryResult<TData = any> {
|
|
499
|
+
data: TData | undefined;
|
|
500
|
+
loading: boolean;
|
|
501
|
+
error: Error | undefined;
|
|
502
|
+
refetch: () => Promise<void>;
|
|
503
|
+
}
|
|
504
|
+
interface UseMutationOptions<TData = any, TVariables = any> {
|
|
505
|
+
onSuccess?: (data: TData, variables: TVariables) => void;
|
|
506
|
+
onError?: (error: Error, variables: TVariables) => void;
|
|
507
|
+
}
|
|
508
|
+
interface UseMutationResult<TData = any, TVariables = any> {
|
|
509
|
+
mutate: (variables: TVariables) => Promise<TData>;
|
|
510
|
+
data: TData | undefined;
|
|
511
|
+
loading: boolean;
|
|
512
|
+
error: Error | undefined;
|
|
513
|
+
reset: () => void;
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Hook for GraphQL queries with automatic caching and refetching
|
|
517
|
+
*
|
|
518
|
+
* @example
|
|
519
|
+
* ```tsx
|
|
520
|
+
* const { data, loading, error, refetch } = useGraphQLQuery(
|
|
521
|
+
* context.capabilities.api,
|
|
522
|
+
* {
|
|
523
|
+
* pluginId: 'my-plugin',
|
|
524
|
+
* apiName: 'githubApi',
|
|
525
|
+
* query: GET_USER_QUERY,
|
|
526
|
+
* variables: { login: 'octocat' }
|
|
527
|
+
* },
|
|
528
|
+
* {
|
|
529
|
+
* enabled: true,
|
|
530
|
+
* onSuccess: (data) => console.log('User loaded:', data)
|
|
531
|
+
* }
|
|
532
|
+
* );
|
|
533
|
+
* ```
|
|
534
|
+
*/
|
|
535
|
+
declare function useGraphQLQuery<TData = any>(apiCapability: ApiAPI, config: GraphQLRequestConfig, options?: UseQueryOptions<TData>): UseQueryResult<TData>;
|
|
536
|
+
/**
|
|
537
|
+
* Hook for GraphQL mutations
|
|
538
|
+
*
|
|
539
|
+
* @example
|
|
540
|
+
* ```tsx
|
|
541
|
+
* const { mutate, loading, error } = useGraphQLMutation(
|
|
542
|
+
* context.capabilities.api,
|
|
543
|
+
* {
|
|
544
|
+
* pluginId: 'my-plugin',
|
|
545
|
+
* apiName: 'githubApi',
|
|
546
|
+
* query: CREATE_ISSUE_MUTATION
|
|
547
|
+
* },
|
|
548
|
+
* {
|
|
549
|
+
* onSuccess: (data) => console.log('Issue created:', data)
|
|
550
|
+
* }
|
|
551
|
+
* );
|
|
552
|
+
*
|
|
553
|
+
* // Later
|
|
554
|
+
* await mutate({ title: 'Bug', body: 'Description' });
|
|
555
|
+
* ```
|
|
556
|
+
*/
|
|
557
|
+
declare function useGraphQLMutation<TData = any, TVariables = any>(apiCapability: ApiAPI, config: Omit<GraphQLRequestConfig, 'variables'>, options?: UseMutationOptions<TData, TVariables>): UseMutationResult<TData, TVariables>;
|
|
558
|
+
/**
|
|
559
|
+
* Hook for GraphQL subscriptions (placeholder for future implementation)
|
|
560
|
+
*
|
|
561
|
+
* @example
|
|
562
|
+
* ```tsx
|
|
563
|
+
* const { data, loading, error } = useGraphQLSubscription(
|
|
564
|
+
* context.capabilities.api,
|
|
565
|
+
* {
|
|
566
|
+
* pluginId: 'my-plugin',
|
|
567
|
+
* apiName: 'githubApi',
|
|
568
|
+
* query: ISSUE_UPDATES_SUBSCRIPTION,
|
|
569
|
+
* variables: { repoId: '123' }
|
|
570
|
+
* }
|
|
571
|
+
* );
|
|
572
|
+
* ```
|
|
573
|
+
*/
|
|
574
|
+
declare function useGraphQLSubscription<TData = any>(apiCapability: ApiAPI, config: GraphQLRequestConfig, options?: UseQueryOptions<TData>): UseQueryResult<TData>;
|
|
575
|
+
|
|
576
|
+
declare class PluginHostAdapter implements HttpAdapter {
|
|
577
|
+
private context;
|
|
578
|
+
private pluginId;
|
|
579
|
+
constructor(context: HostContext, pluginId: string);
|
|
580
|
+
request<T>(config: HttpRequest): Promise<HttpResponse<T>>;
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* Create a fetch adapter instance
|
|
584
|
+
*/
|
|
585
|
+
declare function createPluginHostAdapter(context: HostContext, pluginId: string): PluginHostAdapter;
|
|
586
|
+
|
|
587
|
+
export { type AlertOptions, type ApiAPI, type ApiRequestConfig, type ConfirmOptions, type EndpointConfig, type EventAPI, type EventHandler, ExtensionPoint, type GraphQLApiConfig, type GraphQLError, type GraphQLOperation, type GraphQLRequestConfig, type GraphQLResponse, type HostCapabilities, type HostContext, type ModalAPI, type ModalAction, type ModalConfig, type NavigateOptions, type NavigationAPI, type NotificationAPI, type NotificationOptions, type Plugin, type PluginApiClient, type PluginApiConfig, type PluginApiHooks, type PluginDefinition, type PluginGraphQLClient, PluginHostAdapter, type PluginManifest, PluginType, type StorageAPI, type UseApiMutationResult, type UseApiQueryOptions, type UseApiQueryResult, type UseMutationOptions, type UseMutationResult, type UseQueryOptions, type UseQueryResult, createGraphQLClient, createPluginApi, createPluginApiHooks, createPluginHostAdapter, createRawGraphQLClient, defineApiConfig, defineEndpoints, defineManifest, definePlugin, useApiMutation, useApiQuery, useGraphQLMutation, useGraphQLQuery, useGraphQLSubscription };
|