@supacloud/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.
Files changed (2) hide show
  1. package/dist/index.js +173 -17
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -184371,9 +184371,10 @@ async function analyzeProject(rootDir, include, cache, changedPaths) {
184371
184371
  className: classInfo.decl.name?.text ?? name,
184372
184372
  name: stringLiteralProp(meta, "name") ?? classInfo.decl.name?.text ?? name,
184373
184373
  permission: stringLiteralProp(meta, "permission"),
184374
- transaction: commandModeProp(meta, "transaction") ?? "none",
184374
+ rpc: checkedRpc(meta, ctx),
184375
+ transaction: checkedCommandMode(meta, "transaction", ctx, classInfo.decl.name?.text ?? name) ?? "none",
184375
184376
  audit: stringLiteralProp(meta, "audit"),
184376
- idempotency: commandModeProp(meta, "idempotency") ?? "none",
184377
+ idempotency: checkedCommandMode(meta, "idempotency", ctx, classInfo.decl.name?.text ?? name) ?? "none",
184377
184378
  standalone: true,
184378
184379
  aspects: parseAspectRefs(getProp(meta, "aspects"), ctx, `command ${classInfo.decl.name?.text ?? name}`)
184379
184380
  });
@@ -184663,9 +184664,10 @@ function parseModule(candidate, nameByNode, ctx) {
184663
184664
  className: cls.name?.text ?? "<anonymous>",
184664
184665
  name: stringLiteralProp(meta, "name") ?? cls.name?.text ?? "<anonymous>",
184665
184666
  permission: stringLiteralProp(meta, "permission"),
184666
- transaction: commandModeProp(meta, "transaction") ?? "none",
184667
+ rpc: checkedRpc(meta, ctx),
184668
+ transaction: checkedCommandMode(meta, "transaction", ctx, cls.name?.text ?? "<anonymous>") ?? "none",
184667
184669
  audit: stringLiteralProp(meta, "audit"),
184668
- idempotency: commandModeProp(meta, "idempotency") ?? "none",
184670
+ idempotency: checkedCommandMode(meta, "idempotency", ctx, cls.name?.text ?? "<anonymous>") ?? "none",
184669
184671
  ...booleanProp(meta, "standalone") ? { standalone: true } : {},
184670
184672
  ...aspects2.length > 0 ? { aspects: aspects2 } : {}
184671
184673
  });
@@ -184795,6 +184797,31 @@ function commandModeProp(object, name) {
184795
184797
  const value = stringLiteralProp(object, name);
184796
184798
  return value === "required" || value === "none" ? value : undefined;
184797
184799
  }
184800
+ function checkedCommandMode(object, property, ctx, command) {
184801
+ const expression = getProp(object, property);
184802
+ const value = commandModeProp(object, property);
184803
+ if (expression && value === undefined) {
184804
+ const file = sourcePath(ctx.rootDir, expression.getSourceFile().fileName);
184805
+ ctx.diagnostics.push({
184806
+ severity: "error",
184807
+ code: "invalid-command-mode",
184808
+ errorCode: "SC4012",
184809
+ docsUrl: "https://supacloud.dev/errors/SC4012",
184810
+ message: `${command}.${property} must be the explicit literal "required" or "none"; invalid governance cannot be disabled silently.`,
184811
+ file,
184812
+ line: lineOf(expression),
184813
+ suggestion: `Choose the intended ${property} policy explicitly; use set_command_mode with value "required" or "none".`,
184814
+ fix: {
184815
+ type: "set_command_mode",
184816
+ targetFile: file,
184817
+ command,
184818
+ property,
184819
+ expectedExpression: nodeText(expression)
184820
+ }
184821
+ });
184822
+ }
184823
+ return value;
184824
+ }
184798
184825
  function parseProvider(el, exportsSet, ctx) {
184799
184826
  const file = sourcePath(ctx.rootDir, el.getSourceFile().fileName);
184800
184827
  const line = lineOf(el);
@@ -185255,6 +185282,10 @@ function parseController(input, ctx) {
185255
185282
  path: routePath,
185256
185283
  handler: propertyName(method.name)
185257
185284
  };
185285
+ const signature = ctx.checker.getSignatureFromDeclaration(method);
185286
+ const resultType = signature && ctx.checker.typeToString(signature.getReturnType());
185287
+ if (resultType && /\bResponse\b/.test(resultType))
185288
+ route.nativeResponse = true;
185258
185289
  const pathParams = [];
185259
185290
  const paramRegex = /:([a-zA-Z0-9_]+)/g;
185260
185291
  let match;
@@ -185403,6 +185434,23 @@ function parseController(input, ctx) {
185403
185434
  }
185404
185435
  const optionsArg = args[1];
185405
185436
  if (optionsArg && ts3.isObjectLiteralExpression(optionsArg)) {
185437
+ const contract = getProp(optionsArg, "contract");
185438
+ if (contract && ts3.isObjectLiteralExpression(contract)) {
185439
+ route.contract = {};
185440
+ for (const field of ["body", "response", "evidence"]) {
185441
+ const value = stringLiteralProp(contract, field);
185442
+ const allowed = field === "body" ? ["framework", "domain"] : field === "response" ? ["framework", "native-json", "binary", "stream"] : undefined;
185443
+ if (getProp(contract, field) && (!value || allowed && !allowed.includes(value))) {
185444
+ ctx.diagnostics.push({
185445
+ severity: "error",
185446
+ code: "invalid-route-contract",
185447
+ file,
185448
+ message: `Invalid contract.${field} on ${route.handler}; use an explicit supported string literal.`
185449
+ });
185450
+ } else if (value)
185451
+ Object.assign(route.contract, { [field]: value });
185452
+ }
185453
+ }
185406
185454
  for (const field of ["body", "params", "query", "response"]) {
185407
185455
  const schemaExpr = getProp(optionsArg, field);
185408
185456
  if (schemaExpr && ts3.isIdentifier(schemaExpr)) {
@@ -185410,6 +185458,11 @@ function parseController(input, ctx) {
185410
185458
  const importPath = importPathOf(schemaExpr, ctx);
185411
185459
  if (importPath)
185412
185460
  schemaImports[schemaExpr.text] = importPath;
185461
+ const declaration = resolveDeclaration(schemaExpr, ctx)[0];
185462
+ const typeName = ctx.checker.typeToString(ctx.checker.getTypeAtLocation(schemaExpr));
185463
+ const initializer = declaration && ts3.isVariableDeclaration(declaration) ? declaration.initializer : undefined;
185464
+ const opaque = /\bT(?:Unknown|Any)\b/.test(typeName) || initializer && ts3.isCallExpression(initializer) && ts3.isPropertyAccessExpression(initializer.expression) && ["Unknown", "Any"].includes(initializer.expression.name.text);
185465
+ (route.schemaKinds ??= {})[field] = opaque ? "opaque" : "declared";
185413
185466
  }
185414
185467
  }
185415
185468
  const commandExpr = getProp(optionsArg, "command");
@@ -185504,6 +185557,23 @@ function parseController(input, ctx) {
185504
185557
  schemaImports: Object.keys(schemaImports).length > 0 ? schemaImports : undefined
185505
185558
  };
185506
185559
  }
185560
+ function checkedRpc(meta, ctx) {
185561
+ const expression = getProp(meta, "rpc");
185562
+ if (!expression)
185563
+ return;
185564
+ const value = stringLiteralProp(meta, "rpc");
185565
+ if (value?.trim())
185566
+ return value;
185567
+ ctx.diagnostics.push({
185568
+ severity: "error",
185569
+ code: "invalid-command-rpc",
185570
+ file: sourcePath(ctx.rootDir, meta.getSourceFile().fileName),
185571
+ line: lineOf(meta),
185572
+ message: "Command rpc must be a non-empty string literal identifying a configured adapter.",
185573
+ suggestion: "Declare a named RPC adapter and its tested persistence capabilities."
185574
+ });
185575
+ return;
185576
+ }
185507
185577
  function classDeps(cls, ctx) {
185508
185578
  const injectable = parseInjectableOptions(cls, ctx);
185509
185579
  const ctor = cls.members.find(ts3.isConstructorDeclaration);
@@ -185859,6 +185929,7 @@ function parseAspectRefs(expression, ctx, owner) {
185859
185929
  const declaredFile = declaration.getSourceFile().fileName;
185860
185930
  const projectLocal = isProjectSourcePath(declaredFile, ctx.rootDir);
185861
185931
  refs.push({
185932
+ ...projectLocal ? { file: sourcePath(ctx.rootDir, declaredFile) } : {},
185862
185933
  name,
185863
185934
  expression: element.text,
185864
185935
  importPath: projectLocal ? modulePath(ctx.rootDir, declaredFile) : undefined,
@@ -186044,6 +186115,7 @@ var INTERFACES = `export interface CompiledRoute {
186044
186115
  }
186045
186116
 
186046
186117
  export interface CompiledCommand {
186118
+ rpc?: string;
186047
186119
  className: string;
186048
186120
  name: string;
186049
186121
  permission: string;
@@ -186569,6 +186641,7 @@ ${indent(item, 2)}`).join(",")}
186569
186641
  `transaction: ${JSON.stringify(command.transaction)}`,
186570
186642
  ...command.audit ? [`audit: ${JSON.stringify(command.audit)}`] : [],
186571
186643
  `idempotency: ${JSON.stringify(command.idempotency)}`,
186644
+ ...command.rpc ? [`rpc: ${JSON.stringify(command.rpc)}`] : [],
186572
186645
  ...command.standalone ? ["standalone: true"] : [],
186573
186646
  ...command.aspects && command.aspects.length > 0 ? [`aspects: ${this.renderAspects(command.aspects)}`] : []
186574
186647
  ];
@@ -187329,6 +187402,10 @@ var COMPILER_DIAGNOSTIC_CODES = {
187329
187402
  "invalid-job-scope": { code: "SC4007", docsUrl: "https://supacloud.dev/errors/SC4007" },
187330
187403
  "dynamic-aspect-reference": { code: "SC4010", docsUrl: "https://supacloud.dev/errors/SC4010" },
187331
187404
  "invalid-aspect-reference": { code: "SC4011", docsUrl: "https://supacloud.dev/errors/SC4011" },
187405
+ "invalid-command-mode": { code: "SC4012", docsUrl: "https://supacloud.dev/errors/SC4012" },
187406
+ "invalid-command-rpc": { code: "SC4013", docsUrl: "https://supacloud.dev/errors/SC4013" },
187407
+ "command-rpc-unavailable": { code: "SC4014", docsUrl: "https://supacloud.dev/errors/SC4014" },
187408
+ "invalid-route-contract": { code: "SC3020", docsUrl: "https://supacloud.dev/errors/SC3020" },
187332
187409
  "unused-root-provider": { code: "SC5001", docsUrl: "https://supacloud.dev/errors/SC5001" },
187333
187410
  "invalid-feature-states": { code: "SC6001", docsUrl: "https://supacloud.dev/errors/SC6001" },
187334
187411
  "duplicate-feature-transition": { code: "SC6002", docsUrl: "https://supacloud.dev/errors/SC6002" },
@@ -187758,8 +187835,18 @@ function validateGraph(graph, options = false) {
187758
187835
  permission: `${module.name}.${command.name}`
187759
187836
  });
187760
187837
  }
187838
+ if (command.rpc && (typeof options !== "object" || !Object.hasOwn(options.commandCapabilities?.rpc ?? {}, command.rpc))) {
187839
+ error("command-rpc-unavailable", `Command ${command.name} requires configured RPC adapter '${command.rpc}'.`, module.file, module.line);
187840
+ }
187761
187841
  if (typeof options === "object" && options.commandCapabilities) {
187762
- const caps = options.commandCapabilities;
187842
+ const hostCaps = options.commandCapabilities;
187843
+ const rpcCaps = command.rpc && Object.hasOwn(hostCaps.rpc ?? {}, command.rpc) ? hostCaps.rpc?.[command.rpc] : undefined;
187844
+ const caps = command.rpc ? {
187845
+ permission: hostCaps.permission,
187846
+ audit: rpcCaps?.audit === true,
187847
+ transaction: rpcCaps?.transaction === true,
187848
+ idempotency: rpcCaps?.idempotency === true
187849
+ } : hostCaps;
187763
187850
  const location = `${command.className} (${module.file})`;
187764
187851
  if (command.permission && caps.permission === false) {
187765
187852
  error("command-permission-unsupported", `Command ${command.name} declares permission, but runtime permission checks are unavailable (${location}).`, module.file, module.line);
@@ -188320,8 +188407,10 @@ function inspectRouteContracts(graph) {
188320
188407
  missing.push("params");
188321
188408
  if ((route.queryBindings?.length || route.handlerParams?.some((param) => param.kind === "query")) && !route.query)
188322
188409
  missing.push("query");
188323
- if (!route.response)
188410
+ if (!route.response && !["binary", "stream"].includes(route.contract?.response ?? ""))
188324
188411
  missing.push("response");
188412
+ const body = !route.body ? "missing" : route.contract?.body === "domain" ? "domain" : route.schemaKinds?.body === "opaque" ? "opaque" : "framework-declared";
188413
+ const response = route.contract?.response ?? (route.nativeResponse ? "native-response-unclassified" : route.schemaKinds?.response === "opaque" ? "opaque" : !route.response ? "missing" : "framework-declared");
188325
188414
  return {
188326
188415
  module: module.name,
188327
188416
  controller: controller.className,
@@ -188329,7 +188418,21 @@ function inspectRouteContracts(graph) {
188329
188418
  method: route.method,
188330
188419
  path: `${controller.path}${route.path}`,
188331
188420
  file: controller.file,
188332
- missing
188421
+ missing,
188422
+ validation: {
188423
+ body,
188424
+ response,
188425
+ schemas: route.schemaKinds ?? {},
188426
+ evidence: route.contract?.evidence ?? null,
188427
+ verified: false,
188428
+ obligations: [
188429
+ "Exercise actual HTTP request and response boundaries.",
188430
+ ...response === "opaque" ? ["Decode the response's business fields; an opaque schema accepts unvalidated output."] : [],
188431
+ ...body === "domain" || body === "opaque" ? ["Prove invalid input is rejected by the domain before writes."] : [],
188432
+ ...response === "native-json" || response === "native-response-unclassified" ? ["Validate serialized JSON explicitly; native Response bypasses framework response schemas."] : [],
188433
+ ...["binary", "stream"].includes(response) ? ["Test transport headers, access and bytes without JSON decoding."] : []
188434
+ ]
188435
+ }
188333
188436
  };
188334
188437
  })));
188335
188438
  }
@@ -188397,7 +188500,7 @@ async function compileProject(options) {
188397
188500
  treeShakeUnusedProviders: options.treeShakeUnusedProviders,
188398
188501
  artifactHashes: options.cache?.generatedHashes
188399
188502
  };
188400
- const written = !hasErrors || options.writeOnError !== false ? await generateApplication(graph, generatedOptions) : [];
188503
+ const written = !hasErrors || options.writeOnError === true ? await generateApplication(graph, generatedOptions) : [];
188401
188504
  const stats = graph.cacheStats ? {
188402
188505
  cacheHit: graph.cacheStats.reanalyzedModules.length === 0,
188403
188506
  changedFiles: [],
@@ -188802,7 +188905,7 @@ test("partial and untagged inherited remote profiles cannot mix with selected fi
188802
188905
  // ../compiler/package.json
188803
188906
  var package_default = {
188804
188907
  name: "@supacloud/compiler",
188805
- version: "0.11.0",
188908
+ version: "0.12.0",
188806
188909
  description: "Static compiler for @supacloud/app metadata: builds the application graph from AST, validates it, and generates reflection-free factory code",
188807
188910
  type: "module",
188808
188911
  main: "./dist/index.js",
@@ -188857,13 +188960,18 @@ var package_default = {
188857
188960
  // ../app/package.json
188858
188961
  var package_default2 = {
188859
188962
  name: "@supacloud/app",
188860
- version: "0.10.0",
188963
+ version: "0.11.0",
188861
188964
  description: "Angular-style application metadata for SupaCloud: modules, DI tokens, providers, scopes, controllers and commands",
188862
188965
  type: "module",
188863
188966
  main: "./dist/index.js",
188864
188967
  module: "./dist/index.js",
188865
188968
  types: "./dist/index.d.ts",
188866
188969
  exports: {
188970
+ "./contracts": {
188971
+ types: "./dist/contract_client.d.ts",
188972
+ import: "./dist/contract_client.js",
188973
+ default: "./dist/contract_client.js"
188974
+ },
188867
188975
  ".": {
188868
188976
  types: "./dist/index.d.ts",
188869
188977
  import: "./dist/index.js",
@@ -188876,7 +188984,7 @@ var package_default2 = {
188876
188984
  ],
188877
188985
  scripts: {
188878
188986
  build: "bun run clean && bun run build:js && bun run build:types",
188879
- "build:js": "bun build src/index.ts --outdir dist --target node",
188987
+ "build:js": "bun build src/index.ts --outdir dist --target node && bun build src/contract_client.ts --outdir dist --target browser",
188880
188988
  "build:types": "tsc -p tsconfig.json --emitDeclarationOnly",
188881
188989
  clean: "rm -rf dist",
188882
188990
  prepublishOnly: "bun run build",
@@ -188908,7 +189016,7 @@ var package_default2 = {
188908
189016
  // ../elysia/package.json
188909
189017
  var package_default3 = {
188910
189018
  name: "@supacloud/elysia",
188911
- version: "0.8.1",
189019
+ version: "0.10.0",
188912
189020
  description: "Elysia runtime adapter for SupaCloud compiled modules: application/request scopes, route registration and validation",
188913
189021
  type: "module",
188914
189022
  main: "./dist/index.js",
@@ -188927,7 +189035,7 @@ var package_default3 = {
188927
189035
  ],
188928
189036
  scripts: {
188929
189037
  build: "bun run clean && bun run build:js && bun run build:types",
188930
- "build:js": "bun build src/index.ts --outdir dist --target node --external elysia",
189038
+ "build:js": "bun build src/index.ts --outdir dist --target node --external elysia --external jose",
188931
189039
  "build:types": "tsc -p tsconfig.json --emitDeclarationOnly",
188932
189040
  clean: "rm -rf dist",
188933
189041
  prepublishOnly: "bun run build",
@@ -188948,6 +189056,9 @@ var package_default3 = {
188948
189056
  url: "https://github.com/vibeunion/supacloud.git",
188949
189057
  directory: "packages/elysia"
188950
189058
  },
189059
+ dependencies: {
189060
+ jose: "^6.2.11"
189061
+ },
188951
189062
  peerDependencies: {
188952
189063
  elysia: "^1.4.30"
188953
189064
  },
@@ -189101,16 +189212,17 @@ export function createDemo() {
189101
189212
  return sandbox;
189102
189213
  }
189103
189214
  `,
189104
- "src/application.ts": `import { createApplication, type ApplicationOptions, type CommandGovernance } from "@supacloud/elysia";
189215
+ "src/application.ts": `import { createApplication, createSupAuthRequestContext, type SupAuthContextOptions, type ApplicationOptions, type CommandGovernance } from "@supacloud/elysia";
189105
189216
  import { createCompiledModules } from "../generated/application";
189106
189217
 
189107
189218
  export interface AppAdapters {
189108
189219
  deps: NonNullable<ApplicationOptions["deps"]>;
189109
189220
  requestContext: NonNullable<ApplicationOptions["requestContext"]>;
189110
189221
  commandGovernance: CommandGovernance;
189222
+ onExecution?: ApplicationOptions["onExecution"];
189111
189223
  }
189112
189224
 
189113
- // Supply trusted identity, persistent storage and durable governance in the host.
189225
+ // The host verifies external identity (SupAuth for unified login) before creating requestContext.
189114
189226
  export function createApp(adapters: AppAdapters) {
189115
189227
  return createApplication({
189116
189228
  ...adapters,
@@ -189118,6 +189230,10 @@ export function createApp(adapters: AppAdapters) {
189118
189230
  modules: createCompiledModules(),
189119
189231
  });
189120
189232
  }
189233
+
189234
+ export function createSupAuthApp(identity: SupAuthContextOptions, adapters: Omit<AppAdapters, "requestContext">) {
189235
+ return createApp({ ...adapters, requestContext: createSupAuthRequestContext(identity) });
189236
+ }
189121
189237
  `,
189122
189238
  "src/review/review.ts": `import {
189123
189239
  Body, Command, Controller, DB_CLIENT, Get, Inject, Param, Post,
@@ -189340,6 +189456,46 @@ and commit transition, idempotency receipt and audit atomically. For distributed
189340
189456
  side effects use a transactional outbox. Client state machines are projections,
189341
189457
  not a security boundary. Missing declared runtime adapters return an error.
189342
189458
 
189459
+ ## Unified User Center
189460
+
189461
+ For enterprise unified login, use SupAuth as the external user center. This
189462
+ starter exports createSupAuthApp(identity, adapters) from dist/application.js.
189463
+ Supply issuer, audience, clientId, projectId, an explicit HTTPS jwksUrl and resolveAccess
189464
+ that reads current application-local access. The runtime verifies credential
189465
+ signatures, configured issuer and audience, allowed asymmetric algorithms/keys
189466
+ and expiry before constructing requestContext. The token must have the
189467
+ authenticated user role and matching client_id/azp application binding.
189468
+ Invalid credentials return 401; verification service failures return 503.
189469
+ It does not create a user center.
189470
+
189471
+ Map the verified issuer and subject to application-local membership and
189472
+ permissions. A unified user does not automatically have access to every project.
189473
+ Never trust a body-supplied actor or an unverified decoded token. When identity
189474
+ cannot be verified, deny protected access; never fall back to the demo identity,
189475
+ local login or a service-role bypass. Do not duplicate passwords or token issuance
189476
+ in business modules. Recheck business authorization on idempotent replay.
189477
+
189478
+ Local compilation and deterministic tests do not require SupAuth credentials.
189479
+ Before production acceptance, test legitimate SupAuth sessions across two
189480
+ applications, cross-project denial, invalid/expired credentials and permission
189481
+ revocation. The local memory tests are not proof of these integration guarantees.
189482
+
189483
+ ## Inspection And Repair
189484
+
189485
+ \`\`\`sh
189486
+ bunx supacloud-compiler context review --root src --json
189487
+ bunx supacloud-compiler explain review --root src
189488
+ bunx supacloud-compiler check --json
189489
+ bunx supacloud-compiler fix ./fix.json --dry-run
189490
+ \`\`\`
189491
+
189492
+ Context packs include directional dependencies, relevant aspect files, diagnostics
189493
+ and static execution plans. Share these rather than credentials or production
189494
+ data. Fixes default to preview; use --write only after reviewing the selected
189495
+ policy. Invalid transaction/idempotency modes fail compilation instead of
189496
+ silently disabling governance. onExecution receives metadata-only trace events;
189497
+ durable audit still belongs to the command governance adapter.
189498
+
189343
189499
  ## CI
189344
189500
 
189345
189501
  After the first compilation, commit generated/. In CI run
@@ -193192,7 +193348,7 @@ function registerRemoteDevTools(server2, options = {}) {
193192
193348
  // package.json
193193
193349
  var package_default4 = {
193194
193350
  name: "@supacloud/cli",
193195
- version: "0.49.2",
193351
+ version: "0.50.0",
193196
193352
  description: "Project-scoped CLI for SupaCloud users",
193197
193353
  type: "module",
193198
193354
  main: "./dist/index.js",
@@ -193225,7 +193381,7 @@ var package_default4 = {
193225
193381
  },
193226
193382
  dependencies: {
193227
193383
  "@sinclair/typebox": "^0.34.52",
193228
- "@supacloud/compiler": "^0.11.0",
193384
+ "@supacloud/compiler": "^0.12.0",
193229
193385
  "@supacloud/db": "^0.2.0",
193230
193386
  fflate: "^0.8.3"
193231
193387
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supacloud/cli",
3
- "version": "0.49.2",
3
+ "version": "0.50.0",
4
4
  "description": "Project-scoped CLI for SupaCloud users",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@sinclair/typebox": "^0.34.52",
36
- "@supacloud/compiler": "^0.11.0",
36
+ "@supacloud/compiler": "^0.12.0",
37
37
  "@supacloud/db": "^0.2.0",
38
38
  "fflate": "^0.8.3"
39
39
  },