@cogover/sdk 0.1.0 → 0.1.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/README.md +55 -37
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,69 +1,87 @@
|
|
|
1
1
|
# `@cogover/sdk`
|
|
2
2
|
|
|
3
|
-
TypeScript SDK dành cho code khách hàng chạy trên Cogover. Package
|
|
4
|
-
|
|
5
|
-
documentation và type checking.
|
|
3
|
+
TypeScript SDK dành cho code khách hàng chạy trên Cogover. Package có sẵn type
|
|
4
|
+
declaration để IDE cung cấp autocomplete, documentation và type checking.
|
|
6
5
|
|
|
7
|
-
##
|
|
6
|
+
## Yêu cầu
|
|
7
|
+
|
|
8
|
+
- Node.js 18 trở lên.
|
|
9
|
+
- Project TypeScript sử dụng ECMAScript Modules (ESM).
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
## Cài đặt
|
|
10
12
|
|
|
11
13
|
```bash
|
|
12
14
|
npm install @cogover/sdk
|
|
13
15
|
```
|
|
14
16
|
|
|
15
|
-
## Sử dụng
|
|
17
|
+
## Sử dụng nhanh
|
|
16
18
|
|
|
17
19
|
```typescript
|
|
18
20
|
import { createGreeting } from "@cogover/sdk";
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
const greeting = createGreeting("Cogover");
|
|
23
|
+
console.log(greeting); // Hello Cogover
|
|
21
24
|
```
|
|
22
25
|
|
|
23
|
-
|
|
24
|
-
`cogover-sdk/docs/` của source repository và không được đóng gói vào npm
|
|
25
|
-
package.
|
|
26
|
+
SDK sử dụng named exports và hiện không có default export.
|
|
26
27
|
|
|
27
|
-
##
|
|
28
|
+
## Sử dụng trong Cogover handler
|
|
28
29
|
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
```typescript
|
|
31
|
+
import { createGreeting } from "@cogover/sdk";
|
|
32
|
+
|
|
33
|
+
interface Input {
|
|
34
|
+
name: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default function handler(inputJson: string): string {
|
|
38
|
+
const input: Input = JSON.parse(inputJson);
|
|
39
|
+
|
|
40
|
+
return JSON.stringify({
|
|
41
|
+
greeting: createGreeting(input.name)
|
|
42
|
+
});
|
|
43
|
+
}
|
|
38
44
|
```
|
|
39
45
|
|
|
40
|
-
|
|
46
|
+
Handler phải default-export một synchronous function nhận `inputJson: string` và trả
|
|
47
|
+
về JSON string hoặc `null`.
|
|
41
48
|
|
|
42
|
-
|
|
49
|
+
## API
|
|
43
50
|
|
|
44
|
-
|
|
45
|
-
|
|
51
|
+
### `createGreeting(name)`
|
|
52
|
+
|
|
53
|
+
Tạo lời chào bằng cách thêm tiền tố `Hello ` trước tên.
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
function createGreeting(name: string): string;
|
|
46
57
|
```
|
|
47
58
|
|
|
48
|
-
|
|
59
|
+
Ví dụ:
|
|
49
60
|
|
|
50
|
-
```
|
|
51
|
-
|
|
61
|
+
```typescript
|
|
62
|
+
createGreeting("Cogover"); // "Hello Cogover"
|
|
52
63
|
```
|
|
53
64
|
|
|
54
|
-
|
|
55
|
-
nếu typecheck hoặc test thất bại.
|
|
65
|
+
## TypeScript
|
|
56
66
|
|
|
57
|
-
|
|
67
|
+
Package đã bao gồm file khai báo type. Sau khi chạy `npm install`, IDE có thể
|
|
68
|
+
resolve trực tiếp `@cogover/sdk` mà không cần cài thêm package type.
|
|
58
69
|
|
|
59
|
-
|
|
60
|
-
khách hàng được compile trên server, TypeScript Runtime thay import này bằng
|
|
61
|
-
`runtime-tools/cogover-sdk.mjs` và không bundle `node_modules` của khách hàng.
|
|
70
|
+
Cấu hình `tsconfig.json` khuyến nghị:
|
|
62
71
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
72
|
+
```json
|
|
73
|
+
{
|
|
74
|
+
"compilerOptions": {
|
|
75
|
+
"target": "ES2022",
|
|
76
|
+
"module": "ESNext",
|
|
77
|
+
"moduleResolution": "Bundler",
|
|
78
|
+
"strict": true,
|
|
79
|
+
"noEmit": true,
|
|
80
|
+
"skipLibCheck": true
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
```
|
|
66
84
|
|
|
67
85
|
## License
|
|
68
86
|
|
|
69
|
-
|
|
87
|
+
[MIT](LICENSE)
|