zinkee 0.1.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.
Files changed (61) hide show
  1. package/AGENTS.md +46 -0
  2. package/README.md +395 -0
  3. package/dist/index.d.ts +13 -0
  4. package/dist/index.js +7142 -0
  5. package/dist/index.js.map +1 -0
  6. package/package.json +32 -0
  7. package/src/api/automations.ts +403 -0
  8. package/src/api/comments.ts +51 -0
  9. package/src/api/displays.ts +276 -0
  10. package/src/api/files.ts +50 -0
  11. package/src/api/navigation.ts +71 -0
  12. package/src/api/records.ts +167 -0
  13. package/src/api/schemas.ts +130 -0
  14. package/src/api/teamspace.ts +110 -0
  15. package/src/cli-examples.ts +175 -0
  16. package/src/cli-runner.ts +73 -0
  17. package/src/client.test.ts +128 -0
  18. package/src/client.ts +243 -0
  19. package/src/command-registry.ts +749 -0
  20. package/src/commands/automations.test.ts +728 -0
  21. package/src/commands/automations.ts +2013 -0
  22. package/src/commands/comments.test.ts +214 -0
  23. package/src/commands/comments.ts +303 -0
  24. package/src/commands/config.test.ts +81 -0
  25. package/src/commands/config.ts +150 -0
  26. package/src/commands/displays.test.ts +266 -0
  27. package/src/commands/displays.ts +755 -0
  28. package/src/commands/files.test.ts +284 -0
  29. package/src/commands/files.ts +280 -0
  30. package/src/commands/navigation.test.ts +214 -0
  31. package/src/commands/navigation.ts +348 -0
  32. package/src/commands/profiles.test.ts +82 -0
  33. package/src/commands/profiles.ts +281 -0
  34. package/src/commands/records.test.ts +367 -0
  35. package/src/commands/records.ts +726 -0
  36. package/src/commands/schemas.test.ts +748 -0
  37. package/src/commands/schemas.ts +746 -0
  38. package/src/commands/teamspace.test.ts +229 -0
  39. package/src/commands/teamspace.ts +540 -0
  40. package/src/config.test.ts +165 -0
  41. package/src/config.ts +248 -0
  42. package/src/index.test.ts +140 -0
  43. package/src/index.ts +8 -0
  44. package/src/parsers/expressions.test.ts +50 -0
  45. package/src/parsers/expressions.ts +111 -0
  46. package/src/parsers/kv.test.ts +35 -0
  47. package/src/parsers/kv.ts +49 -0
  48. package/src/parsers/selectors.test.ts +23 -0
  49. package/src/parsers/selectors.ts +29 -0
  50. package/src/program.ts +56 -0
  51. package/src/runtime-context.ts +18 -0
  52. package/src/types.ts +71 -0
  53. package/src/utils/errors.test.ts +48 -0
  54. package/src/utils/errors.ts +183 -0
  55. package/src/utils/examples.test.ts +67 -0
  56. package/src/utils/examples.ts +855 -0
  57. package/src/utils/output.test.ts +39 -0
  58. package/src/utils/output.ts +124 -0
  59. package/src/utils/schema-fields.ts +529 -0
  60. package/tsconfig.json +20 -0
  61. package/tsup.config.ts +13 -0
@@ -0,0 +1,276 @@
1
+ import { ApiClient } from "../client.js";
2
+ import type { NormalizedUuidOrSlug } from "../parsers/selectors.js";
3
+
4
+ export interface ApiDisplay {
5
+ [key: string]: unknown;
6
+ id?: string;
7
+ name?: string;
8
+ layoutTemplate?: string;
9
+ layout?: {
10
+ template?: string;
11
+ freeformLayouts?: unknown;
12
+ slots?: Array<Record<string, unknown>>;
13
+ tabs?: Array<Record<string, unknown>>;
14
+ };
15
+ variables?: Array<Record<string, unknown>>;
16
+ widgets?: Array<Record<string, unknown>>;
17
+ navigationTargets?: Array<Record<string, unknown>>;
18
+ crossWidgetFilter?: Record<string, unknown> | null;
19
+ }
20
+
21
+ export interface ApiDisplayTab {
22
+ [key: string]: unknown;
23
+ id?: string;
24
+ name?: string;
25
+ orientation?: string;
26
+ }
27
+
28
+ export interface ApiDisplayVariable {
29
+ [key: string]: unknown;
30
+ id?: string;
31
+ name?: string;
32
+ type?: string;
33
+ }
34
+
35
+ export interface ApiDisplayWidget {
36
+ [key: string]: unknown;
37
+ id?: string;
38
+ name?: string;
39
+ type?: string;
40
+ }
41
+
42
+ export interface ApiDisplayNavigationTarget {
43
+ [key: string]: unknown;
44
+ id?: string;
45
+ label?: string;
46
+ }
47
+
48
+ export type DisplaySummary = ApiDisplay;
49
+ export type DisplayResource = ApiDisplay;
50
+
51
+ function jsonOptions(body: unknown, method: string): RequestInit {
52
+ return {
53
+ method,
54
+ headers: {
55
+ "content-type": "application/json",
56
+ },
57
+ body: JSON.stringify(body),
58
+ };
59
+ }
60
+
61
+ function selectorValue(selector: NormalizedUuidOrSlug): string {
62
+ return encodeURIComponent(selector.value);
63
+ }
64
+
65
+ function segment(value: string): string {
66
+ return encodeURIComponent(value);
67
+ }
68
+
69
+ export class DisplaysApi {
70
+ constructor(private readonly client: ApiClient) {}
71
+
72
+ listDisplays(): Promise<ApiDisplay[]> {
73
+ return this.client.getJson<ApiDisplay[]>("/api/v2/displays");
74
+ }
75
+
76
+ getDisplay(display: NormalizedUuidOrSlug): Promise<ApiDisplay> {
77
+ return this.client.getJson<ApiDisplay>(`/api/v2/displays/${selectorValue(display)}`);
78
+ }
79
+
80
+ createDisplay(body: Record<string, unknown>): Promise<ApiDisplay> {
81
+ return this.client.requestJson<ApiDisplay>("/api/v2/displays", jsonOptions(body, "POST"));
82
+ }
83
+
84
+ updateDisplay(
85
+ display: NormalizedUuidOrSlug,
86
+ body: Record<string, unknown>,
87
+ ): Promise<ApiDisplay> {
88
+ return this.client.requestJson<ApiDisplay>(
89
+ `/api/v2/displays/${selectorValue(display)}`,
90
+ jsonOptions(body, "PATCH"),
91
+ );
92
+ }
93
+
94
+ deleteDisplay(display: NormalizedUuidOrSlug): Promise<Record<string, unknown>> {
95
+ return this.client.requestJson<Record<string, unknown>>(
96
+ `/api/v2/displays/${selectorValue(display)}`,
97
+ { method: "DELETE" },
98
+ );
99
+ }
100
+
101
+ getLayout(display: NormalizedUuidOrSlug): Promise<Record<string, unknown>> {
102
+ return this.client.getJson<Record<string, unknown>>(
103
+ `/api/v2/displays/${selectorValue(display)}/layout`,
104
+ );
105
+ }
106
+
107
+ patchLayout(
108
+ display: NormalizedUuidOrSlug,
109
+ body: Record<string, unknown>,
110
+ ): Promise<Record<string, unknown>> {
111
+ return this.client.requestJson<Record<string, unknown>>(
112
+ `/api/v2/displays/${selectorValue(display)}/layout`,
113
+ jsonOptions(body, "PATCH"),
114
+ );
115
+ }
116
+
117
+ listTabs(display: NormalizedUuidOrSlug): Promise<ApiDisplayTab[]> {
118
+ return this.client.getJson<ApiDisplayTab[]>(
119
+ `/api/v2/displays/${selectorValue(display)}/tabs`,
120
+ );
121
+ }
122
+
123
+ createTab(
124
+ display: NormalizedUuidOrSlug,
125
+ body: Record<string, unknown>,
126
+ ): Promise<ApiDisplayTab> {
127
+ return this.client.requestJson<ApiDisplayTab>(
128
+ `/api/v2/displays/${selectorValue(display)}/tabs`,
129
+ jsonOptions(body, "POST"),
130
+ );
131
+ }
132
+
133
+ updateTab(
134
+ display: NormalizedUuidOrSlug,
135
+ tabId: string,
136
+ body: Record<string, unknown>,
137
+ ): Promise<ApiDisplayTab> {
138
+ return this.client.requestJson<ApiDisplayTab>(
139
+ `/api/v2/displays/${selectorValue(display)}/tabs/${segment(tabId)}`,
140
+ jsonOptions(body, "PATCH"),
141
+ );
142
+ }
143
+
144
+ deleteTab(display: NormalizedUuidOrSlug, tabId: string): Promise<Record<string, unknown>> {
145
+ return this.client.requestJson<Record<string, unknown>>(
146
+ `/api/v2/displays/${selectorValue(display)}/tabs/${segment(tabId)}`,
147
+ { method: "DELETE" },
148
+ );
149
+ }
150
+
151
+ listVariables(display: NormalizedUuidOrSlug): Promise<ApiDisplayVariable[]> {
152
+ return this.client.getJson<ApiDisplayVariable[]>(
153
+ `/api/v2/displays/${selectorValue(display)}/variables`,
154
+ );
155
+ }
156
+
157
+ getVariable(display: NormalizedUuidOrSlug, variableId: string): Promise<ApiDisplayVariable> {
158
+ return this.client.getJson<ApiDisplayVariable>(
159
+ `/api/v2/displays/${selectorValue(display)}/variables/${segment(variableId)}`,
160
+ );
161
+ }
162
+
163
+ createVariable(
164
+ display: NormalizedUuidOrSlug,
165
+ body: Record<string, unknown>,
166
+ ): Promise<ApiDisplayVariable> {
167
+ return this.client.requestJson<ApiDisplayVariable>(
168
+ `/api/v2/displays/${selectorValue(display)}/variables`,
169
+ jsonOptions(body, "POST"),
170
+ );
171
+ }
172
+
173
+ updateVariable(display: NormalizedUuidOrSlug, variableId: string, body: Record<string, unknown>): Promise<ApiDisplayVariable> {
174
+ return this.client.requestJson<ApiDisplayVariable>(
175
+ `/api/v2/displays/${selectorValue(display)}/variables/${segment(variableId)}`,
176
+ jsonOptions(body, "PATCH"),
177
+ );
178
+ }
179
+
180
+ deleteVariable(display: NormalizedUuidOrSlug, variableId: string): Promise<Record<string, unknown>> {
181
+ return this.client.requestJson<Record<string, unknown>>(
182
+ `/api/v2/displays/${selectorValue(display)}/variables/${segment(variableId)}`,
183
+ { method: "DELETE" },
184
+ );
185
+ }
186
+
187
+ listWidgets(display: NormalizedUuidOrSlug): Promise<ApiDisplayWidget[]> {
188
+ return this.client.getJson<ApiDisplayWidget[]>(
189
+ `/api/v2/displays/${selectorValue(display)}/widgets`,
190
+ );
191
+ }
192
+
193
+ getWidget(display: NormalizedUuidOrSlug, widgetId: string): Promise<ApiDisplayWidget> {
194
+ return this.client.getJson<ApiDisplayWidget>(
195
+ `/api/v2/displays/${selectorValue(display)}/widgets/${segment(widgetId)}`,
196
+ );
197
+ }
198
+
199
+ createWidget(
200
+ display: NormalizedUuidOrSlug,
201
+ body: Record<string, unknown>,
202
+ ): Promise<ApiDisplayWidget> {
203
+ return this.client.requestJson<ApiDisplayWidget>(
204
+ `/api/v2/displays/${selectorValue(display)}/widgets`,
205
+ jsonOptions(body, "POST"),
206
+ );
207
+ }
208
+
209
+ updateWidget(display: NormalizedUuidOrSlug, widgetId: string, body: Record<string, unknown>): Promise<ApiDisplayWidget> {
210
+ return this.client.requestJson<ApiDisplayWidget>(
211
+ `/api/v2/displays/${selectorValue(display)}/widgets/${segment(widgetId)}`,
212
+ jsonOptions(body, "PATCH"),
213
+ );
214
+ }
215
+
216
+ deleteWidget(display: NormalizedUuidOrSlug, widgetId: string): Promise<Record<string, unknown>> {
217
+ return this.client.requestJson<Record<string, unknown>>(
218
+ `/api/v2/displays/${selectorValue(display)}/widgets/${segment(widgetId)}`,
219
+ { method: "DELETE" },
220
+ );
221
+ }
222
+
223
+ createNavigationTarget(
224
+ display: NormalizedUuidOrSlug,
225
+ body: Record<string, unknown>,
226
+ ): Promise<ApiDisplayNavigationTarget> {
227
+ return this.client.requestJson<ApiDisplayNavigationTarget>(
228
+ `/api/v2/displays/${selectorValue(display)}/navigation-targets`,
229
+ jsonOptions(body, "POST"),
230
+ );
231
+ }
232
+
233
+ updateNavigationTarget(
234
+ display: NormalizedUuidOrSlug,
235
+ targetId: string,
236
+ body: Record<string, unknown>,
237
+ ): Promise<ApiDisplayNavigationTarget> {
238
+ return this.client.requestJson<ApiDisplayNavigationTarget>(
239
+ `/api/v2/displays/${selectorValue(display)}/navigation-targets/${segment(targetId)}`,
240
+ jsonOptions(body, "PATCH"),
241
+ );
242
+ }
243
+
244
+ deleteNavigationTarget(
245
+ display: NormalizedUuidOrSlug,
246
+ targetId: string,
247
+ ): Promise<Record<string, unknown>> {
248
+ return this.client.requestJson<Record<string, unknown>>(
249
+ `/api/v2/displays/${selectorValue(display)}/navigation-targets/${segment(targetId)}`,
250
+ { method: "DELETE" },
251
+ );
252
+ }
253
+
254
+ getCrossWidgetFilter(display: NormalizedUuidOrSlug): Promise<Record<string, unknown>> {
255
+ return this.client.getJson<Record<string, unknown>>(
256
+ `/api/v2/displays/${selectorValue(display)}/cross-widget-filter`,
257
+ );
258
+ }
259
+
260
+ setCrossWidgetFilter(
261
+ display: NormalizedUuidOrSlug,
262
+ body: Record<string, unknown>,
263
+ ): Promise<Record<string, unknown>> {
264
+ return this.client.requestJson<Record<string, unknown>>(
265
+ `/api/v2/displays/${selectorValue(display)}/cross-widget-filter`,
266
+ jsonOptions(body, "PUT"),
267
+ );
268
+ }
269
+
270
+ deleteCrossWidgetFilter(display: NormalizedUuidOrSlug): Promise<Record<string, unknown>> {
271
+ return this.client.requestJson<Record<string, unknown>>(
272
+ `/api/v2/displays/${selectorValue(display)}/cross-widget-filter`,
273
+ { method: "DELETE" },
274
+ );
275
+ }
276
+ }
@@ -0,0 +1,50 @@
1
+ import { ApiClient } from "../client.js";
2
+ import type { NormalizedUuidOrSlug } from "../parsers/selectors.js";
3
+
4
+ export interface ApiFile {
5
+ [key: string]: unknown;
6
+ id?: string;
7
+ name?: string;
8
+ filename?: string;
9
+ size?: number;
10
+ mimeType?: string;
11
+ }
12
+
13
+ export interface FileStorageInfo {
14
+ [key: string]: unknown;
15
+ usedBytes?: number;
16
+ totalBytes?: number;
17
+ availableBytes?: number;
18
+ used?: number;
19
+ limitBytes?: number;
20
+ }
21
+
22
+ function selectorValue(selector: NormalizedUuidOrSlug): string {
23
+ return selector.value;
24
+ }
25
+
26
+ export class FilesApi {
27
+ constructor(private readonly client: ApiClient) {}
28
+
29
+ uploadFile(input: FormData): Promise<ApiFile> {
30
+ return this.client.requestJson<ApiFile>("/api/v2/files", {
31
+ method: "POST",
32
+ body: input,
33
+ });
34
+ }
35
+
36
+ downloadFile(file: NormalizedUuidOrSlug): Promise<ArrayBuffer> {
37
+ return this.client.requestBinary(`/api/v2/files/${selectorValue(file)}`);
38
+ }
39
+
40
+ deleteFile(file: NormalizedUuidOrSlug): Promise<Record<string, unknown>> {
41
+ return this.client.requestJson<Record<string, unknown>>(
42
+ `/api/v2/files/${selectorValue(file)}`,
43
+ { method: "DELETE" },
44
+ );
45
+ }
46
+
47
+ getStorageInfo(): Promise<FileStorageInfo> {
48
+ return this.client.getJson<FileStorageInfo>("/api/v2/files/storage-info");
49
+ }
50
+ }
@@ -0,0 +1,71 @@
1
+ import { ApiClient } from "../client.js";
2
+ import type { NormalizedUuidOrSlug } from "../parsers/selectors.js";
3
+
4
+ export interface NavigationFolder {
5
+ id: string;
6
+ order?: number;
7
+ name?: string;
8
+ resources?: Array<Record<string, unknown>>;
9
+ additionalProperties?: Record<string, unknown>;
10
+ }
11
+
12
+ export interface NavigationFolderMutation {
13
+ folderId?: string;
14
+ name?: string;
15
+ }
16
+
17
+ export interface NavigationMoveResourceInput {
18
+ resourceId: string;
19
+ resourceType: string;
20
+ targetFolderId: string;
21
+ }
22
+
23
+ function jsonOptions(body: unknown, method: string): RequestInit {
24
+ return {
25
+ method,
26
+ headers: {
27
+ "content-type": "application/json",
28
+ },
29
+ body: JSON.stringify(body),
30
+ };
31
+ }
32
+
33
+ function selectorValue(selector: NormalizedUuidOrSlug): string {
34
+ return selector.value;
35
+ }
36
+
37
+ export class NavigationApi {
38
+ constructor(private readonly client: ApiClient) {}
39
+
40
+ listFolders(): Promise<NavigationFolder[]> {
41
+ return this.client.getJson<NavigationFolder[]>("/api/v2/navigation/folders");
42
+ }
43
+
44
+ createFolder(body: Record<string, unknown>): Promise<NavigationFolderMutation> {
45
+ return this.client.requestJson<NavigationFolderMutation>(
46
+ "/api/v2/navigation/folders",
47
+ jsonOptions(body, "POST"),
48
+ );
49
+ }
50
+
51
+ updateFolder(folder: NormalizedUuidOrSlug, body: Record<string, unknown>): Promise<NavigationFolderMutation> {
52
+ return this.client.requestJson<NavigationFolderMutation>(
53
+ `/api/v2/navigation/folders/${selectorValue(folder)}`,
54
+ jsonOptions(body, "PATCH"),
55
+ );
56
+ }
57
+
58
+ deleteFolder(folder: NormalizedUuidOrSlug): Promise<NavigationFolderMutation> {
59
+ return this.client.requestJson<NavigationFolderMutation>(
60
+ `/api/v2/navigation/folders/${selectorValue(folder)}`,
61
+ { method: "DELETE" },
62
+ );
63
+ }
64
+
65
+ moveResource(body: NavigationMoveResourceInput): Promise<Record<string, unknown>> {
66
+ return this.client.requestJson<Record<string, unknown>>(
67
+ "/api/v2/navigation/resources:move",
68
+ jsonOptions(body, "POST"),
69
+ );
70
+ }
71
+ }
@@ -0,0 +1,167 @@
1
+ import { ApiClient } from "../client.js";
2
+ import type { NormalizedUuidOrSlug } from "../parsers/selectors.js";
3
+
4
+ export interface ApiRecord {
5
+ [key: string]: unknown;
6
+ recordId?: string;
7
+ values?: Record<string, unknown>;
8
+ }
9
+
10
+ export interface RecordQueryExpression {
11
+ field: string;
12
+ comparator: string;
13
+ value: unknown;
14
+ }
15
+
16
+ export interface RecordQuerySort {
17
+ field: string;
18
+ direction: "ASC" | "DESC";
19
+ }
20
+
21
+ export interface RecordQueryResult {
22
+ records: ApiRecord[];
23
+ page?: Record<string, unknown>;
24
+ }
25
+
26
+ export interface RecordQueryInput {
27
+ [key: string]: unknown;
28
+ select?: string[];
29
+ where?: RecordQueryExpression[];
30
+ sort?: string[];
31
+ limit?: number;
32
+ offset?: number;
33
+ }
34
+
35
+ export interface CreateRecordInput {
36
+ [key: string]: unknown;
37
+ }
38
+
39
+ export interface UpdateRecordInput {
40
+ [key: string]: unknown;
41
+ set?: Record<string, unknown>;
42
+ unset?: string[];
43
+ }
44
+
45
+ function jsonOptions(body: unknown, method: string): RequestInit {
46
+ return {
47
+ method,
48
+ headers: {
49
+ "content-type": "application/json",
50
+ },
51
+ body: JSON.stringify(body),
52
+ };
53
+ }
54
+
55
+ function selectorValue(selector: NormalizedUuidOrSlug): string {
56
+ return selector.value;
57
+ }
58
+
59
+ export class RecordsApi {
60
+ constructor(private readonly client: ApiClient) {}
61
+
62
+ listRecords(
63
+ schema: NormalizedUuidOrSlug,
64
+ query: RecordQueryInput,
65
+ ): Promise<RecordQueryResult> {
66
+ const params = new URLSearchParams();
67
+
68
+ if (query.limit !== undefined) {
69
+ params.set("limit", String(query.limit));
70
+ }
71
+
72
+ if (query.offset !== undefined) {
73
+ params.set("offset", String(query.offset));
74
+ }
75
+
76
+ const path = `/api/v2/schemas/${selectorValue(schema)}/records`;
77
+ const queryString = params.toString();
78
+
79
+ return this.client.getJson<RecordQueryResult>(
80
+ queryString ? `${path}?${queryString}` : path,
81
+ );
82
+ }
83
+
84
+ queryRecords(
85
+ schema: NormalizedUuidOrSlug,
86
+ query: RecordQueryInput,
87
+ ): Promise<RecordQueryResult> {
88
+ const body = this.normalizeQueryInput(query);
89
+
90
+ return this.client.requestJson<RecordQueryResult>(
91
+ `/api/v2/schemas/${selectorValue(schema)}/records:query`,
92
+ jsonOptions(body, "POST"),
93
+ );
94
+ }
95
+
96
+ getRecord(
97
+ schema: NormalizedUuidOrSlug,
98
+ record: NormalizedUuidOrSlug,
99
+ ): Promise<ApiRecord> {
100
+ return this.client.getJson<ApiRecord>(
101
+ `/api/v2/schemas/${selectorValue(schema)}/records/${selectorValue(record)}`,
102
+ );
103
+ }
104
+
105
+ createRecord(
106
+ schema: NormalizedUuidOrSlug,
107
+ input: CreateRecordInput,
108
+ ): Promise<ApiRecord> {
109
+ return this.client.requestJson<ApiRecord>(
110
+ `/api/v2/schemas/${selectorValue(schema)}/records`,
111
+ jsonOptions(input, "POST"),
112
+ );
113
+ }
114
+
115
+ updateRecord(
116
+ schema: NormalizedUuidOrSlug,
117
+ record: NormalizedUuidOrSlug,
118
+ input: UpdateRecordInput,
119
+ ): Promise<ApiRecord> {
120
+ return this.client.requestJson<ApiRecord>(
121
+ `/api/v2/schemas/${selectorValue(schema)}/records/${selectorValue(record)}`,
122
+ jsonOptions(input, "PATCH"),
123
+ );
124
+ }
125
+
126
+ deleteRecord(
127
+ schema: NormalizedUuidOrSlug,
128
+ record: NormalizedUuidOrSlug,
129
+ ): Promise<Record<string, unknown>> {
130
+ return this.client.requestJson<Record<string, unknown>>(
131
+ `/api/v2/schemas/${selectorValue(schema)}/records/${selectorValue(record)}`,
132
+ { method: "DELETE" },
133
+ );
134
+ }
135
+
136
+ private normalizeQueryInput(query: RecordQueryInput): Record<string, unknown> {
137
+ const where = query.where?.map((expression) => ({
138
+ field: expression.field,
139
+ op: expression.comparator,
140
+ value: expression.value,
141
+ }));
142
+
143
+ const sort = query.sort?.map((entry) => {
144
+ const [field, direction = "asc"] = entry.split(":");
145
+ return {
146
+ field,
147
+ direction: direction.toUpperCase(),
148
+ };
149
+ });
150
+
151
+ return {
152
+ ...query,
153
+ select: query.select,
154
+ where,
155
+ sort,
156
+ page:
157
+ query.limit !== undefined || query.offset !== undefined
158
+ ? {
159
+ offset: query.offset,
160
+ limit: query.limit,
161
+ }
162
+ : undefined,
163
+ limit: undefined,
164
+ offset: undefined,
165
+ };
166
+ }
167
+ }
@@ -0,0 +1,130 @@
1
+ import { ApiClient } from "../client.js";
2
+ import type { NormalizedUuidOrSlug } from "../parsers/selectors.js";
3
+
4
+ export interface ApiSchemaField {
5
+ [key: string]: unknown;
6
+ id?: string;
7
+ type?: string;
8
+ slug?: string;
9
+ label?: string;
10
+ required?: boolean;
11
+ }
12
+
13
+ export interface ApiSchema {
14
+ [key: string]: unknown;
15
+ id?: string;
16
+ name?: string;
17
+ slug?: string;
18
+ auditable?: boolean;
19
+ commentable?: boolean;
20
+ fields?: ApiSchemaField[];
21
+ }
22
+
23
+ export interface CreateSchemaInput {
24
+ name: string;
25
+ slug: string;
26
+ auditable?: boolean;
27
+ commentable?: boolean;
28
+ }
29
+
30
+ export interface UpdateSchemaInput {
31
+ name?: string;
32
+ slug?: string;
33
+ auditable?: boolean;
34
+ commentable?: boolean;
35
+ }
36
+
37
+ export interface CreateSchemaFieldInput {
38
+ [key: string]: unknown;
39
+ type: string;
40
+ slug: string;
41
+ label: string;
42
+ required?: boolean;
43
+ }
44
+
45
+ export interface UpdateSchemaFieldInput {
46
+ [key: string]: unknown;
47
+ label?: string;
48
+ required?: boolean;
49
+ }
50
+
51
+ function jsonOptions(body: unknown, method: string): RequestInit {
52
+ return {
53
+ method,
54
+ headers: {
55
+ "content-type": "application/json",
56
+ },
57
+ body: JSON.stringify(body),
58
+ };
59
+ }
60
+
61
+ function selectorValue(selector: NormalizedUuidOrSlug): string {
62
+ return selector.value;
63
+ }
64
+
65
+ export class SchemasApi {
66
+ constructor(private readonly client: ApiClient) {}
67
+
68
+ listSchemas(): Promise<ApiSchema[]> {
69
+ return this.client.getJson<ApiSchema[]>("/api/v2/schemas");
70
+ }
71
+
72
+ getSchema(schema: NormalizedUuidOrSlug): Promise<ApiSchema> {
73
+ return this.client.getJson<ApiSchema>(`/api/v2/schemas/${selectorValue(schema)}`);
74
+ }
75
+
76
+ createSchema(input: CreateSchemaInput): Promise<ApiSchema> {
77
+ return this.client.requestJson<ApiSchema>("/api/v2/schemas", jsonOptions(input, "POST"));
78
+ }
79
+
80
+ updateSchema(schema: NormalizedUuidOrSlug, input: UpdateSchemaInput): Promise<ApiSchema> {
81
+ return this.client.requestJson<ApiSchema>(
82
+ `/api/v2/schemas/${selectorValue(schema)}`,
83
+ jsonOptions(input, "PATCH"),
84
+ );
85
+ }
86
+
87
+ deleteSchema(schema: NormalizedUuidOrSlug): Promise<Record<string, unknown>> {
88
+ return this.client.requestJson<Record<string, unknown>>(
89
+ `/api/v2/schemas/${selectorValue(schema)}`,
90
+ { method: "DELETE" },
91
+ );
92
+ }
93
+
94
+ async listFields(schema: NormalizedUuidOrSlug): Promise<ApiSchemaField[]> {
95
+ const result = await this.getSchema(schema);
96
+
97
+ return Array.isArray(result.fields) ? result.fields : [];
98
+ }
99
+
100
+ getField(schema: NormalizedUuidOrSlug, field: NormalizedUuidOrSlug): Promise<ApiSchemaField> {
101
+ return this.client.getJson<ApiSchemaField>(
102
+ `/api/v2/schemas/${selectorValue(schema)}/fields/${selectorValue(field)}`,
103
+ );
104
+ }
105
+
106
+ createField(schema: NormalizedUuidOrSlug, input: CreateSchemaFieldInput): Promise<ApiSchemaField> {
107
+ return this.client.requestJson<ApiSchemaField>(
108
+ `/api/v2/schemas/${selectorValue(schema)}/fields`,
109
+ jsonOptions(input, "POST"),
110
+ );
111
+ }
112
+
113
+ updateField(
114
+ schema: NormalizedUuidOrSlug,
115
+ field: NormalizedUuidOrSlug,
116
+ input: UpdateSchemaFieldInput,
117
+ ): Promise<ApiSchemaField> {
118
+ return this.client.requestJson<ApiSchemaField>(
119
+ `/api/v2/schemas/${selectorValue(schema)}/fields/${selectorValue(field)}`,
120
+ jsonOptions(input, "PATCH"),
121
+ );
122
+ }
123
+
124
+ deleteField(schema: NormalizedUuidOrSlug, field: NormalizedUuidOrSlug): Promise<Record<string, unknown>> {
125
+ return this.client.requestJson<Record<string, unknown>>(
126
+ `/api/v2/schemas/${selectorValue(schema)}/fields/${selectorValue(field)}`,
127
+ { method: "DELETE" },
128
+ );
129
+ }
130
+ }