@seaverse/data-sdk 0.2.0 → 0.2.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
@@ -205,83 +205,6 @@ interface EnvironmentConfig {
205
205
  /** 是否为生产环境 */
206
206
  isProduction: boolean;
207
207
  }
208
- /**
209
- * 预定义的环境配置
210
- *
211
- * 使用说明:
212
- * - production: 正式生产环境
213
- * - staging: 预发布环境
214
- * - development: 开发测试环境
215
- * - local: 本地开发环境
216
- */
217
- declare const ENVIRONMENT_CONFIGS: Record<Environment, EnvironmentConfig>;
218
- /**
219
- * 根据当前运行环境自动检测应该使用的环境配置
220
- *
221
- * 检测规则:
222
- * 1. localhost/127.0.0.1 → local
223
- * 2. 包含 -dev 或 .dev → development
224
- * 3. 包含 staging → staging
225
- * 4. 其他 → production (默认)
226
- *
227
- * @returns 检测到的环境类型
228
- */
229
- declare function detectEnvironment(): Environment;
230
- /**
231
- * 获取环境配置
232
- *
233
- * @param env 环境类型,如果不提供则自动检测
234
- * @returns 环境配置对象
235
- */
236
- declare function getEnvironmentConfig(env?: Environment): EnvironmentConfig;
237
- /**
238
- * 解析用户配置,返回最终的 baseURL
239
- *
240
- * 优先级:
241
- * 1. 显式传入的 baseURL(最高优先级)
242
- * 2. environment 参数指定的环境
243
- * 3. 自动检测环境(最低优先级)
244
- *
245
- * @param options 用户配置选项
246
- * @returns 最终使用的 baseURL
247
- */
248
- declare function resolveBaseURL(options: {
249
- baseURL?: string;
250
- environment?: Environment;
251
- }): string;
252
- /**
253
- * 默认超时时间(毫秒)
254
- */
255
- declare const DEFAULT_TIMEOUT = 10000;
256
- /**
257
- * API 端点路径
258
- */
259
- declare const ENDPOINTS: {
260
- APP_DATA: string;
261
- APP_ADMINS: string;
262
- };
263
- /**
264
- * 动态获取 API Token
265
- * 优先级:
266
- * 1. 传入的 apiKey(最高优先级)
267
- * 2. 通过 PostMessage 从父页面获取
268
- * 3. 没有找到 → 返回空字符串
269
- *
270
- * @param providedApiKey 用户提供的 apiKey(可选)
271
- * @returns API Token
272
- */
273
- declare function getApiToken(providedApiKey?: string): Promise<string | undefined>;
274
- /**
275
- * 动态获取 App ID
276
- * 优先级:
277
- * 1. 传入的 appId(最高优先级)
278
- * 2. 通过 PostMessage 从父页面获取
279
- * 3. 没有找到 → 返回空字符串
280
- *
281
- * @param providedAppId 用户提供的 appId(可选)
282
- * @returns App ID
283
- */
284
- declare function getAppId(providedAppId?: string): Promise<string | undefined>;
285
208
 
286
209
  /**
287
210
  * Data SDK Client
@@ -567,255 +490,26 @@ declare class DataClient {
567
490
  */
568
491
  isAdmin(): Promise<boolean>;
569
492
  /**
570
- * Update token
493
+ * Get current SDK configuration
571
494
  *
572
- * 更新 JWT token
495
+ * 获取当前 SDK 配置信息
573
496
  *
574
- * @param token - New JWT token
575
- */
576
- updateToken(token: string): void;
577
- /**
578
- * Update app ID
579
- *
580
- * 更新应用 ID
497
+ * @returns SDK 配置对象(包含 appId、token、url)
581
498
  *
582
- * @param appId - New application ID
583
- */
584
- updateAppId(appId: string): void;
585
- /**
586
- * Get current app ID
587
- */
588
- getAppId(): string;
589
- /**
590
- * Get current user ID
499
+ * @example
500
+ * ```typescript
501
+ * const config = client.getConfig();
502
+ * console.log('App ID:', config.appId);
503
+ * console.log('Token:', config.token);
504
+ * console.log('API URL:', config.url);
505
+ * ```
591
506
  */
592
- getUserId(): string;
593
- }
594
-
595
- /**
596
- * Global Configuration for Data SDK
597
- * 全局配置模块 - 支持无缝接入
598
- */
599
-
600
- /**
601
- * 初始化选项接口(扩展)
602
- */
603
- interface InitDataOptions extends Partial<DataClientOptions> {
507
+ getConfig(): {
508
+ appId: string;
509
+ token: string;
510
+ url: string;
511
+ };
604
512
  }
605
- /**
606
- * 初始化 Data SDK(可选)
607
- *
608
- * 可以在应用启动时调用,也可以完全不调用(SDK会自动从localStorage获取配置)
609
- *
610
- * @param options - 初始化选项(所有参数都是可选的)
611
- *
612
- * @example
613
- * ```typescript
614
- * // 方式1: 从 localStorage 自动获取 appId 和 token(最常用)
615
- * await initData();
616
- * // appId 自动从 localStorage.app_id 读取
617
- * // token 自动从 localStorage.auth_token 读取
618
- *
619
- * // 方式2: 显式提供 appId
620
- * await initData({
621
- * appId: 'my-app-123'
622
- * // token 自动从 localStorage.auth_token 读取
623
- * });
624
- *
625
- * // 方式3: 显式提供 appId 和 token
626
- * await initData({
627
- * appId: 'my-app-123',
628
- * token: 'user-jwt-token'
629
- * });
630
- * ```
631
- */
632
- declare function initData(options?: InitDataOptions): Promise<void>;
633
- /**
634
- * 获取或创建 DataClient 实例
635
- *
636
- * 如果已经初始化,返回已有实例;否则自动创建新实例
637
- *
638
- * @returns DataClient 实例
639
- * @throws 如果无法获取必需的配置
640
- */
641
- declare function getClient(): Promise<DataClient>;
642
- /**
643
- * 更新全局 token(用于 token 刷新场景)
644
- *
645
- * @param token - 新的 JWT token
646
- *
647
- * @example
648
- * ```typescript
649
- * // Token 刷新后更新
650
- * updateToken('new-jwt-token');
651
- * ```
652
- */
653
- declare function updateToken(token: string): void;
654
- /**
655
- * 更新全局 appId(用于切换应用场景)
656
- *
657
- * @param appId - 新的应用 ID
658
- *
659
- * @example
660
- * ```typescript
661
- * // 切换到其他应用
662
- * updateAppId('another-app-id');
663
- * ```
664
- */
665
- declare function updateAppId(appId: string): void;
666
- /**
667
- * 获取当前配置的 appId
668
- *
669
- * @returns 当前的 appId 或 undefined
670
- */
671
- declare function getCurrentAppId(): string | undefined;
672
- /**
673
- * 清除全局配置(用于登出场景)
674
- *
675
- * @example
676
- * ```typescript
677
- * // 用户登出时清除配置
678
- * clearConfig();
679
- * ```
680
- */
681
- declare function clearConfig(): void;
682
-
683
- /**
684
- * Convenient Function-based APIs
685
- * 便捷的函数式 API 封装 - 无需创建 client 实例
686
- */
687
-
688
- /**
689
- * 查询数据列表
690
- *
691
- * 便捷函数 - 无需创建 client 实例
692
- *
693
- * @param options - 查询选项
694
- * @returns 数据记录数组
695
- *
696
- * @example
697
- * ```typescript
698
- * import { query } from '@seaverse/data-sdk';
699
- *
700
- * const notes = await query({
701
- * table: 'notes',
702
- * filters: { category: 'work' },
703
- * order: { field: 'created_at', direction: 'desc' },
704
- * });
705
- * ```
706
- */
707
- declare function query(options: QueryOptions): Promise<DataRecord[]>;
708
- /**
709
- * 获取单条数据
710
- *
711
- * @param id - 数据 ID
712
- * @returns 数据记录或 null
713
- *
714
- * @example
715
- * ```typescript
716
- * import { get } from '@seaverse/data-sdk';
717
- *
718
- * const note = await get('note-id-123');
719
- * ```
720
- */
721
- declare function get(id: string): Promise<DataRecord | null>;
722
- /**
723
- * 创建数据
724
- *
725
- * @param options - 创建选项
726
- * @returns 创建的数据记录
727
- *
728
- * @example
729
- * ```typescript
730
- * import { create } from '@seaverse/data-sdk';
731
- *
732
- * const newNote = await create({
733
- * table: 'notes',
734
- * data: { title: 'My Note', content: '...' },
735
- * visibility: 'private',
736
- * });
737
- * ```
738
- */
739
- declare function create(options: CreateDataOptions): Promise<DataRecord>;
740
- /**
741
- * 更新数据
742
- *
743
- * @param id - 数据 ID
744
- * @param options - 更新选项
745
- * @returns 更新后的数据记录
746
- *
747
- * @example
748
- * ```typescript
749
- * import { update } from '@seaverse/data-sdk';
750
- *
751
- * const updated = await update('note-id-123', {
752
- * data: { title: 'Updated Title' },
753
- * });
754
- * ```
755
- */
756
- declare function update(id: string, options: UpdateDataOptions): Promise<DataRecord>;
757
- /**
758
- * 删除数据
759
- *
760
- * @param id - 数据 ID
761
- *
762
- * @example
763
- * ```typescript
764
- * import { deleteData } from '@seaverse/data-sdk';
765
- *
766
- * await deleteData('note-id-123');
767
- * ```
768
- */
769
- declare function deleteData(id: string): Promise<void>;
770
- /**
771
- * 批量删除数据
772
- *
773
- * @param ids - 数据 ID 数组
774
- *
775
- * @example
776
- * ```typescript
777
- * import { batchDelete } from '@seaverse/data-sdk';
778
- *
779
- * await batchDelete(['id-1', 'id-2', 'id-3']);
780
- * ```
781
- */
782
- declare function batchDelete(ids: string[]): Promise<void>;
783
- /**
784
- * 查询数据并返回分页信息
785
- *
786
- * @param options - 查询选项
787
- * @returns 分页响应(包含 total, hasMore 等元数据)
788
- *
789
- * @example
790
- * ```typescript
791
- * import { queryWithPagination } from '@seaverse/data-sdk';
792
- *
793
- * const result = await queryWithPagination({
794
- * table: 'posts',
795
- * pagination: { limit: 10, offset: 0 },
796
- * });
797
- *
798
- * console.log(`总共 ${result.total} 条数据`);
799
- * console.log(`是否还有更多: ${result.hasMore}`);
800
- * ```
801
- */
802
- declare function queryWithPagination(options: QueryOptions): Promise<PaginatedResponse<DataRecord>>;
803
- /**
804
- * 检查当前用户是否是管理员
805
- *
806
- * @returns 是否是管理员
807
- *
808
- * @example
809
- * ```typescript
810
- * import { isAdmin } from '@seaverse/data-sdk';
811
- *
812
- * const admin = await isAdmin();
813
- * if (admin) {
814
- * console.log('当前用户是管理员');
815
- * }
816
- * ```
817
- */
818
- declare function isAdmin(): Promise<boolean>;
819
513
 
820
- export { DEFAULT_TIMEOUT, DataClient, DataSDKError, ENDPOINTS, ENVIRONMENT_CONFIGS, NotFoundError, PermissionError, RateLimitError, SDKError, ValidationError, batchDelete, clearConfig, create, deleteData, detectEnvironment, get, getApiToken, getAppId, getClient, getCurrentAppId, getEnvironmentConfig, initData, isAdmin, query, queryWithPagination, resolveBaseURL, update, updateAppId, updateToken };
514
+ export { DataClient, DataSDKError, NotFoundError, PermissionError, RateLimitError, SDKError, ValidationError };
821
515
  export type { AdminRole, CreateDataOptions, DataClientOptions, DataRecord, Environment, EnvironmentConfig, FilterOperator, JWTClaims, PaginatedResponse, QueryOptions, UpdateDataOptions, Visibility };