@kodiak-finance/orderly-plugin-core 2.9.2-alpha.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/dist/index.d.mts +266 -0
- package/dist/index.d.ts +266 -0
- package/dist/index.js +503 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +469 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +47 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import React$1, { FC, PropsWithChildren, ReactNode, ReactElement, ElementType, ComponentType } from 'react';
|
|
2
|
+
import { TrackerEventName, NetworkId } from '@kodiak-finance/orderly-types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Plugin scope value: identifies the current plugin for API request attribution.
|
|
6
|
+
* When useQuery etc. run inside PluginScopeProvider, they add X-Orderly-Plugin-Id header.
|
|
7
|
+
*/
|
|
8
|
+
interface PluginScopeValue {
|
|
9
|
+
pluginId: string;
|
|
10
|
+
pluginName?: string;
|
|
11
|
+
pluginVersion?: string;
|
|
12
|
+
}
|
|
13
|
+
declare const PluginScopeContext: React$1.Context<PluginScopeValue | null>;
|
|
14
|
+
declare const usePluginScope: () => PluginScopeValue | null;
|
|
15
|
+
interface PluginScopeProviderProps extends PropsWithChildren, PluginScopeValue {
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Wraps plugin output so useQuery/useMutation etc. can inject X-Orderly-Plugin-Id header.
|
|
19
|
+
*/
|
|
20
|
+
declare const PluginScopeProvider: FC<PluginScopeProviderProps>;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Plugin events API interface.
|
|
24
|
+
* Forwards to global EventEmitter (SimpleDI "EE") used by useTrack and useEventEmitter.
|
|
25
|
+
*/
|
|
26
|
+
interface PluginEventsAPI {
|
|
27
|
+
on(event: TrackerEventName, handler: (data: unknown) => void): void;
|
|
28
|
+
off(event: TrackerEventName, handler: (data: unknown) => void): void;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Creates the events facade wired to the global EventEmitter (SimpleDI "EE").
|
|
32
|
+
* Returns a noop stub if EE has not been initialized yet.
|
|
33
|
+
*/
|
|
34
|
+
declare function createEventsFacade(): PluginEventsAPI;
|
|
35
|
+
|
|
36
|
+
/** API Facade for plugins (placeholder, extend later) */
|
|
37
|
+
interface OrderlyPluginAPI {
|
|
38
|
+
data?: Record<string, unknown>;
|
|
39
|
+
actions?: Record<string, unknown>;
|
|
40
|
+
utils?: Record<string, unknown>;
|
|
41
|
+
/** Event subscription - forwards to global EventEmitter (SimpleDI "EE") */
|
|
42
|
+
events: PluginEventsAPI;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Mapping from interceptor target path to component props type.
|
|
46
|
+
* Extend via module augmentation in UI packages (e.g. @orderly.network/trading)
|
|
47
|
+
* to enable typed props in createInterceptor(target, (Original, props, api) => ...).
|
|
48
|
+
* No index signature so that augmented entries keep their exact prop types.
|
|
49
|
+
*/
|
|
50
|
+
interface InterceptorTargetPropsMap {
|
|
51
|
+
}
|
|
52
|
+
/** Union of known interceptor target paths (keys of InterceptorTargetPropsMap) */
|
|
53
|
+
type KnownInterceptorTarget = keyof InterceptorTargetPropsMap;
|
|
54
|
+
/**
|
|
55
|
+
* Descriptor for one interceptable target (path + optional props type name for docs).
|
|
56
|
+
* Returned lazily by window.__ORDERLY_INTERCEPTOR_TARGETS_REGISTRY__() when called.
|
|
57
|
+
*/
|
|
58
|
+
interface InterceptorTargetDescriptor {
|
|
59
|
+
path: string;
|
|
60
|
+
/** Props type name (e.g. 'DepositFormProps') for documentation / Inspector */
|
|
61
|
+
propsType?: string;
|
|
62
|
+
description?: string;
|
|
63
|
+
}
|
|
64
|
+
declare global {
|
|
65
|
+
interface Window {
|
|
66
|
+
/** Lazy getter: when called, collects supported targets from current plugins' interceptors. Set by OrderlyPluginProvider. Same style as __ORDERLY_EXTENSION_REGISTRY__. */
|
|
67
|
+
__ORDERLY_INTERCEPTOR_TARGETS_REGISTRY__?: () => InterceptorTargetDescriptor[];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Interceptor component signature: (Original, props, api) => ReactNode.
|
|
72
|
+
* Use generic TProps to get typed props when targeting a known path.
|
|
73
|
+
*/
|
|
74
|
+
type PluginInterceptorComponent<TProps extends object = Record<string, unknown>> = (Original: React.ComponentType<TProps>, props: TProps, api: OrderlyPluginAPI) => ReactNode;
|
|
75
|
+
/** Single interceptor targeting a component path. TProps defaults to Record<string, unknown> for backward compat. */
|
|
76
|
+
interface PluginInterceptor<TProps extends object = Record<string, unknown>> {
|
|
77
|
+
target: string;
|
|
78
|
+
component: PluginInterceptorComponent<TProps>;
|
|
79
|
+
}
|
|
80
|
+
/** Plugin descriptor (per GUIDE.md) */
|
|
81
|
+
interface OrderlyPlugin {
|
|
82
|
+
id: string;
|
|
83
|
+
name?: string;
|
|
84
|
+
version?: string;
|
|
85
|
+
orderlyVersion?: string;
|
|
86
|
+
/** Interceptors targeting component paths (e.g. Trading.OrderEntry.SubmitButton). Uses array of any to accept interceptors whose props are augmented (and may not have index signature required by Record<string, unknown>). */
|
|
87
|
+
interceptors?: Array<PluginInterceptor<any>>;
|
|
88
|
+
setup?: (api: OrderlyPluginAPI) => void;
|
|
89
|
+
onInitialize?: () => void;
|
|
90
|
+
onInstall?: () => void | Promise<void>;
|
|
91
|
+
onError?: (error: Error) => void;
|
|
92
|
+
onFallback?: () => ReactNode | ReactElement;
|
|
93
|
+
}
|
|
94
|
+
/** SDK instance passed to plugin registration fn */
|
|
95
|
+
interface OrderlySDK {
|
|
96
|
+
registerPlugin: (descriptor: OrderlyPlugin) => void;
|
|
97
|
+
}
|
|
98
|
+
type Logo = {
|
|
99
|
+
img?: string;
|
|
100
|
+
component?: ReactNode;
|
|
101
|
+
className?: string;
|
|
102
|
+
};
|
|
103
|
+
type AppLogos = Partial<{
|
|
104
|
+
main: Logo;
|
|
105
|
+
secondary: Logo;
|
|
106
|
+
}>;
|
|
107
|
+
interface ApplicationState {
|
|
108
|
+
config: {
|
|
109
|
+
appIcons?: AppLogos;
|
|
110
|
+
brokerName: string;
|
|
111
|
+
dateFormatting?: string;
|
|
112
|
+
};
|
|
113
|
+
networkId: NetworkId;
|
|
114
|
+
}
|
|
115
|
+
/** Plugin registration function: (SDK, state?) => void; calls SDK.registerPlugin internally */
|
|
116
|
+
type PluginRegistrationFn<TState = ApplicationState> = (SDK: OrderlySDK, state?: TState) => void;
|
|
117
|
+
/** @deprecated Use PluginInterceptor with path-based target instead */
|
|
118
|
+
type ExtensionBuilder<Props = Record<string, unknown>> = (props?: Partial<Props> & Record<string, unknown>) => Props;
|
|
119
|
+
/** @deprecated Use path strings (e.g. 'Deposit.DepositForm') instead */
|
|
120
|
+
type ExtensionPosition = ExtensionPositionEnum | string;
|
|
121
|
+
/** @deprecated Use OrderlyPlugin with interceptors instead */
|
|
122
|
+
interface Extension<Props extends object = object> {
|
|
123
|
+
__isInternal: boolean;
|
|
124
|
+
name: string;
|
|
125
|
+
positions: ExtensionPosition[];
|
|
126
|
+
initialize?: () => void;
|
|
127
|
+
builder?: ExtensionBuilder<Props>;
|
|
128
|
+
render: ElementType<Props> | ((props: Props) => ReactElement);
|
|
129
|
+
}
|
|
130
|
+
/** @deprecated Use path strings (e.g. 'Deposit.DepositForm') instead */
|
|
131
|
+
declare enum ExtensionPositionEnum {
|
|
132
|
+
DepositForm = "depositForm",
|
|
133
|
+
WithdrawForm = "withdrawForm",
|
|
134
|
+
AccountMenu = "accountMenu",
|
|
135
|
+
MobileAccountMenu = "mobileAccountMenu",
|
|
136
|
+
MainMenus = "mainMenus",
|
|
137
|
+
EmptyDataIdentifier = "emptyDataIdentifier",
|
|
138
|
+
/** @deprecated Use EmptyDataIdentifier - same value for backward compatibility */
|
|
139
|
+
EmptyDataState = "emptyDataIdentifier"
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
type ExtensionContextState = Record<string, never>;
|
|
143
|
+
declare const useExtensionContext: () => ExtensionContextState;
|
|
144
|
+
declare const ExtensionProvider: React$1.FC<React$1.PropsWithChildren>;
|
|
145
|
+
interface OrderlyPluginContextValue {
|
|
146
|
+
plugins: OrderlyPlugin[];
|
|
147
|
+
apiFacade: OrderlyPluginAPI;
|
|
148
|
+
/** List of interceptable targets (when provided by host); used for window registry and optional useInterceptorTargets */
|
|
149
|
+
interceptorTargets: InterceptorTargetDescriptor[];
|
|
150
|
+
}
|
|
151
|
+
declare const useOrderlyPluginContext: () => OrderlyPluginContextValue;
|
|
152
|
+
/** Returns the list of interceptable targets when provided via OrderlyPluginProvider (e.g. for in-app dev panel). */
|
|
153
|
+
declare const useInterceptorTargets: () => InterceptorTargetDescriptor[];
|
|
154
|
+
interface OrderlyPluginProviderProps extends PropsWithChildren {
|
|
155
|
+
plugins: (OrderlyPlugin | PluginRegistrationFn)[];
|
|
156
|
+
/** Optional state passed to plugin registration fns (e.g. AppState) */
|
|
157
|
+
pluginState?: ApplicationState;
|
|
158
|
+
}
|
|
159
|
+
declare const OrderlyPluginProvider: FC<OrderlyPluginProviderProps>;
|
|
160
|
+
|
|
161
|
+
/** @deprecated Use OrderlyPlugin with interceptors instead */
|
|
162
|
+
type ExtensionOptions<Props> = {
|
|
163
|
+
name: string;
|
|
164
|
+
scope?: string[];
|
|
165
|
+
engines?: string;
|
|
166
|
+
positions: ExtensionPosition[];
|
|
167
|
+
builder?: (props: any) => Props;
|
|
168
|
+
__isInternal?: boolean;
|
|
169
|
+
entry?: string[];
|
|
170
|
+
installed?: () => Promise<void>;
|
|
171
|
+
onInit?: () => void;
|
|
172
|
+
activate?: () => Promise<void>;
|
|
173
|
+
deactivate?: () => Promise<void>;
|
|
174
|
+
};
|
|
175
|
+
type ExtensionRenderComponentType<Props> = ElementType<Props> | ((props: Props) => ReactElement);
|
|
176
|
+
/**
|
|
177
|
+
* Registers an extension. Registers to both legacy registry and new plugin registry.
|
|
178
|
+
* @deprecated Prefer registerPlugin via OrderlyPluginProvider plugins prop
|
|
179
|
+
*/
|
|
180
|
+
declare const installExtension: <Props extends object>(options: ExtensionOptions<Props>) => ((component: ExtensionRenderComponentType<Props>) => void);
|
|
181
|
+
/**
|
|
182
|
+
* @deprecated Prefer registerPlugin via OrderlyPluginProvider plugins prop
|
|
183
|
+
*/
|
|
184
|
+
declare const setExtensionBuilder: <Props extends object = Record<string, unknown>>(position: ExtensionPosition, builder: () => Props) => void;
|
|
185
|
+
|
|
186
|
+
interface SlotProps {
|
|
187
|
+
position: ExtensionPosition;
|
|
188
|
+
defaultWidget?: React$1.ComponentType<any>;
|
|
189
|
+
scope?: string[];
|
|
190
|
+
[key: string]: any;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Renders the component for the given position, resolving interceptors via useInjectedComponent.
|
|
194
|
+
* Requires OrderlyPluginProvider in the tree (can have plugins=[]).
|
|
195
|
+
* @deprecated Prefer useInjectedComponent with path string directly (e.g. 'Deposit.DepositForm')
|
|
196
|
+
*/
|
|
197
|
+
declare const ExtensionSlot: React$1.FC<SlotProps>;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Returns a component that chains all interceptors for the given path (onion model).
|
|
201
|
+
* Each interceptor is wrapped in PluginErrorBoundary; plugin's onError/onFallback
|
|
202
|
+
* are used when provided, else SDK defaults.
|
|
203
|
+
*/
|
|
204
|
+
declare function useInjectedComponent<P extends object>(name: string, DefaultComponent: ComponentType<P>): ComponentType<P>;
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* HOC: wraps a component to make it interceptable by plugins.
|
|
208
|
+
* Registers the target path in a static registry so it appears in interceptor target lists.
|
|
209
|
+
*/
|
|
210
|
+
declare function injectable<P extends object>(Component: ComponentType<P>, name: string): ComponentType<P>;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Converts ExtensionPosition to interceptor path.
|
|
214
|
+
* @deprecated Use path strings directly (e.g. 'Deposit.DepositForm') instead of ExtensionPosition
|
|
215
|
+
*/
|
|
216
|
+
declare function positionToPath(position: ExtensionPosition): string;
|
|
217
|
+
|
|
218
|
+
declare const OrderlyPluginRegistry: {
|
|
219
|
+
register(descriptor: OrderlyPlugin): void;
|
|
220
|
+
getPlugins(): OrderlyPlugin[];
|
|
221
|
+
clear(): void;
|
|
222
|
+
};
|
|
223
|
+
/** SDK instance for plugin registration (used by registration fns) */
|
|
224
|
+
declare const createOrderlySDK: () => OrderlySDK;
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* String-target overload: use when `@orderly.network/plugin-core` is the only dependency and
|
|
228
|
+
* `InterceptorTargetPropsMap` is empty (ambient augmentation from UI packages not loaded).
|
|
229
|
+
* Avoids DTS failures where keyof an empty map is `never`.
|
|
230
|
+
*/
|
|
231
|
+
declare function createInterceptor(target: string, component: PluginInterceptorComponent<Record<string, unknown>>): PluginInterceptor<Record<string, unknown>>;
|
|
232
|
+
/** Typed overload when workspace packages augment `InterceptorTargetPropsMap`. */
|
|
233
|
+
declare function createInterceptor<T extends KnownInterceptorTarget>(target: T, component: PluginInterceptorComponent<InterceptorTargetPropsMap[T]>): PluginInterceptor<InterceptorTargetPropsMap[T]>;
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Legacy extension registry (position-based, for installExtension backward compat).
|
|
237
|
+
* @deprecated Use registerPlugin via OrderlyPluginProvider plugins prop instead
|
|
238
|
+
*/
|
|
239
|
+
declare class OrderlyExtensionRegistry {
|
|
240
|
+
static getInstance(): OrderlyExtensionRegistry;
|
|
241
|
+
private extensionMap;
|
|
242
|
+
register<Props extends object>(plugin: Omit<Extension<Props>, "builder"> & {
|
|
243
|
+
builder?: (props: any) => Props;
|
|
244
|
+
}): void;
|
|
245
|
+
private registerToPosition;
|
|
246
|
+
setBuilder<Props extends object>(position: ExtensionPosition, builder: ExtensionBuilder<Props>): void;
|
|
247
|
+
getPluginsByPosition(position: ExtensionPosition): Extension<Record<string, unknown>> | undefined;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Error boundary for plugin interceptors.
|
|
252
|
+
* Prevents a single plugin crash from taking down the whole page.
|
|
253
|
+
* Uses plugin's onError/onFallback when provided, else SDK defaults.
|
|
254
|
+
*/
|
|
255
|
+
declare const PluginErrorBoundary: React$1.FC<{
|
|
256
|
+
children: ReactNode;
|
|
257
|
+
/** Override fallback (legacy); prefer onFallback from plugin */
|
|
258
|
+
fallback?: ReactNode;
|
|
259
|
+
pluginId?: string;
|
|
260
|
+
/** Plugin's error handler; called when error is caught */
|
|
261
|
+
onError?: (error: Error) => void;
|
|
262
|
+
/** Plugin's fallback renderer; used when error is caught */
|
|
263
|
+
onFallback?: () => ReactNode;
|
|
264
|
+
}>;
|
|
265
|
+
|
|
266
|
+
export { type ApplicationState, type Extension, type ExtensionBuilder, type ExtensionOptions, type ExtensionPosition, ExtensionPositionEnum, ExtensionProvider, ExtensionSlot, type InterceptorTargetDescriptor, type InterceptorTargetPropsMap, type KnownInterceptorTarget, OrderlyExtensionRegistry, type OrderlyPlugin, type OrderlyPluginAPI, type OrderlyPluginContextValue, OrderlyPluginProvider, OrderlyPluginRegistry, type OrderlySDK, PluginErrorBoundary, type PluginEventsAPI, type PluginInterceptor, type PluginInterceptorComponent, type PluginRegistrationFn, PluginScopeContext, PluginScopeProvider, type PluginScopeValue, createEventsFacade, createInterceptor, createOrderlySDK, injectable, installExtension, positionToPath, setExtensionBuilder, useExtensionContext, useInjectedComponent, useInterceptorTargets, useOrderlyPluginContext, usePluginScope };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import React$1, { FC, PropsWithChildren, ReactNode, ReactElement, ElementType, ComponentType } from 'react';
|
|
2
|
+
import { TrackerEventName, NetworkId } from '@kodiak-finance/orderly-types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Plugin scope value: identifies the current plugin for API request attribution.
|
|
6
|
+
* When useQuery etc. run inside PluginScopeProvider, they add X-Orderly-Plugin-Id header.
|
|
7
|
+
*/
|
|
8
|
+
interface PluginScopeValue {
|
|
9
|
+
pluginId: string;
|
|
10
|
+
pluginName?: string;
|
|
11
|
+
pluginVersion?: string;
|
|
12
|
+
}
|
|
13
|
+
declare const PluginScopeContext: React$1.Context<PluginScopeValue | null>;
|
|
14
|
+
declare const usePluginScope: () => PluginScopeValue | null;
|
|
15
|
+
interface PluginScopeProviderProps extends PropsWithChildren, PluginScopeValue {
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Wraps plugin output so useQuery/useMutation etc. can inject X-Orderly-Plugin-Id header.
|
|
19
|
+
*/
|
|
20
|
+
declare const PluginScopeProvider: FC<PluginScopeProviderProps>;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Plugin events API interface.
|
|
24
|
+
* Forwards to global EventEmitter (SimpleDI "EE") used by useTrack and useEventEmitter.
|
|
25
|
+
*/
|
|
26
|
+
interface PluginEventsAPI {
|
|
27
|
+
on(event: TrackerEventName, handler: (data: unknown) => void): void;
|
|
28
|
+
off(event: TrackerEventName, handler: (data: unknown) => void): void;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Creates the events facade wired to the global EventEmitter (SimpleDI "EE").
|
|
32
|
+
* Returns a noop stub if EE has not been initialized yet.
|
|
33
|
+
*/
|
|
34
|
+
declare function createEventsFacade(): PluginEventsAPI;
|
|
35
|
+
|
|
36
|
+
/** API Facade for plugins (placeholder, extend later) */
|
|
37
|
+
interface OrderlyPluginAPI {
|
|
38
|
+
data?: Record<string, unknown>;
|
|
39
|
+
actions?: Record<string, unknown>;
|
|
40
|
+
utils?: Record<string, unknown>;
|
|
41
|
+
/** Event subscription - forwards to global EventEmitter (SimpleDI "EE") */
|
|
42
|
+
events: PluginEventsAPI;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Mapping from interceptor target path to component props type.
|
|
46
|
+
* Extend via module augmentation in UI packages (e.g. @orderly.network/trading)
|
|
47
|
+
* to enable typed props in createInterceptor(target, (Original, props, api) => ...).
|
|
48
|
+
* No index signature so that augmented entries keep their exact prop types.
|
|
49
|
+
*/
|
|
50
|
+
interface InterceptorTargetPropsMap {
|
|
51
|
+
}
|
|
52
|
+
/** Union of known interceptor target paths (keys of InterceptorTargetPropsMap) */
|
|
53
|
+
type KnownInterceptorTarget = keyof InterceptorTargetPropsMap;
|
|
54
|
+
/**
|
|
55
|
+
* Descriptor for one interceptable target (path + optional props type name for docs).
|
|
56
|
+
* Returned lazily by window.__ORDERLY_INTERCEPTOR_TARGETS_REGISTRY__() when called.
|
|
57
|
+
*/
|
|
58
|
+
interface InterceptorTargetDescriptor {
|
|
59
|
+
path: string;
|
|
60
|
+
/** Props type name (e.g. 'DepositFormProps') for documentation / Inspector */
|
|
61
|
+
propsType?: string;
|
|
62
|
+
description?: string;
|
|
63
|
+
}
|
|
64
|
+
declare global {
|
|
65
|
+
interface Window {
|
|
66
|
+
/** Lazy getter: when called, collects supported targets from current plugins' interceptors. Set by OrderlyPluginProvider. Same style as __ORDERLY_EXTENSION_REGISTRY__. */
|
|
67
|
+
__ORDERLY_INTERCEPTOR_TARGETS_REGISTRY__?: () => InterceptorTargetDescriptor[];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Interceptor component signature: (Original, props, api) => ReactNode.
|
|
72
|
+
* Use generic TProps to get typed props when targeting a known path.
|
|
73
|
+
*/
|
|
74
|
+
type PluginInterceptorComponent<TProps extends object = Record<string, unknown>> = (Original: React.ComponentType<TProps>, props: TProps, api: OrderlyPluginAPI) => ReactNode;
|
|
75
|
+
/** Single interceptor targeting a component path. TProps defaults to Record<string, unknown> for backward compat. */
|
|
76
|
+
interface PluginInterceptor<TProps extends object = Record<string, unknown>> {
|
|
77
|
+
target: string;
|
|
78
|
+
component: PluginInterceptorComponent<TProps>;
|
|
79
|
+
}
|
|
80
|
+
/** Plugin descriptor (per GUIDE.md) */
|
|
81
|
+
interface OrderlyPlugin {
|
|
82
|
+
id: string;
|
|
83
|
+
name?: string;
|
|
84
|
+
version?: string;
|
|
85
|
+
orderlyVersion?: string;
|
|
86
|
+
/** Interceptors targeting component paths (e.g. Trading.OrderEntry.SubmitButton). Uses array of any to accept interceptors whose props are augmented (and may not have index signature required by Record<string, unknown>). */
|
|
87
|
+
interceptors?: Array<PluginInterceptor<any>>;
|
|
88
|
+
setup?: (api: OrderlyPluginAPI) => void;
|
|
89
|
+
onInitialize?: () => void;
|
|
90
|
+
onInstall?: () => void | Promise<void>;
|
|
91
|
+
onError?: (error: Error) => void;
|
|
92
|
+
onFallback?: () => ReactNode | ReactElement;
|
|
93
|
+
}
|
|
94
|
+
/** SDK instance passed to plugin registration fn */
|
|
95
|
+
interface OrderlySDK {
|
|
96
|
+
registerPlugin: (descriptor: OrderlyPlugin) => void;
|
|
97
|
+
}
|
|
98
|
+
type Logo = {
|
|
99
|
+
img?: string;
|
|
100
|
+
component?: ReactNode;
|
|
101
|
+
className?: string;
|
|
102
|
+
};
|
|
103
|
+
type AppLogos = Partial<{
|
|
104
|
+
main: Logo;
|
|
105
|
+
secondary: Logo;
|
|
106
|
+
}>;
|
|
107
|
+
interface ApplicationState {
|
|
108
|
+
config: {
|
|
109
|
+
appIcons?: AppLogos;
|
|
110
|
+
brokerName: string;
|
|
111
|
+
dateFormatting?: string;
|
|
112
|
+
};
|
|
113
|
+
networkId: NetworkId;
|
|
114
|
+
}
|
|
115
|
+
/** Plugin registration function: (SDK, state?) => void; calls SDK.registerPlugin internally */
|
|
116
|
+
type PluginRegistrationFn<TState = ApplicationState> = (SDK: OrderlySDK, state?: TState) => void;
|
|
117
|
+
/** @deprecated Use PluginInterceptor with path-based target instead */
|
|
118
|
+
type ExtensionBuilder<Props = Record<string, unknown>> = (props?: Partial<Props> & Record<string, unknown>) => Props;
|
|
119
|
+
/** @deprecated Use path strings (e.g. 'Deposit.DepositForm') instead */
|
|
120
|
+
type ExtensionPosition = ExtensionPositionEnum | string;
|
|
121
|
+
/** @deprecated Use OrderlyPlugin with interceptors instead */
|
|
122
|
+
interface Extension<Props extends object = object> {
|
|
123
|
+
__isInternal: boolean;
|
|
124
|
+
name: string;
|
|
125
|
+
positions: ExtensionPosition[];
|
|
126
|
+
initialize?: () => void;
|
|
127
|
+
builder?: ExtensionBuilder<Props>;
|
|
128
|
+
render: ElementType<Props> | ((props: Props) => ReactElement);
|
|
129
|
+
}
|
|
130
|
+
/** @deprecated Use path strings (e.g. 'Deposit.DepositForm') instead */
|
|
131
|
+
declare enum ExtensionPositionEnum {
|
|
132
|
+
DepositForm = "depositForm",
|
|
133
|
+
WithdrawForm = "withdrawForm",
|
|
134
|
+
AccountMenu = "accountMenu",
|
|
135
|
+
MobileAccountMenu = "mobileAccountMenu",
|
|
136
|
+
MainMenus = "mainMenus",
|
|
137
|
+
EmptyDataIdentifier = "emptyDataIdentifier",
|
|
138
|
+
/** @deprecated Use EmptyDataIdentifier - same value for backward compatibility */
|
|
139
|
+
EmptyDataState = "emptyDataIdentifier"
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
type ExtensionContextState = Record<string, never>;
|
|
143
|
+
declare const useExtensionContext: () => ExtensionContextState;
|
|
144
|
+
declare const ExtensionProvider: React$1.FC<React$1.PropsWithChildren>;
|
|
145
|
+
interface OrderlyPluginContextValue {
|
|
146
|
+
plugins: OrderlyPlugin[];
|
|
147
|
+
apiFacade: OrderlyPluginAPI;
|
|
148
|
+
/** List of interceptable targets (when provided by host); used for window registry and optional useInterceptorTargets */
|
|
149
|
+
interceptorTargets: InterceptorTargetDescriptor[];
|
|
150
|
+
}
|
|
151
|
+
declare const useOrderlyPluginContext: () => OrderlyPluginContextValue;
|
|
152
|
+
/** Returns the list of interceptable targets when provided via OrderlyPluginProvider (e.g. for in-app dev panel). */
|
|
153
|
+
declare const useInterceptorTargets: () => InterceptorTargetDescriptor[];
|
|
154
|
+
interface OrderlyPluginProviderProps extends PropsWithChildren {
|
|
155
|
+
plugins: (OrderlyPlugin | PluginRegistrationFn)[];
|
|
156
|
+
/** Optional state passed to plugin registration fns (e.g. AppState) */
|
|
157
|
+
pluginState?: ApplicationState;
|
|
158
|
+
}
|
|
159
|
+
declare const OrderlyPluginProvider: FC<OrderlyPluginProviderProps>;
|
|
160
|
+
|
|
161
|
+
/** @deprecated Use OrderlyPlugin with interceptors instead */
|
|
162
|
+
type ExtensionOptions<Props> = {
|
|
163
|
+
name: string;
|
|
164
|
+
scope?: string[];
|
|
165
|
+
engines?: string;
|
|
166
|
+
positions: ExtensionPosition[];
|
|
167
|
+
builder?: (props: any) => Props;
|
|
168
|
+
__isInternal?: boolean;
|
|
169
|
+
entry?: string[];
|
|
170
|
+
installed?: () => Promise<void>;
|
|
171
|
+
onInit?: () => void;
|
|
172
|
+
activate?: () => Promise<void>;
|
|
173
|
+
deactivate?: () => Promise<void>;
|
|
174
|
+
};
|
|
175
|
+
type ExtensionRenderComponentType<Props> = ElementType<Props> | ((props: Props) => ReactElement);
|
|
176
|
+
/**
|
|
177
|
+
* Registers an extension. Registers to both legacy registry and new plugin registry.
|
|
178
|
+
* @deprecated Prefer registerPlugin via OrderlyPluginProvider plugins prop
|
|
179
|
+
*/
|
|
180
|
+
declare const installExtension: <Props extends object>(options: ExtensionOptions<Props>) => ((component: ExtensionRenderComponentType<Props>) => void);
|
|
181
|
+
/**
|
|
182
|
+
* @deprecated Prefer registerPlugin via OrderlyPluginProvider plugins prop
|
|
183
|
+
*/
|
|
184
|
+
declare const setExtensionBuilder: <Props extends object = Record<string, unknown>>(position: ExtensionPosition, builder: () => Props) => void;
|
|
185
|
+
|
|
186
|
+
interface SlotProps {
|
|
187
|
+
position: ExtensionPosition;
|
|
188
|
+
defaultWidget?: React$1.ComponentType<any>;
|
|
189
|
+
scope?: string[];
|
|
190
|
+
[key: string]: any;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Renders the component for the given position, resolving interceptors via useInjectedComponent.
|
|
194
|
+
* Requires OrderlyPluginProvider in the tree (can have plugins=[]).
|
|
195
|
+
* @deprecated Prefer useInjectedComponent with path string directly (e.g. 'Deposit.DepositForm')
|
|
196
|
+
*/
|
|
197
|
+
declare const ExtensionSlot: React$1.FC<SlotProps>;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Returns a component that chains all interceptors for the given path (onion model).
|
|
201
|
+
* Each interceptor is wrapped in PluginErrorBoundary; plugin's onError/onFallback
|
|
202
|
+
* are used when provided, else SDK defaults.
|
|
203
|
+
*/
|
|
204
|
+
declare function useInjectedComponent<P extends object>(name: string, DefaultComponent: ComponentType<P>): ComponentType<P>;
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* HOC: wraps a component to make it interceptable by plugins.
|
|
208
|
+
* Registers the target path in a static registry so it appears in interceptor target lists.
|
|
209
|
+
*/
|
|
210
|
+
declare function injectable<P extends object>(Component: ComponentType<P>, name: string): ComponentType<P>;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Converts ExtensionPosition to interceptor path.
|
|
214
|
+
* @deprecated Use path strings directly (e.g. 'Deposit.DepositForm') instead of ExtensionPosition
|
|
215
|
+
*/
|
|
216
|
+
declare function positionToPath(position: ExtensionPosition): string;
|
|
217
|
+
|
|
218
|
+
declare const OrderlyPluginRegistry: {
|
|
219
|
+
register(descriptor: OrderlyPlugin): void;
|
|
220
|
+
getPlugins(): OrderlyPlugin[];
|
|
221
|
+
clear(): void;
|
|
222
|
+
};
|
|
223
|
+
/** SDK instance for plugin registration (used by registration fns) */
|
|
224
|
+
declare const createOrderlySDK: () => OrderlySDK;
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* String-target overload: use when `@orderly.network/plugin-core` is the only dependency and
|
|
228
|
+
* `InterceptorTargetPropsMap` is empty (ambient augmentation from UI packages not loaded).
|
|
229
|
+
* Avoids DTS failures where keyof an empty map is `never`.
|
|
230
|
+
*/
|
|
231
|
+
declare function createInterceptor(target: string, component: PluginInterceptorComponent<Record<string, unknown>>): PluginInterceptor<Record<string, unknown>>;
|
|
232
|
+
/** Typed overload when workspace packages augment `InterceptorTargetPropsMap`. */
|
|
233
|
+
declare function createInterceptor<T extends KnownInterceptorTarget>(target: T, component: PluginInterceptorComponent<InterceptorTargetPropsMap[T]>): PluginInterceptor<InterceptorTargetPropsMap[T]>;
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Legacy extension registry (position-based, for installExtension backward compat).
|
|
237
|
+
* @deprecated Use registerPlugin via OrderlyPluginProvider plugins prop instead
|
|
238
|
+
*/
|
|
239
|
+
declare class OrderlyExtensionRegistry {
|
|
240
|
+
static getInstance(): OrderlyExtensionRegistry;
|
|
241
|
+
private extensionMap;
|
|
242
|
+
register<Props extends object>(plugin: Omit<Extension<Props>, "builder"> & {
|
|
243
|
+
builder?: (props: any) => Props;
|
|
244
|
+
}): void;
|
|
245
|
+
private registerToPosition;
|
|
246
|
+
setBuilder<Props extends object>(position: ExtensionPosition, builder: ExtensionBuilder<Props>): void;
|
|
247
|
+
getPluginsByPosition(position: ExtensionPosition): Extension<Record<string, unknown>> | undefined;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Error boundary for plugin interceptors.
|
|
252
|
+
* Prevents a single plugin crash from taking down the whole page.
|
|
253
|
+
* Uses plugin's onError/onFallback when provided, else SDK defaults.
|
|
254
|
+
*/
|
|
255
|
+
declare const PluginErrorBoundary: React$1.FC<{
|
|
256
|
+
children: ReactNode;
|
|
257
|
+
/** Override fallback (legacy); prefer onFallback from plugin */
|
|
258
|
+
fallback?: ReactNode;
|
|
259
|
+
pluginId?: string;
|
|
260
|
+
/** Plugin's error handler; called when error is caught */
|
|
261
|
+
onError?: (error: Error) => void;
|
|
262
|
+
/** Plugin's fallback renderer; used when error is caught */
|
|
263
|
+
onFallback?: () => ReactNode;
|
|
264
|
+
}>;
|
|
265
|
+
|
|
266
|
+
export { type ApplicationState, type Extension, type ExtensionBuilder, type ExtensionOptions, type ExtensionPosition, ExtensionPositionEnum, ExtensionProvider, ExtensionSlot, type InterceptorTargetDescriptor, type InterceptorTargetPropsMap, type KnownInterceptorTarget, OrderlyExtensionRegistry, type OrderlyPlugin, type OrderlyPluginAPI, type OrderlyPluginContextValue, OrderlyPluginProvider, OrderlyPluginRegistry, type OrderlySDK, PluginErrorBoundary, type PluginEventsAPI, type PluginInterceptor, type PluginInterceptorComponent, type PluginRegistrationFn, PluginScopeContext, PluginScopeProvider, type PluginScopeValue, createEventsFacade, createInterceptor, createOrderlySDK, injectable, installExtension, positionToPath, setExtensionBuilder, useExtensionContext, useInjectedComponent, useInterceptorTargets, useOrderlyPluginContext, usePluginScope };
|