@seaverse/data-sdk 0.1.0 → 0.1.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
@@ -260,6 +260,32 @@ declare const ENDPOINTS: {
260
260
  APP_DATA: string;
261
261
  APP_ADMINS: string;
262
262
  };
263
+ /**
264
+ * 自动获取 API Token
265
+ *
266
+ * 按照以下优先级获取 token:
267
+ * 1. 传入的 token 参数
268
+ * 2. localStorage 中的 auth_token
269
+ * 3. PostMessage 从父窗口获取(iframe 场景)
270
+ * 4. 环境变量 DATA_SDK_TOKEN
271
+ *
272
+ * @param providedToken - 可选的直接提供的 token
273
+ * @returns token 字符串
274
+ */
275
+ declare function getApiToken(providedToken?: string): Promise<string>;
276
+ /**
277
+ * 自动获取 App ID
278
+ *
279
+ * 按照以下优先级获取 appId:
280
+ * 1. 传入的 appId 参数
281
+ * 2. localStorage 中的 app_id
282
+ * 3. PostMessage 从父窗口获取(iframe 场景)
283
+ * 4. 环境变量 DATA_SDK_APP_ID
284
+ *
285
+ * @param providedAppId - 可选的直接提供的 appId
286
+ * @returns appId 字符串
287
+ */
288
+ declare function getAppId(providedAppId?: string): Promise<string>;
263
289
 
264
290
  /**
265
291
  * Data SDK Client
@@ -538,5 +564,219 @@ declare class DataClient {
538
564
  getUserId(): string;
539
565
  }
540
566
 
541
- export { DEFAULT_TIMEOUT, DataClient, DataSDKError, ENDPOINTS, ENVIRONMENT_CONFIGS, NotFoundError, PermissionError, RateLimitError, SDKError, ValidationError, detectEnvironment, getEnvironmentConfig, resolveBaseURL };
567
+ /**
568
+ * Global Configuration for Data SDK
569
+ * 全局配置模块 - 支持无缝接入
570
+ */
571
+
572
+ /**
573
+ * 初始化 Data SDK(可选)
574
+ *
575
+ * 可以在应用启动时调用,也可以完全不调用(SDK会自动从localStorage获取配置)
576
+ *
577
+ * @param options - 初始化选项(所有参数都是可选的)
578
+ *
579
+ * @example
580
+ * ```typescript
581
+ * // 方式1: 显式初始化(推荐用于需要自定义配置的场景)
582
+ * await initData({
583
+ * appId: 'my-app-123',
584
+ * token: 'user-jwt-token',
585
+ * debug: true,
586
+ * });
587
+ *
588
+ * // 方式2: 不初始化,直接使用(推荐用于SeaVerse平台应用)
589
+ * // SDK 会自动从 localStorage 读取 auth_token 和 app_id
590
+ * const notes = await query({ table: 'notes' });
591
+ * ```
592
+ */
593
+ declare function initData(options?: Partial<DataClientOptions>): Promise<void>;
594
+ /**
595
+ * 获取或创建 DataClient 实例
596
+ *
597
+ * 如果已经初始化,返回已有实例;否则自动创建新实例
598
+ *
599
+ * @returns DataClient 实例
600
+ * @throws 如果无法获取必需的配置
601
+ */
602
+ declare function getClient(): Promise<DataClient>;
603
+ /**
604
+ * 更新全局 token(用于 token 刷新场景)
605
+ *
606
+ * @param token - 新的 JWT token
607
+ *
608
+ * @example
609
+ * ```typescript
610
+ * // Token 刷新后更新
611
+ * updateToken('new-jwt-token');
612
+ * ```
613
+ */
614
+ declare function updateToken(token: string): void;
615
+ /**
616
+ * 更新全局 appId(用于切换应用场景)
617
+ *
618
+ * @param appId - 新的应用 ID
619
+ *
620
+ * @example
621
+ * ```typescript
622
+ * // 切换到其他应用
623
+ * updateAppId('another-app-id');
624
+ * ```
625
+ */
626
+ declare function updateAppId(appId: string): void;
627
+ /**
628
+ * 获取当前配置的 appId
629
+ *
630
+ * @returns 当前的 appId 或 undefined
631
+ */
632
+ declare function getCurrentAppId(): string | undefined;
633
+ /**
634
+ * 清除全局配置(用于登出场景)
635
+ *
636
+ * @example
637
+ * ```typescript
638
+ * // 用户登出时清除配置
639
+ * clearConfig();
640
+ * ```
641
+ */
642
+ declare function clearConfig(): void;
643
+
644
+ /**
645
+ * Convenient Function-based APIs
646
+ * 便捷的函数式 API 封装 - 无需创建 client 实例
647
+ */
648
+
649
+ /**
650
+ * 查询数据列表
651
+ *
652
+ * 便捷函数 - 无需创建 client 实例
653
+ *
654
+ * @param options - 查询选项
655
+ * @returns 数据记录数组
656
+ *
657
+ * @example
658
+ * ```typescript
659
+ * import { query } from '@seaverse/data-sdk';
660
+ *
661
+ * const notes = await query({
662
+ * table: 'notes',
663
+ * filters: { category: 'work' },
664
+ * order: { field: 'created_at', direction: 'desc' },
665
+ * });
666
+ * ```
667
+ */
668
+ declare function query(options: QueryOptions): Promise<DataRecord[]>;
669
+ /**
670
+ * 获取单条数据
671
+ *
672
+ * @param id - 数据 ID
673
+ * @returns 数据记录或 null
674
+ *
675
+ * @example
676
+ * ```typescript
677
+ * import { get } from '@seaverse/data-sdk';
678
+ *
679
+ * const note = await get('note-id-123');
680
+ * ```
681
+ */
682
+ declare function get(id: string): Promise<DataRecord | null>;
683
+ /**
684
+ * 创建数据
685
+ *
686
+ * @param options - 创建选项
687
+ * @returns 创建的数据记录
688
+ *
689
+ * @example
690
+ * ```typescript
691
+ * import { create } from '@seaverse/data-sdk';
692
+ *
693
+ * const newNote = await create({
694
+ * table: 'notes',
695
+ * data: { title: 'My Note', content: '...' },
696
+ * visibility: 'private',
697
+ * });
698
+ * ```
699
+ */
700
+ declare function create(options: CreateDataOptions): Promise<DataRecord>;
701
+ /**
702
+ * 更新数据
703
+ *
704
+ * @param id - 数据 ID
705
+ * @param options - 更新选项
706
+ * @returns 更新后的数据记录
707
+ *
708
+ * @example
709
+ * ```typescript
710
+ * import { update } from '@seaverse/data-sdk';
711
+ *
712
+ * const updated = await update('note-id-123', {
713
+ * data: { title: 'Updated Title' },
714
+ * });
715
+ * ```
716
+ */
717
+ declare function update(id: string, options: UpdateDataOptions): Promise<DataRecord>;
718
+ /**
719
+ * 删除数据
720
+ *
721
+ * @param id - 数据 ID
722
+ *
723
+ * @example
724
+ * ```typescript
725
+ * import { deleteData } from '@seaverse/data-sdk';
726
+ *
727
+ * await deleteData('note-id-123');
728
+ * ```
729
+ */
730
+ declare function deleteData(id: string): Promise<void>;
731
+ /**
732
+ * 批量删除数据
733
+ *
734
+ * @param ids - 数据 ID 数组
735
+ *
736
+ * @example
737
+ * ```typescript
738
+ * import { batchDelete } from '@seaverse/data-sdk';
739
+ *
740
+ * await batchDelete(['id-1', 'id-2', 'id-3']);
741
+ * ```
742
+ */
743
+ declare function batchDelete(ids: string[]): Promise<void>;
744
+ /**
745
+ * 查询数据并返回分页信息
746
+ *
747
+ * @param options - 查询选项
748
+ * @returns 分页响应(包含 total, hasMore 等元数据)
749
+ *
750
+ * @example
751
+ * ```typescript
752
+ * import { queryWithPagination } from '@seaverse/data-sdk';
753
+ *
754
+ * const result = await queryWithPagination({
755
+ * table: 'posts',
756
+ * pagination: { limit: 10, offset: 0 },
757
+ * });
758
+ *
759
+ * console.log(`总共 ${result.total} 条数据`);
760
+ * console.log(`是否还有更多: ${result.hasMore}`);
761
+ * ```
762
+ */
763
+ declare function queryWithPagination(options: QueryOptions): Promise<PaginatedResponse<DataRecord>>;
764
+ /**
765
+ * 检查当前用户是否是管理员
766
+ *
767
+ * @returns 是否是管理员
768
+ *
769
+ * @example
770
+ * ```typescript
771
+ * import { isAdmin } from '@seaverse/data-sdk';
772
+ *
773
+ * const admin = await isAdmin();
774
+ * if (admin) {
775
+ * console.log('当前用户是管理员');
776
+ * }
777
+ * ```
778
+ */
779
+ declare function isAdmin(): Promise<boolean>;
780
+
781
+ 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 };
542
782
  export type { AdminRole, CreateDataOptions, DataClientOptions, DataRecord, Environment, EnvironmentConfig, FilterOperator, JWTClaims, PaginatedResponse, QueryOptions, UpdateDataOptions, Visibility };