@subiz/widget-v4 4.1.2 → 4.1.4
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/compiled_src/chatbox/ChatButton.js +25 -0
- package/compiled_src/lib.js +18 -3
- package/compiled_src/store/api.js +116 -108
- package/compiled_src/store/api_fake.js +4 -5
- package/compiled_src/store/store.js +50 -35
- package/dist/132.js +6611 -0
- package/dist/178.js +406 -0
- package/dist/185588facf6.132.js +1 -0
- package/dist/185588facf6.178.js +1 -0
- package/dist/185588facf6.213.js +1 -0
- package/dist/185588facf6.335.js +1 -0
- package/dist/185588facf6.362.js +1 -0
- package/dist/185588facf6.441.js +1 -0
- package/dist/185588facf6.605.js +1 -0
- package/dist/185588facf6.678.js +1 -0
- package/dist/185588facf6.782.js +1 -0
- package/dist/185588facf6.app.js +1 -0
- package/dist/185588facf6.index.html +26 -0
- package/dist/185588facf6.library.html +26 -0
- package/dist/185588facf6.library.js +1 -0
- package/dist/185588facf6.preview.html +759 -0
- package/dist/185588facf6.preview.js +1 -0
- package/dist/185588facf6.screenshoot.js +1 -0
- package/dist/185588facf6.webview.js +1 -0
- package/dist/213.js +2774 -0
- package/dist/335.js +372 -0
- package/dist/362.js +107 -0
- package/dist/441.js +2855 -0
- package/dist/605.js +297 -0
- package/dist/678.js +107 -0
- package/dist/782.js +107 -0
- package/dist/HASH +1 -0
- package/dist/assets/img/Facebook.64607ec.png +0 -0
- package/dist/assets/img/Zalo.6845707.png +0 -0
- package/dist/assets/img/award1a.1a58e10.png +0 -0
- package/dist/assets/img/award3a.3b74423.png +0 -0
- package/dist/assets/img/award4a.ed6ccd4.png +0 -0
- package/dist/assets/img/award5.39eb7ae.png +0 -0
- package/dist/assets/img/bubble_default.7d5e4ab.svg +20 -0
- package/dist/assets/img/caret.998eb8f.svg +1 -0
- package/dist/assets/img/convos_empty.2353007.svg +72 -0
- package/dist/assets/img/default.06e6ee0.jpg +0 -0
- package/dist/assets/img/default_avatar.5b74dc1.png +0 -0
- package/dist/assets/img/done_gray.d7e8203.svg +4 -0
- package/dist/assets/img/done_green.b817fd4.svg +4 -0
- package/dist/assets/img/emoji/messenger/sub_23.529_58.824.d5faf14.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_23.529_60.784.1420241.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_25.490_0.000.1e6b2c0.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_25.490_45.098.3dfbc08.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_25.490_5.882.4b49e94.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_27.451_72.549.7114f58.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_27.451_84.314.231e2b7.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_27.451_96.078.ddbb008.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_29.412_5.882.61f3359.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_58.824_100.000.6df72bc.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_58.824_45.098.3d7a7ad.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_58.824_47.059.0f4d6e2.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_58.824_54.902.65724c1.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_58.824_64.706.9da3cba.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_58.824_72.549.edca5cf.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_58.824_78.431.f910f2a.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_58.824_88.235.def4e71.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_60.784_11.765.49c03d0.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_60.784_27.451.46b54e5.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_60.784_29.412.e36d284.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_60.784_3.922.bb191b0.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_60.784_35.294.af7b927.png +0 -0
- package/dist/assets/img/emoji/messenger/sub_60.784_7.843.98f2a99.png +0 -0
- package/dist/assets/img/empty.29bed2d.svg +23 -0
- package/dist/assets/img/empty_1.0b98af0.svg +11 -0
- package/dist/assets/img/examplte_logo.f86535f.svg +1 -0
- package/dist/assets/img/external-link.90577cc.svg +1 -0
- package/dist/assets/img/fb_inverse_circle.36c2cfc.png +0 -0
- package/dist/assets/img/ghn.070f8e3.svg +17 -0
- package/dist/assets/img/ghtk.326eac1.svg +18 -0
- package/dist/assets/img/image_default.be0698b.png +0 -0
- package/dist/assets/img/info.ebce7ea.svg +1 -0
- package/dist/assets/img/loader.37000a7.svg +1 -0
- package/dist/assets/img/loading_static.8f403ae.svg +10 -0
- package/dist/assets/img/main-service1.d536cc2.png +0 -0
- package/dist/assets/img/main-service2.9b99549.png +0 -0
- package/dist/assets/img/not_found_search.2ddb8d1.png +0 -0
- package/dist/assets/img/package.8d37d0f.svg +5 -0
- package/dist/assets/img/package_fade.763c001.svg +1 -0
- package/dist/assets/img/rating--average.1ea492c.svg +12 -0
- package/dist/assets/img/rating--great.e3d712e.svg +16 -0
- package/dist/assets/img/rating--poor.2938a25.svg +12 -0
- package/dist/assets/img/search.f9705ff.svg +1 -0
- package/dist/assets/img/send.6db52a9.svg +3 -0
- package/dist/assets/img/shop.f7dc7d8.svg +1 -0
- package/dist/assets/img/shop_faded.df7845a.svg +1 -0
- package/dist/assets/img/subiz-mono.877e9f5.svg +3 -0
- package/dist/assets/img/x.26fdfa3.svg +5 -0
- package/dist/malicious-app.js +13 -0
- package/dist/screenshoot.html +7 -0
- package/dist/screenshoot.js +5608 -0
- package/inject.js +2 -6
- package/package.json +9 -8
- package/src/chatbox/ChatButton.js +30 -0
- package/src/lib.js +23 -3
- package/src/store/api.js +139 -114
- package/src/store/api_fake.js +1 -2
- package/src/store/store.js +53 -44
- package/webpack.dev.js +1 -0
- package/webpack.prod.js +1 -0
- package/webview.js +43 -0
|
@@ -310,6 +310,7 @@ class ChatButton extends _common.Com {
|
|
|
310
310
|
defmsg = defmsg || 'Sent you a message';
|
|
311
311
|
let message = _index.default.get(ev, 'data.message.text');
|
|
312
312
|
var format = _index.default.get(ev, 'data.message.format');
|
|
313
|
+
if (format === 'delta') return this.renderDeltaMessagePreview(ev, defmsg);
|
|
313
314
|
if (format && format !== 'plaintext') message = defmsg;
|
|
314
315
|
if (!message && _index.default.size(_index.default.get(ev, 'data.message.attachments')) > 0) message = defmsg;
|
|
315
316
|
if (!message) return null;
|
|
@@ -323,6 +324,30 @@ class ChatButton extends _common.Com {
|
|
|
323
324
|
});
|
|
324
325
|
return tags;
|
|
325
326
|
}
|
|
327
|
+
renderDeltaMessagePreview(ev, defmsg) {
|
|
328
|
+
defmsg = defmsg || 'Sent you a message';
|
|
329
|
+
let message = _index.default.get(ev, 'data.message.quill_delta');
|
|
330
|
+
if (!message && _index.default.size(_index.default.get(ev, 'data.message.attachments')) > 0) message = defmsg;
|
|
331
|
+
if (!message) return;
|
|
332
|
+
let quilldeltas = _index.default.parseJSON(message) || {};
|
|
333
|
+
if (!quilldeltas || _index.default.size(quilldeltas.ops) === 0) return null;
|
|
334
|
+
let $deltas = _index.default.map(quilldeltas.ops, delta => {
|
|
335
|
+
let html = '';
|
|
336
|
+
let insert = delta.insert;
|
|
337
|
+
let attributes = delta.attributes;
|
|
338
|
+
if (insert.dynamicField) {
|
|
339
|
+
return _index.default.get(insert, 'dynamicField.text', '');
|
|
340
|
+
}
|
|
341
|
+
if (insert.emoji) return (0, _preact.h)(_Emoji.default, {
|
|
342
|
+
emojiCode: `:${insert.emoji}:`
|
|
343
|
+
});
|
|
344
|
+
if (typeof insert === 'string') {
|
|
345
|
+
return insert;
|
|
346
|
+
}
|
|
347
|
+
return null;
|
|
348
|
+
});
|
|
349
|
+
return $deltas;
|
|
350
|
+
}
|
|
326
351
|
closePreview(e) {
|
|
327
352
|
if (e) {
|
|
328
353
|
e.preventDefault();
|
package/compiled_src/lib.js
CHANGED
|
@@ -51,12 +51,27 @@ class Widget {
|
|
|
51
51
|
this.domGate.open();
|
|
52
52
|
return user;
|
|
53
53
|
}
|
|
54
|
-
logout(
|
|
55
|
-
return this.store.logout();
|
|
54
|
+
logout(userref) {
|
|
55
|
+
return this.store.logout(userref);
|
|
56
|
+
}
|
|
57
|
+
async init(param, $container) {
|
|
58
|
+
param = param || {};
|
|
59
|
+
let accid = param.account_id;
|
|
60
|
+
let ref = param.ref;
|
|
61
|
+
let user = await this.store.init(accid, undefined, ref);
|
|
62
|
+
if (!$container) $container = document.body || document;
|
|
63
|
+
this.pluginMgr = new _plugin.default(this, $container);
|
|
64
|
+
let clean = setInterval(() => {
|
|
65
|
+
if ($container && $container.isConnected) return;
|
|
66
|
+
this.pluginMgr.destroy();
|
|
67
|
+
clearInterval(clean);
|
|
68
|
+
}, 1000);
|
|
69
|
+
this.domGate.open();
|
|
70
|
+
return user;
|
|
56
71
|
}
|
|
57
72
|
async setAccount(id, $container, mask, cb) {
|
|
58
73
|
let outmask = await this.store.init(id, mask);
|
|
59
|
-
if (!$container) $container = document.body;
|
|
74
|
+
if (!$container) $container = document.body || document;
|
|
60
75
|
this.pluginMgr = new _plugin.default(this, $container);
|
|
61
76
|
let clean = setInterval(() => {
|
|
62
77
|
if ($container && $container.isConnected) return;
|
|
@@ -11,7 +11,6 @@ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typ
|
|
|
11
11
|
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
12
12
|
const ajax = require('@subiz/ajax/src/ajax.js');
|
|
13
13
|
ajax.env.XMLHttpRequest = window.XMLHttpRequest;
|
|
14
|
-
const findAnswer = challenge => challenge.answer;
|
|
15
14
|
function jsonifyTextPlain(param, done) {
|
|
16
15
|
let req = param.request;
|
|
17
16
|
if (req.content_type === 'text/plain' && req.body !== undefined) req.body = _index.default.stringify(req.body);
|
|
@@ -19,8 +18,8 @@ function jsonifyTextPlain(param, done) {
|
|
|
19
18
|
}
|
|
20
19
|
class _default {
|
|
21
20
|
constructor(ApiURL, FileURL) {
|
|
22
|
-
_defineProperty(this, "listConversations", _ => this.apireq.addQuery('user_id', this.uid).addQuery('integration_id', `${this.accid}.subizv4.subikon`).get(
|
|
23
|
-
_defineProperty(this, "listMessages", (cid, limit, start_id) => this.apireq.addQuery('limit', limit).addQuery('start_id', start_id).get(`/conversations/${cid}/messages`));
|
|
21
|
+
_defineProperty(this, "listConversations", _ => this.apireq.addQuery('user_id', this.uid).addQuery('integration_id', `${this.accid}.subizv4.subikon`).get(`/accounts/${this.accid}/conversations`));
|
|
22
|
+
_defineProperty(this, "listMessages", (cid, limit, start_id) => this.apireq.addQuery('limit', limit).addQuery('start_id', start_id).get(`/accounts/${this.accid}/conversations/${cid}/messages`));
|
|
24
23
|
_defineProperty(this, "ajax", ajax);
|
|
25
24
|
_defineProperty(this, "start", extraData => {
|
|
26
25
|
let data = {
|
|
@@ -34,16 +33,16 @@ class _default {
|
|
|
34
33
|
_index.default.each(extraData, (v, k) => {
|
|
35
34
|
data[k] = v;
|
|
36
35
|
});
|
|
37
|
-
return this.apireq.post(
|
|
36
|
+
return this.apireq.post(`/accounts/${this.accid}/conversations`, data);
|
|
38
37
|
});
|
|
39
38
|
_defineProperty(this, "sendConvoEvent", (cid, ev) => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/events`, ev));
|
|
40
39
|
_defineProperty(this, "createPostback", (cid, p) => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/postbacks`, p));
|
|
41
|
-
_defineProperty(this, "markAsReceived", (cid, messageId) => this.apireq.post(`/conversations/${cid}/messages/${messageId}/receive`));
|
|
42
|
-
_defineProperty(this, "markAsSeen", (cid, messageId) => this.apireq.post(`/conversations/${cid}/messages/${messageId}/seen`));
|
|
43
|
-
_defineProperty(this, "getConversation", cid => this.apireq.get(`/conversations/${cid}`));
|
|
40
|
+
_defineProperty(this, "markAsReceived", (cid, messageId) => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/messages/${messageId}/receive`));
|
|
41
|
+
_defineProperty(this, "markAsSeen", (cid, messageId) => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/messages/${messageId}/seen`));
|
|
42
|
+
_defineProperty(this, "getConversation", cid => this.apireq.get(`/accounts/${this.accid}/conversations/${cid}`));
|
|
44
43
|
_defineProperty(this, "getLocaleContent", locale => this.apireq.get(`/accounts/${this.accid}/locales/${locale}`));
|
|
45
|
-
_defineProperty(this, "sendEvent", data => this.apireq.post(`/users/${this.uid}/events`, data));
|
|
46
|
-
_defineProperty(this, "sendTyping", cid => this.apireq.post(`/conversations/${cid}/typing`));
|
|
44
|
+
_defineProperty(this, "sendEvent", data => this.apireq.post(`/accounts/${this.accid}/users/${this.uid}/events`, data));
|
|
45
|
+
_defineProperty(this, "sendTyping", cid => this.apireq.post(`/accounts/${this.accid}/conversations/${cid}/typing`));
|
|
47
46
|
_defineProperty(this, "sendLostFocus", (device, productid, source_id, sku) => this.sendEvent({
|
|
48
47
|
by: {
|
|
49
48
|
id: this.uid,
|
|
@@ -95,9 +94,8 @@ class _default {
|
|
|
95
94
|
url: this.FileURL + body.url
|
|
96
95
|
};
|
|
97
96
|
});
|
|
98
|
-
_defineProperty(this, "
|
|
99
|
-
_defineProperty(this, "
|
|
100
|
-
_defineProperty(this, "updateUser", data => this.apireq.post(`/users/${this.uid}`, data));
|
|
97
|
+
_defineProperty(this, "time", _ => ajax.setBaseUrl(this.ApiURL).withCredentials(true).setParser('json').get('/time'));
|
|
98
|
+
_defineProperty(this, "updateUser", data => this.apireq.post(`/accounts/${this.accid}/users/${this.uid}`, data));
|
|
101
99
|
_defineProperty(this, "getUser", _ => this.apireq.get(`/accounts/${this.accid}/users/${this.uid}`));
|
|
102
100
|
_defineProperty(this, "getAccountSetting", () => this.apireq.get(`/accounts/${this.accid}/settings`));
|
|
103
101
|
_defineProperty(this, "getIsOnline", () => this.apireq.get(`/accounts/${this.accid}/is_online`));
|
|
@@ -129,99 +127,130 @@ class _default {
|
|
|
129
127
|
});
|
|
130
128
|
return;
|
|
131
129
|
}
|
|
132
|
-
if (this.mask) param.request = param.request.addQuery('x-user-mask', this.mask);
|
|
130
|
+
if (this.ref) param.request = param.request.addQuery('x-user-ref', this.ref);else if (this.mask) param.request = param.request.addQuery('x-user-mask', this.mask);
|
|
133
131
|
return done(true);
|
|
134
132
|
});
|
|
135
133
|
}
|
|
136
134
|
setAgentId(agid) {
|
|
137
135
|
this.agentid = agid;
|
|
138
136
|
}
|
|
139
|
-
setAuth(obj) {
|
|
140
|
-
this.accid = obj.accid;
|
|
137
|
+
async setAuth(obj) {
|
|
138
|
+
if (obj.accid) this.accid = obj.accid;
|
|
139
|
+
if (obj.ref) this.ref = obj.ref;
|
|
141
140
|
this.mask = obj.mask;
|
|
142
|
-
this.
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
};
|
|
154
|
-
if (typeof tokenGenerator !== 'function') return {
|
|
155
|
-
error: 'invalid_token_generator'
|
|
156
|
-
};
|
|
157
|
-
this.accid = accid;
|
|
158
|
-
this.profile_id = uid;
|
|
159
|
-
this.token_generator = async force => {
|
|
160
|
-
await this.refreshLock.lock();
|
|
161
|
-
if (tokensession != this.tokensession) {
|
|
162
|
-
this.refreshLock.unlock();
|
|
163
|
-
return;
|
|
141
|
+
this.profile_id = obj.profile_id;
|
|
142
|
+
if (obj.ref) {
|
|
143
|
+
let outuser;
|
|
144
|
+
for (let i = 0; true; i++) {
|
|
145
|
+
outuser = await ajax.setBaseUrl(this.ApiURL).withCredentials(true).addQuery('v', '6').addQuery('x-user-ref', this.ref).setParser('json').get(`/accounts/${this.accid}/users/${this.ref}`);
|
|
146
|
+
if (!_index.default.get(outuser, 'body.id')) {
|
|
147
|
+
let sleeptime = Math.min(2000 + i * 200, 60000);
|
|
148
|
+
await _index.default.sleep(sleeptime);
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
break;
|
|
164
152
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
153
|
+
if (outuser.error) {
|
|
154
|
+
if (_index.default.get(outuser.body.code)) return {
|
|
155
|
+
error: outuser.body.code
|
|
156
|
+
};
|
|
157
|
+
return outuser;
|
|
169
158
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
159
|
+
this.uid = outuser.body.id;
|
|
160
|
+
return outuser.body;
|
|
161
|
+
}
|
|
162
|
+
if (obj.tokenGenerator) {
|
|
163
|
+
this.tokensession = this.tokensession || 0;
|
|
164
|
+
this.tokensession++;
|
|
165
|
+
let tokensession = this.tokensession;
|
|
166
|
+
if (!this.accid || !_index.default.startsWith(this.accid, 'ac')) return {
|
|
167
|
+
error: 'invalid_account_id'
|
|
168
|
+
};
|
|
169
|
+
if (!this.profile_id) return {
|
|
170
|
+
error: 'invalid_profile_id'
|
|
171
|
+
};
|
|
172
|
+
if (typeof this.tokenGenerator !== 'function') return {
|
|
173
|
+
error: 'invalid_token_generator'
|
|
174
|
+
};
|
|
175
|
+
let profile_id = this.profile_id;
|
|
176
|
+
this.token_generator = async force => {
|
|
177
|
+
await this.refreshLock.lock();
|
|
178
|
+
if (tokensession != this.tokensession) {
|
|
179
|
+
this.refreshLock.unlock();
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
let age = (_index.default.Date.now() - (this.last_token_at || 0)) / 1000;
|
|
183
|
+
if (!force && this.last_token && age < 1800) {
|
|
184
|
+
this.refreshLock.unlock();
|
|
185
|
+
return this.last_token;
|
|
186
|
+
}
|
|
187
|
+
if (!force && this.last_token && age < 3000) {
|
|
188
|
+
if (this.token_generator) setTimeout(async () => {
|
|
189
|
+
let token, err;
|
|
190
|
+
try {
|
|
191
|
+
token = await tokenGenerator(profile_id);
|
|
192
|
+
} catch (e) {
|
|
193
|
+
err = e;
|
|
194
|
+
}
|
|
195
|
+
if (tokensession != this.tokensession) {
|
|
196
|
+
this.refreshLock.unlock();
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (err) this.last_token = 'error';else this.last_token = token;
|
|
200
|
+
this.last_token_at = _index.default.Date.now();
|
|
179
201
|
this.refreshLock.unlock();
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
202
|
+
});
|
|
203
|
+
return this.last_token;
|
|
204
|
+
}
|
|
205
|
+
let token;
|
|
206
|
+
let err;
|
|
207
|
+
try {
|
|
208
|
+
token = await tokenGenerator(profile_id);
|
|
209
|
+
} catch (e) {
|
|
210
|
+
err = e;
|
|
211
|
+
}
|
|
212
|
+
if (tokensession != this.tokensession) {
|
|
184
213
|
this.refreshLock.unlock();
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
let err;
|
|
190
|
-
try {
|
|
191
|
-
token = await tokenGenerator(uid);
|
|
192
|
-
} catch (e) {
|
|
193
|
-
err = e;
|
|
194
|
-
}
|
|
195
|
-
if (tokensession != this.tokensession) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
if (err) this.last_token = 'error';else this.last_token = token;
|
|
217
|
+
this.last_token_at = _index.default.Date.now();
|
|
196
218
|
this.refreshLock.unlock();
|
|
197
|
-
return;
|
|
219
|
+
return this.last_token;
|
|
220
|
+
};
|
|
221
|
+
let outuser;
|
|
222
|
+
for (let i = 0; true; i++) {
|
|
223
|
+
await this.token_generator(true);
|
|
224
|
+
if (tokensession != this.tokensession) break;
|
|
225
|
+
outuser = await ajax.setBaseUrl(this.ApiURL).withCredentials(true).addQuery('v', '6').addQuery('x-access-token', this.last_token).setParser('json').get(`/accounts/${accid}/users/${profile_id}`);
|
|
226
|
+
if (!_index.default.get(outuser, 'body.id')) {
|
|
227
|
+
let sleeptime = Math.min(2000 + i * 100, 120000);
|
|
228
|
+
await _index.default.sleep(sleeptime);
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
break;
|
|
198
232
|
}
|
|
199
|
-
if (
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
let outuser;
|
|
205
|
-
for (let i = 0; true; i++) {
|
|
206
|
-
await this.token_generator(true);
|
|
207
|
-
if (tokensession != this.tokensession) break;
|
|
208
|
-
outuser = await ajax.setBaseUrl(this.ApiURL).withCredentials(true).addQuery('v', '6').addQuery('x-access-token', this.last_token).setParser('json').get(`/accounts/${accid}/users/${uid}`);
|
|
209
|
-
if (!_index.default.get(outuser, 'body.id')) {
|
|
210
|
-
let sleeptime = Math.min(2000 + i * 100, 120000);
|
|
211
|
-
await _index.default.sleep(sleeptime);
|
|
212
|
-
continue;
|
|
233
|
+
if (outuser.error) {
|
|
234
|
+
if (_index.default.get(outuser.body.code)) return {
|
|
235
|
+
error: outuser.body.code
|
|
236
|
+
};
|
|
237
|
+
return outuser;
|
|
213
238
|
}
|
|
214
|
-
|
|
239
|
+
this.uid = outuser.body.id;
|
|
240
|
+
return outuser.body;
|
|
215
241
|
}
|
|
216
|
-
if (
|
|
217
|
-
|
|
218
|
-
|
|
242
|
+
if (this.mask) {
|
|
243
|
+
let parts = this.mask.split('@');
|
|
244
|
+
this.uid = parts[1];
|
|
245
|
+
return {
|
|
246
|
+
id: this.uid
|
|
219
247
|
};
|
|
220
|
-
return outuser;
|
|
221
248
|
}
|
|
222
|
-
|
|
223
|
-
|
|
249
|
+
return {
|
|
250
|
+
error: 'invalid_auth'
|
|
251
|
+
};
|
|
224
252
|
}
|
|
253
|
+
async setTokenGenerator(accid, uid, tokenGenerator) {}
|
|
225
254
|
sendContentView(device, pageUrl, pageTitle, id, source_id, sku) {
|
|
226
255
|
if (!id) id = undefined;
|
|
227
256
|
if (!source_id) source_id = undefined;
|
|
@@ -243,26 +272,5 @@ class _default {
|
|
|
243
272
|
}
|
|
244
273
|
});
|
|
245
274
|
}
|
|
246
|
-
async createUser(accid) {
|
|
247
|
-
for (var i = 0; i < 10; i++) {
|
|
248
|
-
const {
|
|
249
|
-
body: challenge
|
|
250
|
-
} = await this.getChallenge(accid);
|
|
251
|
-
const answer = findAnswer(challenge);
|
|
252
|
-
const data = {
|
|
253
|
-
challenge_id: challenge.id,
|
|
254
|
-
answer: '' + answer
|
|
255
|
-
};
|
|
256
|
-
let {
|
|
257
|
-
body: user,
|
|
258
|
-
error
|
|
259
|
-
} = await this.apireq.post(`/accounts/${accid}/scrypt-challenges/users`, data);
|
|
260
|
-
if (error) {
|
|
261
|
-
await _index.default.sleep(1000);
|
|
262
|
-
continue;
|
|
263
|
-
}
|
|
264
|
-
return user;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
275
|
}
|
|
268
276
|
exports.default = _default;
|
|
@@ -56,11 +56,6 @@ class _default {
|
|
|
56
56
|
_defineProperty(this, "sendContent", data => OK200);
|
|
57
57
|
_defineProperty(this, "uploadToS3", async file => OK200);
|
|
58
58
|
_defineProperty(this, "getChallenge", accid => OK200);
|
|
59
|
-
_defineProperty(this, "createUser", accid => Promise.resolve({
|
|
60
|
-
account_id: accid,
|
|
61
|
-
id: 'usqzgtgfake',
|
|
62
|
-
mask: 'fakemask'
|
|
63
|
-
}));
|
|
64
59
|
_defineProperty(this, "time", _ => Promise.resolve({
|
|
65
60
|
code: 200,
|
|
66
61
|
body: new _index.default.Date().toISOString()
|
|
@@ -89,6 +84,10 @@ class _default {
|
|
|
89
84
|
this.accid = obj.accid;
|
|
90
85
|
this.mask = obj.mask;
|
|
91
86
|
this.uid = obj.uid;
|
|
87
|
+
return {
|
|
88
|
+
account_id: accid,
|
|
89
|
+
id: 'usqzgtgfake'
|
|
90
|
+
};
|
|
92
91
|
}
|
|
93
92
|
}
|
|
94
93
|
exports.default = _default;
|
|
@@ -167,6 +167,13 @@ class Store {
|
|
|
167
167
|
this.inmem = inmem;
|
|
168
168
|
this.cookie = inmemCookie;
|
|
169
169
|
}
|
|
170
|
+
if (!inmem) {
|
|
171
|
+
try {
|
|
172
|
+
this.cookie.get('_', '');
|
|
173
|
+
} catch (e) {
|
|
174
|
+
inmem = true;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
170
177
|
this.pubsub = new _index.default.Pubsub();
|
|
171
178
|
this.kv = new _storage.default.kv(new _storage.default.lsdb('sbz2020', this.inmem), 'kv');
|
|
172
179
|
this.cache = new _storage.default.kv(new _storage.default.lsdb('sbz2020', true), 'kv');
|
|
@@ -302,58 +309,64 @@ class Store {
|
|
|
302
309
|
await this.readyGate.entry();
|
|
303
310
|
if (!this.isInsync('account')) this.reconnect();
|
|
304
311
|
}
|
|
305
|
-
async init(accid, mask) {
|
|
312
|
+
async init(accid, mask, userRef) {
|
|
306
313
|
this.readyGate.close();
|
|
307
314
|
accid = (accid || '').trim();
|
|
308
315
|
this.api.setAuth({
|
|
309
316
|
accid: accid
|
|
310
317
|
});
|
|
311
318
|
this.g_sync = {};
|
|
312
|
-
if (!
|
|
319
|
+
if (!userRef) {
|
|
313
320
|
try {
|
|
314
|
-
|
|
321
|
+
userRef = this.cookie.get('__sbref', '');
|
|
315
322
|
} catch (e) {}
|
|
323
|
+
if (!userRef) {
|
|
324
|
+
if (!mask) {
|
|
325
|
+
try {
|
|
326
|
+
mask = this.cookie.get('__sbmask', '');
|
|
327
|
+
} catch (e) {}
|
|
328
|
+
}
|
|
329
|
+
if (mask) {
|
|
330
|
+
let parts = mask.split('@');
|
|
331
|
+
if (parts[0] != accid) {
|
|
332
|
+
userRef = _index.default.randomString(40);
|
|
333
|
+
this.new_visitor = true;
|
|
334
|
+
}
|
|
335
|
+
this.new_visitor = false;
|
|
336
|
+
this.cookie.set('__sbmask', mask);
|
|
337
|
+
} else {
|
|
338
|
+
userRef = _index.default.randomString(40);
|
|
339
|
+
this.new_visitor = true;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
316
342
|
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
mask = '';
|
|
325
|
-
this.clearBrowserData();
|
|
326
|
-
} else userId = parts[1];
|
|
327
|
-
}
|
|
328
|
-
if (!mask) {
|
|
329
|
-
let user = await this.api.createUser(accid);
|
|
330
|
-
this.new_visitor = true;
|
|
331
|
-
mask = user.mask;
|
|
332
|
-
userId = user.id;
|
|
333
|
-
} else {
|
|
334
|
-
this.new_visitor = false;
|
|
335
|
-
}
|
|
336
|
-
this.cookie.set('__sbmask', mask);
|
|
337
|
-
this.kv.put('mask', mask);
|
|
343
|
+
if (userRef) this.cookie.set('__sbref', userRef);
|
|
344
|
+
let user = await this.api.setAuth({
|
|
345
|
+
accid: accid,
|
|
346
|
+
mask: mask,
|
|
347
|
+
ref: userRef
|
|
348
|
+
});
|
|
349
|
+
if (user.error) return;
|
|
338
350
|
if (this.realtime) this.realtime.stop();
|
|
339
351
|
if (this.fake) this.realtime = new _realtime_fake.default();else this.realtime = new Realtime(this.RealtimeURL, {
|
|
352
|
+
account_id: accid,
|
|
353
|
+
user_ref: userRef,
|
|
340
354
|
user_mask: mask
|
|
341
355
|
});
|
|
342
356
|
this.realtime.onEvent(this.onWs.bind(this));
|
|
343
|
-
this.realtime.onInterrupted(() => this.reconnectWs(accid,
|
|
344
|
-
this.api.setAuth({
|
|
345
|
-
accid: accid,
|
|
346
|
-
uid: userId,
|
|
347
|
-
mask: mask
|
|
348
|
-
});
|
|
357
|
+
this.realtime.onInterrupted(() => this.reconnectWs(accid, user.id));
|
|
349
358
|
this.seenLoop();
|
|
350
359
|
await this.reconnect();
|
|
351
360
|
this.readyGate.open();
|
|
352
|
-
this.reconnectWs(accid,
|
|
353
|
-
return
|
|
361
|
+
this.reconnectWs(accid, user.id);
|
|
362
|
+
return user;
|
|
354
363
|
}
|
|
355
364
|
async login(accid, user_id, tokenGenerator) {
|
|
356
|
-
let user = await this.api.
|
|
365
|
+
let user = await this.api.setAuth({
|
|
366
|
+
accid: accid,
|
|
367
|
+
profile_id: user_id,
|
|
368
|
+
tokenGenerator: tokenGenerator
|
|
369
|
+
});
|
|
357
370
|
if (user.error) return user;
|
|
358
371
|
this.clearBrowserData();
|
|
359
372
|
this.readyGate.close();
|
|
@@ -372,8 +385,10 @@ class Store {
|
|
|
372
385
|
this.reconnectWs(accid, user.id);
|
|
373
386
|
return user;
|
|
374
387
|
}
|
|
375
|
-
logout(
|
|
376
|
-
this.api.
|
|
388
|
+
logout(userRef) {
|
|
389
|
+
return this.api.setAuth({
|
|
390
|
+
ref: userRef
|
|
391
|
+
});
|
|
377
392
|
}
|
|
378
393
|
seenLoop() {
|
|
379
394
|
this.seenQueue = [];
|