@gravito/satellite-announcement 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/CHANGELOG.md +10 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +56 -0
- package/package.json +28 -0
- package/src/Domain/Entities/Announcement.ts +26 -0
- package/src/index.ts +58 -0
- package/tsconfig.json +21 -0
package/CHANGELOG.md
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { ServiceProvider } from "@gravito/core";
|
|
3
|
+
var AnnouncementServiceProvider = class extends ServiceProvider {
|
|
4
|
+
register(_container) {
|
|
5
|
+
}
|
|
6
|
+
boot() {
|
|
7
|
+
const core = this.core;
|
|
8
|
+
if (!core) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
core.logger.info("\u{1F4E2} Announcement Satellite initialized");
|
|
12
|
+
core.router.prefix("/api/admin/v1/announcements").group((router) => {
|
|
13
|
+
router.get(
|
|
14
|
+
"/",
|
|
15
|
+
(ctx) => ctx.json([
|
|
16
|
+
{
|
|
17
|
+
id: "1",
|
|
18
|
+
title: "\u6625\u5B63\u8CFC\u7269\u7BC0\u958B\u8DD1",
|
|
19
|
+
type: "PROMOTION",
|
|
20
|
+
status: "PUBLISHED",
|
|
21
|
+
startsAt: "2025-03-01",
|
|
22
|
+
endsAt: "2025-03-31",
|
|
23
|
+
priority: 10
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
id: "2",
|
|
27
|
+
title: "\u7CFB\u7D71\u4F8B\u884C\u7DAD\u8B77\u901A\u77E5",
|
|
28
|
+
type: "MAINTENANCE",
|
|
29
|
+
status: "DRAFT",
|
|
30
|
+
startsAt: "2025-04-15",
|
|
31
|
+
priority: 100
|
|
32
|
+
}
|
|
33
|
+
])
|
|
34
|
+
);
|
|
35
|
+
router.post("/", async (ctx) => {
|
|
36
|
+
const body = await ctx.req.json();
|
|
37
|
+
return ctx.json({ message: "Created", id: "new-id", ...body }, 201);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
core.router.get(
|
|
41
|
+
"/api/v1/announcements/active",
|
|
42
|
+
(ctx) => ctx.json([
|
|
43
|
+
{
|
|
44
|
+
id: "1",
|
|
45
|
+
title: "\u6625\u5B63\u8CFC\u7269\u7BC0\u958B\u8DD1",
|
|
46
|
+
content: "\u5168\u7AD9 8 \u6298\u8D77...",
|
|
47
|
+
type: "PROMOTION",
|
|
48
|
+
displayType: "BANNER"
|
|
49
|
+
}
|
|
50
|
+
])
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
export {
|
|
55
|
+
AnnouncementServiceProvider
|
|
56
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gravito/satellite-announcement",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"build": "tsup src/index.ts --format esm --dts",
|
|
8
|
+
"typecheck": "bun tsc -p tsconfig.json --noEmit --skipLibCheck"
|
|
9
|
+
},
|
|
10
|
+
"types": "dist/index.d.ts",
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"@gravito/enterprise": "workspace:*",
|
|
13
|
+
"@gravito/atlas": "workspace:*",
|
|
14
|
+
"@gravito/core": "workspace:*"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"tsup": "^8.3.5",
|
|
18
|
+
"typescript": "^5.9.3"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/gravito-framework/gravito.git",
|
|
26
|
+
"directory": "satellites/announcement"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Entity } from '@gravito/enterprise'
|
|
2
|
+
|
|
3
|
+
export interface AnnouncementProps {
|
|
4
|
+
title: string
|
|
5
|
+
content: string
|
|
6
|
+
type: 'INFO' | 'WARNING' | 'PROMOTION' | 'MAINTENANCE'
|
|
7
|
+
displayType: 'BANNER' | 'MODAL' | 'NEWS'
|
|
8
|
+
status: 'DRAFT' | 'PUBLISHED' | 'EXPIRED'
|
|
9
|
+
priority: number
|
|
10
|
+
startsAt: Date
|
|
11
|
+
endsAt?: Date
|
|
12
|
+
createdAt: Date
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class Announcement extends Entity<string> {
|
|
16
|
+
private _props: AnnouncementProps
|
|
17
|
+
|
|
18
|
+
constructor(props: AnnouncementProps, id?: string) {
|
|
19
|
+
super(id || crypto.randomUUID())
|
|
20
|
+
this._props = props
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
unpack() {
|
|
24
|
+
return { ...this._props }
|
|
25
|
+
}
|
|
26
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type Container, ServiceProvider } from '@gravito/core'
|
|
2
|
+
|
|
3
|
+
export class AnnouncementServiceProvider extends ServiceProvider {
|
|
4
|
+
register(_container: Container): void {
|
|
5
|
+
// 注入解析器或 Repository
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
override boot(): void {
|
|
9
|
+
const core = this.core
|
|
10
|
+
if (!core) {
|
|
11
|
+
return
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
core.logger.info('📢 Announcement Satellite initialized')
|
|
15
|
+
|
|
16
|
+
core.router.prefix('/api/admin/v1/announcements').group((router) => {
|
|
17
|
+
router.get('/', (ctx) =>
|
|
18
|
+
ctx.json([
|
|
19
|
+
{
|
|
20
|
+
id: '1',
|
|
21
|
+
title: '春季購物節開跑',
|
|
22
|
+
type: 'PROMOTION',
|
|
23
|
+
status: 'PUBLISHED',
|
|
24
|
+
startsAt: '2025-03-01',
|
|
25
|
+
endsAt: '2025-03-31',
|
|
26
|
+
priority: 10,
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
id: '2',
|
|
30
|
+
title: '系統例行維護通知',
|
|
31
|
+
type: 'MAINTENANCE',
|
|
32
|
+
status: 'DRAFT',
|
|
33
|
+
startsAt: '2025-04-15',
|
|
34
|
+
priority: 100,
|
|
35
|
+
},
|
|
36
|
+
])
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
router.post('/', async (ctx) => {
|
|
40
|
+
const body = await ctx.req.json<Record<string, any>>()
|
|
41
|
+
return ctx.json({ message: 'Created', id: 'new-id', ...body }, 201)
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
// 公開 API: 客戶端獲取公告
|
|
46
|
+
core.router.get('/api/v1/announcements/active', (ctx) =>
|
|
47
|
+
ctx.json([
|
|
48
|
+
{
|
|
49
|
+
id: '1',
|
|
50
|
+
title: '春季購物節開跑',
|
|
51
|
+
content: '全站 8 折起...',
|
|
52
|
+
type: 'PROMOTION',
|
|
53
|
+
displayType: 'BANNER',
|
|
54
|
+
},
|
|
55
|
+
])
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "./dist",
|
|
5
|
+
"baseUrl": ".",
|
|
6
|
+
"skipLibCheck": true,
|
|
7
|
+
"types": ["bun-types"],
|
|
8
|
+
"paths": {
|
|
9
|
+
"@gravito/core": ["../../packages/core/src/index.ts"],
|
|
10
|
+
"@gravito/*": ["../../packages/*/src/index.ts"]
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"include": [
|
|
14
|
+
"src/**/*"
|
|
15
|
+
],
|
|
16
|
+
"exclude": [
|
|
17
|
+
"node_modules",
|
|
18
|
+
"dist",
|
|
19
|
+
"**/*.test.ts"
|
|
20
|
+
]
|
|
21
|
+
}
|