@supernova-studio/client 0.58.0 → 0.58.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supernova-studio/client",
3
- "version": "0.58.0",
3
+ "version": "0.58.1",
4
4
  "description": "Supernova Data Models",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",
@@ -0,0 +1,7 @@
1
+ import { z } from "zod";
2
+
3
+ export const DTOColorTokenInlineData = z.object({
4
+ value: z.string().regex(/^#[a-f0-9]{6,8}$/),
5
+ });
6
+
7
+ export type DTOColorTokenInlineData = z.infer<typeof DTOColorTokenInlineData>;
@@ -1 +1,3 @@
1
+ export * from "./color";
2
+ export * from "./meta";
1
3
  export * from "./pagination";
@@ -0,0 +1,8 @@
1
+ import { z } from "zod";
2
+
3
+ export const DTOObjectMeta = z.object({
4
+ name: z.string().max(512),
5
+ description: z.string().max(2048).optional(),
6
+ });
7
+
8
+ export type DTOObjectMeta = z.infer<typeof DTOObjectMeta>;
@@ -34,14 +34,6 @@ import {
34
34
  DTODocumentationPageUpdateActionOutputV2,
35
35
  } from "./documentation/page-actions-v2";
36
36
  import { DTOFigmaNodeRenderActionInput, DTOFigmaNodeRenderActionOutput } from "./figma-nodes/node-actions-v2";
37
- import {
38
- DTOPropertyDefinitionCreateActionInputV2,
39
- DTOPropertyDefinitionCreateActionOutputV2,
40
- DTOPropertyDefinitionDeleteActionInputV2,
41
- DTOPropertyDefinitionDeleteActionOutputV2,
42
- DTOPropertyDefinitionUpdateActionInputV2,
43
- DTOPropertyDefinitionUpdateActionOutputV2,
44
- } from "./properties/property-definitions-actions-v2";
45
37
 
46
38
  //
47
39
  // Read
@@ -67,11 +59,6 @@ export const DTOElementActionOutput = z.discriminatedUnion("type", [
67
59
  // Figma frames
68
60
  DTOFigmaNodeRenderActionOutput,
69
61
 
70
- // Properties Definitions
71
- DTOPropertyDefinitionCreateActionOutputV2,
72
- DTOPropertyDefinitionUpdateActionOutputV2,
73
- DTOPropertyDefinitionDeleteActionOutputV2,
74
-
75
62
  // Restore
76
63
  DTODocumentationPageRestoreActionOutput,
77
64
  DTODocumentationGroupRestoreActionOutput,
@@ -106,11 +93,6 @@ export const DTOElementActionInput = z.discriminatedUnion("type", [
106
93
  // Figma frames
107
94
  DTOFigmaNodeRenderActionInput,
108
95
 
109
- // Properties Definitions
110
- DTOPropertyDefinitionCreateActionInputV2,
111
- DTOPropertyDefinitionUpdateActionInputV2,
112
- DTOPropertyDefinitionDeleteActionInputV2,
113
-
114
96
  // Restore
115
97
  DTODocumentationPageRestoreActionInput,
116
98
  DTODocumentationGroupRestoreActionInput,
@@ -1,3 +1,2 @@
1
- export * from "./property-definitions-actions-v2";
2
1
  export * from "./property-definitions";
3
2
  export * from "./property-values";
@@ -1,28 +1,35 @@
1
1
  import {
2
- ElementPropertyDefinitionOption,
3
2
  ElementPropertyLinkType,
4
3
  ElementPropertyTargetType,
5
4
  ElementPropertyTypeSchema,
6
5
  nullishToOptional,
7
- ObjectMeta,
8
6
  } from "@supernova-studio/model";
9
7
  import { z } from "zod";
8
+ import { DTOColorTokenInlineData } from "../../aux";
9
+ import { DTOObjectMeta } from "../../aux/meta";
10
10
 
11
11
  const CODE_NAME_REGEX = /^[a-zA-Z_$][a-zA-Z_$0-9]{1,99}$/;
12
12
 
13
+ export const DTOElementPropertyDefinitionOption = z.object({
14
+ id: z.string(),
15
+ name: z.string(),
16
+ backgroundColor: DTOColorTokenInlineData.optional(),
17
+ });
18
+
13
19
  // DTO Object
14
20
  export const DTOElementPropertyDefinition = z.object({
15
21
  id: z.string(),
16
22
  designSystemVersionId: z.string(),
17
- meta: ObjectMeta,
23
+ meta: DTOObjectMeta,
18
24
  persistentId: z.string(),
19
25
  type: ElementPropertyTypeSchema,
20
26
  targetElementType: ElementPropertyTargetType,
21
27
  codeName: z.string().regex(CODE_NAME_REGEX),
22
- options: nullishToOptional(z.array(ElementPropertyDefinitionOption)),
28
+ options: nullishToOptional(z.array(DTOElementPropertyDefinitionOption)),
23
29
  linkElementType: nullishToOptional(ElementPropertyLinkType),
24
30
  });
25
31
 
32
+ export type DTOElementPropertyDefinitionOption = z.infer<typeof DTOElementPropertyDefinitionOption>;
26
33
  export type DTOElementPropertyDefinition = z.infer<typeof DTOElementPropertyDefinition>;
27
34
 
28
35
  //
@@ -44,23 +51,22 @@ export type DTOElementPropertyDefinitionResponse = z.infer<typeof DTOElementProp
44
51
  // Write
45
52
  //
46
53
 
47
- export const DTOElementPropertyDefinitionCreatePayload = DTOElementPropertyDefinition.omit({
48
- id: true,
49
- designSystemVersionId: true,
54
+ export const DTOElementPropertyDefinitionCreatePayload = z.object({
55
+ meta: DTOObjectMeta,
56
+ persistentId: z.string(),
57
+ type: ElementPropertyTypeSchema,
58
+ targetElementType: ElementPropertyTargetType,
59
+ codeName: z.string().regex(CODE_NAME_REGEX),
60
+ options: nullishToOptional(z.array(DTOElementPropertyDefinitionOption)),
61
+ linkElementType: nullishToOptional(ElementPropertyLinkType),
62
+ columnWidth: z.number().max(1024).optional(),
50
63
  });
51
64
 
52
65
  export const DTOElementPropertyDefinitionUpdatePayload = z.object({
53
- id: z.string(),
54
- name: z.string().optional(),
55
- description: z.string().optional(),
66
+ meta: DTOObjectMeta.optional(),
56
67
  codeName: z.string().regex(CODE_NAME_REGEX).optional(),
57
- options: z.array(ElementPropertyDefinitionOption).optional(),
58
- });
59
-
60
- export const DTOElementPropertyDefinitionDeletePayload = z.object({
61
- id: z.string(),
68
+ options: z.array(DTOElementPropertyDefinitionOption).optional(),
62
69
  });
63
70
 
64
71
  export type DTOElementPropertyDefinitionCreatePayload = z.infer<typeof DTOElementPropertyDefinitionCreatePayload>;
65
72
  export type DTOElementPropertyDefinitionUpdatePayload = z.infer<typeof DTOElementPropertyDefinitionUpdatePayload>;
66
- export type DTOElementPropertyDefinitionDeletePayload = z.infer<typeof DTOElementPropertyDefinitionDeletePayload>;
@@ -1,7 +1,9 @@
1
+ import { z } from "zod";
1
2
  import {
2
3
  DTOElementPropertyDefinitionCreatePayload,
3
4
  DTOElementPropertyDefinitionListResponse,
4
5
  DTOElementPropertyDefinitionResponse,
6
+ DTOElementPropertyDefinitionUpdatePayload,
5
7
  } from "../../../dto";
6
8
  import { RequestExecutor } from "../../../transport/request-executor";
7
9
 
@@ -22,4 +24,20 @@ export class ElementPropertyDefinitionsEndpoint {
22
24
  { method: "POST", body }
23
25
  );
24
26
  }
27
+
28
+ update(designSystemId: string, versionId: string, defId: string, body: DTOElementPropertyDefinitionUpdatePayload) {
29
+ return this.requestExecutor.json(
30
+ `/design-systems/${designSystemId}/versions/${versionId}/element-properties/definitions/${defId}`,
31
+ DTOElementPropertyDefinitionResponse,
32
+ { method: "PUT", body }
33
+ );
34
+ }
35
+
36
+ delete(designSystemId: string, versionId: string, defId: string) {
37
+ return this.requestExecutor.json(
38
+ `/design-systems/${designSystemId}/versions/${versionId}/element-properties/definitions/${defId}`,
39
+ z.any(),
40
+ { method: "DELETE" }
41
+ );
42
+ }
25
43
  }
@@ -58,8 +58,11 @@ export class RequestExecutor {
58
58
  throw RequestExecutorError.serverError(endpoint, response.status, bodyString);
59
59
  }
60
60
 
61
- const wrapperParseResult = ResponseWrapper.safeParse(await response.json());
61
+ const json = await response.json();
62
+ const wrapperParseResult = ResponseWrapper.safeParse(json);
62
63
  if (!wrapperParseResult.success) {
64
+ console.error(`Response was:`);
65
+ console.error(json);
63
66
  throw RequestExecutorError.responseParsingError(endpoint, wrapperParseResult.error);
64
67
  }
65
68
 
@@ -1,53 +0,0 @@
1
- import { z } from "zod";
2
- import {
3
- DTOElementPropertyDefinition,
4
- DTOElementPropertyDefinitionCreatePayload,
5
- DTOElementPropertyDefinitionDeletePayload,
6
- DTOElementPropertyDefinitionUpdatePayload,
7
- } from "./property-definitions";
8
-
9
- // Outputs
10
-
11
- const SuccessPayload = z.object({
12
- success: z.literal(true),
13
- });
14
-
15
- export const DTOPropertyDefinitionCreateActionOutputV2 = z.object({
16
- type: z.literal("PropertyDefinitionCreate"),
17
- definition: DTOElementPropertyDefinition,
18
- });
19
-
20
- export const DTOPropertyDefinitionUpdateActionOutputV2 = z.object({
21
- type: z.literal("PropertyDefinitionUpdate"),
22
- definition: DTOElementPropertyDefinition,
23
- });
24
-
25
- export const DTOPropertyDefinitionDeleteActionOutputV2 = z.object({
26
- type: z.literal("PropertyDefinitionDelete"),
27
- output: SuccessPayload,
28
- });
29
-
30
- export type DTOPropertyDefinitionCreateActionOutputV2 = z.infer<typeof DTOPropertyDefinitionCreateActionOutputV2>;
31
- export type DTOPropertyDefinitionUpdateActionOutputV2 = z.infer<typeof DTOPropertyDefinitionUpdateActionOutputV2>;
32
- export type DTOPropertyDefinitionDeleteActionOutputV2 = z.infer<typeof DTOPropertyDefinitionDeleteActionOutputV2>;
33
-
34
- // Inputs
35
-
36
- export const DTOPropertyDefinitionCreateActionInputV2 = z.object({
37
- type: z.literal("PropertyDefinitionCreate"),
38
- input: DTOElementPropertyDefinitionCreatePayload,
39
- });
40
-
41
- export const DTOPropertyDefinitionUpdateActionInputV2 = z.object({
42
- type: z.literal("PropertyDefinitionUpdate"),
43
- input: DTOElementPropertyDefinitionUpdatePayload,
44
- });
45
-
46
- export const DTOPropertyDefinitionDeleteActionInputV2 = z.object({
47
- type: z.literal("PropertyDefinitionDelete"),
48
- input: DTOElementPropertyDefinitionDeletePayload,
49
- });
50
-
51
- export type DTOPropertyDefinitionCreateActionInputV2 = z.infer<typeof DTOPropertyDefinitionCreateActionInputV2>;
52
- export type DTOPropertyDefinitionUpdateActionInputV2 = z.infer<typeof DTOPropertyDefinitionUpdateActionInputV2>;
53
- export type DTOPropertyDefinitionDeleteActionInputV2 = z.infer<typeof DTOPropertyDefinitionDeleteActionInputV2>;