@widgetic/ui-sdk 0.1.3 → 0.1.6
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 +161 -10
- package/dist/{index.js → index.cjs} +17 -24
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +52 -0
- package/dist/index.esm.js +16 -23
- package/dist/index.esm.js.map +1 -1
- package/dist/sdk/core/component.d.cts +46 -0
- package/dist/sdk/core/component.d.ts +1 -1
- package/dist/sdk/core/component.d.ts.map +1 -1
- package/dist/sdk/core/events.d.cts +25 -0
- package/dist/sdk/core/events.d.ts +1 -1
- package/dist/sdk/core/events.d.ts.map +1 -1
- package/dist/sdk/core/index.d.cts +32 -0
- package/dist/sdk/core/index.d.ts +6 -6
- package/dist/sdk/core/index.d.ts.map +1 -1
- package/dist/sdk/core/lifecycle.d.cts +96 -0
- package/dist/sdk/core/lifecycle.d.ts +3 -3
- package/dist/sdk/core/lifecycle.d.ts.map +1 -1
- package/dist/sdk/core/local-events.d.cts +24 -0
- package/dist/sdk/core/local-events.d.ts +1 -1
- package/dist/sdk/core/local-events.d.ts.map +1 -1
- package/dist/sdk/core/messaging.d.cts +57 -0
- package/dist/sdk/core/messaging.d.ts +2 -2
- package/dist/sdk/core/messaging.d.ts.map +1 -1
- package/dist/sdk/core/state.d.cts +64 -0
- package/dist/sdk/core/state.d.ts +10 -3
- package/dist/sdk/core/state.d.ts.map +1 -1
- package/dist/sdk/core/theme-mode.d.cts +43 -0
- package/dist/sdk/core/theme-mode.d.ts +1 -1
- package/dist/sdk/core/theme-mode.d.ts.map +1 -1
- package/dist/sdk/core/theme.d.cts +57 -0
- package/dist/sdk/core/theme.d.ts +2 -2
- package/dist/sdk/core/theme.d.ts.map +1 -1
- package/dist/sdk/index.d.cts +3 -0
- package/dist/sdk/index.d.ts +1 -1
- package/dist/sdk/index.d.ts.map +1 -1
- package/dist/sdk/integration/host.d.cts +53 -0
- package/dist/sdk/integration/host.d.ts +2 -2
- package/dist/sdk/integration/host.d.ts.map +1 -1
- package/dist/sdk/integration/index.d.cts +18 -0
- package/dist/sdk/integration/index.d.ts +1 -1
- package/dist/sdk/integration/index.d.ts.map +1 -1
- package/dist/sdk/layers/index.d.cts +35 -0
- package/dist/sdk/loader/ui.d.cts +207 -0
- package/dist/sdk/loader/ui.d.ts +49 -6
- package/dist/sdk/loader/ui.d.ts.map +1 -1
- package/dist/sdk/modules/index.d.cts +8 -0
- package/dist/sdk/modules/index.d.ts +1 -1
- package/dist/sdk/modules/index.d.ts.map +1 -1
- package/dist/sdk/modules/loader.d.cts +83 -0
- package/dist/sdk/modules/loader.d.ts +1 -1
- package/dist/sdk/modules/loader.d.ts.map +1 -1
- package/dist/sdk/types/component.d.cts +214 -0
- package/dist/sdk/types/component.d.ts +49 -11
- package/dist/sdk/types/component.d.ts.map +1 -1
- package/dist/sdk/types/events.d.cts +111 -0
- package/dist/sdk/types/events.d.ts.map +1 -1
- package/dist/sdk/types/index.d.cts +43 -0
- package/dist/sdk/types/index.d.ts +8 -6
- package/dist/sdk/types/index.d.ts.map +1 -1
- package/dist/sdk/types/messaging.d.cts +40 -0
- package/dist/sdk/types/module-events.d.cts +212 -0
- package/dist/sdk/types/module-events.d.ts +213 -0
- package/dist/sdk/types/module-events.d.ts.map +1 -0
- package/dist/sdk/types/module-language.d.cts +46 -0
- package/dist/sdk/types/module-media-library.d.cts +143 -0
- package/dist/sdk/types/module-media-library.d.ts +144 -0
- package/dist/sdk/types/module-media-library.d.ts.map +1 -0
- package/dist/sdk/types/module-theme.d.cts +96 -0
- package/dist/sdk/types/module-theme.d.ts +1 -1
- package/dist/sdk/types/module-theme.d.ts.map +1 -1
- package/dist/sdk/types/state.d.cts +37 -0
- package/dist/sdk/types/state.d.ts.map +1 -1
- package/dist/sdk/types/theme.d.cts +75 -0
- package/dist/sdk/utils/config.d.cts +69 -0
- package/dist/sdk/utils/config.d.ts.map +1 -1
- package/dist/sdk/utils/errors.d.cts +55 -0
- package/dist/sdk/utils/errors.d.ts +1 -1
- package/dist/sdk/utils/errors.d.ts.map +1 -1
- package/dist/sdk/utils/http.d.cts +20 -0
- package/dist/sdk/utils/security.d.cts +94 -0
- package/dist/sdk/utils/validation.d.cts +63 -0
- package/dist/sdk/utils/validation.d.ts +1 -1
- package/dist/sdk/utils/validation.d.ts.map +1 -1
- package/dist/sdk/version.d.cts +10 -0
- package/dist/sdk/version.d.ts +5 -2
- package/dist/sdk/version.d.ts.map +1 -1
- package/dist/services/dataService.d.cts +9 -0
- package/dist/services/dataService.d.ts +4 -4
- package/dist/services/dataService.d.ts.map +1 -1
- package/dist/umd/ui-sdk.js +1 -1
- package/dist/umd/ui-sdk.js.map +1 -1
- package/dist/utils/caseConversion.d.cts +2 -0
- package/dist/utils/caseConversion.d.ts +2 -2
- package/dist/utils/caseConversion.d.ts.map +1 -1
- package/modules/README.md +79 -43
- package/package.json +24 -10
- package/dist/index.js.map +0 -1
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a partner can say about its own files: the `mediaLibrary` option of the File Browser, the composition editor
|
|
3
|
+
* and the widget creator, and the `pickFile` option of the composition editor and the widget creator.
|
|
4
|
+
*
|
|
5
|
+
* await ui.mount('composition-editor', {
|
|
6
|
+
* container,
|
|
7
|
+
* compositionId,
|
|
8
|
+
* mediaLibrary: {
|
|
9
|
+
* id: 'acme-assets',
|
|
10
|
+
* list: async ({ cursor, limit, signal }) => ({ items: await listAcmeFiles(cursor, limit, signal), nextCursor: null }),
|
|
11
|
+
* urlResolver: async (file) => `https://cdn.acme.com/assets/${file.id}`, // the address that is saved
|
|
12
|
+
* },
|
|
13
|
+
* pickFile: async ({ accept, multiple, signal }) => openAcmePicker({ accept, multiple, signal }), // [] when cancelled
|
|
14
|
+
* });
|
|
15
|
+
*
|
|
16
|
+
* The File Browser package (`@widgetic/file-browser`) defines the same shapes for its own insides. They are written out
|
|
17
|
+
* here, so that the package stays free of it, and `modules/tests/rootMediaLibraryTypes.test.ts` fails the modules' type
|
|
18
|
+
* check when what you write against these types is no longer what the modules accept. It holds types only.
|
|
19
|
+
*/
|
|
20
|
+
/** One file, as your library or your picker hands it to a module. */
|
|
21
|
+
export interface MediaLibraryFile {
|
|
22
|
+
/**
|
|
23
|
+
* The file's id in your library: stable and unique there. It is handed back unchanged when the visitor picks the
|
|
24
|
+
* file and when a rename or a delete is asked for. A widget keeps it only so the picker shows the file as selected
|
|
25
|
+
* the next time it opens.
|
|
26
|
+
*/
|
|
27
|
+
id: string;
|
|
28
|
+
/** The name shown to the visitor, with its extension (`logo.png`). */
|
|
29
|
+
name: string;
|
|
30
|
+
/**
|
|
31
|
+
* Where the visitor's browser can fetch the file: an `http:` or `https:` address, or a path on the page's own site.
|
|
32
|
+
* This is what a widget stores and shows, and everyone who sees the published widget loads it, so give one that
|
|
33
|
+
* stays valid and needs no sign-in (see `mediaLibrary.urlResolver`).
|
|
34
|
+
*/
|
|
35
|
+
url: string;
|
|
36
|
+
/** The file's media type, like `image/png`. It tells images from audio, video and documents. */
|
|
37
|
+
mimeType?: string;
|
|
38
|
+
/** Size in bytes. */
|
|
39
|
+
size?: number;
|
|
40
|
+
/** When the file last changed: an ISO 8601 string, a `Date`, or milliseconds since 1970. */
|
|
41
|
+
modified?: string | number | Date;
|
|
42
|
+
/** A small preview picture (an image address), for a file that is not itself a small image. */
|
|
43
|
+
thumbnail?: string;
|
|
44
|
+
/** A content hash, handed back to you as it is. Never interpreted. */
|
|
45
|
+
hash?: string;
|
|
46
|
+
}
|
|
47
|
+
/** What `list` is asked for. */
|
|
48
|
+
export interface MediaLibraryListRequest {
|
|
49
|
+
/** The `nextCursor` of the page before. Absent for the first page. */
|
|
50
|
+
cursor?: string;
|
|
51
|
+
/** The most files the module wants in this page. Returning fewer is fine. */
|
|
52
|
+
limit: number;
|
|
53
|
+
/** Aborted when the module no longer wants the answer (it was closed, or reloaded). */
|
|
54
|
+
signal: AbortSignal;
|
|
55
|
+
}
|
|
56
|
+
/** One page of your library, newest files first. */
|
|
57
|
+
export interface MediaLibraryPage {
|
|
58
|
+
items: MediaLibraryFile[];
|
|
59
|
+
/** Pass this back as `cursor` to get the next page. Absent, `null` or empty when there is no more. */
|
|
60
|
+
nextCursor?: string | null;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Where in the product a file is being stored, when the module can say.
|
|
64
|
+
* - `field`: a file field of the composition editor, or of the widget creator's settings panel.
|
|
65
|
+
* - `chat`: an attachment of the widget creator's chat.
|
|
66
|
+
* - `canvas`: a picture dropped on the widget creator's canvas or into its prompt.
|
|
67
|
+
*/
|
|
68
|
+
export type MediaUploadPurpose = 'canvas' | 'chat' | 'field';
|
|
69
|
+
/**
|
|
70
|
+
* What `upload` is asked for. `purpose` is given by the composition editor and the widget creator; the File Browser
|
|
71
|
+
* module leaves it out.
|
|
72
|
+
*/
|
|
73
|
+
export interface MediaLibraryUploadRequest {
|
|
74
|
+
file: File;
|
|
75
|
+
purpose?: MediaUploadPurpose;
|
|
76
|
+
/** Tell the module how far the upload is, from 0 to 100. Optional to call. */
|
|
77
|
+
onProgress?: (percentage: number) => void;
|
|
78
|
+
signal?: AbortSignal;
|
|
79
|
+
}
|
|
80
|
+
/** What `rename` is asked for. */
|
|
81
|
+
export interface MediaLibraryRenameRequest {
|
|
82
|
+
id: string;
|
|
83
|
+
/** The new name, with its extension. */
|
|
84
|
+
name: string;
|
|
85
|
+
signal: AbortSignal;
|
|
86
|
+
}
|
|
87
|
+
/** What `delete` is asked for. */
|
|
88
|
+
export interface MediaLibraryDeleteRequest {
|
|
89
|
+
id: string;
|
|
90
|
+
signal: AbortSignal;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Turns a file of your library (or one your `pickFile` returned) into the address that is saved with the widget. It may
|
|
94
|
+
* answer at once or later; the module waits up to 10 seconds. When it throws, takes longer, or answers something that
|
|
95
|
+
* is not an `http:` or `https:` address, the file's own `url` is kept and one warning is written to the console.
|
|
96
|
+
*/
|
|
97
|
+
export type MediaLibraryUrlResolver = (file: MediaLibraryFile) => string | Promise<string>;
|
|
98
|
+
/** Your own media library: plain functions that read and write your files. Only `list` is required. */
|
|
99
|
+
export interface PartnerMediaLibrary {
|
|
100
|
+
/** A short stable name for the library, like `acme-assets`. Used in logs. */
|
|
101
|
+
readonly id: string;
|
|
102
|
+
/** What the visitor sees as the list's name. Default: "My uploads". */
|
|
103
|
+
readonly label?: string;
|
|
104
|
+
/**
|
|
105
|
+
* Switches actions off. A button is shown only for the functions you give, so this can only take actions away:
|
|
106
|
+
* `capabilities: { delete: false }` hides Delete although `delete` is given.
|
|
107
|
+
*/
|
|
108
|
+
readonly capabilities?: {
|
|
109
|
+
upload?: boolean;
|
|
110
|
+
rename?: boolean;
|
|
111
|
+
delete?: boolean;
|
|
112
|
+
download?: boolean;
|
|
113
|
+
};
|
|
114
|
+
/** Gives one page of your library. Required. */
|
|
115
|
+
list(request: MediaLibraryListRequest): Promise<MediaLibraryPage>;
|
|
116
|
+
/** Stores a new file and gives back how your library knows it now. */
|
|
117
|
+
upload?(request: MediaLibraryUploadRequest): Promise<MediaLibraryFile>;
|
|
118
|
+
/** Renames a file. Gives back the file as it is now, or nothing. */
|
|
119
|
+
rename?(request: MediaLibraryRenameRequest): Promise<MediaLibraryFile | void>;
|
|
120
|
+
/** Removes a file from your library. */
|
|
121
|
+
delete?(request: MediaLibraryDeleteRequest): Promise<void>;
|
|
122
|
+
/** See {@link MediaLibraryUrlResolver}. */
|
|
123
|
+
urlResolver?: MediaLibraryUrlResolver;
|
|
124
|
+
}
|
|
125
|
+
/** What `pickFile` is asked for. */
|
|
126
|
+
export interface PickFileRequest {
|
|
127
|
+
/**
|
|
128
|
+
* The file types the field allows, passed on as the field gives them (for example `['image/*']`), and the one
|
|
129
|
+
* pattern that matches every type (an asterisk, a slash and an asterisk: see the README) when the field names none.
|
|
130
|
+
*/
|
|
131
|
+
accept: string[];
|
|
132
|
+
/** Whether more than one file may be chosen. File fields ask for one: `false`. */
|
|
133
|
+
multiple: boolean;
|
|
134
|
+
/** Aborted when the visitor closes the editor or starts another pick. */
|
|
135
|
+
signal: AbortSignal;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Opens your own file picker instead of the built-in File Browser, for the file fields of the composition editor and of
|
|
139
|
+
* the widget creator's settings panel. Resolve the files the visitor chose (each needs an `id` and a `url`; a field
|
|
140
|
+
* takes the first one), or `[]` when the visitor cancelled. Rejecting with an `AbortError` also means cancelled; any other
|
|
141
|
+
* error is written to the console once and counts as nothing picked.
|
|
142
|
+
*/
|
|
143
|
+
export type PickFileFn = (request: PickFileRequest) => Promise<MediaLibraryFile[]>;
|
|
144
|
+
//# sourceMappingURL=module-media-library.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-media-library.d.ts","sourceRoot":"","sources":["../../../src/sdk/types/module-media-library.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a partner can say about the look of a UI module: the `theme` of a mount call, of `new WidgeticUI({ theme })`
|
|
3
|
+
* and of `updateTheme(...)`, and the `theme` option every module takes when it is built without the loader.
|
|
4
|
+
*
|
|
5
|
+
* await ui.mount('file-browser', { container, theme: 'dark' }); // just light or dark
|
|
6
|
+
* await ui.mount('file-browser', { container, theme: { preset: 'ocean' } }); // one of the built-in themes
|
|
7
|
+
* await ui.mount('composition-editor', {
|
|
8
|
+
* container,
|
|
9
|
+
* theme: {
|
|
10
|
+
* preset: 'graphite', // start from a built-in theme ...
|
|
11
|
+
* colors: { primary: '#e0541b', background: '#fffaf5' }, // ... and change what is yours
|
|
12
|
+
* radius: 'large',
|
|
13
|
+
* font: { family: '"Poppins", sans-serif', stylesheetUrl: 'https://fonts.googleapis.com/css2?family=Poppins' },
|
|
14
|
+
* },
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* Each module takes its own `theme`, so the modules on one page can look different.
|
|
18
|
+
*
|
|
19
|
+
* This file is the single source of these types: the modules (`modules/src/shared/theme/themeTypes.ts`) re-export it, so
|
|
20
|
+
* what the loader accepts and what a module accepts cannot drift apart. It holds types only.
|
|
21
|
+
*/
|
|
22
|
+
import type { ThemeMode } from './theme.cjs';
|
|
23
|
+
/** Light or dark. */
|
|
24
|
+
export type ModuleThemeMode = 'light' | 'dark';
|
|
25
|
+
/** The built-in themes. `widgetic` is the look the modules have when nothing is asked. */
|
|
26
|
+
export type ModuleThemePresetName = 'widgetic' | 'graphite' | 'ocean' | 'violet' | 'sunset';
|
|
27
|
+
/**
|
|
28
|
+
* Colours of a theme. Any CSS colour that is written out (`#0b6bcb`, `rgb(11 107 203)`, `hsl(210 90% 41%)`, `rebeccapurple`,
|
|
29
|
+
* `oklch(0.6 0.15 250)`); `var(--x)` and `currentColor` are not understood. A colour is used opaque: a transparency in it is ignored.
|
|
30
|
+
* Leave a colour out and it follows from the others (a theme with only a `primary` still has readable text on it).
|
|
31
|
+
*/
|
|
32
|
+
export interface ModuleThemeColors {
|
|
33
|
+
/** The brand colour: buttons, selected items, links, the focus ring. */
|
|
34
|
+
primary?: string;
|
|
35
|
+
/** Text and icons on `primary`. Default: white or near-black, whichever reads better. */
|
|
36
|
+
primaryForeground?: string;
|
|
37
|
+
/** The module's own background (its panels, menus and dialogs). */
|
|
38
|
+
background?: string;
|
|
39
|
+
/** Main text and icons. */
|
|
40
|
+
foreground?: string;
|
|
41
|
+
/** Quiet surfaces: a search box, a hovered row, a tab strip. Default: a little of `foreground` over `background`. */
|
|
42
|
+
muted?: string;
|
|
43
|
+
/** Secondary text: captions, placeholders, file sizes. Default: `foreground` over `background`, softened. */
|
|
44
|
+
mutedForeground?: string;
|
|
45
|
+
/** Lines around cards and inputs, and between sections. Default: a little of `foreground` over `background`. */
|
|
46
|
+
border?: string;
|
|
47
|
+
/** A soft highlight: the selected file, a hovered menu entry. Default: a light tint of `primary`. */
|
|
48
|
+
accent?: string;
|
|
49
|
+
/** Errors, warnings about data loss, and delete buttons. */
|
|
50
|
+
destructive?: string;
|
|
51
|
+
/** Panel and card surfaces (`--background`, `--card`, `--popover`, `--surface-canvas`). */
|
|
52
|
+
surface?: string;
|
|
53
|
+
/** Secondary fills and quiet rows (`--secondary`, `--muted`, `--grey1`). */
|
|
54
|
+
secondary?: string;
|
|
55
|
+
}
|
|
56
|
+
/** The typeface of a module. The widgets the visitor builds keep their own fonts. */
|
|
57
|
+
export interface ModuleThemeFont {
|
|
58
|
+
/**
|
|
59
|
+
* A CSS font-family list, like `'"Poppins", system-ui, sans-serif'`. A single name (`'Poppins'`) gets a safe list of
|
|
60
|
+
* fallbacks added behind it. The font has to be available on the page: already loaded by the page, or through `stylesheetUrl`.
|
|
61
|
+
*/
|
|
62
|
+
family: string;
|
|
63
|
+
/**
|
|
64
|
+
* A stylesheet that defines the font, such as a Google Fonts address. The module adds it to the page's `<head>`
|
|
65
|
+
* once (a font can only be defined there, not inside the module). Needs `https:`; your Content-Security-Policy has
|
|
66
|
+
* to allow it. Not needed for a font your page loads itself.
|
|
67
|
+
*/
|
|
68
|
+
stylesheetUrl?: string;
|
|
69
|
+
}
|
|
70
|
+
/** How round the corners are: a word, or the radius in pixels of a normal control. `medium` (8px) is how the modules look by default. */
|
|
71
|
+
export type ModuleThemeRadius = 'none' | 'small' | 'medium' | 'large' | number;
|
|
72
|
+
/** Everything about a look. All of it is optional. */
|
|
73
|
+
export interface ModuleThemeSettings {
|
|
74
|
+
/** The built-in theme to start from. Default `widgetic`. */
|
|
75
|
+
preset?: ModuleThemePresetName;
|
|
76
|
+
/** Light or dark. Default `light`. */
|
|
77
|
+
mode?: ModuleThemeMode;
|
|
78
|
+
/** Your colours, on top of the preset's. */
|
|
79
|
+
colors?: ModuleThemeColors;
|
|
80
|
+
/** Roundness of buttons, cards and inputs. */
|
|
81
|
+
radius?: ModuleThemeRadius;
|
|
82
|
+
/** Your typeface. */
|
|
83
|
+
font?: ModuleThemeFont;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* What a module takes as its `theme`: `'light'`, `'dark'`, or the settings. As the argument of a module's `setTheme`, a
|
|
87
|
+
* bare `'light'` or `'dark'` changes only the mode and keeps the rest; settings replace the whole theme.
|
|
88
|
+
*/
|
|
89
|
+
export type ModuleTheme = ModuleThemeMode | ModuleThemeSettings;
|
|
90
|
+
/**
|
|
91
|
+
* What a page may write wherever the loader takes a theme (`new WidgeticUI({ theme })`, `updateTheme`, the `theme` of a
|
|
92
|
+
* mount call): the modules' theme, where the mode may also be `'system'` to follow the visitor's operating system.
|
|
93
|
+
*/
|
|
94
|
+
export type ThemeOption = ThemeMode | (Omit<ModuleThemeSettings, 'mode'> & {
|
|
95
|
+
mode?: ThemeMode;
|
|
96
|
+
});
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* This file is the single source of these types: the modules (`modules/src/shared/theme/themeTypes.ts`) re-export it, so
|
|
20
20
|
* what the loader accepts and what a module accepts cannot drift apart. It holds types only.
|
|
21
21
|
*/
|
|
22
|
-
import type { ThemeMode } from './theme';
|
|
22
|
+
import type { ThemeMode } from './theme.js';
|
|
23
23
|
/** Light or dark. */
|
|
24
24
|
export type ModuleThemeMode = 'light' | 'dark';
|
|
25
25
|
/** The built-in themes. `widgetic` is the look the modules have when nothing is asked. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module-theme.d.ts","sourceRoot":"","sources":["../../../src/sdk/types/module-theme.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"module-theme.d.ts","sourceRoot":"","sources":["../../../src/sdk/types/module-theme.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,qBAAqB;AACrB,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,MAAM,CAAC;AAE/C,0FAA0F;AAC1F,MAAM,MAAM,qBAAqB,GAAG,UAAU,GAAG,UAAU,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE5F;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,wEAAwE;IACxE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yFAAyF;IACzF,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,mEAAmE;IACnE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,2BAA2B;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qHAAqH;IACrH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,6GAA6G;IAC7G,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gHAAgH;IAChH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qGAAqG;IACrG,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,4DAA4D;IAC5D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2FAA2F;IAC3F,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4EAA4E;IAC5E,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,qFAAqF;AACrF,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,yIAAyI;AACzI,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC;AAE/E,sDAAsD;AACtD,MAAM,WAAW,mBAAmB;IAClC,4DAA4D;IAC5D,MAAM,CAAC,EAAE,qBAAqB,CAAC;IAC/B,sCAAsC;IACtC,IAAI,CAAC,EAAE,eAAe,CAAC;IACvB,4CAA4C;IAC5C,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B,8CAA8C;IAC9C,MAAM,CAAC,EAAE,iBAAiB,CAAC;IAC3B,qBAAqB;IACrB,IAAI,CAAC,EAAE,eAAe,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,eAAe,GAAG,mBAAmB,CAAC;AAEhE;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,CAAC,IAAI,CAAC,mBAAmB,EAAE,MAAM,CAAC,GAAG;IAAE,IAAI,CAAC,EAAE,SAAS,CAAA;CAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* State Management Types
|
|
3
|
+
* Contains type definitions for component and system state management.
|
|
4
|
+
* Used for tracking component status, errors, and configuration.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Component state configuration
|
|
8
|
+
* Defines state manager settings
|
|
9
|
+
*/
|
|
10
|
+
export interface StateConfig {
|
|
11
|
+
maxSnapshots?: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Component state snapshot
|
|
15
|
+
* Point-in-time capture of component state
|
|
16
|
+
*/
|
|
17
|
+
export interface StateSnapshot {
|
|
18
|
+
timestamp: number;
|
|
19
|
+
state: Map<string, any>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Component state interface
|
|
23
|
+
* Current state of a UI component
|
|
24
|
+
*/
|
|
25
|
+
export interface ComponentState {
|
|
26
|
+
status: 'initializing' | 'ready' | 'error';
|
|
27
|
+
error: Error | null;
|
|
28
|
+
data?: Record<string, any>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* State update configuration
|
|
32
|
+
* Options for state updates
|
|
33
|
+
*/
|
|
34
|
+
export interface StateUpdateOptions {
|
|
35
|
+
silent?: boolean;
|
|
36
|
+
snapshot?: boolean;
|
|
37
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/sdk/types/state.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;GAGG;AACH,MAAM,WAAW,WAAW;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC1B,SAAS,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../../../src/sdk/types/state.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;GAGG;AACH,MAAM,WAAW,WAAW;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC1B,SAAS,EAAE,MAAM,CAAC;IAElB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC3B;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC3B,MAAM,EAAE,cAAc,GAAG,OAAO,GAAG,OAAO,CAAC;IAC3C,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;IAEpB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC9B;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IAC/B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACtB"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Theme Type Definitions
|
|
3
|
+
* Contains types for theme configuration and customization.
|
|
4
|
+
* Used for consistent styling across components.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Theme mode options
|
|
8
|
+
* Defines available color schemes
|
|
9
|
+
*/
|
|
10
|
+
export type ThemeMode = 'light' | 'dark' | 'system';
|
|
11
|
+
/**
|
|
12
|
+
* Color scheme configuration
|
|
13
|
+
* Defines customizable colors for components
|
|
14
|
+
*/
|
|
15
|
+
export interface ColorScheme {
|
|
16
|
+
primary: string;
|
|
17
|
+
secondary: string;
|
|
18
|
+
background: string;
|
|
19
|
+
surface: string;
|
|
20
|
+
text: string;
|
|
21
|
+
border: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Spacing configuration
|
|
25
|
+
* Defines consistent spacing units
|
|
26
|
+
*/
|
|
27
|
+
export interface SpacingConfig {
|
|
28
|
+
unit: number;
|
|
29
|
+
scale: number[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Typography configuration
|
|
33
|
+
* Defines font settings and scale
|
|
34
|
+
*/
|
|
35
|
+
export interface TypographyConfig {
|
|
36
|
+
fontFamily: string;
|
|
37
|
+
scale: number[];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Complete theme configuration
|
|
41
|
+
* Combines all theme settings
|
|
42
|
+
*/
|
|
43
|
+
export interface ThemeConfig {
|
|
44
|
+
mode: ThemeMode;
|
|
45
|
+
colors: ColorScheme;
|
|
46
|
+
spacing: SpacingConfig;
|
|
47
|
+
typography: TypographyConfig;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Partial theme updates
|
|
51
|
+
* Allows updating specific theme properties
|
|
52
|
+
*/
|
|
53
|
+
export type PartialThemeConfig = Partial<ThemeConfig>;
|
|
54
|
+
/**
|
|
55
|
+
* Partner theme overrides
|
|
56
|
+
* Allows partners to customize specific theme aspects
|
|
57
|
+
*/
|
|
58
|
+
export interface PartnerTheme {
|
|
59
|
+
mode?: ThemeMode;
|
|
60
|
+
colors?: Partial<ColorScheme>;
|
|
61
|
+
spacing?: Partial<SpacingConfig>;
|
|
62
|
+
typography?: Partial<TypographyConfig>;
|
|
63
|
+
}
|
|
64
|
+
export type ThemePreset = {
|
|
65
|
+
readonly mode: ThemeMode;
|
|
66
|
+
readonly colors: Readonly<ColorScheme>;
|
|
67
|
+
readonly spacing: {
|
|
68
|
+
readonly unit: number;
|
|
69
|
+
readonly scale: readonly number[];
|
|
70
|
+
};
|
|
71
|
+
readonly typography: {
|
|
72
|
+
readonly fontFamily: string;
|
|
73
|
+
readonly scale: readonly number[];
|
|
74
|
+
};
|
|
75
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK Configuration Management
|
|
3
|
+
*
|
|
4
|
+
* Holds the SDK's default addresses and the few switches the legacy security helpers read.
|
|
5
|
+
*
|
|
6
|
+
* Nothing in here handles credentials. The SDK never sees an API key: a partner's server mints a short-lived editor
|
|
7
|
+
* session token and the partner's `getToken` function hands it to the SDK (see `WidgeticUI`).
|
|
8
|
+
*/
|
|
9
|
+
/** The Widgetic API every module talks to unless the partner points it somewhere else (staging, local gateway). */
|
|
10
|
+
export declare const DEFAULT_API_URL = "https://api.widgetic.com";
|
|
11
|
+
/** Where the UI modules are served from. Each module lives in a folder named after it: `<base>/<name>/…`. */
|
|
12
|
+
export declare const DEFAULT_MODULE_BASE_URL = "https://cdn.widgetic.com/modules";
|
|
13
|
+
export interface Config {
|
|
14
|
+
CDN_URL: string;
|
|
15
|
+
NODE_ENV: string;
|
|
16
|
+
API_URL: string;
|
|
17
|
+
API_VERSION: string;
|
|
18
|
+
CLIENT_URL: string;
|
|
19
|
+
PRODUCTION_URL: string;
|
|
20
|
+
EMBED_SDK_URL: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Default configuration values.
|
|
24
|
+
*
|
|
25
|
+
* `NODE_ENV` defaults to production: the origin checks in the security helpers are only relaxed when a developer
|
|
26
|
+
* asks for development mode explicitly, never because nobody configured anything.
|
|
27
|
+
*/
|
|
28
|
+
export declare const DEFAULT_CONFIG: Config;
|
|
29
|
+
/**
|
|
30
|
+
* Configuration Manager
|
|
31
|
+
* Singleton class that handles the SDK's configuration values.
|
|
32
|
+
*/
|
|
33
|
+
export declare class ConfigManager {
|
|
34
|
+
private static instance;
|
|
35
|
+
private config;
|
|
36
|
+
private constructor();
|
|
37
|
+
/**
|
|
38
|
+
* Get singleton instance
|
|
39
|
+
* Creates instance if it doesn't exist
|
|
40
|
+
*/
|
|
41
|
+
static getInstance(): ConfigManager;
|
|
42
|
+
/**
|
|
43
|
+
* Initialize configuration with custom values
|
|
44
|
+
* Merges provided config with defaults
|
|
45
|
+
* @param config - Partial configuration to apply
|
|
46
|
+
*/
|
|
47
|
+
initialize(config: Partial<Config>): void;
|
|
48
|
+
/**
|
|
49
|
+
* Get API base URL
|
|
50
|
+
* @returns Configured API URL
|
|
51
|
+
*/
|
|
52
|
+
getApiUrl(): string;
|
|
53
|
+
/**
|
|
54
|
+
* Get CDN base URL
|
|
55
|
+
* @returns Configured CDN URL
|
|
56
|
+
*/
|
|
57
|
+
getCdnUrl(): string;
|
|
58
|
+
/**
|
|
59
|
+
* Check if running in production mode
|
|
60
|
+
*/
|
|
61
|
+
get isProduction(): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Validate required configuration
|
|
64
|
+
* Ensures all required values are present
|
|
65
|
+
* @throws Error if required config is missing
|
|
66
|
+
*/
|
|
67
|
+
validateConfig(): void;
|
|
68
|
+
}
|
|
69
|
+
export declare const config: ConfigManager;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/sdk/utils/config.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,mHAAmH;AACnH,eAAO,MAAM,eAAe,6BAA6B,CAAC;AAE1D,6GAA6G;AAC7G,eAAO,MAAM,uBAAuB,qCAAqC,CAAC;AAE1E,MAAM,WAAW,MAAM;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;CACzB;AAED;;;;;GAKG;AACH,eAAO,MAAM,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/sdk/utils/config.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,mHAAmH;AACnH,eAAO,MAAM,eAAe,6BAA6B,CAAC;AAE1D,6GAA6G;AAC7G,eAAO,MAAM,uBAAuB,qCAAqC,CAAC;AAE1E,MAAM,WAAW,MAAM;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;CACzB;AAED;;;;;GAKG;AACH,eAAO,MAAM,cAAc,EAAE,MAS5B,CAAC;AAEF;;;GAGG;AACH,qBAAa,aAAa;IACtB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAgB;IACvC,OAAO,CAAC,MAAM,CAAS;IAEvB,OAAO;IAIP;;;OAGG;IACH,MAAM,CAAC,WAAW,IAAI,aAAa;IAOnC;;;;OAIG;IACH,UAAU,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,IAAI;IAOzC;;;OAGG;IACH,SAAS,IAAI,MAAM;IAInB;;;OAGG;IACH,SAAS,IAAI,MAAM;IAInB;;OAEG;IACH,IAAI,YAAY,IAAI,OAAO,CAE1B;IAED;;;;OAIG;IACH,cAAc,IAAI,IAAI;CAazB;AAGD,eAAO,MAAM,MAAM,eAA8B,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error Handling System
|
|
3
|
+
* Provides centralized error handling and standardization.
|
|
4
|
+
* Creates consistent error objects with proper typing and context.
|
|
5
|
+
*/
|
|
6
|
+
import type { SDKError } from '../types/index.cjs';
|
|
7
|
+
export declare class SDKErrorHandler {
|
|
8
|
+
/**
|
|
9
|
+
* Create standardized error object
|
|
10
|
+
* Formats error with message and code for consistent handling
|
|
11
|
+
* @param message - Human readable error message
|
|
12
|
+
* @param code - Error code for programmatic handling
|
|
13
|
+
* @returns Formatted error object
|
|
14
|
+
*/
|
|
15
|
+
static createError(message: string, code: string): Error;
|
|
16
|
+
/**
|
|
17
|
+
* Handle and transform errors
|
|
18
|
+
* Converts various error types to standardized SDK errors
|
|
19
|
+
* @param error - Original error object
|
|
20
|
+
* @param context - Error context for tracking
|
|
21
|
+
* @returns Standardized error object
|
|
22
|
+
*/
|
|
23
|
+
static handleError(error: unknown, context: string): Error;
|
|
24
|
+
/**
|
|
25
|
+
* Convert error to SDK error format
|
|
26
|
+
* Ensures error object matches SDK error interface
|
|
27
|
+
* @param error - Error to convert
|
|
28
|
+
* @returns SDK formatted error
|
|
29
|
+
*/
|
|
30
|
+
static toSDKError(error: Error): SDKError;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Validation Error
|
|
34
|
+
* Thrown when input validation fails
|
|
35
|
+
*/
|
|
36
|
+
export declare class ValidationError extends Error {
|
|
37
|
+
field?: string | undefined;
|
|
38
|
+
constructor(message: string, field?: string | undefined);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Security Error
|
|
42
|
+
* Thrown when security checks fail
|
|
43
|
+
*/
|
|
44
|
+
export declare class SecurityError extends Error {
|
|
45
|
+
code?: string | undefined;
|
|
46
|
+
constructor(message: string, code?: string | undefined);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Component Error
|
|
50
|
+
* Thrown when component operations fail
|
|
51
|
+
*/
|
|
52
|
+
export declare class ComponentError extends Error {
|
|
53
|
+
componentId?: string | undefined;
|
|
54
|
+
constructor(message: string, componentId?: string | undefined);
|
|
55
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Provides centralized error handling and standardization.
|
|
4
4
|
* Creates consistent error objects with proper typing and context.
|
|
5
5
|
*/
|
|
6
|
-
import type { SDKError } from '../types';
|
|
6
|
+
import type { SDKError } from '../types/index.js';
|
|
7
7
|
export declare class SDKErrorHandler {
|
|
8
8
|
/**
|
|
9
9
|
* Create standardized error object
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/sdk/utils/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/sdk/utils/errors.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAKlD,qBAAa,eAAe;IACxB;;;;;;OAMG;IACH,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,KAAK;IAMxD;;;;;;OAMG;IACH,MAAM,CAAC,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,KAAK;IAqB1D;;;;;OAKG;IACH,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,KAAK,GAAG,QAAQ;CAS5C;AAED;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,KAAK;IACF,KAAK,CAAC,EAAE,MAAM;gBAAtC,OAAO,EAAE,MAAM,EAAS,KAAK,CAAC,EAAE,MAAM,YAAA;CAIrD;AAED;;;GAGG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACA,IAAI,CAAC,EAAE,MAAM;gBAArC,OAAO,EAAE,MAAM,EAAS,IAAI,CAAC,EAAE,MAAM,YAAA;CAIpD;AAED;;;GAGG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACD,WAAW,CAAC,EAAE,MAAM;gBAA5C,OAAO,EAAE,MAAM,EAAS,WAAW,CAAC,EAAE,MAAM,YAAA;CAI3D"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP helpers
|
|
3
|
+
*
|
|
4
|
+
* Small request/response helpers. The SDK itself makes no authenticated API calls: the UI modules talk to the
|
|
5
|
+
* Widgetic API with the editor session token the partner's `getToken` returns. A browser-side HTTP client that
|
|
6
|
+
* attached an API key to requests used to live here; it was removed so an API key can never end up in a browser.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Create a secure HTTP request
|
|
10
|
+
* @param url - Request URL
|
|
11
|
+
* @param options - Request options
|
|
12
|
+
* @returns Configured request
|
|
13
|
+
*/
|
|
14
|
+
export declare function createSecureRequest(url: string, options?: RequestInit): Request;
|
|
15
|
+
/**
|
|
16
|
+
* Validate HTTP response
|
|
17
|
+
* @param response - Response to validate
|
|
18
|
+
* @returns True if response is valid
|
|
19
|
+
*/
|
|
20
|
+
export declare function validateResponse(response: Response): boolean;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
export declare class SecurityManager {
|
|
2
|
+
private allowedOrigins;
|
|
3
|
+
/**
|
|
4
|
+
* Validate domain against allowed list
|
|
5
|
+
* @param domain - Domain to validate
|
|
6
|
+
* @returns boolean indicating if domain is valid
|
|
7
|
+
*/
|
|
8
|
+
validateDomain(domain: string): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Development CSP Configuration
|
|
11
|
+
* Relaxed rules for local development
|
|
12
|
+
* @private
|
|
13
|
+
*/
|
|
14
|
+
private readonly DEVELOPMENT_CSP;
|
|
15
|
+
/**
|
|
16
|
+
* Production CSP Configuration
|
|
17
|
+
* Strict rules for production environment
|
|
18
|
+
* @private
|
|
19
|
+
*/
|
|
20
|
+
private readonly PRODUCTION_CSP;
|
|
21
|
+
/**
|
|
22
|
+
* Allowed Development Origins
|
|
23
|
+
* Origins that are always allowed in development
|
|
24
|
+
* @private
|
|
25
|
+
*/
|
|
26
|
+
private readonly ALLOWED_DEV_ORIGINS;
|
|
27
|
+
/**
|
|
28
|
+
* Initialize security manager
|
|
29
|
+
* Sets up CSP and configures allowed origins
|
|
30
|
+
* @param allowedOrigins - List of allowed origins
|
|
31
|
+
*/
|
|
32
|
+
constructor(allowedOrigins?: string[]);
|
|
33
|
+
/**
|
|
34
|
+
* Set up Content Security Policy
|
|
35
|
+
* In an embedded UI SDK, injecting top-level document CSP meta tags
|
|
36
|
+
* can interfere with the host application. Boundaries are maintained
|
|
37
|
+
* via iframe isolation and shadow DOM scoping.
|
|
38
|
+
* @private
|
|
39
|
+
*/
|
|
40
|
+
private setupCSP;
|
|
41
|
+
/**
|
|
42
|
+
* Build CSP directive string
|
|
43
|
+
* Converts CSP config to valid directive string
|
|
44
|
+
* @private
|
|
45
|
+
*/
|
|
46
|
+
private buildCSPString;
|
|
47
|
+
/**
|
|
48
|
+
* Validate request origin
|
|
49
|
+
* Checks if origin is allowed to make requests
|
|
50
|
+
* @param origin - Request origin to validate
|
|
51
|
+
*/
|
|
52
|
+
validateOrigin(origin: string): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Validate HTTP request
|
|
55
|
+
* Checks origin and CSRF token
|
|
56
|
+
* @param request - Request to validate
|
|
57
|
+
*/
|
|
58
|
+
validateRequest(request: Request): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Validate CSRF token
|
|
61
|
+
* Placeholder for CSRF token validation
|
|
62
|
+
* @private
|
|
63
|
+
*/
|
|
64
|
+
private validateCSRFToken;
|
|
65
|
+
/**
|
|
66
|
+
* Validate message event
|
|
67
|
+
* Checks message structure and content
|
|
68
|
+
* @param event - Message event to validate
|
|
69
|
+
*/
|
|
70
|
+
validateMessage(event: MessageEvent): boolean;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Validate origin against allowed list
|
|
74
|
+
* @param origin - Origin to validate
|
|
75
|
+
* @param allowedOrigins - List of allowed origins
|
|
76
|
+
* @returns True if origin is valid
|
|
77
|
+
*/
|
|
78
|
+
export declare function validateOrigin(origin: string, allowedOrigins?: string[]): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Sanitize input string
|
|
81
|
+
* @param input - Input to sanitize
|
|
82
|
+
* @returns Sanitized input
|
|
83
|
+
*/
|
|
84
|
+
export declare function sanitizeInput(input: string): string;
|
|
85
|
+
/**
|
|
86
|
+
* Create secure context for iframe communication
|
|
87
|
+
* @param allowedOrigins - List of allowed origins
|
|
88
|
+
* @returns Security context
|
|
89
|
+
*/
|
|
90
|
+
export declare function createSecureContext(allowedOrigins?: string[]): {
|
|
91
|
+
validateMessage: (event: MessageEvent) => boolean;
|
|
92
|
+
validateOrigin: (origin: string) => boolean;
|
|
93
|
+
sanitizeInput: typeof sanitizeInput;
|
|
94
|
+
};
|