@clearance/cli 0.1.4
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/LICENSE +29 -0
- package/LICENSE.md +20 -0
- package/dist/api-client.d.ts +18 -0
- package/dist/api-client.js +88 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2494 -0
- package/dist/operator-auth.d.ts +28 -0
- package/dist/operator-auth.js +310 -0
- package/dist/ops/deploy/compose/docker-compose.production.yml +129 -0
- package/dist/ops/deploy/upgrades/README.md +24 -0
- package/dist/ops/deploy/upgrades/steps/0.2.0/apply.sh +62 -0
- package/dist/ops/scripts/backup-create.sh +197 -0
- package/dist/ops/scripts/backup-restore-verify.sh +129 -0
- package/dist/ops/scripts/backup-verify.sh +121 -0
- package/dist/ops/scripts/lib/ops-common.sh +375 -0
- package/dist/ops/scripts/scim-legacy-preflight.sh +103 -0
- package/dist/ops/scripts/upgrade-apply.sh +168 -0
- package/dist/ops/scripts/upgrade-plan.sh +129 -0
- package/dist/ops/scripts/upgrade-preflight.sh +136 -0
- package/dist/ops/scripts/upgrade-rollback.sh +394 -0
- package/dist/ops/scripts/upgrade-verify.sh +98 -0
- package/dist/ops/scripts/validate-production-env.sh +232 -0
- package/dist/output.d.ts +19 -0
- package/dist/output.js +52 -0
- package/dist/remote-dispatch.d.ts +10 -0
- package/dist/remote-dispatch.js +232 -0
- package/dist/store.d.ts +9 -0
- package/dist/store.js +43 -0
- package/dist/upgrade.d.ts +114 -0
- package/dist/upgrade.js +262 -0
- package/package.json +38 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Clearance contributors
|
|
4
|
+
|
|
5
|
+
This project includes substantial portions of software originally developed
|
|
6
|
+
by Bereket Engida and used under the following license terms.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
The MIT License (MIT)
|
|
11
|
+
Copyright (c) 2024 - present, Bereket Engida
|
|
12
|
+
|
|
13
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
14
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
15
|
+
the Software without restriction, including without limitation the rights to
|
|
16
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
17
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
18
|
+
subject to the following conditions:
|
|
19
|
+
|
|
20
|
+
The above copyright notice and this permission notice shall be included in all
|
|
21
|
+
copies or substantial portions of the Software.
|
|
22
|
+
|
|
23
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
26
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
27
|
+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
28
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
29
|
+
DEALINGS IN THE SOFTWARE.
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
Copyright (c) 2024 - present, Bereket Engida
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
5
|
+
this software and associated documentation files (the “Software”), to deal in
|
|
6
|
+
the Software without restriction, including without limitation the rights to
|
|
7
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
8
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
9
|
+
subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
16
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
17
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
18
|
+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
19
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
20
|
+
DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type ApiSession = {
|
|
2
|
+
apiUrl: string;
|
|
3
|
+
token: string;
|
|
4
|
+
profile: string;
|
|
5
|
+
credentialSource: "environment" | "saved";
|
|
6
|
+
};
|
|
7
|
+
type ApiRequest = {
|
|
8
|
+
method?: "GET" | "POST" | "PATCH" | "DELETE";
|
|
9
|
+
path: `/v1/${string}`;
|
|
10
|
+
body?: unknown;
|
|
11
|
+
idempotencyKey?: string;
|
|
12
|
+
};
|
|
13
|
+
export declare function resolveApiSession(options?: {
|
|
14
|
+
profile?: string;
|
|
15
|
+
apiUrl?: string;
|
|
16
|
+
}): Promise<ApiSession | undefined>;
|
|
17
|
+
export declare function requestManagementApi<T>(session: ApiSession, request: ApiRequest): Promise<T>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { ClearanceError } from "@clearance/management";
|
|
3
|
+
import { environmentToken, normalizeApiUrl, normalizeProfile, readSavedCredential, } from "./operator-auth.js";
|
|
4
|
+
const API_TIMEOUT_MS = 15_000;
|
|
5
|
+
function cliError(code, message, remediation, retryable = false) {
|
|
6
|
+
return new ClearanceError({ code, message, stage: "cli.api", remediation, retryable });
|
|
7
|
+
}
|
|
8
|
+
export async function resolveApiSession(options = {}) {
|
|
9
|
+
const profile = normalizeProfile(options.profile);
|
|
10
|
+
const envToken = environmentToken();
|
|
11
|
+
if (options.profile !== undefined && envToken) {
|
|
12
|
+
throw cliError("CLI_PROFILE_ENV_TOKEN_CONFLICT", "An explicit --profile cannot be paired with an unscoped environment token.", "Unset CLEARANCE_OPERATOR_TOKEN and CLEARANCE_API_TOKEN to use the saved profile, or omit --profile to use the environment token.");
|
|
13
|
+
}
|
|
14
|
+
if (envToken) {
|
|
15
|
+
if (!options.apiUrl?.trim() && !process.env.CLEARANCE_API_URL?.trim()) {
|
|
16
|
+
throw cliError("CLI_ENV_TOKEN_API_URL_REQUIRED", "Environment-token sessions require an explicit Clearance API URL.", "Pass --api-url or set CLEARANCE_API_URL to the token's intended API origin.");
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
apiUrl: normalizeApiUrl(options.apiUrl),
|
|
20
|
+
token: envToken,
|
|
21
|
+
profile,
|
|
22
|
+
credentialSource: "environment",
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
const saved = await readSavedCredential(process.env, profile);
|
|
26
|
+
if (!saved)
|
|
27
|
+
return undefined;
|
|
28
|
+
const requestedApiUrl = options.apiUrl ? normalizeApiUrl(options.apiUrl) : undefined;
|
|
29
|
+
if (requestedApiUrl && requestedApiUrl !== saved.apiUrl) {
|
|
30
|
+
throw cliError("CLI_CREDENTIAL_ORIGIN_MISMATCH", "The saved profile is bound to a different Clearance API origin.", "Use the profile's saved API URL, or log in to the requested origin with a separate profile.");
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
apiUrl: saved.apiUrl,
|
|
34
|
+
token: saved.token,
|
|
35
|
+
profile,
|
|
36
|
+
credentialSource: "saved",
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export async function requestManagementApi(session, request) {
|
|
40
|
+
const method = request.method ?? "GET";
|
|
41
|
+
const controller = new AbortController();
|
|
42
|
+
const timer = setTimeout(() => controller.abort(), API_TIMEOUT_MS);
|
|
43
|
+
const headers = {
|
|
44
|
+
authorization: `Bearer ${session.token}`,
|
|
45
|
+
accept: "application/json",
|
|
46
|
+
};
|
|
47
|
+
if (request.body !== undefined)
|
|
48
|
+
headers["content-type"] = "application/json";
|
|
49
|
+
if (method !== "GET")
|
|
50
|
+
headers["idempotency-key"] = request.idempotencyKey ?? randomUUID();
|
|
51
|
+
try {
|
|
52
|
+
const response = await fetch(`${session.apiUrl}${request.path}`, {
|
|
53
|
+
method,
|
|
54
|
+
headers,
|
|
55
|
+
...(request.body !== undefined ? { body: JSON.stringify(request.body) } : {}),
|
|
56
|
+
signal: controller.signal,
|
|
57
|
+
});
|
|
58
|
+
const payload = response.status === 204
|
|
59
|
+
? undefined
|
|
60
|
+
: await response.json().catch(() => undefined);
|
|
61
|
+
if (response.ok)
|
|
62
|
+
return payload;
|
|
63
|
+
const remote = payload && typeof payload === "object"
|
|
64
|
+
? payload.error
|
|
65
|
+
: undefined;
|
|
66
|
+
throw new ClearanceError({
|
|
67
|
+
code: typeof remote?.code === "string" ? remote.code : "CLI_API_REQUEST_FAILED",
|
|
68
|
+
message: typeof remote?.message === "string" ? remote.message : `Clearance API returned HTTP ${response.status}.`,
|
|
69
|
+
stage: typeof remote?.stage === "string" ? remote.stage : "cli.api",
|
|
70
|
+
remediation: typeof remote?.remediation === "string"
|
|
71
|
+
? remote.remediation
|
|
72
|
+
: "Check the selected profile, API health, and operator authorization.",
|
|
73
|
+
retryable: typeof remote?.retryable === "boolean" ? remote.retryable : response.status >= 500,
|
|
74
|
+
status: response.status,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
catch (cause) {
|
|
78
|
+
if (cause instanceof ClearanceError)
|
|
79
|
+
throw cause;
|
|
80
|
+
if (cause.name === "AbortError") {
|
|
81
|
+
throw cliError("CLI_API_TIMEOUT", "Clearance API request timed out.", "Check API reachability and retry.", true);
|
|
82
|
+
}
|
|
83
|
+
throw cliError("CLI_API_UNREACHABLE", "Clearance API could not be reached.", "Check the selected profile and network connection.", true);
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
clearTimeout(timer);
|
|
87
|
+
}
|
|
88
|
+
}
|
package/dist/index.d.ts
ADDED