@qrvey/widget-configurability 0.0.0-beta.4589 → 0.0.0-beta.4657

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.
Files changed (40) hide show
  1. package/README.md +53 -0
  2. package/dist/cjs/index.js +12 -1
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/metadata/customization-metadata.js +241 -0
  5. package/dist/cjs/metadata/customization-metadata.js.map +1 -0
  6. package/dist/cjs/metadata/index.js +11 -0
  7. package/dist/cjs/metadata/index.js.map +1 -0
  8. package/dist/cjs/metadata/labels/chart-panel.labels.js +56 -0
  9. package/dist/cjs/metadata/labels/chart-panel.labels.js.map +1 -0
  10. package/dist/cjs/metadata/labels/dashboard.labels.js +207 -0
  11. package/dist/cjs/metadata/labels/dashboard.labels.js.map +1 -0
  12. package/dist/cjs/metadata/metadata.models.js +3 -0
  13. package/dist/cjs/metadata/metadata.models.js.map +1 -0
  14. package/dist/cjs/models/remote.models.js +3 -0
  15. package/dist/cjs/models/remote.models.js.map +1 -0
  16. package/dist/cjs/models/validation.models.js +3 -0
  17. package/dist/cjs/models/validation.models.js.map +1 -0
  18. package/dist/cjs/remote/remote-customization.loader.js +213 -0
  19. package/dist/cjs/remote/remote-customization.loader.js.map +1 -0
  20. package/dist/cjs/structural-manager.js +35 -2
  21. package/dist/cjs/structural-manager.js.map +1 -1
  22. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  23. package/dist/cjs/utils/defaults.helpers.js +3 -0
  24. package/dist/cjs/utils/defaults.helpers.js.map +1 -1
  25. package/dist/cjs/utils/layers.helpers.js +178 -0
  26. package/dist/cjs/utils/layers.helpers.js.map +1 -0
  27. package/dist/cjs/utils/logger.helpers.js +10 -0
  28. package/dist/cjs/utils/logger.helpers.js.map +1 -0
  29. package/dist/cjs/utils/scope.helpers.js +4 -1
  30. package/dist/cjs/utils/scope.helpers.js.map +1 -1
  31. package/dist/cjs/validation/customization.validator.js +366 -0
  32. package/dist/cjs/validation/customization.validator.js.map +1 -0
  33. package/dist/esm/index.mjs +846 -28
  34. package/dist/esm/index.mjs.map +1 -1
  35. package/dist/esm/metadata.mjs +2750 -0
  36. package/dist/esm/metadata.mjs.map +1 -0
  37. package/dist/types/customization.models-CCSWjfb2.d.ts +47 -0
  38. package/dist/types/index.d.ts +98 -47
  39. package/dist/types/metadata.d.ts +59 -0
  40. package/package.json +7 -1
@@ -1,48 +1,5 @@
1
- declare enum Widget {
2
- DASHBOARD = "dashboard",
3
- REPORT = "report",
4
- DOWNLOAD_MANAGER = "download-manager",
5
- DOWNLOAD_MODAL = "download-modal",
6
- CHART_PANEL = "chart-panel",
7
- CHART_GALLERY = "chart-gallery",
8
- CHART_BUILDER = "chart-builder"
9
- }
10
- declare const WIDGET_SUBMODULE_NAMES: Partial<Record<Widget, string>>;
11
- declare const WIDGET_STRUCTURE_SCOPE_KIND = "qrvey.widget-structure-scope";
12
- declare const WIDGET_STRUCTURE_SCOPE_FORMAT = 1;
13
- declare enum WidgetVersion {
14
- v1 = "1.0",
15
- latest = "latest"
16
- }
17
-
18
- declare const allowedOperators: readonly ["=", "!=", ">", ">=", "<", "<=", "startsWith", "endsWith", "contains"];
19
- type Operators = (typeof allowedOperators)[number];
20
- type ConditionValue = string | number;
21
- interface Condition {
22
- field: string;
23
- operator: Operators;
24
- value: ConditionValue;
25
- }
26
- type ConditionState = Record<string, ConditionValue>;
27
-
28
- interface Verbs {
29
- remove?: string[];
30
- keep?: string[];
31
- reorder?: string[];
32
- }
33
- interface CustomizationStructure extends Verbs {
34
- defaults?: Record<string, unknown>;
35
- subModules?: WidgetSubModuleCollection;
36
- }
37
- interface Conditional extends CustomizationStructure {
38
- condition: Condition;
39
- }
40
- type View = Record<string, WidgetCustomization>;
41
- type WidgetSubModuleCollection = Record<string, WidgetCustomization>;
42
- interface WidgetCustomization extends CustomizationStructure {
43
- conditional?: Conditional[];
44
- views?: View;
45
- }
1
+ import { W as WidgetCustomization, C as Condition, a as Widget, b as WidgetVersion, c as ConditionState } from './customization.models-CCSWjfb2.js';
2
+ export { d as ConditionValue, O as Operators, e as WIDGET_STRUCTURE_SCOPE_FORMAT, f as WIDGET_STRUCTURE_SCOPE_KIND, g as WIDGET_SUBMODULE_NAMES, h as WidgetSubModuleCollection } from './customization.models-CCSWjfb2.js';
46
3
 
47
4
  type SectionValue = number | boolean | string | undefined | SectionValue[] | Record<string, unknown>;
48
5
  type SectionDefinition = WidgetStructure | (string | WidgetStructure)[] | undefined | boolean;
@@ -68,6 +25,7 @@ interface StructureEngineOptions {
68
25
  }
69
26
  interface BuildStructureOptions extends StructureEngineOptions {
70
27
  validationMap?: ValidationMap;
28
+ layers?: WidgetCustomization[];
71
29
  }
72
30
  interface WidgetItemCondition {
73
31
  effect: 'keep' | 'remove';
@@ -102,16 +60,77 @@ interface WidgetStructureScope {
102
60
  defaults?: Record<string, unknown>;
103
61
  }
104
62
 
63
+ type CustomizationErrorCode = 'INVALID_TYPE' | 'UNKNOWN_PROPERTY' | 'UNKNOWN_VIEW' | 'UNKNOWN_SUBMODULE' | 'UNKNOWN_KEY' | 'INVALID_PATTERN' | 'INVALID_DEFAULT' | 'INVALID_CONDITION' | 'EMPTY_CUSTOMIZATION' | 'UNKNOWN_WIDGET' | 'UNKNOWN_VERSION';
64
+ type CustomizationPath = (string | number)[];
65
+ interface CustomizationValidationError {
66
+ path: CustomizationPath;
67
+ code: CustomizationErrorCode;
68
+ severity: 'error' | 'warning';
69
+ message: string;
70
+ suggestion?: string;
71
+ }
72
+ interface CustomizationValidationResult {
73
+ valid: boolean;
74
+ errors: CustomizationValidationError[];
75
+ }
76
+ interface ValidateCustomizationOptions {
77
+ version?: string;
78
+ allowEmpty?: boolean;
79
+ }
80
+
81
+ interface RemoteCustomizationDefinition {
82
+ widget: string;
83
+ customizationId: string;
84
+ name?: string | null;
85
+ description?: string | null;
86
+ source?: 'system' | 'user';
87
+ structureVersion?: string;
88
+ contexts?: string[];
89
+ customization: WidgetCustomization;
90
+ createdAt?: string;
91
+ updatedAt?: string;
92
+ }
93
+ interface LoadRemoteCustomizationOptions {
94
+ widget: string;
95
+ customizationId?: string | null;
96
+ context?: string;
97
+ domain: string;
98
+ apiDomain?: string;
99
+ apiKey?: string;
100
+ qvToken?: string;
101
+ timeoutMs?: number;
102
+ fetchFn?: typeof fetch;
103
+ cache?: boolean;
104
+ }
105
+ type RemoteCustomizationStatus = 'found' | 'fallback' | 'none' | 'error';
106
+ interface RemoteCustomizationError {
107
+ code: 'NETWORK' | 'TIMEOUT' | 'HTTP' | 'INVALID_RESPONSE' | 'INVALID_INPUT';
108
+ status?: number;
109
+ message: string;
110
+ }
111
+ interface RemoteCustomizationResult {
112
+ status: RemoteCustomizationStatus;
113
+ definition?: RemoteCustomizationDefinition;
114
+ error?: RemoteCustomizationError;
115
+ }
116
+
117
+ type SubmoduleLayers = Record<string, Record<string, WidgetCustomization[]>>;
118
+
105
119
  declare function getWidgetConfig(widget: Widget, version?: WidgetVersion): WidgetConfig;
106
120
  declare function buildStructure(widget: Widget, customization?: WidgetCustomization, version?: WidgetVersion, options?: BuildStructureOptions): WidgetStructureInstance;
107
121
  declare class WidgetStructureInstance {
108
122
  private viewMap;
109
123
  private rootDefaults?;
110
- constructor(viewMap: WidgetViewMap, rootDefaults?: Record<string, unknown> | undefined);
124
+ private submoduleLayers?;
125
+ constructor(viewMap: WidgetViewMap, rootDefaults?: Record<string, unknown> | undefined, submoduleLayers?: SubmoduleLayers | undefined);
111
126
  private getValue;
112
127
  isVisible(key: string, state?: ConditionState): boolean;
113
128
  getChildMap(key: string): WidgetViewMap | undefined;
114
129
  getSubmodule(module: string, view?: string): WidgetCustomization | undefined;
130
+ /**
131
+ * Submodule customizations of the stored layers, to pass as layers when building the embedded widget (structureFromSubmodule).
132
+ */
133
+ getSubmoduleLayers(module: string, view?: string): WidgetCustomization[] | undefined;
115
134
  getDefaults(key: string): Record<string, unknown> | undefined;
116
135
  getRootDefaults(): Record<string, unknown> | undefined;
117
136
  /**
@@ -173,6 +192,38 @@ declare const DOWNLOAD_MODAL_V1_DEFAULTS: {
173
192
  subscribeMyself: boolean;
174
193
  };
175
194
 
195
+ /**
196
+ * Formats a validation path as the API error messages show it, e.g. views.design.remove[2]
197
+ * (admin_api_manager prefixes it with `customization.`).
198
+ */
199
+ declare function formatCustomizationPath(path: CustomizationPath): string;
200
+ /**
201
+ * True when the customization has no effective rule: no verb with items and no defaults anywhere.
202
+ */
203
+ declare function isEmptyCustomization(value: unknown): boolean;
204
+ /**
205
+ * Strict validation of a customization for writes (API and Admin Center): collects every error in one pass, each with its path.
206
+ */
207
+ declare function validateCustomization(widget: Widget | string, customization: unknown, options?: ValidateCustomizationOptions): CustomizationValidationResult;
208
+
209
+ declare const CUSTOMIZATIONS_API_PATH = "/api/admin/v5/customizations/widgets";
210
+ declare const DEFAULT_CUSTOMIZATION_ID = "default";
211
+ /**
212
+ * Forgets every cached request (tests, or a host that needs to re-read definitions without reloading).
213
+ */
214
+ declare function clearRemoteCustomizationCache(): void;
215
+ declare const isValidCustomizationId: (value: unknown) => value is string;
216
+ /**
217
+ * Resolves the stored customization a widget uses as its base layer (resolution table 3.3.1 of QRV-749).
218
+ * found: the requested definition (or the context's); fallback: default, because the requested one does not exist;
219
+ * none: no remote layer; error: the widget shows its configuration error.
220
+ */
221
+ declare function loadRemoteCustomization(options: LoadRemoteCustomizationOptions): Promise<RemoteCustomizationResult>;
222
+ /**
223
+ * The layers a widget passes to buildStructure for a resolved result: the definition's customization, or none.
224
+ */
225
+ declare function remoteCustomizationLayers(result: RemoteCustomizationResult | undefined): WidgetCustomization[];
226
+
176
227
  declare class ViewsDto {
177
228
  list: string[];
178
229
  design: string[];
@@ -236,4 +287,4 @@ declare namespace dashboard_structure_doc {
236
287
  export { dashboard_structure_doc_AssetListDto as AssetListDto, dashboard_structure_doc_BaseDashboardV1StructureDto as BaseDashboardV1StructureDto, dashboard_structure_doc_FilterPanelDto as FilterPanelDto, dashboard_structure_doc_MenuBarDto as MenuBarDto, dashboard_structure_doc_SubModulesDto as SubModulesDto, dashboard_structure_doc_ViewsDto as ViewsDto };
237
288
  }
238
289
 
239
- export { type BuildStructureOptions, type Condition, type ConditionState, type ConditionValue, DOWNLOAD_MODAL_V1_DEFAULTS, DOWNLOAD_MODAL_V1_KEYS, DOWNLOAD_MODAL_VALIDATOR_MAP, DX_VALIDATOR_MAP, dashboard_structure_doc as DashboardDoc, type DownloadModalKey, type Operators, type SanitizeFn, type ScopeOptions, type StructureEngineOptions, type StructureInput, type ValidationFN, type ValidationMap, WIDGET_STRUCTURE_SCOPE_FORMAT, WIDGET_STRUCTURE_SCOPE_KIND, WIDGET_SUBMODULE_NAMES, Widget, type WidgetConditionMap, type WidgetConfig, type WidgetCustomization, type WidgetItemCondition, type WidgetStructure, WidgetStructureInstance, type WidgetStructureRoot, type WidgetStructureScope, type WidgetSubModuleCollection, WidgetVersion, type WidgetViewMap, type WidgetViewMapItem, buildStructure, calculateRootDefaults, calculateViewMap, checkConditions, evaluateCondition, extractCustomization, getWidgetConfig, getWidgetStructure, hostKeepInheritance, isWidgetStructureScope, scopeToCustomization, structureFrom, structureFromSubmodule, validateBoolean, validateDefaults };
290
+ export { type BuildStructureOptions, CUSTOMIZATIONS_API_PATH, Condition, ConditionState, type CustomizationErrorCode, type CustomizationPath, type CustomizationValidationError, type CustomizationValidationResult, DEFAULT_CUSTOMIZATION_ID, DOWNLOAD_MODAL_V1_DEFAULTS, DOWNLOAD_MODAL_V1_KEYS, DOWNLOAD_MODAL_VALIDATOR_MAP, DX_VALIDATOR_MAP, dashboard_structure_doc as DashboardDoc, type DownloadModalKey, type LoadRemoteCustomizationOptions, type RemoteCustomizationDefinition, type RemoteCustomizationError, type RemoteCustomizationResult, type RemoteCustomizationStatus, type SanitizeFn, type ScopeOptions, type StructureEngineOptions, type StructureInput, type ValidateCustomizationOptions, type ValidationFN, type ValidationMap, Widget, type WidgetConditionMap, type WidgetConfig, WidgetCustomization, type WidgetItemCondition, type WidgetStructure, WidgetStructureInstance, type WidgetStructureRoot, type WidgetStructureScope, WidgetVersion, type WidgetViewMap, type WidgetViewMapItem, buildStructure, calculateRootDefaults, calculateViewMap, checkConditions, clearRemoteCustomizationCache, evaluateCondition, extractCustomization, formatCustomizationPath, getWidgetConfig, getWidgetStructure, hostKeepInheritance, isEmptyCustomization, isValidCustomizationId, isWidgetStructureScope, loadRemoteCustomization, remoteCustomizationLayers, scopeToCustomization, structureFrom, structureFromSubmodule, validateBoolean, validateCustomization, validateDefaults };
@@ -0,0 +1,59 @@
1
+ import { a as Widget, b as WidgetVersion, W as WidgetCustomization } from './customization.models-CCSWjfb2.js';
2
+
3
+ interface CustomizationLabel {
4
+ label: string;
5
+ description?: string;
6
+ }
7
+ type CustomizationLabelMap = Record<string, CustomizationLabel>;
8
+ interface CustomizationTarget {
9
+ views: string[];
10
+ subModules?: string[];
11
+ }
12
+ interface CustomizationTreeNode {
13
+ key: string;
14
+ id: string;
15
+ label: string;
16
+ description?: string;
17
+ kind: 'section' | 'item' | 'subModule';
18
+ children?: CustomizationTreeNode[];
19
+ }
20
+ interface CustomizationLock {
21
+ verb: 'keep' | 'remove';
22
+ pattern: string;
23
+ scope: 'root' | 'view' | 'conditional' | 'parent';
24
+ }
25
+ interface CustomizationTreeStateNode extends CustomizationTreeNode {
26
+ visible: boolean | 'mixed';
27
+ lockedBy?: CustomizationLock;
28
+ children?: CustomizationTreeStateNode[];
29
+ }
30
+
31
+ declare const widgetMetadata: Partial<Record<Widget, {
32
+ labels: CustomizationLabelMap;
33
+ }>>;
34
+ /**
35
+ * Keys of the structure in a view (or at the root), in structure order, without the view prefix.
36
+ */
37
+ declare function structureKeysOf(widget: Widget, view?: string, version?: WidgetVersion): string[];
38
+ /**
39
+ * Label of a key: full path first, then the leaf id; a humanized id when neither exists.
40
+ */
41
+ declare function getCustomizationLabel(widget: Widget, key: string): CustomizationLabel;
42
+ /**
43
+ * The labelled tree of a target: a widget view, or the structure of the embedded widget when subModules is set.
44
+ */
45
+ declare function getCustomizationTree(widget: Widget, target: CustomizationTarget, options?: {
46
+ version?: WidgetVersion;
47
+ }): CustomizationTreeNode[];
48
+ /**
49
+ * The tree with the visibility of each node for a customization, computed with the real engine. A node whose
50
+ * visibility differs between the target views is 'mixed'; a hidden node a switch cannot bring back is locked.
51
+ */
52
+ declare function getCustomizationTreeState(widget: Widget, customization: WidgetCustomization | undefined, target: CustomizationTarget): CustomizationTreeStateNode[];
53
+ /**
54
+ * A new customization with the minimal change for one switch, applied to every view of the target. It only edits
55
+ * the remove list of each view (or of the submodule inside it), never keep, conditional, defaults or root verbs.
56
+ */
57
+ declare function toggleCustomizationKey(customization: WidgetCustomization | undefined, target: CustomizationTarget, key: string, visible: boolean): WidgetCustomization;
58
+
59
+ export { type CustomizationLabel, type CustomizationLabelMap, type CustomizationLock, type CustomizationTarget, type CustomizationTreeNode, type CustomizationTreeStateNode, getCustomizationLabel, getCustomizationTree, getCustomizationTreeState, structureKeysOf, toggleCustomizationKey, widgetMetadata };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qrvey/widget-configurability",
3
- "version": "0.0.0-beta.4589",
3
+ "version": "0.0.0-beta.4657",
4
4
  "types": "dist/types/index.d.ts",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.mjs",
@@ -10,6 +10,12 @@
10
10
  "import": "./dist/esm/index.mjs",
11
11
  "require": "./dist/cjs/index.js",
12
12
  "default": "./dist/cjs/index.js"
13
+ },
14
+ "./metadata": {
15
+ "types": "./dist/types/metadata.d.ts",
16
+ "import": "./dist/esm/metadata.mjs",
17
+ "require": "./dist/cjs/metadata/index.js",
18
+ "default": "./dist/cjs/metadata/index.js"
13
19
  }
14
20
  },
15
21
  "files": [