jinbi-utils 1.0.21 → 1.0.23

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 (73) hide show
  1. package/dist/chunk-optimizer.cjs +703 -0
  2. package/dist/index.esm.js +3085 -0
  3. package/dist/index.esm.min.js +15 -0
  4. package/dist/index.umd.js +3198 -0
  5. package/dist/index.umd.min.js +16 -0
  6. package/package.json +36 -3
  7. package/.babelrc +0 -19
  8. package/.cz-config.js +0 -55
  9. package/.dockerignore +0 -3
  10. package/.editorconfig +0 -12
  11. package/.eslintignore +0 -8
  12. package/.eslintrc.js +0 -54
  13. package/.versionrc.json +0 -9
  14. package/CHUNK_OPTIMIZER_USAGE.md +0 -132
  15. package/Dockerfile +0 -3
  16. package/QUICK_RELEASE.md +0 -85
  17. package/RELEASE_GUIDE.md +0 -243
  18. package/api-extractor.json +0 -15
  19. package/commitlint.config.js +0 -3
  20. package/jest.config.js +0 -15
  21. package/rollup.config.chunk-optimizer.js +0 -32
  22. package/rollup.config.js +0 -73
  23. package/src/array/index.ts +0 -85
  24. package/src/build/chunk-optimizer/ARCHITECTURE.md +0 -347
  25. package/src/build/chunk-optimizer/QUICK_START.md +0 -370
  26. package/src/build/chunk-optimizer/README.md +0 -240
  27. package/src/build/chunk-optimizer/core/chunk-generator.ts +0 -166
  28. package/src/build/chunk-optimizer/core/classifier.ts +0 -148
  29. package/src/build/chunk-optimizer/core/dependency-reader.ts +0 -138
  30. package/src/build/chunk-optimizer/examples/basic-usage.ts +0 -234
  31. package/src/build/chunk-optimizer/index.ts +0 -166
  32. package/src/build/chunk-optimizer/rules/common-rules.ts +0 -131
  33. package/src/build/chunk-optimizer/rules/framework-rules.ts +0 -93
  34. package/src/build/chunk-optimizer/rules/index.ts +0 -27
  35. package/src/build/chunk-optimizer/test.ts +0 -94
  36. package/src/build/chunk-optimizer/types.ts +0 -128
  37. package/src/color/index.ts +0 -58
  38. package/src/common/index.ts +0 -353
  39. package/src/constant/common.constant.ts +0 -13
  40. package/src/date/index.ts +0 -143
  41. package/src/dom/index.ts +0 -198
  42. package/src/file/index.ts +0 -319
  43. package/src/http/apiBuilder/README.md +0 -648
  44. package/src/http/apiBuilder/api-builder.ts +0 -502
  45. package/src/http/apiBuilder/example.ts +0 -243
  46. package/src/http/apiBuilder/index.ts +0 -1
  47. package/src/http/apiBuilder//345/277/253/351/200/237/345/217/202/350/200/203.md +0 -199
  48. package/src/http/http.ts +0 -79
  49. package/src/http/httpEnums.ts +0 -61
  50. package/src/iam/index.ts +0 -46
  51. package/src/index.ts +0 -20
  52. package/src/middleware/requestLogger.middware.ts +0 -371
  53. package/src/middleware/requestLoggerUnified.ts +0 -371
  54. package/src/number/index.ts +0 -362
  55. package/src/object/index.ts +0 -54
  56. package/src/print/index.ts +0 -102
  57. package/src/string/index.ts +0 -189
  58. package/src/utils/curl.ts +0 -108
  59. package/src/validate/index.ts +0 -100
  60. package/src/websocket/emitter.ts +0 -39
  61. package/src/websocket/index.ts +0 -6
  62. package/src/websocket/manager.ts +0 -151
  63. package/src/websocket/pinia-store.ts +0 -91
  64. package/src/websocket/service.ts +0 -34
  65. package/src/websocket/types.ts +0 -45
  66. package/test/common/index.test.ts +0 -19
  67. package/test/date/index.test.ts +0 -107
  68. package/test/file/index.test.ts +0 -104
  69. package/test/number/index.test.ts +0 -108
  70. package/test/object/index.test.ts +0 -20
  71. package/test/string/index.test.ts +0 -82
  72. package/tsconfig.json +0 -39
  73. package/typedoc.json +0 -12
@@ -1,243 +0,0 @@
1
- /**
2
- * 使用示例
3
- */
4
-
5
- import type { FieldCatalog } from './api-builder';
6
- import { ApiBuilder } from './api-builder';
7
-
8
- // 字段目录
9
- const cartFieldCatalog: FieldCatalog = {
10
- 'sfs_cart.id': {
11
- type: 'number',
12
- label: '主键ID',
13
- allowed_field: 'id',
14
- nullable: false,
15
- dict_field: false,
16
- },
17
- 'sfs_cart.user_id': {
18
- type: 'number',
19
- label: '用户ID',
20
- allowed_field: 'user_id',
21
- nullable: false,
22
- dict_field: false,
23
- },
24
- 'sfs_cart.goods_id': {
25
- type: 'number',
26
- label: '商品ID',
27
- allowed_field: 'goods_id',
28
- nullable: false,
29
- dict_field: false,
30
- },
31
- 'sfs_cart.quantity': {
32
- type: 'number',
33
- label: '购买数量',
34
- allowed_field: 'quantity',
35
- nullable: true,
36
- dict_field: false,
37
- },
38
- 'sfs_cart.selected': {
39
- type: 'number',
40
- label: '是否选中',
41
- allowed_field: 'selected',
42
- nullable: false,
43
- dict_field: true,
44
- },
45
- 'sfs_cart.is_deleted': {
46
- type: 'number',
47
- label: '逻辑删除',
48
- allowed_field: 'is_deleted',
49
- nullable: false,
50
- dict_field: false,
51
- },
52
- };
53
-
54
- // ========== 新用法:实例化后使用(推荐)==========
55
- console.log('=== 新用法:实例化 ApiBuilder(推荐)===');
56
- const cartApi = new ApiBuilder(cartFieldCatalog);
57
-
58
- // ========== 不传 fieldCatalog(简化版)==========
59
- console.log('\n=== 不传 fieldCatalog(不拼接 field_catalog 字段)===');
60
- const simpleApi = new ApiBuilder(); // 不传参数
61
-
62
- // 查询示例 - 基础用法
63
- console.log('\n=== 查询示例 - 基础用法 ===');
64
- const queryParams = cartApi.query()
65
- .where('user_id', 10086) // 简化:默认 =
66
- .where('is_deleted', 0)
67
- .orderBy('created_time', 'desc')
68
- .limit(20)
69
- .offset(0)
70
- .build();
71
-
72
- console.log(JSON.stringify(queryParams, null, 2));
73
-
74
- // 查询示例 - 对象形式
75
- console.log('\n=== 查询示例 - 对象形式 ===');
76
- const queryParams2 = cartApi.query()
77
- .where({ user_id: 10086, is_deleted: 0 })
78
- .orderBy('created_time', 'desc')
79
- .limit(20)
80
- .build();
81
-
82
- console.log(JSON.stringify(queryParams2, null, 2));
83
-
84
- // 查询示例 - 特殊条件
85
- console.log('\n=== 查询示例 - 特殊条件 ===');
86
- const queryParams3 = cartApi.query()
87
- .whereIn('status', [1, 2, 3])
88
- .whereLike('goods_name', '%手机%')
89
- .whereNotNull('goods_price')
90
- .orderBy('created_time', 'desc')
91
- .limit(20)
92
- .build();
93
-
94
- console.log(JSON.stringify(queryParams3, null, 2));
95
-
96
- // 新增示例
97
- console.log('\n=== 新增示例 ===');
98
- const insertParams = cartApi.insert()
99
- .add({
100
- cart_id: 19,
101
- user_id: 10086,
102
- store_id: 2001,
103
- goods_id: 30005,
104
- quantity: 6,
105
- goods_price: 50,
106
- selected: 1,
107
- })
108
- .build();
109
-
110
- console.log(JSON.stringify(insertParams, null, 2));
111
-
112
- // 更新示例
113
- console.log('\n=== 更新示例 ===');
114
- const updateParams = cartApi.update()
115
- .set({ selected: 1 })
116
- .where({ id: 1 })
117
- .build();
118
-
119
- console.log(JSON.stringify(updateParams, null, 2));
120
-
121
- // 批量更新示例
122
- console.log('\n=== 批量更新示例 ===');
123
- const batchUpdateParams = cartApi.update()
124
- .set({ selected: 0 })
125
- .where({ id: 1 })
126
- .and()
127
- .set({ is_deleted: 1 })
128
- .where({ goods_id: 8, user_id: 8 })
129
- .build();
130
-
131
- console.log(JSON.stringify(batchUpdateParams, null, 2));
132
-
133
- // ========== Knex 风格查询示例 ==========
134
- console.log('\n=== Knex 风格查询 ===');
135
- const knexStyleQuery = cartApi.query()
136
- .where('user_id', 10086)
137
- .where('is_deleted', 0)
138
- .orderBy('created_time', 'desc')
139
- .limit(20)
140
- .offset(0)
141
- .build();
142
-
143
- console.log('类似 Knex.js 的简洁语法:');
144
- console.log(JSON.stringify(knexStyleQuery, null, 2));
145
-
146
- // ========== 不传 fieldCatalog 的查询示例 ==========
147
- console.log('\n=== 不传 fieldCatalog 的查询(无 field_catalog 字段)===');
148
- const simpleQuery = simpleApi.query()
149
- .where('user_id', 10086)
150
- .where('is_deleted', 0)
151
- .limit(20)
152
- .build();
153
-
154
- console.log('生成的参数(不包含 field_catalog):');
155
- console.log(JSON.stringify(simpleQuery, null, 2));
156
-
157
- // ========== 旧用法:静态方法(仍然支持)==========
158
- console.log('\n=== 旧用法:静态方法(向后兼容)===');
159
- const oldStyleQuery = ApiBuilder.query(cartFieldCatalog)
160
- .where('user_id', '=', 10086)
161
- .build();
162
-
163
- console.log(JSON.stringify(oldStyleQuery, null, 2));
164
-
165
- // ========== 实际应用示例 ==========
166
- console.log('\n=== 实际应用示例 ===');
167
-
168
- // 购物车服务类(新用法)
169
- class CartService {
170
- private static api = new ApiBuilder(cartFieldCatalog);
171
-
172
- // 查询购物车
173
- static getCart(userId: number, page: number = 1, pageSize: number = 20) {
174
- return this.api.query()
175
- .where('user_id', userId) // 简化:默认 =
176
- .where('is_deleted', 0)
177
- .orderBy('created_time', 'desc')
178
- .limit(pageSize)
179
- .offset((page - 1) * pageSize)
180
- .build();
181
- }
182
-
183
- // 添加到购物车
184
- static addToCart(item: {
185
- cart_id: number;
186
- user_id: number;
187
- store_id: number;
188
- goods_id: number;
189
- quantity: number;
190
- goods_price: number;
191
- }) {
192
- return this.api.insert()
193
- .add({ ...item, selected: 1 })
194
- .build();
195
- }
196
-
197
- // 选中商品
198
- static selectItem(itemId: number) {
199
- return this.api.update()
200
- .set({ selected: 1 })
201
- .where({ id: itemId })
202
- .build();
203
- }
204
-
205
- // 更新数量
206
- static updateQuantity(itemId: number, quantity: number) {
207
- return this.api.update()
208
- .set({ quantity })
209
- .where({ id: itemId })
210
- .build();
211
- }
212
-
213
- // 删除商品
214
- static deleteItem(itemId: number) {
215
- return this.api.update()
216
- .set({ is_deleted: 1 })
217
- .where({ id: itemId })
218
- .build();
219
- }
220
-
221
- // 批量删除
222
- static deleteBatch(itemIds: number[]) {
223
- const builder = this.api.update();
224
-
225
- itemIds.forEach((id, index) => {
226
- if (index > 0)
227
- builder.and();
228
- builder.set({ is_deleted: 1 }).where({ id });
229
- });
230
-
231
- return builder.build();
232
- }
233
- }
234
-
235
- // 使用服务
236
- console.log('查询购物车:');
237
- console.log(JSON.stringify(CartService.getCart(10086), null, 2));
238
-
239
- console.log('\n选中商品:');
240
- console.log(JSON.stringify(CartService.selectItem(123), null, 2));
241
-
242
- console.log('\n批量删除:');
243
- console.log(JSON.stringify(CartService.deleteBatch([1, 2, 3]), null, 2));
@@ -1 +0,0 @@
1
- export * from './api-builder';
@@ -1,199 +0,0 @@
1
- # 快速参考
2
-
3
- ## 基础用法
4
-
5
- ```typescript
6
- import ApiBuilder from './api-builder';
7
-
8
- // 1. 实例化
9
- const api = new ApiBuilder(fieldCatalog);
10
-
11
- // 2. 查询
12
- api.query()
13
- .where('field', 'op', value)
14
- .orderBy('field', 'desc')
15
- .paginate(20, 0)
16
- .build();
17
-
18
- // 3. 新增
19
- api.insert()
20
- .add({ field: value })
21
- .build();
22
-
23
- // 4. 更新
24
- api.update()
25
- .set({ field: value })
26
- .where({ id: 1 })
27
- .build();
28
- ```
29
-
30
- ## 查询操作符
31
-
32
- | 类型 | 操作符 |
33
- |------|--------|
34
- | 字符串 | `=`, `!=`, `like`, `not like`, `in`, `not in` |
35
- | 数字 | `=`, `!=`, `>`, `>=`, `<`, `<=`, `in`, `not in`, `between` |
36
- | 日期 | `=`, `>`, `>=`, `<`, `<=`, `between` |
37
- | 布尔 | `is true`, `is false`, `is null`, `is not null` |
38
-
39
- ## 常用示例
40
-
41
- ### 查询
42
-
43
- ```typescript
44
- // 单条件(默认 =)
45
- api.query().where('user_id', 10086).build();
46
-
47
- // 多条件(AND)
48
- api.query()
49
- .where('user_id', 10086)
50
- .where('is_deleted', 0)
51
- .build();
52
-
53
- // 对象形式
54
- api.query()
55
- .where({ user_id: 10086, is_deleted: 0 })
56
- .build();
57
-
58
- // 多条件(OR)
59
- api.query()
60
- .where('status', 1)
61
- .orWhere('status', 2)
62
- .build();
63
-
64
- // IN 条件
65
- api.query().whereIn('status', [1, 2, 3]).build();
66
-
67
- // LIKE 查询
68
- api.query().whereLike('name', '%关键词%').build();
69
-
70
- // NULL 查询
71
- api.query().whereNull('deleted_at').build();
72
- api.query().whereNotNull('price').build();
73
-
74
- // BETWEEN
75
- api.query().whereBetween('price', 100, 500).build();
76
-
77
- // 排序
78
- api.query().orderBy('created_time', 'desc').build();
79
-
80
- // 分页
81
- api.query().limit(20).offset(0).build();
82
- // 或
83
- api.query().paginate(20, 0).build();
84
- ```
85
-
86
- ### 新增
87
-
88
- ```typescript
89
- // 单条
90
- api.insert().add({ user_id: 10086, name: '张三' }).build();
91
-
92
- // 批量
93
- api.insert().addBatch([
94
- { user_id: 10086, name: '张三' },
95
- { user_id: 10087, name: '李四' }
96
- ]).build();
97
- ```
98
-
99
- ### 更新
100
-
101
- ```typescript
102
- // 单条(对象形式)
103
- api.update()
104
- .set({ status: 1 })
105
- .where({ id: 1 })
106
- .build();
107
-
108
- // 单条(键值对形式)
109
- api.update()
110
- .set({ status: 1 })
111
- .where('id', 1)
112
- .build();
113
-
114
- // 多个条件
115
- api.update()
116
- .set({ status: 1 })
117
- .where('user_id', 10086)
118
- .where('goods_id', 30005)
119
- .build();
120
-
121
- // 批量更新
122
- api.update()
123
- .set({ status: 0 })
124
- .where({ id: 1 })
125
- .and()
126
- .set({ status: 1 })
127
- .where({ id: 2 })
128
- .build();
129
- ```
130
-
131
- ## 服务类模板
132
-
133
- ```typescript
134
- class YourService {
135
- private static api = new ApiBuilder(YOUR_CATALOG);
136
-
137
- static query(params: any) {
138
- return this.api.query()
139
- .where('field', '=', params.value)
140
- .build();
141
- }
142
-
143
- static create(data: any) {
144
- return this.api.insert()
145
- .add(data)
146
- .build();
147
- }
148
-
149
- static update(id: number, data: any) {
150
- return this.api.update()
151
- .set(data)
152
- .where({ id })
153
- .build();
154
- }
155
-
156
- static delete(id: number) {
157
- return this.api.update()
158
- .set({ is_deleted: 1 })
159
- .where({ id })
160
- .build();
161
- }
162
- }
163
- ```
164
-
165
- ## 链式调用顺序
166
-
167
- ### Query
168
- ```
169
- query() → where() → logic() → orderBy() → paginate() → build()
170
- ```
171
-
172
- ### Insert
173
- ```
174
- insert() → add() / addBatch() → build()
175
- ```
176
-
177
- ### Update
178
- ```
179
- update() → set() → where() → [and() → set() → where()] → build()
180
- ```
181
-
182
- ## 注意事项
183
-
184
- 1. `where()` 可以多次调用,默认 AND 关系
185
- 2. `logic('or')` 改变条件逻辑为 OR
186
- 3. `and()` 用于批量更新时分隔多个更新操作
187
- 4. `build()` 必须最后调用,返回最终参数
188
- 5. 更新操作必须先 `set()` 再 `where()`
189
-
190
- ## 类型定义
191
-
192
- ```typescript
193
- import ApiBuilder, {
194
- FieldCatalog,
195
- QueryParams,
196
- InsertParams,
197
- UpdateParams
198
- } from './api-builder';
199
- ```
package/src/http/http.ts DELETED
@@ -1,79 +0,0 @@
1
- import axios, {AxiosInstance, AxiosResponse} from "axios";
2
- import { httpEnum } from './httpEnums';
3
- import {getDeviceType, getFromType, getToken, removeToken} from "../common/index";
4
- interface IHttp {
5
- cacheType: 'localStorage' | 'sessionStorage' | 'both';
6
- currentMode: string; // local | dev | test | prod 等自定义mode
7
- errorCb?: (error: any) => void;
8
- getTokenCb?: () => void;
9
- tokenKey?: 'token';
10
- }
11
- const request = axios.create({
12
- timeout: 15000,
13
- headers: {
14
- // 'Authorization': getToken(),
15
- "Content-Type": "application/json",
16
- },
17
- });
18
- // const requestArr = [request];
19
-
20
- /**
21
- * @param cacheType localStorage | sessionStorage | both
22
- * @param currentMode local | dev | test | prod 等自定义mode
23
- * @param errorCb 错误回调
24
- * @param getTokenCb 获取token的回调
25
- * @param tokenKey
26
- * */
27
- export const http = ({cacheType, currentMode, errorCb, getTokenCb, tokenKey}: IHttp):AxiosInstance => {
28
- request.interceptors.request.use(
29
- async (config: any) => {
30
- const token = getToken(cacheType, tokenKey);
31
- const deviceType = getDeviceType();
32
- config.headers.Authorization = token;
33
- config.headers.token = token;
34
- config.headers.FrontType = getFromType(deviceType);
35
- return config;
36
- },
37
- (error) => {
38
- // do something with request error
39
- return Promise.reject(error);
40
- }
41
- );
42
-
43
- // response interceptor
44
- request.interceptors.response.use(
45
- async (response: AxiosResponse) => {
46
- const res = response.data;
47
- const statusCode = res.code || response.status;
48
- // blob文件流
49
- if (res instanceof Blob) {
50
- return res;
51
- }
52
- // 成功
53
- if (statusCode === httpEnum.CODES.Success) {
54
- return res;
55
- }
56
- // token失效
57
- if (statusCode === httpEnum.CODES.UnAuthorized) {
58
- if (currentMode !== "local" && currentMode !== "dev" && currentMode !== 'development') {
59
- removeToken(cacheType, tokenKey);
60
- if (getTokenCb && typeof getTokenCb === "function") {
61
- getTokenCb();
62
- }
63
- }
64
- return Promise.reject(new Error("token过期!"));
65
- }
66
- const errMsg = res.message || res.msg;
67
- return Promise.reject(new Error(errMsg || "Error"));
68
- },
69
- async (error) => {
70
- if (errorCb && typeof errorCb === "function") {
71
- errorCb(error);
72
- }
73
- return Promise.reject(error);
74
- }
75
-
76
- );
77
- return request
78
- }
79
-
@@ -1,61 +0,0 @@
1
- export const httpEnum = {
2
- // http响应状态码
3
- HTTP_STATUS: {
4
- // 1xx,临时响应
5
- TEMP_RESPOND: {
6
- Continue: 100, // 服务器通知浏览器之前一切正常,请客户端继续请求,如果请求结束,可忽略
7
- SwitchingProtocal: 101 // 针对请求头的Upgrade返回的信息。表明服务器正在切换到指定的协议
8
- },
9
- // 2xx,成功
10
- SUCCESS: {
11
- Ok: 200, // 请求成功
12
- Created: 201, // 常用于POST,PUT 请求,表明请求已经成功,并新建了一个资源。并在响应体中返回路径
13
- Accepted: 202, // 请求已经接收到,但没有响应,稍后也不会返回一个异步请求结果。 该状态码适用于等待其他进程处理或者批处理的场景
14
- NoAuthoritativeInformation: 203, // 表明响应返回的元信息(meta-infomation)和最初的服务器不同,而是从本地或者第三方获取的
15
- NoContent: 204, // 请求没有数据返回,但是头信息有用。用户代理(浏览器)会更新缓存的头信息
16
- ResetContent: 205, // 告诉用户代理(浏览器)重置发送该请求的文档
17
- ParticalContent: 206 // 客户端使用Range请求头时,返回该状态码
18
- },
19
- // 3xx,重定向
20
- REDIRECT: {
21
- MultipleChoice: 300, // 返回多个响应,需要浏览器或者用户选择
22
- MovedPermanently: 301, // 请求资源的URL被永久的改变,新的URL会在响应的Location中给出。浏览器到新的URL重新请求资源,因为有些客户端会把请求方式method改成GET。所以该状态码建议GET和HEAD方法中使用。搜索引擎会更新地址到资源的链接(SEO中‘link-judge’被发送到新的URL)
23
- Found: 302, // 请求资源的URL被暂时修改到Location提供的URL。未来可能还会有新的修改。览器会根据新的URL重新请求资源。有些客户端会把方法method改为GET,建议在GET和HEAD方法中使用。搜索引擎不会更改URL到资源的。
24
- SeeOther: 303, // 服务通过返回的响应数据指导客户端通过GET方法去另一个URL获取资源。通常用于POST或者PUT的请求返回结果,重定向到信息提示页面或者进度展示页面。重定向页面的方法是GET方法。
25
- NotModified: 304, // 资源未变更。服务器根据请求头判断,需要资源未修改,只返回响应头;否则将资源一起返回。
26
- TemporaryRedirect: 307, // 临时重定向。基本和302相同。唯一的区别是这个状态码严格禁止浏览器到新URL请求资源时修改原来的请求方式和请求体。
27
- PermanentRedirect: 308 // 永久重定向。基本和301相同。但是严格禁止修改请求方式和请求体。
28
- },
29
- // 4xx,请求错误
30
- REQUEST_ERROR: {
31
- BadRequest: 400, // 请求语法有问题,服务器无法识别。
32
- UnAuthorized: 401, // 客户端未授权该请求。缺乏有效的身份认证凭证,一般可能是未登陆。登陆后一般都解决问题。
33
- Forbidden: 403, // 服务器拒绝响应。权限不足。
34
- NotFound: 404, // URL无效或者URL有效但是没有资源。
35
- MethodNotAllowed: 405, // 请求方式Method不允许。但是GET和HEAD属于强制方式,不能返回这个状态码。
36
- NotAccepted: 406, // 资源类型不符合服务器要求。
37
- ProxyAuthorizationRequired: 407, // 需要代理授权。
38
- RequestTimeout: 408, // 服务器将不再使用的连接关闭。响应头会有Connection: close。
39
- UpgradeRequired: 426, // 告诉客户端需要升级通信协议。
40
- TokenUnAuthorized: 499, // 告诉客户端需要升级通信协议。
41
- },
42
- // 5xx,服务器错误
43
- SERVER_ERROR: {
44
- InternalServerError: 500, // 服务器内部错误,未捕获。
45
- BadGateway: 502, // 服务器作为网关使用时,收到上游服务器返回的无效响应。
46
- ServiceUnavailable: 503, // 无法服务。一般发生在因维护而停机或者服务过载。一般还会伴随着返回一个响应头Retry-After: 说明恢复服务的估计时间。
47
- GateTimeout: 504, // 网关超时。服务器作为网关或者代理,不能及时从上游服务器获取响应返回给客户端。
48
- HttpVersionNotSupported: 505 // 发出的请求http版本服务器不支持。如果请求通过http2发送,服务器不支持http2.0,就会返回该状态码。
49
- }
50
- },
51
- // http状态码
52
- CODES: {
53
- Success: '00000',
54
- UnAuthorized: '00099',
55
- UnAuthorizedPhone: '11001', //未授权用户手机号
56
- UnAuthorizedWecom: '11000', //调用企微接口异常
57
- UnAuthorizedHavePhone: '11002', //查到手机号但是也报错
58
- },
59
- // http状态码白名单,在具体业务中处理
60
- ERR_CODE_WHITE_LIST: []
61
- }
package/src/iam/index.ts DELETED
@@ -1,46 +0,0 @@
1
- /**
2
- * 扁平化 state 字段
3
- * @param state 需要扁平化的 state 字段
4
- * @param keyName 需要剥离的 key 名称
5
- * @returns 扁平化后的 state 字段
6
- */
7
- function flattenStateRecursive(state: unknown, keyName: string = 'state') {
8
- let result: unknown = state;
9
- let lastResult: unknown;
10
- // 递归解码和解析
11
- while (typeof result === 'string') {
12
- try {
13
- lastResult = result;
14
- result = decodeURIComponent(result as string);
15
- result = JSON.parse(result as string);
16
- } catch {
17
- result = lastResult;
18
- break;
19
- }
20
- }
21
- // 递归剥离 state 字段
22
- while (
23
- result &&
24
- typeof result === 'object' &&
25
- keyName in result &&
26
- (typeof (result as any)[keyName] === 'string' || typeof (result as any)[keyName] === 'object')
27
- ) {
28
- result = (result as any)[keyName];
29
- if (typeof result === 'string') {
30
- try {
31
- result = decodeURIComponent(result as string);
32
- result = JSON.parse(result as string);
33
- } catch {
34
- break;
35
- }
36
- }
37
- }
38
- return result;
39
- }
40
- export const handleFlatStr = (keyName: string = 'state', value: unknown) => {
41
- // return `${key}=${value}`
42
-
43
- let flat = flattenStateRecursive(value, keyName);
44
- let flatStr = typeof flat === 'object' ? JSON.stringify(flat) : String(flat);
45
- return flatStr;
46
- }
package/src/index.ts DELETED
@@ -1,20 +0,0 @@
1
- export * from './common';
2
- export * from './date';
3
- export * from './file';
4
- export * from './object';
5
- export * from './print';
6
- export * from './validate';
7
- export * from './number';
8
- export * from './string';
9
- export * from './http/httpEnums'
10
- export * from './http/http'
11
- export * from './http/apiBuilder'
12
- export * from './middleware/requestLogger.middware'
13
- export * from './iam'
14
- export * from './color';
15
- export * from './array';
16
- export * from './dom';
17
- // chunk-optimizer 是构建时工具,不应该被打包到浏览器端
18
- // 如需使用,请通过单独的导入路径:import { createChunkOptimizer } from 'jinbi-utils/chunk-optimizer'
19
- // export * from './build/chunk-optimizer'
20
- export * from './websocket'