@inboxsdk/core 0.2.28-alpha.3 → 0.2.28-alpha.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/inboxsdk.js +1 -1
- package/inboxsdk.js.map +1 -1
- package/package.json +1 -1
- package/src/build/exec.js +26 -0
- package/src/build/spawn.js +17 -0
- package/src/common/ajax.js +90 -0
- package/src/common/cachebust-url.js +10 -0
- package/src/common/censorHTMLstring.js +37 -0
- package/src/common/censorHTMLtree.js +28 -0
- package/src/common/censorJSONTree.js +15 -0
- package/src/common/connectivity-test.js +21 -0
- package/src/common/defer.js +11 -0
- package/src/common/find-parent.js +10 -0
- package/src/common/get-extension-id.js +7 -0
- package/src/common/get-or-fail.js +8 -0
- package/src/common/get-session-id.js +14 -0
- package/src/common/get-stack-trace.js +6 -0
- package/src/common/html-to-text.js +7 -0
- package/src/common/isElementVisible.js +6 -0
- package/src/common/load-script.js +127 -0
- package/src/common/log-error.js +191 -0
- package/src/common/quoted-split.js +18 -0
- package/src/common/rate-limit-queuer.js +57 -0
- package/src/common/rate-limit.js +14 -0
- package/src/common/version.js +6 -0
- package/src/inboxsdk-js/loading/platform-implementation-loader.js +27 -0
- package/src/injected-js/gmail/constants.js +2 -0
- package/src/injected-js/gmail/modify-suggestions.js +106 -0
- package/src/injected-js/gmail/setup-gmonkey-handler.js +49 -0
- package/src/injected-js/gmail/sync-compose-processor-20220909.js +298 -0
- package/src/injected-js/gmail/sync-compose-processor.js +55 -0
- package/src/injected-js/gmail/sync-compose-request-processor.js +110 -0
- package/src/injected-js/injected-logger.js +50 -0
- package/src/injected-js/setupCustomViewEventAssassin.js +90 -0
- package/src/platform-implementation-js/constants/nav-item-types.js +19 -0
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/add-app-menu-item.js +21 -0
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/add-collapsible-panel.js +28 -0
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/add-nav-item.js +98 -0
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/add-support-item.js +4 -0
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/encodeDraftUrlId.js +8 -0
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/get-rfc-message-id-for-gmail-message-id.js +12 -0
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/get-rfc-message-id-for-gmail-thread-id.js +33 -0
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/isIntegratedViewGmail.js +4 -0
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/open-draft-by-message-id.js +44 -0
- package/src/platform-implementation-js/dom-driver/gmail/gmail-driver/track-gmail-styles.js +95 -0
- package/src/platform-implementation-js/dom-driver/gmail/gmail-element-getter/get-main-content-element-changed-stream.js +38 -0
- package/src/platform-implementation-js/dom-driver/gmail/gmail-element-getter/wait-for-gmail-mode-to-settle.js +12 -0
- package/src/platform-implementation-js/dom-driver/gmail/gmail-element-getter.js +253 -0
- package/src/platform-implementation-js/dom-driver/gmail/gmail-page-communicator.js +200 -0
- package/src/platform-implementation-js/dom-driver/gmail/gmail-response-processor.js +533 -0
- package/src/platform-implementation-js/dom-driver/gmail/gmail-sync-response-processor.js +289 -0
- package/src/platform-implementation-js/dom-driver/gmail/is-compose-titlebar-light-color.js +21 -0
- package/src/platform-implementation-js/dom-driver/gmail/makePageParserTree.js +28 -0
- package/src/platform-implementation-js/dom-driver/gmail/pageParserOptions.js +19 -0
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-app-menu-item-view.js +126 -0
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-compose-view/add-status-bar.js +101 -0
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-compose-view/detectClassicRecipientsArea.js +38 -0
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-compose-view/get-address-information-extractor.js +28 -0
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-compose-view/get-recipients.js +22 -0
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-compose-view/gmail-compose-button-view.js +233 -0
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-compose-view/page-parser.js +223 -0
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-compose-view/set-recipients.js +157 -0
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-compose-view/setupLinkPopovers.js +109 -0
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-message-view/attachment-icon.js +5 -0
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-nav-item-view.js +759 -0
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-support-item-view.js +84 -0
- package/src/platform-implementation-js/dom-driver/gmail/widgets/buttons/button-color-classes.js +33 -0
- package/src/platform-implementation-js/dom-driver/gmail/widgets/buttons/button-view.js +325 -0
- package/src/platform-implementation-js/dom-driver/gmail/widgets/buttons/create-accessory-button-view.js +58 -0
- package/src/platform-implementation-js/dom-driver/gmail/widgets/buttons/create-parent-accessory-button-view.js +55 -0
- package/src/platform-implementation-js/dom-driver/gmail/widgets/buttons/modal-button-view.js +96 -0
- package/src/platform-implementation-js/dom-driver/gmail/widgets/buttons/more-dropdown-button-view.js +30 -0
- package/src/platform-implementation-js/dom-driver/gmail/widgets/buttons/more-parent-accessory-button-view.js +10 -0
- package/src/platform-implementation-js/dom-driver/gmail/widgets/gmail-dropdown-view.js +22 -0
- package/src/platform-implementation-js/driver-common/getAccountUrlPart.js +17 -0
- package/src/platform-implementation-js/driver-common/getOriginalMessagePage.js +33 -0
- package/src/platform-implementation-js/driver-common/getSyncThreadsForSearch.js +49 -0
- package/src/platform-implementation-js/driver-common/gmailAjax.js +65 -0
- package/src/platform-implementation-js/driver-common/render-custom-icon.js +16 -0
- package/src/platform-implementation-js/driver-common/update-icon.js +90 -0
- package/src/platform-implementation-js/lib/ErrorCollector.js +47 -0
- package/src/platform-implementation-js/lib/Membrane.js +22 -0
- package/src/platform-implementation-js/lib/ScrollableContainByScreen.js +30 -0
- package/src/platform-implementation-js/lib/attemptWithRetries.js +16 -0
- package/src/platform-implementation-js/lib/common-page-communicator.js +137 -0
- package/src/platform-implementation-js/lib/delay-asap.js +12 -0
- package/src/platform-implementation-js/lib/delay-idle.js +16 -0
- package/src/platform-implementation-js/lib/dom/block-and-reemit-keyboard-events.js +36 -0
- package/src/platform-implementation-js/lib/dom/generic-button-view.js +39 -0
- package/src/platform-implementation-js/lib/dom/get-insert-before-element.js +39 -0
- package/src/platform-implementation-js/lib/dom/insert-element-in-order.js +38 -0
- package/src/platform-implementation-js/lib/dom/keyboard-shortcut-stream.js +12 -0
- package/src/platform-implementation-js/lib/dom/make-element-child-stream.js +79 -0
- package/src/platform-implementation-js/lib/dom/make-element-stream-merger.js +28 -0
- package/src/platform-implementation-js/lib/dom/make-element-view-stream.js +15 -0
- package/src/platform-implementation-js/lib/dom/make-mutation-observer-chunked-stream.js +15 -0
- package/src/platform-implementation-js/lib/dom/make-mutation-observer-stream.js +5 -0
- package/src/platform-implementation-js/lib/dom/outsideClicksAndEscape.js +39 -0
- package/src/platform-implementation-js/lib/dom/parentNodes.js +8 -0
- package/src/platform-implementation-js/lib/dom/querySelectorOrFail.js +6 -0
- package/src/platform-implementation-js/lib/dom/reemitClickEventForReact.js +22 -0
- package/src/platform-implementation-js/lib/dom/simulate-key.js +46 -0
- package/src/platform-implementation-js/lib/dom/simulate-mouse-event.js +16 -0
- package/src/platform-implementation-js/lib/dom/trigger-relay-event.js +7 -0
- package/src/platform-implementation-js/lib/extract-contact-from-email-contact-string.js +25 -0
- package/src/platform-implementation-js/lib/fake-window-resize.js +5 -0
- package/src/platform-implementation-js/lib/from-event-target-capture.js +12 -0
- package/src/platform-implementation-js/lib/fromEventsWithOptions.js +10 -0
- package/src/platform-implementation-js/lib/handler-registry.js +67 -0
- package/src/platform-implementation-js/lib/idMap.js +45 -0
- package/src/platform-implementation-js/lib/imageRequest.js +8 -0
- package/src/platform-implementation-js/lib/incrementName.js +7 -0
- package/src/platform-implementation-js/lib/inject-script-EMBEDDED.js +14 -0
- package/src/platform-implementation-js/lib/inject-script.js +33 -0
- package/src/platform-implementation-js/lib/is-valid-app-id.js +27 -0
- package/src/platform-implementation-js/lib/is-valid-email.js +14 -0
- package/src/platform-implementation-js/lib/isNotNil.js +5 -0
- package/src/platform-implementation-js/lib/isStreakAppId.js +11 -0
- package/src/platform-implementation-js/lib/logger.js +441 -0
- package/src/platform-implementation-js/lib/persistent-queue.js +107 -0
- package/src/platform-implementation-js/lib/safe-event-emitter.js +17 -0
- package/src/platform-implementation-js/lib/stopper-pool.js +41 -0
- package/src/platform-implementation-js/lib/stream-wait-for.js +30 -0
- package/src/platform-implementation-js/lib/wait-for.js +28 -0
- package/src/platform-implementation-js/lib/waitForAsync.js +19 -0
- package/src/platform-implementation-js/namespaces/app-menu.d.ts.map +1 -1
- package/src/platform-implementation-js/namespaces/app-menu.js +31 -0
- package/src/platform-implementation-js/namespaces/butter-bar.js +163 -0
- package/src/platform-implementation-js/views/SimpleElementView.js +16 -0
- package/src/platform-implementation-js/views/app-menu-item-view.js +257 -0
- package/src/platform-implementation-js/views/collapsible-panel-view.js +222 -0
- package/src/platform-implementation-js/views/compose-button-view.js +45 -0
- package/src/platform-implementation-js/views/compose-view.js +312 -0
- package/src/platform-implementation-js/views/keyboard-shortcut-handle.js +14 -0
- package/src/platform-implementation-js/widgets/buttons/basic-button-view-controller.js +39 -0
- package/src/platform-implementation-js/widgets/buttons/dropdown-button-view-controller.js +98 -0
- package/src/platform-implementation-js/widgets/buttons/dropdown-view.js +122 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const re = /^([^<>()[\]\\,;:\s"]+|".+")@[^\s<>]+$/;
|
|
2
|
+
// This function is supposed to be pretty forgiving because emails can have
|
|
3
|
+
// almost anything in their From header. This function exists as a sanity check
|
|
4
|
+
// to make sure that we didn't try to read from the wrong DOM element. It
|
|
5
|
+
// passes anything with at least one @ sign that doesn't contain certain
|
|
6
|
+
// symbols. We might want to make it even less strict and allow more symbols if
|
|
7
|
+
// it turns out people are legitimately receiving emails with these in the From
|
|
8
|
+
// or other recipient headers.
|
|
9
|
+
export default function isValidEmail(candidate) {
|
|
10
|
+
if (candidate == null) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
return re.test(candidate);
|
|
14
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Sha256 from 'sha.js/sha256';
|
|
2
|
+
function hash(x) {
|
|
3
|
+
const hasher = new Sha256();
|
|
4
|
+
hasher.update('bdnanNrDjv' + x);
|
|
5
|
+
return hasher.digest('hex').slice(0, 32);
|
|
6
|
+
}
|
|
7
|
+
export default function isStreakAppId(appId) {
|
|
8
|
+
// Checks if appId === 'sdk_streak_21e9788951' without putting the appId in
|
|
9
|
+
// the source. Just using a similar technique to is-valid-app-id.
|
|
10
|
+
return hash(appId) === 'f471fe7b7343b47a202437c3962cc335';
|
|
11
|
+
}
|
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import Sha256 from 'sha.js/sha256';
|
|
3
|
+
import ajax from '../../common/ajax';
|
|
4
|
+
import getExtensionId from '../../common/get-extension-id';
|
|
5
|
+
import getSessionId from '../../common/get-session-id';
|
|
6
|
+
import logError from '../../common/log-error';
|
|
7
|
+
import PersistentQueue from './persistent-queue';
|
|
8
|
+
import makeMutationObserverStream from './dom/make-mutation-observer-stream';
|
|
9
|
+
import { getXMLHttpRequest } from 'ext-corb-workaround';
|
|
10
|
+
import isStreakAppId from './isStreakAppId';
|
|
11
|
+
// Yeah, this module is a singleton with some shared state. This is just for
|
|
12
|
+
// logging convenience. Other modules should avoid doing this!
|
|
13
|
+
const _extensionAppIds = [];
|
|
14
|
+
let _extensionLoaderVersion;
|
|
15
|
+
let _extensionImplVersion;
|
|
16
|
+
let _extensionUserEmailHash;
|
|
17
|
+
let _extensionUseEventTracking = false;
|
|
18
|
+
let _isUsingSyncAPI = undefined;
|
|
19
|
+
const _sessionId = getSessionId();
|
|
20
|
+
const _loggedDeprecatedMessages = new Set();
|
|
21
|
+
// The logger master is the first InboxSDK extension to load. This
|
|
22
|
+
// first extension is tasked with reporting tracked events to the server.
|
|
23
|
+
const _extensionIsLoggerMaster = (function () {
|
|
24
|
+
if (typeof document === 'undefined') {
|
|
25
|
+
return true; // for unit tests
|
|
26
|
+
}
|
|
27
|
+
if (document.documentElement.hasAttribute('data-inboxsdk-master-claimed')) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
document.documentElement.setAttribute('data-inboxsdk-master-claimed', 'true');
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
})();
|
|
35
|
+
function getAllAppIds() {
|
|
36
|
+
const str = (typeof document !== 'undefined' &&
|
|
37
|
+
document.documentElement.getAttribute('data-inboxsdk-active-app-ids')) ||
|
|
38
|
+
'[]';
|
|
39
|
+
return JSON.parse(str);
|
|
40
|
+
}
|
|
41
|
+
const _trackedEventsQueue = new PersistentQueue('events');
|
|
42
|
+
const FIRST_LOADED_TIME = Date.now();
|
|
43
|
+
export default class Logger {
|
|
44
|
+
_appId;
|
|
45
|
+
_isMaster;
|
|
46
|
+
constructor(appId, opts, loaderVersion, implVersion) {
|
|
47
|
+
_extensionLoggerSetup(appId, opts, loaderVersion, implVersion);
|
|
48
|
+
this._appId = appId;
|
|
49
|
+
this._isMaster = (() => {
|
|
50
|
+
if (!_extensionUseEventTracking ||
|
|
51
|
+
(typeof document !== 'undefined' &&
|
|
52
|
+
document.documentElement.hasAttribute('data-inboxsdk-app-logger-master-chosen'))) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
document.documentElement.setAttribute('data-inboxsdk-app-logger-master-chosen', 'true');
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
})();
|
|
60
|
+
if (this._isMaster && typeof document !== 'undefined') {
|
|
61
|
+
document.addEventListener('inboxSDKinjectedError', (event) => {
|
|
62
|
+
if (!(event instanceof CustomEvent && event?.detail)) {
|
|
63
|
+
this.error(new Error('Invalid inboxSDKinjectedError event'), event);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const detail = event.detail;
|
|
67
|
+
this.error(Object.assign(new Error(detail.message), { stack: detail.stack }), detail.details);
|
|
68
|
+
});
|
|
69
|
+
document.addEventListener('inboxSDKinjectedEventSdkPassive', (event) => {
|
|
70
|
+
const detail = event.detail;
|
|
71
|
+
this.eventSdkPassive(detail.name, detail.details, detail.sensitive);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
setUserEmailAddress(email) {
|
|
76
|
+
_extensionUserEmailHash = hashEmail(email);
|
|
77
|
+
}
|
|
78
|
+
shouldTrackEverything() {
|
|
79
|
+
return (_extensionUserEmailHash ===
|
|
80
|
+
'ca05afe92819df590a4196c31814fdb24050e8f49d8a41613f3d6cfb5729c785');
|
|
81
|
+
}
|
|
82
|
+
setIsUsingSyncAPI(isUsing) {
|
|
83
|
+
_isUsingSyncAPI = isUsing;
|
|
84
|
+
}
|
|
85
|
+
static run(cb, details) {
|
|
86
|
+
try {
|
|
87
|
+
return cb();
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
Logger.error(err, details);
|
|
91
|
+
throw err;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
run(cb, details) {
|
|
95
|
+
try {
|
|
96
|
+
return cb();
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
this.error(err, details);
|
|
100
|
+
throw err;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
static error(err, details) {
|
|
104
|
+
_logError(err, details, undefined, false);
|
|
105
|
+
}
|
|
106
|
+
error(err, details) {
|
|
107
|
+
_logError(err, details, this._appId, false);
|
|
108
|
+
}
|
|
109
|
+
errorApp(err, details) {
|
|
110
|
+
_logError(err, details, this._appId, true);
|
|
111
|
+
}
|
|
112
|
+
errorSite(err, details) {
|
|
113
|
+
// Only the first logger instance reports Site errors.
|
|
114
|
+
if (!this._isMaster) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
this.error(err, details);
|
|
118
|
+
}
|
|
119
|
+
// Should only be used by the InboxSDK users for their own app events.
|
|
120
|
+
eventApp(name, details) {
|
|
121
|
+
_trackEvent(this._appId, 'app', name, details);
|
|
122
|
+
}
|
|
123
|
+
// For tracking app events that are possibly triggered by the user. Extensions
|
|
124
|
+
// can opt out of this with a flag passed to InboxSDK.load().
|
|
125
|
+
eventSdkActive(name, details) {
|
|
126
|
+
if (!_extensionUseEventTracking) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
_trackEvent(this._appId, 'sdkActive', name, details);
|
|
130
|
+
}
|
|
131
|
+
// Track events unrelated to user activity about how the app uses the SDK.
|
|
132
|
+
// Examples include the app being initialized, and calls to any of the
|
|
133
|
+
// register___ViewHandler functions.
|
|
134
|
+
eventSdkPassive(name, details, sensitive) {
|
|
135
|
+
if (sensitive && !isStreakAppId(this._appId)) {
|
|
136
|
+
// do not log events if they were marked as sensitive
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
_trackEvent(this._appId, 'sdkPassive', name, details);
|
|
140
|
+
}
|
|
141
|
+
// Track Site events.
|
|
142
|
+
eventSite(name, details) {
|
|
143
|
+
// Only the first logger instance reports Site events.
|
|
144
|
+
if (!this._isMaster) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
_trackEvent(this._appId, 'gmail', name, details);
|
|
148
|
+
}
|
|
149
|
+
deprecationWarning(name, suggestion) {
|
|
150
|
+
console.warn(`InboxSDK: ${name} is deprecated.` +
|
|
151
|
+
(suggestion ? ` Please use ${suggestion} instead.` : ''));
|
|
152
|
+
const key = name + (suggestion ? ':' + suggestion : '');
|
|
153
|
+
if (!_loggedDeprecatedMessages.has(key)) {
|
|
154
|
+
this.eventSdkPassive(`deprecated.${name}`);
|
|
155
|
+
_loggedDeprecatedMessages.add(key);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
getAppLogger() {
|
|
159
|
+
return {
|
|
160
|
+
error: (err, details) => this.errorApp(err, details),
|
|
161
|
+
event: (name, details) => this.eventApp(name, details),
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
trackFunctionPerformance(fn, sampleRate, details) {
|
|
165
|
+
if (Math.random() < sampleRate &&
|
|
166
|
+
document.visibilityState === 'visible' &&
|
|
167
|
+
this._isMaster) {
|
|
168
|
+
const start = Date.now();
|
|
169
|
+
fn();
|
|
170
|
+
setTimeout(() => {
|
|
171
|
+
const now = Date.now();
|
|
172
|
+
this.eventSdkPassive('function performance result', {
|
|
173
|
+
value: now - start,
|
|
174
|
+
timeSinceFirstLoad: now - FIRST_LOADED_TIME,
|
|
175
|
+
...details,
|
|
176
|
+
});
|
|
177
|
+
}, 10);
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
fn();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function _extensionLoggerSetup(appId, opts, loaderVersion, implVersion) {
|
|
185
|
+
_extensionAppIds.push(Object.freeze({
|
|
186
|
+
appId: appId,
|
|
187
|
+
version: opts.appVersion || undefined,
|
|
188
|
+
}));
|
|
189
|
+
document.documentElement.setAttribute('data-inboxsdk-active-app-ids', JSON.stringify(getAllAppIds().concat([
|
|
190
|
+
{
|
|
191
|
+
appId: appId,
|
|
192
|
+
version: opts.appVersion || undefined,
|
|
193
|
+
},
|
|
194
|
+
])));
|
|
195
|
+
if (_extensionLoaderVersion) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
_extensionLoaderVersion = loaderVersion;
|
|
199
|
+
_extensionImplVersion = implVersion;
|
|
200
|
+
_extensionUseEventTracking = opts.eventTracking;
|
|
201
|
+
if (opts.globalErrorLogging) {
|
|
202
|
+
if (Error.stackTraceLimit < 40) {
|
|
203
|
+
Error.stackTraceLimit = 40;
|
|
204
|
+
}
|
|
205
|
+
window.addEventListener('error', function (event) {
|
|
206
|
+
// Ugh, currently Chrome makes this pretty useless. Once Chrome fixes
|
|
207
|
+
// this, we can remove the logged function wrappers around setTimeout and
|
|
208
|
+
// things.
|
|
209
|
+
if (event.error) {
|
|
210
|
+
Logger.error(event.error, 'Uncaught exception');
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
replaceFunction(window, 'setTimeout', function (original) {
|
|
214
|
+
return function wrappedSetTimeout(...args) {
|
|
215
|
+
if (typeof args[0] == 'function') {
|
|
216
|
+
args[0] = makeLoggedFunction(args[0], 'setTimeout callback');
|
|
217
|
+
}
|
|
218
|
+
return original.apply(this, args);
|
|
219
|
+
};
|
|
220
|
+
});
|
|
221
|
+
replaceFunction(window, 'setInterval', function (original) {
|
|
222
|
+
return function wrappedSetInterval(...args) {
|
|
223
|
+
if (typeof args[0] == 'function') {
|
|
224
|
+
args[0] = makeLoggedFunction(args[0], 'setInterval callback');
|
|
225
|
+
}
|
|
226
|
+
return original.apply(this, args);
|
|
227
|
+
};
|
|
228
|
+
});
|
|
229
|
+
const ETp = (window.EventTarget && window.EventTarget.prototype) ||
|
|
230
|
+
window.Node.prototype;
|
|
231
|
+
replaceFunction(ETp, 'addEventListener', function (original) {
|
|
232
|
+
return function wrappedAddEventListener(...args) {
|
|
233
|
+
if (typeof args[1] == 'function') {
|
|
234
|
+
try {
|
|
235
|
+
// If we've made a logger for this function before, use it again,
|
|
236
|
+
// otherwise attach it as a property to the original function.
|
|
237
|
+
// This is necessary so that removeEventListener is called with
|
|
238
|
+
// the right function.
|
|
239
|
+
let loggedFn = args[1].__inboxsdk_logged;
|
|
240
|
+
if (!loggedFn) {
|
|
241
|
+
loggedFn = makeLoggedFunction(args[1], 'event listener');
|
|
242
|
+
// eslint-disable-next-line
|
|
243
|
+
args[1].__inboxsdk_logged = loggedFn;
|
|
244
|
+
}
|
|
245
|
+
args[1] = loggedFn;
|
|
246
|
+
}
|
|
247
|
+
catch (e) {
|
|
248
|
+
// This could be triggered if the given function was immutable
|
|
249
|
+
// and stopped us from saving the logged copy on it.
|
|
250
|
+
console.error('Failed to error wrap function', e);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return original.apply(this, args);
|
|
254
|
+
};
|
|
255
|
+
});
|
|
256
|
+
replaceFunction(ETp, 'removeEventListener', function (original) {
|
|
257
|
+
return function wrappedRemoveEventListener(...args) {
|
|
258
|
+
if (typeof args[1] == 'function' && args[1].__inboxsdk_logged) {
|
|
259
|
+
args[1] = args[1].__inboxsdk_logged;
|
|
260
|
+
}
|
|
261
|
+
return original.apply(this, args);
|
|
262
|
+
};
|
|
263
|
+
});
|
|
264
|
+
replaceFunction(window, 'MutationObserver', function (Original) {
|
|
265
|
+
Original = Original || window.WebKitMutationObserver;
|
|
266
|
+
function WrappedMutationObserver(...args) {
|
|
267
|
+
if (typeof args[0] == 'function') {
|
|
268
|
+
args[0] = makeLoggedFunction(args[0], 'MutationObserver callback');
|
|
269
|
+
}
|
|
270
|
+
if (Original.bind && Original.bind.apply) {
|
|
271
|
+
// call constructor with variable number of arguments
|
|
272
|
+
return new (Original.bind.apply(Original, [null].concat(args)))();
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
// Safari's MutationObserver lacks a bind method, but its constructor
|
|
276
|
+
// doesn't support extra arguments anyway, so don't bother logging an
|
|
277
|
+
// error here.
|
|
278
|
+
return new Original(args[0]);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
// Just in case someone wants to monkey-patch the prototype.
|
|
282
|
+
WrappedMutationObserver.prototype = Original.prototype;
|
|
283
|
+
return WrappedMutationObserver;
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
function getAppIdsProperty(causedByAppId, onlyExtensionApps = true) {
|
|
288
|
+
const appIds = onlyExtensionApps ? _extensionAppIds : getAllAppIds();
|
|
289
|
+
if (!causedByAppId) {
|
|
290
|
+
return appIds;
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
const appIdsWithCause = appIds.slice();
|
|
294
|
+
let hasSetCause = false;
|
|
295
|
+
appIdsWithCause.forEach((entry, i) => {
|
|
296
|
+
if (!hasSetCause && entry.appId === causedByAppId) {
|
|
297
|
+
hasSetCause = true;
|
|
298
|
+
appIdsWithCause[i] = { ...entry, causedBy: true };
|
|
299
|
+
}
|
|
300
|
+
Object.freeze(appIdsWithCause[i]);
|
|
301
|
+
});
|
|
302
|
+
return Object.freeze(appIdsWithCause);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
// err should be an Error instance, and details can be any JSON-ifiable value.
|
|
306
|
+
function _logError(err, details, appId, sentByApp) {
|
|
307
|
+
logError(err, details, {
|
|
308
|
+
appId,
|
|
309
|
+
sentByApp,
|
|
310
|
+
appIds: getAppIdsProperty(appId),
|
|
311
|
+
loaderVersion: _extensionLoaderVersion,
|
|
312
|
+
implVersion: _extensionImplVersion,
|
|
313
|
+
userEmailHash: _extensionUserEmailHash,
|
|
314
|
+
isUsingSyncAPI: _isUsingSyncAPI,
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
function makeLoggedFunction(func, name) {
|
|
318
|
+
const msg = name ? 'Uncaught error in ' + name : 'Uncaught error';
|
|
319
|
+
return function (...args) {
|
|
320
|
+
return Logger.run(() => func.apply(this, args), msg);
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
function replaceFunction(parent, name, newFnMaker) {
|
|
324
|
+
const newFn = newFnMaker(parent[name]);
|
|
325
|
+
newFn.__original = parent[name];
|
|
326
|
+
parent[name] = newFn;
|
|
327
|
+
}
|
|
328
|
+
export function hashEmail(str) {
|
|
329
|
+
const hasher = new Sha256();
|
|
330
|
+
hasher.update('inboxsdk:' + str);
|
|
331
|
+
return hasher.digest('hex');
|
|
332
|
+
}
|
|
333
|
+
function _trackEvent(appId, type, eventName, properties) {
|
|
334
|
+
if (properties && typeof properties != 'object') {
|
|
335
|
+
throw new Error('properties must be object or null: ' + properties);
|
|
336
|
+
}
|
|
337
|
+
const event = {
|
|
338
|
+
type: type,
|
|
339
|
+
event: eventName,
|
|
340
|
+
timestamp: Date.now() * 1000,
|
|
341
|
+
origin: document.location.origin,
|
|
342
|
+
sessionId: _sessionId,
|
|
343
|
+
emailHash: _extensionUserEmailHash,
|
|
344
|
+
loaderVersion: _extensionLoaderVersion,
|
|
345
|
+
implementationVersion: _extensionImplVersion,
|
|
346
|
+
isUsingSyncAPI: _isUsingSyncAPI,
|
|
347
|
+
properties: properties,
|
|
348
|
+
};
|
|
349
|
+
if (type != 'gmail') {
|
|
350
|
+
Object.assign(event, {
|
|
351
|
+
extensionId: getExtensionId(),
|
|
352
|
+
appIds: getAppIdsProperty(appId),
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
Object.assign(event, {
|
|
357
|
+
appIds: getAppIdsProperty(null, false),
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
if (typeof document === 'undefined') {
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
_trackedEventsQueue.add(event);
|
|
364
|
+
// Signal to the logger master that a new event is ready to be sent.
|
|
365
|
+
document.documentElement.setAttribute('data-inboxsdk-last-event', '' + Date.now());
|
|
366
|
+
}
|
|
367
|
+
let currentAccessToken = null;
|
|
368
|
+
function isTimestampExpired(n) {
|
|
369
|
+
// Let's refresh the token 10 minutes early
|
|
370
|
+
return Date.now() + 10 * 60 * 1000 > n;
|
|
371
|
+
}
|
|
372
|
+
async function retrieveNewEventsAccessToken() {
|
|
373
|
+
const { text } = await ajax({
|
|
374
|
+
url: 'https://api.inboxsdk.com/api/v2/events/oauth',
|
|
375
|
+
// Work around CORB for extensions that have permissions to inboxsdk.com
|
|
376
|
+
XMLHttpRequest: getXMLHttpRequest(),
|
|
377
|
+
});
|
|
378
|
+
const accessToken = JSON.parse(text);
|
|
379
|
+
if (isTimestampExpired(accessToken.expirationDate)) {
|
|
380
|
+
console.warn('Got an apparently already expired token. Assuming our clock is busted...');
|
|
381
|
+
// Let's assume the token expires in 30 minutes. The server refreshes the
|
|
382
|
+
// token 30 minutes before it expires so it's probably a safe bet.
|
|
383
|
+
accessToken.expirationDate = Date.now() + 30 * 60 * 1000;
|
|
384
|
+
}
|
|
385
|
+
return accessToken;
|
|
386
|
+
}
|
|
387
|
+
async function getEventsAccessToken() {
|
|
388
|
+
const t = currentAccessToken;
|
|
389
|
+
if (t && !isTimestampExpired(t.expirationDate)) {
|
|
390
|
+
return t;
|
|
391
|
+
}
|
|
392
|
+
else {
|
|
393
|
+
currentAccessToken = await retrieveNewEventsAccessToken();
|
|
394
|
+
return currentAccessToken;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
if (_extensionIsLoggerMaster &&
|
|
398
|
+
typeof document !== 'undefined' &&
|
|
399
|
+
typeof MutationObserver !== 'undefined') {
|
|
400
|
+
makeMutationObserverStream(document.documentElement, {
|
|
401
|
+
attributes: true,
|
|
402
|
+
attributeFilter: ['data-inboxsdk-last-event'],
|
|
403
|
+
})
|
|
404
|
+
.map(() => null)
|
|
405
|
+
.throttle(120 * 1000)
|
|
406
|
+
.onValue(function () {
|
|
407
|
+
const events = _trackedEventsQueue.removeAll();
|
|
408
|
+
// The trackedEventsQueue is in localStorage, which is shared between
|
|
409
|
+
// multiple tabs. A different tab could have flushed it already recently.
|
|
410
|
+
if (events.length === 0) {
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
(async function () {
|
|
414
|
+
const { oauthToken } = await getEventsAccessToken();
|
|
415
|
+
const apiKey = 'AIzaSyAwlvUR2x3OnCeas8hW8NDzVMswL5hZGg8';
|
|
416
|
+
// TODO change to use CommonPageCommunicator.pageAjax()
|
|
417
|
+
await ajax({
|
|
418
|
+
url: `https://pubsub.googleapis.com/v1/projects/mailfoogae/topics/events:publish?key=${encodeURIComponent(apiKey)}`,
|
|
419
|
+
method: 'POST',
|
|
420
|
+
headers: {
|
|
421
|
+
Authorization: `Bearer ${oauthToken}`,
|
|
422
|
+
'Content-Type': 'application/json',
|
|
423
|
+
},
|
|
424
|
+
data: JSON.stringify({
|
|
425
|
+
messages: [
|
|
426
|
+
{
|
|
427
|
+
data: Buffer.from(JSON.stringify({
|
|
428
|
+
data: events,
|
|
429
|
+
timestamp: Date.now() * 1000,
|
|
430
|
+
})).toString('base64'),
|
|
431
|
+
},
|
|
432
|
+
],
|
|
433
|
+
}),
|
|
434
|
+
});
|
|
435
|
+
})().catch((err) => {
|
|
436
|
+
Logger.error(err, {
|
|
437
|
+
type: 'Failed to log events',
|
|
438
|
+
});
|
|
439
|
+
});
|
|
440
|
+
});
|
|
441
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// Queue which tries to persist its data into localStorage so its contents
|
|
2
|
+
// aren't wiped when the page is closed. It handles localStorage not being
|
|
3
|
+
// present or not working (such as if we're running into quota issues).
|
|
4
|
+
// Safe for use in multiple tabs on the same domain at once.
|
|
5
|
+
export default class PersistentQueue {
|
|
6
|
+
_fallbackQueue = [];
|
|
7
|
+
_sid;
|
|
8
|
+
constructor(id) {
|
|
9
|
+
this._sid = 'inboxsdk__persistentqueue_' + id;
|
|
10
|
+
}
|
|
11
|
+
_getSavedQueue() {
|
|
12
|
+
let queue = JSON.parse(localStorage.getItem(this._sid));
|
|
13
|
+
if (queue == null) {
|
|
14
|
+
queue = [];
|
|
15
|
+
}
|
|
16
|
+
return queue;
|
|
17
|
+
}
|
|
18
|
+
_putSavedQueue(queue) {
|
|
19
|
+
localStorage.setItem(this._sid, JSON.stringify(queue));
|
|
20
|
+
}
|
|
21
|
+
_clearSavedQueue() {
|
|
22
|
+
localStorage.removeItem(this._sid);
|
|
23
|
+
}
|
|
24
|
+
add(val) {
|
|
25
|
+
let success = false;
|
|
26
|
+
if (typeof localStorage !== 'undefined') {
|
|
27
|
+
try {
|
|
28
|
+
const queue = this._getSavedQueue();
|
|
29
|
+
queue.push(val);
|
|
30
|
+
this._putSavedQueue(queue);
|
|
31
|
+
success = true;
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
// ignore
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (!success) {
|
|
38
|
+
this._fallbackQueue.push(val);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
remove() {
|
|
42
|
+
let ret;
|
|
43
|
+
if (typeof localStorage !== 'undefined') {
|
|
44
|
+
try {
|
|
45
|
+
const queue = this._getSavedQueue();
|
|
46
|
+
const tmpRet = queue.shift();
|
|
47
|
+
this._putSavedQueue(queue);
|
|
48
|
+
ret = tmpRet;
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
// ignore
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// If we didn't get anything from the localStorage queue, or if we
|
|
55
|
+
// failed to update the queue, then try the fallback instead.
|
|
56
|
+
if (ret === undefined) {
|
|
57
|
+
ret = this._fallbackQueue.shift();
|
|
58
|
+
}
|
|
59
|
+
return ret;
|
|
60
|
+
}
|
|
61
|
+
removeAll() {
|
|
62
|
+
let ret = undefined;
|
|
63
|
+
if (typeof localStorage !== 'undefined') {
|
|
64
|
+
try {
|
|
65
|
+
const queue = this._getSavedQueue();
|
|
66
|
+
this._clearSavedQueue();
|
|
67
|
+
ret = queue;
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
// ignore
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (ret === undefined) {
|
|
74
|
+
ret = [];
|
|
75
|
+
}
|
|
76
|
+
ret = ret.concat(this._fallbackQueue);
|
|
77
|
+
this._fallbackQueue = [];
|
|
78
|
+
return ret;
|
|
79
|
+
}
|
|
80
|
+
peekAll() {
|
|
81
|
+
let ret = undefined;
|
|
82
|
+
if (typeof localStorage !== 'undefined') {
|
|
83
|
+
try {
|
|
84
|
+
ret = this._getSavedQueue();
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
// ignore
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (ret === undefined) {
|
|
91
|
+
ret = [];
|
|
92
|
+
}
|
|
93
|
+
ret = ret.concat(this._fallbackQueue);
|
|
94
|
+
return ret;
|
|
95
|
+
}
|
|
96
|
+
clear() {
|
|
97
|
+
if (typeof localStorage !== 'undefined') {
|
|
98
|
+
try {
|
|
99
|
+
this._clearSavedQueue();
|
|
100
|
+
}
|
|
101
|
+
catch (e) {
|
|
102
|
+
// ignore
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
this._fallbackQueue.length = 0;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import EventEmitter from 'events';
|
|
2
|
+
import Logger from './logger';
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
4
|
+
/* eslint-disable prefer-rest-params */
|
|
5
|
+
// Version of EventEmitter where any exceptions thrown by event handlers are
|
|
6
|
+
// caught. This is used to catch exceptions from application code.
|
|
7
|
+
export default class SafeEventEmitter extends EventEmitter {
|
|
8
|
+
emit(event, ...args) {
|
|
9
|
+
try {
|
|
10
|
+
return super.emit.apply(this, arguments);
|
|
11
|
+
}
|
|
12
|
+
catch (e) {
|
|
13
|
+
Logger.error(e);
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as Kefir from 'kefir';
|
|
2
|
+
// An StopperPool is created from a stopper stream, and can have more stopper
|
|
3
|
+
// streams added to it. It has a stream property which is a stopper stream which
|
|
4
|
+
// emits a stop event and ends only after all of its input stopper streams have
|
|
5
|
+
// stopped.
|
|
6
|
+
export default class StopperPool {
|
|
7
|
+
_streamCount = 0;
|
|
8
|
+
_ended = false;
|
|
9
|
+
_pool = Kefir.pool();
|
|
10
|
+
stream;
|
|
11
|
+
constructor(streams) {
|
|
12
|
+
this.stream = this._pool
|
|
13
|
+
.filter(() => {
|
|
14
|
+
this._streamCount--;
|
|
15
|
+
if (this._streamCount === 0) {
|
|
16
|
+
this._ended = true;
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
})
|
|
21
|
+
.take(1)
|
|
22
|
+
.toProperty();
|
|
23
|
+
// force stream to be active so this._streamCount, this._ended, and the
|
|
24
|
+
// property's cached value will be kept up-to-date
|
|
25
|
+
this.stream.onValue(() => {
|
|
26
|
+
// ignore
|
|
27
|
+
});
|
|
28
|
+
this.add(streams);
|
|
29
|
+
}
|
|
30
|
+
add(newStreams) {
|
|
31
|
+
if (this._ended) {
|
|
32
|
+
throw new Error('Tried to add a stream to a stopped StopperPool');
|
|
33
|
+
}
|
|
34
|
+
const arrStreams = Array.isArray(newStreams) ? newStreams : [newStreams];
|
|
35
|
+
this._streamCount += arrStreams.length;
|
|
36
|
+
this._pool.plug(Kefir.merge(arrStreams.map((newStream) => newStream.take(1))));
|
|
37
|
+
}
|
|
38
|
+
getSize() {
|
|
39
|
+
return this._streamCount;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as Kefir from 'kefir';
|
|
2
|
+
/**
|
|
3
|
+
* Returns a Kefir stream that repeatedly calls the condition callback until it
|
|
4
|
+
* returns a truthy value, and then the stream emits that value and ends.
|
|
5
|
+
* If the timeout passes, an error event is emitted and the error is also
|
|
6
|
+
* thrown so that it gets logged. Well-behaving code should not let the timeout
|
|
7
|
+
* get tripped.
|
|
8
|
+
*/
|
|
9
|
+
export default function streamWaitFor(condition, timeout = 60 * 1000, steptime = 250) {
|
|
10
|
+
// make this error here so we have a sensible stack.
|
|
11
|
+
const timeoutError = new Error('waitFor timeout');
|
|
12
|
+
const timeoutStream = Kefir.later(timeout, null).flatMap(() => {
|
|
13
|
+
const result = condition();
|
|
14
|
+
if (result) {
|
|
15
|
+
return Kefir.constant(result);
|
|
16
|
+
}
|
|
17
|
+
setTimeout(() => {
|
|
18
|
+
throw timeoutError;
|
|
19
|
+
}, 0);
|
|
20
|
+
return Kefir.constantError(timeoutError);
|
|
21
|
+
});
|
|
22
|
+
const isTruthy = Boolean;
|
|
23
|
+
return Kefir.later(0, null)
|
|
24
|
+
.merge(Kefir.interval(steptime, null))
|
|
25
|
+
.map(() => condition())
|
|
26
|
+
.filter(isTruthy)
|
|
27
|
+
.merge(timeoutStream)
|
|
28
|
+
.take(1)
|
|
29
|
+
.takeErrors(1);
|
|
30
|
+
}
|