@suprsend/web-sdk 1.3.3 → 1.5.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.
- package/dist/cdn_bundle.js +1 -1
- package/dist/cdn_bundle.js.LICENSE.txt +10 -0
- package/dist/cjs_bundle.js +1 -1
- package/dist/cjs_bundle.js.LICENSE.txt +10 -0
- package/package.json +2 -1
- package/src/encryption.js +2 -231
- package/src/index.d.ts +8 -2
- package/src/preferences.js +30 -6
package/src/encryption.js
CHANGED
|
@@ -1,235 +1,6 @@
|
|
|
1
1
|
import config from "./config";
|
|
2
2
|
import { constants } from "./constants";
|
|
3
|
-
|
|
4
|
-
var MD5 = function (string) {
|
|
5
|
-
function RotateLeft(lValue, iShiftBits) {
|
|
6
|
-
return (lValue << iShiftBits) | (lValue >>> (32 - iShiftBits));
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function AddUnsigned(lX, lY) {
|
|
10
|
-
var lX4, lY4, lX8, lY8, lResult;
|
|
11
|
-
lX8 = lX & 0x80000000;
|
|
12
|
-
lY8 = lY & 0x80000000;
|
|
13
|
-
lX4 = lX & 0x40000000;
|
|
14
|
-
lY4 = lY & 0x40000000;
|
|
15
|
-
lResult = (lX & 0x3fffffff) + (lY & 0x3fffffff);
|
|
16
|
-
if (lX4 & lY4) {
|
|
17
|
-
return lResult ^ 0x80000000 ^ lX8 ^ lY8;
|
|
18
|
-
}
|
|
19
|
-
if (lX4 | lY4) {
|
|
20
|
-
if (lResult & 0x40000000) {
|
|
21
|
-
return lResult ^ 0xc0000000 ^ lX8 ^ lY8;
|
|
22
|
-
} else {
|
|
23
|
-
return lResult ^ 0x40000000 ^ lX8 ^ lY8;
|
|
24
|
-
}
|
|
25
|
-
} else {
|
|
26
|
-
return lResult ^ lX8 ^ lY8;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function F(x, y, z) {
|
|
31
|
-
return (x & y) | (~x & z);
|
|
32
|
-
}
|
|
33
|
-
function G(x, y, z) {
|
|
34
|
-
return (x & z) | (y & ~z);
|
|
35
|
-
}
|
|
36
|
-
function H(x, y, z) {
|
|
37
|
-
return x ^ y ^ z;
|
|
38
|
-
}
|
|
39
|
-
function I(x, y, z) {
|
|
40
|
-
return y ^ (x | ~z);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function FF(a, b, c, d, x, s, ac) {
|
|
44
|
-
a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac));
|
|
45
|
-
return AddUnsigned(RotateLeft(a, s), b);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function GG(a, b, c, d, x, s, ac) {
|
|
49
|
-
a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac));
|
|
50
|
-
return AddUnsigned(RotateLeft(a, s), b);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function HH(a, b, c, d, x, s, ac) {
|
|
54
|
-
a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac));
|
|
55
|
-
return AddUnsigned(RotateLeft(a, s), b);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function II(a, b, c, d, x, s, ac) {
|
|
59
|
-
a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac));
|
|
60
|
-
return AddUnsigned(RotateLeft(a, s), b);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function ConvertToWordArray(string) {
|
|
64
|
-
var lWordCount;
|
|
65
|
-
var lMessageLength = string.length;
|
|
66
|
-
var lNumberOfWords_temp1 = lMessageLength + 8;
|
|
67
|
-
var lNumberOfWords_temp2 =
|
|
68
|
-
(lNumberOfWords_temp1 - (lNumberOfWords_temp1 % 64)) / 64;
|
|
69
|
-
var lNumberOfWords = (lNumberOfWords_temp2 + 1) * 16;
|
|
70
|
-
var lWordArray = Array(lNumberOfWords - 1);
|
|
71
|
-
var lBytePosition = 0;
|
|
72
|
-
var lByteCount = 0;
|
|
73
|
-
while (lByteCount < lMessageLength) {
|
|
74
|
-
lWordCount = (lByteCount - (lByteCount % 4)) / 4;
|
|
75
|
-
lBytePosition = (lByteCount % 4) * 8;
|
|
76
|
-
lWordArray[lWordCount] =
|
|
77
|
-
lWordArray[lWordCount] |
|
|
78
|
-
(string.charCodeAt(lByteCount) << lBytePosition);
|
|
79
|
-
lByteCount++;
|
|
80
|
-
}
|
|
81
|
-
lWordCount = (lByteCount - (lByteCount % 4)) / 4;
|
|
82
|
-
lBytePosition = (lByteCount % 4) * 8;
|
|
83
|
-
lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80 << lBytePosition);
|
|
84
|
-
lWordArray[lNumberOfWords - 2] = lMessageLength << 3;
|
|
85
|
-
lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29;
|
|
86
|
-
return lWordArray;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function WordToHex(lValue) {
|
|
90
|
-
var WordToHexValue = "",
|
|
91
|
-
WordToHexValue_temp = "",
|
|
92
|
-
lByte,
|
|
93
|
-
lCount;
|
|
94
|
-
for (lCount = 0; lCount <= 3; lCount++) {
|
|
95
|
-
lByte = (lValue >>> (lCount * 8)) & 255;
|
|
96
|
-
WordToHexValue_temp = "0" + lByte.toString(16);
|
|
97
|
-
WordToHexValue =
|
|
98
|
-
WordToHexValue +
|
|
99
|
-
WordToHexValue_temp.substr(WordToHexValue_temp.length - 2, 2);
|
|
100
|
-
}
|
|
101
|
-
return WordToHexValue;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function Utf8Encode(string) {
|
|
105
|
-
string = string.replace(/\r\n/g, "\n");
|
|
106
|
-
var utftext = "";
|
|
107
|
-
|
|
108
|
-
for (var n = 0; n < string.length; n++) {
|
|
109
|
-
var c = string.charCodeAt(n);
|
|
110
|
-
|
|
111
|
-
if (c < 128) {
|
|
112
|
-
utftext += String.fromCharCode(c);
|
|
113
|
-
} else if (c > 127 && c < 2048) {
|
|
114
|
-
utftext += String.fromCharCode((c >> 6) | 192);
|
|
115
|
-
utftext += String.fromCharCode((c & 63) | 128);
|
|
116
|
-
} else {
|
|
117
|
-
utftext += String.fromCharCode((c >> 12) | 224);
|
|
118
|
-
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
|
|
119
|
-
utftext += String.fromCharCode((c & 63) | 128);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return utftext;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
var x = Array();
|
|
127
|
-
var k, AA, BB, CC, DD, a, b, c, d;
|
|
128
|
-
var S11 = 7,
|
|
129
|
-
S12 = 12,
|
|
130
|
-
S13 = 17,
|
|
131
|
-
S14 = 22;
|
|
132
|
-
var S21 = 5,
|
|
133
|
-
S22 = 9,
|
|
134
|
-
S23 = 14,
|
|
135
|
-
S24 = 20;
|
|
136
|
-
var S31 = 4,
|
|
137
|
-
S32 = 11,
|
|
138
|
-
S33 = 16,
|
|
139
|
-
S34 = 23;
|
|
140
|
-
var S41 = 6,
|
|
141
|
-
S42 = 10,
|
|
142
|
-
S43 = 15,
|
|
143
|
-
S44 = 21;
|
|
144
|
-
|
|
145
|
-
string = Utf8Encode(string);
|
|
146
|
-
|
|
147
|
-
x = ConvertToWordArray(string);
|
|
148
|
-
|
|
149
|
-
a = 0x67452301;
|
|
150
|
-
b = 0xefcdab89;
|
|
151
|
-
c = 0x98badcfe;
|
|
152
|
-
d = 0x10325476;
|
|
153
|
-
|
|
154
|
-
for (k = 0; k < x.length; k += 16) {
|
|
155
|
-
AA = a;
|
|
156
|
-
BB = b;
|
|
157
|
-
CC = c;
|
|
158
|
-
DD = d;
|
|
159
|
-
a = FF(a, b, c, d, x[k + 0], S11, 0xd76aa478);
|
|
160
|
-
d = FF(d, a, b, c, x[k + 1], S12, 0xe8c7b756);
|
|
161
|
-
c = FF(c, d, a, b, x[k + 2], S13, 0x242070db);
|
|
162
|
-
b = FF(b, c, d, a, x[k + 3], S14, 0xc1bdceee);
|
|
163
|
-
a = FF(a, b, c, d, x[k + 4], S11, 0xf57c0faf);
|
|
164
|
-
d = FF(d, a, b, c, x[k + 5], S12, 0x4787c62a);
|
|
165
|
-
c = FF(c, d, a, b, x[k + 6], S13, 0xa8304613);
|
|
166
|
-
b = FF(b, c, d, a, x[k + 7], S14, 0xfd469501);
|
|
167
|
-
a = FF(a, b, c, d, x[k + 8], S11, 0x698098d8);
|
|
168
|
-
d = FF(d, a, b, c, x[k + 9], S12, 0x8b44f7af);
|
|
169
|
-
c = FF(c, d, a, b, x[k + 10], S13, 0xffff5bb1);
|
|
170
|
-
b = FF(b, c, d, a, x[k + 11], S14, 0x895cd7be);
|
|
171
|
-
a = FF(a, b, c, d, x[k + 12], S11, 0x6b901122);
|
|
172
|
-
d = FF(d, a, b, c, x[k + 13], S12, 0xfd987193);
|
|
173
|
-
c = FF(c, d, a, b, x[k + 14], S13, 0xa679438e);
|
|
174
|
-
b = FF(b, c, d, a, x[k + 15], S14, 0x49b40821);
|
|
175
|
-
a = GG(a, b, c, d, x[k + 1], S21, 0xf61e2562);
|
|
176
|
-
d = GG(d, a, b, c, x[k + 6], S22, 0xc040b340);
|
|
177
|
-
c = GG(c, d, a, b, x[k + 11], S23, 0x265e5a51);
|
|
178
|
-
b = GG(b, c, d, a, x[k + 0], S24, 0xe9b6c7aa);
|
|
179
|
-
a = GG(a, b, c, d, x[k + 5], S21, 0xd62f105d);
|
|
180
|
-
d = GG(d, a, b, c, x[k + 10], S22, 0x2441453);
|
|
181
|
-
c = GG(c, d, a, b, x[k + 15], S23, 0xd8a1e681);
|
|
182
|
-
b = GG(b, c, d, a, x[k + 4], S24, 0xe7d3fbc8);
|
|
183
|
-
a = GG(a, b, c, d, x[k + 9], S21, 0x21e1cde6);
|
|
184
|
-
d = GG(d, a, b, c, x[k + 14], S22, 0xc33707d6);
|
|
185
|
-
c = GG(c, d, a, b, x[k + 3], S23, 0xf4d50d87);
|
|
186
|
-
b = GG(b, c, d, a, x[k + 8], S24, 0x455a14ed);
|
|
187
|
-
a = GG(a, b, c, d, x[k + 13], S21, 0xa9e3e905);
|
|
188
|
-
d = GG(d, a, b, c, x[k + 2], S22, 0xfcefa3f8);
|
|
189
|
-
c = GG(c, d, a, b, x[k + 7], S23, 0x676f02d9);
|
|
190
|
-
b = GG(b, c, d, a, x[k + 12], S24, 0x8d2a4c8a);
|
|
191
|
-
a = HH(a, b, c, d, x[k + 5], S31, 0xfffa3942);
|
|
192
|
-
d = HH(d, a, b, c, x[k + 8], S32, 0x8771f681);
|
|
193
|
-
c = HH(c, d, a, b, x[k + 11], S33, 0x6d9d6122);
|
|
194
|
-
b = HH(b, c, d, a, x[k + 14], S34, 0xfde5380c);
|
|
195
|
-
a = HH(a, b, c, d, x[k + 1], S31, 0xa4beea44);
|
|
196
|
-
d = HH(d, a, b, c, x[k + 4], S32, 0x4bdecfa9);
|
|
197
|
-
c = HH(c, d, a, b, x[k + 7], S33, 0xf6bb4b60);
|
|
198
|
-
b = HH(b, c, d, a, x[k + 10], S34, 0xbebfbc70);
|
|
199
|
-
a = HH(a, b, c, d, x[k + 13], S31, 0x289b7ec6);
|
|
200
|
-
d = HH(d, a, b, c, x[k + 0], S32, 0xeaa127fa);
|
|
201
|
-
c = HH(c, d, a, b, x[k + 3], S33, 0xd4ef3085);
|
|
202
|
-
b = HH(b, c, d, a, x[k + 6], S34, 0x4881d05);
|
|
203
|
-
a = HH(a, b, c, d, x[k + 9], S31, 0xd9d4d039);
|
|
204
|
-
d = HH(d, a, b, c, x[k + 12], S32, 0xe6db99e5);
|
|
205
|
-
c = HH(c, d, a, b, x[k + 15], S33, 0x1fa27cf8);
|
|
206
|
-
b = HH(b, c, d, a, x[k + 2], S34, 0xc4ac5665);
|
|
207
|
-
a = II(a, b, c, d, x[k + 0], S41, 0xf4292244);
|
|
208
|
-
d = II(d, a, b, c, x[k + 7], S42, 0x432aff97);
|
|
209
|
-
c = II(c, d, a, b, x[k + 14], S43, 0xab9423a7);
|
|
210
|
-
b = II(b, c, d, a, x[k + 5], S44, 0xfc93a039);
|
|
211
|
-
a = II(a, b, c, d, x[k + 12], S41, 0x655b59c3);
|
|
212
|
-
d = II(d, a, b, c, x[k + 3], S42, 0x8f0ccc92);
|
|
213
|
-
c = II(c, d, a, b, x[k + 10], S43, 0xffeff47d);
|
|
214
|
-
b = II(b, c, d, a, x[k + 1], S44, 0x85845dd1);
|
|
215
|
-
a = II(a, b, c, d, x[k + 8], S41, 0x6fa87e4f);
|
|
216
|
-
d = II(d, a, b, c, x[k + 15], S42, 0xfe2ce6e0);
|
|
217
|
-
c = II(c, d, a, b, x[k + 6], S43, 0xa3014314);
|
|
218
|
-
b = II(b, c, d, a, x[k + 13], S44, 0x4e0811a1);
|
|
219
|
-
a = II(a, b, c, d, x[k + 4], S41, 0xf7537e82);
|
|
220
|
-
d = II(d, a, b, c, x[k + 11], S42, 0xbd3af235);
|
|
221
|
-
c = II(c, d, a, b, x[k + 2], S43, 0x2ad7d2bb);
|
|
222
|
-
b = II(b, c, d, a, x[k + 9], S44, 0xeb86d391);
|
|
223
|
-
a = AddUnsigned(a, AA);
|
|
224
|
-
b = AddUnsigned(b, BB);
|
|
225
|
-
c = AddUnsigned(c, CC);
|
|
226
|
-
d = AddUnsigned(d, DD);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
var temp = WordToHex(a) + WordToHex(b) + WordToHex(c) + WordToHex(d);
|
|
230
|
-
|
|
231
|
-
return temp.toLowerCase();
|
|
232
|
-
};
|
|
3
|
+
import { md5 } from "js-md5";
|
|
233
4
|
|
|
234
5
|
const getUtf8Bytes = (str) =>
|
|
235
6
|
new Uint8Array(
|
|
@@ -249,7 +20,7 @@ export default async function create_signature(
|
|
|
249
20
|
const content_type = "application/json";
|
|
250
21
|
let md5_str = "";
|
|
251
22
|
if (str) {
|
|
252
|
-
md5_str =
|
|
23
|
+
md5_str = md5(str);
|
|
253
24
|
}
|
|
254
25
|
const message = `${method}\n${md5_str}\n${content_type}\n${date}\n${route}`;
|
|
255
26
|
const keyBytes = getUtf8Bytes(key);
|
package/src/index.d.ts
CHANGED
|
@@ -72,17 +72,21 @@ interface GetOverAllChannelPreferencesResponse extends PreferenceErrorData {
|
|
|
72
72
|
interface Preferences {
|
|
73
73
|
data: PreferenceData;
|
|
74
74
|
|
|
75
|
-
get_preferences(args?: {
|
|
75
|
+
get_preferences(args?: {
|
|
76
|
+
tenant_id?: string;
|
|
77
|
+
show_opt_out_channels?: boolean;
|
|
78
|
+
}): Promise<PreferencesResponse>;
|
|
76
79
|
|
|
77
80
|
get_categories(args?: {
|
|
78
81
|
tenant_id?: string;
|
|
79
82
|
limit?: number;
|
|
80
83
|
offset?: number;
|
|
84
|
+
show_opt_out_channels?: boolean;
|
|
81
85
|
}): Promise<GetCategoriesResponse>;
|
|
82
86
|
|
|
83
87
|
get_category(
|
|
84
88
|
category: string,
|
|
85
|
-
args?: { tenant_id?: string }
|
|
89
|
+
args?: { tenant_id?: string; show_opt_out_channels?: boolean }
|
|
86
90
|
): Promise<Category>;
|
|
87
91
|
|
|
88
92
|
get_overall_channel_preferences(): Promise<GetOverAllChannelPreferencesResponse>;
|
|
@@ -92,6 +96,7 @@ interface Preferences {
|
|
|
92
96
|
preference: PreferenceOptions,
|
|
93
97
|
args?: {
|
|
94
98
|
tenant_id?: string;
|
|
99
|
+
show_opt_out_channels?: boolean;
|
|
95
100
|
}
|
|
96
101
|
): PreferencesResponse;
|
|
97
102
|
|
|
@@ -101,6 +106,7 @@ interface Preferences {
|
|
|
101
106
|
category: string,
|
|
102
107
|
args?: {
|
|
103
108
|
tenant_id?: string;
|
|
109
|
+
show_opt_out_channels?: boolean;
|
|
104
110
|
}
|
|
105
111
|
): PreferencesResponse;
|
|
106
112
|
|
package/src/preferences.js
CHANGED
|
@@ -182,7 +182,10 @@ class Preferences {
|
|
|
182
182
|
async get_preferences(args = {}) {
|
|
183
183
|
let url_path = "full_preference";
|
|
184
184
|
this._preference_args = args;
|
|
185
|
-
let query_params = {
|
|
185
|
+
let query_params = {
|
|
186
|
+
tenant_id: args?.tenant_id,
|
|
187
|
+
show_opt_out_channels: args?.show_opt_out_channels,
|
|
188
|
+
};
|
|
186
189
|
|
|
187
190
|
const response = await this._get_request(url_path, query_params);
|
|
188
191
|
if (!response?.error) {
|
|
@@ -195,6 +198,7 @@ class Preferences {
|
|
|
195
198
|
let url_path = "category";
|
|
196
199
|
const query_params = {
|
|
197
200
|
tenant_id: args?.tenant_id,
|
|
201
|
+
show_opt_out_channels: args?.show_opt_out_channels,
|
|
198
202
|
limit: args?.limit,
|
|
199
203
|
offset: args?.offset,
|
|
200
204
|
};
|
|
@@ -212,7 +216,10 @@ class Preferences {
|
|
|
212
216
|
}
|
|
213
217
|
|
|
214
218
|
let url_path = `category/${category}`;
|
|
215
|
-
let query_params = {
|
|
219
|
+
let query_params = {
|
|
220
|
+
tenant_id: args?.tenant_id,
|
|
221
|
+
show_opt_out_channels: args?.show_opt_out_channels,
|
|
222
|
+
};
|
|
216
223
|
|
|
217
224
|
const response = await this._get_request(url_path, query_params);
|
|
218
225
|
return response;
|
|
@@ -248,6 +255,7 @@ class Preferences {
|
|
|
248
255
|
|
|
249
256
|
let category_data;
|
|
250
257
|
let data_updated = false;
|
|
258
|
+
let show_opt_out_channels = args?.show_opt_out_channels;
|
|
251
259
|
|
|
252
260
|
// optimistic update in local store
|
|
253
261
|
for (let section of this.data.sections) {
|
|
@@ -295,7 +303,10 @@ class Preferences {
|
|
|
295
303
|
|
|
296
304
|
const request_payload = {
|
|
297
305
|
preference: category_data.preference,
|
|
298
|
-
opt_out_channels
|
|
306
|
+
opt_out_channels:
|
|
307
|
+
show_opt_out_channels && preference === PreferenceOptions.OPT_IN
|
|
308
|
+
? null
|
|
309
|
+
: opt_out_channels,
|
|
299
310
|
};
|
|
300
311
|
|
|
301
312
|
this._debounced_update_category_preferences(
|
|
@@ -303,7 +314,10 @@ class Preferences {
|
|
|
303
314
|
category,
|
|
304
315
|
request_payload,
|
|
305
316
|
category_data,
|
|
306
|
-
{
|
|
317
|
+
{
|
|
318
|
+
tenant_id: args?.tenant_id,
|
|
319
|
+
show_opt_out_channels: args?.show_opt_out_channels,
|
|
320
|
+
}
|
|
307
321
|
);
|
|
308
322
|
|
|
309
323
|
return this.data;
|
|
@@ -404,8 +418,15 @@ class Preferences {
|
|
|
404
418
|
}
|
|
405
419
|
});
|
|
406
420
|
|
|
421
|
+
const category_preference =
|
|
422
|
+
args?.show_opt_out_channels &&
|
|
423
|
+
category_data.preference === PreferenceOptions.OPT_OUT &&
|
|
424
|
+
preference === PreferenceOptions.OPT_IN
|
|
425
|
+
? PreferenceOptions.OPT_IN
|
|
426
|
+
: category_data.preference;
|
|
427
|
+
|
|
407
428
|
const request_payload = {
|
|
408
|
-
preference:
|
|
429
|
+
preference: category_preference,
|
|
409
430
|
opt_out_channels,
|
|
410
431
|
};
|
|
411
432
|
|
|
@@ -414,7 +435,10 @@ class Preferences {
|
|
|
414
435
|
category,
|
|
415
436
|
request_payload,
|
|
416
437
|
category_data,
|
|
417
|
-
{
|
|
438
|
+
{
|
|
439
|
+
tenant_id: args?.tenant_id,
|
|
440
|
+
show_opt_out_channels: args?.show_opt_out_channels,
|
|
441
|
+
}
|
|
418
442
|
);
|
|
419
443
|
|
|
420
444
|
return this.data;
|