@quatronic/qore 0.3.0-rc.1 → 0.3.0-rc.3

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 (2) hide show
  1. package/dist/cli.js +79 -48
  2. package/package.json +1 -1
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]="28cd5ca7-9197-5e2a-b7a3-beb912fc49ed")}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]="2ac9292b-9c15-5fb7-bdc6-c773ad369497")}catch(e){}}();
4
4
  import { createRequire as __qoreCreateRequire } from "node:module"; const require = __qoreCreateRequire(import.meta.url);
5
5
  import {
6
6
  addSecretValues,
@@ -3632,6 +3632,16 @@ function providerDown(o) {
3632
3632
  action: { command: o.fix }
3633
3633
  };
3634
3634
  }
3635
+ function noLocalRole(o) {
3636
+ return {
3637
+ code: "dev.no-local-role",
3638
+ severity: "warn",
3639
+ module: o.slug,
3640
+ message: `You have no role on local in ${o.app} \u2014 signing in to ${o.slug} will be refused.`,
3641
+ why: o.known.length > 0 ? `Roles known on local: ${o.known.join(", ")}. Sign in again after taking one.` : "Local knows no roles yet; `qore roles use` also announces the roles in your code. Sign in again after taking one.",
3642
+ action: { command: `${o.cd}${o.known.length === 1 ? `qore roles use ${o.known[0]}` : "qore roles use <role>"}` }
3643
+ };
3644
+ }
3635
3645
 
3636
3646
  // src/core/dev/project.ts
3637
3647
  import { access, readFile as readFile7 } from "fs/promises";
@@ -4079,6 +4089,63 @@ async function leftoverOwnsPort(deps2, run4, port) {
4079
4089
  return false;
4080
4090
  }
4081
4091
 
4092
+ // src/core/roles/api.ts
4093
+ var CAPABILITY = "module.local-roles";
4094
+ var path = (mc, app) => `/api/cli/v1/modules/${encodeURIComponent(mc.module.id)}/local-roles?app_id=${encodeURIComponent(app.id)}`;
4095
+ async function fetchLocalRoles(deps2, mc, app) {
4096
+ await ensureCapability(deps2, mc.portal.apiOrigin, CAPABILITY);
4097
+ return explained(mc, () => mc.session.api.get(path(mc, app)));
4098
+ }
4099
+ async function useLocalRoles(deps2, mc, app, roles, use) {
4100
+ await ensureCapability(deps2, mc.portal.apiOrigin, CAPABILITY);
4101
+ return explained(mc, () => mc.session.api.post(path(mc, app), { roles, use }));
4102
+ }
4103
+ var ANNOUNCE_CAPABILITY = "module.local-roles-announce";
4104
+ async function announceLocalRoles(deps2, mc, app, roles) {
4105
+ await ensureCapability(deps2, mc.portal.apiOrigin, ANNOUNCE_CAPABILITY);
4106
+ return explained(mc, () => mc.session.api.post(path(mc, app), { roles }));
4107
+ }
4108
+ async function explained(mc, call) {
4109
+ try {
4110
+ return await call();
4111
+ } catch (e) {
4112
+ if (!(e instanceof QoreError)) throw e;
4113
+ if (e.serverCode === "app.access.denied") {
4114
+ throw withDetails(
4115
+ e,
4116
+ { required: "write", have: mc.module.access },
4117
+ `You have ${mc.module.access} on ${mc.module.slug}; local roles need write. Ask a maintainer of the app's dev team for write access.`
4118
+ );
4119
+ }
4120
+ if (e.serverCode === "membership.permission.denied") {
4121
+ throw withDetails(e, {}, "Taking roles on this app needs write on one of its dev teams.");
4122
+ }
4123
+ if (e.serverCode === "auth.scope.insufficient") throw withDetails(e, {}, "Run `qore login` again.");
4124
+ if (e.serverCode === "app.no_platform_identity") {
4125
+ throw new QoreError("QORE_CONTEXT_UNSUPPORTED", "This app manages its own users; the portal hands out no roles for it", {
4126
+ hint: "Give yourself the role in the app's own user admin.",
4127
+ serverCode: e.serverCode,
4128
+ requestId: e.requestId
4129
+ });
4130
+ }
4131
+ throw e;
4132
+ }
4133
+ }
4134
+
4135
+ // src/core/dev/localRole.ts
4136
+ async function localRoleFinding(deps2, mc, app, env, cd) {
4137
+ if (!env.KC_CLIENT_ID) return null;
4138
+ try {
4139
+ if (!(await metaFor(deps2, mc.portal.apiOrigin)).capabilities.includes("module.local-roles")) return null;
4140
+ const roles = await fetchLocalRoles(deps2, mc, app);
4141
+ if (roles.effective.length > 0) return null;
4142
+ return noLocalRole({ slug: mc.module.slug, app: app.slug, known: roles.roles.map((r) => r.slug), cd });
4143
+ } catch (e) {
4144
+ if (e instanceof QoreError) return null;
4145
+ throw e;
4146
+ }
4147
+ }
4148
+
4082
4149
  // src/core/dev/providers.ts
4083
4150
  var LOCAL_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]"]);
4084
4151
  function connPorts(env) {
@@ -4904,6 +4971,10 @@ async function prepareWorkspace(ctx, ws, f, waitTimeout, p) {
4904
4971
  );
4905
4972
  }
4906
4973
  report({ module: slug, step: "env", status: "done", detail: relative6(rootReal, dev.envFile) });
4974
+ if (online && !dev.offline) {
4975
+ const role = await localRoleFinding(deps2, mcFor(u), appRef, dev.env, cdPrefix(deps2.home, u.dir));
4976
+ if (role) renderFinding(ctx, role);
4977
+ }
4907
4978
  const services = servicesMissing(slug, dev.env, u.recipe, { servicesFlag: f.services, configured: u.cfg.dev?.services !== void 0 });
4908
4979
  if (services) renderFinding(ctx, services);
4909
4980
  try {
@@ -5159,14 +5230,15 @@ function parseWaitTimeout(raw) {
5159
5230
  var str3 = (v) => typeof v === "string" && v.length > 0;
5160
5231
  var SHELL_SAFE = /^[A-Za-z0-9_./,:@%+=-]*$/;
5161
5232
  var shellQuote = (s) => SHELL_SAFE.test(s) ? s : `'${s.replace(/'/g, "'\\''")}'`;
5162
- function cdAndDev(home, dir2) {
5163
- if (/^[A-Za-z]:[\\/]|^\\\\/.test(dir2)) return `cd ${/\s/.test(dir2) ? `"${dir2}"` : dir2} && qore dev`;
5233
+ function cdPrefix(home, dir2) {
5234
+ if (/^[A-Za-z]:[\\/]|^\\\\/.test(dir2)) return `cd ${/\s/.test(dir2) ? `"${dir2}"` : dir2} && `;
5164
5235
  const h = home.length > 1 ? home.replace(/\/+$/, "") : home;
5165
5236
  let target = shellQuote(dir2);
5166
5237
  if (h && dir2 === h) target = "~";
5167
5238
  else if (h && dir2.startsWith(h + "/")) target = `~/${shellQuote(dir2.slice(h.length + 1))}`;
5168
- return `cd ${target} && qore dev`;
5239
+ return `cd ${target} && `;
5169
5240
  }
5241
+ var cdAndDev = (home, dir2) => `${cdPrefix(home, dir2)}qore dev`;
5170
5242
  async function providerFindings(ctx, root, mc, app, env) {
5171
5243
  const { deps: deps2 } = ctx;
5172
5244
  try {
@@ -5334,6 +5406,8 @@ async function prepareModule(ctx, f, waitTimeout, p) {
5334
5406
  if (c.online && !dev.offline) {
5335
5407
  const provider = await providerFindings(ctx, root, c.online.mc, c.online.app, dev.env);
5336
5408
  if (provider) renderFinding(ctx, provider);
5409
+ const role = await localRoleFinding(deps2, c.online.mc, c.online.app, dev.env, "");
5410
+ if (role) renderFinding(ctx, role);
5337
5411
  }
5338
5412
  const services = servicesMissing(slug, dev.env, recipe, { servicesFlag: f.services, configured: cfg.dev?.services !== void 0 });
5339
5413
  if (services) renderFinding(ctx, services);
@@ -6805,49 +6879,6 @@ function registerLogout(program, ctx) {
6805
6879
  });
6806
6880
  }
6807
6881
 
6808
- // src/core/roles/api.ts
6809
- var CAPABILITY = "module.local-roles";
6810
- var path = (mc, app) => `/api/cli/v1/modules/${encodeURIComponent(mc.module.id)}/local-roles?app_id=${encodeURIComponent(app.id)}`;
6811
- async function fetchLocalRoles(deps2, mc, app) {
6812
- await ensureCapability(deps2, mc.portal.apiOrigin, CAPABILITY);
6813
- return explained(mc, () => mc.session.api.get(path(mc, app)));
6814
- }
6815
- async function useLocalRoles(deps2, mc, app, roles, use) {
6816
- await ensureCapability(deps2, mc.portal.apiOrigin, CAPABILITY);
6817
- return explained(mc, () => mc.session.api.post(path(mc, app), { roles, use }));
6818
- }
6819
- var ANNOUNCE_CAPABILITY = "module.local-roles-announce";
6820
- async function announceLocalRoles(deps2, mc, app, roles) {
6821
- await ensureCapability(deps2, mc.portal.apiOrigin, ANNOUNCE_CAPABILITY);
6822
- return explained(mc, () => mc.session.api.post(path(mc, app), { roles }));
6823
- }
6824
- async function explained(mc, call) {
6825
- try {
6826
- return await call();
6827
- } catch (e) {
6828
- if (!(e instanceof QoreError)) throw e;
6829
- if (e.serverCode === "app.access.denied") {
6830
- throw withDetails(
6831
- e,
6832
- { required: "write", have: mc.module.access },
6833
- `You have ${mc.module.access} on ${mc.module.slug}; local roles need write. Ask a maintainer of the app's dev team for write access.`
6834
- );
6835
- }
6836
- if (e.serverCode === "membership.permission.denied") {
6837
- throw withDetails(e, {}, "Taking roles on this app needs write on one of its dev teams.");
6838
- }
6839
- if (e.serverCode === "auth.scope.insufficient") throw withDetails(e, {}, "Run `qore login` again.");
6840
- if (e.serverCode === "app.no_platform_identity") {
6841
- throw new QoreError("QORE_CONTEXT_UNSUPPORTED", "This app manages its own users; the portal hands out no roles for it", {
6842
- hint: "Give yourself the role in the app's own user admin.",
6843
- serverCode: e.serverCode,
6844
- requestId: e.requestId
6845
- });
6846
- }
6847
- throw e;
6848
- }
6849
- }
6850
-
6851
6882
  // src/core/roles/read.ts
6852
6883
  import { join as join26 } from "path";
6853
6884
 
@@ -8210,4 +8241,4 @@ if (!drained) {
8210
8241
  process.exit();
8211
8242
  }
8212
8243
  //# sourceMappingURL=cli.js.map
8213
- //# debugId=28cd5ca7-9197-5e2a-b7a3-beb912fc49ed
8244
+ //# debugId=2ac9292b-9c15-5fb7-bdc6-c773ad369497
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quatronic/qore",
3
- "version": "0.3.0-rc.1",
3
+ "version": "0.3.0-rc.3",
4
4
  "description": "Qore developer CLI",
5
5
  "type": "module",
6
6
  "bin": {