@be-link/pos-cli-nodejs 1.0.49 → 1.0.51-beta.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.
Files changed (86) hide show
  1. package/.github/workflows/JMeter.yml +92 -0
  2. package/.husky/commit-msg +4 -0
  3. package/.versionrc +22 -0
  4. package/CHANGELOG.md +599 -0
  5. package/Makefile +4 -0
  6. package/ceshi.jmx +326 -0
  7. package/ci/index.ts +73 -0
  8. package/commitlint.config.js +3 -0
  9. package/dist/README.md +40 -0
  10. package/dist/package.json +54 -0
  11. package/{types.d.ts → dist/types.d.ts} +138 -16
  12. package/jest.config.js +194 -0
  13. package/package.json +13 -13
  14. package/src/errors/BizError.ts +10 -0
  15. package/src/errors/SystemError.ts +10 -0
  16. package/src/index.ts +33 -0
  17. package/src/pos/http.ts +70 -0
  18. package/src/pos/modules/dataMigrate/service.ts +18 -0
  19. package/src/pos/modules/dataMigrate/types.ts +11 -0
  20. package/src/pos/modules/orderCore/service.ts +80 -0
  21. package/src/pos/modules/orderCore/types.ts +418 -0
  22. package/src/pos/modules/orderFulfill/service.ts +126 -0
  23. package/src/pos/modules/orderFulfill/types.ts +548 -0
  24. package/src/pos/modules/orderJob/service.ts +87 -0
  25. package/src/pos/modules/orderJob/types.ts +54 -0
  26. package/src/pos/modules/orderNote/service.ts +29 -0
  27. package/src/pos/modules/orderNote/types.ts +78 -0
  28. package/src/pos/modules/orderQuery/commodity.ts +59 -0
  29. package/src/pos/modules/orderQuery/store.ts +24 -0
  30. package/src/pos/modules/orderQuery/supplier.ts +34 -0
  31. package/src/pos/modules/orderQuery/types.ts +1159 -0
  32. package/src/pos/modules/orderQuery/user.ts +83 -0
  33. package/src/pos/modules/orderQuery/web.ts +26 -0
  34. package/src/pos/modules/service.ts +31 -0
  35. package/src/types.ts +1237 -0
  36. package/src/utils/env.ts +14 -0
  37. package/src/utils/string.ts +6 -0
  38. package/tsconfig.json +114 -0
  39. package/typedoc.json +15 -0
  40. /package/{errors → dist/errors}/BizError.d.ts +0 -0
  41. /package/{errors → dist/errors}/BizError.js +0 -0
  42. /package/{errors → dist/errors}/SystemError.d.ts +0 -0
  43. /package/{errors → dist/errors}/SystemError.js +0 -0
  44. /package/{index.d.ts → dist/index.d.ts} +0 -0
  45. /package/{index.js → dist/index.js} +0 -0
  46. /package/{pos → dist/pos}/http.d.ts +0 -0
  47. /package/{pos → dist/pos}/http.js +0 -0
  48. /package/{pos → dist/pos}/modules/dataMigrate/service.d.ts +0 -0
  49. /package/{pos → dist/pos}/modules/dataMigrate/service.js +0 -0
  50. /package/{pos → dist/pos}/modules/dataMigrate/types.d.ts +0 -0
  51. /package/{pos → dist/pos}/modules/dataMigrate/types.js +0 -0
  52. /package/{pos → dist/pos}/modules/orderCore/service.d.ts +0 -0
  53. /package/{pos → dist/pos}/modules/orderCore/service.js +0 -0
  54. /package/{pos → dist/pos}/modules/orderCore/types.d.ts +0 -0
  55. /package/{pos → dist/pos}/modules/orderCore/types.js +0 -0
  56. /package/{pos → dist/pos}/modules/orderFulfill/service.d.ts +0 -0
  57. /package/{pos → dist/pos}/modules/orderFulfill/service.js +0 -0
  58. /package/{pos → dist/pos}/modules/orderFulfill/types.d.ts +0 -0
  59. /package/{pos → dist/pos}/modules/orderFulfill/types.js +0 -0
  60. /package/{pos → dist/pos}/modules/orderJob/service.d.ts +0 -0
  61. /package/{pos → dist/pos}/modules/orderJob/service.js +0 -0
  62. /package/{pos → dist/pos}/modules/orderJob/types.d.ts +0 -0
  63. /package/{pos → dist/pos}/modules/orderJob/types.js +0 -0
  64. /package/{pos → dist/pos}/modules/orderNote/service.d.ts +0 -0
  65. /package/{pos → dist/pos}/modules/orderNote/service.js +0 -0
  66. /package/{pos → dist/pos}/modules/orderNote/types.d.ts +0 -0
  67. /package/{pos → dist/pos}/modules/orderNote/types.js +0 -0
  68. /package/{pos → dist/pos}/modules/orderQuery/commodity.d.ts +0 -0
  69. /package/{pos → dist/pos}/modules/orderQuery/commodity.js +0 -0
  70. /package/{pos → dist/pos}/modules/orderQuery/store.d.ts +0 -0
  71. /package/{pos → dist/pos}/modules/orderQuery/store.js +0 -0
  72. /package/{pos → dist/pos}/modules/orderQuery/supplier.d.ts +0 -0
  73. /package/{pos → dist/pos}/modules/orderQuery/supplier.js +0 -0
  74. /package/{pos → dist/pos}/modules/orderQuery/types.d.ts +0 -0
  75. /package/{pos → dist/pos}/modules/orderQuery/types.js +0 -0
  76. /package/{pos → dist/pos}/modules/orderQuery/user.d.ts +0 -0
  77. /package/{pos → dist/pos}/modules/orderQuery/user.js +0 -0
  78. /package/{pos → dist/pos}/modules/orderQuery/web.d.ts +0 -0
  79. /package/{pos → dist/pos}/modules/orderQuery/web.js +0 -0
  80. /package/{pos → dist/pos}/modules/service.d.ts +0 -0
  81. /package/{pos → dist/pos}/modules/service.js +0 -0
  82. /package/{types.js → dist/types.js} +0 -0
  83. /package/{utils → dist/utils}/env.d.ts +0 -0
  84. /package/{utils → dist/utils}/env.js +0 -0
  85. /package/{utils → dist/utils}/string.d.ts +0 -0
  86. /package/{utils → dist/utils}/string.js +0 -0
@@ -1,5 +1,8 @@
1
1
  import * as PosConstants from 'vitality-meta/enums/pos';
2
2
  import * as commodityConstants from 'vitality-meta/enums/commodity';
3
+ import * as CSDto from '@be-link/cs-cli-nodejs/types';
4
+ import * as ServiceVenueDto from '@be-link/cs-cli-nodejs/cs/modules/serviceVenue/types';
5
+ import { CommonSaleStatus } from 'vitality-meta/enums/commodity';
3
6
  /**
4
7
  * 订单正向结构
5
8
  */
@@ -100,6 +103,8 @@ export interface IPositiveAttributes {
100
103
  groupBookingType: number;
101
104
  /** 是否班车信息需要确认 */
102
105
  isShuttleBusNeedCheck: boolean;
106
+ /** 是否是迁移商品订单 */
107
+ isMigratedItemOrder: boolean;
103
108
  /** 快照创建时间 */
104
109
  createdAt: number;
105
110
  /** 快照更新时间 */
@@ -273,6 +278,21 @@ export interface IPositiveItemInfo {
273
278
  /** 更新时间 */
274
279
  updatedAt: number;
275
280
  }
281
+ export type IPositiveItemInfoV2 = {
282
+ _id: string;
283
+ name: string;
284
+ categoryOne: string;
285
+ categoryTwo: string;
286
+ venueId: string;
287
+ supplierId: string;
288
+ basicInfo: CSDto.IItemBasicInfo;
289
+ attributes: CSDto.IItemAttributes;
290
+ hotelItemInfo?: CSDto.IHotelItemInfo;
291
+ /** 金币信息 */
292
+ creditInfo: CreditInfo;
293
+ createdAt: number;
294
+ updatedAt: number;
295
+ };
276
296
  export interface IPositiveSkuInfo {
277
297
  /** SKU ID */
278
298
  _id: string;
@@ -383,6 +403,8 @@ export interface IPositiveSkuInfo {
383
403
  settlementPrice: number;
384
404
  };
385
405
  };
406
+ /** sku类型 */
407
+ type: PosConstants.SkuTypeEnum;
386
408
  /** 剩余数量 */
387
409
  remainQuantity: number;
388
410
  /** 一级类目 */
@@ -394,6 +416,67 @@ export interface IPositiveSkuInfo {
394
416
  /** sku快照更新时间 */
395
417
  updatedAt: number;
396
418
  }
419
+ export interface IPositiveSkuInfoV2 {
420
+ _id: string;
421
+ skuCreatedAt: number;
422
+ skuUpdatedAt: number;
423
+ categoryOne: string;
424
+ categoryTwo: string;
425
+ itemId: string;
426
+ comboId: string;
427
+ status: string;
428
+ stock: number;
429
+ departureDate: number;
430
+ quantity: number;
431
+ salePrice: number;
432
+ settlementPrice: number;
433
+ memberPrice: number;
434
+ memberPriceLimitCnt: number;
435
+ singleRoomPrice: number;
436
+ singleRoomSettlementPrice: number;
437
+ saleBeginTime: number;
438
+ saleEndTime: number;
439
+ lastUpdateStockTime: number;
440
+ type: PosConstants.SkuTypeEnum;
441
+ skuSnapShotId: string;
442
+ remainQuantity: number;
443
+ createdAt: number;
444
+ updatedAt: number;
445
+ }
446
+ export interface IPositiveShuttleBusSkuInfo {
447
+ itemId: string;
448
+ quantity: number;
449
+ relationInfo: {
450
+ id: string;
451
+ createdAt: number;
452
+ updatedAt: number;
453
+ deletedAt: number;
454
+ itemId: string;
455
+ supplierId: string;
456
+ routeId: string;
457
+ status: CommonSaleStatus;
458
+ salePrice: number;
459
+ settlementPrice: number;
460
+ saleDesc: string;
461
+ minOrderCount: number;
462
+ isLimitStock: number;
463
+ pickUpTime: string;
464
+ };
465
+ type: PosConstants.SkuTypeEnum;
466
+ skuSnapShotId: string;
467
+ remainQuantity: number;
468
+ createdAt: number;
469
+ updatedAt: number;
470
+ }
471
+ export type IPositiveOrderComboInfo = {
472
+ id: string;
473
+ createdAt: number;
474
+ updatedAt: number;
475
+ orderId: string;
476
+ comboInfo: CSDto.IItemCombo | CSDto.IItemComboShortcut;
477
+ comboId: string;
478
+ type: PosConstants.ComboTypeEnum;
479
+ };
397
480
  export interface IWxPaymentInfo {
398
481
  appId: string;
399
482
  nonceStr: string;
@@ -458,6 +541,38 @@ export interface CouponSnapShotInfo {
458
541
  /** 优惠券的使用限制。 */
459
542
  usageLimit: any;
460
543
  }
544
+ export interface IPositiveRoomInfo {
545
+ id: string;
546
+ createdAt: number;
547
+ updatedAt: number;
548
+ deletedAt: number;
549
+ orderId: string;
550
+ roomInfo: ServiceVenueDto.ServiceVenue.Response.IGetRoomTypeInfoRes;
551
+ roomId: string;
552
+ }
553
+ export interface IPositiveVenueInfo {
554
+ id: string;
555
+ createdAt: number;
556
+ updatedAt: number;
557
+ deletedAt: number;
558
+ orderId: string;
559
+ venueInfo: ServiceVenueDto.ServiceVenue.Response.IGetServiceVenueInfoRes;
560
+ venueId: string;
561
+ }
562
+ export interface IPositiveFeeDetailInfo {
563
+ id: string;
564
+ createdAt: number;
565
+ updatedAt: number;
566
+ deletedAt: number;
567
+ orderId: string;
568
+ itemId: string;
569
+ comboId: string;
570
+ skuId: string;
571
+ value: number;
572
+ quantity: number;
573
+ type: string;
574
+ desc: string;
575
+ }
461
576
  export interface IPositivePromotionInfo {
462
577
  /** 营销记录Id */
463
578
  _id: string;
@@ -550,6 +665,13 @@ export interface TouristInfo {
550
665
  isVoiceSucceed?: boolean;
551
666
  /** 是否发送短信 */
552
667
  isSmsSucceed?: boolean;
668
+ cardType?: string;
669
+ passportInfo?: {
670
+ region: string;
671
+ birthday: number;
672
+ validityDate: number;
673
+ imageUrl: string;
674
+ };
553
675
  }
554
676
  /** 旅游出行信息,已不再适用,兼容旧数据 */
555
677
  export interface ItineraryInfo {
@@ -819,26 +941,18 @@ export interface IStore {
819
941
  export interface IRawOrderStructure {
820
942
  basicInfo: IPositiveOrder;
821
943
  attributes?: {
822
- isMemberOrder: number;
823
- isFirstTrade: number;
824
- hasMergedOrder: number;
825
- isMerged: number;
826
- isMealInfoModified: number;
827
- isMealInfoConfirmed: number;
828
- isPurchasedInsurance: number;
829
- buyerWxNotificationIsRead: number;
830
- hasSentWXNotification: number;
831
- isAuthSendItineraryInfoSubscribeMessage: number;
832
- isTouristsCompletely: number;
833
- isShuttleBusNeedCheck: number;
834
- isGroupMainOrder: number;
835
- isGroupSubOrder: number;
836
- groupBookingType: number;
944
+ [K in keyof Omit<IPositiveAttributes, 'id' | 'createdAt' | 'updatedAt'>]: number;
837
945
  };
838
946
  commodityInfo?: (IPositiveItemInfo & {
839
947
  skus: IPositiveSkuInfo[];
840
948
  storeInfo?: IStore;
841
949
  })[];
950
+ itemInfo?: IPositiveItemInfoV2;
951
+ skuInfoList?: (IPositiveSkuInfoV2 | IPositiveShuttleBusSkuInfo)[];
952
+ comboInfoList?: IPositiveOrderComboInfo[];
953
+ roomInfoList?: IPositiveRoomInfo[];
954
+ venueInfo?: IPositiveVenueInfo;
955
+ feeDetailInfoList?: IPositiveFeeDetailInfo[];
842
956
  paymentInfo?: IPositivePaymentInfo[];
843
957
  promotionInfo?: IPositivePromotionInfo[];
844
958
  }
@@ -983,7 +1097,15 @@ export interface QueryDataBlockTypeMap {
983
1097
  storeInfo: IStore;
984
1098
  })[];
985
1099
  /** sku快照信息 */
986
- skuInfo: IPositiveSkuInfo[];
1100
+ skuInfo: (IPositiveSkuInfo | IPositiveShuttleBusSkuInfo | IPositiveSkuInfoV2)[];
1101
+ /** 套餐快照信息 */
1102
+ comboInfo: IPositiveOrderComboInfo[];
1103
+ /** 房型快照信息 */
1104
+ roomInfo: IPositiveRoomInfo[];
1105
+ /** 场所快照信息 */
1106
+ venueInfo: IPositiveVenueInfo;
1107
+ /** 费用明细信息 */
1108
+ feeDetailInfoList: IPositiveFeeDetailInfo[];
987
1109
  /** 支付信息 */
988
1110
  paymentInfo: IPositivePaymentInfo[];
989
1111
  /** 营销信息 */
package/jest.config.js ADDED
@@ -0,0 +1,194 @@
1
+ /*
2
+ * For a detailed explanation regarding each configuration property, visit:
3
+ * https://jestjs.io/docs/configuration
4
+ */
5
+
6
+ module.exports = {
7
+ // All imported modules in your tests should be mocked automatically
8
+ // automock: false,
9
+
10
+ // Stop running tests after `n` failures
11
+ // bail: 0,
12
+
13
+ // The directory where Jest should store its cached dependency information
14
+ // cacheDirectory: "/private/var/folders/dt/kcn7j7yj36n1881sqpgzqv3c0000gn/T/jest_dx",
15
+
16
+ // Automatically clear mock calls and instances between every test
17
+ clearMocks: true,
18
+
19
+ // Indicates whether the coverage information should be collected while executing the test
20
+ // collectCoverage: false,
21
+
22
+ // An array of glob patterns indicating a set of files for which coverage information should be collected
23
+ // collectCoverageFrom: undefined,
24
+
25
+ // The directory where Jest should output its coverage files
26
+ // coverageDirectory: undefined,
27
+
28
+ // An array of regexp pattern strings used to skip coverage collection
29
+ // coveragePathIgnorePatterns: [
30
+ // "/node_modules/"
31
+ // ],
32
+
33
+ // Indicates which provider should be used to instrument code for coverage
34
+ coverageProvider: 'v8',
35
+
36
+ // A list of reporter names that Jest uses when writing coverage reports
37
+ // coverageReporters: [
38
+ // "json",
39
+ // "text",
40
+ // "lcov",
41
+ // "clover"
42
+ // ],
43
+
44
+ // An object that configures minimum threshold enforcement for coverage results
45
+ // coverageThreshold: undefined,
46
+
47
+ // A path to a custom dependency extractor
48
+ // dependencyExtractor: undefined,
49
+
50
+ // Make calling deprecated APIs throw helpful error messages
51
+ // errorOnDeprecated: false,
52
+
53
+ // Force coverage collection from ignored files using an array of glob patterns
54
+ // forceCoverageMatch: [],
55
+
56
+ // A path to a module which exports an async function that is triggered once before all test suites
57
+ // globalSetup: undefined,
58
+
59
+ // A path to a module which exports an async function that is triggered once after all test suites
60
+ // globalTeardown: undefined,
61
+
62
+ // A set of global variables that need to be available in all test environments
63
+ // globals: {},
64
+
65
+ // The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
66
+ // maxWorkers: "50%",
67
+
68
+ // An array of directory names to be searched recursively up from the requiring module's location
69
+ // moduleDirectories: [
70
+ // "node_modules"
71
+ // ],
72
+
73
+ // An array of file extensions your modules use
74
+ moduleFileExtensions: [
75
+ "js",
76
+ "jsx",
77
+ "ts",
78
+ "tsx",
79
+ "json",
80
+ "node"
81
+ ],
82
+
83
+ // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
84
+ // moduleNameMapper: {},
85
+
86
+ // An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
87
+ // modulePathIgnorePatterns: [],
88
+
89
+ // Activates notifications for test results
90
+ // notify: false,
91
+
92
+ // An enum that specifies notification mode. Requires { notify: true }
93
+ // notifyMode: "failure-change",
94
+
95
+ // A preset that is used as a base for Jest's configuration
96
+ preset: 'ts-jest',
97
+
98
+ // Run tests from one or more projects
99
+ // projects: undefined,
100
+
101
+ // Use this configuration option to add custom reporters to Jest
102
+ // reporters: undefined,
103
+
104
+ // Automatically reset mock state between every test
105
+ // resetMocks: false,
106
+
107
+ // Reset the module registry before running each individual test
108
+ // resetModules: false,
109
+
110
+ // A path to a custom resolver
111
+ // resolver: undefined,
112
+
113
+ // Automatically restore mock state between every test
114
+ // restoreMocks: false,
115
+
116
+ // The root directory that Jest should scan for tests and modules within
117
+ // rootDir: undefined,
118
+
119
+ // A list of paths to directories that Jest should use to search for files in
120
+ // roots: [
121
+ // "<rootDir>"
122
+ // ],
123
+
124
+ // Allows you to use a custom runner instead of Jest's default test runner
125
+ // runner: "jest-runner",
126
+
127
+ // The paths to modules that run some code to configure or set up the testing environment before each test
128
+ // setupFiles: [],
129
+
130
+ // A list of paths to modules that run some code to configure or set up the testing framework before each test
131
+ // setupFilesAfterEnv: [],
132
+
133
+ // The number of seconds after which a test is considered as slow and reported as such in the results.
134
+ // slowTestThreshold: 5,
135
+
136
+ // A list of paths to snapshot serializer modules Jest should use for snapshot testing
137
+ // snapshotSerializers: [],
138
+
139
+ // The test environment that will be used for testing
140
+ // testEnvironment: "jest-environment-node",
141
+
142
+ // Options that will be passed to the testEnvironment
143
+ // testEnvironmentOptions: {},
144
+
145
+ // Adds a location field to test results
146
+ // testLocationInResults: false,
147
+
148
+ // The glob patterns Jest uses to detect test files
149
+ // testMatch: [
150
+ // "**/__tests__/**/*.[jt]s?(x)",
151
+ // "**/?(*.)+(spec|test).[tj]s?(x)"
152
+ // ],
153
+
154
+ // An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
155
+ // testPathIgnorePatterns: [
156
+ // "/node_modules/"
157
+ // ],
158
+
159
+ // The regexp pattern or array of patterns that Jest uses to detect test files
160
+ // testRegex: [],
161
+
162
+ // This option allows the use of a custom results processor
163
+ // testResultsProcessor: undefined,
164
+
165
+ // This option allows use of a custom test runner
166
+ // testRunner: "jest-circus/runner",
167
+
168
+ // This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
169
+ // testURL: "http://localhost",
170
+
171
+ // Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
172
+ // timers: "real",
173
+
174
+ // A map from regular expressions to paths to transformers
175
+ transform: { "^.+\\.ts?$": "ts-jest" },
176
+
177
+ // An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
178
+ // transformIgnorePatterns: [
179
+ // "/node_modules/",
180
+ // "\\.pnp\\.[^\\/]+$"
181
+ // ],
182
+
183
+ // An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
184
+ // unmockedModulePathPatterns: undefined,
185
+
186
+ // Indicates whether each individual test should be reported during the run
187
+ // verbose: undefined,
188
+
189
+ // An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
190
+ // watchPathIgnorePatterns: [],
191
+
192
+ // Whether to use watchman for file crawling
193
+ // watchman: true,
194
+ }
package/package.json CHANGED
@@ -1,18 +1,8 @@
1
1
  {
2
2
  "name": "@be-link/pos-cli-nodejs",
3
- "version": "1.0.49",
3
+ "version": "1.0.51-beta.0",
4
4
  "description": "正向订单服务Nodejs客户端",
5
5
  "main": "index.js",
6
- "scripts": {
7
- "build": "rm -rf ./dist && tsc && cp package.json README.md ./dist/",
8
- "test": "npx jest",
9
- "gen-doc": "npx typedoc --options typedoc.json",
10
- "update:major": "standard-version --release-as major",
11
- "update:minor": "standard-version --release-as minor",
12
- "update:patch": "standard-version --release-as patch",
13
- "update:beta": "standard-version --prerelease beta",
14
- "publish": "ts-node ./ci/index"
15
- },
16
6
  "repository": {
17
7
  "type": "git",
18
8
  "url": "git+https://github.com/snowmountain-top/pos-cli-nodejs.git"
@@ -48,6 +38,16 @@
48
38
  "axios": "0.27.2",
49
39
  "axios-retry": "^4.0.0",
50
40
  "uuid": "^9.0.1",
51
- "vitality-meta": "1.0.165"
41
+ "vitality-meta": "1.0.165",
42
+ "@be-link/cs-cli-nodejs": "0.1.1"
43
+ },
44
+ "scripts": {
45
+ "build": "rm -rf ./dist && tsc && cp package.json README.md ./dist/",
46
+ "test": "npx jest",
47
+ "gen-doc": "npx typedoc --options typedoc.json",
48
+ "update:major": "standard-version --release-as major",
49
+ "update:minor": "standard-version --release-as minor",
50
+ "update:patch": "standard-version --release-as patch",
51
+ "update:beta": "standard-version --prerelease beta"
52
52
  }
53
- }
53
+ }
@@ -0,0 +1,10 @@
1
+ export default class BizError extends Error {
2
+
3
+ code: number
4
+
5
+ constructor(message: string, code: number = 400) {
6
+ super(message)
7
+ this.code = code
8
+ this.name = 'BizError'
9
+ }
10
+ }
@@ -0,0 +1,10 @@
1
+ export default class SystemError extends Error {
2
+
3
+ code: number
4
+
5
+ constructor(message: string, code: number = 500) {
6
+ super(message)
7
+ this.code = code
8
+ this.name = 'SystemError'
9
+ }
10
+ }
package/src/index.ts ADDED
@@ -0,0 +1,33 @@
1
+ import * as PosConstants from 'vitality-meta/enums/pos'
2
+ import * as PosDto from './types'
3
+ import BizError from './errors/BizError'
4
+
5
+ import orderCoreService from './pos/modules/orderCore/service'
6
+ import orderFulfillService from './pos/modules/orderFulfill/service'
7
+ import queryByCommodityService from './pos/modules/orderQuery/commodity'
8
+ import queryByStoreService from './pos/modules/orderQuery/store'
9
+ import queryByUserService from './pos/modules/orderQuery/user'
10
+ import queryByWebService from './pos/modules/orderQuery/web'
11
+ import queryBySupplierService from './pos/modules/orderQuery/supplier'
12
+ import orderNoteService from './pos/modules/orderNote/service'
13
+ import orderJobService from './pos/modules/orderJob/service'
14
+ import dataMigrateService from './pos/modules/dataMigrate/service'
15
+
16
+ export {
17
+ /** 业务模块 */
18
+ orderCoreService,
19
+ orderFulfillService,
20
+ queryByCommodityService,
21
+ queryByStoreService,
22
+ queryByUserService,
23
+ queryByWebService,
24
+ queryBySupplierService,
25
+ orderNoteService,
26
+ orderJobService,
27
+ dataMigrateService,
28
+ /** 枚举类 */
29
+ PosConstants,
30
+ PosDto,
31
+ /** 错误类 */
32
+ BizError
33
+ }
@@ -0,0 +1,70 @@
1
+ import axios, {AxiosError} from 'axios'
2
+ import { v4 as uuidV4 } from 'uuid'
3
+ import BizError from '../errors/BizError'
4
+ import SystemError from '../errors/SystemError'
5
+ import axiosRetry from 'axios-retry'
6
+
7
+ const axiosInstance = axios.create(
8
+ {
9
+ timeout: 55000,
10
+ httpsAgent: new (require('https').Agent)({ keepAlive: true }),
11
+ httpAgent: new (require('http').Agent)({ keepAlive: true }),
12
+ }
13
+ )
14
+
15
+ axiosRetry(axiosInstance, {
16
+ retries: 1,
17
+ retryCondition(error) {
18
+ console.info('errorMessage', error.message)
19
+ console.info('errorResponse', error.response ? error.response.data : null)
20
+ const isSocketHangUp = error.message.includes('socket hang up')
21
+ return isSocketHangUp || error.message.includes('getaddrinfo ENOTFOUND') || (Boolean(error.response) && [502, 503].includes(error.response!.status))
22
+ },
23
+ retryDelay: (retryCount, error) => {
24
+ console.info(`retryCount: ${retryCount}, retryDelay: ${retryCount * 500}`)
25
+ return retryCount * 500
26
+ },
27
+ onRetry(retryCount, error, requestConfig) {
28
+ console.info(`retryCount: ${retryCount}, onRetry: ${error}, requestHeader: ${JSON.stringify(requestConfig.headers)}`)
29
+ },
30
+ })
31
+
32
+ type ResponseData = {
33
+ data: any
34
+ message: string
35
+ }
36
+
37
+ export async function callApi<T extends (args: any) => Promise<any>>(url: string, ...request: Parameters<T>)
38
+ : Promise<Awaited<ReturnType<T>>>
39
+ {
40
+ const requestId = uuidV4()
41
+ try {
42
+ console.info(`准备发起POS请求[${requestId}]: ${url}, 参数: ${JSON.stringify(request)}`)
43
+ const response = await axiosInstance.post(url, request[0], {
44
+ headers: {
45
+ 'X-Request-Id': requestId,
46
+ 'x-belink-accessType': 'authorizationTokenInside',
47
+ 'x-belink-authorization': process.env.authorizationTokenInside || ""
48
+ }
49
+ })
50
+ const responseData = response.data as ResponseData
51
+ return responseData.data
52
+ } catch (error: any) {
53
+ const axiosError = error as AxiosError
54
+ const ErrorClass = axiosError.response
55
+ ? axiosError.response.status === 400
56
+ ? BizError
57
+ : SystemError
58
+ : SystemError
59
+ if (axiosError.response) {
60
+ const response = axiosError.response
61
+ const data = response.data as ResponseData
62
+ console.error(`POS 异常[${requestId}]: ${axiosError.message}`)
63
+ console.info('响应信息', data.message)
64
+ console.error('异常堆栈', JSON.stringify(error.stack))
65
+ throw new ErrorClass(data.message || 'Pos Error', response.status)
66
+ }
67
+ console.error(`POS 未知异常[${requestId}]: ${axiosError.message}`, error.stack)
68
+ throw error
69
+ }
70
+ }
@@ -0,0 +1,18 @@
1
+ import { Service } from './types'
2
+ import { callApi } from '../../http'
3
+ import BaseService from '../service'
4
+
5
+ class DataMigrateService extends BaseService implements Service.DataMigrateController {
6
+ protected prefixUrl: string = '/dataMigrate'
7
+
8
+ pos(): Promise<void> {
9
+ return callApi<Service.DataMigrateController['pos']>(this.getApiUrl(this.pos))
10
+ }
11
+ rev(): Promise<void> {
12
+ return callApi<Service.DataMigrateController['rev']>(this.getApiUrl(this.rev))
13
+ }
14
+ }
15
+
16
+ const dataMigrateService = new DataMigrateService()
17
+
18
+ export default dataMigrateService
@@ -0,0 +1,11 @@
1
+ import * as PosConstants from 'vitality-meta/enums/pos'
2
+ import * as DTO from '../../../types'
3
+
4
+
5
+ export namespace Service {
6
+
7
+ export interface DataMigrateController {
8
+ pos(): Promise<void>
9
+ rev(): Promise<void>
10
+ }
11
+ }