@plugmatica/plugin-sdk 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +136 -2
- package/dist/advanced.d.ts +315 -0
- package/dist/advanced.js +3 -0
- package/dist/advanced.js.map +1 -0
- package/dist/chunk-ACHELRPS.js +182 -0
- package/dist/chunk-ACHELRPS.js.map +1 -0
- package/dist/chunk-AFVR6B2A.js +256 -0
- package/dist/chunk-AFVR6B2A.js.map +1 -0
- package/dist/chunk-YY4H56JF.js +84 -0
- package/dist/chunk-YY4H56JF.js.map +1 -0
- package/dist/extension-index.d.ts +178 -0
- package/dist/extension-index.js +3 -0
- package/dist/extension-index.js.map +1 -0
- package/dist/host.d.ts +859 -0
- package/dist/host.js +2280 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +1465 -0
- package/dist/index.js +749 -0
- package/dist/index.js.map +1 -0
- package/dist/types-83DpQEKd.d.ts +599 -0
- package/package.json +107 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Plugmatica contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,137 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @plugmatica/plugin-sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The supported frontend runtime SDK for independently developed Plugmatica plugins.
|
|
4
|
+
|
|
5
|
+
## Who should use it
|
|
6
|
+
|
|
7
|
+
Frontend plugin code should use this SDK for runtime context, scoped API access, navigation, routes, sessions and extension execution. Plugins must not import runtime-shell internals or the host router directly.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pnpm add @plugmatica/plugin-sdk@beta
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Requirements
|
|
16
|
+
|
|
17
|
+
Peer requirements:
|
|
18
|
+
|
|
19
|
+
- `react ^19.0.0`
|
|
20
|
+
- `react-dom ^19.0.0`
|
|
21
|
+
- `@plugmatica/i18n ^0.1.0`
|
|
22
|
+
- `@plugmatica/ui-kit ^0.1.0`
|
|
23
|
+
- `@module-federation/enhanced 2.9.4` is optional for the normal plugin-author entry point, but required in a host that imports `@plugmatica/plugin-sdk/host` (also required by `@plugmatica/plugin-testing`)
|
|
24
|
+
|
|
25
|
+
`@plugmatica/core-sdk` is installed as a normal dependency. For host projects,
|
|
26
|
+
verify the installed Module Federation declaration-tooling dependencies are patched
|
|
27
|
+
(`adm-zip` >= 0.6.1 and `undici` >= 7.30.2 within 7.x). Repository-local pnpm
|
|
28
|
+
overrides are not inherited by consumers.
|
|
29
|
+
|
|
30
|
+
## Quick start
|
|
31
|
+
|
|
32
|
+
React plugin pages and renderable extensions are hooks-first, zero-prop components. Host context is already provided by the runtime:
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
import { usePluginApi, usePluginRouteMatch } from "@plugmatica/plugin-sdk";
|
|
36
|
+
|
|
37
|
+
export default function CustomerPage() {
|
|
38
|
+
const api = usePluginApi();
|
|
39
|
+
const route = usePluginRouteMatch("/customers/:customerPid");
|
|
40
|
+
|
|
41
|
+
void api;
|
|
42
|
+
return <div>{route?.customerPid}</div>;
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Use `usePluginNavigation().navigate()` for SPA navigation. Do not import the host router or parse `window.location` in plugin code.
|
|
47
|
+
For **external OAuth provider sign-in only**, call `await usePluginNavigation().navigateExternal?.(authorizationUrl)` after the host returns an authorised HTTPS URL. Runtime shell navigation validates and performs the full-document redirect. `navigate()` is for internal Plugmatica routes and must not receive OAuth provider URLs. Hosts without external navigation support may omit this optional capability; present an error rather than performing plugin-source `window.location.assign()`.
|
|
48
|
+
|
|
49
|
+
### Translations in static descriptors
|
|
50
|
+
|
|
51
|
+
Normal React components use the scoped runtime hook:
|
|
52
|
+
|
|
53
|
+
```tsx
|
|
54
|
+
const { t } = usePluginI18n();
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
When translated content must live in a module-level/static render descriptor, keep the descriptor static and render the translation at the React boundary with `PluginMessage`:
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
import { PluginMessage } from "@plugmatica/plugin-sdk";
|
|
61
|
+
|
|
62
|
+
const columns = [
|
|
63
|
+
{
|
|
64
|
+
accessorKey: "name",
|
|
65
|
+
header: () => <PluginMessage id="customers.name" />,
|
|
66
|
+
},
|
|
67
|
+
];
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
`PluginMessage` uses the same plugin-local and `$common` / `$terms` references as `t(...)` and remains reactive to locale changes. It is not a replacement for `usePluginI18n()` in normal components.
|
|
71
|
+
|
|
72
|
+
### Entity references
|
|
73
|
+
|
|
74
|
+
Follow relationships through the field declared by your own entity rather than naming the target plugin:
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
const contacts = ownerEntity(api, "contact");
|
|
78
|
+
const customers = contacts.reference("customer");
|
|
79
|
+
const page = await customers.search({ text: "north", limit: 20 });
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The runtime resolves the target from effective `EntityRef` schema metadata, derives safe indexed string fields for search, applies target read policy, and returns only a reference plus human-readable label. This keeps independently built plugins free from target-plugin frontend dependencies.
|
|
83
|
+
|
|
84
|
+
## Public entry points
|
|
85
|
+
|
|
86
|
+
- `@plugmatica/plugin-sdk` — normal plugin-author API.
|
|
87
|
+
- `@plugmatica/plugin-sdk/advanced` — advanced/headless extension APIs for unusual cases.
|
|
88
|
+
- `@plugmatica/plugin-sdk/host` — host/runtime integration; not an ordinary plugin-author API.
|
|
89
|
+
- `@plugmatica/plugin-sdk/extension-index` — host-internal extension index integration; test helpers use it internally.
|
|
90
|
+
|
|
91
|
+
Package-internal source paths are not public entry points. `./host` and
|
|
92
|
+
`./extension-index` ship for host integration but are classified **host-internal**,
|
|
93
|
+
not ordinary plugin-author imports. `./advanced` is a supported plugin-author
|
|
94
|
+
surface; it does not grant host privileges.
|
|
95
|
+
|
|
96
|
+
### Host-owned context and scope
|
|
97
|
+
|
|
98
|
+
The host mounts each federated plugin with its runtime context. Plugin components
|
|
99
|
+
consume `usePluginApi()`, session/navigation hooks and supported managed-resource
|
|
100
|
+
hooks; they must not replace that context, create a second authentication client,
|
|
101
|
+
choose another actor/scope or inject credentials. Root exports such as
|
|
102
|
+
`createPluginRuntime` and `PluginRuntimeProvider` support integration/test
|
|
103
|
+
composition, not a separate production runtime inside a plugin.
|
|
104
|
+
|
|
105
|
+
The optional Module Federation peer supports host-side integration. It is not
|
|
106
|
+
permission to bundle a private host runtime. Reuse the host's shared React, SDK,
|
|
107
|
+
UI Kit and query dependencies. A missing-context error should be fixed at the
|
|
108
|
+
host mounting/shared-dependency boundary; for isolated tests use
|
|
109
|
+
`@plugmatica/plugin-testing` instead of imitating production authentication.
|
|
110
|
+
Backend authorization remains authoritative for every request.
|
|
111
|
+
|
|
112
|
+
`matchPluginRoute` returns ordinary plain-object route parameters. Even a valid but unusual parameter named `:__proto__` is preserved as an own enumerable property without altering the result prototype; standard parameter names, optional final segments and catch-alls are unaffected. See the [SDK boundary recipes](https://plugmatica.com/plugmatica/sdk/plugin-runtime-boundaries).
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
## Beta stability
|
|
116
|
+
|
|
117
|
+
This package is part of the Plugmatica public beta API. Breaking public API changes are deliberate, versioned, release-noted and checked against the public API baseline. Host-only entry points may evolve more aggressively than the normal package-root plugin API and are documented as such.
|
|
118
|
+
|
|
119
|
+
## Documentation
|
|
120
|
+
|
|
121
|
+
Frontend plugin guide: https://plugmatica.com/plugmatica/plugin-development/frontend/
|
|
122
|
+
|
|
123
|
+
SDK definitions and stability: https://plugmatica.com/plugmatica/sdk/intro
|
|
124
|
+
|
|
125
|
+
## Guest and kiosk pages
|
|
126
|
+
|
|
127
|
+
A page rendered through an enabled guest surface remains an ordinary plugin page, but the runtime session actor is `guest` and the host supplies a narrow guest lifecycle capability. Plugins should not bypass that capability by calling public-session endpoints directly.
|
|
128
|
+
|
|
129
|
+
### Workflow data-source status
|
|
130
|
+
|
|
131
|
+
`createWorkflowNodeFields(...)` exposes an advisory `WorkflowNodeFieldState.referenceStatus` for direct mapped sources: `available`, `conditional`, `optional`, or `unverified` (undefined for fixed/unset/other formulas). A direct reference no longer in the host-approved source catalogue does not count as `configured`, but is **never** deleted by read operations. Plugin code should treat status as authoring guidance, not as an access-control or publish decision; backend contracts and runtime permissions remain authoritative.
|
|
132
|
+
|
|
133
|
+
For canvas-only composition, `workflowUpstreamNodeIds(graph, targetNodeId)` derives connected predecessors. Pass this result as the optional third argument to `projectWorkflowNodePresentationFields(node, descriptor, predecessors)` to mark disconnected `$.nodes.<node>.output...` references as not configured. The returned field projection is deliberately limited to path, required/mode/configured values and **never** forwards predecessors, expressions, Connection identifiers or BlobRef tokens. `@plugmatica/blocks` `WorkflowField` displays a host-translated warning for an unverified direct reference. See the Workflow developer guide.
|
|
134
|
+
|
|
135
|
+
## License
|
|
136
|
+
|
|
137
|
+
MIT.
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { u as EventHandlerModule, O as OperationHookModule, v as ProviderModule, S as StructuredUiExtensionModule, w as ExtensionLifecycleHooks } from './types-83DpQEKd.js';
|
|
2
|
+
export { x as ExtensionContributionContext, y as ExtensionLifecycleContext, z as ExtensionRegistrationLifecycleHooks, A as ExtensionRenderContext, R as RenderableUiExtensionModule } from './types-83DpQEKd.js';
|
|
3
|
+
import { EventExtensionTargetToken, OperationExtensionTargetToken, OperationExtensionPhase, ProviderExtensionTargetToken, UiExtensionTargetToken, ExtensionSurface, ExtensionContractRequirement, PluginKey } from '@plugmatica/core-sdk';
|
|
4
|
+
import { ComponentType } from 'react';
|
|
5
|
+
import '@plugmatica/i18n';
|
|
6
|
+
import '@plugmatica/ui-kit/host';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Callable action exposed through a semantic `defineActions()` collection.
|
|
10
|
+
*
|
|
11
|
+
* @param args Arguments accepted by the concrete action implementation.
|
|
12
|
+
* @returns Value returned by the concrete action implementation.
|
|
13
|
+
*/
|
|
14
|
+
type PluginAction = (...args: any[]) => any;
|
|
15
|
+
/**
|
|
16
|
+
* Read-only map of semantic action keys to plugin action implementations.
|
|
17
|
+
*/
|
|
18
|
+
type PluginActionMap = Readonly<Record<string, PluginAction>>;
|
|
19
|
+
/**
|
|
20
|
+
* Declare semantic actions while preserving their static keys for the frontend compiler.
|
|
21
|
+
* The helper is a runtime no-op and returns the exact object passed to it.
|
|
22
|
+
*
|
|
23
|
+
* @param actions Action implementations keyed by their stable semantic action name.
|
|
24
|
+
* @returns The unchanged action map with literal keys/types preserved.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const actions = defineActions({
|
|
29
|
+
* save: async () => saveCustomer(),
|
|
30
|
+
* refresh: async () => reloadCustomer(),
|
|
31
|
+
* });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
declare function defineActions<const TActions extends PluginActionMap>(actions: TActions): TActions;
|
|
35
|
+
/**
|
|
36
|
+
* Mark a compile-time collection as intentional repeated instances of one semantic surface.
|
|
37
|
+
*
|
|
38
|
+
* @param items Static items that deliberately share one extension identity and use `instanceKey` at runtime.
|
|
39
|
+
* @returns The unchanged collection with literal tuple/array types preserved.
|
|
40
|
+
*/
|
|
41
|
+
declare function defineRepeatedInstances<const TItems extends readonly unknown[]>(items: TItems): TItems;
|
|
42
|
+
type CapabilityResolvedTarget<TTarget> = Extract<TTarget, {
|
|
43
|
+
readonly resolution: "capability";
|
|
44
|
+
}>;
|
|
45
|
+
type CapabilityTargetBase<TContract extends ExtensionContractRequirement, TRequired extends boolean> = {
|
|
46
|
+
readonly contract: TContract;
|
|
47
|
+
readonly required?: TRequired;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Declare an extension target by public runtime capability rather than by a
|
|
51
|
+
* concrete provider plugin package. The runtime resolves exactly one compatible
|
|
52
|
+
* installed provider before exposing the contribution.
|
|
53
|
+
*/
|
|
54
|
+
declare const extensionTarget: {
|
|
55
|
+
readonly ui: <const TSurface extends ExtensionSurface, const TKey extends string, const TPoint extends string, const TContract extends ExtensionContractRequirement, const TRequired extends boolean = true>(target: CapabilityTargetBase<TContract, TRequired> & {
|
|
56
|
+
readonly surface: TSurface;
|
|
57
|
+
readonly key: TKey;
|
|
58
|
+
readonly point: TPoint;
|
|
59
|
+
}) => CapabilityResolvedTarget<UiExtensionTargetToken<PluginKey, string, TSurface, TKey, TPoint, TContract>> & {
|
|
60
|
+
readonly required: TRequired;
|
|
61
|
+
};
|
|
62
|
+
readonly operation: <const TSurface extends ExtensionSurface, const TKey extends string, const TOperation extends string, const TContract extends ExtensionContractRequirement, const TRequired extends boolean = true>(target: CapabilityTargetBase<TContract, TRequired> & {
|
|
63
|
+
readonly surface: TSurface;
|
|
64
|
+
readonly key: TKey;
|
|
65
|
+
readonly operation: TOperation;
|
|
66
|
+
}) => CapabilityResolvedTarget<OperationExtensionTargetToken<PluginKey, string, TSurface, TKey, TOperation, TContract>> & {
|
|
67
|
+
readonly required: TRequired;
|
|
68
|
+
};
|
|
69
|
+
readonly event: <const TEvent extends string, const TContract extends ExtensionContractRequirement, const TRequired extends boolean = true>(target: CapabilityTargetBase<TContract, TRequired> & {
|
|
70
|
+
readonly event: TEvent;
|
|
71
|
+
}) => CapabilityResolvedTarget<EventExtensionTargetToken<unknown, PluginKey, string, TEvent, TContract>> & {
|
|
72
|
+
readonly required: TRequired;
|
|
73
|
+
};
|
|
74
|
+
readonly provider: <const TProvider extends string, const TContract extends ExtensionContractRequirement, const TRequired extends boolean = true>(target: CapabilityTargetBase<TContract, TRequired> & {
|
|
75
|
+
readonly provider: TProvider;
|
|
76
|
+
}) => CapabilityResolvedTarget<ProviderExtensionTargetToken<unknown, unknown, PluginKey, string, TProvider, TContract>> & {
|
|
77
|
+
readonly required: TRequired;
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
/** Public UI target accepted from either a generated direct target or a capability selector. */
|
|
81
|
+
type UiExtensionTarget = UiExtensionTargetToken;
|
|
82
|
+
/**
|
|
83
|
+
* Infer the structured contribution value carried by a generated UI target token.
|
|
84
|
+
*/
|
|
85
|
+
type UiContributionOf<TTarget> = TTarget extends {
|
|
86
|
+
readonly __contribution?: infer TContribution;
|
|
87
|
+
} ? TContribution : unknown;
|
|
88
|
+
/**
|
|
89
|
+
* Generated provider target token carrying provider request and value types.
|
|
90
|
+
*/
|
|
91
|
+
type ProviderTarget<TRequest = unknown, TValue = unknown> = ProviderExtensionTargetToken<TRequest, TValue>;
|
|
92
|
+
/**
|
|
93
|
+
* Generated event target token carrying the event payload type.
|
|
94
|
+
*/
|
|
95
|
+
type EventHandlerTarget<TPayload = unknown> = EventExtensionTargetToken<TPayload>;
|
|
96
|
+
/**
|
|
97
|
+
* Generated operation target token carrying operation payload and result types.
|
|
98
|
+
*/
|
|
99
|
+
type OperationHookTarget<TPayload = unknown, TResult = unknown> = OperationExtensionTargetToken & {
|
|
100
|
+
/** Type-only operation payload/result carriers for specialised target packages. */
|
|
101
|
+
readonly __payload?: TPayload;
|
|
102
|
+
/**
|
|
103
|
+
* Type-only operation result carrier for specialised target packages.
|
|
104
|
+
*/
|
|
105
|
+
readonly __result?: TResult;
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* React component type accepted by a renderable Plugmatica UI extension.
|
|
109
|
+
*/
|
|
110
|
+
type DefinedExtensionComponent = ComponentType;
|
|
111
|
+
/**
|
|
112
|
+
* Optional compiler-owned contribution metadata. `module` is the stable Module
|
|
113
|
+
* Federation expose name; target protocol fields come exclusively from the
|
|
114
|
+
* generated token. `contribution` is an escape hatch for preserving the
|
|
115
|
+
* contribution key when a module expose is renamed.
|
|
116
|
+
*/
|
|
117
|
+
type ExtensionContributionDefinition = {
|
|
118
|
+
/**
|
|
119
|
+
* Module Federation expose name or generated contribution module path.
|
|
120
|
+
*/
|
|
121
|
+
readonly module?: `./${string}`;
|
|
122
|
+
/**
|
|
123
|
+
* Optional stable contribution key retained when a module expose is renamed.
|
|
124
|
+
*/
|
|
125
|
+
readonly contribution?: string;
|
|
126
|
+
/**
|
|
127
|
+
* Resolved ordering value used to sort contributions.
|
|
128
|
+
*/
|
|
129
|
+
readonly order?: number;
|
|
130
|
+
/**
|
|
131
|
+
* Optional human-readable contribution label.
|
|
132
|
+
*/
|
|
133
|
+
readonly label?: string | null;
|
|
134
|
+
/**
|
|
135
|
+
* Optional translation key for the contribution label.
|
|
136
|
+
*/
|
|
137
|
+
readonly labelKey?: string | null;
|
|
138
|
+
/**
|
|
139
|
+
* Optional permission scope required before the contribution is activated.
|
|
140
|
+
*/
|
|
141
|
+
readonly requiredScope?: string | null;
|
|
142
|
+
/**
|
|
143
|
+
* Optional compiler/runtime metadata associated with the contribution.
|
|
144
|
+
*/
|
|
145
|
+
readonly metadata?: Readonly<Record<string, unknown>> | null;
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Definition for a UI extension implemented by rendering a React component.
|
|
149
|
+
*/
|
|
150
|
+
type RenderableUiExtensionDefinition<TTarget extends UiExtensionTarget = UiExtensionTarget, TComponent extends DefinedExtensionComponent = DefinedExtensionComponent> = ExtensionContributionDefinition & {
|
|
151
|
+
/**
|
|
152
|
+
* Generated/normalized target identifying what this extension or augmentation applies to.
|
|
153
|
+
*/
|
|
154
|
+
target: TTarget;
|
|
155
|
+
/**
|
|
156
|
+
* React component rendered by a renderable UI extension.
|
|
157
|
+
*/
|
|
158
|
+
component: TComponent;
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* Structured standard-surface contribution. Use this shape for collection
|
|
162
|
+
* points such as Form.fields, Form.actions, DataTable.columns and Tabs.items.
|
|
163
|
+
* The contribution value is ordinary UI-kit data; target protocol metadata is
|
|
164
|
+
* still supplied entirely by the generated target token.
|
|
165
|
+
*/
|
|
166
|
+
type StructuredUiExtensionDefinition<TTarget extends UiExtensionTarget = UiExtensionTarget, TContribution = UiContributionOf<TTarget>, TPayload = unknown> = ExtensionContributionDefinition & {
|
|
167
|
+
/**
|
|
168
|
+
* Generated/normalized target identifying what this extension or augmentation applies to.
|
|
169
|
+
*/
|
|
170
|
+
target: TTarget;
|
|
171
|
+
/**
|
|
172
|
+
* Produce structured contribution data for the target collection point.
|
|
173
|
+
*
|
|
174
|
+
* @param context Scoped runtime context for this callback/operation.
|
|
175
|
+
* @returns Structured contribution value, or a promise resolving to it.
|
|
176
|
+
*/
|
|
177
|
+
contribute: StructuredUiExtensionModule<TContribution, TPayload>["contribute"];
|
|
178
|
+
/**
|
|
179
|
+
* Decide whether this extension participates for the current runtime context.
|
|
180
|
+
*
|
|
181
|
+
* @param context Scoped runtime context for this callback/operation.
|
|
182
|
+
* @returns Whether visible condition is satisfied.
|
|
183
|
+
*/
|
|
184
|
+
visible?: StructuredUiExtensionModule<TContribution, TPayload>["visible"];
|
|
185
|
+
/**
|
|
186
|
+
* Optional lifecycle hooks for this extension module.
|
|
187
|
+
*/
|
|
188
|
+
lifecycle?: ExtensionLifecycleHooks;
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* Union of renderable and structured UI extension definition shapes.
|
|
192
|
+
*/
|
|
193
|
+
type UiExtensionDefinition<TTarget extends UiExtensionTarget = UiExtensionTarget, TComponent extends DefinedExtensionComponent = DefinedExtensionComponent, TContribution = unknown, TPayload = unknown> = RenderableUiExtensionDefinition<TTarget, TComponent> | StructuredUiExtensionDefinition<TTarget, TContribution, TPayload>;
|
|
194
|
+
/** Define a renderable UI contribution whose runtime value is the supplied React component. */
|
|
195
|
+
declare function defineExtension<const TTarget extends UiExtensionTarget, TComponent extends DefinedExtensionComponent>(definition: RenderableUiExtensionDefinition<TTarget, TComponent>): TComponent;
|
|
196
|
+
/** Define a structured contribution for a generated semantic collection point. */
|
|
197
|
+
declare function defineExtension<const TTarget extends UiExtensionTarget, TPayload = unknown>(definition: StructuredUiExtensionDefinition<TTarget, UiContributionOf<TTarget>, TPayload>): StructuredUiExtensionModule<UiContributionOf<TTarget>, TPayload>;
|
|
198
|
+
/**
|
|
199
|
+
* Infer the request type carried by a generated provider target token.
|
|
200
|
+
*/
|
|
201
|
+
type ProviderRequestOf<TTarget> = TTarget extends ProviderExtensionTargetToken<infer TRequest, any> ? TRequest : unknown;
|
|
202
|
+
/**
|
|
203
|
+
* Infer the provided value type carried by a generated provider target token.
|
|
204
|
+
*/
|
|
205
|
+
type ProviderValueOf<TTarget> = TTarget extends ProviderExtensionTargetToken<any, infer TValue> ? TValue : unknown;
|
|
206
|
+
/**
|
|
207
|
+
* Infer the event payload type carried by a generated event target token.
|
|
208
|
+
*/
|
|
209
|
+
type EventPayloadOf<TTarget> = TTarget extends EventExtensionTargetToken<infer TPayload> ? TPayload : unknown;
|
|
210
|
+
/**
|
|
211
|
+
* Infer the operation payload type carried by a generated operation target token.
|
|
212
|
+
*/
|
|
213
|
+
type OperationPayloadOf<TTarget> = TTarget extends {
|
|
214
|
+
readonly __payload?: infer TPayload;
|
|
215
|
+
} ? TPayload : unknown;
|
|
216
|
+
/**
|
|
217
|
+
* Infer the operation result type carried by a generated operation target token.
|
|
218
|
+
*/
|
|
219
|
+
type OperationResultOf<TTarget> = TTarget extends {
|
|
220
|
+
readonly __result?: infer TResult;
|
|
221
|
+
} ? TResult : unknown;
|
|
222
|
+
/**
|
|
223
|
+
* Definition of a provider extension for a generated provider target.
|
|
224
|
+
*/
|
|
225
|
+
type ProviderDefinition<TTarget extends ProviderTarget<any, any> = ProviderTarget> = ExtensionContributionDefinition & {
|
|
226
|
+
/**
|
|
227
|
+
* Generated/normalized target identifying what this extension or augmentation applies to.
|
|
228
|
+
*/
|
|
229
|
+
target: TTarget;
|
|
230
|
+
/**
|
|
231
|
+
* Resolve a value for the targeted provider request.
|
|
232
|
+
*
|
|
233
|
+
* @param context Scoped runtime context for this callback/operation.
|
|
234
|
+
* @returns Provider value for the current request, or a promise resolving to it.
|
|
235
|
+
*/
|
|
236
|
+
provide: ProviderModule<ProviderRequestOf<TTarget>, ProviderValueOf<TTarget>>["provide"];
|
|
237
|
+
};
|
|
238
|
+
/**
|
|
239
|
+
* Define a provider extension using a generated provider target.
|
|
240
|
+
*
|
|
241
|
+
* @param definition Provider target, implementation and optional contribution metadata.
|
|
242
|
+
* @returns The unchanged provider definition consumed by build/runtime tooling.
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* ```ts
|
|
246
|
+
* export default defineProvider({
|
|
247
|
+
* target: customer.$providers.displayName,
|
|
248
|
+
* module: "./CustomerDisplayName",
|
|
249
|
+
* provide: ({ request }) => `Customer ${request.customerId}`,
|
|
250
|
+
* });
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
253
|
+
declare function defineProvider<const TTarget extends ProviderTarget<any, any>>(definition: ProviderDefinition<TTarget>): ProviderDefinition<TTarget>;
|
|
254
|
+
/**
|
|
255
|
+
* Definition of an event-handler extension for a generated event target.
|
|
256
|
+
*/
|
|
257
|
+
type EventHandlerDefinition<TTarget extends EventHandlerTarget<any> = EventHandlerTarget> = ExtensionContributionDefinition & {
|
|
258
|
+
/**
|
|
259
|
+
* Generated/normalized target identifying what this extension or augmentation applies to.
|
|
260
|
+
*/
|
|
261
|
+
target: TTarget;
|
|
262
|
+
/**
|
|
263
|
+
* Handle one event emitted by the targeted event contract.
|
|
264
|
+
*
|
|
265
|
+
* @param context Scoped runtime context for this callback/operation.
|
|
266
|
+
* @returns Completes when the operation finishes.
|
|
267
|
+
*/
|
|
268
|
+
handle: EventHandlerModule<EventPayloadOf<TTarget>>["handle"];
|
|
269
|
+
};
|
|
270
|
+
/**
|
|
271
|
+
* Define an event-handler extension using a generated event target.
|
|
272
|
+
*
|
|
273
|
+
* @param definition Event target, handler and optional contribution metadata.
|
|
274
|
+
* @returns The unchanged event-handler definition consumed by build/runtime tooling.
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* ```ts
|
|
278
|
+
* export const audit = defineEventHandler({
|
|
279
|
+
* target: customer.$events.saved,
|
|
280
|
+
* module: "./CustomerSavedAudit",
|
|
281
|
+
* handle: async ({ payload }) => auditCustomer(payload),
|
|
282
|
+
* });
|
|
283
|
+
* ```
|
|
284
|
+
*/
|
|
285
|
+
declare function defineEventHandler<const TTarget extends EventHandlerTarget<any>>(definition: EventHandlerDefinition<TTarget>): EventHandlerDefinition<TTarget>;
|
|
286
|
+
/**
|
|
287
|
+
* Definition of an operation-hook extension for a generated operation target.
|
|
288
|
+
*/
|
|
289
|
+
type OperationHookDefinition<TTarget extends OperationHookTarget<any, any> = OperationHookTarget> = ExtensionContributionDefinition & {
|
|
290
|
+
/**
|
|
291
|
+
* Generated/normalized target identifying what this extension or augmentation applies to.
|
|
292
|
+
*/
|
|
293
|
+
target: TTarget;
|
|
294
|
+
/** Optional explicit phase intent; handler presence remains authoritative. */
|
|
295
|
+
phases?: readonly OperationExtensionPhase[];
|
|
296
|
+
} & OperationHookModule<OperationPayloadOf<TTarget>, OperationResultOf<TTarget>>;
|
|
297
|
+
/**
|
|
298
|
+
* Define an operation-hook extension using a generated operation target.
|
|
299
|
+
*
|
|
300
|
+
* @param definition Operation target, phase handlers and optional contribution metadata.
|
|
301
|
+
* @returns The unchanged operation-hook definition consumed by build/runtime tooling.
|
|
302
|
+
*
|
|
303
|
+
* @example
|
|
304
|
+
* ```ts
|
|
305
|
+
* export const guard = defineOperationHook({
|
|
306
|
+
* target: customer.detail.form.$operations.submit,
|
|
307
|
+
* module: "./CustomerSubmitGuard",
|
|
308
|
+
* before: async ({ payload }) => ({ kind: "continue", payload }),
|
|
309
|
+
* });
|
|
310
|
+
* ```
|
|
311
|
+
*/
|
|
312
|
+
declare function defineOperationHook<const TTarget extends OperationHookTarget<any, any>>(definition: OperationHookDefinition<TTarget>): OperationHookDefinition<TTarget>;
|
|
313
|
+
|
|
314
|
+
export { EventHandlerModule, ExtensionLifecycleHooks, OperationHookModule, ProviderModule, StructuredUiExtensionModule, defineActions, defineEventHandler, defineExtension, defineOperationHook, defineProvider, defineRepeatedInstances, extensionTarget };
|
|
315
|
+
export type { DefinedExtensionComponent, EventHandlerDefinition, EventHandlerTarget, EventPayloadOf, ExtensionContributionDefinition, OperationHookDefinition, OperationHookTarget, OperationPayloadOf, OperationResultOf, PluginAction, PluginActionMap, ProviderDefinition, ProviderRequestOf, ProviderTarget, ProviderValueOf, RenderableUiExtensionDefinition, StructuredUiExtensionDefinition, UiContributionOf, UiExtensionDefinition, UiExtensionTarget };
|
package/dist/advanced.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"advanced.js"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { useScopedI18n } from '@plugmatica/i18n';
|
|
2
|
+
import { UiExtensionRuntimeProvider } from '@plugmatica/ui-kit/host';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
5
|
+
|
|
6
|
+
// src/externalNavigation.ts
|
|
7
|
+
function assertExternalNavigationUrl(destination) {
|
|
8
|
+
if (typeof destination !== "string" || destination.length > 4096) {
|
|
9
|
+
throw new Error("External navigation URL is invalid.");
|
|
10
|
+
}
|
|
11
|
+
let url;
|
|
12
|
+
try {
|
|
13
|
+
url = new URL(destination);
|
|
14
|
+
} catch {
|
|
15
|
+
throw new Error("External navigation URL is invalid.");
|
|
16
|
+
}
|
|
17
|
+
if (url.protocol !== "https:" || !url.hostname || url.port && url.port !== "443" || url.username || url.password || url.hash || !url.hostname.includes(".") || url.hostname === "localhost") {
|
|
18
|
+
throw new Error("External navigation requires a public HTTPS URL without credentials or fragments.");
|
|
19
|
+
}
|
|
20
|
+
return url.toString();
|
|
21
|
+
}
|
|
22
|
+
var defaultNavigation = {
|
|
23
|
+
navigate(to, options) {
|
|
24
|
+
if (typeof window === "undefined") {
|
|
25
|
+
throw new Error(
|
|
26
|
+
"Plugin navigation is unavailable outside a browser host."
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
if (options?.replace) {
|
|
30
|
+
window.location.replace(to);
|
|
31
|
+
} else {
|
|
32
|
+
window.location.assign(to);
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
navigateExternal(url) {
|
|
36
|
+
if (typeof window === "undefined") {
|
|
37
|
+
throw new Error("External navigation is unavailable outside a browser host.");
|
|
38
|
+
}
|
|
39
|
+
window.location.assign(assertExternalNavigationUrl(url));
|
|
40
|
+
},
|
|
41
|
+
currentPath() {
|
|
42
|
+
return typeof window === "undefined" ? "/" : `${window.location.pathname}${window.location.search}${window.location.hash}`;
|
|
43
|
+
},
|
|
44
|
+
subscribe(listener) {
|
|
45
|
+
if (typeof window === "undefined") return () => void 0;
|
|
46
|
+
window.addEventListener("popstate", listener);
|
|
47
|
+
window.addEventListener("hashchange", listener);
|
|
48
|
+
return () => {
|
|
49
|
+
window.removeEventListener("popstate", listener);
|
|
50
|
+
window.removeEventListener("hashchange", listener);
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
var defaultExtensions = {
|
|
55
|
+
registerSurface: () => void 0,
|
|
56
|
+
renderUi: ({ emptyFallback }) => emptyFallback ?? null,
|
|
57
|
+
resolveUi: async () => [],
|
|
58
|
+
runOperation: async ({ payload, execute }) => ({
|
|
59
|
+
status: "completed",
|
|
60
|
+
execution: "owner",
|
|
61
|
+
result: await execute(payload)
|
|
62
|
+
}),
|
|
63
|
+
emitEvent: async () => void 0,
|
|
64
|
+
resolveProviders: async () => [],
|
|
65
|
+
reportDiagnostic: () => void 0
|
|
66
|
+
};
|
|
67
|
+
function missingApiMethod(method) {
|
|
68
|
+
throw new Error(
|
|
69
|
+
`Plugin API method '${method}' is not configured. Ensure PluginRenderer receives a scoped API client.`
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
var defaultApi = {
|
|
73
|
+
get: async () => missingApiMethod("GET"),
|
|
74
|
+
getBlob: async () => missingApiMethod("GET Blob"),
|
|
75
|
+
getTransferBlob: async () => missingApiMethod("GET Blob Transfer"),
|
|
76
|
+
uploadTransfer: async () => missingApiMethod("PUT Blob Transfer"),
|
|
77
|
+
getArrayBuffer: async () => missingApiMethod("GET ArrayBuffer"),
|
|
78
|
+
post: async () => missingApiMethod("POST"),
|
|
79
|
+
put: async () => missingApiMethod("PUT"),
|
|
80
|
+
patch: async () => missingApiMethod("PATCH"),
|
|
81
|
+
delete: async () => missingApiMethod("DELETE"),
|
|
82
|
+
getWithMeta: async () => missingApiMethod("GET metadata"),
|
|
83
|
+
postWithMeta: async () => missingApiMethod("POST metadata"),
|
|
84
|
+
putWithMeta: async () => missingApiMethod("PUT metadata"),
|
|
85
|
+
patchWithMeta: async () => missingApiMethod("PATCH metadata"),
|
|
86
|
+
deleteWithMeta: async () => missingApiMethod("DELETE metadata")
|
|
87
|
+
};
|
|
88
|
+
function createPluginRuntime(context) {
|
|
89
|
+
return {
|
|
90
|
+
context,
|
|
91
|
+
api: context.api ?? defaultApi,
|
|
92
|
+
i18n: context.i18n,
|
|
93
|
+
session: context.session,
|
|
94
|
+
guest: context.guest,
|
|
95
|
+
navigation: context.navigation ?? defaultNavigation,
|
|
96
|
+
workflows: context.workflows,
|
|
97
|
+
workflowRealtime: context.workflowRealtime,
|
|
98
|
+
managedResources: context.managedResources,
|
|
99
|
+
extensions: context.extensions ?? defaultExtensions
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
var PluginRuntimeContext = React.createContext(null);
|
|
103
|
+
function PluginRuntimeProvider({
|
|
104
|
+
value,
|
|
105
|
+
children
|
|
106
|
+
}) {
|
|
107
|
+
const extensions = value.extensions;
|
|
108
|
+
const extensionEnvironmentKey = value.navigation.currentPath();
|
|
109
|
+
const uiRuntime = React.useMemo(
|
|
110
|
+
() => ({
|
|
111
|
+
ownerPluginIdentifier: value.context.plugin.identifier,
|
|
112
|
+
registerSurface: extensions.registerSurface,
|
|
113
|
+
renderUi: extensions.renderUi,
|
|
114
|
+
resolveUi: extensions.resolveUi,
|
|
115
|
+
runOperation: extensions.runOperation,
|
|
116
|
+
emitEvent: extensions.emitEvent,
|
|
117
|
+
resolveProviders: extensions.resolveProviders,
|
|
118
|
+
reportDiagnostic: extensions.reportDiagnostic
|
|
119
|
+
}),
|
|
120
|
+
[
|
|
121
|
+
value.context.plugin.identifier,
|
|
122
|
+
extensions.registerSurface,
|
|
123
|
+
extensions.renderUi,
|
|
124
|
+
extensions.resolveUi,
|
|
125
|
+
extensions.runOperation,
|
|
126
|
+
extensions.emitEvent,
|
|
127
|
+
extensions.resolveProviders,
|
|
128
|
+
extensions.reportDiagnostic
|
|
129
|
+
]
|
|
130
|
+
);
|
|
131
|
+
return /* @__PURE__ */ jsx(PluginRuntimeContext.Provider, { value, children: /* @__PURE__ */ jsx(
|
|
132
|
+
UiExtensionRuntimeProvider,
|
|
133
|
+
{
|
|
134
|
+
runtime: uiRuntime,
|
|
135
|
+
environmentKey: extensionEnvironmentKey,
|
|
136
|
+
children
|
|
137
|
+
}
|
|
138
|
+
) });
|
|
139
|
+
}
|
|
140
|
+
function usePluginRuntime() {
|
|
141
|
+
const runtime = React.useContext(PluginRuntimeContext);
|
|
142
|
+
if (!runtime) {
|
|
143
|
+
throw new Error(
|
|
144
|
+
"Plugin runtime is unavailable. Render plugin content through PluginRenderer or PluginRuntimeProvider."
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
return runtime;
|
|
148
|
+
}
|
|
149
|
+
var usePluginContext = () => usePluginRuntime().context;
|
|
150
|
+
var usePluginApi = () => usePluginRuntime().api;
|
|
151
|
+
var usePluginExtensions = () => usePluginRuntime().extensions;
|
|
152
|
+
var usePluginNavigation = () => usePluginRuntime().navigation;
|
|
153
|
+
var usePluginWorkflows = () => {
|
|
154
|
+
const workflows = usePluginRuntime().workflows;
|
|
155
|
+
if (!workflows)
|
|
156
|
+
throw new Error(
|
|
157
|
+
"Workflow management capability is unavailable for this plugin."
|
|
158
|
+
);
|
|
159
|
+
return workflows;
|
|
160
|
+
};
|
|
161
|
+
var usePluginWorkflowRealtime = () => usePluginRuntime().workflowRealtime;
|
|
162
|
+
var usePluginManagedResources = () => {
|
|
163
|
+
const managedResources = usePluginRuntime().managedResources;
|
|
164
|
+
if (!managedResources)
|
|
165
|
+
throw new Error(
|
|
166
|
+
"Managed resource capability is unavailable for this plugin."
|
|
167
|
+
);
|
|
168
|
+
return managedResources;
|
|
169
|
+
};
|
|
170
|
+
function usePluginI18n() {
|
|
171
|
+
return useScopedI18n(usePluginRuntime().i18n);
|
|
172
|
+
}
|
|
173
|
+
function PluginMessage({ id, values }) {
|
|
174
|
+
const { t } = usePluginI18n();
|
|
175
|
+
return /* @__PURE__ */ jsx(Fragment, { children: t(id, values) });
|
|
176
|
+
}
|
|
177
|
+
var usePluginSession = () => usePluginRuntime().session;
|
|
178
|
+
var usePluginGuestSession = () => usePluginRuntime().guest;
|
|
179
|
+
|
|
180
|
+
export { PluginMessage, PluginRuntimeProvider, assertExternalNavigationUrl, createPluginRuntime, usePluginApi, usePluginContext, usePluginExtensions, usePluginGuestSession, usePluginI18n, usePluginManagedResources, usePluginNavigation, usePluginSession, usePluginWorkflowRealtime, usePluginWorkflows };
|
|
181
|
+
//# sourceMappingURL=chunk-ACHELRPS.js.map
|
|
182
|
+
//# sourceMappingURL=chunk-ACHELRPS.js.map
|