@rei-standard/amsg-client 1.2.1 → 2.0.0-pre1
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 +48 -15
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
# @rei-standard/amsg-client
|
|
2
2
|
|
|
3
|
-
`@rei-standard/amsg-client` 是 ReiStandard 主动消息标准的浏览器端 SDK
|
|
3
|
+
`@rei-standard/amsg-client` 是 ReiStandard 主动消息标准的浏览器端 SDK 包,负责加密请求、解密响应和 Push 订阅。
|
|
4
4
|
|
|
5
|
-
## 文档导航
|
|
6
|
-
|
|
7
|
-
- [SDK 总览](../README.md)
|
|
8
|
-
- [主 README](../../../README.md)
|
|
9
|
-
- [Service Worker 规范](../../../standards/service-worker-specification.md)
|
|
10
5
|
|
|
11
6
|
## 安装
|
|
12
7
|
|
|
@@ -14,7 +9,7 @@
|
|
|
14
9
|
npm install @rei-standard/amsg-client
|
|
15
10
|
```
|
|
16
11
|
|
|
17
|
-
##
|
|
12
|
+
## 快速使用
|
|
18
13
|
|
|
19
14
|
```js
|
|
20
15
|
import { ReiClient } from '@rei-standard/amsg-client';
|
|
@@ -25,16 +20,54 @@ const client = new ReiClient({
|
|
|
25
20
|
});
|
|
26
21
|
|
|
27
22
|
await client.init();
|
|
23
|
+
|
|
24
|
+
await navigator.serviceWorker.register('/service-worker.js');
|
|
25
|
+
const registration = await navigator.serviceWorker.ready;
|
|
26
|
+
const subscription = await client.subscribePush(
|
|
27
|
+
window.__VAPID_PUBLIC_KEY__,
|
|
28
|
+
registration
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
await client.scheduleMessage({
|
|
32
|
+
contactName: 'Rei',
|
|
33
|
+
messageType: 'fixed',
|
|
34
|
+
userMessage: '下班记得带伞~',
|
|
35
|
+
firstSendTime: new Date(Date.now() + 60 * 1000).toISOString(),
|
|
36
|
+
recurrenceType: 'none',
|
|
37
|
+
pushSubscription: subscription.toJSON()
|
|
38
|
+
});
|
|
28
39
|
```
|
|
29
40
|
|
|
30
|
-
|
|
41
|
+
## 导出 API(Exports)
|
|
42
|
+
|
|
43
|
+
- `ReiClient`
|
|
44
|
+
|
|
45
|
+
`ReiClient` 主要方法:
|
|
46
|
+
|
|
47
|
+
- `init()`
|
|
48
|
+
- `scheduleMessage(payload)`
|
|
49
|
+
- `updateMessage(uuid, updates)`
|
|
50
|
+
- `cancelMessage(uuid)`
|
|
51
|
+
- `listMessages(opts)`
|
|
52
|
+
- `subscribePush(vapidPublicKey, registration)`
|
|
53
|
+
|
|
54
|
+
## 模块格式与类型(ESM/CJS/Types)
|
|
55
|
+
|
|
56
|
+
- ESM:`import { ReiClient } from '@rei-standard/amsg-client'`
|
|
57
|
+
- CJS:`const { ReiClient } = require('@rei-standard/amsg-client')`
|
|
58
|
+
- 类型:包内提供 `types` 入口(`dist/index.d.ts`)
|
|
59
|
+
|
|
60
|
+
## 运行环境与要求
|
|
31
61
|
|
|
32
|
-
-
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
-
|
|
62
|
+
- 浏览器环境(需 `fetch`、`crypto.subtle`)
|
|
63
|
+
- Push 订阅需可用 Service Worker 与 Push API
|
|
64
|
+
- 需要可用的 `baseUrl`(示例:`/api/v1`)
|
|
65
|
+
- `userId` 必须是 UUID v4
|
|
36
66
|
|
|
37
|
-
##
|
|
67
|
+
## 相关链接(绝对 URL)
|
|
38
68
|
|
|
39
|
-
-
|
|
40
|
-
-
|
|
69
|
+
- [SDK Workspace 总览](https://github.com/Tosd0/ReiStandard/blob/main/packages/rei-standard-amsg/README.md)
|
|
70
|
+
- [Server 包 README](https://github.com/Tosd0/ReiStandard/blob/main/packages/rei-standard-amsg/server/README.md)
|
|
71
|
+
- [SW 包 README](https://github.com/Tosd0/ReiStandard/blob/main/packages/rei-standard-amsg/sw/README.md)
|
|
72
|
+
- [Service Worker 规范](https://github.com/Tosd0/ReiStandard/blob/main/standards/service-worker-specification.md)
|
|
73
|
+
- [API 技术规范](https://github.com/Tosd0/ReiStandard/blob/main/standards/active-messaging-api.md)
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED