@apotech-os/cli 0.3.0 → 0.4.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.
package/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # @apotech-os/cli
2
+
3
+ CLI for Wopilo OS apps: scaffold locally, plan/apply your manifest against a
4
+ server, and publish releases.
5
+
6
+ ```sh
7
+ npm install -g @apotech-os/cli
8
+ ```
9
+
10
+ ## Remotes and login
11
+
12
+ ```sh
13
+ apotech-os remote add --url https://your-server.example.com --as production
14
+ apotech-os login --remote production
15
+ ```
16
+
17
+ `login` starts a browser-based approval (device-code flow): the CLI prints a
18
+ confirmation code and opens the web app, a platform admin checks that the code
19
+ matches and clicks **Autoriser**, and the CLI receives an API key and stores it
20
+ in `~/.wopilo/credentials.json` (mode `0600`).
21
+
22
+ The key is an ordinary platform API key, labelled with the requesting machine
23
+ and revocable at any time under _Paramètres › Clés API_.
24
+
25
+ On a headless machine you can open the printed URL from another device, or skip
26
+ the browser entirely and paste a key you created by hand:
27
+
28
+ ```sh
29
+ apotech-os login --remote production --with-key
30
+ ```
31
+
32
+ Environment variables work too, and take no `--remote`:
33
+
34
+ - `WOPILO_API_URL` — server API root. No `/api` prefix is added automatically.
35
+ - `WOPILO_API_KEY` — Bearer token.
36
+
37
+ ## Commands
38
+
39
+ | Command | What it does |
40
+ | ----------------------------------------------- | ------------------------------------------ |
41
+ | `apotech-os dev` | Watch and rebuild the app manifest locally |
42
+ | `apotech-os build` | Build the app bundle |
43
+ | `apotech-os plan --remote <name>` | Diff the local manifest against the server |
44
+ | `apotech-os apply --remote <name>` | Apply the manifest to the server |
45
+ | `apotech-os publish --remote <name>` | Publish a versioned release |
46
+ | `apotech-os remote add --url <url> --as <name>` | Register a remote |
47
+ | `apotech-os login --remote <name>` | Obtain and store an API key |
48
+
49
+ See `docs/app-platform/app-developer-guide.md` in the repo for the full guide.
package/dist/index.js CHANGED
@@ -22803,7 +22803,7 @@ var AppManifestSchema = external_exports.object({
22803
22803
  description: external_exports.string().optional(),
22804
22804
  icon: external_exports.string(),
22805
22805
  color: external_exports.string(),
22806
- // tailwind token, e.g. 'space-pilotage'
22806
+ // tailwind token, e.g. 'space-brand'
22807
22807
  placeholder: external_exports.boolean().optional(),
22808
22808
  // true for spaces with no views yet
22809
22809
  reads: external_exports.array(external_exports.string()),
@@ -22882,22 +22882,18 @@ var ShopifyOrderV1Schema = external_exports.object({
22882
22882
  shopifyId: external_exports.string(),
22883
22883
  createdAt: external_exports.coerce.date(),
22884
22884
  totalPrice: external_exports.number(),
22885
- // maps to totalPriceTTC in DB
22886
22885
  subtotalPrice: external_exports.number().nullable(),
22887
- // subtotalPriceSet (nullable until re-synced)
22888
22886
  totalDiscounts: external_exports.number().nullable(),
22889
- // totalDiscountsSet (nullable until re-synced)
22890
22887
  discountCode: external_exports.string().nullable(),
22891
22888
  newOrRepeat: external_exports.string().nullable(),
22892
22889
  financialStatus: external_exports.string().nullable(),
22893
22890
  note: external_exports.string().nullable(),
22894
- // maps to grapevineRaw in DB (order.note)
22895
22891
  customerId: external_exports.string().nullable()
22896
22892
  });
22897
22893
  var shopifyOrderV1 = {
22898
22894
  key: "shopify-order.v1",
22899
- prismaModel: "PilotageOrder",
22900
- appRecord: { appSlug: "pilotage", objectKey: "pilotage-order" },
22895
+ prismaModel: "AppRecord",
22896
+ appRecord: { appSlug: "_core", objectKey: "shopify-order" },
22901
22897
  schema: ShopifyOrderV1Schema,
22902
22898
  requiredRole: "VIEWER"
22903
22899
  };
@@ -23553,14 +23549,102 @@ function buildRemoteCommand() {
23553
23549
  }
23554
23550
 
23555
23551
  // src/commands/login.ts
23552
+ var import_child_process = require("child_process");
23553
+ var import_os4 = require("os");
23554
+ function clientLabel() {
23555
+ try {
23556
+ return `${(0, import_os4.userInfo)().username}@${(0, import_os4.hostname)()}`;
23557
+ } catch {
23558
+ return (0, import_os4.hostname)();
23559
+ }
23560
+ }
23561
+ function openBrowser(url2) {
23562
+ const command = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
23563
+ try {
23564
+ const child = (0, import_child_process.spawn)(command, [url2], {
23565
+ detached: true,
23566
+ stdio: "ignore",
23567
+ shell: process.platform === "win32"
23568
+ });
23569
+ child.on("error", () => void 0);
23570
+ child.unref();
23571
+ } catch {
23572
+ }
23573
+ }
23574
+ function sleep(ms) {
23575
+ return new Promise((resolve4) => setTimeout(resolve4, ms));
23576
+ }
23577
+ async function postJson(url2, body) {
23578
+ const res = await fetch(url2, {
23579
+ method: "POST",
23580
+ headers: { "Content-Type": "application/json" },
23581
+ body: JSON.stringify(body)
23582
+ });
23583
+ const parsed = await res.json().catch(() => void 0);
23584
+ return { status: res.status, body: parsed };
23585
+ }
23586
+ async function promptForKey(remote) {
23587
+ const passwordMod = await Promise.resolve().then(() => (init_esm5(), esm_exports2));
23588
+ const password = passwordMod.default;
23589
+ const key = await password({ message: `API key for "${remote}":` });
23590
+ storeApiKey(remote, key);
23591
+ console.log(`Credentials stored for remote "${remote}".`);
23592
+ }
23593
+ async function browserLogin(remote, baseUrl) {
23594
+ const device = await postJson(`${baseUrl.replace(/\/$/, "")}/platform/cli-auth/device`, {
23595
+ clientLabel: clientLabel()
23596
+ });
23597
+ if (device.status === 404) {
23598
+ console.log("This server does not support browser login yet \u2014 falling back to an API key.");
23599
+ console.log("Create one in the web app under Param\xE8tres \u203A Cl\xE9s API.");
23600
+ await promptForKey(remote);
23601
+ return;
23602
+ }
23603
+ if (device.status >= 400) {
23604
+ throw new Error(`Could not start the login flow (HTTP ${device.status}).`);
23605
+ }
23606
+ const auth = device.body;
23607
+ console.log(`Opening ${auth.verificationUriComplete} in your browser\u2026`);
23608
+ console.log(` Confirmation code: ${auth.userCode}`);
23609
+ console.log(" (If the browser did not open, visit the URL above.)");
23610
+ openBrowser(auth.verificationUriComplete);
23611
+ const key = await pollForKey(baseUrl, auth);
23612
+ storeApiKey(remote, key);
23613
+ console.log(`Logged in to remote "${remote}". Credentials stored in ~/.wopilo/credentials.json.`);
23614
+ }
23615
+ async function pollForKey(baseUrl, auth) {
23616
+ const tokenUrl = `${baseUrl.replace(/\/$/, "")}/platform/cli-auth/token`;
23617
+ const deadline = Date.now() + auth.expiresIn * 1e3;
23618
+ process.stdout.write("Waiting for approval\u2026 ");
23619
+ while (Date.now() < deadline) {
23620
+ await sleep(auth.interval * 1e3);
23621
+ if (Date.now() >= deadline) break;
23622
+ const res = await postJson(tokenUrl, { deviceCode: auth.deviceCode });
23623
+ const result = res.body;
23624
+ if (result?.status === "approved") {
23625
+ console.log("\u2713");
23626
+ return result.apiKey;
23627
+ }
23628
+ if (result?.status === "denied") {
23629
+ console.log("\u2717");
23630
+ throw new Error("Login was denied in the browser.");
23631
+ }
23632
+ if (result?.status === "expired") {
23633
+ console.log("\u2717");
23634
+ throw new Error("Login request expired. Run the command again.");
23635
+ }
23636
+ }
23637
+ console.log("\u2717");
23638
+ throw new Error("Login request expired. Run the command again.");
23639
+ }
23556
23640
  function buildLoginCommand() {
23557
- return new Command("login").description("Store an API key for a remote server").requiredOption("--remote <name>", "Remote alias").action(async (opts) => {
23558
- getRemoteUrl(opts.remote);
23559
- const passwordMod = await Promise.resolve().then(() => (init_esm5(), esm_exports2));
23560
- const password = passwordMod.default;
23561
- const key = await password({ message: `API key for "${opts.remote}":` });
23562
- storeApiKey(opts.remote, key);
23563
- console.log(`Credentials stored for remote "${opts.remote}".`);
23641
+ return new Command("login").description("Log in to a remote server (opens your browser)").requiredOption("--remote <name>", "Remote alias").option("--with-key", "Paste an existing API key instead of using the browser (CI/headless)").action(async (opts) => {
23642
+ const baseUrl = getRemoteUrl(opts.remote);
23643
+ if (opts.withKey) {
23644
+ await promptForKey(opts.remote);
23645
+ return;
23646
+ }
23647
+ await browserLogin(opts.remote, baseUrl);
23564
23648
  });
23565
23649
  }
23566
23650