@seaverse/data-sdk 0.1.8 → 0.1.9
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 +12 -5
- package/dist/index.cjs +4 -4
- package/dist/index.js +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -174,7 +174,7 @@ SDK 会按照以下优先级自动获取 appId:
|
|
|
174
174
|
1. 显式传入的 `appId` 参数(最高优先级)
|
|
175
175
|
2. `localStorage.getItem('app_id')` - **标准 key**
|
|
176
176
|
3. 环境变量 `process.env.APP_ID`
|
|
177
|
-
4. PostMessage 从父窗口获取(iframe 场景,使用 `seaverse:
|
|
177
|
+
4. PostMessage 从父窗口获取(iframe 场景,使用 `seaverse:get_appId` 协议)
|
|
178
178
|
|
|
179
179
|
> 💡 **最佳实践**:
|
|
180
180
|
> - 使用 `@seaverse/auth-sdk` 进行登录,token 会自动存储到 `localStorage.auth_token`
|
|
@@ -419,12 +419,12 @@ window.addEventListener('message', (event) => {
|
|
|
419
419
|
}
|
|
420
420
|
|
|
421
421
|
// 处理 appId 请求
|
|
422
|
-
if (event.data.type === 'seaverse:
|
|
422
|
+
if (event.data.type === 'seaverse:get_appId') {
|
|
423
423
|
const appId = localStorage.getItem('app_id');
|
|
424
424
|
|
|
425
425
|
if (appId) {
|
|
426
426
|
event.source.postMessage({
|
|
427
|
-
type: 'seaverse:
|
|
427
|
+
type: 'seaverse:appId',
|
|
428
428
|
payload: {
|
|
429
429
|
appId: appId
|
|
430
430
|
}
|
|
@@ -453,7 +453,7 @@ const notes = await query({ table: 'notes' });
|
|
|
453
453
|
| 协议 | 请求 type | 响应 type | 响应 payload |
|
|
454
454
|
|------|----------|----------|-------------|
|
|
455
455
|
| Token | `seaverse:get_token` | `seaverse:token` | `{ accessToken: string, expiresIn: number }` |
|
|
456
|
-
| AppId | `seaverse:
|
|
456
|
+
| AppId | `seaverse:get_appId` | `seaverse:appId` | `{ appId: string }` |
|
|
457
457
|
| 错误 | - | `seaverse:error` | `{ error: string }` |
|
|
458
458
|
|
|
459
459
|
#### 服务端渲染(SSR/SSG)
|
|
@@ -613,12 +613,19 @@ psql -h <host> -U postgres -d <database> -f init/init-schema.sql
|
|
|
613
613
|
|
|
614
614
|
## 版本历史
|
|
615
615
|
|
|
616
|
+
### v0.1.9 (2026-01-15)
|
|
617
|
+
|
|
618
|
+
**🔧 PostMessage 协议调整**
|
|
619
|
+
|
|
620
|
+
- ✅ **协议命名优化**:PostMessage appId 协议从 `seaverse:get_appid` / `seaverse:appid` 改为 `seaverse:get_appId` / `seaverse:appId`(驼峰命名)
|
|
621
|
+
- ✅ **保持一致性**:与 token 协议命名风格保持一致
|
|
622
|
+
|
|
616
623
|
### v0.1.8 (2026-01-15)
|
|
617
624
|
|
|
618
625
|
**🎉 AppId 自动获取功能**
|
|
619
626
|
|
|
620
627
|
- ✅ **AppId 自动获取**:支持从 localStorage/环境变量/PostMessage 自动获取 appId
|
|
621
|
-
- ✅ **PostMessage 协议扩展**:新增 `seaverse:
|
|
628
|
+
- ✅ **PostMessage 协议扩展**:新增 `seaverse:get_appId` / `seaverse:appId` 协议
|
|
622
629
|
- ✅ **零配置使用**:`initData()` 和 `DataClient.create()` 现在可以不传任何参数
|
|
623
630
|
- ✅ **优先级统一**:appId 和 token 采用相同的获取优先级
|
|
624
631
|
- ✅ **环境变量支持**:新增 `APP_ID` 环境变量支持
|
package/dist/index.cjs
CHANGED
|
@@ -253,8 +253,8 @@ async function getTokenFromParent(timeout = 5000) {
|
|
|
253
253
|
*
|
|
254
254
|
* 此函数允许接收来自任何源的 PostMessage 消息,便于跨域 iframe 集成。
|
|
255
255
|
* 使用 seaverse 协议与父页面通信:
|
|
256
|
-
* - 发送: { type: 'seaverse:
|
|
257
|
-
* - 接收: { type: 'seaverse:
|
|
256
|
+
* - 发送: { type: 'seaverse:get_appId' }
|
|
257
|
+
* - 接收: { type: 'seaverse:appId', payload: { appId: string } }
|
|
258
258
|
* - 错误: { type: 'seaverse:error', error: string }
|
|
259
259
|
*
|
|
260
260
|
* @param timeout 超时时间(毫秒),默认 5000ms
|
|
@@ -267,7 +267,7 @@ async function getAppIdFromParent(timeout = 5000) {
|
|
|
267
267
|
return new Promise((resolve) => {
|
|
268
268
|
const messageHandler = (event) => {
|
|
269
269
|
// 验证消息格式
|
|
270
|
-
if (event.data && event.data.type === 'seaverse:
|
|
270
|
+
if (event.data && event.data.type === 'seaverse:appId') {
|
|
271
271
|
cleanup();
|
|
272
272
|
// 从 payload.appId 中获取 appId
|
|
273
273
|
const appId = event.data.payload?.appId;
|
|
@@ -292,7 +292,7 @@ async function getAppIdFromParent(timeout = 5000) {
|
|
|
292
292
|
globalThis.window.addEventListener('message', messageHandler);
|
|
293
293
|
// 向父页面发送请求(允许任何源接收)
|
|
294
294
|
try {
|
|
295
|
-
globalThis.window.parent.postMessage({ type: 'seaverse:
|
|
295
|
+
globalThis.window.parent.postMessage({ type: 'seaverse:get_appId' }, '*' // 允许任何源,支持跨域场景
|
|
296
296
|
);
|
|
297
297
|
}
|
|
298
298
|
catch (e) {
|
package/dist/index.js
CHANGED
|
@@ -251,8 +251,8 @@ async function getTokenFromParent(timeout = 5000) {
|
|
|
251
251
|
*
|
|
252
252
|
* 此函数允许接收来自任何源的 PostMessage 消息,便于跨域 iframe 集成。
|
|
253
253
|
* 使用 seaverse 协议与父页面通信:
|
|
254
|
-
* - 发送: { type: 'seaverse:
|
|
255
|
-
* - 接收: { type: 'seaverse:
|
|
254
|
+
* - 发送: { type: 'seaverse:get_appId' }
|
|
255
|
+
* - 接收: { type: 'seaverse:appId', payload: { appId: string } }
|
|
256
256
|
* - 错误: { type: 'seaverse:error', error: string }
|
|
257
257
|
*
|
|
258
258
|
* @param timeout 超时时间(毫秒),默认 5000ms
|
|
@@ -265,7 +265,7 @@ async function getAppIdFromParent(timeout = 5000) {
|
|
|
265
265
|
return new Promise((resolve) => {
|
|
266
266
|
const messageHandler = (event) => {
|
|
267
267
|
// 验证消息格式
|
|
268
|
-
if (event.data && event.data.type === 'seaverse:
|
|
268
|
+
if (event.data && event.data.type === 'seaverse:appId') {
|
|
269
269
|
cleanup();
|
|
270
270
|
// 从 payload.appId 中获取 appId
|
|
271
271
|
const appId = event.data.payload?.appId;
|
|
@@ -290,7 +290,7 @@ async function getAppIdFromParent(timeout = 5000) {
|
|
|
290
290
|
globalThis.window.addEventListener('message', messageHandler);
|
|
291
291
|
// 向父页面发送请求(允许任何源接收)
|
|
292
292
|
try {
|
|
293
|
-
globalThis.window.parent.postMessage({ type: 'seaverse:
|
|
293
|
+
globalThis.window.parent.postMessage({ type: 'seaverse:get_appId' }, '*' // 允许任何源,支持跨域场景
|
|
294
294
|
);
|
|
295
295
|
}
|
|
296
296
|
catch (e) {
|