@gravitee/graphene-policy-studio 1.0.0-alpha.1 → 1.0.0-alpha.2

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/USAGE_GUIDE.md ADDED
@@ -0,0 +1,211 @@
1
+ # Using Policy Studio
2
+
3
+ > **Scope:** These rules only apply when working with `@gravitee/graphene-policy-studio`. Do not apply them to unrelated parts of the codebase.
4
+
5
+ Policy Studio is the Graphene module for editing API flows, plans, and policy steps. The host application owns API data and persistence; the library provides the React contract (`PolicyStudioProvider`), domain types, and (as components land) studio UI.
6
+
7
+ Browse the live component catalog in this package’s Storybook (local: `yarn workspace @gravitee/graphene-policy-studio storybook`).
8
+
9
+ ## Package exports
10
+
11
+ | Export | What it is |
12
+ | ------ | ---------- |
13
+ | `@gravitee/graphene-policy-studio` | Single entry: provider, context hook, domain types, phase mappings, and `PolicyStudioLayout` (POC shell). |
14
+
15
+ **Named exports (main integration surface):**
16
+
17
+ | Symbol | Role |
18
+ | ------ | ---- |
19
+ | `PolicyStudioProvider` | Host contract wrapper — required at the root of any studio tree |
20
+ | `usePolicyStudioContext` | Read studio data and cached fetchers from child components |
21
+ | `PolicyStudioProviderProps`, `PolicyStudioContextValue` | TypeScript types for props and context |
22
+ | `PolicyStudioLayout` | Layout shell (sidebar + info bar + canvas regions) — POC, may evolve |
23
+ | `getFlowPhases`, `getProtocolType` | Map `ApiType` → flow phases and protocol |
24
+ | `API_TYPE_TO_PROTOCOL`, `FLOW_PHASES_BY_API_TYPE` | Static lookup tables |
25
+ | Domain types | `ApiType`, `Policy`, `Plan`, `Flow`, `SaveOutput`, `PolicyDocumentation`, etc. |
26
+
27
+ There are no subpath exports (e.g. no `@gravitee/graphene-policy-studio/context`). Import everything from the package root.
28
+
29
+ ## Dependencies (what the host needs)
30
+
31
+ | Dependency | Required | Notes |
32
+ | ---------- | -------- | ----- |
33
+ | `react`, `react-dom` | Yes (^19) | Provider and future UI components |
34
+ | `@gravitee/graphene-core` | Yes (^2) | Shared primitives used by studio UI (`cn`, `ScrollArea`, …) |
35
+ | `tailwindcss` | Optional (^4) | Recommended when using layout/components that rely on Graphene utility classes |
36
+
37
+ Install:
38
+
39
+ ```bash
40
+ yarn add @gravitee/graphene-policy-studio @gravitee/graphene-core react react-dom
41
+ ```
42
+
43
+ The host should also follow [Graphene integration](../core/USAGE_GUIDE.md) (fonts, styles, and optionally Tailwind theme) so studio UI matches the design system.
44
+
45
+ ## Imports
46
+
47
+ ```tsx
48
+ import {
49
+ PolicyStudioProvider,
50
+ usePolicyStudioContext,
51
+ getFlowPhases,
52
+ type ApiType,
53
+ type Policy,
54
+ type SaveOutput,
55
+ } from '@gravitee/graphene-policy-studio';
56
+ ```
57
+
58
+ Never import from internal paths under the package source tree. Only the published entry is supported.
59
+
60
+ ## Host integration (`PolicyStudioProvider`)
61
+
62
+ Wrap your API policy editing page with `PolicyStudioProvider`. The host supplies domain data and three callbacks: save, schema fetch, and documentation fetch.
63
+
64
+ ### Required props
65
+
66
+ | Prop | Type | Role |
67
+ | ---- | ---- | ---- |
68
+ | `apiType` | `ApiType` | Drives flow phases and protocol (`PROXY`, `MESSAGE`, `MCP_PROXY`, …) |
69
+ | `policies` | `readonly Policy[]` | Policy catalog for the API |
70
+ | `sharedPolicyGroups` | `readonly SharedPolicyGroupPolicy[]` | Shared policy groups available to the API |
71
+ | `plans` | `readonly Plan[]` | Plans and their flows |
72
+ | `commonFlows` | `readonly Flow[]` | API-level flows |
73
+ | `entrypointsInfo` | `readonly ConnectorInfo[]` | Entrypoint connectors (used for connector filtering) |
74
+ | `endpointsInfo` | `readonly ConnectorInfo[]` | Endpoint connectors |
75
+ | `flowExecution` | `FlowExecution` | Flow matching mode and `matchRequired` |
76
+ | `onSave` | `(output: SaveOutput) => void` | Persist studio changes (delta only) |
77
+ | `onFetchPolicySchema` | `(policy: Policy) => Promise<unknown>` | Host API: JSON schema for policy config |
78
+ | `onFetchPolicyDocumentation` | `(policy: Policy) => Promise<string \| PolicyDocumentation>` | Host API: policy docs |
79
+ | `children` | `React.ReactNode` | Studio UI or custom consumers |
80
+
81
+ ### Optional props
82
+
83
+ | Prop | Default | Role |
84
+ | ---- | ------- | ---- |
85
+ | `readOnly` | `false` | Disable editing in the studio |
86
+ | `loading` | `false` | Show loading state in studio consumers |
87
+
88
+ ### Performance
89
+
90
+ - **Memoize** array props (`policies`, `plans`, `commonFlows`, …) and `onSave` with `useMemo` / `useCallback`. They are in the context `useMemo` dependency array; new references every render force all consumers to re-render.
91
+ - **Fetcher callbacks** (`onFetchPolicySchema`, `onFetchPolicyDocumentation`) are captured on **first mount** inside the provider. Keep them referentially stable for the lifetime of the provider, or ensure they close over values that do not change.
92
+
93
+ ### To implement
94
+
95
+ Copy the snippet from `snippets/policy-studio-provider-host.tsx` and replace the placeholder comments with your API data and handlers. See Storybook **Policy Studio/PolicyStudioProvider** for interactive cache and save behavior.
96
+
97
+ ```mermaid
98
+ flowchart TB
99
+ Host[Host app]
100
+ Provider[PolicyStudioProvider]
101
+ Children[Studio UI or usePolicyStudioContext]
102
+ Host -->|policies plans onSave fetchers| Provider
103
+ Provider --> Children
104
+ ```
105
+
106
+ ## Context API (`usePolicyStudioContext`)
107
+
108
+ Call from any descendant of `PolicyStudioProvider`:
109
+
110
+ ```tsx
111
+ function PolicyConfigPanel() {
112
+ const { fetchPolicySchema, policies, readOnly, onSave } = usePolicyStudioContext();
113
+ // ...
114
+ }
115
+ ```
116
+
117
+ **Exposed on context:**
118
+
119
+ - All data props from the provider (`apiType`, `policies`, `plans`, `commonFlows`, …)
120
+ - `readOnly`, `loading`
121
+ - `onSave` — same callback the host passed in
122
+ - `fetchPolicySchema` — cached wrapper (not the raw host callback)
123
+ - `fetchPolicyDocumentation` — cached, normalized wrapper
124
+
125
+ Throws if used outside `PolicyStudioProvider`.
126
+
127
+ ## Fetcher contract
128
+
129
+ ### Policy schema (`onFetchPolicySchema` → `fetchPolicySchema`)
130
+
131
+ - Host returns `Promise<unknown>` (typically a JSON Schema object).
132
+ - Cached **per `policy.id`** for the lifetime of the provider mount.
133
+ - **Concurrent** calls for the same id share one in-flight promise.
134
+ - **Rejected** promises are **evicted** from the cache; the next call retries the host fetcher (transient network errors are not permanently cached).
135
+
136
+ Use `fetchPolicySchema` from context in UI — do not call the host callback directly from children.
137
+
138
+ ### Policy documentation (`onFetchPolicyDocumentation` → `fetchPolicyDocumentation`)
139
+
140
+ - Host may return a raw `string` (treated as ASCIIDOC: `{ content, language: 'ASCIIDOC' }`) or a `PolicyDocumentation` object.
141
+ - Empty content and fetch **errors** resolve to a standard placeholder: `{ content: 'No documentation available.', language: 'MARKDOWN' }`.
142
+ - Cached per `policy.id` like schema; concurrent deduplication applies.
143
+
144
+ Use `fetchPolicyDocumentation` from context — it always returns `Promise<PolicyDocumentation>`.
145
+
146
+ ## Save contract
147
+
148
+ `onSave` receives a **`SaveOutput` delta**, not the full API entity:
149
+
150
+ ```ts
151
+ type SaveOutput = {
152
+ readonly commonFlows?: readonly Flow[];
153
+ readonly flowExecution?: FlowExecution;
154
+ readonly plansToUpdate?: readonly Plan[];
155
+ };
156
+ ```
157
+
158
+ The host merges this delta into its API model and persists. Saving does not clear schema or documentation caches.
159
+
160
+ ## Domain helpers
161
+
162
+ Align host payloads with studio rules:
163
+
164
+ ```tsx
165
+ import { getFlowPhases, getProtocolType, API_TYPE_TO_PROTOCOL } from '@gravitee/graphene-policy-studio';
166
+
167
+ const phases = getFlowPhases('PROXY'); // ['REQUEST', 'RESPONSE']
168
+ const protocol = getProtocolType('MESSAGE'); // 'HTTP_MESSAGE'
169
+ ```
170
+
171
+ | Helper | Use |
172
+ | ------ | --- |
173
+ | `getFlowPhases(apiType)` | Which phases to show in the canvas for this API type |
174
+ | `getProtocolType(apiType)` | Protocol key used for policy compatibility |
175
+ | `FLOW_PHASES_BY_API_TYPE` | Static phase list per API type |
176
+ | `API_TYPE_TO_PROTOCOL` | Static protocol mapping |
177
+
178
+ ## Key types
179
+
180
+ | Type | Purpose |
181
+ | ---- | ------- |
182
+ | `ApiType` | `PROXY`, `MESSAGE`, `MCP_PROXY`, `LLM_PROXY`, `NATIVE`, `A2A_PROXY` |
183
+ | `Policy` | Catalog entry (`id`, `name`, optional `category`, `icon`, …) |
184
+ | `Flow` | Selectors + phase steps (`request`, `response`, `connect`, …) |
185
+ | `Plan` | `id`, `name`, `flows` |
186
+ | `Step` | Policy step on a flow (`policy`, `configuration`, `enabled`, …) |
187
+ | `SaveOutput` | Delta passed to `onSave` |
188
+ | `PolicyDocumentation` | `{ content: string; language: 'MARKDOWN' \| 'ASCIIDOC' }` |
189
+
190
+ Import the named types from `@gravitee/graphene-policy-studio` for full TypeScript shapes in your host app.
191
+
192
+ ## Layout shell (`PolicyStudioLayout`)
193
+
194
+ Optional POC layout: three regions (sidebar, info bar, main). Requires Graphene styles/Tailwind in the host. Most POC components are not exported yet — build custom UI with `usePolicyStudioContext()` or follow in-repo Storybook under **Policy Studio - POC** until production `components/` ship.
195
+
196
+ ## Common mistakes to avoid
197
+
198
+ - Passing **inline arrays** (`policies={[...]}`) or **inline callbacks** without `useMemo` / `useCallback` — causes unnecessary context updates.
199
+ - Recreating **fetcher functions** on every render while expecting updated closures — fetchers are frozen at first mount.
200
+ - Calling **`onFetchPolicySchema`** from children instead of **`fetchPolicySchema`** from context — bypasses cache and deduplication.
201
+ - Treating documentation fetch results as always `string` — use context’s normalized `PolicyDocumentation`.
202
+ - Expecting **`onSave`** to receive the full API definition — only `SaveOutput` fields the user changed.
203
+ - Using Policy Studio **without** `@gravitee/graphene-core` styling when rendering exported layout/components — UI will look unstyled.
204
+
205
+ ## Snippets
206
+
207
+ | File | When to use |
208
+ | ---- | ----------- |
209
+ | `snippets/policy-studio-provider-host.tsx` | First integration: provider + memoized host callbacks |
210
+
211
+ Snippets ship in the npm package under `node_modules/@gravitee/graphene-policy-studio/snippets/`. They are copy-paste templates, not importable modules.
@@ -0,0 +1,46 @@
1
+ import { ApiType, ConnectorInfo, Flow, FlowExecution, Plan, Policy, PolicyDocumentation, SaveOutput, SharedPolicyGroupPolicy } from '../types';
2
+ /**
3
+ * Props for the Policy Studio host contract.
4
+ *
5
+ * Array and callback props (`policies`, `plans`, `onSave`, `onFetchPolicySchema`, etc.)
6
+ * are included in the context `useMemo` dependency array. Hosts should memoize these
7
+ * values (e.g. via `useMemo` / `useCallback`) to avoid unnecessary context re-renders.
8
+ *
9
+ * Fetcher callbacks (`onFetchPolicySchema`, `onFetchPolicyDocumentation`) are captured
10
+ * by `useRef` on first mount — their identity is frozen for the lifetime of the provider.
11
+ * Ensure they are referentially stable or close over values that won't change.
12
+ */
13
+ export interface PolicyStudioProviderProps {
14
+ readonly apiType: ApiType;
15
+ readonly policies: readonly Policy[];
16
+ readonly sharedPolicyGroups: readonly SharedPolicyGroupPolicy[];
17
+ readonly plans: readonly Plan[];
18
+ readonly commonFlows: readonly Flow[];
19
+ readonly entrypointsInfo: readonly ConnectorInfo[];
20
+ readonly endpointsInfo: readonly ConnectorInfo[];
21
+ readonly flowExecution: FlowExecution;
22
+ readonly readOnly?: boolean;
23
+ readonly loading?: boolean;
24
+ readonly onSave: (output: SaveOutput) => void;
25
+ readonly onFetchPolicySchema: (policy: Policy) => Promise<unknown>;
26
+ readonly onFetchPolicyDocumentation: (policy: Policy) => Promise<string | PolicyDocumentation>;
27
+ readonly children: React.ReactNode;
28
+ }
29
+ export interface PolicyStudioContextValue {
30
+ readonly apiType: ApiType;
31
+ readonly policies: readonly Policy[];
32
+ readonly sharedPolicyGroups: readonly SharedPolicyGroupPolicy[];
33
+ readonly plans: readonly Plan[];
34
+ readonly commonFlows: readonly Flow[];
35
+ readonly entrypointsInfo: readonly ConnectorInfo[];
36
+ readonly endpointsInfo: readonly ConnectorInfo[];
37
+ readonly flowExecution: FlowExecution;
38
+ readonly readOnly: boolean;
39
+ readonly loading: boolean;
40
+ readonly onSave: (output: SaveOutput) => void;
41
+ readonly fetchPolicySchema: (policy: Policy) => Promise<unknown>;
42
+ readonly fetchPolicyDocumentation: (policy: Policy) => Promise<PolicyDocumentation>;
43
+ }
44
+ export declare function PolicyStudioProvider({ apiType, policies, sharedPolicyGroups, plans, commonFlows, entrypointsInfo, endpointsInfo, flowExecution, readOnly, loading, onSave, onFetchPolicySchema, onFetchPolicyDocumentation, children, }: PolicyStudioProviderProps): import("react/jsx-runtime").JSX.Element;
45
+ export declare function usePolicyStudioContext(): PolicyStudioContextValue;
46
+ //# sourceMappingURL=PolicyStudioProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PolicyStudioProvider.d.ts","sourceRoot":"","sources":["../../src/context/PolicyStudioProvider.tsx"],"names":[],"mappings":"AAUA,OAAO,KAAK,EACV,OAAO,EACP,aAAa,EACb,IAAI,EACJ,aAAa,EACb,IAAI,EACJ,MAAM,EACN,mBAAmB,EACnB,UAAU,EACV,uBAAuB,EACxB,MAAM,UAAU,CAAC;AAIlB;;;;;;;;;;GAUG;AACH,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,QAAQ,CAAC,kBAAkB,EAAE,SAAS,uBAAuB,EAAE,CAAC;IAChE,QAAQ,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC;IAChC,QAAQ,CAAC,WAAW,EAAE,SAAS,IAAI,EAAE,CAAC;IACtC,QAAQ,CAAC,eAAe,EAAE,SAAS,aAAa,EAAE,CAAC;IACnD,QAAQ,CAAC,aAAa,EAAE,SAAS,aAAa,EAAE,CAAC;IACjD,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IACtC,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;IAC9C,QAAQ,CAAC,mBA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BAA0B,EAC1B,QAAQ,GACT,EAAE,yBAAyB,2CAwC3B;AAID,wBAAgB,sBAAsB,IAAI,wBAAwB,CAMjE"}
@@ -0,0 +1,3 @@
1
+ export { PolicyStudioProvider, usePolicyStudioContext } from './PolicyStudioProvider';
2
+ export type { PolicyStudioContextValue, PolicyStudioProviderProps } from './PolicyStudioProvider';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACtF,YAAY,EAAE,wBAAwB,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { Policy, PolicyDocumentation } from '../types';
2
+ interface UsePolicyDocsOptions {
3
+ readonly onFetchPolicySchema: (policy: Policy) => Promise<unknown>;
4
+ readonly onFetchPolicyDocumentation: (policy: Policy) => Promise<string | PolicyDocumentation>;
5
+ }
6
+ interface UsePolicyDocsResult {
7
+ readonly fetchPolicySchema: (policy: Policy) => Promise<unknown>;
8
+ readonly fetchPolicyDocumentation: (policy: Policy) => Promise<PolicyDocumentation>;
9
+ }
10
+ /**
11
+ * Composes host-provided fetchers with per-instance caching (spec 15).
12
+ *
13
+ * Cache maps are stored in refs so they persist across re-renders but are
14
+ * scoped to a single provider mount — matching the "per-service-instance"
15
+ * requirement from the spec.
16
+ */
17
+ export declare function usePolicyDocs({ onFetchPolicySchema, onFetchPolicyDocumentation, }: UsePolicyDocsOptions): UsePolicyDocsResult;
18
+ export {};
19
+ //# sourceMappingURL=use-policy-docs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-policy-docs.d.ts","sourceRoot":"","sources":["../../src/hooks/use-policy-docs.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAE5D,UAAU,oBAAoB;IAC5B,QAAQ,CAAC,mBAAmB,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACnE,QAAQ,CAAC,0BAA0B,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,mBAAmB,CAAC,CAAC;CAChG;AAED,UAAU,mBAAmB;IAC3B,QAAQ,CAAC,iBAAiB,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACjE,QAAQ,CAAC,wBAAwB,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,mBAAmB,CAAC,CAAC;CACrF;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,EAC5B,mBAAmB,EACnB,0BAA0B,GAC3B,EAAE,oBAAoB,GAAG,mBAAmB,CAS5C"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './context';
1
2
  export * from './poc/index';
2
3
  export * from './mappings';
3
4
  export * from './types';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC"}
package/dist/index.js CHANGED
@@ -1,23 +1,118 @@
1
- import { ScrollArea as e, cn as t } from "@gravitee/graphene-core";
2
- import { jsx as n, jsxs as r } from "react/jsx-runtime";
1
+ import { createContext as e, useCallback as t, useContext as n, useMemo as r, useRef as i } from "react";
2
+ import { jsx as a, jsxs as o } from "react/jsx-runtime";
3
+ import { ScrollArea as s, cn as c } from "@gravitee/graphene-core";
4
+ //#region src/lib/policy-documentation.ts
5
+ var l = {
6
+ content: "No documentation available.",
7
+ language: "MARKDOWN"
8
+ };
9
+ function u(e) {
10
+ return typeof e == "object" && !!e && "content" in e && typeof e.content == "string" && "language" in e;
11
+ }
12
+ function d(e) {
13
+ return u(e) ? e.content ? e : l : e ? {
14
+ content: e,
15
+ language: "ASCIIDOC"
16
+ } : l;
17
+ }
18
+ function f(e) {
19
+ return async (t) => {
20
+ try {
21
+ return d(await e(t));
22
+ } catch {
23
+ return l;
24
+ }
25
+ };
26
+ }
27
+ //#endregion
28
+ //#region src/lib/policy-fetch-cache.ts
29
+ function p(e) {
30
+ let t = /* @__PURE__ */ new Map();
31
+ function n(n) {
32
+ let r = t.get(n.id);
33
+ if (r) return r;
34
+ let i = e(n);
35
+ return t.set(n.id, i), i.catch(() => t.delete(n.id)), i;
36
+ }
37
+ return {
38
+ fetch: n,
39
+ cache: t
40
+ };
41
+ }
42
+ //#endregion
43
+ //#region src/hooks/use-policy-docs.ts
44
+ function m({ onFetchPolicySchema: e, onFetchPolicyDocumentation: n }) {
45
+ let r = i(p(e)), a = i(p(f(n)));
46
+ return {
47
+ fetchPolicySchema: t((e) => r.current.fetch(e), []),
48
+ fetchPolicyDocumentation: t((e) => a.current.fetch(e), [])
49
+ };
50
+ }
51
+ //#endregion
52
+ //#region src/context/PolicyStudioProvider.tsx
53
+ var h = e(null);
54
+ function g({ apiType: e, policies: t, sharedPolicyGroups: n, plans: i, commonFlows: o, entrypointsInfo: s, endpointsInfo: c, flowExecution: l, readOnly: u = !1, loading: d = !1, onSave: f, onFetchPolicySchema: p, onFetchPolicyDocumentation: g, children: _ }) {
55
+ let { fetchPolicySchema: v, fetchPolicyDocumentation: y } = m({
56
+ onFetchPolicySchema: p,
57
+ onFetchPolicyDocumentation: g
58
+ }), b = r(() => ({
59
+ apiType: e,
60
+ policies: t,
61
+ sharedPolicyGroups: n,
62
+ plans: i,
63
+ commonFlows: o,
64
+ entrypointsInfo: s,
65
+ endpointsInfo: c,
66
+ flowExecution: l,
67
+ readOnly: u,
68
+ loading: d,
69
+ onSave: f,
70
+ fetchPolicySchema: v,
71
+ fetchPolicyDocumentation: y
72
+ }), [
73
+ e,
74
+ t,
75
+ n,
76
+ i,
77
+ o,
78
+ s,
79
+ c,
80
+ l,
81
+ u,
82
+ d,
83
+ f,
84
+ v,
85
+ y
86
+ ]);
87
+ return /* @__PURE__ */ a(h.Provider, {
88
+ value: b,
89
+ children: _
90
+ });
91
+ }
92
+ function _() {
93
+ let e = n(h);
94
+ if (!e) throw Error("usePolicyStudioContext must be used within a PolicyStudioProvider.");
95
+ return e;
96
+ }
97
+ //#endregion
3
98
  //#region src/poc/PolicyStudioLayout.tsx
4
- function i({ sidebar: i, infoBar: a, children: o, className: s }) {
5
- return /* @__PURE__ */ r("div", {
6
- className: t("grid h-full grid-cols-[240px_1fr] grid-rows-[auto_1fr] overflow-hidden", s),
99
+ function v({ sidebar: e, infoBar: t, children: n, className: r }) {
100
+ return /* @__PURE__ */ o("div", {
101
+ className: c("grid h-full grid-cols-[240px_1fr] grid-rows-[auto_1fr] overflow-hidden", r),
7
102
  children: [
8
- /* @__PURE__ */ n(e, {
103
+ /* @__PURE__ */ a(s, {
9
104
  className: "row-span-2 border-r bg-background",
10
- children: i
105
+ children: e
11
106
  }),
12
- /* @__PURE__ */ n("div", {
107
+ /* @__PURE__ */ a("div", {
13
108
  className: "min-w-0",
14
- children: a
109
+ children: t
15
110
  }),
16
- /* @__PURE__ */ n(e, {
111
+ /* @__PURE__ */ a(s, {
17
112
  className: "min-w-0 bg-background",
18
- children: /* @__PURE__ */ n("div", {
113
+ children: /* @__PURE__ */ a("div", {
19
114
  className: "p-6",
20
- children: o
115
+ children: n
21
116
  })
22
117
  })
23
118
  ]
@@ -25,14 +120,14 @@ function i({ sidebar: i, infoBar: a, children: o, className: s }) {
25
120
  }
26
121
  //#endregion
27
122
  //#region src/mappings.ts
28
- var a = {
123
+ var y = {
29
124
  A2A_PROXY: "A2A_PROXY",
30
125
  LLM_PROXY: "LLM_PROXY",
31
126
  MCP_PROXY: "MCP_PROXY",
32
127
  MESSAGE: "HTTP_MESSAGE",
33
128
  NATIVE: "NATIVE_KAFKA",
34
129
  PROXY: "HTTP_PROXY"
35
- }, o = {
130
+ }, b = {
36
131
  A2A_PROXY: [],
37
132
  LLM_PROXY: ["REQUEST", "RESPONSE"],
38
133
  MCP_PROXY: ["REQUEST", "RESPONSE"],
@@ -50,11 +145,11 @@ var a = {
50
145
  ],
51
146
  PROXY: ["REQUEST", "RESPONSE"]
52
147
  };
53
- function s(e) {
54
- return a[e];
148
+ function x(e) {
149
+ return y[e];
55
150
  }
56
- function c(e) {
57
- return o[e];
151
+ function S(e) {
152
+ return b[e];
58
153
  }
59
154
  //#endregion
60
- export { a as API_TYPE_TO_PROTOCOL, o as FLOW_PHASES_BY_API_TYPE, i as PolicyStudioLayout, c as getFlowPhases, s as getProtocolType };
155
+ export { y as API_TYPE_TO_PROTOCOL, b as FLOW_PHASES_BY_API_TYPE, v as PolicyStudioLayout, g as PolicyStudioProvider, S as getFlowPhases, x as getProtocolType, _ as usePolicyStudioContext };
@@ -0,0 +1,16 @@
1
+ import { Policy, PolicyDocumentation } from '../types';
2
+ /**
3
+ * Normalize a raw fetcher result into a `PolicyDocumentation`.
4
+ *
5
+ * - Raw `string` → `{ content, language: 'ASCIIDOC' }` (spec 15 string fallback).
6
+ * - Empty content or `null`/`undefined` → standard placeholder.
7
+ * - Already `PolicyDocumentation` → pass through.
8
+ */
9
+ export declare function normalizePolicyDocumentation(raw: string | PolicyDocumentation): PolicyDocumentation;
10
+ /**
11
+ * Wraps a host-provided documentation fetcher so callers always receive
12
+ * a `PolicyDocumentation` — errors and empty results resolve to the
13
+ * standard fallback instead of rejecting.
14
+ */
15
+ export declare function createNormalizedDocumentationFetcher(rawFetcher: (policy: Policy) => Promise<string | PolicyDocumentation>): (policy: Policy) => Promise<PolicyDocumentation>;
16
+ //# sourceMappingURL=policy-documentation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy-documentation.d.ts","sourceRoot":"","sources":["../../src/lib/policy-documentation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAiB5D;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAAC,GAAG,EAAE,MAAM,GAAG,mBAAmB,GAAG,mBAAmB,CAKnG;AAED;;;;GAIG;AACH,wBAAgB,oCAAoC,CAClD,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,mBAAmB,CAAC,GACpE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,mBAAmB,CAAC,CASlD"}
@@ -0,0 +1,15 @@
1
+ import { Policy } from '../types';
2
+ interface PolicyFetchCache<T> {
3
+ readonly fetch: (policy: Policy) => Promise<T>;
4
+ readonly cache: Map<string, Promise<T>>;
5
+ }
6
+ /**
7
+ * Creates a per-instance cache that deduplicates in-flight requests by `policy.id`.
8
+ * The **Promise itself** is cached so concurrent callers share one request.
9
+ *
10
+ * Rejected promises are evicted so transient failures don't permanently
11
+ * poison the cache — the next call for the same `policy.id` retries.
12
+ */
13
+ export declare function createPolicyFetchCache<T>(fetcher: (policy: Policy) => Promise<T>): PolicyFetchCache<T>;
14
+ export {};
15
+ //# sourceMappingURL=policy-fetch-cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy-fetch-cache.d.ts","sourceRoot":"","sources":["../../src/lib/policy-fetch-cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC,UAAU,gBAAgB,CAAC,CAAC;IAC1B,QAAQ,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IAC/C,QAAQ,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;CACzC;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CActG"}
package/dist/types.d.ts CHANGED
@@ -95,4 +95,8 @@ export type SaveOutput = {
95
95
  readonly flowExecution?: FlowExecution;
96
96
  readonly plansToUpdate?: readonly Plan[];
97
97
  };
98
+ export interface PolicyDocumentation {
99
+ readonly content: string;
100
+ readonly language: 'MARKDOWN' | 'ASCIIDOC';
101
+ }
98
102
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,MAAM,OAAO,GAAG,WAAW,GAAG,WAAW,GAAG,WAAW,GAAG,SAAS,GAAG,QAAQ,GAAG,OAAO,CAAC;AAE/F,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,cAAc,GAAG,YAAY,GAAG,WAAW,GAAG,WAAW,GAAG,cAAc,CAAC;AAEvH,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,UAAU,GAAG,UAAU,GAAG,SAAS,GAAG,SAAS,GAAG,WAAW,CAAC;AAElG,MAAM,MAAM,QAAQ,GAAG,YAAY,GAAG,SAAS,CAAC;AAEhD,MAAM,MAAM,oBAAoB,GAAG,SAAS,GAAG,WAAW,GAAG,MAAM,GAAG,KAAK,CAAC;AAE5E,8FAA8F;AAC9F,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,QAAQ,GAAG,KAAK,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,CAAC;AAEhH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MA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AED,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAC1B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,mBAAmB,CAAC,EAAE,MAAM,CAAC;CACvC,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,WAAW,CAAC,EAAE,SAAS,IAAI,EAAE,CAAC;IACvC,QAAQ,CAAC,aAAa,CAAC,EAAE,aAAa,CAAC;IACvC,QAAQ,CAAC,aAAa,CAAC,EAAE,SAAS,IAAI,EAAE,CAAC;CAC1C,CAAC;AAEF,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,UAAU,GAAG,UAAU,CAAC;CAC5C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravitee/graphene-policy-studio",
3
- "version": "1.0.0-alpha.1",
3
+ "version": "1.0.0-alpha.2",
4
4
  "type": "module",
5
5
  "description": "Gravitee Policy Studio UI for the Graphene design system.",
6
6
  "keywords": [
@@ -30,7 +30,9 @@
30
30
  }
31
31
  },
32
32
  "files": [
33
- "dist"
33
+ "dist",
34
+ "snippets",
35
+ "USAGE_GUIDE.md"
34
36
  ],
35
37
  "scripts": {
36
38
  "dev": "storybook dev -p 6008",
@@ -0,0 +1,55 @@
1
+ // Snippet: Policy Studio host provider wiring
2
+ //
3
+ // Use when embedding Policy Studio in an API management page and you own
4
+ // the API data, fetchers, and save handler (provider host contract).
5
+ // Do NOT use without real onFetchPolicySchema / onFetchPolicyDocumentation /
6
+ // onSave implementations — the studio needs live host callbacks.
7
+ //
8
+ // Replace {PLACEHOLDERS} with your actual values.
9
+ // See Storybook "Policy Studio/PolicyStudioProvider" for cache and save demos.
10
+
11
+ import { useCallback, useMemo } from 'react';
12
+ import { PolicyStudioProvider } from '@gravitee/graphene-policy-studio';
13
+ import type { ApiType, Policy, SaveOutput } from '@gravitee/graphene-policy-studio';
14
+
15
+ // 1. Build the page that wires host data and callbacks into the provider.
16
+ export function ApiPolicyStudioPage({ apiType }: { apiType: ApiType }) {
17
+ const policies = useMemo(() => [] as const /* replace with policies from API */, []);
18
+ const plans = useMemo(() => [] as const /* replace with plans from API */, []);
19
+ const commonFlows = useMemo(() => [] as const /* replace with commonFlows from API */, []);
20
+ const sharedPolicyGroups = useMemo(() => [] as const /* replace with shared policy groups */, []);
21
+ const entrypointsInfo = useMemo(() => [] as const /* replace with entrypointsInfo */, []);
22
+ const endpointsInfo = useMemo(() => [] as const /* replace with endpointsInfo */, []);
23
+
24
+ const onSave = useCallback((_output: SaveOutput) => {
25
+ /* replace: persist SaveOutput delta to your API */
26
+ }, []);
27
+
28
+ const onFetchPolicySchema = useCallback(async (_policy: Policy) => {
29
+ /* replace: GET JSON schema for policy.id */
30
+ return {};
31
+ }, []);
32
+
33
+ const onFetchPolicyDocumentation = useCallback(async (_policy: Policy) => {
34
+ /* replace: GET docs (string or PolicyDocumentation) for policy.id */
35
+ return '';
36
+ }, []);
37
+
38
+ return (
39
+ <PolicyStudioProvider
40
+ apiType={apiType}
41
+ policies={policies}
42
+ sharedPolicyGroups={sharedPolicyGroups}
43
+ plans={plans}
44
+ commonFlows={commonFlows}
45
+ entrypointsInfo={entrypointsInfo}
46
+ endpointsInfo={endpointsInfo}
47
+ flowExecution={{ mode: 'DEFAULT' }}
48
+ onSave={onSave}
49
+ onFetchPolicySchema={onFetchPolicySchema}
50
+ onFetchPolicyDocumentation={onFetchPolicyDocumentation}
51
+ >
52
+ {null /* replace with studio UI (PolicyStudioLayout) or children using usePolicyStudioContext() */}
53
+ </PolicyStudioProvider>
54
+ );
55
+ }