@cloudbase/js-sdk 3.1.6 → 3.1.8

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # 更新日志
2
2
 
3
+ ## [3.1.8] 2026-03-12
4
+ - [Fixed] 增加 storage 类型定义
5
+
6
+ ## [3.1.7] 2026-03-12
7
+ - [Fixed] getVerification 增加 phone_number 参数格式化
8
+
3
9
  ## [3.1.6] 2026-03-12
4
10
  - [Added] signInWithOtp 增加可选参数 options.shouldCreateUser 控制是否自动注册用户
5
11
 
@@ -40,6 +46,9 @@
40
46
  ## [3.0.0] 2026-02-10
41
47
  - [Changed] endPointMode 默认启用 GATEWAY 模式
42
48
 
49
+ ## [2.26.1] 2026-03-12
50
+ - [Fixed] getVerification 增加 phone_number 参数格式化
51
+
43
52
  ## [2.26.0] 2026-03-12
44
53
  - [Added] signInWithOtp 增加可选参数 options.shouldCreateUser 控制是否自动注册用户
45
54
 
package/dist/index.cjs.js CHANGED
@@ -14,7 +14,7 @@ var cloudrun_1 = require("@cloudbase/cloudrun");
14
14
  var mysql_1 = require("@cloudbase/mysql");
15
15
  var apis_1 = require("@cloudbase/apis");
16
16
  var database_1 = require("./../database");
17
- var version = "3.1.6";
17
+ var version = "3.1.8";
18
18
  app_1.default.registerVersion(version);
19
19
  try {
20
20
  (0, auth_1.registerAuth)(app_1.default);
package/dist/index.esm.js CHANGED
@@ -10,7 +10,7 @@ import { registerCloudrun } from '@cloudbase/cloudrun';
10
10
  import { registerMySQL } from '@cloudbase/mysql';
11
11
  import { registerApis } from '@cloudbase/apis';
12
12
  import { registerDatabase } from './../database';
13
- var version = "3.1.6";
13
+ var version = "3.1.8";
14
14
  cloudbase.registerVersion(version);
15
15
  try {
16
16
  registerAuth(cloudbase);
package/index.d.ts CHANGED
@@ -512,8 +512,7 @@ declare namespace cloudbase.app {
512
512
 
513
513
  getFileInfo(
514
514
  params: cloudbase.storage.ICloudbaseGetTempFileURLParams,
515
- callback?: Function,
516
- ): Promise<cloudbase.storage.ICloudbaseGetTempFileURLResult>
515
+ ): Promise<cloudbase.storage.ICloudbaseGetFileInfoResult>
517
516
  /**
518
517
  * 云存储-获取上传元信息
519
518
  *
@@ -522,6 +521,17 @@ declare namespace cloudbase.app {
522
521
  * @param callback
523
522
  */
524
523
  getUploadMetadata(params: cloudbase.storage.ICloudbaseGetUploadMetadataParams, callback?: Function): Promise<any>
524
+
525
+ /**
526
+ * Supabase 风格的文件存储 API
527
+ *
528
+ * @example
529
+ * ```typescript
530
+ * const bucket = app.storage.from('my-bucket')
531
+ * const { data, error } = await bucket.upload('path/to/file.jpg', file)
532
+ * ```
533
+ */
534
+ storage: cloudbase.storage.SupabaseFileAPILikeStorage
525
535
  /**
526
536
  * 获取数据库实例
527
537
  *
@@ -1428,6 +1438,365 @@ declare namespace cloudbase.storage {
1428
1438
  }>
1429
1439
  requestId?: string
1430
1440
  }
1441
+
1442
+ interface ICloudbaseGetFileInfoResultItem {
1443
+ code?: string
1444
+ message?: string
1445
+ fileID: string
1446
+ tempFileURL: string
1447
+ fileName?: string
1448
+ cloudId?: string
1449
+ contentType?: string
1450
+ mime?: string
1451
+ size?: number
1452
+ cacheControl?: string
1453
+ lastModified?: string
1454
+ etag?: string
1455
+ }
1456
+
1457
+ interface ICloudbaseGetFileInfoResult {
1458
+ fileList: ICloudbaseGetFileInfoResultItem[]
1459
+ requestId: string
1460
+ }
1461
+
1462
+ // ---- Supabase-like Storage Types ----
1463
+
1464
+ type FileBody =
1465
+ | ArrayBuffer
1466
+ | ArrayBufferView
1467
+ | Blob
1468
+ | Buffer
1469
+ | File
1470
+ | FormData
1471
+ | NodeJS.ReadableStream
1472
+ | ReadableStream<Uint8Array>
1473
+ | URLSearchParams
1474
+ | string
1475
+
1476
+ interface FileOptions {
1477
+ cacheControl?: string
1478
+ contentType?: string
1479
+ upsert?: boolean
1480
+ duplex?: string
1481
+ metadata?: Record<string, any>
1482
+ headers?: Record<string, string>
1483
+ }
1484
+
1485
+ interface TransformOptions {
1486
+ width?: number
1487
+ height?: number
1488
+ resize?: 'cover' | 'contain' | 'fill'
1489
+ quality?: number
1490
+ format?: 'origin'
1491
+ }
1492
+
1493
+ interface FileObject {
1494
+ name: string
1495
+ bucket_id: string
1496
+ owner: string
1497
+ id: string
1498
+ updated_at: string
1499
+ created_at: string
1500
+ /** @deprecated */
1501
+ last_accessed_at: string
1502
+ metadata: Record<string, any>
1503
+ buckets: {
1504
+ id: string
1505
+ name: string
1506
+ owner: string
1507
+ public: boolean
1508
+ created_at: string
1509
+ updated_at: string
1510
+ }
1511
+ }
1512
+
1513
+ interface FileObjectV2 {
1514
+ id: string
1515
+ version: string
1516
+ name: string
1517
+ bucketId: string
1518
+ updatedAt: string
1519
+ createdAt: string
1520
+ /** @deprecated */
1521
+ lastAccessedAt: string
1522
+ size?: number
1523
+ cacheControl?: string
1524
+ contentType?: string
1525
+ etag?: string
1526
+ lastModified?: string
1527
+ metadata?: Record<string, any>
1528
+ }
1529
+
1530
+ class StorageError extends Error {
1531
+ name: 'StorageError'
1532
+ constructor(message: string)
1533
+ }
1534
+
1535
+ /**
1536
+ * Supabase 风格的文件存储 API
1537
+ *
1538
+ * 通过 `app.storage` 获取实例,提供类似 Supabase Storage 的操作接口。
1539
+ *
1540
+ * @example
1541
+ * ```typescript
1542
+ * const app = cloudbase.init({ env: 'your-envid' })
1543
+ * const bucket = app.storage.from('my-bucket')
1544
+ *
1545
+ * // 上传文件
1546
+ * const { data, error } = await bucket.upload('path/to/file.jpg', file)
1547
+ *
1548
+ * // 获取签名 URL
1549
+ * const { data } = await bucket.createSignedUrl('path/to/file.jpg', 3600)
1550
+ *
1551
+ * // 下载文件
1552
+ * const { data } = await bucket.download('path/to/file.jpg')
1553
+ * ```
1554
+ */
1555
+ interface SupabaseFileAPILikeStorage {
1556
+ /**
1557
+ * 启用错误抛出模式,而非返回 `{ data: null, error }` 格式
1558
+ */
1559
+ throwOnError(): this
1560
+
1561
+ /**
1562
+ * 选择存储桶
1563
+ *
1564
+ * @param bucket 存储桶名称
1565
+ * @returns 当前实例(链式调用)
1566
+ *
1567
+ * @example
1568
+ * ```typescript
1569
+ * const bucket = app.storage.from('my-bucket')
1570
+ * ```
1571
+ */
1572
+ from(bucket?: string): this
1573
+
1574
+ /**
1575
+ * 上传文件
1576
+ *
1577
+ * @param path 文件路径
1578
+ * @param fileBody 文件内容
1579
+ * @param fileOptions 上传选项
1580
+ */
1581
+ upload(
1582
+ path: string,
1583
+ fileBody: FileBody,
1584
+ fileOptions?: FileOptions,
1585
+ ): Promise<
1586
+ | { data: { id: string; path: string; fullPath: string }; error: null }
1587
+ | { data: null; error: StorageError }
1588
+ >
1589
+
1590
+ /**
1591
+ * 上传文件到已签名的 URL
1592
+ *
1593
+ * @param path 文件路径
1594
+ * @param token 签名 Token
1595
+ * @param fileBody 文件内容
1596
+ * @param fileOptions 上传选项
1597
+ */
1598
+ uploadToSignedUrl(
1599
+ path: string,
1600
+ token: string,
1601
+ fileBody: FileBody,
1602
+ fileOptions?: FileOptions,
1603
+ ): Promise<
1604
+ | { data: { id: string; path: string; fullPath: string }; error: null }
1605
+ | { data: null; error: StorageError }
1606
+ >
1607
+
1608
+ /**
1609
+ * 创建用于上传的签名 URL
1610
+ *
1611
+ * @param path 文件路径
1612
+ */
1613
+ createSignedUploadUrl(path: string): Promise<
1614
+ | {
1615
+ data: {
1616
+ signedUrl: string
1617
+ token: string
1618
+ path: string
1619
+ authorization?: string
1620
+ id?: string
1621
+ cosFileId?: string
1622
+ downloadUrl?: string
1623
+ }
1624
+ error: null
1625
+ }
1626
+ | { data: null; error: StorageError }
1627
+ >
1628
+
1629
+ /**
1630
+ * 更新(覆盖)文件
1631
+ *
1632
+ * @param path 文件路径
1633
+ * @param fileBody 文件内容
1634
+ * @param fileOptions 上传选项
1635
+ */
1636
+ update(
1637
+ path: string,
1638
+ fileBody: FileBody,
1639
+ fileOptions?: FileOptions,
1640
+ ): Promise<
1641
+ | { data: { id: string; path: string; fullPath: string }; error: null }
1642
+ | { data: null; error: StorageError }
1643
+ >
1644
+
1645
+ /**
1646
+ * 移动文件(复制后删除源文件)
1647
+ *
1648
+ * @param fromPath 源文件路径
1649
+ * @param toPath 目标文件路径
1650
+ */
1651
+ move(
1652
+ fromPath: string,
1653
+ toPath: string,
1654
+ ): Promise<
1655
+ | { data: { message: string }; error: null }
1656
+ | { data: null; error: StorageError }
1657
+ >
1658
+
1659
+ /**
1660
+ * 复制文件
1661
+ *
1662
+ * @param fromPath 源文件路径
1663
+ * @param toPath 目标文件路径
1664
+ */
1665
+ copy(
1666
+ fromPath: string,
1667
+ toPath: string,
1668
+ ): Promise<
1669
+ | { data: { path: string }; error: null }
1670
+ | { data: null; error: StorageError }
1671
+ >
1672
+
1673
+ /**
1674
+ * 创建签名下载 URL
1675
+ *
1676
+ * @param path 文件路径
1677
+ * @param expiresIn 有效期(秒)
1678
+ * @param options 可选配置
1679
+ */
1680
+ createSignedUrl(
1681
+ path: string,
1682
+ expiresIn: number,
1683
+ options?: {
1684
+ download?: string | boolean
1685
+ transform?: TransformOptions
1686
+ },
1687
+ ): Promise<
1688
+ | { data: { signedUrl: string }; error: null }
1689
+ | { data: null; error: StorageError }
1690
+ >
1691
+
1692
+ /**
1693
+ * 批量创建签名下载 URL
1694
+ *
1695
+ * @param paths 文件路径数组
1696
+ * @param expiresIn 有效期(秒)
1697
+ */
1698
+ createSignedUrls(
1699
+ paths: string[],
1700
+ expiresIn: number,
1701
+ ): Promise<
1702
+ | { data: Array<{ path: string; signedUrl: string; error: string | null }>; error: null }
1703
+ | { data: null; error: StorageError }
1704
+ >
1705
+
1706
+ /**
1707
+ * 下载文件,返回 Blob
1708
+ *
1709
+ * @param path 文件路径
1710
+ * @param options 图片转换选项
1711
+ */
1712
+ download(
1713
+ path: string,
1714
+ options?: TransformOptions,
1715
+ ): Promise<{ data: Blob; error: StorageError | null }>
1716
+
1717
+ /**
1718
+ * 获取文件详细信息
1719
+ *
1720
+ * @param pathOrFileId 相对路径或 CloudBase fileID
1721
+ */
1722
+ info(pathOrFileId: string): Promise<
1723
+ | { data: FileObjectV2; error: null }
1724
+ | { data: null; error: StorageError }
1725
+ >
1726
+
1727
+ /**
1728
+ * 检查文件是否存在
1729
+ *
1730
+ * @param pathOrFileId 相对路径或 CloudBase fileID
1731
+ */
1732
+ exists(pathOrFileId: string): Promise<
1733
+ | { data: boolean; error: null }
1734
+ | { data: null; error: StorageError }
1735
+ >
1736
+
1737
+ /**
1738
+ * 获取文件的公开 URL
1739
+ *
1740
+ * @param path 文件路径
1741
+ * @param options 可选配置
1742
+ */
1743
+ getPublicUrl(
1744
+ path: string,
1745
+ options?: {
1746
+ download?: string | boolean
1747
+ transform?: TransformOptions
1748
+ },
1749
+ ): Promise<
1750
+ | { data: { publicUrl: string } }
1751
+ | { data: null; error: StorageError }
1752
+ >
1753
+
1754
+ /**
1755
+ * 批量删除文件
1756
+ *
1757
+ * @param paths 文件路径数组
1758
+ */
1759
+ remove(paths: string[]): Promise<
1760
+ | { data: FileObject[]; error: null }
1761
+ | { data: null; error: StorageError }
1762
+ >
1763
+
1764
+ // ---- 继承自 CloudbaseStorage 的方法 ----
1765
+
1766
+ uploadFile(
1767
+ params: ICloudbaseUploadFileParams,
1768
+ callback?: Function,
1769
+ ): Promise<ICloudbaseUploadFileResult>
1770
+
1771
+ deleteFile(
1772
+ params: ICloudbaseDeleteFileParams,
1773
+ callback?: Function,
1774
+ ): Promise<ICloudbaseDeleteFileResult>
1775
+
1776
+ getTempFileURL(
1777
+ params: ICloudbaseGetTempFileURLParams,
1778
+ callback?: Function,
1779
+ ): Promise<ICloudbaseGetTempFileURLResult>
1780
+
1781
+ downloadFile(
1782
+ params: ICloudbaseDownloadFileParams,
1783
+ callback?: Function,
1784
+ ): Promise<ICloudbaseDownloadFileResult>
1785
+
1786
+ getUploadMetadata(
1787
+ params: ICloudbaseGetUploadMetadataParams,
1788
+ callback?: Function,
1789
+ ): Promise<ICloudbaseFileMetaDataRes>
1790
+
1791
+ copyFile(
1792
+ params: ICloudbaseCopyFileParams,
1793
+ callback?: Function,
1794
+ ): Promise<ICloudbaseCopyFileResult>
1795
+
1796
+ getFileInfo(
1797
+ params: ICloudbaseGetTempFileURLParams,
1798
+ ): Promise<ICloudbaseGetFileInfoResult>
1799
+ }
1431
1800
  }
1432
1801
 
1433
1802
  declare namespace cloudbase.database {