@wix/himalaya-cli 0.991.0 → 0.993.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.
@@ -0,0 +1,58 @@
1
+ /** Which hosts a WIX-SCOPED dev-server request may be sent to.
2
+ *
3
+ * The dev-server does not merely forward these requests — it ATTACHES CREDENTIALS to them:
4
+ * a minted anonymous visitor token, a signed-in member token, the developer's `wixSession2`
5
+ * cookie. So the destination is not a detail. A wix-scoped request to any other host is those
6
+ * credentials leaving for that host, from a server that binds `0.0.0.0` (it has to, to serve
7
+ * simulators and physical devices) with no auth in front of it.
8
+ *
9
+ * The serve plane states the same rule for its own bridge — `core/serve-runtime/src/wix-bridge.ts`
10
+ * is "host-locked to www.wixapis.com — absolute URLs are rejected (no open proxy)". The
11
+ * dev-server needs the ALLOWLIST form rather than that outright rejection, because absolute
12
+ * URLs to other first-party hosts are a real, tested capability here: `users.wix.com` for
13
+ * identity, `apps`/`bo`/`manage`/`support`/`www`.wix.com elsewhere in this package, and
14
+ * `chat.nownia.com` for the Orion/Genie assistant — `orion-chat`'s `createConversation` sends
15
+ * an absolute url there through `wixApi.call`, whose own comment records the contract
16
+ * ("forwards this absolute, non-*.wix.com URL untouched"). Rejecting every absolute URL the way
17
+ * the serve plane does would break both that and
18
+ * "webWixCall preserves absolute Wix URLs for users.wix.com calls".
19
+ *
20
+ * THE LIST IS NOT INVENTED HERE. It mirrors `WixRequestPolicyRules.isFirstPartyWixHost`, which
21
+ * both natives already implement identically — `core/runtime/ios/HimalayaCore/Sources/
22
+ * HimalayaCore/WixRequestPolicy.swift` and the Kotlin twin under `core/runtime/android`. That is
23
+ * the platform's definition of "first party", so the web/dev arm has no business holding a
24
+ * narrower one: a host the device may call is a host this bridge may call. `wix-hosts.test.ts`
25
+ * pins the two together, so a root added natively cannot silently leave this arm behind — which
26
+ * is exactly how `nownia.com` was missed the first time (codebot review on #3120).
27
+ *
28
+ * PARSED, NEVER STRING-MATCHED. `apps/himi-owner-lite/dev/net-mocks.ts` records three spellings
29
+ * that defeated an earlier host parse in this repo, and all three are why this reads
30
+ * `new URL(...).hostname` instead of testing the raw text:
31
+ *
32
+ * `https://www.wixapis.com@evil.example/x` userinfo — the host is `evil.example`, and a
33
+ * `startsWith`/`includes` test says "wixapis".
34
+ * `https://www.wix.com\@evil.example/x` a backslash ENDS THE AUTHORITY for http(s), so
35
+ * the host really is `www.wix.com` and that is
36
+ * really where the request goes — a hand-rolled
37
+ * parser that splits on `/` disagrees.
38
+ * `https:///x` an empty authority yields no host at all.
39
+ *
40
+ * Judging the PARSED host cannot disagree with the connection that gets made, because `fetch`
41
+ * resolves the same string through the same WHATWG parser. A regex over the text can, and that
42
+ * divergence is the whole bug class.
43
+ *
44
+ * This is a destination check, NOT an SSRF guard in the `net-guard.ts` sense: it does not
45
+ * resolve the name or pin the address, so it does not close DNS rebinding. It does not need to
46
+ * — the property wanted here is "these credentials only ever go to Wix", and a name that
47
+ * resolves somewhere unexpected is still a name Wix controls. */
48
+ /** Registrable suffixes whose hosts may receive wix-scoped, credential-bearing traffic.
49
+ *
50
+ * Kept in lockstep with the natives' `isFirstPartyWixHost` roots — see the note above. */
51
+ export declare const WIX_HOST_SUFFIXES: readonly ["wix.com", "wixapis.com", "nownia.com"];
52
+ /** The host this url would actually be dialled on, lowercased — or `""` when it has none. */
53
+ export declare function targetHost(raw: string): string;
54
+ /** May a wix-scoped, credential-bearing request go to this url?
55
+ *
56
+ * `https:` only: every legitimate target in this package is https, and a downgrade to `http:`
57
+ * would put the very credentials this exists to protect on the wire in clear. */
58
+ export declare function isWixTarget(raw: string): boolean;
package/dist/cli.mjs CHANGED
@@ -15163,6 +15163,33 @@ var init_derive_transport_capability = __esm({
15163
15163
  }
15164
15164
  });
15165
15165
 
15166
+ // ../../core/dev-server/src/wix-hosts.ts
15167
+ function targetHost(raw) {
15168
+ try {
15169
+ return new URL(raw).hostname.toLowerCase();
15170
+ } catch {
15171
+ return "";
15172
+ }
15173
+ }
15174
+ function isWixTarget(raw) {
15175
+ let url;
15176
+ try {
15177
+ url = new URL(raw);
15178
+ } catch {
15179
+ return false;
15180
+ }
15181
+ if (url.protocol !== "https:") return false;
15182
+ const host = url.hostname.toLowerCase();
15183
+ if (!host) return false;
15184
+ return WIX_HOST_SUFFIXES.some((suffix) => host === suffix || host.endsWith(`.${suffix}`));
15185
+ }
15186
+ var WIX_HOST_SUFFIXES;
15187
+ var init_wix_hosts = __esm({
15188
+ "../../core/dev-server/src/wix-hosts.ts"() {
15189
+ WIX_HOST_SUFFIXES = ["wix.com", "wixapis.com", "nownia.com"];
15190
+ }
15191
+ });
15192
+
15166
15193
  // ../../core/dev-server/src/wix-member-login.ts
15167
15194
  var wix_member_login_exports = {};
15168
15195
  __export(wix_member_login_exports, {
@@ -15287,6 +15314,9 @@ async function memberDirectRegister(clientId, redirectUri, email, password, firs
15287
15314
  }
15288
15315
  async function webWixCall(method, path, body, token, cookie, forwardedHeaders = {}) {
15289
15316
  const url = /^https?:\/\//i.test(path) ? path : `${API}${path.startsWith("/") ? path : "/" + path}`;
15317
+ if (!isWixTarget(url)) {
15318
+ throw new Error(`refusing to send Wix credentials to a non-Wix host (${targetHost(url) || "no host"})`);
15319
+ }
15290
15320
  const res = await fetch(url, {
15291
15321
  method,
15292
15322
  headers: {
@@ -15302,6 +15332,7 @@ async function webWixCall(method, path, body, token, cookie, forwardedHeaders =
15302
15332
  var API;
15303
15333
  var init_wix_member_login = __esm({
15304
15334
  "../../core/dev-server/src/wix-member-login.ts"() {
15335
+ init_wix_hosts();
15305
15336
  API = "https://www.wixapis.com";
15306
15337
  }
15307
15338
  });
@@ -54515,7 +54546,7 @@ var init_site_oauth_client = __esm({
54515
54546
 
54516
54547
  // src/cli.ts
54517
54548
  import { mkdtempSync as mkdtempSync4, readFileSync as readFileSync65, mkdirSync as mkdirSync25, writeFileSync as writeFileSync23, existsSync as existsSync54, rmSync as rmSync9, readdirSync as readdirSync25, statSync as statSync12, lstatSync as lstatSync6, accessSync, constants } from "node:fs";
54518
- import { execFileSync as execFileSync7, spawnSync as spawnSync5 } from "node:child_process";
54549
+ import { execFileSync as execFileSync7, spawnSync as spawnSync5, spawn as spawn5 } from "node:child_process";
54519
54550
  import { createHash as createHash24, randomUUID as randomUUID3 } from "node:crypto";
54520
54551
  import { tmpdir as tmpdir5, homedir as homedir7, hostname } from "node:os";
54521
54552
  import { join as join51, resolve as resolve42, relative as relative8, basename as basename11, dirname as dirname30 } from "node:path";
@@ -58885,8 +58916,11 @@ async function fetchPackumentFrom(registry, fetchImpl, timeoutMs) {
58885
58916
  }
58886
58917
  }
58887
58918
  async function fetchCliPackument(fetchImpl = fetch, timeoutMs = DOCTOR_TIMEOUT_MS, env = process.env, scopedRegistry = npmScopedWixRegistry) {
58919
+ const deadline = Date.now() + timeoutMs;
58888
58920
  for (const registry of registryCandidates(env, scopedRegistry())) {
58889
- const packument = await fetchPackumentFrom(registry, fetchImpl, timeoutMs);
58921
+ const remaining = deadline - Date.now();
58922
+ if (remaining <= 0) break;
58923
+ const packument = await fetchPackumentFrom(registry, fetchImpl, remaining);
58890
58924
  if (packument) return packument;
58891
58925
  }
58892
58926
  return void 0;
@@ -58926,7 +58960,7 @@ function resolvedSdkVersion(fromDir = process.cwd(), bundledManifest = new URL("
58926
58960
  }
58927
58961
  async function doctorVersionReport(running, fetchImpl = fetch, sdk = resolvedSdkVersion(), scopedRegistry = npmScopedWixRegistry) {
58928
58962
  const minimumSdk = "0.33.0";
58929
- const packument = await fetchCliPackument(fetchImpl, DOCTOR_TIMEOUT_MS, process.env, scopedRegistry);
58963
+ const packument = await fetchCliPackument(fetchImpl, UPDATE_EXPLICIT_BUDGET_MS, process.env, scopedRegistry);
58930
58964
  const latest = packument?.latest;
58931
58965
  const publishedAt = packument?.time[running];
58932
58966
  const ageDays = ageInDays(publishedAt);
@@ -58958,6 +58992,10 @@ var CLI_PACKAGE = "@wix/himalaya-cli";
58958
58992
  var UNPUBLISHED_CLI_VERSION = "0.1.0";
58959
58993
  var UPDATE_MAX_AGE_DAYS = 7;
58960
58994
  var UPDATE_CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
58995
+ var UPDATE_FOREGROUND_BUDGET_MS = 1500;
58996
+ var UPDATE_EXPLICIT_BUDGET_MS = 2e4;
58997
+ var UPDATE_BACKGROUND_BUDGET_MS = 6e4;
58998
+ var UPDATE_RETRY_AFTER_FAILURE_MS = 60 * 60 * 1e3;
58961
58999
  var UPDATE_SNOOZE_MS = 24 * 60 * 60 * 1e3;
58962
59000
  var UPDATE_REEXEC_ENV = "HIMI_UPDATED_ONCE";
58963
59001
  function updateCachePath(env = process.env) {
@@ -58981,7 +59019,7 @@ function writeUpdateCache(path, cache) {
58981
59019
  function updateCheckSuppression(running, command, env = process.env, cwd = process.cwd()) {
58982
59020
  if (env[UPDATE_REEXEC_ENV] === "1") return "already-updated";
58983
59021
  if (env.HIMI_NO_UPDATE_CHECK === "1") return "opted-out";
58984
- if (command === "upgrade" || command === "doctor") return "own-command";
59022
+ if (command === "upgrade" || command === "doctor" || command === UPDATE_REFRESH_COMMAND) return "own-command";
58985
59023
  if (running === UNPUBLISHED_CLI_VERSION) return "unpublished";
58986
59024
  if (isHimalayaMonorepoCheckout(cwd)) return "monorepo";
58987
59025
  return void 0;
@@ -59015,12 +59053,12 @@ function npmInstallArgs(registry, version2) {
59015
59053
  return ["i", "-g", `${CLI_PACKAGE}@${version2}`, `--registry=${pinned}`, `--@wix:registry=${pinned}`];
59016
59054
  }
59017
59055
  var INSTALLABLE_SPEC = /^(?:latest|\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?)$/;
59018
- function createUpdateRunner(spawn5 = spawnSync5) {
59056
+ function createUpdateRunner(spawn6 = spawnSync5) {
59019
59057
  return {
59020
59058
  install: async (registry, version2) => {
59021
59059
  if (!isTrustedRegistry(registry)) return { ok: false, detail: `refusing untrusted registry ${registry}` };
59022
59060
  if (!INSTALLABLE_SPEC.test(version2)) return { ok: false, detail: `refusing install spec ${JSON.stringify(version2)}` };
59023
- const result = spawn5("npm", npmInstallArgs(registry, version2), {
59061
+ const result = spawn6("npm", npmInstallArgs(registry, version2), {
59024
59062
  // npm's stdout goes to OUR stderr: in `himi <cmd> --json | jq` (and `himi upgrade --json`) its
59025
59063
  // "added 212 packages" would otherwise land in stdout ahead of the envelope and break the
59026
59064
  // parse — the agent case this whole feature exists for (#2985 review). And no stdin: an
@@ -59169,6 +59207,49 @@ function upgradeEnvelope(outcome) {
59169
59207
  ...outcome.detail ? { detail: outcome.detail } : {}
59170
59208
  };
59171
59209
  }
59210
+ var UPDATE_REFRESH_COMMAND = "__refresh-update-cache";
59211
+ async function refreshUpdateCache(opts = {}) {
59212
+ const env = opts.env ?? process.env;
59213
+ const running = opts.running ?? cliVersion();
59214
+ const cachePath = opts.cachePath ?? updateCachePath(env);
59215
+ const packument = await fetchCliPackument(opts.fetchImpl ?? fetch, UPDATE_BACKGROUND_BUDGET_MS, env, opts.scopedRegistry);
59216
+ if (!packument) return false;
59217
+ const now = opts.now ?? Date.now();
59218
+ writeUpdateCache(cachePath, {
59219
+ ...readUpdateCache(cachePath),
59220
+ running,
59221
+ latest: packument.latest,
59222
+ runningPublishedAt: packument.time[running],
59223
+ checkedAt: new Date(now).toISOString()
59224
+ });
59225
+ return true;
59226
+ }
59227
+ function createUpdateRefreshSpawner(spawnFn = spawn5, execArgv = process.execArgv) {
59228
+ return () => {
59229
+ try {
59230
+ const child = spawnFn(process.execPath, [...loaderArgs(execArgv), fileURLToPath24(import.meta.url), UPDATE_REFRESH_COMMAND], {
59231
+ detached: true,
59232
+ stdio: "ignore",
59233
+ cwd: homedir7(),
59234
+ env: process.env
59235
+ });
59236
+ child.on("error", () => {
59237
+ });
59238
+ child.unref();
59239
+ } catch {
59240
+ }
59241
+ };
59242
+ }
59243
+ function loaderArgs(execArgv) {
59244
+ const out = [];
59245
+ for (let i = 0; i < execArgv.length; i++) {
59246
+ const arg = execArgv[i];
59247
+ if (/^--(import|loader|experimental-loader|require)=/.test(arg)) out.push(arg);
59248
+ else if (/^(--import|--loader|--experimental-loader|--require|-r)$/.test(arg) && i + 1 < execArgv.length) out.push(arg, execArgv[++i]);
59249
+ }
59250
+ return out;
59251
+ }
59252
+ var spawnUpdateRefresh = createUpdateRefreshSpawner();
59172
59253
  async function maybeSelfUpdate(argv, io, opts = {}) {
59173
59254
  const env = opts.env ?? process.env;
59174
59255
  const running = opts.running ?? cliVersion();
@@ -59186,14 +59267,19 @@ async function maybeSelfUpdate(argv, io, opts = {}) {
59186
59267
  if (!describesThisBuild) runningPublishedAt = void 0;
59187
59268
  let answeredBy;
59188
59269
  let answeredLatest;
59189
- if (!fresh) {
59190
- const packument = await fetchCliPackument(opts.fetchImpl ?? fetch, DOCTOR_TIMEOUT_MS, env, opts.scopedRegistry);
59270
+ const attemptedAt = cache.attemptedAt ? Date.parse(cache.attemptedAt) : Number.NaN;
59271
+ const recentlyTried = cache.attemptedFor === running && Number.isFinite(attemptedAt) && now - attemptedAt < UPDATE_RETRY_AFTER_FAILURE_MS;
59272
+ if (!fresh && !recentlyTried) {
59273
+ const packument = await fetchCliPackument(opts.fetchImpl ?? fetch, UPDATE_FOREGROUND_BUDGET_MS, env, opts.scopedRegistry);
59191
59274
  if (packument) {
59192
59275
  latest = packument.latest;
59193
59276
  runningPublishedAt = packument.time[running];
59194
59277
  answeredBy = packument.registry;
59195
59278
  answeredLatest = packument.latest;
59196
59279
  writeUpdateCache(cachePath, { ...cache, running, checkedAt: new Date(now).toISOString(), latest, runningPublishedAt });
59280
+ } else {
59281
+ writeUpdateCache(cachePath, { ...cache, attemptedAt: new Date(now).toISOString(), attemptedFor: running });
59282
+ (opts.spawnRefresh ?? spawnUpdateRefresh)();
59197
59283
  }
59198
59284
  }
59199
59285
  const ageDays = ageInDays(runningPublishedAt, now);
@@ -59237,7 +59323,7 @@ async function maybeSelfUpdate(argv, io, opts = {}) {
59237
59323
  }
59238
59324
  try {
59239
59325
  if (!answeredBy) {
59240
- const again = await fetchCliPackument(opts.fetchImpl ?? fetch, DOCTOR_TIMEOUT_MS, env, opts.scopedRegistry);
59326
+ const again = await fetchCliPackument(opts.fetchImpl ?? fetch, UPDATE_EXPLICIT_BUDGET_MS, env, opts.scopedRegistry);
59241
59327
  answeredBy = again?.registry;
59242
59328
  answeredLatest = again?.latest;
59243
59329
  }
@@ -64726,6 +64812,11 @@ ${label2}`);
64726
64812
  });
64727
64813
  return 0;
64728
64814
  }
64815
+ case UPDATE_REFRESH_COMMAND: {
64816
+ const up = deps.selfUpdate ?? {};
64817
+ await refreshUpdateCache({ env: up.env, fetchImpl: up.fetchImpl, cachePath: up.cachePath, scopedRegistry: up.scopedRegistry, now: up.now, running: up.running });
64818
+ return 0;
64819
+ }
64729
64820
  case "upgrade": {
64730
64821
  const up = deps.selfUpdate ?? {};
64731
64822
  const runner2 = up.runner ?? defaultUpdateRunner;
@@ -64741,7 +64832,7 @@ ${label2}`);
64741
64832
  }
64742
64833
  try {
64743
64834
  const scoped = up.scopedRegistry ?? npmScopedWixRegistry;
64744
- const answered = await fetchCliPackument(up.fetchImpl ?? fetch, DOCTOR_TIMEOUT_MS, env, scoped);
64835
+ const answered = await fetchCliPackument(up.fetchImpl ?? fetch, UPDATE_EXPLICIT_BUDGET_MS, env, scoped);
64745
64836
  const registry = answered?.registry ?? registryCandidates(env, scoped())[0];
64746
64837
  if (answered?.latest && compareVersions2(answered.latest, before) <= 0) {
64747
64838
  if (flags.json) print({ ok: true, running: before, installed: before, changed: false, registry, latest: answered.latest });
@@ -65228,6 +65319,10 @@ export {
65228
65319
  PREVIEW_TOKEN_NOTE,
65229
65320
  PUBLIC_NPM_REGISTRY,
65230
65321
  PUBLIC_WIX_API_BASE,
65322
+ UPDATE_BACKGROUND_BUDGET_MS,
65323
+ UPDATE_EXPLICIT_BUDGET_MS,
65324
+ UPDATE_FOREGROUND_BUDGET_MS,
65325
+ UPDATE_REFRESH_COMMAND,
65231
65326
  WIX_NPM_MIRROR,
65232
65327
  acquireUpdateLock,
65233
65328
  ageInDays,
@@ -65235,6 +65330,7 @@ export {
65235
65330
  buildDoctorReport,
65236
65331
  compareVersions2 as compareVersions,
65237
65332
  createScopedRegistryResolver,
65333
+ createUpdateRefreshSpawner,
65238
65334
  createUpdateRunner,
65239
65335
  credentialKind,
65240
65336
  credentialSwapNotice,
@@ -65257,6 +65353,7 @@ export {
65257
65353
  isLoopbackBase,
65258
65354
  isPublicTarget,
65259
65355
  isTrustedRegistry,
65356
+ loaderArgs,
65260
65357
  loginModeMark,
65261
65358
  loginModeReport,
65262
65359
  loopbackTargetWarning,
@@ -65286,6 +65383,7 @@ export {
65286
65383
  probeReachable,
65287
65384
  pushAuthHint,
65288
65385
  readUpdateCache,
65386
+ refreshUpdateCache,
65289
65387
  registryCandidates,
65290
65388
  renderDataSource,
65291
65389
  renderDeviceWidths,
@@ -65297,6 +65395,7 @@ export {
65297
65395
  serveUnreachableHint,
65298
65396
  servesAll,
65299
65397
  shellShaDivergenceWarnings,
65398
+ spawnUpdateRefresh,
65300
65399
  staleUpdateLockFile,
65301
65400
  switchFlagErrors,
65302
65401
  templatePreviewAuthError,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/himalaya-cli",
3
- "version": "0.991.0",
3
+ "version": "0.993.0",
4
4
  "type": "module",
5
5
  "description": "himi — the Himalaya authoring CLI. Build a Tier-5 content package on your own machine, push it to the production serve as a draft, preview it on web + Himi Player, and read worker logs back — the remote dev loop. Wraps @himalaya/serve-cli for transport.",
6
6
  "keywords": [
@@ -65,5 +65,5 @@
65
65
  "artifactId": "himalaya-cli"
66
66
  }
67
67
  },
68
- "falconPackageHash": "ebb2d80b9a686fc18878c48955d691cd014019a04d2ed731b2a431dd"
68
+ "falconPackageHash": "65760e4588c44ee36e6538fcc1bf8802e544b4045157544b3f4d0d94"
69
69
  }