@nasebanal/cli 0.11.0 → 0.12.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 CHANGED
@@ -69,6 +69,15 @@ NB_API_VERSION=v2 nb assurance report upload --file specmatic/v2/junit.xml --kin
69
69
  # a project may require a version for some kinds of result (Assurance > Projects > the project's settings): a result of such a kind
70
70
  # without one is refused with 422 API_VERSION_REQUIRED (the message says to pass --api-version or set NB_API_VERSION)
71
71
 
72
+ # Which contract the result was produced against: the SHA-256 of the contract document (the catalog's content_hash; `nb specs versions`
73
+ # prints it), so Evolution can tell a result of the current contract from one of an older or an unknown version. Not the API's URL version
74
+ # (--api-version) and not the document's info.version (edited by hand): a hash. Informational, not part of the result's identity.
75
+ nb assurance report upload --file specmatic/junit.xml --kind contract --tool specmatic --spec-hash 9f2c...64 hex characters
76
+ # or let the CLI hash the file the test ran against (a pinned package's spec.yaml hashes to what `nb specs push` of it registered)
77
+ nb assurance report upload --file specmatic/junit.xml --kind contract --tool specmatic \
78
+ --contract-file node_modules/@nasebanal/api-specs-assurance/spec.yaml
79
+ # needs an Assurance that knows spec_hash (the assurance contract 1.10.0 and later); an older one ignores the field
80
+
72
81
  # Extra numbers for the suite (repeatable), e.g. ZAP's findings by severity - what the Assurance security gate reads
73
82
  nb assurance report upload --file zap/report/baseline-junit.xml --kind security --tool zap --metric high=0 --metric medium=3 --metric low=2
74
83
 
@@ -192,6 +192,7 @@ export function parseReport(opts) {
192
192
  ...(opts.components && opts.components.length > 0 ? { components: opts.components } : {}),
193
193
  ...(opts.label ? { label: opts.label } : {}),
194
194
  ...(opts.toolVersion ? { tool_version: opts.toolVersion } : {}),
195
+ ...(opts.specHash ? { spec_hash: opts.specHash } : {}),
195
196
  };
196
197
  if (opts.format === "junit") {
197
198
  const j = parseJunit(text);
@@ -379,6 +380,24 @@ function checkToolVersion(raw) {
379
380
  fail("--tool-version must be 50 characters or fewer");
380
381
  return version;
381
382
  }
383
+ /** The `--spec-hash`: a SHA-256 in hex (what `nb specs versions` prints), lower-cased because the API takes lowercase only. */
384
+ function checkSpecHash(raw) {
385
+ if (raw === undefined)
386
+ return undefined;
387
+ const hash = raw.trim().toLowerCase();
388
+ if (!/^[0-9a-f]{64}$/.test(hash))
389
+ fail("--spec-hash must be a SHA-256 in hex (64 characters), e.g. the sha256 `nb specs versions` prints");
390
+ return hash;
391
+ }
392
+ /** The `--contract-file`: the hash the catalog would keep as `content_hash` for this document (SHA-256 of its text). */
393
+ function hashOfContractFile(file) {
394
+ try {
395
+ return hashText(readSpecFile(file));
396
+ }
397
+ catch (err) {
398
+ return fail(String(err.message).replace(/^--file:/, "--contract-file:"));
399
+ }
400
+ }
382
401
  /** The `--component` names: trimmed, no empty one, no two alike ignoring case, within the API's limits. */
383
402
  function checkComponents(raw) {
384
403
  if (raw === undefined)
@@ -455,6 +474,8 @@ export function buildReportUploadCommand() {
455
474
  .option("--component <name>", "a component the result is for (e.g. frontend, backend), repeatable when it covers several (e.g. an end-to-end test: --component frontend --component backend); new names are created in the project; leave it out for the component `default`", (v, all = []) => [...all, v])
456
475
  .option("--label <name>", "tells apart results that are otherwise the same, such as two scans of one tool on the same components (e.g. --label baseline, --label full-scan); part of the result's identity, so the same label again replaces the result; optional")
457
476
  .option("--tool-version <version>", "the version of the tool that produced the report (e.g. 9.1.0): informational, shown next to the tool, handy when a tool's new version changes its layout; optional")
477
+ .option("--spec-hash <sha256>", "the SHA-256 of the API contract this result was produced against (64 hex characters; the sha256 `nb specs versions` prints for a catalog version): Evolution compares it with the catalog's versions and tells whether the result was produced with the current contract, an older one or an unknown one. Informational, not part of the result's identity; a report sent again replaces it. Exclusive with --contract-file")
478
+ .option("--contract-file <path>", "the contract document the result was produced against (e.g. node_modules/@nasebanal/api-specs-<api>/spec.yaml): its SHA-256 is sent as --spec-hash would, the same hash the catalog keeps for that document. Exclusive with --spec-hash")
458
479
  .option("--metric <key=value>", "an extra number for the suite, repeatable (e.g. --metric high=0 --metric medium=3; for security: critical, high, medium, low, info)", (v, all = []) => [...all, v])
459
480
  .option("--api-version <label>", "the API version the result is for (e.g. v1, v2), part of the result's identity next to its kind and components; leave it out for results that hold for every version, such as unit tests. Default: the NB_API_VERSION environment variable (set it once per CI job or branch). A project can require a version for some kinds of result, and then refuses one without it")
460
481
  .option("--project <name>", "project name (CI: the repository); found, or created if missing")
@@ -500,6 +521,8 @@ export function buildReportUploadCommand() {
500
521
  // The flag wins; NB_API_VERSION (a CI variable) is the default, and an empty one (a CI that declares it but does not set it) is none.
501
522
  const versionRaw = opts.apiVersion ?? (process.env.NB_API_VERSION || undefined);
502
523
  const apiVersion = versionRaw === undefined ? undefined : checkApiVersion(versionRaw);
524
+ if (opts.specHash !== undefined && opts.contractFile !== undefined)
525
+ fail("--spec-hash and --contract-file are exclusive: one gives the hash, the other a file to take it from");
503
526
  const parsed = parseReport({
504
527
  format,
505
528
  kind,
@@ -507,6 +530,7 @@ export function buildReportUploadCommand() {
507
530
  components: checkComponents(opts.component),
508
531
  label: checkLabel(opts.label),
509
532
  toolVersion: checkToolVersion(opts.toolVersion),
533
+ specHash: opts.contractFile !== undefined ? hashOfContractFile(opts.contractFile) : checkSpecHash(opts.specHash),
510
534
  status: opts.status,
511
535
  maxFailRatio,
512
536
  file,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nasebanal/cli",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "gcloud-style command-line interface for NASEBANAL APIs, generated from nb-api-specs OpenAPI contracts.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -1,8 +1,8 @@
1
1
  openapi: 3.0.3
2
2
  info:
3
- title: NASEBANAL - Assurance API
3
+ title: NASEBANAL Assurance API
4
4
  description: "Backend of NASEBANAL Assurance (quality assurance for APIs and web apps, under NASEBANAL Evolution). Authenticates users via Auth0 JWT and Personal Access Tokens (PAT) and integrates with the Account API. External monitoring: register URLs to be probed on an interval, then read availability reports. Test results: report the normalised result of each CI/CD job into a named project (typically one per repository), then read its runs and suites. Every response is wrapped as `{ success, data }` (or `{ success: false, error }`)."
5
- version: 1.9.0
5
+ version: 1.9.2
6
6
  contact:
7
7
  name: NASEBANAL
8
8
  url: https://www.nasebanal.com
@@ -1872,9 +1872,19 @@ components:
1872
1872
  $ref: "#/components/schemas/User"
1873
1873
  Error:
1874
1874
  type: object
1875
+ required:
1876
+ - success
1877
+ - error
1875
1878
  properties:
1879
+ success:
1880
+ type: boolean
1881
+ enum:
1882
+ - false
1876
1883
  error:
1877
1884
  type: object
1885
+ required:
1886
+ - code
1887
+ - message
1878
1888
  properties:
1879
1889
  code:
1880
1890
  type: string
@@ -3354,6 +3364,7 @@ components:
3354
3364
  schema:
3355
3365
  $ref: "#/components/schemas/Error"
3356
3366
  example:
3367
+ success: false
3357
3368
  error:
3358
3369
  code: AUTH_ERROR
3359
3370
  message: No authentication token provided
package/specs/target.yaml CHANGED
@@ -1,6 +1,6 @@
1
1
  openapi: 3.0.3
2
2
  info:
3
- title: NASEBANAL - Target API
3
+ title: NASEBANAL Target API
4
4
  description: "Target API for NASEBANAL. Provides hierarchical target management: users define goals and organize them in a tree structure. Parent-child links are persisted via `targets.parent_target_id` (authoritative since migration 0017); a legacy cell-based storage layer is kept in sync best-effort for backward compatibility. Targets can be shared with other users (read/write, optionally including the subtree and linked Recorder data), and ownership of a personal target subtree can be transferred to a recipient via an email-approved migration flow. Supports user authentication via Auth0 JWT and Personal Access Tokens (PAT)."
5
5
  version: 1.5.0
6
6
  contact: