@aiot-nexus/plugin-sdk 2.1.1 → 3.1.0

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 (44) hide show
  1. package/README.md +197 -90
  2. package/dev-host/main.js +366 -505
  3. package/dist/.generated/plugin-framework-version.d.ts +1 -1
  4. package/dist/.generated/plugin-framework-version.js +1 -1
  5. package/dist/.generated/plugin-manifest.schema.json +3 -2
  6. package/dist/browser/frame-client.d.ts +1 -0
  7. package/dist/browser/frame-client.mjs +121 -13
  8. package/dist/src/browser/frame-client.d.ts +1 -0
  9. package/dist/src/browser/frame-client.js +121 -13
  10. package/dist/src/cli/run.js +81 -6
  11. package/dist/src/cli/update-notice.js +1 -1
  12. package/dist/src/dev.js +3 -3
  13. package/dist/src/{electron-facade.js → electron-namespaces.js} +2 -3
  14. package/dist/src/index.d.ts +2 -2
  15. package/dist/src/index.js +3 -3
  16. package/dist/src/nexus-dev-control.d.ts +1 -1
  17. package/dist/src/nexus-dev-control.js +2 -2
  18. package/dist/src/nexus-dev.d.ts +0 -3
  19. package/dist/src/nexus-dev.js +118 -53
  20. package/dist/src/scaffold.js +6 -5
  21. package/dist/src/sdk-info.d.ts +17 -0
  22. package/dist/src/sdk-info.js +23 -0
  23. package/dist/src/types.d.ts +15 -98
  24. package/dist/src/upgrade.d.ts +44 -0
  25. package/dist/src/upgrade.js +1189 -0
  26. package/dist/src/validation.js +9 -0
  27. package/package.json +2 -2
  28. package/scripts/sdk-update-check.js +1 -1
  29. package/templates/minimal/.vscode/launch.json +1 -1
  30. package/templates/minimal/README.md.tmpl +18 -17
  31. package/templates/minimal/src/main.ts.tmpl +5 -4
  32. package/templates/sqlite/.vscode/launch.json +1 -1
  33. package/templates/sqlite/README.md.tmpl +15 -13
  34. package/templates/sqlite/src/main.ts.tmpl +24 -20
  35. package/dev-host/plugin-host.js +0 -4
  36. package/dist/internal/src-electron/main/core/runtime-result.js +0 -42
  37. package/dist/internal/src-electron/main/plugins/plugin-electron-facade-broker.js +0 -890
  38. package/dist/internal/src-electron/plugin-host-bootstrap.js +0 -417
  39. package/dist/internal/src-electron/shared/contracts.js +0 -2
  40. package/dist/internal/src-electron/shared/plugin-electron-facade-client.js +0 -181
  41. package/dist/internal/src-electron/shared/plugin-electron-facade-descriptors.js +0 -70
  42. package/dist/internal/src-electron/shared/plugin-electron-facade.js +0 -243
  43. package/dist/internal/src-electron/shared/plugin-rpc.js +0 -245
  44. /package/dist/src/{electron-facade.d.ts → electron-namespaces.d.ts} +0 -0
@@ -1,4 +1,4 @@
1
- export declare const PLUGIN_FRAMEWORK_VERSION = "2.1.0";
1
+ export declare const PLUGIN_FRAMEWORK_VERSION = "3.1.0";
2
2
  export declare const PLUGIN_MANIFEST_SCHEMA_VERSION = 1;
3
3
  export declare const PLUGIN_COMPATIBLE_VERSION_PATTERN = "^(0|[1-9][0-9]*)(\\.(0|[1-9][0-9]*))?(\\.(0|[1-9][0-9]*))?$";
4
4
  export interface ParsedPluginVersion {
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isPluginFrameworkVersionCompatible = exports.comparePluginVersions = exports.parsePluginCompatibleVersion = exports.PLUGIN_COMPATIBLE_VERSION_PATTERN = exports.PLUGIN_MANIFEST_SCHEMA_VERSION = exports.PLUGIN_FRAMEWORK_VERSION = void 0;
4
- exports.PLUGIN_FRAMEWORK_VERSION = "2.1.0";
4
+ exports.PLUGIN_FRAMEWORK_VERSION = "3.1.0";
5
5
  exports.PLUGIN_MANIFEST_SCHEMA_VERSION = 1;
6
6
  exports.PLUGIN_COMPATIBLE_VERSION_PATTERN = "^(0|[1-9][0-9]*)(\\.(0|[1-9][0-9]*))?(\\.(0|[1-9][0-9]*))?$";
7
7
  function parsePluginCompatibleVersion(value) {
@@ -33,7 +33,7 @@
33
33
  "permissions": {
34
34
  "type": "array",
35
35
  "items": {
36
- "enum": ["businessLog", "settings", "filesystem", "udp", "serial", "externalProcess", "dialog", "electronHostControl"]
36
+ "enum": ["businessLog", "settings", "filesystem", "udp", "serial", "externalProcess", "dialog"]
37
37
  },
38
38
  "uniqueItems": true
39
39
  },
@@ -73,7 +73,8 @@
73
73
  "component": { "type": "string", "minLength": 1 },
74
74
  "pageRoute": { "type": "string", "minLength": 1 },
75
75
  "isFullBleed": { "type": "boolean" },
76
- "showBusinessLogToggle": { "type": "boolean" }
76
+ "showBusinessLogToggle": { "type": "boolean" },
77
+ "showHostStatusBar": { "type": "boolean" }
77
78
  }
78
79
  },
79
80
  "tool": {
@@ -7,6 +7,7 @@ export declare class PluginFrameClientError extends Error {
7
7
  export interface PluginFrameClientOptions {
8
8
  frameWindow?: Window;
9
9
  targetWindow?: Window;
10
+ initializationTimeoutMs?: number;
10
11
  requestTimeoutMs?: number;
11
12
  autoResize?: boolean;
12
13
  resizeRoot?: HTMLElement;
@@ -4,7 +4,7 @@ const readyMessageType = "nexus-plugin:ready";
4
4
  const requestMessageType = "nexus-plugin:request";
5
5
  const responseMessageType = "nexus-plugin:response";
6
6
  const resizeMessageType = "nexus-plugin:resize";
7
- const defaultRequestTimeoutMs = 20000;
7
+ const defaultInitializationTimeoutMs = 20000;
8
8
  export class PluginFrameClientError extends Error {
9
9
  constructor(code, message) {
10
10
  super(message);
@@ -19,9 +19,13 @@ export function createPluginFrameClient(options = {}) {
19
19
  }
20
20
  const frameWindow = resolvedFrameWindow;
21
21
  const targetWindow = options.targetWindow || frameWindow.parent;
22
- const requestTimeoutMs = options.requestTimeoutMs === undefined ? defaultRequestTimeoutMs : options.requestTimeoutMs;
23
- if (!Number.isFinite(requestTimeoutMs) || requestTimeoutMs <= 0) {
24
- throw new PluginFrameClientError("ProtocolError", "requestTimeoutMs must be a positive finite number.");
22
+ const initializationTimeoutMs = options.initializationTimeoutMs === undefined ? defaultInitializationTimeoutMs : options.initializationTimeoutMs;
23
+ const requestTimeoutMs = options.requestTimeoutMs === undefined ? 0 : options.requestTimeoutMs;
24
+ if (!Number.isFinite(initializationTimeoutMs) || initializationTimeoutMs <= 0) {
25
+ throw new PluginFrameClientError("ProtocolError", "initializationTimeoutMs must be a positive finite number.");
26
+ }
27
+ if (!Number.isFinite(requestTimeoutMs) || requestTimeoutMs < 0) {
28
+ throw new PluginFrameClientError("ProtocolError", "requestTimeoutMs must be zero or a positive finite number.");
25
29
  }
26
30
  let requestSequence = 0;
27
31
  let disposed = false;
@@ -46,7 +50,7 @@ export function createPluginFrameClient(options = {}) {
46
50
  contextSettled = true;
47
51
  rejectContext(new PluginFrameClientError("RequestTimeout", "PluginFrame initialization timed out."));
48
52
  }
49
- }, requestTimeoutMs);
53
+ }, initializationTimeoutMs);
50
54
  frameWindow.addEventListener("message", handleMessage);
51
55
  if (options.autoResize !== false) {
52
56
  frameWindow.addEventListener("resize", scheduleResize);
@@ -80,16 +84,18 @@ export function createPluginFrameClient(options = {}) {
80
84
  }
81
85
  const requestId = "nexus-sdk-" + Date.now() + "-" + (++requestSequence);
82
86
  return new Promise((resolve, reject) => {
83
- const timeoutId = frameWindow.setTimeout(() => {
84
- pendingRequests.delete(requestId);
85
- reject(new PluginFrameClientError("RequestTimeout", "PluginFrame request timed out: " + method));
86
- }, requestTimeoutMs);
87
+ const timeoutId = requestTimeoutMs > 0
88
+ ? frameWindow.setTimeout(() => {
89
+ pendingRequests.delete(requestId);
90
+ reject(new PluginFrameClientError("RequestTimeout", "PluginFrame request timed out: " + method));
91
+ }, requestTimeoutMs)
92
+ : undefined;
87
93
  pendingRequests.set(requestId, {
88
94
  resolve: (result) => resolve(result),
89
95
  reject,
90
96
  timeoutId
91
97
  });
92
- post({ type: requestMessageType, requestId, method, params });
98
+ post({ type: requestMessageType, requestId, method, params: encodeFrameValue(params) });
93
99
  });
94
100
  }
95
101
  function getSettings() {
@@ -140,12 +146,14 @@ export function createPluginFrameClient(options = {}) {
140
146
  return;
141
147
  }
142
148
  pendingRequests.delete(event.data.requestId);
143
- frameWindow.clearTimeout(pending.timeoutId);
149
+ if (pending.timeoutId !== undefined) {
150
+ frameWindow.clearTimeout(pending.timeoutId);
151
+ }
144
152
  if (!isNexusResult(event.data.result)) {
145
153
  pending.reject(new PluginFrameClientError("ProtocolError", "PluginFrame response is malformed."));
146
154
  return;
147
155
  }
148
- pending.resolve(event.data.result);
156
+ pending.resolve(decodeFrameResult(event.data.result));
149
157
  }
150
158
  function notifyContextChanged(context) {
151
159
  for (const listener of Array.from(contextListeners)) {
@@ -202,7 +210,9 @@ export function createPluginFrameClient(options = {}) {
202
210
  rejectContext(error);
203
211
  }
204
212
  for (const pending of pendingRequests.values()) {
205
- frameWindow.clearTimeout(pending.timeoutId);
213
+ if (pending.timeoutId !== undefined) {
214
+ frameWindow.clearTimeout(pending.timeoutId);
215
+ }
206
216
  pending.reject(error);
207
217
  }
208
218
  pendingRequests.clear();
@@ -237,3 +247,101 @@ function isNexusResult(value) {
237
247
  }
238
248
  return isRecord(value.error) && typeof value.error.code === "string" && typeof value.error.message === "string";
239
249
  }
250
+ function encodeFrameValue(value, seen = new WeakSet()) {
251
+ if (value === undefined) {
252
+ return { __nexusWire: "undefined" };
253
+ }
254
+ if (value === null || typeof value === "string" || typeof value === "boolean") {
255
+ return value;
256
+ }
257
+ if (typeof value === "number") {
258
+ return Number.isFinite(value) ? value : null;
259
+ }
260
+ if (typeof value === "bigint") {
261
+ return { __nexusWire: "bigint", value: value.toString(10) };
262
+ }
263
+ if (value instanceof Date) {
264
+ return { __nexusWire: "date", value: value.toISOString() };
265
+ }
266
+ if (value instanceof Error) {
267
+ return { __nexusWire: "error", name: value.name, message: value.message, stack: value.stack };
268
+ }
269
+ if (value instanceof Uint8Array) {
270
+ return { __nexusWire: "buffer", value: bytesToHex(value) };
271
+ }
272
+ if (typeof value !== "object" || seen.has(value)) {
273
+ return null;
274
+ }
275
+ seen.add(value);
276
+ try {
277
+ if (Array.isArray(value)) {
278
+ return value.map((item) => encodeFrameValue(item, seen));
279
+ }
280
+ const encoded = Object.fromEntries(Object.entries(value).map(([key, item]) => [key, encodeFrameValue(item, seen)]));
281
+ return Object.prototype.hasOwnProperty.call(value, "__nexusWire")
282
+ ? { __nexusWire: "object", value: encoded }
283
+ : encoded;
284
+ }
285
+ finally {
286
+ seen.delete(value);
287
+ }
288
+ }
289
+ function decodeFrameResult(result) {
290
+ return result.ok
291
+ ? { ok: true, value: decodeFrameValue(result.value) }
292
+ : { ok: false, error: { ...result.error, details: decodeFrameValue(result.error.details) } };
293
+ }
294
+ function decodeFrameValue(value) {
295
+ if (value === null || typeof value !== "object") {
296
+ return value;
297
+ }
298
+ const record = value;
299
+ if (record.__nexusWire === "undefined") {
300
+ return undefined;
301
+ }
302
+ if (record.__nexusWire === "bigint" && typeof record.value === "string") {
303
+ try {
304
+ return BigInt(record.value);
305
+ }
306
+ catch {
307
+ return null;
308
+ }
309
+ }
310
+ if (record.__nexusWire === "date" && typeof record.value === "string") {
311
+ const date = new Date(record.value);
312
+ return Number.isNaN(date.getTime()) ? null : date;
313
+ }
314
+ if (record.__nexusWire === "buffer" && typeof record.value === "string") {
315
+ return hexToUint8Array(record.value);
316
+ }
317
+ if (record.__nexusWire === "error" && typeof record.message === "string") {
318
+ const error = new Error(record.message);
319
+ if (typeof record.name === "string") {
320
+ error.name = record.name;
321
+ }
322
+ if (typeof record.stack === "string") {
323
+ error.stack = record.stack;
324
+ }
325
+ return error;
326
+ }
327
+ if (record.__nexusWire === "object" && isRecord(record.value)) {
328
+ return decodeFrameValue(record.value);
329
+ }
330
+ if (Array.isArray(value)) {
331
+ return value.map((item) => decodeFrameValue(item));
332
+ }
333
+ return Object.fromEntries(Object.entries(record).map(([key, item]) => [key, decodeFrameValue(item)]));
334
+ }
335
+ function bytesToHex(bytes) {
336
+ return Array.from(bytes).map((byte) => byte.toString(16).padStart(2, "0")).join("");
337
+ }
338
+ function hexToUint8Array(value) {
339
+ if (value.length % 2 !== 0 || !/^[0-9a-f]*$/i.test(value)) {
340
+ return null;
341
+ }
342
+ const bytes = new Uint8Array(value.length / 2);
343
+ for (let index = 0; index < bytes.length; index += 1) {
344
+ bytes[index] = Number.parseInt(value.slice(index * 2, index * 2 + 2), 16);
345
+ }
346
+ return bytes;
347
+ }
@@ -7,6 +7,7 @@ export declare class PluginFrameClientError extends Error {
7
7
  export interface PluginFrameClientOptions {
8
8
  frameWindow?: Window;
9
9
  targetWindow?: Window;
10
+ initializationTimeoutMs?: number;
10
11
  requestTimeoutMs?: number;
11
12
  autoResize?: boolean;
12
13
  resizeRoot?: HTMLElement;
@@ -7,7 +7,7 @@ const readyMessageType = "nexus-plugin:ready";
7
7
  const requestMessageType = "nexus-plugin:request";
8
8
  const responseMessageType = "nexus-plugin:response";
9
9
  const resizeMessageType = "nexus-plugin:resize";
10
- const defaultRequestTimeoutMs = 20000;
10
+ const defaultInitializationTimeoutMs = 20000;
11
11
  class PluginFrameClientError extends Error {
12
12
  constructor(code, message) {
13
13
  super(message);
@@ -23,9 +23,13 @@ function createPluginFrameClient(options = {}) {
23
23
  }
24
24
  const frameWindow = resolvedFrameWindow;
25
25
  const targetWindow = options.targetWindow || frameWindow.parent;
26
- const requestTimeoutMs = options.requestTimeoutMs === undefined ? defaultRequestTimeoutMs : options.requestTimeoutMs;
27
- if (!Number.isFinite(requestTimeoutMs) || requestTimeoutMs <= 0) {
28
- throw new PluginFrameClientError("ProtocolError", "requestTimeoutMs must be a positive finite number.");
26
+ const initializationTimeoutMs = options.initializationTimeoutMs === undefined ? defaultInitializationTimeoutMs : options.initializationTimeoutMs;
27
+ const requestTimeoutMs = options.requestTimeoutMs === undefined ? 0 : options.requestTimeoutMs;
28
+ if (!Number.isFinite(initializationTimeoutMs) || initializationTimeoutMs <= 0) {
29
+ throw new PluginFrameClientError("ProtocolError", "initializationTimeoutMs must be a positive finite number.");
30
+ }
31
+ if (!Number.isFinite(requestTimeoutMs) || requestTimeoutMs < 0) {
32
+ throw new PluginFrameClientError("ProtocolError", "requestTimeoutMs must be zero or a positive finite number.");
29
33
  }
30
34
  let requestSequence = 0;
31
35
  let disposed = false;
@@ -50,7 +54,7 @@ function createPluginFrameClient(options = {}) {
50
54
  contextSettled = true;
51
55
  rejectContext(new PluginFrameClientError("RequestTimeout", "PluginFrame initialization timed out."));
52
56
  }
53
- }, requestTimeoutMs);
57
+ }, initializationTimeoutMs);
54
58
  frameWindow.addEventListener("message", handleMessage);
55
59
  if (options.autoResize !== false) {
56
60
  frameWindow.addEventListener("resize", scheduleResize);
@@ -84,16 +88,18 @@ function createPluginFrameClient(options = {}) {
84
88
  }
85
89
  const requestId = "nexus-sdk-" + Date.now() + "-" + (++requestSequence);
86
90
  return new Promise((resolve, reject) => {
87
- const timeoutId = frameWindow.setTimeout(() => {
88
- pendingRequests.delete(requestId);
89
- reject(new PluginFrameClientError("RequestTimeout", "PluginFrame request timed out: " + method));
90
- }, requestTimeoutMs);
91
+ const timeoutId = requestTimeoutMs > 0
92
+ ? frameWindow.setTimeout(() => {
93
+ pendingRequests.delete(requestId);
94
+ reject(new PluginFrameClientError("RequestTimeout", "PluginFrame request timed out: " + method));
95
+ }, requestTimeoutMs)
96
+ : undefined;
91
97
  pendingRequests.set(requestId, {
92
98
  resolve: (result) => resolve(result),
93
99
  reject,
94
100
  timeoutId
95
101
  });
96
- post({ type: requestMessageType, requestId, method, params });
102
+ post({ type: requestMessageType, requestId, method, params: encodeFrameValue(params) });
97
103
  });
98
104
  }
99
105
  function getSettings() {
@@ -144,12 +150,14 @@ function createPluginFrameClient(options = {}) {
144
150
  return;
145
151
  }
146
152
  pendingRequests.delete(event.data.requestId);
147
- frameWindow.clearTimeout(pending.timeoutId);
153
+ if (pending.timeoutId !== undefined) {
154
+ frameWindow.clearTimeout(pending.timeoutId);
155
+ }
148
156
  if (!isNexusResult(event.data.result)) {
149
157
  pending.reject(new PluginFrameClientError("ProtocolError", "PluginFrame response is malformed."));
150
158
  return;
151
159
  }
152
- pending.resolve(event.data.result);
160
+ pending.resolve(decodeFrameResult(event.data.result));
153
161
  }
154
162
  function notifyContextChanged(context) {
155
163
  for (const listener of Array.from(contextListeners)) {
@@ -206,7 +214,9 @@ function createPluginFrameClient(options = {}) {
206
214
  rejectContext(error);
207
215
  }
208
216
  for (const pending of pendingRequests.values()) {
209
- frameWindow.clearTimeout(pending.timeoutId);
217
+ if (pending.timeoutId !== undefined) {
218
+ frameWindow.clearTimeout(pending.timeoutId);
219
+ }
210
220
  pending.reject(error);
211
221
  }
212
222
  pendingRequests.clear();
@@ -242,3 +252,101 @@ function isNexusResult(value) {
242
252
  }
243
253
  return isRecord(value.error) && typeof value.error.code === "string" && typeof value.error.message === "string";
244
254
  }
255
+ function encodeFrameValue(value, seen = new WeakSet()) {
256
+ if (value === undefined) {
257
+ return { __nexusWire: "undefined" };
258
+ }
259
+ if (value === null || typeof value === "string" || typeof value === "boolean") {
260
+ return value;
261
+ }
262
+ if (typeof value === "number") {
263
+ return Number.isFinite(value) ? value : null;
264
+ }
265
+ if (typeof value === "bigint") {
266
+ return { __nexusWire: "bigint", value: value.toString(10) };
267
+ }
268
+ if (value instanceof Date) {
269
+ return { __nexusWire: "date", value: value.toISOString() };
270
+ }
271
+ if (value instanceof Error) {
272
+ return { __nexusWire: "error", name: value.name, message: value.message, stack: value.stack };
273
+ }
274
+ if (value instanceof Uint8Array) {
275
+ return { __nexusWire: "buffer", value: bytesToHex(value) };
276
+ }
277
+ if (typeof value !== "object" || seen.has(value)) {
278
+ return null;
279
+ }
280
+ seen.add(value);
281
+ try {
282
+ if (Array.isArray(value)) {
283
+ return value.map((item) => encodeFrameValue(item, seen));
284
+ }
285
+ const encoded = Object.fromEntries(Object.entries(value).map(([key, item]) => [key, encodeFrameValue(item, seen)]));
286
+ return Object.prototype.hasOwnProperty.call(value, "__nexusWire")
287
+ ? { __nexusWire: "object", value: encoded }
288
+ : encoded;
289
+ }
290
+ finally {
291
+ seen.delete(value);
292
+ }
293
+ }
294
+ function decodeFrameResult(result) {
295
+ return result.ok
296
+ ? { ok: true, value: decodeFrameValue(result.value) }
297
+ : { ok: false, error: { ...result.error, details: decodeFrameValue(result.error.details) } };
298
+ }
299
+ function decodeFrameValue(value) {
300
+ if (value === null || typeof value !== "object") {
301
+ return value;
302
+ }
303
+ const record = value;
304
+ if (record.__nexusWire === "undefined") {
305
+ return undefined;
306
+ }
307
+ if (record.__nexusWire === "bigint" && typeof record.value === "string") {
308
+ try {
309
+ return BigInt(record.value);
310
+ }
311
+ catch {
312
+ return null;
313
+ }
314
+ }
315
+ if (record.__nexusWire === "date" && typeof record.value === "string") {
316
+ const date = new Date(record.value);
317
+ return Number.isNaN(date.getTime()) ? null : date;
318
+ }
319
+ if (record.__nexusWire === "buffer" && typeof record.value === "string") {
320
+ return hexToUint8Array(record.value);
321
+ }
322
+ if (record.__nexusWire === "error" && typeof record.message === "string") {
323
+ const error = new Error(record.message);
324
+ if (typeof record.name === "string") {
325
+ error.name = record.name;
326
+ }
327
+ if (typeof record.stack === "string") {
328
+ error.stack = record.stack;
329
+ }
330
+ return error;
331
+ }
332
+ if (record.__nexusWire === "object" && isRecord(record.value)) {
333
+ return decodeFrameValue(record.value);
334
+ }
335
+ if (Array.isArray(value)) {
336
+ return value.map((item) => decodeFrameValue(item));
337
+ }
338
+ return Object.fromEntries(Object.entries(record).map(([key, item]) => [key, decodeFrameValue(item)]));
339
+ }
340
+ function bytesToHex(bytes) {
341
+ return Array.from(bytes).map((byte) => byte.toString(16).padStart(2, "0")).join("");
342
+ }
343
+ function hexToUint8Array(value) {
344
+ if (value.length % 2 !== 0 || !/^[0-9a-f]*$/i.test(value)) {
345
+ return null;
346
+ }
347
+ const bytes = new Uint8Array(value.length / 2);
348
+ for (let index = 0; index < bytes.length; index += 1) {
349
+ bytes[index] = Number.parseInt(value.slice(index * 2, index * 2 + 2), 16);
350
+ }
351
+ return bytes;
352
+ }
@@ -30,7 +30,7 @@ const scaffold_1 = require("../scaffold");
30
30
  const dev_1 = require("../dev");
31
31
  const web_dev_1 = require("../web-dev");
32
32
  const nexus_dev_1 = require("../nexus-dev");
33
- const nodeEngine = ">=16.20.0 <17";
33
+ const upgrade_1 = require("../upgrade");
34
34
  function runCli(args, io) {
35
35
  const command = args[0];
36
36
  if (command === "--help" || command === "-h") {
@@ -38,14 +38,21 @@ function runCli(args, io) {
38
38
  return 0;
39
39
  }
40
40
  if (command === "info") {
41
+ if (args.length === 2 && args[1] === "--json") {
42
+ io.stdout(JSON.stringify((0, index_1.getPluginSdkInfo)(), null, 2));
43
+ return 0;
44
+ }
41
45
  if (args.length !== 1) {
42
- return usageError(io, "info does not accept arguments.");
46
+ return usageError(io, "info only accepts --json.");
43
47
  }
44
48
  io.stdout([
45
49
  "SDK version: " + index_1.PLUGIN_SDK_VERSION,
46
50
  "Plugin Framework API: " + index_1.PLUGIN_FRAMEWORK_VERSION,
47
51
  "Manifest schema: " + index_1.PLUGIN_MANIFEST_SCHEMA_VERSION,
48
- "Node engine: " + nodeEngine
52
+ "Node engine: " + index_1.PLUGIN_SDK_NODE_ENGINE,
53
+ "npm engine: " + index_1.PLUGIN_SDK_NPM_ENGINE,
54
+ "Electron: " + index_1.PLUGIN_SDK_ELECTRON_VERSION,
55
+ "TypeScript: " + index_1.PLUGIN_SDK_TYPESCRIPT_VERSION
49
56
  ].join("\n"));
50
57
  return 0;
51
58
  }
@@ -65,6 +72,9 @@ function runCli(args, io) {
65
72
  if (command === "create") {
66
73
  return runCreate(args.slice(1), io);
67
74
  }
75
+ if (command === "upgrade") {
76
+ return runUpgrade(args.slice(1), io);
77
+ }
68
78
  if (command === "dev") {
69
79
  return runDev(args.slice(1), io);
70
80
  }
@@ -80,10 +90,12 @@ exports.runCli = runCli;
80
90
  function usage() {
81
91
  return [
82
92
  "Usage:",
83
- " nexus-plugin info",
93
+ " nexus-plugin info [--json]",
84
94
  " nexus-plugin validate <plugin-package-directory>",
85
95
  " nexus-plugin create <plugin-id> [--template minimal|sqlite] [--output <parent-directory>]",
86
96
  " [--display-name <name>] [--sdk-source <version-or-local-tgz>] [--install]",
97
+ " nexus-plugin upgrade [plugin-project-directory] [--check] [--sdk-source <version-or-local-tgz>]",
98
+ " [--allow-major] [--skip-project-checks] [--json]",
87
99
  " nexus-plugin dev [plugin-project-directory] [--no-build] [--inspect[=<port>] | --inspect-brk[=<port>]]",
88
100
  " [--host-version <X.Y.Z>] [--language <culture>] [--theme system|light|dark] [--surface business|tool|settings]",
89
101
  " [--contribution-id <id>] [--no-devtools]",
@@ -97,6 +109,69 @@ function usage() {
97
109
  ].join("\n");
98
110
  }
99
111
  exports.usage = usage;
112
+ function runUpgrade(args, io) {
113
+ if (args.length === 1 && (args[0] === "--help" || args[0] === "-h")) {
114
+ io.stdout(usage());
115
+ return 0;
116
+ }
117
+ let projectDirectory = io.cwd();
118
+ let index = 0;
119
+ if (args[0] && !args[0].startsWith("--")) {
120
+ projectDirectory = path.resolve(io.cwd(), args[0]);
121
+ index = 1;
122
+ }
123
+ let sdkSource;
124
+ let checkOnly = false;
125
+ let allowMajor = false;
126
+ let skipProjectChecks = false;
127
+ let json = false;
128
+ const seen = new Set();
129
+ for (; index < args.length; index += 1) {
130
+ const option = args[index];
131
+ if (["--check", "--allow-major", "--skip-project-checks", "--json"].includes(option)) {
132
+ if (seen.has(option)) {
133
+ return usageError(io, "Duplicate option: " + option);
134
+ }
135
+ seen.add(option);
136
+ if (option === "--check") {
137
+ checkOnly = true;
138
+ }
139
+ else if (option === "--allow-major") {
140
+ allowMajor = true;
141
+ }
142
+ else if (option === "--skip-project-checks") {
143
+ skipProjectChecks = true;
144
+ }
145
+ else {
146
+ json = true;
147
+ }
148
+ continue;
149
+ }
150
+ if (option !== "--sdk-source") {
151
+ return usageError(io, "Unknown upgrade option: " + option);
152
+ }
153
+ if (seen.has(option)) {
154
+ return usageError(io, "Duplicate option: " + option);
155
+ }
156
+ seen.add(option);
157
+ const value = args[index + 1];
158
+ if (value === undefined || value.startsWith("--")) {
159
+ return usageError(io, option + " requires a value.");
160
+ }
161
+ sdkSource = value;
162
+ index += 1;
163
+ }
164
+ const result = (0, upgrade_1.runPluginSdkUpgrade)({
165
+ projectDirectory,
166
+ workingDirectory: io.cwd(),
167
+ sdkSource,
168
+ checkOnly,
169
+ allowMajor,
170
+ skipProjectChecks
171
+ });
172
+ io.stdout(json ? JSON.stringify(result, null, 2) : (0, upgrade_1.formatPluginSdkUpgradeResult)(result));
173
+ return result.status === "blocked" || result.status === "rolled-back" ? 1 : 0;
174
+ }
100
175
  function runNexusDev(args, io) {
101
176
  if (args.length === 1 && (args[0] === "--help" || args[0] === "-h")) {
102
177
  io.stdout(usage());
@@ -126,7 +201,7 @@ function runNexusDev(args, io) {
126
201
  const inspector = parseInspectorOption(option);
127
202
  if (inspector) {
128
203
  if (options.inspectorMode) {
129
- return usageError(io, "Only one plugin worker inspector option can be used.");
204
+ return usageError(io, "Only one plugin main-process inspector option can be used.");
130
205
  }
131
206
  const key = "--" + inspector.mode;
132
207
  if (seen.has(key)) {
@@ -304,7 +379,7 @@ function runDev(args, io) {
304
379
  const inspector = parseInspectorOption(option);
305
380
  if (inspector) {
306
381
  if (options.inspectorMode) {
307
- return usageError(io, "Only one plugin worker inspector option can be used.");
382
+ return usageError(io, "Only one plugin main-process inspector option can be used.");
308
383
  }
309
384
  const key = "--" + inspector.mode;
310
385
  if (seen.has(key)) {
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.showSdkUpdateNotice = void 0;
4
4
  function showSdkUpdateNotice(args, stdout, updateCheck, currentVersion) {
5
- if (args.includes("--help") || args.includes("-h") || updateCheck.isDisabled(process.env)) {
5
+ if (args.includes("--help") || args.includes("-h") || args.includes("--json") || updateCheck.isDisabled(process.env)) {
6
6
  return;
7
7
  }
8
8
  const cached = updateCheck.readCachedSdkUpdate({ currentVersion });
package/dist/src/dev.js CHANGED
@@ -52,14 +52,14 @@ function runPluginDev(options, io) {
52
52
  + "\nContribution: " + target.surface + ":" + target.contributionId
53
53
  + "\nSimulated Nexus application version: " + target.hostVersion);
54
54
  if (options.inspectorMode) {
55
- io.stdout("Plugin worker debugger: " + options.inspectorMode
55
+ io.stdout("Plugin main-process debugger: " + options.inspectorMode
56
56
  + " on 127.0.0.1:" + String(options.inspectorPort || 9229));
57
57
  }
58
58
  const electronArgs = [];
59
- electronArgs.push(target.devHostMainPath, "--plugin-package=" + target.packageDirectory, "--project-directory=" + target.projectDirectory, "--surface=" + target.surface, "--contribution-id=" + target.contributionId, "--language=" + target.language, "--theme=" + target.themeMode, "--host-version=" + target.hostVersion);
60
59
  if (options.inspectorMode) {
61
- electronArgs.push("--worker-inspector=" + options.inspectorMode + ":" + String(options.inspectorPort || 9229));
60
+ electronArgs.push("--" + options.inspectorMode + "=" + String(options.inspectorPort || 9229));
62
61
  }
62
+ electronArgs.push(target.devHostMainPath, "--plugin-package=" + target.packageDirectory, "--project-directory=" + target.projectDirectory, "--surface=" + target.surface, "--contribution-id=" + target.contributionId, "--language=" + target.language, "--theme=" + target.themeMode, "--host-version=" + target.hostVersion);
63
63
  if (!options.openDevTools) {
64
64
  electronArgs.push("--no-devtools");
65
65
  }
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isPluginElectronProtocolScheme = exports.isPluginElectronIpcChannel = exports.createPluginElectronProtocolScheme = exports.createPluginElectronIpcChannel = void 0;
4
4
  const ipcPrefix = "nexus-plugin:";
5
5
  const protocolPrefix = "nexus-plugin-";
6
- const pluginIdPattern = /^[a-z0-9][a-z0-9._-]{0,63}$/;
6
+ const pluginIdPattern = /^[a-z0-9][a-z0-9._-]{1,63}$/;
7
7
  const channelPattern = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,119}$/;
8
8
  const schemePattern = /^[a-z][a-z0-9+.-]{0,62}$/;
9
9
  function createPluginElectronIpcChannel(pluginId, channel) {
@@ -44,8 +44,7 @@ function requirePluginId(value) {
44
44
  return normalized;
45
45
  }
46
46
  function normalizePluginId(value) {
47
- const normalized = typeof value === "string" ? value.trim() : "";
48
- return pluginIdPattern.test(normalized) ? normalized : undefined;
47
+ return typeof value === "string" && pluginIdPattern.test(value) ? value : undefined;
49
48
  }
50
49
  function requireLogicalName(value, pattern, label) {
51
50
  const normalized = String(value).trim();
@@ -1,8 +1,8 @@
1
1
  import pluginManifestSchema from "../.generated/plugin-manifest.schema.json";
2
- export declare const PLUGIN_SDK_VERSION = "2.1.1";
3
2
  export { pluginManifestSchema };
4
3
  export * from "../.generated/plugin-framework-version";
4
+ export * from "./sdk-info";
5
5
  export * from "./types";
6
- export * from "./electron-facade";
6
+ export * from "./electron-namespaces";
7
7
  export * from "./browser/frame-client";
8
8
  export * from "./validation";
package/dist/src/index.js CHANGED
@@ -17,12 +17,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.pluginManifestSchema = exports.PLUGIN_SDK_VERSION = void 0;
20
+ exports.pluginManifestSchema = void 0;
21
21
  const plugin_manifest_schema_json_1 = __importDefault(require("../.generated/plugin-manifest.schema.json"));
22
22
  exports.pluginManifestSchema = plugin_manifest_schema_json_1.default;
23
- exports.PLUGIN_SDK_VERSION = "2.1.1";
24
23
  __exportStar(require("../.generated/plugin-framework-version"), exports);
24
+ __exportStar(require("./sdk-info"), exports);
25
25
  __exportStar(require("./types"), exports);
26
- __exportStar(require("./electron-facade"), exports);
26
+ __exportStar(require("./electron-namespaces"), exports);
27
27
  __exportStar(require("./browser/frame-client"), exports);
28
28
  __exportStar(require("./validation"), exports);
@@ -1,4 +1,4 @@
1
- export type NexusDevUpdateType = "rendererUpdated" | "manifestUpdated" | "packageUpdatePreparing" | "packageUpdated";
1
+ export type NexusDevUpdateType = "hostReady" | "rendererUpdated" | "manifestUpdated";
2
2
  export interface NexusDevUpdateResult {
3
3
  ok: boolean;
4
4
  message: string;