@ningboyz/ding 1.0.12 → 1.0.14

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.
File without changes
package/.prettierrc ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "printWidth": 200,
3
+ "tabWidth": 2,
4
+ "useTabs": false,
5
+ "semi": true,
6
+ "singleQuote": false,
7
+ "trailingComma": "none",
8
+ "bracketSpacing": true,
9
+ "bracketSameLine": true,
10
+ "arrowParens": "always",
11
+ "htmlWhitespaceSensitivity": "ignore",
12
+ "vueIndentScriptAndStyle": false,
13
+ "endOfLine": "auto",
14
+ "singleAttributePerLine": false
15
+ }
package/package.json CHANGED
@@ -1,24 +1,15 @@
1
1
  {
2
2
  "name": "@ningboyz/ding",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "private": false,
5
5
  "description": "宁波甬政钉钉库",
6
6
  "author": "nbyt-syq",
7
7
  "license": "ISC",
8
8
  "keywords": [],
9
- "exports": {
10
- ".": {
11
- "types": "./es/index.d.ts",
12
- "import": "./es/index.js"
13
- },
14
- "./es/*": "./es/*",
15
- "./package.json": "./package.json"
16
- },
17
- "main": "es/index.js",
18
- "types": "es/index.d.ts",
19
- "files": [
20
- "es"
21
- ],
9
+
10
+ "main": "index.js",
11
+ "types": "index.d.ts",
12
+
22
13
  "scripts": {
23
14
  "build": "vite build",
24
15
  "prettier": "prettier --config ./.prettierrc --write \"./**/*.{ts,tsx}\" "
@@ -0,0 +1,41 @@
1
+ import axios, { AxiosInstance } from "axios";
2
+ import { IAxiosConfig } from "../types/core/IAxiosConfig";
3
+ import { IResponse } from "@ningboyz/types";
4
+ import { TResponse } from "@ningboyz/types/src/response/IResponse";
5
+ import _ from "lodash";
6
+
7
+ class DingRequest {
8
+ private instance: AxiosInstance;
9
+ private constructor(config: IAxiosConfig) {
10
+ this.instance = axios.create({
11
+ baseURL: config.baseURL,
12
+ timeout: config.timeout
13
+ });
14
+ }
15
+
16
+ public static create(config: IAxiosConfig) {
17
+ return new DingRequest(config);
18
+ }
19
+
20
+ public post<T>(url: string, querys?: object, data?: object, headers?: object): Promise<IResponse<T>> {
21
+ return new Promise((resolve) => {
22
+ this.instance
23
+ .post<IResponse<T>>(url, data, {
24
+ params: querys,
25
+ headers: headers
26
+ })
27
+ .then((res) => {
28
+ resolve(res.data);
29
+ })
30
+ .catch((err) => {
31
+ const result = TResponse.toError(JSON.stringify(err));
32
+ resolve(result);
33
+ });
34
+ });
35
+ }
36
+ }
37
+
38
+ const createDingRequest = (config: IAxiosConfig) => {
39
+ return DingRequest.create(config);
40
+ };
41
+ export { type DingRequest, createDingRequest };
@@ -0,0 +1,51 @@
1
+ import _ from "lodash";
2
+ import { DingRequest, createDingRequest } from "../axios/dingRequest";
3
+ import { IDingConfig } from "../types/core/IDingConfig";
4
+ import { IGetUserInfoByAuthCodeQuerys } from "../types/request/IGetUserInfoByAuthCodeQuerys";
5
+ import { IDingTalkUserAuthCodeResponse } from "../types/response/IDingTalkUserAuthCodeResponse";
6
+ import { IGetUserInfoByQrCodeQuerys } from "../types/request/IGetUserInfoByQrCodeQuerys";
7
+
8
+ class DingClient {
9
+ private prefixURL: string = "dapi";
10
+ private config: IDingConfig;
11
+ private dingRequest: DingRequest;
12
+
13
+ private constructor(config: IDingConfig) {
14
+ this.config = config;
15
+ this.dingRequest = createDingRequest({ baseURL: config.dingTalkURL, timeout: 60000 });
16
+ }
17
+
18
+ public static create = (config: IDingConfig) => {
19
+ return new DingClient(config);
20
+ };
21
+
22
+ private createURL = (url: string) => {
23
+ return `/${this.prefixURL}${url}`;
24
+ };
25
+
26
+ /**
27
+ * 通过临时授权码获取用户信息
28
+ * @param querys
29
+ * @returns
30
+ */
31
+ public getUserInfoByAuthCode(querys: IGetUserInfoByAuthCodeQuerys) {
32
+ const url = this.createURL("/user/get_userinfo_by_authcode");
33
+ return this.dingRequest.post<IDingTalkUserAuthCodeResponse[]>(url, querys, undefined, { appid: this.config.appId });
34
+ }
35
+
36
+ /**
37
+ * 扫码通过临时授权码获取用户信息
38
+ * @param querys
39
+ * @returns
40
+ */
41
+ public getUserInfoByQrCode(querys: IGetUserInfoByQrCodeQuerys) {
42
+ const url = this.createURL("/user/get_userinfo_by_qrcode");
43
+ return this.dingRequest.post<IDingTalkUserAuthCodeResponse[]>(url, querys, undefined, { appid: this.config.scanAppId });
44
+ }
45
+ }
46
+
47
+ const createDingClient = (config: IDingConfig) => {
48
+ return DingClient.create(config);
49
+ };
50
+
51
+ export { type DingClient, createDingClient };
package/src/index.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { DingClient, createDingClient } from "./client/dingClient";
2
+ import * as DCore from "./types/core";
3
+ import * as DRequest from "./types/request";
4
+ import * as DResponse from "./types/response";
5
+ import * as DCommonDingTalk from "./types/commonDingTalk";
6
+ import * as DDedicatedDingTalk from "./types/dedicatedDingTalk";
7
+ export { type DingClient, createDingClient, DCore, DRequest, DResponse, DCommonDingTalk, DDedicatedDingTalk };
@@ -0,0 +1,24 @@
1
+ import { IDingTalkBaseResponse } from "../response/IDingTalkBaseResponse";
2
+ import * as dd from "dingtalk-jsapi";
3
+
4
+ // 钉钉标准扫描
5
+ export interface ICommonDingTalkScanResponse extends IDingTalkBaseResponse {}
6
+
7
+ export class TCommonDingTalkScanResponse implements ICommonDingTalkScanResponse {
8
+ scan(): Promise<string> {
9
+ return new Promise((resolve, reject) => {
10
+ dd.scan({
11
+ type: "qr",
12
+ source: "camera",
13
+ success: (res: any) => {
14
+ const { text } = res;
15
+ resolve(text);
16
+ },
17
+ fail: (error: any) => {
18
+ reject(error);
19
+ },
20
+ complete: () => {}
21
+ });
22
+ });
23
+ }
24
+ }
@@ -0,0 +1,3 @@
1
+ import { ICommonDingTalkScanResponse, TCommonDingTalkScanResponse } from "./ICommonDingTalkScanResponse";
2
+
3
+ export { type ICommonDingTalkScanResponse, TCommonDingTalkScanResponse };
@@ -0,0 +1,9 @@
1
+ export interface IAxiosConfig {
2
+ baseURL: string;
3
+ timeout: number;
4
+ }
5
+
6
+ export class TAxiosConfig implements IAxiosConfig {
7
+ baseURL: string = "";
8
+ timeout: number = 60000;
9
+ }
@@ -0,0 +1,11 @@
1
+ export interface IDingConfig {
2
+ appId: string;
3
+ scanAppId: string;
4
+ dingTalkURL: string;
5
+ }
6
+
7
+ export class TDingConfig implements IDingConfig {
8
+ appId: string = "";
9
+ scanAppId: string = "";
10
+ dingTalkURL: string = "";
11
+ }
@@ -0,0 +1,4 @@
1
+ import { IAxiosConfig, TAxiosConfig } from "./IAxiosConfig";
2
+ import { IDingConfig, TDingConfig } from "./IDingConfig";
3
+
4
+ export { type IAxiosConfig, type IDingConfig, TAxiosConfig, TDingConfig };
@@ -0,0 +1,21 @@
1
+ import { IDingTalkBaseResponse } from "../response/IDingTalkBaseResponse";
2
+ import * as dd from "gdt-jsapi";
3
+
4
+ // 专有钉钉
5
+ export interface IDedicatedDingTalkScanResponse extends IDingTalkBaseResponse {}
6
+
7
+ export class TDedicatedDingTalkScanResponse implements IDedicatedDingTalkScanResponse {
8
+ scan(): Promise<string> {
9
+ return new Promise((resolve, reject) => {
10
+ dd.scan({
11
+ type: "all"
12
+ })
13
+ .then((res: any) => {
14
+ resolve(res.text);
15
+ })
16
+ .catch((error: any) => {
17
+ reject(error);
18
+ });
19
+ });
20
+ }
21
+ }
@@ -0,0 +1,3 @@
1
+ import { IDedicatedDingTalkScanResponse, TDedicatedDingTalkScanResponse } from "./IDedicatedDingTalkScanResponse";
2
+
3
+ export { type IDedicatedDingTalkScanResponse, TDedicatedDingTalkScanResponse };
@@ -0,0 +1,7 @@
1
+ export interface IGetUserInfoByAuthCodeQuerys {
2
+ authcode: string;
3
+ }
4
+
5
+ export class TGetUserInfoByAuthCodeQuerys implements IGetUserInfoByAuthCodeQuerys {
6
+ authcode: string = "";
7
+ }
@@ -0,0 +1,7 @@
1
+ export interface IGetUserInfoByQrCodeQuerys {
2
+ authcode: string;
3
+ }
4
+
5
+ export class TGetUserInfoByQrCodeQuerys implements IGetUserInfoByQrCodeQuerys {
6
+ authcode: string = "";
7
+ }
@@ -0,0 +1,4 @@
1
+ import { IGetUserInfoByAuthCodeQuerys, TGetUserInfoByAuthCodeQuerys } from "./IGetUserInfoByAuthCodeQuerys";
2
+ import { IGetUserInfoByQrCodeQuerys, TGetUserInfoByQrCodeQuerys } from "./IGetUserInfoByQrCodeQuerys";
3
+
4
+ export { type IGetUserInfoByAuthCodeQuerys, type IGetUserInfoByQrCodeQuerys, TGetUserInfoByAuthCodeQuerys, TGetUserInfoByQrCodeQuerys };
@@ -0,0 +1,4 @@
1
+ // 规范钉钉和专有钉钉的基本类
2
+ export interface IDingTalkBaseResponse {
3
+ scan(): Promise<string>;
4
+ }
@@ -0,0 +1,15 @@
1
+ export interface IDingTalkUserAuthCodeResponse {
2
+ accountId: string;
3
+ userName: string;
4
+ employeeCode: string;
5
+ avatar: string;
6
+ encryptData: string;
7
+ }
8
+
9
+ export class TDingTalkUserAuthCodeResponse implements IDingTalkUserAuthCodeResponse {
10
+ accountId: string = "";
11
+ userName: string = "";
12
+ employeeCode: string = "";
13
+ avatar: string = "";
14
+ encryptData: string = "";
15
+ }
@@ -0,0 +1,3 @@
1
+ import { IDingTalkUserAuthCodeResponse, TDingTalkUserAuthCodeResponse } from "./IDingTalkUserAuthCodeResponse";
2
+
3
+ export { type IDingTalkUserAuthCodeResponse, TDingTalkUserAuthCodeResponse };
package/tsconfig.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "lib": ["ES2023", "DOM"],
5
+ "module": "ESNext",
6
+ "skipLibCheck": true,
7
+
8
+ /* Bundler mode */
9
+ "moduleResolution": "bundler",
10
+ "allowImportingTsExtensions": true,
11
+ "isolatedModules": true,
12
+ "moduleDetection": "force",
13
+ "noEmit": true,
14
+
15
+ /* Linting */
16
+ "strict": true,
17
+ "noUnusedLocals": true,
18
+ "noUnusedParameters": true,
19
+ "noFallthroughCasesInSwitch": true,
20
+ "experimentalDecorators": true
21
+ }
22
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,32 @@
1
+ import { defineConfig } from "vite";
2
+
3
+ import tsxResolveTypes from "vite-plugin-tsx-resolve-types";
4
+ import dts from "vite-plugin-dts";
5
+
6
+ export default defineConfig({
7
+ plugins: [
8
+ tsxResolveTypes(),
9
+ dts({
10
+ entryRoot: "src",
11
+ outDir: ["es"],
12
+ exclude: ["**/tests/**"]
13
+ })
14
+ ],
15
+ build: {
16
+ rollupOptions: {
17
+ external: ["lodash", "@ningboyz/types", "axios"],
18
+ output: [
19
+ {
20
+ preserveModules: true,
21
+ preserveModulesRoot: "src",
22
+ entryFileNames: "[name].js",
23
+ format: "esm",
24
+ dir: "es"
25
+ }
26
+ ]
27
+ },
28
+ lib: {
29
+ entry: "src/index.ts"
30
+ }
31
+ }
32
+ });