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 +22 -15
- package/bundle.min.js +1 -1
- package/index.d.ts +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -50,10 +50,12 @@ const MyEditor = () => {
|
|
|
50
50
|
useEffect(() => {
|
|
51
51
|
if (containerRef.current) {
|
|
52
52
|
hivewrite.init({
|
|
53
|
-
|
|
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/
|
|
56
|
-
|
|
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
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
| `
|
|
111
|
-
| `
|
|
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
|
|
152
|
+
HiveWrite uses a dual-token authentication system: you provide an initial token and a callback to refresh it.
|
|
148
153
|
|
|
149
|
-
### 1. The `
|
|
154
|
+
### 1. The `onTokenRefresh` Callback
|
|
150
155
|
|
|
151
|
-
You must provide an `
|
|
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
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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
|
});
|