@pisell/utils 2.0.1 → 2.0.2

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.
package/lib/index.js CHANGED
@@ -2,6 +2,10 @@ var __defProp = Object.defineProperty;
2
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
5
9
  var __copyProps = (to, from, except, desc) => {
6
10
  if (from && typeof from === "object" || typeof from === "function") {
7
11
  for (let key of __getOwnPropNames(from))
@@ -15,6 +19,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
15
19
 
16
20
  // src/index.ts
17
21
  var src_exports = {};
22
+ __export(src_exports, {
23
+ getPisellUtilsConfig: () => getPisellUtilsConfig,
24
+ setPisellUtilsConfig: () => setPisellUtilsConfig
25
+ });
18
26
  module.exports = __toCommonJS(src_exports);
19
27
  __reExport(src_exports, require("./otherUtils"), module.exports);
20
28
  __reExport(src_exports, require("./typeUtils"), module.exports);
@@ -29,8 +37,21 @@ __reExport(src_exports, require("./jsBridge"), module.exports);
29
37
  __reExport(src_exports, require("./image"), module.exports);
30
38
  __reExport(src_exports, require("./locales"), module.exports);
31
39
  __reExport(src_exports, require("./arrayUtils"), module.exports);
40
+ var setPisellUtilsConfig = (config) => {
41
+ globalThis.pisellUtilsConfig = {
42
+ ...globalThis.pisellUtilsConfig || {},
43
+ ...config || {}
44
+ };
45
+ console.log("PisellUtilsConfig_set>>>>", config, globalThis);
46
+ };
47
+ var getPisellUtilsConfig = () => {
48
+ console.log("PisellUtilsConfig_get>>>>", globalThis);
49
+ return globalThis.pisellUtilsConfig || {};
50
+ };
32
51
  // Annotate the CommonJS export names for ESM import in node:
33
52
  0 && (module.exports = {
53
+ getPisellUtilsConfig,
54
+ setPisellUtilsConfig,
34
55
  ...require("./otherUtils"),
35
56
  ...require("./typeUtils"),
36
57
  ...require("./document"),
@@ -1,106 +1,22 @@
1
- declare type LanguageNumber = {
2
- en: number;
3
- zh_CN: number;
4
- zh_HK: number;
5
- };
6
- declare type LanguageString = {
7
- en: string;
8
- zh_CN: string;
9
- zh_HK: string;
10
- } | string;
1
+ import { WebPrintParams, DataManagerParams, WebPaymentParams } from './types';
11
2
  /**
12
- * 打印小票
3
+ * webView页面中调用打印机打印
4
+ * 此api暂时只支持native app平台下ios手机
5
+ * @param params
6
+ * @param callback
13
7
  */
14
- declare type WebPrint0 = {
15
- /**
16
- * 打印类型
17
- * 0: 小票
18
- * 1:ITS备货单/划菜单
19
- * 2:手环
20
- */
21
- type: "0";
22
- data: {
23
- /** 订单ID */
24
- order_id: string;
25
- };
26
- /** 打印语言对应的数量 */
27
- language: LanguageNumber;
28
- };
8
+ export declare function webPrint(params: WebPrintParams, callback: (...arg: any) => void, onError?: (error: any) => void): void;
29
9
  /**
30
- * 打印ITS备货单/划菜单
10
+ * webView页面中调用APP内的数据
11
+ * 此api暂时只支持native app平台下ios手机
12
+ * @param params
13
+ * @param callback
31
14
  */
32
- declare type WebPrint1 = {
33
- /**
34
- * 打印类型
35
- * 0: 小票
36
- * 1:ITS备货单/划菜单
37
- * 2:手环
38
- */
39
- type: "1";
40
- data: {
41
- /** 0:备货 1:划单 */
42
- mode: "0" | "1";
43
- resource: LanguageString;
44
- /** 订单备注 */
45
- order_note: string;
46
- /** 订单时间或商品下单时间 */
47
- time: string;
48
- /** 订单编号 */
49
- order_number?: string;
50
- /** 商品 */
51
- products: {
52
- /** 商品名称 */
53
- product_title: LanguageString;
54
- /** 商品规格 */
55
- product_option_string: LanguageString;
56
- /** 商品备注 */
57
- product_note: string;
58
- /** 商品数量 */
59
- product_quantity: number;
60
- /** 加菜标识 待定 */
61
- is_append?: boolean;
62
- /** 退菜标识 待定 */
63
- is_removed?: boolean;
64
- }[];
65
- };
66
- /** 打印语言对应的数量 */
67
- language: LanguageNumber;
68
- };
69
- declare type WebPrint2 = {
70
- /**
71
- * 打印类型
72
- * 0: 小票
73
- * 1:ITS备货单/划菜单
74
- * 2:手环
75
- */
76
- type: "2";
77
- data: {
78
- /** 0: 普通票 1:成人票 2:免费成人票 */
79
- type: "0" | "1" | "2";
80
- /** 发行编码 */
81
- encoded: string;
82
- /** 编码 */
83
- code: string;
84
- /** 到期时间 */
85
- expire_date: string;
86
- areas: {
87
- /** 区域名字 */
88
- area_name: string;
89
- /** 区域代码 */
90
- area_code: string;
91
- /** 可用次数 */
92
- limit_num: number;
93
- /** 已用次数 */
94
- used_num: number;
95
- }[];
96
- };
97
- };
98
- declare type WebPrintParams = WebPrint0 | WebPrint1 | WebPrint2;
15
+ export declare function dataManager(params: DataManagerParams, callback: (...arg: any) => void, onError: () => void): void;
99
16
  /**
100
- * webView页面中调用打印机打印
101
- * 此api暂时只支持native app平台下ios手机
17
+ * webView页面中调用APP内的支付
18
+ * 此api暂时只支持native app平台下ios
102
19
  * @param params
103
20
  * @param callback
104
21
  */
105
- export declare function webPrint(params: WebPrintParams, callback: (...arg: any) => void): void;
106
- export {};
22
+ export declare function webPayment(params: WebPaymentParams, callback: (...arg: any) => void, onError?: (error: any) => void): void;
@@ -29,11 +29,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  // src/jsBridge/index.ts
30
30
  var jsBridge_exports = {};
31
31
  __export(jsBridge_exports, {
32
+ dataManager: () => dataManager,
33
+ webPayment: () => webPayment,
32
34
  webPrint: () => webPrint
33
35
  });
34
36
  module.exports = __toCommonJS(jsBridge_exports);
35
37
  var import_regDeviceApi = __toESM(require("./regDeviceApi"));
36
- function webPrint(params, callback) {
38
+ function webPrint(params, callback, onError) {
37
39
  (0, import_regDeviceApi.default)().then((jsBridge) => {
38
40
  jsBridge.callDeviceApi({
39
41
  apiName: "webPrint",
@@ -42,9 +44,39 @@ function webPrint(params, callback) {
42
44
  callback && callback(...arg);
43
45
  }
44
46
  });
47
+ }).catch((err) => {
48
+ onError == null ? void 0 : onError(err);
49
+ console.error("webPrint", err);
50
+ });
51
+ }
52
+ function dataManager(params, callback, onError) {
53
+ (0, import_regDeviceApi.default)().then((jsBridge) => {
54
+ jsBridge.callDeviceApi({
55
+ apiName: "dataManager",
56
+ params,
57
+ callback: (...arg) => {
58
+ callback && callback(...arg);
59
+ }
60
+ });
61
+ }).catch(onError);
62
+ }
63
+ function webPayment(params, callback, onError) {
64
+ (0, import_regDeviceApi.default)().then((jsBridge) => {
65
+ jsBridge.callDeviceApi({
66
+ apiName: "webPayment",
67
+ params,
68
+ callback: (...arg) => {
69
+ callback && callback(...arg);
70
+ }
71
+ });
72
+ }).catch((err) => {
73
+ onError == null ? void 0 : onError(err);
74
+ console.error("webPayment", err);
45
75
  });
46
76
  }
47
77
  // Annotate the CommonJS export names for ESM import in node:
48
78
  0 && (module.exports = {
79
+ dataManager,
80
+ webPayment,
49
81
  webPrint
50
82
  });
@@ -60,8 +60,7 @@ function regAndroidJsBridge(extraInit) {
60
60
  (event) => {
61
61
  const { bridge } = event;
62
62
  window._jsBridge = bridge;
63
- if (!bridge)
64
- return;
63
+ if (!bridge) return;
65
64
  bridge.init((message, responseCallback) => {
66
65
  if (responseCallback) {
67
66
  responseCallback("init responseCallback");
@@ -86,27 +85,20 @@ function getComposedBridge(deviceType) {
86
85
  } catch (error) {
87
86
  console.log(`error ${apiName}`, error);
88
87
  }
89
- if (result.code || result.code === 0) {
90
- result.code = `${result.code}`;
91
- }
92
88
  inCb(result, ...args);
93
89
  };
94
90
  if (deviceType === "iphone") {
95
91
  iosBridge.callHandler(apiName, params, callback, (e) => {
96
- console.log(e, "--- \u8C03\u7528ios api\u62A5\u9519\uFF1A", apiName);
92
+ console.log(e, "--- 调用ios api报错:", apiName);
97
93
  if (onError) {
98
94
  onError(e);
99
95
  }
100
96
  });
101
97
  } else if (deviceType === "android") {
102
- androidBridge.callHandler(apiName, params, callback, (e) => {
103
- console.log(e, "--- \u8C03\u7528android api\u62A5\u9519\uFF1A", apiName);
104
- if (onError) {
105
- onError(e);
106
- }
107
- });
98
+ const res = androidBridge.callHandler(apiName, JSON.stringify(params));
99
+ callback(res);
108
100
  } else {
109
- console.log("--- \u6CA1\u83B7\u53D6\u5230js bridge ---");
101
+ console.log("--- 没获取到js bridge ---");
110
102
  }
111
103
  },
112
104
  // 被设备调用的方法
@@ -0,0 +1,17 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+
15
+ // src/jsBridge/types.ts
16
+ var types_exports = {};
17
+ module.exports = __toCommonJS(types_exports);
package/lib/locales.js CHANGED
@@ -50,7 +50,6 @@ var init = (_localeMaps, _locale) => {
50
50
  }
51
51
  localeMaps = allLocales;
52
52
  localeMap = localeMaps[locale];
53
- console.log("\u591A\u8BED\u8A00\u6CE8\u5165\u6210\u529F, \u5F53\u524D\u8BED\u8A00\u4E3A:" + locale);
54
53
  };
55
54
  var getText = (id) => {
56
55
  return localeMap[id] || id;
package/lib/log.js CHANGED
@@ -22,6 +22,7 @@ __export(log_exports, {
22
22
  sendWarningLog: () => sendWarningLog
23
23
  });
24
24
  module.exports = __toCommonJS(log_exports);
25
+ var import_index = require("./index");
25
26
  var import_constants = require("./constants");
26
27
  var createFeishuMessageContent = (contentArr) => {
27
28
  return JSON.stringify(
@@ -35,7 +36,15 @@ var createFeishuMessageContent = (contentArr) => {
35
36
  };
36
37
  var sendWarningLog = async ({ title, content }) => {
37
38
  const contentStr = createFeishuMessageContent(content);
38
- const response = await fetch(import_constants.webHookApi.warning_log, {
39
+ let apiUrl = "";
40
+ const config = (0, import_index.getPisellUtilsConfig)();
41
+ console.log("PISELL_UTILS_CONFIG>>>>", config);
42
+ if ((config == null ? void 0 : config.env) === "dev" || (config == null ? void 0 : config.env) === "pre" || (config == null ? void 0 : config.env) === "release") {
43
+ apiUrl = import_constants.webHookApi.warning_log.test;
44
+ } else {
45
+ apiUrl = import_constants.webHookApi.warning_log.prod;
46
+ }
47
+ const response = await fetch(apiUrl, {
39
48
  headers: {
40
49
  "Content-Type": "application/json"
41
50
  },
package/package.json CHANGED
@@ -1,6 +1,10 @@
1
1
  {
2
2
  "name": "@pisell/utils",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
+ "scripts": {
5
+ "build": "father build",
6
+ "dev": "father dev"
7
+ },
4
8
  "sideEffects": false,
5
9
  "main": "./lib/index.js",
6
10
  "module": "./es/index.js",
@@ -24,9 +28,5 @@
24
28
  ],
25
29
  "publishConfig": {
26
30
  "access": "public"
27
- },
28
- "scripts": {
29
- "build": "father build",
30
- "dev": "father dev"
31
31
  }
32
32
  }
@@ -1,4 +0,0 @@
1
- declare const webHookApi: {
2
- warning_log: string;
3
- };
4
- export { webHookApi };
package/es/locales.d.ts DELETED
@@ -1,12 +0,0 @@
1
- export declare const locales: {
2
- init: (_localeMaps: any, _locale: string) => void;
3
- getText: (id: string) => any;
4
- locale: string;
5
- localeMap: any;
6
- localeMaps: {
7
- en: {};
8
- 'zh-CN': {};
9
- 'zh-HK': {};
10
- };
11
- formatLocale: (_locale: string) => string;
12
- };
@@ -1,4 +0,0 @@
1
- declare const webHookApi: {
2
- warning_log: string;
3
- };
4
- export { webHookApi };
package/lib/locales.d.ts DELETED
@@ -1,12 +0,0 @@
1
- export declare const locales: {
2
- init: (_localeMaps: any, _locale: string) => void;
3
- getText: (id: string) => any;
4
- locale: string;
5
- localeMap: any;
6
- localeMaps: {
7
- en: {};
8
- 'zh-CN': {};
9
- 'zh-HK': {};
10
- };
11
- formatLocale: (_locale: string) => string;
12
- };