@nvwa-app/sdk-core 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.cjs +726 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +217 -0
- package/dist/index.d.mts +217 -0
- package/dist/index.d.ts +217 -0
- package/dist/index.mjs +705 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +49 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import * as _nvwa_app_postgrest_js from '@nvwa-app/postgrest-js';
|
|
2
|
+
import { PostgrestClient } from '@nvwa-app/postgrest-js';
|
|
3
|
+
import { BetterAuthClientOptions } from 'better-auth';
|
|
4
|
+
import { createAuthClient } from 'better-auth/client';
|
|
5
|
+
|
|
6
|
+
interface NvwaLocalStorage {
|
|
7
|
+
get(key: string): Promise<any | null>;
|
|
8
|
+
/**
|
|
9
|
+
* @param expires 过期时间(秒),可选
|
|
10
|
+
*/
|
|
11
|
+
set(key: string, value: any, expires?: number): Promise<void>;
|
|
12
|
+
remove(key: string): Promise<void>;
|
|
13
|
+
clear(): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare class Headers {
|
|
17
|
+
private readonly headerMap;
|
|
18
|
+
constructor(init?: Headers | Record<string, string> | [string, string][]);
|
|
19
|
+
append(name: string, value: string): void;
|
|
20
|
+
set(name: string, value: string): void;
|
|
21
|
+
get(name: string): string | null;
|
|
22
|
+
has(name: string): boolean;
|
|
23
|
+
delete(name: string): void;
|
|
24
|
+
forEach(callback: (value: string, key: string, parent: Headers) => void): void;
|
|
25
|
+
entries(): IterableIterator<[string, string]>;
|
|
26
|
+
keys(): IterableIterator<string>;
|
|
27
|
+
values(): IterableIterator<string>;
|
|
28
|
+
[Symbol.iterator](): IterableIterator<[string, string]>;
|
|
29
|
+
}
|
|
30
|
+
declare class URLSearchParams {
|
|
31
|
+
private params;
|
|
32
|
+
constructor(init?: string | URLSearchParams | Record<string, string> | [string, string][] | Iterable<[string, string]>);
|
|
33
|
+
private parseString;
|
|
34
|
+
append(name: string, value: string): void;
|
|
35
|
+
delete(name: string): void;
|
|
36
|
+
get(name: string): string | null;
|
|
37
|
+
getAll(name: string): string[];
|
|
38
|
+
has(name: string): boolean;
|
|
39
|
+
set(name: string, value: string): void;
|
|
40
|
+
sort(): void;
|
|
41
|
+
toString(): string;
|
|
42
|
+
forEach(callback: (value: string, key: string, parent: URLSearchParams) => void): void;
|
|
43
|
+
keys(): IterableIterator<string>;
|
|
44
|
+
values(): IterableIterator<string>;
|
|
45
|
+
entries(): IterableIterator<[string, string]>;
|
|
46
|
+
[Symbol.iterator](): IterableIterator<[string, string]>;
|
|
47
|
+
get size(): number;
|
|
48
|
+
}
|
|
49
|
+
declare class URL$1 {
|
|
50
|
+
readonly href: string;
|
|
51
|
+
readonly origin: string;
|
|
52
|
+
readonly protocol: string;
|
|
53
|
+
readonly username: string;
|
|
54
|
+
readonly password: string;
|
|
55
|
+
readonly host: string;
|
|
56
|
+
readonly hostname: string;
|
|
57
|
+
readonly port: string;
|
|
58
|
+
readonly pathname: string;
|
|
59
|
+
readonly search: string;
|
|
60
|
+
readonly searchParams: URLSearchParams;
|
|
61
|
+
readonly hash: string;
|
|
62
|
+
constructor(url: string | URL$1, base?: string | URL$1);
|
|
63
|
+
private resolve;
|
|
64
|
+
private parseUrl;
|
|
65
|
+
toString(): string;
|
|
66
|
+
toJSON(): string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
interface RequestInit {
|
|
70
|
+
method?: string;
|
|
71
|
+
headers?: Headers;
|
|
72
|
+
body?: any;
|
|
73
|
+
timeout?: number;
|
|
74
|
+
signal?: {
|
|
75
|
+
aborted: boolean;
|
|
76
|
+
addEventListener: Function;
|
|
77
|
+
} | null;
|
|
78
|
+
}
|
|
79
|
+
type RequestInfo = string | {
|
|
80
|
+
url?: string;
|
|
81
|
+
} | URL;
|
|
82
|
+
declare class Request {
|
|
83
|
+
readonly url: string;
|
|
84
|
+
readonly method: string;
|
|
85
|
+
readonly headers: Headers;
|
|
86
|
+
readonly body?: any;
|
|
87
|
+
readonly timeout?: number;
|
|
88
|
+
readonly signal?: any;
|
|
89
|
+
constructor(input: RequestInfo, init?: RequestInit);
|
|
90
|
+
clone(): Request;
|
|
91
|
+
toString(): string;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
interface ResponseInit {
|
|
95
|
+
status?: number;
|
|
96
|
+
statusText?: string;
|
|
97
|
+
headers?: Headers;
|
|
98
|
+
}
|
|
99
|
+
declare class Response {
|
|
100
|
+
private readonly bodyData;
|
|
101
|
+
readonly status: number;
|
|
102
|
+
readonly statusText: string;
|
|
103
|
+
readonly headers: Headers;
|
|
104
|
+
readonly ok: boolean;
|
|
105
|
+
constructor(body?: any, init?: ResponseInit);
|
|
106
|
+
text(): Promise<string>;
|
|
107
|
+
json<T = unknown>(): Promise<T>;
|
|
108
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
type AbortListener = () => void;
|
|
112
|
+
declare class AbortSignal {
|
|
113
|
+
private _aborted;
|
|
114
|
+
private listeners;
|
|
115
|
+
onabort: AbortListener | null;
|
|
116
|
+
get aborted(): boolean;
|
|
117
|
+
_trigger(): void;
|
|
118
|
+
addEventListener(_: "abort", listener: AbortListener): void;
|
|
119
|
+
removeEventListener(_: "abort", listener: AbortListener): void;
|
|
120
|
+
toString(): string;
|
|
121
|
+
}
|
|
122
|
+
declare class AbortController {
|
|
123
|
+
private _signal;
|
|
124
|
+
constructor();
|
|
125
|
+
get signal(): AbortSignal;
|
|
126
|
+
abort(): void;
|
|
127
|
+
toString(): string;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
declare function polyfill(_global: any): void;
|
|
131
|
+
|
|
132
|
+
type NvwaFetch = (input: string | URL$1 | RequestInfo, init?: RequestInit) => Promise<Response>;
|
|
133
|
+
|
|
134
|
+
declare const AUTH_BASE_PATH = "/auth";
|
|
135
|
+
declare const LOGIN_TOKEN_KEY = "nvwa_login_token";
|
|
136
|
+
declare const LOGIN_USER_PROFILE_KEY = "nvwa_user_profile";
|
|
137
|
+
type AuthClient = ReturnType<typeof createAuthClient<BetterAuthClientOptions>>;
|
|
138
|
+
type SignInResult = ReturnType<ReturnType<typeof createAuthClient>["signIn"]["email"]>;
|
|
139
|
+
declare abstract class NvwaAuthClient {
|
|
140
|
+
protected storage: NvwaLocalStorage;
|
|
141
|
+
protected authClient: AuthClient;
|
|
142
|
+
constructor(baseUrl: string, fetch: NvwaFetch, storage: NvwaLocalStorage);
|
|
143
|
+
signInWithUsername(username: string, password: string): Promise<void>;
|
|
144
|
+
saveSession(result: SignInResult): void;
|
|
145
|
+
signOut(): Promise<void>;
|
|
146
|
+
updateUserPassword(oldPassword: string, newPassword: string, revokeOtherSessions?: boolean): Promise<void>;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "OPTIONS" | "HEAD";
|
|
150
|
+
type HttpRequest = {
|
|
151
|
+
method: string;
|
|
152
|
+
data?: any;
|
|
153
|
+
headers?: Record<string, string>;
|
|
154
|
+
};
|
|
155
|
+
type HttpResponse<T> = {
|
|
156
|
+
status: number;
|
|
157
|
+
body: T;
|
|
158
|
+
headers: {
|
|
159
|
+
[key: string]: string;
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
declare class FetchResponse {
|
|
163
|
+
ok: boolean;
|
|
164
|
+
status: number;
|
|
165
|
+
statusText: string;
|
|
166
|
+
headers: Record<string, string>;
|
|
167
|
+
body: any;
|
|
168
|
+
constructor(ok: boolean, status: number, statusText: string, headers: Record<string, string>, body: any);
|
|
169
|
+
text(): Promise<string>;
|
|
170
|
+
json(): Promise<any>;
|
|
171
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
172
|
+
blob(): Promise<Blob>;
|
|
173
|
+
}
|
|
174
|
+
declare abstract class NvwaHttpClient {
|
|
175
|
+
abstract request<T>(url: string | URL, request: HttpRequest): Promise<HttpResponse<T>>;
|
|
176
|
+
abstract requestWithAuth<T>(url: string | URL, request: HttpRequest, handleUnauthorized: () => void): Promise<HttpResponse<T>>;
|
|
177
|
+
jsonRequest<T>(url: string | URL, request: HttpRequest): Promise<HttpResponse<T>>;
|
|
178
|
+
jsonRequestWithAuth<T>(url: string | URL, request: HttpRequest, handleUnauthorized: () => void): Promise<HttpResponse<T>>;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
type HttpUploadFileResponse = {
|
|
182
|
+
url: string;
|
|
183
|
+
};
|
|
184
|
+
declare const FILE_STORAGE_BASE_PATH = "/storage";
|
|
185
|
+
declare const GENERATE_UPLOAD_URL_PATH: string;
|
|
186
|
+
declare class NvwaFileStorage {
|
|
187
|
+
private baseUrl;
|
|
188
|
+
private http;
|
|
189
|
+
constructor(baseUrl: string, http: NvwaHttpClient);
|
|
190
|
+
uploadFile(file: any): Promise<HttpUploadFileResponse>;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
type FunctionInvokeOptions = {
|
|
194
|
+
headers?: {
|
|
195
|
+
[key: string]: string;
|
|
196
|
+
};
|
|
197
|
+
method?: 'POST' | 'GET' | 'PUT' | 'PATCH' | 'DELETE';
|
|
198
|
+
body?: File | Blob | ArrayBuffer | FormData | ReadableStream<Uint8Array> | Record<string, any> | string;
|
|
199
|
+
};
|
|
200
|
+
declare class NvwaEdgeFunctions {
|
|
201
|
+
protected http: NvwaHttpClient;
|
|
202
|
+
constructor(http: NvwaHttpClient);
|
|
203
|
+
invoke<T = any>(name: string, options: FunctionInvokeOptions): Promise<T>;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
declare const ENTITIES_BASE_PATH = "/entities";
|
|
207
|
+
declare const createPostgrestClient: (baseUrl: string, httpClient: NvwaHttpClient, handleUnauthorized: () => void) => PostgrestClient<any, {} | _nvwa_app_postgrest_js.PostgrestClientOptions, "public", any>;
|
|
208
|
+
|
|
209
|
+
interface INvwa {
|
|
210
|
+
entities: PostgrestClient;
|
|
211
|
+
auth: NvwaAuthClient;
|
|
212
|
+
functions: NvwaEdgeFunctions;
|
|
213
|
+
fileStorage: NvwaFileStorage;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export { AUTH_BASE_PATH, AbortController, AbortSignal, ENTITIES_BASE_PATH, FILE_STORAGE_BASE_PATH, FetchResponse, GENERATE_UPLOAD_URL_PATH, Headers, LOGIN_TOKEN_KEY, LOGIN_USER_PROFILE_KEY, NvwaAuthClient, NvwaEdgeFunctions, NvwaFileStorage, NvwaHttpClient, Request, Response, URL$1 as URL, URLSearchParams, createPostgrestClient, polyfill };
|
|
217
|
+
export type { AuthClient, FunctionInvokeOptions, HttpMethod, HttpRequest, HttpResponse, HttpUploadFileResponse, INvwa, NvwaFetch, NvwaLocalStorage, RequestInfo, RequestInit, ResponseInit };
|