@memberjunction/interactive-component-types 6.3.0-edge.1 → 6.3.0-edge.3
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 +43 -0
- package/dist/component-language.d.ts +109 -0
- package/dist/component-language.d.ts.map +1 -0
- package/dist/component-language.js +153 -0
- package/dist/component-language.js.map +1 -0
- package/dist/component-spec.d.ts +16 -1
- package/dist/component-spec.d.ts.map +1 -1
- package/dist/component-spec.js.map +1 -1
- package/dist/data-requirements.d.ts +81 -0
- package/dist/data-requirements.d.ts.map +1 -1
- package/dist/data-requirements.js +117 -0
- package/dist/data-requirements.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/json-types.d.ts +68 -0
- package/dist/json-types.d.ts.map +1 -0
- package/dist/json-types.js +97 -0
- package/dist/json-types.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/update-host-adapter.d.ts +153 -0
- package/dist/update-host-adapter.d.ts.map +1 -0
- package/dist/update-host-adapter.js +196 -0
- package/dist/update-host-adapter.js.map +1 -0
- package/dist/widget-host.d.ts +286 -0
- package/dist/widget-host.d.ts.map +1 -0
- package/dist/widget-host.js +398 -0
- package/dist/widget-host.js.map +1 -0
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -526,6 +526,49 @@ behavior as a CodeGen-generated Angular form.
|
|
|
526
526
|
|
|
527
527
|
See [/plans/interactive-forms/phase-2-runtime-loop.md](../../plans/interactive-forms/phase-2-runtime-loop.md) for the full architecture, lifecycle, and security model (Create / Modify / Activate / Revert + ownership checks).
|
|
528
528
|
|
|
529
|
+
## Wave S0 Contracts (Widgets, TSX Language, Remote Ops Allowlist & Unified Updates)
|
|
530
|
+
|
|
531
|
+
Wave S0 extends `@memberjunction/interactive-component-types` with four framework-free host and spec contracts, backed by strict recursive JSON types (`JsonPrimitive`, `JsonObject`, `JsonArray`, `JsonValue`) and `RuntimeValue` validator inputs with zero `any` or lazy `unknown` payloads.
|
|
532
|
+
|
|
533
|
+
### 1. Widget Host Contract (`P8` — `widget-host.ts`)
|
|
534
|
+
|
|
535
|
+
Components declaring `componentRole: 'widget'` target `WidgetHostProps<TSettings extends JsonObject = JsonObject>` across `'home' | 'dashboard' | 'tray' | 'desktop-widget' | 'companion'` surfaces:
|
|
536
|
+
|
|
537
|
+
- **Placement & Layout**: `surface` (`WidgetSurface`), `placementId`, open-extensible `sizeClass` (`'sm' | 'md' | 'lg' | 'wide' | 'tall' | (string & Record<never, never>)`), and strongly typed `hostContext` (`WidgetHostContext`).
|
|
538
|
+
- **Settings & Persistence**: `userSettings` (hydrated by the host via `UserInfoEngine` / `MJ: User Settings`, never browser `localStorage`), optional JSON Schema `settingsSchema` (`WidgetSettingsSchema`), and `onSaveUserSettings(settings)`. Host implementations should debounce writes (`DEFAULT_WIDGET_SETTINGS_SAVE_DEBOUNCE_MS = 300`) and enforce payload ceilings (`MAX_WIDGET_SETTINGS_PAYLOAD_BYTES = 65536`).
|
|
539
|
+
- **Upward Intents (Callbacks & Events)**: `onOpenRecord` / `WidgetEventNames.RecordOpenRequested`, `onInvokeAction` / `WidgetEventNames.ActionRequested`, `onNotify` / `WidgetEventNames.NotificationRequested`, and `onSaveUserSettings` / `WidgetEventNames.UserSettingsSaveRequested`.
|
|
540
|
+
- **Runtime Validators**: `IsWidgetRole`, `IsWidgetSurface`, `IsWidgetSizeClass`, `IsWidgetHostContext`, `IsWidgetSettingsSchema`, `IsWidgetHostProps`, `ValidateWidgetHostProps`, `ValidateWidgetSettingsAgainstSchema`.
|
|
541
|
+
|
|
542
|
+
### 2. TSX Language & `erasableSyntaxOnly` Metadata (`P6` — `component-language.ts`, `component-spec.ts`)
|
|
543
|
+
|
|
544
|
+
`ComponentSpec` supports optional `language?: 'jsx' | 'tsx'`, `erasableSyntaxOnly?: boolean`, and `tsxMetadata?: ComponentTsxMetadata`:
|
|
545
|
+
|
|
546
|
+
- **G9 Backward Compatibility**: Omitting `language` resolves to `'jsx'` via `ResolveComponentLanguage(spec)` so all legacy JSX `ComponentSpec` records remain valid without edits.
|
|
547
|
+
- **TSX Defaults**: Declaring `language: 'tsx'` defaults `erasableSyntaxOnly` to `true` via `ResolveErasableSyntaxOnly(spec)` and `ResolveComponentLanguageInfo(spec)`, disallowing runtime-emitting TypeScript constructs (`enum`, value `namespace`, parameter properties, decorators) so lightweight type-stripping runtimes can compile TSX safely.
|
|
548
|
+
- **Validation**: `IsComponentLanguage`, `IsComponentTsxMetadata`, and `ValidateComponentLanguageSpec` reject unsupported language strings and conflicting flags.
|
|
549
|
+
|
|
550
|
+
### 3. Remote Operations Allowlist (`P11` — `data-requirements.ts`)
|
|
551
|
+
|
|
552
|
+
`ComponentDataRequirements` supports an optional `operations?: ComponentOperationDataRequirement[]` allowlist specifying which `BaseRemotableOperation` keys (`utilities.ops`) a sandboxed component may invoke:
|
|
553
|
+
|
|
554
|
+
- **Default-Deny Security**: Omitting `operations` resolves via `ResolveAllowedOperations(requirements)` strictly to `[]` (zero permitted operations).
|
|
555
|
+
- **Exact Keys Only**: `IsValidOperationKey` and `ValidateOperationAllowlist` reject empty keys, whitespace, duplicates, and wildcard patterns (`*`, `?`). Use `IsOperationAllowed(requirements, operationKey)` at the sandbox bridge boundary.
|
|
556
|
+
|
|
557
|
+
### 4. Unified Update Host Adapter (`P18` — `update-host-adapter.ts`)
|
|
558
|
+
|
|
559
|
+
Provides one framework-free contract for Web (`SwUpdate`), Mobile (`expo-updates` / App Store / Play Store), and Desktop (`electron-updater`) shells:
|
|
560
|
+
|
|
561
|
+
- **State Machine**: `UpdateStatus` (`'idle' | 'checking' | 'downloading' | 'ready-to-apply' | 'store-upgrade-required'`), `UpdateStateSnapshot` (`currentVersion`, `targetVersion`, `minSupportedClientVersion`, `releaseNotesUrl`, `downloadProgress`, optional `platform`, `lastCheckedAt`, and structured `error?: UpdateErrorDescriptor`), `UpdateUnsubscribe`, and `UpdateHostAdapter` (`checkForUpdates()`, `applyUpdate()`, `subscribe()`).
|
|
562
|
+
- **Transition Validation**: `UPDATE_STATE_TRANSITIONS`, `IsValidUpdateTransition`, and `ValidateUpdateTransition` enforce monotonic `downloadProgress` (`0..100`), require `100%` on `'ready-to-apply'`, forbid OTA transitions out of `'store-upgrade-required'`, and revert transient check/download/signature failures cleanly to `'idle'` with `snapshot.error`.
|
|
563
|
+
|
|
564
|
+
### Migration Guidance
|
|
565
|
+
|
|
566
|
+
- **Legacy JSX ComponentSpecs**: No changes required. Keep omitting `language`, `erasableSyntaxOnly`, and `operations`; hosts resolve `language` to `'jsx'` and `operations` to `[]` automatically.
|
|
567
|
+
- **New TSX Widgets**: Set `componentRole: 'widget'`, `language: 'tsx'`, `erasableSyntaxOnly: true`, declare every required `BaseRemotableOperation` under `dataRequirements.operations`, and persist settings exclusively through `onSaveUserSettings` (`UserInfoEngine`).
|
|
568
|
+
- **Platform Update Shells**: Implement `UpdateHostAdapter` with singleflight `checkForUpdates()` coalescing and throttled `downloadProgress` subscriber notifications (`DEFAULT_PROGRESS_EMIT_THROTTLE_MS = 250`).
|
|
569
|
+
|
|
570
|
+
For the full Wave S0 specification, see [.mj/specs/one-contract-s0-types/README.md](../../.mj/specs/one-contract-s0-types/README.md).
|
|
571
|
+
|
|
529
572
|
## Dependencies
|
|
530
573
|
|
|
531
574
|
- `@memberjunction/core`: Core MemberJunction types and interfaces
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Source language and `erasableSyntaxOnly` metadata contracts for
|
|
3
|
+
* {@link ComponentSpec} (Wave S0, P6).
|
|
4
|
+
*
|
|
5
|
+
* Legacy component specs omit `language` and continue resolving to `'jsx'`
|
|
6
|
+
* without modification (G9 backward compatibility).
|
|
7
|
+
*/
|
|
8
|
+
import { RuntimeValue } from './json-types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Supported source languages for interactive component `code`.
|
|
11
|
+
*/
|
|
12
|
+
export declare const COMPONENT_LANGUAGES: readonly ["jsx", "tsx"];
|
|
13
|
+
/**
|
|
14
|
+
* Source code language identifier for {@link ComponentSpec.language}.
|
|
15
|
+
*/
|
|
16
|
+
export type ComponentLanguage = (typeof COMPONENT_LANGUAGES)[number];
|
|
17
|
+
/**
|
|
18
|
+
* Default component source language when `ComponentSpec.language` is omitted.
|
|
19
|
+
*/
|
|
20
|
+
export declare const DEFAULT_COMPONENT_LANGUAGE: ComponentLanguage;
|
|
21
|
+
/**
|
|
22
|
+
* Runtime-emitting TypeScript syntax constructs disallowed when
|
|
23
|
+
* `erasableSyntaxOnly` is enabled.
|
|
24
|
+
*/
|
|
25
|
+
export declare const TSX_DISALLOWED_SYNTAX_KINDS: readonly ["enum", "namespace", "parameter-property", "decorator"];
|
|
26
|
+
/**
|
|
27
|
+
* Single disallowed TypeScript construct identifier for `erasableSyntaxOnly`.
|
|
28
|
+
*/
|
|
29
|
+
export type ComponentTsxDisallowedSyntax = (typeof TSX_DISALLOWED_SYNTAX_KINDS)[number];
|
|
30
|
+
/**
|
|
31
|
+
* Supported JSX transform targets for TSX compilation.
|
|
32
|
+
*/
|
|
33
|
+
export type ComponentJsxTransform = 'react' | 'react-jsx';
|
|
34
|
+
/**
|
|
35
|
+
* Detailed compilation & syntax-constraint metadata for TSX components (P6).
|
|
36
|
+
*/
|
|
37
|
+
export interface ComponentTsxMetadata {
|
|
38
|
+
/**
|
|
39
|
+
* Requires `code` to use only erasable TypeScript syntax (disallows `enum`,
|
|
40
|
+
* value `namespace`, and constructor parameter properties), enabling fast
|
|
41
|
+
* type-stripping without full TypeScript semantic emit.
|
|
42
|
+
*/
|
|
43
|
+
erasableSyntaxOnly: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Optional JSX transform mode expected by the component code.
|
|
46
|
+
*/
|
|
47
|
+
jsxTransform?: ComponentJsxTransform;
|
|
48
|
+
/**
|
|
49
|
+
* Optional minimum TypeScript language version targeted by the component.
|
|
50
|
+
*/
|
|
51
|
+
targetTypeScriptVersion?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Explicit list of runtime-emitting TypeScript constructs disallowed in `code`.
|
|
54
|
+
*/
|
|
55
|
+
disallowedSyntax?: readonly ComponentTsxDisallowedSyntax[];
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Normalized language resolution output for a {@link ComponentSpec}.
|
|
59
|
+
*/
|
|
60
|
+
export interface ResolvedComponentLanguageInfo {
|
|
61
|
+
language: ComponentLanguage;
|
|
62
|
+
isTsx: boolean;
|
|
63
|
+
erasableSyntaxOnly: boolean;
|
|
64
|
+
jsxTransform: ComponentJsxTransform;
|
|
65
|
+
disallowedSyntax: readonly ComponentTsxDisallowedSyntax[];
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Minimal structural projection of `ComponentSpec` language fields used by
|
|
69
|
+
* pure resolvers and runtime validators.
|
|
70
|
+
*/
|
|
71
|
+
export interface ComponentLanguageSpecProjection {
|
|
72
|
+
language?: ComponentLanguage;
|
|
73
|
+
erasableSyntaxOnly?: boolean;
|
|
74
|
+
tsxMetadata?: ComponentTsxMetadata;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Runtime type guard for {@link ComponentLanguage}.
|
|
78
|
+
*/
|
|
79
|
+
export declare function IsComponentLanguage(value: RuntimeValue): value is ComponentLanguage;
|
|
80
|
+
/**
|
|
81
|
+
* Runtime type guard for {@link ComponentTsxMetadata}.
|
|
82
|
+
*/
|
|
83
|
+
export declare function IsComponentTsxMetadata(value: RuntimeValue): value is ComponentTsxMetadata;
|
|
84
|
+
/**
|
|
85
|
+
* Resolves the effective source language of a component spec.
|
|
86
|
+
* Omitted or nullish `language` defaults safely to `'jsx'` (G9).
|
|
87
|
+
*/
|
|
88
|
+
export declare function ResolveComponentLanguage(spec: Pick<ComponentLanguageSpecProjection, 'language'> | null | undefined): ComponentLanguage;
|
|
89
|
+
/**
|
|
90
|
+
* Resolves whether `erasableSyntaxOnly` enforcement applies to a component spec.
|
|
91
|
+
* TSX components default to `true` unless explicitly set to `false`; JSX components
|
|
92
|
+
* default to `false` unless explicitly configured.
|
|
93
|
+
*/
|
|
94
|
+
export declare function ResolveErasableSyntaxOnly(spec: ComponentLanguageSpecProjection | null | undefined): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Resolves full normalized language & TSX compilation metadata for a spec.
|
|
97
|
+
*/
|
|
98
|
+
export declare function ResolveComponentLanguageInfo(spec: ComponentLanguageSpecProjection | null | undefined): ResolvedComponentLanguageInfo;
|
|
99
|
+
/**
|
|
100
|
+
* Validates language and `erasableSyntaxOnly` metadata fields on a runtime spec payload.
|
|
101
|
+
* Returns structured errors when unsupported language strings or malformed `tsxMetadata`
|
|
102
|
+
* are supplied. Omitted fields are valid and default to legacy `'jsx'` behavior.
|
|
103
|
+
*/
|
|
104
|
+
export declare function ValidateComponentLanguageSpec(value: RuntimeValue): {
|
|
105
|
+
valid: boolean;
|
|
106
|
+
errors: string[];
|
|
107
|
+
resolved?: ResolvedComponentLanguageInfo;
|
|
108
|
+
};
|
|
109
|
+
//# sourceMappingURL=component-language.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-language.d.ts","sourceRoot":"","sources":["../src/component-language.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAiB,YAAY,EAAE,MAAM,cAAc,CAAC;AAE3D;;GAEG;AACH,eAAO,MAAM,mBAAmB,yBAA0B,CAAC;AAE3D;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;AAErE;;GAEG;AACH,eAAO,MAAM,0BAA0B,EAAE,iBAAyB,CAAC;AAEnE;;;GAGG;AACH,eAAO,MAAM,2BAA2B,mEAK9B,CAAC;AAEX;;GAEG;AACH,MAAM,MAAM,4BAA4B,GAAG,CAAC,OAAO,2BAA2B,CAAC,CAAC,MAAM,CAAC,CAAC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GACzD,6BAA6B,CAc/B;AAED;;;;GAIG;AACH,wBAAgB,6BAA6B,CACzC,KAAK,EAAE,YAAY,GACpB;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAC;IAAC,QAAQ,CAAC,EAAE,6BAA6B,CAAA;CAAE,CAyChF"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Source language and `erasableSyntaxOnly` metadata contracts for
|
|
3
|
+
* {@link ComponentSpec} (Wave S0, P6).
|
|
4
|
+
*
|
|
5
|
+
* Legacy component specs omit `language` and continue resolving to `'jsx'`
|
|
6
|
+
* without modification (G9 backward compatibility).
|
|
7
|
+
*/
|
|
8
|
+
import { IsPlainObject } from './json-types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Supported source languages for interactive component `code`.
|
|
11
|
+
*/
|
|
12
|
+
export const COMPONENT_LANGUAGES = ['jsx', 'tsx'];
|
|
13
|
+
/**
|
|
14
|
+
* Default component source language when `ComponentSpec.language` is omitted.
|
|
15
|
+
*/
|
|
16
|
+
export const DEFAULT_COMPONENT_LANGUAGE = 'jsx';
|
|
17
|
+
/**
|
|
18
|
+
* Runtime-emitting TypeScript syntax constructs disallowed when
|
|
19
|
+
* `erasableSyntaxOnly` is enabled.
|
|
20
|
+
*/
|
|
21
|
+
export const TSX_DISALLOWED_SYNTAX_KINDS = [
|
|
22
|
+
'enum',
|
|
23
|
+
'namespace',
|
|
24
|
+
'parameter-property',
|
|
25
|
+
'decorator',
|
|
26
|
+
];
|
|
27
|
+
/**
|
|
28
|
+
* Runtime type guard for {@link ComponentLanguage}.
|
|
29
|
+
*/
|
|
30
|
+
export function IsComponentLanguage(value) {
|
|
31
|
+
return value === 'jsx' || value === 'tsx';
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Runtime type guard for {@link ComponentTsxMetadata}.
|
|
35
|
+
*/
|
|
36
|
+
export function IsComponentTsxMetadata(value) {
|
|
37
|
+
if (!IsPlainObject(value)) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
const erasable = Reflect.get(value, 'erasableSyntaxOnly');
|
|
41
|
+
if (typeof erasable !== 'boolean') {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
const jsxTransform = Reflect.get(value, 'jsxTransform');
|
|
45
|
+
if (jsxTransform !== undefined && jsxTransform !== 'react' && jsxTransform !== 'react-jsx') {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
const targetVersion = Reflect.get(value, 'targetTypeScriptVersion');
|
|
49
|
+
if (targetVersion !== undefined && (typeof targetVersion !== 'string' || targetVersion.trim().length === 0)) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
const disallowedSyntax = Reflect.get(value, 'disallowedSyntax');
|
|
53
|
+
if (disallowedSyntax !== undefined && !isValidDisallowedSyntaxList(disallowedSyntax)) {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
function isValidDisallowedSyntaxList(value) {
|
|
59
|
+
if (!Array.isArray(value)) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
for (const item of value) {
|
|
63
|
+
if (typeof item !== 'string' || !TSX_DISALLOWED_SYNTAX_KINDS.includes(item)) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Resolves the effective source language of a component spec.
|
|
71
|
+
* Omitted or nullish `language` defaults safely to `'jsx'` (G9).
|
|
72
|
+
*/
|
|
73
|
+
export function ResolveComponentLanguage(spec) {
|
|
74
|
+
if (!spec || spec.language === undefined || spec.language === null) {
|
|
75
|
+
return DEFAULT_COMPONENT_LANGUAGE;
|
|
76
|
+
}
|
|
77
|
+
return spec.language === 'tsx' ? 'tsx' : DEFAULT_COMPONENT_LANGUAGE;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Resolves whether `erasableSyntaxOnly` enforcement applies to a component spec.
|
|
81
|
+
* TSX components default to `true` unless explicitly set to `false`; JSX components
|
|
82
|
+
* default to `false` unless explicitly configured.
|
|
83
|
+
*/
|
|
84
|
+
export function ResolveErasableSyntaxOnly(spec) {
|
|
85
|
+
if (!spec) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
if (spec.tsxMetadata !== undefined) {
|
|
89
|
+
return spec.tsxMetadata.erasableSyntaxOnly;
|
|
90
|
+
}
|
|
91
|
+
if (spec.erasableSyntaxOnly !== undefined) {
|
|
92
|
+
return spec.erasableSyntaxOnly;
|
|
93
|
+
}
|
|
94
|
+
return ResolveComponentLanguage(spec) === 'tsx';
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Resolves full normalized language & TSX compilation metadata for a spec.
|
|
98
|
+
*/
|
|
99
|
+
export function ResolveComponentLanguageInfo(spec) {
|
|
100
|
+
const language = ResolveComponentLanguage(spec);
|
|
101
|
+
const erasableSyntaxOnly = ResolveErasableSyntaxOnly(spec);
|
|
102
|
+
const jsxTransform = spec?.tsxMetadata?.jsxTransform ?? 'react';
|
|
103
|
+
const disallowedSyntax = spec?.tsxMetadata?.disallowedSyntax ?? (erasableSyntaxOnly ? TSX_DISALLOWED_SYNTAX_KINDS : []);
|
|
104
|
+
return {
|
|
105
|
+
language,
|
|
106
|
+
isTsx: language === 'tsx',
|
|
107
|
+
erasableSyntaxOnly,
|
|
108
|
+
jsxTransform,
|
|
109
|
+
disallowedSyntax,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Validates language and `erasableSyntaxOnly` metadata fields on a runtime spec payload.
|
|
114
|
+
* Returns structured errors when unsupported language strings or malformed `tsxMetadata`
|
|
115
|
+
* are supplied. Omitted fields are valid and default to legacy `'jsx'` behavior.
|
|
116
|
+
*/
|
|
117
|
+
export function ValidateComponentLanguageSpec(value) {
|
|
118
|
+
if (!IsPlainObject(value)) {
|
|
119
|
+
return { valid: false, errors: ['Component spec must be a non-null object.'] };
|
|
120
|
+
}
|
|
121
|
+
const errors = [];
|
|
122
|
+
const languageVal = Reflect.get(value, 'language');
|
|
123
|
+
const erasableVal = Reflect.get(value, 'erasableSyntaxOnly');
|
|
124
|
+
const tsxMetaVal = Reflect.get(value, 'tsxMetadata');
|
|
125
|
+
if (languageVal !== undefined && !IsComponentLanguage(languageVal)) {
|
|
126
|
+
errors.push(`Unsupported component language "${String(languageVal)}". Expected "jsx" or "tsx".`);
|
|
127
|
+
}
|
|
128
|
+
if (erasableVal !== undefined && typeof erasableVal !== 'boolean') {
|
|
129
|
+
errors.push('erasableSyntaxOnly must be a boolean when provided.');
|
|
130
|
+
}
|
|
131
|
+
if (tsxMetaVal !== undefined && !IsComponentTsxMetadata(tsxMetaVal)) {
|
|
132
|
+
errors.push('tsxMetadata is malformed; expected { erasableSyntaxOnly: boolean, ... }.');
|
|
133
|
+
}
|
|
134
|
+
if (typeof erasableVal === 'boolean' &&
|
|
135
|
+
IsComponentTsxMetadata(tsxMetaVal) &&
|
|
136
|
+
erasableVal !== tsxMetaVal.erasableSyntaxOnly) {
|
|
137
|
+
errors.push('Conflicting erasableSyntaxOnly values between spec.erasableSyntaxOnly and spec.tsxMetadata.erasableSyntaxOnly.');
|
|
138
|
+
}
|
|
139
|
+
if (errors.length > 0) {
|
|
140
|
+
return { valid: false, errors };
|
|
141
|
+
}
|
|
142
|
+
const projection = {
|
|
143
|
+
language: IsComponentLanguage(languageVal) ? languageVal : undefined,
|
|
144
|
+
erasableSyntaxOnly: typeof erasableVal === 'boolean' ? erasableVal : undefined,
|
|
145
|
+
tsxMetadata: IsComponentTsxMetadata(tsxMetaVal) ? tsxMetaVal : undefined,
|
|
146
|
+
};
|
|
147
|
+
return {
|
|
148
|
+
valid: true,
|
|
149
|
+
errors: [],
|
|
150
|
+
resolved: ResolveComponentLanguageInfo(projection),
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=component-language.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-language.js","sourceRoot":"","sources":["../src/component-language.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,aAAa,EAAgB,MAAM,cAAc,CAAC;AAE3D;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,KAAK,EAAE,KAAK,CAAU,CAAC;AAO3D;;GAEG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAsB,KAAK,CAAC;AAEnE;;;GAGG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG;IACvC,MAAM;IACN,WAAW;IACX,oBAAoB;IACpB,WAAW;CACL,CAAC;AA4DX;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAmB;IACnD,OAAO,KAAK,KAAK,KAAK,IAAI,KAAK,KAAK,KAAK,CAAC;AAC9C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,KAAmB;IACtD,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;QACxB,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,oBAAoB,CAAC,CAAC;IAC1D,IAAI,OAAO,QAAQ,KAAK,SAAS,EAAE,CAAC;QAChC,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;IACxD,IAAI,YAAY,KAAK,SAAS,IAAI,YAAY,KAAK,OAAO,IAAI,YAAY,KAAK,WAAW,EAAE,CAAC;QACzF,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,yBAAyB,CAAC,CAAC;IACpE,IAAI,aAAa,KAAK,SAAS,IAAI,CAAC,OAAO,aAAa,K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ponentDataRequirements } from "./data-requirements.js";
|
|
|
3
3
|
import { ComponentLibraryDependency } from "./library-dependency.js";
|
|
4
4
|
import { ComponentTypeDefinition } from "./component-constraints.js";
|
|
5
5
|
import type { FormContributionSpec } from "./forms/form-contribution-spec.js";
|
|
6
|
+
import type { ComponentLanguage, ComponentTsxMetadata } from "./component-language.js";
|
|
6
7
|
/**
|
|
7
8
|
* Contract a component commits to implementing. Hosts use this to decide how
|
|
8
9
|
* to mount the component and what props/events to wire up. Authoring agents
|
|
@@ -227,9 +228,23 @@ export declare class ComponentSpec {
|
|
|
227
228
|
*/
|
|
228
229
|
formContribution?: FormContributionSpec;
|
|
229
230
|
/**
|
|
230
|
-
* JavaScript code
|
|
231
|
+
* JavaScript or TypeScript JSX source code for the component.
|
|
231
232
|
*/
|
|
232
233
|
code: string;
|
|
234
|
+
/**
|
|
235
|
+
* Source language of `code` (`'jsx'` or `'tsx'`).
|
|
236
|
+
* Defaults to `'jsx'` when omitted so all legacy ComponentSpec payloads remain compatible (G9).
|
|
237
|
+
*/
|
|
238
|
+
language?: ComponentLanguage;
|
|
239
|
+
/**
|
|
240
|
+
* Whether `code` uses only TypeScript syntax that can be erased without semantic emit
|
|
241
|
+
* (no runtime `enum`, value `namespace`, or constructor parameter properties) (P6).
|
|
242
|
+
*/
|
|
243
|
+
erasableSyntaxOnly?: boolean;
|
|
244
|
+
/**
|
|
245
|
+
* Optional detailed compilation & syntax-constraint metadata for TSX components (P6).
|
|
246
|
+
*/
|
|
247
|
+
tsxMetadata?: ComponentTsxMetadata;
|
|
233
248
|
/**
|
|
234
249
|
* A functional description of what the component should do in markdown.
|
|
235
250
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-spec.d.ts","sourceRoot":"","sources":["../src/component-spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAA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CAAC;CACtB;AAED;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B;;OAEG;IACH,4BAA4B,CAAC,EAAE,MAAM,EAAE,CAAC;IACxC;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;IAEjC;;OAEG;IACH,KAAK,CAAC,EAAE,GAAG,CAAC;CACf,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-spec.js","sourceRoot":"","sources":["../src/component-spec.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"component-spec.js","sourceRoot":"","sources":["../src/component-spec.ts"],"names":[],"mappings":"AA4JA;;GAEG;AACH,MAAM,OAAO,aAAa;CA6OzB;AAAA,CAAC"}
|
|
@@ -1,4 +1,80 @@
|
|
|
1
1
|
import { EntityInfo, EntityFieldInfo } from '@memberjunction/core';
|
|
2
|
+
import { JsonObject, RuntimeValue } from './json-types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Execution mode mirrored from `@memberjunction/core` `RemoteOpExecMode` for
|
|
5
|
+
* declaring expected remote operation behavior in component metadata.
|
|
6
|
+
*/
|
|
7
|
+
export type ComponentOperationExecutionMode = 'Sync' | 'LongRunning';
|
|
8
|
+
/**
|
|
9
|
+
* Declares a single `BaseRemotableOperation` that a sandboxed interactive component
|
|
10
|
+
* is explicitly permitted to invoke via `utilities.ops` (P11).
|
|
11
|
+
*
|
|
12
|
+
* Security model: default-deny. Omitting `ComponentDataRequirements.operations`
|
|
13
|
+
* resolves to an empty allowlist `[]` (zero permitted operations). Empty keys and
|
|
14
|
+
* wildcard patterns (`*`) are invalid and rejected by runtime validators.
|
|
15
|
+
*/
|
|
16
|
+
export interface ComponentOperationDataRequirement {
|
|
17
|
+
/**
|
|
18
|
+
* Exact canonical `BaseRemotableOperation` key registered in MJ metadata / ClassFactory
|
|
19
|
+
* (e.g., `'Template.Run'`, `'RecordProcess.GetRunStatus'`).
|
|
20
|
+
* Must be non-empty and must not contain wildcards (`*`, `?`) or whitespace.
|
|
21
|
+
*/
|
|
22
|
+
operationKey: string;
|
|
23
|
+
/**
|
|
24
|
+
* Human-readable explanation of why the component invokes this operation.
|
|
25
|
+
*/
|
|
26
|
+
description?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Expected execution mode (`'Sync'` or `'LongRunning'`).
|
|
29
|
+
*/
|
|
30
|
+
executionMode?: ComponentOperationExecutionMode;
|
|
31
|
+
/**
|
|
32
|
+
* Optional API/capability scope required for invoking this operation.
|
|
33
|
+
*/
|
|
34
|
+
requiredScope?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Optional JSON Schema or structured input parameter descriptor for documentation and linting.
|
|
37
|
+
*/
|
|
38
|
+
inputSchema?: JsonObject;
|
|
39
|
+
/**
|
|
40
|
+
* Advisory per-session invocation rate ceiling per minute for host governance.
|
|
41
|
+
*/
|
|
42
|
+
maxCallsPerMinute?: number;
|
|
43
|
+
/**
|
|
44
|
+
* When true, the component can gracefully degrade if the host or user lacks access.
|
|
45
|
+
*/
|
|
46
|
+
optional?: boolean;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Runtime type guard validating a single `BaseRemotableOperation` key in an allowlist.
|
|
50
|
+
* Rejects empty strings, whitespace, wildcards (`*`, `?`), and control characters.
|
|
51
|
+
*/
|
|
52
|
+
export declare function IsValidOperationKey(value: RuntimeValue): value is string;
|
|
53
|
+
/**
|
|
54
|
+
* Runtime type guard for {@link ComponentOperationDataRequirement}.
|
|
55
|
+
*/
|
|
56
|
+
export declare function IsComponentOperationDataRequirement(value: RuntimeValue): value is ComponentOperationDataRequirement;
|
|
57
|
+
/**
|
|
58
|
+
* Validates an entire `operations` allowlist array, rejecting malformed entries,
|
|
59
|
+
* empty or wildcard operation keys, and duplicate `operationKey` declarations.
|
|
60
|
+
*/
|
|
61
|
+
export declare function ValidateOperationAllowlist(operations: RuntimeValue): {
|
|
62
|
+
valid: boolean;
|
|
63
|
+
errors: string[];
|
|
64
|
+
allowlist: ComponentOperationDataRequirement[];
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Resolves the effective allowlist of permitted `BaseRemotableOperation` requirements.
|
|
68
|
+
* Enforces strict default-deny: omitted or null `operations` resolves to `[]` (zero
|
|
69
|
+
* permitted operations), and invalid/wildcard entries are never included.
|
|
70
|
+
*/
|
|
71
|
+
export declare function ResolveAllowedOperations(requirements: Pick<ComponentDataRequirements, 'operations'> | null | undefined): readonly ComponentOperationDataRequirement[];
|
|
72
|
+
/**
|
|
73
|
+
* Checks whether a specific `operationKey` is explicitly permitted by `requirements.operations`.
|
|
74
|
+
* Always returns `false` when `operations` is omitted (default-deny) or when `operationKey` is
|
|
75
|
+
* empty or contains wildcards.
|
|
76
|
+
*/
|
|
77
|
+
export declare function IsOperationAllowed(requirements: Pick<ComponentDataRequirements, 'operations'> | null | undefined, operationKey: string): boolean;
|
|
2
78
|
export interface ComponentDataRequirements {
|
|
3
79
|
/**
|
|
4
80
|
* How the component gets its data
|
|
@@ -15,6 +91,11 @@ export interface ComponentDataRequirements {
|
|
|
15
91
|
* Stored Queries that the component will use to fetch data.
|
|
16
92
|
*/
|
|
17
93
|
queries: ComponentQueryDataRequirement[];
|
|
94
|
+
/**
|
|
95
|
+
* Optional allowlist of `BaseRemotableOperation` keys this component is permitted
|
|
96
|
+
* to invoke via `utilities.ops` (P11). Defaults to `[]` (default-deny) when omitted.
|
|
97
|
+
*/
|
|
98
|
+
operations?: ComponentOperationDataRequirement[];
|
|
18
99
|
/**
|
|
19
100
|
* Description of data access patterns
|
|
20
101
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-requirements.d.ts","sourceRoot":"","sources":["../src/data-requirements.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"data-requirements.d.ts","sourceRoot":"","sources":["../src/data-requirements.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAiD,UAAU,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEvG;;;GAGG;AACH,MAAM,MAAM,+BAA+B,GAAG,MAAM,GAAG,aAAa,CAAC;AAErE;;;;;;;GAOG;AACH,MAAM,WAAW,iCAAiC;IAC9C;;;;OAIG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,aAAa,CAAC,EAAE,+BAA+B,CAAC;IAEhD;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;OAEG;IACH,WAAW,CAAC,EAAE,UAAU,CAAC;IAEzB;;OAEG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAE3B;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;CACtB;AAID;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,YAAY,GAAG,KAAK,IAAI,MAAM,CAWxE;AAED;;GAEG;AACH,wBAAgB,mCAAmC,CAAC,KAAK,EAAE,YAAY,GAAG,KAAK,IAAI,iCAAiC,CAoCnH;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CACtC,UAAU,EAAE,YAAY,GACzB;IAAE,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
|
+
const VALID_OPERATION_KEY_REGEX = /^[A-Za-z0-9][A-Za-z0-9._:/-]*$/;
|
|
3
|
+
/**
|
|
4
|
+
* Runtime type guard validating a single `BaseRemotableOperation` key in an allowlist.
|
|
5
|
+
* Rejects empty strings, whitespace, wildcards (`*`, `?`), and control characters.
|
|
6
|
+
*/
|
|
7
|
+
export function IsValidOperationKey(value) {
|
|
8
|
+
if (!IsNonEmptyString(value)) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
if (value !== value.trim()) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
if (value.includes('*') || value.includes('?')) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
return VALID_OPERATION_KEY_REGEX.test(value);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Runtime type guard for {@link ComponentOperationDataRequirement}.
|
|
21
|
+
*/
|
|
22
|
+
export function IsComponentOperationDataRequirement(value) {
|
|
23
|
+
if (!IsPlainObject(value)) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
const operationKey = Reflect.get(value, 'operationKey');
|
|
27
|
+
if (!IsValidOperationKey(operationKey)) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
const description = Reflect.get(value, 'description');
|
|
31
|
+
if (description !== undefined && typeof description !== 'string') {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
const executionMode = Reflect.get(value, 'executionMode');
|
|
35
|
+
if (executionMode !== undefined && executionMode !== 'Sync' && executionMode !== 'LongRunning') {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
const requiredScope = Reflect.get(value, 'requiredScope');
|
|
39
|
+
if (requiredScope !== undefined && !IsNonEmptyString(requiredScope)) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
const inputSchema = Reflect.get(value, 'inputSchema');
|
|
43
|
+
if (inputSchema !== undefined && !IsJsonObject(inputSchema)) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
const maxCallsPerMinute = Reflect.get(value, 'maxCallsPerMinute');
|
|
47
|
+
if (maxCallsPerMinute !== undefined &&
|
|
48
|
+
(typeof maxCallsPerMinute !== 'number' || !Number.isFinite(maxCallsPerMinute) || maxCallsPerMinute <= 0)) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
const optional = Reflect.get(value, 'optional');
|
|
52
|
+
if (optional !== undefined && typeof optional !== 'boolean') {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Validates an entire `operations` allowlist array, rejecting malformed entries,
|
|
59
|
+
* empty or wildcard operation keys, and duplicate `operationKey` declarations.
|
|
60
|
+
*/
|
|
61
|
+
export function ValidateOperationAllowlist(operations) {
|
|
62
|
+
if (operations === undefined || operations === null) {
|
|
63
|
+
return { valid: true, errors: [], allowlist: [] };
|
|
64
|
+
}
|
|
65
|
+
if (!Array.isArray(operations)) {
|
|
66
|
+
return {
|
|
67
|
+
valid: false,
|
|
68
|
+
errors: ['ComponentDataRequirements.operations must be an array when provided.'],
|
|
69
|
+
allowlist: [],
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const errors = [];
|
|
73
|
+
const allowlist = [];
|
|
74
|
+
const seenKeys = new Set();
|
|
75
|
+
for (let i = 0; i < operations.length; i++) {
|
|
76
|
+
const entry = operations[i];
|
|
77
|
+
if (!IsComponentOperationDataRequirement(entry)) {
|
|
78
|
+
errors.push(`operations[${i}] is invalid: operationKey must be a non-empty exact key without wildcards.`);
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (seenKeys.has(entry.operationKey)) {
|
|
82
|
+
errors.push(`operations[${i}] duplicates operationKey "${entry.operationKey}".`);
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
seenKeys.add(entry.operationKey);
|
|
86
|
+
allowlist.push(entry);
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
valid: errors.length === 0,
|
|
90
|
+
errors,
|
|
91
|
+
allowlist,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Resolves the effective allowlist of permitted `BaseRemotableOperation` requirements.
|
|
96
|
+
* Enforces strict default-deny: omitted or null `operations` resolves to `[]` (zero
|
|
97
|
+
* permitted operations), and invalid/wildcard entries are never included.
|
|
98
|
+
*/
|
|
99
|
+
export function ResolveAllowedOperations(requirements) {
|
|
100
|
+
if (!requirements || !Array.isArray(requirements.operations)) {
|
|
101
|
+
return [];
|
|
102
|
+
}
|
|
103
|
+
const { allowlist } = ValidateOperationAllowlist(requirements.operations);
|
|
104
|
+
return allowlist;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Checks whether a specific `operationKey` is explicitly permitted by `requirements.operations`.
|
|
108
|
+
* Always returns `false` when `operations` is omitted (default-deny) or when `operationKey` is
|
|
109
|
+
* empty or contains wildcards.
|
|
110
|
+
*/
|
|
111
|
+
export function IsOperationAllowed(requirements, operationKey) {
|
|
112
|
+
if (!IsValidOperationKey(operationKey)) {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
const allowed = ResolveAllowedOperations(requirements);
|
|
116
|
+
return allowed.some((entry) => entry.operationKey === operationKey);
|
|
117
|
+
}
|
|
1
118
|
/**
|
|
2
119
|
* Lightweight class to share field metadata for component validation and linting.
|
|
3
120
|
* This is a simplified version of EntityFieldInfo from @memberjunction/core,
|