@seamware/odrl-policy-editor 1.5.0-PRE-53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +782 -0
- package/dist-component/odrl-policy-editor.d.ts +185 -0
- package/dist-component/odrl-policy-editor.js +36446 -0
- package/package.json +76 -0
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public TypeScript declarations for `@seamware/odrl-policy-editor`.
|
|
3
|
+
*
|
|
4
|
+
* This hand-crafted declaration file is copied into `dist-component/`
|
|
5
|
+
* during the `build:component` script so npm consumers get type-checking
|
|
6
|
+
* out of the box.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
// Editor mode & theme preset
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
|
|
15
|
+
/** Editor operating mode: create a new policy or edit an existing one. */
|
|
16
|
+
export type EditorMode = 'create' | 'edit';
|
|
17
|
+
|
|
18
|
+
/** Theme preset names supported by the embedded component. */
|
|
19
|
+
export type EmbeddedThemePreset = 'light' | 'dark';
|
|
20
|
+
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
// Event map
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Map of custom event names to their `detail` payload types.
|
|
27
|
+
*
|
|
28
|
+
* The Web Component host listens for these events on the custom element:
|
|
29
|
+
*
|
|
30
|
+
* ```js
|
|
31
|
+
* editor.addEventListener('policy-created', (e) => {
|
|
32
|
+
* console.log(e.detail.id, e.detail.policy);
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export interface EmbeddedEventMap {
|
|
37
|
+
/** Fired after a new policy is successfully saved. */
|
|
38
|
+
'policy-created': { policy: Record<string, unknown>; id: string };
|
|
39
|
+
/** Fired after an existing policy is successfully updated. */
|
|
40
|
+
'policy-updated': { policy: Record<string, unknown>; id: string };
|
|
41
|
+
/** Fired after a policy validation completes. */
|
|
42
|
+
'policy-validated': { result: Record<string, unknown> };
|
|
43
|
+
/** Fired when the user clicks Cancel. */
|
|
44
|
+
'editor-cancelled': Record<string, never>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Callback signature for dispatching custom events to the host. */
|
|
48
|
+
export type OnEventCallback = <K extends keyof EmbeddedEventMap>(
|
|
49
|
+
type: K,
|
|
50
|
+
detail: EmbeddedEventMap[K],
|
|
51
|
+
) => void;
|
|
52
|
+
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
// Configuration
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
|
|
57
|
+
/** Configuration supplied by the Web Component wrapper. */
|
|
58
|
+
export interface EmbeddedConfig {
|
|
59
|
+
/** Base URL for all PAP API calls (e.g., `"https://pap.example.com"`). */
|
|
60
|
+
apiBaseUrl: string;
|
|
61
|
+
/** Optional Bearer token injected into every API request. */
|
|
62
|
+
authToken: string | null;
|
|
63
|
+
/** Whether to create a new policy or edit an existing one. */
|
|
64
|
+
mode: EditorMode;
|
|
65
|
+
/** Policy ID to load when `mode` is `"edit"`. */
|
|
66
|
+
policyId: string | null;
|
|
67
|
+
/** UI locale (e.g., `"en"`, `"de"`). */
|
|
68
|
+
locale: string;
|
|
69
|
+
/** Theme preset name. */
|
|
70
|
+
theme: EmbeddedThemePreset;
|
|
71
|
+
/** Callback to emit Custom Events on the host element. */
|
|
72
|
+
onEvent: OnEventCallback;
|
|
73
|
+
/**
|
|
74
|
+
* Custom JSON-LD `@context` for new policies.
|
|
75
|
+
*
|
|
76
|
+
* Accepts an object (namespaced map) or a string (context URI).
|
|
77
|
+
* When set, overrides the built-in default context.
|
|
78
|
+
*/
|
|
79
|
+
policyContext?: Record<string, string> | string | null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// ---------------------------------------------------------------------------
|
|
83
|
+
// Custom Element class
|
|
84
|
+
// ---------------------------------------------------------------------------
|
|
85
|
+
|
|
86
|
+
/** Tag name registered in the Custom Elements registry. */
|
|
87
|
+
export const TAG_NAME: 'odrl-policy-editor';
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* `<odrl-policy-editor>` custom element class.
|
|
91
|
+
*
|
|
92
|
+
* ## Observed HTML attributes
|
|
93
|
+
*
|
|
94
|
+
* | Attribute | Description | Default |
|
|
95
|
+
* |------------------|-----------------------------------------------|------------|
|
|
96
|
+
* | `api-base-url` | PAP API base URL | `""` |
|
|
97
|
+
* | `auth-token` | Bearer token for API authentication | `null` |
|
|
98
|
+
* | `mode` | `"create"` or `"edit"` | `"create"` |
|
|
99
|
+
* | `policy-id` | Policy ID to load (when `mode="edit"`) | `null` |
|
|
100
|
+
* | `theme` | `"light"` or `"dark"` | `"light"` |
|
|
101
|
+
* | `locale` | Language code (e.g., `"en"`, `"de"`) | `"en"` |
|
|
102
|
+
* | `policy-context` | JSON-LD `@context` for new policies (JSON) | `null` |
|
|
103
|
+
*
|
|
104
|
+
* ## JS Properties
|
|
105
|
+
*
|
|
106
|
+
* - `i18nStrings` — partial i18n override object (deep-merged with defaults)
|
|
107
|
+
* - `themeConfig` — partial ThemeConfig override merged on top of the preset
|
|
108
|
+
* - `template` — a PolicyTemplate object to pre-fill and constrain the editor
|
|
109
|
+
* - `policyContext` — custom JSON-LD `@context` object/string for new policies
|
|
110
|
+
*
|
|
111
|
+
* ## Custom Events
|
|
112
|
+
*
|
|
113
|
+
* | Event | Detail |
|
|
114
|
+
* |--------------------|---------------------------------------------|
|
|
115
|
+
* | `policy-created` | `{ policy: object, id: string }` |
|
|
116
|
+
* | `policy-updated` | `{ policy: object, id: string }` |
|
|
117
|
+
* | `policy-validated` | `{ result: object }` |
|
|
118
|
+
* | `editor-cancelled` | `{}` |
|
|
119
|
+
*/
|
|
120
|
+
export declare class OdrlPolicyEditorElement extends HTMLElement {
|
|
121
|
+
/** Attributes that trigger re-renders when changed. */
|
|
122
|
+
static readonly observedAttributes: string[];
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Partial i18n string overrides.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```js
|
|
129
|
+
* editor.i18nStrings = { policyBuilder: { title: 'Richtlinien-Editor' } };
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
i18nStrings: Record<string, unknown> | undefined;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Partial theme config overrides.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```js
|
|
139
|
+
* editor.themeConfig = { 'odrl-primary-color': '#1a73e8' };
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
themeConfig: Record<string, string> | undefined;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Policy template to pre-fill and constrain the editor.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```js
|
|
149
|
+
* editor.template = {
|
|
150
|
+
* id: 'dome-access',
|
|
151
|
+
* name: 'DOME Marketplace Access',
|
|
152
|
+
* skeleton: { '@context': '...', '@type': 'odrl:Agreement', ... },
|
|
153
|
+
* editableFields: [{ path: 'odrl:permission.odrl:target', ... }],
|
|
154
|
+
* lockedFields: ['odrl:permission.odrl:action'],
|
|
155
|
+
* };
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
template: Record<string, unknown> | undefined;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Custom JSON-LD `@context` for new policies.
|
|
162
|
+
*
|
|
163
|
+
* Overrides the built-in default context. The JS property takes
|
|
164
|
+
* precedence over the `policy-context` HTML attribute.
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```js
|
|
168
|
+
* editor.policyContext = {
|
|
169
|
+
* odrl: 'http://www.w3.org/ns/odrl/2/',
|
|
170
|
+
* 'dome-op': 'https://github.com/DOME-Marketplace/dome-odrl-profile#',
|
|
171
|
+
* };
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
policyContext: Record<string, string> | string | undefined;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// ---------------------------------------------------------------------------
|
|
178
|
+
// HTMLElementTagNameMap augmentation
|
|
179
|
+
// ---------------------------------------------------------------------------
|
|
180
|
+
|
|
181
|
+
declare global {
|
|
182
|
+
interface HTMLElementTagNameMap {
|
|
183
|
+
'odrl-policy-editor': OdrlPolicyEditorElement;
|
|
184
|
+
}
|
|
185
|
+
}
|