@floegence/redevplugin-ui 0.1.6 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,13 @@
1
- import { type PluginPlatformClientOptions, type PluginRecord } from "./index.js";
1
+ import type { PluginPlatformClientOptions, PluginRecord } from "./platform.js";
2
2
  export type PluginImportLocalPackageRequest = {
3
3
  package_base64: string;
4
4
  plugin_instance_id?: string;
5
+ plugin_state_version: 0;
5
6
  };
6
7
  export type PluginUpdateLocalPackageRequest = {
7
8
  plugin_instance_id: string;
8
9
  package_base64: string;
10
+ plugin_state_version: number;
9
11
  };
10
12
  export declare class PluginLocalImportClient {
11
13
  #private;
@@ -1,76 +1,32 @@
1
- import { PluginBridgeError, } from "./index.js";
1
+ import { defaultFetch, readHostEnvelope, trimTrailingSlash } from "./http.js";
2
+ import { defaultPluginSurfaceScope, disposePluginSurfaceScope, } from "./surface-scope.js";
2
3
  export class PluginLocalImportClient {
3
4
  #fetch;
4
5
  #apiBaseURL;
5
- #ownerSessionHashHeader;
6
+ #surfaceScope;
6
7
  constructor(options = {}) {
7
8
  this.#fetch = options.fetch ?? defaultFetch();
8
9
  this.#apiBaseURL = trimTrailingSlash(options.apiBaseURL ?? "");
9
- this.#ownerSessionHashHeader = options.ownerSessionHashHeader;
10
+ this.#surfaceScope = options.surfaceScope ?? defaultPluginSurfaceScope;
10
11
  }
11
12
  importLocalPackage(request) {
12
13
  return this.#postJSON("/_redevplugin/api/plugins/local-import/install", request);
13
14
  }
14
- updateLocalPackage(request) {
15
- return this.#postJSON("/_redevplugin/api/plugins/local-import/update", request);
15
+ async updateLocalPackage(request) {
16
+ const plugin = await this.#postJSON("/_redevplugin/api/plugins/local-import/update", request);
17
+ disposePluginSurfaceScope(this.#surfaceScope, request.plugin_instance_id);
18
+ return plugin;
16
19
  }
17
20
  async #postJSON(path, body) {
18
21
  const response = await this.#fetch(this.#apiBaseURL + path, {
19
22
  method: "POST",
20
- headers: this.#headers(),
23
+ headers: {
24
+ "Accept": "application/json",
25
+ "Content-Type": "application/json",
26
+ },
21
27
  body: JSON.stringify(body),
22
28
  credentials: "same-origin",
23
29
  });
24
- return readHostEnvelope(response);
30
+ return readHostEnvelope(response, "PLUGIN_PLATFORM_REQUEST_FAILED");
25
31
  }
26
- #headers() {
27
- const headers = {
28
- "Accept": "application/json",
29
- "Content-Type": "application/json",
30
- };
31
- if (this.#ownerSessionHashHeader) {
32
- headers["X-ReDevPlugin-Owner-Session-Hash"] = this.#ownerSessionHashHeader;
33
- }
34
- return headers;
35
- }
36
- }
37
- function defaultFetch() {
38
- const fetchLike = globalThis.fetch;
39
- if (!fetchLike) {
40
- throw new Error("fetch is required when globalThis.fetch is unavailable");
41
- }
42
- return fetchLike.bind(globalThis);
43
- }
44
- function trimTrailingSlash(value) {
45
- return value.endsWith("/") ? value.slice(0, -1) : value;
46
- }
47
- async function readHostEnvelope(response) {
48
- const raw = await response.json();
49
- if (!isHostEnvelope(raw)) {
50
- throw new PluginBridgeError("PLUGIN_CONTRACT_MISMATCH", `Plugin platform endpoint returned an invalid envelope with HTTP ${response.status}`);
51
- }
52
- const envelope = raw;
53
- if (response.ok && envelope.ok) {
54
- return envelope.data;
55
- }
56
- if (envelope.ok) {
57
- throw new PluginBridgeError("PLUGIN_PLATFORM_REQUEST_FAILED", `Plugin platform request failed with HTTP ${response.status}`, envelope.data);
58
- }
59
- const errorCode = envelope.error_code ?? "PLUGIN_PLATFORM_REQUEST_FAILED";
60
- const message = envelope.error ?? "Plugin platform request failed";
61
- throw new PluginBridgeError(errorCode, message, envelope.data, envelope.error_details ?? envelope.data);
62
- }
63
- function isHostEnvelope(value) {
64
- if (!isRecord(value) || typeof value.ok !== "boolean") {
65
- return false;
66
- }
67
- if (value.ok) {
68
- return true;
69
- }
70
- return ((value.error === undefined || typeof value.error === "string") &&
71
- (value.error_code === undefined || typeof value.error_code === "string") &&
72
- (value.error_details === undefined || isRecord(value.error_details)));
73
- }
74
- function isRecord(value) {
75
- return typeof value === "object" && value !== null && !Array.isArray(value);
76
32
  }
@@ -0,0 +1,34 @@
1
+ export declare const opaqueSurfaceAllowedTags: readonly ["main", "section", "header", "footer", "nav", "aside", "article", "div", "span", "p", "h1", "h2", "h3", "h4", "h5", "h6", "button", "input", "textarea", "select", "option", "label", "fieldset", "legend", "form", "ul", "ol", "li", "dl", "dt", "dd", "table", "thead", "tbody", "tfoot", "tr", "th", "td", "caption", "details", "summary", "pre", "code", "kbd", "samp", "strong", "em", "small", "mark", "time", "progress", "meter", "img", "picture", "source", "audio", "video", "track"];
2
+ export type OpaqueSurfaceAllowedTag = (typeof opaqueSurfaceAllowedTags)[number];
3
+ export declare const opaqueSurfaceGlobalAttributes: readonly ["id", "class", "role", "title", "hidden", "tabindex", "lang", "dir", "data-redevplugin-action", "data-redevplugin-asset-binding", "data-redevplugin-asset-attr"];
4
+ export declare const opaqueSurfaceTagAttributes: {
5
+ readonly button: readonly ["type", "name", "value", "disabled", "aria-pressed", "aria-expanded"];
6
+ readonly input: readonly ["type", "name", "value", "checked", "disabled", "readonly", "required", "placeholder", "min", "max", "step", "autocomplete"];
7
+ readonly textarea: readonly ["name", "disabled", "readonly", "required", "placeholder", "rows", "cols", "maxlength"];
8
+ readonly select: readonly ["name", "disabled", "required", "multiple", "size"];
9
+ readonly option: readonly ["value", "selected", "disabled", "label"];
10
+ readonly label: readonly ["for"];
11
+ readonly form: readonly ["name", "autocomplete"];
12
+ readonly th: readonly ["scope", "colspan", "rowspan"];
13
+ readonly td: readonly ["colspan", "rowspan"];
14
+ readonly progress: readonly ["value", "max"];
15
+ readonly meter: readonly ["value", "min", "max", "low", "high", "optimum"];
16
+ readonly img: readonly ["alt", "width", "height", "loading", "decoding"];
17
+ readonly audio: readonly ["controls", "autoplay", "muted", "loop", "preload"];
18
+ readonly video: readonly ["controls", "autoplay", "muted", "loop", "preload", "width", "height", "playsinline"];
19
+ readonly source: readonly ["type", "media"];
20
+ readonly track: readonly ["kind", "srclang", "label", "default"];
21
+ readonly time: readonly ["datetime"];
22
+ };
23
+ export declare const opaqueSurfaceSafeInputTypes: readonly ["text", "search", "number", "checkbox", "radio", "button", "submit", "reset"];
24
+ export declare const opaqueSurfaceRenderLimits: {
25
+ readonly max_message_bytes: 262144;
26
+ readonly max_in_flight_requests: 256;
27
+ readonly max_renders_per_second: 30;
28
+ readonly max_render_depth: 32;
29
+ readonly max_render_nodes: 4096;
30
+ readonly max_attributes_per_element: 64;
31
+ readonly max_text_length: 65536;
32
+ readonly max_attribute_value_length: 4096;
33
+ readonly max_form_fields: 128;
34
+ };
@@ -0,0 +1,207 @@
1
+ // Code generated by scripts/generate_contract_registry.mjs; DO NOT EDIT.
2
+ export const opaqueSurfaceAllowedTags = [
3
+ "main",
4
+ "section",
5
+ "header",
6
+ "footer",
7
+ "nav",
8
+ "aside",
9
+ "article",
10
+ "div",
11
+ "span",
12
+ "p",
13
+ "h1",
14
+ "h2",
15
+ "h3",
16
+ "h4",
17
+ "h5",
18
+ "h6",
19
+ "button",
20
+ "input",
21
+ "textarea",
22
+ "select",
23
+ "option",
24
+ "label",
25
+ "fieldset",
26
+ "legend",
27
+ "form",
28
+ "ul",
29
+ "ol",
30
+ "li",
31
+ "dl",
32
+ "dt",
33
+ "dd",
34
+ "table",
35
+ "thead",
36
+ "tbody",
37
+ "tfoot",
38
+ "tr",
39
+ "th",
40
+ "td",
41
+ "caption",
42
+ "details",
43
+ "summary",
44
+ "pre",
45
+ "code",
46
+ "kbd",
47
+ "samp",
48
+ "strong",
49
+ "em",
50
+ "small",
51
+ "mark",
52
+ "time",
53
+ "progress",
54
+ "meter",
55
+ "img",
56
+ "picture",
57
+ "source",
58
+ "audio",
59
+ "video",
60
+ "track"
61
+ ];
62
+ export const opaqueSurfaceGlobalAttributes = [
63
+ "id",
64
+ "class",
65
+ "role",
66
+ "title",
67
+ "hidden",
68
+ "tabindex",
69
+ "lang",
70
+ "dir",
71
+ "data-redevplugin-action",
72
+ "data-redevplugin-asset-binding",
73
+ "data-redevplugin-asset-attr"
74
+ ];
75
+ export const opaqueSurfaceTagAttributes = {
76
+ "button": [
77
+ "type",
78
+ "name",
79
+ "value",
80
+ "disabled",
81
+ "aria-pressed",
82
+ "aria-expanded"
83
+ ],
84
+ "input": [
85
+ "type",
86
+ "name",
87
+ "value",
88
+ "checked",
89
+ "disabled",
90
+ "readonly",
91
+ "required",
92
+ "placeholder",
93
+ "min",
94
+ "max",
95
+ "step",
96
+ "autocomplete"
97
+ ],
98
+ "textarea": [
99
+ "name",
100
+ "disabled",
101
+ "readonly",
102
+ "required",
103
+ "placeholder",
104
+ "rows",
105
+ "cols",
106
+ "maxlength"
107
+ ],
108
+ "select": [
109
+ "name",
110
+ "disabled",
111
+ "required",
112
+ "multiple",
113
+ "size"
114
+ ],
115
+ "option": [
116
+ "value",
117
+ "selected",
118
+ "disabled",
119
+ "label"
120
+ ],
121
+ "label": [
122
+ "for"
123
+ ],
124
+ "form": [
125
+ "name",
126
+ "autocomplete"
127
+ ],
128
+ "th": [
129
+ "scope",
130
+ "colspan",
131
+ "rowspan"
132
+ ],
133
+ "td": [
134
+ "colspan",
135
+ "rowspan"
136
+ ],
137
+ "progress": [
138
+ "value",
139
+ "max"
140
+ ],
141
+ "meter": [
142
+ "value",
143
+ "min",
144
+ "max",
145
+ "low",
146
+ "high",
147
+ "optimum"
148
+ ],
149
+ "img": [
150
+ "alt",
151
+ "width",
152
+ "height",
153
+ "loading",
154
+ "decoding"
155
+ ],
156
+ "audio": [
157
+ "controls",
158
+ "autoplay",
159
+ "muted",
160
+ "loop",
161
+ "preload"
162
+ ],
163
+ "video": [
164
+ "controls",
165
+ "autoplay",
166
+ "muted",
167
+ "loop",
168
+ "preload",
169
+ "width",
170
+ "height",
171
+ "playsinline"
172
+ ],
173
+ "source": [
174
+ "type",
175
+ "media"
176
+ ],
177
+ "track": [
178
+ "kind",
179
+ "srclang",
180
+ "label",
181
+ "default"
182
+ ],
183
+ "time": [
184
+ "datetime"
185
+ ]
186
+ };
187
+ export const opaqueSurfaceSafeInputTypes = [
188
+ "text",
189
+ "search",
190
+ "number",
191
+ "checkbox",
192
+ "radio",
193
+ "button",
194
+ "submit",
195
+ "reset"
196
+ ];
197
+ export const opaqueSurfaceRenderLimits = {
198
+ "max_message_bytes": 262144,
199
+ "max_in_flight_requests": 256,
200
+ "max_renders_per_second": 30,
201
+ "max_render_depth": 32,
202
+ "max_render_nodes": 4096,
203
+ "max_attributes_per_element": 64,
204
+ "max_text_length": 65536,
205
+ "max_attribute_value_length": 4096,
206
+ "max_form_fields": 128
207
+ };