@yunzhanghu/sdk-nodejs 1.0.2 → 1.0.4

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.
Files changed (66) hide show
  1. package/.editorconfig +8 -0
  2. package/.eslintrc.js +16 -0
  3. package/.prettierrc.js +3 -0
  4. package/README.md +23 -6
  5. package/example/apiUserSign.js +66 -12
  6. package/example/authentication.js +136 -25
  7. package/example/bizlicXjjH5.js +33 -7
  8. package/example/bizlicXjjH5Api.js +50 -10
  9. package/example/conf/config.js +2 -0
  10. package/example/dataService.js +105 -8
  11. package/example/h5UserSign.js +65 -10
  12. package/example/invoice.js +111 -14
  13. package/example/notify.js +0 -1
  14. package/example/payment.js +208 -26
  15. package/example/tax.js +31 -3
  16. package/example/uploadusersign.js +66 -0
  17. package/package.json +50 -45
  18. package/src/common/client.ts +364 -355
  19. package/src/common/exception/yzhSDKHttpException.ts +29 -26
  20. package/src/common/http/index.ts +62 -53
  21. package/src/common/utils/index.ts +16 -14
  22. package/src/index.ts +1 -1
  23. package/src/services/apiusersign/index.ts +107 -105
  24. package/src/services/authentication/index.ts +162 -196
  25. package/src/services/bizlicxjjh5/index.ts +77 -107
  26. package/src/services/bizlicxjjh5api/index.ts +108 -156
  27. package/src/services/dataservice/index.ts +246 -268
  28. package/src/services/h5usersign/index.ts +93 -105
  29. package/src/services/index.ts +11 -10
  30. package/src/services/invoice/index.ts +184 -244
  31. package/src/services/payment/index.ts +501 -435
  32. package/src/services/tax/index.ts +53 -51
  33. package/src/services/uploadusersign/index.ts +88 -0
  34. package/src/typings.d.ts +1 -1
  35. package/tdsformat.js +22 -0
  36. package/tsconfig.json +2 -1
  37. package/yzh/common/client.d.ts +3 -0
  38. package/yzh/common/client.js +9 -3
  39. package/yzh/common/http/index.d.ts +1 -0
  40. package/yzh/common/http/index.js +18 -8
  41. package/yzh/common/utils/index.d.ts +1 -0
  42. package/yzh/common/utils/index.js +1 -0
  43. package/yzh/services/apiusersign/index.d.ts +34 -7
  44. package/yzh/services/apiusersign/index.js +9 -8
  45. package/yzh/services/authentication/index.d.ts +57 -19
  46. package/yzh/services/authentication/index.js +12 -11
  47. package/yzh/services/bizlicxjjh5/index.d.ts +16 -4
  48. package/yzh/services/bizlicxjjh5/index.js +6 -5
  49. package/yzh/services/bizlicxjjh5api/index.d.ts +22 -5
  50. package/yzh/services/bizlicxjjh5api/index.js +7 -6
  51. package/yzh/services/dataservice/index.d.ts +52 -11
  52. package/yzh/services/dataservice/index.js +23 -10
  53. package/yzh/services/h5usersign/index.d.ts +28 -6
  54. package/yzh/services/h5usersign/index.js +8 -7
  55. package/yzh/services/index.d.ts +3 -2
  56. package/yzh/services/index.js +7 -5
  57. package/yzh/services/invoice/index.d.ts +51 -12
  58. package/yzh/services/invoice/index.js +11 -10
  59. package/yzh/services/payment/index.d.ts +194 -18
  60. package/yzh/services/payment/index.js +28 -13
  61. package/yzh/services/tax/index.d.ts +17 -4
  62. package/yzh/services/tax/index.js +6 -5
  63. package/yzh/services/uploadusersign/index.d.ts +78 -0
  64. package/yzh/services/uploadusersign/index.js +19 -0
  65. package/.eslintrc.json +0 -19
  66. package/prettier.config.js +0 -32
@@ -1,32 +1,35 @@
1
1
  export default class YZHSDKHttpException extends Error {
2
- // 请求 ID
3
- request_id: string
4
- // HTTP 状态码
5
- httpCode?: number
6
- // 接口返回状态码
7
- code?: string
2
+ // 请求 ID
3
+ request_id: string;
8
4
 
9
- constructor(error: string, request_id = "") {
10
- super(error)
11
- this.request_id = request_id || ""
12
- }
5
+ // HTTP 状态码
6
+ httpCode?: number;
13
7
 
14
- getMessage(): string {
15
- return this.message
16
- }
8
+ // 接口返回状态码
9
+ code?: string;
17
10
 
18
- getRequestId(): string {
19
- return this.request_id
20
- }
11
+ constructor(error: string, request_id = '') {
12
+ super(error);
13
+ this.request_id = request_id || '';
14
+ }
21
15
 
22
- toString(): string {
23
- return `[yzh_sdk_exception] ${
24
- this.code && `code:${this.code}`
25
- } requestId:${this.getRequestId()} message:${this.getMessage()}`
26
- }
27
- toLocaleString(): string {
28
- return `[yzh_sdk_exception] ${
29
- this.code && `code:${this.code}`
30
- } requestId:${this.getRequestId()} message:${this.getMessage()}`
31
- }
16
+ getMessage(): string {
17
+ return this.message;
18
+ }
19
+
20
+ getRequestId(): string {
21
+ return this.request_id;
22
+ }
23
+
24
+ toString(): string {
25
+ return `[yzh_sdk_exception] ${
26
+ this.code && `code:${this.code}`
27
+ } requestId:${this.getRequestId()} message:${this.getMessage()}`;
28
+ }
29
+
30
+ toLocaleString(): string {
31
+ return `[yzh_sdk_exception] ${
32
+ this.code && `code:${this.code}`
33
+ } requestId:${this.getRequestId()} message:${this.getMessage()}`;
34
+ }
32
35
  }
@@ -1,57 +1,66 @@
1
- import axios from "axios"
2
- import * as urlencode from "urlencode"
3
- import * as pkg from "../../../package.json"
4
- import * as child_process from "child_process"
5
- const BASE_URL = "https://api-service.yunzhanghu.com/"
6
-
7
- const getInstance = (
8
- config: { request_id?: string; dealer_id?: string; base_url?: string } = {}
9
- ) => {
10
- const instance = axios.create({
11
- baseURL: config.base_url || BASE_URL,
12
- headers: {
13
- "request-id": config?.request_id,
14
- "dealer-id": config?.dealer_id,
15
- "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
16
- "User-Agent": `yunzhanghu-sdk-nodejs/${pkg.version}/${child_process
17
- .execSync("uname -m -r -s")
18
- .toString("utf-8")
19
- .replace("\n", "")}/${process.version}`,
20
- },
21
- timeout: 30 * 1000,
22
- })
23
-
24
- // 拦截器
25
- instance.interceptors.request.use(function (config) {
26
- // URL Encode
27
- if (config.method === "get") {
28
- const { params: urlData } = config
29
- const { data, sign, ...resData } = urlData
30
- config.data = {
31
- data: urlencode(data),
32
- sign: urlencode(sign),
33
- ...resData,
34
- }
35
- }
36
- return config
37
- })
38
-
39
- instance.interceptors.response.use(function (response) {
40
- const { data } = response
41
- if (data) {
42
- const { request_id, requestID, ...resResponse } = data
43
- if (request_id || requestID) {
44
- response.data = {
45
- ...resResponse,
46
- request_id: request_id || requestID,
1
+ import axios from 'axios';
2
+ import * as urlencode from 'urlencode';
3
+
4
+ import * as pkg from '../../../package.json';
5
+
6
+ const JsonBigString = require('json-bigint')({ storeAsString: true });
7
+
8
+ const BASE_URL = 'https://api-service.yunzhanghu.com/';
9
+
10
+ const getInstance = (config: { request_id?: string; dealer_id?: string; base_url?: string; timeout?: number } = {}) => {
11
+ const instance = axios.create({
12
+ baseURL: config.base_url || BASE_URL,
13
+ headers: {
14
+ 'request-id': config?.request_id,
15
+ 'dealer-id': config?.dealer_id,
16
+ 'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
17
+ 'User-Agent': `yunzhanghu-sdk-nodejs/${pkg.version}/${process.version}`,
18
+ },
19
+ timeout: config.timeout ?? 30 * 1000,
20
+ transformResponse: [
21
+ function toJson(data) {
22
+ try {
23
+ return JsonBigString.parse(data);
24
+ } catch (e) {
25
+ // data 返回的内容不是合法的json字符串时会报错,此时直接返回原 data 数据
26
+ return data;
27
+ }
28
+ },
29
+ ],
30
+ });
31
+
32
+ // 拦截器
33
+ instance.interceptors.request.use(config => {
34
+ // URL Encode
35
+ if (config.method === 'get') {
36
+ const { params: urlData } = config;
37
+ const { data, sign, ...resData } = urlData;
38
+ // eslint-disable-next-line no-param-reassign
39
+ config.data = {
40
+ data: urlencode(data),
41
+ sign: urlencode(sign),
42
+ ...resData,
43
+ };
44
+ }
45
+ return config;
46
+ });
47
+
48
+ instance.interceptors.response.use(response => {
49
+ const { data } = response;
50
+ if (data) {
51
+ const { request_id, requestID, ...resResponse } = data;
52
+ if (request_id || requestID) {
53
+ response.data = {
54
+ ...resResponse,
55
+ request_id: request_id || requestID,
56
+ };
57
+ }
47
58
  }
48
- }
49
- }
50
59
 
51
- return response
52
- })
60
+ return response;
61
+ });
53
62
 
54
- return instance
55
- }
63
+ return instance;
64
+ };
56
65
 
57
- export default getInstance
66
+ export default getInstance;
@@ -1,18 +1,20 @@
1
- import YZHclient from "../client"
1
+ import YZHclient from '../client';
2
2
 
3
3
  export class Util extends YZHclient {
4
- constructor(conf: {
5
- dealer_id: string
6
- broker_id: string
7
- app_key: string
8
- des3_key: string
9
- private_key: string
10
- yzh_public_key: string
11
- sign_type: "rsa" | "sha256"
12
- base_url?: string
13
- }) {
14
- super(conf)
15
- }
4
+ // eslint-disable-next-line no-useless-constructor
5
+ constructor(conf: {
6
+ dealer_id: string;
7
+ broker_id: string;
8
+ app_key: string;
9
+ des3_key: string;
10
+ private_key: string;
11
+ yzh_public_key: string;
12
+ sign_type: 'rsa' | 'sha256';
13
+ base_url?: string;
14
+ timeout?: number;
15
+ }) {
16
+ super(conf);
17
+ }
16
18
  }
17
19
 
18
- export default Util
20
+ export default Util;
package/src/index.ts CHANGED
@@ -1 +1 @@
1
- export * from "./services"
1
+ export * from './services';
@@ -1,148 +1,150 @@
1
- import YZHclient from "../../common/client"
1
+ import YZHclient from '../../common/client';
2
2
 
3
3
  /** ApiUseSignContractRequest 获取协议预览 URL 请求 */
4
4
  interface ApiUseSignContractRequest {
5
- /** 平台企业 ID */
6
- dealer_id: string
7
- /** 综合服务主体 ID */
8
- broker_id: string
5
+ /** 平台企业 ID */
6
+ dealer_id: string;
7
+ /** 综合服务主体 ID */
8
+ broker_id: string;
9
9
  }
10
10
 
11
11
  /** ApiUseSignContractResponse 获取协议预览 URL 返回 */
12
12
  interface ApiUseSignContractResponse {
13
- /** 预览跳转 URL */
14
- url: string
15
- /** 协议名称 */
16
- title: string
13
+ /** 预览跳转 URL */
14
+ url: string;
15
+ /** 协议名称 */
16
+ title: string;
17
17
  }
18
18
 
19
19
  /** ApiUserSignContractRequest 获取协议预览 URL 请求 V2 */
20
20
  interface ApiUserSignContractRequest {
21
- /** 平台企业 ID */
22
- dealer_id: string
23
- /** 综合服务主体 ID */
24
- broker_id: string
21
+ /** 平台企业 ID */
22
+ dealer_id: string;
23
+ /** 综合服务主体 ID */
24
+ broker_id: string;
25
25
  }
26
26
 
27
27
  /** ApiUserSignContractResponse 获取协议预览 URL 返回 V2 */
28
28
  interface ApiUserSignContractResponse {
29
- /** 预览跳转 URL */
30
- url: string
31
- /** 协议名称 */
32
- title: string
29
+ /** 预览跳转 URL */
30
+ url: string;
31
+ /** 协议名称 */
32
+ title: string;
33
33
  }
34
34
 
35
35
  /** ApiUserSignRequest 用户签约请求 */
36
36
  interface ApiUserSignRequest {
37
- /** 综合服务主体 ID */
38
- broker_id: string
39
- /** 平台企业 ID */
40
- dealer_id: string
41
- /** 姓名 */
42
- real_name: string
43
- /** 证件号码 */
44
- id_card: string
45
- /** 证件类型 idcard:身份证 passport:护照 mtphkm:港澳居民来往内地通行证 mtpt:台湾居民往来大陆通行证 rphkm:中华人民共和国港澳居民居住证 rpt:中华人民共和国台湾居民居住证 fpr:外国人永久居留身份证 ffwp:中华人民共和国外国人就业许可证书 */
46
- card_type: string
37
+ /** 综合服务主体 ID */
38
+ broker_id: string;
39
+ /** 平台企业 ID */
40
+ dealer_id: string;
41
+ /** 姓名 */
42
+ real_name: string;
43
+ /** 证件号码 */
44
+ id_card: string;
45
+ /** 证件类型 idcard:身份证 passport:护照 mtphkm:港澳居民来往内地通行证 mtpt:台湾居民往来大陆通行证 rphkm:中华人民共和国港澳居民居住证 rpt:中华人民共和国台湾居民居住证 fpr:外国人永久居留身份证 ffwp:中华人民共和国外国人就业许可证书 */
46
+ card_type: string;
47
47
  }
48
48
 
49
49
  /** ApiUserSignResponse 用户签约返回 */
50
50
  interface ApiUserSignResponse {
51
- /** 是否签约成功 */
52
- status: string
51
+ /** 是否签约成功 */
52
+ status: string;
53
53
  }
54
54
 
55
55
  /** GetApiUserSignStatusRequest 获取用户签约状态请求 */
56
56
  interface GetApiUserSignStatusRequest {
57
- /** 平台企业 ID */
58
- dealer_id: string
59
- /** 综合服务主体 ID */
60
- broker_id: string
61
- /** 姓名 */
62
- real_name: string
63
- /** 证件号码 */
64
- id_card: string
57
+ /** 平台企业 ID */
58
+ dealer_id: string;
59
+ /** 综合服务主体 ID */
60
+ broker_id: string;
61
+ /** 姓名 */
62
+ real_name: string;
63
+ /** 证件号码 */
64
+ id_card: string;
65
65
  }
66
66
 
67
67
  /** GetApiUserSignStatusResponse 获取用户签约状态返回 */
68
68
  interface GetApiUserSignStatusResponse {
69
- /** 签约时间 */
70
- signed_at: string
71
- /** 用户签约状态 */
72
- status: string
69
+ /** 签约时间 */
70
+ signed_at: string;
71
+ /** 用户签约状态 */
72
+ status: string;
73
73
  }
74
74
 
75
75
  /** ApiUserSignReleaseRequest 用户解约(测试账号专用接口)请求 */
76
76
  interface ApiUserSignReleaseRequest {
77
- /** 综合服务主体 ID */
78
- broker_id: string
79
- /** 平台企业 ID */
80
- dealer_id: string
81
- /** 姓名 */
82
- real_name: string
83
- /** 证件号码 */
84
- id_card: string
85
- /** 证件类型 idcard:身份证 passport:护照 mtphkm:港澳居民来往内地通行证 mtpt:台湾居民往来大陆通行证 rphkm:中华人民共和国港澳居民居住证 rpt:中华人民共和国台湾居民居住证 fpr:外国人永久居留身份证 ffwp:中华人民共和国外国人就业许可证书 */
86
- card_type: string
77
+ /** 综合服务主体 ID */
78
+ broker_id: string;
79
+ /** 平台企业 ID */
80
+ dealer_id: string;
81
+ /** 姓名 */
82
+ real_name: string;
83
+ /** 证件号码 */
84
+ id_card: string;
85
+ /** 证件类型 idcard:身份证 passport:护照 mtphkm:港澳居民来往内地通行证 mtpt:台湾居民往来大陆通行证 rphkm:中华人民共和国港澳居民居住证 rpt:中华人民共和国台湾居民居住证 fpr:外国人永久居留身份证 ffwp:中华人民共和国外国人就业许可证书 */
86
+ card_type: string;
87
87
  }
88
88
 
89
89
  /** ApiUserSignReleaseResponse 用户解约(测试账号专用接口)返回 */
90
90
  interface ApiUserSignReleaseResponse {
91
- /** 是否解约成功 */
92
- status: string
91
+ /** 是否解约成功 */
92
+ status: string;
93
93
  }
94
94
 
95
95
  export class ApiUserSignServiceClient extends YZHclient {
96
- constructor(conf: {
97
- dealer_id: string
98
- broker_id: string
99
- app_key: string
100
- des3_key: string
101
- private_key: string
102
- yzh_public_key: string
103
- sign_type: "rsa" | "sha256"
104
- base_url?: string
105
- }) {
106
- super(conf)
107
- }
108
-
109
- // ApiUseSignContract 获取协议预览 URL
110
- async ApiUseSignContract(
111
- req: ApiUseSignContractRequest,
112
- cb?: (error: null | string, rep: ApiUseSignContractResponse) => void
113
- ): Promise<ApiUseSignContractResponse> {
114
- return this.request("get", "/api/sign/v1/user/contract", req, { encryption: false }, cb)
115
- }
116
-
117
- // ApiUserSignContract 获取协议预览 URL V2
118
- async ApiUserSignContract(
119
- req: ApiUserSignContractRequest,
120
- cb?: (error: null | string, rep: ApiUserSignContractResponse) => void
121
- ): Promise<ApiUserSignContractResponse> {
122
- return this.request("get", "/api/sign/v1/user/contract", req, { encryption: false }, cb)
123
- }
124
-
125
- // ApiUserSign 用户签约
126
- async ApiUserSign(
127
- req: ApiUserSignRequest,
128
- cb?: (error: null | string, rep: ApiUserSignResponse) => void
129
- ): Promise<ApiUserSignResponse> {
130
- return this.request("post", "/api/sign/v1/user/sign", req, { encryption: false }, cb)
131
- }
132
-
133
- // GetApiUserSignStatus 获取用户签约状态
134
- async GetApiUserSignStatus(
135
- req: GetApiUserSignStatusRequest,
136
- cb?: (error: null | string, rep: GetApiUserSignStatusResponse) => void
137
- ): Promise<GetApiUserSignStatusResponse> {
138
- return this.request("get", "/api/sign/v1/user/status", req, { encryption: false }, cb)
139
- }
140
-
141
- // ApiUserSignRelease 用户解约(测试账号专用接口)
142
- async ApiUserSignRelease(
143
- req: ApiUserSignReleaseRequest,
144
- cb?: (error: null | string, rep: ApiUserSignReleaseResponse) => void
145
- ): Promise<ApiUserSignReleaseResponse> {
146
- return this.request("post", "/api/sign/v1/user/release", req, { encryption: false }, cb)
147
- }
96
+ // eslint-disable-next-line no-useless-constructor
97
+ constructor(conf: {
98
+ dealer_id: string;
99
+ broker_id: string;
100
+ app_key: string;
101
+ des3_key: string;
102
+ private_key: string;
103
+ yzh_public_key: string;
104
+ sign_type: 'rsa' | 'sha256';
105
+ base_url?: string;
106
+ timeout?: number;
107
+ }) {
108
+ super(conf);
109
+ }
110
+
111
+ // ApiUseSignContract 获取协议预览 URL
112
+ async ApiUseSignContract(
113
+ req: ApiUseSignContractRequest,
114
+ cb?: (error: null | string, rep: ApiUseSignContractResponse) => void
115
+ ): Promise<ApiUseSignContractResponse> {
116
+ return this.request('get', '/api/sign/v1/user/contract', req, { encryption: false }, cb);
117
+ }
118
+
119
+ // ApiUserSignContract 获取协议预览 URL V2
120
+ async ApiUserSignContract(
121
+ req: ApiUserSignContractRequest,
122
+ cb?: (error: null | string, rep: ApiUserSignContractResponse) => void
123
+ ): Promise<ApiUserSignContractResponse> {
124
+ return this.request('get', '/api/sign/v1/user/contract', req, { encryption: false }, cb);
125
+ }
126
+
127
+ // ApiUserSign 用户签约
128
+ async ApiUserSign(
129
+ req: ApiUserSignRequest,
130
+ cb?: (error: null | string, rep: ApiUserSignResponse) => void
131
+ ): Promise<ApiUserSignResponse> {
132
+ return this.request('post', '/api/sign/v1/user/sign', req, { encryption: false }, cb);
133
+ }
134
+
135
+ // GetApiUserSignStatus 获取用户签约状态
136
+ async GetApiUserSignStatus(
137
+ req: GetApiUserSignStatusRequest,
138
+ cb?: (error: null | string, rep: GetApiUserSignStatusResponse) => void
139
+ ): Promise<GetApiUserSignStatusResponse> {
140
+ return this.request('get', '/api/sign/v1/user/status', req, { encryption: false }, cb);
141
+ }
142
+
143
+ // ApiUserSignRelease 用户解约(测试账号专用接口)
144
+ async ApiUserSignRelease(
145
+ req: ApiUserSignReleaseRequest,
146
+ cb?: (error: null | string, rep: ApiUserSignReleaseResponse) => void
147
+ ): Promise<ApiUserSignReleaseResponse> {
148
+ return this.request('post', '/api/sign/v1/user/release', req, { encryption: false }, cb);
149
+ }
148
150
  }