@diagonal-hq/pages 0.7.1 → 0.7.2

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 = {
@@ -10974,6 +11059,43 @@ export type EmailComposerRecipient = {
10974
11059
  | { resourceId: string; recordId: string }
10975
11060
  );
10976
11061
 
11062
+ export type EmailComposerDraftProps = {
11063
+ /**
11064
+ * `draft` edits a notification template's content without sending it. The composer
11065
+ * shows **Subject** and the email, but no **To** and no send button. The page saves
11066
+ * the content from `onDraftChange`, for example with `Sdk.hooks.useSaveNotificationTemplate`.
11067
+ * Requires `manage_notifications` and `send_emails`.
11068
+ */
11069
+ mode: 'draft';
11070
+
11071
+ /**
11072
+ * Notification template the draft starts from: a starting template, or the page's
11073
+ * own saved campaign copy. The composer loads its raw subject, fixed layout, layout
11074
+ * fields, and generated `{{ ref.<key> }}` values once per mount and never refreshes
11075
+ * them in the background. A different ID or a new `key` discards the edits.
11076
+ */
11077
+ notificationTemplateId: string;
11078
+
11079
+ /**
11080
+ * Called with the raw content after each edit. Before the first edit the draft is
11081
+ * the loaded template, which `Sdk.hooks.useNotificationTemplate` reads. Liquid,
11082
+ * bound fields, and references stay unrendered. Save it without `id` to make a new
11083
+ * template, so the starting template does not change.
11084
+ */
11085
+ onDraftChange?: (draft: SdkNotificationTemplateContent) => void;
11086
+
11087
+ /** Values of the type's variables that every preview reads. A recipient's `data` overrides them. */
11088
+ data?: Record<string, any>;
11089
+
11090
+ /**
11091
+ * The failed save of this draft. Its field errors show on the subject and body.
11092
+ * The edits stay.
11093
+ */
11094
+ error?: SdkApiError | null;
11095
+
11096
+ className?: string;
11097
+ } & EmailComposerAudienceProps;
11098
+
10977
11099
  export type EmailMessagesProps = {
10978
11100
  /**
10979
11101
  * Resource the record belongs to. Pair it with `recordId` for one record's history.
@@ -14683,6 +14805,7 @@ export declare const useNewCalendarEvent: SdkInternal.FilePageSdk["hooks"]["useN
14683
14805
  export declare const useNotificationConsent: SdkInternal.FilePageSdk["hooks"]["useNotificationConsent"];
14684
14806
  export declare const useNotificationHistory: SdkInternal.FilePageSdk["hooks"]["useNotificationHistory"];
14685
14807
  export declare const useNotificationHistoryDetail: SdkInternal.FilePageSdk["hooks"]["useNotificationHistoryDetail"];
14808
+ export declare const useNotificationTemplate: SdkInternal.FilePageSdk["hooks"]["useNotificationTemplate"];
14686
14809
  export declare const useNotificationTemplateEmailDraft: SdkInternal.FilePageSdk["hooks"]["useNotificationTemplateEmailDraft"];
14687
14810
  export declare const useNotificationTemplates: SdkInternal.FilePageSdk["hooks"]["useNotificationTemplates"];
14688
14811
  export declare const useNotificationTypes: SdkInternal.FilePageSdk["hooks"]["useNotificationTypes"];
@@ -14698,6 +14821,7 @@ export declare const useRecords: SdkInternal.FilePageSdk["hooks"]["useRecords"];
14698
14821
  export declare const useResourceDataTable: SdkInternal.FilePageSdk["hooks"]["useResourceDataTable"];
14699
14822
  export declare const useRestoreResourceRecord: SdkInternal.FilePageSdk["hooks"]["useRestoreResourceRecord"];
14700
14823
  export declare const useResumeScheduledNotification: SdkInternal.FilePageSdk["hooks"]["useResumeScheduledNotification"];
14824
+ export declare const useSaveNotificationTemplate: SdkInternal.FilePageSdk["hooks"]["useSaveNotificationTemplate"];
14701
14825
  export declare const useScheduleConflicts: SdkInternal.FilePageSdk["hooks"]["useScheduleConflicts"];
14702
14826
  export declare const useScheduleNotification: SdkInternal.FilePageSdk["hooks"]["useScheduleNotification"];
14703
14827
  export declare const useScheduledNotification: SdkInternal.FilePageSdk["hooks"]["useScheduledNotification"];
@@ -15123,6 +15247,18 @@ export declare const workspace: SdkInternal.FilePageSdk["workspace"];
15123
15247
 
15124
15248
  export type NotificationTemplateEmailDraft = SdkInternal.SdkNotificationTemplateEmailDraft;
15125
15249
 
15250
+ export type NotificationTemplateReference = SdkInternal.SdkNotificationTemplateReference;
15251
+
15252
+ export type NotificationTemplateContent = SdkInternal.SdkNotificationTemplateContent;
15253
+
15254
+ export type NotificationTemplateDefinition = SdkInternal.SdkNotificationTemplateDefinition;
15255
+
15256
+ export type SaveNotificationTemplateInput = SdkInternal.SdkSaveNotificationTemplateInput;
15257
+
15258
+ export type UseSaveNotificationTemplateOptions = SdkInternal.SdkUseSaveNotificationTemplateOptions;
15259
+
15260
+ export type SaveNotificationTemplateHandle = SdkInternal.SdkSaveNotificationTemplateHandle;
15261
+
15126
15262
  export type NavigationMenu = SdkInternal.SdkNavigationMenu;
15127
15263
 
15128
15264
  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.2",
4
4
  "description": "The Page SDK for the pages of file-based Diagonal workspaces.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "repository": {