@docoi/mys-sdk 1.0.3 → 1.1.0

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/api/biz.d.ts CHANGED
@@ -1,17 +1,18 @@
1
- import { Callbacks, NativeResponse, ShareWebCardParams, ShareImageParams, ShareImageResult, ShowAdParams, BindGameRoleParams, LoginResult, GetTokenResult, GetCircleInfoResult } from '../types';
1
+ import { Callbacks, NativeResponse, EventListenOptions, ShareWebCardParams, ShareImageParams, ShareImageResult, ShowAdParams, BindGameRoleParams, OpenCommentPanelParams, VoteActionParams, OpenGiftBagParams, OpenFriendsListParams, OpenFriendsListResult, UpdateDataParams, LoginResult, GetTokenResult, GetCircleInfoResult, VoteData, AdFinishedCallback, MemberActivateHandler } from '../types';
2
2
  /**
3
- * 登录授权,获取用户信息。
3
+ * 登录授权。
4
4
  *
5
- * @app 1.2.3
5
+ * @note App 4.4.0 以下 Native 只保证登录动作被处理,result.isLogin 不一定返回。
6
+ *
7
+ * @app 2.7.0
6
8
  * @example
7
- * const res = await mys.login()
8
- * console.log(res.result.code)
9
+ * await mys.login()
9
10
  */
10
11
  export declare function login(params?: Callbacks<LoginResult>): Promise<NativeResponse<LoginResult>>;
11
12
  /**
12
13
  * 获取当前用户的登录 Token。
13
14
  *
14
- * @app 1.2.3
15
+ * @app 3.2.0
15
16
  * @example
16
17
  * const res = await mys.getToken()
17
18
  * console.log(res.result.token)
@@ -20,39 +21,59 @@ export declare function getToken(params?: Callbacks<GetTokenResult>): Promise<Na
20
21
  /**
21
22
  * 获取当前社群/圈子信息。
22
23
  *
23
- * @app 1.2.3
24
+ * @app 3.6.0
24
25
  * @example
25
26
  * const res = await mys.getCurrentCircleInfo()
26
- * console.log(res.result.name)
27
+ * console.log(res.result.serverId)
27
28
  */
28
29
  export declare function getCurrentCircleInfo(params?: Callbacks<GetCircleInfoResult>): Promise<NativeResponse<GetCircleInfoResult>>;
29
30
  /**
30
31
  * 分享网页卡片到社交平台(微信、QQ 等)。
31
32
  *
32
- * @note
33
- * title 不能为空。
34
- * shareTypes 默认 [1, 2, 3]。
33
+ * @note 响应只表示分享面板已唤起,不包含分享结果;用户完成分享后通过 onShared 回调通知,不需要单独监听事件。
34
+ * @note activityDetail 传对象时会序列化为 JSON 字符串后下发;trackData 需自行 JSON.stringify。
35
+ * @note onShared、getSharePictureUrl 不需要手动取消,触发后、调用失败或下一次调用 shareWebCard 时自动取消。
36
+ * @note 每次调用都会重新注册 getSharePictureUrl,截图结果的缓存要放在函数外面(页面级变量),否则每次分享都会重新截图。
35
37
  *
36
- * @app 1.2.3
38
+ * @app 2.9.0
37
39
  * @example
40
+ * // 只关心分享结果:用户完成分享后触发 onShared,取消分享不会触发
38
41
  * await mys.shareWebCard({
39
- * title: '精彩文章',
40
- * content: '点开看看',
42
+ * title: '梦游社App马到成功',
43
+ * content: '梦游社App一往无前',
41
44
  * icon: 'https://example.com/icon.png',
42
- * shareUrl: 'https://example.com/article/1',
43
- * shareTypes: [1, 2, 3],
45
+ * shareUrl: 'https://docoi.cc',
46
+ * daokeUrl: 'daoke://page?type=5&h5Type=4&url=https://docoi.cc',
47
+ * externalContent: '梦游社App一往无前',
48
+ * shareTypes: [ShareType.RecentContacts, ShareType.External, ShareType.Channel],
49
+ * onShared: (res) => {
50
+ * console.log('分享完成', res?.shareChannel)
51
+ * },
52
+ * })
53
+ *
54
+ * // 分享图片:isSharePic 为 true 时提供 getSharePictureUrl,其余字段同上。
55
+ * // 用户点击客户端的生成图片按钮时 Native 才会调用它,在里面截图并上传;失败时返回 { pictureUrl: undefined }
56
+ * await mys.shareWebCard({
57
+ * // ...其余字段同上
58
+ * isSharePic: true,
59
+ * getSharePictureUrl: async () => ({ pictureUrl: await generateShareImg() }),
60
+ * onShared: (res) => {
61
+ * console.log('分享完成', res?.shareChannel)
62
+ * },
44
63
  * })
64
+ *
65
+ * export async function share(getSharePictureUrl: SharePictureUrlHandler) {
66
+ * await mys.shareWebCard({ ..., isSharePic: true, getSharePictureUrl })
67
+ * }
45
68
  */
46
69
  export declare function shareWebCard(params: ShareWebCardParams): Promise<NativeResponse<void>>;
47
70
  /**
48
71
  * 唤起客户端图片分享弹窗,分享网络图片。
49
72
  *
50
- * 弹窗提供微信好友、微信朋友圈、QQ 好友、保存图片、取消五个操作,用户点击后通过 result.action 返回所选操作。
51
- *
52
- * @note
53
- * url 不能为空,且必须为 http(s) 网络地址。
54
- * 点击取消按钮属于成功响应,result.action 为 cancel。
73
+ * @note 弹窗提供微信好友、微信朋友圈、QQ 好友、保存图片、取消五个操作,用户点击后通过 result.action 返回所选操作。
74
+ * @note 点击取消按钮属于成功响应,result.action 为 cancel。
55
75
  *
76
+ * @app 4.4.0
56
77
  * @example
57
78
  * const res = await mys.shareImage({ url: 'https://example.com/poster.png' })
58
79
  * console.log(res.result.action) // 'wechat' | 'moment' | 'qq' | 'save' | 'cancel'
@@ -61,30 +82,132 @@ export declare function shareImage(params: ShareImageParams): Promise<NativeResp
61
82
  /**
62
83
  * 打开添加自定义表情页面。
63
84
  *
64
- * @app 1.2.3
85
+ * @app 3.9.0
65
86
  * @example
66
87
  * await mys.openAddCustomEmoji()
67
88
  */
68
89
  export declare function openAddCustomEmoji(params?: Callbacks): Promise<NativeResponse<void>>;
69
90
  /**
70
- * 跳转绑定游戏角色页面。
91
+ * 打开动态评论区面板。
71
92
  *
72
- * @note
73
- * gameName 和 serverId 不能为空。
93
+ * @note 面板的打开、关闭状态可通过 onCommentPanelChange 监听。
74
94
  *
75
- * @app 1.2.3
95
+ * @app 4.2.0
96
+ * @example
97
+ * await mys.openCommentPanel({ serverId: 's123', dynamicId: 'd456', autoFocusInput: true })
98
+ */
99
+ export declare function openCommentPanel(params: OpenCommentPanelParams): Promise<NativeResponse<void>>;
100
+ /**
101
+ * 打开龙跃会员说明弹窗。
102
+ *
103
+ * @app 3.2.0
104
+ * @example
105
+ * await mys.showLongVipDesDialog()
106
+ */
107
+ export declare function showLongVipDesDialog(params?: Callbacks): Promise<NativeResponse<void>>;
108
+ /**
109
+ * 在客户端预览中点击投票或取消投票。
110
+ *
111
+ * @note 入参为当前投票数据(字段同返回值)加上被点击选项的下标 index,返回更新后的投票数据。
112
+ *
113
+ * @app 4.1.0
114
+ * @example
115
+ * const res = await mys.voteAction({ ...voteData, index: 0 })
116
+ * console.log(res.result.vote_total)
117
+ */
118
+ export declare function voteAction(params: VoteActionParams): Promise<NativeResponse<VoteData>>;
119
+ /**
120
+ * 打开好友选择列表,选中的好友在返回结果的 selectedList 里。
121
+ *
122
+ * @note 已选好友回显后继续选择,只会返回新增的好友(增量数据)。
123
+ * @note 低版本 App 的调用方式和返回值与新版一致,不需要区分版本,也不需要自己监听事件。
124
+ *
125
+ * @app 3.4.0
126
+ * @example
127
+ * const res = await mys.openFriendsList({ selectedUserIds: [] })
128
+ * console.log(res.result.selectedList)
129
+ */
130
+ export declare function openFriendsList(params: OpenFriendsListParams): Promise<NativeResponse<OpenFriendsListResult>>;
131
+ /**
132
+ * 跳转绑定游戏角色页面。
133
+ *
134
+ * @app 2.7.0
76
135
  * @example
77
136
  * await mys.toBindGameRole({ gameName: '大话西游', serverId: 's123' })
78
137
  */
79
138
  export declare function toBindGameRole(params: BindGameRoleParams): Promise<NativeResponse<void>>;
139
+ /**
140
+ * 通知 Native 游戏角色绑定成功。
141
+ *
142
+ * @app 3.2.0
143
+ * @example
144
+ * await mys.bindGameRoleSuccess()
145
+ */
146
+ export declare function bindGameRoleSuccess(params?: Callbacks): Promise<NativeResponse<void>>;
80
147
  /**
81
148
  * 展示原生广告视频。
82
149
  *
83
- * @note
84
- * type 不能为空。
150
+ * @note 广告播放完成后 Native 通过 onAdFinished 事件通知。
85
151
  *
86
- * @app 1.2.3
152
+ * @app 3.9.0
87
153
  * @example
88
- * await mys.showAd({ type: 1, circle_id: '123' })
154
+ * await mys.showAd({ type: 1, params: { circle_id: '123', module: 1 } })
89
155
  */
90
156
  export declare function showAd(params: ShowAdParams): Promise<NativeResponse<void>>;
157
+ /**
158
+ * 监听广告播放完成。
159
+ *
160
+ * @app 3.7.0
161
+ * @example
162
+ * mys.onAdFinished((res) => {
163
+ * console.log(res.module)
164
+ * })
165
+ */
166
+ export declare function onAdFinished(callback: AdFinishedCallback, options?: EventListenOptions): void;
167
+ /**
168
+ * 取消监听广告播放完成。
169
+ *
170
+ * @param callback 要取消的监听函数,不传则取消全部广告播放完成监听
171
+ * @app 3.7.0
172
+ * @example
173
+ * mys.offAdFinished()
174
+ */
175
+ export declare function offAdFinished(callback?: AdFinishedCallback): void;
176
+ /**
177
+ * 通知 Native 更新数据。
178
+ *
179
+ * @app 3.6.0
180
+ * @example
181
+ * await mys.updateData({ type: 3 })
182
+ * await mys.updateData({ type: 10, params: { server_id: 's123' } })
183
+ */
184
+ export declare function updateData(params: UpdateDataParams): Promise<NativeResponse<void>>;
185
+ /**
186
+ * 打开客户端背包。
187
+ *
188
+ * @app 3.2.0
189
+ * @example
190
+ * await mys.openGiftBag({ user_id: 'u1', server_id: 's123', openBag: true })
191
+ */
192
+ export declare function openGiftBag(params: OpenGiftBagParams): Promise<NativeResponse<void>>;
193
+ /**
194
+ * 注册会员激活通知的处理函数,Native 通知 H5 会员已激活时调用。
195
+ *
196
+ * @note 同一时间只保留一个处理函数,重复注册会覆盖。
197
+ * @note 页面卸载时应调用 offMemberActivate。
198
+ *
199
+ * @app 4.4.0
200
+ * @example
201
+ * mys.onMemberActivate(async () => {
202
+ * await reloadMemberData()
203
+ * })
204
+ */
205
+ export declare function onMemberActivate(handler: MemberActivateHandler): void;
206
+ /**
207
+ * 取消注册会员激活通知的处理函数。
208
+ *
209
+ * @app 4.4.0
210
+ * @example
211
+ * mys.offMemberActivate()
212
+ */
213
+ export declare function offMemberActivate(): void;
@@ -0,0 +1,68 @@
1
+ import { Callbacks, NativeResponse, NavigateToParams, OpenInExternalBrowserParams, OpenSchemeParams, OpenWebviewParams, SwitchTabParams } from '../../types';
2
+ /**
3
+ * 跳转到 App 底部 tab 页面。
4
+ *
5
+ * @note 不在 App 内时唤起 App,唤起失败(超时仍停留在当前页)时触发 onLaunchFail,由业务侧引导下载。
6
+ * @note 唤起 App 和 App 4.4.0 以下的跳转都是发出即成功,不代表页面已打开。
7
+ * @note App 4.4.0 以下能否跳转取决于目标页面自己的起始版本,不支持的返回 ENV_UNSUPPORTED(5002)。
8
+ *
9
+ * @app 4.4.0
10
+ * @example
11
+ * await mys.switchTab({ tab: 'discover', params: { subTab: 'square' } })
12
+ */
13
+ export declare function switchTab(params: SwitchTabParams): Promise<NativeResponse<void>>;
14
+ /**
15
+ * 跳转到 App 原生页面。type 指定目标页面,params 传入该页面所需参数(见下方「页面参数」);也可以传入 daoke:// 链接。
16
+ *
17
+ * @note 不在 App 内时唤起 App,唤起失败(超时仍停留在当前页)时触发 onLaunchFail,由业务侧引导下载。
18
+ * @note 唤起 App 和 App 4.4.0 以下的跳转都是发出即成功,不代表页面已打开。
19
+ * @note App 4.4.0 以下能否跳转取决于目标页面自己的起始版本,不支持的返回 ENV_UNSUPPORTED(5002);绑定游戏角色、添加自定义表情页面在低版本仍可用。
20
+ *
21
+ * @app 4.4.0
22
+ * @paramsMap NavigatePageParamsMap
23
+ * @example
24
+ * await mys.navigateTo({ type: 'userHomePage', params: { userId: '123' } })
25
+ * await mys.navigateTo({ url: 'daoke://page?type=11&user_id=123' })
26
+ */
27
+ export declare function navigateTo(params: NavigateToParams): Promise<NativeResponse<void>>;
28
+ /**
29
+ * 打开新的 Webview 页面,type 指定容器类型;用外部浏览器打开请使用 openInExternalBrowser。
30
+ *
31
+ * @note 不在 App 内时唤起 App,唤起失败(超时仍停留在当前页)时触发 onLaunchFail,由业务侧引导下载。
32
+ * @note 唤起 App 和 App 4.4.0 以下的跳转都是发出即成功,不代表页面已打开。
33
+ * @note App 4.4.0 以下 transparent 类型需要 App 3.8.0,更低版本返回 ENV_UNSUPPORTED(5002)。
34
+ *
35
+ * @app 4.4.0
36
+ * @example
37
+ * await mys.openWebview({ url: 'https://example.com', type: 'immersive' })
38
+ */
39
+ export declare function openWebview(params: OpenWebviewParams): Promise<NativeResponse<void>>;
40
+ /**
41
+ * 按 daoke://page?... 链接跳转,链接原样处理,适用于服务端下发的存量链接。
42
+ *
43
+ * @note 唤起 App、低版本兼容和 onLaunchFail 的规则与 navigateTo 一致。
44
+ *
45
+ * @app 4.4.0
46
+ * @example
47
+ * await mys.openScheme({ url: 'daoke://page?type=11&user_id=123' })
48
+ */
49
+ export declare function openScheme(params: OpenSchemeParams): Promise<NativeResponse<void>>;
50
+ /**
51
+ * 用系统外部浏览器打开链接。
52
+ *
53
+ * @note 不限制为 http(s),weixin:// 等 scheme 由系统决定能否打开。
54
+ * @note 只在 App 内有效,不会唤起 App。
55
+ *
56
+ * @app 3.2.0
57
+ * @example
58
+ * await mys.openInExternalBrowser({ url: 'https://example.com/download' })
59
+ */
60
+ export declare function openInExternalBrowser(params: OpenInExternalBrowserParams): Promise<NativeResponse<void>>;
61
+ /**
62
+ * 关闭当前 WebView 页面。
63
+ *
64
+ * @app 2.7.0
65
+ * @example
66
+ * await mys.closeWebView()
67
+ */
68
+ export declare function closeWebView(params?: Callbacks): Promise<NativeResponse<void>>;
@@ -0,0 +1,3 @@
1
+ import { DaokeLink } from './routes';
2
+ /** community 壳内交给父级、通用链接由浏览器自行处理,这两个分支检测不到结果,不会触发 onLaunchFail */
3
+ export declare function launchOutsideApp(link: DaokeLink, onLaunchFail?: () => void): void;
@@ -0,0 +1,22 @@
1
+ import { Query } from './routes';
2
+ /** openScheme 在新通道上的起始 App 版本,低于它走旧逻辑 */
3
+ export declare const OPEN_SCHEME_SINCE = "4.4.0";
4
+ export type LegacyPlan = {
5
+ via: 'redirectPage';
6
+ page: number;
7
+ params: Record<string, unknown>;
8
+ } | {
9
+ via: 'legacyMethod';
10
+ method: string;
11
+ data: Record<string, unknown>;
12
+ } | {
13
+ via: 'locationHref';
14
+ } | {
15
+ via: 'unsupported';
16
+ reason: string;
17
+ };
18
+ /**
19
+ * 页面起始版本(routes.ts since)高于当前 App 版本:有旧方法调旧方法(legacyMethod),有旧页面号走 redirectPage,否则不支持;
20
+ * 其余:iOS 走 redirectPage page 11,Android 走 location.href 由 WebView 拦截。
21
+ */
22
+ export declare function planLegacy(url: string, query: Query): LegacyPlan;