Skip to content

Commit 5ccf4d8

Browse files
author
shengyonggen
committed
Release 1.14.9
1 parent f5c4845 commit 5ccf4d8

14 files changed

+322
-31
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 1.14.9(2021-04-22)
2+
1. 新增
3+
- 新增本地 `storage` 加密
14
## 1.14.8(2021-04-20)
25
1. 修复
36
- 修复页面参数含有 `scene``$url_query` 为空问题;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sa-sdk-miniprogram",
3-
"version": "1.14.8",
3+
"version": "1.14.9",
44
"description": "sensorsdata miniprogram sdk",
55
"main": "sensorsdata.min.js",
66
"scripts": {

product/sensorsdata.custom.es6.full.js

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ logger.info = function() {
7272
};
7373

7474
sa.setPara = function(para) {
75-
7675
sa.para = _.extend2Lev(sa.para, para);
77-
7876
var channel = [];
7977
if (_.isArray(sa.para.source_channel)) {
8078
var len = sa.para.source_channel.length;
@@ -145,7 +143,7 @@ var ArrayProto = Array.prototype,
145143
slice = ArrayProto.slice,
146144
toString = ObjProto.toString,
147145
hasOwnProperty = ObjProto.hasOwnProperty,
148-
LIB_VERSION = '1.14.8',
146+
LIB_VERSION = '1.14.9',
149147
LIB_NAME = 'MiniProgram';
150148

151149
var source_channel_standard = 'utm_source utm_medium utm_campaign utm_content utm_term';
@@ -577,6 +575,31 @@ _.base64Encode = function(data) {
577575
return enc;
578576
};
579577

578+
_.rot13obfs = function(str, key) {
579+
str = String(str);
580+
key = typeof key === 'number' ? key : 13;
581+
var n = 126;
582+
583+
var chars = str.split('');
584+
585+
for (var i = 0, len = chars.length; i < len; i++) {
586+
var c = chars[i].charCodeAt(0);
587+
588+
if (c < n) {
589+
chars[i] = String.fromCharCode((chars[i].charCodeAt(0) + key) % n);
590+
}
591+
}
592+
593+
return chars.join('');
594+
};
595+
596+
_.rot13defs = function(str) {
597+
var key = 13,
598+
n = 126,
599+
str = String(str);
600+
return _.rot13obfs(str, n - key);
601+
};
602+
580603
_.getCurrentPath = function() {
581604
var url = '未取到';
582605
try {
@@ -1284,15 +1307,38 @@ sa.store = {
12841307
change: function(name, value) {
12851308
this._state['_' + name] = value;
12861309
},
1310+
encryptStorage: function() {
1311+
let copyState = this.getStorage();
1312+
const flag = 'data:enc;';
1313+
if (_.isObject(copyState)) {
1314+
copyState = flag + _.rot13obfs(JSON.stringify(copyState));
1315+
} else if (_.isString(copyState)) {
1316+
if (copyState.indexOf(flag) === -1) {
1317+
copyState = flag + _.rot13obfs(copyState);
1318+
}
1319+
}
1320+
sa._.setStorageSync("sensorsdata2015_wechat", copyState);
1321+
},
12871322
save: function() {
12881323
var copyState = JSON.parse(JSON.stringify(this._state));
12891324
delete copyState._first_id;
12901325
delete copyState._distinct_id;
1326+
if (sa.para.encrypt_storage) {
1327+
const flag = 'data:enc;';
1328+
copyState = flag + _.rot13obfs(JSON.stringify(copyState));
1329+
}
12911330
sa._.setStorageSync("sensorsdata2015_wechat", copyState);
12921331
},
12931332
init: function() {
12941333
var info = this.getStorage();
1334+
const flag = 'data:enc;';
12951335
if (info) {
1336+
if (_.isString(info)) {
1337+
if (info.indexOf(flag) !== -1) {
1338+
info = info.substring(flag.length);
1339+
info = JSON.parse(_.rot13defs(info));
1340+
}
1341+
}
12961342
this.toState(info);
12971343
} else {
12981344
is_first_launch = true;
@@ -1585,6 +1631,9 @@ sa.init = function(obj) {
15851631
}
15861632
this.hasInit = true;
15871633
sa.setPara(obj);
1634+
if (sa.para.encrypt_storage) {
1635+
this.store.encryptStorage();
1636+
}
15881637
if (sa.para.batch_send) {
15891638
wx.getStorage({
15901639
key: 'sensors_mp_prepare_data',
@@ -1920,7 +1969,6 @@ sa.autoTrackCustom = {
19201969
}
19211970
_.setShareInfo(para, prop);
19221971
var utms = _.setUtm(para, prop);
1923-
19241972
if (is_first_launch) {
19251973
prop.$is_first_time = true;
19261974
if (!_.isEmptyObject(utms.pre1)) {

product/sensorsdata.custom.full.js

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ logger.info = function() {
7272
};
7373

7474
sa.setPara = function(para) {
75-
7675
sa.para = _.extend2Lev(sa.para, para);
77-
7876
var channel = [];
7977
if (_.isArray(sa.para.source_channel)) {
8078
var len = sa.para.source_channel.length;
@@ -145,7 +143,7 @@ var ArrayProto = Array.prototype,
145143
slice = ArrayProto.slice,
146144
toString = ObjProto.toString,
147145
hasOwnProperty = ObjProto.hasOwnProperty,
148-
LIB_VERSION = '1.14.8',
146+
LIB_VERSION = '1.14.9',
149147
LIB_NAME = 'MiniProgram';
150148

151149
var source_channel_standard = 'utm_source utm_medium utm_campaign utm_content utm_term';
@@ -577,6 +575,31 @@ _.base64Encode = function(data) {
577575
return enc;
578576
};
579577

578+
_.rot13obfs = function(str, key) {
579+
str = String(str);
580+
key = typeof key === 'number' ? key : 13;
581+
var n = 126;
582+
583+
var chars = str.split('');
584+
585+
for (var i = 0, len = chars.length; i < len; i++) {
586+
var c = chars[i].charCodeAt(0);
587+
588+
if (c < n) {
589+
chars[i] = String.fromCharCode((chars[i].charCodeAt(0) + key) % n);
590+
}
591+
}
592+
593+
return chars.join('');
594+
};
595+
596+
_.rot13defs = function(str) {
597+
var key = 13,
598+
n = 126,
599+
str = String(str);
600+
return _.rot13obfs(str, n - key);
601+
};
602+
580603
_.getCurrentPath = function() {
581604
var url = '未取到';
582605
try {
@@ -1284,15 +1307,38 @@ sa.store = {
12841307
change: function(name, value) {
12851308
this._state['_' + name] = value;
12861309
},
1310+
encryptStorage: function() {
1311+
let copyState = this.getStorage();
1312+
const flag = 'data:enc;';
1313+
if (_.isObject(copyState)) {
1314+
copyState = flag + _.rot13obfs(JSON.stringify(copyState));
1315+
} else if (_.isString(copyState)) {
1316+
if (copyState.indexOf(flag) === -1) {
1317+
copyState = flag + _.rot13obfs(copyState);
1318+
}
1319+
}
1320+
sa._.setStorageSync("sensorsdata2015_wechat", copyState);
1321+
},
12871322
save: function() {
12881323
var copyState = JSON.parse(JSON.stringify(this._state));
12891324
delete copyState._first_id;
12901325
delete copyState._distinct_id;
1326+
if (sa.para.encrypt_storage) {
1327+
const flag = 'data:enc;';
1328+
copyState = flag + _.rot13obfs(JSON.stringify(copyState));
1329+
}
12911330
sa._.setStorageSync("sensorsdata2015_wechat", copyState);
12921331
},
12931332
init: function() {
12941333
var info = this.getStorage();
1334+
const flag = 'data:enc;';
12951335
if (info) {
1336+
if (_.isString(info)) {
1337+
if (info.indexOf(flag) !== -1) {
1338+
info = info.substring(flag.length);
1339+
info = JSON.parse(_.rot13defs(info));
1340+
}
1341+
}
12961342
this.toState(info);
12971343
} else {
12981344
is_first_launch = true;
@@ -1585,6 +1631,9 @@ sa.init = function(obj) {
15851631
}
15861632
this.hasInit = true;
15871633
sa.setPara(obj);
1634+
if (sa.para.encrypt_storage) {
1635+
this.store.encryptStorage();
1636+
}
15881637
if (sa.para.batch_send) {
15891638
wx.getStorage({
15901639
key: 'sensors_mp_prepare_data',
@@ -1920,7 +1969,6 @@ sa.autoTrackCustom = {
19201969
}
19211970
_.setShareInfo(para, prop);
19221971
var utms = _.setUtm(para, prop);
1923-
19241972
if (is_first_launch) {
19251973
prop.$is_first_time = true;
19261974
if (!_.isEmptyObject(utms.pre1)) {

product/sensorsdata.es6.full.js

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ logger.info = function() {
7272
};
7373

7474
sa.setPara = function(para) {
75-
7675
sa.para = _.extend2Lev(sa.para, para);
77-
7876
var channel = [];
7977
if (_.isArray(sa.para.source_channel)) {
8078
var len = sa.para.source_channel.length;
@@ -145,7 +143,7 @@ var ArrayProto = Array.prototype,
145143
slice = ArrayProto.slice,
146144
toString = ObjProto.toString,
147145
hasOwnProperty = ObjProto.hasOwnProperty,
148-
LIB_VERSION = '1.14.8',
146+
LIB_VERSION = '1.14.9',
149147
LIB_NAME = 'MiniProgram';
150148

151149
var source_channel_standard = 'utm_source utm_medium utm_campaign utm_content utm_term';
@@ -577,6 +575,31 @@ _.base64Encode = function(data) {
577575
return enc;
578576
};
579577

578+
_.rot13obfs = function(str, key) {
579+
str = String(str);
580+
key = typeof key === 'number' ? key : 13;
581+
var n = 126;
582+
583+
var chars = str.split('');
584+
585+
for (var i = 0, len = chars.length; i < len; i++) {
586+
var c = chars[i].charCodeAt(0);
587+
588+
if (c < n) {
589+
chars[i] = String.fromCharCode((chars[i].charCodeAt(0) + key) % n);
590+
}
591+
}
592+
593+
return chars.join('');
594+
};
595+
596+
_.rot13defs = function(str) {
597+
var key = 13,
598+
n = 126,
599+
str = String(str);
600+
return _.rot13obfs(str, n - key);
601+
};
602+
580603
_.getCurrentPath = function() {
581604
var url = '未取到';
582605
try {
@@ -1284,15 +1307,38 @@ sa.store = {
12841307
change: function(name, value) {
12851308
this._state['_' + name] = value;
12861309
},
1310+
encryptStorage: function() {
1311+
let copyState = this.getStorage();
1312+
const flag = 'data:enc;';
1313+
if (_.isObject(copyState)) {
1314+
copyState = flag + _.rot13obfs(JSON.stringify(copyState));
1315+
} else if (_.isString(copyState)) {
1316+
if (copyState.indexOf(flag) === -1) {
1317+
copyState = flag + _.rot13obfs(copyState);
1318+
}
1319+
}
1320+
sa._.setStorageSync("sensorsdata2015_wechat", copyState);
1321+
},
12871322
save: function() {
12881323
var copyState = JSON.parse(JSON.stringify(this._state));
12891324
delete copyState._first_id;
12901325
delete copyState._distinct_id;
1326+
if (sa.para.encrypt_storage) {
1327+
const flag = 'data:enc;';
1328+
copyState = flag + _.rot13obfs(JSON.stringify(copyState));
1329+
}
12911330
sa._.setStorageSync("sensorsdata2015_wechat", copyState);
12921331
},
12931332
init: function() {
12941333
var info = this.getStorage();
1334+
const flag = 'data:enc;';
12951335
if (info) {
1336+
if (_.isString(info)) {
1337+
if (info.indexOf(flag) !== -1) {
1338+
info = info.substring(flag.length);
1339+
info = JSON.parse(_.rot13defs(info));
1340+
}
1341+
}
12961342
this.toState(info);
12971343
} else {
12981344
is_first_launch = true;
@@ -1585,6 +1631,9 @@ sa.init = function(obj) {
15851631
}
15861632
this.hasInit = true;
15871633
sa.setPara(obj);
1634+
if (sa.para.encrypt_storage) {
1635+
this.store.encryptStorage();
1636+
}
15881637
if (sa.para.batch_send) {
15891638
wx.getStorage({
15901639
key: 'sensors_mp_prepare_data',
@@ -1983,7 +2032,6 @@ sa.autoTrackCustom = {
19832032
}
19842033
_.setShareInfo(para, prop);
19852034
var utms = _.setUtm(para, prop);
1986-
19872035
if (is_first_launch) {
19882036
prop.$is_first_time = true;
19892037
if (!_.isEmptyObject(utms.pre1)) {

0 commit comments

Comments
 (0)