@supernova-studio/client 0.54.32 → 0.54.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supernova-studio/client",
3
- "version": "0.54.32",
3
+ "version": "0.54.34",
4
4
  "description": "Supernova Data Models",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",
@@ -1,3 +1,4 @@
1
+ import { DesignSystemMembershipUpdates, UserInvite } from "@supernova-studio/model";
1
2
  import { z } from "zod";
2
3
 
3
4
  //
@@ -8,8 +9,14 @@ export const DTODesignSystemMember = z.object({
8
9
  userId: z.string(),
9
10
  });
10
11
 
12
+ export const DTODesignSystemInvitation = z.object({
13
+ id: z.string(),
14
+ workspaceInvitationId: z.string(),
15
+ });
16
+
11
17
  export const DTODesignSystemMemberListResponse = z.object({
12
18
  members: DTODesignSystemMember.array(),
19
+ invitations: DTODesignSystemInvitation.array(),
13
20
  });
14
21
 
15
22
  export const DTODesignSystemMembersUpdateResponse = z.object({
@@ -17,6 +24,7 @@ export const DTODesignSystemMembersUpdateResponse = z.object({
17
24
  });
18
25
 
19
26
  export type DTODesignSystemMember = z.infer<typeof DTODesignSystemMember>;
27
+ export type DTODesignSystemInvitation = z.infer<typeof DTODesignSystemInvitation>;
20
28
  export type DTODesignSystemMemberListResponse = z.infer<typeof DTODesignSystemMemberListResponse>;
21
29
  export type DTODesignSystemMembersUpdateResponse = z.infer<typeof DTODesignSystemMembersUpdateResponse>;
22
30
 
@@ -24,9 +32,6 @@ export type DTODesignSystemMembersUpdateResponse = z.infer<typeof DTODesignSyste
24
32
  // Write
25
33
  //
26
34
 
27
- export const DTODesignSystemMembersUpdatePayload = z.object({
28
- inviteUserIds: z.string().array().optional(),
29
- removeUserIds: z.string().array().optional(),
30
- });
35
+ export const DTODesignSystemMembersUpdatePayload = DesignSystemMembershipUpdates;
31
36
 
32
37
  export type DTODesignSystemMembersUpdatePayload = z.infer<typeof DTODesignSystemMembersUpdatePayload>;
@@ -1,4 +1,4 @@
1
- import { WorkspaceRoleSchema } from "@supernova-studio/model";
1
+ import { WorkspaceInvitation, WorkspaceRoleSchema } from "@supernova-studio/model";
2
2
  import { z } from "zod";
3
3
 
4
4
  export const DTOWorkspaceInvitationInput = z.object({
@@ -11,5 +11,10 @@ export const DTOWorkspaceInvitationsListInput = z.object({
11
11
  designSystemId: z.string().optional(),
12
12
  });
13
13
 
14
+ export const DTOWorkspaceInvitationsResponse = z.object({
15
+ invitations: WorkspaceInvitation.array(),
16
+ });
17
+
14
18
  export type DTOWorkspaceInvitationInput = z.infer<typeof DTOWorkspaceInvitationInput>;
15
19
  export type DTOWorkspaceInvitationsListInput = z.infer<typeof DTOWorkspaceInvitationsListInput>;
20
+ export type DTOWorkspaceInvitationsResponse = z.infer<typeof DTOWorkspaceInvitationsResponse>;
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { DTODesignSystemCreateInput, DTODesignSystemResponse, DTODesignSystemsListResponse } from "../dto";
3
- import { DTODesignSystemUpdateInput } from "../payloads";
3
+ import { DTODesignSystemUpdateAccessModeInput, DTODesignSystemUpdateInput } from "../payloads";
4
4
  import { RequestExecutor } from "../transport/request-executor";
5
5
  import { DesignSystemMembersEndpoint } from "./design-system-members";
6
6
 
@@ -32,4 +32,11 @@ export class DesignSystemsEndpoint {
32
32
  body,
33
33
  });
34
34
  }
35
+
36
+ updateAccessMode(dsId: string, body: DTODesignSystemUpdateAccessModeInput) {
37
+ return this.requestExecutor.json(`/design-systems/${dsId}/access-mode`, DTODesignSystemResponse, {
38
+ method: "PUT",
39
+ body,
40
+ });
41
+ }
35
42
  }
@@ -1,5 +1,6 @@
1
1
  export * from "./design-system-members";
2
2
  export * from "./design-systems";
3
3
  export * from "./users";
4
+ export * from "./workspace-invites";
4
5
  export * from "./workspace-members";
5
6
  export * from "./workspaces";
@@ -0,0 +1,12 @@
1
+ import { DTOWorkspaceInvitationsResponse } from "../dto";
2
+ import { RequestExecutor } from "../transport";
3
+
4
+ export class WorkspaceInvitationsEndpoint {
5
+ constructor(private readonly requestExecutor: RequestExecutor) {}
6
+
7
+ list(workspaceId: string) {
8
+ return this.requestExecutor.json(`/workspaces/${workspaceId}/invitations`, DTOWorkspaceInvitationsResponse, {
9
+ method: "GET",
10
+ });
11
+ }
12
+ }
@@ -2,13 +2,16 @@ import { z } from "zod";
2
2
  import { DTOWorkspaceCreateInput, DTOWorkspaceResponse } from "../dto";
3
3
  import { RequestExecutor } from "../transport/request-executor";
4
4
  import { WorkspaceMembersEndpoint } from "./workspace-members";
5
+ import { WorkspaceInvitationsEndpoint } from "./workspace-invites";
5
6
 
6
7
  // TODO Response types
7
8
  export class WorkspacesEndpoint {
8
9
  public members: WorkspaceMembersEndpoint;
10
+ public invitations: WorkspaceInvitationsEndpoint;
9
11
 
10
12
  constructor(private readonly requestExecutor: RequestExecutor) {
11
13
  this.members = new WorkspaceMembersEndpoint(requestExecutor);
14
+ this.invitations = new WorkspaceInvitationsEndpoint(requestExecutor);
12
15
  }
13
16
 
14
17
  create(body: DTOWorkspaceCreateInput) {
@@ -1,4 +1,4 @@
1
- import { DesignSystem, ObjectMeta } from "@supernova-studio/model";
1
+ import { DesignSystem, DesignSystemAccessMode, ObjectMeta } from "@supernova-studio/model";
2
2
  import { z } from "zod";
3
3
 
4
4
  export const DTODesignSystemUpdateInput = DesignSystem.partial()
@@ -9,9 +9,21 @@ export const DTODesignSystemUpdateInput = DesignSystem.partial()
9
9
  updatedAt: true,
10
10
  docSlug: true,
11
11
  docViewUrl: true,
12
+ accessMode: true,
12
13
  })
13
14
  .extend({
14
15
  meta: ObjectMeta.partial().optional(),
15
16
  });
16
17
 
18
+ export const DTODesignSystemUpdateAccessModeInput = z.object({
19
+ accessMode: DesignSystemAccessMode,
20
+ retain: z
21
+ .object({
22
+ userIds: z.string().array(),
23
+ inviteIds: z.string().array(),
24
+ })
25
+ .optional(),
26
+ });
27
+
17
28
  export type DTODesignSystemUpdateInput = z.infer<typeof DTODesignSystemUpdateInput>;
29
+ export type DTODesignSystemUpdateAccessModeInput = z.infer<typeof DTODesignSystemUpdateAccessModeInput>;
@@ -1,18 +1,49 @@
1
+ import { SupernovaExceptionType } from "@supernova-studio/model";
2
+
1
3
  export type RequestExecutorErrorType = "ServerError" | "ResponseParsingError";
4
+ export type RequestEexecutorServerErrorCode = SupernovaExceptionType | undefined;
2
5
 
3
6
  export class RequestExecutorError extends Error {
7
+ readonly type: RequestExecutorErrorType;
8
+ readonly errorCode: RequestEexecutorServerErrorCode;
9
+
10
+ static tryParseErrorCode(body: string) {
11
+ try {
12
+ const errorObj = JSON.parse(body);
13
+ if (errorObj && typeof errorObj.errorCode === "string") {
14
+ return errorObj.errorCode;
15
+ }
16
+ return null;
17
+ } catch (e) {
18
+ return null;
19
+ }
20
+ }
21
+
4
22
  static serverError(endpoint: string, status: number, bodyText: string) {
5
- return new RequestExecutorError("ServerError", `Endpoint ${endpoint} returned ${status}\n${bodyText}`);
23
+ return new RequestExecutorError(
24
+ "ServerError",
25
+ `Endpoint ${endpoint} returned ${status}\n${bodyText}`,
26
+ this.tryParseErrorCode(bodyText)
27
+ );
6
28
  }
7
29
 
8
30
  static responseParsingError(endpoint: string, cause: Error) {
9
- return new RequestExecutorError("ResponseParsingError", `Endpoint ${endpoint} returned incompatible JSON`, cause);
31
+ return new RequestExecutorError(
32
+ "ResponseParsingError",
33
+ `Endpoint ${endpoint} returned incompatible JSON`,
34
+ undefined,
35
+ cause
36
+ );
10
37
  }
11
38
 
12
- readonly type: RequestExecutorErrorType;
13
-
14
- private constructor(type: RequestExecutorErrorType, message: string, cause?: unknown) {
39
+ private constructor(
40
+ type: RequestExecutorErrorType,
41
+ message: string,
42
+ errorCode: RequestEexecutorServerErrorCode | undefined,
43
+ cause?: unknown
44
+ ) {
15
45
  super(`${type}: ${message}`, { cause });
16
46
  this.type = type;
47
+ this.errorCode = errorCode;
17
48
  }
18
49
  }