@nebula-rn/client 0.0.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/chooseMedia/index.d.ts +22 -0
- package/dist/chooseMedia/index.js +4 -0
- package/dist/compressImage/index.d.ts +7 -0
- package/dist/compressImage/index.js +4 -0
- package/dist/descriptions.d.ts +9 -0
- package/dist/descriptions.js +259 -0
- package/dist/file.d.ts +51 -0
- package/dist/file.js +14 -0
- package/dist/getAppBaseInfo/index.d.ts +6 -0
- package/dist/getAppBaseInfo/index.js +4 -0
- package/dist/getClipboardData/index.d.ts +1 -0
- package/dist/getClipboardData/index.js +4 -0
- package/dist/getFileInfo/index.d.ts +9 -0
- package/dist/getFileInfo/index.js +4 -0
- package/dist/getFileSystemManager/index.d.ts +70 -0
- package/dist/getFileSystemManager/index.js +43 -0
- package/dist/getImageInfo/index.d.ts +16 -0
- package/dist/getImageInfo/index.js +20 -0
- package/dist/getLocation/index.d.ts +15 -0
- package/dist/getLocation/index.js +4 -0
- package/dist/getScreenBrightness/index.d.ts +1 -0
- package/dist/getScreenBrightness/index.js +4 -0
- package/dist/getStorage/index.d.ts +1 -0
- package/dist/getStorage/index.js +8 -0
- package/dist/getStorageInfo/index.d.ts +6 -0
- package/dist/getStorageInfo/index.js +12 -0
- package/dist/getSystemInfo/index.d.ts +1 -0
- package/dist/getSystemInfo/index.js +4 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +26 -0
- package/dist/location.d.ts +10 -0
- package/dist/location.js +18 -0
- package/dist/makePhoneCall/index.d.ts +1 -0
- package/dist/makePhoneCall/index.js +4 -0
- package/dist/media.d.ts +5 -0
- package/dist/media.js +8 -0
- package/dist/miniAppUpdate/index.d.ts +3 -0
- package/dist/miniAppUpdate/index.js +7 -0
- package/dist/network.d.ts +9 -0
- package/dist/network.js +15 -0
- package/dist/onUserCaptureScreen/index.d.ts +1 -0
- package/dist/onUserCaptureScreen/index.js +11 -0
- package/dist/previewImage/index.d.ts +8 -0
- package/dist/previewImage/index.js +4 -0
- package/dist/runtime/host.d.ts +41 -0
- package/dist/runtime/host.js +152 -0
- package/dist/scanCode/contract.d.ts +7 -0
- package/dist/scanCode/contract.js +8 -0
- package/dist/scanCode/icon_close.png +0 -0
- package/dist/scanCode/icon_pic.png +0 -0
- package/dist/scanCode/index.d.ts +6 -0
- package/dist/scanCode/index.js +72 -0
- package/dist/scanCode/types.d.ts +25 -0
- package/dist/scanCode/types.js +8 -0
- package/dist/sensors.d.ts +13 -0
- package/dist/sensors.js +15 -0
- package/dist/setClipboardData/index.d.ts +1 -0
- package/dist/setClipboardData/index.js +2 -0
- package/dist/setStorage/index.d.ts +5 -0
- package/dist/setStorage/index.js +5 -0
- package/dist/storage.d.ts +9 -0
- package/dist/storage.js +36 -0
- package/dist/uploadFile/index.d.ts +30 -0
- package/dist/uploadFile/index.js +6 -0
- package/package.json +77 -0
- package/src/chooseMedia/index.ts +36 -0
- package/src/compressImage/index.ts +14 -0
- package/src/descriptions.ts +294 -0
- package/src/file.ts +89 -0
- package/src/getAppBaseInfo/index.ts +10 -0
- package/src/getClipboardData/index.ts +5 -0
- package/src/getFileInfo/index.ts +17 -0
- package/src/getFileSystemManager/index.ts +141 -0
- package/src/getImageInfo/index.ts +40 -0
- package/src/getLocation/index.ts +23 -0
- package/src/getScreenBrightness/index.ts +5 -0
- package/src/getStorage/index.ts +10 -0
- package/src/getStorageInfo/index.ts +20 -0
- package/src/getSystemInfo/index.ts +5 -0
- package/src/index.ts +26 -0
- package/src/location.ts +40 -0
- package/src/makePhoneCall/index.ts +5 -0
- package/src/media.ts +19 -0
- package/src/miniAppUpdate/index.ts +20 -0
- package/src/network.ts +36 -0
- package/src/onUserCaptureScreen/index.ts +17 -0
- package/src/previewImage/index.tsx +13 -0
- package/src/runtime/host.ts +356 -0
- package/src/scanCode/contract.ts +20 -0
- package/src/scanCode/icon_close.png +0 -0
- package/src/scanCode/icon_pic.png +0 -0
- package/src/scanCode/index.tsx +127 -0
- package/src/scanCode/types.ts +38 -0
- package/src/sensors.ts +48 -0
- package/src/setClipboardData/index.ts +4 -0
- package/src/setStorage/index.ts +11 -0
- package/src/storage.ts +51 -0
- package/src/uploadFile/index.ts +57 -0
package/package.json
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nebula-rn/client",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Nebula miniapp client API surface",
|
|
5
|
+
"author": "Hector Zhuang",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"react-native": "src/index.ts",
|
|
9
|
+
"source": "src/index.ts",
|
|
10
|
+
"types": "types/index.d.ts",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist",
|
|
13
|
+
"src",
|
|
14
|
+
"types",
|
|
15
|
+
"apiList.js",
|
|
16
|
+
"libList.js"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"prod": "npm run build",
|
|
20
|
+
"assets": "cpy 'src/**/*.png' '!src/__tests__/*' dist",
|
|
21
|
+
"prebuild": "npm run clean",
|
|
22
|
+
"clean": "rimraf ./dist apiList.js libList.js",
|
|
23
|
+
"build": "tsc && npm run assets",
|
|
24
|
+
"dev": "npm run assets && tsc --watch",
|
|
25
|
+
"prepack": "npm run build",
|
|
26
|
+
"docs": "node ./script",
|
|
27
|
+
"lint": "eslint src --ext .js,.jsx.ts,.tsx",
|
|
28
|
+
"test": "jest --silent",
|
|
29
|
+
"test:ci": "jest --ci -i --coverage --silent",
|
|
30
|
+
"test:coverage": "jest --coverage",
|
|
31
|
+
"test:dev": "jest --watch",
|
|
32
|
+
"script": "node ./script"
|
|
33
|
+
},
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git+https://github.com/Hector-Zhuang/nebula.git",
|
|
37
|
+
"directory": "packages/api"
|
|
38
|
+
},
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/Hector-Zhuang/nebula/issues"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://github.com/Hector-Zhuang/nebula/tree/main/packages/api#readme",
|
|
43
|
+
"keywords": ["nebula", "superapp", "miniapp", "react-native", "client"],
|
|
44
|
+
"publishConfig": { "access": "public" },
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">= 18"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"@nebula-rn/sdk": "^0.0.1",
|
|
50
|
+
"@dr.pogodin/react-native-fs": "^2.37.0",
|
|
51
|
+
"base64-js": "^1.5.1",
|
|
52
|
+
"prop-types": "^15.8.1",
|
|
53
|
+
"react-native-image-picker": "^8.2.1",
|
|
54
|
+
"react-native-screenshot-aware": "^2.0.0",
|
|
55
|
+
"react-native-sensors": "^7.3.6"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@bam.tech/react-native-image-resizer": "^3.0.11",
|
|
59
|
+
"cpy-cli": "^5.0.0",
|
|
60
|
+
"dpdm": "^3.14.0",
|
|
61
|
+
"react-native-image-zoom-viewer": "^3.0.1",
|
|
62
|
+
"react-native-root-siblings": "^5.0.1",
|
|
63
|
+
"react-native-safe-area-context": "^5.7.0"
|
|
64
|
+
},
|
|
65
|
+
"peerDependencies": {
|
|
66
|
+
"@bam.tech/react-native-image-resizer": "^3.0.11",
|
|
67
|
+
"@react-native-camera-roll/camera-roll": "^7.10.2",
|
|
68
|
+
"@react-native-community/geolocation": "^3.4.0",
|
|
69
|
+
"@react-native-community/netinfo": "^12.0.1",
|
|
70
|
+
"react": ">=19",
|
|
71
|
+
"react-native": ">=0.83",
|
|
72
|
+
"react-native-device-info": "^15.0.2",
|
|
73
|
+
"react-native-image-zoom-viewer": "^3.0.1",
|
|
74
|
+
"react-native-mmkv": "^4.2.0",
|
|
75
|
+
"react-native-safe-area-context": "^5.7.0"
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { invokeHostApi } from '../runtime/host';
|
|
2
|
+
|
|
3
|
+
export interface ChooseMediaFile {
|
|
4
|
+
tempFilePath: string;
|
|
5
|
+
size: number;
|
|
6
|
+
duration?: number;
|
|
7
|
+
height?: number;
|
|
8
|
+
width?: number;
|
|
9
|
+
thumbTempFilePath?: string;
|
|
10
|
+
fileType: 'image' | 'video';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface ChooseMediaResult {
|
|
14
|
+
tempFiles: ChooseMediaFile[];
|
|
15
|
+
type: 'image' | 'video' | 'mix';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface ChooseMediaOption {
|
|
19
|
+
count?: number;
|
|
20
|
+
mediaType?: ('image' | 'video' | 'mix')[];
|
|
21
|
+
sourceType?: ('album' | 'camera')[];
|
|
22
|
+
maxDuration?: number;
|
|
23
|
+
sizeType?: ('original' | 'compressed')[];
|
|
24
|
+
camera?: 'back' | 'front';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const chooseMedia = (
|
|
28
|
+
options: ChooseMediaOption = {},
|
|
29
|
+
): Promise<ChooseMediaResult> => {
|
|
30
|
+
return invokeHostApi<ChooseMediaResult>(
|
|
31
|
+
'chooseMedia',
|
|
32
|
+
options,
|
|
33
|
+
'1.0',
|
|
34
|
+
120000,
|
|
35
|
+
);
|
|
36
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { invokeHostApi } from '../runtime/host';
|
|
2
|
+
|
|
3
|
+
export interface CompressImageOption {
|
|
4
|
+
src: string;
|
|
5
|
+
quality?: number;
|
|
6
|
+
compressedWidth?: number;
|
|
7
|
+
compressedHeight?: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const compressImage = (
|
|
11
|
+
options: CompressImageOption,
|
|
12
|
+
): Promise<string> => {
|
|
13
|
+
return invokeHostApi<string>('compressImage', options);
|
|
14
|
+
};
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import { Miniapp } from '@nebula-rn/sdk';
|
|
2
|
+
import type {
|
|
3
|
+
NebulaHostApiDescription,
|
|
4
|
+
NebulaHostApiDescriptionMap,
|
|
5
|
+
} from '@nebula-rn/sdk';
|
|
6
|
+
|
|
7
|
+
export type NebulaPublicApiDescription = NebulaHostApiDescription & {
|
|
8
|
+
kind?: 'api' | 'manager' | 'subscription' | 'task' | 'utility';
|
|
9
|
+
methods?: Record<string, NebulaHostApiDescription>;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export type NebulaPublicApiDescriptionMap = Record<
|
|
13
|
+
string,
|
|
14
|
+
NebulaPublicApiDescription
|
|
15
|
+
>;
|
|
16
|
+
|
|
17
|
+
export const nebulaApiDescriptions: NebulaPublicApiDescriptionMap = {
|
|
18
|
+
chooseMedia: {
|
|
19
|
+
summary:
|
|
20
|
+
'Open the host media picker and return selected image or video assets.',
|
|
21
|
+
kind: 'api',
|
|
22
|
+
tags: ['media', 'picker'],
|
|
23
|
+
},
|
|
24
|
+
compressImage: {
|
|
25
|
+
summary: 'Resize and compress an image through the host runtime.',
|
|
26
|
+
kind: 'api',
|
|
27
|
+
tags: ['media', 'image'],
|
|
28
|
+
},
|
|
29
|
+
downloadFile: {
|
|
30
|
+
summary:
|
|
31
|
+
'Start a host-managed download task with progress and abort support.',
|
|
32
|
+
kind: 'task',
|
|
33
|
+
tags: ['file', 'network'],
|
|
34
|
+
},
|
|
35
|
+
uploadFile: {
|
|
36
|
+
summary:
|
|
37
|
+
'Start a host-managed upload task with progress and abort support.',
|
|
38
|
+
kind: 'task',
|
|
39
|
+
tags: ['file', 'network'],
|
|
40
|
+
},
|
|
41
|
+
getAppBaseInfo: {
|
|
42
|
+
summary:
|
|
43
|
+
'Return basic host app information for the current miniapp runtime.',
|
|
44
|
+
kind: 'api',
|
|
45
|
+
tags: ['device', 'app'],
|
|
46
|
+
},
|
|
47
|
+
getClipboardData: {
|
|
48
|
+
summary: 'Read plain text from the system clipboard.',
|
|
49
|
+
kind: 'api',
|
|
50
|
+
tags: ['clipboard'],
|
|
51
|
+
},
|
|
52
|
+
getFileInfo: {
|
|
53
|
+
summary: 'Read size and digest information for a file path.',
|
|
54
|
+
kind: 'api',
|
|
55
|
+
tags: ['file'],
|
|
56
|
+
},
|
|
57
|
+
getFileSystemManager: {
|
|
58
|
+
summary: 'Return a file system manager bound to host-backed file APIs.',
|
|
59
|
+
kind: 'manager',
|
|
60
|
+
tags: ['file'],
|
|
61
|
+
methods: {
|
|
62
|
+
access: {
|
|
63
|
+
summary: 'Check whether a path exists and is accessible.',
|
|
64
|
+
tags: ['file'],
|
|
65
|
+
},
|
|
66
|
+
appendFile: {
|
|
67
|
+
summary: 'Append text data to a file path.',
|
|
68
|
+
tags: ['file'],
|
|
69
|
+
},
|
|
70
|
+
saveFile: {
|
|
71
|
+
summary: 'Persist a temp file into the miniapp sandbox.',
|
|
72
|
+
tags: ['file'],
|
|
73
|
+
},
|
|
74
|
+
copyFile: {
|
|
75
|
+
summary: 'Copy a file from one path to another.',
|
|
76
|
+
tags: ['file'],
|
|
77
|
+
},
|
|
78
|
+
mkdir: {
|
|
79
|
+
summary: 'Create a directory path recursively.',
|
|
80
|
+
tags: ['file'],
|
|
81
|
+
},
|
|
82
|
+
readFile: {
|
|
83
|
+
summary: 'Read a file as text with optional encoding.',
|
|
84
|
+
tags: ['file'],
|
|
85
|
+
},
|
|
86
|
+
readdir: {
|
|
87
|
+
summary: 'List child entries in a directory.',
|
|
88
|
+
tags: ['file'],
|
|
89
|
+
},
|
|
90
|
+
rename: {
|
|
91
|
+
summary: 'Rename or move a file or directory.',
|
|
92
|
+
tags: ['file'],
|
|
93
|
+
},
|
|
94
|
+
rmdir: {
|
|
95
|
+
summary: 'Remove a directory path recursively.',
|
|
96
|
+
tags: ['file'],
|
|
97
|
+
},
|
|
98
|
+
unlink: {
|
|
99
|
+
summary: 'Delete a file path.',
|
|
100
|
+
tags: ['file'],
|
|
101
|
+
},
|
|
102
|
+
writeFile: {
|
|
103
|
+
summary: 'Write text data to a file path.',
|
|
104
|
+
tags: ['file'],
|
|
105
|
+
},
|
|
106
|
+
getFileInfo: {
|
|
107
|
+
summary: 'Read file stat information for a sandbox path.',
|
|
108
|
+
tags: ['file'],
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
getImageInfo: {
|
|
113
|
+
summary:
|
|
114
|
+
'Read width, height, and metadata information for an image source.',
|
|
115
|
+
kind: 'api',
|
|
116
|
+
tags: ['media', 'image'],
|
|
117
|
+
},
|
|
118
|
+
getLocation: {
|
|
119
|
+
summary: 'Get the current device location once.',
|
|
120
|
+
description:
|
|
121
|
+
'The host may request runtime location permission before resolving.',
|
|
122
|
+
kind: 'api',
|
|
123
|
+
tags: ['location'],
|
|
124
|
+
},
|
|
125
|
+
getScreenBrightness: {
|
|
126
|
+
summary: 'Read the current screen brightness reported by the device.',
|
|
127
|
+
kind: 'api',
|
|
128
|
+
tags: ['device'],
|
|
129
|
+
},
|
|
130
|
+
getStorage: {
|
|
131
|
+
summary:
|
|
132
|
+
'Read a JSON-serializable value from host-backed key-value storage.',
|
|
133
|
+
kind: 'api',
|
|
134
|
+
tags: ['storage'],
|
|
135
|
+
},
|
|
136
|
+
getStorageInfo: {
|
|
137
|
+
summary: 'Read host-backed storage usage and key information.',
|
|
138
|
+
kind: 'api',
|
|
139
|
+
tags: ['storage'],
|
|
140
|
+
},
|
|
141
|
+
getSystemInfo: {
|
|
142
|
+
summary:
|
|
143
|
+
'Return device, screen, and safe-area information for layout and diagnostics.',
|
|
144
|
+
kind: 'api',
|
|
145
|
+
tags: ['device', 'layout'],
|
|
146
|
+
},
|
|
147
|
+
onLocationChange: {
|
|
148
|
+
summary: 'Subscribe to host location change events.',
|
|
149
|
+
kind: 'subscription',
|
|
150
|
+
tags: ['location', 'subscription'],
|
|
151
|
+
},
|
|
152
|
+
makePhoneCall: {
|
|
153
|
+
summary: 'Open the system dialer for a phone number.',
|
|
154
|
+
kind: 'api',
|
|
155
|
+
tags: ['device', 'communication'],
|
|
156
|
+
},
|
|
157
|
+
getMiniAppUpdateInfo: {
|
|
158
|
+
summary:
|
|
159
|
+
'Read the installed miniapp version, update strategy, and whether a newer remote version exists.',
|
|
160
|
+
kind: 'api',
|
|
161
|
+
tags: ['miniapp', 'update'],
|
|
162
|
+
},
|
|
163
|
+
applyMiniAppUpdate: {
|
|
164
|
+
summary:
|
|
165
|
+
'Install the newest available bundle for the current miniapp and return the updated version state.',
|
|
166
|
+
kind: 'api',
|
|
167
|
+
tags: ['miniapp', 'update'],
|
|
168
|
+
},
|
|
169
|
+
saveMedia: {
|
|
170
|
+
summary: 'Save a photo or video into the system media library.',
|
|
171
|
+
kind: 'api',
|
|
172
|
+
tags: ['media'],
|
|
173
|
+
},
|
|
174
|
+
getNetworkType: {
|
|
175
|
+
summary: 'Read the current network connection type and connectivity state.',
|
|
176
|
+
kind: 'api',
|
|
177
|
+
tags: ['network'],
|
|
178
|
+
},
|
|
179
|
+
onNetworkStatusChange: {
|
|
180
|
+
summary: 'Subscribe to host network status change events.',
|
|
181
|
+
kind: 'subscription',
|
|
182
|
+
tags: ['network', 'subscription'],
|
|
183
|
+
},
|
|
184
|
+
onUserCaptureScreen: {
|
|
185
|
+
summary: 'Subscribe to host screenshot capture events.',
|
|
186
|
+
kind: 'subscription',
|
|
187
|
+
tags: ['device', 'subscription'],
|
|
188
|
+
},
|
|
189
|
+
previewImage: {
|
|
190
|
+
summary:
|
|
191
|
+
'Open a host-managed fullscreen image preview modal for one or more image URLs.',
|
|
192
|
+
kind: 'api',
|
|
193
|
+
tags: ['media', 'image', 'modal'],
|
|
194
|
+
},
|
|
195
|
+
scanCode: {
|
|
196
|
+
summary:
|
|
197
|
+
'Open a host-managed scanner modal and return the first detected barcode or QR code.',
|
|
198
|
+
kind: 'api',
|
|
199
|
+
tags: ['camera', 'scanner', 'modal'],
|
|
200
|
+
},
|
|
201
|
+
scanCodeSafe: {
|
|
202
|
+
summary:
|
|
203
|
+
'Open the host scanner modal and always resolve with an ok/error result object.',
|
|
204
|
+
kind: 'api',
|
|
205
|
+
tags: ['camera', 'scanner', 'modal'],
|
|
206
|
+
},
|
|
207
|
+
onAccelerometerChange: {
|
|
208
|
+
summary: 'Subscribe to host accelerometer events.',
|
|
209
|
+
kind: 'subscription',
|
|
210
|
+
tags: ['sensor', 'subscription'],
|
|
211
|
+
},
|
|
212
|
+
onGyroscopeChange: {
|
|
213
|
+
summary: 'Subscribe to host gyroscope events.',
|
|
214
|
+
kind: 'subscription',
|
|
215
|
+
tags: ['sensor', 'subscription'],
|
|
216
|
+
},
|
|
217
|
+
onMagnetometerChange: {
|
|
218
|
+
summary: 'Subscribe to host magnetometer events.',
|
|
219
|
+
kind: 'subscription',
|
|
220
|
+
tags: ['sensor', 'subscription'],
|
|
221
|
+
},
|
|
222
|
+
onBarometerChange: {
|
|
223
|
+
summary: 'Subscribe to host barometer events.',
|
|
224
|
+
kind: 'subscription',
|
|
225
|
+
tags: ['sensor', 'subscription'],
|
|
226
|
+
},
|
|
227
|
+
setClipboardData: {
|
|
228
|
+
summary: 'Write plain text to the system clipboard.',
|
|
229
|
+
kind: 'api',
|
|
230
|
+
tags: ['clipboard'],
|
|
231
|
+
},
|
|
232
|
+
setStorage: {
|
|
233
|
+
summary:
|
|
234
|
+
'Persist a JSON-serializable value in host-backed key-value storage.',
|
|
235
|
+
kind: 'api',
|
|
236
|
+
tags: ['storage'],
|
|
237
|
+
},
|
|
238
|
+
storage: {
|
|
239
|
+
summary:
|
|
240
|
+
'Low-level storage helpers for host-backed key-value access and serialization.',
|
|
241
|
+
kind: 'utility',
|
|
242
|
+
tags: ['storage'],
|
|
243
|
+
methods: {
|
|
244
|
+
serializeStorageValue: {
|
|
245
|
+
summary:
|
|
246
|
+
'Serialize a JSON-serializable value before writing to storage.',
|
|
247
|
+
tags: ['storage'],
|
|
248
|
+
},
|
|
249
|
+
deserializeStorageValue: {
|
|
250
|
+
summary: 'Deserialize a stored JSON string into a typed value.',
|
|
251
|
+
tags: ['storage'],
|
|
252
|
+
},
|
|
253
|
+
setStorageItem: {
|
|
254
|
+
summary: 'Persist a raw storage item by key.',
|
|
255
|
+
tags: ['storage'],
|
|
256
|
+
},
|
|
257
|
+
getStorageItem: {
|
|
258
|
+
summary: 'Read a raw storage item by key.',
|
|
259
|
+
tags: ['storage'],
|
|
260
|
+
},
|
|
261
|
+
removeStorageItem: {
|
|
262
|
+
summary: 'Remove a raw storage item by key.',
|
|
263
|
+
tags: ['storage'],
|
|
264
|
+
},
|
|
265
|
+
clearStorageItems: {
|
|
266
|
+
summary: 'Clear all host-backed storage entries.',
|
|
267
|
+
tags: ['storage'],
|
|
268
|
+
},
|
|
269
|
+
getStorageKeys: {
|
|
270
|
+
summary: 'List all keys in host-backed storage.',
|
|
271
|
+
tags: ['storage'],
|
|
272
|
+
},
|
|
273
|
+
getStorageCurrentSize: {
|
|
274
|
+
summary: 'Return the approximate storage size in KB.',
|
|
275
|
+
tags: ['storage'],
|
|
276
|
+
},
|
|
277
|
+
},
|
|
278
|
+
},
|
|
279
|
+
removeFile: {
|
|
280
|
+
summary: 'Remove a file from the miniapp sandbox.',
|
|
281
|
+
kind: 'api',
|
|
282
|
+
tags: ['file'],
|
|
283
|
+
},
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
export function getNebulaApiDescriptions(): NebulaPublicApiDescriptionMap {
|
|
287
|
+
return nebulaApiDescriptions;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export function getHostApiDescriptions(
|
|
291
|
+
timeoutMs: number = 15000,
|
|
292
|
+
): Promise<NebulaHostApiDescriptionMap> {
|
|
293
|
+
return Miniapp.getHostApiDescriptions(timeoutMs);
|
|
294
|
+
}
|
package/src/file.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { createHostTask, invokeHostApi } from './runtime/host';
|
|
2
|
+
|
|
3
|
+
export interface HeadersRes {
|
|
4
|
+
header: Record<string, string>;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface Task<T, P> {
|
|
8
|
+
abort(): Promise<void>;
|
|
9
|
+
onProgressUpdate(listener: (res: P) => void): void;
|
|
10
|
+
offProgressUpdate(listener: (res: P) => void): void;
|
|
11
|
+
onHeadersReceived(listener: (res: HeadersRes) => void): void;
|
|
12
|
+
offHeadersReceived(listener: (res: HeadersRes) => void): void;
|
|
13
|
+
then<TResult1 = T, TResult2 = never>(
|
|
14
|
+
onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | null,
|
|
15
|
+
onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null,
|
|
16
|
+
): Promise<TResult1 | TResult2>;
|
|
17
|
+
catch<TResult = never>(
|
|
18
|
+
onrejected?: ((reason: unknown) => TResult | PromiseLike<TResult>) | null,
|
|
19
|
+
): Promise<T | TResult>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface DownloadProgressRes {
|
|
23
|
+
progress: number;
|
|
24
|
+
totalBytesWritten: number;
|
|
25
|
+
totalBytesExpectedToWrite: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface DownloadFileResult {
|
|
29
|
+
tempFilePath: string;
|
|
30
|
+
statusCode: number;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface DownloadFileOption {
|
|
34
|
+
url: string;
|
|
35
|
+
header?: Record<string, string>;
|
|
36
|
+
timeout?: number;
|
|
37
|
+
filePath?: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export type DownloadTask = Task<DownloadFileResult, DownloadProgressRes>;
|
|
41
|
+
|
|
42
|
+
export const downloadFile = (options: DownloadFileOption): DownloadTask => {
|
|
43
|
+
return createHostTask<DownloadFileResult, DownloadProgressRes, HeadersRes>(
|
|
44
|
+
'downloadFile',
|
|
45
|
+
options,
|
|
46
|
+
{
|
|
47
|
+
timeoutMs: 60000,
|
|
48
|
+
},
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export interface UploadProgressRes {
|
|
53
|
+
progress: number;
|
|
54
|
+
totalBytesSent: number;
|
|
55
|
+
totalBytesExpectedToSend: number;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface UploadFileResult {
|
|
59
|
+
data: string;
|
|
60
|
+
statusCode: number;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface UploadFileOption {
|
|
64
|
+
url: string;
|
|
65
|
+
filePath: string;
|
|
66
|
+
name: string;
|
|
67
|
+
header?: Record<string, string>;
|
|
68
|
+
formData?: Record<string, string>;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type UploadTask = Task<UploadFileResult, UploadProgressRes>;
|
|
72
|
+
|
|
73
|
+
export const uploadFile = (options: UploadFileOption): UploadTask => {
|
|
74
|
+
return createHostTask<UploadFileResult, UploadProgressRes, HeadersRes>(
|
|
75
|
+
'uploadFile',
|
|
76
|
+
options,
|
|
77
|
+
{
|
|
78
|
+
timeoutMs: 60000,
|
|
79
|
+
},
|
|
80
|
+
);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export interface RemoveFileOption {
|
|
84
|
+
filePath: string;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export const removeFile = (options: RemoveFileOption): Promise<void> => {
|
|
88
|
+
return invokeHostApi<void>('removeFile', options);
|
|
89
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { invokeHostApi } from '../runtime/host';
|
|
2
|
+
|
|
3
|
+
export interface GetFileInfoOption {
|
|
4
|
+
filePath: string;
|
|
5
|
+
digestAlgorithm?: 'md5' | 'sha1' | 'sha256';
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface GetFileInfoResult {
|
|
9
|
+
size: number;
|
|
10
|
+
digest: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const getFileInfo = (
|
|
14
|
+
options: GetFileInfoOption,
|
|
15
|
+
): Promise<GetFileInfoResult> => {
|
|
16
|
+
return invokeHostApi<GetFileInfoResult>('getFileInfo', options);
|
|
17
|
+
};
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { invokeHostApi } from '../runtime/host';
|
|
2
|
+
import { GetFileInfoOption, GetFileInfoResult } from '../getFileInfo';
|
|
3
|
+
|
|
4
|
+
export interface FileAccessOption {
|
|
5
|
+
path: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface FileAppendOption {
|
|
9
|
+
filePath: string;
|
|
10
|
+
data: string;
|
|
11
|
+
encoding?: 'ascii' | 'base64' | 'utf8';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface FileSaveOption {
|
|
15
|
+
tempFilePath: string;
|
|
16
|
+
filePath?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface FileSaveResult {
|
|
20
|
+
savedFilePath: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface FileCopyOption {
|
|
24
|
+
srcPath: string;
|
|
25
|
+
destPath: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface FileMkdirOption {
|
|
29
|
+
dirPath: string;
|
|
30
|
+
recursive?: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface FileReadOption {
|
|
34
|
+
filePath: string;
|
|
35
|
+
encoding?: 'ascii' | 'base64' | 'utf8';
|
|
36
|
+
position?: number;
|
|
37
|
+
length?: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface FileReadResult {
|
|
41
|
+
data: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface FileReaddirOption {
|
|
45
|
+
dirPath: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface FileReaddirResult {
|
|
49
|
+
files: string[];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface FileRenameOption {
|
|
53
|
+
oldPath: string;
|
|
54
|
+
newPath: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface FileRmdirOption {
|
|
58
|
+
dirPath: string;
|
|
59
|
+
recursive?: boolean;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface FileUnlinkOption {
|
|
63
|
+
filePath: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface FileWriteOption {
|
|
67
|
+
filePath: string;
|
|
68
|
+
data: string;
|
|
69
|
+
encoding?: 'ascii' | 'base64' | 'utf8';
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface FileSystemManager {
|
|
73
|
+
access(options: FileAccessOption): Promise<void>;
|
|
74
|
+
appendFile(options: FileAppendOption): Promise<void>;
|
|
75
|
+
saveFile(options: FileSaveOption): Promise<FileSaveResult>;
|
|
76
|
+
copyFile(options: FileCopyOption): Promise<void>;
|
|
77
|
+
mkdir(options: FileMkdirOption): Promise<void>;
|
|
78
|
+
readFile(options: FileReadOption): Promise<FileReadResult>;
|
|
79
|
+
readdir(options: FileReaddirOption): Promise<FileReaddirResult>;
|
|
80
|
+
rename(options: FileRenameOption): Promise<void>;
|
|
81
|
+
rmdir(options: FileRmdirOption): Promise<void>;
|
|
82
|
+
unlink(options: FileUnlinkOption): Promise<void>;
|
|
83
|
+
writeFile(options: FileWriteOption): Promise<void>;
|
|
84
|
+
getFileInfo(options: GetFileInfoOption): Promise<GetFileInfoResult>;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
class FileSystemManagerImpl implements FileSystemManager {
|
|
88
|
+
public access(options: FileAccessOption): Promise<void> {
|
|
89
|
+
return invokeHostApi<void>('fileSystem.access', options);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
public appendFile(options: FileAppendOption): Promise<void> {
|
|
93
|
+
return invokeHostApi<void>('fileSystem.appendFile', options);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
public saveFile(options: FileSaveOption): Promise<FileSaveResult> {
|
|
97
|
+
return invokeHostApi<FileSaveResult>('fileSystem.saveFile', options);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
public copyFile(options: FileCopyOption): Promise<void> {
|
|
101
|
+
return invokeHostApi<void>('fileSystem.copyFile', options);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
public mkdir(options: FileMkdirOption): Promise<void> {
|
|
105
|
+
return invokeHostApi<void>('fileSystem.mkdir', options);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
public readFile(options: FileReadOption): Promise<FileReadResult> {
|
|
109
|
+
return invokeHostApi<FileReadResult>('fileSystem.readFile', options);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
public readdir(options: FileReaddirOption): Promise<FileReaddirResult> {
|
|
113
|
+
return invokeHostApi<FileReaddirResult>('fileSystem.readdir', options);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
public rename(options: FileRenameOption): Promise<void> {
|
|
117
|
+
return invokeHostApi<void>('fileSystem.rename', options);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
public rmdir(options: FileRmdirOption): Promise<void> {
|
|
121
|
+
return invokeHostApi<void>('fileSystem.rmdir', options);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
public unlink(options: FileUnlinkOption): Promise<void> {
|
|
125
|
+
return invokeHostApi<void>('fileSystem.unlink', options);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
public writeFile(options: FileWriteOption): Promise<void> {
|
|
129
|
+
return invokeHostApi<void>('fileSystem.writeFile', options);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
public getFileInfo(options: GetFileInfoOption): Promise<GetFileInfoResult> {
|
|
133
|
+
return invokeHostApi<GetFileInfoResult>('fileSystem.getFileInfo', options);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const fileSystemManager = new FileSystemManagerImpl();
|
|
138
|
+
|
|
139
|
+
export const getFileSystemManager = (): FileSystemManager => {
|
|
140
|
+
return fileSystemManager;
|
|
141
|
+
};
|