@mondaydotcomorg/z2h-cli 0.13.0 → 0.13.2
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/dist/commands/delete.d.ts +6 -0
- package/dist/commands/delete.d.ts.map +1 -0
- package/dist/commands/delete.js +53 -0
- package/dist/commands/deploy.d.ts.map +1 -1
- package/dist/commands/deploy.js +26 -0
- package/dist/commands/tag.d.ts +14 -0
- package/dist/commands/tag.d.ts.map +1 -0
- package/dist/commands/tag.js +114 -0
- package/dist/esm/commands/delete.d.ts +6 -0
- package/dist/esm/commands/delete.d.ts.map +1 -0
- package/dist/esm/commands/delete.mjs +51 -0
- package/dist/esm/commands/deploy.d.ts.map +1 -1
- package/dist/esm/commands/deploy.mjs +27 -1
- package/dist/esm/commands/tag.d.ts +14 -0
- package/dist/esm/commands/tag.d.ts.map +1 -0
- package/dist/esm/commands/tag.mjs +107 -0
- package/dist/esm/index.mjs +36 -0
- package/dist/esm/util/git/repo.d.ts.map +1 -1
- package/dist/esm/util/git/repo.mjs +10 -0
- package/dist/esm/util/tags.d.ts +24 -0
- package/dist/esm/util/tags.d.ts.map +1 -0
- package/dist/esm/util/tags.mjs +63 -0
- package/dist/index.js +36 -0
- package/dist/util/git/repo.d.ts.map +1 -1
- package/dist/util/git/repo.js +10 -0
- package/dist/util/tags.d.ts +24 -0
- package/dist/util/tags.d.ts.map +1 -0
- package/dist/util/tags.js +69 -0
- package/package.json +1 -1
- package/src/commands/delete.ts +63 -0
- package/src/commands/deploy.ts +31 -1
- package/src/commands/tag.ts +134 -0
- package/src/index.ts +37 -0
- package/src/util/git/__tests__/repo.test.ts +23 -1
- package/src/util/git/repo.ts +12 -0
- package/src/util/tags.ts +94 -0
package/src/util/tags.ts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { brokerBaseUrl, routingHeaders } from '../constants';
|
|
2
|
+
import { readZthAuth } from './auth/auth-store';
|
|
3
|
+
|
|
4
|
+
/** The dimension a tag categorizes an app by. */
|
|
5
|
+
export type TagType = 'app_type' | 'team';
|
|
6
|
+
|
|
7
|
+
/** The tag dimensions, in prompt order. */
|
|
8
|
+
export const TAG_TYPES: TagType[] = ['app_type', 'team'];
|
|
9
|
+
|
|
10
|
+
/** Human labels for each dimension (CLI prompts / output). */
|
|
11
|
+
export const TAG_TYPE_LABELS: Record<TagType, string> = {
|
|
12
|
+
app_type: 'App type',
|
|
13
|
+
team: 'Team',
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/** A catalog entry: one selectable tag with its dimension + global usage count. */
|
|
17
|
+
export interface CatalogEntry {
|
|
18
|
+
name: string;
|
|
19
|
+
type: TagType;
|
|
20
|
+
count: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** A tag assigned to an app — name + dimension. */
|
|
24
|
+
export interface AppTag {
|
|
25
|
+
name: string;
|
|
26
|
+
type: TagType;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface CatalogResponse {
|
|
30
|
+
tags?: CatalogEntry[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface AppTagsResponse {
|
|
34
|
+
tags?: AppTag[];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Authenticated request to the bigbrain-zth tag endpoints. Mirrors the Bearer
|
|
39
|
+
* pattern used by the STS broker / lock-release calls, with network-error
|
|
40
|
+
* wrapping, auth-failure guidance, and response-body inclusion on failure.
|
|
41
|
+
*/
|
|
42
|
+
async function tagFetch(method: 'GET' | 'PUT', path: string, body?: unknown): Promise<Response> {
|
|
43
|
+
const { token } = await readZthAuth();
|
|
44
|
+
|
|
45
|
+
let res: Response;
|
|
46
|
+
try {
|
|
47
|
+
res = await fetch(`${brokerBaseUrl()}${path}`, {
|
|
48
|
+
method,
|
|
49
|
+
headers: {
|
|
50
|
+
Authorization: `Bearer ${token}`,
|
|
51
|
+
Accept: 'application/json',
|
|
52
|
+
...(body === undefined ? {} : { 'Content-Type': 'application/json' }),
|
|
53
|
+
...routingHeaders(),
|
|
54
|
+
},
|
|
55
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
56
|
+
});
|
|
57
|
+
} catch (err) {
|
|
58
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
59
|
+
throw new Error(`Z2H tag request failed: ${message}`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (res.status === 401 || res.status === 403) {
|
|
63
|
+
throw new Error(
|
|
64
|
+
`Z2H tag request rejected by the broker (${res.status}). Refresh your token by running 'z2h-cli generate-z2h-token'.`
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
if (!res.ok) {
|
|
68
|
+
const text = await res.text();
|
|
69
|
+
throw new Error(`Z2H tag request returned ${res.status}: ${text.slice(0, 1024)}`);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return res;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The full closed tag catalog (app types + teams), with usage counts. */
|
|
76
|
+
export async function fetchTagCatalog(): Promise<CatalogEntry[]> {
|
|
77
|
+
const res = await tagFetch('GET', '/z2h-cli/tags');
|
|
78
|
+
const data = (await res.json()) as CatalogResponse;
|
|
79
|
+
return data.tags ?? [];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Tags currently assigned to an app (bare slug). */
|
|
83
|
+
export async function fetchAppTags(appSlug: string): Promise<AppTag[]> {
|
|
84
|
+
const res = await tagFetch('GET', `/z2h-cli/tags/${encodeURIComponent(appSlug)}`);
|
|
85
|
+
const data = (await res.json()) as AppTagsResponse;
|
|
86
|
+
return data.tags ?? [];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Full-replace an app's tag set; returns the resulting tags. */
|
|
90
|
+
export async function setAppTags(appSlug: string, tags: string[]): Promise<AppTag[]> {
|
|
91
|
+
const res = await tagFetch('PUT', `/z2h-cli/tags/${encodeURIComponent(appSlug)}`, { tags });
|
|
92
|
+
const data = (await res.json()) as AppTagsResponse;
|
|
93
|
+
return data.tags ?? [];
|
|
94
|
+
}
|