hivewrite-sdk 1.1.47 → 1.1.48

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/README.md CHANGED
@@ -50,10 +50,12 @@ const MyEditor = () => {
50
50
  useEffect(() => {
51
51
  if (containerRef.current) {
52
52
  hivewrite.init({
53
- authorize: async () => {
53
+ accessToken: "initial_access_token_here",
54
+ onTokenRefresh: async () => {
54
55
  // Best practice: Fetch from your backend to keep API key secure
55
- const response = await fetch("/api/hivewrite/authorize");
56
- return await response.json(); // Must return AuthData structure
56
+ const response = await fetch("/api/hivewrite/refresh-token");
57
+ const data = await response.json();
58
+ return data.access_token; // Return the new access token string
57
59
  },
58
60
  container: containerRef.current,
59
61
  mode: "FULL_EDITOR",
@@ -79,9 +81,11 @@ const MyEditor = () => {
79
81
  <script src="https://cdn.jsdelivr.net/npm/hivewrite-sdk@latest/bundle.min.js"></script>
80
82
  <script>
81
83
  hivewrite.init({
82
- authorize: async () => {
83
- const response = await fetch("/api/hivewrite/authorize");
84
- return await response.json();
84
+ accessToken: "initial_access_token_here",
85
+ onTokenRefresh: async () => {
86
+ const response = await fetch("/api/hivewrite/refresh-token");
87
+ const data = await response.json();
88
+ return data.access_token;
85
89
  },
86
90
  container: "#editor-container",
87
91
  mode: "FULL_EDITOR",
@@ -107,8 +111,9 @@ Initializes and mounts the editor.
107
111
 
108
112
  | Parameter | Type | Required | Description |
109
113
  | :------------- | :---------------------- | :------- | :-------------------------------------------------------------------------------------------------------------------------------------------------- |
110
- | `authorize` | `() => Promise<AuthData>` | Yes | Callback function that returns authorization data (token and account info) |
111
- | `container` | `string \| HTMLElement` | Yes | CSS selector or DOM element to mount the editor |
114
+ | `onTokenRefresh` | `() => Promise<string>` | Yes | Callback function that returns a new access token when the current one expires |
115
+ | `accessToken` | `string` | Yes | Initial access token for authorization |
116
+ | `container` | `string \| HTMLElement` | Yes | CSS selector or DOM element to mount the editor |
112
117
  | `userId` | `string` | No | Unique identifier for the current user |
113
118
  | `mode` | `string` | Yes | `'FULL_EDITOR'`, `'DESIGN_ONLY'`, `'READ_ONLY'` |
114
119
  | `theme` | `string` | No | `'light'` (default) or `'dark'` |
@@ -144,20 +149,22 @@ Initializes and mounts the editor.
144
149
 
145
150
  ## 🔐 Authentication & Security
146
151
 
147
- HiveWrite uses a callback-based authentication system to ensure your API keys are never exposed in the client-side code.
152
+ HiveWrite uses a dual-token authentication system: you provide an initial token and a callback to refresh it.
148
153
 
149
- ### 1. The `authorize` Callback
154
+ ### 1. The `onTokenRefresh` Callback
150
155
 
151
- You must provide an `authorize` function that returns a `Promise` resolving to `AuthData`.
156
+ You must provide an `onTokenRefresh` function that returns a `Promise` resolving to a new access token string.
152
157
 
153
158
  ```javascript
154
159
  import { EmailEditor } from "hivewrite-sdk";
155
160
 
156
161
  EmailEditor.init({
157
- authorize: async () => {
158
- // Call your backend proxy
159
- const res = await fetch("/api/hivewrite-auth");
160
- return await res.json();
162
+ accessToken: "initial_token",
163
+ onTokenRefresh: async () => {
164
+ // Call your backend proxy to get a fresh token
165
+ const res = await fetch("/api/hivewrite-refresh");
166
+ const data = await res.json();
167
+ return data.access_token;
161
168
  },
162
169
  // ... other config
163
170
  });