@supernova-studio/client 0.48.37 → 0.49.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.48.37",
3
+ "version": "0.49.1",
4
4
  "description": "Supernova Data Models",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/index.js",
@@ -0,0 +1,5 @@
1
+ import { DocumentationPageApproval } from "@supernova-studio/model";
2
+
3
+ export const DTODocumentationPageApprovalState = DocumentationPageApproval;
4
+
5
+ export type DTODocumentationPageApprovalState = DocumentationPageApproval;
@@ -1,4 +1,5 @@
1
1
  export * from "./anchor";
2
+ export * from "./approvals";
2
3
  export * from "./block-definition";
3
4
  export * from "./block";
4
5
  export * from "./documentation-page-snapshot";
@@ -2,7 +2,7 @@ import { z } from "zod";
2
2
  import {
3
3
  DTOCreateDocumentationPageInputV2,
4
4
  DTODeleteDocumentationPageInputV2,
5
- DTODocumentationPageV2,
5
+ DTODocumentationPageApprovalStateChangeInput,
6
6
  DTODuplicateDocumentationPageInputV2,
7
7
  DTOMoveDocumentationPageInputV2,
8
8
  DTORestoreDocumentationGroupInput,
@@ -53,6 +53,11 @@ export const DTODocumentationGroupRestoreActionOutput = z.object({
53
53
  output: SuccessPayload,
54
54
  });
55
55
 
56
+ export const DTODocumentationPageApprovalStateChangeActionOutput = z.object({
57
+ type: z.literal("DocumentationPageApprovalStateChange"),
58
+ output: SuccessPayload,
59
+ });
60
+
56
61
  export type DTODocumentationPageCreateActionOutputV2 = z.infer<typeof DTODocumentationPageCreateActionOutputV2>;
57
62
  export type DTODocumentationPageUpdateActionOutputV2 = z.infer<typeof DTODocumentationPageUpdateActionOutputV2>;
58
63
  export type DTODocumentationPageMoveActionOutputV2 = z.infer<typeof DTODocumentationPageMoveActionOutputV2>;
@@ -60,6 +65,9 @@ export type DTODocumentationPageDuplicateActionOutputV2 = z.infer<typeof DTODocu
60
65
  export type DTODocumentationPageDeleteActionOutputV2 = z.infer<typeof DTODocumentationPageDeleteActionOutputV2>;
61
66
  export type DTODocumentationPageRestoreActionOutput = z.infer<typeof DTODocumentationPageRestoreActionOutput>;
62
67
  export type DTODocumentationGroupRestoreActionOutput = z.infer<typeof DTODocumentationGroupRestoreActionOutput>;
68
+ export type DTODocumentationPageApprovalStateChangeActionOutput = z.infer<
69
+ typeof DTODocumentationPageApprovalStateChangeActionOutput
70
+ >;
63
71
 
64
72
  // Write
65
73
  //
@@ -99,6 +107,11 @@ export const DTODocumentationGroupRestoreActionInput = z.object({
99
107
  input: DTORestoreDocumentationGroupInput,
100
108
  });
101
109
 
110
+ export const DTODocumentationPageApprovalStateChangeActionInput = z.object({
111
+ type: z.literal("DocumentationPageApprovalStateChange"),
112
+ input: DTODocumentationPageApprovalStateChangeInput,
113
+ });
114
+
102
115
  export type DTODocumentationPageCreateActionInputV2 = z.infer<typeof DTODocumentationPageCreateActionInputV2>;
103
116
  export type DTODocumentationPageUpdateActionInputV2 = z.infer<typeof DTODocumentationPageUpdateActionInputV2>;
104
117
  export type DTODocumentationPageMoveActionInputV2 = z.infer<typeof DTODocumentationPageMoveActionInputV2>;
@@ -1,4 +1,6 @@
1
+ import { DocumentationPageApprovalState } from "@supernova-studio/model";
1
2
  import { z } from "zod";
3
+ import { DTODocumentationPageApprovalState } from "../../documentation";
2
4
  import { DTODocumentationDraftState } from "./draft-state";
3
5
  import { DTODocumentationItemConfigurationV2 } from "./item-configuration-v2";
4
6
  import { DTODocumentationPublishMetadata } from "./metadata";
@@ -32,6 +34,9 @@ export const DTODocumentationPageV2 = z.object({
32
34
  /** Defined if a page was published at least once and contains metadata about last publish */
33
35
  publishMetadata: DTODocumentationPublishMetadata.optional(),
34
36
 
37
+ /** Defines the approval state of the documentation page */
38
+ approvalState: DTODocumentationPageApprovalState.optional(),
39
+
35
40
  // Backward compatibility
36
41
  type: z.literal("Page"),
37
42
  });
@@ -100,6 +105,11 @@ export const DTORestoreDocumentationGroupInput = z.object({
100
105
  snapshotId: z.string().optional(),
101
106
  });
102
107
 
108
+ export const DTODocumentationPageApprovalStateChangeInput = z.object({
109
+ persistentId: z.string(),
110
+ approvalState: DocumentationPageApprovalState.optional(),
111
+ });
112
+
103
113
  export type DTOCreateDocumentationPageInputV2 = z.infer<typeof DTOCreateDocumentationPageInputV2>;
104
114
  export type DTOUpdateDocumentationPageInputV2 = z.infer<typeof DTOUpdateDocumentationPageInputV2>;
105
115
  export type DTOMoveDocumentationPageInputV2 = z.infer<typeof DTOMoveDocumentationPageInputV2>;
@@ -107,3 +117,4 @@ export type DTODuplicateDocumentationPageInputV2 = z.infer<typeof DTODuplicateDo
107
117
  export type DTODeleteDocumentationPageInputV2 = z.infer<typeof DTODeleteDocumentationPageInputV2>;
108
118
  export type DTORestoreDocumentationPageInput = z.infer<typeof DTORestoreDocumentationPageInput>;
109
119
  export type DTORestoreDocumentationGroupInput = z.infer<typeof DTORestoreDocumentationGroupInput>;
120
+ export type DTODocumentationPageApprovalStateChangeInput = z.infer<typeof DTODocumentationPageApprovalStateChangeInput>;
@@ -18,6 +18,8 @@ import {
18
18
  import {
19
19
  DTODocumentationGroupRestoreActionInput,
20
20
  DTODocumentationGroupRestoreActionOutput,
21
+ DTODocumentationPageApprovalStateChangeActionInput,
22
+ DTODocumentationPageApprovalStateChangeActionOutput,
21
23
  DTODocumentationPageCreateActionInputV2,
22
24
  DTODocumentationPageCreateActionOutputV2,
23
25
  DTODocumentationPageDeleteActionInputV2,
@@ -73,6 +75,9 @@ export const DTOElementActionOutput = z.discriminatedUnion("type", [
73
75
  // Restore
74
76
  DTODocumentationPageRestoreActionOutput,
75
77
  DTODocumentationGroupRestoreActionOutput,
78
+
79
+ // Approvals
80
+ DTODocumentationPageApprovalStateChangeActionOutput,
76
81
  ]);
77
82
 
78
83
  export type DTOElementActionOutput = z.infer<typeof DTOElementActionOutput>;
@@ -109,6 +114,9 @@ export const DTOElementActionInput = z.discriminatedUnion("type", [
109
114
  // Restore
110
115
  DTODocumentationPageRestoreActionInput,
111
116
  DTODocumentationGroupRestoreActionInput,
117
+
118
+ // Approval
119
+ DTODocumentationPageApprovalStateChangeActionInput,
112
120
  ]);
113
121
 
114
122
  export type DTOElementActionInput = z.infer<typeof DTOElementActionInput>;
@@ -21,6 +21,7 @@ import { FrontendVersionRoomYDoc } from "../version-room/frontend";
21
21
  export const DocumentationHierarchySettings = z.object({
22
22
  routingVersion: z.string(),
23
23
  isDraftFeatureAdopted: z.boolean(),
24
+ isApprovalFeatureEnabled: z.boolean(),
24
25
  });
25
26
 
26
27
  export type DocumentationHierarchySettings = z.infer<typeof DocumentationHierarchySettings>;
@@ -1,4 +1,5 @@
1
1
  import {
2
+ DocumentationPageApproval,
2
3
  DocumentationPageSnapshot,
3
4
  DocumentationPageV2,
4
5
  ElementGroup,
@@ -22,7 +23,11 @@ type DocumentationHierarchyTransaction = {
22
23
  groupSnapshotIdsToDelete?: string[];
23
24
 
24
25
  internalSettings?: DocumentationHierarchySettings;
26
+
25
27
  pageHashesToUpdate?: Record<string, string>;
28
+
29
+ pageApprovals?: DocumentationPageApproval[];
30
+ pageApprovalIdsToDelete?: string[];
26
31
  };
27
32
 
28
33
  export class BackendVersionRoomYDoc {
@@ -55,6 +60,8 @@ export class BackendVersionRoomYDoc {
55
60
  // Settings
56
61
  transaction.internalSettings && yDoc.updateDocumentationInternalSettings(transaction.internalSettings);
57
62
  transaction.pageHashesToUpdate && yDoc.updateDocumentationPageContentHashes(transaction.pageHashesToUpdate);
63
+ transaction.pageApprovals && yDoc.updateApprovalStates(transaction.pageApprovals);
64
+ transaction.pageApprovalIdsToDelete && yDoc.removeApprovalStates(transaction.pageApprovalIdsToDelete);
58
65
  });
59
66
  }
60
67
  }
@@ -1,4 +1,5 @@
1
1
  import {
2
+ DocumentationPageApproval,
2
3
  DocumentationPageSnapshot,
3
4
  DocumentationPageV2,
4
5
  ElementGroup,
@@ -77,6 +78,7 @@ export class VersionRoomBaseYDoc {
77
78
  const rawSettings: Record<keyof DocumentationHierarchySettings, any> = {
78
79
  routingVersion: map.get("routingVersion"),
79
80
  isDraftFeatureAdopted: map.get("isDraftFeatureAdopted") ?? false,
81
+ isApprovalFeatureEnabled: map.get("isApprovalFeatureEnabled") ?? false,
80
82
  };
81
83
 
82
84
  const settingsParseResult = DocumentationHierarchySettings.safeParse(rawSettings);
@@ -84,6 +86,7 @@ export class VersionRoomBaseYDoc {
84
86
  return {
85
87
  routingVersion: "2",
86
88
  isDraftFeatureAdopted: false,
89
+ isApprovalFeatureEnabled: false,
87
90
  };
88
91
  }
89
92
 
@@ -95,6 +98,7 @@ export class VersionRoomBaseYDoc {
95
98
 
96
99
  map.set("routingVersion", settings.routingVersion);
97
100
  map.set("isDraftFeatureAdopted", settings.isDraftFeatureAdopted);
101
+ map.set("isApprovalFeatureEnabled", settings.isApprovalFeatureEnabled);
98
102
  }
99
103
 
100
104
  private get internalSettingsYMap() {
@@ -182,4 +186,21 @@ export class VersionRoomBaseYDoc {
182
186
  private get documentationPageContentHashesYMap() {
183
187
  return this.yDoc.getMap<string>("documentationPageHashes");
184
188
  }
189
+
190
+ // Approval states
191
+ updateApprovalStates(updates: DocumentationPageApproval[]) {
192
+ this.setObjects(this.documentationPageApprovalsMap, updates);
193
+ }
194
+
195
+ removeApprovalStates(ids: string[]) {
196
+ this.deleteObjects(this.documentationPageApprovalsMap, ids);
197
+ }
198
+
199
+ getApprovals() {
200
+ return this.getObjects(this.documentationPageApprovalsMap, DocumentationPageApproval);
201
+ }
202
+
203
+ private get documentationPageApprovalsMap() {
204
+ return this.yDoc.getMap<object>("documentationPageApprovals");
205
+ }
185
206
  }
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  DocumentationItemConfigurationV2,
3
+ DocumentationPageApproval,
3
4
  DocumentationPageSnapshot,
4
5
  DocumentationPageV2,
5
6
  ElementGroup,
@@ -15,6 +16,7 @@ import {
15
16
  DTODocumentationDraftState,
16
17
  DTODocumentationDraftStateUpdated,
17
18
  DTODocumentationHierarchyV2,
19
+ DTODocumentationPageApprovalState,
18
20
  documentationItemConfigurationToDTOV2,
19
21
  documentationPagesToDTOV2,
20
22
  elementGroupsToDocumentationGroupDTOV2,
@@ -75,6 +77,7 @@ export class FrontendVersionRoomYDoc {
75
77
  const pageDraftStates = this.buildPageDraftCreatedAndUpdatedStates(pages, pageSnapshots);
76
78
  const pageDraftDeletedStates = this.buildPageDraftDeletedStates(pages, pageSnapshots);
77
79
  const pagePublishedMetadata = this.buildPagePublishedMetadata(pages, pageSnapshots);
80
+ const pageApprovalStates = this.buildPageApprovalStates(pages);
78
81
 
79
82
  pageDTOs.forEach(p => {
80
83
  // Assign draft state
@@ -84,6 +87,10 @@ export class FrontendVersionRoomYDoc {
84
87
  // Assign publish metadata
85
88
  const publishMetadata = pagePublishedMetadata.get(p.id);
86
89
  publishMetadata && (p.publishMetadata = publishMetadata);
90
+
91
+ // Assign approval state
92
+ const approvalState = pageApprovalStates.get(p.id);
93
+ approvalState && (p.approvalState = approvalState);
87
94
  });
88
95
 
89
96
  const groupDraftStates = this.buildGroupDraftCreatedAndUpdatedStates(groups, groupSnapshots);
@@ -407,4 +414,24 @@ export class FrontendVersionRoomYDoc {
407
414
  doc.getGroupSnapshots().filter(s => s.reason === "Publish").length > 0
408
415
  );
409
416
  }
417
+
418
+ isApprovalsFeatureEnabled() {
419
+ const doc = new VersionRoomBaseYDoc(this.yDoc);
420
+ const settings = doc.getDocumentationInternalSettings();
421
+ return settings.isApprovalFeatureEnabled;
422
+ }
423
+
424
+ private buildPageApprovalStates(pages: DocumentationPageV2[]) {
425
+ const doc = new VersionRoomBaseYDoc(this.yDoc);
426
+ const pageIds = pages.map(p => p.id);
427
+ const result = new Map<string, DTODocumentationPageApprovalState>();
428
+ const approvals = doc.getApprovals();
429
+ for (const pId of pageIds) {
430
+ const approval = approvals.find(approval => approval.pageId === pId);
431
+ if (approval) {
432
+ result.set(pId, approval);
433
+ }
434
+ }
435
+ return result;
436
+ }
410
437
  }