@nasebanal/cli 0.12.0 → 0.14.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 +283 -79
- package/dist/apis.js +2 -1
- package/dist/auth.js +75 -2
- package/dist/config.js +30 -0
- package/dist/index.js +12 -3
- package/dist/reports/monitors.js +57 -0
- package/dist/reports/upload.js +119 -252
- package/dist/spec/build.js +65 -12
- package/dist/specs/apiVersion.js +38 -0
- package/dist/specs/command.js +212 -13
- package/dist/specs/docs.js +73 -0
- package/dist/specs/pull.js +18 -13
- package/dist/specs/push.js +227 -16
- package/dist/specs/resolve.js +182 -0
- package/dist/specs/servers.js +88 -0
- package/dist/specs/settings.js +48 -0
- package/package.json +1 -1
- package/specs/account.yaml +90 -1
- package/specs/assurance.yaml +229 -1215
- package/specs/recorder.yaml +253 -1
- package/specs/specs.yaml +1587 -0
- package/specs/target.yaml +187 -1
package/README.md
CHANGED
|
@@ -29,8 +29,9 @@ $ nb account me tokens create --data '{"name":"ci"}'
|
|
|
29
29
|
|
|
30
30
|
`nb assurance report upload` reads a test report on the runner, reduces it to a
|
|
31
31
|
small summary (counts, coverage-free metrics, the first failures, and for JUnit
|
|
32
|
-
the per-test cases) and reports it to a NASEBANAL Assurance
|
|
33
|
-
laptop; in CI it needs
|
|
32
|
+
the per-test cases) and reports it to a NASEBANAL Assurance **spec**: an API spec of the catalog that is tied to a repository
|
|
33
|
+
(see "Which spec a result or a monitor is about" below). The same line works in a pipeline and on a laptop; in CI it needs a
|
|
34
|
+
token and the spec's id:
|
|
34
35
|
|
|
35
36
|
The **kind** is one of a fixed set of perspectives (`unit`, `e2e`, `contract`,
|
|
36
37
|
`security`, `load`); the **tool** is a free label (`vitest`, `pytest`, `playwright`,
|
|
@@ -42,41 +43,48 @@ numbers with `--metric` (for a scanner: `critical`, `high`, `medium`, `low`, `in
|
|
|
42
43
|
|
|
43
44
|
```bash
|
|
44
45
|
export NB_TOKEN=nbpat_… # a PAT or service-account token (no browser needed)
|
|
46
|
+
export NB_SPEC_ID=… # the spec's id in the catalog (Spec Management, or `nb specs specs list`; a CI variable)
|
|
45
47
|
|
|
46
48
|
# JUnit XML: vitest (--reporter=junit), pytest (--junitxml), Specmatic, Playwright (--reporter=junit)
|
|
47
49
|
nb assurance report upload --file report/junit.xml --kind unit --tool pytest
|
|
48
|
-
nb assurance report upload --file results/junit.xml --kind e2e --tool playwright
|
|
50
|
+
nb assurance report upload --file results/junit.xml --kind e2e --tool playwright
|
|
49
51
|
|
|
50
|
-
#
|
|
51
|
-
|
|
52
|
-
nb assurance report upload --file
|
|
52
|
+
# By names instead of the id (all checked against the catalog; --component is optional: none = the repository as a whole;
|
|
53
|
+
# --group is optional too: none = the specs in no group, an environment is a group)
|
|
54
|
+
nb assurance report upload --file results/junit.xml --kind e2e --tool playwright \
|
|
55
|
+
--repository nasebanal/nb-account-api --component account-internal --group Staging --spec "Account API (internal)"
|
|
56
|
+
|
|
57
|
+
# A result that belongs to the source, not to an environment (unit tests, a security scan), goes to EVERY spec of the repository
|
|
58
|
+
# at ONE API version (one per environment), one line each; refused for the other kinds. A repository row whose specs are all at one
|
|
59
|
+
# API version needs no --api-version; with several (v1 and v2 side by side) it is required: a release branch feeds its own version only
|
|
60
|
+
nb assurance report upload --file report/junit.xml --kind unit --tool vitest --repository nasebanal/nb-account-api --all-specs --api-version v1
|
|
61
|
+
|
|
62
|
+
# Two scans of one tool of the same spec (ZAP's baseline and full scan): a label tells them apart
|
|
63
|
+
nb assurance report upload --file report/baseline-junit.xml --kind security --tool zap --label baseline
|
|
64
|
+
nb assurance report upload --file report/full-scan-junit.xml --kind security --tool zap --label full-scan
|
|
53
65
|
|
|
54
66
|
# The tool's own version is informational and optional
|
|
55
67
|
nb assurance report upload --file report/junit.xml --kind unit --tool pytest --tool-version 9.1.0
|
|
56
68
|
|
|
57
|
-
# A result may be about several components: repeat the flag (new names are created in the project; none = `default`)
|
|
58
|
-
nb assurance report upload --file results/junit.xml --kind e2e --tool playwright --component frontend --component backend
|
|
59
|
-
|
|
60
69
|
# Specmatic: the JUnit XML, plus its HTML report for the API coverage (coverage_pct = operations exercised / operations in the spec)
|
|
61
70
|
nb assurance report upload --file specmatic/junit/TEST-junit-jupiter.xml --kind contract --tool specmatic \
|
|
62
71
|
--coverage-report specmatic/report/test/html/index.html
|
|
63
72
|
|
|
64
|
-
#
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
NB_API_VERSION
|
|
69
|
-
#
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
#
|
|
73
|
-
#
|
|
74
|
-
# (--api-version) and not the document's info.version (edited by hand): a hash. Informational, not part of the result's identity.
|
|
73
|
+
# An API at several API versions (v1 and v2 side by side) is one SPEC per API version, so a result needs no version of its own: it
|
|
74
|
+
# goes to the spec it belongs to. By names, --api-version is part of the spec's KEY (it selects the spec; it is not a label of the result)
|
|
75
|
+
nb assurance report upload --file specmatic/v2/junit.xml --kind contract --tool specmatic \
|
|
76
|
+
--repository nasebanal/nb-account-api --spec "Account API" --api-version v2
|
|
77
|
+
# NB_API_VERSION and the result's own api_version are retired (the variable is ignored with a warning); the API versions a result
|
|
78
|
+
# must name (the spec's "How results are handled") are gone with them
|
|
79
|
+
|
|
80
|
+
# Which contract the result was produced against: the SHA-256 of the contract document (the catalog's content_hash; `nb specs specs versions list`
|
|
81
|
+
# prints it), so Evolution can tell a result of the current revision from one of an older or an unknown one. Not the API version
|
|
82
|
+
# (v1, v2: the spec's) and not the document's info.version (edited by hand): a hash. Informational, not part of the result's identity.
|
|
75
83
|
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)
|
|
84
|
+
# or let the CLI hash the file the test ran against (a pinned package's spec.yaml hashes to what `nb specs specs push` of it registered)
|
|
77
85
|
nb assurance report upload --file specmatic/junit.xml --kind contract --tool specmatic \
|
|
78
86
|
--contract-file node_modules/@nasebanal/api-specs-assurance/spec.yaml
|
|
79
|
-
#
|
|
87
|
+
# Evolution matches the hash against the revisions of this spec
|
|
80
88
|
|
|
81
89
|
# Extra numbers for the suite (repeatable), e.g. ZAP's findings by severity - what the Assurance security gate reads
|
|
82
90
|
nb assurance report upload --file zap/report/baseline-junit.xml --kind security --tool zap --metric high=0 --metric medium=3 --metric low=2
|
|
@@ -85,16 +93,26 @@ nb assurance report upload --file zap/report/baseline-junit.xml --kind security
|
|
|
85
93
|
nb assurance report upload --dir locust/logs/20261001_090000
|
|
86
94
|
```
|
|
87
95
|
|
|
88
|
-
- **
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
`
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
- **Spec (the target of a report):** a result is reported to a **spec of the catalog that is tied to a
|
|
97
|
+
repository**, by its id, `--spec-id <id>` or `$NB_SPEC_ID` (a pipeline's repository variable; it is not
|
|
98
|
+
a secret, and it is not a file in the repository: a copy of a workflow keeps its own variable, so it
|
|
99
|
+
cannot report into another API by accident), or by names, `--repository <owner/name> [--component <name>] [--group <name>] [--api-version <v>] --spec <name>`
|
|
100
|
+
(+ `--repository-provider`, default `github`; no `--component` = the repository as a whole; no `--group` = the specs
|
|
101
|
+
in no group, **not** any group; no `--api-version` = the API version of the one spec the rest of the key leaves, several
|
|
102
|
+
are an error that lists them), which are checked against each other (the spec must be tied to exactly that group,
|
|
103
|
+
repository row and API version; on a miss the error lists where the name does exist). `--all-specs` (with `--repository`
|
|
104
|
+
[`--api-version`], instead of `--spec`) sends a `unit` or `security` result to every spec tied to that repository row at that API
|
|
105
|
+
version. A name asked for wins over the variable; an id and
|
|
106
|
+
names together are refused; with none the command stops before sending anything and says how. **Nothing is created:** a
|
|
107
|
+
spec or a repository that the catalog does not have is an error that points at `nb specs`, and a spec tied to no
|
|
108
|
+
repository is refused (the request carries the spec in the path and its `repository_id` in the body, and Assurance
|
|
109
|
+
checks the pair with the catalog: `422 SPEC_WITHOUT_REPOSITORY` / `REPOSITORY_MISMATCH`). The ids are printed after
|
|
110
|
+
every upload (and, in GitHub Actions, written to `$GITHUB_OUTPUT` as `spec_id` and `repository_id`). `--org <id|personal>`
|
|
111
|
+
(or `$NB_SPECS_ORG`) says whose specs these are; it is sent to the catalog and, for an organization, to Assurance.
|
|
112
|
+
Keep one id per environment (`--env`). **What this replaces:** `--repository-id` / `NB_REPOSITORY_ID` (a clear error says
|
|
113
|
+
so for this release), the old `--component` of a result (the component is now part of the repository's key), `--project`,
|
|
114
|
+
`--project-id`, `--no-create-project`, `--spec-environment` and `--spec-file` are gone: Assurance creates and links
|
|
115
|
+
nothing, the spec and its repository belong to the catalog, and registering them is its own step (`nb specs`).
|
|
98
116
|
- **Link to the report in the repository:** the CLI also sends the CI `--provider`
|
|
99
117
|
(`github` | `gitlab` | `other`, detected) and, when the report file is **committed**
|
|
100
118
|
(tracked, unchanged since `HEAD`, and `HEAD` is the reported commit), its path
|
|
@@ -103,24 +121,7 @@ nb assurance report upload --dir locust/logs/20261001_090000
|
|
|
103
121
|
override with `--report-path`.
|
|
104
122
|
The repository's web address is sent too (`repo_url`, detected from `GITHUB_SERVER_URL` /
|
|
105
123
|
`CI_PROJECT_URL`; override with `--repo-url`), so the link also works on a self-hosted
|
|
106
|
-
GitLab or GitHub Enterprise.
|
|
107
|
-
(the latest sender wins).
|
|
108
|
-
- **Tie the project to its API in the catalog (`--spec-id`, `--spec-environment`):**
|
|
109
|
-
`--spec-id <id>` links the project to a spec of the API catalog (its id in Assurance /
|
|
110
|
-
Specs), `--spec-environment production` says which environment of it the project covers
|
|
111
|
-
(needs `--spec-id`). A new project is created already linked; an existing one is
|
|
112
|
-
changed **only when it differs**, so a pipeline that runs on every commit writes nothing
|
|
113
|
-
once the link is right. Pointing it at another spec clears the old environment unless one
|
|
114
|
-
is given too. The id is not looked up in the catalog (it is another service): a typo shows
|
|
115
|
-
as "no spec" on the project. The link is set after the result is in, so a failure there
|
|
116
|
-
leaves the result reported and says so. `--spec-file <openapi.yaml>` does the whole chain in one command (see below).
|
|
117
|
-
- **Register the spec file and tie the project to it in one command (`--spec-file`):**
|
|
118
|
-
`nb assurance report upload ... --spec-file openapi.yaml [--spec-name N] [--spec-group G]
|
|
119
|
-
[--spec-org ID] [--spec-environment production]` first runs `nb specs push` on the file,
|
|
120
|
-
then creates / links the project to the spec it returns, then reports the result. The
|
|
121
|
-
catalog's answer never costs the result: if registering the spec fails (a plan without the
|
|
122
|
-
catalog, the limit of specs), the result is still reported, without the link, and the command
|
|
123
|
-
ends with the reason and a non-zero exit. Exclusive with `--spec-id`.
|
|
124
|
+
GitLab or GitHub Enterprise.
|
|
124
125
|
- **Run:** every job of one pipeline run shares a run key (CI: `GITHUB_RUN_ID` +
|
|
125
126
|
attempt, `CI_PIPELINE_ID`; locally `local-<sha>-<day>`), so a unit job and an e2e
|
|
126
127
|
job land in the same run, and re-running a job replaces its own result.
|
|
@@ -131,12 +132,12 @@ nb assurance report upload --dir locust/logs/20261001_090000
|
|
|
131
132
|
report, Specmatic's report, a JUnit file with everything in it). `--attach` sends the
|
|
132
133
|
original with the result: a file as it is, a folder as a zip made by the CLI (regular
|
|
133
134
|
files only, symbolic links are never followed). Up to 20 MiB per result and 200 MiB per
|
|
134
|
-
|
|
135
|
+
repository; the CLI checks the size before anything is sent. It is **opt-in twice** - nothing is
|
|
135
136
|
attached unless you pass it, and the server refuses it (403 `ATTACHMENTS_DISABLED`) until
|
|
136
|
-
the
|
|
137
|
+
the spec has turned on "Attaching original reports" in its settings (off by
|
|
137
138
|
default). Make sure the report holds no secrets or personal data.
|
|
138
139
|
The server only stores it (next to the result's cases, deleted with the result and by
|
|
139
|
-
the
|
|
140
|
+
the repository's retention) and offers it as a **download** to the repository's members in
|
|
140
141
|
Assurance; it is never opened, unzipped or shown in the browser. A failed attachment
|
|
141
142
|
leaves the result reported and the command exits non-zero with the reason.
|
|
142
143
|
- **Pass / fail:** JUnit - any failed or errored test fails the suite. Locust - an
|
|
@@ -150,12 +151,145 @@ nb assurance report upload --dir locust/logs/20261001_090000
|
|
|
150
151
|
is sent in total (names and outcomes always stay). Locust reports have no cases.
|
|
151
152
|
- `--dry-run` prints what would be sent and calls nothing.
|
|
152
153
|
|
|
153
|
-
##
|
|
154
|
+
## Repositories and the API catalog from a pipeline (`nb specs`)
|
|
155
|
+
|
|
156
|
+
`nb specs` is generated from the catalog's contract like every other group, so it reads
|
|
157
|
+
`nb specs <resource> <verb>`: `nb specs specs list`, `nb specs specs versions list <id>`,
|
|
158
|
+
`nb specs repositories get <id>`, `nb specs groups list`, and `--org <id|personal>` (or
|
|
159
|
+
`$NB_SPECS_ORG`) on each, since the catalog is per owner. The verbs a pipeline wants are
|
|
160
|
+
hand-written and sit in the same tree: `specs push`, `specs pull`, `specs settings` and `repositories upsert`.
|
|
161
|
+
The old direct form (`nb specs push`, `nb specs pull`, `nb specs versions`) still works, as hidden aliases.
|
|
162
|
+
|
|
163
|
+
**The commands match the screens.** Each sub-menu of NASEBANAL Evolution's *API management* manages one resource of
|
|
164
|
+
the catalog, and `nb specs <resource>` is that resource:
|
|
165
|
+
|
|
166
|
+
| Evolution screen | Resource | Command group | What it holds |
|
|
167
|
+
|---|---|---|---|
|
|
168
|
+
| Repository Management | repositories | `nb specs repositories` | `provider`, `name`, `component` and the one repository setting, `attachments_enabled` (`upsert --attachments`, `update --attachments`) |
|
|
169
|
+
| Spec Management | specs | `nb specs specs` | the spec (`push`, `update`, `delete`), its description document (`docs push|pull|delete`), the consumer-facing reference publishing (`update`: `reference_access`) and the quality settings: the public badge and report with their links (`settings`) |
|
|
170
|
+
| Catalog | (a read-only view of the specs) | `nb specs specs list` / `get` / `versions list` / `docs pull` | what is registered, its revisions and its description document, to read |
|
|
171
|
+
|
|
172
|
+
The quality settings (public badge and report with their links) are columns of the
|
|
173
|
+
**spec**; the repository is where it lives (its identity) and holds one setting, **attachments**: whether a result may
|
|
174
|
+
carry the original test report, which comes from the repository's CI. A spec is tied to a repository
|
|
175
|
+
optionally, so either can be registered first.
|
|
176
|
+
|
|
177
|
+
### Environments: one spec per environment, filed in a group
|
|
178
|
+
|
|
179
|
+
An API deployed to several environments (development, staging, production) is **one OpenAPI file in the
|
|
180
|
+
repository and one spec per environment**, each filed in a **group named after the environment**. What
|
|
181
|
+
differs between them is where the API is served, which is the document's top-level `servers`: `push
|
|
182
|
+
--server-url <url>` replaces it just before sending (see below), and the catalog's **contract hash**
|
|
183
|
+
(`latest_contract_hash`, which ignores `servers`) says whether two environments run the same contract.
|
|
184
|
+
A promotion is the same file pushed to the next environment's spec; a rollback is an older file pushed
|
|
185
|
+
as a new revision of that environment's spec (the history stays one straight line). A spec's key is its
|
|
186
|
+
**group, its repository row (provider, name, component), its API version and its name**: the same name may exist in other
|
|
187
|
+
groups, which is exactly the case of the same API in two environments.
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
# the first run makes the group, the repository and the spec (idempotent; nothing set on a screen is overwritten)
|
|
191
|
+
nb specs specs push --file openapi.yaml --group Staging --server-url https://staging.api.example.com/v1 \
|
|
192
|
+
--repository nasebanal/nb-account-api --name "Account API"
|
|
193
|
+
# the spec's id goes to the environment's variable (GitHub: Settings > Environments > Staging > Variables)
|
|
194
|
+
# NB_SPEC_ID=<spec_id printed above>
|
|
195
|
+
# every later run pushes a new version only if the document changed, and the test jobs report to NB_SPEC_ID
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
In GitHub Actions use **Environments**: the same workflow runs per environment and each environment carries
|
|
199
|
+
its own `NB_SPEC_ID`, so the report steps are written once.
|
|
200
|
+
|
|
201
|
+
### API versions: one spec per API version, one branch per version
|
|
202
|
+
|
|
203
|
+
The **API version** (`v1`, `v2`) is a property of the **spec**, and a new major API version is a **new spec**. The numbered
|
|
204
|
+
history inside a spec is its **revisions** (#1, #2, ...: one per push that changed the document; the catalog's `version`
|
|
205
|
+
field). `nb specs specs push` takes the API version from the document: the major of `info.version` (`1.8.0` -> `v1`,
|
|
206
|
+
`v2.0` -> `v2`, `1.0.0-rc.1` -> `v1`, `007.1` -> `v7`). A version that has no leading major (`2023-01`, `latest`, `1.x`) needs
|
|
207
|
+
`--api-version <v>`; an explicit one always wins. So:
|
|
208
|
+
|
|
209
|
+
- an additive change (an example, a new field) is a new **revision** of the same spec: bump `info.version` to `1.9.0`, push, and the
|
|
210
|
+
spec is still `v1`;
|
|
211
|
+
- a breaking change is a new major (`2.0.0`): the same push makes the **v2 spec** and leaves v1 untouched; pushing a document of
|
|
212
|
+
another major to a spec by `--id` is refused (`API_VERSION_MISMATCH`: register it as its own spec).
|
|
213
|
+
|
|
214
|
+
**A CI that names the API once: `--follow-version`.** The versions of one API are a family: each later version names the API's first
|
|
215
|
+
spec (its initial version) as `initial_spec_id`. Give the id of that FIRST spec and never change it:
|
|
216
|
+
|
|
217
|
+
```bash
|
|
218
|
+
nb specs specs push --file openapi.yaml --id <the API's first spec> --follow-version --server-url "$API_URL"
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
The document goes to the spec of ITS API version of that API (found by the API version, whichever spec of the family the id names).
|
|
222
|
+
When the API does not have that version yet the spec is made (named as the first spec is; the catalog keeps the family's group and
|
|
223
|
+
repository), so a new major (`2.0.0`) needs no change of the id. API versions are registered **in order**: the next one after the
|
|
224
|
+
highest the API has (v1, v2, then v3). A version that skips (v1, then v3) fails with the version that is next, and nothing is
|
|
225
|
+
registered (`--dry-run` says the same without writing): register a placeholder of the missing version first, then the real document
|
|
226
|
+
is a new revision of that spec afterwards. Needs `@nasebanal/api-specs-specs` 1.5.0 (`initial_spec_id`) on the catalog side.
|
|
227
|
+
|
|
228
|
+
To maintain several API versions, keep each one on a **branch** of the repository with its own OpenAPI file, and let the same CI
|
|
229
|
+
job push and report from whichever branch it runs on:
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
# main (v2, info.version 2.x) and release/v1 (v1, info.version 1.x): the same step on both branches
|
|
233
|
+
nb specs specs push --file openapi.yaml --group Production --server-url "$API_URL" --repository nasebanal/nb-account-api --name "Account API"
|
|
234
|
+
# test results: the spec of the branch's API version. Either the id (a variable per branch, picked in the workflow) ...
|
|
235
|
+
nb assurance report upload --file junit.xml --kind e2e --tool playwright --spec-id "${{ github.ref_name == 'main' && vars.NB_SPEC_ID_V2 || vars.NB_SPEC_ID_V1 }}"
|
|
236
|
+
# ... or by names, with the branch's API version
|
|
237
|
+
nb assurance report upload --file junit.xml --kind e2e --tool playwright \
|
|
238
|
+
--repository nasebanal/nb-account-api --group Production --api-version "$API_VERSION" --spec "Account API"
|
|
239
|
+
# a result that belongs to the source goes to every environment of THIS API version only
|
|
240
|
+
nb assurance report upload --file junit.xml --kind unit --tool vitest --repository nasebanal/nb-account-api --all-specs --api-version "$API_VERSION"
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
`NB_SPEC_ID` is a per-repository or per-**environment** variable, not a per-branch one: with several API versions either pick
|
|
244
|
+
the id in the workflow as above (one variable per API version) or report by names with `--api-version`.
|
|
245
|
+
|
|
246
|
+
### A repository first (`nb specs repositories upsert`)
|
|
154
247
|
|
|
155
|
-
|
|
156
|
-
|
|
248
|
+
A **repository** is where one or more of your APIs are implemented (something that is not in git,
|
|
249
|
+
such as a vendor's delivery, is a repository with provider `other`). Its key is the **provider, the
|
|
250
|
+
name and the component**: the component is your own name for a part of it (`account-api`, `web`),
|
|
251
|
+
optional (none = the repository as a whole, which is a row of its own), and one id says which
|
|
252
|
+
repository AND which component. A part of a monorepo is simply another row. Register it once, by
|
|
253
|
+
hand or from the screen, and keep the id the catalog issues:
|
|
254
|
+
|
|
255
|
+
```bash
|
|
256
|
+
nb specs repositories upsert --provider github --name nasebanal/nb-recorder-api
|
|
257
|
+
# -> {"id":"kMsl4TXEMmeN","provider":"github","name":"nasebanal/nb-recorder-api","component":""}
|
|
258
|
+
nb specs repositories upsert --name nasebanal/nb-account-api --component account-internal
|
|
259
|
+
nb specs repositories upsert --name nasebanal/nb-recorder-api --attachments on # applied only when it registers the repository
|
|
260
|
+
nb specs repositories update kMsl4TXEMmeN --attachments on # change it later (merged into --data)
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
It is idempotent (the same provider, name and component always answer the same id, and nothing
|
|
264
|
+
set on a screen is overwritten: `--attachments` is applied only when the call registers the repository), so it is safe to repeat. Give the id to the pipeline as the repository
|
|
265
|
+
variable `NB_REPOSITORY_ID` (it is not a secret, and it is not a file in the repository: a copy of
|
|
266
|
+
a template would report into another repository); `nb specs specs push` reads it (or takes `--repository-id`) to tie
|
|
267
|
+
the spec it registers. Test results do not use it: they are reported to the **spec** (`NB_SPEC_ID`), see below.
|
|
268
|
+
|
|
269
|
+
### Registering a spec (`nb specs specs push`)
|
|
270
|
+
|
|
271
|
+
`nb specs specs push --file openapi.yaml` registers an OpenAPI document in the catalog (your own
|
|
272
|
+
specs, Evolution): a new spec, or a new revision of the one that has the same name at the same API version (or `--id`).
|
|
157
273
|
It is made to run on **every commit**:
|
|
158
274
|
|
|
275
|
+
- **A spec's key is its group, its repository row, its API version and its name** (a name is unique within a group, a
|
|
276
|
+
repository row, `repository + component`, and an API version; the ones with no group or no repository are unique among
|
|
277
|
+
themselves). So the name is looked up **inside the group you name** with `--group`, **inside the
|
|
278
|
+
repository you name** with `--repository [--component]` and **at the API version of the document** (its `info.version`,
|
|
279
|
+
or `--api-version`; see "API versions" above): another group's, repository's or API version's spec of that
|
|
280
|
+
name is not touched (a document of another major makes the new spec), and a spec with no repository is not adopted by name
|
|
281
|
+
(use `--id` to tie one).
|
|
282
|
+
**A group left out means "no group", not any group**: a name that exists only in groups is an error that
|
|
283
|
+
lists them and asks for `--group` (or `--id`), instead of silently making a second spec. With no
|
|
284
|
+
repository named, the spec that has none wins; a name held by exactly one spec is used; a name held by
|
|
285
|
+
several specs under repositories is refused, listing them.
|
|
286
|
+
- **`--server-url <url>`** replaces the document's top-level `servers` with `[{ url }]` before sending: one file
|
|
287
|
+
in the repository, one URL per environment. A JSON file is edited as JSON; a YAML file as **text** (comments and
|
|
288
|
+
order kept) when the edit is proven safe (the document without `servers` must be identical), otherwise it is
|
|
289
|
+
written again (the CLI says so: comments are not kept in what is pushed; the file on disk is never changed).
|
|
290
|
+
The hash used for "unchanged" is of the text that is sent, so the same file to the same environment is
|
|
291
|
+
unchanged on the next run; `--dry-run` shows `server_url`.
|
|
292
|
+
|
|
159
293
|
- **A retitled document needs `--id`.** Without it the spec is found by its name (the document's
|
|
160
294
|
`info.title`), so a new title registers a second spec next to the old one. `--id <id>` pushes to
|
|
161
295
|
the spec you mean (a pipeline can read the id from `spec_id` of an earlier run), and adding
|
|
@@ -163,54 +297,123 @@ It is made to run on **every commit**:
|
|
|
163
297
|
printed (`renamed_from` in the JSON). A rename happens only on request, so a name set by hand in
|
|
164
298
|
the catalog is not overwritten on every push, and `--rename` without `--id` is refused.
|
|
165
299
|
|
|
166
|
-
- **Nothing is uploaded when the file is already the latest
|
|
167
|
-
document's SHA-256 with the `content_hash` the catalog keeps for the latest
|
|
168
|
-
sends anything; the same bytes print `unchanged (already
|
|
300
|
+
- **Nothing is uploaded when the file is already the latest revision.** The CLI compares the
|
|
301
|
+
document's SHA-256 with the `content_hash` the catalog keeps for the latest revision before it
|
|
302
|
+
sends anything; the same bytes print `unchanged (already rev N of vM: nothing uploaded)`. (The catalog
|
|
169
303
|
refuses an identical upload itself, `409 UNCHANGED`, which is also taken as "unchanged", for two
|
|
170
304
|
jobs racing.) The comparison is of bytes: a generator that writes a timestamp into the
|
|
171
|
-
document makes a new
|
|
305
|
+
document makes a new revision every run, so keep the output stable.
|
|
172
306
|
- **No group has to exist.** A spec is registered in no group unless `--group <name>` is given
|
|
173
|
-
(the group is made when missing); an existing spec is never moved by a push (the
|
|
174
|
-
moves it, by drag and drop or the select on its page).
|
|
175
|
-
- The name is `--name`, else the document's `info.title`, else the file's name. A new
|
|
307
|
+
(the group is made when missing, on the first run); an existing spec is never moved by a push (the
|
|
308
|
+
catalog moves it, by drag and drop or the select on its page).
|
|
309
|
+
- The name is `--name`, else the document's `info.title`, else the file's name. A new revision
|
|
176
310
|
carries a note made from the commit, the branch and the CI run (`--note` replaces it), so
|
|
177
|
-
"which commit made
|
|
311
|
+
"which commit made revision 7" has an answer.
|
|
312
|
+
- **`--api-version <v>`** names the API version when the document's `info.version` gives none (and always wins over it); a bad
|
|
313
|
+
label is refused before the catalog is read. The result prints `api_version`.
|
|
178
314
|
- `--org <id|personal>` (or `$NB_SPECS_ORG`) says whose catalog it is: the catalog is per
|
|
179
315
|
owner and needs `X-Active-Organization-Id`; `personal` (the default) is your own, an
|
|
180
316
|
organization's needs its Enterprise plan. `--dry-run` reads the catalog and says what would
|
|
181
317
|
happen. `NB_SPECS_BASE_URL` points it at another host (local: `http://localhost:8792`).
|
|
182
|
-
-
|
|
318
|
+
- **A repository is optional.** `--repository-id <id>` (default `$NB_REPOSITORY_ID`) ties the spec
|
|
319
|
+
to that repository: a new spec is created tied to it, an existing spec that has none is tied to
|
|
320
|
+
it. `--repository <owner/name>` (+ `--provider`, default `github`, and the optional `--component`)
|
|
321
|
+
registers the repository first, idempotently, and uses the id it returns, for a pipeline that would rather not keep an
|
|
322
|
+
id. **A push never moves a spec:** one that is tied to another repository stays there and the
|
|
323
|
+
command says so (`repository_kept` in the JSON). A spec uploaded by hand needs no repository.
|
|
324
|
+
- In GitHub Actions the spec's id is written to `$GITHUB_OUTPUT` as `spec_id`, and the repository's
|
|
325
|
+
as `repository_id`.
|
|
326
|
+
|
|
327
|
+
### A spec's description document (`nb specs specs docs`)
|
|
328
|
+
|
|
329
|
+
One **Markdown file per spec** (up to 200 KiB, UTF-8), shown rendered in the catalog beside the API reference, like
|
|
330
|
+
a developer portal's overview page. It belongs to Spec Management; the catalog only shows it.
|
|
331
|
+
|
|
332
|
+
```bash
|
|
333
|
+
nb specs specs docs push --file README.md --spec-id kMsl4TXEMmeN # added or replaced (201 / 200)
|
|
334
|
+
nb specs specs docs push --file docs/overview.md --spec "Account API" --group Staging --repository nasebanal/nb-account-api
|
|
335
|
+
nb specs specs docs pull --spec-id kMsl4TXEMmeN --out README.md # or to standard output
|
|
336
|
+
nb specs specs docs delete --spec-id kMsl4TXEMmeN # also when there is none
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
The spec is named like everywhere else: `--spec-id` (default `$NB_SPEC_ID`), or `--spec <name>` with the optional
|
|
340
|
+
`--repository [--component]` and `--group`. For these verbs what is left out means none (a spec in no group, tied to no
|
|
341
|
+
repository), so a spec that is tied to a repository needs `--repository`. The catalog answers `413` over 200 KiB and `415`
|
|
342
|
+
for a body that is not Markdown; a missing file, an empty one and a binary one are refused before anything is sent. (This
|
|
343
|
+
group replaces the generated `docs` leaf, whose body would be JSON.)
|
|
344
|
+
|
|
345
|
+
### A spec's public settings (`nb specs specs settings`)
|
|
346
|
+
|
|
347
|
+
```bash
|
|
348
|
+
nb specs specs settings kMsl4TXEMmeN --public-badge on --report-access login
|
|
349
|
+
nb specs specs settings kMsl4TXEMmeN --rotate-quality-public-id # new badge / report links; the old ones stop
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
One `PATCH /specs/{id}` with only the flags you pass (the same fields as the screen: `public_badge`,
|
|
353
|
+
`report_access` = `hidden` / `login` / `public`, `rotate_quality_public_id`); there is no API version rule any more (a spec has
|
|
354
|
+
one API version, so a result needs none); it prints the spec, including its `quality_public_id`. A spec starts
|
|
355
|
+
private. Attachments are the repository's, not the spec's (`nb specs repositories update <id> --attachments on`). (`nb specs specs update <id> --data '{...}'` does the same with a raw body.)
|
|
356
|
+
|
|
357
|
+
### Which spec a result or a monitor is about
|
|
358
|
+
|
|
359
|
+
Test results and external monitoring belong to a **spec that has a repository** (they are reported
|
|
360
|
+
against that repository row). A command that needs one takes the spec by id, `--spec-id <id>`, or by
|
|
361
|
+
the names of its key, `--repository <name> [--component <name>] [--group <name>] [--api-version <v>] --spec <name>`
|
|
362
|
+
(`--provider`, default `github`; no `--component` = the repository as a whole; no `--group` = the specs in no group, not any;
|
|
363
|
+
**no `--api-version` is the one exception to "left out means none"**: it is the API version of the one spec the rest of the key
|
|
364
|
+
leaves, and when it leaves several the error lists their API versions and asks for `--api-version`);
|
|
365
|
+
it never creates a spec or a
|
|
366
|
+
repository (`--no-create` has no meaning for specs: register them with `nb specs`), and a spec that is tied to
|
|
367
|
+
no repository is refused. The shared resolution is `resolveSpec` in `src/specs/resolve.ts`.
|
|
368
|
+
|
|
369
|
+
**API quality assessment: screens and commands.** The three screens under *API quality assessment* in
|
|
370
|
+
Evolution work on one API's data (Assurance), each of its sub-menus is a command group of `nb assurance`, and
|
|
371
|
+
what they work on is a spec:
|
|
372
|
+
|
|
373
|
+
| Evolution screen | Command | What it does |
|
|
374
|
+
|---|---|---|
|
|
375
|
+
| Charts | `nb assurance specs quality <id>` (and `nb assurance specs list` / `get`) | the quality dashboard data of a spec |
|
|
376
|
+
| Test results | `nb assurance report upload` (to send), `nb assurance specs runs ...`, `nb assurance specs results ...` | register and read results |
|
|
377
|
+
| External monitoring | `nb assurance monitors ...` | the monitors of a spec |
|
|
378
|
+
|
|
379
|
+
```bash
|
|
380
|
+
# A monitor is about a spec that has a repository: the spec by id or by names, put into the body as spec_id and repository_id
|
|
381
|
+
nb assurance monitors create --spec-id kMsl4TXEMmeN --data '{"url":"https://api.example.com/health","method":"GET","interval_minutes":5,"timeout_ms":10000}'
|
|
382
|
+
nb assurance monitors create --repository nasebanal/nb-account-api --spec "Account API" --data @monitor.json
|
|
383
|
+
nb assurance monitors update <monitor-id> --spec-id kMsl4TXEMmeN --data '{"enabled":true}' # moves it to that spec
|
|
384
|
+
```
|
|
183
385
|
|
|
184
|
-
### Reading a
|
|
386
|
+
### Reading a revision back (`nb specs specs pull`, `nb specs specs versions list`)
|
|
185
387
|
|
|
186
388
|
A pipeline can work from the catalog's document instead of a copy kept in a repository (a
|
|
187
389
|
contract test with Specmatic against the API's provider side, a stub for a consumer, a client
|
|
188
390
|
generator):
|
|
189
391
|
|
|
190
392
|
```bash
|
|
191
|
-
nb specs versions
|
|
192
|
-
nb specs pull --name "Billing API" --spec-version 3 --out spec.yaml
|
|
193
|
-
nb specs pull --id kMsl4TXEMmeN --spec-version 3 --hash <sha256> --out spec.yaml # pinned: fails if it differs
|
|
194
|
-
nb specs pull --name "Billing API" > spec.yaml
|
|
393
|
+
nb specs specs versions list <id> # revisions newest first, each with its sha256
|
|
394
|
+
nb specs specs pull --name "Billing API" --group Production --repository nasebanal/billing --spec-version 3 --out spec.yaml
|
|
395
|
+
nb specs specs pull --id kMsl4TXEMmeN --spec-version 3 --hash <sha256> --out spec.yaml # pinned: fails if it differs
|
|
396
|
+
nb specs specs pull --name "Billing API" > spec.yaml # latest; the document is all of stdout
|
|
195
397
|
```
|
|
196
398
|
|
|
197
|
-
- **`--spec-version` is the catalog's
|
|
198
|
-
changed the document). It is not the API
|
|
199
|
-
|
|
200
|
-
the CLI's own `nb --version`.
|
|
399
|
+
- **`--spec-version` is the catalog's revision number** (1, 2, 3...: one per `nb specs specs push` that
|
|
400
|
+
changed the document). It is not the API version (`v1`, `v2`: a property of the spec), not the document's own
|
|
401
|
+
`info.version`, and not the CLI's own `nb --version`.
|
|
201
402
|
Absent or `latest` is the newest; **pin a number in a pipeline**, `latest` moves.
|
|
202
403
|
- **The document comes back exactly as it was uploaded** (the bytes: a JSON document is not
|
|
203
404
|
parsed and re-printed), and its SHA-256 is checked against the `content_hash` the catalog keeps
|
|
204
|
-
for that
|
|
205
|
-
the pipeline expects, so a
|
|
206
|
-
spec, fails instead of testing the wrong thing. `nb specs versions` prints the hashes.
|
|
207
|
-
- A spec is named by `--id` (a rename cannot change it) or by `--name` (matched ignoring case)
|
|
405
|
+
for that revision, so a document that did not arrive intact fails. `--hash <sha256>` pins what
|
|
406
|
+
the pipeline expects, so a revision that was replaced, or a name that now points at another
|
|
407
|
+
spec, fails instead of testing the wrong thing. `nb specs specs versions list` prints the hashes.
|
|
408
|
+
- A spec is named by `--id` (a rename cannot change it) or by `--name` (matched ignoring case); with `--group` and
|
|
409
|
+
`--repository [--component]` and `--api-version` the name is looked up in that group, repository row and API version (its key), which is
|
|
410
|
+
how the same name in two environments (or at two API versions) is told apart.
|
|
208
411
|
`--org <id|personal>` / `$NB_SPECS_ORG` and `NB_SPECS_BASE_URL` work as for `push`. With `--out`
|
|
209
412
|
the details are printed as JSON; without it they go to stderr. In GitHub Actions `spec_id`,
|
|
210
413
|
`spec_version` and `spec_hash` are written to `$GITHUB_OUTPUT`.
|
|
211
414
|
- The catalog has no "released" mark yet: unlike the `@nasebanal/api-specs-*` packages, which
|
|
212
415
|
only advance once the provider has deployed, a pull of `latest` can return a version that
|
|
213
|
-
nothing implements. Pinning a
|
|
416
|
+
nothing implements. Pinning a revision (and its hash) is the safe way to use it today.
|
|
214
417
|
|
|
215
418
|
## Installation
|
|
216
419
|
|
|
@@ -429,6 +632,7 @@ Overridable env vars: `NB_AUTH0_DOMAIN`, `NB_AUTH0_AUDIENCE`,
|
|
|
429
632
|
| Option | Description |
|
|
430
633
|
|--------|-------------|
|
|
431
634
|
| `--env <production\|local>` | Target environment; picks the matching `servers` entry from the spec. Also `NB_ENV`. |
|
|
635
|
+
| `NB_<API>_BASE_URL` | The host of ONE API instead of its spec's `servers` entry (origin only; the spec's path is appended): `NB_ASSURANCE_BASE_URL=http://localhost:8791`, `NB_SPECS_BASE_URL=http://localhost:8792`, and `NB_ACCOUNT_BASE_URL` / `NB_RECORD_BASE_URL` / `NB_TARGET_BASE_URL`. `<API>` is the command group, as in `NB_<API>_ORG`. The shared `NB_BASE_URL` (one host for every API) still works but is **deprecated** and says so on stderr: pointing it at one local Worker sent every other command there too. |
|
|
432
636
|
| `--token <token>` | Override stored credentials with a PAT for one invocation. |
|
|
433
637
|
| `-V, --version` | Print the CLI version. |
|
|
434
638
|
|
package/dist/apis.js
CHANGED
|
@@ -2,5 +2,6 @@ export const API_CATALOG = [
|
|
|
2
2
|
{ name: "account", spec: "account.yaml", summary: "User profiles, subscriptions, billing, and API tokens" },
|
|
3
3
|
{ name: "record", spec: "recorder.yaml", summary: "Records and tags (NASEBANAL Recorder)" },
|
|
4
4
|
{ name: "target", spec: "target.yaml", summary: "Targets, cells, and shares (NASEBANAL Target)" },
|
|
5
|
-
{ name: "assurance", spec: "assurance.yaml", summary: "Monitors
|
|
5
|
+
{ name: "assurance", spec: "assurance.yaml", summary: "Monitors and CI/CD test results of your specs (NASEBANAL Assurance, API quality assessment)" },
|
|
6
|
+
{ name: "specs", spec: "specs.yaml", summary: "Repositories and your own OpenAPI documents: the API catalog (NASEBANAL Evolution)" },
|
|
6
7
|
];
|
package/dist/auth.js
CHANGED
|
@@ -9,7 +9,11 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { Command } from "commander";
|
|
11
11
|
import { createInterface } from "node:readline";
|
|
12
|
-
import { loadConfig, saveConfig, resolveToken, resolveEnv, configFilePath } from "./config.js";
|
|
12
|
+
import { loadConfig, saveConfig, resolveToken, resolveEnv, configFilePath, peekBaseUrlOverride } from "./config.js";
|
|
13
|
+
import { API_CATALOG } from "./apis.js";
|
|
14
|
+
import { resolveBaseUrl } from "./http.js";
|
|
15
|
+
import { loadSpec } from "./spec/loader.js";
|
|
16
|
+
import { specsBaseUrl } from "./specs/push.js";
|
|
13
17
|
import { login } from "./oauth.js";
|
|
14
18
|
import { envTokenHint } from "./output.js";
|
|
15
19
|
function readSecretLine(promptText) {
|
|
@@ -90,8 +94,19 @@ export function buildAuthCommand() {
|
|
|
90
94
|
? "stored PAT"
|
|
91
95
|
: "none";
|
|
92
96
|
const masked = token ? `${token.slice(0, 10)}…${token.slice(-4)}` : "(not set)";
|
|
93
|
-
|
|
97
|
+
const env = resolveEnv(config);
|
|
98
|
+
process.stdout.write(`Environment: ${env}\n`);
|
|
99
|
+
process.stdout.write(`Targets (the host each command calls; a NB_<API>_BASE_URL wins over the environment):\n`);
|
|
100
|
+
for (const line of targetLines(env))
|
|
101
|
+
process.stdout.write(` ${line}\n`);
|
|
94
102
|
process.stdout.write(`Token: ${masked} [source: ${source}]\n`);
|
|
103
|
+
// The stored `nb auth login` session is shown whether or not it is the credential in use: NB_TOKEN beats it, and a
|
|
104
|
+
// status that hid it would make "am I logged in, and as whom" unanswerable exactly when the two disagree.
|
|
105
|
+
if (config.auth) {
|
|
106
|
+
const who = loginIdentity(config.auth.id_token) ?? "(not readable)";
|
|
107
|
+
const note = source === "OAuth login" ? "in use; from the login, not checked with the server" : "stored, NOT in use: another credential wins";
|
|
108
|
+
process.stdout.write(`Login: ${who} [${note}]\n`);
|
|
109
|
+
}
|
|
95
110
|
if (config.auth?.expires_at) {
|
|
96
111
|
const expired = config.auth.expires_at <= Date.now();
|
|
97
112
|
process.stdout.write(`Expires: ${new Date(config.auth.expires_at).toLocaleString()}` +
|
|
@@ -101,3 +116,61 @@ export function buildAuthCommand() {
|
|
|
101
116
|
});
|
|
102
117
|
return auth;
|
|
103
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* The word the reader is looking for, next to the URL, decided by the host itself: `*.nasebanal.com` is production, `localhost` /
|
|
121
|
+
* `127.0.0.1` is local, anything else (a stub, a self-hosted copy) is `other`, never claimed to be production.
|
|
122
|
+
*/
|
|
123
|
+
export function hostKind(url) {
|
|
124
|
+
let host;
|
|
125
|
+
try {
|
|
126
|
+
host = new URL(url).hostname.toLowerCase();
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
return "other";
|
|
130
|
+
}
|
|
131
|
+
if (host === "localhost" || host === "127.0.0.1" || host === "[::1]" || host === "::1")
|
|
132
|
+
return "local";
|
|
133
|
+
if (host === "nasebanal.com" || host.endsWith(".nasebanal.com"))
|
|
134
|
+
return "production";
|
|
135
|
+
return "other";
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* What `nb auth status` says about where the commands go: per API, the host the next command would call and whether that is
|
|
139
|
+
* local or production, plus which variable put it there when one did (the environment alone does not tell, because a
|
|
140
|
+
* NB_<API>_BASE_URL beats it).
|
|
141
|
+
*/
|
|
142
|
+
export function targetLines(env) {
|
|
143
|
+
const width = Math.max(...API_CATALOG.map((a) => a.name.length));
|
|
144
|
+
return API_CATALOG.map((api) => {
|
|
145
|
+
// `nb specs` verbs read the catalog's host (NB_SPECS_BASE_URL only); every other group resolves from its spec's `servers`.
|
|
146
|
+
const peek = peekBaseUrlOverride(api.name);
|
|
147
|
+
const via = api.name === "specs"
|
|
148
|
+
? process.env.NB_SPECS_BASE_URL?.trim()
|
|
149
|
+
? { url: specsBaseUrl(env), variable: "NB_SPECS_BASE_URL" }
|
|
150
|
+
: undefined
|
|
151
|
+
: peek;
|
|
152
|
+
const url = api.name === "specs" ? specsBaseUrl(env) : (peek?.url ?? resolveBaseUrl(loadSpec(api.spec).servers, env));
|
|
153
|
+
return `${api.name.padEnd(width)} ${url} [${hostKind(url)}${via ? `, from ${via.variable}` : ""}]`;
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Who a `nb auth login` was done as, `Name <email>`, read from the ID token that login stored (the payload is plain base64url JSON).
|
|
158
|
+
* For display only: nothing is authorized on it (the servers verify the access token's signature). null when there is no ID token
|
|
159
|
+
* or it cannot be read.
|
|
160
|
+
*/
|
|
161
|
+
export function loginIdentity(idToken) {
|
|
162
|
+
const payload = idToken?.split(".")[1];
|
|
163
|
+
if (!payload)
|
|
164
|
+
return null;
|
|
165
|
+
try {
|
|
166
|
+
const claims = JSON.parse(Buffer.from(payload, "base64url").toString("utf8"));
|
|
167
|
+
const email = typeof claims.email === "string" ? claims.email : "";
|
|
168
|
+
const name = typeof claims.name === "string" ? claims.name : typeof claims.nickname === "string" ? claims.nickname : "";
|
|
169
|
+
if (name && email)
|
|
170
|
+
return `${name} <${email}>`;
|
|
171
|
+
return email || name || null;
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
}
|
package/dist/config.js
CHANGED
|
@@ -95,3 +95,33 @@ export function resolveEnv(config = loadConfig()) {
|
|
|
95
95
|
export function configFilePath() {
|
|
96
96
|
return configPath();
|
|
97
97
|
}
|
|
98
|
+
let warnedSharedBaseUrl = false;
|
|
99
|
+
/**
|
|
100
|
+
* The host a command group talks to when the environment names one, or undefined (then the spec's own `servers` entry for the
|
|
101
|
+
* active environment is used). `NB_<API>_BASE_URL` is that API's alone (`NB_ASSURANCE_BASE_URL`, `NB_RECORD_BASE_URL`, ...: the
|
|
102
|
+
* API is the command group's name, as in `NB_<API>_ORG`). The older `NB_BASE_URL` is still read as a fallback, but it applies
|
|
103
|
+
* to EVERY API at once (pointing it at one local Worker sends `nb record` there too), so it is deprecated and says so, once, on stderr.
|
|
104
|
+
* Origin only: the spec's path is appended. A trailing slash is dropped; an empty value counts as unset.
|
|
105
|
+
*/
|
|
106
|
+
export function baseUrlOverride(apiName) {
|
|
107
|
+
const found = peekBaseUrlOverride(apiName);
|
|
108
|
+
if (found?.variable === "NB_BASE_URL" && !warnedSharedBaseUrl) {
|
|
109
|
+
warnedSharedBaseUrl = true;
|
|
110
|
+
process.stderr.write(`nb: NB_BASE_URL applies to every API and is deprecated; set NB_${apiName.toUpperCase()}_BASE_URL (the host of the ${apiName} API) instead.\n`);
|
|
111
|
+
}
|
|
112
|
+
return found?.url;
|
|
113
|
+
}
|
|
114
|
+
/** The same lookup without the deprecation notice, and with the variable that supplied the host (for `nb auth status`). */
|
|
115
|
+
export function peekBaseUrlOverride(apiName) {
|
|
116
|
+
const clean = (v) => v?.trim().replace(/\/$/, "") || undefined;
|
|
117
|
+
const ownName = `NB_${apiName.toUpperCase()}_BASE_URL`;
|
|
118
|
+
const own = clean(process.env[ownName]);
|
|
119
|
+
if (own)
|
|
120
|
+
return { url: own, variable: ownName };
|
|
121
|
+
const shared = clean(process.env.NB_BASE_URL);
|
|
122
|
+
return shared ? { url: shared, variable: "NB_BASE_URL" } : undefined;
|
|
123
|
+
}
|
|
124
|
+
/** Tests: forget that the deprecation was already said. */
|
|
125
|
+
export function resetBaseUrlWarning() {
|
|
126
|
+
warnedSharedBaseUrl = false;
|
|
127
|
+
}
|