@cogover/sdk 0.1.0 → 0.1.2
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
|
|
4
|
-
|
|
5
|
-
documentation và type checking.
|
|
3
|
+
The TypeScript SDK for customer code running on Cogover. The package includes
|
|
4
|
+
type declarations for IDE autocomplete, inline documentation, and type checking.
|
|
6
5
|
|
|
7
|
-
##
|
|
6
|
+
## Requirements
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
- Node.js 18 or later.
|
|
9
|
+
- A TypeScript project using ECMAScript Modules (ESM).
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
10
12
|
|
|
11
13
|
```bash
|
|
12
14
|
npm install @cogover/sdk
|
|
13
15
|
```
|
|
14
16
|
|
|
15
|
-
##
|
|
17
|
+
## Quick start
|
|
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
|
+
The SDK uses named exports and currently has no default export.
|
|
26
27
|
|
|
27
|
-
##
|
|
28
|
+
## Use in a 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
|
+
A handler must default-export a synchronous function that accepts
|
|
47
|
+
`inputJson: string` and returns a JSON string or `null`.
|
|
41
48
|
|
|
42
|
-
|
|
49
|
+
## API
|
|
43
50
|
|
|
44
|
-
|
|
45
|
-
|
|
51
|
+
### `createGreeting(name)`
|
|
52
|
+
|
|
53
|
+
Creates a greeting by adding the `Hello ` prefix to a name.
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
function createGreeting(name: string): string;
|
|
46
57
|
```
|
|
47
58
|
|
|
48
|
-
|
|
59
|
+
Example:
|
|
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
|
+
Type declarations are included in the package. After installation, IDEs can
|
|
68
|
+
resolve `@cogover/sdk` without a separate type package.
|
|
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
|
+
Recommended `tsconfig.json` options:
|
|
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)
|