@alipay/ams-checkout 1.11.1 → 1.13.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.
@@ -12,6 +12,7 @@ type Extra = Record<string, any>;
12
12
  export interface LogMetaData {
13
13
  platform?: string;
14
14
  sdkVersion?: string;
15
+ webAppVersion?: string;
15
16
  fistLogTime?: number;
16
17
  fsDuration?: number;
17
18
  instanceId?: string;
@@ -23,6 +24,7 @@ export interface LogMetaData {
23
24
  paymentMethodType?: string;
24
25
  paymentMethodCategoryType?: string;
25
26
  requestSeq?: string;
27
+ trackId?: string;
26
28
  }
27
29
  interface Config {
28
30
  scriptUrl: string;
@@ -41,7 +43,11 @@ export declare class Logger {
41
43
  private debug;
42
44
  private componentStartTime;
43
45
  private isLoaded;
46
+ private static instance;
47
+ private trackId;
44
48
  constructor(config: Config, debug: boolean);
49
+ static setInstance(instance: Logger): Logger;
50
+ static getInstance(): Logger;
45
51
  setMedta(mdata: LogMetaData): void;
46
52
  logError(error: LogPayload, extra?: Extra): Logger;
47
53
  logInfo(info: LogPayload, extra?: Extra): Logger;
@@ -51,6 +57,8 @@ export declare class Logger {
51
57
  initTracker(): void;
52
58
  send(): void;
53
59
  setComponentStartTime(val: number): void;
60
+ setTrackId(trackId: string): void;
61
+ getComponentStartTime(): number;
54
62
  }
55
63
  export declare const LogConfig: Config;
56
64
  export {};
@@ -15,6 +15,7 @@ export var Logger = /*#__PURE__*/function () {
15
15
  _defineProperty(this, "debug", void 0);
16
16
  _defineProperty(this, "componentStartTime", void 0);
17
17
  _defineProperty(this, "isLoaded", void 0);
18
+ _defineProperty(this, "trackId", void 0);
18
19
  this.logs = [];
19
20
  this.config = config;
20
21
  this.debug = debug;
@@ -99,19 +100,28 @@ export var Logger = /*#__PURE__*/function () {
99
100
  try {
100
101
  var log = logs.pop();
101
102
  if (log.type === 'error') {
103
+ var _log$logPayload;
102
104
  logError(log.logPayload, _objectSpread({
103
105
  fsDuration: fsDuration,
104
- timeStamp: now
106
+ timeStamp: now,
107
+ trackId: this.trackId,
108
+ title: (_log$logPayload = log.logPayload) === null || _log$logPayload === void 0 ? void 0 : _log$logPayload.title
105
109
  }, log === null || log === void 0 ? void 0 : log.extra));
106
110
  } else if (log.type === 'info') {
111
+ var _log$logPayload2;
107
112
  logInfo(log.logPayload, _objectSpread({
108
113
  fsDuration: fsDuration,
109
- timeStamp: now
114
+ timeStamp: now,
115
+ trackId: this.trackId,
116
+ title: (_log$logPayload2 = log.logPayload) === null || _log$logPayload2 === void 0 ? void 0 : _log$logPayload2.title
110
117
  }, log === null || log === void 0 ? void 0 : log.extra));
111
118
  } else if (log.type === 'rpc') {
119
+ var _log$logPayload3;
112
120
  reportRPC(log.logPayload, _objectSpread({
113
121
  fsDuration: fsDuration,
114
- timeStamp: now
122
+ timeStamp: now,
123
+ trackId: this.trackId,
124
+ title: (_log$logPayload3 = log.logPayload) === null || _log$logPayload3 === void 0 ? void 0 : _log$logPayload3.title
115
125
  }, log === null || log === void 0 ? void 0 : log.extra));
116
126
  }
117
127
  } catch (error) {
@@ -166,9 +176,30 @@ export var Logger = /*#__PURE__*/function () {
166
176
  value: function setComponentStartTime(val) {
167
177
  this.componentStartTime = val;
168
178
  }
179
+ }, {
180
+ key: "setTrackId",
181
+ value: function setTrackId(trackId) {
182
+ this.trackId = trackId;
183
+ }
184
+ }, {
185
+ key: "getComponentStartTime",
186
+ value: function getComponentStartTime() {
187
+ return this.componentStartTime;
188
+ }
189
+ }], [{
190
+ key: "setInstance",
191
+ value: function setInstance(instance) {
192
+ return this.instance = instance;
193
+ }
194
+ }, {
195
+ key: "getInstance",
196
+ value: function getInstance() {
197
+ return this.instance;
198
+ }
169
199
  }]);
170
200
  return Logger;
171
201
  }();
202
+ _defineProperty(Logger, "instance", void 0);
172
203
  export var LogConfig = {
173
204
  scriptUrl: 'https://gw.alipayobjects.com/render/p/yuyan_npm/@alipay_intl-tracker/1.6.0/dist/common.min.js',
174
205
  spmConfig: {},
@@ -0,0 +1,2 @@
1
+ export declare const getStorageString: (key: string, fallback?: string) => string;
2
+ export declare const setStorageString: (key: string, value: string) => boolean;
@@ -0,0 +1,23 @@
1
+ export var getStorageString = function getStorageString(key) {
2
+ var fallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
3
+ try {
4
+ if (key && window) {
5
+ var storageValue = window.localStorage.getItem(key);
6
+ if (storageValue) {
7
+ return storageValue;
8
+ }
9
+ return fallback;
10
+ }
11
+ } catch (error) {
12
+ return fallback;
13
+ }
14
+ };
15
+ export var setStorageString = function setStorageString(key, value) {
16
+ try {
17
+ if (key && window) {
18
+ window.localStorage.setItem(key, value);
19
+ return true;
20
+ }
21
+ } catch (error) {}
22
+ return false;
23
+ };
@@ -0,0 +1,39 @@
1
+ export declare function isWebPlatform(platform?: string): boolean;
2
+ export interface UpgradeItem {
3
+ productScene?: string;
4
+ v: string;
5
+ appVersion: string;
6
+ platform?: string;
7
+ mid?: string;
8
+ greyscale?: string;
9
+ }
10
+ export interface UpgradeSdkInfo {
11
+ productScene?: string;
12
+ sdkVersion: string;
13
+ appVersion?: string;
14
+ greyscale?: number;
15
+ mid?: string;
16
+ }
17
+ export declare function findUpgradeVersion(upgradeItems: UpgradeItem[], sdkInfo: UpgradeSdkInfo): string;
18
+ export declare const getGrascaleId: (key?: string) => string;
19
+ export declare function getGrayscaleValue(seed?: string): number;
20
+ export declare function isGreyscaleMatch(item: UpgradeItem, randomGreyscale: number): boolean;
21
+ /**
22
+ * 查询匹配到的版本
23
+ * @param _extendInfo
24
+ * @param param1
25
+ * @returns
26
+ */
27
+ export declare const getMatchAppVersion: (_extendInfo: string, sdkInfo: UpgradeSdkInfo) => string;
28
+ /**
29
+ * 获取保存的加载版本
30
+ * @param productScene
31
+ * @returns
32
+ */
33
+ export declare const getLastAppVersion: (productScene: string) => string;
34
+ /**
35
+ * 保存指定场景的加载版本供下次使用
36
+ * @param productScene
37
+ * @returns
38
+ */
39
+ export declare const setLastAppVersion: (productScene: string, appVersion: string) => boolean;
@@ -0,0 +1,115 @@
1
+ import { v4 as uuid } from 'uuid';
2
+ import { getStorageString, setStorageString } from "./storage";
3
+ import { compareVersion, isVersionInStringRange } from "./versionCompare";
4
+ export function isWebPlatform(platform) {
5
+ if (platform) {
6
+ return platform.toUpperCase().includes('Web'.toUpperCase()) || platform === '';
7
+ }
8
+ return true;
9
+ }
10
+ export function findUpgradeVersion(upgradeItems, sdkInfo) {
11
+ var sortedItems = upgradeItems.sort(function (a, b) {
12
+ return compareVersion(b.appVersion, a.appVersion);
13
+ });
14
+ // console.log("sortedItems",sortedItems)
15
+ var upgradeItem = sortedItems.find(function (item) {
16
+ if (isVersionInStringRange(sdkInfo.sdkVersion, item.v) && isWebPlatform(item.platform)) {
17
+ var _item$productScene, _sdkInfo$productScene, _item$mid, _sdkInfo$mid, _sdkInfo$greyscale;
18
+ var matchProductScene = (_item$productScene = item.productScene) !== null && _item$productScene !== void 0 && _item$productScene.trim() ? item.productScene.toUpperCase().includes(sdkInfo === null || sdkInfo === void 0 || (_sdkInfo$productScene = sdkInfo.productScene) === null || _sdkInfo$productScene === void 0 ? void 0 : _sdkInfo$productScene.toUpperCase()) : true;
19
+ var matchMid = (_item$mid = item.mid) !== null && _item$mid !== void 0 && _item$mid.trim() ? item.mid.toUpperCase().includes(sdkInfo === null || sdkInfo === void 0 || (_sdkInfo$mid = sdkInfo.mid) === null || _sdkInfo$mid === void 0 ? void 0 : _sdkInfo$mid.toUpperCase()) : true;
20
+ var matchGreyscale = isGreyscaleMatch(item, (_sdkInfo$greyscale = sdkInfo.greyscale) !== null && _sdkInfo$greyscale !== void 0 ? _sdkInfo$greyscale : getGrayscaleValue());
21
+ if (matchProductScene && matchMid && matchGreyscale) {
22
+ return item;
23
+ }
24
+ }
25
+ });
26
+ return (upgradeItem === null || upgradeItem === void 0 ? void 0 : upgradeItem.appVersion) || null;
27
+ }
28
+ export var getGrascaleId = function getGrascaleId() {
29
+ var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'AntomDefaultGrascaleId';
30
+ try {
31
+ if (key && window) {
32
+ var storageValue = getStorageString(key, '');
33
+ if (storageValue) {
34
+ return storageValue;
35
+ }
36
+ var grascaleId = uuid();
37
+ if (key && grascaleId) {
38
+ setStorageString(key, grascaleId);
39
+ }
40
+ }
41
+ } catch (error) {
42
+ return '';
43
+ }
44
+ };
45
+ export function getGrayscaleValue() {
46
+ var seed = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGrascaleId();
47
+ if (!seed) {
48
+ return 0;
49
+ }
50
+ // 取倒数2、3位
51
+ var sub = seed.substring(seed.length - 3, seed.length - 1);
52
+ // 将16进制转成10进制值
53
+ var decimal = parseInt(sub, 16);
54
+ var finalValue = Math.floor(decimal * 100 / 255);
55
+ return finalValue;
56
+ }
57
+ export function isGreyscaleMatch(item, randomGreyscale) {
58
+ if (!(item !== null && item !== void 0 && item.greyscale)) {
59
+ return true;
60
+ }
61
+ try {
62
+ var greyscale = parseInt(item === null || item === void 0 ? void 0 : item.greyscale);
63
+ if (greyscale === 0) {
64
+ return false;
65
+ }
66
+ return greyscale >= randomGreyscale;
67
+ } catch (error) {
68
+ return false;
69
+ }
70
+ }
71
+
72
+ /**
73
+ * 查询匹配到的版本
74
+ * @param _extendInfo
75
+ * @param param1
76
+ * @returns
77
+ */
78
+ export var getMatchAppVersion = function getMatchAppVersion(_extendInfo, sdkInfo) {
79
+ try {
80
+ var _info$sdkUpgradeInfo;
81
+ var info = JSON.parse(_extendInfo);
82
+ var versions = info === null || info === void 0 || (_info$sdkUpgradeInfo = info.sdkUpgradeInfo) === null || _info$sdkUpgradeInfo === void 0 ? void 0 : _info$sdkUpgradeInfo.versions;
83
+ var appVersion = findUpgradeVersion(versions, sdkInfo);
84
+ return appVersion;
85
+ } catch (error) {
86
+ return '';
87
+ }
88
+ };
89
+
90
+ /**
91
+ * 获取保存的加载版本
92
+ * @param productScene
93
+ * @returns
94
+ */
95
+ export var getLastAppVersion = function getLastAppVersion(productScene) {
96
+ try {
97
+ var key = "Antom_".concat(productScene, "_LastAppVersion");
98
+ return getStorageString(key, '');
99
+ } catch (error) {
100
+ return '';
101
+ }
102
+ };
103
+ /**
104
+ * 保存指定场景的加载版本供下次使用
105
+ * @param productScene
106
+ * @returns
107
+ */
108
+ export var setLastAppVersion = function setLastAppVersion(productScene, appVersion) {
109
+ try {
110
+ var key = "Antom_".concat(productScene, "_LastAppVersion");
111
+ return setStorageString(key, appVersion);
112
+ } catch (error) {
113
+ return false;
114
+ }
115
+ };
@@ -3,6 +3,13 @@
3
3
  * @param v1
4
4
  * @param v2
5
5
  */
6
- export declare function compareVersion(v1: string, v2: string): 1 | 0 | -1;
6
+ export declare function compareVersion(v1: string, v2: string): 0 | 1 | -1;
7
+ /**
8
+ * 判断version版本是否在range参数版本的范围内
9
+ * @param version
10
+ * @param range
11
+ * @returns
12
+ */
13
+ export declare function isVersionInStringRange(version: string, range: string): boolean;
7
14
  export declare function isVersionInRange(currentVersion: any, minVersion: any, maxVersion: any): boolean;
8
15
  export declare function matchVersion(config: any, currentVersion: any): boolean;
@@ -49,6 +49,28 @@ export function compareVersion(v1, v2) {
49
49
  return 1;
50
50
  }
51
51
  }
52
+ /**
53
+ * 判断version版本是否在range参数版本的范围内
54
+ * @param version
55
+ * @param range
56
+ * @returns
57
+ */
58
+ export function isVersionInStringRange(version, range) {
59
+ if (!range) {
60
+ // 未指定版本限制
61
+ return true;
62
+ }
63
+ if (range.includes(',')) {
64
+ return range.split(',').includes(version);
65
+ }
66
+ if (!range.includes('|')) {
67
+ return version === range;
68
+ }
69
+ var minVersion = range.split('|')[0];
70
+ var maxVersion = range.split('|')[1] || '999999.9.9';
71
+ var matchVersion = compareVersion(version, minVersion) >= 0 && compareVersion(maxVersion, version) >= 0;
72
+ return matchVersion;
73
+ }
52
74
  export function isVersionInRange(currentVersion, minVersion, maxVersion) {
53
75
  function splitVersion(version) {
54
76
  return version.split('.').map(function (num) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alipay/ams-checkout",
3
- "version": "1.11.1",
3
+ "version": "1.13.0",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "main": "esm/index.js",