@diagonal-hq/pages 0.7.1 → 0.7.3

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/index.d.ts CHANGED
@@ -2898,6 +2898,63 @@ export type SdkNotificationTemplateEmailDraft = {
2898
2898
  variables: SdkNotificationVariableSummary[];
2899
2899
  };
2900
2900
 
2901
+ export type SdkNotificationTemplateReference = {
2902
+ label: string;
2903
+ resolver: Record<string, any>;
2904
+ };
2905
+
2906
+ export type SdkNotificationTemplateContent = {
2907
+ notification_type_id: string;
2908
+ /** Liquid source, such as `News for {{ record.first_name | default: "friend" }}`. */
2909
+ email_subject: string;
2910
+ /** The template's published layout, or null for the default body. */
2911
+ email_layout_id: string | null;
2912
+ /** Layout field values. A Liquid field is a source string; a bound field keeps its `context.get` value. */
2913
+ email_layout_data: Record<string, any>;
2914
+ /** The generated values that the content reads as `{{ ref.<key> }}`. */
2915
+ references: Record<string, SdkNotificationTemplateReference>;
2916
+ };
2917
+
2918
+ export type SdkNotificationTemplateDefinition = SdkNotificationTemplateContent & {
2919
+ id: string;
2920
+ name: string;
2921
+ notification_type_name: string;
2922
+ email_layout_name: string | null;
2923
+ is_default: boolean;
2924
+ is_email_enabled: boolean;
2925
+ is_sms_enabled: boolean;
2926
+ sms_body: string | null;
2927
+ };
2928
+
2929
+ export type SdkSaveNotificationTemplateInput = SdkNotificationTemplateContent & {
2930
+ id?: string;
2931
+ name: string;
2932
+ };
2933
+
2934
+ export type SdkUseSaveNotificationTemplateOptions = {
2935
+ onSuccess?: (template: SdkNotificationTemplateDefinition) => void;
2936
+ onError?: (error: SdkApiError) => void;
2937
+ };
2938
+
2939
+ export type SdkSaveNotificationTemplateHandle = {
2940
+ /**
2941
+ * Save the template. Resolves with the saved definition, or `null` when the request
2942
+ * failed. It never rejects. Read `error` for the failure.
2943
+ */
2944
+ save: (
2945
+ input: SdkSaveNotificationTemplateInput
2946
+ ) => Promise<SdkNotificationTemplateDefinition | null>;
2947
+ /** The definition of the most recent successful save. */
2948
+ data: SdkNotificationTemplateDefinition | undefined;
2949
+ /** `true` while a request is in flight. */
2950
+ isPending: boolean;
2951
+ isError: boolean;
2952
+ /** The failed request's {@link SdkApiError} (with `status` and `body`), or `null`. */
2953
+ error: SdkApiError | null;
2954
+ /** Clears `data`, `error`, and `isError` back to their initial state. */
2955
+ reset: () => void;
2956
+ };
2957
+
2901
2958
  export type SdkNavigationMenu = {
2902
2959
  id: string;
2903
2960
  name: string;
@@ -7597,6 +7654,31 @@ export type SdkHooks = {
7597
7654
  notificationTemplateId: string | null | undefined,
7598
7655
  options?: { enabled?: boolean }
7599
7656
  ): SdkApiHandle<SdkNotificationTemplateEmailDraft>;
7657
+ /**
7658
+ * Read a saved notification template with its raw subject, layout, layout fields, and
7659
+ * generated references. Requires manage_notifications. No request runs until
7660
+ * notificationTemplateId is set. To edit the content in the page, use
7661
+ * `<Sdk.Components.EmailComposer mode="draft" notificationTemplateId>`.
7662
+ * @example
7663
+ * const campaign = Sdk.hooks.useNotificationTemplate(campaignTemplateId);
7664
+ */
7665
+ useNotificationTemplate(
7666
+ notificationTemplateId: string | null | undefined,
7667
+ options?: { enabled?: boolean }
7668
+ ): SdkApiHandle<SdkNotificationTemplateDefinition>;
7669
+ /**
7670
+ * Create or replace a notification template through `/api/notification-templates`.
7671
+ * Requires manage_notifications. Without `id`, the save creates a new template of the
7672
+ * type, for example a campaign copy of a starting template, and the starting template
7673
+ * does not change. With `id`, it replaces that template's name and email content.
7674
+ * The save validates the content as the notification editor does. Saving sends no email.
7675
+ * @example
7676
+ * const { save, isPending, error } = Sdk.hooks.useSaveNotificationTemplate();
7677
+ * const saved = await save({ ...draft, id: campaignTemplateId ?? undefined, name: 'Feature spotlight' });
7678
+ */
7679
+ useSaveNotificationTemplate(
7680
+ options?: SdkUseSaveNotificationTemplateOptions
7681
+ ): SdkSaveNotificationTemplateHandle;
7600
7682
 
7601
7683
  /**
7602
7684
  * List pending and failed notifications associated with one source or recipient record.
@@ -10821,8 +10903,11 @@ export type DropdownMenuItem = {
10821
10903
  onSelect?: () => void;
10822
10904
  };
10823
10905
 
10824
- export type EmailComposerProps = EmailComposerBaseProps &
10825
- EmailComposerContentProps &
10906
+ export type EmailComposerProps = EmailComposerSendProps | EmailComposerDraftProps;
10907
+
10908
+ export type EmailComposerSendProps = EmailComposerBaseProps & {
10909
+ mode?: 'send';
10910
+ } & EmailComposerContentProps &
10826
10911
  EmailComposerAudienceProps;
10827
10912
 
10828
10913
  export type EmailComposerBaseProps = {
@@ -10897,12 +10982,19 @@ export type EmailComposerContentProps =
10897
10982
  * only this email, never the template. Requires `send_emails`, not
10898
10983
  * `manage_notifications`.
10899
10984
  *
10900
- * The composer shows a loading state, then the draft. A failed load shows the
10901
- * reason with a "Try again" button; templates that only a notification send can
10902
- * render fail this way. The draft is read once per mount and is not refreshed
10903
- * in the background, so it never replaces the viewer's edits. A different ID
10904
- * discards the edits and loads that template. A new `key` reloads the same
10905
- * template. "Send another" restores the template's copy.
10985
+ * While the template loads, the recipient row, the Subject field, the toolbar,
10986
+ * and the preview frame stay in place: the frame shows the loading state and
10987
+ * Send is disabled. A failed load shows the reason with a "Try again" button
10988
+ * under the frame; templates that only a notification send can render fail this
10989
+ * way. The draft is read once per selection and is not refreshed in the
10990
+ * background, so it never replaces the viewer's edits.
10991
+ *
10992
+ * A different ID discards the edits and loads that template in place, so do
10993
+ * not change the `key` with the ID. The composer does the same when the page
10994
+ * renders it with an ID in one branch and without one in the other, at the same
10995
+ * place in the tree. The recipients, the "Preview as" pick, and the view stay.
10996
+ * A new `key` is a full reset that reads the same template again. "Send
10997
+ * another" restores the template's copy.
10906
10998
  */
10907
10999
  notificationTemplateId: string;
10908
11000
  emailLayoutId?: never;
@@ -10974,6 +11066,43 @@ export type EmailComposerRecipient = {
10974
11066
  | { resourceId: string; recordId: string }
10975
11067
  );
10976
11068
 
11069
+ export type EmailComposerDraftProps = {
11070
+ /**
11071
+ * `draft` edits a notification template's content without sending it. The composer
11072
+ * shows **Subject** and the email, but no **To** and no send button. The page saves
11073
+ * the content from `onDraftChange`, for example with `Sdk.hooks.useSaveNotificationTemplate`.
11074
+ * Requires `manage_notifications` and `send_emails`.
11075
+ */
11076
+ mode: 'draft';
11077
+
11078
+ /**
11079
+ * Notification template the draft starts from: a starting template, or the page's
11080
+ * own saved campaign copy. The composer loads its raw subject, fixed layout, layout
11081
+ * fields, and generated `{{ ref.<key> }}` values once per mount and never refreshes
11082
+ * them in the background. A different ID or a new `key` discards the edits.
11083
+ */
11084
+ notificationTemplateId: string;
11085
+
11086
+ /**
11087
+ * Called with the raw content after each edit. Before the first edit the draft is
11088
+ * the loaded template, which `Sdk.hooks.useNotificationTemplate` reads. Liquid,
11089
+ * bound fields, and references stay unrendered. Save it without `id` to make a new
11090
+ * template, so the starting template does not change.
11091
+ */
11092
+ onDraftChange?: (draft: SdkNotificationTemplateContent) => void;
11093
+
11094
+ /** Values of the type's variables that every preview reads. A recipient's `data` overrides them. */
11095
+ data?: Record<string, any>;
11096
+
11097
+ /**
11098
+ * The failed save of this draft. Its field errors show on the subject and body.
11099
+ * The edits stay.
11100
+ */
11101
+ error?: SdkApiError | null;
11102
+
11103
+ className?: string;
11104
+ } & EmailComposerAudienceProps;
11105
+
10977
11106
  export type EmailMessagesProps = {
10978
11107
  /**
10979
11108
  * Resource the record belongs to. Pair it with `recordId` for one record's history.
@@ -14683,6 +14812,7 @@ export declare const useNewCalendarEvent: SdkInternal.FilePageSdk["hooks"]["useN
14683
14812
  export declare const useNotificationConsent: SdkInternal.FilePageSdk["hooks"]["useNotificationConsent"];
14684
14813
  export declare const useNotificationHistory: SdkInternal.FilePageSdk["hooks"]["useNotificationHistory"];
14685
14814
  export declare const useNotificationHistoryDetail: SdkInternal.FilePageSdk["hooks"]["useNotificationHistoryDetail"];
14815
+ export declare const useNotificationTemplate: SdkInternal.FilePageSdk["hooks"]["useNotificationTemplate"];
14686
14816
  export declare const useNotificationTemplateEmailDraft: SdkInternal.FilePageSdk["hooks"]["useNotificationTemplateEmailDraft"];
14687
14817
  export declare const useNotificationTemplates: SdkInternal.FilePageSdk["hooks"]["useNotificationTemplates"];
14688
14818
  export declare const useNotificationTypes: SdkInternal.FilePageSdk["hooks"]["useNotificationTypes"];
@@ -14698,6 +14828,7 @@ export declare const useRecords: SdkInternal.FilePageSdk["hooks"]["useRecords"];
14698
14828
  export declare const useResourceDataTable: SdkInternal.FilePageSdk["hooks"]["useResourceDataTable"];
14699
14829
  export declare const useRestoreResourceRecord: SdkInternal.FilePageSdk["hooks"]["useRestoreResourceRecord"];
14700
14830
  export declare const useResumeScheduledNotification: SdkInternal.FilePageSdk["hooks"]["useResumeScheduledNotification"];
14831
+ export declare const useSaveNotificationTemplate: SdkInternal.FilePageSdk["hooks"]["useSaveNotificationTemplate"];
14701
14832
  export declare const useScheduleConflicts: SdkInternal.FilePageSdk["hooks"]["useScheduleConflicts"];
14702
14833
  export declare const useScheduleNotification: SdkInternal.FilePageSdk["hooks"]["useScheduleNotification"];
14703
14834
  export declare const useScheduledNotification: SdkInternal.FilePageSdk["hooks"]["useScheduledNotification"];
@@ -15123,6 +15254,18 @@ export declare const workspace: SdkInternal.FilePageSdk["workspace"];
15123
15254
 
15124
15255
  export type NotificationTemplateEmailDraft = SdkInternal.SdkNotificationTemplateEmailDraft;
15125
15256
 
15257
+ export type NotificationTemplateReference = SdkInternal.SdkNotificationTemplateReference;
15258
+
15259
+ export type NotificationTemplateContent = SdkInternal.SdkNotificationTemplateContent;
15260
+
15261
+ export type NotificationTemplateDefinition = SdkInternal.SdkNotificationTemplateDefinition;
15262
+
15263
+ export type SaveNotificationTemplateInput = SdkInternal.SdkSaveNotificationTemplateInput;
15264
+
15265
+ export type UseSaveNotificationTemplateOptions = SdkInternal.SdkUseSaveNotificationTemplateOptions;
15266
+
15267
+ export type SaveNotificationTemplateHandle = SdkInternal.SdkSaveNotificationTemplateHandle;
15268
+
15126
15269
  export type NavigationMenu = SdkInternal.SdkNavigationMenu;
15127
15270
 
15128
15271
  export type NavigationMenuCatalog = SdkInternal.SdkNavigationMenuCatalog;
package/dist/index.js CHANGED
@@ -187,6 +187,7 @@ export const useNewCalendarEvent = undefined;
187
187
  export const useNotificationConsent = undefined;
188
188
  export const useNotificationHistory = undefined;
189
189
  export const useNotificationHistoryDetail = undefined;
190
+ export const useNotificationTemplate = undefined;
190
191
  export const useNotificationTemplateEmailDraft = undefined;
191
192
  export const useNotificationTemplates = undefined;
192
193
  export const useNotificationTypes = undefined;
@@ -202,6 +203,7 @@ export const useRecords = undefined;
202
203
  export const useResourceDataTable = undefined;
203
204
  export const useRestoreResourceRecord = undefined;
204
205
  export const useResumeScheduledNotification = undefined;
206
+ export const useSaveNotificationTemplate = undefined;
205
207
  export const useScheduleConflicts = undefined;
206
208
  export const useScheduleNotification = undefined;
207
209
  export const useScheduledNotification = undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diagonal-hq/pages",
3
- "version": "0.7.1",
3
+ "version": "0.7.3",
4
4
  "description": "The Page SDK for the pages of file-based Diagonal workspaces.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "repository": {