@mitway/sdk 0.3.0 → 0.4.0

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.cts CHANGED
@@ -548,6 +548,18 @@ declare class HttpClient {
548
548
  private computeRetryDelay;
549
549
  private handleRequest;
550
550
  request<T>(method: string, path: string, options?: RequestOptions): Promise<T>;
551
+ /**
552
+ * Low-level fetch helper for binary bodies (uploads) and streamed responses
553
+ * (downloads). Applies the current Bearer token (user session → anon key
554
+ * fallback) plus any configured default headers, resolves `path` against
555
+ * `baseUrl`, and returns the raw `Response` — it does NOT unwrap the
556
+ * `{ data, error }` envelope, so the caller is responsible for status
557
+ * checking and parsing.
558
+ *
559
+ * Used by the storage module for object upload/download paths where the
560
+ * body or response is not JSON.
561
+ */
562
+ rawFetch(path: string, init?: RequestInit): Promise<Response>;
551
563
  get<T>(path: string, options?: RequestOptions): Promise<T>;
552
564
  post<T>(path: string, body?: any, options?: RequestOptions): Promise<T>;
553
565
  put<T>(path: string, body?: any, options?: RequestOptions): Promise<T>;
@@ -718,6 +730,136 @@ declare class Database {
718
730
  getUrl(): string;
719
731
  }
720
732
 
733
+ /**
734
+ * Storage types — kept in sync manually with the MITWAY-BaaS shared-schemas
735
+ * definitions at
736
+ * `MITWAY-BaaS/packages/shared-schemas/src/storage.schema.ts`.
737
+ *
738
+ * All SDK-facing fields are camelCase. The wire format is snake_case; the
739
+ * storage module maps between the two.
740
+ */
741
+ interface StorageBucket {
742
+ id: string;
743
+ name: string;
744
+ public: boolean;
745
+ fileSizeLimitBytes: number | null;
746
+ allowedMimeTypes: string[] | null;
747
+ createdAt: string;
748
+ updatedAt: string;
749
+ }
750
+ interface StorageObject {
751
+ id: string;
752
+ bucket: string;
753
+ key: string;
754
+ size: number;
755
+ mimeType: string | null;
756
+ etag: string;
757
+ cacheControl: string | null;
758
+ contentDisposition: string | null;
759
+ uploadedBy: string | null;
760
+ uploadedAt: string;
761
+ updatedAt: string;
762
+ }
763
+ interface StorageConfig {
764
+ defaultFileSizeLimitBytes: number;
765
+ maxFileSizeLimitBytes: number;
766
+ tenantStorageQuotaBytes: number;
767
+ reservedSpaceBytes: number;
768
+ signedUrlDefaultTtlSec: number;
769
+ signedUrlMaxTtlSec: number;
770
+ }
771
+ interface CreateBucketOptions {
772
+ public?: boolean;
773
+ fileSizeLimitBytes?: number | null;
774
+ allowedMimeTypes?: string[] | null;
775
+ }
776
+ interface UpdateBucketOptions {
777
+ public?: boolean;
778
+ fileSizeLimitBytes?: number | null;
779
+ allowedMimeTypes?: string[] | null;
780
+ }
781
+ interface UploadOptions {
782
+ contentType?: string;
783
+ cacheControl?: string;
784
+ contentDisposition?: string;
785
+ /** Defaults to false (POST, fails on duplicate). If true, uses PUT (upsert). */
786
+ upsert?: boolean;
787
+ abortSignal?: AbortSignal;
788
+ }
789
+ interface DownloadOptions {
790
+ range?: {
791
+ start: number;
792
+ end: number;
793
+ };
794
+ abortSignal?: AbortSignal;
795
+ }
796
+ interface ListOptions {
797
+ prefix?: string;
798
+ limit?: number;
799
+ startAfter?: string;
800
+ }
801
+ interface SignedUrlOptions {
802
+ expiresIn?: number;
803
+ }
804
+ interface SignedUrlResult {
805
+ url: string;
806
+ token: string;
807
+ expiresAt: string;
808
+ }
809
+ type UploadBody = Blob | ArrayBuffer | ArrayBufferView | ReadableStream<Uint8Array> | string;
810
+
811
+ /**
812
+ * Storage module — thin wrapper over the /api/storage/* REST endpoints
813
+ * exposed by MITWAY-BaaS.
814
+ *
815
+ * Surface mirrors what coding agents expect from a Supabase-style storage
816
+ * SDK but routes through the Mitway backend (no direct S3 calls). Binary
817
+ * upload/download uses `HttpClient.rawFetch`; JSON operations use the
818
+ * standard typed `request<T>` path.
819
+ */
820
+
821
+ type StorageResult<T> = {
822
+ data: T | null;
823
+ error: MitwayBaasError | null;
824
+ };
825
+ declare class StorageBucketClient {
826
+ private readonly http;
827
+ private readonly bucketName;
828
+ constructor(http: HttpClient, bucketName: string);
829
+ private bucketBase;
830
+ private objectPath;
831
+ upload(key: string, body: UploadBody, opts?: UploadOptions): Promise<StorageResult<StorageObject>>;
832
+ download(key: string, opts?: DownloadOptions): Promise<StorageResult<Blob>>;
833
+ getStream(key: string, opts?: DownloadOptions): Promise<StorageResult<ReadableStream<Uint8Array>>>;
834
+ remove(keys: string[]): Promise<StorageResult<{
835
+ removed: string[];
836
+ }>>;
837
+ list(opts?: ListOptions): Promise<StorageResult<StorageObject[]>>;
838
+ copy(fromKey: string, toKey: string, toBucket?: string): Promise<StorageResult<StorageObject>>;
839
+ move(fromKey: string, toKey: string, toBucket?: string): Promise<StorageResult<StorageObject>>;
840
+ createSignedUrl(key: string, opts?: SignedUrlOptions): Promise<StorageResult<SignedUrlResult>>;
841
+ getPublicUrl(key: string): {
842
+ data: {
843
+ url: string;
844
+ };
845
+ };
846
+ }
847
+ declare class Storage {
848
+ private readonly http;
849
+ constructor(http: HttpClient);
850
+ /** Scope subsequent operations to a single bucket. */
851
+ from(bucketName: string): StorageBucketClient;
852
+ listBuckets(): Promise<StorageResult<StorageBucket[]>>;
853
+ getBucket(name: string): Promise<StorageResult<StorageBucket>>;
854
+ createBucket(name: string, opts?: CreateBucketOptions): Promise<StorageResult<StorageBucket>>;
855
+ updateBucket(name: string, opts: UpdateBucketOptions): Promise<StorageResult<StorageBucket>>;
856
+ deleteBucket(name: string): Promise<StorageResult<null>>;
857
+ emptyBucket(name: string): Promise<StorageResult<{
858
+ removed: number;
859
+ }>>;
860
+ getConfig(): Promise<StorageResult<StorageConfig>>;
861
+ }
862
+
721
863
  /**
722
864
  * MITWAY-BaaS SDK client.
723
865
  *
@@ -751,6 +893,7 @@ declare class MitwayBaasClient {
751
893
  readonly auth: Auth;
752
894
  readonly database: Database;
753
895
  readonly realtime: Realtime;
896
+ readonly storage: Storage;
754
897
  constructor(config?: MitwayBaasConfig);
755
898
  /**
756
899
  * Escape hatch for callers that need to make custom requests against the
@@ -791,4 +934,4 @@ declare class MitwayBaasClient {
791
934
  */
792
935
  declare function createClient(config: MitwayBaasConfig): MitwayBaasClient;
793
936
 
794
- export { type ApiError, Auth, type AuthRefreshResponse, type AuthResponse, type AuthResult, type AuthSession, type BroadcastFilter, type BroadcastPayload, type ChannelOptions, type ChannelStatus, type ChannelStatusCallback, Database, HttpClient, Logger, MitwayBaasClient, type MitwayBaasConfig, MitwayBaasError, type PostgresChangesDeletePayload, type PostgresChangesEventSelector, type PostgresChangesFilter, type PostgresChangesInsertPayload, type PostgresChangesPayload, type PostgresChangesUpdatePayload, type PresenceEventSelector, type PresenceFilter, type PresenceJoinPayload, type PresenceLeavePayload, type PresencePayload, type PresenceState, type PresenceSyncPayload, Realtime, RealtimeChannel, type RealtimeMessageMeta, type RealtimeOptions, type SignInRequest, type SignUpRequest, TokenManager, type User, createClient, MitwayBaasClient as default };
937
+ export { type ApiError, Auth, type AuthRefreshResponse, type AuthResponse, type AuthResult, type AuthSession, type BroadcastFilter, type BroadcastPayload, type ChannelOptions, type ChannelStatus, type ChannelStatusCallback, type CreateBucketOptions, Database, type DownloadOptions, HttpClient, type ListOptions, Logger, MitwayBaasClient, type MitwayBaasConfig, MitwayBaasError, type PostgresChangesDeletePayload, type PostgresChangesEventSelector, type PostgresChangesFilter, type PostgresChangesInsertPayload, type PostgresChangesPayload, type PostgresChangesUpdatePayload, type PresenceEventSelector, type PresenceFilter, type PresenceJoinPayload, type PresenceLeavePayload, type PresencePayload, type PresenceState, type PresenceSyncPayload, Realtime, RealtimeChannel, type RealtimeMessageMeta, type RealtimeOptions, type SignInRequest, type SignUpRequest, type SignedUrlOptions, type SignedUrlResult, Storage, type StorageBucket, StorageBucketClient, type StorageConfig, type StorageObject, type StorageResult, TokenManager, type UpdateBucketOptions, type UploadBody, type UploadOptions, type User, createClient, MitwayBaasClient as default };
package/dist/index.d.ts CHANGED
@@ -548,6 +548,18 @@ declare class HttpClient {
548
548
  private computeRetryDelay;
549
549
  private handleRequest;
550
550
  request<T>(method: string, path: string, options?: RequestOptions): Promise<T>;
551
+ /**
552
+ * Low-level fetch helper for binary bodies (uploads) and streamed responses
553
+ * (downloads). Applies the current Bearer token (user session → anon key
554
+ * fallback) plus any configured default headers, resolves `path` against
555
+ * `baseUrl`, and returns the raw `Response` — it does NOT unwrap the
556
+ * `{ data, error }` envelope, so the caller is responsible for status
557
+ * checking and parsing.
558
+ *
559
+ * Used by the storage module for object upload/download paths where the
560
+ * body or response is not JSON.
561
+ */
562
+ rawFetch(path: string, init?: RequestInit): Promise<Response>;
551
563
  get<T>(path: string, options?: RequestOptions): Promise<T>;
552
564
  post<T>(path: string, body?: any, options?: RequestOptions): Promise<T>;
553
565
  put<T>(path: string, body?: any, options?: RequestOptions): Promise<T>;
@@ -718,6 +730,136 @@ declare class Database {
718
730
  getUrl(): string;
719
731
  }
720
732
 
733
+ /**
734
+ * Storage types — kept in sync manually with the MITWAY-BaaS shared-schemas
735
+ * definitions at
736
+ * `MITWAY-BaaS/packages/shared-schemas/src/storage.schema.ts`.
737
+ *
738
+ * All SDK-facing fields are camelCase. The wire format is snake_case; the
739
+ * storage module maps between the two.
740
+ */
741
+ interface StorageBucket {
742
+ id: string;
743
+ name: string;
744
+ public: boolean;
745
+ fileSizeLimitBytes: number | null;
746
+ allowedMimeTypes: string[] | null;
747
+ createdAt: string;
748
+ updatedAt: string;
749
+ }
750
+ interface StorageObject {
751
+ id: string;
752
+ bucket: string;
753
+ key: string;
754
+ size: number;
755
+ mimeType: string | null;
756
+ etag: string;
757
+ cacheControl: string | null;
758
+ contentDisposition: string | null;
759
+ uploadedBy: string | null;
760
+ uploadedAt: string;
761
+ updatedAt: string;
762
+ }
763
+ interface StorageConfig {
764
+ defaultFileSizeLimitBytes: number;
765
+ maxFileSizeLimitBytes: number;
766
+ tenantStorageQuotaBytes: number;
767
+ reservedSpaceBytes: number;
768
+ signedUrlDefaultTtlSec: number;
769
+ signedUrlMaxTtlSec: number;
770
+ }
771
+ interface CreateBucketOptions {
772
+ public?: boolean;
773
+ fileSizeLimitBytes?: number | null;
774
+ allowedMimeTypes?: string[] | null;
775
+ }
776
+ interface UpdateBucketOptions {
777
+ public?: boolean;
778
+ fileSizeLimitBytes?: number | null;
779
+ allowedMimeTypes?: string[] | null;
780
+ }
781
+ interface UploadOptions {
782
+ contentType?: string;
783
+ cacheControl?: string;
784
+ contentDisposition?: string;
785
+ /** Defaults to false (POST, fails on duplicate). If true, uses PUT (upsert). */
786
+ upsert?: boolean;
787
+ abortSignal?: AbortSignal;
788
+ }
789
+ interface DownloadOptions {
790
+ range?: {
791
+ start: number;
792
+ end: number;
793
+ };
794
+ abortSignal?: AbortSignal;
795
+ }
796
+ interface ListOptions {
797
+ prefix?: string;
798
+ limit?: number;
799
+ startAfter?: string;
800
+ }
801
+ interface SignedUrlOptions {
802
+ expiresIn?: number;
803
+ }
804
+ interface SignedUrlResult {
805
+ url: string;
806
+ token: string;
807
+ expiresAt: string;
808
+ }
809
+ type UploadBody = Blob | ArrayBuffer | ArrayBufferView | ReadableStream<Uint8Array> | string;
810
+
811
+ /**
812
+ * Storage module — thin wrapper over the /api/storage/* REST endpoints
813
+ * exposed by MITWAY-BaaS.
814
+ *
815
+ * Surface mirrors what coding agents expect from a Supabase-style storage
816
+ * SDK but routes through the Mitway backend (no direct S3 calls). Binary
817
+ * upload/download uses `HttpClient.rawFetch`; JSON operations use the
818
+ * standard typed `request<T>` path.
819
+ */
820
+
821
+ type StorageResult<T> = {
822
+ data: T | null;
823
+ error: MitwayBaasError | null;
824
+ };
825
+ declare class StorageBucketClient {
826
+ private readonly http;
827
+ private readonly bucketName;
828
+ constructor(http: HttpClient, bucketName: string);
829
+ private bucketBase;
830
+ private objectPath;
831
+ upload(key: string, body: UploadBody, opts?: UploadOptions): Promise<StorageResult<StorageObject>>;
832
+ download(key: string, opts?: DownloadOptions): Promise<StorageResult<Blob>>;
833
+ getStream(key: string, opts?: DownloadOptions): Promise<StorageResult<ReadableStream<Uint8Array>>>;
834
+ remove(keys: string[]): Promise<StorageResult<{
835
+ removed: string[];
836
+ }>>;
837
+ list(opts?: ListOptions): Promise<StorageResult<StorageObject[]>>;
838
+ copy(fromKey: string, toKey: string, toBucket?: string): Promise<StorageResult<StorageObject>>;
839
+ move(fromKey: string, toKey: string, toBucket?: string): Promise<StorageResult<StorageObject>>;
840
+ createSignedUrl(key: string, opts?: SignedUrlOptions): Promise<StorageResult<SignedUrlResult>>;
841
+ getPublicUrl(key: string): {
842
+ data: {
843
+ url: string;
844
+ };
845
+ };
846
+ }
847
+ declare class Storage {
848
+ private readonly http;
849
+ constructor(http: HttpClient);
850
+ /** Scope subsequent operations to a single bucket. */
851
+ from(bucketName: string): StorageBucketClient;
852
+ listBuckets(): Promise<StorageResult<StorageBucket[]>>;
853
+ getBucket(name: string): Promise<StorageResult<StorageBucket>>;
854
+ createBucket(name: string, opts?: CreateBucketOptions): Promise<StorageResult<StorageBucket>>;
855
+ updateBucket(name: string, opts: UpdateBucketOptions): Promise<StorageResult<StorageBucket>>;
856
+ deleteBucket(name: string): Promise<StorageResult<null>>;
857
+ emptyBucket(name: string): Promise<StorageResult<{
858
+ removed: number;
859
+ }>>;
860
+ getConfig(): Promise<StorageResult<StorageConfig>>;
861
+ }
862
+
721
863
  /**
722
864
  * MITWAY-BaaS SDK client.
723
865
  *
@@ -751,6 +893,7 @@ declare class MitwayBaasClient {
751
893
  readonly auth: Auth;
752
894
  readonly database: Database;
753
895
  readonly realtime: Realtime;
896
+ readonly storage: Storage;
754
897
  constructor(config?: MitwayBaasConfig);
755
898
  /**
756
899
  * Escape hatch for callers that need to make custom requests against the
@@ -791,4 +934,4 @@ declare class MitwayBaasClient {
791
934
  */
792
935
  declare function createClient(config: MitwayBaasConfig): MitwayBaasClient;
793
936
 
794
- export { type ApiError, Auth, type AuthRefreshResponse, type AuthResponse, type AuthResult, type AuthSession, type BroadcastFilter, type BroadcastPayload, type ChannelOptions, type ChannelStatus, type ChannelStatusCallback, Database, HttpClient, Logger, MitwayBaasClient, type MitwayBaasConfig, MitwayBaasError, type PostgresChangesDeletePayload, type PostgresChangesEventSelector, type PostgresChangesFilter, type PostgresChangesInsertPayload, type PostgresChangesPayload, type PostgresChangesUpdatePayload, type PresenceEventSelector, type PresenceFilter, type PresenceJoinPayload, type PresenceLeavePayload, type PresencePayload, type PresenceState, type PresenceSyncPayload, Realtime, RealtimeChannel, type RealtimeMessageMeta, type RealtimeOptions, type SignInRequest, type SignUpRequest, TokenManager, type User, createClient, MitwayBaasClient as default };
937
+ export { type ApiError, Auth, type AuthRefreshResponse, type AuthResponse, type AuthResult, type AuthSession, type BroadcastFilter, type BroadcastPayload, type ChannelOptions, type ChannelStatus, type ChannelStatusCallback, type CreateBucketOptions, Database, type DownloadOptions, HttpClient, type ListOptions, Logger, MitwayBaasClient, type MitwayBaasConfig, MitwayBaasError, type PostgresChangesDeletePayload, type PostgresChangesEventSelector, type PostgresChangesFilter, type PostgresChangesInsertPayload, type PostgresChangesPayload, type PostgresChangesUpdatePayload, type PresenceEventSelector, type PresenceFilter, type PresenceJoinPayload, type PresenceLeavePayload, type PresencePayload, type PresenceState, type PresenceSyncPayload, Realtime, RealtimeChannel, type RealtimeMessageMeta, type RealtimeOptions, type SignInRequest, type SignUpRequest, type SignedUrlOptions, type SignedUrlResult, Storage, type StorageBucket, StorageBucketClient, type StorageConfig, type StorageObject, type StorageResult, TokenManager, type UpdateBucketOptions, type UploadBody, type UploadOptions, type User, createClient, MitwayBaasClient as default };