@trimjs/web-app 0.3.3 → 0.4.1

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
@@ -1,382 +1,141 @@
1
- declare interface App {
2
- name: string;
3
- icon: string;
4
- headerIconVisible?: boolean;
5
- appName: string;
6
- serviceName?: string;
7
- alias?: string;
8
- type: AppType;
9
- componentUrl?: string;
10
- iframe?: boolean;
11
- microApp?: boolean;
12
- url?: string;
13
- description?: string;
14
- multiple?: boolean;
15
- hiddenDesktopIcon?: boolean;
16
- enableSettings?: boolean;
17
- enableMaximize?: boolean;
18
- width?: number;
19
- style?: any;
20
- }
21
-
22
- export declare interface AppAuthAuthorizeRequest extends AppAuthBaseRequest {
23
- routeMethod: AppAuthAuthorizeRouteMethod;
24
- method: Extract<AppAuthMethod, 'authorizeUserFile' | 'authorizeSharedFile'>;
25
- path: string;
26
- }
27
-
28
- declare type AppAuthAuthorizeRouteMethod = Extract<AppAuthRouteMethod, 'authorize-user-file' | 'authorize-shared-file'>;
29
-
30
- export declare interface AppAuthBaseRequest {
31
- appName: string;
32
- redirectUri?: string;
33
- state?: string;
34
- }
35
-
36
- export declare type AppAuthCallbackError = 'access_denied';
37
-
38
- export declare type AppAuthCallbackStatus = 'success' | 'cancel' | 'error';
39
-
40
- export declare type AppAuthMethod = (typeof appAuthMethodRouteMap)[AppAuthRouteMethod];
41
-
42
- declare const appAuthMethodRouteMap: {
43
- readonly 'pick-file': "pickFile";
44
- readonly 'pick-shared-file': "pickSharedFile";
45
- readonly 'authorize-user-file': "authorizeUserFile";
46
- readonly 'authorize-shared-file': "authorizeSharedFile";
47
- };
48
-
49
- declare interface AppAuthPickFileRequest extends AppAuthBaseRequest {
50
- routeMethod: 'pick-file';
51
- method: 'pickFile';
52
- directory?: boolean;
53
- accept?: string[];
54
- }
55
-
56
- export declare type AppAuthPickRequest = AppAuthPickFileRequest | AppAuthPickSharedFileRequest;
57
-
58
- declare interface AppAuthPickSharedFileRequest extends AppAuthBaseRequest {
59
- routeMethod: 'pick-shared-file';
60
- method: 'pickSharedFile';
61
- }
62
-
63
- export declare type AppAuthRequest = AppAuthPickRequest | AppAuthAuthorizeRequest;
64
-
65
- export declare interface AppAuthResult {
66
- status?: AppAuthCallbackStatus;
67
- error?: AppAuthCallbackError;
68
- method?: AppAuthMethod;
69
- appName?: string;
70
- state?: string;
71
- }
72
-
73
- export declare type AppAuthRouteMethod = keyof typeof appAuthMethodRouteMap;
74
-
75
- export declare type AppBridgeResponse<T> = {
76
- code: number;
77
- msg: string;
78
- data: T;
79
- };
80
-
81
- declare type AppBridgeResponse_2<T> = {
82
- code: number;
83
- msg: string;
84
- data: T;
85
- };
86
-
87
- declare enum AppType {
88
- INBUILT = "inbuilt",// 内置应用
89
- THIRD_PARTY = "third-party",// 第三方
90
- TEMPORARY = "temporary"
91
- }
92
-
93
- export declare type AuthorizeFileResult = boolean;
94
-
95
- export declare interface FileDetailsOptions {
96
- admin?: boolean;
97
- }
98
-
99
- export declare interface FilePickerParams {
100
- /**
101
- * 是否多选
102
- *
103
- * @default false
104
- */
105
- multiple?: boolean;
106
- /**
107
- * 是否选择文件夹
108
- *
109
- * @default false
110
- */
111
- directory?: boolean;
112
- /**
113
- * 接受的文件类型
114
- *
115
- * @example
116
- * accept: ['.txt', '.jpg', '.png'];
117
- */
118
- accept?: string[];
119
- /**
120
- * 可选的范围 传入顺序决定侧边栏的顺序 myFiles. 我的文件 otherShare. 他人共享 external. 外接存储 favorites. 我的收藏 storage.
121
- * 存储空间(管理员)
122
- *
123
- * @default
124
- * ['myFiles']
125
- */
126
- sidebarGroup?: ('myFiles' | 'otherShare' | 'external' | 'remote' | 'favorites' | 'storage' | 'torrent' | 'team' | string)[];
127
- /**
128
- * 不可选的路径列表, 如果是路径也不可被展开
129
- *
130
- * @example
131
- * disabledPaths: ['/vol1/1000/xxx', '/vol2/1000/yyy'];
132
- */
133
- disabledPaths?: string[];
134
- /**
135
- * 可选择的正则表达式(预留)
136
- *
137
- * @example
138
- * selectablePatterns: [['\\.(torrent|bt)$', 'i']];
139
- */
140
- selectablePatterns?: [string, string][];
141
- /**
142
- * 扩充搜索 文件类型
143
- *
144
- * @example
145
- * expandFiles: [
146
- * {
147
- * title: '我的种子',
148
- * extension: '.torrent',
149
- * },
150
- * ];
151
- */
152
- expandFiles?: {
153
- /**
154
- * 侧边栏标题
155
- */
156
- title: string;
157
- /**
158
- * 文件扩展名
159
- */
160
- extension: string;
161
- }[];
162
- /**
163
- * 是否允许创建文件夹
164
- *
165
- * @default true
166
- */
167
- creatable?: boolean;
168
- /**
169
- * 标题
170
- *
171
- * @default '选择文件' | '选择文件夹'
172
- */
173
- title?: string;
174
- /**
175
- * 确认按钮文本
176
- *
177
- * @default '确定'
178
- */
179
- okText?: string;
180
- }
181
-
182
- export declare interface HostSnapshot {
183
- status: string;
184
- host?: string;
185
- username?: string;
186
- currentSessionId?: string;
187
- sessions: Array<{
188
- id: string;
189
- label: string;
190
- host?: string;
191
- username?: string;
192
- }>;
193
- errorMessage?: string;
194
- }
195
-
196
- declare interface OpenAppParams {
197
- custom?: {
198
- name?: string;
199
- };
200
- app?: App;
201
- params?: {
202
- [key: string]: any;
203
- };
204
- }
205
-
206
- export declare interface PlatformConfig {
207
- theme: 'dark' | 'light';
208
- language: string;
209
- appVersion?: string;
210
- systemVersion: string;
211
- format: {
212
- date?: string;
213
- time?: string;
214
- };
215
- }
216
-
217
- export declare interface QueryConfig {
218
- timer?: boolean;
219
- observable?: boolean;
220
- encrypt?: boolean;
221
- timeout?: number;
222
- skipPreflight?: boolean;
223
- autoFailTips?: boolean;
224
- failTipsPrefix?: string;
225
- }
226
-
227
- export declare type ResponseData<T> = T extends undefined ? ResponseDataBase : ResponseDataBase & T;
228
-
229
- declare interface ResponseDataBase {
230
- reqid: string;
231
- result: ResponseStatus;
232
- taskId?: string;
233
- type?: string;
234
- errmsg?: string;
235
- errno?: number;
236
- extra?: string;
237
- }
238
-
239
- declare enum ResponseStatus {
240
- SUCCESS = "succ",// 成功
241
- FAIL = "fail",// 失败
242
- CANCEL = "cancel",// 用户取消
243
- DOING = "doing"
244
- }
245
-
246
- /**
247
- * Trim App 实例类
248
- */
249
- declare class TrimApp {
250
- private options;
251
- private flutterInAppWebView;
252
- private osConnector;
253
- private initPromise;
254
- private appApiVersion?;
255
- isWeb: boolean;
256
- isStandaloneWeb: boolean;
257
- constructor(options?: TrimAppOptions);
258
- private init;
259
- private getWebMethods;
260
- private loadAppMessage;
261
- private initMobileAppApi;
262
- private assertMobileAppApi;
263
- private isAtLeastVersion;
264
- private parseVersion;
265
- callAppMethod<T>(fn: string, ...params: Array<string | undefined>): Promise<T | null>;
266
- /**
267
- * 等待初始化完成
268
- *
269
- * @returns Promise
270
- */
271
- ready(): Promise<void>;
272
- /**
273
- * 获取配置
274
- */
275
- getOptions(): TrimAppOptions;
276
- /**
277
- * 更新配置
278
- */
279
- setOptions(options: Partial<TrimAppOptions>): void;
280
- /**
281
- * 获取平台配置
282
- */
283
- getPlatformConfig(): Promise<PlatformConfig>;
284
- getHostSnapshot(): Promise<HostSnapshot>;
285
- getAppAuthBaseUrl(): Promise<string>;
286
- buildAppAuthUrl(request: AppAuthRequest): Promise<string>;
287
- openAppAuth(request: AppAuthRequest, options?: {
288
- target?: string;
289
- features?: string;
290
- }): Promise<string>;
291
- parseAppAuthCallback(input?: string | URL | URLSearchParams): AppAuthResult;
292
- /**
293
- * setTitle - 设置标题
294
- *
295
- * @param title 标题文本
296
- */
297
- setTitle(title: string): Promise<void>;
298
- /**
299
- * setExitPageTips - 设置退出页面提示
300
- *
301
- * @param params 提示参数
302
- */
303
- setExitPageTips(params?: {
304
- title?: string;
305
- content?: string;
306
- }): Promise<unknown>;
307
- /**
308
- * 通过应用打开某个文件
309
- */
310
- openFile(path: string): Promise<unknown>;
311
- /**
312
- * 打开文件管理器
313
- */
314
- openFileManager(path: string): Promise<unknown>;
315
- showFileDetails(paths: string[], options?: FileDetailsOptions): Promise<unknown>;
316
- authorizeUserFile(path: string): Promise<AppBridgeResponse_2<AuthorizeFileResult> | undefined>;
317
- authorizeSharedFile(path: string): Promise<AppBridgeResponse_2<AuthorizeFileResult> | undefined>;
318
- /**
319
- * 打开当前应用在系统中的应用设置页
320
- */
321
- openAppSetting(): Promise<unknown>;
322
- /**
323
- * 打开应用
324
- *
325
- * @param anchor 锚点
326
- */
327
- openApp(anchor: string): Promise<unknown>;
328
- /**
329
- * 打开自定义应用
330
- *
331
- * @param appName 自定义应用标识
332
- * @param options 自定义应用配置和打开参数
333
- */
334
- openCustomApp(appName: string, options: OpenAppParams): Promise<void>;
335
- /**
336
- * 打开外部链接 App 端通过系统浏览器打开,Web 端沿用 window.open 行为
337
- */
338
- openURL(url: string, target?: string, features?: string): Promise<unknown>;
339
- /**
340
- * 关闭应用
341
- */
342
- close(): Promise<unknown>;
343
- /**
344
- * 请求接口
345
- */
346
- query<T>(params: any, config?: QueryConfig): Promise<ResponseData<T>>;
347
- refreshToken(): Promise<void>;
348
- /**
349
- * 监听事件(仅 Web 平台)
350
- */
351
- $on(event: string, cb: (...args: any[]) => void): Promise<void>;
352
- /**
353
- * 取消监听事件(仅 Web 平台)
354
- */
355
- $off(event: string, cb: (...args: any[]) => void): Promise<void>;
356
- /**
357
- * 监听一次事件(仅 Web 平台)
358
- */
359
- $once(event: string, cb: (...args: any[]) => void): Promise<void>;
360
- /**
361
- * 选择文件
362
- */
363
- pickFile(params: FilePickerParams): Promise<string[] | undefined>;
364
- /**
365
- * 选择共享文件并授权给当前应用
366
- */
367
- pickSharedFile(params?: Omit<FilePickerParams, 'directory'>): Promise<AppBridgeResponse_2<string[]> | undefined>;
368
- }
369
- export { TrimApp }
370
- export default TrimApp;
371
-
372
- /**
373
- * SDK 配置选项
374
- */
375
- export declare interface TrimAppOptions {
376
- /**
377
- * 是否开启 debug 模式,开启后会输出日志
378
- */
379
- debug?: boolean;
380
- }
381
-
382
- export { }
1
+ import { AuthorizeFileResult, FileDetailsOptions, HostSnapshot, PlatformConfig, TrimAppOptions } from './types';
2
+ import { AppAuthMethod, AppAuthParams, AppAuthResult } from './app-auth';
3
+ import { ObservableLike } from './mobile/index';
4
+ import { AppBridgeResponse, OpenAppParams, ResponseData, FilePickerParams, QueryConfig } from '@fn/micro-app-postmate';
5
+ export type { FilePickerParams, QueryConfig, ResponseData } from '@fn/micro-app-postmate';
6
+ /**
7
+ * nas 应用 SDK
8
+ *
9
+ * @trim/app - NAS 应用 SDK
10
+ */
11
+ export type { PlatformConfig, TrimAppOptions } from './types';
12
+ export type { HostSnapshot } from './types';
13
+ export type { AppBridgeResponse, AuthorizeFileResult, FileDetailsOptions } from './types';
14
+ export type { AppAuthAuthorizeParams, AppAuthBaseParams, AppAuthCallbackError, AppAuthCallbackStatus, AppAuthMethod, AppAuthMethodParamsMap, AppAuthParams, AppAuthPickFileParams, AppAuthPickSharedFileParams, AppAuthResult, } from './types';
15
+ /**
16
+ * Trim App 实例类
17
+ */
18
+ export declare class TrimApp {
19
+ private options;
20
+ private flutterInAppWebView;
21
+ private osConnector;
22
+ private initPromise;
23
+ private appApiVersion?;
24
+ isWeb: boolean;
25
+ isStandaloneWeb: boolean;
26
+ constructor(options?: TrimAppOptions);
27
+ private init;
28
+ private getWebMethods;
29
+ private loadAppMessage;
30
+ private initMobileAppApi;
31
+ private assertMobileAppApi;
32
+ private isAtLeastVersion;
33
+ private parseVersion;
34
+ callAppMethod<T>(fn: string, ...params: Array<string | undefined>): Promise<T | null>;
35
+ /**
36
+ * 等待初始化完成
37
+ *
38
+ * @returns Promise
39
+ */
40
+ ready(): Promise<void>;
41
+ /**
42
+ * 获取配置
43
+ */
44
+ getOptions(): TrimAppOptions;
45
+ /**
46
+ * 更新配置
47
+ */
48
+ setOptions(options: Partial<TrimAppOptions>): void;
49
+ /**
50
+ * 获取平台配置
51
+ */
52
+ getPlatformConfig(): Promise<PlatformConfig>;
53
+ getHostSnapshot(): Promise<HostSnapshot>;
54
+ getAppAuthBaseUrl(): Promise<string>;
55
+ buildAppAuthUrl<TMethod extends AppAuthMethod>(method: TMethod, params: AppAuthParams<NoInfer<TMethod>>): Promise<string>;
56
+ openAppAuth<TMethod extends AppAuthMethod>(method: TMethod, params: AppAuthParams<NoInfer<TMethod>>, options?: {
57
+ target?: string;
58
+ features?: string;
59
+ }): Promise<string>;
60
+ parseAppAuthCallback(input?: string | URL | URLSearchParams): AppAuthResult;
61
+ /**
62
+ * setTitle - 设置标题
63
+ *
64
+ * @param title 标题文本
65
+ */
66
+ setTitle(title: string): Promise<void>;
67
+ /**
68
+ * setExitPageTips - 设置退出页面提示
69
+ *
70
+ * @param params 提示参数
71
+ */
72
+ setExitPageTips(params?: {
73
+ title?: string;
74
+ content?: string;
75
+ }): Promise<unknown>;
76
+ /**
77
+ * 通过应用打开某个文件
78
+ */
79
+ openFile(path: string): Promise<unknown>;
80
+ /**
81
+ * 打开文件管理器
82
+ */
83
+ openFileManager(path: string): Promise<unknown>;
84
+ showFileDetails(paths: string[], options?: FileDetailsOptions): Promise<unknown>;
85
+ authorizeUserFile(path: string): Promise<AppBridgeResponse<AuthorizeFileResult> | undefined>;
86
+ authorizeSharedFile(path: string): Promise<AppBridgeResponse<AuthorizeFileResult> | undefined>;
87
+ /**
88
+ * 打开当前应用在系统中的应用设置页
89
+ */
90
+ openAppSetting(): Promise<unknown>;
91
+ /**
92
+ * 打开应用
93
+ *
94
+ * @param anchor 锚点
95
+ */
96
+ openApp(anchor: string): Promise<unknown>;
97
+ /**
98
+ * 打开自定义应用
99
+ *
100
+ * @param appName 自定义应用标识
101
+ * @param options 自定义应用配置和打开参数
102
+ */
103
+ openCustomApp(appName: string, options: OpenAppParams): Promise<void>;
104
+ /**
105
+ * 打开外部链接 App 端通过系统浏览器打开,Web 端沿用 window.open 行为
106
+ */
107
+ openURL(url: string, target?: string, features?: string): Promise<unknown>;
108
+ /**
109
+ * 关闭应用
110
+ */
111
+ close(): Promise<unknown>;
112
+ /**
113
+ * 请求接口
114
+ */
115
+ query<T>(params: any, config: QueryConfig & {
116
+ observable: true;
117
+ }): Promise<ObservableLike<ResponseData<T>>>;
118
+ query<T>(params: any, config?: QueryConfig): Promise<ResponseData<T>>;
119
+ refreshToken(): Promise<void>;
120
+ /**
121
+ * 监听事件(仅 Web 平台)
122
+ */
123
+ $on(event: string, cb: (...args: any[]) => void): Promise<void>;
124
+ /**
125
+ * 取消监听事件(仅 Web 平台)
126
+ */
127
+ $off(event: string, cb: (...args: any[]) => void): Promise<void>;
128
+ /**
129
+ * 监听一次事件(仅 Web 平台)
130
+ */
131
+ $once(event: string, cb: (...args: any[]) => void): Promise<void>;
132
+ /**
133
+ * 选择文件
134
+ */
135
+ pickFile(params: FilePickerParams): Promise<string[] | undefined>;
136
+ /**
137
+ * 选择共享文件并授权给当前应用
138
+ */
139
+ pickSharedFile(params?: Omit<FilePickerParams, 'directory'>): Promise<AppBridgeResponse<string[]> | undefined>;
140
+ }
141
+ export default TrimApp;