From 7e0c6ff9e446423a052e8bc23ac74b5ace1f6990 Mon Sep 17 00:00:00 2001 From: Jungzl <13jungzl@gmail.com> Date: Sun, 28 May 2023 16:36:21 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#65601=20add=20@typ?= =?UTF-8?q?es/zwlog-browser=20by=20@Jungzl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add @types/zwlog * rename to zwlog-browser --- types/zwlog-browser/index.d.ts | 195 +++++++++++++++++++++ types/zwlog-browser/tsconfig.json | 16 ++ types/zwlog-browser/tslint.json | 3 + types/zwlog-browser/zwlog-browser-tests.ts | 21 +++ 4 files changed, 235 insertions(+) create mode 100644 types/zwlog-browser/index.d.ts create mode 100644 types/zwlog-browser/tsconfig.json create mode 100644 types/zwlog-browser/tslint.json create mode 100644 types/zwlog-browser/zwlog-browser-tests.ts diff --git a/types/zwlog-browser/index.d.ts b/types/zwlog-browser/index.d.ts new file mode 100644 index 0000000000..41c4038b7c --- /dev/null +++ b/types/zwlog-browser/index.d.ts @@ -0,0 +1,195 @@ +// Type definitions for non-npm package ZwLog API - zwlog.js 1.0 +// Project: //assets.zjzwfw.gov.cn/assets/zwlog/1.0.0/zwlog.js +// Definitions by: Jungzl +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 4.2 + +/** + * “浙里办” 多端容器环境支持的数据埋点上报能力。 + * This API just for [浙里办](https://apps.apple.com/us/app/zhe-jiang-zheng-wu-fu-wu/id910260096) + * 1. 在页面 head 中先引入 zwjsbridge: + * ```js + * + * ``` + * 2. 在 zwjsbridge 后面引入 zwlog: + * ```js + * + * ``` + * 3. 在声明 Zwlog 对象实例时,可以传入一些 app 或者用户信息 + * ```js + * const zwlog = new ZwLog({ + * _user_id:"用户 ID", + * _user_nick:"用户昵称" + * }) + * ``` + */ + +interface ZwLogInitOptions { + /** + * 用户ID + */ + _user_id: string; + /** + * 用户昵称 + */ + _user_nick: string; +} + +type EventParamsKey = + | 'uidaplus' + | 'spm-url' + | 'spmpre' + | 'spm_cnt' + | 'pvid' + | '_dev_id' + | '_anony_id' + | '_user_id' + | '_user_nick' + | '_session_id'; + +interface zwlog { + cbQueue: any[]; + metaInfo: { + 'aplus-cpvdata': { + sdk_info: string; + sdk_version: string; + }; + 'aplus-exdata': { + sdk_info: string; + sdk_version: string; + }; + 'aplus-rhost-g': string; + 'aplus-rhost-v': string; + 'aplus-waiting': string; + appId: string; + } & ZwLogInitOptions; + readyFlag: boolean; + init: () => void; + + /** + * 初始化jsapi,初始化完成即onReady之后再调用jsapi。 + * + * @param callBack 初始化成功回调 + */ + onReady(callBack: () => void): void; + + /** + * PV日志 + * + * @param data + */ + sendPV: (data: { + /** + * IRS 服务侧应用 appid, + */ + miniAppId: string; + /** + * IRS 服务侧应用 appname, + */ + miniAppName: string; + /** + * 页面 ID + */ + pageId: string; + /** + * 页面名称 + */ + pageName: string; + /** + * 页面启动到加载完成的时间 + */ + t2: number; + /** + * 页面启动到页面响应完成的时间 + */ + t0: number; + /** + * 用户登录状态(01:未登录/ 02:单点登录) + */ + log_status: '01' | '02'; + }) => void; + /** + * 令箭日志 + * + * @param data + */ + record: ( + /** + * 注册的事件编码 可传空值或特定事件指定编码 + */ + trackerEventCode: string, + /** + * 时间类型 取值为'EXP':⾃定义曝光事件/'CLK':⾃定义点击事件/'OTHER': 其他⾃定义事件 + */ + eventType: 'EXP' | 'CLK' | 'OTHER' | string, + /** + * 本次事件中上报的事件参数. 其取值为⼀个 JSON 对象(平铺的简单对象,不能多层嵌套) + * JSON 中的 key 不能是以下保留属性:uidaplus,spm-url,spmpre,spm_cnt,pvid,_dev_id,_anony_id,_user_id,_user_nick,_session_id + */ + eventParams: Record & { [key in EventParamsKey]?: never }, + ) => void; + /** + * 支付宝上报采集 + * + * @param data + */ + sendAliMonitor: ( + data: + | { + /** + * 固定值,针对涉及“拆解”业务; + */ + name: 'cj'; + /** + * 业务数据 + */ + obj: { + /** + * 填写具体业务名称,如“余额查询” + */ + title: string; + /** + * 常规业务:taSR;医疗或医保业务:taSR_YL + */ + c1: string; + /** + * H5 服务 url + */ + url: string; + }; + } + | { + /** + * 固定值,针对涉及“办结”业务 + */ + name: 'bj'; + /** + * 业务数据 + */ + obj: { + /** + * 填写具体业务名称,如“余额查询” + */ + title: string; + /** + * 常规业务:taSR;医疗或医保业务:taSR_YL + */ + c1: string; + /** + * 服务耗时,无法统计填写 0 + */ + time: number; + /** + * 办结成功或失败 + */ + success: boolean; + }; + }, + ) => void; +} + +interface ZwLog { + new (initOptions: ZwLogInitOptions): zwlog; +} + +declare var ZwLog: ZwLog; diff --git a/types/zwlog-browser/tsconfig.json b/types/zwlog-browser/tsconfig.json new file mode 100644 index 0000000000..0b96f1955c --- /dev/null +++ b/types/zwlog-browser/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": ["index.d.ts", "zwlog-browser-tests.ts"] +} diff --git a/types/zwlog-browser/tslint.json b/types/zwlog-browser/tslint.json new file mode 100644 index 0000000000..2efa283002 --- /dev/null +++ b/types/zwlog-browser/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "@definitelytyped/dtslint/dt.json" +} diff --git a/types/zwlog-browser/zwlog-browser-tests.ts b/types/zwlog-browser/zwlog-browser-tests.ts new file mode 100644 index 0000000000..8a9a360fe8 --- /dev/null +++ b/types/zwlog-browser/zwlog-browser-tests.ts @@ -0,0 +1,21 @@ +async () => { + const zwlog = new ZwLog({ _user_id: '用户 ID', _user_nick: '用户昵称' }); + zwlog.onReady(() => { + zwlog.init(); + zwlog.sendPV({ + miniAppId: '2002308510', + miniAppName: '小程序名称', + pageId: '页面 ID', + pageName: '页面名称', + t2: 0.3, + t0: 0.3, + log_status: '02', + }); + + zwlog.cbQueue.push(() => ({ foo: 'bar' })); + zwlog.metaInfo; + zwlog.readyFlag; + zwlog.record('__CLICK__', 'CLK', { dd: 'gg' }); + zwlog.sendAliMonitor({ name: 'cj', obj: { title: '余额查询', c1: 'taSR', url: '/pages/index/' } }); + }); +};