@pmate/cli 0.38.0 → 0.38.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.
package/README.md CHANGED
@@ -268,7 +268,7 @@ Meili's Host may pass `--actor-profile-id` with `PMATE_LOG_DELEGATE_TOKEN` in th
268
268
 
269
269
  ### Package a desktop app
270
270
 
271
- Packaged installers are automatically uploaded to Aliyun OSS (`parrot-static`), using the same credentials as Android APK releases. The completion output and build report include public download URLs, SHA-256 checksums, and a `release.json` URL. Configure `oss.public.region` and `aliyun.ak/sk` in your PMate configuration. Conflicting published versions require an app version bump. `--dir` produces local unpacked output only; `--dry-run` does not upload.
271
+ Packaged installers are automatically uploaded to Aliyun OSS (`parrot-static`), using the same credentials as Android APK releases. The completion output and build report include public download URLs, SHA-256 checksums, and a `release.json` URL. Configure `oss.public.region` and `aliyun.ak/sk` in your PMate configuration. Conflicting published versions require an app version bump. `--dir` produces local unpacked output only; `--dry-run` does not upload. The CLI owns publication after electron-builder completes; electron-builder itself runs without a publish provider.
272
272
 
273
273
  `pmate app build <ns:app> --target electron --config <file>` packages a native shell that loads its configured HTTPS origin directly, without building or embedding web resources, and produces macOS DMG/ZIP or Windows NSIS/ZIP artifacts. Packaged releases require a CLI login with admin permission in the app namespace; `--dir` and `--dry-run` stay local. The first build downloads pinned Electron and electron-builder versions. Current targets: macOS and Windows, `arm64` and `x64`; macOS packages require a macOS build host.
274
274
 
@@ -287,10 +287,13 @@ Config schema 2 (`icon` is relative to the config file; migrate schema 1 by remo
287
287
  "version": "0.1.0",
288
288
  "origin": "https://hello.pmate.chat",
289
289
  "authOrigins": ["https://auth.pmate.chat"],
290
+ "externalOrigins": ["https://github.com"],
290
291
  "icon": "desktop/icon.png"
291
292
  }
292
293
  ```
293
294
 
295
+ `externalOrigins` is optional. Links to these exact origins open in the system browser when initiated by the application document, even when the same origin is also allowed in `authOrigins`; isolated authentication windows continue navigating internally.
296
+
294
297
  Use `--dry-run` to inspect the plan, `--dir` for an unpacked `.app`, or `--signed` to require a configured macOS signing identity. Default builds are ad-hoc signed for local use; they are not notarized distribution releases. Signed builds use electron-builder's standard signing/notarization environment variables; verify notarization separately before distributing.
295
298
 
296
299
  The shell loads the deployed HTTPS website. Packaging requires only the desktop configuration, icon and native runtime dependencies: no frontend package manager, source tree or `dist` is needed. Web UI, business logic and compatible frontend bridge SDK changes ship through web deployment; the next open or user refresh receives them. Do not reload an active conversation or call automatically. Rebuild installers only when installed preload/main-process bridge code, native capabilities/permissions, or the Electron runtime must change. The first migration from an embedded renderer needs one new installer.
package/dist/index.js CHANGED
@@ -17597,6 +17597,8 @@ function readDesktopConfig(file, appId) {
17597
17597
  origin(c.origin);
17598
17598
  if (!Array.isArray(c.authOrigins)) throw new Error("authOrigins must be an array");
17599
17599
  c.authOrigins.forEach(origin);
17600
+ if (c.externalOrigins !== void 0 && !Array.isArray(c.externalOrigins)) throw new Error("externalOrigins must be an array");
17601
+ c.externalOrigins?.forEach(origin);
17600
17602
  if ("web" in c) throw new Error("Remote desktop builds do not accept web build configuration; remove web");
17601
17603
  return c;
17602
17604
  }
@@ -17625,7 +17627,7 @@ async function buildDesktop(args) {
17625
17627
  (0, import_node_fs19.mkdirSync)(appDir);
17626
17628
  const templateDir = import_node_path24.default.join(__dirname, "templates", "electron");
17627
17629
  (0, import_node_fs19.cpSync)(templateDir, appDir, { recursive: true });
17628
- (0, import_node_fs19.writeFileSync)(import_node_path24.default.join(appDir, "desktop-config.json"), JSON.stringify({ app: c.app, productName: c.productName, origin: c.origin, authOrigins: c.authOrigins, bundleId: c.bundleId }));
17630
+ (0, import_node_fs19.writeFileSync)(import_node_path24.default.join(appDir, "desktop-config.json"), JSON.stringify({ app: c.app, productName: c.productName, origin: c.origin, authOrigins: c.authOrigins, externalOrigins: c.externalOrigins ?? [], bundleId: c.bundleId }));
17629
17631
  (0, import_node_fs19.writeFileSync)(import_node_path24.default.join(appDir, "package.json"), JSON.stringify({ name: c.bundleId.replace(/\./g, "-"), version: c.version, description: `${c.productName} desktop application`, author: "PMate", main: "main.cjs", dependencies: { "@pmate/chat-sdk": "0.11.7" } }));
17630
17632
  await runBuildCommand(["npm", "install", "--omit=dev", "--no-audit", "--no-fund"], appDir);
17631
17633
  const cache = import_node_path24.default.join((0, import_node_os9.homedir)(), ".cache", "pmate", "electron", `${ELECTRON_VERSION}-${BUILDER_VERSION}`);
@@ -17649,7 +17651,7 @@ async function buildDesktop(args) {
17649
17651
  };
17650
17652
  const configPath = import_node_path24.default.join(staging, "builder.json");
17651
17653
  (0, import_node_fs19.writeFileSync)(configPath, JSON.stringify(builderConfig));
17652
- await runBuildCommand([process.execPath, import_node_path24.default.join(cache, "node_modules", "electron-builder", "cli.js"), "--config", configPath, args.platform === "mac" ? "--mac" : "--win", `--${args.arch}`, "--publish", "never"], appDir, { ...process.env, ...args.signed ? {} : { CSC_IDENTITY_AUTO_DISCOVERY: "false" } });
17654
+ await runBuildCommand([process.execPath, import_node_path24.default.join(cache, "node_modules", "electron-builder", "cli.js"), "--config", configPath, args.platform === "mac" ? "--mac" : "--win", `--${args.arch}`], appDir, { ...process.env, ...args.signed ? {} : { CSC_IDENTITY_AUTO_DISCOVERY: "false" } });
17653
17655
  const result = { ...plan, signature: args.signed ? args.platform === "mac" ? "configured-signing-required; verify notarization before distribution" : "configured-signing-required; verify Authenticode before distribution" : args.platform === "mac" ? "ad-hoc; local development" : "unsigned; local development", artifacts: import_node_path24.default.join(staging, "artifacts") };
17654
17656
  (0, import_node_fs19.writeFileSync)(import_node_path24.default.join(staging, "build-report.json"), JSON.stringify(result, null, 2));
17655
17657
  const publication = args.dir ? void 0 : await uploadDesktopArtifacts(result.artifacts, c.app, c.version, args.platform, args.arch);
@@ -7,31 +7,17 @@ const { createDesktopNotifications } = require('./notifications.cjs')
7
7
  const { desktopInstanceId, createDesktopReach } = require('./reach.cjs')
8
8
  const { createRendererReach } = require('./reach-renderer.cjs')
9
9
  const { createDesktopCalls, supportsDesktopCalls } = require('./calls.cjs')
10
+ const { installNavigationRestrictions } = require('./navigation.cjs')
10
11
  const config = require('./desktop-config.json')
11
12
  app.setName(config.productName)
12
13
  if (process.platform === 'win32') app.setAppUserModelId(config.bundleId)
13
14
  // Stable across installer versions; separate from every other packaged PMate app.
14
15
  app.setPath('userData', path.join(app.getPath('appData'), config.bundleId))
15
- const allowedNavigation = new Set([config.origin, ...config.authOrigins])
16
16
  let mainWindow
17
17
  let desktopNotifications, desktopReach, desktopCalls
18
- function isAllowed(raw) { try { return allowedNavigation.has(new URL(raw).origin) } catch { return false } }
19
- function external(raw) {
20
- try { if (['https:', 'http:', 'mailto:'].includes(new URL(raw).protocol)) void shell.openExternal(raw) } catch { /* Invalid links are not executable targets. */ }
21
- }
22
- function restrict(window) {
23
- window.webContents.on('will-navigate', (event, url) => { if (!isAllowed(url)) { event.preventDefault(); external(url) } })
24
- window.webContents.on('will-redirect', (event, url) => { if (!isAllowed(url)) event.preventDefault() })
25
- window.webContents.on('will-attach-webview', event => event.preventDefault())
26
- window.webContents.setWindowOpenHandler(({ url }) => {
27
- if (!isAllowed(url)) { external(url); return { action: 'deny' } }
28
- return { action: 'allow', overrideBrowserWindowOptions: { autoHideMenuBar: true, webPreferences: { session: window.webContents.session, nodeIntegration: false, contextIsolation: true, sandbox: true, webSecurity: true } } }
29
- })
30
- window.webContents.on('did-create-window', child => restrict(child))
31
- }
32
18
  function createWindow() {
33
19
  mainWindow = new BrowserWindow({ width: 1180, height: 820, minWidth: 380, minHeight: 540, title: config.productName, backgroundColor: '#f6f8fb', webPreferences: { additionalArguments: [`--pmate-app-version=${app.getVersion()}`, `--pmate-origin=${config.origin}`, `--pmate-desktop-calls=${supportsDesktopCalls(config.app)}`], preload: path.join(__dirname, 'preload.cjs'), partition: 'persist:desktop', nodeIntegration: false, contextIsolation: true, sandbox: true, webSecurity: true } })
34
- restrict(mainWindow)
20
+ installNavigationRestrictions(mainWindow, config, url => shell.openExternal(url))
35
21
  mainWindow.webContents.on('did-start-navigation', (_event, _url, _inPlace, mainFrame) => { if (mainFrame) desktopNotifications?.clearContext() })
36
22
  mainWindow.webContents.on('did-fail-load', (_event, code, _description, url, mainFrame) => {
37
23
  if (mainFrame && code !== -3 && url !== `${config.origin}/_desktop/offline`) void mainWindow.loadURL(`${config.origin}/_desktop/offline`).catch(error => console.error("Offline page failed:", error.message))
@@ -0,0 +1,27 @@
1
+ function origin(raw) {
2
+ try { return new URL(raw).origin } catch { return undefined }
3
+ }
4
+
5
+ function installNavigationRestrictions(window, config, openExternal) {
6
+ const allowedNavigation = new Set([config.origin, ...config.authOrigins])
7
+ const externalFromApp = new Set(config.externalOrigins || [])
8
+ const isAppDocument = () => origin(window.webContents.getURL()) === config.origin
9
+ const shouldOpenExternally = raw => isAppDocument() && externalFromApp.has(origin(raw))
10
+ const isAllowed = raw => allowedNavigation.has(origin(raw))
11
+ const external = raw => {
12
+ try { if (['https:', 'http:', 'mailto:'].includes(new URL(raw).protocol)) void openExternal(raw) } catch { /* Invalid links are not executable targets. */ }
13
+ }
14
+
15
+ window.webContents.on('will-navigate', (event, url) => {
16
+ if (shouldOpenExternally(url) || !isAllowed(url)) { event.preventDefault(); external(url) }
17
+ })
18
+ window.webContents.on('will-redirect', (event, url) => { if (shouldOpenExternally(url) || !isAllowed(url)) event.preventDefault() })
19
+ window.webContents.on('will-attach-webview', event => event.preventDefault())
20
+ window.webContents.setWindowOpenHandler(({ url }) => {
21
+ if (shouldOpenExternally(url) || !isAllowed(url)) { external(url); return { action: 'deny' } }
22
+ return { action: 'allow', overrideBrowserWindowOptions: { autoHideMenuBar: true, webPreferences: { session: window.webContents.session, nodeIntegration: false, contextIsolation: true, sandbox: true, webSecurity: true } } }
23
+ })
24
+ window.webContents.on('did-create-window', child => installNavigationRestrictions(child, config, openExternal))
25
+ }
26
+
27
+ module.exports = { installNavigationRestrictions }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pmate/cli",
3
- "version": "0.38.0",
3
+ "version": "0.38.2",
4
4
  "description": "CLI utilities for the pMate project",
5
5
  "license": "MIT",
6
6
  "bin": {