@mitway/sdk 0.3.0 → 0.5.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/README.md +16 -0
- package/dist/index.cjs +530 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +196 -3
- package/dist/index.d.ts +196 -3
- package/dist/index.js +528 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -33,22 +33,42 @@ interface User {
|
|
|
33
33
|
/**
|
|
34
34
|
* Token Manager for the MITWAY-BaaS SDK.
|
|
35
35
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
36
|
+
* Stores the access token + user in memory and optionally persists them
|
|
37
|
+
* to `localStorage` so sessions survive page reloads (F5). Browser CSRF
|
|
38
|
+
* token lives in a cookie for the cookie-based refresh flow.
|
|
38
39
|
*/
|
|
39
40
|
|
|
41
|
+
interface TokenManagerOptions {
|
|
42
|
+
/** Persist session to localStorage so it survives page reloads. Default: true. */
|
|
43
|
+
persistSession?: boolean;
|
|
44
|
+
/** localStorage key. Default: 'mitway_baas_session'. */
|
|
45
|
+
storageKey?: string;
|
|
46
|
+
}
|
|
40
47
|
declare class TokenManager {
|
|
41
48
|
private accessToken;
|
|
49
|
+
private refreshToken;
|
|
42
50
|
private user;
|
|
51
|
+
private readonly persistSession;
|
|
52
|
+
private readonly storageKey;
|
|
43
53
|
/** Fired when the access token changes (used by long-lived consumers). */
|
|
44
54
|
onTokenChange: (() => void) | null;
|
|
55
|
+
constructor(opts?: TokenManagerOptions);
|
|
45
56
|
saveSession(session: AuthSession): void;
|
|
46
57
|
getSession(): AuthSession | null;
|
|
47
58
|
getAccessToken(): string | null;
|
|
48
59
|
setAccessToken(token: string): void;
|
|
60
|
+
getRefreshToken(): string | null;
|
|
61
|
+
setRefreshToken(token: string | null): void;
|
|
49
62
|
getUser(): User | null;
|
|
50
63
|
setUser(user: User): void;
|
|
51
64
|
clearSession(): void;
|
|
65
|
+
/**
|
|
66
|
+
* Restore the session from localStorage. Returns true if a persisted
|
|
67
|
+
* session was found and loaded into memory.
|
|
68
|
+
*/
|
|
69
|
+
restoreSession(): boolean;
|
|
70
|
+
private persist;
|
|
71
|
+
private removePersisted;
|
|
52
72
|
}
|
|
53
73
|
|
|
54
74
|
/**
|
|
@@ -451,6 +471,18 @@ interface MitwayBaasConfig {
|
|
|
451
471
|
* Realtime transport options. See `RealtimeOptions`.
|
|
452
472
|
*/
|
|
453
473
|
realtime?: RealtimeOptions;
|
|
474
|
+
/**
|
|
475
|
+
* Persist the auth session to `localStorage` so it survives page reloads.
|
|
476
|
+
* Set to `false` for SSR / Node.js environments where `localStorage` is
|
|
477
|
+
* not available.
|
|
478
|
+
* @default true
|
|
479
|
+
*/
|
|
480
|
+
persistSession?: boolean;
|
|
481
|
+
/**
|
|
482
|
+
* `localStorage` key used to persist the session.
|
|
483
|
+
* @default "mitway_baas_session"
|
|
484
|
+
*/
|
|
485
|
+
storageKey?: string;
|
|
454
486
|
}
|
|
455
487
|
/**
|
|
456
488
|
* Active user session in memory. Mirrors what the auth endpoints return.
|
|
@@ -458,6 +490,7 @@ interface MitwayBaasConfig {
|
|
|
458
490
|
interface AuthSession {
|
|
459
491
|
user: User;
|
|
460
492
|
accessToken: string;
|
|
493
|
+
refreshToken?: string;
|
|
461
494
|
expiresAt?: Date;
|
|
462
495
|
}
|
|
463
496
|
/**
|
|
@@ -548,6 +581,18 @@ declare class HttpClient {
|
|
|
548
581
|
private computeRetryDelay;
|
|
549
582
|
private handleRequest;
|
|
550
583
|
request<T>(method: string, path: string, options?: RequestOptions): Promise<T>;
|
|
584
|
+
/**
|
|
585
|
+
* Low-level fetch helper for binary bodies (uploads) and streamed responses
|
|
586
|
+
* (downloads). Applies the current Bearer token (user session → anon key
|
|
587
|
+
* fallback) plus any configured default headers, resolves `path` against
|
|
588
|
+
* `baseUrl`, and returns the raw `Response` — it does NOT unwrap the
|
|
589
|
+
* `{ data, error }` envelope, so the caller is responsible for status
|
|
590
|
+
* checking and parsing.
|
|
591
|
+
*
|
|
592
|
+
* Used by the storage module for object upload/download paths where the
|
|
593
|
+
* body or response is not JSON.
|
|
594
|
+
*/
|
|
595
|
+
rawFetch(path: string, init?: RequestInit): Promise<Response>;
|
|
551
596
|
get<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
552
597
|
post<T>(path: string, body?: any, options?: RequestOptions): Promise<T>;
|
|
553
598
|
put<T>(path: string, body?: any, options?: RequestOptions): Promise<T>;
|
|
@@ -642,6 +687,23 @@ declare class Auth {
|
|
|
642
687
|
* not need to call it directly.
|
|
643
688
|
*/
|
|
644
689
|
refreshSession(): Promise<AuthResult<AuthResponse>>;
|
|
690
|
+
/**
|
|
691
|
+
* Restore the session from localStorage and validate it with the backend.
|
|
692
|
+
* Call this once on app startup (e.g. in a React AuthProvider useEffect).
|
|
693
|
+
*
|
|
694
|
+
* Flow:
|
|
695
|
+
* 1. Read persisted session from localStorage.
|
|
696
|
+
* 2. Populate in-memory state (TokenManager + HttpClient).
|
|
697
|
+
* 3. Validate with `GET /api/auth/sessions/current`.
|
|
698
|
+
* - If the access token expired, the HttpClient auto-refresh kicks in
|
|
699
|
+
* using the persisted refresh token (sent in the POST body, not
|
|
700
|
+
* cookies — works cross-site).
|
|
701
|
+
* 4. Return the validated user or an error.
|
|
702
|
+
*
|
|
703
|
+
* If no persisted session exists, returns `{ data: null, error }` — the
|
|
704
|
+
* app should show the login page.
|
|
705
|
+
*/
|
|
706
|
+
initialize(): Promise<AuthResult<AuthResponse>>;
|
|
645
707
|
/**
|
|
646
708
|
* Get the current in-memory session, or null if the user is not signed in.
|
|
647
709
|
* Synchronous — does not hit the network.
|
|
@@ -718,6 +780,136 @@ declare class Database {
|
|
|
718
780
|
getUrl(): string;
|
|
719
781
|
}
|
|
720
782
|
|
|
783
|
+
/**
|
|
784
|
+
* Storage types — kept in sync manually with the MITWAY-BaaS shared-schemas
|
|
785
|
+
* definitions at
|
|
786
|
+
* `MITWAY-BaaS/packages/shared-schemas/src/storage.schema.ts`.
|
|
787
|
+
*
|
|
788
|
+
* All SDK-facing fields are camelCase. The wire format is snake_case; the
|
|
789
|
+
* storage module maps between the two.
|
|
790
|
+
*/
|
|
791
|
+
interface StorageBucket {
|
|
792
|
+
id: string;
|
|
793
|
+
name: string;
|
|
794
|
+
public: boolean;
|
|
795
|
+
fileSizeLimitBytes: number | null;
|
|
796
|
+
allowedMimeTypes: string[] | null;
|
|
797
|
+
createdAt: string;
|
|
798
|
+
updatedAt: string;
|
|
799
|
+
}
|
|
800
|
+
interface StorageObject {
|
|
801
|
+
id: string;
|
|
802
|
+
bucket: string;
|
|
803
|
+
key: string;
|
|
804
|
+
size: number;
|
|
805
|
+
mimeType: string | null;
|
|
806
|
+
etag: string;
|
|
807
|
+
cacheControl: string | null;
|
|
808
|
+
contentDisposition: string | null;
|
|
809
|
+
uploadedBy: string | null;
|
|
810
|
+
uploadedAt: string;
|
|
811
|
+
updatedAt: string;
|
|
812
|
+
}
|
|
813
|
+
interface StorageConfig {
|
|
814
|
+
defaultFileSizeLimitBytes: number;
|
|
815
|
+
maxFileSizeLimitBytes: number;
|
|
816
|
+
tenantStorageQuotaBytes: number;
|
|
817
|
+
reservedSpaceBytes: number;
|
|
818
|
+
signedUrlDefaultTtlSec: number;
|
|
819
|
+
signedUrlMaxTtlSec: number;
|
|
820
|
+
}
|
|
821
|
+
interface CreateBucketOptions {
|
|
822
|
+
public?: boolean;
|
|
823
|
+
fileSizeLimitBytes?: number | null;
|
|
824
|
+
allowedMimeTypes?: string[] | null;
|
|
825
|
+
}
|
|
826
|
+
interface UpdateBucketOptions {
|
|
827
|
+
public?: boolean;
|
|
828
|
+
fileSizeLimitBytes?: number | null;
|
|
829
|
+
allowedMimeTypes?: string[] | null;
|
|
830
|
+
}
|
|
831
|
+
interface UploadOptions {
|
|
832
|
+
contentType?: string;
|
|
833
|
+
cacheControl?: string;
|
|
834
|
+
contentDisposition?: string;
|
|
835
|
+
/** Defaults to false (POST, fails on duplicate). If true, uses PUT (upsert). */
|
|
836
|
+
upsert?: boolean;
|
|
837
|
+
abortSignal?: AbortSignal;
|
|
838
|
+
}
|
|
839
|
+
interface DownloadOptions {
|
|
840
|
+
range?: {
|
|
841
|
+
start: number;
|
|
842
|
+
end: number;
|
|
843
|
+
};
|
|
844
|
+
abortSignal?: AbortSignal;
|
|
845
|
+
}
|
|
846
|
+
interface ListOptions {
|
|
847
|
+
prefix?: string;
|
|
848
|
+
limit?: number;
|
|
849
|
+
startAfter?: string;
|
|
850
|
+
}
|
|
851
|
+
interface SignedUrlOptions {
|
|
852
|
+
expiresIn?: number;
|
|
853
|
+
}
|
|
854
|
+
interface SignedUrlResult {
|
|
855
|
+
url: string;
|
|
856
|
+
token: string;
|
|
857
|
+
expiresAt: string;
|
|
858
|
+
}
|
|
859
|
+
type UploadBody = Blob | ArrayBuffer | ArrayBufferView | ReadableStream<Uint8Array> | string;
|
|
860
|
+
|
|
861
|
+
/**
|
|
862
|
+
* Storage module — thin wrapper over the /api/storage/* REST endpoints
|
|
863
|
+
* exposed by MITWAY-BaaS.
|
|
864
|
+
*
|
|
865
|
+
* Surface mirrors what coding agents expect from a Supabase-style storage
|
|
866
|
+
* SDK but routes through the Mitway backend (no direct S3 calls). Binary
|
|
867
|
+
* upload/download uses `HttpClient.rawFetch`; JSON operations use the
|
|
868
|
+
* standard typed `request<T>` path.
|
|
869
|
+
*/
|
|
870
|
+
|
|
871
|
+
type StorageResult<T> = {
|
|
872
|
+
data: T | null;
|
|
873
|
+
error: MitwayBaasError | null;
|
|
874
|
+
};
|
|
875
|
+
declare class StorageBucketClient {
|
|
876
|
+
private readonly http;
|
|
877
|
+
private readonly bucketName;
|
|
878
|
+
constructor(http: HttpClient, bucketName: string);
|
|
879
|
+
private bucketBase;
|
|
880
|
+
private objectPath;
|
|
881
|
+
upload(key: string, body: UploadBody, opts?: UploadOptions): Promise<StorageResult<StorageObject>>;
|
|
882
|
+
download(key: string, opts?: DownloadOptions): Promise<StorageResult<Blob>>;
|
|
883
|
+
getStream(key: string, opts?: DownloadOptions): Promise<StorageResult<ReadableStream<Uint8Array>>>;
|
|
884
|
+
remove(keys: string[]): Promise<StorageResult<{
|
|
885
|
+
removed: string[];
|
|
886
|
+
}>>;
|
|
887
|
+
list(opts?: ListOptions): Promise<StorageResult<StorageObject[]>>;
|
|
888
|
+
copy(fromKey: string, toKey: string, toBucket?: string): Promise<StorageResult<StorageObject>>;
|
|
889
|
+
move(fromKey: string, toKey: string, toBucket?: string): Promise<StorageResult<StorageObject>>;
|
|
890
|
+
createSignedUrl(key: string, opts?: SignedUrlOptions): Promise<StorageResult<SignedUrlResult>>;
|
|
891
|
+
getPublicUrl(key: string): {
|
|
892
|
+
data: {
|
|
893
|
+
url: string;
|
|
894
|
+
};
|
|
895
|
+
};
|
|
896
|
+
}
|
|
897
|
+
declare class Storage {
|
|
898
|
+
private readonly http;
|
|
899
|
+
constructor(http: HttpClient);
|
|
900
|
+
/** Scope subsequent operations to a single bucket. */
|
|
901
|
+
from(bucketName: string): StorageBucketClient;
|
|
902
|
+
listBuckets(): Promise<StorageResult<StorageBucket[]>>;
|
|
903
|
+
getBucket(name: string): Promise<StorageResult<StorageBucket>>;
|
|
904
|
+
createBucket(name: string, opts?: CreateBucketOptions): Promise<StorageResult<StorageBucket>>;
|
|
905
|
+
updateBucket(name: string, opts: UpdateBucketOptions): Promise<StorageResult<StorageBucket>>;
|
|
906
|
+
deleteBucket(name: string): Promise<StorageResult<null>>;
|
|
907
|
+
emptyBucket(name: string): Promise<StorageResult<{
|
|
908
|
+
removed: number;
|
|
909
|
+
}>>;
|
|
910
|
+
getConfig(): Promise<StorageResult<StorageConfig>>;
|
|
911
|
+
}
|
|
912
|
+
|
|
721
913
|
/**
|
|
722
914
|
* MITWAY-BaaS SDK client.
|
|
723
915
|
*
|
|
@@ -751,6 +943,7 @@ declare class MitwayBaasClient {
|
|
|
751
943
|
readonly auth: Auth;
|
|
752
944
|
readonly database: Database;
|
|
753
945
|
readonly realtime: Realtime;
|
|
946
|
+
readonly storage: Storage;
|
|
754
947
|
constructor(config?: MitwayBaasConfig);
|
|
755
948
|
/**
|
|
756
949
|
* Escape hatch for callers that need to make custom requests against the
|
|
@@ -791,4 +984,4 @@ declare class MitwayBaasClient {
|
|
|
791
984
|
*/
|
|
792
985
|
declare function createClient(config: MitwayBaasConfig): MitwayBaasClient;
|
|
793
986
|
|
|
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 };
|
|
987
|
+
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
|
@@ -33,22 +33,42 @@ interface User {
|
|
|
33
33
|
/**
|
|
34
34
|
* Token Manager for the MITWAY-BaaS SDK.
|
|
35
35
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
36
|
+
* Stores the access token + user in memory and optionally persists them
|
|
37
|
+
* to `localStorage` so sessions survive page reloads (F5). Browser CSRF
|
|
38
|
+
* token lives in a cookie for the cookie-based refresh flow.
|
|
38
39
|
*/
|
|
39
40
|
|
|
41
|
+
interface TokenManagerOptions {
|
|
42
|
+
/** Persist session to localStorage so it survives page reloads. Default: true. */
|
|
43
|
+
persistSession?: boolean;
|
|
44
|
+
/** localStorage key. Default: 'mitway_baas_session'. */
|
|
45
|
+
storageKey?: string;
|
|
46
|
+
}
|
|
40
47
|
declare class TokenManager {
|
|
41
48
|
private accessToken;
|
|
49
|
+
private refreshToken;
|
|
42
50
|
private user;
|
|
51
|
+
private readonly persistSession;
|
|
52
|
+
private readonly storageKey;
|
|
43
53
|
/** Fired when the access token changes (used by long-lived consumers). */
|
|
44
54
|
onTokenChange: (() => void) | null;
|
|
55
|
+
constructor(opts?: TokenManagerOptions);
|
|
45
56
|
saveSession(session: AuthSession): void;
|
|
46
57
|
getSession(): AuthSession | null;
|
|
47
58
|
getAccessToken(): string | null;
|
|
48
59
|
setAccessToken(token: string): void;
|
|
60
|
+
getRefreshToken(): string | null;
|
|
61
|
+
setRefreshToken(token: string | null): void;
|
|
49
62
|
getUser(): User | null;
|
|
50
63
|
setUser(user: User): void;
|
|
51
64
|
clearSession(): void;
|
|
65
|
+
/**
|
|
66
|
+
* Restore the session from localStorage. Returns true if a persisted
|
|
67
|
+
* session was found and loaded into memory.
|
|
68
|
+
*/
|
|
69
|
+
restoreSession(): boolean;
|
|
70
|
+
private persist;
|
|
71
|
+
private removePersisted;
|
|
52
72
|
}
|
|
53
73
|
|
|
54
74
|
/**
|
|
@@ -451,6 +471,18 @@ interface MitwayBaasConfig {
|
|
|
451
471
|
* Realtime transport options. See `RealtimeOptions`.
|
|
452
472
|
*/
|
|
453
473
|
realtime?: RealtimeOptions;
|
|
474
|
+
/**
|
|
475
|
+
* Persist the auth session to `localStorage` so it survives page reloads.
|
|
476
|
+
* Set to `false` for SSR / Node.js environments where `localStorage` is
|
|
477
|
+
* not available.
|
|
478
|
+
* @default true
|
|
479
|
+
*/
|
|
480
|
+
persistSession?: boolean;
|
|
481
|
+
/**
|
|
482
|
+
* `localStorage` key used to persist the session.
|
|
483
|
+
* @default "mitway_baas_session"
|
|
484
|
+
*/
|
|
485
|
+
storageKey?: string;
|
|
454
486
|
}
|
|
455
487
|
/**
|
|
456
488
|
* Active user session in memory. Mirrors what the auth endpoints return.
|
|
@@ -458,6 +490,7 @@ interface MitwayBaasConfig {
|
|
|
458
490
|
interface AuthSession {
|
|
459
491
|
user: User;
|
|
460
492
|
accessToken: string;
|
|
493
|
+
refreshToken?: string;
|
|
461
494
|
expiresAt?: Date;
|
|
462
495
|
}
|
|
463
496
|
/**
|
|
@@ -548,6 +581,18 @@ declare class HttpClient {
|
|
|
548
581
|
private computeRetryDelay;
|
|
549
582
|
private handleRequest;
|
|
550
583
|
request<T>(method: string, path: string, options?: RequestOptions): Promise<T>;
|
|
584
|
+
/**
|
|
585
|
+
* Low-level fetch helper for binary bodies (uploads) and streamed responses
|
|
586
|
+
* (downloads). Applies the current Bearer token (user session → anon key
|
|
587
|
+
* fallback) plus any configured default headers, resolves `path` against
|
|
588
|
+
* `baseUrl`, and returns the raw `Response` — it does NOT unwrap the
|
|
589
|
+
* `{ data, error }` envelope, so the caller is responsible for status
|
|
590
|
+
* checking and parsing.
|
|
591
|
+
*
|
|
592
|
+
* Used by the storage module for object upload/download paths where the
|
|
593
|
+
* body or response is not JSON.
|
|
594
|
+
*/
|
|
595
|
+
rawFetch(path: string, init?: RequestInit): Promise<Response>;
|
|
551
596
|
get<T>(path: string, options?: RequestOptions): Promise<T>;
|
|
552
597
|
post<T>(path: string, body?: any, options?: RequestOptions): Promise<T>;
|
|
553
598
|
put<T>(path: string, body?: any, options?: RequestOptions): Promise<T>;
|
|
@@ -642,6 +687,23 @@ declare class Auth {
|
|
|
642
687
|
* not need to call it directly.
|
|
643
688
|
*/
|
|
644
689
|
refreshSession(): Promise<AuthResult<AuthResponse>>;
|
|
690
|
+
/**
|
|
691
|
+
* Restore the session from localStorage and validate it with the backend.
|
|
692
|
+
* Call this once on app startup (e.g. in a React AuthProvider useEffect).
|
|
693
|
+
*
|
|
694
|
+
* Flow:
|
|
695
|
+
* 1. Read persisted session from localStorage.
|
|
696
|
+
* 2. Populate in-memory state (TokenManager + HttpClient).
|
|
697
|
+
* 3. Validate with `GET /api/auth/sessions/current`.
|
|
698
|
+
* - If the access token expired, the HttpClient auto-refresh kicks in
|
|
699
|
+
* using the persisted refresh token (sent in the POST body, not
|
|
700
|
+
* cookies — works cross-site).
|
|
701
|
+
* 4. Return the validated user or an error.
|
|
702
|
+
*
|
|
703
|
+
* If no persisted session exists, returns `{ data: null, error }` — the
|
|
704
|
+
* app should show the login page.
|
|
705
|
+
*/
|
|
706
|
+
initialize(): Promise<AuthResult<AuthResponse>>;
|
|
645
707
|
/**
|
|
646
708
|
* Get the current in-memory session, or null if the user is not signed in.
|
|
647
709
|
* Synchronous — does not hit the network.
|
|
@@ -718,6 +780,136 @@ declare class Database {
|
|
|
718
780
|
getUrl(): string;
|
|
719
781
|
}
|
|
720
782
|
|
|
783
|
+
/**
|
|
784
|
+
* Storage types — kept in sync manually with the MITWAY-BaaS shared-schemas
|
|
785
|
+
* definitions at
|
|
786
|
+
* `MITWAY-BaaS/packages/shared-schemas/src/storage.schema.ts`.
|
|
787
|
+
*
|
|
788
|
+
* All SDK-facing fields are camelCase. The wire format is snake_case; the
|
|
789
|
+
* storage module maps between the two.
|
|
790
|
+
*/
|
|
791
|
+
interface StorageBucket {
|
|
792
|
+
id: string;
|
|
793
|
+
name: string;
|
|
794
|
+
public: boolean;
|
|
795
|
+
fileSizeLimitBytes: number | null;
|
|
796
|
+
allowedMimeTypes: string[] | null;
|
|
797
|
+
createdAt: string;
|
|
798
|
+
updatedAt: string;
|
|
799
|
+
}
|
|
800
|
+
interface StorageObject {
|
|
801
|
+
id: string;
|
|
802
|
+
bucket: string;
|
|
803
|
+
key: string;
|
|
804
|
+
size: number;
|
|
805
|
+
mimeType: string | null;
|
|
806
|
+
etag: string;
|
|
807
|
+
cacheControl: string | null;
|
|
808
|
+
contentDisposition: string | null;
|
|
809
|
+
uploadedBy: string | null;
|
|
810
|
+
uploadedAt: string;
|
|
811
|
+
updatedAt: string;
|
|
812
|
+
}
|
|
813
|
+
interface StorageConfig {
|
|
814
|
+
defaultFileSizeLimitBytes: number;
|
|
815
|
+
maxFileSizeLimitBytes: number;
|
|
816
|
+
tenantStorageQuotaBytes: number;
|
|
817
|
+
reservedSpaceBytes: number;
|
|
818
|
+
signedUrlDefaultTtlSec: number;
|
|
819
|
+
signedUrlMaxTtlSec: number;
|
|
820
|
+
}
|
|
821
|
+
interface CreateBucketOptions {
|
|
822
|
+
public?: boolean;
|
|
823
|
+
fileSizeLimitBytes?: number | null;
|
|
824
|
+
allowedMimeTypes?: string[] | null;
|
|
825
|
+
}
|
|
826
|
+
interface UpdateBucketOptions {
|
|
827
|
+
public?: boolean;
|
|
828
|
+
fileSizeLimitBytes?: number | null;
|
|
829
|
+
allowedMimeTypes?: string[] | null;
|
|
830
|
+
}
|
|
831
|
+
interface UploadOptions {
|
|
832
|
+
contentType?: string;
|
|
833
|
+
cacheControl?: string;
|
|
834
|
+
contentDisposition?: string;
|
|
835
|
+
/** Defaults to false (POST, fails on duplicate). If true, uses PUT (upsert). */
|
|
836
|
+
upsert?: boolean;
|
|
837
|
+
abortSignal?: AbortSignal;
|
|
838
|
+
}
|
|
839
|
+
interface DownloadOptions {
|
|
840
|
+
range?: {
|
|
841
|
+
start: number;
|
|
842
|
+
end: number;
|
|
843
|
+
};
|
|
844
|
+
abortSignal?: AbortSignal;
|
|
845
|
+
}
|
|
846
|
+
interface ListOptions {
|
|
847
|
+
prefix?: string;
|
|
848
|
+
limit?: number;
|
|
849
|
+
startAfter?: string;
|
|
850
|
+
}
|
|
851
|
+
interface SignedUrlOptions {
|
|
852
|
+
expiresIn?: number;
|
|
853
|
+
}
|
|
854
|
+
interface SignedUrlResult {
|
|
855
|
+
url: string;
|
|
856
|
+
token: string;
|
|
857
|
+
expiresAt: string;
|
|
858
|
+
}
|
|
859
|
+
type UploadBody = Blob | ArrayBuffer | ArrayBufferView | ReadableStream<Uint8Array> | string;
|
|
860
|
+
|
|
861
|
+
/**
|
|
862
|
+
* Storage module — thin wrapper over the /api/storage/* REST endpoints
|
|
863
|
+
* exposed by MITWAY-BaaS.
|
|
864
|
+
*
|
|
865
|
+
* Surface mirrors what coding agents expect from a Supabase-style storage
|
|
866
|
+
* SDK but routes through the Mitway backend (no direct S3 calls). Binary
|
|
867
|
+
* upload/download uses `HttpClient.rawFetch`; JSON operations use the
|
|
868
|
+
* standard typed `request<T>` path.
|
|
869
|
+
*/
|
|
870
|
+
|
|
871
|
+
type StorageResult<T> = {
|
|
872
|
+
data: T | null;
|
|
873
|
+
error: MitwayBaasError | null;
|
|
874
|
+
};
|
|
875
|
+
declare class StorageBucketClient {
|
|
876
|
+
private readonly http;
|
|
877
|
+
private readonly bucketName;
|
|
878
|
+
constructor(http: HttpClient, bucketName: string);
|
|
879
|
+
private bucketBase;
|
|
880
|
+
private objectPath;
|
|
881
|
+
upload(key: string, body: UploadBody, opts?: UploadOptions): Promise<StorageResult<StorageObject>>;
|
|
882
|
+
download(key: string, opts?: DownloadOptions): Promise<StorageResult<Blob>>;
|
|
883
|
+
getStream(key: string, opts?: DownloadOptions): Promise<StorageResult<ReadableStream<Uint8Array>>>;
|
|
884
|
+
remove(keys: string[]): Promise<StorageResult<{
|
|
885
|
+
removed: string[];
|
|
886
|
+
}>>;
|
|
887
|
+
list(opts?: ListOptions): Promise<StorageResult<StorageObject[]>>;
|
|
888
|
+
copy(fromKey: string, toKey: string, toBucket?: string): Promise<StorageResult<StorageObject>>;
|
|
889
|
+
move(fromKey: string, toKey: string, toBucket?: string): Promise<StorageResult<StorageObject>>;
|
|
890
|
+
createSignedUrl(key: string, opts?: SignedUrlOptions): Promise<StorageResult<SignedUrlResult>>;
|
|
891
|
+
getPublicUrl(key: string): {
|
|
892
|
+
data: {
|
|
893
|
+
url: string;
|
|
894
|
+
};
|
|
895
|
+
};
|
|
896
|
+
}
|
|
897
|
+
declare class Storage {
|
|
898
|
+
private readonly http;
|
|
899
|
+
constructor(http: HttpClient);
|
|
900
|
+
/** Scope subsequent operations to a single bucket. */
|
|
901
|
+
from(bucketName: string): StorageBucketClient;
|
|
902
|
+
listBuckets(): Promise<StorageResult<StorageBucket[]>>;
|
|
903
|
+
getBucket(name: string): Promise<StorageResult<StorageBucket>>;
|
|
904
|
+
createBucket(name: string, opts?: CreateBucketOptions): Promise<StorageResult<StorageBucket>>;
|
|
905
|
+
updateBucket(name: string, opts: UpdateBucketOptions): Promise<StorageResult<StorageBucket>>;
|
|
906
|
+
deleteBucket(name: string): Promise<StorageResult<null>>;
|
|
907
|
+
emptyBucket(name: string): Promise<StorageResult<{
|
|
908
|
+
removed: number;
|
|
909
|
+
}>>;
|
|
910
|
+
getConfig(): Promise<StorageResult<StorageConfig>>;
|
|
911
|
+
}
|
|
912
|
+
|
|
721
913
|
/**
|
|
722
914
|
* MITWAY-BaaS SDK client.
|
|
723
915
|
*
|
|
@@ -751,6 +943,7 @@ declare class MitwayBaasClient {
|
|
|
751
943
|
readonly auth: Auth;
|
|
752
944
|
readonly database: Database;
|
|
753
945
|
readonly realtime: Realtime;
|
|
946
|
+
readonly storage: Storage;
|
|
754
947
|
constructor(config?: MitwayBaasConfig);
|
|
755
948
|
/**
|
|
756
949
|
* Escape hatch for callers that need to make custom requests against the
|
|
@@ -791,4 +984,4 @@ declare class MitwayBaasClient {
|
|
|
791
984
|
*/
|
|
792
985
|
declare function createClient(config: MitwayBaasConfig): MitwayBaasClient;
|
|
793
986
|
|
|
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 };
|
|
987
|
+
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 };
|