esender-email-editor 1.0.2 → 1.1.0

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
@@ -23,6 +23,7 @@ interface TemplateDocument {
23
23
  _id: string;
24
24
  userId: string;
25
25
  projectId: string;
26
+ templateId?: string;
26
27
  HTML: string;
27
28
  JSON: unknown;
28
29
  createdAt?: string;
@@ -34,8 +35,76 @@ interface TemplateApiResponse {
34
35
  template?: TemplateDocument;
35
36
  }
36
37
 
38
+ /**
39
+ * Module-level API configuration for the editor.
40
+ *
41
+ * Consumers override these via the `apiConfig` prop on <Package />. Internal
42
+ * modules (axiosClient, license, template, UploadMedia) read from this module
43
+ * instead of hardcoded constants so the editor can talk to any backend that
44
+ * implements the same contract.
45
+ *
46
+ * Endpoint defaults follow the spec paths (e.g. /template/create). The host
47
+ * URL (`baseUrl`) defaults to the eSender production API.
48
+ *
49
+ * Template URLs may contain :projectId / :templateId placeholders, which
50
+ * `resolveTemplatePath` substitutes at call time.
51
+ */
52
+ interface ApiConfig {
53
+ /** API host. No trailing slash. */
54
+ baseUrl?: string;
55
+ /** POST — exchange apiKey for access + refresh tokens. */
56
+ verifyUrl?: string;
57
+ /** POST — exchange refresh token for new access token. */
58
+ refreshUrl?: string;
59
+ /** POST — create or update a template (templateId in body for update). */
60
+ saveTemplateUrl?: string;
61
+ /** GET — load the project's current template. `:projectId` is substituted. */
62
+ getTemplatesUrl?: string;
63
+ /** GET — load a specific template. `:projectId` / `:templateId` are substituted. */
64
+ getTemplateByIdUrl?: string;
65
+ /** POST (multipart) — upload an image. Receives a hosted URL back. */
66
+ uploadMediaUrl?: string;
67
+ }
68
+
69
+ /**
70
+ * Editor event callbacks exposed to consumers via <Package />.
71
+ *
72
+ * Internal components reach these through `useEditorEvents()` instead of
73
+ * prop-drilling. Callbacks are stored in a ref so re-renders never re-fire
74
+ * subscribers, and a no-op fallback is returned when a callback is unset —
75
+ * call sites don't need to null-check.
76
+ */
77
+ interface MediaUploadEvent {
78
+ url: string;
79
+ /** Original File object the user picked, if available. */
80
+ file?: File;
81
+ /** Raw API response body, untyped — varies by backend. */
82
+ response?: unknown;
83
+ }
84
+ interface SaveEvent {
85
+ projectId: string;
86
+ templateId?: string;
87
+ /** API response body from the save call. */
88
+ response: unknown;
89
+ }
90
+ interface LoadEvent {
91
+ projectId: string;
92
+ templateId?: string;
93
+ /** API response body from the load call. */
94
+ response: unknown;
95
+ }
96
+ interface EditorEventCallbacks {
97
+ onSave?: (event: SaveEvent) => void;
98
+ onLoad?: (event: LoadEvent) => void;
99
+ onTemplateChange?: (json: unknown) => void;
100
+ onHtmlExport?: (html: string) => void;
101
+ onMediaUpload?: (event: MediaUploadEvent) => void;
102
+ }
103
+
37
104
  interface SaveTemplateOptions {
38
105
  projectId: string;
106
+ /** Provide to update an existing template instead of creating a new one. */
107
+ templateId?: string;
39
108
  }
40
109
  interface LoadTemplateOptions {
41
110
  projectId: string;
@@ -48,7 +117,8 @@ interface EditorHandle {
48
117
  loadJson: (json: string, raw?: boolean) => void;
49
118
  /**
50
119
  * Export the current editor state (HTML + JSON) and persist it to the
51
- * eSender template API. apiKey comes from the Package's prop.
120
+ * template API. apiKey comes from the Package's prop. Pass `templateId` to
121
+ * update an existing template.
52
122
  */
53
123
  saveTemplate: (options: SaveTemplateOptions) => Promise<TemplateApiResponse>;
54
124
  /**
@@ -57,13 +127,18 @@ interface EditorHandle {
57
127
  */
58
128
  loadTemplate: (options: LoadTemplateOptions) => Promise<TemplateApiResponse>;
59
129
  }
60
- interface PackageProps {
130
+ interface PackageProps extends EditorEventCallbacks {
61
131
  apiKey: string;
62
132
  /**
63
- * @deprecated The new eSender license flow does not use projectId. Kept for
133
+ * @deprecated The license flow does not use projectId. Kept for
64
134
  * backwards-compatible prop signatures during the migration. Ignored at runtime.
65
135
  */
66
136
  projectId?: string;
137
+ /**
138
+ * Override default API endpoints (base URL + per-route paths). Consumers
139
+ * who self-host the backend pass this to point the editor at their server.
140
+ */
141
+ apiConfig?: ApiConfig;
67
142
  onLicenseError?: (error: LicenseError) => void;
68
143
  customButtons?: ReactNode;
69
144
  showUndoRedo?: boolean;
@@ -71,4 +146,4 @@ interface PackageProps {
71
146
  declare const Package: React.ForwardRefExoticComponent<PackageProps & React.RefAttributes<EditorHandle>>;
72
147
 
73
148
  export { Package, Package as default };
74
- export type { EditorHandle, LicenseError, LicenseErrorCode, LoadTemplateOptions, PackageProps, RefreshTokenResponse, SaveTemplateOptions, TemplateApiResponse, TemplateDocument, VerifyLicenseResponse };
149
+ export type { ApiConfig, EditorEventCallbacks, EditorHandle, LicenseError, LicenseErrorCode, LoadEvent, LoadTemplateOptions, MediaUploadEvent, PackageProps, RefreshTokenResponse, SaveEvent, SaveTemplateOptions, TemplateApiResponse, TemplateDocument, VerifyLicenseResponse };