UNPKG

1.76 kBTypeScriptView Raw
1export declare namespace nam {
2 const socketRpcEventNamePrefix = "socket-rpc.device";
3 interface AppletImage {
4 naType: string;
5 naVersion: string;
6 packageName: string;
7 version: string;
8 }
9 interface AppletRunOptions extends AppletImage {
10 appletId: string;
11 appletToken: string;
12 }
13 interface AppletStatus extends AppletImage {
14 appletId: string;
15 ip: string;
16 port: number;
17 status: string;
18 }
19 interface RouteOptions extends AppletImage {
20 appletId: string;
21 }
22 interface Route {
23 route: string;
24 target: string;
25 }
26 interface RequestOptions extends RouteOptions {
27 uri: string;
28 method: string;
29 body?: object;
30 headers?: {
31 [key: string]: string;
32 };
33 resolveWithFullResponse?: boolean;
34 }
35 interface WorkOptions {
36 userApplet: string;
37 route: RouteOptions;
38 worker: Worker;
39 payload: object;
40 }
41 interface RequestResponse {
42 statusCode: number;
43 headers?: {
44 [key: string]: string;
45 };
46 body: object;
47 }
48 interface Worker {
49 handler: string;
50 name: string;
51 }
52 interface AccountOperateOptions {
53 accountId: string;
54 appletId: string;
55 body: string;
56 }
57 interface INAM {
58 install(options: AppletImage): Promise<void>;
59 images(): Promise<AppletImage[]>;
60 run(options: AppletRunOptions): Promise<void>;
61 ps(): Promise<AppletStatus[]>;
62 kill(options: RouteOptions): Promise<void>;
63 work(options: WorkOptions): Promise<any>;
64 request<T>(options: RequestOptions): Promise<RequestResponse | T>;
65 }
66}