@apso/cli 0.49.2 → 0.50.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.
@@ -28,3 +28,18 @@ export default class Deploy extends BaseCommand {
28
28
  */
29
29
  private resolveRepo;
30
30
  }
31
+ type SignInCommand = Pick<BaseCommand, "log" | "error"> & {
32
+ config: {
33
+ runCommand: (id: string, argv?: string[]) => Promise<unknown>;
34
+ };
35
+ };
36
+ /**
37
+ * Deploy signs you in instead of stopping. The browser flow needs no TTY, so
38
+ * an agent can run deploy and the person finishes sign-in in the browser. CI
39
+ * has nobody to do that, so it still fails with the token instructions.
40
+ *
41
+ * @param {SignInCommand} cmd - The running command.
42
+ * @returns {Promise<void>} Resolves once valid credentials are stored.
43
+ */
44
+ export declare function signInIfNeeded(cmd: SignInCommand): Promise<void>;
45
+ export {};
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.signInIfNeeded = void 0;
3
4
  const tslib_1 = require("tslib");
4
5
  const core_1 = require("@oclif/core");
5
6
  const base_command_1 = tslib_1.__importDefault(require("../lib/base-command"));
@@ -17,10 +18,7 @@ class Deploy extends base_command_1.default {
17
18
  async run() {
18
19
  const { flags } = await this.parse(Deploy);
19
20
  const env = (0, environments_1.asEnv)(flags.env);
20
- // Auth guard
21
- if (!config_1.credentials.isValid()) {
22
- this.error("Not logged in. Run 'apso login' first.");
23
- }
21
+ await signInIfNeeded(this);
24
22
  // Link guard
25
23
  const link = config_1.projectLink.read();
26
24
  if (!link) {
@@ -310,3 +308,22 @@ Deploy.flags = {
310
308
  }),
311
309
  };
312
310
  exports.default = Deploy;
311
+ /**
312
+ * Deploy signs you in instead of stopping. The browser flow needs no TTY, so
313
+ * an agent can run deploy and the person finishes sign-in in the browser. CI
314
+ * has nobody to do that, so it still fails with the token instructions.
315
+ *
316
+ * @param {SignInCommand} cmd - The running command.
317
+ * @returns {Promise<void>} Resolves once valid credentials are stored.
318
+ */
319
+ async function signInIfNeeded(cmd) {
320
+ if (config_1.credentials.isValid())
321
+ return;
322
+ if (process.env.CI === "true" || process.env.CI === "1")
323
+ cmd.error('Not logged in. In CI, run `apso login --token "$APSO_API_TOKEN"` before `apso deploy`.');
324
+ cmd.log("You're not signed in to Apso, so signing in first.");
325
+ await cmd.config.runCommand("login");
326
+ if (!config_1.credentials.isValid())
327
+ cmd.error("Sign-in didn't finish. Run 'apso login', then re-run deploy.");
328
+ }
329
+ exports.signInIfNeeded = signInIfNeeded;
@@ -16,8 +16,9 @@ const lib_1 = require("../../lib");
16
16
  const runner_1 = require("../../lib/doctor/runner");
17
17
  const crud_deps_1 = require("../../lib/utils/crud-deps");
18
18
  const file_system_1 = require("../../lib/utils/file-system");
19
- const schema_convert_1 = require("../../lib/utils/schema-convert");
20
19
  const mcp_schema_tools_1 = require("../../lib/mcp-schema-tools");
20
+ const schema_tools_1 = require("@apso/schema-tools");
21
+ const validate_1 = require("../schema/validate");
21
22
  const perf_hooks_1 = require("perf_hooks");
22
23
  class McpServe extends base_command_1.default {
23
24
  async run() {
@@ -176,18 +177,26 @@ class McpServe extends base_command_1.default {
176
177
  .optional()
177
178
  .describe("Optional: JSON string of a schema to validate. If not provided, reads .apsorc from the current directory."),
178
179
  }, async ({ schema_json }) => {
179
- var _a, _b, _c;
180
+ var _a, _b;
180
181
  try {
181
182
  if (schema_json) {
182
183
  // Validate the provided JSON
183
184
  const schema = JSON.parse(schema_json);
184
185
  const errors = validateSchemaObject(schema);
186
+ let lintReport = "";
187
+ if (errors.length === 0) {
188
+ const lint = (0, schema_tools_1.lintSchema)(schema);
189
+ if (lint.issues.length > 0)
190
+ lintReport = `${(0, schema_tools_1.formatLintReport)(lint)}\n\n`;
191
+ if (lint.errorCount > 0)
192
+ errors.push(`${lint.errorCount} lint error(s), listed above.`);
193
+ }
185
194
  if (errors.length > 0) {
186
195
  return {
187
196
  content: [
188
197
  {
189
198
  type: "text",
190
- text: `Validation failed with ${errors.length} error(s):\n${errors.map((e) => ` - ${e}`).join("\n")}`,
199
+ text: `${lintReport}Validation failed with ${errors.length} error(s):\n${errors.map((e) => ` - ${e}`).join("\n")}`,
191
200
  },
192
201
  ],
193
202
  isError: true,
@@ -218,46 +227,21 @@ class McpServe extends base_command_1.default {
218
227
  isError: true,
219
228
  };
220
229
  }
221
- const parsed = (0, apsorc_parser_1.parseApsorc)();
222
- const schema = (0, schema_convert_1.apsorcToServiceSchema)(parsed);
223
- const entityCount = schema.entities.length;
224
- let fieldCount = 0;
225
- let relationshipCount = 0;
226
- const errors = [];
227
- for (const entity of schema.entities) {
228
- fieldCount += entity.fields.length;
229
- relationshipCount += ((_c = entity.relationships) === null || _c === void 0 ? void 0 : _c.length) || 0;
230
- if (!entity.name || entity.name.trim() === "") {
231
- errors.push("Entity found with empty name");
232
- }
233
- if (entity.relationships) {
234
- for (const rel of entity.relationships) {
235
- const targetExists = schema.entities.some((e) => e.name === rel.target);
236
- if (!targetExists) {
237
- errors.push(`Entity "${entity.name}": relationship target "${rel.target}" does not reference an existing entity`);
238
- }
239
- }
240
- }
230
+ // The same checks as `apso schema validate --local`
231
+ const check = await (0, validate_1.localSchemaCheck)();
232
+ const lines = [];
233
+ if (check.lintReport)
234
+ lines.push(check.lintReport, "");
235
+ if (check.stats)
236
+ lines.push(`Schema: ${check.stats.entities} entities, ${check.stats.fields} fields, ${check.stats.relationships} relationships`);
237
+ for (const warning of check.warnings)
238
+ lines.push(`Warning: ${warning}`);
239
+ if (check.errors.length > 0) {
240
+ lines.push("", `Validation failed with ${check.errors.length} error(s):`, ...check.errors.map((e) => ` - ${e}`));
241
+ return { content: [{ type: "text", text: lines.join("\n") }], isError: true };
241
242
  }
242
- if (errors.length > 0) {
243
- return {
244
- content: [
245
- {
246
- type: "text",
247
- text: `Schema: ${entityCount} entities, ${fieldCount} fields, ${relationshipCount} relationships\n\nValidation failed with ${errors.length} error(s):\n${errors.map((e) => ` - ${e}`).join("\n")}`,
248
- },
249
- ],
250
- isError: true,
251
- };
252
- }
253
- return {
254
- content: [
255
- {
256
- type: "text",
257
- text: `Schema: ${entityCount} entities, ${fieldCount} fields, ${relationshipCount} relationships\nValidation passed.`,
258
- },
259
- ],
260
- };
243
+ lines.push("Validation passed.");
244
+ return { content: [{ type: "text", text: lines.join("\n") }] };
261
245
  }
262
246
  catch (error) {
263
247
  const msg = error instanceof Error ? error.message : String(error);
@@ -9,6 +9,27 @@ import { ParsedApsorc } from "../../lib/apsorc-parser";
9
9
  * @returns {Promise<string[]>} One message per problem; empty when there are none.
10
10
  */
11
11
  export declare function accessRuleErrors(parsed: Pick<ParsedApsorc, "rootFolder" | "apiType" | "entities" | "relationshipMap" | "auth" | "language">): Promise<string[]>;
12
+ export interface LocalSchemaCheck {
13
+ /** The lint report, empty when the linter found nothing. */
14
+ lintReport: string;
15
+ errors: string[];
16
+ warnings: string[];
17
+ /** Set once the file parsed; absent when lint errors stopped the check first. */
18
+ parsed?: ParsedApsorc;
19
+ stats?: {
20
+ entities: number;
21
+ fields: number;
22
+ relationships: number;
23
+ };
24
+ }
25
+ /**
26
+ * Every check `apso schema validate --local` runs on the project's .apsorc.
27
+ * The CLI command and the MCP validate_schema tool both call this, so an
28
+ * agent gets the same answer from either.
29
+ *
30
+ * @returns {Promise<LocalSchemaCheck>} The lint report, errors and warnings.
31
+ */
32
+ export declare function localSchemaCheck(): Promise<LocalSchemaCheck>;
12
33
  export default class SchemaValidate extends BaseCommand {
13
34
  static description: string;
14
35
  static examples: string[];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.accessRuleErrors = void 0;
3
+ exports.localSchemaCheck = exports.accessRuleErrors = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const core_1 = require("@oclif/core");
6
6
  const base_command_1 = tslib_1.__importDefault(require("../../lib/base-command"));
@@ -58,67 +58,73 @@ async function accessRuleErrors(parsed) {
58
58
  return [...new Set(errors)];
59
59
  }
60
60
  exports.accessRuleErrors = accessRuleErrors;
61
- class SchemaValidate extends base_command_1.default {
62
- async run() {
63
- var _a;
64
- const { flags } = await this.parse(SchemaValidate);
65
- // Lint first so every issue is listed, not just the first one parseApsorc throws on
66
- let file;
67
- try {
68
- file = (0, apsorc_parser_1.readApsorcFile)();
61
+ /**
62
+ * Every check `apso schema validate --local` runs on the project's .apsorc.
63
+ * The CLI command and the MCP validate_schema tool both call this, so an
64
+ * agent gets the same answer from either.
65
+ *
66
+ * @returns {Promise<LocalSchemaCheck>} The lint report, errors and warnings.
67
+ */
68
+ async function localSchemaCheck() {
69
+ var _a, _b;
70
+ const result = { lintReport: "", errors: [], warnings: [] };
71
+ // Lint first so every issue is listed, not just the first one parseApsorc throws on
72
+ const file = (0, apsorc_parser_1.readApsorcFile)();
73
+ if (file.apsorc.version === 2) {
74
+ const lint = (0, schema_tools_1.lintSchema)(file.apsorc);
75
+ if (lint.issues.length > 0)
76
+ result.lintReport = (0, schema_tools_1.formatLintReport)(lint);
77
+ if (lint.errorCount > 0) {
78
+ result.errors.push(`${lint.errorCount} lint error(s). Run "apso schema lint --fix" to apply the safe fixes.`);
79
+ return result;
69
80
  }
70
- catch (error) {
71
- const msg = error instanceof Error ? error.message : String(error);
72
- this.error(`Failed to read .apsorc: ${msg}`);
81
+ }
82
+ const parsed = (0, apsorc_parser_1.parseApsorc)();
83
+ result.parsed = parsed;
84
+ result.warnings.push(...(0, guards_1.tenantClaimWarnings)(parsed.entities, parsed.auth));
85
+ const schema = (0, schema_convert_1.apsorcToServiceSchema)(parsed);
86
+ let fields = 0;
87
+ let relationships = 0;
88
+ for (const entity of schema.entities) {
89
+ fields += entity.fields.length;
90
+ relationships += ((_a = entity.relationships) === null || _a === void 0 ? void 0 : _a.length) || 0;
91
+ if (!entity.name || entity.name.trim() === "") {
92
+ result.errors.push("Entity found with empty name");
73
93
  }
74
- if (file.apsorc.version === 2) {
75
- const lint = (0, schema_tools_1.lintSchema)(file.apsorc);
76
- if (lint.issues.length > 0) {
77
- this.log((0, schema_tools_1.formatLintReport)(lint));
78
- this.log("");
79
- }
80
- if (lint.errorCount > 0) {
81
- this.error(`Validation failed with ${lint.errorCount} lint error(s). Run "apso schema lint --fix" to apply the safe fixes.`);
94
+ for (const rel of (_b = entity.relationships) !== null && _b !== void 0 ? _b : []) {
95
+ if (!schema.entities.some((e) => e.name === rel.target)) {
96
+ result.errors.push(`Entity "${entity.name}": relationship target "${rel.target}" does not reference an existing entity`);
82
97
  }
83
98
  }
84
- // Parse .apsorc
85
- let parsed;
99
+ }
100
+ result.stats = { entities: schema.entities.length, fields, relationships };
101
+ // The rules apso generate enforces for auth, permissions and mcp
102
+ result.errors.push(...(await accessRuleErrors(parsed)));
103
+ return result;
104
+ }
105
+ exports.localSchemaCheck = localSchemaCheck;
106
+ class SchemaValidate extends base_command_1.default {
107
+ async run() {
108
+ const { flags } = await this.parse(SchemaValidate);
109
+ let check;
86
110
  try {
87
- parsed = (0, apsorc_parser_1.parseApsorc)();
111
+ check = await localSchemaCheck();
88
112
  }
89
113
  catch (error) {
90
114
  const msg = error instanceof Error ? error.message : String(error);
91
- this.error(`Failed to parse .apsorc: ${msg}`);
115
+ this.error(`Failed to read or parse .apsorc: ${msg}`);
116
+ }
117
+ if (check.lintReport) {
118
+ this.log(check.lintReport);
119
+ this.log("");
92
120
  }
93
- for (const warning of (0, guards_1.tenantClaimWarnings)(parsed.entities, parsed.auth))
121
+ if (!check.parsed)
122
+ this.error(`Validation failed with ${check.errors[0]}`);
123
+ for (const warning of check.warnings)
94
124
  this.warn(warning);
95
- // Convert to platform schema format
125
+ const { errors, parsed } = check;
96
126
  const schema = (0, schema_convert_1.apsorcToServiceSchema)(parsed);
97
- // Count stats
98
- const entityCount = schema.entities.length;
99
- let fieldCount = 0;
100
- let relationshipCount = 0;
101
- for (const entity of schema.entities) {
102
- fieldCount += entity.fields.length;
103
- relationshipCount += ((_a = entity.relationships) === null || _a === void 0 ? void 0 : _a.length) || 0;
104
- }
105
- // Local validation
106
- const errors = [];
107
- for (const entity of schema.entities) {
108
- if (!entity.name || entity.name.trim() === "") {
109
- errors.push("Entity found with empty name");
110
- }
111
- if (entity.relationships) {
112
- for (const rel of entity.relationships) {
113
- const targetExists = schema.entities.some((e) => e.name === rel.target);
114
- if (!targetExists) {
115
- errors.push(`Entity "${entity.name}": relationship target "${rel.target}" does not reference an existing entity`);
116
- }
117
- }
118
- }
119
- }
120
- // The rules apso generate enforces for auth, permissions and mcp
121
- errors.push(...(await accessRuleErrors(parsed)));
127
+ const { entities: entityCount, fields: fieldCount, relationships: relationshipCount } = check.stats;
122
128
  // Server validation if linked and not --local
123
129
  const isLinked = config_1.projectLink.exists();
124
130
  const isAuthenticated = config_1.credentials.isValid();
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@apso/cli",
3
- "version": "0.49.2",
3
+ "version": "0.50.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@apso/cli",
9
- "version": "0.49.2",
9
+ "version": "0.50.0",
10
10
  "license": "Apache-2.0",
11
11
  "dependencies": {
12
12
  "@apso/schema-tools": "^0.2.2",
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.49.2",
2
+ "version": "0.50.0",
3
3
  "commands": {
4
4
  "config": {
5
5
  "id": "config",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apso/cli",
3
- "version": "0.49.2",
3
+ "version": "0.50.0",
4
4
  "mcpName": "io.github.apsoai/apso",
5
5
  "description": "Apso CLI",
6
6
  "author": "Apso by Mavric - @mavric",