@quatronic/qore 0.4.0-rc.1 → 0.4.0-test.45abf0b

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 (3) hide show
  1. package/README.md +13 -0
  2. package/dist/cli.js +116 -22
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -141,6 +141,19 @@ qore env pull
141
141
  directory, then renamed over the target — it's never truncated in place.
142
142
  (On Windows, POSIX file modes don't apply — setting `0600` there is a
143
143
  no-op; there's no equivalent file-permission hardening on that platform.)
144
+ - When the repository has a `mobile/` directory (an Expo app), the pull also
145
+ writes `mobile/.env.local` with the app's **public** staging config:
146
+ `EXPO_PUBLIC_SERVER_URL`, `EXPO_PUBLIC_SENTRY_DSN` and
147
+ `EXPO_PUBLIC_QORE_ENV=staging`. qore owns those three keys and overwrites
148
+ them; every other line in the file is kept. A value the portal does not have
149
+ yet is left out rather than written empty, because an empty `EXPO_PUBLIC_*`
150
+ value would override the one baked into `app.config.ts`. Until staging is
151
+ deployed there is no server URL; the pull says so, and running it again
152
+ after the deploy fills it in. A portal too old to serve this config is
153
+ skipped with a note, and a failed fetch warns without failing the pull.
154
+ `--json` reports it as
155
+ `mobile: { target, environment, serverUrl, sentryDsn: <set?>, written }`
156
+ (`null` without a `mobile/` directory). `qore dev` does not write this file.
144
157
 
145
158
  **First use of a repository** requires confirmation — see "Trust on first
146
159
  use" below. **Values are never printed**: not in `qore env pull`'s output,
package/dist/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="05d31518-1117-59ee-858c-044499f160e6")}catch(e){}}();
3
+ !function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="ce41f571-68ec-5ea7-85ee-ae940086da7e")}catch(e){}}();
4
4
  import { createRequire as __qoreCreateRequire } from "node:module"; const require = __qoreCreateRequire(import.meta.url);
5
5
  import {
6
6
  addSecretValues,
@@ -135,6 +135,7 @@ function processIo(interactive, stderrTTY = Boolean(process.stderr.isTTY)) {
135
135
  stderrTTY,
136
136
  stderrRaw: process.stderr,
137
137
  async select(message, choices) {
138
+ if (choices.length === 0) throw noChoices(message);
138
139
  try {
139
140
  return await select({ message, choices });
140
141
  } catch (e) {
@@ -170,6 +171,11 @@ function processIo(interactive, stderrTTY = Boolean(process.stderr.isTTY)) {
170
171
  openUrl: openBrowser
171
172
  };
172
173
  }
174
+ function noChoices(message) {
175
+ return new QoreError("QORE_RESOURCE_NOT_FOUND", `Nothing to choose from (${message}): the list is empty`, {
176
+ hint: "Run `qore whoami` to check what your account has access to, or pass the value as an argument."
177
+ });
178
+ }
173
179
  function createWaitForEnter(input2, output) {
174
180
  return (message, signal) => new Promise((resolve9, reject) => {
175
181
  const rl = createInterface({ input: input2, output, terminal: true });
@@ -7291,8 +7297,50 @@ function registerDoctor(program, ctx) {
7291
7297
 
7292
7298
  // src/cli/commands/env.ts
7293
7299
  import { randomBytes as randomBytes9 } from "crypto";
7294
- import { chmod as chmod3, realpath as realpath13 } from "fs/promises";
7295
- import { dirname as dirname11, join as join29, relative as relative10 } from "path";
7300
+ import { chmod as chmod4, realpath as realpath13 } from "fs/promises";
7301
+ import { dirname as dirname11, join as join30, relative as relative10 } from "path";
7302
+
7303
+ // src/core/env/mobile.ts
7304
+ import { chmod as chmod3, stat as stat7 } from "fs/promises";
7305
+ import { join as join29 } from "path";
7306
+ var MOBILE_ENV_FILE = "mobile/.env.local";
7307
+ var MOBILE_KEYS = ["EXPO_PUBLIC_SERVER_URL", "EXPO_PUBLIC_SENTRY_DSN", "EXPO_PUBLIC_QORE_ENV"];
7308
+ async function hasMobileApp(repoRoot) {
7309
+ try {
7310
+ return (await stat7(join29(repoRoot, "mobile"))).isDirectory();
7311
+ } catch {
7312
+ return false;
7313
+ }
7314
+ }
7315
+ async function fetchMobileConfig(deps2, mc, app) {
7316
+ if (!await hasCapability(deps2, mc.portal.apiOrigin, "module.mobile-config")) return null;
7317
+ return mc.session.api.get(
7318
+ `/api/cli/v1/modules/${encodeURIComponent(mc.module.id)}/mobile-config?app_id=${encodeURIComponent(app.id)}`
7319
+ );
7320
+ }
7321
+ function mobileEnvValues(config) {
7322
+ const values = {};
7323
+ if (config.serverUrl) values.EXPO_PUBLIC_SERVER_URL = config.serverUrl;
7324
+ if (config.sentryDsn) values.EXPO_PUBLIC_SENTRY_DSN = config.sentryDsn;
7325
+ values.EXPO_PUBLIC_QORE_ENV = config.environment;
7326
+ return values;
7327
+ }
7328
+ function planMobileEnv(existing, config) {
7329
+ const original = existing ?? "";
7330
+ const { merged } = planEnvUpdate({ current: parseEnv(original), fetched: mobileEnvValues(config), managed: [...MOBILE_KEYS] });
7331
+ const text2 = renderEnv(original, merged);
7332
+ return { text: text2, changed: existing === null || text2 !== existing };
7333
+ }
7334
+ async function writeMobileEnv(repoRoot, config) {
7335
+ const target = await resolveTarget(repoRoot, MOBILE_ENV_FILE);
7336
+ const existing = await readOrNull(target);
7337
+ const plan = planMobileEnv(existing, config);
7338
+ if (plan.changed) await writeSecurely(target, plan.text);
7339
+ else await chmod3(target, 384);
7340
+ return { target, written: plan.changed };
7341
+ }
7342
+
7343
+ // src/cli/commands/env.ts
7296
7344
  var maskLen = (v) => v === void 0 ? "(unset)" : `\u2022\u2022\u2022\u2022 (${v.length} chars)`;
7297
7345
  function registerEnv(program, ctx) {
7298
7346
  const env = program.command("env").description("Local environment");
@@ -7311,7 +7359,7 @@ function registerEnv(program, ctx) {
7311
7359
  const target = f.target ? await resolveTarget(mc.repoRoot, f.target, deps2.cwd) : await resolveTarget(mc.repoRoot, cfg.envFile ?? defaults.envFile);
7312
7360
  await ensureTrusted(c, mc, app, { yes: f.yes });
7313
7361
  const existing = await readOrNull(target);
7314
- const example = existing === null ? await readOrNull(join29(dirname11(target), ".env.example")) : null;
7362
+ const example = existing === null ? await readOrNull(join30(dirname11(target), ".env.example")) : null;
7315
7363
  const local = await fetchLocalEnv(deps2, mc, app);
7316
7364
  const inputs = {
7317
7365
  existing,
@@ -7348,11 +7396,12 @@ function registerEnv(program, ctx) {
7348
7396
  plan = planPull({ ...inputs, choices });
7349
7397
  }
7350
7398
  if (existing !== null && plan.text === existing) {
7351
- await chmod3(target, 384);
7399
+ await chmod4(target, 384);
7352
7400
  } else {
7353
7401
  await writeSecurely(target, plan.text);
7354
7402
  }
7355
7403
  const rel = relative10(await realpath13(mc.repoRoot), target);
7404
+ const mobile = await pullMobile(c, mc, app);
7356
7405
  if (g.json) {
7357
7406
  const names = {
7358
7407
  created: plan.created,
@@ -7364,7 +7413,7 @@ function registerEnv(program, ctx) {
7364
7413
  unchanged: plan.unchanged,
7365
7414
  generated: plan.generated
7366
7415
  };
7367
- renderJson(io2, { context: contextJson(mc, app), target: rel, ...names });
7416
+ renderJson(io2, { context: contextJson(mc, app), target: rel, ...names, mobile: mobile && mobileJson(mobile) });
7368
7417
  return;
7369
7418
  }
7370
7419
  if (await isGitIgnored(deps2.git, mc.repoRoot, target) === false) io2.err(`! ${notIgnoredWarning(rel)}`);
@@ -7379,8 +7428,48 @@ function registerEnv(program, ctx) {
7379
7428
  plan.generated.length && `${plan.generated.length} generated`
7380
7429
  ].filter(Boolean);
7381
7430
  io2.out(`\u2713 ${rel}${plan.seededFromExample ? " (created from .env.example)" : ""} \u2014 ${parts.length ? parts.join(", ") : "up to date"}`);
7431
+ if (mobile) await reportMobile(c, mc.repoRoot, mobile);
7382
7432
  });
7383
7433
  }
7434
+ async function pullMobile(c, mc, app) {
7435
+ if (!mc.repoRoot || !await hasMobileApp(mc.repoRoot)) return null;
7436
+ try {
7437
+ const config = await fetchMobileConfig(c.deps, mc, app);
7438
+ if (!config) return { kind: "unsupported" };
7439
+ return { kind: "written", config, ...await writeMobileEnv(mc.repoRoot, config) };
7440
+ } catch (e) {
7441
+ if (e instanceof QoreError) return { kind: "failed", error: e };
7442
+ throw e;
7443
+ }
7444
+ }
7445
+ function mobileJson(m) {
7446
+ if (m.kind === "unsupported") return { target: MOBILE_ENV_FILE, skipped: "unsupported-portal" };
7447
+ if (m.kind === "failed") return { target: MOBILE_ENV_FILE, error: { code: m.error.code, message: m.error.message } };
7448
+ return {
7449
+ target: MOBILE_ENV_FILE,
7450
+ environment: m.config.environment,
7451
+ serverUrl: m.config.serverUrl,
7452
+ sentryDsn: m.config.sentryDsn !== null,
7453
+ written: m.written
7454
+ };
7455
+ }
7456
+ async function reportMobile(c, repoRoot, m) {
7457
+ const { io: io2, deps: deps2 } = c;
7458
+ if (m.kind === "unsupported") {
7459
+ io2.err(`! ${MOBILE_ENV_FILE}: skipped \u2014 this portal cannot serve the mobile app's config yet`);
7460
+ return;
7461
+ }
7462
+ if (m.kind === "failed") {
7463
+ io2.err(`! ${MOBILE_ENV_FILE}: not updated \u2014 ${m.error.message}`);
7464
+ return;
7465
+ }
7466
+ if (await isGitIgnored(deps2.git, repoRoot, m.target) === false) io2.err(`! ${notIgnoredWarning(MOBILE_ENV_FILE)}`);
7467
+ if (m.config.serverUrl === null) {
7468
+ io2.err(`! ${MOBILE_ENV_FILE}: ${m.config.environment} has no server URL yet \u2014 deploy ${m.config.environment}, then run qore env pull again`);
7469
+ }
7470
+ const server = m.config.serverUrl ? `server ${m.config.serverUrl}` : "no server URL";
7471
+ io2.out(`\u2713 ${MOBILE_ENV_FILE} \u2014 ${server} (${m.config.environment})${m.written ? "" : ", up to date"}`);
7472
+ }
7384
7473
 
7385
7474
  // src/core/observability/compose.ts
7386
7475
  function pageWarnings(...pages) {
@@ -8103,6 +8192,11 @@ async function useTenant(ctx, slug, known) {
8103
8192
  const portal = resolvePortal(g.portal, cfg.defaultProfile);
8104
8193
  const me = known ?? await (await openSession(deps2, portal, "tenant use", requestLog(ctx))).api.get("/api/cli/v1/me");
8105
8194
  const candidates = me.tenants.map((t) => ({ kind: "tenant", id: t.id, slug: t.slug, name: t.name }));
8195
+ if (me.tenants.length === 0) {
8196
+ throw new QoreError("QORE_NO_DEVELOPER_ACCESS", "Your account is not a developer in any organisation", {
8197
+ hint: "Ask an admin to invite you as a developer."
8198
+ });
8199
+ }
8106
8200
  let chosen;
8107
8201
  if (slug) {
8108
8202
  const found = me.tenants.find((t) => t.slug === slug);
@@ -8317,7 +8411,7 @@ function registerPortal(program, ctx) {
8317
8411
  }
8318
8412
 
8319
8413
  // src/core/roles/read.ts
8320
- import { join as join30 } from "path";
8414
+ import { join as join31 } from "path";
8321
8415
 
8322
8416
  // src/core/roles/extract.ts
8323
8417
  var KNOWN = { user: "User", admin: "App admin" };
@@ -8348,11 +8442,11 @@ async function extractRoles(source) {
8348
8442
 
8349
8443
  // src/core/roles/read.ts
8350
8444
  var PERMISSIONS_FILE = "src/lib/permissions.ts";
8351
- var SLUG = /^[a-z0-9][a-z0-9_-]*$/;
8445
+ var SLUG = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
8352
8446
  var MAX_SLUG = 64;
8353
8447
  var MAX_ROLES = 100;
8354
8448
  async function readCodeRoles(repoRoot) {
8355
- const source = await readOrNull(join30(repoRoot, PERMISSIONS_FILE));
8449
+ const source = await readOrNull(join31(repoRoot, PERMISSIONS_FILE));
8356
8450
  if (source === null) {
8357
8451
  throw new QoreError("QORE_CONTEXT_UNSUPPORTED", `No ${PERMISSIONS_FILE} in this module`, {
8358
8452
  hint: "App roles live in the app's frontend module; run this there."
@@ -8367,7 +8461,7 @@ async function readCodeRoles(repoRoot) {
8367
8461
  const invalid4 = roles.filter((r) => !SLUG.test(r.slug) || r.slug.length > MAX_SLUG).map((r) => r.slug);
8368
8462
  if (invalid4.length) {
8369
8463
  throw new QoreError("QORE_CONTEXT_INVALID", `The portal refuses these role names: ${invalid4.join(", ")}`, {
8370
- hint: `Use lowercase letters, digits, - and _, starting with a letter or digit, at most ${MAX_SLUG} characters.`,
8464
+ hint: `Use letters, digits, - and _, starting with a letter or digit, at most ${MAX_SLUG} characters.`,
8371
8465
  details: { invalid: invalid4 }
8372
8466
  });
8373
8467
  }
@@ -8544,7 +8638,7 @@ function registerStatus(program, ctx) {
8544
8638
 
8545
8639
  // src/cli/commands/sync.ts
8546
8640
  import { realpath as realpath15 } from "fs/promises";
8547
- import { basename as basename9, join as join31, relative as relative11 } from "path";
8641
+ import { basename as basename9, join as join32, relative as relative11 } from "path";
8548
8642
  import { Option as Option3 } from "commander";
8549
8643
  function asFailure2(slug, e) {
8550
8644
  if (e instanceof QoreError && e.code !== "QORE_GIT_UNAVAILABLE") {
@@ -8564,7 +8658,7 @@ async function syncInPlace(deps2, o) {
8564
8658
  continue;
8565
8659
  }
8566
8660
  try {
8567
- dirs[m.slug] = await deps2.git.inspect(join31(root, m.slug));
8661
+ dirs[m.slug] = await deps2.git.inspect(join32(root, m.slug));
8568
8662
  modulesForPlan.push(m);
8569
8663
  } catch (e) {
8570
8664
  earlyFailures.push(asFailure2(m.slug, e));
@@ -9010,7 +9104,7 @@ async function maybeNotifyUpdate(deps2, io2, o, timeoutMs = DEFAULT_TIMEOUT_MS)
9010
9104
 
9011
9105
  // src/core/config.ts
9012
9106
  import { readFile as readFile8 } from "fs/promises";
9013
- import { join as join32 } from "path";
9107
+ import { join as join33 } from "path";
9014
9108
  var empty = () => ({ schemaVersion: 1, profiles: {} });
9015
9109
  var ConfigStore = class {
9016
9110
  constructor(dir2) {
@@ -9018,7 +9112,7 @@ var ConfigStore = class {
9018
9112
  }
9019
9113
  dir;
9020
9114
  get file() {
9021
- return join32(this.dir, "config.json");
9115
+ return join33(this.dir, "config.json");
9022
9116
  }
9023
9117
  async read() {
9024
9118
  let raw;
@@ -9049,9 +9143,9 @@ var ConfigStore = class {
9049
9143
 
9050
9144
  // src/platform/git.ts
9051
9145
  import { execFile, execFileSync } from "child_process";
9052
- import { mkdir as mkdir6, readdir as readdir7, stat as stat7 } from "fs/promises";
9146
+ import { mkdir as mkdir6, readdir as readdir7, stat as stat8 } from "fs/promises";
9053
9147
  import { homedir } from "os";
9054
- import { dirname as dirname12, join as join33 } from "path";
9148
+ import { dirname as dirname12, join as join34 } from "path";
9055
9149
  function parseRemotes(stdout) {
9056
9150
  const seen = /* @__PURE__ */ new Set();
9057
9151
  const out = [];
@@ -9192,7 +9286,7 @@ async function stashCount(repoRoot) {
9192
9286
  }
9193
9287
  async function statOrThrow(path2) {
9194
9288
  try {
9195
- return await stat7(path2);
9289
+ return await stat8(path2);
9196
9290
  } catch (err) {
9197
9291
  if (err.code === "ENOENT") return void 0;
9198
9292
  throw new QoreError("QORE_INTERNAL", `could not stat ${path2}`, { cause: err });
@@ -9209,7 +9303,7 @@ async function inspect(dir2) {
9209
9303
  throw new QoreError("QORE_INTERNAL", `could not read ${dir2}`, { cause: err });
9210
9304
  }
9211
9305
  const empty2 = entries.length === 0;
9212
- const isRepo = await statOrThrow(join33(dir2, ".git")) !== void 0;
9306
+ const isRepo = await statOrThrow(join34(dir2, ".git")) !== void 0;
9213
9307
  const dirRemotes = isRepo ? await remotes(dir2) : [];
9214
9308
  return { exists: true, empty: empty2, isRepo, remotes: dirRemotes };
9215
9309
  }
@@ -9342,13 +9436,13 @@ var OsKeychain = class extends ChunkedKeychain {
9342
9436
 
9343
9437
  // src/platform/lock.ts
9344
9438
  import { mkdir as mkdir7, writeFile as writeFile7 } from "fs/promises";
9345
- import { join as join34 } from "path";
9439
+ import { join as join35 } from "path";
9346
9440
  import lockfile from "proper-lockfile";
9347
9441
  function fileLock(dir2) {
9348
9442
  return async (name, fn) => {
9349
- const locks = join34(dir2, "locks");
9443
+ const locks = join35(dir2, "locks");
9350
9444
  await mkdir7(locks, { recursive: true, mode: 448 });
9351
- const target = join34(locks, `${name}.lock`);
9445
+ const target = join35(locks, `${name}.lock`);
9352
9446
  await writeFile7(target, "", { flag: "a" });
9353
9447
  let release;
9354
9448
  let compromised;
@@ -9801,4 +9895,4 @@ if (!drained) {
9801
9895
  process.exit();
9802
9896
  }
9803
9897
  //# sourceMappingURL=cli.js.map
9804
- //# debugId=05d31518-1117-59ee-858c-044499f160e6
9898
+ //# debugId=ce41f571-68ec-5ea7-85ee-ae940086da7e
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quatronic/qore",
3
- "version": "0.4.0-rc.1",
3
+ "version": "0.4.0-test.45abf0b",
4
4
  "description": "Qore developer CLI",
5
5
  "type": "module",
6
6
  "bin": {