@mittwald/cli 1.0.0-alpha.33 → 1.0.0-alpha.34
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 +18 -10
- package/dist/esm/ExtendedBaseCommand.d.ts +1 -1
- package/dist/esm/ListBaseCommand.d.ts +4 -1
- package/dist/esm/ListBaseCommand.js +9 -4
- package/dist/esm/commands/app/copy.d.ts +0 -1
- package/dist/esm/commands/app/dependency/list.js +2 -2
- package/dist/esm/commands/app/dependency/update.d.ts +0 -1
- package/dist/esm/commands/app/download.d.ts +0 -1
- package/dist/esm/commands/app/get.d.ts +0 -1
- package/dist/esm/commands/app/list.d.ts +1 -1
- package/dist/esm/commands/app/list.js +5 -10
- package/dist/esm/commands/app/ssh.d.ts +0 -1
- package/dist/esm/commands/app/uninstall.d.ts +0 -1
- package/dist/esm/commands/app/versions.js +1 -1
- package/dist/esm/commands/backup/list.js +3 -3
- package/dist/esm/commands/backup/schedule/list.js +3 -3
- package/dist/esm/commands/context/reset.d.ts +6 -0
- package/dist/esm/commands/context/reset.js +9 -0
- package/dist/esm/commands/context/set.js +5 -6
- package/dist/esm/commands/conversation/close.js +2 -2
- package/dist/esm/commands/conversation/list.js +2 -2
- package/dist/esm/commands/conversation/reply.js +2 -2
- package/dist/esm/commands/conversation/show.js +2 -2
- package/dist/esm/commands/cronjob/create.d.ts +0 -1
- package/dist/esm/commands/cronjob/list.js +4 -4
- package/dist/esm/commands/database/mysql/delete.js +2 -2
- package/dist/esm/commands/database/mysql/list.js +6 -7
- package/dist/esm/commands/database/mysql/user/list.js +6 -4
- package/dist/esm/commands/database/redis/list.js +6 -4
- package/dist/esm/commands/mail/address/list.d.ts +0 -2
- package/dist/esm/commands/mail/address/list.js +1 -7
- package/dist/esm/commands/org/list.d.ts +1 -1
- package/dist/esm/commands/org/list.js +6 -6
- package/dist/esm/commands/project/list.js +5 -8
- package/dist/esm/commands/server/list.js +4 -4
- package/dist/esm/commands/sftp-user/list.js +6 -4
- package/dist/esm/commands/ssh-user/list.js +6 -4
- package/dist/esm/lib/app/flags.d.ts +1 -2
- package/dist/esm/lib/app/flags.js +4 -14
- package/dist/esm/lib/app/uuid.d.ts +39 -3
- package/dist/esm/lib/app/uuid.js +66 -33
- package/dist/esm/lib/context.d.ts +2 -0
- package/dist/esm/lib/context.js +7 -0
- package/dist/esm/lib/context_user.d.ts +1 -0
- package/dist/esm/lib/context_user.js +15 -1
- package/dist/esm/lib/database/mysql/flags.js +1 -1
- package/dist/esm/lib/database/redis/flags.js +1 -1
- package/dist/esm/lib/domain/dnszone/flags.js +1 -1
- package/dist/esm/lib/domain/flags.js +1 -1
- package/dist/esm/lib/org/flags.js +2 -2
- package/dist/esm/lib/project/flags.js +2 -2
- package/dist/esm/lib/project/ingress.js +2 -2
- package/dist/esm/lib/server/flags.js +2 -2
- package/dist/esm/normalize_id.d.ts +7 -0
- package/dist/esm/normalize_id.js +34 -0
- package/dist/esm/rendering/react/RenderBaseCommand.d.ts +1 -1
- package/package.json +1 -1
- package/dist/esm/Helpers.d.ts +0 -7
- package/dist/esm/Helpers.js +0 -36
- package/dist/esm/Translator.d.ts +0 -9
- package/dist/esm/Translator.js +0 -74
|
@@ -19,13 +19,15 @@ export default class List extends ListBaseCommand {
|
|
|
19
19
|
return data;
|
|
20
20
|
}
|
|
21
21
|
getColumns(data) {
|
|
22
|
-
const
|
|
22
|
+
const { id, userName, createdAt } = super.getColumns(data, {
|
|
23
|
+
shortIdKey: "userName",
|
|
24
|
+
});
|
|
23
25
|
return {
|
|
24
|
-
id
|
|
25
|
-
userName
|
|
26
|
+
id,
|
|
27
|
+
userName,
|
|
26
28
|
description: {},
|
|
27
29
|
active: {},
|
|
28
|
-
createdAt
|
|
30
|
+
createdAt,
|
|
29
31
|
};
|
|
30
32
|
}
|
|
31
33
|
}
|
|
@@ -17,13 +17,15 @@ export class List extends ListBaseCommand {
|
|
|
17
17
|
return data;
|
|
18
18
|
}
|
|
19
19
|
getColumns(data) {
|
|
20
|
-
const
|
|
20
|
+
const { id, userName, createdAt } = super.getColumns(data, {
|
|
21
|
+
shortIdKey: "userName",
|
|
22
|
+
});
|
|
21
23
|
return {
|
|
22
|
-
id
|
|
23
|
-
userName
|
|
24
|
+
id,
|
|
25
|
+
userName,
|
|
24
26
|
description: {},
|
|
25
27
|
active: {},
|
|
26
|
-
createdAt
|
|
28
|
+
createdAt,
|
|
27
29
|
};
|
|
28
30
|
}
|
|
29
31
|
}
|
|
@@ -2,8 +2,7 @@ import { MittwaldAPIV2Client } from "@mittwald/api-client";
|
|
|
2
2
|
import { ProcessRenderer } from "../../rendering/process/process.js";
|
|
3
3
|
import { ProcessFlags } from "../../rendering/process/process_flags.js";
|
|
4
4
|
import { BooleanFlag, FlagInput, OptionFlag, OutputFlags } from "@oclif/core/lib/interfaces/parser.js";
|
|
5
|
-
export declare const appInstallationFlags: import("../context_flags.js").ContextFlags<"
|
|
6
|
-
export declare function normalizeAppInstallationId(apiClient: MittwaldAPIV2Client, projectId: string, id: string): Promise<string>;
|
|
5
|
+
export declare const appInstallationFlags: import("../context_flags.js").ContextFlags<"installation", "installation-id">, appInstallationArgs: import("../context_flags.js").ContextArgs<"installation", "installation-id">, withAppInstallationId: (apiClient: MittwaldAPIV2Client, command: "flag" | "arg" | import("../context_flags.js").CommandType<"installation", "installation-id">, flags: import("@oclif/core/lib/interfaces/parser.js").FlagOutput, args: import("@oclif/core/lib/interfaces/parser.js").ArgOutput, cfg: import("@oclif/core").Config) => Promise<string>;
|
|
7
6
|
export type AvailableFlagName = keyof AvailableFlags;
|
|
8
7
|
interface AvailableFlags {
|
|
9
8
|
version: OptionFlag<string>;
|
|
@@ -4,26 +4,16 @@ import { Value } from "../../rendering/react/components/Value.js";
|
|
|
4
4
|
import { getProjectShortIdFromUuid } from "../project/shortId.js";
|
|
5
5
|
import { Text } from "ink";
|
|
6
6
|
import { assertStatus } from "@mittwald/api-client-commons";
|
|
7
|
-
import {
|
|
7
|
+
import { projectFlags } from "../project/flags.js";
|
|
8
8
|
import { processFlags, } from "../../rendering/process/process_flags.js";
|
|
9
9
|
import { Flags } from "@oclif/core";
|
|
10
10
|
import { generatePasswordWithSpecialChars } from "../password.js";
|
|
11
|
-
import {
|
|
12
|
-
|
|
11
|
+
import { normalizeAppInstallationId } from "../../normalize_id.js";
|
|
12
|
+
import { makeFlagSet } from "../context_flags.js";
|
|
13
|
+
export const { flags: appInstallationFlags, args: appInstallationArgs, withId: withAppInstallationId, } = makeFlagSet("installation", "i", {
|
|
13
14
|
displayName: "app installation",
|
|
14
15
|
normalize: normalizeAppInstallationId,
|
|
15
|
-
supportsContext: true,
|
|
16
16
|
});
|
|
17
|
-
export async function normalizeAppInstallationId(apiClient, projectId, id) {
|
|
18
|
-
if (isUuid(id)) {
|
|
19
|
-
return id;
|
|
20
|
-
}
|
|
21
|
-
const appInstallations = await apiClient.app.listAppinstallations({
|
|
22
|
-
projectId,
|
|
23
|
-
});
|
|
24
|
-
assertStatus(appInstallations, 200);
|
|
25
|
-
return appInstallations.data.find((inst) => inst.shortId === id)?.id ?? id;
|
|
26
|
-
}
|
|
27
17
|
function buildFlagsWithDescription(appName) {
|
|
28
18
|
return {
|
|
29
19
|
version: Flags.string({
|
|
@@ -1,4 +1,40 @@
|
|
|
1
|
-
import { MittwaldAPIV2Client } from "@mittwald/api-client";
|
|
2
|
-
|
|
1
|
+
import { MittwaldAPIV2, MittwaldAPIV2Client } from "@mittwald/api-client";
|
|
2
|
+
import AppAppVersion = MittwaldAPIV2.Components.Schemas.AppAppVersion;
|
|
3
|
+
import AppApp = MittwaldAPIV2.Components.Schemas.AppApp;
|
|
4
|
+
/**
|
|
5
|
+
* Lookup an app by its UUID
|
|
6
|
+
*
|
|
7
|
+
* @param apiClient
|
|
8
|
+
* @param appId
|
|
9
|
+
*/
|
|
10
|
+
export declare function getAppFromUuid(apiClient: MittwaldAPIV2Client, appId: string): Promise<AppApp>;
|
|
11
|
+
/**
|
|
12
|
+
* Lookup an app version by its UUID
|
|
13
|
+
*
|
|
14
|
+
* @param apiClient
|
|
15
|
+
* @param appId
|
|
16
|
+
* @param appVersionId
|
|
17
|
+
*/
|
|
18
|
+
export declare function getAppVersionFromUuid(apiClient: MittwaldAPIV2Client, appId: string, appVersionId: string): Promise<AppAppVersion>;
|
|
19
|
+
/**
|
|
20
|
+
* Lookup an app by its human readable name
|
|
21
|
+
*
|
|
22
|
+
* @param apiClient
|
|
23
|
+
* @param appName
|
|
24
|
+
*/
|
|
25
|
+
export declare function getAppUuidFromAppName(apiClient: MittwaldAPIV2Client, appName: string): Promise<string>;
|
|
26
|
+
/**
|
|
27
|
+
* Lookup an app name by its UUID
|
|
28
|
+
*
|
|
29
|
+
* @param apiClient
|
|
30
|
+
* @param uuid
|
|
31
|
+
*/
|
|
3
32
|
export declare function getAppNameFromUuid(apiClient: MittwaldAPIV2Client, uuid: string): Promise<string>;
|
|
4
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Lookup an app version number by its UUID
|
|
35
|
+
*
|
|
36
|
+
* @param apiClient
|
|
37
|
+
* @param appId
|
|
38
|
+
* @param appVersionId
|
|
39
|
+
*/
|
|
40
|
+
export declare function getAppVersionNumberFromUuid(apiClient: MittwaldAPIV2Client, appId: string, appVersionId: string): Promise<string>;
|
package/dist/esm/lib/app/uuid.js
CHANGED
|
@@ -1,34 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
throw new Error("Access Denied.");
|
|
15
|
-
}
|
|
16
|
-
// Get App Human readable Name from App UUID
|
|
17
|
-
export async function getAppNameFromUuid(apiClient, uuid) {
|
|
18
|
-
if (!isUuid(uuid)) {
|
|
19
|
-
throw new Error("Given UUID not valid.");
|
|
20
|
-
}
|
|
21
|
-
const apps = await apiClient.app.listApps();
|
|
22
|
-
assertStatus(apps, 200);
|
|
23
|
-
const foundApp = apps.data.find((item) => {
|
|
24
|
-
return item.id === uuid;
|
|
25
|
-
});
|
|
26
|
-
if (foundApp) {
|
|
27
|
-
return foundApp.name;
|
|
28
|
-
}
|
|
29
|
-
throw new Error("App not found.");
|
|
1
|
+
import { isUuid } from "../../normalize_id.js";
|
|
2
|
+
import { assertStatus, } from "@mittwald/api-client";
|
|
3
|
+
/**
|
|
4
|
+
* Lookup an app by its UUID
|
|
5
|
+
*
|
|
6
|
+
* @param apiClient
|
|
7
|
+
* @param appId
|
|
8
|
+
*/
|
|
9
|
+
export async function getAppFromUuid(apiClient, appId) {
|
|
10
|
+
const result = await apiClient.app.getApp({ appId });
|
|
11
|
+
assertStatus(result, 200);
|
|
12
|
+
return result.data;
|
|
30
13
|
}
|
|
31
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Lookup an app version by its UUID
|
|
16
|
+
*
|
|
17
|
+
* @param apiClient
|
|
18
|
+
* @param appId
|
|
19
|
+
* @param appVersionId
|
|
20
|
+
*/
|
|
32
21
|
export async function getAppVersionFromUuid(apiClient, appId, appVersionId) {
|
|
33
22
|
if (!isUuid(appId) && !isUuid(appVersionId)) {
|
|
34
23
|
throw new Error("Given UUID not valid.");
|
|
@@ -37,8 +26,52 @@ export async function getAppVersionFromUuid(apiClient, appId, appVersionId) {
|
|
|
37
26
|
appId: appId,
|
|
38
27
|
appVersionId: appVersionId,
|
|
39
28
|
});
|
|
40
|
-
|
|
41
|
-
|
|
29
|
+
assertStatus(appVersion, 200);
|
|
30
|
+
return appVersion.data;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Convert an app name in a format suitable for fuzzy comparison (ignore casing,
|
|
34
|
+
* punctuation, etc.)
|
|
35
|
+
*
|
|
36
|
+
* @param appName
|
|
37
|
+
*/
|
|
38
|
+
function canonicalizeAppName(appName) {
|
|
39
|
+
return appName.toLowerCase().replace(/[!. ]/g, "");
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Lookup an app by its human readable name
|
|
43
|
+
*
|
|
44
|
+
* @param apiClient
|
|
45
|
+
* @param appName
|
|
46
|
+
*/
|
|
47
|
+
export async function getAppUuidFromAppName(apiClient, appName) {
|
|
48
|
+
const apps = await apiClient.app.listApps();
|
|
49
|
+
assertStatus(apps, 200);
|
|
50
|
+
const appNameCanonical = canonicalizeAppName(appName);
|
|
51
|
+
const appNameMatches = (item) => canonicalizeAppName(item.name) === appNameCanonical;
|
|
52
|
+
const foundApp = apps.data.find(appNameMatches);
|
|
53
|
+
if (foundApp) {
|
|
54
|
+
return foundApp.id;
|
|
42
55
|
}
|
|
43
|
-
throw new Error("
|
|
56
|
+
throw new Error("Access Denied.");
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Lookup an app name by its UUID
|
|
60
|
+
*
|
|
61
|
+
* @param apiClient
|
|
62
|
+
* @param uuid
|
|
63
|
+
*/
|
|
64
|
+
export async function getAppNameFromUuid(apiClient, uuid) {
|
|
65
|
+
return (await getAppFromUuid(apiClient, uuid)).name;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Lookup an app version number by its UUID
|
|
69
|
+
*
|
|
70
|
+
* @param apiClient
|
|
71
|
+
* @param appId
|
|
72
|
+
* @param appVersionId
|
|
73
|
+
*/
|
|
74
|
+
export async function getAppVersionNumberFromUuid(apiClient, appId, appVersionId) {
|
|
75
|
+
return (await getAppVersionFromUuid(apiClient, appId, appVersionId))
|
|
76
|
+
.externalVersion;
|
|
44
77
|
}
|
|
@@ -17,12 +17,14 @@ export interface ContextProvider {
|
|
|
17
17
|
}
|
|
18
18
|
export interface WritableContextProvider extends ContextProvider {
|
|
19
19
|
update(data: ContextMapUpdate): Promise<void>;
|
|
20
|
+
reset(): Promise<void>;
|
|
20
21
|
}
|
|
21
22
|
export declare class Context {
|
|
22
23
|
private readonly contextData;
|
|
23
24
|
readonly providers: ContextProvider[];
|
|
24
25
|
constructor(config: Config);
|
|
25
26
|
private initializeContextData;
|
|
27
|
+
reset(): Promise<void>;
|
|
26
28
|
private persist;
|
|
27
29
|
private setContextValue;
|
|
28
30
|
getContextValue(key: ContextKey): Promise<ContextValue | undefined>;
|
package/dist/esm/lib/context.js
CHANGED
|
@@ -21,6 +21,13 @@ export class Context {
|
|
|
21
21
|
}
|
|
22
22
|
return contextData;
|
|
23
23
|
}
|
|
24
|
+
async reset() {
|
|
25
|
+
for (const provider of this.providers) {
|
|
26
|
+
if (isWritable(provider)) {
|
|
27
|
+
await provider.reset();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
24
31
|
async persist(data) {
|
|
25
32
|
for (const provider of this.providers) {
|
|
26
33
|
if (isWritable(provider)) {
|
|
@@ -6,5 +6,6 @@ export declare class UserContextProvider implements ContextProvider, WritableCon
|
|
|
6
6
|
constructor(config: Config);
|
|
7
7
|
private get contextFile();
|
|
8
8
|
getOverrides(): Promise<ContextMap>;
|
|
9
|
+
reset(): Promise<void>;
|
|
9
10
|
update(updatedData: Record<ContextKey, string>): Promise<void>;
|
|
10
11
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import fs from "fs/promises";
|
|
2
2
|
import path from "path";
|
|
3
|
+
function isNotExists(e) {
|
|
4
|
+
return e instanceof Error && "code" in e && e.code === "ENOENT";
|
|
5
|
+
}
|
|
3
6
|
export class UserContextProvider {
|
|
4
7
|
config;
|
|
5
8
|
name = "user";
|
|
@@ -17,12 +20,23 @@ export class UserContextProvider {
|
|
|
17
20
|
return Object.fromEntries(Object.entries(rawValues).map(([k, v]) => [k, { value: v, source }]));
|
|
18
21
|
}
|
|
19
22
|
catch (e) {
|
|
20
|
-
if (e
|
|
23
|
+
if (isNotExists(e)) {
|
|
21
24
|
return {};
|
|
22
25
|
}
|
|
23
26
|
throw e;
|
|
24
27
|
}
|
|
25
28
|
}
|
|
29
|
+
async reset() {
|
|
30
|
+
try {
|
|
31
|
+
await fs.unlink(this.contextFile);
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
if (isNotExists(e)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
throw e;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
26
40
|
async update(updatedData) {
|
|
27
41
|
const data = await this.getOverrides();
|
|
28
42
|
const source = { type: "user", identifier: this.contextFile };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Args, Flags } from "@oclif/core";
|
|
2
|
-
import { isUuid } from "../../../
|
|
2
|
+
import { isUuid } from "../../../normalize_id.js";
|
|
3
3
|
import { withProjectId } from "../../project/flags.js";
|
|
4
4
|
import { assertStatus } from "@mittwald/api-client-commons";
|
|
5
5
|
export const mysqlConnectionFlags = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Args } from "@oclif/core";
|
|
2
|
-
import { isUuid } from "../../../
|
|
2
|
+
import { isUuid } from "../../../normalize_id.js";
|
|
3
3
|
import { withProjectId } from "../../project/flags.js";
|
|
4
4
|
import { assertStatus } from "@mittwald/api-client-commons";
|
|
5
5
|
export const redisArgs = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isUuid } from "../../../
|
|
1
|
+
import { isUuid } from "../../../normalize_id.js";
|
|
2
2
|
import { makeProjectFlagSet } from "../../project/flags.js";
|
|
3
3
|
import { assertStatus } from "@mittwald/api-client-commons";
|
|
4
4
|
export const { flags: dnsZoneFlags, args: dnsZoneArgs, withId: withDnsZoneId, } = makeProjectFlagSet("dnszone", "z", {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isUuid } from "../../
|
|
1
|
+
import { isUuid } from "../../normalize_id.js";
|
|
2
2
|
import { makeProjectFlagSet } from "../project/flags.js";
|
|
3
3
|
import { assertStatus } from "@mittwald/api-client-commons";
|
|
4
4
|
export const { flags: domainFlags, args: domainArgs, withId: withDomainId, } = makeProjectFlagSet("domain", "d", {
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { makeFlagSet } from "../context_flags.js";
|
|
2
|
-
import {
|
|
3
|
-
export const { flags: orgFlags, args: orgArgs, withId: withOrgId, } = makeFlagSet("org", "o", { normalize:
|
|
2
|
+
import { normalizeCustomerId } from "../../normalize_id.js";
|
|
3
|
+
export const { flags: orgFlags, args: orgArgs, withId: withOrgId, } = makeFlagSet("org", "o", { normalize: normalizeCustomerId });
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { isUuid,
|
|
1
|
+
import { isUuid, normalizeProjectId } from "../../normalize_id.js";
|
|
2
2
|
import { makeFlagSet, makeMissingContextInputError, } from "../context_flags.js";
|
|
3
3
|
import { Context } from "../context.js";
|
|
4
4
|
import { Args, Flags } from "@oclif/core";
|
|
5
|
-
export const { flags: projectFlags, args: projectArgs, withId: withProjectId, } = makeFlagSet("project", "p", { normalize:
|
|
5
|
+
export const { flags: projectFlags, args: projectArgs, withId: withProjectId, } = makeFlagSet("project", "p", { normalize: normalizeProjectId });
|
|
6
6
|
export function makeProjectFlagSet(name, char, opts = {}) {
|
|
7
7
|
const { normalize = (_1, _2, id) => id, shortIDName = "short ID", displayName = name, supportsContext = false, } = opts;
|
|
8
8
|
const article = displayName.match(/^[aeiou]/i) ? "an" : "a";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { assertStatus } from "@mittwald/api-client-commons";
|
|
2
|
-
import {
|
|
2
|
+
import { normalizeProjectId } from "../../normalize_id.js";
|
|
3
3
|
export async function getDefaultIngressForProject(apiClient, projectId) {
|
|
4
|
-
const projectUuid = await
|
|
4
|
+
const projectUuid = await normalizeProjectId(apiClient, projectId);
|
|
5
5
|
const projectIngresses = await apiClient.domain.ingressListIngresses({
|
|
6
6
|
queryParameters: {
|
|
7
7
|
projectId: projectUuid,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { normalizeServerId } from "../../normalize_id.js";
|
|
2
2
|
import { makeFlagSet } from "../context_flags.js";
|
|
3
|
-
export const { flags: serverFlags, args: serverArgs, withId: withServerId, } = makeFlagSet("server", "s", { normalize:
|
|
3
|
+
export const { flags: serverFlags, args: serverArgs, withId: withServerId, } = makeFlagSet("server", "s", { normalize: normalizeServerId });
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { MittwaldAPIV2Client } from "@mittwald/api-client";
|
|
2
|
+
export declare function isUuid(id: string): boolean;
|
|
3
|
+
export declare function normalizeProjectId(apiClient: MittwaldAPIV2Client, projectId: string): Promise<string>;
|
|
4
|
+
export declare function normalizeServerId(apiClient: MittwaldAPIV2Client, serverId: string): Promise<string>;
|
|
5
|
+
export declare function normalizeCustomerId(apiClient: MittwaldAPIV2Client, customerId: string): Promise<string>;
|
|
6
|
+
export declare function normalizeConversationId(apiClient: MittwaldAPIV2Client, conversationId: string): Promise<string>;
|
|
7
|
+
export declare function normalizeAppInstallationId(apiClient: MittwaldAPIV2Client, appInstallationId: string): Promise<string>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { assertStatus } from "@mittwald/api-client";
|
|
2
|
+
const uuidRegex = RegExp("^[0-9a-fA-F]{8}(-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}$");
|
|
3
|
+
export function isUuid(id) {
|
|
4
|
+
return uuidRegex.test(id);
|
|
5
|
+
}
|
|
6
|
+
export async function normalizeProjectId(apiClient, projectId) {
|
|
7
|
+
const result = await apiClient.project.getProject({ projectId });
|
|
8
|
+
assertStatus(result, 200);
|
|
9
|
+
return result.data.id;
|
|
10
|
+
}
|
|
11
|
+
export async function normalizeServerId(apiClient, serverId) {
|
|
12
|
+
const result = await apiClient.project.getServer({ serverId });
|
|
13
|
+
assertStatus(result, 200);
|
|
14
|
+
return result.data.id;
|
|
15
|
+
}
|
|
16
|
+
export async function normalizeCustomerId(apiClient, customerId) {
|
|
17
|
+
const customer = await apiClient.customer.getCustomer({ customerId });
|
|
18
|
+
assertStatus(customer, 200);
|
|
19
|
+
return customer.data.customerId;
|
|
20
|
+
}
|
|
21
|
+
export async function normalizeConversationId(apiClient, conversationId) {
|
|
22
|
+
const conversation = await apiClient.conversation.getConversation({
|
|
23
|
+
conversationId,
|
|
24
|
+
});
|
|
25
|
+
assertStatus(conversation, 200);
|
|
26
|
+
return conversation.data.conversationId;
|
|
27
|
+
}
|
|
28
|
+
export async function normalizeAppInstallationId(apiClient, appInstallationId) {
|
|
29
|
+
const appInstallations = await apiClient.app.getAppinstallation({
|
|
30
|
+
appInstallationId,
|
|
31
|
+
});
|
|
32
|
+
assertStatus(appInstallations, 200);
|
|
33
|
+
return appInstallations.data.id;
|
|
34
|
+
}
|
|
@@ -16,7 +16,7 @@ export declare abstract class RenderBaseCommand<T extends typeof BaseCommand> ex
|
|
|
16
16
|
init(): Promise<void>;
|
|
17
17
|
run(): Promise<void>;
|
|
18
18
|
protected abstract render(): ReactNode;
|
|
19
|
-
protected useAppInstallationId(command: CommandType<"installation"
|
|
19
|
+
protected useAppInstallationId(command: CommandType<"installation"> | "flag" | "arg"): string;
|
|
20
20
|
protected useProjectId(command: CommandType<"project"> | "flag" | "arg"): string;
|
|
21
21
|
}
|
|
22
22
|
export {};
|
package/package.json
CHANGED
package/dist/esm/Helpers.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { MittwaldAPIV2Client } from "@mittwald/api-client";
|
|
2
|
-
export declare function isUuid(id: string): boolean;
|
|
3
|
-
export declare function isProjectShortId(id: string): boolean;
|
|
4
|
-
export declare function normalizeProjectIdToUuid(apiClient: MittwaldAPIV2Client, uuidOrShortId: string): Promise<string>;
|
|
5
|
-
export declare function normalizeServerIdToUuid(apiClient: MittwaldAPIV2Client, uuidOrShortId: string): Promise<string>;
|
|
6
|
-
export declare function normalizeCustomerIdToUuid(apiClient: MittwaldAPIV2Client, uuidOrShortId: string): Promise<string>;
|
|
7
|
-
export declare function normalizeConversationIdToUuid(apiClient: MittwaldAPIV2Client, uuidOrShortId: string): Promise<string>;
|
package/dist/esm/Helpers.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { getConversationUuidFromShortId, getCustomerUuidFromCustomerNumber, getProjectUuidFromShortId, getServerUuidFromShortId, } from "./Translator.js";
|
|
2
|
-
const uuidRegex = RegExp("^[0-9a-fA-F]{8}(-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}$");
|
|
3
|
-
const projectShortIdRegex = RegExp("p-[0-9a-zA-Z]{6}");
|
|
4
|
-
export function isUuid(id) {
|
|
5
|
-
return uuidRegex.test(id);
|
|
6
|
-
}
|
|
7
|
-
export function isProjectShortId(id) {
|
|
8
|
-
return projectShortIdRegex.test(id);
|
|
9
|
-
}
|
|
10
|
-
export async function normalizeProjectIdToUuid(apiClient, uuidOrShortId) {
|
|
11
|
-
if (isUuid(uuidOrShortId)) {
|
|
12
|
-
return uuidOrShortId;
|
|
13
|
-
}
|
|
14
|
-
if (isProjectShortId(uuidOrShortId)) {
|
|
15
|
-
return await getProjectUuidFromShortId(apiClient, uuidOrShortId);
|
|
16
|
-
}
|
|
17
|
-
throw new Error(`Given ID ${uuidOrShortId} does not seem to be valid`);
|
|
18
|
-
}
|
|
19
|
-
export async function normalizeServerIdToUuid(apiClient, uuidOrShortId) {
|
|
20
|
-
if (isUuid(uuidOrShortId)) {
|
|
21
|
-
return uuidOrShortId;
|
|
22
|
-
}
|
|
23
|
-
return await getServerUuidFromShortId(apiClient, uuidOrShortId);
|
|
24
|
-
}
|
|
25
|
-
export async function normalizeCustomerIdToUuid(apiClient, uuidOrShortId) {
|
|
26
|
-
if (isUuid(uuidOrShortId)) {
|
|
27
|
-
return uuidOrShortId;
|
|
28
|
-
}
|
|
29
|
-
return await getCustomerUuidFromCustomerNumber(apiClient, uuidOrShortId);
|
|
30
|
-
}
|
|
31
|
-
export async function normalizeConversationIdToUuid(apiClient, uuidOrShortId) {
|
|
32
|
-
if (isUuid(uuidOrShortId)) {
|
|
33
|
-
return uuidOrShortId;
|
|
34
|
-
}
|
|
35
|
-
return await getConversationUuidFromShortId(apiClient, uuidOrShortId);
|
|
36
|
-
}
|
package/dist/esm/Translator.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { MittwaldAPIV2, MittwaldAPIV2Client } from "@mittwald/api-client";
|
|
2
|
-
import AppAppVersion = MittwaldAPIV2.Components.Schemas.AppAppVersion;
|
|
3
|
-
import AppApp = MittwaldAPIV2.Components.Schemas.AppApp;
|
|
4
|
-
export declare function getProjectUuidFromShortId(apiClient: MittwaldAPIV2Client, shortId: string): Promise<string>;
|
|
5
|
-
export declare function getServerUuidFromShortId(apiClient: MittwaldAPIV2Client, shortId: string): Promise<string>;
|
|
6
|
-
export declare function getCustomerUuidFromCustomerNumber(apiClient: MittwaldAPIV2Client, shortId: string): Promise<string>;
|
|
7
|
-
export declare function getConversationUuidFromShortId(apiClient: MittwaldAPIV2Client, shortId: string): Promise<string>;
|
|
8
|
-
export declare function getAppFromUuid(apiClient: MittwaldAPIV2Client, uuid: string): Promise<AppApp>;
|
|
9
|
-
export declare function getAppVersionFromUuid(apiClient: MittwaldAPIV2Client, appId: string, appVersionId: string): Promise<AppAppVersion>;
|
package/dist/esm/Translator.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { assertStatus } from "@mittwald/api-client-commons";
|
|
2
|
-
import { isProjectShortId, isUuid } from "./Helpers.js";
|
|
3
|
-
export async function getProjectUuidFromShortId(apiClient, shortId) {
|
|
4
|
-
if (!isProjectShortId(shortId)) {
|
|
5
|
-
throw new Error("Given ShortID not valid.");
|
|
6
|
-
}
|
|
7
|
-
const projects = await apiClient.project.listProjects();
|
|
8
|
-
assertStatus(projects, 200);
|
|
9
|
-
const foundProject = projects.data.find((item) => {
|
|
10
|
-
return item.shortId === shortId;
|
|
11
|
-
});
|
|
12
|
-
if (foundProject) {
|
|
13
|
-
return foundProject.id;
|
|
14
|
-
}
|
|
15
|
-
throw new Error("Access Denied.");
|
|
16
|
-
}
|
|
17
|
-
export async function getServerUuidFromShortId(apiClient, shortId) {
|
|
18
|
-
const servers = await apiClient.project.listServers();
|
|
19
|
-
assertStatus(servers, 200);
|
|
20
|
-
const foundServer = servers.data.find((item) => {
|
|
21
|
-
return item.shortId === shortId;
|
|
22
|
-
});
|
|
23
|
-
if (foundServer) {
|
|
24
|
-
return foundServer.id;
|
|
25
|
-
}
|
|
26
|
-
throw new Error("Access Denied.");
|
|
27
|
-
}
|
|
28
|
-
export async function getCustomerUuidFromCustomerNumber(apiClient, shortId) {
|
|
29
|
-
const customers = await apiClient.customer.listCustomers();
|
|
30
|
-
assertStatus(customers, 200);
|
|
31
|
-
const foundCustomer = customers.data.find((item) => {
|
|
32
|
-
return item.customerNumber === shortId;
|
|
33
|
-
});
|
|
34
|
-
if (foundCustomer) {
|
|
35
|
-
return foundCustomer.customerId;
|
|
36
|
-
}
|
|
37
|
-
throw new Error("Access Denied.");
|
|
38
|
-
}
|
|
39
|
-
export async function getConversationUuidFromShortId(apiClient, shortId) {
|
|
40
|
-
const conversations = await apiClient.conversation.listConversations();
|
|
41
|
-
assertStatus(conversations, 200);
|
|
42
|
-
const foundConversation = conversations.data.find((item) => {
|
|
43
|
-
return item.shortId === shortId;
|
|
44
|
-
});
|
|
45
|
-
if (foundConversation) {
|
|
46
|
-
return foundConversation.conversationId;
|
|
47
|
-
}
|
|
48
|
-
throw new Error("Access Denied.");
|
|
49
|
-
}
|
|
50
|
-
export async function getAppFromUuid(apiClient, uuid) {
|
|
51
|
-
if (!isUuid(uuid)) {
|
|
52
|
-
throw new Error("Given UUID not valid.");
|
|
53
|
-
}
|
|
54
|
-
const apps = await apiClient.app.listApps();
|
|
55
|
-
assertStatus(apps, 200);
|
|
56
|
-
const foundApp = apps.data.find((item) => {
|
|
57
|
-
return item.id === uuid;
|
|
58
|
-
});
|
|
59
|
-
if (foundApp) {
|
|
60
|
-
return foundApp;
|
|
61
|
-
}
|
|
62
|
-
throw new Error("App not found.");
|
|
63
|
-
}
|
|
64
|
-
export async function getAppVersionFromUuid(apiClient, appId, appVersionId) {
|
|
65
|
-
if (!isUuid(appId) && !isUuid(appVersionId)) {
|
|
66
|
-
throw new Error("Given UUID not valid.");
|
|
67
|
-
}
|
|
68
|
-
const appVersion = await apiClient.app.getAppversion({
|
|
69
|
-
appId: appId,
|
|
70
|
-
appVersionId: appVersionId,
|
|
71
|
-
});
|
|
72
|
-
assertStatus(appVersion, 200);
|
|
73
|
-
return appVersion.data;
|
|
74
|
-
}
|